Skip to content

Commit c43fe48

Browse files
hgao656gregkh
authored andcommitted
bnxt_en: Add a 'force' parameter to bnxt_free_ctx_mem()
[ Upstream commit 46010d4 ] If 'force' is false, it will keep the memory pages and all data structures for the context memory type if the memory is valid. This patch always passes true for the 'force' parameter so there is no change in behavior. Later patches will adjust the 'force' parameter for the FW log context memory types so that the logs will not be reset after FW reset. Signed-off-by: Hongguang Gao <hongguang.gao@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/20241115151438.550106-5-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: 5204943 ("bnxt_en: Fix warning in bnxt_dl_reload_down()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 48c3e65 commit c43fe48

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8340,18 +8340,20 @@ static int bnxt_hwrm_func_backing_store_qcaps_v2(struct bnxt *bp)
83408340
{
83418341
struct hwrm_func_backing_store_qcaps_v2_output *resp;
83428342
struct hwrm_func_backing_store_qcaps_v2_input *req;
8343-
struct bnxt_ctx_mem_info *ctx;
8343+
struct bnxt_ctx_mem_info *ctx = bp->ctx;
83448344
u16 type;
83458345
int rc;
83468346

83478347
rc = hwrm_req_init(bp, req, HWRM_FUNC_BACKING_STORE_QCAPS_V2);
83488348
if (rc)
83498349
return rc;
83508350

8351-
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
8352-
if (!ctx)
8353-
return -ENOMEM;
8354-
bp->ctx = ctx;
8351+
if (!ctx) {
8352+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
8353+
if (!ctx)
8354+
return -ENOMEM;
8355+
bp->ctx = ctx;
8356+
}
83558357

83568358
resp = hwrm_req_hold(bp, req);
83578359

@@ -8400,7 +8402,8 @@ static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp)
84008402
struct hwrm_func_backing_store_qcaps_input *req;
84018403
int rc;
84028404

8403-
if (bp->hwrm_spec_code < 0x10902 || BNXT_VF(bp) || bp->ctx)
8405+
if (bp->hwrm_spec_code < 0x10902 || BNXT_VF(bp) ||
8406+
(bp->ctx && bp->ctx->flags & BNXT_CTX_FLAG_INITED))
84048407
return 0;
84058408

84068409
if (bp->fw_cap & BNXT_FW_CAP_BACKING_STORE_V2)
@@ -8873,11 +8876,16 @@ static int bnxt_backing_store_cfg_v2(struct bnxt *bp, u32 ena)
88738876
}
88748877

