]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net/mlx5e: Profile specific stats groups
authorSaeed Mahameed <saeedm@mellanox.com>
Tue, 21 Jan 2020 06:32:12 +0000 (22:32 -0800)
committerSaeed Mahameed <saeedm@mellanox.com>
Thu, 23 Jan 2020 06:29:49 +0000 (22:29 -0800)
Attach stats groups array to the profiles and make the stats utility
functions (get_num, update, fill, fill_strings) generic and use the
profile->stats_grps rather the hardcoded NIC stats groups.

This will allow future extension to have per profile stats groups.

In this patch mlx5e NIC and IPoIB will still share the same stats
groups.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
drivers/net/ethernet/mellanox/mlx5/core/en_stats.h
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c

index fc80b59db9a8d837fb84fe5c8f38c3483ab2f68c..f85d99d601a69e02a39bfb11eccf6e865dd98285 100644 (file)
@@ -892,6 +892,8 @@ struct mlx5e_profile {
        int     (*update_rx)(struct mlx5e_priv *priv);
        void    (*update_stats)(struct mlx5e_priv *priv);
        void    (*update_carrier)(struct mlx5e_priv *priv);
+       unsigned int (*stats_grps_num)(struct mlx5e_priv *priv);
+       const struct mlx5e_stats_grp *stats_grps;
        struct {
                mlx5e_fp_handle_rx_cqe handle_rx_cqe;
                mlx5e_fp_handle_rx_cqe handle_rx_cqe_mpwqe;
@@ -964,7 +966,6 @@ struct sk_buff *
 mlx5e_skb_from_cqe_nonlinear(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe,
                             struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt);
 
-void mlx5e_update_stats(struct mlx5e_priv *priv);
 void mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
 void mlx5e_fold_sw_stats64(struct mlx5e_priv *priv, struct rtnl_link_stats64 *s);
 
index c6776f308d5e60e7fe792ab464c4cfb14e81656f..d674cb6798950a8ca186756e8d2d09ce8a2e1b67 100644 (file)
@@ -218,13 +218,9 @@ static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS];
 
 int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset)
 {
-       int i, num_stats = 0;
-
        switch (sset) {
        case ETH_SS_STATS:
-               for (i = 0; i < mlx5e_num_stats_grps; i++)
-                       num_stats += mlx5e_stats_grps[i].get_num_stats(priv);
-               return num_stats;
+               return mlx5e_stats_total_num(priv);
        case ETH_SS_PRIV_FLAGS:
                return MLX5E_NUM_PFLAGS;
        case ETH_SS_TEST:
@@ -242,14 +238,6 @@ static int mlx5e_get_sset_count(struct net_device *dev, int sset)
        return mlx5e_ethtool_get_sset_count(priv, sset);
 }
 
-static void mlx5e_fill_stats_strings(struct mlx5e_priv *priv, u8 *data)
-{
-       int i, idx = 0;
-
-       for (i = 0; i < mlx5e_num_stats_grps; i++)
-               idx = mlx5e_stats_grps[i].fill_strings(priv, data, idx);
-}
-
 void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv, u32 stringset, u8 *data)
 {
        int i;
@@ -268,7 +256,7 @@ void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv, u32 stringset, u8 *data)
                break;
 
        case ETH_SS_STATS:
-               mlx5e_fill_stats_strings(priv, data);
+               mlx5e_stats_fill_strings(priv, data);
                break;
        }
 }
@@ -283,14 +271,13 @@ static void mlx5e_get_strings(struct net_device *dev, u32 stringset, u8 *data)
 void mlx5e_ethtool_get_ethtool_stats(struct mlx5e_priv *priv,
                                     struct ethtool_stats *stats, u64 *data)
 {
-       int i, idx = 0;
+       int idx = 0;
 
        mutex_lock(&priv->state_lock);
-       mlx5e_update_stats(priv);
+       mlx5e_stats_update(priv);
        mutex_unlock(&priv->state_lock);
 
-       for (i = 0; i < mlx5e_num_stats_grps; i++)
-               idx = mlx5e_stats_grps[i].fill_stats(priv, data, idx);
+       mlx5e_stats_fill(priv, data, idx);
 }
 
 static void mlx5e_get_ethtool_stats(struct net_device *dev,
index 87267c18ff8c651ec31191dab4bbff5ad15a4515..a1bb9eb8e3b5349e71fd21cfc5005d1835d26f22 100644 (file)
@@ -159,23 +159,14 @@ static void mlx5e_update_carrier_work(struct work_struct *work)
        mutex_unlock(&priv->state_lock);
 }
 
