Skip to contentSkip to conversation

net-next: add basic support for RK3568 XPCS

PATCH Superseded Coia Prant 6 participants 40 messages Aug 1 – Aug 6

Subsystems (13)

v2 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Coia Prant

author maintainer
#0 lore raw

v2 cover net-next: add basic support for RK3568 XPCS

Changes since v1:

Patch 2 (dt-bindings: phy: naneng-combphy)
- Changed rockchip,sgmii-mac-sel default from 0 to 1 to match hardware reset value (GMAC1)
- Added if-then conditional in allOf to restrict the property to rockchip,rk3568-naneng-combphy only
- Updated commit message to reflect hardware default

Patch 3 (phy: rockchip: naneng-combphy)
- Changed priv->sgmii_mac_sel initial value from 0 to 1 to match hardware default
- Updated commit message to align with binding changes

Patch 4 (dt-bindings: net: pcs: rockchip-dwxpcs)
- Fixed reg format in example to pass dt_binding_check
- Added missing #include <dt-bindings/phy/phy.h> in example

Patch 5 (arm64: dts: rockchip: rk3568)
- Clarified commit message: "all nodes disabled" refers to XPCS device nodes, not fixed-clock nodes
- Noted that assigned-clock-parents are applied at board level (Patch 9), not in SoC dtsi

Patch 6 (net: pcs: xpcs: add ANRESTART support for SGMII link recovery)
- Split the original RFC patch into two: the SGMII state reading fix was sent separately to the net tree and has been merged. This patch now only adds the ANRESTART functionality as a new feature for net-next.
- Removed unintentional BMCR_ANRESTART change in c37_1000basex (this was not tested and should not have been included)
- Kept SGMII path changes for RK3568 only

Patch 7 (net: pcs: xpcs: add Rockchip RK3568 platform glue driver)
- Added .remove callback with pm_runtime_force_suspend() to fix potential CSR clock leak on device removal
- Added compatible string validation in xpcs_rk_create() before dereferencing drvdata (using of_match_node(xpcs_rk_of_ids, pcs_np))
- Removed __maybe_unused from PM runtime callbacks
- Add depends on PM in Kconfig to ensure CONFIG_PM is enabled for this driver

Patch 8 (net: stmmac: dwmac-rk)
- Moved gmac_clk_enable() call before SGMII check to ensure clocks are enabled before register access in SGMII mode
- Added unified error handling (clk_disable label) for all failure paths
- Added error handling for default (unhandled interface) case

===

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:
- Fixing the XPCS driver's SGMII AN state handling
- Refactoring stmmac PCS lifetime management to allow platform drivers full control over PCS creation/destruction
- Adding a Rockchip XPCS platform glue driver and wiring it up in dwmac-rk

Series overview
===============

Generic:
Patch 1: move XPCS lifetime management to platform drivers
(introduces pcs_init/pcs_exit callbacks)

PHY:
Patch 2: DT binding for Naneng Combo PHY SGMII MAC selection Patch 3: implement the PHY SGMII MAC selection in driver

RK3568 XPCS/SGMII:
Patch 4: DT binding for Rockchip RK3568 XPCS Patch 5: add XPCS and fixed-clock nodes to rk3568.dtsi Patch 6: add ANRESTART support for SGMII link recovery Patch 7: implement the Rockchip XPCS platform glue driver Patch 8: wire up SGMII support in dwmac-rk
Patch 10: update MAINTAINERS

Board enablement:
Patch 9: enable SGMII LAN port on Photonicat board

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.

Dependencies
============
None. All patches apply cleanly on top of torvalds master tree (v7.2).

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 (10):
net: stmmac: move XPCS lifetime management to platform drivers
dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel
property
phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568
dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding
arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
net: pcs: xpcs: add ANRESTART support for SGMII link recovery
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
net: stmmac: dwmac-rk: add SGMII support for RK3568
arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port
MAINTAINERS: add entry for Rockchip XPCS driver

 .../bindings/net/pcs/rockchip-dwxpcs.yaml     | 127 +++++
 .../phy/phy-rockchip-naneng-combphy.yaml      |  13 +
 MAINTAINERS                                   |   9 +
 .../boot/dts/rockchip/rk3568-photonicat.dts   |  77 ++-
 arch/arm64/boot/dts/rockchip/rk3568.dtsi      |  45 ++
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |   1 +
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c |  44 +-
 .../stmicro/stmmac/dwmac-renesas-gbeth.c      |   7 +-
 .../net/ethernet/stmicro/stmmac/dwmac-rk.c    | 121 +++-
 .../net/ethernet/stmicro/stmmac/dwmac-rzn1.c  |   7 +-
 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   |   7 +-
 .../net/ethernet/stmicro/stmmac/stmmac_mdio.c |  37 +-
 drivers/net/pcs/Kconfig                       |  23 +
 drivers/net/pcs/Makefile                      |   7 +-
 drivers/net/pcs/pcs-xpcs-rk.c                 | 538 ++++++++++++++++++
 drivers/net/pcs/pcs-xpcs.c                    |  17 +-
 .../rockchip/phy-rockchip-naneng-combphy.c    |   8 +
 include/linux/pcs/pcs-xpcs-rk.h               |  11 +
 18 files changed, 1030 insertions(+), 69 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.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
author maintainer
#1 lore raw

PATCH v2 1/10 net: stmmac: move XPCS lifetime management to platform drivers

The current XPCS creation logic in stmmac_pcs_setup() is problematic for several reasons.

First, if a device tree specifies a "pcs-handle" but no select_pcs() callback is provided by the platform driver, the created XPCS is never used. The phylink framework requires select_pcs() to actually return the PCS to the core, so the pcs-handle property becomes effectively useless without the matching callback. This is confusing for developers who expect that specifying a pcs-handle in their device tree should be sufficient to enable the PCS.

Second, and more critically, when stmmac_pcs_setup() fails to create an XPCS (either because no pcs-handle is present and no pcs_mask is configured), it falls through to the else branch and leaves priv->hw->xpcs as NULL. This will silently override any XPCS that a platform driver may have already set up during its own initialization, for example in a pcs_init() callback or during probe. The platform driver has no way to prevent this override because the common code runs unconditionally after the platform-specific initialization.

After commit 93f84152e4ae ("net: stmmac: clean up stmmac_mac_select_pcs()"), the common code no longer falls back to priv->hw->phylink_pcs if select_pcs() is not set. This change reinforces that each platform must manage its own PCS life cycle explicitly, but the XPCS creation code in stmmac_pcs_setup() was not updated to match this new expectation, leaving a gap where platform drivers have no clean way to take control of XPCS creation.

Address all of these issues by introducing pcs_init() and pcs_exit() callbacks in plat_stmmacenet_data. These callbacks give platform drivers full control over when and how the XPCS is created, configured, and destroyed. The common stmmac_pcs_setup() and stmmac_pcs_clean() functions are simplified to just call these callbacks, removing the confusing and error-prone XPCS creation logic from the common code.

Platforms that do not need an XPCS simply leave the callbacks as NULL and no change in behavior occurs. Platforms that do need an XPCS can now create it with the exact configuration they require, including wrapping it with custom phylink_pcs_ops when necessary.

Existing platform drivers (intel, rzn1, socfpga) are updated to use the new callbacks by moving their XPCS creation and cleanup logic into pcs_init() and pcs_exit(). In their pcs_exit() implementations, the pointer to the destroyed PCS is explicitly set to NULL to avoid dangling pointer references.

---
 .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 44 +++++++++++++++++--
 .../stmicro/stmmac/dwmac-renesas-gbeth.c      |  7 ++-
 .../net/ethernet/stmicro/stmmac/dwmac-rzn1.c  |  7 ++-
 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   |  7 ++-
 .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 37 +++-------------
 5 files changed, 61 insertions(+), 41 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +40 -4
index 4d207f41a43b3..221b3203a81ed 100644
@@ -603,13 +603,47 @@ static void common_default_data(struct plat_stmmacenet_data *plat)
 	plat->mdio_bus_data->needs_reset = true;
 }
 
+static int intel_mgbe_pcs_init(struct stmmac_priv *priv)
+{
+	struct fwnode_handle *devnode, *pcsnode;
+	struct dw_xpcs *xpcs = NULL;
+	int addr;
+
+	devnode = dev_fwnode(priv->device);
+
+	if (fwnode_property_present(devnode, "pcs-handle")) {
+		pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0);
+		xpcs = xpcs_create_fwnode(pcsnode);
+		fwnode_handle_put(pcsnode);
+	} else {
+		addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1;
+		xpcs = xpcs_create_mdiodev(priv->mii, addr);
+	}
+
+	if (IS_ERR(xpcs))
+		return PTR_ERR(xpcs);
+
+	xpcs_config_eee_mult_fact(xpcs, priv->plat->mult_fact_100ns);
+
+	priv->hw->xpcs = xpcs;
+	return 0;
+}
+
+static void intel_mgbe_pcs_exit(struct stmmac_priv *priv)
+{
+	if (!priv->hw->xpcs)
+		return;
+
+	xpcs_destroy(priv->hw->xpcs);
+	priv->hw->xpcs = NULL;
+}
+
 static struct phylink_pcs *intel_mgbe_select_pcs(struct stmmac_priv *priv,
 						 phy_interface_t interface)
 {
-	/* plat->mdio_bus_data->has_xpcs has been set true, so there
-	 * should always be an XPCS. The original code would always
-	 * return this if present.
-	 */
+	if (!priv->hw->xpcs)
+		return NULL;
+
 	return xpcs_to_phylink_pcs(priv->hw->xpcs);
 }
 
@@ -733,6 +767,8 @@ static int intel_mgbe_common_data(struct pci_dev *pdev,
 	    plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) {
 		plat->mdio_bus_data->pcs_mask = BIT_U32(INTEL_MGBE_XPCS_ADDR);
 		plat->default_an_inband = true;
+		plat->pcs_init = intel_mgbe_pcs_init;
+		plat->pcs_exit = intel_mgbe_pcs_exit;
 		plat->select_pcs = intel_mgbe_select_pcs;
 	}
 
drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +5 -2
index 19f34e18bfef2..9af32c26f9c14 100644
@@ -81,8 +81,11 @@ static int renesas_gmac_pcs_init(struct stmmac_priv *priv)
 
 static void renesas_gmac_pcs_exit(struct stmmac_priv *priv)
 {
-	if (priv->hw->phylink_pcs)
-		miic_destroy(priv->hw->phylink_pcs);
+	if (!priv->hw->phylink_pcs)
+		return;
+
+	miic_destroy(priv->hw->phylink_pcs);
+	priv->hw->phylink_pcs = NULL;
 }
 
 static struct phylink_pcs *renesas_gmac_select_pcs(struct stmmac_priv *priv,
drivers/net/ethernet/stmicro/stmmac/dwmac-rzn1.c +5 -2
index 13634965bc19a..01df4776edb3f 100644
@@ -35,8 +35,11 @@ static int rzn1_dwmac_pcs_init(struct stmmac_priv *priv)
 
 static void rzn1_dwmac_pcs_exit(struct stmmac_priv *priv)
 {
-	if (priv->hw->phylink_pcs)
-		miic_destroy(priv->hw->phylink_pcs);
+	if (!priv->hw->phylink_pcs)
+		return;
+
+	miic_destroy(priv->hw->phylink_pcs);
+	priv->hw->phylink_pcs = NULL;
 }
 
 static struct phylink_pcs *rzn1_dwmac_select_pcs(struct stmmac_priv *priv,
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +5 -2
index 1d7f0a57d2889..6d4bc1fe8f751 100644
@@ -539,8 +539,11 @@ static int socfpga_dwmac_pcs_init(struct stmmac_priv *priv)
 
 static void socfpga_dwmac_pcs_exit(struct stmmac_priv *priv)
 {
-	if (priv->hw->phylink_pcs)
-		lynx_pcs_destroy(priv->hw->phylink_pcs);
+	if (!priv->hw->phylink_pcs)
+		return;
+
+	lynx_pcs_destroy(priv->hw->phylink_pcs);
+	priv->hw->phylink_pcs = NULL;
 }
 
 static struct phylink_pcs *socfpga_dwmac_select_pcs(struct stmmac_priv *priv,
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +6 -31
index afe98ff5bdcb0..d2f77f0c223a7 100644
@@ -426,36 +426,15 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 int stmmac_pcs_setup(struct net_device *ndev)
 {
 	struct stmmac_priv *priv = netdev_priv(ndev);
-	struct fwnode_handle *devnode, *pcsnode;
-	struct dw_xpcs *xpcs = NULL;
-	int addr, ret;
-
-	devnode = dev_fwnode(priv->device);
-
-	if (priv->plat->pcs_init) {
-		ret = priv->plat->pcs_init(priv);
-	} else if (fwnode_property_present(devnode, "pcs-handle")) {
-		pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0);
-		xpcs = xpcs_create_fwnode(pcsnode);
-		fwnode_handle_put(pcsnode);
-		ret = PTR_ERR_OR_ZERO(xpcs);
-	} else if (priv->plat->mdio_bus_data &&
-		   priv->plat->mdio_bus_data->pcs_mask) {
-		addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1;
-		xpcs = xpcs_create_mdiodev(priv->mii, addr);
-		ret = PTR_ERR_OR_ZERO(xpcs);
-	} else {
+	int ret;
+
+	if (!priv->plat->pcs_init)
 		return 0;
-	}
 
+	ret = priv->plat->pcs_init(priv);
 	if (ret)
 		return dev_err_probe(priv->device, ret, "No xPCS found\n");
 
-	if (xpcs)
-		xpcs_config_eee_mult_fact(xpcs, priv->plat->mult_fact_100ns);
-
-	priv->hw->xpcs = xpcs;
-
 	return 0;
 }
 
@@ -463,14 +442,10 @@ void stmmac_pcs_clean(struct net_device *ndev)
 {
 	struct stmmac_priv *priv = netdev_priv(ndev);
 
-	if (priv->plat->pcs_exit)
-		priv->plat->pcs_exit(priv);
-
-	if (!priv->hw->xpcs)
+	if (!priv->plat->pcs_exit)
 		return;
 
-	xpcs_destroy(priv->hw->xpcs);
-	priv->hw->xpcs = NULL;
+	priv->plat->pcs_exit(priv);
 }
 
 struct stmmac_clk_rate {
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH v2 2/10 dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property

In reply to Coia Prant

On RK3568, the SGMII interface can be routed to either GMAC0 or GMAC1 via the pipe_sgmii_mac_sel bit in the pipe GRF registers.

Add the optional "rockchip,sgmii-mac-sel" property to allow the device tree to select which GMAC controller is used for SGMII.

The property takes a value of 0 (GMAC0) or 1 (GMAC1). The hardware reset value is 1 (GMAC1), but this can be overridden by setting the property to 0 for boards where SGMII is connected to GMAC0.

This is necessary for boards such as the Ariaboard Photonicat, where the SGMII interface is connected to GMAC0 and needs to be explicitly configured.

---
 .../bindings/phy/phy-rockchip-naneng-combphy.yaml   | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/phy/phy-rockchip-naneng-combphy.yaml +13 -0
index 379b08bd9e97a..8e898bce9af73 100644
@@ -80,6 +80,15 @@ properties:
     description:
       Some additional pipe settings are accessed through GRF regs.
 
+  rockchip,sgmii-mac-sel:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1]
+    default: 1
+    description:
+      Select gmac0 or gmac1 to be used as SGMII controller.
+      The hardware reset value is GMAC1 (1). Set this to 0 to route
+      SGMII to GMAC0.
+
   "#phy-cells":
     const: 1
 
@@ -105,6 +114,10 @@ allOf:
           maxItems: 1
         reset-names:
           maxItems: 1
+        rockchip,sgmii-mac-sel: true
+    else:
+      properties:
+        rockchip,sgmii-mac-sel: false
   - if:
       properties:
         compatible:
Signature · 1 line
2.47.3
#3 lore raw

Re: [PATCH v2 02/10] dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `rockchip,sgmii-mac-sel` property is defined in the device tree bindings but is not…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The rockchip,sgmii-mac-sel property is defined in the device tree bindings but is not implemented in any kernel driver. --

--- Patch [2]: [PATCH v2 02/10] dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property --- commit d067678ae28ccb1e1d1f20a8cb8013f22a387abc
Author: Coia Prant <[email protected]>

dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property

This commit adds the optional rockchip,sgmii-mac-sel property to the Rockchip Naneng combphy device tree binding. The property is intended to allow routing the SGMII interface to either GMAC0 or GMAC1 via GRF registers.

Quoted 3 lines
Documentation/devicetree/bindings/phy/phy-rockchip-naneng-combphy.yaml +0 -0

[ ... ]

Documentation/devicetree/bindings/phy/phy-rockchip-naneng-combphy.yaml properties: · line 85

Quoted 7 lines
Documentation/devicetree/bindings/phy/phy-rockchip-naneng-combphy.yaml +3 -0
@@ -80,6 +80,15 @@ properties:
     description:
       Some additional pipe settings are accessed through GRF regs.
 
+  rockchip,sgmii-mac-sel:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 1]

[Severity: Medium]
Is the driver implementation for this property missing from the series?

The device tree binding defines rockchip,sgmii-mac-sel, but it appears no kernel driver currently parses this property or writes the corresponding configuration to the GRF registers.

Without driver support, boards relying on this property to configure the MAC will fail to route SGMII to GMAC0, leaving it at the default GMAC1.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#4 lore raw

PATCH v2 3/10 phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568

In reply to Coia Prant

On RK3568, the SGMII interface can be routed to either GMAC0 or GMAC1 via the GRF register pipe_sgmii_mac_sel.

Add support for this selection by introducing
the "rockchip,sgmii-mac-sel" DT property.

The hardware reset value is GMAC1 (1). If the property is set to 0, the driver routes SGMII to GMAC0; if set to 1 (or omitted), it remains at GMAC1.

This is necessary for boards such as the Ariaboard Photonicat, which uses the SGMII interface connected to GMAC0.

---
 drivers/phy/rockchip/phy-rockchip-naneng-combphy.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +8 -0
index 2b0f152f54709..539acd1459948 100644
@@ -186,6 +186,7 @@ struct rockchip_combphy_grfcfg {
 	struct combphy_reg pipe_xpcs_phy_ready;
 	struct combphy_reg pipe_pcie1l0_sel;
 	struct combphy_reg pipe_pcie1l1_sel;
+	struct combphy_reg pipe_sgmii_mac_sel;
 	struct combphy_reg u3otg0_port_en;
 	struct combphy_reg u3otg1_port_en;
 };
@@ -212,6 +213,7 @@ struct rockchip_combphy_priv {
 	bool enable_ssc;
 	bool ext_refclk;
 	struct clk *refclk;
+	u32 sgmii_mac_sel;
 };
 
 static void rockchip_combphy_updatel(struct rockchip_combphy_priv *priv,
@@ -375,6 +377,9 @@ static int rockchip_combphy_parse_dt(struct device *dev, struct rockchip_combphy
 
 	priv->ext_refclk = device_property_present(dev, "rockchip,ext-refclk");
 
+	priv->sgmii_mac_sel = 1;
+	device_property_read_u32(dev, "rockchip,sgmii-mac-sel", &priv->sgmii_mac_sel);
+
 	priv->phy_rst = devm_reset_control_get_exclusive(dev, "phy");
 	/* fallback to old behaviour */
 	if (PTR_ERR(priv->phy_rst) == -ENOENT)
@@ -873,6 +878,8 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)
 		break;
 
 	case PHY_TYPE_SGMII:
+		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_sgmii_mac_sel,
+					priv->sgmii_mac_sel > 0);
 		rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true);
 		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true);
 		rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true);
