Commit | Line | Data |
---|---|---|
bc38a6ab RD |
1 | /* |
2 | * Copyright (c) 2005 Topspin Communications. All rights reserved. | |
33b9b3ee | 3 | * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. |
2a1d9b7f RD |
4 | * Copyright (c) 2005 Mellanox Technologies. All rights reserved. |
5 | * Copyright (c) 2005 Voltaire, Inc. All rights reserved. | |
67cdb40c | 6 | * Copyright (c) 2005 PathScale, Inc. All rights reserved. |
bc38a6ab RD |
7 | * |
8 | * This software is available to you under a choice of one of two | |
9 | * licenses. You may choose to be licensed under the terms of the GNU | |
10 | * General Public License (GPL) Version 2, available from the file | |
11 | * COPYING in the main directory of this source tree, or the | |
12 | * OpenIB.org BSD license below: | |
13 | * | |
14 | * Redistribution and use in source and binary forms, with or | |
15 | * without modification, are permitted provided that the following | |
16 | * conditions are met: | |
17 | * | |
18 | * - Redistributions of source code must retain the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer. | |
21 | * | |
22 | * - Redistributions in binary form must reproduce the above | |
23 | * copyright notice, this list of conditions and the following | |
24 | * disclaimer in the documentation and/or other materials | |
25 | * provided with the distribution. | |
26 | * | |
27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
28 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
29 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
30 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
31 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
32 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
33 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
34 | * SOFTWARE. | |
bc38a6ab RD |
35 | */ |
36 | ||
37 | #ifndef UVERBS_H | |
38 | #define UVERBS_H | |
39 | ||
bc38a6ab RD |
40 | #include <linux/kref.h> |
41 | #include <linux/idr.h> | |
95ed644f | 42 | #include <linux/mutex.h> |
fd60ae40 | 43 | #include <linux/completion.h> |
055422dd | 44 | #include <linux/cdev.h> |
bc38a6ab | 45 | |
a4d61e84 | 46 | #include <rdma/ib_verbs.h> |
f7c6a7b5 | 47 | #include <rdma/ib_umem.h> |
a4d61e84 | 48 | #include <rdma/ib_user_verbs.h> |
dfb13955 | 49 | #include <rdma/uverbs_std_types.h> |
bc38a6ab | 50 | |
1f7ff9d5 MB |
51 | #define UVERBS_MODULE_NAME ib_uverbs |
52 | #include <rdma/uverbs_named_ioctl.h> | |
53 | ||
40a20339 AB |
54 | static inline void |
55 | ib_uverbs_init_udata(struct ib_udata *udata, | |
56 | const void __user *ibuf, | |
57 | void __user *obuf, | |
58 | size_t ilen, size_t olen) | |
59 | { | |
60 | udata->inbuf = ibuf; | |
61 | udata->outbuf = obuf; | |
62 | udata->inlen = ilen; | |
63 | udata->outlen = olen; | |
64 | } | |
f21519b2 | 65 | |
12f72772 AB |
66 | static inline void |
67 | ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata, | |
68 | const void __user *ibuf, | |
69 | void __user *obuf, | |
70 | size_t ilen, size_t olen) | |
71 | { | |
40a20339 AB |
72 | ib_uverbs_init_udata(udata, |
73 | ilen ? ibuf : NULL, olen ? obuf : NULL, | |
74 | ilen, olen); | |
12f72772 | 75 | } |
a96e4e2f | 76 | |
70a30e16 RD |
77 | /* |
78 | * Our lifetime rules for these structs are the following: | |
79 | * | |
80 | * struct ib_uverbs_device: One reference is held by the module and | |
81 | * released in ib_uverbs_remove_one(). Another reference is taken by | |
82 | * ib_uverbs_open() each time the character special file is opened, | |
83 | * and released in ib_uverbs_release_file() when the file is released. | |
84 | * | |
85 | * struct ib_uverbs_file: One reference is held by the VFS and | |
86 | * released when the file is closed. Another reference is taken when | |
87 | * an asynchronous event queue file is created and released when the | |
88 | * event file is closed. | |
89 | * | |
db1b5ddd MB |
90 | * struct ib_uverbs_event_queue: Base structure for |
91 | * struct ib_uverbs_async_event_file and struct ib_uverbs_completion_event_file. | |
92 | * One reference is held by the VFS and released when the file is closed. | |
93 | * For asynchronous event files, another reference is held by the corresponding | |
94 | * main context file and released when that file is closed. For completion | |
95 | * event files, a reference is taken when a CQ is created that uses the file, | |
96 | * and released when the CQ is destroyed. | |
70a30e16 RD |
97 | */ |
98 | ||
bc38a6ab | 99 | struct ib_uverbs_device { |
35d4a0b6 | 100 | atomic_t refcount; |
055422dd | 101 | int num_comp_vectors; |
fd60ae40 | 102 | struct completion comp; |
f4e91eb4 | 103 | struct device *dev; |
036b1063 | 104 | struct ib_device __rcu *ib_dev; |
055422dd AC |
105 | int devnum; |
106 | struct cdev cdev; | |
53d0bd1e SH |
107 | struct rb_root xrcd_tree; |
108 | struct mutex xrcd_tree_mutex; | |
35d4a0b6 | 109 | struct kobject kobj; |
036b1063 YH |
110 | struct srcu_struct disassociate_srcu; |
111 | struct mutex lists_mutex; /* protect lists */ | |
112 | struct list_head uverbs_file_list; | |
113 | struct list_head uverbs_events_file_list; | |
52427112 | 114 | struct uverbs_root_spec *specs_root; |
bc38a6ab RD |
115 | }; |
116 | ||
db1b5ddd | 117 | struct ib_uverbs_event_queue { |
bc38a6ab | 118 | spinlock_t lock; |
830a3871 | 119 | int is_closed; |
bc38a6ab | 120 | wait_queue_head_t poll_wait; |
abdf119b | 121 | struct fasync_struct *async_queue; |
bc38a6ab | 122 | struct list_head event_list; |
1e7710f3 MB |
123 | }; |
124 | ||
125 | struct ib_uverbs_async_event_file { | |
db1b5ddd | 126 | struct ib_uverbs_event_queue ev_queue; |
1e7710f3 MB |
127 | struct ib_uverbs_file *uverbs_file; |
128 | struct kref ref; | |
036b1063 | 129 | struct list_head list; |
bc38a6ab RD |
130 | }; |
131 | ||
1e7710f3 | 132 | struct ib_uverbs_completion_event_file { |
d0259e82 | 133 | struct ib_uobject uobj; |
db1b5ddd | 134 | struct ib_uverbs_event_queue ev_queue; |
1e7710f3 MB |
135 | }; |
136 | ||
bc38a6ab RD |
137 | struct ib_uverbs_file { |
138 | struct kref ref; | |
139 | struct ib_uverbs_device *device; | |
e951747a | 140 | struct mutex ucontext_lock; |
22fa27fb JG |
141 | /* |
142 | * ucontext must be accessed via ib_uverbs_get_ucontext() or with | |
143 | * ucontext_lock held | |
144 | */ | |
bc38a6ab RD |
145 | struct ib_ucontext *ucontext; |
146 | struct ib_event_handler event_handler; | |
1e7710f3 | 147 | struct ib_uverbs_async_event_file *async_file; |
036b1063 YH |
148 | struct list_head list; |
149 | int is_closed; | |
771addf6 | 150 | |
87064277 JG |
151 | /* |
152 | * To access the uobjects list hw_destroy_rwsem must be held for write | |
153 | * OR hw_destroy_rwsem held for read AND uobjects_lock held. | |
154 | * hw_destroy_rwsem should be called across any destruction of the HW | |
155 | * object of an associated uobject. | |
156 | */ | |
157 | struct rw_semaphore hw_destroy_rwsem; | |
158 | spinlock_t uobjects_lock; | |
6a5e9c88 JG |
159 | struct list_head uobjects; |
160 | ||
771addf6 MB |
161 | struct idr idr; |
162 | /* spinlock protects write access to idr */ | |
163 | spinlock_t idr_lock; | |
bc38a6ab RD |
164 | }; |
165 | ||
63aaf647 RD |
166 | struct ib_uverbs_event { |
167 | union { | |
168 | struct ib_uverbs_async_event_desc async; | |
169 | struct ib_uverbs_comp_event_desc comp; | |
170 | } desc; | |
bc38a6ab | 171 | struct list_head list; |
63aaf647 RD |
172 | struct list_head obj_list; |
173 | u32 *counter; | |
bc38a6ab RD |
174 | }; |
175 | ||
f4e40156 JM |
176 | struct ib_uverbs_mcast_entry { |
177 | struct list_head list; | |
178 | union ib_gid gid; | |
179 | u16 lid; | |
180 | }; | |
181 | ||
63aaf647 RD |
182 | struct ib_uevent_object { |
183 | struct ib_uobject uobject; | |
184 | struct list_head event_list; | |
185 | u32 events_reported; | |
bc38a6ab RD |
186 | }; |
187 | ||
53d0bd1e SH |
188 | struct ib_uxrcd_object { |
189 | struct ib_uobject uobject; | |
190 | atomic_t refcnt; | |
191 | }; | |
192 | ||
8541f8de SH |
193 | struct ib_usrq_object { |
194 | struct ib_uevent_object uevent; | |
195 | struct ib_uxrcd_object *uxrcd; | |
196 | }; | |
197 | ||
f4e40156 JM |
198 | struct ib_uqp_object { |
199 | struct ib_uevent_object uevent; | |
f48b7269 MB |
200 | /* lock for mcast list */ |
201 | struct mutex mcast_lock; | |
f4e40156 | 202 | struct list_head mcast_list; |
846be90d | 203 | struct ib_uxrcd_object *uxrcd; |
f4e40156 JM |
204 | }; |
205 | ||
f213c052 YH |
206 | struct ib_uwq_object { |
207 | struct ib_uevent_object uevent; | |
208 | }; | |
209 | ||
63aaf647 RD |
210 | struct ib_ucq_object { |
211 | struct ib_uobject uobject; | |
212 | struct list_head comp_list; | |
213 | struct list_head async_list; | |
214 | u32 comp_events_reported; | |
215 | u32 async_events_reported; | |
bc38a6ab RD |
216 | }; |
217 | ||
9b828441 MB |
218 | struct ib_uflow_resources; |
219 | struct ib_uflow_object { | |
220 | struct ib_uobject uobject; | |
221 | struct ib_uflow_resources *resources; | |
222 | }; | |
223 | ||
1e7710f3 | 224 | extern const struct file_operations uverbs_event_fops; |
db1b5ddd | 225 | void ib_uverbs_init_event_queue(struct ib_uverbs_event_queue *ev_queue); |
1e7710f3 MB |
226 | struct file *ib_uverbs_alloc_async_event_file(struct ib_uverbs_file *uverbs_file, |
227 | struct ib_device *ib_dev); | |
03c40442 | 228 | void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file); |
9b828441 | 229 | void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res); |
6b73597e | 230 | |
70a30e16 | 231 | void ib_uverbs_release_ucq(struct ib_uverbs_file *file, |
1e7710f3 | 232 | struct ib_uverbs_completion_event_file *ev_file, |
70a30e16 RD |
233 | struct ib_ucq_object *uobj); |
234 | void ib_uverbs_release_uevent(struct ib_uverbs_file *file, | |
235 | struct ib_uevent_object *uobj); | |
cf8966b3 | 236 | void ib_uverbs_release_file(struct kref *ref); |
70a30e16 | 237 | |
bc38a6ab RD |
238 | void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context); |
239 | void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr); | |
240 | void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr); | |
f213c052 | 241 | void ib_uverbs_wq_event_handler(struct ib_event *event, void *context_ptr); |
f520ba5a | 242 | void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr); |
6b73597e RD |
243 | void ib_uverbs_event_handler(struct ib_event_handler *handler, |
244 | struct ib_event *event); | |
1c77483e | 245 | int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd, |
6be60aed | 246 | enum rdma_remove_reason why); |
bc38a6ab | 247 | |
feb7c1e3 | 248 | int uverbs_dealloc_mw(struct ib_mw *mw); |
6be60aed MB |
249 | void ib_uverbs_detach_umcast(struct ib_qp *qp, |
250 | struct ib_uqp_object *uobj); | |
feb7c1e3 | 251 | |
41b2a71f | 252 | void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata); |
8eb19e8e MB |
253 | long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
254 | ||
2490f20b YD |
255 | struct ib_uverbs_flow_spec { |
256 | union { | |
257 | union { | |
258 | struct ib_uverbs_flow_spec_hdr hdr; | |
259 | struct { | |
260 | __u32 type; | |
261 | __u16 size; | |
262 | __u16 reserved; | |
263 | }; | |
264 | }; | |
265 | struct ib_uverbs_flow_spec_eth eth; | |
266 | struct ib_uverbs_flow_spec_ipv4 ipv4; | |
56ab0b38 | 267 | struct ib_uverbs_flow_spec_esp esp; |
2490f20b | 268 | struct ib_uverbs_flow_spec_tcp_udp tcp_udp; |
4c2aae71 | 269 | struct ib_uverbs_flow_spec_ipv6 ipv6; |
94e03f11 | 270 | struct ib_uverbs_flow_spec_action_tag flow_tag; |
483a3966 | 271 | struct ib_uverbs_flow_spec_action_drop drop; |
9b828441 | 272 | struct ib_uverbs_flow_spec_action_handle action; |
b6ba4a9a | 273 | struct ib_uverbs_flow_spec_action_count flow_count; |
2490f20b YD |
274 | }; |
275 | }; | |
276 | ||
766d8551 MB |
277 | int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type, |
278 | const void *kern_spec_mask, | |
279 | const void *kern_spec_val, | |
280 | size_t kern_filter_sz, | |
281 | union ib_flow_spec *ib_spec); | |
282 | ||
dfb13955 MB |
283 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DEVICE); |
284 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_PD); | |
285 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_MR); | |
286 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COMP_CHANNEL); | |
287 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_CQ); | |
288 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_QP); | |
289 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_AH); | |
290 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_MW); | |
291 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_SRQ); | |
292 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW); | |
293 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_WQ); | |
294 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_RWQ_IND_TBL); | |
295 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_XRCD); | |
2eb9beae | 296 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION); |
bee76d7a | 297 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DM); |
d9a5a644 | 298 | extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COUNTERS); |
dfb13955 | 299 | |
bc38a6ab RD |
300 | #define IB_UVERBS_DECLARE_CMD(name) \ |
301 | ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ | |
302 | const char __user *buf, int in_len, \ | |
303 | int out_len) | |
304 | ||
bc38a6ab RD |
305 | IB_UVERBS_DECLARE_CMD(get_context); |
306 | IB_UVERBS_DECLARE_CMD(query_device); | |
307 | IB_UVERBS_DECLARE_CMD(query_port); | |
bc38a6ab RD |
308 | IB_UVERBS_DECLARE_CMD(alloc_pd); |
309 | IB_UVERBS_DECLARE_CMD(dealloc_pd); | |
310 | IB_UVERBS_DECLARE_CMD(reg_mr); | |
7e6edb9b | 311 | IB_UVERBS_DECLARE_CMD(rereg_mr); |
bc38a6ab | 312 | IB_UVERBS_DECLARE_CMD(dereg_mr); |
6b52a12b SM |
313 | IB_UVERBS_DECLARE_CMD(alloc_mw); |
314 | IB_UVERBS_DECLARE_CMD(dealloc_mw); | |
6b73597e | 315 | IB_UVERBS_DECLARE_CMD(create_comp_channel); |
bc38a6ab | 316 | IB_UVERBS_DECLARE_CMD(create_cq); |
33b9b3ee | 317 | IB_UVERBS_DECLARE_CMD(resize_cq); |
67cdb40c RD |
318 | IB_UVERBS_DECLARE_CMD(poll_cq); |
319 | IB_UVERBS_DECLARE_CMD(req_notify_cq); | |
bc38a6ab RD |
320 | IB_UVERBS_DECLARE_CMD(destroy_cq); |
321 | IB_UVERBS_DECLARE_CMD(create_qp); | |
42849b26 | 322 | IB_UVERBS_DECLARE_CMD(open_qp); |
7ccc9a24 | 323 | IB_UVERBS_DECLARE_CMD(query_qp); |
bc38a6ab RD |
324 | IB_UVERBS_DECLARE_CMD(modify_qp); |
325 | IB_UVERBS_DECLARE_CMD(destroy_qp); | |
67cdb40c RD |
326 | IB_UVERBS_DECLARE_CMD(post_send); |
327 | IB_UVERBS_DECLARE_CMD(post_recv); | |
328 | IB_UVERBS_DECLARE_CMD(post_srq_recv); | |
329 | IB_UVERBS_DECLARE_CMD(create_ah); | |
330 | IB_UVERBS_DECLARE_CMD(destroy_ah); | |
bc38a6ab RD |
331 | IB_UVERBS_DECLARE_CMD(attach_mcast); |
332 | IB_UVERBS_DECLARE_CMD(detach_mcast); | |
f520ba5a RD |
333 | IB_UVERBS_DECLARE_CMD(create_srq); |
334 | IB_UVERBS_DECLARE_CMD(modify_srq); | |
8bdb0e86 | 335 | IB_UVERBS_DECLARE_CMD(query_srq); |
f520ba5a | 336 | IB_UVERBS_DECLARE_CMD(destroy_srq); |
8541f8de | 337 | IB_UVERBS_DECLARE_CMD(create_xsrq); |
53d0bd1e SH |
338 | IB_UVERBS_DECLARE_CMD(open_xrcd); |
339 | IB_UVERBS_DECLARE_CMD(close_xrcd); | |
f21519b2 | 340 | |
f21519b2 YD |
341 | #define IB_UVERBS_DECLARE_EX_CMD(name) \ |
342 | int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \ | |
343 | struct ib_udata *ucore, \ | |
344 | struct ib_udata *uhw) | |
345 | ||
346 | IB_UVERBS_DECLARE_EX_CMD(create_flow); | |
347 | IB_UVERBS_DECLARE_EX_CMD(destroy_flow); | |
02d1aa7a | 348 | IB_UVERBS_DECLARE_EX_CMD(query_device); |
565197dd | 349 | IB_UVERBS_DECLARE_EX_CMD(create_cq); |
6d8a7497 | 350 | IB_UVERBS_DECLARE_EX_CMD(create_qp); |
f213c052 YH |
351 | IB_UVERBS_DECLARE_EX_CMD(create_wq); |
352 | IB_UVERBS_DECLARE_EX_CMD(modify_wq); | |
353 | IB_UVERBS_DECLARE_EX_CMD(destroy_wq); | |
de019a94 YH |
354 | IB_UVERBS_DECLARE_EX_CMD(create_rwq_ind_table); |
355 | IB_UVERBS_DECLARE_EX_CMD(destroy_rwq_ind_table); | |
189aba99 | 356 | IB_UVERBS_DECLARE_EX_CMD(modify_qp); |
869ddcf8 | 357 | IB_UVERBS_DECLARE_EX_CMD(modify_cq); |
f21519b2 | 358 | |
bc38a6ab | 359 | #endif /* UVERBS_H */ |