4707aacd9d3269d916f769845060dc135f606c8d
[openwrt/staging/xback.git] /
1 From 84b9cd389036d4a262d8cee794d56c04095358a7 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Fri, 22 Jul 2022 09:19:40 +0200
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: add support for
5 page_pool_get_stats
6
7 Introduce support for the page_pool stats API into mtk_eth_soc driver.
8 Report page_pool stats through ethtool.
9
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 drivers/net/ethernet/mediatek/Kconfig | 1 +
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 37 +++++++++++++++++++--
15 2 files changed, 35 insertions(+), 3 deletions(-)
16
17 --- a/drivers/net/ethernet/mediatek/Kconfig
18 +++ b/drivers/net/ethernet/mediatek/Kconfig
19 @@ -17,6 +17,7 @@ config NET_MEDIATEK_SOC
20 select PHYLINK
21 select DIMLIB
22 select PAGE_POOL
23 + select PAGE_POOL_STATS
24 help
25 This driver supports the gigabit ethernet MACs in the
26 MediaTek SoC family.
27 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
28 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
29 @@ -3473,11 +3473,18 @@ static void mtk_get_strings(struct net_d
30 int i;
31
32 switch (stringset) {
33 - case ETH_SS_STATS:
34 + case ETH_SS_STATS: {
35 + struct mtk_mac *mac = netdev_priv(dev);
36 +
37 for (i = 0; i < ARRAY_SIZE(mtk_ethtool_stats); i++) {
38 memcpy(data, mtk_ethtool_stats[i].str, ETH_GSTRING_LEN);
39 data += ETH_GSTRING_LEN;
40 }
41 + if (mtk_page_pool_enabled(mac->hw))
42 + page_pool_ethtool_stats_get_strings(data);
43 + break;
44 + }
45 + default:
46 break;
47 }
48 }
49 @@ -3485,13 +3492,35 @@ static void mtk_get_strings(struct net_d
50 static int mtk_get_sset_count(struct net_device *dev, int sset)
51 {
52 switch (sset) {
53 - case ETH_SS_STATS:
54 - return ARRAY_SIZE(mtk_ethtool_stats);
55 + case ETH_SS_STATS: {
56 + int count = ARRAY_SIZE(mtk_ethtool_stats);
57 + struct mtk_mac *mac = netdev_priv(dev);
58 +
59 + if (mtk_page_pool_enabled(mac->hw))
60 + count += page_pool_ethtool_stats_get_count();
61 + return count;
62 + }
63 default:
64 return -EOPNOTSUPP;
65 }
66 }
67
68 +static void mtk_ethtool_pp_stats(struct mtk_eth *eth, u64 *data)
69 +{
70 + struct page_pool_stats stats = {};
71 + int i;
72 +
73 + for (i = 0; i < ARRAY_SIZE(eth->rx_ring); i++) {
74 + struct mtk_rx_ring *ring = &eth->rx_ring[i];
75 +
76 + if (!ring->page_pool)
77 + continue;
78 +
79 + page_pool_get_stats(ring->page_pool, &stats);
80 + }
81 + page_pool_ethtool_stats_get(data, &stats);
82 +}
83 +
84 static void mtk_get_ethtool_stats(struct net_device *dev,
85 struct ethtool_stats *stats, u64 *data)
86 {
87 @@ -3519,6 +3548,8 @@ static void mtk_get_ethtool_stats(struct
88
89 for (i = 0; i < ARRAY_SIZE(mtk_ethtool_stats); i++)
90 *data_dst++ = *(data_src + mtk_ethtool_stats[i].offset);
91 + if (mtk_page_pool_enabled(mac->hw))
92 + mtk_ethtool_pp_stats(mac->hw, data_dst);
93 } while (u64_stats_fetch_retry_irq(&hwstats->syncp, start));
94 }
95