uverbs.h revision 302408
1/*
2 * Copyright (c) 2005 Topspin Communications.  All rights reserved.
3 * Copyright (c) 2005, 2006 Cisco Systems.  All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
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.
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#include <linux/rbtree.h>
46
47#include <rdma/ib_verbs.h>
48#include <rdma/ib_verbs_exp.h>
49#include <rdma/ib_umem.h>
50#include <rdma/ib_user_verbs.h>
51#include <rdma/ib_user_verbs_exp.h>
52
53/*
54 * Our lifetime rules for these structs are the following:
55 *
56 * struct ib_uverbs_device: One reference is held by the module and
57 * released in ib_uverbs_remove_one().  Another reference is taken by
58 * ib_uverbs_open() each time the character special file is opened,
59 * and released in ib_uverbs_release_file() when the file is released.
60 *
61 * struct ib_uverbs_file: One reference is held by the VFS and
62 * released when the file is closed.  Another reference is taken when
63 * an asynchronous event queue file is created and released when the
64 * event file is closed.
65 *
66 * struct ib_uverbs_event_file: One reference is held by the VFS and
67 * released when the file is closed.  For asynchronous event files,
68 * another reference is held by the corresponding main context file
69 * and released when that file is closed.  For completion event files,
70 * a reference is taken when a CQ is created that uses the file, and
71 * released when the CQ is destroyed.
72 */
73
74struct ib_uverbs_device {
75	struct kref				ref;
76	int					num_comp_vectors;
77	struct completion			comp;
78	struct device			       *dev;
79	struct ib_device		       *ib_dev;
80	int					devnum;
81	struct cdev			        cdev;
82	struct rb_root				xrcd_tree;
83	struct mutex				xrcd_tree_mutex;
84};
85
86struct ib_uverbs_event_file {
87	struct kref				ref;
88	struct file			       *filp;
89	int					is_async;
90	struct ib_uverbs_file		       *uverbs_file;
91	spinlock_t				lock;
92	int					is_closed;
93	wait_queue_head_t			poll_wait;
94	struct fasync_struct		       *async_queue;
95	struct list_head			event_list;
96};
97
98struct ib_uverbs_file {
99	struct kref				ref;
100	struct mutex				mutex;
101	struct ib_uverbs_device		       *device;
102	struct ib_ucontext		       *ucontext;
103	struct ib_event_handler			event_handler;
104	struct ib_uverbs_event_file	       *async_file;
105};
106
107struct ib_uverbs_event {
108	union {
109		struct ib_uverbs_async_event_desc	async;
110		struct ib_uverbs_comp_event_desc	comp;
111	}					desc;
112	struct list_head			list;
113	struct list_head			obj_list;
114	u32				       *counter;
115};
116
117struct ib_uverbs_mcast_entry {
118	struct list_head	list;
119	union ib_gid 		gid;
120	u16 			lid;
121};
122
123struct ib_uevent_object {
124	struct ib_uobject	uobject;
125	struct list_head	event_list;
126	u32			events_reported;
127};
128
129struct ib_uxrcd_object {
130	struct ib_uobject	uobject;
131	atomic_t		refcnt;
132};
133
134struct ib_usrq_object {
135	struct ib_uevent_object	uevent;
136	struct ib_uxrcd_object *uxrcd;
137};
138
139struct ib_uqp_object {
140	struct ib_uevent_object	uevent;
141	struct list_head 	mcast_list;
142	struct ib_uxrcd_object *uxrcd;
143};
144
145struct ib_ucq_object {
146	struct ib_uobject	uobject;
147	struct ib_uverbs_file  *uverbs_file;
148	struct list_head	comp_list;
149	struct list_head	async_list;
150	u32			comp_events_reported;
151	u32			async_events_reported;
152};
153
154struct ib_udct_object {
155	struct ib_uobject	uobject;
156};
157
158extern spinlock_t ib_uverbs_idr_lock;
159extern struct idr ib_uverbs_pd_idr;
160extern struct idr ib_uverbs_mr_idr;
161extern struct idr ib_uverbs_mw_idr;
162extern struct idr ib_uverbs_ah_idr;
163extern struct idr ib_uverbs_cq_idr;
164extern struct idr ib_uverbs_qp_idr;
165extern struct idr ib_uverbs_srq_idr;
166extern struct idr ib_uverbs_xrcd_idr;
167extern struct idr ib_uverbs_rule_idr;
168extern struct idr ib_uverbs_dct_idr;
169
170void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);
171
172struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
173					int is_async);
174struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd);
175
176void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
177			   struct ib_uverbs_event_file *ev_file,
178			   struct ib_ucq_object *uobj);
179void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
180			      struct ib_uevent_object *uobj);
181
182void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
183void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
184void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
185void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
186void ib_uverbs_event_handler(struct ib_event_handler *handler,
187			     struct ib_event *event);
188void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd);
189
190struct ib_uverbs_flow_spec {
191	union {
192		union {
193			struct ib_uverbs_flow_spec_hdr hdr;
194			struct {
195				__u32 type;
196				__u16 size;
197				__u16 reserved;
198			};
199		};
200		struct ib_uverbs_flow_spec_eth     eth;
201		struct ib_uverbs_flow_spec_ib      ib;
202		struct ib_uverbs_flow_spec_ipv4    ipv4;
203		struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
204	};
205};
206
207#define IB_UVERBS_DECLARE_CMD(name)					\
208	ssize_t ib_uverbs_##name(struct ib_uverbs_file *file,		\
209				 const char __user *buf, int in_len,	\
210				 int out_len)
211
212IB_UVERBS_DECLARE_CMD(get_context);
213IB_UVERBS_DECLARE_CMD(query_device);
214IB_UVERBS_DECLARE_CMD(query_port);
215IB_UVERBS_DECLARE_CMD(alloc_pd);
216IB_UVERBS_DECLARE_CMD(dealloc_pd);
217IB_UVERBS_DECLARE_CMD(reg_mr);
218IB_UVERBS_DECLARE_CMD(dereg_mr);
219IB_UVERBS_DECLARE_CMD(alloc_mw);
220IB_UVERBS_DECLARE_CMD(dealloc_mw);
221IB_UVERBS_DECLARE_CMD(create_comp_channel);
222IB_UVERBS_DECLARE_CMD(create_cq);
223IB_UVERBS_DECLARE_CMD(resize_cq);
224IB_UVERBS_DECLARE_CMD(poll_cq);
225IB_UVERBS_DECLARE_CMD(req_notify_cq);
226IB_UVERBS_DECLARE_CMD(destroy_cq);
227IB_UVERBS_DECLARE_CMD(create_qp);
228IB_UVERBS_DECLARE_CMD(open_qp);
229IB_UVERBS_DECLARE_CMD(query_qp);
230IB_UVERBS_DECLARE_CMD(modify_qp);
231IB_UVERBS_DECLARE_CMD(destroy_qp);
232IB_UVERBS_DECLARE_CMD(post_send);
233IB_UVERBS_DECLARE_CMD(post_recv);
234IB_UVERBS_DECLARE_CMD(post_srq_recv);
235IB_UVERBS_DECLARE_CMD(create_ah);
236IB_UVERBS_DECLARE_CMD(destroy_ah);
237IB_UVERBS_DECLARE_CMD(attach_mcast);
238IB_UVERBS_DECLARE_CMD(detach_mcast);
239IB_UVERBS_DECLARE_CMD(create_srq);
240IB_UVERBS_DECLARE_CMD(modify_srq);
241IB_UVERBS_DECLARE_CMD(query_srq);
242IB_UVERBS_DECLARE_CMD(destroy_srq);
243IB_UVERBS_DECLARE_CMD(create_xsrq);
244IB_UVERBS_DECLARE_CMD(open_xrcd);
245IB_UVERBS_DECLARE_CMD(close_xrcd);
246
247#define IB_UVERBS_DECLARE_EX_CMD(name)				\
248	int ib_uverbs_ex_##name(struct ib_uverbs_file *file,\
249				struct ib_udata *ucore,	\
250				struct ib_udata *uhw)
251
252#define IB_UVERBS_DECLARE_EXP_CMD(name)					\
253	ssize_t ib_uverbs_exp_##name(struct ib_uverbs_file *file,	\
254				     struct ib_udata *ucore,		\
255				     struct ib_udata *uhw)
256
257IB_UVERBS_DECLARE_EX_CMD(create_flow);
258IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
259
260IB_UVERBS_DECLARE_EXP_CMD(create_qp);
261IB_UVERBS_DECLARE_EXP_CMD(modify_cq);
262IB_UVERBS_DECLARE_EXP_CMD(modify_qp);
263IB_UVERBS_DECLARE_EXP_CMD(create_cq);
264IB_UVERBS_DECLARE_EXP_CMD(query_device);
265IB_UVERBS_DECLARE_EXP_CMD(create_dct);
266IB_UVERBS_DECLARE_EXP_CMD(destroy_dct);
267IB_UVERBS_DECLARE_EXP_CMD(query_dct);
268
269#endif /* UVERBS_H */
270