2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/file.h>
38 #include <linux/slab.h>
40 #include <asm/uaccess.h>
44 static struct lock_class_key pd_lock_key;
45 static struct lock_class_key mr_lock_key;
46 static struct lock_class_key cq_lock_key;
47 static struct lock_class_key qp_lock_key;
48 static struct lock_class_key ah_lock_key;
49 static struct lock_class_key srq_lock_key;
50 static struct lock_class_key xrcd_lock_key;
52 #define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
54 (udata)->inbuf = (void __user *) (ibuf); \
55 (udata)->outbuf = (void __user *) (obuf); \
56 (udata)->inlen = (ilen); \
57 (udata)->outlen = (olen); \
61 * The ib_uobject locking scheme is as follows:
63 * - ib_uverbs_idr_lock protects the uverbs idrs themselves, so it
64 * needs to be held during all idr operations. When an object is
65 * looked up, a reference must be taken on the object's kref before
68 * - Each object also has an rwsem. This rwsem must be held for
69 * reading while an operation that uses the object is performed.
70 * For example, while registering an MR, the associated PD's
71 * uobject.mutex must be held for reading. The rwsem must be held
72 * for writing while initializing or destroying an object.
74 * - In addition, each object has a "live" flag. If this flag is not
75 * set, then lookups of the object will fail even if it is found in
76 * the idr. This handles a reader that blocks and does not acquire
77 * the rwsem until after the object is destroyed. The destroy
78 * operation will set the live flag to 0 and then drop the rwsem;
79 * this will allow the reader to acquire the rwsem, see that the
80 * live flag is 0, and then drop the rwsem and its reference to
81 * object. The underlying storage will not be freed until the last
82 * reference to the object is dropped.
85 static void init_uobj(struct ib_uobject *uobj, u64 user_handle,
86 struct ib_ucontext *context, struct lock_class_key *key)
88 uobj->user_handle = user_handle;
89 uobj->context = context;
90 kref_init(&uobj->ref);
91 init_rwsem(&uobj->mutex);
92 lockdep_set_class(&uobj->mutex, key);
96 static void release_uobj(struct kref *kref)
98 kfree(container_of(kref, struct ib_uobject, ref));
101 static void put_uobj(struct ib_uobject *uobj)
103 kref_put(&uobj->ref, release_uobj);
106 static void put_uobj_read(struct ib_uobject *uobj)
108 up_read(&uobj->mutex);
112 static void put_uobj_write(struct ib_uobject *uobj)
114 up_write(&uobj->mutex);
118 static int idr_add_uobj(struct idr *idr, struct ib_uobject *uobj)
123 if (!idr_pre_get(idr, GFP_KERNEL))
126 spin_lock(&ib_uverbs_idr_lock);
127 ret = idr_get_new(idr, uobj, &uobj->id);
128 spin_unlock(&ib_uverbs_idr_lock);
136 void idr_remove_uobj(struct idr *idr, struct ib_uobject *uobj)
138 spin_lock(&ib_uverbs_idr_lock);
139 idr_remove(idr, uobj->id);
140 spin_unlock(&ib_uverbs_idr_lock);
143 static struct ib_uobject *__idr_get_uobj(struct idr *idr, int id,
144 struct ib_ucontext *context)
146 struct ib_uobject *uobj;
148 spin_lock(&ib_uverbs_idr_lock);
149 uobj = idr_find(idr, id);
151 if (uobj->context == context)
152 kref_get(&uobj->ref);
156 spin_unlock(&ib_uverbs_idr_lock);
161 static struct ib_uobject *idr_read_uobj(struct idr *idr, int id,
162 struct ib_ucontext *context, int nested)
164 struct ib_uobject *uobj;
166 uobj = __idr_get_uobj(idr, id, context);
171 down_read_nested(&uobj->mutex, SINGLE_DEPTH_NESTING);
173 down_read(&uobj->mutex);
182 static struct ib_uobject *idr_write_uobj(struct idr *idr, int id,
183 struct ib_ucontext *context)
185 struct ib_uobject *uobj;
187 uobj = __idr_get_uobj(idr, id, context);
191 down_write(&uobj->mutex);
193 put_uobj_write(uobj);
200 static void *idr_read_obj(struct idr *idr, int id, struct ib_ucontext *context,
203 struct ib_uobject *uobj;
205 uobj = idr_read_uobj(idr, id, context, nested);
206 return uobj ? uobj->object : NULL;
209 static struct ib_pd *idr_read_pd(int pd_handle, struct ib_ucontext *context)
211 return idr_read_obj(&ib_uverbs_pd_idr, pd_handle, context, 0);
214 static void put_pd_read(struct ib_pd *pd)
216 put_uobj_read(pd->uobject);
219 static struct ib_cq *idr_read_cq(int cq_handle, struct ib_ucontext *context, int nested)
221 return idr_read_obj(&ib_uverbs_cq_idr, cq_handle, context, nested);
224 static void put_cq_read(struct ib_cq *cq)
226 put_uobj_read(cq->uobject);
229 static struct ib_ah *idr_read_ah(int ah_handle, struct ib_ucontext *context)
231 return idr_read_obj(&ib_uverbs_ah_idr, ah_handle, context, 0);
234 static void put_ah_read(struct ib_ah *ah)
236 put_uobj_read(ah->uobject);
239 static struct ib_qp *idr_read_qp(int qp_handle, struct ib_ucontext *context)
241 return idr_read_obj(&ib_uverbs_qp_idr, qp_handle, context, 0);
244 static struct ib_qp *idr_write_qp(int qp_handle, struct ib_ucontext *context)
246 struct ib_uobject *uobj;
248 uobj = idr_write_uobj(&ib_uverbs_qp_idr, qp_handle, context);
249 return uobj ? uobj->object : NULL;
252 static void put_qp_read(struct ib_qp *qp)
254 put_uobj_read(qp->uobject);
257 static void put_qp_write(struct ib_qp *qp)
259 put_uobj_write(qp->uobject);
262 static struct ib_srq *idr_read_srq(int srq_handle, struct ib_ucontext *context)
264 return idr_read_obj(&ib_uverbs_srq_idr, srq_handle, context, 0);
267 static void put_srq_read(struct ib_srq *srq)
269 put_uobj_read(srq->uobject);
272 static struct ib_xrcd *idr_read_xrcd(int xrcd_handle, struct ib_ucontext *context,
273 struct ib_uobject **uobj)
275 *uobj = idr_read_uobj(&ib_uverbs_xrcd_idr, xrcd_handle, context, 0);
276 return *uobj ? (*uobj)->object : NULL;
279 static void put_xrcd_read(struct ib_uobject *uobj)
284 ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
285 const char __user *buf,
286 int in_len, int out_len)
288 struct ib_uverbs_get_context cmd;
289 struct ib_uverbs_get_context_resp resp;
290 struct ib_udata udata;
291 struct ib_device *ibdev = file->device->ib_dev;
292 struct ib_ucontext *ucontext;
296 if (out_len < sizeof resp)
299 if (copy_from_user(&cmd, buf, sizeof cmd))
302 mutex_lock(&file->mutex);
304 if (file->ucontext) {
309 INIT_UDATA(&udata, buf + sizeof cmd,
310 (unsigned long) cmd.response + sizeof resp,
311 in_len - sizeof cmd, out_len - sizeof resp);
313 ucontext = ibdev->alloc_ucontext(ibdev, &udata);
314 if (IS_ERR(ucontext)) {
315 ret = PTR_ERR(ucontext);
319 ucontext->device = ibdev;
320 INIT_LIST_HEAD(&ucontext->pd_list);
321 INIT_LIST_HEAD(&ucontext->mr_list);
322 INIT_LIST_HEAD(&ucontext->mw_list);
323 INIT_LIST_HEAD(&ucontext->cq_list);
324 INIT_LIST_HEAD(&ucontext->qp_list);
325 INIT_LIST_HEAD(&ucontext->srq_list);
326 INIT_LIST_HEAD(&ucontext->ah_list);
327 INIT_LIST_HEAD(&ucontext->xrcd_list);
328 ucontext->closing = 0;
330 resp.num_comp_vectors = file->device->num_comp_vectors;
332 ret = get_unused_fd();
337 filp = ib_uverbs_alloc_event_file(file, 1);
343 if (copy_to_user((void __user *) (unsigned long) cmd.response,
344 &resp, sizeof resp)) {
349 file->async_file = filp->private_data;
351 INIT_IB_EVENT_HANDLER(&file->event_handler, file->device->ib_dev,
352 ib_uverbs_event_handler);
353 ret = ib_register_event_handler(&file->event_handler);
357 kref_get(&file->async_file->ref);
358 kref_get(&file->ref);
359 file->ucontext = ucontext;
361 fd_install(resp.async_fd, filp);
363 mutex_unlock(&file->mutex);
371 put_unused_fd(resp.async_fd);
374 ibdev->dealloc_ucontext(ucontext);
377 mutex_unlock(&file->mutex);
381 ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
382 const char __user *buf,
383 int in_len, int out_len)
385 struct ib_uverbs_query_device cmd;
386 struct ib_uverbs_query_device_resp resp;
387 struct ib_device_attr attr;
390 if (out_len < sizeof resp)
393 if (copy_from_user(&cmd, buf, sizeof cmd))
396 ret = ib_query_device(file->device->ib_dev, &attr);
400 memset(&resp, 0, sizeof resp);
402 resp.fw_ver = attr.fw_ver;
403 resp.node_guid = file->device->ib_dev->node_guid;
404 resp.sys_image_guid = attr.sys_image_guid;
405 resp.max_mr_size = attr.max_mr_size;
406 resp.page_size_cap = attr.page_size_cap;
407 resp.vendor_id = attr.vendor_id;
408 resp.vendor_part_id = attr.vendor_part_id;
409 resp.hw_ver = attr.hw_ver;
410 resp.max_qp = attr.max_qp;
411 resp.max_qp_wr = attr.max_qp_wr;
412 resp.device_cap_flags = attr.device_cap_flags;
413 resp.max_sge = attr.max_sge;
414 resp.max_sge_rd = attr.max_sge_rd;
415 resp.max_cq = attr.max_cq;
416 resp.max_cqe = attr.max_cqe;
417 resp.max_mr = attr.max_mr;
418 resp.max_pd = attr.max_pd;
419 resp.max_qp_rd_atom = attr.max_qp_rd_atom;
420 resp.max_ee_rd_atom = attr.max_ee_rd_atom;
421 resp.max_res_rd_atom = attr.max_res_rd_atom;
422 resp.max_qp_init_rd_atom = attr.max_qp_init_rd_atom;
423 resp.max_ee_init_rd_atom = attr.max_ee_init_rd_atom;
424 resp.atomic_cap = attr.atomic_cap;
425 resp.max_ee = attr.max_ee;
426 resp.max_rdd = attr.max_rdd;
427 resp.max_mw = attr.max_mw;
428 resp.max_raw_ipv6_qp = attr.max_raw_ipv6_qp;
429 resp.max_raw_ethy_qp = attr.max_raw_ethy_qp;
430 resp.max_mcast_grp = attr.max_mcast_grp;
431 resp.max_mcast_qp_attach = attr.max_mcast_qp_attach;
432 resp.max_total_mcast_qp_attach = attr.max_total_mcast_qp_attach;
433 resp.max_ah = attr.max_ah;
434 resp.max_fmr = attr.max_fmr;
435 resp.max_map_per_fmr = attr.max_map_per_fmr;
436 resp.max_srq = attr.max_srq;
437 resp.max_srq_wr = attr.max_srq_wr;
438 resp.max_srq_sge = attr.max_srq_sge;
439 resp.max_pkeys = attr.max_pkeys;
440 resp.local_ca_ack_delay = attr.local_ca_ack_delay;
441 resp.phys_port_cnt = file->device->ib_dev->phys_port_cnt;
443 if (copy_to_user((void __user *) (unsigned long) cmd.response,
450 ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
451 const char __user *buf,
452 int in_len, int out_len)
454 struct ib_uverbs_query_port cmd;
455 struct ib_uverbs_query_port_resp resp;
456 struct ib_port_attr attr;
459 if (out_len < sizeof resp)
462 if (copy_from_user(&cmd, buf, sizeof cmd))
465 ret = ib_query_port(file->device->ib_dev, cmd.port_num, &attr);
469 memset(&resp, 0, sizeof resp);
471 resp.state = attr.state;
472 resp.max_mtu = attr.max_mtu;
473 resp.active_mtu = attr.active_mtu;
474 resp.gid_tbl_len = attr.gid_tbl_len;
475 resp.port_cap_flags = attr.port_cap_flags;
476 resp.max_msg_sz = attr.max_msg_sz;
477 resp.bad_pkey_cntr = attr.bad_pkey_cntr;
478 resp.qkey_viol_cntr = attr.qkey_viol_cntr;
479 resp.pkey_tbl_len = attr.pkey_tbl_len;
481 resp.sm_lid = attr.sm_lid;
483 resp.max_vl_num = attr.max_vl_num;
484 resp.sm_sl = attr.sm_sl;
485 resp.subnet_timeout = attr.subnet_timeout;
486 resp.init_type_reply = attr.init_type_reply;
487 resp.active_width = attr.active_width;
488 resp.active_speed = attr.active_speed;
489 resp.phys_state = attr.phys_state;
490 resp.link_layer = rdma_port_get_link_layer(file->device->ib_dev,
493 if (copy_to_user((void __user *) (unsigned long) cmd.response,
500 ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
501 const char __user *buf,
502 int in_len, int out_len)
504 struct ib_uverbs_alloc_pd cmd;
505 struct ib_uverbs_alloc_pd_resp resp;
506 struct ib_udata udata;
507 struct ib_uobject *uobj;
511 if (out_len < sizeof resp)
514 if (copy_from_user(&cmd, buf, sizeof cmd))
517 INIT_UDATA(&udata, buf + sizeof cmd,
518 (unsigned long) cmd.response + sizeof resp,
519 in_len - sizeof cmd, out_len - sizeof resp);
521 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
525 init_uobj(uobj, 0, file->ucontext, &pd_lock_key);
526 down_write(&uobj->mutex);
528 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev,
529 file->ucontext, &udata);
535 pd->device = file->device->ib_dev;
537 atomic_set(&pd->usecnt, 0);
540 ret = idr_add_uobj(&ib_uverbs_pd_idr, uobj);
544 memset(&resp, 0, sizeof resp);
545 resp.pd_handle = uobj->id;
547 if (copy_to_user((void __user *) (unsigned long) cmd.response,
548 &resp, sizeof resp)) {
553 mutex_lock(&file->mutex);
554 list_add_tail(&uobj->list, &file->ucontext->pd_list);
555 mutex_unlock(&file->mutex);
559 up_write(&uobj->mutex);
564 idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
570 put_uobj_write(uobj);
574 ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
575 const char __user *buf,
576 int in_len, int out_len)
578 struct ib_uverbs_dealloc_pd cmd;
579 struct ib_uobject *uobj;
582 if (copy_from_user(&cmd, buf, sizeof cmd))
585 uobj = idr_write_uobj(&ib_uverbs_pd_idr, cmd.pd_handle, file->ucontext);
589 ret = ib_dealloc_pd(uobj->object);
593 put_uobj_write(uobj);
598 idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
600 mutex_lock(&file->mutex);
601 list_del(&uobj->list);
602 mutex_unlock(&file->mutex);
609 struct xrcd_table_entry {
611 struct ib_xrcd *xrcd;
615 static int xrcd_table_insert(struct ib_uverbs_device *dev,
617 struct ib_xrcd *xrcd)
619 struct xrcd_table_entry *entry, *scan;
620 struct rb_node **p = &dev->xrcd_tree.rb_node;
621 struct rb_node *parent = NULL;
623 entry = kmalloc(sizeof *entry, GFP_KERNEL);
628 entry->inode = inode;
632 scan = rb_entry(parent, struct xrcd_table_entry, node);
634 if (inode < scan->inode) {
636 } else if (inode > scan->inode) {
644 rb_link_node(&entry->node, parent, p);
645 rb_insert_color(&entry->node, &dev->xrcd_tree);
650 static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
653 struct xrcd_table_entry *entry;
654 struct rb_node *p = dev->xrcd_tree.rb_node;
657 entry = rb_entry(p, struct xrcd_table_entry, node);
659 if (inode < entry->inode)
661 else if (inode > entry->inode)
670 static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
672 struct xrcd_table_entry *entry;
674 entry = xrcd_table_search(dev, inode);
681 static void xrcd_table_delete(struct ib_uverbs_device *dev,
684 struct xrcd_table_entry *entry;
686 entry = xrcd_table_search(dev, inode);
689 rb_erase(&entry->node, &dev->xrcd_tree);
694 ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
695 const char __user *buf, int in_len,
698 struct ib_uverbs_open_xrcd cmd;
699 struct ib_uverbs_open_xrcd_resp resp;
700 struct ib_udata udata;
701 struct ib_uxrcd_object *obj;
702 struct ib_xrcd *xrcd = NULL;
703 struct file *f = NULL;
704 struct inode *inode = NULL;
708 if (out_len < sizeof resp)
711 if (copy_from_user(&cmd, buf, sizeof cmd))
714 INIT_UDATA(&udata, buf + sizeof cmd,
715 (unsigned long) cmd.response + sizeof resp,
716 in_len - sizeof cmd, out_len - sizeof resp);
718 mutex_lock(&file->device->xrcd_tree_mutex);
721 /* search for file descriptor */
725 goto err_tree_mutex_unlock;
728 inode = f->f_dentry->d_inode;
731 goto err_tree_mutex_unlock;
734 xrcd = find_xrcd(file->device, inode);
735 if (!xrcd && !(cmd.oflags & O_CREAT)) {
736 /* no file descriptor. Need CREATE flag */
738 goto err_tree_mutex_unlock;
741 if (xrcd && cmd.oflags & O_EXCL) {
743 goto err_tree_mutex_unlock;
747 obj = kmalloc(sizeof *obj, GFP_KERNEL);
750 goto err_tree_mutex_unlock;
753 init_uobj(&obj->uobject, 0, file->ucontext, &xrcd_lock_key);
755 down_write(&obj->uobject.mutex);
758 xrcd = file->device->ib_dev->alloc_xrcd(file->device->ib_dev,
759 file->ucontext, &udata);
766 xrcd->device = file->device->ib_dev;
767 atomic_set(&xrcd->usecnt, 0);
768 mutex_init(&xrcd->tgt_qp_mutex);
769 INIT_LIST_HEAD(&xrcd->tgt_qp_list);
773 atomic_set(&obj->refcnt, 0);
774 obj->uobject.object = xrcd;
775 ret = idr_add_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
779 memset(&resp, 0, sizeof resp);
780 resp.xrcd_handle = obj->uobject.id;
784 /* create new inode/xrcd table entry */
785 ret = xrcd_table_insert(file->device, inode, xrcd);
787 goto err_insert_xrcd;
789 atomic_inc(&xrcd->usecnt);
792 if (copy_to_user((void __user *) (unsigned long) cmd.response,
793 &resp, sizeof resp)) {
801 mutex_lock(&file->mutex);
802 list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list);
803 mutex_unlock(&file->mutex);
805 obj->uobject.live = 1;
806 up_write(&obj->uobject.mutex);
808 mutex_unlock(&file->device->xrcd_tree_mutex);
814 xrcd_table_delete(file->device, inode);
815 atomic_dec(&xrcd->usecnt);
819 idr_remove_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
822 ib_dealloc_xrcd(xrcd);
825 put_uobj_write(&obj->uobject);
827 err_tree_mutex_unlock:
831 mutex_unlock(&file->device->xrcd_tree_mutex);
836 ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file,
837 const char __user *buf, int in_len,
840 struct ib_uverbs_close_xrcd cmd;
841 struct ib_uobject *uobj;
842 struct ib_xrcd *xrcd = NULL;
843 struct inode *inode = NULL;
844 struct ib_uxrcd_object *obj;
848 if (copy_from_user(&cmd, buf, sizeof cmd))
851 mutex_lock(&file->device->xrcd_tree_mutex);
852 uobj = idr_write_uobj(&ib_uverbs_xrcd_idr, cmd.xrcd_handle, file->ucontext);
860 obj = container_of(uobj, struct ib_uxrcd_object, uobject);
861 if (atomic_read(&obj->refcnt)) {
862 put_uobj_write(uobj);
867 if (!inode || atomic_dec_and_test(&xrcd->usecnt)) {
868 ret = ib_dealloc_xrcd(uobj->object);
875 atomic_inc(&xrcd->usecnt);
877 put_uobj_write(uobj);
883 xrcd_table_delete(file->device, inode);
885 idr_remove_uobj(&ib_uverbs_xrcd_idr, uobj);
886 mutex_lock(&file->mutex);
887 list_del(&uobj->list);
888 mutex_unlock(&file->mutex);
894 mutex_unlock(&file->device->xrcd_tree_mutex);
898 void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev,
899 struct ib_xrcd *xrcd)
904 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
907 ib_dealloc_xrcd(xrcd);
910 xrcd_table_delete(dev, inode);
913 ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
914 const char __user *buf, int in_len,
917 struct ib_uverbs_reg_mr cmd;
918 struct ib_uverbs_reg_mr_resp resp;
919 struct ib_udata udata;
920 struct ib_uobject *uobj;
925 if (out_len < sizeof resp)
928 if (copy_from_user(&cmd, buf, sizeof cmd))
931 INIT_UDATA(&udata, buf + sizeof cmd,
932 (unsigned long) cmd.response + sizeof resp,
933 in_len - sizeof cmd, out_len - sizeof resp);
935 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
939 * Local write permission is required if remote write or
940 * remote atomic permission is also requested.
942 if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
943 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
946 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
950 init_uobj(uobj, 0, file->ucontext, &mr_lock_key);
951 down_write(&uobj->mutex);
953 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
959 mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
960 cmd.access_flags, &udata);
966 mr->device = pd->device;
969 atomic_inc(&pd->usecnt);
970 atomic_set(&mr->usecnt, 0);
973 ret = idr_add_uobj(&ib_uverbs_mr_idr, uobj);
977 memset(&resp, 0, sizeof resp);
978 resp.lkey = mr->lkey;
979 resp.rkey = mr->rkey;
980 resp.mr_handle = uobj->id;
982 if (copy_to_user((void __user *) (unsigned long) cmd.response,
983 &resp, sizeof resp)) {
990 mutex_lock(&file->mutex);
991 list_add_tail(&uobj->list, &file->ucontext->mr_list);
992 mutex_unlock(&file->mutex);
996 up_write(&uobj->mutex);
1001 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
1010 put_uobj_write(uobj);
1014 ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
1015 const char __user *buf, int in_len,
1018 struct ib_uverbs_dereg_mr cmd;
1020 struct ib_uobject *uobj;
1023 if (copy_from_user(&cmd, buf, sizeof cmd))
1026 uobj = idr_write_uobj(&ib_uverbs_mr_idr, cmd.mr_handle, file->ucontext);
1032 ret = ib_dereg_mr(mr);
1036 put_uobj_write(uobj);
1041 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
1043 mutex_lock(&file->mutex);
1044 list_del(&uobj->list);
1045 mutex_unlock(&file->mutex);
1052 ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
1053 const char __user *buf, int in_len,
1056 struct ib_uverbs_create_comp_channel cmd;
1057 struct ib_uverbs_create_comp_channel_resp resp;
1061 if (out_len < sizeof resp)
1064 if (copy_from_user(&cmd, buf, sizeof cmd))
1067 ret = get_unused_fd();
1072 filp = ib_uverbs_alloc_event_file(file, 0);
1074 put_unused_fd(resp.fd);
1075 return PTR_ERR(filp);
1078 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1079 &resp, sizeof resp)) {
1080 put_unused_fd(resp.fd);
1085 fd_install(resp.fd, filp);
1089 ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
1090 const char __user *buf, int in_len,
1093 struct ib_uverbs_create_cq cmd;
1094 struct ib_uverbs_create_cq_resp resp;
1095 struct ib_udata udata;
1096 struct ib_ucq_object *obj;
1097 struct ib_uverbs_event_file *ev_file = NULL;
1101 if (out_len < sizeof resp)
1104 if (copy_from_user(&cmd, buf, sizeof cmd))
1107 INIT_UDATA(&udata, buf + sizeof cmd,
1108 (unsigned long) cmd.response + sizeof resp,
1109 in_len - sizeof cmd, out_len - sizeof resp);
1111 if (cmd.comp_vector >= file->device->num_comp_vectors)
1114 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1118 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &cq_lock_key);
1119 down_write(&obj->uobject.mutex);
1121 if (cmd.comp_channel >= 0) {
1122 ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel);
1129 obj->uverbs_file = file;
1130 obj->comp_events_reported = 0;
1131 obj->async_events_reported = 0;
1132 INIT_LIST_HEAD(&obj->comp_list);
1133 INIT_LIST_HEAD(&obj->async_list);
1135 cq = file->device->ib_dev->create_cq(file->device->ib_dev, cmd.cqe,
1137 file->ucontext, &udata);
1143 cq->device = file->device->ib_dev;
1144 cq->uobject = &obj->uobject;
1145 cq->comp_handler = ib_uverbs_comp_handler;
1146 cq->event_handler = ib_uverbs_cq_event_handler;
1147 cq->cq_context = ev_file;
1148 atomic_set(&cq->usecnt, 0);
1150 obj->uobject.object = cq;
1151 ret = idr_add_uobj(&ib_uverbs_cq_idr, &obj->uobject);
1155 memset(&resp, 0, sizeof resp);
1156 resp.cq_handle = obj->uobject.id;
1159 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1160 &resp, sizeof resp)) {
1165 mutex_lock(&file->mutex);
1166 list_add_tail(&obj->uobject.list, &file->ucontext->cq_list);
1167 mutex_unlock(&file->mutex);
1169 obj->uobject.live = 1;
1171 up_write(&obj->uobject.mutex);
1176 idr_remove_uobj(&ib_uverbs_cq_idr, &obj->uobject);
1183 ib_uverbs_release_ucq(file, ev_file, obj);
1186 put_uobj_write(&obj->uobject);
1190 ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file,
1191 const char __user *buf, int in_len,
1194 struct ib_uverbs_resize_cq cmd;
1195 struct ib_uverbs_resize_cq_resp resp;
1196 struct ib_udata udata;
1200 if (copy_from_user(&cmd, buf, sizeof cmd))
1203 INIT_UDATA(&udata, buf + sizeof cmd,
1204 (unsigned long) cmd.response + sizeof resp,
1205 in_len - sizeof cmd, out_len - sizeof resp);
1207 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1211 ret = cq->device->resize_cq(cq, cmd.cqe, &udata);
1217 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1218 &resp, sizeof resp.cqe))
1224 return ret ? ret : in_len;
1227 static int copy_wc_to_user(void __user *dest, struct ib_wc *wc)
1229 struct ib_uverbs_wc tmp;
1231 tmp.wr_id = wc->wr_id;
1232 tmp.status = wc->status;
1233 tmp.opcode = wc->opcode;
1234 tmp.vendor_err = wc->vendor_err;
1235 tmp.byte_len = wc->byte_len;
1236 tmp.ex.imm_data = (__u32 __force) wc->ex.imm_data;
1237 tmp.qp_num = wc->qp->qp_num;
1238 tmp.src_qp = wc->src_qp;
1239 tmp.wc_flags = wc->wc_flags;
1240 tmp.pkey_index = wc->pkey_index;
1241 tmp.slid = wc->slid;
1243 tmp.dlid_path_bits = wc->dlid_path_bits;
1244 tmp.port_num = wc->port_num;
1247 if (copy_to_user(dest, &tmp, sizeof tmp))
1253 ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
1254 const char __user *buf, int in_len,
1257 struct ib_uverbs_poll_cq cmd;
1258 struct ib_uverbs_poll_cq_resp resp;
1259 u8 __user *header_ptr;
1260 u8 __user *data_ptr;
1265 if (copy_from_user(&cmd, buf, sizeof cmd))
1268 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1272 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1273 header_ptr = (void __user *)(unsigned long) cmd.response;
1274 data_ptr = header_ptr + sizeof resp;
1276 memset(&resp, 0, sizeof resp);
1277 while (resp.count < cmd.ne) {
1278 ret = ib_poll_cq(cq, 1, &wc);
1284 ret = copy_wc_to_user(data_ptr, &wc);
1288 data_ptr += sizeof(struct ib_uverbs_wc);
1292 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1304 ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
1305 const char __user *buf, int in_len,
1308 struct ib_uverbs_req_notify_cq cmd;
1311 if (copy_from_user(&cmd, buf, sizeof cmd))
1314 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1318 ib_req_notify_cq(cq, cmd.solicited_only ?
1319 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1326 ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
1327 const char __user *buf, int in_len,
1330 struct ib_uverbs_destroy_cq cmd;
1331 struct ib_uverbs_destroy_cq_resp resp;
1332 struct ib_uobject *uobj;
1334 struct ib_ucq_object *obj;
1335 struct ib_uverbs_event_file *ev_file;
1338 if (copy_from_user(&cmd, buf, sizeof cmd))
1341 uobj = idr_write_uobj(&ib_uverbs_cq_idr, cmd.cq_handle, file->ucontext);
1345 ev_file = cq->cq_context;
1346 obj = container_of(cq->uobject, struct ib_ucq_object, uobject);
1348 ret = ib_destroy_cq(cq);
1352 put_uobj_write(uobj);
1357 idr_remove_uobj(&ib_uverbs_cq_idr, uobj);
1359 mutex_lock(&file->mutex);
1360 list_del(&uobj->list);
1361 mutex_unlock(&file->mutex);
1363 ib_uverbs_release_ucq(file, ev_file, obj);
1365 memset(&resp, 0, sizeof resp);
1366 resp.comp_events_reported = obj->comp_events_reported;
1367 resp.async_events_reported = obj->async_events_reported;
1371 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1372 &resp, sizeof resp))
1378 ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
1379 const char __user *buf, int in_len,
1382 struct ib_uverbs_create_qp cmd;
1383 struct ib_uverbs_create_qp_resp resp;
1384 struct ib_udata udata;
1385 struct ib_uqp_object *obj;
1386 struct ib_device *device;
1387 struct ib_pd *pd = NULL;
1388 struct ib_xrcd *xrcd = NULL;
1389 struct ib_uobject *uninitialized_var(xrcd_uobj);
1390 struct ib_cq *scq = NULL, *rcq = NULL;
1391 struct ib_srq *srq = NULL;
1393 struct ib_qp_init_attr attr;
1396 if (out_len < sizeof resp)
1399 if (copy_from_user(&cmd, buf, sizeof cmd))
1402 INIT_UDATA(&udata, buf + sizeof cmd,
1403 (unsigned long) cmd.response + sizeof resp,
1404 in_len - sizeof cmd, out_len - sizeof resp);
1406 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1410 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
1411 down_write(&obj->uevent.uobject.mutex);
1413 if (cmd.qp_type == IB_QPT_XRC_TGT) {
1414 xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
1419 device = xrcd->device;
1421 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
1422 scq = idr_read_cq(cmd.send_cq_handle, file->ucontext, 0);
1428 if (cmd.qp_type == IB_QPT_XRC_INI) {
1429 cmd.max_recv_wr = cmd.max_recv_sge = 0;
1432 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
1433 if (!srq || srq->srq_type != IB_SRQT_BASIC) {
1438 rcq = (cmd.recv_cq_handle == cmd.send_cq_handle) ?
1439 scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext, 1);
1445 device = pd->device;
1448 attr.event_handler = ib_uverbs_qp_event_handler;
1449 attr.qp_context = file;
1454 attr.sq_sig_type = cmd.sq_sig_all ? IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR;
1455 attr.qp_type = cmd.qp_type;
1456 attr.create_flags = 0;
1458 attr.cap.max_send_wr = cmd.max_send_wr;
1459 attr.cap.max_recv_wr = cmd.max_recv_wr;
1460 attr.cap.max_send_sge = cmd.max_send_sge;
1461 attr.cap.max_recv_sge = cmd.max_recv_sge;
1462 attr.cap.max_inline_data = cmd.max_inline_data;
1464 obj->uevent.events_reported = 0;
1465 INIT_LIST_HEAD(&obj->uevent.event_list);
1466 INIT_LIST_HEAD(&obj->mcast_list);
1468 if (cmd.qp_type == IB_QPT_XRC_TGT)
1469 qp = ib_create_qp(pd, &attr);
1471 qp = device->create_qp(pd, &attr, &udata);
1478 if (cmd.qp_type != IB_QPT_XRC_TGT) {
1480 qp->device = device;
1482 qp->send_cq = attr.send_cq;
1483 qp->recv_cq = attr.recv_cq;
1485 qp->event_handler = attr.event_handler;
1486 qp->qp_context = attr.qp_context;
1487 qp->qp_type = attr.qp_type;
1488 atomic_inc(&pd->usecnt);
1489 atomic_inc(&attr.send_cq->usecnt);
1491 atomic_inc(&attr.recv_cq->usecnt);
1493 atomic_inc(&attr.srq->usecnt);
1495 qp->uobject = &obj->uevent.uobject;
1497 obj->uevent.uobject.object = qp;
1498 ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1502 memset(&resp, 0, sizeof resp);
1503 resp.qpn = qp->qp_num;
1504 resp.qp_handle = obj->uevent.uobject.id;
1505 resp.max_recv_sge = attr.cap.max_recv_sge;
1506 resp.max_send_sge = attr.cap.max_send_sge;
1507 resp.max_recv_wr = attr.cap.max_recv_wr;
1508 resp.max_send_wr = attr.cap.max_send_wr;
1509 resp.max_inline_data = attr.cap.max_inline_data;
1511 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1512 &resp, sizeof resp)) {
1518 put_xrcd_read(xrcd_uobj);
1523 if (rcq && rcq != scq)
1528 mutex_lock(&file->mutex);
1529 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
1530 mutex_unlock(&file->mutex);
1532 obj->uevent.uobject.live = 1;
1534 up_write(&obj->uevent.uobject.mutex);
1539 idr_remove_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1546 put_xrcd_read(xrcd_uobj);
1551 if (rcq && rcq != scq)
1556 put_uobj_write(&obj->uevent.uobject);
1560 ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file,
1561 const char __user *buf, int in_len, int out_len)
1563 struct ib_uverbs_open_qp cmd;
1564 struct ib_uverbs_create_qp_resp resp;
1565 struct ib_udata udata;
1566 struct ib_uqp_object *obj;
1567 struct ib_xrcd *xrcd;
1568 struct ib_uobject *uninitialized_var(xrcd_uobj);
1570 struct ib_qp_open_attr attr;
1573 if (out_len < sizeof resp)
1576 if (copy_from_user(&cmd, buf, sizeof cmd))
1579 INIT_UDATA(&udata, buf + sizeof cmd,
1580 (unsigned long) cmd.response + sizeof resp,
1581 in_len - sizeof cmd, out_len - sizeof resp);
1583 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1587 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
1588 down_write(&obj->uevent.uobject.mutex);
1590 xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
1596 attr.event_handler = ib_uverbs_qp_event_handler;
1597 attr.qp_context = file;
1598 attr.qp_num = cmd.qpn;
1599 attr.qp_type = cmd.qp_type;
1601 obj->uevent.events_reported = 0;
1602 INIT_LIST_HEAD(&obj->uevent.event_list);
1603 INIT_LIST_HEAD(&obj->mcast_list);
1605 qp = ib_open_qp(xrcd, &attr);
1611 qp->uobject = &obj->uevent.uobject;
1613 obj->uevent.uobject.object = qp;
1614 ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1618 memset(&resp, 0, sizeof resp);
1619 resp.qpn = qp->qp_num;
1620 resp.qp_handle = obj->uevent.uobject.id;
1622 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1623 &resp, sizeof resp)) {
1628 put_xrcd_read(xrcd_uobj);
1630 mutex_lock(&file->mutex);
1631 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
1632 mutex_unlock(&file->mutex);
1634 obj->uevent.uobject.live = 1;
1636 up_write(&obj->uevent.uobject.mutex);
1641 idr_remove_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1647 put_xrcd_read(xrcd_uobj);
1648 put_uobj_write(&obj->uevent.uobject);
1652 ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file,
1653 const char __user *buf, int in_len,
1656 struct ib_uverbs_query_qp cmd;
1657 struct ib_uverbs_query_qp_resp resp;
1659 struct ib_qp_attr *attr;
1660 struct ib_qp_init_attr *init_attr;
1663 if (copy_from_user(&cmd, buf, sizeof cmd))
1666 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1667 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1668 if (!attr || !init_attr) {
1673 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1679 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1686 memset(&resp, 0, sizeof resp);
1688 resp.qp_state = attr->qp_state;
1689 resp.cur_qp_state = attr->cur_qp_state;
1690 resp.path_mtu = attr->path_mtu;
1691 resp.path_mig_state = attr->path_mig_state;
1692 resp.qkey = attr->qkey;
1693 resp.rq_psn = attr->rq_psn;
1694 resp.sq_psn = attr->sq_psn;
1695 resp.dest_qp_num = attr->dest_qp_num;
1696 resp.qp_access_flags = attr->qp_access_flags;
1697 resp.pkey_index = attr->pkey_index;
1698 resp.alt_pkey_index = attr->alt_pkey_index;
1699 resp.sq_draining = attr->sq_draining;
1700 resp.max_rd_atomic = attr->max_rd_atomic;
1701 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1702 resp.min_rnr_timer = attr->min_rnr_timer;
1703 resp.port_num = attr->port_num;
1704 resp.timeout = attr->timeout;
1705 resp.retry_cnt = attr->retry_cnt;
1706 resp.rnr_retry = attr->rnr_retry;
1707 resp.alt_port_num = attr->alt_port_num;
1708 resp.alt_timeout = attr->alt_timeout;
1710 memcpy(resp.dest.dgid, attr->ah_attr.grh.dgid.raw, 16);
1711 resp.dest.flow_label = attr->ah_attr.grh.flow_label;
1712 resp.dest.sgid_index = attr->ah_attr.grh.sgid_index;
1713 resp.dest.hop_limit = attr->ah_attr.grh.hop_limit;
1714 resp.dest.traffic_class = attr->ah_attr.grh.traffic_class;
1715 resp.dest.dlid = attr->ah_attr.dlid;
1716 resp.dest.sl = attr->ah_attr.sl;
1717 resp.dest.src_path_bits = attr->ah_attr.src_path_bits;
1718 resp.dest.static_rate = attr->ah_attr.static_rate;
1719 resp.dest.is_global = !!(attr->ah_attr.ah_flags & IB_AH_GRH);
1720 resp.dest.port_num = attr->ah_attr.port_num;
1722 memcpy(resp.alt_dest.dgid, attr->alt_ah_attr.grh.dgid.raw, 16);
1723 resp.alt_dest.flow_label = attr->alt_ah_attr.grh.flow_label;
1724 resp.alt_dest.sgid_index = attr->alt_ah_attr.grh.sgid_index;
1725 resp.alt_dest.hop_limit = attr->alt_ah_attr.grh.hop_limit;
1726 resp.alt_dest.traffic_class = attr->alt_ah_attr.grh.traffic_class;
1727 resp.alt_dest.dlid = attr->alt_ah_attr.dlid;
1728 resp.alt_dest.sl = attr->alt_ah_attr.sl;
1729 resp.alt_dest.src_path_bits = attr->alt_ah_attr.src_path_bits;
1730 resp.alt_dest.static_rate = attr->alt_ah_attr.static_rate;
1731 resp.alt_dest.is_global = !!(attr->alt_ah_attr.ah_flags & IB_AH_GRH);
1732 resp.alt_dest.port_num = attr->alt_ah_attr.port_num;
1734 resp.max_send_wr = init_attr->cap.max_send_wr;
1735 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1736 resp.max_send_sge = init_attr->cap.max_send_sge;
1737 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1738 resp.max_inline_data = init_attr->cap.max_inline_data;
1739 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1741 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1742 &resp, sizeof resp))
1749 return ret ? ret : in_len;
1752 /* Remove ignored fields set in the attribute mask */
1753 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1756 case IB_QPT_XRC_INI:
1757 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1758 case IB_QPT_XRC_TGT:
1759 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1766 ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
1767 const char __user *buf, int in_len,
1770 struct ib_uverbs_modify_qp cmd;
1771 struct ib_udata udata;
1773 struct ib_qp_attr *attr;
1776 if (copy_from_user(&cmd, buf, sizeof cmd))
1779 INIT_UDATA(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd,
1782 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1786 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1792 attr->qp_state = cmd.qp_state;
1793 attr->cur_qp_state = cmd.cur_qp_state;
1794 attr->path_mtu = cmd.path_mtu;
1795 attr->path_mig_state = cmd.path_mig_state;
1796 attr->qkey = cmd.qkey;
1797 attr->rq_psn = cmd.rq_psn;
1798 attr->sq_psn = cmd.sq_psn;
1799 attr->dest_qp_num = cmd.dest_qp_num;
1800 attr->qp_access_flags = cmd.qp_access_flags;
1801 attr->pkey_index = cmd.pkey_index;
1802 attr->alt_pkey_index = cmd.alt_pkey_index;
1803 attr->en_sqd_async_notify = cmd.en_sqd_async_notify;
1804 attr->max_rd_atomic = cmd.max_rd_atomic;
1805 attr->max_dest_rd_atomic = cmd.max_dest_rd_atomic;
1806 attr->min_rnr_timer = cmd.min_rnr_timer;
1807 attr->port_num = cmd.port_num;
1808 attr->timeout = cmd.timeout;
1809 attr->retry_cnt = cmd.retry_cnt;
1810 attr->rnr_retry = cmd.rnr_retry;
1811 attr->alt_port_num = cmd.alt_port_num;
1812 attr->alt_timeout = cmd.alt_timeout;
1814 memcpy(attr->ah_attr.grh.dgid.raw, cmd.dest.dgid, 16);
1815 attr->ah_attr.grh.flow_label = cmd.dest.flow_label;
1816 attr->ah_attr.grh.sgid_index = cmd.dest.sgid_index;
1817 attr->ah_attr.grh.hop_limit = cmd.dest.hop_limit;
1818 attr->ah_attr.grh.traffic_class = cmd.dest.traffic_class;
1819 attr->ah_attr.dlid = cmd.dest.dlid;
1820 attr->ah_attr.sl = cmd.dest.sl;
1821 attr->ah_attr.src_path_bits = cmd.dest.src_path_bits;
1822 attr->ah_attr.static_rate = cmd.dest.static_rate;
1823 attr->ah_attr.ah_flags = cmd.dest.is_global ? IB_AH_GRH : 0;
1824 attr->ah_attr.port_num = cmd.dest.port_num;
1826 memcpy(attr->alt_ah_attr.grh.dgid.raw, cmd.alt_dest.dgid, 16);
1827 attr->alt_ah_attr.grh.flow_label = cmd.alt_dest.flow_label;
1828 attr->alt_ah_attr.grh.sgid_index = cmd.alt_dest.sgid_index;
1829 attr->alt_ah_attr.grh.hop_limit = cmd.alt_dest.hop_limit;
1830 attr->alt_ah_attr.grh.traffic_class = cmd.alt_dest.traffic_class;
1831 attr->alt_ah_attr.dlid = cmd.alt_dest.dlid;
1832 attr->alt_ah_attr.sl = cmd.alt_dest.sl;
1833 attr->alt_ah_attr.src_path_bits = cmd.alt_dest.src_path_bits;
1834 attr->alt_ah_attr.static_rate = cmd.alt_dest.static_rate;
1835 attr->alt_ah_attr.ah_flags = cmd.alt_dest.is_global ? IB_AH_GRH : 0;
1836 attr->alt_ah_attr.port_num = cmd.alt_dest.port_num;
1838 if (qp->real_qp == qp) {
1839 ret = qp->device->modify_qp(qp, attr,
1840 modify_qp_mask(qp->qp_type, cmd.attr_mask), &udata);
1842 ret = ib_modify_qp(qp, attr, modify_qp_mask(qp->qp_type, cmd.attr_mask));
1858 ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1859 const char __user *buf, int in_len,
1862 struct ib_uverbs_destroy_qp cmd;
1863 struct ib_uverbs_destroy_qp_resp resp;
1864 struct ib_uobject *uobj;
1866 struct ib_uqp_object *obj;
1869 if (copy_from_user(&cmd, buf, sizeof cmd))
1872 memset(&resp, 0, sizeof resp);
1874 uobj = idr_write_uobj(&ib_uverbs_qp_idr, cmd.qp_handle, file->ucontext);
1878 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1880 if (!list_empty(&obj->mcast_list)) {
1881 put_uobj_write(uobj);
1885 ret = ib_destroy_qp(qp);
1889 put_uobj_write(uobj);
1894 idr_remove_uobj(&ib_uverbs_qp_idr, uobj);
1896 mutex_lock(&file->mutex);
1897 list_del(&uobj->list);
1898 mutex_unlock(&file->mutex);
1900 ib_uverbs_release_uevent(file, &obj->uevent);
1902 resp.events_reported = obj->uevent.events_reported;
1906 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1907 &resp, sizeof resp))
1913 ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1914 const char __user *buf, int in_len,
1917 struct ib_uverbs_post_send cmd;
1918 struct ib_uverbs_post_send_resp resp;
1919 struct ib_uverbs_send_wr *user_wr;
1920 struct ib_send_wr *wr = NULL, *last, *next, *bad_wr;
1924 ssize_t ret = -EINVAL;
1926 if (copy_from_user(&cmd, buf, sizeof cmd))
1929 if (in_len < sizeof cmd + cmd.wqe_size * cmd.wr_count +
1930 cmd.sge_count * sizeof (struct ib_uverbs_sge))
1933 if (cmd.wqe_size < sizeof (struct ib_uverbs_send_wr))
1936 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
1940 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1944 is_ud = qp->qp_type == IB_QPT_UD;
1947 for (i = 0; i < cmd.wr_count; ++i) {
1948 if (copy_from_user(user_wr,
1949 buf + sizeof cmd + i * cmd.wqe_size,
1955 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
1960 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
1961 user_wr->num_sge * sizeof (struct ib_sge),
1975 next->wr_id = user_wr->wr_id;
1976 next->num_sge = user_wr->num_sge;
1977 next->opcode = user_wr->opcode;
1978 next->send_flags = user_wr->send_flags;
1981 next->wr.ud.ah = idr_read_ah(user_wr->wr.ud.ah,
1983 if (!next->wr.ud.ah) {
1987 next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn;
1988 next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey;
1990 switch (next->opcode) {
1991 case IB_WR_RDMA_WRITE_WITH_IMM:
1993 (__be32 __force) user_wr->ex.imm_data;
1994 case IB_WR_RDMA_WRITE:
1995 case IB_WR_RDMA_READ:
1996 next->wr.rdma.remote_addr =
1997 user_wr->wr.rdma.remote_addr;
1998 next->wr.rdma.rkey =
1999 user_wr->wr.rdma.rkey;
2001 case IB_WR_SEND_WITH_IMM:
2003 (__be32 __force) user_wr->ex.imm_data;
2005 case IB_WR_SEND_WITH_INV:
2006 next->ex.invalidate_rkey =
2007 user_wr->ex.invalidate_rkey;
2009 case IB_WR_ATOMIC_CMP_AND_SWP:
2010 case IB_WR_ATOMIC_FETCH_AND_ADD:
2011 next->wr.atomic.remote_addr =
2012 user_wr->wr.atomic.remote_addr;
2013 next->wr.atomic.compare_add =
2014 user_wr->wr.atomic.compare_add;
2015 next->wr.atomic.swap = user_wr->wr.atomic.swap;
2016 next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
2023 if (next->num_sge) {
2024 next->sg_list = (void *) next +
2025 ALIGN(sizeof *next, sizeof (struct ib_sge));
2026 if (copy_from_user(next->sg_list,
2028 cmd.wr_count * cmd.wqe_size +
2029 sg_ind * sizeof (struct ib_sge),
2030 next->num_sge * sizeof (struct ib_sge))) {
2034 sg_ind += next->num_sge;
2036 next->sg_list = NULL;
2040 ret = qp->device->post_send(qp->real_qp, wr, &bad_wr);
2042 for (next = wr; next; next = next->next) {
2048 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2049 &resp, sizeof resp))
2056 if (is_ud && wr->wr.ud.ah)
2057 put_ah_read(wr->wr.ud.ah);
2066 return ret ? ret : in_len;
2069 static struct ib_recv_wr *ib_uverbs_unmarshall_recv(const char __user *buf,
2075 struct ib_uverbs_recv_wr *user_wr;
2076 struct ib_recv_wr *wr = NULL, *last, *next;
2081 if (in_len < wqe_size * wr_count +
2082 sge_count * sizeof (struct ib_uverbs_sge))
2083 return ERR_PTR(-EINVAL);
2085 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
2086 return ERR_PTR(-EINVAL);
2088 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2090 return ERR_PTR(-ENOMEM);
2094 for (i = 0; i < wr_count; ++i) {
2095 if (copy_from_user(user_wr, buf + i * wqe_size,
2101 if (user_wr->num_sge + sg_ind > sge_count) {
2106 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
2107 user_wr->num_sge * sizeof (struct ib_sge),
2121 next->wr_id = user_wr->wr_id;
2122 next->num_sge = user_wr->num_sge;
2124 if (next->num_sge) {
2125 next->sg_list = (void *) next +
2126 ALIGN(sizeof *next, sizeof (struct ib_sge));
2127 if (copy_from_user(next->sg_list,
2128 buf + wr_count * wqe_size +
2129 sg_ind * sizeof (struct ib_sge),
2130 next->num_sge * sizeof (struct ib_sge))) {
2134 sg_ind += next->num_sge;
2136 next->sg_list = NULL;
2151 return ERR_PTR(ret);
2154 ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
2155 const char __user *buf, int in_len,
2158 struct ib_uverbs_post_recv cmd;
2159 struct ib_uverbs_post_recv_resp resp;
2160 struct ib_recv_wr *wr, *next, *bad_wr;
2162 ssize_t ret = -EINVAL;
2164 if (copy_from_user(&cmd, buf, sizeof cmd))
2167 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
2168 in_len - sizeof cmd, cmd.wr_count,
2169 cmd.sge_count, cmd.wqe_size);
2173 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
2178 ret = qp->device->post_recv(qp->real_qp, wr, &bad_wr);
2183 for (next = wr; next; next = next->next) {
2189 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2190 &resp, sizeof resp))
2200 return ret ? ret : in_len;
2203 ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
2204 const char __user *buf, int in_len,
2207 struct ib_uverbs_post_srq_recv cmd;
2208 struct ib_uverbs_post_srq_recv_resp resp;
2209 struct ib_recv_wr *wr, *next, *bad_wr;
2211 ssize_t ret = -EINVAL;
2213 if (copy_from_user(&cmd, buf, sizeof cmd))
2216 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
2217 in_len - sizeof cmd, cmd.wr_count,
2218 cmd.sge_count, cmd.wqe_size);
2222 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2227 ret = srq->device->post_srq_recv(srq, wr, &bad_wr);
2232 for (next = wr; next; next = next->next) {
2238 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2239 &resp, sizeof resp))
2249 return ret ? ret : in_len;
2252 ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
2253 const char __user *buf, int in_len,
2256 struct ib_uverbs_create_ah cmd;
2257 struct ib_uverbs_create_ah_resp resp;
2258 struct ib_uobject *uobj;
2261 struct ib_ah_attr attr;
2264 if (out_len < sizeof resp)
2267 if (copy_from_user(&cmd, buf, sizeof cmd))
2270 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
2274 init_uobj(uobj, cmd.user_handle, file->ucontext, &ah_lock_key);
2275 down_write(&uobj->mutex);
2277 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
2283 attr.dlid = cmd.attr.dlid;
2284 attr.sl = cmd.attr.sl;
2285 attr.src_path_bits = cmd.attr.src_path_bits;
2286 attr.static_rate = cmd.attr.static_rate;
2287 attr.ah_flags = cmd.attr.is_global ? IB_AH_GRH : 0;
2288 attr.port_num = cmd.attr.port_num;
2289 attr.grh.flow_label = cmd.attr.grh.flow_label;
2290 attr.grh.sgid_index = cmd.attr.grh.sgid_index;
2291 attr.grh.hop_limit = cmd.attr.grh.hop_limit;
2292 attr.grh.traffic_class = cmd.attr.grh.traffic_class;
2293 memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16);
2295 ah = ib_create_ah(pd, &attr);
2304 ret = idr_add_uobj(&ib_uverbs_ah_idr, uobj);
2308 resp.ah_handle = uobj->id;
2310 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2311 &resp, sizeof resp)) {
2318 mutex_lock(&file->mutex);
2319 list_add_tail(&uobj->list, &file->ucontext->ah_list);
2320 mutex_unlock(&file->mutex);
2324 up_write(&uobj->mutex);
2329 idr_remove_uobj(&ib_uverbs_ah_idr, uobj);
2338 put_uobj_write(uobj);
2342 ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
2343 const char __user *buf, int in_len, int out_len)
2345 struct ib_uverbs_destroy_ah cmd;
2347 struct ib_uobject *uobj;
2350 if (copy_from_user(&cmd, buf, sizeof cmd))
2353 uobj = idr_write_uobj(&ib_uverbs_ah_idr, cmd.ah_handle, file->ucontext);
2358 ret = ib_destroy_ah(ah);
2362 put_uobj_write(uobj);
2367 idr_remove_uobj(&ib_uverbs_ah_idr, uobj);
2369 mutex_lock(&file->mutex);
2370 list_del(&uobj->list);
2371 mutex_unlock(&file->mutex);
2378 ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
2379 const char __user *buf, int in_len,
2382 struct ib_uverbs_attach_mcast cmd;
2384 struct ib_uqp_object *obj;
2385 struct ib_uverbs_mcast_entry *mcast;
2388 if (copy_from_user(&cmd, buf, sizeof cmd))
2391 qp = idr_write_qp(cmd.qp_handle, file->ucontext);
2395 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2397 list_for_each_entry(mcast, &obj->mcast_list, list)
2398 if (cmd.mlid == mcast->lid &&
2399 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2404 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2410 mcast->lid = cmd.mlid;
2411 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2413 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2415 list_add_tail(&mcast->list, &obj->mcast_list);
2422 return ret ? ret : in_len;
2425 ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
2426 const char __user *buf, int in_len,
2429 struct ib_uverbs_detach_mcast cmd;
2430 struct ib_uqp_object *obj;
2432 struct ib_uverbs_mcast_entry *mcast;
2435 if (copy_from_user(&cmd, buf, sizeof cmd))
2438 qp = idr_write_qp(cmd.qp_handle, file->ucontext);
2442 ret = ib_detach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
2446 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2448 list_for_each_entry(mcast, &obj->mcast_list, list)
2449 if (cmd.mlid == mcast->lid &&
2450 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2451 list_del(&mcast->list);
2459 return ret ? ret : in_len;
2462 int __uverbs_create_xsrq(struct ib_uverbs_file *file,
2463 struct ib_uverbs_create_xsrq *cmd,
2464 struct ib_udata *udata)
2466 struct ib_uverbs_create_srq_resp resp;
2467 struct ib_usrq_object *obj;
2470 struct ib_uobject *uninitialized_var(xrcd_uobj);
2471 struct ib_srq_init_attr attr;
2474 obj = kmalloc(sizeof *obj, GFP_KERNEL);
2478 init_uobj(&obj->uevent.uobject, cmd->user_handle, file->ucontext, &srq_lock_key);
2479 down_write(&obj->uevent.uobject.mutex);
2481 pd = idr_read_pd(cmd->pd_handle, file->ucontext);
2487 if (cmd->srq_type == IB_SRQT_XRC) {
2488 attr.ext.xrc.cq = idr_read_cq(cmd->cq_handle, file->ucontext, 0);
2489 if (!attr.ext.xrc.cq) {
2494 attr.ext.xrc.xrcd = idr_read_xrcd(cmd->xrcd_handle, file->ucontext, &xrcd_uobj);
2495 if (!attr.ext.xrc.xrcd) {
2500 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
2501 atomic_inc(&obj->uxrcd->refcnt);
2504 attr.event_handler = ib_uverbs_srq_event_handler;
2505 attr.srq_context = file;
2506 attr.srq_type = cmd->srq_type;
2507 attr.attr.max_wr = cmd->max_wr;
2508 attr.attr.max_sge = cmd->max_sge;
2509 attr.attr.srq_limit = cmd->srq_limit;
2511 obj->uevent.events_reported = 0;
2512 INIT_LIST_HEAD(&obj->uevent.event_list);
2514 srq = pd->device->create_srq(pd, &attr, udata);
2520 srq->device = pd->device;
2522 srq->srq_type = cmd->srq_type;
2523 srq->uobject = &obj->uevent.uobject;
2524 srq->event_handler = attr.event_handler;
2525 srq->srq_context = attr.srq_context;
2527 if (cmd->srq_type == IB_SRQT_XRC) {
2528 srq->ext.xrc.cq = attr.ext.xrc.cq;
2529 srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
2530 atomic_inc(&attr.ext.xrc.cq->usecnt);
2531 atomic_inc(&attr.ext.xrc.xrcd->usecnt);
2534 atomic_inc(&pd->usecnt);
2535 atomic_set(&srq->usecnt, 0);
2537 obj->uevent.uobject.object = srq;
2538 ret = idr_add_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
2542 memset(&resp, 0, sizeof resp);
2543 resp.srq_handle = obj->uevent.uobject.id;
2544 resp.max_wr = attr.attr.max_wr;
2545 resp.max_sge = attr.attr.max_sge;
2546 if (cmd->srq_type == IB_SRQT_XRC)
2547 resp.srqn = srq->ext.xrc.srq_num;
2549 if (copy_to_user((void __user *) (unsigned long) cmd->response,
2550 &resp, sizeof resp)) {
2555 if (cmd->srq_type == IB_SRQT_XRC) {
2556 put_uobj_read(xrcd_uobj);
2557 put_cq_read(attr.ext.xrc.cq);
2561 mutex_lock(&file->mutex);
2562 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->srq_list);
2563 mutex_unlock(&file->mutex);
2565 obj->uevent.uobject.live = 1;
2567 up_write(&obj->uevent.uobject.mutex);
2572 idr_remove_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
2575 ib_destroy_srq(srq);
2578 if (cmd->srq_type == IB_SRQT_XRC) {
2579 atomic_dec(&obj->uxrcd->refcnt);
2580 put_uobj_read(xrcd_uobj);
2584 if (cmd->srq_type == IB_SRQT_XRC)
2585 put_cq_read(attr.ext.xrc.cq);
2591 put_uobj_write(&obj->uevent.uobject);
2595 ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
2596 const char __user *buf, int in_len,
2599 struct ib_uverbs_create_srq cmd;
2600 struct ib_uverbs_create_xsrq xcmd;
2601 struct ib_uverbs_create_srq_resp resp;
2602 struct ib_udata udata;
2605 if (out_len < sizeof resp)
2608 if (copy_from_user(&cmd, buf, sizeof cmd))
2611 xcmd.response = cmd.response;
2612 xcmd.user_handle = cmd.user_handle;
2613 xcmd.srq_type = IB_SRQT_BASIC;
2614 xcmd.pd_handle = cmd.pd_handle;
2615 xcmd.max_wr = cmd.max_wr;
2616 xcmd.max_sge = cmd.max_sge;
2617 xcmd.srq_limit = cmd.srq_limit;
2619 INIT_UDATA(&udata, buf + sizeof cmd,
2620 (unsigned long) cmd.response + sizeof resp,
2621 in_len - sizeof cmd, out_len - sizeof resp);
2623 ret = __uverbs_create_xsrq(file, &xcmd, &udata);
2630 ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file,
2631 const char __user *buf, int in_len, int out_len)
2633 struct ib_uverbs_create_xsrq cmd;
2634 struct ib_uverbs_create_srq_resp resp;
2635 struct ib_udata udata;
2638 if (out_len < sizeof resp)
2641 if (copy_from_user(&cmd, buf, sizeof cmd))
2644 INIT_UDATA(&udata, buf + sizeof cmd,
2645 (unsigned long) cmd.response + sizeof resp,
2646 in_len - sizeof cmd, out_len - sizeof resp);
2648 ret = __uverbs_create_xsrq(file, &cmd, &udata);
2655 ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
2656 const char __user *buf, int in_len,
2659 struct ib_uverbs_modify_srq cmd;
2660 struct ib_udata udata;
2662 struct ib_srq_attr attr;
2665 if (copy_from_user(&cmd, buf, sizeof cmd))
2668 INIT_UDATA(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd,
2671 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2675 attr.max_wr = cmd.max_wr;
2676 attr.srq_limit = cmd.srq_limit;
2678 ret = srq->device->modify_srq(srq, &attr, cmd.attr_mask, &udata);
2682 return ret ? ret : in_len;
2685 ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file,
2686 const char __user *buf,
2687 int in_len, int out_len)
2689 struct ib_uverbs_query_srq cmd;
2690 struct ib_uverbs_query_srq_resp resp;
2691 struct ib_srq_attr attr;
2695 if (out_len < sizeof resp)
2698 if (copy_from_user(&cmd, buf, sizeof cmd))
2701 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2705 ret = ib_query_srq(srq, &attr);
2712 memset(&resp, 0, sizeof resp);
2714 resp.max_wr = attr.max_wr;
2715 resp.max_sge = attr.max_sge;
2716 resp.srq_limit = attr.srq_limit;
2718 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2719 &resp, sizeof resp))
2725 ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
2726 const char __user *buf, int in_len,
2729 struct ib_uverbs_destroy_srq cmd;
2730 struct ib_uverbs_destroy_srq_resp resp;
2731 struct ib_uobject *uobj;
2733 struct ib_uevent_object *obj;
2736 if (copy_from_user(&cmd, buf, sizeof cmd))
2739 uobj = idr_write_uobj(&ib_uverbs_srq_idr, cmd.srq_handle, file->ucontext);
2743 obj = container_of(uobj, struct ib_uevent_object, uobject);
2745 ret = ib_destroy_srq(srq);
2749 put_uobj_write(uobj);
2754 idr_remove_uobj(&ib_uverbs_srq_idr, uobj);
2756 mutex_lock(&file->mutex);
2757 list_del(&uobj->list);
2758 mutex_unlock(&file->mutex);
2760 ib_uverbs_release_uevent(file, obj);
2762 memset(&resp, 0, sizeof resp);
2763 resp.events_reported = obj->events_reported;
2767 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2768 &resp, sizeof resp))
2771 return ret ? ret : in_len;