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 (copy_to_user(attrs->ucore.outbuf, resp,
64 min(attrs->ucore.outlen, resp_len)))
67 if (resp_len < attrs->ucore.outlen) {
69 * Zero fill any extra memory that user
70 * space might have provided.
72 ret = clear_user(attrs->ucore.outbuf + resp_len,
73 attrs->ucore.outlen - resp_len);
82 * Copy a request from userspace. If the provided 'req' is larger than the
83 * user buffer then the user buffer is zero extended into the 'req'. If 'req'
84 * is smaller than the user buffer then the uncopied bytes in the user buffer
87 static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,
90 if (copy_from_user(req, attrs->ucore.inbuf,
91 min(attrs->ucore.inlen, req_len)))
94 if (attrs->ucore.inlen < req_len) {
95 memset(req + attrs->ucore.inlen, 0,
96 req_len - attrs->ucore.inlen);
97 } else if (attrs->ucore.inlen > req_len) {
98 if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len,
99 attrs->ucore.inlen - req_len))
106 * Generate the value for the 'response_length' protocol used by write_ex.
107 * This is the number of bytes the kernel actually wrote. Userspace can use
108 * this to detect what structure members in the response the kernel
111 static u32 uverbs_response_length(struct uverbs_attr_bundle *attrs,
114 return min_t(size_t, attrs->ucore.outlen, resp_len);
118 * The iterator version of the request interface is for handlers that need to
119 * step over a flex array at the end of a command header.
121 struct uverbs_req_iter {
122 const void __user *cur;
123 const void __user *end;
126 static int uverbs_request_start(struct uverbs_attr_bundle *attrs,
127 struct uverbs_req_iter *iter,
131 if (attrs->ucore.inlen < req_len)
134 if (copy_from_user(req, attrs->ucore.inbuf, req_len))
137 iter->cur = attrs->ucore.inbuf + req_len;
138 iter->end = attrs->ucore.inbuf + attrs->ucore.inlen;
142 static int uverbs_request_next(struct uverbs_req_iter *iter, void *val,
145 if (iter->cur + len > iter->end)
148 if (copy_from_user(val, iter->cur, len))
155 static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter,
158 const void __user *res = iter->cur;
160 if (iter->cur + len > iter->end)
161 return ERR_PTR(-ENOSPC);
166 static int uverbs_request_finish(struct uverbs_req_iter *iter)
168 if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur))
173 static struct ib_uverbs_completion_event_file *
174 _ib_uverbs_lookup_comp_file(s32 fd, const struct uverbs_attr_bundle *attrs)
176 struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
182 uverbs_uobject_get(uobj);
185 return container_of(uobj, struct ib_uverbs_completion_event_file,
188 #define ib_uverbs_lookup_comp_file(_fd, _ufile) \
189 _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile)
191 static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
193 struct ib_uverbs_file *file = attrs->ufile;
194 struct ib_uverbs_get_context cmd;
195 struct ib_uverbs_get_context_resp resp;
196 struct ib_ucontext *ucontext;
198 struct ib_rdmacg_object cg_obj;
199 struct ib_device *ib_dev;
202 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
206 mutex_lock(&file->ucontext_lock);
207 ib_dev = srcu_dereference(file->device->ib_dev,
208 &file->device->disassociate_srcu);
214 if (file->ucontext) {
219 ret = ib_rdmacg_try_charge(&cg_obj, ib_dev, RDMACG_RESOURCE_HCA_HANDLE);
223 ucontext = ib_dev->ops.alloc_ucontext(ib_dev, &attrs->driver_udata);
224 if (IS_ERR(ucontext)) {
225 ret = PTR_ERR(ucontext);
229 ucontext->device = ib_dev;
230 ucontext->cg_obj = cg_obj;
231 /* ufile is required when some objects are released */
232 ucontext->ufile = file;
234 ucontext->closing = false;
235 ucontext->cleanup_retryable = false;
237 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
238 mutex_init(&ucontext->per_mm_list_lock);
239 INIT_LIST_HEAD(&ucontext->per_mm_list);
240 if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING))
241 ucontext->invalidate_range = NULL;
245 resp.num_comp_vectors = file->device->num_comp_vectors;
247 ret = get_unused_fd_flags(O_CLOEXEC);
252 filp = ib_uverbs_alloc_async_event_file(file, ib_dev);
258 ret = uverbs_response(attrs, &resp, sizeof(resp));
262 fd_install(resp.async_fd, filp);
264 ucontext->res.type = RDMA_RESTRACK_CTX;
265 rdma_restrack_uadd(&ucontext->res);
268 * Make sure that ib_uverbs_get_ucontext() sees the pointer update
269 * only after all writes to setup the ucontext have completed
271 smp_store_release(&file->ucontext, ucontext);
273 mutex_unlock(&file->ucontext_lock);
278 ib_uverbs_free_async_event_file(file);
282 put_unused_fd(resp.async_fd);
285 ib_dev->ops.dealloc_ucontext(ucontext);
288 ib_rdmacg_uncharge(&cg_obj, ib_dev, RDMACG_RESOURCE_HCA_HANDLE);
291 mutex_unlock(&file->ucontext_lock);
295 static void copy_query_dev_fields(struct ib_ucontext *ucontext,
296 struct ib_uverbs_query_device_resp *resp,
297 struct ib_device_attr *attr)
299 struct ib_device *ib_dev = ucontext->device;
301 resp->fw_ver = attr->fw_ver;
302 resp->node_guid = ib_dev->node_guid;
303 resp->sys_image_guid = attr->sys_image_guid;
304 resp->max_mr_size = attr->max_mr_size;
305 resp->page_size_cap = attr->page_size_cap;
306 resp->vendor_id = attr->vendor_id;
307 resp->vendor_part_id = attr->vendor_part_id;
308 resp->hw_ver = attr->hw_ver;
309 resp->max_qp = attr->max_qp;
310 resp->max_qp_wr = attr->max_qp_wr;
311 resp->device_cap_flags = lower_32_bits(attr->device_cap_flags);
312 resp->max_sge = min(attr->max_send_sge, attr->max_recv_sge);
313 resp->max_sge_rd = attr->max_sge_rd;
314 resp->max_cq = attr->max_cq;
315 resp->max_cqe = attr->max_cqe;
316 resp->max_mr = attr->max_mr;
317 resp->max_pd = attr->max_pd;
318 resp->max_qp_rd_atom = attr->max_qp_rd_atom;
319 resp->max_ee_rd_atom = attr->max_ee_rd_atom;
320 resp->max_res_rd_atom = attr->max_res_rd_atom;
321 resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom;
322 resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom;
323 resp->atomic_cap = attr->atomic_cap;
324 resp->max_ee = attr->max_ee;
325 resp->max_rdd = attr->max_rdd;
326 resp->max_mw = attr->max_mw;
327 resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp;
328 resp->max_raw_ethy_qp = attr->max_raw_ethy_qp;
329 resp->max_mcast_grp = attr->max_mcast_grp;
330 resp->max_mcast_qp_attach = attr->max_mcast_qp_attach;
331 resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach;
332 resp->max_ah = attr->max_ah;
333 resp->max_fmr = attr->max_fmr;
334 resp->max_map_per_fmr = attr->max_map_per_fmr;
335 resp->max_srq = attr->max_srq;
336 resp->max_srq_wr = attr->max_srq_wr;
337 resp->max_srq_sge = attr->max_srq_sge;
338 resp->max_pkeys = attr->max_pkeys;
339 resp->local_ca_ack_delay = attr->local_ca_ack_delay;
340 resp->phys_port_cnt = ib_dev->phys_port_cnt;
343 static int ib_uverbs_query_device(struct uverbs_attr_bundle *attrs)
345 struct ib_uverbs_query_device cmd;
346 struct ib_uverbs_query_device_resp resp;
347 struct ib_ucontext *ucontext;
350 ucontext = ib_uverbs_get_ucontext(attrs);
351 if (IS_ERR(ucontext))
352 return PTR_ERR(ucontext);
354 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
358 memset(&resp, 0, sizeof resp);
359 copy_query_dev_fields(ucontext, &resp, &ucontext->device->attrs);
361 return uverbs_response(attrs, &resp, sizeof(resp));
365 * ib_uverbs_query_port_resp.port_cap_flags started out as just a copy of the
366 * PortInfo CapabilityMask, but was extended with unique bits.
368 static u32 make_port_cap_flags(const struct ib_port_attr *attr)
372 /* All IBA CapabilityMask bits are passed through here, except bit 26,
373 * which is overridden with IP_BASED_GIDS. This is due to a historical
374 * mistake in the implementation of IP_BASED_GIDS. Otherwise all other
375 * bits match the IBA definition across all kernel versions.
377 res = attr->port_cap_flags & ~(u32)IB_UVERBS_PCF_IP_BASED_GIDS;
380 res |= IB_UVERBS_PCF_IP_BASED_GIDS;
385 static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs)
387 struct ib_uverbs_query_port cmd;
388 struct ib_uverbs_query_port_resp resp;
389 struct ib_port_attr attr;
391 struct ib_ucontext *ucontext;
392 struct ib_device *ib_dev;
394 ucontext = ib_uverbs_get_ucontext(attrs);
395 if (IS_ERR(ucontext))
396 return PTR_ERR(ucontext);
397 ib_dev = ucontext->device;
399 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
403 ret = ib_query_port(ib_dev, cmd.port_num, &attr);
407 memset(&resp, 0, sizeof resp);
409 resp.state = attr.state;
410 resp.max_mtu = attr.max_mtu;
411 resp.active_mtu = attr.active_mtu;
412 resp.gid_tbl_len = attr.gid_tbl_len;
413 resp.port_cap_flags = make_port_cap_flags(&attr);
414 resp.max_msg_sz = attr.max_msg_sz;
415 resp.bad_pkey_cntr = attr.bad_pkey_cntr;
416 resp.qkey_viol_cntr = attr.qkey_viol_cntr;
417 resp.pkey_tbl_len = attr.pkey_tbl_len;
419 if (rdma_is_grh_required(ib_dev, cmd.port_num))
420 resp.flags |= IB_UVERBS_QPF_GRH_REQUIRED;
422 if (rdma_cap_opa_ah(ib_dev, cmd.port_num)) {
423 resp.lid = OPA_TO_IB_UCAST_LID(attr.lid);
424 resp.sm_lid = OPA_TO_IB_UCAST_LID(attr.sm_lid);
426 resp.lid = ib_lid_cpu16(attr.lid);
427 resp.sm_lid = ib_lid_cpu16(attr.sm_lid);
430 resp.max_vl_num = attr.max_vl_num;
431 resp.sm_sl = attr.sm_sl;
432 resp.subnet_timeout = attr.subnet_timeout;
433 resp.init_type_reply = attr.init_type_reply;
434 resp.active_width = attr.active_width;
435 resp.active_speed = attr.active_speed;
436 resp.phys_state = attr.phys_state;
437 resp.link_layer = rdma_port_get_link_layer(ib_dev,
440 return uverbs_response(attrs, &resp, sizeof(resp));
443 static int ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs)
445 struct ib_uverbs_alloc_pd cmd;
446 struct ib_uverbs_alloc_pd_resp resp;
447 struct ib_uobject *uobj;
450 struct ib_device *ib_dev;
452 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
456 uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ib_dev);
458 return PTR_ERR(uobj);
460 pd = ib_dev->ops.alloc_pd(ib_dev, uobj->context, &attrs->driver_udata);
468 pd->__internal_mr = NULL;
469 atomic_set(&pd->usecnt, 0);
472 memset(&resp, 0, sizeof resp);
473 resp.pd_handle = uobj->id;
474 pd->res.type = RDMA_RESTRACK_PD;
475 rdma_restrack_uadd(&pd->res);
477 ret = uverbs_response(attrs, &resp, sizeof(resp));
481 return uobj_alloc_commit(uobj);
487 uobj_alloc_abort(uobj);
491 static int ib_uverbs_dealloc_pd(struct uverbs_attr_bundle *attrs)
493 struct ib_uverbs_dealloc_pd cmd;
496 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
500 return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
503 struct xrcd_table_entry {
505 struct ib_xrcd *xrcd;
509 static int xrcd_table_insert(struct ib_uverbs_device *dev,
511 struct ib_xrcd *xrcd)
513 struct xrcd_table_entry *entry, *scan;
514 struct rb_node **p = &dev->xrcd_tree.rb_node;
515 struct rb_node *parent = NULL;
517 entry = kmalloc(sizeof *entry, GFP_KERNEL);
522 entry->inode = inode;
526 scan = rb_entry(parent, struct xrcd_table_entry, node);
528 if (inode < scan->inode) {
530 } else if (inode > scan->inode) {
538 rb_link_node(&entry->node, parent, p);
539 rb_insert_color(&entry->node, &dev->xrcd_tree);
544 static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
547 struct xrcd_table_entry *entry;
548 struct rb_node *p = dev->xrcd_tree.rb_node;
551 entry = rb_entry(p, struct xrcd_table_entry, node);
553 if (inode < entry->inode)
555 else if (inode > entry->inode)
564 static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
566 struct xrcd_table_entry *entry;
568 entry = xrcd_table_search(dev, inode);
575 static void xrcd_table_delete(struct ib_uverbs_device *dev,
578 struct xrcd_table_entry *entry;
580 entry = xrcd_table_search(dev, inode);
583 rb_erase(&entry->node, &dev->xrcd_tree);
588 static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
590 struct ib_uverbs_device *ibudev = attrs->ufile->device;
591 struct ib_uverbs_open_xrcd cmd;
592 struct ib_uverbs_open_xrcd_resp resp;
593 struct ib_uxrcd_object *obj;
594 struct ib_xrcd *xrcd = NULL;
595 struct fd f = {NULL, 0};
596 struct inode *inode = NULL;
599 struct ib_device *ib_dev;
601 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
605 mutex_lock(&ibudev->xrcd_tree_mutex);
608 /* search for file descriptor */
612 goto err_tree_mutex_unlock;
615 inode = file_inode(f.file);
616 xrcd = find_xrcd(ibudev, inode);
617 if (!xrcd && !(cmd.oflags & O_CREAT)) {
618 /* no file descriptor. Need CREATE flag */
620 goto err_tree_mutex_unlock;
623 if (xrcd && cmd.oflags & O_EXCL) {
625 goto err_tree_mutex_unlock;
629 obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs,
633 goto err_tree_mutex_unlock;
637 xrcd = ib_dev->ops.alloc_xrcd(ib_dev, obj->uobject.context,
638 &attrs->driver_udata);
645 xrcd->device = ib_dev;
646 atomic_set(&xrcd->usecnt, 0);
647 mutex_init(&xrcd->tgt_qp_mutex);
648 INIT_LIST_HEAD(&xrcd->tgt_qp_list);
652 atomic_set(&obj->refcnt, 0);
653 obj->uobject.object = xrcd;
654 memset(&resp, 0, sizeof resp);
655 resp.xrcd_handle = obj->uobject.id;
659 /* create new inode/xrcd table entry */
660 ret = xrcd_table_insert(ibudev, inode, xrcd);
662 goto err_dealloc_xrcd;
664 atomic_inc(&xrcd->usecnt);
667 ret = uverbs_response(attrs, &resp, sizeof(resp));
674 mutex_unlock(&ibudev->xrcd_tree_mutex);
676 return uobj_alloc_commit(&obj->uobject);
681 xrcd_table_delete(ibudev, inode);
682 atomic_dec(&xrcd->usecnt);
686 ib_dealloc_xrcd(xrcd);
689 uobj_alloc_abort(&obj->uobject);
691 err_tree_mutex_unlock:
695 mutex_unlock(&ibudev->xrcd_tree_mutex);
700 static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs)
702 struct ib_uverbs_close_xrcd cmd;
705 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
709 return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs);
712 int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject,
713 struct ib_xrcd *xrcd,
714 enum rdma_remove_reason why)
718 struct ib_uverbs_device *dev = uobject->context->ufile->device;
721 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
724 ret = ib_dealloc_xrcd(xrcd);
726 if (ib_is_destroy_retryable(ret, why, uobject)) {
727 atomic_inc(&xrcd->usecnt);
732 xrcd_table_delete(dev, inode);
737 static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
739 struct ib_uverbs_reg_mr cmd;
740 struct ib_uverbs_reg_mr_resp resp;
741 struct ib_uobject *uobj;
745 struct ib_device *ib_dev;
747 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
751 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
754 ret = ib_check_mr_access(cmd.access_flags);
758 uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
760 return PTR_ERR(uobj);
762 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
768 if (cmd.access_flags & IB_ACCESS_ON_DEMAND) {
769 if (!(pd->device->attrs.device_cap_flags &
770 IB_DEVICE_ON_DEMAND_PAGING)) {
771 pr_debug("ODP support not available\n");
777 mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
779 &attrs->driver_udata);
785 mr->device = pd->device;
789 atomic_inc(&pd->usecnt);
790 mr->res.type = RDMA_RESTRACK_MR;
791 rdma_restrack_uadd(&mr->res);
795 memset(&resp, 0, sizeof resp);
796 resp.lkey = mr->lkey;
797 resp.rkey = mr->rkey;
798 resp.mr_handle = uobj->id;
800 ret = uverbs_response(attrs, &resp, sizeof(resp));
804 uobj_put_obj_read(pd);
806 return uobj_alloc_commit(uobj);
812 uobj_put_obj_read(pd);
815 uobj_alloc_abort(uobj);
819 static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
821 struct ib_uverbs_rereg_mr cmd;
822 struct ib_uverbs_rereg_mr_resp resp;
823 struct ib_pd *pd = NULL;
825 struct ib_pd *old_pd;
827 struct ib_uobject *uobj;
829 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
833 if (cmd.flags & ~IB_MR_REREG_SUPPORTED || !cmd.flags)
836 if ((cmd.flags & IB_MR_REREG_TRANS) &&
837 (!cmd.start || !cmd.hca_va || 0 >= cmd.length ||
838 (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)))
841 uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
843 return PTR_ERR(uobj);
852 if (cmd.flags & IB_MR_REREG_ACCESS) {
853 ret = ib_check_mr_access(cmd.access_flags);
858 if (cmd.flags & IB_MR_REREG_PD) {
859 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle,
868 ret = mr->device->ops.rereg_user_mr(mr, cmd.flags, cmd.start,
869 cmd.length, cmd.hca_va,
870 cmd.access_flags, pd,
871 &attrs->driver_udata);
873 if (cmd.flags & IB_MR_REREG_PD) {
874 atomic_inc(&pd->usecnt);
876 atomic_dec(&old_pd->usecnt);
882 memset(&resp, 0, sizeof(resp));
883 resp.lkey = mr->lkey;
884 resp.rkey = mr->rkey;
886 ret = uverbs_response(attrs, &resp, sizeof(resp));
889 if (cmd.flags & IB_MR_REREG_PD)
890 uobj_put_obj_read(pd);
893 uobj_put_write(uobj);
898 static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs)
900 struct ib_uverbs_dereg_mr cmd;
903 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
907 return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
910 static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs)
912 struct ib_uverbs_alloc_mw cmd;
913 struct ib_uverbs_alloc_mw_resp resp;
914 struct ib_uobject *uobj;
918 struct ib_device *ib_dev;
920 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
924 uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev);
926 return PTR_ERR(uobj);
928 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
934 mw = pd->device->ops.alloc_mw(pd, cmd.mw_type, &attrs->driver_udata);
940 mw->device = pd->device;
943 atomic_inc(&pd->usecnt);
947 memset(&resp, 0, sizeof(resp));
948 resp.rkey = mw->rkey;
949 resp.mw_handle = uobj->id;
951 ret = uverbs_response(attrs, &resp, sizeof(resp));
955 uobj_put_obj_read(pd);
956 return uobj_alloc_commit(uobj);
959 uverbs_dealloc_mw(mw);
961 uobj_put_obj_read(pd);
963 uobj_alloc_abort(uobj);
967 static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs)
969 struct ib_uverbs_dealloc_mw cmd;
972 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
976 return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs);
979 static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs)
981 struct ib_uverbs_create_comp_channel cmd;
982 struct ib_uverbs_create_comp_channel_resp resp;
983 struct ib_uobject *uobj;
984 struct ib_uverbs_completion_event_file *ev_file;
985 struct ib_device *ib_dev;
988 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
992 uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev);
994 return PTR_ERR(uobj);
998 ev_file = container_of(uobj, struct ib_uverbs_completion_event_file,
1000 ib_uverbs_init_event_queue(&ev_file->ev_queue);
1002 ret = uverbs_response(attrs, &resp, sizeof(resp));
1004 uobj_alloc_abort(uobj);
1008 return uobj_alloc_commit(uobj);
1011 static struct ib_ucq_object *create_cq(struct uverbs_attr_bundle *attrs,
1012 struct ib_uverbs_ex_create_cq *cmd)
1014 struct ib_ucq_object *obj;
1015 struct ib_uverbs_completion_event_file *ev_file = NULL;
1018 struct ib_uverbs_ex_create_cq_resp resp;
1019 struct ib_cq_init_attr attr = {};
1020 struct ib_device *ib_dev;
1022 if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
1023 return ERR_PTR(-EINVAL);
1025 obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
1030 if (cmd->comp_channel >= 0) {
1031 ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs);
1032 if (IS_ERR(ev_file)) {
1033 ret = PTR_ERR(ev_file);
1038 obj->uobject.user_handle = cmd->user_handle;
1039 obj->comp_events_reported = 0;
1040 obj->async_events_reported = 0;
1041 INIT_LIST_HEAD(&obj->comp_list);
1042 INIT_LIST_HEAD(&obj->async_list);
1044 attr.cqe = cmd->cqe;
1045 attr.comp_vector = cmd->comp_vector;
1046 attr.flags = cmd->flags;
1048 cq = ib_dev->ops.create_cq(ib_dev, &attr, obj->uobject.context,
1049 &attrs->driver_udata);
1055 cq->device = ib_dev;
1056 cq->uobject = &obj->uobject;
1057 cq->comp_handler = ib_uverbs_comp_handler;
1058 cq->event_handler = ib_uverbs_cq_event_handler;
1059 cq->cq_context = ev_file ? &ev_file->ev_queue : NULL;
1060 atomic_set(&cq->usecnt, 0);
1062 obj->uobject.object = cq;
1063 memset(&resp, 0, sizeof resp);
1064 resp.base.cq_handle = obj->uobject.id;
1065 resp.base.cqe = cq->cqe;
1066 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1068 cq->res.type = RDMA_RESTRACK_CQ;
1069 rdma_restrack_uadd(&cq->res);
1071 ret = uverbs_response(attrs, &resp, sizeof(resp));
1075 ret = uobj_alloc_commit(&obj->uobject);
1077 return ERR_PTR(ret);
1085 ib_uverbs_release_ucq(attrs->ufile, ev_file, obj);
1088 uobj_alloc_abort(&obj->uobject);
1090 return ERR_PTR(ret);
1093 static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs)
1095 struct ib_uverbs_create_cq cmd;
1096 struct ib_uverbs_ex_create_cq cmd_ex;
1097 struct ib_ucq_object *obj;
1100 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1104 memset(&cmd_ex, 0, sizeof(cmd_ex));
1105 cmd_ex.user_handle = cmd.user_handle;
1106 cmd_ex.cqe = cmd.cqe;
1107 cmd_ex.comp_vector = cmd.comp_vector;
1108 cmd_ex.comp_channel = cmd.comp_channel;
1110 obj = create_cq(attrs, &cmd_ex);
1111 return PTR_ERR_OR_ZERO(obj);
1114 static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs)
1116 struct ib_uverbs_ex_create_cq cmd;
1117 struct ib_ucq_object *obj;
1120 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1130 obj = create_cq(attrs, &cmd);
1131 return PTR_ERR_OR_ZERO(obj);
1134 static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs)
1136 struct ib_uverbs_resize_cq cmd;
1137 struct ib_uverbs_resize_cq_resp resp = {};
1141 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1145 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1149 ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata);
1155 ret = uverbs_response(attrs, &resp, sizeof(resp));
1157 uobj_put_obj_read(cq);
1162 static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
1165 struct ib_uverbs_wc tmp;
1167 tmp.wr_id = wc->wr_id;
1168 tmp.status = wc->status;
1169 tmp.opcode = wc->opcode;
1170 tmp.vendor_err = wc->vendor_err;
1171 tmp.byte_len = wc->byte_len;
1172 tmp.ex.imm_data = wc->ex.imm_data;
1173 tmp.qp_num = wc->qp->qp_num;
1174 tmp.src_qp = wc->src_qp;
1175 tmp.wc_flags = wc->wc_flags;
1176 tmp.pkey_index = wc->pkey_index;
1177 if (rdma_cap_opa_ah(ib_dev, wc->port_num))
1178 tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid);
1180 tmp.slid = ib_lid_cpu16(wc->slid);
1182 tmp.dlid_path_bits = wc->dlid_path_bits;
1183 tmp.port_num = wc->port_num;
1186 if (copy_to_user(dest, &tmp, sizeof tmp))
1192 static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs)
1194 struct ib_uverbs_poll_cq cmd;
1195 struct ib_uverbs_poll_cq_resp resp;
1196 u8 __user *header_ptr;
1197 u8 __user *data_ptr;
1202 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1206 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1210 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1211 header_ptr = attrs->ucore.outbuf;
1212 data_ptr = header_ptr + sizeof resp;
1214 memset(&resp, 0, sizeof resp);
1215 while (resp.count < cmd.ne) {
1216 ret = ib_poll_cq(cq, 1, &wc);
1222 ret = copy_wc_to_user(cq->device, data_ptr, &wc);
1226 data_ptr += sizeof(struct ib_uverbs_wc);
1230 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1238 uobj_put_obj_read(cq);
1242 static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs)
1244 struct ib_uverbs_req_notify_cq cmd;
1248 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1252 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1256 ib_req_notify_cq(cq, cmd.solicited_only ?
1257 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1259 uobj_put_obj_read(cq);
1264 static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs)
1266 struct ib_uverbs_destroy_cq cmd;
1267 struct ib_uverbs_destroy_cq_resp resp;
1268 struct ib_uobject *uobj;
1269 struct ib_ucq_object *obj;
1272 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1276 uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1278 return PTR_ERR(uobj);
1280 obj = container_of(uobj, struct ib_ucq_object, uobject);
1281 memset(&resp, 0, sizeof(resp));
1282 resp.comp_events_reported = obj->comp_events_reported;
1283 resp.async_events_reported = obj->async_events_reported;
1285 uobj_put_destroy(uobj);
1287 return uverbs_response(attrs, &resp, sizeof(resp));
1290 static int create_qp(struct uverbs_attr_bundle *attrs,
1291 struct ib_uverbs_ex_create_qp *cmd)
1293 struct ib_uqp_object *obj;
1294 struct ib_device *device;
1295 struct ib_pd *pd = NULL;
1296 struct ib_xrcd *xrcd = NULL;
1297 struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT);
1298 struct ib_cq *scq = NULL, *rcq = NULL;
1299 struct ib_srq *srq = NULL;
1301 struct ib_qp_init_attr attr = {};
1302 struct ib_uverbs_ex_create_qp_resp resp;
1304 struct ib_rwq_ind_table *ind_tbl = NULL;
1306 struct ib_device *ib_dev;
1308 if (cmd->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
1311 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1314 return PTR_ERR(obj);
1316 obj->uevent.uobject.user_handle = cmd->user_handle;
1317 mutex_init(&obj->mcast_lock);
1319 if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) {
1320 ind_tbl = uobj_get_obj_read(rwq_ind_table,
1321 UVERBS_OBJECT_RWQ_IND_TBL,
1322 cmd->rwq_ind_tbl_handle, attrs);
1328 attr.rwq_ind_tbl = ind_tbl;
1331 if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1336 if (ind_tbl && !cmd->max_send_wr)
1339 if (cmd->qp_type == IB_QPT_XRC_TGT) {
1340 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle,
1343 if (IS_ERR(xrcd_uobj)) {
1348 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1353 device = xrcd->device;
1355 if (cmd->qp_type == IB_QPT_XRC_INI) {
1356 cmd->max_recv_wr = 0;
1357 cmd->max_recv_sge = 0;
1360 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ,
1361 cmd->srq_handle, attrs);
1362 if (!srq || srq->srq_type == IB_SRQT_XRC) {
1369 if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1370 rcq = uobj_get_obj_read(
1371 cq, UVERBS_OBJECT_CQ,
1372 cmd->recv_cq_handle, attrs);
1382 scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
1383 cmd->send_cq_handle, attrs);
1386 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle,
1388 if (!pd || (!scq && has_sq)) {
1393 device = pd->device;
1396 attr.event_handler = ib_uverbs_qp_event_handler;
1397 attr.qp_context = attrs->ufile;
1402 attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR :
1404 attr.qp_type = cmd->qp_type;
1405 attr.create_flags = 0;
1407 attr.cap.max_send_wr = cmd->max_send_wr;
1408 attr.cap.max_recv_wr = cmd->max_recv_wr;
1409 attr.cap.max_send_sge = cmd->max_send_sge;
1410 attr.cap.max_recv_sge = cmd->max_recv_sge;
1411 attr.cap.max_inline_data = cmd->max_inline_data;
1413 obj->uevent.events_reported = 0;
1414 INIT_LIST_HEAD(&obj->uevent.event_list);
1415 INIT_LIST_HEAD(&obj->mcast_list);
1417 attr.create_flags = cmd->create_flags;
1418 if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
1419 IB_QP_CREATE_CROSS_CHANNEL |
1420 IB_QP_CREATE_MANAGED_SEND |
1421 IB_QP_CREATE_MANAGED_RECV |
1422 IB_QP_CREATE_SCATTER_FCS |
1423 IB_QP_CREATE_CVLAN_STRIPPING |
1424 IB_QP_CREATE_SOURCE_QPN |
1425 IB_QP_CREATE_PCI_WRITE_END_PADDING)) {
1430 if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
1431 if (!capable(CAP_NET_RAW)) {
1436 attr.source_qpn = cmd->source_qpn;
1439 if (cmd->qp_type == IB_QPT_XRC_TGT)
1440 qp = ib_create_qp(pd, &attr);
1442 qp = _ib_create_qp(device, pd, &attr, &attrs->driver_udata,
1443 &obj->uevent.uobject);
1450 if (cmd->qp_type != IB_QPT_XRC_TGT) {
1451 ret = ib_create_qp_security(qp, device);
1457 qp->send_cq = attr.send_cq;
1458 qp->recv_cq = attr.recv_cq;
1460 qp->rwq_ind_tbl = ind_tbl;
1461 qp->event_handler = attr.event_handler;
1462 qp->qp_context = attr.qp_context;
1463 qp->qp_type = attr.qp_type;
1464 atomic_set(&qp->usecnt, 0);
1465 atomic_inc(&pd->usecnt);
1468 atomic_inc(&attr.send_cq->usecnt);
1470 atomic_inc(&attr.recv_cq->usecnt);
1472 atomic_inc(&attr.srq->usecnt);
1474 atomic_inc(&ind_tbl->usecnt);
1476 /* It is done in _ib_create_qp for other QP types */
1477 qp->uobject = &obj->uevent.uobject;
1480 obj->uevent.uobject.object = qp;
1482 memset(&resp, 0, sizeof resp);
1483 resp.base.qpn = qp->qp_num;
1484 resp.base.qp_handle = obj->uevent.uobject.id;
1485 resp.base.max_recv_sge = attr.cap.max_recv_sge;
1486 resp.base.max_send_sge = attr.cap.max_send_sge;
1487 resp.base.max_recv_wr = attr.cap.max_recv_wr;
1488 resp.base.max_send_wr = attr.cap.max_send_wr;
1489 resp.base.max_inline_data = attr.cap.max_inline_data;
1490 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1492 ret = uverbs_response(attrs, &resp, sizeof(resp));
1497 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object,
1499 atomic_inc(&obj->uxrcd->refcnt);
1500 uobj_put_read(xrcd_uobj);
1504 uobj_put_obj_read(pd);
1506 uobj_put_obj_read(scq);
1507 if (rcq && rcq != scq)
1508 uobj_put_obj_read(rcq);
1510 uobj_put_obj_read(srq);
1512 uobj_put_obj_read(ind_tbl);
1514 return uobj_alloc_commit(&obj->uevent.uobject);
1519 if (!IS_ERR(xrcd_uobj))
1520 uobj_put_read(xrcd_uobj);
1522 uobj_put_obj_read(pd);
1524 uobj_put_obj_read(scq);
1525 if (rcq && rcq != scq)
1526 uobj_put_obj_read(rcq);
1528 uobj_put_obj_read(srq);
1530 uobj_put_obj_read(ind_tbl);
1532 uobj_alloc_abort(&obj->uevent.uobject);
1536 static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs)
1538 struct ib_uverbs_create_qp cmd;
1539 struct ib_uverbs_ex_create_qp cmd_ex;
1542 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1546 memset(&cmd_ex, 0, sizeof(cmd_ex));
1547 cmd_ex.user_handle = cmd.user_handle;
1548 cmd_ex.pd_handle = cmd.pd_handle;
1549 cmd_ex.send_cq_handle = cmd.send_cq_handle;
1550 cmd_ex.recv_cq_handle = cmd.recv_cq_handle;
1551 cmd_ex.srq_handle = cmd.srq_handle;
1552 cmd_ex.max_send_wr = cmd.max_send_wr;
1553 cmd_ex.max_recv_wr = cmd.max_recv_wr;
1554 cmd_ex.max_send_sge = cmd.max_send_sge;
1555 cmd_ex.max_recv_sge = cmd.max_recv_sge;
1556 cmd_ex.max_inline_data = cmd.max_inline_data;
1557 cmd_ex.sq_sig_all = cmd.sq_sig_all;
1558 cmd_ex.qp_type = cmd.qp_type;
1559 cmd_ex.is_srq = cmd.is_srq;
1561 return create_qp(attrs, &cmd_ex);
1564 static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs)
1566 struct ib_uverbs_ex_create_qp cmd;
1569 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1573 if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
1579 return create_qp(attrs, &cmd);
1582 static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs)
1584 struct ib_uverbs_open_qp cmd;
1585 struct ib_uverbs_create_qp_resp resp;
1586 struct ib_uqp_object *obj;
1587 struct ib_xrcd *xrcd;
1588 struct ib_uobject *uninitialized_var(xrcd_uobj);
1590 struct ib_qp_open_attr attr;
1592 struct ib_device *ib_dev;
1594 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1598 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1601 return PTR_ERR(obj);
1603 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs);
1604 if (IS_ERR(xrcd_uobj)) {
1609 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1615 attr.event_handler = ib_uverbs_qp_event_handler;
1616 attr.qp_context = attrs->ufile;
1617 attr.qp_num = cmd.qpn;
1618 attr.qp_type = cmd.qp_type;
1620 obj->uevent.events_reported = 0;
1621 INIT_LIST_HEAD(&obj->uevent.event_list);
1622 INIT_LIST_HEAD(&obj->mcast_list);
1624 qp = ib_open_qp(xrcd, &attr);
1630 obj->uevent.uobject.object = qp;
1631 obj->uevent.uobject.user_handle = cmd.user_handle;
1633 memset(&resp, 0, sizeof resp);
1634 resp.qpn = qp->qp_num;
1635 resp.qp_handle = obj->uevent.uobject.id;
1637 ret = uverbs_response(attrs, &resp, sizeof(resp));
1641 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
1642 atomic_inc(&obj->uxrcd->refcnt);
1643 qp->uobject = &obj->uevent.uobject;
1644 uobj_put_read(xrcd_uobj);
1646 return uobj_alloc_commit(&obj->uevent.uobject);
1651 uobj_put_read(xrcd_uobj);
1653 uobj_alloc_abort(&obj->uevent.uobject);
1657 static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr,
1658 struct rdma_ah_attr *rdma_attr)
1660 const struct ib_global_route *grh;
1662 uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr);
1663 uverb_attr->sl = rdma_ah_get_sl(rdma_attr);
1664 uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr);
1665 uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr);
1666 uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) &
1668 if (uverb_attr->is_global) {
1669 grh = rdma_ah_read_grh(rdma_attr);
1670 memcpy(uverb_attr->dgid, grh->dgid.raw, 16);
1671 uverb_attr->flow_label = grh->flow_label;
1672 uverb_attr->sgid_index = grh->sgid_index;
1673 uverb_attr->hop_limit = grh->hop_limit;
1674 uverb_attr->traffic_class = grh->traffic_class;
1676 uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr);
1679 static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
1681 struct ib_uverbs_query_qp cmd;
1682 struct ib_uverbs_query_qp_resp resp;
1684 struct ib_qp_attr *attr;
1685 struct ib_qp_init_attr *init_attr;
1688 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1692 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1693 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1694 if (!attr || !init_attr) {
1699 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1705 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1707 uobj_put_obj_read(qp);
1712 memset(&resp, 0, sizeof resp);
1714 resp.qp_state = attr->qp_state;
1715 resp.cur_qp_state = attr->cur_qp_state;
1716 resp.path_mtu = attr->path_mtu;
1717 resp.path_mig_state = attr->path_mig_state;
1718 resp.qkey = attr->qkey;
1719 resp.rq_psn = attr->rq_psn;
1720 resp.sq_psn = attr->sq_psn;
1721 resp.dest_qp_num = attr->dest_qp_num;
1722 resp.qp_access_flags = attr->qp_access_flags;
1723 resp.pkey_index = attr->pkey_index;
1724 resp.alt_pkey_index = attr->alt_pkey_index;
1725 resp.sq_draining = attr->sq_draining;
1726 resp.max_rd_atomic = attr->max_rd_atomic;
1727 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1728 resp.min_rnr_timer = attr->min_rnr_timer;
1729 resp.port_num = attr->port_num;
1730 resp.timeout = attr->timeout;
1731 resp.retry_cnt = attr->retry_cnt;
1732 resp.rnr_retry = attr->rnr_retry;
1733 resp.alt_port_num = attr->alt_port_num;
1734 resp.alt_timeout = attr->alt_timeout;
1736 copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr);
1737 copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr);
1739 resp.max_send_wr = init_attr->cap.max_send_wr;
1740 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1741 resp.max_send_sge = init_attr->cap.max_send_sge;
1742 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1743 resp.max_inline_data = init_attr->cap.max_inline_data;
1744 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1746 ret = uverbs_response(attrs, &resp, sizeof(resp));
1755 /* Remove ignored fields set in the attribute mask */
1756 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1759 case IB_QPT_XRC_INI:
1760 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1761 case IB_QPT_XRC_TGT:
1762 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1769 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
1770 struct rdma_ah_attr *rdma_attr,
1771 struct ib_uverbs_qp_dest *uverb_attr)
1773 rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
1774 if (uverb_attr->is_global) {
1775 rdma_ah_set_grh(rdma_attr, NULL,
1776 uverb_attr->flow_label,
1777 uverb_attr->sgid_index,
1778 uverb_attr->hop_limit,
1779 uverb_attr->traffic_class);
1780 rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid);
1782 rdma_ah_set_ah_flags(rdma_attr, 0);
1784 rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
1785 rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
1786 rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
1787 rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
1788 rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
1789 rdma_ah_set_make_grd(rdma_attr, false);
1792 static int modify_qp(struct uverbs_attr_bundle *attrs,
1793 struct ib_uverbs_ex_modify_qp *cmd)
1795 struct ib_qp_attr *attr;
1799 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1803 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle,
1810 if ((cmd->base.attr_mask & IB_QP_PORT) &&
1811 !rdma_is_port_valid(qp->device, cmd->base.port_num)) {
1816 if ((cmd->base.attr_mask & IB_QP_AV)) {
1817 if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1822 if (cmd->base.attr_mask & IB_QP_STATE &&
1823 cmd->base.qp_state == IB_QPS_RTR) {
1824 /* We are in INIT->RTR TRANSITION (if we are not,
1825 * this transition will be rejected in subsequent checks).
1826 * In the INIT->RTR transition, we cannot have IB_QP_PORT set,
1827 * but the IB_QP_STATE flag is required.
1829 * Since kernel 3.14 (commit dbf727de7440), the uverbs driver,
1830 * when IB_QP_AV is set, has required inclusion of a valid
1831 * port number in the primary AV. (AVs are created and handled
1832 * differently for infiniband and ethernet (RoCE) ports).
1834 * Check the port number included in the primary AV against
1835 * the port number in the qp struct, which was set (and saved)
1836 * in the RST->INIT transition.
1838 if (cmd->base.dest.port_num != qp->real_qp->port) {
1843 /* We are in SQD->SQD. (If we are not, this transition will
1844 * be rejected later in the verbs layer checks).
1845 * Check for both IB_QP_PORT and IB_QP_AV, these can be set
1846 * together in the SQD->SQD transition.
1848 * If only IP_QP_AV was set, add in IB_QP_PORT as well (the
1849 * verbs layer driver does not track primary port changes
1850 * resulting from path migration. Thus, in SQD, if the primary
1851 * AV is modified, the primary port should also be modified).
1853 * Note that in this transition, the IB_QP_STATE flag
1856 if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1857 == (IB_QP_AV | IB_QP_PORT)) &&
1858 cmd->base.port_num != cmd->base.dest.port_num) {
1862 if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1864 cmd->base.attr_mask |= IB_QP_PORT;
1865 cmd->base.port_num = cmd->base.dest.port_num;
1870 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1871 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1872 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) ||
1873 cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) {
1878 if ((cmd->base.attr_mask & IB_QP_CUR_STATE &&
1879 cmd->base.cur_qp_state > IB_QPS_ERR) ||
1880 (cmd->base.attr_mask & IB_QP_STATE &&
1881 cmd->base.qp_state > IB_QPS_ERR)) {
1886 if (cmd->base.attr_mask & IB_QP_STATE)
1887 attr->qp_state = cmd->base.qp_state;
1888 if (cmd->base.attr_mask & IB_QP_CUR_STATE)
1889 attr->cur_qp_state = cmd->base.cur_qp_state;
1890 if (cmd->base.attr_mask & IB_QP_PATH_MTU)
1891 attr->path_mtu = cmd->base.path_mtu;
1892 if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE)
1893 attr->path_mig_state = cmd->base.path_mig_state;
1894 if (cmd->base.attr_mask & IB_QP_QKEY)
1895 attr->qkey = cmd->base.qkey;
1896 if (cmd->base.attr_mask & IB_QP_RQ_PSN)
1897 attr->rq_psn = cmd->base.rq_psn;
1898 if (cmd->base.attr_mask & IB_QP_SQ_PSN)
1899 attr->sq_psn = cmd->base.sq_psn;
1900 if (cmd->base.attr_mask & IB_QP_DEST_QPN)
1901 attr->dest_qp_num = cmd->base.dest_qp_num;
1902 if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS)
1903 attr->qp_access_flags = cmd->base.qp_access_flags;
1904 if (cmd->base.attr_mask & IB_QP_PKEY_INDEX)
1905 attr->pkey_index = cmd->base.pkey_index;
1906 if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
1907 attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify;
1908 if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1909 attr->max_rd_atomic = cmd->base.max_rd_atomic;
1910 if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1911 attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic;
1912 if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER)
1913 attr->min_rnr_timer = cmd->base.min_rnr_timer;
1914 if (cmd->base.attr_mask & IB_QP_PORT)
1915 attr->port_num = cmd->base.port_num;
1916 if (cmd->base.attr_mask & IB_QP_TIMEOUT)
1917 attr->timeout = cmd->base.timeout;
1918 if (cmd->base.attr_mask & IB_QP_RETRY_CNT)
1919 attr->retry_cnt = cmd->base.retry_cnt;
1920 if (cmd->base.attr_mask & IB_QP_RNR_RETRY)
1921 attr->rnr_retry = cmd->base.rnr_retry;
1922 if (cmd->base.attr_mask & IB_QP_ALT_PATH) {
1923 attr->alt_port_num = cmd->base.alt_port_num;
1924 attr->alt_timeout = cmd->base.alt_timeout;
1925 attr->alt_pkey_index = cmd->base.alt_pkey_index;
1927 if (cmd->base.attr_mask & IB_QP_RATE_LIMIT)
1928 attr->rate_limit = cmd->rate_limit;
1930 if (cmd->base.attr_mask & IB_QP_AV)
1931 copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr,
1934 if (cmd->base.attr_mask & IB_QP_ALT_PATH)
1935 copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr,
1936 &cmd->base.alt_dest);
1938 ret = ib_modify_qp_with_udata(qp, attr,
1939 modify_qp_mask(qp->qp_type,
1940 cmd->base.attr_mask),
1941 &attrs->driver_udata);
1944 uobj_put_obj_read(qp);
1951 static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs)
1953 struct ib_uverbs_ex_modify_qp cmd;
1956 ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base));
1960 if (cmd.base.attr_mask &
1961 ~((IB_USER_LEGACY_LAST_QP_ATTR_MASK << 1) - 1))
1964 return modify_qp(attrs, &cmd);
1967 static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)
1969 struct ib_uverbs_ex_modify_qp cmd;
1970 struct ib_uverbs_ex_modify_qp_resp resp = {
1971 .response_length = uverbs_response_length(attrs, sizeof(resp))
1975 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1980 * Last bit is reserved for extending the attr_mask by
1981 * using another field.
1983 BUILD_BUG_ON(IB_USER_LAST_QP_ATTR_MASK == (1 << 31));
1985 if (cmd.base.attr_mask &
1986 ~((IB_USER_LAST_QP_ATTR_MASK << 1) - 1))
1989 ret = modify_qp(attrs, &cmd);
1993 return uverbs_response(attrs, &resp, sizeof(resp));
1996 static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs)
1998 struct ib_uverbs_destroy_qp cmd;
1999 struct ib_uverbs_destroy_qp_resp resp;
2000 struct ib_uobject *uobj;
2001 struct ib_uqp_object *obj;
2004 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2008 uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2010 return PTR_ERR(uobj);
2012 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
2013 memset(&resp, 0, sizeof(resp));
2014 resp.events_reported = obj->uevent.events_reported;
2016 uobj_put_destroy(uobj);
2018 return uverbs_response(attrs, &resp, sizeof(resp));
2021 static void *alloc_wr(size_t wr_size, __u32 num_sge)
2023 if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof (struct ib_sge))) /
2024 sizeof (struct ib_sge))
2027 return kmalloc(ALIGN(wr_size, sizeof (struct ib_sge)) +
2028 num_sge * sizeof (struct ib_sge), GFP_KERNEL);
2031 static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
2033 struct ib_uverbs_post_send cmd;
2034 struct ib_uverbs_post_send_resp resp;
2035 struct ib_uverbs_send_wr *user_wr;
2036 struct ib_send_wr *wr = NULL, *last, *next;
2037 const struct ib_send_wr *bad_wr;
2043 const struct ib_sge __user *sgls;
2044 const void __user *wqes;
2045 struct uverbs_req_iter iter;
2047 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2050 wqes = uverbs_request_next_ptr(&iter, cmd.wqe_size * cmd.wr_count);
2052 return PTR_ERR(wqes);
2053 sgls = uverbs_request_next_ptr(
2054 &iter, cmd.sge_count * sizeof(struct ib_uverbs_sge));
2056 return PTR_ERR(sgls);
2057 ret = uverbs_request_finish(&iter);
2061 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
2065 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2069 is_ud = qp->qp_type == IB_QPT_UD;
2072 for (i = 0; i < cmd.wr_count; ++i) {
2073 if (copy_from_user(user_wr, wqes + i * cmd.wqe_size,
2079 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
2085 struct ib_ud_wr *ud;
2087 if (user_wr->opcode != IB_WR_SEND &&
2088 user_wr->opcode != IB_WR_SEND_WITH_IMM) {
2093 next_size = sizeof(*ud);
2094 ud = alloc_wr(next_size, user_wr->num_sge);
2100 ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH,
2101 user_wr->wr.ud.ah, attrs);
2107 ud->remote_qpn = user_wr->wr.ud.remote_qpn;
2108 ud->remote_qkey = user_wr->wr.ud.remote_qkey;
2111 } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
2112 user_wr->opcode == IB_WR_RDMA_WRITE ||
2113 user_wr->opcode == IB_WR_RDMA_READ) {
2114 struct ib_rdma_wr *rdma;
2116 next_size = sizeof(*rdma);
2117 rdma = alloc_wr(next_size, user_wr->num_sge);
2123 rdma->remote_addr = user_wr->wr.rdma.remote_addr;
2124 rdma->rkey = user_wr->wr.rdma.rkey;
2127 } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
2128 user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
2129 struct ib_atomic_wr *atomic;
2131 next_size = sizeof(*atomic);
2132 atomic = alloc_wr(next_size, user_wr->num_sge);
2138 atomic->remote_addr = user_wr->wr.atomic.remote_addr;
2139 atomic->compare_add = user_wr->wr.atomic.compare_add;
2140 atomic->swap = user_wr->wr.atomic.swap;
2141 atomic->rkey = user_wr->wr.atomic.rkey;
2144 } else if (user_wr->opcode == IB_WR_SEND ||
2145 user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2146 user_wr->opcode == IB_WR_SEND_WITH_INV) {
2147 next_size = sizeof(*next);
2148 next = alloc_wr(next_size, user_wr->num_sge);
2158 if (user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2159 user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
2161 (__be32 __force) user_wr->ex.imm_data;
2162 } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) {
2163 next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey;
2173 next->wr_id = user_wr->wr_id;
2174 next->num_sge = user_wr->num_sge;
2175 next->opcode = user_wr->opcode;
2176 next->send_flags = user_wr->send_flags;
2178 if (next->num_sge) {
2179 next->sg_list = (void *) next +
2180 ALIGN(next_size, sizeof(struct ib_sge));
2181 if (copy_from_user(next->sg_list, sgls + sg_ind,
2183 sizeof(struct ib_sge))) {
2187 sg_ind += next->num_sge;
2189 next->sg_list = NULL;
2193 ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr);
2195 for (next = wr; next; next = next->next) {
2201 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2206 uobj_put_obj_read(qp);
2209 if (is_ud && ud_wr(wr)->ah)
2210 uobj_put_obj_read(ud_wr(wr)->ah);
2222 static struct ib_recv_wr *
2223 ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count,
2224 u32 wqe_size, u32 sge_count)
2226 struct ib_uverbs_recv_wr *user_wr;
2227 struct ib_recv_wr *wr = NULL, *last, *next;
2231 const struct ib_sge __user *sgls;
2232 const void __user *wqes;
2234 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
2235 return ERR_PTR(-EINVAL);
2237 wqes = uverbs_request_next_ptr(iter, wqe_size * wr_count);
2239 return ERR_CAST(wqes);
2240 sgls = uverbs_request_next_ptr(
2241 iter, sge_count * sizeof(struct ib_uverbs_sge));
2243 return ERR_CAST(sgls);
2244 ret = uverbs_request_finish(iter);
2246 return ERR_PTR(ret);
2248 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2250 return ERR_PTR(-ENOMEM);
2254 for (i = 0; i < wr_count; ++i) {
2255 if (copy_from_user(user_wr, wqes + i * wqe_size,
2261 if (user_wr->num_sge + sg_ind > sge_count) {
2266 if (user_wr->num_sge >=
2267 (U32_MAX - ALIGN(sizeof *next, sizeof (struct ib_sge))) /
2268 sizeof (struct ib_sge)) {
2273 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
2274 user_wr->num_sge * sizeof (struct ib_sge),
2288 next->wr_id = user_wr->wr_id;
2289 next->num_sge = user_wr->num_sge;
2291 if (next->num_sge) {
2292 next->sg_list = (void *) next +
2293 ALIGN(sizeof *next, sizeof (struct ib_sge));
2294 if (copy_from_user(next->sg_list, sgls + sg_ind,
2296 sizeof(struct ib_sge))) {
2300 sg_ind += next->num_sge;
2302 next->sg_list = NULL;
2317 return ERR_PTR(ret);
2320 static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
2322 struct ib_uverbs_post_recv cmd;
2323 struct ib_uverbs_post_recv_resp resp;
2324 struct ib_recv_wr *wr, *next;
2325 const struct ib_recv_wr *bad_wr;
2328 struct uverbs_req_iter iter;
2330 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2334 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2339 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2346 ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
2348 uobj_put_obj_read(qp);
2350 for (next = wr; next; next = next->next) {
2357 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2370 static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs)
2372 struct ib_uverbs_post_srq_recv cmd;
2373 struct ib_uverbs_post_srq_recv_resp resp;
2374 struct ib_recv_wr *wr, *next;
2375 const struct ib_recv_wr *bad_wr;
2378 struct uverbs_req_iter iter;
2380 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2384 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2389 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
2396 ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr);
2398 uobj_put_obj_read(srq);
2401 for (next = wr; next; next = next->next) {
2407 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2421 static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
2423 struct ib_uverbs_create_ah cmd;
2424 struct ib_uverbs_create_ah_resp resp;
2425 struct ib_uobject *uobj;
2428 struct rdma_ah_attr attr = {};
2430 struct ib_device *ib_dev;
2432 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2436 uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev);
2438 return PTR_ERR(uobj);
2440 if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
2445 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2451 attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
2452 rdma_ah_set_make_grd(&attr, false);
2453 rdma_ah_set_dlid(&attr, cmd.attr.dlid);
2454 rdma_ah_set_sl(&attr, cmd.attr.sl);
2455 rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
2456 rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
2457 rdma_ah_set_port_num(&attr, cmd.attr.port_num);
2459 if (cmd.attr.is_global) {
2460 rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
2461 cmd.attr.grh.sgid_index,
2462 cmd.attr.grh.hop_limit,
2463 cmd.attr.grh.traffic_class);
2464 rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
2466 rdma_ah_set_ah_flags(&attr, 0);
2469 ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
2476 uobj->user_handle = cmd.user_handle;
2479 resp.ah_handle = uobj->id;
2481 ret = uverbs_response(attrs, &resp, sizeof(resp));
2485 uobj_put_obj_read(pd);
2486 return uobj_alloc_commit(uobj);
2489 rdma_destroy_ah(ah, RDMA_DESTROY_AH_SLEEPABLE);
2492 uobj_put_obj_read(pd);
2495 uobj_alloc_abort(uobj);
2499 static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs)
2501 struct ib_uverbs_destroy_ah cmd;
2504 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2508 return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs);
2511 static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs)
2513 struct ib_uverbs_attach_mcast cmd;
2515 struct ib_uqp_object *obj;
2516 struct ib_uverbs_mcast_entry *mcast;
2519 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2523 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2527 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2529 mutex_lock(&obj->mcast_lock);
2530 list_for_each_entry(mcast, &obj->mcast_list, list)
2531 if (cmd.mlid == mcast->lid &&
2532 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2537 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2543 mcast->lid = cmd.mlid;
2544 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2546 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2548 list_add_tail(&mcast->list, &obj->mcast_list);
2553 mutex_unlock(&obj->mcast_lock);
2554 uobj_put_obj_read(qp);
2559 static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs)
2561 struct ib_uverbs_detach_mcast cmd;
2562 struct ib_uqp_object *obj;
2564 struct ib_uverbs_mcast_entry *mcast;
2568 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2572 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2576 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2577 mutex_lock(&obj->mcast_lock);
2579 list_for_each_entry(mcast, &obj->mcast_list, list)
2580 if (cmd.mlid == mcast->lid &&
2581 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2582 list_del(&mcast->list);
2593 ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2596 mutex_unlock(&obj->mcast_lock);
2597 uobj_put_obj_read(qp);
2601 struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2603 struct ib_uflow_resources *resources;
2605 resources = kzalloc(sizeof(*resources), GFP_KERNEL);
2613 resources->counters =
2614 kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
2615 resources->collection =
2616 kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL);
2618 if (!resources->counters || !resources->collection)
2622 resources->max = num_specs;
2626 kfree(resources->counters);
2631 EXPORT_SYMBOL(flow_resources_alloc);
2633 void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2640 for (i = 0; i < uflow_res->collection_num; i++)
2641 atomic_dec(&uflow_res->collection[i]->usecnt);
2643 for (i = 0; i < uflow_res->counters_num; i++)
2644 atomic_dec(&uflow_res->counters[i]->usecnt);
2646 kfree(uflow_res->collection);
2647 kfree(uflow_res->counters);
2650 EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2652 void flow_resources_add(struct ib_uflow_resources *uflow_res,
2653 enum ib_flow_spec_type type,
2656 WARN_ON(uflow_res->num >= uflow_res->max);
2659 case IB_FLOW_SPEC_ACTION_HANDLE:
2660 atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt);
2661 uflow_res->collection[uflow_res->collection_num++] =
2662 (struct ib_flow_action *)ibobj;
2664 case IB_FLOW_SPEC_ACTION_COUNT:
2665 atomic_inc(&((struct ib_counters *)ibobj)->usecnt);
2666 uflow_res->counters[uflow_res->counters_num++] =
2667 (struct ib_counters *)ibobj;
2675 EXPORT_SYMBOL(flow_resources_add);
2677 static int kern_spec_to_ib_spec_action(const struct uverbs_attr_bundle *attrs,
2678 struct ib_uverbs_flow_spec *kern_spec,
2679 union ib_flow_spec *ib_spec,
2680 struct ib_uflow_resources *uflow_res)
2682 ib_spec->type = kern_spec->type;
2683 switch (ib_spec->type) {
2684 case IB_FLOW_SPEC_ACTION_TAG:
2685 if (kern_spec->flow_tag.size !=
2686 sizeof(struct ib_uverbs_flow_spec_action_tag))
2689 ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
2690 ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
2692 case IB_FLOW_SPEC_ACTION_DROP:
2693 if (kern_spec->drop.size !=
2694 sizeof(struct ib_uverbs_flow_spec_action_drop))
2697 ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop);
2699 case IB_FLOW_SPEC_ACTION_HANDLE:
2700 if (kern_spec->action.size !=
2701 sizeof(struct ib_uverbs_flow_spec_action_handle))
2703 ib_spec->action.act = uobj_get_obj_read(flow_action,
2704 UVERBS_OBJECT_FLOW_ACTION,
2705 kern_spec->action.handle,
2707 if (!ib_spec->action.act)
2709 ib_spec->action.size =
2710 sizeof(struct ib_flow_spec_action_handle);
2711 flow_resources_add(uflow_res,
2712 IB_FLOW_SPEC_ACTION_HANDLE,
2713 ib_spec->action.act);
2714 uobj_put_obj_read(ib_spec->action.act);
2716 case IB_FLOW_SPEC_ACTION_COUNT:
2717 if (kern_spec->flow_count.size !=
2718 sizeof(struct ib_uverbs_flow_spec_action_count))
2720 ib_spec->flow_count.counters =
2721 uobj_get_obj_read(counters,
2722 UVERBS_OBJECT_COUNTERS,
2723 kern_spec->flow_count.handle,
2725 if (!ib_spec->flow_count.counters)
2727 ib_spec->flow_count.size =
2728 sizeof(struct ib_flow_spec_action_count);
2729 flow_resources_add(uflow_res,
2730 IB_FLOW_SPEC_ACTION_COUNT,
2731 ib_spec->flow_count.counters);
2732 uobj_put_obj_read(ib_spec->flow_count.counters);
2740 static size_t kern_spec_filter_sz(const struct ib_uverbs_flow_spec_hdr *spec)
2742 /* Returns user space filter size, includes padding */
2743 return (spec->size - sizeof(struct ib_uverbs_flow_spec_hdr)) / 2;
2746 static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size,
2747 u16 ib_real_filter_sz)
2750 * User space filter structures must be 64 bit aligned, otherwise this
2751 * may pass, but we won't handle additional new attributes.
2754 if (kern_filter_size > ib_real_filter_sz) {
2755 if (memchr_inv(kern_spec_filter +
2756 ib_real_filter_sz, 0,
2757 kern_filter_size - ib_real_filter_sz))
2759 return ib_real_filter_sz;
2761 return kern_filter_size;
2764 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
2765 const void *kern_spec_mask,
2766 const void *kern_spec_val,
2767 size_t kern_filter_sz,
2768 union ib_flow_spec *ib_spec)
2770 ssize_t actual_filter_sz;
2771 ssize_t ib_filter_sz;
2773 /* User flow spec size must be aligned to 4 bytes */
2774 if (kern_filter_sz != ALIGN(kern_filter_sz, 4))
2777 ib_spec->type = type;
2779 if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL))
2782 switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) {
2783 case IB_FLOW_SPEC_ETH:
2784 ib_filter_sz = offsetof(struct ib_flow_eth_filter, real_sz);
2785 actual_filter_sz = spec_filter_size(kern_spec_mask,
2788 if (actual_filter_sz <= 0)
2790 ib_spec->size = sizeof(struct ib_flow_spec_eth);
2791 memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz);
2792 memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz);
2794 case IB_FLOW_SPEC_IPV4:
2795 ib_filter_sz = offsetof(struct ib_flow_ipv4_filter, real_sz);
2796 actual_filter_sz = spec_filter_size(kern_spec_mask,
2799 if (actual_filter_sz <= 0)
2801 ib_spec->size = sizeof(struct ib_flow_spec_ipv4);
2802 memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz);
2803 memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz);
2805 case IB_FLOW_SPEC_IPV6:
2806 ib_filter_sz = offsetof(struct ib_flow_ipv6_filter, real_sz);
2807 actual_filter_sz = spec_filter_size(kern_spec_mask,
2810 if (actual_filter_sz <= 0)
2812 ib_spec->size = sizeof(struct ib_flow_spec_ipv6);
2813 memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz);
2814 memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz);
2816 if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) ||
2817 (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20))
2820 case IB_FLOW_SPEC_TCP:
2821 case IB_FLOW_SPEC_UDP:
2822 ib_filter_sz = offsetof(struct ib_flow_tcp_udp_filter, real_sz);
2823 actual_filter_sz = spec_filter_size(kern_spec_mask,
2826 if (actual_filter_sz <= 0)
2828 ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp);
2829 memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz);
2830 memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz);
2832 case IB_FLOW_SPEC_VXLAN_TUNNEL:
2833 ib_filter_sz = offsetof(struct ib_flow_tunnel_filter, real_sz);
2834 actual_filter_sz = spec_filter_size(kern_spec_mask,
2837 if (actual_filter_sz <= 0)
2839 ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel);
2840 memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz);
2841 memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz);
2843 if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) ||
2844 (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24))
2847 case IB_FLOW_SPEC_ESP:
2848 ib_filter_sz = offsetof(struct ib_flow_esp_filter, real_sz);
2849 actual_filter_sz = spec_filter_size(kern_spec_mask,
2852 if (actual_filter_sz <= 0)
2854 ib_spec->esp.size = sizeof(struct ib_flow_spec_esp);
2855 memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz);
2856 memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz);
2858 case IB_FLOW_SPEC_GRE:
2859 ib_filter_sz = offsetof(struct ib_flow_gre_filter, real_sz);
2860 actual_filter_sz = spec_filter_size(kern_spec_mask,
2863 if (actual_filter_sz <= 0)
2865 ib_spec->gre.size = sizeof(struct ib_flow_spec_gre);
2866 memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz);
2867 memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz);
2869 case IB_FLOW_SPEC_MPLS:
2870 ib_filter_sz = offsetof(struct ib_flow_mpls_filter, real_sz);
2871 actual_filter_sz = spec_filter_size(kern_spec_mask,
2874 if (actual_filter_sz <= 0)
2876 ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls);
2877 memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz);
2878 memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz);
2886 static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
2887 union ib_flow_spec *ib_spec)
2889 ssize_t kern_filter_sz;
2890 void *kern_spec_mask;
2891 void *kern_spec_val;
2893 kern_filter_sz = kern_spec_filter_sz(&kern_spec->hdr);
2895 kern_spec_val = (void *)kern_spec +
2896 sizeof(struct ib_uverbs_flow_spec_hdr);
2897 kern_spec_mask = kern_spec_val + kern_filter_sz;
2899 return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type,
2902 kern_filter_sz, ib_spec);
2905 static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs,
2906 struct ib_uverbs_flow_spec *kern_spec,
2907 union ib_flow_spec *ib_spec,
2908 struct ib_uflow_resources *uflow_res)
2910 if (kern_spec->reserved)
2913 if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
2914 return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec,
2917 return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
2920 static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs)
2922 struct ib_uverbs_ex_create_wq cmd;
2923 struct ib_uverbs_ex_create_wq_resp resp = {};
2924 struct ib_uwq_object *obj;
2929 struct ib_wq_init_attr wq_init_attr = {};
2930 struct ib_device *ib_dev;
2932 err = uverbs_request(attrs, &cmd, sizeof(cmd));
2939 obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs,
2942 return PTR_ERR(obj);
2944 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2950 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
2956 wq_init_attr.cq = cq;
2957 wq_init_attr.max_sge = cmd.max_sge;
2958 wq_init_attr.max_wr = cmd.max_wr;
2959 wq_init_attr.wq_context = attrs->ufile;
2960 wq_init_attr.wq_type = cmd.wq_type;
2961 wq_init_attr.event_handler = ib_uverbs_wq_event_handler;
2962 wq_init_attr.create_flags = cmd.create_flags;
2963 obj->uevent.events_reported = 0;
2964 INIT_LIST_HEAD(&obj->uevent.event_list);
2966 wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata);
2972 wq->uobject = &obj->uevent.uobject;
2973 obj->uevent.uobject.object = wq;
2974 wq->wq_type = wq_init_attr.wq_type;
2977 wq->device = pd->device;
2978 wq->wq_context = wq_init_attr.wq_context;
2979 atomic_set(&wq->usecnt, 0);
2980 atomic_inc(&pd->usecnt);
2981 atomic_inc(&cq->usecnt);
2982 wq->uobject = &obj->uevent.uobject;
2983 obj->uevent.uobject.object = wq;
2985 memset(&resp, 0, sizeof(resp));
2986 resp.wq_handle = obj->uevent.uobject.id;
2987 resp.max_sge = wq_init_attr.max_sge;
2988 resp.max_wr = wq_init_attr.max_wr;
2989 resp.wqn = wq->wq_num;
2990 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2991 err = uverbs_response(attrs, &resp, sizeof(resp));
2995 uobj_put_obj_read(pd);
2996 uobj_put_obj_read(cq);
2997 return uobj_alloc_commit(&obj->uevent.uobject);
3002 uobj_put_obj_read(cq);
3004 uobj_put_obj_read(pd);
3006 uobj_alloc_abort(&obj->uevent.uobject);
3011 static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs)
3013 struct ib_uverbs_ex_destroy_wq cmd;
3014 struct ib_uverbs_ex_destroy_wq_resp resp = {};
3015 struct ib_uobject *uobj;
3016 struct ib_uwq_object *obj;
3019 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3026 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3027 uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3029 return PTR_ERR(uobj);
3031 obj = container_of(uobj, struct ib_uwq_object, uevent.uobject);
3032 resp.events_reported = obj->uevent.events_reported;
3034 uobj_put_destroy(uobj);
3036 return uverbs_response(attrs, &resp, sizeof(resp));
3039 static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
3041 struct ib_uverbs_ex_modify_wq cmd;
3043 struct ib_wq_attr wq_attr = {};
3046 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3053 if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS))
3056 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3060 wq_attr.curr_wq_state = cmd.curr_wq_state;
3061 wq_attr.wq_state = cmd.wq_state;
3062 if (cmd.attr_mask & IB_WQ_FLAGS) {
3063 wq_attr.flags = cmd.flags;
3064 wq_attr.flags_mask = cmd.flags_mask;
3066 ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
3067 &attrs->driver_udata);
3068 uobj_put_obj_read(wq);
3072 static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3074 struct ib_uverbs_ex_create_rwq_ind_table cmd;
3075 struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
3076 struct ib_uobject *uobj;
3078 struct ib_rwq_ind_table_init_attr init_attr = {};
3079 struct ib_rwq_ind_table *rwq_ind_tbl;
3080 struct ib_wq **wqs = NULL;
3081 u32 *wqs_handles = NULL;
3082 struct ib_wq *wq = NULL;
3083 int i, j, num_read_wqs;
3085 struct uverbs_req_iter iter;
3086 struct ib_device *ib_dev;
3088 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3095 if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE)
3098 num_wq_handles = 1 << cmd.log_ind_tbl_size;
3099 wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles),
3104 err = uverbs_request_next(&iter, wqs_handles,
3105 num_wq_handles * sizeof(__u32));
3109 err = uverbs_request_finish(&iter);
3113 wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL);
3119 for (num_read_wqs = 0; num_read_wqs < num_wq_handles;
3121 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ,
3122 wqs_handles[num_read_wqs], attrs);
3128 wqs[num_read_wqs] = wq;
3131 uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev);
3133 err = PTR_ERR(uobj);
3137 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3138 init_attr.ind_tbl = wqs;
3140 rwq_ind_tbl = ib_dev->ops.create_rwq_ind_table(ib_dev, &init_attr,
3141 &attrs->driver_udata);
3143 if (IS_ERR(rwq_ind_tbl)) {
3144 err = PTR_ERR(rwq_ind_tbl);
3148 rwq_ind_tbl->ind_tbl = wqs;
3149 rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size;
3150 rwq_ind_tbl->uobject = uobj;
3151 uobj->object = rwq_ind_tbl;
3152 rwq_ind_tbl->device = ib_dev;
3153 atomic_set(&rwq_ind_tbl->usecnt, 0);
3155 for (i = 0; i < num_wq_handles; i++)
3156 atomic_inc(&wqs[i]->usecnt);
3158 resp.ind_tbl_handle = uobj->id;
3159 resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num;
3160 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3162 err = uverbs_response(attrs, &resp, sizeof(resp));
3168 for (j = 0; j < num_read_wqs; j++)
3169 uobj_put_obj_read(wqs[j]);
3171 return uobj_alloc_commit(uobj);
3174 ib_destroy_rwq_ind_table(rwq_ind_tbl);
3176 uobj_alloc_abort(uobj);
3178 for (j = 0; j < num_read_wqs; j++)
3179 uobj_put_obj_read(wqs[j]);
3186 static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3188 struct ib_uverbs_ex_destroy_rwq_ind_table cmd;
3191 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3198 return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
3199 cmd.ind_tbl_handle, attrs);
3202 static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
3204 struct ib_uverbs_create_flow cmd;
3205 struct ib_uverbs_create_flow_resp resp;
3206 struct ib_uobject *uobj;
3207 struct ib_flow *flow_id;
3208 struct ib_uverbs_flow_attr *kern_flow_attr;
3209 struct ib_flow_attr *flow_attr;
3211 struct ib_uflow_resources *uflow_res;
3212 struct ib_uverbs_flow_spec_hdr *kern_spec;
3213 struct uverbs_req_iter iter;
3217 struct ib_device *ib_dev;
3219 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3226 if (!capable(CAP_NET_RAW))
3229 if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
3232 if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) &&
3233 ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) ||
3234 (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT)))
3237 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
3240 if (cmd.flow_attr.size >
3241 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
3244 if (cmd.flow_attr.reserved[0] ||
3245 cmd.flow_attr.reserved[1])
3248 if (cmd.flow_attr.num_of_specs) {
3249 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
3251 if (!kern_flow_attr)
3254 *kern_flow_attr = cmd.flow_attr;
3255 err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs,
3256 cmd.flow_attr.size);
3260 kern_flow_attr = &cmd.flow_attr;
3263 err = uverbs_request_finish(&iter);
3267 uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev);
3269 err = PTR_ERR(uobj);
3273 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
3279 if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) {
3284 flow_attr = kzalloc(struct_size(flow_attr, flows,
3285 cmd.flow_attr.num_of_specs), GFP_KERNEL);
3290 uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs);
3293 goto err_free_flow_attr;
3296 flow_attr->type = kern_flow_attr->type;
3297 flow_attr->priority = kern_flow_attr->priority;
3298 flow_attr->num_of_specs = kern_flow_attr->num_of_specs;
3299 flow_attr->port = kern_flow_attr->port;
3300 flow_attr->flags = kern_flow_attr->flags;
3301 flow_attr->size = sizeof(*flow_attr);
3303 kern_spec = kern_flow_attr->flow_specs;
3304 ib_spec = flow_attr + 1;
3305 for (i = 0; i < flow_attr->num_of_specs &&
3306 cmd.flow_attr.size >= sizeof(*kern_spec) &&
3307 cmd.flow_attr.size >= kern_spec->size;
3309 err = kern_spec_to_ib_spec(
3310 attrs, (struct ib_uverbs_flow_spec *)kern_spec,
3311 ib_spec, uflow_res);
3316 ((union ib_flow_spec *) ib_spec)->size;
3317 cmd.flow_attr.size -= kern_spec->size;
3318 kern_spec = ((void *)kern_spec) + kern_spec->size;
3319 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
3321 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
3322 pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
3323 i, cmd.flow_attr.size);
3328 flow_id = qp->device->ops.create_flow(
3329 qp, flow_attr, IB_FLOW_DOMAIN_USER, &attrs->driver_udata);
3331 if (IS_ERR(flow_id)) {
3332 err = PTR_ERR(flow_id);
3336 ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res);
3338 memset(&resp, 0, sizeof(resp));
3339 resp.flow_handle = uobj->id;
3341 err = uverbs_response(attrs, &resp, sizeof(resp));
3345 uobj_put_obj_read(qp);
3347 if (cmd.flow_attr.num_of_specs)
3348 kfree(kern_flow_attr);
3349 return uobj_alloc_commit(uobj);
3351 if (!qp->device->ops.destroy_flow(flow_id))
3352 atomic_dec(&qp->usecnt);
3354 ib_uverbs_flow_resources_free(uflow_res);
3358 uobj_put_obj_read(qp);
3360 uobj_alloc_abort(uobj);
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 obj->uevent.events_reported = 0;
3444 INIT_LIST_HEAD(&obj->uevent.event_list);
3446 srq = pd->device->ops.create_srq(pd, &attr, udata);
3452 srq->device = pd->device;
3454 srq->srq_type = cmd->srq_type;
3455 srq->uobject = &obj->uevent.uobject;
3456 srq->event_handler = attr.event_handler;
3457 srq->srq_context = attr.srq_context;
3459 if (ib_srq_has_cq(cmd->srq_type)) {
3460 srq->ext.cq = attr.ext.cq;
3461 atomic_inc(&attr.ext.cq->usecnt);
3464 if (cmd->srq_type == IB_SRQT_XRC) {
3465 srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
3466 atomic_inc(&attr.ext.xrc.xrcd->usecnt);
3469 atomic_inc(&pd->usecnt);
3470 atomic_set(&srq->usecnt, 0);
3472 obj->uevent.uobject.object = srq;
3473 obj->uevent.uobject.user_handle = cmd->user_handle;
3475 memset(&resp, 0, sizeof resp);
3476 resp.srq_handle = obj->uevent.uobject.id;
3477 resp.max_wr = attr.attr.max_wr;
3478 resp.max_sge = attr.attr.max_sge;
3479 if (cmd->srq_type == IB_SRQT_XRC)
3480 resp.srqn = srq->ext.xrc.srq_num;
3482 ret = uverbs_response(attrs, &resp, sizeof(resp));
3486 if (cmd->srq_type == IB_SRQT_XRC)
3487 uobj_put_read(xrcd_uobj);
3489 if (ib_srq_has_cq(cmd->srq_type))
3490 uobj_put_obj_read(attr.ext.cq);
3492 uobj_put_obj_read(pd);
3493 return uobj_alloc_commit(&obj->uevent.uobject);
3496 ib_destroy_srq(srq);
3499 uobj_put_obj_read(pd);
3502 if (ib_srq_has_cq(cmd->srq_type))
3503 uobj_put_obj_read(attr.ext.cq);
3506 if (cmd->srq_type == IB_SRQT_XRC) {
3507 atomic_dec(&obj->uxrcd->refcnt);
3508 uobj_put_read(xrcd_uobj);
3512 uobj_alloc_abort(&obj->uevent.uobject);
3516 static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs)
3518 struct ib_uverbs_create_srq cmd;
3519 struct ib_uverbs_create_xsrq xcmd;
3522 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3526 memset(&xcmd, 0, sizeof(xcmd));
3527 xcmd.response = cmd.response;
3528 xcmd.user_handle = cmd.user_handle;
3529 xcmd.srq_type = IB_SRQT_BASIC;
3530 xcmd.pd_handle = cmd.pd_handle;
3531 xcmd.max_wr = cmd.max_wr;
3532 xcmd.max_sge = cmd.max_sge;
3533 xcmd.srq_limit = cmd.srq_limit;
3535 return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata);
3538 static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs)
3540 struct ib_uverbs_create_xsrq cmd;
3543 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3547 return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata);
3550 static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs)
3552 struct ib_uverbs_modify_srq cmd;
3554 struct ib_srq_attr attr;
3557 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3561 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3565 attr.max_wr = cmd.max_wr;
3566 attr.srq_limit = cmd.srq_limit;
3568 ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask,
3569 &attrs->driver_udata);
3571 uobj_put_obj_read(srq);
3576 static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs)
3578 struct ib_uverbs_query_srq cmd;
3579 struct ib_uverbs_query_srq_resp resp;
3580 struct ib_srq_attr attr;
3584 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3588 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3592 ret = ib_query_srq(srq, &attr);
3594 uobj_put_obj_read(srq);
3599 memset(&resp, 0, sizeof resp);
3601 resp.max_wr = attr.max_wr;
3602 resp.max_sge = attr.max_sge;
3603 resp.srq_limit = attr.srq_limit;
3605 return uverbs_response(attrs, &resp, sizeof(resp));
3608 static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs)
3610 struct ib_uverbs_destroy_srq cmd;
3611 struct ib_uverbs_destroy_srq_resp resp;
3612 struct ib_uobject *uobj;
3613 struct ib_uevent_object *obj;
3616 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3620 uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3622 return PTR_ERR(uobj);
3624 obj = container_of(uobj, struct ib_uevent_object, uobject);
3625 memset(&resp, 0, sizeof(resp));
3626 resp.events_reported = obj->events_reported;
3628 uobj_put_destroy(uobj);
3630 return uverbs_response(attrs, &resp, sizeof(resp));
3633 static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
3635 struct ib_uverbs_ex_query_device_resp resp = {};
3636 struct ib_uverbs_ex_query_device cmd;
3637 struct ib_device_attr attr = {0};
3638 struct ib_ucontext *ucontext;
3639 struct ib_device *ib_dev;
3642 ucontext = ib_uverbs_get_ucontext(attrs);
3643 if (IS_ERR(ucontext))
3644 return PTR_ERR(ucontext);
3645 ib_dev = ucontext->device;
3647 err = uverbs_request(attrs, &cmd, sizeof(cmd));
3657 err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata);
3661 copy_query_dev_fields(ucontext, &resp.base, &attr);
3663 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
3664 resp.odp_caps.general_caps = attr.odp_caps.general_caps;
3665 resp.odp_caps.per_transport_caps.rc_odp_caps =
3666 attr.odp_caps.per_transport_caps.rc_odp_caps;
3667 resp.odp_caps.per_transport_caps.uc_odp_caps =
3668 attr.odp_caps.per_transport_caps.uc_odp_caps;
3669 resp.odp_caps.per_transport_caps.ud_odp_caps =
3670 attr.odp_caps.per_transport_caps.ud_odp_caps;
3673 resp.timestamp_mask = attr.timestamp_mask;
3674 resp.hca_core_clock = attr.hca_core_clock;
3675 resp.device_cap_flags_ex = attr.device_cap_flags;
3676 resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts;
3677 resp.rss_caps.max_rwq_indirection_tables =
3678 attr.rss_caps.max_rwq_indirection_tables;
3679 resp.rss_caps.max_rwq_indirection_table_size =
3680 attr.rss_caps.max_rwq_indirection_table_size;
3681 resp.max_wq_type_rq = attr.max_wq_type_rq;
3682 resp.raw_packet_caps = attr.raw_packet_caps;
3683 resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size;
3684 resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags;
3685 resp.tm_caps.max_ops = attr.tm_caps.max_ops;
3686 resp.tm_caps.max_sge = attr.tm_caps.max_sge;
3687 resp.tm_caps.flags = attr.tm_caps.flags;
3688 resp.cq_moderation_caps.max_cq_moderation_count =
3689 attr.cq_caps.max_cq_moderation_count;
3690 resp.cq_moderation_caps.max_cq_moderation_period =
3691 attr.cq_caps.max_cq_moderation_period;
3692 resp.max_dm_size = attr.max_dm_size;
3693 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3695 return uverbs_response(attrs, &resp, sizeof(resp));
3698 static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs)
3700 struct ib_uverbs_ex_modify_cq cmd;
3704 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3708 if (!cmd.attr_mask || cmd.reserved)
3711 if (cmd.attr_mask > IB_CQ_MODERATE)
3714 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
3718 ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period);
3720 uobj_put_obj_read(cq);
3726 * Describe the input structs for write(). Some write methods have an input
3727 * only struct, most have an input and output. If the struct has an output then
3728 * the 'response' u64 must be the first field in the request structure.
3730 * If udata is present then both the request and response structs have a
3731 * trailing driver_data flex array. In this case the size of the base struct
3732 * cannot be changed.
3734 #define offsetof_after(_struct, _member) \
3735 (offsetof(_struct, _member) + sizeof(((_struct *)NULL)->_member))
3737 #define UAPI_DEF_WRITE_IO(req, resp) \
3738 .write.has_resp = 1 + \
3739 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \
3740 BUILD_BUG_ON_ZERO(sizeof(((req *)0)->response) != \
3742 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp)
3744 #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req)
3746 #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \
3747 UAPI_DEF_WRITE_IO(req, resp), \
3748 .write.has_udata = \
3750 BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3752 BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \
3755 #define UAPI_DEF_WRITE_UDATA_I(req) \
3756 UAPI_DEF_WRITE_I(req), \
3757 .write.has_udata = \
3758 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3762 * The _EX versions are for use with WRITE_EX and allow the last struct member
3763 * to be specified. Buffers that do not include that member will be rejected.
3765 #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \
3766 .write.has_resp = 1, \
3767 .write.req_size = offsetof_after(req, req_last_member), \
3768 .write.resp_size = offsetof_after(resp, resp_last_member)
3770 #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \
3771 .write.req_size = offsetof_after(req, req_last_member)
3773 const struct uapi_definition uverbs_def_write_intf[] = {
3774 DECLARE_UVERBS_OBJECT(
3776 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH,
3777 ib_uverbs_create_ah,
3778 UAPI_DEF_WRITE_UDATA_IO(
3779 struct ib_uverbs_create_ah,
3780 struct ib_uverbs_create_ah_resp),
3781 UAPI_DEF_METHOD_NEEDS_FN(create_ah)),
3782 DECLARE_UVERBS_WRITE(
3783 IB_USER_VERBS_CMD_DESTROY_AH,
3784 ib_uverbs_destroy_ah,
3785 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah),
3786 UAPI_DEF_METHOD_NEEDS_FN(destroy_ah))),
3788 DECLARE_UVERBS_OBJECT(
3789 UVERBS_OBJECT_COMP_CHANNEL,
3790 DECLARE_UVERBS_WRITE(
3791 IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
3792 ib_uverbs_create_comp_channel,
3794 struct ib_uverbs_create_comp_channel,
3795 struct ib_uverbs_create_comp_channel_resp))),
3797 DECLARE_UVERBS_OBJECT(
3799 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ,
3800 ib_uverbs_create_cq,
3801 UAPI_DEF_WRITE_UDATA_IO(
3802 struct ib_uverbs_create_cq,
3803 struct ib_uverbs_create_cq_resp),
3804 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3805 DECLARE_UVERBS_WRITE(
3806 IB_USER_VERBS_CMD_DESTROY_CQ,
3807 ib_uverbs_destroy_cq,
3808 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq,
3809 struct ib_uverbs_destroy_cq_resp),
3810 UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)),
3811 DECLARE_UVERBS_WRITE(
3812 IB_USER_VERBS_CMD_POLL_CQ,
3814 UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq,
3815 struct ib_uverbs_poll_cq_resp),
3816 UAPI_DEF_METHOD_NEEDS_FN(poll_cq)),
3817 DECLARE_UVERBS_WRITE(
3818 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
3819 ib_uverbs_req_notify_cq,
3820 UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq),
3821 UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)),
3822 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ,
3823 ib_uverbs_resize_cq,
3824 UAPI_DEF_WRITE_UDATA_IO(
3825 struct ib_uverbs_resize_cq,
3826 struct ib_uverbs_resize_cq_resp),
3827 UAPI_DEF_METHOD_NEEDS_FN(resize_cq)),
3828 DECLARE_UVERBS_WRITE_EX(
3829 IB_USER_VERBS_EX_CMD_CREATE_CQ,
3830 ib_uverbs_ex_create_cq,
3831 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq,
3833 struct ib_uverbs_ex_create_cq_resp,
3835 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3836 DECLARE_UVERBS_WRITE_EX(
3837 IB_USER_VERBS_EX_CMD_MODIFY_CQ,
3838 ib_uverbs_ex_modify_cq,
3839 UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq),
3840 UAPI_DEF_METHOD_NEEDS_FN(create_cq))),
3842 DECLARE_UVERBS_OBJECT(
3843 UVERBS_OBJECT_DEVICE,
3844 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT,
3845 ib_uverbs_get_context,
3846 UAPI_DEF_WRITE_UDATA_IO(
3847 struct ib_uverbs_get_context,
3848 struct ib_uverbs_get_context_resp)),
3849 DECLARE_UVERBS_WRITE(
3850 IB_USER_VERBS_CMD_QUERY_DEVICE,
3851 ib_uverbs_query_device,
3852 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device,
3853 struct ib_uverbs_query_device_resp)),
3854 DECLARE_UVERBS_WRITE(
3855 IB_USER_VERBS_CMD_QUERY_PORT,
3856 ib_uverbs_query_port,
3857 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port,
3858 struct ib_uverbs_query_port_resp),
3859 UAPI_DEF_METHOD_NEEDS_FN(query_port)),
3860 DECLARE_UVERBS_WRITE_EX(
3861 IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
3862 ib_uverbs_ex_query_device,
3863 UAPI_DEF_WRITE_IO_EX(
3864 struct ib_uverbs_ex_query_device,
3866 struct ib_uverbs_ex_query_device_resp,
3868 UAPI_DEF_METHOD_NEEDS_FN(query_device)),
3869 UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext),
3870 UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)),
3872 DECLARE_UVERBS_OBJECT(
3874 DECLARE_UVERBS_WRITE_EX(
3875 IB_USER_VERBS_EX_CMD_CREATE_FLOW,
3876 ib_uverbs_ex_create_flow,
3877 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow,
3879 struct ib_uverbs_create_flow_resp,
3881 UAPI_DEF_METHOD_NEEDS_FN(create_flow)),
3882 DECLARE_UVERBS_WRITE_EX(
3883 IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
3884 ib_uverbs_ex_destroy_flow,
3885 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow),
3886 UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))),
3888 DECLARE_UVERBS_OBJECT(
3890 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR,
3892 UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr),
3893 UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)),
3894 DECLARE_UVERBS_WRITE(
3895 IB_USER_VERBS_CMD_REG_MR,
3897 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr,
3898 struct ib_uverbs_reg_mr_resp),
3899 UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)),
3900 DECLARE_UVERBS_WRITE(
3901 IB_USER_VERBS_CMD_REREG_MR,
3903 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr,
3904 struct ib_uverbs_rereg_mr_resp),
3905 UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))),
3907 DECLARE_UVERBS_OBJECT(
3909 DECLARE_UVERBS_WRITE(
3910 IB_USER_VERBS_CMD_ALLOC_MW,
3912 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw,
3913 struct ib_uverbs_alloc_mw_resp),
3914 UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)),
3915 DECLARE_UVERBS_WRITE(
3916 IB_USER_VERBS_CMD_DEALLOC_MW,
3917 ib_uverbs_dealloc_mw,
3918 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw),
3919 UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))),
3921 DECLARE_UVERBS_OBJECT(
3923 DECLARE_UVERBS_WRITE(
3924 IB_USER_VERBS_CMD_ALLOC_PD,
3926 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd,
3927 struct ib_uverbs_alloc_pd_resp),
3928 UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)),
3929 DECLARE_UVERBS_WRITE(
3930 IB_USER_VERBS_CMD_DEALLOC_PD,
3931 ib_uverbs_dealloc_pd,
3932 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd),
3933 UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))),
3935 DECLARE_UVERBS_OBJECT(
3937 DECLARE_UVERBS_WRITE(
3938 IB_USER_VERBS_CMD_ATTACH_MCAST,
3939 ib_uverbs_attach_mcast,
3940 UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast),
3941 UAPI_DEF_METHOD_NEEDS_FN(attach_mcast),
3942 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3943 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP,
3944 ib_uverbs_create_qp,
3945 UAPI_DEF_WRITE_UDATA_IO(
3946 struct ib_uverbs_create_qp,
3947 struct ib_uverbs_create_qp_resp),
3948 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3949 DECLARE_UVERBS_WRITE(
3950 IB_USER_VERBS_CMD_DESTROY_QP,
3951 ib_uverbs_destroy_qp,
3952 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp,
3953 struct ib_uverbs_destroy_qp_resp),
3954 UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)),
3955 DECLARE_UVERBS_WRITE(
3956 IB_USER_VERBS_CMD_DETACH_MCAST,
3957 ib_uverbs_detach_mcast,
3958 UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast),
3959 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3960 DECLARE_UVERBS_WRITE(
3961 IB_USER_VERBS_CMD_MODIFY_QP,
3962 ib_uverbs_modify_qp,
3963 UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp),
3964 UAPI_DEF_METHOD_NEEDS_FN(modify_qp)),
3965 DECLARE_UVERBS_WRITE(
3966 IB_USER_VERBS_CMD_POST_RECV,
3967 ib_uverbs_post_recv,
3968 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv,
3969 struct ib_uverbs_post_recv_resp),
3970 UAPI_DEF_METHOD_NEEDS_FN(post_recv)),
3971 DECLARE_UVERBS_WRITE(
3972 IB_USER_VERBS_CMD_POST_SEND,
3973 ib_uverbs_post_send,
3974 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send,
3975 struct ib_uverbs_post_send_resp),
3976 UAPI_DEF_METHOD_NEEDS_FN(post_send)),
3977 DECLARE_UVERBS_WRITE(
3978 IB_USER_VERBS_CMD_QUERY_QP,
3980 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp,
3981 struct ib_uverbs_query_qp_resp),
3982 UAPI_DEF_METHOD_NEEDS_FN(query_qp)),
3983 DECLARE_UVERBS_WRITE_EX(
3984 IB_USER_VERBS_EX_CMD_CREATE_QP,
3985 ib_uverbs_ex_create_qp,
3986 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp,
3988 struct ib_uverbs_ex_create_qp_resp,
3990 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3991 DECLARE_UVERBS_WRITE_EX(
3992 IB_USER_VERBS_EX_CMD_MODIFY_QP,
3993 ib_uverbs_ex_modify_qp,
3994 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp,
3996 struct ib_uverbs_ex_modify_qp_resp,
3998 UAPI_DEF_METHOD_NEEDS_FN(modify_qp))),
4000 DECLARE_UVERBS_OBJECT(
4001 UVERBS_OBJECT_RWQ_IND_TBL,
4002 DECLARE_UVERBS_WRITE_EX(
4003 IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
4004 ib_uverbs_ex_create_rwq_ind_table,
4005 UAPI_DEF_WRITE_IO_EX(
4006 struct ib_uverbs_ex_create_rwq_ind_table,
4008 struct ib_uverbs_ex_create_rwq_ind_table_resp,
4010 UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)),
4011 DECLARE_UVERBS_WRITE_EX(
4012 IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
4013 ib_uverbs_ex_destroy_rwq_ind_table,
4015 struct ib_uverbs_ex_destroy_rwq_ind_table),
4016 UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))),
4018 DECLARE_UVERBS_OBJECT(
4020 DECLARE_UVERBS_WRITE_EX(
4021 IB_USER_VERBS_EX_CMD_CREATE_WQ,
4022 ib_uverbs_ex_create_wq,
4023 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq,
4025 struct ib_uverbs_ex_create_wq_resp,
4027 UAPI_DEF_METHOD_NEEDS_FN(create_wq)),
4028 DECLARE_UVERBS_WRITE_EX(
4029 IB_USER_VERBS_EX_CMD_DESTROY_WQ,
4030 ib_uverbs_ex_destroy_wq,
4031 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq,
4033 struct ib_uverbs_ex_destroy_wq_resp,
4035 UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)),
4036 DECLARE_UVERBS_WRITE_EX(
4037 IB_USER_VERBS_EX_CMD_MODIFY_WQ,
4038 ib_uverbs_ex_modify_wq,
4039 UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq,
4041 UAPI_DEF_METHOD_NEEDS_FN(modify_wq))),
4043 DECLARE_UVERBS_OBJECT(
4045 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ,
4046 ib_uverbs_create_srq,
4047 UAPI_DEF_WRITE_UDATA_IO(
4048 struct ib_uverbs_create_srq,
4049 struct ib_uverbs_create_srq_resp),
4050 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4051 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ,
4052 ib_uverbs_create_xsrq,
4053 UAPI_DEF_WRITE_UDATA_IO(
4054 struct ib_uverbs_create_xsrq,
4055 struct ib_uverbs_create_srq_resp),
4056 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4057 DECLARE_UVERBS_WRITE(
4058 IB_USER_VERBS_CMD_DESTROY_SRQ,
4059 ib_uverbs_destroy_srq,
4060 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq,
4061 struct ib_uverbs_destroy_srq_resp),
4062 UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)),
4063 DECLARE_UVERBS_WRITE(
4064 IB_USER_VERBS_CMD_MODIFY_SRQ,
4065 ib_uverbs_modify_srq,
4066 UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq),
4067 UAPI_DEF_METHOD_NEEDS_FN(modify_srq)),
4068 DECLARE_UVERBS_WRITE(
4069 IB_USER_VERBS_CMD_POST_SRQ_RECV,
4070 ib_uverbs_post_srq_recv,
4071 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv,
4072 struct ib_uverbs_post_srq_recv_resp),
4073 UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)),
4074 DECLARE_UVERBS_WRITE(
4075 IB_USER_VERBS_CMD_QUERY_SRQ,
4076 ib_uverbs_query_srq,
4077 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq,
4078 struct ib_uverbs_query_srq_resp),
4079 UAPI_DEF_METHOD_NEEDS_FN(query_srq))),
4081 DECLARE_UVERBS_OBJECT(
4083 DECLARE_UVERBS_WRITE(
4084 IB_USER_VERBS_CMD_CLOSE_XRCD,
4085 ib_uverbs_close_xrcd,
4086 UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd),
4087 UAPI_DEF_METHOD_NEEDS_FN(dealloc_xrcd)),
4088 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP,
4090 UAPI_DEF_WRITE_UDATA_IO(
4091 struct ib_uverbs_open_qp,
4092 struct ib_uverbs_create_qp_resp)),
4093 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD,
4094 ib_uverbs_open_xrcd,
4095 UAPI_DEF_WRITE_UDATA_IO(
4096 struct ib_uverbs_open_xrcd,
4097 struct ib_uverbs_open_xrcd_resp),
4098 UAPI_DEF_METHOD_NEEDS_FN(alloc_xrcd))),