Commit | Line | Data |
---|---|---|
bc38a6ab RD |
1 | /* |
2 | * Copyright (c) 2005 Topspin Communications. All rights reserved. | |
f7c6a7b5 | 3 | * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved. |
eb9d3cd5 | 4 | * Copyright (c) 2005 PathScale, Inc. All rights reserved. |
8bdb0e86 | 5 | * Copyright (c) 2006 Mellanox Technologies. All rights reserved. |
bc38a6ab RD |
6 | * |
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: | |
12 | * | |
13 | * Redistribution and use in source and binary forms, with or | |
14 | * without modification, are permitted provided that the following | |
15 | * conditions are met: | |
16 | * | |
17 | * - Redistributions of source code must retain the above | |
18 | * copyright notice, this list of conditions and the following | |
19 | * disclaimer. | |
20 | * | |
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. | |
25 | * | |
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 | |
33 | * SOFTWARE. | |
bc38a6ab RD |
34 | */ |
35 | ||
6b73597e | 36 | #include <linux/file.h> |
70a30e16 | 37 | #include <linux/fs.h> |
5a0e3ad6 | 38 | #include <linux/slab.h> |
8ada2c1c | 39 | #include <linux/sched.h> |
6b73597e | 40 | |
7c0f6ba6 | 41 | #include <linux/uaccess.h> |
bc38a6ab | 42 | |
fd3c7904 MB |
43 | #include <rdma/uverbs_types.h> |
44 | #include <rdma/uverbs_std_types.h> | |
fe9d7822 | 45 | #include <rdma/ib_ucaps.h> |
fd3c7904 MB |
46 | #include "rdma_core.h" |
47 | ||
bc38a6ab | 48 | #include "uverbs.h" |
ed4c54e5 | 49 | #include "core_priv.h" |
bc38a6ab | 50 | |
931373a1 JG |
51 | /* |
52 | * Copy a response to userspace. If the provided 'resp' is larger than the | |
53 | * user buffer it is silently truncated. If the user provided a larger buffer | |
54 | * then the trailing portion is zero filled. | |
55 | * | |
56 | * These semantics are intended to support future extension of the output | |
57 | * structures. | |
58 | */ | |
59 | static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp, | |
60 | size_t resp_len) | |
61 | { | |
931373a1 JG |
62 | int ret; |
63 | ||
d6f4a21f JG |
64 | if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT)) |
65 | return uverbs_copy_to_struct_or_zero( | |
66 | attrs, UVERBS_ATTR_CORE_OUT, resp, resp_len); | |
67 | ||
931373a1 JG |
68 | if (copy_to_user(attrs->ucore.outbuf, resp, |
69 | min(attrs->ucore.outlen, resp_len))) | |
70 | return -EFAULT; | |
71 | ||
9435ef4c LR |
72 | if (resp_len < attrs->ucore.outlen) { |
73 | /* | |
74 | * Zero fill any extra memory that user | |
75 | * space might have provided. | |
76 | */ | |
77 | ret = clear_user(attrs->ucore.outbuf + resp_len, | |
78 | attrs->ucore.outlen - resp_len); | |
931373a1 | 79 | if (ret) |
9435ef4c | 80 | return -EFAULT; |
931373a1 JG |
81 | } |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
3c2c2094 JG |
86 | /* |
87 | * Copy a request from userspace. If the provided 'req' is larger than the | |
88 | * user buffer then the user buffer is zero extended into the 'req'. If 'req' | |
89 | * is smaller than the user buffer then the uncopied bytes in the user buffer | |
90 | * must be zero. | |
91 | */ | |
92 | static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req, | |
93 | size_t req_len) | |
94 | { | |
95 | if (copy_from_user(req, attrs->ucore.inbuf, | |
96 | min(attrs->ucore.inlen, req_len))) | |
97 | return -EFAULT; | |
98 | ||
99 | if (attrs->ucore.inlen < req_len) { | |
100 | memset(req + attrs->ucore.inlen, 0, | |
101 | req_len - attrs->ucore.inlen); | |
102 | } else if (attrs->ucore.inlen > req_len) { | |
103 | if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len, | |
104 | attrs->ucore.inlen - req_len)) | |
105 | return -EOPNOTSUPP; | |
106 | } | |
107 | return 0; | |
108 | } | |
109 | ||
29a29d18 JG |
110 | /* |
111 | * Generate the value for the 'response_length' protocol used by write_ex. | |
112 | * This is the number of bytes the kernel actually wrote. Userspace can use | |
113 | * this to detect what structure members in the response the kernel | |
114 | * understood. | |
115 | */ | |
116 | static u32 uverbs_response_length(struct uverbs_attr_bundle *attrs, | |
117 | size_t resp_len) | |
118 | { | |
119 | return min_t(size_t, attrs->ucore.outlen, resp_len); | |
120 | } | |
121 | ||
335708c7 JG |
122 | /* |
123 | * The iterator version of the request interface is for handlers that need to | |
124 | * step over a flex array at the end of a command header. | |
125 | */ | |
126 | struct uverbs_req_iter { | |
127 | const void __user *cur; | |
128 | const void __user *end; | |
129 | }; | |
130 | ||
131 | static int uverbs_request_start(struct uverbs_attr_bundle *attrs, | |
132 | struct uverbs_req_iter *iter, | |
133 | void *req, | |
134 | size_t req_len) | |
135 | { | |
136 | if (attrs->ucore.inlen < req_len) | |
137 | return -ENOSPC; | |
138 | ||
139 | if (copy_from_user(req, attrs->ucore.inbuf, req_len)) | |
140 | return -EFAULT; | |
141 | ||
142 | iter->cur = attrs->ucore.inbuf + req_len; | |
143 | iter->end = attrs->ucore.inbuf + attrs->ucore.inlen; | |
144 | return 0; | |
145 | } | |
146 | ||
147 | static int uverbs_request_next(struct uverbs_req_iter *iter, void *val, | |
148 | size_t len) | |
149 | { | |
150 | if (iter->cur + len > iter->end) | |
151 | return -ENOSPC; | |
152 | ||
153 | if (copy_from_user(val, iter->cur, len)) | |
154 | return -EFAULT; | |
155 | ||
156 | iter->cur += len; | |
157 | return 0; | |
158 | } | |
159 | ||
c3bea3d2 JG |
160 | static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter, |
161 | size_t len) | |
162 | { | |
163 | const void __user *res = iter->cur; | |
164 | ||
d0257e08 | 165 | if (len > iter->end - iter->cur) |
2dcdebff | 166 | return (void __force __user *)ERR_PTR(-ENOSPC); |
c3bea3d2 JG |
167 | iter->cur += len; |
168 | return res; | |
169 | } | |
170 | ||
335708c7 JG |
171 | static int uverbs_request_finish(struct uverbs_req_iter *iter) |
172 | { | |
173 | if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur)) | |
174 | return -EOPNOTSUPP; | |
175 | return 0; | |
176 | } | |
177 | ||
6875cb17 JG |
178 | /* |
179 | * When calling a destroy function during an error unwind we need to pass in | |
180 | * the udata that is sanitized of all user arguments. Ie from the driver | |
181 | * perspective it looks like no udata was passed. | |
182 | */ | |
183 | struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs) | |
184 | { | |
185 | attrs->driver_udata = (struct ib_udata){}; | |
186 | return &attrs->driver_udata; | |
187 | } | |
188 | ||
1e7710f3 | 189 | static struct ib_uverbs_completion_event_file * |
70f06b26 | 190 | _ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs) |
1e7710f3 | 191 | { |
1250c304 | 192 | struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL, |
8313c10f | 193 | fd, attrs); |
1e7710f3 MB |
194 | |
195 | if (IS_ERR(uobj)) | |
7bc871af | 196 | return ERR_CAST(uobj); |
1e7710f3 MB |
197 | |
198 | uverbs_uobject_get(uobj); | |
199 | uobj_put_read(uobj); | |
200 | ||
d0259e82 JG |
201 | return container_of(uobj, struct ib_uverbs_completion_event_file, |
202 | uobj); | |
1e7710f3 | 203 | } |
1250c304 JG |
204 | #define ib_uverbs_lookup_comp_file(_fd, _ufile) \ |
205 | _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile) | |
1e7710f3 | 206 | |
a1123418 | 207 | int ib_alloc_ucontext(struct uverbs_attr_bundle *attrs) |
bc38a6ab | 208 | { |
a1123418 JG |
209 | struct ib_uverbs_file *ufile = attrs->ufile; |
210 | struct ib_ucontext *ucontext; | |
bbd51e88 | 211 | struct ib_device *ib_dev; |
bc38a6ab | 212 | |
a1123418 JG |
213 | ib_dev = srcu_dereference(ufile->device->ib_dev, |
214 | &ufile->device->disassociate_srcu); | |
215 | if (!ib_dev) | |
216 | return -EIO; | |
217 | ||
218 | ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext); | |
219 | if (!ucontext) | |
220 | return -ENOMEM; | |
221 | ||
a1123418 JG |
222 | ucontext->device = ib_dev; |
223 | ucontext->ufile = ufile; | |
224 | xa_init_flags(&ucontext->mmap_xa, XA_FLAGS_ALLOC); | |
13ef5539 LR |
225 | |
226 | rdma_restrack_new(&ucontext->res, RDMA_RESTRACK_CTX); | |
b09c4d70 | 227 | rdma_restrack_set_name(&ucontext->res, NULL); |
a1123418 JG |
228 | attrs->context = ucontext; |
229 | return 0; | |
230 | } | |
231 | ||
232 | int ib_init_ucontext(struct uverbs_attr_bundle *attrs) | |
233 | { | |
234 | struct ib_ucontext *ucontext = attrs->context; | |
235 | struct ib_uverbs_file *file = attrs->ufile; | |
fe9d7822 CM |
236 | int *fd_array; |
237 | int fd_count; | |
a1123418 | 238 | int ret; |
bc38a6ab | 239 | |
da57db25 JG |
240 | if (!down_read_trylock(&file->hw_destroy_rwsem)) |
241 | return -EIO; | |
e951747a | 242 | mutex_lock(&file->ucontext_lock); |
63c47c28 RD |
243 | if (file->ucontext) { |
244 | ret = -EINVAL; | |
245 | goto err; | |
246 | } | |
247 | ||
a1123418 JG |
248 | ret = ib_rdmacg_try_charge(&ucontext->cg_obj, ucontext->device, |
249 | RDMACG_RESOURCE_HCA_HANDLE); | |
43579b5f PP |
250 | if (ret) |
251 | goto err; | |
252 | ||
fe9d7822 CM |
253 | if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_GET_CONTEXT_FD_ARR)) { |
254 | fd_count = uverbs_attr_ptr_get_array_size(attrs, | |
255 | UVERBS_ATTR_GET_CONTEXT_FD_ARR, | |
256 | sizeof(int)); | |
257 | if (fd_count < 0) { | |
258 | ret = fd_count; | |
259 | goto err_uncharge; | |
260 | } | |
261 | ||
262 | fd_array = uverbs_attr_get_alloced_ptr(attrs, | |
263 | UVERBS_ATTR_GET_CONTEXT_FD_ARR); | |
264 | ret = ib_get_ucaps(fd_array, fd_count, &ucontext->enabled_caps); | |
265 | if (ret) | |
266 | goto err_uncharge; | |
267 | } | |
268 | ||
a1123418 JG |
269 | ret = ucontext->device->ops.alloc_ucontext(ucontext, |
270 | &attrs->driver_udata); | |
271 | if (ret) | |
272 | goto err_uncharge; | |
bc38a6ab | 273 | |
b09c4d70 | 274 | rdma_restrack_add(&ucontext->res); |
4f33dd41 | 275 | |
a1123418 JG |
276 | /* |
277 | * Make sure that ib_uverbs_get_ucontext() sees the pointer update | |
278 | * only after all writes to setup the ucontext have completed | |
279 | */ | |
280 | smp_store_release(&file->ucontext, ucontext); | |
281 | ||
282 | mutex_unlock(&file->ucontext_lock); | |
283 | up_read(&file->hw_destroy_rwsem); | |
284 | return 0; | |
fd3c7904 | 285 | |
a1123418 JG |
286 | err_uncharge: |
287 | ib_rdmacg_uncharge(&ucontext->cg_obj, ucontext->device, | |
288 | RDMACG_RESOURCE_HCA_HANDLE); | |
289 | err: | |
290 | mutex_unlock(&file->ucontext_lock); | |
291 | up_read(&file->hw_destroy_rwsem); | |
292 | return ret; | |
293 | } | |
bc38a6ab | 294 | |
a1123418 JG |
295 | static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs) |
296 | { | |
297 | struct ib_uverbs_get_context_resp resp; | |
298 | struct ib_uverbs_get_context cmd; | |
299 | struct ib_device *ib_dev; | |
300 | struct ib_uobject *uobj; | |
301 | int ret; | |
302 | ||
303 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); | |
304 | if (ret) | |
305 | return ret; | |
306 | ||
307 | ret = ib_alloc_ucontext(attrs); | |
308 | if (ret) | |
309 | return ret; | |
3411f9f0 | 310 | |
3e032c0e JG |
311 | uobj = uobj_alloc(UVERBS_OBJECT_ASYNC_EVENT, attrs, &ib_dev); |
312 | if (IS_ERR(uobj)) { | |
313 | ret = PTR_ERR(uobj); | |
a1123418 | 314 | goto err_ucontext; |
6b73597e | 315 | } |
bc38a6ab | 316 | |
a1123418 JG |
317 | resp = (struct ib_uverbs_get_context_resp){ |
318 | .num_comp_vectors = attrs->ufile->device->num_comp_vectors, | |
319 | .async_fd = uobj->id, | |
320 | }; | |
9a073857 JG |
321 | ret = uverbs_response(attrs, &resp, sizeof(resp)); |
322 | if (ret) | |
3e032c0e | 323 | goto err_uobj; |
63c47c28 | 324 | |
a1123418 | 325 | ret = ib_init_ucontext(attrs); |
a2a074ef | 326 | if (ret) |
3e032c0e | 327 | goto err_uobj; |
6b73597e | 328 | |
3e032c0e JG |
329 | ib_uverbs_init_async_event_file( |
330 | container_of(uobj, struct ib_uverbs_async_event_file, uobj)); | |
331 | rdma_alloc_commit_uobject(uobj, attrs); | |
7106a976 | 332 | return 0; |
bc38a6ab | 333 | |
3e032c0e | 334 | err_uobj: |
0ac8903c | 335 | rdma_alloc_abort_uobject(uobj, attrs, false); |
a1123418 | 336 | err_ucontext: |
13ef5539 | 337 | rdma_restrack_put(&attrs->context->res); |
a1123418 JG |
338 | kfree(attrs->context); |
339 | attrs->context = NULL; | |
63c47c28 | 340 | return ret; |
bc38a6ab RD |
341 | } |
342 | ||
bbd51e88 | 343 | static void copy_query_dev_fields(struct ib_ucontext *ucontext, |
02d1aa7a EC |
344 | struct ib_uverbs_query_device_resp *resp, |
345 | struct ib_device_attr *attr) | |
346 | { | |
bbd51e88 JG |
347 | struct ib_device *ib_dev = ucontext->device; |
348 | ||
02d1aa7a | 349 | resp->fw_ver = attr->fw_ver; |
057aec0d | 350 | resp->node_guid = ib_dev->node_guid; |
02d1aa7a EC |
351 | resp->sys_image_guid = attr->sys_image_guid; |
352 | resp->max_mr_size = attr->max_mr_size; | |
353 | resp->page_size_cap = attr->page_size_cap; | |
354 | resp->vendor_id = attr->vendor_id; | |
355 | resp->vendor_part_id = attr->vendor_part_id; | |
356 | resp->hw_ver = attr->hw_ver; | |
357 | resp->max_qp = attr->max_qp; | |
358 | resp->max_qp_wr = attr->max_qp_wr; | |
e945c653 | 359 | resp->device_cap_flags = lower_32_bits(attr->device_cap_flags); |
33023fb8 | 360 | resp->max_sge = min(attr->max_send_sge, attr->max_recv_sge); |
02d1aa7a EC |
361 | resp->max_sge_rd = attr->max_sge_rd; |
362 | resp->max_cq = attr->max_cq; | |
363 | resp->max_cqe = attr->max_cqe; | |
364 | resp->max_mr = attr->max_mr; | |
365 | resp->max_pd = attr->max_pd; | |
366 | resp->max_qp_rd_atom = attr->max_qp_rd_atom; | |
367 | resp->max_ee_rd_atom = attr->max_ee_rd_atom; | |
368 | resp->max_res_rd_atom = attr->max_res_rd_atom; | |
369 | resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom; | |
370 | resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom; | |
371 | resp->atomic_cap = attr->atomic_cap; | |
372 | resp->max_ee = attr->max_ee; | |
373 | resp->max_rdd = attr->max_rdd; | |
374 | resp->max_mw = attr->max_mw; | |
375 | resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp; | |
376 | resp->max_raw_ethy_qp = attr->max_raw_ethy_qp; | |
377 | resp->max_mcast_grp = attr->max_mcast_grp; | |
378 | resp->max_mcast_qp_attach = attr->max_mcast_qp_attach; | |
379 | resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach; | |
380 | resp->max_ah = attr->max_ah; | |
02d1aa7a EC |
381 | resp->max_srq = attr->max_srq; |
382 | resp->max_srq_wr = attr->max_srq_wr; | |
383 | resp->max_srq_sge = attr->max_srq_sge; | |
384 | resp->max_pkeys = attr->max_pkeys; | |
385 | resp->local_ca_ack_delay = attr->local_ca_ack_delay; | |
1fb7f897 | 386 | resp->phys_port_cnt = min_t(u32, ib_dev->phys_port_cnt, U8_MAX); |
02d1aa7a EC |
387 | } |
388 | ||
974d6b4b | 389 | static int ib_uverbs_query_device(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
390 | { |
391 | struct ib_uverbs_query_device cmd; | |
392 | struct ib_uverbs_query_device_resp resp; | |
bbd51e88 | 393 | struct ib_ucontext *ucontext; |
3c2c2094 | 394 | int ret; |
bbd51e88 | 395 | |
8313c10f | 396 | ucontext = ib_uverbs_get_ucontext(attrs); |
bbd51e88 JG |
397 | if (IS_ERR(ucontext)) |
398 | return PTR_ERR(ucontext); | |
bc38a6ab | 399 | |
3c2c2094 JG |
400 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
401 | if (ret) | |
402 | return ret; | |
bc38a6ab | 403 | |
bc38a6ab | 404 | memset(&resp, 0, sizeof resp); |
bbd51e88 | 405 | copy_query_dev_fields(ucontext, &resp, &ucontext->device->attrs); |
bc38a6ab | 406 | |
9a073857 | 407 | return uverbs_response(attrs, &resp, sizeof(resp)); |
bc38a6ab RD |
408 | } |
409 | ||
974d6b4b | 410 | static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
411 | { |
412 | struct ib_uverbs_query_port cmd; | |
413 | struct ib_uverbs_query_port_resp resp; | |
414 | struct ib_port_attr attr; | |
415 | int ret; | |
bbd51e88 JG |
416 | struct ib_ucontext *ucontext; |
417 | struct ib_device *ib_dev; | |
418 | ||
8313c10f | 419 | ucontext = ib_uverbs_get_ucontext(attrs); |
bbd51e88 JG |
420 | if (IS_ERR(ucontext)) |
421 | return PTR_ERR(ucontext); | |
422 | ib_dev = ucontext->device; | |
bc38a6ab | 423 | |
3c2c2094 JG |
424 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
425 | if (ret) | |
426 | return ret; | |
bc38a6ab | 427 | |
057aec0d | 428 | ret = ib_query_port(ib_dev, cmd.port_num, &attr); |
bc38a6ab RD |
429 | if (ret) |
430 | return ret; | |
431 | ||
432 | memset(&resp, 0, sizeof resp); | |
641d1207 | 433 | copy_port_attr_to_resp(&attr, &resp, ib_dev, cmd.port_num); |
bc38a6ab | 434 | |
9a073857 | 435 | return uverbs_response(attrs, &resp, sizeof(resp)); |
bc38a6ab RD |
436 | } |
437 | ||
974d6b4b | 438 | static int ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs) |
bc38a6ab | 439 | { |
16e51f78 | 440 | struct ib_uverbs_alloc_pd_resp resp = {}; |
bc38a6ab | 441 | struct ib_uverbs_alloc_pd cmd; |
bc38a6ab RD |
442 | struct ib_uobject *uobj; |
443 | struct ib_pd *pd; | |
444 | int ret; | |
bbd51e88 | 445 | struct ib_device *ib_dev; |
bc38a6ab | 446 | |
3c2c2094 JG |
447 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
448 | if (ret) | |
449 | return ret; | |
bc38a6ab | 450 | |
8313c10f | 451 | uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ib_dev); |
fd3c7904 MB |
452 | if (IS_ERR(uobj)) |
453 | return PTR_ERR(uobj); | |
bc38a6ab | 454 | |
21a428a0 LR |
455 | pd = rdma_zalloc_drv_obj(ib_dev, ib_pd); |
456 | if (!pd) { | |
457 | ret = -ENOMEM; | |
bc38a6ab RD |
458 | goto err; |
459 | } | |
460 | ||
057aec0d | 461 | pd->device = ib_dev; |
bc38a6ab RD |
462 | pd->uobject = uobj; |
463 | atomic_set(&pd->usecnt, 0); | |
21a428a0 | 464 | |
13ef5539 | 465 | rdma_restrack_new(&pd->res, RDMA_RESTRACK_PD); |
b09c4d70 LR |
466 | rdma_restrack_set_name(&pd->res, NULL); |
467 | ||
ff23dfa1 | 468 | ret = ib_dev->ops.alloc_pd(pd, &attrs->driver_udata); |
21a428a0 LR |
469 | if (ret) |
470 | goto err_alloc; | |
b09c4d70 | 471 | rdma_restrack_add(&pd->res); |
bc38a6ab | 472 | |
16e51f78 LR |
473 | uobj->object = pd; |
474 | uobj_finalize_uobj_create(uobj, attrs); | |
bc38a6ab | 475 | |
16e51f78 LR |
476 | resp.pd_handle = uobj->id; |
477 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
eb9d3cd5 | 478 | |
21a428a0 | 479 | err_alloc: |
13ef5539 | 480 | rdma_restrack_put(&pd->res); |
21a428a0 | 481 | kfree(pd); |
bc38a6ab | 482 | err: |
a6a3797d | 483 | uobj_alloc_abort(uobj, attrs); |
bc38a6ab RD |
484 | return ret; |
485 | } | |
486 | ||
974d6b4b | 487 | static int ib_uverbs_dealloc_pd(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
488 | { |
489 | struct ib_uverbs_dealloc_pd cmd; | |
3c2c2094 | 490 | int ret; |
bc38a6ab | 491 | |
3c2c2094 JG |
492 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
493 | if (ret) | |
494 | return ret; | |
bc38a6ab | 495 | |
7106a976 | 496 | return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, attrs); |
bc38a6ab RD |
497 | } |
498 | ||
53d0bd1e SH |
499 | struct xrcd_table_entry { |
500 | struct rb_node node; | |
501 | struct ib_xrcd *xrcd; | |
502 | struct inode *inode; | |
503 | }; | |
504 | ||
505 | static int xrcd_table_insert(struct ib_uverbs_device *dev, | |
506 | struct inode *inode, | |
507 | struct ib_xrcd *xrcd) | |
508 | { | |
509 | struct xrcd_table_entry *entry, *scan; | |
510 | struct rb_node **p = &dev->xrcd_tree.rb_node; | |
511 | struct rb_node *parent = NULL; | |
512 | ||
513 | entry = kmalloc(sizeof *entry, GFP_KERNEL); | |
514 | if (!entry) | |
515 | return -ENOMEM; | |
516 | ||
517 | entry->xrcd = xrcd; | |
518 | entry->inode = inode; | |
519 | ||
520 | while (*p) { | |
521 | parent = *p; | |
522 | scan = rb_entry(parent, struct xrcd_table_entry, node); | |
523 | ||
524 | if (inode < scan->inode) { | |
525 | p = &(*p)->rb_left; | |
526 | } else if (inode > scan->inode) { | |
527 | p = &(*p)->rb_right; | |
528 | } else { | |
529 | kfree(entry); | |
530 | return -EEXIST; | |
531 | } | |
532 | } | |
533 | ||
534 | rb_link_node(&entry->node, parent, p); | |
535 | rb_insert_color(&entry->node, &dev->xrcd_tree); | |
536 | igrab(inode); | |
537 | return 0; | |
538 | } | |
539 | ||
540 | static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev, | |
541 | struct inode *inode) | |
542 | { | |
543 | struct xrcd_table_entry *entry; | |
544 | struct rb_node *p = dev->xrcd_tree.rb_node; | |
545 | ||
546 | while (p) { | |
547 | entry = rb_entry(p, struct xrcd_table_entry, node); | |
548 | ||
549 | if (inode < entry->inode) | |
550 | p = p->rb_left; | |
551 | else if (inode > entry->inode) | |
552 | p = p->rb_right; | |
553 | else | |
554 | return entry; | |
555 | } | |
556 | ||
557 | return NULL; | |
558 | } | |
559 | ||
560 | static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode) | |
561 | { | |
562 | struct xrcd_table_entry *entry; | |
563 | ||
564 | entry = xrcd_table_search(dev, inode); | |
565 | if (!entry) | |
566 | return NULL; | |
567 | ||
568 | return entry->xrcd; | |
569 | } | |
570 | ||
571 | static void xrcd_table_delete(struct ib_uverbs_device *dev, | |
572 | struct inode *inode) | |
573 | { | |
574 | struct xrcd_table_entry *entry; | |
575 | ||
576 | entry = xrcd_table_search(dev, inode); | |
577 | if (entry) { | |
578 | iput(inode); | |
579 | rb_erase(&entry->node, &dev->xrcd_tree); | |
580 | kfree(entry); | |
581 | } | |
582 | } | |
583 | ||
974d6b4b | 584 | static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs) |
53d0bd1e | 585 | { |
8313c10f | 586 | struct ib_uverbs_device *ibudev = attrs->ufile->device; |
16e51f78 | 587 | struct ib_uverbs_open_xrcd_resp resp = {}; |
53d0bd1e | 588 | struct ib_uverbs_open_xrcd cmd; |
53d0bd1e SH |
589 | struct ib_uxrcd_object *obj; |
590 | struct ib_xrcd *xrcd = NULL; | |
53d0bd1e | 591 | struct inode *inode = NULL; |
53d0bd1e | 592 | int new_xrcd = 0; |
bbd51e88 | 593 | struct ib_device *ib_dev; |
88a2f646 | 594 | struct fd f = EMPTY_FD; |
29f3fe1d | 595 | int ret; |
53d0bd1e | 596 | |
3c2c2094 JG |
597 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
598 | if (ret) | |
599 | return ret; | |
53d0bd1e | 600 | |
8313c10f | 601 | mutex_lock(&ibudev->xrcd_tree_mutex); |
53d0bd1e SH |
602 | |
603 | if (cmd.fd != -1) { | |
604 | /* search for file descriptor */ | |
2903ff01 | 605 | f = fdget(cmd.fd); |
38052c2d | 606 | if (fd_empty(f)) { |
53d0bd1e SH |
607 | ret = -EBADF; |
608 | goto err_tree_mutex_unlock; | |
609 | } | |
610 | ||
1da91ea8 | 611 | inode = file_inode(fd_file(f)); |
8313c10f | 612 | xrcd = find_xrcd(ibudev, inode); |
53d0bd1e SH |
613 | if (!xrcd && !(cmd.oflags & O_CREAT)) { |
614 | /* no file descriptor. Need CREATE flag */ | |
615 | ret = -EAGAIN; | |
616 | goto err_tree_mutex_unlock; | |
617 | } | |
618 | ||
619 | if (xrcd && cmd.oflags & O_EXCL) { | |
620 | ret = -EINVAL; | |
621 | goto err_tree_mutex_unlock; | |
622 | } | |
623 | } | |
624 | ||
8313c10f | 625 | obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs, |
bbd51e88 | 626 | &ib_dev); |
fd3c7904 MB |
627 | if (IS_ERR(obj)) { |
628 | ret = PTR_ERR(obj); | |
53d0bd1e SH |
629 | goto err_tree_mutex_unlock; |
630 | } | |
631 | ||
53d0bd1e | 632 | if (!xrcd) { |
b73efcb2 | 633 | xrcd = ib_alloc_xrcd_user(ib_dev, inode, &attrs->driver_udata); |
53d0bd1e SH |
634 | if (IS_ERR(xrcd)) { |
635 | ret = PTR_ERR(xrcd); | |
636 | goto err; | |
637 | } | |
53d0bd1e SH |
638 | new_xrcd = 1; |
639 | } | |
640 | ||
641 | atomic_set(&obj->refcnt, 0); | |
642 | obj->uobject.object = xrcd; | |
53d0bd1e SH |
643 | |
644 | if (inode) { | |
645 | if (new_xrcd) { | |
646 | /* create new inode/xrcd table entry */ | |
8313c10f | 647 | ret = xrcd_table_insert(ibudev, inode, xrcd); |
53d0bd1e | 648 | if (ret) |
fd3c7904 | 649 | goto err_dealloc_xrcd; |
53d0bd1e SH |
650 | } |
651 | atomic_inc(&xrcd->usecnt); | |
652 | } | |
653 | ||
38052c2d | 654 | fdput(f); |
53d0bd1e | 655 | |
8313c10f | 656 | mutex_unlock(&ibudev->xrcd_tree_mutex); |
16e51f78 | 657 | uobj_finalize_uobj_create(&obj->uobject, attrs); |
1ff5325c | 658 | |
16e51f78 LR |
659 | resp.xrcd_handle = obj->uobject.id; |
660 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
53d0bd1e | 661 | |
fd3c7904 | 662 | err_dealloc_xrcd: |
b73efcb2 | 663 | ib_dealloc_xrcd_user(xrcd, uverbs_get_cleared_udata(attrs)); |
53d0bd1e SH |
664 | |
665 | err: | |
a6a3797d | 666 | uobj_alloc_abort(&obj->uobject, attrs); |
53d0bd1e SH |
667 | |
668 | err_tree_mutex_unlock: | |
38052c2d | 669 | fdput(f); |
53d0bd1e | 670 | |
8313c10f | 671 | mutex_unlock(&ibudev->xrcd_tree_mutex); |
53d0bd1e SH |
672 | |
673 | return ret; | |
674 | } | |
675 | ||
974d6b4b | 676 | static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs) |
53d0bd1e SH |
677 | { |
678 | struct ib_uverbs_close_xrcd cmd; | |
3c2c2094 | 679 | int ret; |
53d0bd1e | 680 | |
3c2c2094 JG |
681 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
682 | if (ret) | |
683 | return ret; | |
53d0bd1e | 684 | |
7106a976 | 685 | return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs); |
53d0bd1e SH |
686 | } |
687 | ||
c4367a26 | 688 | int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd, |
bdeacabd SR |
689 | enum rdma_remove_reason why, |
690 | struct uverbs_attr_bundle *attrs) | |
53d0bd1e SH |
691 | { |
692 | struct inode *inode; | |
6be60aed | 693 | int ret; |
bdeacabd | 694 | struct ib_uverbs_device *dev = attrs->ufile->device; |
53d0bd1e SH |
695 | |
696 | inode = xrcd->inode; | |
697 | if (inode && !atomic_dec_and_test(&xrcd->usecnt)) | |
6be60aed | 698 | return 0; |
53d0bd1e | 699 | |
b73efcb2 | 700 | ret = ib_dealloc_xrcd_user(xrcd, &attrs->driver_udata); |
efa968ee | 701 | if (ret) { |
6be60aed | 702 | atomic_inc(&xrcd->usecnt); |
1c77483e YH |
703 | return ret; |
704 | } | |
705 | ||
706 | if (inode) | |
53d0bd1e | 707 | xrcd_table_delete(dev, inode); |
6be60aed | 708 | |
efa968ee | 709 | return 0; |
53d0bd1e SH |
710 | } |
711 | ||
974d6b4b | 712 | static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs) |
bc38a6ab | 713 | { |
16e51f78 | 714 | struct ib_uverbs_reg_mr_resp resp = {}; |
bc38a6ab | 715 | struct ib_uverbs_reg_mr cmd; |
f7c6a7b5 | 716 | struct ib_uobject *uobj; |
bc38a6ab RD |
717 | struct ib_pd *pd; |
718 | struct ib_mr *mr; | |
719 | int ret; | |
bbd51e88 | 720 | struct ib_device *ib_dev; |
bc38a6ab | 721 | |
3c2c2094 JG |
722 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
723 | if (ret) | |
724 | return ret; | |
bc38a6ab | 725 | |
bc38a6ab RD |
726 | if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) |
727 | return -EINVAL; | |
728 | ||
8313c10f | 729 | uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev); |
fd3c7904 MB |
730 | if (IS_ERR(uobj)) |
731 | return PTR_ERR(uobj); | |
bc38a6ab | 732 | |
adac4cb3 JG |
733 | ret = ib_check_mr_access(ib_dev, cmd.access_flags); |
734 | if (ret) | |
735 | goto err_free; | |
736 | ||
8313c10f | 737 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); |
81f8f745 MS |
738 | if (IS_ERR(pd)) { |
739 | ret = PTR_ERR(pd); | |
f7c6a7b5 | 740 | goto err_free; |
aaf1aef5 | 741 | } |
bc38a6ab | 742 | |
3023a1e9 KH |
743 | mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va, |
744 | cmd.access_flags, | |
745 | &attrs->driver_udata); | |
bc38a6ab RD |
746 | if (IS_ERR(mr)) { |
747 | ret = PTR_ERR(mr); | |
9ead190b | 748 | goto err_put; |
bc38a6ab RD |
749 | } |
750 | ||
751 | mr->device = pd->device; | |
752 | mr->pd = pd; | |
a0bc099a | 753 | mr->type = IB_MR_TYPE_USER; |
54e7e48b | 754 | mr->dm = NULL; |
7c717d3a | 755 | mr->sig_attrs = NULL; |
f7c6a7b5 | 756 | mr->uobject = uobj; |
bc38a6ab | 757 | atomic_inc(&pd->usecnt); |
04c0a5fc | 758 | mr->iova = cmd.hca_va; |
241f9a27 | 759 | mr->length = cmd.length; |
13ef5539 LR |
760 | |
761 | rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR); | |
b09c4d70 LR |
762 | rdma_restrack_set_name(&mr->res, NULL); |
763 | rdma_restrack_add(&mr->res); | |
bc38a6ab | 764 | |
f7c6a7b5 | 765 | uobj->object = mr; |
fd3c7904 | 766 | uobj_put_obj_read(pd); |
16e51f78 | 767 | uobj_finalize_uobj_create(uobj, attrs); |
eb9d3cd5 | 768 | |
16e51f78 LR |
769 | resp.lkey = mr->lkey; |
770 | resp.rkey = mr->rkey; | |
771 | resp.mr_handle = uobj->id; | |
772 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
bc38a6ab | 773 | |
9ead190b | 774 | err_put: |
fd3c7904 | 775 | uobj_put_obj_read(pd); |
bc38a6ab | 776 | err_free: |
a6a3797d | 777 | uobj_alloc_abort(uobj, attrs); |
bc38a6ab RD |
778 | return ret; |
779 | } | |
780 | ||
974d6b4b | 781 | static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs) |
7e6edb9b MB |
782 | { |
783 | struct ib_uverbs_rereg_mr cmd; | |
784 | struct ib_uverbs_rereg_mr_resp resp; | |
7e6edb9b | 785 | struct ib_mr *mr; |
7e6edb9b MB |
786 | int ret; |
787 | struct ib_uobject *uobj; | |
6e0954b1 JG |
788 | struct ib_uobject *new_uobj; |
789 | struct ib_device *ib_dev; | |
790 | struct ib_pd *orig_pd; | |
791 | struct ib_pd *new_pd; | |
792 | struct ib_mr *new_mr; | |
7e6edb9b | 793 | |
3c2c2094 JG |
794 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
795 | if (ret) | |
796 | return ret; | |
7e6edb9b | 797 | |
b9653b31 | 798 | if (!cmd.flags) |
7e6edb9b MB |
799 | return -EINVAL; |
800 | ||
b9653b31 JG |
801 | if (cmd.flags & ~IB_MR_REREG_SUPPORTED) |
802 | return -EOPNOTSUPP; | |
803 | ||
7e6edb9b | 804 | if ((cmd.flags & IB_MR_REREG_TRANS) && |
b9653b31 JG |
805 | (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) |
806 | return -EINVAL; | |
7e6edb9b | 807 | |
8313c10f | 808 | uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs); |
fd3c7904 MB |
809 | if (IS_ERR(uobj)) |
810 | return PTR_ERR(uobj); | |
7e6edb9b MB |
811 | |
812 | mr = uobj->object; | |
813 | ||
5ccbf63f AL |
814 | if (mr->dm) { |
815 | ret = -EINVAL; | |
816 | goto put_uobjs; | |
817 | } | |
818 | ||
7e6edb9b | 819 | if (cmd.flags & IB_MR_REREG_ACCESS) { |
adac4cb3 | 820 | ret = ib_check_mr_access(mr->device, cmd.access_flags); |
7e6edb9b MB |
821 | if (ret) |
822 | goto put_uobjs; | |
823 | } | |
824 | ||
6e0954b1 | 825 | orig_pd = mr->pd; |
7e6edb9b | 826 | if (cmd.flags & IB_MR_REREG_PD) { |
6e0954b1 JG |
827 | new_pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, |
828 | attrs); | |
81f8f745 MS |
829 | if (IS_ERR(new_pd)) { |
830 | ret = PTR_ERR(new_pd); | |
7e6edb9b MB |
831 | goto put_uobjs; |
832 | } | |
6e0954b1 JG |
833 | } else { |
834 | new_pd = mr->pd; | |
7e6edb9b MB |
835 | } |
836 | ||
6e0954b1 JG |
837 | /* |
838 | * The driver might create a new HW object as part of the rereg, we need | |
839 | * to have a uobject ready to hold it. | |
840 | */ | |
841 | new_uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev); | |
842 | if (IS_ERR(new_uobj)) { | |
843 | ret = PTR_ERR(new_uobj); | |
7e6edb9b | 844 | goto put_uobj_pd; |
6e0954b1 | 845 | } |
e278173f | 846 | |
6e0954b1 JG |
847 | new_mr = ib_dev->ops.rereg_user_mr(mr, cmd.flags, cmd.start, cmd.length, |
848 | cmd.hca_va, cmd.access_flags, new_pd, | |
849 | &attrs->driver_udata); | |
850 | if (IS_ERR(new_mr)) { | |
851 | ret = PTR_ERR(new_mr); | |
852 | goto put_new_uobj; | |
7e6edb9b | 853 | } |
6e0954b1 JG |
854 | if (new_mr) { |
855 | new_mr->device = new_pd->device; | |
856 | new_mr->pd = new_pd; | |
857 | new_mr->type = IB_MR_TYPE_USER; | |
6e0954b1 JG |
858 | new_mr->uobject = uobj; |
859 | atomic_inc(&new_pd->usecnt); | |
6e0954b1 JG |
860 | new_uobj->object = new_mr; |
861 | ||
862 | rdma_restrack_new(&new_mr->res, RDMA_RESTRACK_MR); | |
863 | rdma_restrack_set_name(&new_mr->res, NULL); | |
864 | rdma_restrack_add(&new_mr->res); | |
7e6edb9b | 865 | |
6e0954b1 JG |
866 | /* |
867 | * The new uobj for the new HW object is put into the same spot | |
868 | * in the IDR and the old uobj & HW object is deleted. | |
869 | */ | |
870 | rdma_assign_uobject(uobj, new_uobj, attrs); | |
871 | rdma_alloc_commit_uobject(new_uobj, attrs); | |
872 | uobj_put_destroy(uobj); | |
873 | new_uobj = NULL; | |
874 | uobj = NULL; | |
875 | mr = new_mr; | |
876 | } else { | |
877 | if (cmd.flags & IB_MR_REREG_PD) { | |
878 | atomic_dec(&orig_pd->usecnt); | |
879 | mr->pd = new_pd; | |
880 | atomic_inc(&new_pd->usecnt); | |
881 | } | |
241f9a27 | 882 | if (cmd.flags & IB_MR_REREG_TRANS) { |
6e0954b1 | 883 | mr->iova = cmd.hca_va; |
241f9a27 DM |
884 | mr->length = cmd.length; |
885 | } | |
6e0954b1 | 886 | } |
04c0a5fc | 887 | |
7e6edb9b MB |
888 | memset(&resp, 0, sizeof(resp)); |
889 | resp.lkey = mr->lkey; | |
890 | resp.rkey = mr->rkey; | |
891 | ||
9a073857 | 892 | ret = uverbs_response(attrs, &resp, sizeof(resp)); |
7e6edb9b | 893 | |
6e0954b1 JG |
894 | put_new_uobj: |
895 | if (new_uobj) | |
896 | uobj_alloc_abort(new_uobj, attrs); | |
7e6edb9b MB |
897 | put_uobj_pd: |
898 | if (cmd.flags & IB_MR_REREG_PD) | |
6e0954b1 | 899 | uobj_put_obj_read(new_pd); |
7e6edb9b MB |
900 | |
901 | put_uobjs: | |
6e0954b1 JG |
902 | if (uobj) |
903 | uobj_put_write(uobj); | |
7e6edb9b MB |
904 | |
905 | return ret; | |
906 | } | |
907 | ||
974d6b4b | 908 | static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
909 | { |
910 | struct ib_uverbs_dereg_mr cmd; | |
3c2c2094 | 911 | int ret; |
bc38a6ab | 912 | |
3c2c2094 JG |
913 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
914 | if (ret) | |
915 | return ret; | |
bc38a6ab | 916 | |
7106a976 | 917 | return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs); |
bc38a6ab RD |
918 | } |
919 | ||
974d6b4b | 920 | static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs) |
6b52a12b SM |
921 | { |
922 | struct ib_uverbs_alloc_mw cmd; | |
d18bb3e1 | 923 | struct ib_uverbs_alloc_mw_resp resp = {}; |
6b52a12b SM |
924 | struct ib_uobject *uobj; |
925 | struct ib_pd *pd; | |
926 | struct ib_mw *mw; | |
927 | int ret; | |
bbd51e88 | 928 | struct ib_device *ib_dev; |
6b52a12b | 929 | |
3c2c2094 JG |
930 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
931 | if (ret) | |
932 | return ret; | |
6b52a12b | 933 | |
8313c10f | 934 | uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev); |
fd3c7904 MB |
935 | if (IS_ERR(uobj)) |
936 | return PTR_ERR(uobj); | |
6b52a12b | 937 | |
8313c10f | 938 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); |
81f8f745 MS |
939 | if (IS_ERR(pd)) { |
940 | ret = PTR_ERR(pd); | |
6b52a12b SM |
941 | goto err_free; |
942 | } | |
943 | ||
d0e02bf6 NO |
944 | if (cmd.mw_type != IB_MW_TYPE_1 && cmd.mw_type != IB_MW_TYPE_2) { |
945 | ret = -EINVAL; | |
946 | goto err_put; | |
947 | } | |
948 | ||
d18bb3e1 LR |
949 | mw = rdma_zalloc_drv_obj(ib_dev, ib_mw); |
950 | if (!mw) { | |
951 | ret = -ENOMEM; | |
6b52a12b SM |
952 | goto err_put; |
953 | } | |
954 | ||
d18bb3e1 LR |
955 | mw->device = ib_dev; |
956 | mw->pd = pd; | |
6b52a12b | 957 | mw->uobject = uobj; |
d18bb3e1 LR |
958 | mw->type = cmd.mw_type; |
959 | ||
960 | ret = pd->device->ops.alloc_mw(mw, &attrs->driver_udata); | |
961 | if (ret) | |
962 | goto err_alloc; | |
963 | ||
6b52a12b SM |
964 | atomic_inc(&pd->usecnt); |
965 | ||
966 | uobj->object = mw; | |
16e51f78 LR |
967 | uobj_put_obj_read(pd); |
968 | uobj_finalize_uobj_create(uobj, attrs); | |
6b52a12b | 969 | |
16e51f78 | 970 | resp.rkey = mw->rkey; |
6b52a12b | 971 | resp.mw_handle = uobj->id; |
16e51f78 | 972 | return uverbs_response(attrs, &resp, sizeof(resp)); |
6b52a12b | 973 | |
d18bb3e1 LR |
974 | err_alloc: |
975 | kfree(mw); | |
6b52a12b | 976 | err_put: |
fd3c7904 | 977 | uobj_put_obj_read(pd); |
6b52a12b | 978 | err_free: |
a6a3797d | 979 | uobj_alloc_abort(uobj, attrs); |
6b52a12b SM |
980 | return ret; |
981 | } | |
982 | ||
974d6b4b | 983 | static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs) |
6b52a12b SM |
984 | { |
985 | struct ib_uverbs_dealloc_mw cmd; | |
3c2c2094 | 986 | int ret; |
6b52a12b | 987 | |
3c2c2094 JG |
988 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
989 | if (ret) | |
990 | return ret; | |
6b52a12b | 991 | |
7106a976 | 992 | return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs); |
6b52a12b SM |
993 | } |
994 | ||
974d6b4b | 995 | static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs) |
6b73597e RD |
996 | { |
997 | struct ib_uverbs_create_comp_channel cmd; | |
998 | struct ib_uverbs_create_comp_channel_resp resp; | |
1e7710f3 MB |
999 | struct ib_uobject *uobj; |
1000 | struct ib_uverbs_completion_event_file *ev_file; | |
bbd51e88 | 1001 | struct ib_device *ib_dev; |
9a073857 | 1002 | int ret; |
6b73597e | 1003 | |
3c2c2094 JG |
1004 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1005 | if (ret) | |
1006 | return ret; | |
6b73597e | 1007 | |
8313c10f | 1008 | uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev); |
1e7710f3 MB |
1009 | if (IS_ERR(uobj)) |
1010 | return PTR_ERR(uobj); | |
b1e4594b | 1011 | |
1e7710f3 | 1012 | ev_file = container_of(uobj, struct ib_uverbs_completion_event_file, |
d0259e82 | 1013 | uobj); |
db1b5ddd | 1014 | ib_uverbs_init_event_queue(&ev_file->ev_queue); |
16e51f78 | 1015 | uobj_finalize_uobj_create(uobj, attrs); |
6b73597e | 1016 | |
16e51f78 LR |
1017 | resp.fd = uobj->id; |
1018 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
6b73597e RD |
1019 | } |
1020 | ||
16e51f78 LR |
1021 | static int create_cq(struct uverbs_attr_bundle *attrs, |
1022 | struct ib_uverbs_ex_create_cq *cmd) | |
bc38a6ab | 1023 | { |
9ead190b | 1024 | struct ib_ucq_object *obj; |
1e7710f3 | 1025 | struct ib_uverbs_completion_event_file *ev_file = NULL; |
bc38a6ab RD |
1026 | struct ib_cq *cq; |
1027 | int ret; | |
16e51f78 | 1028 | struct ib_uverbs_ex_create_cq_resp resp = {}; |
bcf4c1ea | 1029 | struct ib_cq_init_attr attr = {}; |
bbd51e88 | 1030 | struct ib_device *ib_dev; |
21885586 | 1031 | |
8313c10f | 1032 | if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors) |
16e51f78 | 1033 | return -EINVAL; |
bc38a6ab | 1034 | |
8313c10f | 1035 | obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs, |
bbd51e88 | 1036 | &ib_dev); |
fd3c7904 | 1037 | if (IS_ERR(obj)) |
16e51f78 | 1038 | return PTR_ERR(obj); |
9ead190b | 1039 | |
565197dd | 1040 | if (cmd->comp_channel >= 0) { |
8313c10f | 1041 | ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs); |
1e7710f3 MB |
1042 | if (IS_ERR(ev_file)) { |
1043 | ret = PTR_ERR(ev_file); | |
ac4e7b35 JM |
1044 | goto err; |
1045 | } | |
1046 | } | |
1047 | ||
4ec1dcfc | 1048 | obj->uevent.uobject.user_handle = cmd->user_handle; |
9ead190b | 1049 | INIT_LIST_HEAD(&obj->comp_list); |
4ec1dcfc | 1050 | INIT_LIST_HEAD(&obj->uevent.event_list); |
bc38a6ab | 1051 | |
565197dd MB |
1052 | attr.cqe = cmd->cqe; |
1053 | attr.comp_vector = cmd->comp_vector; | |
ece9ca97 | 1054 | attr.flags = cmd->flags; |
565197dd | 1055 | |
e39afe3d LR |
1056 | cq = rdma_zalloc_drv_obj(ib_dev, ib_cq); |
1057 | if (!cq) { | |
1058 | ret = -ENOMEM; | |
9ead190b | 1059 | goto err_file; |
bc38a6ab | 1060 | } |
057aec0d | 1061 | cq->device = ib_dev; |
5bd48c18 | 1062 | cq->uobject = obj; |
bc38a6ab RD |
1063 | cq->comp_handler = ib_uverbs_comp_handler; |
1064 | cq->event_handler = ib_uverbs_cq_event_handler; | |
699a2d5b | 1065 | cq->cq_context = ev_file ? &ev_file->ev_queue : NULL; |
bc38a6ab RD |
1066 | atomic_set(&cq->usecnt, 0); |
1067 | ||
13ef5539 | 1068 | rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ); |
b09c4d70 LR |
1069 | rdma_restrack_set_name(&cq->res, NULL); |
1070 | ||
dd6d7f85 | 1071 | ret = ib_dev->ops.create_cq(cq, &attr, attrs); |
e39afe3d LR |
1072 | if (ret) |
1073 | goto err_free; | |
b09c4d70 | 1074 | rdma_restrack_add(&cq->res); |
e39afe3d | 1075 | |
4ec1dcfc | 1076 | obj->uevent.uobject.object = cq; |
98a8890f YH |
1077 | obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file); |
1078 | if (obj->uevent.event_file) | |
1079 | uverbs_uobject_get(&obj->uevent.event_file->uobj); | |
16e51f78 | 1080 | uobj_finalize_uobj_create(&obj->uevent.uobject, attrs); |
98a8890f | 1081 | |
4ec1dcfc | 1082 | resp.base.cq_handle = obj->uevent.uobject.id; |
16e51f78 | 1083 | resp.base.cqe = cq->cqe; |
29a29d18 | 1084 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); |
16e51f78 | 1085 | return uverbs_response(attrs, &resp, sizeof(resp)); |
565197dd | 1086 | |
e39afe3d | 1087 | err_free: |
13ef5539 | 1088 | rdma_restrack_put(&cq->res); |
e39afe3d | 1089 | kfree(cq); |
9ead190b | 1090 | err_file: |
ac4e7b35 | 1091 | if (ev_file) |
5c55cfd6 | 1092 | ib_uverbs_release_ucq(ev_file, obj); |
9ead190b | 1093 | err: |
4ec1dcfc | 1094 | uobj_alloc_abort(&obj->uevent.uobject, attrs); |
16e51f78 | 1095 | return ret; |
565197dd MB |
1096 | } |
1097 | ||
974d6b4b | 1098 | static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs) |
565197dd MB |
1099 | { |
1100 | struct ib_uverbs_create_cq cmd; | |
1101 | struct ib_uverbs_ex_create_cq cmd_ex; | |
3c2c2094 | 1102 | int ret; |
565197dd | 1103 | |
3c2c2094 JG |
1104 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1105 | if (ret) | |
1106 | return ret; | |
565197dd | 1107 | |
565197dd MB |
1108 | memset(&cmd_ex, 0, sizeof(cmd_ex)); |
1109 | cmd_ex.user_handle = cmd.user_handle; | |
1110 | cmd_ex.cqe = cmd.cqe; | |
1111 | cmd_ex.comp_vector = cmd.comp_vector; | |
1112 | cmd_ex.comp_channel = cmd.comp_channel; | |
1113 | ||
16e51f78 | 1114 | return create_cq(attrs, &cmd_ex); |
565197dd MB |
1115 | } |
1116 | ||
974d6b4b | 1117 | static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs) |
565197dd | 1118 | { |
565197dd | 1119 | struct ib_uverbs_ex_create_cq cmd; |
29a29d18 | 1120 | int ret; |
565197dd | 1121 | |
29a29d18 JG |
1122 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1123 | if (ret) | |
1124 | return ret; | |
565197dd MB |
1125 | |
1126 | if (cmd.comp_mask) | |
1127 | return -EINVAL; | |
1128 | ||
1129 | if (cmd.reserved) | |
1130 | return -EINVAL; | |
1131 | ||
16e51f78 | 1132 | return create_cq(attrs, &cmd); |
bc38a6ab RD |
1133 | } |
1134 | ||
974d6b4b | 1135 | static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs) |
33b9b3ee RD |
1136 | { |
1137 | struct ib_uverbs_resize_cq cmd; | |
f7a6cb7b | 1138 | struct ib_uverbs_resize_cq_resp resp = {}; |
33b9b3ee | 1139 | struct ib_cq *cq; |
29f3fe1d | 1140 | int ret; |
33b9b3ee | 1141 | |
3c2c2094 JG |
1142 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1143 | if (ret) | |
1144 | return ret; | |
33b9b3ee | 1145 | |
8313c10f | 1146 | cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
81f8f745 MS |
1147 | if (IS_ERR(cq)) |
1148 | return PTR_ERR(cq); | |
33b9b3ee | 1149 | |
3023a1e9 | 1150 | ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata); |
33b9b3ee RD |
1151 | if (ret) |
1152 | goto out; | |
1153 | ||
33b9b3ee RD |
1154 | resp.cqe = cq->cqe; |
1155 | ||
9a073857 | 1156 | ret = uverbs_response(attrs, &resp, sizeof(resp)); |
33b9b3ee | 1157 | out: |
5bd48c18 JG |
1158 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, |
1159 | UVERBS_LOOKUP_READ); | |
33b9b3ee | 1160 | |
7106a976 | 1161 | return ret; |
33b9b3ee RD |
1162 | } |
1163 | ||
7db20ecd HD |
1164 | static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest, |
1165 | struct ib_wc *wc) | |
7182afea DC |
1166 | { |
1167 | struct ib_uverbs_wc tmp; | |
1168 | ||
1169 | tmp.wr_id = wc->wr_id; | |
1170 | tmp.status = wc->status; | |
1171 | tmp.opcode = wc->opcode; | |
1172 | tmp.vendor_err = wc->vendor_err; | |
1173 | tmp.byte_len = wc->byte_len; | |
c966ea12 | 1174 | tmp.ex.imm_data = wc->ex.imm_data; |
7182afea DC |
1175 | tmp.qp_num = wc->qp->qp_num; |
1176 | tmp.src_qp = wc->src_qp; | |
1177 | tmp.wc_flags = wc->wc_flags; | |
1178 | tmp.pkey_index = wc->pkey_index; | |
7db20ecd | 1179 | if (rdma_cap_opa_ah(ib_dev, wc->port_num)) |
62ede777 | 1180 | tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid); |
7db20ecd | 1181 | else |
62ede777 | 1182 | tmp.slid = ib_lid_cpu16(wc->slid); |
7182afea DC |
1183 | tmp.sl = wc->sl; |
1184 | tmp.dlid_path_bits = wc->dlid_path_bits; | |
1185 | tmp.port_num = wc->port_num; | |
1186 | tmp.reserved = 0; | |
1187 | ||
1188 | if (copy_to_user(dest, &tmp, sizeof tmp)) | |
1189 | return -EFAULT; | |
1190 | ||
1191 | return 0; | |
1192 | } | |
1193 | ||
974d6b4b | 1194 | static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
1195 | { |
1196 | struct ib_uverbs_poll_cq cmd; | |
7182afea DC |
1197 | struct ib_uverbs_poll_cq_resp resp; |
1198 | u8 __user *header_ptr; | |
1199 | u8 __user *data_ptr; | |
67cdb40c | 1200 | struct ib_cq *cq; |
7182afea DC |
1201 | struct ib_wc wc; |
1202 | int ret; | |
67cdb40c | 1203 | |
3c2c2094 JG |
1204 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1205 | if (ret) | |
1206 | return ret; | |
67cdb40c | 1207 | |
8313c10f | 1208 | cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
81f8f745 MS |
1209 | if (IS_ERR(cq)) |
1210 | return PTR_ERR(cq); | |
67cdb40c | 1211 | |
7182afea | 1212 | /* we copy a struct ib_uverbs_poll_cq_resp to user space */ |
c2a939fd | 1213 | header_ptr = attrs->ucore.outbuf; |
7182afea | 1214 | data_ptr = header_ptr + sizeof resp; |
9ead190b | 1215 | |
7182afea DC |
1216 | memset(&resp, 0, sizeof resp); |
1217 | while (resp.count < cmd.ne) { | |
1218 | ret = ib_poll_cq(cq, 1, &wc); | |
1219 | if (ret < 0) | |
1220 | goto out_put; | |
1221 | if (!ret) | |
1222 | break; | |
1223 | ||
bbd51e88 | 1224 | ret = copy_wc_to_user(cq->device, data_ptr, &wc); |
7182afea DC |
1225 | if (ret) |
1226 | goto out_put; | |
1227 | ||
1228 | data_ptr += sizeof(struct ib_uverbs_wc); | |
1229 | ++resp.count; | |
67cdb40c RD |
1230 | } |
1231 | ||
7182afea | 1232 | if (copy_to_user(header_ptr, &resp, sizeof resp)) { |
67cdb40c | 1233 | ret = -EFAULT; |
7182afea DC |
1234 | goto out_put; |
1235 | } | |
9a778678 | 1236 | ret = 0; |
67cdb40c | 1237 | |
d6f4a21f JG |
1238 | if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT)) |
1239 | ret = uverbs_output_written(attrs, UVERBS_ATTR_CORE_OUT); | |
1240 | ||
7182afea | 1241 | out_put: |
5bd48c18 JG |
1242 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, |
1243 | UVERBS_LOOKUP_READ); | |
7182afea | 1244 | return ret; |
67cdb40c RD |
1245 | } |
1246 | ||
974d6b4b | 1247 | static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
1248 | { |
1249 | struct ib_uverbs_req_notify_cq cmd; | |
1250 | struct ib_cq *cq; | |
3c2c2094 | 1251 | int ret; |
67cdb40c | 1252 | |
3c2c2094 JG |
1253 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1254 | if (ret) | |
1255 | return ret; | |
67cdb40c | 1256 | |
8313c10f | 1257 | cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
81f8f745 MS |
1258 | if (IS_ERR(cq)) |
1259 | return PTR_ERR(cq); | |
67cdb40c | 1260 | |
9ead190b RD |
1261 | ib_req_notify_cq(cq, cmd.solicited_only ? |
1262 | IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); | |
1263 | ||
5bd48c18 JG |
1264 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, |
1265 | UVERBS_LOOKUP_READ); | |
7106a976 | 1266 | return 0; |
67cdb40c RD |
1267 | } |
1268 | ||
974d6b4b | 1269 | static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs) |
bc38a6ab | 1270 | { |
63aaf647 RD |
1271 | struct ib_uverbs_destroy_cq cmd; |
1272 | struct ib_uverbs_destroy_cq_resp resp; | |
9ead190b | 1273 | struct ib_uobject *uobj; |
9ead190b | 1274 | struct ib_ucq_object *obj; |
3c2c2094 | 1275 | int ret; |
bc38a6ab | 1276 | |
3c2c2094 JG |
1277 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1278 | if (ret) | |
1279 | return ret; | |
bc38a6ab | 1280 | |
8313c10f | 1281 | uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
fd3c7904 MB |
1282 | if (IS_ERR(uobj)) |
1283 | return PTR_ERR(uobj); | |
1284 | ||
4ec1dcfc | 1285 | obj = container_of(uobj, struct ib_ucq_object, uevent.uobject); |
fd3c7904 | 1286 | memset(&resp, 0, sizeof(resp)); |
9ead190b | 1287 | resp.comp_events_reported = obj->comp_events_reported; |
4ec1dcfc | 1288 | resp.async_events_reported = obj->uevent.events_reported; |
63aaf647 | 1289 | |
32ed5c00 JG |
1290 | uobj_put_destroy(uobj); |
1291 | ||
9a073857 | 1292 | return uverbs_response(attrs, &resp, sizeof(resp)); |
bc38a6ab RD |
1293 | } |
1294 | ||
8313c10f | 1295 | static int create_qp(struct uverbs_attr_bundle *attrs, |
ece9ca97 | 1296 | struct ib_uverbs_ex_create_qp *cmd) |
bc38a6ab | 1297 | { |
6d8a7497 EBE |
1298 | struct ib_uqp_object *obj; |
1299 | struct ib_device *device; | |
1300 | struct ib_pd *pd = NULL; | |
1301 | struct ib_xrcd *xrcd = NULL; | |
fd3c7904 | 1302 | struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT); |
6d8a7497 EBE |
1303 | struct ib_cq *scq = NULL, *rcq = NULL; |
1304 | struct ib_srq *srq = NULL; | |
1305 | struct ib_qp *qp; | |
c70285f8 | 1306 | struct ib_qp_init_attr attr = {}; |
16e51f78 | 1307 | struct ib_uverbs_ex_create_qp_resp resp = {}; |
6d8a7497 | 1308 | int ret; |
c70285f8 YH |
1309 | struct ib_rwq_ind_table *ind_tbl = NULL; |
1310 | bool has_sq = true; | |
bbd51e88 | 1311 | struct ib_device *ib_dev; |
6d8a7497 | 1312 | |
5807bb32 LR |
1313 | switch (cmd->qp_type) { |
1314 | case IB_QPT_RAW_PACKET: | |
1315 | if (!capable(CAP_NET_RAW)) | |
1316 | return -EPERM; | |
1317 | break; | |
1318 | case IB_QPT_RC: | |
1319 | case IB_QPT_UC: | |
1320 | case IB_QPT_UD: | |
1321 | case IB_QPT_XRC_INI: | |
1322 | case IB_QPT_XRC_TGT: | |
1323 | case IB_QPT_DRIVER: | |
1324 | break; | |
1325 | default: | |
1326 | return -EINVAL; | |
1327 | } | |
c938a616 | 1328 | |
8313c10f | 1329 | obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs, |
bbd51e88 | 1330 | &ib_dev); |
fd3c7904 MB |
1331 | if (IS_ERR(obj)) |
1332 | return PTR_ERR(obj); | |
1333 | obj->uxrcd = NULL; | |
1334 | obj->uevent.uobject.user_handle = cmd->user_handle; | |
f48b7269 | 1335 | mutex_init(&obj->mcast_lock); |
bc38a6ab | 1336 | |
ece9ca97 | 1337 | if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) { |
2cc1e3b8 JG |
1338 | ind_tbl = uobj_get_obj_read(rwq_ind_table, |
1339 | UVERBS_OBJECT_RWQ_IND_TBL, | |
8313c10f | 1340 | cmd->rwq_ind_tbl_handle, attrs); |
81f8f745 MS |
1341 | if (IS_ERR(ind_tbl)) { |
1342 | ret = PTR_ERR(ind_tbl); | |
c70285f8 YH |
1343 | goto err_put; |
1344 | } | |
1345 | ||
1346 | attr.rwq_ind_tbl = ind_tbl; | |
1347 | } | |
1348 | ||
c70285f8 YH |
1349 | if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) { |
1350 | ret = -EINVAL; | |
1351 | goto err_put; | |
1352 | } | |
1353 | ||
1354 | if (ind_tbl && !cmd->max_send_wr) | |
1355 | has_sq = false; | |
bc38a6ab | 1356 | |
6d8a7497 | 1357 | if (cmd->qp_type == IB_QPT_XRC_TGT) { |
1f7ff9d5 | 1358 | xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle, |
8313c10f | 1359 | attrs); |
fd3c7904 MB |
1360 | |
1361 | if (IS_ERR(xrcd_uobj)) { | |
1362 | ret = -EINVAL; | |
1363 | goto err_put; | |
1364 | } | |
1365 | ||
1366 | xrcd = (struct ib_xrcd *)xrcd_uobj->object; | |
b93f3c18 SH |
1367 | if (!xrcd) { |
1368 | ret = -EINVAL; | |
1369 | goto err_put; | |
1370 | } | |
1371 | device = xrcd->device; | |
9977f4f6 | 1372 | } else { |
6d8a7497 EBE |
1373 | if (cmd->qp_type == IB_QPT_XRC_INI) { |
1374 | cmd->max_recv_wr = 0; | |
1375 | cmd->max_recv_sge = 0; | |
b93f3c18 | 1376 | } else { |
6d8a7497 | 1377 | if (cmd->is_srq) { |
2cc1e3b8 | 1378 | srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, |
8313c10f | 1379 | cmd->srq_handle, attrs); |
81f8f745 MS |
1380 | if (IS_ERR(srq) || |
1381 | srq->srq_type == IB_SRQT_XRC) { | |
1382 | ret = IS_ERR(srq) ? PTR_ERR(srq) : | |
1383 | -EINVAL; | |
b93f3c18 SH |
1384 | goto err_put; |
1385 | } | |
1386 | } | |
5909ce54 | 1387 | |
c70285f8 YH |
1388 | if (!ind_tbl) { |
1389 | if (cmd->recv_cq_handle != cmd->send_cq_handle) { | |
2cc1e3b8 JG |
1390 | rcq = uobj_get_obj_read( |
1391 | cq, UVERBS_OBJECT_CQ, | |
8313c10f | 1392 | cmd->recv_cq_handle, attrs); |
81f8f745 MS |
1393 | if (IS_ERR(rcq)) { |
1394 | ret = PTR_ERR(rcq); | |
c70285f8 YH |
1395 | goto err_put; |
1396 | } | |
5909ce54 | 1397 | } |
9977f4f6 SH |
1398 | } |
1399 | } | |
5909ce54 | 1400 | |
81f8f745 | 1401 | if (has_sq) { |
2cc1e3b8 | 1402 | scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, |
8313c10f | 1403 | cmd->send_cq_handle, attrs); |
81f8f745 MS |
1404 | if (IS_ERR(scq)) { |
1405 | ret = PTR_ERR(scq); | |
1406 | goto err_put; | |
1407 | } | |
1408 | } | |
1409 | ||
efeb973f | 1410 | if (!ind_tbl && cmd->qp_type != IB_QPT_XRC_INI) |
c70285f8 | 1411 | rcq = rcq ?: scq; |
2cc1e3b8 | 1412 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, |
8313c10f | 1413 | attrs); |
81f8f745 MS |
1414 | if (IS_ERR(pd)) { |
1415 | ret = PTR_ERR(pd); | |
5909ce54 RD |
1416 | goto err_put; |
1417 | } | |
1418 | ||
b93f3c18 | 1419 | device = pd->device; |
9977f4f6 SH |
1420 | } |
1421 | ||
bc38a6ab | 1422 | attr.event_handler = ib_uverbs_qp_event_handler; |
bc38a6ab RD |
1423 | attr.send_cq = scq; |
1424 | attr.recv_cq = rcq; | |
f520ba5a | 1425 | attr.srq = srq; |
b93f3c18 | 1426 | attr.xrcd = xrcd; |
6d8a7497 EBE |
1427 | attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR : |
1428 | IB_SIGNAL_REQ_WR; | |
1429 | attr.qp_type = cmd->qp_type; | |
bc38a6ab | 1430 | |
6d8a7497 EBE |
1431 | attr.cap.max_send_wr = cmd->max_send_wr; |
1432 | attr.cap.max_recv_wr = cmd->max_recv_wr; | |
1433 | attr.cap.max_send_sge = cmd->max_send_sge; | |
1434 | attr.cap.max_recv_sge = cmd->max_recv_sge; | |
1435 | attr.cap.max_inline_data = cmd->max_inline_data; | |
bc38a6ab | 1436 | |
9ead190b RD |
1437 | INIT_LIST_HEAD(&obj->uevent.event_list); |
1438 | INIT_LIST_HEAD(&obj->mcast_list); | |
bc38a6ab | 1439 | |
ece9ca97 | 1440 | attr.create_flags = cmd->create_flags; |
8a06ce59 LR |
1441 | if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK | |
1442 | IB_QP_CREATE_CROSS_CHANNEL | | |
1443 | IB_QP_CREATE_MANAGED_SEND | | |
b531b909 | 1444 | IB_QP_CREATE_MANAGED_RECV | |
9e1b161f | 1445 | IB_QP_CREATE_SCATTER_FCS | |
2dee0e54 | 1446 | IB_QP_CREATE_CVLAN_STRIPPING | |
e1d2e887 NO |
1447 | IB_QP_CREATE_SOURCE_QPN | |
1448 | IB_QP_CREATE_PCI_WRITE_END_PADDING)) { | |
6d8a7497 EBE |
1449 | ret = -EINVAL; |
1450 | goto err_put; | |
1451 | } | |
1452 | ||
2dee0e54 YH |
1453 | if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) { |
1454 | if (!capable(CAP_NET_RAW)) { | |
1455 | ret = -EPERM; | |
1456 | goto err_put; | |
1457 | } | |
1458 | ||
1459 | attr.source_qpn = cmd->source_qpn; | |
1460 | } | |
1461 | ||
d2b10794 LR |
1462 | qp = ib_create_qp_user(device, pd, &attr, &attrs->driver_udata, obj, |
1463 | KBUILD_MODNAME); | |
bc38a6ab RD |
1464 | if (IS_ERR(qp)) { |
1465 | ret = PTR_ERR(qp); | |
fd3c7904 | 1466 | goto err_put; |
bc38a6ab | 1467 | } |
5507f67d | 1468 | ib_qp_usecnt_inc(qp); |
bc38a6ab | 1469 | |
9ead190b | 1470 | obj->uevent.uobject.object = qp; |
98a8890f YH |
1471 | obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file); |
1472 | if (obj->uevent.event_file) | |
1473 | uverbs_uobject_get(&obj->uevent.event_file->uobj); | |
bc38a6ab | 1474 | |
846be90d YH |
1475 | if (xrcd) { |
1476 | obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, | |
1477 | uobject); | |
1478 | atomic_inc(&obj->uxrcd->refcnt); | |
fd3c7904 | 1479 | uobj_put_read(xrcd_uobj); |
846be90d YH |
1480 | } |
1481 | ||
b93f3c18 | 1482 | if (pd) |
fd3c7904 | 1483 | uobj_put_obj_read(pd); |
b93f3c18 | 1484 | if (scq) |
5bd48c18 JG |
1485 | rdma_lookup_put_uobject(&scq->uobject->uevent.uobject, |
1486 | UVERBS_LOOKUP_READ); | |
9977f4f6 | 1487 | if (rcq && rcq != scq) |
5bd48c18 JG |
1488 | rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject, |
1489 | UVERBS_LOOKUP_READ); | |
9ead190b | 1490 | if (srq) |
9fbe334c JG |
1491 | rdma_lookup_put_uobject(&srq->uobject->uevent.uobject, |
1492 | UVERBS_LOOKUP_READ); | |
c70285f8 | 1493 | if (ind_tbl) |
fd3c7904 | 1494 | uobj_put_obj_read(ind_tbl); |
16e51f78 LR |
1495 | uobj_finalize_uobj_create(&obj->uevent.uobject, attrs); |
1496 | ||
1497 | resp.base.qpn = qp->qp_num; | |
1498 | resp.base.qp_handle = obj->uevent.uobject.id; | |
1499 | resp.base.max_recv_sge = attr.cap.max_recv_sge; | |
1500 | resp.base.max_send_sge = attr.cap.max_send_sge; | |
1501 | resp.base.max_recv_wr = attr.cap.max_recv_wr; | |
1502 | resp.base.max_send_wr = attr.cap.max_send_wr; | |
1503 | resp.base.max_inline_data = attr.cap.max_inline_data; | |
1504 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); | |
1505 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
9ead190b | 1506 | |
9ead190b | 1507 | err_put: |
fd3c7904 MB |
1508 | if (!IS_ERR(xrcd_uobj)) |
1509 | uobj_put_read(xrcd_uobj); | |
81f8f745 | 1510 | if (!IS_ERR_OR_NULL(pd)) |
fd3c7904 | 1511 | uobj_put_obj_read(pd); |
81f8f745 | 1512 | if (!IS_ERR_OR_NULL(scq)) |
5bd48c18 JG |
1513 | rdma_lookup_put_uobject(&scq->uobject->uevent.uobject, |
1514 | UVERBS_LOOKUP_READ); | |
81f8f745 | 1515 | if (!IS_ERR_OR_NULL(rcq) && rcq != scq) |
5bd48c18 JG |
1516 | rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject, |
1517 | UVERBS_LOOKUP_READ); | |
81f8f745 | 1518 | if (!IS_ERR_OR_NULL(srq)) |
9fbe334c JG |
1519 | rdma_lookup_put_uobject(&srq->uobject->uevent.uobject, |
1520 | UVERBS_LOOKUP_READ); | |
81f8f745 | 1521 | if (!IS_ERR_OR_NULL(ind_tbl)) |
fd3c7904 | 1522 | uobj_put_obj_read(ind_tbl); |
9ead190b | 1523 | |
a6a3797d | 1524 | uobj_alloc_abort(&obj->uevent.uobject, attrs); |
bc38a6ab RD |
1525 | return ret; |
1526 | } | |
1527 | ||
974d6b4b | 1528 | static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs) |
6d8a7497 EBE |
1529 | { |
1530 | struct ib_uverbs_create_qp cmd; | |
1531 | struct ib_uverbs_ex_create_qp cmd_ex; | |
3c2c2094 | 1532 | int ret; |
6d8a7497 | 1533 | |
3c2c2094 JG |
1534 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1535 | if (ret) | |
1536 | return ret; | |
6d8a7497 | 1537 | |
6d8a7497 EBE |
1538 | memset(&cmd_ex, 0, sizeof(cmd_ex)); |
1539 | cmd_ex.user_handle = cmd.user_handle; | |
1540 | cmd_ex.pd_handle = cmd.pd_handle; | |
1541 | cmd_ex.send_cq_handle = cmd.send_cq_handle; | |
1542 | cmd_ex.recv_cq_handle = cmd.recv_cq_handle; | |
1543 | cmd_ex.srq_handle = cmd.srq_handle; | |
1544 | cmd_ex.max_send_wr = cmd.max_send_wr; | |
1545 | cmd_ex.max_recv_wr = cmd.max_recv_wr; | |
1546 | cmd_ex.max_send_sge = cmd.max_send_sge; | |
1547 | cmd_ex.max_recv_sge = cmd.max_recv_sge; | |
1548 | cmd_ex.max_inline_data = cmd.max_inline_data; | |
1549 | cmd_ex.sq_sig_all = cmd.sq_sig_all; | |
1550 | cmd_ex.qp_type = cmd.qp_type; | |
1551 | cmd_ex.is_srq = cmd.is_srq; | |
1552 | ||
ece9ca97 | 1553 | return create_qp(attrs, &cmd_ex); |
6d8a7497 EBE |
1554 | } |
1555 | ||
974d6b4b | 1556 | static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs) |
6d8a7497 | 1557 | { |
29a29d18 JG |
1558 | struct ib_uverbs_ex_create_qp cmd; |
1559 | int ret; | |
6d8a7497 | 1560 | |
29a29d18 JG |
1561 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1562 | if (ret) | |
1563 | return ret; | |
6d8a7497 | 1564 | |
c70285f8 | 1565 | if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK) |
6d8a7497 EBE |
1566 | return -EINVAL; |
1567 | ||
1568 | if (cmd.reserved) | |
1569 | return -EINVAL; | |
1570 | ||
ece9ca97 | 1571 | return create_qp(attrs, &cmd); |
6d8a7497 EBE |
1572 | } |
1573 | ||
974d6b4b | 1574 | static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs) |
42849b26 | 1575 | { |
16e51f78 | 1576 | struct ib_uverbs_create_qp_resp resp = {}; |
42849b26 | 1577 | struct ib_uverbs_open_qp cmd; |
42849b26 SH |
1578 | struct ib_uqp_object *obj; |
1579 | struct ib_xrcd *xrcd; | |
42849b26 | 1580 | struct ib_qp *qp; |
817d6576 | 1581 | struct ib_qp_open_attr attr = {}; |
42849b26 | 1582 | int ret; |
29f3fe1d | 1583 | struct ib_uobject *xrcd_uobj; |
bbd51e88 | 1584 | struct ib_device *ib_dev; |
42849b26 | 1585 | |
3c2c2094 JG |
1586 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1587 | if (ret) | |
1588 | return ret; | |
42849b26 | 1589 | |
8313c10f | 1590 | obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs, |
bbd51e88 | 1591 | &ib_dev); |
fd3c7904 MB |
1592 | if (IS_ERR(obj)) |
1593 | return PTR_ERR(obj); | |
42849b26 | 1594 | |
8313c10f | 1595 | xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs); |
fd3c7904 MB |
1596 | if (IS_ERR(xrcd_uobj)) { |
1597 | ret = -EINVAL; | |
1598 | goto err_put; | |
1599 | } | |
42849b26 | 1600 | |
fd3c7904 | 1601 | xrcd = (struct ib_xrcd *)xrcd_uobj->object; |
42849b26 SH |
1602 | if (!xrcd) { |
1603 | ret = -EINVAL; | |
fd3c7904 | 1604 | goto err_xrcd; |
42849b26 SH |
1605 | } |
1606 | ||
1607 | attr.event_handler = ib_uverbs_qp_event_handler; | |
42849b26 SH |
1608 | attr.qp_num = cmd.qpn; |
1609 | attr.qp_type = cmd.qp_type; | |
1610 | ||
42849b26 SH |
1611 | INIT_LIST_HEAD(&obj->uevent.event_list); |
1612 | INIT_LIST_HEAD(&obj->mcast_list); | |
1613 | ||
1614 | qp = ib_open_qp(xrcd, &attr); | |
1615 | if (IS_ERR(qp)) { | |
1616 | ret = PTR_ERR(qp); | |
fd3c7904 | 1617 | goto err_xrcd; |
42849b26 SH |
1618 | } |
1619 | ||
42849b26 | 1620 | obj->uevent.uobject.object = qp; |
fd3c7904 | 1621 | obj->uevent.uobject.user_handle = cmd.user_handle; |
42849b26 | 1622 | |
846be90d YH |
1623 | obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject); |
1624 | atomic_inc(&obj->uxrcd->refcnt); | |
620d3f81 | 1625 | qp->uobject = obj; |
fd3c7904 | 1626 | uobj_put_read(xrcd_uobj); |
16e51f78 | 1627 | uobj_finalize_uobj_create(&obj->uevent.uobject, attrs); |
42849b26 | 1628 | |
16e51f78 LR |
1629 | resp.qpn = qp->qp_num; |
1630 | resp.qp_handle = obj->uevent.uobject.id; | |
1631 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
42849b26 | 1632 | |
fd3c7904 MB |
1633 | err_xrcd: |
1634 | uobj_put_read(xrcd_uobj); | |
42849b26 | 1635 | err_put: |
a6a3797d | 1636 | uobj_alloc_abort(&obj->uevent.uobject, attrs); |
42849b26 SH |
1637 | return ret; |
1638 | } | |
1639 | ||
89caa053 PP |
1640 | static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr, |
1641 | struct rdma_ah_attr *rdma_attr) | |
1642 | { | |
1643 | const struct ib_global_route *grh; | |
1644 | ||
1645 | uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr); | |
1646 | uverb_attr->sl = rdma_ah_get_sl(rdma_attr); | |
1647 | uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr); | |
1648 | uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr); | |
1649 | uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) & | |
1650 | IB_AH_GRH); | |
1651 | if (uverb_attr->is_global) { | |
1652 | grh = rdma_ah_read_grh(rdma_attr); | |
1653 | memcpy(uverb_attr->dgid, grh->dgid.raw, 16); | |
1654 | uverb_attr->flow_label = grh->flow_label; | |
1655 | uverb_attr->sgid_index = grh->sgid_index; | |
1656 | uverb_attr->hop_limit = grh->hop_limit; | |
1657 | uverb_attr->traffic_class = grh->traffic_class; | |
1658 | } | |
1659 | uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr); | |
1660 | } | |
1661 | ||
974d6b4b | 1662 | static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs) |
7ccc9a24 DB |
1663 | { |
1664 | struct ib_uverbs_query_qp cmd; | |
1665 | struct ib_uverbs_query_qp_resp resp; | |
1666 | struct ib_qp *qp; | |
1667 | struct ib_qp_attr *attr; | |
1668 | struct ib_qp_init_attr *init_attr; | |
1669 | int ret; | |
1670 | ||
3c2c2094 JG |
1671 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1672 | if (ret) | |
1673 | return ret; | |
7ccc9a24 DB |
1674 | |
1675 | attr = kmalloc(sizeof *attr, GFP_KERNEL); | |
1676 | init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL); | |
1677 | if (!attr || !init_attr) { | |
1678 | ret = -ENOMEM; | |
1679 | goto out; | |
1680 | } | |
1681 | ||
8313c10f | 1682 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
1683 | if (IS_ERR(qp)) { |
1684 | ret = PTR_ERR(qp); | |
9ead190b RD |
1685 | goto out; |
1686 | } | |
1687 | ||
1688 | ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr); | |
7ccc9a24 | 1689 | |
620d3f81 JG |
1690 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
1691 | UVERBS_LOOKUP_READ); | |
7ccc9a24 DB |
1692 | |
1693 | if (ret) | |
1694 | goto out; | |
1695 | ||
1696 | memset(&resp, 0, sizeof resp); | |
1697 | ||
1698 | resp.qp_state = attr->qp_state; | |
1699 | resp.cur_qp_state = attr->cur_qp_state; | |
1700 | resp.path_mtu = attr->path_mtu; | |
1701 | resp.path_mig_state = attr->path_mig_state; | |
1702 | resp.qkey = attr->qkey; | |
1703 | resp.rq_psn = attr->rq_psn; | |
1704 | resp.sq_psn = attr->sq_psn; | |
1705 | resp.dest_qp_num = attr->dest_qp_num; | |
1706 | resp.qp_access_flags = attr->qp_access_flags; | |
1707 | resp.pkey_index = attr->pkey_index; | |
1708 | resp.alt_pkey_index = attr->alt_pkey_index; | |
0b26c88f | 1709 | resp.sq_draining = attr->sq_draining; |
7ccc9a24 DB |
1710 | resp.max_rd_atomic = attr->max_rd_atomic; |
1711 | resp.max_dest_rd_atomic = attr->max_dest_rd_atomic; | |
1712 | resp.min_rnr_timer = attr->min_rnr_timer; | |
1713 | resp.port_num = attr->port_num; | |
1714 | resp.timeout = attr->timeout; | |
1715 | resp.retry_cnt = attr->retry_cnt; | |
1716 | resp.rnr_retry = attr->rnr_retry; | |
1717 | resp.alt_port_num = attr->alt_port_num; | |
1718 | resp.alt_timeout = attr->alt_timeout; | |
1719 | ||
89caa053 PP |
1720 | copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr); |
1721 | copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr); | |
7ccc9a24 DB |
1722 | |
1723 | resp.max_send_wr = init_attr->cap.max_send_wr; | |
1724 | resp.max_recv_wr = init_attr->cap.max_recv_wr; | |
1725 | resp.max_send_sge = init_attr->cap.max_send_sge; | |
1726 | resp.max_recv_sge = init_attr->cap.max_recv_sge; | |
1727 | resp.max_inline_data = init_attr->cap.max_inline_data; | |
27d56300 | 1728 | resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR; |
7ccc9a24 | 1729 | |
9a073857 | 1730 | ret = uverbs_response(attrs, &resp, sizeof(resp)); |
7ccc9a24 DB |
1731 | |
1732 | out: | |
1733 | kfree(attr); | |
1734 | kfree(init_attr); | |
1735 | ||
7106a976 | 1736 | return ret; |
7ccc9a24 DB |
1737 | } |
1738 | ||
9977f4f6 SH |
1739 | /* Remove ignored fields set in the attribute mask */ |
1740 | static int modify_qp_mask(enum ib_qp_type qp_type, int mask) | |
1741 | { | |
1742 | switch (qp_type) { | |
1743 | case IB_QPT_XRC_INI: | |
1744 | return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER); | |
b93f3c18 SH |
1745 | case IB_QPT_XRC_TGT: |
1746 | return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT | | |
1747 | IB_QP_RNR_RETRY); | |
9977f4f6 SH |
1748 | default: |
1749 | return mask; | |
1750 | } | |
1751 | } | |
1752 | ||
89caa053 PP |
1753 | static void copy_ah_attr_from_uverbs(struct ib_device *dev, |
1754 | struct rdma_ah_attr *rdma_attr, | |
1755 | struct ib_uverbs_qp_dest *uverb_attr) | |
1756 | { | |
1757 | rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num); | |
1758 | if (uverb_attr->is_global) { | |
1759 | rdma_ah_set_grh(rdma_attr, NULL, | |
1760 | uverb_attr->flow_label, | |
1761 | uverb_attr->sgid_index, | |
1762 | uverb_attr->hop_limit, | |
1763 | uverb_attr->traffic_class); | |
1764 | rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid); | |
1765 | } else { | |
1766 | rdma_ah_set_ah_flags(rdma_attr, 0); | |
1767 | } | |
1768 | rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid); | |
1769 | rdma_ah_set_sl(rdma_attr, uverb_attr->sl); | |
1770 | rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits); | |
1771 | rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate); | |
1772 | rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num); | |
1773 | rdma_ah_set_make_grd(rdma_attr, false); | |
1774 | } | |
1775 | ||
8313c10f | 1776 | static int modify_qp(struct uverbs_attr_bundle *attrs, |
ef87df2c | 1777 | struct ib_uverbs_ex_modify_qp *cmd) |
bc38a6ab | 1778 | { |
189aba99 BW |
1779 | struct ib_qp_attr *attr; |
1780 | struct ib_qp *qp; | |
1781 | int ret; | |
9bc57e2d | 1782 | |
fb51eeca | 1783 | attr = kzalloc(sizeof(*attr), GFP_KERNEL); |
bc38a6ab RD |
1784 | if (!attr) |
1785 | return -ENOMEM; | |
1786 | ||
8313c10f JG |
1787 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle, |
1788 | attrs); | |
81f8f745 MS |
1789 | if (IS_ERR(qp)) { |
1790 | ret = PTR_ERR(qp); | |
bc38a6ab RD |
1791 | goto out; |
1792 | } | |
1793 | ||
5a7a88f1 IM |
1794 | if ((cmd->base.attr_mask & IB_QP_PORT) && |
1795 | !rdma_is_port_valid(qp->device, cmd->base.port_num)) { | |
5ecce4c9 BP |
1796 | ret = -EINVAL; |
1797 | goto release_qp; | |
1798 | } | |
1799 | ||
addb8a65 JM |
1800 | if ((cmd->base.attr_mask & IB_QP_AV)) { |
1801 | if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) { | |
1802 | ret = -EINVAL; | |
1803 | goto release_qp; | |
1804 | } | |
1805 | ||
1806 | if (cmd->base.attr_mask & IB_QP_STATE && | |
1807 | cmd->base.qp_state == IB_QPS_RTR) { | |
1808 | /* We are in INIT->RTR TRANSITION (if we are not, | |
1809 | * this transition will be rejected in subsequent checks). | |
1810 | * In the INIT->RTR transition, we cannot have IB_QP_PORT set, | |
1811 | * but the IB_QP_STATE flag is required. | |
1812 | * | |
1813 | * Since kernel 3.14 (commit dbf727de7440), the uverbs driver, | |
1814 | * when IB_QP_AV is set, has required inclusion of a valid | |
1815 | * port number in the primary AV. (AVs are created and handled | |
1816 | * differently for infiniband and ethernet (RoCE) ports). | |
1817 | * | |
1818 | * Check the port number included in the primary AV against | |
1819 | * the port number in the qp struct, which was set (and saved) | |
1820 | * in the RST->INIT transition. | |
1821 | */ | |
1822 | if (cmd->base.dest.port_num != qp->real_qp->port) { | |
1823 | ret = -EINVAL; | |
1824 | goto release_qp; | |
1825 | } | |
1826 | } else { | |
1827 | /* We are in SQD->SQD. (If we are not, this transition will | |
1828 | * be rejected later in the verbs layer checks). | |
1829 | * Check for both IB_QP_PORT and IB_QP_AV, these can be set | |
1830 | * together in the SQD->SQD transition. | |
1831 | * | |
1832 | * If only IP_QP_AV was set, add in IB_QP_PORT as well (the | |
1833 | * verbs layer driver does not track primary port changes | |
1834 | * resulting from path migration. Thus, in SQD, if the primary | |
1835 | * AV is modified, the primary port should also be modified). | |
1836 | * | |
1837 | * Note that in this transition, the IB_QP_STATE flag | |
1838 | * is not allowed. | |
1839 | */ | |
1840 | if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT)) | |
1841 | == (IB_QP_AV | IB_QP_PORT)) && | |
1842 | cmd->base.port_num != cmd->base.dest.port_num) { | |
1843 | ret = -EINVAL; | |
1844 | goto release_qp; | |
1845 | } | |
1846 | if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT)) | |
1847 | == IB_QP_AV) { | |
1848 | cmd->base.attr_mask |= IB_QP_PORT; | |
1849 | cmd->base.port_num = cmd->base.dest.port_num; | |
1850 | } | |
1851 | } | |
5d4c05c3 LR |
1852 | } |
1853 | ||
4cae8ff1 | 1854 | if ((cmd->base.attr_mask & IB_QP_ALT_PATH) && |
5d4c05c3 | 1855 | (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) || |
addb8a65 JM |
1856 | !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) || |
1857 | cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) { | |
4cae8ff1 DJ |
1858 | ret = -EINVAL; |
1859 | goto release_qp; | |
1860 | } | |
1861 | ||
88de869b LR |
1862 | if ((cmd->base.attr_mask & IB_QP_CUR_STATE && |
1863 | cmd->base.cur_qp_state > IB_QPS_ERR) || | |
4eeed368 MD |
1864 | (cmd->base.attr_mask & IB_QP_STATE && |
1865 | cmd->base.qp_state > IB_QPS_ERR)) { | |
88de869b LR |
1866 | ret = -EINVAL; |
1867 | goto release_qp; | |
1868 | } | |
1869 | ||
4eeed368 MD |
1870 | if (cmd->base.attr_mask & IB_QP_STATE) |
1871 | attr->qp_state = cmd->base.qp_state; | |
1872 | if (cmd->base.attr_mask & IB_QP_CUR_STATE) | |
1873 | attr->cur_qp_state = cmd->base.cur_qp_state; | |
1874 | if (cmd->base.attr_mask & IB_QP_PATH_MTU) | |
1875 | attr->path_mtu = cmd->base.path_mtu; | |
1876 | if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE) | |
1877 | attr->path_mig_state = cmd->base.path_mig_state; | |
0cadb4db | 1878 | if (cmd->base.attr_mask & IB_QP_QKEY) { |
465d6b42 PH |
1879 | if (cmd->base.qkey & IB_QP_SET_QKEY && |
1880 | !rdma_nl_get_privileged_qkey()) { | |
0cadb4db ES |
1881 | ret = -EPERM; |
1882 | goto release_qp; | |
1883 | } | |
4eeed368 | 1884 | attr->qkey = cmd->base.qkey; |
0cadb4db | 1885 | } |
4eeed368 MD |
1886 | if (cmd->base.attr_mask & IB_QP_RQ_PSN) |
1887 | attr->rq_psn = cmd->base.rq_psn; | |
1888 | if (cmd->base.attr_mask & IB_QP_SQ_PSN) | |
1889 | attr->sq_psn = cmd->base.sq_psn; | |
1890 | if (cmd->base.attr_mask & IB_QP_DEST_QPN) | |
1891 | attr->dest_qp_num = cmd->base.dest_qp_num; | |
1892 | if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS) | |
1893 | attr->qp_access_flags = cmd->base.qp_access_flags; | |
1894 | if (cmd->base.attr_mask & IB_QP_PKEY_INDEX) | |
1895 | attr->pkey_index = cmd->base.pkey_index; | |
1896 | if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY) | |
1897 | attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify; | |
1898 | if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC) | |
1899 | attr->max_rd_atomic = cmd->base.max_rd_atomic; | |
1900 | if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) | |
1901 | attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic; | |
1902 | if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER) | |
1903 | attr->min_rnr_timer = cmd->base.min_rnr_timer; | |
1904 | if (cmd->base.attr_mask & IB_QP_PORT) | |
1905 | attr->port_num = cmd->base.port_num; | |
1906 | if (cmd->base.attr_mask & IB_QP_TIMEOUT) | |
1907 | attr->timeout = cmd->base.timeout; | |
1908 | if (cmd->base.attr_mask & IB_QP_RETRY_CNT) | |
1909 | attr->retry_cnt = cmd->base.retry_cnt; | |
1910 | if (cmd->base.attr_mask & IB_QP_RNR_RETRY) | |
1911 | attr->rnr_retry = cmd->base.rnr_retry; | |
1912 | if (cmd->base.attr_mask & IB_QP_ALT_PATH) { | |
1913 | attr->alt_port_num = cmd->base.alt_port_num; | |
1914 | attr->alt_timeout = cmd->base.alt_timeout; | |
1915 | attr->alt_pkey_index = cmd->base.alt_pkey_index; | |
1916 | } | |
1917 | if (cmd->base.attr_mask & IB_QP_RATE_LIMIT) | |
1918 | attr->rate_limit = cmd->rate_limit; | |
189aba99 | 1919 | |
498ca3c8 | 1920 | if (cmd->base.attr_mask & IB_QP_AV) |
89caa053 PP |
1921 | copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr, |
1922 | &cmd->base.dest); | |
189aba99 | 1923 | |
498ca3c8 | 1924 | if (cmd->base.attr_mask & IB_QP_ALT_PATH) |
89caa053 PP |
1925 | copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr, |
1926 | &cmd->base.alt_dest); | |
bc38a6ab | 1927 | |
f7c8f2e9 PP |
1928 | ret = ib_modify_qp_with_udata(qp, attr, |
1929 | modify_qp_mask(qp->qp_type, | |
1930 | cmd->base.attr_mask), | |
ef87df2c | 1931 | &attrs->driver_udata); |
9ead190b | 1932 | |
0fb8bcf0 | 1933 | release_qp: |
620d3f81 JG |
1934 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
1935 | UVERBS_LOOKUP_READ); | |
bc38a6ab | 1936 | out: |
bc38a6ab RD |
1937 | kfree(attr); |
1938 | ||
1939 | return ret; | |
1940 | } | |
1941 | ||
974d6b4b | 1942 | static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs) |
189aba99 | 1943 | { |
29a29d18 | 1944 | struct ib_uverbs_ex_modify_qp cmd; |
3c2c2094 | 1945 | int ret; |
189aba99 | 1946 | |
3c2c2094 JG |
1947 | ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base)); |
1948 | if (ret) | |
1949 | return ret; | |
189aba99 | 1950 | |
26e990ba | 1951 | if (cmd.base.attr_mask & ~IB_QP_ATTR_STANDARD_BITS) |
189aba99 BW |
1952 | return -EOPNOTSUPP; |
1953 | ||
ef87df2c | 1954 | return modify_qp(attrs, &cmd); |
189aba99 BW |
1955 | } |
1956 | ||
974d6b4b | 1957 | static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs) |
189aba99 | 1958 | { |
29a29d18 | 1959 | struct ib_uverbs_ex_modify_qp cmd; |
40efca7a JG |
1960 | struct ib_uverbs_ex_modify_qp_resp resp = { |
1961 | .response_length = uverbs_response_length(attrs, sizeof(resp)) | |
1962 | }; | |
189aba99 BW |
1963 | int ret; |
1964 | ||
29a29d18 JG |
1965 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1966 | if (ret) | |
1967 | return ret; | |
1968 | ||
189aba99 BW |
1969 | /* |
1970 | * Last bit is reserved for extending the attr_mask by | |
1971 | * using another field. | |
1972 | */ | |
26e990ba | 1973 | if (cmd.base.attr_mask & ~(IB_QP_ATTR_STANDARD_BITS | IB_QP_RATE_LIMIT)) |
189aba99 BW |
1974 | return -EOPNOTSUPP; |
1975 | ||
40efca7a JG |
1976 | ret = modify_qp(attrs, &cmd); |
1977 | if (ret) | |
1978 | return ret; | |
1979 | ||
1980 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
189aba99 BW |
1981 | } |
1982 | ||
974d6b4b | 1983 | static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs) |
bc38a6ab | 1984 | { |
63aaf647 RD |
1985 | struct ib_uverbs_destroy_qp cmd; |
1986 | struct ib_uverbs_destroy_qp_resp resp; | |
9ead190b | 1987 | struct ib_uobject *uobj; |
9ead190b | 1988 | struct ib_uqp_object *obj; |
3c2c2094 | 1989 | int ret; |
bc38a6ab | 1990 | |
3c2c2094 JG |
1991 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
1992 | if (ret) | |
1993 | return ret; | |
bc38a6ab | 1994 | |
8313c10f | 1995 | uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
fd3c7904 MB |
1996 | if (IS_ERR(uobj)) |
1997 | return PTR_ERR(uobj); | |
1998 | ||
9ead190b | 1999 | obj = container_of(uobj, struct ib_uqp_object, uevent.uobject); |
32ed5c00 | 2000 | memset(&resp, 0, sizeof(resp)); |
9ead190b | 2001 | resp.events_reported = obj->uevent.events_reported; |
32ed5c00 JG |
2002 | |
2003 | uobj_put_destroy(uobj); | |
bc38a6ab | 2004 | |
9a073857 | 2005 | return uverbs_response(attrs, &resp, sizeof(resp)); |
bc38a6ab RD |
2006 | } |
2007 | ||
e622f2f4 CH |
2008 | static void *alloc_wr(size_t wr_size, __u32 num_sge) |
2009 | { | |
f681967a WL |
2010 | if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof(struct ib_sge))) / |
2011 | sizeof(struct ib_sge)) | |
4f7f4dcf VT |
2012 | return NULL; |
2013 | ||
f681967a WL |
2014 | return kmalloc(ALIGN(wr_size, sizeof(struct ib_sge)) + |
2015 | num_sge * sizeof(struct ib_sge), | |
2016 | GFP_KERNEL); | |
4f7f4dcf | 2017 | } |
e622f2f4 | 2018 | |
974d6b4b | 2019 | static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
2020 | { |
2021 | struct ib_uverbs_post_send cmd; | |
2022 | struct ib_uverbs_post_send_resp resp; | |
2023 | struct ib_uverbs_send_wr *user_wr; | |
d34ac5cd BVA |
2024 | struct ib_send_wr *wr = NULL, *last, *next; |
2025 | const struct ib_send_wr *bad_wr; | |
67cdb40c RD |
2026 | struct ib_qp *qp; |
2027 | int i, sg_ind; | |
9ead190b | 2028 | int is_ud; |
9a073857 | 2029 | int ret, ret2; |
1d784b89 | 2030 | size_t next_size; |
c3bea3d2 JG |
2031 | const struct ib_sge __user *sgls; |
2032 | const void __user *wqes; | |
2033 | struct uverbs_req_iter iter; | |
67cdb40c | 2034 | |
c3bea3d2 JG |
2035 | ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd)); |
2036 | if (ret) | |
2037 | return ret; | |
d0257e08 DC |
2038 | wqes = uverbs_request_next_ptr(&iter, size_mul(cmd.wqe_size, |
2039 | cmd.wr_count)); | |
c3bea3d2 JG |
2040 | if (IS_ERR(wqes)) |
2041 | return PTR_ERR(wqes); | |
d0257e08 DC |
2042 | sgls = uverbs_request_next_ptr(&iter, |
2043 | size_mul(cmd.sge_count, | |
2044 | sizeof(struct ib_uverbs_sge))); | |
c3bea3d2 JG |
2045 | if (IS_ERR(sgls)) |
2046 | return PTR_ERR(sgls); | |
2047 | ret = uverbs_request_finish(&iter); | |
2048 | if (ret) | |
2049 | return ret; | |
67cdb40c RD |
2050 | |
2051 | user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL); | |
2052 | if (!user_wr) | |
2053 | return -ENOMEM; | |
2054 | ||
8313c10f | 2055 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
2056 | if (IS_ERR(qp)) { |
2057 | ret = PTR_ERR(qp); | |
67cdb40c | 2058 | goto out; |
f687ccea | 2059 | } |
67cdb40c | 2060 | |
9ead190b | 2061 | is_ud = qp->qp_type == IB_QPT_UD; |
67cdb40c RD |
2062 | sg_ind = 0; |
2063 | last = NULL; | |
2064 | for (i = 0; i < cmd.wr_count; ++i) { | |
c3bea3d2 | 2065 | if (copy_from_user(user_wr, wqes + i * cmd.wqe_size, |
67cdb40c RD |
2066 | cmd.wqe_size)) { |
2067 | ret = -EFAULT; | |
9ead190b | 2068 | goto out_put; |
67cdb40c RD |
2069 | } |
2070 | ||
2071 | if (user_wr->num_sge + sg_ind > cmd.sge_count) { | |
2072 | ret = -EINVAL; | |
9ead190b | 2073 | goto out_put; |
67cdb40c RD |
2074 | } |
2075 | ||
e622f2f4 CH |
2076 | if (is_ud) { |
2077 | struct ib_ud_wr *ud; | |
2078 | ||
2079 | if (user_wr->opcode != IB_WR_SEND && | |
2080 | user_wr->opcode != IB_WR_SEND_WITH_IMM) { | |
2081 | ret = -EINVAL; | |
2082 | goto out_put; | |
2083 | } | |
2084 | ||
1d784b89 MM |
2085 | next_size = sizeof(*ud); |
2086 | ud = alloc_wr(next_size, user_wr->num_sge); | |
e622f2f4 CH |
2087 | if (!ud) { |
2088 | ret = -ENOMEM; | |
2089 | goto out_put; | |
2090 | } | |
2091 | ||
2cc1e3b8 | 2092 | ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH, |
8313c10f | 2093 | user_wr->wr.ud.ah, attrs); |
81f8f745 MS |
2094 | if (IS_ERR(ud->ah)) { |
2095 | ret = PTR_ERR(ud->ah); | |
e622f2f4 | 2096 | kfree(ud); |
e622f2f4 CH |
2097 | goto out_put; |
2098 | } | |
2099 | ud->remote_qpn = user_wr->wr.ud.remote_qpn; | |
2100 | ud->remote_qkey = user_wr->wr.ud.remote_qkey; | |
2101 | ||
2102 | next = &ud->wr; | |
2103 | } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM || | |
2104 | user_wr->opcode == IB_WR_RDMA_WRITE || | |
2105 | user_wr->opcode == IB_WR_RDMA_READ) { | |
2106 | struct ib_rdma_wr *rdma; | |
2107 | ||
1d784b89 MM |
2108 | next_size = sizeof(*rdma); |
2109 | rdma = alloc_wr(next_size, user_wr->num_sge); | |
e622f2f4 CH |
2110 | if (!rdma) { |
2111 | ret = -ENOMEM; | |
2112 | goto out_put; | |
2113 | } | |
2114 | ||
2115 | rdma->remote_addr = user_wr->wr.rdma.remote_addr; | |
2116 | rdma->rkey = user_wr->wr.rdma.rkey; | |
2117 | ||
2118 | next = &rdma->wr; | |
2119 | } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP || | |
2120 | user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) { | |
2121 | struct ib_atomic_wr *atomic; | |
2122 | ||
1d784b89 MM |
2123 | next_size = sizeof(*atomic); |
2124 | atomic = alloc_wr(next_size, user_wr->num_sge); | |
e622f2f4 CH |
2125 | if (!atomic) { |
2126 | ret = -ENOMEM; | |
2127 | goto out_put; | |
2128 | } | |
2129 | ||
2130 | atomic->remote_addr = user_wr->wr.atomic.remote_addr; | |
2131 | atomic->compare_add = user_wr->wr.atomic.compare_add; | |
2132 | atomic->swap = user_wr->wr.atomic.swap; | |
2133 | atomic->rkey = user_wr->wr.atomic.rkey; | |
2134 | ||
2135 | next = &atomic->wr; | |
2136 | } else if (user_wr->opcode == IB_WR_SEND || | |
2137 | user_wr->opcode == IB_WR_SEND_WITH_IMM || | |
2138 | user_wr->opcode == IB_WR_SEND_WITH_INV) { | |
1d784b89 MM |
2139 | next_size = sizeof(*next); |
2140 | next = alloc_wr(next_size, user_wr->num_sge); | |
e622f2f4 CH |
2141 | if (!next) { |
2142 | ret = -ENOMEM; | |
2143 | goto out_put; | |
2144 | } | |
2145 | } else { | |
2146 | ret = -EINVAL; | |
9ead190b | 2147 | goto out_put; |
67cdb40c RD |
2148 | } |
2149 | ||
e622f2f4 CH |
2150 | if (user_wr->opcode == IB_WR_SEND_WITH_IMM || |
2151 | user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) { | |
2152 | next->ex.imm_data = | |
2153 | (__be32 __force) user_wr->ex.imm_data; | |
2154 | } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) { | |
2155 | next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey; | |
2156 | } | |
2157 | ||
67cdb40c RD |
2158 | if (!last) |
2159 | wr = next; | |
2160 | else | |
2161 | last->next = next; | |
2162 | last = next; | |
2163 | ||
2164 | next->next = NULL; | |
2165 | next->wr_id = user_wr->wr_id; | |
2166 | next->num_sge = user_wr->num_sge; | |
2167 | next->opcode = user_wr->opcode; | |
2168 | next->send_flags = user_wr->send_flags; | |
67cdb40c | 2169 | |
67cdb40c RD |
2170 | if (next->num_sge) { |
2171 | next->sg_list = (void *) next + | |
1d784b89 | 2172 | ALIGN(next_size, sizeof(struct ib_sge)); |
c3bea3d2 JG |
2173 | if (copy_from_user(next->sg_list, sgls + sg_ind, |
2174 | next->num_sge * | |
2175 | sizeof(struct ib_sge))) { | |
67cdb40c | 2176 | ret = -EFAULT; |
9ead190b | 2177 | goto out_put; |
67cdb40c RD |
2178 | } |
2179 | sg_ind += next->num_sge; | |
2180 | } else | |
2181 | next->sg_list = NULL; | |
2182 | } | |
2183 | ||
2184 | resp.bad_wr = 0; | |
3023a1e9 | 2185 | ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr); |
67cdb40c RD |
2186 | if (ret) |
2187 | for (next = wr; next; next = next->next) { | |
2188 | ++resp.bad_wr; | |
2189 | if (next == bad_wr) | |
2190 | break; | |
2191 | } | |
2192 | ||
9a073857 JG |
2193 | ret2 = uverbs_response(attrs, &resp, sizeof(resp)); |
2194 | if (ret2) | |
2195 | ret = ret2; | |
67cdb40c | 2196 | |
9ead190b | 2197 | out_put: |
620d3f81 JG |
2198 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
2199 | UVERBS_LOOKUP_READ); | |
67cdb40c RD |
2200 | |
2201 | while (wr) { | |
e622f2f4 | 2202 | if (is_ud && ud_wr(wr)->ah) |
fd3c7904 | 2203 | uobj_put_obj_read(ud_wr(wr)->ah); |
67cdb40c RD |
2204 | next = wr->next; |
2205 | kfree(wr); | |
2206 | wr = next; | |
2207 | } | |
2208 | ||
18320828 | 2209 | out: |
67cdb40c RD |
2210 | kfree(user_wr); |
2211 | ||
7106a976 | 2212 | return ret; |
67cdb40c RD |
2213 | } |
2214 | ||
c3bea3d2 JG |
2215 | static struct ib_recv_wr * |
2216 | ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count, | |
2217 | u32 wqe_size, u32 sge_count) | |
67cdb40c RD |
2218 | { |
2219 | struct ib_uverbs_recv_wr *user_wr; | |
2220 | struct ib_recv_wr *wr = NULL, *last, *next; | |
2221 | int sg_ind; | |
2222 | int i; | |
2223 | int ret; | |
c3bea3d2 JG |
2224 | const struct ib_sge __user *sgls; |
2225 | const void __user *wqes; | |
67cdb40c | 2226 | |
f681967a | 2227 | if (wqe_size < sizeof(struct ib_uverbs_recv_wr)) |
67cdb40c RD |
2228 | return ERR_PTR(-EINVAL); |
2229 | ||
d0257e08 | 2230 | wqes = uverbs_request_next_ptr(iter, size_mul(wqe_size, wr_count)); |
c3bea3d2 JG |
2231 | if (IS_ERR(wqes)) |
2232 | return ERR_CAST(wqes); | |
d0257e08 DC |
2233 | sgls = uverbs_request_next_ptr(iter, size_mul(sge_count, |
2234 | sizeof(struct ib_uverbs_sge))); | |
c3bea3d2 JG |
2235 | if (IS_ERR(sgls)) |
2236 | return ERR_CAST(sgls); | |
2237 | ret = uverbs_request_finish(iter); | |
2238 | if (ret) | |
2239 | return ERR_PTR(ret); | |
2240 | ||
67cdb40c RD |
2241 | user_wr = kmalloc(wqe_size, GFP_KERNEL); |
2242 | if (!user_wr) | |
2243 | return ERR_PTR(-ENOMEM); | |
2244 | ||
2245 | sg_ind = 0; | |
2246 | last = NULL; | |
2247 | for (i = 0; i < wr_count; ++i) { | |
c3bea3d2 | 2248 | if (copy_from_user(user_wr, wqes + i * wqe_size, |
67cdb40c RD |
2249 | wqe_size)) { |
2250 | ret = -EFAULT; | |
2251 | goto err; | |
2252 | } | |
2253 | ||
2254 | if (user_wr->num_sge + sg_ind > sge_count) { | |
2255 | ret = -EINVAL; | |
2256 | goto err; | |
2257 | } | |
2258 | ||
4f7f4dcf | 2259 | if (user_wr->num_sge >= |
f681967a WL |
2260 | (U32_MAX - ALIGN(sizeof(*next), sizeof(struct ib_sge))) / |
2261 | sizeof(struct ib_sge)) { | |
4f7f4dcf VT |
2262 | ret = -EINVAL; |
2263 | goto err; | |
2264 | } | |
2265 | ||
f681967a WL |
2266 | next = kmalloc(ALIGN(sizeof(*next), sizeof(struct ib_sge)) + |
2267 | user_wr->num_sge * sizeof(struct ib_sge), | |
67cdb40c RD |
2268 | GFP_KERNEL); |
2269 | if (!next) { | |
2270 | ret = -ENOMEM; | |
2271 | goto err; | |
2272 | } | |
2273 | ||
2274 | if (!last) | |
2275 | wr = next; | |
2276 | else | |
2277 | last->next = next; | |
2278 | last = next; | |
2279 | ||
2280 | next->next = NULL; | |
2281 | next->wr_id = user_wr->wr_id; | |
2282 | next->num_sge = user_wr->num_sge; | |
2283 | ||
2284 | if (next->num_sge) { | |
f681967a WL |
2285 | next->sg_list = (void *)next + |
2286 | ALIGN(sizeof(*next), sizeof(struct ib_sge)); | |
c3bea3d2 JG |
2287 | if (copy_from_user(next->sg_list, sgls + sg_ind, |
2288 | next->num_sge * | |
2289 | sizeof(struct ib_sge))) { | |
67cdb40c RD |
2290 | ret = -EFAULT; |
2291 | goto err; | |
2292 | } | |
2293 | sg_ind += next->num_sge; | |
2294 | } else | |
2295 | next->sg_list = NULL; | |
2296 | } | |
2297 | ||
2298 | kfree(user_wr); | |
2299 | return wr; | |
2300 | ||
2301 | err: | |
2302 | kfree(user_wr); | |
2303 | ||
2304 | while (wr) { | |
2305 | next = wr->next; | |
2306 | kfree(wr); | |
2307 | wr = next; | |
2308 | } | |
2309 | ||
2310 | return ERR_PTR(ret); | |
2311 | } | |
2312 | ||
974d6b4b | 2313 | static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
2314 | { |
2315 | struct ib_uverbs_post_recv cmd; | |
2316 | struct ib_uverbs_post_recv_resp resp; | |
d34ac5cd BVA |
2317 | struct ib_recv_wr *wr, *next; |
2318 | const struct ib_recv_wr *bad_wr; | |
67cdb40c | 2319 | struct ib_qp *qp; |
9a073857 | 2320 | int ret, ret2; |
c3bea3d2 | 2321 | struct uverbs_req_iter iter; |
67cdb40c | 2322 | |
c3bea3d2 JG |
2323 | ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd)); |
2324 | if (ret) | |
2325 | return ret; | |
67cdb40c | 2326 | |
c3bea3d2 JG |
2327 | wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size, |
2328 | cmd.sge_count); | |
67cdb40c RD |
2329 | if (IS_ERR(wr)) |
2330 | return PTR_ERR(wr); | |
2331 | ||
8313c10f | 2332 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
2333 | if (IS_ERR(qp)) { |
2334 | ret = PTR_ERR(qp); | |
67cdb40c | 2335 | goto out; |
9a073857 | 2336 | } |
67cdb40c RD |
2337 | |
2338 | resp.bad_wr = 0; | |
3023a1e9 | 2339 | ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr); |
9ead190b | 2340 | |
620d3f81 JG |
2341 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
2342 | UVERBS_LOOKUP_READ); | |
fd3c7904 | 2343 | if (ret) { |
67cdb40c RD |
2344 | for (next = wr; next; next = next->next) { |
2345 | ++resp.bad_wr; | |
2346 | if (next == bad_wr) | |
2347 | break; | |
2348 | } | |
fd3c7904 | 2349 | } |
67cdb40c | 2350 | |
9a073857 JG |
2351 | ret2 = uverbs_response(attrs, &resp, sizeof(resp)); |
2352 | if (ret2) | |
2353 | ret = ret2; | |
67cdb40c | 2354 | out: |
67cdb40c RD |
2355 | while (wr) { |
2356 | next = wr->next; | |
2357 | kfree(wr); | |
2358 | wr = next; | |
2359 | } | |
2360 | ||
7106a976 | 2361 | return ret; |
67cdb40c RD |
2362 | } |
2363 | ||
974d6b4b | 2364 | static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
2365 | { |
2366 | struct ib_uverbs_post_srq_recv cmd; | |
2367 | struct ib_uverbs_post_srq_recv_resp resp; | |
d34ac5cd BVA |
2368 | struct ib_recv_wr *wr, *next; |
2369 | const struct ib_recv_wr *bad_wr; | |
67cdb40c | 2370 | struct ib_srq *srq; |
9a073857 | 2371 | int ret, ret2; |
c3bea3d2 | 2372 | struct uverbs_req_iter iter; |
67cdb40c | 2373 | |
c3bea3d2 JG |
2374 | ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd)); |
2375 | if (ret) | |
2376 | return ret; | |
67cdb40c | 2377 | |
c3bea3d2 JG |
2378 | wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size, |
2379 | cmd.sge_count); | |
67cdb40c RD |
2380 | if (IS_ERR(wr)) |
2381 | return PTR_ERR(wr); | |
2382 | ||
8313c10f | 2383 | srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); |
81f8f745 MS |
2384 | if (IS_ERR(srq)) { |
2385 | ret = PTR_ERR(srq); | |
67cdb40c | 2386 | goto out; |
9a073857 | 2387 | } |
67cdb40c RD |
2388 | |
2389 | resp.bad_wr = 0; | |
3023a1e9 | 2390 | ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr); |
9ead190b | 2391 | |
9fbe334c JG |
2392 | rdma_lookup_put_uobject(&srq->uobject->uevent.uobject, |
2393 | UVERBS_LOOKUP_READ); | |
9ead190b | 2394 | |
67cdb40c RD |
2395 | if (ret) |
2396 | for (next = wr; next; next = next->next) { | |
2397 | ++resp.bad_wr; | |
2398 | if (next == bad_wr) | |
2399 | break; | |
2400 | } | |
2401 | ||
9a073857 JG |
2402 | ret2 = uverbs_response(attrs, &resp, sizeof(resp)); |
2403 | if (ret2) | |
2404 | ret = ret2; | |
67cdb40c RD |
2405 | |
2406 | out: | |
67cdb40c RD |
2407 | while (wr) { |
2408 | next = wr->next; | |
2409 | kfree(wr); | |
2410 | wr = next; | |
2411 | } | |
2412 | ||
7106a976 | 2413 | return ret; |
67cdb40c RD |
2414 | } |
2415 | ||
974d6b4b | 2416 | static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
2417 | { |
2418 | struct ib_uverbs_create_ah cmd; | |
2419 | struct ib_uverbs_create_ah_resp resp; | |
2420 | struct ib_uobject *uobj; | |
2421 | struct ib_pd *pd; | |
2422 | struct ib_ah *ah; | |
fb51eeca | 2423 | struct rdma_ah_attr attr = {}; |
67cdb40c | 2424 | int ret; |
bbd51e88 | 2425 | struct ib_device *ib_dev; |
67cdb40c | 2426 | |
3c2c2094 JG |
2427 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
2428 | if (ret) | |
2429 | return ret; | |
67cdb40c | 2430 | |
8313c10f | 2431 | uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev); |
fd3c7904 MB |
2432 | if (IS_ERR(uobj)) |
2433 | return PTR_ERR(uobj); | |
67cdb40c | 2434 | |
bbd51e88 JG |
2435 | if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) { |
2436 | ret = -EINVAL; | |
2437 | goto err; | |
2438 | } | |
2439 | ||
8313c10f | 2440 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); |
81f8f745 MS |
2441 | if (IS_ERR(pd)) { |
2442 | ret = PTR_ERR(pd); | |
9ead190b | 2443 | goto err; |
67cdb40c RD |
2444 | } |
2445 | ||
44c58487 | 2446 | attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num); |
d98bb7f7 | 2447 | rdma_ah_set_make_grd(&attr, false); |
d8966fcd DC |
2448 | rdma_ah_set_dlid(&attr, cmd.attr.dlid); |
2449 | rdma_ah_set_sl(&attr, cmd.attr.sl); | |
2450 | rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits); | |
2451 | rdma_ah_set_static_rate(&attr, cmd.attr.static_rate); | |
2452 | rdma_ah_set_port_num(&attr, cmd.attr.port_num); | |
2453 | ||
4ba66093 | 2454 | if (cmd.attr.is_global) { |
d8966fcd DC |
2455 | rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label, |
2456 | cmd.attr.grh.sgid_index, | |
2457 | cmd.attr.grh.hop_limit, | |
2458 | cmd.attr.grh.traffic_class); | |
2459 | rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid); | |
4ba66093 | 2460 | } else { |
d8966fcd | 2461 | rdma_ah_set_ah_flags(&attr, 0); |
4ba66093 | 2462 | } |
477864c8 | 2463 | |
ef87df2c | 2464 | ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata); |
67cdb40c RD |
2465 | if (IS_ERR(ah)) { |
2466 | ret = PTR_ERR(ah); | |
fd3c7904 | 2467 | goto err_put; |
67cdb40c RD |
2468 | } |
2469 | ||
9ead190b | 2470 | ah->uobject = uobj; |
fd3c7904 | 2471 | uobj->user_handle = cmd.user_handle; |
9ead190b | 2472 | uobj->object = ah; |
fd3c7904 | 2473 | uobj_put_obj_read(pd); |
16e51f78 | 2474 | uobj_finalize_uobj_create(uobj, attrs); |
67cdb40c | 2475 | |
16e51f78 LR |
2476 | resp.ah_handle = uobj->id; |
2477 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
67cdb40c | 2478 | |
fd3c7904 MB |
2479 | err_put: |
2480 | uobj_put_obj_read(pd); | |
9ead190b | 2481 | err: |
a6a3797d | 2482 | uobj_alloc_abort(uobj, attrs); |
67cdb40c RD |
2483 | return ret; |
2484 | } | |
2485 | ||
974d6b4b | 2486 | static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs) |
67cdb40c RD |
2487 | { |
2488 | struct ib_uverbs_destroy_ah cmd; | |
3c2c2094 | 2489 | int ret; |
67cdb40c | 2490 | |
3c2c2094 JG |
2491 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
2492 | if (ret) | |
2493 | return ret; | |
67cdb40c | 2494 | |
7106a976 | 2495 | return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs); |
67cdb40c RD |
2496 | } |
2497 | ||
974d6b4b | 2498 | static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
2499 | { |
2500 | struct ib_uverbs_attach_mcast cmd; | |
2501 | struct ib_qp *qp; | |
9ead190b | 2502 | struct ib_uqp_object *obj; |
f4e40156 | 2503 | struct ib_uverbs_mcast_entry *mcast; |
9ead190b | 2504 | int ret; |
bc38a6ab | 2505 | |
3c2c2094 JG |
2506 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
2507 | if (ret) | |
2508 | return ret; | |
bc38a6ab | 2509 | |
8313c10f | 2510 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
2511 | if (IS_ERR(qp)) |
2512 | return PTR_ERR(qp); | |
f4e40156 | 2513 | |
620d3f81 | 2514 | obj = qp->uobject; |
f4e40156 | 2515 | |
f48b7269 | 2516 | mutex_lock(&obj->mcast_lock); |
9ead190b | 2517 | list_for_each_entry(mcast, &obj->mcast_list, list) |
f4e40156 JM |
2518 | if (cmd.mlid == mcast->lid && |
2519 | !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) { | |
2520 | ret = 0; | |
9ead190b | 2521 | goto out_put; |
f4e40156 JM |
2522 | } |
2523 | ||
2524 | mcast = kmalloc(sizeof *mcast, GFP_KERNEL); | |
2525 | if (!mcast) { | |
2526 | ret = -ENOMEM; | |
9ead190b | 2527 | goto out_put; |
f4e40156 JM |
2528 | } |
2529 | ||
2530 | mcast->lid = cmd.mlid; | |
2531 | memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw); | |
bc38a6ab | 2532 | |
f4e40156 | 2533 | ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid); |
9ead190b RD |
2534 | if (!ret) |
2535 | list_add_tail(&mcast->list, &obj->mcast_list); | |
2536 | else | |
f4e40156 JM |
2537 | kfree(mcast); |
2538 | ||
9ead190b | 2539 | out_put: |
f48b7269 | 2540 | mutex_unlock(&obj->mcast_lock); |
620d3f81 JG |
2541 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
2542 | UVERBS_LOOKUP_READ); | |
bc38a6ab | 2543 | |
7106a976 | 2544 | return ret; |
bc38a6ab RD |
2545 | } |
2546 | ||
974d6b4b | 2547 | static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs) |
bc38a6ab RD |
2548 | { |
2549 | struct ib_uverbs_detach_mcast cmd; | |
9ead190b | 2550 | struct ib_uqp_object *obj; |
bc38a6ab | 2551 | struct ib_qp *qp; |
f4e40156 | 2552 | struct ib_uverbs_mcast_entry *mcast; |
0bddcff6 | 2553 | int ret; |
20c7840a | 2554 | bool found = false; |
bc38a6ab | 2555 | |
3c2c2094 JG |
2556 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
2557 | if (ret) | |
2558 | return ret; | |
bc38a6ab | 2559 | |
8313c10f | 2560 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
2561 | if (IS_ERR(qp)) |
2562 | return PTR_ERR(qp); | |
bc38a6ab | 2563 | |
620d3f81 | 2564 | obj = qp->uobject; |
f48b7269 | 2565 | mutex_lock(&obj->mcast_lock); |
fd3c7904 | 2566 | |
9ead190b | 2567 | list_for_each_entry(mcast, &obj->mcast_list, list) |
f4e40156 JM |
2568 | if (cmd.mlid == mcast->lid && |
2569 | !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) { | |
2570 | list_del(&mcast->list); | |
2571 | kfree(mcast); | |
20c7840a | 2572 | found = true; |
f4e40156 JM |
2573 | break; |
2574 | } | |
2575 | ||
20c7840a MR |
2576 | if (!found) { |
2577 | ret = -EINVAL; | |
2578 | goto out_put; | |
2579 | } | |
2580 | ||
2581 | ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid); | |
2582 | ||
9ead190b | 2583 | out_put: |
f48b7269 | 2584 | mutex_unlock(&obj->mcast_lock); |
620d3f81 JG |
2585 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
2586 | UVERBS_LOOKUP_READ); | |
7106a976 | 2587 | return ret; |
bc38a6ab | 2588 | } |
f520ba5a | 2589 | |
fa76d24e | 2590 | struct ib_uflow_resources *flow_resources_alloc(size_t num_specs) |
9b828441 MB |
2591 | { |
2592 | struct ib_uflow_resources *resources; | |
2593 | ||
b6ba4a9a | 2594 | resources = kzalloc(sizeof(*resources), GFP_KERNEL); |
9b828441 MB |
2595 | |
2596 | if (!resources) | |
de749814 | 2597 | return NULL; |
b6ba4a9a | 2598 | |
a5cc9831 LR |
2599 | if (!num_specs) |
2600 | goto out; | |
2601 | ||
b6ba4a9a RS |
2602 | resources->counters = |
2603 | kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL); | |
b6ba4a9a RS |
2604 | resources->collection = |
2605 | kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL); | |
2606 | ||
de749814 LR |
2607 | if (!resources->counters || !resources->collection) |
2608 | goto err; | |
9b828441 | 2609 | |
a5cc9831 | 2610 | out: |
9b828441 | 2611 | resources->max = num_specs; |
9b828441 | 2612 | return resources; |
b6ba4a9a | 2613 | |
de749814 | 2614 | err: |
b6ba4a9a | 2615 | kfree(resources->counters); |
b6ba4a9a | 2616 | kfree(resources); |
de749814 | 2617 | |
b6ba4a9a | 2618 | return NULL; |
9b828441 | 2619 | } |
fa76d24e | 2620 | EXPORT_SYMBOL(flow_resources_alloc); |
9b828441 MB |
2621 | |
2622 | void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res) | |
2623 | { | |
2624 | unsigned int i; | |
2625 | ||
6cd080a6 YH |
2626 | if (!uflow_res) |
2627 | return; | |
2628 | ||
b6ba4a9a | 2629 | for (i = 0; i < uflow_res->collection_num; i++) |
9b828441 MB |
2630 | atomic_dec(&uflow_res->collection[i]->usecnt); |
2631 | ||
b6ba4a9a RS |
2632 | for (i = 0; i < uflow_res->counters_num; i++) |
2633 | atomic_dec(&uflow_res->counters[i]->usecnt); | |
2634 | ||
2635 | kfree(uflow_res->collection); | |
2636 | kfree(uflow_res->counters); | |
9b828441 MB |
2637 | kfree(uflow_res); |
2638 | } | |
fa76d24e | 2639 | EXPORT_SYMBOL(ib_uverbs_flow_resources_free); |
9b828441 | 2640 | |
fa76d24e MB |
2641 | void flow_resources_add(struct ib_uflow_resources *uflow_res, |
2642 | enum ib_flow_spec_type type, | |
2643 | void *ibobj) | |
9b828441 MB |
2644 | { |
2645 | WARN_ON(uflow_res->num >= uflow_res->max); | |
2646 | ||
b6ba4a9a RS |
2647 | switch (type) { |
2648 | case IB_FLOW_SPEC_ACTION_HANDLE: | |
2649 | atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt); | |
2650 | uflow_res->collection[uflow_res->collection_num++] = | |
2651 | (struct ib_flow_action *)ibobj; | |
2652 | break; | |
2653 | case IB_FLOW_SPEC_ACTION_COUNT: | |
2654 | atomic_inc(&((struct ib_counters *)ibobj)->usecnt); | |
2655 | uflow_res->counters[uflow_res->counters_num++] = | |
2656 | (struct ib_counters *)ibobj; | |
2657 | break; | |
2658 | default: | |
2659 | WARN_ON(1); | |
2660 | } | |
2661 | ||
2662 | uflow_res->num++; | |
9b828441 | 2663 | } |
fa76d24e | 2664 | EXPORT_SYMBOL(flow_resources_add); |
9b828441 | 2665 | |
3d9dfd06 | 2666 | static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs, |
9b828441 MB |
2667 | struct ib_uverbs_flow_spec *kern_spec, |
2668 | union ib_flow_spec *ib_spec, | |
2669 | struct ib_uflow_resources *uflow_res) | |
94e03f11 MR |
2670 | { |
2671 | ib_spec->type = kern_spec->type; | |
2672 | switch (ib_spec->type) { | |
2673 | case IB_FLOW_SPEC_ACTION_TAG: | |
2674 | if (kern_spec->flow_tag.size != | |
2675 | sizeof(struct ib_uverbs_flow_spec_action_tag)) | |
2676 | return -EINVAL; | |
2677 | ||
2678 | ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag); | |
2679 | ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id; | |
2680 | break; | |
483a3966 SS |
2681 | case IB_FLOW_SPEC_ACTION_DROP: |
2682 | if (kern_spec->drop.size != | |
2683 | sizeof(struct ib_uverbs_flow_spec_action_drop)) | |
2684 | return -EINVAL; | |
2685 | ||
2686 | ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop); | |
2687 | break; | |
9b828441 MB |
2688 | case IB_FLOW_SPEC_ACTION_HANDLE: |
2689 | if (kern_spec->action.size != | |
2690 | sizeof(struct ib_uverbs_flow_spec_action_handle)) | |
2691 | return -EOPNOTSUPP; | |
2692 | ib_spec->action.act = uobj_get_obj_read(flow_action, | |
2693 | UVERBS_OBJECT_FLOW_ACTION, | |
2694 | kern_spec->action.handle, | |
8313c10f | 2695 | attrs); |
81f8f745 MS |
2696 | if (IS_ERR(ib_spec->action.act)) |
2697 | return PTR_ERR(ib_spec->action.act); | |
9b828441 MB |
2698 | ib_spec->action.size = |
2699 | sizeof(struct ib_flow_spec_action_handle); | |
b6ba4a9a RS |
2700 | flow_resources_add(uflow_res, |
2701 | IB_FLOW_SPEC_ACTION_HANDLE, | |
2702 | ib_spec->action.act); | |
9b828441 MB |
2703 | uobj_put_obj_read(ib_spec->action.act); |
2704 | break; | |
b6ba4a9a RS |
2705 | case IB_FLOW_SPEC_ACTION_COUNT: |
2706 | if (kern_spec->flow_count.size != | |
2707 | sizeof(struct ib_uverbs_flow_spec_action_count)) | |
2708 | return -EINVAL; | |
2709 | ib_spec->flow_count.counters = | |
2710 | uobj_get_obj_read(counters, | |
2711 | UVERBS_OBJECT_COUNTERS, | |
2712 | kern_spec->flow_count.handle, | |
8313c10f | 2713 | attrs); |
81f8f745 MS |
2714 | if (IS_ERR(ib_spec->flow_count.counters)) |
2715 | return PTR_ERR(ib_spec->flow_count.counters); | |
b6ba4a9a RS |
2716 | ib_spec->flow_count.size = |
2717 | sizeof(struct ib_flow_spec_action_count); | |
2718 | flow_resources_add(uflow_res, | |
2719 | IB_FLOW_SPEC_ACTION_COUNT, | |
2720 | ib_spec->flow_count.counters); | |
2721 | uobj_put_obj_read(ib_spec->flow_count.counters); | |
2722 | break; | |
94e03f11 MR |
2723 | default: |
2724 | return -EINVAL; | |
2725 | } | |
2726 | return 0; | |
2727 | } | |
2728 | ||
766d8551 | 2729 | static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size, |
15dfbd6b MG |
2730 | u16 ib_real_filter_sz) |
2731 | { | |
2732 | /* | |
2733 | * User space filter structures must be 64 bit aligned, otherwise this | |
2734 | * may pass, but we won't handle additional new attributes. | |
2735 | */ | |
2736 | ||
2737 | if (kern_filter_size > ib_real_filter_sz) { | |
2738 | if (memchr_inv(kern_spec_filter + | |
2739 | ib_real_filter_sz, 0, | |
2740 | kern_filter_size - ib_real_filter_sz)) | |
2741 | return -EINVAL; | |
2742 | return ib_real_filter_sz; | |
2743 | } | |
2744 | return kern_filter_size; | |
2745 | } | |
2746 | ||
766d8551 MB |
2747 | int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type, |
2748 | const void *kern_spec_mask, | |
2749 | const void *kern_spec_val, | |
2750 | size_t kern_filter_sz, | |
2751 | union ib_flow_spec *ib_spec) | |
436f2ad0 | 2752 | { |
15dfbd6b | 2753 | ssize_t actual_filter_sz; |
15dfbd6b | 2754 | ssize_t ib_filter_sz; |
15dfbd6b | 2755 | |
15dfbd6b MG |
2756 | /* User flow spec size must be aligned to 4 bytes */ |
2757 | if (kern_filter_sz != ALIGN(kern_filter_sz, 4)) | |
2758 | return -EINVAL; | |
2759 | ||
766d8551 MB |
2760 | ib_spec->type = type; |
2761 | ||
fbf46860 MR |
2762 | if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL)) |
2763 | return -EINVAL; | |
15dfbd6b | 2764 | |
fbf46860 | 2765 | switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) { |
436f2ad0 | 2766 | case IB_FLOW_SPEC_ETH: |
14b526f5 | 2767 | ib_filter_sz = sizeof(struct ib_flow_eth_filter); |
15dfbd6b MG |
2768 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2769 | kern_filter_sz, | |
2770 | ib_filter_sz); | |
2771 | if (actual_filter_sz <= 0) | |
436f2ad0 | 2772 | return -EINVAL; |
15dfbd6b MG |
2773 | ib_spec->size = sizeof(struct ib_flow_spec_eth); |
2774 | memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz); | |
2775 | memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz); | |
436f2ad0 HHZ |
2776 | break; |
2777 | case IB_FLOW_SPEC_IPV4: | |
14b526f5 | 2778 | ib_filter_sz = sizeof(struct ib_flow_ipv4_filter); |
15dfbd6b MG |
2779 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2780 | kern_filter_sz, | |
2781 | ib_filter_sz); | |
2782 | if (actual_filter_sz <= 0) | |
436f2ad0 | 2783 | return -EINVAL; |
15dfbd6b MG |
2784 | ib_spec->size = sizeof(struct ib_flow_spec_ipv4); |
2785 | memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz); | |
2786 | memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz); | |
436f2ad0 | 2787 | break; |
4c2aae71 | 2788 | case IB_FLOW_SPEC_IPV6: |
14b526f5 | 2789 | ib_filter_sz = sizeof(struct ib_flow_ipv6_filter); |
15dfbd6b MG |
2790 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2791 | kern_filter_sz, | |
2792 | ib_filter_sz); | |
2793 | if (actual_filter_sz <= 0) | |
4c2aae71 | 2794 | return -EINVAL; |
15dfbd6b MG |
2795 | ib_spec->size = sizeof(struct ib_flow_spec_ipv6); |
2796 | memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz); | |
2797 | memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz); | |
a72c6a2b MG |
2798 | |
2799 | if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) || | |
2800 | (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20)) | |
2801 | return -EINVAL; | |
4c2aae71 | 2802 | break; |
436f2ad0 HHZ |
2803 | case IB_FLOW_SPEC_TCP: |
2804 | case IB_FLOW_SPEC_UDP: | |
14b526f5 | 2805 | ib_filter_sz = sizeof(struct ib_flow_tcp_udp_filter); |
15dfbd6b MG |
2806 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2807 | kern_filter_sz, | |
2808 | ib_filter_sz); | |
2809 | if (actual_filter_sz <= 0) | |
436f2ad0 | 2810 | return -EINVAL; |
15dfbd6b MG |
2811 | ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp); |
2812 | memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz); | |
2813 | memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz); | |
436f2ad0 | 2814 | break; |
0dbf3332 | 2815 | case IB_FLOW_SPEC_VXLAN_TUNNEL: |
14b526f5 | 2816 | ib_filter_sz = sizeof(struct ib_flow_tunnel_filter); |
0dbf3332 MR |
2817 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2818 | kern_filter_sz, | |
2819 | ib_filter_sz); | |
2820 | if (actual_filter_sz <= 0) | |
2821 | return -EINVAL; | |
2822 | ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel); | |
2823 | memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz); | |
2824 | memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz); | |
2825 | ||
2826 | if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) || | |
2827 | (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24)) | |
2828 | return -EINVAL; | |
2829 | break; | |
56ab0b38 | 2830 | case IB_FLOW_SPEC_ESP: |
14b526f5 | 2831 | ib_filter_sz = sizeof(struct ib_flow_esp_filter); |
56ab0b38 MB |
2832 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2833 | kern_filter_sz, | |
2834 | ib_filter_sz); | |
2835 | if (actual_filter_sz <= 0) | |
2836 | return -EINVAL; | |
2837 | ib_spec->esp.size = sizeof(struct ib_flow_spec_esp); | |
2838 | memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz); | |
2839 | memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz); | |
2840 | break; | |
d90e5e50 | 2841 | case IB_FLOW_SPEC_GRE: |
14b526f5 | 2842 | ib_filter_sz = sizeof(struct ib_flow_gre_filter); |
d90e5e50 AL |
2843 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2844 | kern_filter_sz, | |
2845 | ib_filter_sz); | |
2846 | if (actual_filter_sz <= 0) | |
2847 | return -EINVAL; | |
2848 | ib_spec->gre.size = sizeof(struct ib_flow_spec_gre); | |
2849 | memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz); | |
2850 | memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz); | |
2851 | break; | |
b04f0f03 | 2852 | case IB_FLOW_SPEC_MPLS: |
14b526f5 | 2853 | ib_filter_sz = sizeof(struct ib_flow_mpls_filter); |
b04f0f03 AL |
2854 | actual_filter_sz = spec_filter_size(kern_spec_mask, |
2855 | kern_filter_sz, | |
2856 | ib_filter_sz); | |
2857 | if (actual_filter_sz <= 0) | |
2858 | return -EINVAL; | |
2859 | ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls); | |
2860 | memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz); | |
2861 | memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz); | |
2862 | break; | |
436f2ad0 HHZ |
2863 | default: |
2864 | return -EINVAL; | |
2865 | } | |
2866 | return 0; | |
2867 | } | |
2868 | ||
766d8551 MB |
2869 | static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec, |
2870 | union ib_flow_spec *ib_spec) | |
2871 | { | |
a72f4ac1 | 2872 | size_t kern_filter_sz; |
766d8551 MB |
2873 | void *kern_spec_mask; |
2874 | void *kern_spec_val; | |
2875 | ||
a72f4ac1 AH |
2876 | if (check_sub_overflow((size_t)kern_spec->hdr.size, |
2877 | sizeof(struct ib_uverbs_flow_spec_hdr), | |
2878 | &kern_filter_sz)) | |
2879 | return -EINVAL; | |
2880 | ||
2881 | kern_filter_sz /= 2; | |
766d8551 MB |
2882 | |
2883 | kern_spec_val = (void *)kern_spec + | |
2884 | sizeof(struct ib_uverbs_flow_spec_hdr); | |
2885 | kern_spec_mask = kern_spec_val + kern_filter_sz; | |
2886 | ||
2887 | return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type, | |
2888 | kern_spec_mask, | |
2889 | kern_spec_val, | |
2890 | kern_filter_sz, ib_spec); | |
2891 | } | |
2892 | ||
8313c10f | 2893 | static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs, |
9b828441 MB |
2894 | struct ib_uverbs_flow_spec *kern_spec, |
2895 | union ib_flow_spec *ib_spec, | |
2896 | struct ib_uflow_resources *uflow_res) | |
94e03f11 MR |
2897 | { |
2898 | if (kern_spec->reserved) | |
2899 | return -EINVAL; | |
2900 | ||
2901 | if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG) | |
8313c10f | 2902 | return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec, |
9b828441 | 2903 | uflow_res); |
94e03f11 MR |
2904 | else |
2905 | return kern_spec_to_ib_spec_filter(kern_spec, ib_spec); | |
2906 | } | |
2907 | ||
974d6b4b | 2908 | static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs) |
f213c052 | 2909 | { |
29a29d18 | 2910 | struct ib_uverbs_ex_create_wq cmd; |
f213c052 YH |
2911 | struct ib_uverbs_ex_create_wq_resp resp = {}; |
2912 | struct ib_uwq_object *obj; | |
2913 | int err = 0; | |
2914 | struct ib_cq *cq; | |
2915 | struct ib_pd *pd; | |
2916 | struct ib_wq *wq; | |
2917 | struct ib_wq_init_attr wq_init_attr = {}; | |
bbd51e88 | 2918 | struct ib_device *ib_dev; |
f213c052 | 2919 | |
29a29d18 | 2920 | err = uverbs_request(attrs, &cmd, sizeof(cmd)); |
f213c052 YH |
2921 | if (err) |
2922 | return err; | |
2923 | ||
2924 | if (cmd.comp_mask) | |
2925 | return -EOPNOTSUPP; | |
2926 | ||
8313c10f | 2927 | obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs, |
bbd51e88 | 2928 | &ib_dev); |
fd3c7904 MB |
2929 | if (IS_ERR(obj)) |
2930 | return PTR_ERR(obj); | |
f213c052 | 2931 | |
8313c10f | 2932 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs); |
81f8f745 MS |
2933 | if (IS_ERR(pd)) { |
2934 | err = PTR_ERR(pd); | |
f213c052 YH |
2935 | goto err_uobj; |
2936 | } | |
2937 | ||
8313c10f | 2938 | cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
81f8f745 MS |
2939 | if (IS_ERR(cq)) { |
2940 | err = PTR_ERR(cq); | |
f213c052 YH |
2941 | goto err_put_pd; |
2942 | } | |
2943 | ||
2944 | wq_init_attr.cq = cq; | |
2945 | wq_init_attr.max_sge = cmd.max_sge; | |
2946 | wq_init_attr.max_wr = cmd.max_wr; | |
f213c052 YH |
2947 | wq_init_attr.wq_type = cmd.wq_type; |
2948 | wq_init_attr.event_handler = ib_uverbs_wq_event_handler; | |
29a29d18 | 2949 | wq_init_attr.create_flags = cmd.create_flags; |
f213c052 | 2950 | INIT_LIST_HEAD(&obj->uevent.event_list); |
dbd67252 | 2951 | obj->uevent.uobject.user_handle = cmd.user_handle; |
21885586 | 2952 | |
3023a1e9 | 2953 | wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata); |
f213c052 YH |
2954 | if (IS_ERR(wq)) { |
2955 | err = PTR_ERR(wq); | |
2956 | goto err_put_cq; | |
2957 | } | |
2958 | ||
e04dd131 | 2959 | wq->uobject = obj; |
f213c052 YH |
2960 | obj->uevent.uobject.object = wq; |
2961 | wq->wq_type = wq_init_attr.wq_type; | |
2962 | wq->cq = cq; | |
2963 | wq->pd = pd; | |
2964 | wq->device = pd->device; | |
f213c052 YH |
2965 | atomic_set(&wq->usecnt, 0); |
2966 | atomic_inc(&pd->usecnt); | |
2967 | atomic_inc(&cq->usecnt); | |
98a8890f YH |
2968 | obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file); |
2969 | if (obj->uevent.event_file) | |
2970 | uverbs_uobject_get(&obj->uevent.event_file->uobj); | |
f213c052 | 2971 | |
16e51f78 LR |
2972 | uobj_put_obj_read(pd); |
2973 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, | |
2974 | UVERBS_LOOKUP_READ); | |
2975 | uobj_finalize_uobj_create(&obj->uevent.uobject, attrs); | |
2976 | ||
f213c052 YH |
2977 | resp.wq_handle = obj->uevent.uobject.id; |
2978 | resp.max_sge = wq_init_attr.max_sge; | |
2979 | resp.max_wr = wq_init_attr.max_wr; | |
2980 | resp.wqn = wq->wq_num; | |
29a29d18 | 2981 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); |
16e51f78 | 2982 | return uverbs_response(attrs, &resp, sizeof(resp)); |
f213c052 | 2983 | |
f213c052 | 2984 | err_put_cq: |
5bd48c18 JG |
2985 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, |
2986 | UVERBS_LOOKUP_READ); | |
f213c052 | 2987 | err_put_pd: |
fd3c7904 | 2988 | uobj_put_obj_read(pd); |
f213c052 | 2989 | err_uobj: |
a6a3797d | 2990 | uobj_alloc_abort(&obj->uevent.uobject, attrs); |
f213c052 YH |
2991 | |
2992 | return err; | |
2993 | } | |
2994 | ||
974d6b4b | 2995 | static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs) |
f213c052 | 2996 | { |
29a29d18 | 2997 | struct ib_uverbs_ex_destroy_wq cmd; |
f213c052 | 2998 | struct ib_uverbs_ex_destroy_wq_resp resp = {}; |
f213c052 YH |
2999 | struct ib_uobject *uobj; |
3000 | struct ib_uwq_object *obj; | |
f213c052 YH |
3001 | int ret; |
3002 | ||
29a29d18 | 3003 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
f213c052 YH |
3004 | if (ret) |
3005 | return ret; | |
3006 | ||
3007 | if (cmd.comp_mask) | |
3008 | return -EOPNOTSUPP; | |
3009 | ||
29a29d18 | 3010 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); |
8313c10f | 3011 | uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs); |
fd3c7904 MB |
3012 | if (IS_ERR(uobj)) |
3013 | return PTR_ERR(uobj); | |
f213c052 | 3014 | |
f213c052 | 3015 | obj = container_of(uobj, struct ib_uwq_object, uevent.uobject); |
f213c052 | 3016 | resp.events_reported = obj->uevent.events_reported; |
32ed5c00 JG |
3017 | |
3018 | uobj_put_destroy(uobj); | |
f213c052 | 3019 | |
9a073857 | 3020 | return uverbs_response(attrs, &resp, sizeof(resp)); |
f213c052 YH |
3021 | } |
3022 | ||
974d6b4b | 3023 | static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs) |
f213c052 | 3024 | { |
29a29d18 | 3025 | struct ib_uverbs_ex_modify_wq cmd; |
f213c052 YH |
3026 | struct ib_wq *wq; |
3027 | struct ib_wq_attr wq_attr = {}; | |
f213c052 YH |
3028 | int ret; |
3029 | ||
29a29d18 | 3030 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
f213c052 YH |
3031 | if (ret) |
3032 | return ret; | |
3033 | ||
3034 | if (!cmd.attr_mask) | |
3035 | return -EINVAL; | |
3036 | ||
af1cb95d | 3037 | if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS)) |
f213c052 YH |
3038 | return -EINVAL; |
3039 | ||
8313c10f | 3040 | wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs); |
81f8f745 MS |
3041 | if (IS_ERR(wq)) |
3042 | return PTR_ERR(wq); | |
f213c052 | 3043 | |
af1cb95d NO |
3044 | if (cmd.attr_mask & IB_WQ_FLAGS) { |
3045 | wq_attr.flags = cmd.flags; | |
3046 | wq_attr.flags_mask = cmd.flags_mask; | |
3047 | } | |
f9744288 LR |
3048 | |
3049 | if (cmd.attr_mask & IB_WQ_CUR_STATE) { | |
3050 | if (cmd.curr_wq_state > IB_WQS_ERR) | |
3051 | return -EINVAL; | |
3052 | ||
3053 | wq_attr.curr_wq_state = cmd.curr_wq_state; | |
3054 | } else { | |
3055 | wq_attr.curr_wq_state = wq->state; | |
3056 | } | |
3057 | ||
3058 | if (cmd.attr_mask & IB_WQ_STATE) { | |
3059 | if (cmd.wq_state > IB_WQS_ERR) | |
3060 | return -EINVAL; | |
3061 | ||
3062 | wq_attr.wq_state = cmd.wq_state; | |
3063 | } else { | |
3064 | wq_attr.wq_state = wq_attr.curr_wq_state; | |
3065 | } | |
3066 | ||
3023a1e9 KH |
3067 | ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask, |
3068 | &attrs->driver_udata); | |
e04dd131 JG |
3069 | rdma_lookup_put_uobject(&wq->uobject->uevent.uobject, |
3070 | UVERBS_LOOKUP_READ); | |
f213c052 YH |
3071 | return ret; |
3072 | } | |
3073 | ||
974d6b4b | 3074 | static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs) |
de019a94 | 3075 | { |
335708c7 | 3076 | struct ib_uverbs_ex_create_rwq_ind_table cmd; |
de019a94 | 3077 | struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {}; |
c0a6b5ec | 3078 | struct ib_uobject *uobj; |
335708c7 | 3079 | int err; |
de019a94 YH |
3080 | struct ib_rwq_ind_table_init_attr init_attr = {}; |
3081 | struct ib_rwq_ind_table *rwq_ind_tbl; | |
c0a6b5ec | 3082 | struct ib_wq **wqs = NULL; |
de019a94 YH |
3083 | u32 *wqs_handles = NULL; |
3084 | struct ib_wq *wq = NULL; | |
16e51f78 | 3085 | int i, num_read_wqs; |
de019a94 | 3086 | u32 num_wq_handles; |
335708c7 | 3087 | struct uverbs_req_iter iter; |
bbd51e88 | 3088 | struct ib_device *ib_dev; |
de019a94 | 3089 | |
335708c7 | 3090 | err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd)); |
de019a94 YH |
3091 | if (err) |
3092 | return err; | |
3093 | ||
de019a94 YH |
3094 | if (cmd.comp_mask) |
3095 | return -EOPNOTSUPP; | |
3096 | ||
3097 | if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE) | |
3098 | return -EINVAL; | |
3099 | ||
3100 | num_wq_handles = 1 << cmd.log_ind_tbl_size; | |
de019a94 YH |
3101 | wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles), |
3102 | GFP_KERNEL); | |
3103 | if (!wqs_handles) | |
3104 | return -ENOMEM; | |
3105 | ||
335708c7 JG |
3106 | err = uverbs_request_next(&iter, wqs_handles, |
3107 | num_wq_handles * sizeof(__u32)); | |
3108 | if (err) | |
3109 | goto err_free; | |
3110 | ||
3111 | err = uverbs_request_finish(&iter); | |
de019a94 YH |
3112 | if (err) |
3113 | goto err_free; | |
3114 | ||
3115 | wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL); | |
3116 | if (!wqs) { | |
3117 | err = -ENOMEM; | |
3118 | goto err_free; | |
3119 | } | |
3120 | ||
3121 | for (num_read_wqs = 0; num_read_wqs < num_wq_handles; | |
3122 | num_read_wqs++) { | |
2cc1e3b8 | 3123 | wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, |
8313c10f | 3124 | wqs_handles[num_read_wqs], attrs); |
81f8f745 MS |
3125 | if (IS_ERR(wq)) { |
3126 | err = PTR_ERR(wq); | |
de019a94 YH |
3127 | goto put_wqs; |
3128 | } | |
3129 | ||
3130 | wqs[num_read_wqs] = wq; | |
16e51f78 | 3131 | atomic_inc(&wqs[num_read_wqs]->usecnt); |
de019a94 YH |
3132 | } |
3133 | ||
8313c10f | 3134 | uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev); |
fd3c7904 MB |
3135 | if (IS_ERR(uobj)) { |
3136 | err = PTR_ERR(uobj); | |
de019a94 YH |
3137 | goto put_wqs; |
3138 | } | |
3139 | ||
c0a6b5ec LR |
3140 | rwq_ind_tbl = rdma_zalloc_drv_obj(ib_dev, ib_rwq_ind_table); |
3141 | if (!rwq_ind_tbl) { | |
3142 | err = -ENOMEM; | |
de019a94 YH |
3143 | goto err_uobj; |
3144 | } | |
3145 | ||
c0a6b5ec LR |
3146 | init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size; |
3147 | init_attr.ind_tbl = wqs; | |
3148 | ||
de019a94 YH |
3149 | rwq_ind_tbl->ind_tbl = wqs; |
3150 | rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size; | |
3151 | rwq_ind_tbl->uobject = uobj; | |
3152 | uobj->object = rwq_ind_tbl; | |
3153 | rwq_ind_tbl->device = ib_dev; | |
3154 | atomic_set(&rwq_ind_tbl->usecnt, 0); | |
3155 | ||
c0a6b5ec LR |
3156 | err = ib_dev->ops.create_rwq_ind_table(rwq_ind_tbl, &init_attr, |
3157 | &attrs->driver_udata); | |
3158 | if (err) | |
3159 | goto err_create; | |
3160 | ||
de019a94 | 3161 | for (i = 0; i < num_wq_handles; i++) |
16e51f78 LR |
3162 | rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject, |
3163 | UVERBS_LOOKUP_READ); | |
3164 | kfree(wqs_handles); | |
3165 | uobj_finalize_uobj_create(uobj, attrs); | |
de019a94 | 3166 | |
de019a94 YH |
3167 | resp.ind_tbl_handle = uobj->id; |
3168 | resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num; | |
29a29d18 | 3169 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); |
16e51f78 | 3170 | return uverbs_response(attrs, &resp, sizeof(resp)); |
de019a94 | 3171 | |
c0a6b5ec LR |
3172 | err_create: |
3173 | kfree(rwq_ind_tbl); | |
de019a94 | 3174 | err_uobj: |
a6a3797d | 3175 | uobj_alloc_abort(uobj, attrs); |
de019a94 | 3176 | put_wqs: |
16e51f78 LR |
3177 | for (i = 0; i < num_read_wqs; i++) { |
3178 | rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject, | |
e04dd131 | 3179 | UVERBS_LOOKUP_READ); |
16e51f78 LR |
3180 | atomic_dec(&wqs[i]->usecnt); |
3181 | } | |
de019a94 YH |
3182 | err_free: |
3183 | kfree(wqs_handles); | |
3184 | kfree(wqs); | |
3185 | return err; | |
3186 | } | |
3187 | ||
974d6b4b | 3188 | static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs) |
de019a94 | 3189 | { |
29a29d18 JG |
3190 | struct ib_uverbs_ex_destroy_rwq_ind_table cmd; |
3191 | int ret; | |
de019a94 | 3192 | |
29a29d18 | 3193 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
de019a94 YH |
3194 | if (ret) |
3195 | return ret; | |
3196 | ||
3197 | if (cmd.comp_mask) | |
3198 | return -EOPNOTSUPP; | |
3199 | ||
c33e73af | 3200 | return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL, |
7106a976 | 3201 | cmd.ind_tbl_handle, attrs); |
de019a94 YH |
3202 | } |
3203 | ||
974d6b4b | 3204 | static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs) |
436f2ad0 HHZ |
3205 | { |
3206 | struct ib_uverbs_create_flow cmd; | |
16e51f78 | 3207 | struct ib_uverbs_create_flow_resp resp = {}; |
436f2ad0 HHZ |
3208 | struct ib_uobject *uobj; |
3209 | struct ib_flow *flow_id; | |
d82693da | 3210 | struct ib_uverbs_flow_attr *kern_flow_attr; |
436f2ad0 HHZ |
3211 | struct ib_flow_attr *flow_attr; |
3212 | struct ib_qp *qp; | |
9b828441 | 3213 | struct ib_uflow_resources *uflow_res; |
4fae7f17 | 3214 | struct ib_uverbs_flow_spec_hdr *kern_spec; |
335708c7 JG |
3215 | struct uverbs_req_iter iter; |
3216 | int err; | |
436f2ad0 HHZ |
3217 | void *ib_spec; |
3218 | int i; | |
bbd51e88 | 3219 | struct ib_device *ib_dev; |
436f2ad0 | 3220 | |
335708c7 | 3221 | err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd)); |
f21519b2 YD |
3222 | if (err) |
3223 | return err; | |
3224 | ||
22878dbc MB |
3225 | if (cmd.comp_mask) |
3226 | return -EINVAL; | |
3227 | ||
e3b6d8cf | 3228 | if (!capable(CAP_NET_RAW)) |
436f2ad0 HHZ |
3229 | return -EPERM; |
3230 | ||
a3100a78 MV |
3231 | if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED) |
3232 | return -EINVAL; | |
3233 | ||
3234 | if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) && | |
3235 | ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) || | |
3236 | (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT))) | |
3237 | return -EINVAL; | |
3238 | ||
f8848274 | 3239 | if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS) |
22878dbc MB |
3240 | return -EINVAL; |
3241 | ||
335708c7 | 3242 | if (cmd.flow_attr.size > |
b68c9560 | 3243 | (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec))) |
22878dbc MB |
3244 | return -EINVAL; |
3245 | ||
c780d82a YD |
3246 | if (cmd.flow_attr.reserved[0] || |
3247 | cmd.flow_attr.reserved[1]) | |
3248 | return -EINVAL; | |
3249 | ||
436f2ad0 | 3250 | if (cmd.flow_attr.num_of_specs) { |
f8848274 MB |
3251 | kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size, |
3252 | GFP_KERNEL); | |
436f2ad0 HHZ |
3253 | if (!kern_flow_attr) |
3254 | return -ENOMEM; | |
3255 | ||
4fae7f17 | 3256 | *kern_flow_attr = cmd.flow_attr; |
335708c7 JG |
3257 | err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs, |
3258 | cmd.flow_attr.size); | |
f21519b2 | 3259 | if (err) |
436f2ad0 | 3260 | goto err_free_attr; |
436f2ad0 HHZ |
3261 | } else { |
3262 | kern_flow_attr = &cmd.flow_attr; | |
436f2ad0 HHZ |
3263 | } |
3264 | ||
335708c7 JG |
3265 | err = uverbs_request_finish(&iter); |
3266 | if (err) | |
3267 | goto err_free_attr; | |
3268 | ||
8313c10f | 3269 | uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev); |
fd3c7904 MB |
3270 | if (IS_ERR(uobj)) { |
3271 | err = PTR_ERR(uobj); | |
436f2ad0 HHZ |
3272 | goto err_free_attr; |
3273 | } | |
436f2ad0 | 3274 | |
2adcb4c5 MG |
3275 | if (!rdma_is_port_valid(uobj->context->device, cmd.flow_attr.port)) { |
3276 | err = -EINVAL; | |
3277 | goto err_uobj; | |
3278 | } | |
3279 | ||
8313c10f | 3280 | qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs); |
81f8f745 MS |
3281 | if (IS_ERR(qp)) { |
3282 | err = PTR_ERR(qp); | |
436f2ad0 HHZ |
3283 | goto err_uobj; |
3284 | } | |
3285 | ||
940efcc8 LR |
3286 | if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) { |
3287 | err = -EINVAL; | |
3288 | goto err_put; | |
3289 | } | |
3290 | ||
7654cb1b MW |
3291 | flow_attr = kzalloc(struct_size(flow_attr, flows, |
3292 | cmd.flow_attr.num_of_specs), GFP_KERNEL); | |
436f2ad0 HHZ |
3293 | if (!flow_attr) { |
3294 | err = -ENOMEM; | |
3295 | goto err_put; | |
3296 | } | |
9b828441 MB |
3297 | uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs); |
3298 | if (!uflow_res) { | |
3299 | err = -ENOMEM; | |
3300 | goto err_free_flow_attr; | |
3301 | } | |
436f2ad0 HHZ |
3302 | |
3303 | flow_attr->type = kern_flow_attr->type; | |
3304 | flow_attr->priority = kern_flow_attr->priority; | |
3305 | flow_attr->num_of_specs = kern_flow_attr->num_of_specs; | |
3306 | flow_attr->port = kern_flow_attr->port; | |
3307 | flow_attr->flags = kern_flow_attr->flags; | |
3308 | flow_attr->size = sizeof(*flow_attr); | |
3309 | ||
4fae7f17 | 3310 | kern_spec = kern_flow_attr->flow_specs; |
436f2ad0 | 3311 | ib_spec = flow_attr + 1; |
f8848274 | 3312 | for (i = 0; i < flow_attr->num_of_specs && |
fe48aecb | 3313 | cmd.flow_attr.size >= sizeof(*kern_spec) && |
4fae7f17 LR |
3314 | cmd.flow_attr.size >= kern_spec->size; |
3315 | i++) { | |
3316 | err = kern_spec_to_ib_spec( | |
8313c10f | 3317 | attrs, (struct ib_uverbs_flow_spec *)kern_spec, |
4fae7f17 | 3318 | ib_spec, uflow_res); |
436f2ad0 HHZ |
3319 | if (err) |
3320 | goto err_free; | |
b04f0f03 | 3321 | |
436f2ad0 HHZ |
3322 | flow_attr->size += |
3323 | ((union ib_flow_spec *) ib_spec)->size; | |
4fae7f17 LR |
3324 | cmd.flow_attr.size -= kern_spec->size; |
3325 | kern_spec = ((void *)kern_spec) + kern_spec->size; | |
436f2ad0 HHZ |
3326 | ib_spec += ((union ib_flow_spec *) ib_spec)->size; |
3327 | } | |
f8848274 | 3328 | if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) { |
3cea7b4a | 3329 | pr_warn("create flow failed, flow %d: %u bytes left from uverb cmd\n", |
f8848274 | 3330 | i, cmd.flow_attr.size); |
98a37510 | 3331 | err = -EINVAL; |
436f2ad0 HHZ |
3332 | goto err_free; |
3333 | } | |
59082a32 | 3334 | |
d6673746 LR |
3335 | flow_id = qp->device->ops.create_flow(qp, flow_attr, |
3336 | &attrs->driver_udata); | |
59082a32 | 3337 | |
436f2ad0 HHZ |
3338 | if (IS_ERR(flow_id)) { |
3339 | err = PTR_ERR(flow_id); | |
fd3c7904 | 3340 | goto err_free; |
436f2ad0 | 3341 | } |
86e1d464 MB |
3342 | |
3343 | ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res); | |
436f2ad0 | 3344 | |
620d3f81 JG |
3345 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
3346 | UVERBS_LOOKUP_READ); | |
436f2ad0 | 3347 | kfree(flow_attr); |
16e51f78 | 3348 | |
436f2ad0 HHZ |
3349 | if (cmd.flow_attr.num_of_specs) |
3350 | kfree(kern_flow_attr); | |
16e51f78 LR |
3351 | uobj_finalize_uobj_create(uobj, attrs); |
3352 | ||
3353 | resp.flow_handle = uobj->id; | |
3354 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
3355 | ||
436f2ad0 | 3356 | err_free: |
9b828441 MB |
3357 | ib_uverbs_flow_resources_free(uflow_res); |
3358 | err_free_flow_attr: | |
436f2ad0 HHZ |
3359 | kfree(flow_attr); |
3360 | err_put: | |
620d3f81 JG |
3361 | rdma_lookup_put_uobject(&qp->uobject->uevent.uobject, |
3362 | UVERBS_LOOKUP_READ); | |
436f2ad0 | 3363 | err_uobj: |
a6a3797d | 3364 | uobj_alloc_abort(uobj, attrs); |
436f2ad0 HHZ |
3365 | err_free_attr: |
3366 | if (cmd.flow_attr.num_of_specs) | |
3367 | kfree(kern_flow_attr); | |
3368 | return err; | |
3369 | } | |
3370 | ||
974d6b4b | 3371 | static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs) |
f21519b2 | 3372 | { |
436f2ad0 | 3373 | struct ib_uverbs_destroy_flow cmd; |
436f2ad0 HHZ |
3374 | int ret; |
3375 | ||
29a29d18 | 3376 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
f21519b2 YD |
3377 | if (ret) |
3378 | return ret; | |
436f2ad0 | 3379 | |
2782c2d3 YD |
3380 | if (cmd.comp_mask) |
3381 | return -EINVAL; | |
3382 | ||
7106a976 | 3383 | return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs); |
436f2ad0 HHZ |
3384 | } |
3385 | ||
8313c10f | 3386 | static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs, |
c89d1bed SH |
3387 | struct ib_uverbs_create_xsrq *cmd, |
3388 | struct ib_udata *udata) | |
f520ba5a | 3389 | { |
16e51f78 | 3390 | struct ib_uverbs_create_srq_resp resp = {}; |
8541f8de | 3391 | struct ib_usrq_object *obj; |
f520ba5a RD |
3392 | struct ib_pd *pd; |
3393 | struct ib_srq *srq; | |
3394 | struct ib_srq_init_attr attr; | |
3395 | int ret; | |
29f3fe1d | 3396 | struct ib_uobject *xrcd_uobj; |
bbd51e88 | 3397 | struct ib_device *ib_dev; |
f520ba5a | 3398 | |
8313c10f | 3399 | obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs, |
bbd51e88 | 3400 | &ib_dev); |
fd3c7904 MB |
3401 | if (IS_ERR(obj)) |
3402 | return PTR_ERR(obj); | |
f520ba5a | 3403 | |
38eb44fa AK |
3404 | if (cmd->srq_type == IB_SRQT_TM) |
3405 | attr.ext.tag_matching.max_num_tags = cmd->max_num_tags; | |
3406 | ||
8541f8de | 3407 | if (cmd->srq_type == IB_SRQT_XRC) { |
1f7ff9d5 | 3408 | xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle, |
8313c10f | 3409 | attrs); |
fd3c7904 | 3410 | if (IS_ERR(xrcd_uobj)) { |
8541f8de | 3411 | ret = -EINVAL; |
5909ce54 | 3412 | goto err; |
8541f8de SH |
3413 | } |
3414 | ||
fd3c7904 MB |
3415 | attr.ext.xrc.xrcd = (struct ib_xrcd *)xrcd_uobj->object; |
3416 | if (!attr.ext.xrc.xrcd) { | |
3417 | ret = -EINVAL; | |
3418 | goto err_put_xrcd; | |
3419 | } | |
3420 | ||
8541f8de SH |
3421 | obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject); |
3422 | atomic_inc(&obj->uxrcd->refcnt); | |
1a56ff6d | 3423 | } |
5909ce54 | 3424 | |
1a56ff6d | 3425 | if (ib_srq_has_cq(cmd->srq_type)) { |
2cc1e3b8 | 3426 | attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, |
8313c10f | 3427 | cmd->cq_handle, attrs); |
81f8f745 MS |
3428 | if (IS_ERR(attr.ext.cq)) { |
3429 | ret = PTR_ERR(attr.ext.cq); | |
5909ce54 RD |
3430 | goto err_put_xrcd; |
3431 | } | |
3432 | } | |
3433 | ||
8313c10f | 3434 | pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs); |
81f8f745 MS |
3435 | if (IS_ERR(pd)) { |
3436 | ret = PTR_ERR(pd); | |
5909ce54 | 3437 | goto err_put_cq; |
8541f8de SH |
3438 | } |
3439 | ||
f520ba5a | 3440 | attr.event_handler = ib_uverbs_srq_event_handler; |
8541f8de SH |
3441 | attr.srq_type = cmd->srq_type; |
3442 | attr.attr.max_wr = cmd->max_wr; | |
3443 | attr.attr.max_sge = cmd->max_sge; | |
3444 | attr.attr.srq_limit = cmd->srq_limit; | |
f520ba5a | 3445 | |
8541f8de | 3446 | INIT_LIST_HEAD(&obj->uevent.event_list); |
b0810b03 | 3447 | obj->uevent.uobject.user_handle = cmd->user_handle; |
f520ba5a | 3448 | |
b0810b03 JG |
3449 | srq = ib_create_srq_user(pd, &attr, obj, udata); |
3450 | if (IS_ERR(srq)) { | |
3451 | ret = PTR_ERR(srq); | |
3452 | goto err_put_pd; | |
8541f8de SH |
3453 | } |
3454 | ||
8541f8de | 3455 | obj->uevent.uobject.object = srq; |
98a8890f YH |
3456 | obj->uevent.uobject.user_handle = cmd->user_handle; |
3457 | obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file); | |
3458 | if (obj->uevent.event_file) | |
3459 | uverbs_uobject_get(&obj->uevent.event_file->uobj); | |
f520ba5a | 3460 | |
8541f8de SH |
3461 | if (cmd->srq_type == IB_SRQT_XRC) |
3462 | resp.srqn = srq->ext.xrc.srq_num; | |
f520ba5a | 3463 | |
1a56ff6d | 3464 | if (cmd->srq_type == IB_SRQT_XRC) |
fd3c7904 | 3465 | uobj_put_read(xrcd_uobj); |
1a56ff6d AK |
3466 | |
3467 | if (ib_srq_has_cq(cmd->srq_type)) | |
5bd48c18 JG |
3468 | rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject, |
3469 | UVERBS_LOOKUP_READ); | |
1a56ff6d | 3470 | |
fd3c7904 | 3471 | uobj_put_obj_read(pd); |
16e51f78 LR |
3472 | uobj_finalize_uobj_create(&obj->uevent.uobject, attrs); |
3473 | ||
3474 | resp.srq_handle = obj->uevent.uobject.id; | |
3475 | resp.max_wr = attr.attr.max_wr; | |
3476 | resp.max_sge = attr.attr.max_sge; | |
3477 | return uverbs_response(attrs, &resp, sizeof(resp)); | |
f520ba5a | 3478 | |
b0810b03 | 3479 | err_put_pd: |
fd3c7904 | 3480 | uobj_put_obj_read(pd); |
8541f8de | 3481 | err_put_cq: |
1a56ff6d | 3482 | if (ib_srq_has_cq(cmd->srq_type)) |
5bd48c18 JG |
3483 | rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject, |
3484 | UVERBS_LOOKUP_READ); | |
8541f8de | 3485 | |
5909ce54 RD |
3486 | err_put_xrcd: |
3487 | if (cmd->srq_type == IB_SRQT_XRC) { | |
3488 | atomic_dec(&obj->uxrcd->refcnt); | |
fd3c7904 | 3489 | uobj_put_read(xrcd_uobj); |
5909ce54 | 3490 | } |
ec924b47 | 3491 | |
9ead190b | 3492 | err: |
a6a3797d | 3493 | uobj_alloc_abort(&obj->uevent.uobject, attrs); |
f520ba5a RD |
3494 | return ret; |
3495 | } | |
3496 | ||
974d6b4b | 3497 | static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs) |
8541f8de SH |
3498 | { |
3499 | struct ib_uverbs_create_srq cmd; | |
3500 | struct ib_uverbs_create_xsrq xcmd; | |
3c2c2094 | 3501 | int ret; |
8541f8de | 3502 | |
3c2c2094 JG |
3503 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
3504 | if (ret) | |
3505 | return ret; | |
8541f8de | 3506 | |
38eb44fa | 3507 | memset(&xcmd, 0, sizeof(xcmd)); |
8541f8de SH |
3508 | xcmd.response = cmd.response; |
3509 | xcmd.user_handle = cmd.user_handle; | |
3510 | xcmd.srq_type = IB_SRQT_BASIC; | |
3511 | xcmd.pd_handle = cmd.pd_handle; | |
3512 | xcmd.max_wr = cmd.max_wr; | |
3513 | xcmd.max_sge = cmd.max_sge; | |
3514 | xcmd.srq_limit = cmd.srq_limit; | |
3515 | ||
ef87df2c | 3516 | return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata); |
8541f8de SH |
3517 | } |
3518 | ||
974d6b4b | 3519 | static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs) |
8541f8de SH |
3520 | { |
3521 | struct ib_uverbs_create_xsrq cmd; | |
3c2c2094 | 3522 | int ret; |
8541f8de | 3523 | |
3c2c2094 JG |
3524 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
3525 | if (ret) | |
3526 | return ret; | |
8541f8de | 3527 | |
ef87df2c | 3528 | return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata); |
8541f8de SH |
3529 | } |
3530 | ||
974d6b4b | 3531 | static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs) |
f520ba5a RD |
3532 | { |
3533 | struct ib_uverbs_modify_srq cmd; | |
3534 | struct ib_srq *srq; | |
3535 | struct ib_srq_attr attr; | |
3536 | int ret; | |
3537 | ||
3c2c2094 JG |
3538 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
3539 | if (ret) | |
3540 | return ret; | |
f520ba5a | 3541 | |
8313c10f | 3542 | srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); |
81f8f745 MS |
3543 | if (IS_ERR(srq)) |
3544 | return PTR_ERR(srq); | |
f520ba5a RD |
3545 | |
3546 | attr.max_wr = cmd.max_wr; | |
f520ba5a RD |
3547 | attr.srq_limit = cmd.srq_limit; |
3548 | ||
3023a1e9 KH |
3549 | ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask, |
3550 | &attrs->driver_udata); | |
f520ba5a | 3551 | |
9fbe334c JG |
3552 | rdma_lookup_put_uobject(&srq->uobject->uevent.uobject, |
3553 | UVERBS_LOOKUP_READ); | |
f520ba5a | 3554 | |
7106a976 | 3555 | return ret; |
f520ba5a RD |
3556 | } |
3557 | ||
974d6b4b | 3558 | static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs) |
8bdb0e86 DB |
3559 | { |
3560 | struct ib_uverbs_query_srq cmd; | |
3561 | struct ib_uverbs_query_srq_resp resp; | |
3562 | struct ib_srq_attr attr; | |
3563 | struct ib_srq *srq; | |
3564 | int ret; | |
3565 | ||
3c2c2094 JG |
3566 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
3567 | if (ret) | |
3568 | return ret; | |
8bdb0e86 | 3569 | |
8313c10f | 3570 | srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); |
81f8f745 MS |
3571 | if (IS_ERR(srq)) |
3572 | return PTR_ERR(srq); | |
8bdb0e86 | 3573 | |
9ead190b | 3574 | ret = ib_query_srq(srq, &attr); |
8bdb0e86 | 3575 | |
9fbe334c JG |
3576 | rdma_lookup_put_uobject(&srq->uobject->uevent.uobject, |
3577 | UVERBS_LOOKUP_READ); | |
8bdb0e86 DB |
3578 | |
3579 | if (ret) | |
9ead190b | 3580 | return ret; |
8bdb0e86 DB |
3581 | |
3582 | memset(&resp, 0, sizeof resp); | |
3583 | ||
3584 | resp.max_wr = attr.max_wr; | |
3585 | resp.max_sge = attr.max_sge; | |
3586 | resp.srq_limit = attr.srq_limit; | |
3587 | ||
9a073857 | 3588 | return uverbs_response(attrs, &resp, sizeof(resp)); |
8bdb0e86 DB |
3589 | } |
3590 | ||
974d6b4b | 3591 | static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs) |
f520ba5a | 3592 | { |
63aaf647 RD |
3593 | struct ib_uverbs_destroy_srq cmd; |
3594 | struct ib_uverbs_destroy_srq_resp resp; | |
9ead190b | 3595 | struct ib_uobject *uobj; |
9ead190b | 3596 | struct ib_uevent_object *obj; |
3c2c2094 | 3597 | int ret; |
f520ba5a | 3598 | |
3c2c2094 JG |
3599 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
3600 | if (ret) | |
3601 | return ret; | |
f520ba5a | 3602 | |
8313c10f | 3603 | uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs); |
fd3c7904 MB |
3604 | if (IS_ERR(uobj)) |
3605 | return PTR_ERR(uobj); | |
3606 | ||
9ead190b | 3607 | obj = container_of(uobj, struct ib_uevent_object, uobject); |
fd3c7904 | 3608 | memset(&resp, 0, sizeof(resp)); |
9ead190b | 3609 | resp.events_reported = obj->events_reported; |
32ed5c00 JG |
3610 | |
3611 | uobj_put_destroy(uobj); | |
3612 | ||
9a073857 | 3613 | return uverbs_response(attrs, &resp, sizeof(resp)); |
f520ba5a | 3614 | } |
02d1aa7a | 3615 | |
974d6b4b | 3616 | static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs) |
02d1aa7a | 3617 | { |
7eebced1 | 3618 | struct ib_uverbs_ex_query_device_resp resp = {}; |
02d1aa7a | 3619 | struct ib_uverbs_ex_query_device cmd; |
2953f425 | 3620 | struct ib_device_attr attr = {0}; |
bbd51e88 JG |
3621 | struct ib_ucontext *ucontext; |
3622 | struct ib_device *ib_dev; | |
02d1aa7a EC |
3623 | int err; |
3624 | ||
8313c10f | 3625 | ucontext = ib_uverbs_get_ucontext(attrs); |
bbd51e88 JG |
3626 | if (IS_ERR(ucontext)) |
3627 | return PTR_ERR(ucontext); | |
3628 | ib_dev = ucontext->device; | |
3629 | ||
7eebced1 | 3630 | err = uverbs_request(attrs, &cmd, sizeof(cmd)); |
02d1aa7a EC |
3631 | if (err) |
3632 | return err; | |
3633 | ||
3634 | if (cmd.comp_mask) | |
3635 | return -EINVAL; | |
3636 | ||
3637 | if (cmd.reserved) | |
3638 | return -EINVAL; | |
3639 | ||
3023a1e9 | 3640 | err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata); |
02d1aa7a EC |
3641 | if (err) |
3642 | return err; | |
3643 | ||
bbd51e88 | 3644 | copy_query_dev_fields(ucontext, &resp.base, &attr); |
02d1aa7a | 3645 | |
f4056bfd HE |
3646 | resp.odp_caps.general_caps = attr.odp_caps.general_caps; |
3647 | resp.odp_caps.per_transport_caps.rc_odp_caps = | |
3648 | attr.odp_caps.per_transport_caps.rc_odp_caps; | |
3649 | resp.odp_caps.per_transport_caps.uc_odp_caps = | |
3650 | attr.odp_caps.per_transport_caps.uc_odp_caps; | |
3651 | resp.odp_caps.per_transport_caps.ud_odp_caps = | |
3652 | attr.odp_caps.per_transport_caps.ud_odp_caps; | |
52a72e2a | 3653 | resp.xrc_odp_caps = attr.odp_caps.per_transport_caps.xrc_odp_caps; |
24306dc6 MB |
3654 | |
3655 | resp.timestamp_mask = attr.timestamp_mask; | |
24306dc6 | 3656 | resp.hca_core_clock = attr.hca_core_clock; |
e945c653 | 3657 | resp.device_cap_flags_ex = attr.device_cap_flags; |
47adf2f4 YH |
3658 | resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts; |
3659 | resp.rss_caps.max_rwq_indirection_tables = | |
3660 | attr.rss_caps.max_rwq_indirection_tables; | |
3661 | resp.rss_caps.max_rwq_indirection_table_size = | |
3662 | attr.rss_caps.max_rwq_indirection_table_size; | |
47adf2f4 | 3663 | resp.max_wq_type_rq = attr.max_wq_type_rq; |
5f23d426 | 3664 | resp.raw_packet_caps = attr.raw_packet_caps; |
78b1beb0 LR |
3665 | resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size; |
3666 | resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags; | |
3667 | resp.tm_caps.max_ops = attr.tm_caps.max_ops; | |
3668 | resp.tm_caps.max_sge = attr.tm_caps.max_sge; | |
3669 | resp.tm_caps.flags = attr.tm_caps.flags; | |
18bd9072 YC |
3670 | resp.cq_moderation_caps.max_cq_moderation_count = |
3671 | attr.cq_caps.max_cq_moderation_count; | |
3672 | resp.cq_moderation_caps.max_cq_moderation_period = | |
3673 | attr.cq_caps.max_cq_moderation_period; | |
1d8eeb9f | 3674 | resp.max_dm_size = attr.max_dm_size; |
7eebced1 JG |
3675 | resp.response_length = uverbs_response_length(attrs, sizeof(resp)); |
3676 | ||
9a073857 | 3677 | return uverbs_response(attrs, &resp, sizeof(resp)); |
02d1aa7a | 3678 | } |
869ddcf8 | 3679 | |
974d6b4b | 3680 | static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs) |
869ddcf8 | 3681 | { |
29a29d18 | 3682 | struct ib_uverbs_ex_modify_cq cmd; |
869ddcf8 | 3683 | struct ib_cq *cq; |
869ddcf8 YC |
3684 | int ret; |
3685 | ||
29a29d18 | 3686 | ret = uverbs_request(attrs, &cmd, sizeof(cmd)); |
869ddcf8 YC |
3687 | if (ret) |
3688 | return ret; | |
3689 | ||
3690 | if (!cmd.attr_mask || cmd.reserved) | |
3691 | return -EINVAL; | |
3692 | ||
3693 | if (cmd.attr_mask > IB_CQ_MODERATE) | |
3694 | return -EOPNOTSUPP; | |
3695 | ||
8313c10f | 3696 | cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs); |
81f8f745 MS |
3697 | if (IS_ERR(cq)) |
3698 | return PTR_ERR(cq); | |
869ddcf8 | 3699 | |
4190b4e9 | 3700 | ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period); |
869ddcf8 | 3701 | |
5bd48c18 JG |
3702 | rdma_lookup_put_uobject(&cq->uobject->uevent.uobject, |
3703 | UVERBS_LOOKUP_READ); | |
869ddcf8 YC |
3704 | return ret; |
3705 | } | |
d120c3c9 | 3706 | |
669dac1e JG |
3707 | /* |
3708 | * Describe the input structs for write(). Some write methods have an input | |
3709 | * only struct, most have an input and output. If the struct has an output then | |
3710 | * the 'response' u64 must be the first field in the request structure. | |
3711 | * | |
3712 | * If udata is present then both the request and response structs have a | |
3713 | * trailing driver_data flex array. In this case the size of the base struct | |
3714 | * cannot be changed. | |
3715 | */ | |
669dac1e JG |
3716 | #define UAPI_DEF_WRITE_IO(req, resp) \ |
3717 | .write.has_resp = 1 + \ | |
3718 | BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \ | |
bebcfe85 | 3719 | BUILD_BUG_ON_ZERO(sizeof_field(req, response) != \ |
669dac1e JG |
3720 | sizeof(u64)), \ |
3721 | .write.req_size = sizeof(req), .write.resp_size = sizeof(resp) | |
3722 | ||
3723 | #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req) | |
3724 | ||
3725 | #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \ | |
3726 | UAPI_DEF_WRITE_IO(req, resp), \ | |
3727 | .write.has_udata = \ | |
3728 | 1 + \ | |
3729 | BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \ | |
3730 | sizeof(req)) + \ | |
3731 | BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \ | |
3732 | sizeof(resp)) | |
3733 | ||
3734 | #define UAPI_DEF_WRITE_UDATA_I(req) \ | |
3735 | UAPI_DEF_WRITE_I(req), \ | |
3736 | .write.has_udata = \ | |
3737 | 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \ | |
3738 | sizeof(req)) | |
3739 | ||
3740 | /* | |
3741 | * The _EX versions are for use with WRITE_EX and allow the last struct member | |
3742 | * to be specified. Buffers that do not include that member will be rejected. | |
3743 | */ | |
3744 | #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \ | |
3745 | .write.has_resp = 1, \ | |
d384742e JG |
3746 | .write.req_size = offsetofend(req, req_last_member), \ |
3747 | .write.resp_size = offsetofend(resp, resp_last_member) | |
669dac1e JG |
3748 | |
3749 | #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \ | |
d384742e | 3750 | .write.req_size = offsetofend(req, req_last_member) |
669dac1e | 3751 | |
d120c3c9 | 3752 | const struct uapi_definition uverbs_def_write_intf[] = { |
a140692a JG |
3753 | DECLARE_UVERBS_OBJECT( |
3754 | UVERBS_OBJECT_AH, | |
3755 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH, | |
3756 | ib_uverbs_create_ah, | |
669dac1e JG |
3757 | UAPI_DEF_WRITE_UDATA_IO( |
3758 | struct ib_uverbs_create_ah, | |
676a80ad | 3759 | struct ib_uverbs_create_ah_resp)), |
669dac1e JG |
3760 | DECLARE_UVERBS_WRITE( |
3761 | IB_USER_VERBS_CMD_DESTROY_AH, | |
3762 | ib_uverbs_destroy_ah, | |
676a80ad JG |
3763 | UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah)), |
3764 | UAPI_DEF_OBJ_NEEDS_FN(create_user_ah), | |
3765 | UAPI_DEF_OBJ_NEEDS_FN(destroy_ah)), | |
d120c3c9 JG |
3766 | |
3767 | DECLARE_UVERBS_OBJECT( | |
3768 | UVERBS_OBJECT_COMP_CHANNEL, | |
669dac1e JG |
3769 | DECLARE_UVERBS_WRITE( |
3770 | IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL, | |
3771 | ib_uverbs_create_comp_channel, | |
3772 | UAPI_DEF_WRITE_IO( | |
3773 | struct ib_uverbs_create_comp_channel, | |
3774 | struct ib_uverbs_create_comp_channel_resp))), | |
d120c3c9 JG |
3775 | |
3776 | DECLARE_UVERBS_OBJECT( | |
3777 | UVERBS_OBJECT_CQ, | |
3778 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ, | |
a140692a | 3779 | ib_uverbs_create_cq, |
669dac1e JG |
3780 | UAPI_DEF_WRITE_UDATA_IO( |
3781 | struct ib_uverbs_create_cq, | |
3782 | struct ib_uverbs_create_cq_resp), | |
a140692a | 3783 | UAPI_DEF_METHOD_NEEDS_FN(create_cq)), |
669dac1e JG |
3784 | DECLARE_UVERBS_WRITE( |
3785 | IB_USER_VERBS_CMD_DESTROY_CQ, | |
3786 | ib_uverbs_destroy_cq, | |
3787 | UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq, | |
3788 | struct ib_uverbs_destroy_cq_resp), | |
3789 | UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)), | |
3790 | DECLARE_UVERBS_WRITE( | |
3791 | IB_USER_VERBS_CMD_POLL_CQ, | |
3792 | ib_uverbs_poll_cq, | |
3793 | UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq, | |
3794 | struct ib_uverbs_poll_cq_resp), | |
3795 | UAPI_DEF_METHOD_NEEDS_FN(poll_cq)), | |
3796 | DECLARE_UVERBS_WRITE( | |
3797 | IB_USER_VERBS_CMD_REQ_NOTIFY_CQ, | |
3798 | ib_uverbs_req_notify_cq, | |
3799 | UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq), | |
3800 | UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)), | |
d120c3c9 | 3801 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ, |
a140692a | 3802 | ib_uverbs_resize_cq, |
669dac1e JG |
3803 | UAPI_DEF_WRITE_UDATA_IO( |
3804 | struct ib_uverbs_resize_cq, | |
3805 | struct ib_uverbs_resize_cq_resp), | |
a140692a | 3806 | UAPI_DEF_METHOD_NEEDS_FN(resize_cq)), |
669dac1e JG |
3807 | DECLARE_UVERBS_WRITE_EX( |
3808 | IB_USER_VERBS_EX_CMD_CREATE_CQ, | |
3809 | ib_uverbs_ex_create_cq, | |
3810 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq, | |
3811 | reserved, | |
3812 | struct ib_uverbs_ex_create_cq_resp, | |
3813 | response_length), | |
3814 | UAPI_DEF_METHOD_NEEDS_FN(create_cq)), | |
3815 | DECLARE_UVERBS_WRITE_EX( | |
3816 | IB_USER_VERBS_EX_CMD_MODIFY_CQ, | |
3817 | ib_uverbs_ex_modify_cq, | |
3818 | UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq), | |
b8e3130d | 3819 | UAPI_DEF_METHOD_NEEDS_FN(modify_cq))), |
d120c3c9 JG |
3820 | |
3821 | DECLARE_UVERBS_OBJECT( | |
3822 | UVERBS_OBJECT_DEVICE, | |
3823 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT, | |
669dac1e JG |
3824 | ib_uverbs_get_context, |
3825 | UAPI_DEF_WRITE_UDATA_IO( | |
3826 | struct ib_uverbs_get_context, | |
3827 | struct ib_uverbs_get_context_resp)), | |
3828 | DECLARE_UVERBS_WRITE( | |
3829 | IB_USER_VERBS_CMD_QUERY_DEVICE, | |
3830 | ib_uverbs_query_device, | |
3831 | UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device, | |
3832 | struct ib_uverbs_query_device_resp)), | |
3833 | DECLARE_UVERBS_WRITE( | |
3834 | IB_USER_VERBS_CMD_QUERY_PORT, | |
3835 | ib_uverbs_query_port, | |
3836 | UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port, | |
3837 | struct ib_uverbs_query_port_resp), | |
3838 | UAPI_DEF_METHOD_NEEDS_FN(query_port)), | |
3839 | DECLARE_UVERBS_WRITE_EX( | |
3840 | IB_USER_VERBS_EX_CMD_QUERY_DEVICE, | |
3841 | ib_uverbs_ex_query_device, | |
3842 | UAPI_DEF_WRITE_IO_EX( | |
3843 | struct ib_uverbs_ex_query_device, | |
3844 | reserved, | |
3845 | struct ib_uverbs_ex_query_device_resp, | |
3846 | response_length), | |
3847 | UAPI_DEF_METHOD_NEEDS_FN(query_device)), | |
a140692a JG |
3848 | UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext), |
3849 | UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)), | |
d120c3c9 JG |
3850 | |
3851 | DECLARE_UVERBS_OBJECT( | |
3852 | UVERBS_OBJECT_FLOW, | |
669dac1e JG |
3853 | DECLARE_UVERBS_WRITE_EX( |
3854 | IB_USER_VERBS_EX_CMD_CREATE_FLOW, | |
3855 | ib_uverbs_ex_create_flow, | |
3856 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow, | |
3857 | flow_attr, | |
3858 | struct ib_uverbs_create_flow_resp, | |
3859 | flow_handle), | |
3860 | UAPI_DEF_METHOD_NEEDS_FN(create_flow)), | |
3861 | DECLARE_UVERBS_WRITE_EX( | |
3862 | IB_USER_VERBS_EX_CMD_DESTROY_FLOW, | |
3863 | ib_uverbs_ex_destroy_flow, | |
3864 | UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow), | |
3865 | UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))), | |
a140692a JG |
3866 | |
3867 | DECLARE_UVERBS_OBJECT( | |
3868 | UVERBS_OBJECT_MR, | |
3869 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR, | |
3870 | ib_uverbs_dereg_mr, | |
669dac1e | 3871 | UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr), |
a140692a | 3872 | UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)), |
669dac1e JG |
3873 | DECLARE_UVERBS_WRITE( |
3874 | IB_USER_VERBS_CMD_REG_MR, | |
3875 | ib_uverbs_reg_mr, | |
3876 | UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr, | |
3877 | struct ib_uverbs_reg_mr_resp), | |
3878 | UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)), | |
3879 | DECLARE_UVERBS_WRITE( | |
3880 | IB_USER_VERBS_CMD_REREG_MR, | |
3881 | ib_uverbs_rereg_mr, | |
3882 | UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr, | |
3883 | struct ib_uverbs_rereg_mr_resp), | |
3884 | UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))), | |
a140692a JG |
3885 | |
3886 | DECLARE_UVERBS_OBJECT( | |
3887 | UVERBS_OBJECT_MW, | |
669dac1e JG |
3888 | DECLARE_UVERBS_WRITE( |
3889 | IB_USER_VERBS_CMD_ALLOC_MW, | |
3890 | ib_uverbs_alloc_mw, | |
3891 | UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw, | |
3892 | struct ib_uverbs_alloc_mw_resp), | |
3893 | UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)), | |
3894 | DECLARE_UVERBS_WRITE( | |
3895 | IB_USER_VERBS_CMD_DEALLOC_MW, | |
3896 | ib_uverbs_dealloc_mw, | |
3897 | UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw), | |
3898 | UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))), | |
a140692a JG |
3899 | |
3900 | DECLARE_UVERBS_OBJECT( | |
3901 | UVERBS_OBJECT_PD, | |
669dac1e JG |
3902 | DECLARE_UVERBS_WRITE( |
3903 | IB_USER_VERBS_CMD_ALLOC_PD, | |
3904 | ib_uverbs_alloc_pd, | |
3905 | UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd, | |
3906 | struct ib_uverbs_alloc_pd_resp), | |
3907 | UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)), | |
3908 | DECLARE_UVERBS_WRITE( | |
3909 | IB_USER_VERBS_CMD_DEALLOC_PD, | |
3910 | ib_uverbs_dealloc_pd, | |
3911 | UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd), | |
3912 | UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))), | |
d120c3c9 JG |
3913 | |
3914 | DECLARE_UVERBS_OBJECT( | |
3915 | UVERBS_OBJECT_QP, | |
669dac1e JG |
3916 | DECLARE_UVERBS_WRITE( |
3917 | IB_USER_VERBS_CMD_ATTACH_MCAST, | |
3918 | ib_uverbs_attach_mcast, | |
3919 | UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast), | |
3920 | UAPI_DEF_METHOD_NEEDS_FN(attach_mcast), | |
3921 | UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)), | |
d120c3c9 | 3922 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP, |
a140692a | 3923 | ib_uverbs_create_qp, |
669dac1e JG |
3924 | UAPI_DEF_WRITE_UDATA_IO( |
3925 | struct ib_uverbs_create_qp, | |
3926 | struct ib_uverbs_create_qp_resp), | |
a140692a | 3927 | UAPI_DEF_METHOD_NEEDS_FN(create_qp)), |
669dac1e JG |
3928 | DECLARE_UVERBS_WRITE( |
3929 | IB_USER_VERBS_CMD_DESTROY_QP, | |
3930 | ib_uverbs_destroy_qp, | |
3931 | UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp, | |
3932 | struct ib_uverbs_destroy_qp_resp), | |
3933 | UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)), | |
3934 | DECLARE_UVERBS_WRITE( | |
3935 | IB_USER_VERBS_CMD_DETACH_MCAST, | |
3936 | ib_uverbs_detach_mcast, | |
3937 | UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast), | |
3938 | UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)), | |
3939 | DECLARE_UVERBS_WRITE( | |
3940 | IB_USER_VERBS_CMD_MODIFY_QP, | |
3941 | ib_uverbs_modify_qp, | |
3942 | UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp), | |
3943 | UAPI_DEF_METHOD_NEEDS_FN(modify_qp)), | |
3944 | DECLARE_UVERBS_WRITE( | |
3945 | IB_USER_VERBS_CMD_POST_RECV, | |
3946 | ib_uverbs_post_recv, | |
3947 | UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv, | |
3948 | struct ib_uverbs_post_recv_resp), | |
3949 | UAPI_DEF_METHOD_NEEDS_FN(post_recv)), | |
3950 | DECLARE_UVERBS_WRITE( | |
3951 | IB_USER_VERBS_CMD_POST_SEND, | |
3952 | ib_uverbs_post_send, | |
3953 | UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send, | |
3954 | struct ib_uverbs_post_send_resp), | |
3955 | UAPI_DEF_METHOD_NEEDS_FN(post_send)), | |
3956 | DECLARE_UVERBS_WRITE( | |
3957 | IB_USER_VERBS_CMD_QUERY_QP, | |
3958 | ib_uverbs_query_qp, | |
3959 | UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp, | |
3960 | struct ib_uverbs_query_qp_resp), | |
3961 | UAPI_DEF_METHOD_NEEDS_FN(query_qp)), | |
3962 | DECLARE_UVERBS_WRITE_EX( | |
3963 | IB_USER_VERBS_EX_CMD_CREATE_QP, | |
3964 | ib_uverbs_ex_create_qp, | |
3965 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp, | |
3966 | comp_mask, | |
3967 | struct ib_uverbs_ex_create_qp_resp, | |
3968 | response_length), | |
3969 | UAPI_DEF_METHOD_NEEDS_FN(create_qp)), | |
3970 | DECLARE_UVERBS_WRITE_EX( | |
3971 | IB_USER_VERBS_EX_CMD_MODIFY_QP, | |
3972 | ib_uverbs_ex_modify_qp, | |
3973 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp, | |
3974 | base, | |
3975 | struct ib_uverbs_ex_modify_qp_resp, | |
3976 | response_length), | |
3977 | UAPI_DEF_METHOD_NEEDS_FN(modify_qp))), | |
d120c3c9 JG |
3978 | |
3979 | DECLARE_UVERBS_OBJECT( | |
3980 | UVERBS_OBJECT_RWQ_IND_TBL, | |
a140692a JG |
3981 | DECLARE_UVERBS_WRITE_EX( |
3982 | IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL, | |
3983 | ib_uverbs_ex_create_rwq_ind_table, | |
669dac1e JG |
3984 | UAPI_DEF_WRITE_IO_EX( |
3985 | struct ib_uverbs_ex_create_rwq_ind_table, | |
3986 | log_ind_tbl_size, | |
3987 | struct ib_uverbs_ex_create_rwq_ind_table_resp, | |
3988 | ind_tbl_num), | |
a140692a JG |
3989 | UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)), |
3990 | DECLARE_UVERBS_WRITE_EX( | |
3991 | IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL, | |
3992 | ib_uverbs_ex_destroy_rwq_ind_table, | |
669dac1e JG |
3993 | UAPI_DEF_WRITE_I( |
3994 | struct ib_uverbs_ex_destroy_rwq_ind_table), | |
a140692a | 3995 | UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))), |
d120c3c9 JG |
3996 | |
3997 | DECLARE_UVERBS_OBJECT( | |
3998 | UVERBS_OBJECT_WQ, | |
669dac1e JG |
3999 | DECLARE_UVERBS_WRITE_EX( |
4000 | IB_USER_VERBS_EX_CMD_CREATE_WQ, | |
4001 | ib_uverbs_ex_create_wq, | |
4002 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq, | |
4003 | max_sge, | |
4004 | struct ib_uverbs_ex_create_wq_resp, | |
4005 | wqn), | |
4006 | UAPI_DEF_METHOD_NEEDS_FN(create_wq)), | |
4007 | DECLARE_UVERBS_WRITE_EX( | |
4008 | IB_USER_VERBS_EX_CMD_DESTROY_WQ, | |
4009 | ib_uverbs_ex_destroy_wq, | |
4010 | UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq, | |
4011 | wq_handle, | |
4012 | struct ib_uverbs_ex_destroy_wq_resp, | |
4013 | reserved), | |
4014 | UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)), | |
4015 | DECLARE_UVERBS_WRITE_EX( | |
4016 | IB_USER_VERBS_EX_CMD_MODIFY_WQ, | |
4017 | ib_uverbs_ex_modify_wq, | |
4018 | UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq, | |
4019 | curr_wq_state), | |
4020 | UAPI_DEF_METHOD_NEEDS_FN(modify_wq))), | |
d120c3c9 JG |
4021 | |
4022 | DECLARE_UVERBS_OBJECT( | |
4023 | UVERBS_OBJECT_SRQ, | |
4024 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ, | |
a140692a | 4025 | ib_uverbs_create_srq, |
669dac1e JG |
4026 | UAPI_DEF_WRITE_UDATA_IO( |
4027 | struct ib_uverbs_create_srq, | |
4028 | struct ib_uverbs_create_srq_resp), | |
a140692a | 4029 | UAPI_DEF_METHOD_NEEDS_FN(create_srq)), |
d120c3c9 | 4030 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ, |
a140692a | 4031 | ib_uverbs_create_xsrq, |
669dac1e JG |
4032 | UAPI_DEF_WRITE_UDATA_IO( |
4033 | struct ib_uverbs_create_xsrq, | |
4034 | struct ib_uverbs_create_srq_resp), | |
a140692a | 4035 | UAPI_DEF_METHOD_NEEDS_FN(create_srq)), |
669dac1e JG |
4036 | DECLARE_UVERBS_WRITE( |
4037 | IB_USER_VERBS_CMD_DESTROY_SRQ, | |
4038 | ib_uverbs_destroy_srq, | |
4039 | UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq, | |
4040 | struct ib_uverbs_destroy_srq_resp), | |
4041 | UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)), | |
4042 | DECLARE_UVERBS_WRITE( | |
4043 | IB_USER_VERBS_CMD_MODIFY_SRQ, | |
4044 | ib_uverbs_modify_srq, | |
4045 | UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq), | |
4046 | UAPI_DEF_METHOD_NEEDS_FN(modify_srq)), | |
4047 | DECLARE_UVERBS_WRITE( | |
4048 | IB_USER_VERBS_CMD_POST_SRQ_RECV, | |
4049 | ib_uverbs_post_srq_recv, | |
4050 | UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv, | |
4051 | struct ib_uverbs_post_srq_recv_resp), | |
4052 | UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)), | |
4053 | DECLARE_UVERBS_WRITE( | |
4054 | IB_USER_VERBS_CMD_QUERY_SRQ, | |
4055 | ib_uverbs_query_srq, | |
4056 | UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq, | |
4057 | struct ib_uverbs_query_srq_resp), | |
4058 | UAPI_DEF_METHOD_NEEDS_FN(query_srq))), | |
a140692a JG |
4059 | |
4060 | DECLARE_UVERBS_OBJECT( | |
4061 | UVERBS_OBJECT_XRCD, | |
669dac1e JG |
4062 | DECLARE_UVERBS_WRITE( |
4063 | IB_USER_VERBS_CMD_CLOSE_XRCD, | |
4064 | ib_uverbs_close_xrcd, | |
44ce37bc | 4065 | UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd)), |
a140692a | 4066 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP, |
669dac1e JG |
4067 | ib_uverbs_open_qp, |
4068 | UAPI_DEF_WRITE_UDATA_IO( | |
4069 | struct ib_uverbs_open_qp, | |
4070 | struct ib_uverbs_create_qp_resp)), | |
a140692a JG |
4071 | DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD, |
4072 | ib_uverbs_open_xrcd, | |
669dac1e JG |
4073 | UAPI_DEF_WRITE_UDATA_IO( |
4074 | struct ib_uverbs_open_xrcd, | |
44ce37bc JG |
4075 | struct ib_uverbs_open_xrcd_resp)), |
4076 | UAPI_DEF_OBJ_NEEDS_FN(alloc_xrcd), | |
4077 | UAPI_DEF_OBJ_NEEDS_FN(dealloc_xrcd)), | |
d120c3c9 JG |
4078 | |
4079 | {}, | |
4080 | }; |