197f17497SC.J. Collier/*-
297f17497SC.J. Collier *   BSD LICENSE
397f17497SC.J. Collier *
497f17497SC.J. Collier *   Copyright 2015 6WIND S.A.
597f17497SC.J. Collier *   Copyright 2015 Mellanox.
697f17497SC.J. Collier *
797f17497SC.J. Collier *   Redistribution and use in source and binary forms, with or without
897f17497SC.J. Collier *   modification, are permitted provided that the following conditions
997f17497SC.J. Collier *   are met:
1097f17497SC.J. Collier *
1197f17497SC.J. Collier *     * Redistributions of source code must retain the above copyright
1297f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer.
1397f17497SC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
1497f17497SC.J. Collier *       notice, this list of conditions and the following disclaimer in
1597f17497SC.J. Collier *       the documentation and/or other materials provided with the
1697f17497SC.J. Collier *       distribution.
1797f17497SC.J. Collier *     * Neither the name of 6WIND S.A. nor the names of its
1897f17497SC.J. Collier *       contributors may be used to endorse or promote products derived
1997f17497SC.J. Collier *       from this software without specific prior written permission.
2097f17497SC.J. Collier *
2197f17497SC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2297f17497SC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2397f17497SC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2497f17497SC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2597f17497SC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2697f17497SC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2797f17497SC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2897f17497SC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2997f17497SC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3097f17497SC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3197f17497SC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3297f17497SC.J. Collier */
3397f17497SC.J. Collier
3497f17497SC.J. Collier/* DPDK headers don't like -pedantic. */
3597f17497SC.J. Collier#ifdef PEDANTIC
3632e04ea0SChristian Ehrhardt#pragma GCC diagnostic ignored "-Wpedantic"
3797f17497SC.J. Collier#endif
3897f17497SC.J. Collier#include <rte_ethdev.h>
3997f17497SC.J. Collier#ifdef PEDANTIC
4032e04ea0SChristian Ehrhardt#pragma GCC diagnostic error "-Wpedantic"
4197f17497SC.J. Collier#endif
4297f17497SC.J. Collier
4397f17497SC.J. Collier#include "mlx5.h"
4497f17497SC.J. Collier#include "mlx5_rxtx.h"
4597f17497SC.J. Collier#include "mlx5_defs.h"
4697f17497SC.J. Collier
4797f17497SC.J. Collier/**
4897f17497SC.J. Collier * DPDK callback to get device statistics.
4997f17497SC.J. Collier *
5097f17497SC.J. Collier * @param dev
5197f17497SC.J. Collier *   Pointer to Ethernet device structure.
5297f17497SC.J. Collier * @param[out] stats
5397f17497SC.J. Collier *   Stats structure output buffer.
5497f17497SC.J. Collier */
5597f17497SC.J. Colliervoid
5697f17497SC.J. Colliermlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
5797f17497SC.J. Collier{
5897f17497SC.J. Collier	struct priv *priv = mlx5_get_priv(dev);
5997f17497SC.J. Collier	struct rte_eth_stats tmp = {0};
6097f17497SC.J. Collier	unsigned int i;
6197f17497SC.J. Collier	unsigned int idx;
6297f17497SC.J. Collier
6397f17497SC.J. Collier	priv_lock(priv);
6497f17497SC.J. Collier	/* Add software counters. */
6597f17497SC.J. Collier	for (i = 0; (i != priv->rxqs_n); ++i) {
6697f17497SC.J. Collier		struct rxq *rxq = (*priv->rxqs)[i];
6797f17497SC.J. Collier
6897f17497SC.J. Collier		if (rxq == NULL)
6997f17497SC.J. Collier			continue;
7097f17497SC.J. Collier		idx = rxq->stats.idx;
7197f17497SC.J. Collier		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
7297f17497SC.J. Collier#ifdef MLX5_PMD_SOFT_COUNTERS
7397f17497SC.J. Collier			tmp.q_ipackets[idx] += rxq->stats.ipackets;
7497f17497SC.J. Collier			tmp.q_ibytes[idx] += rxq->stats.ibytes;
7597f17497SC.J. Collier#endif
7697f17497SC.J. Collier			tmp.q_errors[idx] += (rxq->stats.idropped +
7797f17497SC.J. Collier					      rxq->stats.rx_nombuf);
7897f17497SC.J. Collier		}
7997f17497SC.J. Collier#ifdef MLX5_PMD_SOFT_COUNTERS
8097f17497SC.J. Collier		tmp.ipackets += rxq->stats.ipackets;
8197f17497SC.J. Collier		tmp.ibytes += rxq->stats.ibytes;
8297f17497SC.J. Collier#endif
8397f17497SC.J. Collier		tmp.ierrors += rxq->stats.idropped;
8497f17497SC.J. Collier		tmp.rx_nombuf += rxq->stats.rx_nombuf;
8597f17497SC.J. Collier	}
8697f17497SC.J. Collier	for (i = 0; (i != priv->txqs_n); ++i) {
8797f17497SC.J. Collier		struct txq *txq = (*priv->txqs)[i];
8897f17497SC.J. Collier
8997f17497SC.J. Collier		if (txq == NULL)
9097f17497SC.J. Collier			continue;
9197f17497SC.J. Collier		idx = txq->stats.idx;
9297f17497SC.J. Collier		if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
9397f17497SC.J. Collier#ifdef MLX5_PMD_SOFT_COUNTERS
9497f17497SC.J. Collier			tmp.q_opackets[idx] += txq->stats.opackets;
9597f17497SC.J. Collier			tmp.q_obytes[idx] += txq->stats.obytes;
9697f17497SC.J. Collier#endif
9747d9763aSLuca Boccassi			tmp.q_errors[idx] += txq->stats.oerrors;
9897f17497SC.J. Collier		}
9997f17497SC.J. Collier#ifdef MLX5_PMD_SOFT_COUNTERS
10097f17497SC.J. Collier		tmp.opackets += txq->stats.opackets;
10197f17497SC.J. Collier		tmp.obytes += txq->stats.obytes;
10297f17497SC.J. Collier#endif
10347d9763aSLuca Boccassi		tmp.oerrors += txq->stats.oerrors;
10497f17497SC.J. Collier	}
10597f17497SC.J. Collier#ifndef MLX5_PMD_SOFT_COUNTERS
10697f17497SC.J. Collier	/* FIXME: retrieve and add hardware counters. */
10797f17497SC.J. Collier#endif
10897f17497SC.J. Collier	*stats = tmp;
10997f17497SC.J. Collier	priv_unlock(priv);
11097f17497SC.J. Collier}
11197f17497SC.J. Collier
11297f17497SC.J. Collier/**
11397f17497SC.J. Collier * DPDK callback to clear device statistics.
11497f17497SC.J. Collier *
11597f17497SC.J. Collier * @param dev
11697f17497SC.J. Collier *   Pointer to Ethernet device structure.
11797f17497SC.J. Collier */
11897f17497SC.J. Colliervoid
11997f17497SC.J. Colliermlx5_stats_reset(struct rte_eth_dev *dev)
12097f17497SC.J. Collier{
12197f17497SC.J. Collier	struct priv *priv = dev->data->dev_private;
12297f17497SC.J. Collier	unsigned int i;
12397f17497SC.J. Collier	unsigned int idx;
12497f17497SC.J. Collier
12597f17497SC.J. Collier	priv_lock(priv);
12697f17497SC.J. Collier	for (i = 0; (i != priv->rxqs_n); ++i) {
12797f17497SC.J. Collier		if ((*priv->rxqs)[i] == NULL)
12897f17497SC.J. Collier			continue;
12997f17497SC.J. Collier		idx = (*priv->rxqs)[i]->stats.idx;
13097f17497SC.J. Collier		(*priv->rxqs)[i]->stats =
13197f17497SC.J. Collier			(struct mlx5_rxq_stats){ .idx = idx };
13297f17497SC.J. Collier	}
13397f17497SC.J. Collier	for (i = 0; (i != priv->txqs_n); ++i) {
13497f17497SC.J. Collier		if ((*priv->txqs)[i] == NULL)
13597f17497SC.J. Collier			continue;
13697f17497SC.J. Collier		idx = (*priv->txqs)[i]->stats.idx;
13797f17497SC.J. Collier		(*priv->txqs)[i]->stats =
13897f17497SC.J. Collier			(struct mlx5_txq_stats){ .idx = idx };
13997f17497SC.J. Collier	}
14097f17497SC.J. Collier#ifndef MLX5_PMD_SOFT_COUNTERS
14197f17497SC.J. Collier	/* FIXME: reset hardware counters. */
14297f17497SC.J. Collier#endif
14397f17497SC.J. Collier	priv_unlock(priv);
14497f17497SC.J. Collier}
145