Skip to content

Commit 7d0314b

Browse files
Ron DiskinSaeed Mahameed
authored andcommitted
net/mlx5e: Modify uplink state on interface up/down
When setting the PF interface up/down, notify the firmware to update uplink state via MODIFY_VPORT_STATE, when E-Switch is enabled. This behavior will prevent sending traffic out on uplink port when PF is down, such as sending traffic from a VF interface which is still up. Currently when calling mlx5e_open/close(), the driver only sends PAOS command to notify the firmware to set the physical port state to up/down, however, it is not sufficient. When VF is in "auto" state, it follows the uplink state, which was not updated on mlx5e_open/close() before this patch. When switchdev mode is enabled and uplink representor is first enabled, set the uplink port state value back to its FW default "AUTO". Fixes: 63bfd39 ("net/mlx5e: Send PAOS command on interface up/down") Signed-off-by: Ron Diskin <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Reviewed-by: Moshe Shemesh <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent ed56d74 commit 7d0314b

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,25 @@ void mlx5e_timestamp_init(struct mlx5e_priv *priv)
30693069
priv->tstamp.rx_filter = HWTSTAMP_FILTER_NONE;
30703070
}
30713071

3072+
static void mlx5e_modify_admin_state(struct mlx5_core_dev *mdev,
3073+
enum mlx5_port_status state)
3074+
{
3075+
struct mlx5_eswitch *esw = mdev->priv.eswitch;
3076+
int vport_admin_state;
3077+
3078+
mlx5_set_port_admin_status(mdev, state);
3079+
3080+
if (!MLX5_ESWITCH_MANAGER(mdev) || mlx5_eswitch_mode(esw) == MLX5_ESWITCH_OFFLOADS)
3081+
return;
3082+
3083+
if (state == MLX5_PORT_UP)
3084+
vport_admin_state = MLX5_VPORT_ADMIN_STATE_AUTO;
3085+
else
3086+
vport_admin_state = MLX5_VPORT_ADMIN_STATE_DOWN;
3087+
3088+
mlx5_eswitch_set_vport_state(esw, MLX5_VPORT_UPLINK, vport_admin_state);
3089+
}
3090+
30723091
int mlx5e_open_locked(struct net_device *netdev)
30733092
{
30743093
struct mlx5e_priv *priv = netdev_priv(netdev);
@@ -3101,7 +3120,7 @@ int mlx5e_open(struct net_device *netdev)
31013120
mutex_lock(&priv->state_lock);
31023121
err = mlx5e_open_locked(netdev);
31033122
if (!err)
3104-
mlx5_set_port_admin_status(priv->mdev, MLX5_PORT_UP);
3123+
mlx5e_modify_admin_state(priv->mdev, MLX5_PORT_UP);
31053124
mutex_unlock(&priv->state_lock);
31063125

31073126
return err;
@@ -3135,7 +3154,7 @@ int mlx5e_close(struct net_device *netdev)
31353154
return -ENODEV;
31363155

31373156
mutex_lock(&priv->state_lock);
3138-
mlx5_set_port_admin_status(priv->mdev, MLX5_PORT_DOWN);
3157+
mlx5e_modify_admin_state(priv->mdev, MLX5_PORT_DOWN);
31393158
err = mlx5e_close_locked(netdev);
31403159
mutex_unlock(&priv->state_lock);
31413160

@@ -5182,7 +5201,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
51825201

51835202
/* Marking the link as currently not needed by the Driver */
51845203
if (!netif_running(netdev))
5185-
mlx5_set_port_admin_status(mdev, MLX5_PORT_DOWN);
5204+
mlx5e_modify_admin_state(mdev, MLX5_PORT_DOWN);
51865205

51875206
mlx5e_set_netdev_mtu_boundaries(priv);
51885207
mlx5e_set_dev_port_mtu(priv);

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,8 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
10811081

10821082
mlx5e_rep_tc_enable(priv);
10831083

1084+
mlx5_modify_vport_admin_state(mdev, MLX5_VPORT_STATE_OP_MOD_UPLINK,
1085+
0, 0, MLX5_VPORT_ADMIN_STATE_AUTO);
10841086
mlx5_lag_add(mdev, netdev);
10851087
priv->events_nb.notifier_call = uplink_rep_async_event;
10861088
mlx5_notifier_register(mdev, &priv->events_nb);

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,22 +1826,26 @@ int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
18261826
u16 vport, int link_state)
18271827
{
18281828
struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
1829+
int opmod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT;
1830+
int other_vport = 1;
18291831
int err = 0;
18301832

18311833
if (!ESW_ALLOWED(esw))
18321834
return -EPERM;
18331835
if (IS_ERR(evport))
18341836
return PTR_ERR(evport);
18351837

1838+
if (vport == MLX5_VPORT_UPLINK) {
1839+
opmod = MLX5_VPORT_STATE_OP_MOD_UPLINK;
1840+
other_vport = 0;
1841+
vport = 0;
1842+
}
18361843
mutex_lock(&esw->state_lock);
18371844

1838-
err = mlx5_modify_vport_admin_state(esw->dev,
1839-
MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
1840-
vport, 1, link_state);
1845+
err = mlx5_modify_vport_admin_state(esw->dev, opmod, vport, other_vport, link_state);
18411846
if (err) {
1842-
mlx5_core_warn(esw->dev,
1843-
"Failed to set vport %d link state, err = %d",
1844-
vport, err);
1847+
mlx5_core_warn(esw->dev, "Failed to set vport %d link state, opmod = %d, err = %d",
1848+
vport, opmod, err);
18451849
goto unlock;
18461850
}
18471851

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ static inline int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs) { r
680680
static inline void mlx5_eswitch_disable(struct mlx5_eswitch *esw, bool clear_vf) {}
681681
static inline bool mlx5_esw_lag_prereq(struct mlx5_core_dev *dev0, struct mlx5_core_dev *dev1) { return true; }
682682
static inline bool mlx5_eswitch_is_funcs_handler(struct mlx5_core_dev *dev) { return false; }
683+
static inline
684+
int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw, u16 vport, int link_state) { return 0; }
683685
static inline const u32 *mlx5_esw_query_functions(struct mlx5_core_dev *dev)
684686
{
685687
return ERR_PTR(-EOPNOTSUPP);

include/linux/mlx5/mlx5_ifc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,6 +4381,7 @@ struct mlx5_ifc_query_vport_state_out_bits {
43814381
enum {
43824382
MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT = 0x0,
43834383
MLX5_VPORT_STATE_OP_MOD_ESW_VPORT = 0x1,
4384+
MLX5_VPORT_STATE_OP_MOD_UPLINK = 0x2,
43844385
};
43854386

43864387
struct mlx5_ifc_arm_monitor_counter_in_bits {

0 commit comments

Comments
 (0)