-void mlx5e_update_stats(struct mlx5e_priv *priv)
-{
-       int i;
-
-       for (i = mlx5e_num_stats_grps - 1; i >= 0; i--)
-               if (mlx5e_stats_grps[i].update_stats)
-                       mlx5e_stats_grps[i].update_stats(priv);
-}
-
 void mlx5e_update_ndo_stats(struct mlx5e_priv *priv)
 {
        int i;
 
-       for (i = mlx5e_num_stats_grps - 1; i >= 0; i--)
-               if (mlx5e_stats_grps[i].update_stats_mask &
+       for (i = mlx5e_nic_stats_grps_num(priv) - 1; i >= 0; i--)
+               if (mlx5e_nic_stats_grps[i].update_stats_mask &
                    MLX5E_NDO_UPDATE_STATS)
-                       mlx5e_stats_grps[i].update_stats(priv);
+                       mlx5e_nic_stats_grps[i].update_stats(priv);
 }
 
 static void mlx5e_update_stats_work(struct work_struct *work)
@@ -5197,6 +5188,8 @@ static const struct mlx5e_profile mlx5e_nic_profile = {
        .rx_handlers.handle_rx_cqe_mpwqe = mlx5e_handle_rx_cqe_mpwrq,
        .max_tc            = MLX5E_MAX_NUM_TC,
        .rq_groups         = MLX5E_NUM_RQ_GROUPS(XSK),
+       .stats_grps        = mlx5e_nic_stats_grps,
+       .stats_grps_num    = mlx5e_nic_stats_grps_num,
 };
 
 /* mlx5e generic netdev management API (move to en_common.c) */
index 4291db78efc989dc3a24c606dbbab5336cc5c6a7..a8baa6298d9589aafa33e5864cf565a7f6dd49b3 100644 (file)
 #include "en_accel/ipsec.h"
 #include "en_accel/tls.h"
 
+static unsigned int stats_grps_num(struct mlx5e_priv *priv)
+{
+       return !priv->profile->stats_grps_num ? 0 :
+               priv->profile->stats_grps_num(priv);
+}
+
+unsigned int mlx5e_stats_total_num(struct mlx5e_priv *priv)
+{
+       const struct mlx5e_stats_grp *stats_grps = priv->profile->stats_grps;
+       const unsigned int num_stats_grps = stats_grps_num(priv);
+       unsigned int total = 0;
+       int i;
+
+       for (i = 0; i < num_stats_grps; i++)
+               total += stats_grps[i].get_num_stats(priv);
+
+       return total;
+}
+
+void mlx5e_stats_update(struct mlx5e_priv *priv)
+{
+       const struct mlx5e_stats_grp *stats_grps = priv->profile->stats_grps;
+       const unsigned int num_stats_grps = stats_grps_num(priv);
+       int i;
+
+       for (i = num_stats_grps - 1; i >= 0; i--)
+               if (stats_grps[i].update_stats)
+                       stats_grps[i].update_stats(priv);
+}
+
+void mlx5e_stats_fill(struct mlx5e_priv *priv, u64 *data, int idx)
+{
+       const struct mlx5e_stats_grp *stats_grps = priv->profile->stats_grps;
+       const unsigned int num_stats_grps = stats_grps_num(priv);
+       int i;
+
+       for (i = 0; i < num_stats_grps; i++)
+               idx = stats_grps[i].fill_stats(priv, data, idx);
+}
+
+void mlx5e_stats_fill_strings(struct mlx5e_priv *priv, u8 *data)
+{
+       const struct mlx5e_stats_grp *stats_grps = priv->profile->stats_grps;
+       const unsigned int num_stats_grps = stats_grps_num(priv);
+       int i, idx = 0;
+
+       for (i = 0; i < num_stats_grps; i++)
+               idx = stats_grps[i].fill_strings(priv, data, idx);
+}
+
+/* Concrete NIC Stats */
+
 static const struct counter_desc sw_stats_desc[] = {
        { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
        { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
@@ -1669,7 +1721,7 @@ static int mlx5e_grp_channels_fill_stats(struct mlx5e_priv *priv, u64 *data,
 }
 
 /* The stats groups order is opposite to the update_stats() order calls */
-const struct mlx5e_stats_grp mlx5e_stats_grps[] = {
+const struct mlx5e_stats_grp mlx5e_nic_stats_grps[] = {
        {
                .get_num_stats = mlx5e_grp_sw_get_num_stats,
                .fill_strings = mlx5e_grp_sw_fill_strings,
@@ -1768,4 +1820,7 @@ const struct mlx5e_stats_grp mlx5e_stats_grps[] = {
        },
 };
 
-const int mlx5e_num_stats_grps = ARRAY_SIZE(mlx5e_stats_grps);
+unsigned int mlx5e_nic_stats_grps_num(struct mlx5e_priv *priv)
+{
+       return ARRAY_SIZE(mlx5e_nic_stats_grps);
+}
index 869f3502f6312845e35d888f972a5a78a8a3b84e..06eeedaacb8886a1b12e24a040b8a622151a4a5b 100644 (file)
@@ -55,6 +55,26 @@ struct counter_desc {
        size_t          offset; /* Byte offset */
 };
 
+enum {
+       MLX5E_NDO_UPDATE_STATS = BIT(0x1),
+};
+
+struct mlx5e_priv;
+struct mlx5e_stats_grp {
+       u16 update_stats_mask;
+       int (*get_num_stats)(struct mlx5e_priv *priv);
+       int (*fill_strings)(struct mlx5e_priv *priv, u8 *data, int idx);
+       int (*fill_stats)(struct mlx5e_priv *priv, u64 *data, int idx);
+       void (*update_stats)(struct mlx5e_priv *priv);
+};
+
+unsigned int mlx5e_stats_total_num(struct mlx5e_priv *priv);
+void mlx5e_stats_update(struct mlx5e_priv *priv);
+void mlx5e_stats_fill(struct mlx5e_priv *priv, u64 *data, int idx);
+void mlx5e_stats_fill_strings(struct mlx5e_priv *priv, u8 *data);
+
+/* Concrete NIC Stats */
+
 struct mlx5e_sw_stats {
        u64 rx_packets;
        u64 rx_bytes;
@@ -322,21 +342,8 @@ struct mlx5e_stats {
        struct mlx5e_pcie_stats pcie;
 };
 
-enum {
-       MLX5E_NDO_UPDATE_STATS = BIT(0x1),
-};
-
-struct mlx5e_priv;
-struct mlx5e_stats_grp {
-       u16 update_stats_mask;
-       int (*get_num_stats)(struct mlx5e_priv *priv);
-       int (*fill_strings)(struct mlx5e_priv *priv, u8 *data, int idx);
-       int (*fill_stats)(struct mlx5e_priv *priv, u64 *data, int idx);
-       void (*update_stats)(struct mlx5e_priv *priv);
-};
-
-extern const struct mlx5e_stats_grp mlx5e_stats_grps[];
-extern const int mlx5e_num_stats_grps;
+extern const struct mlx5e_stats_grp mlx5e_nic_stats_grps[];
+unsigned int mlx5e_nic_stats_grps_num(struct mlx5e_priv *priv);
 
 void mlx5e_grp_802_3_update_stats(struct mlx5e_priv *priv);
 
index 7c87f523e370ad491ef9a302b24d4a0eaaa4cd40..bd870ffeb1be314040239856ebd2d79c511ce036 100644 (file)
@@ -435,6 +435,8 @@ static const struct mlx5e_profile mlx5i_nic_profile = {
        .rx_handlers.handle_rx_cqe_mpwqe = NULL, /* Not supported */
        .max_tc            = MLX5I_MAX_NUM_TC,
        .rq_groups         = MLX5E_NUM_RQ_GROUPS(REGULAR),
+       .stats_grps        = mlx5e_nic_stats_grps,
+       .stats_grps_num    = mlx5e_nic_stats_grps_num,
 };
 
 /* mlx5i netdev NDos */