rxe_verbs.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 <linux/workqueue.h>
  37. #include <rdma/rdma_user_rxe.h>
  38. #include "rxe_pool.h"
  39. #include "rxe_task.h"
  40. #include "rxe_hw_counters.h"
  41. static inline int pkey_match(u16 key1, u16 key2)
  42. {
  43. return (((key1 & 0x7fff) != 0) &&
  44. ((key1 & 0x7fff) == (key2 & 0x7fff)) &&
  45. ((key1 & 0x8000) || (key2 & 0x8000))) ? 1 : 0;
  46. }
  47. /* Return >0 if psn_a > psn_b
  48. * 0 if psn_a == psn_b
  49. * <0 if psn_a < psn_b
  50. */
  51. static inline int psn_compare(u32 psn_a, u32 psn_b)
  52. {
  53. s32 diff;
  54. diff = (psn_a - psn_b) << 8;
  55. return diff;
  56. }
  57. struct rxe_ucontext {
  58. struct rxe_pool_entry pelem;
  59. struct ib_ucontext ibuc;
  60. };
  61. struct rxe_pd {
  62. struct rxe_pool_entry pelem;
  63. struct ib_pd ibpd;
  64. };
  65. struct rxe_ah {
  66. struct rxe_pool_entry pelem;
  67. struct ib_ah ibah;
  68. struct rxe_pd *pd;
  69. struct rxe_av av;
  70. };
  71. struct rxe_cqe {
  72. union {
  73. struct ib_wc ibwc;
  74. struct ib_uverbs_wc uibwc;
  75. };
  76. };
  77. struct rxe_cq {
  78. struct rxe_pool_entry pelem;
  79. struct ib_cq ibcq;
  80. struct rxe_queue *queue;
  81. spinlock_t cq_lock;
  82. u8 notify;
  83. bool is_dying;
  84. int is_user;
  85. struct tasklet_struct comp_task;
  86. };
  87. enum wqe_state {
  88. wqe_state_posted,
  89. wqe_state_processing,
  90. wqe_state_pending,
  91. wqe_state_done,
  92. wqe_state_error,
  93. };
  94. struct rxe_sq {
  95. int max_wr;
  96. int max_sge;
  97. int max_inline;
  98. spinlock_t sq_lock; /* guard queue */
  99. struct rxe_queue *queue;
  100. };
  101. struct rxe_rq {
  102. int max_wr;
  103. int max_sge;
  104. spinlock_t producer_lock; /* guard queue producer */
  105. spinlock_t consumer_lock; /* guard queue consumer */
  106. struct rxe_queue *queue;
  107. };
  108. struct rxe_srq {
  109. struct rxe_pool_entry pelem;
  110. struct ib_srq ibsrq;
  111. struct rxe_pd *pd;
  112. struct rxe_rq rq;
  113. u32 srq_num;
  114. int limit;
  115. int error;
  116. };
  117. enum rxe_qp_state {
  118. QP_STATE_RESET,
  119. QP_STATE_INIT,
  120. QP_STATE_READY,
  121. QP_STATE_DRAIN, /* req only */
  122. QP_STATE_DRAINED, /* req only */
  123. QP_STATE_ERROR
  124. };
  125. struct rxe_req_info {
  126. enum rxe_qp_state state;
  127. int wqe_index;
  128. u32 psn;
  129. int opcode;
  130. atomic_t rd_atomic;
  131. int wait_fence;
  132. int need_rd_atomic;
  133. int wait_psn;
  134. int need_retry;
  135. int noack_pkts;
  136. struct rxe_task task;
  137. };
  138. struct rxe_comp_info {
  139. u32 psn;
  140. int opcode;
  141. int timeout;
  142. int timeout_retry;
  143. int started_retry;
  144. u32 retry_cnt;
  145. u32 rnr_retry;
  146. struct rxe_task task;
  147. };
  148. enum rdatm_res_state {
  149. rdatm_res_state_next,
  150. rdatm_res_state_new,
  151. rdatm_res_state_replay,
  152. };
  153. struct resp_res {
  154. int type;
  155. int replay;
  156. u32 first_psn;
  157. u32 last_psn;
  158. u32 cur_psn;
  159. enum rdatm_res_state state;
  160. union {
  161. struct {
  162. struct sk_buff *skb;
  163. } atomic;
  164. struct {
  165. struct rxe_mem *mr;
  166. u64 va_org;
  167. u32 rkey;
  168. u32 length;
  169. u64 va;
  170. u32 resid;
  171. } read;
  172. };
  173. };
  174. struct rxe_resp_info {
  175. enum rxe_qp_state state;
  176. u32 msn;
  177. u32 psn;
  178. u32 ack_psn;
  179. int opcode;
  180. int drop_msg;
  181. int goto_error;
  182. int sent_psn_nak;
  183. enum ib_wc_status status;
  184. u8 aeth_syndrome;
  185. /* Receive only */
  186. struct rxe_recv_wqe *wqe;
  187. /* RDMA read / atomic only */
  188. u64 va;
  189. struct rxe_mem *mr;
  190. u32 resid;
  191. u32 rkey;
  192. u32 length;
  193. u64 atomic_orig;
  194. /* SRQ only */
  195. struct {
  196. struct rxe_recv_wqe wqe;
  197. struct ib_sge sge[RXE_MAX_SGE];
  198. } srq_wqe;
  199. /* Responder resources. It's a circular list where the oldest
  200. * resource is dropped first.
  201. */
  202. struct resp_res *resources;
  203. unsigned int res_head;
  204. unsigned int res_tail;
  205. struct resp_res *res;
  206. struct rxe_task task;
  207. };
  208. struct rxe_qp {
  209. struct rxe_pool_entry pelem;
  210. struct ib_qp ibqp;
  211. struct ib_qp_attr attr;
  212. unsigned int valid;
  213. unsigned int mtu;
  214. int is_user;
  215. struct rxe_pd *pd;
  216. struct rxe_srq *srq;
  217. struct rxe_cq *scq;
  218. struct rxe_cq *rcq;
  219. enum ib_sig_type sq_sig_type;
  220. struct rxe_sq sq;
  221. struct rxe_rq rq;
  222. struct socket *sk;
  223. u32 dst_cookie;
  224. struct rxe_av pri_av;
  225. struct rxe_av alt_av;
  226. /* list of mcast groups qp has joined (for cleanup) */
  227. struct list_head grp_list;
  228. spinlock_t grp_lock; /* guard grp_list */
  229. struct sk_buff_head req_pkts;
  230. struct sk_buff_head resp_pkts;
  231. struct sk_buff_head send_pkts;
  232. struct rxe_req_info req;
  233. struct rxe_comp_info comp;
  234. struct rxe_resp_info resp;
  235. atomic_t ssn;
  236. atomic_t skb_out;
  237. int need_req_skb;
  238. /* Timer for retranmitting packet when ACKs have been lost. RC
  239. * only. The requester sets it when it is not already
  240. * started. The responder resets it whenever an ack is
  241. * received.
  242. */
  243. struct timer_list retrans_timer;
  244. u64 qp_timeout_jiffies;
  245. /* Timer for handling RNR NAKS. */
  246. struct timer_list rnr_nak_timer;
  247. spinlock_t state_lock; /* guard requester and completer */
  248. struct execute_work cleanup_work;
  249. };
  250. enum rxe_mem_state {
  251. RXE_MEM_STATE_ZOMBIE,
  252. RXE_MEM_STATE_INVALID,
  253. RXE_MEM_STATE_FREE,
  254. RXE_MEM_STATE_VALID,
  255. };
  256. enum rxe_mem_type {
  257. RXE_MEM_TYPE_NONE,
  258. RXE_MEM_TYPE_DMA,
  259. RXE_MEM_TYPE_MR,
  260. RXE_MEM_TYPE_FMR,
  261. RXE_MEM_TYPE_MW,
  262. };
  263. #define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf))
  264. struct rxe_phys_buf {
  265. u64 addr;
  266. u64 size;
  267. };
  268. struct rxe_map {
  269. struct rxe_phys_buf buf[RXE_BUF_PER_MAP];
  270. };
  271. struct rxe_mem {
  272. struct rxe_pool_entry pelem;
  273. union {
  274. struct ib_mr ibmr;
  275. struct ib_mw ibmw;
  276. };
  277. struct rxe_pd *pd;
  278. struct ib_umem *umem;
  279. u32 lkey;
  280. u32 rkey;
  281. enum rxe_mem_state state;
  282. enum rxe_mem_type type;
  283. u64 va;
  284. u64 iova;
  285. size_t length;
  286. u32 offset;
  287. int access;
  288. int page_shift;
  289. int page_mask;
  290. int map_shift;
  291. int map_mask;
  292. u32 num_buf;
  293. u32 nbuf;
  294. u32 max_buf;
  295. u32 num_map;
  296. struct rxe_map **map;
  297. };
  298. struct rxe_mc_grp {
  299. struct rxe_pool_entry pelem;
  300. spinlock_t mcg_lock; /* guard group */
  301. struct rxe_dev *rxe;
  302. struct list_head qp_list;
  303. union ib_gid mgid;
  304. int num_qp;
  305. u32 qkey;
  306. u16 pkey;
  307. };
  308. struct rxe_mc_elem {
  309. struct rxe_pool_entry pelem;
  310. struct list_head qp_list;
  311. struct list_head grp_list;
  312. struct rxe_qp *qp;
  313. struct rxe_mc_grp *grp;
  314. };
  315. struct rxe_port {
  316. struct ib_port_attr attr;
  317. u16 *pkey_tbl;
  318. __be64 port_guid;
  319. __be64 subnet_prefix;
  320. spinlock_t port_lock; /* guard port */
  321. unsigned int mtu_cap;
  322. /* special QPs */
  323. u32 qp_smi_index;
  324. u32 qp_gsi_index;
  325. };
  326. struct rxe_dev {
  327. struct ib_device ib_dev;
  328. struct ib_device_attr attr;
  329. int max_ucontext;
  330. int max_inline_data;
  331. struct kref ref_cnt;
  332. struct mutex usdev_lock;
  333. struct net_device *ndev;
  334. int xmit_errors;
  335. struct rxe_pool uc_pool;
  336. struct rxe_pool pd_pool;
  337. struct rxe_pool ah_pool;
  338. struct rxe_pool srq_pool;
  339. struct rxe_pool qp_pool;
  340. struct rxe_pool cq_pool;
  341. struct rxe_pool mr_pool;
  342. struct rxe_pool mw_pool;
  343. struct rxe_pool mc_grp_pool;
  344. struct rxe_pool mc_elem_pool;
  345. spinlock_t pending_lock; /* guard pending_mmaps */
  346. struct list_head pending_mmaps;
  347. spinlock_t mmap_offset_lock; /* guard mmap_offset */
  348. u64 mmap_offset;
  349. atomic64_t stats_counters[RXE_NUM_OF_COUNTERS];
  350. struct rxe_port port;
  351. struct list_head list;
  352. struct crypto_shash *tfm;
  353. };
  354. static inline void rxe_counter_inc(struct rxe_dev *rxe, enum rxe_counters index)
  355. {
  356. atomic64_inc(&rxe->stats_counters[index]);
  357. }
  358. static inline struct rxe_dev *to_rdev(struct ib_device *dev)
  359. {
  360. return dev ? container_of(dev, struct rxe_dev, ib_dev) : NULL;
  361. }
  362. static inline struct rxe_ucontext *to_ruc(struct ib_ucontext *uc)
  363. {
  364. return uc ? container_of(uc, struct rxe_ucontext, ibuc) : NULL;
  365. }
  366. static inline struct rxe_pd *to_rpd(struct ib_pd *pd)
  367. {
  368. return pd ? container_of(pd, struct rxe_pd, ibpd) : NULL;
  369. }
  370. static inline struct rxe_ah *to_rah(struct ib_ah *ah)
  371. {
  372. return ah ? container_of(ah, struct rxe_ah, ibah) : NULL;
  373. }
  374. static inline struct rxe_srq *to_rsrq(struct ib_srq *srq)
  375. {
  376. return srq ? container_of(srq, struct rxe_srq, ibsrq) : NULL;
  377. }
  378. static inline struct rxe_qp *to_rqp(struct ib_qp *qp)
  379. {
  380. return qp ? container_of(qp, struct rxe_qp, ibqp) : NULL;
  381. }
  382. static inline struct rxe_cq *to_rcq(struct ib_cq *cq)
  383. {
  384. return cq ? container_of(cq, struct rxe_cq, ibcq) : NULL;
  385. }
  386. static inline struct rxe_mem *to_rmr(struct ib_mr *mr)
  387. {
  388. return mr ? container_of(mr, struct rxe_mem, ibmr) : NULL;
  389. }
  390. static inline struct rxe_mem *to_rmw(struct ib_mw *mw)
  391. {
  392. return mw ? container_of(mw, struct rxe_mem, ibmw) : NULL;
  393. }
  394. int rxe_register_device(struct rxe_dev *rxe);
  395. int rxe_unregister_device(struct rxe_dev *rxe);
  396. void rxe_mc_cleanup(struct rxe_pool_entry *arg);
  397. #endif /* RXE_VERBS_H */