Skip to content

generic: rtl8365mb: add support for RTL8367S-VB - #25101

Draft
namiltd wants to merge 4 commits into
openwrt:mainfrom
namiltd:Realtek_DSA2
Draft

namiltd wants to merge 4 commits into
openwrt:mainfrom
namiltd:Realtek_DSA2

Conversation

@namiltd

@namiltd namiltd commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

This series (14 patches) extends the existing family C (RTL8365MB/RTL8367S/RTL8367SB/RTL8367RB-VB) driver with a new
family D branch. Family C's functional behaviour is unchanged.

Patches:

  • dt-bindings: net: dsa: realtek: add RTL8367S-VB
  • net: dsa: realtek: rtl8365mb: add chip family infrastructure
  • net: dsa: realtek: rtl8365mb: refactor forcemode handling
  • net: dsa: realtek: rtl8365mb: set speed for family D
  • net: dsa: realtek: rtl8365mb: set RGMII mode for family D
  • net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling
  • net: dsa: realtek: rtl8365mb: set and get VLAN 4k for family D
  • net: dsa: realtek: rtl8365mb: refactor PVID handling
  • net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D
  • net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support
  • net: dsa: realtek: rtl8365mb: refactor L2 MAC handling
  • net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
  • net: dsa: realtek: rtl8365mb: use PCP numbering on family D
  • net: dsa: realtek: rtl8365mb: add support for RTL8367S-VBs

@openwrt openwrt Bot added the kernel pull request/issue with Linux kernel related changes label Sep 9, 2026
@namiltd
namiltd marked this pull request as ready for review September 9, 2026 20:22

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • 2ba8190 "generic: rtl8365mb: add support for RTL8367S-VB" — the 8/8 paragraph states sds_lock serializes "the shared SDS_INDACS window and SDS_MISC register", but SDS_MISC is still accessed without it, in rtl8365mb_pcs_config() (the shared regmap_update_bits(), before the work is cancelled) and in rtl8365mb_phylink_mac_link_up(). Either lock those two sites or narrow the claim to SDS_INDACS plus the park/restore sequence.

Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit.


Generated by Claude Code

@namiltd
namiltd force-pushed the Realtek_DSA2 branch 2 times, most recently from 5f36b7d to 2985f8f Compare September 11, 2026 18:37
@namiltd
namiltd requested a review from openwrt-ai September 11, 2026 18:45

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit.


Generated by Claude Code

kuncy7 added a commit to kuncy7/openwrt-nss-edma that referenced this pull request Sep 13, 2026
The TP-Link Archer AX55 v1 carries an RTL8367S-VB, a family D chip the
upstream rtl8365mb driver does not know: it detects the chip, sets speed
and RGMII mode, reads and writes the VLAN 4K table and the PVID the family
D way, and brings up the SDS13 SerDes as a PCS with the re-latch the chip
needs. 930-01..08 are Mieczyslaw Nalewaj's series from openwrt/openwrt
PR openwrt#25101.

930-09 repeats the switch-side SerDes bring-up once the conduit link is
up: the switch end of the 2.5G trunk is configured about two seconds
before the IPQ5018 UNIPHY resets and recalibrates its own end, and the
trunk intermittently came up broken (bad FCS on every frame at the CPU
port, or no octets counted). Sent as openwrt/openwrt PR openwrt#25153; 17 boots
without a broken trunk on an AX55.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@namiltd
namiltd requested a review from openwrt-ai September 14, 2026 05:06

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

kuncy7 added a commit to kuncy7/openwrt-nss-edma that referenced this pull request Sep 16, 2026
The TP-Link Archer AX55 v1 carries an RTL8367S-VB, a family D chip the
upstream rtl8365mb driver does not know: it detects the chip, sets speed
and RGMII mode, reads and writes the VLAN 4K table and the PVID the family
D way, and brings up the SDS13 SerDes as a PCS with the re-latch the chip
needs. 930-01..08 are Mieczyslaw Nalewaj's series from openwrt/openwrt
PR openwrt#25101.

930-09 repeats the switch-side SerDes bring-up once the conduit link is
up: the switch end of the 2.5G trunk is configured about two seconds
before the IPQ5018 UNIPHY resets and recalibrates its own end, and the
trunk intermittently came up broken (bad FCS on every frame at the CPU
port, or no octets counted). Sent as openwrt/openwrt PR openwrt#25153; 17 boots
without a broken trunk on an AX55.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@gusfm

gusfm commented Sep 16, 2026

Copy link
Copy Markdown

@namiltd a review from the family D board this was measured on, a TP-Link
EX511 v2 (RTL8367S-VB, chip ID 0x6642, headerless CPU port over 1G SGMII to an
IPQ5018). I have been running an independent family D implementation of this
driver on it since 2026-09-10, with bridge VLAN filtering and per-port PVIDs,
and compared the two register for register. Most of it agrees. One thing does
not, and it is about what family D does differently from C rather than
about the code as such.

