4 * Copyright 2015 6WIND S.A.
5 * Copyright 2015 Mellanox.
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 6WIND S.A. 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.
34 /* DPDK headers don't like -pedantic. */
36 #pragma GCC diagnostic ignored "-pedantic"
38 #include <rte_ethdev.h>
40 #pragma GCC diagnostic error "-pedantic"
44 #include "mlx5_rxtx.h"
45 #include "mlx5_defs.h"
48 * DPDK callback to get device statistics.
51 * Pointer to Ethernet device structure.
53 * Stats structure output buffer.
56 mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
58 struct priv *priv = dev->data->dev_private;
59 struct rte_eth_stats tmp = {0};
64 /* Add software counters. */
65 for (i = 0; (i != priv->rxqs_n); ++i) {
66 struct rxq *rxq = (*priv->rxqs)[i];
71 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
72 #ifdef MLX5_PMD_SOFT_COUNTERS
73 tmp.q_ipackets[idx] += rxq->stats.ipackets;
74 tmp.q_ibytes[idx] += rxq->stats.ibytes;
76 tmp.q_errors[idx] += (rxq->stats.idropped +
77 rxq->stats.rx_nombuf);
79 #ifdef MLX5_PMD_SOFT_COUNTERS
80 tmp.ipackets += rxq->stats.ipackets;
81 tmp.ibytes += rxq->stats.ibytes;
83 tmp.ierrors += rxq->stats.idropped;
84 tmp.rx_nombuf += rxq->stats.rx_nombuf;
86 for (i = 0; (i != priv->txqs_n); ++i) {
87 struct txq *txq = (*priv->txqs)[i];
92 if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
93 #ifdef MLX5_PMD_SOFT_COUNTERS
94 tmp.q_opackets[idx] += txq->stats.opackets;
95 tmp.q_obytes[idx] += txq->stats.obytes;
97 tmp.q_errors[idx] += txq->stats.odropped;
99 #ifdef MLX5_PMD_SOFT_COUNTERS
100 tmp.opackets += txq->stats.opackets;
101 tmp.obytes += txq->stats.obytes;
103 tmp.oerrors += txq->stats.odropped;
105 #ifndef MLX5_PMD_SOFT_COUNTERS
106 /* FIXME: retrieve and add hardware counters. */
113 * DPDK callback to clear device statistics.
116 * Pointer to Ethernet device structure.
119 mlx5_stats_reset(struct rte_eth_dev *dev)
121 struct priv *priv = dev->data->dev_private;
126 for (i = 0; (i != priv->rxqs_n); ++i) {
127 if ((*priv->rxqs)[i] == NULL)
129 idx = (*priv->rxqs)[i]->stats.idx;
130 (*priv->rxqs)[i]->stats =
131 (struct mlx5_rxq_stats){ .idx = idx };
133 for (i = 0; (i != priv->txqs_n); ++i) {
134 if ((*priv->txqs)[i] == NULL)
136 idx = (*priv->txqs)[i]->stats.idx;
137 (*priv->txqs)[i]->stats =
138 (struct mlx5_txq_stats){ .idx = idx };
140 #ifndef MLX5_PMD_SOFT_COUNTERS
141 /* FIXME: reset hardware counters. */