qplib_res.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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: QPLib resource manager (header)
  37. */
  38. #ifndef __BNXT_QPLIB_RES_H__
  39. #define __BNXT_QPLIB_RES_H__
  40. extern const struct bnxt_qplib_gid bnxt_qplib_gid_zero;
  41. #define PTR_CNT_PER_PG (PAGE_SIZE / sizeof(void *))
  42. #define PTR_MAX_IDX_PER_PG (PTR_CNT_PER_PG - 1)
  43. #define PTR_PG(x) (((x) & ~PTR_MAX_IDX_PER_PG) / PTR_CNT_PER_PG)
  44. #define PTR_IDX(x) ((x) & PTR_MAX_IDX_PER_PG)
  45. #define HWQ_CMP(idx, hwq) ((idx) & ((hwq)->max_elements - 1))
  46. enum bnxt_qplib_hwq_type {
  47. HWQ_TYPE_CTX,
  48. HWQ_TYPE_QUEUE,
  49. HWQ_TYPE_L2_CMPL
  50. };
  51. #define MAX_PBL_LVL_0_PGS 1
  52. #define MAX_PBL_LVL_1_PGS 512
  53. #define MAX_PBL_LVL_1_PGS_SHIFT 9
  54. #define MAX_PBL_LVL_1_PGS_FOR_LVL_2 256
  55. #define MAX_PBL_LVL_2_PGS (256 * 512)
  56. enum bnxt_qplib_pbl_lvl {
  57. PBL_LVL_0,
  58. PBL_LVL_1,
  59. PBL_LVL_2,
  60. PBL_LVL_MAX
  61. };
  62. #define ROCE_PG_SIZE_4K (4 * 1024)
  63. #define ROCE_PG_SIZE_8K (8 * 1024)
  64. #define ROCE_PG_SIZE_64K (64 * 1024)
  65. #define ROCE_PG_SIZE_2M (2 * 1024 * 1024)
  66. #define ROCE_PG_SIZE_8M (8 * 1024 * 1024)
  67. #define ROCE_PG_SIZE_1G (1024 * 1024 * 1024)
  68. struct bnxt_qplib_pbl {
  69. u32 pg_count;
  70. u32 pg_size;
  71. void **pg_arr;
  72. dma_addr_t *pg_map_arr;
  73. };
  74. struct bnxt_qplib_hwq {
  75. struct pci_dev *pdev;
  76. /* lock to protect qplib_hwq */
  77. spinlock_t lock;
  78. struct bnxt_qplib_pbl pbl[PBL_LVL_MAX];
  79. enum bnxt_qplib_pbl_lvl level; /* 0, 1, or 2 */
  80. /* ptr for easy access to the PBL entries */
  81. void **pbl_ptr;
  82. /* ptr for easy access to the dma_addr */
  83. dma_addr_t *pbl_dma_ptr;
  84. u32 max_elements;
  85. u16 element_size; /* Size of each entry */
  86. u32 prod; /* raw */
  87. u32 cons; /* raw */
  88. u8 cp_bit;
  89. u8 is_user;
  90. };
  91. /* Tables */
  92. struct bnxt_qplib_pd_tbl {
  93. unsigned long *tbl;
  94. u32 max;
  95. };
  96. struct bnxt_qplib_sgid_tbl {
  97. struct bnxt_qplib_gid *tbl;
  98. u16 *hw_id;
  99. u16 max;
  100. u16 active;
  101. void *ctx;
  102. };
  103. struct bnxt_qplib_pkey_tbl {
  104. u16 *tbl;
  105. u16 max;
  106. u16 active;
  107. };
  108. struct bnxt_qplib_dpi {
  109. u32 dpi;
  110. void __iomem *dbr;
  111. u64 umdbr;
  112. };
  113. struct bnxt_qplib_dpi_tbl {
  114. void **app_tbl;
  115. unsigned long *tbl;
  116. u16 max;
  117. void __iomem *dbr_bar_reg_iomem;
  118. u64 unmapped_dbr;
  119. };
  120. struct bnxt_qplib_stats {
  121. dma_addr_t dma_map;
  122. void *dma;
  123. u32 size;
  124. u32 fw_id;
  125. };
  126. struct bnxt_qplib_vf_res {
  127. u32 max_qp_per_vf;
  128. u32 max_mrw_per_vf;
  129. u32 max_srq_per_vf;
  130. u32 max_cq_per_vf;
  131. u32 max_gid_per_vf;
  132. };
  133. #define BNXT_QPLIB_MAX_QP_CTX_ENTRY_SIZE 448
  134. #define BNXT_QPLIB_MAX_SRQ_CTX_ENTRY_SIZE 64
  135. #define BNXT_QPLIB_MAX_CQ_CTX_ENTRY_SIZE 64
  136. #define BNXT_QPLIB_MAX_MRW_CTX_ENTRY_SIZE 128
  137. struct bnxt_qplib_ctx {
  138. u32 qpc_count;
  139. struct bnxt_qplib_hwq qpc_tbl;
  140. u32 mrw_count;
  141. struct bnxt_qplib_hwq mrw_tbl;
  142. u32 srqc_count;
  143. struct bnxt_qplib_hwq srqc_tbl;
  144. u32 cq_count;
  145. struct bnxt_qplib_hwq cq_tbl;
  146. struct bnxt_qplib_hwq tim_tbl;
  147. #define MAX_TQM_ALLOC_REQ 32
  148. #define MAX_TQM_ALLOC_BLK_SIZE 8
  149. u8 tqm_count[MAX_TQM_ALLOC_REQ];
  150. struct bnxt_qplib_hwq tqm_pde;
  151. u32 tqm_pde_level;
  152. struct bnxt_qplib_hwq tqm_tbl[MAX_TQM_ALLOC_REQ];
  153. struct bnxt_qplib_stats stats;
  154. struct bnxt_qplib_vf_res vf_res;
  155. };
  156. struct bnxt_qplib_res {
  157. struct pci_dev *pdev;
  158. struct net_device *netdev;
  159. struct bnxt_qplib_rcfw *rcfw;
  160. struct bnxt_qplib_pd_tbl pd_tbl;
  161. struct bnxt_qplib_sgid_tbl sgid_tbl;
  162. struct bnxt_qplib_pkey_tbl pkey_tbl;
  163. struct bnxt_qplib_dpi_tbl dpi_tbl;
  164. };
  165. #define to_bnxt_qplib(ptr, type, member) \
  166. container_of(ptr, type, member)
  167. struct bnxt_qplib_pd;
  168. struct bnxt_qplib_dev_attr;
  169. void bnxt_qplib_free_hwq(struct pci_dev *pdev, struct bnxt_qplib_hwq *hwq);
  170. int bnxt_qplib_alloc_init_hwq(struct pci_dev *pdev, struct bnxt_qplib_hwq *hwq,
  171. struct scatterlist *sl, int nmap, u32 *elements,
  172. u32 elements_per_page, u32 aux, u32 pg_size,
  173. enum bnxt_qplib_hwq_type hwq_type);
  174. void bnxt_qplib_get_guid(u8 *dev_addr, u8 *guid);
  175. int bnxt_qplib_alloc_pd(struct bnxt_qplib_pd_tbl *pd_tbl,
  176. struct bnxt_qplib_pd *pd);
  177. int bnxt_qplib_dealloc_pd(struct bnxt_qplib_res *res,
  178. struct bnxt_qplib_pd_tbl *pd_tbl,
  179. struct bnxt_qplib_pd *pd);
  180. int bnxt_qplib_alloc_dpi(struct bnxt_qplib_dpi_tbl *dpit,
  181. struct bnxt_qplib_dpi *dpi,
  182. void *app);
  183. int bnxt_qplib_dealloc_dpi(struct bnxt_qplib_res *res,
  184. struct bnxt_qplib_dpi_tbl *dpi_tbl,
  185. struct bnxt_qplib_dpi *dpi);
  186. void bnxt_qplib_cleanup_res(struct bnxt_qplib_res *res);
  187. int bnxt_qplib_init_res(struct bnxt_qplib_res *res);
  188. void bnxt_qplib_free_res(struct bnxt_qplib_res *res);
  189. int bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct pci_dev *pdev,
  190. struct net_device *netdev,
  191. struct bnxt_qplib_dev_attr *dev_attr);
  192. void bnxt_qplib_free_ctx(struct pci_dev *pdev,
  193. struct bnxt_qplib_ctx *ctx);
  194. int bnxt_qplib_alloc_ctx(struct pci_dev *pdev,
  195. struct bnxt_qplib_ctx *ctx,
  196. bool virt_fn);
  197. #endif /* __BNXT_QPLIB_RES_H__ */