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