mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-03 17:40:04 +00:00
mlxsw: spectrum_trap: Allow for per-ASIC traps initialization
Subsequent patches will need to register different traps for Spectrum-1 and Spectrum-2 onwards. Enable that by invoking a per-ASIC operation during traps initialization. Reviewed-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Petr Machata <petrm@mellanox.com> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
36d1fd687d
commit
869c7be940
2 changed files with 75 additions and 9 deletions
|
@ -1247,6 +1247,43 @@ mlxsw_sp_trap_listener_is_valid(const struct mlxsw_listener *listener)
|
||||||
return listener->trap_id != 0;
|
return listener->trap_id != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mlxsw_sp_trap_items_arr_init(struct mlxsw_sp *mlxsw_sp)
|
||||||
|
{
|
||||||
|
size_t common_traps_count = ARRAY_SIZE(mlxsw_sp_trap_items_arr);
|
||||||
|
const struct mlxsw_sp_trap_item *spec_trap_items_arr;
|
||||||
|
size_t elem_size = sizeof(struct mlxsw_sp_trap_item);
|
||||||
|
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
|
||||||
|
size_t traps_count, spec_traps_count;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = mlxsw_sp->trap_ops->traps_init(mlxsw_sp, &spec_trap_items_arr,
|
||||||
|
&spec_traps_count);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
/* The trap items array is created by concatenating the common trap
|
||||||
|
* items and the ASIC-specific trap items.
|
||||||
|
*/
|
||||||
|
traps_count = common_traps_count + spec_traps_count;
|
||||||
|
trap->trap_items_arr = kcalloc(traps_count, elem_size, GFP_KERNEL);
|
||||||
|
if (!trap->trap_items_arr)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
memcpy(trap->trap_items_arr, mlxsw_sp_trap_items_arr,
|
||||||
|
elem_size * common_traps_count);
|
||||||
|
memcpy(trap->trap_items_arr + common_traps_count,
|
||||||
|
spec_trap_items_arr, elem_size * spec_traps_count);
|
||||||
|
|
||||||
|
trap->traps_count = traps_count;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mlxsw_sp_trap_items_arr_fini(struct mlxsw_sp *mlxsw_sp)
|
||||||
|
{
|
||||||
|
kfree(mlxsw_sp->trap->trap_items_arr);
|
||||||
|
}
|
||||||
|
|
||||||
static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
|
static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
|
||||||
{
|
{
|
||||||
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
|
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
|
||||||
|
@ -1254,13 +1291,9 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
|
||||||
const struct mlxsw_sp_trap_item *trap_item;
|
const struct mlxsw_sp_trap_item *trap_item;
|
||||||
int err, i;
|
int err, i;
|
||||||
|
|
||||||
trap->trap_items_arr = kmemdup(mlxsw_sp_trap_items_arr,
|
err = mlxsw_sp_trap_items_arr_init(mlxsw_sp);
|
||||||
sizeof(mlxsw_sp_trap_items_arr),
|
if (err)
|
||||||
GFP_KERNEL);
|
return err;
|
||||||
if (!trap->trap_items_arr)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
trap->traps_count = ARRAY_SIZE(mlxsw_sp_trap_items_arr);
|
|
||||||
|
|
||||||
for (i = 0; i < trap->traps_count; i++) {
|
for (i = 0; i < trap->traps_count; i++) {
|
||||||
trap_item = &trap->trap_items_arr[i];
|
trap_item = &trap->trap_items_arr[i];
|
||||||
|
@ -1277,7 +1310,7 @@ static int mlxsw_sp_traps_init(struct mlxsw_sp *mlxsw_sp)
|
||||||
trap_item = &trap->trap_items_arr[i];
|
trap_item = &trap->trap_items_arr[i];
|
||||||
devlink_traps_unregister(devlink, &trap_item->trap, 1);
|
devlink_traps_unregister(devlink, &trap_item->trap, 1);
|
||||||
}
|
}
|
||||||
kfree(trap->trap_items_arr);
|
mlxsw_sp_trap_items_arr_fini(mlxsw_sp);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1293,7 +1326,7 @@ static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp)
|
||||||
trap_item = &trap->trap_items_arr[i];
|
trap_item = &trap->trap_items_arr[i];
|
||||||
devlink_traps_unregister(devlink, &trap_item->trap, 1);
|
devlink_traps_unregister(devlink, &trap_item->trap, 1);
|
||||||
}
|
}
|
||||||
kfree(trap->trap_items_arr);
|
mlxsw_sp_trap_items_arr_fini(mlxsw_sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp)
|
int mlxsw_sp_devlink_traps_init(struct mlxsw_sp *mlxsw_sp)
|
||||||
|
@ -1617,6 +1650,10 @@ static const struct mlxsw_sp_trap_group_item
|
||||||
mlxsw_sp1_trap_group_items_arr[] = {
|
mlxsw_sp1_trap_group_items_arr[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct mlxsw_sp_trap_item
|
||||||
|
mlxsw_sp1_trap_items_arr[] = {
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mlxsw_sp1_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
mlxsw_sp1_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
const struct mlxsw_sp_trap_group_item **arr,
|
const struct mlxsw_sp_trap_group_item **arr,
|
||||||
|
@ -1628,14 +1665,29 @@ mlxsw_sp1_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mlxsw_sp1_traps_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
|
const struct mlxsw_sp_trap_item **arr,
|
||||||
|
size_t *p_traps_count)
|
||||||
|
{
|
||||||
|
*arr = mlxsw_sp1_trap_items_arr;
|
||||||
|
*p_traps_count = ARRAY_SIZE(mlxsw_sp1_trap_items_arr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops = {
|
const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops = {
|
||||||
.groups_init = mlxsw_sp1_trap_groups_init,
|
.groups_init = mlxsw_sp1_trap_groups_init,
|
||||||
|
.traps_init = mlxsw_sp1_traps_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct mlxsw_sp_trap_group_item
|
static const struct mlxsw_sp_trap_group_item
|
||||||
mlxsw_sp2_trap_group_items_arr[] = {
|
mlxsw_sp2_trap_group_items_arr[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct mlxsw_sp_trap_item
|
||||||
|
mlxsw_sp2_trap_items_arr[] = {
|
||||||
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mlxsw_sp2_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
mlxsw_sp2_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
const struct mlxsw_sp_trap_group_item **arr,
|
const struct mlxsw_sp_trap_group_item **arr,
|
||||||
|
@ -1647,6 +1699,17 @@ mlxsw_sp2_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mlxsw_sp2_traps_init(struct mlxsw_sp *mlxsw_sp,
|
||||||
|
const struct mlxsw_sp_trap_item **arr,
|
||||||
|
size_t *p_traps_count)
|
||||||
|
{
|
||||||
|
*arr = mlxsw_sp2_trap_items_arr;
|
||||||
|
*p_traps_count = ARRAY_SIZE(mlxsw_sp2_trap_items_arr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const struct mlxsw_sp_trap_ops mlxsw_sp2_trap_ops = {
|
const struct mlxsw_sp_trap_ops mlxsw_sp2_trap_ops = {
|
||||||
.groups_init = mlxsw_sp2_trap_groups_init,
|
.groups_init = mlxsw_sp2_trap_groups_init,
|
||||||
|
.traps_init = mlxsw_sp2_traps_init,
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,9 @@ struct mlxsw_sp_trap_ops {
|
||||||
int (*groups_init)(struct mlxsw_sp *mlxsw_sp,
|
int (*groups_init)(struct mlxsw_sp *mlxsw_sp,
|
||||||
const struct mlxsw_sp_trap_group_item **arr,
|
const struct mlxsw_sp_trap_group_item **arr,
|
||||||
size_t *p_groups_count);
|
size_t *p_groups_count);
|
||||||
|
int (*traps_init)(struct mlxsw_sp *mlxsw_sp,
|
||||||
|
const struct mlxsw_sp_trap_item **arr,
|
||||||
|
size_t *p_traps_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops;
|
extern const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops;
|
||||||
|
|
Loading…
Reference in a new issue