net: pcs: add basic support for RK3568 XPCS
Subsystems (9)
Coia Prant
maintainerv12 cover net: pcs: add basic support for RK3568 XPCS
This series adds proper SGMII support for the Rockchip RK3568 SoC using the integrated Synopsys DesignWare XPCS, along with necessary fixes and refactoring in the stmmac core and XPCS driver.
Motivation
==========
The RK3568 integrates a DW XPCS accessed via APB3 and connected to a Naneng Combo SerDes PHY. Several boards (e.g., Ariaboard Photonicat) use this interface for Gigabit Ethernet. However, the current upstream stmmac driver does not support this configuration, and the XPCS driver has issues in SGMII poll mode that cause the link to be reported incorrectly.
This series addresses these issues by:
- Adding ANRESTART support for SGMII link recovery
- Adding a Rockchip XPCS platform glue driver and wiring it up in dwmac-rk
Series overview
===============
RK3568 XPCS/SGMII:
Patch 1: add ANRESTART support for SGMII link recovery Patch 2: DT binding for Rockchip RK3568 XPCS Patch 3: implement the Rockchip XPCS platform glue driver Patch 4: DT binding for Rockchip DWMAC PCS
Patch 5: wire up SGMII support in dwmac-rk
Patch 6: update MAINTAINERS
Dependencies
============
- Generic PM domain (genpd) changes:
https://lore.kernel.org/all/[email protected]/
- PHY binding+driver (Naneng Combo PHY SGMII MAC selection):
https://lore.kernel.org/all/[email protected]/
The DTS changes using the PHY property are sent separately to Heiko/linux-rockchip. There is no hard build dependency; the pieces can converge during the merge window.
Changelog
=========
Changes since v11:
- Drop the "default PCS_XPCS" for PCS_XPCS_PLATFORM and the "default ARCH_ROCKCHIP" for PCS_XPCS_ROCKCHIP. There is no in-tree user of the generic snps,dw-xpcs glue that needs it selected by default, and new symbols defaulting to enabled on olddefconfig are something we should avoid (Jakub).
- Update the PCS_XPCS_PLATFORM commit message accordingly.
Key design decisions
====================
- The stmmac core now delegates XPCS creation entirely to platform drivers via pcs_init/pcs_exit. This is necessary because the generic XPCS creation logic would override any XPCS set up by the platform driver.
- The Rockchip XPCS driver creates a virtual MDIO bus over the APB3 registers and implements address remapping. The generic XPCS core handles all PCS configuration via phylink_pcs_ops.
- On RK3568 in SGMII mode, the MAC clock is fixed at 125 MHz and cannot be dynamically changed. In-band mode is used, and the generic stmmac set_clk_tx_rate callback is disabled to prevent incorrect clock updates that would break RX.
- The SerDes and power domain are attached to the XPCS device tree node rather than the MAC node. This reflects the actual hardware topology and simplifies the dwmac-rk driver by keeping all PCS-related resources self-contained. It also prepares for possible future QSGMII support, where a single SerDes serves multiple MACs and would be more naturally managed under the XPCS node.
Testing
=======
Board: Ariaboard Photonicat (RK3568)
OS: Armbian (trixie)
Kernel: 6.18 (backports)
Result: The SGMII interface obtains an IP address, SSH works, and
ping traffic passes without loss.
Notes
=====
- When testing out-band mode with set_clk_tx_rate, only 1000Mbps works on both TX/RX; 10/100Mbps only works on TX side.
Acknowledgments
===============
This work was inspired by and builds upon the excellent work of others:
- Serge Semin's Synopsys DesignWare XPCS platform driver (pcs-xpcs-plat.c)
- Clément Léger's Renesas MIIC driver (pcs-rzn1-miic.c)
- The Rockchip TRM and downstream OEM drivers
Thanks in advance,
Coia Prant
---
Coia Prant (6):
net: pcs: xpcs: add ANRESTART support for SGMII link recovery
dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
dt-bindings: net: rockchip-dwmac: document pcs-handle
net: stmmac: dwmac-rk: add SGMII support for RK3568
MAINTAINERS: add entry for Rockchip XPCS driver
.../net/pcs/rockchip,rk3568-xpcs.yaml | 69 ++ .../bindings/net/rockchip-dwmac.yaml | 27 + MAINTAINERS | 9 + drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 131 +++- drivers/net/pcs/Kconfig | 23 + drivers/net/pcs/Makefile | 5 +- drivers/net/pcs/pcs-xpcs-rk.c | 598 ++++++++++++++++++ drivers/net/pcs/pcs-xpcs.c | 35 +- include/linux/pcs/pcs-xpcs-rk.h | 11 + 10 files changed, 881 insertions(+), 28 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml create mode 100644 drivers/net/pcs/pcs-xpcs-rk.c create mode 100644 include/linux/pcs/pcs-xpcs-rk.h
Signature · 1 line
2.47.3
Coia Prant
maintainerPATCH v12 1/6 net: pcs: xpcs: add ANRESTART support for SGMII link recovery
On some hardware using the DesignWare XPCS IP (e.g., RK3568 MAC side SGMII), the PCS does not automatically restart auto-negotiation when the link goes down and comes back up. Without an explicit ANRESTART, the link stays down forever.
Add BMCR_ANRESTART in two places:
1. In xpcs_config_aneg_c37_sgmii(), when starting AN, set ANRESTART alongside ANENABLE to initiate a fresh negotiation.
2. In xpcs_get_state_c37_sgmii(), when link is down and AN completion is detected, clear the interrupt and trigger ANRESTART to restart the negotiation process. Propagate the return value of the restart so errors are not silently ignored.
The restart cannot go through the .pcs_an_restart op: phylink only calls it for 802.3z interfaces, and SGMII is not one. Changing hardware state from pcs_get_state() is already done elsewhere in this driver (xpcs_get_state_c73() calls xpcs_soft_reset() and xpcs_do_config()), so the same pattern is used here.
The latch is cleared before issuing the restart, not after: clearing it afterwards would discard a freshly latched ANCMPLT from the new negotiation. If an MDIO access fails at this point, it indicates an unrecoverable hardware condition until reset.
Also clear DW_VR_MII_AN_INTR_STS in xpcs_config_aneg_c37_sgmii() before starting AN, matching what xpcs_config_aneg_c37_1000basex() already does. On the non-inband path the function now returns the result of that write instead of the DIG_CTRL1 modify.
Update the comment in xpcs_config_aneg_c37_sgmii() to note that although the DesignWare databook says AN restart is not needed for MAC side SGMII, some implementations (e.g. Rockchip RK3568) require it to recover the link after a disconnect.
This is not a fix for an existing mainline platform: the affected platform (RK3568 XPCS) is introduced later in the same series.
--- drivers/net/pcs/pcs-xpcs.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-)
drivers/net/pcs/pcs-xpcs.c +29 -6
@@ -761,7 +761,9 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,* DW xPCS used with DW EQoS MAC is always MAC side SGMII. * 4) VR_MII_DIG_CTRL1 Bit(9) [MAC_AUTO_SW] = 1b (Automatic * speed/duplex mode change by HW after SGMII AN complete) -* 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) +* 5) VR_MII_AN_INTR_STS = 0x0 (Clear CL37 AN complete status) +* 6) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN) +* VR_MII_MMD_CTRL Bit(9) [AN_RESTART] = 1b (Restart SGMII AN) * * Note that VR_MII_MMD_CTRL is MII_BMCR. *
@@ -769,7 +771,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,* SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from * PHY about the link state change after C28 AN is completed * between PHY and Link Partner. There is also no need to -* trigger AN restart for MAC-side SGMII. +* trigger AN restart for MAC-side SGMII on most devices. +* +* Note: While the DesignWare databook states that AN restart is +* not needed for MAC side SGMII, some implementations (e.g. +* Rockchip RK3568) exhibit a timing quirk when integrated with +* phylink and do not restart AN automatically when the link +* comes back up. An explicit AN restart is required on those +* parts to recover the link after a disconnect. */ mdio_ctrl =xpcs_read (xpcs,MDIO_MMD_VEND2 ,MII_BMCR );if (mdio_ctrl <0 )
@@ -816,9 +825,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,if (ret <0 )return ret; +/* Clear CL37 AN complete status */ + ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); +if (ret <0 ) +return ret; +if (neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED ) ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,MII_BMCR , - mdio_ctrl |BMCR_ANENABLE ); + mdio_ctrl |BMCR_ANENABLE |BMCR_ANRESTART );return ret; }
@@ -1093,9 +1107,18 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,return 0 ; } -/* Clear AN complete status or interrupt */ -if (state->an_complete) -xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); +if (state->an_complete) { +/* Clear AN complete status or interrupt */ + ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); +if (ret <0 ) +return ret; + +/* Initiate the next round of AN */ + ret =xpcs_modify (xpcs,MDIO_MMD_VEND2 ,MII_BMCR ,BMCR_ANRESTART , +BMCR_ANRESTART ); +if (ret <0 ) +return ret; + }return 0 ; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v12 1/6] net: pcs: xpcs: add ANRESTART support for SGMII link recovery
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In xpcs_get_state_c37_sgmii() (drivers/net/pcs/pcs-xpcs.c lines 1110-1121), the ANCMPLT latch is cleared with…
--
net: pcs: xpcs: add ANRESTART support for SGMII link recovery
This commit sets BMCR_ANRESTART along with BMCR_ANENABLE in xpcs_config_aneg_c37_sgmii() and clears DW_VR_MII_AN_INTR_STS before starting AN. It also makes xpcs_get_state_c37_sgmii() clear the ANCMPLT latch and trigger an AN restart when the link is down and AN complete is latched. This works around RK3568 XPCS, which does not restart AN on its own.
Quoted 4 lines
drivers/net/pcs/pcs-xpcs.c +0
-0
[ ... ]
Quoted 8 lines
drivers/net/pcs/pcs-xpcs.c +1
-3@@ -1093,9 +1107,18 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,return 0 ; } -/* Clear AN complete status or interrupt */ -if (state->an_complete) -xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); +if (state->an_complete) {
drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, · line 1120
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +10
-0+/* Clear AN complete status or interrupt */ + ret =xpcs_write (xpcs,MDIO_MMD_VEND2 ,DW_VR_MII_AN_INTR_STS ,0 ); +if (ret <0 ) +return ret; + +/* Initiate the next round of AN */ + ret =xpcs_modify (xpcs,MDIO_MMD_VEND2 ,MII_BMCR ,BMCR_ANRESTART , +BMCR_ANRESTART ); +if (ret <0 ) +return ret;
[Severity: Low]
What happens if the DW_VR_MII_AN_INTR_STS write succeeds but the xpcs_modify() of MII_BMCR fails?
At that point the ANCMPLT latch is already cleared. If the read fails, __mdiobus_c45_modify_changed() returns without writing anything:
drivers/net/phy/mdio_bus.c:__mdiobus_c45_modify_changed() {
...
ret = __mdiobus_c45_read(bus, addr, devad, regnum);
if (ret < 0)
return ret;
...
}On hardware that needs this workaround, the latched ANCMPLT seems to be the only thing that triggers the restart. Later calls to xpcs_get_state_c37_sgmii() would see the link down with no ANCMPLT, so the restart would never be retried.
xpcs_get_state() only logs the error:
case DW_AN_C37_SGMII: ret = xpcs_get_state_c37_sgmii(xpcs, state); if (ret) dev_err(&xpcs->mdiodev->dev, "%s returned %pe\n", "xpcs_get_state_c37_sgmii", ERR_PTR(ret)); break;
phylink_resolve() only reconfigures the PCS when the interface changes or force_major_config is set:
if ((mac_config && link_state.interface != pl->link_config.interface) ||
pl->force_major_config) {Would the link then stay down until pcs_config runs again, for example after an interface down/up?
The commit message says:
If an MDIO access fails at this point, it indicates an unrecoverable hardware condition until reset.
Does that hold for RK3568? In the later patch "net: pcs: xpcs: add Rockchip RK3568 platform glue driver", xpcs_rk_read_reg() and xpcs_rk_write_reg() appear to fail only through pm_runtime_resume_and_get(). A failed runtime resume callback does not set the sticky power.runtime_error, so the failure could be transient rather than permanent.
Quoted 4 lines
drivers/net/pcs/pcs-xpcs.c +1
-0+ }return 0 ; }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017054406.1828061-1-coiaprant%40gmail.com
Coia Prant
maintainerPATCH v12 2/6 dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
In reply to Coia PrantAdd device tree binding documentation for the Synopsys DesignWare XPCS integrated on the Rockchip RK3568 SoC.
The XPCS is accessed over the APB3 bus and internally connected to a Naneng Combo SerDes PHY. It supports 1000BASE-X, SGMII, and QSGMII modes, with four MII ports.
The MII port used by the SGMII link is derived from the MAC it is routed to: GMAC0 uses port 0, GMAC1 uses port 1. The port index is not an independent board-level configuration, so the binding does not describe the ports. If a future SoC needs per-port configuration that cannot be derived, pcs-handle argument cells can be added then.
The CRU reset lines (SRST_XPCS*) are intentionally not described: no in-tree user requests them, and bring-up relies on the PD_PIPE power domain, the SerDes PHY and the in-IP soft reset. They can be added later as optional without breaking ABI.
--- .../net/pcs/rockchip,rk3568-xpcs.yaml | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file +69 -0
@@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pcs/rockchip,rk3568-xpcs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Rockchip RK3568 Synopsys DesignWare Ethernet PCS + +maintainers: + - Coia Prant <[email protected]> + +description: | + Rockchip RK3568 SoC integrates a Synopsys DesignWare Ethernet Physical + Coding Sublayer (XPCS). + The PCS provides an interface between the Media Access Control (MAC) + and the Physical Medium Attachment (PMA) sublayer through a Media + Independent Interface (GMII). + + The XPCS is accessed over the APB3 bus and internally connected to a + Naneng Combo SerDes PHY. + It supports 1000BASE-X, SGMII and QSGMII modes. + +properties: + compatible: + const: rockchip,rk3568-xpcs + + reg: + maxItems: 1 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csr + - const: eee + + phys: + maxItems: 1 + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - phys + - power-domains + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/rk3568-cru.h> + #include <dt-bindings/power/rk3568-power.h> + #include <dt-bindings/phy/phy.h> + + ethernet-pcs@fda00000 { + compatible = "rockchip,rk3568-xpcs"; + reg = <0xfda00000 0x200000>; + clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>; + clock-names = "csr", "eee"; + phys = <&combphy2 PHY_TYPE_SGMII>; + power-domains = <&power RK3568_PD_PIPE>; + };
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v12 2/6] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new binding Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml…
--
dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
This patch adds a device tree binding for the Synopsys DesignWare XPCS on the Rockchip RK3568 SoC. The XPCS sits on the APB3 bus and connects internally to the Naneng Combo SerDes PHY. It supports 1000BASE-X, SGMII and QSGMII.
Quoted 5 lines
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file +0
-0
[ ... ]
Quoted 22 lines
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file +22
-0+properties: + compatible: + const: rockchip,rk3568-xpcs + + reg: + maxItems: 1 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csr + - const: eee + + phys: + maxItems: 1 + + power-domains: + maxItems: 1
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml line 54
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file +10
-0+ +required: + - compatible + - reg + - clocks + - clock-names + - phys + - power-domains + +additionalProperties: false
[Severity: Low]
Should this binding let the XPCS act as a clock provider?
The RK3568 CRU uses XPCS-named clocks as parents for the GMAC RX/TX muxes, in drivers/clk/rockchip/clk-rk3568.c:
PNAME(mux_gmac0_rx_tx_p) = { "clk_gmac0_rgmii_speed", "clk_gmac0_rmii_speed", "clk_gmac0_xpcs_mii" }; PNAME(mux_gmac1_rx_tx_p) = { "clk_gmac1_rgmii_speed", "clk_gmac1_rmii_speed", "clk_gmac1_xpcs_mii" };
These are the parents of SCLK_GMAC0_RX_TX and SCLK_GMAC1_RX_TX. rk356x-base.dtsi passes those clocks to the GMAC as mac_clk_rx, mac_clk_tx and clk_mac_speed. Nothing in the tree registers clk_gmac0_xpcs_mii or clk_gmac1_xpcs_mii today.
For SGMII on GMAC0/GMAC1, a board DT would need assigned-clock-parents to point SCLK_GMACn_RX_TX at the XPCS MII clock. This schema has no #clock-cells or clock-output-names, and additionalProperties: false means dt_binding_check rejects them. So the DT can't name the XPCS node as the source of that clock. Boards would have to use a fixed-clock placeholder carrying the CRU's string name instead.
Documentation/devicetree/bindings/writing-bindings.rst says "DO attempt to make bindings complete even if a driver doesn't support some features". The commit message explains why the SRST_XPCS* resets are left out but says nothing about the MII clock outputs.
Could #clock-cells (and clock-output-names, if needed) be added for the per-port MII clocks? Or could the commit message say why they are left out?
Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml new file +2
-0+ +examples:
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017054406.1828061-1-coiaprant%40gmail.com
Coia Prant
maintainerPATCH v12 3/6 net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Coia PrantThe RK3568 SoC integrates a Synopsys DesignWare XPCS that is accessed via APB3 memory-mapped registers. This driver provides the glue logic to make the XPCS accessible to the generic pcs-xpcs core.
The XPCS block contains four MII ports (0..3). On RK3568 the MII port used by SGMII follows the MAC it is routed to: GMAC0 maps to port 0 and GMAC1 maps to port 1. The glue driver receives the port index from the MAC side and passes it to xpcs_create_mdiodev().
The hardware maps these ports to different MMDs:
- port 0: MMD 7 (ROCKCHIP_MMD_MII)
- port 1: MMD 2 (ROCKCHIP_MMD_MII1)
- port 2: MMD 3 (ROCKCHIP_MMD_MII2)
- port 3: MMD 4 (ROCKCHIP_MMD_MII3)
This driver creates a virtual MDIO bus that translates MDIO operations to APB3 register accesses, with proper address remapping for each port. The generic xpcs driver then creates a phylink_pcs instance on top of this bus, allowing the MAC to use the PCS via the standard phylink API.
The generic XPCS platform glue (pcs-xpcs-plat.o) is split out of the pcs_xpcs composite object into its own module, gated behind the new PCS_XPCS_PLATFORM symbol. There is no in-tree user of the generic snps,dw-xpcs glue that would need it selected by default, so the symbol has no default and platforms that need it select it explicitly.
PCS_XPCS_ROCKCHIP selects GENERIC_PHY and PM_GENERIC_DOMAINS. ARCH_ROCKCHIP already selects PM, so the dependency of PM_GENERIC_DOMAINS on PM is satisfied on the target platform.
The EEE multiplier is derived at runtime from the EEE clock rate instead of being hardcoded, because the clock is muxed between gpll200 (200 MHz) and cpll125 (125 MHz) and can be changed by the board or firmware. A 64-bit intermediate avoids overflow on 32-bit builds, and the result is clamped to the 4-bit DW_VR_MII_EEE_MULT_FACT_100NS field.
Power management
================
The XPCS, its SerDes PHY and the SATA/PCIe controllers share the PD_PIPE power domain on RK3568. genpd powers the domain down during system suspend once every consumer is suspended, which also kills the SerDes and the XPCS.
Boards that rely on MAC WoL need the PCS and SerDes alive to receive magic packets, so PD_PIPE must stay powered across system suspend. Keep it on by marking the XPCS as part of the wakeup path via device_set_wakeup_path(). genpd then leaves the domain powered, because the Rockchip power domain driver sets GENPD_FLAG_ACTIVE_WAKEUP on PD_PIPE, which makes genpd check the wakeup path of its consumers during system suspend.
This is unconditional because the XPCS core currently has no platform callback through which a consumer could convey the MAC WoL state, and the state itself is dynamic: WoL is toggled at runtime via ethtool, so a static DT property cannot express it either. The affected hardware is limited to RK3568 boards using SGMII, which are always-on routers where system suspend is not a realistic use case; the extra power draw is therefore acceptable.
Runtime PM is unaffected: the runtime callbacks only gate the CSR clock, and dev_pm_genpd_rpm_always_on() already keeps PD_PIPE on at runtime.
--- drivers/net/pcs/Kconfig | 23 ++ drivers/net/pcs/Makefile | 5 +- drivers/net/pcs/pcs-xpcs-rk.c | 598 ++++++++++++++++++++++++++++++++ include/linux/pcs/pcs-xpcs-rk.h | 11 + 4 files changed, 635 insertions(+), 2 deletions(-) create mode 100644 drivers/net/pcs/pcs-xpcs-rk.c create mode 100644 include/linux/pcs/pcs-xpcs-rk.h
drivers/net/pcs/Kconfig +23 -0
@@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCS + +config PCS_XPCS_PLATFORM + tristate "Generic XPCS controller support" + help + Generic DWXPCS driver for platforms that don't require any + platform specific code to function or is using platform + data for setup. + + If you have a controller with this interface, say Y or M here. + +config PCS_XPCS_ROCKCHIP + tristate "Rockchip XPCS controller support" + depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) + select GENERIC_PHY + select PM_GENERIC_DOMAINS if PM + help + Support for XPCS controller on Rockchip RK356x SoC. + + If you have a Rockchip SoC with this interface, say Y or M here. + +endif # PCS_XPCS + config PCS_LYNX tristate help
drivers/net/pcs/Makefile +3 -2
@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ - pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o +obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o +obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.o
drivers/net/pcs/pcs-xpcs-rk.c new file +598 -0
598 lines not on this page · raw message
include/linux/pcs/pcs-xpcs-rk.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_PCS_XPCS_ROCKCHIP_H +#define __LINUX_PCS_XPCS_ROCKCHIP_H + +#include <linux/device.h> +#include <linux/of.h> +#include <linux/pcs/pcs-xpcs.h> + +struct dw_xpcs *xpcs_rk_create (struct device *dev,struct device_node *pcs,int port); + +#endif /* __LINUX_PCS_XPCS_ROCKCHIP_H */
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v12 3/6] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] net: pcs: xpcs: xpcs_rk_system_suspend() relies on unset active_wakeup --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net: pcs: xpcs: xpcs_rk_system_suspend() relies on unset active_wakeup --
commit 51040950622ac8bc620e18e37d9000b98191388d
Author: Coia Prant <[email protected]>
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
This commit adds a platform glue driver for the Synopsys DesignWare XPCS on Rockchip RK3568 SoCs, creating a virtual MDIO bus over APB3 registers and managing the SerDes PHY, clocks, and power domain.
Quoted 6 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +0
-0@@ -0,0 +1,598 @@
[ ... ]
Quoted 9 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +9
-0+static int xpcs_rk_system_suspend (struct device *dev) +{ +/* +* Keep the PD_PIPE power domain on during system suspend. +* +* PD_PIPE is shared with SATA/PCIe and would be powered down by +* genpd once all its consumers are suspended, killing the SerDes +* and breaking MAC WoL. Mark the XPCS as part of the wakeup path +* so genpd keeps the domain on. Unconditional because the XPCS
drivers/net/pcs/pcs-xpcs-rk.c line 579
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+* core has no callback to convey the MAC WoL state. +*/ +device_set_wakeup_path (dev); +return 0 ; +} + +static int xpcs_rk_system_resume (struct device *dev) +{ +return 0 ; +}
[Severity: Medium]
Does calling device_set_wakeup_path(dev) in xpcs_rk_system_suspend() actually keep the RK3568_PD_PIPE power domain powered on during system suspend?
The commit message notes that genpd leaves the domain powered because the Rockchip power domain driver sets GENPD_FLAG_ACTIVE_WAKEUP on PD_PIPE. However, in drivers/pmdomain/rockchip/pm-domains.c, rk3568_pm_domains defines RK3568_PD_PIPE with wakeup set to false:
drivers/pmdomain/rockchip/pm-domains.c:
[RK3568_PD_PIPE] = DOMAIN_RK3568("pipe", BIT(8), BIT(11), false, false),In rockchip_pm_add_one_domain(), GENPD_FLAG_ACTIVE_WAKEUP is only set when pd_info->active_wakeup is true:
pd->genpd.flags = GENPD_FLAG_PM_CLK | GENPD_FLAG_NO_STAY_ON; if (pd_info->active_wakeup) pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
When the system suspends via genpd_suspend_noirq() -> genpd_finish_suspend() in drivers/pmdomain/core.c, genpd checks:
if (device_awake_path(dev) && genpd_is_active_wakeup(genpd) && !device_out_band_wakeup(dev)) return 0;
Because genpd_is_active_wakeup(genpd) is false for RK3568_PD_PIPE, genpd ignores device_awake_path(dev) and powers off the domain once all consumers are suspended. This powers down the shared SerDes PHY and XPCS controller, breaking MAC Wake-on-LAN and losing hardware state across suspend and resume since xpcs_rk_system_resume() is a no-op.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH net-next v12 3/6] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Coia PrantThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The system-suspend design for keeping PD_PIPE powered does not work.
- [Medium] xpcs_rk_create() (drivers/net/pcs/pcs-xpcs-rk.c:481) first calls device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)…
- [Low] The patch moves pcs-xpcs-plat.o (the generic snps,dw-xpcs platform driver, name "dwxpcs") out of the pcs_xpcs composite object…
- [Low] Concern: xpcs_rk_create() is exported with no in-tree caller, and include/linux/pcs/pcs-xpcs-rk.h has no !CONFIG_PCS_XPCS_ROCKCHIP stub,…
--
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
This adds a platform glue driver for the Synopsys DesignWare XPCS in the RK3568. The driver exposes the XPCS APB3 registers through a virtual MDIO bus and remaps the MMD per port. It also moves pcs-xpcs-plat.o out of the pcs_xpcs composite object behind a new PCS_XPCS_PLATFORM symbol, and tries to keep PD_PIPE powered across system suspend with device_set_wakeup_path().
Quoted 19 lines
drivers/net/pcs/Kconfig +11
-0@@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCS + +config PCS_XPCS_PLATFORM + tristate "Generic XPCS controller support" + help + Generic DWXPCS driver for platforms that don't require any + platform specific code to function or is using platform + data for setup. + + If you have a controller with this interface, say Y or M here. +
[ ... ]
Quoted 5 lines
drivers/net/pcs/Makefile +0
-0
drivers/net/pcs/Makefile line 7
Quoted 9 lines
drivers/net/pcs/Makefile +2
-2@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ - pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o +obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o
[Severity: Low]
Is it intended that existing configs lose the generic snps,dw-xpcs platform driver here?
Before this change, any config with PCS_XPCS enabled (for example through the select PCS_XPCS in STMMAC_ETH) always built pcs-xpcs-plat.o. The new PCS_XPCS_PLATFORM has no default, so make olddefconfig silently turns the generic glue off.
Some systems have a DT, for instance one provided by firmware, with an MMIO node using the documented snps,dw-xpcs binding. On those systems no MDIO device would be created for that node, and a MAC calling xpcs_create_fwnode() would get -EPROBE_DEFER forever:
drivers/net/pcs/pcs-xpcs.c:xpcs_create_fwnode() {
...
mdiodev = fwnode_mdio_find_device(fwnode);
if (!mdiodev)
return ERR_PTR(-EPROBE_DEFER);
...
}No in-tree DTS uses the binding, and the commit message says the change is deliberate. However, the Rockchip glue only uses exported core symbols, so it does not seem to need the split.
Would adding "default PCS_XPCS" keep the old behaviour? Alternatively, could the split go into its own patch?
Quoted 10 lines
drivers/net/pcs/Makefile +1
-0+obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.odrivers/net/pcs/pcs-xpcs-rk.c new file +0
-0@@ -0,0 +1,598 @@
[ ... ]
Quoted 2 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +2
-0+struct dw_xpcs *xpcs_rk_create (struct device *dev,struct device_node *pcs,int port) +{
[ ... ]
Quoted 20 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +20
-0+ pdev =of_find_device_by_node (pcs); +if (!pdev) +return ERR_PTR (-EPROBE_DEFER ); + +/* +* Establish the device link before reading the supplier's drvdata. +* device_link_add() does not fail on a supplier that is unbinding; +* it creates the link in DL_STATE_SUPPLIER_UNBIND. +* +* The check below only confirms that the supplier is bound at this +* point. It does not fully protect against a concurrent unbind +* between here and xpcs_create_mdiodev(); closing that window would +* require reading a managed link's status or device_lock(), neither +* of which is acceptable on this path. The window is small and +* requires an explicit unbind from userspace. Discussed on +* driver-core. +* +* The link is released automatically when the consumer device is +* destroyed (DL_FLAG_AUTOREMOVE_CONSUMER), so no explicit +* device_link_remove() is needed on the failure paths.
drivers/net/pcs/pcs-xpcs-rk.c line 525
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+*/ +if (!device_link_add (dev, &pdev->dev,DL_FLAG_AUTOREMOVE_CONSUMER )) { +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + } + +if (READ_ONCE (pdev->dev.links.status) !=DL_DEV_DRIVER_BOUND ) { +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + }
[Severity: Medium]
Does this check protect the rest of the MAC probe?
pcs-handle is not a fw_devlink supplier binding, so the MAC can reach this point while the XPCS is still unbound. In that case device_link_init_status() creates the link as DL_STATE_DORMANT.
The XPCS probe can finish on another CPU between device_link_add() and the READ_ONCE(), for example with parallel module loading or async probe:
CPU1 (MAC probe) CPU2 (XPCS probe)xpcs_rk_create()
device_link_add()
link is DL_STATE_DORMANT
device_links_driver_bound()
link becomes DL_STATE_AVAILABLE
READ_ONCE(pdev->dev.links.status)
is DL_DEV_DRIVER_BOUND, passes
xpcs_create_mdiodev(pxpcs->bus, port)
device_links_busy() only counts CONSUMER_PROBE and ACTIVE as busy:
drivers/base/core.c:device_links_busy() {
...
if (link->status == DL_STATE_CONSUMER_PROBE
|| link->status == DL_STATE_ACTIVE) {
ret = true;
...
}So until the MAC finishes probing, a sysfs unbind or module unload of the XPCS would not wait for it. The XPCS devres teardown would then free pxpcs and the mii_bus. Meanwhile xpcs_rk_create() or the rest of the stmmac probe can still reach them through bus->priv and reg_base in xpcs_rk_read_c45() and xpcs_rk_write_c45().
Can this lead to a use-after-free of pxpcs?
Even without an unbind, wouldn't the MAC's own bind hit this warning on the AVAILABLE link?
drivers/base/core.c:device_links_driver_bound() {
...
WARN_ON(link->status != DL_STATE_CONSUMER_PROBE);
WRITE_ONCE(link->status, DL_STATE_ACTIVE);
...
}Also, if the supplier unbinds while this AUTOREMOVE_CONSUMER link is still present, device_links_driver_cleanup() would trigger:
WARN_ON(device_link_test(link, DL_FLAG_AUTOREMOVE_CONSUMER));
The comment above only covers a window up to xpcs_create_mdiodev() opened by an explicit userspace unbind. In this race, the link never gets CONSUMER_PROBE protection for the rest of the MAC probe.
Would it work to check the status of the link returned by device_link_add() instead? That would mean requiring DL_STATE_CONSUMER_PROBE or DL_STATE_ACTIVE, and otherwise calling device_link_del() and returning -EPROBE_DEFER. If the supplier is already bound when the link is created, the link starts as CONSUMER_PROBE and that path looks fine.
Quoted 8 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8
-0+ + pxpcs =platform_get_drvdata (pdev); +if (!pxpcs || !pxpcs->bus) { +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + } + + xpcs =xpcs_create_mdiodev (pxpcs->bus, port);
[ ... ]
Quoted 9 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +9
-0+static int xpcs_rk_system_suspend (struct device *dev) +{ +/* +* Keep the PD_PIPE power domain on during system suspend. +* +* PD_PIPE is shared with SATA/PCIe and would be powered down by +* genpd once all its consumers are suspended, killing the SerDes +* and breaking MAC WoL. Mark the XPCS as part of the wakeup path +* so genpd keeps the domain on. Unconditional because the XPCS
drivers/net/pcs/pcs-xpcs-rk.c line 579
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+* core has no callback to convey the MAC WoL state. +*/ +device_set_wakeup_path (dev); +return 0 ; +} + +static int xpcs_rk_system_resume (struct device *dev) +{ +return 0 ; +}
[Severity: High]
Does device_set_wakeup_path() in xpcs_rk_system_suspend() actually keep PD_PIPE on?
genpd only honours the wakeup path when the domain has GENPD_FLAG_ACTIVE_WAKEUP:
drivers/pmdomain/core.c:genpd_finish_suspend() {
...
if (device_awake_path(dev) && genpd_is_active_wakeup(genpd) &&
!device_out_band_wakeup(dev))
return 0;
...
}The commit message says:
"genpd then leaves the domain powered, because the Rockchip power domain driver sets GENPD_FLAG_ACTIVE_WAKEUP on PD_PIPE"
However, PD_PIPE is declared with wakeup set to false:
drivers/pmdomain/rockchip/pm-domains.c:
[RK3568_PD_PIPE] = DOMAIN_RK3568("pipe", BIT(8), BIT(11), false, false),rockchip_pm_add_one_domain() only adds the flag when active_wakeup is set:
pd->genpd.flags = GENPD_FLAG_PM_CLK | GENPD_FLAG_NO_STAY_ON; if (pd_info->active_wakeup) pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP;
So the early return is never taken. suspended_count is incremented and genpd_sync_power_off() runs. That function ignores the per-device rpm_always_on set by dev_pm_genpd_rpm_always_on(). Once SATA, PCIe and the XPCS are all suspended, PD_PIPE would be powered off in the noirq phase.
Wouldn't that break MAC WoL over SGMII, which this code is meant to preserve?
If PD_PIPE is power-cycled, xpcs_rk_system_resume() does not repeat the probe-time setup either. The probe comment says the SerDes phy_init() and phy_power_on() are needed for register access and soft reset. Also, need_reset in the core is only set in xpcs_create(), so the XPCS soft reset is not run again after power loss.
_DEFINE_DEV_PM_OPS() also maps freeze/thaw/poweroff/restore to these callbacks, so hibernation seems to have the same gap.
Would this need either a change to the PD_PIPE active_wakeup setting (which also affects PCIe and SATA), or a resume path that restores the SerDes and the XPCS?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017054406.1828061-1-coiaprant%40gmail.com
Coia Prant
maintainerPATCH v12 4/6 dt-bindings: net: rockchip-dwmac: document pcs-handle
In reply to Coia PrantThe Rockchip GMAC binding needs to describe the PCS reference used by the SGMII support added later in this series. The property will be parsed by rk_pcs_init(), and a missing phandle fails the probe. Add it and require it when phy-mode is "sgmii" on rockchip,rk3568-gmac, the only SoC in this binding that has SGMII support.
--- .../bindings/net/rockchip-dwmac.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+)
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +27 -0
@@ -120,6 +120,12 @@ properties: maximum: 0x7F default: 0x10 + pcs-handle: + description: + Specifies a reference to a node representing the PCS device + connected to this GMAC. Required when phy-mode is "sgmii". + maxItems: 1 + phy-supply: description: PHY regulator
@@ -159,6 +165,27 @@ allOf: clocks: minItems: 5 + - if: + properties: + compatible: + contains: + const: rockchip,rk3568-gmac + then: + required: + - phy-mode + + - if: + properties: + compatible: + contains: + const: rockchip,rk3568-gmac + phy-mode: + contains: + const: sgmii + then: + required: + - pcs-handle + unevaluatedProperties: false examples:
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v12 4/6] dt-bindings: net: rockchip-dwmac: document pcs-handle
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The rule that makes pcs-handle required is true even when phy- mode is absent, and the patch adds a redundant rule that the commit…
--
dt-bindings: net: rockchip-dwmac: document pcs-handle
This adds a pcs-handle property to the Rockchip GMAC binding for the SGMII support added later in the series. It also adds two allOf rules for rockchip,rk3568-gmac. The first requires phy-mode. The second requires pcs-handle when phy-mode is "sgmii".
Quoted 4 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +0
-0
[ ... ]
Quoted 14 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +10
-0@@ -159,6 +165,27 @@ allOf: clocks: minItems: 5 + - if: + properties: + compatible: + contains: + const: rockchip,rk3568-gmac + then: + required: + - phy-mode + + - if:
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml allOf: · line 187
Quoted 10 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yaml +10
-0+ properties: + compatible: + contains: + const: rockchip,rk3568-gmac + phy-mode: + contains: + const: sgmii + then: + required: + - pcs-handle
[Severity: Low]
Is the sgmii if above true when phy-mode is missing?
In JSON Schema, a properties subschema passes when the property is not there. That means a rockchip,rk3568-gmac node without phy-mode matches this if. It then gets a "pcs-handle is a required property" error, even though nothing says the link is SGMII.
The standalone phy-mode block before it does not make this if false. Each allOf entry is checked on its own, so that block only adds its own error.
Is the standalone phy-mode block needed at all? rockchip-dwmac.yaml already pulls in snps,dwmac.yaml with "- $ref: snps,dwmac.yaml#" under allOf. That schema already requires phy-mode at the top level:
Documentation/devicetree/bindings/net/snps,dwmac.yaml:
required:
- compatible
- reg
- interrupts
- interrupt-names
- phy-mode
So an rk3568-gmac node with no phy-mode would get two "phy-mode is a required property" errors and a misleading pcs-handle error.
The commit message also does not say that phy-mode becomes mandatory for rk3568. It only says pcs-handle is required when phy-mode is "sgmii".
Could required: [phy-mode] go inside the sgmii if instead, which is the usual idiom? The standalone phy-mode block could then be dropped.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017054406.1828061-1-coiaprant%40gmail.com
Coia Prant
maintainerPATCH v12 5/6 net: stmmac: dwmac-rk: add SGMII support for RK3568
In reply to Coia PrantThe RK3568 SoC integrates a Synopsys DesignWare XPCS that can be connected to GMAC0 or GMAC1 in SGMII mode. Add the necessary glue logic to support this configuration.
The current dwmac-rk driver does not support SGMII mode. SGMII requires a PCS to handle auto-negotiation and link state reporting, but the existing driver only supports RGMII and RMII.
Add a set_to_sgmii() callback to configure the GMAC GRF register for SGMII mode (bit 7 set, interface selection bits 4:6 ignored when set). Also add a set_to_rmii() callback for rk3568 to explicitly clear bit 7, since the new SGMII path leaves it set and the RMII branch previously relied on the SoC reset value.
Provide pcs_init/pcs_exit callbacks to create/destroy the XPCS via xpcs_rk_create() from the Rockchip XPCS platform driver, and a select_pcs callback to return the XPCS to phylink. The MII port passed to xpcs_rk_create() is the GMAC id (bsp_priv->id): GMAC0 maps to port 0, GMAC1 maps to port 1, matching the hardware routing.
SGMII is not added to rk_get_interfaces(): it comes from the XPCS's own supported_interfaces, merged by stmmac_phylink_setup().
The SerDes PHY and the PD_PIPE power domain are owned by the XPCS driver rather than managed through the stmmac serdes_poweron/serdes_poweroff callbacks, which are legacy and meant for single-MAC platforms. On RK3568 the XPCS is the natural owner of the shared SerDes.
DWMAC_ROCKCHIP selects PCS_XPCS_ROCKCHIP. PCS_XPCS itself is already selected by STMMAC_ETH, and PM is selected by ARCH_ROCKCHIP, so no further selects are needed.
Reorder rk_gmac_powerup() so that gmac_clk_enable() is called before the SGMII check. The SGMII path skips rk_get_phy_intf_sel(), so the clock must be enabled earlier to cover all register accesses in that path. While at it, unify the error unwinding into a single clk_disable label and add error handling for the default (unhandled interface) case.
SGMII In-band vs Out-of-band
============================
On RK3568, the MAC clock is fixed at 125 MHz and cannot be changed per speed. Out-of-band mode requires the MAC to change its clock to 125/25/2.5 MHz for 1000/100/10 Mbps respectively, which the hardware does not support here. The driver therefore clears rk_set_clk_tx_rate() and the clock stays at 125 MHz.
The PCS is still told the speed in out-of-band mode (through a BMCR write in xpcs_link_up_sgmii_1000basex()), but the MAC clock does not follow. At 10/100 Mbps this gives working TX and failing RX.
Enable default_an_inband for SGMII and clear rk_set_clk_tx_rate(), so phylink uses in-band mode, where the PCS is responsible for speed/duplex negotiation.
Note that default_an_inband can be overridden by a fixed-link node, and phylink may also fall back to out-of-band if the PHY does not support in-band signalling. Out-of-band SGMII is not supported by this driver. The only out-of-band configuration that would work is 1000BASE-X with a fixed-link, where the MAC clock stays at 125 MHz; 10/100 Mbps gives working TX and failing RX. Boards must use in-band mode (managed = "in-band-status" or an in-band capable PHY).
1000BASE-X is not enabled by this series; it may be added later if there is a user for it.
--- drivers/net/ethernet/stmicro/stmmac/Kconfig | 1 + .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 131 +++++++++++++++--- 2 files changed, 112 insertions(+), 20 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
@@ -170,6 +170,7 @@ config DWMAC_ROCKCHIP default ARCH_ROCKCHIP depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST) select MFD_SYSCON + select PCS_XPCS_ROCKCHIP help Support for Ethernet controller on Rockchip RK3288 SoC.
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +111 -20
250 lines not on this page · raw message
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net-next v12 5/6] net: stmmac: dwmac-rk: add SGMII support for RK3568
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 (2) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] On SGMII, phylink is offered more interface modes than the RK3568 glue can configure.
- [Medium] The commit message says out-of-band SGMII at 10/100 gives working TX and failing RX on RK3568, because the MAC clock is fixed at…
- [Medium] The new SGMII path cannot open a PHY-less in-band link, such as a direct SGMII connection to a switch with managed = "in-band-…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but rk_gmac_resume() throws away the return value of rk_gmac_powerup() and…
- [Medium] This problem wasn't introduced by this patch, but __stmmac_dvr_probe() calls pm_runtime_get_noresume(),…
--
net: stmmac: dwmac-rk: add SGMII support for RK3568
This patch adds SGMII support to the RK3568 dwmac-rk glue. It sets the GRF mode bit and creates the Rockchip XPCS through xpcs_rk_create() in new pcs_init/pcs_exit/select_pcs callbacks, and it asks for in-band mode via default_an_inband. It also reorders rk_gmac_powerup() so the clocks are enabled before the SGMII check, and it merges the error unwinding into one clk_disable label.
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +5
-0@@ -1211,6 +1239,44 @@ static void rk_phy_powerdown(struct rk_priv_data *bsp_priv)dev_err (bsp_priv->dev,"fail to disable phy-supply\n" ); } +static int rk_pcs_init (struct stmmac_priv *priv) +{ +struct rk_priv_data *bsp_priv = priv->plat->bsp_priv; +struct device_node *node = priv->device->of_node; +struct device_node *pcs_node;
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) · line 1256
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +10
-0+struct dw_xpcs *xpcs; + + pcs_node =of_parse_phandle (node,"pcs-handle" ,0 ); +if (!pcs_node) +return -ENODEV ; + + xpcs =xpcs_rk_create (priv->device, pcs_node, bsp_priv->id); +of_node_put (pcs_node); +if (IS_ERR (xpcs)) +return PTR_ERR (xpcs);
[Severity: Medium]
This is a pre-existing issue in the stmmac core, but this new path seems to make it much easier to hit. xpcs_rk_create() returns -EPROBE_DEFER until the XPCS is bound. fw_devlink does not appear to track pcs-handle, so the MAC can probe first.
__stmmac_dvr_probe() takes a runtime PM reference before stmmac_pcs_setup():
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:__stmmac_dvr_probe() {
...
pm_runtime_get_noresume(device);
pm_runtime_set_active(device);
if (!pm_runtime_enabled(device))
pm_runtime_enable(device);
...
error_pcs_setup:
stmmac_mdio_unregister(ndev);
...
}The unwind labels never drop that reference and never disable runtime PM.
Does each deferred probe attempt leak one usage count on the GMAC device? Runtime PM is left enabled, so pm_runtime_reinit() would not reset the count. After the eventual successful probe, the GMAC would then never runtime suspend and its clocks would stay on.
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) · line 1260
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +4
-0+ + priv->hw->xpcs = xpcs; +return 0 ; +}
[Severity: Medium]
Does this work for a PHY-less in-band link? An example would be phy-mode = "sgmii" with managed = "in-band-status", a pcs-handle and no phy-handle.
The PCS is only stored in priv->hw->xpcs, so hw->phylink_pcs stays NULL. In stmmac_init_phy(), phylink_expects_phy() is true for MLO_AN_INBAND, and the xpcs bypass only covers clause 73:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_init_phy() {
...
if (priv->hw->xpcs &&
xpcs_get_an_mode(priv->hw->xpcs, mode) == DW_AN_C73)
return 0;
...
if (addr < 0) {
/* If a custom PCS is in use, no PHY is needed */
if (priv->hw->phylink_pcs)
return 0;
netdev_err(priv->dev, "no phy found\n");
return -ENODEV;
...
}SGMII uses DW_AN_C37_SGMII. With plat->phy_addr == -1, this would log "no phy found" and stmmac_open() would fail with -ENODEV.
If the DT has no mdio subnode, the legacy MDIO scan in stmmac_mdio_register() would instead fail probe with "No PHY found".
The commit message recommends managed = "in-band-status", so is this configuration expected to work?
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +8
-0+ +static void rk_pcs_exit (struct stmmac_priv *priv) +{ +if (!priv->hw->xpcs) +return ; + +xpcs_destroy (priv->hw->xpcs); + priv->hw->xpcs =NULL ;
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) · line 1278
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +10
-0+} + +static struct phylink_pcs *rk_select_pcs (struct stmmac_priv *priv, +phy_interface_t interface) +{ +if (!priv->hw->xpcs) +return NULL ; + +return xpcs_to_phylink_pcs (priv->hw->xpcs); +}
[Severity: Medium]
Can phylink select an interface mode here that the glue never set up?
rk_select_pcs() ignores the interface argument and returns the XPCS for every mode. stmmac_phylink_setup() adds the XPCS supported_interfaces to phylink's set, and the glue does not filter them:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_phylink_setup() {
...
if (priv->hw->xpcs)
pcs = xpcs_to_phylink_pcs(priv->hw->xpcs);
...
phy_interface_or(config->supported_interfaces,
config->supported_interfaces,
pcs->supported_interfaces);
...
}If the XPCS uses the generic synopsys_xpcs_compat table, xpcs_get_interfaces() advertises 1000BASE-X, 2500BASE-X and the 10G+ modes alongside SGMII. The GMAC4 MAC capabilities (MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD) do not rule out 1000BASE-X or 2500BASE-X, so both would pass phylink validation.
The glue only programs SGMII, though. rk_gmac_check_ops(), the rk_gmac_powerup() switch and rk3568_set_to_sgmii() each act once, on the phy-mode from DT.
Take an SFP cage, or a PHY whose possible_interfaces includes 2500BASE-X. Would phylink then move the XPCS into a mode that the GRF, SerDes and MAC path were never configured for?
This also seems to conflict with the commit message:
1000BASE-X is not enabled by this series; it may be added later if there is a user for it.
Should rk_select_pcs() reject anything other than PHY_INTERFACE_MODE_SGMII, or should the supported interfaces be masked down to SGMII?
[ ... ]
Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0
-0@@ -1450,15 +1521,20 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
[ ... ]
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +2
-4ret =rk_phy_powerup (bsp_priv); -if (ret) { -gmac_clk_enable (bsp_priv, false); -return ret; - } +if (ret) + goto clk_disable;pm_runtime_get_sync (dev);
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) · line 1549
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +4
-0@@ -1466,6 +1542,10 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) bsp_priv->ops->integrated_phy_powerup (bsp_priv);return 0 ; + +clk_disable: +gmac_clk_enable (bsp_priv, false); +return ret; }
[Severity: Medium]
This bug was not introduced by this patch, but rk_gmac_resume() ignores the return value of rk_gmac_powerup():
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:rk_gmac_resume() {
...
if (!device_may_wakeup(dev))
rk_gmac_powerup(bsp_priv);
return 0;
}When rk_gmac_powerup() fails, the clk_disable exit runs before rk_phy_powerup() and pm_runtime_get_sync() have been called. A later rk_gmac_suspend() or rk_gmac_exit() still calls rk_gmac_powerdown():
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:rk_gmac_powerdown() {
...
pm_runtime_put_sync(gmac->dev);
rk_phy_powerdown(gmac);
gmac_clk_enable(gmac, false);
}Would a failed resume leave the runtime PM usage count and the phy-supply regulator enable count unbalanced?
The new exits added here (the rk_get_phy_intf_sel() failure and the default case) should not be reachable at resume, because probe has already validated the interface. The clock enable, GRF write and regulator enable failures can still happen.
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_probe(struct platform_device *pdev) · line 1693
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +6
-0@@ -1605,6 +1685,17 @@ static int rk_gmac_probe(struct platform_device *pdev) plat_dat->suspend = rk_gmac_suspend; plat_dat->resume = rk_gmac_resume; +if (plat_dat->phy_interface ==PHY_INTERFACE_MODE_SGMII ) { +/* SGMII clock always runs at 125 MHz */ + plat_dat->set_clk_tx_rate =NULL ; + +/* SGMII requires a PCS */ + plat_dat->default_an_inband = true;
[Severity: Medium]
The commit message says out-of-band SGMII at 10/100 gives working TX and failing RX, because the MAC clock is fixed at 125 MHz. Does anything in the driver enforce or report that limit?
default_an_inband only states a preference. phylink_parse_mode() turns a fixed-link node into MLO_AN_FIXED. A PHY whose phy_inband_caps() reports only LINK_INBAND_DISABLE makes phylink_pcs_neg_mode() fall back:
drivers/net/phy/phylink.c:phylink_pcs_neg_mode() {
...
neg_mode = PHYLINK_PCS_NEG_OUTBAND;
if (pl->phydev)
mode = MLO_AN_PHY;
...
}For SGMII, xpcs_inband_caps() returns LINK_INBAND_DISABLE | LINK_INBAND_ENABLE, so the PCS accepts the out-of-band fallback.
stmmac_mac_link_up() then sets the MAC to 10/100, and xpcs_link_up_sgmii_1000basex() writes the speed into BMCR, but the clock stays at 125 MHz. Would the link then report up while RX silently does not work?
Could the driver reject out-of-band SGMII below 1000 Mbps, or at least warn about it? fix_mac_speed() receives the mode and could do this, or the MAC capabilities could be limited.
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +4
-0+ plat_dat->pcs_init = rk_pcs_init; + plat_dat->pcs_exit = rk_pcs_exit; + plat_dat->select_pcs = rk_select_pcs; + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261017054406.1828061-1-coiaprant%40gmail.com
Coia Prant
maintainerPATCH v12 6/6 MAINTAINERS: add entry for Rockchip XPCS driver
In reply to Coia PrantAdd a MAINTAINERS entry for the Rockchip RK3568 XPCS platform driver and its device tree binding.
Include the relevant mailing lists (netdev and linux-rockchip) so that future patches are properly distributed.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -23757,6 +23757,15 @@ S: Maintained F: Documentation/devicetree/bindings/sound/rockchip,rk3576-sai.yaml F: sound/soc/rockchip/rockchip_sai.* +ROCKCHIP XPCS DRIVER +M: Coia Prant <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/net/pcs/rockchip,rk3568-xpcs.yaml +F: drivers/net/pcs/pcs-xpcs-rk.c +F: include/linux/pcs/pcs-xpcs-rk.h + ROCKER DRIVER M: Jiri Pirko <[email protected]> L: [email protected]
Signature · 1 line
2.47.3
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 13 lines · On Sat, 17 Oct 2026 13:43:58 +0800 you wrote:
This series adds proper SGMII support for the Rockchip RK3568 SoC using the integrated Synopsys DesignWare XPCS, along with necessary fixes and refactoring in the stmmac core and XPCS driver.
Motivation
==========
The RK3568 integrates a DW XPCS accessed via APB3 and connected to a Naneng Combo SerDes PHY. Several boards (e.g., Ariaboard Photonicat) use this interface for Gigabit Ethernet. However, the current upstream stmmac driver does not support this configuration, and the XPCS driver has issues in SGMII poll mode that cause the link to be reported incorrectly.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v12,1/6] net: pcs: xpcs: add ANRESTART support for SGMII link recovery
https://git.kernel.org/netdev/net-next/c/e42329945d16 - [net-next,v12,2/6] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support https://git.kernel.org/netdev/net-next/c/20bd39c3c267 - [net-next,v12,3/6] net: pcs: xpcs: add Rockchip RK3568 platform glue driver https://git.kernel.org/netdev/net-next/c/b9e7cb89aac8 - [net-next,v12,4/6] dt-bindings: net: rockchip-dwmac: document pcs-handle https://git.kernel.org/netdev/net-next/c/dffa8241fca5 - [net-next,v12,5/6] net: stmmac: dwmac-rk: add SGMII support for RK3568 https://git.kernel.org/netdev/net-next/c/5cd3229579ef - [net-next,v12,6/6] MAINTAINERS: add entry for Rockchip XPCS driver https://git.kernel.org/netdev/net-next/c/5e91edfb0e45
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html