Skip to content

generic: rtl8365mb: bring the SerDes up once the conduit is up - #25153

Open
kuncy7 wants to merge 1 commit into
openwrt:mainfrom
kuncy7:ax55-lateinit-main
Open

kuncy7 wants to merge 1 commit into
openwrt:mainfrom
kuncy7:ax55-lateinit-main

Conversation

@kuncy7

@kuncy7 kuncy7 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The merged TP-Link Archer AX55 v1 support (8ac63a1) lists a known issue: the wired network is sometimes
dead after boot. Two forms were measured on the switch CPU port (ethtool -S eth0 | grep s00_p06_):

  • every frame from the CPU arrives with a bad FCS (dot3StatsFCSErrors climbs), or
  • the CPU port counts no octets at all while the conduit keeps transmitting.

A reboot may or may not clear it: two soft reboots in a row have left the trunk dead, needing a power cycle,
while on another occasion the second soft reboot was enough. The failure is in current snapshots.

It is not specific to one unit: @c127dev reproduced it on a Mercusys MR80X v2 (same IPQ5018 + RTL8367S,
2500base-x trunk) in 2 of 12 boots, and not at all in 38 boots at sgmii.

Cause

The switch end of the trunk is configured when phylink brings up the DSA CPU port, seconds before the
conduit MAC configures its own end and the IPQ5018 UNIPHY resets and recalibrates the PLL. The vendor
bootloader sets up the UNIPHY first and only then resets and configures the switch.

Change

One pending patch for 6.18, 797, on plain main. When the conduit behind the SerDes CPU port is not up at
pcs_config() time, the switch-side bring-up is recorded and run from conduit_state_change() once DSA
reports the conduit operational, which is after its MAC and PCS are configured; pcs_link_up() parameters
are held back the same way. The SerDes mux is parked at DISABLE before the mode is written, so a bring-up
on a mux already in the mode still produces the edge the receiver latches on. This is done only when the
conduit is an IPQ5018 GMAC (qcom,ipq5018-gmac), the only SoC this was seen on; the MediaTek boards that
also run rtl8365mb over a 2500base-x CPU port keep their current order. No timer, no polling.

Testing

Bad boot = CPU port counts FCS errors or no octets while the conduit transmits.

board image boots bad
Archer AX55 v1 main without this change 9 2
Archer AX55 v1 this change (standalone and the earlier stacked version) 5 0
Archer AX55 v1 earlier version of the same logic 17 0
Mercusys MR80X v2 (@c127dev) main without this change, 2500base-x 12 2
Mercusys MR80X v2 (@c127dev) this version (70b248530b; later pushes only add non-functional cleanups) 16 0
Mercusys MR80X v2 (@c127dev) earlier revision, stacked on #25101 16 0
Mercusys MR80X v2 (@c127dev) earlier revision, standalone 17 0

On both boards the deferred bring-up runs 43-46 ms after the conduit link comes up, on every boot.

Upstream status

This is not sent to netdev yet. The deferral is enabled only for a qcom,ipq5018-gmac conduit, and that glue
driver (dwmac-ipq5018.c) and the UNIPHY PCS driver it uses are themselves OpenWrt-only
(target/linux/qualcommax/files/). Upstream the condition would never be true and the failure cannot be
reproduced there. The patch will be submitted together with, or right after, those drivers.

History

This PR first sat on top of #25101 as 930-09, at @namiltd's request, to avoid a textual conflict in the same
file. The change itself does not depend on the family D series - it gates on the conduit SoC, not on the
chip family - and that series is still being reworked while this failure ships in snapshots, so the patch
now stands on plain main. Whichever lands second needs a small rebase; I am happy to do it on this side.
An earlier version repeated the bring-up from a delayed work a second after the conduit reported carrier;
this one moves it to the point where DSA reports the conduit operational instead.

🤖 Generated with Claude Code

@openwrt openwrt Bot added the kernel pull request/issue with Linux kernel related changes label Sep 13, 2026
@namiltd

namiltd commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Could you apply your changes after #25101 (patch number the next one as well)? I’d like to avoid a race to apply fixes.

@kuncy7

kuncy7 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Sure, no race intended. I've rebased it on top of #25101 as 930-09-net-dsa-realtek-rtl8365mb-repeat-the-SerDes-bring-up-once-the-conduit-link-is-up.patch (6.18 only, qualcommax is the only user) and pushed the branch with your commit underneath, so this PR now depends on #25101.

The change itself is the same: the only differences from the 797 version are context, plus dropping the workqueue.h include and the mb declaration in teardown() that your series already adds. Family D is not affected, since rtl8365mb_pcs_link_up() returns before the work is armed, and the repeated rtl8365mb_pcs_config() takes sds_lock on its own.

Comment on lines +136 to +138
+ rtl8365mb_pcs_link_up(&mb->pcs, mb->serdes_reinit_neg_mode,
+ mb->serdes_reinit_interface, mb->serdes_reinit_speed,
+ mb->serdes_reinit_duplex);

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.

rtl8365mb_pcs_link_up() is the one RTL8365MB_SDS_MISC_REG writer that 930-08 left outside sds_lock — its regmap_update_bits() is unlocked, while the read-modify-write on the same register in mac_link_up()`` now takes it. Calling it from this work is what first makes the two concurrent, so a pause-bit update can be lost. Wrap that update_bits in `sds_lock` as well (the PR comment only covers `rtl8365mb_pcs_config()`).


Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

Comment on lines +67 to +76
+ if (!mb->serdes_reinit_armed) {
+ mb->serdes_reinit_armed = true;
+ mb->serdes_reinit_neg_mode = neg_mode;
+ mb->serdes_reinit_interface = interface;
+ mb->serdes_reinit_speed = speed;
+ mb->serdes_reinit_duplex = duplex;
+ mb->serdes_reinit_waited = 0;
+ mb->serdes_reinit_settling = false;
+ schedule_delayed_work(&mb->serdes_reinit_work, 0);
+ }

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.

The link parameters are stashed only on the arming call, but the work fires at least 1.2 s later; any pcs_link_up() in between (link flap, renegotiated speed) leaves the replay forcing stale speed/duplex. Stash on every call and keep the one-shot guard only around the scheduling.

