@@ -603,6 +603,8 @@ static int bcmgenet_get_coalesce(struct net_device *dev,
603
603
struct ethtool_coalesce * ec )
604
604
{
605
605
struct bcmgenet_priv * priv = netdev_priv (dev );
606
+ struct bcmgenet_rx_ring * ring ;
607
+ unsigned int i ;
606
608
607
609
ec -> tx_max_coalesced_frames =
608
610
bcmgenet_tdma_ring_readl (priv , DESC_INDEX ,
@@ -613,15 +615,37 @@ static int bcmgenet_get_coalesce(struct net_device *dev,
613
615
ec -> rx_coalesce_usecs =
614
616
bcmgenet_rdma_readl (priv , DMA_RING16_TIMEOUT ) * 8192 / 1000 ;
615
617
618
+ for (i = 0 ; i < priv -> hw_params -> rx_queues ; i ++ ) {
619
+ ring = & priv -> rx_rings [i ];
620
+ ec -> use_adaptive_rx_coalesce |= ring -> dim .use_dim ;
621
+ }
622
+ ring = & priv -> rx_rings [DESC_INDEX ];
623
+ ec -> use_adaptive_rx_coalesce |= ring -> dim .use_dim ;
624
+
616
625
return 0 ;
617
626
}
618
627
628
+ static void bcmgenet_set_rx_coalesce (struct bcmgenet_rx_ring * ring )
629
+ {
630
+ struct bcmgenet_priv * priv = ring -> priv ;
631
+ unsigned int i = ring -> index ;
632
+ u32 reg ;
633
+
634
+ bcmgenet_rdma_ring_writel (priv , i , ring -> dim .coal_pkts ,
635
+ DMA_MBUF_DONE_THRESH );
636
+
637
+ reg = bcmgenet_rdma_readl (priv , DMA_RING0_TIMEOUT + i );
638
+ reg &= ~DMA_TIMEOUT_MASK ;
639
+ reg |= DIV_ROUND_UP (ring -> dim .coal_usecs * 1000 , 8192 );
640
+ bcmgenet_rdma_writel (priv , reg , DMA_RING0_TIMEOUT + i );
641
+ }
642
+
619
643
static int bcmgenet_set_coalesce (struct net_device * dev ,
620
644
struct ethtool_coalesce * ec )
621
645
{
622
646
struct bcmgenet_priv * priv = netdev_priv (dev );
647
+ struct bcmgenet_rx_ring * ring ;
623
648
unsigned int i ;
624
- u32 reg ;
625
649
626
650
/* Base system clock is 125Mhz, DMA timeout is this reference clock
627
651
* divided by 1024, which yields roughly 8.192us, our maximum value
@@ -641,7 +665,8 @@ static int bcmgenet_set_coalesce(struct net_device *dev,
641
665
* transmitted, or when the ring is empty.
642
666
*/
643
667
if (ec -> tx_coalesce_usecs || ec -> tx_coalesce_usecs_high ||
644
- ec -> tx_coalesce_usecs_irq || ec -> tx_coalesce_usecs_low )
668
+ ec -> tx_coalesce_usecs_irq || ec -> tx_coalesce_usecs_low ||
669
+ ec -> use_adaptive_tx_coalesce )
645
670
return - EOPNOTSUPP ;
646
671
647
672
/* Program all TX queues with the same values, as there is no
@@ -656,24 +681,26 @@ static int bcmgenet_set_coalesce(struct net_device *dev,
656
681
DMA_MBUF_DONE_THRESH );
657
682
658
683
for (i = 0 ; i < priv -> hw_params -> rx_queues ; i ++ ) {
659
- bcmgenet_rdma_ring_writel (priv , i ,
660
- ec -> rx_max_coalesced_frames ,
661
- DMA_MBUF_DONE_THRESH );
662
-
663
- reg = bcmgenet_rdma_readl (priv , DMA_RING0_TIMEOUT + i );
664
- reg &= ~DMA_TIMEOUT_MASK ;
665
- reg |= DIV_ROUND_UP (ec -> rx_coalesce_usecs * 1000 , 8192 );
666
- bcmgenet_rdma_writel (priv , reg , DMA_RING0_TIMEOUT + i );
684
+ ring = & priv -> rx_rings [i ];
685
+ ring -> dim .coal_usecs = ec -> rx_coalesce_usecs ;
686
+ ring -> dim .coal_pkts = ec -> rx_max_coalesced_frames ;
687
+ if (!ec -> use_adaptive_rx_coalesce && ring -> dim .use_dim ) {
688
+ ring -> dim .coal_pkts = 1 ;
689
+ ring -> dim .coal_usecs = 0 ;
690
+ }
691
+ ring -> dim .use_dim = ec -> use_adaptive_rx_coalesce ;
692
+ bcmgenet_set_rx_coalesce (ring );
667
693
}
668
694
669
- bcmgenet_rdma_ring_writel (priv , DESC_INDEX ,
670
- ec -> rx_max_coalesced_frames ,
671
- DMA_MBUF_DONE_THRESH );
672
-
673
- reg = bcmgenet_rdma_readl (priv , DMA_RING16_TIMEOUT );
674
- reg &= ~DMA_TIMEOUT_MASK ;
675
- reg |= DIV_ROUND_UP (ec -> rx_coalesce_usecs * 1000 , 8192 );
676
- bcmgenet_rdma_writel (priv , reg , DMA_RING16_TIMEOUT );
695
+ ring = & priv -> rx_rings [DESC_INDEX ];
696
+ ring -> dim .coal_usecs = ec -> rx_coalesce_usecs ;
697
+ ring -> dim .coal_pkts = ec -> rx_max_coalesced_frames ;
698
+ if (!ec -> use_adaptive_rx_coalesce && ring -> dim .use_dim ) {
699
+ ring -> dim .coal_pkts = 1 ;
700
+ ring -> dim .coal_usecs = 0 ;
701
+ }
702
+ ring -> dim .use_dim = ec -> use_adaptive_rx_coalesce ;
703
+ bcmgenet_set_rx_coalesce (ring );
677
704
678
705
return 0 ;
679
706
}
@@ -1713,6 +1740,7 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
1713
1740
unsigned long dma_flag ;
1714
1741
int len ;
1715
1742
unsigned int rxpktprocessed = 0 , rxpkttoprocess ;
1743
+ unsigned int bytes_processed = 0 ;
1716
1744
unsigned int p_index , mask ;
1717
1745
unsigned int discards ;
1718
1746
unsigned int chksum_ok = 0 ;
@@ -1832,6 +1860,8 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
1832
1860
len -= ETH_FCS_LEN ;
1833
1861
}
1834
1862
1863
+ bytes_processed += len ;
1864
+
1835
1865
/*Finish setting up the received SKB and send it to the kernel*/
1836
1866
skb -> protocol = eth_type_trans (skb , priv -> dev );
1837
1867
ring -> packets ++ ;
@@ -1854,6 +1884,9 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
1854
1884
bcmgenet_rdma_ring_writel (priv , ring -> index , ring -> c_index , RDMA_CONS_INDEX );
1855
1885
}
1856
1886
1887
+ ring -> dim .bytes = bytes_processed ;
1888
+ ring -> dim .packets = rxpktprocessed ;
1889
+
1857
1890
return rxpktprocessed ;
1858
1891
}
1859
1892
@@ -1862,6 +1895,7 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget)
1862
1895
{
1863
1896
struct bcmgenet_rx_ring * ring = container_of (napi ,
1864
1897
struct bcmgenet_rx_ring , napi );
1898
+ struct net_dim_sample dim_sample ;
1865
1899
unsigned int work_done ;
1866
1900
1867
1901
work_done = bcmgenet_desc_rx (ring , budget );
@@ -1871,9 +1905,32 @@ static int bcmgenet_rx_poll(struct napi_struct *napi, int budget)
1871
1905
ring -> int_enable (ring );
1872
1906
}
1873
1907
1908
+ if (ring -> dim .use_dim ) {
1909
+ net_dim_sample (ring -> dim .event_ctr , ring -> dim .packets ,
1910
+ ring -> dim .bytes , & dim_sample );
1911
+ net_dim (& ring -> dim .dim , dim_sample );
1912
+ }
1913
+
1874
1914
return work_done ;
1875
1915
}
1876
1916
1917
+ static void bcmgenet_dim_work (struct work_struct * work )
1918
+ {
1919
+ struct net_dim * dim = container_of (work , struct net_dim , work );
1920
+ struct bcmgenet_net_dim * ndim =
1921
+ container_of (dim , struct bcmgenet_net_dim , dim );
1922
+ struct bcmgenet_rx_ring * ring =
1923
+ container_of (ndim , struct bcmgenet_rx_ring , dim );
1924
+ struct net_dim_cq_moder cur_profile =
1925
+ net_dim_get_profile (dim -> mode , dim -> profile_ix );
1926
+
1927
+ ring -> dim .coal_usecs = cur_profile .usec ;
1928
+ ring -> dim .coal_pkts = cur_profile .pkts ;
1929
+
1930
+ bcmgenet_set_rx_coalesce (ring );
1931
+ dim -> state = NET_DIM_START_MEASURE ;
1932
+ }
1933
+
1877
1934
/* Assign skb to RX DMA descriptor. */
1878
1935
static int bcmgenet_alloc_rx_buffers (struct bcmgenet_priv * priv ,
1879
1936
struct bcmgenet_rx_ring * ring )
@@ -2022,6 +2079,16 @@ static void init_umac(struct bcmgenet_priv *priv)
2022
2079
dev_dbg (kdev , "done init umac\n" );
2023
2080
}
2024
2081
2082
+ static void bcmgenet_init_dim (struct bcmgenet_net_dim * dim ,
2083
+ void (* cb )(struct work_struct * work ))
2084
+ {
2085
+ INIT_WORK (& dim -> dim .work , cb );
2086
+ dim -> dim .mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE ;
2087
+ dim -> event_ctr = 0 ;
2088
+ dim -> packets = 0 ;
2089
+ dim -> bytes = 0 ;
2090
+ }
2091
+
2025
2092
/* Initialize a Tx ring along with corresponding hardware registers */
2026
2093
static void bcmgenet_init_tx_ring (struct bcmgenet_priv * priv ,
2027
2094
unsigned int index , unsigned int size ,
@@ -2111,6 +2178,8 @@ static int bcmgenet_init_rx_ring(struct bcmgenet_priv *priv,
2111
2178
if (ret )
2112
2179
return ret ;
2113
2180
2181
+ bcmgenet_init_dim (& ring -> dim , bcmgenet_dim_work );
2182
+
2114
2183
/* Initialize Rx NAPI */
2115
2184
netif_napi_add (priv -> dev , & ring -> napi , bcmgenet_rx_poll ,
2116
2185
NAPI_POLL_WEIGHT );
@@ -2276,10 +2345,12 @@ static void bcmgenet_disable_rx_napi(struct bcmgenet_priv *priv)
2276
2345
for (i = 0 ; i < priv -> hw_params -> rx_queues ; ++ i ) {
2277
2346
ring = & priv -> rx_rings [i ];
2278
2347
napi_disable (& ring -> napi );
2348
+ cancel_work_sync (& ring -> dim .dim .work );
2279
2349
}
2280
2350
2281
2351
ring = & priv -> rx_rings [DESC_INDEX ];
2282
2352
napi_disable (& ring -> napi );
2353
+ cancel_work_sync (& ring -> dim .dim .work );
2283
2354
}
2284
2355
2285
2356
static void bcmgenet_fini_rx_napi (struct bcmgenet_priv * priv )
@@ -2557,6 +2628,7 @@ static irqreturn_t bcmgenet_isr1(int irq, void *dev_id)
2557
2628
continue ;
2558
2629
2559
2630
rx_ring = & priv -> rx_rings [index ];
2631
+ rx_ring -> dim .event_ctr ++ ;
2560
2632
2561
2633
if (likely (napi_schedule_prep (& rx_ring -> napi ))) {
2562
2634
rx_ring -> int_disable (rx_ring );
@@ -2601,6 +2673,7 @@ static irqreturn_t bcmgenet_isr0(int irq, void *dev_id)
2601
2673
2602
2674
if (status & UMAC_IRQ_RXDMA_DONE ) {
2603
2675
rx_ring = & priv -> rx_rings [DESC_INDEX ];
2676
+ rx_ring -> dim .event_ctr ++ ;
2604
2677
2605
2678
if (likely (napi_schedule_prep (& rx_ring -> napi ))) {
2606
2679
rx_ring -> int_disable (rx_ring );
0 commit comments