Re: [PATCH net-next v2 7/9] net: microchip: sparx5: Writing rules to the IS2 VCAP
From: Casper Andersson
Date: Thu Oct 20 2022 - 03:48:18 EST
On 2022-10-19 13:42, Steen Hegelund wrote:
> +static void vcap_iter_skip_tg(struct vcap_stream_iter *itr)
> +{
> + /* Compensate the field offset for preceding typegroups */
> + while (itr->tg->width && itr->offset >= itr->tg->offset) {
> + itr->offset += itr->tg->width;
> + itr->tg++; /* next typegroup */
> + }
> +}
It was not immediately obvious to me why it should stop iterating when
tg->width is zero. But after some digging I saw that the tg iterators
always ends with an empty element (all bits zero, and therefore width is
zero). Could this be made clearer? Or maybe this is something common
that I'm just not used to seeing.
> +static void vcap_encode_bit(u32 *stream, struct vcap_stream_iter *itr, bool val)
> +{
> + /* When intersected by a type group field, stream the type group bits
> + * before continuing with the value bit
> + */
> + while (itr->tg->width &&
> + itr->offset >= itr->tg->offset &&
> + itr->offset < itr->tg->offset + itr->tg->width) {
> + int tg_bitpos = itr->tg->offset - itr->offset;
> +
> + vcap_set_bit(stream, itr, (itr->tg->value >> tg_bitpos) & 0x1);
> + itr->offset++;
> + vcap_iter_update(itr);
> + }
Same as above.
> +static void vcap_encode_typegroups(u32 *stream, int sw_width,
> + const struct vcap_typegroup *tg,
> + bool mask)
> +{
> + struct vcap_stream_iter iter;
> + int idx;
> +
> + /* Mask bits must be set to zeros (inverted later when writing to the
> + * mask cache register), so that the mask typegroup bits consist of
> + * match-1 or match-0, or both
> + */
> + vcap_iter_set(&iter, sw_width, tg, 0);
> + while (iter.tg->width) {
> + /* Set position to current typegroup bit */
> + iter.offset = iter.tg->offset;
> + vcap_iter_update(&iter);
> + for (idx = 0; idx < iter.tg->width; idx++) {
> + /* Iterate over current typegroup bits. Mask typegroup
> + * bits are always set
> + */
> + if (mask)
> + vcap_set_bit(stream, &iter, 0x1);
> + else
> + vcap_set_bit(stream, &iter,
> + (iter.tg->value >> idx) & 0x1);
> + iter.offset++;
> + vcap_iter_update(&iter);
> + }
> + iter.tg++; /* next typegroup */
> + }
Same as above.
Tested on Microchip PCB135 switch.
Tested-by: Casper Andersson <casper.casan@xxxxxxxxx>
Reviewed-by: Casper Andersson <casper.casan@xxxxxxxxx>
Best Regards,
Casper