]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: dsa: convert trailer tag hack into separate module 21815/head
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sun, 1 Feb 2026 10:11:51 +0000 (11:11 +0100)
committerRobert Marko <robimarko@gmail.com>
Thu, 5 Feb 2026 10:45:51 +0000 (11:45 +0100)
DSA tagging currently works with a tuned trailer tagging. That means:

- realtek target uses tag_trailer for tagging
- there is a patch for the trailer tagger to write the target port not
  as a bitfield but as an integer

Make the tagging independent from upstream and hacky patches by providing
a new downstream driver. This can be aligned easier for future development.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/21815
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/Kconfig
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c
target/linux/realtek/files-6.12/net/dsa/tag_rtl_otto.c [new file with mode: 0644]
target/linux/realtek/patches-6.12/721-net-dsa-add-support-for-tag-rtl-otto.patch [new file with mode: 0644]
target/linux/realtek/patches-6.12/722-net-dsa-add-rtl838x-support-for-tag-trailer.patch [deleted file]
target/linux/realtek/rtl838x/config-6.12
target/linux/realtek/rtl839x/config-6.12
target/linux/realtek/rtl930x/config-6.12
target/linux/realtek/rtl930x_nand/config-6.12
target/linux/realtek/rtl931x/config-6.12
target/linux/realtek/rtl931x_nand/config-6.12

index 97e6c8f428a86df1d818c9b319380437d4b82c00..5808ad11e0cf862ef990d2aaaa3229f1dd6eef46 100644 (file)
@@ -2,7 +2,7 @@
 config NET_DSA_RTL83XX
        tristate "Realtek RTL838x/RTL839x switch support"
        depends on MACH_REALTEK_RTL
-       select NET_DSA_TAG_TRAILER
+       select NET_DSA_TAG_RTL_OTTO
        help
          This driver adds support for Realtek RTL83xx series switching.
 
