mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Roger Quadros <rogerq@kernel.org>,
	Siddharth Vadapalli <s-vadapalli@ti.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	danishanwar@ti.com
Cc: srk@ti.com, linux-omap@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 8/9] net: ethernet: ti: am65-cpsw: add network flow classification support
Date: Thu, 8 May 2025 16:00:05 +0200	[thread overview]
Message-ID: <244138b2-a90e-404d-946f-9ce25c6155e1@redhat.com> (raw)
In-Reply-To: <20250505-am65-cpsw-rx-class-v2-8-5359ea025144@kernel.org>

On 5/5/25 6:26 PM, Roger Quadros wrote:
[...]
> +/* validate the rxnfc rule and convert it to policer config */
> +static int am65_cpsw_rxnfc_validate(struct am65_cpsw_port *port,
> +				    struct ethtool_rxnfc *rxnfc,
> +				    struct cpsw_ale_policer_cfg *cfg)
> +{
> +	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
> +	int flow_type = AM65_CPSW_FLOW_TYPE(fs->flow_type);
> +	struct ethhdr *eth_mask;

(Minor nit only mentioned because of more relevant comments on previous
patch) Please respect the reverse christmas tree order above.

> +
> +	memset(cfg, 0, sizeof(*cfg));
> +
> +	if (flow_type & FLOW_RSS)
> +		return -EINVAL;
> +
> +	if (fs->location == RX_CLS_LOC_ANY ||
> +	    fs->location >= port->rxnfc_max)
> +		return -EINVAL;
> +
> +	if (fs->ring_cookie == RX_CLS_FLOW_DISC)
> +		cfg->drop = true;
> +	else if (fs->ring_cookie > AM65_CPSW_MAX_QUEUES)
> +		return -EINVAL;
> +
> +	cfg->port_id = port->port_id;
> +	cfg->thread_id = fs->ring_cookie;
> +
> +	switch (flow_type) {
> +	case ETHER_FLOW:
> +		eth_mask = &fs->m_u.ether_spec;
> +
> +		/* etherType matching is supported by h/w but not yet here */
> +		if (eth_mask->h_proto)
> +			return -EINVAL;
> +
> +		/* Only support source matching addresses by full mask */
> +		if (is_broadcast_ether_addr(eth_mask->h_source)) {
> +			cfg->match_flags |= CPSW_ALE_POLICER_MATCH_MACSRC;
> +			ether_addr_copy(cfg->src_addr,
> +					fs->h_u.ether_spec.h_source);
> +		}
> +
> +		/* Only support destination matching addresses by full mask */
> +		if (is_broadcast_ether_addr(eth_mask->h_dest)) {
> +			cfg->match_flags |= CPSW_ALE_POLICER_MATCH_MACDST;
> +			ether_addr_copy(cfg->dst_addr,
> +					fs->h_u.ether_spec.h_dest);
> +		}
> +
> +		if ((fs->flow_type & FLOW_EXT) && fs->m_ext.vlan_tci) {
> +			/* Don't yet support vlan ethertype */
> +			if (fs->m_ext.vlan_etype)
> +				return -EINVAL;
> +
> +			if (fs->m_ext.vlan_tci != VLAN_TCI_FULL_MASK)
> +				return -EINVAL;
> +
> +			cfg->vid = FIELD_GET(VLAN_VID_MASK,
> +					     ntohs(fs->h_ext.vlan_tci));
> +			cfg->vlan_prio = FIELD_GET(VLAN_PRIO_MASK,
> +						   ntohs(fs->h_ext.vlan_tci));
> +			cfg->match_flags |= CPSW_ALE_POLICER_MATCH_OVLAN;
> +		}
> +
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int am65_cpsw_policer_find_match(struct am65_cpsw_port *port,
> +					struct cpsw_ale_policer_cfg *cfg)
> +{
> +	struct am65_cpsw_rxnfc_rule *rule;
> +	int loc = -EINVAL;
> +
> +	mutex_lock(&port->rxnfc_lock);
> +	list_for_each_entry(rule, &port->rxnfc_rules, list) {
> +		if (!memcmp(&rule->cfg, cfg, sizeof(*cfg))) {
> +			loc = rule->location;
> +			break;
> +		}
> +	}
> +
> +	mutex_unlock(&port->rxnfc_lock);
> +
> +	return loc;
> +}
> +
> +static int am65_cpsw_rxnfc_add_rule(struct am65_cpsw_port *port,
> +				    struct ethtool_rxnfc *rxnfc)
> +{
> +	struct ethtool_rx_flow_spec *fs = &rxnfc->fs;
> +	struct am65_cpsw_rxnfc_rule *rule;
> +	struct cpsw_ale_policer_cfg cfg;
> +	int loc, ret;
> +
> +	if (am65_cpsw_rxnfc_validate(port, rxnfc, &cfg))
> +		return -EINVAL;
> +
> +	/* need to check if similar rule is already present at another location,
> +	 * if yes error out
> +	 */
> +	loc = am65_cpsw_policer_find_match(port, &cfg);
> +	if (loc >= 0 && loc != fs->location) {
> +		netdev_info(port->ndev,
> +			    "rule already exists in location %d. not adding\n",
> +			    loc);
> +		return -EINVAL;
> +	}
> +
> +	/* delete exisiting rule */
> +	if (loc >= 0) {
> +		mutex_lock(&port->rxnfc_lock);

The rxnfc_lock mutex is released and re-aquired after the previous
lookup. Con some other thread delete the matching rule in-between and
add another one at a different location?

/P


  reply	other threads:[~2025-05-08 14:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 16:26 [PATCH net-next v2 0/9] " Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 1/9] net: ethernet: ti: cpsw_ale: Update Policer fields for more ALE size/ports Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 2/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_add_vlan() Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 3/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_vlan_add_modify() Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 4/9] net: ethernet: ti: cpsw_ale: return ALE index in cpsw_ale_add_ucast() Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 5/9] net: ethernet: ti: cpsw_ale: add cpsw_ale_policer_reset_entry() Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 6/9] net: ethernet: ti: cpsw_ale: add cpsw_ale_policer_set/clr_entry() Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 7/9] net: ethernet: ti: cpsw_ale: add policer save restore for PM sleep Roger Quadros
2025-05-08 13:49   ` Paolo Abeni
2025-05-13 11:23     ` Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 8/9] net: ethernet: ti: am65-cpsw: add network flow classification support Roger Quadros
2025-05-08 14:00   ` Paolo Abeni [this message]
2025-05-13 11:41     ` Roger Quadros
2025-05-05 16:26 ` [PATCH net-next v2 9/9] net: ethernet: ti: am65-cpsw: remove cpsw_ale_classifier_setup_default() Roger Quadros

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=244138b2-a90e-404d-946f-9ce25c6155e1@redhat.com \
    --to=pabeni@redhat.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=rogerq@kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=srk@ti.com \
    /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

all inboxes | Powered by JetHome®