New upstream version 18.11-rc1
[deb_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_byteorder.h>
9
10 #include "bnxt.h"
11 #include "bnxt_cpr.h"
12 #include "bnxt_hwrm.h"
13 #include "bnxt_rxq.h"
14 #include "bnxt_stats.h"
15 #include "bnxt_txq.h"
16 #include "hsi_struct_def_dpdk.h"
17
18 static const struct bnxt_xstats_name_off bnxt_rx_stats_strings[] = {
19         {"rx_64b_frames", offsetof(struct rx_port_stats,
20                                 rx_64b_frames)},
21         {"rx_65b_127b_frames", offsetof(struct rx_port_stats,
22                                 rx_65b_127b_frames)},
23         {"rx_128b_255b_frames", offsetof(struct rx_port_stats,
24                                 rx_128b_255b_frames)},
25         {"rx_256b_511b_frames", offsetof(struct rx_port_stats,
26                                 rx_256b_511b_frames)},
27         {"rx_512b_1023b_frames", offsetof(struct rx_port_stats,
28                                 rx_512b_1023b_frames)},
29         {"rx_1024b_1518b_frames", offsetof(struct rx_port_stats,
30                                 rx_1024b_1518b_frames)},
31         {"rx_good_vlan_frames", offsetof(struct rx_port_stats,
32                                 rx_good_vlan_frames)},
33         {"rx_1519b_2047b_frames", offsetof(struct rx_port_stats,
34                                 rx_1519b_2047b_frames)},
35         {"rx_2048b_4095b_frames", offsetof(struct rx_port_stats,
36                                 rx_2048b_4095b_frames)},
37         {"rx_4096b_9216b_frames", offsetof(struct rx_port_stats,
38                                 rx_4096b_9216b_frames)},
39         {"rx_9217b_16383b_frames", offsetof(struct rx_port_stats,
40                                 rx_9217b_16383b_frames)},
41         {"rx_total_frames", offsetof(struct rx_port_stats,
42                                 rx_total_frames)},
43         {"rx_ucast_frames", offsetof(struct rx_port_stats,
44                                 rx_ucast_frames)},
45         {"rx_mcast_frames", offsetof(struct rx_port_stats,
46                                 rx_mcast_frames)},
47         {"rx_bcast_frames", offsetof(struct rx_port_stats,
48                                 rx_bcast_frames)},
49         {"rx_fcs_err_frames", offsetof(struct rx_port_stats,
50                                 rx_fcs_err_frames)},
51         {"rx_ctrl_frames", offsetof(struct rx_port_stats,
52                                 rx_ctrl_frames)},
53         {"rx_pause_frames", offsetof(struct rx_port_stats,
54                                 rx_pause_frames)},
55         {"rx_pfc_frames", offsetof(struct rx_port_stats,
56                                 rx_pfc_frames)},
57         {"rx_align_err_frames", offsetof(struct rx_port_stats,
58                                 rx_align_err_frames)},
59         {"rx_ovrsz_frames", offsetof(struct rx_port_stats,
60                                 rx_ovrsz_frames)},
61         {"rx_jbr_frames", offsetof(struct rx_port_stats,
62                                 rx_jbr_frames)},
63         {"rx_mtu_err_frames", offsetof(struct rx_port_stats,
64                                 rx_mtu_err_frames)},
65         {"rx_tagged_frames", offsetof(struct rx_port_stats,
66                                 rx_tagged_frames)},
67         {"rx_double_tagged_frames", offsetof(struct rx_port_stats,
68                                 rx_double_tagged_frames)},
69         {"rx_good_frames", offsetof(struct rx_port_stats,
70                                 rx_good_frames)},
71         {"rx_undrsz_frames", offsetof(struct rx_port_stats,
72                                 rx_undrsz_frames)},
73         {"rx_eee_lpi_events", offsetof(struct rx_port_stats,
74                                 rx_eee_lpi_events)},
75         {"rx_eee_lpi_duration", offsetof(struct rx_port_stats,
76                                 rx_eee_lpi_duration)},
77         {"rx_bytes", offsetof(struct rx_port_stats,
78                                 rx_bytes)},
79         {"rx_runt_bytes", offsetof(struct rx_port_stats,
80                                 rx_runt_bytes)},
81         {"rx_runt_frames", offsetof(struct rx_port_stats,
82                                 rx_runt_frames)},
83 };
84
85 static const struct bnxt_xstats_name_off bnxt_tx_stats_strings[] = {
86         {"tx_64b_frames", offsetof(struct tx_port_stats,
87                                 tx_64b_frames)},
88         {"tx_65b_127b_frames", offsetof(struct tx_port_stats,
89                                 tx_65b_127b_frames)},
90         {"tx_128b_255b_frames", offsetof(struct tx_port_stats,
91                                 tx_128b_255b_frames)},
92         {"tx_256b_511b_frames", offsetof(struct tx_port_stats,
93                                 tx_256b_511b_frames)},
94         {"tx_512b_1023b_frames", offsetof(struct tx_port_stats,
95                                 tx_512b_1023b_frames)},
96         {"tx_1024b_1518b_frames", offsetof(struct tx_port_stats,
97                                 tx_1024b_1518b_frames)},
98         {"tx_good_vlan_frames", offsetof(struct tx_port_stats,
99                                 tx_good_vlan_frames)},
100         {"tx_1519b_2047b_frames", offsetof(struct tx_port_stats,
101                                 tx_1519b_2047b_frames)},
102         {"tx_2048b_4095b_frames", offsetof(struct tx_port_stats,
103                                 tx_2048b_4095b_frames)},
104         {"tx_4096b_9216b_frames", offsetof(struct tx_port_stats,
105                                 tx_4096b_9216b_frames)},
106         {"tx_9217b_16383b_frames", offsetof(struct tx_port_stats,
107                                 tx_9217b_16383b_frames)},
108         {"tx_good_frames", offsetof(struct tx_port_stats,
109                                 tx_good_frames)},
110         {"tx_total_frames", offsetof(struct tx_port_stats,
111                                 tx_total_frames)},
112         {"tx_ucast_frames", offsetof(struct tx_port_stats,
113                                 tx_ucast_frames)},
114         {"tx_mcast_frames", offsetof(struct tx_port_stats,
115                                 tx_mcast_frames)},
116         {"tx_bcast_frames", offsetof(struct tx_port_stats,
117                                 tx_bcast_frames)},
118         {"tx_pause_frames", offsetof(struct tx_port_stats,
119                                 tx_pause_frames)},
120         {"tx_pfc_frames", offsetof(struct tx_port_stats,
121                                 tx_pfc_frames)},
122         {"tx_jabber_frames", offsetof(struct tx_port_stats,
123                                 tx_jabber_frames)},
124         {"tx_fcs_err_frames", offsetof(struct tx_port_stats,
125                                 tx_fcs_err_frames)},
126         {"tx_err", offsetof(struct tx_port_stats,
127                                 tx_err)},
128         {"tx_fifo_underruns", offsetof(struct tx_port_stats,
129                                 tx_fifo_underruns)},
130         {"tx_eee_lpi_events", offsetof(struct tx_port_stats,
131                                 tx_eee_lpi_events)},
132         {"tx_eee_lpi_duration", offsetof(struct tx_port_stats,
133                                 tx_eee_lpi_duration)},
134         {"tx_total_collisions", offsetof(struct tx_port_stats,
135                                 tx_total_collisions)},
136         {"tx_bytes", offsetof(struct tx_port_stats,
137                                 tx_bytes)},
138 };
139
140 static const struct bnxt_xstats_name_off bnxt_func_stats_strings[] = {
141         {"tx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
142                                 tx_ucast_pkts)},
143         {"tx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
144                                 tx_mcast_pkts)},
145         {"tx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
146                                 tx_bcast_pkts)},
147         {"tx_discard_pkts", offsetof(struct hwrm_func_qstats_output,
148                                 tx_discard_pkts)},
149         {"tx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
150                                 tx_drop_pkts)},
151         {"tx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
152                                 tx_ucast_bytes)},
153         {"tx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
154                                 tx_mcast_bytes)},
155         {"tx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
156                                 tx_bcast_bytes)},
157         {"rx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
158                                 rx_ucast_pkts)},
159         {"rx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
160                                 rx_mcast_pkts)},
161         {"rx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
162                                 rx_bcast_pkts)},
163         {"rx_discard_pkts", offsetof(struct hwrm_func_qstats_output,
164                                 rx_discard_pkts)},
165         {"rx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
166                                 rx_drop_pkts)},
167         {"rx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
168                                 rx_ucast_bytes)},
169         {"rx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
170                                 rx_mcast_bytes)},
171         {"rx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
172                                 rx_bcast_bytes)},
173         {"rx_agg_pkts", offsetof(struct hwrm_func_qstats_output,
174                                 rx_agg_pkts)},
175         {"rx_agg_bytes", offsetof(struct hwrm_func_qstats_output,
176                                 rx_agg_bytes)},
177         {"rx_agg_events", offsetof(struct hwrm_func_qstats_output,
178                                 rx_agg_events)},
179         {"rx_agg_aborts", offsetof(struct hwrm_func_qstats_output,
180                                 rx_agg_aborts)},
181 };
182
183 static const struct bnxt_xstats_name_off bnxt_rx_ext_stats_strings[] = {
184         {"link_down_events", offsetof(struct rx_port_stats_ext,
185                                 link_down_events)},
186         {"continuous_pause_events", offsetof(struct rx_port_stats_ext,
187                                 continuous_pause_events)},
188         {"resume_pause_events", offsetof(struct rx_port_stats_ext,
189                                 resume_pause_events)},
190         {"continuous_roce_pause_events", offsetof(struct rx_port_stats_ext,
191                                 continuous_roce_pause_events)},
192         {"resume_roce_pause_events", offsetof(struct rx_port_stats_ext,
193                                 resume_roce_pause_events)},
194         {"rx_bytes_cos0", offsetof(struct rx_port_stats_ext,
195                                 rx_bytes_cos0)},
196         {"rx_bytes_cos1", offsetof(struct rx_port_stats_ext,
197                                 rx_bytes_cos1)},
198         {"rx_bytes_cos2", offsetof(struct rx_port_stats_ext,
199                                 rx_bytes_cos2)},
200         {"rx_bytes_cos3", offsetof(struct rx_port_stats_ext,
201                                 rx_bytes_cos3)},
202         {"rx_bytes_cos4", offsetof(struct rx_port_stats_ext,
203                                 rx_bytes_cos4)},
204         {"rx_bytes_cos5", offsetof(struct rx_port_stats_ext,
205                                 rx_bytes_cos5)},
206         {"rx_bytes_cos6", offsetof(struct rx_port_stats_ext,
207                                 rx_bytes_cos6)},
208         {"rx_bytes_cos7", offsetof(struct rx_port_stats_ext,
209                                 rx_bytes_cos7)},
210         {"rx_packets_cos0", offsetof(struct rx_port_stats_ext,
211                                 rx_packets_cos0)},
212         {"rx_packets_cos1", offsetof(struct rx_port_stats_ext,
213                                 rx_packets_cos1)},
214         {"rx_packets_cos2", offsetof(struct rx_port_stats_ext,
215                                 rx_packets_cos2)},
216         {"rx_packets_cos3", offsetof(struct rx_port_stats_ext,
217                                 rx_packets_cos3)},
218         {"rx_packets_cos4", offsetof(struct rx_port_stats_ext,
219                                 rx_packets_cos4)},
220         {"rx_packets_cos5", offsetof(struct rx_port_stats_ext,
221                                 rx_packets_cos5)},
222         {"rx_packets_cos6", offsetof(struct rx_port_stats_ext,
223                                 rx_packets_cos6)},
224         {"rx_packets_cos7", offsetof(struct rx_port_stats_ext,
225                                 rx_packets_cos7)},
226         {"pfc_pri0_rx_duration_us", offsetof(struct rx_port_stats_ext,
227                                 pfc_pri0_rx_duration_us)},
228         {"pfc_pri0_rx_transitions", offsetof(struct rx_port_stats_ext,
229                                 pfc_pri0_rx_transitions)},
230         {"pfc_pri1_rx_duration_us", offsetof(struct rx_port_stats_ext,
231                                 pfc_pri1_rx_duration_us)},
232         {"pfc_pri1_rx_transitions", offsetof(struct rx_port_stats_ext,
233                                 pfc_pri1_rx_transitions)},
234         {"pfc_pri2_rx_duration_us", offsetof(struct rx_port_stats_ext,
235                                 pfc_pri2_rx_duration_us)},
236         {"pfc_pri2_rx_transitions", offsetof(struct rx_port_stats_ext,
237                                 pfc_pri2_rx_transitions)},
238         {"pfc_pri3_rx_duration_us", offsetof(struct rx_port_stats_ext,
239                                 pfc_pri3_rx_duration_us)},
240         {"pfc_pri3_rx_transitions", offsetof(struct rx_port_stats_ext,
241                                 pfc_pri3_rx_transitions)},
242         {"pfc_pri4_rx_duration_us", offsetof(struct rx_port_stats_ext,
243                                 pfc_pri4_rx_duration_us)},
244         {"pfc_pri4_rx_transitions", offsetof(struct rx_port_stats_ext,
245                                 pfc_pri4_rx_transitions)},
246         {"pfc_pri5_rx_duration_us", offsetof(struct rx_port_stats_ext,
247                                 pfc_pri5_rx_duration_us)},
248         {"pfc_pri5_rx_transitions", offsetof(struct rx_port_stats_ext,
249                                 pfc_pri5_rx_transitions)},
250         {"pfc_pri6_rx_duration_us", offsetof(struct rx_port_stats_ext,
251                                 pfc_pri6_rx_duration_us)},
252         {"pfc_pri6_rx_transitions", offsetof(struct rx_port_stats_ext,
253                                 pfc_pri6_rx_transitions)},
254         {"pfc_pri7_rx_duration_us", offsetof(struct rx_port_stats_ext,
255                                 pfc_pri7_rx_duration_us)},
256         {"pfc_pri7_rx_transitions", offsetof(struct rx_port_stats_ext,
257                                 pfc_pri7_rx_transitions)},
258 };
259
260 static const struct bnxt_xstats_name_off bnxt_tx_ext_stats_strings[] = {
261         {"tx_bytes_cos0", offsetof(struct tx_port_stats_ext,
262                                 tx_bytes_cos0)},
263         {"tx_bytes_cos1", offsetof(struct tx_port_stats_ext,
264                                 tx_bytes_cos1)},
265         {"tx_bytes_cos2", offsetof(struct tx_port_stats_ext,
266                                 tx_bytes_cos2)},
267         {"tx_bytes_cos3", offsetof(struct tx_port_stats_ext,
268                                 tx_bytes_cos3)},
269         {"tx_bytes_cos4", offsetof(struct tx_port_stats_ext,
270                                 tx_bytes_cos4)},
271         {"tx_bytes_cos5", offsetof(struct tx_port_stats_ext,
272                                 tx_bytes_cos5)},
273         {"tx_bytes_cos6", offsetof(struct tx_port_stats_ext,
274                                 tx_bytes_cos6)},
275         {"tx_bytes_cos7", offsetof(struct tx_port_stats_ext,
276                                 tx_bytes_cos7)},
277         {"tx_packets_cos0", offsetof(struct tx_port_stats_ext,
278                                 tx_packets_cos0)},
279         {"tx_packets_cos1", offsetof(struct tx_port_stats_ext,
280                                 tx_packets_cos1)},
281         {"tx_packets_cos2", offsetof(struct tx_port_stats_ext,
282                                 tx_packets_cos2)},
283         {"tx_packets_cos3", offsetof(struct tx_port_stats_ext,
284                                 tx_packets_cos3)},
285         {"tx_packets_cos4", offsetof(struct tx_port_stats_ext,
286                                 tx_packets_cos4)},
287         {"tx_packets_cos5", offsetof(struct tx_port_stats_ext,
288                                 tx_packets_cos5)},
289         {"tx_packets_cos6", offsetof(struct tx_port_stats_ext,
290                                 tx_packets_cos6)},
291         {"tx_packets_cos7", offsetof(struct tx_port_stats_ext,
292                                 tx_packets_cos7)},
293         {"pfc_pri0_tx_duration_us", offsetof(struct tx_port_stats_ext,
294                                 pfc_pri0_tx_duration_us)},
295         {"pfc_pri0_tx_transitions", offsetof(struct tx_port_stats_ext,
296                                 pfc_pri0_tx_transitions)},
297         {"pfc_pri1_tx_duration_us", offsetof(struct tx_port_stats_ext,
298                                 pfc_pri1_tx_duration_us)},
299         {"pfc_pri1_tx_transitions", offsetof(struct tx_port_stats_ext,
300                                 pfc_pri1_tx_transitions)},
301         {"pfc_pri2_tx_duration_us", offsetof(struct tx_port_stats_ext,
302                                 pfc_pri2_tx_duration_us)},
303         {"pfc_pri2_tx_transitions", offsetof(struct tx_port_stats_ext,
304                                 pfc_pri2_tx_transitions)},
305         {"pfc_pri3_tx_duration_us", offsetof(struct tx_port_stats_ext,
306                                 pfc_pri3_tx_duration_us)},
307         {"pfc_pri3_tx_transitions", offsetof(struct tx_port_stats_ext,
308                                 pfc_pri3_tx_transitions)},
309         {"pfc_pri4_tx_duration_us", offsetof(struct tx_port_stats_ext,
310                                 pfc_pri4_tx_duration_us)},
311         {"pfc_pri4_tx_transitions", offsetof(struct tx_port_stats_ext,
312                                 pfc_pri4_tx_transitions)},
313         {"pfc_pri5_tx_duration_us", offsetof(struct tx_port_stats_ext,
314                                 pfc_pri5_tx_duration_us)},
315         {"pfc_pri5_tx_transitions", offsetof(struct tx_port_stats_ext,
316                                 pfc_pri5_tx_transitions)},
317         {"pfc_pri6_tx_duration_us", offsetof(struct tx_port_stats_ext,
318                                 pfc_pri6_tx_duration_us)},
319         {"pfc_pri6_tx_transitions", offsetof(struct tx_port_stats_ext,
320                                 pfc_pri6_tx_transitions)},
321         {"pfc_pri7_tx_duration_us", offsetof(struct tx_port_stats_ext,
322                                 pfc_pri7_tx_duration_us)},
323         {"pfc_pri7_tx_transitions", offsetof(struct tx_port_stats_ext,
324                                 pfc_pri7_tx_transitions)},
325 };
326
327 /*
328  * Statistics functions
329  */
330
331 void bnxt_free_stats(struct bnxt *bp)
332 {
333         int i;
334
335         for (i = 0; i < (int)bp->tx_cp_nr_rings; i++) {
336                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
337
338                 bnxt_free_txq_stats(txq);
339         }
340         for (i = 0; i < (int)bp->rx_cp_nr_rings; i++) {
341                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
342
343                 bnxt_free_rxq_stats(rxq);
344         }
345 }
346
347 int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
348                            struct rte_eth_stats *bnxt_stats)
349 {
350         int rc = 0;
351         unsigned int i;
352         struct bnxt *bp = eth_dev->data->dev_private;
353
354         memset(bnxt_stats, 0, sizeof(*bnxt_stats));
355         if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
356                 PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
357                 return -1;
358         }
359
360         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
361                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
362                 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
363
364                 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
365                                      bnxt_stats, 1);
366                 if (unlikely(rc))
367                         return rc;
368                 bnxt_stats->rx_nombuf +=
369                                 rte_atomic64_read(&rxq->rx_mbuf_alloc_fail);
370         }
371
372         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
373                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
374                 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
375
376                 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
377                                      bnxt_stats, 0);
378                 if (unlikely(rc))
379                         return rc;
380         }
381         rc = bnxt_hwrm_func_qstats(bp, 0xffff, bnxt_stats);
382         if (unlikely(rc))
383                 return rc;
384         return rc;
385 }
386
387 void bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
388 {
389         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
390         unsigned int i;
391
392         if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
393                 PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
394                 return;
395         }
396
397         bnxt_clear_all_hwrm_stat_ctxs(bp);
398         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
399                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
400
401                 rte_atomic64_clear(&rxq->rx_mbuf_alloc_fail);
402         }
403 }
404
405 int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
406                            struct rte_eth_xstat *xstats, unsigned int n)
407 {
408         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
409
410         unsigned int count, i;
411         uint64_t tx_drop_pkts;
412         unsigned int rx_port_stats_ext_cnt;
413         unsigned int tx_port_stats_ext_cnt;
414         unsigned int stat_size = sizeof(uint64_t);
415         unsigned int stat_count;
416
417         bnxt_hwrm_port_qstats(bp);
418         bnxt_hwrm_func_qstats_tx_drop(bp, 0xffff, &tx_drop_pkts);
419         bnxt_hwrm_ext_port_qstats(bp);
420         rx_port_stats_ext_cnt = bp->fw_rx_port_stats_ext_size / stat_size;
421         tx_port_stats_ext_cnt = bp->fw_tx_port_stats_ext_size / stat_size;
422
423         count = RTE_DIM(bnxt_rx_stats_strings) +
424                 RTE_DIM(bnxt_tx_stats_strings) + 1/* For tx_drop_pkts */ +
425                 RTE_DIM(bnxt_rx_ext_stats_strings) +
426                 RTE_DIM(bnxt_tx_ext_stats_strings);
427         stat_count = count;
428
429         if (n < count)
430                 return count;
431
432         count = 0;
433         for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
434                 uint64_t *rx_stats = (uint64_t *)bp->hw_rx_port_stats;
435                 xstats[count].id = count;
436                 xstats[count].value = rte_le_to_cpu_64(
437                                 *(uint64_t *)((char *)rx_stats +
438                                 bnxt_rx_stats_strings[i].offset));
439                 count++;
440         }
441
442         for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
443                 uint64_t *tx_stats = (uint64_t *)bp->hw_tx_port_stats;
444                 xstats[count].id = count;
445                 xstats[count].value = rte_le_to_cpu_64(
446                                  *(uint64_t *)((char *)tx_stats +
447                                 bnxt_tx_stats_strings[i].offset));
448                 count++;
449         }
450
451         /* The Tx drop pkts aka the Anti spoof coounter */
452         xstats[count].id = count;
453         xstats[count].value = rte_le_to_cpu_64(tx_drop_pkts);
454         count++;
455
456         for (i = 0; i < tx_port_stats_ext_cnt; i++) {
457                 uint64_t *tx_stats_ext = (uint64_t *)bp->hw_tx_port_stats_ext;
458
459                 xstats[count].value = rte_le_to_cpu_64
460                                         (*(uint64_t *)((char *)tx_stats_ext +
461                                          bnxt_tx_ext_stats_strings[i].offset));
462
463                 count++;
464         }
465
466         for (i = 0; i < rx_port_stats_ext_cnt; i++) {
467                 uint64_t *rx_stats_ext = (uint64_t *)bp->hw_rx_port_stats_ext;
468
469                 xstats[count].value = rte_le_to_cpu_64
470                                         (*(uint64_t *)((char *)rx_stats_ext +
471                                          bnxt_rx_ext_stats_strings[i].offset));
472
473                 count++;
474         }
475
476         return stat_count;
477 }
478
479 int bnxt_dev_xstats_get_names_op(__rte_unused struct rte_eth_dev *eth_dev,
480         struct rte_eth_xstat_name *xstats_names,
481         __rte_unused unsigned int limit)
482 {
483         /* Account for the Tx drop pkts aka the Anti spoof counter */
484         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
485                                 RTE_DIM(bnxt_tx_stats_strings) + 1 +
486                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
487                                 RTE_DIM(bnxt_tx_ext_stats_strings);
488         unsigned int i, count;
489
490         if (xstats_names != NULL) {
491                 count = 0;
492
493                 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
494                         snprintf(xstats_names[count].name,
495                                 sizeof(xstats_names[count].name),
496                                 "%s",
497                                 bnxt_rx_stats_strings[i].name);
498                         count++;
499                 }
500
501                 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
502                         snprintf(xstats_names[count].name,
503                                 sizeof(xstats_names[count].name),
504                                 "%s",
505                                 bnxt_tx_stats_strings[i].name);
506                         count++;
507                 }
508
509                 snprintf(xstats_names[count].name,
510                                 sizeof(xstats_names[count].name),
511                                 "%s",
512                                 bnxt_func_stats_strings[4].name);
513                 count++;
514
515                 for (i = 0; i < RTE_DIM(bnxt_rx_ext_stats_strings); i++) {
516                         snprintf(xstats_names[count].name,
517                                  sizeof(xstats_names[count].name),
518                                  "%s",
519                                  bnxt_rx_ext_stats_strings[i].name);
520
521                         count++;
522                 }
523
524                 for (i = 0; i < RTE_DIM(bnxt_tx_ext_stats_strings); i++) {
525                         snprintf(xstats_names[count].name,
526                                  sizeof(xstats_names[count].name),
527                                  "%s",
528                                  bnxt_tx_ext_stats_strings[i].name);
529
530                         count++;
531                 }
532
533         }
534         return stat_cnt;
535 }
536
537 void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
538 {
539         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
540
541         if (bp->flags & BNXT_FLAG_PORT_STATS && BNXT_SINGLE_PF(bp))
542                 bnxt_hwrm_port_clr_stats(bp);
543
544         if (BNXT_VF(bp))
545                 PMD_DRV_LOG(ERR, "Operation not supported on a VF device\n");
546         if (!BNXT_SINGLE_PF(bp))
547                 PMD_DRV_LOG(ERR, "Operation not supported on a MF device\n");
548         if (!(bp->flags & BNXT_FLAG_PORT_STATS))
549                 PMD_DRV_LOG(ERR, "Operation not supported\n");
550 }
551
552 int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
553                 uint64_t *values, unsigned int limit)
554 {
555         /* Account for the Tx drop pkts aka the Anti spoof counter */
556         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
557                                 RTE_DIM(bnxt_tx_stats_strings) + 1 +
558                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
559                                 RTE_DIM(bnxt_tx_ext_stats_strings);
560         struct rte_eth_xstat xstats[stat_cnt];
561         uint64_t values_copy[stat_cnt];
562         uint16_t i;
563
564         if (!ids)
565                 return bnxt_dev_xstats_get_op(dev, xstats, stat_cnt);
566
567         bnxt_dev_xstats_get_by_id_op(dev, NULL, values_copy, stat_cnt);
568         for (i = 0; i < limit; i++) {
569                 if (ids[i] >= stat_cnt) {
570                         PMD_DRV_LOG(ERR, "id value isn't valid");
571                         return -1;
572                 }
573                 values[i] = values_copy[ids[i]];
574         }
575         return stat_cnt;
576 }
577
578 int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
579                                 struct rte_eth_xstat_name *xstats_names,
580                                 const uint64_t *ids, unsigned int limit)
581 {
582         /* Account for the Tx drop pkts aka the Anti spoof counter */
583         const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
584                                 RTE_DIM(bnxt_tx_stats_strings) + 1 +
585                                 RTE_DIM(bnxt_rx_ext_stats_strings) +
586                                 RTE_DIM(bnxt_tx_ext_stats_strings);
587         struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
588         uint16_t i;
589
590         if (!ids)
591                 return bnxt_dev_xstats_get_names_op(dev, xstats_names,
592                                                     stat_cnt);
593         bnxt_dev_xstats_get_names_by_id_op(dev, xstats_names_copy, NULL,
594                         stat_cnt);
595
596         for (i = 0; i < limit; i++) {
597                 if (ids[i] >= stat_cnt) {
598                         PMD_DRV_LOG(ERR, "id value isn't valid");
599                         return -1;
600                 }
601                 strcpy(xstats_names[i].name,
602                                 xstats_names_copy[ids[i]].name);
603         }
604         return stat_cnt;
605 }