cf4d658684ba82076f7a6f4ccd7ed2b536d26e40
[openwrt/staging/jogo.git] /
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
5
6 Report xdp stats through ethtool
7
8 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
9 Signed-off-by: David S. Miller <davem@davemloft.net>
10 ---
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(-)
14
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) }
20
21 +#define MTK_ETHTOOL_XDP_STAT(x) { #x, \
22 + offsetof(struct mtk_hw_stats, xdp_stats.x) / \
23 + sizeof(u64) }
24 +
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),
39 };
40
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)
45 {
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;
50 u32 act = XDP_PASS;
51
52 @@ -1471,13 +1485,16 @@ static u32 mtk_xdp_run(struct mtk_eth *e
53 act = bpf_prog_run_xdp(prog, xdp);
54 switch (act) {
55 case XDP_PASS:
56 - goto out;
57 + count = &hw_stats->xdp_stats.rx_xdp_pass;
58 + goto update_stats;
59 case XDP_REDIRECT:
60 if (unlikely(xdp_do_redirect(dev, xdp, prog))) {
61 act = XDP_DROP;
62 break;
63 }
64 - goto out;
65 +
66 + count = &hw_stats->xdp_stats.rx_xdp_redirect;
67 + goto update_stats;
68 default:
69 bpf_warn_invalid_xdp_action(act);
70 fallthrough;
71 @@ -1490,6 +1507,11 @@ static u32 mtk_xdp_run(struct mtk_eth *e
72
73 page_pool_put_full_page(ring->page_pool,
74 virt_to_head_page(xdp->data), true);
75 +
76 +update_stats:
77 + u64_stats_update_begin(&hw_stats->syncp);
78 + *count = *count + 1;
79 + u64_stats_update_end(&hw_stats->syncp);
80 out:
81 rcu_read_unlock();
82
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 {
86 struct mtk_eth;
87 struct mtk_mac;
88
89 +struct mtk_xdp_stats {
90 + u64 rx_xdp_redirect;
91 + u64 rx_xdp_pass;
92 + u64 rx_xdp_drop;
93 + u64 rx_xdp_tx;
94 + u64 rx_xdp_tx_errors;
95 + u64 tx_xdp_xmit;
96 + u64 tx_xdp_xmit_errors;
97 +};
98 +
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;
105
106 + struct mtk_xdp_stats xdp_stats;
107 +
108 spinlock_t stats_lock;
109 u32 reg_offset;
110 struct u64_stats_sync syncp;