Skip to content

Commit ceee35e

Browse files
Michael Chankuba-moo
authored andcommitted
bnxt_en: Refactor some basic ring setup and adjustment logic
Refactor out the basic code that trims the default rings, sets up and adjusts XDP TX rings and CP rings. There is no change in behavior. This is to prepare for the next bug fix patch. Reviewed-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com> Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Link: https://patch.msgid.link/20260331065138.948205-2-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a59dc0f commit ceee35e

4 files changed

Lines changed: 41 additions & 23 deletions

File tree

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12992,6 +12992,21 @@ static int bnxt_tx_nr_rings_per_tc(struct bnxt *bp)
1299212992
return bp->num_tc ? bp->tx_nr_rings / bp->num_tc : bp->tx_nr_rings;
1299312993
}
1299412994

12995+
static void bnxt_set_xdp_tx_rings(struct bnxt *bp)
12996+
{
12997+
bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
12998+
bp->tx_nr_rings += bp->tx_nr_rings_xdp;
12999+
}
13000+
13001+
static void bnxt_adj_tx_rings(struct bnxt *bp)
13002+
{
13003+
/* Make adjustments if reserved TX rings are less than requested */
13004+
bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
13005+
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
13006+
if (bp->tx_nr_rings_xdp)
13007+
bnxt_set_xdp_tx_rings(bp);
13008+
}
13009+
1299513010
static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1299613011
{
1299713012
int rc = 0;
@@ -13009,13 +13024,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1300913024
if (rc)
1301013025
return rc;
1301113026

13012-
/* Make adjustments if reserved TX rings are less than requested */
13013-
bp->tx_nr_rings -= bp->tx_nr_rings_xdp;
13014-
bp->tx_nr_rings_per_tc = bnxt_tx_nr_rings_per_tc(bp);
13015-
if (bp->tx_nr_rings_xdp) {
13016-
bp->tx_nr_rings_xdp = bp->tx_nr_rings_per_tc;
13017-
bp->tx_nr_rings += bp->tx_nr_rings_xdp;
13018-
}
13027+
bnxt_adj_tx_rings(bp);
1301913028
rc = bnxt_alloc_mem(bp, irq_re_init);
1302013029
if (rc) {
1302113030
netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc);
@@ -15436,11 +15445,19 @@ static int bnxt_change_mtu(struct net_device *dev, int new_mtu)
1543615445
return 0;
1543715446
}
1543815447

15448+
void bnxt_set_cp_rings(struct bnxt *bp, bool sh)
15449+
{
15450+
int tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
15451+
15452+
bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
15453+
tx_cp + bp->rx_nr_rings;
15454+
}
15455+
1543915456
int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
1544015457
{
1544115458
struct bnxt *bp = netdev_priv(dev);
1544215459
bool sh = false;
15443-
int rc, tx_cp;
15460+
int rc;
1544415461

1544515462
if (tc > bp->max_tc) {
1544615463
netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
@@ -15473,9 +15490,7 @@ int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
1547315490
bp->num_tc = 0;
1547415491
}
1547515492
bp->tx_nr_rings += bp->tx_nr_rings_xdp;
15476-
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
15477-
bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
15478-
tx_cp + bp->rx_nr_rings;
15493+
bnxt_set_cp_rings(bp, sh);
1547915494

1548015495
if (netif_running(bp->dev))
1548115496
return bnxt_open_nic(bp, true, false);
@@ -16525,6 +16540,15 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
1652516540
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
1652616541
}
1652716542

16543+
static void bnxt_adj_dflt_rings(struct bnxt *bp, bool sh)
16544+
{
16545+
if (sh)
16546+
bnxt_trim_dflt_sh_rings(bp);
16547+
else
16548+
bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
16549+
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
16550+
}
16551+
1652816552
static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1652916553
{
1653016554
int dflt_rings, max_rx_rings, max_tx_rings, rc;
@@ -16550,11 +16574,8 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1655016574
return rc;
1655116575
bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
1655216576
bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
16553-
if (sh)
16554-
bnxt_trim_dflt_sh_rings(bp);
16555-
else
16556-
bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
16557-
bp->tx_nr_rings = bnxt_tx_nr_rings(bp);
16577+
16578+
bnxt_adj_dflt_rings(bp, sh);
1655816579

1655916580
avail_msix = bnxt_get_max_func_irqs(bp) - bp->cp_nr_rings;
1656016581
if (avail_msix >= BNXT_MIN_ROCE_CP_RINGS) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,7 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
29852985
int tx_xdp);
29862986
int bnxt_fw_init_one(struct bnxt *bp);
29872987
bool bnxt_hwrm_reset_permitted(struct bnxt *bp);
2988+
void bnxt_set_cp_rings(struct bnxt *bp, bool sh);
29882989
int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
29892990
struct bnxt_ntuple_filter *bnxt_lookup_ntp_filter_from_idx(struct bnxt *bp,
29902991
struct bnxt_ntuple_filter *fltr, u32 idx);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ static int bnxt_set_channels(struct net_device *dev,
945945
bool sh = false;
946946
int tx_xdp = 0;
947947
int rc = 0;
948-
int tx_cp;
949948

950949
if (channel->other_count)
951950
return -EINVAL;
@@ -1013,9 +1012,7 @@ static int bnxt_set_channels(struct net_device *dev,
10131012
if (tcs > 1)
10141013
bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
10151014

1016-
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
1017-
bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
1018-
tx_cp + bp->rx_nr_rings;
1015+
bnxt_set_cp_rings(bp, sh);
10191016

10201017
/* After changing number of rx channels, update NTUPLE feature. */
10211018
netdev_update_features(dev);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames,
384384
static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
385385
{
386386
struct net_device *dev = bp->dev;
387-
int tx_xdp = 0, tx_cp, rc, tc;
387+
int tx_xdp = 0, rc, tc;
388388
struct bpf_prog *old;
389389

390390
netdev_assert_locked(dev);
@@ -431,8 +431,7 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
431431
}
432432
bp->tx_nr_rings_xdp = tx_xdp;
433433
bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp;
434-
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
435-
bp->cp_nr_rings = max_t(int, tx_cp, bp->rx_nr_rings);
434+
bnxt_set_cp_rings(bp, true);
436435
bnxt_set_tpa_flags(bp);
437436
bnxt_set_ring_params(bp);
438437

0 commit comments

Comments
 (0)