161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 3*f4cc2d17SEric Joyner Copyright (c) 2013-2018, Intel Corporation 461ae650dSJack F Vogel All rights reserved. 561ae650dSJack F Vogel 661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without 761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met: 861ae650dSJack F Vogel 961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice, 1061ae650dSJack F Vogel this list of conditions and the following disclaimer. 1161ae650dSJack F Vogel 1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright 1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the 1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution. 1561ae650dSJack F Vogel 1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its 1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from 1861ae650dSJack F Vogel this software without specific prior written permission. 1961ae650dSJack F Vogel 2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE. 3161ae650dSJack F Vogel 3261ae650dSJack F Vogel ******************************************************************************/ 3361ae650dSJack F Vogel 3461ae650dSJack F Vogel #ifndef _I40E_HMC_H_ 3561ae650dSJack F Vogel #define _I40E_HMC_H_ 3661ae650dSJack F Vogel 3761ae650dSJack F Vogel #define I40E_HMC_MAX_BP_COUNT 512 3861ae650dSJack F Vogel 3961ae650dSJack F Vogel /* forward-declare the HW struct for the compiler */ 4061ae650dSJack F Vogel struct i40e_hw; 4161ae650dSJack F Vogel 4261ae650dSJack F Vogel #define I40E_HMC_INFO_SIGNATURE 0x484D5347 /* HMSG */ 4361ae650dSJack F Vogel #define I40E_HMC_PD_CNT_IN_SD 512 4461ae650dSJack F Vogel #define I40E_HMC_DIRECT_BP_SIZE 0x200000 /* 2M */ 4561ae650dSJack F Vogel #define I40E_HMC_PAGED_BP_SIZE 4096 4661ae650dSJack F Vogel #define I40E_HMC_PD_BP_BUF_ALIGNMENT 4096 4761ae650dSJack F Vogel #define I40E_FIRST_VF_FPM_ID 16 4861ae650dSJack F Vogel 4961ae650dSJack F Vogel struct i40e_hmc_obj_info { 5061ae650dSJack F Vogel u64 base; /* base addr in FPM */ 5161ae650dSJack F Vogel u32 max_cnt; /* max count available for this hmc func */ 5261ae650dSJack F Vogel u32 cnt; /* count of objects driver actually wants to create */ 5361ae650dSJack F Vogel u64 size; /* size in bytes of one object */ 5461ae650dSJack F Vogel }; 5561ae650dSJack F Vogel 5661ae650dSJack F Vogel enum i40e_sd_entry_type { 5761ae650dSJack F Vogel I40E_SD_TYPE_INVALID = 0, 5861ae650dSJack F Vogel I40E_SD_TYPE_PAGED = 1, 5961ae650dSJack F Vogel I40E_SD_TYPE_DIRECT = 2 6061ae650dSJack F Vogel }; 6161ae650dSJack F Vogel 6261ae650dSJack F Vogel struct i40e_hmc_bp { 6361ae650dSJack F Vogel enum i40e_sd_entry_type entry_type; 6461ae650dSJack F Vogel struct i40e_dma_mem addr; /* populate to be used by hw */ 6561ae650dSJack F Vogel u32 sd_pd_index; 6661ae650dSJack F Vogel u32 ref_cnt; 6761ae650dSJack F Vogel }; 6861ae650dSJack F Vogel 6961ae650dSJack F Vogel struct i40e_hmc_pd_entry { 7061ae650dSJack F Vogel struct i40e_hmc_bp bp; 7161ae650dSJack F Vogel u32 sd_index; 72be771cdaSJack F Vogel bool rsrc_pg; 7361ae650dSJack F Vogel bool valid; 7461ae650dSJack F Vogel }; 7561ae650dSJack F Vogel 7661ae650dSJack F Vogel struct i40e_hmc_pd_table { 7761ae650dSJack F Vogel struct i40e_dma_mem pd_page_addr; /* populate to be used by hw */ 7861ae650dSJack F Vogel struct i40e_hmc_pd_entry *pd_entry; /* [512] for sw book keeping */ 7961ae650dSJack F Vogel struct i40e_virt_mem pd_entry_virt_mem; /* virt mem for pd_entry */ 8061ae650dSJack F Vogel 8161ae650dSJack F Vogel u32 ref_cnt; 8261ae650dSJack F Vogel u32 sd_index; 8361ae650dSJack F Vogel }; 8461ae650dSJack F Vogel 8561ae650dSJack F Vogel struct i40e_hmc_sd_entry { 8661ae650dSJack F Vogel enum i40e_sd_entry_type entry_type; 8761ae650dSJack F Vogel bool valid; 8861ae650dSJack F Vogel 8961ae650dSJack F Vogel union { 9061ae650dSJack F Vogel struct i40e_hmc_pd_table pd_table; 9161ae650dSJack F Vogel struct i40e_hmc_bp bp; 9261ae650dSJack F Vogel } u; 9361ae650dSJack F Vogel }; 9461ae650dSJack F Vogel 9561ae650dSJack F Vogel struct i40e_hmc_sd_table { 9661ae650dSJack F Vogel struct i40e_virt_mem addr; /* used to track sd_entry allocations */ 9761ae650dSJack F Vogel u32 sd_cnt; 9861ae650dSJack F Vogel u32 ref_cnt; 9961ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; /* (sd_cnt*512) entries max */ 10061ae650dSJack F Vogel }; 10161ae650dSJack F Vogel 10261ae650dSJack F Vogel struct i40e_hmc_info { 10361ae650dSJack F Vogel u32 signature; 10461ae650dSJack F Vogel /* equals to pci func num for PF and dynamically allocated for VFs */ 10561ae650dSJack F Vogel u8 hmc_fn_id; 10661ae650dSJack F Vogel u16 first_sd_index; /* index of the first available SD */ 10761ae650dSJack F Vogel 10861ae650dSJack F Vogel /* hmc objects */ 10961ae650dSJack F Vogel struct i40e_hmc_obj_info *hmc_obj; 11061ae650dSJack F Vogel struct i40e_virt_mem hmc_obj_virt_mem; 11161ae650dSJack F Vogel struct i40e_hmc_sd_table sd_table; 11261ae650dSJack F Vogel }; 11361ae650dSJack F Vogel 11461ae650dSJack F Vogel #define I40E_INC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt++) 11561ae650dSJack F Vogel #define I40E_INC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt++) 11661ae650dSJack F Vogel #define I40E_INC_BP_REFCNT(bp) ((bp)->ref_cnt++) 11761ae650dSJack F Vogel 11861ae650dSJack F Vogel #define I40E_DEC_SD_REFCNT(sd_table) ((sd_table)->ref_cnt--) 11961ae650dSJack F Vogel #define I40E_DEC_PD_REFCNT(pd_table) ((pd_table)->ref_cnt--) 12061ae650dSJack F Vogel #define I40E_DEC_BP_REFCNT(bp) ((bp)->ref_cnt--) 12161ae650dSJack F Vogel 12261ae650dSJack F Vogel /** 12361ae650dSJack F Vogel * I40E_SET_PF_SD_ENTRY - marks the sd entry as valid in the hardware 12461ae650dSJack F Vogel * @hw: pointer to our hw struct 12561ae650dSJack F Vogel * @pa: pointer to physical address 12661ae650dSJack F Vogel * @sd_index: segment descriptor index 12761ae650dSJack F Vogel * @type: if sd entry is direct or paged 12861ae650dSJack F Vogel **/ 12961ae650dSJack F Vogel #define I40E_SET_PF_SD_ENTRY(hw, pa, sd_index, type) \ 13061ae650dSJack F Vogel { \ 13161ae650dSJack F Vogel u32 val1, val2, val3; \ 13261ae650dSJack F Vogel val1 = (u32)(I40E_HI_DWORD(pa)); \ 13361ae650dSJack F Vogel val2 = (u32)(pa) | (I40E_HMC_MAX_BP_COUNT << \ 13461ae650dSJack F Vogel I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 13561ae650dSJack F Vogel ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 13661ae650dSJack F Vogel I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT) | \ 137be771cdaSJack F Vogel BIT(I40E_PFHMC_SDDATALOW_PMSDVALID_SHIFT); \ 138be771cdaSJack F Vogel val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 13961ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDDATAHIGH, val1); \ 14061ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 14161ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDCMD, val3); \ 14261ae650dSJack F Vogel } 14361ae650dSJack F Vogel 14461ae650dSJack F Vogel /** 14561ae650dSJack F Vogel * I40E_CLEAR_PF_SD_ENTRY - marks the sd entry as invalid in the hardware 14661ae650dSJack F Vogel * @hw: pointer to our hw struct 14761ae650dSJack F Vogel * @sd_index: segment descriptor index 14861ae650dSJack F Vogel * @type: if sd entry is direct or paged 14961ae650dSJack F Vogel **/ 15061ae650dSJack F Vogel #define I40E_CLEAR_PF_SD_ENTRY(hw, sd_index, type) \ 15161ae650dSJack F Vogel { \ 15261ae650dSJack F Vogel u32 val2, val3; \ 15361ae650dSJack F Vogel val2 = (I40E_HMC_MAX_BP_COUNT << \ 15461ae650dSJack F Vogel I40E_PFHMC_SDDATALOW_PMSDBPCOUNT_SHIFT) | \ 15561ae650dSJack F Vogel ((((type) == I40E_SD_TYPE_PAGED) ? 0 : 1) << \ 15661ae650dSJack F Vogel I40E_PFHMC_SDDATALOW_PMSDTYPE_SHIFT); \ 157be771cdaSJack F Vogel val3 = (sd_index) | BIT_ULL(I40E_PFHMC_SDCMD_PMSDWR_SHIFT); \ 15861ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDDATAHIGH, 0); \ 15961ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDDATALOW, val2); \ 16061ae650dSJack F Vogel wr32((hw), I40E_PFHMC_SDCMD, val3); \ 16161ae650dSJack F Vogel } 16261ae650dSJack F Vogel 16361ae650dSJack F Vogel /** 16461ae650dSJack F Vogel * I40E_INVALIDATE_PF_HMC_PD - Invalidates the pd cache in the hardware 16561ae650dSJack F Vogel * @hw: pointer to our hw struct 16661ae650dSJack F Vogel * @sd_idx: segment descriptor index 16761ae650dSJack F Vogel * @pd_idx: page descriptor index 16861ae650dSJack F Vogel **/ 16961ae650dSJack F Vogel #define I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, pd_idx) \ 17061ae650dSJack F Vogel wr32((hw), I40E_PFHMC_PDINV, \ 17161ae650dSJack F Vogel (((sd_idx) << I40E_PFHMC_PDINV_PMSDIDX_SHIFT) | \ 17261ae650dSJack F Vogel ((pd_idx) << I40E_PFHMC_PDINV_PMPDIDX_SHIFT))) 17361ae650dSJack F Vogel 17461ae650dSJack F Vogel /** 17561ae650dSJack F Vogel * I40E_FIND_SD_INDEX_LIMIT - finds segment descriptor index limit 17661ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 17761ae650dSJack F Vogel * @type: type of HMC resources we're searching 17861ae650dSJack F Vogel * @index: starting index for the object 17961ae650dSJack F Vogel * @cnt: number of objects we're trying to create 18061ae650dSJack F Vogel * @sd_idx: pointer to return index of the segment descriptor in question 18161ae650dSJack F Vogel * @sd_limit: pointer to return the maximum number of segment descriptors 18261ae650dSJack F Vogel * 18361ae650dSJack F Vogel * This function calculates the segment descriptor index and index limit 18461ae650dSJack F Vogel * for the resource defined by i40e_hmc_rsrc_type. 18561ae650dSJack F Vogel **/ 18661ae650dSJack F Vogel #define I40E_FIND_SD_INDEX_LIMIT(hmc_info, type, index, cnt, sd_idx, sd_limit)\ 18761ae650dSJack F Vogel { \ 18861ae650dSJack F Vogel u64 fpm_addr, fpm_limit; \ 18961ae650dSJack F Vogel fpm_addr = (hmc_info)->hmc_obj[(type)].base + \ 19061ae650dSJack F Vogel (hmc_info)->hmc_obj[(type)].size * (index); \ 19161ae650dSJack F Vogel fpm_limit = fpm_addr + (hmc_info)->hmc_obj[(type)].size * (cnt);\ 19261ae650dSJack F Vogel *(sd_idx) = (u32)(fpm_addr / I40E_HMC_DIRECT_BP_SIZE); \ 19361ae650dSJack F Vogel *(sd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_DIRECT_BP_SIZE); \ 19461ae650dSJack F Vogel /* add one more to the limit to correct our range */ \ 19561ae650dSJack F Vogel *(sd_limit) += 1; \ 19661ae650dSJack F Vogel } 19761ae650dSJack F Vogel 19861ae650dSJack F Vogel /** 19961ae650dSJack F Vogel * I40E_FIND_PD_INDEX_LIMIT - finds page descriptor index limit 20061ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information struct 20161ae650dSJack F Vogel * @type: HMC resource type we're examining 20261ae650dSJack F Vogel * @idx: starting index for the object 20361ae650dSJack F Vogel * @cnt: number of objects we're trying to create 20461ae650dSJack F Vogel * @pd_index: pointer to return page descriptor index 20561ae650dSJack F Vogel * @pd_limit: pointer to return page descriptor index limit 20661ae650dSJack F Vogel * 20761ae650dSJack F Vogel * Calculates the page descriptor index and index limit for the resource 20861ae650dSJack F Vogel * defined by i40e_hmc_rsrc_type. 20961ae650dSJack F Vogel **/ 21061ae650dSJack F Vogel #define I40E_FIND_PD_INDEX_LIMIT(hmc_info, type, idx, cnt, pd_index, pd_limit)\ 21161ae650dSJack F Vogel { \ 21261ae650dSJack F Vogel u64 fpm_adr, fpm_limit; \ 21361ae650dSJack F Vogel fpm_adr = (hmc_info)->hmc_obj[(type)].base + \ 21461ae650dSJack F Vogel (hmc_info)->hmc_obj[(type)].size * (idx); \ 21561ae650dSJack F Vogel fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt); \ 21661ae650dSJack F Vogel *(pd_index) = (u32)(fpm_adr / I40E_HMC_PAGED_BP_SIZE); \ 21761ae650dSJack F Vogel *(pd_limit) = (u32)((fpm_limit - 1) / I40E_HMC_PAGED_BP_SIZE); \ 21861ae650dSJack F Vogel /* add one more to the limit to correct our range */ \ 21961ae650dSJack F Vogel *(pd_limit) += 1; \ 22061ae650dSJack F Vogel } 22161ae650dSJack F Vogel enum i40e_status_code i40e_add_sd_table_entry(struct i40e_hw *hw, 22261ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 22361ae650dSJack F Vogel u32 sd_index, 22461ae650dSJack F Vogel enum i40e_sd_entry_type type, 22561ae650dSJack F Vogel u64 direct_mode_sz); 22661ae650dSJack F Vogel 22761ae650dSJack F Vogel enum i40e_status_code i40e_add_pd_table_entry(struct i40e_hw *hw, 22861ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 229be771cdaSJack F Vogel u32 pd_index, 230be771cdaSJack F Vogel struct i40e_dma_mem *rsrc_pg); 23161ae650dSJack F Vogel enum i40e_status_code i40e_remove_pd_bp(struct i40e_hw *hw, 23261ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 23361ae650dSJack F Vogel u32 idx); 23461ae650dSJack F Vogel enum i40e_status_code i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info, 23561ae650dSJack F Vogel u32 idx); 23661ae650dSJack F Vogel enum i40e_status_code i40e_remove_sd_bp_new(struct i40e_hw *hw, 23761ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 23861ae650dSJack F Vogel u32 idx, bool is_pf); 23961ae650dSJack F Vogel enum i40e_status_code i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info, 24061ae650dSJack F Vogel u32 idx); 24161ae650dSJack F Vogel enum i40e_status_code i40e_remove_pd_page_new(struct i40e_hw *hw, 24261ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 24361ae650dSJack F Vogel u32 idx, bool is_pf); 24461ae650dSJack F Vogel 24561ae650dSJack F Vogel #endif /* _I40E_HMC_H_ */ 246