ocrdma.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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_err(format, arg...) printk(KERN_ERR format, ##arg)
  40. #define OCRDMA_MAX_AH 512
  41. #define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  42. struct ocrdma_dev_attr {
  43. u8 fw_ver[32];
  44. u32 vendor_id;
  45. u32 device_id;
  46. u16 max_pd;
  47. u16 max_cq;
  48. u16 max_cqe;
  49. u16 max_qp;
  50. u16 max_wqe;
  51. u16 max_rqe;
  52. u32 max_inline_data;
  53. int max_send_sge;
  54. int max_recv_sge;
  55. int max_srq_sge;
  56. int max_mr;
  57. u64 max_mr_size;
  58. u32 max_num_mr_pbl;
  59. int max_fmr;
  60. int max_map_per_fmr;
  61. int max_pages_per_frmr;
  62. u16 max_ord_per_qp;
  63. u16 max_ird_per_qp;
  64. int device_cap_flags;
  65. u8 cq_overflow_detect;
  66. u8 srq_supported;
  67. u32 wqe_size;
  68. u32 rqe_size;
  69. u32 ird_page_size;
  70. u8 local_ca_ack_delay;
  71. u8 ird;
  72. u8 num_ird_pages;
  73. };
  74. struct ocrdma_pbl {
  75. void *va;
  76. dma_addr_t pa;
  77. };
  78. struct ocrdma_queue_info {
  79. void *va;
  80. dma_addr_t dma;
  81. u32 size;
  82. u16 len;
  83. u16 entry_size; /* Size of an element in the queue */
  84. u16 id; /* qid, where to ring the doorbell. */
  85. u16 head, tail;
  86. bool created;
  87. atomic_t used; /* Number of valid elements in the queue */
  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 meq;
  117. struct ocrdma_eq *qp_eq_tbl;
  118. int eq_cnt;
  119. u16 base_eqid;
  120. u16 max_eq;
  121. union ib_gid *sgid_tbl;
  122. /* provided synchronization to sgid table for
  123. * updating gid entries triggered by notifier.
  124. */
  125. spinlock_t sgid_lock;
  126. int gsi_qp_created;
  127. struct ocrdma_cq *gsi_sqcq;
  128. struct ocrdma_cq *gsi_rqcq;
  129. struct {
  130. struct ocrdma_av *va;
  131. dma_addr_t pa;
  132. u32 size;
  133. u32 num_ah;
  134. /* provide synchronization for av
  135. * entry allocations.
  136. */
  137. spinlock_t lock;
  138. u32 ahid;
  139. struct ocrdma_pbl pbl;
  140. } av_tbl;
  141. void *mbx_cmd;
  142. struct ocrdma_mq mq;
  143. struct mqe_ctx mqe_ctx;
  144. struct be_dev_info nic_info;
  145. struct list_head entry;
  146. struct rcu_head rcu;
  147. int id;
  148. };
  149. struct ocrdma_cq {
  150. struct ib_cq ibcq;
  151. struct ocrdma_dev *dev;
  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. atomic_t use_cnt;
  173. /* head of all qp's sq and rq for which cqes need to be flushed
  174. * by the software.
  175. */
  176. struct list_head sq_head, rq_head;
  177. };
  178. struct ocrdma_pd {
  179. struct ib_pd ibpd;
  180. struct ocrdma_dev *dev;
  181. struct ocrdma_ucontext *uctx;
  182. atomic_t use_cnt;
  183. u32 id;
  184. int num_dpp_qp;
  185. u32 dpp_page;
  186. bool dpp_enabled;
  187. };
  188. struct ocrdma_ah {
  189. struct ib_ah ibah;
  190. struct ocrdma_dev *dev;
  191. struct ocrdma_av *av;
  192. u16 sgid_index;
  193. u32 id;
  194. };
  195. struct ocrdma_qp_hwq_info {
  196. u8 *va; /* virtual address */
  197. u32 max_sges;
  198. u32 head, tail;
  199. u32 entry_size;
  200. u32 max_cnt;
  201. u32 max_wqe_idx;
  202. u16 dbid; /* qid, where to ring the doorbell. */
  203. u32 len;
  204. dma_addr_t pa;
  205. };
  206. struct ocrdma_srq {
  207. struct ib_srq ibsrq;
  208. struct ocrdma_dev *dev;
  209. u8 __iomem *db;
  210. /* provide synchronization to multiple context(s) posting rqe */
  211. spinlock_t q_lock ____cacheline_aligned;
  212. struct ocrdma_qp_hwq_info rq;
  213. struct ocrdma_pd *pd;
  214. atomic_t use_cnt;
  215. u32 id;
  216. u64 *rqe_wr_id_tbl;
  217. u32 *idx_bit_fields;
  218. u32 bit_fields_len;
  219. };
  220. struct ocrdma_qp {
  221. struct ib_qp ibqp;
  222. struct ocrdma_dev *dev;
  223. u8 __iomem *sq_db;
  224. /* provide synchronization to multiple context(s) posting wqe, rqe */
  225. spinlock_t q_lock ____cacheline_aligned;
  226. struct ocrdma_qp_hwq_info sq;
  227. struct {
  228. uint64_t wrid;
  229. uint16_t dpp_wqe_idx;
  230. uint16_t dpp_wqe;
  231. uint8_t signaled;
  232. uint8_t rsvd[3];
  233. } *wqe_wr_id_tbl;
  234. u32 max_inline_data;
  235. struct ocrdma_cq *sq_cq;
  236. /* list maintained per CQ to flush SQ errors */
  237. struct list_head sq_entry;
  238. u8 __iomem *rq_db;
  239. struct ocrdma_qp_hwq_info rq;
  240. u64 *rqe_wr_id_tbl;
  241. struct ocrdma_cq *rq_cq;
  242. struct ocrdma_srq *srq;
  243. /* list maintained per CQ to flush RQ errors */
  244. struct list_head rq_entry;
  245. enum ocrdma_qp_state state; /* QP state */
  246. int cap_flags;
  247. u32 max_ord, max_ird;
  248. u32 id;
  249. struct ocrdma_pd *pd;
  250. enum ib_qp_type qp_type;
  251. int sgid_idx;
  252. u32 qkey;
  253. bool dpp_enabled;
  254. u8 *ird_q_va;
  255. };
  256. #define OCRDMA_GET_NUM_POSTED_SHIFT_VAL(qp) \
  257. (((qp->dev->nic_info.dev_family == OCRDMA_GEN2_FAMILY) && \
  258. (qp->id < 64)) ? 24 : 16)
  259. struct ocrdma_hw_mr {
  260. struct ocrdma_dev *dev;
  261. u32 lkey;
  262. u8 fr_mr;
  263. u8 remote_atomic;
  264. u8 remote_rd;
  265. u8 remote_wr;
  266. u8 local_rd;
  267. u8 local_wr;
  268. u8 mw_bind;
  269. u8 rsvd;
  270. u64 len;
  271. struct ocrdma_pbl *pbl_table;
  272. u32 num_pbls;
  273. u32 num_pbes;
  274. u32 pbl_size;
  275. u32 pbe_size;
  276. u64 fbo;
  277. u64 va;
  278. };
  279. struct ocrdma_mr {
  280. struct ib_mr ibmr;
  281. struct ib_umem *umem;
  282. struct ocrdma_hw_mr hwmr;
  283. struct ocrdma_pd *pd;
  284. };
  285. struct ocrdma_ucontext {
  286. struct ib_ucontext ibucontext;
  287. struct ocrdma_dev *dev;
  288. struct list_head mm_head;
  289. struct mutex mm_list_lock; /* protects list entries of mm type */
  290. struct {
  291. u32 *va;
  292. dma_addr_t pa;
  293. u32 len;
  294. } ah_tbl;
  295. };
  296. struct ocrdma_mm {
  297. struct {
  298. u64 phy_addr;
  299. unsigned long len;
  300. } key;
  301. struct list_head entry;
  302. };
  303. static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
  304. {
  305. return container_of(ibdev, struct ocrdma_dev, ibdev);
  306. }
  307. static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
  308. *ibucontext)
  309. {
  310. return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
  311. }
  312. static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
  313. {
  314. return container_of(ibpd, struct ocrdma_pd, ibpd);
  315. }
  316. static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
  317. {
  318. return container_of(ibcq, struct ocrdma_cq, ibcq);
  319. }
  320. static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
  321. {
  322. return container_of(ibqp, struct ocrdma_qp, ibqp);
  323. }
  324. static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
  325. {
  326. return container_of(ibmr, struct ocrdma_mr, ibmr);
  327. }
  328. static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
  329. {
  330. return container_of(ibah, struct ocrdma_ah, ibah);
  331. }
  332. static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
  333. {
  334. return container_of(ibsrq, struct ocrdma_srq, ibsrq);
  335. }
  336. #endif