All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant
@ 2026-11-19 16:50 Rustam Adilov
  2026-11-20 12:09 ` Alvin Šipraga
  0 siblings, 1 reply; 4+ messages in thread
From: Rustam Adilov @ 2026-11-19 16:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Alvin Šipraga,
	Linus Walleij, netdev, linux-kernel
  Cc: Rustam Adilov, Taiga Ogawa

The RTL9607C family of SoCs have an embdedded switch that utilizes
the same Realtek CPU Tag protocol 4 with 8 bytes in size but have
a bit different of a layout. And that layout is also different for
TX versus RX sides and introduces new fields not seen by RTL8_4.

Add basic necessities for this cpu tag variant to function.

Tested-by: Taiga Ogawa <zectaiga@gmail.com>
Signed-off-by: Rustam Adilov <adilov@disroot.org>
---
Tested on OpenWrt with 6.18 kernel version [1].

The RTL8_4AP name was mostly chosen because Realtek gave the RTL9607C
family of SoCs a codename "ApolloPro" in their SDK, hence "AP" part.
Originally it was named RTL8_4_RTL9607C but that feels weird.

[1] https://github.com/openwrt/openwrt/pull/26496
---
 include/net/dsa.h    |   2 +
 net/dsa/tag_rtl8_4.c | 193 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 09f3043d57f0..6f86c7625304 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -63,6 +63,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_MT7628_VALUE		35
 #define DSA_TAG_PROTO_KS8995_VALUE		36
 #define DSA_TAG_PROTO_LAN9645X_VALUE		37
+#define DSA_TAG_PROTO_RTL8_4AP_VALUE		38
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -103,6 +104,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_MT7628		= DSA_TAG_PROTO_MT7628_VALUE,
 	DSA_TAG_PROTO_KS8995		= DSA_TAG_PROTO_KS8995_VALUE,
 	DSA_TAG_PROTO_LAN9645X		= DSA_TAG_PROTO_LAN9645X_VALUE,
+	DSA_TAG_PROTO_RTL8_4AP		= DSA_TAG_PROTO_RTL8_4AP_VALUE,
 };
 
 struct dsa_switch;
diff --git a/net/dsa/tag_rtl8_4.c b/net/dsa/tag_rtl8_4.c
index 4da3beebef75..c934c232d330 100644
--- a/net/dsa/tag_rtl8_4.c
+++ b/net/dsa/tag_rtl8_4.c
@@ -74,6 +74,54 @@
  * software or hardware. To avoid this issue, if the checksum is still pending,
  * this tagger checksums the packet in software before adding the tag.
  *
+ * This 8 byte switch tag can also be found on RTL9607C family of SoCs with
+ * identical protocol "4", but the format is slightly different.
+ *
+ * On switch->CPU the bytes 4-7 look like this:
+ *
+ *  |-----------------------------------+-----------------------------------|
+ *  | (3) |     (3)    |    (5)         |     (2)     |  (1)  |  (1) |  (4) |
+ *  | PRI |   EXTSPA  OR PON_STREAM_ID  |PON_STREAM_ID|L3ROUTE| ORIG | PORT |
+ *  |-----------------------------------+-----------------------------------|
+ *  |    (1)   |           (15-bit)     /      (6-bit)                      |
+ *  |    FBI   |      FLOW_BASED_HASH   /   DST_PORT_MASK                   |
+ *  |-----------------------------------+-----------------------------------|
+ *
+ * On CPU->Switch however the byte 3 is also different:
+ *
+ *  |-----------------------------------+-----------------------------------|
+ *  |              (8-bit)              |             (8-bit)               |
+ *  |          Protocol [0x04]          |         TX_PORTMASK_LOW           |
+ *  |-----------------------------------+-----------------------------------|
+ *  |     (3-bit)    |(1)|   (1)  | (3) |(1) |(1)|   (1)   |(1) |(2)| (1) |1|
+ *  |TX_PORTMASK_HIGH| X | PRI_EN | PRI |KEEP| X |LEARN_DIS|PSEL| X |DIRTX|X|
+ *  |-----------------------------------+-----------------------------------|
+ *  | (3-bit)|    (2-bit)   |     (4-bit)    |           (7-bit)            |
+ *  | EXTSPA |   PPPOE_ACT  |    PPPOE_IDX   |        PON_STREAM_ID         |
+ *  |-----------------------------------+-----------------------------------|
+ *
+ * With the following descriptions for new fields:
+ *
+ *    field           | description
+ *   -----------------+-------------
+ *    EXTSPA          | Source Extension Port. Relevant when port is CPU (9, 10, 7).
+ *    PON_STREAM_ID   | PON Stream ID (GPON) or LLID index (EPON). Relevant when
+ *                    | port is PON (5)
+ *    L3ROUTE         | "This frame is an intended routed frames" as per docs
+ *    ORIG            | The received frame by NIC is the original packet's format
+ *                    | before switch lookup and switch didn't do any modifications
+ *    FBI             | Flow Based I...? Only relevant when REASON is FB (aka < 64)
+ *    FLOW_BASED_HASH | Flow Based Hash Index.
+ *    DST_PORT_MASK   | Switch lookup destination port mask. bit 0: CPU, bit 1-5 are
+ *                    | extension ports 0~4.
+ *    PSEL            | PON stream id (GPON) / LLID index(EPON) selection.
+ *    DIRTX           | Direct TX, whatever that means? Used to be called L34KEEP.
+ *    PPPOE_ACT       | Egress action for PPPoE header whose Ether Type = 0x8864.
+ *                    | 0: intact, 1: Add PPPoE header, 2: Remove PPPoE header,
+ *                    | 3: remarking PPPoE switch TX mac action.
+ *    PPPOE_IDX       | PPPoE index pointed to an entry of the PPPoE table in the
+ *                    | switch. Switch TX-MAC look PPPoE table up by this index to
+ *                    | get PPPoE session ID.
  */
 
 #include <linux/bitfield.h>
@@ -84,11 +132,12 @@
 
 /* Protocols supported:
  *
- * 0x04 = RTL8365MB DSA protocol
+ * 0x04 = RTL8365MB / RTL9607C (aka ApolloPro) DSA protocol
  */
 
 #define RTL8_4_NAME			"rtl8_4"
 #define RTL8_4T_NAME			"rtl8_4t"
+#define RTL8_4AP_NAME			"rtl8_4ap"
 
 #define RTL8_4_TAG_LEN			8
 
@@ -97,13 +146,63 @@
 #define RTL8_4_REASON			GENMASK(7, 0)
 #define   RTL8_4_REASON_FORWARD		0
 #define   RTL8_4_REASON_TRAP		80
+#define   RTL8_4AP_REASON_BCAST_TRAP	203
+#define   RTL8_4AP_REASON_RESV_TRAP	215
+#define   RTL8_4AP_REASON_IGMP		219
+#define   RTL8_4AP_REASON_RMA		220
+#define   RTL8_4AP_REASON_ACL		227
+
+#define RTL8_4AP_RX_LO			GENMASK(7, 0)
+#define RTL8_4AP_RX_HI			GENMASK(15, 13)
+#define RTL9607C_RX_HI_MSK		GENMASK(10, 8)
 
+#define RTL8_4AP_DIRTX			BIT(1)
 #define RTL8_4_LEARN_DIS		BIT(5)
 #define RTL8_4_KEEP			BIT(7)
 
 #define RTL8_4_TX			GENMASK(3, 0)
 #define RTL8_4_RX			GENMASK(10, 0)
 
+static void rtl8_4ap_write_tag(struct sk_buff *skb, struct net_device *dev,
+			       void *tag)
+{
+	u16 pmask = dsa_xmit_port_mask(skb, dev);
+	__be16 tag16[RTL8_4_TAG_LEN / 2];
+	u16 pmask_low, pmask_high;
+
+	/* Set Realtek EtherType */
+	tag16[0] = htons(ETH_P_REALTEK);
+
+	pmask_low = FIELD_GET(RTL8_4AP_RX_LO, pmask);
+	/* Set Protocol; set RX (CPU->switch) low forwarding port mask */
+	tag16[1] = htons(FIELD_PREP(RTL8_4_PROTOCOL, RTL8_4_PROTOCOL_RTL8365MB) |
+			 FIELD_PREP(RTL8_4AP_RX_LO, pmask_low));
+
+	pmask_high = FIELD_GET(RTL9607C_RX_HI_MSK, pmask);
+	/* set high forwarding port mask, KEEP, LEARN_DIS and DIRTX */
+	tag16[2] = htons(FIELD_PREP(RTL8_4AP_RX_HI, pmask_high) |
+			 FIELD_PREP(RTL8_4_LEARN_DIS, 1) |
+			 FIELD_PREP(RTL8_4_KEEP, 1) |
+			 FIELD_PREP(RTL8_4AP_DIRTX, 1));
+
+	/* Zero EXTSPA, PPPOE_ACT/IDX and PON_STREAM_ID */
+	tag16[3] = 0;
+
+	memcpy(tag, tag16, RTL8_4_TAG_LEN);
+}
+
+static struct sk_buff *rtl8_4ap_tag_xmit(struct sk_buff *skb,
+					 struct net_device *dev)
+{
+	skb_push(skb, RTL8_4_TAG_LEN);
+
+	dsa_alloc_etype_header(skb, RTL8_4_TAG_LEN);
+
+	rtl8_4ap_write_tag(skb, dev, dsa_etype_header_pos_tx(skb));
+
+	return skb;
+}
+
 static void rtl8_4_write_tag(struct sk_buff *skb, struct net_device *dev,
 			     void *tag)
 {
@@ -153,6 +252,84 @@ static struct sk_buff *rtl8_4t_tag_xmit(struct sk_buff *skb,
 	return skb;
 }
 
+static int rtl8_4ap_read_tag(struct sk_buff *skb, struct net_device *dev,
+			     void *tag)
+{
+	__be16 tag16[RTL8_4_TAG_LEN / 2];
+	u16 etype;
+	u8 reason;
+	u8 proto;
+	u8 port;
+
+	memcpy(tag16, tag, RTL8_4_TAG_LEN);
+
+	/* Parse Realtek EtherType */
+	etype = ntohs(tag16[0]);
+	if (unlikely(etype != ETH_P_REALTEK)) {
+		dev_warn_ratelimited(&dev->dev,
+				     "non-realtek ethertype 0x%04x\n", etype);
+		return -EPROTO;
+	}
+
+	/* Parse Protocol */
+	proto = FIELD_GET(RTL8_4_PROTOCOL, ntohs(tag16[1]));
+	if (unlikely(proto != RTL8_4_PROTOCOL_RTL8365MB)) {
+		dev_warn_ratelimited(&dev->dev,
+				     "unknown realtek protocol 0x%02x\n",
+				     proto);
+		return -EPROTO;
+	}
+
+	/* Parse REASON */
+	reason = FIELD_GET(RTL8_4_REASON, ntohs(tag16[1]));
+
+	/* Parse TX (switch->CPU) */
+	port = FIELD_GET(RTL8_4_TX, ntohs(tag16[2]));
+	skb->dev = dsa_conduit_find_user(dev, 0, port);
+	if (!skb->dev) {
+		dev_warn_ratelimited(&dev->dev,
+				     "could not find user for port %d\n",
+				     port);
+		return -ENOENT;
+	}
+
+	switch (reason) {
+	case RTL8_4AP_REASON_BCAST_TRAP:
+	case RTL8_4AP_REASON_RESV_TRAP:
+	case RTL8_4AP_REASON_IGMP:
+	case RTL8_4AP_REASON_RMA:
+	case RTL8_4AP_REASON_ACL:
+		break;
+	default:
+		dsa_default_offload_fwd_mark(skb);
+		break;
+	}
+
+	return 0;
+}
+
+static struct sk_buff *rtl8_4ap_tag_rcv(struct sk_buff *skb,
+					struct net_device *dev)
+{
+	if (unlikely(!pskb_may_pull(skb, RTL8_4_TAG_LEN))) {
+		kfree_skb(skb);
+		return NULL;
+	}
+
+	if (unlikely(rtl8_4ap_read_tag(skb, dev,
+				       dsa_etype_header_pos_rx(skb)))) {
+		kfree_skb(skb);
+		return NULL;
+	}
+
+	/* Remove tag and recalculate checksum */
+	skb_pull_rcsum(skb, RTL8_4_TAG_LEN);
+
+	dsa_strip_etype_header(skb, RTL8_4_TAG_LEN);
+
+	return skb;
+}
+
 static int rtl8_4_read_tag(struct sk_buff *skb, struct net_device *dev,
 			   void *tag)
 {
@@ -268,9 +445,23 @@ DSA_TAG_DRIVER(rtl8_4t_netdev_ops);
 
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL8_4T, RTL8_4T_NAME);
 
+/* Ethertype RTL9607C version */
+static const struct dsa_device_ops rtl8_4ap_netdev_ops = {
+	.name = "rtl8_4ap",
+	.proto = DSA_TAG_PROTO_RTL8_4AP,
+	.xmit = rtl8_4ap_tag_xmit,
+	.rcv = rtl8_4ap_tag_rcv,
+	.needed_headroom = RTL8_4_TAG_LEN,
+};
+
+DSA_TAG_DRIVER(rtl8_4ap_netdev_ops);
+
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_RTL8_4AP, RTL8_4AP_NAME);
+
 static struct dsa_tag_driver *dsa_tag_drivers[] = {
 	&DSA_TAG_DRIVER_NAME(rtl8_4_netdev_ops),
 	&DSA_TAG_DRIVER_NAME(rtl8_4t_netdev_ops),
+	&DSA_TAG_DRIVER_NAME(rtl8_4ap_netdev_ops),
 };
 module_dsa_tag_drivers(dsa_tag_drivers);
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant
  2026-11-19 16:50 [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Rustam Adilov
@ 2026-11-20 12:09 ` Alvin Šipraga
  2026-11-20 13:10   ` Andrew Lunn
  2026-11-20 14:47   ` Rustam Adilov
  0 siblings, 2 replies; 4+ messages in thread
