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
7 Introduce support for the page_pool stats API into mtk_eth_soc driver.
8 Report page_pool stats through ethtool.
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
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(-)
17 --- a/drivers/net/ethernet/mediatek/Kconfig
18 +++ b/drivers/net/ethernet/mediatek/Kconfig
19 @@ -17,6 +17,7 @@ config NET_MEDIATEK_SOC
23 + select PAGE_POOL_STATS
25 This driver supports the gigabit ethernet MACs in the
27 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
28 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
29 @@ -3488,11 +3488,18 @@ static void mtk_get_strings(struct net_d
34 + case ETH_SS_STATS: {
35 + struct mtk_mac *mac = netdev_priv(dev);
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;
41 + if (mtk_page_pool_enabled(mac->hw))
42 + page_pool_ethtool_stats_get_strings(data);
49 @@ -3500,13 +3507,35 @@ static void mtk_get_strings(struct net_d
50 static int mtk_get_sset_count(struct net_device *dev, int sset)
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);
59 + if (mtk_page_pool_enabled(mac->hw))
60 + count += page_pool_ethtool_stats_get_count();
68 +static void mtk_ethtool_pp_stats(struct mtk_eth *eth, u64 *data)
70 + struct page_pool_stats stats = {};
73 + for (i = 0; i < ARRAY_SIZE(eth->rx_ring); i++) {
74 + struct mtk_rx_ring *ring = ð->rx_ring[i];
76 + if (!ring->page_pool)
79 + page_pool_get_stats(ring->page_pool, &stats);
81 + page_pool_ethtool_stats_get(data, &stats);
84 static void mtk_get_ethtool_stats(struct net_device *dev,
85 struct ethtool_stats *stats, u64 *data)
87 @@ -3534,6 +3563,8 @@ static void mtk_get_ethtool_stats(struct
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));