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