Commit 8ff57c18 authored by Tariq Toukan's avatar Tariq Toukan Committed by Saeed Mahameed

net/mlx5e: Improve ethtool private-flags code structure

Refactor the code of private-flags setter.
Replace consecutive calls to mlx5e_handle_pflag with a loop
that uses a preset set of parameters.
Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 756c4160
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <net/switchdev.h> #include <net/switchdev.h>
#include <net/xdp.h> #include <net/xdp.h>
#include <linux/net_dim.h> #include <linux/net_dim.h>
#include <linux/bits.h>
#include "wq.h" #include "wq.h"
#include "mlx5_core.h" #include "mlx5_core.h"
#include "en_stats.h" #include "en_stats.h"
...@@ -211,22 +212,23 @@ struct mlx5e_umr_wqe { ...@@ -211,22 +212,23 @@ struct mlx5e_umr_wqe {
extern const char mlx5e_self_tests[][ETH_GSTRING_LEN]; extern const char mlx5e_self_tests[][ETH_GSTRING_LEN];
enum mlx5e_priv_flag { enum mlx5e_priv_flag {
MLX5E_PFLAG_RX_CQE_BASED_MODER = (1 << 0), MLX5E_PFLAG_RX_CQE_BASED_MODER,
MLX5E_PFLAG_TX_CQE_BASED_MODER = (1 << 1), MLX5E_PFLAG_TX_CQE_BASED_MODER,
MLX5E_PFLAG_RX_CQE_COMPRESS = (1 << 2), MLX5E_PFLAG_RX_CQE_COMPRESS,
MLX5E_PFLAG_RX_STRIDING_RQ = (1 << 3), MLX5E_PFLAG_RX_STRIDING_RQ,
MLX5E_PFLAG_RX_NO_CSUM_COMPLETE = (1 << 4), MLX5E_PFLAG_RX_NO_CSUM_COMPLETE,
MLX5E_NUM_PFLAGS, /* Keep last */
}; };
#define MLX5E_SET_PFLAG(params, pflag, enable) \ #define MLX5E_SET_PFLAG(params, pflag, enable) \
do { \ do { \
if (enable) \ if (enable) \
(params)->pflags |= (pflag); \ (params)->pflags |= BIT(pflag); \
else \ else \
(params)->pflags &= ~(pflag); \ (params)->pflags &= ~(BIT(pflag)); \
} while (0) } while (0)
#define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (pflag))) #define MLX5E_GET_PFLAG(params, pflag) (!!((params)->pflags & (BIT(pflag))))
#ifdef CONFIG_MLX5_CORE_EN_DCB #ifdef CONFIG_MLX5_CORE_EN_DCB
#define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */ #define MLX5E_MAX_BW_ALLOC 100 /* Max percentage of BW allocation */
......
...@@ -135,14 +135,15 @@ void mlx5e_build_ptys2ethtool_map(void) ...@@ -135,14 +135,15 @@ void mlx5e_build_ptys2ethtool_map(void)
ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT); ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT);
} }
static const char mlx5e_priv_flags[][ETH_GSTRING_LEN] = { typedef int (*mlx5e_pflag_handler)(struct net_device *netdev, bool enable);
"rx_cqe_moder",
"tx_cqe_moder", struct pflag_desc {
"rx_cqe_compress", char name[ETH_GSTRING_LEN];
"rx_striding_rq", mlx5e_pflag_handler handler;
"rx_no_csum_complete",
}; };
static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS];
int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset) int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset)
{ {
int i, num_stats = 0; int i, num_stats = 0;
...@@ -153,7 +154,7 @@ int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset) ...@@ -153,7 +154,7 @@ int mlx5e_ethtool_get_sset_count(struct mlx5e_priv *priv, int sset)
num_stats += mlx5e_stats_grps[i].get_num_stats(priv); num_stats += mlx5e_stats_grps[i].get_num_stats(priv);
return num_stats; return num_stats;
case ETH_SS_PRIV_FLAGS: case ETH_SS_PRIV_FLAGS:
return ARRAY_SIZE(mlx5e_priv_flags); return MLX5E_NUM_PFLAGS;
case ETH_SS_TEST: case ETH_SS_TEST:
return mlx5e_self_test_num(priv); return mlx5e_self_test_num(priv);
/* fallthrough */ /* fallthrough */
...@@ -183,8 +184,9 @@ void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv, u32 stringset, u8 *data) ...@@ -183,8 +184,9 @@ void mlx5e_ethtool_get_strings(struct mlx5e_priv *priv, u32 stringset, u8 *data)
switch (stringset) { switch (stringset) {
case ETH_SS_PRIV_FLAGS: case ETH_SS_PRIV_FLAGS:
for (i = 0; i < ARRAY_SIZE(mlx5e_priv_flags); i++) for (i = 0; i < MLX5E_NUM_PFLAGS; i++)
strcpy(data + i * ETH_GSTRING_LEN, mlx5e_priv_flags[i]); strcpy(data + i * ETH_GSTRING_LEN,
mlx5e_priv_flags[i].name);
break; break;
case ETH_SS_TEST: case ETH_SS_TEST:
...@@ -1485,8 +1487,6 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev, ...@@ -1485,8 +1487,6 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev,
return 0; return 0;
} }
typedef int (*mlx5e_pflag_handler)(struct net_device *netdev, bool enable);
static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable, static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
bool is_rx_cq) bool is_rx_cq)
{ {
...@@ -1649,23 +1649,30 @@ static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable) ...@@ -1649,23 +1649,30 @@ static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable)
return 0; return 0;
} }
static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = {
{ "rx_cqe_moder", set_pflag_rx_cqe_based_moder },
{ "tx_cqe_moder", set_pflag_tx_cqe_based_moder },
{ "rx_cqe_compress", set_pflag_rx_cqe_compress },
{ "rx_striding_rq", set_pflag_rx_striding_rq },
{ "rx_no_csum_complete", set_pflag_rx_no_csum_complete },
};
static int mlx5e_handle_pflag(struct net_device *netdev, static int mlx5e_handle_pflag(struct net_device *netdev,
u32 wanted_flags, u32 wanted_flags,
enum mlx5e_priv_flag flag, enum mlx5e_priv_flag flag)
mlx5e_pflag_handler pflag_handler)
{ {
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
bool enable = !!(wanted_flags & flag); bool enable = !!(wanted_flags & BIT(flag));
u32 changes = wanted_flags ^ priv->channels.params.pflags; u32 changes = wanted_flags ^ priv->channels.params.pflags;
int err; int err;
if (!(changes & flag)) if (!(changes & BIT(flag)))
return 0; return 0;
err = pflag_handler(netdev, enable); err = mlx5e_priv_flags[flag].handler(netdev, enable);
if (err) { if (err) {
netdev_err(netdev, "%s private flag 0x%x failed err %d\n", netdev_err(netdev, "%s private flag '%s' failed err %d\n",
enable ? "Enable" : "Disable", flag, err); enable ? "Enable" : "Disable", mlx5e_priv_flags[flag].name, err);
return err; return err;
} }
...@@ -1676,38 +1683,17 @@ static int mlx5e_handle_pflag(struct net_device *netdev, ...@@ -1676,38 +1683,17 @@ static int mlx5e_handle_pflag(struct net_device *netdev,
static int mlx5e_set_priv_flags(struct net_device *netdev, u32 pflags) static int mlx5e_set_priv_flags(struct net_device *netdev, u32 pflags)
{ {
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
enum mlx5e_priv_flag pflag;
int err; int err;
mutex_lock(&priv->state_lock); mutex_lock(&priv->state_lock);
err = mlx5e_handle_pflag(netdev, pflags,
MLX5E_PFLAG_RX_CQE_BASED_MODER,
set_pflag_rx_cqe_based_moder);
if (err)
goto out;
err = mlx5e_handle_pflag(netdev, pflags, for (pflag = 0; pflag < MLX5E_NUM_PFLAGS; pflag++) {
MLX5E_PFLAG_TX_CQE_BASED_MODER, err = mlx5e_handle_pflag(netdev, pflags, pflag);
set_pflag_tx_cqe_based_moder);
if (err) if (err)
goto out; break;
}
err = mlx5e_handle_pflag(netdev, pflags,
MLX5E_PFLAG_RX_CQE_COMPRESS,
set_pflag_rx_cqe_compress);
if (err)
goto out;
err = mlx5e_handle_pflag(netdev, pflags,
MLX5E_PFLAG_RX_STRIDING_RQ,
set_pflag_rx_striding_rq);
if (err)
goto out;
err = mlx5e_handle_pflag(netdev, pflags,
MLX5E_PFLAG_RX_NO_CSUM_COMPLETE,
set_pflag_rx_no_csum_complete);
out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
/* Need to fix some features.. */ /* Need to fix some features.. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment