qplib_rcfw.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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: RDMA Controller HW interface (header)
  37. */
  38. #ifndef __BNXT_QPLIB_RCFW_H__
  39. #define __BNXT_QPLIB_RCFW_H__
  40. #define RCFW_CMDQ_TRIG_VAL 1
  41. #define RCFW_COMM_PCI_BAR_REGION 0
  42. #define RCFW_COMM_CONS_PCI_BAR_REGION 2
  43. #define RCFW_COMM_BASE_OFFSET 0x600
  44. #define RCFW_PF_COMM_PROD_OFFSET 0xc
  45. #define RCFW_VF_COMM_PROD_OFFSET 0xc
  46. #define RCFW_COMM_TRIG_OFFSET 0x100
  47. #define RCFW_COMM_SIZE 0x104
  48. #define RCFW_DBR_PCI_BAR_REGION 2
  49. #define RCFW_CMD_PREP(req, CMD, cmd_flags) \
  50. do { \
  51. memset(&(req), 0, sizeof((req))); \
  52. (req).opcode = CMDQ_BASE_OPCODE_##CMD; \
  53. (req).cmd_size = (sizeof((req)) + \
  54. BNXT_QPLIB_CMDQE_UNITS - 1) / \
  55. BNXT_QPLIB_CMDQE_UNITS; \
  56. (req).flags = cpu_to_le16(cmd_flags); \
  57. } while (0)
  58. #define RCFW_CMD_WAIT_TIME_MS 20000 /* 20 Seconds timeout */
  59. /* CMDQ elements */
  60. #define BNXT_QPLIB_CMDQE_MAX_CNT 256
  61. #define BNXT_QPLIB_CMDQE_UNITS sizeof(struct bnxt_qplib_cmdqe)
  62. #define BNXT_QPLIB_CMDQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_CMDQE_UNITS)
  63. #define MAX_CMDQ_IDX (BNXT_QPLIB_CMDQE_MAX_CNT - 1)
  64. #define MAX_CMDQ_IDX_PER_PG (BNXT_QPLIB_CMDQE_CNT_PER_PG - 1)
  65. #define RCFW_MAX_OUTSTANDING_CMD BNXT_QPLIB_CMDQE_MAX_CNT
  66. #define RCFW_MAX_COOKIE_VALUE 0x7FFF
  67. #define RCFW_CMD_IS_BLOCKING 0x8000
  68. /* Cmdq contains a fix number of a 16-Byte slots */
  69. struct bnxt_qplib_cmdqe {
  70. u8 data[16];
  71. };
  72. static inline u32 get_cmdq_pg(u32 val)
  73. {
  74. return (val & ~MAX_CMDQ_IDX_PER_PG) / BNXT_QPLIB_CMDQE_CNT_PER_PG;
  75. }
  76. static inline u32 get_cmdq_idx(u32 val)
  77. {
  78. return val & MAX_CMDQ_IDX_PER_PG;
  79. }
  80. /* Crsq buf is 1024-Byte */
  81. struct bnxt_qplib_crsbe {
  82. u8 data[1024];
  83. };
  84. /* CRSQ SB */
  85. #define BNXT_QPLIB_CRSBE_MAX_CNT 4
  86. #define BNXT_QPLIB_CRSBE_UNITS sizeof(struct bnxt_qplib_crsbe)
  87. #define BNXT_QPLIB_CRSBE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_CRSBE_UNITS)
  88. #define MAX_CRSB_IDX (BNXT_QPLIB_CRSBE_MAX_CNT - 1)
  89. #define MAX_CRSB_IDX_PER_PG (BNXT_QPLIB_CRSBE_CNT_PER_PG - 1)
  90. static inline u32 get_crsb_pg(u32 val)
  91. {
  92. return (val & ~MAX_CRSB_IDX_PER_PG) / BNXT_QPLIB_CRSBE_CNT_PER_PG;
  93. }
  94. static inline u32 get_crsb_idx(u32 val)
  95. {
  96. return val & MAX_CRSB_IDX_PER_PG;
  97. }
  98. static inline void bnxt_qplib_crsb_dma_next(dma_addr_t *pg_map_arr,
  99. u32 prod, dma_addr_t *dma_addr)
  100. {
  101. *dma_addr = pg_map_arr[(prod) / BNXT_QPLIB_CRSBE_CNT_PER_PG];
  102. *dma_addr += ((prod) % BNXT_QPLIB_CRSBE_CNT_PER_PG) *
  103. BNXT_QPLIB_CRSBE_UNITS;
  104. }
  105. /* CREQ */
  106. /* Allocate 1 per QP for async error notification for now */
  107. #define BNXT_QPLIB_CREQE_MAX_CNT (64 * 1024)
  108. #define BNXT_QPLIB_CREQE_UNITS 16 /* 16-Bytes per prod unit */
  109. #define BNXT_QPLIB_CREQE_CNT_PER_PG (PAGE_SIZE / BNXT_QPLIB_CREQE_UNITS)
  110. #define MAX_CREQ_IDX (BNXT_QPLIB_CREQE_MAX_CNT - 1)
  111. #define MAX_CREQ_IDX_PER_PG (BNXT_QPLIB_CREQE_CNT_PER_PG - 1)
  112. static inline u32 get_creq_pg(u32 val)
  113. {
  114. return (val & ~MAX_CREQ_IDX_PER_PG) / BNXT_QPLIB_CREQE_CNT_PER_PG;
  115. }
  116. static inline u32 get_creq_idx(u32 val)
  117. {
  118. return val & MAX_CREQ_IDX_PER_PG;
  119. }
  120. #define BNXT_QPLIB_CREQE_PER_PG (PAGE_SIZE / sizeof(struct creq_base))
  121. #define CREQ_CMP_VALID(hdr, raw_cons, cp_bit) \
  122. (!!((hdr)->v & CREQ_BASE_V) == \
  123. !((raw_cons) & (cp_bit)))
  124. #define CREQ_DB_KEY_CP (0x2 << CMPL_DOORBELL_KEY_SFT)
  125. #define CREQ_DB_IDX_VALID CMPL_DOORBELL_IDX_VALID
  126. #define CREQ_DB_IRQ_DIS CMPL_DOORBELL_MASK
  127. #define CREQ_DB_CP_FLAGS_REARM (CREQ_DB_KEY_CP | \
  128. CREQ_DB_IDX_VALID)
  129. #define CREQ_DB_CP_FLAGS (CREQ_DB_KEY_CP | \
  130. CREQ_DB_IDX_VALID | \
  131. CREQ_DB_IRQ_DIS)
  132. #define CREQ_DB_REARM(db, raw_cons, cp_bit) \
  133. writel(CREQ_DB_CP_FLAGS_REARM | ((raw_cons) & ((cp_bit) - 1)), db)
  134. #define CREQ_DB(db, raw_cons, cp_bit) \
  135. writel(CREQ_DB_CP_FLAGS | ((raw_cons) & ((cp_bit) - 1)), db)
  136. /* HWQ */
  137. struct bnxt_qplib_crsqe {
  138. struct creq_qp_event qp_event;
  139. u32 req_size;
  140. };
  141. struct bnxt_qplib_crsq {
  142. struct bnxt_qplib_crsqe *crsq;
  143. u32 prod;
  144. u32 cons;
  145. u32 max_elements;
  146. };
  147. /* RCFW Communication Channels */
  148. struct bnxt_qplib_rcfw {
  149. struct pci_dev *pdev;
  150. int vector;
  151. struct tasklet_struct worker;
  152. bool requested;
  153. unsigned long *cmdq_bitmap;
  154. u32 bmap_size;
  155. unsigned long flags;
  156. #define FIRMWARE_INITIALIZED_FLAG 1
  157. #define FIRMWARE_FIRST_FLAG BIT(31)
  158. wait_queue_head_t waitq;
  159. int (*aeq_handler)(struct bnxt_qplib_rcfw *,
  160. struct creq_func_event *);
  161. atomic_t seq_num;
  162. /* Bar region info */
  163. void __iomem *cmdq_bar_reg_iomem;
  164. u16 cmdq_bar_reg;
  165. u16 cmdq_bar_reg_prod_off;
  166. u16 cmdq_bar_reg_trig_off;
  167. u16 creq_ring_id;
  168. u16 creq_bar_reg;
  169. void __iomem *creq_bar_reg_iomem;
  170. /* Cmd-Resp and Async Event notification queue */
  171. struct bnxt_qplib_hwq creq;
  172. u64 creq_qp_event_processed;
  173. u64 creq_func_event_processed;
  174. /* Actual Cmd and Resp Queues */
  175. struct bnxt_qplib_hwq cmdq;
  176. struct bnxt_qplib_crsq crsq;
  177. struct bnxt_qplib_hwq crsb;
  178. };
  179. void bnxt_qplib_free_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
  180. int bnxt_qplib_alloc_rcfw_channel(struct pci_dev *pdev,
  181. struct bnxt_qplib_rcfw *rcfw);
  182. void bnxt_qplib_disable_rcfw_channel(struct bnxt_qplib_rcfw *rcfw);
  183. int bnxt_qplib_enable_rcfw_channel(struct pci_dev *pdev,
  184. struct bnxt_qplib_rcfw *rcfw,
  185. int msix_vector,
  186. int cp_bar_reg_off, int virt_fn,
  187. int (*aeq_handler)
  188. (struct bnxt_qplib_rcfw *,
  189. struct creq_func_event *));
  190. int bnxt_qplib_rcfw_block_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie);
  191. int bnxt_qplib_rcfw_wait_for_resp(struct bnxt_qplib_rcfw *rcfw, u16 cookie);
  192. void *bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw,
  193. struct cmdq_base *req, void **crsbe,
  194. u8 is_block);
  195. int bnxt_qplib_deinit_rcfw(struct bnxt_qplib_rcfw *rcfw);
  196. int bnxt_qplib_init_rcfw(struct bnxt_qplib_rcfw *rcfw,
  197. struct bnxt_qplib_ctx *ctx, int is_virtfn);
  198. #endif /* __BNXT_QPLIB_RCFW_H__ */