net: pcs: add basic support for RK3568 XPCS
Subsystems (13)
Coia Prant
maintainerv4 cover net: pcs: add basic support for RK3568 XPCS
This series adds proper SGMII support for the Rockchip RK3568 SoC using the integrated Synopsys DesignWare XPCS, along with necessary fixes and refactoring in the stmmac core and XPCS driver.
Motivation
==========
The RK3568 integrates a DW XPCS accessed via APB3 and connected to a Naneng Combo SerDes PHY. Several boards (e.g., Ariaboard Photonicat) use this interface for Gigabit Ethernet. However, the current upstream stmmac driver does not support this configuration, and the XPCS driver has issues in SGMII poll mode that cause the link to be reported incorrectly.
This series addresses these issues by:
- Refactoring stmmac PCS lifetime management to allow platform drivers full control over PCS creation/destruction
- Fixing the XPCS driver's SGMII link recovery
- 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
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
Changelog
=========
Changes since v3:
Patch 7 (net: pcs: xpcs: add Rockchip RK3568 platform glue driver)
- Reverted Makefile change to keep pcs_xpcs as a composite module
- Switched from manual devm_pm_runtime_enable() to pm_runtime_enable() and use pm_runtime_force_suspend() in xpcs_rk_exit_clk()
- Removed xpcs_rk_remove() callback entirely; cleanup is now fully managed by devres via xpcs_rk_exit_clk().
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.3).
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 support
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 | 110 ++++ .../phy/phy-rockchip-naneng-combphy.yaml | 13 + MAINTAINERS | 9 + .../boot/dts/rockchip/rk3568-photonicat.dts | 74 ++- 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 | 5 +- drivers/net/pcs/pcs-xpcs-rk.c | 543 ++++++++++++++++++ drivers/net/pcs/pcs-xpcs.c | 16 +- .../rockchip/phy-rockchip-naneng-combphy.c | 8 + include/linux/pcs/pcs-xpcs-rk.h | 11 + 18 files changed, 1015 insertions(+), 66 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
Coia Prant
maintainerPATCH v4 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Coia Prant
maintainerPATCH v4 2/10 dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property
In reply to Coia PrantOn 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
@@ -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
Coia Prant
maintainerPATCH v4 3/10 phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568
In reply to Coia PrantOn 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
@@ -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
Coia Prant
maintainerPATCH v4 4/10 dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
In reply to Coia PrantAdd device tree binding documentation for the Synopsys DesignWare XPCS integrated on the Rockchip RK3568 SoC.
The XPCS is accessed over the APB3 bus and internally connected to a Naneng Combo SerDes PHY. It supports 1000BASE-X, SGMII, and QSGMII modes, with four MII ports.
--- .../bindings/net/pcs/rockchip-dwxpcs.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# 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 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 + + reg: + maxItems: 1 + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csr + - const: eee + + phys: + maxItems: 1 + + phy-names: + const: serdes + + power-domains: + maxItems: 1 + +patternProperties: + "^pcs-mii@[0-3]$": + type: object + description: + One of the four MII ports of the XPCS. The port is linked to an + Ethernet MAC controller via the pcs-handle property in the MAC's + device tree node. + + properties: + reg: + description: MII port number. + enum: [0, 1, 2, 3] + + required: + - reg + + additionalProperties: false + +required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + - clocks + - clock-names + - phys + - phy-names + - power-domains + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/rk3568-cru.h> + #include <dt-bindings/power/rk3568-power.h> + #include <dt-bindings/phy/phy.h> + + pcs@fda00000 { + compatible = "rockchip,rk3568-xpcs"; + reg = <0xfda00000 0x200000>; + #address-cells = <1>; + #size-cells = <0>; + 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
Coia Prant
maintainerPATCH v4 5/10 arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
In reply to Coia PrantThe 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
@@ -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
Coia Prant
maintainerPATCH v4 6/10 net: pcs: xpcs: add ANRESTART support for SGMII link recovery
In reply to Coia PrantOn 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.
--- drivers/net/pcs/pcs-xpcs.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/net/pcs/pcs-xpcs.c +13 -3
@@ -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; }
@@ -1093,10 +1098,15 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,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
Coia Prant
maintainerPATCH v4 7/10 net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Coia PrantThe RK3568 SoC integrates a Synopsys DesignWare XPCS that is accessed via APB3 memory-mapped registers.
This driver provides the glue logic to make the XPCS accessible to the generic pcs-xpcs core.
The XPCS block contains four MII ports (0..3), 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 | 5 +- drivers/net/pcs/pcs-xpcs-rk.c | 543 ++++++++++++++++++++++++++++++++ include/linux/pcs/pcs-xpcs-rk.h | 11 + 4 files changed, 580 insertions(+), 2 deletions(-) create mode 100644 drivers/net/pcs/pcs-xpcs-rk.c create mode 100644 include/linux/pcs/pcs-xpcs-rk.h
drivers/net/pcs/Kconfig +23 -0
@@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCS + +config PCS_XPCS_PLATFORM + tristate "Generic XPCS controller support" + 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" + default ARCH_ROCKCHIP + depends on OF && (ARCH_ROCKCHIP || 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 -2
@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ - pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o +obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o +obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.o
drivers/net/pcs/pcs-xpcs-rk.c new file +543 -0
543 lines not on this page · raw message
include/linux/pcs/pcs-xpcs-rk.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_PCS_XPCS_ROCKCHIP_H +#define __LINUX_PCS_XPCS_ROCKCHIP_H + +#include <linux/device.h> +#include <linux/of.h> +#include <linux/pcs/pcs-xpcs.h> + +struct dw_xpcs *xpcs_rk_create (struct device *dev,struct device_node *np); + +#endif /* __LINUX_PCS_XPCS_ROCKCHIP_H */
Signature · 1 line
2.47.3
Coia Prant
maintainerPATCH v4 8/10 net: stmmac: dwmac-rk: add SGMII support for RK3568
In reply to Coia PrantThe RK3568 SoC integrates a Synopsys DesignWare XPCS that can be connected to GMAC0 or GMAC1 in SGMII mode. Add the necessary glue logic to support this configuration.
The current dwmac-rk driver does not support SGMII mode. SGMII requires a PCS to handle auto-negotiation and link state reporting, but the existing driver only supports RGMII and RMII.
Add a set_to_sgmii() callback to configure the GMAC GRF register for SGMII mode (bit 7 set, interface selection bits 4:6 ignored when set). Also add a 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
@@ -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
Coia Prant
maintainerPATCH v4 9/10 arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port
In reply to Coia PrantThe 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 | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +72 -2
@@ -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,36 @@ &i2s0_8ch { status = "okay"; }; +&mdio0 { + sgmii_phy: ethernet-phy@3 { + compatible = "ethernet-phy-ieee802.3-c22"; + reg = <0x3>; + max-speed = <1000>; + 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 +391,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 +646,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
Coia Prant
maintainerPATCH v4 10/10 MAINTAINERS: add entry for Rockchip XPCS driver
In reply to Coia PrantAdd a MAINTAINERS entry for the Rockchip RK3568 XPCS platform driver and its device tree binding.
Include the relevant mailing lists (netdev and linux-rockchip) so that future patches are properly distributed.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -23738,6 +23738,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
[email protected]
AI reviewRe: [PATCH net-next v4 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
In reply to Coia PrantThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] Missing 'phy-names' and 'phys' properties in the XPCS node causes dtbs_check failures. - [Low] The…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] Missing 'phy-names' and 'phys' properties in the XPCS node causes dtbs_check failures.
- [Low] The fixed-clock nodes use a deprecated naming convention.
--
commit 44bcecc3ab36daaafbcaa0b05c41e194b9da4c06
Author: Coia Prant <[email protected]>
arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
This commit adds the XPCS device node and its pcs-mii sub-nodes to the RK3568 SoC device tree, along with two fixed-clock nodes for the GMAC reference clocks. The XPCS node is disabled by default and meant to be enabled at the board level.
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +0
-0@@ -110,6 +110,51 @@ sata0: sata@fc000000 { status = "disabled"; };
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 121
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +9
-0+ 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";
[Severity: Low]
Will this cause make dtbs_check failures during kernel builds? The dt-schema tool unconditionally validates all nodes against rockchip-dwxpcs.yaml, including those with status = "disabled".
Because phys and phy-names are strictly required by the binding, omitting them here in rk3568.dtsi breaks DT validation for all RK3568 boards that include this file without explicitly providing these properties.
[ ... ]
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 123
Quoted 2 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +2
-0+ xpcs_gmac0_clk: xpcs-gmac0-clock { + compatible = "fixed-clock";
[Severity: Low]
Could this node name trigger deprecation warnings during make dtbs_check?
The fixed-clock.yaml schema restricts valid node names to the pattern ^clock-([0-9]+|[a-z0-9-]+)$. Names outside this pattern, like xpcs-gmac0-clock, fall under a legacy definition tagged as deprecated.
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 152
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +7
-0+ clock-frequency = <125000000>; + clock-output-names = "clk_gmac0_xpcs_mii"; + #clock-cells = <0>; + }; + + xpcs_gmac1_clk: xpcs-gmac1-clock { + compatible = "fixed-clock";
[Severity: Low]
Does this node name also trigger a deprecation warning for the same reason?
Quoted 4 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +4
-0+ clock-frequency = <125000000>; + clock-output-names = "clk_gmac1_xpcs_mii"; + #clock-cells = <0>; + };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net-next v4 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery
In reply to Coia PrantThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Stale comment contradicts new ANRESTART behavior. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Stale comment contradicts new ANRESTART behavior.
--
commit 553a0aad47033d8800155c135475e03ebbeacf26
Author: Coia Prant <[email protected]>
net: pcs: xpcs: add ANRESTART support for SGMII link recovery
This commit modifies the XPCS driver to trigger ANRESTART alongside ANENABLE to ensure auto-negotiation correctly restarts on link state changes for certain hardware. It applies this both when starting AN and when the link is down but AN completion is detected.
Quoted 5 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
-1if (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]
Since this change explicitly triggers AN restart here, does the comment earlier in xpcs_config_aneg_c37_sgmii() need to be updated?
The block comment at the top of the function currently states:
/* For AN for C37 SGMII mode, the settings are :-
[ ... ]
* Note: Since it is MAC side SGMII, there is no need to set
* SR_MII_AN_ADV. MAC side SGMII receives AN Tx Config from
* PHY about the link state change after C28 AN is completed
* between PHY and Link Partner. There is also no need to
* trigger AN restart for MAC-side SGMII.
*/
It seems the new code logic contradicts the last sentence of this comment.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Coia PrantThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in xpcs_rk_create allows a concurrent…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in xpcs_rk_create allows a concurrent unbind of the supplier to free the MDIO bus, leading to a Use-After-Free.
- [Medium] Incorrect LIFO teardown ordering in devres clock cleanup action violates proper device initialization and PM hierarchy rules.
--
commit 7142dbf6b28b5ee94d0edc969bcf16d1183a5f41
Author: Coia Prant <[email protected]>
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
This commit adds a platform glue driver for the Synopsys DesignWare xpcs integrated in the Rockchip RK3568 SoC. It creates a virtual mdio bus to translate mdio operations to apb3 memory-mapped register accesses.
Quoted 5 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +0
-0
[ ... ]
drivers/net/pcs/pcs-xpcs-rk.c line 327
Quoted 8 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8
-0+static void xpcs_rk_exit_clk (void *data) +{ +struct dw_xpcs_rk *pxpcs = data; +struct device *dev = &pxpcs->pdev->dev; + +clk_disable_unprepare (pxpcs->eee_clk); + +pm_runtime_force_suspend (dev);
[Severity: Medium]
Does this sequence result in the clock being disabled before the device is suspended?
In xpcs_rk_init_clk(), eee_clk is enabled first, followed by a call to pm_runtime_enable(), allowing the device to become runtime active. During teardown, pm_runtime_force_suspend() invokes xpcs_rk_pm_runtime_suspend() to disable csr_clk.
Calling clk_disable_unprepare() for eee_clk before pm_runtime_force_suspend() violates last-in, first-out ordering, disabling the prerequisite clock while the device is still considered active. Should pm_runtime_force_suspend() be called prior to disabling the eee_clk?
Quoted 1 line
+}
[ ... ]
Quoted 2 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +2
-0+struct dw_xpcs *xpcs_rk_create (struct device *dev,struct device_node *np) +{
[ ... ]
drivers/net/pcs/pcs-xpcs-rk.c line 493
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+device_lock (&pdev->dev); + pxpcs =platform_get_drvdata (pdev); +if (!pxpcs || !pxpcs->bus) { +device_unlock (&pdev->dev); +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + } + + xpcs =xpcs_create_mdiodev (pxpcs->bus, (int )port); +device_unlock (&pdev->dev);
[Severity: High]
Does dropping the device lock here introduce a time-of-check to time-of-use race condition?
If a concurrent unbind of the rk_xpcs-dwxpcs supplier driver occurs immediately after device_unlock() but before device_link_add(), the unbind would trigger devres cleanup, freeing the mdio bus.
drivers/net/pcs/pcs-xpcs-rk.c line 499
Quoted 6 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +6
-0+if (IS_ERR (xpcs)) { +put_device (&pdev->dev); +return xpcs; + } + +if (!device_link_add (dev, &pdev->dev,DL_FLAG_AUTOREMOVE_CONSUMER )) {
Since device_link_add() permits linking to devices without drivers, it could succeed even if the supplier was just unbound. The consumer driver would then resume probing with the returned xpcs pointer referencing a freed mdio bus, leading to a use-after-free when the mac driver attempts to read or write pcs registers.
Could the device_link_add() call be moved inside the lock block protected by device_lock() to safely establish the dependency before the lock is released?
Quoted 8 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8
-0+xpcs_destroy (xpcs); +put_device (&pdev->dev); +return ERR_PTR (-ENOMEM ); + } + +put_device (&pdev->dev); +return xpcs; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Jakub Kicinski
maintainerRe: [PATCH net-next v4 01/10] net: stmmac: move XPCS lifetime management to platform drivers
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: stmmac: move XPCS lifetime management to platform drivers
This removes the generic XPCS creation and destruction code from stmmac_pcs_setup() and stmmac_pcs_clean(), leaving those functions as plain dispatchers to plat->pcs_init() and plat->pcs_exit(). The Intel mGbE glue gains its own pcs_init()/pcs_exit() implementations, and the renesas-gbeth, rzn1 and socfpga pcs_exit() callbacks now clear priv->hw->phylink_pcs after destroying the PCS.
A few questions on the changelog and on the removed common code below.
[Severity: Medium]
Three statements in the commit message do not seem to match the tree this patch applies to.
First:
Address all of these issues by introducing pcs_init() and pcs_exit() callbacks in plat_stmmacenet_data.
Are these callbacks actually introduced here? Both function pointers already exist in struct plat_stmmacenet_data at the baseline:
int (*pcs_init)(struct stmmac_priv *priv); void (*pcs_exit)(struct stmmac_priv *priv);
and this patch does not touch include/linux/stmmac.h at all. The baseline stmmac_pcs_setup() and stmmac_pcs_clean() already call them.
Second:
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
Is that the branch that causes the override? In the baseline that arm returns immediately:
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c:stmmac_pcs_setup() {
if (priv->plat->pcs_init) {
ret = priv->plat->pcs_init(priv);
} else if (fwnode_property_present(devnode, "pcs-handle")) {
...
} else {
return 0;
}
...
priv->hw->xpcs = xpcs;
}so no XPCS pointer can be clobbered there. The clobber only happens on the plat->pcs_init branch, where the local xpcs stays NULL and the unconditional priv->hw->xpcs = xpcs; afterwards overwrites whatever pcs_init() stored. Could the changelog describe that path instead?
Third:
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().
rzn1 and socfpga already used pcs_init()/pcs_exit() before this patch, and neither creates an XPCS: rzn1_dwmac_pcs_init() calls miic_create() and socfpga_dwmac_pcs_init() calls lynx_pcs_create_mdiodev(). The only change for them is the added NULL assignment. The patch also modifies dwmac-renesas-gbeth.c, which the changelog does not mention. Should that list be corrected to intel only, plus a note about the pointer clearing in renesas-gbeth, rzn1 and socfpga?
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void common_default_data(struct plat_stmmacenet_data *plat) · line 609
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +4
-0@@ -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 ;
[Severity: Low]
This isn't a bug, but is the NULL initializer still reachable here? Both arms of the if/else below assign xpcs unconditionally, from xpcs_create_fwnode() or xpcs_create_mdiodev(), and neither returns NULL. In the common code this was moved from, the initializer mattered because a fall-through left xpcs NULL and the call was guarded by
if (xpcs) xpcs_config_eee_mult_fact(...); that guard is now gone.
Quoted 31 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +31
-0+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 ; +} +
[ ... ]
Quoted 85 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +2
-0@@ -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@@ -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@@ -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@@ -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 +0
-14@@ -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 &&
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_reset(struct mii_bus *bus) · line 449
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +3
-6- 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 ; - }
[Severity: Medium]
Does this drop the generic handling of the "pcs-handle" property? After this change, any snps,dwmac node whose firmware points "pcs-handle" at a Synopsys XPCS, but whose glue driver does not set plat->pcs_init, gets priv->hw->xpcs == NULL and no message at all, since the function just returns 0. "pcs-handle" is still a documented generic property in Documentation/devicetree/bindings/net/ethernet-controller.yaml.
The changelog explains this is harmless because:
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.
Is that accurate? The core consumes priv->hw->xpcs in two places that do not go through plat->select_pcs():
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_phy_setup() {
/* If we have an xpcs, it defines which PHY interfaces are supported. */
if (priv->hw->xpcs)
pcs = xpcs_to_phylink_pcs(priv->hw->xpcs);
else
pcs = priv->hw->phylink_pcs;
if (pcs)
phy_interface_or(config->supported_interfaces, ...);
}drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_init_phy() {
if (priv->hw->xpcs &&
xpcs_get_an_mode(priv->hw->xpcs, mode) == DW_AN_C73)
return 0;
}Without the XPCS, supported_interfaces stays limited to plat->phy_interface and the DW_AN_C73 "no PHY" path is lost, so stmmac_init_phy() can now fail where it previously succeeded.
Related, for Intel mGbE the callbacks are only installed inside the SGMII/1000BASEX branch of intel_mgbe_common_data(), while the removed common code created an XPCS from "pcs-handle" regardless of interface mode. Should a warning be emitted when "pcs-handle" is present but no pcs_init() claims it, or should the changelog state the behaviour change explicitly?
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_reset(struct mii_bus *bus) · line 436
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +1
-0+ ret = priv->plat->pcs_init (priv);if (ret)return dev_err_probe (priv->device, ret,"No xPCS found\n" );
[Severity: Low]
This is a pre-existing wording problem and not introduced by this patch, but with the generic XPCS code gone this is now the only diagnostic in stmmac_pcs_setup(), and three of the four pcs_init() implementers do not create an XPCS:
socfpga_dwmac_pcs_init() -> lynx_pcs_create_mdiodev() rzn1_dwmac_pcs_init() -> miic_create() renesas_gmac_pcs_init() -> miic_create()
So a miic_create() or lynx_pcs_create_mdiodev() failure, including -EPROBE_DEFER, is reported as "No xPCS found". Would something like "failed to initialise PCS" be more accurate here?
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +0
-5-if (xpcs) -xpcs_config_eee_mult_fact (xpcs, priv->plat->mult_fact_100ns); - - priv->hw->xpcs = xpcs; -return 0 ; }
[ ... ]
Jakub Kicinski
maintainerRe: [PATCH net-next v4 03/10] phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568
This adds a "rockchip,sgmii-mac-sel" DT property to the RK3568 combphy driver so the SGMII interface can be routed to GMAC0 or GMAC1 through the pipe GRF pipe_sgmii_mac_sel bit. The value defaults to 1 (GMAC1) when the property is absent, and is written during PHY_TYPE_SGMII configuration.
A few questions below.
Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +0
-0
[ ... ]
Quoted 9 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +1
-0@@ -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,
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static int rockchip_combphy_parse_dt(struct device *dev, struct rockchip_combphy · line 382
Quoted 6 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +3
-0@@ -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); +
[Severity: Medium]
Since the return value of device_property_read_u32() is discarded here, rockchip_combphy_parse_dt() cannot distinguish "the DT asked for GMAC1" from "the DT said nothing about the mux".
The result is that rk3568_combphy_cfg() writes PIPE_GRF 0x0040 bit 1 on every PHY_TYPE_SGMII bring-up, including for device trees that do not have the new property. Before this patch that bit was never touched, so whatever routing the SoC reset or the boot firmware established was left alone.
The commit message states:
"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."
The "or omitted" case now depends entirely on that reset value being 1. If the reset value is actually 0, or if firmware routed SGMII to GMAC0 on a board wired that way and its DT lacks the property, does phy_init() still return success while the XPCS ends up attached to the wrong MAC, giving a link that never comes up and no message explaining why?
Would it make sense to only write the bit when the property is actually present, for example:
if (!device_property_read_u32(dev, "rockchip,sgmii-mac-sel", &priv->sgmii_mac_sel)) priv->sgmii_mac_sel_valid = true;
so that omitting the property leaves the mux untouched?
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv) · line 882
Quoted 9 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +2
-0priv->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 );
[Severity: Low]
The binding added in the preceding patch of this series declares the property as:
rockchip,sgmii-mac-sel:
$ref: /schemas/types.yaml#/definitions/uint32
enum: [0, 1]
default: 1but "priv->sgmii_mac_sel > 0" collapses the value to a boolean, and rockchip_combphy_parse_dt() does no range check.
Does that mean a device tree setting the property to 2 or 0xffffffff is silently treated as GMAC1 rather than rejected? Similarly, a present-but-malformed property (wrong length or type) makes device_property_read_u32() fail, and the pre-seeded default of 1 is used with no diagnostic.
dtschema only validates in-tree device trees, so for bootloader-supplied DTs or overlays the driver is the only place the enum can be enforced. Would checking the value against {0, 1} and returning an error, or alternatively documenting the property as a plain flag, close that gap?
[Severity: Low]
The mux write is only added to the PHY_TYPE_SGMII case. The adjacent PHY_TYPE_QSGMII case in rk3568_combphy_cfg() programs the same pipe-grf register (pipe_xpcs_phy_ready at offset 0x0040 bit 2) but never touches the MAC-select bit:
case PHY_TYPE_QSGMII: rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); ...
The binding gates the property on the compatible only, not on the PHY type, and rockchip_combphy_parse_dt() runs at probe time before the PHY type is known from rockchip_combphy_xlate().
If a device tree sets rockchip,sgmii-mac-sel on a combphy that a consumer later claims with PHY_TYPE_QSGMII, is the requested routing simply dropped with no warning? If the property is meant to be SGMII-only, would rejecting or warning about it for other PHY types make that explicit?
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = { · line 997
Quoted 11 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +1
-0rockchip_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 },
For reference on the first two comments: this disable/enable encoding ({ 0x0040, 1, 1, 0x00, 0x01 }) is what maps the DT value onto GMAC0/GMAC1, and rockchip_combphy_param_write() always sets the write-enable mask:
tmp = en ? reg->enable : reg->disable; mask = GENMASK(reg->bitend, reg->bitstart); val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
so the bit is committed to hardware on every SGMII bring-up regardless of whether the device tree expressed a preference. Could the TRM bit polarity and the claimed reset value of 1 be confirmed in the commit message?
Note that no in-tree Rockchip device tree requests PHY_TYPE_SGMII before this series, and the only user (rk3568-photonicat.dts) is added later in the series, so nothing in-tree changes behaviour today.
Jakub Kicinski
maintainerRe: [PATCH net-next v4 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
This adds a new standalone schema describing the Synopsys DesignWare XPCS as integrated on the Rockchip RK3568, with a CSR window, csr/eee clocks, a Naneng Combo SerDes phy, a power domain and four MII child ports. A few questions about the property set and the file naming below.
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 5
Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5
-0@@ -0,0 +1,110 @@ +# 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#
[Severity: Low]
This isn't a bug, but should the file be named after the documented compatible, i.e. rockchip,rk3568-xpcs.yaml? The other schemas in Documentation/devicetree/bindings/net/pcs/ all use that form:
snps,dw-xpcs.yaml, fsl,lynx-pcs.yaml, mediatek,sgmiisys.yaml, renesas,rzn1-miic.yaml.
A rename would also have to update the $id line above, since it encodes the same name.
Related: the example at the bottom uses pcs@fda00000 and pcs-mii@0, while the sibling PCS binding uses the generic ethernet-pcs@... node name, and no $nodename constraint is added here. The SoC dtsi added later in the series copies the pcs@/pcs-mii@ names verbatim.
Quoted 2 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +2
-0+ +title: Rockchip RK3568 Synopsys DesignWare Ethernet PCS
[ ... ]
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3
-0+properties: + compatible: + const: rockchip,rk3568-xpcs
[Severity: Low]
This isn't a bug, but would a set of SoC-specific if/then blocks in Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yaml be preferred over a second schema for the same IP?
To be clear, a snps,dw-xpcs fallback compatible or a $ref to that schema would be wrong here. The glue driver added later in the series builds CSR addresses with only a 3-bit MMD field:
return FIELD_PREP(0x70000, dev) | FIELD_PREP(0xffff, reg);
and remaps the vendor MMDs in xpcs_rk_mdio_read_remapping() / xpcs_rk_mdio_write_remapping(), so the generic direct mapping described in snps,dw-xpcs.yaml would compute different offsets.
So the only question is where the description should live, not whether the compatible should be shared.
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 32
Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3
-0+ + reg: + maxItems: 1
[Severity: Low]
Should the sbd_intr_o output be described as an optional interrupts property? With additionalProperties: false at the end of the file, a conforming device tree cannot carry it, although adding it later stays backward compatible.
The single unnamed 2 MiB window itself does match the driver:xpcs_rk_init_res() uses platform_get_resource(pdev, IORESOURCE_MEM, 0) and requires resource_size(res) >= SZ_2M, and the largest computed offset 0x7FFFF << 2 = 0x1FFFFC still falls inside 0x200000, so reg-names and reg-io-width are not needed.
Quoted 15 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +15
-0+ + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csr
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10
-0+ - const: eee + + phys: + maxItems: 1 + + phy-names: + const: serdes + + power-domains: + maxItems: 1
[Severity: Low]
Should resets/reset-names be described here too? The RK3568 CRU exposes four dedicated reset lines for this block in include/dt-bindings/clock/rk3568-cru.h:
#define SRST_XPCS 150 #define SRST_XPCS_TX_DIV10 151 #define SRST_XPCS_RX_DIV10 152 #define SRST_XPCS_XGXS_RX 153
Since the schema ends with additionalProperties: false, a conforming device tree cannot express them at all, and the glue driver added later in the series never requests a reset control, so it depends on those resets already being de-asserted.
Peer blocks in the same island do describe theirs, e.g. combphy0 with resets = <&cru SRST_PIPEPHY0> and gmac0 with resets = <&cru SRST_A_GMAC0>.
Note the XPCS core does provide a register-level reset via xpcs_soft_reset() in drivers/net/pcs/pcs-xpcs.c, so a state-machine restart is possible without the CRU resets, and an optional resets property can be added later without breaking the ABI.
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 70
Quoted 13 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +13
-0+ +patternProperties: + "^pcs-mii@[0-3]$": + type: object + description: + One of the four MII ports of the XPCS. The port is linked to an + Ethernet MAC controller via the pcs-handle property in the MAC's + device tree node. + + properties: + reg: + description: MII port number. + enum: [0, 1, 2, 3]
[Severity: Low]
This isn't a bug, but is pcs-mii@N the intended name for these per-port children rather than the generic ethernet-pcs@N?
Resolving a MAC pcs-handle that points at one of these children does work with the rest of the series: xpcs_rk_create() in drivers/net/pcs/pcs-xpcs-rk.c reads the child reg, walks up with of_get_parent() and calls xpcs_create_mdiodev(pxpcs->bus, port), and rk_pcs_init() in drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c does of_parse_phandle(np, "pcs-handle", 0). So the open point is just the node naming.
Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6
-0+ + required: + - reg + + additionalProperties: false +
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10
-0+required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + - clocks + - clock-names + - phys + - phy-names + - power-domains
[Severity: Medium]
Does requiring phys and phy-names here make dtbs_check fail for the RK3568 boards? The SoC node added later in the same series omits both, because the SerDes selection is board specific:
arch/arm64/boot/dts/rockchip/rk3568.dtsi:
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";and only the board fills them in:
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts:
&xpcs {
status = "okay";
phys = <&combphy2 PHY_TYPE_SGMII>;
phy-names = "serdes";
};dtschema validates nodes irrespective of status = "disabled", so wouldn't every rk3568*.dtb apart from the Photonicat report "'phys', 'phy-names' are required properties"?
Should phys/phy-names be dropped from required (or made conditional), or should the SoC dtsi carry them instead?
Quoted 24 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +24
-0+ +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"; + reg = <0xfda00000 0x200000>; + #address-cells = <1>; + #size-cells = <0>; + 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>; + }; + };
Jakub Kicinski
maintainerRe: [PATCH net-next v4 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
This adds the RK3568 Synopsys DesignWare XPCS node (with four pcs-mii sub-nodes) plus two 125 MHz fixed-clock nodes used as GMAC reference clocks. The XPCS node and its sub-nodes are disabled by default and are meant to be completed and enabled at the board level.
A couple of questions about the new nodes below.
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +0
-0@@ -110,6 +110,51 @@ sata0: sata@fc000000 { status = "disabled"; };
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 121
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +9
-0+ 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";
[Severity: Medium]
Does this node validate against the binding added earlier in the same series? Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml lists phys and phy-names unconditionally:
required:
- compatible
- reg
- "#address-cells"
- "#size-cells"
- clocks
- clock-names
- phys
- phy-names
- power-domains
The node here supplies neither, and dt-validate does not skip nodes with status = "disabled", so dtbs_check should report "'phys' is a required property" and "'phy-names' is a required property" for every rk3568 dtb that includes this dtsi.
At the tip of the series only rk3568-photonicat.dts fills them in:
&xpcs {
status = "okay";
phys = <&combphy2 PHY_TYPE_SGMII>;
phy-names = "serdes";
};so rk3568-evb, rk3568-rock-3a, rk3568-roc-pc, rk3568-radxa-cm3j, rk3568-wolfvision-pf5 and friends would still be missing them.
If which combphy carries SGMII is genuinely a board-level choice, should phys/phy-names be moved out of the unconditional required: list in the binding instead, or should the dtsi provide a default?
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 126
Quoted 5 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +5
-0+ + xpcs_mii0: pcs-mii@0 { + reg = <0>; + status = "disabled"; + };
[Severity: Low]
This isn't a bug, just a note for the record: at this commit there is no in-tree consumer of "rockchip,rk3568-xpcs" or of the pcs-mii sub-nodes. Both arrive later in the same series - xpcs_rk_of_ids in drivers/net/pcs/pcs-xpcs-rk.c gains the compatible, and rk_pcs_init() in drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c parses pcs-handle and calls xpcs_rk_create(). With the nodes disabled by default the intermediate state looks harmless, so nothing needs changing here.
Quoted 20 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +20
-0+ + 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>; + };
[Severity: Low]
These two node names take the deprecated branch of the fixed-clock $nodename schema. Documentation/devicetree/bindings/clock/fixed-clock.yaml has:
$nodename:
anyOf:
- description:
Preferred name is 'clock-<freq>' with <freq> being the output frequency as defined in the 'clock-frequency' property.
pattern: "^clock-([0-9]+|[a-z0-9-]+)$"
- description: Any name allowed
deprecated: true
xpcs-gmac0-clock and xpcs-gmac1-clock do not match the preferred pattern, so they land on the "Any name allowed" branch. Newer Rockchip dtsi files use the preferred form already, for example rk3528.dtsi with
xin24m: clock-xin24m and gmac0_clk: clock-gmac50m.
Could these be named clock-xpcs-gmac0 and clock-xpcs-gmac1? The labels xpcs_gmac0_clk / xpcs_gmac1_clk and all references would stay the same.
Quoted 3 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +0
-0pipe_phy_grf0: syscon@fdc70000 { compatible = "rockchip,rk3568-pipe-phy-grf", "syscon"; reg = <0x0 0xfdc70000 0x0 0x1000>;
Jakub Kicinski
maintainerRe: [PATCH net-next v4 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: pcs: xpcs: add ANRESTART support for SGMII link recovery
The patch sets BMCR_ANRESTART together with BMCR_ANENABLE when configuring C37 SGMII in-band negotiation, and clears the latched CL37 AN complete status before doing so. It also restarts negotiation from xpcs_get_state_c37_sgmii() when AN completion is latched but the link is reported down.
Quoted 4 lines
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.
[Severity: Low]
The changelog describes a user visible failure ("the link stays down forever") in long standing shared code, but there is no Fixes: tag and no statement about which histories are affected.
The only hardware named here, RK3568 XPCS, does not exist in the baseline
tree: searching for xpcs_rk, rk3568-xpcs or pcs-xpcs-rk under drivers/net at 879e280b8486 returns nothing, and the glue driver arrives later in this series ("net: pcs: xpcs: add Rockchip RK3568 platform glue driver").
Could the changelog either name the pre-existing commit being fixed, or say explicitly that the affected platform is introduced later in the same series, so that stable tooling does not have to guess?
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c +0
-0@@ -816,9 +816,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,if (ret <0 )return ret;
drivers/net/pcs/pcs-xpcs.c static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, · line 826
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +6
-1+/* 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 );
[Severity: Medium]
Should the comment at the top of xpcs_config_aneg_c37_sgmii() be updated along with this change? It still says the opposite of what the code now does:
drivers/net/pcs/pcs-xpcs.c:xpcs_config_aneg_c37_sgmii() {
/* For AN for C37 SGMII mode, the settings are :-
...
* 5) VR_MII_MMD_CTRL Bit(12) [AN_ENABLE] = 1b (Enable SGMII AN)
*
* Note that VR_MII_MMD_CTRL is MII_BMCR.
*
* Note: Since it is MAC side SGMII, there is no need to set
* SR_MII_AN_ADV. ... There is also no need to
* trigger AN restart for MAC-side SGMII.
*/On the default path this same function selects MAC side SGMII:
} else {
tx_conf = DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII;
}so the restart is now issued for exactly the case the comment says does not need it. The new DW_VR_MII_AN_INTR_STS write is also a sixth step that the enumerated sequence does not mention.
If the databook statement no longer holds for these parts, could the comment be corrected, so that a later reader does not remove the ANRESTART bit as a mistake?
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c +1
-2@@ -1093,10 +1098,15 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,return 0 ; } -/* Clear AN complete status or interrupt */ -if (state->an_complete) +if (state->an_complete) {
drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, · line 1111
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +6
-0+/* 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 ; }
[Severity: Medium]
Can this sequence get stuck if the xpcs_modify() fails?
The latched status is cleared first, and DW_VR_MII_AN_STS_C37_ANCMPLT_INTR is the only thing that brings execution back into this branch:
state->an_complete = ret & DW_VR_MII_AN_STS_C37_ANCMPLT_INTR;
So if the clear succeeds but the restart does not, every later poll reads ANCMPLT as 0, state->an_complete stays false, and the restart is never retried, leaving the port down with AN idle until something calls pcs_config again.
mdiodev_c45_modify() does a read followed by a write, so there are two places it can return an error, for example a bus -ETIMEDOUT, or with the Rockchip glue added later in this series the pm_runtime_resume_and_get() error path in xpcs_rk_read_reg() / xpcs_rk_write_reg().
Both return values are also discarded and the function still ends with return 0, so the diagnostic in the caller can never fire for them:
case DW_AN_C37_SGMII: ret = xpcs_get_state_c37_sgmii(xpcs, state); if (ret) dev_err(&xpcs->mdiodev->dev, "%s returned %pe\n", "xpcs_get_state_c37_sgmii", ERR_PTR(ret));
Would it be better to assert BMCR_ANRESTART before clearing the latched status, and to propagate both return codes to xpcs_get_state()?
Jakub Kicinski
maintainerRe: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: pcs: xpcs: add Rockchip RK3568 platform glue driver
This adds a glue driver for the Synopsys DesignWare XPCS found on RK3568, which is reached through APB3 memory-mapped registers instead of a real MDIO bus. The driver registers a virtual MDIO bus that remaps the four MII ports onto their respective MMDs, and exports xpcs_rk_create() so a MAC driver can obtain a dw_xpcs instance.
A few questions below.
Quoted 9 lines
drivers/net/pcs/Kconfig +1
-0@@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCS
drivers/net/pcs/Kconfig config PCS_XPCS · line 25
Quoted 10 lines
drivers/net/pcs/Kconfig +10
-0+ +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.
[Severity: Medium]
Should this new user-visible symbol be part of a patch whose changelog only describes adding Rockchip RK3568 support?
Two side effects of introducing PCS_XPCS_PLATFORM are not mentioned anywhere in the commit message:
- the "snps,dw-xpcs" platform glue moves out of pcs_xpcs.ko into a new pcs-xpcs-plat.ko, which changes module packaging for every existing memory-mapped DW XPCS user
- the glue becomes optional, so a config with PCS_XPCS=y and PCS_XPCS_PLATFORM=n silently loses "snps,dw-xpcs" support
Since this restructuring of shared code is independent of the Rockchip glue, could it be split into its own preparatory patch with the effects described?
drivers/net/pcs/Kconfig config PCS_XPCS · line 30
Quoted 5 lines
drivers/net/pcs/Kconfig +5
-0+ +config PCS_XPCS_ROCKCHIP + tristate "Rockchip XPCS controller support" + default ARCH_ROCKCHIP + depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
[Severity: Medium]
Do the dependencies here need GENERIC_PHY and PM_GENERIC_DOMAINS as well?
xpcs_rk_probe() cannot make forward progress without either of them. With CONFIG_GENERIC_PHY=n, the first probe step hits the stub:
include/linux/phy/phy.h:
static inline struct phy *devm_phy_get(struct device *dev,
const char *string)
{
return ERR_PTR(-ENOSYS);
}so xpcs_rk_serdes_phy_init() always fails through dev_err_probe().
With CONFIG_PM_GENERIC_DOMAINS=n (which covers every CONFIG_PM=n build), xpcs_rk_serdes_phy_poweron() hits:
include/linux/pm_domain.h:
static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on)
{
return -EOPNOTSUPP;
}and the driver treats that as fatal. Since the symbol is also default ARCH_ROCKCHIP, it can be built and matched in configurations where it can never bind. Would adding depends on GENERIC_PHY and PM_GENERIC_DOMAINS be appropriate?
Quoted 34 lines
drivers/net/pcs/Kconfig +7
-0+ 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 helpdrivers/net/pcs/Makefile +3
-2@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ - pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o +obj-$(CONFIG_PCS_XPCS_PLATFORM) += pcs-xpcs-plat.o +obj-$(CONFIG_PCS_XPCS_ROCKCHIP) += pcs-xpcs-rk.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o obj-$(CONFIG_PCS_RZN1_MIIC) += pcs-rzn1-miic.odrivers/net/pcs/pcs-xpcs-rk.c new file +0
-0@@ -0,0 +1,543 @@
[ ... ]
drivers/net/pcs/pcs-xpcs-rk.c line 238
Quoted 11 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +11
-0+static int xpcs_rk_serdes_phy_init (struct dw_xpcs_rk *pxpcs) +{ +struct device *dev = &pxpcs->pdev->dev; + + pxpcs->serdes_phy =devm_phy_get (dev,"serdes" ); +if (IS_ERR (pxpcs->serdes_phy)) +return dev_err_probe (dev,PTR_ERR (pxpcs->serdes_phy), +"Failed to get SerDes PHY\n" ); + +return 0 ; +}
[Severity: Low]
Is the mandatory "serdes" PHY consistent with the device tree added by the rest of the series?
The binding added in this series lists phys and phy-names under required:
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml:
required:
- compatible
- reg
...
- phys
- phy-names
- power-domains
but the SoC node has neither property:
arch/arm64/boot/dts/rockchip/rk3568.dtsi:
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";dtschema validates nodes regardless of status, so every RK3568 DTB other than the one board patched later in the series should report that phys is a required property. Any board that enables the node without adding phys/phy-names also gets an unconditional probe failure here, since there is no devm_phy_get_optional() path. Should the PHY properties move to the SoC dtsi, or should they be dropped from required:?
[ ... ]
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+static int xpcs_rk_init_clk (struct dw_xpcs_rk *pxpcs) +{ +struct device *dev = &pxpcs->pdev->dev; +int ret; + + pxpcs->csr_clk =devm_clk_get (dev,"csr" ); +if (IS_ERR (pxpcs->csr_clk)) +return dev_err_probe (dev,PTR_ERR (pxpcs->csr_clk), +"Failed to get CSR clock\n" ); +
drivers/net/pcs/pcs-xpcs-rk.c line 349
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+ pxpcs->eee_clk =devm_clk_get (dev,"eee" ); +if (IS_ERR (pxpcs->eee_clk)) +return dev_err_probe (dev,PTR_ERR (pxpcs->eee_clk), +"Failed to get EEE clock\n" ); + + ret =clk_prepare_enable (pxpcs->eee_clk); +if (ret) { +dev_err (dev,"Failed to enable EEE clock\n" ); +return ret; + }
[Severity: Low]
The EEE clock is acquired and permanently enabled, but nothing ever derives the XPCS 100 ns multiplier from its rate. Should this driver call xpcs_config_eee_mult_fact() the way dwmac-intel.c does?
Without it xpcs->eee_mult_fact stays 0, and the core programs that value verbatim when EEE is turned on:
drivers/net/pcs/pcs-xpcs.c:
/* Configure the eee_mult_fact so that * clk_eee_time_period * (mult_fact + 1) is within the range * 80 to 120ns. */ val = ... FIELD_PREP(DW_VR_MII_EEE_MULT_FACT_100NS, xpcs->eee_mult_fact);
With the RK3568 EEE clock parents (125/200 MHz, so a 5-8 ns period), a multiplier of 0 puts the LPI timing well below that range. The register reset value is also 0, so nothing valid is being overwritten, but is the timing expected to be programmed here?
[ ... ]
Quoted 2 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +2
-0+struct dw_xpcs *xpcs_rk_create (struct device *dev,struct device_node *np) +{
[ ... ]
Quoted 11 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +11
-0+ pdev =of_find_device_by_node (pcs_np); +of_node_put (pcs_np); +if (!pdev) +return ERR_PTR (-EPROBE_DEFER ); + +device_lock (&pdev->dev); + pxpcs =platform_get_drvdata (pdev); +if (!pxpcs || !pxpcs->bus) { +device_unlock (&pdev->dev); +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER );
drivers/net/pcs/pcs-xpcs-rk.c line 499
Quoted 10 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +10
-0+ } + + xpcs =xpcs_create_mdiodev (pxpcs->bus, (int )port); +device_unlock (&pdev->dev); +if (IS_ERR (xpcs)) { +put_device (&pdev->dev); +return xpcs; + } + +if (!device_link_add (dev, &pdev->dev,DL_FLAG_AUTOREMOVE_CONSUMER )) {
[Severity: Medium]
Can the mii_bus be freed under the new dw_xpcs in the window between device_unlock() and device_link_add()?
The bus is devm managed, so it goes away when the XPCS platform driver unbinds:
xpcs_rk_init_bus()
bus = devm_mdiobus_alloc_size(dev, 0); ... ret = devm_mdiobus_register(dev, bus);
and xpcs_create_mdiodev() takes no reference on it:
drivers/net/phy/mdio_device.c:mdio_device_create()
mdiodev->bus = bus; mdiodev->addr = addr;
so the managed device link is the only thing keeping the supplier binding alive. With the lock already dropped, an unbind through sysfs or an rmmod of pcs-xpcs-rk can run device_release_driver() before the link exists. put_device() keeps the struct device around but not the driver binding or its devm resources, leaving mdiodev->bus and the ioremapped window pointing at freed memory. The xpcs_destroy() call on the device_link_add() failure path would then touch it too.
Would creating the device link while still holding device_lock(), or otherwise pinning the supplier before unlocking, close this?
[ ... ]
Quoted 1 line
+EXPORT_SYMBOL_GPL(xpcs_rk_create);
[Severity: Low]
As of this commit alone, xpcs_rk_create() has no in-tree caller, so the driver only probes, pins the power domain and SerDes, and registers the virtual MDIO bus without ever producing the phylink_pcs the changelog describes.
This resolves later in the same series: rk_pcs_init() in drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c calls xpcs_rk_create(priv->device, pcs_node), rk_gmac_probe() installs pcs_init/pcs_exit/select_pcs, and DWMAC_ROCKCHIP gains select PCS_XPCS_ROCKCHIP. Noting it only in case the ordering was intentional.
[ ... ]
Jakub Kicinski
maintainerRe: [PATCH net-next v4 08/10] net: stmmac: dwmac-rk: add SGMII support for RK3568
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: stmmac: dwmac-rk: add SGMII support for RK3568
This adds SGMII glue for RK3568: a set_to_sgmii() callback that programs GMAC CON1 bit 7, pcs_init/pcs_exit/select_pcs callbacks that create the Rockchip XPCS from the "pcs-handle" phandle, and a rework of the rk_gmac_powerup() error unwinding into a single clk_disable label.
A few questions below.
Quoted 5 lines
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.
[Severity: Low]
Does this paragraph describe the baseline? At 879e280b8486 there is no SGMII case and no goto in rk_gmac_powerup(), and the order is already:
ret = rk_get_phy_intf_sel(bsp_priv->phy_iface); if (ret < 0) return ret; intf = ret; ret = gmac_clk_enable(bsp_priv, true); if (ret) return ret; ... ret = rk_write_gmac_grf_reg(bsp_priv, val);
so gmac_clk_enable() already preceded every register access and there was nothing that could bypass it. The change here is a pure reorder ahead of rk_get_phy_intf_sel(), which touches no registers, plus the new unified unwind label.
Would it be more accurate to describe this as preparing the ordering for the new SGMII path rather than as a fix for a synchronous external abort?
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0
-0
[ ... ]
Quoted 29 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +13
-0@@ -809,6 +813,8 @@ static const struct rk_gmac_ops rk3528_ops = {#define RK3568_GRF_GMAC1_CON1 0x038c/* RK3568_GRF_GMAC0_CON1 && RK3568_GRF_GMAC1_CON1 */ +#define RK3568_GMAC_MODE_RMII_RGMII GRF_CLR_BIT(7) +#define RK3568_GMAC_MODE_SGMII_QSGMII GRF_BIT(7)#define RK3568_GMAC_FLOW_CTRL GRF_BIT(3)#define RK3568_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(3)#define RK3568_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1)@@ -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 ); } +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 ); +} +static const struct rk_gmac_ops rk3568_ops = {
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv, · line 885
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-0.init = rk3568_init, .set_to_rgmii = rk3568_set_to_rgmii, + .set_to_sgmii = rk3568_set_to_sgmii, + .set_speed = rk_set_clk_mac_speed, .gmac_phy_intf_sel_mask = GENMASK_U16(6, 4), .supports_rmii = true, + .supports_sgmii = true,
[Severity: Medium]
Who clears CON1 bit 7 for RMII on rk3568?
rk3568_set_to_rgmii() now explicitly writes RK3568_GMAC_MODE_RMII_RGMII, which shows bit 7 has to be programmed by the driver. rk3568_ops declares supports_rmii = true but has no .set_to_rmii, so the RMII branch of rk_gmac_powerup() is a no-op:
case PHY_INTERFACE_MODE_RMII: dev_info(dev, "init for RMII\n"); if (bsp_priv->ops->set_to_rmii) bsp_priv->ops->set_to_rmii(bsp_priv); break;
and the generic GRF write uses gmac_phy_intf_sel_mask = GENMASK_U16(6, 4), whose write-enable half-word never covers bit 7.
Since rk3568_set_to_sgmii() leaves bit 7 set persistently and nothing in rk_gmac_powerdown() restores it, can an RMII port come up muxed to the SerDes when bit 7 was left set by firmware or by a previous SGMII configuration of the same MAC (kexec, warm reboot)? The probe would report success while the link never works.
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0
-0.regs_valid = true, .regs = {@@ -1208,6 +1228,43 @@ static void rk_phy_powerdown(struct rk_priv_data *bsp_priv)dev_err (bsp_priv->dev,"fail to disable phy-supply\n" ); }
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) · line 1239
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +9
-0+static int rk_pcs_init (struct stmmac_priv *priv) +{ +struct device_node *np = priv->device->of_node; +struct device_node *pcs_node; +struct dw_xpcs *xpcs; + + pcs_node =of_parse_phandle (np,"pcs-handle" ,0 ); +if (!pcs_node) +return -ENODEV ;
[Severity: Low]
Should "pcs-handle" be documented in the Rockchip MAC binding?
This makes the property effectively mandatory for phy-mode = "sgmii" on
RK3568: a missing phandle returns -ENODEV, and stmmac_pcs_setup() turns that into a probe failure:
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c:stmmac_pcs_setup() {
ret = priv->plat->pcs_init(priv);
if (ret)
return dev_err_probe(priv->device, ret, "No xPCS found\n");
}Documentation/devicetree/bindings/net/rockchip-dwmac.yaml does not mention pcs-handle at all - it is neither described nor conditionally required for the SGMII-capable compatibles - while the new Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml says the port "is linked to an Ethernet MAC controller via the pcs-handle property in the MAC's device tree node". Other stmmac glue bindings that parse this property describe it (renesas,rzn1-gmac.yaml, renesas,rzv2h-gbeth.yaml). Could the MAC binding be updated to match?
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +9
-0+ + xpcs =xpcs_rk_create (priv->device, pcs_node); +of_node_put (pcs_node); +if (IS_ERR (xpcs)) +return PTR_ERR (xpcs); + + priv->hw->xpcs = xpcs; +return 0 ; +}
[ ... ]
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +1
-0@@ -1330,6 +1387,7 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev, bsp_priv->supports_rgmii = ops->supports_rgmii || !!ops->set_to_rgmii; bsp_priv->supports_rmii = ops->supports_rmii || !!ops->set_to_rmii; + bsp_priv->supports_sgmii = ops->supports_sgmii || !!ops->set_to_sgmii;
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) · line 1446
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-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;
[Severity: Medium]
This isn't a bug introduced by this patch, but the bare return here cannot unwind a partially enabled clock domain. gmac_clk_enable() leaks the bulk clock references when the PHY clock fails:
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:gmac_clk_enable() {
ret = clk_bulk_prepare_enable(bsp_priv->num_clks,
bsp_priv->clks);
if (ret)
return ret;
ret = clk_prepare_enable(bsp_priv->clk_phy);
if (ret)
return ret;
...
bsp_priv->clk_enabled = true;
}The second failure path returns without clk_bulk_disable_unprepare() and without setting clk_enabled, so the new clk_disable label, rk_gmac_powerdown() and the suspend path are all no-ops afterwards because the disable branch is gated on clk_enabled. Does this leave the bulk clocks prepared and enabled for the lifetime of the system?
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +5
-1+ +if (bsp_priv->phy_iface ==PHY_INTERFACE_MODE_SGMII ) + goto set_mode; + ret =rk_get_phy_intf_sel (bsp_priv->phy_iface);if (ret <0 ) -return ret; + goto clk_disable; intf = ret;
[ ... ]
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +7
-0@@ -1447,15 +1509,20 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)if (bsp_priv->ops->set_to_rmii) bsp_priv->ops->set_to_rmii (bsp_priv);break ; +case PHY_INTERFACE_MODE_SGMII : +dev_info (dev,"init for SGMII\n" ); +if (bsp_priv->ops->set_to_sgmii) + bsp_priv->ops->set_to_sgmii (bsp_priv); +break ;default :dev_err (dev,"NO interface defined!\n" ); + ret = -EINVAL ; + goto clk_disable; }
[ ... ]
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_get_interfaces(struct stmmac_priv *priv, void *bsp_priv, · line 1563
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-0@@ -1486,6 +1557,9 @@ static void rk_get_interfaces(struct stmmac_priv *priv, void *bsp_priv,if (rk->supports_rmii)__set_bit (PHY_INTERFACE_MODE_RMII , interfaces); + +if (rk->supports_sgmii) +__set_bit (PHY_INTERFACE_MODE_SGMII , interfaces); }
[Severity: Medium]
Is the SGMII advertisement here consistent with where the PCS is installed?
supports_sgmii is true for every rk3568 instance regardless of DT, so SGMII always lands in phylink_config.supported_interfaces. The PCS plumbing, however, is only installed when the DT phy-mode is exactly SGMII (see the rk_gmac_probe() hunk below).
On an RK3568 board with phy-mode = "rgmii"/"rmii", phylink can still pick SGMII - phylink_validate_phy() intersects phy->possible_interfaces with config->supported_interfaces - and then:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_mac_select_pcs() {
if (priv->plat->select_pcs) {
pcs = priv->plat->select_pcs(priv, interface);
if (!IS_ERR(pcs))
return pcs;
}
}returns NULL because select_pcs is unset, no XPCS was ever created (pcs_init is NULL), and rk_gmac_powerup() has already programmed the GRF once from the DT-derived bsp_priv->phy_iface, so rk3568_set_to_sgmii() never ran. Would gating the SGMII bit on the same condition that installs select_pcs/pcs_init keep the two in agreement?
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_probe(struct platform_device *pdev) · line 1684
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +6
-0static int rk_set_clk_tx_rate(void *bsp_priv_, struct clk *clk_tx_i,@@ -1602,6 +1676,17 @@ static int rk_gmac_probe(struct platform_device *pdev) plat_dat->suspend = rk_gmac_suspend; plat_dat->resume = rk_gmac_resume; +if (plat_dat->phy_interface ==PHY_INTERFACE_MODE_SGMII ) { +/* SGMII clock always runs at 125 MHz */ + plat_dat->set_clk_tx_rate =NULL ; + +/* SGMII requires a PCS */ + plat_dat->default_an_inband = true;
[Severity: Medium]
Does default_an_inband guarantee in-band mode here?
include/linux/phylink.h describes it as a default that "a fixed-link specification will override", and phylink has two ways out of in-band:
drivers/net/phy/phylink.c:phylink_parse_mode() {
dn = fwnode_get_named_child_node(fwnode, "fixed-link");
if (dn || fwnode_property_present(fwnode, "fixed-link"))
pl->cfg_link_an_mode = MLO_AN_FIXED;
}drivers/net/phy/phylink.c:phylink_pcs_neg_mode() {
neg_mode = PHYLINK_PCS_NEG_OUTBAND;
if (pl->phydev)
mode = MLO_AN_PHY;
}With set_clk_tx_rate cleared, stmmac_mac_link_up() then programs no rate at all:
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_mac_link_up() {
if (priv->plat->set_clk_tx_rate) {
ret = priv->plat->set_clk_tx_rate(priv->plat->bsp_priv,
priv->plat->clk_tx_i,
interface, speed);
}So for phy-mode = "sgmii" with a fixed-link node, or with a PHY that cannot do in-band signalling, the fixed 125 MHz clock is used at 10/100 Mbps - which the commit message says gives working TX and failing RX. Should the driver reject out-of-band SGMII explicitly instead of relying on the default?
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +5
-0+ plat_dat->pcs_init = rk_pcs_init; + plat_dat->pcs_exit = rk_pcs_exit; + plat_dat->select_pcs = rk_select_pcs; + } +
[ ... ]
Jakub Kicinski
maintainerRe: [PATCH net-next v4 09/10] arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port
In reply to Coia PrantThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port
This enables the GMAC0 SGMII LAN port on the Ariaboard Photonicat by adding the xpcs/xpcs_mii0 overrides, the combphy2 SGMII MAC selection, and an mdio0 node with the YT8521SC PHY. It also adds PHY LED descriptions on both mdio0 and mdio1.
Quoted 4 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +0
-0
[ ... ]
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts &combphy1 { · line 247
Quoted 6 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +1
-0@@ -242,6 +243,7 @@ &combphy1 { &combphy2 { status = "okay"; + rockchip,sgmii-mac-sel = <0>; };
[Severity: Low]
The changelog says:
"Enable combphy2 with rockchip,sgmii-mac-sel = <0> to route the SGMII
interface to GMAC0."
Is that description accurate? In the baseline the node already reads:
&combphy2 {
status = "okay";
};so the only new thing here is the rockchip,sgmii-mac-sel property. Could the wording be adjusted to say the property is added to an already enabled combphy2?
[Severity: Low]
This isn't a bug, but the new properties do not follow the ordering used by the rest of this file, where properties come roughly alphabetically and status is last. Here rockchip,sgmii-mac-sel lands after status, in &gmac0 below pcs-handle comes before managed, and in the new &xpcs override status is first with phys/phy-names after it. Compare the existing &gmac1 override, which ends with status = "okay";. Could these be reordered?
Quoted 21 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +11
-2&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"; };
[ ... ]
Quoted 15 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +11
-0@@ -350,6 +391,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"; + };
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts rgmii_phy: ethernet-phy@3 { · line 414
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +8
-0+ + led@2 { + reg = <2>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_WAN; + default-state = "keep"; + }; + }; }; };
[Severity: Low]
This hunk describes the LEDs of the pre-existing RGMII WAN PHY on &mdio1, which is already functional and unaffected by the SGMII enablement. The changelog justifies it only with:
"Also add LED configuration for the existing RGMII PHY on mdio1 for
consistency."
Would it be preferable to split this into its own patch, so this commit contains only the SGMII LAN port enablement?
[ ... ]
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts &xin32k { · line 654
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +6
-0@@ -586,3 +646,13 @@ &xin32k { pinctrl-names = "default"; pinctrl-0 = <&clk32k_out1>; }; + +&xpcs { + status = "okay"; + phys = <&combphy2 PHY_TYPE_SGMII>; + phy-names = "serdes"; +};
[Severity: Medium]
Should phys/phy-names live in rk3568.dtsi rather than in each board file?
The binding lists them as required properties of the XPCS node:
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml required:
- compatible
- reg
- "#address-cells"
- "#size-cells"
- clocks
- clock-names
- phys
- phy-names
- power-domains
but the SoC node in arch/arm64/boot/dts/rockchip/rk3568.dtsi has neither:
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";Does this mean every rk3568 dtb reports pcs@fda00000 as missing the required phys and phy-names under make CHECK_DTBS=y, including boards that do not enable the XPCS?
The XPCS to combphy2 connection is internal to the SoC, so each board that enables it will have to repeat the same phandle, as this patch does. Could phys = <&combphy2 PHY_TYPE_SGMII>; and phy-names = "serdes"; be moved into the dtsi node instead?
Quoted 4 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +4
-0+ +&xpcs_mii0 { + status = "okay"; +};
Jakub Kicinski
maintainerQuoted 3 lines · On Mon, 7 Sep 2026 23:37:03 +0800 Coia Prant wrote:
This series adds proper SGMII support for the Rockchip RK3568 SoC using the integrated Synopsys DesignWare XPCS, along with necessary fixes and refactoring in the stmmac core and XPCS driver.
Sending the AI review FYI, please look thru it and judge if any of the comments are worth respinning for. We're waiting for a review on the device tree bindings, anyway.
Coia Prant
maintainerQuoted 9 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:14写道:
Quoted 3 lines · On Mon, 7 Sep 2026 23:37:03 +0800 Coia Prant wrote:
This series adds proper SGMII support for the Rockchip RK3568 SoC using the integrated Synopsys DesignWare XPCS, along with necessary fixes and refactoring in the stmmac core and XPCS driver.
Sending the AI review FYI, please look thru it and judge if any of the comments are worth respinning for. We're waiting for a review on the device tree bindings, anyway.
I apologize; I have been so busy this week that I’ve repeatedly overlooked my plan to reply to sashiko-bot's comment. I will get back to you as soon as possible.
Best,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 01/10] net: stmmac: move XPCS lifetime management to platform drivers
In reply to Jakub KicinskiQuoted 24 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: stmmac: move XPCS lifetime management to platform driversThis removes the generic XPCS creation and destruction code from
stmmac_pcs_setup()andstmmac_pcs_clean(), leaving those functions as plain dispatchers toplat->pcs_init()andplat->pcs_exit(). The Intel mGbE glue gains its own pcs_init()/pcs_exit() implementations, and the renesas-gbeth, rzn1 and socfpgapcs_exit()callbacks now clearpriv->hw->phylink_pcsafter destroying the PCS.A few questions on the changelog and on the removed common code below.
[Severity: Medium]
Three statements in the commit message do not seem to match the tree this patch applies to.First:
Address all of these issues by introducing
pcs_init()andpcs_exit()callbacks inplat_stmmacenet_data.
Quoted 8 lines
Are these callbacks actually introduced here? Both function pointers already exist in struct
plat_stmmacenet_dataat the baseline:int (*pcs_init)(struct stmmac_priv *priv); void (*pcs_exit)(struct stmmac_priv *priv);and this patch does not touch
include/linux/stmmac.hat all. The baselinestmmac_pcs_setup()andstmmac_pcs_clean()already call them.
You're right. These callbacks already exist. My patch simplifies the dispatch, not introduces them. I'll fix the wording.
Quoted 23 lines
Second:
Second, and more critically, when
stmmac_pcs_setup()fails to create an XPCS (either because no pcs-handle is present and nopcs_maskis configured), it falls through to the else branch and leavespriv->hw->xpcsas NULL. This will silently override any XPCS that a platform driver may have already set upIs that the branch that causes the override? In the baseline that arm returns immediately:
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c:stmmac_pcs_setup() { if (priv->plat->pcs_init) { ret = priv->plat->pcs_init(priv); } else if (fwnode_property_present(devnode, "pcs-handle")) { ... } else { return 0; } ... priv->hw->xpcs = xpcs; }
Quoted 4 lines
so no XPCS pointer can be clobbered there. The clobber only happens on the
plat->pcs_initbranch, where the local xpcs stays NULL and the unconditionalpriv->hw->xpcs= xpcs; afterwards overwrites whateverpcs_init()stored. Could the changelog describe that path instead?
You're right. The else branch returns immediately. The clobber happens on the plat->pcs_init branch. I'll fix the changelog.
Quoted 6 lines
Third:
Existing platform drivers (intel, rzn1, socfpga) are updated to use the new callbacks by moving their XPCS creation and cleanup logic into
pcs_init()andpcs_exit().
Quoted 7 lines
rzn1 and socfpga already used pcs_init()/pcs_exit() before this patch, and neither creates an XPCS:
rzn1_dwmac_pcs_init()callsmiic_create()andsocfpga_dwmac_pcs_init()callslynx_pcs_create_mdiodev(). The only change for them is the added NULL assignment. The patch also modifiesdwmac-renesas-gbeth.c, which the changelog does not mention. Should that list be corrected to intel only, plus a note about the pointer clearing in renesas-gbeth, rzn1 and socfpga?
Okay, I will update it.
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +0
-0@@ -603,13 +603,47 @@ static void common_default_data(struct plat_stmmacenet_data *plat) plat->mdio_bus_data->needs_reset = true; }
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c static void common_default_data(struct plat_stmmacenet_data *plat) · line 609
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +4
-0+static int intel_mgbe_pcs_init (struct stmmac_priv *priv) +{ +struct fwnode_handle *devnode, *pcsnode; +struct dw_xpcs *xpcs =NULL ;[Severity: Low]
This isn't a bug, but is the NULL initializer still reachable here? Both arms of the if/else below assign xpcs unconditionally, fromxpcs_create_fwnode()orxpcs_create_mdiodev(), and neither returns NULL. In the common code this was moved from, the initializer mattered because a fall-through left xpcs NULL and the call was guarded by
if (xpcs)xpcs_config_eee_mult_fact(...); that guard is now gone.
You're right. I'll drop it.
Quoted 125 lines
Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-renesas-gbeth.c +5
-2@@ -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@@ -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@@ -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 +0
-14@@ -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 &&drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_reset(struct mii_bus *bus) · line 449
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +3
-6- 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 ; - }[Severity: Medium]
Does this drop the generic handling of the "pcs-handle" property? After this change, any snps,dwmac node whose firmware points "pcs-handle" at a Synopsys XPCS, but whose glue driver does not setplat->pcs_init, getspriv->hw->xpcs== NULL and no message at all, since the function just returns 0. "pcs-handle" is still a documented generic property inDocumentation/devicetree/bindings/net/ethernet-controller.yaml.The changelog explains this is harmless because:
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.Is that accurate? The core consumes
priv->hw->xpcsin two places that do not go throughplat->select_pcs():drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_phy_setup() { /* If we have an xpcs, it defines which PHY interfaces are supported. */ if (priv->hw->xpcs) pcs = xpcs_to_phylink_pcs(priv->hw->xpcs); else pcs = priv->hw->phylink_pcs; if (pcs) phy_interface_or(config->supported_interfaces, ...); }drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_init_phy() { if (priv->hw->xpcs && xpcs_get_an_mode(priv->hw->xpcs, mode) == DW_AN_C73) return 0; }Without the XPCS,
supported_interfacesstays limited toplat->phy_interfaceand theDW_AN_C73"no PHY" path is lost, sostmmac_init_phy()can now fail where it previously succeeded.
Quoted 6 lines
Related, for Intel mGbE the callbacks are only installed inside the SGMII/1000BASEX branch of
intel_mgbe_common_data(), while the removed common code created an XPCS from "pcs-handle" regardless of interface mode. Should a warning be emitted when "pcs-handle" is present but nopcs_init()claims it, or should the changelog state the behaviour change explicitly?
This removal is intentional. Phylink relies on select_pcs() to obtain the PCS. Without that callback, the PCS is effectively never used, as phylink has no way to obtain it. Requiring pcs_init() to be set is a way to ensure that only platforms that know they need a PCS will create one.
The two places in stmmac_main.c that read priv->hw->xpcs directly (stmmac_phy_setup and stmmac_init_phy) do so under the assumption that the platform has already set up a working PCS. A platform with "pcs-handle" but no pcs_init()/select_pcs() has never had a functional PCS.
However, to make this behaviour change explicit and avoid silent failures, I'll add a warning or a comment in the changelog describing the requirement. If you prefer, I can also emit a diagnostic when "pcs-handle" is present but no pcs_init() claims it.
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c int stmmac_mdio_reset(struct mii_bus *bus) · line 436
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +1
-0+ ret = priv->plat->pcs_init (priv);if (ret)return dev_err_probe (priv->device, ret,"No xPCS found\n" );[Severity: Low]
This is a pre-existing wording problem and not introduced by this patch, but with the generic XPCS code gone this is now the only diagnostic instmmac_pcs_setup(), and three of the fourpcs_init()implementers do not create an XPCS:
Quoted 7 lines
socfpga_dwmac_pcs_init() -> lynx_pcs_create_mdiodev() rzn1_dwmac_pcs_init() -> miic_create() renesas_gmac_pcs_init() -> miic_create()So a
miic_create()orlynx_pcs_create_mdiodev()failure, including -EPROBE_DEFER, is reported as "No xPCS found". Would something like "failed to initialise PCS" be more accurate here?
I'll change it to "Failed to initialize PCS".
Coia Prant
maintainerRe: [PATCH net-next v4 03/10] phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568
In reply to Jakub KicinskiQuoted 60 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568This adds a "rockchip,sgmii-mac-sel" DT property to the RK3568 combphy driver so the SGMII interface can be routed to GMAC0 or GMAC1 through the pipe GRF
pipe_sgmii_mac_selbit. The value defaults to 1 (GMAC1) when the property is absent, and is written duringPHY_TYPE_SGMIIconfiguration.A few questions below.
Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +0
-0[ ... ]
Quoted 9 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +1
-0@@ -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,drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static int rockchip_combphy_parse_dt(struct device *dev, struct rockchip_combphy · line 382
Quoted 6 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +3
-0@@ -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); +[Severity: Medium]
Since the return value ofdevice_property_read_u32()is discarded here,rockchip_combphy_parse_dt()cannot distinguish "the DT asked for GMAC1" from "the DT said nothing about the mux".The result is that
rk3568_combphy_cfg()writesPIPE_GRF0x0040bit 1 on everyPHY_TYPE_SGMIIbring-up, including for device trees that do not have the new property. Before this patch that bit was never touched, so whatever routing the SoC reset or the boot firmware established was left alone.The commit message states:
"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."
The "or omitted" case now depends entirely on that reset value being 1. If the reset value is actually 0, or if firmware routed SGMII to GMAC0 on a board wired that way and its DT lacks the property, does
phy_init()still return success while the XPCS ends up attached to the wrong MAC, giving a link that never comes up and no message explaining why?
Quoted 8 lines
Would it make sense to only write the bit when the property is actually present, for example:
if (!device_property_read_u32(dev, "rockchip,sgmii-mac-sel", &priv->sgmii_mac_sel)) priv->sgmii_mac_sel_valid = true;so that omitting the property leaves the mux untouched?
SGMII has never been functional on RK3568 in mainline before this series. There is no existing user that relies on the old behaviour, and no in-tree device tree enables SGMII. Boards that have the SGMII routing configured in their bootloader were never able to use it with a mainline kernel, because the driver did not support it.
Given that, unconditionally writing the MAC-select bit (with a default of GMAC1, which matches the hardware reset value) is reasonable. It makes the driver's behaviour explicit and deterministic rather than depending on whatever the bootloader happened to leave behind.
I'll keep the current logic, but I'll make the commit message clearer about the hardware reset value and the fact that SGMII is new in mainline.
Quoted 28 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv) · line 882
Quoted 9 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +2
-0priv->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 );[Severity: Low]
The binding added in the preceding patch of this series declares the property as:rockchip,sgmii-mac-sel:
$ref: /schemas/types.yaml#/definitions/uint32 enum: [0, 1] default: 1but "
priv->sgmii_mac_sel> 0" collapses the value to a boolean, androckchip_combphy_parse_dt()does no range check.Does that mean a device tree setting the property to 2 or
0xffffffffis silently treated as GMAC1 rather than rejected? Similarly, a present-but-malformed property (wrong length or type) makesdevice_property_read_u32()fail, and the pre-seeded default of 1 is used with no diagnostic.
Quoted 4 lines
dtschema only validates in-tree device trees, so for bootloader-supplied DTs or overlays the driver is the only place the enum can be enforced. Would checking the value against {0, 1} and returning an error, or alternatively documenting the property as a plain flag, close that gap?
The property is validated by dtschema. For in-tree device trees, values other than 0 or 1 are rejected at build time. I don't think the driver needs to duplicate this check.
Quoted 10 lines
[Severity: Low]
The mux write is only added to thePHY_TYPE_SGMIIcase. The adjacentPHY_TYPE_QSGMIIcase inrk3568_combphy_cfg()programs the same pipe-grf register (pipe_xpcs_phy_readyat offset0x0040bit 2) but never touches the MAC-select bit:case PHY_TYPE_QSGMII: rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); ...
Quoted 8 lines
The binding gates the property on the compatible only, not on the PHY type, and
rockchip_combphy_parse_dt()runs at probe time before the PHY type is known fromrockchip_combphy_xlate().If a device tree sets rockchip,sgmii-mac-sel on a combphy that a consumer later claims with
PHY_TYPE_QSGMII, is the requested routing simply dropped with no warning? If the property is meant to be SGMII-only, would rejecting or warning about it for other PHY types make that explicit?
You're right that the property is SGMII-only. For QSGMII, the hardware routes to both MACs internally, so there is no MAC-selection bit to program. We have not found any QSGMII device that exists outside of OEM SDK EVB code, and mainline XPCS does not support QSGMII, so this case is not currently reachable. I'll leave it as is.
Quoted 20 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = { · line 997
Quoted 11 lines
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +1
-0rockchip_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 },For reference on the first two comments: this disable/enable encoding ({
0x0040, 1, 1,0x00,0x01}) is what maps the DT value onto GMAC0/GMAC1, androckchip_combphy_param_write()always sets the write-enable mask:tmp = en ? reg->enable : reg->disable; mask = GENMASK(reg->bitend, reg->bitstart); val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
Quoted 7 lines
so the bit is committed to hardware on every SGMII bring-up regardless of whether the device tree expressed a preference. Could the TRM bit polarity and the claimed reset value of 1 be confirmed in the commit message?
Note that no in-tree Rockchip device tree requests
PHY_TYPE_SGMIIbefore this series, and the only user (rk3568-photonicat.dts) is added later in the series, so nothing in-tree changes behaviour today.
You're right, the commit message should state this explicitly. I'll update it to describe both the bit polarity and the hardware reset value.
From the RK3568 TRM Part1 (Page 229), the PIPE_GRF_XPCS_CON0 register bit 1 is pipe_sgmii_mac_sel:
0: SGMII interface is routed to GMAC0
1: SGMII interface is routed to GMAC1
The hardware reset value is 1 (GMAC1). This matches the default I use when the property is absent.
I'll include this in the commit message and the binding description so that reviewers can verify the behaviour against the TRM.
Regarding the unconditional write: as I mentioned, SGMII has never been functional on RK3568 in mainline before this series, and no in-tree device tree enables it. So writing the bit on every SGMII bring-up does not change behaviour for any existing user.
Thanks,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support
In reply to Jakub KicinskiQuoted 31 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
dt-bindings: net: pcs: add rockchip,rk3568-xpcs supportThis adds a new standalone schema describing the Synopsys DesignWare XPCS as integrated on the Rockchip RK3568, with a CSR window, csr/eee clocks, a Naneng Combo SerDes phy, a power domain and four MII child ports. A few questions about the property set and the file naming below.
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 5
Quoted 11 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +5
-0@@ -0,0 +1,110 @@ +# 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#[Severity: Low]
This isn't a bug, but should the file be named after the documented compatible, i.e. rockchip,rk3568-xpcs.yaml? The other schemas in
Documentation/devicetree/bindings/net/pcs/all use that form:
snps,dw-xpcs.yaml, fsl,lynx-pcs.yaml, mediatek,sgmiisys.yaml, renesas,rzn1-miic.yaml.
Quoted 7 lines
A rename would also have to update the $id line above, since it encodes the same name.
Related: the example at the bottom uses pcs@fda00000 and pcs-mii@0, while the sibling PCS binding uses the generic ethernet-pcs@... node name, and no $nodename constraint is added here. The SoC dtsi added later in the series copies the pcs@/pcs-mii@ names verbatim.
I chose rockchip-dwxpcs.yaml intentionally, in case Rockchip integrates the same XPCS IP into other SoCs in the future. The filename is more generic and can cover multiple compatible strings if needed.
However, I understand the convention is to name the file after the compatible string (like snps,dw-xpcs.yaml and fsl,lynx-pcs.yaml). If you prefer rockchip,rk3568-xpcs.yaml, I will rename it.
Quoted 14 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +3
-0+properties: + compatible: + const: rockchip,rk3568-xpcs[Severity: Low]
This isn't a bug, but would a set of SoC-specific if/then blocks in
Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yamlbe preferred over a second schema for the same IP?To be clear, a snps,dw-xpcs fallback compatible or a $ref to that schema would be wrong here. The glue driver added later in the series builds CSR addresses with only a 3-bit MMD field:
Quoted 8 lines
return FIELD_PREP(0x70000, dev) | FIELD_PREP(0xffff, reg);and remaps the vendor MMDs in
xpcs_rk_mdio_read_remapping()/xpcs_rk_mdio_write_remapping(), so the generic direct mapping described in snps,dw-xpcs.yaml would compute different offsets.So the only question is where the description should live, not whether the compatible should be shared.
As you noted, a $ref to snps,dw-xpcs.yaml would be wrong because the Rockchip glue uses a different address mapping (3-bit MMD field with remapping). A separate schema is the right choice.
Quoted 7 lines
[Severity: Low]
Should the
sbd_intr_ooutput be described as an optional interrupts property? With additionalProperties: false at the end of the file, a conforming device tree cannot carry it, although adding it later stays backward compatible.
Quoted 5 lines
The single unnamed 2 MiB window itself does match the driver:
xpcs_rk_init_res()usesplatform_get_resource(pdev, IORESOURCE_MEM, 0)and requiresresource_size(res)>=SZ_2M, and the largest computed offset0x7FFFF<< 2 =0x1FFFFCstill falls inside0x200000, so reg-names and reg-io-width are not needed.
These are optional and can be added later without breaking ABI. I'll leave them out for now, since the mainline XPCS driver doesn't use them.
Quoted 42 lines
Quoted 15 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +15
-0+ + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + clocks: + items: + - description: APB3 bus interface clock (clk_csr_i), required for register access + - description: EEE clock (clk_eee_i), required for Energy Efficient Ethernet operation + + clock-names: + items: + - const: csrDocumentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 57
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10
-0+ - const: eee + + phys: + maxItems: 1 + + phy-names: + const: serdes + + power-domains: + maxItems: 1[Severity: Low]
Should resets/reset-names be described here too? The RK3568 CRU exposes four dedicated reset lines for this block in
include/dt-bindings/clock/rk3568-cru.h:#define SRST_XPCS 150 #define SRST_XPCS_TX_DIV10 151 #define SRST_XPCS_RX_DIV10 152 #define SRST_XPCS_XGXS_RX 153Since the schema ends with additionalProperties: false, a conforming device tree cannot express them at all, and the glue driver added later in the series never requests a reset control, so it depends on those resets already being de-asserted.
Quoted 7 lines
Peer blocks in the same island do describe theirs, e.g. combphy0 with resets = <&cru
SRST_PIPEPHY0> and gmac0 with resets = <&cruSRST_A_GMAC0>.Note the XPCS core does provide a register-level reset via
xpcs_soft_reset()indrivers/net/pcs/pcs-xpcs.c, so a state-machine restart is possible without the CRU resets, and an optional resets property can be added later without breaking the ABI.
These are optional and can be added later without breaking ABI. I'll leave them out for now, since the mainline XPCS driver doesn't use them.
Quoted 18 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 70
Quoted 12 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +12
-0+patternProperties: + "^pcs-mii@[0-3]$": + type: object + description: + One of the four MII ports of the XPCS. The port is linked to an + Ethernet MAC controller via the pcs-handle property in the MAC's + device tree node. + + properties: + reg: + description: MII port number. + enum: [0, 1, 2, 3][Severity: Low]
This isn't a bug, but is pcs-mii@N the intended name for these per-port children rather than the generic ethernet-pcs@N?
Quoted 7 lines
Resolving a MAC pcs-handle that points at one of these children does work with the rest of the series:
xpcs_rk_create()indrivers/net/pcs/pcs-xpcs-rk.creads the child reg, walks up withof_get_parent()and callsxpcs_create_mdiodev(pxpcs->bus, port), andrk_pcs_init()indrivers/net/ethernet/stmicro/stmmac/dwmac-rk.cdoesof_parse_phandle(np, "pcs-handle", 0). So the open point is just the node naming.
Yes, I will use ethernet-pcs@N
Quoted 43 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +6
-0+ + required: + - reg + + additionalProperties: false +Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml new file +10
-0+required: + - compatible + - reg + - "#address-cells" + - "#size-cells" + - clocks + - clock-names + - phys + - phy-names + - power-domains[Severity: Medium]
Does requiring phys and phy-names here make
dtbs_checkfail for the RK3568 boards? The SoC node added later in the same series omits both, because the SerDes selection is board specific:
arch/arm64/boot/dts/rockchip/rk3568.dtsi: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";and only the board fills them in:
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts:&xpcs { status = "okay"; phys = <&combphy2 PHY_TYPE_SGMII>; phy-names = "serdes"; };
Quoted 6 lines
dtschema validates nodes irrespective of status = "disabled", so wouldn't every rk3568*.dtb apart from the Photonicat report "'phys', 'phy-names' are required properties"?
Should phys/phy-names be dropped from required (or made conditional), or should the SoC dtsi carry them instead?
This is not actually a problem. dtbs_check and CHECK_DTBS only validate required properties for enabled nodes. As confirmed by Rob Herring:
"the dtbs_check only checks required properties from yaml if the
node is enabled. Yes, that is exactly how it works."
The xpcs node in rk3568.dtsi is marked status = "disabled", so boards that include rk3568.dtsi without enabling XPCS will not trigger any validation warnings. Only boards that enable it need to provide phys and phy-names, and they do so at the board level (as Photonicat does).
This is also the standard pattern for SoC nodes with board-specific
connections: keep the SoC node disabled, and let the board dts enable it with all required properties.
The phys/phy-names properties cannot be moved into rk3568.dtsi anyway, because the SerDes connection is board-specific: some boards use combphy1 for SGMII, others use combphy2 (like Photonicat).
Thanks,
Coia Prant
maintainerRe: [PATCH net-next v4 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes
In reply to Jakub KicinskiQuoted 60 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodesThis adds the RK3568 Synopsys DesignWare XPCS node (with four pcs-mii sub-nodes) plus two 125 MHz fixed-clock nodes used as GMAC reference clocks. The XPCS node and its sub-nodes are disabled by default and are meant to be completed and enabled at the board level.
A couple of questions about the new nodes below.
Quoted 7 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +0
-0@@ -110,6 +110,51 @@ sata0: sata@fc000000 { status = "disabled"; };arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 121
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +9
-0+ 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";[Severity: Medium]
Does this node validate against the binding added earlier in the same series?Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yamllists phys and phy-names unconditionally:required:
- compatible
- reg
- "#address-cells"
- "#size-cells"
- clocks
- clock-names
- phys
- phy-names
- power-domainsThe node here supplies neither, and dt-validate does not skip nodes with status = "disabled", so
dtbs_checkshould report "'phys' is a required property" and "'phy-names' is a required property" for every rk3568 dtb that includes this dtsi.At the tip of the series only
rk3568-photonicat.dtsfills them in:&xpcs { status = "okay"; phys = <&combphy2 PHY_TYPE_SGMII>; phy-names = "serdes"; };
Quoted 6 lines
so rk3568-evb, rk3568-rock-3a, rk3568-roc-pc, rk3568-radxa-cm3j, rk3568-wolfvision-pf5 and friends would still be missing them.
If which combphy carries SGMII is genuinely a board-level choice, should phys/phy-names be moved out of the unconditional required: list in the binding instead, or should the dtsi provide a default?
As I replied in the earlier patch, dtbs_check and CHECK_DTBS only validate required properties for enabled nodes, as confirmed by Rob Herring. The xpcs node in rk3568.dtsi is status = "disabled", so boards that include rk3568.dtsi without enabling XPCS will not trigger any validation warnings. Only boards that enable it need to provide phys and phy-names, and they do so at the board level.
The phys/phy-names properties cannot be moved into rk3568.dtsi anyway, because the SerDes connection is board-specific: some boards use combphy1 for SGMII, others use combphy2 (like Photonicat).
Quoted 28 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi sata0: sata@fc000000 { · line 156
Quoted 13 lines
arch/arm64/boot/dts/rockchip/rk3568.dtsi +13
-0+ 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>; + };[Severity: Low]
These two node names take the deprecated branch of the fixed-clock $nodename schema.Documentation/devicetree/bindings/clock/fixed-clock.yamlhas:$nodename:
anyOf:
- description:
Preferred name is 'clock-<freq>' with <freq> being the output frequency as defined in the 'clock-frequency' property.
pattern: "^clock-([0-9]+|[a-z0-9-]+)$"
- description: Any name allowed
deprecated: true
Quoted 7 lines
xpcs-gmac0-clock and xpcs-gmac1-clock do not match the preferred pattern, so they land on the "Any name allowed" branch. Newer Rockchip dtsi files use the preferred form already, for example
rk3528.dtsiwith
xin24m: clock-xin24m andgmac0_clk: clock-gmac50m.Could these be named clock-xpcs-gmac0 and clock-xpcs-gmac1? The labels
xpcs_gmac0_clk/xpcs_gmac1_clkand all references would stay the same.
You're right, xpcs-gmac0-clock and xpcs-gmac1-clock do not match the preferred clock-<freq> pattern in fixed-clock.yaml. I'll rename them to clock-xpcs-gmac0 and clock-xpcs-gmac1. The labels xpcs_gmac0_clk and xpcs_gmac1_clk will be match clock-output-names.
Best,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery
In reply to Jakub KicinskiQuoted 22 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: pcs: xpcs: add ANRESTART support for SGMII link recoveryThe patch sets
BMCR_ANRESTARTtogether withBMCR_ANENABLEwhen configuring C37 SGMII in-band negotiation, and clears the latched CL37 AN complete status before doing so. It also restarts negotiation fromxpcs_get_state_c37_sgmii()when AN completion is latched but the link is reported down.Quoted 4 lines
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.
[Severity: Low]
The changelog describes a user visible failure ("the link stays down forever") in long standing shared code, but there is no Fixes: tag and no statement about which histories are affected.
Quoted 8 lines
The only hardware named here, RK3568 XPCS, does not exist in the baseline
tree: searching forxpcs_rk, rk3568-xpcs or pcs-xpcs-rk underdrivers/netat879e280b8486returns nothing, and the glue driver arrives later in this series ("net: pcs: xpcs: add Rockchip RK3568 platform glue driver").Could the changelog either name the pre-existing commit being fixed, or say explicitly that the affected platform is introduced later in the same series, so that stable tooling does not have to guess?
The affected platform (RK3568 XPCS) is introduced later in the same series. I'll make that explicit in the changelog so stable tooling does not have to guess.
Quoted 41 lines
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c +0
-0@@ -816,9 +816,14 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs,if (ret <0 )return ret;drivers/net/pcs/pcs-xpcs.c static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, · line 826
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +6
-1+/* 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 );[Severity: Medium]
Should the comment at the top ofxpcs_config_aneg_c37_sgmii()be updated along with this change? It still says the opposite of what the code now does:drivers/net/pcs/pcs-xpcs.c:xpcs_config_aneg_c37_sgmii() {
/* For AN for C37 SGMII mode, the settings are :-
...
* 5)VR_MII_MMD_CTRLBit(12) [AN_ENABLE] = 1b (Enable SGMII AN) *
* Note thatVR_MII_MMD_CTRLisMII_BMCR.
*
* Note: Since it is MAC side SGMII, there is no need to set
*SR_MII_AN_ADV. ... There is also no need to
* trigger AN restart for MAC-side SGMII.
*/On the default path this same function selects MAC side SGMII:
} else { tx_conf = DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII; }
Quoted 7 lines
so the restart is now issued for exactly the case the comment says does not need it. The new
DW_VR_MII_AN_INTR_STSwrite is also a sixth step that the enumerated sequence does not mention.If the databook statement no longer holds for these parts, could the comment be corrected, so that a later reader does not remove the ANRESTART bit as a mistake?
You're right. The comment still states that AN restart is not needed for MAC side SGMII, which now contradicts the code. I'll update it to note that on some hardware (e.g. RK3568) the PCS does not restart AN automatically when the link comes back, so an explicit ANRESTART is required.
Quoted 39 lines
Quoted 7 lines
drivers/net/pcs/pcs-xpcs.c +1
-2@@ -1093,10 +1098,15 @@ static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs,return 0 ; } -/* Clear AN complete status or interrupt */ -if (state->an_complete) +if (state->an_complete) {drivers/net/pcs/pcs-xpcs.c static int xpcs_get_state_c37_sgmii(struct dw_xpcs *xpcs, · line 1111
Quoted 10 lines
drivers/net/pcs/pcs-xpcs.c +6
-0+/* 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 ; }[Severity: Medium]
Can this sequence get stuck if thexpcs_modify()fails?The latched status is cleared first, and
DW_VR_MII_AN_STS_C37_ANCMPLT_INTRis the only thing that brings execution back into this branch:state->an_complete = ret & DW_VR_MII_AN_STS_C37_ANCMPLT_INTR;So if the clear succeeds but the restart does not, every later poll reads ANCMPLT as 0,
state->an_completestays false, and the restart is never retried, leaving the port down with AN idle until something callspcs_configagain.
mdiodev_c45_modify()does a read followed by a write, so there are two places it can return an error, for example a bus-ETIMEDOUT, or with the Rockchip glue added later in this series thepm_runtime_resume_and_get()error path inxpcs_rk_read_reg()/xpcs_rk_write_reg().Both return values are also discarded and the function still ends with return 0, so the diagnostic in the caller can never fire for them:
Quoted 8 lines
case DW_AN_C37_SGMII: ret = xpcs_get_state_c37_sgmii(xpcs, state); if (ret) dev_err(&xpcs->mdiodev->dev, "%s returned %pe\n", "xpcs_get_state_c37_sgmii", ERR_PTR(ret));Would it be better to assert
BMCR_ANRESTARTbefore clearing the latched status, and to propagate both return codes toxpcs_get_state()?
The current order (clear the latched status first, then restart AN) is intentional. If the restart is issued first, the newly completed AN status could be cleared by the subsequent write, losing the completion event.
I'll keep the original order and propagate the return value of xpcs_modify() so the caller can observe errors on the restart path.
Best,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to Jakub KicinskiQuoted 49 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: pcs: xpcs: add Rockchip RK3568 platform glue driverThis adds a glue driver for the Synopsys DesignWare XPCS found on RK3568, which is reached through APB3 memory-mapped registers instead of a real MDIO bus. The driver registers a virtual MDIO bus that remaps the four MII ports onto their respective MMDs, and exports
xpcs_rk_create()so a MAC driver can obtain adw_xpcsinstance.A few questions below.
Quoted 9 lines
drivers/net/pcs/Kconfig +1
-0@@ -12,6 +12,29 @@ config PCS_XPCS This module provides a driver and helper functions for Synopsys DesignWare XPCS controllers. +if PCS_XPCSdrivers/net/pcs/Kconfig config PCS_XPCS · line 25
Quoted 10 lines
drivers/net/pcs/Kconfig +10
-0+ +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.[Severity: Medium]
Should this new user-visible symbol be part of a patch whose changelog only describes adding Rockchip RK3568 support?Two side effects of introducing
PCS_XPCS_PLATFORMare not mentioned anywhere in the commit message:- the "snps,dw-xpcs" platform glue moves out of pcs_xpcs.ko into a new pcs-xpcs-plat.ko, which changes module packaging for every existing memory-mapped DW XPCS user
- the glue becomes optional, so a config with PCS_XPCS=y and PCS_XPCS_PLATFORM=n silently loses "snps,dw-xpcs" support
Quoted 3 lines
Since this restructuring of shared code is independent of the Rockchip glue, could it be split into its own preparatory patch with the effects described?
You're right that this restructuring is independent of the Rockchip glue, but the "silently loses snps,dw-xpcs support" concern is not
accurate: PCS_XPCS_PLATFORM has default PCS_XPCS, so when PCS_XPCS is enabled, the platform glue is also enabled by default. A user would have to explicitly set CONFIG_PCS_XPCS_PLATFORM=n to lose it.
The module packaging change (snps,dw-xpcs moving from pcs_xpcs.ko to pcs-xpcs-plat.ko) is real, though. I'll mention it in the changelog.
I'll keep the Kconfig change in this patch since it is small and directly related to making the Rockchip glue a separate module, but I'll describe the module packaging side effect explicitly.
Quoted 30 lines
drivers/net/pcs/Kconfig config PCS_XPCS · line 30
Quoted 5 lines
drivers/net/pcs/Kconfig +5
-0+ +config PCS_XPCS_ROCKCHIP + tristate "Rockchip XPCS controller support" + default ARCH_ROCKCHIP + depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)[Severity: Medium]
Do the dependencies here needGENERIC_PHYandPM_GENERIC_DOMAINSas well?
xpcs_rk_probe()cannot make forward progress without either of them. WithCONFIG_GENERIC_PHY=n, the first probe step hits the stub:
include/linux/phy/phy.h:static inline struct phy *devm_phy_get(struct device *dev, const char *string) { return ERR_PTR(-ENOSYS); }so
xpcs_rk_serdes_phy_init()always fails throughdev_err_probe().With
CONFIG_PM_GENERIC_DOMAINS=n(which covers everyCONFIG_PM=nbuild),xpcs_rk_serdes_phy_poweron()hits:
include/linux/pm_domain.h:static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on) { return -EOPNOTSUPP; }
Quoted 4 lines
and the driver treats that as fatal. Since the symbol is also default
ARCH_ROCKCHIP, it can be built and matched in configurations where it can never bind. Would adding depends onGENERIC_PHYandPM_GENERIC_DOMAINSbe appropriate?
Sure, I will add it.
Quoted 40 lines
drivers/net/pcs/Kconfig config PCS_XPCS
Quoted 11 lines
drivers/net/pcs/Kconfig +11
-0+static int xpcs_rk_serdes_phy_init(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + + pxpcs->serdes_phy = devm_phy_get(dev, "serdes"); + if (IS_ERR(pxpcs->serdes_phy)) + return dev_err_probe(dev, PTR_ERR(pxpcs->serdes_phy), + "Failed to get SerDes PHY\n"); + + return 0; +}[Severity: Low]
Is the mandatory "serdes" PHY consistent with the device tree added by the rest of the series?The binding added in this series lists phys and phy-names under required:
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yaml:
required:
- compatible
- reg
...
- phys
- phy-names
- power-domainsbut the SoC node has neither property:
arch/arm64/boot/dts/rockchip/rk3568.dtsi: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";
Quoted 6 lines
dtschema validates nodes regardless of status, so every RK3568 DTB other than the one board patched later in the series should report that phys is a required property. Any board that enables the node without adding phys/phy-names also gets an unconditional probe failure here, since there is no
devm_phy_get_optional()path. Should the PHY properties move to the SoC dtsi, or should they be dropped from required:?
As replied earlier, the phys/phy-names properties cannot move into rk3568.dtsi because the SerDes connection is board-specific. Boards that enable XPCS must provide them.
Quoted 37 lines
Quoted 10 lines
drivers/net/pcs/Kconfig +10
-0+static int xpcs_rk_init_clk(struct dw_xpcs_rk *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + int ret; + + pxpcs->csr_clk = devm_clk_get(dev, "csr"); + if (IS_ERR(pxpcs->csr_clk)) + return dev_err_probe(dev, PTR_ERR(pxpcs->csr_clk), + "Failed to get CSR clock\n"); +drivers/net/pcs/Kconfig
Quoted 10 lines
drivers/net/pcs/Kconfig +10
-0+ pxpcs->eee_clk = devm_clk_get(dev, "eee"); + if (IS_ERR(pxpcs->eee_clk)) + return dev_err_probe(dev, PTR_ERR(pxpcs->eee_clk), + "Failed to get EEE clock\n"); + + ret = clk_prepare_enable(pxpcs->eee_clk); + if (ret) { + dev_err(dev, "Failed to enable EEE clock\n"); + return ret; + }[Severity: Low]
The EEE clock is acquired and permanently enabled, but nothing ever derives the XPCS 100 ns multiplier from its rate. Should this driver callxpcs_config_eee_mult_fact()the waydwmac-intel.cdoes?Without it
xpcs->eee_mult_factstays 0, and the core programs that value verbatim when EEE is turned on:
drivers/net/pcs/pcs-xpcs.c:/* Configure the eee_mult_fact so that * clk_eee_time_period * (mult_fact + 1) is within the range * 80 to 120ns. */ val = ... FIELD_PREP(DW_VR_MII_EEE_MULT_FACT_100NS, xpcs->eee_mult_fact);
Quoted 4 lines
With the RK3568 EEE clock parents (125/200 MHz, so a 5-8 ns period), a multiplier of 0 puts the LPI timing well below that range. The register reset value is also 0, so nothing valid is being overwritten, but is the timing expected to be programmed here?
mainline's clk-rk3568.c registers CLK_XPCS_EEE with a parent mux between gpll200 (200 MHz) and cpll125 (125 MHz), controlled by CRU_CLKSEL_CON29 bit 13. The reset value is 0 (gpll200, 200 MHz), and no in-tree DTS changes it, so the default multiplier is 19.
To stay correct if a board changes the mux, I'll derive the value at runtime in xpcs_rk_init_clk() where the EEE clock is already obtained:
pxpcs->eee_mult_fact =
DIV_ROUND_CLOSEST(100 * clk_get_rate(pxpcs->eee_clk),
1000000000UL) - 1;and call xpcs_config_eee_mult_fact() in xpcs_rk_create() right after xpcs_create_mdiodev() succeeds, since that is where the dw_xpcs pointer becomes available.
This yields 19 for 200 MHz (100 ns) and 12 for 125 MHz (104 ns), both within the required 80..120 ns range.
Quoted 53 lines
Quoted 2 lines
drivers/net/pcs/Kconfig +2
-0+struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *np) +{[ ... ]
Quoted 11 lines
drivers/net/pcs/Kconfig +11
-0+ pdev = of_find_device_by_node(pcs_np); + of_node_put(pcs_np); + if (!pdev) + return ERR_PTR(-EPROBE_DEFER); + + device_lock(&pdev->dev); + pxpcs = platform_get_drvdata(pdev); + if (!pxpcs || !pxpcs->bus) { + device_unlock(&pdev->dev); + put_device(&pdev->dev); + return ERR_PTR(-EPROBE_DEFER);drivers/net/pcs/Kconfig
Quoted 10 lines
drivers/net/pcs/Kconfig +10
-0+ } + + xpcs = xpcs_create_mdiodev(pxpcs->bus, (int)port); + device_unlock(&pdev->dev); + if (IS_ERR(xpcs)) { + put_device(&pdev->dev); + return xpcs; + } + + if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {[Severity: Medium]
Can themii_busbe freed under the newdw_xpcsin the window betweendevice_unlock()anddevice_link_add()?The bus is devm managed, so it goes away when the XPCS platform driver unbinds:
xpcs_rk_init_bus()bus = devm_mdiobus_alloc_size(dev, 0); ... ret = devm_mdiobus_register(dev, bus);and
xpcs_create_mdiodev()takes no reference on it:drivers/net/phy/mdio_device.c:mdio_device_create()
mdiodev->bus = bus; mdiodev->addr = addr;so the managed device link is the only thing keeping the supplier binding alive. With the lock already dropped, an unbind through sysfs or an rmmod of pcs-xpcs-rk can run
device_release_driver()before the link exists.put_device()keeps the struct device around but not the driver binding or its devm resources, leavingmdiodev->busand the ioremapped window pointing at freed memory. Thexpcs_destroy()call on thedevice_link_add()failure path would then touch it too.
Quoted 2 lines
Would creating the device link while still holding
device_lock(), or otherwise pinning the supplier before unlocking, close this?
I've addressed this by keeping device_link_add() inside the device_lock() critical section. device_link_add() uses global locks (device_links_lock and dpm_list_mtx), not the supplier's device_lock, so calling it while holding the lock is safe.
Quoted 8 lines
Quoted 1 line
+EXPORT_SYMBOL_GPL(xpcs_rk_create);
[Severity: Low]
As of this commit alone,xpcs_rk_create()has no in-tree caller, so the driver only probes, pins the power domain and SerDes, and registers the virtual MDIO bus without ever producing thephylink_pcsthe changelog describes.
Quoted 6 lines
This resolves later in the same series:
rk_pcs_init()indrivers/net/ethernet/stmicro/stmmac/dwmac-rk.ccallsxpcs_rk_create(priv->device, pcs_node),rk_gmac_probe()installs pcs_init/pcs_exit/select_pcs, andDWMAC_ROCKCHIPgains selectPCS_XPCS_ROCKCHIP. Noting it only in case the ordering was intentional.
This ordering is intentional. Patch 7 adds the XPCS glue driver (provider), and the consumer (rk_pcs_init() in dwmac-rk) is added in the next patch. This is the standard way to split provider and consumer
patches: each commit compiles on its own, but the full functionality only comes together at the end of the series.
The exported symbol has no caller until the next patch, which is expected for this kind of split.
Thanks,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
In reply to [email protected]Quoted 41 lines · <[email protected]> 于2026年9月8日周二 23:41写道:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition inxpcs_rk_createallows a concurrent unbind of the supplier to free the MDIO bus, leading to a Use-After-Free.
- [Medium] Incorrect LIFO teardown ordering in devres clock cleanup action violates proper device initialization and PM hierarchy rules.
--commit
7142dbf6b28b5ee94d0edc969bcf16d1183a5f41
Author: Coia Prant <[email protected]>net: pcs: xpcs: add Rockchip RK3568 platform glue driver
This commit adds a platform glue driver for the Synopsys DesignWare xpcs integrated in the Rockchip RK3568 SoC. It creates a virtual mdio bus to translate mdio operations to apb3 memory-mapped register accesses.
Quoted 5 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +0
-0[ ... ]
drivers/net/pcs/pcs-xpcs-rk.c line 327
Quoted 8 lines
drivers/net/pcs/pcs-xpcs-rk.c new file +8
-0+static void xpcs_rk_exit_clk (void *data) +{ +struct dw_xpcs_rk *pxpcs = data; +struct device *dev = &pxpcs->pdev->dev; + +clk_disable_unprepare (pxpcs->eee_clk); + +pm_runtime_force_suspend (dev);[Severity: Medium]
Does this sequence result in the clock being disabled before the device is suspended?In
xpcs_rk_init_clk(),eee_clkis enabled first, followed by a call topm_runtime_enable(), allowing the device to become runtime active. During teardown,pm_runtime_force_suspend()invokesxpcs_rk_pm_runtime_suspend()to disablecsr_clk.
Quoted 4 lines
Calling
clk_disable_unprepare()foreee_clkbeforepm_runtime_force_suspend()violates last-in, first-out ordering, disabling the prerequisite clock while the device is still considered active. Shouldpm_runtime_force_suspend()be called prior to disabling theeee_clk?
Sure, I will reorder it.
Coia Prant
maintainerRe: [PATCH net-next v4 08/10] net: stmmac: dwmac-rk: add SGMII support for RK3568
In reply to Jakub KicinskiQuoted 36 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: stmmac: dwmac-rk: add SGMII support for RK3568This adds SGMII glue for RK3568: a
set_to_sgmii()callback that programs GMAC CON1 bit 7, pcs_init/pcs_exit/select_pcs callbacks that create the Rockchip XPCS from the "pcs-handle" phandle, and a rework of therk_gmac_powerup()error unwinding into a singleclk_disablelabel.A few questions below.
Quoted 5 lines
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.[Severity: Low]
Does this paragraph describe the baseline? At879e280b8486there is no SGMII case and no goto inrk_gmac_powerup(), and the order is already:ret = rk_get_phy_intf_sel(bsp_priv->phy_iface); if (ret < 0) return ret; intf = ret; ret = gmac_clk_enable(bsp_priv, true); if (ret) return ret; ... ret = rk_write_gmac_grf_reg(bsp_priv, val);
Quoted 7 lines
so
gmac_clk_enable()already preceded every register access and there was nothing that could bypass it. The change here is a pure reorder ahead ofrk_get_phy_intf_sel(), which touches no registers, plus the new unified unwind label.Would it be more accurate to describe this as preparing the ordering for the new SGMII path rather than as a fix for a synchronous external abort?
You're right. The baseline already had gmac_clk_enable() before any register access. This change is a reorder to prepare for the new SGMII path that skips rk_get_phy_intf_sel(), not a fix for a pre-existing SError. I'll correct the wording.
Quoted 61 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +0
-0[ ... ]
Quoted 29 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +13
-0@@ -809,6 +813,8 @@ static const struct rk_gmac_ops rk3528_ops = {#define RK3568_GRF_GMAC1_CON1 0x038c/* RK3568_GRF_GMAC0_CON1 && RK3568_GRF_GMAC1_CON1 */ +#define RK3568_GMAC_MODE_RMII_RGMII GRF_CLR_BIT(7) +#define RK3568_GMAC_MODE_SGMII_QSGMII GRF_BIT(7)#define RK3568_GMAC_FLOW_CTRL GRF_BIT(3)#define RK3568_GMAC_FLOW_CTRL_CLR GRF_CLR_BIT(3)#define RK3568_GMAC_RXCLK_DLY_ENABLE GRF_BIT(1)@@ -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 ); } +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 ); +} +static const struct rk_gmac_ops rk3568_ops = {drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk3568_set_to_rgmii(struct rk_priv_data *bsp_priv, · line 885
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-0.init = rk3568_init, .set_to_rgmii = rk3568_set_to_rgmii, + .set_to_sgmii = rk3568_set_to_sgmii, + .set_speed = rk_set_clk_mac_speed, .gmac_phy_intf_sel_mask = GENMASK_U16(6, 4), .supports_rmii = true, + .supports_sgmii = true,[Severity: Medium]
Who clears CON1 bit 7 for RMII on rk3568?
rk3568_set_to_rgmii()now explicitly writesRK3568_GMAC_MODE_RMII_RGMII, which shows bit 7 has to be programmed by the driver.rk3568_opsdeclaressupports_rmii= true but has no .set_to_rmii, so the RMII branch ofrk_gmac_powerup()is a no-op:case PHY_INTERFACE_MODE_RMII: dev_info(dev, "init for RMII\n"); if (bsp_priv->ops->set_to_rmii) bsp_priv->ops->set_to_rmii(bsp_priv); break;
Quoted 8 lines
and the generic GRF write uses
gmac_phy_intf_sel_mask=GENMASK_U16(6, 4), whose write-enable half-word never covers bit 7.Since
rk3568_set_to_sgmii()leaves bit 7 set persistently and nothing inrk_gmac_powerdown()restores it, can an RMII port come up muxed to the SerDes when bit 7 was left set by firmware or by a previous SGMII configuration of the same MAC (kexec, warm reboot)? The probe would report success while the link never works.
Good catch. rk3568_ops declares supports_rmii but has no .set_to_rmii, so the RMII branch is a no-op. If bit 7 was left set by SGMII or firmware, an RMII port would be muxed to the SerDes.
I'll add rk3568_set_to_rmii() that explicitly clears bit 7, and wire it up in rk3568_ops.
Since we set set_to_rmii and set_to_sgmii, supports_rmii and supports_sgmii will be omitted.
Quoted 23 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_phy_powerdown(struct rk_priv_data *bsp_priv) · line 1239
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +9
-0+static int rk_pcs_init (struct stmmac_priv *priv) +{ +struct device_node *np = priv->device->of_node; +struct device_node *pcs_node; +struct dw_xpcs *xpcs; + + pcs_node =of_parse_phandle (np,"pcs-handle" ,0 ); +if (!pcs_node) +return -ENODEV ;[Severity: Low]
Should "pcs-handle" be documented in the Rockchip MAC binding?This makes the property effectively mandatory for phy-mode = "sgmii" on
RK3568: a missing phandle returns-ENODEV, andstmmac_pcs_setup()turns that into a probe failure:drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c:stmmac_pcs_setup() { ret = priv->plat->pcs_init(priv); if (ret) return dev_err_probe(priv->device, ret, "No xPCS found\n"); }
Quoted 8 lines
Documentation/devicetree/bindings/net/rockchip-dwmac.yamldoes not mention pcs-handle at all - it is neither described nor conditionally required for the SGMII-capable compatibles - while the newDocumentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yamlsays the port "is linked to an Ethernet MAC controller via the pcs-handle property in the MAC's device tree node". Other stmmac glue bindings that parse this property describe it (renesas,rzn1-gmac.yaml, renesas,rzv2h-gbeth.yaml). Could the MAC binding be updated to match?
You're right, rockchip-dwmac.yaml should describe pcs-handle, since the driver now requires it for phy-mode = "sgmii". I'll add it to the MAC binding.
Quoted 26 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_powerup(struct rk_priv_data *bsp_priv) · line 1446
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-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;[Severity: Medium]
This isn't a bug introduced by this patch, but the bare return here cannot unwind a partially enabled clock domain.gmac_clk_enable()leaks the bulk clock references when the PHY clock fails:drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:gmac_clk_enable() { ret = clk_bulk_prepare_enable(bsp_priv->num_clks, bsp_priv->clks); if (ret) return ret; ret = clk_prepare_enable(bsp_priv->clk_phy); if (ret) return ret; ... bsp_priv->clk_enabled = true; }
Quoted 5 lines
The second failure path returns without
clk_bulk_disable_unprepare()and without settingclk_enabled, so the newclk_disablelabel,rk_gmac_powerdown()and the suspend path are all no-ops afterwards because the disable branch is gated onclk_enabled. Does this leave the bulk clocks prepared and enabled for the lifetime of the system?
This is a pre-existing bug, not introduced by this patch. The second failure path returns without clk_bulk_disable_unprepare() and without setting clk_enabled, so the new clk_disable label cannot unwind it. It should fix it as a separate small patch.
Quoted 29 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static void rk_get_interfaces(struct stmmac_priv *priv, void *bsp_priv, · line 1563
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +3
-0@@ -1486,6 +1557,9 @@ static void rk_get_interfaces(struct stmmac_priv *priv, void *bsp_priv,if (rk->supports_rmii)__set_bit (PHY_INTERFACE_MODE_RMII , interfaces); + +if (rk->supports_sgmii) +__set_bit (PHY_INTERFACE_MODE_SGMII , interfaces); }[Severity: Medium]
Is the SGMII advertisement here consistent with where the PCS is installed?
supports_sgmiiis true for every rk3568 instance regardless of DT, so SGMII always lands in phylink_config.supported_interfaces. The PCS plumbing, however, is only installed when the DT phy-mode is exactly SGMII (see therk_gmac_probe()hunk below).On an RK3568 board with phy-mode = "rgmii"/"rmii", phylink can still pick SGMII -
phylink_validate_phy()intersectsphy->possible_interfaceswithconfig->supported_interfaces- and then:drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_mac_select_pcs() { if (priv->plat->select_pcs) { pcs = priv->plat->select_pcs(priv, interface); if (!IS_ERR(pcs)) return pcs; } }
Quoted 5 lines
returns NULL because
select_pcsis unset, no XPCS was ever created (pcs_initis NULL), andrk_gmac_powerup()has already programmed the GRF once from the DT-derivedbsp_priv->phy_iface, sork3568_set_to_sgmii()never ran. Would gating the SGMII bit on the same condition that installs select_pcs/pcs_init keep the two in agreement?
The phy-mode is fixed by the device tree and does not change at runtime.
rk_gmac_powerup() programs the GRF according to bsp_priv->phy_iface, which is derived from phy-mode, not from supported_interfaces. So advertising SGMII in supported_interfaces does not cause the MAC to switch to SGMII on an RGMII board.
This is the same as the existing handling for RGMII and RMII, which are also advertised unconditionally when the SoC supports them. There is no inconsistency introduced by this patch.
Quoted 40 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c static int rk_gmac_probe(struct platform_device *pdev) · line 1684
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +6
-0static int rk_set_clk_tx_rate(void *bsp_priv_, struct clk *clk_tx_i,@@ -1602,6 +1676,17 @@ static int rk_gmac_probe(struct platform_device *pdev) plat_dat->suspend = rk_gmac_suspend; plat_dat->resume = rk_gmac_resume; +if (plat_dat->phy_interface ==PHY_INTERFACE_MODE_SGMII ) { +/* SGMII clock always runs at 125 MHz */ + plat_dat->set_clk_tx_rate =NULL ; + +/* SGMII requires a PCS */ + plat_dat->default_an_inband = true;[Severity: Medium]
Doesdefault_an_inbandguarantee in-band mode here?
include/linux/phylink.hdescribes it as a default that "a fixed-link specification will override", and phylink has two ways out of in-band:drivers/net/phy/phylink.c:phylink_parse_mode() { dn = fwnode_get_named_child_node(fwnode, "fixed-link"); if (dn || fwnode_property_present(fwnode, "fixed-link")) pl->cfg_link_an_mode = MLO_AN_FIXED; }drivers/net/phy/phylink.c:phylink_pcs_neg_mode() { neg_mode = PHYLINK_PCS_NEG_OUTBAND; if (pl->phydev) mode = MLO_AN_PHY; }With
set_clk_tx_ratecleared,stmmac_mac_link_up()then programs no rate at all:drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:stmmac_mac_link_up() { if (priv->plat->set_clk_tx_rate) { ret = priv->plat->set_clk_tx_rate(priv->plat->bsp_priv, priv->plat->clk_tx_i, interface, speed); }
Quoted 5 lines
So for phy-mode = "sgmii" with a fixed-link node, or with a PHY that cannot do in-band signalling, the fixed 125 MHz clock is used at 10/100 Mbps - which the commit message says gives working TX and failing RX. Should the driver reject out-of-band SGMII explicitly instead of relying on the default?
You're right. default_an_inband can be overridden by fixed-link, and phylink can fall back to outband if the PHY cannot do in-band. With set_clk_tx_rate = NULL, the MAC clock must stay at 125 MHz for 10/100 Mbps, otherwise the TX-works-RX-fails behaviour described in the changelog occurs.
I will document the in-band-only limitation in the changelog.
Thanks,
Coia
Coia Prant
maintainerRe: [PATCH net-next v4 09/10] arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port
In reply to Jakub KicinskiQuoted 15 lines · Jakub Kicinski <[email protected]> 于2026年9月13日周日 04:13写道:
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts &combphy1 { · line 247
Quoted 6 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +1
-0@@ -242,6 +243,7 @@ &combphy1 { &combphy2 { status = "okay"; + rockchip,sgmii-mac-sel = <0>; };[Severity: Low]
The changelog says:"Enable combphy2 with rockchip,sgmii-mac-sel = <0> to route the SGMII
interface to GMAC0."Is that description accurate? In the baseline the node already reads:
Quoted 7 lines
&combphy2 { status = "okay"; };so the only new thing here is the rockchip,sgmii-mac-sel property. Could the wording be adjusted to say the property is added to an already enabled combphy2?
You're right. combphy2 is already status = "okay" in the baseline; this patch only adds the rockchip,sgmii-mac-sel property to it. I'll fix the wording to say the property is added to an already-enabled combphy2.
Quoted 7 lines
[Severity: Low]
This isn't a bug, but the new properties do not follow the ordering used by the rest of this file, where properties come roughly alphabetically and status is last. Here rockchip,sgmii-mac-sel lands after status, in &gmac0 below pcs-handle comes before managed, and in the new &xpcs override status is first with phys/phy-names after it. Compare the existing &gmac1 override, which ends with status = "okay";. Could these be reordered?
I'll reorder the properties to follow the file's convention (roughly alphabetical, with status last)
Quoted 31 lines
Quoted 15 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +11
-0@@ -350,6 +391,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"; + };arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts rgmii_phy: ethernet-phy@3 { · line 414
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +8
-0+ + led@2 { + reg = <2>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_WAN; + default-state = "keep"; + }; + }; }; };[Severity: Low]
This hunk describes the LEDs of the pre-existing RGMII WAN PHY on &mdio1, which is already functional and unaffected by the SGMII enablement. The changelog justifies it only with:
Quoted 5 lines
"Also add LED configuration for the existing RGMII PHY on mdio1 for
consistency."Would it be preferable to split this into its own patch, so this commit contains only the SGMII LAN port enablement?
The LED configuration for both PHYs is kept in this patch because the two PHYs are the same Motorcomm family wired identically on this board, and describing them together keeps the two mdio nodes consistent. The change is purely descriptive and does not affect the SGMII enablement.
That said, if you prefer it split out, I can move the mdio1 LED description into a separate patch in v4.
Quoted 40 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts &xin32k { · line 654
Quoted 10 lines
arch/arm64/boot/dts/rockchip/rk3568-photonicat.dts +6
-0@@ -586,3 +646,13 @@ &xin32k { pinctrl-names = "default"; pinctrl-0 = <&clk32k_out1>; }; + +&xpcs { + status = "okay"; + phys = <&combphy2 PHY_TYPE_SGMII>; + phy-names = "serdes"; +};[Severity: Medium]
Should phys/phy-names live inrk3568.dtsirather than in each board file?The binding lists them as required properties of the XPCS node:
Documentation/devicetree/bindings/net/pcs/rockchip-dwxpcs.yamlrequired:
- compatible
- reg
- "#address-cells"
- "#size-cells"
- clocks
- clock-names
- phys
- phy-names
- power-domainsbut the SoC node in
arch/arm64/boot/dts/rockchip/rk3568.dtsihas neither: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";
Quoted 8 lines
Does this mean every rk3568 dtb reports pcs@fda00000 as missing the required phys and phy-names under make CHECK_DTBS=y, including boards that do not enable the XPCS?
The XPCS to combphy2 connection is internal to the SoC, so each board that enables it will have to repeat the same phandle, as this patch does. Could phys = <&combphy2
PHY_TYPE_SGMII>; and phy-names = "serdes"; be moved into the dtsi node instead?
As replied in the earlier patch, the SerDes connection is board-specific (some boards use combphy1 for SGMII, others use combphy2), so it cannot be moved into rk3568.dtsi.
Best,
Coia