1ae06c70bSJeff Kirsher /* SPDX-License-Identifier: GPL-2.0 */ 251dce24bSJeff Kirsher /* Copyright(c) 2013 - 2018 Intel Corporation. */ 356a62fc8SJesse Brandeburg 456a62fc8SJesse Brandeburg #ifndef _I40E_HMC_H_ 556a62fc8SJesse Brandeburg #define _I40E_HMC_H_ 656a62fc8SJesse Brandeburg 756a62fc8SJesse Brandeburg #define I40E_HMC_MAX_BP_COUNT 512 856a62fc8SJesse Brandeburg 956a62fc8SJesse Brandeburg /* forward-declare the HW struct for the compiler */ 1056a62fc8SJesse Brandeburg struct i40e_hw; 1156a62fc8SJesse Brandeburg 1256a62fc8SJesse Brandeburg #define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */ 1356a62fc8SJesse Brandeburg #define I40E_HMC_PD_CNT_IN_SD 512 1456a62fc8SJesse Brandeburg #define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */ 1556a62fc8SJesse Brandeburg #define I40E_HMC_PAGED_BP_SIZE 4096 1656a62fc8SJesse Brandeburg #define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096 1756a62fc8SJesse Brandeburg #define I40E_FIRST_VF_FPM_ID 16 1856a62fc8SJesse Brandeburg 1956a62fc8SJesse Brandeburg struct i40e_hmc_obj_info { 2056a62fc8SJesse Brandeburg u64 base; /* base addr in FPM */ 2156a62fc8SJesse Brandeburg u32 max_cnt; /* max count available for this hmc func */ 2256a62fc8SJesse Brandeburg u32 cnt; /* count of objects driver actually wants to create */ 2356a62fc8SJesse Brandeburg u64 size; /* size in bytes of one object */ 2456a62fc8SJesse Brandeburg }; 2556a62fc8SJesse Brandeburg 2656a62fc8SJesse Brandeburg enum i40e_sd_entry_type { 2756a62fc8SJesse Brandeburg I40E_SD_TYPE_INVALID = 0, 2856a62fc8SJesse Brandeburg I40E_SD_TYPE_PAGED = 1, 2956a62fc8SJesse Brandeburg I40E_SD_TYPE_DIRECT = 2 3056a62fc8SJesse Brandeburg }; 3156a62fc8SJesse Brandeburg 3256a62fc8SJesse Brandeburg struct i40e_hmc_bp { 3356a62fc8SJesse Brandeburg enum i40e_sd_entry_type entry_type; 3456a62fc8SJesse Brandeburg struct i40e_dma_mem addr; /* populate to be used by hw */ 3556a62fc8SJesse Brandeburg u32 sd_pd_index; 3656a62fc8SJesse Brandeburg u32 ref_cnt; 3756a62fc8SJesse Brandeburg }; 3856a62fc8SJesse Brandeburg 3956a62fc8SJesse Brandeburg struct i40e_hmc_pd_entry { 4056a62fc8SJesse Brandeburg struct i40e_hmc_bp bp; 4156a62fc8SJesse Brandeburg u32 sd_index; 423bbf0faaSFaisal Latif bool rsrc_pg; 4356a62fc8SJesse Brandeburg bool valid; 4456a62fc8SJesse Brandeburg }; 4556a62fc8SJesse Brandeburg 4656a62fc8SJesse Brandeburg struct i40e_hmc_pd_table { 4756a62fc8SJesse Brandeburg struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */ 4856a62fc8SJesse Brandeburg struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */ 4956a62fc8SJesse Brandeburg struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */ 5056a62fc8SJesse Brandeburg 5156a62fc8SJesse Brandeburg u32 ref_cnt; 5256a62fc8SJesse Brandeburg u32 sd_index; 5356a62fc8SJesse Brandeburg }; 5456a62fc8SJesse Brandeburg 5556a62fc8SJesse Brandeburg struct i40e_hmc_sd_entry { 5656a62fc8SJesse Brandeburg enum i40e_sd_entry_type entry_type; 5756a62fc8SJesse Brandeburg bool valid; 5856a62fc8SJesse Brandeburg 5956a62fc8SJesse Brandeburg union { 6056a62fc8SJesse Brandeburg struct i40e_hmc_pd_table pd_table; 6156a62fc8SJesse Brandeburg struct i40e_hmc_bp bp; 6256a62fc8SJesse Brandeburg } u; 6356a62fc8SJesse Brandeburg }; 6456a62fc8SJesse Brandeburg 6556a62fc8SJesse Brandeburg struct i40e_hmc_sd_table { 6656a62fc8SJesse Brandeburg struct i40e_virt_mem addr; /* used to track sd_entry allocations */ 6756a62fc8SJesse Brandeburg u32 sd_cnt; 6856a62fc8SJesse Brandeburg u32 ref_cnt; 6956a62fc8SJesse Brandeburg struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */ 7056a62fc8SJesse Brandeburg }; 7156a62fc8SJesse Brandeburg 7256a62fc8SJesse Brandeburg struct i40e_hmc_info { 7356a62fc8SJesse Brandeburg u32 signature; 7456a62fc8SJesse Brandeburg /* equals to pci func num for PF and dynamically allocated for VFs */ 7556a62fc8SJesse Brandeburg u8 hmc_fn_id; 7656a62fc8SJesse Brandeburg u16 first_sd_index; /* index of the first available SD */ 7756a62fc8SJesse Brandeburg 7856a62fc8SJesse Brandeburg /* hmc objects */ 7956a62fc8SJesse Brandeburg struct i40e_hmc_obj_info *hmc_obj; 8056a62fc8SJesse Brandeburg struct i40e_virt_mem hmc_obj_virt_mem; 8156a62fc8SJesse Brandeburg struct i40e_hmc_sd_table sd_table; 8256a62fc8SJesse Brandeburg }; 8356a62fc8SJesse Brandeburg 8456a62fc8SJesse Brandeburg #define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++) 8556a62fc8SJesse Brandeburg #define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++) 8656a62fc8SJesse Brandeburg #define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++) 8756a62fc8SJesse Brandeburg 8856a62fc8SJesse Brandeburg #define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--) 8956a62fc8SJesse Brandeburg #define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--) 9056a62fc8SJesse Brandeburg #define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--) 9156a62fc8SJesse Brandeburg 9256a62fc8SJesse Brandeburg /** 9356a62fc8SJesse Brandeburg * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware 9456a62fc8SJesse Brandeburg * @hw: pointer to our hw struct 9556a62fc8SJesse Brandeburg * @pa: pointer to physical address 9656a62fc8SJesse Brandeburg * @sd_index: segment descriptor index 9756a62fc8SJesse Brandeburg * @type: if sd entry is direct or paged 9856a62fc8SJesse Brandeburg **/ 9956a62fc8SJesse Brandeburg #define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \ 10056a62fc8SJesse Brandeburg { \ 10156a62fc8SJesse Brandeburg u32 val1, val2, val3; \ 10256a62fc8SJesse Brandeburg val1 = (u32)(upper_32_bits(pa)); \ 10356a62fc8SJesse Brandeburg val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \ 10456a62fc8SJesse Brandeburg I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 10556a62fc8SJesse Brandeburg ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 10656a62fc8SJesse Brandeburg I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \ 10741a1d04bSJesse Brandeburg BIT(I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \ 10841a1d04bSJesse Brandeburg val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 10956a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \ 11056a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 11156a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDCMD, val3); \ 11256a62fc8SJesse Brandeburg } 11356a62fc8SJesse Brandeburg 11456a62fc8SJesse Brandeburg /** 11556a62fc8SJesse Brandeburg * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware 11656a62fc8SJesse Brandeburg * @hw: pointer to our hw struct 11756a62fc8SJesse Brandeburg * @sd_index: segment descriptor index 11856a62fc8SJesse Brandeburg * @type: if sd entry is direct or paged 11956a62fc8SJesse Brandeburg **/ 12056a62fc8SJesse Brandeburg #define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \ 12156a62fc8SJesse Brandeburg { \ 12256a62fc8SJesse Brandeburg u32 val2, val3; \ 12356a62fc8SJesse Brandeburg val2 = (I40E_HMC_MAX_BP_COUNT << \ 12456a62fc8SJesse Brandeburg I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 12556a62fc8SJesse Brandeburg ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 12656a62fc8SJesse Brandeburg I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \ 12741a1d04bSJesse Brandeburg val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 12856a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \ 12956a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 13056a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_SDCMD, val3); \ 13156a62fc8SJesse Brandeburg } 13256a62fc8SJesse Brandeburg 13356a62fc8SJesse Brandeburg /** 13456a62fc8SJesse Brandeburg * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware 13556a62fc8SJesse Brandeburg * @hw: pointer to our hw struct 13656a62fc8SJesse Brandeburg * @sd_idx: segment descriptor index 13756a62fc8SJesse Brandeburg * @pd_idx: page descriptor index 13856a62fc8SJesse Brandeburg **/ 13956a62fc8SJesse Brandeburg #define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \ 14056a62fc8SJesse Brandeburg wr32((hw), I40E_PFHMC_PDINV, \ 14156a62fc8SJesse Brandeburg (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \ 14256a62fc8SJesse Brandeburg ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT))) 14356a62fc8SJesse Brandeburg 14456a62fc8SJesse Brandeburg /** 14556a62fc8SJesse Brandeburg * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit 14656a62fc8SJesse Brandeburg * @hmc_info: pointer to the HMC configuration information structure 14756a62fc8SJesse Brandeburg * @type: type of HMC resources we're searching 14856a62fc8SJesse Brandeburg * @index: starting index for the object 14956a62fc8SJesse Brandeburg * @cnt: number of objects we're trying to create 15056a62fc8SJesse Brandeburg * @sd_idx: pointer to return index of the segment descriptor in question 15156a62fc8SJesse Brandeburg * @sd_limit: pointer to return the maximum number of segment descriptors 15256a62fc8SJesse Brandeburg * 15356a62fc8SJesse Brandeburg * This function calculates the segment descriptor index and index limit 15456a62fc8SJesse Brandeburg * for the resource defined by i40e_hmc_rsrc_type. 15556a62fc8SJesse Brandeburg **/ 15656a62fc8SJesse Brandeburg #define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\ 15756a62fc8SJesse Brandeburg { \ 15856a62fc8SJesse Brandeburg u64 fpm_addr, fpm_limit; \ 15956a62fc8SJesse Brandeburg fpm_addr = (hmc_info)->hmc_obj[(type)].base + \ 16056a62fc8SJesse Brandeburg (hmc_info)->hmc_obj[(type)].size * (index); \ 16156a62fc8SJesse Brandeburg fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\ 16256a62fc8SJesse Brandeburg *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \ 16356a62fc8SJesse Brandeburg *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \ 16456a62fc8SJesse Brandeburg /* add one more to the limit to correct our range */ \ 16556a62fc8SJesse Brandeburg *(sd_limit) += 1; \ 16656a62fc8SJesse Brandeburg } 16756a62fc8SJesse Brandeburg 16856a62fc8SJesse Brandeburg /** 16956a62fc8SJesse Brandeburg * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit 17056a62fc8SJesse Brandeburg * @hmc_info: pointer to the HMC configuration information struct 17156a62fc8SJesse Brandeburg * @type: HMC resource type we're examining 17256a62fc8SJesse Brandeburg * @idx: starting index for the object 17356a62fc8SJesse Brandeburg * @cnt: number of objects we're trying to create 17456a62fc8SJesse Brandeburg * @pd_index: pointer to return page descriptor index 17556a62fc8SJesse Brandeburg * @pd_limit: pointer to return page descriptor index limit 17656a62fc8SJesse Brandeburg * 17756a62fc8SJesse Brandeburg * Calculates the page descriptor index and index limit for the resource 17856a62fc8SJesse Brandeburg * defined by i40e_hmc_rsrc_type. 17956a62fc8SJesse Brandeburg **/ 18056a62fc8SJesse Brandeburg #define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\ 18156a62fc8SJesse Brandeburg { \ 18256a62fc8SJesse Brandeburg u64 fpm_adr, fpm_limit; \ 18356a62fc8SJesse Brandeburg fpm_adr = (hmc_info)->hmc_obj[(type)].base + \ 18456a62fc8SJesse Brandeburg (hmc_info)->hmc_obj[(type)].size * (idx); \ 18556a62fc8SJesse Brandeburg fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \ 18656a62fc8SJesse Brandeburg *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \ 18756a62fc8SJesse Brandeburg *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \ 18856a62fc8SJesse Brandeburg /* add one more to the limit to correct our range */ \ 18956a62fc8SJesse Brandeburg *(pd_limit) += 1; \ 19056a62fc8SJesse Brandeburg } 19156a62fc8SJesse Brandeburg i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw, 19256a62fc8SJesse Brandeburg struct i40e_hmc_info *hmc_info, 19356a62fc8SJesse Brandeburg u32 sd_index, 19456a62fc8SJesse Brandeburg enum i40e_sd_entry_type type, 19556a62fc8SJesse Brandeburg u64 direct_mode_sz); 19656a62fc8SJesse Brandeburg 19756a62fc8SJesse Brandeburg i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw, 19856a62fc8SJesse Brandeburg struct i40e_hmc_info *hmc_info, 1993bbf0faaSFaisal Latif u32 pd_index, 2003bbf0faaSFaisal Latif struct i40e_dma_mem *rsrc_pg); 20156a62fc8SJesse Brandeburg i40e_status i40e_remove_pd_bp(struct i40e_hw *hw, 20256a62fc8SJesse Brandeburg struct i40e_hmc_info *hmc_info, 203467d729aSAnjali Singhai Jain u32 idx); 20456a62fc8SJesse Brandeburg i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info, 20556a62fc8SJesse Brandeburg u32 idx); 20656a62fc8SJesse Brandeburg i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw, 20756a62fc8SJesse Brandeburg struct i40e_hmc_info *hmc_info, 20856a62fc8SJesse Brandeburg u32 idx, bool is_pf); 20956a62fc8SJesse Brandeburg i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info, 21056a62fc8SJesse Brandeburg u32 idx); 21156a62fc8SJesse Brandeburg i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw, 21256a62fc8SJesse Brandeburg struct i40e_hmc_info *hmc_info, 21356a62fc8SJesse Brandeburg u32 idx, bool is_pf); 21456a62fc8SJesse Brandeburg 21556a62fc8SJesse Brandeburg #endif /* _I40E_HMC_H_ */ 216