@@ -984,6 +991,7 @@ static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = {
 	.con3_for_sata		= { 0x000c, 15, 0, 0x00, 0x4407 },
 	/* pipe-grf */
 	.pipe_con0_for_sata	= { 0x0000, 15, 0, 0x00, 0x2220 },
+	.pipe_sgmii_mac_sel	= { 0x0040, 1, 1, 0x00, 0x01 },
 	.pipe_xpcs_phy_ready	= { 0x0040, 2, 2, 0x00, 0x01 },
 	.u3otg0_port_en		= { 0x0104, 15, 0, 0x0181, 0x1100 },
 	.u3otg1_port_en		= { 0x0144, 15, 0, 0x0181, 0x1100 },
Signature · 1 line
2.47.3
maintainer
#5 lore raw

Re: [PATCH v2 03/10] phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568

Quoted 6 lines · Coia Prant

On RK3568, the SGMII interface can be routed to either GMAC0 or GMAC1 via the GRF register pipe_sgmii_mac_sel.

Add support for this selection by introducing
the "rockchip,sgmii-mac-sel" DT property.

Quoted 6 lines

The hardware reset value is GMAC1 (1). If the property is set to 0, the driver routes SGMII to GMAC0; if set to 1 (or omitted), it remains at GMAC1.

This is necessary for boards such as the Ariaboard Photonicat, which uses the SGMII interface connected to GMAC0.

If SGMII is not selected, what MII is used? RGMII?

Can this setting be implied from phy-mode?

Andrew

author maintainer
#6 lore raw

Re: [PATCH v2 03/10] phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568

Quoted 11 lines · Andrew Lunn
Quoted 10 lines · Coia Prant

On RK3568, the SGMII interface can be routed to either GMAC0 or GMAC1 via the GRF register pipe_sgmii_mac_sel.

Add support for this selection by introducing
the "rockchip,sgmii-mac-sel" DT property.

The hardware reset value is GMAC1 (1). If the property is set to 0, the driver routes SGMII to GMAC0; if set to 1 (or omitted), it remains at GMAC1.

Quoted 8 lines
Quoted 2 lines

This is necessary for boards such as the Ariaboard Photonicat, which uses the SGMII interface connected to GMAC0.

If SGMII is not selected, what MII is used? RGMII?

Can this setting be implied from phy-mode?

Andrew

Hi Andrew,

If phy-mode is not "sgmii" (e.g., "rgmii" or "rmii"), the GMAC works in the corresponding mode and this register is not touched. The reset default (GMAC1) remains, but it has no effect in non-SGMII modes because the register only controls SGMII signal routing.

Regarding inference from phy-mode: phy-mode = "sgmii" only tells the MAC driver that the interface is SGMII. It does not specify whether the SGMII signals are physically routed to GMAC0 or GMAC1 on the board. That routing is a board-level decision and cannot be derived from any other DT property.

Also, the PHY (Naneng Combo PHY) is initialized by the XPCS glue driver (pcs-xpcs-rk), not by the GMAC driver. The PHY driver has no way to know which GMAC is using it. Making the PHY aware of the MAC ID would require significant changes to the PHY layer, which is out of scope for this series.

Therefore, an explicit DT property is the cleanest and most maintainable way to describe this hardware routing.

Thanks,
Coia

author maintainer
#7 lore raw

PATCH v2 4/10 dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

In reply to Coia Prant

Add 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 binding describes:
- Required properties: compatible, reg, clocks, clock-names
- Optional properties: phys, phy-names, power-domains
- pcs-mii sub-nodes for each MII port (reg 0..3)

---
 .../bindings/net/pcs/rockchip-dwxpcs.yaml     | 127 ++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +127 -0
new file mode 100644
index 0000000000000..3e3f3a388d822
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pcs/rockchip-dwxpcs.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.
+
+  The block contains four MII ports ([email protected]) that can be
+  individually enabled and routed to one of the Ethernet GMAC controllers
+  via the pcs-handle property in the MAC device tree node.
+
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.
+    maxItems: 1
+
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |
+      The phandle of SerDes PHY (Naneng Combo PHY) that provides
+      the serial lanes for 1000BASE-X / SGMII / QSGMII.
+      The SerDes must be powered on and initialised before any XPCS
+      register access.
+    maxItems: 1
+
+  phy-names:
+    const: serdes
+
+  power-domains:
+    description: |
+      Power domain for the XPCS.
+      On RK3568 this is typically the PD_PIPE power domain, which also
+      supplies the SerDes PHY.
+    maxItems: 1
+
+patternProperties:
+  "^pcs-mii@[0-3]$":
+    type: object
+    description: |
+      One of the four MII ports of the XPCS.
+      The port number is specified by the reg property (0..3).
+      The port is linked to an Ethernet MAC controller via the
+      pcs-handle property in the MAC's device tree node.
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3
+        description: |
+          MII port number of PCS.
+
+      status: true
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/rk3568-cru.h>
+    #include <dt-bindings/power/rk3568-power.h>
+    #include <dt-bindings/phy/phy.h>
+
+    pcs@fda00000 {
+      compatible = "rockchip,rk3568-xpcs";
+      #address-cells = <1>;
+      #size-cells = <0>;
+      reg = <0xfda00000 0x200000>;
+      clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+      clock-names = "csr", "eee";
+      phys = <&combphy2 PHY_TYPE_SGMII>;
+      phy-names = "serdes";
+      power-domains = <&power RK3568_PD_PIPE>;
+
+      pcs-mii@0 {
+        reg = <0>;
+      };
+    };
Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing XPCS initialization for Rockchip DWMAC (Hardware Initialization Failure). - [Low] Invalid…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing XPCS initialization for Rockchip DWMAC (Hardware Initialization Failure).
- [Low] Invalid use of 'minimum' and 'maximum' constraints on the 'reg' property in the subnode. --

--- Patch [4]: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding --- commit 3427e61df71bfcc8fb661a8f120af0f4c141f21b
Author: Coia Prant <[email protected]>

dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

Add device tree binding documentation for the Synopsys DesignWare XPCS integrated on the Rockchip RK3568 SoC.

Quoted 4 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +0 -0
new file mode 100644

[ ... ]

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 83

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+patternProperties:
+  "^pcs-mii@[0-3]$":
+    type: object
+    description: |
+      One of the four MII ports of the XPCS.
+      The port number is specified by the reg property (0..3).
+      The port is linked to an Ethernet MAC controller via the
+      pcs-handle property in the MAC's device tree node.

[Severity: High]
How is the pcs-handle property parsed by the Rockchip driver in practice?

With the generic pcs-handle parsing logic removed from stmmac_pcs_setup() in favor of the platform-specific pcs_init callback:

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c:stmmac_pcs_setup() {
	if (!priv->plat->pcs_init)
		return 0;

	ret = priv->plat->pcs_init(priv);
}

Does the Rockchip DWMAC driver provide this callback? If not, it seems stmmac_pcs_setup() will silently return 0 without parsing the pcs-handle, leaving the XPCS uninitialized and breaking the SGMII/QSGMII support described here.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 88

Quoted 5 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5 -0
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3

[Severity: Low]
Does applying scalar numeric constraints like minimum and maximum directly to the reg property cause a meta-schema validation error during
make dt_binding_check?

In the dtschema core, reg evaluates to an array of integers rather than a scalar, so strict JSON schema validation typically fails with an error that minimum is not allowed for an array.

Could this be constrained as an array item instead, or omitted entirely in favor of maxItems: 1 since the node name regex (^pcs-mii@[0-3]$) already enforces the port number?

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+        description: |
+          MII port number of PCS.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

Re: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

In reply to Coia Prant
Quoted 11 lines · Coia Prant

Add 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 binding describes:
- Required properties: compatible, reg, clocks, clock-names
- Optional properties: phys, phy-names, power-domains
- pcs-mii sub-nodes for each MII port (reg 0..3)

Irrelevant paragraph. We can read the diff. Drop.

A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Quoted 38 lines
---
 .../bindings/net/pcs/rockchip-dwxpcs.yaml     | 127 ++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +25 -0
new file mode 100644
index 0000000000000..3e3f3a388d822
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pcs/rockchip-dwxpcs.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.
+
+  The block contains four MII ports ([email protected]) that can be
+  individually enabled and routed to one of the Ethernet GMAC controllers
+  via the pcs-handle property in the MAC device tree node.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10 -0
+
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

reg is always the second property.

Also, use consistent style of quotes.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 40

Quoted 5 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5 -0
+
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.

Drop description, redundant.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 51

Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +11 -0
+    maxItems: 1
+
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2

No, instead list items with description.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 59

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 71

Quoted 12 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +12 -0
+      The phandle of SerDes PHY (Naneng Combo PHY) that provides
+      the serial lanes for 1000BASE-X / SGMII / QSGMII.
+      The SerDes must be powered on and initialised before any XPCS
+      register access.
+    maxItems: 1
+
+  phy-names:
+    const: serdes
+
+  power-domains:
+    description: |
+      Power domain for the XPCS.

Drop sentence and |

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 77

Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6 -0
+      On RK3568 this is typically the PD_PIPE power domain, which also
+      supplies the SerDes PHY.
+    maxItems: 1
+
+patternProperties:
+  "^pcs-mii@[0-3]$":

Why git grep pcs-mii@ gives me no results? Are you doing this similarly to existing devices or is this quite different device than every other hardware?

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 79

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+    type: object
+    description: |

Same here

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 81

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+      One of the four MII ports of the XPCS.
+      The port number is specified by the reg property (0..3).

Drop sentence, redundant. Schema tells that.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 89

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+      The port is linked to an Ethernet MAC controller via the
+      pcs-handle property in the MAC's device tree node.
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3
+        description: |

As well

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 92

Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3 -0
+          MII port number of PCS.
+
+      status: true

Nope, do you see anywhere code like this?

Quoted 38 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +35 -0
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/rk3568-cru.h>
+    #include <dt-bindings/power/rk3568-power.h>
+    #include <dt-bindings/phy/phy.h>
+
+    pcs@fda00000 {
+      compatible = "rockchip,rk3568-xpcs";
+      #address-cells = <1>;
+      #size-cells = <0>;
+      reg = <0xfda00000 0x200000>;
+      clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+      clock-names = "csr", "eee";
+      phys = <&combphy2 PHY_TYPE_SGMII>;
+      phy-names = "serdes";
+      power-domains = <&power RK3568_PD_PIPE>;
+
+      pcs-mii@0 {
+        reg = <0>;
+      };
+    };
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

Re: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

Hi Krzysztof,

Thanks for the detailed review. Here's my response to each point:

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +11 -0
+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).
Quoted 8 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 25

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+
+  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.
+
+  The block contains four MII ports ([email protected]) that can be
+  individually enabled and routed to one of the Ethernet GMAC controllers
+  via the pcs-handle property in the MAC device tree node.

1. Commit message: I'll drop the redundant description paragraph and keep only the essential information.

2. Subject: I'll drop the redundant "binding" word.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 35

Quoted 9 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +9 -0
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

3. reg order: I'll move reg to the second property (after compatible).

4. Quotes: I'll use consistent quoting style throughout.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 40

Quoted 4 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +4 -0
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.

5. reg description: I'll drop it as redundant.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 51

Quoted 9 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +9 -0
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2

6. clocks: I'll change to items with descriptions instead of min/maxItems.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 59

Quoted 7 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +7 -0
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |

7. description formatting: I'll remove unnecessary '|' where not needed.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 71

Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3 -0
+  power-domains:
+    description: |
+      Power domain for the XPCS.

8. power-domains description: I'll drop the redundant part.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 77

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+patternProperties:
+  "^pcs-mii@[0-3]$":

9. pcs-mii naming: I used "pcs-mii" because the Rockchip TRM refers to these as "MII ports" and they are functionally PCS instances. I do see a similar pattern in the Renesas RZN1 MIIC binding (renesas,rzn1-miic.yaml), which uses "mii-conv@[0-5]$" for its ports. So the idea of having child nodes per port is not new.

If you prefer a different name (e.g., "port@0"-"port@3" or "pcs@0"-"pcs@3"), I'm happy to change it. Please let me know what naming you'd recommend.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 88

Quoted 4 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +4 -0
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3

10. reg constraints: I'll fix the min/max constraint to use items (or drop it since the node name regex already enforces the range).

Quoted 1 line

+ status: true

11. status property: I'll remove it, as it's a generic property and doesn't need explicit declaration.

Thanks,
Coia

Quoted 198 lines · Krzysztof Kozlowski <[email protected]> 于2026年8月5日周三 15:29写道:
Quoted 11 lines · Coia Prant

Add 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 binding describes:
- Required properties: compatible, reg, clocks, clock-names
- Optional properties: phys, phy-names, power-domains
- pcs-mii sub-nodes for each MII port (reg 0..3)

Irrelevant paragraph. We can read the diff. Drop.

A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Quoted 38 lines
---
 .../bindings/net/pcs/rockchip-dwxpcs.yaml     | 127 ++++++++++++++++++
 1 file changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +25 -0
new file mode 100644
index 0000000000000..3e3f3a388d822
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/pcs/rockchip-dwxpcs.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.
+
+  The block contains four MII ports ([email protected]) that can be
+  individually enabled and routed to one of the Ethernet GMAC controllers
+  via the pcs-handle property in the MAC device tree node.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10 -0
+
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

reg is always the second property.

Also, use consistent style of quotes.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 40

Quoted 5 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5 -0
+
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.

Drop description, redundant.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 51

Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +11 -0
+    maxItems: 1
+
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2

No, instead list items with description.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 59

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 71

Quoted 12 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +12 -0
+      The phandle of SerDes PHY (Naneng Combo PHY) that provides
+      the serial lanes for 1000BASE-X / SGMII / QSGMII.
+      The SerDes must be powered on and initialised before any XPCS
+      register access.
+    maxItems: 1
+
+  phy-names:
+    const: serdes
+
+  power-domains:
+    description: |
+      Power domain for the XPCS.

Drop sentence and |

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 77

Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6 -0
+      On RK3568 this is typically the PD_PIPE power domain, which also
+      supplies the SerDes PHY.
+    maxItems: 1
+
+patternProperties:
+  "^pcs-mii@[0-3]$":

Why git grep pcs-mii@ gives me no results? Are you doing this similarly to existing devices or is this quite different device than every other hardware?

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 79

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+    type: object
+    description: |

Same here

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 81

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+      One of the four MII ports of the XPCS.
+      The port number is specified by the reg property (0..3).

Drop sentence, redundant. Schema tells that.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 89

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+      The port is linked to an Ethernet MAC controller via the
+      pcs-handle property in the MAC's device tree node.
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3
+        description: |

As well

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 92

Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3 -0
+          MII port number of PCS.
+
+      status: true

Nope, do you see anywhere code like this?

Quoted 38 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +35 -1
+
+    required:
+      - reg
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/rk3568-cru.h>
+    #include <dt-bindings/power/rk3568-power.h>
+    #include <dt-bindings/phy/phy.h>
+
+    pcs@fda00000 {
+      compatible = "rockchip,rk3568-xpcs";
+      #address-cells = <1>;
+      #size-cells = <0>;
+      reg = <0xfda00000 0x200000>;
+      clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+      clock-names = "csr", "eee";
+      phys = <&combphy2 PHY_TYPE_SGMII>;
+      phy-names = "serdes";
+      power-domains = <&power RK3568_PD_PIPE>;
+
+      pcs-mii@0 {
+        reg = <0>;
+      };
+    };
--

2.47.3

#11 lore raw

Re: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

Quoted 70 lines · Coia Prant

Hi Krzysztof,

Thanks for the detailed review. Here's my response to each point:

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +11 -0
+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).
Quoted 8 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 25

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+
+  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.
+
+  The block contains four MII ports ([email protected]) that can be
+  individually enabled and routed to one of the Ethernet GMAC controllers
+  via the pcs-handle property in the MAC device tree node.

1. Commit message: I'll drop the redundant description paragraph and keep only the essential information.

2. Subject: I'll drop the redundant "binding" word.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 35

Quoted 9 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +9 -0
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

3. reg order: I'll move reg to the second property (after compatible).

4. Quotes: I'll use consistent quoting style throughout.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 40

