Skip to contentSkip to conversation

net: dsa: tag_rtl8_4: add support for RTL9607C tag variant

PATCH In review Rustam Adilov 4 participants 5 messages Nov 19 – Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: tag_rtl8_4: add support for RTL9607C tag variant

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 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(-)
include/net/dsa.h +2 -0
index 09f3043d57f0..6f86c7625304 100644
@@ -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;
net/dsa/tag_rtl8_4.c +192 -1

237 lines not on this page · raw message

Signature · 1 line
2.56.1
#1 lore raw
Quoted 11 lines · Rustam Adilov

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

Quoted 10 lines

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

maintainer
#2 lore raw
Quoted 8 lines · Alvin Šipraga
Quoted 7 lines · Rustam Adilov

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.

Quoted 8 lines
Quoted 4 lines

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

#3 lore raw
In reply to Alvin Šipraga

Hello!

Quoted 8 lines · Alvin Šipraga
Quoted 7 lines · Rustam Adilov

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.

Quoted 8 lines
Quoted 4 lines

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

Quoted 2 lines

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.

Quoted 6 lines

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

Quoted 4 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 5 lines

[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

#4 lore raw
In reply to Rustam Adilov
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] This patch adds a new DSA tag protocol, DSA_TAG_PROTO_RTL8_4AP (value 38), and the tagger rtl8_4ap_netdev_ops.
- [Medium] rtl8_4ap_read_tag() (net/dsa/tag_rtl8_4.c, lines 296-306) uses a deny-list to decide whether the switch already forwarded a received…
- [Low] The patch makes tag_rtl8_4.c cover a second chip family, but some existing documentation was not updated and the new comment contradicts…
- [Low] The comment and the code in net/dsa/tag_rtl8_4.c disagree on what REASON means for the rtl8_4ap tagger.

--

net: dsa: tag_rtl8_4: add support for RTL9607C tag variant

This commit adds a new DSA tag protocol, rtl8_4ap (DSA_TAG_PROTO_RTL8_4AP), for the variant of the 8 byte Realtek protocol 4 tag used by the switch embedded in RTL9607C SoCs. The tag sits after the source MAC, as with rtl8_4, but the fields are laid out differently and the TX and RX layouts differ from each other.

include/net/dsa.h struct tc_action; · line 66

Quoted 9 lines
include/net/dsa.h +1 -0
index 09f3043d57f06..6f86c76253043 100644
@@ -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

[Severity: Medium]
Which switch driver is expected to select DSA_TAG_PROTO_RTL8_4AP?

The only in-tree user of the protocol 4 taggers is rtl8365mb. It only returns the two existing values:

drivers/net/dsa/realtek/rtl8365mb_main.c:rtl8365mb_get_tag_protocol() {
    ...
	if (cpu->position == RTL8365MB_CPU_POS_BEFORE_CRC)
		return DSA_TAG_PROTO_RTL8_4T;

	return DSA_TAG_PROTO_RTL8_4;
}

Likewise, rtl8365mb_change_tag_protocol() only accepts DSA_TAG_PROTO_RTL8_4 and DSA_TAG_PROTO_RTL8_4T.

So nothing in mainline can reach rtl8_4ap_tag_xmit() or rtl8_4ap_tag_rcv(). The patch still permanently reserves protocol ID 38 and adds the module aliases "id-38" and "rtl8_4ap".

The commit message says:

Add basic necessities for this cpu tag variant to function.

However, the RTL9607C switch driver that would use this tagger is not part of the submission. The only testing mentioned was on an out-of-tree OpenWrt 6.18 kernel.

Could this be resubmitted together with the switch driver that consumes it?

[ ... ]

Quoted 5 lines
net/dsa/tag_rtl8_4.c +0 -0
index 4da3beebef75e..c934c232d330e 100644
@@ -74,6 +74,54 @@

[ ... ]

Quoted 8 lines

+ * 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|

[Severity: Low]
This isn't a bug, but the CPU->switch diagram calls the forwarding port mask TX_PORTMASK_LOW and TX_PORTMASK_HIGH. The glossary earlier in the file says "RX (CPU->switch): forwarding port mask", and the code names the same fields RTL8_4AP_RX_LO and RTL8_4AP_RX_HI. Should the diagram say RX to match?

The new macros also mix two prefixes: RTL9607C_RX_HI_MSK sits next to RTL8_4AP_RX_LO and RTL8_4AP_RX_HI.

A few existing descriptions were not updated for the new variant. The file header still says:

* NOTE: Currently only supports protocol "4" found in the RTL8365MB, hence
* named tag_rtl8_4.

The tag placement text only mentions "rtl8_4" and "rtl8_4t". The NET_DSA_TAG_RTL8_4 help text in net/dsa/Kconfig only mentions the RTL8365MB-VC:

switches with 8 byte protocol 4 tags, such as the Realtek RTL8365MB-VC.

Could these be updated to cover RTL9607C and rtl8_4ap?

[ ... ]

net/dsa/tag_rtl8_4.c line 153

Quoted 9 lines
net/dsa/tag_rtl8_4.c +5 -0
@@ -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

[Severity: Low]
The only REASON documentation in this file is the shared table:

 *    REASON     | reason for forwarding packet to CPU
 *               | 0: packet was forwarded or flooded to CPU
 *               | 80: packet was trapped to CPU

The new RTL9607C section says only bytes 4-7 differ on switch->CPU. That suggests REASON means the same thing on this SoC.

However, rtl8_4ap_read_tag() treats 203, 215, 219, 220 and 227 as traps, and none of these codes appear in the comment. It also treats 80 as forwarded, which is the opposite of the documented meaning.

The new FBI description ("Only relevant when REASON is FB (aka < 64)") also implies that 0..63 are flow based reasons. That conflicts with "0: packet was forwarded or flooded to CPU".

Could the RTL9607C REASON codes be documented, and the existing table marked as RTL8365MB specific?

[ ... ]

Quoted 1 line
net/dsa/tag_rtl8_4.c +0 -0
@@ -153,6 +252,84 @@ static struct sk_buff *rtl8_4t_tag_xmit(struct sk_buff *skb,

[ ... ]

Quoted 2 lines
net/dsa/tag_rtl8_4.c +2 -0
+	/* Parse REASON */
+	reason = FIELD_GET(RTL8_4_REASON, ntohs(tag16[1]));

[ ... ]

net/dsa/tag_rtl8_4.c static struct sk_buff *rtl8_4t_tag_xmit(struct sk_buff *skb, · line 306

Quoted 11 lines
net/dsa/tag_rtl8_4.c +11 -0
+	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;
+	}

[Severity: Medium]
Is a deny-list safe here? Every REASON value except these five ends up in dsa_default_offload_fwd_mark():

net/dsa/tag.h:dsa_default_offload_fwd_mark() {
	struct dsa_port *dp = dsa_user_to_port(skb->dev);

	skb->offload_fwd_mark = !!(dp->bridge);
}

That covers the flow based reasons (< 64) from the FBI description, code 80, and any other trap reason the RTL9607C can emit.

Suppose the switch traps a frame to the CPU on a bridged port for one of those unlisted reasons. Wouldn't the bridge then treat the frame as already forwarded in hardware, and skip software forwarding to the other ports in the same hardware domain? That frame would be silently lost.

Whether this happens depends on which reason codes the hardware emits and how the switch driver configures trapping. Neither is visible in the tree.

Would it be safer to set offload_fwd_mark only for reasons that are known to mean the switch already forwarded or flooded the frame?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119165129.26693-1-adilov%40disroot.org