930-05: the family D VLAN4k entry is two words, not three.

On the RTL8367D the CVLAN table entry is two words. In the EX511's stock
qca-ssdk.ko, _dal_rtl8367d_setAsicVlan4kEntry() writes 0x0510 and
0x0511, then the address at 0x0501 and the command at 0x0500; nothing
goes to 0x0512. The layout it packs:

field family C (rtl8365mb_vlan.c today) family D (DAL)
member d0[7:0] + d2[2:0] d0[7:0]
untag d0[15:8] + d2[5:3] d0[15:8]
FID d1[3:0] d1[1:0]
IVL / SVL d1[14] d1[3], with d1[2] the S-VLAN check
priority, meter d1, d2 absent

There are no extension words because the die has eight ports.

930-05 keeps the three-word pack and adjusts FID and the IVL bit inside it, so
on family D the read still folds data[2] bits 2:0 and 5:3 into member and
untag bits 10:8, and the write still emits data[2]. That third read-data
word is not part of the entry on this die, so what lands in bits 10:8 is
whatever 0x0522 last held, and rtl8365mb_vlan_4k_port_set() is a
read-modify-write: every bridge join and leave reads the entry, flips one
port's bit and writes all of it back, including a third word the vendor
never writes. Nothing shows today because the driver only sets and clears
the port's own bit and compares nothing above bit 7, but anything that later
compares or iterates member masks inherits phantom ports, and the table
write is not the sequence the vendor uses.

I would give family D its own pack and unpack, two words with the fields
above. For reference, that is what
947 in kuncy7's tree
does, and it has been running on the EX511 with VLAN-aware bridges, tagged
and untagged members and PVIDs since 2026-09-10; take whatever is useful
from it.

I have not raised the 0x612F NCTL enable: that was a question on my side
and it was settled in kuncy7's tree, the re-latch in 930-08 is the part that
matters.

@namiltd

namiltd commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@gusfm I wrote these patches blindly, basing them on the rtl8367b driver with the help of other users and Claude AI, without even owning a router with that chip. I’d be happy to hand over my "work" to a more experienced user who can finish it and submit the results to the Linux upstream. Are you able to verify and make the necessary corrections to this code?

@gusfm

gusfm commented Sep 17, 2026

Copy link
Copy Markdown

@namiltd I'm in the same boat. My EX511 support was also mostly done with Claude. I rather not accept your offer because I am not a kernel developer. What I can do is test the code of the D family driver in my EX511 that uses it.

kuncy7 added a commit to kuncy7/openwrt-nss-edma that referenced this pull request Oct 10, 2026
930-01..09 were a copy of namiltd's RTL8367S-VB series from 2026-09-16
plus our openwrt#25153. Both moved on since. Take the current
series under its own numbers, so the next sync is a copy:

- 777-01..08 from openwrt#19644 (= openwrt#25101, f12e62e): the family D CVLAN
  entry is two words, not three (the old 930-05 read and wrote a third
  word that family D does not have); the SerDes re-latch keeps checking
  the link every 10 s after its 15 fast attempts instead of giving up;
  family D has 8 ports; sds_lock also covers the SDS_MISC access in
  pcs_get_state() and the link force on family C; the PVID rollback
  restores the frame filter too.
- 778 is openwrt#25153 as it is now, with family D kept out of the deferred
  bring-up, as agreed with namiltd. Only the dsa_switch_ops hunk is
  rebased onto our 762, which adds .port_enable next to it.

Tested on a TP-Link Archer AX55 v1 (RTL8367S, family C): 5 of 5 cold
boots, up to 10 minutes without power, each with the SerDes brought up
after eth0 came up, no FCS errors on the CPU port and traffic through
the trunk; 3 network restarts with the firmware nodes back each time;
routed Wi-Fi to the WAN at the usual rates, offloaded. Family D is not
tested here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LS3434

LS3434 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

@namiltd I included this PR in my build for TP-Link MX515v (IPQ5018, Realtek RTL8367S-VB switch, 2LAN, 1WAN) and it works perfectly. CPU to switch link is 1Gb. Some logs:

[    4.421786] rtl8365mb-mdio 90000.mdio-1:1d: found an RTL8367S-VB switch
[    4.656916] rtl8365mb-mdio 90000.mdio-1:1d: missing child interrupt-controller node
[    4.656968] rtl8365mb-mdio 90000.mdio-1:1d: no interrupt support
[    4.922880] rtl8365mb-mdio 90000.mdio-1:1d: configuring for fixed/sgmii link mode
[    4.933630] rtl8365mb-mdio 90000.mdio-1:1d: Link is Up - 1Gbps/Full - flow control off
[    4.944786] rtl8365mb-mdio 90000.mdio-1:1d wan (uninitialized): PHY [90000.mdio-1:1d:user_mii:00] driver [Generic PHY] (irq=POLL)
[    4.960775] rtl8365mb-mdio 90000.mdio-1:1d lan2 (uninitialized): PHY [90000.mdio-1:1d:user_mii:01] driver [Generic PHY] (irq=POLL)
[    4.976648] rtl8365mb-mdio 90000.mdio-1:1d lan1 (uninitialized): PHY [90000.mdio-1:1d:user_mii:02] driver [Generic PHY] (irq=POLL)
[    4.983571] DSA: tree 0 setup