From: Alvin Šipraga @ 2026-11-20 12:09 UTC (permalink / raw)
  To: Rustam Adilov
  Cc: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Linus Walleij, netdev,
	linux-kernel, Taiga Ogawa

On Thu, Nov 19, 2026 at 09:50:51PM +0500, Rustam Adilov wrote:
> The RTL9607C family of SoCs have an embdedded switch that utilizes
> the same Realtek CPU Tag protocol 4 with 8 bytes in size but have
> a bit different of a layout. And that layout is also different for
> TX versus RX sides and introduces new fields not seen by RTL8_4.
> 
> Add basic necessities for this cpu tag variant to function.
> 
> Tested-by: Taiga Ogawa <zectaiga@gmail.com>
> Signed-off-by: Rustam Adilov <adilov@disroot.org>
> ---
> Tested on OpenWrt with 6.18 kernel version [1].

Mainline doesn't have the requisite DSA driver to make use of this
protocol. Andrew, is it normal to accept tag protocol drivers without
the corresponding DSA driver?

I can see that the OpenWRT kernel has a DSA driver using it. Why not
submit that together with this? Otherwise it is kind of dead code IMO.

As a side note, it's unfortunate that Realtek recycles
EtherType/protocol ID values for seemingly different formats. At first I
thought this should be its own file/module, but I can see why you put it
here. My one concern would be whether the semantics for the common
fields are actually the same for both protocols? If not then maybe it's
better to separate them after all to avoid confusion.

