i40e_hmc.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #ifndef _I40E_HMC_H_
  28. #define _I40E_HMC_H_
  29. #define I40E_HMC_MAX_BP_COUNT 512
  30. /* forward-declare the HW struct for the compiler */
  31. struct i40e_hw;
  32. #define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */
  33. #define I40E_HMC_PD_CNT_IN_SD 512
  34. #define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */
  35. #define I40E_HMC_PAGED_BP_SIZE 4096
  36. #define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096
  37. #define I40E_FIRST_VF_FPM_ID 16
  38. struct i40e_hmc_obj_info {
  39. u64 base; /* base addr in FPM */
  40. u32 max_cnt; /* max count available for this hmc func */
  41. u32 cnt; /* count of objects driver actually wants to create */
  42. u64 size; /* size in bytes of one object */
  43. };
  44. enum i40e_sd_entry_type {
  45. I40E_SD_TYPE_INVALID = 0,
  46. I40E_SD_TYPE_PAGED = 1,
  47. I40E_SD_TYPE_DIRECT = 2
  48. };
  49. struct i40e_hmc_bp {
  50. enum i40e_sd_entry_type entry_type;
  51. struct i40e_dma_mem addr; /* populate to be used by hw */
  52. u32 sd_pd_index;
  53. u32 ref_cnt;
  54. };
  55. struct i40e_hmc_pd_entry {
  56. struct i40e_hmc_bp bp;
  57. u32 sd_index;
  58. bool valid;
  59. };
  60. struct i40e_hmc_pd_table {
  61. struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */
  62. struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */
  63. struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */
  64. u32 ref_cnt;
  65. u32 sd_index;
  66. };
  67. struct i40e_hmc_sd_entry {
  68. enum i40e_sd_entry_type entry_type;
  69. bool valid;
  70. union {
  71. struct i40e_hmc_pd_table pd_table;
  72. struct i40e_hmc_bp bp;
  73. } u;
  74. };
  75. struct i40e_hmc_sd_table {
  76. struct i40e_virt_mem addr; /* used to track sd_entry allocations */
  77. u32 sd_cnt;
  78. u32 ref_cnt;
  79. struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */
  80. };
  81. struct i40e_hmc_info {
  82. u32 signature;
  83. /* equals to pci func num for PF and dynamically allocated for VFs */
  84. u8 hmc_fn_id;
  85. u16 first_sd_index; /* index of the first available SD */
  86. /* hmc objects */
  87. struct i40e_hmc_obj_info *hmc_obj;
  88. struct i40e_virt_mem hmc_obj_virt_mem;
  89. struct i40e_hmc_sd_table sd_table;
  90. };
  91. #define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++)
  92. #define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++)
  93. #define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++)
  94. #define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--)
  95. #define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--)
  96. #define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--)
  97. /**
  98. * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware
  99. * @hw: pointer to our hw struct
  100. * @pa: pointer to physical address
  101. * @sd_index: segment descriptor index
  102. * @hmc_fn_id: hmc function id
  103. * @type: if sd entry is direct or paged
  104. **/
  105. #define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \
  106. { \
  107. u32 val1, val2, val3; \
  108. val1 = (u32)(upper_32_bits(pa)); \
  109. val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \
  110. I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
  111. ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
  112. I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \
  113. (1 << I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \
  114. val3 = (sd_index) | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
  115. wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \
  116. wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
  117. wr32((hw), I40E_PFHMC_SDCMD, val3); \
  118. }
  119. /**
  120. * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware
  121. * @hw: pointer to our hw struct
  122. * @sd_index: segment descriptor index
  123. * @hmc_fn_id: hmc function id
  124. * @type: if sd entry is direct or paged
  125. **/
  126. #define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \
  127. { \
  128. u32 val2, val3; \
  129. val2 = (I40E_HMC_MAX_BP_COUNT << \
  130. I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \
  131. ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \
  132. I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \
  133. val3 = (sd_index) | (1 << I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \
  134. wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \
  135. wr32((hw), I40E_PFHMC_SDDATALOW, val2); \
  136. wr32((hw), I40E_PFHMC_SDCMD, val3); \
  137. }
  138. /**
  139. * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware
  140. * @hw: pointer to our hw struct
  141. * @sd_idx: segment descriptor index
  142. * @pd_idx: page descriptor index
  143. * @hmc_fn_id: hmc function id
  144. **/
  145. #define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \
  146. wr32((hw), I40E_PFHMC_PDINV, \
  147. (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
  148. ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
  149. #define I40E_INVALIDATE_VF_HMC_PD(hw, sd_idx, pd_idx, hmc_fn_id) \
  150. wr32((hw), I40E_GLHMC_VFPDINV((hmc_fn_id) - I40E_FIRST_VF_FPM_ID), \
  151. (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \
  152. ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT)))
  153. /**
  154. * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit
  155. * @hmc_info: pointer to the HMC configuration information structure
  156. * @type: type of HMC resources we're searching
  157. * @index: starting index for the object
  158. * @cnt: number of objects we're trying to create
  159. * @sd_idx: pointer to return index of the segment descriptor in question
  160. * @sd_limit: pointer to return the maximum number of segment descriptors
  161. *
  162. * This function calculates the segment descriptor index and index limit
  163. * for the resource defined by i40e_hmc_rsrc_type.
  164. **/
  165. #define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\
  166. { \
  167. u64 fpm_addr, fpm_limit; \
  168. fpm_addr = (hmc_info)->hmc_obj[(type)].base + \
  169. (hmc_info)->hmc_obj[(type)].size * (index); \
  170. fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\
  171. *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \
  172. *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \
  173. /* add one more to the limit to correct our range */ \
  174. *(sd_limit) += 1; \
  175. }
  176. /**
  177. * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit
  178. * @hmc_info: pointer to the HMC configuration information struct
  179. * @type: HMC resource type we're examining
  180. * @idx: starting index for the object
  181. * @cnt: number of objects we're trying to create
  182. * @pd_index: pointer to return page descriptor index
  183. * @pd_limit: pointer to return page descriptor index limit
  184. *
  185. * Calculates the page descriptor index and index limit for the resource
  186. * defined by i40e_hmc_rsrc_type.
  187. **/
  188. #define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\
  189. { \
  190. u64 fpm_adr, fpm_limit; \
  191. fpm_adr = (hmc_info)->hmc_obj[(type)].base + \
  192. (hmc_info)->hmc_obj[(type)].size * (idx); \
  193. fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \
  194. *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \
  195. *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \
  196. /* add one more to the limit to correct our range */ \
  197. *(pd_limit) += 1; \
  198. }
  199. i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw,
  200. struct i40e_hmc_info *hmc_info,
  201. u32 sd_index,
  202. enum i40e_sd_entry_type type,
  203. u64 direct_mode_sz);
  204. i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw,
  205. struct i40e_hmc_info *hmc_info,
  206. u32 pd_index);
  207. i40e_status i40e_remove_pd_bp(struct i40e_hw *hw,
  208. struct i40e_hmc_info *hmc_info,
  209. u32 idx, bool is_pf);
  210. i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info,
  211. u32 idx);
  212. i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw,
  213. struct i40e_hmc_info *hmc_info,
  214. u32 idx, bool is_pf);
  215. i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info,
  216. u32 idx);
  217. i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw,
  218. struct i40e_hmc_info *hmc_info,
  219. u32 idx, bool is_pf);
  220. #endif /* _I40E_HMC_H_ */