Quoted 4 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +4 -0
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.

5. reg description: I'll drop it as redundant.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 51

Quoted 9 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +9 -0
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2

6. clocks: I'll change to items with descriptions instead of min/maxItems.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 59

Quoted 7 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +7 -0
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |
Quoted 7 lines

7. description formatting: I'll remove unnecessary '|' where not needed.

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 71

Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3 -0
+  power-domains:
+    description: |
+      Power domain for the XPCS.

8. power-domains description: I'll drop the redundant part.

I don't understand any of these. There are none of my quotes. I don't get what you are referring to.

Best regards,
Krzysztof

author maintainer
#12 lore raw

Re: [PATCH v2 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs binding

In reply to Krzysztof Kozlowski

Hi Krzysztof,

Quoted 2 lines · Krzysztof Kozlowski <[email protected]> 于2026年8月6日周四 14:49写道:

I don't understand any of these. There are none of my quotes. I don't get what you are referring to.

Sorry for the confusing previous reply, I didn't quote your original comments properly. Here's a clean response with your points quoted.

Quoted 14 lines · Krzysztof Kozlowski <[email protected]> 于2026年8月5日周三 15:29写道:
Quoted 11 lines · Coia Prant

Add 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 binding describes:
- Required properties: compatible, reg, clocks, clock-names
- Optional properties: phys, phy-names, power-domains
- pcs-mii sub-nodes for each MII port (reg 0..3)

Quoted 5 lines

Irrelevant paragraph. We can read the diff. Drop.
A nit, subject: drop second/last, redundant "binding". The "dt-bindings" prefix is already stating that these are bindings. See also:
https://elixir.bootlin.com/linux/v7.1-rc7/source/Documentation/devicetree/bindings/submitting-patches.rst#L23

Okay. I will drop these in v3.

Quoted 12 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 35

Quoted 9 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +9 -0
+properties:
+  compatible:
+    const: rockchip,rk3568-xpcs
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0

reg is always the second property.

Quoted 1 line

Also, use consistent style of quotes.

Okay.

Quoted 7 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 40

Quoted 5 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5 -0
+
+  reg:
+    description: |
+      Base address and size of the XPCS register space mapped over the
+      APB3 bus.

Drop description, redundant.

I'll drop the redundant description paragraph from the commit message and keep only the essential information.

Quoted 12 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 51

Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +11 -0
+    maxItems: 1
+
+  clocks:
+    description: |
+      Clock sources for the XPCS:
+      - csr: APB3 bus interface clock (clk_csr_i), required for register
+        access.
+      - eee: EEE clock (clk_eee_i), required for Energy Efficient
+        Ethernet (EEE) operation.
+    minItems: 2
+    maxItems: 2
Quoted 1 line

No, instead list items with description.

I'll change to items with descriptions.

Quoted 10 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 59

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+
+  clock-names:
+    items:
+      - const: csr
+      - const: eee
+
+  phys:
+    description: |

Do not need '|' unless you need to preserve formatting.

I'll remove unnecessary '|' where not needed.

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6 -0
+      The phandle of SerDes PHY (Naneng Combo PHY) that provides
+      the serial lanes for 1000BASE-X / SGMII / QSGMII.
+      The SerDes must be powered on and initialised before any XPCS
+      register access.
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 71

Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6 -0
+  phy-names:
+    const: serdes
+
+  power-domains:
+    description: |
+      Power domain for the XPCS.

Drop sentence and |

I'll drop the redundant part.

Quoted 10 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 77

Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6 -0
+      On RK3568 this is typically the PD_PIPE power domain, which also
+      supplies the SerDes PHY.
+    maxItems: 1
+
+patternProperties:
+  "^pcs-mii@[0-3]$":

Why git grep pcs-mii@ gives me no results? Are you doing this similarly to existing devices or is this quite different device than every other hardware?

I used "pcs-mii" because the Rockchip TRM refers to these as "MII ports" and they are functionally PCS instances. I see a similar pattern in the Renesas RZN1 MIIC binding (renesas,rzn1-miic.yaml), which uses "mii-conv@[0-5]$" for its ports.

If you prefer a different name (e.g., "port@0"-"port@3"), I'm happy to change it. Please let me know.

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    type: object
+    description: |

Same here

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 81

Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2 -0
+      One of the four MII ports of the XPCS.
+      The port number is specified by the reg property (0..3).

Drop sentence, redundant. Schema tells that.

I'll fix this to use items with min/max.

Quoted 9 lines

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 89

Quoted 8 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +8 -0
+      The port is linked to an Ethernet MAC controller via the
+      pcs-handle property in the MAC's device tree node.
+
+    properties:
+      reg:
+        minimum: 0
+        maximum: 3
+        description: |
Quoted 7 lines

As well

Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 92

Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3 -0
+          MII port number of PCS.
+
+      status: true

Nope, do you see anywhere code like this?

I'll remove this generic property.

Thanks,
Coia

author maintainer
#13 lore raw

PATCH v2 5/10 arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

In reply to Coia Prant

The RK3568 SoC integrates a Synopsys DesignWare XPCS that provides the Physical Coding Sublayer for 1000BASE-X, SGMII, and QSGMII interfaces via its four MII ports. Add the XPCS device node and its pcs-mii sub-nodes to the SoC device tree.

The XPCS device is accessed via the APB3 bus at 0xfda00000 and requires the CSR clock (PCLK_XPCS) for register access and the EEE clock (CLK_XPCS_EEE) for Energy Efficient Ethernet operation. The PD_PIPE power domain must be enabled before any register access.

Also add two fixed-clock nodes (xpcs_gmac0_clk and xpcs_gmac1_clk) providing the 125 MHz reference clock for the GMACs when operating with XPCS. These clocks are used as the assigned-clock-parents for the respective GMAC nodes in board-level device trees.

The XPCS node and its pcs-mii sub-nodes are disabled by default and must be enabled at the board level when 1000BASE-X/SGMII/QSGMII is in use. The fixed-clock nodes are always present and do not have a status property, as they are static clock sources.

The XPCS node also requires a reference to the appropriate Naneng Combo PHY via the phys property at the board level.

---
 arch/arm64/boot/dts/rockchip/rk3568.dtsi | 45 ++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
arch/arm64/boot/dts/rockchip/rk3568.dtsi +45 -0
index 3bc653f027f1f..989e164c0eb39 100644
@@ -110,6 +110,51 @@ sata0: sata@fc000000 {
 		status = "disabled";
 	};
 
+	xpcs: pcs@fda00000 {
+		compatible = "rockchip,rk3568-xpcs";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0x0 0xfda00000 0x0 0x200000>;
+		clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+		clock-names = "csr", "eee";
+		power-domains = <&power RK3568_PD_PIPE>;
+		status = "disabled";
+
+		xpcs_mii0: pcs-mii@0 {
+			reg = <0>;
+			status = "disabled";
+		};
+
+		xpcs_mii1: pcs-mii@1 {
+			reg = <1>;
+			status = "disabled";
+		};
+
+		xpcs_mii2: pcs-mii@2 {
+			reg = <2>;
+			status = "disabled";
+		};
+
+		xpcs_mii3: pcs-mii@3 {
+			reg = <3>;
+			status = "disabled";
+		};
+	};
+
+	xpcs_gmac0_clk: xpcs-gmac0-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <125000000>;
+		clock-output-names = "clk_gmac0_xpcs_mii";
+		#clock-cells = <0>;
+	};
+
+	xpcs_gmac1_clk: xpcs-gmac1-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <125000000>;
+		clock-output-names = "clk_gmac1_xpcs_mii";
+		#clock-cells = <0>;
+	};
+
 	pipe_phy_grf0: syscon@fdc70000 {
 		compatible = "rockchip,rk3568-pipe-phy-grf", "syscon";
 		reg = <0x0 0xfdc70000 0x0 0x1000>;
Signature · 1 line
2.47.3
maintainer
#14 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Am Samstag, 1. August 2026, 16:22:29 Mitteleuropäische Sommerzeit schrieb Coia Prant:

Quoted 70 lines

The RK3568 SoC integrates a Synopsys DesignWare XPCS that provides the Physical Coding Sublayer for 1000BASE-X, SGMII, and QSGMII interfaces via its four MII ports. Add the XPCS device node and its pcs-mii sub-nodes to the SoC device tree.

The XPCS device is accessed via the APB3 bus at 0xfda00000 and requires the CSR clock (PCLK_XPCS) for register access and the EEE clock (CLK_XPCS_EEE) for Energy Efficient Ethernet operation. The PD_PIPE power domain must be enabled before any register access.

Also add two fixed-clock nodes (xpcs_gmac0_clk and xpcs_gmac1_clk) providing the 125 MHz reference clock for the GMACs when operating with XPCS. These clocks are used as the assigned-clock-parents for the respective GMAC nodes in board-level device trees.

The XPCS node and its pcs-mii sub-nodes are disabled by default and must be enabled at the board level when 1000BASE-X/SGMII/QSGMII is in use. The fixed-clock nodes are always present and do not have a status property, as they are static clock sources.

The XPCS node also requires a reference to the appropriate Naneng Combo PHY via the phys property at the board level.

---
 arch/arm64/boot/dts/rockchip/rk3568.dtsi | 45 ++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
arch/arm64/boot/dts/rockchip/rk3568.dtsi +34 -0
index 3bc653f027f1f..989e164c0eb39 100644
@@ -110,6 +110,51 @@ sata0: sata@fc000000 {
 		status = "disabled";
 	};
 
+	xpcs: pcs@fda00000 {
+		compatible = "rockchip,rk3568-xpcs";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		reg = <0x0 0xfda00000 0x0 0x200000>;
+		clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+		clock-names = "csr", "eee";
+		power-domains = <&power RK3568_PD_PIPE>;
+		status = "disabled";
+
+		xpcs_mii0: pcs-mii@0 {
+			reg = <0>;
+			status = "disabled";
+		};
+
+		xpcs_mii1: pcs-mii@1 {
+			reg = <1>;
+			status = "disabled";
+		};
+
+		xpcs_mii2: pcs-mii@2 {
+			reg = <2>;
+			status = "disabled";
+		};
+
+		xpcs_mii3: pcs-mii@3 {
+			reg = <3>;
+			status = "disabled";
+		};
+	};
+
+	xpcs_gmac0_clk: xpcs-gmac0-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <125000000>;

arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 156

Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +10 -0
+		clock-output-names = "clk_gmac0_xpcs_mii";
+		#clock-cells = <0>;
+	};
+
+	xpcs_gmac1_clk: xpcs-gmac1-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <125000000>;
+		clock-output-names = "clk_gmac1_xpcs_mii";
+		#clock-cells = <0>;
+	};

I don't fully believe those clocks are "just there" inside the SoC. Instead I _assume_ they are generated by some oscillator on the individual boards?

Because as described there, they would be just magically be there.

So please aim for a real clock description (likely on a board-level)

Heiko

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
author maintainer
#15 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Quoted 87 lines · Heiko Stübner <[email protected]> 于2026年8月2日周日 00:28写道:

Am Samstag, 1. August 2026, 16:22:29 Mitteleuropäische Sommerzeit schrieb Coia Prant:

Quoted 70 lines

The RK3568 SoC integrates a Synopsys DesignWare XPCS that provides the Physical Coding Sublayer for 1000BASE-X, SGMII, and QSGMII interfaces via its four MII ports. Add the XPCS device node and its pcs-mii sub-nodes to the SoC device tree.

The XPCS device is accessed via the APB3 bus at 0xfda00000 and requires the CSR clock (PCLK_XPCS) for register access and the EEE clock (CLK_XPCS_EEE) for Energy Efficient Ethernet operation. The PD_PIPE power domain must be enabled before any register access.

Also add two fixed-clock nodes (xpcs_gmac0_clk and xpcs_gmac1_clk) providing the 125 MHz reference clock for the GMACs when operating with XPCS. These clocks are used as the assigned-clock-parents for the respective GMAC nodes in board-level device trees.