> 
> The RTL8_4AP name was mostly chosen because Realtek gave the RTL9607C
> family of SoCs a codename "ApolloPro" in their SDK, hence "AP" part.
> Originally it was named RTL8_4_RTL9607C but that feels weird.
> 
> [1] https://github.com/openwrt/openwrt/pull/26496
> ---
>  include/net/dsa.h    |   2 +
>  net/dsa/tag_rtl8_4.c | 193 ++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 194 insertions(+), 1 deletion(-)

Kind regards,
Alvin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant
  2026-11-20 12:09 ` Alvin Šipraga
@ 2026-11-20 13:10   ` Andrew Lunn
  2026-11-20 14:47   ` Rustam Adilov
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2026-11-20 13:10 UTC (permalink / raw)
  To: Alvin Šipraga
  Cc: Rustam Adilov, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Linus Walleij, netdev,
	linux-kernel, Taiga Ogawa

On Fri, Nov 20, 2026 at 01:09:42PM +0100, Alvin Šipraga wrote:
> On Thu, Nov 19, 2026 at 09:50:51PM +0500, Rustam Adilov wrote:
> > The RTL9607C family of SoCs have an embdedded switch that utilizes
> > the same Realtek CPU Tag protocol 4 with 8 bytes in size but have
> > a bit different of a layout. And that layout is also different for
> > TX versus RX sides and introduces new fields not seen by RTL8_4.
> > 
> > Add basic necessities for this cpu tag variant to function.
> > 
> > Tested-by: Taiga Ogawa <zectaiga@gmail.com>
> > Signed-off-by: Rustam Adilov <adilov@disroot.org>
> > ---
> > Tested on OpenWrt with 6.18 kernel version [1].
> 
> Mainline doesn't have the requisite DSA driver to make use of this
> protocol. Andrew, is it normal to accept tag protocol drivers without
> the corresponding DSA driver?

At minimum, i would like to know the DSA driver is on the way. It
could be posted as an RFC. Best would be to make it a patch series,
the tag driver and a minimal DSA driver. That would be normal.

	Andrew

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant
  2026-11-20 12:09 ` Alvin Šipraga
  2026-11-20 13:10   ` Andrew Lunn
@ 2026-11-20 14:47   ` Rustam Adilov
  1 sibling, 0 replies; 4+ messages in thread
