qedr.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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 <linux/idr.h>
  36. #include <rdma/ib_addr.h>
  37. #include <linux/qed/qed_if.h>
  38. #include <linux/qed/qed_chain.h>
  39. #include <linux/qed/qed_rdma_if.h>
  40. #include <linux/qed/qede_rdma.h>
  41. #include <linux/qed/roce_common.h>
  42. #include "qedr_hsi_rdma.h"
  43. #define QEDR_NODE_DESC "QLogic 579xx RoCE HCA"
  44. #define DP_NAME(dev) ((dev)->ibdev.name)
  45. #define IS_IWARP(_dev) ((_dev)->rdma_type == QED_RDMA_TYPE_IWARP)
  46. #define IS_ROCE(_dev) ((_dev)->rdma_type == QED_RDMA_TYPE_ROCE)
  47. #define DP_DEBUG(dev, module, fmt, ...) \
  48. pr_debug("(%s) " module ": " fmt, \
  49. DP_NAME(dev) ? DP_NAME(dev) : "", ## __VA_ARGS__)
  50. #define QEDR_MSG_INIT "INIT"
  51. #define QEDR_MSG_MISC "MISC"
  52. #define QEDR_MSG_CQ " CQ"
  53. #define QEDR_MSG_MR " MR"
  54. #define QEDR_MSG_RQ " RQ"
  55. #define QEDR_MSG_SQ " SQ"
  56. #define QEDR_MSG_QP " QP"
  57. #define QEDR_MSG_SRQ " SRQ"
  58. #define QEDR_MSG_GSI " GSI"
  59. #define QEDR_MSG_IWARP " IW"
  60. #define QEDR_CQ_MAGIC_NUMBER (0x11223344)
  61. #define FW_PAGE_SIZE (RDMA_RING_PAGE_SIZE)
  62. #define FW_PAGE_SHIFT (12)
  63. struct qedr_dev;
  64. struct qedr_cnq {
  65. struct qedr_dev *dev;
  66. struct qed_chain pbl;
  67. struct qed_sb_info *sb;
  68. char name[32];
  69. u64 n_comp;
  70. __le16 *hw_cons_ptr;
  71. u8 index;
  72. };
  73. #define QEDR_MAX_SGID 128
  74. struct qedr_device_attr {
  75. u32 vendor_id;
  76. u32 vendor_part_id;
  77. u32 hw_ver;
  78. u64 fw_ver;
  79. u64 node_guid;
  80. u64 sys_image_guid;
  81. u8 max_cnq;
  82. u8 max_sge;
  83. u16 max_inline;
  84. u32 max_sqe;
  85. u32 max_rqe;
  86. u8 max_qp_resp_rd_atomic_resc;
  87. u8 max_qp_req_rd_atomic_resc;
  88. u64 max_dev_resp_rd_atomic_resc;
  89. u32 max_cq;
  90. u32 max_qp;
  91. u32 max_mr;
  92. u64 max_mr_size;
  93. u32 max_cqe;
  94. u32 max_mw;
  95. u32 max_fmr;
  96. u32 max_mr_mw_fmr_pbl;
  97. u64 max_mr_mw_fmr_size;
  98. u32 max_pd;
  99. u32 max_ah;
  100. u8 max_pkey;
  101. u32 max_srq;
  102. u32 max_srq_wr;
  103. u8 max_srq_sge;
  104. u8 max_stats_queues;
  105. u32 dev_caps;
  106. u64 page_size_caps;
  107. u8 dev_ack_delay;
  108. u32 reserved_lkey;
  109. u32 bad_pkey_counter;
  110. struct qed_rdma_events events;
  111. };
  112. #define QEDR_ENET_STATE_BIT (0)
  113. struct qedr_idr {
  114. spinlock_t idr_lock; /* Protect idr data-structure */
  115. struct idr idr;
  116. };
  117. struct qedr_dev {
  118. struct ib_device ibdev;
  119. struct qed_dev *cdev;
  120. struct pci_dev *pdev;
  121. struct net_device *ndev;
  122. enum ib_atomic_cap atomic_cap;
  123. void *rdma_ctx;
  124. struct qedr_device_attr attr;
  125. const struct qed_rdma_ops *ops;
  126. struct qed_int_info int_info;
  127. struct qed_sb_info *sb_array;
  128. struct qedr_cnq *cnq_array;
  129. int num_cnq;
  130. int sb_start;
  131. void __iomem *db_addr;
  132. u64 db_phys_addr;
  133. u32 db_size;
  134. u16 dpi;
  135. union ib_gid *sgid_tbl;
  136. /* Lock for sgid table */
  137. spinlock_t sgid_lock;
  138. u64 guid;
  139. u32 dp_module;
  140. u8 dp_level;
  141. u8 num_hwfns;
  142. u8 gsi_ll2_handle;
  143. uint wq_multiplier;
  144. u8 gsi_ll2_mac_address[ETH_ALEN];
  145. int gsi_qp_created;
  146. struct qedr_cq *gsi_sqcq;
  147. struct qedr_cq *gsi_rqcq;
  148. struct qedr_qp *gsi_qp;
  149. enum qed_rdma_type rdma_type;
  150. struct qedr_idr qpidr;
  151. struct qedr_idr srqidr;
  152. struct workqueue_struct *iwarp_wq;
  153. u16 iwarp_max_mtu;
  154. unsigned long enet_state;
  155. u8 user_dpm_enabled;
  156. };
  157. #define QEDR_MAX_SQ_PBL (0x8000)
  158. #define QEDR_MAX_SQ_PBL_ENTRIES (0x10000 / sizeof(void *))
  159. #define QEDR_SQE_ELEMENT_SIZE (sizeof(struct rdma_sq_sge))
  160. #define QEDR_MAX_SQE_ELEMENTS_PER_SQE (ROCE_REQ_MAX_SINGLE_SQ_WQE_SIZE / \
  161. QEDR_SQE_ELEMENT_SIZE)
  162. #define QEDR_MAX_SQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
  163. QEDR_SQE_ELEMENT_SIZE)
  164. #define QEDR_MAX_SQE ((QEDR_MAX_SQ_PBL_ENTRIES) *\
  165. (RDMA_RING_PAGE_SIZE) / \
  166. (QEDR_SQE_ELEMENT_SIZE) /\
  167. (QEDR_MAX_SQE_ELEMENTS_PER_SQE))
  168. /* RQ */
  169. #define QEDR_MAX_RQ_PBL (0x2000)
  170. #define QEDR_MAX_RQ_PBL_ENTRIES (0x10000 / sizeof(void *))
  171. #define QEDR_RQE_ELEMENT_SIZE (sizeof(struct rdma_rq_sge))
  172. #define QEDR_MAX_RQE_ELEMENTS_PER_RQE (RDMA_MAX_SGE_PER_RQ_WQE)
  173. #define QEDR_MAX_RQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
  174. QEDR_RQE_ELEMENT_SIZE)
  175. #define QEDR_MAX_RQE ((QEDR_MAX_RQ_PBL_ENTRIES) *\
  176. (RDMA_RING_PAGE_SIZE) / \
  177. (QEDR_RQE_ELEMENT_SIZE) /\
  178. (QEDR_MAX_RQE_ELEMENTS_PER_RQE))
  179. #define QEDR_CQE_SIZE (sizeof(union rdma_cqe))
  180. #define QEDR_MAX_CQE_PBL_SIZE (512 * 1024)
  181. #define QEDR_MAX_CQE_PBL_ENTRIES (((QEDR_MAX_CQE_PBL_SIZE) / \
  182. sizeof(u64)) - 1)
  183. #define QEDR_MAX_CQES ((u32)((QEDR_MAX_CQE_PBL_ENTRIES) * \
  184. (QED_CHAIN_PAGE_SIZE) / QEDR_CQE_SIZE))
  185. #define QEDR_ROCE_MAX_CNQ_SIZE (0x4000)
  186. #define QEDR_MAX_PORT (1)
  187. #define QEDR_PORT (1)
  188. #define QEDR_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
  189. #define QEDR_ROCE_PKEY_MAX 1
  190. #define QEDR_ROCE_PKEY_TABLE_LEN 1
  191. #define QEDR_ROCE_PKEY_DEFAULT 0xffff
  192. struct qedr_pbl {
  193. struct list_head list_entry;
  194. void *va;
  195. dma_addr_t pa;
  196. };
  197. struct qedr_ucontext {
  198. struct ib_ucontext ibucontext;
  199. struct qedr_dev *dev;
  200. struct qedr_pd *pd;
  201. u64 dpi_addr;
  202. u64 dpi_phys_addr;
  203. u32 dpi_size;
  204. u16 dpi;
  205. struct list_head mm_head;
  206. /* Lock to protect mm list */
  207. struct mutex mm_list_lock;
  208. };
  209. union db_prod64 {
  210. struct rdma_pwm_val32_data data;
  211. u64 raw;
  212. };
  213. enum qedr_cq_type {
  214. QEDR_CQ_TYPE_GSI,
  215. QEDR_CQ_TYPE_KERNEL,
  216. QEDR_CQ_TYPE_USER,
  217. };
  218. struct qedr_pbl_info {
  219. u32 num_pbls;
  220. u32 num_pbes;
  221. u32 pbl_size;
  222. u32 pbe_size;
  223. bool two_layered;
  224. };
  225. struct qedr_userq {
  226. struct ib_umem *umem;
  227. struct qedr_pbl_info pbl_info;
  228. struct qedr_pbl *pbl_tbl;
  229. u64 buf_addr;
  230. size_t buf_len;
  231. };
  232. struct qedr_cq {
  233. struct ib_cq ibcq;
  234. enum qedr_cq_type cq_type;
  235. u32 sig;
  236. u16 icid;
  237. /* Lock to protect multiplem CQ's */
  238. spinlock_t cq_lock;
  239. u8 arm_flags;
  240. struct qed_chain pbl;
  241. void __iomem *db_addr;
  242. union db_prod64 db;
  243. u8 pbl_toggle;
  244. union rdma_cqe *latest_cqe;
  245. union rdma_cqe *toggle_cqe;
  246. u32 cq_cons;
  247. struct qedr_userq q;
  248. u8 destroyed;
  249. u16 cnq_notif;
  250. };
  251. struct qedr_pd {
  252. struct ib_pd ibpd;
  253. u32 pd_id;
  254. struct qedr_ucontext *uctx;
  255. };
  256. struct qedr_mm {
  257. struct {
  258. u64 phy_addr;
  259. unsigned long len;
  260. } key;
  261. struct list_head entry;
  262. };
  263. union db_prod32 {
  264. struct rdma_pwm_val16_data data;
  265. u32 raw;
  266. };
  267. struct qedr_qp_hwq_info {
  268. /* WQE Elements */
  269. struct qed_chain pbl;
  270. u64 p_phys_addr_tbl;
  271. u32 max_sges;
  272. /* WQE */
  273. u16 prod;
  274. u16 cons;
  275. u16 wqe_cons;
  276. u16 gsi_cons;
  277. u16 max_wr;
  278. /* DB */
  279. void __iomem *db;
  280. union db_prod32 db_data;
  281. void __iomem *iwarp_db2;
  282. union db_prod32 iwarp_db2_data;
  283. };
  284. #define QEDR_INC_SW_IDX(p_info, index) \
  285. do { \
  286. p_info->index = (p_info->index + 1) & \
  287. qed_chain_get_capacity(p_info->pbl) \
  288. } while (0)
  289. struct qedr_srq_hwq_info {
  290. u32 max_sges;
  291. u32 max_wr;
  292. struct qed_chain pbl;
  293. u64 p_phys_addr_tbl;
  294. u32 wqe_prod;
  295. u32 sge_prod;
  296. u32 wr_prod_cnt;
  297. atomic_t wr_cons_cnt;
  298. u32 num_elems;
  299. struct rdma_srq_producers *virt_prod_pair_addr;
  300. dma_addr_t phy_prod_pair_addr;
  301. };
  302. struct qedr_srq {
  303. struct ib_srq ibsrq;
  304. struct qedr_dev *dev;
  305. struct qedr_userq usrq;
  306. struct qedr_srq_hwq_info hw_srq;
  307. struct ib_umem *prod_umem;
  308. u16 srq_id;
  309. u32 srq_limit;
  310. /* lock to protect srq recv post */
  311. spinlock_t lock;
  312. };
  313. enum qedr_qp_err_bitmap {
  314. QEDR_QP_ERR_SQ_FULL = 1,
  315. QEDR_QP_ERR_RQ_FULL = 2,
  316. QEDR_QP_ERR_BAD_SR = 4,
  317. QEDR_QP_ERR_BAD_RR = 8,
  318. QEDR_QP_ERR_SQ_PBL_FULL = 16,
  319. QEDR_QP_ERR_RQ_PBL_FULL = 32,
  320. };
  321. struct qedr_qp {
  322. struct ib_qp ibqp; /* must be first */
  323. struct qedr_dev *dev;
  324. struct qedr_iw_ep *ep;
  325. struct qedr_qp_hwq_info sq;
  326. struct qedr_qp_hwq_info rq;
  327. u32 max_inline_data;
  328. /* Lock for QP's */
  329. spinlock_t q_lock;
  330. struct qedr_cq *sq_cq;
  331. struct qedr_cq *rq_cq;
  332. struct qedr_srq *srq;
  333. enum qed_roce_qp_state state;
  334. u32 id;
  335. struct qedr_pd *pd;
  336. enum ib_qp_type qp_type;
  337. struct qed_rdma_qp *qed_qp;
  338. u32 qp_id;
  339. u16 icid;
  340. u16 mtu;
  341. int sgid_idx;
  342. u32 rq_psn;
  343. u32 sq_psn;
  344. u32 qkey;
  345. u32 dest_qp_num;
  346. /* Relevant to qps created from kernel space only (ULPs) */
  347. u8 prev_wqe_size;
  348. u16 wqe_cons;
  349. u32 err_bitmap;
  350. bool signaled;
  351. /* SQ shadow */
  352. struct {
  353. u64 wr_id;
  354. enum ib_wc_opcode opcode;
  355. u32 bytes_len;
  356. u8 wqe_size;
  357. bool signaled;
  358. dma_addr_t icrc_mapping;
  359. u32 *icrc;
  360. struct qedr_mr *mr;
  361. } *wqe_wr_id;
  362. /* RQ shadow */
  363. struct {
  364. u64 wr_id;
  365. struct ib_sge sg_list[RDMA_MAX_SGE_PER_RQ_WQE];
  366. u8 wqe_size;
  367. u8 smac[ETH_ALEN];
  368. u16 vlan;
  369. int rc;
  370. } *rqe_wr_id;
  371. /* Relevant to qps created from user space only (applications) */
  372. struct qedr_userq usq;
  373. struct qedr_userq urq;
  374. atomic_t refcnt;
  375. bool destroyed;
  376. };
  377. struct qedr_ah {
  378. struct ib_ah ibah;
  379. struct rdma_ah_attr attr;
  380. };
  381. enum qedr_mr_type {
  382. QEDR_MR_USER,
  383. QEDR_MR_KERNEL,
  384. QEDR_MR_DMA,
  385. QEDR_MR_FRMR,
  386. };
  387. struct mr_info {
  388. struct qedr_pbl *pbl_table;
  389. struct qedr_pbl_info pbl_info;
  390. struct list_head free_pbl_list;
  391. struct list_head inuse_pbl_list;
  392. u32 completed;
  393. u32 completed_handled;
  394. };
  395. struct qedr_mr {
  396. struct ib_mr ibmr;
  397. struct ib_umem *umem;
  398. struct qed_rdma_register_tid_in_params hw_mr;
  399. enum qedr_mr_type type;
  400. struct qedr_dev *dev;
  401. struct mr_info info;
  402. u64 *pages;
  403. u32 npages;
  404. };
  405. #define SET_FIELD2(value, name, flag) ((value) |= ((flag) << (name ## _SHIFT)))
  406. #define QEDR_RESP_IMM (RDMA_CQE_RESPONDER_IMM_FLG_MASK << \
  407. RDMA_CQE_RESPONDER_IMM_FLG_SHIFT)
  408. #define QEDR_RESP_RDMA (RDMA_CQE_RESPONDER_RDMA_FLG_MASK << \
  409. RDMA_CQE_RESPONDER_RDMA_FLG_SHIFT)
  410. #define QEDR_RESP_INV (RDMA_CQE_RESPONDER_INV_FLG_MASK << \
  411. RDMA_CQE_RESPONDER_INV_FLG_SHIFT)
  412. static inline void qedr_inc_sw_cons(struct qedr_qp_hwq_info *info)
  413. {
  414. info->cons = (info->cons + 1) % info->max_wr;
  415. info->wqe_cons++;
  416. }
  417. static inline void qedr_inc_sw_prod(struct qedr_qp_hwq_info *info)
  418. {
  419. info->prod = (info->prod + 1) % info->max_wr;
  420. }
  421. static inline int qedr_get_dmac(struct qedr_dev *dev,
  422. struct rdma_ah_attr *ah_attr, u8 *mac_addr)
  423. {
  424. union ib_gid zero_sgid = { { 0 } };
  425. struct in6_addr in6;
  426. const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
  427. u8 *dmac;
  428. if (!memcmp(&grh->dgid, &zero_sgid, sizeof(union ib_gid))) {
  429. DP_ERR(dev, "Local port GID not supported\n");
  430. eth_zero_addr(mac_addr);
  431. return -EINVAL;
  432. }
  433. memcpy(&in6, grh->dgid.raw, sizeof(in6));
  434. dmac = rdma_ah_retrieve_dmac(ah_attr);
  435. if (!dmac)
  436. return -EINVAL;
  437. ether_addr_copy(mac_addr, dmac);
  438. return 0;
  439. }
  440. struct qedr_iw_listener {
  441. struct qedr_dev *dev;
  442. struct iw_cm_id *cm_id;
  443. int backlog;
  444. void *qed_handle;
  445. };
  446. struct qedr_iw_ep {
  447. struct qedr_dev *dev;
  448. struct iw_cm_id *cm_id;
  449. struct qedr_qp *qp;
  450. void *qed_context;
  451. u8 during_connect;
  452. };
  453. static inline
  454. struct qedr_ucontext *get_qedr_ucontext(struct ib_ucontext *ibucontext)
  455. {
  456. return container_of(ibucontext, struct qedr_ucontext, ibucontext);
  457. }
  458. static inline struct qedr_dev *get_qedr_dev(struct ib_device *ibdev)
  459. {
  460. return container_of(ibdev, struct qedr_dev, ibdev);
  461. }
  462. static inline struct qedr_pd *get_qedr_pd(struct ib_pd *ibpd)
  463. {
  464. return container_of(ibpd, struct qedr_pd, ibpd);
  465. }
  466. static inline struct qedr_cq *get_qedr_cq(struct ib_cq *ibcq)
  467. {
  468. return container_of(ibcq, struct qedr_cq, ibcq);
  469. }
  470. static inline struct qedr_qp *get_qedr_qp(struct ib_qp *ibqp)
  471. {
  472. return container_of(ibqp, struct qedr_qp, ibqp);
  473. }
  474. static inline struct qedr_ah *get_qedr_ah(struct ib_ah *ibah)
  475. {
  476. return container_of(ibah, struct qedr_ah, ibah);
  477. }
  478. static inline struct qedr_mr *get_qedr_mr(struct ib_mr *ibmr)
  479. {
  480. return container_of(ibmr, struct qedr_mr, ibmr);
  481. }
  482. static inline struct qedr_srq *get_qedr_srq(struct ib_srq *ibsrq)
  483. {
  484. return container_of(ibsrq, struct qedr_srq, ibsrq);
  485. }
  486. #endif