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