[    7.858050] rtl8365mb-mdio 90000.mdio-1:1d lan1: configuring for phy/gmii link mode

[   24.822461] ipq5018-gmac-dwmac 39d00000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0
[   24.823676] ipq5018-gmac-dwmac 39d00000.ethernet eth0: No Safety Features support found
[   24.829690] ipq5018-gmac-dwmac 39d00000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   24.838044] ipq5018-gmac-dwmac 39d00000.ethernet eth0: registered PTP clock
[   24.846551] ipq5018-gmac-dwmac 39d00000.ethernet eth0: configuring for fixed/sgmii link mode
[   24.856963] ipq5018-gmac-dwmac 39d00000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off
[   24.870665] rtl8365mb-mdio 90000.mdio-1:1d lan1: configuring for phy/gmii link mode

[   24.878189] rtl8365mb-mdio 90000.mdio-1:1d lan1: rtl8365mb: VLAN 0 is reserved by this driver
[   24.911611] br-lan: port 1(lan1) entered blocking state
[   24.911663] br-lan: port 1(lan1) entered disabled state
[   24.915709] rtl8365mb-mdio 90000.mdio-1:1d lan1: entered allmulticast mode
[   24.920870] ipq5018-gmac-dwmac 39d00000.ethernet eth0: entered allmulticast mode
[   24.951350] rtl8365mb-mdio 90000.mdio-1:1d lan1: entered promiscuous mode
[   24.951427] ipq5018-gmac-dwmac 39d00000.ethernet eth0: entered promiscuous mode
daemon.notice: netifd: Interface 'lan' is enabled
daemon.notice: netifd: Interface 'lan' is setting up now
daemon.notice: netifd: Interface 'lan' is now up
[   24.980856] rtl8365mb-mdio 90000.mdio-1:1d lan2: configuring for phy/gmii link mode
[   24.982816] 8021q: adding VLAN 0 to HW filter on device lan2
[   24.987373] rtl8365mb-mdio 90000.mdio-1:1d lan2: rtl8365mb: VLAN 0 is reserved by this driver
[   25.031894] br-lan: port 2(lan2) entered blocking state
[   25.031971] br-lan: port 2(lan2) entered disabled state
[   25.036016] rtl8365mb-mdio 90000.mdio-1:1d lan2: entered allmulticast mode
[   25.058749] rtl8365mb-mdio 90000.mdio-1:1d lan2: entered promiscuous mode
daemon.notice: netifd: Interface 'loopback' is enabled
daemon.notice: netifd: Interface 'loopback' is setting up now
daemon.notice: netifd: Interface 'loopback' is now up
[   25.082631] rtl8365mb-mdio 90000.mdio-1:1d wan: configuring for phy/gmii link mode
[   25.084420] 8021q: adding VLAN 0 to HW filter on device wan
[   25.089141] rtl8365mb-mdio 90000.mdio-1:1d wan: rtl8365mb: VLAN 0 is reserved by this driver
daemon.notice: netifd: Interface 'wan' is enabled
daemon.notice: netifd: Interface 'wan6' is enabled
daemon.notice: netifd: Network device 'eth0' link is up
daemon.notice: netifd: Network device 'lo' link is up

[  175.759191] rtl8365mb-mdio 90000.mdio-1:1d lan1: Link is Up - 1Gbps/Full - flow control rx/tx

All ports are working, nice job making this work.

@namiltd

