ocrdma.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*******************************************************************
  2. * This file is part of the Emulex RoCE Device Driver for *
  3. * RoCE (RDMA over Converged Ethernet) adapters. *
  4. * Copyright (C) 2008-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *
  20. * Contact Information:
  21. * linux-drivers@emulex.com
  22. *
  23. * Emulex
  24. * 3333 Susan Street
  25. * Costa Mesa, CA 92626
  26. *******************************************************************/
  27. #ifndef __OCRDMA_H__
  28. #define __OCRDMA_H__
  29. #include <linux/mutex.h>
  30. #include <linux/list.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/pci.h>
  33. #include <rdma/ib_verbs.h>
  34. #include <rdma/ib_user_verbs.h>
  35. #include <be_roce.h>
  36. #include "ocrdma_sli.h"
  37. #define OCRDMA_ROCE_DEV_VERSION "1.0.0"
  38. #define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
  39. #define OCRDMA_MAX_AH 512
  40. #define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  41. struct ocrdma_dev_attr {
  42. u8 fw_ver[32];
  43. u32 vendor_id;
  44. u32 device_id;
  45. u16 max_pd;
  46. u16 max_cq;
  47. u16 max_cqe;
  48. u16 max_qp;
  49. u16 max_wqe;
  50. u16 max_rqe;
  51. u16 max_srq;
  52. u32 max_inline_data;
  53. int max_send_sge;
  54. int max_recv_sge;
  55. int max_srq_sge;
  56. int max_rdma_sge;
  57. int max_mr;
  58. u64 max_mr_size;
  59. u32 max_num_mr_pbl;
  60. int max_fmr;
  61. int max_map_per_fmr;
  62. int max_pages_per_frmr;
  63. u16 max_ord_per_qp;
  64. u16 max_ird_per_qp;
  65. int device_cap_flags;
  66. u8 cq_overflow_detect;
  67. u8 srq_supported;
  68. u32 wqe_size;
  69. u32 rqe_size;
  70. u32 ird_page_size;
  71. u8 local_ca_ack_delay;
  72. u8 ird;
  73. u8 num_ird_pages;
  74. };
  75. struct ocrdma_pbl {
  76. void *va;
  77. dma_addr_t pa;
  78. };
  79. struct ocrdma_queue_info {
  80. void *va;
  81. dma_addr_t dma;
  82. u32 size;
  83. u16 len;
  84. u16 entry_size; /* Size of an element in the queue */
  85. u16 id; /* qid, where to ring the doorbell. */
  86. u16 head, tail;
  87. bool created;
  88. };
  89. struct ocrdma_eq {
  90. struct ocrdma_queue_info q;
  91. u32 vector;
  92. int cq_cnt;
  93. struct ocrdma_dev *dev;
  94. char irq_name[32];
  95. };
  96. struct ocrdma_mq {
  97. struct ocrdma_queue_info sq;
  98. struct ocrdma_queue_info cq;
  99. bool rearm_cq;
  100. };
  101. struct mqe_ctx {
  102. struct mutex lock; /* for serializing mailbox commands on MQ */
  103. wait_queue_head_t cmd_wait;
  104. u32 tag;
  105. u16 cqe_status;
  106. u16 ext_status;
  107. bool cmd_done;
  108. };
  109. struct ocrdma_dev {
  110. struct ib_device ibdev;
  111. struct ocrdma_dev_attr attr;
  112. struct mutex dev_lock; /* provides syncronise access to device data */
  113. spinlock_t flush_q_lock ____cacheline_aligned;
  114. struct ocrdma_cq **cq_tbl;
  115. struct ocrdma_qp **qp_tbl;
  116. struct ocrdma_eq *eq_tbl;
  117. int eq_cnt;
  118. u16 base_eqid;
  119. u16 max_eq;
  120. union ib_gid *sgid_tbl;
  121. /* provided synchronization to sgid table for
  122. * updating gid entries triggered by notifier.
  123. */
  124. spinlock_t sgid_lock;
  125. int gsi_qp_created;
  126. struct ocrdma_cq *gsi_sqcq;
  127. struct ocrdma_cq *gsi_rqcq;
  128. struct {
  129. struct ocrdma_av *va;
  130. dma_addr_t pa;
  131. u32 size;
  132. u32 num_ah;
  133. /* provide synchronization for av
  134. * entry allocations.
  135. */
  136. spinlock_t lock;
  137. u32 ahid;
  138. struct ocrdma_pbl pbl;
  139. } av_tbl;
  140. void *mbx_cmd;
  141. struct ocrdma_mq mq;
  142. struct mqe_ctx mqe_ctx;
  143. struct be_dev_info nic_info;
  144. struct list_head entry;
  145. struct rcu_head rcu;
  146. int id;
  147. u64 stag_arr[OCRDMA_MAX_STAG];
  148. u16 pvid;
  149. };
  150. struct ocrdma_cq {
  151. struct ib_cq ibcq;
  152. struct ocrdma_cqe *va;
  153. u32 phase;
  154. u32 getp; /* pointer to pending wrs to
  155. * return to stack, wrap arounds
  156. * at max_hw_cqe
  157. */
  158. u32 max_hw_cqe;
  159. bool phase_change;
  160. bool armed, solicited;
  161. bool arm_needed;
  162. spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
  163. * to cq polling
  164. */
  165. /* syncronizes cq completion handler invoked from multiple context */
  166. spinlock_t comp_handler_lock ____cacheline_aligned;
  167. u16 id;
  168. u16 eqn;
  169. struct ocrdma_ucontext *ucontext;
  170. dma_addr_t pa;
  171. u32 len;
  172. /* head of all qp's sq and rq for which cqes need to be flushed
  173. * by the software.
  174. */
  175. struct list_head sq_head, rq_head;
  176. };
  177. struct ocrdma_pd {
  178. struct ib_pd ibpd;
  179. struct ocrdma_dev *dev;
  180. struct ocrdma_ucontext *uctx;
  181. u32 id;
  182. int num_dpp_qp;
  183. u32 dpp_page;
  184. bool dpp_enabled;
  185. };
  186. struct ocrdma_ah {
  187. struct ib_ah ibah;
  188. struct ocrdma_av *av;
  189. u16 sgid_index;
  190. u32 id;
  191. };
  192. struct ocrdma_qp_hwq_info {
  193. u8 *va; /* virtual address */
  194. u32 max_sges;
  195. u32 head, tail;
  196. u32 entry_size;
  197. u32 max_cnt;
  198. u32 max_wqe_idx;
  199. u16 dbid; /* qid, where to ring the doorbell. */
  200. u32 len;
  201. dma_addr_t pa;
  202. };
  203. struct ocrdma_srq {
  204. struct ib_srq ibsrq;
  205. u8 __iomem *db;
  206. struct ocrdma_qp_hwq_info rq;
  207. u64 *rqe_wr_id_tbl;
  208. u32 *idx_bit_fields;
  209. u32 bit_fields_len;
  210. /* provide synchronization to multiple context(s) posting rqe */
  211. spinlock_t q_lock ____cacheline_aligned;
  212. struct ocrdma_pd *pd;
  213. u32 id;
  214. };
  215. struct ocrdma_qp {
  216. struct ib_qp ibqp;
  217. struct ocrdma_dev *dev;
  218. u8 __iomem *sq_db;
  219. struct ocrdma_qp_hwq_info sq;
  220. struct {
  221. uint64_t wrid;
  222. uint16_t dpp_wqe_idx;
  223. uint16_t dpp_wqe;
  224. uint8_t signaled;
  225. uint8_t rsvd[3];
  226. } *wqe_wr_id_tbl;
  227. u32 max_inline_data;
  228. /* provide synchronization to multiple context(s) posting wqe, rqe */
  229. spinlock_t q_lock ____cacheline_aligned;
  230. struct ocrdma_cq *sq_cq;
  231. /* list maintained per CQ to flush SQ errors */
  232. struct list_head sq_entry;
  233. u8 __iomem *rq_db;
  234. struct ocrdma_qp_hwq_info rq;
  235. u64 *rqe_wr_id_tbl;
  236. struct ocrdma_cq *rq_cq;
  237. struct ocrdma_srq *srq;
  238. /* list maintained per CQ to flush RQ errors */
  239. struct list_head rq_entry;
  240. enum ocrdma_qp_state state; /* QP state */
  241. int cap_flags;
  242. u32 max_ord, max_ird;
  243. u32 id;
  244. struct ocrdma_pd *pd;
  245. enum ib_qp_type qp_type;
  246. int sgid_idx;
  247. u32 qkey;
  248. bool dpp_enabled;
  249. u8 *ird_q_va;
  250. bool signaled;
  251. u16 db_cache;
  252. };
  253. struct ocrdma_hw_mr {
  254. u32 lkey;
  255. u8 fr_mr;
  256. u8 remote_atomic;
  257. u8 remote_rd;
  258. u8 remote_wr;
  259. u8 local_rd;
  260. u8 local_wr;
  261. u8 mw_bind;
  262. u8 rsvd;
  263. u64 len;
  264. struct ocrdma_pbl *pbl_table;
  265. u32 num_pbls;
  266. u32 num_pbes;
  267. u32 pbl_size;
  268. u32 pbe_size;
  269. u64 fbo;
  270. u64 va;
  271. };
  272. struct ocrdma_mr {
  273. struct ib_mr ibmr;
  274. struct ib_umem *umem;
  275. struct ocrdma_hw_mr hwmr;
  276. };
  277. struct ocrdma_ucontext {
  278. struct ib_ucontext ibucontext;
  279. struct list_head mm_head;
  280. struct mutex mm_list_lock; /* protects list entries of mm type */
  281. struct ocrdma_pd *cntxt_pd;
  282. int pd_in_use;
  283. struct {
  284. u32 *va;
  285. dma_addr_t pa;
  286. u32 len;
  287. } ah_tbl;
  288. };
  289. struct ocrdma_mm {
  290. struct {
  291. u64 phy_addr;
  292. unsigned long len;
  293. } key;
  294. struct list_head entry;
  295. };
  296. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  297. {
  298. return container_of(ibdev, struct ocrdma_dev, ibdev);
  299. }
  300. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  301. *ibucontext)
  302. {
  303. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  304. }
  305. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  306. {
  307. return container_of(ibpd, struct ocrdma_pd, ibpd);
  308. }
  309. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  310. {
  311. return container_of(ibcq, struct ocrdma_cq, ibcq);
  312. }
  313. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  314. {
  315. return container_of(ibqp, struct ocrdma_qp, ibqp);
  316. }
  317. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  318. {
  319. return container_of(ibmr, struct ocrdma_mr, ibmr);
  320. }
  321. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  322. {
  323. return container_of(ibah, struct ocrdma_ah, ibah);
  324. }
  325. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  326. {
  327. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  328. }
  329. static inline int ocrdma_get_num_posted_shift(struct ocrdma_qp *qp)
  330. {
  331. return ((qp->dev->nic_info.dev_family == OCRDMA_GEN2_FAMILY &&
  332. qp->id < 128) ? 24 : 16);
  333. }
  334. static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
  335. {
  336. int cqe_valid;
  337. cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
  338. return (cqe_valid == cq->phase);
  339. }
  340. static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
  341. {
  342. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  343. OCRDMA_CQE_QTYPE) ? 0 : 1;
  344. }
  345. static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
  346. {
  347. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  348. OCRDMA_CQE_INVALIDATE) ? 1 : 0;
  349. }
  350. static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
  351. {
  352. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  353. OCRDMA_CQE_IMM) ? 1 : 0;
  354. }
  355. static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
  356. {
  357. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  358. OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
  359. }
  360. #endif