1 /* bnx2x_stats.h: Broadcom Everest network driver.
3 * Copyright (c) 2007-2011 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
20 #include <linux/types.h>
26 u32 flow_ctrl_discard;
37 u32 egress_mac_pkt0_lo;
38 u32 egress_mac_pkt0_hi;
39 u32 egress_mac_pkt1_lo;
40 u32 egress_mac_pkt1_hi;
44 enum bnx2x_stats_event {
52 enum bnx2x_stats_state {
53 STATS_STATE_DISABLED = 0,
58 struct bnx2x_eth_stats {
59 u32 total_bytes_received_hi;
60 u32 total_bytes_received_lo;
61 u32 total_bytes_transmitted_hi;
62 u32 total_bytes_transmitted_lo;
63 u32 total_unicast_packets_received_hi;
64 u32 total_unicast_packets_received_lo;
65 u32 total_multicast_packets_received_hi;
66 u32 total_multicast_packets_received_lo;
67 u32 total_broadcast_packets_received_hi;
68 u32 total_broadcast_packets_received_lo;
69 u32 total_unicast_packets_transmitted_hi;
70 u32 total_unicast_packets_transmitted_lo;
71 u32 total_multicast_packets_transmitted_hi;
72 u32 total_multicast_packets_transmitted_lo;
73 u32 total_broadcast_packets_transmitted_hi;
74 u32 total_broadcast_packets_transmitted_lo;
75 u32 valid_bytes_received_hi;
76 u32 valid_bytes_received_lo;
78 u32 error_bytes_received_hi;
79 u32 error_bytes_received_lo;
80 u32 etherstatsoverrsizepkts_hi;
81 u32 etherstatsoverrsizepkts_lo;
82 u32 no_buff_discard_hi;
83 u32 no_buff_discard_lo;
85 u32 rx_stat_ifhcinbadoctets_hi;
86 u32 rx_stat_ifhcinbadoctets_lo;
87 u32 tx_stat_ifhcoutbadoctets_hi;
88 u32 tx_stat_ifhcoutbadoctets_lo;
89 u32 rx_stat_dot3statsfcserrors_hi;
90 u32 rx_stat_dot3statsfcserrors_lo;
91 u32 rx_stat_dot3statsalignmenterrors_hi;
92 u32 rx_stat_dot3statsalignmenterrors_lo;
93 u32 rx_stat_dot3statscarriersenseerrors_hi;
94 u32 rx_stat_dot3statscarriersenseerrors_lo;
95 u32 rx_stat_falsecarriererrors_hi;
96 u32 rx_stat_falsecarriererrors_lo;
97 u32 rx_stat_etherstatsundersizepkts_hi;
98 u32 rx_stat_etherstatsundersizepkts_lo;
99 u32 rx_stat_dot3statsframestoolong_hi;
100 u32 rx_stat_dot3statsframestoolong_lo;
101 u32 rx_stat_etherstatsfragments_hi;
102 u32 rx_stat_etherstatsfragments_lo;
103 u32 rx_stat_etherstatsjabbers_hi;
104 u32 rx_stat_etherstatsjabbers_lo;
105 u32 rx_stat_maccontrolframesreceived_hi;
106 u32 rx_stat_maccontrolframesreceived_lo;
107 u32 rx_stat_bmac_xpf_hi;
108 u32 rx_stat_bmac_xpf_lo;
109 u32 rx_stat_bmac_xcf_hi;
110 u32 rx_stat_bmac_xcf_lo;
111 u32 rx_stat_xoffstateentered_hi;
112 u32 rx_stat_xoffstateentered_lo;
113 u32 rx_stat_xonpauseframesreceived_hi;
114 u32 rx_stat_xonpauseframesreceived_lo;
115 u32 rx_stat_xoffpauseframesreceived_hi;
116 u32 rx_stat_xoffpauseframesreceived_lo;
117 u32 tx_stat_outxonsent_hi;
118 u32 tx_stat_outxonsent_lo;
119 u32 tx_stat_outxoffsent_hi;
120 u32 tx_stat_outxoffsent_lo;
121 u32 tx_stat_flowcontroldone_hi;
122 u32 tx_stat_flowcontroldone_lo;
123 u32 tx_stat_etherstatscollisions_hi;
124 u32 tx_stat_etherstatscollisions_lo;
125 u32 tx_stat_dot3statssinglecollisionframes_hi;
126 u32 tx_stat_dot3statssinglecollisionframes_lo;
127 u32 tx_stat_dot3statsmultiplecollisionframes_hi;
128 u32 tx_stat_dot3statsmultiplecollisionframes_lo;
129 u32 tx_stat_dot3statsdeferredtransmissions_hi;
130 u32 tx_stat_dot3statsdeferredtransmissions_lo;
131 u32 tx_stat_dot3statsexcessivecollisions_hi;
132 u32 tx_stat_dot3statsexcessivecollisions_lo;
133 u32 tx_stat_dot3statslatecollisions_hi;
134 u32 tx_stat_dot3statslatecollisions_lo;
135 u32 tx_stat_etherstatspkts64octets_hi;
136 u32 tx_stat_etherstatspkts64octets_lo;
137 u32 tx_stat_etherstatspkts65octetsto127octets_hi;
138 u32 tx_stat_etherstatspkts65octetsto127octets_lo;
139 u32 tx_stat_etherstatspkts128octetsto255octets_hi;
140 u32 tx_stat_etherstatspkts128octetsto255octets_lo;
141 u32 tx_stat_etherstatspkts256octetsto511octets_hi;
142 u32 tx_stat_etherstatspkts256octetsto511octets_lo;
143 u32 tx_stat_etherstatspkts512octetsto1023octets_hi;
144 u32 tx_stat_etherstatspkts512octetsto1023octets_lo;
145 u32 tx_stat_etherstatspkts1024octetsto1522octets_hi;
146 u32 tx_stat_etherstatspkts1024octetsto1522octets_lo;
147 u32 tx_stat_etherstatspktsover1522octets_hi;
148 u32 tx_stat_etherstatspktsover1522octets_lo;
149 u32 tx_stat_bmac_2047_hi;
150 u32 tx_stat_bmac_2047_lo;
151 u32 tx_stat_bmac_4095_hi;
152 u32 tx_stat_bmac_4095_lo;
153 u32 tx_stat_bmac_9216_hi;
154 u32 tx_stat_bmac_9216_lo;
155 u32 tx_stat_bmac_16383_hi;
156 u32 tx_stat_bmac_16383_lo;
157 u32 tx_stat_dot3statsinternalmactransmiterrors_hi;
158 u32 tx_stat_dot3statsinternalmactransmiterrors_lo;
159 u32 tx_stat_bmac_ufl_hi;
160 u32 tx_stat_bmac_ufl_lo;
162 u32 pause_frames_received_hi;
163 u32 pause_frames_received_lo;
164 u32 pause_frames_sent_hi;
165 u32 pause_frames_sent_lo;
167 u32 etherstatspkts1024octetsto1522octets_hi;
168 u32 etherstatspkts1024octetsto1522octets_lo;
169 u32 etherstatspktsover1522octets_hi;
170 u32 etherstatspktsover1522octets_lo;
177 u32 mac_filter_discard;
179 u32 brb_truncate_discard;
183 u32 rx_err_discard_pkt;
184 u32 rx_skb_alloc_failed;
190 u32 total_tpa_aggregations_hi;
191 u32 total_tpa_aggregations_lo;
192 u32 total_tpa_aggregated_frames_hi;
193 u32 total_tpa_aggregated_frames_lo;
194 u32 total_tpa_bytes_hi;
195 u32 total_tpa_bytes_lo;
199 struct bnx2x_eth_q_stats {
200 u32 total_unicast_bytes_received_hi;
201 u32 total_unicast_bytes_received_lo;
202 u32 total_broadcast_bytes_received_hi;
203 u32 total_broadcast_bytes_received_lo;
204 u32 total_multicast_bytes_received_hi;
205 u32 total_multicast_bytes_received_lo;
206 u32 total_bytes_received_hi;
207 u32 total_bytes_received_lo;
208 u32 total_unicast_bytes_transmitted_hi;
209 u32 total_unicast_bytes_transmitted_lo;
210 u32 total_broadcast_bytes_transmitted_hi;
211 u32 total_broadcast_bytes_transmitted_lo;
212 u32 total_multicast_bytes_transmitted_hi;
213 u32 total_multicast_bytes_transmitted_lo;
214 u32 total_bytes_transmitted_hi;
215 u32 total_bytes_transmitted_lo;
216 u32 total_unicast_packets_received_hi;
217 u32 total_unicast_packets_received_lo;
218 u32 total_multicast_packets_received_hi;
219 u32 total_multicast_packets_received_lo;
220 u32 total_broadcast_packets_received_hi;
221 u32 total_broadcast_packets_received_lo;
222 u32 total_unicast_packets_transmitted_hi;
223 u32 total_unicast_packets_transmitted_lo;
224 u32 total_multicast_packets_transmitted_hi;
225 u32 total_multicast_packets_transmitted_lo;
226 u32 total_broadcast_packets_transmitted_hi;
227 u32 total_broadcast_packets_transmitted_lo;
228 u32 valid_bytes_received_hi;
229 u32 valid_bytes_received_lo;
231 u32 etherstatsoverrsizepkts_hi;
232 u32 etherstatsoverrsizepkts_lo;
233 u32 no_buff_discard_hi;
234 u32 no_buff_discard_lo;
237 u32 rx_err_discard_pkt;
238 u32 rx_skb_alloc_failed;
241 u32 total_packets_received_checksum_discarded_hi;
242 u32 total_packets_received_checksum_discarded_lo;
243 u32 total_packets_received_ttl0_discarded_hi;
244 u32 total_packets_received_ttl0_discarded_lo;
245 u32 total_transmitted_dropped_packets_error_hi;
246 u32 total_transmitted_dropped_packets_error_lo;
249 u32 total_tpa_aggregations_hi;
250 u32 total_tpa_aggregations_lo;
251 u32 total_tpa_aggregated_frames_hi;
252 u32 total_tpa_aggregated_frames_lo;
253 u32 total_tpa_bytes_hi;
254 u32 total_tpa_bytes_lo;
257 /****************************************************************************
259 ****************************************************************************/
261 /* sum[hi:lo] += add[hi:lo] */
262 #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
265 s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
268 /* difference = minuend - subtrahend */
269 #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
273 d_hi = m_hi - s_hi; \
275 /* we can 'loan' 1 */ \
277 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
290 d_hi = m_hi - s_hi; \
291 d_lo = m_lo - s_lo; \
296 #define UPDATE_STAT64(s, t) \
298 DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
299 diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
300 pstats->mac_stx[0].t##_hi = new->s##_hi; \
301 pstats->mac_stx[0].t##_lo = new->s##_lo; \
302 ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
303 pstats->mac_stx[1].t##_lo, diff.lo); \
306 #define UPDATE_STAT64_NIG(s, t) \
308 DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
309 diff.lo, new->s##_lo, old->s##_lo); \
310 ADD_64(estats->t##_hi, diff.hi, \
311 estats->t##_lo, diff.lo); \
314 /* sum[hi:lo] += add */
315 #define ADD_EXTEND_64(s_hi, s_lo, a) \
318 s_hi += (s_lo < a) ? 1 : 0; \
321 #define ADD_STAT64(diff, t) \
323 ADD_64(pstats->mac_stx[1].t##_hi, new->diff##_hi, \
324 pstats->mac_stx[1].t##_lo, new->diff##_lo); \
327 #define UPDATE_EXTEND_STAT(s) \
329 ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
330 pstats->mac_stx[1].s##_lo, \
334 #define UPDATE_EXTEND_TSTAT(s, t) \
336 diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
337 old_tclient->s = tclient->s; \
338 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
341 #define UPDATE_EXTEND_USTAT(s, t) \
343 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
344 old_uclient->s = uclient->s; \
345 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
348 #define UPDATE_EXTEND_XSTAT(s, t) \
350 diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
351 old_xclient->s = xclient->s; \
352 ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
355 /* minuend -= subtrahend */
356 #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
358 DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
361 /* minuend[hi:lo] -= subtrahend */
362 #define SUB_EXTEND_64(m_hi, m_lo, s) \
364 SUB_64(m_hi, 0, m_lo, s); \
367 #define SUB_EXTEND_USTAT(s, t) \
369 diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
370 SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
377 void bnx2x_stats_init(struct bnx2x *bp);
379 void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
381 #endif /* BNX2X_STATS_H */