1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37#ifndef UVERBS_H
38#define UVERBS_H
39
40#include <linux/kref.h>
41#include <linux/idr.h>
42#include <linux/mutex.h>
43#include <linux/completion.h>
44#include <linux/cdev.h>
45
46#include <rdma/ib_verbs.h>
47#include <rdma/ib_umem.h>
48#include <rdma/ib_user_verbs.h>
49#include <rdma/uverbs_std_types.h>
50
51#define UVERBS_MODULE_NAME ib_uverbs
52#include <rdma/uverbs_named_ioctl.h>
53
54static inline void
55ib_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}
65
66static inline void
67ib_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{
72 ib_uverbs_init_udata(udata,
73 ilen ? ibuf : NULL, olen ? obuf : NULL,
74 ilen, olen);
75}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99struct ib_uverbs_device {
100 atomic_t refcount;
101 u32 num_comp_vectors;
102 struct completion comp;
103 struct device dev;
104
105 const struct attribute_group *groups[2];
106 struct ib_device __rcu *ib_dev;
107 int devnum;
108 struct cdev cdev;
109 struct rb_root xrcd_tree;
110 struct mutex xrcd_tree_mutex;
111 struct srcu_struct disassociate_srcu;
112 struct mutex lists_mutex;
113 struct list_head uverbs_file_list;
114 struct uverbs_api *uapi;
115};
116
117struct ib_uverbs_event_queue {
118 spinlock_t lock;
119 int is_closed;
120 wait_queue_head_t poll_wait;
121 struct fasync_struct *async_queue;
122 struct list_head event_list;
123};
124
125struct ib_uverbs_async_event_file {
126 struct ib_uobject uobj;
127 struct ib_uverbs_event_queue ev_queue;
128 struct ib_event_handler event_handler;
129};
130
131struct ib_uverbs_completion_event_file {
132 struct ib_uobject uobj;
133 struct ib_uverbs_event_queue ev_queue;
134};
135
136struct ib_uverbs_file {
137 struct kref ref;
138 struct ib_uverbs_device *device;
139 struct mutex ucontext_lock;
140
141
142
143
144 struct ib_ucontext *ucontext;
145 struct ib_uverbs_async_event_file *async_file;
146 struct list_head list;
147
148
149
150
151
152
153
154 struct rw_semaphore hw_destroy_rwsem;
155 spinlock_t uobjects_lock;
156 struct list_head uobjects;
157
158 struct mutex umap_lock;
159 struct list_head umaps;
160 struct page *disassociate_page;
161
162 struct xarray idr;
163};
164
165struct ib_uverbs_event {
166 union {
167 struct ib_uverbs_async_event_desc async;
168 struct ib_uverbs_comp_event_desc comp;
169 } desc;
170 struct list_head list;
171 struct list_head obj_list;
172 u32 *counter;
173};
174
175struct ib_uverbs_mcast_entry {
176 struct list_head list;
177 union ib_gid gid;
178 u16 lid;
179};
180
181struct ib_uevent_object {
182 struct ib_uobject uobject;
183
184 struct list_head event_list;
185 u32 events_reported;
186};
187
188struct ib_uxrcd_object {
189 struct ib_uobject uobject;
190 atomic_t refcnt;
191};
192
193struct ib_usrq_object {
194 struct ib_uevent_object uevent;
195 struct ib_uxrcd_object *uxrcd;
196};
197
198struct ib_uqp_object {
199 struct ib_uevent_object uevent;
200
201 struct mutex mcast_lock;
202 struct list_head mcast_list;
203 struct ib_uxrcd_object *uxrcd;
204};
205
206struct ib_uwq_object {
207 struct ib_uevent_object uevent;
208};
209
210struct ib_ucq_object {
211 struct ib_uevent_object uevent;
212 struct list_head comp_list;
213 u32 comp_events_reported;
214};
215
216extern const struct file_operations uverbs_event_fops;
217extern const struct file_operations uverbs_async_event_fops;
218void ib_uverbs_init_event_queue(struct ib_uverbs_event_queue *ev_queue);
219void ib_uverbs_init_async_event_file(struct ib_uverbs_async_event_file *ev_file);
220void ib_uverbs_free_event_queue(struct ib_uverbs_event_queue *event_queue);
221void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res);
222
223int ib_alloc_ucontext(struct uverbs_attr_bundle *attrs);
224int ib_init_ucontext(struct uverbs_attr_bundle *attrs);
225
226void ib_uverbs_release_ucq(struct ib_uverbs_completion_event_file *ev_file,
227 struct ib_ucq_object *uobj);
228void ib_uverbs_release_uevent(struct ib_uevent_object *uobj);
229void ib_uverbs_release_file(struct kref *ref);
230
231void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
232void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
233void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
234void ib_uverbs_wq_event_handler(struct ib_event *event, void *context_ptr);
235void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
236int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
237 enum rdma_remove_reason why,
238 struct uverbs_attr_bundle *attrs);
239
240int uverbs_dealloc_mw(struct ib_mw *mw);
241void ib_uverbs_detach_umcast(struct ib_qp *qp,
242 struct ib_uqp_object *uobj);
243
244long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
245
246struct ib_uverbs_flow_spec {
247 union {
248 union {
249 struct ib_uverbs_flow_spec_hdr hdr;
250 struct {
251 __u32 type;
252 __u16 size;
253 __u16 reserved;
254 };
255 };
256 struct ib_uverbs_flow_spec_eth eth;
257 struct ib_uverbs_flow_spec_ipv4 ipv4;
258 struct ib_uverbs_flow_spec_esp esp;
259 struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
260 struct ib_uverbs_flow_spec_ipv6 ipv6;
261 struct ib_uverbs_flow_spec_action_tag flow_tag;
262 struct ib_uverbs_flow_spec_action_drop drop;
263 struct ib_uverbs_flow_spec_action_handle action;
264 struct ib_uverbs_flow_spec_action_count flow_count;
265 };
266};
267
268int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
269 const void *kern_spec_mask,
270 const void *kern_spec_val,
271 size_t kern_filter_sz,
272 union ib_flow_spec *ib_spec);
273
274
275
276
277
278static inline u32 make_port_cap_flags(const struct ib_port_attr *attr)
279{
280 u32 res;
281
282
283
284
285
286
287 res = attr->port_cap_flags & ~(u32)IB_UVERBS_PCF_IP_BASED_GIDS;
288
289 if (attr->ip_gids)
290 res |= IB_UVERBS_PCF_IP_BASED_GIDS;
291
292 return res;
293}
294
295
296void copy_port_attr_to_resp(struct ib_port_attr *attr,
297 struct ib_uverbs_query_port_resp *resp,
298 struct ib_device *ib_dev, u8 port_num);
299#endif
300