BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Meghana Malladi" <m-malladi@ti.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support
Date: Thu, 19 Nov 2026 18:50:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-223806@kernel.org> (raw)
In-Reply-To: <20261118184729.2302130-3-m-malladi@ti.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net: ti: icssg-prueth: slot 15 rejected in
  icssg_rxnfc_rule_add()
- [Medium] net: ti: icssg: broken ETHTOOL_GRXCLSRLALL contract in
  emac_get_rxnfc()
- [Medium] net: ti: icssg: RXNFC rules wiped and not restored in
  prueth_emac_restart()
- [Medium] net: ti: icssg-prueth: missing icssg_rxnfc_rule_restore() on
  fw restart
- [Low] net: ti: icssg-prueth: sparse __be16 warning in
  icssg_ft3_program_filter()
--

commit 9fd710bfddff4882ecad02b113fc08db59485950
Author: Meghana Malladi <m-malladi@ti.com>

net: ti: icssg-prueth: Add ethtool RX flow classification support

This commit adds ethtool RX flow classification support (get_rxnfc and
set_rxnfc) to steer EtherType matches to specific RX flows using the ICSSG
FT3 hardware filters and RX classifier OR tables.

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_classifier.c b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> index 87a8577093dbb..520b3f3377784 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_classifier.c
> @@ -105,6 +105,14 @@ enum ft1_cfg_type {
>  	((BIT(slot) << RX_CLASS_FT_FT1_MATCH_SHIFT) & \
>  	RX_CLASS_FT_FT1_MATCH_MASK)
>  
> +#define RX_CLASS_FT_FT3_MATCH(slot)	\
> +	((BIT(slot) << RX_CLASS_FT_FT3_MATCH_SHIFT) & \
> +	RX_CLASS_FT_FT3_MATCH_MASK)
> +
> +/* FT3 Configuration registers and modes */
> +#define FT3_CFG_REGISTER_EQUAL		(1U)
> +#define FT3_CFG_REGISTER_VLAN_SKIP	BIT(2)
> +
>  /* HSR/PRP protocol frame filtering */
>  #define HSR_PTP_ETHERTYPE_OFFSET	0x12
>  #define PRP_PTP_ETHERTYPE_OFFSET	0x0C
> @@ -532,3 +540,402 @@ void icssg_ft3_hsr_configurations(struct regmap *miig_rt, int slice,
>  	}
>  }
>  EXPORT_SYMBOL_GPL(icssg_ft3_hsr_configurations);
> +
> +/* RX Flow Classification (ethtool) rule management */
> +
> +/* Allocate free FT3 slot, avoiding reserved slot 14 */
> +static int allocate_ft3_slot(struct prueth_emac *emac)
> +{
> +	u16 used = emac->rxnfc.ft3_slots_used | ICSSG_FT3_RESERVED_SLOTS;
> +	int slot;
> +
> +	for (slot = 0; slot < ICSSG_NUM_FT3_SLOTS; slot++) {
> +		if (!(used & BIT(slot))) {
> +			emac->rxnfc.ft3_slots_used |= BIT(slot);
> +			return slot;
> +		}
> +	}
> +	return -ENOSPC;
> +}
> +
> +/* Free allocated FT3 slot */
> +static void free_ft3_slot(struct prueth_emac *emac, int slot)
> +{
> +	emac->rxnfc.ft3_slots_used &= ~BIT(slot);
> +}
> +
> +/* Program FT3 filter slot with ethertype pattern */
> +static void icssg_ft3_program_filter(struct regmap *miig_rt, int slice,
> +				     int slot, struct icssg_rxnfc_rule *rule)
> +{
> +	const struct ethtool_rx_flow_spec *fs = &rule->flow_spec;
> +	u16 ether_type;
> +
> +	/* Extract EtherType from flow spec (network byte order) */
> +	ether_type = fs->h_u.ether_spec.h_proto;
> +
> +	/* Deactivate filter before programming */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_CFG), 0);
> +
> +	/* EtherType is at byte 12 in standard Ethernet frames */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START),
> +		     PRP_PTP_ETHERTYPE_OFFSET);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_AUTO), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_START_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_JUMP_OFFSET), 0);
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_LEN), 0);
> +
> +	/* FT3 compares a 32-bit LE word at FT3_START. EtherType occupies the
> +	 * lower 16 bits of that word. FT3_T_MASK=0xFFFF0000 masks the upper
> +	 * 16 bits (payload bytes), so only the lower 16 bits are compared.
> +	 *
> +	 * h_proto is __be16 (network byte order). On LE the raw integer value
> +	 * equals the lower 16 bits of the LE 32-bit word at the EtherType
> +	 * offset in the frame — e.g. IPv4 0x0800 BE → h_proto = 0x0008 on LE,
> +	 * which is exactly what FT3 sees in the lower 16 bits of the word at
> +	 * byte 12. No conversion needed; using be16_to_cpu() here would invert
> +	 * the byte order and break the match.
> +	 * Reference: FT3_PTP_PATTERN = 0xF788 = htons(0x88F7) = raw h_proto value.
> +	 */
> +	regmap_write(miig_rt, FT3_N_REG(slice, slot, FT3_T),
> +		     (__force u32)ether_type);

