4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_byteorder.h>
40 #include "bnxt_hwrm.h"
42 #include "bnxt_stats.h"
44 #include "hsi_struct_def_dpdk.h"
46 static const struct bnxt_xstats_name_off bnxt_rx_stats_strings[] = {
47 {"rx_64b_frames", offsetof(struct rx_port_stats,
49 {"rx_65b_127b_frames", offsetof(struct rx_port_stats,
51 {"rx_128b_255b_frames", offsetof(struct rx_port_stats,
52 rx_128b_255b_frames)},
53 {"rx_256b_511b_frames", offsetof(struct rx_port_stats,
54 rx_256b_511b_frames)},
55 {"rx_512b_1023b_frames", offsetof(struct rx_port_stats,
56 rx_512b_1023b_frames)},
57 {"rx_1024b_1518_frames", offsetof(struct rx_port_stats,
58 rx_1024b_1518_frames)},
59 {"rx_good_vlan_frames", offsetof(struct rx_port_stats,
60 rx_good_vlan_frames)},
61 {"rx_1519b_2047b_frames", offsetof(struct rx_port_stats,
62 rx_1519b_2047b_frames)},
63 {"rx_2048b_4095b_frames", offsetof(struct rx_port_stats,
64 rx_2048b_4095b_frames)},
65 {"rx_4096b_9216b_frames", offsetof(struct rx_port_stats,
66 rx_4096b_9216b_frames)},
67 {"rx_9217b_16383b_frames", offsetof(struct rx_port_stats,
68 rx_9217b_16383b_frames)},
69 {"rx_total_frames", offsetof(struct rx_port_stats,
71 {"rx_ucast_frames", offsetof(struct rx_port_stats,
73 {"rx_mcast_frames", offsetof(struct rx_port_stats,
75 {"rx_bcast_frames", offsetof(struct rx_port_stats,
77 {"rx_fcs_err_frames", offsetof(struct rx_port_stats,
79 {"rx_ctrl_frames", offsetof(struct rx_port_stats,
81 {"rx_pause_frames", offsetof(struct rx_port_stats,
83 {"rx_pfc_frames", offsetof(struct rx_port_stats,
85 {"rx_align_err_frames", offsetof(struct rx_port_stats,
86 rx_align_err_frames)},
87 {"rx_ovrsz_frames", offsetof(struct rx_port_stats,
89 {"rx_jbr_frames", offsetof(struct rx_port_stats,
91 {"rx_mtu_err_frames", offsetof(struct rx_port_stats,
93 {"rx_tagged_frames", offsetof(struct rx_port_stats,
95 {"rx_double_tagged_frames", offsetof(struct rx_port_stats,
96 rx_double_tagged_frames)},
97 {"rx_good_frames", offsetof(struct rx_port_stats,
99 {"rx_undrsz_frames", offsetof(struct rx_port_stats,
101 {"rx_eee_lpi_events", offsetof(struct rx_port_stats,
103 {"rx_eee_lpi_duration", offsetof(struct rx_port_stats,
104 rx_eee_lpi_duration)},
105 {"rx_bytes", offsetof(struct rx_port_stats,
107 {"rx_runt_bytes", offsetof(struct rx_port_stats,
109 {"rx_runt_frames", offsetof(struct rx_port_stats,
113 static const struct bnxt_xstats_name_off bnxt_tx_stats_strings[] = {
114 {"tx_64b_frames", offsetof(struct tx_port_stats,
116 {"tx_65b_127b_frames", offsetof(struct tx_port_stats,
117 tx_65b_127b_frames)},
118 {"tx_128b_255b_frames", offsetof(struct tx_port_stats,
119 tx_128b_255b_frames)},
120 {"tx_256b_511b_frames", offsetof(struct tx_port_stats,
121 tx_256b_511b_frames)},
122 {"tx_512b_1023b_frames", offsetof(struct tx_port_stats,
123 tx_512b_1023b_frames)},
124 {"tx_1024b_1518_frames", offsetof(struct tx_port_stats,
125 tx_1024b_1518_frames)},
126 {"tx_good_vlan_frames", offsetof(struct tx_port_stats,
127 tx_good_vlan_frames)},
128 {"tx_1519b_2047_frames", offsetof(struct tx_port_stats,
129 tx_1519b_2047_frames)},
130 {"tx_2048b_4095b_frames", offsetof(struct tx_port_stats,
131 tx_2048b_4095b_frames)},
132 {"tx_4096b_9216b_frames", offsetof(struct tx_port_stats,
133 tx_4096b_9216b_frames)},
134 {"tx_9217b_16383b_frames", offsetof(struct tx_port_stats,
135 tx_9217b_16383b_frames)},
136 {"tx_good_frames", offsetof(struct tx_port_stats,
138 {"tx_total_frames", offsetof(struct tx_port_stats,
140 {"tx_ucast_frames", offsetof(struct tx_port_stats,
142 {"tx_mcast_frames", offsetof(struct tx_port_stats,
144 {"tx_bcast_frames", offsetof(struct tx_port_stats,
146 {"tx_pause_frames", offsetof(struct tx_port_stats,
148 {"tx_pfc_frames", offsetof(struct tx_port_stats,
150 {"tx_jabber_frames", offsetof(struct tx_port_stats,
152 {"tx_fcs_err_frames", offsetof(struct tx_port_stats,
154 {"tx_err", offsetof(struct tx_port_stats,
156 {"tx_fifo_underruns", offsetof(struct tx_port_stats,
158 {"tx_eee_lpi_events", offsetof(struct tx_port_stats,
160 {"tx_eee_lpi_duration", offsetof(struct tx_port_stats,
161 tx_eee_lpi_duration)},
162 {"tx_total_collisions", offsetof(struct tx_port_stats,
163 tx_total_collisions)},
164 {"tx_bytes", offsetof(struct tx_port_stats,
169 * Statistics functions
172 void bnxt_free_stats(struct bnxt *bp)
176 for (i = 0; i < (int)bp->tx_cp_nr_rings; i++) {
177 struct bnxt_tx_queue *txq = bp->tx_queues[i];
179 bnxt_free_txq_stats(txq);
181 for (i = 0; i < (int)bp->rx_cp_nr_rings; i++) {
182 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
184 bnxt_free_rxq_stats(rxq);
188 void bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
189 struct rte_eth_stats *bnxt_stats)
192 struct bnxt *bp = eth_dev->data->dev_private;
194 memset(bnxt_stats, 0, sizeof(*bnxt_stats));
196 for (i = 0; i < bp->rx_cp_nr_rings; i++) {
197 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
198 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
199 struct ctx_hw_stats64 *hw_stats =
200 (struct ctx_hw_stats64 *)cpr->hw_stats;
202 bnxt_stats->q_ipackets[i] +=
203 rte_le_to_cpu_64(hw_stats->rx_ucast_pkts);
204 bnxt_stats->q_ipackets[i] +=
205 rte_le_to_cpu_64(hw_stats->rx_mcast_pkts);
206 bnxt_stats->q_ipackets[i] +=
207 rte_le_to_cpu_64(hw_stats->rx_bcast_pkts);
209 bnxt_stats->q_ibytes[i] +=
210 rte_le_to_cpu_64(hw_stats->rx_ucast_bytes);
211 bnxt_stats->q_ibytes[i] +=
212 rte_le_to_cpu_64(hw_stats->rx_mcast_bytes);
213 bnxt_stats->q_ibytes[i] +=
214 rte_le_to_cpu_64(hw_stats->rx_bcast_bytes);
217 * TBD: No clear mapping to this... we don't seem
218 * to have a stat specifically for dropped due to
219 * insufficient mbufs.
221 bnxt_stats->q_errors[i] = 0;
223 /* These get replaced once the *_QSTATS commands work */
224 bnxt_stats->ipackets += bnxt_stats->q_ipackets[i];
225 bnxt_stats->ibytes += bnxt_stats->q_ibytes[i];
226 bnxt_stats->imissed += bnxt_stats->q_errors[i];
227 bnxt_stats->ierrors +=
228 rte_le_to_cpu_64(hw_stats->rx_discard_pkts);
231 for (i = 0; i < bp->tx_cp_nr_rings; i++) {
232 struct bnxt_tx_queue *txq = bp->tx_queues[i];
233 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
234 struct ctx_hw_stats64 *hw_stats =
235 (struct ctx_hw_stats64 *)cpr->hw_stats;
237 bnxt_stats->q_opackets[i] +=
238 rte_le_to_cpu_64(hw_stats->tx_ucast_pkts);
239 bnxt_stats->q_opackets[i] +=
240 rte_le_to_cpu_64(hw_stats->tx_mcast_pkts);
241 bnxt_stats->q_opackets[i] +=
242 rte_le_to_cpu_64(hw_stats->tx_bcast_pkts);
244 bnxt_stats->q_obytes[i] +=
245 rte_le_to_cpu_64(hw_stats->tx_ucast_bytes);
246 bnxt_stats->q_obytes[i] +=
247 rte_le_to_cpu_64(hw_stats->tx_mcast_bytes);
248 bnxt_stats->q_obytes[i] +=
249 rte_le_to_cpu_64(hw_stats->tx_bcast_bytes);
251 /* These get replaced once the *_QSTATS commands work */
252 bnxt_stats->opackets += bnxt_stats->q_opackets[i];
253 bnxt_stats->obytes += bnxt_stats->q_obytes[i];
254 bnxt_stats->oerrors += rte_le_to_cpu_64(hw_stats->tx_drop_pkts);
255 bnxt_stats->oerrors += rte_le_to_cpu_64(hw_stats->tx_discard_pkts);
259 void bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
261 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
263 bnxt_clear_all_hwrm_stat_ctxs(bp);
266 int bnxt_dev_xstats_get_op(struct rte_eth_dev *eth_dev,
267 struct rte_eth_xstat *xstats, unsigned int n)
269 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
271 unsigned int count, i;
273 if (!(bp->flags & BNXT_FLAG_PORT_STATS)) {
274 RTE_LOG(ERR, PMD, "xstats not supported for VF\n");
278 bnxt_hwrm_port_qstats(bp);
280 count = RTE_DIM(bnxt_rx_stats_strings) +
281 RTE_DIM(bnxt_tx_stats_strings);
287 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
288 uint64_t *rx_stats = (uint64_t *)bp->hw_rx_port_stats;
289 xstats[count].value = rte_le_to_cpu_64(
290 *(uint64_t *)((char *)rx_stats +
291 bnxt_rx_stats_strings[i].offset));
295 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
296 uint64_t *tx_stats = (uint64_t *)bp->hw_tx_port_stats;
297 xstats[count].value = rte_le_to_cpu_64(
298 *(uint64_t *)((char *)tx_stats +
299 bnxt_tx_stats_strings[i].offset));
306 int bnxt_dev_xstats_get_names_op(__rte_unused struct rte_eth_dev *eth_dev,
307 struct rte_eth_xstat_name *xstats_names,
308 __rte_unused unsigned int limit)
310 const unsigned int stat_cnt = RTE_DIM(bnxt_rx_stats_strings) +
311 RTE_DIM(bnxt_tx_stats_strings);
312 unsigned int i, count;
314 if (xstats_names != NULL) {
317 for (i = 0; i < RTE_DIM(bnxt_rx_stats_strings); i++) {
318 snprintf(xstats_names[count].name,
319 sizeof(xstats_names[count].name),
321 bnxt_rx_stats_strings[i].name);
325 for (i = 0; i < RTE_DIM(bnxt_tx_stats_strings); i++) {
326 snprintf(xstats_names[count].name,
327 sizeof(xstats_names[count].name),
329 bnxt_tx_stats_strings[i].name);
336 void bnxt_dev_xstats_reset_op(struct rte_eth_dev *eth_dev)
338 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
340 if (bp->flags & BNXT_FLAG_PORT_STATS && !BNXT_NPAR_PF(bp))
341 bnxt_hwrm_port_clr_stats(bp);
344 RTE_LOG(ERR, PMD, "Operation not supported on a VF device\n");
345 if (BNXT_NPAR_PF(bp))
346 RTE_LOG(ERR, PMD, "Operation not supported on a MF device\n");
347 if (!(bp->flags & BNXT_FLAG_PORT_STATS))
348 RTE_LOG(ERR, PMD, "Operation not supported\n");