Skip to content

Commit 5a2f3aa

Browse files
Michael Chankuba-moo
authored andcommitted
bnxt_en: Refactor bnxt_need_reserve_rings()
bnxt_need_reserve_rings() checks 6 ring resources against the reserved values to determine if a new reservation is needed. Factor out the code to collect the total resources into a new helper function bnxt_get_total_resources() to make the code cleaner and easier to read. Instead of individual scalar variables, use the struct bnxt_hw_rings to hold all the ring resources. Using the struct, hwr.cp replaces the nq variable and the chip specific hwr.cp_p5 replaces cp on newer chips. There is no change in behavior. This will make it easier to check the RSS context resource in the next patch. Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Reviewed-by: Joe Damato <joe@dama.to> Link: https://patch.msgid.link/20260207235118.1987301-2-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e5e2e43 commit 5a2f3aa

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

  • drivers/net/ethernet/broadcom/bnxt

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7951,13 +7951,27 @@ static int bnxt_get_total_vnics(struct bnxt *bp, int rx_rings)
79517951
return 1;
79527952
}
79537953

7954+
static void bnxt_get_total_resources(struct bnxt *bp, struct bnxt_hw_rings *hwr)
7955+
{
7956+
hwr->cp = bnxt_nq_rings_in_use(bp);
7957+
hwr->cp_p5 = 0;
7958+
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
7959+
hwr->cp_p5 = bnxt_cp_rings_in_use(bp);
7960+
hwr->tx = bp->tx_nr_rings;
7961+
hwr->rx = bp->rx_nr_rings;
7962+
hwr->grp = hwr->rx;
7963+
hwr->vnic = bnxt_get_total_vnics(bp, hwr->rx);
7964+
if (bp->flags & BNXT_FLAG_AGG_RINGS)
7965+
hwr->rx <<= 1;
7966+
hwr->stat = bnxt_get_func_stat_ctxs(bp);
7967+
}
7968+
79547969
static bool bnxt_need_reserve_rings(struct bnxt *bp)
79557970
{
79567971
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
7957-
int cp = bnxt_cp_rings_in_use(bp);
7958-
int nq = bnxt_nq_rings_in_use(bp);
7959-
int rx = bp->rx_nr_rings, stat;
7960-
int vnic, grp = rx;
7972+
struct bnxt_hw_rings hwr;
7973+
7974+
bnxt_get_total_resources(bp, &hwr);
79617975

79627976
/* Old firmware does not need RX ring reservations but we still
79637977
* need to setup a default RSS map when needed. With new firmware
@@ -7967,25 +7981,26 @@ static bool bnxt_need_reserve_rings(struct bnxt *bp)
79677981
if (!BNXT_NEW_RM(bp))
79687982
bnxt_check_rss_tbl_no_rmgr(bp);
79697983

7970-
if (hw_resc->resv_tx_rings != bp->tx_nr_rings &&
7971-
bp->hwrm_spec_code >= 0x10601)
7984+
if (hw_resc->resv_tx_rings != hwr.tx && bp->hwrm_spec_code >= 0x10601)
79727985
return true;
79737986

79747987
if (!BNXT_NEW_RM(bp))
79757988
return false;
79767989

7977-
vnic = bnxt_get_total_vnics(bp, rx);
7978-
7979-
if (bp->flags & BNXT_FLAG_AGG_RINGS)
7980-
rx <<= 1;
7981-
stat = bnxt_get_func_stat_ctxs(bp);
7982-
if (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
7983-
hw_resc->resv_vnics != vnic || hw_resc->resv_stat_ctxs != stat ||
7984-
(hw_resc->resv_hw_ring_grps != grp &&
7990+
if (hw_resc->resv_rx_rings != hwr.rx ||
7991+
hw_resc->resv_vnics != hwr.vnic ||
7992+
hw_resc->resv_stat_ctxs != hwr.stat ||
7993+
(hw_resc->resv_hw_ring_grps != hwr.grp &&
79857994
!(bp->flags & BNXT_FLAG_CHIP_P5_PLUS)))
79867995
return true;
7996+
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS) {
7997+
if (hw_resc->resv_cp_rings != hwr.cp_p5)
7998+
return true;
7999+
} else if (hw_resc->resv_cp_rings != hwr.cp) {
8000+
return true;
8001+
}
79878002
if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && BNXT_PF(bp) &&
7988-
hw_resc->resv_irqs != nq)
8003+
hw_resc->resv_irqs != hwr.cp)
79898004
return true;
79908005
return false;
79918006
}

0 commit comments

Comments
 (0)