Commit 9421c8b8 authored by Vadim Pasternak's avatar Vadim Pasternak Committed by Jakub Kicinski

mlxsw: minimal: Move ports allocation to separate routine

Perform ports allocation in a separate routine.
Motivation is to re-use this routine for ports found on line cards.
Signed-off-by: default avatarVadim Pasternak <vadimp@nvidia.com>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c7ea08ba
...@@ -335,12 +335,10 @@ mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module) ...@@ -335,12 +335,10 @@ mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module)
mlxsw_env_module_port_unmap(mlxsw_m->core, slot_index, module); mlxsw_env_module_port_unmap(mlxsw_m->core, slot_index, module);
} }
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) static int mlxsw_m_linecards_init(struct mlxsw_m *mlxsw_m)
{ {
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
u8 last_module = max_ports; int i, err;
int i;
int err;
mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports), mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports),
GFP_KERNEL); GFP_KERNEL);
...@@ -358,6 +356,26 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) ...@@ -358,6 +356,26 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
for (i = 0; i < max_ports; i++) for (i = 0; i < max_ports; i++)
mlxsw_m->module_to_port[i] = -1; mlxsw_m->module_to_port[i] = -1;
return 0;
err_module_to_port_alloc:
kfree(mlxsw_m->ports);
return err;
}
static void mlxsw_m_linecards_fini(struct mlxsw_m *mlxsw_m)
{
kfree(mlxsw_m->module_to_port);
kfree(mlxsw_m->ports);
}
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
{
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
u8 last_module = max_ports;
int i;
int err;
/* Fill out module to local port mapping array */ /* Fill out module to local port mapping array */
for (i = 1; i < max_ports; i++) { for (i = 1; i < max_ports; i++) {
err = mlxsw_m_port_module_map(mlxsw_m, i, &last_module); err = mlxsw_m_port_module_map(mlxsw_m, i, &last_module);
...@@ -388,9 +406,6 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) ...@@ -388,9 +406,6 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
err_module_to_port_map: err_module_to_port_map:
for (i--; i > 0; i--) for (i--; i > 0; i--)
mlxsw_m_port_module_unmap(mlxsw_m, 0, i); mlxsw_m_port_module_unmap(mlxsw_m, 0, i);
kfree(mlxsw_m->module_to_port);
err_module_to_port_alloc:
kfree(mlxsw_m->ports);
return err; return err;
} }
...@@ -448,13 +463,23 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, ...@@ -448,13 +463,23 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
return err; return err;
} }
err = mlxsw_m_linecards_init(mlxsw_m);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create line cards\n");
return err;
}
err = mlxsw_m_ports_create(mlxsw_m); err = mlxsw_m_ports_create(mlxsw_m);
if (err) { if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n"); dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n");
return err; goto err_ports_create;
} }
return 0; return 0;
err_ports_create:
mlxsw_m_linecards_fini(mlxsw_m);
return err;
} }
static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core) static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
...@@ -462,6 +487,7 @@ static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core) ...@@ -462,6 +487,7 @@ static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
mlxsw_m_ports_remove(mlxsw_m); mlxsw_m_ports_remove(mlxsw_m);
mlxsw_m_linecards_fini(mlxsw_m);
} }
static const struct mlxsw_config_profile mlxsw_m_config_profile; static const struct mlxsw_config_profile mlxsw_m_config_profile;
......
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