uverbs.h 9.5 KB
Newer Older
1 2
/*
 * Copyright (c) 2005 Topspin Communications.  All rights reserved.
3
 * Copyright (c) 2005, 2006 Cisco Systems.  All rights reserved.
4 5
 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
 * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
6
 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
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 38 39 40 41
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef UVERBS_H
#define UVERBS_H

#include <linux/kref.h>
#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

50 51
#define INIT_UDATA(udata, ibuf, obuf, ilen, olen)			\
	do {								\
52
		(udata)->inbuf  = (const void __user *) (ibuf);		\
53 54 55 56 57
		(udata)->outbuf = (void __user *) (obuf);		\
		(udata)->inlen  = (ilen);				\
		(udata)->outlen = (olen);				\
	} while (0)

58 59 60 61 62 63 64 65
#define INIT_UDATA_BUF_OR_NULL(udata, ibuf, obuf, ilen, olen)			\
	do {									\
		(udata)->inbuf  = (ilen) ? (const void __user *) (ibuf) : NULL;	\
		(udata)->outbuf = (olen) ? (void __user *) (obuf) : NULL;	\
		(udata)->inlen  = (ilen);					\
		(udata)->outlen = (olen);					\
	} while (0)

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*
 * Our lifetime rules for these structs are the following:
 *
 * struct ib_uverbs_device: One reference is held by the module and
 * released in ib_uverbs_remove_one().  Another reference is taken by
 * ib_uverbs_open() each time the character special file is opened,
 * and released in ib_uverbs_release_file() when the file is released.
 *
 * struct ib_uverbs_file: One reference is held by the VFS and
 * released when the file is closed.  Another reference is taken when
 * an asynchronous event queue file is created and released when the
 * event file is closed.
 *
 * struct ib_uverbs_event_file: One reference is held by the VFS and
 * released when the file is closed.  For asynchronous event files,
 * another reference is held by the corresponding main context file
 * and released when that file is closed.  For completion event files,
 * a reference is taken when a CQ is created that uses the file, and
 * released when the CQ is destroyed.
 */

87
struct ib_uverbs_device {
88
	atomic_t				refcount;
89
	int					num_comp_vectors;
90
	struct completion			comp;
91
	struct device			       *dev;
92
	struct ib_device	__rcu	       *ib_dev;
93 94
	int					devnum;
	struct cdev			        cdev;
95 96
	struct rb_root				xrcd_tree;
	struct mutex				xrcd_tree_mutex;
97
	struct kobject				kobj;
98 99 100 101
	struct srcu_struct			disassociate_srcu;
	struct mutex				lists_mutex; /* protect lists */
	struct list_head			uverbs_file_list;
	struct list_head			uverbs_events_file_list;
102 103 104 105
};

struct ib_uverbs_event_file {
	spinlock_t				lock;
106
	int					is_closed;
107
	wait_queue_head_t			poll_wait;
G
Gleb Natapov 已提交
108
	struct fasync_struct		       *async_queue;
109
	struct list_head			event_list;
110 111 112 113 114 115
};

struct ib_uverbs_async_event_file {
	struct ib_uverbs_event_file		ev_file;
	struct ib_uverbs_file		       *uverbs_file;
	struct kref				ref;
116
	struct list_head			list;
117 118
};

119 120 121 122 123
struct ib_uverbs_completion_event_file {
	struct ib_uobject_file			uobj_file;
	struct ib_uverbs_event_file		ev_file;
};

124 125
struct ib_uverbs_file {
	struct kref				ref;
126
	struct mutex				mutex;
127
	struct mutex                            cleanup_mutex; /* protect cleanup */
128 129 130
	struct ib_uverbs_device		       *device;
	struct ib_ucontext		       *ucontext;
	struct ib_event_handler			event_handler;
131
	struct ib_uverbs_async_event_file       *async_file;
132 133
	struct list_head			list;
	int					is_closed;
134 135 136 137

	struct idr		idr;
	/* spinlock protects write access to idr */
	spinlock_t		idr_lock;
138 139
};

140 141 142 143 144
struct ib_uverbs_event {
	union {
		struct ib_uverbs_async_event_desc	async;
		struct ib_uverbs_comp_event_desc	comp;
	}					desc;
145
	struct list_head			list;
146 147
	struct list_head			obj_list;
	u32				       *counter;
148 149
};

150 151 152 153 154 155
struct ib_uverbs_mcast_entry {
	struct list_head	list;
	union ib_gid 		gid;
	u16 			lid;
};

156 157 158 159
struct ib_uevent_object {
	struct ib_uobject	uobject;
	struct list_head	event_list;
	u32			events_reported;
160 161
};

162 163 164 165 166
struct ib_uxrcd_object {
	struct ib_uobject	uobject;
	atomic_t		refcnt;
};

167 168 169 170 171
struct ib_usrq_object {
	struct ib_uevent_object	uevent;
	struct ib_uxrcd_object *uxrcd;
};

172 173
struct ib_uqp_object {
	struct ib_uevent_object	uevent;
174 175
	/* lock for mcast list */
	struct mutex		mcast_lock;
176
	struct list_head 	mcast_list;
177
	struct ib_uxrcd_object *uxrcd;
178 179
};

Y
Yishai Hadas 已提交
180 181 182 183
struct ib_uwq_object {
	struct ib_uevent_object	uevent;
};

184 185
struct ib_ucq_object {
	struct ib_uobject	uobject;
186
	struct ib_uverbs_file  *uverbs_file;
187 188 189 190
	struct list_head	comp_list;
	struct list_head	async_list;
	u32			comp_events_reported;
	u32			async_events_reported;
191 192
};