88758878
static void bnxt_free_one_ctx_mem(struct bnxt *bp,
8876-
struct bnxt_ctx_mem_type *ctxm)
8879+
struct bnxt_ctx_mem_type *ctxm, bool force)
88778880
{
88788881
struct bnxt_ctx_pg_info *ctx_pg;
88798882
int i, n = 1;
88808883

8884+
ctxm->last = 0;
8885+
8886+
if (ctxm->mem_valid && !force)
8887+
return;
8888+
88818889
ctx_pg = ctxm->pg_info;
88828890
if (ctx_pg) {
88838891
if (ctxm->instance_bmap)
@@ -8891,7 +8899,7 @@ static void bnxt_free_one_ctx_mem(struct bnxt *bp,
88918899
}
88928900
}
88938901

8894-
void bnxt_free_ctx_mem(struct bnxt *bp)
8902+
void bnxt_free_ctx_mem(struct bnxt *bp, bool force)
88958903
{
88968904
struct bnxt_ctx_mem_info *ctx = bp->ctx;
88978905
u16 type;
@@ -8900,11 +8908,13 @@ void bnxt_free_ctx_mem(struct bnxt *bp)
89008908
return;
89018909

89028910
for (type = 0; type < BNXT_CTX_V2_MAX; type++)
8903-
bnxt_free_one_ctx_mem(bp, &ctx->ctx_arr[type]);
8911+
bnxt_free_one_ctx_mem(bp, &ctx->ctx_arr[type], force);
89048912

89058913
ctx->flags &= ~BNXT_CTX_FLAG_INITED;
8906-
kfree(ctx);
8907-
bp->ctx = NULL;
8914+
if (force) {
8915+
kfree(ctx);
8916+
bp->ctx = NULL;
8917+
}
89088918
}
89098919

89108920
static int bnxt_alloc_ctx_mem(struct bnxt *bp)
@@ -11933,7 +11943,7 @@ static int bnxt_hwrm_if_change(struct bnxt *bp, bool up)
1193311943
set_bit(BNXT_STATE_FW_RESET_DET, &bp->state);
1193411944
if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
1193511945
bnxt_ulp_irq_stop(bp);
11936-
bnxt_free_ctx_mem(bp);
11946+
bnxt_free_ctx_mem(bp, true);
1193711947
bnxt_dcb_free(bp);
1193811948
rc = bnxt_fw_init_one(bp);
1193911949
if (rc) {
@@ -13657,7 +13667,7 @@ static void bnxt_fw_reset_close(struct bnxt *bp)
1365713667
bnxt_hwrm_func_drv_unrgtr(bp);
1365813668
if (pci_is_enabled(bp->pdev))
1365913669
pci_disable_device(bp->pdev);
13660-
bnxt_free_ctx_mem(bp);
13670+
bnxt_free_ctx_mem(bp, true);
1366113671
}
1366213672

1366313673
static bool is_bnxt_fw_ok(struct bnxt *bp)
@@ -15553,7 +15563,7 @@ static void bnxt_remove_one(struct pci_dev *pdev)
1555315563
kfree(bp->fw_health);
1555415564
bp->fw_health = NULL;
1555515565
bnxt_cleanup_pci(bp);
15556-
bnxt_free_ctx_mem(bp);
15566+
bnxt_free_ctx_mem(bp, true);
1555715567
bnxt_free_crash_dump_mem(bp);
1555815568
kfree(bp->rss_indir_tbl);
1555915569
bp->rss_indir_tbl = NULL;
@@ -16195,7 +16205,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1619516205
kfree(bp->fw_health);
1619616206
bp->fw_health = NULL;
1619716207
bnxt_cleanup_pci(bp);
16198-
bnxt_free_ctx_mem(bp);
16208+
bnxt_free_ctx_mem(bp, true);
1619916209
bnxt_free_crash_dump_mem(bp);
1620016210
kfree(bp->rss_indir_tbl);
1620116211
bp->rss_indir_tbl = NULL;
@@ -16251,7 +16261,7 @@ static int bnxt_suspend(struct device *device)
1625116261
bnxt_hwrm_func_drv_unrgtr(bp);
1625216262
bnxt_ptp_clear(bp);
1625316263
pci_disable_device(bp->pdev);
16254-
bnxt_free_ctx_mem(bp);
16264+
bnxt_free_ctx_mem(bp, true);
1625516265
rtnl_unlock();
1625616266
return rc;
1625716267
}
@@ -16367,7 +16377,7 @@ static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
1636716377

1636816378
if (pci_is_enabled(pdev))
1636916379
pci_disable_device(pdev);
16370-
bnxt_free_ctx_mem(bp);
16380+
bnxt_free_ctx_mem(bp, true);
1637116381
rtnl_unlock();
1637216382

1637316383
/* Request a slot slot reset. */

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,7 @@ int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic,
28282828
int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);
28292829
int bnxt_nq_rings_in_use(struct bnxt *bp);
28302830
int bnxt_hwrm_set_coal(struct bnxt *);
2831-
void bnxt_free_ctx_mem(struct bnxt *bp);
2831+
void bnxt_free_ctx_mem(struct bnxt *bp, bool force);
28322832
int bnxt_num_tx_to_cp(struct bnxt *bp, int tx);
28332833
unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
28342834
unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp);

drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int bnxt_dl_reload_down(struct devlink *dl, bool netns_change,
463463
break;
464464
}
465465
bnxt_cancel_reservations(bp, false);
466-
bnxt_free_ctx_mem(bp);
466+
bnxt_free_ctx_mem(bp, true);
467467
break;
468468
}
469469
case DEVLINK_RELOAD_ACTION_FW_ACTIVATE: {

0 commit comments

Comments
 (0)