rxe_verbs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #ifndef RXE_VERBS_H
  34. #define RXE_VERBS_H
  35. #include <linux/interrupt.h>
  36. #include <rdma/rdma_user_rxe.h>
  37. #include "rxe_pool.h"
  38. #include "rxe_task.h"
  39. static inline int pkey_match(u16 key1, u16 key2)
  40. {
  41. return (((key1 & 0x7fff) != 0) &&
  42. ((key1 & 0x7fff) == (key2 & 0x7fff)) &&
  43. ((key1 & 0x8000) || (key2 & 0x8000))) ? 1 : 0;
  44. }
  45. /* Return >0 if psn_a > psn_b
  46. * 0 if psn_a == psn_b
  47. * <0 if psn_a < psn_b
  48. */
  49. static inline int psn_compare(u32 psn_a, u32 psn_b)
  50. {
  51. s32 diff;
  52. diff = (psn_a - psn_b) << 8;
  53. return diff;
  54. }
  55. struct rxe_ucontext {
  56. struct rxe_pool_entry pelem;
  57. struct ib_ucontext ibuc;
  58. };
  59. struct rxe_pd {
  60. struct rxe_pool_entry pelem;
  61. struct ib_pd ibpd;
  62. };
  63. struct rxe_ah {
  64. struct rxe_pool_entry pelem;
  65. struct ib_ah ibah;
  66. struct rxe_pd *pd;
  67. struct rxe_av av;
  68. };
  69. struct rxe_cqe {
  70. union {
  71. struct ib_wc ibwc;
  72. struct ib_uverbs_wc uibwc;
  73. };
  74. };
  75. struct rxe_cq {
  76. struct rxe_pool_entry pelem;
  77. struct ib_cq ibcq;
  78. struct rxe_queue *queue;
  79. spinlock_t cq_lock;
  80. u8 notify;
  81. int is_user;
  82. struct tasklet_struct comp_task;
  83. };
  84. enum wqe_state {
  85. wqe_state_posted,
  86. wqe_state_processing,
  87. wqe_state_pending,
  88. wqe_state_done,
  89. wqe_state_error,
  90. };
  91. struct rxe_sq {
  92. int max_wr;
  93. int max_sge;
  94. int max_inline;
  95. spinlock_t sq_lock; /* guard queue */
  96. struct rxe_queue *queue;
  97. };
  98. struct rxe_rq {
  99. int max_wr;
  100. int max_sge;
  101. spinlock_t producer_lock; /* guard queue producer */
  102. spinlock_t consumer_lock; /* guard queue consumer */
  103. struct rxe_queue *queue;
  104. };
  105. struct rxe_srq {
  106. struct rxe_pool_entry pelem;
  107. struct ib_srq ibsrq;
  108. struct rxe_pd *pd;
  109. struct rxe_rq rq;
  110. u32 srq_num;
  111. int limit;
  112. int error;
  113. };
  114. enum rxe_qp_state {
  115. QP_STATE_RESET,
  116. QP_STATE_INIT,
  117. QP_STATE_READY,
  118. QP_STATE_DRAIN, /* req only */
  119. QP_STATE_DRAINED, /* req only */
  120. QP_STATE_ERROR
  121. };
  122. extern char *rxe_qp_state_name[];
  123. struct rxe_req_info {
  124. enum rxe_qp_state state;
  125. int wqe_index;
  126. u32 psn;
  127. int opcode;
  128. atomic_t rd_atomic;
  129. int wait_fence;
  130. int need_rd_atomic;
  131. int wait_psn;
  132. int need_retry;
  133. int noack_pkts;
  134. struct rxe_task task;
  135. };
  136. struct rxe_comp_info {
  137. u32 psn;
  138. int opcode;
  139. int timeout;
  140. int timeout_retry;
  141. u32 retry_cnt;
  142. u32 rnr_retry;
  143. struct rxe_task task;
  144. };
  145. enum rdatm_res_state {
  146. rdatm_res_state_next,
  147. rdatm_res_state_new,
  148. rdatm_res_state_replay,
  149. };
  150. struct resp_res {
  151. int type;
  152. u32 first_psn;
  153. u32 last_psn;
  154. u32 cur_psn;
  155. enum rdatm_res_state state;
  156. union {
  157. struct {
  158. struct sk_buff *skb;
  159. } atomic;
  160. struct {
  161. struct rxe_mem *mr;
  162. u64 va_org;
  163. u32 rkey;
  164. u32 length;
  165. u64 va;
  166. u32 resid;
  167. } read;
  168. };
  169. };
  170. struct rxe_resp_info {
  171. enum rxe_qp_state state;
  172. u32 msn;
  173. u32 psn;
  174. int opcode;
  175. int drop_msg;
  176. int goto_error;
  177. int sent_psn_nak;
  178. enum ib_wc_status status;
  179. u8 aeth_syndrome;
  180. /* Receive only */
  181. struct rxe_recv_wqe *wqe;
  182. /* RDMA read / atomic only */
  183. u64 va;
  184. struct rxe_mem *mr;
  185. u32 resid;
  186. u32 rkey;
  187. u64 atomic_orig;
  188. /* SRQ only */
  189. struct {
  190. struct rxe_recv_wqe wqe;
  191. struct ib_sge sge[RXE_MAX_SGE];
  192. } srq_wqe;
  193. /* Responder resources. It's a circular list where the oldest
  194. * resource is dropped first.
  195. */
  196. struct resp_res *resources;
  197. unsigned int res_head;
  198. unsigned int res_tail;
  199. struct resp_res *res;
  200. struct rxe_task task;
  201. };
  202. struct rxe_qp {
  203. struct rxe_pool_entry pelem;
  204. struct ib_qp ibqp;
  205. struct ib_qp_attr attr;
  206. unsigned int valid;
  207. unsigned int mtu;
  208. int is_user;
  209. struct rxe_pd *pd;
  210. struct rxe_srq *srq;
  211. struct rxe_cq *scq;
  212. struct rxe_cq *rcq;
  213. enum ib_sig_type sq_sig_type;
  214. struct rxe_sq sq;
  215. struct rxe_rq rq;
  216. struct socket *sk;
  217. struct rxe_av pri_av;
  218. struct rxe_av alt_av;
  219. /* list of mcast groups qp has joined (for cleanup) */
  220. struct list_head grp_list;
  221. spinlock_t grp_lock; /* guard grp_list */
  222. struct sk_buff_head req_pkts;
  223. struct sk_buff_head resp_pkts;
  224. struct sk_buff_head send_pkts;
  225. struct rxe_req_info req;
  226. struct rxe_comp_info comp;
  227. struct rxe_resp_info resp;
  228. atomic_t ssn;
  229. atomic_t skb_out;
  230. int need_req_skb;
  231. /* Timer for retranmitting packet when ACKs have been lost. RC
  232. * only. The requester sets it when it is not already
  233. * started. The responder resets it whenever an ack is
  234. * received.
  235. */
  236. struct timer_list retrans_timer;
  237. u64 qp_timeout_jiffies;
  238. /* Timer for handling RNR NAKS. */
  239. struct timer_list rnr_nak_timer;
  240. spinlock_t state_lock; /* guard requester and completer */
  241. };
  242. enum rxe_mem_state {
  243. RXE_MEM_STATE_ZOMBIE,
  244. RXE_MEM_STATE_INVALID,
  245. RXE_MEM_STATE_FREE,
  246. RXE_MEM_STATE_VALID,
  247. };
  248. enum rxe_mem_type {
  249. RXE_MEM_TYPE_NONE,
  250. RXE_MEM_TYPE_DMA,
  251. RXE_MEM_TYPE_MR,
  252. RXE_MEM_TYPE_FMR,
  253. RXE_MEM_TYPE_MW,
  254. };
  255. #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
  256. struct rxe_phys_buf {
  257. u64 addr;
  258. u64 size;
  259. };
  260. struct rxe_map {
  261. struct rxe_phys_buf buf[RXE_BUF_PER_MAP];
  262. };
  263. struct rxe_mem {
  264. struct rxe_pool_entry pelem;
  265. union {
  266. struct ib_mr ibmr;
  267. struct ib_mw ibmw;
  268. };
  269. struct rxe_pd *pd;
  270. struct ib_umem *umem;
  271. u32 lkey;
  272. u32 rkey;
  273. enum rxe_mem_state state;
  274. enum rxe_mem_type type;
  275. u64 va;
  276. u64 iova;
  277. size_t length;
  278. u32 offset;
  279. int access;
  280. int page_shift;
  281. int page_mask;
  282. int map_shift;
  283. int map_mask;
  284. u32 num_buf;
  285. u32 nbuf;
  286. u32 max_buf;
  287. u32 num_map;
  288. struct rxe_map **map;
  289. };
  290. struct rxe_mc_grp {
  291. struct rxe_pool_entry pelem;
  292. spinlock_t mcg_lock; /* guard group */
  293. struct rxe_dev *rxe;
  294. struct list_head qp_list;
  295. union ib_gid mgid;
  296. int num_qp;
  297. u32 qkey;
  298. u16 pkey;
  299. };
  300. struct rxe_mc_elem {
  301. struct rxe_pool_entry pelem;
  302. struct list_head qp_list;
  303. struct list_head grp_list;
  304. struct rxe_qp *qp;
  305. struct rxe_mc_grp *grp;
  306. };
  307. struct rxe_port {
  308. struct ib_port_attr attr;
  309. u16 *pkey_tbl;
  310. __be64 port_guid;
  311. __be64 subnet_prefix;
  312. spinlock_t port_lock; /* guard port */
  313. unsigned int mtu_cap;
  314. /* special QPs */
  315. u32 qp_smi_index;
  316. u32 qp_gsi_index;
  317. };
  318. /* callbacks from rdma_rxe to network interface layer */
  319. struct rxe_ifc_ops {
  320. void (*release)(struct rxe_dev *rxe);
  321. __be64 (*node_guid)(struct rxe_dev *rxe);
  322. __be64 (*port_guid)(struct rxe_dev *rxe);
  323. struct device *(*dma_device)(struct rxe_dev *rxe);
  324. int (*mcast_add)(struct rxe_dev *rxe, union ib_gid *mgid);
  325. int (*mcast_delete)(struct rxe_dev *rxe, union ib_gid *mgid);
  326. int (*prepare)(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
  327. struct sk_buff *skb, u32 *crc);
  328. int (*send)(struct rxe_dev *rxe, struct rxe_pkt_info *pkt,
  329. struct sk_buff *skb);
  330. int (*loopback)(struct sk_buff *skb);
  331. struct sk_buff *(*init_packet)(struct rxe_dev *rxe, struct rxe_av *av,
  332. int paylen, struct rxe_pkt_info *pkt);
  333. char *(*parent_name)(struct rxe_dev *rxe, unsigned int port_num);
  334. enum rdma_link_layer (*link_layer)(struct rxe_dev *rxe,
  335. unsigned int port_num);
  336. };
  337. struct rxe_dev {
  338. struct ib_device ib_dev;
  339. struct ib_device_attr attr;
  340. int max_ucontext;
  341. int max_inline_data;
  342. struct kref ref_cnt;
  343. struct mutex usdev_lock;
  344. struct rxe_ifc_ops *ifc_ops;
  345. struct net_device *ndev;
  346. int xmit_errors;
  347. struct rxe_pool uc_pool;
  348. struct rxe_pool pd_pool;
  349. struct rxe_pool ah_pool;
  350. struct rxe_pool srq_pool;
  351. struct rxe_pool qp_pool;
  352. struct rxe_pool cq_pool;
  353. struct rxe_pool mr_pool;
  354. struct rxe_pool mw_pool;
  355. struct rxe_pool mc_grp_pool;
  356. struct rxe_pool mc_elem_pool;
  357. spinlock_t pending_lock; /* guard pending_mmaps */
  358. struct list_head pending_mmaps;
  359. spinlock_t mmap_offset_lock; /* guard mmap_offset */
  360. int mmap_offset;
  361. struct rxe_port port;
  362. struct list_head list;
  363. };
  364. static inline struct rxe_dev *to_rdev(struct ib_device *dev)
  365. {
  366. return dev ? container_of(dev, struct rxe_dev, ib_dev) : NULL;
  367. }
  368. static inline struct rxe_ucontext *to_ruc(struct ib_ucontext *uc)
  369. {
  370. return uc ? container_of(uc, struct rxe_ucontext, ibuc) : NULL;
  371. }
  372. static inline struct rxe_pd *to_rpd(struct ib_pd *pd)
  373. {
  374. return pd ? container_of(pd, struct rxe_pd, ibpd) : NULL;
  375. }
  376. static inline struct rxe_ah *to_rah(struct ib_ah *ah)
  377. {
  378. return ah ? container_of(ah, struct rxe_ah, ibah) : NULL;
  379. }
  380. static inline struct rxe_srq *to_rsrq(struct ib_srq *srq)
  381. {
  382. return srq ? container_of(srq, struct rxe_srq, ibsrq) : NULL;
  383. }
  384. static inline struct rxe_qp *to_rqp(struct ib_qp *qp)
  385. {
  386. return qp ? container_of(qp, struct rxe_qp, ibqp) : NULL;
  387. }
  388. static inline struct rxe_cq *to_rcq(struct ib_cq *cq)
  389. {
  390. return cq ? container_of(cq, struct rxe_cq, ibcq) : NULL;
  391. }
  392. static inline struct rxe_mem *to_rmr(struct ib_mr *mr)
  393. {
  394. return mr ? container_of(mr, struct rxe_mem, ibmr) : NULL;
  395. }
  396. static inline struct rxe_mem *to_rmw(struct ib_mw *mw)
  397. {
  398. return mw ? container_of(mw, struct rxe_mem, ibmw) : NULL;
  399. }
  400. int rxe_register_device(struct rxe_dev *rxe);
  401. int rxe_unregister_device(struct rxe_dev *rxe);
  402. void rxe_mc_cleanup(void *arg);
  403. #endif /* RXE_VERBS_H */