193 194 195 196
extern const struct file_operations uverbs_event_fops;
void ib_uverbs_init_event_file(struct ib_uverbs_event_file *ev_file);
struct file *ib_uverbs_alloc_async_event_file(struct ib_uverbs_file *uverbs_file,
					      struct ib_device *ib_dev);
197
void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file);
198

199
void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
200
			   struct ib_uverbs_completion_event_file *ev_file,
201 202 203
			   struct ib_ucq_object *uobj);
void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
			      struct ib_uevent_object *uobj);
204
void ib_uverbs_release_file(struct kref *ref);
205

206 207 208
void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
Y
Yishai Hadas 已提交
209
void ib_uverbs_wq_event_handler(struct ib_event *event, void *context_ptr);
210
void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
211 212
void ib_uverbs_event_handler(struct ib_event_handler *handler,
			     struct ib_event *event);
213 214
int ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd,
			   enum rdma_remove_reason why);
215

216
int uverbs_dealloc_mw(struct ib_mw *mw);
217 218
void ib_uverbs_detach_umcast(struct ib_qp *qp,
			     struct ib_uqp_object *uobj);
219

220 221 222 223 224 225 226 227 228 229 230 231 232
struct ib_uverbs_flow_spec {
	union {
		union {
			struct ib_uverbs_flow_spec_hdr hdr;
			struct {
				__u32 type;
				__u16 size;
				__u16 reserved;
			};
		};
		struct ib_uverbs_flow_spec_eth     eth;
		struct ib_uverbs_flow_spec_ipv4    ipv4;
		struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
233
		struct ib_uverbs_flow_spec_ipv6    ipv6;
234
		struct ib_uverbs_flow_spec_action_tag	flow_tag;
235 236 237
	};
};

238 239
#define IB_UVERBS_DECLARE_CMD(name)					\
	ssize_t ib_uverbs_##name(struct ib_uverbs_file *file,		\
240
				 struct ib_device *ib_dev,              \
241 242 243 244 245 246 247 248 249
				 const char __user *buf, int in_len,	\
				 int out_len)

IB_UVERBS_DECLARE_CMD(get_context);
IB_UVERBS_DECLARE_CMD(query_device);
IB_UVERBS_DECLARE_CMD(query_port);
IB_UVERBS_DECLARE_CMD(alloc_pd);
IB_UVERBS_DECLARE_CMD(dealloc_pd);
IB_UVERBS_DECLARE_CMD(reg_mr);
250
IB_UVERBS_DECLARE_CMD(rereg_mr);
251
IB_UVERBS_DECLARE_CMD(dereg_mr);
252 253
IB_UVERBS_DECLARE_CMD(alloc_mw);
IB_UVERBS_DECLARE_CMD(dealloc_mw);
254
IB_UVERBS_DECLARE_CMD(create_comp_channel);
255
IB_UVERBS_DECLARE_CMD(create_cq);
256
IB_UVERBS_DECLARE_CMD(resize_cq);
257 258
IB_UVERBS_DECLARE_CMD(poll_cq);
IB_UVERBS_DECLARE_CMD(req_notify_cq);
259 260
IB_UVERBS_DECLARE_CMD(destroy_cq);
IB_UVERBS_DECLARE_CMD(create_qp);
261
IB_UVERBS_DECLARE_CMD(open_qp);
262
IB_UVERBS_DECLARE_CMD(query_qp);
263 264
IB_UVERBS_DECLARE_CMD(modify_qp);
IB_UVERBS_DECLARE_CMD(destroy_qp);
265 266 267 268 269
IB_UVERBS_DECLARE_CMD(post_send);
IB_UVERBS_DECLARE_CMD(post_recv);
IB_UVERBS_DECLARE_CMD(post_srq_recv);
IB_UVERBS_DECLARE_CMD(create_ah);
IB_UVERBS_DECLARE_CMD(destroy_ah);
270 271
IB_UVERBS_DECLARE_CMD(attach_mcast);
IB_UVERBS_DECLARE_CMD(detach_mcast);
272 273
IB_UVERBS_DECLARE_CMD(create_srq);
IB_UVERBS_DECLARE_CMD(modify_srq);
274
IB_UVERBS_DECLARE_CMD(query_srq);
275
IB_UVERBS_DECLARE_CMD(destroy_srq);
276
IB_UVERBS_DECLARE_CMD(create_xsrq);
277 278
IB_UVERBS_DECLARE_CMD(open_xrcd);
IB_UVERBS_DECLARE_CMD(close_xrcd);
279 280 281

#define IB_UVERBS_DECLARE_EX_CMD(name)				\
	int ib_uverbs_ex_##name(struct ib_uverbs_file *file,	\
282
				struct ib_device *ib_dev,		\
283 284 285 286 287
				struct ib_udata *ucore,		\
				struct ib_udata *uhw)

IB_UVERBS_DECLARE_EX_CMD(create_flow);
IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
288
IB_UVERBS_DECLARE_EX_CMD(query_device);
289
IB_UVERBS_DECLARE_EX_CMD(create_cq);
290
IB_UVERBS_DECLARE_EX_CMD(create_qp);
Y
Yishai Hadas 已提交
291 292 293
IB_UVERBS_DECLARE_EX_CMD(create_wq);
IB_UVERBS_DECLARE_EX_CMD(modify_wq);
IB_UVERBS_DECLARE_EX_CMD(destroy_wq);
294 295
IB_UVERBS_DECLARE_EX_CMD(create_rwq_ind_table);
IB_UVERBS_DECLARE_EX_CMD(destroy_rwq_ind_table);
296
IB_UVERBS_DECLARE_EX_CMD(modify_qp);
297

298
#endif /* UVERBS_H */