Skip to content

Commit 9421c8b

Browse files
vadimp-nvidiakuba-moo
authored andcommitted
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: Vadim Pasternak <vadimp@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c7ea08b commit 9421c8b

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

drivers/net/ethernet/mellanox/mlxsw/minimal.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,10 @@ mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module)
335335
mlxsw_env_module_port_unmap(mlxsw_m->core, slot_index, module);
336336
}
337337

338-
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
338+
static int mlxsw_m_linecards_init(struct mlxsw_m *mlxsw_m)
339339
{
340340
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
341-
u8 last_module = max_ports;
342-
int i;
343-
int err;
341+
int i, err;
344342

345343
mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports),
346344
GFP_KERNEL);
@@ -358,6 +356,26 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
358356
for (i = 0; i < max_ports; i++)
359357
mlxsw_m->module_to_port[i] = -1;
360358

359+
return 0;
360+
361+
err_module_to_port_alloc:
362+
kfree(mlxsw_m->ports);
363+
return err;
364+
}
365+
366+
static void mlxsw_m_linecards_fini(struct mlxsw_m *mlxsw_m)
367+
{
368+
kfree(mlxsw_m->module_to_port);
369+
kfree(mlxsw_m->ports);
370+
}
371+
372+
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
373+
{
374+
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
375+
u8 last_module = max_ports;
376+
int i;
377+
int err;
378+
361379
/* Fill out module to local port mapping array */
362380
for (i = 1; i < max_ports; i++) {
363381
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)
388406
err_module_to_port_map:
389407
for (i--; i > 0; i--)
390408
mlxsw_m_port_module_unmap(mlxsw_m, 0, i);
391-
kfree(mlxsw_m->module_to_port);
392-
err_module_to_port_alloc:
393-
kfree(mlxsw_m->ports);
394409
return err;
395410
}
396411

@@ -448,20 +463,31 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
448463
return err;
449464
}
450465

466+
err = mlxsw_m_linecards_init(mlxsw_m);
467+
if (err) {
468+
dev_err(mlxsw_m->bus_info->dev, "Failed to create line cards\n");
469+
return err;
470+
}
471+
451472
err = mlxsw_m_ports_create(mlxsw_m);
452473
if (err) {
453474
dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n");
454-
return err;
475+
goto err_ports_create;
455476
}
456477

457478
return 0;
479+
480+
err_ports_create:
481+
mlxsw_m_linecards_fini(mlxsw_m);
482+
return err;
458483
}
459484

460485
static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
461486
{
462487
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
463488

464489
mlxsw_m_ports_remove(mlxsw_m);
490+
mlxsw_m_linecards_fini(mlxsw_m);
465491
}
466492

467493
static const struct mlxsw_config_profile mlxsw_m_config_profile;

0 commit comments

Comments
 (0)