0001
0002
0003
0004 #include "i40e.h"
0005 #include "i40e_osdep.h"
0006 #include "i40e_register.h"
0007 #include "i40e_status.h"
0008 #include "i40e_alloc.h"
0009 #include "i40e_hmc.h"
0010 #include "i40e_type.h"
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw,
0021 struct i40e_hmc_info *hmc_info,
0022 u32 sd_index,
0023 enum i40e_sd_entry_type type,
0024 u64 direct_mode_sz)
0025 {
0026 enum i40e_memory_type mem_type __attribute__((unused));
0027 struct i40e_hmc_sd_entry *sd_entry;
0028 bool dma_mem_alloc_done = false;
0029 struct i40e_dma_mem mem;
0030 i40e_status ret_code = I40E_SUCCESS;
0031 u64 alloc_len;
0032
0033 if (NULL == hmc_info->sd_table.sd_entry) {
0034 ret_code = I40E_ERR_BAD_PTR;
0035 hw_dbg(hw, "i40e_add_sd_table_entry: bad sd_entry\n");
0036 goto exit;
0037 }
0038
0039 if (sd_index >= hmc_info->sd_table.sd_cnt) {
0040 ret_code = I40E_ERR_INVALID_SD_INDEX;
0041 hw_dbg(hw, "i40e_add_sd_table_entry: bad sd_index\n");
0042 goto exit;
0043 }
0044
0045 sd_entry = &hmc_info->sd_table.sd_entry[sd_index];
0046 if (!sd_entry->valid) {
0047 if (I40E_SD_TYPE_PAGED == type) {
0048 mem_type = i40e_mem_pd;
0049 alloc_len = I40E_HMC_PAGED_BP_SIZE;
0050 } else {
0051 mem_type = i40e_mem_bp_jumbo;
0052 alloc_len = direct_mode_sz;
0053 }
0054
0055
0056 ret_code = i40e_allocate_dma_mem(hw, &mem, mem_type, alloc_len,
0057 I40E_HMC_PD_BP_BUF_ALIGNMENT);
0058 if (ret_code)
0059 goto exit;
0060 dma_mem_alloc_done = true;
0061 if (I40E_SD_TYPE_PAGED == type) {
0062 ret_code = i40e_allocate_virt_mem(hw,
0063 &sd_entry->u.pd_table.pd_entry_virt_mem,
0064 sizeof(struct i40e_hmc_pd_entry) * 512);
0065 if (ret_code)
0066 goto exit;
0067 sd_entry->u.pd_table.pd_entry =
0068 (struct i40e_hmc_pd_entry *)
0069 sd_entry->u.pd_table.pd_entry_virt_mem.va;
0070 sd_entry->u.pd_table.pd_page_addr = mem;
0071 } else {
0072 sd_entry->u.bp.addr = mem;
0073 sd_entry->u.bp.sd_pd_index = sd_index;
0074 }
0075
0076 hmc_info->sd_table.sd_entry[sd_index].entry_type = type;
0077
0078
0079 I40E_INC_SD_REFCNT(&hmc_info->sd_table);
0080 }
0081
0082 if (I40E_SD_TYPE_DIRECT == sd_entry->entry_type)
0083 I40E_INC_BP_REFCNT(&sd_entry->u.bp);
0084 exit:
0085 if (ret_code)
0086 if (dma_mem_alloc_done)
0087 i40e_free_dma_mem(hw, &mem);
0088
0089 return ret_code;
0090 }
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw,
0110 struct i40e_hmc_info *hmc_info,
0111 u32 pd_index,
0112 struct i40e_dma_mem *rsrc_pg)
0113 {
0114 i40e_status ret_code = 0;
0115 struct i40e_hmc_pd_table *pd_table;
0116 struct i40e_hmc_pd_entry *pd_entry;
0117 struct i40e_dma_mem mem;
0118 struct i40e_dma_mem *page = &mem;
0119 u32 sd_idx, rel_pd_idx;
0120 u64 *pd_addr;
0121 u64 page_desc;
0122
0123 if (pd_index / I40E_HMC_PD_CNT_IN_SD >= hmc_info->sd_table.sd_cnt) {
0124 ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX;
0125 hw_dbg(hw, "i40e_add_pd_table_entry: bad pd_index\n");
0126 goto exit;
0127 }
0128
0129
0130 sd_idx = (pd_index / I40E_HMC_PD_CNT_IN_SD);
0131 if (I40E_SD_TYPE_PAGED !=
0132 hmc_info->sd_table.sd_entry[sd_idx].entry_type)
0133 goto exit;
0134
0135 rel_pd_idx = (pd_index % I40E_HMC_PD_CNT_IN_SD);
0136 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
0137 pd_entry = &pd_table->pd_entry[rel_pd_idx];
0138 if (!pd_entry->valid) {
0139 if (rsrc_pg) {
0140 pd_entry->rsrc_pg = true;
0141 page = rsrc_pg;
0142 } else {
0143
0144 ret_code = i40e_allocate_dma_mem(hw, page, i40e_mem_bp,
0145 I40E_HMC_PAGED_BP_SIZE,
0146 I40E_HMC_PD_BP_BUF_ALIGNMENT);
0147 if (ret_code)
0148 goto exit;
0149 pd_entry->rsrc_pg = false;
0150 }
0151
0152 pd_entry->bp.addr = *page;
0153 pd_entry->bp.sd_pd_index = pd_index;
0154 pd_entry->bp.entry_type = I40E_SD_TYPE_PAGED;
0155
0156 page_desc = page->pa | 0x1;
0157
0158 pd_addr = (u64 *)pd_table->pd_page_addr.va;
0159 pd_addr += rel_pd_idx;
0160
0161
0162 memcpy(pd_addr, &page_desc, sizeof(u64));
0163
0164 pd_entry->sd_index = sd_idx;
0165 pd_entry->valid = true;
0166 I40E_INC_PD_REFCNT(pd_table);
0167 }
0168 I40E_INC_BP_REFCNT(&pd_entry->bp);
0169 exit:
0170 return ret_code;
0171 }
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 i40e_status i40e_remove_pd_bp(struct i40e_hw *hw,
0189 struct i40e_hmc_info *hmc_info,
0190 u32 idx)
0191 {
0192 i40e_status ret_code = 0;
0193 struct i40e_hmc_pd_entry *pd_entry;
0194 struct i40e_hmc_pd_table *pd_table;
0195 struct i40e_hmc_sd_entry *sd_entry;
0196 u32 sd_idx, rel_pd_idx;
0197 u64 *pd_addr;
0198
0199
0200 sd_idx = idx / I40E_HMC_PD_CNT_IN_SD;
0201 rel_pd_idx = idx % I40E_HMC_PD_CNT_IN_SD;
0202 if (sd_idx >= hmc_info->sd_table.sd_cnt) {
0203 ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX;
0204 hw_dbg(hw, "i40e_remove_pd_bp: bad idx\n");
0205 goto exit;
0206 }
0207 sd_entry = &hmc_info->sd_table.sd_entry[sd_idx];
0208 if (I40E_SD_TYPE_PAGED != sd_entry->entry_type) {
0209 ret_code = I40E_ERR_INVALID_SD_TYPE;
0210 hw_dbg(hw, "i40e_remove_pd_bp: wrong sd_entry type\n");
0211 goto exit;
0212 }
0213
0214 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
0215 pd_entry = &pd_table->pd_entry[rel_pd_idx];
0216 I40E_DEC_BP_REFCNT(&pd_entry->bp);
0217 if (pd_entry->bp.ref_cnt)
0218 goto exit;
0219
0220
0221 pd_entry->valid = false;
0222 I40E_DEC_PD_REFCNT(pd_table);
0223 pd_addr = (u64 *)pd_table->pd_page_addr.va;
0224 pd_addr += rel_pd_idx;
0225 memset(pd_addr, 0, sizeof(u64));
0226 I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, idx);
0227
0228
0229 if (!pd_entry->rsrc_pg)
0230 ret_code = i40e_free_dma_mem(hw, &pd_entry->bp.addr);
0231 if (ret_code)
0232 goto exit;
0233 if (!pd_table->ref_cnt)
0234 i40e_free_virt_mem(hw, &pd_table->pd_entry_virt_mem);
0235 exit:
0236 return ret_code;
0237 }
0238
0239
0240
0241
0242
0243
0244 i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info,
0245 u32 idx)
0246 {
0247 i40e_status ret_code = 0;
0248 struct i40e_hmc_sd_entry *sd_entry;
0249
0250
0251 sd_entry = &hmc_info->sd_table.sd_entry[idx];
0252 I40E_DEC_BP_REFCNT(&sd_entry->u.bp);
0253 if (sd_entry->u.bp.ref_cnt) {
0254 ret_code = I40E_ERR_NOT_READY;
0255 goto exit;
0256 }
0257 I40E_DEC_SD_REFCNT(&hmc_info->sd_table);
0258
0259
0260 sd_entry->valid = false;
0261 exit:
0262 return ret_code;
0263 }
0264
0265
0266
0267
0268
0269
0270
0271
0272 i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw,
0273 struct i40e_hmc_info *hmc_info,
0274 u32 idx, bool is_pf)
0275 {
0276 struct i40e_hmc_sd_entry *sd_entry;
0277
0278 if (!is_pf)
0279 return I40E_NOT_SUPPORTED;
0280
0281
0282 sd_entry = &hmc_info->sd_table.sd_entry[idx];
0283 I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_DIRECT);
0284
0285 return i40e_free_dma_mem(hw, &sd_entry->u.bp.addr);
0286 }
0287
0288
0289
0290
0291
0292
0293 i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info,
0294 u32 idx)
0295 {
0296 i40e_status ret_code = 0;
0297 struct i40e_hmc_sd_entry *sd_entry;
0298
0299 sd_entry = &hmc_info->sd_table.sd_entry[idx];
0300
0301 if (sd_entry->u.pd_table.ref_cnt) {
0302 ret_code = I40E_ERR_NOT_READY;
0303 goto exit;
0304 }
0305
0306
0307 sd_entry->valid = false;
0308
0309 I40E_DEC_SD_REFCNT(&hmc_info->sd_table);
0310 exit:
0311 return ret_code;
0312 }
0313
0314
0315
0316
0317
0318
0319
0320
0321 i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw,
0322 struct i40e_hmc_info *hmc_info,
0323 u32 idx, bool is_pf)
0324 {
0325 struct i40e_hmc_sd_entry *sd_entry;
0326
0327 if (!is_pf)
0328 return I40E_NOT_SUPPORTED;
0329
0330 sd_entry = &hmc_info->sd_table.sd_entry[idx];
0331 I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_PAGED);
0332
0333 return i40e_free_dma_mem(hw, &sd_entry->u.pd_table.pd_page_addr);
0334 }