New upstream version 18.08
[deb_dpdk.git] / drivers / net / bnx2x / bnx2x_stats.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2007-2013 Broadcom Corporation.
3  *
4  * Eric Davis        <edavis@broadcom.com>
5  * David Christensen <davidch@broadcom.com>
6  * Gary Zambrano     <zambrano@broadcom.com>
7  *
8  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
9  * Copyright (c) 2015-2018 Cavium Inc.
10  * All rights reserved.
11  * www.cavium.com
12  */
13
14 #ifndef BNX2X_STATS_H
15 #define BNX2X_STATS_H
16
17 #include <sys/types.h>
18
19 struct nig_stats {
20     uint32_t brb_discard;
21     uint32_t brb_packet;
22     uint32_t brb_truncate;
23     uint32_t flow_ctrl_discard;
24     uint32_t flow_ctrl_octets;
25     uint32_t flow_ctrl_packet;
26     uint32_t mng_discard;
27     uint32_t mng_octet_inp;
28     uint32_t mng_octet_out;
29     uint32_t mng_packet_inp;
30     uint32_t mng_packet_out;
31     uint32_t pbf_octets;
32     uint32_t pbf_packet;
33     uint32_t safc_inp;
34     uint32_t egress_mac_pkt0_lo;
35     uint32_t egress_mac_pkt0_hi;
36     uint32_t egress_mac_pkt1_lo;
37     uint32_t egress_mac_pkt1_hi;
38 };
39
40
41 enum bnx2x_stats_event {
42     STATS_EVENT_PMF = 0,
43     STATS_EVENT_LINK_UP,
44     STATS_EVENT_UPDATE,
45     STATS_EVENT_STOP,
46     STATS_EVENT_MAX
47 };
48
49 enum bnx2x_stats_state {
50     STATS_STATE_DISABLED = 0,
51     STATS_STATE_ENABLED,
52     STATS_STATE_MAX
53 };
54
55 struct bnx2x_eth_stats {
56     uint32_t total_bytes_received_hi;
57     uint32_t total_bytes_received_lo;
58     uint32_t total_bytes_transmitted_hi;
59     uint32_t total_bytes_transmitted_lo;
60     uint32_t total_unicast_packets_received_hi;
61     uint32_t total_unicast_packets_received_lo;
62     uint32_t total_multicast_packets_received_hi;
63     uint32_t total_multicast_packets_received_lo;
64     uint32_t total_broadcast_packets_received_hi;
65     uint32_t total_broadcast_packets_received_lo;
66     uint32_t total_unicast_packets_transmitted_hi;
67     uint32_t total_unicast_packets_transmitted_lo;
68     uint32_t total_multicast_packets_transmitted_hi;
69     uint32_t total_multicast_packets_transmitted_lo;
70     uint32_t total_broadcast_packets_transmitted_hi;
71     uint32_t total_broadcast_packets_transmitted_lo;
72     uint32_t valid_bytes_received_hi;
73     uint32_t valid_bytes_received_lo;
74
75     uint32_t error_bytes_received_hi;
76     uint32_t error_bytes_received_lo;
77     uint32_t etherstatsoverrsizepkts_hi;
78     uint32_t etherstatsoverrsizepkts_lo;
79     uint32_t no_buff_discard_hi;
80     uint32_t no_buff_discard_lo;
81
82     uint32_t rx_stat_ifhcinbadoctets_hi;
83     uint32_t rx_stat_ifhcinbadoctets_lo;
84     uint32_t tx_stat_ifhcoutbadoctets_hi;
85     uint32_t tx_stat_ifhcoutbadoctets_lo;
86     uint32_t rx_stat_dot3statsfcserrors_hi;
87     uint32_t rx_stat_dot3statsfcserrors_lo;
88     uint32_t rx_stat_dot3statsalignmenterrors_hi;
89     uint32_t rx_stat_dot3statsalignmenterrors_lo;
90     uint32_t rx_stat_dot3statscarriersenseerrors_hi;
91     uint32_t rx_stat_dot3statscarriersenseerrors_lo;
92     uint32_t rx_stat_falsecarriererrors_hi;
93     uint32_t rx_stat_falsecarriererrors_lo;
94     uint32_t rx_stat_etherstatsundersizepkts_hi;
95     uint32_t rx_stat_etherstatsundersizepkts_lo;
96     uint32_t rx_stat_dot3statsframestoolong_hi;
97     uint32_t rx_stat_dot3statsframestoolong_lo;
98     uint32_t rx_stat_etherstatsfragments_hi;
99     uint32_t rx_stat_etherstatsfragments_lo;
100     uint32_t rx_stat_etherstatsjabbers_hi;
101     uint32_t rx_stat_etherstatsjabbers_lo;
102     uint32_t rx_stat_maccontrolframesreceived_hi;
103     uint32_t rx_stat_maccontrolframesreceived_lo;
104     uint32_t rx_stat_bmac_xpf_hi;
105     uint32_t rx_stat_bmac_xpf_lo;
106     uint32_t rx_stat_bmac_xcf_hi;
107     uint32_t rx_stat_bmac_xcf_lo;
108     uint32_t rx_stat_xoffstateentered_hi;
109     uint32_t rx_stat_xoffstateentered_lo;
110     uint32_t rx_stat_xonpauseframesreceived_hi;
111     uint32_t rx_stat_xonpauseframesreceived_lo;
112     uint32_t rx_stat_xoffpauseframesreceived_hi;
113     uint32_t rx_stat_xoffpauseframesreceived_lo;
114     uint32_t tx_stat_outxonsent_hi;
115     uint32_t tx_stat_outxonsent_lo;
116     uint32_t tx_stat_outxoffsent_hi;
117     uint32_t tx_stat_outxoffsent_lo;
118     uint32_t tx_stat_flowcontroldone_hi;
119     uint32_t tx_stat_flowcontroldone_lo;
120     uint32_t tx_stat_etherstatscollisions_hi;
121     uint32_t tx_stat_etherstatscollisions_lo;
122     uint32_t tx_stat_dot3statssinglecollisionframes_hi;
123     uint32_t tx_stat_dot3statssinglecollisionframes_lo;
124     uint32_t tx_stat_dot3statsmultiplecollisionframes_hi;
125     uint32_t tx_stat_dot3statsmultiplecollisionframes_lo;
126     uint32_t tx_stat_dot3statsdeferredtransmissions_hi;
127     uint32_t tx_stat_dot3statsdeferredtransmissions_lo;
128     uint32_t tx_stat_dot3statsexcessivecollisions_hi;
129     uint32_t tx_stat_dot3statsexcessivecollisions_lo;
130     uint32_t tx_stat_dot3statslatecollisions_hi;
131     uint32_t tx_stat_dot3statslatecollisions_lo;
132     uint32_t tx_stat_etherstatspkts64octets_hi;
133     uint32_t tx_stat_etherstatspkts64octets_lo;
134     uint32_t tx_stat_etherstatspkts65octetsto127octets_hi;
135     uint32_t tx_stat_etherstatspkts65octetsto127octets_lo;
136     uint32_t tx_stat_etherstatspkts128octetsto255octets_hi;
137     uint32_t tx_stat_etherstatspkts128octetsto255octets_lo;
138     uint32_t tx_stat_etherstatspkts256octetsto511octets_hi;
139     uint32_t tx_stat_etherstatspkts256octetsto511octets_lo;
140     uint32_t tx_stat_etherstatspkts512octetsto1023octets_hi;
141     uint32_t tx_stat_etherstatspkts512octetsto1023octets_lo;
142     uint32_t tx_stat_etherstatspkts1024octetsto1522octets_hi;
143     uint32_t tx_stat_etherstatspkts1024octetsto1522octets_lo;
144     uint32_t tx_stat_etherstatspktsover1522octets_hi;
145     uint32_t tx_stat_etherstatspktsover1522octets_lo;
146     uint32_t tx_stat_bmac_2047_hi;
147     uint32_t tx_stat_bmac_2047_lo;
148     uint32_t tx_stat_bmac_4095_hi;
149     uint32_t tx_stat_bmac_4095_lo;
150     uint32_t tx_stat_bmac_9216_hi;
151     uint32_t tx_stat_bmac_9216_lo;
152     uint32_t tx_stat_bmac_16383_hi;
153     uint32_t tx_stat_bmac_16383_lo;
154     uint32_t tx_stat_dot3statsinternalmactransmiterrors_hi;
155     uint32_t tx_stat_dot3statsinternalmactransmiterrors_lo;
156     uint32_t tx_stat_bmac_ufl_hi;
157     uint32_t tx_stat_bmac_ufl_lo;
158
159     uint32_t pause_frames_received_hi;
160     uint32_t pause_frames_received_lo;
161     uint32_t pause_frames_sent_hi;
162     uint32_t pause_frames_sent_lo;
163
164     uint32_t etherstatspkts1024octetsto1522octets_hi;
165     uint32_t etherstatspkts1024octetsto1522octets_lo;
166     uint32_t etherstatspktsover1522octets_hi;
167     uint32_t etherstatspktsover1522octets_lo;
168
169     uint32_t brb_drop_hi;
170     uint32_t brb_drop_lo;
171     uint32_t brb_truncate_hi;
172     uint32_t brb_truncate_lo;
173
174     uint32_t mac_filter_discard;
175     uint32_t mf_tag_discard;
176     uint32_t brb_truncate_discard;
177     uint32_t mac_discard;
178
179     uint32_t nig_timer_max;
180
181     /* PFC */
182     uint32_t pfc_frames_received_hi;
183     uint32_t pfc_frames_received_lo;
184     uint32_t pfc_frames_sent_hi;
185     uint32_t pfc_frames_sent_lo;
186
187     /* Recovery */
188     uint32_t recoverable_error;
189     uint32_t unrecoverable_error;
190
191     /* src: Clear-on-Read register; Will not survive PMF Migration */
192     uint32_t eee_tx_lpi;
193
194     /* receive path driver statistics */
195     uint32_t rx_calls;
196     uint32_t rx_pkts;
197     uint32_t rx_soft_errors;
198     uint32_t rx_hw_csum_errors;
199     uint32_t rx_ofld_frames_csum_ip;
200     uint32_t rx_ofld_frames_csum_tcp_udp;
201     uint32_t rx_budget_reached;
202
203     /* tx path driver statistics */
204     uint32_t tx_pkts;
205     uint32_t tx_soft_errors;
206     uint32_t tx_ofld_frames_csum_ip;
207     uint32_t tx_ofld_frames_csum_tcp;
208     uint32_t tx_ofld_frames_csum_udp;
209     uint32_t tx_encap_failures;
210     uint32_t tx_hw_queue_full;
211     uint32_t tx_hw_max_queue_depth;
212     uint32_t tx_dma_mapping_failure;
213     uint32_t tx_max_drbr_queue_depth;
214     uint32_t tx_window_violation_std;
215     uint32_t tx_chain_lost_mbuf;
216     uint32_t tx_frames_deferred;
217     uint32_t tx_queue_xoff;
218
219     /* mbuf driver statistics */
220     uint32_t mbuf_defrag_attempts;
221     uint32_t mbuf_defrag_failures;
222     uint32_t mbuf_rx_bd_alloc_failed;
223     uint32_t mbuf_rx_bd_mapping_failed;
224
225     /* track the number of allocated mbufs */
226     uint32_t mbuf_alloc_tx;
227     uint32_t mbuf_alloc_rx;
228 };
229
230
231 struct bnx2x_eth_q_stats {
232     uint32_t total_unicast_bytes_received_hi;
233     uint32_t total_unicast_bytes_received_lo;
234     uint32_t total_broadcast_bytes_received_hi;
235     uint32_t total_broadcast_bytes_received_lo;
236     uint32_t total_multicast_bytes_received_hi;
237     uint32_t total_multicast_bytes_received_lo;
238     uint32_t total_bytes_received_hi;
239     uint32_t total_bytes_received_lo;
240     uint32_t total_unicast_bytes_transmitted_hi;
241     uint32_t total_unicast_bytes_transmitted_lo;
242     uint32_t total_broadcast_bytes_transmitted_hi;
243     uint32_t total_broadcast_bytes_transmitted_lo;
244     uint32_t total_multicast_bytes_transmitted_hi;
245     uint32_t total_multicast_bytes_transmitted_lo;
246     uint32_t total_bytes_transmitted_hi;
247     uint32_t total_bytes_transmitted_lo;
248     uint32_t total_unicast_packets_received_hi;
249     uint32_t total_unicast_packets_received_lo;
250     uint32_t total_multicast_packets_received_hi;
251     uint32_t total_multicast_packets_received_lo;
252     uint32_t total_broadcast_packets_received_hi;
253     uint32_t total_broadcast_packets_received_lo;
254     uint32_t total_unicast_packets_transmitted_hi;
255     uint32_t total_unicast_packets_transmitted_lo;
256     uint32_t total_multicast_packets_transmitted_hi;
257     uint32_t total_multicast_packets_transmitted_lo;
258     uint32_t total_broadcast_packets_transmitted_hi;
259     uint32_t total_broadcast_packets_transmitted_lo;
260     uint32_t valid_bytes_received_hi;
261     uint32_t valid_bytes_received_lo;
262
263     uint32_t etherstatsoverrsizepkts_hi;
264     uint32_t etherstatsoverrsizepkts_lo;
265     uint32_t no_buff_discard_hi;
266     uint32_t no_buff_discard_lo;
267
268     uint32_t total_packets_received_checksum_discarded_hi;
269     uint32_t total_packets_received_checksum_discarded_lo;
270     uint32_t total_packets_received_ttl0_discarded_hi;
271     uint32_t total_packets_received_ttl0_discarded_lo;
272     uint32_t total_transmitted_dropped_packets_error_hi;
273     uint32_t total_transmitted_dropped_packets_error_lo;
274
275     /* receive path driver statistics */
276     uint32_t rx_calls;
277     uint32_t rx_pkts;
278     uint32_t rx_soft_errors;
279     uint32_t rx_hw_csum_errors;
280     uint32_t rx_ofld_frames_csum_ip;
281     uint32_t rx_ofld_frames_csum_tcp_udp;
282     uint32_t rx_budget_reached;
283
284     /* tx path driver statistics */
285     uint32_t tx_pkts;
286     uint32_t tx_soft_errors;
287     uint32_t tx_ofld_frames_csum_ip;
288     uint32_t tx_ofld_frames_csum_tcp;
289     uint32_t tx_ofld_frames_csum_udp;
290     uint32_t tx_encap_failures;
291     uint32_t tx_hw_queue_full;
292     uint32_t tx_hw_max_queue_depth;
293     uint32_t tx_dma_mapping_failure;
294     uint32_t tx_max_drbr_queue_depth;
295     uint32_t tx_window_violation_std;
296     uint32_t tx_chain_lost_mbuf;
297     uint32_t tx_frames_deferred;
298     uint32_t tx_queue_xoff;
299
300     /* mbuf driver statistics */
301     uint32_t mbuf_defrag_attempts;
302     uint32_t mbuf_defrag_failures;
303     uint32_t mbuf_rx_bd_alloc_failed;
304     uint32_t mbuf_rx_bd_mapping_failed;
305
306     /* track the number of allocated mbufs */
307     uint32_t mbuf_alloc_tx;
308     uint32_t mbuf_alloc_rx;
309 };
310
311 struct bnx2x_eth_stats_old {
312     uint32_t rx_stat_dot3statsframestoolong_hi;
313     uint32_t rx_stat_dot3statsframestoolong_lo;
314 };
315
316 struct bnx2x_eth_q_stats_old {
317     /* Fields to perserve over fw reset*/
318     uint32_t total_unicast_bytes_received_hi;
319     uint32_t total_unicast_bytes_received_lo;
320     uint32_t total_broadcast_bytes_received_hi;
321     uint32_t total_broadcast_bytes_received_lo;
322     uint32_t total_multicast_bytes_received_hi;
323     uint32_t total_multicast_bytes_received_lo;
324     uint32_t total_unicast_bytes_transmitted_hi;
325     uint32_t total_unicast_bytes_transmitted_lo;
326     uint32_t total_broadcast_bytes_transmitted_hi;
327     uint32_t total_broadcast_bytes_transmitted_lo;
328     uint32_t total_multicast_bytes_transmitted_hi;
329     uint32_t total_multicast_bytes_transmitted_lo;
330
331     /* Fields to perserve last of */
332     uint32_t total_bytes_received_hi;
333     uint32_t total_bytes_received_lo;
334     uint32_t total_bytes_transmitted_hi;
335     uint32_t total_bytes_transmitted_lo;
336     uint32_t total_unicast_packets_received_hi;
337     uint32_t total_unicast_packets_received_lo;
338     uint32_t total_multicast_packets_received_hi;
339     uint32_t total_multicast_packets_received_lo;
340     uint32_t total_broadcast_packets_received_hi;
341     uint32_t total_broadcast_packets_received_lo;
342     uint32_t total_unicast_packets_transmitted_hi;
343     uint32_t total_unicast_packets_transmitted_lo;
344     uint32_t total_multicast_packets_transmitted_hi;
345     uint32_t total_multicast_packets_transmitted_lo;
346     uint32_t total_broadcast_packets_transmitted_hi;
347     uint32_t total_broadcast_packets_transmitted_lo;
348     uint32_t valid_bytes_received_hi;
349     uint32_t valid_bytes_received_lo;
350
351     /* receive path driver statistics */
352     uint32_t rx_calls_old;
353     uint32_t rx_pkts_old;
354     uint32_t rx_soft_errors_old;
355     uint32_t rx_hw_csum_errors_old;
356     uint32_t rx_ofld_frames_csum_ip_old;
357     uint32_t rx_ofld_frames_csum_tcp_udp_old;
358     uint32_t rx_budget_reached_old;
359
360     /* tx path driver statistics */
361     uint32_t tx_pkts_old;
362     uint32_t tx_soft_errors_old;
363     uint32_t tx_ofld_frames_csum_ip_old;
364     uint32_t tx_ofld_frames_csum_tcp_old;
365     uint32_t tx_ofld_frames_csum_udp_old;
366     uint32_t tx_encap_failures_old;
367     uint32_t tx_hw_queue_full_old;
368     uint32_t tx_hw_max_queue_depth_old;
369     uint32_t tx_dma_mapping_failure_old;
370     uint32_t tx_max_drbr_queue_depth_old;
371     uint32_t tx_window_violation_std_old;
372     uint32_t tx_chain_lost_mbuf_old;
373     uint32_t tx_frames_deferred_old;
374     uint32_t tx_queue_xoff_old;
375
376     /* mbuf driver statistics */
377     uint32_t mbuf_defrag_attempts_old;
378     uint32_t mbuf_defrag_failures_old;
379     uint32_t mbuf_rx_bd_alloc_failed_old;
380     uint32_t mbuf_rx_bd_mapping_failed_old;
381
382     /* track the number of allocated mbufs */
383     int mbuf_alloc_tx_old;
384     int mbuf_alloc_rx_old;
385 };
386
387 struct bnx2x_net_stats_old {
388     uint32_t rx_dropped;
389 };
390
391 struct bnx2x_fw_port_stats_old {
392     uint32_t pfc_frames_tx_hi;
393     uint32_t pfc_frames_tx_lo;
394     uint32_t pfc_frames_rx_hi;
395     uint32_t pfc_frames_rx_lo;
396
397     uint32_t mac_filter_discard;
398     uint32_t mf_tag_discard;
399     uint32_t brb_truncate_discard;
400     uint32_t mac_discard;
401 };
402
403 /* sum[hi:lo] += add[hi:lo] */
404 #define ADD_64(s_hi, a_hi, s_lo, a_lo)          \
405     do {                                        \
406         s_lo += a_lo;                           \
407         s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
408     } while (0)
409
410 #define LE32_0 ((uint32_t) 0)
411 #define LE16_0 ((uint16_t) 0)
412
413 /* The _force is for cases where high value is 0 */
414 #define ADD_64_LE(s_hi, a_hi_le, s_lo, a_lo_le) \
415         ADD_64(s_hi, le32toh(a_hi_le),          \
416                s_lo, le32toh(a_lo_le))
417
418 #define ADD_64_LE16(s_hi, a_hi_le, s_lo, a_lo_le) \
419         ADD_64(s_hi, le16toh(a_hi_le),            \
420                s_lo, le16toh(a_lo_le))
421
422 /* difference = minuend - subtrahend */
423 #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo)  \
424     do {                                             \
425         if (m_lo < s_lo) {                           \
426             /* underflow */                          \
427             d_hi = m_hi - s_hi;                      \
428             if (d_hi > 0) {                          \
429                 /* we can 'loan' 1 */                \
430                 d_hi--;                              \
431                 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
432             } else {                                 \
433                 /* m_hi <= s_hi */                   \
434                 d_hi = 0;                            \
435                 d_lo = 0;                            \
436             }                                        \
437         } else {                                     \
438             /* m_lo >= s_lo */                       \
439             if (m_hi < s_hi) {                       \
440                 d_hi = 0;                            \
441                 d_lo = 0;                            \
442             } else {                                 \
443                 /* m_hi >= s_hi */                   \
444                 d_hi = m_hi - s_hi;                  \
445                 d_lo = m_lo - s_lo;                  \
446             }                                        \
447         }                                            \
448     } while (0)
449
450 #define UPDATE_STAT64(s, t)                                      \
451     do {                                                         \
452         DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
453             diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo);    \
454         pstats->mac_stx[0].t##_hi = new->s##_hi;                 \
455         pstats->mac_stx[0].t##_lo = new->s##_lo;                 \
456         ADD_64(pstats->mac_stx[1].t##_hi, diff.hi,               \
457                pstats->mac_stx[1].t##_lo, diff.lo);              \
458     } while (0)
459
460 #define UPDATE_STAT64_NIG(s, t)                    \
461     do {                                           \
462         DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
463             diff.lo, new->s##_lo, old->s##_lo);    \
464         ADD_64(estats->t##_hi, diff.hi,            \
465                estats->t##_lo, diff.lo);           \
466     } while (0)
467
468 /* sum[hi:lo] += add */
469 #define ADD_EXTEND_64(s_hi, s_lo, a) \
470     do {                             \
471         s_lo += a;                   \
472         s_hi += (s_lo < a) ? 1 : 0;  \
473     } while (0)
474
475 #define ADD_STAT64(diff, t)                                \
476     do {                                                   \
477         ADD_64(pstats->mac_stx[1].t##_hi, new->diff##_hi,  \
478                pstats->mac_stx[1].t##_lo, new->diff##_lo); \
479     } while (0)
480
481 #define UPDATE_EXTEND_STAT(s)                    \
482     do {                                         \
483         ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
484                   pstats->mac_stx[1].s##_lo,     \
485                   new->s);                       \
486     } while (0)
487
488 #define UPDATE_EXTEND_TSTAT_X(s, t, size)                    \
489     do {                                                     \
490         diff = le##size##toh(tclient->s) -                   \
491                le##size##toh(old_tclient->s);                \
492         old_tclient->s = tclient->s;                         \
493         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
494     } while (0)
495
496 #define UPDATE_EXTEND_TSTAT(s, t) UPDATE_EXTEND_TSTAT_X(s, t, 32)
497
498 #define UPDATE_EXTEND_E_TSTAT(s, t, size)                    \
499     do {                                                     \
500         UPDATE_EXTEND_TSTAT_X(s, t, size);                   \
501         ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
502     } while (0)
503
504 #define UPDATE_EXTEND_USTAT(s, t)                             \
505     do {                                                      \
506         diff = le32toh(uclient->s) - le32toh(old_uclient->s); \
507         old_uclient->s = uclient->s;                          \
508         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
509     } while (0)
510
511 #define UPDATE_EXTEND_E_USTAT(s, t)                          \
512     do {                                                     \
513         UPDATE_EXTEND_USTAT(s, t);                           \
514         ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
515     } while (0)
516
517 #define UPDATE_EXTEND_XSTAT(s, t)                             \
518     do {                                                      \
519         diff = le32toh(xclient->s) - le32toh(old_xclient->s); \
520         old_xclient->s = xclient->s;                          \
521         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
522     } while (0)
523
524 #define UPDATE_QSTAT(s, t)                                   \
525     do {                                                     \
526         qstats->t##_hi = qstats_old->t##_hi + le32toh(s.hi); \
527         qstats->t##_lo = qstats_old->t##_lo + le32toh(s.lo); \
528     } while (0)
529
530 #define UPDATE_QSTAT_OLD(f)        \
531     do {                           \
532         qstats_old->f = qstats->f; \
533     } while (0)
534
535 #define UPDATE_ESTAT_QSTAT_64(s)                        \
536     do {                                                \
537         ADD_64(estats->s##_hi, qstats->s##_hi,          \
538                estats->s##_lo, qstats->s##_lo);         \
539         SUB_64(estats->s##_hi, qstats_old->s##_hi_old,  \
540                estats->s##_lo, qstats_old->s##_lo_old); \
541         qstats_old->s##_hi_old = qstats->s##_hi;        \
542         qstats_old->s##_lo_old = qstats->s##_lo;        \
543     } while (0)
544
545 #define UPDATE_ESTAT_QSTAT(s)             \
546     do {                                  \
547         estats->s += qstats->s;           \
548         estats->s -= qstats_old->s##_old; \
549         qstats_old->s##_old = qstats->s;  \
550     } while (0)
551
552 #define UPDATE_FSTAT_QSTAT(s)                       \
553     do {                                            \
554         ADD_64(fstats->s##_hi, qstats->s##_hi,      \
555                fstats->s##_lo, qstats->s##_lo);     \
556         SUB_64(fstats->s##_hi, qstats_old->s##_hi,  \
557                fstats->s##_lo, qstats_old->s##_lo); \
558         estats->s##_hi = fstats->s##_hi;            \
559         estats->s##_lo = fstats->s##_lo;            \
560         qstats_old->s##_hi = qstats->s##_hi;        \
561         qstats_old->s##_lo = qstats->s##_lo;        \
562     } while (0)
563
564 #define UPDATE_FW_STAT(s)                           \
565     do {                                            \
566         estats->s = le32toh(tport->s) + fwstats->s; \
567     } while (0)
568
569 #define UPDATE_FW_STAT_OLD(f)   \
570     do {                        \
571         fwstats->f = estats->f; \
572     } while (0)
573
574 #define UPDATE_ESTAT(s, t)                          \
575     do {                                            \
576         SUB_64(estats->s##_hi, estats_old->t##_hi,  \
577                estats->s##_lo, estats_old->t##_lo); \
578         ADD_64(estats->s##_hi, estats->t##_hi,      \
579                estats->s##_lo, estats->t##_lo);     \
580         estats_old->t##_hi = estats->t##_hi;        \
581         estats_old->t##_lo = estats->t##_lo;        \
582     } while (0)
583
584 /* minuend -= subtrahend */
585 #define SUB_64(m_hi, s_hi, m_lo, s_lo)               \
586     do {                                             \
587         DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
588     } while (0)
589
590 /* minuend[hi:lo] -= subtrahend */
591 #define SUB_EXTEND_64(m_hi, m_lo, s)    \
592     do {                                \
593         uint32_t s_hi = 0;              \
594         SUB_64(m_hi, s_hi, m_lo, s);    \
595     } while (0)
596
597 #define SUB_EXTEND_USTAT(s, t)                                \
598     do {                                                      \
599         diff = le32toh(uclient->s) - le32toh(old_uclient->s); \
600         SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
601     } while (0)
602
603 struct bnx2x_softc;
604 void bnx2x_stats_init(struct bnx2x_softc *sc);
605 void bnx2x_stats_handle(struct bnx2x_softc *sc, enum bnx2x_stats_event event);
606 void bnx2x_save_statistics(struct bnx2x_softc *sc);
607 void bnx2x_memset_stats(struct bnx2x_softc *sc);
608
609 #endif /* BNX2X_STATS_H */