The XPCS node and its pcs-mii sub-nodes are disabled by default and must be enabled at the board level when 1000BASE-X/SGMII/QSGMII is in use. The fixed-clock nodes are always present and do not have a status property, as they are static clock sources.

The XPCS node also requires a reference to the appropriate Naneng Combo PHY via the phys property at the board level.

---
 arch/arm64/boot/dts/rockchip/rk3568.dtsi | 45 ++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
arch/arm64/boot/dts/rockchip/rk3568.dtsi +34 -0
index 3bc653f027f1f..989e164c0eb39 100644
@@ -110,6 +110,51 @@ sata0: sata@fc000000 {
              status = "disabled";
      };
 
+     xpcs: pcs@fda00000 {
+             compatible = "rockchip,rk3568-xpcs";
+             #address-cells = <1>;
+             #size-cells = <0>;
+             reg = <0x0 0xfda00000 0x0 0x200000>;
+             clocks = <&cru PCLK_XPCS>, <&cru CLK_XPCS_EEE>;
+             clock-names = "csr", "eee";
+             power-domains = <&power RK3568_PD_PIPE>;
+             status = "disabled";
+
+             xpcs_mii0: pcs-mii@0 {
+                     reg = <0>;
+                     status = "disabled";
+             };
+
+             xpcs_mii1: pcs-mii@1 {
+                     reg = <1>;
+                     status = "disabled";
+             };
+
+             xpcs_mii2: pcs-mii@2 {
+                     reg = <2>;
+                     status = "disabled";
+             };
+
+             xpcs_mii3: pcs-mii@3 {
+                     reg = <3>;
+                     status = "disabled";
+             };
+     };
+
+     xpcs_gmac0_clk: xpcs-gmac0-clock {
+             compatible = "fixed-clock";
+             clock-frequency = <125000000>;

arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 156

Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +10 -0
+             clock-output-names = "clk_gmac0_xpcs_mii";
+             #clock-cells = <0>;
+     };
+
+     xpcs_gmac1_clk: xpcs-gmac1-clock {
+             compatible = "fixed-clock";
+             clock-frequency = <125000000>;
+             clock-output-names = "clk_gmac1_xpcs_mii";
+             #clock-cells = <0>;
+     };

I don't fully believe those clocks are "just there" inside the SoC. Instead I _assume_ they are generated by some oscillator on the individual boards?

Quoted 6 lines

Because as described there, they would be just magically be there.

So please aim for a real clock description (likely on a board-level)

Heiko

Hi Heiko,

Thanks for the review.

During my tests, I found that the 125 MHz clocks (xpcs_gmac0_clk / xpcs_gmac1_clk) are actually outputs of the Naneng Combo PHY (SerDes) when it's initialized for SGMII/QSGMII mode, rather than independent board-level oscillators.

Since these clocks are part of the SoC's internal design and consistent across all RK3568 boards, I think keeping them in the SoC dtsi makes sense to avoid unnecessary duplication. However, I also understand your concern that they might appear to be "magically there" without any explicit dependency.

To address this, I'm considering adding status = "disabled" to both clock nodes in the dtsi, so boards that actually use SGMII/QSGMII can explicitly enable them together with the XPCS node and the corresponding Combo PHY reference. This would make the dependency and activation requirements clearer.

What's your thought on this? Would you prefer adding status = "disabled" to clarify the dependency, or do you think the nodes should be moved to board-level dts entirely? I'm open to either direction.

Thanks,
Coia

maintainer
#16 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Quoted 4 lines

During my tests, I found that the 125 MHz clocks (xpcs_gmac0_clk / xpcs_gmac1_clk) are actually outputs of the Naneng Combo PHY (SerDes) when it's initialized for SGMII/QSGMII mode, rather than independent board-level oscillators.

Do you have documentation for these Combo PHYs? Can these clocks be enabled/disabled? And how is the Combo PHY fed with a clock? Does it have an external oscillator/crystal?

Andrew

author maintainer
#17 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Hi Andrew,

Thanks for the detailed questions. I've looked into the clock tree more carefully.

Quoted 1 line

Do you have documentation for these Combo PHYs?

Yes, the information is available in the Rockchip RK3568 TRM (Technical Reference Manual).
The relevant clock tree details are also mentioned in upstream discussions and patches.

Quoted 1 line

Can these clocks be enabled/disabled?

The 100 MHz input clock to the Combo PHY is a prerequisite for its operation. It is generated by the SoC's internal PPLL and fed to the PHY through a fixed divider.
It is not a gate that can be individually enabled or disabled by software; it is part of the
PHY's fundamental operating conditions.

Quoted 1 line

And how is the Combo PHY fed with a clock? Does it have an external oscillator/crystal?

The Combo PHY is fed by an internal 100 MHz clock derived from the PPLL. Specifically, the PPLL runs at 200 MHz, and this is divided by 2 to provide the
100 MHz clock input to the Combo PHY.
So, it does not use an external oscillator or crystal for its main reference clock;
it's generated internally by the SoC.

To summarize:
- The 125 MHz clocks (xpcs_gmac0_clk / xpcs_gmac1_clk) are outputs from the Combo PHY.
- The Combo PHY itself is clocked by an internal 100 MHz clock from the PPLL.
- This is all internal to the SoC and does not involve a board-level oscillator.

I hope this clarifies the clock architecture.

Thanks,
Coia

maintainer
#18 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Quoted 30 lines · Coia Prant

Hi Andrew,

Thanks for the detailed questions. I've looked into the clock tree more carefully.

Quoted 1 line

Do you have documentation for these Combo PHYs?

Yes, the information is available in the Rockchip RK3568 TRM (Technical Reference Manual).
The relevant clock tree details are also mentioned in upstream discussions and patches.

Quoted 1 line

Can these clocks be enabled/disabled?

The 100 MHz input clock to the Combo PHY is a prerequisite for its operation. It is generated by the SoC's internal PPLL and fed to the PHY through a fixed divider.
It is not a gate that can be individually enabled or disabled by software; it is part of the
PHY's fundamental operating conditions.

Quoted 1 line

And how is the Combo PHY fed with a clock? Does it have an external oscillator/crystal?

The Combo PHY is fed by an internal 100 MHz clock derived from the PPLL. Specifically, the PPLL runs at 200 MHz, and this is divided by 2 to provide the
100 MHz clock input to the Combo PHY.
So, it does not use an external oscillator or crystal for its main reference clock;
it's generated internally by the SoC.

Quoted 7 lines

To summarize:
- The 125 MHz clocks (xpcs_gmac0_clk / xpcs_gmac1_clk) are outputs from the Combo PHY.
- The Combo PHY itself is clocked by an internal 100 MHz clock from the PPLL.
- This is all internal to the SoC and does not involve a board-level oscillator.

I hope this clarifies the clock architecture.

So what is the purpose of the fixed-clock DT nodes?

If you want to describe the hardware, is the PPLL in DT? Should you then add a fixed divider to give 100MHz? And then a fixed multiplier to give 125MHz?

Andrew

author maintainer
#19 lore raw

Re: [PATCH v2 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes

Quoted 39 lines · Andrew Lunn
Quoted 30 lines · Coia Prant

Hi Andrew,

Thanks for the detailed questions. I've looked into the clock tree more carefully.

Quoted 1 line

Do you have documentation for these Combo PHYs?

Yes, the information is available in the Rockchip RK3568 TRM (Technical Reference Manual).
The relevant clock tree details are also mentioned in upstream discussions and patches.

Quoted 1 line

Can these clocks be enabled/disabled?

The 100 MHz input clock to the Combo PHY is a prerequisite for its operation. It is generated by the SoC's internal PPLL and fed to the PHY through a fixed divider.
It is not a gate that can be individually enabled or disabled by software; it is part of the
PHY's fundamental operating conditions.

Quoted 1 line

And how is the Combo PHY fed with a clock? Does it have an external oscillator/crystal?

The Combo PHY is fed by an internal 100 MHz clock derived from the PPLL. Specifically, the PPLL runs at 200 MHz, and this is divided by 2 to provide the
100 MHz clock input to the Combo PHY.
So, it does not use an external oscillator or crystal for its main reference clock;
it's generated internally by the SoC.

Quoted 7 lines

To summarize:
- The 125 MHz clocks (xpcs_gmac0_clk / xpcs_gmac1_clk) are outputs from the Combo PHY.
- The Combo PHY itself is clocked by an internal 100 MHz clock from the PPLL.
- This is all internal to the SoC and does not involve a board-level oscillator.

I hope this clarifies the clock architecture.

Quoted 7 lines

So what is the purpose of the fixed-clock DT nodes?

If you want to describe the hardware, is the PPLL in DT? Should you then add a fixed divider to give 100MHz? And then a fixed multiplier to give 125MHz?

Andrew

Hi Andrew,

Thanks for the follow-up.

The fixed-clock nodes (xpcs_gmac0_clk and xpcs_gmac1_clk) serve as clock inputs to the GMAC controller. From the GMAC driver's perspective, the 125 MHz clock is a fixed, external input. The fact that it's generated internally by the Combo PHY from the PPLL is an implementation detail of the SoC, not something the GMAC driver needs to be aware of.

In the device tree, the principle is to describe the hardware interfaces, not the entire internal clock generation pipeline. The PPLL configuration (200 MHz) is already set up in the CRU node via assigned-clocks. The Combo PHY's internal PLL that generates 125 MHz is part of the PHY's own operation, not something that the system clock framework needs to manage or represent as a separate clock node.

If we were to fully model PPLL -> divider (100 MHz) -> Combo PHY PLL (125 MHz) in DT, we would be overcomplicating the DT for no real gain. It would also make board variations harder to handle (e.g., if a board uses an external oscillator instead of the internal path, we'd have to rewrite the entire clock tree). This approach is consistent with how other similar SoCs (e.g., pcs-xpcs-plat) handle fixed reference clocks.

I think keeping these as fixed-clock nodes is the right balance between accuracy and simplicity. If you still have concerns, I can add a comment in the DT to clarify that these clocks are outputs of the Combo PHY.

Thanks,
Coia

author maintainer
#20 lore raw

PATCH v2 6/10 net: pcs: xpcs: add ANRESTART support for SGMII link recovery

In reply to Coia Prant

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.

This change has been verified on:
- RK3568 (Photonicat board)
- Wangxun NICs (no regression)

---
 drivers/net/pcs/pcs-xpcs.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/pcs/pcs-xpcs.c +13 -4
index 0337e2bcc0125..28e98449e8ac2 100644
@@ -816,9 +816,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;
 }
@@ -1089,14 +1094,18 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
 			state->duplex = DUPLEX_FULL;
 		else
 			state->duplex = DUPLEX_HALF;
-
 		return 0;
 	}
 
-	/* Clear AN complete status or interrupt */
-	if (state->an_complete)
+	if (state->an_complete) {
+		/* Clear AN complete status or interrupt */
 		xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0);
 
+		/* Initiate the next round of AN */
+		xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
+				    BMCR_ANRESTART);
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.47.3
maintainer
#21 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, · line 1108

Quoted 11 lines
drivers/net/pcs/pcs-xpcs.c +7 -2
-	/* Clear AN complete status or interrupt */
-	if (state->an_complete)
+	if (state->an_complete) {
+		/* Clear AN complete status or interrupt */
 		xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0);
 
+		/* Initiate the next round of AN */
+		xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
+				    BMCR_ANRESTART);
+	}
+

This probably needs more wide spread testing. I would be afraid that if you kick off an AN cycle, you loose the link until it completes? You would of noticed that on your hardware, but other hardware obviously behaves differently...

Andrew

author maintainer
#22 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

Hi Andrew,

Thanks for the careful review.

Quoted 4 lines

This probably needs more wide spread testing. I would be afraid that if you kick off an AN cycle, you loose the link until it completes? You would of noticed that on your hardware, but other hardware obviously behaves differently...

The trigger condition is: link is down AND an_complete is set. This means auto-negotiation has already completed (or completed with failure), but the link is still down. In this state, the hardware will not restart AN on its own on RK3568, so the link stays dead forever. Kicking ANRESTART here is the only way to recover.

