summaryrefslogtreecommitdiff
path: root/drivers/net/mlx5/mlx5_stats.c
diff options
context:
space:
mode:
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>2018-02-08 17:37:06 +0100
committerFerruh Yigit <ferruh.yigit@intel.com>2018-03-30 14:08:42 +0200
commitfc40db997323bb0e9b725a6e8d65eae95372446c (patch)
treec04eb96d1955a0ea4590e6bfe3c3b65f981d32b4 /drivers/net/mlx5/mlx5_stats.c
parent984af543c254be1fc3f0ae46f381d75dcd0af361 (diff)
downloaddpdk-fc40db997323bb0e9b725a6e8d65eae95372446c.zip
dpdk-fc40db997323bb0e9b725a6e8d65eae95372446c.tar.gz
dpdk-fc40db997323bb0e9b725a6e8d65eae95372446c.tar.xz
net/mlx: control netdevices through ioctl only
Several control operations implemented by these PMDs affect netdevices through sysfs, itself subject to file system permission checks enforced by the kernel, which limits their use for most purposes to applications running with root privileges. Since performing the same operations through ioctl() requires fewer capabilities (only CAP_NET_ADMIN) and given the remaining operations are already implemented this way, this patch standardizes on ioctl() and gets rid of redundant code. Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Diffstat (limited to 'drivers/net/mlx5/mlx5_stats.c')
-rw-r--r--drivers/net/mlx5/mlx5_stats.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
index 378472a..eb9c65d 100644
--- a/drivers/net/mlx5/mlx5_stats.c
+++ b/drivers/net/mlx5/mlx5_stats.c
@@ -3,8 +3,11 @@
* Copyright 2015 Mellanox.
*/
+#include <inttypes.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
+#include <stdint.h>
+#include <stdio.h>
#include <rte_ethdev_driver.h>
#include <rte_common.h>
@@ -19,6 +22,7 @@ struct mlx5_counter_ctrl {
char dpdk_name[RTE_ETH_XSTATS_NAME_SIZE];
/* Name of the counter on the device table. */
char ctr_name[RTE_ETH_XSTATS_NAME_SIZE];
+ uint32_t ib:1; /**< Nonzero for IB counters. */
};
static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
@@ -93,6 +97,7 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
{
.dpdk_name = "rx_out_of_buffer",
.ctr_name = "out_of_buffer",
+ .ib = 1,
},
{
.dpdk_name = "tx_packets_phy",
@@ -143,13 +148,24 @@ priv_read_dev_counters(struct priv *priv, uint64_t *stats)
return -1;
}
for (i = 0; i != xstats_n; ++i) {
- if (priv_is_ib_cntr(mlx5_counters_init[i].ctr_name))
- priv_get_cntr_sysfs(priv,
- mlx5_counters_init[i].ctr_name,
- &stats[i]);
- else
+ if (mlx5_counters_init[i].ib) {
+ FILE *file;
+ MKSTR(path, "%s/ports/1/hw_counters/%s",
+ priv->ibdev_path,
+ mlx5_counters_init[i].ctr_name);
+
+ file = fopen(path, "rb");
+ if (file) {
+ int n = fscanf(file, "%" SCNu64, &stats[i]);
+
+ fclose(file);
+ if (n != 1)
+ stats[i] = 0;
+ }
+ } else {
stats[i] = (uint64_t)
et_stats->data[xstats_ctrl->dev_table_idx[i]];
+ }
}
return 0;
}
@@ -232,7 +248,7 @@ priv_xstats_init(struct priv *priv)
}
}
for (j = 0; j != xstats_n; ++j) {
- if (priv_is_ib_cntr(mlx5_counters_init[j].ctr_name))
+ if (mlx5_counters_init[j].ib)
continue;
if (xstats_ctrl->dev_table_idx[j] >= dev_stats_n) {
WARN("counter \"%s\" is not recognized",