Skip to content

Commit 03490a8

Browse files
idoschdavem330
authored andcommitted
mlxsw: spectrum_router: Enable resilient nexthop groups to be programmed
Now that mlxsw supports resilient nexthop groups, allow them to be programmed after validating that their configuration conforms to the device's limitations (e.g., number of buckets is within predefined range). Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent debd2b3 commit 03490a8

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

‎drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4519,11 +4519,86 @@ mlxsw_sp_nexthop_obj_group_validate(struct mlxsw_sp *mlxsw_sp,
45194519
return 0;
45204520
}
45214521

4522+
static int
4523+
mlxsw_sp_nexthop_obj_res_group_size_validate(struct mlxsw_sp *mlxsw_sp,
4524+
const struct nh_notifier_res_table_info *nh_res_table,
4525+
struct netlink_ext_ack *extack)
4526+
{
4527+
unsigned int alloc_size;
4528+
bool valid_size = false;
4529+
int err, i;
4530+
4531+
if (nh_res_table->num_nh_buckets < 32) {
4532+
NL_SET_ERR_MSG_MOD(extack, "Minimum number of buckets is 32");
4533+
return -EINVAL;
4534+
}
4535+
4536+
for (i = 0; i < mlxsw_sp->router->adj_grp_size_ranges_count; i++) {
4537+
const struct mlxsw_sp_adj_grp_size_range *size_range;
4538+
4539+
size_range = &mlxsw_sp->router->adj_grp_size_ranges[i];
4540+
4541+
if (nh_res_table->num_nh_buckets >= size_range->start &&
4542+
nh_res_table->num_nh_buckets <= size_range->end) {
4543+
valid_size = true;
4544+
break;
4545+
}
4546+
}
4547+
4548+
if (!valid_size) {
4549+
NL_SET_ERR_MSG_MOD(extack, "Invalid number of buckets");
4550+
return -EINVAL;
4551+
}
4552+
4553+
err = mlxsw_sp_kvdl_alloc_count_query(mlxsw_sp,
4554+
MLXSW_SP_KVDL_ENTRY_TYPE_ADJ,
4555+
nh_res_table->num_nh_buckets,
4556+
&alloc_size);
4557+
if (err || nh_res_table->num_nh_buckets != alloc_size) {
4558+
NL_SET_ERR_MSG_MOD(extack, "Number of buckets does not fit allocation size of any KVDL partition");
4559+
return -EINVAL;
4560+
}
4561+
4562+
return 0;
4563+
}
4564+
4565+
static int
4566+
mlxsw_sp_nexthop_obj_res_group_validate(struct mlxsw_sp *mlxsw_sp,
4567+
const struct nh_notifier_res_table_info *nh_res_table,
4568+
struct netlink_ext_ack *extack)
4569+
{
4570+
int err;
4571+
u16 i;
4572+
4573+
err = mlxsw_sp_nexthop_obj_res_group_size_validate(mlxsw_sp,
4574+
nh_res_table,
4575+
extack);
4576+
if (err)
4577+
return err;
4578+
4579+
for (i = 0; i < nh_res_table->num_nh_buckets; i++) {
4580+
const struct nh_notifier_single_info *nh;
4581+
int err;
4582+
4583+
nh = &nh_res_table->nhs[i];
4584+
err = mlxsw_sp_nexthop_obj_group_entry_validate(mlxsw_sp, nh,
4585+
extack);
4586+
if (err)
4587+
return err;
4588+
}
4589+
4590+
return 0;
4591+
}
4592+
45224593
static int mlxsw_sp_nexthop_obj_validate(struct mlxsw_sp *mlxsw_sp,
45234594
unsigned long event,
45244595
struct nh_notifier_info *info)
45254596
{
4526-
if (event != NEXTHOP_EVENT_REPLACE)
4597+
struct nh_notifier_single_info *nh;
4598+
4599+
if (event != NEXTHOP_EVENT_REPLACE &&
4600+
event != NEXTHOP_EVENT_RES_TABLE_PRE_REPLACE &&
4601+
event != NEXTHOP_EVENT_BUCKET_REPLACE)
45274602
return 0;
45284603

45294604
switch (info->type) {
@@ -4534,6 +4609,14 @@ static int mlxsw_sp_nexthop_obj_validate(struct mlxsw_sp *mlxsw_sp,
45344609
return mlxsw_sp_nexthop_obj_group_validate(mlxsw_sp,
45354610
info->nh_grp,
45364611
info->extack);
4612+
case NH_NOTIFIER_INFO_TYPE_RES_TABLE:
4613+
return mlxsw_sp_nexthop_obj_res_group_validate(mlxsw_sp,
4614+
info->nh_res_table,
4615+
info->extack);
4616+
case NH_NOTIFIER_INFO_TYPE_RES_BUCKET:
4617+
nh = &info->nh_res_bucket->new_nh;
4618+
return mlxsw_sp_nexthop_obj_group_entry_validate(mlxsw_sp, nh,
4619+
info->extack);
45374620
default:
45384621
NL_SET_ERR_MSG_MOD(info->extack, "Unsupported nexthop type");
45394622
return -EOPNOTSUPP;
@@ -4551,6 +4634,7 @@ static bool mlxsw_sp_nexthop_obj_is_gateway(struct mlxsw_sp *mlxsw_sp,
45514634
return info->nh->gw_family || info->nh->is_reject ||
45524635
mlxsw_sp_netdev_ipip_type(mlxsw_sp, dev, NULL);
45534636
case NH_NOTIFIER_INFO_TYPE_GRP:
4637+
case NH_NOTIFIER_INFO_TYPE_RES_TABLE:
45544638
/* Already validated earlier. */
45554639
return true;
45564640
default:

0 commit comments

Comments
 (0)