Просмотр исходного кода

realtek: dsa: convert trailer tag hack into separate module

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 <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/21815
Signed-off-by: Robert Marko <[email protected]>
Markus Stockhausen 1 неделя назад
Родитель
Сommit
336ffdf631

+ 1 - 1
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/Kconfig

@@ -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.
 

+ 1 - 1
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c

@@ -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,

+ 76 - 0
target/linux/realtek/files-6.12/net/dsa/tag_rtl_otto.c

@@ -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);

+ 51 - 0
target/linux/realtek/patches-6.12/721-net-dsa-add-support-for-tag-rtl-otto.patch

@@ -0,0 +1,51 @@
+From: Markus Stockhausen <[email protected]>
+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 <[email protected]>
+
+--- 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;

+ 0 - 61
target/linux/realtek/patches-6.12/722-net-dsa-add-rtl838x-support-for-tag-trailer.patch

@@ -1,61 +0,0 @@
-From 2b88563ee5aafd9571d965b7f2093a0f58d98a31 Mon Sep 17 00:00:00 2001
-From: John Crispin <[email protected]>
-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 <[email protected]>
-Submitted-by: Birger Koblitz <[email protected]>
-Submitted-by: Sander Vanheule <[email protected]>
-Submitted-by: Bjørn Mork <[email protected]>
-Submitted-by: John Crispin <[email protected]>
----
- 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;

+ 1 - 1
target/linux/realtek/rtl838x/config-6.12

@@ -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

+ 1 - 1
target/linux/realtek/rtl839x/config-6.12

@@ -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

+ 1 - 1
target/linux/realtek/rtl930x/config-6.12

@@ -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

+ 1 - 1
target/linux/realtek/rtl930x_nand/config-6.12

@@ -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

+ 1 - 1
target/linux/realtek/rtl931x/config-6.12

@@ -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

+ 1 - 1
target/linux/realtek/rtl931x_nand/config-6.12

@@ -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