Commit 981f1d18 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

mlxsw: core: Move functions to register/unregister array of traps to core.c

These functions belong to core.c alongside the functions that
register/unregister a single trap. Move it there. Make the functions
possibly usable by other parts of mlxsw code.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8ae89cf4
...@@ -2564,6 +2564,45 @@ void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core, ...@@ -2564,6 +2564,45 @@ void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
} }
EXPORT_SYMBOL(mlxsw_core_trap_unregister); EXPORT_SYMBOL(mlxsw_core_trap_unregister);
int mlxsw_core_traps_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listeners,
size_t listeners_count, void *priv)
{
int i, err;
for (i = 0; i < listeners_count; i++) {
err = mlxsw_core_trap_register(mlxsw_core,
&listeners[i],
priv);
if (err)
goto err_listener_register;
}
return 0;
err_listener_register:
for (i--; i >= 0; i--) {
mlxsw_core_trap_unregister(mlxsw_core,
&listeners[i],
priv);
}
return err;
}
EXPORT_SYMBOL(mlxsw_core_traps_register);
void mlxsw_core_traps_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listeners,
size_t listeners_count, void *priv)
{
int i;
for (i = 0; i < listeners_count; i++) {
mlxsw_core_trap_unregister(mlxsw_core,
&listeners[i],
priv);
}
}
EXPORT_SYMBOL(mlxsw_core_traps_unregister);
int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core, int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener, const struct mlxsw_listener *listener,
bool enabled) bool enabled)
......
...@@ -181,6 +181,12 @@ int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core, ...@@ -181,6 +181,12 @@ int mlxsw_core_trap_register(struct mlxsw_core *mlxsw_core,
void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core, void mlxsw_core_trap_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener, const struct mlxsw_listener *listener,
void *priv); void *priv);
int mlxsw_core_traps_register(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listeners,
size_t listeners_count, void *priv);
void mlxsw_core_traps_unregister(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listeners,
size_t listeners_count, void *priv);
int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core, int mlxsw_core_trap_state_set(struct mlxsw_core *mlxsw_core,
const struct mlxsw_listener *listener, const struct mlxsw_listener *listener,
bool enabled); bool enabled);
......
...@@ -2393,45 +2393,6 @@ static int mlxsw_sp_trap_groups_set(struct mlxsw_core *mlxsw_core) ...@@ -2393,45 +2393,6 @@ static int mlxsw_sp_trap_groups_set(struct mlxsw_core *mlxsw_core)
return 0; return 0;
} }
static int mlxsw_sp_traps_register(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_listener listeners[],
size_t listeners_count)
{
int i;
int err;
for (i = 0; i < listeners_count; i++) {
err = mlxsw_core_trap_register(mlxsw_sp->core,
&listeners[i],
mlxsw_sp);
if (err)
goto err_listener_register;
}
return 0;
err_listener_register:
for (i--; i >= 0; i--) {
mlxsw_core_trap_unregister(mlxsw_sp->core,
&listeners[i],
mlxsw_sp);
}
return err;
}
static void mlxsw_sp_traps_unregister(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_listener listeners[],
size_t listeners_count)
{
int i;
for (i = 0; i < listeners_count; i++) {
mlxsw_core_trap_unregister(mlxsw_sp->core,
&listeners[i],
mlxsw_sp);
}
}
static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
{ {
struct mlxsw_sp_trap *trap; struct mlxsw_sp_trap *trap;
...@@ -2456,21 +2417,23 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp) ...@@ -2456,21 +2417,23 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
if (err) if (err)
goto err_trap_groups_set; goto err_trap_groups_set;
err = mlxsw_sp_traps_register(mlxsw_sp, mlxsw_sp_listener, err = mlxsw_core_traps_register(mlxsw_sp->core, mlxsw_sp_listener,
ARRAY_SIZE(mlxsw_sp_listener)); ARRAY_SIZE(mlxsw_sp_listener),
mlxsw_sp);
if (err) if (err)
goto err_traps_register; goto err_traps_register;
err = mlxsw_sp_traps_register(mlxsw_sp, mlxsw_sp->listeners, err = mlxsw_core_traps_register(mlxsw_sp->core, mlxsw_sp->listeners,
mlxsw_sp->listeners_count); mlxsw_sp->listeners_count, mlxsw_sp);
if (err) if (err)
goto err_extra_traps_init; goto err_extra_traps_init;
return 0; return 0;
err_extra_traps_init: err_extra_traps_init:
mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp_listener, mlxsw_core_traps_unregister(mlxsw_sp->core, mlxsw_sp_listener,
ARRAY_SIZE(mlxsw_sp_listener)); ARRAY_SIZE(mlxsw_sp_listener),
mlxsw_sp);
err_traps_register: err_traps_register:
err_trap_groups_set: err_trap_groups_set:
err_cpu_policers_set: err_cpu_policers_set:
...@@ -2480,10 +2443,11 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp) ...@@ -2480,10 +2443,11 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp) static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp)
{ {
mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp->listeners, mlxsw_core_traps_unregister(mlxsw_sp->core, mlxsw_sp->listeners,
mlxsw_sp->listeners_count); mlxsw_sp->listeners_count,
mlxsw_sp_traps_unregister(mlxsw_sp, mlxsw_sp_listener, mlxsw_sp);
ARRAY_SIZE(mlxsw_sp_listener)); mlxsw_core_traps_unregister(mlxsw_sp->core, mlxsw_sp_listener,
ARRAY_SIZE(mlxsw_sp_listener), mlxsw_sp);
kfree(mlxsw_sp->trap); kfree(mlxsw_sp->trap);
} }
......
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