Skip to content

Commit 3e9ec2b

Browse files
Edwin Peerdavem330
authored andcommitted
bnxt_en: refactor bnxt_alloc_fw_health()
The allocator for the firmware health structure conflates allocation and capability checks, limiting the reusability of the code. This patch separates out the capability check and disablement and improves the warning message to better describe the consequences of an allocation failure. Signed-off-by: Edwin Peer <edwin.peer@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 424174f commit 3e9ec2b

File tree

1 file changed

+38
-22
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+38
-22
lines changed

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

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7336,6 +7336,36 @@ static int bnxt_hwrm_cfa_adv_flow_mgnt_qcaps(struct bnxt *bp)
73367336
return rc;
73377337
}
73387338

7339+
static int __bnxt_alloc_fw_health(struct bnxt *bp)
7340+
{
7341+
if (bp->fw_health)
7342+
return 0;
7343+
7344+
bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL);
7345+
if (!bp->fw_health)
7346+
return -ENOMEM;
7347+
7348+
return 0;
7349+
}
7350+
7351+
static int bnxt_alloc_fw_health(struct bnxt *bp)
7352+
{
7353+
int rc;
7354+
7355+
if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) &&
7356+
!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
7357+
return 0;
7358+
7359+
rc = __bnxt_alloc_fw_health(bp);
7360+
if (rc) {
7361+
bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET;
7362+
bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
7363+
return rc;
7364+
}
7365+
7366+
return 0;
7367+
}
7368+
73397369
static int bnxt_map_fw_health_regs(struct bnxt *bp)
73407370
{
73417371
struct bnxt_fw_health *fw_health = bp->fw_health;
@@ -10966,23 +10996,6 @@ static void bnxt_init_dflt_coal(struct bnxt *bp)
1096610996
bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS;
1096710997
}
1096810998

10969-
static void bnxt_alloc_fw_health(struct bnxt *bp)
10970-
{
10971-
if (bp->fw_health)
10972-
return;
10973-
10974-
if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET) &&
10975-
!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY))
10976-
return;
10977-
10978-
bp->fw_health = kzalloc(sizeof(*bp->fw_health), GFP_KERNEL);
10979-
if (!bp->fw_health) {
10980-
netdev_warn(bp->dev, "Failed to allocate fw_health\n");
10981-
bp->fw_cap &= ~BNXT_FW_CAP_HOT_RESET;
10982-
bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
10983-
}
10984-
}
10985-
1098610999
static int bnxt_fw_init_one_p1(struct bnxt *bp)
1098711000
{
1098811001
int rc;
@@ -11029,11 +11042,14 @@ static int bnxt_fw_init_one_p2(struct bnxt *bp)
1102911042
netdev_warn(bp->dev, "hwrm query adv flow mgnt failure rc: %d\n",
1103011043
rc);
1103111044

11032-
bnxt_alloc_fw_health(bp);
11033-
rc = bnxt_hwrm_error_recovery_qcfg(bp);
11034-
if (rc)
11035-
netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n",
11036-
rc);
11045+
if (bnxt_alloc_fw_health(bp)) {
11046+
netdev_warn(bp->dev, "no memory for firmware error recovery\n");
11047+
} else {
11048+
rc = bnxt_hwrm_error_recovery_qcfg(bp);
11049+
if (rc)
11050+
netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n",
11051+
rc);
11052+
}
1103711053

1103811054
rc = bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, false);
1103911055
if (rc)

0 commit comments

Comments
 (0)