162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright(c) 2013 - 2018 Intel Corporation. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#ifndef _I40E_HMC_H_ 562306a36Sopenharmony_ci#define _I40E_HMC_H_ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#define I40E_HMC_MAX_BP_COUNT 512 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* forward-declare the HW struct for the compiler */ 1062306a36Sopenharmony_cistruct i40e_hw; 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */ 1362306a36Sopenharmony_ci#define I40E_HMC_PD_CNT_IN_SD 512 1462306a36Sopenharmony_ci#define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */ 1562306a36Sopenharmony_ci#define I40E_HMC_PAGED_BP_SIZE 4096 1662306a36Sopenharmony_ci#define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_cistruct i40e_hmc_obj_info { 1962306a36Sopenharmony_ci u64 base; /* base addr in FPM */ 2062306a36Sopenharmony_ci u32 max_cnt; /* max count available for this hmc func */ 2162306a36Sopenharmony_ci u32 cnt; /* count of objects driver actually wants to create */ 2262306a36Sopenharmony_ci u64 size; /* size in bytes of one object */ 2362306a36Sopenharmony_ci}; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cienum i40e_sd_entry_type { 2662306a36Sopenharmony_ci I40E_SD_TYPE_INVALID = 0, 2762306a36Sopenharmony_ci I40E_SD_TYPE_PAGED = 1, 2862306a36Sopenharmony_ci I40E_SD_TYPE_DIRECT = 2 2962306a36Sopenharmony_ci}; 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistruct i40e_hmc_bp { 3262306a36Sopenharmony_ci enum i40e_sd_entry_type entry_type; 3362306a36Sopenharmony_ci struct i40e_dma_mem addr; /* populate to be used by hw */ 3462306a36Sopenharmony_ci u32 sd_pd_index; 3562306a36Sopenharmony_ci u32 ref_cnt; 3662306a36Sopenharmony_ci}; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cistruct i40e_hmc_pd_entry { 3962306a36Sopenharmony_ci struct i40e_hmc_bp bp; 4062306a36Sopenharmony_ci u32 sd_index; 4162306a36Sopenharmony_ci bool rsrc_pg; 4262306a36Sopenharmony_ci bool valid; 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistruct i40e_hmc_pd_table { 4662306a36Sopenharmony_ci struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */ 4762306a36Sopenharmony_ci struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */ 4862306a36Sopenharmony_ci struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */ 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci u32 ref_cnt; 5162306a36Sopenharmony_ci u32 sd_index; 5262306a36Sopenharmony_ci}; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistruct i40e_hmc_sd_entry { 5562306a36Sopenharmony_ci enum i40e_sd_entry_type entry_type; 5662306a36Sopenharmony_ci bool valid; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci union { 5962306a36Sopenharmony_ci struct i40e_hmc_pd_table pd_table; 6062306a36Sopenharmony_ci struct i40e_hmc_bp bp; 6162306a36Sopenharmony_ci } u; 6262306a36Sopenharmony_ci}; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistruct i40e_hmc_sd_table { 6562306a36Sopenharmony_ci struct i40e_virt_mem addr; /* used to track sd_entry allocations */ 6662306a36Sopenharmony_ci u32 sd_cnt; 6762306a36Sopenharmony_ci u32 ref_cnt; 6862306a36Sopenharmony_ci struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */ 6962306a36Sopenharmony_ci}; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistruct i40e_hmc_info { 7262306a36Sopenharmony_ci u32 signature; 7362306a36Sopenharmony_ci /* equals to pci func num for PF and dynamically allocated for VFs */ 7462306a36Sopenharmony_ci u8 hmc_fn_id; 7562306a36Sopenharmony_ci u16 first_sd_index; /* index of the first available SD */ 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci /* hmc objects */ 7862306a36Sopenharmony_ci struct i40e_hmc_obj_info *hmc_obj; 7962306a36Sopenharmony_ci struct i40e_virt_mem hmc_obj_virt_mem; 8062306a36Sopenharmony_ci struct i40e_hmc_sd_table sd_table; 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++) 8462306a36Sopenharmony_ci#define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++) 8562306a36Sopenharmony_ci#define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++) 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--) 8862306a36Sopenharmony_ci#define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--) 8962306a36Sopenharmony_ci#define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--) 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/** 9262306a36Sopenharmony_ci * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware 9362306a36Sopenharmony_ci * @hw: pointer to our hw struct 9462306a36Sopenharmony_ci * @pa: pointer to physical address 9562306a36Sopenharmony_ci * @sd_index: segment descriptor index 9662306a36Sopenharmony_ci * @type: if sd entry is direct or paged 9762306a36Sopenharmony_ci **/ 9862306a36Sopenharmony_ci#define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \ 9962306a36Sopenharmony_ci{ \ 10062306a36Sopenharmony_ci u32 val1, val2, val3; \ 10162306a36Sopenharmony_ci val1 = (u32)(upper_32_bits(pa)); \ 10262306a36Sopenharmony_ci val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \ 10362306a36Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 10462306a36Sopenharmony_ci ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 10562306a36Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \ 10662306a36Sopenharmony_ci BIT(I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \ 10762306a36Sopenharmony_ci val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 10862306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \ 10962306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 11062306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDCMD, val3); \ 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/** 11462306a36Sopenharmony_ci * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware 11562306a36Sopenharmony_ci * @hw: pointer to our hw struct 11662306a36Sopenharmony_ci * @sd_index: segment descriptor index 11762306a36Sopenharmony_ci * @type: if sd entry is direct or paged 11862306a36Sopenharmony_ci **/ 11962306a36Sopenharmony_ci#define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \ 12062306a36Sopenharmony_ci{ \ 12162306a36Sopenharmony_ci u32 val2, val3; \ 12262306a36Sopenharmony_ci val2 = (I40E_HMC_MAX_BP_COUNT << \ 12362306a36Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 12462306a36Sopenharmony_ci ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 12562306a36Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \ 12662306a36Sopenharmony_ci val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 12762306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \ 12862306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 12962306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_SDCMD, val3); \ 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/** 13362306a36Sopenharmony_ci * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware 13462306a36Sopenharmony_ci * @hw: pointer to our hw struct 13562306a36Sopenharmony_ci * @sd_idx: segment descriptor index 13662306a36Sopenharmony_ci * @pd_idx: page descriptor index 13762306a36Sopenharmony_ci **/ 13862306a36Sopenharmony_ci#define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \ 13962306a36Sopenharmony_ci wr32((hw), I40E_PFHMC_PDINV, \ 14062306a36Sopenharmony_ci (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \ 14162306a36Sopenharmony_ci ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT))) 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci/** 14462306a36Sopenharmony_ci * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit 14562306a36Sopenharmony_ci * @hmc_info: pointer to the HMC configuration information structure 14662306a36Sopenharmony_ci * @type: type of HMC resources we're searching 14762306a36Sopenharmony_ci * @index: starting index for the object 14862306a36Sopenharmony_ci * @cnt: number of objects we're trying to create 14962306a36Sopenharmony_ci * @sd_idx: pointer to return index of the segment descriptor in question 15062306a36Sopenharmony_ci * @sd_limit: pointer to return the maximum number of segment descriptors 15162306a36Sopenharmony_ci * 15262306a36Sopenharmony_ci * This function calculates the segment descriptor index and index limit 15362306a36Sopenharmony_ci * for the resource defined by i40e_hmc_rsrc_type. 15462306a36Sopenharmony_ci **/ 15562306a36Sopenharmony_ci#define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\ 15662306a36Sopenharmony_ci{ \ 15762306a36Sopenharmony_ci u64 fpm_addr, fpm_limit; \ 15862306a36Sopenharmony_ci fpm_addr = (hmc_info)->hmc_obj[(type)].base + \ 15962306a36Sopenharmony_ci (hmc_info)->hmc_obj[(type)].size * (index); \ 16062306a36Sopenharmony_ci fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\ 16162306a36Sopenharmony_ci *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \ 16262306a36Sopenharmony_ci *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \ 16362306a36Sopenharmony_ci /* add one more to the limit to correct our range */ \ 16462306a36Sopenharmony_ci *(sd_limit) += 1; \ 16562306a36Sopenharmony_ci} 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/** 16862306a36Sopenharmony_ci * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit 16962306a36Sopenharmony_ci * @hmc_info: pointer to the HMC configuration information struct 17062306a36Sopenharmony_ci * @type: HMC resource type we're examining 17162306a36Sopenharmony_ci * @idx: starting index for the object 17262306a36Sopenharmony_ci * @cnt: number of objects we're trying to create 17362306a36Sopenharmony_ci * @pd_index: pointer to return page descriptor index 17462306a36Sopenharmony_ci * @pd_limit: pointer to return page descriptor index limit 17562306a36Sopenharmony_ci * 17662306a36Sopenharmony_ci * Calculates the page descriptor index and index limit for the resource 17762306a36Sopenharmony_ci * defined by i40e_hmc_rsrc_type. 17862306a36Sopenharmony_ci **/ 17962306a36Sopenharmony_ci#define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\ 18062306a36Sopenharmony_ci{ \ 18162306a36Sopenharmony_ci u64 fpm_adr, fpm_limit; \ 18262306a36Sopenharmony_ci fpm_adr = (hmc_info)->hmc_obj[(type)].base + \ 18362306a36Sopenharmony_ci (hmc_info)->hmc_obj[(type)].size * (idx); \ 18462306a36Sopenharmony_ci fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \ 18562306a36Sopenharmony_ci *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \ 18662306a36Sopenharmony_ci *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \ 18762306a36Sopenharmony_ci /* add one more to the limit to correct our range */ \ 18862306a36Sopenharmony_ci *(pd_limit) += 1; \ 18962306a36Sopenharmony_ci} 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ciint i40e_add_sd_table_entry(struct i40e_hw *hw, 19262306a36Sopenharmony_ci struct i40e_hmc_info *hmc_info, 19362306a36Sopenharmony_ci u32 sd_index, 19462306a36Sopenharmony_ci enum i40e_sd_entry_type type, 19562306a36Sopenharmony_ci u64 direct_mode_sz); 19662306a36Sopenharmony_ciint i40e_add_pd_table_entry(struct i40e_hw *hw, 19762306a36Sopenharmony_ci struct i40e_hmc_info *hmc_info, 19862306a36Sopenharmony_ci u32 pd_index, 19962306a36Sopenharmony_ci struct i40e_dma_mem *rsrc_pg); 20062306a36Sopenharmony_ciint i40e_remove_pd_bp(struct i40e_hw *hw, 20162306a36Sopenharmony_ci struct i40e_hmc_info *hmc_info, 20262306a36Sopenharmony_ci u32 idx); 20362306a36Sopenharmony_ciint i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info, 20462306a36Sopenharmony_ci u32 idx); 20562306a36Sopenharmony_ciint i40e_remove_sd_bp_new(struct i40e_hw *hw, 20662306a36Sopenharmony_ci struct i40e_hmc_info *hmc_info, 20762306a36Sopenharmony_ci u32 idx, bool is_pf); 20862306a36Sopenharmony_ciint i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info, 20962306a36Sopenharmony_ci u32 idx); 21062306a36Sopenharmony_ciint i40e_remove_pd_page_new(struct i40e_hw *hw, 21162306a36Sopenharmony_ci struct i40e_hmc_info *hmc_info, 21262306a36Sopenharmony_ci u32 idx, bool is_pf); 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci#endif /* _I40E_HMC_H_ */ 215