From: Joris Vaisvila <joey@tinyisr.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Joris Vaisvila <joey@tinyisr.com>
Subject: [RFC PATCH 1/2 net-next] net: dsa: initial MT7628 special tag driver
Date: Sat, 28 Feb 2026 20:52:42 +0200 [thread overview]
Message-ID: <20260228185242.800836-3-joey@tinyisr.com> (raw)
In-Reply-To: <20260228185242.800836-1-joey@tinyisr.com>
Add support for the MT7628 embedded switch's ralink special tag.
The ralink "special tag" is merged with the VLAN TPID when a VLAN is
appended by the switch. It is not installed if the VLAN tag is already
there on ingress, so the tagger assumes VLAN tagging is set up using
tag_8021q and that the outer tag is only used for port identification
and can be dropped.
On egress the special tag allows precise TX, but the correct VLAN tag
still needs to be appended.
Signed-off-by: Joris Vaisvila <joey@tinyisr.com>
---
include/net/dsa.h | 2 ++
net/dsa/Kconfig | 6 ++++
net/dsa/Makefile | 1 +
net/dsa/tag_mt7628.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 94 insertions(+)
create mode 100644 net/dsa/tag_mt7628.c
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 6c17446f3dcc..e93f9356b5c3 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -58,6 +58,7 @@ struct tc_action;
#define DSA_TAG_PROTO_YT921X_VALUE 30
#define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31
#define DSA_TAG_PROTO_MXL862_VALUE 32
+#define DSA_TAG_PROTO_MT7628_VALUE 33
enum dsa_tag_protocol {
DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE,
@@ -93,6 +94,7 @@ enum dsa_tag_protocol {
DSA_TAG_PROTO_YT921X = DSA_TAG_PROTO_YT921X_VALUE,
DSA_TAG_PROTO_MXL_GSW1XX = DSA_TAG_PROTO_MXL_GSW1XX_VALUE,
DSA_TAG_PROTO_MXL862 = DSA_TAG_PROTO_MXL862_VALUE,
+ DSA_TAG_PROTO_MT7628 = DSA_TAG_PROTO_MT7628_VALUE,
};
struct dsa_switch;
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 5ed8c704636d..4aa73bd1aa9b 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -211,4 +211,10 @@ config NET_DSA_TAG_YT921X
Say Y or M if you want to enable support for tagging frames for
Motorcomm YT921x switches.
+config NET_DSA_TAG_MT7628
+ tristate "Tag driver for the MT7628 embedded switch"
+ help
+ Say Y or M if you want to enable support for tagging frames for the
+ switch embedded in the MT7628 SoC.
+
endif
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index bf7247759a64..d25ec0ab7d67 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o
obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o
+obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o
# for tracing framework to find trace.h
CFLAGS_trace.o := -I$(src)
diff --git a/net/dsa/tag_mt7628.c b/net/dsa/tag_mt7628.c
new file mode 100644
index 000000000000..a612df43682c
--- /dev/null
+++ b/net/dsa/tag_mt7628.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026, Joris Vaisvila <joey@tinyisr.com>
+ * MT7628 ralink special tag support
+ */
+
+#include <linux/etherdevice.h>
+#include <linux/dsa/8021q.h>
+#include <net/dsa.h>
+
+#include "tag.h"
+
+/*
+ * MT7628 uses the ralink special tag. It merges the VLAN TPID with source
+ * port ID on RX and target port bitmap on TX.
+ *
+ * The switch forwarding is controlled with VLANs, so each port is put in a
+ * standalone VLAN using tag_8021q. Double tag is enabled to simulate VLAN
+ * unaware ports.
+ *
+ * A VLAN tag is constructed on egress to target the standalone VLAN and port.
+ * The outer VLAN tag is parsed and removed on ingress.
+ */
+
+#define MT7628_TAG_NAME "tag_mt7628"
+
+#define SPECIAL_HEADER_RECV_SOURCE_PORT_MASK GENMASK(2, 0)
+#define SPECIAL_TAG_LEN 4
+
+static struct sk_buff *dsa_user_special_xmit(struct sk_buff *skb,
+ struct net_device *dev)
+{
+ struct dsa_port *dp = dsa_user_to_port(dev);
+ u16 xmit_vlan = dsa_tag_8021q_standalone_vid(dp);
+ u8 *special_tag;
+
+ skb_push(skb, SPECIAL_TAG_LEN);
+ dsa_alloc_etype_header(skb, SPECIAL_TAG_LEN);
+
+ special_tag = dsa_etype_header_pos_tx(skb);
+
+ special_tag[0] = ETH_P_8021Q >> 8;
+ special_tag[1] = BIT(dp->index);
+
+ special_tag[2] = xmit_vlan >> 8;
+ special_tag[3] = xmit_vlan & 0xff;
+ return skb;
+}
+
+static struct sk_buff *dsa_user_special_recv(struct sk_buff *skb,
+ struct net_device *dev)
+{
+ u16 hdr;
+ int port;
+ __be16 *phdr;
+
+ if (unlikely(!pskb_may_pull(skb, SPECIAL_TAG_LEN)))
+ return NULL;
+
+ phdr = dsa_etype_header_pos_rx(skb);
+ hdr = ntohs(*phdr);
+ skb_pull_rcsum(skb, SPECIAL_TAG_LEN);
+ dsa_strip_etype_header(skb, SPECIAL_TAG_LEN);
+
+ port = hdr & SPECIAL_HEADER_RECV_SOURCE_PORT_MASK;
+
+ skb->dev = dsa_conduit_find_user(dev, 0, port);
+ if (!skb->dev)
+ return NULL;
+ dsa_default_offload_fwd_mark(skb);
+ return skb;
+}
+
+static const struct dsa_device_ops mt7628_tag_ops = {
+ .name = MT7628_TAG_NAME,
+ .proto = DSA_TAG_PROTO_MT7628,
+ .xmit = dsa_user_special_xmit,
+ .rcv = dsa_user_special_recv,
+ .needed_headroom = SPECIAL_TAG_LEN,
+};
+module_dsa_tag_driver(mt7628_tag_ops);
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_MT7628, MT7628_TAG_NAME);
+MODULE_DESCRIPTION("DSA tag driver for MT7628 switch");
+MODULE_LICENSE("GPL v2");
--
2.53.0
next prev parent reply other threads:[~2026-02-28 18:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-28 18:52 [RFC 0/2 net-next] net: dsa: MT7628 embedded switch initial support Joris Vaisvila
2026-02-28 18:52 ` Joris Vaisvila [this message]
2026-02-28 20:12 ` [RFC PATCH 1/2 net-next] net: dsa: initial MT7628 special tag driver Andrew Lunn
2026-03-04 22:16 ` Vladimir Oltean
2026-02-28 18:52 ` [RFC PATCH 2/2 net-next] net: dsa: initial support for MT7628 embedded switch Joris Vaisvila
2026-02-28 20:16 ` Andrew Lunn
2026-02-28 20:31 ` Andrew Lunn
2026-03-01 17:23 ` Joris Vaišvila
2026-02-28 23:40 ` [RFC 0/2 net-next] net: dsa: MT7628 embedded switch initial support Vladimir Oltean
2026-03-01 12:00 ` Daniel Golle
2026-03-01 12:36 ` Vladimir Oltean
2026-03-01 13:13 ` Joris Vaišvila
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=20260228185242.800836-3-joey@tinyisr.com \
--to=joey@tinyisr.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.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