@@ -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+
90889131static 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
92489291static 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 */
1219012237int 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 }
0 commit comments