net/mlx5: add physical port counters
[dpdk.git] / drivers / net / mlx5 / mlx5_stats.c
index 703f48c..4cb6136 100644 (file)
 #include <linux/sockios.h>
 #include <linux/ethtool.h>
 
-/* DPDK headers don't like -pedantic. */
-#ifdef PEDANTIC
-#pragma GCC diagnostic ignored "-Wpedantic"
-#endif
 #include <rte_ethdev.h>
 #include <rte_common.h>
 #include <rte_malloc.h>
-#ifdef PEDANTIC
-#pragma GCC diagnostic error "-Wpedantic"
-#endif
 
 #include "mlx5.h"
 #include "mlx5_rxtx.h"
@@ -129,6 +122,22 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
                .dpdk_name = "rx_out_of_buffer",
                .ctr_name = "out_of_buffer",
        },
+       {
+               .dpdk_name = "tx_packets_phy",
+               .ctr_name = "tx_packets_phy",
+       },
+       {
+               .dpdk_name = "rx_packets_phy",
+               .ctr_name = "rx_packets_phy",
+       },
+       {
+               .dpdk_name = "tx_bytes_phy",
+               .ctr_name = "tx_bytes_phy",
+       },
+       {
+               .dpdk_name = "rx_bytes_phy",
+               .ctr_name = "rx_bytes_phy",
+       },
 };
 
 static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init);
@@ -150,11 +159,9 @@ priv_read_dev_counters(struct priv *priv, uint64_t *stats)
        struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
        unsigned int i;
        struct ifreq ifr;
-       unsigned int stats_sz = (xstats_ctrl->stats_n * sizeof(uint64_t)) +
-                                sizeof(struct ethtool_stats);
-       struct ethtool_stats et_stats[(stats_sz + (
-                                     sizeof(struct ethtool_stats) - 1)) /
-                                     sizeof(struct ethtool_stats)];
+       unsigned int stats_sz = xstats_ctrl->stats_n * sizeof(uint64_t);
+       unsigned char et_stat_buf[sizeof(struct ethtool_stats) + stats_sz];
+       struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf;
 
        et_stats->cmd = ETHTOOL_GSTATS;
        et_stats->n_stats = xstats_ctrl->stats_n;
@@ -325,10 +332,10 @@ priv_xstats_reset(struct priv *priv)
  * @param[out] stats
  *   Stats structure output buffer.
  */
-void
+int
 mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        struct rte_eth_stats tmp = {0};
        unsigned int i;
        unsigned int idx;
@@ -336,7 +343,7 @@ mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
        priv_lock(priv);
        /* Add software counters. */
        for (i = 0; (i != priv->rxqs_n); ++i) {
-               struct rxq *rxq = (*priv->rxqs)[i];
+               struct mlx5_rxq_data *rxq = (*priv->rxqs)[i];
 
                if (rxq == NULL)
                        continue;
@@ -357,7 +364,7 @@ mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                tmp.rx_nombuf += rxq->stats.rx_nombuf;
        }
        for (i = 0; (i != priv->txqs_n); ++i) {
-               struct txq *txq = (*priv->txqs)[i];
+               struct mlx5_txq_data *txq = (*priv->txqs)[i];
 
                if (txq == NULL)
                        continue;
@@ -367,19 +374,20 @@ mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                        tmp.q_opackets[idx] += txq->stats.opackets;
                        tmp.q_obytes[idx] += txq->stats.obytes;
 #endif
-                       tmp.q_errors[idx] += txq->stats.odropped;
+                       tmp.q_errors[idx] += txq->stats.oerrors;
                }
 #ifdef MLX5_PMD_SOFT_COUNTERS
                tmp.opackets += txq->stats.opackets;
                tmp.obytes += txq->stats.obytes;
 #endif
-               tmp.oerrors += txq->stats.odropped;
+               tmp.oerrors += txq->stats.oerrors;
        }
 #ifndef MLX5_PMD_SOFT_COUNTERS
        /* FIXME: retrieve and add hardware counters. */
 #endif
        *stats = tmp;
        priv_unlock(priv);
+       return 0;
 }
 
 /**
@@ -433,7 +441,7 @@ int
 mlx5_xstats_get(struct rte_eth_dev *dev,
                struct rte_eth_xstat *stats, unsigned int n)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        int ret = xstats_n;
 
        if (n >= xstats_n && stats) {
@@ -442,8 +450,10 @@ mlx5_xstats_get(struct rte_eth_dev *dev,
 
                priv_lock(priv);
                stats_n = priv_ethtool_get_stats_n(priv);
-               if (stats_n < 0)
+               if (stats_n < 0) {
+                       priv_unlock(priv);
                        return -1;
+               }
                if (xstats_ctrl->stats_n != stats_n)
                        priv_xstats_init(priv);
                ret = priv_xstats_get(priv, stats);
@@ -461,17 +471,18 @@ mlx5_xstats_get(struct rte_eth_dev *dev,
 void
 mlx5_xstats_reset(struct rte_eth_dev *dev)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
        int stats_n;
 
        priv_lock(priv);
        stats_n = priv_ethtool_get_stats_n(priv);
        if (stats_n < 0)
-               return;
+               goto unlock;
        if (xstats_ctrl->stats_n != stats_n)
                priv_xstats_init(priv);
        priv_xstats_reset(priv);
+unlock:
        priv_unlock(priv);
 }
 
@@ -492,7 +503,7 @@ int
 mlx5_xstats_get_names(struct rte_eth_dev *dev,
                struct rte_eth_xstat_name *xstats_names, unsigned int n)
 {
-       struct priv *priv = mlx5_get_priv(dev);
+       struct priv *priv = dev->data->dev_private;
        unsigned int i;
 
        if (n >= xstats_n && xstats_names) {