mlxsw: Narrow the critical section of devl_lock during ports creation/removal
No need to hold the lock for alloc and freecpu. So narrow the critical section. Follow-up patch is going to benefit from this by adding more code to the functions which will be out of the critical as well. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ebf0c53417
commit
adc6462376
@ -328,6 +328,7 @@ static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module)
|
||||
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
|
||||
{
|
||||
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_m->core);
|
||||
u8 last_module = max_ports;
|
||||
int i;
|
||||
int err;
|
||||
@ -356,6 +357,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
|
||||
}
|
||||
|
||||
/* Create port objects for each valid entry */
|
||||
devl_lock(devlink);
|
||||
for (i = 0; i < mlxsw_m->max_ports; i++) {
|
||||
if (mlxsw_m->module_to_port[i] > 0 &&
|
||||
!mlxsw_core_port_is_xm(mlxsw_m->core, i)) {
|
||||
@ -366,6 +368,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
|
||||
goto err_module_to_port_create;
|
||||
}
|
||||
}
|
||||
devl_unlock(devlink);
|
||||
|
||||
return 0;
|
||||
|
||||
@ -375,6 +378,7 @@ err_module_to_port_create:
|
||||
mlxsw_m_port_remove(mlxsw_m,
|
||||
mlxsw_m->module_to_port[i]);
|
||||
}
|
||||
devl_unlock(devlink);
|
||||
i = max_ports;
|
||||
err_module_to_port_map:
|
||||
for (i--; i > 0; i--)
|
||||
@ -387,8 +391,10 @@ err_module_to_port_alloc:
|
||||
|
||||
static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
|
||||
{
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_m->core);
|
||||
int i;
|
||||
|
||||
devl_lock(devlink);
|
||||
for (i = 0; i < mlxsw_m->max_ports; i++) {
|
||||
if (mlxsw_m->module_to_port[i] > 0) {
|
||||
mlxsw_m_port_remove(mlxsw_m,
|
||||
@ -396,6 +402,7 @@ static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
|
||||
mlxsw_m_port_module_unmap(mlxsw_m, i);
|
||||
}
|
||||
}
|
||||
devl_unlock(devlink);
|
||||
|
||||
kfree(mlxsw_m->module_to_port);
|
||||
kfree(mlxsw_m->ports);
|
||||
@ -424,7 +431,6 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
int err;
|
||||
|
||||
mlxsw_m->core = mlxsw_core;
|
||||
@ -440,9 +446,7 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
|
||||
return err;
|
||||
}
|
||||
|
||||
devl_lock(devlink);
|
||||
err = mlxsw_m_ports_create(mlxsw_m);
|
||||
devl_unlock(devlink);
|
||||
if (err) {
|
||||
dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n");
|
||||
return err;
|
||||
@ -454,11 +458,8 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
|
||||
static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core)
|
||||
{
|
||||
struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
|
||||
devl_lock(devlink);
|
||||
mlxsw_m_ports_remove(mlxsw_m);
|
||||
devl_unlock(devlink);
|
||||
}
|
||||
|
||||
static const struct mlxsw_config_profile mlxsw_m_config_profile;
|
||||
|
@ -1863,12 +1863,15 @@ static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u16 local_port)
|
||||
|
||||
static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
|
||||
{
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
|
||||
int i;
|
||||
|
||||
devl_lock(devlink);
|
||||
for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++)
|
||||
if (mlxsw_sp_port_created(mlxsw_sp, i))
|
||||
mlxsw_sp_port_remove(mlxsw_sp, i);
|
||||
mlxsw_sp_cpu_port_remove(mlxsw_sp);
|
||||
devl_unlock(devlink);
|
||||
kfree(mlxsw_sp->ports);
|
||||
mlxsw_sp->ports = NULL;
|
||||
}
|
||||
@ -1876,6 +1879,7 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp)
|
||||
static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
|
||||
{
|
||||
unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
|
||||
struct mlxsw_sp_port_mapping *port_mapping;
|
||||
size_t alloc_size;
|
||||
int i;
|
||||
@ -1886,6 +1890,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
|
||||
if (!mlxsw_sp->ports)
|
||||
return -ENOMEM;
|
||||
|
||||
devl_lock(devlink);
|
||||
err = mlxsw_sp_cpu_port_create(mlxsw_sp);
|
||||
if (err)
|
||||
goto err_cpu_port_create;
|
||||
@ -1898,6 +1903,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp)
|
||||
if (err)
|
||||
goto err_port_create;
|
||||
}
|
||||
devl_unlock(devlink);
|
||||
return 0;
|
||||
|
||||
err_port_create:
|
||||
@ -1906,6 +1912,7 @@ err_port_create:
|
||||
mlxsw_sp_port_remove(mlxsw_sp, i);
|
||||
mlxsw_sp_cpu_port_remove(mlxsw_sp);
|
||||
err_cpu_port_create:
|
||||
devl_unlock(devlink);
|
||||
kfree(mlxsw_sp->ports);
|
||||
mlxsw_sp->ports = NULL;
|
||||
return err;
|
||||
@ -2805,7 +2812,6 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
int err;
|
||||
|
||||
mlxsw_sp->core = mlxsw_core;
|
||||
@ -2966,9 +2972,7 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
|
||||
goto err_sample_trigger_init;
|
||||
}
|
||||
|
||||
devl_lock(devlink);
|
||||
err = mlxsw_sp_ports_create(mlxsw_sp);
|
||||
devl_unlock(devlink);
|
||||
if (err) {
|
||||
dev_err(mlxsw_sp->bus_info->dev, "Failed to create ports\n");
|
||||
goto err_ports_create;
|
||||
@ -3149,12 +3153,8 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core,
|
||||
static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core)
|
||||
{
|
||||
struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
|
||||
devl_lock(devlink);
|
||||
mlxsw_sp_ports_remove(mlxsw_sp);
|
||||
devl_unlock(devlink);
|
||||
|
||||
rhashtable_destroy(&mlxsw_sp->sample_trigger_ht);
|
||||
mlxsw_sp_port_module_info_fini(mlxsw_sp);
|
||||
mlxsw_sp_dpipe_fini(mlxsw_sp);
|
||||
|
Loading…
Reference in New Issue
Block a user