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 /*$FreeBSD$*/ 3461ae650dSJack F Vogel 3561ae650dSJack F Vogel #include "i40e_osdep.h" 3661ae650dSJack F Vogel #include "i40e_register.h" 3761ae650dSJack F Vogel #include "i40e_status.h" 3861ae650dSJack F Vogel #include "i40e_alloc.h" 3961ae650dSJack F Vogel #include "i40e_hmc.h" 4061ae650dSJack F Vogel #include "i40e_type.h" 4161ae650dSJack F Vogel 4261ae650dSJack F Vogel /** 4361ae650dSJack F Vogel * i40e_add_sd_table_entry - Adds a segment descriptor to the table 4461ae650dSJack F Vogel * @hw: pointer to our hw struct 4561ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information struct 4661ae650dSJack F Vogel * @sd_index: segment descriptor index to manipulate 4761ae650dSJack F Vogel * @type: what type of segment descriptor we're manipulating 4861ae650dSJack F Vogel * @direct_mode_sz: size to alloc in direct mode 4961ae650dSJack F Vogel **/ 5061ae650dSJack F Vogel enum i40e_status_code i40e_add_sd_table_entry(struct i40e_hw *hw, 5161ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 5261ae650dSJack F Vogel u32 sd_index, 5361ae650dSJack F Vogel enum i40e_sd_entry_type type, 5461ae650dSJack F Vogel u64 direct_mode_sz) 5561ae650dSJack F Vogel { 5661ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS; 5761ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 5861ae650dSJack F Vogel enum i40e_memory_type mem_type; 5961ae650dSJack F Vogel bool dma_mem_alloc_done = FALSE; 6061ae650dSJack F Vogel struct i40e_dma_mem mem; 6161ae650dSJack F Vogel u64 alloc_len; 6261ae650dSJack F Vogel 6361ae650dSJack F Vogel if (NULL == hmc_info->sd_table.sd_entry) { 6461ae650dSJack F Vogel ret_code = I40E_ERR_BAD_PTR; 6561ae650dSJack F Vogel DEBUGOUT("i40e_add_sd_table_entry: bad sd_entry\n"); 6661ae650dSJack F Vogel goto exit; 6761ae650dSJack F Vogel } 6861ae650dSJack F Vogel 6961ae650dSJack F Vogel if (sd_index >= hmc_info->sd_table.sd_cnt) { 7061ae650dSJack F Vogel ret_code = I40E_ERR_INVALID_SD_INDEX; 7161ae650dSJack F Vogel DEBUGOUT("i40e_add_sd_table_entry: bad sd_index\n"); 7261ae650dSJack F Vogel goto exit; 7361ae650dSJack F Vogel } 7461ae650dSJack F Vogel 7561ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[sd_index]; 7661ae650dSJack F Vogel if (!sd_entry->valid) { 7761ae650dSJack F Vogel if (I40E_SD_TYPE_PAGED == type) { 7861ae650dSJack F Vogel mem_type = i40e_mem_pd; 7961ae650dSJack F Vogel alloc_len = I40E_HMC_PAGED_BP_SIZE; 8061ae650dSJack F Vogel } else { 8161ae650dSJack F Vogel mem_type = i40e_mem_bp_jumbo; 8261ae650dSJack F Vogel alloc_len = direct_mode_sz; 8361ae650dSJack F Vogel } 8461ae650dSJack F Vogel 8561ae650dSJack F Vogel /* allocate a 4K pd page or 2M backing page */ 8661ae650dSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, &mem, mem_type, alloc_len, 8761ae650dSJack F Vogel I40E_HMC_PD_BP_BUF_ALIGNMENT); 8861ae650dSJack F Vogel if (ret_code) 8961ae650dSJack F Vogel goto exit; 9061ae650dSJack F Vogel dma_mem_alloc_done = TRUE; 9161ae650dSJack F Vogel if (I40E_SD_TYPE_PAGED == type) { 9261ae650dSJack F Vogel ret_code = i40e_allocate_virt_mem(hw, 9361ae650dSJack F Vogel &sd_entry->u.pd_table.pd_entry_virt_mem, 9461ae650dSJack F Vogel sizeof(struct i40e_hmc_pd_entry) * 512); 9561ae650dSJack F Vogel if (ret_code) 9661ae650dSJack F Vogel goto exit; 9761ae650dSJack F Vogel sd_entry->u.pd_table.pd_entry = 9861ae650dSJack F Vogel (struct i40e_hmc_pd_entry *) 9961ae650dSJack F Vogel sd_entry->u.pd_table.pd_entry_virt_mem.va; 10061ae650dSJack F Vogel i40e_memcpy(&sd_entry->u.pd_table.pd_page_addr, 10161ae650dSJack F Vogel &mem, sizeof(struct i40e_dma_mem), 10261ae650dSJack F Vogel I40E_NONDMA_TO_NONDMA); 10361ae650dSJack F Vogel } else { 10461ae650dSJack F Vogel i40e_memcpy(&sd_entry->u.bp.addr, 10561ae650dSJack F Vogel &mem, sizeof(struct i40e_dma_mem), 10661ae650dSJack F Vogel I40E_NONDMA_TO_NONDMA); 10761ae650dSJack F Vogel sd_entry->u.bp.sd_pd_index = sd_index; 10861ae650dSJack F Vogel } 10961ae650dSJack F Vogel /* initialize the sd entry */ 11061ae650dSJack F Vogel hmc_info->sd_table.sd_entry[sd_index].entry_type = type; 11161ae650dSJack F Vogel 11261ae650dSJack F Vogel /* increment the ref count */ 11361ae650dSJack F Vogel I40E_INC_SD_REFCNT(&hmc_info->sd_table); 11461ae650dSJack F Vogel } 11561ae650dSJack F Vogel /* Increment backing page reference count */ 11661ae650dSJack F Vogel if (I40E_SD_TYPE_DIRECT == sd_entry->entry_type) 11761ae650dSJack F Vogel I40E_INC_BP_REFCNT(&sd_entry->u.bp); 11861ae650dSJack F Vogel exit: 11961ae650dSJack F Vogel if (I40E_SUCCESS != ret_code) 12061ae650dSJack F Vogel if (dma_mem_alloc_done) 12161ae650dSJack F Vogel i40e_free_dma_mem(hw, &mem); 12261ae650dSJack F Vogel 12361ae650dSJack F Vogel return ret_code; 12461ae650dSJack F Vogel } 12561ae650dSJack F Vogel 12661ae650dSJack F Vogel /** 12761ae650dSJack F Vogel * i40e_add_pd_table_entry - Adds page descriptor to the specified table 12861ae650dSJack F Vogel * @hw: pointer to our HW structure 12961ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 13061ae650dSJack F Vogel * @pd_index: which page descriptor index to manipulate 131be771cdaSJack F Vogel * @rsrc_pg: if not NULL, use preallocated page instead of allocating new one. 13261ae650dSJack F Vogel * 13361ae650dSJack F Vogel * This function: 13461ae650dSJack F Vogel * 1. Initializes the pd entry 13561ae650dSJack F Vogel * 2. Adds pd_entry in the pd_table 13661ae650dSJack F Vogel * 3. Mark the entry valid in i40e_hmc_pd_entry structure 13761ae650dSJack F Vogel * 4. Initializes the pd_entry's ref count to 1 13861ae650dSJack F Vogel * assumptions: 13961ae650dSJack F Vogel * 1. The memory for pd should be pinned down, physically contiguous and 14061ae650dSJack F Vogel * aligned on 4K boundary and zeroed memory. 14161ae650dSJack F Vogel * 2. It should be 4K in size. 14261ae650dSJack F Vogel **/ 14361ae650dSJack F Vogel enum i40e_status_code i40e_add_pd_table_entry(struct i40e_hw *hw, 14461ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 145be771cdaSJack F Vogel u32 pd_index, 146be771cdaSJack F Vogel struct i40e_dma_mem *rsrc_pg) 14761ae650dSJack F Vogel { 14861ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS; 14961ae650dSJack F Vogel struct i40e_hmc_pd_table *pd_table; 15061ae650dSJack F Vogel struct i40e_hmc_pd_entry *pd_entry; 15161ae650dSJack F Vogel struct i40e_dma_mem mem; 152be771cdaSJack F Vogel struct i40e_dma_mem *page = &mem; 15361ae650dSJack F Vogel u32 sd_idx, rel_pd_idx; 15461ae650dSJack F Vogel u64 *pd_addr; 15561ae650dSJack F Vogel u64 page_desc; 15661ae650dSJack F Vogel 15761ae650dSJack F Vogel if (pd_index / I40E_HMC_PD_CNT_IN_SD >= hmc_info->sd_table.sd_cnt) { 15861ae650dSJack F Vogel ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX; 15961ae650dSJack F Vogel DEBUGOUT("i40e_add_pd_table_entry: bad pd_index\n"); 16061ae650dSJack F Vogel goto exit; 16161ae650dSJack F Vogel } 16261ae650dSJack F Vogel 16361ae650dSJack F Vogel /* find corresponding sd */ 16461ae650dSJack F Vogel sd_idx = (pd_index / I40E_HMC_PD_CNT_IN_SD); 16561ae650dSJack F Vogel if (I40E_SD_TYPE_PAGED != 16661ae650dSJack F Vogel hmc_info->sd_table.sd_entry[sd_idx].entry_type) 16761ae650dSJack F Vogel goto exit; 16861ae650dSJack F Vogel 16961ae650dSJack F Vogel rel_pd_idx = (pd_index % I40E_HMC_PD_CNT_IN_SD); 17061ae650dSJack F Vogel pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table; 17161ae650dSJack F Vogel pd_entry = &pd_table->pd_entry[rel_pd_idx]; 17261ae650dSJack F Vogel if (!pd_entry->valid) { 173be771cdaSJack F Vogel if (rsrc_pg) { 174be771cdaSJack F Vogel pd_entry->rsrc_pg = TRUE; 175be771cdaSJack F Vogel page = rsrc_pg; 176be771cdaSJack F Vogel } else { 17761ae650dSJack F Vogel /* allocate a 4K backing page */ 178be771cdaSJack F Vogel ret_code = i40e_allocate_dma_mem(hw, page, i40e_mem_bp, 17961ae650dSJack F Vogel I40E_HMC_PAGED_BP_SIZE, 18061ae650dSJack F Vogel I40E_HMC_PD_BP_BUF_ALIGNMENT); 18161ae650dSJack F Vogel if (ret_code) 18261ae650dSJack F Vogel goto exit; 183be771cdaSJack F Vogel pd_entry->rsrc_pg = FALSE; 184be771cdaSJack F Vogel } 18561ae650dSJack F Vogel 186be771cdaSJack F Vogel i40e_memcpy(&pd_entry->bp.addr, page, 18761ae650dSJack F Vogel sizeof(struct i40e_dma_mem), I40E_NONDMA_TO_NONDMA); 18861ae650dSJack F Vogel pd_entry->bp.sd_pd_index = pd_index; 18961ae650dSJack F Vogel pd_entry->bp.entry_type = I40E_SD_TYPE_PAGED; 19061ae650dSJack F Vogel /* Set page address and valid bit */ 191be771cdaSJack F Vogel page_desc = page->pa | 0x1; 19261ae650dSJack F Vogel 19361ae650dSJack F Vogel pd_addr = (u64 *)pd_table->pd_page_addr.va; 19461ae650dSJack F Vogel pd_addr += rel_pd_idx; 19561ae650dSJack F Vogel 19661ae650dSJack F Vogel /* Add the backing page physical address in the pd entry */ 19761ae650dSJack F Vogel i40e_memcpy(pd_addr, &page_desc, sizeof(u64), 19861ae650dSJack F Vogel I40E_NONDMA_TO_DMA); 19961ae650dSJack F Vogel 20061ae650dSJack F Vogel pd_entry->sd_index = sd_idx; 20161ae650dSJack F Vogel pd_entry->valid = TRUE; 20261ae650dSJack F Vogel I40E_INC_PD_REFCNT(pd_table); 20361ae650dSJack F Vogel } 20461ae650dSJack F Vogel I40E_INC_BP_REFCNT(&pd_entry->bp); 20561ae650dSJack F Vogel exit: 20661ae650dSJack F Vogel return ret_code; 20761ae650dSJack F Vogel } 20861ae650dSJack F Vogel 20961ae650dSJack F Vogel /** 21061ae650dSJack F Vogel * i40e_remove_pd_bp - remove a backing page from a page descriptor 21161ae650dSJack F Vogel * @hw: pointer to our HW structure 21261ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 21361ae650dSJack F Vogel * @idx: the page index 21461ae650dSJack F Vogel * 21561ae650dSJack F Vogel * This function: 21661ae650dSJack F Vogel * 1. Marks the entry in pd tabe (for paged address mode) or in sd table 21761ae650dSJack F Vogel * (for direct address mode) invalid. 21861ae650dSJack F Vogel * 2. Write to register PMPDINV to invalidate the backing page in FV cache 21961ae650dSJack F Vogel * 3. Decrement the ref count for the pd _entry 22061ae650dSJack F Vogel * assumptions: 22161ae650dSJack F Vogel * 1. Caller can deallocate the memory used by backing storage after this 22261ae650dSJack F Vogel * function returns. 22361ae650dSJack F Vogel **/ 22461ae650dSJack F Vogel enum i40e_status_code i40e_remove_pd_bp(struct i40e_hw *hw, 22561ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 22661ae650dSJack F Vogel u32 idx) 22761ae650dSJack F Vogel { 22861ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS; 22961ae650dSJack F Vogel struct i40e_hmc_pd_entry *pd_entry; 23061ae650dSJack F Vogel struct i40e_hmc_pd_table *pd_table; 23161ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 23261ae650dSJack F Vogel u32 sd_idx, rel_pd_idx; 23361ae650dSJack F Vogel u64 *pd_addr; 23461ae650dSJack F Vogel 23561ae650dSJack F Vogel /* calculate index */ 23661ae650dSJack F Vogel sd_idx = idx / I40E_HMC_PD_CNT_IN_SD; 23761ae650dSJack F Vogel rel_pd_idx = idx % I40E_HMC_PD_CNT_IN_SD; 23861ae650dSJack F Vogel if (sd_idx >= hmc_info->sd_table.sd_cnt) { 23961ae650dSJack F Vogel ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX; 24061ae650dSJack F Vogel DEBUGOUT("i40e_remove_pd_bp: bad idx\n"); 24161ae650dSJack F Vogel goto exit; 24261ae650dSJack F Vogel } 24361ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[sd_idx]; 24461ae650dSJack F Vogel if (I40E_SD_TYPE_PAGED != sd_entry->entry_type) { 24561ae650dSJack F Vogel ret_code = I40E_ERR_INVALID_SD_TYPE; 24661ae650dSJack F Vogel DEBUGOUT("i40e_remove_pd_bp: wrong sd_entry type\n"); 24761ae650dSJack F Vogel goto exit; 24861ae650dSJack F Vogel } 24961ae650dSJack F Vogel /* get the entry and decrease its ref counter */ 25061ae650dSJack F Vogel pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table; 25161ae650dSJack F Vogel pd_entry = &pd_table->pd_entry[rel_pd_idx]; 25261ae650dSJack F Vogel I40E_DEC_BP_REFCNT(&pd_entry->bp); 25361ae650dSJack F Vogel if (pd_entry->bp.ref_cnt) 25461ae650dSJack F Vogel goto exit; 25561ae650dSJack F Vogel 25661ae650dSJack F Vogel /* mark the entry invalid */ 25761ae650dSJack F Vogel pd_entry->valid = FALSE; 25861ae650dSJack F Vogel I40E_DEC_PD_REFCNT(pd_table); 25961ae650dSJack F Vogel pd_addr = (u64 *)pd_table->pd_page_addr.va; 26061ae650dSJack F Vogel pd_addr += rel_pd_idx; 26161ae650dSJack F Vogel i40e_memset(pd_addr, 0, sizeof(u64), I40E_DMA_MEM); 26261ae650dSJack F Vogel I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, idx); 26361ae650dSJack F Vogel 26461ae650dSJack F Vogel /* free memory here */ 265be771cdaSJack F Vogel if (!pd_entry->rsrc_pg) 26661ae650dSJack F Vogel ret_code = i40e_free_dma_mem(hw, &(pd_entry->bp.addr)); 26761ae650dSJack F Vogel if (I40E_SUCCESS != ret_code) 26861ae650dSJack F Vogel goto exit; 26961ae650dSJack F Vogel if (!pd_table->ref_cnt) 27061ae650dSJack F Vogel i40e_free_virt_mem(hw, &pd_table->pd_entry_virt_mem); 27161ae650dSJack F Vogel exit: 27261ae650dSJack F Vogel return ret_code; 27361ae650dSJack F Vogel } 27461ae650dSJack F Vogel 27561ae650dSJack F Vogel /** 27661ae650dSJack F Vogel * i40e_prep_remove_sd_bp - Prepares to remove a backing page from a sd entry 27761ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 27861ae650dSJack F Vogel * @idx: the page index 27961ae650dSJack F Vogel **/ 28061ae650dSJack F Vogel enum i40e_status_code i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info, 28161ae650dSJack F Vogel u32 idx) 28261ae650dSJack F Vogel { 28361ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS; 28461ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 28561ae650dSJack F Vogel 28661ae650dSJack F Vogel /* get the entry and decrease its ref counter */ 28761ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[idx]; 28861ae650dSJack F Vogel I40E_DEC_BP_REFCNT(&sd_entry->u.bp); 28961ae650dSJack F Vogel if (sd_entry->u.bp.ref_cnt) { 29061ae650dSJack F Vogel ret_code = I40E_ERR_NOT_READY; 29161ae650dSJack F Vogel goto exit; 29261ae650dSJack F Vogel } 29361ae650dSJack F Vogel I40E_DEC_SD_REFCNT(&hmc_info->sd_table); 29461ae650dSJack F Vogel 29561ae650dSJack F Vogel /* mark the entry invalid */ 29661ae650dSJack F Vogel sd_entry->valid = FALSE; 29761ae650dSJack F Vogel exit: 29861ae650dSJack F Vogel return ret_code; 29961ae650dSJack F Vogel } 30061ae650dSJack F Vogel 30161ae650dSJack F Vogel /** 30261ae650dSJack F Vogel * i40e_remove_sd_bp_new - Removes a backing page from a segment descriptor 30361ae650dSJack F Vogel * @hw: pointer to our hw struct 30461ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 30561ae650dSJack F Vogel * @idx: the page index 30661ae650dSJack F Vogel * @is_pf: used to distinguish between VF and PF 30761ae650dSJack F Vogel **/ 30861ae650dSJack F Vogel enum i40e_status_code i40e_remove_sd_bp_new(struct i40e_hw *hw, 30961ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 31061ae650dSJack F Vogel u32 idx, bool is_pf) 31161ae650dSJack F Vogel { 31261ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 313be771cdaSJack F Vogel 314be771cdaSJack F Vogel if (!is_pf) 315be771cdaSJack F Vogel return I40E_NOT_SUPPORTED; 31661ae650dSJack F Vogel 31761ae650dSJack F Vogel /* get the entry and decrease its ref counter */ 31861ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[idx]; 31961ae650dSJack F Vogel I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_DIRECT); 320be771cdaSJack F Vogel 321be771cdaSJack F Vogel return i40e_free_dma_mem(hw, &(sd_entry->u.bp.addr)); 32261ae650dSJack F Vogel } 32361ae650dSJack F Vogel 32461ae650dSJack F Vogel /** 32561ae650dSJack F Vogel * i40e_prep_remove_pd_page - Prepares to remove a PD page from sd entry. 32661ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 32761ae650dSJack F Vogel * @idx: segment descriptor index to find the relevant page descriptor 32861ae650dSJack F Vogel **/ 32961ae650dSJack F Vogel enum i40e_status_code i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info, 33061ae650dSJack F Vogel u32 idx) 33161ae650dSJack F Vogel { 33261ae650dSJack F Vogel enum i40e_status_code ret_code = I40E_SUCCESS; 33361ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 33461ae650dSJack F Vogel 33561ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[idx]; 33661ae650dSJack F Vogel 33761ae650dSJack F Vogel if (sd_entry->u.pd_table.ref_cnt) { 33861ae650dSJack F Vogel ret_code = I40E_ERR_NOT_READY; 33961ae650dSJack F Vogel goto exit; 34061ae650dSJack F Vogel } 34161ae650dSJack F Vogel 34261ae650dSJack F Vogel /* mark the entry invalid */ 34361ae650dSJack F Vogel sd_entry->valid = FALSE; 34461ae650dSJack F Vogel 34561ae650dSJack F Vogel I40E_DEC_SD_REFCNT(&hmc_info->sd_table); 34661ae650dSJack F Vogel exit: 34761ae650dSJack F Vogel return ret_code; 34861ae650dSJack F Vogel } 34961ae650dSJack F Vogel 35061ae650dSJack F Vogel /** 35161ae650dSJack F Vogel * i40e_remove_pd_page_new - Removes a PD page from sd entry. 35261ae650dSJack F Vogel * @hw: pointer to our hw struct 35361ae650dSJack F Vogel * @hmc_info: pointer to the HMC configuration information structure 35461ae650dSJack F Vogel * @idx: segment descriptor index to find the relevant page descriptor 35561ae650dSJack F Vogel * @is_pf: used to distinguish between VF and PF 35661ae650dSJack F Vogel **/ 35761ae650dSJack F Vogel enum i40e_status_code i40e_remove_pd_page_new(struct i40e_hw *hw, 35861ae650dSJack F Vogel struct i40e_hmc_info *hmc_info, 35961ae650dSJack F Vogel u32 idx, bool is_pf) 36061ae650dSJack F Vogel { 36161ae650dSJack F Vogel struct i40e_hmc_sd_entry *sd_entry; 36261ae650dSJack F Vogel 363be771cdaSJack F Vogel if (!is_pf) 364be771cdaSJack F Vogel return I40E_NOT_SUPPORTED; 365be771cdaSJack F Vogel 36661ae650dSJack F Vogel sd_entry = &hmc_info->sd_table.sd_entry[idx]; 36761ae650dSJack F Vogel I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_PAGED); 368be771cdaSJack F Vogel 369be771cdaSJack F Vogel return i40e_free_dma_mem(hw, &(sd_entry->u.pd_table.pd_page_addr)); 37061ae650dSJack F Vogel } 371