Skip to content

Commit f5b29c6

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Add helper to get the number of CP rings required for TX rings
Up until now, each TX ring always requires a completion ring/NQ/MSIX. bnxt_trim_rings() and the assignment of bp->cp_nr_rings always make this assumption. This will no longer be true in the next patches, so we refactor and add helper functions to determine the proper relationship between TX rings and the required completion ring/NQ/MSIX. This patch does not change the 1:1 relationship yet. Note that on P5 chips, each RX and TX ring still requires a completion ring. Only the number of NQs has been reduced. We should no longer call bnxt_trim_rings() to adjust the RX and TX rings on P5 chips. Replace with simple logic to check that RX + TX < CP and adjust accordingly. bnxt_check_rings() should call _bnxt_get_max_rings() to get the raw number of rings instead of bnxt_get_max_rings(). If we are about to create TCs, bnxt_get_max_rings() would not be able to calculate the max rings correctly. Reviewed-by: Andy Gospodarek <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0589a1e commit f5b29c6

File tree

4 files changed

+82
-25
lines changed

4 files changed

+82
-25
lines changed

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

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6284,7 +6284,8 @@ static int bnxt_hwrm_get_rings(struct bnxt *bp)
62846284
if (bp->flags & BNXT_FLAG_AGG_RINGS)
62856285
rx >>= 1;
62866286
if (cp < (rx + tx)) {
6287-
bnxt_trim_rings(bp, &rx, &tx, cp, false);
6287+
rx = cp / 2;
6288+
tx = rx;
62886289
if (bp->flags & BNXT_FLAG_AGG_RINGS)
62896290
rx <<= 1;
62906291
hw_resc->resv_rx_rings = rx;
@@ -6585,6 +6586,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
65856586
int grp, rx_rings, rc;
65866587
int vnic = 1, stat;
65876588
bool sh = false;
6589+
int tx_cp;
65886590

65896591
if (!bnxt_need_reserve_rings(bp))
65906592
return 0;
@@ -6634,7 +6636,8 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
66346636
rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh);
66356637
if (bp->flags & BNXT_FLAG_AGG_RINGS)
66366638
rx = rx_rings << 1;
6637-
cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings;
6639+
tx_cp = bnxt_num_tx_to_cp(bp, tx);
6640+
cp = sh ? max_t(int, tx_cp, rx_rings) : tx_cp + rx_rings;
66386641
bp->tx_nr_rings = tx;
66396642