Suggested change
+ if (!mb->serdes_reinit_armed) {
+ mb->serdes_reinit_armed = true;
+ mb->serdes_reinit_neg_mode = neg_mode;
+ mb->serdes_reinit_interface = interface;
+ mb->serdes_reinit_speed = speed;
+ mb->serdes_reinit_duplex = duplex;
+ mb->serdes_reinit_waited = 0;
+ mb->serdes_reinit_settling = false;
+ schedule_delayed_work(&mb->serdes_reinit_work, 0);
+ }
+ mb->serdes_reinit_neg_mode = neg_mode;
+ mb->serdes_reinit_interface = interface;
+ mb->serdes_reinit_speed = speed;
+ mb->serdes_reinit_duplex = duplex;
+ if (!mb->serdes_reinit_armed) {
+ mb->serdes_reinit_armed = true;
+ mb->serdes_reinit_waited = 0;
+ mb->serdes_reinit_settling = false;
+ schedule_delayed_work(&mb->serdes_reinit_work, 0);
+ }

Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

Comment on lines +79 to +88
+/* The switch side of a SerDes CPU port is configured when phylink brings the
+ * CPU port up, which on some boards happens well before the conduit MAC has
+ * configured its own end of the link. On an IPQ5018 the UNIPHY resets and
+ * recalibrates its PLL at that point, about two seconds after the switch
+ * SerDes was set up, and the switch receiver sometimes comes out of it
+ * counting nothing or FCS errors only. A second bring-up clears that. The
+ * vendor bootloader avoids it by configuring the SoC end first and the
+ * switch afterwards. Wait for the conduit link, let it settle and run the
+ * bring-up once more.
+ */

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.

This arms for every family-C SerDes CPU port, not only IPQ5018: mt7622-buffalo-wsr-2533dhp2.dts:93, mt7622-elecom-wrc-2533gent.dts, mt7622-totolink-a8000ru.dts and mt7981b-mercusys-mr85x-common.dtsi all drive rtl8365mb over a 2500base-x CPU port and mediatek is on the same 6.18 kernel, so they get an extra SerDes reset and link bounce ~1.2 s after the conduit comes up. The PR comment says qualcommax is the only user — is the unconditional arming intended, or should it be gated (DT property, or the conduit/SoC that actually needs it)?


Generated by Claude Code

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.

solved by gating the arming on an IPQ5018 GMAC conduit, thanks


Generated by Claude Code

Comment on lines +89 to +91
+#define RTL8365MB_SERDES_REINIT_POLL_MS 200
+#define RTL8365MB_SERDES_REINIT_SETTLE_MS 1000
+#define RTL8365MB_SERDES_REINIT_TIMEOUT_MS 30000

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: 930-08 keeps its work constants in the register/constant block near the top of the file (RTL8365MB_D_SDS_RELATCH_TRIES/_INTERVAL_MS) and names the struct fields sds_relatch*; this adds defines mid-file and a second serdes_reinit_* prefix (lines 47-54) for the same SerDes machinery. Move these up with the other defines and settle on one prefix.


Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

+ mb->serdes_reinit_duplex = duplex;
+ mb->serdes_reinit_waited = 0;
+ mb->serdes_reinit_settling = false;
+ schedule_delayed_work(&mb->serdes_reinit_work, 0);

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 sibling relatch work in 930-08 queues on system_power_efficient_wq; this polls every 200 ms for up to 30 s on the default system_wq. Use queue_delayed_work(system_power_efficient_wq, ...) here and at the two reschedules on lines 117 and 123.


Generated by Claude Code

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.

fixed, thanks


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

kuncy7 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all five points were valid. Updated 930-09:

  • The SDS_MISC update in rtl8365mb_pcs_link_up() now takes sds_lock, so the work can no longer race the pause bits written from mac_link_up().
  • The link parameters are stored on every pcs_link_up(); only the scheduling is one-shot.
  • The work is armed only when the conduit is an IPQ5018 GMAC (qcom,ipq5018-gmac). The MediaTek boards that run rtl8365mb over a 2500base-x CPU port keep their current behaviour. My earlier "qualcommax is the only user" was wrong: 6.18 is the only kernel qualcommax needs, but it is not the only target using this driver path.
  • The constants moved up next to RTL8365MB_D_SDS_RELATCH_*, and everything uses one sds_reinit_* prefix.
  • The work is queued on system_power_efficient_wq, like the relatch work in 930-08.

Retested on the AX55 v1: the v2 build boots clean. The repeated bring-up runs 1.0 s after the conduit link comes up, so the IPQ5018 check matches, and the CPU port shows no FCS errors while WAN is up. The previous version of the same logic had 17 clean boots out of 17, 8 of them cold starts.

The branch now sits on the current head of #25101 (8240e4d2ed).

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]>
Comment on lines +179 to +184
+ dsa_switch_for_each_cpu_port(dp, &priv->ds) {
+ if (dp->conduit && dp->conduit->dev.parent &&
+ of_device_is_compatible(dp->conduit->dev.parent->of_node,
+ "qcom,ipq5018-gmac"))
+ return true;
+ }

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.

qcom,ipq5018-gmac only exists in OpenWrt's own ipq5018-ess.dtsi:3;`` a grep of v6.18.52 finds it in no upstream DT, binding or driver match table, so a pending-* patch keyed on it is not submittable as-is. Would a property on the switch/CPU-port node express this better than matching the conduit's SoC compatible?


Generated by Claude Code

Comment on lines +161 to +171
+ ret = rtl8365mb_pcs_config(&mb->pcs, mb->sds_reinit_neg_mode,
+ mb->sds_reinit_interface, NULL, false);
+ if (ret) {
+ dev_err(priv->dev, "failed to repeat SerDes bring-up: %pe\n",
+ ERR_PTR(ret));
+ return;
+ }
+
+ rtl8365mb_pcs_link_up(&mb->pcs, mb->sds_reinit_neg_mode,
+ mb->sds_reinit_interface, mb->sds_reinit_speed,
+ mb->sds_reinit_duplex);

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.

