]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: Lag: refactor representor reload handling
authorMark Bloch <mbloch@nvidia.com>
Sun, 3 May 2026 20:27:20 +0000 (23:27 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 7 May 2026 02:03:36 +0000 (19:03 -0700)
Representor reload during LAG/MPESW transitions has to be repeated in
several flows, and each open-coded loop was easy to get out of sync
when adding new flags or tweaking error handling. Move the sequencing
into a single helper so that all call sites share the same ordering
and checks.

Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260503202726.266415-2-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c

index 449e4bd86c0645afd180e6a1b070ed1fbb9edbe4..a474f970e0566010d8f932fd24b141513ee5bcf8 100644 (file)
@@ -1093,6 +1093,27 @@ void mlx5_lag_remove_devices(struct mlx5_lag *ldev)
        }
 }
 
+int mlx5_lag_reload_ib_reps(struct mlx5_lag *ldev, u32 flags, bool cont_on_fail)
+{
+       struct lag_func *pf;
+       int ret;
+       int i;
+
+       mlx5_ldev_for_each(i, 0, ldev) {
+               pf = mlx5_lag_pf(ldev, i);
+               if (!(pf->dev->priv.flags & flags)) {
+                       struct mlx5_eswitch *esw;
+
+                       esw = pf->dev->priv.eswitch;
+                       ret = mlx5_eswitch_reload_ib_reps(esw);
+                       if (ret && !cont_on_fail)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
 void mlx5_disable_lag(struct mlx5_lag *ldev)
 {
        bool shared_fdb = test_bit(MLX5_LAG_MODE_FLAG_SHARED_FDB, &ldev->mode_flags);
@@ -1130,9 +1151,8 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)
                mlx5_lag_add_devices(ldev);
 
        if (shared_fdb)
-               mlx5_ldev_for_each(i, 0, ldev)
-                       if (!(mlx5_lag_pf(ldev, i)->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV))
-                               mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
+               mlx5_lag_reload_ib_reps(ldev, MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV,
+                                       true);
 }
 
 bool mlx5_lag_shared_fdb_supported(struct mlx5_lag *ldev)
@@ -1388,10 +1408,8 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
                if (err) {
                        if (shared_fdb || roce_lag)
                                mlx5_lag_add_devices(ldev);
-                       if (shared_fdb) {
-                               mlx5_ldev_for_each(i, 0, ldev)
-                                       mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
-                       }
+                       if (shared_fdb)
+                               mlx5_lag_reload_ib_reps(ldev, 0, true);
 
                        return;
                }
@@ -1409,24 +1427,15 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
                                        mlx5_nic_vport_enable_roce(dev);
                        }
                } else if (shared_fdb) {
-                       int i;
-
                        dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
                        mlx5_rescan_drivers_locked(dev0);
-
-                       mlx5_ldev_for_each(i, 0, ldev) {
-                               err = mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
-                               if (err)
-                                       break;
-                       }
-
+                       err = mlx5_lag_reload_ib_reps(ldev, 0, false);
                        if (err) {
                                dev0->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
                                mlx5_rescan_drivers_locked(dev0);
                                mlx5_deactivate_lag(ldev);
                                mlx5_lag_add_devices(ldev);
-                               mlx5_ldev_for_each(i, 0, ldev)
-                                       mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
+                               mlx5_lag_reload_ib_reps(ldev, 0, true);
                                mlx5_core_err(dev0, "Failed to enable lag\n");
                                return;
                        }
index 6c911374f409ba7d3ecedb465cdb7b4965d01ba9..daca8ebd52567373591d27770f7881b61ff63a4f 100644 (file)
@@ -199,4 +199,6 @@ int mlx5_get_next_ldev_func(struct mlx5_lag *ldev, int start_idx);
 int mlx5_lag_get_dev_index_by_seq(struct mlx5_lag *ldev, int seq);
 int mlx5_lag_num_devs(struct mlx5_lag *ldev);
 int mlx5_lag_num_netdevs(struct mlx5_lag *ldev);
+int mlx5_lag_reload_ib_reps(struct mlx5_lag *ldev, u32 flags,
+                           bool cont_on_fail);
 #endif /* __MLX5_LAG_H__ */
index 5eea12a6887ac0c11675488a6615957869d145e1..edcd06f3be7a74b86e7094510ca33c44e41bc83e 100644 (file)
@@ -70,7 +70,6 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
        int idx = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1);
        struct mlx5_core_dev *dev0;
        int err;
-       int i;
 
        if (ldev->mode == MLX5_LAG_MODE_MPESW)
                return 0;
@@ -103,11 +102,9 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
 
        dev0->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
        mlx5_rescan_drivers_locked(dev0);
-       mlx5_ldev_for_each(i, 0, ldev) {
-               err = mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
-               if (err)
-                       goto err_rescan_drivers;
-       }
+       err = mlx5_lag_reload_ib_reps(ldev, 0, false);
+       if (err)
+               goto err_rescan_drivers;
 
        mlx5_lag_set_vports_agg_speed(ldev);
 
@@ -119,8 +116,7 @@ err_rescan_drivers:
        mlx5_deactivate_lag(ldev);
 err_add_devices:
        mlx5_lag_add_devices(ldev);
-       mlx5_ldev_for_each(i, 0, ldev)
-               mlx5_eswitch_reload_ib_reps(mlx5_lag_pf(ldev, i)->dev->priv.eswitch);
+       mlx5_lag_reload_ib_reps(ldev, 0, true);
        mlx5_mpesw_metadata_cleanup(ldev);
        return err;
 }