For a working link (link up), state->an_complete may still be set, but the function returns earlier at the "if (state->link)" check, so ANRESTART is never triggered on an active link. This should not cause unexpected link loss on any hardware.

Regarding testing:
- Jiawen Wu has tested this on Wangxun NICs and reported no regression (Tested-by tag included in the patch).
- On RK3568 (Photonicat board), this fixes the SGMII link recovery issue.

I agree that wider testing is beneficial, and I'm open to running more tests on different platforms if needed. However, given the condition is strictly limited to "link down + an_complete", the risk of disrupting an already-working link is minimal.

Thanks,
Coia

maintainer
#23 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

Quoted 10 lines · Coia Prant

Hi Andrew,

Thanks for the careful review.

Quoted 4 lines

This probably needs more wide spread testing. I would be afraid that if you kick off an AN cycle, you loose the link until it completes? You would of noticed that on your hardware, but other hardware obviously behaves differently...

The trigger condition is: link is down AND an_complete is set.

Ah, i missed the "link is down" check. That makes it safer.

I still find it interesting that this devices is different. Has the silicon vendor done the integration of the licensed IP wrong?

Quoted 3 lines

Regarding testing:
- Jiawen Wu has tested this on Wangxun NICs and reported no regression (Tested-by tag included in the patch).

Probably Maxime will test on the platform he has, but i don't know if any use the XPCS.

Andrew

#24 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

Hi,

Quoted 17 lines · Andrew Lunn
Quoted 10 lines · Coia Prant

Hi Andrew,

Thanks for the careful review.

Quoted 4 lines

This probably needs more wide spread testing. I would be afraid that if you kick off an AN cycle, you loose the link until it completes? You would of noticed that on your hardware, but other hardware obviously behaves differently...

The trigger condition is: link is down AND an_complete is set.

Ah, i missed the "link is down" check. That makes it safer.

I still find it interesting that this devices is different. Has the silicon vendor done the integration of the licensed IP wrong?

Quoted 6 lines
Quoted 3 lines

Regarding testing:
- Jiawen Wu has tested this on Wangxun NICs and reported no regression (Tested-by tag included in the patch).

Probably Maxime will test on the platform he has, but i don't know if any use the XPCS.

Indeed :( The only XPCS HW I have right now is the ksz9477 switch, and it uses an old version of the IP with its own quirks.

I'll test it indeed, but I've yet to find some affordable HW with an XPCS and that I can easily source :(

Maxime

Quoted 2 lines

Andrew

author maintainer
#25 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

In reply to Andrew Lunn
Quoted 17 lines · Andrew Lunn
Quoted 10 lines · Coia Prant

Hi Andrew,

Thanks for the careful review.

Quoted 4 lines

This probably needs more wide spread testing. I would be afraid that if you kick off an AN cycle, you loose the link until it completes? You would of noticed that on your hardware, but other hardware obviously behaves differently...

The trigger condition is: link is down AND an_complete is set.

Ah, i missed the "link is down" check. That makes it safer.

I still find it interesting that this devices is different. Has the silicon vendor done the integration of the licensed IP wrong?

Quoted 8 lines
Quoted 3 lines

Regarding testing:
- Jiawen Wu has tested this on Wangxun NICs and reported no regression (Tested-by tag included in the patch).

Probably Maxime will test on the platform he has, but i don't know if any use the XPCS.

Andrew

Hi Andrew,

Thanks for the follow-up.

Honestly, I'm not sure why the RK3568 XPCS behaves this way. I don't have other DW XPCS hardware to compare against, so I can't say whether this is a silicon integration quirk or something else.

What I can confirm is that on RK3568, the PCS does not restart AN automatically when the link drops and comes back. Without this ANRESTART change, the link stays dead forever.

I agree that wider testing is needed. If Maxime or anyone else finds a regression on other hardware, we can revisit and condition it with a platform-specific flag. For now, the change is limited to the SGMII recovery path with a safe condition (link down + an_complete), so the risk should be minimal.

Thanks,
Coia

#26 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

In reply to Coia Prant
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Stale documentation: the patch introduces BMCR_ANRESTART for MAC-side SGMII but fails to update the…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Stale documentation: the patch introduces BMCR_ANRESTART for MAC-side SGMII but fails to update the block comment that explicitly states this is not needed. --

--- Patch [6]: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery --- commit 2bc2528d92a030c16f9b0b3ce9ca602d98573c26
Author: Coia Prant <[email protected]>

net: pcs: xpcs: add ANRESTART support for SGMII link recovery

This commit adds ANRESTART support for SGMII link recovery on hardware using the DesignWare XPCS IP. It sets BMCR_ANRESTART when starting auto-negotiation and triggers it again if the link goes down after completion to ensure the negotiation restarts properly.

Quoted 4 lines
drivers/net/pcs/pcs-xpcs.c +0 -0
@@ -816,9 +816,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,

[ ... ]

drivers/net/pcs/pcs-xpcs.c static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, · line 826

Quoted 4 lines
drivers/net/pcs/pcs-xpcs.c +1 -1
 	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);

[Severity: Low]
This isn't a bug, but does this change make the large block comment earlier in xpcs_config_aneg_c37_sgmii() contradictory?

The existing comment explicitly states:
"There is also no need to trigger AN restart for MAC-side SGMII."

Since this patch adds the BMCR_ANRESTART flag to the MAC-side SGMII path, should the comment be updated to reflect the new behavior?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
maintainer Tested-by on v2 6/10
#27 lore raw

Re: [PATCH v2 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery

In reply to Coia Prant

Hi Coia,

Quoted 12 lines · Coia Prant

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.

Quoted 6 lines

This change has been verified on:
- RK3568 (Photonicat board)
- Wangxun NICs (no regression)

KSZ9477's old XPCS doesn't break with that code, tested in SGMII mode :)

Maxime

Quoted 46 lines
---
 drivers/net/pcs/pcs-xpcs.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/net/pcs/pcs-xpcs.c +13 -4
index 0337e2bcc0125..28e98449e8ac2 100644
@@ -816,9 +816,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;
 }
@@ -1089,14 +1094,18 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,
 			state->duplex = DUPLEX_FULL;
 		else
 			state->duplex = DUPLEX_HALF;
-
 		return 0;
 	}
 
-	/* Clear AN complete status or interrupt */
-	if (state->an_complete)
+	if (state->an_complete) {
+		/* Clear AN complete status or interrupt */
 		xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS, 0);
 
+		/* Initiate the next round of AN */
+		xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
+				    BMCR_ANRESTART);
+	}
+
 	return 0;
 }
 
author maintainer
#28 lore raw

PATCH v2 7/10 net: pcs: xpcs: add Rockchip RK3568 platform glue driver

In reply to Coia Prant

The 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), each of which can be routed to GMAC0 or GMAC1 via the pcs-handle property in the MAC node. 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.

---
 drivers/net/pcs/Kconfig         |  23 ++
 drivers/net/pcs/Makefile        |   7 +-
 drivers/net/pcs/pcs-xpcs-rk.c   | 538 ++++++++++++++++++++++++++++++++
 include/linux/pcs/pcs-xpcs-rk.h |  11 +
 4 files changed, 575 insertions(+), 4 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
index e417fd66f660a..500400e3f4808 100644
@@ -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"
+	default PCS_XPCS
+	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)
+	depends on PM || COMPILE_TEST
+	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 -4
index 4f7920618b900..c809b7f942a51 100644
@@ -1,10 +1,9 @@
 # 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
-
-obj-$(CONFIG_PCS_XPCS)		+= pcs_xpcs.o
+obj-$(CONFIG_PCS_XPCS) += pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.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 +538 -0

538 lines not on this page · raw message

include/linux/pcs/pcs-xpcs-rk.h new file +11 -0
new file mode 100644
index 0000000000000..28723d5bd75cc
@@ -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 *np);
+
+#endif /* __LINUX_PCS_XPCS_ROCKCHIP_H */
Signature · 1 line
2.47.3
maintainer
#29 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

Quoted 5 lines · Coia Prant

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

Quoted 7 lines

The XPCS block contains four MII ports (0..3), each of which can be routed to GMAC0 or GMAC1 via the pcs-handle property in the MAC node. 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)

Why is port 0 called ROCKCHIP_MMD_MII not ROCKCHIP_MMD_MII0 ?

Quoted 4 lines

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.

I would put some of this into the driver itself, but reading the code it is not so obvious.

drivers/net/pcs/pcs-xpcs-rk.c line 163

Quoted 9 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +9 -0
+static int xpcs_rk_read_c22(struct mii_bus *bus, int addr, int reg)
+{
+	struct dw_xpcs_rk *pxpcs = bus->priv;
+	int dev;
+
+	if (!xpcs_rk_mdio_addr_validate(addr))
+		return -ENODEV;
+
+	dev = xpcs_rk_mdio_read_remapping(addr, MDIO_MMD_VEND2, reg);

Does this mean C22 registers are mapped into the first 32 of C45 MDIO_MMD_VEND2?

drivers/net/pcs/pcs-xpcs-rk.c line 192

Quoted 8 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8 -0
+static int xpcs_rk_read_c45(struct mii_bus *bus, int addr, int dev, int reg)
+{
+	struct dw_xpcs_rk *pxpcs = bus->priv;
+
+	if (!xpcs_rk_mdio_addr_validate(addr))
+		return -ENODEV;
+
+	dev = xpcs_rk_mdio_read_remapping(addr, dev, reg);

Should it be returning an error for dev == MDIO_MMD_VEND2? Or at least if reg < 32?

Andrew

author maintainer
#30 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

Quoted 10 lines · Coia Prant
Quoted 7 lines

The XPCS block contains four MII ports (0..3), each of which can be routed to GMAC0 or GMAC1 via the pcs-handle property in the MAC node. 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)

Why is port 0 called ROCKCHIP_MMD_MII not ROCKCHIP_MMD_MII0 ?

Hi Andrew,

The naming follows the Rockchip TRM. The hardware documentation refers to the MMD for the first port as simply "MII" without a numeric suffix, while the other ports are named "MII1", "MII2", "MII3". I kept the naming consistent with the TRM to make it easier to cross-reference.

As I understand it, this is probably because the MII controls not only Port 0, but
also the entire PCS (these registers are read-only in Ports 1-3 and reflected back to the MII).

If you prefer, I can rename it to ROCKCHIP_MMD_MII0 for consistency. Let me know and I'll update it in v3.

Quoted 13 lines

drivers/net/pcs/pcs-xpcs-rk.c line 163

Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +9 -0
+static int xpcs_rk_read_c22(struct mii_bus *bus, int addr, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+     int dev;
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, MDIO_MMD_VEND2, reg);

Does this mean C22 registers are mapped into the first 32 of C45 MDIO_MMD_VEND2?

Yes, exactly. The C22 register space (reg 0-31) is mapped into the first 32 registers of the VEND2 MMD (MMD 7). This is how the hardware is designed and matches the standard C22 to C45 address mapping.

Quoted 12 lines

drivers/net/pcs/pcs-xpcs-rk.c line 192

Quoted 9 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8 -0
+static int xpcs_rk_read_c45(struct mii_bus *bus, int addr, int dev, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, dev, reg);

Should it be returning an error for dev == MDIO_MMD_VEND2? Or at least if reg < 32?

No, we cannot simply return an error here. The generic xpcs driver uses C45 reads to access the VEND2 MMD for various operations, including reading the device ID (xpcs_read_id). If we returned an error for VEND2 or blocked reg < 32, the xpcs core driver would fail to identify the device and the PCS would not work.

The VEND2 MMD is fully accessible on this hardware and contains the standard C22 registers (0-31) as well as vendor-specific registers. The remapping function maps the C45 address space to the correct hardware MMD, and then the read/write functions handle the actual access. This design matches how other xpcs platform drivers (e.g., pcs-xpcs-plat.c) handle similar hardware.

For invalid MMIDs (e.g., MDIO_MMD_PCS, MDIO_MMD_VEND1, etc.), the xpcs_rk_mdio_read_remapping() function returns -ENXIO, which is then returned as 0xffff (meaning "no link" / "unavailable"). This is the standard MDIO behavior for unimplemented registers.

Thanks,
Coia

maintainer
#31 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

Quoted 18 lines · Coia Prant
Quoted 10 lines · Coia Prant
Quoted 7 lines

The XPCS block contains four MII ports (0..3), each of which can be routed to GMAC0 or GMAC1 via the pcs-handle property in the MAC node. 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)

