i40e_hmc.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #ifndef _I40E_HMC_H_
  4. #define _I40E_HMC_H_
  5. #define I40E_HMC_MAX_BP_COUNT 512
  6. /* forward-declare the HW struct for the compiler */
  7. struct i40e_hw;
  8. #define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */
  9. #define I40E_HMC_PD_CNT_IN_SD 512
  10. #define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */
  11. #define I40E_HMC_PAGED_BP_SIZE 4096
  12. #define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096
  13. #define I40E_FIRST_VF_FPM_ID 16
  14. struct i40e_hmc_obj_info {
  15. u64 base; /* base addr in FPM */
  16. u32 max_cnt; /* max count available for this hmc func */
  17. u32 cnt; /* count of objects driver actually wants to create */
  18. u64 size; /* size in bytes of one object */
  19. };
  20. enum i40e_sd_entry_type {
  21. I40E_SD_TYPE_INVALID = 0,
  22. I40E_SD_TYPE_PAGED = 1,
  23. I40E_SD_TYPE_DIRECT = 2
  24. };
  25. struct i40e_hmc_bp {
  26. enum i40e_sd_entry_type entry_type;
  27. struct i40e_dma_mem addr; /* populate to be used by hw */
  28. u32 sd_pd_index;
  29. u32 ref_cnt;
  30. };
  31. struct i40e_hmc_pd_entry {
  32. struct i40e_hmc_bp bp;
  33. u32 sd_index;
  34. bool rsrc_pg;
  35. bool valid;
  36. };
  37. struct i40e_hmc_pd_table {
  38. struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */
  39. struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */
  40. struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */
  41. u32 ref_cnt;
  42. u32 sd_index;
  43. };
  44. struct i40e_hmc_sd_entry {
  45. enum i40e_sd_entry_type entry_type;
  46. bool valid;
  47. union {
  48. struct i40e_hmc_pd_table pd_table;
  49. struct i40e_hmc_bp bp;
  50. } u;
  51. };
  52. struct i40e_hmc_sd_table {
  53. struct i40e_virt_mem addr; /* used to track sd_entry allocations */
  54. u32 sd_cnt;
  55. u32 ref_cnt;
  56. struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */
  57. };
  58. struct i40e_hmc_info {
  59. u32 signature;
  60. /* equals to pci func num for PF and dynamically allocated for VFs */
  61. u8 hmc_fn_id;
  62. u16 first_sd_index; /* index of the first available SD */
  63. /* hmc objects */
  64. struct i40e_hmc_obj_info *hmc_obj;
  65. struct i40e_virt_mem hmc_obj_virt_mem;
  66. struct i40e_hmc_sd_table sd_table;
  67. };
  68. #define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++)
  69. #define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++)
  70. #define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++)
  71. #define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--)
  72. #define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--)
  73. #define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--)
  74. /**
  75. * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware
  76. * @hw: pointer to our hw struct
  77. * @pa: pointer to physical address
  78. * @sd_index: segment descriptor index
  79. * @type: if sd entry is direct or paged
  80. **/
  81. #define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \
  82. { \
  83. u32 val1, val2, val3; \
  84. val1 = (u32)(upper_32_bits(pa)); \
  85. val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \
  86. I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
  87. ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
  88. I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \
  89. BIT(I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \
  90. val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
  91. wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \
  92. wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
  93. wr32((hw), I40E_PFHMC_SDCMD, val3); \
  94. }
  95. /**
  96. * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware
  97. * @hw: pointer to our hw struct
  98. * @sd_index: segment descriptor index
  99. * @type: if sd entry is direct or paged
  100. **/
  101. #define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \
  102. { \
  103. u32 val2, val3; \
  104. val2 = (I40E_HMC_MAX_BP_COUNT << \
  105. I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
  106. ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
  107. I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \
  108. val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
  109. wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \
  110. wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
  111. wr32((hw), I40E_PFHMC_SDCMD, val3); \
  112. }
  113. /**
  114. * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware
  115. * @hw: pointer to our hw struct
  116. * @sd_idx: segment descriptor index
  117. * @pd_idx: page descriptor index
  118. **/
  119. #define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \
  120. wr32((hw), I40E_PFHMC_PDINV, \
  121. (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
  122. ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
  123. /**
  124. * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit
  125. * @hmc_info: pointer to the HMC configuration information structure
  126. * @type: type of HMC resources we're searching
  127. * @index: starting index for the object
  128. * @cnt: number of objects we're trying to create
  129. * @sd_idx: pointer to return index of the segment descriptor in question
  130. * @sd_limit: pointer to return the maximum number of segment descriptors
  131. *
  132. * This function calculates the segment descriptor index and index limit
  133. * for the resource defined by i40e_hmc_rsrc_type.
  134. **/
  135. #define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\
  136. { \
  137. u64 fpm_addr, fpm_limit; \
  138. fpm_addr = (hmc_info)->hmc_obj[(type)].base + \
  139. (hmc_info)->hmc_obj[(type)].size * (index); \
  140. fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\
  141. *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \
  142. *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \
  143. /* add one more to the limit to correct our range */ \
  144. *(sd_limit) += 1; \
  145. }
  146. /**
  147. * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit
  148. * @hmc_info: pointer to the HMC configuration information struct
  149. * @type: HMC resource type we're examining
  150. * @idx: starting index for the object
  151. * @cnt: number of objects we're trying to create
  152. * @pd_index: pointer to return page descriptor index
  153. * @pd_limit: pointer to return page descriptor index limit
  154. *
  155. * Calculates the page descriptor index and index limit for the resource
  156. * defined by i40e_hmc_rsrc_type.
  157. **/
  158. #define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\
  159. { \
  160. u64 fpm_adr, fpm_limit; \
  161. fpm_adr = (hmc_info)->hmc_obj[(type)].base + \
  162. (hmc_info)->hmc_obj[(type)].size * (idx); \
  163. fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \
  164. *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \
  165. *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \
  166. /* add one more to the limit to correct our range */ \
  167. *(pd_limit) += 1; \
  168. }
  169. i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw,
  170. struct i40e_hmc_info *hmc_info,
  171. u32 sd_index,
  172. enum i40e_sd_entry_type type,
  173. u64 direct_mode_sz);
  174. i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw,
  175. struct i40e_hmc_info *hmc_info,
  176. u32 pd_index,
  177. struct i40e_dma_mem *rsrc_pg);
  178. i40e_status i40e_remove_pd_bp(struct i40e_hw *hw,
  179. struct i40e_hmc_info *hmc_info,
  180. u32 idx);
  181. i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info,
  182. u32 idx);
  183. i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw,
  184. struct i40e_hmc_info *hmc_info,
  185. u32 idx, bool is_pf);
  186. i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info,
  187. u32 idx);
  188. i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw,
  189. struct i40e_hmc_info *hmc_info,
  190. u32 idx, bool is_pf);
  191. #endif /* _I40E_HMC_H_ */