sds_lock is acquired and released inside each rtl8365mb_sds_write()`` / rtl8365mb_sds_read(), so it serializes single register accesses, not a whole bring-up sequence. phylink runs `pcs_config()`/`pcs_link_up()` under its own state mutex, which this work does not hold, so a CPU-port link event arriving while the replay runs interleaves two bring-up sequences on the same SerDes. Is that ruled out in practice, or should the replay be serialized against phylink (e.g. under `rtnl_lock()`)?


Generated by Claude Code

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.

solved by dropping the work entirely — the bring-up now runs under sds_defer_lock, thanks


Generated by Claude Code

@kuncy7 kuncy7 changed the title generic: rtl8365mb: repeat the SerDes bring-up once the conduit link is up generic: rtl8365mb: bring the SerDes up once the conduit is up Sep 18, 2026
@kuncy7

kuncy7 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Rewritten, and both open questions from the last review are answered by the rewrite rather than argued with.

Serialization. There is no work any more. The bring-up now runs either from pcs_config() itself, when the conduit is already up, or from conduit_state_change(), which DSA calls from its netdev notifier under rtnl. Both paths hold sds_defer_lock across the whole sequence, so two bring-ups cannot interleave on the same SerDes, and there is no timer and no polling left.

qcom,ipq5018-gmac. Deliberate, and I would rather keep it here. This is an OpenWrt pending-* patch and the compatible is the one the tree's own ipq5018-ess.dtsi uses, so it resolves on every board that can hit this. The alternative is to change the bring-up order for every family C board with a SerDes CPU port, including the four MediaTek boards, which nobody has tested. If this goes to netdev the gate has to be expressed differently - a DT property on the switch or CPU port node is the obvious candidate - and I will raise it there rather than guess now.

What else changed. The failure is an ordering problem: phylink configures the switch end when the switch is set up, seconds before the conduit MAC configures its own end and the IPQ5018 resets and recalibrates the UNIPHY PLL. So instead of repeating the bring-up afterwards, the patch holds it back until DSA reports the conduit operational, which is the order the vendor bootloader uses. The mux is parked at DISABLE before the mode is written, so a bring-up on a mux already in the mode still produces the edge the receiver latches on.

Testing. 4 boots on this version with no broken trunk: one after a sysupgrade and three cold starts, the last two after ten hours and overnight without power. The bring-up ran 43-44 ms after the conduit link came up in every one of them, with no FCS errors on the CPU port. Restarting the interfaces left the trunk clean too. The earlier version of the same logic had 17 clean boots, 8 of them cold; without the change 2 of 9 boots were broken.

The branch now sits on the current head of #25101 (681b7966f1).

@openwrt openwrt Bot added the target/qualcommax pull request/issue for qualcommax target label Sep 18, 2026
@namiltd

namiltd commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Synchronize generic: rtl8365mb: added RTL8367S-VB support because there have been some code changes.

@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

  • ff362b2b "generic: rtl8365mb: bring the SerDes up once the conduit is up" — the message says the change is done "only when the conduit is an IPQ5018 GMAC ... other boards keep the current order", but the DISABLE park plus 20 ms settle added to the family C branch of pcs_config() runs on every family C board, IPQ5018 or not. State that the park is unconditional on family C.

Generated by Claude Code

+
+ ret = rtl8365mb_sds_config(mb, mb->sds_neg_mode, mb->sds_interface);
+ if (!ret && mb->sds_link_deferred)
+ rtl8365mb_sds_link_up(mb, mb->sds_speed, mb->sds_duplex);

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.

rtl8365mb_sds_link_up() still does its regmap_update_bits() on RTL8365MB_SDS_MISC_REG without sds_lock, and calling it from here — netdev notifier, under rtnl — makes it concurrent with the locked read-modify-write of the pause bits in rtl8365mb_phylink_mac_link_up(),`` which runs from phylink's resolve work. Until now both were on the phylink path and serialized by it, so either update can now be lost. Wrap that update_bits in `sds_lock` as well.


Generated by Claude Code

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.

solved by splitting off #25101 — there is no sds_lock on plain main, so the competing writer is gone, thanks


Generated by Claude Code

+ bool sds_defer_needed;
+ bool sds_deferred;
+ bool sds_link_deferred;
+ unsigned int sds_neg_mode;

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: neg_mode is not read anywhere in the old rtl8365mb_pcs_config() body that became rtl8365mb_sds_config(), so this field only stores a value nothing consumes. Drop the field and the neg_mode parameter of rtl8365mb_sds_config().


Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

@c127dev

c127dev commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Tested patch 930-09-net-dsa-realtek-rtl8365mb-bring-the-SerDes-up-once-the-conduit-is-up.patch‎ using a Mercusys MR80X v2 (RTL8367S).

Noticed 1 of 8 boots failed while using HSGMII, and your patch fixed it. (16/16 booted correctly)

What about isolating the patch as a separate series? It works for the whole driver rather than only family D, since it gates on the conduit being an IPQ5018 GMAC and not on the chip family.

@kuncy7

kuncy7 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

@c127dev That is the first independent reproduction of this on another board, and the first confirmation of the fix outside my own unit - thank you for running it. 1 of 8 against 16 of 16 is a much better case than anything I could make on my own.

Two things.

