mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 10:46:33 +00:00
mlxsw: spectrum_router: Encode adjacency group size ranges in an array
The device supports a fixed set of adjacency group sizes. Encode these sizes in an array, so that the next patch will be able to split it between Spectrum-1 and Spectrum-{2,3}, which support different size ranges. Signed-off-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
d354fdd923
commit
164fa130dd
@ -3559,34 +3559,57 @@ mlxsw_sp_nexthop_fib_entries_update(struct mlxsw_sp *mlxsw_sp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct mlxsw_sp_adj_grp_size_range {
|
||||
u16 start; /* Inclusive */
|
||||
u16 end; /* Inclusive */
|
||||
};
|
||||
|
||||
/* Ordered by range start value */
|
||||
static const struct mlxsw_sp_adj_grp_size_range
|
||||
mlxsw_sp_adj_grp_size_ranges[] = {
|
||||
{ .start = 1, .end = 64 },
|
||||
{ .start = 512, .end = 512 },
|
||||
{ .start = 1024, .end = 1024 },
|
||||
{ .start = 2048, .end = 2048 },
|
||||
{ .start = 4096, .end = 4096 },
|
||||
};
|
||||
|
||||
static void mlxsw_sp_adj_grp_size_round_up(u16 *p_adj_grp_size)
|
||||
{
|
||||
/* Valid sizes for an adjacency group are:
|
||||
* 1-64, 512, 1024, 2048 and 4096.
|
||||
*/
|
||||
if (*p_adj_grp_size <= 64)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mlxsw_sp_adj_grp_size_ranges); i++) {
|
||||
const struct mlxsw_sp_adj_grp_size_range *size_range;
|
||||
|
||||
size_range = &mlxsw_sp_adj_grp_size_ranges[i];
|
||||
|
||||
if (*p_adj_grp_size >= size_range->start &&
|
||||
*p_adj_grp_size <= size_range->end)
|
||||
return;
|
||||
else if (*p_adj_grp_size <= 512)
|
||||
*p_adj_grp_size = 512;
|
||||
else if (*p_adj_grp_size <= 1024)
|
||||
*p_adj_grp_size = 1024;
|
||||
else if (*p_adj_grp_size <= 2048)
|
||||
*p_adj_grp_size = 2048;
|
||||
else
|
||||
*p_adj_grp_size = 4096;
|
||||
|
||||
if (*p_adj_grp_size <= size_range->end) {
|
||||
*p_adj_grp_size = size_range->end;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mlxsw_sp_adj_grp_size_round_down(u16 *p_adj_grp_size,
|
||||
unsigned int alloc_size)
|
||||
{
|
||||
if (alloc_size >= 4096)
|
||||
*p_adj_grp_size = 4096;
|
||||
else if (alloc_size >= 2048)
|
||||
*p_adj_grp_size = 2048;
|
||||
else if (alloc_size >= 1024)
|
||||
*p_adj_grp_size = 1024;
|
||||
else if (alloc_size >= 512)
|
||||
*p_adj_grp_size = 512;
|
||||
size_t arr_size = ARRAY_SIZE(mlxsw_sp_adj_grp_size_ranges);
|
||||
int i;
|
||||
|
||||
for (i = arr_size - 1; i >= 0; i--) {
|
||||
const struct mlxsw_sp_adj_grp_size_range *size_range;
|
||||
|
||||
size_range = &mlxsw_sp_adj_grp_size_ranges[i];
|
||||
|
||||
if (alloc_size >= size_range->end) {
|
||||
*p_adj_grp_size = size_range->end;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int mlxsw_sp_fix_adj_grp_size(struct mlxsw_sp *mlxsw_sp,
|
||||
|
Loading…
x
Reference in New Issue
Block a user