18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright(c) 2013 - 2018 Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _I40E_HMC_H_ 58c2ecf20Sopenharmony_ci#define _I40E_HMC_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define I40E_HMC_MAX_BP_COUNT 512 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* forward-declare the HW struct for the compiler */ 108c2ecf20Sopenharmony_cistruct i40e_hw; 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */ 138c2ecf20Sopenharmony_ci#define I40E_HMC_PD_CNT_IN_SD 512 148c2ecf20Sopenharmony_ci#define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */ 158c2ecf20Sopenharmony_ci#define I40E_HMC_PAGED_BP_SIZE 4096 168c2ecf20Sopenharmony_ci#define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct i40e_hmc_obj_info { 198c2ecf20Sopenharmony_ci u64 base; /* base addr in FPM */ 208c2ecf20Sopenharmony_ci u32 max_cnt; /* max count available for this hmc func */ 218c2ecf20Sopenharmony_ci u32 cnt; /* count of objects driver actually wants to create */ 228c2ecf20Sopenharmony_ci u64 size; /* size in bytes of one object */ 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cienum i40e_sd_entry_type { 268c2ecf20Sopenharmony_ci I40E_SD_TYPE_INVALID = 0, 278c2ecf20Sopenharmony_ci I40E_SD_TYPE_PAGED = 1, 288c2ecf20Sopenharmony_ci I40E_SD_TYPE_DIRECT = 2 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistruct i40e_hmc_bp { 328c2ecf20Sopenharmony_ci enum i40e_sd_entry_type entry_type; 338c2ecf20Sopenharmony_ci struct i40e_dma_mem addr; /* populate to be used by hw */ 348c2ecf20Sopenharmony_ci u32 sd_pd_index; 358c2ecf20Sopenharmony_ci u32 ref_cnt; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct i40e_hmc_pd_entry { 398c2ecf20Sopenharmony_ci struct i40e_hmc_bp bp; 408c2ecf20Sopenharmony_ci u32 sd_index; 418c2ecf20Sopenharmony_ci bool rsrc_pg; 428c2ecf20Sopenharmony_ci bool valid; 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct i40e_hmc_pd_table { 468c2ecf20Sopenharmony_ci struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */ 478c2ecf20Sopenharmony_ci struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */ 488c2ecf20Sopenharmony_ci struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci u32 ref_cnt; 518c2ecf20Sopenharmony_ci u32 sd_index; 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct i40e_hmc_sd_entry { 558c2ecf20Sopenharmony_ci enum i40e_sd_entry_type entry_type; 568c2ecf20Sopenharmony_ci bool valid; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci union { 598c2ecf20Sopenharmony_ci struct i40e_hmc_pd_table pd_table; 608c2ecf20Sopenharmony_ci struct i40e_hmc_bp bp; 618c2ecf20Sopenharmony_ci } u; 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct i40e_hmc_sd_table { 658c2ecf20Sopenharmony_ci struct i40e_virt_mem addr; /* used to track sd_entry allocations */ 668c2ecf20Sopenharmony_ci u32 sd_cnt; 678c2ecf20Sopenharmony_ci u32 ref_cnt; 688c2ecf20Sopenharmony_ci struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */ 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistruct i40e_hmc_info { 728c2ecf20Sopenharmony_ci u32 signature; 738c2ecf20Sopenharmony_ci /* equals to pci func num for PF and dynamically allocated for VFs */ 748c2ecf20Sopenharmony_ci u8 hmc_fn_id; 758c2ecf20Sopenharmony_ci u16 first_sd_index; /* index of the first available SD */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci /* hmc objects */ 788c2ecf20Sopenharmony_ci struct i40e_hmc_obj_info *hmc_obj; 798c2ecf20Sopenharmony_ci struct i40e_virt_mem hmc_obj_virt_mem; 808c2ecf20Sopenharmony_ci struct i40e_hmc_sd_table sd_table; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++) 848c2ecf20Sopenharmony_ci#define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++) 858c2ecf20Sopenharmony_ci#define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--) 888c2ecf20Sopenharmony_ci#define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--) 898c2ecf20Sopenharmony_ci#define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/** 928c2ecf20Sopenharmony_ci * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware 938c2ecf20Sopenharmony_ci * @hw: pointer to our hw struct 948c2ecf20Sopenharmony_ci * @pa: pointer to physical address 958c2ecf20Sopenharmony_ci * @sd_index: segment descriptor index 968c2ecf20Sopenharmony_ci * @type: if sd entry is direct or paged 978c2ecf20Sopenharmony_ci **/ 988c2ecf20Sopenharmony_ci#define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \ 998c2ecf20Sopenharmony_ci{ \ 1008c2ecf20Sopenharmony_ci u32 val1, val2, val3; \ 1018c2ecf20Sopenharmony_ci val1 = (u32)(upper_32_bits(pa)); \ 1028c2ecf20Sopenharmony_ci val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \ 1038c2ecf20Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 1048c2ecf20Sopenharmony_ci ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 1058c2ecf20Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \ 1068c2ecf20Sopenharmony_ci BIT(I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \ 1078c2ecf20Sopenharmony_ci val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 1088c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \ 1098c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 1108c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDCMD, val3); \ 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/** 1148c2ecf20Sopenharmony_ci * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware 1158c2ecf20Sopenharmony_ci * @hw: pointer to our hw struct 1168c2ecf20Sopenharmony_ci * @sd_index: segment descriptor index 1178c2ecf20Sopenharmony_ci * @type: if sd entry is direct or paged 1188c2ecf20Sopenharmony_ci **/ 1198c2ecf20Sopenharmony_ci#define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \ 1208c2ecf20Sopenharmony_ci{ \ 1218c2ecf20Sopenharmony_ci u32 val2, val3; \ 1228c2ecf20Sopenharmony_ci val2 = (I40E_HMC_MAX_BP_COUNT << \ 1238c2ecf20Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 1248c2ecf20Sopenharmony_ci ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 1258c2ecf20Sopenharmony_ci I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \ 1268c2ecf20Sopenharmony_ci val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 1278c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \ 1288c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 1298c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_SDCMD, val3); \ 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/** 1338c2ecf20Sopenharmony_ci * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware 1348c2ecf20Sopenharmony_ci * @hw: pointer to our hw struct 1358c2ecf20Sopenharmony_ci * @sd_idx: segment descriptor index 1368c2ecf20Sopenharmony_ci * @pd_idx: page descriptor index 1378c2ecf20Sopenharmony_ci **/ 1388c2ecf20Sopenharmony_ci#define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \ 1398c2ecf20Sopenharmony_ci wr32((hw), I40E_PFHMC_PDINV, \ 1408c2ecf20Sopenharmony_ci (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \ 1418c2ecf20Sopenharmony_ci ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT))) 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci/** 1448c2ecf20Sopenharmony_ci * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit 1458c2ecf20Sopenharmony_ci * @hmc_info: pointer to the HMC configuration information structure 1468c2ecf20Sopenharmony_ci * @type: type of HMC resources we're searching 1478c2ecf20Sopenharmony_ci * @index: starting index for the object 1488c2ecf20Sopenharmony_ci * @cnt: number of objects we're trying to create 1498c2ecf20Sopenharmony_ci * @sd_idx: pointer to return index of the segment descriptor in question 1508c2ecf20Sopenharmony_ci * @sd_limit: pointer to return the maximum number of segment descriptors 1518c2ecf20Sopenharmony_ci * 1528c2ecf20Sopenharmony_ci * This function calculates the segment descriptor index and index limit 1538c2ecf20Sopenharmony_ci * for the resource defined by i40e_hmc_rsrc_type. 1548c2ecf20Sopenharmony_ci **/ 1558c2ecf20Sopenharmony_ci#define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\ 1568c2ecf20Sopenharmony_ci{ \ 1578c2ecf20Sopenharmony_ci u64 fpm_addr, fpm_limit; \ 1588c2ecf20Sopenharmony_ci fpm_addr = (hmc_info)->hmc_obj[(type)].base + \ 1598c2ecf20Sopenharmony_ci (hmc_info)->hmc_obj[(type)].size * (index); \ 1608c2ecf20Sopenharmony_ci fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\ 1618c2ecf20Sopenharmony_ci *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \ 1628c2ecf20Sopenharmony_ci *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \ 1638c2ecf20Sopenharmony_ci /* add one more to the limit to correct our range */ \ 1648c2ecf20Sopenharmony_ci *(sd_limit) += 1; \ 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/** 1688c2ecf20Sopenharmony_ci * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit 1698c2ecf20Sopenharmony_ci * @hmc_info: pointer to the HMC configuration information struct 1708c2ecf20Sopenharmony_ci * @type: HMC resource type we're examining 1718c2ecf20Sopenharmony_ci * @idx: starting index for the object 1728c2ecf20Sopenharmony_ci * @cnt: number of objects we're trying to create 1738c2ecf20Sopenharmony_ci * @pd_index: pointer to return page descriptor index 1748c2ecf20Sopenharmony_ci * @pd_limit: pointer to return page descriptor index limit 1758c2ecf20Sopenharmony_ci * 1768c2ecf20Sopenharmony_ci * Calculates the page descriptor index and index limit for the resource 1778c2ecf20Sopenharmony_ci * defined by i40e_hmc_rsrc_type. 1788c2ecf20Sopenharmony_ci **/ 1798c2ecf20Sopenharmony_ci#define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\ 1808c2ecf20Sopenharmony_ci{ \ 1818c2ecf20Sopenharmony_ci u64 fpm_adr, fpm_limit; \ 1828c2ecf20Sopenharmony_ci fpm_adr = (hmc_info)->hmc_obj[(type)].base + \ 1838c2ecf20Sopenharmony_ci (hmc_info)->hmc_obj[(type)].size * (idx); \ 1848c2ecf20Sopenharmony_ci fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \ 1858c2ecf20Sopenharmony_ci *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \ 1868c2ecf20Sopenharmony_ci *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \ 1878c2ecf20Sopenharmony_ci /* add one more to the limit to correct our range */ \ 1888c2ecf20Sopenharmony_ci *(pd_limit) += 1; \ 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_cii40e_status i40e_add_sd_table_entry(struct i40e_hw *hw, 1918c2ecf20Sopenharmony_ci struct i40e_hmc_info *hmc_info, 1928c2ecf20Sopenharmony_ci u32 sd_index, 1938c2ecf20Sopenharmony_ci enum i40e_sd_entry_type type, 1948c2ecf20Sopenharmony_ci u64 direct_mode_sz); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cii40e_status i40e_add_pd_table_entry(struct i40e_hw *hw, 1978c2ecf20Sopenharmony_ci struct i40e_hmc_info *hmc_info, 1988c2ecf20Sopenharmony_ci u32 pd_index, 1998c2ecf20Sopenharmony_ci struct i40e_dma_mem *rsrc_pg); 2008c2ecf20Sopenharmony_cii40e_status i40e_remove_pd_bp(struct i40e_hw *hw, 2018c2ecf20Sopenharmony_ci struct i40e_hmc_info *hmc_info, 2028c2ecf20Sopenharmony_ci u32 idx); 2038c2ecf20Sopenharmony_cii40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info, 2048c2ecf20Sopenharmony_ci u32 idx); 2058c2ecf20Sopenharmony_cii40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw, 2068c2ecf20Sopenharmony_ci struct i40e_hmc_info *hmc_info, 2078c2ecf20Sopenharmony_ci u32 idx, bool is_pf); 2088c2ecf20Sopenharmony_cii40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info, 2098c2ecf20Sopenharmony_ci u32 idx); 2108c2ecf20Sopenharmony_cii40e_status i40e_remove_pd_page_new(struct i40e_hw *hw, 2118c2ecf20Sopenharmony_ci struct i40e_hmc_info *hmc_info, 2128c2ecf20Sopenharmony_ci u32 idx, bool is_pf); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#endif /* _I40E_HMC_H_ */ 215