2018-01-29 13:11:30 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright 2015 6WIND S.A.
|
2018-03-20 19:20:35 +00:00
|
|
|
* Copyright 2015 Mellanox Technologies, Ltd
|
2015-10-30 18:52:36 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-08 16:37:06 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2020-04-09 20:37:06 +00:00
|
|
|
#include <unistd.h>
|
2017-01-17 14:37:08 +00:00
|
|
|
|
2021-01-29 16:48:19 +00:00
|
|
|
#include <ethdev_driver.h>
|
2017-01-17 14:37:08 +00:00
|
|
|
#include <rte_common.h>
|
|
|
|
#include <rte_malloc.h>
|
2015-10-30 18:52:36 +00:00
|
|
|
|
2020-01-29 12:38:29 +00:00
|
|
|
#include <mlx5_common.h>
|
|
|
|
|
2020-01-29 12:38:27 +00:00
|
|
|
#include "mlx5_defs.h"
|
2015-10-30 18:52:36 +00:00
|
|
|
#include "mlx5.h"
|
2021-04-12 06:32:20 +00:00
|
|
|
#include "mlx5_rx.h"
|
2021-04-12 06:32:22 +00:00
|
|
|
#include "mlx5_tx.h"
|
2020-10-19 06:36:50 +00:00
|
|
|
#include "mlx5_malloc.h"
|
2015-10-30 18:52:36 +00:00
|
|
|
|
2017-01-17 14:37:08 +00:00
|
|
|
/**
|
2018-03-05 12:21:04 +00:00
|
|
|
* DPDK callback to get extended device statistics.
|
2017-01-17 14:37:08 +00:00
|
|
|
*
|
2018-03-05 12:21:04 +00:00
|
|
|
* @param dev
|
|
|
|
* Pointer to Ethernet device.
|
2017-01-17 14:37:08 +00:00
|
|
|
* @param[out] stats
|
|
|
|
* Pointer to rte extended stats table.
|
2018-03-05 12:21:04 +00:00
|
|
|
* @param n
|
|
|
|
* The size of the stats table.
|
2017-01-17 14:37:08 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Number of extended stats on success and stats is filled,
|
2018-03-05 12:21:06 +00:00
|
|
|
* negative on error and rte_errno is set.
|
2017-01-17 14:37:08 +00:00
|
|
|
*/
|
2018-03-05 12:21:04 +00:00
|
|
|
int
|
|
|
|
mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
|
|
|
|
unsigned int n)
|
2017-01-17 14:37:08 +00:00
|
|
|
{
|
2019-02-21 09:29:14 +00:00
|
|
|
struct mlx5_priv *priv = dev->data->dev_private;
|
2017-01-17 14:37:08 +00:00
|
|
|
unsigned int i;
|
|
|
|
uint64_t counters[n];
|
2018-09-17 09:46:34 +00:00
|
|
|
struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
|
|
|
|
uint16_t mlx5_stats_n = xstats_ctrl->mlx5_stats_n;
|
2017-01-17 14:37:08 +00:00
|
|
|
|
2018-09-17 09:46:34 +00:00
|
|
|
if (n >= mlx5_stats_n && stats) {
|
2018-03-05 12:21:04 +00:00
|
|
|
int stats_n;
|
2018-03-05 12:21:06 +00:00
|
|
|
int ret;
|
2018-03-05 12:21:04 +00:00
|
|
|
|
2020-06-10 09:32:33 +00:00
|
|
|
stats_n = mlx5_os_get_stats_n(dev);
|
2018-03-05 12:21:04 +00:00
|
|
|
if (stats_n < 0)
|
2018-03-05 12:21:06 +00:00
|
|
|
return stats_n;
|
2018-03-05 12:21:04 +00:00
|
|
|
if (xstats_ctrl->stats_n != stats_n)
|
2020-06-10 09:32:33 +00:00
|
|
|
mlx5_os_stats_init(dev);
|
|
|
|
ret = mlx5_os_read_dev_counters(dev, counters);
|
2018-03-05 12:21:04 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-09-17 09:46:34 +00:00
|
|
|
for (i = 0; i != mlx5_stats_n; ++i) {
|
2018-03-05 12:21:04 +00:00
|
|
|
stats[i].id = i;
|
2020-06-10 09:32:33 +00:00
|
|
|
if (xstats_ctrl->info[i].dev) {
|
2020-03-30 03:02:10 +00:00
|
|
|
uint64_t wrap_n;
|
|
|
|
uint64_t hw_stat = xstats_ctrl->hw_stats[i];
|
|
|
|
|
|
|
|
stats[i].value = (counters[i] -
|
|
|
|
xstats_ctrl->base[i]) &
|
|
|
|
(uint64_t)UINT32_MAX;
|
|
|
|
wrap_n = hw_stat >> 32;
|
|
|
|
if (stats[i].value <
|
|
|
|
(hw_stat & (uint64_t)UINT32_MAX))
|
|
|
|
wrap_n++;
|
|
|
|
stats[i].value |= (wrap_n) << 32;
|
|
|
|
xstats_ctrl->hw_stats[i] = stats[i].value;
|
|
|
|
} else {
|
|
|
|
stats[i].value =
|
|
|
|
(counters[i] - xstats_ctrl->base[i]);
|
|
|
|
}
|
2018-03-05 12:21:04 +00:00
|
|
|
}
|
2017-01-17 14:37:08 +00:00
|
|
|
}
|
2020-07-16 08:23:18 +00:00
|
|
|
mlx5_stats_n = mlx5_txpp_xstats_get(dev, stats, n, mlx5_stats_n);
|
2018-09-17 09:46:34 +00:00
|
|
|
return mlx5_stats_n;
|
2017-01-17 14:37:08 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 18:52:36 +00:00
|
|
|
/**
|
|
|
|
* DPDK callback to get device statistics.
|
|
|
|
*
|
|
|
|
* @param dev
|
|
|
|
* Pointer to Ethernet device structure.
|
|
|
|
* @param[out] stats
|
|
|
|
* Stats structure output buffer.
|
2018-03-05 12:21:06 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* 0 on success and stats is filled, negative errno value otherwise and
|
|
|
|
* rte_errno is set.
|
2015-10-30 18:52:36 +00:00
|
|
|
*/
|
2017-10-10 20:20:18 +00:00
|
|
|
int
|
2015-10-30 18:52:36 +00:00
|
|
|
mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
|
|
|
|
{
|
2019-02-21 09:29:14 +00:00
|
|
|
struct mlx5_priv *priv = dev->data->dev_private;
|
2020-03-30 03:02:10 +00:00
|
|
|
struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
|
2018-11-13 19:11:07 +00:00
|
|
|
struct rte_eth_stats tmp;
|
2015-10-30 18:52:36 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int idx;
|
2020-03-30 03:02:10 +00:00
|
|
|
uint64_t wrap_n;
|
|
|
|
int ret;
|
2015-10-30 18:52:36 +00:00
|
|
|
|
2018-11-13 19:11:07 +00:00
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
2015-10-30 18:52:36 +00:00
|
|
|
/* Add software counters. */
|
|
|
|
for (i = 0; (i != priv->rxqs_n); ++i) {
|
2021-11-04 12:33:18 +00:00
|
|
|
struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, i);
|
2015-10-30 18:52:36 +00:00
|
|
|
|
|
|
|
if (rxq == NULL)
|
|
|
|
continue;
|
2019-04-10 18:41:16 +00:00
|
|
|
idx = rxq->idx;
|
2015-10-30 18:52:36 +00:00
|
|
|
if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
|
|
|
|
#ifdef MLX5_PMD_SOFT_COUNTERS
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.q_ipackets[idx] += rxq->stats.ipackets -
|
|
|
|
rxq->stats_reset.ipackets;
|
|
|
|
tmp.q_ibytes[idx] += rxq->stats.ibytes -
|
|
|
|
rxq->stats_reset.ibytes;
|
2015-10-30 18:52:36 +00:00
|
|
|
#endif
|
|
|
|
tmp.q_errors[idx] += (rxq->stats.idropped +
|
2022-04-20 15:32:17 +00:00
|
|
|
rxq->stats.rx_nombuf) -
|
|
|
|
(rxq->stats_reset.idropped +
|
|
|
|
rxq->stats_reset.rx_nombuf);
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
|
|
|
#ifdef MLX5_PMD_SOFT_COUNTERS
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.ipackets += rxq->stats.ipackets - rxq->stats_reset.ipackets;
|
|
|
|
tmp.ibytes += rxq->stats.ibytes - rxq->stats_reset.ibytes;
|
2015-10-30 18:52:36 +00:00
|
|
|
#endif
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.ierrors += rxq->stats.idropped - rxq->stats_reset.idropped;
|
|
|
|
tmp.rx_nombuf += rxq->stats.rx_nombuf -
|
|
|
|
rxq->stats_reset.rx_nombuf;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
|
|
|
for (i = 0; (i != priv->txqs_n); ++i) {
|
2017-10-09 14:44:40 +00:00
|
|
|
struct mlx5_txq_data *txq = (*priv->txqs)[i];
|
2015-10-30 18:52:36 +00:00
|
|
|
|
|
|
|
if (txq == NULL)
|
|
|
|
continue;
|
2019-04-10 18:41:16 +00:00
|
|
|
idx = txq->idx;
|
2015-10-30 18:52:36 +00:00
|
|
|
if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
|
|
|
|
#ifdef MLX5_PMD_SOFT_COUNTERS
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.q_opackets[idx] += txq->stats.opackets -
|
|
|
|
txq->stats_reset.opackets;
|
|
|
|
tmp.q_obytes[idx] += txq->stats.obytes -
|
|
|
|
txq->stats_reset.obytes;
|
2015-10-30 18:52:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef MLX5_PMD_SOFT_COUNTERS
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.opackets += txq->stats.opackets - txq->stats_reset.opackets;
|
|
|
|
tmp.obytes += txq->stats.obytes - txq->stats_reset.obytes;
|
2015-10-30 18:52:36 +00:00
|
|
|
#endif
|
2022-04-20 15:32:17 +00:00
|
|
|
tmp.oerrors += txq->stats.oerrors - txq->stats_reset.oerrors;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
2020-06-10 09:32:33 +00:00
|
|
|
ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &tmp.imissed);
|
2020-03-30 03:02:10 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
tmp.imissed = (tmp.imissed - stats_ctrl->imissed_base) &
|
|
|
|
(uint64_t)UINT32_MAX;
|
|
|
|
wrap_n = stats_ctrl->imissed >> 32;
|
|
|
|
if (tmp.imissed < (stats_ctrl->imissed & (uint64_t)UINT32_MAX))
|
|
|
|
wrap_n++;
|
|
|
|
tmp.imissed |= (wrap_n) << 32;
|
|
|
|
stats_ctrl->imissed = tmp.imissed;
|
|
|
|
} else {
|
|
|
|
tmp.imissed = stats_ctrl->imissed;
|
|
|
|
}
|
2015-10-30 18:52:36 +00:00
|
|
|
#ifndef MLX5_PMD_SOFT_COUNTERS
|
|
|
|
/* FIXME: retrieve and add hardware counters. */
|
|
|
|
#endif
|
|
|
|
*stats = tmp;
|
2017-10-10 20:20:18 +00:00
|
|
|
return 0;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DPDK callback to clear device statistics.
|
|
|
|
*
|
|
|
|
* @param dev
|
|
|
|
* Pointer to Ethernet device structure.
|
2019-09-06 14:34:54 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* always 0 on success and stats is reset
|
2015-10-30 18:52:36 +00:00
|
|
|
*/
|
2019-09-06 14:34:54 +00:00
|
|
|
int
|
2015-10-30 18:52:36 +00:00
|
|
|
mlx5_stats_reset(struct rte_eth_dev *dev)
|
|
|
|
{
|
2019-02-21 09:29:14 +00:00
|
|
|
struct mlx5_priv *priv = dev->data->dev_private;
|
2018-11-23 08:03:37 +00:00
|
|
|
struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
|
2015-10-30 18:52:36 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; (i != priv->rxqs_n); ++i) {
|
2021-11-04 12:33:18 +00:00
|
|
|
struct mlx5_rxq_data *rxq_data = mlx5_rxq_data_get(dev, i);
|
|
|
|
|
|
|
|
if (rxq_data == NULL)
|
2015-10-30 18:52:36 +00:00
|
|
|
continue;
|
2022-04-20 15:32:17 +00:00
|
|
|
rxq_data->stats_reset = rxq_data->stats;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
|
|
|
for (i = 0; (i != priv->txqs_n); ++i) {
|
2022-04-20 15:32:17 +00:00
|
|
|
struct mlx5_txq_data *txq_data = (*priv->txqs)[i];
|
|
|
|
|
|
|
|
if (txq_data == NULL)
|
2015-10-30 18:52:36 +00:00
|
|
|
continue;
|
2022-04-20 15:32:17 +00:00
|
|
|
txq_data->stats_reset = txq_data->stats;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
2020-06-10 09:32:33 +00:00
|
|
|
mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
|
2020-03-30 03:02:10 +00:00
|
|
|
stats_ctrl->imissed = 0;
|
2015-10-30 18:52:36 +00:00
|
|
|
#ifndef MLX5_PMD_SOFT_COUNTERS
|
|
|
|
/* FIXME: reset hardware counters. */
|
|
|
|
#endif
|
2019-09-06 14:34:54 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-10-30 18:52:36 +00:00
|
|
|
}
|
2017-01-17 14:37:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DPDK callback to clear device extended statistics.
|
|
|
|
*
|
|
|
|
* @param dev
|
|
|
|
* Pointer to Ethernet device structure.
|
2019-09-06 14:34:54 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* 0 on success and stats is reset, negative errno value otherwise and
|
|
|
|
* rte_errno is set.
|
2017-01-17 14:37:08 +00:00
|
|
|
*/
|
2019-09-06 14:34:54 +00:00
|
|
|
int
|
2017-01-17 14:37:08 +00:00
|
|
|
mlx5_xstats_reset(struct rte_eth_dev *dev)
|
|
|
|
{
|
2019-02-21 09:29:14 +00:00
|
|
|
struct mlx5_priv *priv = dev->data->dev_private;
|
2017-02-21 14:37:24 +00:00
|
|
|
struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
|
|
|
|
int stats_n;
|
2018-03-05 12:21:04 +00:00
|
|
|
unsigned int i;
|
2020-10-19 06:36:50 +00:00
|
|
|
uint64_t *counters;
|
2018-03-05 12:21:06 +00:00
|
|
|
int ret;
|
2017-01-17 14:37:08 +00:00
|
|
|
|
2020-06-10 09:32:33 +00:00
|
|
|
stats_n = mlx5_os_get_stats_n(dev);
|
2018-03-05 12:21:06 +00:00
|
|
|
if (stats_n < 0) {
|
2018-03-13 09:23:56 +00:00
|
|
|
DRV_LOG(ERR, "port %u cannot get stats: %s", dev->data->port_id,
|
|
|
|
strerror(-stats_n));
|
2019-09-06 14:34:54 +00:00
|
|
|
return stats_n;
|
2018-03-05 12:21:06 +00:00
|
|
|
}
|
2017-02-21 14:37:24 +00:00
|
|
|
if (xstats_ctrl->stats_n != stats_n)
|
2020-06-10 09:32:33 +00:00
|
|
|
mlx5_os_stats_init(dev);
|
2020-10-19 06:36:50 +00:00
|
|
|
counters = mlx5_malloc(MLX5_MEM_SYS, sizeof(*counters) *
|
|
|
|
xstats_ctrl->mlx5_stats_n, 0,
|
|
|
|
SOCKET_ID_ANY);
|
|
|
|
if (!counters) {
|
|
|
|
DRV_LOG(WARNING, "port %u unable to allocate memory for xstats "
|
|
|
|
"counters",
|
|
|
|
dev->data->port_id);
|
|
|
|
rte_errno = ENOMEM;
|
|
|
|
return -rte_errno;
|
|
|
|
}
|
2020-06-10 09:32:33 +00:00
|
|
|
ret = mlx5_os_read_dev_counters(dev, counters);
|
2018-03-05 12:21:06 +00:00
|
|
|
if (ret) {
|
2018-03-13 09:23:56 +00:00
|
|
|
DRV_LOG(ERR, "port %u cannot read device counters: %s",
|
|
|
|
dev->data->port_id, strerror(rte_errno));
|
2020-10-19 06:36:50 +00:00
|
|
|
mlx5_free(counters);
|
2019-09-06 14:34:54 +00:00
|
|
|
return ret;
|
2018-03-05 12:21:06 +00:00
|
|
|
}
|
2020-10-19 06:36:50 +00:00
|
|
|
for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
|
2018-03-05 12:21:04 +00:00
|
|
|
xstats_ctrl->base[i] = counters[i];
|
2020-03-30 03:02:10 +00:00
|
|
|
xstats_ctrl->hw_stats[i] = 0;
|
|
|
|
}
|
2020-07-16 08:23:18 +00:00
|
|
|
mlx5_txpp_xstats_reset(dev);
|
2020-10-19 06:36:50 +00:00
|
|
|
mlx5_free(counters);
|
2019-09-06 14:34:54 +00:00
|
|
|
return 0;
|
2017-01-17 14:37:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DPDK callback to retrieve names of extended device statistics
|
|
|
|
*
|
|
|
|
* @param dev
|
|
|
|
* Pointer to Ethernet device structure.
|
|
|
|
* @param[out] xstats_names
|
|
|
|
* Buffer to insert names into.
|
|
|
|
* @param n
|
|
|
|
* Number of names.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Number of xstats names.
|
|
|
|
*/
|
|
|
|
int
|
2020-07-16 08:23:18 +00:00
|
|
|
mlx5_xstats_get_names(struct rte_eth_dev *dev,
|
2018-03-13 09:23:55 +00:00
|
|
|
struct rte_eth_xstat_name *xstats_names, unsigned int n)
|
2017-01-17 14:37:08 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2019-02-21 09:29:14 +00:00
|
|
|
struct mlx5_priv *priv = dev->data->dev_private;
|
2018-09-17 09:46:34 +00:00
|
|
|
struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
|
|
|
|
unsigned int mlx5_xstats_n = xstats_ctrl->mlx5_stats_n;
|
2017-01-17 14:37:08 +00:00
|
|
|
|
2018-09-17 09:46:34 +00:00
|
|
|
if (n >= mlx5_xstats_n && xstats_names) {
|
|
|
|
for (i = 0; i != mlx5_xstats_n; ++i) {
|
2017-01-17 14:37:08 +00:00
|
|
|
strncpy(xstats_names[i].name,
|
2018-09-17 09:46:34 +00:00
|
|
|
xstats_ctrl->info[i].dpdk_name,
|
2017-01-17 14:37:08 +00:00
|
|
|
RTE_ETH_XSTATS_NAME_SIZE);
|
|
|
|
xstats_names[i].name[RTE_ETH_XSTATS_NAME_SIZE - 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 08:23:18 +00:00
|
|
|
mlx5_xstats_n = mlx5_txpp_xstats_get_names(dev, xstats_names,
|
|
|
|
n, mlx5_xstats_n);
|
2018-09-17 09:46:34 +00:00
|
|
|
return mlx5_xstats_n;
|
2017-01-17 14:37:08 +00:00
|
|
|
}
|