@@ -4038,6 +4038,30 @@ static int bnxt_set_real_num_queues(struct bnxt *bp)
4038
4038
return rc ;
4039
4039
}
4040
4040
4041
+ static int bnxt_trim_rings (struct bnxt * bp , int * rx , int * tx , int max ,
4042
+ bool shared )
4043
+ {
4044
+ int _rx = * rx , _tx = * tx ;
4045
+
4046
+ if (shared ) {
4047
+ * rx = min_t (int , _rx , max );
4048
+ * tx = min_t (int , _tx , max );
4049
+ } else {
4050
+ if (max < 2 )
4051
+ return - ENOMEM ;
4052
+
4053
+ while (_rx + _tx > max ) {
4054
+ if (_rx > _tx && _rx > 1 )
4055
+ _rx -- ;
4056
+ else if (_tx > 1 )
4057
+ _tx -- ;
4058
+ }
4059
+ * rx = _rx ;
4060
+ * tx = _tx ;
4061
+ }
4062
+ return 0 ;
4063
+ }
4064
+
4041
4065
static int bnxt_setup_msix (struct bnxt * bp )
4042
4066
{
4043
4067
struct msix_entry * msix_ent ;
@@ -4068,8 +4092,11 @@ static int bnxt_setup_msix(struct bnxt *bp)
4068
4092
int tcs ;
4069
4093
4070
4094
/* Trim rings based upon num of vectors allocated */
4071
- bp -> rx_nr_rings = min_t (int , total_vecs , bp -> rx_nr_rings );
4072
- bp -> tx_nr_rings = min_t (int , total_vecs , bp -> tx_nr_rings );
4095
+ rc = bnxt_trim_rings (bp , & bp -> rx_nr_rings , & bp -> tx_nr_rings ,
4096
+ total_vecs , true);
4097
+ if (rc )
4098
+ goto msix_setup_exit ;
4099
+
4073
4100
bp -> tx_nr_rings_per_tc = bp -> tx_nr_rings ;
4074
4101
tcs = netdev_get_num_tc (dev );
4075
4102
if (tcs > 1 ) {
@@ -5337,10 +5364,10 @@ static int bnxt_setup_tc(struct net_device *dev, u8 tc)
5337
5364
return 0 ;
5338
5365
5339
5366
if (tc ) {
5340
- int max_rx_rings , max_tx_rings ;
5367
+ int max_rx_rings , max_tx_rings , rc ;
5341
5368
5342
- bnxt_get_max_rings (bp , & max_rx_rings , & max_tx_rings );
5343
- if (bp -> tx_nr_rings_per_tc * tc > max_tx_rings )
5369
+ rc = bnxt_get_max_rings (bp , & max_rx_rings , & max_tx_rings , true );
5370
+ if (rc || bp -> tx_nr_rings_per_tc * tc > max_tx_rings )
5344
5371
return - ENOMEM ;
5345
5372
}
5346
5373
@@ -5654,39 +5681,70 @@ static int bnxt_get_max_irq(struct pci_dev *pdev)
5654
5681
return (ctrl & PCI_MSIX_FLAGS_QSIZE ) + 1 ;
5655
5682
}
5656
5683
5657
- void bnxt_get_max_rings (struct bnxt * bp , int * max_rx , int * max_tx )
5684
+ static void _bnxt_get_max_rings (struct bnxt * bp , int * max_rx , int * max_tx ,
5685
+ int * max_cp )
5658
5686
{
5659
- int max_rings = 0 , max_ring_grps = 0 ;
5687
+ int max_ring_grps = 0 ;
5660
5688
5661
5689
if (BNXT_PF (bp )) {
5662
5690
* max_tx = bp -> pf .max_tx_rings ;
5663
5691
* max_rx = bp -> pf .max_rx_rings ;
5664
- max_rings = min_t (int , bp -> pf .max_irqs , bp -> pf .max_cp_rings );
5665
- max_rings = min_t (int , max_rings , bp -> pf .max_stat_ctxs );
5692
+ * max_cp = min_t (int , bp -> pf .max_irqs , bp -> pf .max_cp_rings );
5693
+ * max_cp = min_t (int , * max_cp , bp -> pf .max_stat_ctxs );
5666
5694
max_ring_grps = bp -> pf .max_hw_ring_grps ;
5667
5695
} else {
5668
5696
#ifdef CONFIG_BNXT_SRIOV
5669
5697
* max_tx = bp -> vf .max_tx_rings ;
5670
5698
* max_rx = bp -> vf .max_rx_rings ;
5671
- max_rings = min_t (int , bp -> vf .max_irqs , bp -> vf .max_cp_rings );
5672
- max_rings = min_t (int , max_rings , bp -> vf .max_stat_ctxs );
5699
+ * max_cp = min_t (int , bp -> vf .max_irqs , bp -> vf .max_cp_rings );
5700
+ * max_cp = min_t (int , * max_cp , bp -> vf .max_stat_ctxs );
5673
5701
max_ring_grps = bp -> vf .max_hw_ring_grps ;
5674
5702
#endif
5675
5703
}
5676
5704
if (bp -> flags & BNXT_FLAG_AGG_RINGS )
5677
5705
* max_rx >>= 1 ;
5678
-
5679
- * max_rx = min_t (int , * max_rx , max_rings );
5680
5706
* max_rx = min_t (int , * max_rx , max_ring_grps );
5681
- * max_tx = min_t (int , * max_tx , max_rings );
5707
+ }
5708
+
5709
+ int bnxt_get_max_rings (struct bnxt * bp , int * max_rx , int * max_tx , bool shared )
5710
+ {
5711
+ int rx , tx , cp ;
5712
+
5713
+ _bnxt_get_max_rings (bp , & rx , & tx , & cp );
5714
+ if (!rx || !tx || !cp )
5715
+ return - ENOMEM ;
5716
+
5717
+ * max_rx = rx ;
5718
+ * max_tx = tx ;
5719
+ return bnxt_trim_rings (bp , max_rx , max_tx , cp , shared );
5720
+ }
5721
+
5722
+ static int bnxt_set_dflt_rings (struct bnxt * bp )
5723
+ {
5724
+ int dflt_rings , max_rx_rings , max_tx_rings , rc ;
5725
+ bool sh = true;
5726
+
5727
+ if (sh )
5728
+ bp -> flags |= BNXT_FLAG_SHARED_RINGS ;
5729
+ dflt_rings = netif_get_num_default_rss_queues ();
5730
+ rc = bnxt_get_max_rings (bp , & max_rx_rings , & max_tx_rings , sh );
5731
+ if (rc )
5732
+ return rc ;
5733
+ bp -> rx_nr_rings = min_t (int , dflt_rings , max_rx_rings );
5734
+ bp -> tx_nr_rings_per_tc = min_t (int , dflt_rings , max_tx_rings );
5735
+ bp -> tx_nr_rings = bp -> tx_nr_rings_per_tc ;
5736
+ bp -> cp_nr_rings = sh ? max_t (int , bp -> tx_nr_rings , bp -> rx_nr_rings ) :
5737
+ bp -> tx_nr_rings + bp -> rx_nr_rings ;
5738
+ bp -> num_stat_ctxs = bp -> cp_nr_rings ;
5739
+ return rc ;
5682
5740
}
5683
5741
5684
5742
static int bnxt_init_one (struct pci_dev * pdev , const struct pci_device_id * ent )
5685
5743
{
5686
5744
static int version_printed ;
5687
5745
struct net_device * dev ;
5688
5746
struct bnxt * bp ;
5689
- int rc , max_rx_rings , max_tx_rings , max_irqs , dflt_rings ;
5747
+ int rc , max_irqs ;
5690
5748
5691
5749
if (version_printed ++ == 0 )
5692
5750
pr_info ("%s" , version );
@@ -5765,19 +5823,13 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
5765
5823
5766
5824
bnxt_set_tpa_flags (bp );
5767
5825
bnxt_set_ring_params (bp );
5768
- dflt_rings = netif_get_num_default_rss_queues ();
5769
5826
if (BNXT_PF (bp ))
5770
5827
bp -> pf .max_irqs = max_irqs ;
5771
5828
#if defined(CONFIG_BNXT_SRIOV )
5772
5829
else
5773
5830
bp -> vf .max_irqs = max_irqs ;
5774
5831
#endif
5775
- bnxt_get_max_rings (bp , & max_rx_rings , & max_tx_rings );
5776
- bp -> rx_nr_rings = min_t (int , dflt_rings , max_rx_rings );
5777
- bp -> tx_nr_rings_per_tc = min_t (int , dflt_rings , max_tx_rings );
5778
- bp -> tx_nr_rings = bp -> tx_nr_rings_per_tc ;
5779
- bp -> cp_nr_rings = max_t (int , bp -> rx_nr_rings , bp -> tx_nr_rings );
5780
- bp -> num_stat_ctxs = bp -> cp_nr_rings ;
5832
+ bnxt_set_dflt_rings (bp );
5781
5833
5782
5834
if (BNXT_PF (bp )) {
5783
5835
dev -> hw_features |= NETIF_F_NTUPLE ;
0 commit comments