[Severity: Low]
Does assigning fs->h_u.ether_spec.h_proto (__be16) to ether_type (u16) trigger
a sparse endianness warning because the __force cast is placed on the
subsequent u16-to-u32 conversion instead of on h_proto?  Also,
FT3_CFG_REGISTER_VLAN_SKIP defined above is unused.

[ ... ]

> +/* Restore RX flow classification hardware state from the in-memory rule list.
> + * Call after icssg_class_default() resets the classifier registers on open or
> + * after firmware restart so that existing rules take effect again.
> + */
> +void icssg_rxnfc_rule_restore(struct prueth_emac *emac)
> +{
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +
> +	if (slice < 0)
> +		return;
> +
> +	mutex_lock(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list)
> +		icssg_ft3_program_filter(miig_rt, slice, rule->ft3_slot, rule);
> +
> +	icssg_rxnfc_classifier_update(emac);
> +
> +	mutex_unlock(&emac->rxnfc.rxnfc_lock);
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_restore);

[Severity: Medium]
Should prueth_emac_restart() also call icssg_rxnfc_rule_restore() for both
ports after prueth_emac_common_start()?  During bridge or HSR mode transitions
on running interfaces, prueth_emac_restart() calls prueth_emac_common_start()
-> icssg_class_default() without going through emac_ndo_open(), which resets
all RX_CLASS_OR_EN registers and silently disables active RXNFC rules in
hardware while leaving them in emac->rxnfc.rules.

[ ... ]

