qplib_fp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * Broadcom NetXtreme-E RoCE driver.
  3. *
  4. * Copyright (c) 2016 - 2017, Broadcom. All rights reserved. The term
  5. * Broadcom refers to Broadcom Limited and/or its subsidiaries.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in
  21. * the documentation and/or other materials provided with the
  22. * distribution.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
  28. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  31. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  33. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  34. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * Description: Fast Path Operators (header)
  37. */
  38. #ifndef __BNXT_QPLIB_FP_H__
  39. #define __BNXT_QPLIB_FP_H__
  40. struct bnxt_qplib_sge {
  41. u64 addr;
  42. u32 lkey;
  43. u32 size;
  44. };
  45. #define BNXT_QPLIB_MAX_SQE_ENTRY_SIZE sizeof(struct sq_send)
  46. #define SQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_MAX_SQE_ENTRY_SIZE)
  47. #define SQE_MAX_IDX_PER_PG (SQE_CNT_PER_PG - 1)
  48. static inline u32 get_sqe_pg(u32 val)
  49. {
  50. return ((val & ~SQE_MAX_IDX_PER_PG) / SQE_CNT_PER_PG);
  51. }
  52. static inline u32 get_sqe_idx(u32 val)
  53. {
  54. return (val & SQE_MAX_IDX_PER_PG);
  55. }
  56. #define BNXT_QPLIB_MAX_PSNE_ENTRY_SIZE sizeof(struct sq_psn_search)
  57. #define PSNE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_MAX_PSNE_ENTRY_SIZE)
  58. #define PSNE_MAX_IDX_PER_PG (PSNE_CNT_PER_PG - 1)
  59. static inline u32 get_psne_pg(u32 val)
  60. {
  61. return ((val & ~PSNE_MAX_IDX_PER_PG) / PSNE_CNT_PER_PG);
  62. }
  63. static inline u32 get_psne_idx(u32 val)
  64. {
  65. return (val & PSNE_MAX_IDX_PER_PG);
  66. }
  67. #define BNXT_QPLIB_QP_MAX_SGL 6
  68. struct bnxt_qplib_swq {
  69. u64 wr_id;
  70. u8 type;
  71. u8 flags;
  72. u32 start_psn;
  73. u32 next_psn;
  74. struct sq_psn_search *psn_search;
  75. };
  76. struct bnxt_qplib_swqe {
  77. /* General */
  78. u64 wr_id;
  79. u8 reqs_type;
  80. u8 type;
  81. #define BNXT_QPLIB_SWQE_TYPE_SEND 0
  82. #define BNXT_QPLIB_SWQE_TYPE_SEND_WITH_IMM 1
  83. #define BNXT_QPLIB_SWQE_TYPE_SEND_WITH_INV 2
  84. #define BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE 4
  85. #define BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE_WITH_IMM 5
  86. #define BNXT_QPLIB_SWQE_TYPE_RDMA_READ 6
  87. #define BNXT_QPLIB_SWQE_TYPE_ATOMIC_CMP_AND_SWP 8
  88. #define BNXT_QPLIB_SWQE_TYPE_ATOMIC_FETCH_AND_ADD 11
  89. #define BNXT_QPLIB_SWQE_TYPE_LOCAL_INV 12
  90. #define BNXT_QPLIB_SWQE_TYPE_FAST_REG_MR 13
  91. #define BNXT_QPLIB_SWQE_TYPE_REG_MR 13
  92. #define BNXT_QPLIB_SWQE_TYPE_BIND_MW 14
  93. #define BNXT_QPLIB_SWQE_TYPE_RECV 128
  94. #define BNXT_QPLIB_SWQE_TYPE_RECV_RDMA_IMM 129
  95. u8 flags;
  96. #define BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP BIT(0)
  97. #define BNXT_QPLIB_SWQE_FLAGS_RD_ATOMIC_FENCE BIT(1)
  98. #define BNXT_QPLIB_SWQE_FLAGS_UC_FENCE BIT(2)
  99. #define BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT BIT(3)
  100. #define BNXT_QPLIB_SWQE_FLAGS_INLINE BIT(4)
  101. struct bnxt_qplib_sge sg_list[BNXT_QPLIB_QP_MAX_SGL];
  102. int num_sge;
  103. /* Max inline data is 96 bytes */
  104. u32 inline_len;
  105. #define BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH 96
  106. u8 inline_data[BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH];
  107. union {
  108. /* Send, with imm, inval key */
  109. struct {
  110. union {
  111. __be32 imm_data;
  112. u32 inv_key;
  113. };
  114. u32 q_key;
  115. u32 dst_qp;
  116. u16 avid;
  117. } send;
  118. /* Send Raw Ethernet and QP1 */
  119. struct {
  120. u16 lflags;
  121. u16 cfa_action;
  122. u32 cfa_meta;
  123. } rawqp1;
  124. /* RDMA write, with imm, read */
  125. struct {
  126. union {
  127. __be32 imm_data;
  128. u32 inv_key;
  129. };
  130. u64 remote_va;
  131. u32 r_key;
  132. } rdma;
  133. /* Atomic cmp/swap, fetch/add */
  134. struct {
  135. u64 remote_va;
  136. u32 r_key;
  137. u64 swap_data;
  138. u64 cmp_data;
  139. } atomic;
  140. /* Local Invalidate */
  141. struct {
  142. u32 inv_l_key;
  143. } local_inv;
  144. /* FR-PMR */
  145. struct {
  146. u8 access_cntl;
  147. u8 pg_sz_log;
  148. bool zero_based;
  149. u32 l_key;
  150. u32 length;
  151. u8 pbl_pg_sz_log;
  152. #define BNXT_QPLIB_SWQE_PAGE_SIZE_4K 0
  153. #define BNXT_QPLIB_SWQE_PAGE_SIZE_8K 1
  154. #define BNXT_QPLIB_SWQE_PAGE_SIZE_64K 4
  155. #define BNXT_QPLIB_SWQE_PAGE_SIZE_256K 6
  156. #define BNXT_QPLIB_SWQE_PAGE_SIZE_1M 8
  157. #define BNXT_QPLIB_SWQE_PAGE_SIZE_2M 9
  158. #define BNXT_QPLIB_SWQE_PAGE_SIZE_4M 10
  159. #define BNXT_QPLIB_SWQE_PAGE_SIZE_1G 18
  160. u8 levels;
  161. #define PAGE_SHIFT_4K 12
  162. __le64 *pbl_ptr;
  163. dma_addr_t pbl_dma_ptr;
  164. u64 *page_list;
  165. u16 page_list_len;
  166. u64 va;
  167. } frmr;
  168. /* Bind */
  169. struct {
  170. u8 access_cntl;
  171. #define BNXT_QPLIB_BIND_SWQE_ACCESS_LOCAL_WRITE BIT(0)
  172. #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_READ BIT(1)
  173. #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_WRITE BIT(2)
  174. #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_ATOMIC BIT(3)
  175. #define BNXT_QPLIB_BIND_SWQE_ACCESS_WINDOW_BIND BIT(4)
  176. bool zero_based;
  177. u8 mw_type;
  178. u32 parent_l_key;
  179. u32 r_key;
  180. u64 va;
  181. u32 length;
  182. } bind;
  183. };
  184. };
  185. #define BNXT_QPLIB_MAX_RQE_ENTRY_SIZE sizeof(struct rq_wqe)
  186. #define RQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_MAX_RQE_ENTRY_SIZE)
  187. #define RQE_MAX_IDX_PER_PG (RQE_CNT_PER_PG - 1)
  188. #define RQE_PG(x) (((x) & ~RQE_MAX_IDX_PER_PG) / RQE_CNT_PER_PG)
  189. #define RQE_IDX(x) ((x) & RQE_MAX_IDX_PER_PG)
  190. struct bnxt_qplib_q {
  191. struct bnxt_qplib_hwq hwq;
  192. struct bnxt_qplib_swq *swq;
  193. struct scatterlist *sglist;
  194. u32 nmap;
  195. u32 max_wqe;
  196. u16 max_sge;
  197. u32 psn;
  198. bool flush_in_progress;
  199. };
  200. struct bnxt_qplib_qp {
  201. struct bnxt_qplib_pd *pd;
  202. struct bnxt_qplib_dpi *dpi;
  203. u64 qp_handle;
  204. u32 id;
  205. u8 type;
  206. u8 sig_type;
  207. u32 modify_flags;
  208. u8 state;
  209. u8 cur_qp_state;
  210. u32 max_inline_data;
  211. u32 mtu;
  212. u8 path_mtu;
  213. bool en_sqd_async_notify;
  214. u16 pkey_index;
  215. u32 qkey;
  216. u32 dest_qp_id;
  217. u8 access;
  218. u8 timeout;
  219. u8 retry_cnt;
  220. u8 rnr_retry;
  221. u32 min_rnr_timer;
  222. u32 max_rd_atomic;
  223. u32 max_dest_rd_atomic;
  224. u32 dest_qpn;
  225. u8 smac[6];
  226. u16 vlan_id;
  227. u8 nw_type;
  228. struct bnxt_qplib_ah ah;
  229. #define BTH_PSN_MASK ((1 << 24) - 1)
  230. /* SQ */
  231. struct bnxt_qplib_q sq;
  232. /* RQ */
  233. struct bnxt_qplib_q rq;
  234. /* SRQ */
  235. struct bnxt_qplib_srq *srq;
  236. /* CQ */
  237. struct bnxt_qplib_cq *scq;
  238. struct bnxt_qplib_cq *rcq;
  239. /* IRRQ and ORRQ */
  240. struct bnxt_qplib_hwq irrq;
  241. struct bnxt_qplib_hwq orrq;
  242. /* Header buffer for QP1 */
  243. int sq_hdr_buf_size;
  244. int rq_hdr_buf_size;
  245. /*
  246. * Buffer space for ETH(14), IP or GRH(40), UDP header(8)
  247. * and ib_bth + ib_deth (20).
  248. * Max required is 82 when RoCE V2 is enabled
  249. */
  250. #define BNXT_QPLIB_MAX_QP1_SQ_HDR_SIZE_V2 86
  251. /* Ethernet header = 14 */
  252. /* ib_grh = 40 (provided by MAD) */
  253. /* ib_bth + ib_deth = 20 */
  254. /* MAD = 256 (provided by MAD) */
  255. /* iCRC = 4 */
  256. #define BNXT_QPLIB_MAX_QP1_RQ_ETH_HDR_SIZE 14
  257. #define BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2 512
  258. #define BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV4 20
  259. #define BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV6 40
  260. #define BNXT_QPLIB_MAX_QP1_RQ_BDETH_HDR_SIZE 20
  261. void *sq_hdr_buf;
  262. dma_addr_t sq_hdr_buf_map;
  263. void *rq_hdr_buf;
  264. dma_addr_t rq_hdr_buf_map;
  265. };
  266. #define BNXT_QPLIB_MAX_CQE_ENTRY_SIZE sizeof(struct cq_base)
  267. #define CQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_MAX_CQE_ENTRY_SIZE)
  268. #define CQE_MAX_IDX_PER_PG (CQE_CNT_PER_PG - 1)
  269. #define CQE_PG(x) (((x) & ~CQE_MAX_IDX_PER_PG) / CQE_CNT_PER_PG)
  270. #define CQE_IDX(x) ((x) & CQE_MAX_IDX_PER_PG)
  271. #define ROCE_CQE_CMP_V 0
  272. #define CQE_CMP_VALID(hdr, raw_cons, cp_bit) \
  273. (!!((hdr)->cqe_type_toggle & CQ_BASE_TOGGLE) == \
  274. !((raw_cons) & (cp_bit)))
  275. struct bnxt_qplib_cqe {
  276. u8 status;
  277. u8 type;
  278. u8 opcode;
  279. u32 length;
  280. u64 wr_id;
  281. union {
  282. __be32 immdata;
  283. u32 invrkey;
  284. };
  285. u64 qp_handle;
  286. u64 mr_handle;
  287. u16 flags;
  288. u8 smac[6];
  289. u32 src_qp;
  290. u16 raweth_qp1_flags;
  291. u16 raweth_qp1_errors;
  292. u16 raweth_qp1_cfa_code;
  293. u32 raweth_qp1_flags2;
  294. u32 raweth_qp1_metadata;
  295. u8 raweth_qp1_payload_offset;
  296. u16 pkey_index;
  297. };
  298. #define BNXT_QPLIB_QUEUE_START_PERIOD 0x01
  299. struct bnxt_qplib_cq {
  300. struct bnxt_qplib_dpi *dpi;
  301. void __iomem *dbr_base;
  302. u32 max_wqe;
  303. u32 id;
  304. u16 count;
  305. u16 period;
  306. struct bnxt_qplib_hwq hwq;
  307. u32 cnq_hw_ring_id;
  308. bool resize_in_progress;
  309. struct scatterlist *sghead;
  310. u32 nmap;
  311. u64 cq_handle;
  312. #define CQ_RESIZE_WAIT_TIME_MS 500
  313. unsigned long flags;
  314. #define CQ_FLAGS_RESIZE_IN_PROG 1
  315. wait_queue_head_t waitq;
  316. };
  317. #define BNXT_QPLIB_MAX_IRRQE_ENTRY_SIZE sizeof(struct xrrq_irrq)
  318. #define BNXT_QPLIB_MAX_ORRQE_ENTRY_SIZE sizeof(struct xrrq_orrq)
  319. #define IRD_LIMIT_TO_IRRQ_SLOTS(x) (2 * (x) + 2)
  320. #define IRRQ_SLOTS_TO_IRD_LIMIT(s) (((s) >> 1) - 1)
  321. #define ORD_LIMIT_TO_ORRQ_SLOTS(x) ((x) + 1)
  322. #define ORRQ_SLOTS_TO_ORD_LIMIT(s) ((s) - 1)
  323. #define BNXT_QPLIB_MAX_NQE_ENTRY_SIZE sizeof(struct nq_base)
  324. #define NQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_MAX_NQE_ENTRY_SIZE)
  325. #define NQE_MAX_IDX_PER_PG (NQE_CNT_PER_PG - 1)
  326. #define NQE_PG(x) (((x) & ~NQE_MAX_IDX_PER_PG) / NQE_CNT_PER_PG)
  327. #define NQE_IDX(x) ((x) & NQE_MAX_IDX_PER_PG)
  328. #define NQE_CMP_VALID(hdr, raw_cons, cp_bit) \
  329. (!!(le32_to_cpu((hdr)->info63_v[0]) & NQ_BASE_V) == \
  330. !((raw_cons) & (cp_bit)))
  331. #define BNXT_QPLIB_NQE_MAX_CNT (128 * 1024)
  332. #define NQ_CONS_PCI_BAR_REGION 2
  333. #define NQ_DB_KEY_CP (0x2 << CMPL_DOORBELL_KEY_SFT)
  334. #define NQ_DB_IDX_VALID CMPL_DOORBELL_IDX_VALID
  335. #define NQ_DB_IRQ_DIS CMPL_DOORBELL_MASK
  336. #define NQ_DB_CP_FLAGS_REARM (NQ_DB_KEY_CP | \
  337. NQ_DB_IDX_VALID)
  338. #define NQ_DB_CP_FLAGS (NQ_DB_KEY_CP | \
  339. NQ_DB_IDX_VALID | \
  340. NQ_DB_IRQ_DIS)
  341. #define NQ_DB_REARM(db, raw_cons, cp_bit) \
  342. writel(NQ_DB_CP_FLAGS_REARM | ((raw_cons) & ((cp_bit) - 1)), db)
  343. #define NQ_DB(db, raw_cons, cp_bit) \
  344. writel(NQ_DB_CP_FLAGS | ((raw_cons) & ((cp_bit) - 1)), db)
  345. struct bnxt_qplib_nq {
  346. struct pci_dev *pdev;
  347. int vector;
  348. int budget;
  349. bool requested;
  350. struct tasklet_struct worker;
  351. struct bnxt_qplib_hwq hwq;
  352. u16 bar_reg;
  353. u16 bar_reg_off;
  354. u16 ring_id;
  355. void __iomem *bar_reg_iomem;
  356. int (*cqn_handler)
  357. (struct bnxt_qplib_nq *nq,
  358. struct bnxt_qplib_cq *cq);
  359. int (*srqn_handler)
  360. (struct bnxt_qplib_nq *nq,
  361. void *srq,
  362. u8 event);
  363. };
  364. void bnxt_qplib_disable_nq(struct bnxt_qplib_nq *nq);
  365. int bnxt_qplib_enable_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq,
  366. int msix_vector, int bar_reg_offset,
  367. int (*cqn_handler)(struct bnxt_qplib_nq *nq,
  368. struct bnxt_qplib_cq *cq),
  369. int (*srqn_handler)(struct bnxt_qplib_nq *nq,
  370. void *srq,
  371. u8 event));
  372. int bnxt_qplib_create_qp1(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
  373. int bnxt_qplib_create_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
  374. int bnxt_qplib_modify_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
  375. int bnxt_qplib_query_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
  376. int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
  377. void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp,
  378. struct bnxt_qplib_sge *sge);
  379. void *bnxt_qplib_get_qp1_rq_buf(struct bnxt_qplib_qp *qp,
  380. struct bnxt_qplib_sge *sge);
  381. u32 bnxt_qplib_get_rq_prod_index(struct bnxt_qplib_qp *qp);
  382. dma_addr_t bnxt_qplib_get_qp_buf_from_index(struct bnxt_qplib_qp *qp,
  383. u32 index);
  384. void bnxt_qplib_post_send_db(struct bnxt_qplib_qp *qp);
  385. int bnxt_qplib_post_send(struct bnxt_qplib_qp *qp,
  386. struct bnxt_qplib_swqe *wqe);
  387. void bnxt_qplib_post_recv_db(struct bnxt_qplib_qp *qp);
  388. int bnxt_qplib_post_recv(struct bnxt_qplib_qp *qp,
  389. struct bnxt_qplib_swqe *wqe);
  390. int bnxt_qplib_create_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq);
  391. int bnxt_qplib_destroy_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq);
  392. int bnxt_qplib_poll_cq(struct bnxt_qplib_cq *cq, struct bnxt_qplib_cqe *cqe,
  393. int num);
  394. void bnxt_qplib_req_notify_cq(struct bnxt_qplib_cq *cq, u32 arm_type);
  395. void bnxt_qplib_free_nq(struct bnxt_qplib_nq *nq);
  396. int bnxt_qplib_alloc_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq);
  397. #endif /* __BNXT_QPLIB_FP_H__ */