May I carry a Tested-by: ... from you on the patch? If yes, please tell me the name and address you want in the tag, and which base you tested on (kernel version and whether the family D series from #25101 was underneath), so the commit message describes your run accurately rather than approximately.

And yes to your suggestion: I am splitting it out. It only ever sat on top of #25101 because that series touches the same lines and @namiltd asked me to stack it to avoid a race. But the change itself is family-agnostic - it gates on the conduit being an IPQ5018 GMAC, as you noticed - and the dependency has become the main cost here: that series is still in draft and has been rewritten several times, while this failure is in today's snapshots. So the patch goes to main on its own and whoever lands second rebases.

@c127dev

c127dev commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Tested-by: Johan Alvarado [email protected]

Board: Mercusys MR80X v2 (IPQ5018 + RTL8367S, non-VB), CPU port at 2500base-x on both gmac1 and the switch port, kernel 6.18.52.

Two runs, both of this PR's current 930-09 (ff362b2):

  1. Whole series as posted, generic: rtl8365mb: add support for RTL8367S-VB #25101 underneath (681b796): 16/16 boots clean.
  2. 930-09 alone, rebased to apply without generic: rtl8365mb: add support for RTL8367S-VB #25101: 17/17 boots clean.

Without the patch, at 2500base-x: 2 of 12 boots came up with the trunk dead - eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors, link reporting 2.5 Gbps. (My earlier "1/8" was the first run only, a second run of 4 added one more failure)

At sgmii on the same board the failure did not reproduce in 38 sampled boots.

The deferred bring-up fired on every boot, 43-45 ms after the conduit:

[ 6.623124] eth0: Link is Up - 2.5Gbps/Full
[ 6.666778] rtl8365mb-mdio 90000.mdio-1:1d: SerDes brought up after eth0 link up

One caveat for the split: my standalone rebase drops mb->sds_lock, since that mutex comes from 930-08 and with no family D relatch work there is no competing writer in my tree. If your standalone version keeps a lock around the SDS_MISC updates - pcs_link_up() and mac_link_up() both read-modify-write that register, then it is not quite what I ran. Post the split and I will rerun it as posted and confirm the tag against that version.

c127dev added a commit to c127dev/openwrt that referenced this pull request Sep 19, 2026
Hardware:
  SoC:    Qualcomm IPQ5018 (2x Cortex-A53)
  RAM:    256 MiB DDR3
  Flash:  128 MiB SPI-NAND (ESMT)
  Switch: Realtek RTL8367S, 4x GbE (3x LAN + 1x WAN), SGMII CPU port
  WiFi:   IPQ5018 2.4 GHz, QCN6122 5 GHz, both 802.11ax
  LEDs:   system (green/amber), WAN, LAN1-3
  Button: reset
  UART:   115200 8N1, 3.3V, on-board header

Wi-Fi is left disabled: 256 MiB is too few for ath11k, same as on the
ELECOM WRC-X3000GS2.

Notes:
- The label reads "Ver 2.20", but the vendor firmware only ever calls the
  board V2: the GPL tree is GPL_MR80Xv2, PRODUCT_NAME is MR80Xv2, the
  running system reports "MR80X V2" and the fwup support list carries
  product_ver 2.0.0. The trailing digits are a production sub-revision,
  so the port is named v2.
- MAC1 runs sgmii through the UNIPHY PCS to RTL8367S port 6. The link is
  wired for HSGMII and 2500base-x does come up, but only when gmac1 and
  the CPU port carry the same phy-mode: the UNIPHY PCS belongs to the
  conduit (pcs-handle = <&uniphy0> in ipq5018-ess.dtsi), so setting the
  CPU port alone leaves the switch running HSGMII into a SerDes still
  clocked for SGMII.
  With both ends at 2500base-x the trunk still dies on some boots: over
  12 reboots, 2 came up with the CPU port passing no traffic at all -
  eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors,
  the link reporting 2.5 Gbps. That matches the bring-up ordering race
  described in openwrt#25153, where the switch end of the trunk
  is configured before the IPQ5018 UNIPHY resets and recalibrates its
  PLL. sgmii has not reproduced it, so the port ships at sgmii until
  that fix lands.
- MAC addresses come from default-mac in the vendor tp_data UBI volume,
  6 raw bytes at offset 0, mounted read-only during preinit:
    label   default-mac
    LAN     default-mac
    WAN     default-mac + 1
    2.4 GHz default-mac - 1
    5 GHz   default-mac - 2
- Sysupgrade A/B ping-pongs rootfs/rootfs_1 via tp_boot_idx. primaryboot
  stays 0, the stock loader and the button recovery rely on it.
- factory.bin is wrapped in the Mercusys fwup container the stock web UI
  accepts (scripts/mercusys-fwup.py). The generic tplink-image-2022
  container is rejected: the loader picks its verification algorithm from
  the fw-type string, which that container does not write.
- The board needs the backported spi-qpic-snand ECC context fix,
  otherwise about half of the boots end in "Waiting for root device
  /dev/ubiblock0_1".

Installation:
  In the stock web UI go to Advanced -> System -> Firmware Update ->
  Local Update, browse for
  openwrt-qualcommax-ipq50xx-mercusys_mr80x-v2-squashfs-factory.bin
  and press UPDATE.

  Tested on stock firmware MR80X(EU)_V2.20_1.1.7 Build 20250415
  (Multi-language).

  The U-Boot web recovery does not accept this image: it verifies an
  RSA1024 signature and has no keyless path. Use the stock web UI.

Signed-off-by: Johan Alvarado <[email protected]>
@kuncy7

kuncy7 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

@c127dev Thank you - that is exactly the run I needed, and 2 of 12 against 16/16 and 17/17 settles it far better than my single board could.

On the caveat: the split is what you ran. It has no sds_lock at all - that mutex only exists in #25101, and on plain main there is nothing to take it around. The one mutex the patch adds, sds_defer_lock, guards the deferral state (whether a bring-up is pending and with which parameters) and the deferred run itself; it does not wrap the SDS_MISC updates. Those are safe without it: pcs_link_up() writes the link/speed/duplex bits and mac_link_up() the pause bits, the masks do not overlap, and each regmap_update_bits() is a single read-modify-write under regmap's own lock, so neither can lose the other's bits. That is the same situation main is in today, before this patch.

The standalone version is up as 797-net-dsa-realtek-rtl8365mb-bring-the-SerDes-up-once-the-conduit-is-up.patch on plain main (kernel 6.18.52 now, same as yours). Apart from the context it differs from the stacked 930-09 in two places only: the mux is parked through the explicit MAC8_SEL masks rather than #25101's misc_mask, and there is no family D branch, because main has none in that path. The deferred bring-up fires at the same point here, 44 ms after the conduit link.

I have not put your tag on the commit yet - I will add it once you confirm against this version, as you offered. Your numbers are in the commit message already, attributed to you.

@kuncy7

kuncy7 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

@namiltd Heads-up on the ordering: this PR no longer sits on top of #25101. The SerDes bring-up change does not depend on the family D series - it gates on the conduit SoC, not on the chip family - and with @c127dev's confirmation on a second board and the failure shipping in current snapshots, it now stands on plain main as 797-net-dsa-realtek-rtl8365mb-bring-the-SerDes-up-once-the-conduit-is-up.patch.

The two still touch the same spots in rtl8365mb_main.c (the pcs_config()/pcs_link_up() split and the struct rtl8365mb tail), so whichever lands second needs a small rebase. If this one goes in first, I am happy to send you the rebased 930-* context, or to rebase mine again if yours does - just say which.

@namiltd

namiltd commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

I will also follow the order chosen by the developers merging the PRs.

#include <linux/regmap.h>
#include <linux/if_bridge.h>
#include <linux/if_vlan.h>
+#include <linux/netdevice.h>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All three added includes are most likely unnecessary.

@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

  • b7c29d8a "generic: rtl8365mb: bring the SerDes up once the conduit is up" — the commit message reports "5 boots ... three of them cold starts" plus the MR80X v2 runs, while the patch header it adds reports "4 boots - one after a sysupgrade and three cold starts" and no MR80X v2 at all. Make the upstream-facing header carry the same numbers.

Generated by Claude Code

Comment on lines +109 to +122
+ /* 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 - a second
+ * pcs_config(), or the deferred one after a first - would otherwise be
+ * a write that update_bits skips, and produce no edge at all.
+ */
+ ret = regmap_update_bits_check(priv->map, RTL8365MB_SDS_MISC_REG,
+ RTL8365MB_SDS_MISC_MAC8_SEL_SGMII_MASK |
+ RTL8365MB_SDS_MISC_MAC8_SEL_HSGMII_MASK,
+ 0, &parked);
+ if (ret)
+ return ret;
+
+ if (parked)
+ msleep(20);

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.

The park sits on the common path of rtl8365mb_sds_config(), so it also runs on the four MediaTek boards that drive rtl8365mb over a 2500base-x CPU port (mt7622-buffalo-wsr-2533dhp2.dts:93, plus mt7622-elecom-wrc-2533gent.dts, mt7622-totolink-a8000ru.dts, mt7981b-mercusys-mr85x-common.dtsi), all on 6.18 too. There a second pcs_config() on an already-muxed SerDes used to skip the write entirely and now drops the mux to DISABLE for 20 ms, which is not "other boards keep the current order". Gate it on mb->sds_defer_needed.


Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

Comment on lines +173 to +176
+static bool rtl8365mb_conduit_is_up(const struct net_device *conduit)
+{
+ return netif_running(conduit) && netif_oper_up(conduit);
+}

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.

This is not the predicate DSA uses for the operational flag that later drives conduit_state_change(): dsa_port_conduit_is_operational() also needs conduit_admin_up, which DSA only sets once the conduit has a non-noop qdisc (user.c:3575-3576). A conduit that is already running with carrier but not yet dev_activated reads as up here, so pcs_config() skips the deferral and silently falls back to the ordering this patch exists to avoid. Use dsa_port_conduit_is_operational(dsa_to_port(ds, extint->port)) instead, which also removes the need for the netdevice.h include.


Generated by Claude Code

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.

fixed, thanks


Generated by Claude Code

+ mutex_unlock(&mb->sds_defer_lock);
+ return;
+ }
+ mutex_unlock(&mb->sds_defer_lock);

