]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/bxe/bxe_stats.h
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / sys / dev / bxe / bxe_stats.h
1 /*-
2  * Copyright (c) 2007-2013 Broadcom Corporation. All rights reserved.
3  *
4  * Eric Davis        <edavis@broadcom.com>
5  * David Christensen <davidch@broadcom.com>
6  * Gary Zambrano     <zambrano@broadcom.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of Broadcom Corporation nor the name of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written consent.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef BXE_STATS_H
35 #define BXE_STATS_H
36
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39
40 #include <sys/types.h>
41
42 struct nig_stats {
43     uint32_t brb_discard;
44     uint32_t brb_packet;
45     uint32_t brb_truncate;
46     uint32_t flow_ctrl_discard;
47     uint32_t flow_ctrl_octets;
48     uint32_t flow_ctrl_packet;
49     uint32_t mng_discard;
50     uint32_t mng_octet_inp;
51     uint32_t mng_octet_out;
52     uint32_t mng_packet_inp;
53     uint32_t mng_packet_out;
54     uint32_t pbf_octets;
55     uint32_t pbf_packet;
56     uint32_t safc_inp;
57     uint32_t egress_mac_pkt0_lo;
58     uint32_t egress_mac_pkt0_hi;
59     uint32_t egress_mac_pkt1_lo;
60     uint32_t egress_mac_pkt1_hi;
61 };
62
63
64 enum bxe_stats_event {
65     STATS_EVENT_PMF = 0,
66     STATS_EVENT_LINK_UP,
67     STATS_EVENT_UPDATE,
68     STATS_EVENT_STOP,
69     STATS_EVENT_MAX
70 };
71
72 enum bxe_stats_state {
73     STATS_STATE_DISABLED = 0,
74     STATS_STATE_ENABLED,
75     STATS_STATE_MAX
76 };
77
78 struct bxe_eth_stats {
79     uint32_t total_bytes_received_hi;
80     uint32_t total_bytes_received_lo;
81     uint32_t total_bytes_transmitted_hi;
82     uint32_t total_bytes_transmitted_lo;
83     uint32_t total_unicast_packets_received_hi;
84     uint32_t total_unicast_packets_received_lo;
85     uint32_t total_multicast_packets_received_hi;
86     uint32_t total_multicast_packets_received_lo;
87     uint32_t total_broadcast_packets_received_hi;
88     uint32_t total_broadcast_packets_received_lo;
89     uint32_t total_unicast_packets_transmitted_hi;
90     uint32_t total_unicast_packets_transmitted_lo;
91     uint32_t total_multicast_packets_transmitted_hi;
92     uint32_t total_multicast_packets_transmitted_lo;
93     uint32_t total_broadcast_packets_transmitted_hi;
94     uint32_t total_broadcast_packets_transmitted_lo;
95     uint32_t valid_bytes_received_hi;
96     uint32_t valid_bytes_received_lo;
97
98     uint32_t error_bytes_received_hi;
99     uint32_t error_bytes_received_lo;
100     uint32_t etherstatsoverrsizepkts_hi;
101     uint32_t etherstatsoverrsizepkts_lo;
102     uint32_t no_buff_discard_hi;
103     uint32_t no_buff_discard_lo;
104
105     uint32_t rx_stat_ifhcinbadoctets_hi;
106     uint32_t rx_stat_ifhcinbadoctets_lo;
107     uint32_t tx_stat_ifhcoutbadoctets_hi;
108     uint32_t tx_stat_ifhcoutbadoctets_lo;
109     uint32_t rx_stat_dot3statsfcserrors_hi;
110     uint32_t rx_stat_dot3statsfcserrors_lo;
111     uint32_t rx_stat_dot3statsalignmenterrors_hi;
112     uint32_t rx_stat_dot3statsalignmenterrors_lo;
113     uint32_t rx_stat_dot3statscarriersenseerrors_hi;
114     uint32_t rx_stat_dot3statscarriersenseerrors_lo;
115     uint32_t rx_stat_falsecarriererrors_hi;
116     uint32_t rx_stat_falsecarriererrors_lo;
117     uint32_t rx_stat_etherstatsundersizepkts_hi;
118     uint32_t rx_stat_etherstatsundersizepkts_lo;
119     uint32_t rx_stat_dot3statsframestoolong_hi;
120     uint32_t rx_stat_dot3statsframestoolong_lo;
121     uint32_t rx_stat_etherstatsfragments_hi;
122     uint32_t rx_stat_etherstatsfragments_lo;
123     uint32_t rx_stat_etherstatsjabbers_hi;
124     uint32_t rx_stat_etherstatsjabbers_lo;
125     uint32_t rx_stat_maccontrolframesreceived_hi;
126     uint32_t rx_stat_maccontrolframesreceived_lo;
127     uint32_t rx_stat_bmac_xpf_hi;
128     uint32_t rx_stat_bmac_xpf_lo;
129     uint32_t rx_stat_bmac_xcf_hi;
130     uint32_t rx_stat_bmac_xcf_lo;
131     uint32_t rx_stat_xoffstateentered_hi;
132     uint32_t rx_stat_xoffstateentered_lo;
133     uint32_t rx_stat_xonpauseframesreceived_hi;
134     uint32_t rx_stat_xonpauseframesreceived_lo;
135     uint32_t rx_stat_xoffpauseframesreceived_hi;
136     uint32_t rx_stat_xoffpauseframesreceived_lo;
137     uint32_t tx_stat_outxonsent_hi;
138     uint32_t tx_stat_outxonsent_lo;
139     uint32_t tx_stat_outxoffsent_hi;
140     uint32_t tx_stat_outxoffsent_lo;
141     uint32_t tx_stat_flowcontroldone_hi;
142     uint32_t tx_stat_flowcontroldone_lo;
143     uint32_t tx_stat_etherstatscollisions_hi;
144     uint32_t tx_stat_etherstatscollisions_lo;
145     uint32_t tx_stat_dot3statssinglecollisionframes_hi;
146     uint32_t tx_stat_dot3statssinglecollisionframes_lo;
147     uint32_t tx_stat_dot3statsmultiplecollisionframes_hi;
148     uint32_t tx_stat_dot3statsmultiplecollisionframes_lo;
149     uint32_t tx_stat_dot3statsdeferredtransmissions_hi;
150     uint32_t tx_stat_dot3statsdeferredtransmissions_lo;
151     uint32_t tx_stat_dot3statsexcessivecollisions_hi;
152     uint32_t tx_stat_dot3statsexcessivecollisions_lo;
153     uint32_t tx_stat_dot3statslatecollisions_hi;
154     uint32_t tx_stat_dot3statslatecollisions_lo;
155     uint32_t tx_stat_etherstatspkts64octets_hi;
156     uint32_t tx_stat_etherstatspkts64octets_lo;
157     uint32_t tx_stat_etherstatspkts65octetsto127octets_hi;
158     uint32_t tx_stat_etherstatspkts65octetsto127octets_lo;
159     uint32_t tx_stat_etherstatspkts128octetsto255octets_hi;
160     uint32_t tx_stat_etherstatspkts128octetsto255octets_lo;
161     uint32_t tx_stat_etherstatspkts256octetsto511octets_hi;
162     uint32_t tx_stat_etherstatspkts256octetsto511octets_lo;
163     uint32_t tx_stat_etherstatspkts512octetsto1023octets_hi;
164     uint32_t tx_stat_etherstatspkts512octetsto1023octets_lo;
165     uint32_t tx_stat_etherstatspkts1024octetsto1522octets_hi;
166     uint32_t tx_stat_etherstatspkts1024octetsto1522octets_lo;
167     uint32_t tx_stat_etherstatspktsover1522octets_hi;
168     uint32_t tx_stat_etherstatspktsover1522octets_lo;
169     uint32_t tx_stat_bmac_2047_hi;
170     uint32_t tx_stat_bmac_2047_lo;
171     uint32_t tx_stat_bmac_4095_hi;
172     uint32_t tx_stat_bmac_4095_lo;
173     uint32_t tx_stat_bmac_9216_hi;
174     uint32_t tx_stat_bmac_9216_lo;
175     uint32_t tx_stat_bmac_16383_hi;
176     uint32_t tx_stat_bmac_16383_lo;
177     uint32_t tx_stat_dot3statsinternalmactransmiterrors_hi;
178     uint32_t tx_stat_dot3statsinternalmactransmiterrors_lo;
179     uint32_t tx_stat_bmac_ufl_hi;
180     uint32_t tx_stat_bmac_ufl_lo;
181
182     uint32_t pause_frames_received_hi;
183     uint32_t pause_frames_received_lo;
184     uint32_t pause_frames_sent_hi;
185     uint32_t pause_frames_sent_lo;
186
187     uint32_t etherstatspkts1024octetsto1522octets_hi;
188     uint32_t etherstatspkts1024octetsto1522octets_lo;
189     uint32_t etherstatspktsover1522octets_hi;
190     uint32_t etherstatspktsover1522octets_lo;
191
192     uint32_t brb_drop_hi;
193     uint32_t brb_drop_lo;
194     uint32_t brb_truncate_hi;
195     uint32_t brb_truncate_lo;
196
197     uint32_t mac_filter_discard;
198     uint32_t mf_tag_discard;
199     uint32_t brb_truncate_discard;
200     uint32_t mac_discard;
201
202     uint32_t nig_timer_max;
203
204     uint32_t total_tpa_aggregations_hi;
205     uint32_t total_tpa_aggregations_lo;
206     uint32_t total_tpa_aggregated_frames_hi;
207     uint32_t total_tpa_aggregated_frames_lo;
208     uint32_t total_tpa_bytes_hi;
209     uint32_t total_tpa_bytes_lo;
210
211     /* PFC */
212     uint32_t pfc_frames_received_hi;
213     uint32_t pfc_frames_received_lo;
214     uint32_t pfc_frames_sent_hi;
215     uint32_t pfc_frames_sent_lo;
216
217     /* Recovery */
218     uint32_t recoverable_error;
219     uint32_t unrecoverable_error;
220
221     /* src: Clear-on-Read register; Will not survive PMF Migration */
222     uint32_t eee_tx_lpi;
223
224     /* receive path driver statistics */
225     uint32_t rx_calls;
226     uint32_t rx_pkts;
227     uint32_t rx_tpa_pkts;
228     uint32_t rx_soft_errors;
229     uint32_t rx_hw_csum_errors;
230     uint32_t rx_ofld_frames_csum_ip;
231     uint32_t rx_ofld_frames_csum_tcp_udp;
232     uint32_t rx_budget_reached;
233
234     /* tx path driver statistics */
235     uint32_t tx_pkts;
236     uint32_t tx_soft_errors;
237     uint32_t tx_ofld_frames_csum_ip;
238     uint32_t tx_ofld_frames_csum_tcp;
239     uint32_t tx_ofld_frames_csum_udp;
240     uint32_t tx_ofld_frames_lso;
241     uint32_t tx_ofld_frames_lso_hdr_splits;
242     uint32_t tx_encap_failures;
243     uint32_t tx_hw_queue_full;
244     uint32_t tx_hw_max_queue_depth;
245     uint32_t tx_dma_mapping_failure;
246     uint32_t tx_max_drbr_queue_depth;
247     uint32_t tx_window_violation_std;
248     uint32_t tx_window_violation_tso;
249     //uint32_t tx_unsupported_tso_request_ipv6;
250     //uint32_t tx_unsupported_tso_request_not_tcp;
251     uint32_t tx_chain_lost_mbuf;
252     uint32_t tx_frames_deferred;
253     uint32_t tx_queue_xoff;
254
255     /* mbuf driver statistics */
256     uint32_t mbuf_defrag_attempts;
257     uint32_t mbuf_defrag_failures;
258     uint32_t mbuf_rx_bd_alloc_failed;
259     uint32_t mbuf_rx_bd_mapping_failed;
260     uint32_t mbuf_rx_tpa_alloc_failed;
261     uint32_t mbuf_rx_tpa_mapping_failed;
262     uint32_t mbuf_rx_sge_alloc_failed;
263     uint32_t mbuf_rx_sge_mapping_failed;
264
265     /* track the number of allocated mbufs */
266     uint32_t mbuf_alloc_tx;
267     uint32_t mbuf_alloc_rx;
268     uint32_t mbuf_alloc_sge;
269     uint32_t mbuf_alloc_tpa;
270 };
271
272
273 struct bxe_eth_q_stats {
274     uint32_t total_unicast_bytes_received_hi;
275     uint32_t total_unicast_bytes_received_lo;
276     uint32_t total_broadcast_bytes_received_hi;
277     uint32_t total_broadcast_bytes_received_lo;
278     uint32_t total_multicast_bytes_received_hi;
279     uint32_t total_multicast_bytes_received_lo;
280     uint32_t total_bytes_received_hi;
281     uint32_t total_bytes_received_lo;
282     uint32_t total_unicast_bytes_transmitted_hi;
283     uint32_t total_unicast_bytes_transmitted_lo;
284     uint32_t total_broadcast_bytes_transmitted_hi;
285     uint32_t total_broadcast_bytes_transmitted_lo;
286     uint32_t total_multicast_bytes_transmitted_hi;
287     uint32_t total_multicast_bytes_transmitted_lo;
288     uint32_t total_bytes_transmitted_hi;
289     uint32_t total_bytes_transmitted_lo;
290     uint32_t total_unicast_packets_received_hi;
291     uint32_t total_unicast_packets_received_lo;
292     uint32_t total_multicast_packets_received_hi;
293     uint32_t total_multicast_packets_received_lo;
294     uint32_t total_broadcast_packets_received_hi;
295     uint32_t total_broadcast_packets_received_lo;
296     uint32_t total_unicast_packets_transmitted_hi;
297     uint32_t total_unicast_packets_transmitted_lo;
298     uint32_t total_multicast_packets_transmitted_hi;
299     uint32_t total_multicast_packets_transmitted_lo;
300     uint32_t total_broadcast_packets_transmitted_hi;
301     uint32_t total_broadcast_packets_transmitted_lo;
302     uint32_t valid_bytes_received_hi;
303     uint32_t valid_bytes_received_lo;
304
305     uint32_t etherstatsoverrsizepkts_hi;
306     uint32_t etherstatsoverrsizepkts_lo;
307     uint32_t no_buff_discard_hi;
308     uint32_t no_buff_discard_lo;
309
310     uint32_t total_packets_received_checksum_discarded_hi;
311     uint32_t total_packets_received_checksum_discarded_lo;
312     uint32_t total_packets_received_ttl0_discarded_hi;
313     uint32_t total_packets_received_ttl0_discarded_lo;
314     uint32_t total_transmitted_dropped_packets_error_hi;
315     uint32_t total_transmitted_dropped_packets_error_lo;
316
317     uint32_t total_tpa_aggregations_hi;
318     uint32_t total_tpa_aggregations_lo;
319     uint32_t total_tpa_aggregated_frames_hi;
320     uint32_t total_tpa_aggregated_frames_lo;
321     uint32_t total_tpa_bytes_hi;
322     uint32_t total_tpa_bytes_lo;
323
324     /* receive path driver statistics */
325     uint32_t rx_calls;
326     uint32_t rx_pkts;
327     uint32_t rx_tpa_pkts;
328     uint32_t rx_soft_errors;
329     uint32_t rx_hw_csum_errors;
330     uint32_t rx_ofld_frames_csum_ip;
331     uint32_t rx_ofld_frames_csum_tcp_udp;
332     uint32_t rx_budget_reached;
333
334     /* tx path driver statistics */
335     uint32_t tx_pkts;
336     uint32_t tx_soft_errors;
337     uint32_t tx_ofld_frames_csum_ip;
338     uint32_t tx_ofld_frames_csum_tcp;
339     uint32_t tx_ofld_frames_csum_udp;
340     uint32_t tx_ofld_frames_lso;
341     uint32_t tx_ofld_frames_lso_hdr_splits;
342     uint32_t tx_encap_failures;
343     uint32_t tx_hw_queue_full;
344     uint32_t tx_hw_max_queue_depth;
345     uint32_t tx_dma_mapping_failure;
346     uint32_t tx_max_drbr_queue_depth;
347     uint32_t tx_window_violation_std;
348     uint32_t tx_window_violation_tso;
349     //uint32_t tx_unsupported_tso_request_ipv6;
350     //uint32_t tx_unsupported_tso_request_not_tcp;
351     uint32_t tx_chain_lost_mbuf;
352     uint32_t tx_frames_deferred;
353     uint32_t tx_queue_xoff;
354
355     /* mbuf driver statistics */
356     uint32_t mbuf_defrag_attempts;
357     uint32_t mbuf_defrag_failures;
358     uint32_t mbuf_rx_bd_alloc_failed;
359     uint32_t mbuf_rx_bd_mapping_failed;
360     uint32_t mbuf_rx_tpa_alloc_failed;
361     uint32_t mbuf_rx_tpa_mapping_failed;
362     uint32_t mbuf_rx_sge_alloc_failed;
363     uint32_t mbuf_rx_sge_mapping_failed;
364
365     /* track the number of allocated mbufs */
366     uint32_t mbuf_alloc_tx;
367     uint32_t mbuf_alloc_rx;
368     uint32_t mbuf_alloc_sge;
369     uint32_t mbuf_alloc_tpa;
370 };
371
372 struct bxe_eth_stats_old {
373     uint32_t rx_stat_dot3statsframestoolong_hi;
374     uint32_t rx_stat_dot3statsframestoolong_lo;
375 };
376
377 struct bxe_eth_q_stats_old {
378     /* Fields to perserve over fw reset*/
379     uint32_t total_unicast_bytes_received_hi;
380     uint32_t total_unicast_bytes_received_lo;
381     uint32_t total_broadcast_bytes_received_hi;
382     uint32_t total_broadcast_bytes_received_lo;
383     uint32_t total_multicast_bytes_received_hi;
384     uint32_t total_multicast_bytes_received_lo;
385     uint32_t total_unicast_bytes_transmitted_hi;
386     uint32_t total_unicast_bytes_transmitted_lo;
387     uint32_t total_broadcast_bytes_transmitted_hi;
388     uint32_t total_broadcast_bytes_transmitted_lo;
389     uint32_t total_multicast_bytes_transmitted_hi;
390     uint32_t total_multicast_bytes_transmitted_lo;
391     uint32_t total_tpa_bytes_hi;
392     uint32_t total_tpa_bytes_lo;
393
394     /* Fields to perserve last of */
395     uint32_t total_bytes_received_hi;
396     uint32_t total_bytes_received_lo;
397     uint32_t total_bytes_transmitted_hi;
398     uint32_t total_bytes_transmitted_lo;
399     uint32_t total_unicast_packets_received_hi;
400     uint32_t total_unicast_packets_received_lo;
401     uint32_t total_multicast_packets_received_hi;
402     uint32_t total_multicast_packets_received_lo;
403     uint32_t total_broadcast_packets_received_hi;
404     uint32_t total_broadcast_packets_received_lo;
405     uint32_t total_unicast_packets_transmitted_hi;
406     uint32_t total_unicast_packets_transmitted_lo;
407     uint32_t total_multicast_packets_transmitted_hi;
408     uint32_t total_multicast_packets_transmitted_lo;
409     uint32_t total_broadcast_packets_transmitted_hi;
410     uint32_t total_broadcast_packets_transmitted_lo;
411     uint32_t valid_bytes_received_hi;
412     uint32_t valid_bytes_received_lo;
413
414     uint32_t total_tpa_bytes_hi_old;
415     uint32_t total_tpa_bytes_lo_old;
416
417     /* receive path driver statistics */
418     uint32_t rx_calls_old;
419     uint32_t rx_pkts_old;
420     uint32_t rx_tpa_pkts_old;
421     uint32_t rx_soft_errors_old;
422     uint32_t rx_hw_csum_errors_old;
423     uint32_t rx_ofld_frames_csum_ip_old;
424     uint32_t rx_ofld_frames_csum_tcp_udp_old;
425     uint32_t rx_budget_reached_old;
426
427     /* tx path driver statistics */
428     uint32_t tx_pkts_old;
429     uint32_t tx_soft_errors_old;
430     uint32_t tx_ofld_frames_csum_ip_old;
431     uint32_t tx_ofld_frames_csum_tcp_old;
432     uint32_t tx_ofld_frames_csum_udp_old;
433     uint32_t tx_ofld_frames_lso_old;
434     uint32_t tx_ofld_frames_lso_hdr_splits_old;
435     uint32_t tx_encap_failures_old;
436     uint32_t tx_hw_queue_full_old;
437     uint32_t tx_hw_max_queue_depth_old;
438     uint32_t tx_dma_mapping_failure_old;
439     uint32_t tx_max_drbr_queue_depth_old;
440     uint32_t tx_window_violation_std_old;
441     uint32_t tx_window_violation_tso_old;
442     //uint32_t tx_unsupported_tso_request_ipv6_old;
443     //uint32_t tx_unsupported_tso_request_not_tcp_old;
444     uint32_t tx_chain_lost_mbuf_old;
445     uint32_t tx_frames_deferred_old;
446     uint32_t tx_queue_xoff_old;
447
448     /* mbuf driver statistics */
449     uint32_t mbuf_defrag_attempts_old;
450     uint32_t mbuf_defrag_failures_old;
451     uint32_t mbuf_rx_bd_alloc_failed_old;
452     uint32_t mbuf_rx_bd_mapping_failed_old;
453     uint32_t mbuf_rx_tpa_alloc_failed_old;
454     uint32_t mbuf_rx_tpa_mapping_failed_old;
455     uint32_t mbuf_rx_sge_alloc_failed_old;
456     uint32_t mbuf_rx_sge_mapping_failed_old;
457
458     /* track the number of allocated mbufs */
459     int mbuf_alloc_tx_old;
460     int mbuf_alloc_rx_old;
461     int mbuf_alloc_sge_old;
462     int mbuf_alloc_tpa_old;
463 };
464
465 struct bxe_net_stats_old {
466     uint32_t rx_dropped;
467 };
468
469 struct bxe_fw_port_stats_old {
470     uint32_t pfc_frames_tx_hi;
471     uint32_t pfc_frames_tx_lo;
472     uint32_t pfc_frames_rx_hi;
473     uint32_t pfc_frames_rx_lo;
474
475     uint32_t mac_filter_discard;
476     uint32_t mf_tag_discard;
477     uint32_t brb_truncate_discard;
478     uint32_t mac_discard;
479 };
480
481 /* sum[hi:lo] += add[hi:lo] */
482 #define ADD_64(s_hi, a_hi, s_lo, a_lo)          \
483     do {                                        \
484         s_lo += a_lo;                           \
485         s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
486     } while (0)
487
488 #define LE32_0 ((uint32_t) 0)
489 #define LE16_0 ((uint16_t) 0)
490
491 /* The _force is for cases where high value is 0 */
492 #define ADD_64_LE(s_hi, a_hi_le, s_lo, a_lo_le) \
493         ADD_64(s_hi, le32toh(a_hi_le),          \
494                s_lo, le32toh(a_lo_le))
495
496 #define ADD_64_LE16(s_hi, a_hi_le, s_lo, a_lo_le) \
497         ADD_64(s_hi, le16toh(a_hi_le),            \
498                s_lo, le16toh(a_lo_le))
499
500 /* difference = minuend - subtrahend */
501 #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo)  \
502     do {                                             \
503         if (m_lo < s_lo) {                           \
504             /* underflow */                          \
505             d_hi = m_hi - s_hi;                      \
506             if (d_hi > 0) {                          \
507                 /* we can 'loan' 1 */                \
508                 d_hi--;                              \
509                 d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
510             } else {                                 \
511                 /* m_hi <= s_hi */                   \
512                 d_hi = 0;                            \
513                 d_lo = 0;                            \
514             }                                        \
515         } else {                                     \
516             /* m_lo >= s_lo */                       \
517             if (m_hi < s_hi) {                       \
518                 d_hi = 0;                            \
519                 d_lo = 0;                            \
520             } else {                                 \
521                 /* m_hi >= s_hi */                   \
522                 d_hi = m_hi - s_hi;                  \
523                 d_lo = m_lo - s_lo;                  \
524             }                                        \
525         }                                            \
526     } while (0)
527
528 #define UPDATE_STAT64(s, t)                                      \
529     do {                                                         \
530         DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
531             diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo);    \
532         pstats->mac_stx[0].t##_hi = new->s##_hi;                 \
533         pstats->mac_stx[0].t##_lo = new->s##_lo;                 \
534         ADD_64(pstats->mac_stx[1].t##_hi, diff.hi,               \
535                pstats->mac_stx[1].t##_lo, diff.lo);              \
536     } while (0)
537
538 #define UPDATE_STAT64_NIG(s, t)                    \
539     do {                                           \
540         DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
541             diff.lo, new->s##_lo, old->s##_lo);    \
542         ADD_64(estats->t##_hi, diff.hi,            \
543                estats->t##_lo, diff.lo);           \
544     } while (0)
545
546 /* sum[hi:lo] += add */
547 #define ADD_EXTEND_64(s_hi, s_lo, a) \
548     do {                             \
549         s_lo += a;                   \
550         s_hi += (s_lo < a) ? 1 : 0;  \
551     } while (0)
552
553 #define ADD_STAT64(diff, t)                                \
554     do {                                                   \
555         ADD_64(pstats->mac_stx[1].t##_hi, new->diff##_hi,  \
556                pstats->mac_stx[1].t##_lo, new->diff##_lo); \
557     } while (0)
558
559 #define UPDATE_EXTEND_STAT(s)                    \
560     do {                                         \
561         ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
562                   pstats->mac_stx[1].s##_lo,     \
563                   new->s);                       \
564     } while (0)
565
566 #define UPDATE_EXTEND_TSTAT_X(s, t, size)                    \
567     do {                                                     \
568         diff = le##size##toh(tclient->s) -                   \
569                le##size##toh(old_tclient->s);                \
570         old_tclient->s = tclient->s;                         \
571         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
572     } while (0)
573
574 #define UPDATE_EXTEND_TSTAT(s, t) UPDATE_EXTEND_TSTAT_X(s, t, 32)
575
576 #define UPDATE_EXTEND_E_TSTAT(s, t, size)                    \
577     do {                                                     \
578         UPDATE_EXTEND_TSTAT_X(s, t, size);                   \
579         ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
580     } while (0)
581
582 #define UPDATE_EXTEND_USTAT(s, t)                             \
583     do {                                                      \
584         diff = le32toh(uclient->s) - le32toh(old_uclient->s); \
585         old_uclient->s = uclient->s;                          \
586         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
587     } while (0)
588
589 #define UPDATE_EXTEND_E_USTAT(s, t)                          \
590     do {                                                     \
591         UPDATE_EXTEND_USTAT(s, t);                           \
592         ADD_EXTEND_64(estats->t##_hi, estats->t##_lo, diff); \
593     } while (0)
594
595 #define UPDATE_EXTEND_XSTAT(s, t)                             \
596     do {                                                      \
597         diff = le32toh(xclient->s) - le32toh(old_xclient->s); \
598         old_xclient->s = xclient->s;                          \
599         ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
600     } while (0)
601
602 #define UPDATE_QSTAT(s, t)                                   \
603     do {                                                     \
604         qstats->t##_hi = qstats_old->t##_hi + le32toh(s.hi); \
605         qstats->t##_lo = qstats_old->t##_lo + le32toh(s.lo); \
606     } while (0)
607
608 #define UPDATE_QSTAT_OLD(f)        \
609     do {                           \
610         qstats_old->f = qstats->f; \
611     } while (0)
612
613 #define UPDATE_ESTAT_QSTAT_64(s)                        \
614     do {                                                \
615         ADD_64(estats->s##_hi, qstats->s##_hi,          \
616                estats->s##_lo, qstats->s##_lo);         \
617         SUB_64(estats->s##_hi, qstats_old->s##_hi_old,  \
618                estats->s##_lo, qstats_old->s##_lo_old); \
619         qstats_old->s##_hi_old = qstats->s##_hi;        \
620         qstats_old->s##_lo_old = qstats->s##_lo;        \
621     } while (0)
622
623 #define UPDATE_ESTAT_QSTAT(s)             \
624     do {                                  \
625         estats->s += qstats->s;           \
626         estats->s -= qstats_old->s##_old; \
627         qstats_old->s##_old = qstats->s;  \
628     } while (0)
629
630 #define UPDATE_FSTAT_QSTAT(s)                       \
631     do {                                            \
632         ADD_64(fstats->s##_hi, qstats->s##_hi,      \
633                fstats->s##_lo, qstats->s##_lo);     \
634         SUB_64(fstats->s##_hi, qstats_old->s##_hi,  \
635                fstats->s##_lo, qstats_old->s##_lo); \
636         estats->s##_hi = fstats->s##_hi;            \
637         estats->s##_lo = fstats->s##_lo;            \
638         qstats_old->s##_hi = qstats->s##_hi;        \
639         qstats_old->s##_lo = qstats->s##_lo;        \
640     } while (0)
641
642 #define UPDATE_FW_STAT(s)                           \
643     do {                                            \
644         estats->s = le32toh(tport->s) + fwstats->s; \
645     } while (0)
646
647 #define UPDATE_FW_STAT_OLD(f)   \
648     do {                        \
649         fwstats->f = estats->f; \
650     } while (0)
651
652 #define UPDATE_ESTAT(s, t)                          \
653     do {                                            \
654         SUB_64(estats->s##_hi, estats_old->t##_hi,  \
655                estats->s##_lo, estats_old->t##_lo); \
656         ADD_64(estats->s##_hi, estats->t##_hi,      \
657                estats->s##_lo, estats->t##_lo);     \
658         estats_old->t##_hi = estats->t##_hi;        \
659         estats_old->t##_lo = estats->t##_lo;        \
660     } while (0)
661
662 /* minuend -= subtrahend */
663 #define SUB_64(m_hi, s_hi, m_lo, s_lo)               \
664     do {                                             \
665         DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
666     } while (0)
667
668 /* minuend[hi:lo] -= subtrahend */
669 #define SUB_EXTEND_64(m_hi, m_lo, s) \
670     do {                             \
671         SUB_64(m_hi, 0, m_lo, s);    \
672     } while (0)
673
674 #define SUB_EXTEND_USTAT(s, t)                                \
675     do {                                                      \
676         diff = le32toh(uclient->s) - le32toh(old_uclient->s); \
677         SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff);  \
678     } while (0)
679
680 struct bxe_softc;
681 void bxe_stats_init(struct bxe_softc *sc);
682 void bxe_stats_handle(struct bxe_softc *sc, enum bxe_stats_event event);
683 void bxe_save_statistics(struct bxe_softc *sc);
684 void bxe_afex_collect_stats(struct bxe_softc *sc, void *void_afex_stats, uint32_t stats_type);
685
686 #endif /* BXE_STATS_H */
687