net/mlx5e: Remove redundant active_channels indication
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_stats.c
index e17919c0af088a0ad2f70d2a8230fa786724ab47..697dc7397ba22af794acefe7a098ec6f003ec056 100644 (file)
@@ -81,7 +81,6 @@ static const struct counter_desc sw_stats_desc[] = {
        { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_busy) },
        { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_waive) },
        { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_eq_rearm) },
-       { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, link_down_events_phy) },
 };
 
 #define NUM_SW_COUNTERS                        ARRAY_SIZE(sw_stats_desc)
@@ -109,20 +108,19 @@ static int mlx5e_grp_sw_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
        return idx;
 }
 
-static void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
+void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
 {
        struct mlx5e_sw_stats temp, *s = &temp;
-       struct mlx5e_rq_stats *rq_stats;
-       struct mlx5e_sq_stats *sq_stats;
-       struct mlx5e_ch_stats *ch_stats;
-       int i, j;
+       int i;
 
        memset(s, 0, sizeof(*s));
-       for (i = 0; i < priv->channels.num; i++) {
-               struct mlx5e_channel *c = priv->channels.c[i];
 
-               rq_stats = &c->rq.stats;
-               ch_stats = &c->stats;
+       for (i = 0; i < priv->profile->max_nch(priv->mdev); i++) {
+               struct mlx5e_channel_stats *channel_stats =
+                       &priv->channel_stats[i];
+               struct mlx5e_rq_stats *rq_stats = &channel_stats->rq;
+               struct mlx5e_ch_stats *ch_stats = &channel_stats->ch;
+               int j;
 
                s->rx_packets   += rq_stats->packets;
                s->rx_bytes     += rq_stats->bytes;
@@ -149,8 +147,8 @@ static void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
                s->rx_cache_waive += rq_stats->cache_waive;
                s->ch_eq_rearm += ch_stats->eq_rearm;
 
-               for (j = 0; j < priv->channels.params.num_tc; j++) {
-                       sq_stats = &c->sq[j].stats;
+               for (j = 0; j < priv->max_opened_tc; j++) {
+                       struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j];
 
                        s->tx_packets           += sq_stats->packets;
                        s->tx_bytes             += sq_stats->bytes;
@@ -175,9 +173,6 @@ static void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
                }
        }
 
-       s->link_down_events_phy = MLX5_GET(ppcnt_reg,
-                               priv->stats.pport.phy_counters,
-                               counter_set.phys_layer_cntrs.link_down_events);
        memcpy(&priv->stats.sw, s, sizeof(*s));
 }
 
@@ -580,12 +575,13 @@ static const struct counter_desc pport_phy_statistical_stats_desc[] = {
        { "rx_corrected_bits_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits) },
 };
 
-#define NUM_PPORT_PHY_COUNTERS         ARRAY_SIZE(pport_phy_statistical_stats_desc)
+#define NUM_PPORT_PHY_STATISTICAL_COUNTERS ARRAY_SIZE(pport_phy_statistical_stats_desc)
 
 static int mlx5e_grp_phy_get_num_stats(struct mlx5e_priv *priv)
 {
+       /* "1" for link_down_events special counter */
        return MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group) ?
-               NUM_PPORT_PHY_COUNTERS : 0;
+               NUM_PPORT_PHY_STATISTICAL_COUNTERS + 1 : 1;
 }
 
 static int mlx5e_grp_phy_fill_strings(struct mlx5e_priv *priv, u8 *data,
@@ -593,10 +589,14 @@ static int mlx5e_grp_phy_fill_strings(struct mlx5e_priv *priv, u8 *data,
 {
        int i;
 
-       if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group))
-               for (i = 0; i < NUM_PPORT_PHY_COUNTERS; i++)
-                       strcpy(data + (idx++) * ETH_GSTRING_LEN,
-                              pport_phy_statistical_stats_desc[i].format);
+       strcpy(data + (idx++) * ETH_GSTRING_LEN, "link_down_events_phy");
+
+       if (!MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group))
+               return idx;
+
+       for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
+               strcpy(data + (idx++) * ETH_GSTRING_LEN,
+                      pport_phy_statistical_stats_desc[i].format);
        return idx;
 }
 
@@ -604,11 +604,17 @@ static int mlx5e_grp_phy_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
 {
        int i;
 
-       if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group))
-               for (i = 0; i < NUM_PPORT_PHY_COUNTERS; i++)
-                       data[idx++] =
-                               MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
-                                                   pport_phy_statistical_stats_desc, i);
+       /* link_down_events_phy has special handling since it is not stored in __be64 format */
+       data[idx++] = MLX5_GET(ppcnt_reg, priv->stats.pport.phy_counters,
+                              counter_set.phys_layer_cntrs.link_down_events);
+
+       if (!MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group))
+               return idx;
+
+       for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
+               data[idx++] =
+                       MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
+                                           pport_phy_statistical_stats_desc, i);
        return idx;
 }
 