> +/* Add a new RX flow classification rule */
> +int icssg_rxnfc_rule_add(struct prueth_emac *emac, struct ethtool_rxnfc *info)
> +{
> +	struct ethtool_rx_flow_spec *fs = &info->fs;
> +	struct prueth *prueth = emac->prueth;
> +	struct regmap *miig_rt = prueth->miig_rt;
> +	int slice = prueth_emac_slice(emac);
> +	struct icssg_rxnfc_rule *rule;
> +	int ft3_slot;
> +	int ret;
> +
> +	if (slice < 0)
> +		return -EINVAL;
> +
> +	/* Validate rule parameters */
> +	ret = validate_rule(emac, fs);
> +	if (ret)
> +		return ret;
> +
> +	/* Validate explicit location: reject special specifiers, out-of-range
> +	 * values, and the reserved slot 14 used by HSR/PRP.
> +	 */
> +	if (fs->location != RX_CLS_LOC_ANY) {
> +		if (fs->location >= ICSSG_RXNFC_MAX_RULES ||
> +		    BIT(fs->location) & ICSSG_FT3_RESERVED_SLOTS)
> +			return -EINVAL;
> +	}

[Severity: Medium]
Does checking fs->location >= ICSSG_RXNFC_MAX_RULES (15) instead of
ICSSG_NUM_FT3_SLOTS (16) reject valid slot 15 with -EINVAL?  Because slot 14
is reserved by ICSSG_FT3_RESERVED_SLOTS, the 15 usable FT3 slots are 0..13 and
15 (which allocate_ft3_slot() assigns for RX_CLS_LOC_ANY), so bounding explicit
locations by ICSSG_RXNFC_MAX_RULES restricts explicit insertions to 14 slots
(0..13).  Similarly, ETHTOOL_GRXCLSRLCNT in emac_get_rxnfc() reports a table
size of ICSSG_RXNFC_MAX_RULES (15) in info->data instead of
ICSSG_NUM_FT3_SLOTS (16).

[ ... ]

> +/* Get all RX flow classification rules */
> +int icssg_rxnfc_rule_get_all(struct prueth_emac *emac, u32 *rule_locs,
> +			     u32 rule_locs_capacity, u32 *rule_cnt)
> +{
> +	struct icssg_rxnfc_rule *rule;
> +	u32 count = 0;
> +	int ret = 0;
> +
> +	mutex_lock(&emac->rxnfc.rxnfc_lock);
> +
> +	list_for_each_entry(rule, &emac->rxnfc.rules, list) {
> +		if (!rule_locs) {
> +			/* Caller passed rule_cnt=0: just count active rules */
> +			count++;
> +			continue;
> +		}
> +		if (count >= rule_locs_capacity) {
> +			ret = -EMSGSIZE;
> +			break;
> +		}
> +		rule_locs[count++] = rule->location;
> +	}
> +
> +	*rule_cnt = count;
> +
> +	mutex_unlock(&emac->rxnfc.rxnfc_lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(icssg_rxnfc_rule_get_all);
> diff --git a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> index 68646cb7df442..35eb056dab6d9 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_ethtool.c
> @@ -300,6 +300,62 @@ static int emac_set_per_queue_coalesce(struct net_device *ndev, u32 queue,
>  	return 0;
>  }
>  
> +static u32 emac_get_rx_ring_count(struct net_device *ndev)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +
> +	return emac->rx_flow_num;
> +}
> +
> +static int emac_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *info,
> +			  u32 *rule_locs)
> +{
> +	struct prueth_emac *emac = netdev_priv(ndev);
> +	int ret = 0;
> +
> +	if (emac->is_sr1)
> +		return -EOPNOTSUPP;
> +
> +	switch (info->cmd) {
> +	case ETHTOOL_GRXCLSRLCNT:
> +		info->rule_cnt = emac->rxnfc.rxnfc_rule_count;
> +		info->data = ICSSG_RXNFC_MAX_RULES | RX_CLS_LOC_SPECIAL;
> +		break;
> +	case ETHTOOL_GRXCLSRULE:
> +		ret = icssg_rxnfc_rule_get(emac, info->fs.location, &info->fs);
> +		break;
> +	case ETHTOOL_GRXCLSRLALL: {
> +		u32 rule_cnt = 0;
> +
> +		ret = icssg_rxnfc_rule_get_all(emac, rule_locs,
> +					       info->rule_cnt, &rule_cnt);
> +		info->rule_cnt = rule_cnt;
> +		break;
> +	}

[Severity: Medium]
Does ETHTOOL_GRXCLSRLALL violate the ethtool_rxnfc UAPI contract by leaving
info->data unset and returning 0 instead of -EMSGSIZE when rule_locs is NULL
and active rules exist?  For ETHTOOL_GRXCLSRLALL, info->data is supposed to
return the rule table size, and passing info->rule_cnt == 0 (which makes
ethtool_get_rxnfc() pass rule_locs == NULL with capacity 0) should hit the
count >= rule_locs_capacity check and return -EMSGSIZE when rules are present.

[ ... ]

> diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> index 716f1b9195d67..b08e74e24a5a3 100644
> --- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> +++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
> @@ -1101,6 +1101,12 @@ static int emac_ndo_open(struct net_device *ndev)
>  
>  	icssg_mii_update_mtu(prueth->mii_rt, slice, ndev->max_mtu);
>  
> +	/* Re-program FT3 filters and classifier OR tables from the persistent
> +	 * rule list. icssg_class_default() called above resets all classifiers,
> +	 * so rules must be restored here on every open/restart.
> +	 */
> +	icssg_rxnfc_rule_restore(emac);

[Severity: Medium]
As noted in this comment, rules must be restored on every open or restart,
yet icssg_rxnfc_rule_restore() is only called here in emac_ndo_open() and not
in prueth_emac_restart().  When prueth_emac_restart() runs (for example, via
icssg_change_mode(), prueth_netdevice_port_unlink(), or
prueth_hsr_port_unlink()), prueth_emac_common_start() calls
icssg_class_default() on both ICSS_SLICE0 and ICSS_SLICE1, resetting
classifier 0 back to RX_CLASS_FT_BC | RX_CLASS_FT_DA_P and clearing
classifiers 1..15 without restoring the RXNFC rules for either port.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118184729.2302130-1-m-malladi@ti.com?part=2

      parent reply	other threads:[~2026-11-19 18:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 18:47 [PATCH net-next 0/2] net: ti: icssg: Multi-flow RX and ethtool RX flow classification Meghana Malladi
2026-11-18 18:47 ` [PATCH net-next 1/2] net: ti: icssg-prueth: Add multi-flow RX support with per-flow NAPI Meghana Malladi
2026-11-19 18:50   ` sashiko-bot
2026-11-18 18:47 ` [PATCH net-next 2/2] net: ti: icssg-prueth: Add ethtool RX flow classification support Meghana Malladi
2026-11-19  9:19   ` Marco Crivellari
2026-11-19 18:50   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-223806@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=m-malladi@ti.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox