Skip to content

Commit

Permalink
net/mlx5: Support enable_eth devlink dev param
Browse files Browse the repository at this point in the history
Enable user to disable Ethernet auxiliary device so that when it is not
required, user can disable it.

For example,

$ devlink dev param set pci/0000:06:00.0 \
              name enable_eth value false cmode driverinit
$ devlink dev reload pci/0000:06:00.0

At this point devlink instance do not create mlx5_core.eth.2 auxiliary
device for the Ethernet functionality.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Parav Pandit authored and David S. Miller committed Aug 11, 2021
1 parent 6f35723 commit a17beb2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
42 changes: 40 additions & 2 deletions drivers/net/ethernet/mellanox/mlx5/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static bool is_eth_rep_supported(struct mlx5_core_dev *dev)
return true;
}

static bool is_eth_supported(struct mlx5_core_dev *dev)
bool mlx5_eth_supported(struct mlx5_core_dev *dev)
{
if (!IS_ENABLED(CONFIG_MLX5_CORE_EN))
return false;
Expand Down Expand Up @@ -105,6 +105,17 @@ static bool is_eth_supported(struct mlx5_core_dev *dev)
return true;
}

static bool is_eth_enabled(struct mlx5_core_dev *dev)
{
union devlink_param_value val;
int err;

err = devlink_param_driverinit_value_get(priv_to_devlink(dev),
DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
&val);
return err ? false : val.vbool;
}

static bool is_vnet_supported(struct mlx5_core_dev *dev)
{
if (!IS_ENABLED(CONFIG_MLX5_VDPA_NET))
Expand Down Expand Up @@ -201,13 +212,15 @@ enum {
static const struct mlx5_adev_device {
const char *suffix;
bool (*is_supported)(struct mlx5_core_dev *dev);
bool (*is_enabled)(struct mlx5_core_dev *dev);
} mlx5_adev_devices[] = {
[MLX5_INTERFACE_PROTOCOL_VNET] = { .suffix = "vnet",
.is_supported = &is_vnet_supported },
[MLX5_INTERFACE_PROTOCOL_IB] = { .suffix = "rdma",
.is_supported = &is_ib_supported },
[MLX5_INTERFACE_PROTOCOL_ETH] = { .suffix = "eth",
.is_supported = &is_eth_supported },
.is_supported = &mlx5_eth_supported,
.is_enabled = &is_eth_enabled },
[MLX5_INTERFACE_PROTOCOL_ETH_REP] = { .suffix = "eth-rep",
.is_supported = &is_eth_rep_supported },
[MLX5_INTERFACE_PROTOCOL_IB_REP] = { .suffix = "rdma-rep",
Expand Down Expand Up @@ -308,6 +321,14 @@ int mlx5_attach_device(struct mlx5_core_dev *dev)
if (!priv->adev[i]) {
bool is_supported = false;

if (mlx5_adev_devices[i].is_enabled) {
bool enabled;

enabled = mlx5_adev_devices[i].is_enabled(dev);
if (!enabled)
continue;
}

if (mlx5_adev_devices[i].is_supported)
is_supported = mlx5_adev_devices[i].is_supported(dev);

Expand Down Expand Up @@ -360,6 +381,14 @@ void mlx5_detach_device(struct mlx5_core_dev *dev)
if (!priv->adev[i])
continue;

if (mlx5_adev_devices[i].is_enabled) {
bool enabled;

enabled = mlx5_adev_devices[i].is_enabled(dev);
if (!enabled)
goto skip_suspend;
}

adev = &priv->adev[i]->adev;
/* Auxiliary driver was unbind manually through sysfs */
if (!adev->dev.driver)
Expand Down Expand Up @@ -447,12 +476,21 @@ static void delete_drivers(struct mlx5_core_dev *dev)
if (!priv->adev[i])
continue;

if (mlx5_adev_devices[i].is_enabled) {
bool enabled;

enabled = mlx5_adev_devices[i].is_enabled(dev);
if (!enabled)
goto del_adev;
}

if (mlx5_adev_devices[i].is_supported && !delete_all)
is_supported = mlx5_adev_devices[i].is_supported(dev);

if (is_supported)
continue;

del_adev:
del_adev(&priv->adev[i]->adev);
priv->adev[i] = NULL;
}
Expand Down
53 changes: 53 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,52 @@ static void mlx5_devlink_set_params_init_values(struct devlink *devlink)
#endif
}

static const struct devlink_param enable_eth_param =
DEVLINK_PARAM_GENERIC(ENABLE_ETH, BIT(DEVLINK_PARAM_CMODE_DRIVERINIT),
NULL, NULL, NULL);

static int mlx5_devlink_eth_param_register(struct devlink *devlink)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);
union devlink_param_value value;
int err;

if (!mlx5_eth_supported(dev))
return 0;

err = devlink_param_register(devlink, &enable_eth_param);
if (err)
return err;

value.vbool = true;
devlink_param_driverinit_value_set(devlink,
DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
value);
devlink_param_publish(devlink, &enable_eth_param);
return 0;
}

static void mlx5_devlink_eth_param_unregister(struct devlink *devlink)
{
struct mlx5_core_dev *dev = devlink_priv(devlink);

if (!mlx5_eth_supported(dev))
return;

devlink_param_unpublish(devlink, &enable_eth_param);
devlink_param_unregister(devlink, &enable_eth_param);
}

static int mlx5_devlink_auxdev_params_register(struct devlink *devlink)
{
return mlx5_devlink_eth_param_register(devlink);
}

static void mlx5_devlink_auxdev_params_unregister(struct devlink *devlink)
{
mlx5_devlink_eth_param_unregister(devlink);
}

#define MLX5_TRAP_DROP(_id, _group_id) \
DEVLINK_TRAP_GENERIC(DROP, DROP, _id, \
DEVLINK_TRAP_GROUP_GENERIC_ID_##_group_id, \
Expand Down Expand Up @@ -654,13 +700,19 @@ int mlx5_devlink_register(struct devlink *devlink)
mlx5_devlink_set_params_init_values(devlink);
devlink_params_publish(devlink);

err = mlx5_devlink_auxdev_params_register(devlink);
if (err)
goto auxdev_reg_err;

err = mlx5_devlink_traps_register(devlink);
if (err)
goto traps_reg_err;

return 0;

traps_reg_err:
mlx5_devlink_auxdev_params_unregister(devlink);
auxdev_reg_err:
devlink_params_unregister(devlink, mlx5_devlink_params,
ARRAY_SIZE(mlx5_devlink_params));
params_reg_err:
Expand All @@ -671,6 +723,7 @@ int mlx5_devlink_register(struct devlink *devlink)
void mlx5_devlink_unregister(struct devlink *devlink)
{
mlx5_devlink_traps_unregister(devlink);
mlx5_devlink_auxdev_params_unregister(devlink);
devlink_params_unpublish(devlink);
devlink_params_unregister(devlink, mlx5_devlink_params,
ARRAY_SIZE(mlx5_devlink_params));
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,7 @@ static inline u32 mlx5_sriov_get_vf_total_msix(struct pci_dev *pdev)

return MLX5_CAP_GEN_MAX(dev, num_total_dynamic_vf_msix);
}

bool mlx5_eth_supported(struct mlx5_core_dev *dev);

#endif /* __MLX5_CORE_H__ */

0 comments on commit a17beb2

Please sign in to comment.