All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Joris Vaisvila <joey@tinyisr.com>
Cc: netdev@vger.kernel.org, horms@kernel.org, pabeni@redhat.com,
	kuba@kernel.org, edumazet@google.com, davem@davemloft.net,
	olteanv@gmail.com, Andrew Lunn <andrew@lunn.ch>,
	devicetree@vger.kernel.org, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH net-next 3/4] net: dsa: initial MT7628 tagging driver
Date: Thu, 26 Mar 2026 23:24:19 +0000	[thread overview]
Message-ID: <acXAIxG3kwuEmuOp@makrotopia.org> (raw)
In-Reply-To: <20260326204413.3317584-4-joey@tinyisr.com>

On Thu, Mar 26, 2026 at 10:44:12PM +0200, Joris Vaisvila wrote:
> Add support for the MT7628 embedded switch's tag.
> [...]

> +++ b/net/dsa/tag_mt7628.c
> [...]
> +
> +#define MT7628_TAG_NAME "mt7628"
> +
> +#define MT7628_TAG_TX_PORT_BIT_MASK GENMASK(5, 0)
> +#define MT7628_TAG_RX_PORT_MASK GENMASK(2, 0)

'MASK' vs. 'BIT_MASK'... Maybe just

#define MT7628_TAG_TX_PORT	GENMASK(5, 0)
#define MT7628_TAG_RX_PORT	GENMASK(2, 0)


> +#define MT7628_TAG_LEN 4
> +
> +static struct sk_buff *mt7628_tag_xmit(struct sk_buff *skb,
> +				       struct net_device *dev)
> +{
> +	struct dsa_port *dp;
> +	u16 xmit_vlan;
> +	__be16 *tag;
> +
> +	dp = dsa_user_to_port(dev);
> +	xmit_vlan = dsa_tag_8021q_standalone_vid(dp);
> +
> +	skb_push(skb, MT7628_TAG_LEN);
> +	dsa_alloc_etype_header(skb, MT7628_TAG_LEN);
> +
> +	tag = dsa_etype_header_pos_tx(skb);
> +
> +	tag[0] = htons(ETH_P_8021Q |
> +		       FIELD_PREP(MT7628_TAG_TX_PORT_BIT_MASK,
> +				  dsa_xmit_port_mask(skb, dev)));
> +	tag[1] = htons(xmit_vlan);
> +
> +	return skb;
> +}
> +
> +static struct sk_buff *mt7628_tag_rcv(struct sk_buff *skb,
> +				      struct net_device *dev)
> +{
> +	int src_port;
> +	__be16 *phdr;
> +	u16 tpid;
> +
> +	if (unlikely(!pskb_may_pull(skb, MT7628_TAG_LEN)))
> +		return NULL;
> +
> +	phdr = dsa_etype_header_pos_rx(skb);
> +	tpid = ntohs(*phdr);

Why not directly

	src_port = FIELD_GET(MT7628_TAG_RX_PORT, ntohs(*phdr));

tpid isn't used for anything else (at this point).

Or even getting rid of both stack variables:

	skb->dev = dsa_conduit_find_user(dev, 0, FIELD_GET(MT7628_TAG_RX_PORT,
							   ntohs(*phdr)));

(though the compiler probably treats both forms equally or
almost equally)

> +	skb_pull_rcsum(skb, MT7628_TAG_LEN);
> +	dsa_strip_etype_header(skb, MT7628_TAG_LEN);
> +
> +	src_port = tpid & MT7628_TAG_RX_PORT_MASK;

As you are using FIELD_PREP above for something which also could as well
just be an & operation, I would say you should then also use FIELD_GET here,
just to maintain an consistent style. And potentially move up to get rid
of the stack variables, see above.

> +
> +	skb->dev = dsa_conduit_find_user(dev, 0, src_port);
> +	if (!skb->dev)
> +		return NULL;
> +	dsa_default_offload_fwd_mark(skb);
> +	return skb;
> +}

  reply	other threads:[~2026-03-26 23:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-26 20:44 [PATCH net-next 0/4] net: dsa: mt7628 embedded switch initial support Joris Vaisvila
2026-03-26 20:44 ` [PATCH net-next 1/4] dt-bindings: net: dsa: add MT7628 ESW Joris Vaisvila
2026-03-26 23:11   ` Daniel Golle
2026-03-27  6:00     ` Joris Vaisvila
2026-03-27 11:32       ` Daniel Golle
2026-03-27 15:35         ` Joris Vaisvila
2026-03-26 20:44 ` [PATCH net-next 2/4] net: phy: mediatek: add phy driver for MT7628 built-in Fast Ethernet PHYs Joris Vaisvila
2026-03-27 11:48   ` Andrew Lunn
2026-03-26 20:44 ` [PATCH net-next 3/4] net: dsa: initial MT7628 tagging driver Joris Vaisvila
2026-03-26 23:24   ` Daniel Golle [this message]
2026-03-26 20:44 ` [PATCH net-next 4/4] net: dsa: initial support for MT7628 embedded switch Joris Vaisvila
2026-03-27 12:07   ` Andrew Lunn
2026-03-27 15:39     ` Joris Vaisvila

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=acXAIxG3kwuEmuOp@makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=joey@tinyisr.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.