@namiltd namiltd Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The proposed change avoids causing an unnecessary lock when one is not needed:

@@ -254,15 +262,17 @@
 +{
 +	struct rtl8365mb *mb = pcs_to_rtl8365mb(pcs);
 +
-+	mutex_lock(&mb->sds_defer_lock);
-+	if (mb->sds_deferred) {
-+		mb->sds_speed = speed;
-+		mb->sds_duplex = duplex;
-+		mb->sds_link_deferred = true;
++	if (mb->sds_defer_needed) {
++		mutex_lock(&mb->sds_defer_lock);
++		if (mb->sds_deferred) {
++			mb->sds_speed = speed;
++			mb->sds_duplex = duplex;
++			mb->sds_link_deferred = true;
++			mutex_unlock(&mb->sds_defer_lock);
++			return;
++		}
 +		mutex_unlock(&mb->sds_defer_lock);
-+		return;
 +	}
-+	mutex_unlock(&mb->sds_defer_lock);
 +
 +	rtl8365mb_sds_link_up(mb, speed, duplex);
 +}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, applied: boards that never defer no longer take sds_defer_lock in pcs_link_up(). sds_defer_needed is set in setup() before phylink can call into the PCS, so reading it without the lock is safe.

+ struct dsa_port *dp;
+ int ret;
+
+ if (!operational)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Exit when sds_defer_needed is not set, as there is no point in proceeding further:

-+	if (!operational)
++	if (!operational || !mb->sds_defer_needed)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied as well, same reasoning: without the deferral there is nothing to look up.

+ return ret;
+
+ if (parked)
+ msleep(20);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: please use usleep_range(20000, 21000) instead of msleep(20) here, since msleep() can overshoot due to jiffy rounding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied.

@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

@namiltd

namiltd commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Look at this: #19644 (review)

Change to:

+	ret = rtl8365mb_sds_config(mb, mb->sds_interface);
+	if (!ret) {
+		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;
+	}
+	mutex_unlock(&mb->sds_defer_lock);
+
+	if (ret)
+		dev_err(priv->dev, "SerDes bring-up after %s link up failed: %pe\n",
+			conduit->name, ERR_PTR(ret));
+	else
+		dev_info(priv->dev, "SerDes brought up after %s link up\n",
+			 conduit->name);
+}
 	if (ret)
 		return ret;
 
+	ret = devm_mutex_init(priv->dev, &mb->sds_defer_lock);
+	if (ret)
+		return ret;
+
 	mb->priv = priv;
 	mb->cpu.trap_port = RTL8365MB_MAX_NUM_PORTS;
 	mb->cpu.insert = RTL8365MB_CPU_INSERT_TO_ALL;

@kuncy7

kuncy7 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@namiltd Both applied, thanks. The bot was right about the error path: on a fixed link nothing calls pcs_config() again, so clearing the flags after a failed bring-up left the SerDes unconfigured until the next boot. Now the bring-up stays pending and is retried the next time the conduit comes up. The lock is initialised in rtl8365mb_detect() now, before anything can use it. None of this touches the successful path that the Tested-by covers.