index d33e0fa449ecca02ab0937e35fa7aebd91c54ee4..311e59e6f8cf9cf82150f734c50a7ba95f6c9aec 100644 (file)
@@ -428,7 +428,7 @@ static enum dsa_tag_protocol rtldsa_get_tag_protocol(struct dsa_switch *ds,
        /* The switch does not tag the frames, instead internally the header
         * structure for each packet is tagged accordingly.
         */
-       return DSA_TAG_PROTO_TRAILER;
+       return DSA_TAG_PROTO_RTL_OTTO;
 }
 
 static void rtldsa_vlan_set_pvid(struct rtl838x_switch_priv *priv,
diff --git a/target/linux/realtek/files-6.12/net/dsa/tag_rtl_otto.c b/target/linux/realtek/files-6.12/net/dsa/tag_rtl_otto.c
new file mode 100644 (file)
index 0000000..08a9915
--- /dev/null
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * net/dsa/tag_trailer.c - Trailer tag format handling
+ * Copyright (c) 2008-2009 Marvell Semiconductor
+ */
+
+#include <linux/etherdevice.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#include "tag.h"
+
+#define RTL_OTTO_NAME "rtl_otto"
+
+/*
+ * TODO: This driver was copied over from trailer tagging. It will be developed
+ * downstream in OpenWrt in conjunction with the Realtek Otto ethernet driver.
+ * For now rely on the old trailer handling and keep everything as is.
+ */
+
+static struct sk_buff *rtl_otto_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       struct dsa_port *dp = dsa_user_to_port(dev);
+       u8 *trailer;
+
+       trailer = skb_put(skb, 4);
+       trailer[0] = 0x80;
+       trailer[1] = dp->index;
+       trailer[2] = 0x10;
+       trailer[3] = 0x00;
+
+       return skb;
+}
+
+static struct sk_buff *rtl_otto_rcv(struct sk_buff *skb, struct net_device *dev)
+{
+       u8 *trailer;
+       int source_port;
+
+       if (skb_linearize(skb))
+               return NULL;
+
+       trailer = skb_tail_pointer(skb) - 4;
+
+       if (trailer[0] != 0x80 || (trailer[1] & 0x80) != 0x00 ||
+           (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
+               return NULL;
+
+       if (trailer[1] & 0x40)
+               skb->offload_fwd_mark = 1;
+
+       source_port = trailer[1] & 0x3f;
+
+       skb->dev = dsa_conduit_find_user(dev, 0, source_port);
+       if (!skb->dev)
+               return NULL;
+
+       if (pskb_trim_rcsum(skb, skb->len - 4))
+               return NULL;
+
+       return skb;
+}
+
+static const struct dsa_device_ops rtl_otto_netdev_ops = {
+       .name   = RTL_OTTO_NAME,
+       .proto  = DSA_TAG_PROTO_RTL_OTTO,
+       .xmit   = rtl_otto_xmit,
+       .rcv    = rtl_otto_rcv,
+       .needed_tailroom = 4,
+};
+
+MODULE_DESCRIPTION("DSA tag driver for Realtek Otto switches (RTL83xx/RTL93xx)");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL_OTTO, RTL_OTTO_NAME);
+
+module_dsa_tag_driver(rtl_otto_netdev_ops);
diff --git a/target/linux/realtek/patches-6.12/721-net-dsa-add-support-for-tag-rtl-otto.patch b/target/linux/realtek/patches-6.12/721-net-dsa-add-support-for-tag-rtl-otto.patch
new file mode 100644 (file)
index 0000000..7ad7122
--- /dev/null
@@ -0,0 +1,51 @@
+From: Markus Stockhausen <markus.stockhausen@gmx.de>
+Date: Sun, 1 Feb 2026 10:40:52 +0100
+Subject: realtek: net: dsa: add suport for tag rtl-otto
+
+This adds the rtl-otto tag feature for Realtek switches.
+
+Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
+
+--- a/net/dsa/Makefile
++++ b/net/dsa/Makefile
+@@ -35,6 +35,7 @@ obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca
+ obj-$(CONFIG_NET_DSA_TAG_RTL4_A) += tag_rtl4_a.o
+ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) += tag_rtl8_4.o
+ obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o
++obj-$(CONFIG_NET_DSA_TAG_RTL_OTTO) += tag_rtl_otto.o
+ obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o
+ obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
+ obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o
+--- a/net/dsa/Kconfig
++++ b/net/dsa/Kconfig
+@@ -163,6 +163,12 @@ config NET_DSA_TAG_LAN9303
+         Say Y or M if you want to enable support for tagging frames for the
+         SMSC/Microchip LAN9303 family of switches.
++config NET_DSA_TAG_RTL_OTTO
++      tristate "Tag driver for Realtek Otto switches (RTL83xx/RTL93xx)"
++      help
++        Say Y or M if you want to enable support for tagging frames for the
++        Realtek Otto family of switches.
++ 
+ config NET_DSA_TAG_SJA1105
+       tristate "Tag driver for NXP SJA1105 switches"
+       select PACKING
+--- a/include/net/dsa.h
++++ b/include/net/dsa.h
+@@ -55,6 +55,7 @@ struct tc_action;
+ #define DSA_TAG_PROTO_LAN937X_VALUE           27
+ #define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE     28
+ #define DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE   29
++#define DSA_TAG_PROTO_RTL_OTTO_VALUE          30
+ enum dsa_tag_protocol {
+       DSA_TAG_PROTO_NONE              = DSA_TAG_PROTO_NONE_VALUE,
+@@ -87,6 +88,7 @@ enum dsa_tag_protocol {
+       DSA_TAG_PROTO_RZN1_A5PSW        = DSA_TAG_PROTO_RZN1_A5PSW_VALUE,
+       DSA_TAG_PROTO_LAN937X           = DSA_TAG_PROTO_LAN937X_VALUE,
+       DSA_TAG_PROTO_VSC73XX_8021Q     = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE,
++      DSA_TAG_PROTO_RTL_OTTO          = DSA_TAG_PROTO_RTL_OTTO_VALUE,
+ };
+ struct dsa_switch;
diff --git a/target/linux/realtek/patches-6.12/722-net-dsa-add-rtl838x-support-for-tag-trailer.patch b/target/linux/realtek/patches-6.12/722-net-dsa-add-rtl838x-support-for-tag-trailer.patch
deleted file mode 100644 (file)
index 8f02f03..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-From 2b88563ee5aafd9571d965b7f2093a0f58d98a31 Mon Sep 17 00:00:00 2001
-From: John Crispin <john@phrozen.org>
-Date: Thu, 26 Nov 2020 12:02:21 +0100
-Subject: net: dsa: Add rtl838x support for tag trailer
-
-* rename the target to realtek
-* add refactored DSA driver
-* add latest gpio driver
-* lots of arch cleanups
-* new irq driver
-* additional boards
-
-Submitted-by: Bert Vermeulen <bert@biot.com>
-Submitted-by: Birger Koblitz <mail@birger-koblitz.de>
-Submitted-by: Sander Vanheule <sander@svanheule.net>
-Submitted-by: Bjørn Mork <bjorn@mork.no>
-Submitted-by: John Crispin <john@phrozen.org>
----
- net/dsa/tag_trailer.c                         | 16 +++++++++++++-
- 1 file changed, 17 insertions(+), 1 deletion(-)
-
---- a/net/dsa/tag_trailer.c
-+++ b/net/dsa/tag_trailer.c
-@@ -19,7 +19,12 @@ static struct sk_buff *trailer_xmit(stru
-       trailer = skb_put(skb, 4);
-       trailer[0] = 0x80;
-+
-+#ifdef CONFIG_NET_DSA_RTL83XX
-+      trailer[1] = dp->index;
-+#else
-       trailer[1] = 1 << dp->index;
-+#endif /* CONFIG_NET_DSA_RTL838X */
-       trailer[2] = 0x10;
-       trailer[3] = 0x00;
-@@ -35,12 +40,23 @@ static struct sk_buff *trailer_rcv(struc
-               return NULL;
-       trailer = skb_tail_pointer(skb) - 4;
-+
-+#ifdef CONFIG_NET_DSA_RTL83XX
-+      if (trailer[0] != 0x80 || (trailer[1] & 0x80) != 0x00 ||
-+          (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
-+              return NULL;
-+
-+      if (trailer[1] & 0x40)
-+              skb->offload_fwd_mark = 1;
-+
-+      source_port = trailer[1] & 0x3f;
-+#else
-       if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
-           (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
-               return NULL;
-       source_port = trailer[1] & 7;
--
-+#endif
-       skb->dev = dsa_conduit_find_user(dev, 0, source_port);
-       if (!skb->dev)
-               return NULL;
index fe55afc06514ce503fe9ee136b93babe6da69c95..70b8598e17d93bb1a0ffde9750c7878151ea63c8 100644 (file)
@@ -174,7 +174,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_INGRESS=y
 CONFIG_NET_RTL838X=y
index b71f3f170263b2448252d6d8fd15471266e38f34..2651a42d2e23791c4a166d35e113c5a37272adfe 100644 (file)
@@ -178,7 +178,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_FLOW_LIMIT=y
 CONFIG_NET_INGRESS=y
index 02d1463659844bb03ee196652dcccf5c842e33c4..ce58654015a84edb3183a52d55d7e6ac269f5ab0 100644 (file)
@@ -160,7 +160,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_FLOW_LIMIT=y
 CONFIG_NET_INGRESS=y
index 4365107528a9f04b7871ff8da0dccc6bbbf27106..8cd4db24d74105f57c65e07b20f33672768663ce 100644 (file)
@@ -166,7 +166,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_FLOW_LIMIT=y
 CONFIG_NET_INGRESS=y
index 622044c9ebdd01f7bb6d4386bfa945899348a94f..60f3a6067c881ae5c04957ff321f2d4852925d0c 100644 (file)
@@ -170,7 +170,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_FLOW_LIMIT=y
 CONFIG_NET_INGRESS=y
index 4357e0ee23a27baf349222bbf1791416779e0865..dfe46a968f234147111617969f4369827cb3fd41 100644 (file)
@@ -177,7 +177,7 @@ CONFIG_NET_DEVLINK=y
 CONFIG_NET_DSA=y
 CONFIG_NET_DSA_RTL83XX=y
 # CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD is not set
-CONFIG_NET_DSA_TAG_TRAILER=y
+CONFIG_NET_DSA_TAG_RTL_OTTO=y
 CONFIG_NET_EGRESS=y
 CONFIG_NET_FLOW_LIMIT=y
 CONFIG_NET_INGRESS=y