Merge tag 'mt76-for-kvalo-2021-01-29' of https://github.com/nbd168/wireless
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / eswitch_offloads.c
index 2f6a0ae..7f09f2b 100644 (file)
@@ -1800,11 +1800,22 @@ static void __esw_offloads_unload_rep(struct mlx5_eswitch *esw,
                esw->offloads.rep_ops[rep_type]->unload(rep);
 }
 
+static void __unload_reps_sf_vport(struct mlx5_eswitch *esw, u8 rep_type)
+{
+       struct mlx5_eswitch_rep *rep;
+       int i;
+
+       mlx5_esw_for_each_sf_rep(esw, i, rep)
+               __esw_offloads_unload_rep(esw, rep, rep_type);
+}
+
 static void __unload_reps_all_vport(struct mlx5_eswitch *esw, u8 rep_type)
 {
        struct mlx5_eswitch_rep *rep;
        int i;
 
+       __unload_reps_sf_vport(esw, rep_type);
+
        mlx5_esw_for_each_vf_rep_reverse(esw, i, rep, esw->esw_funcs.num_vfs)
                __esw_offloads_unload_rep(esw, rep, rep_type);
 
@@ -1822,7 +1833,7 @@ static void __unload_reps_all_vport(struct mlx5_eswitch *esw, u8 rep_type)
        __esw_offloads_unload_rep(esw, rep, rep_type);
 }
 
-static int mlx5_esw_offloads_rep_load(struct mlx5_eswitch *esw, u16 vport_num)
+int mlx5_esw_offloads_rep_load(struct mlx5_eswitch *esw, u16 vport_num)
 {
        struct mlx5_eswitch_rep *rep;
        int rep_type;
@@ -1846,7 +1857,7 @@ err_reps:
        return err;
 }
 
-static void mlx5_esw_offloads_rep_unload(struct mlx5_eswitch *esw, u16 vport_num)
+void mlx5_esw_offloads_rep_unload(struct mlx5_eswitch *esw, u16 vport_num)
 {
        struct mlx5_eswitch_rep *rep;
        int rep_type;
@@ -2824,3 +2835,35 @@ u32 mlx5_eswitch_get_vport_metadata_for_match(struct mlx5_eswitch *esw,
        return vport->metadata << (32 - ESW_SOURCE_PORT_METADATA_BITS);
 }
 EXPORT_SYMBOL(mlx5_eswitch_get_vport_metadata_for_match);
+
+int mlx5_esw_offloads_sf_vport_enable(struct mlx5_eswitch *esw, struct devlink_port *dl_port,
+                                     u16 vport_num, u32 sfnum)
+{
+       int err;
+
+       err = mlx5_esw_vport_enable(esw, vport_num, MLX5_VPORT_UC_ADDR_CHANGE);
+       if (err)
+               return err;
+
+       err = mlx5_esw_devlink_sf_port_register(esw, dl_port, vport_num, sfnum);
+       if (err)
+               goto devlink_err;
+
+       err = mlx5_esw_offloads_rep_load(esw, vport_num);
+       if (err)
+               goto rep_err;
+       return 0;
+
+rep_err:
+       mlx5_esw_devlink_sf_port_unregister(esw, vport_num);
+devlink_err:
+       mlx5_esw_vport_disable(esw, vport_num);
+       return err;
+}
+
+void mlx5_esw_offloads_sf_vport_disable(struct mlx5_eswitch *esw, u16 vport_num)
+{
+       mlx5_esw_offloads_rep_unload(esw, vport_num);
+       mlx5_esw_devlink_sf_port_unregister(esw, vport_num);
+       mlx5_esw_vport_disable(esw, vport_num);
+}