From: Rustam Adilov @ 2026-11-20 14:47 UTC (permalink / raw)
  To: Alvin Šipraga
  Cc: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Linus Walleij, netdev,
	linux-kernel, Taiga Ogawa

Hello!
On 2026-11-20 12:09, Alvin Šipraga wrote:
> On Thu, Nov 19, 2026 at 09:50:51PM +0500, Rustam Adilov wrote:
>> The RTL9607C family of SoCs have an embdedded switch that utilizes
>> the same Realtek CPU Tag protocol 4 with 8 bytes in size but have
>> a bit different of a layout. And that layout is also different for
>> TX versus RX sides and introduces new fields not seen by RTL8_4.
>> 
>> Add basic necessities for this cpu tag variant to function.
>> 
>> Tested-by: Taiga Ogawa <zectaiga@gmail.com>
>> Signed-off-by: Rustam Adilov <adilov@disroot.org>
>> ---
>> Tested on OpenWrt with 6.18 kernel version [1].
> 
> Mainline doesn't have the requisite DSA driver to make use of this
> protocol. Andrew, is it normal to accept tag protocol drivers without
> the corresponding DSA driver?

I suppose that is fair. I guess that also means i need to hold on to
the PHY support patches until then too?

> I can see that the OpenWRT kernel has a DSA driver using it. Why not
> submit that together with this? Otherwise it is kind of dead code IMO.

