Skip to content

Commit 2e20a15

Browse files
author
Saeed Mahameed
committed
net/mlx5e: Fail safe mtu and lro setting
Use the new fail-safe channels switch mechanism to set new netdev mtu and lro settings. MTU and lro settings demand some HW configuration changes after new channels are created and ready for action. In order to unify switch channels routine for LRO and MTU changes, and maybe future configuration features, we now pass to it a modify HW function pointer to be invoked directly after old channels are de-activated and before new channels are activated. Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Tariq Toukan <[email protected]>
1 parent 6f9485a commit 2e20a15

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,14 @@ int mlx5e_close_locked(struct net_device *netdev);
867867
int mlx5e_open_channels(struct mlx5e_priv *priv,
868868
struct mlx5e_channels *chs);
869869
void mlx5e_close_channels(struct mlx5e_channels *chs);
870+
871+
/* Function pointer to be used to modify WH settings while
872+
* switching channels
873+
*/
874+
typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv);
870875
void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
871-
struct mlx5e_channels *new_chs);
876+
struct mlx5e_channels *new_chs,
877+
mlx5e_fp_hw_modify hw_modify);
872878

873879
void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
874880
u32 *indirection_rqt, int len,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static int mlx5e_set_ringparam(struct net_device *dev,
540540
if (err)
541541
goto unlock;
542542

543-
mlx5e_switch_priv_channels(priv, &new_channels);
543+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
544544

545545
unlock:
546546
mutex_unlock(&priv->state_lock);
@@ -597,7 +597,7 @@ static int mlx5e_set_channels(struct net_device *dev,
597597
mlx5e_arfs_disable(priv);
598598

599599
/* Switch to new channels, set new parameters and close old ones */
600-
mlx5e_switch_priv_channels(priv, &new_channels);
600+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
601601

602602
if (arfs_enabled) {
603603
err = mlx5e_arfs_enable(priv);
@@ -691,7 +691,7 @@ static int mlx5e_set_coalesce(struct net_device *netdev,
691691
if (err)
692692
goto out;
693693

694-
mlx5e_switch_priv_channels(priv, &new_channels);
694+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
695695

696696
out:
697697
mutex_unlock(&priv->state_lock);
@@ -1166,7 +1166,7 @@ static int mlx5e_set_tunable(struct net_device *dev,
11661166
err = mlx5e_open_channels(priv, &new_channels);
11671167
if (err)
11681168
break;
1169-
mlx5e_switch_priv_channels(priv, &new_channels);
1169+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
11701170

11711171
break;
11721172
default:
@@ -1503,7 +1503,7 @@ static int set_pflag_rx_cqe_based_moder(struct net_device *netdev, bool enable)
15031503
if (err)
15041504
return err;
15051505

1506-
mlx5e_switch_priv_channels(priv, &new_channels);
1506+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
15071507
return 0;
15081508
}
15091509

@@ -1534,7 +1534,7 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
15341534
if (err)
15351535
return err;
15361536

1537-
mlx5e_switch_priv_channels(priv, &new_channels);
1537+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
15381538
return 0;
15391539
}
15401540

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

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,9 +2437,9 @@ static void mlx5e_query_mtu(struct mlx5e_priv *priv, u16 *mtu)
24372437
*mtu = MLX5E_HW2SW_MTU(hw_mtu);
24382438
}
24392439

2440-
static int mlx5e_set_dev_port_mtu(struct net_device *netdev)
2440+
static int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
24412441
{
2442-
struct mlx5e_priv *priv = netdev_priv(netdev);
2442+
struct net_device *netdev = priv->netdev;
24432443
u16 mtu;
24442444
int err;
24452445

@@ -2534,7 +2534,8 @@ static void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)
25342534
}
25352535

25362536
void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
2537-
struct mlx5e_channels *new_chs)
2537+
struct mlx5e_channels *new_chs,
2538+
mlx5e_fp_hw_modify hw_modify)
25382539
{
25392540
struct net_device *netdev = priv->netdev;
25402541
int new_num_txqs;
@@ -2551,6 +2552,10 @@ void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
25512552

25522553
priv->channels = *new_chs;
25532554

2555+
/* New channels are ready to roll, modify HW settings if needed */
2556+
if (hw_modify)
2557+
hw_modify(priv);
2558+
25542559
mlx5e_refresh_tirs(priv, false);
25552560
mlx5e_activate_priv_channels(priv);
25562561

@@ -2930,7 +2935,7 @@ static int mlx5e_setup_tc(struct net_device *netdev, u8 tc)
29302935
if (err)
29312936
goto out;
29322937

2933-
mlx5e_switch_priv_channels(priv, &new_channels);
2938+
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
29342939
out:
29352940
mutex_unlock(&priv->state_lock);
29362941
return err;
@@ -3049,26 +3054,31 @@ typedef int (*mlx5e_feature_handler)(struct net_device *netdev, bool enable);
30493054
static int set_feature_lro(struct net_device *netdev, bool enable)
30503055
{
30513056
struct mlx5e_priv *priv = netdev_priv(netdev);
3052-
bool was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
3053-
int err;
3057+
struct mlx5e_channels new_channels = {};
3058+
int err = 0;
3059+
bool reset;
30543060

30553061
mutex_lock(&priv->state_lock);
30563062

3057-
if (was_opened && (priv->channels.params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
3058-
mlx5e_close_locked(priv->netdev);
3063+
reset = (priv->channels.params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST);
3064+
reset = reset && test_bit(MLX5E_STATE_OPENED, &priv->state);
30593065

3060-
priv->channels.params.lro_en = enable;
3061-
err = mlx5e_modify_tirs_lro(priv);
3062-
if (err) {
3063-
netdev_err(netdev, "lro modify failed, %d\n", err);
3064-
priv->channels.params.lro_en = !enable;
3066+
new_channels.params = priv->channels.params;
3067+
new_channels.params.lro_en = enable;
3068+
3069+
if (!reset) {
3070+
priv->channels.params = new_channels.params;
3071+
err = mlx5e_modify_tirs_lro(priv);
3072+
goto out;
30653073
}
30663074

3067-
if (was_opened && (priv->channels.params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST))
3068-
mlx5e_open_locked(priv->netdev);
3075+
err = mlx5e_open_channels(priv, &new_channels);
3076+
if (err)
3077+
goto out;
30693078

3079+
mlx5e_switch_priv_channels(priv, &new_channels, mlx5e_modify_tirs_lro);
3080+
out:
30703081
mutex_unlock(&priv->state_lock);
3071-
30723082
return err;
30733083
}
30743084

@@ -3191,7 +3201,8 @@ static int mlx5e_set_features(struct net_device *netdev,
31913201
static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
31923202
{
31933203
struct mlx5e_priv *priv = netdev_priv(netdev);
3194-
bool was_opened;
3204+
struct mlx5e_channels new_channels = {};
3205+
int curr_mtu;
31953206
int err = 0;
31963207
bool reset;
31973208

@@ -3201,18 +3212,27 @@ static int mlx5e_change_mtu(struct net_device *netdev, int new_mtu)
32013212
(priv->channels.params.rq_wq_type !=
32023213
MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ);
32033214

3204-
was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
3205-
if (was_opened && reset)
3206-
mlx5e_close_locked(netdev);
3215+
reset = reset && test_bit(MLX5E_STATE_OPENED, &priv->state);
32073216

3217+
curr_mtu = netdev->mtu;
32083218
netdev->mtu = new_mtu;
3209-
mlx5e_set_dev_port_mtu(netdev);
32103219

3211-
if (was_opened && reset)
3212-
err = mlx5e_open_locked(netdev);
3220+
if (!reset) {
3221+
mlx5e_set_dev_port_mtu(priv);
3222+
goto out;
3223+
}
32133224

3214-
mutex_unlock(&priv->state_lock);
3225+
new_channels.params = priv->channels.params;
3226+
err = mlx5e_open_channels(priv, &new_channels);
3227+
if (err) {
3228+
netdev->mtu = curr_mtu;
3229+
goto out;
3230+
}
3231+
3232+
mlx5e_switch_priv_channels(priv, &new_channels, mlx5e_set_dev_port_mtu);
32153233

3234+
out:
3235+
mutex_unlock(&priv->state_lock);
32163236
return err;
32173237
}
32183238

@@ -4169,7 +4189,7 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev)
41694189
mlx5_query_port_max_mtu(priv->mdev, &max_mtu, 1);
41704190
netdev->max_mtu = MLX5E_HW2SW_MTU(max_mtu);
41714191

4172-
mlx5e_set_dev_port_mtu(netdev);
4192+
mlx5e_set_dev_port_mtu(priv);
41734193

41744194
if (profile->enable)
41754195
profile->enable(priv);

0 commit comments

Comments
 (0)