1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "i40e_osdep.h"
28#include "i40e_register.h"
29#include "i40e_status.h"
30#include "i40e_alloc.h"
31#include "i40e_hmc.h"
32#include "i40e_type.h"
33
34
35
36
37
38
39
40
41
42i40e_status i40e_add_sd_table_entry(struct i40e_hw *hw,
43 struct i40e_hmc_info *hmc_info,
44 u32 sd_index,
45 enum i40e_sd_entry_type type,
46 u64 direct_mode_sz)
47{
48 enum i40e_memory_type mem_type __attribute__((unused));
49 struct i40e_hmc_sd_entry *sd_entry;
50 bool dma_mem_alloc_done = false;
51 struct i40e_dma_mem mem;
52 i40e_status ret_code;
53 u64 alloc_len;
54
55 if (NULL == hmc_info->sd_table.sd_entry) {
56 ret_code = I40E_ERR_BAD_PTR;
57 hw_dbg(hw, "i40e_add_sd_table_entry: bad sd_entry\n");
58 goto exit;
59 }
60
61 if (sd_index >= hmc_info->sd_table.sd_cnt) {
62 ret_code = I40E_ERR_INVALID_SD_INDEX;
63 hw_dbg(hw, "i40e_add_sd_table_entry: bad sd_index\n");
64 goto exit;
65 }
66
67 sd_entry = &hmc_info->sd_table.sd_entry[sd_index];
68 if (!sd_entry->valid) {
69 if (I40E_SD_TYPE_PAGED == type) {
70 mem_type = i40e_mem_pd;
71 alloc_len = I40E_HMC_PAGED_BP_SIZE;
72 } else {
73 mem_type = i40e_mem_bp_jumbo;
74 alloc_len = direct_mode_sz;
75 }
76
77
78 ret_code = i40e_allocate_dma_mem(hw, &mem, mem_type, alloc_len,
79 I40E_HMC_PD_BP_BUF_ALIGNMENT);
80 if (ret_code)
81 goto exit;
82 dma_mem_alloc_done = true;
83 if (I40E_SD_TYPE_PAGED == type) {
84 ret_code = i40e_allocate_virt_mem(hw,
85 &sd_entry->u.pd_table.pd_entry_virt_mem,
86 sizeof(struct i40e_hmc_pd_entry) * 512);
87 if (ret_code)
88 goto exit;
89 sd_entry->u.pd_table.pd_entry =
90 (struct i40e_hmc_pd_entry *)
91 sd_entry->u.pd_table.pd_entry_virt_mem.va;
92 sd_entry->u.pd_table.pd_page_addr = mem;
93 } else {
94 sd_entry->u.bp.addr = mem;
95 sd_entry->u.bp.sd_pd_index = sd_index;
96 }
97
98 hmc_info->sd_table.sd_entry[sd_index].entry_type = type;
99
100
101 I40E_INC_SD_REFCNT(&hmc_info->sd_table);
102 }
103
104 if (I40E_SD_TYPE_DIRECT == sd_entry->entry_type)
105 I40E_INC_BP_REFCNT(&sd_entry->u.bp);
106exit:
107 if (ret_code)
108 if (dma_mem_alloc_done)
109 i40e_free_dma_mem(hw, &mem);
110
111 return ret_code;
112}
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130i40e_status i40e_add_pd_table_entry(struct i40e_hw *hw,
131 struct i40e_hmc_info *hmc_info,
132 u32 pd_index)
133{
134 i40e_status ret_code = 0;
135 struct i40e_hmc_pd_table *pd_table;
136 struct i40e_hmc_pd_entry *pd_entry;
137 struct i40e_dma_mem mem;
138 u32 sd_idx, rel_pd_idx;
139 u64 *pd_addr;
140 u64 page_desc;
141
142 if (pd_index / I40E_HMC_PD_CNT_IN_SD >= hmc_info->sd_table.sd_cnt) {
143 ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX;
144 hw_dbg(hw, "i40e_add_pd_table_entry: bad pd_index\n");
145 goto exit;
146 }
147
148
149 sd_idx = (pd_index / I40E_HMC_PD_CNT_IN_SD);
150 if (I40E_SD_TYPE_PAGED !=
151 hmc_info->sd_table.sd_entry[sd_idx].entry_type)
152 goto exit;
153
154 rel_pd_idx = (pd_index % I40E_HMC_PD_CNT_IN_SD);
155 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
156 pd_entry = &pd_table->pd_entry[rel_pd_idx];
157 if (!pd_entry->valid) {
158
159 ret_code = i40e_allocate_dma_mem(hw, &mem, i40e_mem_bp,
160 I40E_HMC_PAGED_BP_SIZE,
161 I40E_HMC_PD_BP_BUF_ALIGNMENT);
162 if (ret_code)
163 goto exit;
164
165 pd_entry->bp.addr = mem;
166 pd_entry->bp.sd_pd_index = pd_index;
167 pd_entry->bp.entry_type = I40E_SD_TYPE_PAGED;
168
169 page_desc = mem.pa | 0x1;
170
171 pd_addr = (u64 *)pd_table->pd_page_addr.va;
172 pd_addr += rel_pd_idx;
173
174
175 memcpy(pd_addr, &page_desc, sizeof(u64));
176
177 pd_entry->sd_index = sd_idx;
178 pd_entry->valid = true;
179 I40E_INC_PD_REFCNT(pd_table);
180 }
181 I40E_INC_BP_REFCNT(&pd_entry->bp);
182exit:
183 return ret_code;
184}
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202i40e_status i40e_remove_pd_bp(struct i40e_hw *hw,
203 struct i40e_hmc_info *hmc_info,
204 u32 idx)
205{
206 i40e_status ret_code = 0;
207 struct i40e_hmc_pd_entry *pd_entry;
208 struct i40e_hmc_pd_table *pd_table;
209 struct i40e_hmc_sd_entry *sd_entry;
210 u32 sd_idx, rel_pd_idx;
211 u64 *pd_addr;
212
213
214 sd_idx = idx / I40E_HMC_PD_CNT_IN_SD;
215 rel_pd_idx = idx % I40E_HMC_PD_CNT_IN_SD;
216 if (sd_idx >= hmc_info->sd_table.sd_cnt) {
217 ret_code = I40E_ERR_INVALID_PAGE_DESC_INDEX;
218 hw_dbg(hw, "i40e_remove_pd_bp: bad idx\n");
219 goto exit;
220 }
221 sd_entry = &hmc_info->sd_table.sd_entry[sd_idx];
222 if (I40E_SD_TYPE_PAGED != sd_entry->entry_type) {
223 ret_code = I40E_ERR_INVALID_SD_TYPE;
224 hw_dbg(hw, "i40e_remove_pd_bp: wrong sd_entry type\n");
225 goto exit;
226 }
227
228 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
229 pd_entry = &pd_table->pd_entry[rel_pd_idx];
230 I40E_DEC_BP_REFCNT(&pd_entry->bp);
231 if (pd_entry->bp.ref_cnt)
232 goto exit;
233
234
235 pd_entry->valid = false;
236 I40E_DEC_PD_REFCNT(pd_table);
237 pd_addr = (u64 *)pd_table->pd_page_addr.va;
238 pd_addr += rel_pd_idx;
239 memset(pd_addr, 0, sizeof(u64));
240 I40E_INVALIDATE_PF_HMC_PD(hw, sd_idx, idx);
241
242
243 ret_code = i40e_free_dma_mem(hw, &(pd_entry->bp.addr));
244 if (ret_code)
245 goto exit;
246 if (!pd_table->ref_cnt)
247 i40e_free_virt_mem(hw, &pd_table->pd_entry_virt_mem);
248exit:
249 return ret_code;
250}
251
252
253
254
255
256
257i40e_status i40e_prep_remove_sd_bp(struct i40e_hmc_info *hmc_info,
258 u32 idx)
259{
260 i40e_status ret_code = 0;
261 struct i40e_hmc_sd_entry *sd_entry;
262
263
264 sd_entry = &hmc_info->sd_table.sd_entry[idx];
265 I40E_DEC_BP_REFCNT(&sd_entry->u.bp);
266 if (sd_entry->u.bp.ref_cnt) {
267 ret_code = I40E_ERR_NOT_READY;
268 goto exit;
269 }
270 I40E_DEC_SD_REFCNT(&hmc_info->sd_table);
271
272
273 sd_entry->valid = false;
274exit:
275 return ret_code;
276}
277
278
279
280
281
282
283
284
285i40e_status i40e_remove_sd_bp_new(struct i40e_hw *hw,
286 struct i40e_hmc_info *hmc_info,
287 u32 idx, bool is_pf)
288{
289 struct i40e_hmc_sd_entry *sd_entry;
290 i40e_status ret_code = 0;
291
292
293 sd_entry = &hmc_info->sd_table.sd_entry[idx];
294 if (is_pf) {
295 I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_DIRECT);
296 } else {
297 ret_code = I40E_NOT_SUPPORTED;
298 goto exit;
299 }
300 ret_code = i40e_free_dma_mem(hw, &(sd_entry->u.bp.addr));
301 if (ret_code)
302 goto exit;
303exit:
304 return ret_code;
305}
306
307
308
309
310
311
312i40e_status i40e_prep_remove_pd_page(struct i40e_hmc_info *hmc_info,
313 u32 idx)
314{
315 i40e_status ret_code = 0;
316 struct i40e_hmc_sd_entry *sd_entry;
317
318 sd_entry = &hmc_info->sd_table.sd_entry[idx];
319
320 if (sd_entry->u.pd_table.ref_cnt) {
321 ret_code = I40E_ERR_NOT_READY;
322 goto exit;
323 }
324
325
326 sd_entry->valid = false;
327
328 I40E_DEC_SD_REFCNT(&hmc_info->sd_table);
329exit:
330 return ret_code;
331}
332
333
334
335
336
337
338
339
340i40e_status i40e_remove_pd_page_new(struct i40e_hw *hw,
341 struct i40e_hmc_info *hmc_info,
342 u32 idx, bool is_pf)
343{
344 i40e_status ret_code = 0;
345 struct i40e_hmc_sd_entry *sd_entry;
346
347 sd_entry = &hmc_info->sd_table.sd_entry[idx];
348 if (is_pf) {
349 I40E_CLEAR_PF_SD_ENTRY(hw, idx, I40E_SD_TYPE_PAGED);
350 } else {
351 ret_code = I40E_NOT_SUPPORTED;
352 goto exit;
353 }
354
355 ret_code = i40e_free_dma_mem(hw, &(sd_entry->u.pd_table.pd_page_addr));
356 if (ret_code)
357 goto exit;
358exit:
359 return ret_code;
360}
361