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