mlxsw: spectrum_trap: Allow for per-ASIC trap groups initialization

Subsequent patches will need to register different trap groups for
Spectrum-1 and Spectrum-2 onwards.

Enable that by invoking a per-ASIC operation during trap groups
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:
Ido Schimmel 2020-08-03 19:11:37 +03:00 committed by David S. Miller
parent 928345c08b
commit 36d1fd687d
4 changed files with 93 additions and 9 deletions

View File

@ -3055,6 +3055,7 @@ static int mlxsw_sp1_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->ptp_ops = &mlxsw_sp1_ptp_ops;
mlxsw_sp->span_ops = &mlxsw_sp1_span_ops;
mlxsw_sp->policer_core_ops = &mlxsw_sp1_policer_core_ops;
mlxsw_sp->trap_ops = &mlxsw_sp1_trap_ops;
mlxsw_sp->listeners = mlxsw_sp1_listener;
mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp1_listener);
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP1;
@ -3084,6 +3085,7 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
mlxsw_sp->span_ops = &mlxsw_sp2_span_ops;
mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2;
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);
@ -3111,6 +3113,7 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core,
mlxsw_sp->ptp_ops = &mlxsw_sp2_ptp_ops;
mlxsw_sp->span_ops = &mlxsw_sp3_span_ops;
mlxsw_sp->policer_core_ops = &mlxsw_sp2_policer_core_ops;
mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops;
mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3;
return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack);

View File

@ -177,6 +177,7 @@ struct mlxsw_sp {
const struct mlxsw_sp_ptp_ops *ptp_ops;
const struct mlxsw_sp_span_ops *span_ops;
const struct mlxsw_sp_policer_core_ops *policer_core_ops;
const struct mlxsw_sp_trap_ops *trap_ops;
const struct mlxsw_listener *listeners;
size_t listeners_count;
u32 lowest_shaper_bs;

View File

@ -1159,6 +1159,43 @@ static void mlxsw_sp_trap_policers_fini(struct mlxsw_sp *mlxsw_sp)
mlxsw_sp_trap_policer_items_arr_fini(mlxsw_sp);
}
static int mlxsw_sp_trap_group_items_arr_init(struct mlxsw_sp *mlxsw_sp)
{
size_t common_groups_count = ARRAY_SIZE(mlxsw_sp_trap_group_items_arr);
const struct mlxsw_sp_trap_group_item *spec_group_items_arr;
size_t elem_size = sizeof(struct mlxsw_sp_trap_group_item);
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
size_t groups_count, spec_groups_count;
int err;
err = mlxsw_sp->trap_ops->groups_init(mlxsw_sp, &spec_group_items_arr,
&spec_groups_count);
if (err)
return err;
/* The group items array is created by concatenating the common trap
* group items and the ASIC-specific trap group items.
*/
groups_count = common_groups_count + spec_groups_count;
trap->group_items_arr = kcalloc(groups_count, elem_size, GFP_KERNEL);
if (!trap->group_items_arr)
return -ENOMEM;
memcpy(trap->group_items_arr, mlxsw_sp_trap_group_items_arr,
elem_size * common_groups_count);
memcpy(trap->group_items_arr + common_groups_count,
spec_group_items_arr, elem_size * spec_groups_count);
trap->groups_count = groups_count;
return 0;
}
static void mlxsw_sp_trap_group_items_arr_fini(struct mlxsw_sp *mlxsw_sp)
{
kfree(mlxsw_sp->trap->group_items_arr);
}
static int mlxsw_sp_trap_groups_init(struct mlxsw_sp *mlxsw_sp)
{
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
@ -1166,13 +1203,9 @@ static int mlxsw_sp_trap_groups_init(struct mlxsw_sp *mlxsw_sp)
struct mlxsw_sp_trap *trap = mlxsw_sp->trap;
int err, i;
trap->group_items_arr = kmemdup(mlxsw_sp_trap_group_items_arr,
sizeof(mlxsw_sp_trap_group_items_arr),
GFP_KERNEL);
if (!trap->group_items_arr)
return -ENOMEM;
trap->groups_count = ARRAY_SIZE(mlxsw_sp_trap_group_items_arr);
err = mlxsw_sp_trap_group_items_arr_init(mlxsw_sp);
if (err)
return err;
for (i = 0; i < trap->groups_count; i++) {
group_item = &trap->group_items_arr[i];
@ -1189,7 +1222,7 @@ static int mlxsw_sp_trap_groups_init(struct mlxsw_sp *mlxsw_sp)
group_item = &trap->group_items_arr[i];
devlink_trap_groups_unregister(devlink, &group_item->group, 1);
}
kfree(trap->group_items_arr);
mlxsw_sp_trap_group_items_arr_fini(mlxsw_sp);
return err;
}
@ -1205,7 +1238,7 @@ static void mlxsw_sp_trap_groups_fini(struct mlxsw_sp *mlxsw_sp)
group_item = &trap->group_items_arr[i];
devlink_trap_groups_unregister(devlink, &group_item->group, 1);
}
kfree(trap->group_items_arr);
mlxsw_sp_trap_group_items_arr_fini(mlxsw_sp);
}
static bool
@ -1579,3 +1612,41 @@ mlxsw_sp_trap_policer_counter_get(struct mlxsw_core *mlxsw_core,
return 0;
}
static const struct mlxsw_sp_trap_group_item
mlxsw_sp1_trap_group_items_arr[] = {
};
static int
mlxsw_sp1_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_trap_group_item **arr,
size_t *p_groups_count)
{
*arr = mlxsw_sp1_trap_group_items_arr;
*p_groups_count = ARRAY_SIZE(mlxsw_sp1_trap_group_items_arr);
return 0;
}
const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops = {
.groups_init = mlxsw_sp1_trap_groups_init,
};
static const struct mlxsw_sp_trap_group_item
mlxsw_sp2_trap_group_items_arr[] = {
};
static int
mlxsw_sp2_trap_groups_init(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_trap_group_item **arr,
size_t *p_groups_count)
{
*arr = mlxsw_sp2_trap_group_items_arr;
*p_groups_count = ARRAY_SIZE(mlxsw_sp2_trap_group_items_arr);
return 0;
}
const struct mlxsw_sp_trap_ops mlxsw_sp2_trap_ops = {
.groups_init = mlxsw_sp2_trap_groups_init,
};

View File

@ -23,4 +23,13 @@ struct mlxsw_sp_trap {
unsigned long policers_usage[]; /* Usage bitmap */
};
struct mlxsw_sp_trap_ops {
int (*groups_init)(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_trap_group_item **arr,
size_t *p_groups_count);
};
extern const struct mlxsw_sp_trap_ops mlxsw_sp1_trap_ops;
extern const struct mlxsw_sp_trap_ops mlxsw_sp2_trap_ops;
#endif