uverbs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. #ifndef UVERBS_H
  37. #define UVERBS_H
  38. #include <linux/kref.h>
  39. #include <linux/idr.h>
  40. #include <linux/mutex.h>
  41. #include <linux/completion.h>
  42. #include <linux/cdev.h>
  43. #include <rdma/ib_verbs.h>
  44. #include <rdma/ib_umem.h>
  45. #include <rdma/ib_user_verbs.h>
  46. #include <rdma/uverbs_std_types.h>
  47. #define UVERBS_MODULE_NAME ib_uverbs
  48. #include <rdma/uverbs_named_ioctl.h>
  49. static inline void
  50. ib_uverbs_init_udata(struct ib_udata *udata,
  51. const void __user *ibuf,
  52. void __user *obuf,
  53. size_t ilen, size_t olen)
  54. {
  55. udata->inbuf = ibuf;
  56. udata->outbuf = obuf;
  57. udata->inlen = ilen;
  58. udata->outlen = olen;
  59. }
  60. static inline void
  61. ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata,
  62. const void __user *ibuf,
  63. void __user *obuf,
  64. size_t ilen, size_t olen)
  65. {
  66. ib_uverbs_init_udata(udata,
  67. ilen ? ibuf : NULL, olen ? obuf : NULL,
  68. ilen, olen);
  69. }
  70. /*
  71. * Our lifetime rules for these structs are the following:
  72. *
  73. * struct ib_uverbs_device: One reference is held by the module and
  74. * released in ib_uverbs_remove_one(). Another reference is taken by
  75. * ib_uverbs_open() each time the character special file is opened,
  76. * and released in ib_uverbs_release_file() when the file is released.
  77. *
  78. * struct ib_uverbs_file: One reference is held by the VFS and
  79. * released when the file is closed. Another reference is taken when
  80. * an asynchronous event queue file is created and released when the
  81. * event file is closed.
  82. *
  83. * struct ib_uverbs_event_queue: Base structure for
  84. * struct ib_uverbs_async_event_file and struct ib_uverbs_completion_event_file.
  85. * One reference is held by the VFS and released when the file is closed.
  86. * For asynchronous event files, another reference is held by the corresponding
  87. * main context file and released when that file is closed. For completion
  88. * event files, a reference is taken when a CQ is created that uses the file,
  89. * and released when the CQ is destroyed.
  90. */
  91. struct ib_uverbs_device {
  92. atomic_t refcount;
  93. int num_comp_vectors;
  94. struct completion comp;
  95. struct device *dev;
  96. struct ib_device __rcu *ib_dev;
  97. int devnum;
  98. struct cdev cdev;
  99. struct rb_root xrcd_tree;
  100. struct mutex xrcd_tree_mutex;
  101. struct kobject kobj;
  102. struct srcu_struct disassociate_srcu;
  103. struct mutex lists_mutex; /* protect lists */
  104. struct list_head uverbs_file_list;
  105. struct list_head uverbs_events_file_list;
  106. struct uverbs_root_spec *specs_root;
  107. };
  108. struct ib_uverbs_event_queue {
  109. spinlock_t lock;
  110. int is_closed;
  111. wait_queue_head_t poll_wait;
  112. struct fasync_struct *async_queue;
  113. struct list_head event_list;
  114. };
  115. struct ib_uverbs_async_event_file {
  116. struct ib_uverbs_event_queue ev_queue;
  117. struct ib_uverbs_file *uverbs_file;
  118. struct kref ref;
  119. struct list_head list;
  120. };
  121. struct ib_uverbs_completion_event_file {
  122. struct ib_uobject_file uobj_file;
  123. struct ib_uverbs_event_queue ev_queue;
  124. };
  125. struct ib_uverbs_file {
  126. struct kref ref;
  127. struct mutex mutex;
  128. struct mutex cleanup_mutex; /* protect cleanup */
  129. struct ib_uverbs_device *device;
  130. struct ib_ucontext *ucontext;
  131. struct ib_event_handler event_handler;
  132. struct ib_uverbs_async_event_file *async_file;
  133. struct list_head list;
  134. int is_closed;
  135. struct idr idr;
  136. /* spinlock protects write access to idr */
  137. spinlock_t idr_lock;
  138. };
  139. struct ib_uverbs_event {
  140. union {
  141. struct ib_uverbs_async_event_desc async;
  142. struct ib_uverbs_comp_event_desc comp;
  143. } desc;
  144. struct list_head list;
  145. struct list_head obj_list;
  146. u32 *counter;
  147. };
  148. struct ib_uverbs_mcast_entry {
  149. struct list_head list;
  150. union ib_gid gid;
  151. u16 lid;
  152. };
  153. struct ib_uevent_object {
  154. struct ib_uobject uobject;
  155. struct list_head event_list;
  156. u32 events_reported;
  157. };
  158. struct ib_uxrcd_object {
  159. struct ib_uobject uobject;
  160. atomic_t refcnt;
  161. };
  162. struct ib_usrq_object {
  163. struct ib_uevent_object uevent;
  164. struct ib_uxrcd_object *uxrcd;
  165. };
  166. struct ib_uqp_object {
  167. struct ib_uevent_object uevent;
  168. /* lock for mcast list */
  169. struct mutex mcast_lock;
  170. struct list_head mcast_list;
  171. struct ib_uxrcd_object *uxrcd;
  172. };
  173. struct ib_uwq_object {
  174. struct ib_uevent_object uevent;
  175. };
  176. struct ib_ucq_object {
  177. struct ib_uobject uobject;
  178. struct ib_uverbs_file *uverbs_file;
  179. struct list_head comp_list;
  180. struct list_head async_list;
  181. u32 comp_events_reported;
  182. u32 async_events_reported;
  183. };
  184. struct ib_uflow_resources;
  185. struct ib_uflow_object {
  186. struct ib_uobject uobject;
  187. struct ib_uflow_resources *resources;
  188. };
  189. extern const struct file_operations uverbs_event_fops;
  190. void ib_uverbs_init_event_queue(struct ib_uverbs_event_queue *ev_queue);
  191. struct file *ib_uverbs_alloc_async_event_file(struct ib_uverbs_file *uverbs_file,
  192. struct ib_device *ib_dev);
  193. void ib_uverbs_free_async_event_file(struct ib_uverbs_file *uverbs_file);
  194. void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res);
  195. void ib_uverbs_release_ucq(struct ib_uverbs_file *file,
  196. struct ib_uverbs_completion_event_file *ev_file,
  197. struct ib_ucq_object *uobj);
  198. void ib_uverbs_release_uevent(struct ib_uverbs_file *file,
  199. struct ib_uevent_object *uobj);
  200. void ib_uverbs_release_file(struct kref *ref);
  201. void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);
  202. void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);
  203. void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);
  204. void ib_uverbs_wq_event_handler(struct ib_event *event, void *context_ptr);
  205. void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
  206. void ib_uverbs_event_handler(struct ib_event_handler *handler,
  207. struct ib_event *event);
  208. int ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd,
  209. enum rdma_remove_reason why);
  210. int uverbs_dealloc_mw(struct ib_mw *mw);
  211. void ib_uverbs_detach_umcast(struct ib_qp *qp,
  212. struct ib_uqp_object *uobj);
  213. void create_udata(struct uverbs_attr_bundle *ctx, struct ib_udata *udata);
  214. extern const struct uverbs_attr_def uverbs_uhw_compat_in;
  215. extern const struct uverbs_attr_def uverbs_uhw_compat_out;
  216. long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
  217. int uverbs_destroy_def_handler(struct ib_device *ib_dev,
  218. struct ib_uverbs_file *file,
  219. struct uverbs_attr_bundle *attrs);
  220. struct ib_uverbs_flow_spec {
  221. union {
  222. union {
  223. struct ib_uverbs_flow_spec_hdr hdr;
  224. struct {
  225. __u32 type;
  226. __u16 size;
  227. __u16 reserved;
  228. };
  229. };
  230. struct ib_uverbs_flow_spec_eth eth;
  231. struct ib_uverbs_flow_spec_ipv4 ipv4;
  232. struct ib_uverbs_flow_spec_esp esp;
  233. struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
  234. struct ib_uverbs_flow_spec_ipv6 ipv6;
  235. struct ib_uverbs_flow_spec_action_tag flow_tag;
  236. struct ib_uverbs_flow_spec_action_drop drop;
  237. struct ib_uverbs_flow_spec_action_handle action;
  238. };
  239. };
  240. int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
  241. const void *kern_spec_mask,
  242. const void *kern_spec_val,
  243. size_t kern_filter_sz,
  244. union ib_flow_spec *ib_spec);
  245. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DEVICE);
  246. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_PD);
  247. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_MR);
  248. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_COMP_CHANNEL);
  249. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_CQ);
  250. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_QP);
  251. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_AH);
  252. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_MW);
  253. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_SRQ);
  254. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW);
  255. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_WQ);
  256. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_RWQ_IND_TBL);
  257. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_XRCD);
  258. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_FLOW_ACTION);
  259. extern const struct uverbs_object_def UVERBS_OBJECT(UVERBS_OBJECT_DM);
  260. #define IB_UVERBS_DECLARE_CMD(name) \
  261. ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
  262. struct ib_device *ib_dev, \
  263. const char __user *buf, int in_len, \
  264. int out_len)
  265. IB_UVERBS_DECLARE_CMD(get_context);
  266. IB_UVERBS_DECLARE_CMD(query_device);
  267. IB_UVERBS_DECLARE_CMD(query_port);
  268. IB_UVERBS_DECLARE_CMD(alloc_pd);
  269. IB_UVERBS_DECLARE_CMD(dealloc_pd);
  270. IB_UVERBS_DECLARE_CMD(reg_mr);
  271. IB_UVERBS_DECLARE_CMD(rereg_mr);
  272. IB_UVERBS_DECLARE_CMD(dereg_mr);
  273. IB_UVERBS_DECLARE_CMD(alloc_mw);
  274. IB_UVERBS_DECLARE_CMD(dealloc_mw);
  275. IB_UVERBS_DECLARE_CMD(create_comp_channel);
  276. IB_UVERBS_DECLARE_CMD(create_cq);
  277. IB_UVERBS_DECLARE_CMD(resize_cq);
  278. IB_UVERBS_DECLARE_CMD(poll_cq);
  279. IB_UVERBS_DECLARE_CMD(req_notify_cq);
  280. IB_UVERBS_DECLARE_CMD(destroy_cq);
  281. IB_UVERBS_DECLARE_CMD(create_qp);
  282. IB_UVERBS_DECLARE_CMD(open_qp);
  283. IB_UVERBS_DECLARE_CMD(query_qp);
  284. IB_UVERBS_DECLARE_CMD(modify_qp);
  285. IB_UVERBS_DECLARE_CMD(destroy_qp);
  286. IB_UVERBS_DECLARE_CMD(post_send);
  287. IB_UVERBS_DECLARE_CMD(post_recv);
  288. IB_UVERBS_DECLARE_CMD(post_srq_recv);
  289. IB_UVERBS_DECLARE_CMD(create_ah);
  290. IB_UVERBS_DECLARE_CMD(destroy_ah);
  291. IB_UVERBS_DECLARE_CMD(attach_mcast);
  292. IB_UVERBS_DECLARE_CMD(detach_mcast);
  293. IB_UVERBS_DECLARE_CMD(create_srq);
  294. IB_UVERBS_DECLARE_CMD(modify_srq);
  295. IB_UVERBS_DECLARE_CMD(query_srq);
  296. IB_UVERBS_DECLARE_CMD(destroy_srq);
  297. IB_UVERBS_DECLARE_CMD(create_xsrq);
  298. IB_UVERBS_DECLARE_CMD(open_xrcd);
  299. IB_UVERBS_DECLARE_CMD(close_xrcd);
  300. #define IB_UVERBS_DECLARE_EX_CMD(name) \
  301. int ib_uverbs_ex_##name(struct ib_uverbs_file *file, \
  302. struct ib_device *ib_dev, \
  303. struct ib_udata *ucore, \
  304. struct ib_udata *uhw)
  305. IB_UVERBS_DECLARE_EX_CMD(create_flow);
  306. IB_UVERBS_DECLARE_EX_CMD(destroy_flow);
  307. IB_UVERBS_DECLARE_EX_CMD(query_device);
  308. IB_UVERBS_DECLARE_EX_CMD(create_cq);
  309. IB_UVERBS_DECLARE_EX_CMD(create_qp);
  310. IB_UVERBS_DECLARE_EX_CMD(create_wq);
  311. IB_UVERBS_DECLARE_EX_CMD(modify_wq);
  312. IB_UVERBS_DECLARE_EX_CMD(destroy_wq);
  313. IB_UVERBS_DECLARE_EX_CMD(create_rwq_ind_table);
  314. IB_UVERBS_DECLARE_EX_CMD(destroy_rwq_ind_table);
  315. IB_UVERBS_DECLARE_EX_CMD(modify_qp);
  316. IB_UVERBS_DECLARE_EX_CMD(modify_cq);
  317. #endif /* UVERBS_H */