ocrdma.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. };
  149. struct ocrdma_cq {
  150. struct ib_cq ibcq;
  151. struct ocrdma_cqe *va;
  152. u32 phase;
  153. u32 getp; /* pointer to pending wrs to
  154. * return to stack, wrap arounds
  155. * at max_hw_cqe
  156. */
  157. u32 max_hw_cqe;
  158. bool phase_change;
  159. bool armed, solicited;
  160. bool arm_needed;
  161. spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
  162. * to cq polling
  163. */
  164. /* syncronizes cq completion handler invoked from multiple context */
  165. spinlock_t comp_handler_lock ____cacheline_aligned;
  166. u16 id;
  167. u16 eqn;
  168. struct ocrdma_ucontext *ucontext;
  169. dma_addr_t pa;
  170. u32 len;
  171. /* head of all qp's sq and rq for which cqes need to be flushed
  172. * by the software.
  173. */
  174. struct list_head sq_head, rq_head;
  175. };
  176. struct ocrdma_pd {
  177. struct ib_pd ibpd;
  178. struct ocrdma_dev *dev;
  179. struct ocrdma_ucontext *uctx;
  180. u32 id;
  181. int num_dpp_qp;
  182. u32 dpp_page;
  183. bool dpp_enabled;
  184. };
  185. struct ocrdma_ah {
  186. struct ib_ah ibah;
  187. struct ocrdma_av *av;
  188. u16 sgid_index;
  189. u32 id;
  190. };
  191. struct ocrdma_qp_hwq_info {
  192. u8 *va; /* virtual address */
  193. u32 max_sges;
  194. u32 head, tail;
  195. u32 entry_size;
  196. u32 max_cnt;
  197. u32 max_wqe_idx;
  198. u16 dbid; /* qid, where to ring the doorbell. */
  199. u32 len;
  200. dma_addr_t pa;
  201. };
  202. struct ocrdma_srq {
  203. struct ib_srq ibsrq;
  204. u8 __iomem *db;
  205. struct ocrdma_qp_hwq_info rq;
  206. u64 *rqe_wr_id_tbl;
  207. u32 *idx_bit_fields;
  208. u32 bit_fields_len;
  209. /* provide synchronization to multiple context(s) posting rqe */
  210. spinlock_t q_lock ____cacheline_aligned;
  211. struct ocrdma_pd *pd;
  212. u32 id;
  213. };
  214. struct ocrdma_qp {
  215. struct ib_qp ibqp;
  216. struct ocrdma_dev *dev;
  217. u8 __iomem *sq_db;
  218. struct ocrdma_qp_hwq_info sq;
  219. struct {
  220. uint64_t wrid;
  221. uint16_t dpp_wqe_idx;
  222. uint16_t dpp_wqe;
  223. uint8_t signaled;
  224. uint8_t rsvd[3];
  225. } *wqe_wr_id_tbl;
  226. u32 max_inline_data;
  227. /* provide synchronization to multiple context(s) posting wqe, rqe */
  228. spinlock_t q_lock ____cacheline_aligned;
  229. struct ocrdma_cq *sq_cq;
  230. /* list maintained per CQ to flush SQ errors */
  231. struct list_head sq_entry;
  232. u8 __iomem *rq_db;
  233. struct ocrdma_qp_hwq_info rq;
  234. u64 *rqe_wr_id_tbl;
  235. struct ocrdma_cq *rq_cq;
  236. struct ocrdma_srq *srq;
  237. /* list maintained per CQ to flush RQ errors */
  238. struct list_head rq_entry;
  239. enum ocrdma_qp_state state; /* QP state */
  240. int cap_flags;
  241. u32 max_ord, max_ird;
  242. u32 id;
  243. struct ocrdma_pd *pd;
  244. enum ib_qp_type qp_type;
  245. int sgid_idx;
  246. u32 qkey;
  247. bool dpp_enabled;
  248. u8 *ird_q_va;
  249. bool signaled;
  250. u16 db_cache;
  251. };
  252. struct ocrdma_hw_mr {
  253. u32 lkey;
  254. u8 fr_mr;
  255. u8 remote_atomic;
  256. u8 remote_rd;
  257. u8 remote_wr;
  258. u8 local_rd;
  259. u8 local_wr;
  260. u8 mw_bind;
  261. u8 rsvd;
  262. u64 len;
  263. struct ocrdma_pbl *pbl_table;
  264. u32 num_pbls;
  265. u32 num_pbes;
  266. u32 pbl_size;
  267. u32 pbe_size;
  268. u64 fbo;
  269. u64 va;
  270. };
  271. struct ocrdma_mr {
  272. struct ib_mr ibmr;
  273. struct ib_umem *umem;
  274. struct ocrdma_hw_mr hwmr;
  275. };
  276. struct ocrdma_ucontext {
  277. struct ib_ucontext ibucontext;
  278. struct list_head mm_head;
  279. struct mutex mm_list_lock; /* protects list entries of mm type */
  280. struct {
  281. u32 *va;
  282. dma_addr_t pa;
  283. u32 len;
  284. } ah_tbl;
  285. };
  286. struct ocrdma_mm {
  287. struct {
  288. u64 phy_addr;
  289. unsigned long len;
  290. } key;
  291. struct list_head entry;
  292. };
  293. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  294. {
  295. return container_of(ibdev, struct ocrdma_dev, ibdev);
  296. }
  297. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  298. *ibucontext)
  299. {
  300. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  301. }
  302. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  303. {
  304. return container_of(ibpd, struct ocrdma_pd, ibpd);
  305. }
  306. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  307. {
  308. return container_of(ibcq, struct ocrdma_cq, ibcq);
  309. }
  310. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  311. {
  312. return container_of(ibqp, struct ocrdma_qp, ibqp);
  313. }
  314. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  315. {
  316. return container_of(ibmr, struct ocrdma_mr, ibmr);
  317. }
  318. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  319. {
  320. return container_of(ibah, struct ocrdma_ah, ibah);
  321. }
  322. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  323. {
  324. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  325. }
  326. static inline int ocrdma_get_num_posted_shift(struct ocrdma_qp *qp)
  327. {
  328. return ((qp->dev->nic_info.dev_family == OCRDMA_GEN2_FAMILY &&
  329. qp->id < 128) ? 24 : 16);
  330. }
  331. static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
  332. {
  333. int cqe_valid;
  334. cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
  335. return (cqe_valid == cq->phase);
  336. }
  337. static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
  338. {
  339. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  340. OCRDMA_CQE_QTYPE) ? 0 : 1;
  341. }
  342. static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
  343. {
  344. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  345. OCRDMA_CQE_INVALIDATE) ? 1 : 0;
  346. }
  347. static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
  348. {
  349. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  350. OCRDMA_CQE_IMM) ? 1 : 0;
  351. }
  352. static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
  353. {
  354. return (le32_to_cpu(cqe->flags_status_srcqpn) &
  355. OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
  356. }
  357. #endif