xref: /openbmc/linux/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
14ad79e13SYuval Mintz /* bnx2x_stats.h: QLogic Everest network driver.
2adfc5217SJeff Kirsher  *
3247fa82bSYuval Mintz  * Copyright (c) 2007-2013 Broadcom Corporation
44ad79e13SYuval Mintz  * Copyright (c) 2014 QLogic Corporation
54ad79e13SYuval Mintz  * All rights reserved
6adfc5217SJeff Kirsher  *
7adfc5217SJeff Kirsher  * This program is free software; you can redistribute it and/or modify
8adfc5217SJeff Kirsher  * it under the terms of the GNU General Public License as published by
9adfc5217SJeff Kirsher  * the Free Software Foundation.
10adfc5217SJeff Kirsher  *
1108f6dd89SAriel Elior  * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
12adfc5217SJeff Kirsher  * Written by: Eliezer Tamir
13adfc5217SJeff Kirsher  * Based on code from Michael Chan's bnx2 driver
14adfc5217SJeff Kirsher  * UDP CSUM errata workaround by Arik Gendelman
15adfc5217SJeff Kirsher  * Slowpath and fastpath rework by Vladislav Zolotarov
16adfc5217SJeff Kirsher  * Statistics and Link management by Yitchak Gertner
17adfc5217SJeff Kirsher  *
18adfc5217SJeff Kirsher  */
19adfc5217SJeff Kirsher #ifndef BNX2X_STATS_H
20adfc5217SJeff Kirsher #define BNX2X_STATS_H
21adfc5217SJeff Kirsher 
22adfc5217SJeff Kirsher #include <linux/types.h>
23adfc5217SJeff Kirsher 
24adfc5217SJeff Kirsher struct nig_stats {
25adfc5217SJeff Kirsher 	u32 brb_discard;
26adfc5217SJeff Kirsher 	u32 brb_packet;
27adfc5217SJeff Kirsher 	u32 brb_truncate;
28adfc5217SJeff Kirsher 	u32 flow_ctrl_discard;
29adfc5217SJeff Kirsher 	u32 flow_ctrl_octets;
30adfc5217SJeff Kirsher 	u32 flow_ctrl_packet;
31adfc5217SJeff Kirsher 	u32 mng_discard;
32adfc5217SJeff Kirsher 	u32 mng_octet_inp;
33adfc5217SJeff Kirsher 	u32 mng_octet_out;
34adfc5217SJeff Kirsher 	u32 mng_packet_inp;
35adfc5217SJeff Kirsher 	u32 mng_packet_out;
36adfc5217SJeff Kirsher 	u32 pbf_octets;
37adfc5217SJeff Kirsher 	u32 pbf_packet;
38adfc5217SJeff Kirsher 	u32 safc_inp;
39*29fd0ec6SKees Cook 	struct_group(egress_mac_pkt0,
40adfc5217SJeff Kirsher 		u32 egress_mac_pkt0_lo;
41adfc5217SJeff Kirsher 		u32 egress_mac_pkt0_hi;
42*29fd0ec6SKees Cook 	);
43*29fd0ec6SKees Cook 	struct_group(egress_mac_pkt1,
44adfc5217SJeff Kirsher 		u32 egress_mac_pkt1_lo;
45adfc5217SJeff Kirsher 		u32 egress_mac_pkt1_hi;
46*29fd0ec6SKees Cook 	);
47adfc5217SJeff Kirsher };
48adfc5217SJeff Kirsher 
49adfc5217SJeff Kirsher enum bnx2x_stats_event {
50adfc5217SJeff Kirsher 	STATS_EVENT_PMF = 0,
51adfc5217SJeff Kirsher 	STATS_EVENT_LINK_UP,
52adfc5217SJeff Kirsher 	STATS_EVENT_UPDATE,
53adfc5217SJeff Kirsher 	STATS_EVENT_STOP,
54adfc5217SJeff Kirsher 	STATS_EVENT_MAX
55adfc5217SJeff Kirsher };
56adfc5217SJeff Kirsher 
57adfc5217SJeff Kirsher enum bnx2x_stats_state {
58adfc5217SJeff Kirsher 	STATS_STATE_DISABLED = 0,
59adfc5217SJeff Kirsher 	STATS_STATE_ENABLED,
60adfc5217SJeff Kirsher 	STATS_STATE_MAX
61adfc5217SJeff Kirsher };
62adfc5217SJeff Kirsher 
63adfc5217SJeff Kirsher struct bnx2x_eth_stats {
64adfc5217SJeff Kirsher 	u32 total_bytes_received_hi;
65adfc5217SJeff Kirsher 	u32 total_bytes_received_lo;
66adfc5217SJeff Kirsher 	u32 total_bytes_transmitted_hi;
67adfc5217SJeff Kirsher 	u32 total_bytes_transmitted_lo;
68adfc5217SJeff Kirsher 	u32 total_unicast_packets_received_hi;
69adfc5217SJeff Kirsher 	u32 total_unicast_packets_received_lo;
70adfc5217SJeff Kirsher 	u32 total_multicast_packets_received_hi;
71adfc5217SJeff Kirsher 	u32 total_multicast_packets_received_lo;
72adfc5217SJeff Kirsher 	u32 total_broadcast_packets_received_hi;
73adfc5217SJeff Kirsher 	u32 total_broadcast_packets_received_lo;
74adfc5217SJeff Kirsher 	u32 total_unicast_packets_transmitted_hi;
75adfc5217SJeff Kirsher 	u32 total_unicast_packets_transmitted_lo;
76adfc5217SJeff Kirsher 	u32 total_multicast_packets_transmitted_hi;
77adfc5217SJeff Kirsher 	u32 total_multicast_packets_transmitted_lo;
78adfc5217SJeff Kirsher 	u32 total_broadcast_packets_transmitted_hi;
79adfc5217SJeff Kirsher 	u32 total_broadcast_packets_transmitted_lo;
80adfc5217SJeff Kirsher 	u32 valid_bytes_received_hi;
81adfc5217SJeff Kirsher 	u32 valid_bytes_received_lo;
82adfc5217SJeff Kirsher 
83adfc5217SJeff Kirsher 	u32 error_bytes_received_hi;
84adfc5217SJeff Kirsher 	u32 error_bytes_received_lo;
85adfc5217SJeff Kirsher 	u32 etherstatsoverrsizepkts_hi;
86adfc5217SJeff Kirsher 	u32 etherstatsoverrsizepkts_lo;
87adfc5217SJeff Kirsher 	u32 no_buff_discard_hi;
88adfc5217SJeff Kirsher 	u32 no_buff_discard_lo;
89adfc5217SJeff Kirsher 
90*29fd0ec6SKees Cook 	struct_group(shared,
91adfc5217SJeff Kirsher 	u32 rx_stat_ifhcinbadoctets_hi;
92adfc5217SJeff Kirsher 	u32 rx_stat_ifhcinbadoctets_lo;
93adfc5217SJeff Kirsher 	u32 tx_stat_ifhcoutbadoctets_hi;
94adfc5217SJeff Kirsher 	u32 tx_stat_ifhcoutbadoctets_lo;
95adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsfcserrors_hi;
96adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsfcserrors_lo;
97adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsalignmenterrors_hi;
98adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsalignmenterrors_lo;
99adfc5217SJeff Kirsher 	u32 rx_stat_dot3statscarriersenseerrors_hi;
100adfc5217SJeff Kirsher 	u32 rx_stat_dot3statscarriersenseerrors_lo;
101adfc5217SJeff Kirsher 	u32 rx_stat_falsecarriererrors_hi;
102adfc5217SJeff Kirsher 	u32 rx_stat_falsecarriererrors_lo;
103adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsundersizepkts_hi;
104adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsundersizepkts_lo;
105adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsframestoolong_hi;
106adfc5217SJeff Kirsher 	u32 rx_stat_dot3statsframestoolong_lo;
107adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsfragments_hi;
108adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsfragments_lo;
109adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsjabbers_hi;
110adfc5217SJeff Kirsher 	u32 rx_stat_etherstatsjabbers_lo;
111adfc5217SJeff Kirsher 	u32 rx_stat_maccontrolframesreceived_hi;
112adfc5217SJeff Kirsher 	u32 rx_stat_maccontrolframesreceived_lo;
113adfc5217SJeff Kirsher 	u32 rx_stat_bmac_xpf_hi;
114adfc5217SJeff Kirsher 	u32 rx_stat_bmac_xpf_lo;
115adfc5217SJeff Kirsher 	u32 rx_stat_bmac_xcf_hi;
116adfc5217SJeff Kirsher 	u32 rx_stat_bmac_xcf_lo;
117adfc5217SJeff Kirsher 	u32 rx_stat_xoffstateentered_hi;
118adfc5217SJeff Kirsher 	u32 rx_stat_xoffstateentered_lo;
119adfc5217SJeff Kirsher 	u32 rx_stat_xonpauseframesreceived_hi;
120adfc5217SJeff Kirsher 	u32 rx_stat_xonpauseframesreceived_lo;
121adfc5217SJeff Kirsher 	u32 rx_stat_xoffpauseframesreceived_hi;
122adfc5217SJeff Kirsher 	u32 rx_stat_xoffpauseframesreceived_lo;
123adfc5217SJeff Kirsher 	u32 tx_stat_outxonsent_hi;
124adfc5217SJeff Kirsher 	u32 tx_stat_outxonsent_lo;
125adfc5217SJeff Kirsher 	u32 tx_stat_outxoffsent_hi;
126adfc5217SJeff Kirsher 	u32 tx_stat_outxoffsent_lo;
127adfc5217SJeff Kirsher 	u32 tx_stat_flowcontroldone_hi;
128adfc5217SJeff Kirsher 	u32 tx_stat_flowcontroldone_lo;
129adfc5217SJeff Kirsher 	u32 tx_stat_etherstatscollisions_hi;
130adfc5217SJeff Kirsher 	u32 tx_stat_etherstatscollisions_lo;
131adfc5217SJeff Kirsher 	u32 tx_stat_dot3statssinglecollisionframes_hi;
132adfc5217SJeff Kirsher 	u32 tx_stat_dot3statssinglecollisionframes_lo;
133adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsmultiplecollisionframes_hi;
134adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsmultiplecollisionframes_lo;
135adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsdeferredtransmissions_hi;
136adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsdeferredtransmissions_lo;
137adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsexcessivecollisions_hi;
138adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsexcessivecollisions_lo;
139adfc5217SJeff Kirsher 	u32 tx_stat_dot3statslatecollisions_hi;
140adfc5217SJeff Kirsher 	u32 tx_stat_dot3statslatecollisions_lo;
141adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts64octets_hi;
142adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts64octets_lo;
143adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts65octetsto127octets_hi;
144adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts65octetsto127octets_lo;
145adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts128octetsto255octets_hi;
146adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts128octetsto255octets_lo;
147adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts256octetsto511octets_hi;
148adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts256octetsto511octets_lo;
149adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts512octetsto1023octets_hi;
150adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts512octetsto1023octets_lo;
151adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts1024octetsto1522octets_hi;
152adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspkts1024octetsto1522octets_lo;
153adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspktsover1522octets_hi;
154adfc5217SJeff Kirsher 	u32 tx_stat_etherstatspktsover1522octets_lo;
155adfc5217SJeff Kirsher 	u32 tx_stat_bmac_2047_hi;
156adfc5217SJeff Kirsher 	u32 tx_stat_bmac_2047_lo;
157adfc5217SJeff Kirsher 	u32 tx_stat_bmac_4095_hi;
158adfc5217SJeff Kirsher 	u32 tx_stat_bmac_4095_lo;
159adfc5217SJeff Kirsher 	u32 tx_stat_bmac_9216_hi;
160adfc5217SJeff Kirsher 	u32 tx_stat_bmac_9216_lo;
161adfc5217SJeff Kirsher 	u32 tx_stat_bmac_16383_hi;
162adfc5217SJeff Kirsher 	u32 tx_stat_bmac_16383_lo;
163adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsinternalmactransmiterrors_hi;
164adfc5217SJeff Kirsher 	u32 tx_stat_dot3statsinternalmactransmiterrors_lo;
165adfc5217SJeff Kirsher 	u32 tx_stat_bmac_ufl_hi;
166adfc5217SJeff Kirsher 	u32 tx_stat_bmac_ufl_lo;
167*29fd0ec6SKees Cook 	);
168adfc5217SJeff Kirsher 
169adfc5217SJeff Kirsher 	u32 pause_frames_received_hi;
170adfc5217SJeff Kirsher 	u32 pause_frames_received_lo;
171adfc5217SJeff Kirsher 	u32 pause_frames_sent_hi;
172adfc5217SJeff Kirsher 	u32 pause_frames_sent_lo;
173adfc5217SJeff Kirsher 
174adfc5217SJeff Kirsher 	u32 etherstatspkts1024octetsto1522octets_hi;
175adfc5217SJeff Kirsher 	u32 etherstatspkts1024octetsto1522octets_lo;
176adfc5217SJeff Kirsher 	u32 etherstatspktsover1522octets_hi;
177adfc5217SJeff Kirsher 	u32 etherstatspktsover1522octets_lo;
178adfc5217SJeff Kirsher 
179adfc5217SJeff Kirsher 	u32 brb_drop_hi;
180adfc5217SJeff Kirsher 	u32 brb_drop_lo;
181adfc5217SJeff Kirsher 	u32 brb_truncate_hi;
182adfc5217SJeff Kirsher 	u32 brb_truncate_lo;
183adfc5217SJeff Kirsher 
184adfc5217SJeff Kirsher 	u32 mac_filter_discard;
185adfc5217SJeff Kirsher 	u32 mf_tag_discard;
186adfc5217SJeff Kirsher 	u32 brb_truncate_discard;
187adfc5217SJeff Kirsher 	u32 mac_discard;
188adfc5217SJeff Kirsher 
189adfc5217SJeff Kirsher 	u32 driver_xoff;
190adfc5217SJeff Kirsher 	u32 rx_err_discard_pkt;
191adfc5217SJeff Kirsher 	u32 rx_skb_alloc_failed;
192adfc5217SJeff Kirsher 	u32 hw_csum_err;
193adfc5217SJeff Kirsher 
194adfc5217SJeff Kirsher 	u32 nig_timer_max;
195adfc5217SJeff Kirsher 
196adfc5217SJeff Kirsher 	/* TPA */
197adfc5217SJeff Kirsher 	u32 total_tpa_aggregations_hi;
198adfc5217SJeff Kirsher 	u32 total_tpa_aggregations_lo;
199adfc5217SJeff Kirsher 	u32 total_tpa_aggregated_frames_hi;
200adfc5217SJeff Kirsher 	u32 total_tpa_aggregated_frames_lo;
201adfc5217SJeff Kirsher 	u32 total_tpa_bytes_hi;
202adfc5217SJeff Kirsher 	u32 total_tpa_bytes_lo;
2030e898dd7SBarak Witkowski 
2040e898dd7SBarak Witkowski 	/* PFC */
2050e898dd7SBarak Witkowski 	u32 pfc_frames_received_hi;
2060e898dd7SBarak Witkowski 	u32 pfc_frames_received_lo;
2070e898dd7SBarak Witkowski 	u32 pfc_frames_sent_hi;
2080e898dd7SBarak Witkowski 	u32 pfc_frames_sent_lo;
2097a752993SAriel Elior 
2107a752993SAriel Elior 	/* Recovery */
2117a752993SAriel Elior 	u32 recoverable_error;
2127a752993SAriel Elior 	u32 unrecoverable_error;
213c96bdc0cSDmitry Kravkov 	u32 driver_filtered_tx_pkt;
214c8c60d88SYuval Mintz 	/* src: Clear-on-Read register; Will not survive PMF Migration */
215c8c60d88SYuval Mintz 	u32 eee_tx_lpi;
2163c91f25cSGuilherme G. Piccoli 
2173c91f25cSGuilherme G. Piccoli 	/* PTP */
2183c91f25cSGuilherme G. Piccoli 	u32 ptp_skip_tx_ts;
219adfc5217SJeff Kirsher };
220adfc5217SJeff Kirsher 
221adfc5217SJeff Kirsher struct bnx2x_eth_q_stats {
222adfc5217SJeff Kirsher 	u32 total_unicast_bytes_received_hi;
223adfc5217SJeff Kirsher 	u32 total_unicast_bytes_received_lo;
224adfc5217SJeff Kirsher 	u32 total_broadcast_bytes_received_hi;
225adfc5217SJeff Kirsher 	u32 total_broadcast_bytes_received_lo;
226adfc5217SJeff Kirsher 	u32 total_multicast_bytes_received_hi;
227adfc5217SJeff Kirsher 	u32 total_multicast_bytes_received_lo;
228adfc5217SJeff Kirsher 	u32 total_bytes_received_hi;
229adfc5217SJeff Kirsher 	u32 total_bytes_received_lo;
230adfc5217SJeff Kirsher 	u32 total_unicast_bytes_transmitted_hi;
231adfc5217SJeff Kirsher 	u32 total_unicast_bytes_transmitted_lo;
232adfc5217SJeff Kirsher 	u32 total_broadcast_bytes_transmitted_hi;
233adfc5217SJeff Kirsher 	u32 total_broadcast_bytes_transmitted_lo;
234adfc5217SJeff Kirsher 	u32 total_multicast_bytes_transmitted_hi;
235adfc5217SJeff Kirsher 	u32 total_multicast_bytes_transmitted_lo;
236adfc5217SJeff Kirsher 	u32 total_bytes_transmitted_hi;
237adfc5217SJeff Kirsher 	u32 total_bytes_transmitted_lo;
238adfc5217SJeff Kirsher 	u32 total_unicast_packets_received_hi;
239adfc5217SJeff Kirsher 	u32 total_unicast_packets_received_lo;
240adfc5217SJeff Kirsher 	u32 total_multicast_packets_received_hi;
241adfc5217SJeff Kirsher 	u32 total_multicast_packets_received_lo;
242adfc5217SJeff Kirsher 	u32 total_broadcast_packets_received_hi;
243adfc5217SJeff Kirsher 	u32 total_broadcast_packets_received_lo;
244adfc5217SJeff Kirsher 	u32 total_unicast_packets_transmitted_hi;
245adfc5217SJeff Kirsher 	u32 total_unicast_packets_transmitted_lo;
246adfc5217SJeff Kirsher 	u32 total_multicast_packets_transmitted_hi;
247adfc5217SJeff Kirsher 	u32 total_multicast_packets_transmitted_lo;
248adfc5217SJeff Kirsher 	u32 total_broadcast_packets_transmitted_hi;
249adfc5217SJeff Kirsher 	u32 total_broadcast_packets_transmitted_lo;
250adfc5217SJeff Kirsher 	u32 valid_bytes_received_hi;
251adfc5217SJeff Kirsher 	u32 valid_bytes_received_lo;
252adfc5217SJeff Kirsher 
253adfc5217SJeff Kirsher 	u32 etherstatsoverrsizepkts_hi;
254adfc5217SJeff Kirsher 	u32 etherstatsoverrsizepkts_lo;
255adfc5217SJeff Kirsher 	u32 no_buff_discard_hi;
256adfc5217SJeff Kirsher 	u32 no_buff_discard_lo;
257adfc5217SJeff Kirsher 
258adfc5217SJeff Kirsher 	u32 driver_xoff;
259adfc5217SJeff Kirsher 	u32 rx_err_discard_pkt;
260adfc5217SJeff Kirsher 	u32 rx_skb_alloc_failed;
261adfc5217SJeff Kirsher 	u32 hw_csum_err;
262adfc5217SJeff Kirsher 
263adfc5217SJeff Kirsher 	u32 total_packets_received_checksum_discarded_hi;
264adfc5217SJeff Kirsher 	u32 total_packets_received_checksum_discarded_lo;
265adfc5217SJeff Kirsher 	u32 total_packets_received_ttl0_discarded_hi;
266adfc5217SJeff Kirsher 	u32 total_packets_received_ttl0_discarded_lo;
267adfc5217SJeff Kirsher 	u32 total_transmitted_dropped_packets_error_hi;
268adfc5217SJeff Kirsher 	u32 total_transmitted_dropped_packets_error_lo;
269adfc5217SJeff Kirsher 
270adfc5217SJeff Kirsher 	/* TPA */
271adfc5217SJeff Kirsher 	u32 total_tpa_aggregations_hi;
272adfc5217SJeff Kirsher 	u32 total_tpa_aggregations_lo;
273adfc5217SJeff Kirsher 	u32 total_tpa_aggregated_frames_hi;
274adfc5217SJeff Kirsher 	u32 total_tpa_aggregated_frames_lo;
275adfc5217SJeff Kirsher 	u32 total_tpa_bytes_hi;
276adfc5217SJeff Kirsher 	u32 total_tpa_bytes_lo;
277c96bdc0cSDmitry Kravkov 	u32 driver_filtered_tx_pkt;
278adfc5217SJeff Kirsher };
279adfc5217SJeff Kirsher 
2801355b704SMintz Yuval struct bnx2x_eth_stats_old {
2811355b704SMintz Yuval 	u32 rx_stat_dot3statsframestoolong_hi;
2821355b704SMintz Yuval 	u32 rx_stat_dot3statsframestoolong_lo;
2831355b704SMintz Yuval };
2841355b704SMintz Yuval 
2851355b704SMintz Yuval struct bnx2x_eth_q_stats_old {
2861355b704SMintz Yuval 	/* Fields to perserve over fw reset*/
2871355b704SMintz Yuval 	u32 total_unicast_bytes_received_hi;
2881355b704SMintz Yuval 	u32 total_unicast_bytes_received_lo;
2891355b704SMintz Yuval 	u32 total_broadcast_bytes_received_hi;
2901355b704SMintz Yuval 	u32 total_broadcast_bytes_received_lo;
2911355b704SMintz Yuval 	u32 total_multicast_bytes_received_hi;
2921355b704SMintz Yuval 	u32 total_multicast_bytes_received_lo;
2931355b704SMintz Yuval 	u32 total_unicast_bytes_transmitted_hi;
2941355b704SMintz Yuval 	u32 total_unicast_bytes_transmitted_lo;
2951355b704SMintz Yuval 	u32 total_broadcast_bytes_transmitted_hi;
2961355b704SMintz Yuval 	u32 total_broadcast_bytes_transmitted_lo;
2971355b704SMintz Yuval 	u32 total_multicast_bytes_transmitted_hi;
2981355b704SMintz Yuval 	u32 total_multicast_bytes_transmitted_lo;
2991355b704SMintz Yuval 	u32 total_tpa_bytes_hi;
3001355b704SMintz Yuval 	u32 total_tpa_bytes_lo;
3011355b704SMintz Yuval 
3021355b704SMintz Yuval 	/* Fields to perserve last of */
3031355b704SMintz Yuval 	u32 total_bytes_received_hi;
3041355b704SMintz Yuval 	u32 total_bytes_received_lo;
3051355b704SMintz Yuval 	u32 total_bytes_transmitted_hi;
3061355b704SMintz Yuval 	u32 total_bytes_transmitted_lo;
3071355b704SMintz Yuval 	u32 total_unicast_packets_received_hi;
3081355b704SMintz Yuval 	u32 total_unicast_packets_received_lo;
3091355b704SMintz Yuval 	u32 total_multicast_packets_received_hi;
3101355b704SMintz Yuval 	u32 total_multicast_packets_received_lo;
3111355b704SMintz Yuval 	u32 total_broadcast_packets_received_hi;
3121355b704SMintz Yuval 	u32 total_broadcast_packets_received_lo;
3131355b704SMintz Yuval 	u32 total_unicast_packets_transmitted_hi;
3141355b704SMintz Yuval 	u32 total_unicast_packets_transmitted_lo;
3151355b704SMintz Yuval 	u32 total_multicast_packets_transmitted_hi;
3161355b704SMintz Yuval 	u32 total_multicast_packets_transmitted_lo;
3171355b704SMintz Yuval 	u32 total_broadcast_packets_transmitted_hi;
3181355b704SMintz Yuval 	u32 total_broadcast_packets_transmitted_lo;
3191355b704SMintz Yuval 	u32 valid_bytes_received_hi;
3201355b704SMintz Yuval 	u32 valid_bytes_received_lo;
3211355b704SMintz Yuval 
3221355b704SMintz Yuval 	u32 total_tpa_bytes_hi_old;
3231355b704SMintz Yuval 	u32 total_tpa_bytes_lo_old;
3241355b704SMintz Yuval 
3251355b704SMintz Yuval 	u32 driver_xoff_old;
3261355b704SMintz Yuval 	u32 rx_err_discard_pkt_old;
3271355b704SMintz Yuval 	u32 rx_skb_alloc_failed_old;
3281355b704SMintz Yuval 	u32 hw_csum_err_old;
329c96bdc0cSDmitry Kravkov 	u32 driver_filtered_tx_pkt_old;
3301355b704SMintz Yuval };
3311355b704SMintz Yuval 
3321355b704SMintz Yuval struct bnx2x_net_stats_old {
3331355b704SMintz Yuval 	 u32 rx_dropped;
3341355b704SMintz Yuval };
3351355b704SMintz Yuval 
3361355b704SMintz Yuval struct bnx2x_fw_port_stats_old {
3371355b704SMintz Yuval 	 u32 mac_filter_discard;
3381355b704SMintz Yuval 	 u32 mf_tag_discard;
3391355b704SMintz Yuval 	 u32 brb_truncate_discard;
3401355b704SMintz Yuval 	 u32 mac_discard;
3411355b704SMintz Yuval };
3421355b704SMintz Yuval 
343adfc5217SJeff Kirsher /****************************************************************************
344adfc5217SJeff Kirsher * Macros
345adfc5217SJeff Kirsher ****************************************************************************/
346adfc5217SJeff Kirsher 
347adfc5217SJeff Kirsher /* sum[hi:lo] += add[hi:lo] */
348adfc5217SJeff Kirsher #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
349adfc5217SJeff Kirsher 	do { \
350adfc5217SJeff Kirsher 		s_lo += a_lo; \
351adfc5217SJeff Kirsher 		s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
352adfc5217SJeff Kirsher 	} while (0)
353adfc5217SJeff Kirsher 
354a3348722SBarak Witkowski #define LE32_0 ((__force __le32) 0)
355a3348722SBarak Witkowski #define LE16_0 ((__force __le16) 0)
356a3348722SBarak Witkowski 
357a3348722SBarak Witkowski /* The _force is for cases where high value is 0 */
358a3348722SBarak Witkowski #define ADD_64_LE(s_hi, a_hi_le, s_lo, a_lo_le) \
359a3348722SBarak Witkowski 		ADD_64(s_hi, le32_to_cpu(a_hi_le), \
360a3348722SBarak Witkowski 		       s_lo, le32_to_cpu(a_lo_le))
361a3348722SBarak Witkowski 
362a3348722SBarak Witkowski #define ADD_64_LE16(s_hi, a_hi_le, s_lo, a_lo_le) \
363a3348722SBarak Witkowski 		ADD_64(s_hi, le16_to_cpu(a_hi_le), \
364a3348722SBarak Witkowski 		       s_lo, le16_to_cpu(a_lo_le))
365a3348722SBarak Witkowski 
366adfc5217SJeff Kirsher /* difference = minuend - subtrahend */
367adfc5217SJeff Kirsher #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
368adfc5217SJeff Kirsher 	do { \
369adfc5217SJeff Kirsher 		if (m_lo < s_lo) { \
370adfc5217SJeff Kirsher 			/* underflow */ \
371adfc5217SJeff Kirsher 			d_hi = m_hi - s_hi; \
372adfc5217SJeff Kirsher 			if (d_hi > 0) { \
373adfc5217SJeff Kirsher 				/* we can 'loan' 1 */ \
374adfc5217SJeff Kirsher 				d_hi--; \
375adfc5217SJeff Kirsher 				d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
376adfc5217SJeff Kirsher 			} else { \
377adfc5217SJeff Kirsher 				/* m_hi <= s_hi */ \
378adfc5217SJeff Kirsher 				d_hi = 0; \
379adfc5217SJeff Kirsher 				d_lo = 0; \
380adfc5217SJeff Kirsher 			} \
381adfc5217SJeff Kirsher 		} else { \
382adfc5217SJeff Kirsher 			/* m_lo >= s_lo */ \
383adfc5217SJeff Kirsher 			if (m_hi < s_hi) { \
384adfc5217SJeff Kirsher 				d_hi = 0; \
385adfc5217SJeff Kirsher 				d_lo = 0; \
386adfc5217SJeff Kirsher 			} else { \
387adfc5217SJeff Kirsher 				/* m_hi >= s_hi */ \
388adfc5217SJeff Kirsher 				d_hi = m_hi - s_hi; \
389adfc5217SJeff Kirsher 				d_lo = m_lo - s_lo; \
390adfc5217SJeff Kirsher 			} \
391adfc5217SJeff Kirsher 		} \
392adfc5217SJeff Kirsher 	} while (0)
393adfc5217SJeff Kirsher 
394adfc5217SJeff Kirsher #define UPDATE_STAT64(s, t) \
395adfc5217SJeff Kirsher 	do { \
396adfc5217SJeff Kirsher 		DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
397adfc5217SJeff Kirsher 			diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
398adfc5217SJeff Kirsher 		pstats->mac_stx[0].t##_hi = new->s##_hi; \
399adfc5217SJeff Kirsher 		pstats->mac_stx[0].t##_lo = new->s##_lo; \
400adfc5217SJeff Kirsher 		ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
401adfc5217SJeff Kirsher 		       pstats->mac_stx[1].t##_lo, diff.lo); \
402adfc5217SJeff Kirsher 	} while (0)
403adfc5217SJeff Kirsher 
404adfc5217SJeff Kirsher #define UPDATE_STAT64_NIG(s, t) \
405adfc5217SJeff Kirsher 	do { \
406adfc5217SJeff Kirsher 		DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
407adfc5217SJeff Kirsher 			diff.lo, new->s##_lo, old->s##_lo); \
408adfc5217SJeff Kirsher 		ADD_64(estats->t##_hi, diff.hi, \
409adfc5217SJeff Kirsher 		       estats->t##_lo, diff.lo); \
410adfc5217SJeff Kirsher 	} while (0)
411adfc5217SJeff Kirsher 
412adfc5217SJeff Kirsher /* sum[hi:lo] += add */
413adfc5217SJeff Kirsher #define ADD_EXTEND_64(s_hi, s_lo, a) \
414adfc5217SJeff Kirsher 	do { \
415adfc5217SJeff Kirsher 		s_lo += a; \
416adfc5217SJeff Kirsher 		s_hi += (s_lo < a) ? 1 : 0; \
417adfc5217SJeff Kirsher 	} while (0)
418adfc5217SJeff Kirsher 
419adfc5217SJeff Kirsher #define ADD_STAT64(diff, t) \
420adfc5217SJeff Kirsher 	do { \
421adfc5217SJeff Kirsher 		ADD_64(pstats->mac_stx[1].t##_hi, new->diff##_hi, \
422adfc5217SJeff Kirsher 		       pstats->mac_stx[1].t##_lo, new->diff##_lo); \
423adfc5217SJeff Kirsher 	} while (0)
424adfc5217SJeff Kirsher 
425adfc5217SJeff Kirsher #define UPDATE_EXTEND_STAT(s) \
426adfc5217SJeff Kirsher 	do { \
427adfc5217SJeff Kirsher 		ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
428adfc5217SJeff Kirsher 			      pstats->mac_stx[1].s##_lo, \
429adfc5217SJeff Kirsher 			      new->s); \
430adfc5217SJeff Kirsher 	} while (0)
431adfc5217SJeff Kirsher 
43286564c3fSYuval Mintz #define UPDATE_EXTEND_TSTAT_X(s, t, size) \
433adfc5217SJeff Kirsher 	do { \
43486564c3fSYuval Mintz 		diff = le##size##_to_cpu(tclient->s) - \
43586564c3fSYuval Mintz 		       le##size##_to_cpu(old_tclient->s); \
436adfc5217SJeff Kirsher 		old_tclient->s = tclient->s; \
437adfc5217SJeff Kirsher 		ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
438adfc5217SJeff Kirsher 	} while (0)
439adfc5217SJeff Kirsher 
44086564c3fSYuval Mintz #define UPDATE_EXTEND_TSTAT(s, t) UPDATE_EXTEND_TSTAT_X(s, t, 32)
44186564c3fSYuval Mintz 
44286564c3fSYuval Mintz #define UPDATE_EXTEND_E_TSTAT(s, t, size) \
4431355b704SMintz Yuval 	do { \
44486564c3fSYuval Mintz 		UPDATE_EXTEND_TSTAT_X(s, t, size); \
4451355b704SMintz Yuval 		ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
4461355b704SMintz Yuval 	} while (0)
4471355b704SMintz Yuval 
448adfc5217SJeff Kirsher #define UPDATE_EXTEND_USTAT(s, t) \
449adfc5217SJeff Kirsher 	do { \
450adfc5217SJeff Kirsher 		diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
451adfc5217SJeff Kirsher 		old_uclient->s = uclient->s; \
452cb4dca27SYuval Mintz 		ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
4531355b704SMintz Yuval 	} while (0)
4541355b704SMintz Yuval 
4551355b704SMintz Yuval #define UPDATE_EXTEND_E_USTAT(s, t) \
4561355b704SMintz Yuval 	do { \
4571355b704SMintz Yuval 		UPDATE_EXTEND_USTAT(s, t); \
4581355b704SMintz Yuval 		ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
459adfc5217SJeff Kirsher 	} while (0)
460adfc5217SJeff Kirsher 
461adfc5217SJeff Kirsher #define UPDATE_EXTEND_XSTAT(s, t) \
462adfc5217SJeff Kirsher 	do { \
463adfc5217SJeff Kirsher 		diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
464adfc5217SJeff Kirsher 		old_xclient->s = xclient->s; \
465adfc5217SJeff Kirsher 		ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
466adfc5217SJeff Kirsher 	} while (0)
467adfc5217SJeff Kirsher 
4681355b704SMintz Yuval #define UPDATE_QSTAT(s, t) \
4691355b704SMintz Yuval 	do { \
4701355b704SMintz Yuval 		qstats->t##_lo = qstats_old->t##_lo + le32_to_cpu(s.lo); \
471b009aac1SMaciej Żenczykowski 		qstats->t##_hi = qstats_old->t##_hi + le32_to_cpu(s.hi) \
472b009aac1SMaciej Żenczykowski 			+ ((qstats->t##_lo < qstats_old->t##_lo) ? 1 : 0); \
4731355b704SMintz Yuval 	} while (0)
4741355b704SMintz Yuval 
4751355b704SMintz Yuval #define UPDATE_QSTAT_OLD(f) \
4761355b704SMintz Yuval 	do { \
4771355b704SMintz Yuval 		qstats_old->f = qstats->f; \
4781355b704SMintz Yuval 	} while (0)
4791355b704SMintz Yuval 
4801355b704SMintz Yuval #define UPDATE_ESTAT_QSTAT_64(s) \
4811355b704SMintz Yuval 	do { \
4821355b704SMintz Yuval 		ADD_64(estats->s##_hi, qstats->s##_hi, \
4831355b704SMintz Yuval 		       estats->s##_lo, qstats->s##_lo); \
4841355b704SMintz Yuval 		SUB_64(estats->s##_hi, qstats_old->s##_hi_old, \
4851355b704SMintz Yuval 		       estats->s##_lo, qstats_old->s##_lo_old); \
4861355b704SMintz Yuval 		qstats_old->s##_hi_old = qstats->s##_hi; \
4871355b704SMintz Yuval 		qstats_old->s##_lo_old = qstats->s##_lo; \
4881355b704SMintz Yuval 	} while (0)
4891355b704SMintz Yuval 
4901355b704SMintz Yuval #define UPDATE_ESTAT_QSTAT(s) \
4911355b704SMintz Yuval 	do { \
4921355b704SMintz Yuval 		estats->s += qstats->s; \
4931355b704SMintz Yuval 		estats->s -= qstats_old->s##_old; \
4941355b704SMintz Yuval 		qstats_old->s##_old = qstats->s; \
4951355b704SMintz Yuval 	} while (0)
4961355b704SMintz Yuval 
4971355b704SMintz Yuval #define UPDATE_FSTAT_QSTAT(s) \
4981355b704SMintz Yuval 	do { \
4991355b704SMintz Yuval 		ADD_64(fstats->s##_hi, qstats->s##_hi, \
5001355b704SMintz Yuval 		       fstats->s##_lo, qstats->s##_lo); \
5011355b704SMintz Yuval 		SUB_64(fstats->s##_hi, qstats_old->s##_hi, \
5021355b704SMintz Yuval 		       fstats->s##_lo, qstats_old->s##_lo); \
5031355b704SMintz Yuval 		estats->s##_hi = fstats->s##_hi; \
5041355b704SMintz Yuval 		estats->s##_lo = fstats->s##_lo; \
5051355b704SMintz Yuval 		qstats_old->s##_hi = qstats->s##_hi; \
5061355b704SMintz Yuval 		qstats_old->s##_lo = qstats->s##_lo; \
5071355b704SMintz Yuval 	} while (0)
5081355b704SMintz Yuval 
5091355b704SMintz Yuval #define UPDATE_FW_STAT(s) \
5101355b704SMintz Yuval 	do { \
5111355b704SMintz Yuval 		estats->s = le32_to_cpu(tport->s) + fwstats->s; \
5121355b704SMintz Yuval 	} while (0)
5131355b704SMintz Yuval 
5141355b704SMintz Yuval #define UPDATE_FW_STAT_OLD(f) \
5151355b704SMintz Yuval 	do { \
5161355b704SMintz Yuval 		fwstats->f = estats->f; \
5171355b704SMintz Yuval 	} while (0)
5181355b704SMintz Yuval 
5191355b704SMintz Yuval #define UPDATE_ESTAT(s, t) \
5201355b704SMintz Yuval 	do { \
5211355b704SMintz Yuval 		SUB_64(estats->s##_hi, estats_old->t##_hi, \
5221355b704SMintz Yuval 		       estats->s##_lo, estats_old->t##_lo); \
5231355b704SMintz Yuval 		ADD_64(estats->s##_hi, estats->t##_hi, \
5241355b704SMintz Yuval 		       estats->s##_lo, estats->t##_lo); \
5251355b704SMintz Yuval 		estats_old->t##_hi = estats->t##_hi; \
5261355b704SMintz Yuval 		estats_old->t##_lo = estats->t##_lo; \
5271355b704SMintz Yuval 	} while (0)
5281355b704SMintz Yuval 
529adfc5217SJeff Kirsher /* minuend -= subtrahend */
530adfc5217SJeff Kirsher #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
531adfc5217SJeff Kirsher 	do { \
532adfc5217SJeff Kirsher 		DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
533adfc5217SJeff Kirsher 	} while (0)
534adfc5217SJeff Kirsher 
535adfc5217SJeff Kirsher /* minuend[hi:lo] -= subtrahend */
536adfc5217SJeff Kirsher #define SUB_EXTEND_64(m_hi, m_lo, s) \
537adfc5217SJeff Kirsher 	do { \
538adfc5217SJeff Kirsher 		SUB_64(m_hi, 0, m_lo, s); \
539adfc5217SJeff Kirsher 	} while (0)
540adfc5217SJeff Kirsher 
541adfc5217SJeff Kirsher #define SUB_EXTEND_USTAT(s, t) \
542adfc5217SJeff Kirsher 	do { \
543adfc5217SJeff Kirsher 		diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
544adfc5217SJeff Kirsher 		SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
545adfc5217SJeff Kirsher 	} while (0)
546adfc5217SJeff Kirsher 
547adfc5217SJeff Kirsher /* forward */
548adfc5217SJeff Kirsher struct bnx2x;
549adfc5217SJeff Kirsher 
5505b0752c8SAriel Elior void bnx2x_memset_stats(struct bnx2x *bp);
551adfc5217SJeff Kirsher void bnx2x_stats_init(struct bnx2x *bp);
552adfc5217SJeff Kirsher void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
553dff173deSYuval Mintz int bnx2x_stats_safe_exec(struct bnx2x *bp,
554a3097bdaSAriel Elior 			  void (func_to_exec)(void *cookie),
555a3097bdaSAriel Elior 			  void *cookie);
556adfc5217SJeff Kirsher 
5571355b704SMintz Yuval /**
5581355b704SMintz Yuval  * bnx2x_save_statistics - save statistics when unloading.
5591355b704SMintz Yuval  *
5601355b704SMintz Yuval  * @bp:		driver handle
5611355b704SMintz Yuval  */
5621355b704SMintz Yuval void bnx2x_save_statistics(struct bnx2x *bp);
563a3348722SBarak Witkowski 
564a3348722SBarak Witkowski void bnx2x_afex_collect_stats(struct bnx2x *bp, void *void_afex_stats,
565a3348722SBarak Witkowski 			      u32 stats_type);
566adfc5217SJeff Kirsher #endif /* BNX2X_STATS_H */
567