Why is port 0 called ROCKCHIP_MMD_MII not ROCKCHIP_MMD_MII0 ?

Hi Andrew,

The naming follows the Rockchip TRM. The hardware documentation refers to the MMD for the first port as simply "MII" without a numeric suffix, while the other ports are named "MII1", "MII2", "MII3". I kept the naming consistent with the TRM to make it easier to cross-reference.

Quoted 7 lines

As I understand it, this is probably because the MII controls not only Port 0, but
also the entire PCS (these registers are read-only in Ports 1-3 and reflected back to the MII).

If you prefer, I can rename it to ROCKCHIP_MMD_MII0 for consistency. Let me know and I'll update it in v3.

If the TRM gives it this name, then O.K. It just makes the code look odd, unbalanced.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +4 -0
+static int xpcs_rk_read_c22(struct mii_bus *bus, int addr, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+     int dev;
Quoted 8 lines

drivers/net/pcs/pcs-xpcs-rk.c line 163

Quoted 5 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +5 -0
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, MDIO_MMD_VEND2, reg);

Does this mean C22 registers are mapped into the first 32 of C45 MDIO_MMD_VEND2?

Quoted 3 lines

Yes, exactly. The C22 register space (reg 0-31) is mapped into the first 32 registers of the VEND2 MMD (MMD 7). This is how the hardware is designed and matches the standard C22 to C45 address mapping.

Does the xpcs code actually perform any C22 access? A quick look suggests it is C45 only. xpcs_read() calls mdiodev_c45_read(). If C22 is not needed, i would not provide these functions.

Quoted 14 lines
Quoted 13 lines

drivers/net/pcs/pcs-xpcs-rk.c line 192

Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8 -0
+static int xpcs_rk_read_c45(struct mii_bus *bus, int addr, int dev, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, dev, reg);

Should it be returning an error for dev == MDIO_MMD_VEND2? Or at least if reg < 32?

Quoted 1 line

No, we cannot simply return an error here.

Thanks for the explanation.

Andrew

author maintainer
#32 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

Quoted 65 lines · Andrew Lunn
Quoted 18 lines · Coia Prant
Quoted 10 lines · Coia Prant
Quoted 7 lines

The XPCS block contains four MII ports (0..3), each of which can be routed to GMAC0 or GMAC1 via the pcs-handle property in the MAC node. 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)

Why is port 0 called ROCKCHIP_MMD_MII not ROCKCHIP_MMD_MII0 ?

Hi Andrew,

The naming follows the Rockchip TRM. The hardware documentation refers to the MMD for the first port as simply "MII" without a numeric suffix, while the other ports are named "MII1", "MII2", "MII3". I kept the naming consistent with the TRM to make it easier to cross-reference.

Quoted 7 lines

As I understand it, this is probably because the MII controls not only Port 0, but
also the entire PCS (these registers are read-only in Ports 1-3 and reflected back to the MII).

If you prefer, I can rename it to ROCKCHIP_MMD_MII0 for consistency. Let me know and I'll update it in v3.

If the TRM gives it this name, then O.K. It just makes the code look odd, unbalanced.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +4 -0
+static int xpcs_rk_read_c22(struct mii_bus *bus, int addr, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+     int dev;
Quoted 8 lines

drivers/net/pcs/pcs-xpcs-rk.c line 163

Quoted 5 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +5 -0
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, MDIO_MMD_VEND2, reg);

Does this mean C22 registers are mapped into the first 32 of C45 MDIO_MMD_VEND2?

Quoted 3 lines

Yes, exactly. The C22 register space (reg 0-31) is mapped into the first 32 registers of the VEND2 MMD (MMD 7). This is how the hardware is designed and matches the standard C22 to C45 address mapping.

Does the xpcs code actually perform any C22 access? A quick look suggests it is C45 only. xpcs_read() calls mdiodev_c45_read(). If C22 is not needed, i would not provide these functions.

Quoted 14 lines
Quoted 13 lines

drivers/net/pcs/pcs-xpcs-rk.c line 192

Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8 -0
+static int xpcs_rk_read_c45(struct mii_bus *bus, int addr, int dev, int reg)
+{
+     struct dw_xpcs_rk *pxpcs = bus->priv;
+
+     if (!xpcs_rk_mdio_addr_validate(addr))
+             return -ENODEV;
+
+     dev = xpcs_rk_mdio_read_remapping(addr, dev, reg);

Should it be returning an error for dev == MDIO_MMD_VEND2? Or at least if reg < 32?

Quoted 5 lines
Quoted 1 line

No, we cannot simply return an error here.

Thanks for the explanation.

Andrew

Hi Andrew,

You're right that the xpcs core uses C45 exclusively, and modern kernels no longer require C22 callbacks for mdiobus_register().

However, I'd prefer to keep them for two reasons:
1. Debugging tools (mdio-tools, ethtool, etc.) often use C22 reads to inspect PHY/PCS registers. Having these callbacks makes debugging much easier without having to patch the driver.
2. It keeps the driver consistent with pcs-xpcs-plat.c, which also provides both C22 and C45 callbacks even though the xpcs core only uses C45.

If you strongly prefer removing them to keep the code minimal, I can do that in v3. But I think the debug benefit justifies keeping them.

Thanks,
Coia

maintainer
#33 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

Quoted 13 lines

Hi Andrew,

You're right that the xpcs core uses C45 exclusively, and modern kernels no longer require C22 callbacks for mdiobus_register().

However, I'd prefer to keep them for two reasons:
1. Debugging tools (mdio-tools, ethtool, etc.) often use C22 reads to inspect PHY/PCS registers. Having these callbacks makes debugging much easier without having to patch the driver.
2. It keeps the driver consistent with pcs-xpcs-plat.c, which also provides both C22 and C45 callbacks even though the xpcs core only uses C45.

Quoted 2 lines

If you strongly prefer removing them to keep the code minimal, I can do that in v3. But I think the debug benefit justifies keeping them.

Keep them. I was thinking it side steps the issue of accidentally mixing up C22 registers and C45 registers. But there are useful use cases for C22.

Andrew

#34 lore raw

Re: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver

In reply to Coia Prant
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Probe fails unconditionally on systems without a PM domain or with CONFIG_PM_GENERIC_DOMAINS…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Probe fails unconditionally on systems without a PM domain or with CONFIG_PM_GENERIC_DOMAINS disabled.
- [High] Premature pm_runtime_force_suspend() in remove() breaks PHY teardown, causes SErrors, and permanently disables PM runtime on rebind.
- [High] Concurrent unbinding of the XPCS driver during xpcs_rk_create leads to a Use-After-Free of pxpcs and its MDIO bus.
- [High] Unchecked return value of device_link_add() allows Use-After-Free on supplier unbind.
- [Low] Unconditional assignment of dev_pm_ops and missing pm_ptr() wrapper causes unused function compiler warnings. --

--- Patch [7]: [PATCH v2 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver --- commit 749227defaf729e0f171dc87722abef8ebe69759
Author: Coia Prant <[email protected]>
net: pcs: xpcs: add Rockchip RK3568 platform glue driver

This commit introduces a platform glue driver for the Synopsys DesignWare XPCS controller found on Rockchip RK3568 SoCs. It translates MDIO operations to APB3 register accesses via a virtual MDIO bus. The generic xpcs driver then creates a phylink_pcs instance on top of this bus.

drivers/net/pcs/pcs-xpcs-rk.c new file +0 -0
index 0000000000000..36c1557b83367
@@ -0,0 +1,538 @@

[ ... ]

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int xpcs_rk_serdes_phy_poweron(struct dw_xpcs_rk *pxpcs)
+{
+	struct device *dev = &pxpcs->pdev->dev;
+	int ret;
+
+	ret = dev_pm_genpd_rpm_always_on(dev, true);
+	if (ret) {
+		dev_err(dev, "Failed to power on power-domains\n");
+		return ret;
+	}

[Severity: High]
Does this code unintentionally fail the probe on systems without a PM domain or when PM generic domains are disabled?

When CONFIG_PM_GENERIC_DOMAINS is disabled, dev_pm_genpd_rpm_always_on() returns -EOPNOTSUPP. If the device has no power domain (which appears to be optional), it returns -ENODEV.

Because the probe is aborted on any non-zero return value, the driver will fail to load on these hardware configurations or in COMPILE_TEST builds. Should -ENODEV and -EOPNOTSUPP be explicitly ignored here?

[ ... ]

Review

Quoted 4 lines
(quoted diff) +4 -0
+static void xpcs_rk_remove(struct platform_device *pdev)
+{
+	pm_runtime_force_suspend(&pdev->dev);
+}

[Severity: High]
Can this break PHY teardown and disable PM runtime permanently upon rebind?

Because the MDIO bus is registered using devm_mdiobus_register(), devres will unregister it after xpcs_rk_remove() returns. However, pm_runtime_force_suspend() is called here first, cutting the clock and incrementing the PM runtime disable depth.

When devres subsequently unregisters the MDIO bus, attached PHY devices are unbound, which triggers MDIO accesses for teardown. These accesses will call pm_runtime_resume_and_get(), which fails with -EACCES because PM runtime is disabled. This failure can cause a synchronous external abort if the clock is cut during access.

Additionally, the double-disable (here and in devm_pm_runtime_enable cleanup) leaves the disable depth greater than zero on rebind.

[ ... ]

Quoted 2 lines
(quoted diff) +2 -0
+struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *np)
+{

[ ... ]

Review

Quoted 12 lines
(quoted diff) +12 -0
+	pdev = of_find_device_by_node(pcs_np);
+	of_node_put(pcs_np);
+	if (!pdev)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	pxpcs = platform_get_drvdata(pdev);
+	if (!pxpcs || !pxpcs->bus) {
+		put_device(&pdev->dev);
+		return ERR_PTR(-EPROBE_DEFER);
+	}
+
+	xpcs = xpcs_create_mdiodev(pxpcs->bus, (int)port);

[Severity: High]
Is it possible for the XPCS driver to be unbound concurrently while platform_get_drvdata() is reading the data?

The device structure itself is pinned by of_find_device_by_node(), but without holding the device lock, a concurrent sysfs unbind could trigger devres cleanup. This would free pxpcs and unregister the MDIO bus right before xpcs_create_mdiodev() accesses pxpcs->bus, leading to a use-after-free.

Should the device lock be held to verify the driver is still bound before proceeding?

Review

Quoted 6 lines
(quoted diff) +6 -0
+	if (IS_ERR(xpcs)) {
+		put_device(&pdev->dev);
+		return xpcs;
+	}
+
+	device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER);

[Severity: High]
Does this ignore the return value of device_link_add() if the link creation fails?

If device_link_add() fails (for example, due to a memory allocation failure), no link is established. Later, if the XPCS supplier unbinds, the driver core will not automatically unbind the MAC consumer. The XPCS devres cleanup will free the MDIO bus while the MAC driver is still bound and potentially using it, which can cause a use-after-free.

Should the return value of device_link_add() be checked?

[ ... ]

Review

Quoted 12 lines
(quoted diff) +12 -0
+static const struct dev_pm_ops xpcs_rk_pm_ops = {
+	SET_RUNTIME_PM_OPS(xpcs_rk_pm_runtime_suspend,
+			   xpcs_rk_pm_runtime_resume,
+			   NULL)
+};
+
+static struct platform_driver xpcs_rk_driver = {
+	.probe = xpcs_rk_probe,
+	.remove = xpcs_rk_remove,
+	.driver = {
+		.name = "rk_xpcs-dwxpcs",
+		.pm = &xpcs_rk_pm_ops,

[Severity: Low]
Will this generate unused function warnings when CONFIG_PM is disabled?

The xpcs_rk_pm_runtime_suspend() and xpcs_rk_pm_runtime_resume() callbacks are defined as static. When CONFIG_PM is not set, SET_RUNTIME_PM_OPS expands to nothing, leaving the static functions unreferenced.

Since xpcs_rk_pm_ops is unconditionally assigned to .pm without the pm_ptr() wrapper, the struct is always referenced, but the callbacks inside might not be. Should RUNTIME_PM_OPS() and pm_ptr() be used instead?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
author maintainer
#35 lore raw

PATCH v2 8/10 net: stmmac: dwmac-rk: add SGMII support for RK3568

In reply to Coia Prant

The 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 cleared). Also add a supports_sgmii flag to indicate SGMII capability.

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.

While at it, fix the clock enable ordering in rk_gmac_powerup():
gmac_clk_enable() is now called before any register access, including the SGMII mode setup path. Previously SGMII mode would bypass the clock enable via a goto, which could cause synchronous external abort when accessing MAC registers with the clock domain disabled.

Also clean up the error handling in rk_gmac_powerup() by using a unified 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 dynamically changed by the stmmac core's set_clk_tx_rate callback. In-band mode works because the PCS handles rate adaptation internally. Out-of-band mode does not work because the MAC would need to change the clock rate to 125/12.5/1.25 MHz for 1000/100/10 Mbps respectively, and the clock is fixed.

Enable default_an_inband for SGMII and disable the generic stmmac set_clk_tx_rate callback. This forces phylink to use in-band mode, where the PCS is responsible for speed/duplex negotiation. Without this, the stmmac core would attempt to change the clock rate on speed changes, causing TX to work but RX to fail.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |   1 +
 .../net/ethernet/stmicro/stmmac/dwmac-rk.c    | 121 +++++++++++++++---
 2 files changed, 104 insertions(+), 18 deletions(-)
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index e3dd5adda5aca..5088acc06982e 100644
@@ -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 +103 -18

241 lines not on this page · raw message

Signature · 1 line
2.47.3
#36 lore raw

Re: [PATCH v2 08/10] net: stmmac: dwmac-rk: add SGMII support for RK3568

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] rk3568_set_to_sgmii fails to clear interface selection bits 4:6, leading to potential hardware…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] rk3568_set_to_sgmii fails to clear interface selection bits 4:6, leading to potential hardware misconfiguration.
- [Low] DWMAC_ROCKCHIP selects PCS_XPCS_ROCKCHIP without inheriting its PM dependency.
--

--- Patch [8]: [PATCH v2 08/10] net: stmmac: dwmac-rk: add SGMII support for RK3568 --- commit 53e13be00ad70a538e5aaf2d42200c1ae27d3eef
Author: Coia Prant <[email protected]>

net: stmmac: dwmac-rk: add SGMII support for RK3568

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

drivers/net/ethernet/stmicro/stmmac/Kconfig config DWMAC_ROCKCHIP · line 173

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index e3dd5adda5aca..5088acc06982e 100644
@@ -170,6 +170,7 @@ config DWMAC_ROCKCHIP
 	default ARCH_ROCKCHIP
 	depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
 	select MFD_SYSCON
+	select PCS_XPCS_ROCKCHIP

[Severity: Low]
Could selecting PCS_XPCS_ROCKCHIP here cause a Kconfig unmet dependency warning or build failure if PM is disabled?

PCS_XPCS_ROCKCHIP depends on PM || COMPILE_TEST, but DWMAC_ROCKCHIP lacks this dependency.

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/Kconfig +0 -0
 	help
 	  Support for Ethernet controller on Rockchip RK3288 SoC.
 
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0 -0
index 8d7042e689261..e47ca1bec5b8b 100644

[ ... ]

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +1 -0
@@ -851,18 +857,32 @@ static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv,
 		     RK3568_GMAC_CLK_TX_DL_CFG(tx_delay));
 
 	regmap_write(bsp_priv->grf, con1,
+		     RK3568_GMAC_MODE_RMII_RGMII |
 		     RK3568_GMAC_RXCLK_DLY_ENABLE |
 		     RK3568_GMAC_TXCLK_DLY_ENABLE);
 }

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv, · line 873

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +9 -0
 
