rxe_verbs.h 9.4 KB

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