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>
39 #include <linux/sched.h>
41 #include <linux/uaccess.h>
43 #include <rdma/uverbs_types.h>
44 #include <rdma/uverbs_std_types.h>
45 #include "rdma_core.h"
48 #include "core_priv.h"
51 * Copy a response to userspace. If the provided 'resp' is larger than the
52 * user buffer it is silently truncated. If the user provided a larger buffer
53 * then the trailing portion is zero filled.
55 * These semantics are intended to support future extension of the output
58 static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp,
63 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
64 return uverbs_copy_to_struct_or_zero(
65 attrs, UVERBS_ATTR_CORE_OUT, resp, resp_len);
67 if (copy_to_user(attrs->ucore.outbuf, resp,
68 min(attrs->ucore.outlen, resp_len)))
71 if (resp_len < attrs->ucore.outlen) {
73 * Zero fill any extra memory that user
74 * space might have provided.
76 ret = clear_user(attrs->ucore.outbuf + resp_len,
77 attrs->ucore.outlen - resp_len);
86 * Copy a request from userspace. If the provided 'req' is larger than the
87 * user buffer then the user buffer is zero extended into the 'req'. If 'req'
88 * is smaller than the user buffer then the uncopied bytes in the user buffer
91 static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,
94 if (copy_from_user(req, attrs->ucore.inbuf,
95 min(attrs->ucore.inlen, req_len)))
98 if (attrs->ucore.inlen < req_len) {
99 memset(req + attrs->ucore.inlen, 0,
100 req_len - attrs->ucore.inlen);
101 } else if (attrs->ucore.inlen > req_len) {
102 if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len,
103 attrs->ucore.inlen - req_len))
110 * Generate the value for the 'response_length' protocol used by write_ex.
111 * This is the number of bytes the kernel actually wrote. Userspace can use
112 * this to detect what structure members in the response the kernel
115 static u32 uverbs_response_length(struct uverbs_attr_bundle *attrs,
118 return min_t(size_t, attrs->ucore.outlen, resp_len);
122 * The iterator version of the request interface is for handlers that need to
123 * step over a flex array at the end of a command header.
125 struct uverbs_req_iter {
126 const void __user *cur;
127 const void __user *end;
130 static int uverbs_request_start(struct uverbs_attr_bundle *attrs,
131 struct uverbs_req_iter *iter,
135 if (attrs->ucore.inlen < req_len)
138 if (copy_from_user(req, attrs->ucore.inbuf, req_len))
141 iter->cur = attrs->ucore.inbuf + req_len;
142 iter->end = attrs->ucore.inbuf + attrs->ucore.inlen;
146 static int uverbs_request_next(struct uverbs_req_iter *iter, void *val,
149 if (iter->cur + len > iter->end)
152 if (copy_from_user(val, iter->cur, len))
159 static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter,
162 const void __user *res = iter->cur;
164 if (iter->cur + len > iter->end)
165 return (void __force __user *)ERR_PTR(-ENOSPC);
170 static int uverbs_request_finish(struct uverbs_req_iter *iter)
172 if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur))
178 * When calling a destroy function during an error unwind we need to pass in
179 * the udata that is sanitized of all user arguments. Ie from the driver
180 * perspective it looks like no udata was passed.
182 struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs)
184 attrs->driver_udata = (struct ib_udata){};
185 return &attrs->driver_udata;
188 static struct ib_uverbs_completion_event_file *
189 _ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
191 struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
197 uverbs_uobject_get(uobj);
200 return container_of(uobj, struct ib_uverbs_completion_event_file,
203 #define ib_uverbs_lookup_comp_file(_fd, _ufile) \
204 _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile)
206 static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
208 struct ib_uverbs_file *file = attrs->ufile;
209 struct ib_uverbs_get_context cmd;
210 struct ib_uverbs_get_context_resp resp;
211 struct ib_ucontext *ucontext;
212 struct ib_rdmacg_object cg_obj;
213 struct ib_device *ib_dev;
214 struct ib_uobject *uobj;
217 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
221 mutex_lock(&file->ucontext_lock);
222 ib_dev = srcu_dereference(file->device->ib_dev,
223 &file->device->disassociate_srcu);
229 if (file->ucontext) {
234 ret = ib_rdmacg_try_charge(&cg_obj, ib_dev, RDMACG_RESOURCE_HCA_HANDLE);
238 ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext);
244 attrs->context = ucontext;
246 ucontext->res.type = RDMA_RESTRACK_CTX;
247 ucontext->device = ib_dev;
248 ucontext->cg_obj = cg_obj;
249 /* ufile is required when some objects are released */
250 ucontext->ufile = file;
252 ucontext->closing = false;
253 ucontext->cleanup_retryable = false;
255 xa_init_flags(&ucontext->mmap_xa, XA_FLAGS_ALLOC);
257 uobj = uobj_alloc(UVERBS_OBJECT_ASYNC_EVENT, attrs, &ib_dev);
263 resp.async_fd = uobj->id;
264 resp.num_comp_vectors = file->device->num_comp_vectors;
266 ret = uverbs_response(attrs, &resp, sizeof(resp));
270 ret = ib_dev->ops.alloc_ucontext(ucontext, &attrs->driver_udata);
274 rdma_restrack_uadd(&ucontext->res);
276 ib_uverbs_init_async_event_file(
277 container_of(uobj, struct ib_uverbs_async_event_file, uobj));
278 rdma_alloc_commit_uobject(uobj, attrs);
281 * Make sure that ib_uverbs_get_ucontext() sees the pointer update
282 * only after all writes to setup the ucontext have completed
284 smp_store_release(&file->ucontext, ucontext);
286 mutex_unlock(&file->ucontext_lock);
291 rdma_alloc_abort_uobject(uobj, attrs);
297 ib_rdmacg_uncharge(&cg_obj, ib_dev, RDMACG_RESOURCE_HCA_HANDLE);
300 mutex_unlock(&file->ucontext_lock);
304 static void copy_query_dev_fields(struct ib_ucontext *ucontext,
305 struct ib_uverbs_query_device_resp *resp,
306 struct ib_device_attr *attr)
308 struct ib_device *ib_dev = ucontext->device;
310 resp->fw_ver = attr->fw_ver;
311 resp->node_guid = ib_dev->node_guid;
312 resp->sys_image_guid = attr->sys_image_guid;
313 resp->max_mr_size = attr->max_mr_size;
314 resp->page_size_cap = attr->page_size_cap;
315 resp->vendor_id = attr->vendor_id;
316 resp->vendor_part_id = attr->vendor_part_id;
317 resp->hw_ver = attr->hw_ver;
318 resp->max_qp = attr->max_qp;
319 resp->max_qp_wr = attr->max_qp_wr;
320 resp->device_cap_flags = lower_32_bits(attr->device_cap_flags);
321 resp->max_sge = min(attr->max_send_sge, attr->max_recv_sge);
322 resp->max_sge_rd = attr->max_sge_rd;
323 resp->max_cq = attr->max_cq;
324 resp->max_cqe = attr->max_cqe;
325 resp->max_mr = attr->max_mr;
326 resp->max_pd = attr->max_pd;
327 resp->max_qp_rd_atom = attr->max_qp_rd_atom;
328 resp->max_ee_rd_atom = attr->max_ee_rd_atom;
329 resp->max_res_rd_atom = attr->max_res_rd_atom;
330 resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom;
331 resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom;
332 resp->atomic_cap = attr->atomic_cap;
333 resp->max_ee = attr->max_ee;
334 resp->max_rdd = attr->max_rdd;
335 resp->max_mw = attr->max_mw;
336 resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp;
337 resp->max_raw_ethy_qp = attr->max_raw_ethy_qp;
338 resp->max_mcast_grp = attr->max_mcast_grp;
339 resp->max_mcast_qp_attach = attr->max_mcast_qp_attach;
340 resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach;
341 resp->max_ah = attr->max_ah;
342 resp->max_fmr = attr->max_fmr;
343 resp->max_map_per_fmr = attr->max_map_per_fmr;
344 resp->max_srq = attr->max_srq;
345 resp->max_srq_wr = attr->max_srq_wr;
346 resp->max_srq_sge = attr->max_srq_sge;
347 resp->max_pkeys = attr->max_pkeys;
348 resp->local_ca_ack_delay = attr->local_ca_ack_delay;
349 resp->phys_port_cnt = ib_dev->phys_port_cnt;
352 static int ib_uverbs_query_device(struct uverbs_attr_bundle *attrs)
354 struct ib_uverbs_query_device cmd;
355 struct ib_uverbs_query_device_resp resp;
356 struct ib_ucontext *ucontext;
359 ucontext = ib_uverbs_get_ucontext(attrs);
360 if (IS_ERR(ucontext))
361 return PTR_ERR(ucontext);
363 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
367 memset(&resp, 0, sizeof resp);
368 copy_query_dev_fields(ucontext, &resp, &ucontext->device->attrs);
370 return uverbs_response(attrs, &resp, sizeof(resp));
373 static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs)
375 struct ib_uverbs_query_port cmd;
376 struct ib_uverbs_query_port_resp resp;
377 struct ib_port_attr attr;
379 struct ib_ucontext *ucontext;
380 struct ib_device *ib_dev;
382 ucontext = ib_uverbs_get_ucontext(attrs);
383 if (IS_ERR(ucontext))
384 return PTR_ERR(ucontext);
385 ib_dev = ucontext->device;
387 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
391 ret = ib_query_port(ib_dev, cmd.port_num, &attr);
395 memset(&resp, 0, sizeof resp);
396 copy_port_attr_to_resp(&attr, &resp, ib_dev, cmd.port_num);
398 return uverbs_response(attrs, &resp, sizeof(resp));
401 static int ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs)
403 struct ib_uverbs_alloc_pd cmd;
404 struct ib_uverbs_alloc_pd_resp resp;
405 struct ib_uobject *uobj;
408 struct ib_device *ib_dev;
410 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
414 uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ib_dev);
416 return PTR_ERR(uobj);
418 pd = rdma_zalloc_drv_obj(ib_dev, ib_pd);
426 pd->__internal_mr = NULL;
427 atomic_set(&pd->usecnt, 0);
428 pd->res.type = RDMA_RESTRACK_PD;
430 ret = ib_dev->ops.alloc_pd(pd, &attrs->driver_udata);
435 memset(&resp, 0, sizeof resp);
436 resp.pd_handle = uobj->id;
437 rdma_restrack_uadd(&pd->res);
439 ret = uverbs_response(attrs, &resp, sizeof(resp));
443 rdma_alloc_commit_uobject(uobj, attrs);
447 ib_dealloc_pd_user(pd, uverbs_get_cleared_udata(attrs));
452 uobj_alloc_abort(uobj, attrs);
456 static int ib_uverbs_dealloc_pd(struct uverbs_attr_bundle *attrs)
458 struct ib_uverbs_dealloc_pd cmd;
461 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
465 return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
468 struct xrcd_table_entry {
470 struct ib_xrcd *xrcd;
474 static int xrcd_table_insert(struct ib_uverbs_device *dev,
476 struct ib_xrcd *xrcd)
478 struct xrcd_table_entry *entry, *scan;
479 struct rb_node **p = &dev->xrcd_tree.rb_node;
480 struct rb_node *parent = NULL;
482 entry = kmalloc(sizeof *entry, GFP_KERNEL);
487 entry->inode = inode;
491 scan = rb_entry(parent, struct xrcd_table_entry, node);
493 if (inode < scan->inode) {
495 } else if (inode > scan->inode) {
503 rb_link_node(&entry->node, parent, p);
504 rb_insert_color(&entry->node, &dev->xrcd_tree);
509 static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
512 struct xrcd_table_entry *entry;
513 struct rb_node *p = dev->xrcd_tree.rb_node;
516 entry = rb_entry(p, struct xrcd_table_entry, node);
518 if (inode < entry->inode)
520 else if (inode > entry->inode)
529 static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
531 struct xrcd_table_entry *entry;
533 entry = xrcd_table_search(dev, inode);
540 static void xrcd_table_delete(struct ib_uverbs_device *dev,
543 struct xrcd_table_entry *entry;
545 entry = xrcd_table_search(dev, inode);
548 rb_erase(&entry->node, &dev->xrcd_tree);
553 static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
555 struct ib_uverbs_device *ibudev = attrs->ufile->device;
556 struct ib_uverbs_open_xrcd cmd;
557 struct ib_uverbs_open_xrcd_resp resp;
558 struct ib_uxrcd_object *obj;
559 struct ib_xrcd *xrcd = NULL;
560 struct fd f = {NULL, 0};
561 struct inode *inode = NULL;
564 struct ib_device *ib_dev;
566 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
570 mutex_lock(&ibudev->xrcd_tree_mutex);
573 /* search for file descriptor */
577 goto err_tree_mutex_unlock;
580 inode = file_inode(f.file);
581 xrcd = find_xrcd(ibudev, inode);
582 if (!xrcd && !(cmd.oflags & O_CREAT)) {
583 /* no file descriptor. Need CREATE flag */
585 goto err_tree_mutex_unlock;
588 if (xrcd && cmd.oflags & O_EXCL) {
590 goto err_tree_mutex_unlock;
594 obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs,
598 goto err_tree_mutex_unlock;
602 xrcd = ib_dev->ops.alloc_xrcd(ib_dev, &attrs->driver_udata);
609 xrcd->device = ib_dev;
610 atomic_set(&xrcd->usecnt, 0);
611 mutex_init(&xrcd->tgt_qp_mutex);
612 INIT_LIST_HEAD(&xrcd->tgt_qp_list);
616 atomic_set(&obj->refcnt, 0);
617 obj->uobject.object = xrcd;
618 memset(&resp, 0, sizeof resp);
619 resp.xrcd_handle = obj->uobject.id;
623 /* create new inode/xrcd table entry */
624 ret = xrcd_table_insert(ibudev, inode, xrcd);
626 goto err_dealloc_xrcd;
628 atomic_inc(&xrcd->usecnt);
631 ret = uverbs_response(attrs, &resp, sizeof(resp));
638 mutex_unlock(&ibudev->xrcd_tree_mutex);
640 rdma_alloc_commit_uobject(&obj->uobject, attrs);
646 xrcd_table_delete(ibudev, inode);
647 atomic_dec(&xrcd->usecnt);
651 ib_dealloc_xrcd(xrcd, uverbs_get_cleared_udata(attrs));
654 uobj_alloc_abort(&obj->uobject, attrs);
656 err_tree_mutex_unlock:
660 mutex_unlock(&ibudev->xrcd_tree_mutex);
665 static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs)
667 struct ib_uverbs_close_xrcd cmd;
670 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
674 return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs);
677 int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
678 enum rdma_remove_reason why,
679 struct uverbs_attr_bundle *attrs)
683 struct ib_uverbs_device *dev = attrs->ufile->device;
686 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
689 ret = ib_dealloc_xrcd(xrcd, &attrs->driver_udata);
691 if (ib_is_destroy_retryable(ret, why, uobject)) {
692 atomic_inc(&xrcd->usecnt);
697 xrcd_table_delete(dev, inode);
702 static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
704 struct ib_uverbs_reg_mr cmd;
705 struct ib_uverbs_reg_mr_resp resp;
706 struct ib_uobject *uobj;
710 struct ib_device *ib_dev;
712 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
716 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
719 ret = ib_check_mr_access(cmd.access_flags);
723 uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
725 return PTR_ERR(uobj);
727 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
733 if (cmd.access_flags & IB_ACCESS_ON_DEMAND) {
734 if (!(pd->device->attrs.device_cap_flags &
735 IB_DEVICE_ON_DEMAND_PAGING)) {
736 pr_debug("ODP support not available\n");
742 mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
744 &attrs->driver_udata);
750 mr->device = pd->device;
752 mr->type = IB_MR_TYPE_USER;
754 mr->sig_attrs = NULL;
756 atomic_inc(&pd->usecnt);
757 mr->res.type = RDMA_RESTRACK_MR;
758 rdma_restrack_uadd(&mr->res);
762 memset(&resp, 0, sizeof resp);
763 resp.lkey = mr->lkey;
764 resp.rkey = mr->rkey;
765 resp.mr_handle = uobj->id;
767 ret = uverbs_response(attrs, &resp, sizeof(resp));
771 uobj_put_obj_read(pd);
773 rdma_alloc_commit_uobject(uobj, attrs);
777 ib_dereg_mr_user(mr, uverbs_get_cleared_udata(attrs));
780 uobj_put_obj_read(pd);
783 uobj_alloc_abort(uobj, attrs);
787 static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
789 struct ib_uverbs_rereg_mr cmd;
790 struct ib_uverbs_rereg_mr_resp resp;
791 struct ib_pd *pd = NULL;
793 struct ib_pd *old_pd;
795 struct ib_uobject *uobj;
797 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
801 if (cmd.flags & ~IB_MR_REREG_SUPPORTED || !cmd.flags)
804 if ((cmd.flags & IB_MR_REREG_TRANS) &&
805 (!cmd.start || !cmd.hca_va || 0 >= cmd.length ||
806 (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)))
809 uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
811 return PTR_ERR(uobj);
820 if (cmd.flags & IB_MR_REREG_ACCESS) {
821 ret = ib_check_mr_access(cmd.access_flags);
826 if (cmd.flags & IB_MR_REREG_PD) {
827 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle,
836 ret = mr->device->ops.rereg_user_mr(mr, cmd.flags, cmd.start,
837 cmd.length, cmd.hca_va,
838 cmd.access_flags, pd,
839 &attrs->driver_udata);
843 if (cmd.flags & IB_MR_REREG_PD) {
844 atomic_inc(&pd->usecnt);
846 atomic_dec(&old_pd->usecnt);
849 memset(&resp, 0, sizeof(resp));
850 resp.lkey = mr->lkey;
851 resp.rkey = mr->rkey;
853 ret = uverbs_response(attrs, &resp, sizeof(resp));
856 if (cmd.flags & IB_MR_REREG_PD)
857 uobj_put_obj_read(pd);
860 uobj_put_write(uobj);
865 static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs)
867 struct ib_uverbs_dereg_mr cmd;
870 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
874 return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
877 static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs)
879 struct ib_uverbs_alloc_mw cmd;
880 struct ib_uverbs_alloc_mw_resp resp;
881 struct ib_uobject *uobj;
885 struct ib_device *ib_dev;
887 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
891 uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev);
893 return PTR_ERR(uobj);
895 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
901 if (cmd.mw_type != IB_MW_TYPE_1 && cmd.mw_type != IB_MW_TYPE_2) {
906 mw = pd->device->ops.alloc_mw(pd, cmd.mw_type, &attrs->driver_udata);
912 mw->device = pd->device;
915 atomic_inc(&pd->usecnt);
919 memset(&resp, 0, sizeof(resp));
920 resp.rkey = mw->rkey;
921 resp.mw_handle = uobj->id;
923 ret = uverbs_response(attrs, &resp, sizeof(resp));
927 uobj_put_obj_read(pd);
928 rdma_alloc_commit_uobject(uobj, attrs);
932 uverbs_dealloc_mw(mw);
934 uobj_put_obj_read(pd);
936 uobj_alloc_abort(uobj, attrs);
940 static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs)
942 struct ib_uverbs_dealloc_mw cmd;
945 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
949 return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs);
952 static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs)
954 struct ib_uverbs_create_comp_channel cmd;
955 struct ib_uverbs_create_comp_channel_resp resp;
956 struct ib_uobject *uobj;
957 struct ib_uverbs_completion_event_file *ev_file;
958 struct ib_device *ib_dev;
961 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
965 uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev);
967 return PTR_ERR(uobj);
971 ev_file = container_of(uobj, struct ib_uverbs_completion_event_file,
973 ib_uverbs_init_event_queue(&ev_file->ev_queue);
975 ret = uverbs_response(attrs, &resp, sizeof(resp));
977 uobj_alloc_abort(uobj, attrs);
981 rdma_alloc_commit_uobject(uobj, attrs);
985 static struct ib_ucq_object *create_cq(struct uverbs_attr_bundle *attrs,
986 struct ib_uverbs_ex_create_cq *cmd)
988 struct ib_ucq_object *obj;
989 struct ib_uverbs_completion_event_file *ev_file = NULL;
992 struct ib_uverbs_ex_create_cq_resp resp;
993 struct ib_cq_init_attr attr = {};
994 struct ib_device *ib_dev;
996 if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
997 return ERR_PTR(-EINVAL);
999 obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
1004 if (cmd->comp_channel >= 0) {
1005 ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs);
1006 if (IS_ERR(ev_file)) {
1007 ret = PTR_ERR(ev_file);
1012 obj->uevent.uobject.user_handle = cmd->user_handle;
1013 INIT_LIST_HEAD(&obj->comp_list);
1014 INIT_LIST_HEAD(&obj->uevent.event_list);
1016 attr.cqe = cmd->cqe;
1017 attr.comp_vector = cmd->comp_vector;
1018 attr.flags = cmd->flags;
1020 cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
1025 cq->device = ib_dev;
1027 cq->comp_handler = ib_uverbs_comp_handler;
1028 cq->event_handler = ib_uverbs_cq_event_handler;
1029 cq->cq_context = ev_file ? &ev_file->ev_queue : NULL;
1030 atomic_set(&cq->usecnt, 0);
1032 ret = ib_dev->ops.create_cq(cq, &attr, &attrs->driver_udata);
1036 obj->uevent.uobject.object = cq;
1037 memset(&resp, 0, sizeof resp);
1038 resp.base.cq_handle = obj->uevent.uobject.id;
1039 resp.base.cqe = cq->cqe;
1040 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1042 cq->res.type = RDMA_RESTRACK_CQ;
1043 rdma_restrack_uadd(&cq->res);
1045 ret = uverbs_response(attrs, &resp, sizeof(resp));
1049 rdma_alloc_commit_uobject(&obj->uevent.uobject, attrs);
1053 ib_destroy_cq_user(cq, uverbs_get_cleared_udata(attrs));
1059 ib_uverbs_release_ucq(ev_file, obj);
1062 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1064 return ERR_PTR(ret);
1067 static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs)
1069 struct ib_uverbs_create_cq cmd;
1070 struct ib_uverbs_ex_create_cq cmd_ex;
1071 struct ib_ucq_object *obj;
1074 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1078 memset(&cmd_ex, 0, sizeof(cmd_ex));
1079 cmd_ex.user_handle = cmd.user_handle;
1080 cmd_ex.cqe = cmd.cqe;
1081 cmd_ex.comp_vector = cmd.comp_vector;
1082 cmd_ex.comp_channel = cmd.comp_channel;
1084 obj = create_cq(attrs, &cmd_ex);
1085 return PTR_ERR_OR_ZERO(obj);
1088 static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs)
1090 struct ib_uverbs_ex_create_cq cmd;
1091 struct ib_ucq_object *obj;
1094 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1104 obj = create_cq(attrs, &cmd);
1105 return PTR_ERR_OR_ZERO(obj);
1108 static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs)
1110 struct ib_uverbs_resize_cq cmd;
1111 struct ib_uverbs_resize_cq_resp resp = {};
1115 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1119 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1123 ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata);
1129 ret = uverbs_response(attrs, &resp, sizeof(resp));
1131 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1132 UVERBS_LOOKUP_READ);
1137 static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
1140 struct ib_uverbs_wc tmp;
1142 tmp.wr_id = wc->wr_id;
1143 tmp.status = wc->status;
1144 tmp.opcode = wc->opcode;
1145 tmp.vendor_err = wc->vendor_err;
1146 tmp.byte_len = wc->byte_len;
1147 tmp.ex.imm_data = wc->ex.imm_data;
1148 tmp.qp_num = wc->qp->qp_num;
1149 tmp.src_qp = wc->src_qp;
1150 tmp.wc_flags = wc->wc_flags;
1151 tmp.pkey_index = wc->pkey_index;
1152 if (rdma_cap_opa_ah(ib_dev, wc->port_num))
1153 tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid);
1155 tmp.slid = ib_lid_cpu16(wc->slid);
1157 tmp.dlid_path_bits = wc->dlid_path_bits;
1158 tmp.port_num = wc->port_num;
1161 if (copy_to_user(dest, &tmp, sizeof tmp))
1167 static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs)
1169 struct ib_uverbs_poll_cq cmd;
1170 struct ib_uverbs_poll_cq_resp resp;
1171 u8 __user *header_ptr;
1172 u8 __user *data_ptr;
1177 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1181 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1185 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1186 header_ptr = attrs->ucore.outbuf;
1187 data_ptr = header_ptr + sizeof resp;
1189 memset(&resp, 0, sizeof resp);
1190 while (resp.count < cmd.ne) {
1191 ret = ib_poll_cq(cq, 1, &wc);
1197 ret = copy_wc_to_user(cq->device, data_ptr, &wc);
1201 data_ptr += sizeof(struct ib_uverbs_wc);
1205 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1211 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
1212 ret = uverbs_output_written(attrs, UVERBS_ATTR_CORE_OUT);
1215 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1216 UVERBS_LOOKUP_READ);
1220 static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs)
1222 struct ib_uverbs_req_notify_cq cmd;
1226 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1230 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1234 ib_req_notify_cq(cq, cmd.solicited_only ?
1235 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1237 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1238 UVERBS_LOOKUP_READ);
1242 static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs)
1244 struct ib_uverbs_destroy_cq cmd;
1245 struct ib_uverbs_destroy_cq_resp resp;
1246 struct ib_uobject *uobj;
1247 struct ib_ucq_object *obj;
1250 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1254 uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1256 return PTR_ERR(uobj);
1258 obj = container_of(uobj, struct ib_ucq_object, uevent.uobject);
1259 memset(&resp, 0, sizeof(resp));
1260 resp.comp_events_reported = obj->comp_events_reported;
1261 resp.async_events_reported = obj->uevent.events_reported;
1263 uobj_put_destroy(uobj);
1265 return uverbs_response(attrs, &resp, sizeof(resp));
1268 static int create_qp(struct uverbs_attr_bundle *attrs,
1269 struct ib_uverbs_ex_create_qp *cmd)
1271 struct ib_uqp_object *obj;
1272 struct ib_device *device;
1273 struct ib_pd *pd = NULL;
1274 struct ib_xrcd *xrcd = NULL;
1275 struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT);
1276 struct ib_cq *scq = NULL, *rcq = NULL;
1277 struct ib_srq *srq = NULL;
1279 struct ib_qp_init_attr attr = {};
1280 struct ib_uverbs_ex_create_qp_resp resp;
1282 struct ib_rwq_ind_table *ind_tbl = NULL;
1284 struct ib_device *ib_dev;
1286 if (cmd->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
1289 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1292 return PTR_ERR(obj);
1294 obj->uevent.uobject.user_handle = cmd->user_handle;
1295 mutex_init(&obj->mcast_lock);
1297 if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) {
1298 ind_tbl = uobj_get_obj_read(rwq_ind_table,
1299 UVERBS_OBJECT_RWQ_IND_TBL,
1300 cmd->rwq_ind_tbl_handle, attrs);
1306 attr.rwq_ind_tbl = ind_tbl;
1309 if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1314 if (ind_tbl && !cmd->max_send_wr)
1317 if (cmd->qp_type == IB_QPT_XRC_TGT) {
1318 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle,
1321 if (IS_ERR(xrcd_uobj)) {
1326 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1331 device = xrcd->device;
1333 if (cmd->qp_type == IB_QPT_XRC_INI) {
1334 cmd->max_recv_wr = 0;
1335 cmd->max_recv_sge = 0;
1338 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ,
1339 cmd->srq_handle, attrs);
1340 if (!srq || srq->srq_type == IB_SRQT_XRC) {
1347 if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1348 rcq = uobj_get_obj_read(
1349 cq, UVERBS_OBJECT_CQ,
1350 cmd->recv_cq_handle, attrs);
1360 scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
1361 cmd->send_cq_handle, attrs);
1364 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle,
1366 if (!pd || (!scq && has_sq)) {
1371 device = pd->device;
1374 attr.event_handler = ib_uverbs_qp_event_handler;
1379 attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR :
1381 attr.qp_type = cmd->qp_type;
1382 attr.create_flags = 0;
1384 attr.cap.max_send_wr = cmd->max_send_wr;
1385 attr.cap.max_recv_wr = cmd->max_recv_wr;
1386 attr.cap.max_send_sge = cmd->max_send_sge;
1387 attr.cap.max_recv_sge = cmd->max_recv_sge;
1388 attr.cap.max_inline_data = cmd->max_inline_data;
1390 INIT_LIST_HEAD(&obj->uevent.event_list);
1391 INIT_LIST_HEAD(&obj->mcast_list);
1393 attr.create_flags = cmd->create_flags;
1394 if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
1395 IB_QP_CREATE_CROSS_CHANNEL |
1396 IB_QP_CREATE_MANAGED_SEND |
1397 IB_QP_CREATE_MANAGED_RECV |
1398 IB_QP_CREATE_SCATTER_FCS |
1399 IB_QP_CREATE_CVLAN_STRIPPING |
1400 IB_QP_CREATE_SOURCE_QPN |
1401 IB_QP_CREATE_PCI_WRITE_END_PADDING)) {
1406 if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
1407 if (!capable(CAP_NET_RAW)) {
1412 attr.source_qpn = cmd->source_qpn;
1415 if (cmd->qp_type == IB_QPT_XRC_TGT)
1416 qp = ib_create_qp(pd, &attr);
1418 qp = _ib_create_qp(device, pd, &attr, &attrs->driver_udata,
1426 if (cmd->qp_type != IB_QPT_XRC_TGT) {
1427 ret = ib_create_qp_security(qp, device);
1432 qp->send_cq = attr.send_cq;
1433 qp->recv_cq = attr.recv_cq;
1435 qp->rwq_ind_tbl = ind_tbl;
1436 qp->event_handler = attr.event_handler;
1437 qp->qp_type = attr.qp_type;
1438 atomic_set(&qp->usecnt, 0);
1439 atomic_inc(&pd->usecnt);
1442 atomic_inc(&attr.send_cq->usecnt);
1444 atomic_inc(&attr.recv_cq->usecnt);
1446 atomic_inc(&attr.srq->usecnt);
1448 atomic_inc(&ind_tbl->usecnt);
1450 /* It is done in _ib_create_qp for other QP types */
1454 obj->uevent.uobject.object = qp;
1456 memset(&resp, 0, sizeof resp);
1457 resp.base.qpn = qp->qp_num;
1458 resp.base.qp_handle = obj->uevent.uobject.id;
1459 resp.base.max_recv_sge = attr.cap.max_recv_sge;
1460 resp.base.max_send_sge = attr.cap.max_send_sge;
1461 resp.base.max_recv_wr = attr.cap.max_recv_wr;
1462 resp.base.max_send_wr = attr.cap.max_send_wr;
1463 resp.base.max_inline_data = attr.cap.max_inline_data;
1464 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1466 ret = uverbs_response(attrs, &resp, sizeof(resp));
1471 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object,
1473 atomic_inc(&obj->uxrcd->refcnt);
1474 uobj_put_read(xrcd_uobj);
1478 uobj_put_obj_read(pd);
1480 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1481 UVERBS_LOOKUP_READ);
1482 if (rcq && rcq != scq)
1483 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1484 UVERBS_LOOKUP_READ);
1486 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1487 UVERBS_LOOKUP_READ);
1489 uobj_put_obj_read(ind_tbl);
1491 rdma_alloc_commit_uobject(&obj->uevent.uobject, attrs);
1494 ib_destroy_qp_user(qp, uverbs_get_cleared_udata(attrs));
1497 if (!IS_ERR(xrcd_uobj))
1498 uobj_put_read(xrcd_uobj);
1500 uobj_put_obj_read(pd);
1502 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1503 UVERBS_LOOKUP_READ);
1504 if (rcq && rcq != scq)
1505 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1506 UVERBS_LOOKUP_READ);
1508 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1509 UVERBS_LOOKUP_READ);
1511 uobj_put_obj_read(ind_tbl);
1513 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1517 static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs)
1519 struct ib_uverbs_create_qp cmd;
1520 struct ib_uverbs_ex_create_qp cmd_ex;
1523 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1527 memset(&cmd_ex, 0, sizeof(cmd_ex));
1528 cmd_ex.user_handle = cmd.user_handle;
1529 cmd_ex.pd_handle = cmd.pd_handle;
1530 cmd_ex.send_cq_handle = cmd.send_cq_handle;
1531 cmd_ex.recv_cq_handle = cmd.recv_cq_handle;
1532 cmd_ex.srq_handle = cmd.srq_handle;
1533 cmd_ex.max_send_wr = cmd.max_send_wr;
1534 cmd_ex.max_recv_wr = cmd.max_recv_wr;
1535 cmd_ex.max_send_sge = cmd.max_send_sge;
1536 cmd_ex.max_recv_sge = cmd.max_recv_sge;
1537 cmd_ex.max_inline_data = cmd.max_inline_data;
1538 cmd_ex.sq_sig_all = cmd.sq_sig_all;
1539 cmd_ex.qp_type = cmd.qp_type;
1540 cmd_ex.is_srq = cmd.is_srq;
1542 return create_qp(attrs, &cmd_ex);
1545 static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs)
1547 struct ib_uverbs_ex_create_qp cmd;
1550 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1554 if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
1560 return create_qp(attrs, &cmd);
1563 static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs)
1565 struct ib_uverbs_open_qp cmd;
1566 struct ib_uverbs_create_qp_resp resp;
1567 struct ib_uqp_object *obj;
1568 struct ib_xrcd *xrcd;
1569 struct ib_uobject *uninitialized_var(xrcd_uobj);
1571 struct ib_qp_open_attr attr = {};
1573 struct ib_device *ib_dev;
1575 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1579 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1582 return PTR_ERR(obj);
1584 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs);
1585 if (IS_ERR(xrcd_uobj)) {
1590 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1596 attr.event_handler = ib_uverbs_qp_event_handler;
1597 attr.qp_num = cmd.qpn;
1598 attr.qp_type = cmd.qp_type;
1600 INIT_LIST_HEAD(&obj->uevent.event_list);
1601 INIT_LIST_HEAD(&obj->mcast_list);
1603 qp = ib_open_qp(xrcd, &attr);
1609 obj->uevent.uobject.object = qp;
1610 obj->uevent.uobject.user_handle = cmd.user_handle;
1612 memset(&resp, 0, sizeof resp);
1613 resp.qpn = qp->qp_num;
1614 resp.qp_handle = obj->uevent.uobject.id;
1616 ret = uverbs_response(attrs, &resp, sizeof(resp));
1620 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
1621 atomic_inc(&obj->uxrcd->refcnt);
1623 uobj_put_read(xrcd_uobj);
1625 rdma_alloc_commit_uobject(&obj->uevent.uobject, attrs);
1629 ib_destroy_qp_user(qp, uverbs_get_cleared_udata(attrs));
1631 uobj_put_read(xrcd_uobj);
1633 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1637 static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr,
1638 struct rdma_ah_attr *rdma_attr)
1640 const struct ib_global_route *grh;
1642 uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr);
1643 uverb_attr->sl = rdma_ah_get_sl(rdma_attr);
1644 uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr);
1645 uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr);
1646 uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) &
1648 if (uverb_attr->is_global) {
1649 grh = rdma_ah_read_grh(rdma_attr);
1650 memcpy(uverb_attr->dgid, grh->dgid.raw, 16);
1651 uverb_attr->flow_label = grh->flow_label;
1652 uverb_attr->sgid_index = grh->sgid_index;
1653 uverb_attr->hop_limit = grh->hop_limit;
1654 uverb_attr->traffic_class = grh->traffic_class;
1656 uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr);
1659 static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
1661 struct ib_uverbs_query_qp cmd;
1662 struct ib_uverbs_query_qp_resp resp;
1664 struct ib_qp_attr *attr;
1665 struct ib_qp_init_attr *init_attr;
1668 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1672 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1673 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1674 if (!attr || !init_attr) {
1679 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1685 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1687 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1688 UVERBS_LOOKUP_READ);
1693 memset(&resp, 0, sizeof resp);
1695 resp.qp_state = attr->qp_state;
1696 resp.cur_qp_state = attr->cur_qp_state;
1697 resp.path_mtu = attr->path_mtu;
1698 resp.path_mig_state = attr->path_mig_state;
1699 resp.qkey = attr->qkey;
1700 resp.rq_psn = attr->rq_psn;
1701 resp.sq_psn = attr->sq_psn;
1702 resp.dest_qp_num = attr->dest_qp_num;
1703 resp.qp_access_flags = attr->qp_access_flags;
1704 resp.pkey_index = attr->pkey_index;
1705 resp.alt_pkey_index = attr->alt_pkey_index;
1706 resp.sq_draining = attr->sq_draining;
1707 resp.max_rd_atomic = attr->max_rd_atomic;
1708 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1709 resp.min_rnr_timer = attr->min_rnr_timer;
1710 resp.port_num = attr->port_num;
1711 resp.timeout = attr->timeout;
1712 resp.retry_cnt = attr->retry_cnt;
1713 resp.rnr_retry = attr->rnr_retry;
1714 resp.alt_port_num = attr->alt_port_num;
1715 resp.alt_timeout = attr->alt_timeout;
1717 copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr);
1718 copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr);
1720 resp.max_send_wr = init_attr->cap.max_send_wr;
1721 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1722 resp.max_send_sge = init_attr->cap.max_send_sge;
1723 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1724 resp.max_inline_data = init_attr->cap.max_inline_data;
1725 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1727 ret = uverbs_response(attrs, &resp, sizeof(resp));
1736 /* Remove ignored fields set in the attribute mask */
1737 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1740 case IB_QPT_XRC_INI:
1741 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1742 case IB_QPT_XRC_TGT:
1743 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1750 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
1751 struct rdma_ah_attr *rdma_attr,
1752 struct ib_uverbs_qp_dest *uverb_attr)
1754 rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
1755 if (uverb_attr->is_global) {
1756 rdma_ah_set_grh(rdma_attr, NULL,
1757 uverb_attr->flow_label,
1758 uverb_attr->sgid_index,
1759 uverb_attr->hop_limit,
1760 uverb_attr->traffic_class);
1761 rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid);
1763 rdma_ah_set_ah_flags(rdma_attr, 0);
1765 rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
1766 rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
1767 rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
1768 rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
1769 rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
1770 rdma_ah_set_make_grd(rdma_attr, false);
1773 static int modify_qp(struct uverbs_attr_bundle *attrs,
1774 struct ib_uverbs_ex_modify_qp *cmd)
1776 struct ib_qp_attr *attr;
1780 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1784 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle,
1791 if ((cmd->base.attr_mask & IB_QP_PORT) &&
1792 !rdma_is_port_valid(qp->device, cmd->base.port_num)) {
1797 if ((cmd->base.attr_mask & IB_QP_AV)) {
1798 if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1803 if (cmd->base.attr_mask & IB_QP_STATE &&
1804 cmd->base.qp_state == IB_QPS_RTR) {
1805 /* We are in INIT->RTR TRANSITION (if we are not,
1806 * this transition will be rejected in subsequent checks).
1807 * In the INIT->RTR transition, we cannot have IB_QP_PORT set,
1808 * but the IB_QP_STATE flag is required.
1810 * Since kernel 3.14 (commit dbf727de7440), the uverbs driver,
1811 * when IB_QP_AV is set, has required inclusion of a valid
1812 * port number in the primary AV. (AVs are created and handled
1813 * differently for infiniband and ethernet (RoCE) ports).
1815 * Check the port number included in the primary AV against
1816 * the port number in the qp struct, which was set (and saved)
1817 * in the RST->INIT transition.
1819 if (cmd->base.dest.port_num != qp->real_qp->port) {
1824 /* We are in SQD->SQD. (If we are not, this transition will
1825 * be rejected later in the verbs layer checks).
1826 * Check for both IB_QP_PORT and IB_QP_AV, these can be set
1827 * together in the SQD->SQD transition.
1829 * If only IP_QP_AV was set, add in IB_QP_PORT as well (the
1830 * verbs layer driver does not track primary port changes
1831 * resulting from path migration. Thus, in SQD, if the primary
1832 * AV is modified, the primary port should also be modified).
1834 * Note that in this transition, the IB_QP_STATE flag
1837 if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1838 == (IB_QP_AV | IB_QP_PORT)) &&
1839 cmd->base.port_num != cmd->base.dest.port_num) {
1843 if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1845 cmd->base.attr_mask |= IB_QP_PORT;
1846 cmd->base.port_num = cmd->base.dest.port_num;
1851 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1852 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1853 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) ||
1854 cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) {
1859 if ((cmd->base.attr_mask & IB_QP_CUR_STATE &&
1860 cmd->base.cur_qp_state > IB_QPS_ERR) ||
1861 (cmd->base.attr_mask & IB_QP_STATE &&
1862 cmd->base.qp_state > IB_QPS_ERR)) {
1867 if (cmd->base.attr_mask & IB_QP_STATE)
1868 attr->qp_state = cmd->base.qp_state;
1869 if (cmd->base.attr_mask & IB_QP_CUR_STATE)
1870 attr->cur_qp_state = cmd->base.cur_qp_state;
1871 if (cmd->base.attr_mask & IB_QP_PATH_MTU)
1872 attr->path_mtu = cmd->base.path_mtu;
1873 if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE)
1874 attr->path_mig_state = cmd->base.path_mig_state;
1875 if (cmd->base.attr_mask & IB_QP_QKEY)
1876 attr->qkey = cmd->base.qkey;
1877 if (cmd->base.attr_mask & IB_QP_RQ_PSN)
1878 attr->rq_psn = cmd->base.rq_psn;
1879 if (cmd->base.attr_mask & IB_QP_SQ_PSN)
1880 attr->sq_psn = cmd->base.sq_psn;
1881 if (cmd->base.attr_mask & IB_QP_DEST_QPN)
1882 attr->dest_qp_num = cmd->base.dest_qp_num;
1883 if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS)
1884 attr->qp_access_flags = cmd->base.qp_access_flags;
1885 if (cmd->base.attr_mask & IB_QP_PKEY_INDEX)
1886 attr->pkey_index = cmd->base.pkey_index;
1887 if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
1888 attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify;
1889 if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1890 attr->max_rd_atomic = cmd->base.max_rd_atomic;
1891 if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1892 attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic;
1893 if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER)
1894 attr->min_rnr_timer = cmd->base.min_rnr_timer;
1895 if (cmd->base.attr_mask & IB_QP_PORT)
1896 attr->port_num = cmd->base.port_num;
1897 if (cmd->base.attr_mask & IB_QP_TIMEOUT)
1898 attr->timeout = cmd->base.timeout;
1899 if (cmd->base.attr_mask & IB_QP_RETRY_CNT)
1900 attr->retry_cnt = cmd->base.retry_cnt;
1901 if (cmd->base.attr_mask & IB_QP_RNR_RETRY)
1902 attr->rnr_retry = cmd->base.rnr_retry;
1903 if (cmd->base.attr_mask & IB_QP_ALT_PATH) {
1904 attr->alt_port_num = cmd->base.alt_port_num;
1905 attr->alt_timeout = cmd->base.alt_timeout;
1906 attr->alt_pkey_index = cmd->base.alt_pkey_index;
1908 if (cmd->base.attr_mask & IB_QP_RATE_LIMIT)
1909 attr->rate_limit = cmd->rate_limit;
1911 if (cmd->base.attr_mask & IB_QP_AV)
1912 copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr,
1915 if (cmd->base.attr_mask & IB_QP_ALT_PATH)
1916 copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr,
1917 &cmd->base.alt_dest);
1919 ret = ib_modify_qp_with_udata(qp, attr,
1920 modify_qp_mask(qp->qp_type,
1921 cmd->base.attr_mask),
1922 &attrs->driver_udata);
1925 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1926 UVERBS_LOOKUP_READ);
1933 static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs)
1935 struct ib_uverbs_ex_modify_qp cmd;
1938 ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base));
1942 if (cmd.base.attr_mask &
1943 ~((IB_USER_LEGACY_LAST_QP_ATTR_MASK << 1) - 1))
1946 return modify_qp(attrs, &cmd);
1949 static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)
1951 struct ib_uverbs_ex_modify_qp cmd;
1952 struct ib_uverbs_ex_modify_qp_resp resp = {
1953 .response_length = uverbs_response_length(attrs, sizeof(resp))
1957 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1962 * Last bit is reserved for extending the attr_mask by
1963 * using another field.
1965 BUILD_BUG_ON(IB_USER_LAST_QP_ATTR_MASK == (1 << 31));
1967 if (cmd.base.attr_mask &
1968 ~((IB_USER_LAST_QP_ATTR_MASK << 1) - 1))
1971 ret = modify_qp(attrs, &cmd);
1975 return uverbs_response(attrs, &resp, sizeof(resp));
1978 static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs)
1980 struct ib_uverbs_destroy_qp cmd;
1981 struct ib_uverbs_destroy_qp_resp resp;
1982 struct ib_uobject *uobj;
1983 struct ib_uqp_object *obj;
1986 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1990 uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1992 return PTR_ERR(uobj);
1994 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1995 memset(&resp, 0, sizeof(resp));
1996 resp.events_reported = obj->uevent.events_reported;
1998 uobj_put_destroy(uobj);
2000 return uverbs_response(attrs, &resp, sizeof(resp));
2003 static void *alloc_wr(size_t wr_size, __u32 num_sge)
2005 if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof (struct ib_sge))) /
2006 sizeof (struct ib_sge))
2009 return kmalloc(ALIGN(wr_size, sizeof (struct ib_sge)) +
2010 num_sge * sizeof (struct ib_sge), GFP_KERNEL);
2013 static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
2015 struct ib_uverbs_post_send cmd;
2016 struct ib_uverbs_post_send_resp resp;
2017 struct ib_uverbs_send_wr *user_wr;
2018 struct ib_send_wr *wr = NULL, *last, *next;
2019 const struct ib_send_wr *bad_wr;
2025 const struct ib_sge __user *sgls;
2026 const void __user *wqes;
2027 struct uverbs_req_iter iter;
2029 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2032 wqes = uverbs_request_next_ptr(&iter, cmd.wqe_size * cmd.wr_count);
2034 return PTR_ERR(wqes);
2035 sgls = uverbs_request_next_ptr(
2036 &iter, cmd.sge_count * sizeof(struct ib_uverbs_sge));
2038 return PTR_ERR(sgls);
2039 ret = uverbs_request_finish(&iter);
2043 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
2047 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2053 is_ud = qp->qp_type == IB_QPT_UD;
2056 for (i = 0; i < cmd.wr_count; ++i) {
2057 if (copy_from_user(user_wr, wqes + i * cmd.wqe_size,
2063 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
2069 struct ib_ud_wr *ud;
2071 if (user_wr->opcode != IB_WR_SEND &&
2072 user_wr->opcode != IB_WR_SEND_WITH_IMM) {
2077 next_size = sizeof(*ud);
2078 ud = alloc_wr(next_size, user_wr->num_sge);
2084 ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH,
2085 user_wr->wr.ud.ah, attrs);
2091 ud->remote_qpn = user_wr->wr.ud.remote_qpn;
2092 ud->remote_qkey = user_wr->wr.ud.remote_qkey;
2095 } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
2096 user_wr->opcode == IB_WR_RDMA_WRITE ||
2097 user_wr->opcode == IB_WR_RDMA_READ) {
2098 struct ib_rdma_wr *rdma;
2100 next_size = sizeof(*rdma);
2101 rdma = alloc_wr(next_size, user_wr->num_sge);
2107 rdma->remote_addr = user_wr->wr.rdma.remote_addr;
2108 rdma->rkey = user_wr->wr.rdma.rkey;
2111 } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
2112 user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
2113 struct ib_atomic_wr *atomic;
2115 next_size = sizeof(*atomic);
2116 atomic = alloc_wr(next_size, user_wr->num_sge);
2122 atomic->remote_addr = user_wr->wr.atomic.remote_addr;
2123 atomic->compare_add = user_wr->wr.atomic.compare_add;
2124 atomic->swap = user_wr->wr.atomic.swap;
2125 atomic->rkey = user_wr->wr.atomic.rkey;
2128 } else if (user_wr->opcode == IB_WR_SEND ||
2129 user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2130 user_wr->opcode == IB_WR_SEND_WITH_INV) {
2131 next_size = sizeof(*next);
2132 next = alloc_wr(next_size, user_wr->num_sge);
2142 if (user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2143 user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
2145 (__be32 __force) user_wr->ex.imm_data;
2146 } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) {
2147 next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey;
2157 next->wr_id = user_wr->wr_id;
2158 next->num_sge = user_wr->num_sge;
2159 next->opcode = user_wr->opcode;
2160 next->send_flags = user_wr->send_flags;
2162 if (next->num_sge) {
2163 next->sg_list = (void *) next +
2164 ALIGN(next_size, sizeof(struct ib_sge));
2165 if (copy_from_user(next->sg_list, sgls + sg_ind,
2167 sizeof(struct ib_sge))) {
2171 sg_ind += next->num_sge;
2173 next->sg_list = NULL;
2177 ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr);
2179 for (next = wr; next; next = next->next) {
2185 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2190 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2191 UVERBS_LOOKUP_READ);
2194 if (is_ud && ud_wr(wr)->ah)
2195 uobj_put_obj_read(ud_wr(wr)->ah);
2207 static struct ib_recv_wr *
2208 ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count,
2209 u32 wqe_size, u32 sge_count)
2211 struct ib_uverbs_recv_wr *user_wr;
2212 struct ib_recv_wr *wr = NULL, *last, *next;
2216 const struct ib_sge __user *sgls;
2217 const void __user *wqes;
2219 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
2220 return ERR_PTR(-EINVAL);
2222 wqes = uverbs_request_next_ptr(iter, wqe_size * wr_count);
2224 return ERR_CAST(wqes);
2225 sgls = uverbs_request_next_ptr(
2226 iter, sge_count * sizeof(struct ib_uverbs_sge));
2228 return ERR_CAST(sgls);
2229 ret = uverbs_request_finish(iter);
2231 return ERR_PTR(ret);
2233 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2235 return ERR_PTR(-ENOMEM);
2239 for (i = 0; i < wr_count; ++i) {
2240 if (copy_from_user(user_wr, wqes + i * wqe_size,
2246 if (user_wr->num_sge + sg_ind > sge_count) {
2251 if (user_wr->num_sge >=
2252 (U32_MAX - ALIGN(sizeof *next, sizeof (struct ib_sge))) /
2253 sizeof (struct ib_sge)) {
2258 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
2259 user_wr->num_sge * sizeof (struct ib_sge),
2273 next->wr_id = user_wr->wr_id;
2274 next->num_sge = user_wr->num_sge;
2276 if (next->num_sge) {
2277 next->sg_list = (void *) next +
2278 ALIGN(sizeof *next, sizeof (struct ib_sge));
2279 if (copy_from_user(next->sg_list, sgls + sg_ind,
2281 sizeof(struct ib_sge))) {
2285 sg_ind += next->num_sge;
2287 next->sg_list = NULL;
2302 return ERR_PTR(ret);
2305 static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
2307 struct ib_uverbs_post_recv cmd;
2308 struct ib_uverbs_post_recv_resp resp;
2309 struct ib_recv_wr *wr, *next;
2310 const struct ib_recv_wr *bad_wr;
2313 struct uverbs_req_iter iter;
2315 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2319 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2324 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2331 ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
2333 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2334 UVERBS_LOOKUP_READ);
2336 for (next = wr; next; next = next->next) {
2343 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2356 static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs)
2358 struct ib_uverbs_post_srq_recv cmd;
2359 struct ib_uverbs_post_srq_recv_resp resp;
2360 struct ib_recv_wr *wr, *next;
2361 const struct ib_recv_wr *bad_wr;
2364 struct uverbs_req_iter iter;
2366 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2370 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2375 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
2382 ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr);
2384 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
2385 UVERBS_LOOKUP_READ);
2388 for (next = wr; next; next = next->next) {
2394 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2408 static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
2410 struct ib_uverbs_create_ah cmd;
2411 struct ib_uverbs_create_ah_resp resp;
2412 struct ib_uobject *uobj;
2415 struct rdma_ah_attr attr = {};
2417 struct ib_device *ib_dev;
2419 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2423 uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev);
2425 return PTR_ERR(uobj);
2427 if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
2432 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2438 attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
2439 rdma_ah_set_make_grd(&attr, false);
2440 rdma_ah_set_dlid(&attr, cmd.attr.dlid);
2441 rdma_ah_set_sl(&attr, cmd.attr.sl);
2442 rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
2443 rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
2444 rdma_ah_set_port_num(&attr, cmd.attr.port_num);
2446 if (cmd.attr.is_global) {
2447 rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
2448 cmd.attr.grh.sgid_index,
2449 cmd.attr.grh.hop_limit,
2450 cmd.attr.grh.traffic_class);
2451 rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
2453 rdma_ah_set_ah_flags(&attr, 0);
2456 ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
2463 uobj->user_handle = cmd.user_handle;
2466 resp.ah_handle = uobj->id;
2468 ret = uverbs_response(attrs, &resp, sizeof(resp));
2472 uobj_put_obj_read(pd);
2473 rdma_alloc_commit_uobject(uobj, attrs);
2477 rdma_destroy_ah_user(ah, RDMA_DESTROY_AH_SLEEPABLE,
2478 uverbs_get_cleared_udata(attrs));
2481 uobj_put_obj_read(pd);
2484 uobj_alloc_abort(uobj, attrs);
2488 static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs)
2490 struct ib_uverbs_destroy_ah cmd;
2493 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2497 return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs);
2500 static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs)
2502 struct ib_uverbs_attach_mcast cmd;
2504 struct ib_uqp_object *obj;
2505 struct ib_uverbs_mcast_entry *mcast;
2508 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2512 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2518 mutex_lock(&obj->mcast_lock);
2519 list_for_each_entry(mcast, &obj->mcast_list, list)
2520 if (cmd.mlid == mcast->lid &&
2521 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2526 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2532 mcast->lid = cmd.mlid;
2533 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2535 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2537 list_add_tail(&mcast->list, &obj->mcast_list);
2542 mutex_unlock(&obj->mcast_lock);
2543 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2544 UVERBS_LOOKUP_READ);
2549 static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs)
2551 struct ib_uverbs_detach_mcast cmd;
2552 struct ib_uqp_object *obj;
2554 struct ib_uverbs_mcast_entry *mcast;
2558 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2562 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2567 mutex_lock(&obj->mcast_lock);
2569 list_for_each_entry(mcast, &obj->mcast_list, list)
2570 if (cmd.mlid == mcast->lid &&
2571 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2572 list_del(&mcast->list);
2583 ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2586 mutex_unlock(&obj->mcast_lock);
2587 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2588 UVERBS_LOOKUP_READ);
2592 struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2594 struct ib_uflow_resources *resources;
2596 resources = kzalloc(sizeof(*resources), GFP_KERNEL);
2604 resources->counters =
2605 kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
2606 resources->collection =
2607 kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL);
2609 if (!resources->counters || !resources->collection)
2613 resources->max = num_specs;
2617 kfree(resources->counters);
2622 EXPORT_SYMBOL(flow_resources_alloc);
2624 void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2631 for (i = 0; i < uflow_res->collection_num; i++)
2632 atomic_dec(&uflow_res->collection[i]->usecnt);
2634 for (i = 0; i < uflow_res->counters_num; i++)
2635 atomic_dec(&uflow_res->counters[i]->usecnt);
2637 kfree(uflow_res->collection);
2638 kfree(uflow_res->counters);
2641 EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2643 void flow_resources_add(struct ib_uflow_resources *uflow_res,
2644 enum ib_flow_spec_type type,
2647 WARN_ON(uflow_res->num >= uflow_res->max);
2650 case IB_FLOW_SPEC_ACTION_HANDLE:
2651 atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt);
2652 uflow_res->collection[uflow_res->collection_num++] =
2653 (struct ib_flow_action *)ibobj;
2655 case IB_FLOW_SPEC_ACTION_COUNT:
2656 atomic_inc(&((struct ib_counters *)ibobj)->usecnt);
2657 uflow_res->counters[uflow_res->counters_num++] =
2658 (struct ib_counters *)ibobj;
2666 EXPORT_SYMBOL(flow_resources_add);
2668 static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
2669 struct ib_uverbs_flow_spec *kern_spec,
2670 union ib_flow_spec *ib_spec,
2671 struct ib_uflow_resources *uflow_res)
2673 ib_spec->type = kern_spec->type;
2674 switch (ib_spec->type) {
2675 case IB_FLOW_SPEC_ACTION_TAG:
2676 if (kern_spec->flow_tag.size !=
2677 sizeof(struct ib_uverbs_flow_spec_action_tag))
2680 ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
2681 ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
2683 case IB_FLOW_SPEC_ACTION_DROP:
2684 if (kern_spec->drop.size !=
2685 sizeof(struct ib_uverbs_flow_spec_action_drop))
2688 ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop);
2690 case IB_FLOW_SPEC_ACTION_HANDLE:
2691 if (kern_spec->action.size !=
2692 sizeof(struct ib_uverbs_flow_spec_action_handle))
2694 ib_spec->action.act = uobj_get_obj_read(flow_action,
2695 UVERBS_OBJECT_FLOW_ACTION,
2696 kern_spec->action.handle,
2698 if (!ib_spec->action.act)
2700 ib_spec->action.size =
2701 sizeof(struct ib_flow_spec_action_handle);
2702 flow_resources_add(uflow_res,
2703 IB_FLOW_SPEC_ACTION_HANDLE,
2704 ib_spec->action.act);
2705 uobj_put_obj_read(ib_spec->action.act);
2707 case IB_FLOW_SPEC_ACTION_COUNT:
2708 if (kern_spec->flow_count.size !=
2709 sizeof(struct ib_uverbs_flow_spec_action_count))
2711 ib_spec->flow_count.counters =
2712 uobj_get_obj_read(counters,
2713 UVERBS_OBJECT_COUNTERS,
2714 kern_spec->flow_count.handle,
2716 if (!ib_spec->flow_count.counters)
2718 ib_spec->flow_count.size =
2719 sizeof(struct ib_flow_spec_action_count);
2720 flow_resources_add(uflow_res,
2721 IB_FLOW_SPEC_ACTION_COUNT,
2722 ib_spec->flow_count.counters);
2723 uobj_put_obj_read(ib_spec->flow_count.counters);
2731 static size_t kern_spec_filter_sz(const struct ib_uverbs_flow_spec_hdr *spec)
2733 /* Returns user space filter size, includes padding */
2734 return (spec->size - sizeof(struct ib_uverbs_flow_spec_hdr)) / 2;
2737 static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size,
2738 u16 ib_real_filter_sz)
2741 * User space filter structures must be 64 bit aligned, otherwise this
2742 * may pass, but we won't handle additional new attributes.
2745 if (kern_filter_size > ib_real_filter_sz) {
2746 if (memchr_inv(kern_spec_filter +
2747 ib_real_filter_sz, 0,
2748 kern_filter_size - ib_real_filter_sz))
2750 return ib_real_filter_sz;
2752 return kern_filter_size;
2755 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
2756 const void *kern_spec_mask,
2757 const void *kern_spec_val,
2758 size_t kern_filter_sz,
2759 union ib_flow_spec *ib_spec)
2761 ssize_t actual_filter_sz;
2762 ssize_t ib_filter_sz;
2764 /* User flow spec size must be aligned to 4 bytes */
2765 if (kern_filter_sz != ALIGN(kern_filter_sz, 4))
2768 ib_spec->type = type;
2770 if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL))
2773 switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) {
2774 case IB_FLOW_SPEC_ETH:
2775 ib_filter_sz = offsetof(struct ib_flow_eth_filter, real_sz);
2776 actual_filter_sz = spec_filter_size(kern_spec_mask,
2779 if (actual_filter_sz <= 0)
2781 ib_spec->size = sizeof(struct ib_flow_spec_eth);
2782 memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz);
2783 memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz);
2785 case IB_FLOW_SPEC_IPV4:
2786 ib_filter_sz = offsetof(struct ib_flow_ipv4_filter, real_sz);
2787 actual_filter_sz = spec_filter_size(kern_spec_mask,
2790 if (actual_filter_sz <= 0)
2792 ib_spec->size = sizeof(struct ib_flow_spec_ipv4);
2793 memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz);
2794 memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz);
2796 case IB_FLOW_SPEC_IPV6:
2797 ib_filter_sz = offsetof(struct ib_flow_ipv6_filter, real_sz);
2798 actual_filter_sz = spec_filter_size(kern_spec_mask,
2801 if (actual_filter_sz <= 0)
2803 ib_spec->size = sizeof(struct ib_flow_spec_ipv6);
2804 memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz);
2805 memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz);
2807 if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) ||
2808 (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20))
2811 case IB_FLOW_SPEC_TCP:
2812 case IB_FLOW_SPEC_UDP:
2813 ib_filter_sz = offsetof(struct ib_flow_tcp_udp_filter, real_sz);
2814 actual_filter_sz = spec_filter_size(kern_spec_mask,
2817 if (actual_filter_sz <= 0)
2819 ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp);
2820 memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz);
2821 memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz);
2823 case IB_FLOW_SPEC_VXLAN_TUNNEL:
2824 ib_filter_sz = offsetof(struct ib_flow_tunnel_filter, real_sz);
2825 actual_filter_sz = spec_filter_size(kern_spec_mask,
2828 if (actual_filter_sz <= 0)
2830 ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel);
2831 memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz);
2832 memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz);
2834 if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) ||
2835 (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24))
2838 case IB_FLOW_SPEC_ESP:
2839 ib_filter_sz = offsetof(struct ib_flow_esp_filter, real_sz);
2840 actual_filter_sz = spec_filter_size(kern_spec_mask,
2843 if (actual_filter_sz <= 0)
2845 ib_spec->esp.size = sizeof(struct ib_flow_spec_esp);
2846 memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz);
2847 memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz);
2849 case IB_FLOW_SPEC_GRE:
2850 ib_filter_sz = offsetof(struct ib_flow_gre_filter, real_sz);
2851 actual_filter_sz = spec_filter_size(kern_spec_mask,
2854 if (actual_filter_sz <= 0)
2856 ib_spec->gre.size = sizeof(struct ib_flow_spec_gre);
2857 memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz);
2858 memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz);
2860 case IB_FLOW_SPEC_MPLS:
2861 ib_filter_sz = offsetof(struct ib_flow_mpls_filter, real_sz);
2862 actual_filter_sz = spec_filter_size(kern_spec_mask,
2865 if (actual_filter_sz <= 0)
2867 ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls);
2868 memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz);
2869 memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz);
2877 static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
2878 union ib_flow_spec *ib_spec)
2880 ssize_t kern_filter_sz;
2881 void *kern_spec_mask;
2882 void *kern_spec_val;
2884 kern_filter_sz = kern_spec_filter_sz(&kern_spec->hdr);
2886 kern_spec_val = (void *)kern_spec +
2887 sizeof(struct ib_uverbs_flow_spec_hdr);
2888 kern_spec_mask = kern_spec_val + kern_filter_sz;
2890 return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type,
2893 kern_filter_sz, ib_spec);
2896 static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs,
2897 struct ib_uverbs_flow_spec *kern_spec,
2898 union ib_flow_spec *ib_spec,
2899 struct ib_uflow_resources *uflow_res)
2901 if (kern_spec->reserved)
2904 if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
2905 return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec,
2908 return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
2911 static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs)
2913 struct ib_uverbs_ex_create_wq cmd;
2914 struct ib_uverbs_ex_create_wq_resp resp = {};
2915 struct ib_uwq_object *obj;
2920 struct ib_wq_init_attr wq_init_attr = {};
2921 struct ib_device *ib_dev;
2923 err = uverbs_request(attrs, &cmd, sizeof(cmd));
2930 obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs,
2933 return PTR_ERR(obj);
2935 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2941 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
2947 wq_init_attr.cq = cq;
2948 wq_init_attr.max_sge = cmd.max_sge;
2949 wq_init_attr.max_wr = cmd.max_wr;
2950 wq_init_attr.wq_context = attrs->ufile;
2951 wq_init_attr.wq_type = cmd.wq_type;
2952 wq_init_attr.event_handler = ib_uverbs_wq_event_handler;
2953 wq_init_attr.create_flags = cmd.create_flags;
2954 INIT_LIST_HEAD(&obj->uevent.event_list);
2956 wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata);
2963 obj->uevent.uobject.object = wq;
2964 wq->wq_type = wq_init_attr.wq_type;
2967 wq->device = pd->device;
2968 wq->wq_context = wq_init_attr.wq_context;
2969 atomic_set(&wq->usecnt, 0);
2970 atomic_inc(&pd->usecnt);
2971 atomic_inc(&cq->usecnt);
2973 obj->uevent.uobject.object = wq;
2975 memset(&resp, 0, sizeof(resp));
2976 resp.wq_handle = obj->uevent.uobject.id;
2977 resp.max_sge = wq_init_attr.max_sge;
2978 resp.max_wr = wq_init_attr.max_wr;
2979 resp.wqn = wq->wq_num;
2980 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2981 err = uverbs_response(attrs, &resp, sizeof(resp));
2985 uobj_put_obj_read(pd);
2986 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2987 UVERBS_LOOKUP_READ);
2988 rdma_alloc_commit_uobject(&obj->uevent.uobject, attrs);
2992 ib_destroy_wq(wq, uverbs_get_cleared_udata(attrs));
2994 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2995 UVERBS_LOOKUP_READ);
2997 uobj_put_obj_read(pd);
2999 uobj_alloc_abort(&obj->uevent.uobject, attrs);
3004 static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs)
3006 struct ib_uverbs_ex_destroy_wq cmd;
3007 struct ib_uverbs_ex_destroy_wq_resp resp = {};
3008 struct ib_uobject *uobj;
3009 struct ib_uwq_object *obj;
3012 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3019 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3020 uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3022 return PTR_ERR(uobj);
3024 obj = container_of(uobj, struct ib_uwq_object, uevent.uobject);
3025 resp.events_reported = obj->uevent.events_reported;
3027 uobj_put_destroy(uobj);
3029 return uverbs_response(attrs, &resp, sizeof(resp));
3032 static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
3034 struct ib_uverbs_ex_modify_wq cmd;
3036 struct ib_wq_attr wq_attr = {};
3039 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3046 if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS))
3049 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3053 wq_attr.curr_wq_state = cmd.curr_wq_state;
3054 wq_attr.wq_state = cmd.wq_state;
3055 if (cmd.attr_mask & IB_WQ_FLAGS) {
3056 wq_attr.flags = cmd.flags;
3057 wq_attr.flags_mask = cmd.flags_mask;
3059 ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
3060 &attrs->driver_udata);
3061 rdma_lookup_put_uobject(&wq->uobject->uevent.uobject,
3062 UVERBS_LOOKUP_READ);
3066 static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3068 struct ib_uverbs_ex_create_rwq_ind_table cmd;
3069 struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
3070 struct ib_uobject *uobj;
3072 struct ib_rwq_ind_table_init_attr init_attr = {};
3073 struct ib_rwq_ind_table *rwq_ind_tbl;
3074 struct ib_wq **wqs = NULL;
3075 u32 *wqs_handles = NULL;
3076 struct ib_wq *wq = NULL;
3077 int i, j, num_read_wqs;
3079 struct uverbs_req_iter iter;
3080 struct ib_device *ib_dev;
3082 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3089 if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE)
3092 num_wq_handles = 1 << cmd.log_ind_tbl_size;
3093 wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles),
3098 err = uverbs_request_next(&iter, wqs_handles,
3099 num_wq_handles * sizeof(__u32));
3103 err = uverbs_request_finish(&iter);
3107 wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL);
3113 for (num_read_wqs = 0; num_read_wqs < num_wq_handles;
3115 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ,
3116 wqs_handles[num_read_wqs], attrs);
3122 wqs[num_read_wqs] = wq;
3125 uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev);
3127 err = PTR_ERR(uobj);
3131 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3132 init_attr.ind_tbl = wqs;
3134 rwq_ind_tbl = ib_dev->ops.create_rwq_ind_table(ib_dev, &init_attr,
3135 &attrs->driver_udata);
3137 if (IS_ERR(rwq_ind_tbl)) {
3138 err = PTR_ERR(rwq_ind_tbl);
3142 rwq_ind_tbl->ind_tbl = wqs;
3143 rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size;
3144 rwq_ind_tbl->uobject = uobj;
3145 uobj->object = rwq_ind_tbl;
3146 rwq_ind_tbl->device = ib_dev;
3147 atomic_set(&rwq_ind_tbl->usecnt, 0);
3149 for (i = 0; i < num_wq_handles; i++)
3150 atomic_inc(&wqs[i]->usecnt);
3152 resp.ind_tbl_handle = uobj->id;
3153 resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num;
3154 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3156 err = uverbs_response(attrs, &resp, sizeof(resp));
3162 for (j = 0; j < num_read_wqs; j++)
3163 rdma_lookup_put_uobject(&wqs[j]->uobject->uevent.uobject,
3164 UVERBS_LOOKUP_READ);
3166 rdma_alloc_commit_uobject(uobj, attrs);
3170 ib_destroy_rwq_ind_table(rwq_ind_tbl);
3172 uobj_alloc_abort(uobj, attrs);
3174 for (j = 0; j < num_read_wqs; j++)
3175 rdma_lookup_put_uobject(&wqs[j]->uobject->uevent.uobject,
3176 UVERBS_LOOKUP_READ);
3183 static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3185 struct ib_uverbs_ex_destroy_rwq_ind_table cmd;
3188 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3195 return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
3196 cmd.ind_tbl_handle, attrs);
3199 static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
3201 struct ib_uverbs_create_flow cmd;
3202 struct ib_uverbs_create_flow_resp resp;
3203 struct ib_uobject *uobj;
3204 struct ib_flow *flow_id;
3205 struct ib_uverbs_flow_attr *kern_flow_attr;
3206 struct ib_flow_attr *flow_attr;
3208 struct ib_uflow_resources *uflow_res;
3209 struct ib_uverbs_flow_spec_hdr *kern_spec;
3210 struct uverbs_req_iter iter;
3214 struct ib_device *ib_dev;
3216 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3223 if (!capable(CAP_NET_RAW))
3226 if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
3229 if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) &&
3230 ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) ||
3231 (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT)))
3234 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
3237 if (cmd.flow_attr.size >
3238 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
3241 if (cmd.flow_attr.reserved[0] ||
3242 cmd.flow_attr.reserved[1])
3245 if (cmd.flow_attr.num_of_specs) {
3246 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
3248 if (!kern_flow_attr)
3251 *kern_flow_attr = cmd.flow_attr;
3252 err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs,
3253 cmd.flow_attr.size);
3257 kern_flow_attr = &cmd.flow_attr;
3260 err = uverbs_request_finish(&iter);
3264 uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev);
3266 err = PTR_ERR(uobj);
3270 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
3276 if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) {
3281 flow_attr = kzalloc(struct_size(flow_attr, flows,
3282 cmd.flow_attr.num_of_specs), GFP_KERNEL);
3287 uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs);
3290 goto err_free_flow_attr;
3293 flow_attr->type = kern_flow_attr->type;
3294 flow_attr->priority = kern_flow_attr->priority;
3295 flow_attr->num_of_specs = kern_flow_attr->num_of_specs;
3296 flow_attr->port = kern_flow_attr->port;
3297 flow_attr->flags = kern_flow_attr->flags;
3298 flow_attr->size = sizeof(*flow_attr);
3300 kern_spec = kern_flow_attr->flow_specs;
3301 ib_spec = flow_attr + 1;
3302 for (i = 0; i < flow_attr->num_of_specs &&
3303 cmd.flow_attr.size >= sizeof(*kern_spec) &&
3304 cmd.flow_attr.size >= kern_spec->size;
3306 err = kern_spec_to_ib_spec(
3307 attrs, (struct ib_uverbs_flow_spec *)kern_spec,
3308 ib_spec, uflow_res);
3313 ((union ib_flow_spec *) ib_spec)->size;
3314 cmd.flow_attr.size -= kern_spec->size;
3315 kern_spec = ((void *)kern_spec) + kern_spec->size;
3316 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
3318 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
3319 pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
3320 i, cmd.flow_attr.size);
3325 flow_id = qp->device->ops.create_flow(
3326 qp, flow_attr, IB_FLOW_DOMAIN_USER, &attrs->driver_udata);
3328 if (IS_ERR(flow_id)) {
3329 err = PTR_ERR(flow_id);
3333 ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res);
3335 memset(&resp, 0, sizeof(resp));
3336 resp.flow_handle = uobj->id;
3338 err = uverbs_response(attrs, &resp, sizeof(resp));
3342 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3343 UVERBS_LOOKUP_READ);
3345 if (cmd.flow_attr.num_of_specs)
3346 kfree(kern_flow_attr);
3347 rdma_alloc_commit_uobject(uobj, attrs);
3350 if (!qp->device->ops.destroy_flow(flow_id))
3351 atomic_dec(&qp->usecnt);
3353 ib_uverbs_flow_resources_free(uflow_res);
3357 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3358 UVERBS_LOOKUP_READ);
3360 uobj_alloc_abort(uobj, attrs);
3362 if (cmd.flow_attr.num_of_specs)
3363 kfree(kern_flow_attr);
3367 static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs)
3369 struct ib_uverbs_destroy_flow cmd;
3372 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3379 return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs);
3382 static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs,
3383 struct ib_uverbs_create_xsrq *cmd,
3384 struct ib_udata *udata)
3386 struct ib_uverbs_create_srq_resp resp;
3387 struct ib_usrq_object *obj;
3390 struct ib_uobject *uninitialized_var(xrcd_uobj);
3391 struct ib_srq_init_attr attr;
3393 struct ib_device *ib_dev;
3395 obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs,
3398 return PTR_ERR(obj);
3400 if (cmd->srq_type == IB_SRQT_TM)
3401 attr.ext.tag_matching.max_num_tags = cmd->max_num_tags;
3403 if (cmd->srq_type == IB_SRQT_XRC) {
3404 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle,
3406 if (IS_ERR(xrcd_uobj)) {
3411 attr.ext.xrc.xrcd = (struct ib_xrcd *)xrcd_uobj->object;
3412 if (!attr.ext.xrc.xrcd) {
3417 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
3418 atomic_inc(&obj->uxrcd->refcnt);
3421 if (ib_srq_has_cq(cmd->srq_type)) {
3422 attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
3423 cmd->cq_handle, attrs);
3430 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs);
3436 attr.event_handler = ib_uverbs_srq_event_handler;
3437 attr.srq_context = attrs->ufile;
3438 attr.srq_type = cmd->srq_type;
3439 attr.attr.max_wr = cmd->max_wr;
3440 attr.attr.max_sge = cmd->max_sge;
3441 attr.attr.srq_limit = cmd->srq_limit;
3443 INIT_LIST_HEAD(&obj->uevent.event_list);
3445 srq = rdma_zalloc_drv_obj(ib_dev, ib_srq);
3451 srq->device = pd->device;
3453 srq->srq_type = cmd->srq_type;
3455 srq->event_handler = attr.event_handler;
3456 srq->srq_context = attr.srq_context;
3458 ret = pd->device->ops.create_srq(srq, &attr, udata);
3462 if (ib_srq_has_cq(cmd->srq_type)) {
3463 srq->ext.cq = attr.ext.cq;
3464 atomic_inc(&attr.ext.cq->usecnt);
3467 if (cmd->srq_type == IB_SRQT_XRC) {
3468 srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
3469 atomic_inc(&attr.ext.xrc.xrcd->usecnt);
3472 atomic_inc(&pd->usecnt);
3473 atomic_set(&srq->usecnt, 0);
3475 obj->uevent.uobject.object = srq;
3476 obj->uevent.uobject.user_handle = cmd->user_handle;
3478 memset(&resp, 0, sizeof resp);
3479 resp.srq_handle = obj->uevent.uobject.id;
3480 resp.max_wr = attr.attr.max_wr;
3481 resp.max_sge = attr.attr.max_sge;
3482 if (cmd->srq_type == IB_SRQT_XRC)
3483 resp.srqn = srq->ext.xrc.srq_num;
3485 ret = uverbs_response(attrs, &resp, sizeof(resp));
3489 if (cmd->srq_type == IB_SRQT_XRC)
3490 uobj_put_read(xrcd_uobj);
3492 if (ib_srq_has_cq(cmd->srq_type))
3493 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3494 UVERBS_LOOKUP_READ);
3496 uobj_put_obj_read(pd);
3497 rdma_alloc_commit_uobject(&obj->uevent.uobject, attrs);
3501 ib_destroy_srq_user(srq, uverbs_get_cleared_udata(attrs));
3502 /* It was released in ib_destroy_srq_user */
3507 uobj_put_obj_read(pd);
3510 if (ib_srq_has_cq(cmd->srq_type))
3511 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3512 UVERBS_LOOKUP_READ);
3515 if (cmd->srq_type == IB_SRQT_XRC) {
3516 atomic_dec(&obj->uxrcd->refcnt);
3517 uobj_put_read(xrcd_uobj);
3521 uobj_alloc_abort(&obj->uevent.uobject, attrs);
3525 static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs)
3527 struct ib_uverbs_create_srq cmd;
3528 struct ib_uverbs_create_xsrq xcmd;
3531 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3535 memset(&xcmd, 0, sizeof(xcmd));
3536 xcmd.response = cmd.response;
3537 xcmd.user_handle = cmd.user_handle;
3538 xcmd.srq_type = IB_SRQT_BASIC;
3539 xcmd.pd_handle = cmd.pd_handle;
3540 xcmd.max_wr = cmd.max_wr;
3541 xcmd.max_sge = cmd.max_sge;
3542 xcmd.srq_limit = cmd.srq_limit;
3544 return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata);
3547 static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs)
3549 struct ib_uverbs_create_xsrq cmd;
3552 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3556 return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata);
3559 static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs)
3561 struct ib_uverbs_modify_srq cmd;
3563 struct ib_srq_attr attr;
3566 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3570 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3574 attr.max_wr = cmd.max_wr;
3575 attr.srq_limit = cmd.srq_limit;
3577 ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask,
3578 &attrs->driver_udata);
3580 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3581 UVERBS_LOOKUP_READ);
3586 static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs)
3588 struct ib_uverbs_query_srq cmd;
3589 struct ib_uverbs_query_srq_resp resp;
3590 struct ib_srq_attr attr;
3594 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3598 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3602 ret = ib_query_srq(srq, &attr);
3604 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3605 UVERBS_LOOKUP_READ);
3610 memset(&resp, 0, sizeof resp);
3612 resp.max_wr = attr.max_wr;
3613 resp.max_sge = attr.max_sge;
3614 resp.srq_limit = attr.srq_limit;
3616 return uverbs_response(attrs, &resp, sizeof(resp));
3619 static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs)
3621 struct ib_uverbs_destroy_srq cmd;
3622 struct ib_uverbs_destroy_srq_resp resp;
3623 struct ib_uobject *uobj;
3624 struct ib_uevent_object *obj;
3627 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3631 uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3633 return PTR_ERR(uobj);
3635 obj = container_of(uobj, struct ib_uevent_object, uobject);
3636 memset(&resp, 0, sizeof(resp));
3637 resp.events_reported = obj->events_reported;
3639 uobj_put_destroy(uobj);
3641 return uverbs_response(attrs, &resp, sizeof(resp));
3644 static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
3646 struct ib_uverbs_ex_query_device_resp resp = {};
3647 struct ib_uverbs_ex_query_device cmd;
3648 struct ib_device_attr attr = {0};
3649 struct ib_ucontext *ucontext;
3650 struct ib_device *ib_dev;
3653 ucontext = ib_uverbs_get_ucontext(attrs);
3654 if (IS_ERR(ucontext))
3655 return PTR_ERR(ucontext);
3656 ib_dev = ucontext->device;
3658 err = uverbs_request(attrs, &cmd, sizeof(cmd));
3668 err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata);
3672 copy_query_dev_fields(ucontext, &resp.base, &attr);
3674 resp.odp_caps.general_caps = attr.odp_caps.general_caps;
3675 resp.odp_caps.per_transport_caps.rc_odp_caps =
3676 attr.odp_caps.per_transport_caps.rc_odp_caps;
3677 resp.odp_caps.per_transport_caps.uc_odp_caps =
3678 attr.odp_caps.per_transport_caps.uc_odp_caps;
3679 resp.odp_caps.per_transport_caps.ud_odp_caps =
3680 attr.odp_caps.per_transport_caps.ud_odp_caps;
3681 resp.xrc_odp_caps = attr.odp_caps.per_transport_caps.xrc_odp_caps;
3683 resp.timestamp_mask = attr.timestamp_mask;
3684 resp.hca_core_clock = attr.hca_core_clock;
3685 resp.device_cap_flags_ex = attr.device_cap_flags;
3686 resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts;
3687 resp.rss_caps.max_rwq_indirection_tables =
3688 attr.rss_caps.max_rwq_indirection_tables;
3689 resp.rss_caps.max_rwq_indirection_table_size =
3690 attr.rss_caps.max_rwq_indirection_table_size;
3691 resp.max_wq_type_rq = attr.max_wq_type_rq;
3692 resp.raw_packet_caps = attr.raw_packet_caps;
3693 resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size;
3694 resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags;
3695 resp.tm_caps.max_ops = attr.tm_caps.max_ops;
3696 resp.tm_caps.max_sge = attr.tm_caps.max_sge;
3697 resp.tm_caps.flags = attr.tm_caps.flags;
3698 resp.cq_moderation_caps.max_cq_moderation_count =
3699 attr.cq_caps.max_cq_moderation_count;
3700 resp.cq_moderation_caps.max_cq_moderation_period =
3701 attr.cq_caps.max_cq_moderation_period;
3702 resp.max_dm_size = attr.max_dm_size;
3703 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3705 return uverbs_response(attrs, &resp, sizeof(resp));
3708 static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs)
3710 struct ib_uverbs_ex_modify_cq cmd;
3714 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3718 if (!cmd.attr_mask || cmd.reserved)
3721 if (cmd.attr_mask > IB_CQ_MODERATE)
3724 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
3728 ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period);
3730 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
3731 UVERBS_LOOKUP_READ);
3736 * Describe the input structs for write(). Some write methods have an input
3737 * only struct, most have an input and output. If the struct has an output then
3738 * the 'response' u64 must be the first field in the request structure.
3740 * If udata is present then both the request and response structs have a
3741 * trailing driver_data flex array. In this case the size of the base struct
3742 * cannot be changed.
3744 #define UAPI_DEF_WRITE_IO(req, resp) \
3745 .write.has_resp = 1 + \
3746 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \
3747 BUILD_BUG_ON_ZERO(sizeof(((req *)0)->response) != \
3749 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp)
3751 #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req)
3753 #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \
3754 UAPI_DEF_WRITE_IO(req, resp), \
3755 .write.has_udata = \
3757 BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3759 BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \
3762 #define UAPI_DEF_WRITE_UDATA_I(req) \
3763 UAPI_DEF_WRITE_I(req), \
3764 .write.has_udata = \
3765 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3769 * The _EX versions are for use with WRITE_EX and allow the last struct member
3770 * to be specified. Buffers that do not include that member will be rejected.
3772 #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \
3773 .write.has_resp = 1, \
3774 .write.req_size = offsetofend(req, req_last_member), \
3775 .write.resp_size = offsetofend(resp, resp_last_member)
3777 #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \
3778 .write.req_size = offsetofend(req, req_last_member)
3780 const struct uapi_definition uverbs_def_write_intf[] = {
3781 DECLARE_UVERBS_OBJECT(
3783 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH,
3784 ib_uverbs_create_ah,
3785 UAPI_DEF_WRITE_UDATA_IO(
3786 struct ib_uverbs_create_ah,
3787 struct ib_uverbs_create_ah_resp),
3788 UAPI_DEF_METHOD_NEEDS_FN(create_ah)),
3789 DECLARE_UVERBS_WRITE(
3790 IB_USER_VERBS_CMD_DESTROY_AH,
3791 ib_uverbs_destroy_ah,
3792 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah),
3793 UAPI_DEF_METHOD_NEEDS_FN(destroy_ah))),
3795 DECLARE_UVERBS_OBJECT(
3796 UVERBS_OBJECT_COMP_CHANNEL,
3797 DECLARE_UVERBS_WRITE(
3798 IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
3799 ib_uverbs_create_comp_channel,
3801 struct ib_uverbs_create_comp_channel,
3802 struct ib_uverbs_create_comp_channel_resp))),
3804 DECLARE_UVERBS_OBJECT(
3806 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ,
3807 ib_uverbs_create_cq,
3808 UAPI_DEF_WRITE_UDATA_IO(
3809 struct ib_uverbs_create_cq,
3810 struct ib_uverbs_create_cq_resp),
3811 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3812 DECLARE_UVERBS_WRITE(
3813 IB_USER_VERBS_CMD_DESTROY_CQ,
3814 ib_uverbs_destroy_cq,
3815 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq,
3816 struct ib_uverbs_destroy_cq_resp),
3817 UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)),
3818 DECLARE_UVERBS_WRITE(
3819 IB_USER_VERBS_CMD_POLL_CQ,
3821 UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq,
3822 struct ib_uverbs_poll_cq_resp),
3823 UAPI_DEF_METHOD_NEEDS_FN(poll_cq)),
3824 DECLARE_UVERBS_WRITE(
3825 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
3826 ib_uverbs_req_notify_cq,
3827 UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq),
3828 UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)),
3829 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ,
3830 ib_uverbs_resize_cq,
3831 UAPI_DEF_WRITE_UDATA_IO(
3832 struct ib_uverbs_resize_cq,
3833 struct ib_uverbs_resize_cq_resp),
3834 UAPI_DEF_METHOD_NEEDS_FN(resize_cq)),
3835 DECLARE_UVERBS_WRITE_EX(
3836 IB_USER_VERBS_EX_CMD_CREATE_CQ,
3837 ib_uverbs_ex_create_cq,
3838 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq,
3840 struct ib_uverbs_ex_create_cq_resp,
3842 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3843 DECLARE_UVERBS_WRITE_EX(
3844 IB_USER_VERBS_EX_CMD_MODIFY_CQ,
3845 ib_uverbs_ex_modify_cq,
3846 UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq),
3847 UAPI_DEF_METHOD_NEEDS_FN(create_cq))),
3849 DECLARE_UVERBS_OBJECT(
3850 UVERBS_OBJECT_DEVICE,
3851 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT,
3852 ib_uverbs_get_context,
3853 UAPI_DEF_WRITE_UDATA_IO(
3854 struct ib_uverbs_get_context,
3855 struct ib_uverbs_get_context_resp)),
3856 DECLARE_UVERBS_WRITE(
3857 IB_USER_VERBS_CMD_QUERY_DEVICE,
3858 ib_uverbs_query_device,
3859 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device,
3860 struct ib_uverbs_query_device_resp)),
3861 DECLARE_UVERBS_WRITE(
3862 IB_USER_VERBS_CMD_QUERY_PORT,
3863 ib_uverbs_query_port,
3864 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port,
3865 struct ib_uverbs_query_port_resp),
3866 UAPI_DEF_METHOD_NEEDS_FN(query_port)),
3867 DECLARE_UVERBS_WRITE_EX(
3868 IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
3869 ib_uverbs_ex_query_device,
3870 UAPI_DEF_WRITE_IO_EX(
3871 struct ib_uverbs_ex_query_device,
3873 struct ib_uverbs_ex_query_device_resp,
3875 UAPI_DEF_METHOD_NEEDS_FN(query_device)),
3876 UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext),
3877 UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)),
3879 DECLARE_UVERBS_OBJECT(
3881 DECLARE_UVERBS_WRITE_EX(
3882 IB_USER_VERBS_EX_CMD_CREATE_FLOW,
3883 ib_uverbs_ex_create_flow,
3884 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow,
3886 struct ib_uverbs_create_flow_resp,
3888 UAPI_DEF_METHOD_NEEDS_FN(create_flow)),
3889 DECLARE_UVERBS_WRITE_EX(
3890 IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
3891 ib_uverbs_ex_destroy_flow,
3892 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow),
3893 UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))),
3895 DECLARE_UVERBS_OBJECT(
3897 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR,
3899 UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr),
3900 UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)),
3901 DECLARE_UVERBS_WRITE(
3902 IB_USER_VERBS_CMD_REG_MR,
3904 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr,
3905 struct ib_uverbs_reg_mr_resp),
3906 UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)),
3907 DECLARE_UVERBS_WRITE(
3908 IB_USER_VERBS_CMD_REREG_MR,
3910 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr,
3911 struct ib_uverbs_rereg_mr_resp),
3912 UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))),
3914 DECLARE_UVERBS_OBJECT(
3916 DECLARE_UVERBS_WRITE(
3917 IB_USER_VERBS_CMD_ALLOC_MW,
3919 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw,
3920 struct ib_uverbs_alloc_mw_resp),
3921 UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)),
3922 DECLARE_UVERBS_WRITE(
3923 IB_USER_VERBS_CMD_DEALLOC_MW,
3924 ib_uverbs_dealloc_mw,
3925 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw),
3926 UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))),
3928 DECLARE_UVERBS_OBJECT(
3930 DECLARE_UVERBS_WRITE(
3931 IB_USER_VERBS_CMD_ALLOC_PD,
3933 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd,
3934 struct ib_uverbs_alloc_pd_resp),
3935 UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)),
3936 DECLARE_UVERBS_WRITE(
3937 IB_USER_VERBS_CMD_DEALLOC_PD,
3938 ib_uverbs_dealloc_pd,
3939 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd),
3940 UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))),
3942 DECLARE_UVERBS_OBJECT(
3944 DECLARE_UVERBS_WRITE(
3945 IB_USER_VERBS_CMD_ATTACH_MCAST,
3946 ib_uverbs_attach_mcast,
3947 UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast),
3948 UAPI_DEF_METHOD_NEEDS_FN(attach_mcast),
3949 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3950 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP,
3951 ib_uverbs_create_qp,
3952 UAPI_DEF_WRITE_UDATA_IO(
3953 struct ib_uverbs_create_qp,
3954 struct ib_uverbs_create_qp_resp),
3955 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3956 DECLARE_UVERBS_WRITE(
3957 IB_USER_VERBS_CMD_DESTROY_QP,
3958 ib_uverbs_destroy_qp,
3959 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp,
3960 struct ib_uverbs_destroy_qp_resp),
3961 UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)),
3962 DECLARE_UVERBS_WRITE(
3963 IB_USER_VERBS_CMD_DETACH_MCAST,
3964 ib_uverbs_detach_mcast,
3965 UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast),
3966 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3967 DECLARE_UVERBS_WRITE(
3968 IB_USER_VERBS_CMD_MODIFY_QP,
3969 ib_uverbs_modify_qp,
3970 UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp),
3971 UAPI_DEF_METHOD_NEEDS_FN(modify_qp)),
3972 DECLARE_UVERBS_WRITE(
3973 IB_USER_VERBS_CMD_POST_RECV,
3974 ib_uverbs_post_recv,
3975 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv,
3976 struct ib_uverbs_post_recv_resp),
3977 UAPI_DEF_METHOD_NEEDS_FN(post_recv)),
3978 DECLARE_UVERBS_WRITE(
3979 IB_USER_VERBS_CMD_POST_SEND,
3980 ib_uverbs_post_send,
3981 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send,
3982 struct ib_uverbs_post_send_resp),
3983 UAPI_DEF_METHOD_NEEDS_FN(post_send)),
3984 DECLARE_UVERBS_WRITE(
3985 IB_USER_VERBS_CMD_QUERY_QP,
3987 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp,
3988 struct ib_uverbs_query_qp_resp),
3989 UAPI_DEF_METHOD_NEEDS_FN(query_qp)),
3990 DECLARE_UVERBS_WRITE_EX(
3991 IB_USER_VERBS_EX_CMD_CREATE_QP,
3992 ib_uverbs_ex_create_qp,
3993 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp,
3995 struct ib_uverbs_ex_create_qp_resp,
3997 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3998 DECLARE_UVERBS_WRITE_EX(
3999 IB_USER_VERBS_EX_CMD_MODIFY_QP,
4000 ib_uverbs_ex_modify_qp,
4001 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp,
4003 struct ib_uverbs_ex_modify_qp_resp,
4005 UAPI_DEF_METHOD_NEEDS_FN(modify_qp))),
4007 DECLARE_UVERBS_OBJECT(
4008 UVERBS_OBJECT_RWQ_IND_TBL,
4009 DECLARE_UVERBS_WRITE_EX(
4010 IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
4011 ib_uverbs_ex_create_rwq_ind_table,
4012 UAPI_DEF_WRITE_IO_EX(
4013 struct ib_uverbs_ex_create_rwq_ind_table,
4015 struct ib_uverbs_ex_create_rwq_ind_table_resp,
4017 UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)),
4018 DECLARE_UVERBS_WRITE_EX(
4019 IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
4020 ib_uverbs_ex_destroy_rwq_ind_table,
4022 struct ib_uverbs_ex_destroy_rwq_ind_table),
4023 UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))),
4025 DECLARE_UVERBS_OBJECT(
4027 DECLARE_UVERBS_WRITE_EX(
4028 IB_USER_VERBS_EX_CMD_CREATE_WQ,
4029 ib_uverbs_ex_create_wq,
4030 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq,
4032 struct ib_uverbs_ex_create_wq_resp,
4034 UAPI_DEF_METHOD_NEEDS_FN(create_wq)),
4035 DECLARE_UVERBS_WRITE_EX(
4036 IB_USER_VERBS_EX_CMD_DESTROY_WQ,
4037 ib_uverbs_ex_destroy_wq,
4038 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq,
4040 struct ib_uverbs_ex_destroy_wq_resp,
4042 UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)),
4043 DECLARE_UVERBS_WRITE_EX(
4044 IB_USER_VERBS_EX_CMD_MODIFY_WQ,
4045 ib_uverbs_ex_modify_wq,
4046 UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq,
4048 UAPI_DEF_METHOD_NEEDS_FN(modify_wq))),
4050 DECLARE_UVERBS_OBJECT(
4052 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ,
4053 ib_uverbs_create_srq,
4054 UAPI_DEF_WRITE_UDATA_IO(
4055 struct ib_uverbs_create_srq,
4056 struct ib_uverbs_create_srq_resp),
4057 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4058 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ,
4059 ib_uverbs_create_xsrq,
4060 UAPI_DEF_WRITE_UDATA_IO(
4061 struct ib_uverbs_create_xsrq,
4062 struct ib_uverbs_create_srq_resp),
4063 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4064 DECLARE_UVERBS_WRITE(
4065 IB_USER_VERBS_CMD_DESTROY_SRQ,
4066 ib_uverbs_destroy_srq,
4067 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq,
4068 struct ib_uverbs_destroy_srq_resp),
4069 UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)),
4070 DECLARE_UVERBS_WRITE(
4071 IB_USER_VERBS_CMD_MODIFY_SRQ,
4072 ib_uverbs_modify_srq,
4073 UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq),
4074 UAPI_DEF_METHOD_NEEDS_FN(modify_srq)),
4075 DECLARE_UVERBS_WRITE(
4076 IB_USER_VERBS_CMD_POST_SRQ_RECV,
4077 ib_uverbs_post_srq_recv,
4078 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv,
4079 struct ib_uverbs_post_srq_recv_resp),
4080 UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)),
4081 DECLARE_UVERBS_WRITE(
4082 IB_USER_VERBS_CMD_QUERY_SRQ,
4083 ib_uverbs_query_srq,
4084 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq,
4085 struct ib_uverbs_query_srq_resp),
4086 UAPI_DEF_METHOD_NEEDS_FN(query_srq))),
4088 DECLARE_UVERBS_OBJECT(
4090 DECLARE_UVERBS_WRITE(
4091 IB_USER_VERBS_CMD_CLOSE_XRCD,
4092 ib_uverbs_close_xrcd,
4093 UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd),
4094 UAPI_DEF_METHOD_NEEDS_FN(dealloc_xrcd)),
4095 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP,
4097 UAPI_DEF_WRITE_UDATA_IO(
4098 struct ib_uverbs_open_qp,
4099 struct ib_uverbs_create_qp_resp)),
4100 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD,
4101 ib_uverbs_open_xrcd,
4102 UAPI_DEF_WRITE_UDATA_IO(
4103 struct ib_uverbs_open_xrcd,
4104 struct ib_uverbs_open_xrcd_resp),
4105 UAPI_DEF_METHOD_NEEDS_FN(alloc_xrcd))),