Commit b6f2846a authored by Chris Mi's avatar Chris Mi Committed by Saeed Mahameed

net/mlx5: E-switch: Change eswitch mode only via devlink command

Enable or disable switchdev according to the eswitch mode set by
devlink command. So it is not changed by other functions anymore.
Signed-off-by: default avatarChris Mi <cmi@nvidia.com>
Reviewed-by: default avatarRoi Dayan <roid@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent f019679e
...@@ -1227,7 +1227,6 @@ static void mlx5_esw_acls_ns_cleanup(struct mlx5_eswitch *esw) ...@@ -1227,7 +1227,6 @@ static void mlx5_esw_acls_ns_cleanup(struct mlx5_eswitch *esw)
/** /**
* mlx5_eswitch_enable_locked - Enable eswitch * mlx5_eswitch_enable_locked - Enable eswitch
* @esw: Pointer to eswitch * @esw: Pointer to eswitch
* @mode: Eswitch mode to enable
* @num_vfs: Enable eswitch for given number of VFs. This is optional. * @num_vfs: Enable eswitch for given number of VFs. This is optional.
* Valid value are 0, > 0 and MLX5_ESWITCH_IGNORE_NUM_VFS. * Valid value are 0, > 0 and MLX5_ESWITCH_IGNORE_NUM_VFS.
* Caller should pass num_vfs > 0 when enabling eswitch for * Caller should pass num_vfs > 0 when enabling eswitch for
...@@ -1241,7 +1240,7 @@ static void mlx5_esw_acls_ns_cleanup(struct mlx5_eswitch *esw) ...@@ -1241,7 +1240,7 @@ static void mlx5_esw_acls_ns_cleanup(struct mlx5_eswitch *esw)
* mode. If num_vfs >=0 is provided, it setup VF related eswitch vports. * mode. If num_vfs >=0 is provided, it setup VF related eswitch vports.
* It returns 0 on success or error code on failure. * It returns 0 on success or error code on failure.
*/ */
int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs) int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs)
{ {
int err; int err;
...@@ -1260,9 +1259,7 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs) ...@@ -1260,9 +1259,7 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs)
mlx5_eswitch_update_num_of_vfs(esw, num_vfs); mlx5_eswitch_update_num_of_vfs(esw, num_vfs);
esw->mode = mode; if (esw->mode == MLX5_ESWITCH_LEGACY) {
if (mode == MLX5_ESWITCH_LEGACY) {
err = esw_legacy_enable(esw); err = esw_legacy_enable(esw);
} else { } else {
mlx5_rescan_drivers(esw->dev); mlx5_rescan_drivers(esw->dev);
...@@ -1277,19 +1274,14 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs) ...@@ -1277,19 +1274,14 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs)
mlx5_eswitch_event_handlers_register(esw); mlx5_eswitch_event_handlers_register(esw);
esw_info(esw->dev, "Enable: mode(%s), nvfs(%d), active vports(%d)\n", esw_info(esw->dev, "Enable: mode(%s), nvfs(%d), active vports(%d)\n",
mode == MLX5_ESWITCH_LEGACY ? "LEGACY" : "OFFLOADS", esw->mode == MLX5_ESWITCH_LEGACY ? "LEGACY" : "OFFLOADS",
esw->esw_funcs.num_vfs, esw->enabled_vports); esw->esw_funcs.num_vfs, esw->enabled_vports);
mlx5_esw_mode_change_notify(esw, mode); mlx5_esw_mode_change_notify(esw, esw->mode);
return 0; return 0;
abort: abort:
esw->mode = MLX5_ESWITCH_LEGACY;
if (mode == MLX5_ESWITCH_OFFLOADS)
mlx5_rescan_drivers(esw->dev);
mlx5_esw_acls_ns_cleanup(esw); mlx5_esw_acls_ns_cleanup(esw);
return err; return err;
} }
...@@ -1317,7 +1309,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) ...@@ -1317,7 +1309,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
down_write(&esw->mode_lock); down_write(&esw->mode_lock);
if (!mlx5_esw_is_fdb_created(esw)) { if (!mlx5_esw_is_fdb_created(esw)) {
ret = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_LEGACY, num_vfs); ret = mlx5_eswitch_enable_locked(esw, num_vfs);
} else { } else {
enum mlx5_eswitch_vport_event vport_events; enum mlx5_eswitch_vport_event vport_events;
......
...@@ -356,7 +356,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev); ...@@ -356,7 +356,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev);
void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw); void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
#define MLX5_ESWITCH_IGNORE_NUM_VFS (-1) #define MLX5_ESWITCH_IGNORE_NUM_VFS (-1)
int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs); int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int num_vfs);
int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs); int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs);
void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf); void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw, bool clear_vf);
void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw); void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw);
......
...@@ -2179,17 +2179,18 @@ static int esw_offloads_start(struct mlx5_eswitch *esw, ...@@ -2179,17 +2179,18 @@ static int esw_offloads_start(struct mlx5_eswitch *esw,
{ {
int err, err1; int err, err1;
err = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_OFFLOADS, esw->mode = MLX5_ESWITCH_OFFLOADS;
esw->dev->priv.sriov.num_vfs); err = mlx5_eswitch_enable_locked(esw, esw->dev->priv.sriov.num_vfs);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Failed setting eswitch to offloads"); "Failed setting eswitch to offloads");
err1 = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_LEGACY, esw->mode = MLX5_ESWITCH_LEGACY;
MLX5_ESWITCH_IGNORE_NUM_VFS); err1 = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_IGNORE_NUM_VFS);
if (err1) { if (err1) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Failed setting eswitch back to legacy"); "Failed setting eswitch back to legacy");
} }
mlx5_rescan_drivers(esw->dev);
} }
if (esw->offloads.inline_mode == MLX5_INLINE_MODE_NONE) { if (esw->offloads.inline_mode == MLX5_INLINE_MODE_NONE) {
if (mlx5_eswitch_inline_mode_get(esw, if (mlx5_eswitch_inline_mode_get(esw,
...@@ -3237,12 +3238,12 @@ static int esw_offloads_stop(struct mlx5_eswitch *esw, ...@@ -3237,12 +3238,12 @@ static int esw_offloads_stop(struct mlx5_eswitch *esw,
{ {
int err, err1; int err, err1;
err = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_LEGACY, esw->mode = MLX5_ESWITCH_LEGACY;
MLX5_ESWITCH_IGNORE_NUM_VFS); err = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_IGNORE_NUM_VFS);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed setting eswitch to legacy"); NL_SET_ERR_MSG_MOD(extack, "Failed setting eswitch to legacy");
err1 = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_OFFLOADS, esw->mode = MLX5_ESWITCH_OFFLOADS;
MLX5_ESWITCH_IGNORE_NUM_VFS); err1 = mlx5_eswitch_enable_locked(esw, MLX5_ESWITCH_IGNORE_NUM_VFS);
if (err1) { if (err1) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Failed setting eswitch back to offloads"); "Failed setting eswitch back to offloads");
......
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