namiltd commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@LS3434 I am currently in the process of submitting this patch to the Linux upstream (https://lore.kernel.org/netdev/?q=rtl8365mb). The patch is currently at version 5: https://lore.kernel.org/netdev/[email protected]/ It would be great if you could use that version, test it, and report the test results.

@namiltd

namiltd commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@LS3434 The latest version is also available at: #19644

@namiltd

namiltd commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

@LS3434 Would you also be able to test v6 of the fixes?: pending-6.18.zip

@LS3434

LS3434 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@namiltd I will test them next week, i'm preparing a build for TP-Link NX510v, same specs as a MX515v, only modem is 5G instead of 4G.

@kuncy7

kuncy7 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

@namiltd a note on v6 from the family C side (Archer AX55 v1, RTL8367S on a 2500base-x trunk to an IPQ5018 GMAC).

v6 8/9 now adds rtl8365mb_conduit_state_change() and sds_cfg_lock itself, so 797 (bring the SerDes up once the conduit is up, #25153) no longer applies on top of it: same callback, same ops entry, and its pcs_config() split collides with the new locking. The rest of v6 leaves family C as it was: compared with v5 + 797 from #19644, the only family C change is the sds_cfg_lock guard in pcs_config(). So nothing in v6 itself breaks family C, but dropping 797 with it would bring back the cold-start trunk failure on the AX55 and the MR80X v2.

Here is 797 rebased onto v6 (below, pending-6.18). It keeps the v6 code for family D as is and adds to it:

  • one conduit_state_change() for both families: family C runs the held-back bring-up, family D starts the re-latch episode as in v6;
  • the deferral state under your sds_cfg_lock, so the separate sds_defer_lock is gone;
  • pcs_config() / pcs_link_up() split into their hardware halves as before;
  • pcs_disable() and teardown() also drop a pending bring-up.

On top of our tree (6.18.55, with the 802.1Q tagger patch in the ops table) v6 1-9 apply cleanly except the ops hunk of 8/9, the rebased 797 applies after them, and the driver builds without new warnings. On the AX55 with v6 and the rebased 797: 5 boots, 4 of them cold (30 s, 30 s, 5 min and 10 min without power) and two network restarts - every time the trunk came up at 2.5G with "SerDes brought up after eth0 link up" about 7.9 s into the boot, no FCS errors on the CPU port and traffic through it; LAN traffic through a VLAN-aware bridge (the client untagged on its port's PVID) and the host's own multicast out of a switch port both work.

Testing goes on here - more cold starts on the AX55 - and I will report if anything shows up.

797-net-dsa-realtek-rtl8365mb-bring-the-SerDes-up-once-the-conduit-is-up.patch (on v6)
From 9988ea19e4c5f1540596045fd8e326f003c4ba69 Mon Sep 17 00:00:00 2001
From: Stanislaw Pal <[email protected]>
Date: Sun, 20 Sep 2026 12:00:00 +0200
Subject: [PATCH] net: dsa: realtek: rtl8365mb: bring the SerDes up once the
 conduit is up

On the TP-Link Archer AX55 v1 (IPQ5018 + RTL8367S, CPU port on a
2500base-x fixed link) the trunk sometimes comes up broken after a cold
start: every frame the CPU sends reaches the switch CPU port with a bad
FCS, or the port counts no octets while the conduit keeps transmitting.
A reboot may or may not clear it: two soft reboots in a row have left it
dead here, with a power cycle needed to recover, while on another
occasion the second soft reboot was enough.
The same failure reproduces on the Mercusys MR80X v2 (same SoC and
switch): 2 of 12 boots at 2500base-x came up with the CPU port counting
nothing while eth0 transmitted.

The two ends of the trunk are configured in the wrong order: phylink
configures the switch end when the switch is set up, seconds before the
conduit MAC configures its own end, and on the IPQ5018 that step resets
and recalibrates the UNIPHY PLL. The vendor bootloader brings the SoC
end up first and the switch end afterwards.

Do the same: when the conduit behind the SerDes CPU port is not up at
pcs_config() time, hold the bring-up back and run it from
conduit_state_change() once DSA reports the conduit operational, which
is after its MAC and PCS are configured. Nothing needs the trunk before
then. The SerDes mux is parked at DISABLE before the mode is written, so
a bring-up on a mux that already holds the mode still produces the edge
the receiver latches on.

This is done only when the conduit is an IPQ5018 GMAC, the only SoC this
was seen on; other boards keep the current order.

The bring-up is held back once per boot. The UNIPHY resets and
recalibrates its PLL only when its interface mode changes, which on a
fixed link happens once, so a later conduit down/up does not repeat it.

Tested on TP-Link Archer AX55 v1: 5 boots without a single broken
trunk, three of them cold starts, the last two after ten hours and
overnight without power; an earlier version of the same logic ran 17
boots, 8 of them cold, with none broken, against 2 of 9 broken without
the change. On the Mercusys MR80X v2 (Johan Alvarado) this version gave
16 of 16 clean boots, against 2 of 12 broken without it; two earlier
revisions, one stacked on another pending rtl8365mb series and one on
its own, gave 16 of 16 and 17 of 17.

Tested-by: Johan Alvarado <[email protected]>
Signed-off-by: Stanislaw Pal <[email protected]>
[namiltd: rebase onto the family D series; family D keeps its own
 bring-up order and does not defer]
Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
---
 drivers/net/dsa/realtek/rtl8365mb_main.c | 227 +++++++++++++++++++++--
 1 file changed, 213 insertions(+), 14 deletions(-)

--- a/drivers/net/dsa/realtek/rtl8365mb_main.c
+++ b/drivers/net/dsa/realtek/rtl8365mb_main.c
@@ -989,6 +989,14 @@ struct rtl8365mb_port {
  * @sds_misc_target_val: SDS_MISC_CFG_MASK fields the re-latch work restores
  * @sds_relatch_armed: pcs_config() set up 2500base-x; the re-latch work may run
  * @sds_conduit_up: the CPU port conduit is admin and oper up
+ * @sds_defer_needed: the SerDes bring-up is held back until the conduit behind
+ *                    the SerDes CPU port is up, see
+ *                    rtl8365mb_sds_defer_needed() (family C)
+ * @sds_deferred: a bring-up requested by pcs_config() is pending
+ * @sds_link_deferred: pcs_link_up() was called while the bring-up was pending
+ * @sds_interface: interface mode of the pending pcs_config() request
+ * @sds_speed: speed of the pending pcs_link_up()
+ * @sds_duplex: duplex of the pending pcs_link_up()
  *
  * Private data for this driver.
  */
@@ -1017,6 +1025,12 @@ struct rtl8365mb {
 	u32 sds_misc_target_val;
 	bool sds_relatch_armed;
 	bool sds_conduit_up;
+	bool sds_defer_needed;
+	bool sds_deferred;
+	bool sds_link_deferred;
+	phy_interface_t sds_interface;
+	int sds_speed;
+	int sds_duplex;
 };
 
 #define pcs_to_rtl8365mb(_pcs) container_of((_pcs), struct rtl8365mb, pcs)
@@ -1558,28 +1572,30 @@ static int rtl8365mb_sds_relatch_restore(struct rtl8365mb *mb)
 	return ret;
 }
 
-static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
-				phy_interface_t interface,
-				const unsigned long *advertising,
-				bool permit_pause_to_mac)
+/* The hardware half of pcs_config(): tune and mux the SerDes for the
+ * interface mode, take it out of reset and clear the data path. It runs from
+ * rtl8365mb_pcs_config(), or from rtl8365mb_conduit_state_change() when the
+ * bring-up was held back, in both cases with sds_cfg_lock held.
+ */
+static int rtl8365mb_sds_config(struct rtl8365mb *mb, phy_interface_t interface)
 {
 	const struct rtl8365mb_jam_tbl_entry *sds_jam;
 	const int id = RTL8365MB_SDS_EXT_INTERFACE_ID;
-	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
 	struct realtek_priv *priv = mb->priv;
 	size_t sds_jam_size;
 	u32 misc_mask;
 	u32 misc_val;
 	u32 sds_mode;
 	u8 sds_index;
+	bool parked;
 	bool is_d;
 	u16 val;
 	int ret;
 	int i;
 
-	is_d = rtl8365mb_get_family(priv) == RTL8365MB_FAMILY_D;
+	lockdep_assert_held(&mb->sds_cfg_lock);
 
-	guard(mutex)(&mb->sds_cfg_lock);
+	is_d = rtl8365mb_get_family(priv) == RTL8365MB_FAMILY_D;
 
 	/* Cancel any in-flight re-latch edge before touching SDS_MISC: the
 	 * work parks SDS_MISC and restores the target value after a sleep, so
@@ -1672,6 +1688,24 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 		misc_val  = (sds_mode == RTL8365MB_EXT_PORT_MODE_SGMII) ?
 			    RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK :
 			    RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK;
+
+		/* Where the bring-up is held back, park the mux first: the
+		 * receiver latches on the DISABLE -> mode edge, so a bring-up
+		 * run on a mux that already holds the mode - the deferred one
+		 * after a first pcs_config() - would otherwise be a write that
+		 * update_bits skips, and produce no edge at all. Other boards
+		 * keep the plain update below.
+		 */
+		if (mb->sds_defer_needed) {
+			ret = regmap_update_bits_check(priv->map,
+						       RTL8365MB_SDS_MISC_REG,
+						       misc_mask, 0, &parked);
+			if (ret)
+				return ret;
+
+			if (parked)
+				usleep_range(20000, 21000);
+		}
 	}
 
 	ret = regmap_update_bits(priv->map, RTL8365MB_SDS_MISC_REG,
@@ -1751,6 +1785,134 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 	return 0;
 }
 
+/* The CPU port behind the SerDes external interface, or NULL when the SerDes
+ * is not a CPU port on this board - nothing to wait for then.
+ */
+static struct dsa_port *rtl8365mb_sds_cpu_port(struct rtl8365mb *mb)
+{
+	struct dsa_switch *ds = &mb->priv->ds;
+	int i;
+
+	for (i = 0; i < RTL8365MB_MAX_NUM_EXTINTS; i++) {
+		const struct rtl8365mb_extint *extint =
+			&mb->chip_info->extints[i];
+
+		/* Match the SerDes interface by what it can carry rather than
+		 * by its id: the id indexes the chip's digital interface, and
+		 * nothing ties the SerDes to a particular one.
+		 */
+		if (!(extint->supported_interfaces &
+		      (RTL8365MB_PHY_INTERFACE_MODE_SGMII |
+		       RTL8365MB_PHY_INTERFACE_MODE_HSGMII)))
+			continue;
+
+		if (!dsa_is_cpu_port(ds, extint->port))
+			return NULL;
+
+		return dsa_to_port(ds, extint->port);
+	}
+
+	return NULL;
+}
+
+/* Bring the family C SerDes up only once the conduit is up.
+ *
+ * phylink configures the switch end of a SerDes CPU port as soon as the
+ * switch is set up, seconds before the conduit MAC configures its own end.
+ * On an IPQ5018 conduit that later step resets the UNIPHY analog PLL and
+ * recalibrates it, and a switch receiver that latched on a far end which was
+ * not there yet sometimes comes out of it counting nothing or FCS errors
+ * only (TP-Link Archer AX55 v1 and Mercusys MR80X v2, both RTL8367S on a
+ * 2500base-x trunk). The vendor bootloader avoids this by bringing the SoC
+ * end up first and the switch end afterwards; this does the same. When the
+ * conduit is not up at pcs_config() time the bring-up is recorded and run
+ * from rtl8365mb_conduit_state_change() once DSA reports the conduit
+ * operational, which is after its MAC and PCS are configured. Nothing needs
+ * the trunk before then.
+ *
+ * This has only been seen with an IPQ5018 GMAC as the conduit, so the
+ * bring-up is held back only there; other boards keep the current order.
+ * Family D has its own answer to the far end coming up late, the re-latch
+ * work, which also starts from conduit_state_change().
+ */
+static bool rtl8365mb_sds_defer_needed(struct rtl8365mb *mb)
+{
+	struct dsa_port *dp;
+	struct net_device *conduit;
+
+	if (rtl8365mb_get_family(mb->priv) == RTL8365MB_FAMILY_D)
+		return false;
+
+	dp = rtl8365mb_sds_cpu_port(mb);
+	conduit = dp ? dp->conduit : NULL;
+
+	return conduit && conduit->dev.parent &&
+	       of_device_is_compatible(conduit->dev.parent->of_node,
+				       "qcom,ipq5018-gmac");
+}
+
+static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
+				phy_interface_t interface,
+				const unsigned long *advertising,
+				bool permit_pause_to_mac)
+{
+	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
+	struct dsa_port *dp;
+
+	guard(mutex)(&mb->sds_cfg_lock);
+
+	mb->sds_link_deferred = false;
+	dp = mb->sds_defer_needed ? rtl8365mb_sds_cpu_port(mb) : NULL;
+	/* Same predicate DSA uses for the operational flag that drives
+	 * conduit_state_change(), so the two can never disagree.
+	 */
+	if (dp && !dsa_port_conduit_is_operational(dp)) {
+		mb->sds_interface = interface;
+		mb->sds_deferred = true;
+		dev_dbg(mb->priv->dev, "SerDes bring-up held until %s is up\n",
+			dp->conduit->name);
+		return 0;
+	}
+
+	mb->sds_deferred = false;
+	return rtl8365mb_sds_config(mb, interface);
+}
+
+static void rtl8365mb_sds_link_up(struct rtl8365mb *mb, int speed, int duplex);
+
+/* The held back family C bring-up, run once the conduit is up. Called with
+ * sds_cfg_lock held.
+ */
+static void rtl8365mb_sds_deferred_bringup(struct rtl8365mb *mb,
+					   const struct net_device *conduit)
+{
+	struct realtek_priv *priv = mb->priv;
+	struct dsa_port *dp;
+	int ret;
+
+	dp = rtl8365mb_sds_cpu_port(mb);
+	if (!mb->sds_deferred || !dp || dp->conduit != conduit)
+		return;
+
+	/* On failure the bring-up stays pending, so it is tried again the
+	 * next time the conduit comes up.
+	 */
+	ret = rtl8365mb_sds_config(mb, mb->sds_interface);
+	if (ret) {
+		dev_err(priv->dev, "SerDes bring-up after %s link up failed: %pe\n",
+			conduit->name, ERR_PTR(ret));
+		return;
+	}
+
+	if (mb->sds_link_deferred)
+		rtl8365mb_sds_link_up(mb, mb->sds_speed, mb->sds_duplex);
+	mb->sds_deferred = false;
+	mb->sds_link_deferred = false;
+
+	dev_info(priv->dev, "SerDes brought up after %s link up\n",
+		 conduit->name);
+}
+
 static void rtl8365mb_conduit_state_change(struct dsa_switch *ds,
 					   const struct net_device *conduit,
 					   bool operational)
@@ -1758,8 +1920,14 @@ static void rtl8365mb_conduit_state_change(struct dsa_switch *ds,
 	struct realtek_priv *priv = ds->priv;
 	struct rtl8365mb *mb = priv->chip_data;
 
-	if (rtl8365mb_get_family(priv) != RTL8365MB_FAMILY_D)
+	if (rtl8365mb_get_family(priv) != RTL8365MB_FAMILY_D) {
+		if (!operational || !mb->sds_defer_needed)
+			return;
+
+		guard(mutex)(&mb->sds_cfg_lock);
+		rtl8365mb_sds_deferred_bringup(mb, conduit);
 		return;
+	}
 
 	guard(mutex)(&mb->sds_cfg_lock);
 
@@ -2006,12 +2174,11 @@ static void rtl8365mb_pcs_get_state(struct phylink_pcs *pcs,
 	}
 }
 
-static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs,
-				  unsigned int neg_mode,
-				  phy_interface_t interface, int speed,
-				  int duplex)
+/* The hardware half of pcs_link_up(): force the SerDes link parameters.
+ * Held back together with rtl8365mb_sds_config() while the conduit is not up.
+ */
+static void rtl8365mb_sds_link_up(struct rtl8365mb *mb, int speed, int duplex)
 {
-	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
 	struct realtek_priv *priv = mb->priv;
 	u32 mask = RTL8365MB_SDS_MISC_SGMII_FDUP_MASK |
 		   RTL8365MB_SDS_MISC_SGMII_LINK_MASK |
@@ -2060,12 +2227,38 @@ static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs,
 	}
 }
 
