Damjan Marion | 0f60ff8 | 2017-03-30 17:58:42 +0200 | [diff] [blame] | 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 { |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | + * Query the number of statistics provided by ETHTOOL. |
| 10 | + * |
| 11 | + * @param priv |
| 12 | + * Pointer to private structure. |
| 13 | + * |
| 14 | + * @return |
| 15 | + * Number of statistics on success, -1 on error. |
| 16 | + */ |
| 17 | +static int |
| 18 | +priv_ethtool_get_stats_n(struct priv *priv) { |
| 19 | + struct ethtool_drvinfo drvinfo; |
| 20 | + struct ifreq ifr; |
| 21 | + |
| 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"); |
| 26 | + return -1; |
| 27 | + } |
| 28 | + return drvinfo.n_stats; |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | * Init the structures to read device counters. |
| 33 | * |
| 34 | * @param priv |
| 35 | @@ -178,19 +201,11 @@ struct mlx5_counter_ctrl { |
| 36 | unsigned int i; |
| 37 | unsigned int j; |
| 38 | struct ifreq ifr; |
| 39 | - struct ethtool_drvinfo drvinfo; |
| 40 | struct ethtool_gstrings *strings = NULL; |
| 41 | unsigned int dev_stats_n; |
| 42 | unsigned int str_sz; |
| 43 | |
| 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"); |
| 49 | - return; |
| 50 | - } |
| 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"); |
| 55 | return; |
| 56 | @@ -410,7 +425,15 @@ struct mlx5_counter_ctrl { |
| 57 | int ret = xstats_n; |
| 58 | |
| 59 | if (n >= xstats_n && stats) { |
| 60 | + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; |
| 61 | + int stats_n; |
| 62 | + |
| 63 | priv_lock(priv); |
| 64 | + stats_n = priv_ethtool_get_stats_n(priv); |
| 65 | + if (stats_n < 0) |
| 66 | + return -1; |
| 67 | + if (xstats_ctrl->stats_n != stats_n) |
| 68 | + priv_xstats_init(priv); |
| 69 | ret = priv_xstats_get(priv, stats); |
| 70 | priv_unlock(priv); |
| 71 | } |
| 72 | @@ -427,8 +450,15 @@ struct mlx5_counter_ctrl { |
| 73 | mlx5_xstats_reset(struct rte_eth_dev *dev) |
| 74 | { |
| 75 | struct priv *priv = mlx5_get_priv(dev); |
| 76 | + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; |
| 77 | + int stats_n; |
| 78 | |
| 79 | priv_lock(priv); |
| 80 | + stats_n = priv_ethtool_get_stats_n(priv); |
| 81 | + if (stats_n < 0) |
| 82 | + return; |
| 83 | + if (xstats_ctrl->stats_n != stats_n) |
| 84 | + priv_xstats_init(priv); |
| 85 | priv_xstats_reset(priv); |
| 86 | priv_unlock(priv); |
| 87 | } |