uverbs.h 6.6 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 42 43
 *
 * 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.
 *
 * $Id: uverbs.h 2559 2005-06-06 19:43:16Z roland $
 */

#ifndef UVERBS_H
#define UVERBS_H

#include <linux/kref.h>
#include <linux/idr.h>
44
#include <linux/mutex.h>
45
#include <linux/completion.h>
46

47
#include <rdma/ib_verbs.h>
48
#include <rdma/ib_umem.h>
49
#include <rdma/ib_user_verbs.h>
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/*
 * 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.
 */

72
struct ib_uverbs_device {
73
	struct kref				ref;
74
	struct completion			comp;
75
	int					devnum;
76 77
	struct cdev			       *dev;
	struct class_device		       *class_dev;
78
	struct ib_device		       *ib_dev;
79
	int					num_comp_vectors;
80 81 82 83
};

struct ib_uverbs_event_file {
	struct kref				ref;
84
	struct file			       *file;
85 86 87 88
	struct ib_uverbs_file		       *uverbs_file;
	spinlock_t				lock;
	int					is_async;
	wait_queue_head_t			poll_wait;
G
Gleb Natapov 已提交
89
	struct fasync_struct		       *async_queue;
90 91 92 93 94
	struct list_head			event_list;
};

struct ib_uverbs_file {
	struct kref				ref;
95
	struct mutex				mutex;
96 97 98
	struct ib_uverbs_device		       *device;
	struct ib_ucontext		       *ucontext;
	struct ib_event_handler			event_handler;
99
	struct ib_uverbs_event_file	       *async_file;
100 101
};

102 103 104 105 106
struct ib_uverbs_event {
	union {
		struct ib_uverbs_async_event_desc	async;
		struct ib_uverbs_comp_event_desc	comp;
	}					desc;
107
	struct list_head			list;
108 109
	struct list_head			obj_list;
	u32				       *counter;
110 111
};

112 113 114 115 116 117
struct ib_uverbs_mcast_entry {
	struct list_head	list;
	union ib_gid 		gid;
	u16 			lid;
};

118 119 120 121
struct ib_uevent_object {
	struct ib_uobject	uobject;
	struct list_head	event_list;
	u32			events_reported;
122 123
};

124 125 126 127 128
struct ib_uqp_object {
	struct ib_uevent_object	uevent;
	struct list_head 	mcast_list;
};

129 130
struct ib_ucq_object {
	struct ib_uobject	uobject;
131
	struct ib_uverbs_file  *uverbs_file;
132 133 134 135
	struct list_head	comp_list;
	struct list_head	async_list;
	u32			comp_events_reported;
	u32			async_events_reported;
136 137
};

138
extern spinlock_t ib_uverbs_idr_lock;
139 140 141 142 143 144
extern struct idr ib_uverbs_pd_idr;
extern struct idr ib_uverbs_mr_idr;
extern struct idr ib_uverbs_mw_idr;
extern struct idr ib_uverbs_ah_idr;
extern struct idr ib_uverbs_cq_idr;
extern struct idr ib_uverbs_qp_idr;
145
extern struct idr ib_uverbs_srq_idr;
146

147 148
void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);

149 150 151 152
struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
					int is_async, int *fd);
struct ib_uverbs_event_file *ib_uverbs_lookup_comp_file(int fd);

153 154 155 156 157 158
void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
			   struct ib_uverbs_event_file *ev_file,
			   struct ib_ucq_object *uobj);
void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
			      struct ib_uevent_object *uobj);

159 160 161
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);
162
void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
163 164
void ib_uverbs_event_handler(struct ib_event_handler *handler,
			     struct ib_event *event);
165 166 167 168 169 170 171 172 173 174 175 176 177

#define IB_UVERBS_DECLARE_CMD(name)					\
	ssize_t ib_uverbs_##name(struct ib_uverbs_file *file,		\
				 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);
IB_UVERBS_DECLARE_CMD(dereg_mr);
178
IB_UVERBS_DECLARE_CMD(create_comp_channel);
179
IB_UVERBS_DECLARE_CMD(create_cq);
180
IB_UVERBS_DECLARE_CMD(resize_cq);
181 182
IB_UVERBS_DECLARE_CMD(poll_cq);
IB_UVERBS_DECLARE_CMD(req_notify_cq);
183 184
IB_UVERBS_DECLARE_CMD(destroy_cq);
IB_UVERBS_DECLARE_CMD(create_qp);
185
IB_UVERBS_DECLARE_CMD(query_qp);
186 187
IB_UVERBS_DECLARE_CMD(modify_qp);
IB_UVERBS_DECLARE_CMD(destroy_qp);
188 189 190 191 192
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);
193 194
IB_UVERBS_DECLARE_CMD(attach_mcast);
IB_UVERBS_DECLARE_CMD(detach_mcast);
195 196
IB_UVERBS_DECLARE_CMD(create_srq);
IB_UVERBS_DECLARE_CMD(modify_srq);
197
IB_UVERBS_DECLARE_CMD(query_srq);
198
IB_UVERBS_DECLARE_CMD(destroy_srq);
199 200

#endif /* UVERBS_H */