6afd11adb2c18ed6fd01a1d37e9eaed6970d0da3
[dpdk.git] / drivers / net / bnxt / bnxt_stats.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5
6 #include <inttypes.h>
7
8 #include <rte_string_fns.h>
9 #include <rte_byteorder.h>
10
11 #include "bnxt.h"
12 #include "bnxt_cpr.h"
13 #include "bnxt_hwrm.h"
14 #include "bnxt_rxq.h"
15 #include "bnxt_stats.h"
16 #include "bnxt_txq.h"
17 #include "hsi_struct_def_dpdk.h"
18
19 static const struct bnxt_xstats_name_off bnxt_rx_stats_strings[] = {
20         {"rx_64b_frames", offsetof(struct rx_port_stats,
21                                 rx_64b_frames)},
22         {"rx_65b_127b_frames", offsetof(struct rx_port_stats,
23                                 rx_65b_127b_frames)},
24         {"rx_128b_255b_frames", offsetof(struct rx_port_stats,
25                                 rx_128b_255b_frames)},
26         {"rx_256b_511b_frames", offsetof(struct rx_port_stats,
27                                 rx_256b_511b_frames)},
28         {"rx_512b_1023b_frames", offsetof(struct rx_port_stats,
29                                 rx_512b_1023b_frames)},
30         {"rx_1024b_1518b_frames", offsetof(struct rx_port_stats,
31                                 rx_1024b_1518b_frames)},
32         {"rx_good_vlan_frames", offsetof(struct rx_port_stats,
33                                 rx_good_vlan_frames)},
34         {"rx_1519b_2047b_frames", offsetof(struct rx_port_stats,
35                                 rx_1519b_2047b_frames)},
36         {"rx_2048b_4095b_frames", offsetof(struct rx_port_stats,
37                                 rx_2048b_4095b_frames)},
38         {"rx_4096b_9216b_frames", offsetof(struct rx_port_stats,
39                                 rx_4096b_9216b_frames)},
40         {"rx_9217b_16383b_frames", offsetof(struct rx_port_stats,
41                                 rx_9217b_16383b_frames)},
42         {"rx_total_frames", offsetof(struct rx_port_stats,
43                                 rx_total_frames)},
44         {"rx_ucast_frames", offsetof(struct rx_port_stats,
45                                 rx_ucast_frames)},
46         {"rx_mcast_frames", offsetof(struct rx_port_stats,
47                                 rx_mcast_frames)},
48         {"rx_bcast_frames", offsetof(struct rx_port_stats,
49                                 rx_bcast_frames)},
50         {"rx_fcs_err_frames", offsetof(struct rx_port_stats,
51                                 rx_fcs_err_frames)},
52         {"rx_ctrl_frames", offsetof(struct rx_port_stats,
53                                 rx_ctrl_frames)},
54         {"rx_pause_frames", offsetof(struct rx_port_stats,
55                                 rx_pause_frames)},
56         {"rx_pfc_frames", offsetof(struct rx_port_stats,
57                                 rx_pfc_frames)},
58         {"rx_unsupported_opcode_frames", offsetof(struct rx_port_stats,
59                                 rx_unsupported_opcode_frames)},
60         {"rx_unsupported_da_pausepfc_frames", offsetof(struct rx_port_stats,
61                                 rx_unsupported_da_pausepfc_frames)},
62         {"rx_wrong_sa_frames", offsetof(struct rx_port_stats,
63                                 rx_wrong_sa_frames)},
64         {"rx_align_err_frames", offsetof(struct rx_port_stats,
65                                 rx_align_err_frames)},
66         {"rx_oor_len_frames", offsetof(struct rx_port_stats,
67                                 rx_oor_len_frames)},
68         {"rx_code_err_frames", offsetof(struct rx_port_stats,
69                                 rx_code_err_frames)},
70         {"rx_false_carrier_frames", offsetof(struct rx_port_stats,
71                                 rx_false_carrier_frames)},
72         {"rx_ovrsz_frames", offsetof(struct rx_port_stats,
73                                 rx_ovrsz_frames)},
74         {"rx_jbr_frames", offsetof(struct rx_port_stats,
75                                 rx_jbr_frames)},
76         {"rx_mtu_err_frames", offsetof(struct rx_port_stats,
77                                 rx_mtu_err_frames)},
78         {"rx_match_crc_frames", offsetof(struct rx_port_stats,
79                                 rx_match_crc_frames)},
80         {"rx_promiscuous_frames", offsetof(struct rx_port_stats,
81                                 rx_promiscuous_frames)},
82         {"rx_tagged_frames", offsetof(struct rx_port_stats,
83                                 rx_tagged_frames)},
84         {"rx_double_tagged_frames", offsetof(struct rx_port_stats,
85                                 rx_double_tagged_frames)},
86         {"rx_trunc_frames", offsetof(struct rx_port_stats,
87                                 rx_trunc_frames)},
88         {"rx_good_frames", offsetof(struct rx_port_stats,
89                                 rx_good_frames)},
90         {"rx_sch_crc_err_frames", offsetof(struct rx_port_stats,
91                                 rx_sch_crc_err_frames)},
92         {"rx_undrsz_frames", offsetof(struct rx_port_stats,
93                                 rx_undrsz_frames)},
94         {"rx_frag_frames", offsetof(struct rx_port_stats,
95                                 rx_frag_frames)},
96         {"rx_eee_lpi_events", offsetof(struct rx_port_stats,
97                                 rx_eee_lpi_events)},
98         {"rx_eee_lpi_duration", offsetof(struct rx_port_stats,
99                                 rx_eee_lpi_duration)},
100         {"rx_llfc_physical_msgs", offsetof(struct rx_port_stats,
101                                 rx_llfc_physical_msgs)},
102         {"rx_llfc_logical_msgs", offsetof(struct rx_port_stats,
103                                 rx_llfc_logical_msgs)},
104         {"rx_llfc_msgs_with_crc_err", offsetof(struct rx_port_stats,
105                                 rx_llfc_msgs_with_crc_err)},
106         {"rx_hcfc_msgs", offsetof(struct rx_port_stats,
107                                 rx_hcfc_msgs)},
108         {"rx_hcfc_msgs_with_crc_err", offsetof(struct rx_port_stats,
109                                 rx_hcfc_msgs_with_crc_err)},
110         {"rx_bytes", offsetof(struct rx_port_stats,
111                                 rx_bytes)},
112         {"rx_runt_bytes", offsetof(struct rx_port_stats,
113                                 rx_runt_bytes)},
114         {"rx_runt_frames", offsetof(struct rx_port_stats,
115                                 rx_runt_frames)},
116         {"rx_pfc_xon2xoff_frames_pri0", offsetof(struct rx_port_stats,
117                                 rx_pfc_xon2xoff_frames_pri0)},
118         {"rx_pfc_xon2xoff_frames_pri1", offsetof(struct rx_port_stats,
119                                 rx_pfc_xon2xoff_frames_pri1)},
120         {"rx_pfc_xon2xoff_frames_pri2", offsetof(struct rx_port_stats,
121                                 rx_pfc_xon2xoff_frames_pri2)},
122         {"rx_pfc_xon2xoff_frames_pri3", offsetof(struct rx_port_stats,
123                                 rx_pfc_xon2xoff_frames_pri3)},
124         {"rx_pfc_xon2xoff_frames_pri4", offsetof(struct rx_port_stats,
125                                 rx_pfc_xon2xoff_frames_pri4)},
126         {"rx_pfc_xon2xoff_frames_pri5", offsetof(struct rx_port_stats,
127                                 rx_pfc_xon2xoff_frames_pri5)},
128         {"rx_pfc_xon2xoff_frames_pri6", offsetof(struct rx_port_stats,
129                                 rx_pfc_xon2xoff_frames_pri6)},
130         {"rx_pfc_xon2xoff_frames_pri7", offsetof(struct rx_port_stats,
131                                 rx_pfc_xon2xoff_frames_pri7)},
132         {"rx_pfc_ena_frames_pri0", offsetof(struct rx_port_stats,
133                                 rx_pfc_ena_frames_pri0)},
134         {"rx_pfc_ena_frames_pri1", offsetof(struct rx_port_stats,
135                                 rx_pfc_ena_frames_pri1)},
136         {"rx_pfc_ena_frames_pri2", offsetof(struct rx_port_stats,
137                                 rx_pfc_ena_frames_pri2)},
138         {"rx_pfc_ena_frames_pri3", offsetof(struct rx_port_stats,
139                                 rx_pfc_ena_frames_pri3)},
140         {"rx_pfc_ena_frames_pri4", offsetof(struct rx_port_stats,
141                                 rx_pfc_ena_frames_pri4)},
142         {"rx_pfc_ena_frames_pri5", offsetof(struct rx_port_stats,
143                                 rx_pfc_ena_frames_pri5)},
144         {"rx_pfc_ena_frames_pri6", offsetof(struct rx_port_stats,
145                                 rx_pfc_ena_frames_pri6)},
146         {"rx_pfc_ena_frames_pri7", offsetof(struct rx_port_stats,
147                                 rx_pfc_ena_frames_pri7)},
148         {"rx_stat_discard", offsetof(struct rx_port_stats,
149                                 rx_stat_discard)},
150         {"rx_stat_err", offsetof(struct rx_port_stats,
151                                 rx_stat_err)},
152 };
153
154 static const struct bnxt_xstats_name_off bnxt_tx_stats_strings[] = {
155         {"tx_64b_frames", offsetof(struct tx_port_stats,
156                                 tx_64b_frames)},
157         {"tx_65b_127b_frames", offsetof(struct tx_port_stats,
158                                 tx_65b_127b_frames)},
159         {"tx_128b_255b_frames", offsetof(struct tx_port_stats,
160                                 tx_128b_255b_frames)},
161         {"tx_256b_511b_frames", offsetof(struct tx_port_stats,
162                                 tx_256b_511b_frames)},
163         {"tx_512b_1023b_frames", offsetof(struct tx_port_stats,
164                                 tx_512b_1023b_frames)},
165         {"tx_1024b_1518b_frames", offsetof(struct tx_port_stats,
166                                 tx_1024b_1518b_frames)},
167         {"tx_good_vlan_frames", offsetof(struct tx_port_stats,
168                                 tx_good_vlan_frames)},
169         {"tx_1519b_2047b_frames", offsetof(struct tx_port_stats,
170                                 tx_1519b_2047b_frames)},
171         {"tx_2048b_4095b_frames", offsetof(struct tx_port_stats,
172                                 tx_2048b_4095b_frames)},
173         {"tx_4096b_9216b_frames", offsetof(struct tx_port_stats,
174                                 tx_4096b_9216b_frames)},
175         {"tx_9217b_16383b_frames", offsetof(struct tx_port_stats,
176                                 tx_9217b_16383b_frames)},
177         {"tx_good_frames", offsetof(struct tx_port_stats,
178                                 tx_good_frames)},
179         {"tx_total_frames", offsetof(struct tx_port_stats,
180                                 tx_total_frames)},
181         {"tx_ucast_frames", offsetof(struct tx_port_stats,
182                                 tx_ucast_frames)},
183         {"tx_mcast_frames", offsetof(struct tx_port_stats,
184                                 tx_mcast_frames)},
185         {"tx_bcast_frames", offsetof(struct tx_port_stats,
186                                 tx_bcast_frames)},
187         {"tx_pause_frames", offsetof(struct tx_port_stats,
188                                 tx_pause_frames)},
189         {"tx_pfc_frames", offsetof(struct tx_port_stats,
190                                 tx_pfc_frames)},
191         {"tx_jabber_frames", offsetof(struct tx_port_stats,
192                                 tx_jabber_frames)},
193         {"tx_fcs_err_frames", offsetof(struct tx_port_stats,
194                                 tx_fcs_err_frames)},
195         {"tx_control_frames", offsetof(struct tx_port_stats,
196                                 tx_control_frames)},
197         {"tx_oversz_frames", offsetof(struct tx_port_stats,
198                                 tx_oversz_frames)},
199         {"tx_single_dfrl_frames", offsetof(struct tx_port_stats,
200                                 tx_single_dfrl_frames)},
201         {"tx_multi_dfrl_frames", offsetof(struct tx_port_stats,
202                                 tx_multi_dfrl_frames)},
203         {"tx_single_coll_frames", offsetof(struct tx_port_stats,
204                                 tx_single_coll_frames)},
205         {"tx_multi_coll_frames", offsetof(struct tx_port_stats,
206                                 tx_multi_coll_frames)},
207         {"tx_late_coll_frames", offsetof(struct tx_port_stats,
208                                 tx_late_coll_frames)},
209         {"tx_excessive_coll_frames", offsetof(struct tx_port_stats,
210                                 tx_excessive_coll_frames)},
211         {"tx_frag_frames", offsetof(struct tx_port_stats,
212                                 tx_frag_frames)},
213         {"tx_err", offsetof(struct tx_port_stats,
214                                 tx_err)},
215         {"tx_tagged_frames", offsetof(struct tx_port_stats,
216                                 tx_tagged_frames)},
217         {"tx_dbl_tagged_frames", offsetof(struct tx_port_stats,
218                                 tx_dbl_tagged_frames)},
219         {"tx_runt_frames", offsetof(struct tx_port_stats,
220                                 tx_runt_frames)},
221         {"tx_fifo_underruns", offsetof(struct tx_port_stats,
222                                 tx_fifo_underruns)},
223         {"tx_eee_lpi_events", offsetof(struct tx_port_stats,
224                                 tx_eee_lpi_events)},
225         {"tx_eee_lpi_duration", offsetof(struct tx_port_stats,
226                                 tx_eee_lpi_duration)},
227         {"tx_total_collisions", offsetof(struct tx_port_stats,
228                                 tx_total_collisions)},
229         {"tx_bytes", offsetof(struct tx_port_stats,
230                                 tx_bytes)},
231         {"tx_pfc_ena_frames_pri0", offsetof(struct tx_port_stats,
232                                 tx_pfc_ena_frames_pri0)},
233         {"tx_pfc_ena_frames_pri1", offsetof(struct tx_port_stats,
234                                 tx_pfc_ena_frames_pri1)},
235         {"tx_pfc_ena_frames_pri2", offsetof(struct tx_port_stats,
236                                 tx_pfc_ena_frames_pri2)},
237         {"tx_pfc_ena_frames_pri3", offsetof(struct tx_port_stats,
238                                 tx_pfc_ena_frames_pri3)},
239         {"tx_pfc_ena_frames_pri4", offsetof(struct tx_port_stats,
240                                 tx_pfc_ena_frames_pri4)},
241         {"tx_pfc_ena_frames_pri5", offsetof(struct tx_port_stats,
242                                 tx_pfc_ena_frames_pri5)},
243         {"tx_pfc_ena_frames_pri6", offsetof(struct tx_port_stats,
244                                 tx_pfc_ena_frames_pri6)},
245         {"tx_pfc_ena_frames_pri7", offsetof(struct tx_port_stats,
246                                 tx_pfc_ena_frames_pri7)},
247         {"tx_llfc_logical_msgs", offsetof(struct tx_port_stats,
248                                 tx_llfc_logical_msgs)},
249         {"tx_hcfc_msgs", offsetof(struct tx_port_stats,
250                                 tx_hcfc_msgs)},
251         {"tx_xthol_frames", offsetof(struct tx_port_stats,
252                                 tx_xthol_frames)},
253         {"tx_stat_discard", offsetof(struct tx_port_stats,
254                                 tx_stat_discard)},
255         {"tx_stat_error", offsetof(struct tx_port_stats,
256                                 tx_stat_error)},
257 };
258
259 static const struct bnxt_xstats_name_off bnxt_func_stats_strings[] = {
260         {"tx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
261                                 tx_ucast_pkts)},
262         {"tx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
263                                 tx_mcast_pkts)},
264         {"tx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
265                                 tx_bcast_pkts)},
266         {"tx_discard_pkts", offsetof(struct hwrm_func_qstats_output,
267                                 tx_discard_pkts)},
268         {"tx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
269                                 tx_drop_pkts)},
270         {"tx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
271                                 tx_ucast_bytes)},
272         {"tx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
273                                 tx_mcast_bytes)},
274         {"tx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
275                                 tx_bcast_bytes)},
276         {"rx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
277                                 rx_ucast_pkts)},
278         {"rx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
279                                 rx_mcast_pkts)},
280         {"rx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
281                                 rx_bcast_pkts)},
282         {"rx_discard_pkts", offsetof(struct hwrm_func_qstats_output,
283                                 rx_discard_pkts)},
284         {"rx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
285                                 rx_drop_pkts)},
286         {"rx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
287                                 rx_ucast_bytes)},
288         {"rx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
289                                 rx_mcast_bytes)},
290         {"rx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
291                                 rx_bcast_bytes)},
292         {"rx_agg_pkts", offsetof(struct hwrm_func_qstats_output,
293                                 rx_agg_pkts)},
294         {"rx_agg_bytes", offsetof(struct hwrm_func_qstats_output,
295                                 rx_agg_bytes)},
296         {"rx_agg_events", offsetof(struct hwrm_func_qstats_output,
297                                 rx_agg_events)},
298         {"rx_agg_aborts", offsetof(struct hwrm_func_qstats_output,
299                                 rx_agg_aborts)},
300 };
301
302
303 static const struct bnxt_xstats_name_off bnxt_rx_ext_stats_strings[] = {
304         {"link_down_events", offsetof(struct rx_port_stats_ext,
305                                 link_down_events)},
306         {"continuous_pause_events", offsetof(struct rx_port_stats_ext,
307                                 continuous_pause_events)},
308         {"resume_pause_events", offsetof(struct rx_port_stats_ext,
309                                 resume_pause_events)},
310         {"continuous_roce_pause_events", offsetof(struct rx_port_stats_ext,
311                                 continuous_roce_pause_events)},
312         {"resume_roce_pause_events", offsetof(struct rx_port_stats_ext,
313                                 resume_roce_pause_events)},
314         {"rx_bytes_cos0", offsetof(struct rx_port_stats_ext,
315                                 rx_bytes_cos0)},
316         {"rx_bytes_cos1", offsetof(struct rx_port_stats_ext,
317                                 rx_bytes_cos1)},
318         {"rx_bytes_cos2", offsetof(struct rx_port_stats_ext,
319                                 rx_bytes_cos2)},
320         {"rx_bytes_cos3", offsetof(struct rx_port_stats_ext,
321                                 rx_bytes_cos3)},
322         {"rx_bytes_cos4", offsetof(struct rx_port_stats_ext,
323                                 rx_bytes_cos4)},
324         {"rx_bytes_cos5", offsetof(struct rx_port_stats_ext,
325                                 rx_bytes_cos5)},
326         {"rx_bytes_cos6", offsetof(struct rx_port_stats_ext,
327                                 rx_bytes_cos6)},
328         {"rx_bytes_cos7", offsetof(struct rx_port_stats_ext,
329                                 rx_bytes_cos7)},
330         {"rx_packets_cos0", offsetof(struct rx_port_stats_ext,
331                                 rx_packets_cos0)},
332         {"rx_packets_cos1", offsetof(struct rx_port_stats_ext,
333                                 rx_packets_cos1)},
334         {"rx_packets_cos2", offsetof(struct rx_port_stats_ext,
335                                 rx_packets_cos2)},
336         {"rx_packets_cos3", offsetof(struct rx_port_stats_ext,
337                                 rx_packets_cos3)},
338         {"rx_packets_cos4", offsetof(struct rx_port_stats_ext,
339                                 rx_packets_cos4)},
340         {"rx_packets_cos5", offsetof(struct rx_port_stats_ext,
341                                 rx_packets_cos5)},
342         {"rx_packets_cos6", offsetof(struct rx_port_stats_ext,
343                                 rx_packets_cos6)},
344         {"rx_packets_cos7", offsetof(struct rx_port_stats_ext,
345                                 rx_packets_cos7)},
346         {"pfc_pri0_rx_duration_us", offsetof(struct rx_port_stats_ext,
347                                 pfc_pri0_rx_duration_us)},
348         {"pfc_pri0_rx_transitions", offsetof(struct rx_port_stats_ext,
349                                 pfc_pri0_rx_transitions)},
350         {"pfc_pri1_rx_duration_us", offsetof(struct rx_port_stats_ext,
351                                 pfc_pri1_rx_duration_us)},
352         {"pfc_pri1_rx_transitions", offsetof(struct rx_port_stats_ext,
353                                 pfc_pri1_rx_transitions)},
354         {"pfc_pri2_rx_duration_us", offsetof(struct rx_port_stats_ext,
355                                 pfc_pri2_rx_duration_us)},
356         {"pfc_pri2_rx_transitions", offsetof(struct rx_port_stats_ext,
357                                 pfc_pri2_rx_transitions)},
358         {"pfc_pri3_rx_duration_us", offsetof(struct rx_port_stats_ext,
359                                 pfc_pri3_rx_duration_us)},
360         {"pfc_pri3_rx_transitions", offsetof(struct rx_port_stats_ext,
361                                 pfc_pri3_rx_transitions)},
362         {"pfc_pri4_rx_duration_us", offsetof(struct rx_port_stats_ext,
363                                 pfc_pri4_rx_duration_us)},
364         {"pfc_pri4_rx_transitions", offsetof(struct rx_port_stats_ext,
365                                 pfc_pri4_rx_transitions)},
366         {"pfc_pri5_rx_duration_us", offsetof(struct rx_port_stats_ext,
367                                 pfc_pri5_rx_duration_us)},
368         {"pfc_pri5_rx_transitions", offsetof(struct rx_port_stats_ext,
369                                 pfc_pri5_rx_transitions)},
370         {"pfc_pri6_rx_duration_us", offsetof(struct rx_port_stats_ext,
371                                 pfc_pri6_rx_duration_us)},
372         {"pfc_pri6_rx_transitions", offsetof(struct rx_port_stats_ext,
373                                 pfc_pri6_rx_transitions)},
374         {"pfc_pri7_rx_duration_us", offsetof(struct rx_port_stats_ext,
375                                 pfc_pri7_rx_duration_us)},
376         {"pfc_pri7_rx_transitions", offsetof(struct rx_port_stats_ext,
377                                 pfc_pri7_rx_transitions)},
378         {"rx_bits",             offsetof(struct rx_port_stats_ext,
379                                 rx_bits)},
380         {"rx_buffer_passed_threshold", offsetof(struct rx_port_stats_ext,
381                                 rx_buffer_passed_threshold)},
382         {"rx_pcs_symbol_err",   offsetof(struct rx_port_stats_ext,
383                                 rx_pcs_symbol_err)},
384         {"rx_corrected_bits",   offsetof(struct rx_port_stats_ext,
385                                 rx_corrected_bits)},
386         {"rx_discard_bytes_cos0", offsetof(struct rx_port_stats_ext,
387                                 rx_discard_bytes_cos0)},
388         {"rx_discard_bytes_cos1", offsetof(struct rx_port_stats_ext,
389                                 rx_discard_bytes_cos1)},
390         {"rx_discard_bytes_cos2", offsetof(struct rx_port_stats_ext,
391                                 rx_discard_bytes_cos2)},
392         {"rx_discard_bytes_cos3", offsetof(struct rx_port_stats_ext,
393                                 rx_discard_bytes_cos3)},
394         {"rx_discard_bytes_cos4", offsetof(struct rx_port_stats_ext,
395                                 rx_discard_bytes_cos4)},
396         {"rx_discard_bytes_cos5", offsetof(struct rx_port_stats_ext,
397                                 rx_discard_bytes_cos5)},
398         {"rx_discard_bytes_cos6", offsetof(struct rx_port_stats_ext,
399                                 rx_discard_bytes_cos6)},
400         {"rx_discard_bytes_cos7", offsetof(struct rx_port_stats_ext,
401                                 rx_discard_bytes_cos7)},
402         {"rx_discard_packets_cos0", offsetof(struct rx_port_stats_ext,
403                                 rx_discard_packets_cos0)},
404         {"rx_discard_packets_cos1", offsetof(struct rx_port_stats_ext,
405                                 rx_discard_packets_cos1)},
406         {"rx_discard_packets_cos2", offsetof(struct rx_port_stats_ext,
407                                 rx_discard_packets_cos2)},
408         {"rx_discard_packets_cos3", offsetof(struct rx_port_stats_ext,
409                                 rx_discard_packets_cos3)},
410         {"rx_discard_packets_cos4", offsetof(struct rx_port_stats_ext,
411                                 rx_discard_packets_cos4)},
412         {"rx_discard_packets_cos5", offsetof(struct rx_port_stats_ext,
413                                 rx_discard_packets_cos5)},
414         {"rx_discard_packets_cos6", offsetof(struct rx_port_stats_ext,
415                                 rx_discard_packets_cos6)},
416         {"rx_discard_packets_cos7", offsetof(struct rx_port_stats_ext,
417                                 rx_discard_packets_cos7)},
418 };
419
420 static const struct bnxt_xstats_name_off bnxt_tx_ext_stats_strings[] = {
421         {"tx_bytes_cos0", offsetof(struct tx_port_stats_ext,
422                                 tx_bytes_cos0)},
423         {"tx_bytes_cos1", offsetof(struct tx_port_stats_ext,
424                                 tx_bytes_cos1)},
425         {"tx_bytes_cos2", offsetof(struct tx_port_stats_ext,
426                                 tx_bytes_cos2)},
427         {"tx_bytes_cos3", offsetof(struct tx_port_stats_ext,
428                                 tx_bytes_cos3)},
429         {"tx_bytes_cos4", offsetof(struct tx_port_stats_ext,
430                                 tx_bytes_cos4)},
431         {"tx_bytes_cos5", offsetof(struct tx_port_stats_ext,
432                                 tx_bytes_cos5)},
433         {"tx_bytes_cos6", offsetof(struct tx_port_stats_ext,
434                                 tx_bytes_cos6)},
435         {"tx_bytes_cos7", offsetof(struct tx_port_stats_ext,
436                                 tx_bytes_cos7)},
437         {"tx_packets_cos0", offsetof(struct tx_port_stats_ext,
438                                 tx_packets_cos0)},
439         {"tx_packets_cos1", offsetof(struct tx_port_stats_ext,
440                                 tx_packets_cos1)},
441         {"tx_packets_cos2", offsetof(struct tx_port_stats_ext,
442                                 tx_packets_cos2)},
443         {"tx_packets_cos3", offsetof(struct tx_port_stats_ext,
444                                 tx_packets_cos3)},
445         {"tx_packets_cos4", offsetof(struct tx_port_stats_ext,
446                                 tx_packets_cos4)},
447         {"tx_packets_cos5", offsetof(struct tx_port_stats_ext,
448                                 tx_packets_cos5)},
449         {"tx_packets_cos6", offsetof(struct tx_port_stats_ext,
450                                 tx_packets_cos6)},
451         {"tx_packets_cos7", offsetof(struct tx_port_stats_ext,
452                                 tx_packets_cos7)},
453         {"pfc_pri0_tx_duration_us", offsetof(struct tx_port_stats_ext,
454                                 pfc_pri0_tx_duration_us)},
455         {"pfc_pri0_tx_transitions", offsetof(struct tx_port_stats_ext,
456                                 pfc_pri0_tx_transitions)},
457         {"pfc_pri1_tx_duration_us", offsetof(struct tx_port_stats_ext,
458                                 pfc_pri1_tx_duration_us)},
459         {"pfc_pri1_tx_transitions", offsetof(struct tx_port_stats_ext,
460                                 pfc_pri1_tx_transitions)},
461         {"pfc_pri2_tx_duration_us", offsetof(struct tx_port_stats_ext,
462                                 pfc_pri2_tx_duration_us)},
463         {"pfc_pri2_tx_transitions", offsetof(struct tx_port_stats_ext,
464                                 pfc_pri2_tx_transitions)},
465         {"pfc_pri3_tx_duration_us", offsetof(struct tx_port_stats_ext,
466                                 pfc_pri3_tx_duration_us)},
467         {"pfc_pri3_tx_transitions", offsetof(struct tx_port_stats_ext,
468                                 pfc_pri3_tx_transitions)},
469         {"pfc_pri4_tx_duration_us", offsetof(struct tx_port_stats_ext,
470                                 pfc_pri4_tx_duration_us)},
471         {"pfc_pri4_tx_transitions", offsetof(struct tx_port_stats_ext,
472                                 pfc_pri4_tx_transitions)},
473         {"pfc_pri5_tx_duration_us", offsetof(struct tx_port_stats_ext,
474                                 pfc_pri5_tx_duration_us)},
475         {"pfc_pri5_tx_transitions", offsetof(struct tx_port_stats_ext,
476                                 pfc_pri5_tx_transitions)},
477         {"pfc_pri6_tx_duration_us", offsetof(struct tx_port_stats_ext,
478                                 pfc_pri6_tx_duration_us)},
479         {"pfc_pri6_tx_transitions", offsetof(struct tx_port_stats_ext,
480                                 pfc_pri6_tx_transitions)},
481         {"pfc_pri7_tx_duration_us", offsetof(struct tx_port_stats_ext,
482                                 pfc_pri7_tx_duration_us)},
483         {"pfc_pri7_tx_transitions", offsetof(struct tx_port_stats_ext,
484                                 pfc_pri7_tx_transitions)},
485 };
486
487 /*
488  * Statistics functions
489  */
490
491 void bnxt_free_stats(struct bnxt *bp)
492 {
493         int i;
494
495         for (i = 0; i < (int)bp->tx_cp_nr_rings; i++) {
496                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
497
498                 bnxt_free_txq_stats(txq);
499         }
500         for (i = 0; i < (int)bp->rx_cp_nr_rings; i++) {
501                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
502
503                 bnxt_free_rxq_stats(rxq);
504         }
505 }
506
507 int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
508                            struct rte_eth_stats *bnxt_stats)
509 {
510         int rc = 0;
511         unsigned int i;
512         struct bnxt *bp = eth_dev->data->dev_private;
513         unsigned int num_q_stats;
514
515         rc = is_bnxt_in_error(bp);
516         if (rc)
517                 return rc;
518
519         if (!eth_dev->data->dev_started)
520                 return -EIO;
521
522         num_q_stats = RTE_MIN(bp->rx_cp_nr_rings,
523                               (unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS);
524
525         for (i = 0; i < num_q_stats; i++) {
526                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
527                 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
528
529                 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
530                                      bnxt_stats, 1);
531                 if (unlikely(rc))
532                         return rc;
533                 bnxt_stats->rx_nombuf +=
534                                 rte_atomic64_read(&rxq->rx_mbuf_alloc_fail);
535         }
536
537         num_q_stats = RTE_MIN(bp->tx_cp_nr_rings,
538                               (unsigned int)RTE_ETHDEV_QUEUE_STAT_CNTRS);
539
540         for (i = 0; i < num_q_stats; i++) {
541                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
542                 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
543
544                 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
545                                      bnxt_stats, 0);
546                 if (unlikely(rc))
547                         return rc;
548         }
549
550         rc = bnxt_hwrm_func_qstats(bp, 0xffff, bnxt_stats, NULL);
551         return rc;
552 }
553
554 int bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
555 {
556         struct bnxt *bp = eth_dev->data->dev_private;
557         unsigned int i;
558         int ret;
559
560         ret = is_bnxt_in_error(bp);
561         if (ret)
562                 return ret;
563
564         if (!eth_dev->data->dev_started) {
565                 PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
566                 return -EINVAL;
567         }
568
569         ret = bnxt_clear_all_hwrm_stat_ctxs(bp);
570         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
571                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
572
573                 rte_atomic64_clear(&rxq->rx_mbuf_alloc_fail);
574         }
575
576         return ret;
577 }
578
579 int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
580                            struct rte_eth_xstat *xstats, unsigned int n)
581 {
582         struct bnxt *bp = eth_dev->data->dev_private;
583         unsigned int count, i;
584         unsigned int rx_port_stats_ext_cnt;
585         unsigned int tx_port_stats_ext_cnt;
586         unsigned int stat_size = sizeof(uint64_t);
587         struct hwrm_func_qstats_output func_qstats = {0};
588         unsigned int stat_count;
589         int rc;
590
591         rc = is_bnxt_in_error(bp);
592         if (rc)
593                 return rc;
594
595         if (xstats == NULL)
596                 return 0;
597
598         memset(xstats, 0, sizeof(*xstats));
599
600         bnxt_hwrm_func_qstats(bp, 0xffff, NULL, &func_qstats);
601         bnxt_hwrm_port_qstats(bp);
602         bnxt_hwrm_ext_port_qstats(bp);
603         rx_port_stats_ext_cnt = RTE_MIN(RTE_DIM(bnxt_rx_ext_stats_strings),
604                                         (bp->fw_rx_port_stats_ext_size /
605                                          stat_size));
606         tx_port_stats_ext_cnt = RTE_MIN(RTE_DIM(bnxt_tx_ext_stats_strings),
607                                         (bp->fw_tx_port_stats_ext_size /
608                                          stat_size));
609
610         count = RTE_DIM(bnxt_rx_stats_strings) +
611                 RTE_DIM(bnxt_tx_stats_strings) +
612                 RTE_DIM(bnxt_func_stats_strings) +
613                 RTE_DIM(bnxt_rx_ext_stats_strings) +
614                 RTE_DIM(bnxt_tx_ext_stats_strings);
615         stat_count = count;
616
617         if (n < count)
618                 return count;
619
620         count = 0;
621         for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
622                 uint64_t *rx_stats = (uint64_t *)bp->hw_rx_port_stats;
623                 xstats[count].id = count;
624                 xstats[count].value = rte_le_to_cpu_64(
625                                 *(uint64_t *)((char *)rx_stats +
626                                 bnxt_rx_stats_strings[i].offset));
627                 count++;
628         }
629
630         for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
631                 uint64_t *tx_stats = (uint64_t *)bp->hw_tx_port_stats;
632                 xstats[count].id = count;
633                 xstats[count].value = rte_le_to_cpu_64(
634                                  *(uint64_t *)((char *)tx_stats +
635                                 bnxt_tx_stats_strings[i].offset));
636                 count++;
637         }
638
639         for (i = 0; i < RTE_DIM(bnxt_func_stats_strings); i++) {
640                 xstats[count].id = count;
641                 xstats[count].value =
642                 rte_le_to_cpu_64(((uint64_t *)&func_qstats)[i]);
643                 count++;
644         }
645
646
647         for (i = 0; i < rx_port_stats_ext_cnt; i++) {
648                 uint64_t *rx_stats_ext = (uint64_t *)bp->hw_rx_port_stats_ext;
649
650                 xstats[count].value = rte_le_to_cpu_64
651                                         (*(uint64_t *)((char *)rx_stats_ext +
652                                          bnxt_rx_ext_stats_strings[i].offset));
653
654                 count++;
655         }
656
657         for (i = 0; i < tx_port_stats_ext_cnt; i++) {
658                 uint64_t *tx_stats_ext = (uint64_t *)bp->hw_tx_port_stats_ext;
659
660                 xstats[count].value = rte_le_to_cpu_64
661                                         (*(uint64_t *)((char *)tx_stats_ext +
662                                          bnxt_tx_ext_stats_strings[i].offset));
663
664                 count++;
665         }
666
667         return stat_count;
668 }
669
670 int bnxt_dev_xstats_get_names_op(struct rte_eth_dev *eth_dev,
671                                  struct rte_eth_xstat_name *xstats_names,
672                                  __rte_unused unsigned int limit)
673 {
674         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
675                                 RTE_DIM(bnxt_tx_stats_strings) +
676                                 RTE_DIM(bnxt_func_stats_strings) +
677                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
678                                 RTE_DIM(bnxt_tx_ext_stats_strings);
679         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
680         unsigned int i, count;
681         int rc;
682
683         rc = is_bnxt_in_error(bp);
684         if (rc)
685                 return rc;
686
687         if (xstats_names != NULL) {
688                 count = 0;
689
690                 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
691                         strlcpy(xstats_names[count].name,
692                                 bnxt_rx_stats_strings[i].name,
693                                 sizeof(xstats_names[count].name));
694                         count++;
695                 }
696
697                 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
698                         strlcpy(xstats_names[count].name,
699                                 bnxt_tx_stats_strings[i].name,
700                                 sizeof(xstats_names[count].name));
701                         count++;
702                 }
703
704                 for (i = 0; i < RTE_DIM(bnxt_func_stats_strings); i++) {
705                         strlcpy(xstats_names[count].name,
706                                 bnxt_func_stats_strings[i].name,
707                                 sizeof(xstats_names[count].name));
708                         count++;
709                 }
710
711                 for (i = 0; i < RTE_DIM(bnxt_rx_ext_stats_strings); i++) {
712                         strlcpy(xstats_names[count].name,
713                                 bnxt_rx_ext_stats_strings[i].name,
714                                 sizeof(xstats_names[count].name));
715
716                         count++;
717                 }
718
719                 for (i = 0; i < RTE_DIM(bnxt_tx_ext_stats_strings); i++) {
720                         strlcpy(xstats_names[count].name,
721                                 bnxt_tx_ext_stats_strings[i].name,
722                                 sizeof(xstats_names[count].name));
723
724                         count++;
725                 }
726
727         }
728         return stat_cnt;
729 }
730
731 int bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
732 {
733         struct bnxt *bp = eth_dev->data->dev_private;
734         int ret;
735
736         ret = is_bnxt_in_error(bp);
737         if (ret)
738                 return ret;
739
740         if (BNXT_VF(bp) || !BNXT_SINGLE_PF(bp) ||
741             !(bp->flags & BNXT_FLAG_PORT_STATS)) {
742                 PMD_DRV_LOG(ERR, "Operation not supported\n");
743                 return -ENOTSUP;
744         }
745
746         ret = bnxt_hwrm_port_clr_stats(bp);
747         if (ret != 0)
748                 PMD_DRV_LOG(ERR, "Failed to reset xstats: %s\n",
749                             strerror(-ret));
750
751         return ret;
752 }
753
754 int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
755                 uint64_t *values, unsigned int limit)
756 {
757         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
758                                 RTE_DIM(bnxt_tx_stats_strings) +
759                                 RTE_DIM(bnxt_func_stats_strings) +
760                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
761                                 RTE_DIM(bnxt_tx_ext_stats_strings);
762         struct bnxt *bp = dev->data->dev_private;
763         struct rte_eth_xstat xstats[stat_cnt];
764         uint64_t values_copy[stat_cnt];
765         uint16_t i;
766         int rc;
767
768         rc = is_bnxt_in_error(bp);
769         if (rc)
770                 return rc;
771
772         if (!ids)
773                 return bnxt_dev_xstats_get_op(dev, xstats, stat_cnt);
774
775         bnxt_dev_xstats_get_by_id_op(dev, NULL, values_copy, stat_cnt);
776         for (i = 0; i < limit; i++) {
777                 if (ids[i] >= stat_cnt) {
778                         PMD_DRV_LOG(ERR, "id value isn't valid");
779                         return -EINVAL;
780                 }
781                 values[i] = values_copy[ids[i]];
782         }
783         return stat_cnt;
784 }
785
786 int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
787                                 struct rte_eth_xstat_name *xstats_names,
788                                 const uint64_t *ids, unsigned int limit)
789 {
790         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
791                                 RTE_DIM(bnxt_tx_stats_strings) +
792                                 RTE_DIM(bnxt_func_stats_strings) +
793                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
794                                 RTE_DIM(bnxt_tx_ext_stats_strings);
795         struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
796         struct bnxt *bp = dev->data->dev_private;
797         uint16_t i;
798         int rc;
799
800         rc = is_bnxt_in_error(bp);
801         if (rc)
802                 return rc;
803
804         if (!ids)
805                 return bnxt_dev_xstats_get_names_op(dev, xstats_names,
806                                                     stat_cnt);
807         bnxt_dev_xstats_get_names_by_id_op(dev, xstats_names_copy, NULL,
808                         stat_cnt);
809
810         for (i = 0; i < limit; i++) {
811                 if (ids[i] >= stat_cnt) {
812                         PMD_DRV_LOG(ERR, "id value isn't valid");
813                         return -EINVAL;
814                 }
815                 strcpy(xstats_names[i].name,
816                                 xstats_names_copy[ids[i]].name);
817         }
818         return stat_cnt;
819 }