1 // SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
2 /* Copyright (c) 2015 - 2021 Intel Corporation */
11 * irdma_find_sd_index_limit - finds segment descriptor index limit
12 * @hmc_info: pointer to the HMC configuration information structure
13 * @type: type of HMC resources we're searching
14 * @idx: starting index for the object
15 * @cnt: number of objects we're trying to create
16 * @sd_idx: pointer to return index of the segment descriptor in question
17 * @sd_limit: pointer to return the maximum number of segment descriptors
19 * This function calculates the segment descriptor index and index limit
20 * for the resource defined by irdma_hmc_rsrc_type.
23 static void irdma_find_sd_index_limit(struct irdma_hmc_info *hmc_info, u32 type,
24 u32 idx, u32 cnt, u32 *sd_idx,
27 u64 fpm_addr, fpm_limit;
29 fpm_addr = hmc_info->hmc_obj[(type)].base +
30 hmc_info->hmc_obj[type].size * idx;
31 fpm_limit = fpm_addr + hmc_info->hmc_obj[type].size * cnt;
32 *sd_idx = (u32)(fpm_addr / IRDMA_HMC_DIRECT_BP_SIZE);
33 *sd_limit = (u32)((fpm_limit - 1) / IRDMA_HMC_DIRECT_BP_SIZE);
38 * irdma_find_pd_index_limit - finds page descriptor index limit
39 * @hmc_info: pointer to the HMC configuration information struct
40 * @type: HMC resource type we're examining
41 * @idx: starting index for the object
42 * @cnt: number of objects we're trying to create
43 * @pd_idx: pointer to return page descriptor index
44 * @pd_limit: pointer to return page descriptor index limit
46 * Calculates the page descriptor index and index limit for the resource
47 * defined by irdma_hmc_rsrc_type.
50 static void irdma_find_pd_index_limit(struct irdma_hmc_info *hmc_info, u32 type,
51 u32 idx, u32 cnt, u32 *pd_idx,
54 u64 fpm_adr, fpm_limit;
56 fpm_adr = hmc_info->hmc_obj[type].base +
57 hmc_info->hmc_obj[type].size * idx;
58 fpm_limit = fpm_adr + (hmc_info)->hmc_obj[(type)].size * (cnt);
59 *pd_idx = (u32)(fpm_adr / IRDMA_HMC_PAGED_BP_SIZE);
60 *pd_limit = (u32)((fpm_limit - 1) / IRDMA_HMC_PAGED_BP_SIZE);
65 * irdma_set_sd_entry - setup entry for sd programming
68 * @type: paged or direct sd
69 * @entry: sd entry ptr
71 static void irdma_set_sd_entry(u64 pa, u32 idx, enum irdma_sd_entry_type type,
72 struct irdma_update_sd_entry *entry)
75 FIELD_PREP(IRDMA_PFHMC_SDDATALOW_PMSDBPCOUNT, IRDMA_HMC_MAX_BP_COUNT) |
76 FIELD_PREP(IRDMA_PFHMC_SDDATALOW_PMSDTYPE,
77 type == IRDMA_SD_TYPE_PAGED ? 0 : 1) |
78 FIELD_PREP(IRDMA_PFHMC_SDDATALOW_PMSDVALID, 1);
80 entry->cmd = idx | FIELD_PREP(IRDMA_PFHMC_SDCMD_PMSDWR, 1) | BIT(15);
84 * irdma_clr_sd_entry - setup entry for sd clear
86 * @type: paged or direct sd
87 * @entry: sd entry ptr
89 static void irdma_clr_sd_entry(u32 idx, enum irdma_sd_entry_type type,
90 struct irdma_update_sd_entry *entry)
92 entry->data = FIELD_PREP(IRDMA_PFHMC_SDDATALOW_PMSDBPCOUNT, IRDMA_HMC_MAX_BP_COUNT) |
93 FIELD_PREP(IRDMA_PFHMC_SDDATALOW_PMSDTYPE,
94 type == IRDMA_SD_TYPE_PAGED ? 0 : 1);
96 entry->cmd = idx | FIELD_PREP(IRDMA_PFHMC_SDCMD_PMSDWR, 1) | BIT(15);
100 * irdma_invalidate_pf_hmc_pd - Invalidates the pd cache in the hardware for PF
101 * @dev: pointer to our device struct
102 * @sd_idx: segment descriptor index
103 * @pd_idx: page descriptor index
105 static inline void irdma_invalidate_pf_hmc_pd(struct irdma_sc_dev *dev, u32 sd_idx,
108 u32 val = FIELD_PREP(IRDMA_PFHMC_PDINV_PMSDIDX, sd_idx) |
109 FIELD_PREP(IRDMA_PFHMC_PDINV_PMSDPARTSEL, 1) |
110 FIELD_PREP(IRDMA_PFHMC_PDINV_PMPDIDX, pd_idx);
112 writel(val, dev->hw_regs[IRDMA_PFHMC_PDINV]);
116 * irdma_hmc_sd_one - setup 1 sd entry for cqp
117 * @dev: pointer to the device structure
118 * @hmc_fn_id: hmc's function id
121 * @type: paged or direct sd
122 * @setsd: flag to set or clear sd
124 enum irdma_status_code irdma_hmc_sd_one(struct irdma_sc_dev *dev, u8 hmc_fn_id,
126 enum irdma_sd_entry_type type,
129 struct irdma_update_sds_info sdinfo;
132 sdinfo.hmc_fn_id = hmc_fn_id;
134 irdma_set_sd_entry(pa, sd_idx, type, sdinfo.entry);
136 irdma_clr_sd_entry(sd_idx, type, sdinfo.entry);
137 return dev->cqp->process_cqp_sds(dev, &sdinfo);
141 * irdma_hmc_sd_grp - setup group of sd entries for cqp
142 * @dev: pointer to the device structure
143 * @hmc_info: pointer to the HMC configuration information struct
144 * @sd_index: sd index
145 * @sd_cnt: number of sd entries
146 * @setsd: flag to set or clear sd
148 static enum irdma_status_code irdma_hmc_sd_grp(struct irdma_sc_dev *dev,
149 struct irdma_hmc_info *hmc_info,
150 u32 sd_index, u32 sd_cnt,
153 struct irdma_hmc_sd_entry *sd_entry;
154 struct irdma_update_sds_info sdinfo = {};
157 enum irdma_status_code ret_code = 0;
159 sdinfo.hmc_fn_id = hmc_info->hmc_fn_id;
160 for (i = sd_index; i < sd_index + sd_cnt; i++) {
161 sd_entry = &hmc_info->sd_table.sd_entry[i];
162 if (!sd_entry || (!sd_entry->valid && setsd) ||
163 (sd_entry->valid && !setsd))
166 pa = (sd_entry->entry_type == IRDMA_SD_TYPE_PAGED) ?
167 sd_entry->u.pd_table.pd_page_addr.pa :
168 sd_entry->u.bp.addr.pa;
169 irdma_set_sd_entry(pa, i, sd_entry->entry_type,
170 &sdinfo.entry[sdinfo.cnt]);
172 irdma_clr_sd_entry(i, sd_entry->entry_type,
173 &sdinfo.entry[sdinfo.cnt]);
176 if (sdinfo.cnt == IRDMA_MAX_SD_ENTRIES) {
177 ret_code = dev->cqp->process_cqp_sds(dev, &sdinfo);
179 ibdev_dbg(to_ibdev(dev),
180 "HMC: sd_programming failed err=%d\n",
189 ret_code = dev->cqp->process_cqp_sds(dev, &sdinfo);
195 * irdma_hmc_finish_add_sd_reg - program sd entries for objects
196 * @dev: pointer to the device structure
197 * @info: create obj info
199 static enum irdma_status_code
200 irdma_hmc_finish_add_sd_reg(struct irdma_sc_dev *dev,
201 struct irdma_hmc_create_obj_info *info)
203 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt)
204 return IRDMA_ERR_INVALID_HMC_OBJ_INDEX;
206 if ((info->start_idx + info->count) >
207 info->hmc_info->hmc_obj[info->rsrc_type].cnt)
208 return IRDMA_ERR_INVALID_HMC_OBJ_COUNT;
210 if (!info->add_sd_cnt)
212 return irdma_hmc_sd_grp(dev, info->hmc_info,
213 info->hmc_info->sd_indexes[0], info->add_sd_cnt,
218 * irdma_sc_create_hmc_obj - allocate backing store for hmc objects
219 * @dev: pointer to the device structure
220 * @info: pointer to irdma_hmc_create_obj_info struct
222 * This will allocate memory for PDs and backing pages and populate
223 * the sd and pd entries.
225 enum irdma_status_code
226 irdma_sc_create_hmc_obj(struct irdma_sc_dev *dev,
227 struct irdma_hmc_create_obj_info *info)
229 struct irdma_hmc_sd_entry *sd_entry;
231 u32 pd_idx = 0, pd_lmt = 0;
232 u32 pd_idx1 = 0, pd_lmt1 = 0;
234 bool pd_error = false;
235 enum irdma_status_code ret_code = 0;
237 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt)
238 return IRDMA_ERR_INVALID_HMC_OBJ_INDEX;
240 if ((info->start_idx + info->count) >
241 info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
242 ibdev_dbg(to_ibdev(dev),
243 "HMC: error type %u, start = %u, req cnt %u, cnt = %u\n",
244 info->rsrc_type, info->start_idx, info->count,
245 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
246 return IRDMA_ERR_INVALID_HMC_OBJ_COUNT;
249 irdma_find_sd_index_limit(info->hmc_info, info->rsrc_type,
250 info->start_idx, info->count, &sd_idx,
252 if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
253 sd_lmt > info->hmc_info->sd_table.sd_cnt) {
254 return IRDMA_ERR_INVALID_SD_INDEX;
257 irdma_find_pd_index_limit(info->hmc_info, info->rsrc_type,
258 info->start_idx, info->count, &pd_idx,
261 for (j = sd_idx; j < sd_lmt; j++) {
262 ret_code = irdma_add_sd_table_entry(dev->hw, info->hmc_info, j,
264 IRDMA_HMC_DIRECT_BP_SIZE);
268 sd_entry = &info->hmc_info->sd_table.sd_entry[j];
269 if (sd_entry->entry_type == IRDMA_SD_TYPE_PAGED &&
270 (dev->hmc_info == info->hmc_info &&
271 info->rsrc_type != IRDMA_HMC_IW_PBLE)) {
272 pd_idx1 = max(pd_idx, (j * IRDMA_HMC_MAX_BP_COUNT));
273 pd_lmt1 = min(pd_lmt, (j + 1) * IRDMA_HMC_MAX_BP_COUNT);
274 for (i = pd_idx1; i < pd_lmt1; i++) {
275 /* update the pd table entry */
276 ret_code = irdma_add_pd_table_entry(dev,
285 while (i && (i > pd_idx1)) {
286 irdma_remove_pd_bp(dev, info->hmc_info,
295 info->hmc_info->sd_indexes[info->add_sd_cnt] = (u16)j;
297 sd_entry->valid = true;
299 return irdma_hmc_finish_add_sd_reg(dev, info);
302 while (j && (j > sd_idx)) {
303 sd_entry = &info->hmc_info->sd_table.sd_entry[j - 1];
304 switch (sd_entry->entry_type) {
305 case IRDMA_SD_TYPE_PAGED:
306 pd_idx1 = max(pd_idx, (j - 1) * IRDMA_HMC_MAX_BP_COUNT);
307 pd_lmt1 = min(pd_lmt, (j * IRDMA_HMC_MAX_BP_COUNT));
308 for (i = pd_idx1; i < pd_lmt1; i++)
309 irdma_prep_remove_pd_page(info->hmc_info, i);
311 case IRDMA_SD_TYPE_DIRECT:
312 irdma_prep_remove_pd_page(info->hmc_info, (j - 1));
315 ret_code = IRDMA_ERR_INVALID_SD_TYPE;
325 * irdma_finish_del_sd_reg - delete sd entries for objects
326 * @dev: pointer to the device structure
327 * @info: dele obj info
328 * @reset: true if called before reset
330 static enum irdma_status_code
331 irdma_finish_del_sd_reg(struct irdma_sc_dev *dev,
332 struct irdma_hmc_del_obj_info *info, bool reset)
334 struct irdma_hmc_sd_entry *sd_entry;
335 enum irdma_status_code ret_code = 0;
337 struct irdma_dma_mem *mem;
340 ret_code = irdma_hmc_sd_grp(dev, info->hmc_info,
341 info->hmc_info->sd_indexes[0],
342 info->del_sd_cnt, false);
345 ibdev_dbg(to_ibdev(dev), "HMC: error cqp sd sd_grp\n");
346 for (i = 0; i < info->del_sd_cnt; i++) {
347 sd_idx = info->hmc_info->sd_indexes[i];
348 sd_entry = &info->hmc_info->sd_table.sd_entry[sd_idx];
349 mem = (sd_entry->entry_type == IRDMA_SD_TYPE_PAGED) ?
350 &sd_entry->u.pd_table.pd_page_addr :
351 &sd_entry->u.bp.addr;
353 if (!mem || !mem->va) {
354 ibdev_dbg(to_ibdev(dev), "HMC: error cqp sd mem\n");
356 dma_free_coherent(dev->hw->device, mem->size, mem->va,
366 * irdma_sc_del_hmc_obj - remove pe hmc objects
367 * @dev: pointer to the device structure
368 * @info: pointer to irdma_hmc_del_obj_info struct
369 * @reset: true if called before reset
371 * This will de-populate the SDs and PDs. It frees
372 * the memory for PDS and backing storage. After this function is returned,
373 * caller should deallocate memory allocated previously for
374 * book-keeping information about PDs and backing storage.
376 enum irdma_status_code irdma_sc_del_hmc_obj(struct irdma_sc_dev *dev,
377 struct irdma_hmc_del_obj_info *info,
380 struct irdma_hmc_pd_table *pd_table;
382 u32 pd_idx, pd_lmt, rel_pd_idx;
384 enum irdma_status_code ret_code = 0;
386 if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
387 ibdev_dbg(to_ibdev(dev),
388 "HMC: error start_idx[%04d] >= [type %04d].cnt[%04d]\n",
389 info->start_idx, info->rsrc_type,
390 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
391 return IRDMA_ERR_INVALID_HMC_OBJ_INDEX;
394 if ((info->start_idx + info->count) >
395 info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
396 ibdev_dbg(to_ibdev(dev),
397 "HMC: error start_idx[%04d] + count %04d >= [type %04d].cnt[%04d]\n",
398 info->start_idx, info->count, info->rsrc_type,
399 info->hmc_info->hmc_obj[info->rsrc_type].cnt);
400 return IRDMA_ERR_INVALID_HMC_OBJ_COUNT;
403 irdma_find_pd_index_limit(info->hmc_info, info->rsrc_type,
404 info->start_idx, info->count, &pd_idx,
407 for (j = pd_idx; j < pd_lmt; j++) {
408 sd_idx = j / IRDMA_HMC_PD_CNT_IN_SD;
410 if (!info->hmc_info->sd_table.sd_entry[sd_idx].valid)
413 if (info->hmc_info->sd_table.sd_entry[sd_idx].entry_type !=
417 rel_pd_idx = j % IRDMA_HMC_PD_CNT_IN_SD;
418 pd_table = &info->hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
419 if (pd_table->pd_entry &&
420 pd_table->pd_entry[rel_pd_idx].valid) {
421 ret_code = irdma_remove_pd_bp(dev, info->hmc_info, j);
423 ibdev_dbg(to_ibdev(dev),
424 "HMC: remove_pd_bp error\n");
430 irdma_find_sd_index_limit(info->hmc_info, info->rsrc_type,
431 info->start_idx, info->count, &sd_idx,
433 if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
434 sd_lmt > info->hmc_info->sd_table.sd_cnt) {
435 ibdev_dbg(to_ibdev(dev), "HMC: invalid sd_idx\n");
436 return IRDMA_ERR_INVALID_SD_INDEX;
439 for (i = sd_idx; i < sd_lmt; i++) {
440 pd_table = &info->hmc_info->sd_table.sd_entry[i].u.pd_table;
441 if (!info->hmc_info->sd_table.sd_entry[i].valid)
443 switch (info->hmc_info->sd_table.sd_entry[i].entry_type) {
444 case IRDMA_SD_TYPE_DIRECT:
445 ret_code = irdma_prep_remove_sd_bp(info->hmc_info, i);
447 info->hmc_info->sd_indexes[info->del_sd_cnt] =
452 case IRDMA_SD_TYPE_PAGED:
453 ret_code = irdma_prep_remove_pd_page(info->hmc_info, i);
456 if (dev->hmc_info != info->hmc_info &&
457 info->rsrc_type == IRDMA_HMC_IW_PBLE &&
458 pd_table->pd_entry) {
459 kfree(pd_table->pd_entry_virt_mem.va);
460 pd_table->pd_entry = NULL;
462 info->hmc_info->sd_indexes[info->del_sd_cnt] = (u16)i;
469 return irdma_finish_del_sd_reg(dev, info, reset);
473 * irdma_add_sd_table_entry - Adds a segment descriptor to the table
474 * @hw: pointer to our hw struct
475 * @hmc_info: pointer to the HMC configuration information struct
476 * @sd_index: segment descriptor index to manipulate
477 * @type: what type of segment descriptor we're manipulating
478 * @direct_mode_sz: size to alloc in direct mode
480 enum irdma_status_code irdma_add_sd_table_entry(struct irdma_hw *hw,
481 struct irdma_hmc_info *hmc_info,
483 enum irdma_sd_entry_type type,
486 struct irdma_hmc_sd_entry *sd_entry;
487 struct irdma_dma_mem dma_mem;
490 sd_entry = &hmc_info->sd_table.sd_entry[sd_index];
491 if (!sd_entry->valid) {
492 if (type == IRDMA_SD_TYPE_PAGED)
493 alloc_len = IRDMA_HMC_PAGED_BP_SIZE;
495 alloc_len = direct_mode_sz;
497 /* allocate a 4K pd page or 2M backing page */
498 dma_mem.size = ALIGN(alloc_len, IRDMA_HMC_PD_BP_BUF_ALIGNMENT);
499 dma_mem.va = dma_alloc_coherent(hw->device, dma_mem.size,
500 &dma_mem.pa, GFP_KERNEL);
502 return IRDMA_ERR_NO_MEMORY;
503 if (type == IRDMA_SD_TYPE_PAGED) {
504 struct irdma_virt_mem *vmem =
505 &sd_entry->u.pd_table.pd_entry_virt_mem;
507 vmem->size = sizeof(struct irdma_hmc_pd_entry) * 512;
508 vmem->va = kzalloc(vmem->size, GFP_KERNEL);
510 dma_free_coherent(hw->device, dma_mem.size,
511 dma_mem.va, dma_mem.pa);
513 return IRDMA_ERR_NO_MEMORY;
515 sd_entry->u.pd_table.pd_entry = vmem->va;
517 memcpy(&sd_entry->u.pd_table.pd_page_addr, &dma_mem,
518 sizeof(sd_entry->u.pd_table.pd_page_addr));
520 memcpy(&sd_entry->u.bp.addr, &dma_mem,
521 sizeof(sd_entry->u.bp.addr));
523 sd_entry->u.bp.sd_pd_index = sd_index;
526 hmc_info->sd_table.sd_entry[sd_index].entry_type = type;
527 hmc_info->sd_table.use_cnt++;
529 if (sd_entry->entry_type == IRDMA_SD_TYPE_DIRECT)
530 sd_entry->u.bp.use_cnt++;
536 * irdma_add_pd_table_entry - Adds page descriptor to the specified table
537 * @dev: pointer to our device structure
538 * @hmc_info: pointer to the HMC configuration information structure
539 * @pd_index: which page descriptor index to manipulate
540 * @rsrc_pg: if not NULL, use preallocated page instead of allocating new one.
543 * 1. Initializes the pd entry
544 * 2. Adds pd_entry in the pd_table
545 * 3. Mark the entry valid in irdma_hmc_pd_entry structure
546 * 4. Initializes the pd_entry's ref count to 1
548 * 1. The memory for pd should be pinned down, physically contiguous and
549 * aligned on 4K boundary and zeroed memory.
550 * 2. It should be 4K in size.
552 enum irdma_status_code irdma_add_pd_table_entry(struct irdma_sc_dev *dev,
553 struct irdma_hmc_info *hmc_info,
555 struct irdma_dma_mem *rsrc_pg)
557 struct irdma_hmc_pd_table *pd_table;
558 struct irdma_hmc_pd_entry *pd_entry;
559 struct irdma_dma_mem mem;
560 struct irdma_dma_mem *page = &mem;
561 u32 sd_idx, rel_pd_idx;
565 if (pd_index / IRDMA_HMC_PD_CNT_IN_SD >= hmc_info->sd_table.sd_cnt)
566 return IRDMA_ERR_INVALID_PAGE_DESC_INDEX;
568 sd_idx = (pd_index / IRDMA_HMC_PD_CNT_IN_SD);
569 if (hmc_info->sd_table.sd_entry[sd_idx].entry_type !=
573 rel_pd_idx = (pd_index % IRDMA_HMC_PD_CNT_IN_SD);
574 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
575 pd_entry = &pd_table->pd_entry[rel_pd_idx];
576 if (!pd_entry->valid) {
578 pd_entry->rsrc_pg = true;
581 page->size = ALIGN(IRDMA_HMC_PAGED_BP_SIZE,
582 IRDMA_HMC_PD_BP_BUF_ALIGNMENT);
583 page->va = dma_alloc_coherent(dev->hw->device,
584 page->size, &page->pa,
587 return IRDMA_ERR_NO_MEMORY;
589 pd_entry->rsrc_pg = false;
592 memcpy(&pd_entry->bp.addr, page, sizeof(pd_entry->bp.addr));
593 pd_entry->bp.sd_pd_index = pd_index;
594 pd_entry->bp.entry_type = IRDMA_SD_TYPE_PAGED;
595 page_desc = page->pa | 0x1;
596 pd_addr = pd_table->pd_page_addr.va;
597 pd_addr += rel_pd_idx;
598 memcpy(pd_addr, &page_desc, sizeof(*pd_addr));
599 pd_entry->sd_index = sd_idx;
600 pd_entry->valid = true;
602 irdma_invalidate_pf_hmc_pd(dev, sd_idx, rel_pd_idx);
604 pd_entry->bp.use_cnt++;
610 * irdma_remove_pd_bp - remove a backing page from a page descriptor
611 * @dev: pointer to our HW structure
612 * @hmc_info: pointer to the HMC configuration information structure
613 * @idx: the page index
616 * 1. Marks the entry in pd table (for paged address mode) or in sd table
617 * (for direct address mode) invalid.
618 * 2. Write to register PMPDINV to invalidate the backing page in FV cache
619 * 3. Decrement the ref count for the pd _entry
621 * 1. Caller can deallocate the memory used by backing storage after this
624 enum irdma_status_code irdma_remove_pd_bp(struct irdma_sc_dev *dev,
625 struct irdma_hmc_info *hmc_info,
628 struct irdma_hmc_pd_entry *pd_entry;
629 struct irdma_hmc_pd_table *pd_table;
630 struct irdma_hmc_sd_entry *sd_entry;
631 u32 sd_idx, rel_pd_idx;
632 struct irdma_dma_mem *mem;
635 sd_idx = idx / IRDMA_HMC_PD_CNT_IN_SD;
636 rel_pd_idx = idx % IRDMA_HMC_PD_CNT_IN_SD;
637 if (sd_idx >= hmc_info->sd_table.sd_cnt)
638 return IRDMA_ERR_INVALID_PAGE_DESC_INDEX;
640 sd_entry = &hmc_info->sd_table.sd_entry[sd_idx];
641 if (sd_entry->entry_type != IRDMA_SD_TYPE_PAGED)
642 return IRDMA_ERR_INVALID_SD_TYPE;
644 pd_table = &hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
645 pd_entry = &pd_table->pd_entry[rel_pd_idx];
646 if (--pd_entry->bp.use_cnt)
649 pd_entry->valid = false;
651 pd_addr = pd_table->pd_page_addr.va;
652 pd_addr += rel_pd_idx;
653 memset(pd_addr, 0, sizeof(u64));
654 irdma_invalidate_pf_hmc_pd(dev, sd_idx, idx);
656 if (!pd_entry->rsrc_pg) {
657 mem = &pd_entry->bp.addr;
658 if (!mem || !mem->va)
659 return IRDMA_ERR_PARAM;
661 dma_free_coherent(dev->hw->device, mem->size, mem->va,
665 if (!pd_table->use_cnt)
666 kfree(pd_table->pd_entry_virt_mem.va);
672 * irdma_prep_remove_sd_bp - Prepares to remove a backing page from a sd entry
673 * @hmc_info: pointer to the HMC configuration information structure
674 * @idx: the page index
676 enum irdma_status_code irdma_prep_remove_sd_bp(struct irdma_hmc_info *hmc_info,
679 struct irdma_hmc_sd_entry *sd_entry;
681 sd_entry = &hmc_info->sd_table.sd_entry[idx];
682 if (--sd_entry->u.bp.use_cnt)
683 return IRDMA_ERR_NOT_READY;
685 hmc_info->sd_table.use_cnt--;
686 sd_entry->valid = false;
692 * irdma_prep_remove_pd_page - Prepares to remove a PD page from sd entry.
693 * @hmc_info: pointer to the HMC configuration information structure
694 * @idx: segment descriptor index to find the relevant page descriptor
696 enum irdma_status_code
697 irdma_prep_remove_pd_page(struct irdma_hmc_info *hmc_info, u32 idx)
699 struct irdma_hmc_sd_entry *sd_entry;
701 sd_entry = &hmc_info->sd_table.sd_entry[idx];
703 if (sd_entry->u.pd_table.use_cnt)
704 return IRDMA_ERR_NOT_READY;
706 sd_entry->valid = false;
707 hmc_info->sd_table.use_cnt--;