Commit 6ed1803a authored by Mark Bloch's avatar Mark Bloch Committed by Saeed Mahameed

net/mlx5: E-Switch, Refactor load/unload of representors

Refactor the load/unload stages for better code reuse.
Signed-off-by: default avatarMark Bloch <markb@mellanox.com>
Reviewed-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent e8d31c4d
...@@ -767,12 +767,47 @@ int esw_offloads_init_reps(struct mlx5_eswitch *esw) ...@@ -767,12 +767,47 @@ int esw_offloads_init_reps(struct mlx5_eswitch *esw)
return 0; return 0;
} }
int esw_offloads_init(struct mlx5_eswitch *esw, int nvports) static void esw_offloads_unload_reps(struct mlx5_eswitch *esw, int nvports)
{
struct mlx5_eswitch_rep *rep;
int vport;
for (vport = nvports - 1; vport >= 0; vport--) {
rep = &esw->offloads.vport_reps[vport];
if (!rep->valid)
continue;
rep->unload(esw, rep);
}
}
static int esw_offloads_load_reps(struct mlx5_eswitch *esw, int nvports)
{ {
struct mlx5_eswitch_rep *rep; struct mlx5_eswitch_rep *rep;
int vport; int vport;
int err; int err;
for (vport = 0; vport < nvports; vport++) {
rep = &esw->offloads.vport_reps[vport];
if (!rep->valid)
continue;
err = rep->load(esw, rep);
if (err)
goto err_reps;
}
return 0;
err_reps:
esw_offloads_unload_reps(esw, vport);
return err;
}
int esw_offloads_init(struct mlx5_eswitch *esw, int nvports)
{
int err;
/* disable PF RoCE so missed packets don't go through RoCE steering */ /* disable PF RoCE so missed packets don't go through RoCE steering */
mlx5_dev_list_lock(); mlx5_dev_list_lock();
mlx5_remove_dev_by_protocol(esw->dev, MLX5_INTERFACE_PROTOCOL_IB); mlx5_remove_dev_by_protocol(esw->dev, MLX5_INTERFACE_PROTOCOL_IB);
...@@ -790,25 +825,13 @@ int esw_offloads_init(struct mlx5_eswitch *esw, int nvports) ...@@ -790,25 +825,13 @@ int esw_offloads_init(struct mlx5_eswitch *esw, int nvports)
if (err) if (err)
goto create_fg_err; goto create_fg_err;
for (vport = 0; vport < nvports; vport++) { err = esw_offloads_load_reps(esw, nvports);
rep = &esw->offloads.vport_reps[vport];
if (!rep->valid)
continue;
err = rep->load(esw, rep);
if (err) if (err)
goto err_reps; goto err_reps;
}
return 0; return 0;
err_reps: err_reps:
for (vport--; vport >= 0; vport--) {
rep = &esw->offloads.vport_reps[vport];
if (!rep->valid)
continue;
rep->unload(esw, rep);
}
esw_destroy_vport_rx_group(esw); esw_destroy_vport_rx_group(esw);
create_fg_err: create_fg_err:
...@@ -849,16 +872,7 @@ static int esw_offloads_stop(struct mlx5_eswitch *esw) ...@@ -849,16 +872,7 @@ static int esw_offloads_stop(struct mlx5_eswitch *esw)
void esw_offloads_cleanup(struct mlx5_eswitch *esw, int nvports) void esw_offloads_cleanup(struct mlx5_eswitch *esw, int nvports)
{ {
struct mlx5_eswitch_rep *rep; esw_offloads_unload_reps(esw, nvports);
int vport;
for (vport = nvports - 1; vport >= 0; vport--) {
rep = &esw->offloads.vport_reps[vport];
if (!rep->valid)
continue;
rep->unload(esw, rep);
}
esw_destroy_vport_rx_group(esw); esw_destroy_vport_rx_group(esw);
esw_destroy_offloads_table(esw); esw_destroy_offloads_table(esw);
esw_destroy_offloads_fdb_tables(esw); esw_destroy_offloads_fdb_tables(esw);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment