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