66406643
/* If we cannot reserve all the RX rings, reset the RSS map only
@@ -9061,8 +9064,8 @@ static int bnxt_set_real_num_queues(struct bnxt *bp)
90619064
return rc;
90629065
}
90639066

9064-
static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
9065-
bool shared)
9067+
static int __bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
9068+
bool shared)
90669069
{
90679070
int _rx = *rx, _tx = *tx;
90689071

@@ -9085,6 +9088,46 @@ static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
90859088
return 0;
90869089
}
90879090

9091+
static int __bnxt_num_tx_to_cp(struct bnxt *bp, int tx, int tx_sets, int tx_xdp)
9092+
{
9093+
return tx;
9094+
}
9095+
9096+
int bnxt_num_tx_to_cp(struct bnxt *bp, int tx)
9097+
{
9098+
int tcs = netdev_get_num_tc(bp->dev);
9099+
9100+
if (!tcs)
9101+
tcs = 1;
9102+
return __bnxt_num_tx_to_cp(bp, tx, tcs, bp->tx_nr_rings_xdp);
9103+
}
9104+
9105+
static int bnxt_num_cp_to_tx(struct bnxt *bp, int tx_cp)
9106+
{
9107+
int tcs = netdev_get_num_tc(bp->dev);
9108+
9109+
return (tx_cp - bp->tx_nr_rings_xdp) * tcs +
9110+
bp->tx_nr_rings_xdp;
9111+
}
9112+
9113+
static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
9114+
bool sh)
9115+
{
9116+
int tx_cp = bnxt_num_tx_to_cp(bp, *tx);
9117+
9118+
if (tx_cp != *tx) {
9119+
int tx_saved = tx_cp, rc;
9120+
9121+
rc = __bnxt_trim_rings(bp, rx, &tx_cp, max, sh);
9122+
if (rc)
9123+
return rc;
9124+
if (tx_cp != tx_saved)
9125+
*tx = bnxt_num_cp_to_tx(bp, tx_cp);
9126+
return 0;
9127+
}
9128+
return __bnxt_trim_rings(bp, rx, tx, max, sh);
9129+
}
9130+
90889131
static void bnxt_setup_msix(struct bnxt *bp)
90899132
{
90909133
const int len = sizeof(bp->irq_tbl[0].name);
@@ -9247,7 +9290,7 @@ static int bnxt_get_num_msix(struct bnxt *bp)
92479290

92489291
static int bnxt_init_msix(struct bnxt *bp)
92499292
{
9250-
int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
9293+
int i, total_vecs, max, rc = 0, min = 1, ulp_msix, tx_cp;
92519294
struct msix_entry *msix_ent;
92529295

92539296
total_vecs = bnxt_get_num_msix(bp);
@@ -9289,9 +9332,10 @@ static int bnxt_init_msix(struct bnxt *bp)
92899332
if (rc)
92909333
goto msix_setup_exit;
92919334

9335+
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
92929336
bp->cp_nr_rings = (min == 1) ?
9293-
max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
9294-
bp->tx_nr_rings + bp->rx_nr_rings;
9337+
max_t(int, tx_cp, bp->rx_nr_rings) :
9338+
tx_cp + bp->rx_nr_rings;
92959339

92969340
} else {
92979341
rc = -ENOMEM;
@@ -12186,23 +12230,27 @@ static void bnxt_sp_task(struct work_struct *work)
1218612230
clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
1218712231
}
1218812232

12233+
static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
12234+
int *max_cp);
12235+
1218912236
/* Under rtnl_lock */
1219012237
int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
1219112238
int tx_xdp)
1219212239
{
12193-
int max_rx, max_tx, tx_sets = 1;
12240+
int max_rx, max_tx, max_cp, tx_sets = 1, tx_cp;
1219412241
int tx_rings_needed, stats;
1219512242
int rx_rings = rx;
12196-
int cp, vnics, rc;
12243+
int cp, vnics;
1219712244

1219812245
if (tcs)
1219912246
tx_sets = tcs;
1220012247

12201-
rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh);
12202-
if (rc)
12203-
return rc;
12248+
if (bp->flags & BNXT_FLAG_AGG_RINGS)
12249+
rx_rings <<= 1;
1220412250

12205-
if (max_rx < rx)
12251+
_bnxt_get_max_rings(bp, &max_rx, &max_tx, &max_cp);
12252+
12253+
if (max_rx < rx_rings)
1220612254
return -ENOMEM;
1220712255

1220812256
tx_rings_needed = tx * tx_sets + tx_xdp;
@@ -12211,11 +12259,12 @@ int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs,
1221112259

1221212260
vnics = 1;
1221312261
if ((bp->flags & (BNXT_FLAG_RFS | BNXT_FLAG_CHIP_P5)) == BNXT_FLAG_RFS)
12214-
vnics += rx_rings;
12262+
vnics += rx;
1221512263

