net/mlx5: Introduce mlx5_eswitch_load/unload_sf_vport() and use it from SF code
authorJiri Pirko <jiri@nvidia.com>
Fri, 26 May 2023 13:01:47 +0000 (15:01 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 23 Aug 2023 04:34:16 +0000 (21:34 -0700)
Similar to the PF/VF helpers, introduce a set of load/unload helpers
for SF vports. From there, call mlx5_eswitch_load/unload_vport() which
are common for PFs/VFs and newly introduced SF helpers.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
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
drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c

index 60e25fb..540bebd 100644 (file)
@@ -112,9 +112,9 @@ static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw
        devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller);
 }
 
-static int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, u16 vport_num,
-                                                 struct devlink_port *dl_port,
-                                                 u32 controller, u32 sfnum)
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, u16 vport_num,
+                                          struct devlink_port *dl_port,
+                                          u32 controller, u32 sfnum)
 {
        struct mlx5_vport *vport;
 
@@ -128,7 +128,7 @@ static int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, u16
        return 0;
 }
 
-static void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, u16 vport_num)
+void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, u16 vport_num)
 {
        struct mlx5_vport *vport;
 
index 76d05e2..f772374 100644 (file)
@@ -1119,6 +1119,33 @@ static void mlx5_eswitch_unload_pf_vf_vport(struct mlx5_eswitch *esw, u16 vport_
        mlx5_esw_offloads_cleanup_pf_vf_rep(esw, vport_num);
 }
 
+int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
+                              enum mlx5_eswitch_vport_event enabled_events,
+                              struct devlink_port *dl_port, u32 controller, u32 sfnum)
+{
+       int err;
+
+       err = mlx5_esw_offloads_init_sf_rep(esw, vport_num, dl_port, controller, sfnum);
+       if (err)
+               return err;
+
+       err = mlx5_eswitch_load_vport(esw, vport_num, enabled_events);
+       if (err)
+               goto err_load;
+
+       return 0;
+
+err_load:
+       mlx5_esw_offloads_cleanup_sf_rep(esw, vport_num);
+       return err;
+}
+
+void mlx5_eswitch_unload_sf_vport(struct mlx5_eswitch *esw, u16 vport_num)
+{
+       mlx5_eswitch_unload_vport(esw, vport_num);
+       mlx5_esw_offloads_cleanup_sf_rep(esw, vport_num);
+}
+
 void mlx5_eswitch_unload_vf_vports(struct mlx5_eswitch *esw, u16 num_vfs)
 {
        struct mlx5_vport *vport;
index 8367c63..89efeff 100644 (file)
@@ -731,15 +731,32 @@ void mlx5_esw_set_spec_source_port(struct mlx5_eswitch *esw,
 
 int mlx5_esw_offloads_init_pf_vf_rep(struct mlx5_eswitch *esw, u16 vport_num);
 void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, u16 vport_num);
+
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, u16 vport_num,
+                                 struct devlink_port *dl_port,
+                                 u32 controller, u32 sfnum);
+void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, u16 vport_num);
+
 int mlx5_esw_offloads_load_rep(struct mlx5_eswitch *esw, u16 vport_num);
 void mlx5_esw_offloads_unload_rep(struct mlx5_eswitch *esw, u16 vport_num);
 
+int mlx5_eswitch_load_sf_vport(struct mlx5_eswitch *esw, u16 vport_num,
+                              enum mlx5_eswitch_vport_event enabled_events,
+                              struct devlink_port *dl_port, u32 controller, u32 sfnum);
+void mlx5_eswitch_unload_sf_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);
 
 int mlx5_esw_offloads_pf_vf_devlink_port_init(struct mlx5_eswitch *esw, u16 vport_num);
 void mlx5_esw_offloads_pf_vf_devlink_port_cleanup(struct mlx5_eswitch *esw, u16 vport_num);
+
+int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, u16 vport_num,
+                                          struct devlink_port *dl_port,
+                                          u32 controller, u32 sfnum);
+void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, u16 vport_num);
+
 int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_num);
 void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, u16 vport_num);
 struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u16 vport_num);
index 055faaf..998e56c 100644 (file)
@@ -2551,6 +2551,18 @@ void mlx5_esw_offloads_cleanup_pf_vf_rep(struct mlx5_eswitch *esw, u16 vport_num
        mlx5_esw_offloads_pf_vf_devlink_port_cleanup(esw, vport_num);
 }
 
+int mlx5_esw_offloads_init_sf_rep(struct mlx5_eswitch *esw, u16 vport_num,
+                                 struct devlink_port *dl_port,
+                                 u32 controller, u32 sfnum)
+{
+       return mlx5_esw_offloads_sf_devlink_port_init(esw, vport_num, dl_port, controller, sfnum);
+}
+
+void mlx5_esw_offloads_cleanup_sf_rep(struct mlx5_eswitch *esw, u16 vport_num)
+{
+       mlx5_esw_offloads_sf_devlink_port_cleanup(esw, vport_num);
+}
+
 int mlx5_esw_offloads_load_rep(struct mlx5_eswitch *esw, u16 vport_num)
 {
        int err;
index 6a3fa30..f7bdbeb 100644 (file)
@@ -292,8 +292,8 @@ static int mlx5_sf_add(struct mlx5_core_dev *dev, struct mlx5_sf_table *table,
        if (IS_ERR(sf))
                return PTR_ERR(sf);
 
-       err = mlx5_esw_offloads_sf_vport_enable(esw, &sf->dl_port, sf->hw_fn_id,
-                                               new_attr->controller, new_attr->sfnum);
+       err = mlx5_eswitch_load_sf_vport(esw, sf->hw_fn_id, MLX5_VPORT_UC_ADDR_CHANGE,
+                                        &sf->dl_port, new_attr->controller, new_attr->sfnum);
        if (err)
                goto esw_err;
        *dl_port = &sf->dl_port;
@@ -400,7 +400,7 @@ int mlx5_devlink_sf_port_del(struct devlink *devlink,
                goto sf_err;
        }
 
-       mlx5_esw_offloads_sf_vport_disable(esw, sf->hw_fn_id);
+       mlx5_eswitch_unload_sf_vport(esw, sf->hw_fn_id);
        mlx5_sf_id_erase(table, sf);
 
        mutex_lock(&table->sf_state_lock);
@@ -472,7 +472,7 @@ static void mlx5_sf_deactivate_all(struct mlx5_sf_table *table)
         * arrive. It is safe to destroy all user created SFs.
         */
        xa_for_each(&table->port_indices, index, sf) {
-               mlx5_esw_offloads_sf_vport_disable(esw, sf->hw_fn_id);
+               mlx5_eswitch_unload_sf_vport(esw, sf->hw_fn_id);
                mlx5_sf_id_erase(table, sf);
                mlx5_sf_dealloc(table, sf);
        }