@@ -1148,30 +1154,30 @@ static const struct counter_desc ch_stats_desc[] = {
 
 static int mlx5e_grp_channels_get_num_stats(struct mlx5e_priv *priv)
 {
-       return (NUM_RQ_STATS * priv->channels.num) +
-               (NUM_CH_STATS * priv->channels.num) +
-               (NUM_SQ_STATS * priv->channels.num * priv->channels.params.num_tc);
+       int max_nch = priv->profile->max_nch(priv->mdev);
+
+       return (NUM_RQ_STATS * max_nch) +
+              (NUM_CH_STATS * max_nch) +
+              (NUM_SQ_STATS * max_nch * priv->max_opened_tc);
 }
 
 static int mlx5e_grp_channels_fill_strings(struct mlx5e_priv *priv, u8 *data,
                                           int idx)
 {
+       int max_nch = priv->profile->max_nch(priv->mdev);
        int i, j, tc;
 
-       if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
-               return idx;
-
-       for (i = 0; i < priv->channels.num; i++)
+       for (i = 0; i < max_nch; i++)
                for (j = 0; j < NUM_CH_STATS; j++)
                        sprintf(data + (idx++) * ETH_GSTRING_LEN,
                                ch_stats_desc[j].format, i);
 
-       for (i = 0; i < priv->channels.num; i++)
+       for (i = 0; i < max_nch; i++)
                for (j = 0; j < NUM_RQ_STATS; j++)
                        sprintf(data + (idx++) * ETH_GSTRING_LEN, rq_stats_desc[j].format, i);
 
-       for (tc = 0; tc < priv->channels.params.num_tc; tc++)
-               for (i = 0; i < priv->channels.num; i++)
+       for (tc = 0; tc < priv->max_opened_tc; tc++)
+               for (i = 0; i < max_nch; i++)
                        for (j = 0; j < NUM_SQ_STATS; j++)
                                sprintf(data + (idx++) * ETH_GSTRING_LEN,
                                        sq_stats_desc[j].format,
@@ -1183,29 +1189,26 @@ static int mlx5e_grp_channels_fill_strings(struct mlx5e_priv *priv, u8 *data,
 static int mlx5e_grp_channels_fill_stats(struct mlx5e_priv *priv, u64 *data,
                                         int idx)
 {
-       struct mlx5e_channels *channels = &priv->channels;
+       int max_nch = priv->profile->max_nch(priv->mdev);
        int i, j, tc;
 
-       if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
-               return idx;
-
-       for (i = 0; i < channels->num; i++)
+       for (i = 0; i < max_nch; i++)
                for (j = 0; j < NUM_CH_STATS; j++)
                        data[idx++] =
-                               MLX5E_READ_CTR64_CPU(&channels->c[i]->stats,
+                               MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].ch,
                                                     ch_stats_desc, j);
 
-       for (i = 0; i < channels->num; i++)
+       for (i = 0; i < max_nch; i++)
                for (j = 0; j < NUM_RQ_STATS; j++)
                        data[idx++] =
-                               MLX5E_READ_CTR64_CPU(&channels->c[i]->rq.stats,
+                               MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].rq,
                                                     rq_stats_desc, j);
 
-       for (tc = 0; tc < priv->channels.params.num_tc; tc++)
-               for (i = 0; i < channels->num; i++)
+       for (tc = 0; tc < priv->max_opened_tc; tc++)
+               for (i = 0; i < max_nch; i++)
                        for (j = 0; j < NUM_SQ_STATS; j++)
                                data[idx++] =
-                                       MLX5E_READ_CTR64_CPU(&channels->c[i]->sq[tc].stats,
+                                       MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].sq[tc],
                                                             sq_stats_desc, j);
 
        return idx;
@@ -1217,7 +1220,6 @@ const struct mlx5e_stats_grp mlx5e_stats_grps[] = {
                .get_num_stats = mlx5e_grp_sw_get_num_stats,
                .fill_strings = mlx5e_grp_sw_fill_strings,
                .fill_stats = mlx5e_grp_sw_fill_stats,
-               .update_stats_mask = MLX5E_NDO_UPDATE_STATS,
                .update_stats = mlx5e_grp_sw_update_stats,
        },
        {