1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_byteorder.h>
12 #include "bnxt_hwrm.h"
14 #include "bnxt_stats.h"
16 #include "hsi_struct_def_dpdk.h"
18 static const struct bnxt_xstats_name_off bnxt_rx_stats_strings[] = {
19 {"rx_64b_frames", offsetof(struct rx_port_stats,
21 {"rx_65b_127b_frames", offsetof(struct rx_port_stats,
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_1518_frames", offsetof(struct rx_port_stats,
30 rx_1024b_1518_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,
43 {"rx_ucast_frames", offsetof(struct rx_port_stats,
45 {"rx_mcast_frames", offsetof(struct rx_port_stats,
47 {"rx_bcast_frames", offsetof(struct rx_port_stats,
49 {"rx_fcs_err_frames", offsetof(struct rx_port_stats,
51 {"rx_ctrl_frames", offsetof(struct rx_port_stats,
53 {"rx_pause_frames", offsetof(struct rx_port_stats,
55 {"rx_pfc_frames", offsetof(struct rx_port_stats,
57 {"rx_align_err_frames", offsetof(struct rx_port_stats,
58 rx_align_err_frames)},
59 {"rx_ovrsz_frames", offsetof(struct rx_port_stats,
61 {"rx_jbr_frames", offsetof(struct rx_port_stats,
63 {"rx_mtu_err_frames", offsetof(struct rx_port_stats,
65 {"rx_tagged_frames", offsetof(struct rx_port_stats,
67 {"rx_double_tagged_frames", offsetof(struct rx_port_stats,
68 rx_double_tagged_frames)},
69 {"rx_good_frames", offsetof(struct rx_port_stats,
71 {"rx_undrsz_frames", offsetof(struct rx_port_stats,
73 {"rx_eee_lpi_events", offsetof(struct rx_port_stats,
75 {"rx_eee_lpi_duration", offsetof(struct rx_port_stats,
76 rx_eee_lpi_duration)},
77 {"rx_bytes", offsetof(struct rx_port_stats,
79 {"rx_runt_bytes", offsetof(struct rx_port_stats,
81 {"rx_runt_frames", offsetof(struct rx_port_stats,
85 static const struct bnxt_xstats_name_off bnxt_tx_stats_strings[] = {
86 {"tx_64b_frames", offsetof(struct tx_port_stats,
88 {"tx_65b_127b_frames", offsetof(struct tx_port_stats,
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_1518_frames", offsetof(struct tx_port_stats,
97 tx_1024b_1518_frames)},
98 {"tx_good_vlan_frames", offsetof(struct tx_port_stats,
99 tx_good_vlan_frames)},
100 {"tx_1519b_2047_frames", offsetof(struct tx_port_stats,
101 tx_1519b_2047_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,
110 {"tx_total_frames", offsetof(struct tx_port_stats,
112 {"tx_ucast_frames", offsetof(struct tx_port_stats,
114 {"tx_mcast_frames", offsetof(struct tx_port_stats,
116 {"tx_bcast_frames", offsetof(struct tx_port_stats,
118 {"tx_pause_frames", offsetof(struct tx_port_stats,
120 {"tx_pfc_frames", offsetof(struct tx_port_stats,
122 {"tx_jabber_frames", offsetof(struct tx_port_stats,
124 {"tx_fcs_err_frames", offsetof(struct tx_port_stats,
126 {"tx_err", offsetof(struct tx_port_stats,
128 {"tx_fifo_underruns", offsetof(struct tx_port_stats,
130 {"tx_eee_lpi_events", offsetof(struct tx_port_stats,
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,
140 static const struct bnxt_xstats_name_off bnxt_func_stats_strings[] = {
141 {"tx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
143 {"tx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
145 {"tx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
147 {"tx_err_pkts", offsetof(struct hwrm_func_qstats_output,
149 {"tx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
151 {"tx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
153 {"tx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
155 {"tx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
157 {"rx_ucast_pkts", offsetof(struct hwrm_func_qstats_output,
159 {"rx_mcast_pkts", offsetof(struct hwrm_func_qstats_output,
161 {"rx_bcast_pkts", offsetof(struct hwrm_func_qstats_output,
163 {"rx_err_pkts", offsetof(struct hwrm_func_qstats_output,
165 {"rx_drop_pkts", offsetof(struct hwrm_func_qstats_output,
167 {"rx_ucast_bytes", offsetof(struct hwrm_func_qstats_output,
169 {"rx_mcast_bytes", offsetof(struct hwrm_func_qstats_output,
171 {"rx_bcast_bytes", offsetof(struct hwrm_func_qstats_output,
173 {"rx_agg_pkts", offsetof(struct hwrm_func_qstats_output,
175 {"rx_agg_bytes", offsetof(struct hwrm_func_qstats_output,
177 {"rx_agg_events", offsetof(struct hwrm_func_qstats_output,
179 {"rx_agg_aborts", offsetof(struct hwrm_func_qstats_output,
184 * Statistics functions
187 void bnxt_free_stats(struct bnxt *bp)
191 for (i = 0; i < (int)bp->tx_cp_nr_rings; i++) {
192 struct bnxt_tx_queue *txq = bp->tx_queues[i];
194 bnxt_free_txq_stats(txq);
196 for (i = 0; i < (int)bp->rx_cp_nr_rings; i++) {
197 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
199 bnxt_free_rxq_stats(rxq);
203 int bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
204 struct rte_eth_stats *bnxt_stats)
208 struct bnxt *bp = eth_dev->data->dev_private;
210 memset(bnxt_stats, 0, sizeof(*bnxt_stats));
211 if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
212 PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
216 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
217 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
218 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
220 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
226 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
227 struct bnxt_tx_queue *txq = bp->tx_queues[i];
228 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
230 rc = bnxt_hwrm_ctx_qstats(bp, cpr->hw_stats_ctx_id, i,
235 rc = bnxt_hwrm_func_qstats(bp, 0xffff, bnxt_stats);
238 bnxt_stats->rx_nombuf = rte_atomic64_read(&bp->rx_mbuf_alloc_fail);
242 void bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
244 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
246 if (!(bp->flags & BNXT_FLAG_INIT_DONE)) {
247 PMD_DRV_LOG(ERR, "Device Initialization not complete!\n");
251 bnxt_clear_all_hwrm_stat_ctxs(bp);
252 rte_atomic64_clear(&bp->rx_mbuf_alloc_fail);
255 int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
256 struct rte_eth_xstat *xstats, unsigned int n)
258 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
260 unsigned int count, i;
261 uint64_t tx_drop_pkts;
263 if (!(bp->flags & BNXT_FLAG_PORT_STATS)) {
264 PMD_DRV_LOG(ERR, "xstats not supported for VF\n");
268 bnxt_hwrm_port_qstats(bp);
269 bnxt_hwrm_func_qstats_tx_drop(bp, 0xffff, &tx_drop_pkts);
271 count = RTE_DIM(bnxt_rx_stats_strings) +
272 RTE_DIM(bnxt_tx_stats_strings) + 1; /* For tx_drop_pkts */
278 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
279 uint64_t *rx_stats = (uint64_t *)bp->hw_rx_port_stats;
280 xstats[count].value = rte_le_to_cpu_64(
281 *(uint64_t *)((char *)rx_stats +
282 bnxt_rx_stats_strings[i].offset));
286 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
287 uint64_t *tx_stats = (uint64_t *)bp->hw_tx_port_stats;
288 xstats[count].value = rte_le_to_cpu_64(
289 *(uint64_t *)((char *)tx_stats +
290 bnxt_tx_stats_strings[i].offset));
294 /* The Tx drop pkts aka the Anti spoof coounter */
295 xstats[count].value = rte_le_to_cpu_64(tx_drop_pkts);
301 int bnxt_dev_xstats_get_names_op(__rte_unused struct rte_eth_dev *eth_dev,
302 struct rte_eth_xstat_name *xstats_names,
303 __rte_unused unsigned int limit)
305 /* Account for the Tx drop pkts aka the Anti spoof counter */
306 const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
307 RTE_DIM(bnxt_tx_stats_strings) + 1;
308 unsigned int i, count;
310 if (xstats_names != NULL) {
313 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
314 snprintf(xstats_names[count].name,
315 sizeof(xstats_names[count].name),
317 bnxt_rx_stats_strings[i].name);
321 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
322 snprintf(xstats_names[count].name,
323 sizeof(xstats_names[count].name),
325 bnxt_tx_stats_strings[i].name);
329 snprintf(xstats_names[count].name,
330 sizeof(xstats_names[count].name),
332 bnxt_func_stats_strings[4].name);
338 void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
340 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
342 if (bp->flags & BNXT_FLAG_PORT_STATS && BNXT_SINGLE_PF(bp))
343 bnxt_hwrm_port_clr_stats(bp);
346 PMD_DRV_LOG(ERR, "Operation not supported on a VF device\n");
347 if (!BNXT_SINGLE_PF(bp))
348 PMD_DRV_LOG(ERR, "Operation not supported on a MF device\n");
349 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
350 PMD_DRV_LOG(ERR, "Operation not supported\n");
353 int bnxt_dev_xstats_get_by_id_op(struct rte_eth_dev *dev, const uint64_t *ids,
354 uint64_t *values, unsigned int limit)
356 /* Account for the Tx drop pkts aka the Anti spoof counter */
357 const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
358 RTE_DIM(bnxt_tx_stats_strings) + 1;
359 struct rte_eth_xstat xstats[stat_cnt];
360 uint64_t values_copy[stat_cnt];
364 return bnxt_dev_xstats_get_op(dev, xstats, stat_cnt);
366 bnxt_dev_xstats_get_by_id_op(dev, NULL, values_copy, stat_cnt);
367 for (i = 0; i < limit; i++) {
368 if (ids[i] >= stat_cnt) {
369 PMD_DRV_LOG(ERR, "id value isn't valid");
372 values[i] = values_copy[ids[i]];
377 int bnxt_dev_xstats_get_names_by_id_op(struct rte_eth_dev *dev,
378 struct rte_eth_xstat_name *xstats_names,
379 const uint64_t *ids, unsigned int limit)
381 /* Account for the Tx drop pkts aka the Anti spoof counter */
382 const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
383 RTE_DIM(bnxt_tx_stats_strings) + 1;
384 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
388 return bnxt_dev_xstats_get_names_op(dev, xstats_names,
390 bnxt_dev_xstats_get_names_by_id_op(dev, xstats_names_copy, NULL,
393 for (i = 0; i < limit; i++) {
394 if (ids[i] >= stat_cnt) {
395 PMD_DRV_LOG(ERR, "id value isn't valid");
398 strcpy(xstats_names[i].name,
399 xstats_names_copy[ids[i]].name);