xref: /linux/drivers/net/dsa/motorcomm/mib.h (revision ed4453587dc0082a6b6b5a52c89d6b84d713e8ac)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2026 David Yang
4  */
5 
6 #ifndef _YT_MIB_H
7 #define _YT_MIB_H
8 
9 #include <linux/u64_stats_sync.h>
10 
11 #include <net/dsa.h>
12 
13 #define YT921X_MIB_CTRL			0xc0004
14 #define  YT921X_MIB_CTRL_CLEAN			BIT(30)
15 #define  YT921X_MIB_CTRL_PORT_M			GENMASK(6, 3)
16 #define   YT921X_MIB_CTRL_PORT(x)			FIELD_PREP(YT921X_MIB_CTRL_PORT_M, (x))
17 #define  YT921X_MIB_CTRL_ONE_PORT		BIT(1)
18 #define  YT921X_MIB_CTRL_ALL_PORT		BIT(0)
19 #define YT921X_MIBn_DATA0(port)		(0xc0100 + 0x100 * (port))
20 #define YT921X_MIBn_DATAm(port, x)	(YT921X_MIBn_DATA0(port) + 4 * (x))
21 #define  YT921X_MIB_DATA_RX_BROADCAST		0x00
22 #define  YT921X_MIB_DATA_RX_PAUSE		0x04
23 #define  YT921X_MIB_DATA_RX_MULTICAST		0x08
24 #define  YT921X_MIB_DATA_RX_CRC_ERR		0x0c
25 
26 #define  YT921X_MIB_DATA_RX_ALIGN_ERR		0x10
27 #define  YT921X_MIB_DATA_RX_UNDERSIZE_ERR	0x14
28 #define  YT921X_MIB_DATA_RX_FRAG_ERR		0x18
29 #define  YT921X_MIB_DATA_RX_PKT_SZ_64		0x1c
30 
31 #define  YT921X_MIB_DATA_RX_PKT_SZ_65_TO_127	0x20
32 #define  YT921X_MIB_DATA_RX_PKT_SZ_128_TO_255	0x24
33 #define  YT921X_MIB_DATA_RX_PKT_SZ_256_TO_511	0x28
34 #define  YT921X_MIB_DATA_RX_PKT_SZ_512_TO_1023	0x2c
35 
36 #define  YT921X_MIB_DATA_RX_PKT_SZ_1024_TO_1518	0x30
37 #define  YT921X_MIB_DATA_RX_PKT_SZ_1519_TO_MAX	0x34
38 /* 0x38: unused */
39 #define  YT921X_MIB_DATA_RX_GOOD_BYTES		0x3c
40 
41 /* 0x40: 64 bytes */
42 #define  YT921X_MIB_DATA_RX_BAD_BYTES		0x44
43 /* 0x48: 64 bytes */
44 #define  YT921X_MIB_DATA_RX_OVERSIZE_ERR	0x4c
45 
46 #define  YT921X_MIB_DATA_RX_DROPPED		0x50
47 #define  YT921X_MIB_DATA_TX_BROADCAST		0x54
48 #define  YT921X_MIB_DATA_TX_PAUSE		0x58
49 #define  YT921X_MIB_DATA_TX_MULTICAST		0x5c
50 
51 #define  YT921X_MIB_DATA_TX_UNDERSIZE_ERR	0x60
52 #define  YT921X_MIB_DATA_TX_PKT_SZ_64		0x64
53 #define  YT921X_MIB_DATA_TX_PKT_SZ_65_TO_127	0x68
54 #define  YT921X_MIB_DATA_TX_PKT_SZ_128_TO_255	0x6c
55 
56 #define  YT921X_MIB_DATA_TX_PKT_SZ_256_TO_511	0x70
57 #define  YT921X_MIB_DATA_TX_PKT_SZ_512_TO_1023	0x74
58 #define  YT921X_MIB_DATA_TX_PKT_SZ_1024_TO_1518	0x78
59 #define  YT921X_MIB_DATA_TX_PKT_SZ_1519_TO_MAX	0x7c
60 
61 /* 0x80: unused */
62 #define  YT921X_MIB_DATA_TX_GOOD_BYTES		0x84
63 /* 0x88: 64 bytes */
64 #define  YT921X_MIB_DATA_TX_COLLISION		0x8c
65 
66 #define  YT921X_MIB_DATA_TX_EXCESSIVE_COLLISION	0x90
67 #define  YT921X_MIB_DATA_TX_MULTIPLE_COLLISION	0x94
68 #define  YT921X_MIB_DATA_TX_SINGLE_COLLISION	0x98
69 #define  YT921X_MIB_DATA_TX_PKT			0x9c
70 
71 #define  YT921X_MIB_DATA_TX_DEFERRED		0xa0
72 #define  YT921X_MIB_DATA_TX_LATE_COLLISION	0xa4
73 #define  YT921X_MIB_DATA_RX_OAM			0xa8
74 #define  YT921X_MIB_DATA_TX_OAM			0xac
75 
76 struct yt921x_mib_stats {
77 	u64_stats_t rx_broadcast;
78 	u64_stats_t rx_pause;
79 	u64_stats_t rx_multicast;
80 	u64_stats_t rx_crc_errors;
81 
82 	u64_stats_t rx_alignment_errors;
83 	u64_stats_t rx_undersize_errors;
84 	u64_stats_t rx_fragment_errors;
85 	u64_stats_t rx_64byte;
86 
87 	u64_stats_t rx_65_127byte;
88 	u64_stats_t rx_128_255byte;
89 	u64_stats_t rx_256_511byte;
90 	u64_stats_t rx_512_1023byte;
91 
92 	u64_stats_t rx_1024_1518byte;
93 	u64_stats_t rx_jumbo;
94 	u64_stats_t rx_good_bytes;
95 
96 	u64_stats_t rx_bad_bytes;
97 	u64_stats_t rx_oversize_errors;
98 
99 	u64_stats_t rx_dropped;
100 	u64_stats_t tx_broadcast;
101 	u64_stats_t tx_pause;
102 	u64_stats_t tx_multicast;
103 
104 	u64_stats_t tx_undersize_errors;
105 	u64_stats_t tx_64byte;
106 	u64_stats_t tx_65_127byte;
107 	u64_stats_t tx_128_255byte;
108 
109 	u64_stats_t tx_256_511byte;
110 	u64_stats_t tx_512_1023byte;
111 	u64_stats_t tx_1024_1518byte;
112 	u64_stats_t tx_jumbo;
113 
114 	u64_stats_t tx_good_bytes;
115 	u64_stats_t tx_collisions;
116 
117 	u64_stats_t tx_aborted_errors;
118 	u64_stats_t tx_multiple_collisions;
119 	u64_stats_t tx_single_collisions;
120 	u64_stats_t tx_good;
121 
122 	u64_stats_t tx_deferred;
123 	u64_stats_t tx_late_collisions;
124 	u64_stats_t rx_oam;
125 	u64_stats_t tx_oam;
126 };
127 
128 #define YT921X_MIB_STAT_NUM	(sizeof(struct yt921x_mib_stats) / sizeof(u64_stats_t))
129 
130 struct yt921x_mib {
131 	struct yt921x_port *port;
132 
133 	struct delayed_work work;
134 	struct u64_stats_sync syncp;
135 	/* writers: priv->reg_lock + syncp; readers: priv->reg_lock or syncp */
136 	struct yt921x_mib_stats stats;
137 	u64_stats_t rx_frames;
138 	u64_stats_t tx_frames;
139 	/* protected by priv->reg_lock */
140 	u64 data[YT921X_MIB_STAT_NUM];
141 };
142 
143 void yt921x_mib_poll(struct work_struct *work);
144 void
145 yt921x_dsa_get_strings(struct dsa_switch *ds, int port, u32 stringset,
146 		       uint8_t *data);
147 void
148 yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
149 int yt921x_dsa_get_sset_count(struct dsa_switch *ds, int port, int sset);
150 void
151 yt921x_dsa_get_eth_mac_stats(struct dsa_switch *ds, int port,
152 			     struct ethtool_eth_mac_stats *mac_stats);
153 void
154 yt921x_dsa_get_eth_ctrl_stats(struct dsa_switch *ds, int port,
155 			      struct ethtool_eth_ctrl_stats *ctrl_stats);
156 void
157 yt921x_dsa_get_rmon_stats(struct dsa_switch *ds, int port,
158 			  struct ethtool_rmon_stats *rmon_stats,
159 			  const struct ethtool_rmon_hist_range **ranges);
160 void
161 yt921x_dsa_get_stats64(struct dsa_switch *ds, int port,
162 		       struct rtnl_link_stats64 *stats);
163 void
164 yt921x_dsa_get_pause_stats(struct dsa_switch *ds, int port,
165 			   struct ethtool_pause_stats *pause_stats);
166 
167 #endif
168