On Tue, Oct 13, 2026 at 01:03:02PM +0100, Anatoly Burakov wrote: > A lot of parsers will rely on doing the same things over and over, so > create a header with utility functions to aid in writing parsers. > > Signed-off-by: Anatoly Burakov <[email protected]> > Acked-by: Vladimir Medvedkin <[email protected]> > --- > drivers/net/intel/common/flow_util.h | 263 +++++++++++++++++++++++++++ > 1 file changed, 263 insertions(+) > create mode 100644 drivers/net/intel/common/flow_util.h > > diff --git a/drivers/net/intel/common/flow_util.h > b/drivers/net/intel/common/flow_util.h > new file mode 100644 > index 00000000000..96493ba7631 > --- /dev/null > +++ b/drivers/net/intel/common/flow_util.h > @@ -0,0 +1,263 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2025 Intel Corporation > + */ > + > +#ifndef _COMMON_INTEL_FLOW_UTIL_H_ > +#define _COMMON_INTEL_FLOW_UTIL_H_ > + > +#include <stdint.h> > +#include <stdbool.h> > +#include <string.h> > + > +#include <rte_debug.h> > +#include <rte_flow.h> > + > +/* > + * Utility functions primarily intended for flow parsers. > + */ > + > +/** > + * Get the effective mask of a flow item. > + * > + * @param item > + * Flow item. > + * @return > + * - NULL if spec is NULL > + * - item->mask if mask is not NULL > + * - default mask for the item type if mask is NULL > + * - NULL if the item type has no default mask > + */ > +static inline const void * > +ci_flow_item_mask(const struct rte_flow_item *item) > +{ > + const void *mask; > + > + if (item->spec == NULL) > + return NULL; > + if (item->mask != NULL) > + return item->mask; > + if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_DEFAULT_MASK_PTR, &mask, > sizeof(mask), > + (const void *)(uintptr_t)item->type, NULL) < 0) > + return NULL; > + return mask; > +} > + > +/* > + * Simplistic usage counter. Not thread-safe, not atomic. > + */ > +typedef uint32_t ci_usage_count_t; > + > +/** > + * Claim a usage. Returns true if this is the first usage. > + * > + * @param counter > + * Usage counter to claim. > + * @return > + * true if this is the first usage, false otherwise. > + */ > +static inline bool > +ci_usage_count_claim(ci_usage_count_t *counter) > +{ > +#ifdef CI_DEBUG > + if (*counter == UINT32_MAX) > + rte_panic("ci usage counter overflow\n"); > +#endif > + return (*counter)++ == 0; > +} > + > +/** > + * Release a usage. Returns true if this was the last usage. > + * > + * @param counter > + * Usage counter to release. > + * @return > + * true if this was the last usage, false otherwise. > + */ > +static inline bool > +ci_usage_count_release(ci_usage_count_t *counter) > +{ > +#ifdef CI_DEBUG > + if (*counter == 0) > + rte_panic("ci usage counter underflow\n"); > +#endif > + return --(*counter) == 0; > +}
Checkpatches is complaining (rightly) about this rte_panic, but since it's contained inside special debug ifdefs, I'm going to let it go. /Bruce