@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 30, 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]>
c127dev added a commit to c127dev/openwrt that referenced this pull request Sep 30, 2026
Hardware:
  SoC:    Qualcomm IPQ5018 (2x Cortex-A53)
  RAM:    256 MiB DDR3
  Flash:  128 MiB SPI-NAND (ESMT)
  Switch: Realtek RTL8367S, 4x GbE (3x LAN + 1x WAN), SGMII CPU port
  WiFi:   IPQ5018 2.4 GHz, QCN6122 5 GHz, both 802.11ax
  LEDs:   system (green/amber), WAN, LAN1-3
  Button: reset
  UART:   115200 8N1, 3.3V, on-board header

Wi-Fi is left disabled: 256 MiB is too few for ath11k, same as on the
ELECOM WRC-X3000GS2.

Notes:
- The label reads "Ver 2.20", but the vendor firmware only ever calls the
  board V2: the GPL tree is GPL_MR80Xv2, PRODUCT_NAME is MR80Xv2, the
  running system reports "MR80X V2" and the fwup support list carries
  product_ver 2.0.0. The trailing digits are a production sub-revision,
  so the port is named v2.
- MAC1 runs sgmii through the UNIPHY PCS to RTL8367S port 6. The link is
  wired for HSGMII and 2500base-x does come up, but only when gmac1 and
  the CPU port carry the same phy-mode: the UNIPHY PCS belongs to the
  conduit (pcs-handle = <&uniphy0> in ipq5018-ess.dtsi), so setting the
  CPU port alone leaves the switch running HSGMII into a SerDes still
  clocked for SGMII.
  With both ends at 2500base-x the trunk still dies on some boots: over
  12 reboots, 2 came up with the CPU port passing no traffic at all -
  eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors,
  the link reporting 2.5 Gbps. That matches the bring-up ordering race
  described in openwrt#25153, where the switch end of the trunk
  is configured before the IPQ5018 UNIPHY resets and recalibrates its
  PLL. sgmii has not reproduced it, so the port ships at sgmii until
  that fix lands.
- MAC addresses come from default-mac in the vendor tp_data UBI volume,
  6 raw bytes at offset 0, mounted read-only during preinit:
    label   default-mac
    LAN     default-mac
    WAN     default-mac + 1
    2.4 GHz default-mac - 1
    5 GHz   default-mac - 2
- Sysupgrade A/B ping-pongs rootfs/rootfs_1 via tp_boot_idx, switched
  only after the new slot is fully written. primaryboot stays 0, the
  stock loader and the button recovery rely on it.
- factory.bin is wrapped in the Mercusys fwup container the stock web UI
  accepts (scripts/mercusys-fwup.py). The generic tplink-image-2022
  container is rejected: the loader picks its verification algorithm from
  the fw-type string, which that container does not write.
- The board needs the backported spi-qpic-snand ECC context fix,
  otherwise about half of the boots end in "Waiting for root device
  /dev/ubiblock0_1".

Installation:
  In the stock web UI go to Advanced -> System -> Firmware Update ->
  Local Update, browse for
  openwrt-qualcommax-ipq50xx-mercusys_mr80x-v2-squashfs-factory.bin
  and press UPDATE.

  Tested on stock firmware MR80X(EU)_V2.20_1.1.7 Build 20250415
  (Multi-language).

  The U-Boot web recovery does not accept this image: it verifies an
  RSA1024 signature and has no keyless path. Use the stock web UI.

Signed-off-by: Johan Alvarado <[email protected]>
robimarko pushed a commit to c127dev/openwrt that referenced this pull request Oct 2, 2026
Hardware:
  SoC:    Qualcomm IPQ5018 (2x Cortex-A53)
  RAM:    256 MiB DDR3
  Flash:  128 MiB SPI-NAND (ESMT)
  Switch: Realtek RTL8367S, 4x GbE (3x LAN + 1x WAN), SGMII CPU port
  WiFi:   IPQ5018 2.4 GHz, QCN6122 5 GHz, both 802.11ax
  LEDs:   system (green/amber), WAN, LAN1-3
  Button: reset
  UART:   115200 8N1, 3.3V, on-board header

Wi-Fi is left disabled: 256 MiB is too few for ath11k, same as on the
ELECOM WRC-X3000GS2.

Notes:
- The label reads "Ver 2.20", but the vendor firmware only ever calls the
  board V2: the GPL tree is GPL_MR80Xv2, PRODUCT_NAME is MR80Xv2, the
  running system reports "MR80X V2" and the fwup support list carries
  product_ver 2.0.0. The trailing digits are a production sub-revision,
  so the port is named v2.
- MAC1 runs sgmii through the UNIPHY PCS to RTL8367S port 6. The link is
  wired for HSGMII and 2500base-x does come up, but only when gmac1 and
  the CPU port carry the same phy-mode: the UNIPHY PCS belongs to the
  conduit (pcs-handle = <&uniphy0> in ipq5018-ess.dtsi), so setting the
  CPU port alone leaves the switch running HSGMII into a SerDes still
  clocked for SGMII.
  With both ends at 2500base-x the trunk still dies on some boots: over
  12 reboots, 2 came up with the CPU port passing no traffic at all -
  eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors,
  the link reporting 2.5 Gbps. That matches the bring-up ordering race
  described in openwrt#25153, where the switch end of the trunk
  is configured before the IPQ5018 UNIPHY resets and recalibrates its
  PLL. sgmii has not reproduced it, so the port ships at sgmii until
  that fix lands.
- MAC addresses come from default-mac in the vendor tp_data UBI volume,
  6 raw bytes at offset 0, mounted read-only during preinit:
    label   default-mac
    LAN     default-mac
    WAN     default-mac + 1
    2.4 GHz default-mac - 1
    5 GHz   default-mac - 2
- Sysupgrade A/B ping-pongs rootfs/rootfs_1 via tp_boot_idx, switched
  only after the new slot is fully written. primaryboot stays 0, the
  stock loader and the button recovery rely on it.
- factory.bin is wrapped in the Mercusys fwup container the stock web UI
  accepts (scripts/mercusys-fwup.py). The generic tplink-image-2022
  container is rejected: the loader picks its verification algorithm from
  the fw-type string, which that container does not write.