+static void rtl8365mb_pcs_link_up(struct phylink_pcs *pcs,
+				  unsigned int neg_mode,
+				  phy_interface_t interface, int speed,
+				  int duplex)
+{
+	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
+
+	if (mb->sds_defer_needed) {
+		guard(mutex)(&mb->sds_cfg_lock);
+
+		if (mb->sds_deferred) {
+			mb->sds_speed = speed;
+			mb->sds_duplex = duplex;
+			mb->sds_link_deferred = true;
+			return;
+		}
+	}
+
+	rtl8365mb_sds_link_up(mb, speed, duplex);
+}
+
 static void rtl8365mb_pcs_disable(struct phylink_pcs *pcs)
 {
 	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
 
-	if (rtl8365mb_get_family(mb->priv) != RTL8365MB_FAMILY_D)
+	if (rtl8365mb_get_family(mb->priv) != RTL8365MB_FAMILY_D) {
+		guard(mutex)(&mb->sds_cfg_lock);
+
+		mb->sds_deferred = false;
+		mb->sds_link_deferred = false;
 		return;
+	}
 
 	guard(mutex)(&mb->sds_cfg_lock);
 
@@ -4138,6 +4331,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	 * (in-band mode with autonegotiation disabled).
 	 */
 	mb->pcs.poll = true;
+	mb->sds_defer_needed = rtl8365mb_sds_defer_needed(mb);
 
 	ret = rtl8365mb_reset_chip(priv);
 	if (ret) {
@@ -4336,6 +4530,11 @@ static void rtl8365mb_teardown(struct dsa_switch *ds)
 
 		WRITE_ONCE(mb->sds_relatch_armed, false);
 		cancel_delayed_work_sync(&mb->sds_relatch);
+	} else {
+		guard(mutex)(&mb->sds_cfg_lock);
+
+		mb->sds_deferred = false;
+		mb->sds_link_deferred = false;
 	}
 
 	rtl8365mb_stats_teardown(priv);

@namiltd

namiltd commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

PR #19644 updated to v6.

@namiltd

namiltd commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

The patches are currently on the upstream Linux mailing list here: https://lore.kernel.org/netdev/[email protected]/
You can submit test results and any comments directly to this list. This will assist the community in reviewing the patches and may help expedite their approval. You download the relevant email from the list to your computer in raw format, import it into your email program, and reply to all. The email must be in plain text format only.

@namiltd

namiltd commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Since I do not own a router equipped with this integrated circuit, I am unable to perform testing of the software submitted to the Linux kernel’s main code tree (the net-next branch - https://lore.kernel.org/netdev/[email protected]). Consequently, I have left the v6 patch set in an unfinished state; anyone with the appropriate hardware and a suitable test environment is welcome to take it over, refine the L2/FDB layer support and other shared code segments, and continue the work. I encourage others to use, modify, or resubmit any parts of this code.

@namiltd
namiltd marked this pull request as draft October 20, 2026 19:00

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit.


Generated by Claude Code

@kuncy7

kuncy7 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

@namiltd the follow-up I promised on the AX55: with v6 and 797 rebased onto it, 6/6 boots (5 of them cold, the last after a night without power) and 2/2 network restarts came up with the 2.5G trunk working. The board has run that code in every build since. The Tested-by for family C went to the v6 thread on netdev on 17 October: https://lore.kernel.org/netdev/[email protected]/ The v6 in this PR now (53c6cfb) is the code I tested, and the 797 port in #19644 (11ee3ee) is the one the AX55 runs.

@namiltd

namiltd commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

I would like to ask everyone who is able to test the v9 patch from #19644 to provide feedback, including a "Tested-by: full name " line, so that I can forward this information to the upstream Linux net-next tree.

@namiltd
namiltd force-pushed the Realtek_DSA2 branch 2 times, most recently from 5693c4e to 49e08d8 Compare November 12, 2026 18:00
@openwrt openwrt Bot added target/qualcommax pull request/issue for qualcommax target target/realtek pull request/issue for realtek target labels Nov 22, 2026
@namiltd
namiltd force-pushed the Realtek_DSA2 branch 3 times, most recently from 64c3676 to b6ee28b Compare November 26, 2026 20:48

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 new commits.


Generated by Claude Code

Comment on lines 490 to 491
/* Every channel of the instance calls this with its own phylink state
* mutex, so nothing else keeps two of them out of the sequence below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this no longer holds now that qca_uniphy_pcs_preconfig() calls the function from gmac probe, where no phylink state mutex is held. Name the probe-time caller, so it is clear that uniphy->lock is the only serialization.

Suggested change
/* Every channel of the instance calls this with its own phylink state
* mutex, so nothing else keeps two of them out of the sequence below.
/* Channels call this under their own phylink state mutex, or from
* probe with none, so only this lock keeps them out of the sequence.

Generated by Claude Code

From e3f21ffe950d0c604fff32b31bae6d07c98e0fc7 Mon Sep 17 00:00:00 2001
From: Mieczyslaw Nalewaj <[email protected]>
Date: Sat, 21 Nov 2026 19:10:09 +0100
Subject: [PATCH net-next v14 13/15] net: dsa: realtek: rtl8365mb: refactor QoS priority handling

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the PR body says "This series (14 patches)" and its list leaves out this patch, but commit a71d3c8 says 15 patches and lists it. Update the PR body to match the commit.


Generated by Claude Code

namiltd and others added 4 commits November 28, 2026 10:29
Add ingress QoS offload for the RTL8365MB switch through the dcbnl app
interface: a per-port default priority, PCP trust and DSCP trust. The
mapping helpers go to net/core/ieee8021q_helpers.c so other drivers
can share them.

Two changes are visible to users. The driver now rejects a devicetree
port that the chip does not have. With a default priority set, an
untagged frame that leaves a VLAN-tagged port carries that priority as
its PCP.

Tested on an RTL8365MB-VC with eight queues.

ETS scheduling and CPU-tag pre-classification will follow in separate
series.

Signed-off-by: Oleksij Rempel <[email protected]>
Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
This series (15 patches) extends the existing family C
(RTL8365MB/RTL8367S/RTL8367SB/RTL8367RB-VB) driver with a new
family D branch. Family C's functional behaviour is unchanged.

Patches:
 - dt-bindings: net: dsa: realtek: add RTL8367S-VB
 - net: dsa: realtek: rtl8365mb: add chip family infrastructure
 - net: dsa: realtek: rtl8365mb: refactor forcemode handling
 - net: dsa: realtek: rtl8365mb: set speed for family D
 - net: dsa: realtek: rtl8365mb: set RGMII mode for family D
 - net: dsa: realtek: rtl8365mb: refactor VLAN 4k handling
 - net: dsa: realtek: rtl8365mb: set and get VLAN 4k for family D
 - net: dsa: realtek: rtl8365mb: refactor PVID handling
 - net: dsa: realtek: rtl8365mb: use raw VID for PVID on family D
 - net: dsa: realtek: rtl8365mb: add family D SDS13 PCS support
 - net: dsa: realtek: rtl8365mb: refactor L2 MAC handling
 - net: dsa: realtek: rtl8365mb: make L2/LUT access work on family D
 - net: dsa: realtek: rtl8365mb: refactor QoS priority handling
 - net: dsa: realtek: rtl8365mb: use PCP numbering on family D
 - net: dsa: realtek: rtl8365mb: add support for RTL8367S-VB

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
Refresh the rtl8365mb hunk to match the current 6.18 tree.

No functional change.

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
- phylink configures the PCS only at ndo_open, until then the UNIPHY
  keeps the bootloader mode
- MR80X v2 u-boot hands over in SGMII (MODE_CTRL 0x421, MISC2 0x70)
  while the board runs the trunk at 2500base-x
- the RTL8367S CPU port brings its SerDes up at DSA setup, 2 s before
  the first open, and trains its receiver against the wrong line rate
- CPU port dead or FCS errors on 18 of 51 boots, 0 of 32 with the mode
  sequence run from pcs_init
- add qca_uniphy_pcs_preconfig() and call it from dwmac-ipq5018 with
  the DT phy-mode; pcs_config at open then hits the mode cache

Signed-off-by: Johan Alvarado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel pull request/issue with Linux kernel related changes target/qualcommax pull request/issue for qualcommax target target/realtek pull request/issue for realtek target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants