qedr.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /* QLogic qedr NIC Driver
  2. * Copyright (c) 2015-2016 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef __QEDR_H__
  33. #define __QEDR_H__
  34. #include <linux/pci.h>
  35. #include <rdma/ib_addr.h>
  36. #include <linux/qed/qed_if.h>
  37. #include <linux/qed/qed_chain.h>
  38. #include <linux/qed/qed_roce_if.h>
  39. #include <linux/qed/qede_roce.h>
  40. #include "qedr_hsi.h"
  41. #define QEDR_MODULE_VERSION "8.10.10.0"
  42. #define QEDR_NODE_DESC "QLogic 579xx RoCE HCA"
  43. #define DP_NAME(dev) ((dev)->ibdev.name)
  44. #define DP_DEBUG(dev, module, fmt, ...) \
  45. pr_debug("(%s) " module ": " fmt, \
  46. DP_NAME(dev) ? DP_NAME(dev) : "", ## __VA_ARGS__)
  47. #define QEDR_MSG_INIT "INIT"
  48. #define QEDR_MSG_MISC "MISC"
  49. #define QEDR_MSG_CQ " CQ"
  50. #define QEDR_MSG_MR " MR"
  51. #define QEDR_MSG_RQ " RQ"
  52. #define QEDR_MSG_SQ " SQ"
  53. #define QEDR_MSG_QP " QP"
  54. #define QEDR_MSG_GSI " GSI"
  55. #define QEDR_CQ_MAGIC_NUMBER (0x11223344)
  56. struct qedr_dev;
  57. struct qedr_cnq {
  58. struct qedr_dev *dev;
  59. struct qed_chain pbl;
  60. struct qed_sb_info *sb;
  61. char name[32];
  62. u64 n_comp;
  63. __le16 *hw_cons_ptr;
  64. u8 index;
  65. };
  66. #define QEDR_MAX_SGID 128
  67. struct qedr_device_attr {
  68. u32 vendor_id;
  69. u32 vendor_part_id;
  70. u32 hw_ver;
  71. u64 fw_ver;
  72. u64 node_guid;
  73. u64 sys_image_guid;
  74. u8 max_cnq;
  75. u8 max_sge;
  76. u16 max_inline;
  77. u32 max_sqe;
  78. u32 max_rqe;
  79. u8 max_qp_resp_rd_atomic_resc;
  80. u8 max_qp_req_rd_atomic_resc;
  81. u64 max_dev_resp_rd_atomic_resc;
  82. u32 max_cq;
  83. u32 max_qp;
  84. u32 max_mr;
  85. u64 max_mr_size;
  86. u32 max_cqe;
  87. u32 max_mw;
  88. u32 max_fmr;
  89. u32 max_mr_mw_fmr_pbl;
  90. u64 max_mr_mw_fmr_size;
  91. u32 max_pd;
  92. u32 max_ah;
  93. u8 max_pkey;
  94. u32 max_srq;
  95. u32 max_srq_wr;
  96. u8 max_srq_sge;
  97. u8 max_stats_queues;
  98. u32 dev_caps;
  99. u64 page_size_caps;
  100. u8 dev_ack_delay;
  101. u32 reserved_lkey;
  102. u32 bad_pkey_counter;
  103. struct qed_rdma_events events;
  104. };
  105. struct qedr_dev {
  106. struct ib_device ibdev;
  107. struct qed_dev *cdev;
  108. struct pci_dev *pdev;
  109. struct net_device *ndev;
  110. enum ib_atomic_cap atomic_cap;
  111. void *rdma_ctx;
  112. struct qedr_device_attr attr;
  113. const struct qed_rdma_ops *ops;
  114. struct qed_int_info int_info;
  115. struct qed_sb_info *sb_array;
  116. struct qedr_cnq *cnq_array;
  117. int num_cnq;
  118. int sb_start;
  119. void __iomem *db_addr;
  120. u64 db_phys_addr;
  121. u32 db_size;
  122. u16 dpi;
  123. union ib_gid *sgid_tbl;
  124. /* Lock for sgid table */
  125. spinlock_t sgid_lock;
  126. u64 guid;
  127. u32 dp_module;
  128. u8 dp_level;
  129. u8 num_hwfns;
  130. uint wq_multiplier;
  131. u8 gsi_ll2_mac_address[ETH_ALEN];
  132. int gsi_qp_created;
  133. struct qedr_cq *gsi_sqcq;
  134. struct qedr_cq *gsi_rqcq;
  135. struct qedr_qp *gsi_qp;
  136. };
  137. #define QEDR_MAX_SQ_PBL (0x8000)
  138. #define QEDR_MAX_SQ_PBL_ENTRIES (0x10000 / sizeof(void *))
  139. #define QEDR_SQE_ELEMENT_SIZE (sizeof(struct rdma_sq_sge))
  140. #define QEDR_MAX_SQE_ELEMENTS_PER_SQE (ROCE_REQ_MAX_SINGLE_SQ_WQE_SIZE / \
  141. QEDR_SQE_ELEMENT_SIZE)
  142. #define QEDR_MAX_SQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
  143. QEDR_SQE_ELEMENT_SIZE)
  144. #define QEDR_MAX_SQE ((QEDR_MAX_SQ_PBL_ENTRIES) *\
  145. (RDMA_RING_PAGE_SIZE) / \
  146. (QEDR_SQE_ELEMENT_SIZE) /\
  147. (QEDR_MAX_SQE_ELEMENTS_PER_SQE))
  148. /* RQ */
  149. #define QEDR_MAX_RQ_PBL (0x2000)
  150. #define QEDR_MAX_RQ_PBL_ENTRIES (0x10000 / sizeof(void *))
  151. #define QEDR_RQE_ELEMENT_SIZE (sizeof(struct rdma_rq_sge))
  152. #define QEDR_MAX_RQE_ELEMENTS_PER_RQE (RDMA_MAX_SGE_PER_RQ_WQE)
  153. #define QEDR_MAX_RQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
  154. QEDR_RQE_ELEMENT_SIZE)
  155. #define QEDR_MAX_RQE ((QEDR_MAX_RQ_PBL_ENTRIES) *\
  156. (RDMA_RING_PAGE_SIZE) / \
  157. (QEDR_RQE_ELEMENT_SIZE) /\
  158. (QEDR_MAX_RQE_ELEMENTS_PER_RQE))
  159. #define QEDR_CQE_SIZE (sizeof(union rdma_cqe))
  160. #define QEDR_MAX_CQE_PBL_SIZE (512 * 1024)
  161. #define QEDR_MAX_CQE_PBL_ENTRIES (((QEDR_MAX_CQE_PBL_SIZE) / \
  162. sizeof(u64)) - 1)
  163. #define QEDR_MAX_CQES ((u32)((QEDR_MAX_CQE_PBL_ENTRIES) * \
  164. (QED_CHAIN_PAGE_SIZE) / QEDR_CQE_SIZE))
  165. #define QEDR_ROCE_MAX_CNQ_SIZE (0x4000)
  166. #define QEDR_MAX_PORT (1)
  167. #define QEDR_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  168. #define QEDR_ROCE_PKEY_MAX 1
  169. #define QEDR_ROCE_PKEY_TABLE_LEN 1
  170. #define QEDR_ROCE_PKEY_DEFAULT 0xffff
  171. struct qedr_pbl {
  172. struct list_head list_entry;
  173. void *va;
  174. dma_addr_t pa;
  175. };
  176. struct qedr_ucontext {
  177. struct ib_ucontext ibucontext;
  178. struct qedr_dev *dev;
  179. struct qedr_pd *pd;
  180. u64 dpi_addr;
  181. u64 dpi_phys_addr;
  182. u32 dpi_size;
  183. u16 dpi;
  184. struct list_head mm_head;
  185. /* Lock to protect mm list */
  186. struct mutex mm_list_lock;
  187. };
  188. union db_prod64 {
  189. struct rdma_pwm_val32_data data;
  190. u64 raw;
  191. };
  192. enum qedr_cq_type {
  193. QEDR_CQ_TYPE_GSI,
  194. QEDR_CQ_TYPE_KERNEL,
  195. QEDR_CQ_TYPE_USER,
  196. };
  197. struct qedr_pbl_info {
  198. u32 num_pbls;
  199. u32 num_pbes;
  200. u32 pbl_size;
  201. u32 pbe_size;
  202. bool two_layered;
  203. };
  204. struct qedr_userq {
  205. struct ib_umem *umem;
  206. struct qedr_pbl_info pbl_info;
  207. struct qedr_pbl *pbl_tbl;
  208. u64 buf_addr;
  209. size_t buf_len;
  210. };
  211. struct qedr_cq {
  212. struct ib_cq ibcq;
  213. enum qedr_cq_type cq_type;
  214. u32 sig;
  215. u16 icid;
  216. /* Lock to protect completion handler */
  217. spinlock_t comp_handler_lock;
  218. /* Lock to protect multiplem CQ's */
  219. spinlock_t cq_lock;
  220. u8 arm_flags;
  221. struct qed_chain pbl;
  222. void __iomem *db_addr;
  223. union db_prod64 db;
  224. u8 pbl_toggle;
  225. union rdma_cqe *latest_cqe;
  226. union rdma_cqe *toggle_cqe;
  227. u32 cq_cons;
  228. struct qedr_userq q;
  229. };
  230. struct qedr_pd {
  231. struct ib_pd ibpd;
  232. u32 pd_id;
  233. struct qedr_ucontext *uctx;
  234. };
  235. struct qedr_mm {
  236. struct {
  237. u64 phy_addr;
  238. unsigned long len;
  239. } key;
  240. struct list_head entry;
  241. };
  242. union db_prod32 {
  243. struct rdma_pwm_val16_data data;
  244. u32 raw;
  245. };
  246. struct qedr_qp_hwq_info {
  247. /* WQE Elements */
  248. struct qed_chain pbl;
  249. u64 p_phys_addr_tbl;
  250. u32 max_sges;
  251. /* WQE */
  252. u16 prod;
  253. u16 cons;
  254. u16 wqe_cons;
  255. u16 gsi_cons;
  256. u16 max_wr;
  257. /* DB */
  258. void __iomem *db;
  259. union db_prod32 db_data;
  260. };
  261. #define QEDR_INC_SW_IDX(p_info, index) \
  262. do { \
  263. p_info->index = (p_info->index + 1) & \
  264. qed_chain_get_capacity(p_info->pbl) \
  265. } while (0)
  266. enum qedr_qp_err_bitmap {
  267. QEDR_QP_ERR_SQ_FULL = 1,
  268. QEDR_QP_ERR_RQ_FULL = 2,
  269. QEDR_QP_ERR_BAD_SR = 4,
  270. QEDR_QP_ERR_BAD_RR = 8,
  271. QEDR_QP_ERR_SQ_PBL_FULL = 16,
  272. QEDR_QP_ERR_RQ_PBL_FULL = 32,
  273. };
  274. struct qedr_qp {
  275. struct ib_qp ibqp; /* must be first */
  276. struct qedr_dev *dev;
  277. struct qedr_qp_hwq_info sq;
  278. struct qedr_qp_hwq_info rq;
  279. u32 max_inline_data;
  280. /* Lock for QP's */
  281. spinlock_t q_lock;
  282. struct qedr_cq *sq_cq;
  283. struct qedr_cq *rq_cq;
  284. struct qedr_srq *srq;
  285. enum qed_roce_qp_state state;
  286. u32 id;
  287. struct qedr_pd *pd;
  288. enum ib_qp_type qp_type;
  289. struct qed_rdma_qp *qed_qp;
  290. u32 qp_id;
  291. u16 icid;
  292. u16 mtu;
  293. int sgid_idx;
  294. u32 rq_psn;
  295. u32 sq_psn;
  296. u32 qkey;
  297. u32 dest_qp_num;
  298. /* Relevant to qps created from kernel space only (ULPs) */
  299. u8 prev_wqe_size;
  300. u16 wqe_cons;
  301. u32 err_bitmap;
  302. bool signaled;
  303. /* SQ shadow */
  304. struct {
  305. u64 wr_id;
  306. enum ib_wc_opcode opcode;
  307. u32 bytes_len;
  308. u8 wqe_size;
  309. bool signaled;
  310. dma_addr_t icrc_mapping;
  311. u32 *icrc;
  312. struct qedr_mr *mr;
  313. } *wqe_wr_id;
  314. /* RQ shadow */
  315. struct {
  316. u64 wr_id;
  317. struct ib_sge sg_list[RDMA_MAX_SGE_PER_RQ_WQE];
  318. u8 wqe_size;
  319. u8 smac[ETH_ALEN];
  320. u16 vlan_id;
  321. int rc;
  322. } *rqe_wr_id;
  323. /* Relevant to qps created from user space only (applications) */
  324. struct qedr_userq usq;
  325. struct qedr_userq urq;
  326. };
  327. struct qedr_ah {
  328. struct ib_ah ibah;
  329. struct ib_ah_attr attr;
  330. };
  331. enum qedr_mr_type {
  332. QEDR_MR_USER,
  333. QEDR_MR_KERNEL,
  334. QEDR_MR_DMA,
  335. QEDR_MR_FRMR,
  336. };
  337. struct mr_info {
  338. struct qedr_pbl *pbl_table;
  339. struct qedr_pbl_info pbl_info;
  340. struct list_head free_pbl_list;
  341. struct list_head inuse_pbl_list;
  342. u32 completed;
  343. u32 completed_handled;
  344. };
  345. struct qedr_mr {
  346. struct ib_mr ibmr;
  347. struct ib_umem *umem;
  348. struct qed_rdma_register_tid_in_params hw_mr;
  349. enum qedr_mr_type type;
  350. struct qedr_dev *dev;
  351. struct mr_info info;
  352. u64 *pages;
  353. u32 npages;
  354. };
  355. #define SET_FIELD2(value, name, flag) ((value) |= ((flag) << (name ## _SHIFT)))
  356. #define QEDR_RESP_IMM (RDMA_CQE_RESPONDER_IMM_FLG_MASK << \
  357. RDMA_CQE_RESPONDER_IMM_FLG_SHIFT)
  358. #define QEDR_RESP_RDMA (RDMA_CQE_RESPONDER_RDMA_FLG_MASK << \
  359. RDMA_CQE_RESPONDER_RDMA_FLG_SHIFT)
  360. #define QEDR_RESP_RDMA_IMM (QEDR_RESP_IMM | QEDR_RESP_RDMA)
  361. static inline void qedr_inc_sw_cons(struct qedr_qp_hwq_info *info)
  362. {
  363. info->cons = (info->cons + 1) % info->max_wr;
  364. info->wqe_cons++;
  365. }
  366. static inline void qedr_inc_sw_prod(struct qedr_qp_hwq_info *info)
  367. {
  368. info->prod = (info->prod + 1) % info->max_wr;
  369. }
  370. static inline int qedr_get_dmac(struct qedr_dev *dev,
  371. struct ib_ah_attr *ah_attr, u8 *mac_addr)
  372. {
  373. union ib_gid zero_sgid = { { 0 } };
  374. struct in6_addr in6;
  375. if (!memcmp(&ah_attr->grh.dgid, &zero_sgid, sizeof(union ib_gid))) {
  376. DP_ERR(dev, "Local port GID not supported\n");
  377. eth_zero_addr(mac_addr);
  378. return -EINVAL;
  379. }
  380. memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
  381. ether_addr_copy(mac_addr, ah_attr->dmac);
  382. return 0;
  383. }
  384. static inline
  385. struct qedr_ucontext *get_qedr_ucontext(struct ib_ucontext *ibucontext)
  386. {
  387. return container_of(ibucontext, struct qedr_ucontext, ibucontext);
  388. }
  389. static inline struct qedr_dev *get_qedr_dev(struct ib_device *ibdev)
  390. {
  391. return container_of(ibdev, struct qedr_dev, ibdev);
  392. }
  393. static inline struct qedr_pd *get_qedr_pd(struct ib_pd *ibpd)
  394. {
  395. return container_of(ibpd, struct qedr_pd, ibpd);
  396. }
  397. static inline struct qedr_cq *get_qedr_cq(struct ib_cq *ibcq)
  398. {
  399. return container_of(ibcq, struct qedr_cq, ibcq);
  400. }
  401. static inline struct qedr_qp *get_qedr_qp(struct ib_qp *ibqp)
  402. {
  403. return container_of(ibqp, struct qedr_qp, ibqp);
  404. }
  405. static inline struct qedr_ah *get_qedr_ah(struct ib_ah *ibah)
  406. {
  407. return container_of(ibah, struct qedr_ah, ibah);
  408. }
  409. static inline struct qedr_mr *get_qedr_mr(struct ib_mr *ibmr)
  410. {
  411. return container_of(ibmr, struct qedr_mr, ibmr);
  412. }
  413. #endif