Subject: Re: [PATCH net-next 03/10] net: microchip: sparx5: add support for Service Dual Leacky Buckets

From: Simon Horman <[email-masked]>
Date: Sat, 4 Feb 2023 13:53:24 +0100

On Thu, Feb 02, 2023 at 11:43:48AM +0100, Daniel Machon wrote:
> Add support for Service Dual Leacky Buckets (SDLB), used to implement
> PSFP flow-meters. Buckets are linked together in a leak chain of a leak
> group. Leak groups a preconfigured to serve buckets within a certain
> rate interval.
> 
> Signed-off-by: Daniel Machon <[email-masked]>

Reviewed-by: Simon Horman <[email-masked]>

...

> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c b/drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c
> new file mode 100644
> index 000000000000..f5267218caeb
> --- /dev/null
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_sdlb.c

...

> +static u32 sparx5_sdlb_group_get_next(struct sparx5 *sparx5, u32 group,
> +				      u32 lb)
> +{
> +	u32 val;
> +
> +	val = spx5_rd(sparx5, ANA_AC_SDLB_XLB_NEXT(lb));
> +
> +	return ANA_AC_SDLB_XLB_NEXT_LBSET_NEXT_GET(val);
> +}

...

> +static u32 sparx5_sdlb_group_get_last(struct sparx5 *sparx5, u32 group)
> +{
> +	u32 itr, next;
> +
> +	itr = sparx5_sdlb_group_get_first(sparx5, group);
> +
> +	for (;;) {

Unbounded loops like this give me some apprehension.
Will they always terminate?

> +		next = sparx5_sdlb_group_get_next(sparx5, group, itr);
> +		if (itr == next)
> +			return itr;
> +
> +		itr = next;
> +	}
> +}

...

> +static int sparx5_sdlb_group_get_adjacent(struct sparx5 *sparx5, u32 group,
> +					  u32 idx, u32 *prev, u32 *next,
> +					  u32 *first)
> +{
> +	u32 itr;
> +
> +	*first = sparx5_sdlb_group_get_first(sparx5, group);
> +	*prev = *first;
> +	*next = *first;
> +	itr = *first;
> +
> +	for (;;) {
> +		*next = sparx5_sdlb_group_get_next(sparx5, group, itr);
> +
> +		if (itr == idx)
> +			return 0; /* Found it */
> +
> +		if (itr == *next)
> +			return -EINVAL; /* Was not found */
> +
> +		*prev = itr;
> +		itr = *next;
> +	}
> +}
> +
> +static int sparx5_sdlb_group_get_count(struct sparx5 *sparx5, u32 group)
> +{
> +	u32 itr, next;
> +	int count = 0;
> +
> +	itr = sparx5_sdlb_group_get_first(sparx5, group);
> +
> +	for (;;) {
> +		next = sparx5_sdlb_group_get_next(sparx5, group, itr);
> +		if (itr == next)
> +			return count;
> +
> +		itr = next;
> +		count++;
> +	}
> +}

...

> +int sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group)
> +{
> +	u32 itr, next;
> +	int i;
> +
> +	for (i = 0; i < SPX5_SDLB_GROUP_CNT; i++) {
> +		if (sparx5_sdlb_group_is_empty(sparx5, i))
> +			continue;
> +
> +		itr = sparx5_sdlb_group_get_first(sparx5, i);
> +
> +		for (;;) {
> +			next = sparx5_sdlb_group_get_next(sparx5, i, itr);
> +
> +			if (itr == idx) {
> +				*group = i;
> +				return 0; /* Found it */
> +			}
> +			if (itr == next)
> +				break; /* Was not found */
> +
> +			itr = next;
> +		}
> +	}
> +
> +	return -EINVAL;
> +}

...