]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net/mlx5: E-Switch, Update VF vports config when num of VFs changed
authorBodong Wang <bodong@mellanox.com>
Tue, 12 Nov 2019 17:30:10 +0000 (11:30 -0600)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 13 Mar 2020 23:26:12 +0000 (16:26 -0700)
Currently, ECPF eswitch manager does one-time only configuration for
VF vports when device switches to offloads mode. However, when num of
VFs changed from host side, driver doesn't update VF vports
configurations.

Hence, perform VFs vport configuration update whenever num_vfs change
event occurs.

Signed-off-by: Bodong Wang <bodong@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index 2f556c8202306b2d215c7991b86724c0a6ecbd3a..1de2472a72e7f71643deab4d513671a767bf4619 100644 (file)
@@ -1953,8 +1953,8 @@ static void mlx5_eswitch_clear_vf_vports_info(struct mlx5_eswitch *esw)
 /* Public E-Switch API */
 #define ESW_ALLOWED(esw) ((esw) && MLX5_ESWITCH_MANAGER((esw)->dev))
 
-static int mlx5_eswitch_load_vport(struct mlx5_eswitch *esw, u16 vport_num,
-                                  enum mlx5_eswitch_vport_event enabled_events)
+int mlx5_eswitch_load_vport(struct mlx5_eswitch *esw, u16 vport_num,
+                           enum mlx5_eswitch_vport_event enabled_events)
 {
        int err;
 
@@ -1973,12 +1973,39 @@ err_rep:
        return err;
 }
 
-static void mlx5_eswitch_unload_vport(struct mlx5_eswitch *esw, u16 vport_num)
+void mlx5_eswitch_unload_vport(struct mlx5_eswitch *esw, u16 vport_num)
 {
        esw_offloads_unload_rep(esw, vport_num);
        esw_disable_vport(esw, vport_num);
 }
 
+void mlx5_eswitch_unload_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs)
+{
+       int i;
+
+       mlx5_esw_for_each_vf_vport_num_reverse(esw, i, num_vfs)
+               mlx5_eswitch_unload_vport(esw, i);
+}
+
+int mlx5_eswitch_load_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs,
+                               enum mlx5_eswitch_vport_event enabled_events)
+{
+       int err;
+       int i;
+
+       mlx5_esw_for_each_vf_vport_num(esw, i, num_vfs) {
+               err = mlx5_eswitch_load_vport(esw, i, enabled_events);
+               if (err)
+                       goto vf_err;
+       }
+
+       return 0;
+
+vf_err:
+       mlx5_eswitch_unload_vf_vports(esw, i - 1);
+       return err;
+}
+
 /* mlx5_eswitch_enable_pf_vf_vports() enables vports of PF, ECPF and VFs
  * whichever are present on the eswitch.
  */
@@ -1986,9 +2013,7 @@ int
 mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw,
                                 enum mlx5_eswitch_vport_event enabled_events)
 {
-       int num_vfs;
        int ret;
-       int i;
 
        /* Enable PF vport */
        ret = mlx5_eswitch_load_vport(esw, MLX5_VPORT_PF, enabled_events);
@@ -2003,18 +2028,13 @@ mlx5_eswitch_enable_pf_vf_vports(struct mlx5_eswitch *esw,
        }
 
        /* Enable VF vports */
-       mlx5_esw_for_each_vf_vport_num(esw, i, esw->esw_funcs.num_vfs) {
-               ret = mlx5_eswitch_load_vport(esw, i, enabled_events);
-               if (ret)
-                       goto vf_err;
-       }
+       ret = mlx5_eswitch_load_vf_vports(esw, esw->esw_funcs.num_vfs,
+                                         enabled_events);
+       if (ret)
+               goto vf_err;
        return 0;
 
 vf_err:
-       num_vfs = i - 1;
-       mlx5_esw_for_each_vf_vport_num_reverse(esw, i, num_vfs)
-               mlx5_eswitch_unload_vport(esw, i);
-
        if (mlx5_ecpf_vport_exists(esw->dev))
                mlx5_eswitch_unload_vport(esw, MLX5_VPORT_ECPF);
 
@@ -2028,10 +2048,7 @@ ecpf_err:
  */
 void mlx5_eswitch_disable_pf_vf_vports(struct mlx5_eswitch *esw)
 {
-       int i;
-
-       mlx5_esw_for_each_vf_vport_num_reverse(esw, i, esw->esw_funcs.num_vfs)
-               mlx5_eswitch_unload_vport(esw, i);
+       mlx5_eswitch_unload_vf_vports(esw, esw->esw_funcs.num_vfs);
 
        if (mlx5_ecpf_vport_exists(esw->dev))
                mlx5_eswitch_unload_vport(esw, MLX5_VPORT_ECPF);
index 1213a69cf397db073d44fac890601bb4a5147fd2..91b2aedcf52bc754adbd3e8280d27ec2985d4bf2 100644 (file)
@@ -654,6 +654,14 @@ esw_get_max_restore_tag(struct mlx5_eswitch *esw);
 int esw_offloads_load_rep(struct mlx5_eswitch *esw, u16 vport_num);
 void esw_offloads_unload_rep(struct mlx5_eswitch *esw, u16 vport_num);
 
+int mlx5_eswitch_load_vport(struct mlx5_eswitch *esw, u16 vport_num,
+                           enum mlx5_eswitch_vport_event enabled_events);
+void mlx5_eswitch_unload_vport(struct mlx5_eswitch *esw, u16 vport_num);
+
+int mlx5_eswitch_load_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs,
+                               enum mlx5_eswitch_vport_event enabled_events);
+void mlx5_eswitch_unload_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs);
+
 #else  /* CONFIG_MLX5_ESWITCH */
 /* eswitch API stubs */
 static inline int  mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