Yeah but right now it is not upstream ready yet. Ideally i would like it to
merge with rtl8365mb dsa driver cause by all accounts the embedded switch in
RTL9607C is very much like rtl8365mb but connected over MMIO. So that is my
overall plan.

I am already working on making the downstream dsa driver follow the rtl8365mb
in every case, mdio [1], irq [2], mdb plus vlan [3] but it is kinda messy as
VLAN side is very much like family D which is still being worked so nothing
concrete yet... and the table part is currently being provided by downstream
otto-table driver but we could just as well copy rtl8365mb_table in process.

After then introduce something like realtek-mmio (similar to realtek-mdio
and realtek-smi) and bam, we can straight up share the rtl83xx code :)

But maybe i should really jump straight to it and not slowly converting
the downstream dsa first (which wouldn't really be relevant anyway?).
If it turns that i do need DSA for this be also accepted then maybe.

> As a side note, it's unfortunate that Realtek recycles
> EtherType/protocol ID values for seemingly different formats. At first I
> thought this should be its own file/module, but I can see why you put it
> here. My one concern would be whether the semantics for the common
> fields are actually the same for both protocols? If not then maybe it's
> better to separate them after all to avoid confusion.

They do share the same semantics except reason part as its numbering seems
to be a bit different, 80 is reserved, 0 is normal forward. More documented
by the RTL9607C CPU NIC Application Note at [4] and the hwnat driver [5]

Anyways, thanks for review! I partially also wanted to announce our presence
to rtl8365mb folks by this patch as we may share the space soon :)

[1] https://github.com/openwrt/openwrt/pull/26779
[2] https://github.com/openwrt/openwrt/pull/26593
[3] https://github.com/openwrt/openwrt/pull/26415
[4] https://github.com/jameywine/realtek-doc/blob/main/datasheets/RTL9607C%20CPU%20NIC%20Application%20Note.pdf
[5] https://github.com/jameywine/GPL-for-GP3000/blob/main/linux-5.10.x/drivers/net/ethernet/realtek/rtl86900/FleetConntrackDriver/include/rtk_fc_mgrTRx.h#L540

>> The RTL8_4AP name was mostly chosen because Realtek gave the RTL9607C
>> family of SoCs a codename "ApolloPro" in their SDK, hence "AP" part.
>> Originally it was named RTL8_4_RTL9607C but that feels weird.
>> 
>> [1] https://github.com/openwrt/openwrt/pull/26496
>> ---
>>  include/net/dsa.h    |   2 +
>>  net/dsa/tag_rtl8_4.c | 193 ++++++++++++++++++++++++++++++++++++++++++-
>>  2 files changed, 194 insertions(+), 1 deletion(-)
> 
> Kind regards,
> Alvin

Best,
Rustam

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-20 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 16:50 [PATCH net-next] net: dsa: tag_rtl8_4: add support for RTL9607C tag variant Rustam Adilov
2026-11-20 12:09 ` Alvin Šipraga
2026-11-20 13:10   ` Andrew Lunn
2026-11-20 14:47   ` Rustam Adilov

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.