- The board needs the backported spi-qpic-snand ECC context fix,
  otherwise about half of the boots end in "Waiting for root device
  /dev/ubiblock0_1".

Installation:
  In the stock web UI go to Advanced -> System -> Firmware Update ->
  Local Update, browse for
  openwrt-qualcommax-ipq50xx-mercusys_mr80x-v2-squashfs-factory.bin
  and press UPDATE.

  Tested on stock firmware MR80X(EU)_V2.20_1.1.7 Build 20250415
  (Multi-language).

  The U-Boot web recovery does not accept this image: it verifies an
  RSA1024 signature and has no keyless path. Use the stock web UI.

Signed-off-by: Johan Alvarado <[email protected]>
Link: openwrt#24919
Signed-off-by: Robert Marko <[email protected]>
@namiltd

namiltd commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

The Mercusys MR80X v2 has just been added to the list of supported devices, so this PR should be the next step. My PR #25101 (tested in #19644) regarding Family D "slots in" alongside it, so there are no conflicts. All that is required is adapting "generic: rtl8365mb: bring the SerDes up once the conduit is up" to the new code, which I have already done in #19644.

@kuncy7

kuncy7 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@namiltd Agreed, and thank you for saying so. That order works for both of us.

I checked how the two fit together at your current heads. With #25101 (777-01..08) applied first, as the numbering now orders it, 797 as posted here no longer applies: 5 of its 10 hunks fail, in the pcs_config()/sds_config() area that 777-07 and 777-08 rewrite. Your adapted 797 in #19644 fixes that. I built both: its pcs_config(), pcs_link_up(), conduit_state_change() and the port lookup are identical to this PR, and the only addition is the family D early return in rtl8365mb_sds_defer_needed(). So I am happy with that version.

Two requests for when #25101 picks it up, since that commit will have to replace 797 in the same step:

  • Please keep From: Stanislaw Pal on the patch, as it is a refresh of this one, and add your Signed-off-by below with a short bracketed note about the family D adaptation.
  • The Tested-by from @c127dev covers 797 on plain main. For the stack on top of 777-01..08 his offer to regression-test on the MR80X v2 still stands, and I can run the same on the AX55 v1.

For the family D owner you answered in kuncy7/openwrt-ax55-v1#3: he has no build setup, so I published a test image built from your branch at f853b933c4. I will pass his results on in #19644.

@namiltd

namiltd commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

If the operation of patches 777-01 through 777-08 is successfully verified on hardware, please post this information in PR #25101. Please include details regarding the specific router used. This will facilitate the approval of the PR.

@kuncy7

kuncy7 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@namiltd No trouble at all. It is on a branch on top of your current Realtek_DSA head (f853b933c4), as one small commit that touches only the two 797 files (pending-6.12 and pending-6.18):

kuncy7@70dff28

git fetch https://github.com/kuncy7/openwrt-nss-edma.git rtl8365mb-797-on-777
git cherry-pick FETCH_HEAD        # then squash it into your 797 commit

The patch body is untouched: I applied both versions on top of 777-01..08 and the resulting rtl8365mb_main.c is identical. Only the header changed:

From: Stanislaw Pal <[email protected]>
...
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]>

With the bracketed note the Tested-by can stay where it is: it covers the patch as tested, and the note says what was changed afterwards. Reword the note if you prefer.

On hardware verification of 777-01..08: yes, I will post in #25101, with the router details, as soon as the owner of the US family D unit (kuncy7/openwrt-ax55-v1#3) reports back on the test image.

Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request Oct 10, 2026
Hardware:
  SoC:    Qualcomm IPQ5018 (2x Cortex-A53)
  RAM:    256 MiB DDR3
  Flash:  128 MiB SPI-NAND (ESMT)
  Switch: Realtek RTL8367S, 4x GbE (3x LAN + 1x WAN), SGMII CPU port
  WiFi:   IPQ5018 2.4 GHz, QCN6122 5 GHz, both 802.11ax
  LEDs:   system (green/amber), WAN, LAN1-3
  Button: reset
  UART:   115200 8N1, 3.3V, on-board header

Wi-Fi is left disabled: 256 MiB is too few for ath11k, same as on the
ELECOM WRC-X3000GS2.

Notes:
- The label reads "Ver 2.20", but the vendor firmware only ever calls the
  board V2: the GPL tree is GPL_MR80Xv2, PRODUCT_NAME is MR80Xv2, the
  running system reports "MR80X V2" and the fwup support list carries
  product_ver 2.0.0. The trailing digits are a production sub-revision,
  so the port is named v2.
- MAC1 runs sgmii through the UNIPHY PCS to RTL8367S port 6. The link is
  wired for HSGMII and 2500base-x does come up, but only when gmac1 and
  the CPU port carry the same phy-mode: the UNIPHY PCS belongs to the
  conduit (pcs-handle = <&uniphy0> in ipq5018-ess.dtsi), so setting the
  CPU port alone leaves the switch running HSGMII into a SerDes still
  clocked for SGMII.
  With both ends at 2500base-x the trunk still dies on some boots: over
  12 reboots, 2 came up with the CPU port passing no traffic at all -
  eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors,
  the link reporting 2.5 Gbps. That matches the bring-up ordering race
  described in openwrt#25153, where the switch end of the trunk
  is configured before the IPQ5018 UNIPHY resets and recalibrates its
  PLL. sgmii has not reproduced it, so the port ships at sgmii until
  that fix lands.
- MAC addresses come from default-mac in the vendor tp_data UBI volume,
  6 raw bytes at offset 0, mounted read-only during preinit:
    label   default-mac
    LAN     default-mac
    WAN     default-mac + 1
    2.4 GHz default-mac - 1
    5 GHz   default-mac - 2
- Sysupgrade A/B ping-pongs rootfs/rootfs_1 via tp_boot_idx, switched
  only after the new slot is fully written. primaryboot stays 0, the
  stock loader and the button recovery rely on it.
- factory.bin is wrapped in the Mercusys fwup container the stock web UI
  accepts (scripts/mercusys-fwup.py). The generic tplink-image-2022
  container is rejected: the loader picks its verification algorithm from
  the fw-type string, which that container does not write.
