uverbs.h 9.7 KB

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