1 diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
2 index 0c80e4f..60ffbaa 100644
3 --- a/drivers/net/mlx5/mlx5_stats.c
4 +++ b/drivers/net/mlx5/mlx5_stats.c
5 @@ -166,6 +166,29 @@ struct mlx5_counter_ctrl {
9 + * Query the number of statistics provided by ETHTOOL.
12 + * Pointer to private structure.
15 + * Number of statistics on success, -1 on error.
18 +priv_ethtool_get_stats_n(struct priv *priv) {
19 + struct ethtool_drvinfo drvinfo;
22 + drvinfo.cmd = ETHTOOL_GDRVINFO;
23 + ifr.ifr_data = (caddr_t)&drvinfo;
24 + if (priv_ifreq(priv, SIOCETHTOOL, &ifr) != 0) {
25 + WARN("unable to query number of statistics");
28 + return drvinfo.n_stats;
32 * Init the structures to read device counters.
35 @@ -178,19 +201,11 @@ struct mlx5_counter_ctrl {
39 - struct ethtool_drvinfo drvinfo;
40 struct ethtool_gstrings *strings = NULL;
41 unsigned int dev_stats_n;
44 - /* How many statistics are available. */
45 - drvinfo.cmd = ETHTOOL_GDRVINFO;
46 - ifr.ifr_data = (caddr_t)&drvinfo;
47 - if (priv_ifreq(priv, SIOCETHTOOL, &ifr) != 0) {
48 - WARN("unable to get driver info");
51 - dev_stats_n = drvinfo.n_stats;
52 + dev_stats_n = priv_ethtool_get_stats_n(priv);
53 if (dev_stats_n < 1) {
54 WARN("no extended statistics available");
56 @@ -410,7 +425,15 @@ struct mlx5_counter_ctrl {
59 if (n >= xstats_n && stats) {
60 + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
64 + stats_n = priv_ethtool_get_stats_n(priv);
67 + if (xstats_ctrl->stats_n != stats_n)
68 + priv_xstats_init(priv);
69 ret = priv_xstats_get(priv, stats);
72 @@ -427,8 +450,15 @@ struct mlx5_counter_ctrl {
73 mlx5_xstats_reset(struct rte_eth_dev *dev)
75 struct priv *priv = mlx5_get_priv(dev);
76 + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
80 + stats_n = priv_ethtool_get_stats_n(priv);
83 + if (xstats_ctrl->stats_n != stats_n)
84 + priv_xstats_init(priv);
85 priv_xstats_reset(priv);