- The board needs the backported spi-qpic-snand ECC context fix,
  otherwise about half of the boots end in "Waiting for root device
  /dev/ubiblock0_1".

Installation:
  In the stock web UI go to Advanced -> System -> Firmware Update ->
  Local Update, browse for
  openwrt-qualcommax-ipq50xx-mercusys_mr80x-v2-squashfs-factory.bin
  and press UPDATE.

  Tested on stock firmware MR80X(EU)_V2.20_1.1.7 Build 20250415
  (Multi-language).

  The U-Boot web recovery does not accept this image: it verifies an
  RSA1024 signature and has no keyless path. Use the stock web UI.

Signed-off-by: Johan Alvarado <[email protected]>
Link: openwrt#24919
Signed-off-by: Robert Marko <[email protected]>
kuncy7 added a commit to kuncy7/openwrt-nss-edma that referenced this pull request Oct 10, 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]>
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]>
xize pushed a commit to xize/openwrt-xsdk that referenced this pull request Oct 17, 2026
Hardware:
  SoC:    Qualcomm IPQ5018 (2x Cortex-A53)
  RAM:    256 MiB DDR3
  Flash:  128 MiB SPI-NAND (ESMT)
  Switch: Realtek RTL8367S, 4x GbE (3x LAN + 1x WAN), SGMII CPU port
  WiFi:   IPQ5018 2.4 GHz, QCN6122 5 GHz, both 802.11ax
  LEDs:   system (green/amber), WAN, LAN1-3
  Button: reset
  UART:   115200 8N1, 3.3V, on-board header

Wi-Fi is left disabled: 256 MiB is too few for ath11k, same as on the
ELECOM WRC-X3000GS2.

Notes:
- The label reads "Ver 2.20", but the vendor firmware only ever calls the
  board V2: the GPL tree is GPL_MR80Xv2, PRODUCT_NAME is MR80Xv2, the
  running system reports "MR80X V2" and the fwup support list carries
  product_ver 2.0.0. The trailing digits are a production sub-revision,
  so the port is named v2.
- MAC1 runs sgmii through the UNIPHY PCS to RTL8367S port 6. The link is
  wired for HSGMII and 2500base-x does come up, but only when gmac1 and
  the CPU port carry the same phy-mode: the UNIPHY PCS belongs to the
  conduit (pcs-handle = <&uniphy0> in ipq5018-ess.dtsi), so setting the
  CPU port alone leaves the switch running HSGMII into a SerDes still
  clocked for SGMII.
  With both ends at 2500base-x the trunk still dies on some boots: over
  12 reboots, 2 came up with the CPU port passing no traffic at all -
  eth0 transmitting while s00_p06_ifInOctets stayed at 0, no FCS errors,
  the link reporting 2.5 Gbps. That matches the bring-up ordering race
  described in openwrt#25153, where the switch end of the trunk
  is configured before the IPQ5018 UNIPHY resets and recalibrates its
  PLL. sgmii has not reproduced it, so the port ships at sgmii until
  that fix lands.
- MAC addresses come from default-mac in the vendor tp_data UBI volume,
  6 raw bytes at offset 0, mounted read-only during preinit:
    label   default-mac
    LAN     default-mac
    WAN     default-mac + 1
    2.4 GHz default-mac - 1
    5 GHz   default-mac - 2
- Sysupgrade A/B ping-pongs rootfs/rootfs_1 via tp_boot_idx, switched
  only after the new slot is fully written. primaryboot stays 0, the
  stock loader and the button recovery rely on it.
- factory.bin is wrapped in the Mercusys fwup container the stock web UI
  accepts (scripts/mercusys-fwup.py). The generic tplink-image-2022
  container is rejected: the loader picks its verification algorithm from
  the fw-type string, which that container does not write.
- The board needs the backported spi-qpic-snand ECC context fix,
  otherwise about half of the boots end in "Waiting for root device
  /dev/ubiblock0_1".

Installation:
  In the stock web UI go to Advanced -> System -> Firmware Update ->
  Local Update, browse for
  openwrt-qualcommax-ipq50xx-mercusys_mr80x-v2-squashfs-factory.bin
  and press UPDATE.

  Tested on stock firmware MR80X(EU)_V2.20_1.1.7 Build 20250415
  (Multi-language).

  The U-Boot web recovery does not accept this image: it verifies an
  RSA1024 signature and has no keyless path. Use the stock web UI.

Signed-off-by: Johan Alvarado <[email protected]>
Link: openwrt#24919
Signed-off-by: Robert Marko <[email protected]>
@kuncy7

kuncy7 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

A note on how this and #25101 fit together now. Since its v6, #25101 adds rtl8365mb_conduit_state_change() and sds_cfg_lock itself, so the patch here no longer applies on top of it. The port of this patch onto v6 is in #19644 (11ee3eec77), and an Archer AX55 v1 has run it since 17 October. #25101 is still a draft and its series is under review on netdev, so this PR stands on main as it is and fixes the cold-start trunk failure on the AX55 v1 and the MR80X v2 today. Whichever of the two goes in second needs the port: if #25101 is merged first, I'll replace the patch here with it.

@namiltd

namiltd commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

A new version is available at #19644 (6a3f54b); it has been slightly modified to remove the guard(mutex), as this approach is not favored by Linux maintainers.

@namiltd

namiltd commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Patch number 797 is already taken; I suggest renaming it to 779.

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

Add a pending patch that does 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. It is armed only when the conduit is an IPQ5018 GMAC, the
only SoC this was seen on, so 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]>
@kuncy7
kuncy7 force-pushed the ax55-lateinit-main branch from ac038c0 to bb6ca03 Compare November 7, 2026 13:08
@kuncy7

kuncy7 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@namiltd Thanks. Renamed to 779, since 797 is now taken in pending-6.18 by the mtk_eth_soc series, and rebased onto current main; the patch only needed its hunk offsets refreshed after the rtl8365mb BIT()/GENMASK() backport, the code is unchanged. The version here never used guard(mutex), so nothing changes there. The two PRs now carry the same file name; whichever is merged second still needs the port, as before.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants