1 From 916a6ee836d6b7b8ef1ed5f0515e256ca60e9968 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Fri, 22 Jul 2022 09:19:38 +0200
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: introduce xdp ethtool counters
6 Report xdp stats through ethtool
8 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
9 Signed-off-by: David S. Miller <davem@davemloft.net>
11 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 26 +++++++++++++++++++--
12 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 12 ++++++++++
13 2 files changed, 36 insertions(+), 2 deletions(-)
15 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
16 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 @@ -34,6 +34,10 @@ MODULE_PARM_DESC(msg_level, "Message lev
18 #define MTK_ETHTOOL_STAT(x) { #x, \
19 offsetof(struct mtk_hw_stats, x) / sizeof(u64) }
21 +#define MTK_ETHTOOL_XDP_STAT(x) { #x, \
22 + offsetof(struct mtk_hw_stats, xdp_stats.x) / \
25 static const struct mtk_reg_map mtk_reg_map = {
26 .tx_irq_mask = 0x1a1c,
27 .tx_irq_status = 0x1a18,
28 @@ -141,6 +145,13 @@ static const struct mtk_ethtool_stats {
29 MTK_ETHTOOL_STAT(rx_long_errors),
30 MTK_ETHTOOL_STAT(rx_checksum_errors),
31 MTK_ETHTOOL_STAT(rx_flow_control_packets),
32 + MTK_ETHTOOL_XDP_STAT(rx_xdp_redirect),
33 + MTK_ETHTOOL_XDP_STAT(rx_xdp_pass),
34 + MTK_ETHTOOL_XDP_STAT(rx_xdp_drop),
35 + MTK_ETHTOOL_XDP_STAT(rx_xdp_tx),
36 + MTK_ETHTOOL_XDP_STAT(rx_xdp_tx_errors),
37 + MTK_ETHTOOL_XDP_STAT(tx_xdp_xmit),
38 + MTK_ETHTOOL_XDP_STAT(tx_xdp_xmit_errors),
41 static const char * const mtk_clks_source_name[] = {
42 @@ -1459,6 +1470,9 @@ static void mtk_rx_put_buff(struct mtk_r
43 static u32 mtk_xdp_run(struct mtk_eth *eth, struct mtk_rx_ring *ring,
44 struct xdp_buff *xdp, struct net_device *dev)
46 + struct mtk_mac *mac = netdev_priv(dev);
47 + struct mtk_hw_stats *hw_stats = mac->hw_stats;
48 + u64 *count = &hw_stats->xdp_stats.rx_xdp_drop;
49 struct bpf_prog *prog;
52 @@ -1471,13 +1485,16 @@ static u32 mtk_xdp_run(struct mtk_eth *e
53 act = bpf_prog_run_xdp(prog, xdp);
57 + count = &hw_stats->xdp_stats.rx_xdp_pass;
60 if (unlikely(xdp_do_redirect(dev, xdp, prog))) {
66 + count = &hw_stats->xdp_stats.rx_xdp_redirect;
69 bpf_warn_invalid_xdp_action(act);
71 @@ -1490,6 +1507,11 @@ static u32 mtk_xdp_run(struct mtk_eth *e
73 page_pool_put_full_page(ring->page_pool,
74 virt_to_head_page(xdp->data), true);
77 + u64_stats_update_begin(&hw_stats->syncp);
78 + *count = *count + 1;
79 + u64_stats_update_end(&hw_stats->syncp);
83 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
84 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
85 @@ -568,6 +568,16 @@ struct mtk_tx_dma_v2 {
89 +struct mtk_xdp_stats {
90 + u64 rx_xdp_redirect;
94 + u64 rx_xdp_tx_errors;
96 + u64 tx_xdp_xmit_errors;
99 /* struct mtk_hw_stats - the structure that holds the traffic statistics.
100 * @stats_lock: make sure that stats operations are atomic
101 * @reg_offset: the status register offset of the SoC
102 @@ -591,6 +601,8 @@ struct mtk_hw_stats {
103 u64 rx_checksum_errors;
104 u64 rx_flow_control_packets;
106 + struct mtk_xdp_stats xdp_stats;
108 spinlock_t stats_lock;
110 struct u64_stats_sync syncp;