net: pcs: Add generic PCS interface and Synopsys DW XPCS driver
v2 cover net: pcs: Add generic PCS interface and Synopsys DW XPCS driver
This RFC adds a PCS (Physical Coding Sublayer) uclass and a driver for the Synopsys DesignWare Ethernet PCS (DW XPCS) that implements it. I would still like feedback on the interface and on how the driver is structured. The MAC glue for the MP201 SoC that uses this interface is posted as a separate RFC series right after this one, and links back to it.
Background
----------
On SoCs with a DW XPCS between the MAC and the SerDes, the MAC driver has to configure the PCS and read back its link and auto-negotiation state to bring up Ethernet links.
Why a PCS uclass
----------------
Today: every MAC driver has its own XPCS code
fsl_enetc_xpcs_phy.c --> XPCS registers
dwc_eth_qos_intel.c --> XPCS registers
sja1105.c --> XPCS registers
designware.c (NPCM8xx) --> XPCS registersWith this series: MAC drivers share one interface
MP201 MAC glue ----+
other MAC drivers -+--> PCS uclass --> DW XPCS driver
(may follow later)What is in the series
---------------------
1/2 net: pcs: Add PCS uclass and generic interface
UCLASS_PCS, include/pcs.h, documentation, a sandbox PCS driver and dm tests for the uclass
2/2 net: pcs: Add Synopsys DesignWare XPCS driver
Architecture
------------
Where the PCS sits in the hardware:
+---------------------------+
| CPU running U-Boot |
+---------------------------+
| |
| MMIO | MMIO ("indirect" window)
v v
+-------+ +---------+ +--------------+
| MAC |<------->| DW XPCS |<------->| PMA / SerDes |<--> link partner
+-------+ +---------+ +--------------+
MAC-PCS PMA
interface interfaceThe SerDes (PMA) is set up by the platform, not by this series.
How the software is layered:
+----------------------------------------------------+
| network core, Ethernet uclass (UCLASS_ETH) |
+----------------------------------------------------+
|
v
+----------------------------------------------------+
| MAC driver + SoC glue (follow-up: MP201) |
+----------------------------------------------------+
| include/pcs.h
================ added by this series ================
v
+----------------------------------------------------+
| PCS uclass (UCLASS_PCS) patch 1 |
+----------------------------------------------------+
| |
v v
+--------------------------+ +------------------------+
| DW XPCS driver (patch 2)| | sandbox PCS driver |
| "snps,dw-xpcs" binding | | for the dm tests (p. 1)|
+--------------------------+ +------------------------+Interface
---------
struct pcs_ops has set_config(), get_state() and disable(), with a wrapper for each in include/pcs.h. struct pcs_config selects the interface mode (iface) and the negotiation mode (neg_mode: none, in-band or out-of-band). struct pcs_state reports link, auto-negotiation status and speed. The semantics are documented in doc/develop/driver-model/pcs.rst.
Supported modes
---------------
iface neg_mode AN Mbps PHY_INTERFACE_MODE_1000BASEKX PCS_NEG_INBAND Clause 37 1000 PHY_INTERFACE_MODE_10GBASER PCS_NEG_NONE none 10000 PHY_INTERFACE_MODE_10GKR PCS_NEG_INBAND Clause 73 10000
Any other iface is rejected with -EINVAL, a wrong neg_mode for a supported iface with -EOPNOTSUPP. A rejected request leaves the PCS as it was.
Other users of the Synopsys XPCS in the tree
--------------------------------------------
The same IP is already programmed by hand in:
drivers/net/fsl_enetc_xpcs_phy.c NXP ENETC, over MDIO drivers/net/dwc_eth_qos_intel.c Intel mGBE, over MDIO drivers/net/sja1105.c NXP SJA1105/SJA1110, over SPI drivers/net/designware.c NPCM8xx only, MMIO (indirect page)
I did not convert the Airoha PCS driver, since I have no Airoha hardware to validate a conversion. The MP201 glue is the first in-tree user of this interface.
Origin of the code
------------------
The programming sequences (Clause 73 AN, 10GBASE-R and 1000BASE-KX) are written from the Synopsys DesignWare Ethernet PCS databook. The register and bit names and some small parts of the design are taken from the Linux drivers/net/pcs/pcs-xpcs*.c driver. The code is not based on the proposed Linux series. The Synopsys copyright from the Linux file is kept in the file header.
Testing
-------
Tested on the Synopsys VDK emulator: probe, pcs_set_config() for the three modes, pcs_get_state() and pcs_disable(). This covers the register programming sequence only. No packet I/O was tested, and it has not been tested on real hardware.
The uclass is covered by dm tests that use a sandbox PCS driver (ut dm pcs_*). The XPCS driver itself has no sandbox emulation. Builds on sandbox and qemu_arm64.
Not done
--------
- More interface modes. They are planned for the same driver, as further cases in the mode validation and mode programming of pcs-xpcs.c: 10G SFP+ (copper with auto-negotiation, and optical SR/LR/DR/ER), 2.5GBASE-KX, 2.5GBASE-X, 1000BASE-CR, USXGMII, HS-SGMII and SGMII.
- Clause 73 Next Pages
- MDIO access and the "direct" register mapping
- Clocks and the interrupt of the binding
- External PHY handling. How the PCS and an external PHY between it and the link partner are configured together (interface mode, and which side negotiates) is not designed yet. It is planned as a follow-up to this interface.
- PMA/SerDes initialisation, which must be done before pcs_set_config() (see doc/develop/driver-model/pcs-xpcs.rst)
Changes in v2:
- Add a dedicated UCLASS_PCS instead of using UCLASS_MISC (Peter, Tom)
- Add SPDX headers and the Linux copyright (Tom)
- Add documentation: pcs.rst, pcs-xpcs.rst and the API page (Tom)
- Build the driver on sandbox, and add a sandbox PCS driver with dm
tests for the uclass (Tom, Peter)
- Replace the an_mode and speed fields of struct pcs_config with iface
and neg_mode
- Probe: do not compare the device ID with a fixed value, because it
holds the OUI set by the SoC integrator. Read it from the PCS MMD
instead of the PMA/PMD MMD, and log it at debug level
- Clause 37: set the restart bit together with the enable bit
- List the other in-tree users of the XPCS (Peter)
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/
---
Akash Nair (2):
net: pcs: Add PCS uclass and generic interface
net: pcs: Add Synopsys DesignWare XPCS driver
arch/sandbox/dts/test.dts | 8 + configs/sandbox_defconfig | 3 + doc/api/index.rst | 1 + doc/api/pcs.rst | 11 + doc/develop/driver-model/index.rst | 2 + doc/develop/driver-model/pcs-xpcs.rst | 193 ++++++++ doc/develop/driver-model/pcs.rst | 225 +++++++++ drivers/net/Kconfig | 1 + drivers/net/Makefile | 1 + drivers/net/pcs/Kconfig | 34 ++ drivers/net/pcs/Makefile | 8 + drivers/net/pcs/pcs-sandbox.c | 91 ++++ drivers/net/pcs/pcs-uclass.c | 53 ++ drivers/net/pcs/pcs-xpcs.c | 878 ++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/pcs.h | 137 ++++++ test/dm/Makefile | 1 + test/dm/pcs.c | 133 +++++ 18 files changed, 1781 insertions(+)
---
base-commit: 42680af8d15bb49201b298ab5f62058051c13083
change-id: 20261028-rfc-net-pcs-driver-bbdb1b58ddff
Best regards,
Signature · 1 line
Akash Nair <[email protected]>
RFC PATCH v2 1/2 net: pcs: Add PCS uclass and generic interface
Add UCLASS_PCS and include/pcs.h, a generic interface for Ethernet PCS (Physical Coding Sublayer) devices. A PCS driver provides a struct pcs_ops, and a MAC driver calls it through the pcs_set_config(), pcs_get_state() and pcs_disable() wrappers:
- set_config selects the interface mode and the negotiation mode (none, in-band or out-of-band)
- get_state reports link, auto-negotiation status and speed
- disable stops auto-negotiation and powers the PCS down
The MAC driver finds the PCS by phandle. The uclass is enabled with CONFIG_PCS.
Add a sandbox PCS driver and dm tests that exercise the uclass interface. The sandbox driver does not emulate any hardware.
--- arch/sandbox/dts/test.dts | 8 ++ configs/sandbox_defconfig | 2 + doc/api/index.rst | 1 + doc/api/pcs.rst | 11 ++ doc/develop/driver-model/index.rst | 1 + doc/develop/driver-model/pcs.rst | 225 +++++++++++++++++++++++++++++++++++++ drivers/net/Kconfig | 1 + drivers/net/Makefile | 1 + drivers/net/pcs/Kconfig | 21 ++++ drivers/net/pcs/Makefile | 7 ++ drivers/net/pcs/pcs-sandbox.c | 91 +++++++++++++++ drivers/net/pcs/pcs-uclass.c | 53 +++++++++ include/dm/uclass-id.h | 1 + include/pcs.h | 137 ++++++++++++++++++++++ test/dm/Makefile | 1 + test/dm/pcs.c | 133 ++++++++++++++++++++++ 16 files changed, 694 insertions(+)
arch/sandbox/dts/test.dts +8 -0
@@ -474,6 +474,14 @@ compatible = "sandbox,multimatch-test"; }; + pcs-ops { + compatible = "sandbox,pcs"; + }; + + pcs-noops { + compatible = "sandbox,pcs-noops"; + }; + phy_provider0: gen_phy@0 { compatible = "sandbox,phy"; #phy-cells = <1>;
configs/sandbox_defconfig +2 -0
@@ -291,6 +291,8 @@ CONFIG_UBI_BLOCK=y CONFIG_NVMXIP_QSPI=y CONFIG_MULTIPLEXER=y CONFIG_MUX_MMIO=y +CONFIG_PCS=y +CONFIG_PCS_SANDBOX=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y CONFIG_PCI_FTPCI100=y
doc/api/index.rst +1 -0
@@ -22,6 +22,7 @@ U-Boot API documentation logging nvmem part + pcs pinctrl rng sandbox
doc/api/pcs.rst new file +11 -0
@@ -0,0 +1,11 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2026 Marvell International Ltd. + +PCS +=== + +.. kernel-doc:: include/pcs.h + :doc: Overview + +.. kernel-doc:: include/pcs.h + :internal:
doc/develop/driver-model/index.rst +1 -0
@@ -23,6 +23,7 @@ subsystems nvmxip of-plat pci-info + pcs pmic-framework remoteproc-framework serial-howto
doc/develop/driver-model/pcs.rst new file +225 -0
225 lines not on this page · raw message
drivers/net/Kconfig +1 -0
@@ -1154,6 +1154,7 @@ config MDIO_MUX_MESON_GXL This driver is used for the MDIO mux found on the Amlogic GXL & compatible SoCs. +source "drivers/net/pcs/Kconfig" source "drivers/net/phy/Kconfig" source "drivers/net/pfe_eth/Kconfig" source "drivers/net/fsl-mc/Kconfig"
drivers/net/Makefile +1 -0
@@ -99,6 +99,7 @@ obj-$(CONFIG_OCTEONTX2_CGX_INTF) += octeontx2/cgx_intf.o obj-$(CONFIG_OCTEONTX_SMI) += octeontx/smi.o obj-$(CONFIG_PCH_GBE) += pch_gbe.o obj-$(CONFIG_PCNET) += pcnet.o +obj-$(CONFIG_PCS) += pcs/ obj-$(CONFIG_PIC32_ETH) += pic32_mdio.o pic32_eth.o obj-$(CONFIG_RENESAS_ETHER_SWITCH) += rswitch.o obj-$(CONFIG_RENESAS_RAVB) += ravb.o
drivers/net/pcs/Kconfig new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 Marvell International Ltd. +# + +config PCS + bool "Ethernet PCS support" + depends on DM + help + Enable the PCS uclass, a generic interface to configure an Ethernet + PCS and read back its link and auto-negotiation state. MAC drivers + use it through <pcs.h>. + + Enable this if a MAC driver on the board needs a PCS driver. + +config PCS_SANDBOX + bool "Sandbox PCS driver" + depends on SANDBOX && PCS + help + Enable a dummy PCS driver for sandbox. It is used only by the + unit tests of the PCS uclass.
drivers/net/pcs/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 Marvell International Ltd. +# + +obj-$(CONFIG_PCS) += pcs-uclass.o +obj-$(CONFIG_PCS_SANDBOX) += pcs-sandbox.o
drivers/net/pcs/pcs-sandbox.c new file +91 -0
91 lines not on this page · raw message
drivers/net/pcs/pcs-uclass.c new file +53 -0
53 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -114,6 +114,7 @@ enum uclass_id {UCLASS_PCI ,/* PCI bus */ UCLASS_PCI_EP ,/* PCI endpoint device */ UCLASS_PCI_GENERIC ,/* Generic PCI bus device */ +UCLASS_PCS ,/* Ethernet PCS */ UCLASS_PHY ,/* Physical Layer (PHY) device */ UCLASS_PINCONFIG ,/* Pin configuration node device */ UCLASS_PINCTRL, /* Pinctrl (pin muxing/configuration) device */
include/pcs.h new file +137 -0
137 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -119,6 +119,7 @@ obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o +obj-$(CONFIG_PCS) += pcs.o obj-$(CONFIG_PHY) += phy.o obj-$(CONFIG_PHY_COMMON_PROPS) += phy_common_props.o ifneq ($(CONFIG_PINMUX),)
test/dm/pcs.c new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH v2 2/2 net: pcs: Add Synopsys DesignWare XPCS driver
In reply to Akash NairAdd a driver for the Synopsys DesignWare Ethernet PCS (DW XPCS) that implements the PCS uclass interface in <pcs.h>. It matches the existing "snps,dw-xpcs" binding.
The Clause 45 registers are accessed through the memory mapped indirect window ("indirect" reg, reg-io-width = <4>). The driver selects the page of each register and caches it.
Supported modes:
- 1000BASE-KX with Clause 37 auto-negotiation
- 10GBASE-R at fixed speed, without auto-negotiation
- 10GBASE-KR with Clause 73 auto-negotiation
The register names and the Clause 73 and 10GBASE-R programming sequences follow the Linux drivers/net/pcs/pcs-xpcs.c driver.
The PCS is only probed. The MAC driver configures it with pcs_set_config(). The driver has no in-tree user yet, the MAC driver will follow.
The Clause 45 device ID of the PCS MMD holds the OUI set by the SoC integrator, so it differs between SoCs. The driver reads it and logs it at debug level instead of comparing it with a fixed value.
Clause 37 auto-negotiation is started with the restart bit set together with the enable bit, so that the PCS actually begins negotiating.
--- configs/sandbox_defconfig | 1 + doc/develop/driver-model/index.rst | 1 + doc/develop/driver-model/pcs-xpcs.rst | 193 ++++++++ doc/develop/driver-model/pcs.rst | 2 +- drivers/net/pcs/Kconfig | 13 + drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs-xpcs.c | 878 ++++++++++++++++++++++++++++++++++ 7 files changed, 1088 insertions(+), 1 deletion(-)
configs/sandbox_defconfig +1 -0
@@ -292,6 +292,7 @@ CONFIG_NVMXIP_QSPI=y CONFIG_MULTIPLEXER=y CONFIG_MUX_MMIO=y CONFIG_PCS=y +CONFIG_PCS_XPCS=y CONFIG_PCS_SANDBOX=y CONFIG_NVME_PCI=y CONFIG_PCI_REGION_MULTI_ENTRY=y
doc/develop/driver-model/index.rst +1 -0
@@ -24,6 +24,7 @@ subsystems of-plat pci-info pcs + pcs-xpcs pmic-framework remoteproc-framework serial-howto
doc/develop/driver-model/pcs-xpcs.rst new file +193 -0
193 lines not on this page · raw message
doc/develop/driver-model/pcs.rst +1 -1
@@ -7,7 +7,7 @@ Ethernet PCS Driver Guide This guide describes the PCS uclass (``UCLASS_PCS``). It explains how a MAC driver uses a PCS and how to write a PCS driver. The reference for every function and structure is in :doc:`/api/pcs`. The Synopsys DesignWare XPCS -driver is the first driver of the uclass. +driver, the first driver of the uclass, is described in :doc:`pcs-xpcs`. Overview --------
drivers/net/pcs/Kconfig +13 -0
@@ -13,6 +13,19 @@ config PCS Enable this if a MAC driver on the board needs a PCS driver. +config PCS_XPCS + bool "Synopsys DesignWare Ethernet PCS (XPCS)" + depends on PCS + help + Support the Synopsys DesignWare Ethernet PCS (DWC XPCS), accessed + through its memory-mapped indirect register window. + + Supported modes are 1000BASE-KX, 10GBASE-R and 10GBASE-KR. The PCS + is configured by the MAC driver through the generic interface in + <pcs.h>. + + Enable this if the board has a "snps,dw-xpcs" device. + config PCS_SANDBOX bool "Sandbox PCS driver" depends on SANDBOX && PCS
drivers/net/pcs/Makefile +1 -0
@@ -4,4 +4,5 @@ # obj-$(CONFIG_PCS) += pcs-uclass.o +obj-$(CONFIG_PCS_XPCS) += pcs-xpcs.o obj-$(CONFIG_PCS_SANDBOX) += pcs-sandbox.o
drivers/net/pcs/pcs-xpcs.c new file +878 -0
878 lines not on this page · raw message
Signature · 1 line
2.43.0