+static void rk3568_set_to_sgmii(struct rk_priv_data *bsp_priv)
+{
+	u32 con1;
+
+	con1 = (bsp_priv->id == 1) ? RK3568_GRF_GMAC1_CON1 :
+				     RK3568_GRF_GMAC0_CON1;
+
+	regmap_write(bsp_priv->grf, con1, RK3568_GMAC_MODE_SGMII_QSGMII);
+}

[Severity: High]
Does this actually clear the interface selection bits 4:6 as mentioned in the commit message?

It looks like this only writes RK3568_GMAC_MODE_SGMII_QSGMII (which sets bit 7) but doesn't supply a write mask or data to clear bits 4:6. If the bootloader left bits 4:6 set to a non-zero value, could this lead to an incorrect hardware configuration?

[ ... ]

drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) · line 1450

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +7 -0
@@ -1379,16 +1441,19 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
 	if (ret)
 		return ret;
 
+	ret = gmac_clk_enable(bsp_priv, true);
+	if (ret)
+		return ret;
+
+	if (bsp_priv->phy_iface == PHY_INTERFACE_MODE_SGMII)
+		goto set_mode;
+

[Severity: High]
Because of the goto here, the standard clearing of interface selection bits using bsp_priv->gmac_phy_intf_sel_mask that happens below is bypassed for SGMII mode.

Should rk3568_set_to_sgmii() handle clearing those bits instead?

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +1 -1
 	ret = rk_get_phy_intf_sel(bsp_priv->phy_iface);
 	if (ret < 0)
-		return ret;
+		goto clk_disable;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
author maintainer
#37 lore raw

PATCH v2 9/10 arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port

In reply to Coia Prant

The Ariaboard Photonicat has a Motorcomm YT8521SC Gigabit Ethernet PHY connected to GMAC0 via XPCS SGMII. Enable the necessary nodes to make this port functional.

Enable combphy2 with rockchip,sgmii-mac-sel = <0> to route the SGMII interface to GMAC0. Enable the xpcs node and its port 0 sub-node, referencing combphy2 as the SerDes PHY.

Add the mdio0 node with the YT8521SC PHY at address 3, including its reset GPIO and LED configuration. Also add LED configuration for the existing RGMII PHY on mdio1 for consistency.

---
 .../boot/dts/rockchip/rk3568-photonicat.dts   | 77 ++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +75 -2
index 58c1052ba8ef3..91c17b624fd17 100644
@@ -3,6 +3,7 @@
 /dts-v1/;
 
 #include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/leds/common.h>
 #include <dt-bindings/pinctrl/rockchip.h>
 #include <dt-bindings/soc/rockchip,vop2.h>
 #include "rk3568.dtsi"
@@ -242,6 +243,7 @@ &combphy1 {
 
 &combphy2 {
 	status = "okay";
+	rockchip,sgmii-mac-sel = <0>;
 };
 
 &cpu0 {
@@ -260,9 +262,18 @@ &cpu3 {
 	cpu-supply = <&vdd_cpu>;
 };
 
-/* Motorcomm YT8521SC LAN port (require SGMII) */
+/* Motorcomm YT8521SC LAN port */
 &gmac0 {
-	status = "disabled";
+	assigned-clocks = <&cru SCLK_GMAC0_RX_TX>;
+	assigned-clock-parents = <&xpcs_gmac0_clk>;
+	pcs-handle = <&xpcs_mii0>;
+	managed = "in-band-status";
+	phy-handle = <&sgmii_phy>;
+	phy-mode = "sgmii";
+	phy-supply = <&vcc_3v3>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&gmac0_miim>;
+	status = "okay";
 };
 
 /* Motorcomm YT8521SC WAN port */
@@ -341,6 +352,39 @@ &i2s0_8ch {
 	status = "okay";
 };
 
+&mdio0 {
+	sgmii_phy: ethernet-phy@3 {
+		compatible = "ethernet-phy-id0000.011a";
+		reg = <0x3>;
+		max-speed = <1000>;
+		eee-broken-10gt;
+		eee-broken-10gkx4;
+		eee-broken-10gkr;
+		reset-assert-us = <20000>;
+		reset-deassert-us = <100000>;
+		reset-gpios = <&gpio3 RK_PC6 GPIO_ACTIVE_LOW>;
+
+		leds {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			led@1 {
+				reg = <1>;
+				color = <LED_COLOR_ID_AMBER>;
+				function = LED_FUNCTION_LAN;
+				default-state = "keep";
+			};
+
+			led@2 {
+				reg = <2>;
+				color = <LED_COLOR_ID_GREEN>;
+				function = LED_FUNCTION_LAN;
+				default-state = "keep";
+			};
+		};
+	};
+};
+
 &mdio1 {
 	rgmii_phy: ethernet-phy@3 {
 		compatible = "ethernet-phy-ieee802.3-c22";
@@ -350,6 +394,25 @@ rgmii_phy: ethernet-phy@3 {
 		reset-gpios = <&gpio4 RK_PC0 GPIO_ACTIVE_LOW>;
 		rx-internal-delay-ps = <1500>;
 		tx-internal-delay-ps = <1500>;
+
+		leds {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			led@1 {
+				reg = <1>;
+				color = <LED_COLOR_ID_AMBER>;
+				function = LED_FUNCTION_WAN;
+				default-state = "keep";
+			};
+
+			led@2 {
+				reg = <2>;
+				color = <LED_COLOR_ID_GREEN>;
+				function = LED_FUNCTION_WAN;
+				default-state = "keep";
+			};
+		};
 	};
 };
 
@@ -586,3 +649,13 @@ &xin32k {
 	pinctrl-names = "default";
 	pinctrl-0 = <&clk32k_out1>;
 };
+
+&xpcs {
+	status = "okay";
+	phys = <&combphy2 PHY_TYPE_SGMII>;
+	phy-names = "serdes";
+};
+
+&xpcs_mii0 {
+	status = "okay";
+};
Signature · 1 line
2.47.3
#38 lore raw

Re: [PATCH v2 09/10] arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The YT8521SC PHY node specifies 10G Energy Efficient Ethernet (EEE) errata properties…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The YT8521SC PHY node specifies 10G Energy Efficient Ethernet (EEE) errata properties (eee-broken-10gt, eee-broken-10gkx4, eee-broken-10gkr) despite being a Gigabit PHY. --

--- Patch [9]: [PATCH v2 09/10] arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port --- commit 08ee4bf87f62aaa593b62ffb0a37f8f8618a6a2a
Author: Coia Prant <[email protected]>

arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port

This commit enables the SGMII LAN port on the Ariaboard Photonicat, adding the necessary XPCS, GMAC0, and MDIO0 nodes to make the Motorcomm YT8521SC Gigabit Ethernet PHY functional.

Quoted 3 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +0 -0

[ ... ]

arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts &i2s0_8ch { · line 362

Quoted 12 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +8 -0
@@ -341,6 +352,39 @@ &i2s0_8ch {
 	status = "okay";
 };
 
+&mdio0 {
+	sgmii_phy: ethernet-phy@3 {
+		compatible = "ethernet-phy-id0000.011a";
+		reg = <0x3>;
+		max-speed = <1000>;
+		eee-broken-10gt;
+		eee-broken-10gkx4;
+		eee-broken-10gkr;

[Severity: Low]
Are these 10G Energy Efficient Ethernet (EEE) errata properties intended for this Gigabit PHY? Since max-speed is limited to 1000, these 10G-specific properties appear to be inapplicable to this device.

Quoted 2 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +2 -0
+		reset-assert-us = <20000>;
+		reset-deassert-us = <100000>;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
author maintainer
#39 lore raw

PATCH v2 10/10 MAINTAINERS: add entry for Rockchip XPCS driver

In reply to Coia Prant

Add 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
index 5114e6db7307d..cd5ffae6afd34 100644
@@ -23468,6 +23468,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-dwxpcs.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