12216-
if (bp->flags & BNXT_FLAG_AGG_RINGS)
12217-
rx_rings <<= 1;
12218-
cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx;
12264+
tx_cp = __bnxt_num_tx_to_cp(bp, tx_rings_needed, tx_sets, tx_xdp);
12265+
cp = sh ? max_t(int, tx_cp, rx) : tx_cp + rx;
12266+
if (max_cp < cp)
12267+
return -ENOMEM;
1221912268
stats = cp;
1222012269
if (BNXT_NEW_RM(bp)) {
1222112270
cp += bnxt_get_ulp_msix_num(bp);
@@ -12849,7 +12898,7 @@ int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
1284912898
{
1285012899
struct bnxt *bp = netdev_priv(dev);
1285112900
bool sh = false;
12852-
int rc;
12901+
int rc, tx_cp;
1285312902

1285412903
if (tc > bp->max_tc) {
1285512904
netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n",
@@ -12880,8 +12929,9 @@ int bnxt_setup_mq_tc(struct net_device *dev, u8 tc)
1288012929
netdev_reset_tc(dev);
1288112930
}
1288212931
bp->tx_nr_rings += bp->tx_nr_rings_xdp;
12883-
bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
12884-
bp->tx_nr_rings + bp->rx_nr_rings;
12932+
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
12933+
bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
12934+
tx_cp + bp->rx_nr_rings;
1288512935

1288612936
if (netif_running(bp->dev))
1288712937
return bnxt_open_nic(bp, true, false);
@@ -13360,7 +13410,10 @@ static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx,
1336013410
if (bp->flags & BNXT_FLAG_AGG_RINGS)
1336113411
*max_rx >>= 1;
1336213412
if (bp->flags & BNXT_FLAG_CHIP_P5) {
13363-
bnxt_trim_rings(bp, max_rx, max_tx, *max_cp, false);
13413+
if (*max_cp < (*max_rx + *max_tx)) {
13414+
*max_rx = *max_cp / 2;
13415+
*max_tx = *max_rx;
13416+
}
1336413417
/* On P5 chips, max_cp output param should be available NQs */
1336513418
*max_cp = max_irq;
1336613419
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,7 @@ int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);
23932393
int bnxt_nq_rings_in_use(struct bnxt *bp);
23942394
int bnxt_hwrm_set_coal(struct bnxt *);
23952395
void bnxt_free_ctx_mem(struct bnxt *bp);
2396+
int bnxt_num_tx_to_cp(struct bnxt *bp, int tx);
23962397
unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
23972398
unsigned int bnxt_get_avail_stat_ctxs_for_en(struct bnxt *bp);
23982399
unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ static int bnxt_set_channels(struct net_device *dev,
923923
bool sh = false;
924924
int tx_xdp = 0;
925925
int rc = 0;
926+
int tx_cp;
926927

927928
if (channel->other_count)
928929
return -EINVAL;
@@ -994,8 +995,9 @@ static int bnxt_set_channels(struct net_device *dev,
994995
if (tcs > 1)
995996
bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
996997

997-
bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
998-
bp->tx_nr_rings + bp->rx_nr_rings;
998+
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
999+
bp->cp_nr_rings = sh ? max_t(int, tx_cp, bp->rx_nr_rings) :
1000+
tx_cp + bp->rx_nr_rings;
9991001

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int bnxt_xdp_xmit(struct net_device *dev, int num_frames,
398398
static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
399399
{
400400
struct net_device *dev = bp->dev;
401-
int tx_xdp = 0, rc, tc;
401+
int tx_xdp = 0, tx_cp, rc, tc;
402402
struct bpf_prog *old;
403403

404404
if (prog && !prog->aux->xdp_has_frags &&
@@ -446,7 +446,8 @@ static int bnxt_xdp_set(struct bnxt *bp, struct bpf_prog *prog)
446446
}
447447
bp->tx_nr_rings_xdp = tx_xdp;
448448
bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp;
449-
bp->cp_nr_rings = max_t(int, bp->tx_nr_rings, bp->rx_nr_rings);
449+
tx_cp = bnxt_num_tx_to_cp(bp, bp->tx_nr_rings);
450+
bp->cp_nr_rings = max_t(int, tx_cp, bp->rx_nr_rings);
450451
bnxt_set_tpa_flags(bp);
451452
bnxt_set_ring_params(bp);
452453

0 commit comments

Comments
 (0)