index 865c120f577ef837ee729b402511b5a21986d5a3..badae90206ac1cbd9ed28dd08ea347ae6c77716a 100644 (file)
@@ -1662,14 +1662,6 @@ static void __unload_reps_vf_vport(struct mlx5_eswitch *esw, int nvports,
                __esw_offloads_unload_rep(esw, rep, rep_type);
 }
 
-static void esw_offloads_unload_vf_reps(struct mlx5_eswitch *esw, int nvports)
-{
-       u8 rep_type = NUM_REP_TYPES;
-
-       while (rep_type-- > 0)
-               __unload_reps_vf_vport(esw, nvports, rep_type);
-}
-
 static void __unload_reps_all_vport(struct mlx5_eswitch *esw, u8 rep_type)
 {
        __unload_reps_vf_vport(esw, esw->esw_funcs.num_vfs, rep_type);
@@ -1678,60 +1670,6 @@ static void __unload_reps_all_vport(struct mlx5_eswitch *esw, u8 rep_type)
        __unload_reps_special_vport(esw, rep_type);
 }
 
-static int __esw_offloads_load_rep(struct mlx5_eswitch *esw,
-                                  struct mlx5_eswitch_rep *rep, u8 rep_type)
-{
-       int err = 0;
-
-       if (atomic_cmpxchg(&rep->rep_data[rep_type].state,
-                          REP_REGISTERED, REP_LOADED) == REP_REGISTERED) {
-               err = esw->offloads.rep_ops[rep_type]->load(esw->dev, rep);
-               if (err)
-                       atomic_set(&rep->rep_data[rep_type].state,
-                                  REP_REGISTERED);
-       }
-
-       return err;
-}
-
-static int __load_reps_vf_vport(struct mlx5_eswitch *esw, int nvports,
-                               u8 rep_type)
-{
-       struct mlx5_eswitch_rep *rep;
-       int err, i;
-
-       mlx5_esw_for_each_vf_rep(esw, i, rep, nvports) {
-               err = __esw_offloads_load_rep(esw, rep, rep_type);
-               if (err)
-                       goto err_vf;
-       }
-
-       return 0;
-
-err_vf:
-       __unload_reps_vf_vport(esw, --i, rep_type);
-       return err;
-}
-
-static int esw_offloads_load_vf_reps(struct mlx5_eswitch *esw, int nvports)
-{
-       u8 rep_type = 0;
-       int err;
-
-       for (rep_type = 0; rep_type < NUM_REP_TYPES; rep_type++) {
-               err = __load_reps_vf_vport(esw, nvports, rep_type);
-               if (err)
-                       goto err_reps;
-       }
-
-       return err;
-
-err_reps:
-       while (rep_type-- > 0)
-               __unload_reps_vf_vport(esw, nvports, rep_type);
-       return err;
-}
-
 int esw_offloads_load_rep(struct mlx5_eswitch *esw, u16 vport_num)
 {
        struct mlx5_eswitch_rep *rep;
@@ -2346,11 +2284,12 @@ esw_vfs_changed_event_handler(struct mlx5_eswitch *esw, const u32 *out)
 
        /* Number of VFs can only change from "0 to x" or "x to 0". */
        if (esw->esw_funcs.num_vfs > 0) {
-               esw_offloads_unload_vf_reps(esw, esw->esw_funcs.num_vfs);
+               mlx5_eswitch_unload_vf_vports(esw, esw->esw_funcs.num_vfs);
        } else {
                int err;
 
-               err = esw_offloads_load_vf_reps(esw, new_num_vfs);
+               err = mlx5_eswitch_load_vf_vports(esw, new_num_vfs,
+                                                 MLX5_VPORT_UC_ADDR_CHANGE);
                if (err)
                        return;
        }