xref: /openbmc/linux/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1af4b1102SSteen Hegelund // SPDX-License-Identifier: GPL-2.0+
2af4b1102SSteen Hegelund /* Microchip Sparx5 Switch driver
3af4b1102SSteen Hegelund  *
4af4b1102SSteen Hegelund  * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries.
5af4b1102SSteen Hegelund  */
6af4b1102SSteen Hegelund 
7af4b1102SSteen Hegelund #include <linux/ethtool.h>
8af4b1102SSteen Hegelund 
9af4b1102SSteen Hegelund #include "sparx5_main_regs.h"
10af4b1102SSteen Hegelund #include "sparx5_main.h"
11af4b1102SSteen Hegelund #include "sparx5_port.h"
12af4b1102SSteen Hegelund 
13af4b1102SSteen Hegelund /* Index of ANA_AC port counters */
14af4b1102SSteen Hegelund #define SPX5_PORT_POLICER_DROPS 0
15af4b1102SSteen Hegelund 
16af4b1102SSteen Hegelund /* Add a potentially wrapping 32 bit value to a 64 bit counter */
sparx5_update_counter(u64 * cnt,u32 val)17af4b1102SSteen Hegelund static void sparx5_update_counter(u64 *cnt, u32 val)
18af4b1102SSteen Hegelund {
19af4b1102SSteen Hegelund 	if (val < (*cnt & U32_MAX))
20af4b1102SSteen Hegelund 		*cnt += (u64)1 << 32; /* value has wrapped */
21af4b1102SSteen Hegelund 	*cnt = (*cnt & ~(u64)U32_MAX) + val;
22af4b1102SSteen Hegelund }
23af4b1102SSteen Hegelund 
24af4b1102SSteen Hegelund enum sparx5_stats_entry {
25af4b1102SSteen Hegelund 	spx5_stats_rx_symbol_err_cnt = 0,
26af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_symbol_err_cnt = 1,
27af4b1102SSteen Hegelund 	spx5_stats_tx_uc_cnt = 2,
28af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_uc_cnt = 3,
29af4b1102SSteen Hegelund 	spx5_stats_tx_mc_cnt = 4,
30af4b1102SSteen Hegelund 	spx5_stats_tx_bc_cnt = 5,
31af4b1102SSteen Hegelund 	spx5_stats_tx_backoff1_cnt = 6,
32af4b1102SSteen Hegelund 	spx5_stats_tx_multi_coll_cnt = 7,
33af4b1102SSteen Hegelund 	spx5_stats_rx_uc_cnt = 8,
34af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_uc_cnt = 9,
35af4b1102SSteen Hegelund 	spx5_stats_rx_mc_cnt = 10,
36af4b1102SSteen Hegelund 	spx5_stats_rx_bc_cnt = 11,
37af4b1102SSteen Hegelund 	spx5_stats_rx_crc_err_cnt = 12,
38af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_crc_err_cnt = 13,
39af4b1102SSteen Hegelund 	spx5_stats_rx_alignment_lost_cnt = 14,
40af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_alignment_lost_cnt = 15,
41af4b1102SSteen Hegelund 	spx5_stats_tx_ok_bytes_cnt = 16,
42af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_ok_bytes_cnt = 17,
43af4b1102SSteen Hegelund 	spx5_stats_tx_defer_cnt = 18,
44af4b1102SSteen Hegelund 	spx5_stats_tx_late_coll_cnt = 19,
45af4b1102SSteen Hegelund 	spx5_stats_tx_xcoll_cnt = 20,
46af4b1102SSteen Hegelund 	spx5_stats_tx_csense_cnt = 21,
47af4b1102SSteen Hegelund 	spx5_stats_rx_ok_bytes_cnt = 22,
48af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_ok_bytes_cnt = 23,
49af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_mc_cnt = 24,
50af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_bc_cnt = 25,
51af4b1102SSteen Hegelund 	spx5_stats_tx_xdefer_cnt = 26,
52af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_mc_cnt = 27,
53af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_bc_cnt = 28,
54af4b1102SSteen Hegelund 	spx5_stats_rx_in_range_len_err_cnt = 29,
55af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_in_range_len_err_cnt = 30,
56af4b1102SSteen Hegelund 	spx5_stats_rx_out_of_range_len_err_cnt = 31,
57af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_out_of_range_len_err_cnt = 32,
58af4b1102SSteen Hegelund 	spx5_stats_rx_oversize_cnt = 33,
59af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_oversize_cnt = 34,
60af4b1102SSteen Hegelund 	spx5_stats_tx_pause_cnt = 35,
61af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_pause_cnt = 36,
62af4b1102SSteen Hegelund 	spx5_stats_rx_pause_cnt = 37,
63af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_pause_cnt = 38,
64af4b1102SSteen Hegelund 	spx5_stats_rx_unsup_opcode_cnt = 39,
65af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_unsup_opcode_cnt = 40,
66af4b1102SSteen Hegelund 	spx5_stats_rx_undersize_cnt = 41,
67af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_undersize_cnt = 42,
68af4b1102SSteen Hegelund 	spx5_stats_rx_fragments_cnt = 43,
69af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_fragments_cnt = 44,
70af4b1102SSteen Hegelund 	spx5_stats_rx_jabbers_cnt = 45,
71af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_jabbers_cnt = 46,
72af4b1102SSteen Hegelund 	spx5_stats_rx_size64_cnt = 47,
73af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size64_cnt = 48,
74af4b1102SSteen Hegelund 	spx5_stats_rx_size65to127_cnt = 49,
75af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size65to127_cnt = 50,
76af4b1102SSteen Hegelund 	spx5_stats_rx_size128to255_cnt = 51,
77af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size128to255_cnt = 52,
78af4b1102SSteen Hegelund 	spx5_stats_rx_size256to511_cnt = 53,
79af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size256to511_cnt = 54,
80af4b1102SSteen Hegelund 	spx5_stats_rx_size512to1023_cnt = 55,
81af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size512to1023_cnt = 56,
82af4b1102SSteen Hegelund 	spx5_stats_rx_size1024to1518_cnt = 57,
83af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size1024to1518_cnt = 58,
84af4b1102SSteen Hegelund 	spx5_stats_rx_size1519tomax_cnt = 59,
85af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_size1519tomax_cnt = 60,
86af4b1102SSteen Hegelund 	spx5_stats_tx_size64_cnt = 61,
87af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size64_cnt = 62,
88af4b1102SSteen Hegelund 	spx5_stats_tx_size65to127_cnt = 63,
89af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size65to127_cnt = 64,
90af4b1102SSteen Hegelund 	spx5_stats_tx_size128to255_cnt = 65,
91af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size128to255_cnt = 66,
92af4b1102SSteen Hegelund 	spx5_stats_tx_size256to511_cnt = 67,
93af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size256to511_cnt = 68,
94af4b1102SSteen Hegelund 	spx5_stats_tx_size512to1023_cnt = 69,
95af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size512to1023_cnt = 70,
96af4b1102SSteen Hegelund 	spx5_stats_tx_size1024to1518_cnt = 71,
97af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size1024to1518_cnt = 72,
98af4b1102SSteen Hegelund 	spx5_stats_tx_size1519tomax_cnt = 73,
99af4b1102SSteen Hegelund 	spx5_stats_pmac_tx_size1519tomax_cnt = 74,
100af4b1102SSteen Hegelund 	spx5_stats_mm_rx_assembly_err_cnt = 75,
101af4b1102SSteen Hegelund 	spx5_stats_mm_rx_assembly_ok_cnt = 76,
102af4b1102SSteen Hegelund 	spx5_stats_mm_rx_merge_frag_cnt = 77,
103af4b1102SSteen Hegelund 	spx5_stats_mm_rx_smd_err_cnt = 78,
104af4b1102SSteen Hegelund 	spx5_stats_mm_tx_pfragment_cnt = 79,
105af4b1102SSteen Hegelund 	spx5_stats_rx_bad_bytes_cnt = 80,
106af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_bad_bytes_cnt = 81,
107af4b1102SSteen Hegelund 	spx5_stats_rx_in_bytes_cnt = 82,
108af4b1102SSteen Hegelund 	spx5_stats_rx_ipg_shrink_cnt = 83,
109af4b1102SSteen Hegelund 	spx5_stats_rx_sync_lost_err_cnt = 84,
110af4b1102SSteen Hegelund 	spx5_stats_rx_tagged_frms_cnt = 85,
111af4b1102SSteen Hegelund 	spx5_stats_rx_untagged_frms_cnt = 86,
112af4b1102SSteen Hegelund 	spx5_stats_tx_out_bytes_cnt = 87,
113af4b1102SSteen Hegelund 	spx5_stats_tx_tagged_frms_cnt = 88,
114af4b1102SSteen Hegelund 	spx5_stats_tx_untagged_frms_cnt = 89,
115af4b1102SSteen Hegelund 	spx5_stats_rx_hih_cksm_err_cnt = 90,
116af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_hih_cksm_err_cnt = 91,
117af4b1102SSteen Hegelund 	spx5_stats_rx_xgmii_prot_err_cnt = 92,
118af4b1102SSteen Hegelund 	spx5_stats_pmac_rx_xgmii_prot_err_cnt = 93,
119af4b1102SSteen Hegelund 	spx5_stats_ana_ac_port_stat_lsb_cnt = 94,
120af4b1102SSteen Hegelund 	spx5_stats_green_p0_rx_fwd = 95,
121af4b1102SSteen Hegelund 	spx5_stats_green_p0_rx_port_drop = 111,
122af4b1102SSteen Hegelund 	spx5_stats_green_p0_tx_port = 127,
123af4b1102SSteen Hegelund 	spx5_stats_rx_local_drop = 143,
124af4b1102SSteen Hegelund 	spx5_stats_tx_local_drop = 144,
125af4b1102SSteen Hegelund 	spx5_stats_count = 145,
126af4b1102SSteen Hegelund };
127af4b1102SSteen Hegelund 
128af4b1102SSteen Hegelund static const char *const sparx5_stats_layout[] = {
129af4b1102SSteen Hegelund 	"mm_rx_assembly_err_cnt",
130af4b1102SSteen Hegelund 	"mm_rx_assembly_ok_cnt",
131af4b1102SSteen Hegelund 	"mm_rx_merge_frag_cnt",
132af4b1102SSteen Hegelund 	"mm_rx_smd_err_cnt",
133af4b1102SSteen Hegelund 	"mm_tx_pfragment_cnt",
134af4b1102SSteen Hegelund 	"rx_bad_bytes_cnt",
135af4b1102SSteen Hegelund 	"pmac_rx_bad_bytes_cnt",
136af4b1102SSteen Hegelund 	"rx_in_bytes_cnt",
137af4b1102SSteen Hegelund 	"rx_ipg_shrink_cnt",
138af4b1102SSteen Hegelund 	"rx_sync_lost_err_cnt",
139af4b1102SSteen Hegelund 	"rx_tagged_frms_cnt",
140af4b1102SSteen Hegelund 	"rx_untagged_frms_cnt",
141af4b1102SSteen Hegelund 	"tx_out_bytes_cnt",
142af4b1102SSteen Hegelund 	"tx_tagged_frms_cnt",
143af4b1102SSteen Hegelund 	"tx_untagged_frms_cnt",
144af4b1102SSteen Hegelund 	"rx_hih_cksm_err_cnt",
145af4b1102SSteen Hegelund 	"pmac_rx_hih_cksm_err_cnt",
146af4b1102SSteen Hegelund 	"rx_xgmii_prot_err_cnt",
147af4b1102SSteen Hegelund 	"pmac_rx_xgmii_prot_err_cnt",
148af4b1102SSteen Hegelund 	"rx_port_policer_drop",
149af4b1102SSteen Hegelund 	"rx_fwd_green_p0",
150af4b1102SSteen Hegelund 	"rx_fwd_green_p1",
151af4b1102SSteen Hegelund 	"rx_fwd_green_p2",
152af4b1102SSteen Hegelund 	"rx_fwd_green_p3",
153af4b1102SSteen Hegelund 	"rx_fwd_green_p4",
154af4b1102SSteen Hegelund 	"rx_fwd_green_p5",
155af4b1102SSteen Hegelund 	"rx_fwd_green_p6",
156af4b1102SSteen Hegelund 	"rx_fwd_green_p7",
157af4b1102SSteen Hegelund 	"rx_fwd_yellow_p0",
158af4b1102SSteen Hegelund 	"rx_fwd_yellow_p1",
159af4b1102SSteen Hegelund 	"rx_fwd_yellow_p2",
160af4b1102SSteen Hegelund 	"rx_fwd_yellow_p3",
161af4b1102SSteen Hegelund 	"rx_fwd_yellow_p4",
162af4b1102SSteen Hegelund 	"rx_fwd_yellow_p5",
163af4b1102SSteen Hegelund 	"rx_fwd_yellow_p6",
164af4b1102SSteen Hegelund 	"rx_fwd_yellow_p7",
165af4b1102SSteen Hegelund 	"rx_port_drop_green_p0",
166af4b1102SSteen Hegelund 	"rx_port_drop_green_p1",
167af4b1102SSteen Hegelund 	"rx_port_drop_green_p2",
168af4b1102SSteen Hegelund 	"rx_port_drop_green_p3",
169af4b1102SSteen Hegelund 	"rx_port_drop_green_p4",
170af4b1102SSteen Hegelund 	"rx_port_drop_green_p5",
171af4b1102SSteen Hegelund 	"rx_port_drop_green_p6",
172af4b1102SSteen Hegelund 	"rx_port_drop_green_p7",
173af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p0",
174af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p1",
175af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p2",
176af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p3",
177af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p4",
178af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p5",
179af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p6",
180af4b1102SSteen Hegelund 	"rx_port_drop_yellow_p7",
181af4b1102SSteen Hegelund 	"tx_port_green_p0",
182af4b1102SSteen Hegelund 	"tx_port_green_p1",
183af4b1102SSteen Hegelund 	"tx_port_green_p2",
184af4b1102SSteen Hegelund 	"tx_port_green_p3",
185af4b1102SSteen Hegelund 	"tx_port_green_p4",
186af4b1102SSteen Hegelund 	"tx_port_green_p5",
187af4b1102SSteen Hegelund 	"tx_port_green_p6",
188af4b1102SSteen Hegelund 	"tx_port_green_p7",
189af4b1102SSteen Hegelund 	"tx_port_yellow_p0",
190af4b1102SSteen Hegelund 	"tx_port_yellow_p1",
191af4b1102SSteen Hegelund 	"tx_port_yellow_p2",
192af4b1102SSteen Hegelund 	"tx_port_yellow_p3",
193af4b1102SSteen Hegelund 	"tx_port_yellow_p4",
194af4b1102SSteen Hegelund 	"tx_port_yellow_p5",
195af4b1102SSteen Hegelund 	"tx_port_yellow_p6",
196af4b1102SSteen Hegelund 	"tx_port_yellow_p7",
197af4b1102SSteen Hegelund 	"rx_local_drop",
198af4b1102SSteen Hegelund 	"tx_local_drop",
199af4b1102SSteen Hegelund };
200af4b1102SSteen Hegelund 
sparx5_get_queue_sys_stats(struct sparx5 * sparx5,int portno)201af4b1102SSteen Hegelund static void sparx5_get_queue_sys_stats(struct sparx5 *sparx5, int portno)
202af4b1102SSteen Hegelund {
203af4b1102SSteen Hegelund 	u64 *portstats;
204af4b1102SSteen Hegelund 	u64 *stats;
205af4b1102SSteen Hegelund 	u32 addr;
206af4b1102SSteen Hegelund 	int idx;
207af4b1102SSteen Hegelund 
208af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
209af4b1102SSteen Hegelund 	mutex_lock(&sparx5->queue_stats_lock);
210af4b1102SSteen Hegelund 	spx5_wr(XQS_STAT_CFG_STAT_VIEW_SET(portno), sparx5, XQS_STAT_CFG);
211af4b1102SSteen Hegelund 	addr = 0;
212af4b1102SSteen Hegelund 	stats = &portstats[spx5_stats_green_p0_rx_fwd];
213af4b1102SSteen Hegelund 	for (idx = 0; idx < 2 * SPX5_PRIOS; ++idx, ++addr, ++stats)
214af4b1102SSteen Hegelund 		sparx5_update_counter(stats, spx5_rd(sparx5, XQS_CNT(addr)));
215af4b1102SSteen Hegelund 	addr = 16;
216af4b1102SSteen Hegelund 	stats = &portstats[spx5_stats_green_p0_rx_port_drop];
217af4b1102SSteen Hegelund 	for (idx = 0; idx < 2 * SPX5_PRIOS; ++idx, ++addr, ++stats)
218af4b1102SSteen Hegelund 		sparx5_update_counter(stats, spx5_rd(sparx5, XQS_CNT(addr)));
219af4b1102SSteen Hegelund 	addr = 256;
220af4b1102SSteen Hegelund 	stats = &portstats[spx5_stats_green_p0_tx_port];
221af4b1102SSteen Hegelund 	for (idx = 0; idx < 2 * SPX5_PRIOS; ++idx, ++addr, ++stats)
222af4b1102SSteen Hegelund 		sparx5_update_counter(stats, spx5_rd(sparx5, XQS_CNT(addr)));
223af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_local_drop],
224af4b1102SSteen Hegelund 			      spx5_rd(sparx5, XQS_CNT(32)));
225af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_local_drop],
226af4b1102SSteen Hegelund 			      spx5_rd(sparx5, XQS_CNT(272)));
227af4b1102SSteen Hegelund 	mutex_unlock(&sparx5->queue_stats_lock);
228af4b1102SSteen Hegelund }
229af4b1102SSteen Hegelund 
sparx5_get_ana_ac_stats_stats(struct sparx5 * sparx5,int portno)230af4b1102SSteen Hegelund static void sparx5_get_ana_ac_stats_stats(struct sparx5 *sparx5, int portno)
231af4b1102SSteen Hegelund {
232af4b1102SSteen Hegelund 	u64 *portstats = &sparx5->stats[portno * sparx5->num_stats];
233af4b1102SSteen Hegelund 
234af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_ana_ac_port_stat_lsb_cnt],
235af4b1102SSteen Hegelund 			      spx5_rd(sparx5, ANA_AC_PORT_STAT_LSB_CNT(portno,
236af4b1102SSteen Hegelund 								       SPX5_PORT_POLICER_DROPS)));
237af4b1102SSteen Hegelund }
238af4b1102SSteen Hegelund 
sparx5_get_dev_phy_stats(u64 * portstats,void __iomem * inst,u32 tinst)239af4b1102SSteen Hegelund static void sparx5_get_dev_phy_stats(u64 *portstats, void __iomem *inst, u32
240af4b1102SSteen Hegelund 				     tinst)
241af4b1102SSteen Hegelund {
242af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_symbol_err_cnt],
243af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
244af4b1102SSteen Hegelund 					   DEV5G_RX_SYMBOL_ERR_CNT(tinst)));
245af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_symbol_err_cnt],
246af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
247af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SYMBOL_ERR_CNT(tinst)));
248af4b1102SSteen Hegelund }
249af4b1102SSteen Hegelund 
sparx5_get_dev_mac_stats(u64 * portstats,void __iomem * inst,u32 tinst)250af4b1102SSteen Hegelund static void sparx5_get_dev_mac_stats(u64 *portstats, void __iomem *inst, u32
251af4b1102SSteen Hegelund 				     tinst)
252af4b1102SSteen Hegelund {
253af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_uc_cnt],
254af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_UC_CNT(tinst)));
255af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_uc_cnt],
256af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_TX_UC_CNT(tinst)));
257af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_mc_cnt],
258af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_MC_CNT(tinst)));
259af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_bc_cnt],
260af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_BC_CNT(tinst)));
261af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_uc_cnt],
262af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_UC_CNT(tinst)));
263af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_uc_cnt],
264af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_RX_UC_CNT(tinst)));
265af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_mc_cnt],
266af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_MC_CNT(tinst)));
267af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_bc_cnt],
268af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_BC_CNT(tinst)));
269af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_crc_err_cnt],
270af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_CRC_ERR_CNT(tinst)));
271af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_crc_err_cnt],
272af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
273af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_CRC_ERR_CNT(tinst)));
274af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_alignment_lost_cnt],
275af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
276af4b1102SSteen Hegelund 					   DEV5G_RX_ALIGNMENT_LOST_CNT(tinst)));
277af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_alignment_lost_cnt],
278af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
279af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_ALIGNMENT_LOST_CNT(tinst)));
280af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_ok_bytes_cnt],
281af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_OK_BYTES_CNT(tinst)));
282af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_ok_bytes_cnt],
283af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
284af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_OK_BYTES_CNT(tinst)));
285af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_ok_bytes_cnt],
286af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_OK_BYTES_CNT(tinst)));
287af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_ok_bytes_cnt],
288af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
289af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_OK_BYTES_CNT(tinst)));
290af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_mc_cnt],
291af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_TX_MC_CNT(tinst)));
292af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_bc_cnt],
293af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_TX_BC_CNT(tinst)));
294af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_mc_cnt],
295af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_RX_MC_CNT(tinst)));
296af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_bc_cnt],
297af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_PMAC_RX_BC_CNT(tinst)));
298af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_in_range_len_err_cnt],
299af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
300af4b1102SSteen Hegelund 					   DEV5G_RX_IN_RANGE_LEN_ERR_CNT(tinst)));
301af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_in_range_len_err_cnt],
302af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
303af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_IN_RANGE_LEN_ERR_CNT(tinst)));
304af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_out_of_range_len_err_cnt],
305af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
306af4b1102SSteen Hegelund 					   DEV5G_RX_OUT_OF_RANGE_LEN_ERR_CNT(tinst)));
307af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_out_of_range_len_err_cnt],
308af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
309af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_OUT_OF_RANGE_LEN_ERR_CNT(tinst)));
310af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_oversize_cnt],
311af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_OVERSIZE_CNT(tinst)));
312af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_oversize_cnt],
313af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
314af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_OVERSIZE_CNT(tinst)));
315af4b1102SSteen Hegelund }
316af4b1102SSteen Hegelund 
sparx5_get_dev_mac_ctrl_stats(u64 * portstats,void __iomem * inst,u32 tinst)317af4b1102SSteen Hegelund static void sparx5_get_dev_mac_ctrl_stats(u64 *portstats, void __iomem *inst,
318af4b1102SSteen Hegelund 					  u32 tinst)
319af4b1102SSteen Hegelund {
320af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_pause_cnt],
321af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_PAUSE_CNT(tinst)));
322af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_pause_cnt],
323af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
324af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_PAUSE_CNT(tinst)));
325af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_pause_cnt],
326af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_PAUSE_CNT(tinst)));
327af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_pause_cnt],
328af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
329af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_PAUSE_CNT(tinst)));
330af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_unsup_opcode_cnt],
331af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
332af4b1102SSteen Hegelund 					   DEV5G_RX_UNSUP_OPCODE_CNT(tinst)));
333af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_unsup_opcode_cnt],
334af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
335af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_UNSUP_OPCODE_CNT(tinst)));
336af4b1102SSteen Hegelund }
337af4b1102SSteen Hegelund 
sparx5_get_dev_rmon_stats(u64 * portstats,void __iomem * inst,u32 tinst)338af4b1102SSteen Hegelund static void sparx5_get_dev_rmon_stats(u64 *portstats, void __iomem *inst, u32
339af4b1102SSteen Hegelund 				      tinst)
340af4b1102SSteen Hegelund {
341af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_undersize_cnt],
342af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
343af4b1102SSteen Hegelund 					   DEV5G_RX_UNDERSIZE_CNT(tinst)));
344af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_undersize_cnt],
345af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
346af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_UNDERSIZE_CNT(tinst)));
347af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_oversize_cnt],
348af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_OVERSIZE_CNT(tinst)));
349af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_oversize_cnt],
350af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
351af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_OVERSIZE_CNT(tinst)));
352af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_fragments_cnt],
353af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
354af4b1102SSteen Hegelund 					   DEV5G_RX_FRAGMENTS_CNT(tinst)));
355af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_fragments_cnt],
356af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
357af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_FRAGMENTS_CNT(tinst)));
358af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_jabbers_cnt],
359af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_JABBERS_CNT(tinst)));
360af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_jabbers_cnt],
361af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
362af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_JABBERS_CNT(tinst)));
363af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size64_cnt],
364af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_SIZE64_CNT(tinst)));
365af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size64_cnt],
366af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
367af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE64_CNT(tinst)));
368af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size65to127_cnt],
369af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
370af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE65TO127_CNT(tinst)));
371af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size65to127_cnt],
372af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
373af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE65TO127_CNT(tinst)));
374af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size128to255_cnt],
375af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
376af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE128TO255_CNT(tinst)));
377af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size128to255_cnt],
378af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
379af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE128TO255_CNT(tinst)));
380af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size256to511_cnt],
381af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
382af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE256TO511_CNT(tinst)));
383af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size256to511_cnt],
384af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
385af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE256TO511_CNT(tinst)));
386af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size512to1023_cnt],
387af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
388af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE512TO1023_CNT(tinst)));
389af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size512to1023_cnt],
390af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
391af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE512TO1023_CNT(tinst)));
392af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size1024to1518_cnt],
393af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
394af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE1024TO1518_CNT(tinst)));
395af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size1024to1518_cnt],
396af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
397af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE1024TO1518_CNT(tinst)));
398af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size1519tomax_cnt],
399af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
400af4b1102SSteen Hegelund 					   DEV5G_RX_SIZE1519TOMAX_CNT(tinst)));
401af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size1519tomax_cnt],
402af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
403af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_SIZE1519TOMAX_CNT(tinst)));
404af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size64_cnt],
405af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_TX_SIZE64_CNT(tinst)));
406af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size64_cnt],
407af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
408af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE64_CNT(tinst)));
409af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size65to127_cnt],
410af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
411af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE65TO127_CNT(tinst)));
412af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size65to127_cnt],
413af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
414af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE65TO127_CNT(tinst)));
415af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size128to255_cnt],
416af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
417af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE128TO255_CNT(tinst)));
418af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size128to255_cnt],
419af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
420af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE128TO255_CNT(tinst)));
421af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size256to511_cnt],
422af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
423af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE256TO511_CNT(tinst)));
424af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size256to511_cnt],
425af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
426af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE256TO511_CNT(tinst)));
427af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size512to1023_cnt],
428af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
429af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE512TO1023_CNT(tinst)));
430af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size512to1023_cnt],
431af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
432af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE512TO1023_CNT(tinst)));
433af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size1024to1518_cnt],
434af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
435af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE1024TO1518_CNT(tinst)));
436af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size1024to1518_cnt],
437af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
438af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE1024TO1518_CNT(tinst)));
439af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size1519tomax_cnt],
440af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
441af4b1102SSteen Hegelund 					   DEV5G_TX_SIZE1519TOMAX_CNT(tinst)));
442af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size1519tomax_cnt],
443af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
444af4b1102SSteen Hegelund 					   DEV5G_PMAC_TX_SIZE1519TOMAX_CNT(tinst)));
445af4b1102SSteen Hegelund }
446af4b1102SSteen Hegelund 
sparx5_get_dev_misc_stats(u64 * portstats,void __iomem * inst,u32 tinst)447af4b1102SSteen Hegelund static void sparx5_get_dev_misc_stats(u64 *portstats, void __iomem *inst, u32
448af4b1102SSteen Hegelund 				      tinst)
449af4b1102SSteen Hegelund {
450af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_assembly_err_cnt],
451af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
452af4b1102SSteen Hegelund 					   DEV5G_MM_RX_ASSEMBLY_ERR_CNT(tinst)));
453af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_assembly_ok_cnt],
454af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
455af4b1102SSteen Hegelund 					   DEV5G_MM_RX_ASSEMBLY_OK_CNT(tinst)));
456af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_merge_frag_cnt],
457af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
458af4b1102SSteen Hegelund 					   DEV5G_MM_RX_MERGE_FRAG_CNT(tinst)));
459af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_smd_err_cnt],
460af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
461af4b1102SSteen Hegelund 					   DEV5G_MM_RX_SMD_ERR_CNT(tinst)));
462af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_tx_pfragment_cnt],
463af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
464af4b1102SSteen Hegelund 					   DEV5G_MM_TX_PFRAGMENT_CNT(tinst)));
465af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_bad_bytes_cnt],
466af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
467af4b1102SSteen Hegelund 					   DEV5G_RX_BAD_BYTES_CNT(tinst)));
468af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_bad_bytes_cnt],
469af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
470af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_BAD_BYTES_CNT(tinst)));
471af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_in_bytes_cnt],
472af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, DEV5G_RX_IN_BYTES_CNT(tinst)));
473af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_ipg_shrink_cnt],
474af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
475af4b1102SSteen Hegelund 					   DEV5G_RX_IPG_SHRINK_CNT(tinst)));
476af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_tagged_frms_cnt],
477af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
478af4b1102SSteen Hegelund 					   DEV5G_RX_TAGGED_FRMS_CNT(tinst)));
479af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_untagged_frms_cnt],
480af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
481af4b1102SSteen Hegelund 					   DEV5G_RX_UNTAGGED_FRMS_CNT(tinst)));
482af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_out_bytes_cnt],
483af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
484af4b1102SSteen Hegelund 					   DEV5G_TX_OUT_BYTES_CNT(tinst)));
485af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_tagged_frms_cnt],
486af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
487af4b1102SSteen Hegelund 					   DEV5G_TX_TAGGED_FRMS_CNT(tinst)));
488af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_untagged_frms_cnt],
489af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
490af4b1102SSteen Hegelund 					   DEV5G_TX_UNTAGGED_FRMS_CNT(tinst)));
491af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_hih_cksm_err_cnt],
492af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
493af4b1102SSteen Hegelund 					   DEV5G_RX_HIH_CKSM_ERR_CNT(tinst)));
494af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_hih_cksm_err_cnt],
495af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
496af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_HIH_CKSM_ERR_CNT(tinst)));
497af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_xgmii_prot_err_cnt],
498af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
499af4b1102SSteen Hegelund 					   DEV5G_RX_XGMII_PROT_ERR_CNT(tinst)));
500af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_xgmii_prot_err_cnt],
501af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
502af4b1102SSteen Hegelund 					   DEV5G_PMAC_RX_XGMII_PROT_ERR_CNT(tinst)));
503af4b1102SSteen Hegelund }
504af4b1102SSteen Hegelund 
sparx5_get_device_stats(struct sparx5 * sparx5,int portno)505af4b1102SSteen Hegelund static void sparx5_get_device_stats(struct sparx5 *sparx5, int portno)
506af4b1102SSteen Hegelund {
507af4b1102SSteen Hegelund 	u64 *portstats = &sparx5->stats[portno * sparx5->num_stats];
508af4b1102SSteen Hegelund 	u32 tinst = sparx5_port_dev_index(portno);
509af4b1102SSteen Hegelund 	u32 dev = sparx5_to_high_dev(portno);
510af4b1102SSteen Hegelund 	void __iomem *inst;
511af4b1102SSteen Hegelund 
512af4b1102SSteen Hegelund 	inst = spx5_inst_get(sparx5, dev, tinst);
513af4b1102SSteen Hegelund 	sparx5_get_dev_phy_stats(portstats, inst, tinst);
514af4b1102SSteen Hegelund 	sparx5_get_dev_mac_stats(portstats, inst, tinst);
515af4b1102SSteen Hegelund 	sparx5_get_dev_mac_ctrl_stats(portstats, inst, tinst);
516af4b1102SSteen Hegelund 	sparx5_get_dev_rmon_stats(portstats, inst, tinst);
517af4b1102SSteen Hegelund 	sparx5_get_dev_misc_stats(portstats, inst, tinst);
518af4b1102SSteen Hegelund }
519af4b1102SSteen Hegelund 
sparx5_get_asm_phy_stats(u64 * portstats,void __iomem * inst,int portno)520af4b1102SSteen Hegelund static void sparx5_get_asm_phy_stats(u64 *portstats, void __iomem *inst, int
521af4b1102SSteen Hegelund 				     portno)
522af4b1102SSteen Hegelund {
523af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_symbol_err_cnt],
524af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
525af4b1102SSteen Hegelund 					   ASM_RX_SYMBOL_ERR_CNT(portno)));
526af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_symbol_err_cnt],
527af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
528af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SYMBOL_ERR_CNT(portno)));
529af4b1102SSteen Hegelund }
530af4b1102SSteen Hegelund 
sparx5_get_asm_mac_stats(u64 * portstats,void __iomem * inst,int portno)531af4b1102SSteen Hegelund static void sparx5_get_asm_mac_stats(u64 *portstats, void __iomem *inst, int
532af4b1102SSteen Hegelund 				     portno)
533af4b1102SSteen Hegelund {
534af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_uc_cnt],
535af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_UC_CNT(portno)));
536af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_uc_cnt],
537af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_TX_UC_CNT(portno)));
538af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_mc_cnt],
539af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_MC_CNT(portno)));
540af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_bc_cnt],
541af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_BC_CNT(portno)));
542af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_backoff1_cnt],
543af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_BACKOFF1_CNT(portno)));
544af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_multi_coll_cnt],
545af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
546af4b1102SSteen Hegelund 					   ASM_TX_MULTI_COLL_CNT(portno)));
547af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_uc_cnt],
548af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_UC_CNT(portno)));
549af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_uc_cnt],
550af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_RX_UC_CNT(portno)));
551af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_mc_cnt],
552af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_MC_CNT(portno)));
553af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_bc_cnt],
554af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_BC_CNT(portno)));
555af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_crc_err_cnt],
556af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_CRC_ERR_CNT(portno)));
557af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_crc_err_cnt],
558af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
559af4b1102SSteen Hegelund 					   ASM_PMAC_RX_CRC_ERR_CNT(portno)));
560af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_alignment_lost_cnt],
561af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
562af4b1102SSteen Hegelund 					   ASM_RX_ALIGNMENT_LOST_CNT(portno)));
563af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_alignment_lost_cnt],
564af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
565af4b1102SSteen Hegelund 					   ASM_PMAC_RX_ALIGNMENT_LOST_CNT(portno)));
566af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_ok_bytes_cnt],
567af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_OK_BYTES_CNT(portno)));
568af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_ok_bytes_cnt],
569af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
570af4b1102SSteen Hegelund 					   ASM_PMAC_TX_OK_BYTES_CNT(portno)));
571af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_defer_cnt],
572af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_DEFER_CNT(portno)));
573af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_late_coll_cnt],
574af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_LATE_COLL_CNT(portno)));
575af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_xcoll_cnt],
576af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_XCOLL_CNT(portno)));
577af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_csense_cnt],
578af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_CSENSE_CNT(portno)));
579af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_ok_bytes_cnt],
580af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_OK_BYTES_CNT(portno)));
581af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_ok_bytes_cnt],
582af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
583af4b1102SSteen Hegelund 					   ASM_PMAC_RX_OK_BYTES_CNT(portno)));
584af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_mc_cnt],
585af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_TX_MC_CNT(portno)));
586af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_bc_cnt],
587af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_TX_BC_CNT(portno)));
588af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_xdefer_cnt],
589af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_XDEFER_CNT(portno)));
590af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_mc_cnt],
591af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_RX_MC_CNT(portno)));
592af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_bc_cnt],
593af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_PMAC_RX_BC_CNT(portno)));
594af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_in_range_len_err_cnt],
595af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
596af4b1102SSteen Hegelund 					   ASM_RX_IN_RANGE_LEN_ERR_CNT(portno)));
597af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_in_range_len_err_cnt],
598af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
599af4b1102SSteen Hegelund 					   ASM_PMAC_RX_IN_RANGE_LEN_ERR_CNT(portno)));
600af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_out_of_range_len_err_cnt],
601af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
602af4b1102SSteen Hegelund 					   ASM_RX_OUT_OF_RANGE_LEN_ERR_CNT(portno)));
603af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_out_of_range_len_err_cnt],
604af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
605af4b1102SSteen Hegelund 					   ASM_PMAC_RX_OUT_OF_RANGE_LEN_ERR_CNT(portno)));
606af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_oversize_cnt],
607af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_OVERSIZE_CNT(portno)));
608af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_oversize_cnt],
609af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
610af4b1102SSteen Hegelund 					   ASM_PMAC_RX_OVERSIZE_CNT(portno)));
611af4b1102SSteen Hegelund }
612af4b1102SSteen Hegelund 
sparx5_get_asm_mac_ctrl_stats(u64 * portstats,void __iomem * inst,int portno)613af4b1102SSteen Hegelund static void sparx5_get_asm_mac_ctrl_stats(u64 *portstats, void __iomem *inst,
614af4b1102SSteen Hegelund 					  int portno)
615af4b1102SSteen Hegelund {
616af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_pause_cnt],
617af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_PAUSE_CNT(portno)));
618af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_pause_cnt],
619af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
620af4b1102SSteen Hegelund 					   ASM_PMAC_TX_PAUSE_CNT(portno)));
621af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_pause_cnt],
622af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_PAUSE_CNT(portno)));
623af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_pause_cnt],
624af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
625af4b1102SSteen Hegelund 					   ASM_PMAC_RX_PAUSE_CNT(portno)));
626af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_unsup_opcode_cnt],
627af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
628af4b1102SSteen Hegelund 					   ASM_RX_UNSUP_OPCODE_CNT(portno)));
629af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_unsup_opcode_cnt],
630af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
631af4b1102SSteen Hegelund 					   ASM_PMAC_RX_UNSUP_OPCODE_CNT(portno)));
632af4b1102SSteen Hegelund }
633af4b1102SSteen Hegelund 
sparx5_get_asm_rmon_stats(u64 * portstats,void __iomem * inst,int portno)634af4b1102SSteen Hegelund static void sparx5_get_asm_rmon_stats(u64 *portstats, void __iomem *inst, int
635af4b1102SSteen Hegelund 				      portno)
636af4b1102SSteen Hegelund {
637af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_undersize_cnt],
638af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_UNDERSIZE_CNT(portno)));
639af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_undersize_cnt],
640af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
641af4b1102SSteen Hegelund 					   ASM_PMAC_RX_UNDERSIZE_CNT(portno)));
642af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_oversize_cnt],
643af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_OVERSIZE_CNT(portno)));
644af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_oversize_cnt],
645af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
646af4b1102SSteen Hegelund 					   ASM_PMAC_RX_OVERSIZE_CNT(portno)));
647af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_fragments_cnt],
648af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_FRAGMENTS_CNT(portno)));
649af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_fragments_cnt],
650af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
651af4b1102SSteen Hegelund 					   ASM_PMAC_RX_FRAGMENTS_CNT(portno)));
652af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_jabbers_cnt],
653af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_JABBERS_CNT(portno)));
654af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_jabbers_cnt],
655af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
656af4b1102SSteen Hegelund 					   ASM_PMAC_RX_JABBERS_CNT(portno)));
657af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size64_cnt],
658af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_SIZE64_CNT(portno)));
659af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size64_cnt],
660af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
661af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE64_CNT(portno)));
662af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size65to127_cnt],
663af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
664af4b1102SSteen Hegelund 					   ASM_RX_SIZE65TO127_CNT(portno)));
665af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size65to127_cnt],
666af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
667af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE65TO127_CNT(portno)));
668af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size128to255_cnt],
669af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
670af4b1102SSteen Hegelund 					   ASM_RX_SIZE128TO255_CNT(portno)));
671af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size128to255_cnt],
672af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
673af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE128TO255_CNT(portno)));
674af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size256to511_cnt],
675af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
676af4b1102SSteen Hegelund 					   ASM_RX_SIZE256TO511_CNT(portno)));
677af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size256to511_cnt],
678af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
679af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE256TO511_CNT(portno)));
680af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size512to1023_cnt],
681af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
682af4b1102SSteen Hegelund 					   ASM_RX_SIZE512TO1023_CNT(portno)));
683af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size512to1023_cnt],
684af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
685af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE512TO1023_CNT(portno)));
686af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size1024to1518_cnt],
687af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
688af4b1102SSteen Hegelund 					   ASM_RX_SIZE1024TO1518_CNT(portno)));
689af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size1024to1518_cnt],
690af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
691af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE1024TO1518_CNT(portno)));
692af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_size1519tomax_cnt],
693af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
694af4b1102SSteen Hegelund 					   ASM_RX_SIZE1519TOMAX_CNT(portno)));
695af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_size1519tomax_cnt],
696af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
697af4b1102SSteen Hegelund 					   ASM_PMAC_RX_SIZE1519TOMAX_CNT(portno)));
698af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size64_cnt],
699af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_SIZE64_CNT(portno)));
700af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size64_cnt],
701af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
702af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE64_CNT(portno)));
703af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size65to127_cnt],
704af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
705af4b1102SSteen Hegelund 					   ASM_TX_SIZE65TO127_CNT(portno)));
706af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size65to127_cnt],
707af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
708af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE65TO127_CNT(portno)));
709af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size128to255_cnt],
710af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
711af4b1102SSteen Hegelund 					   ASM_TX_SIZE128TO255_CNT(portno)));
712af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size128to255_cnt],
713af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
714af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE128TO255_CNT(portno)));
715af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size256to511_cnt],
716af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
717af4b1102SSteen Hegelund 					   ASM_TX_SIZE256TO511_CNT(portno)));
718af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size256to511_cnt],
719af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
720af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE256TO511_CNT(portno)));
721af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size512to1023_cnt],
722af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
723af4b1102SSteen Hegelund 					   ASM_TX_SIZE512TO1023_CNT(portno)));
724af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size512to1023_cnt],
725af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
726af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE512TO1023_CNT(portno)));
727af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size1024to1518_cnt],
728af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
729af4b1102SSteen Hegelund 					   ASM_TX_SIZE1024TO1518_CNT(portno)));
730af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size1024to1518_cnt],
731af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
732af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE1024TO1518_CNT(portno)));
733af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_size1519tomax_cnt],
734af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
735af4b1102SSteen Hegelund 					   ASM_TX_SIZE1519TOMAX_CNT(portno)));
736af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_tx_size1519tomax_cnt],
737af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
738af4b1102SSteen Hegelund 					   ASM_PMAC_TX_SIZE1519TOMAX_CNT(portno)));
739af4b1102SSteen Hegelund }
740af4b1102SSteen Hegelund 
sparx5_get_asm_misc_stats(u64 * portstats,void __iomem * inst,int portno)741af4b1102SSteen Hegelund static void sparx5_get_asm_misc_stats(u64 *portstats, void __iomem *inst, int
742af4b1102SSteen Hegelund 				      portno)
743af4b1102SSteen Hegelund {
744af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_assembly_err_cnt],
745af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
746af4b1102SSteen Hegelund 					   ASM_MM_RX_ASSEMBLY_ERR_CNT(portno)));
747af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_assembly_ok_cnt],
748af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
749af4b1102SSteen Hegelund 					   ASM_MM_RX_ASSEMBLY_OK_CNT(portno)));
750af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_merge_frag_cnt],
751af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
752af4b1102SSteen Hegelund 					   ASM_MM_RX_MERGE_FRAG_CNT(portno)));
753af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_rx_smd_err_cnt],
754af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
755af4b1102SSteen Hegelund 					   ASM_MM_RX_SMD_ERR_CNT(portno)));
756af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_mm_tx_pfragment_cnt],
757af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
758af4b1102SSteen Hegelund 					   ASM_MM_TX_PFRAGMENT_CNT(portno)));
759af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_bad_bytes_cnt],
760af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_BAD_BYTES_CNT(portno)));
761af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_pmac_rx_bad_bytes_cnt],
762af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
763af4b1102SSteen Hegelund 					   ASM_PMAC_RX_BAD_BYTES_CNT(portno)));
764af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_in_bytes_cnt],
765af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_RX_IN_BYTES_CNT(portno)));
766af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_ipg_shrink_cnt],
767af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
768af4b1102SSteen Hegelund 					   ASM_RX_IPG_SHRINK_CNT(portno)));
769af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_sync_lost_err_cnt],
770af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
771af4b1102SSteen Hegelund 					   ASM_RX_SYNC_LOST_ERR_CNT(portno)));
772af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_tagged_frms_cnt],
773af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
774af4b1102SSteen Hegelund 					   ASM_RX_TAGGED_FRMS_CNT(portno)));
775af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_rx_untagged_frms_cnt],
776af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
777af4b1102SSteen Hegelund 					   ASM_RX_UNTAGGED_FRMS_CNT(portno)));
778af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_out_bytes_cnt],
779af4b1102SSteen Hegelund 			      spx5_inst_rd(inst, ASM_TX_OUT_BYTES_CNT(portno)));
780af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_tagged_frms_cnt],
781af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
782af4b1102SSteen Hegelund 					   ASM_TX_TAGGED_FRMS_CNT(portno)));
783af4b1102SSteen Hegelund 	sparx5_update_counter(&portstats[spx5_stats_tx_untagged_frms_cnt],
784af4b1102SSteen Hegelund 			      spx5_inst_rd(inst,
785af4b1102SSteen Hegelund 					   ASM_TX_UNTAGGED_FRMS_CNT(portno)));
786af4b1102SSteen Hegelund }
787af4b1102SSteen Hegelund 
sparx5_get_asm_stats(struct sparx5 * sparx5,int portno)788af4b1102SSteen Hegelund static void sparx5_get_asm_stats(struct sparx5 *sparx5, int portno)
789af4b1102SSteen Hegelund {
790af4b1102SSteen Hegelund 	u64 *portstats = &sparx5->stats[portno * sparx5->num_stats];
791af4b1102SSteen Hegelund 	void __iomem *inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
792af4b1102SSteen Hegelund 
793af4b1102SSteen Hegelund 	sparx5_get_asm_phy_stats(portstats, inst, portno);
794af4b1102SSteen Hegelund 	sparx5_get_asm_mac_stats(portstats, inst, portno);
795af4b1102SSteen Hegelund 	sparx5_get_asm_mac_ctrl_stats(portstats, inst, portno);
796af4b1102SSteen Hegelund 	sparx5_get_asm_rmon_stats(portstats, inst, portno);
797af4b1102SSteen Hegelund 	sparx5_get_asm_misc_stats(portstats, inst, portno);
798af4b1102SSteen Hegelund }
799af4b1102SSteen Hegelund 
800af4b1102SSteen Hegelund static const struct ethtool_rmon_hist_range sparx5_rmon_ranges[] = {
801af4b1102SSteen Hegelund 	{    0,    64 },
802af4b1102SSteen Hegelund 	{   65,   127 },
803af4b1102SSteen Hegelund 	{  128,   255 },
804af4b1102SSteen Hegelund 	{  256,   511 },
805af4b1102SSteen Hegelund 	{  512,  1023 },
806af4b1102SSteen Hegelund 	{ 1024,  1518 },
807af4b1102SSteen Hegelund 	{ 1519, 10239 },
808af4b1102SSteen Hegelund 	{}
809af4b1102SSteen Hegelund };
810af4b1102SSteen Hegelund 
sparx5_get_eth_phy_stats(struct net_device * ndev,struct ethtool_eth_phy_stats * phy_stats)811af4b1102SSteen Hegelund static void sparx5_get_eth_phy_stats(struct net_device *ndev,
812af4b1102SSteen Hegelund 				     struct ethtool_eth_phy_stats *phy_stats)
813af4b1102SSteen Hegelund {
814af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
815af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
816af4b1102SSteen Hegelund 	int portno = port->portno;
817af4b1102SSteen Hegelund 	void __iomem *inst;
818af4b1102SSteen Hegelund 	u64 *portstats;
819af4b1102SSteen Hegelund 
820af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
821af4b1102SSteen Hegelund 	if (sparx5_is_baser(port->conf.portmode)) {
822af4b1102SSteen Hegelund 		u32 tinst = sparx5_port_dev_index(portno);
823af4b1102SSteen Hegelund 		u32 dev = sparx5_to_high_dev(portno);
824af4b1102SSteen Hegelund 
825af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, dev, tinst);
826af4b1102SSteen Hegelund 		sparx5_get_dev_phy_stats(portstats, inst, tinst);
827af4b1102SSteen Hegelund 	} else {
828af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
829af4b1102SSteen Hegelund 		sparx5_get_asm_phy_stats(portstats, inst, portno);
830af4b1102SSteen Hegelund 	}
831af4b1102SSteen Hegelund 	phy_stats->SymbolErrorDuringCarrier =
832af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_symbol_err_cnt] +
833af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_symbol_err_cnt];
834af4b1102SSteen Hegelund }
835af4b1102SSteen Hegelund 
sparx5_get_eth_mac_stats(struct net_device * ndev,struct ethtool_eth_mac_stats * mac_stats)836af4b1102SSteen Hegelund static void sparx5_get_eth_mac_stats(struct net_device *ndev,
837af4b1102SSteen Hegelund 				     struct ethtool_eth_mac_stats *mac_stats)
838af4b1102SSteen Hegelund {
839af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
840af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
841af4b1102SSteen Hegelund 	int portno = port->portno;
842af4b1102SSteen Hegelund 	void __iomem *inst;
843af4b1102SSteen Hegelund 	u64 *portstats;
844af4b1102SSteen Hegelund 
845af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
846af4b1102SSteen Hegelund 	if (sparx5_is_baser(port->conf.portmode)) {
847af4b1102SSteen Hegelund 		u32 tinst = sparx5_port_dev_index(portno);
848af4b1102SSteen Hegelund 		u32 dev = sparx5_to_high_dev(portno);
849af4b1102SSteen Hegelund 
850af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, dev, tinst);
851af4b1102SSteen Hegelund 		sparx5_get_dev_mac_stats(portstats, inst, tinst);
852af4b1102SSteen Hegelund 	} else {
853af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
854af4b1102SSteen Hegelund 		sparx5_get_asm_mac_stats(portstats, inst, portno);
855af4b1102SSteen Hegelund 	}
856af4b1102SSteen Hegelund 	mac_stats->FramesTransmittedOK = portstats[spx5_stats_tx_uc_cnt] +
857af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_uc_cnt] +
858af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_mc_cnt] +
859af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_bc_cnt];
860af4b1102SSteen Hegelund 	mac_stats->SingleCollisionFrames =
861af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_backoff1_cnt];
862af4b1102SSteen Hegelund 	mac_stats->MultipleCollisionFrames =
863af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_multi_coll_cnt];
864af4b1102SSteen Hegelund 	mac_stats->FramesReceivedOK = portstats[spx5_stats_rx_uc_cnt] +
865af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_uc_cnt] +
866af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_mc_cnt] +
867af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_bc_cnt];
868af4b1102SSteen Hegelund 	mac_stats->FrameCheckSequenceErrors =
869af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_crc_err_cnt] +
870af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_crc_err_cnt];
871af4b1102SSteen Hegelund 	mac_stats->AlignmentErrors = portstats[spx5_stats_rx_alignment_lost_cnt]
872af4b1102SSteen Hegelund 		+ portstats[spx5_stats_pmac_rx_alignment_lost_cnt];
873af4b1102SSteen Hegelund 	mac_stats->OctetsTransmittedOK = portstats[spx5_stats_tx_ok_bytes_cnt] +
874af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_ok_bytes_cnt];
875af4b1102SSteen Hegelund 	mac_stats->FramesWithDeferredXmissions =
876af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_defer_cnt];
877af4b1102SSteen Hegelund 	mac_stats->LateCollisions =
878af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_late_coll_cnt];
879af4b1102SSteen Hegelund 	mac_stats->FramesAbortedDueToXSColls =
880af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_xcoll_cnt];
881af4b1102SSteen Hegelund 	mac_stats->CarrierSenseErrors = portstats[spx5_stats_tx_csense_cnt];
882af4b1102SSteen Hegelund 	mac_stats->OctetsReceivedOK = portstats[spx5_stats_rx_ok_bytes_cnt] +
883af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_ok_bytes_cnt];
884af4b1102SSteen Hegelund 	mac_stats->MulticastFramesXmittedOK = portstats[spx5_stats_tx_mc_cnt] +
885af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_mc_cnt];
886af4b1102SSteen Hegelund 	mac_stats->BroadcastFramesXmittedOK = portstats[spx5_stats_tx_bc_cnt] +
887af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_bc_cnt];
888af4b1102SSteen Hegelund 	mac_stats->FramesWithExcessiveDeferral =
889af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_xdefer_cnt];
890af4b1102SSteen Hegelund 	mac_stats->MulticastFramesReceivedOK = portstats[spx5_stats_rx_mc_cnt] +
891af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_mc_cnt];
892af4b1102SSteen Hegelund 	mac_stats->BroadcastFramesReceivedOK = portstats[spx5_stats_rx_bc_cnt] +
893af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_bc_cnt];
894af4b1102SSteen Hegelund 	mac_stats->InRangeLengthErrors =
895af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_in_range_len_err_cnt] +
896af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_in_range_len_err_cnt];
897af4b1102SSteen Hegelund 	mac_stats->OutOfRangeLengthField =
898af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_out_of_range_len_err_cnt] +
899af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_out_of_range_len_err_cnt];
900af4b1102SSteen Hegelund 	mac_stats->FrameTooLongErrors = portstats[spx5_stats_rx_oversize_cnt] +
901af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_oversize_cnt];
902af4b1102SSteen Hegelund }
903af4b1102SSteen Hegelund 
sparx5_get_eth_mac_ctrl_stats(struct net_device * ndev,struct ethtool_eth_ctrl_stats * mac_ctrl_stats)904af4b1102SSteen Hegelund static void sparx5_get_eth_mac_ctrl_stats(struct net_device *ndev,
905af4b1102SSteen Hegelund 					  struct ethtool_eth_ctrl_stats *mac_ctrl_stats)
906af4b1102SSteen Hegelund {
907af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
908af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
909af4b1102SSteen Hegelund 	int portno = port->portno;
910af4b1102SSteen Hegelund 	void __iomem *inst;
911af4b1102SSteen Hegelund 	u64 *portstats;
912af4b1102SSteen Hegelund 
913af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
914af4b1102SSteen Hegelund 	if (sparx5_is_baser(port->conf.portmode)) {
915af4b1102SSteen Hegelund 		u32 tinst = sparx5_port_dev_index(portno);
916af4b1102SSteen Hegelund 		u32 dev = sparx5_to_high_dev(portno);
917af4b1102SSteen Hegelund 
918af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, dev, tinst);
919af4b1102SSteen Hegelund 		sparx5_get_dev_mac_ctrl_stats(portstats, inst, tinst);
920af4b1102SSteen Hegelund 	} else {
921af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
922af4b1102SSteen Hegelund 		sparx5_get_asm_mac_ctrl_stats(portstats, inst, portno);
923af4b1102SSteen Hegelund 	}
924af4b1102SSteen Hegelund 	mac_ctrl_stats->MACControlFramesTransmitted =
925af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_pause_cnt] +
926af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_pause_cnt];
927af4b1102SSteen Hegelund 	mac_ctrl_stats->MACControlFramesReceived =
928af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_pause_cnt] +
929af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_pause_cnt];
930af4b1102SSteen Hegelund 	mac_ctrl_stats->UnsupportedOpcodesReceived =
931af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_unsup_opcode_cnt] +
932af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_unsup_opcode_cnt];
933af4b1102SSteen Hegelund }
934af4b1102SSteen Hegelund 
sparx5_get_eth_rmon_stats(struct net_device * ndev,struct ethtool_rmon_stats * rmon_stats,const struct ethtool_rmon_hist_range ** ranges)935af4b1102SSteen Hegelund static void sparx5_get_eth_rmon_stats(struct net_device *ndev,
936af4b1102SSteen Hegelund 				      struct ethtool_rmon_stats *rmon_stats,
937af4b1102SSteen Hegelund 				      const struct ethtool_rmon_hist_range **ranges)
938af4b1102SSteen Hegelund {
939af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
940af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
941af4b1102SSteen Hegelund 	int portno = port->portno;
942af4b1102SSteen Hegelund 	void __iomem *inst;
943af4b1102SSteen Hegelund 	u64 *portstats;
944af4b1102SSteen Hegelund 
945af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
946af4b1102SSteen Hegelund 	if (sparx5_is_baser(port->conf.portmode)) {
947af4b1102SSteen Hegelund 		u32 tinst = sparx5_port_dev_index(portno);
948af4b1102SSteen Hegelund 		u32 dev = sparx5_to_high_dev(portno);
949af4b1102SSteen Hegelund 
950af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, dev, tinst);
951af4b1102SSteen Hegelund 		sparx5_get_dev_rmon_stats(portstats, inst, tinst);
952af4b1102SSteen Hegelund 	} else {
953af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
954af4b1102SSteen Hegelund 		sparx5_get_asm_rmon_stats(portstats, inst, portno);
955af4b1102SSteen Hegelund 	}
956af4b1102SSteen Hegelund 	rmon_stats->undersize_pkts = portstats[spx5_stats_rx_undersize_cnt] +
957af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_undersize_cnt];
958af4b1102SSteen Hegelund 	rmon_stats->oversize_pkts = portstats[spx5_stats_rx_oversize_cnt] +
959af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_oversize_cnt];
960af4b1102SSteen Hegelund 	rmon_stats->fragments = portstats[spx5_stats_rx_fragments_cnt] +
961af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_fragments_cnt];
962af4b1102SSteen Hegelund 	rmon_stats->jabbers = portstats[spx5_stats_rx_jabbers_cnt] +
963af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_jabbers_cnt];
964af4b1102SSteen Hegelund 	rmon_stats->hist[0] = portstats[spx5_stats_rx_size64_cnt] +
965af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size64_cnt];
966af4b1102SSteen Hegelund 	rmon_stats->hist[1] = portstats[spx5_stats_rx_size65to127_cnt] +
967af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size65to127_cnt];
968af4b1102SSteen Hegelund 	rmon_stats->hist[2] = portstats[spx5_stats_rx_size128to255_cnt] +
969af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size128to255_cnt];
970af4b1102SSteen Hegelund 	rmon_stats->hist[3] = portstats[spx5_stats_rx_size256to511_cnt] +
971af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size256to511_cnt];
972af4b1102SSteen Hegelund 	rmon_stats->hist[4] = portstats[spx5_stats_rx_size512to1023_cnt] +
973af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size512to1023_cnt];
974af4b1102SSteen Hegelund 	rmon_stats->hist[5] = portstats[spx5_stats_rx_size1024to1518_cnt] +
975af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size1024to1518_cnt];
976af4b1102SSteen Hegelund 	rmon_stats->hist[6] = portstats[spx5_stats_rx_size1519tomax_cnt] +
977af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_size1519tomax_cnt];
978af4b1102SSteen Hegelund 	rmon_stats->hist_tx[0] = portstats[spx5_stats_tx_size64_cnt] +
979af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size64_cnt];
980af4b1102SSteen Hegelund 	rmon_stats->hist_tx[1] = portstats[spx5_stats_tx_size65to127_cnt] +
981af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size65to127_cnt];
982af4b1102SSteen Hegelund 	rmon_stats->hist_tx[2] = portstats[spx5_stats_tx_size128to255_cnt] +
983af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size128to255_cnt];
984af4b1102SSteen Hegelund 	rmon_stats->hist_tx[3] = portstats[spx5_stats_tx_size256to511_cnt] +
985af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size256to511_cnt];
986af4b1102SSteen Hegelund 	rmon_stats->hist_tx[4] = portstats[spx5_stats_tx_size512to1023_cnt] +
987af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size512to1023_cnt];
988af4b1102SSteen Hegelund 	rmon_stats->hist_tx[5] = portstats[spx5_stats_tx_size1024to1518_cnt] +
989af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size1024to1518_cnt];
990af4b1102SSteen Hegelund 	rmon_stats->hist_tx[6] = portstats[spx5_stats_tx_size1519tomax_cnt] +
991af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_size1519tomax_cnt];
992af4b1102SSteen Hegelund 	*ranges = sparx5_rmon_ranges;
993af4b1102SSteen Hegelund }
994af4b1102SSteen Hegelund 
sparx5_get_sset_count(struct net_device * ndev,int sset)995af4b1102SSteen Hegelund static int sparx5_get_sset_count(struct net_device *ndev, int sset)
996af4b1102SSteen Hegelund {
997af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
998af4b1102SSteen Hegelund 	struct sparx5  *sparx5 = port->sparx5;
999af4b1102SSteen Hegelund 
1000af4b1102SSteen Hegelund 	if (sset != ETH_SS_STATS)
1001af4b1102SSteen Hegelund 		return -EOPNOTSUPP;
1002af4b1102SSteen Hegelund 	return sparx5->num_ethtool_stats;
1003af4b1102SSteen Hegelund }
1004af4b1102SSteen Hegelund 
sparx5_get_sset_strings(struct net_device * ndev,u32 sset,u8 * data)1005af4b1102SSteen Hegelund static void sparx5_get_sset_strings(struct net_device *ndev, u32 sset, u8 *data)
1006af4b1102SSteen Hegelund {
1007af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
1008af4b1102SSteen Hegelund 	struct sparx5  *sparx5 = port->sparx5;
1009af4b1102SSteen Hegelund 	int idx;
1010af4b1102SSteen Hegelund 
1011af4b1102SSteen Hegelund 	if (sset != ETH_SS_STATS)
1012af4b1102SSteen Hegelund 		return;
1013af4b1102SSteen Hegelund 
1014af4b1102SSteen Hegelund 	for (idx = 0; idx < sparx5->num_ethtool_stats; idx++)
1015af4b1102SSteen Hegelund 		strncpy(data + idx * ETH_GSTRING_LEN,
1016af4b1102SSteen Hegelund 			sparx5->stats_layout[idx], ETH_GSTRING_LEN);
1017af4b1102SSteen Hegelund }
1018af4b1102SSteen Hegelund 
sparx5_get_sset_data(struct net_device * ndev,struct ethtool_stats * stats,u64 * data)1019af4b1102SSteen Hegelund static void sparx5_get_sset_data(struct net_device *ndev,
1020af4b1102SSteen Hegelund 				 struct ethtool_stats *stats, u64 *data)
1021af4b1102SSteen Hegelund {
1022af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
1023af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
1024af4b1102SSteen Hegelund 	int portno = port->portno;
1025af4b1102SSteen Hegelund 	void __iomem *inst;
1026af4b1102SSteen Hegelund 	u64 *portstats;
1027af4b1102SSteen Hegelund 	int idx;
1028af4b1102SSteen Hegelund 
1029af4b1102SSteen Hegelund 	portstats = &sparx5->stats[portno * sparx5->num_stats];
1030af4b1102SSteen Hegelund 	if (sparx5_is_baser(port->conf.portmode)) {
1031af4b1102SSteen Hegelund 		u32 tinst = sparx5_port_dev_index(portno);
1032af4b1102SSteen Hegelund 		u32 dev = sparx5_to_high_dev(portno);
1033af4b1102SSteen Hegelund 
1034af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, dev, tinst);
1035af4b1102SSteen Hegelund 		sparx5_get_dev_misc_stats(portstats, inst, tinst);
1036af4b1102SSteen Hegelund 	} else {
1037af4b1102SSteen Hegelund 		inst = spx5_inst_get(sparx5, TARGET_ASM, 0);
1038af4b1102SSteen Hegelund 		sparx5_get_asm_misc_stats(portstats, inst, portno);
1039af4b1102SSteen Hegelund 	}
1040af4b1102SSteen Hegelund 	sparx5_get_ana_ac_stats_stats(sparx5, portno);
1041af4b1102SSteen Hegelund 	sparx5_get_queue_sys_stats(sparx5, portno);
1042af4b1102SSteen Hegelund 	/* Copy port counters to the ethtool buffer */
1043af4b1102SSteen Hegelund 	for (idx = spx5_stats_mm_rx_assembly_err_cnt;
1044af4b1102SSteen Hegelund 	     idx < spx5_stats_mm_rx_assembly_err_cnt +
1045af4b1102SSteen Hegelund 	     sparx5->num_ethtool_stats; idx++)
1046af4b1102SSteen Hegelund 		*data++ = portstats[idx];
1047af4b1102SSteen Hegelund }
1048af4b1102SSteen Hegelund 
sparx5_get_stats64(struct net_device * ndev,struct rtnl_link_stats64 * stats)1049af4b1102SSteen Hegelund void sparx5_get_stats64(struct net_device *ndev,
1050af4b1102SSteen Hegelund 			struct rtnl_link_stats64 *stats)
1051af4b1102SSteen Hegelund {
1052af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
1053af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = port->sparx5;
1054af4b1102SSteen Hegelund 	u64 *portstats;
1055af4b1102SSteen Hegelund 	int idx;
1056af4b1102SSteen Hegelund 
1057af4b1102SSteen Hegelund 	if (!sparx5->stats)
1058af4b1102SSteen Hegelund 		return; /* Not initialized yet */
1059af4b1102SSteen Hegelund 
1060af4b1102SSteen Hegelund 	portstats = &sparx5->stats[port->portno * sparx5->num_stats];
1061af4b1102SSteen Hegelund 
1062af4b1102SSteen Hegelund 	stats->rx_packets = portstats[spx5_stats_rx_uc_cnt] +
1063af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_uc_cnt] +
1064af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_mc_cnt] +
1065af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_bc_cnt];
1066af4b1102SSteen Hegelund 	stats->tx_packets = portstats[spx5_stats_tx_uc_cnt] +
1067af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_uc_cnt] +
1068af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_mc_cnt] +
1069af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_bc_cnt];
1070af4b1102SSteen Hegelund 	stats->rx_bytes = portstats[spx5_stats_rx_ok_bytes_cnt] +
1071af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_ok_bytes_cnt];
1072af4b1102SSteen Hegelund 	stats->tx_bytes = portstats[spx5_stats_tx_ok_bytes_cnt] +
1073af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_tx_ok_bytes_cnt];
1074af4b1102SSteen Hegelund 	stats->rx_errors = portstats[spx5_stats_rx_in_range_len_err_cnt] +
1075af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_in_range_len_err_cnt] +
1076af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_out_of_range_len_err_cnt] +
1077af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_out_of_range_len_err_cnt] +
1078af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_oversize_cnt] +
1079af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_oversize_cnt] +
1080af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_crc_err_cnt] +
1081af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_crc_err_cnt] +
1082af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_alignment_lost_cnt] +
1083af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_alignment_lost_cnt];
1084af4b1102SSteen Hegelund 	stats->tx_errors = portstats[spx5_stats_tx_xcoll_cnt] +
1085af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_csense_cnt] +
1086af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_late_coll_cnt];
1087af4b1102SSteen Hegelund 	stats->multicast = portstats[spx5_stats_rx_mc_cnt] +
1088af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_mc_cnt];
1089af4b1102SSteen Hegelund 	stats->collisions = portstats[spx5_stats_tx_late_coll_cnt] +
1090af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_xcoll_cnt] +
1091af4b1102SSteen Hegelund 		portstats[spx5_stats_tx_backoff1_cnt];
1092af4b1102SSteen Hegelund 	stats->rx_length_errors = portstats[spx5_stats_rx_in_range_len_err_cnt] +
1093af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_in_range_len_err_cnt] +
1094af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_out_of_range_len_err_cnt] +
1095af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_out_of_range_len_err_cnt] +
1096af4b1102SSteen Hegelund 		portstats[spx5_stats_rx_oversize_cnt] +
1097af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_oversize_cnt];
1098af4b1102SSteen Hegelund 	stats->rx_crc_errors = portstats[spx5_stats_rx_crc_err_cnt] +
1099af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_crc_err_cnt];
1100af4b1102SSteen Hegelund 	stats->rx_frame_errors = portstats[spx5_stats_rx_alignment_lost_cnt] +
1101af4b1102SSteen Hegelund 		portstats[spx5_stats_pmac_rx_alignment_lost_cnt];
1102af4b1102SSteen Hegelund 	stats->tx_aborted_errors = portstats[spx5_stats_tx_xcoll_cnt];
1103af4b1102SSteen Hegelund 	stats->tx_carrier_errors = portstats[spx5_stats_tx_csense_cnt];
1104af4b1102SSteen Hegelund 	stats->tx_window_errors = portstats[spx5_stats_tx_late_coll_cnt];
1105af4b1102SSteen Hegelund 	stats->rx_dropped = portstats[spx5_stats_ana_ac_port_stat_lsb_cnt];
1106ed14fc7aSSteen Hegelund 	for (idx = 0; idx < 2 * SPX5_PRIOS; ++idx)
1107af4b1102SSteen Hegelund 		stats->rx_dropped += portstats[spx5_stats_green_p0_rx_port_drop
1108af4b1102SSteen Hegelund 					       + idx];
1109af4b1102SSteen Hegelund 	stats->tx_dropped = portstats[spx5_stats_tx_local_drop];
1110af4b1102SSteen Hegelund }
1111af4b1102SSteen Hegelund 
sparx5_update_port_stats(struct sparx5 * sparx5,int portno)1112af4b1102SSteen Hegelund static void sparx5_update_port_stats(struct sparx5 *sparx5, int portno)
1113af4b1102SSteen Hegelund {
1114af4b1102SSteen Hegelund 	if (sparx5_is_baser(sparx5->ports[portno]->conf.portmode))
1115af4b1102SSteen Hegelund 		sparx5_get_device_stats(sparx5, portno);
1116af4b1102SSteen Hegelund 	else
1117af4b1102SSteen Hegelund 		sparx5_get_asm_stats(sparx5, portno);
1118af4b1102SSteen Hegelund 	sparx5_get_ana_ac_stats_stats(sparx5, portno);
1119af4b1102SSteen Hegelund 	sparx5_get_queue_sys_stats(sparx5, portno);
1120af4b1102SSteen Hegelund }
1121af4b1102SSteen Hegelund 
sparx5_update_stats(struct sparx5 * sparx5)1122af4b1102SSteen Hegelund static void sparx5_update_stats(struct sparx5 *sparx5)
1123af4b1102SSteen Hegelund {
1124af4b1102SSteen Hegelund 	int idx;
1125af4b1102SSteen Hegelund 
1126af4b1102SSteen Hegelund 	for (idx = 0; idx < SPX5_PORTS; idx++)
1127af4b1102SSteen Hegelund 		if (sparx5->ports[idx])
1128af4b1102SSteen Hegelund 			sparx5_update_port_stats(sparx5, idx);
1129af4b1102SSteen Hegelund }
1130af4b1102SSteen Hegelund 
sparx5_check_stats_work(struct work_struct * work)1131af4b1102SSteen Hegelund static void sparx5_check_stats_work(struct work_struct *work)
1132af4b1102SSteen Hegelund {
1133af4b1102SSteen Hegelund 	struct delayed_work *dwork = to_delayed_work(work);
1134af4b1102SSteen Hegelund 	struct sparx5 *sparx5 = container_of(dwork,
1135af4b1102SSteen Hegelund 					     struct sparx5,
1136af4b1102SSteen Hegelund 					     stats_work);
1137af4b1102SSteen Hegelund 
1138af4b1102SSteen Hegelund 	sparx5_update_stats(sparx5);
1139af4b1102SSteen Hegelund 
1140af4b1102SSteen Hegelund 	queue_delayed_work(sparx5->stats_queue, &sparx5->stats_work,
1141af4b1102SSteen Hegelund 			   SPX5_STATS_CHECK_DELAY);
1142af4b1102SSteen Hegelund }
1143af4b1102SSteen Hegelund 
sparx5_get_link_settings(struct net_device * ndev,struct ethtool_link_ksettings * cmd)1144af4b1102SSteen Hegelund static int sparx5_get_link_settings(struct net_device *ndev,
1145af4b1102SSteen Hegelund 				    struct ethtool_link_ksettings *cmd)
1146af4b1102SSteen Hegelund {
1147af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
1148af4b1102SSteen Hegelund 
1149af4b1102SSteen Hegelund 	return phylink_ethtool_ksettings_get(port->phylink, cmd);
1150af4b1102SSteen Hegelund }
1151af4b1102SSteen Hegelund 
sparx5_set_link_settings(struct net_device * ndev,const struct ethtool_link_ksettings * cmd)1152af4b1102SSteen Hegelund static int sparx5_set_link_settings(struct net_device *ndev,
1153af4b1102SSteen Hegelund 				    const struct ethtool_link_ksettings *cmd)
1154af4b1102SSteen Hegelund {
1155af4b1102SSteen Hegelund 	struct sparx5_port *port = netdev_priv(ndev);
1156af4b1102SSteen Hegelund 
1157af4b1102SSteen Hegelund 	return phylink_ethtool_ksettings_set(port->phylink, cmd);
1158af4b1102SSteen Hegelund }
1159af4b1102SSteen Hegelund 
sparx5_config_stats(struct sparx5 * sparx5)1160af4b1102SSteen Hegelund static void sparx5_config_stats(struct sparx5 *sparx5)
1161af4b1102SSteen Hegelund {
1162af4b1102SSteen Hegelund 	/* Enable global events for port policer drops */
1163af4b1102SSteen Hegelund 	spx5_rmw(ANA_AC_PORT_SGE_CFG_MASK_SET(0xf0f0),
1164af4b1102SSteen Hegelund 		 ANA_AC_PORT_SGE_CFG_MASK,
1165af4b1102SSteen Hegelund 		 sparx5,
1166af4b1102SSteen Hegelund 		 ANA_AC_PORT_SGE_CFG(SPX5_PORT_POLICER_DROPS));
1167af4b1102SSteen Hegelund }
1168af4b1102SSteen Hegelund 
sparx5_config_port_stats(struct sparx5 * sparx5,int portno)1169af4b1102SSteen Hegelund static void sparx5_config_port_stats(struct sparx5 *sparx5, int portno)
1170af4b1102SSteen Hegelund {
1171af4b1102SSteen Hegelund 	/* Clear Queue System counters */
1172af4b1102SSteen Hegelund 	spx5_wr(XQS_STAT_CFG_STAT_VIEW_SET(portno) |
1173af4b1102SSteen Hegelund 		XQS_STAT_CFG_STAT_CLEAR_SHOT_SET(3), sparx5,
1174af4b1102SSteen Hegelund 		XQS_STAT_CFG);
1175af4b1102SSteen Hegelund 
1176af4b1102SSteen Hegelund 	/* Use counter for port policer drop count */
1177af4b1102SSteen Hegelund 	spx5_rmw(ANA_AC_PORT_STAT_CFG_CFG_CNT_FRM_TYPE_SET(1) |
1178af4b1102SSteen Hegelund 		 ANA_AC_PORT_STAT_CFG_CFG_CNT_BYTE_SET(0) |
1179af4b1102SSteen Hegelund 		 ANA_AC_PORT_STAT_CFG_CFG_PRIO_MASK_SET(0xff),
1180af4b1102SSteen Hegelund 		 ANA_AC_PORT_STAT_CFG_CFG_CNT_FRM_TYPE |
1181af4b1102SSteen Hegelund 		 ANA_AC_PORT_STAT_CFG_CFG_CNT_BYTE |
1182af4b1102SSteen Hegelund 		 ANA_AC_PORT_STAT_CFG_CFG_PRIO_MASK,
1183af4b1102SSteen Hegelund 		 sparx5, ANA_AC_PORT_STAT_CFG(portno, SPX5_PORT_POLICER_DROPS));
1184af4b1102SSteen Hegelund }
1185af4b1102SSteen Hegelund 
sparx5_get_ts_info(struct net_device * dev,struct ethtool_ts_info * info)1186608111fcSHoratiu Vultur static int sparx5_get_ts_info(struct net_device *dev,
1187608111fcSHoratiu Vultur 			      struct ethtool_ts_info *info)
1188608111fcSHoratiu Vultur {
1189608111fcSHoratiu Vultur 	struct sparx5_port *port = netdev_priv(dev);
1190608111fcSHoratiu Vultur 	struct sparx5 *sparx5 = port->sparx5;
1191608111fcSHoratiu Vultur 	struct sparx5_phc *phc;
1192608111fcSHoratiu Vultur 
1193608111fcSHoratiu Vultur 	if (!sparx5->ptp)
1194608111fcSHoratiu Vultur 		return ethtool_op_get_ts_info(dev, info);
1195608111fcSHoratiu Vultur 
1196608111fcSHoratiu Vultur 	phc = &sparx5->phc[SPARX5_PHC_PORT];
1197608111fcSHoratiu Vultur 
1198608111fcSHoratiu Vultur 	info->phc_index = phc->clock ? ptp_clock_index(phc->clock) : -1;
1199608111fcSHoratiu Vultur 	if (info->phc_index == -1) {
1200608111fcSHoratiu Vultur 		info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
1201608111fcSHoratiu Vultur 					 SOF_TIMESTAMPING_RX_SOFTWARE |
1202608111fcSHoratiu Vultur 					 SOF_TIMESTAMPING_SOFTWARE;
1203608111fcSHoratiu Vultur 		return 0;
1204608111fcSHoratiu Vultur 	}
1205608111fcSHoratiu Vultur 	info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
1206608111fcSHoratiu Vultur 				 SOF_TIMESTAMPING_RX_SOFTWARE |
1207608111fcSHoratiu Vultur 				 SOF_TIMESTAMPING_SOFTWARE |
1208608111fcSHoratiu Vultur 				 SOF_TIMESTAMPING_TX_HARDWARE |
1209608111fcSHoratiu Vultur 				 SOF_TIMESTAMPING_RX_HARDWARE |
1210608111fcSHoratiu Vultur 				 SOF_TIMESTAMPING_RAW_HARDWARE;
1211608111fcSHoratiu Vultur 	info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON) |
1212608111fcSHoratiu Vultur 			 BIT(HWTSTAMP_TX_ONESTEP_SYNC);
1213608111fcSHoratiu Vultur 	info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1214608111fcSHoratiu Vultur 			   BIT(HWTSTAMP_FILTER_ALL);
1215608111fcSHoratiu Vultur 
1216608111fcSHoratiu Vultur 	return 0;
1217608111fcSHoratiu Vultur }
1218608111fcSHoratiu Vultur 
1219af4b1102SSteen Hegelund const struct ethtool_ops sparx5_ethtool_ops = {
1220af4b1102SSteen Hegelund 	.get_sset_count         = sparx5_get_sset_count,
1221af4b1102SSteen Hegelund 	.get_strings            = sparx5_get_sset_strings,
1222af4b1102SSteen Hegelund 	.get_ethtool_stats      = sparx5_get_sset_data,
1223af4b1102SSteen Hegelund 	.get_link_ksettings	= sparx5_get_link_settings,
1224af4b1102SSteen Hegelund 	.set_link_ksettings	= sparx5_set_link_settings,
1225af4b1102SSteen Hegelund 	.get_link               = ethtool_op_get_link,
1226af4b1102SSteen Hegelund 	.get_eth_phy_stats      = sparx5_get_eth_phy_stats,
1227af4b1102SSteen Hegelund 	.get_eth_mac_stats      = sparx5_get_eth_mac_stats,
1228af4b1102SSteen Hegelund 	.get_eth_ctrl_stats     = sparx5_get_eth_mac_ctrl_stats,
1229af4b1102SSteen Hegelund 	.get_rmon_stats         = sparx5_get_eth_rmon_stats,
1230608111fcSHoratiu Vultur 	.get_ts_info            = sparx5_get_ts_info,
1231af4b1102SSteen Hegelund };
1232af4b1102SSteen Hegelund 
sparx_stats_init(struct sparx5 * sparx5)1233af4b1102SSteen Hegelund int sparx_stats_init(struct sparx5 *sparx5)
1234af4b1102SSteen Hegelund {
1235af4b1102SSteen Hegelund 	char queue_name[32];
1236af4b1102SSteen Hegelund 	int portno;
1237af4b1102SSteen Hegelund 
1238af4b1102SSteen Hegelund 	sparx5->stats_layout = sparx5_stats_layout;
1239af4b1102SSteen Hegelund 	sparx5->num_stats = spx5_stats_count;
1240af4b1102SSteen Hegelund 	sparx5->num_ethtool_stats = ARRAY_SIZE(sparx5_stats_layout);
1241af4b1102SSteen Hegelund 	sparx5->stats = devm_kcalloc(sparx5->dev,
1242af4b1102SSteen Hegelund 				     SPX5_PORTS_ALL * sparx5->num_stats,
1243af4b1102SSteen Hegelund 				     sizeof(u64), GFP_KERNEL);
1244af4b1102SSteen Hegelund 	if (!sparx5->stats)
1245af4b1102SSteen Hegelund 		return -ENOMEM;
1246af4b1102SSteen Hegelund 
1247af4b1102SSteen Hegelund 	mutex_init(&sparx5->queue_stats_lock);
1248af4b1102SSteen Hegelund 	sparx5_config_stats(sparx5);
1249af4b1102SSteen Hegelund 	for (portno = 0; portno < SPX5_PORTS; portno++)
1250af4b1102SSteen Hegelund 		if (sparx5->ports[portno])
1251af4b1102SSteen Hegelund 			sparx5_config_port_stats(sparx5, portno);
1252af4b1102SSteen Hegelund 
1253af4b1102SSteen Hegelund 	snprintf(queue_name, sizeof(queue_name), "%s-stats",
1254af4b1102SSteen Hegelund 		 dev_name(sparx5->dev));
1255af4b1102SSteen Hegelund 	sparx5->stats_queue = create_singlethread_workqueue(queue_name);
1256*639f5d00SShang XiaoJing 	if (!sparx5->stats_queue)
1257*639f5d00SShang XiaoJing 		return -ENOMEM;
1258*639f5d00SShang XiaoJing 
1259af4b1102SSteen Hegelund 	INIT_DELAYED_WORK(&sparx5->stats_work, sparx5_check_stats_work);
1260af4b1102SSteen Hegelund 	queue_delayed_work(sparx5->stats_queue, &sparx5->stats_work,
1261af4b1102SSteen Hegelund 			   SPX5_STATS_CHECK_DELAY);
1262af4b1102SSteen Hegelund 
1263af4b1102SSteen Hegelund 	return 0;
1264af4b1102SSteen Hegelund }
1265