| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/21 06:09 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch series introduces device tree bindings, ARM64 DTS changes, and drivers for the SerDes PHY and Synopsys XPCS platform glue on NXP S32G automotive SoCs (ARM64). These platform drivers require physical NXP S32G SoC hardware that is not emulated in standard virtualized QEMU/GCE environments, and the code is structurally unreachable on the target architecture (amd64).",
"WorthFuzzing": false
} |
| 1/1 | 2026/09/21 06:09 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 3792723fde6cdccf2b1b8009e7fd2cefb45fcf9b\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Mon Sep 21 06:09:51 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml\nindex 753a04941659b..b168decb540c6 100644\n--- a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml\n+++ b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml\n@@ -15,7 +15,8 @@ description:\n The SoC series S32G2xx and S32G3xx feature one DWMAC instance,\n the SoC S32R45 has two instances. The devices can use RGMII/RMII/MII\n interface over Pinctrl device or the output can be routed\n- to the embedded SerDes for SGMII connectivity.\n+ to the embedded SerDes for SGMII connectivity, in which case the\n+ SerDes XPCS lane acting as the PCS is referenced via pcs-handle.\n The DWMAC instances have connected all RX/TX queues interrupts,\n enabling load balancing of data traffic across all CPU cores.\n \n@@ -81,6 +82,14 @@ properties:\n - const: rx\n - const: ptp_ref\n \n+ pcs-handle:\n+ $ref: /schemas/types.yaml#/definitions/phandle-array\n+ maxItems: 1\n+ description:\n+ phandle pointing to the SerDes XPCS lane child node that provides\n+ the SGMII PCS for this MAC. See\n+ Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml.\n+\n required:\n - clocks\n - clock-names\ndiff --git a/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml b/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml\nindex 66a050028278a..29323e50bd8bc 100644\n--- a/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml\n+++ b/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml\n@@ -82,7 +82,6 @@ unevaluatedProperties: false\n examples:\n - |\n #include \u003cdt-bindings/interrupt-controller/arm-gic.h\u003e\n- #include \u003cdt-bindings/phy/phy.h\u003e\n \n bus {\n #address-cells = \u003c2\u003e;\n@@ -124,7 +123,7 @@ examples:\n ranges;\n \n device_type = \"pci\";\n- phys = \u003c\u0026serdes0 PHY_TYPE_PCIE 0 0\u003e;\n+ phys = \u003c\u0026serdes0_pcie0\u003e;\n };\n };\n };\ndiff --git a/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml b/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml\nnew file mode 100644\nindex 0000000000000..6343d01bfde45\n--- /dev/null\n+++ b/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml\n@@ -0,0 +1,258 @@\n+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)\n+%YAML 1.2\n+---\n+$id: http://devicetree.org/schemas/phy/nxp,s32g-serdes.yaml#\n+$schema: http://devicetree.org/meta-schemas/core.yaml#\n+\n+title: NXP S32G2xxx/S32G3xxx SerDes PHY subsystem\n+\n+maintainers:\n+ - Ghennadi Procopciuc \u003cghennadi.procopciuc@nxp.com\u003e\n+ - Jan Petrous \u003cjan.petrous@oss.nxp.com\u003e\n+\n+description: |\n+ The SerDes subsystem multiplexes two SerDes lanes between one PCIe\n+ controller PHY and two Synopsys DesignWare XPCS (Ethernet PCS) instances,\n+ behind a shared 2-lane combo PHY. The active routing is selected by the\n+ SS_RW_REG_0[SUBSYS_MODE] field.\n+\n+ Reference-manual working modes described by this binding:\n+\n+ Mode Lane0 Lane1 PHY refclk (MHz) Description\n+ ------------------------------------------------------------\n+ 0 PCIe PCIe 100 PCIe x2\n+ 1 PCIe XPCS0 100 PCIe x1 + SGMII\n+ 2 PCIe XPCS1 100 PCIe x1 + SGMII\n+ 3 XPCS0 XPCS1 100 or 125 dual SGMII, 1.25 Gbit/s\n+\n+ Which Ethernet MAC an XPCS instance feeds is fixed by the SoC integration\n+ and differs per SoC and per SerDes instance - on S32G3 SerDes_0, XPCS0\n+ feeds GMAC0 and XPCS1 feeds PFE_MAC2, while on SerDes_1 the same two\n+ instances feed PFE_MAC0 and PFE_MAC1. That mapping is a property of the\n+ SoC, not of this binding, and is resolved by the driver.\n+\n+ The 3.125 Gbit/s working modes are not described here yet. Distinguishing\n+ them from mode 3 requires a per-lane 2500BASE-X capability, which this\n+ binding does not express; the reference clock does not distinguish them\n+ either, as both accept 100 or 125 MHz. They are added by a follow-up.\n+\n+ SUBSYS_MODE is not encoded in the devicetree. It is derived at probe from\n+ information already present in standard form:\n+ - the lane mux, from the per-lane child nodes below;\n+ - the XPCS instance a lane feeds, from nxp,xpcs-instance (this is what\n+ distinguishes modes 1 and 2).\n+ Each mode above has a unique lane mux, so the mode is a pure function of\n+ the child nodes. The reference-clock rate is validated against the\n+ derived mode; it is never used to select it.\n+\n+ Both lanes must always be described, even a lane the board does not wire\n+ out to a connector. The lane mux is a property of the hardware\n+ SUBSYS_MODE, not of the board routing: in mode 1, for example, the\n+ subsystem internally routes lane 1 to XPCS0 whether or not the board\n+ connects that lane to anything. The child nodes describe that fixed\n+ hardware mux, so both must be present; omitting a lane leaves the mode\n+ underivable and the probe fails with -EINVAL. Which of those lanes is\n+ actually used by a given board is expressed elsewhere (the consumer's\n+ phys / pcs-handle reference), not by leaving the lane out here.\n+\n+ The full reference-manual mode tables differ per SoC, which is why S32G2\n+ and S32G3 use distinct compatibles without a fallback between them.\n+\n+ They also differ between the two SerDes instances of one SoC, so each\n+ instance additionally carries a compatible naming it, with the per-SoC\n+ string as fallback:\n+\n+ serdes0: compatible = \"nxp,s32g3-serdes0\", \"nxp,s32g3-serdes\";\n+ serdes1: compatible = \"nxp,s32g3-serdes1\", \"nxp,s32g3-serdes\";\n+\n+ For the modes described here the two instances behave identically and a\n+ driver need only match the fallback. They diverge outside this scope:\n+ on S32G3 the 3.125 Gbit/s dual-XPCS mode 4 exists on SerDes_1 only, and\n+ on S32G2 only SerDes_1 reaches 3.125 Gbit/s at all. Recording the\n+ instance now means the follow-up that adds those modes is purely\n+ additive - it matches the specific strings and needs no devicetree\n+ change.\n+\n+ The same mechanism covers SoCs whose instances differ in kind rather\n+ than in degree: on S32R47 one SerDes has no PCIe controller at all, so\n+ its compatible must be distinguishable in order to reject a PCIe lane\n+ child in schema rather than at probe time.\n+\n+properties:\n+ compatible:\n+ oneOf:\n+ - items:\n+ - enum:\n+ - nxp,s32g2-serdes0\n+ - nxp,s32g2-serdes1\n+ - const: nxp,s32g2-serdes\n+ - items:\n+ - enum:\n+ - nxp,s32g3-serdes0\n+ - nxp,s32g3-serdes1\n+ - const: nxp,s32g3-serdes\n+\n+ reg:\n+ maxItems: 4\n+\n+ reg-names:\n+ items:\n+ - const: ss-pcie\n+ - const: pcie-phy\n+ - const: xpcs0\n+ - const: xpcs1\n+\n+ clocks:\n+ minItems: 4\n+ maxItems: 5\n+\n+ clock-names:\n+ minItems: 4\n+ items:\n+ - const: axi\n+ - const: aux\n+ - const: apb\n+ - const: ref\n+ - const: ext\n+ description:\n+ The combo PHY reference can be taken from the internal reference\n+ clock (\"ref\") or from the external reference pad (\"ext\"). A board\n+ that routes the external pad lists both; the external reference is\n+ then the one used.\n+\n+ resets:\n+ maxItems: 2\n+\n+ reset-names:\n+ items:\n+ - const: serdes\n+ - const: pcie\n+\n+ '#address-cells':\n+ const: 1\n+\n+ '#size-cells':\n+ const: 0\n+\n+patternProperties:\n+ '^phy@[01]$':\n+ description: One SerDes lane. The unit address is the physical lane index.\n+ type: object\n+ additionalProperties: false\n+\n+ properties:\n+ reg:\n+ description: Physical lane index.\n+ maximum: 1\n+\n+ compatible:\n+ enum:\n+ - nxp,s32g-serdes-pcie-phy\n+ - nxp,s32g-serdes-xpcs\n+\n+ '#phy-cells':\n+ const: 0\n+\n+ nxp,xpcs-instance:\n+ $ref: /schemas/types.yaml#/definitions/uint32\n+ enum: [0, 1]\n+ description:\n+ DesignWare XPCS instance this lane is routed to. Required for, and\n+ only valid on, XPCS lanes. Distinguishes modes 1 and 2; for the\n+ dual-XPCS mode the instance equals the lane index.\n+\n+ required:\n+ - reg\n+ - compatible\n+\n+ allOf:\n+ - if:\n+ properties:\n+ compatible:\n+ const: nxp,s32g-serdes-xpcs\n+ required:\n+ - compatible\n+ then:\n+ # An XPCS lane is not a generic PHY provider. It is referenced by\n+ # the Ethernet controller through pcs-handle, not through phys.\n+ required:\n+ - nxp,xpcs-instance\n+ properties:\n+ '#phy-cells': false\n+ else:\n+ required:\n+ - '#phy-cells'\n+ properties:\n+ nxp,xpcs-instance: false\n+\n+required:\n+ - compatible\n+ - reg\n+ - reg-names\n+ - clocks\n+ - clock-names\n+ - resets\n+ - reset-names\n+ - '#address-cells'\n+ - '#size-cells'\n+\n+additionalProperties: false\n+\n+examples:\n+ # PCIe x1 on lane 0 + 1G SGMII on lane 1 via XPCS0 (derived mode 1).\n+ - |\n+ serdes@40480000 {\n+ compatible = \"nxp,s32g3-serdes0\", \"nxp,s32g3-serdes\";\n+ reg = \u003c0x40480000 0x108\u003e,\n+ \u003c0x40483008 0x10\u003e,\n+ \u003c0x40482000 0x800\u003e,\n+ \u003c0x40482800 0x800\u003e;\n+ reg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+ clocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+ clock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+ resets = \u003c\u0026scmi_reset 1\u003e, \u003c\u0026scmi_reset 0\u003e;\n+ reset-names = \"serdes\", \"pcie\";\n+ #address-cells = \u003c1\u003e;\n+ #size-cells = \u003c0\u003e;\n+\n+ phy@0 {\n+ reg = \u003c0\u003e;\n+ compatible = \"nxp,s32g-serdes-pcie-phy\";\n+ #phy-cells = \u003c0\u003e;\n+ };\n+\n+ phy@1 {\n+ reg = \u003c1\u003e;\n+ compatible = \"nxp,s32g-serdes-xpcs\";\n+ nxp,xpcs-instance = \u003c0\u003e;\n+ };\n+ };\n+\n+ # Dual 1G SGMII (derived mode 3).\n+ - |\n+ serdes@44180000 {\n+ compatible = \"nxp,s32g3-serdes1\", \"nxp,s32g3-serdes\";\n+ reg = \u003c0x44180000 0x108\u003e,\n+ \u003c0x44183008 0x10\u003e,\n+ \u003c0x44182000 0x800\u003e,\n+ \u003c0x44182800 0x800\u003e;\n+ reg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+ clocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+ clock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+ resets = \u003c\u0026scmi_reset 11\u003e, \u003c\u0026scmi_reset 10\u003e;\n+ reset-names = \"serdes\", \"pcie\";\n+ #address-cells = \u003c1\u003e;\n+ #size-cells = \u003c0\u003e;\n+\n+ phy@0 {\n+ reg = \u003c0\u003e;\n+ compatible = \"nxp,s32g-serdes-xpcs\";\n+ nxp,xpcs-instance = \u003c0\u003e;\n+ };\n+\n+ phy@1 {\n+ reg = \u003c1\u003e;\n+ compatible = \"nxp,s32g-serdes-xpcs\";\n+ nxp,xpcs-instance = \u003c1\u003e;\n+ };\n+ };\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 3b2eb2a7a89a8..38c6b5e1af0d5 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -3371,6 +3371,20 @@ S:\tMaintained\n F:\tDocumentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml\n F:\tdrivers/pci/controller/dwc/pcie-nxp-s32g*\n \n+ARM/NXP S32G SERDES DRIVER\n+M:\tCiprian Marian Costea \u003cciprianmarian.costea@oss.nxp.com\u003e\n+M:\tJan Petrous \u003cjan.petrous@oss.nxp.com\u003e\n+R:\tNXP S32 Linux Team \u003cs32@nxp.com\u003e\n+L:\tlinux-arm-kernel@lists.infradead.org (moderated for non-subscribers)\n+L:\tlinux-phy@lists.infradead.org\n+L:\tnetdev@vger.kernel.org\n+S:\tMaintained\n+F:\tDocumentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml\n+F:\tdrivers/net/pcs/pcs-nxp-s32g-xpcs.c\n+F:\tdrivers/phy/freescale/phy-nxp-s32g-serdes.c\n+F:\tinclude/linux/pcs/pcs-nxp-s32g-xpcs.h\n+F:\tinclude/linux/phy/nxp-s32g-serdes.h\n+\n ARM/NXP S32G/S32R DWMAC ETHERNET DRIVER\n M:\tJan Petrous \u003cjan.petrous@oss.nxp.com\u003e\n R:\ts32@nxp.com\n@@ -19788,6 +19802,15 @@ S:\tMaintained\n F:\tDocumentation/devicetree/bindings/extcon/extcon-ptn5150.yaml\n F:\tdrivers/extcon/extcon-ptn5150.c\n \n+NXP SERDES XPCS SHARED CORE\n+M:\tJan Petrous \u003cjan.petrous@oss.nxp.com\u003e\n+M:\tClark Wang \u003cxiaoning.wang@nxp.com\u003e\n+R:\tNXP S32 Linux Team \u003cs32@nxp.com\u003e\n+L:\tnetdev@vger.kernel.org\n+S:\tMaintained\n+F:\tdrivers/net/pcs/pcs-nxp-serdes-xpcs.c\n+F:\tinclude/linux/pcs/pcs-nxp-serdes-xpcs.h\n+\n NXP SGTL5000 DRIVER\n M:\tFabio Estevam \u003cfestevam@gmail.com\u003e\n L:\tlinux-sound@vger.kernel.org\ndiff --git a/arch/arm64/boot/dts/freescale/Makefile b/arch/arm64/boot/dts/freescale/Makefile\nindex 95ae85ab4adf5..3f68f36ac2beb 100644\n--- a/arch/arm64/boot/dts/freescale/Makefile\n+++ b/arch/arm64/boot/dts/freescale/Makefile\n@@ -786,5 +786,11 @@ dtb-$(CONFIG_ARCH_MXC) += imx8mm-phygate-tauri-l-rs232-rs485.dtb\n dtb-$(CONFIG_ARCH_S32) += s32g274a-evb.dtb\n dtb-$(CONFIG_ARCH_S32) += s32g274a-rdb2.dtb\n dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3.dtb\n+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode1.dtb\n+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode3.dtb\n+s32g399a-rdb3-serdes-mode1-dtbs := s32g399a-rdb3.dtb s32g399a-rdb3-serdes-mode1.dtbo\n+s32g399a-rdb3-serdes-mode3-dtbs := s32g399a-rdb3.dtb s32g399a-rdb3-serdes-mode3.dtbo\n+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode1.dtbo\n+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode3.dtbo\n dtb-$(CONFIG_ARCH_S32) += s32n79-rdb.dtb\n dtb-$(CONFIG_ARCH_S32) += s32v234-evb.dtb\ndiff --git a/arch/arm64/boot/dts/freescale/s32g2.dtsi b/arch/arm64/boot/dts/freescale/s32g2.dtsi\nindex 996494e34593f..539840340318d 100644\n--- a/arch/arm64/boot/dts/freescale/s32g2.dtsi\n+++ b/arch/arm64/boot/dts/freescale/s32g2.dtsi\n@@ -100,6 +100,11 @@ clks: protocol@14 {\n \t\t\t\treg = \u003c0x14\u003e;\n \t\t\t\t#clock-cells = \u003c1\u003e;\n \t\t\t};\n+\n+\t\t\tscmi_reset: protocol@16 {\n+\t\t\t\treg = \u003c0x16\u003e;\n+\t\t\t\t#reset-cells = \u003c1\u003e;\n+\t\t\t};\n \t\t};\n \n \t\tpsci {\n@@ -872,6 +877,38 @@ gmac0mdio: mdio {\n \t\t\t};\n \t\t};\n \n+\t\tserdes0: serdes@40480000 {\n+\t\t\tcompatible = \"nxp,s32g2-serdes0\", \"nxp,s32g2-serdes\";\n+\t\t\treg = \u003c0x40480000 0x108\u003e,\n+\t\t\t \u003c0x40483008 0x10\u003e,\n+\t\t\t \u003c0x40482000 0x800\u003e,\n+\t\t\t \u003c0x40482800 0x800\u003e;\n+\t\t\treg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+\t\t\tclocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+\t\t\tclock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+\t\t\tresets = \u003c\u0026scmi_reset 9\u003e, \u003c\u0026scmi_reset 8\u003e;\n+\t\t\treset-names = \"serdes\", \"pcie\";\n+\t\t\t#address-cells = \u003c1\u003e;\n+\t\t\t#size-cells = \u003c0\u003e;\n+\t\t\tstatus = \"disabled\";\n+\t\t};\n+\n+\t\tserdes1: serdes@44180000 {\n+\t\t\tcompatible = \"nxp,s32g2-serdes1\", \"nxp,s32g2-serdes\";\n+\t\t\treg = \u003c0x44180000 0x108\u003e,\n+\t\t\t \u003c0x44183008 0x10\u003e,\n+\t\t\t \u003c0x44182000 0x800\u003e,\n+\t\t\t \u003c0x44182800 0x800\u003e;\n+\t\t\treg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+\t\t\tclocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+\t\t\tclock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+\t\t\tresets = \u003c\u0026scmi_reset 11\u003e, \u003c\u0026scmi_reset 10\u003e;\n+\t\t\treset-names = \"serdes\", \"pcie\";\n+\t\t\t#address-cells = \u003c1\u003e;\n+\t\t\t#size-cells = \u003c0\u003e;\n+\t\t\tstatus = \"disabled\";\n+\t\t};\n+\n \t\tgic: interrupt-controller@50800000 {\n \t\t\tcompatible = \"arm,gic-v3\";\n \t\t\treg = \u003c0x50800000 0x10000\u003e,\n@@ -881,7 +918,88 @@ gic: interrupt-controller@50800000 {\n \t\t\t \u003c0x50420000 0x2000\u003e;\n \t\t\tinterrupts = \u003cGIC_PPI 9 IRQ_TYPE_LEVEL_HIGH\u003e;\n \t\t\tinterrupt-controller;\n+\t\t\t#address-cells = \u003c0\u003e;\n \t\t\t#interrupt-cells = \u003c3\u003e;\n \t\t};\n \t};\n+\n+\t/*\n+\t * PCIe controllers. Their config space (0x5f_ffffe000 / 0x4f_ffffe000)\n+\t * lies above the 32-bit window mapped by soc@0, so the root complexes\n+\t * are described at the device tree root. Disabled here; a board file\n+\t * that wires a lane to PCIe enables the controller and adds the phys.\n+\t */\n+\tpcie0: pcie@40400000 {\n+\t\tcompatible = \"nxp,s32g2-pcie\";\n+\t\treg = \u003c0x00 0x40400000 0x0 0x00001000\u003e,\t/* dbi */\n+\t\t \u003c0x00 0x40420000 0x0 0x00001000\u003e,\t/* dbi2 */\n+\t\t \u003c0x00 0x40460000 0x0 0x00001000\u003e,\t/* atu */\n+\t\t \u003c0x00 0x40470000 0x0 0x00001000\u003e,\t/* dma */\n+\t\t \u003c0x00 0x40481000 0x0 0x000000f8\u003e,\t/* ctrl */\n+\t\t \u003c0x5f 0xffffe000 0x0 0x00002000\u003e;\t/* config */\n+\t\treg-names = \"dbi\", \"dbi2\", \"atu\", \"dma\", \"ctrl\", \"config\";\n+\t\tdma-coherent;\n+\t\t#address-cells = \u003c3\u003e;\n+\t\t#size-cells = \u003c2\u003e;\n+\t\tdevice_type = \"pci\";\n+\t\tranges = \u003c0x01000000 0x0 0x00000000 0x5f 0xfffe0000 0x0 0x00010000\u003e,\n+\t\t\t \u003c0x02000000 0x0 0x00000000 0x58 0x00000000 0x0 0x80000000\u003e,\n+\t\t\t \u003c0x02000000 0x1 0x00000000 0x59 0x00000000 0x6 0xfffe0000\u003e;\n+\t\tbus-range = \u003c0x0 0xff\u003e;\n+\t\tinterrupts = \u003cGIC_SPI 125 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t \u003cGIC_SPI 123 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tinterrupt-names = \"msi\", \"dma\";\n+\t\t#interrupt-cells = \u003c1\u003e;\n+\t\tinterrupt-map-mask = \u003c0 0 0 0x7\u003e;\n+\t\tinterrupt-map = \u003c0 0 0 1 \u0026gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 2 \u0026gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 3 \u0026gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 4 \u0026gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tstatus = \"disabled\";\n+\n+\t\tpcie0_rp: pcie@0 {\n+\t\t\treg = \u003c0x0 0x0 0x0 0x0 0x0\u003e;\n+\t\t\t#address-cells = \u003c3\u003e;\n+\t\t\t#size-cells = \u003c2\u003e;\n+\t\t\tranges;\n+\t\t\tdevice_type = \"pci\";\n+\t\t};\n+\t};\n+\n+\tpcie1: pcie@44100000 {\n+\t\tcompatible = \"nxp,s32g2-pcie\";\n+\t\treg = \u003c0x00 0x44100000 0x0 0x00001000\u003e,\t/* dbi */\n+\t\t \u003c0x00 0x44120000 0x0 0x00001000\u003e,\t/* dbi2 */\n+\t\t \u003c0x00 0x44160000 0x0 0x00001000\u003e,\t/* atu */\n+\t\t \u003c0x00 0x44170000 0x0 0x00001000\u003e,\t/* dma */\n+\t\t \u003c0x00 0x44181000 0x0 0x000000f8\u003e,\t/* ctrl */\n+\t\t \u003c0x4f 0xffffe000 0x0 0x00002000\u003e;\t/* config */\n+\t\treg-names = \"dbi\", \"dbi2\", \"atu\", \"dma\", \"ctrl\", \"config\";\n+\t\tdma-coherent;\n+\t\t#address-cells = \u003c3\u003e;\n+\t\t#size-cells = \u003c2\u003e;\n+\t\tdevice_type = \"pci\";\n+\t\tranges = \u003c0x01000000 0x0 0x00000000 0x4f 0xfffe0000 0x0 0x00010000\u003e,\n+\t\t\t \u003c0x02000000 0x0 0x00000000 0x48 0x00000000 0x0 0x80000000\u003e,\n+\t\t\t \u003c0x02000000 0x1 0x00000000 0x49 0x00000000 0x6 0xfffe0000\u003e;\n+\t\tbus-range = \u003c0x0 0xff\u003e;\n+\t\tinterrupts = \u003cGIC_SPI 216 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t \u003cGIC_SPI 214 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tinterrupt-names = \"msi\", \"dma\";\n+\t\t#interrupt-cells = \u003c1\u003e;\n+\t\tinterrupt-map-mask = \u003c0 0 0 0x7\u003e;\n+\t\tinterrupt-map = \u003c0 0 0 1 \u0026gic GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 2 \u0026gic GIC_SPI 220 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 3 \u0026gic GIC_SPI 221 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 4 \u0026gic GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tstatus = \"disabled\";\n+\n+\t\tpcie1_rp: pcie@0 {\n+\t\t\treg = \u003c0x0 0x0 0x0 0x0 0x0\u003e;\n+\t\t\t#address-cells = \u003c3\u003e;\n+\t\t\t#size-cells = \u003c2\u003e;\n+\t\t\tranges;\n+\t\t\tdevice_type = \"pci\";\n+\t\t};\n+\t};\n };\ndiff --git a/arch/arm64/boot/dts/freescale/s32g3.dtsi b/arch/arm64/boot/dts/freescale/s32g3.dtsi\nindex 31f7aad00b764..fdf086363c020 100644\n--- a/arch/arm64/boot/dts/freescale/s32g3.dtsi\n+++ b/arch/arm64/boot/dts/freescale/s32g3.dtsi\n@@ -139,6 +139,11 @@ clks: protocol@14 {\n \t\t\t\treg = \u003c0x14\u003e;\n \t\t\t\t#clock-cells = \u003c1\u003e;\n \t\t\t};\n+\n+\t\t\tscmi_reset: protocol@16 {\n+\t\t\t\treg = \u003c0x16\u003e;\n+\t\t\t\t#reset-cells = \u003c1\u003e;\n+\t\t\t};\n \t\t};\n \n \t\tpsci: psci {\n@@ -951,6 +956,38 @@ gmac0mdio: mdio {\n \t\t\t};\n \t\t};\n \n+\t\tserdes0: serdes@40480000 {\n+\t\t\tcompatible = \"nxp,s32g3-serdes0\", \"nxp,s32g3-serdes\";\n+\t\t\treg = \u003c0x40480000 0x108\u003e,\n+\t\t\t \u003c0x40483008 0x10\u003e,\n+\t\t\t \u003c0x40482000 0x800\u003e,\n+\t\t\t \u003c0x40482800 0x800\u003e;\n+\t\t\treg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+\t\t\tclocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+\t\t\tclock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+\t\t\tresets = \u003c\u0026scmi_reset 9\u003e, \u003c\u0026scmi_reset 8\u003e;\n+\t\t\treset-names = \"serdes\", \"pcie\";\n+\t\t\t#address-cells = \u003c1\u003e;\n+\t\t\t#size-cells = \u003c0\u003e;\n+\t\t\tstatus = \"disabled\";\n+\t\t};\n+\n+\t\tserdes1: serdes@44180000 {\n+\t\t\tcompatible = \"nxp,s32g3-serdes1\", \"nxp,s32g3-serdes\";\n+\t\t\treg = \u003c0x44180000 0x108\u003e,\n+\t\t\t \u003c0x44183008 0x10\u003e,\n+\t\t\t \u003c0x44182000 0x800\u003e,\n+\t\t\t \u003c0x44182800 0x800\u003e;\n+\t\t\treg-names = \"ss-pcie\", \"pcie-phy\", \"xpcs0\", \"xpcs1\";\n+\t\t\tclocks = \u003c\u0026clks 1\u003e, \u003c\u0026clks 2\u003e, \u003c\u0026clks 3\u003e, \u003c\u0026clks 4\u003e;\n+\t\t\tclock-names = \"axi\", \"aux\", \"apb\", \"ref\";\n+\t\t\tresets = \u003c\u0026scmi_reset 11\u003e, \u003c\u0026scmi_reset 10\u003e;\n+\t\t\treset-names = \"serdes\", \"pcie\";\n+\t\t\t#address-cells = \u003c1\u003e;\n+\t\t\t#size-cells = \u003c0\u003e;\n+\t\t\tstatus = \"disabled\";\n+\t\t};\n+\n \t\tswt8: watchdog@40500000 {\n \t\t\tcompatible = \"nxp,s32g3-swt\", \"nxp,s32g2-swt\";\n \t\t\treg = \u003c0x40500000 0x1000\u003e;\n@@ -1021,6 +1058,7 @@ stm11: timer@4052c000 {\n \n \t\tgic: interrupt-controller@50800000 {\n \t\t\tcompatible = \"arm,gic-v3\";\n+\t\t\t#address-cells = \u003c0\u003e;\n \t\t\t#interrupt-cells = \u003c3\u003e;\n \t\t\tinterrupt-controller;\n \t\t\treg = \u003c0x50800000 0x10000\u003e,\n@@ -1032,6 +1070,86 @@ gic: interrupt-controller@50800000 {\n \t\t};\n \t};\n \n+\t/*\n+\t * PCIe controllers. Their config space (0x5f_ffffe000 / 0x4f_ffffe000)\n+\t * lies above the 32-bit window mapped by soc@0, so the root complexes\n+\t * are described at the device tree root. Disabled here; a board file\n+\t * that wires a lane to PCIe enables the controller and adds the phys.\n+\t */\n+\tpcie0: pcie@40400000 {\n+\t\tcompatible = \"nxp,s32g3-pcie\", \"nxp,s32g2-pcie\";\n+\t\treg = \u003c0x00 0x40400000 0x0 0x00001000\u003e,\t/* dbi */\n+\t\t \u003c0x00 0x40420000 0x0 0x00001000\u003e,\t/* dbi2 */\n+\t\t \u003c0x00 0x40460000 0x0 0x00001000\u003e,\t/* atu */\n+\t\t \u003c0x00 0x40470000 0x0 0x00001000\u003e,\t/* dma */\n+\t\t \u003c0x00 0x40481000 0x0 0x000000f8\u003e,\t/* ctrl */\n+\t\t \u003c0x5f 0xffffe000 0x0 0x00002000\u003e;\t/* config */\n+\t\treg-names = \"dbi\", \"dbi2\", \"atu\", \"dma\", \"ctrl\", \"config\";\n+\t\tdma-coherent;\n+\t\t#address-cells = \u003c3\u003e;\n+\t\t#size-cells = \u003c2\u003e;\n+\t\tdevice_type = \"pci\";\n+\t\tranges = \u003c0x01000000 0x0 0x00000000 0x5f 0xfffe0000 0x0 0x00010000\u003e,\n+\t\t\t \u003c0x02000000 0x0 0x00000000 0x58 0x00000000 0x0 0x80000000\u003e,\n+\t\t\t \u003c0x02000000 0x1 0x00000000 0x59 0x00000000 0x6 0xfffe0000\u003e;\n+\t\tbus-range = \u003c0x0 0xff\u003e;\n+\t\tinterrupts = \u003cGIC_SPI 125 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t \u003cGIC_SPI 123 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tinterrupt-names = \"msi\", \"dma\";\n+\t\t#interrupt-cells = \u003c1\u003e;\n+\t\tinterrupt-map-mask = \u003c0 0 0 0x7\u003e;\n+\t\tinterrupt-map = \u003c0 0 0 1 \u0026gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 2 \u0026gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 3 \u0026gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 4 \u0026gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tstatus = \"disabled\";\n+\n+\t\tpcie0_rp: pcie@0 {\n+\t\t\treg = \u003c0x0 0x0 0x0 0x0 0x0\u003e;\n+\t\t\t#address-cells = \u003c3\u003e;\n+\t\t\t#size-cells = \u003c2\u003e;\n+\t\t\tranges;\n+\t\t\tdevice_type = \"pci\";\n+\t\t};\n+\t};\n+\n+\tpcie1: pcie@44100000 {\n+\t\tcompatible = \"nxp,s32g3-pcie\", \"nxp,s32g2-pcie\";\n+\t\treg = \u003c0x00 0x44100000 0x0 0x00001000\u003e,\t/* dbi */\n+\t\t \u003c0x00 0x44120000 0x0 0x00001000\u003e,\t/* dbi2 */\n+\t\t \u003c0x00 0x44160000 0x0 0x00001000\u003e,\t/* atu */\n+\t\t \u003c0x00 0x44170000 0x0 0x00001000\u003e,\t/* dma */\n+\t\t \u003c0x00 0x44181000 0x0 0x000000f8\u003e,\t/* ctrl */\n+\t\t \u003c0x4f 0xffffe000 0x0 0x00002000\u003e;\t/* config */\n+\t\treg-names = \"dbi\", \"dbi2\", \"atu\", \"dma\", \"ctrl\", \"config\";\n+\t\tdma-coherent;\n+\t\t#address-cells = \u003c3\u003e;\n+\t\t#size-cells = \u003c2\u003e;\n+\t\tdevice_type = \"pci\";\n+\t\tranges = \u003c0x01000000 0x0 0x00000000 0x4f 0xfffe0000 0x0 0x00010000\u003e,\n+\t\t\t \u003c0x02000000 0x0 0x00000000 0x48 0x00000000 0x0 0x80000000\u003e,\n+\t\t\t \u003c0x02000000 0x1 0x00000000 0x49 0x00000000 0x6 0xfffe0000\u003e;\n+\t\tbus-range = \u003c0x0 0xff\u003e;\n+\t\tinterrupts = \u003cGIC_SPI 216 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t \u003cGIC_SPI 214 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tinterrupt-names = \"msi\", \"dma\";\n+\t\t#interrupt-cells = \u003c1\u003e;\n+\t\tinterrupt-map-mask = \u003c0 0 0 0x7\u003e;\n+\t\tinterrupt-map = \u003c0 0 0 1 \u0026gic GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 2 \u0026gic GIC_SPI 220 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 3 \u0026gic GIC_SPI 221 IRQ_TYPE_LEVEL_HIGH\u003e,\n+\t\t\t\t\u003c0 0 0 4 \u0026gic GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH\u003e;\n+\t\tstatus = \"disabled\";\n+\n+\t\tpcie1_rp: pcie@0 {\n+\t\t\treg = \u003c0x0 0x0 0x0 0x0 0x0\u003e;\n+\t\t\t#address-cells = \u003c3\u003e;\n+\t\t\t#size-cells = \u003c2\u003e;\n+\t\t\tranges;\n+\t\t\tdevice_type = \"pci\";\n+\t\t};\n+\t};\n+\n \ttimer {\n \t\tcompatible = \"arm,armv8-timer\";\n \t\tinterrupt-parent = \u003c\u0026gic\u003e;\ndiff --git a/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso\nnew file mode 100644\nindex 0000000000000..43219d9bb6eb6\n--- /dev/null\n+++ b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso\n@@ -0,0 +1,111 @@\n+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)\n+/*\n+ * Copyright 2021-2026 NXP\n+ *\n+ * NXP S32G3 Reference Design Board 3 (S32G-VNP-RDB3),\n+ * SerDes_0 Mode 1: PCIe x1 (lane 0) + 1G SGMII via GMAC0 (XPCS0, lane 1).\n+ *\n+ * Overlay applied on top of s32g399a-rdb3.dtb. It reroutes GMAC0 from the\n+ * on-board RGMII PHY to the SerDes_0 XPCS0 lane and brings up the PCIe\n+ * controllers as root complexes. The lane layout present here selects\n+ * SerDes SUBSYS_MODE 1.\n+ */\n+\n+/dts-v1/;\n+/plugin/;\n+\n+\u0026serdes0 {\n+\t#address-cells = \u003c1\u003e;\n+\t#size-cells = \u003c0\u003e;\n+\tstatus = \"okay\";\n+\n+\t/* Mode 1 lane layout: PCIe on lane 0, GMAC SGMII (XPCS0) on lane 1. */\n+\tserdes0_pcie0: phy@0 {\n+\t\treg = \u003c0\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-pcie-phy\";\n+\t\t#phy-cells = \u003c0\u003e;\n+\t};\n+\n+\tserdes0_xpcs0: phy@1 {\n+\t\treg = \u003c1\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-xpcs\";\n+\t\tnxp,xpcs-instance = \u003c0\u003e;\n+\t};\n+};\n+\n+\u0026serdes1 {\n+\t#address-cells = \u003c1\u003e;\n+\t#size-cells = \u003c0\u003e;\n+\tstatus = \"okay\";\n+\n+\t/*\n+\t * SerDes_1 Mode 1 lane layout: PCIe on lane 0, SGMII (PFE_MAC0\n+\t * via XPCS0) on lane 1.\n+\t *\n+\t * Both lanes must be described: the SerDes driver derives the\n+\t * SUBSYS_MODE from the full lane mux, so lane 1 has to be present\n+\t * as XPCS instance 0 (PFE_MAC0) for the mode-1 match to succeed.\n+\t * PFE is not modeled as a MAC consumer in this upstreaming device\n+\t * tree, so the XPCS lane is only brought up by the SerDes driver\n+\t * and left without a pcs-handle user.\n+\t */\n+\tserdes1_pcie0: phy@0 {\n+\t\treg = \u003c0\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-pcie-phy\";\n+\t\t#phy-cells = \u003c0\u003e;\n+\t};\n+\n+\tserdes1_xpcs0: phy@1 {\n+\t\treg = \u003c1\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-xpcs\";\n+\t\tnxp,xpcs-instance = \u003c0\u003e;\n+\t};\n+};\n+\n+/*\n+ * Both PCIe root complexes are wired on the RDB3:\n+ * - PCIe_0 reaches the M.2 slots (M-key or E-key) when board switch\n+ * SW17-2 is set to ON. It consumes SerDes_0 lane-0 PCIe phy.\n+ * - PCIe_1 reaches the PCIe card slot. It consumes SerDes_1 lane-0 PCIe phy.\n+ */\n+\u0026pcie0 {\n+\tstatus = \"okay\";\n+};\n+\n+\u0026pcie0_rp {\n+\tnum-lanes = \u003c1\u003e;\n+\tphys = \u003c\u0026serdes0_pcie0\u003e;\n+};\n+\n+\u0026pcie1 {\n+\tstatus = \"okay\";\n+};\n+\n+\u0026pcie1_rp {\n+\tnum-lanes = \u003c1\u003e;\n+\tphys = \u003c\u0026serdes1_pcie0\u003e;\n+};\n+\n+\u0026gmac0 {\n+\t/delete-property/ phy-handle;\n+\tclocks = \u003c\u0026clks 24\u003e, \u003c\u0026clks 17\u003e, \u003c\u0026clks 16\u003e, \u003c\u0026clks 15\u003e;\n+\tclock-names = \"stmmaceth\", \"tx\", \"rx\", \"ptp_ref\";\n+\tphy-mode = \"sgmii\";\n+\tpcs-handle = \u003c\u0026serdes0_xpcs0\u003e;\n+\tstatus = \"okay\";\n+\n+\t/*\n+\t * GMAC0 is wired back-to-back to the on-board SJA1110 switch over\n+\t * this SGMII lane. There is no PHY on the segment, so there is\n+\t * nothing to reference with phy-handle: the link partner is a\n+\t * switch port. Describe it as a fixed 1G link; phylink then uses\n+\t * out-of-band negotiation. The switch itself is not described by\n+\t * this overlay. The PCS also supports in-band negotiation, for\n+\t * boards whose link partner is described.\n+\t */\n+\tfixed-link {\n+\t\tspeed = \u003c1000\u003e;\n+\t\tfull-duplex;\n+\t\tpause;\n+\t};\n+};\ndiff --git a/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso\nnew file mode 100644\nindex 0000000000000..195c8043c18ac\n--- /dev/null\n+++ b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso\n@@ -0,0 +1,60 @@\n+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)\n+/*\n+ * Copyright 2021-2026 NXP\n+ *\n+ * NXP S32G3 Reference Design Board 3 (S32G-VNP-RDB3),\n+ * SerDes_0 Mode 3: dual SGMII, GMAC0 (XPCS0, lane 0) + PFE_EMAC_2\n+ * (XPCS1, lane 1), both 1G.\n+ *\n+ * Overlay applied on top of s32g399a-rdb3.dtb. It reroutes GMAC0 from the\n+ * on-board RGMII PHY to the SerDes_0 XPCS0 lane. The lane-1 XPCS1\n+ * (PFE_EMAC_2) is described so the mode is derivable and both XPCS\n+ * instances are initialised; it has no upstream MAC consumer in this\n+ * device tree. The lane layout present here selects SerDes SUBSYS_MODE 3.\n+ */\n+\n+/dts-v1/;\n+/plugin/;\n+\n+\u0026serdes0 {\n+\t#address-cells = \u003c1\u003e;\n+\t#size-cells = \u003c0\u003e;\n+\tstatus = \"okay\";\n+\n+\t/* Mode 3 lane layout: GMAC SGMII (XPCS0) on lane 0, PFE2 (XPCS1) on lane 1. */\n+\tserdes0_xpcs0: phy@0 {\n+\t\treg = \u003c0\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-xpcs\";\n+\t\tnxp,xpcs-instance = \u003c0\u003e;\n+\t};\n+\n+\tserdes0_xpcs1: phy@1 {\n+\t\treg = \u003c1\u003e;\n+\t\tcompatible = \"nxp,s32g-serdes-xpcs\";\n+\t\tnxp,xpcs-instance = \u003c1\u003e;\n+\t};\n+};\n+\n+\u0026gmac0 {\n+\t/delete-property/ phy-handle;\n+\tclocks = \u003c\u0026clks 24\u003e, \u003c\u0026clks 17\u003e, \u003c\u0026clks 16\u003e, \u003c\u0026clks 15\u003e;\n+\tclock-names = \"stmmaceth\", \"tx\", \"rx\", \"ptp_ref\";\n+\tphy-mode = \"sgmii\";\n+\tpcs-handle = \u003c\u0026serdes0_xpcs0\u003e;\n+\tstatus = \"okay\";\n+\n+\t/*\n+\t * GMAC0 is wired back-to-back to the on-board SJA1110 switch over\n+\t * this SGMII lane. There is no PHY on the segment, so there is\n+\t * nothing to reference with phy-handle: the link partner is a\n+\t * switch port. Describe it as a fixed 1G link; phylink then uses\n+\t * out-of-band negotiation. The switch itself is not described by\n+\t * this overlay. The PCS also supports in-band negotiation, for\n+\t * boards whose link partner is described.\n+\t */\n+\tfixed-link {\n+\t\tspeed = \u003c1000\u003e;\n+\t\tfull-duplex;\n+\t\tpause;\n+\t};\n+};\ndiff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig\nindex e3dd5adda5aca..1443ff4149b42 100644\n--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig\n+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig\n@@ -192,6 +192,12 @@ config DWMAC_S32\n \ttristate \"NXP S32G/S32R GMAC support\"\n \tdefault ARCH_S32\n \tdepends on OF \u0026\u0026 (ARCH_S32 || COMPILE_TEST)\n+\t# SGMII needs the PCS from the SerDes driver. The header falls back\n+\t# to a stub returning -ENODEV when that driver is not reachable, and\n+\t# stmmac makes a failing plat-\u003epcs_init() fatal, so a built-in MAC\n+\t# with a modular SerDes would refuse to probe on any DT describing\n+\t# pcs-handle. Forbid that combination instead.\n+\tdepends on PHY_S32G_SERDES || PHY_S32G_SERDES=n\n \thelp\n \t Support for ethernet controller on NXP S32CC SOCs.\n \ndiff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c\nindex 024d8e10e9188..a3a56b21181a0 100644\n--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c\n+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c\n@@ -16,12 +16,14 @@\n #include \u003clinux/of_mdio.h\u003e\n #include \u003clinux/of_address.h\u003e\n #include \u003clinux/phy.h\u003e\n+#include \u003clinux/phy/nxp-s32g-serdes.h\u003e\n #include \u003clinux/phylink.h\u003e\n #include \u003clinux/platform_device.h\u003e\n #include \u003clinux/regmap.h\u003e\n #include \u003clinux/stmmac.h\u003e\n \n #include \"stmmac_platform.h\"\n+#include \"stmmac.h\"\n \n #define GMAC_INTF_RATE_125M\t125000000\t/* 125MHz */\n \n@@ -40,23 +42,89 @@ struct s32_priv_data {\n \tphy_interface_t *intf_mode;\n \tstruct clk *tx_clk;\n \tstruct clk *rx_clk;\n+\t/* SGMII PCS provided by the SerDes subsystem (NULL if not SGMII) */\n+\tstruct phylink_pcs *pcs;\n };\n \n static int s32_gmac_write_phy_intf_select(struct s32_priv_data *gmac)\n {\n+\tu32 intf_sel;\n \tint ret = 0;\n \n+\tswitch (*gmac-\u003eintf_mode) {\n+\tcase PHY_INTERFACE_MODE_SGMII:\n+\t\tintf_sel = S32_PHY_INTF_SEL_SGMII;\n+\t\tbreak;\n+\tcase PHY_INTERFACE_MODE_RGMII:\n+\tcase PHY_INTERFACE_MODE_RGMII_ID:\n+\tcase PHY_INTERFACE_MODE_RGMII_RXID:\n+\tcase PHY_INTERFACE_MODE_RGMII_TXID:\n+\t\tintf_sel = S32_PHY_INTF_SEL_RGMII;\n+\t\tbreak;\n+\tcase PHY_INTERFACE_MODE_RMII:\n+\t\tintf_sel = S32_PHY_INTF_SEL_RMII;\n+\t\tbreak;\n+\tcase PHY_INTERFACE_MODE_MII:\n+\t\tintf_sel = S32_PHY_INTF_SEL_MII;\n+\t\tbreak;\n+\tdefault:\n+\t\tdev_err(gmac-\u003edev, \"Unsupported phy interface mode: %s\\n\",\n+\t\t\tphy_modes(*gmac-\u003eintf_mode));\n+\t\treturn -EINVAL;\n+\t}\n+\n \tif (gmac-\u003ectrl_sts)\n-\t\twritel(S32_PHY_INTF_SEL_RGMII, gmac-\u003ectrl_sts);\n+\t\twritel(intf_sel, gmac-\u003ectrl_sts);\n \telse\n \t\tret = regmap_write(gmac-\u003ests_regmap, gmac-\u003ests_offset,\n-\t\t\t\t S32_PHY_INTF_SEL_RGMII);\n+\t\t\t\t intf_sel);\n \n \tdev_dbg(gmac-\u003edev, \"PHY mode set to %s\\n\", phy_modes(*gmac-\u003eintf_mode));\n \n \treturn ret;\n }\n \n+static int s32_gmac_pcs_init(struct stmmac_priv *priv)\n+{\n+\tstruct s32_priv_data *gmac = priv-\u003eplat-\u003ebsp_priv;\n+\tstruct device_node *pcs_node;\n+\n+\t/*\n+\t * pcs-handle points at the SerDes XPCS lane child node; its\n+\t * nxp,xpcs-instance property is what identifies the XPCS instance.\n+\t */\n+\tpcs_node = of_parse_phandle(gmac-\u003edev-\u003eof_node, \"pcs-handle\", 0);\n+\tif (!pcs_node) {\n+\t\tdev_dbg(gmac-\u003edev, \"no 'pcs-handle' property, SGMII PCS unavailable\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tgmac-\u003epcs = s32g_serdes_pcs_create(gmac-\u003edev, pcs_node);\n+\tof_node_put(pcs_node);\n+\n+\tif (IS_ERR(gmac-\u003epcs)) {\n+\t\tint err = PTR_ERR(gmac-\u003epcs);\n+\n+\t\tgmac-\u003epcs = NULL;\n+\t\t/* SerDes may not be probed yet - defer probe. */\n+\t\treturn err;\n+\t}\n+\n+\tdev_dbg(gmac-\u003edev, \"SGMII PCS created via SerDes XPCS\\n\");\n+\treturn 0;\n+}\n+\n+static struct phylink_pcs *s32_gmac_select_pcs(struct stmmac_priv *priv,\n+\t\t\t\t\t phy_interface_t interface)\n+{\n+\tstruct s32_priv_data *gmac = priv-\u003eplat-\u003ebsp_priv;\n+\n+\tif (interface == PHY_INTERFACE_MODE_SGMII \u0026\u0026 gmac-\u003epcs)\n+\t\treturn gmac-\u003epcs;\n+\n+\treturn NULL;\n+}\n+\n static int s32_gmac_init(struct device *dev, void *priv)\n {\n \tstruct s32_priv_data *gmac = priv;\n@@ -204,6 +272,8 @@ static int s32_dwmac_probe(struct platform_device *pdev)\n \n \tplat-\u003einit = s32_gmac_init;\n \tplat-\u003eexit = s32_gmac_exit;\n+\tplat-\u003epcs_init = s32_gmac_pcs_init;\n+\tplat-\u003eselect_pcs = s32_gmac_select_pcs;\n \n \tplat-\u003eclk_tx_i = gmac-\u003etx_clk;\n \tplat-\u003eset_clk_tx_rate = stmmac_set_clk_tx_rate;\ndiff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig\nindex e417fd66f660a..7a4c0da406c96 100644\n--- a/drivers/net/pcs/Kconfig\n+++ b/drivers/net/pcs/Kconfig\n@@ -12,6 +12,17 @@ config PCS_XPCS\n \t This module provides a driver and helper functions for Synopsys\n \t DesignWare XPCS controllers.\n \n+config PCS_NXP_SERDES_XPCS\n+\ttristate \"NXP SerDes XPCS shared core\"\n+\tselect PHYLINK\n+\tselect REGMAP\n+\thelp\n+\t Transport agnostic phylink PCS core for the Synopsys DesignWare\n+\t Ethernet XPCS and Ethernet PHY of the SerDes subsystems found on\n+\t NXP S32G and i.MX SoCs. The platform specific register transport\n+\t (indirect MMIO on S32G, Clause 45 MDIO on i.MX) is implemented as\n+\t regmap callbacks by the platform drivers selecting this core.\n+\n config PCS_LYNX\n \ttristate\n \thelp\n@@ -35,4 +46,18 @@ config PCS_RZN1_MIIC\n \t Renesas RZ/N1, RZ/N2H, and RZ/T2H SoCs. This PCS converts MII to\n \t RMII/RGMII, or can be set in pass-through mode for MII.\n \n+config PCS_NXP_S32G_XPCS\n+\ttristate \"NXP S32G XPCS support\"\n+\tselect PHYLINK\n+\tselect REGMAP\n+\tselect PCS_NXP_SERDES_XPCS\n+\thelp\n+\t This option enables the NXP S32G SerDes XPCS platform glue. It\n+\t provides the indirect-MMIO register transport and the S32G PMA/PLL\n+\t bring-up sequences on top of the shared NXP SerDes xPCS core\n+\t (PCS_NXP_SERDES_XPCS), which supplies the phylink PCS layer for the\n+\t SGMII / 2500BASE-X lanes of the shared SerDes combo PHY. It is\n+\t driven by the S32G SerDes PHY driver. Say Y or M here if you need\n+\t SGMII Ethernet on an NXP S32G2 or S32G3 SoC.\n+\n endmenu\ndiff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile\nindex 4f7920618b900..337e9b503553f 100644\n--- a/drivers/net/pcs/Makefile\n+++ b/drivers/net/pcs/Makefile\n@@ -5,6 +5,8 @@ pcs_xpcs-$(CONFIG_PCS_XPCS)\t:= pcs-xpcs.o pcs-xpcs-plat.o \\\n \t\t\t\t pcs-xpcs-nxp.o pcs-xpcs-wx.o\n \n obj-$(CONFIG_PCS_XPCS)\t\t+= pcs_xpcs.o\n+obj-$(CONFIG_PCS_NXP_SERDES_XPCS) += pcs-nxp-serdes-xpcs.o\n obj-$(CONFIG_PCS_LYNX)\t\t+= pcs-lynx.o\n obj-$(CONFIG_PCS_MTK_LYNXI)\t+= pcs-mtk-lynxi.o\n obj-$(CONFIG_PCS_RZN1_MIIC)\t+= pcs-rzn1-miic.o\n+obj-$(CONFIG_PCS_NXP_S32G_XPCS)\t+= pcs-nxp-s32g-xpcs.o\ndiff --git a/drivers/net/pcs/pcs-nxp-s32g-xpcs.c b/drivers/net/pcs/pcs-nxp-s32g-xpcs.c\nnew file mode 100644\nindex 0000000000000..a44f1da54429f\n--- /dev/null\n+++ b/drivers/net/pcs/pcs-nxp-s32g-xpcs.c\n@@ -0,0 +1,947 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright 2021-2026 NXP\n+ *\n+ * S32G SerDes XPCS platform glue for the NXP SerDes xPCS shared core.\n+ *\n+ * This module no longer implements its own phylink PCS. It provides the\n+ * S32G specific parts the shared core (pcs-nxp-serdes-xpcs.c) consumes:\n+ * - the indirect-MMIO regmap transport. The S32G flat register address\n+ * 0x1fXXXX is already identical to the shared core's regmap key\n+ * \"(devad \u003c\u003c 16) | reg\" (devad 0x1f == MDIO_MMD_VEND2 for the VR_MII\n+ * page, devad 0x1f reg 0x0000 == SR_MII_CTRL/MII_BMCR), so the same\n+ * regmap serves both the S32G PMA sequences below and the shared core.\n+ * - the S32G PMA/PLL bring-up sequences, exported to the SerDes PHY\n+ * driver which drives the ordered dual-XPCS bring-up barrier.\n+ * - a struct nxp_serdes_xpcs_desc describing the S32G revision, with a\n+ * compat[] table (C37 SGMII + 2500BASE-X) and two pma_config() hooks\n+ * (SGMII link-timer / CL37 override, and the 1G\u003c-\u003e2.5G PLL switch).\n+ */\n+\n+#include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/err.h\u003e\n+#include \u003clinux/errno.h\u003e\n+#include \u003clinux/io.h\u003e\n+#include \u003clinux/iopoll.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/pcs/pcs-nxp-s32g-xpcs.h\u003e\n+#include \u003clinux/pcs/pcs-nxp-serdes-xpcs.h\u003e\n+#include \u003clinux/phy.h\u003e\n+#include \u003clinux/phylink.h\u003e\n+#include \u003clinux/regmap.h\u003e\n+#include \u003clinux/units.h\u003e\n+\n+enum s32g_xpcs_pll {\n+\tS32G_XPCS_PLLA,\t/* Slow PLL */\n+\tS32G_XPCS_PLLB,\t/* Fast PLL */\n+};\n+\n+struct s32g_xpcs {\n+\tvoid __iomem *base;\n+\tstruct device *dev;\n+\tunsigned char id;\n+\tstruct regmap *regmap;\n+\tenum s32g_xpcs_pll ref;\n+\tbool ext_clk;\n+\tbool mhz125;\n+\tenum s32g_xpcs_shared pcie_shared;\n+\t/* phylink PCS owned by the shared core, created in s32g_xpcs_create() */\n+\tstruct phylink_pcs *pcs;\n+};\n+\n+#define XPCS_TIMEOUT_US\t\t\t\t(300 * USEC_PER_MSEC)\n+#define XPCS_POLL_SLEEP_US\t\t\t100\n+\n+#define ADDR1_OFS\t\t\t\t0x3fc\n+\n+#define SR_MII_CTRL\t\t\t\t0x1f0000\n+#define SS13\t\t\t\t\tBIT(13)\n+#define AN_ENABLE\t\t\t\tBIT(12)\n+#define RESTART_AN\t\t\t\tBIT(9)\n+#define DUPLEX_MODE\t\t\t\tBIT(8)\n+#define SS6\t\t\t\t\tBIT(6)\n+#define SR_MII_STS\t\t\t\t0x1f0001\n+#define LINK_STS\t\t\t\tBIT(2)\n+#define VR_MII_DIG_CTRL1\t\t\t0x1f8000\n+#define BYP_PWRUP\t\t\t\tBIT(1)\n+#define EN_2_5G_MODE\t\t\t\tBIT(2)\n+#define CL37_TMR_OVRRIDE\t\t\tBIT(3)\n+#define INIT\t\t\t\t\tBIT(8)\n+#define MAC_AUTO_SW\t\t\t\tBIT(9)\n+#define VR_RST\t\t\t\tBIT(15)\n+#define VR_MII_AN_CTRL\t\t\t\t0x1f8001\n+#define MII_AN_INTR_EN\t\t\tBIT(0)\n+#define PCS_MODE_MASK\t\t\t\tGENMASK(2, 1)\n+#define PCS_MODE_SGMII\t\t\t2\n+#define MII_CTRL\t\t\t\tBIT(8)\n+#define VR_MII_AN_INTR_STS\t\t\t0x1f8002\n+#define CL37_ANCMPLT_INTR\t\t\tBIT(0)\n+#define CL37_ANSGM_STS_DUPLEX\t\t\tBIT(1)\n+#define CL37_ANSGM_STS_SPEED_MASK\t\tGENMASK(3, 2)\n+#define CL37_ANSGM_10MBPS\t\t\t0\n+#define CL37_ANSGM_100MBPS\t\t\t1\n+#define CL37_ANSGM_1000MBPS\t\t\t2\n+#define CL37_ANSGM_STS_LINK\t\t\tBIT(4)\n+#define VR_MII_DBG_CTRL\t\t\t\t0x1f8005\n+#define SUPPRESS_LOS_DET\t\t\tBIT(4)\n+#define RX_DT_EN_CTL\t\t\t\tBIT(6)\n+#define VR_MII_LINK_TIMER_CTRL\t\t\t0x1f800a\n+#define VR_MII_DIG_STS\t\t\t\t0x1f8010\n+#define PSEQ_STATE_MASK\t\t\tGENMASK(4, 2)\n+#define POWER_GOOD_STATE\t\t\t0x4\n+#define VR_MII_GEN5_12G_16G_TX_GENCTRL1\t\t0x1f8031\n+#define TX_CLK_RDY_0\t\t\t\tBIT(12)\n+#define\tVR_MII_GEN5_12G_16G_TX_GENCTRL2\t\t0x1f8032\n+#define\t TX_REQ_0\t\t\t\tBIT(0)\n+#define VR_MII_GEN5_12G_16G_TX_RATE_CTRL\t0x1f8034\n+#define TX0_RATE_MASK\t\t\t\tGENMASK(2, 0)\n+#define TX0_BAUD_DIV_1\t\t\t0\n+#define TX0_BAUD_DIV_4\t\t\t2\n+#define VR_MII_GEN5_12G_16G_TX_EQ_CTRL0\t\t0x1f8036\n+#define TX_EQ_MAIN_MASK\t\t\tGENMASK(13, 8)\n+#define VR_MII_GEN5_12G_16G_TX_EQ_CTRL1\t\t0x1f8037\n+#define TX_EQ_OVR_RIDE\t\t\tBIT(6)\n+#define VR_MII_CONSUMER_10G_TX_TERM_CTRL\t0x1f803c\n+#define TX0_TERM_MASK\t\t\t\tGENMASK(2, 0)\n+#define VR_MII_GEN5_12G_16G_RX_GENCTRL1\t\t0x1f8051\n+#define RX_RST_0\t\t\t\tBIT(4)\n+#define VR_MII_GEN5_12G_16G_RX_GENCTRL2\t\t0x1f8052\n+#define RX_REQ_0\t\t\t\tBIT(0)\n+#define VR_MII_GEN5_12G_16G_RX_RATE_CTRL\t0x1f8054\n+#define RX0_RATE_MASK\t\t\t\tGENMASK(1, 0)\n+#define RX0_BAUD_DIV_2\t\t\t0x1\n+#define RX0_BAUD_DIV_8\t\t\t0x3\n+#define VR_MII_GEN5_12G_16G_CDR_CTRL\t\t0x1f8056\n+#define VCO_LOW_FREQ_0\t\t\tBIT(8)\n+#define VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL\t0x1f8070\n+#define MPLLB_SEL_0\t\t\t\tBIT(4)\n+#define VR_MII_GEN5_12G_16G_MPLLA_CTRL0\t\t0x1f8071\n+#define MPLLA_CAL_DISABLE\t\t\tBIT(15)\n+#define MLLA_MULTIPLIER_MASK\t\t\tGENMASK(7, 0)\n+#define VR_MII_GEN5_12G_MPLLA_CTRL1\t\t0x1f8072\n+#define MPLLA_FRACN_CTRL_MASK\t\t\tGENMASK(15, 5)\n+#define VR_MII_GEN5_12G_16G_MPLLA_CTRL2\t\t0x1f8073\n+#define MPLLA_TX_CLK_DIV_MASK\t\t\tGENMASK(13, 11)\n+#define MPLLA_DIV10_CLK_EN\t\t\tBIT(9)\n+#define VR_MII_GEN5_12G_16G_MPLLB_CTRL0\t\t0x1f8074\n+#define MPLLB_CAL_DISABLE\t\t\tBIT(15)\n+#define MLLB_MULTIPLIER_MASK\t\t\tGENMASK(7, 0)\n+#define VR_MII_GEN5_12G_MPLLB_CTRL1\t\t0x1f8075\n+#define MPLLB_FRACN_CTRL_MASK\t\t\tGENMASK(15, 5)\n+#define VR_MII_GEN5_12G_16G_MPLLB_CTRL2\t\t0x1f8076\n+#define MPLLB_TX_CLK_DIV_MASK\t\t\tGENMASK(13, 11)\n+#define MPLLB_DIV10_CLK_EN\t\t\tBIT(9)\n+#define VR_MII_GEN5_12G_MPLLA_CTRL3\t\t0x1f8077\n+#define MPLLA_BANDWIDTH_MASK\t\t\tGENMASK(15, 0)\n+#define VR_MII_GEN5_12G_MPLLB_CTRL3\t\t0x1f8078\n+#define MPLLB_BANDWIDTH_MASK\t\t\tGENMASK(15, 0)\n+#define VR_MII_GEN5_12G_16G_MISC_CTRL0\t\t0x1f8090\n+#define PLL_CTRL\t\t\t\tBIT(15)\n+#define VR_MII_GEN5_12G_16G_REF_CLK_CTRL\t0x1f8091\n+#define REF_USE_PAD\t\t\t\tBIT(1)\n+#define REF_CLK_DIV2\t\t\t\tBIT(2)\n+#define REF_RANGE_MASK\t\t\tGENMASK(5, 3)\n+#define RANGE_26_53_MHZ\t\t\t0x1\n+#define RANGE_52_78_MHZ\t\t\t0x2\n+#define REF_MPLLA_DIV2\t\t\tBIT(6)\n+#define REF_MPLLB_DIV2\t\t\tBIT(7)\n+#define VR_MII_GEN5_12G_16G_VCO_CAL_LD0\t\t0x1f8092\n+#define VCO_LD_VAL_0_MASK\t\t\tGENMASK(12, 0)\n+#define VR_MII_GEN5_12G_VCO_CAL_REF0\t\t0x1f8096\n+#define VCO_REF_LD_0_MASK\t\t\tGENMASK(5, 0)\n+\n+typedef bool (*xpcs_poll_func_t)(struct s32g_xpcs *);\n+\n+/*\n+ * XPCS registers can't be accessed directly and an indirect address method\n+ * must be used instead. The 32-bit \"reg\" is the flat XPCS address and is\n+ * identical to the shared core's \"(devad \u003c\u003c 16) | reg\" key.\n+ */\n+\n+static const struct regmap_range s32g_xpcs_wr_ranges[] = {\n+\tregmap_reg_range(0x1f0000, 0x1f0000),\n+\tregmap_reg_range(0x1f0004, 0x1f0004),\n+\tregmap_reg_range(0x1f8000, 0x1f8003),\n+\tregmap_reg_range(0x1f8005, 0x1f8005),\n+\tregmap_reg_range(0x1f800a, 0x1f800a),\n+\tregmap_reg_range(0x1f8012, 0x1f8012),\n+\tregmap_reg_range(0x1f8015, 0x1f8015),\n+\tregmap_reg_range(0x1f8030, 0x1f8037),\n+\tregmap_reg_range(0x1f803c, 0x1f803e),\n+\tregmap_reg_range(0x1f8050, 0x1f8058),\n+\tregmap_reg_range(0x1f805c, 0x1f805e),\n+\tregmap_reg_range(0x1f8064, 0x1f8064),\n+\tregmap_reg_range(0x1f806b, 0x1f806b),\n+\tregmap_reg_range(0x1f8070, 0x1f8078),\n+\tregmap_reg_range(0x1f8090, 0x1f8092),\n+\tregmap_reg_range(0x1f8096, 0x1f8096),\n+\tregmap_reg_range(0x1f8099, 0x1f8099),\n+\tregmap_reg_range(0x1f80a0, 0x1f80a2),\n+\tregmap_reg_range(0x1f80e1, 0x1f80e1),\n+};\n+\n+static const struct regmap_access_table s32g_xpcs_wr_table = {\n+\t.yes_ranges = s32g_xpcs_wr_ranges,\n+\t.n_yes_ranges = ARRAY_SIZE(s32g_xpcs_wr_ranges),\n+};\n+\n+static const struct regmap_range s32g_xpcs_rd_ranges[] = {\n+\tregmap_reg_range(0x1f0000, 0x1f0006),\n+\tregmap_reg_range(0x1f000f, 0x1f000f),\n+\tregmap_reg_range(0x1f0708, 0x1f0710),\n+\tregmap_reg_range(0x1f8000, 0x1f8003),\n+\tregmap_reg_range(0x1f8005, 0x1f8005),\n+\tregmap_reg_range(0x1f800a, 0x1f800a),\n+\tregmap_reg_range(0x1f8010, 0x1f8012),\n+\tregmap_reg_range(0x1f8015, 0x1f8015),\n+\tregmap_reg_range(0x1f8018, 0x1f8018),\n+\tregmap_reg_range(0x1f8020, 0x1f8020),\n+\tregmap_reg_range(0x1f8030, 0x1f8037),\n+\tregmap_reg_range(0x1f803c, 0x1f803c),\n+\tregmap_reg_range(0x1f8040, 0x1f8040),\n+\tregmap_reg_range(0x1f8050, 0x1f8058),\n+\tregmap_reg_range(0x1f805c, 0x1f805e),\n+\tregmap_reg_range(0x1f8060, 0x1f8060),\n+\tregmap_reg_range(0x1f8064, 0x1f8064),\n+\tregmap_reg_range(0x1f806b, 0x1f806b),\n+\tregmap_reg_range(0x1f8070, 0x1f8078),\n+\tregmap_reg_range(0x1f8090, 0x1f8092),\n+\tregmap_reg_range(0x1f8096, 0x1f8096),\n+\tregmap_reg_range(0x1f8098, 0x1f8099),\n+\tregmap_reg_range(0x1f80a0, 0x1f80a2),\n+\tregmap_reg_range(0x1f80e1, 0x1f80e1),\n+};\n+\n+static const struct regmap_access_table s32g_xpcs_rd_table = {\n+\t.yes_ranges = s32g_xpcs_rd_ranges,\n+\t.n_yes_ranges = ARRAY_SIZE(s32g_xpcs_rd_ranges),\n+};\n+\n+static int s32g_xpcs_regmap_reg_read(void *context, unsigned int reg,\n+\t\t\t\t unsigned int *result)\n+{\n+\tstruct s32g_xpcs *xpcs = context;\n+\tu16 ofsleft = (reg \u003e\u003e 8) \u0026 0xffffU;\n+\tu16 ofsright = (reg \u0026 0xffU);\n+\n+\twritew(ofsleft, xpcs-\u003ebase + ADDR1_OFS);\n+\t*result = readw(xpcs-\u003ebase + (ofsright * 4));\n+\n+\treturn 0;\n+}\n+\n+static int s32g_xpcs_regmap_reg_write(void *context, unsigned int reg,\n+\t\t\t\t unsigned int val)\n+{\n+\tstruct s32g_xpcs *xpcs = context;\n+\tu16 ofsleft = (reg \u003e\u003e 8) \u0026 0xffffU;\n+\tu16 ofsright = (reg \u0026 0xffU);\n+\n+\twritew(ofsleft, xpcs-\u003ebase + ADDR1_OFS);\n+\twritew(val, xpcs-\u003ebase + (ofsright * 4));\n+\n+\treturn 0;\n+}\n+\n+static const struct regmap_config s32g_xpcs0_regmap_config = {\n+\t.reg_bits = 32,\n+\t.val_bits = 16,\n+\t.reg_read = s32g_xpcs_regmap_reg_read,\n+\t.reg_write = s32g_xpcs_regmap_reg_write,\n+\t.wr_table = \u0026s32g_xpcs_wr_table,\n+\t.rd_table = \u0026s32g_xpcs_rd_table,\n+\t.max_register = 0x1f80e1,\n+\t.name = \"xpcs0\",\n+};\n+\n+static const struct regmap_config s32g_xpcs1_regmap_config = {\n+\t.reg_bits = 32,\n+\t.val_bits = 16,\n+\t.reg_read = s32g_xpcs_regmap_reg_read,\n+\t.reg_write = s32g_xpcs_regmap_reg_write,\n+\t.wr_table = \u0026s32g_xpcs_wr_table,\n+\t.rd_table = \u0026s32g_xpcs_rd_table,\n+\t.max_register = 0x1f80e1,\n+\t.name = \"xpcs1\",\n+};\n+\n+static void s32g_xpcs_write_bits(struct s32g_xpcs *xpcs, unsigned int reg,\n+\t\t\t\t unsigned int mask, unsigned int value)\n+{\n+\tint ret = regmap_write_bits(xpcs-\u003eregmap, reg, mask, value);\n+\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"Failed to write bits of XPCS reg: 0x%x\\n\", reg);\n+}\n+\n+static void s32g_xpcs_write(struct s32g_xpcs *xpcs, unsigned int reg,\n+\t\t\t unsigned int value)\n+{\n+\tint ret = regmap_write(xpcs-\u003eregmap, reg, value);\n+\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"Failed to write XPCS reg: 0x%x\\n\", reg);\n+}\n+\n+static unsigned int s32g_xpcs_read(struct s32g_xpcs *xpcs, unsigned int reg)\n+{\n+\tunsigned int val = 0;\n+\tint ret;\n+\n+\tret = regmap_read(xpcs-\u003eregmap, reg, \u0026val);\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"Failed to read XPCS reg: 0x%x\\n\", reg);\n+\n+\treturn val;\n+}\n+\n+/*\n+ * Internal XPCS function\n+ */\n+\n+static int s32g_xpcs_wait(struct s32g_xpcs *xpcs, xpcs_poll_func_t func)\n+{\n+\tbool val;\n+\n+\treturn read_poll_timeout(func, val, val, XPCS_POLL_SLEEP_US,\n+\t\t\t\t XPCS_TIMEOUT_US, false, xpcs);\n+}\n+\n+static int s32g_xpcs_wait_bits(struct s32g_xpcs *xpcs, unsigned int reg,\n+\t\t\t unsigned int mask, unsigned int bits)\n+{\n+\tunsigned int val;\n+\n+\treturn read_poll_timeout(s32g_xpcs_read, val, (val \u0026 mask) == bits,\n+\t\t\t\t XPCS_POLL_SLEEP_US, XPCS_TIMEOUT_US, false,\n+\t\t\t\t xpcs, reg);\n+}\n+\n+static unsigned int s32g_xpcs_digital_status(struct s32g_xpcs *xpcs)\n+{\n+\treturn s32g_xpcs_read(xpcs, VR_MII_DIG_STS);\n+}\n+\n+static int s32g_xpcs_wait_power_good_state(struct s32g_xpcs *xpcs)\n+{\n+\tunsigned int val;\n+\n+\treturn read_poll_timeout(s32g_xpcs_digital_status, val,\n+\t\t\t\t FIELD_GET(PSEQ_STATE_MASK, val) == POWER_GOOD_STATE,\n+\t\t\t\t XPCS_POLL_SLEEP_US,\n+\t\t\t\t XPCS_TIMEOUT_US, false, xpcs);\n+}\n+\n+void s32g_xpcs_vreset(struct s32g_xpcs *xpcs)\n+{\n+\t/* Step 19 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, VR_RST, VR_RST);\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_vreset);\n+\n+static bool s32g_xpcs_is_not_in_reset(struct s32g_xpcs *xpcs)\n+{\n+\tunsigned int val;\n+\n+\tval = s32g_xpcs_read(xpcs, VR_MII_DIG_CTRL1);\n+\n+\treturn !(val \u0026 VR_RST);\n+}\n+\n+int s32g_xpcs_wait_vreset(struct s32g_xpcs *xpcs)\n+{\n+\tint ret;\n+\n+\t/* Step 20 */\n+\tret = s32g_xpcs_wait(xpcs, s32g_xpcs_is_not_in_reset);\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"XPCS%d is in reset\\n\", xpcs-\u003eid);\n+\n+\treturn ret;\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_wait_vreset);\n+\n+int s32g_xpcs_reset_rx(struct s32g_xpcs *xpcs)\n+{\n+\tint ret = 0;\n+\n+\t/*\n+\t * On the shared 1G combo lane the PMA power-up is gated by the PCIe\n+\t * side and BYP_PWRUP stays set, so the power sequencer never reaches\n+\t * POWER_GOOD on its own and the wait would always time out.\n+\t */\n+\tif (xpcs-\u003epcie_shared != S32G_PCIE_XPCS_1G) {\n+\t\tret = s32g_xpcs_wait_power_good_state(xpcs);\n+\t\tif (ret) {\n+\t\t\tdev_err(xpcs-\u003edev, \"Failed to enter in PGOOD state after vendor reset\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\t/* Step 21 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL1,\n+\t\t\t RX_RST_0, RX_RST_0);\n+\n+\t/* Step 22 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL1,\n+\t\t\t RX_RST_0, 0);\n+\n+\t/* Step 23 */\n+\t/* Wait until SR_MII_STS[LINK_STS] = 1 */\n+\n+\treturn ret;\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_reset_rx);\n+\n+static int s32g_xpcs_ref_clk_sel(struct s32g_xpcs *xpcs,\n+\t\t\t\t enum s32g_xpcs_pll ref_pll)\n+{\n+\tswitch (ref_pll) {\n+\tcase S32G_XPCS_PLLA:\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL,\n+\t\t\t\t MPLLB_SEL_0, 0);\n+\t\txpcs-\u003eref = S32G_XPCS_PLLA;\n+\t\tbreak;\n+\tcase S32G_XPCS_PLLB:\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL,\n+\t\t\t\t MPLLB_SEL_0, MPLLB_SEL_0);\n+\t\txpcs-\u003eref = S32G_XPCS_PLLB;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void s32g_xpcs_electrical_configure(struct s32g_xpcs *xpcs)\n+{\n+\t/* Step 2 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_EQ_CTRL0,\n+\t\t\t TX_EQ_MAIN_MASK, FIELD_PREP(TX_EQ_MAIN_MASK, 0xc));\n+\n+\t/* Step 3 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_CONSUMER_10G_TX_TERM_CTRL,\n+\t\t\t TX0_TERM_MASK, FIELD_PREP(TX0_TERM_MASK, 0x4));\n+}\n+\n+static int s32g_xpcs_vco_cfg(struct s32g_xpcs *xpcs, enum s32g_xpcs_pll vco_pll)\n+{\n+\tunsigned int vco_ld = 0;\n+\tunsigned int vco_ref = 0;\n+\tunsigned int rx_baud = 0;\n+\tunsigned int tx_baud = 0;\n+\n+\tswitch (vco_pll) {\n+\tcase S32G_XPCS_PLLA:\n+\t\tif (xpcs-\u003emhz125) {\n+\t\t\tvco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1360);\n+\t\t\tvco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 17);\n+\t\t} else {\n+\t\t\tvco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1350);\n+\t\t\tvco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 27);\n+\t\t}\n+\n+\t\trx_baud = FIELD_PREP(RX0_RATE_MASK, RX0_BAUD_DIV_8);\n+\t\ttx_baud = FIELD_PREP(TX0_RATE_MASK, TX0_BAUD_DIV_4);\n+\t\tbreak;\n+\tcase S32G_XPCS_PLLB:\n+\t\tif (xpcs-\u003emhz125) {\n+\t\t\tvco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1350);\n+\t\t\tvco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 27);\n+\t\t} else {\n+\t\t\tvco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1344);\n+\t\t\tvco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 43);\n+\t\t}\n+\n+\t\trx_baud = FIELD_PREP(RX0_RATE_MASK, RX0_BAUD_DIV_2);\n+\t\ttx_baud = FIELD_PREP(TX0_RATE_MASK, TX0_BAUD_DIV_1);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_VCO_CAL_LD0,\n+\t\t\t VCO_LD_VAL_0_MASK, vco_ld);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_VCO_CAL_REF0,\n+\t\t\t VCO_REF_LD_0_MASK, vco_ref);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_RATE_CTRL,\n+\t\t\t TX0_RATE_MASK, tx_baud);\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_RATE_CTRL,\n+\t\t\t RX0_RATE_MASK, rx_baud);\n+\n+\tif (vco_pll == S32G_XPCS_PLLB) {\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_CDR_CTRL,\n+\t\t\t\t VCO_LOW_FREQ_0, VCO_LOW_FREQ_0);\n+\t} else {\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_CDR_CTRL,\n+\t\t\t\t VCO_LOW_FREQ_0, 0);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void s32g_xpcs_init_mplla(struct s32g_xpcs *xpcs)\n+{\n+\tunsigned int val;\n+\n+\t/* Step 7 */\n+\tval = 0;\n+\tif (xpcs-\u003eext_clk)\n+\t\tval |= REF_USE_PAD;\n+\n+\tif (xpcs-\u003emhz125) {\n+\t\tval |= REF_MPLLA_DIV2;\n+\t\tval |= REF_CLK_DIV2;\n+\t\tval |= FIELD_PREP(REF_RANGE_MASK, RANGE_52_78_MHZ);\n+\t} else {\n+\t\t/*\n+\t\t * A non-125 MHz reference is 100 MHz, which falls in the\n+\t\t * 26-53 MHz range after the internal divider, so select\n+\t\t * RANGE_26_53_MHZ.\n+\t\t */\n+\t\tval |= FIELD_PREP(REF_RANGE_MASK, RANGE_26_53_MHZ);\n+\t}\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_REF_CLK_CTRL,\n+\t\t\t REF_MPLLA_DIV2 | REF_USE_PAD | REF_RANGE_MASK |\n+\t\t\t REF_CLK_DIV2, val);\n+\n+\t/* Step 8 */\n+\tif (xpcs-\u003emhz125)\n+\t\tval = FIELD_PREP(MLLA_MULTIPLIER_MASK, 80);\n+\telse\n+\t\tval = FIELD_PREP(MLLA_MULTIPLIER_MASK, 25);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLA_CTRL0,\n+\t\t\t MPLLA_CAL_DISABLE | MLLA_MULTIPLIER_MASK,\n+\t\t\t val);\n+\n+\t/* Step 9 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLA_CTRL1,\n+\t\t\t MPLLA_FRACN_CTRL_MASK, 0);\n+\n+\t/* Step 10 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLA_CTRL2,\n+\t\t\t MPLLA_TX_CLK_DIV_MASK | MPLLA_DIV10_CLK_EN,\n+\t\t\t FIELD_PREP(MPLLA_TX_CLK_DIV_MASK, 1) | MPLLA_DIV10_CLK_EN);\n+\n+\t/* Step 11 */\n+\tif (xpcs-\u003emhz125)\n+\t\tval = FIELD_PREP(MPLLA_BANDWIDTH_MASK, 43);\n+\telse\n+\t\tval = FIELD_PREP(MPLLA_BANDWIDTH_MASK, 357);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLA_CTRL3,\n+\t\t\t MPLLA_BANDWIDTH_MASK, val);\n+}\n+\n+static void s32g_xpcs_init_mpllb(struct s32g_xpcs *xpcs)\n+{\n+\tunsigned int val;\n+\n+\t/* Step 7 */\n+\tval = 0;\n+\tif (xpcs-\u003eext_clk)\n+\t\tval |= REF_USE_PAD;\n+\n+\tif (xpcs-\u003emhz125) {\n+\t\tval |= REF_MPLLB_DIV2;\n+\t\tval |= REF_CLK_DIV2;\n+\t\tval |= FIELD_PREP(REF_RANGE_MASK, RANGE_52_78_MHZ);\n+\t} else {\n+\t\t/*\n+\t\t * REF_RANGE selects the reference-clock frequency band and is\n+\t\t * shared by both PLLs. For a 100 MHz reference this is the\n+\t\t * 26-53 MHz range after the internal divider: RANGE_26_53_MHZ.\n+\t\t */\n+\t\tval |= FIELD_PREP(REF_RANGE_MASK, RANGE_26_53_MHZ);\n+\t}\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_REF_CLK_CTRL,\n+\t\t\t REF_MPLLB_DIV2 | REF_USE_PAD | REF_RANGE_MASK |\n+\t\t\t REF_CLK_DIV2, val);\n+\n+\t/* Step 8 */\n+\tif (xpcs-\u003emhz125)\n+\t\tval = FIELD_PREP(MLLB_MULTIPLIER_MASK, 125);\n+\telse\n+\t\tval = FIELD_PREP(MLLB_MULTIPLIER_MASK, 39);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLB_CTRL0,\n+\t\t\t MPLLB_CAL_DISABLE | MLLB_MULTIPLIER_MASK,\n+\t\t\t val);\n+\n+\t/* Step 9 */\n+\tif (xpcs-\u003emhz125)\n+\t\tval = FIELD_PREP(MPLLB_FRACN_CTRL_MASK, 0);\n+\telse\n+\t\tval = FIELD_PREP(MPLLB_FRACN_CTRL_MASK, 1044);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLB_CTRL1,\n+\t\t\t MPLLB_FRACN_CTRL_MASK, val);\n+\n+\t/* Step 10 */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLB_CTRL2,\n+\t\t\t MPLLB_TX_CLK_DIV_MASK | MPLLB_DIV10_CLK_EN,\n+\t\t\t FIELD_PREP(MPLLB_TX_CLK_DIV_MASK, 5) | MPLLB_DIV10_CLK_EN);\n+\n+\t/* Step 11 */\n+\tif (xpcs-\u003emhz125)\n+\t\tval = FIELD_PREP(MPLLB_BANDWIDTH_MASK, 68);\n+\telse\n+\t\tval = FIELD_PREP(MPLLB_BANDWIDTH_MASK, 102);\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLB_CTRL3,\n+\t\t\t MPLLB_BANDWIDTH_MASK, val);\n+}\n+\n+static void s32g_serdes_pma_high_freq_recovery(struct s32g_xpcs *xpcs)\n+{\n+\t/* PCS signal protection, PLL railout recovery */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_DBG_CTRL, SUPPRESS_LOS_DET | RX_DT_EN_CTL,\n+\t\t\t SUPPRESS_LOS_DET | RX_DT_EN_CTL);\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MISC_CTRL0,\n+\t\t\t PLL_CTRL, PLL_CTRL);\n+}\n+\n+static void s32g_serdes_pma_configure_tx_eq_post(struct s32g_xpcs *xpcs)\n+{\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_EQ_CTRL1,\n+\t\t\t TX_EQ_OVR_RIDE, TX_EQ_OVR_RIDE);\n+}\n+\n+static int s32g_serdes_bifurcation_pll_transit(struct s32g_xpcs *xpcs,\n+\t\t\t\t\t enum s32g_xpcs_pll target_pll)\n+{\n+\tint ret = 0;\n+\tstruct device *dev = xpcs-\u003edev;\n+\n+\t/* Configure XPCS speed and VCO */\n+\tif (target_pll == S32G_XPCS_PLLA) {\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, EN_2_5G_MODE, 0);\n+\t\ts32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLA);\n+\t} else {\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,\n+\t\t\t\t EN_2_5G_MODE, EN_2_5G_MODE);\n+\t\ts32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLB);\n+\t}\n+\n+\t/* Signal that clock are not available */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL1,\n+\t\t\t TX_CLK_RDY_0, 0);\n+\n+\t/* Select PLL reference */\n+\tif (target_pll == S32G_XPCS_PLLA)\n+\t\ts32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLA);\n+\telse\n+\t\ts32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLB);\n+\n+\t/* Initiate transmitter TX reconfiguration request */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL2,\n+\t\t\t TX_REQ_0, TX_REQ_0);\n+\n+\t/* Wait for transmitter to reconfigure */\n+\tret = s32g_xpcs_wait_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL2,\n+\t\t\t\t TX_REQ_0, 0);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Switch to TX_REQ_0 failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\t/* Initiate transmitter RX reconfiguration request */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL2,\n+\t\t\t RX_REQ_0, RX_REQ_0);\n+\n+\t/* Wait for receiver to reconfigure */\n+\tret = s32g_xpcs_wait_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL2,\n+\t\t\t\t RX_REQ_0, 0);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Switch to RX_REQ_0 failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\t/* Signal that clock are available */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL1,\n+\t\t\t TX_CLK_RDY_0, TX_CLK_RDY_0);\n+\n+\t/* Flush internal logic */\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, INIT, INIT);\n+\n+\t/* Wait for init */\n+\tret = s32g_xpcs_wait_bits(xpcs, VR_MII_DIG_CTRL1, INIT, 0);\n+\tif (ret) {\n+\t\tdev_err(dev, \"XPCS INIT failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+/*\n+ * PMA hooks, run from the shared core's pcs_config() after the generic C37\n+ * SGMII / 2500BASE-X setup. The S32G context hangs off the shared\n+ * nxp_serdes_xpcs priv pointer, set in s32g_xpcs_create().\n+ */\n+\n+static int s32g_xpcs_pma_sgmii(struct nxp_serdes_xpcs *nxpcs)\n+{\n+\tstruct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);\n+\tint ret;\n+\n+\t/*\n+\t * The shared core sets PCS_MODE_SGMII, TX_CONFIG and MAC_AUTO_SW. The\n+\t * link timer differs on the PCIe-shared 2.5G lane, where\n+\t * CL37_TMR_OVRRIDE must be set for the override value to take effect.\n+\t */\n+\tif (xpcs-\u003epcie_shared == S32G_PCIE_XPCS_2G5) {\n+\t\ts32g_xpcs_write(xpcs, VR_MII_LINK_TIMER_CTRL, 0x2faf);\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,\n+\t\t\t\t MAC_AUTO_SW, MAC_AUTO_SW);\n+\t} else {\n+\t\ts32g_xpcs_write(xpcs, VR_MII_LINK_TIMER_CTRL, 0x7a1);\n+\n+\t\t/*\n+\t\t * Clearing EN_2_5G_MODE does not reprogram the PMA line rate:\n+\t\t * the VCO load, the baud dividers and MPLLB_SEL stay at 2.5G if\n+\t\t * the lane last came up as 2500BASE-X. A 2.5G to 1G\n+\t\t * renegotiation then links at 1000 Mbps while the PMA keeps\n+\t\t * clocking at 3.125 Gbaud and no traffic passes, so run the\n+\t\t * full transition back to PLLA. Idempotent on a fresh 1G lane.\n+\t\t */\n+\t\tret = s32g_serdes_bifurcation_pll_transit(xpcs,\n+\t\t\t\t\t\t\t S32G_XPCS_PLLA);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,\n+\t\t\t CL37_TMR_OVRRIDE, CL37_TMR_OVRRIDE);\n+\n+\treturn 0;\n+}\n+\n+static int s32g_xpcs_pma_2500basex(struct nxp_serdes_xpcs *nxpcs)\n+{\n+\tstruct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);\n+\n+\t/*\n+\t * The shared core has set EN_2_5G_MODE (DW_VR_MII_DIG_CTRL1_2G5_EN)\n+\t * via nxp_serdes_xpcs_config_2500basex(). S32G additionally needs the\n+\t * PMA switched from the slow PLLA to the fast PLLB and re-initialised.\n+\t */\n+\treturn s32g_serdes_bifurcation_pll_transit(xpcs, S32G_XPCS_PLLB);\n+}\n+\n+static int s32g_xpcs_pma_link_up_sgmii(struct nxp_serdes_xpcs *nxpcs,\n+\t\t\t\t int speed, int duplex)\n+{\n+\tstruct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);\n+\n+\t/*\n+\t * A 2.5G SGMII fixed-link keeps interface == SGMII and never reaches\n+\t * the 2500BASE-X hook, so the PMA would stay on the 1G-class PLLA that\n+\t * pma_sgmii() programmed at config time. Move to PLLB (which also sets\n+\t * EN_2_5G_MODE) once the link resolves to 2.5G; below that the\n+\t * config-time PLLA setting is already right.\n+\t */\n+\tif (speed != SPEED_2500)\n+\t\treturn 0;\n+\n+\treturn s32g_serdes_bifurcation_pll_transit(xpcs, S32G_XPCS_PLLB);\n+}\n+\n+static const struct nxp_serdes_xpcs_compat s32g_xpcs_compat[] = {\n+\t{\n+\t\t.interface = PHY_INTERFACE_MODE_SGMII,\n+\t\t.supported = nxp_serdes_xpcs_sgmii_features,\n+\t\t.an_mode = NXP_SERDES_AN_C37_SGMII,\n+\t\t.pma_config = s32g_xpcs_pma_sgmii,\n+\t\t.pma_link_up = s32g_xpcs_pma_link_up_sgmii,\n+\t},\n+\t{\n+\t\t.interface = PHY_INTERFACE_MODE_2500BASEX,\n+\t\t.supported = nxp_serdes_xpcs_2500basex_features,\n+\t\t.an_mode = NXP_SERDES_2500BASEX,\n+\t\t.pma_config = s32g_xpcs_pma_2500basex,\n+\t},\n+\t{ }\n+};\n+\n+static const struct nxp_serdes_xpcs_desc s32g_xpcs_desc = {\n+\t.name = \"s32g-serdes-xpcs\",\n+\t.compat = s32g_xpcs_compat,\n+\t/*\n+\t * S32G runs its own vendor reset (VR_RST) as part of the ordered\n+\t * dual-XPCS bring-up barrier in the SerDes PHY driver, so the shared\n+\t * core must not issue the generic BMCR soft reset. S32G3 does not\n+\t * implement the EEE VR_MII_EEE_MCTRL0/1 registers either.\n+\t */\n+\t.quirks = NXP_SERDES_QUIRK_NO_SOFT_RESET | NXP_SERDES_QUIRK_NO_EEE,\n+\t.reset = NULL,\n+};\n+\n+/*\n+ * Serdes functions for initializing/configuring/releasing the xpcs\n+ */\n+\n+int s32g_xpcs_init_plls(struct s32g_xpcs *xpcs)\n+{\n+\tint ret;\n+\n+\tif (!xpcs-\u003eext_clk) {\n+\t\t/* Step 1 */\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, BYP_PWRUP, BYP_PWRUP);\n+\t} else if (xpcs-\u003epcie_shared == S32G_NOT_SHARED) {\n+\t\tret = s32g_xpcs_wait_power_good_state(xpcs);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t} else if (xpcs-\u003epcie_shared == S32G_PCIE_XPCS_2G5) {\n+\t\tret = s32g_xpcs_wait_power_good_state(xpcs);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\t/* Configure equalization */\n+\t\ts32g_serdes_pma_configure_tx_eq_post(xpcs);\n+\t\ts32g_xpcs_electrical_configure(xpcs);\n+\n+\t\t/* Enable receiver recover */\n+\t\ts32g_serdes_pma_high_freq_recovery(xpcs);\n+\t\treturn 0;\n+\t}\n+\n+\ts32g_xpcs_electrical_configure(xpcs);\n+\n+\ts32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLA);\n+\ts32g_xpcs_init_mplla(xpcs);\n+\ts32g_xpcs_init_mpllb(xpcs);\n+\ts32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLA);\n+\n+\t/*\n+\t * Step 18: for an internal reference BYP_PWRUP was set in Step 1 to\n+\t * bypass the power-up sequencer; clear it so the PMA powers up. The\n+\t * shared 1G lane keeps it set - there the PCIe side drives power-up\n+\t * and clearing it stalls the XPCS bring-up.\n+\t */\n+\tif (!xpcs-\u003eext_clk \u0026\u0026 xpcs-\u003epcie_shared != S32G_PCIE_XPCS_1G)\n+\t\ts32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, BYP_PWRUP, 0);\n+\n+\t/* Will be cleared by Step 19 Vreset */\n+\ts32g_xpcs_write_bits(xpcs, SR_MII_CTRL, AN_ENABLE, 0);\n+\ts32g_xpcs_write_bits(xpcs, SR_MII_CTRL, DUPLEX_MODE, DUPLEX_MODE);\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_init_plls);\n+\n+void s32g_xpcs_disable_an(struct s32g_xpcs *xpcs)\n+{\n+\ts32g_xpcs_write_bits(xpcs, SR_MII_CTRL, DUPLEX_MODE, DUPLEX_MODE);\n+\ts32g_xpcs_write_bits(xpcs, SR_MII_CTRL, AN_ENABLE, 0);\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_disable_an);\n+\n+static void s32g_xpcs_pcs_destroy(void *pcs)\n+{\n+\tnxp_serdes_xpcs_destroy(pcs);\n+}\n+\n+/**\n+ * s32g_xpcs_create() - allocate and set up one XPCS instance\n+ * @dev: the SerDes device the XPCS belongs to; owns the allocation\n+ * @id: XPCS instance number within the SerDes subsystem (0 or 1)\n+ * @base: mapped register block of that instance\n+ * @ext_clk: reference is taken from the external pad rather than internal\n+ * @rate: reference clock rate, 100 or 125 MHz\n+ * @pcie_shared: whether the lane shares the combo PHY with PCIe\n+ *\n+ * The instance is devm-allocated against @dev, so it lives as long as the\n+ * SerDes device and must not be freed by the caller. The returned handle\n+ * is opaque; use s32g_xpcs_pcs() to obtain the phylink PCS created on top\n+ * of the NXP SerDes xPCS shared core.\n+ *\n+ * Return: the XPCS handle, or an ERR_PTR() on failure.\n+ */\n+struct s32g_xpcs *s32g_xpcs_create(struct device *dev, unsigned char id,\n+\t\t\t\t void __iomem *base, bool ext_clk,\n+\t\t\t\t unsigned long rate,\n+\t\t\t\t enum s32g_xpcs_shared pcie_shared)\n+{\n+\tconst struct regmap_config *conf;\n+\tstruct nxp_serdes_xpcs *nxpcs;\n+\tstruct s32g_xpcs *xpcs;\n+\tstruct phylink_pcs *pcs;\n+\tint ret;\n+\n+\tif (rate != (125 * HZ_PER_MHZ) \u0026\u0026 rate != (100 * HZ_PER_MHZ)) {\n+\t\tdev_err(dev, \"XPCS cannot operate @%lu HZ\\n\", rate);\n+\t\treturn ERR_PTR(-EINVAL);\n+\t}\n+\n+\txpcs = devm_kzalloc(dev, sizeof(*xpcs), GFP_KERNEL);\n+\tif (!xpcs)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\txpcs-\u003ebase = base;\n+\txpcs-\u003eext_clk = ext_clk;\n+\txpcs-\u003eid = id;\n+\txpcs-\u003edev = dev;\n+\txpcs-\u003epcie_shared = pcie_shared;\n+\n+\tif (rate == (125 * HZ_PER_MHZ))\n+\t\txpcs-\u003emhz125 = true;\n+\telse\n+\t\txpcs-\u003emhz125 = false;\n+\n+\tif (!id)\n+\t\tconf = \u0026s32g_xpcs0_regmap_config;\n+\telse\n+\t\tconf = \u0026s32g_xpcs1_regmap_config;\n+\n+\txpcs-\u003eregmap = devm_regmap_init(dev, NULL, xpcs, conf);\n+\tif (IS_ERR(xpcs-\u003eregmap))\n+\t\treturn ERR_PTR(dev_err_probe(dev, PTR_ERR(xpcs-\u003eregmap),\n+\t\t\t\t\t \"Failed to init register map\\n\"));\n+\n+\t/*\n+\t * Create the phylink PCS on the shared core, handing it the S32G\n+\t * regmap as the register transport. SGMII is the initial interface;\n+\t * phylink re-runs pcs_config() with the real interface at link time.\n+\t */\n+\tpcs = nxp_serdes_xpcs_create(dev, xpcs-\u003eregmap, NULL, \u0026s32g_xpcs_desc,\n+\t\t\t\t id, PHY_INTERFACE_MODE_SGMII);\n+\tif (IS_ERR(pcs))\n+\t\treturn ERR_PTR(dev_err_probe(dev, PTR_ERR(pcs),\n+\t\t\t\t\t \"Failed to create SerDes xPCS\\n\"));\n+\n+\tret = devm_add_action_or_reset(dev, s32g_xpcs_pcs_destroy, pcs);\n+\tif (ret)\n+\t\treturn ERR_PTR(ret);\n+\n+\t/* Let the S32G PMA hooks recover their context from the shared PCS. */\n+\tnxpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tnxp_serdes_xpcs_set_drvdata(nxpcs, xpcs);\n+\n+\txpcs-\u003epcs = pcs;\n+\n+\treturn xpcs;\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_create);\n+\n+/**\n+ * s32g_xpcs_pcs() - the phylink PCS of an XPCS instance\n+ * @xpcs: handle from s32g_xpcs_create()\n+ *\n+ * Return: the phylink_pcs, owned by the SerDes device.\n+ */\n+struct phylink_pcs *s32g_xpcs_pcs(struct s32g_xpcs *xpcs)\n+{\n+\treturn xpcs-\u003epcs;\n+}\n+EXPORT_SYMBOL_GPL(s32g_xpcs_pcs);\n+\n+MODULE_DESCRIPTION(\"NXP S32G SerDes XPCS driver\");\n+MODULE_AUTHOR(\"Jan Petrous (OSS) \u003cjan.petrous@oss.nxp.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/drivers/net/pcs/pcs-nxp-serdes-xpcs.c b/drivers/net/pcs/pcs-nxp-serdes-xpcs.c\nnew file mode 100644\nindex 0000000000000..cc739914496e3\n--- /dev/null\n+++ b/drivers/net/pcs/pcs-nxp-serdes-xpcs.c\n@@ -0,0 +1,853 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* NXP SerDes XPCS / XPCS-PHY shared core\n+ *\n+ * Transport agnostic phylink PCS driver for the Ethernet XPCS and Ethernet\n+ * PHY (XPCS-PHY) of the SerDes subsystems found on NXP S32G and i.MX SoCs.\n+ * The platform glue provides the regmaps and a per revision descriptor\n+ * with the compatibility table, quirks and PMA programming sequences.\n+ *\n+ * The XPCS is a Synopsys DesignWare core, so the Clause 37 / 2500BASE-X /\n+ * USXGMII / 10GBASE-R register sequences below are shared with the Synopsys\n+ * pcs-xpcs driver and were derived from it. This is a separate driver rather\n+ * than an extension of pcs-xpcs because struct dw_xpcs is built around an\n+ * mdio_device: it owns the transport, the reset and the identification of a\n+ * standalone PCS. That model does not fit these SerDes subsystems, where the\n+ * PMA belongs to a combo PHY shared with a PCIe controller, the bring-up is\n+ * sequenced across both XPCS instances by the PHY driver, and the register\n+ * transport is either indirect MMIO or Clause 45 MDIO. What is left here is\n+ * the phylink PCS layer on top of a regmap.\n+ *\n+ * Keep the register sequences in sync with drivers/net/pcs/pcs-xpcs.c when\n+ * fixes apply to both.\n+ *\n+ * Copyright 2023-2026 NXP\n+ * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates.\n+ */\n+\n+#include \u003clinux/device.h\u003e\n+#include \u003clinux/ethtool.h\u003e\n+#include \u003clinux/iopoll.h\u003e\n+#include \u003clinux/mdio.h\u003e\n+#include \u003clinux/mii.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/pcs/pcs-nxp-serdes-xpcs.h\u003e\n+#include \u003clinux/phylink.h\u003e\n+\n+/* SR_MII USXGMII speed selection */\n+#define DW_USXGMII_RST\t\t\tBIT(10)\n+#define DW_USXGMII_EN\t\t\tBIT(9)\n+#define DW_USXGMII_FULL\t\t\tBIT(8)\n+#define DW_USXGMII_SS_MASK\t\t(BIT(13) | BIT(6) | BIT(5))\n+#define DW_USXGMII_10000\t\t(BIT(13) | BIT(6))\n+#define DW_USXGMII_5000\t\t\t(BIT(13) | BIT(5))\n+#define DW_USXGMII_2500\t\t\t(BIT(5))\n+#define DW_USXGMII_1000\t\t\t(BIT(6))\n+#define DW_USXGMII_100\t\t\t(BIT(13))\n+#define DW_USXGMII_10\t\t\t(0)\n+\n+/* VR MII MMD registers offsets */\n+#define DW_VR_MII_DIG_CTRL1\t\t0x8000\n+#define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW\t\tBIT(9)\n+#define DW_VR_MII_DIG_CTRL1_2G5_EN\t\tBIT(2)\n+\n+#define DW_VR_MII_AN_CTRL\t\t0x8001\n+#define DW_VR_MII_TX_CONFIG_MASK\t\tBIT(3)\n+#define DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII\t0x0\n+#define DW_VR_MII_PCS_MODE_MASK\t\t\tGENMASK(2, 1)\n+#define DW_VR_MII_PCS_MODE_C37_SGMII\t\t0x2\n+#define DW_VR_MII_AN_INTR_EN\t\t\tBIT(0)\n+\n+#define DW_VR_MII_AN_INTR_STS\t\t0x8002\n+#define DW_VR_MII_AN_STS_C37_ANCMPLT_INTR\tBIT(0)\n+#define DW_VR_MII_AN_STS_C37_ANSGM_FD\t\tBIT(1)\n+#define DW_VR_MII_AN_STS_C37_ANSGM_SP\t\tGENMASK(3, 2)\n+#define DW_VR_MII_C37_ANSGM_SP_10\t\t0x0\n+#define DW_VR_MII_C37_ANSGM_SP_100\t\t0x1\n+#define DW_VR_MII_C37_ANSGM_SP_1000\t\t0x2\n+#define DW_VR_MII_C37_ANSGM_SP_LNKSTS\t\tBIT(4)\n+#define DW_VR_MII_USX_AN_STS_MASK\t\tGENMASK(14, 8)\n+\n+#define DW_VR_MII_EEE_MCTRL0\t\t0x8006\n+#define DW_VR_MII_EEE_LTX_EN\t\t\tBIT(0) /* LPI Tx Enable */\n+#define DW_VR_MII_EEE_LRX_EN\t\t\tBIT(1) /* LPI Rx Enable */\n+#define DW_VR_MII_EEE_TX_QUIET_EN\t\tBIT(2) /* Tx Quiet Enable */\n+#define DW_VR_MII_EEE_RX_QUIET_EN\t\tBIT(3) /* Rx Quiet Enable */\n+#define DW_VR_MII_EEE_TX_EN_CTRL\t\tBIT(4) /* Tx Control Enable */\n+#define DW_VR_MII_EEE_RX_EN_CTRL\t\tBIT(7) /* Rx Control Enable */\n+#define DW_VR_MII_EEE_MULT_FACT_100NS\t\tGENMASK(11, 8)\n+\n+#define DW_VR_MII_EEE_MCTRL1\t\t0x800b\n+#define DW_VR_MII_EEE_TRN_LPI\t\tBIT(0)\t/* Transparent Mode Enable */\n+\n+const int nxp_serdes_xpcs_usxgmii_features[] = {\n+\tETHTOOL_LINK_MODE_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Asym_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Autoneg_BIT,\n+\tETHTOOL_LINK_MODE_1000baseKX_Full_BIT,\n+\tETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,\n+\tETHTOOL_LINK_MODE_10000baseKR_Full_BIT,\n+\tETHTOOL_LINK_MODE_2500baseX_Full_BIT,\n+\t__ETHTOOL_LINK_MODE_MASK_NBITS,\n+};\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_usxgmii_features);\n+\n+const int nxp_serdes_xpcs_2500basex_features[] = {\n+\tETHTOOL_LINK_MODE_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Asym_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Autoneg_BIT,\n+\tETHTOOL_LINK_MODE_2500baseX_Full_BIT,\n+\tETHTOOL_LINK_MODE_2500baseT_Full_BIT,\n+\t__ETHTOOL_LINK_MODE_MASK_NBITS,\n+};\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_2500basex_features);\n+\n+const int nxp_serdes_xpcs_sgmii_features[] = {\n+\tETHTOOL_LINK_MODE_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Asym_Pause_BIT,\n+\tETHTOOL_LINK_MODE_Autoneg_BIT,\n+\tETHTOOL_LINK_MODE_10baseT_Half_BIT,\n+\tETHTOOL_LINK_MODE_10baseT_Full_BIT,\n+\tETHTOOL_LINK_MODE_100baseT_Half_BIT,\n+\tETHTOOL_LINK_MODE_100baseT_Full_BIT,\n+\tETHTOOL_LINK_MODE_1000baseT_Half_BIT,\n+\tETHTOOL_LINK_MODE_1000baseT_Full_BIT,\n+\t__ETHTOOL_LINK_MODE_MASK_NBITS,\n+};\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_sgmii_features);\n+\n+static const struct nxp_serdes_xpcs_compat *\n+nxp_serdes_xpcs_find_compat(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t phy_interface_t interface)\n+{\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\n+\tfor (compat = xpcs-\u003edesc-\u003ecompat; compat-\u003esupported; compat++)\n+\t\tif (compat-\u003einterface == interface)\n+\t\t\treturn compat;\n+\n+\treturn NULL;\n+}\n+\n+static void nxp_serdes_xpcs_get_interfaces(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t unsigned long *interfaces)\n+{\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\n+\tfor (compat = xpcs-\u003edesc-\u003ecompat; compat-\u003esupported; compat++)\n+\t\t__set_bit(compat-\u003einterface, interfaces);\n+}\n+\n+int nxp_serdes_xpcs_read(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg)\n+{\n+\tunsigned int val;\n+\tint ret;\n+\n+\tret = regmap_read(xpcs-\u003expcs_regmap, (devad \u003c\u003c 16) | (reg \u0026 0xffff),\n+\t\t\t \u0026val);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\treturn val;\n+}\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_read);\n+\n+int nxp_serdes_xpcs_write(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,\n+\t\t\t u16 val)\n+{\n+\treturn regmap_write(xpcs-\u003expcs_regmap, (devad \u003c\u003c 16) | (reg \u0026 0xffff),\n+\t\t\t val);\n+}\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_write);\n+\n+int nxp_serdes_xpcs_modify(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,\n+\t\t\t u16 mask, u16 set)\n+{\n+\treturn regmap_update_bits(xpcs-\u003expcs_regmap,\n+\t\t\t\t (devad \u003c\u003c 16) | (reg \u0026 0xffff), mask, set);\n+}\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_modify);\n+\n+static int nxp_serdes_xpcs_poll_reset(struct nxp_serdes_xpcs *xpcs, int dev)\n+{\n+\tint ret, val;\n+\n+\tret = read_poll_timeout(nxp_serdes_xpcs_read, val,\n+\t\t\t\tval \u003c 0 || !(val \u0026 BMCR_RESET),\n+\t\t\t\t50000, 600000, true, xpcs, dev, MII_BMCR);\n+\tif (val \u003c 0)\n+\t\tret = val;\n+\n+\treturn ret;\n+}\n+\n+static int nxp_serdes_xpcs_soft_reset(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t const struct nxp_serdes_xpcs_compat *compat)\n+{\n+\tint ret, dev;\n+\n+\tswitch (compat-\u003ean_mode) {\n+\tcase NXP_SERDES_10GBASER:\n+\t\tdev = MDIO_MMD_PCS;\n+\t\tbreak;\n+\tcase NXP_SERDES_AN_C37_SGMII:\n+\tcase NXP_SERDES_AN_C37_USXGMII:\n+\tcase NXP_SERDES_2500BASEX:\n+\t\tdev = MDIO_MMD_VEND2;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tret = nxp_serdes_xpcs_write(xpcs, dev, MII_BMCR, BMCR_RESET);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\treturn nxp_serdes_xpcs_poll_reset(xpcs, dev);\n+}\n+\n+static int nxp_serdes_xpcs_validate(struct phylink_pcs *pcs,\n+\t\t\t\t unsigned long *supported,\n+\t\t\t\t const struct phylink_link_state *state)\n+{\n+\t__ETHTOOL_DECLARE_LINK_MODE_MASK(xpcs_supported) = { 0, };\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tstruct nxp_serdes_xpcs *xpcs;\n+\tint i;\n+\n+\txpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, state-\u003einterface);\n+\tif (!compat)\n+\t\treturn -EINVAL;\n+\n+\tfor (i = 0; compat-\u003esupported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++)\n+\t\tset_bit(compat-\u003esupported[i], xpcs_supported);\n+\n+\tlinkmode_and(supported, supported, xpcs_supported);\n+\n+\treturn 0;\n+}\n+\n+static unsigned int nxp_serdes_xpcs_inband_caps(struct phylink_pcs *pcs,\n+\t\t\t\t\t\tphy_interface_t interface)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, interface);\n+\tif (!compat)\n+\t\treturn 0;\n+\n+\tswitch (compat-\u003ean_mode) {\n+\tcase NXP_SERDES_AN_C37_USXGMII:\n+\t\treturn LINK_INBAND_ENABLE;\n+\n+\tcase NXP_SERDES_AN_C37_SGMII:\n+\t\treturn LINK_INBAND_DISABLE | LINK_INBAND_ENABLE;\n+\n+\tcase NXP_SERDES_10GBASER:\n+\tcase NXP_SERDES_2500BASEX:\n+\t\treturn LINK_INBAND_DISABLE;\n+\n+\tdefault:\n+\t\treturn 0;\n+\t}\n+}\n+\n+static void nxp_serdes_xpcs_disable(struct phylink_pcs *pcs)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\tif (xpcs-\u003edesc-\u003ereset)\n+\t\txpcs-\u003edesc-\u003ereset(xpcs);\n+}\n+\n+static void nxp_serdes_xpcs_pre_config(struct phylink_pcs *pcs,\n+\t\t\t\t phy_interface_t interface)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tint ret;\n+\n+\tif (xpcs-\u003einterface != interface) {\n+\t\tif (interface == PHY_INTERFACE_MODE_SGMII)\n+\t\t\txpcs-\u003eneed_reset = true;\n+\t\txpcs-\u003einterface = interface;\n+\t}\n+\n+\tif (xpcs-\u003edesc-\u003equirks \u0026 NXP_SERDES_QUIRK_NO_POLL)\n+\t\txpcs-\u003epcs.poll = false;\n+\n+\tif (xpcs-\u003edesc-\u003equirks \u0026 NXP_SERDES_QUIRK_NO_SOFT_RESET)\n+\t\txpcs-\u003eneed_reset = false;\n+\n+\tif (!xpcs-\u003eneed_reset)\n+\t\treturn;\n+\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, interface);\n+\tif (!compat) {\n+\t\tdev_err(xpcs-\u003edev, \"unsupported interface %s\\n\",\n+\t\t\tphy_modes(interface));\n+\t\treturn;\n+\t}\n+\n+\tret = nxp_serdes_xpcs_soft_reset(xpcs, compat);\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"soft reset failed: %pe\\n\", ERR_PTR(ret));\n+\n+\txpcs-\u003eneed_reset = false;\n+}\n+\n+static int nxp_serdes_xpcs_config_aneg_c37_sgmii(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t\t unsigned int neg_mode)\n+{\n+\tint ret, mdio_ctrl;\n+\tu16 mask, val;\n+\n+\t/* Disable AN while PCS_MODE and TX_CONFIG are switched to C37 SGMII on\n+\t * the MAC side, then re-enable it for in-band mode. MAC_AUTO_SW lets\n+\t * the hardware apply the negotiated speed and duplex.\n+\t */\n+\tmdio_ctrl = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);\n+\tif (mdio_ctrl \u003c 0)\n+\t\treturn mdio_ctrl;\n+\n+\tif (mdio_ctrl \u0026 BMCR_ANENABLE) {\n+\t\tret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,\n+\t\t\t\t\t mdio_ctrl \u0026 ~BMCR_ANENABLE);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\t}\n+\n+\tmask = DW_VR_MII_PCS_MODE_MASK | DW_VR_MII_TX_CONFIG_MASK;\n+\tval = FIELD_PREP(DW_VR_MII_PCS_MODE_MASK,\n+\t\t\t DW_VR_MII_PCS_MODE_C37_SGMII);\n+\tval |= FIELD_PREP(DW_VR_MII_TX_CONFIG_MASK,\n+\t\t\t DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII);\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_CTRL,\n+\t\t\t\t mask, val);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tval = 0;\n+\tmask = DW_VR_MII_DIG_CTRL1_2G5_EN | DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW;\n+\n+\tif (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)\n+\t\tval = DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW;\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,\n+\t\t\t\t mask, val);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tif (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)\n+\t\tret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,\n+\t\t\t\t\t mdio_ctrl | BMCR_ANENABLE);\n+\n+\treturn ret;\n+}\n+\n+static int nxp_serdes_xpcs_config_2500basex(struct nxp_serdes_xpcs *xpcs)\n+{\n+\tint ret;\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,\n+\t\t\t\t DW_VR_MII_DIG_CTRL1_2G5_EN |\n+\t\t\t\t DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW,\n+\t\t\t\t DW_VR_MII_DIG_CTRL1_2G5_EN);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\treturn nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR,\n+\t\t\t\t BMCR_ANENABLE | BMCR_SPEED1000 |\n+\t\t\t\t BMCR_SPEED100, BMCR_SPEED1000);\n+}\n+\n+static int nxp_serdes_xpcs_config_10gbaser(struct nxp_serdes_xpcs *xpcs)\n+{\n+\treturn nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,\n+\t\t\t\t DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW, 0);\n+}\n+\n+static int nxp_serdes_xpcs_do_config(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t phy_interface_t interface,\n+\t\t\t\t const unsigned long *advertising,\n+\t\t\t\t unsigned int neg_mode)\n+{\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tint ret;\n+\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, interface);\n+\tif (!compat)\n+\t\treturn -ENODEV;\n+\n+\tswitch (compat-\u003ean_mode) {\n+\tcase NXP_SERDES_10GBASER:\n+\t\tret = nxp_serdes_xpcs_config_10gbaser(xpcs);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tbreak;\n+\tcase NXP_SERDES_AN_C37_USXGMII:\n+\t\tbreak;\n+\tcase NXP_SERDES_AN_C37_SGMII:\n+\t\tret = nxp_serdes_xpcs_config_aneg_c37_sgmii(xpcs, neg_mode);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tbreak;\n+\tcase NXP_SERDES_2500BASEX:\n+\t\tret = nxp_serdes_xpcs_config_2500basex(xpcs);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (compat-\u003epma_config) {\n+\t\tret = compat-\u003epma_config(xpcs);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int nxp_serdes_xpcs_config(struct phylink_pcs *pcs,\n+\t\t\t\t unsigned int neg_mode,\n+\t\t\t\t phy_interface_t interface,\n+\t\t\t\t const unsigned long *advertising,\n+\t\t\t\t bool permit_pause_to_mac)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\treturn nxp_serdes_xpcs_do_config(xpcs, interface, advertising, neg_mode);\n+}\n+\n+static int nxp_serdes_xpcs_get_state_c37_sgmii(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t unsigned int neg_mode,\n+\t\t\t\t\t struct phylink_link_state *state)\n+{\n+\tint ret;\n+\n+\tstate-\u003elink = false;\n+\tstate-\u003espeed = SPEED_UNKNOWN;\n+\tstate-\u003eduplex = DUPLEX_UNKNOWN;\n+\tstate-\u003epause = 0;\n+\n+\t/* Until AN completes, the status still holds the previous SGMII word */\n+\tif (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {\n+\t\tret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);\n+\t\tif (ret \u003c 0)\n+\t\t\treturn ret;\n+\n+\t\tif (!(ret \u0026 BMSR_ANEGCOMPLETE))\n+\t\t\treturn 0;\n+\t}\n+\n+\tret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tstate-\u003ean_complete = ret \u0026 DW_VR_MII_AN_STS_C37_ANCMPLT_INTR;\n+\n+\tif (ret \u0026 DW_VR_MII_C37_ANSGM_SP_LNKSTS) {\n+\t\tint speed_value;\n+\n+\t\tstate-\u003elink = true;\n+\n+\t\tspeed_value = FIELD_GET(DW_VR_MII_AN_STS_C37_ANSGM_SP, ret);\n+\t\tif (speed_value == DW_VR_MII_C37_ANSGM_SP_1000)\n+\t\t\tstate-\u003espeed = SPEED_1000;\n+\t\telse if (speed_value == DW_VR_MII_C37_ANSGM_SP_100)\n+\t\t\tstate-\u003espeed = SPEED_100;\n+\t\telse\n+\t\t\tstate-\u003espeed = SPEED_10;\n+\n+\t\tif (ret \u0026 DW_VR_MII_AN_STS_C37_ANSGM_FD)\n+\t\t\tstate-\u003eduplex = DUPLEX_FULL;\n+\t\telse\n+\t\t\tstate-\u003eduplex = DUPLEX_HALF;\n+\t} else if (ret == DW_VR_MII_AN_STS_C37_ANCMPLT_INTR) {\n+\t\tint speed, duplex;\n+\n+\t\tstate-\u003elink = true;\n+\n+\t\tspeed = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);\n+\t\tif (speed \u003c 0)\n+\t\t\treturn speed;\n+\n+\t\tspeed \u0026= BMCR_SPEED100 | BMCR_SPEED1000;\n+\t\tif (speed == BMCR_SPEED1000)\n+\t\t\tstate-\u003espeed = SPEED_1000;\n+\t\telse if (speed == BMCR_SPEED100)\n+\t\t\tstate-\u003espeed = SPEED_100;\n+\t\telse if (speed == 0)\n+\t\t\tstate-\u003espeed = SPEED_10;\n+\n+\t\tduplex = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2,\n+\t\t\t\t\t MII_ADVERTISE);\n+\t\tif (duplex \u003c 0)\n+\t\t\treturn duplex;\n+\n+\t\tif (duplex \u0026 ADVERTISE_1000XFULL)\n+\t\t\tstate-\u003eduplex = DUPLEX_FULL;\n+\t\telse if (duplex \u0026 ADVERTISE_1000XHALF)\n+\t\t\tstate-\u003eduplex = DUPLEX_HALF;\n+\n+\t\tnxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2,\n+\t\t\t\t DW_VR_MII_AN_INTR_STS, 0);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int nxp_serdes_xpcs_get_state_2500basex(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t struct phylink_link_state *state)\n+{\n+\tint ret;\n+\n+\tret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);\n+\tif (ret \u003c 0) {\n+\t\tstate-\u003elink = 0;\n+\t\treturn ret;\n+\t}\n+\n+\tstate-\u003elink = !!(ret \u0026 BMSR_LSTATUS);\n+\tif (!state-\u003elink)\n+\t\treturn 0;\n+\n+\tstate-\u003espeed = SPEED_2500;\n+\tstate-\u003epause |= MLO_PAUSE_TX | MLO_PAUSE_RX;\n+\tstate-\u003eduplex = DUPLEX_FULL;\n+\n+\treturn 0;\n+}\n+\n+static int nxp_serdes_xpcs_get_state_c37_usxgmii(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t\t struct phylink_link_state *state)\n+{\n+\tu16 usxg_an_status;\n+\tint ret;\n+\n+\tstate-\u003elink = false;\n+\tstate-\u003espeed = SPEED_UNKNOWN;\n+\tstate-\u003eduplex = DUPLEX_UNKNOWN;\n+\tstate-\u003epause = 0;\n+\n+\tret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tusxg_an_status = FIELD_GET(DW_VR_MII_USX_AN_STS_MASK, ret);\n+\tif (!(usxg_an_status \u0026 BIT(6)))\n+\t\treturn 0;\n+\n+\tstate-\u003elink = true;\n+\tstate-\u003ean_complete = true;\n+\tphylink_decode_usxgmii_word(state, usxg_an_status \u003c\u003c 7);\n+\n+\treturn 0;\n+}\n+\n+static void nxp_serdes_xpcs_get_state(struct phylink_pcs *pcs,\n+\t\t\t\t unsigned int neg_mode,\n+\t\t\t\t struct phylink_link_state *state)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tint stat1;\n+\tint ret;\n+\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, state-\u003einterface);\n+\tif (!compat)\n+\t\treturn;\n+\n+\tswitch (compat-\u003ean_mode) {\n+\tcase NXP_SERDES_10GBASER:\n+\t\tstat1 = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_PCS, MDIO_STAT1);\n+\t\tif (stat1 \u003c 0) {\n+\t\t\tstate-\u003elink = false;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (stat1 \u0026 MDIO_STAT1_FAULT)\n+\t\t\tnxp_serdes_xpcs_do_config(xpcs, state-\u003einterface, NULL,\n+\t\t\t\t\t\t PHYLINK_PCS_NEG_NONE);\n+\n+\t\tstate-\u003elink = !!(stat1 \u0026 MDIO_STAT1_LSTATUS);\n+\t\tif (state-\u003elink \u0026\u0026\n+\t\t state-\u003einterface == PHY_INTERFACE_MODE_10GBASER) {\n+\t\t\tstate-\u003espeed = SPEED_10000;\n+\t\t\tstate-\u003eduplex = DUPLEX_FULL;\n+\t\t}\n+\t\tbreak;\n+\tcase NXP_SERDES_AN_C37_USXGMII:\n+\t\tret = nxp_serdes_xpcs_get_state_c37_usxgmii(xpcs, state);\n+\t\tif (ret)\n+\t\t\tdev_err(xpcs-\u003edev, \"%s returned %pe\\n\",\n+\t\t\t\t\"nxp_serdes_xpcs_get_state_c37_usxgmii\",\n+\t\t\t\tERR_PTR(ret));\n+\t\tbreak;\n+\tcase NXP_SERDES_AN_C37_SGMII:\n+\t\tret = nxp_serdes_xpcs_get_state_c37_sgmii(xpcs, neg_mode, state);\n+\t\tif (ret)\n+\t\t\tdev_err(xpcs-\u003edev, \"%s returned %pe\\n\",\n+\t\t\t\t\"nxp_serdes_xpcs_get_state_c37_sgmii\",\n+\t\t\t\tERR_PTR(ret));\n+\t\tbreak;\n+\tcase NXP_SERDES_2500BASEX:\n+\t\tret = nxp_serdes_xpcs_get_state_2500basex(xpcs, state);\n+\t\tif (ret)\n+\t\t\tdev_err(xpcs-\u003edev, \"%s returned %pe\\n\",\n+\t\t\t\t\"nxp_serdes_xpcs_get_state_2500basex\",\n+\t\t\t\tERR_PTR(ret));\n+\t\tbreak;\n+\tdefault:\n+\t\treturn;\n+\t}\n+}\n+\n+static void nxp_serdes_xpcs_link_up_sgmii_1000basex(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t\t unsigned int neg_mode,\n+\t\t\t\t\t\t phy_interface_t interface,\n+\t\t\t\t\t\t int speed, int duplex)\n+{\n+\tint ret;\n+\n+\tif (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)\n+\t\treturn;\n+\n+\tif (interface == PHY_INTERFACE_MODE_1000BASEX) {\n+\t\tif (speed != SPEED_1000) {\n+\t\t\tdev_err(xpcs-\u003edev, \"%s: speed %dMbps not supported\\n\",\n+\t\t\t\t__func__, speed);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tif (duplex != DUPLEX_FULL)\n+\t\t\tdev_err(xpcs-\u003edev, \"%s: half duplex not supported\\n\",\n+\t\t\t\t__func__);\n+\t}\n+\n+\tret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,\n+\t\t\t\t mii_bmcr_encode_fixed(speed, duplex));\n+\tif (ret)\n+\t\tdev_err(xpcs-\u003edev, \"%s: write returned %pe\\n\",\n+\t\t\t__func__, ERR_PTR(ret));\n+}\n+\n+static void nxp_serdes_xpcs_link_up_usxgmii(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t int speed)\n+{\n+\tint ret, speed_sel;\n+\n+\tswitch (speed) {\n+\tcase SPEED_10:\n+\t\tspeed_sel = DW_USXGMII_10;\n+\t\tbreak;\n+\tcase SPEED_100:\n+\t\tspeed_sel = DW_USXGMII_100;\n+\t\tbreak;\n+\tcase SPEED_1000:\n+\t\tspeed_sel = DW_USXGMII_1000;\n+\t\tbreak;\n+\tcase SPEED_2500:\n+\t\tspeed_sel = DW_USXGMII_2500;\n+\t\tbreak;\n+\tcase SPEED_5000:\n+\t\tspeed_sel = DW_USXGMII_5000;\n+\t\tbreak;\n+\tcase SPEED_10000:\n+\t\tspeed_sel = DW_USXGMII_10000;\n+\t\tbreak;\n+\tdefault:\n+\t\treturn;\n+\t}\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_PCS, BIT(15) | MDIO_CTRL1,\n+\t\t\t\t DW_USXGMII_EN, DW_USXGMII_EN);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR,\n+\t\t\t\t DW_USXGMII_SS_MASK,\n+\t\t\t\t speed_sel | DW_USXGMII_FULL);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_PCS, BIT(15) | MDIO_CTRL1,\n+\t\t\t\t DW_USXGMII_RST, DW_USXGMII_RST);\n+\tif (ret \u003c 0)\n+\t\tgoto out;\n+\n+\treturn;\n+\n+out:\n+\tdev_err(xpcs-\u003edev, \"%s: XPCS access returned %pe\\n\",\n+\t\t__func__, ERR_PTR(ret));\n+}\n+\n+static void nxp_serdes_xpcs_link_up(struct phylink_pcs *pcs,\n+\t\t\t\t unsigned int neg_mode,\n+\t\t\t\t phy_interface_t interface, int speed,\n+\t\t\t\t int duplex)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tint ret;\n+\n+\tswitch (interface) {\n+\tcase PHY_INTERFACE_MODE_USXGMII:\n+\t\tnxp_serdes_xpcs_link_up_usxgmii(xpcs, speed);\n+\t\tbreak;\n+\n+\tcase PHY_INTERFACE_MODE_SGMII:\n+\tcase PHY_INTERFACE_MODE_1000BASEX:\n+\t\tnxp_serdes_xpcs_link_up_sgmii_1000basex(xpcs, neg_mode,\n+\t\t\t\t\t\t\tinterface, speed,\n+\t\t\t\t\t\t\tduplex);\n+\t\tbreak;\n+\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tcompat = nxp_serdes_xpcs_find_compat(xpcs, interface);\n+\tif (compat \u0026\u0026 compat-\u003epma_link_up) {\n+\t\tret = compat-\u003epma_link_up(xpcs, speed, duplex);\n+\t\tif (ret)\n+\t\t\tdev_err(xpcs-\u003edev, \"%s: pma_link_up returned %pe\\n\",\n+\t\t\t\t__func__, ERR_PTR(ret));\n+\t}\n+}\n+\n+static void nxp_serdes_xpcs_an_restart(struct phylink_pcs *pcs)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\tnxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,\n+\t\t\t BMCR_ANRESTART);\n+}\n+\n+static int nxp_serdes_xpcs_config_eee(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t bool enable)\n+{\n+\tu16 mask, val;\n+\tint ret;\n+\n+\tmask = DW_VR_MII_EEE_LTX_EN | DW_VR_MII_EEE_LRX_EN |\n+\t DW_VR_MII_EEE_TX_QUIET_EN | DW_VR_MII_EEE_RX_QUIET_EN |\n+\t DW_VR_MII_EEE_TX_EN_CTRL | DW_VR_MII_EEE_RX_EN_CTRL |\n+\t DW_VR_MII_EEE_MULT_FACT_100NS;\n+\n+\tif (enable)\n+\t\tval = DW_VR_MII_EEE_LTX_EN | DW_VR_MII_EEE_LRX_EN |\n+\t\t DW_VR_MII_EEE_TX_QUIET_EN | DW_VR_MII_EEE_RX_QUIET_EN |\n+\t\t DW_VR_MII_EEE_TX_EN_CTRL | DW_VR_MII_EEE_RX_EN_CTRL |\n+\t\t /* No platform needs a non-default multiply factor */\n+\t\t FIELD_PREP(DW_VR_MII_EEE_MULT_FACT_100NS, 0);\n+\telse\n+\t\tval = 0;\n+\n+\tret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2,\n+\t\t\t\t DW_VR_MII_EEE_MCTRL0, mask, val);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\n+\treturn nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2,\n+\t\t\t\t DW_VR_MII_EEE_MCTRL1,\n+\t\t\t\t DW_VR_MII_EEE_TRN_LPI,\n+\t\t\t\t enable ? DW_VR_MII_EEE_TRN_LPI : 0);\n+}\n+\n+static void nxp_serdes_xpcs_disable_eee(struct phylink_pcs *pcs)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\tif (xpcs-\u003edesc-\u003equirks \u0026 NXP_SERDES_QUIRK_NO_EEE)\n+\t\treturn;\n+\n+\tnxp_serdes_xpcs_config_eee(xpcs, false);\n+}\n+\n+static void nxp_serdes_xpcs_enable_eee(struct phylink_pcs *pcs)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\tif (xpcs-\u003edesc-\u003equirks \u0026 NXP_SERDES_QUIRK_NO_EEE)\n+\t\treturn;\n+\n+\tnxp_serdes_xpcs_config_eee(xpcs, true);\n+}\n+\n+static const struct phylink_pcs_ops nxp_serdes_xpcs_phylink_ops = {\n+\t.pcs_validate = nxp_serdes_xpcs_validate,\n+\t.pcs_inband_caps = nxp_serdes_xpcs_inband_caps,\n+\t.pcs_pre_config = nxp_serdes_xpcs_pre_config,\n+\t.pcs_disable = nxp_serdes_xpcs_disable,\n+\t.pcs_config = nxp_serdes_xpcs_config,\n+\t.pcs_get_state = nxp_serdes_xpcs_get_state,\n+\t.pcs_an_restart = nxp_serdes_xpcs_an_restart,\n+\t.pcs_link_up = nxp_serdes_xpcs_link_up,\n+\t.pcs_disable_eee = nxp_serdes_xpcs_disable_eee,\n+\t.pcs_enable_eee = nxp_serdes_xpcs_enable_eee,\n+};\n+\n+/**\n+ * nxp_serdes_xpcs_create() - create a NXP SerDes XPCS phylink PCS\n+ * @dev: device the PCS belongs to, used for error reporting\n+ * @xpcs_regmap: regmap of the XPCS registers\n+ * @phy_regmap: regmap of the XPCS-PHY registers, may be NULL\n+ * @desc: revision descriptor, see \u0026struct nxp_serdes_xpcs_desc\n+ * @portid: index of the XPCS port, used to select the shared MPLL\n+ * @interface: PHY interface mode used for the link\n+ *\n+ * The regmaps must stay valid until nxp_serdes_xpcs_destroy() has been called.\n+ *\n+ * Return: a pointer to a \u0026struct phylink_pcs, or an ERR_PTR() on failure.\n+ */\n+struct phylink_pcs *nxp_serdes_xpcs_create(struct device *dev,\n+\t\t\t\t\t struct regmap *xpcs_regmap,\n+\t\t\t\t\t struct regmap *phy_regmap,\n+\t\t\t\t\t const struct nxp_serdes_xpcs_desc *desc,\n+\t\t\t\t\t u8 portid, phy_interface_t interface)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs;\n+\n+\tif (!desc || !desc-\u003ecompat)\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\txpcs = kzalloc_obj(struct nxp_serdes_xpcs, GFP_KERNEL);\n+\tif (!xpcs)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\txpcs-\u003edev = dev;\n+\txpcs-\u003expcs_regmap = xpcs_regmap;\n+\txpcs-\u003ephy_regmap = phy_regmap;\n+\txpcs-\u003edesc = desc;\n+\txpcs-\u003epma_id = desc-\u003epma_id;\n+\txpcs-\u003eportid = portid;\n+\txpcs-\u003einterface = interface;\n+\txpcs-\u003epcs.ops = \u0026nxp_serdes_xpcs_phylink_ops;\n+\txpcs-\u003epcs.poll = true;\n+\tnxp_serdes_xpcs_get_interfaces(xpcs, xpcs-\u003epcs.supported_interfaces);\n+\txpcs-\u003eneed_reset = true;\n+\n+\treturn \u0026xpcs-\u003epcs;\n+}\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_create);\n+\n+void nxp_serdes_xpcs_destroy(struct phylink_pcs *pcs)\n+{\n+\tstruct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);\n+\n+\tif (!xpcs)\n+\t\treturn;\n+\n+\tkfree(xpcs);\n+}\n+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_destroy);\n+\n+MODULE_DESCRIPTION(\"NXP SerDes XPCS shared core\");\n+MODULE_AUTHOR(\"Clark Wang \u003cxiaoning.wang@nxp.com\u003e\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig\nindex 7557b624be8fc..59a86597eaa0b 100644\n--- a/drivers/phy/freescale/Kconfig\n+++ b/drivers/phy/freescale/Kconfig\n@@ -77,3 +77,12 @@ config PHY_FSL_LYNX_28G\n \t found on NXP's Layerscape platforms such as LX2160A.\n \t Used to change the protocol running on SerDes lanes at runtime.\n \t Only useful for a restricted set of Ethernet protocols.\n+\n+config PHY_S32G_SERDES\n+\ttristate \"NXP S32G SERDES support\"\n+\tdepends on ARCH_S32 || COMPILE_TEST\n+\tdepends on PCS_NXP_S32G_XPCS\n+\tselect GENERIC_PHY\n+\thelp\n+\t This option enables support for S32G SerDes PHY used for\n+\t PCIe \u0026 Ethernet\ndiff --git a/drivers/phy/freescale/Makefile b/drivers/phy/freescale/Makefile\nindex 5b0e180d6972f..1a0aec7909178 100644\n--- a/drivers/phy/freescale/Makefile\n+++ b/drivers/phy/freescale/Makefile\n@@ -8,3 +8,4 @@ obj-$(CONFIG_PHY_FSL_LYNX_CORE)\t\t+= phy-fsl-lynx-core.o\n obj-$(CONFIG_PHY_FSL_LYNX_10G)\t\t+= phy-fsl-lynx-10g.o\n obj-$(CONFIG_PHY_FSL_LYNX_28G)\t\t+= phy-fsl-lynx-28g.o\n obj-$(CONFIG_PHY_FSL_SAMSUNG_HDMI_PHY)\t+= phy-fsl-samsung-hdmi.o\n+obj-$(CONFIG_PHY_S32G_SERDES)\t\t+= phy-nxp-s32g-serdes.o\ndiff --git a/drivers/phy/freescale/phy-nxp-s32g-serdes.c b/drivers/phy/freescale/phy-nxp-s32g-serdes.c\nnew file mode 100644\nindex 0000000000000..e81878137f2e1\n--- /dev/null\n+++ b/drivers/phy/freescale/phy-nxp-s32g-serdes.c\n@@ -0,0 +1,1057 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * SerDes driver for S32G SoCs\n+ *\n+ * Copyright 2021-2026 NXP\n+ */\n+\n+#include \u003clinux/bitfield.h\u003e\n+#include \u003clinux/clk.h\u003e\n+#include \u003clinux/delay.h\u003e\n+#include \u003clinux/iopoll.h\u003e\n+#include \u003clinux/module.h\u003e\n+#include \u003clinux/of_platform.h\u003e\n+#include \u003clinux/pcs/pcs-nxp-s32g-xpcs.h\u003e\n+#include \u003clinux/phy/nxp-s32g-serdes.h\u003e\n+#include \u003clinux/phy/phy.h\u003e\n+#include \u003clinux/platform_device.h\u003e\n+#include \u003clinux/reset.h\u003e\n+#include \u003clinux/units.h\u003e\n+\n+#define S32G_SERDES_XPCS_MAX\t\t\t2\n+\n+#define EXTERNAL_CLK_NAME\t\t\t\"ext\"\n+#define INTERNAL_CLK_NAME\t\t\t\"ref\"\n+\n+/* Serdes Sub system registers */\n+\n+#define S32G_PCIE_PHY_GEN_CTRL\t\t\t0x0\n+#define REF_USE_PAD\t\t\t\tBIT(17)\n+#define RX_SRIS_MODE\t\t\t\tBIT(9)\n+\n+#define S32G_PCIE_PHY_MPLLA_CTRL\t\t0x10\n+#define MPLL_STATE\t\t\t\tBIT(30)\n+\n+#define S32G_SS_RW_REG_0\t\t\t0xF0\n+#define SUBMODE_MASK\t\t\t\tGENMASK(2, 0)\n+#define CLKEN_MASK\t\t\t\tBIT(23)\n+#define PHY0_CR_PARA_SEL\t\t\tBIT(9)\n+\n+/* PCIe phy subsystem registers */\n+\n+#define S32G_PHY_REG_ADDR\t\t\t0x0\n+#define PHY_REG_EN\t\t\t\tBIT(31)\n+\n+#define S32G_PHY_REG_DATA\t\t\t0x4\n+\n+#define RAWLANE0_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN\t0x3019\n+#define RAWLANE1_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN\t0x3119\n+\n+/*\n+ * DesignWare PCIe PHY reference-clock architecture, passed as the submode\n+ * to phy_set_mode_ext(phy, PHY_MODE_PCIE, submode).\n+ *\n+ * These describe how the reference clock is distributed and whether spread\n+ * spectrum is used, a different axis from the role submodes in\n+ * include/linux/phy/pcie.h (PHY_MODE_PCIE_RC/_EP/_BIFURCATION, 20..22), which\n+ * they do not overlap. Kept driver-private until a second driver needs a\n+ * non-default architecture; pcie-nxp-s32g.c always asks for CRNS.\n+ */\n+enum pcie_phy_mode {\n+\tCRNS = 0, /* Common Reference Clock, No Spread Spectrum */\n+\tCRSS = 1, /* Common Reference Clock, Spread Spectrum */\n+\tSRNS = 2, /* Separate Reference Clock, No Spread Spectrum */\n+\tSRIS = 3 /* Separate Reference Clock, Spread Spectrum */\n+};\n+\n+/*\n+ * SS_RW_REG_0[SUBSYS_MODE] holds the reference-manual \"Mode N\" number. It is\n+ * not in the devicetree: it is derived from the per-lane child nodes (lane\n+ * function + XPCS instance). The reference clock is validated against the\n+ * result, never used to select it.\n+ */\n+\n+enum s32g_lane_fn {\n+\tS32G_LANE_UNUSED = 0,\n+\tS32G_LANE_PCIE,\n+\tS32G_LANE_XPCS,\n+};\n+\n+struct s32g_lane_desc {\n+\tenum s32g_lane_fn fn;\n+\tu32 xpcs_instance;\t/* valid iff fn == S32G_LANE_XPCS */\n+};\n+\n+struct s32g_serdes_mode {\n+\tu32 submode;\t\t\t/* SS_RW_REG_0[SUBSYS_MODE] value */\n+\tstruct s32g_lane_desc lane[2];\n+\tunsigned long refclk[2];\t/* permitted reference clock rates (Hz), 0-terminated */\n+};\n+\n+struct s32g_serdes_soc_data {\n+\tconst struct s32g_serdes_mode *modes;\n+\tunsigned int n_modes;\n+};\n+\n+#define S32G_LANE_IS_PCIE\t{ .fn = S32G_LANE_PCIE }\n+#define S32G_LANE_IS_XPCS(i)\t{ .fn = S32G_LANE_XPCS, .xpcs_instance = (i) }\n+\n+#define S32G_REFCLK_100MHZ\t(100 * HZ_PER_MHZ)\n+#define S32G_REFCLK_125MHZ\t(125 * HZ_PER_MHZ)\n+\n+/*\n+ * Supported working modes (S32G2/S32G3, 1G). Each row has a unique lane mux.\n+ * PCIe needs a 100 MHz reference, so modes 0/1/2 take 100 MHz only; the\n+ * dual-XPCS mode 3 takes 100 or 125 MHz.\n+ */\n+static const struct s32g_serdes_mode s32g_serdes_modes[] = {\n+\t{ 0, { S32G_LANE_IS_PCIE, S32G_LANE_IS_PCIE },\n+\t { S32G_REFCLK_100MHZ } },\n+\t{ 1, { S32G_LANE_IS_PCIE, S32G_LANE_IS_XPCS(0) },\n+\t { S32G_REFCLK_100MHZ } },\n+\t{ 2, { S32G_LANE_IS_PCIE, S32G_LANE_IS_XPCS(1) },\n+\t { S32G_REFCLK_100MHZ } },\n+\t{ 3, { S32G_LANE_IS_XPCS(0), S32G_LANE_IS_XPCS(1) },\n+\t { S32G_REFCLK_100MHZ, S32G_REFCLK_125MHZ } },\n+};\n+\n+/*\n+ * S32G2 and S32G3 share this table for now but keep distinct compatibles with\n+ * no fallback: the full RM mode tables differ per SoC and per SerDes instance\n+ * (only S32G3 SerDes_1 has the 3.125G dual-XPCS mode 4) and will diverge once\n+ * 2500BASE-X lands.\n+ */\n+static const struct s32g_serdes_soc_data s32g2_serdes_soc_data = {\n+\t.modes = s32g_serdes_modes,\n+\t.n_modes = ARRAY_SIZE(s32g_serdes_modes),\n+};\n+\n+static const struct s32g_serdes_soc_data s32g3_serdes_soc_data = {\n+\t.modes = s32g_serdes_modes,\n+\t.n_modes = ARRAY_SIZE(s32g_serdes_modes),\n+};\n+\n+struct s32g_serdes_ctrl {\n+\tvoid __iomem *ss_base;\n+\tstruct reset_control *rst;\n+\tstruct clk_bulk_data *clks;\n+\tint nclks;\n+\tu32 ss_mode;\n+\tunsigned long ref_clk_rate;\n+\tbool ext_clk;\n+};\n+\n+struct s32g_pcie_ctrl {\n+\tvoid __iomem *phy_base;\n+\tstruct reset_control *rst;\n+\tstruct phy *phy;\n+\tenum pcie_phy_mode phy_mode;\n+\tbool powered_on;\n+};\n+\n+struct s32g_xpcs_ctrl {\n+\tstruct s32g_xpcs *phys[2];\t/* indexed by XPCS instance */\n+\tvoid __iomem *base[2];\t\t/* xpcs0 / xpcs1 register blocks */\n+};\n+\n+struct s32g_serdes {\n+\tstruct s32g_serdes_ctrl ctrl;\n+\tstruct s32g_pcie_ctrl pcie;\n+\tstruct s32g_xpcs_ctrl xpcs;\n+\tstruct s32g_lane_desc lane[2];\n+\tconst struct s32g_serdes_soc_data *soc_data;\n+\tstruct device *dev;\n+};\n+\n+/* PCIe phy subsystem */\n+\n+#define S32G_SERDES_PCIE_FREQ\t\t\t(100 * HZ_PER_MHZ)\n+\n+static int s32g_pcie_check_clk(struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_serdes_ctrl *sctrl = \u0026serdes-\u003ectrl;\n+\tunsigned long rate = sctrl-\u003eref_clk_rate;\n+\n+\tif (rate != S32G_SERDES_PCIE_FREQ) {\n+\t\tdev_err(serdes-\u003edev, \"PCIe PHY cannot operate at %lu HZ\\n\", rate);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/* Serdes RM says the PHY is operational within 3.4 to 5.2 ms after reset\n+ * release, depending on the reference clock (MPLL_STATE = 1).\n+ */\n+#define S32G_SERDES_LOCK_TIMEOUT_US\t(10 * USEC_PER_MSEC)\n+#define S32G_SERDES_LOCK_SLEEP_US\t50\n+\n+/*\n+ * MPLL_STATE signals \"PHY operational\" after the subsystem reset is released.\n+ * It must be observed before any PHY or XPCS PMA access in every mode, not\n+ * just on the PCIe path: skipping it on the XPCS-only modes left init\n+ * dependent on incidental timing, and a printk between reset release and XPCS\n+ * setup was enough to break it.\n+ */\n+static int s32g_serdes_wait_phy_operational(struct s32g_serdes *serdes)\n+{\n+\tvoid __iomem *reg = serdes-\u003ectrl.ss_base + S32G_PCIE_PHY_MPLLA_CTRL;\n+\tu32 val;\n+\tint ret;\n+\n+\tret = readl_poll_timeout(reg, val, (val \u0026 MPLL_STATE),\n+\t\t\t\t S32G_SERDES_LOCK_SLEEP_US,\n+\t\t\t\t S32G_SERDES_LOCK_TIMEOUT_US);\n+\tif (ret)\n+\t\tdev_err(serdes-\u003edev, \"SerDes PHY not operational\\n\");\n+\n+\treturn ret;\n+}\n+\n+static int s32g_pcie_phy_power_on_common(struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_serdes_ctrl *sctrl = \u0026serdes-\u003ectrl;\n+\tstruct s32g_pcie_ctrl *pcie = \u0026serdes-\u003epcie;\n+\tu32 reg;\n+\tint ret;\n+\n+\tret = s32g_pcie_check_clk(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\treg = readl(sctrl-\u003ess_base + S32G_PCIE_PHY_GEN_CTRL);\n+\n+\tif (pcie-\u003ephy_mode == SRIS)\n+\t\treg |= RX_SRIS_MODE;\n+\telse\n+\t\treg \u0026= ~RX_SRIS_MODE;\n+\n+\tif (sctrl-\u003eext_clk)\n+\t\treg |= REF_USE_PAD;\n+\telse\n+\t\treg \u0026= ~REF_USE_PAD;\n+\n+\twritel(reg, sctrl-\u003ess_base + S32G_PCIE_PHY_GEN_CTRL);\n+\n+\tret = s32g_serdes_wait_phy_operational(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* Set PHY register access to CR interface */\n+\treg = readl(sctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\treg |= PHY0_CR_PARA_SEL;\n+\twritel(reg, sctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\n+\treturn 0;\n+}\n+\n+static void s32g_pcie_phy_write(struct s32g_serdes *serdes, u32 reg, u32 val)\n+{\n+\twritel(PHY_REG_EN, serdes-\u003epcie.phy_base + S32G_PHY_REG_ADDR);\n+\twritel(reg | PHY_REG_EN, serdes-\u003epcie.phy_base + S32G_PHY_REG_ADDR);\n+\tusleep_range(100, 110);\n+\twritel(val, serdes-\u003epcie.phy_base + S32G_PHY_REG_DATA);\n+\tusleep_range(100, 110);\n+\twritel(0, serdes-\u003epcie.phy_base + S32G_PHY_REG_ADDR);\n+}\n+\n+static int s32g_pcie_phy_power_on(struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_pcie_ctrl *pcie = \u0026serdes-\u003epcie;\n+\tstruct s32g_serdes_ctrl *ctrl = \u0026serdes-\u003ectrl;\n+\tu32 iq_ovrd_in;\n+\tint ret;\n+\n+\tret = s32g_pcie_phy_power_on_common(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/* RX_EQ_DELTA_IQ_OVRD enable and override value for PCIe lanes */\n+\tiq_ovrd_in = RAWLANE0_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN;\n+\n+\ts32g_pcie_phy_write(serdes, iq_ovrd_in, 0x3);\n+\ts32g_pcie_phy_write(serdes, iq_ovrd_in, 0x13);\n+\n+\tif (ctrl-\u003ess_mode == 0) {\n+\t\tiq_ovrd_in = RAWLANE1_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN;\n+\n+\t\ts32g_pcie_phy_write(serdes, iq_ovrd_in, 0x3);\n+\t\ts32g_pcie_phy_write(serdes, iq_ovrd_in, 0x13);\n+\t}\n+\n+\tpcie-\u003epowered_on = true;\n+\n+\treturn 0;\n+}\n+\n+/* PCIe phy ops function */\n+\n+static int s32g_serdes_phy_power_on(struct phy *p)\n+{\n+\tstruct s32g_serdes *serdes = phy_get_drvdata(p);\n+\n+\treturn s32g_pcie_phy_power_on(serdes);\n+}\n+\n+static int s32g_serdes_phy_power_off(struct phy *p)\n+{\n+\tstruct s32g_serdes *serdes = phy_get_drvdata(p);\n+\n+\tserdes-\u003epcie.powered_on = false;\n+\n+\treturn 0;\n+}\n+\n+static inline bool is_pcie_phy_mode_valid(int mode)\n+{\n+\tswitch (mode) {\n+\tcase CRNS:\n+\tcase CRSS:\n+\tcase SRNS:\n+\tcase SRIS:\n+\t\treturn true;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n+static int s32g_serdes_phy_set_mode_ext(struct phy *p,\n+\t\t\t\t\tenum phy_mode mode, int submode)\n+{\n+\tstruct s32g_serdes *serdes = phy_get_drvdata(p);\n+\n+\tif (mode != PHY_MODE_PCIE)\n+\t\treturn -EINVAL;\n+\n+\tif (!is_pcie_phy_mode_valid(submode))\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * Spread-spectrum and common-reference clocking both need an\n+\t * external shared reference, and neither may be combined with an\n+\t * SGMII lane on the same subsystem.\n+\t */\n+\tif ((submode == CRSS || submode == SRIS) \u0026\u0026\n+\t (serdes-\u003ectrl.ss_mode != 0 || !serdes-\u003ectrl.ext_clk))\n+\t\treturn -EINVAL;\n+\n+\tif (serdes-\u003epcie.powered_on)\n+\t\tdev_warn(serdes-\u003edev, \"The phy is already powered on.\\n\");\n+\n+\tserdes-\u003epcie.phy_mode = submode;\n+\n+\treturn 0;\n+}\n+\n+static const struct phy_ops serdes_pcie_ops = {\n+\t.power_on\t= s32g_serdes_phy_power_on,\n+\t.power_off\t= s32g_serdes_phy_power_off,\n+\t.set_mode\t= s32g_serdes_phy_set_mode_ext,\n+};\n+\n+static struct phy *s32g_serdes_phy_xlate(struct device *dev,\n+\t\t\t\t\t const struct of_phandle_args *args)\n+{\n+\tstruct s32g_serdes *serdes;\n+\n+\tserdes = dev_get_drvdata(dev);\n+\tif (!serdes)\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\treturn serdes-\u003epcie.phy;\n+}\n+\n+/* XPCS subsystem */\n+\n+static int s32g_serdes_xpcs_setup(struct s32g_serdes *serdes, u32 instance)\n+{\n+\tstruct s32g_serdes_ctrl *ctrl = \u0026serdes-\u003ectrl;\n+\tstruct s32g_xpcs_ctrl *xpcs_ctrl = \u0026serdes-\u003expcs;\n+\tenum s32g_xpcs_shared shared = S32G_NOT_SHARED;\n+\tstruct device *dev = serdes-\u003edev;\n+\tstruct s32g_xpcs *xpcs;\n+\n+\t/*\n+\t * In the PCIe + SGMII modes the XPCS shares the combo PHY with the\n+\t * PCIe lane. The 2.5G shared variant (S32G_PCIE_XPCS_2G5) is selected at\n+\t * run time and is not wired up yet.\n+\t */\n+\tif (ctrl-\u003ess_mode == 1 || ctrl-\u003ess_mode == 2)\n+\t\tshared = S32G_PCIE_XPCS_1G;\n+\n+\txpcs = s32g_xpcs_create(dev, instance, xpcs_ctrl-\u003ebase[instance],\n+\t\t\t\tctrl-\u003eext_clk, ctrl-\u003eref_clk_rate, shared);\n+\tif (IS_ERR(xpcs))\n+\t\treturn PTR_ERR(xpcs);\n+\n+\txpcs_ctrl-\u003ephys[instance] = xpcs;\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_init_xpcs(struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_serdes_ctrl *ctrl = \u0026serdes-\u003ectrl;\n+\tstruct s32g_xpcs_ctrl *xpcs = \u0026serdes-\u003expcs;\n+\tstruct s32g_xpcs *order[2];\n+\tsize_t i;\n+\tint ret;\n+\n+\t/*\n+\t * Mode 3 initialises XPCS1 before XPCS0. Carried over from the vendor\n+\t * driver and undocumented in the RM. Do not reorder.\n+\t */\n+\tswitch (ctrl-\u003ess_mode) {\n+\tcase 0:\n+\t\treturn 0;\n+\tcase 1:\n+\t\torder[0] = xpcs-\u003ephys[0];\n+\t\torder[1] = NULL;\n+\t\tbreak;\n+\tcase 2:\n+\t\torder[0] = xpcs-\u003ephys[1];\n+\t\torder[1] = NULL;\n+\t\tbreak;\n+\tcase 3:\n+\t\torder[0] = xpcs-\u003ephys[1];\n+\t\torder[1] = xpcs-\u003ephys[0];\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(order); i++) {\n+\t\tif (!order[i])\n+\t\t\tcontinue;\n+\n+\t\tret = s32g_xpcs_init_plls(order[i]);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(order); i++) {\n+\t\tif (!order[i])\n+\t\t\tcontinue;\n+\n+\t\ts32g_xpcs_vreset(order[i]);\n+\t}\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(order); i++) {\n+\t\tif (!order[i])\n+\t\t\tcontinue;\n+\n+\t\tret = s32g_xpcs_wait_vreset(order[i]);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\tret = s32g_xpcs_reset_rx(order[i]);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\ts32g_xpcs_disable_an(order[i]);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/* Serdes subsystem */\n+\n+static int s32g_serdes_assert_reset(struct s32g_serdes *serdes)\n+{\n+\tstruct device *dev = serdes-\u003edev;\n+\tint ret;\n+\n+\tret = reset_control_assert(serdes-\u003epcie.rst);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Failed to assert PCIE reset: %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\tret = reset_control_assert(serdes-\u003ectrl.rst);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Failed to assert SerDes reset: %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_deassert_reset(struct s32g_serdes *serdes)\n+{\n+\tstruct device *dev = serdes-\u003edev;\n+\tint ret;\n+\n+\tret = reset_control_deassert(serdes-\u003epcie.rst);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Failed to deassert PCIE reset: %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\tret = reset_control_deassert(serdes-\u003ectrl.rst);\n+\tif (ret) {\n+\t\tdev_err(dev, \"Failed to deassert SerDes reset: %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static bool s32g_serdes_lane_matches(const struct s32g_lane_desc *mode_lane,\n+\t\t\t\t const struct s32g_lane_desc *req_lane)\n+{\n+\tif (mode_lane-\u003efn != req_lane-\u003efn)\n+\t\treturn false;\n+\n+\tif (mode_lane-\u003efn == S32G_LANE_XPCS)\n+\t\treturn mode_lane-\u003expcs_instance == req_lane-\u003expcs_instance;\n+\n+\treturn true;\n+}\n+\n+static const char *s32g_lane_fn_str(const struct s32g_lane_desc *lane)\n+{\n+\tswitch (lane-\u003efn) {\n+\tcase S32G_LANE_PCIE:\n+\t\treturn \"PCIe\";\n+\tcase S32G_LANE_XPCS:\n+\t\treturn lane-\u003expcs_instance ? \"XPCS1\" : \"XPCS0\";\n+\tdefault:\n+\t\treturn \"unused\";\n+\t}\n+}\n+\n+static int s32g_serdes_derive_mode(struct s32g_serdes *serdes)\n+{\n+\tconst struct s32g_serdes_mode *match = NULL;\n+\tunsigned int i;\n+\tbool refclk_ok = false;\n+\n+\tfor (i = 0; i \u003c serdes-\u003esoc_data-\u003en_modes; i++) {\n+\t\tconst struct s32g_serdes_mode *m = \u0026serdes-\u003esoc_data-\u003emodes[i];\n+\n+\t\tif (s32g_serdes_lane_matches(\u0026m-\u003elane[0], \u0026serdes-\u003elane[0]) \u0026\u0026\n+\t\t s32g_serdes_lane_matches(\u0026m-\u003elane[1], \u0026serdes-\u003elane[1])) {\n+\t\t\tmatch = m;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!match)\n+\t\treturn dev_err_probe(serdes-\u003edev, -EINVAL,\n+\t\t\t\t \"No SerDes mode matches the lane configuration\\n\");\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(match-\u003erefclk) \u0026\u0026 match-\u003erefclk[i]; i++) {\n+\t\tif (serdes-\u003ectrl.ref_clk_rate == match-\u003erefclk[i]) {\n+\t\t\trefclk_ok = true;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!refclk_ok)\n+\t\treturn dev_err_probe(serdes-\u003edev, -EINVAL,\n+\t\t\t\t \"Reference clock %lu Hz invalid for mode %u\\n\",\n+\t\t\t\t serdes-\u003ectrl.ref_clk_rate, match-\u003esubmode);\n+\n+\tserdes-\u003ectrl.ss_mode = match-\u003esubmode;\n+\n+\tdev_dbg(serdes-\u003edev,\n+\t\t\"SerDes mode %u selected: lane0=%s lane1=%s, ref-clk %lu MHz (%s)\\n\",\n+\t\tmatch-\u003esubmode,\n+\t\ts32g_lane_fn_str(\u0026serdes-\u003elane[0]),\n+\t\ts32g_lane_fn_str(\u0026serdes-\u003elane[1]),\n+\t\tserdes-\u003ectrl.ref_clk_rate / HZ_PER_MHZ,\n+\t\tserdes-\u003ectrl.ext_clk ? \"external\" : \"internal\");\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_init(struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_serdes_ctrl *ctrl = \u0026serdes-\u003ectrl;\n+\tu32 reg0;\n+\tint ret;\n+\n+\tret = clk_bulk_prepare_enable(ctrl-\u003enclks, ctrl-\u003eclks);\n+\tif (ret) {\n+\t\tdev_err(serdes-\u003edev, \"Failed to enable SerDes clocks\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tret = s32g_serdes_assert_reset(serdes);\n+\tif (ret)\n+\t\tgoto disable_clks;\n+\n+\t/* Set serdes mode */\n+\treg0 = readl(ctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\treg0 \u0026= ~SUBMODE_MASK;\n+\treg0 |= FIELD_PREP(SUBMODE_MASK, ctrl-\u003ess_mode);\n+\twritel(reg0, ctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\n+\t/* Set Clock source: internal or external */\n+\treg0 = readl(ctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\tif (ctrl-\u003eext_clk)\n+\t\treg0 \u0026= ~CLKEN_MASK;\n+\telse\n+\t\treg0 |= CLKEN_MASK;\n+\n+\twritel(reg0, ctrl-\u003ess_base + S32G_SS_RW_REG_0);\n+\n+\t/*\n+\t * Route the combo-PHY reference: REF_USE_PAD is 0 for the internal\n+\t * reference, 1 for the external pad. s32g_pcie_phy_power_on_common()\n+\t * programs it too, but the XPCS lane is brought up before any PCIe\n+\t * power-on. Left at the bootloader default the XPCS PMA never powers\n+\t * up, VR_RST never self-clears and every register reads back constant.\n+\t */\n+\treg0 = readl(ctrl-\u003ess_base + S32G_PCIE_PHY_GEN_CTRL);\n+\tif (ctrl-\u003eext_clk)\n+\t\treg0 |= REF_USE_PAD;\n+\telse\n+\t\treg0 \u0026= ~REF_USE_PAD;\n+\twritel(reg0, ctrl-\u003ess_base + S32G_PCIE_PHY_GEN_CTRL);\n+\tdev_dbg(serdes-\u003edev,\n+\t\t\"GEN_CTRL after ref-clk route: 0x%08x (REF_USE_PAD=%d)\\n\",\n+\t\treg0, !!(reg0 \u0026 REF_USE_PAD));\n+\n+\t/* Wait for the selection of working mode (as per the manual specs) */\n+\tusleep_range(100, 110);\n+\n+\tret = s32g_serdes_deassert_reset(serdes);\n+\tif (ret)\n+\t\tgoto disable_clks;\n+\n+\t/*\n+\t * The PHY needs up to 5.2 ms after reset release to become\n+\t * operational. Nothing may touch the PHY or the XPCS PMA before\n+\t * that point.\n+\t */\n+\tret = s32g_serdes_wait_phy_operational(serdes);\n+\tif (ret)\n+\t\tgoto disable_clks;\n+\n+\tret = s32g_serdes_init_xpcs(serdes);\n+\tif (ret) {\n+\t\tdev_err(serdes-\u003edev, \"XPCS init failed\\n\");\n+\t\tgoto disable_clks;\n+\t}\n+\n+\tdev_info(serdes-\u003edev, \"SerDes subsystem mode %u (refclk=%lu MHz)\\n\",\n+\t\t ctrl-\u003ess_mode, ctrl-\u003eref_clk_rate / HZ_PER_MHZ);\n+\n+\treturn 0;\n+\n+disable_clks:\n+\t/* Already on an error path; ignore the return value. */\n+\ts32g_serdes_assert_reset(serdes);\n+\tclk_bulk_disable_unprepare(serdes-\u003ectrl.nclks,\n+\t\t\t\t serdes-\u003ectrl.clks);\n+\n+\treturn ret;\n+}\n+\n+static void s32g_serdes_disable(void *data)\n+{\n+\tstruct s32g_serdes *serdes = data;\n+\n+\ts32g_serdes_assert_reset(serdes);\n+\tclk_bulk_disable_unprepare(serdes-\u003ectrl.nclks, serdes-\u003ectrl.clks);\n+}\n+\n+static int s32g_serdes_get_ctrl_resources(struct platform_device *pdev,\n+\t\t\t\t\t struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_serdes_ctrl *ctrl = \u0026serdes-\u003ectrl;\n+\tstruct device *dev = \u0026pdev-\u003edev;\n+\tint ret, idx, i;\n+\n+\tctrl-\u003ess_base = devm_platform_ioremap_resource_byname(pdev, \"ss-pcie\");\n+\tif (IS_ERR(ctrl-\u003ess_base))\n+\t\treturn dev_err_probe(dev, PTR_ERR(ctrl-\u003ess_base),\n+\t\t\t\t \"Failed to map 'ss-pcie'\\n\");\n+\n+\tctrl-\u003erst = devm_reset_control_get_exclusive(dev, \"serdes\");\n+\tif (IS_ERR(ctrl-\u003erst))\n+\t\treturn dev_err_probe(dev, PTR_ERR(ctrl-\u003erst),\n+\t\t\t\t \"Failed to get 'serdes' reset control\\n\");\n+\n+\tctrl-\u003enclks = devm_clk_bulk_get_all(dev, \u0026ctrl-\u003eclks);\n+\tif (ctrl-\u003enclks \u003c 1) {\n+\t\tret = ctrl-\u003enclks ? : -EINVAL;\n+\t\treturn dev_err_probe(dev, ret,\n+\t\t\t\t \"Failed to get SerDes clocks\\n\");\n+\t}\n+\n+\tidx = -1;\n+\tfor (i = 0; i \u003c ctrl-\u003enclks; i++) {\n+\t\tif (!ctrl-\u003eclks[i].id)\n+\t\t\tcontinue;\n+\n+\t\tif (!strcmp(ctrl-\u003eclks[i].id, EXTERNAL_CLK_NAME)) {\n+\t\t\tidx = i;\n+\t\t\tctrl-\u003eext_clk = true;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (!strcmp(ctrl-\u003eclks[i].id, INTERNAL_CLK_NAME))\n+\t\t\tidx = i;\n+\t}\n+\n+\tif (idx \u003c 0) {\n+\t\tdev_err(dev, \"Failed to get Phy reference clock source\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tctrl-\u003eref_clk_rate = clk_get_rate(ctrl-\u003eclks[idx].clk);\n+\tif (!ctrl-\u003eref_clk_rate) {\n+\t\tdev_err(dev, \"Failed to get Phy reference clock rate\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_get_pcie_resources(struct platform_device *pdev,\n+\t\t\t\t\t struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_pcie_ctrl *pcie = \u0026serdes-\u003epcie;\n+\tstruct device *dev = \u0026pdev-\u003edev;\n+\n+\tpcie-\u003ephy_base = devm_platform_ioremap_resource_byname(pdev,\n+\t\t\t\t\t\t\t \"pcie-phy\");\n+\tif (IS_ERR(pcie-\u003ephy_base))\n+\t\treturn dev_err_probe(dev, PTR_ERR(pcie-\u003ephy_base),\n+\t\t\t\t \"Failed to map 'pcie-phy'\\n\");\n+\n+\tpcie-\u003erst = devm_reset_control_get_exclusive(dev, \"pcie\");\n+\tif (IS_ERR(pcie-\u003erst))\n+\t\treturn dev_err_probe(dev, PTR_ERR(pcie-\u003erst),\n+\t\t\t\t \"Failed to get 'pcie' reset control\\n\");\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_get_xpcs_resources(struct platform_device *pdev,\n+\t\t\t\t\t struct s32g_serdes *serdes)\n+{\n+\tstruct s32g_xpcs_ctrl *xpcs = \u0026serdes-\u003expcs;\n+\tstruct device *dev = \u0026pdev-\u003edev;\n+\n+\txpcs-\u003ebase[0] = devm_platform_ioremap_resource_byname(pdev, \"xpcs0\");\n+\tif (IS_ERR(xpcs-\u003ebase[0]))\n+\t\treturn dev_err_probe(dev, PTR_ERR(xpcs-\u003ebase[0]),\n+\t\t\t\t \"Failed to map 'xpcs0'\\n\");\n+\n+\txpcs-\u003ebase[1] = devm_platform_ioremap_resource_byname(pdev, \"xpcs1\");\n+\tif (IS_ERR(xpcs-\u003ebase[1]))\n+\t\treturn dev_err_probe(dev, PTR_ERR(xpcs-\u003ebase[1]),\n+\t\t\t\t \"Failed to map 'xpcs1'\\n\");\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_parse_lane(struct s32g_serdes *serdes,\n+\t\t\t\t struct device_node *child_node)\n+{\n+\tstruct device *dev = serdes-\u003edev;\n+\tu32 index, instance;\n+\tint ret;\n+\n+\tret = of_property_read_u32(child_node, \"reg\", \u0026index);\n+\tif (ret || index \u003e 1)\n+\t\treturn dev_err_probe(dev, ret ? : -EINVAL,\n+\t\t\t\t \"Invalid lane index in %pOFn\\n\",\n+\t\t\t\t child_node);\n+\n+\tif (serdes-\u003elane[index].fn != S32G_LANE_UNUSED)\n+\t\treturn dev_err_probe(dev, -EINVAL,\n+\t\t\t\t \"Duplicate lane %u\\n\", index);\n+\n+\tif (of_device_is_compatible(child_node, \"nxp,s32g-serdes-pcie-phy\")) {\n+\t\tserdes-\u003elane[index].fn = S32G_LANE_PCIE;\n+\t\treturn 0;\n+\t}\n+\n+\tif (of_device_is_compatible(child_node, \"nxp,s32g-serdes-xpcs\")) {\n+\t\tret = of_property_read_u32(child_node, \"nxp,xpcs-instance\",\n+\t\t\t\t\t \u0026instance);\n+\t\tif (ret || instance \u003e 1)\n+\t\t\treturn dev_err_probe(dev, ret ? : -EINVAL,\n+\t\t\t\t\t \"Invalid nxp,xpcs-instance in %pOFn\\n\",\n+\t\t\t\t\t child_node);\n+\n+\t\tserdes-\u003elane[index].fn = S32G_LANE_XPCS;\n+\t\tserdes-\u003elane[index].xpcs_instance = instance;\n+\t\treturn 0;\n+\t}\n+\n+\tdev_warn(dev, \"Skipping unknown child node %pOFn\\n\", child_node);\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_create_pcie_phy(struct s32g_serdes *serdes,\n+\t\t\t\t struct device_node *child_node)\n+{\n+\tstruct phy_provider *phy_provider;\n+\tstruct device *dev = serdes-\u003edev;\n+\tstruct phy *phy;\n+\n+\tphy = devm_phy_create(dev, child_node, \u0026serdes_pcie_ops);\n+\tif (IS_ERR(phy))\n+\t\treturn PTR_ERR(phy);\n+\n+\tphy_set_drvdata(phy, serdes);\n+\n+\tphy-\u003eattrs.mode = PHY_MODE_PCIE;\n+\tserdes-\u003epcie.phy = phy;\n+\n+\tphy_provider = devm_of_phy_provider_register(\u0026phy-\u003edev,\n+\t\t\t\t\t\t s32g_serdes_phy_xlate);\n+\tif (IS_ERR(phy_provider))\n+\t\treturn PTR_ERR(phy_provider);\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_parse_lanes(struct device *dev,\n+\t\t\t\t struct s32g_serdes *serdes)\n+{\n+\tint ret;\n+\n+\tfor_each_available_child_of_node_scoped(dev-\u003eof_node, of_port) {\n+\t\tret = s32g_serdes_parse_lane(serdes, of_port);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\t/*\n+\t * In the x2 mode both lane children are PCIe, but they form one link\n+\t * behind one controller, so create a single phy bound to the first\n+\t * PCIe child. One phy per child would register two providers for one\n+\t * link.\n+\t */\n+\tfor_each_available_child_of_node_scoped(dev-\u003eof_node, of_port) {\n+\t\tif (!of_device_is_compatible(of_port,\n+\t\t\t\t\t \"nxp,s32g-serdes-pcie-phy\"))\n+\t\t\tcontinue;\n+\n+\t\tret = s32g_serdes_create_pcie_phy(serdes, of_port);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\tbreak;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_setup_xpcs_lanes(struct s32g_serdes *serdes)\n+{\n+\tunsigned int i;\n+\tint ret;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(serdes-\u003elane); i++) {\n+\t\tif (serdes-\u003elane[i].fn != S32G_LANE_XPCS)\n+\t\t\tcontinue;\n+\n+\t\tret = s32g_serdes_xpcs_setup(serdes,\n+\t\t\t\t\t serdes-\u003elane[i].xpcs_instance);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_probe(struct platform_device *pdev)\n+{\n+\tstruct device *dev = \u0026pdev-\u003edev;\n+\tconst struct s32g_serdes_soc_data *soc_data;\n+\tstruct s32g_serdes *serdes;\n+\tint ret;\n+\n+\tserdes = devm_kzalloc(dev, sizeof(*serdes), GFP_KERNEL);\n+\tif (!serdes)\n+\t\treturn -ENOMEM;\n+\n+\tserdes-\u003edev = dev;\n+\n+\tsoc_data = of_device_get_match_data(dev);\n+\tif (!soc_data)\n+\t\treturn -EINVAL;\n+\n+\tserdes-\u003esoc_data = soc_data;\n+\n+\tret = s32g_serdes_get_ctrl_resources(pdev, serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_get_pcie_resources(pdev, serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_get_xpcs_resources(pdev, serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_parse_lanes(dev, serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_derive_mode(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_setup_xpcs_lanes(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = s32g_serdes_init(serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = devm_add_action_or_reset(dev, s32g_serdes_disable, serdes);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * Publish drvdata last: s32g_serdes_pcs_create() takes a NULL drvdata\n+\t * as its -EPROBE_DEFER condition, so setting it earlier can hand a MAC\n+\t * a PCS while the PLLs are still down, or after a failed probe has\n+\t * released it.\n+\t */\n+\tplatform_set_drvdata(pdev, serdes);\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_suspend(struct device *device)\n+{\n+\tstruct s32g_serdes *serdes = dev_get_drvdata(device);\n+\n+\tclk_bulk_disable_unprepare(serdes-\u003ectrl.nclks, serdes-\u003ectrl.clks);\n+\n+\treturn 0;\n+}\n+\n+static int s32g_serdes_resume(struct device *device)\n+{\n+\tstruct s32g_serdes *serdes = dev_get_drvdata(device);\n+\tstruct s32g_pcie_ctrl *pcie = \u0026serdes-\u003epcie;\n+\tint ret;\n+\n+\tret = s32g_serdes_init(serdes);\n+\tif (ret) {\n+\t\tdev_err(device, \"Failed to initialize\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\t/* Restore PCIe phy power */\n+\tif (pcie-\u003epowered_on) {\n+\t\tret = s32g_pcie_phy_power_on(serdes);\n+\t\tif (ret)\n+\t\t\tdev_err(device, \"Failed to power-on PCIe phy\\n\");\n+\t}\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * s32g_serdes_pcs_create() - look up the phylink PCS for a SerDes XPCS lane\n+ * @dev: the consumer (MAC) device\n+ * @np: the SerDes XPCS lane child node\n+ *\n+ * A device link is created between @dev and the SerDes device so that the\n+ * MAC is unbound before the SerDes it depends on. If the SerDes device has\n+ * not probed (far enough) yet, -EPROBE_DEFER is returned so the caller\n+ * retries later.\n+ *\n+ * Return: the phylink_pcs on success, or an ERR_PTR() on failure. The\n+ * returned phylink_pcs is owned by the SerDes device and must not be freed\n+ * by the caller.\n+ */\n+struct phylink_pcs *s32g_serdes_pcs_create(struct device *dev,\n+\t\t\t\t\t struct device_node *np)\n+{\n+\tstruct platform_device *pdev;\n+\tstruct device_node *pcs_np;\n+\tstruct s32g_serdes *serdes;\n+\tstruct device_link *link;\n+\tu32 instance;\n+\n+\t/*\n+\t * The lane child's unit address is the physical lane; the PCS is\n+\t * identified by the XPCS instance routed to that lane.\n+\t */\n+\tif (of_property_read_u32(np, \"nxp,xpcs-instance\", \u0026instance))\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\tif (instance \u003e= S32G_SERDES_XPCS_MAX)\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\tpcs_np = of_get_parent(np);\n+\tif (!pcs_np)\n+\t\treturn ERR_PTR(-ENODEV);\n+\n+\tif (!of_device_is_available(pcs_np)) {\n+\t\tof_node_put(pcs_np);\n+\t\treturn ERR_PTR(-ENODEV);\n+\t}\n+\n+\tpdev = of_find_device_by_node(pcs_np);\n+\tof_node_put(pcs_np);\n+\tif (!pdev)\n+\t\treturn ERR_PTR(-EPROBE_DEFER);\n+\n+\tserdes = platform_get_drvdata(pdev);\n+\tif (!serdes) {\n+\t\tput_device(\u0026pdev-\u003edev);\n+\t\treturn ERR_PTR(-EPROBE_DEFER);\n+\t}\n+\n+\tif (!serdes-\u003expcs.phys[instance]) {\n+\t\tput_device(\u0026pdev-\u003edev);\n+\t\treturn ERR_PTR(-EPROBE_DEFER);\n+\t}\n+\n+\tlink = device_link_add(dev, \u0026pdev-\u003edev, DL_FLAG_AUTOREMOVE_CONSUMER);\n+\tput_device(\u0026pdev-\u003edev);\n+\tif (!link)\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\treturn s32g_xpcs_pcs(serdes-\u003expcs.phys[instance]);\n+}\n+EXPORT_SYMBOL_GPL(s32g_serdes_pcs_create);\n+\n+static const struct of_device_id s32g_serdes_match[] = {\n+\t{\n+\t\t.compatible = \"nxp,s32g2-serdes\",\n+\t\t.data = \u0026s32g2_serdes_soc_data,\n+\t},\n+\t{\n+\t\t.compatible = \"nxp,s32g3-serdes\",\n+\t\t.data = \u0026s32g3_serdes_soc_data,\n+\t},\n+\t{ /* sentinel */ }\n+};\n+MODULE_DEVICE_TABLE(of, s32g_serdes_match);\n+\n+/* noirq, like the PCIe controller using this PHY */\n+static const struct dev_pm_ops s32g_serdes_pm_ops = {\n+\tNOIRQ_SYSTEM_SLEEP_PM_OPS(s32g_serdes_suspend,\n+\t\t\t\t s32g_serdes_resume)\n+};\n+\n+static struct platform_driver s32g_serdes_driver = {\n+\t.probe\t\t= s32g_serdes_probe,\n+\t.driver\t\t= {\n+\t\t.name\t= \"phy-s32g-serdes\",\n+\t\t.of_match_table = s32g_serdes_match,\n+\t\t.pm = pm_sleep_ptr(\u0026s32g_serdes_pm_ops),\n+\t},\n+};\n+module_platform_driver(s32g_serdes_driver);\n+\n+MODULE_AUTHOR(\"Ghennadi Procopciuc \u003cghennadi.procopciuc@nxp.com\u003e\");\n+MODULE_DESCRIPTION(\"NXP S32G SerDes driver\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/include/linux/pcs/pcs-nxp-s32g-xpcs.h b/include/linux/pcs/pcs-nxp-s32g-xpcs.h\nnew file mode 100644\nindex 0000000000000..7e1dfb6b638f3\n--- /dev/null\n+++ b/include/linux/pcs/pcs-nxp-s32g-xpcs.h\n@@ -0,0 +1,48 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * Copyright 2021-2026 NXP\n+ */\n+#ifndef PCS_NXP_S32G_XPCS_H\n+#define PCS_NXP_S32G_XPCS_H\n+\n+#include \u003clinux/types.h\u003e\n+\n+struct device;\n+struct phylink_pcs;\n+\n+/*\n+ * Opaque. The XPCS state, including its regmap and the embedded\n+ * phylink_pcs, is private to the PCS driver; the SerDes PHY driver only\n+ * ever holds pointers handed out by s32g_xpcs_create().\n+ */\n+struct s32g_xpcs;\n+\n+/*\n+ * Whether the XPCS shares the combo PHY with the PCIe lane. In the shared\n+ * modes the PMA power-up is driven from the PCIe side, which changes the\n+ * bring-up sequence.\n+ */\n+enum s32g_xpcs_shared {\n+\tS32G_NOT_SHARED,\n+\tS32G_PCIE_XPCS_1G,\n+\tS32G_PCIE_XPCS_2G5,\n+};\n+\n+struct s32g_xpcs *s32g_xpcs_create(struct device *dev, unsigned char id,\n+\t\t\t\t void __iomem *base, bool ext_clk,\n+\t\t\t\t unsigned long rate,\n+\t\t\t\t enum s32g_xpcs_shared pcie_shared);\n+struct phylink_pcs *s32g_xpcs_pcs(struct s32g_xpcs *xpcs);\n+\n+/*\n+ * Bring-up steps, called by the SerDes PHY driver. They are separate\n+ * because the dual-XPCS mode needs cross-instance barriers: every\n+ * instance must complete a step before any instance starts the next.\n+ */\n+int s32g_xpcs_init_plls(struct s32g_xpcs *xpcs);\n+void s32g_xpcs_vreset(struct s32g_xpcs *xpcs);\n+int s32g_xpcs_wait_vreset(struct s32g_xpcs *xpcs);\n+int s32g_xpcs_reset_rx(struct s32g_xpcs *xpcs);\n+void s32g_xpcs_disable_an(struct s32g_xpcs *xpcs);\n+\n+#endif /* PCS_NXP_S32G_XPCS_H */\ndiff --git a/include/linux/pcs/pcs-nxp-serdes-xpcs.h b/include/linux/pcs/pcs-nxp-serdes-xpcs.h\nnew file mode 100644\nindex 0000000000000..2579c6b14a61e\n--- /dev/null\n+++ b/include/linux/pcs/pcs-nxp-serdes-xpcs.h\n@@ -0,0 +1,100 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * NXP SerDes XPCS shared core\n+ * Copyright 2026 NXP\n+ */\n+\n+#ifndef __LINUX_PCS_NXP_SERDES_XPCS_H\n+#define __LINUX_PCS_NXP_SERDES_XPCS_H\n+\n+#include \u003clinux/phy.h\u003e\n+#include \u003clinux/phylink.h\u003e\n+#include \u003clinux/regmap.h\u003e\n+\n+/* AN mode values as defined by the DesignWare XPCS */\n+enum nxp_serdes_an_mode {\n+\tNXP_SERDES_AN_C37_SGMII = 2,\n+\tNXP_SERDES_2500BASEX = 3,\n+\tNXP_SERDES_10GBASER = 5,\n+\tNXP_SERDES_AN_C37_USXGMII = 6,\n+};\n+\n+/* The revision runs its own reset sequence, skip the soft reset */\n+#define NXP_SERDES_QUIRK_NO_SOFT_RESET\tBIT(0)\n+/* The revision reports the link state to the MAC, do not poll the PCS */\n+#define NXP_SERDES_QUIRK_NO_POLL\tBIT(1)\n+/* The revision does not implement the VR_MII_EEE_MCTRL0/1 registers */\n+#define NXP_SERDES_QUIRK_NO_EEE\t\tBIT(2)\n+\n+struct nxp_serdes_xpcs;\n+\n+struct nxp_serdes_xpcs_compat {\n+\tphy_interface_t interface;\n+\tconst int *supported;\n+\tenum nxp_serdes_an_mode an_mode;\n+\tint (*pma_config)(struct nxp_serdes_xpcs *xpcs);\n+\tint (*pma_link_up)(struct nxp_serdes_xpcs *xpcs, int speed,\n+\t\t\t int duplex);\n+};\n+\n+/* Description of one SerDes revision, provided by the platform glue */\n+struct nxp_serdes_xpcs_desc {\n+\tconst char *name;\n+\tu32 pma_id;\n+\tconst struct nxp_serdes_xpcs_compat *compat;\n+\tunsigned int quirks;\n+\tvoid (*reset)(struct nxp_serdes_xpcs *xpcs);\n+};\n+\n+struct nxp_serdes_xpcs {\n+\tstruct device *dev;\n+\tstruct regmap *xpcs_regmap;\n+\tstruct regmap *phy_regmap;\n+\tconst struct nxp_serdes_xpcs_desc *desc;\n+\tstruct phylink_pcs pcs;\n+\tphy_interface_t interface;\n+\tu32 pma_id;\n+\tu8 portid;\n+\tbool need_reset;\n+\tbool sgmii_internal_ref_clk;\n+\tvoid *priv;\n+};\n+\n+#define phylink_pcs_to_nxp_serdes_xpcs(pl_pcs) \\\n+\tcontainer_of((pl_pcs), struct nxp_serdes_xpcs, pcs)\n+\n+static inline void nxp_serdes_xpcs_set_drvdata(struct nxp_serdes_xpcs *xpcs,\n+\t\t\t\t\t void *priv)\n+{\n+\txpcs-\u003epriv = priv;\n+}\n+\n+static inline void *nxp_serdes_xpcs_get_drvdata(struct nxp_serdes_xpcs *xpcs)\n+{\n+\treturn xpcs-\u003epriv;\n+}\n+\n+/* Feature sets for struct nxp_serdes_xpcs_compat::supported */\n+extern const int nxp_serdes_xpcs_usxgmii_features[];\n+extern const int nxp_serdes_xpcs_2500basex_features[];\n+extern const int nxp_serdes_xpcs_sgmii_features[];\n+\n+struct phylink_pcs *nxp_serdes_xpcs_create(struct device *dev,\n+\t\t\t\t\t struct regmap *xpcs_regmap,\n+\t\t\t\t\t struct regmap *phy_regmap,\n+\t\t\t\t\t const struct nxp_serdes_xpcs_desc *desc,\n+\t\t\t\t\t u8 portid,\n+\t\t\t\t\t phy_interface_t interface);\n+void nxp_serdes_xpcs_destroy(struct phylink_pcs *pcs);\n+\n+/* Register accesses are encoded in the regmap as \"(devad \u003c\u003c 16) | reg\", with\n+ * \"devad\" the Clause 45 device address and \"reg\" the 16-bit register address.\n+ * Decoding both fields is up to the regmap of the platform glue.\n+ */\n+int nxp_serdes_xpcs_read(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg);\n+int nxp_serdes_xpcs_write(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,\n+\t\t\t u16 val);\n+int nxp_serdes_xpcs_modify(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,\n+\t\t\t u16 mask, u16 set);\n+\n+#endif /* __LINUX_PCS_NXP_SERDES_XPCS_H */\ndiff --git a/include/linux/phy/nxp-s32g-serdes.h b/include/linux/phy/nxp-s32g-serdes.h\nnew file mode 100644\nindex 0000000000000..d14fcde1d9331\n--- /dev/null\n+++ b/include/linux/phy/nxp-s32g-serdes.h\n@@ -0,0 +1,25 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * Copyright 2021-2026 NXP\n+ */\n+#ifndef PHY_NXP_S32G_SERDES_H\n+#define PHY_NXP_S32G_SERDES_H\n+\n+#include \u003clinux/err.h\u003e\n+\n+struct device;\n+struct device_node;\n+struct phylink_pcs;\n+\n+#if IS_REACHABLE(CONFIG_PHY_S32G_SERDES)\n+struct phylink_pcs *s32g_serdes_pcs_create(struct device *dev,\n+\t\t\t\t\t struct device_node *np);\n+#else\n+static inline struct phylink_pcs *\n+s32g_serdes_pcs_create(struct device *dev, struct device_node *np)\n+{\n+\treturn ERR_PTR(-ENODEV);\n+}\n+#endif\n+\n+#endif /* PHY_NXP_S32G_SERDES_H */\n"
} |
| 2/1 | 2026/09/21 06:09 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series introduces device tree bindings, ARM64 DTS changes, and drivers for the SerDes PHY and Synopsys XPCS platform glue on NXP S32G automotive SoCs (ARM64). These platform drivers require physical NXP S32G SoC hardware that is not emulated in standard virtualized QEMU/GCE environments, and the code is structurally unreachable on the target architecture (amd64).",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 3792723fde6cdccf2b1b8009e7fd2cefb45fcf9b
Author: syz-cluster <triage@syzkaller.com>
Date: Mon Sep 21 06:09:51 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml
index 753a04941659b..b168decb540c6 100644
--- a/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml
+++ b/Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml
@@ -15,7 +15,8 @@ description:
The SoC series S32G2xx and S32G3xx feature one DWMAC instance,
the SoC S32R45 has two instances. The devices can use RGMII/RMII/MII
interface over Pinctrl device or the output can be routed
- to the embedded SerDes for SGMII connectivity.
+ to the embedded SerDes for SGMII connectivity, in which case the
+ SerDes XPCS lane acting as the PCS is referenced via pcs-handle.
The DWMAC instances have connected all RX/TX queues interrupts,
enabling load balancing of data traffic across all CPU cores.
@@ -81,6 +82,14 @@ properties:
- const: rx
- const: ptp_ref
+ pcs-handle:
+ $ref: /schemas/types.yaml#/definitions/phandle-array
+ maxItems: 1
+ description:
+ phandle pointing to the SerDes XPCS lane child node that provides
+ the SGMII PCS for this MAC. See
+ Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml.
+
required:
- clocks
- clock-names
diff --git a/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml b/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml
index 66a050028278a..29323e50bd8bc 100644
--- a/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml
+++ b/Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml
@@ -82,7 +82,6 @@ unevaluatedProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
- #include <dt-bindings/phy/phy.h>
bus {
#address-cells = <2>;
@@ -124,7 +123,7 @@ examples:
ranges;
device_type = "pci";
- phys = <&serdes0 PHY_TYPE_PCIE 0 0>;
+ phys = <&serdes0_pcie0>;
};
};
};
diff --git a/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml b/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
new file mode 100644
index 0000000000000..6343d01bfde45
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
@@ -0,0 +1,258 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/nxp,s32g-serdes.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP S32G2xxx/S32G3xxx SerDes PHY subsystem
+
+maintainers:
+ - Ghennadi Procopciuc <ghennadi.procopciuc@nxp.com>
+ - Jan Petrous <jan.petrous@oss.nxp.com>
+
+description: |
+ The SerDes subsystem multiplexes two SerDes lanes between one PCIe
+ controller PHY and two Synopsys DesignWare XPCS (Ethernet PCS) instances,
+ behind a shared 2-lane combo PHY. The active routing is selected by the
+ SS_RW_REG_0[SUBSYS_MODE] field.
+
+ Reference-manual working modes described by this binding:
+
+ Mode Lane0 Lane1 PHY refclk (MHz) Description
+ ------------------------------------------------------------
+ 0 PCIe PCIe 100 PCIe x2
+ 1 PCIe XPCS0 100 PCIe x1 + SGMII
+ 2 PCIe XPCS1 100 PCIe x1 + SGMII
+ 3 XPCS0 XPCS1 100 or 125 dual SGMII, 1.25 Gbit/s
+
+ Which Ethernet MAC an XPCS instance feeds is fixed by the SoC integration
+ and differs per SoC and per SerDes instance - on S32G3 SerDes_0, XPCS0
+ feeds GMAC0 and XPCS1 feeds PFE_MAC2, while on SerDes_1 the same two
+ instances feed PFE_MAC0 and PFE_MAC1. That mapping is a property of the
+ SoC, not of this binding, and is resolved by the driver.
+
+ The 3.125 Gbit/s working modes are not described here yet. Distinguishing
+ them from mode 3 requires a per-lane 2500BASE-X capability, which this
+ binding does not express; the reference clock does not distinguish them
+ either, as both accept 100 or 125 MHz. They are added by a follow-up.
+
+ SUBSYS_MODE is not encoded in the devicetree. It is derived at probe from
+ information already present in standard form:
+ - the lane mux, from the per-lane child nodes below;
+ - the XPCS instance a lane feeds, from nxp,xpcs-instance (this is what
+ distinguishes modes 1 and 2).
+ Each mode above has a unique lane mux, so the mode is a pure function of
+ the child nodes. The reference-clock rate is validated against the
+ derived mode; it is never used to select it.
+
+ Both lanes must always be described, even a lane the board does not wire
+ out to a connector. The lane mux is a property of the hardware
+ SUBSYS_MODE, not of the board routing: in mode 1, for example, the
+ subsystem internally routes lane 1 to XPCS0 whether or not the board
+ connects that lane to anything. The child nodes describe that fixed
+ hardware mux, so both must be present; omitting a lane leaves the mode
+ underivable and the probe fails with -EINVAL. Which of those lanes is
+ actually used by a given board is expressed elsewhere (the consumer's
+ phys / pcs-handle reference), not by leaving the lane out here.
+
+ The full reference-manual mode tables differ per SoC, which is why S32G2
+ and S32G3 use distinct compatibles without a fallback between them.
+
+ They also differ between the two SerDes instances of one SoC, so each
+ instance additionally carries a compatible naming it, with the per-SoC
+ string as fallback:
+
+ serdes0: compatible = "nxp,s32g3-serdes0", "nxp,s32g3-serdes";
+ serdes1: compatible = "nxp,s32g3-serdes1", "nxp,s32g3-serdes";
+
+ For the modes described here the two instances behave identically and a
+ driver need only match the fallback. They diverge outside this scope:
+ on S32G3 the 3.125 Gbit/s dual-XPCS mode 4 exists on SerDes_1 only, and
+ on S32G2 only SerDes_1 reaches 3.125 Gbit/s at all. Recording the
+ instance now means the follow-up that adds those modes is purely
+ additive - it matches the specific strings and needs no devicetree
+ change.
+
+ The same mechanism covers SoCs whose instances differ in kind rather
+ than in degree: on S32R47 one SerDes has no PCIe controller at all, so
+ its compatible must be distinguishable in order to reject a PCIe lane
+ child in schema rather than at probe time.
+
+properties:
+ compatible:
+ oneOf:
+ - items:
+ - enum:
+ - nxp,s32g2-serdes0
+ - nxp,s32g2-serdes1
+ - const: nxp,s32g2-serdes
+ - items:
+ - enum:
+ - nxp,s32g3-serdes0
+ - nxp,s32g3-serdes1
+ - const: nxp,s32g3-serdes
+
+ reg:
+ maxItems: 4
+
+ reg-names:
+ items:
+ - const: ss-pcie
+ - const: pcie-phy
+ - const: xpcs0
+ - const: xpcs1
+
+ clocks:
+ minItems: 4
+ maxItems: 5
+
+ clock-names:
+ minItems: 4
+ items:
+ - const: axi
+ - const: aux
+ - const: apb
+ - const: ref
+ - const: ext
+ description:
+ The combo PHY reference can be taken from the internal reference
+ clock ("ref") or from the external reference pad ("ext"). A board
+ that routes the external pad lists both; the external reference is
+ then the one used.
+
+ resets:
+ maxItems: 2
+
+ reset-names:
+ items:
+ - const: serdes
+ - const: pcie
+
+ '#address-cells':
+ const: 1
+
+ '#size-cells':
+ const: 0
+
+patternProperties:
+ '^phy@[01]$':
+ description: One SerDes lane. The unit address is the physical lane index.
+ type: object
+ additionalProperties: false
+
+ properties:
+ reg:
+ description: Physical lane index.
+ maximum: 1
+
+ compatible:
+ enum:
+ - nxp,s32g-serdes-pcie-phy
+ - nxp,s32g-serdes-xpcs
+
+ '#phy-cells':
+ const: 0
+
+ nxp,xpcs-instance:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1]
+ description:
+ DesignWare XPCS instance this lane is routed to. Required for, and
+ only valid on, XPCS lanes. Distinguishes modes 1 and 2; for the
+ dual-XPCS mode the instance equals the lane index.
+
+ required:
+ - reg
+ - compatible
+
+ allOf:
+ - if:
+ properties:
+ compatible:
+ const: nxp,s32g-serdes-xpcs
+ required:
+ - compatible
+ then:
+ # An XPCS lane is not a generic PHY provider. It is referenced by
+ # the Ethernet controller through pcs-handle, not through phys.
+ required:
+ - nxp,xpcs-instance
+ properties:
+ '#phy-cells': false
+ else:
+ required:
+ - '#phy-cells'
+ properties:
+ nxp,xpcs-instance: false
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - clocks
+ - clock-names
+ - resets
+ - reset-names
+ - '#address-cells'
+ - '#size-cells'
+
+additionalProperties: false
+
+examples:
+ # PCIe x1 on lane 0 + 1G SGMII on lane 1 via XPCS0 (derived mode 1).
+ - |
+ serdes@40480000 {
+ compatible = "nxp,s32g3-serdes0", "nxp,s32g3-serdes";
+ reg = <0x40480000 0x108>,
+ <0x40483008 0x10>,
+ <0x40482000 0x800>,
+ <0x40482800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 1>, <&scmi_reset 0>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ phy@0 {
+ reg = <0>;
+ compatible = "nxp,s32g-serdes-pcie-phy";
+ #phy-cells = <0>;
+ };
+
+ phy@1 {
+ reg = <1>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <0>;
+ };
+ };
+
+ # Dual 1G SGMII (derived mode 3).
+ - |
+ serdes@44180000 {
+ compatible = "nxp,s32g3-serdes1", "nxp,s32g3-serdes";
+ reg = <0x44180000 0x108>,
+ <0x44183008 0x10>,
+ <0x44182000 0x800>,
+ <0x44182800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 11>, <&scmi_reset 10>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ phy@0 {
+ reg = <0>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <0>;
+ };
+
+ phy@1 {
+ reg = <1>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <1>;
+ };
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index 3b2eb2a7a89a8..38c6b5e1af0d5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3371,6 +3371,20 @@ S: Maintained
F: Documentation/devicetree/bindings/pci/nxp,s32g-pcie.yaml
F: drivers/pci/controller/dwc/pcie-nxp-s32g*
+ARM/NXP S32G SERDES DRIVER
+M: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>
+M: Jan Petrous <jan.petrous@oss.nxp.com>
+R: NXP S32 Linux Team <s32@nxp.com>
+L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
+L: linux-phy@lists.infradead.org
+L: netdev@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
+F: drivers/net/pcs/pcs-nxp-s32g-xpcs.c
+F: drivers/phy/freescale/phy-nxp-s32g-serdes.c
+F: include/linux/pcs/pcs-nxp-s32g-xpcs.h
+F: include/linux/phy/nxp-s32g-serdes.h
+
ARM/NXP S32G/S32R DWMAC ETHERNET DRIVER
M: Jan Petrous <jan.petrous@oss.nxp.com>
R: s32@nxp.com
@@ -19788,6 +19802,15 @@ S: Maintained
F: Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
F: drivers/extcon/extcon-ptn5150.c
+NXP SERDES XPCS SHARED CORE
+M: Jan Petrous <jan.petrous@oss.nxp.com>
+M: Clark Wang <xiaoning.wang@nxp.com>
+R: NXP S32 Linux Team <s32@nxp.com>
+L: netdev@vger.kernel.org
+S: Maintained
+F: drivers/net/pcs/pcs-nxp-serdes-xpcs.c
+F: include/linux/pcs/pcs-nxp-serdes-xpcs.h
+
NXP SGTL5000 DRIVER
M: Fabio Estevam <festevam@gmail.com>
L: linux-sound@vger.kernel.org
diff --git a/arch/arm64/boot/dts/freescale/Makefile b/arch/arm64/boot/dts/freescale/Makefile
index 95ae85ab4adf5..3f68f36ac2beb 100644
--- a/arch/arm64/boot/dts/freescale/Makefile
+++ b/arch/arm64/boot/dts/freescale/Makefile
@@ -786,5 +786,11 @@ dtb-$(CONFIG_ARCH_MXC) += imx8mm-phygate-tauri-l-rs232-rs485.dtb
dtb-$(CONFIG_ARCH_S32) += s32g274a-evb.dtb
dtb-$(CONFIG_ARCH_S32) += s32g274a-rdb2.dtb
dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3.dtb
+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode1.dtb
+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode3.dtb
+s32g399a-rdb3-serdes-mode1-dtbs := s32g399a-rdb3.dtb s32g399a-rdb3-serdes-mode1.dtbo
+s32g399a-rdb3-serdes-mode3-dtbs := s32g399a-rdb3.dtb s32g399a-rdb3-serdes-mode3.dtbo
+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode1.dtbo
+dtb-$(CONFIG_ARCH_S32) += s32g399a-rdb3-serdes-mode3.dtbo
dtb-$(CONFIG_ARCH_S32) += s32n79-rdb.dtb
dtb-$(CONFIG_ARCH_S32) += s32v234-evb.dtb
diff --git a/arch/arm64/boot/dts/freescale/s32g2.dtsi b/arch/arm64/boot/dts/freescale/s32g2.dtsi
index 996494e34593f..539840340318d 100644
--- a/arch/arm64/boot/dts/freescale/s32g2.dtsi
+++ b/arch/arm64/boot/dts/freescale/s32g2.dtsi
@@ -100,6 +100,11 @@ clks: protocol@14 {
reg = <0x14>;
#clock-cells = <1>;
};
+
+ scmi_reset: protocol@16 {
+ reg = <0x16>;
+ #reset-cells = <1>;
+ };
};
psci {
@@ -872,6 +877,38 @@ gmac0mdio: mdio {
};
};
+ serdes0: serdes@40480000 {
+ compatible = "nxp,s32g2-serdes0", "nxp,s32g2-serdes";
+ reg = <0x40480000 0x108>,
+ <0x40483008 0x10>,
+ <0x40482000 0x800>,
+ <0x40482800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 9>, <&scmi_reset 8>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+ };
+
+ serdes1: serdes@44180000 {
+ compatible = "nxp,s32g2-serdes1", "nxp,s32g2-serdes";
+ reg = <0x44180000 0x108>,
+ <0x44183008 0x10>,
+ <0x44182000 0x800>,
+ <0x44182800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 11>, <&scmi_reset 10>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+ };
+
gic: interrupt-controller@50800000 {
compatible = "arm,gic-v3";
reg = <0x50800000 0x10000>,
@@ -881,7 +918,88 @@ gic: interrupt-controller@50800000 {
<0x50420000 0x2000>;
interrupts = <GIC_PPI 9 IRQ_TYPE_LEVEL_HIGH>;
interrupt-controller;
+ #address-cells = <0>;
#interrupt-cells = <3>;
};
};
+
+ /*
+ * PCIe controllers. Their config space (0x5f_ffffe000 / 0x4f_ffffe000)
+ * lies above the 32-bit window mapped by soc@0, so the root complexes
+ * are described at the device tree root. Disabled here; a board file
+ * that wires a lane to PCIe enables the controller and adds the phys.
+ */
+ pcie0: pcie@40400000 {
+ compatible = "nxp,s32g2-pcie";
+ reg = <0x00 0x40400000 0x0 0x00001000>, /* dbi */
+ <0x00 0x40420000 0x0 0x00001000>, /* dbi2 */
+ <0x00 0x40460000 0x0 0x00001000>, /* atu */
+ <0x00 0x40470000 0x0 0x00001000>, /* dma */
+ <0x00 0x40481000 0x0 0x000000f8>, /* ctrl */
+ <0x5f 0xffffe000 0x0 0x00002000>; /* config */
+ reg-names = "dbi", "dbi2", "atu", "dma", "ctrl", "config";
+ dma-coherent;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ device_type = "pci";
+ ranges = <0x01000000 0x0 0x00000000 0x5f 0xfffe0000 0x0 0x00010000>,
+ <0x02000000 0x0 0x00000000 0x58 0x00000000 0x0 0x80000000>,
+ <0x02000000 0x1 0x00000000 0x59 0x00000000 0x6 0xfffe0000>;
+ bus-range = <0x0 0xff>;
+ interrupts = <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "msi", "dma";
+ #interrupt-cells = <1>;
+ interrupt-map-mask = <0 0 0 0x7>;
+ interrupt-map = <0 0 0 1 &gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 2 &gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 3 &gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 4 &gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
+ status = "disabled";
+
+ pcie0_rp: pcie@0 {
+ reg = <0x0 0x0 0x0 0x0 0x0>;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+ device_type = "pci";
+ };
+ };
+
+ pcie1: pcie@44100000 {
+ compatible = "nxp,s32g2-pcie";
+ reg = <0x00 0x44100000 0x0 0x00001000>, /* dbi */
+ <0x00 0x44120000 0x0 0x00001000>, /* dbi2 */
+ <0x00 0x44160000 0x0 0x00001000>, /* atu */
+ <0x00 0x44170000 0x0 0x00001000>, /* dma */
+ <0x00 0x44181000 0x0 0x000000f8>, /* ctrl */
+ <0x4f 0xffffe000 0x0 0x00002000>; /* config */
+ reg-names = "dbi", "dbi2", "atu", "dma", "ctrl", "config";
+ dma-coherent;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ device_type = "pci";
+ ranges = <0x01000000 0x0 0x00000000 0x4f 0xfffe0000 0x0 0x00010000>,
+ <0x02000000 0x0 0x00000000 0x48 0x00000000 0x0 0x80000000>,
+ <0x02000000 0x1 0x00000000 0x49 0x00000000 0x6 0xfffe0000>;
+ bus-range = <0x0 0xff>;
+ interrupts = <GIC_SPI 216 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 214 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "msi", "dma";
+ #interrupt-cells = <1>;
+ interrupt-map-mask = <0 0 0 0x7>;
+ interrupt-map = <0 0 0 1 &gic GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 2 &gic GIC_SPI 220 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 3 &gic GIC_SPI 221 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 4 &gic GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH>;
+ status = "disabled";
+
+ pcie1_rp: pcie@0 {
+ reg = <0x0 0x0 0x0 0x0 0x0>;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+ device_type = "pci";
+ };
+ };
};
diff --git a/arch/arm64/boot/dts/freescale/s32g3.dtsi b/arch/arm64/boot/dts/freescale/s32g3.dtsi
index 31f7aad00b764..fdf086363c020 100644
--- a/arch/arm64/boot/dts/freescale/s32g3.dtsi
+++ b/arch/arm64/boot/dts/freescale/s32g3.dtsi
@@ -139,6 +139,11 @@ clks: protocol@14 {
reg = <0x14>;
#clock-cells = <1>;
};
+
+ scmi_reset: protocol@16 {
+ reg = <0x16>;
+ #reset-cells = <1>;
+ };
};
psci: psci {
@@ -951,6 +956,38 @@ gmac0mdio: mdio {
};
};
+ serdes0: serdes@40480000 {
+ compatible = "nxp,s32g3-serdes0", "nxp,s32g3-serdes";
+ reg = <0x40480000 0x108>,
+ <0x40483008 0x10>,
+ <0x40482000 0x800>,
+ <0x40482800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 9>, <&scmi_reset 8>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+ };
+
+ serdes1: serdes@44180000 {
+ compatible = "nxp,s32g3-serdes1", "nxp,s32g3-serdes";
+ reg = <0x44180000 0x108>,
+ <0x44183008 0x10>,
+ <0x44182000 0x800>,
+ <0x44182800 0x800>;
+ reg-names = "ss-pcie", "pcie-phy", "xpcs0", "xpcs1";
+ clocks = <&clks 1>, <&clks 2>, <&clks 3>, <&clks 4>;
+ clock-names = "axi", "aux", "apb", "ref";
+ resets = <&scmi_reset 11>, <&scmi_reset 10>;
+ reset-names = "serdes", "pcie";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "disabled";
+ };
+
swt8: watchdog@40500000 {
compatible = "nxp,s32g3-swt", "nxp,s32g2-swt";
reg = <0x40500000 0x1000>;
@@ -1021,6 +1058,7 @@ stm11: timer@4052c000 {
gic: interrupt-controller@50800000 {
compatible = "arm,gic-v3";
+ #address-cells = <0>;
#interrupt-cells = <3>;
interrupt-controller;
reg = <0x50800000 0x10000>,
@@ -1032,6 +1070,86 @@ gic: interrupt-controller@50800000 {
};
};
+ /*
+ * PCIe controllers. Their config space (0x5f_ffffe000 / 0x4f_ffffe000)
+ * lies above the 32-bit window mapped by soc@0, so the root complexes
+ * are described at the device tree root. Disabled here; a board file
+ * that wires a lane to PCIe enables the controller and adds the phys.
+ */
+ pcie0: pcie@40400000 {
+ compatible = "nxp,s32g3-pcie", "nxp,s32g2-pcie";
+ reg = <0x00 0x40400000 0x0 0x00001000>, /* dbi */
+ <0x00 0x40420000 0x0 0x00001000>, /* dbi2 */
+ <0x00 0x40460000 0x0 0x00001000>, /* atu */
+ <0x00 0x40470000 0x0 0x00001000>, /* dma */
+ <0x00 0x40481000 0x0 0x000000f8>, /* ctrl */
+ <0x5f 0xffffe000 0x0 0x00002000>; /* config */
+ reg-names = "dbi", "dbi2", "atu", "dma", "ctrl", "config";
+ dma-coherent;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ device_type = "pci";
+ ranges = <0x01000000 0x0 0x00000000 0x5f 0xfffe0000 0x0 0x00010000>,
+ <0x02000000 0x0 0x00000000 0x58 0x00000000 0x0 0x80000000>,
+ <0x02000000 0x1 0x00000000 0x59 0x00000000 0x6 0xfffe0000>;
+ bus-range = <0x0 0xff>;
+ interrupts = <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "msi", "dma";
+ #interrupt-cells = <1>;
+ interrupt-map-mask = <0 0 0 0x7>;
+ interrupt-map = <0 0 0 1 &gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 2 &gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 3 &gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 4 &gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
+ status = "disabled";
+
+ pcie0_rp: pcie@0 {
+ reg = <0x0 0x0 0x0 0x0 0x0>;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+ device_type = "pci";
+ };
+ };
+
+ pcie1: pcie@44100000 {
+ compatible = "nxp,s32g3-pcie", "nxp,s32g2-pcie";
+ reg = <0x00 0x44100000 0x0 0x00001000>, /* dbi */
+ <0x00 0x44120000 0x0 0x00001000>, /* dbi2 */
+ <0x00 0x44160000 0x0 0x00001000>, /* atu */
+ <0x00 0x44170000 0x0 0x00001000>, /* dma */
+ <0x00 0x44181000 0x0 0x000000f8>, /* ctrl */
+ <0x4f 0xffffe000 0x0 0x00002000>; /* config */
+ reg-names = "dbi", "dbi2", "atu", "dma", "ctrl", "config";
+ dma-coherent;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ device_type = "pci";
+ ranges = <0x01000000 0x0 0x00000000 0x4f 0xfffe0000 0x0 0x00010000>,
+ <0x02000000 0x0 0x00000000 0x48 0x00000000 0x0 0x80000000>,
+ <0x02000000 0x1 0x00000000 0x49 0x00000000 0x6 0xfffe0000>;
+ bus-range = <0x0 0xff>;
+ interrupts = <GIC_SPI 216 IRQ_TYPE_LEVEL_HIGH>,
+ <GIC_SPI 214 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "msi", "dma";
+ #interrupt-cells = <1>;
+ interrupt-map-mask = <0 0 0 0x7>;
+ interrupt-map = <0 0 0 1 &gic GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 2 &gic GIC_SPI 220 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 3 &gic GIC_SPI 221 IRQ_TYPE_LEVEL_HIGH>,
+ <0 0 0 4 &gic GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH>;
+ status = "disabled";
+
+ pcie1_rp: pcie@0 {
+ reg = <0x0 0x0 0x0 0x0 0x0>;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+ device_type = "pci";
+ };
+ };
+
timer {
compatible = "arm,armv8-timer";
interrupt-parent = <&gic>;
diff --git a/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso
new file mode 100644
index 0000000000000..43219d9bb6eb6
--- /dev/null
+++ b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode1.dtso
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/*
+ * Copyright 2021-2026 NXP
+ *
+ * NXP S32G3 Reference Design Board 3 (S32G-VNP-RDB3),
+ * SerDes_0 Mode 1: PCIe x1 (lane 0) + 1G SGMII via GMAC0 (XPCS0, lane 1).
+ *
+ * Overlay applied on top of s32g399a-rdb3.dtb. It reroutes GMAC0 from the
+ * on-board RGMII PHY to the SerDes_0 XPCS0 lane and brings up the PCIe
+ * controllers as root complexes. The lane layout present here selects
+ * SerDes SUBSYS_MODE 1.
+ */
+
+/dts-v1/;
+/plugin/;
+
+&serdes0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "okay";
+
+ /* Mode 1 lane layout: PCIe on lane 0, GMAC SGMII (XPCS0) on lane 1. */
+ serdes0_pcie0: phy@0 {
+ reg = <0>;
+ compatible = "nxp,s32g-serdes-pcie-phy";
+ #phy-cells = <0>;
+ };
+
+ serdes0_xpcs0: phy@1 {
+ reg = <1>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <0>;
+ };
+};
+
+&serdes1 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "okay";
+
+ /*
+ * SerDes_1 Mode 1 lane layout: PCIe on lane 0, SGMII (PFE_MAC0
+ * via XPCS0) on lane 1.
+ *
+ * Both lanes must be described: the SerDes driver derives the
+ * SUBSYS_MODE from the full lane mux, so lane 1 has to be present
+ * as XPCS instance 0 (PFE_MAC0) for the mode-1 match to succeed.
+ * PFE is not modeled as a MAC consumer in this upstreaming device
+ * tree, so the XPCS lane is only brought up by the SerDes driver
+ * and left without a pcs-handle user.
+ */
+ serdes1_pcie0: phy@0 {
+ reg = <0>;
+ compatible = "nxp,s32g-serdes-pcie-phy";
+ #phy-cells = <0>;
+ };
+
+ serdes1_xpcs0: phy@1 {
+ reg = <1>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <0>;
+ };
+};
+
+/*
+ * Both PCIe root complexes are wired on the RDB3:
+ * - PCIe_0 reaches the M.2 slots (M-key or E-key) when board switch
+ * SW17-2 is set to ON. It consumes SerDes_0 lane-0 PCIe phy.
+ * - PCIe_1 reaches the PCIe card slot. It consumes SerDes_1 lane-0 PCIe phy.
+ */
+&pcie0 {
+ status = "okay";
+};
+
+&pcie0_rp {
+ num-lanes = <1>;
+ phys = <&serdes0_pcie0>;
+};
+
+&pcie1 {
+ status = "okay";
+};
+
+&pcie1_rp {
+ num-lanes = <1>;
+ phys = <&serdes1_pcie0>;
+};
+
+&gmac0 {
+ /delete-property/ phy-handle;
+ clocks = <&clks 24>, <&clks 17>, <&clks 16>, <&clks 15>;
+ clock-names = "stmmaceth", "tx", "rx", "ptp_ref";
+ phy-mode = "sgmii";
+ pcs-handle = <&serdes0_xpcs0>;
+ status = "okay";
+
+ /*
+ * GMAC0 is wired back-to-back to the on-board SJA1110 switch over
+ * this SGMII lane. There is no PHY on the segment, so there is
+ * nothing to reference with phy-handle: the link partner is a
+ * switch port. Describe it as a fixed 1G link; phylink then uses
+ * out-of-band negotiation. The switch itself is not described by
+ * this overlay. The PCS also supports in-band negotiation, for
+ * boards whose link partner is described.
+ */
+ fixed-link {
+ speed = <1000>;
+ full-duplex;
+ pause;
+ };
+};
diff --git a/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso
new file mode 100644
index 0000000000000..195c8043c18ac
--- /dev/null
+++ b/arch/arm64/boot/dts/freescale/s32g399a-rdb3-serdes-mode3.dtso
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
+/*
+ * Copyright 2021-2026 NXP
+ *
+ * NXP S32G3 Reference Design Board 3 (S32G-VNP-RDB3),
+ * SerDes_0 Mode 3: dual SGMII, GMAC0 (XPCS0, lane 0) + PFE_EMAC_2
+ * (XPCS1, lane 1), both 1G.
+ *
+ * Overlay applied on top of s32g399a-rdb3.dtb. It reroutes GMAC0 from the
+ * on-board RGMII PHY to the SerDes_0 XPCS0 lane. The lane-1 XPCS1
+ * (PFE_EMAC_2) is described so the mode is derivable and both XPCS
+ * instances are initialised; it has no upstream MAC consumer in this
+ * device tree. The lane layout present here selects SerDes SUBSYS_MODE 3.
+ */
+
+/dts-v1/;
+/plugin/;
+
+&serdes0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ status = "okay";
+
+ /* Mode 3 lane layout: GMAC SGMII (XPCS0) on lane 0, PFE2 (XPCS1) on lane 1. */
+ serdes0_xpcs0: phy@0 {
+ reg = <0>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <0>;
+ };
+
+ serdes0_xpcs1: phy@1 {
+ reg = <1>;
+ compatible = "nxp,s32g-serdes-xpcs";
+ nxp,xpcs-instance = <1>;
+ };
+};
+
+&gmac0 {
+ /delete-property/ phy-handle;
+ clocks = <&clks 24>, <&clks 17>, <&clks 16>, <&clks 15>;
+ clock-names = "stmmaceth", "tx", "rx", "ptp_ref";
+ phy-mode = "sgmii";
+ pcs-handle = <&serdes0_xpcs0>;
+ status = "okay";
+
+ /*
+ * GMAC0 is wired back-to-back to the on-board SJA1110 switch over
+ * this SGMII lane. There is no PHY on the segment, so there is
+ * nothing to reference with phy-handle: the link partner is a
+ * switch port. Describe it as a fixed 1G link; phylink then uses
+ * out-of-band negotiation. The switch itself is not described by
+ * this overlay. The PCS also supports in-band negotiation, for
+ * boards whose link partner is described.
+ */
+ fixed-link {
+ speed = <1000>;
+ full-duplex;
+ pause;
+ };
+};
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index e3dd5adda5aca..1443ff4149b42 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -192,6 +192,12 @@ config DWMAC_S32
tristate "NXP S32G/S32R GMAC support"
default ARCH_S32
depends on OF && (ARCH_S32 || COMPILE_TEST)
+ # SGMII needs the PCS from the SerDes driver. The header falls back
+ # to a stub returning -ENODEV when that driver is not reachable, and
+ # stmmac makes a failing plat->pcs_init() fatal, so a built-in MAC
+ # with a modular SerDes would refuse to probe on any DT describing
+ # pcs-handle. Forbid that combination instead.
+ depends on PHY_S32G_SERDES || PHY_S32G_SERDES=n
help
Support for ethernet controller on NXP S32CC SOCs.
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c
index 024d8e10e9188..a3a56b21181a0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c
@@ -16,12 +16,14 @@
#include <linux/of_mdio.h>
#include <linux/of_address.h>
#include <linux/phy.h>
+#include <linux/phy/nxp-s32g-serdes.h>
#include <linux/phylink.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/stmmac.h>
#include "stmmac_platform.h"
+#include "stmmac.h"
#define GMAC_INTF_RATE_125M 125000000 /* 125MHz */
@@ -40,23 +42,89 @@ struct s32_priv_data {
phy_interface_t *intf_mode;
struct clk *tx_clk;
struct clk *rx_clk;
+ /* SGMII PCS provided by the SerDes subsystem (NULL if not SGMII) */
+ struct phylink_pcs *pcs;
};
static int s32_gmac_write_phy_intf_select(struct s32_priv_data *gmac)
{
+ u32 intf_sel;
int ret = 0;
+ switch (*gmac->intf_mode) {
+ case PHY_INTERFACE_MODE_SGMII:
+ intf_sel = S32_PHY_INTF_SEL_SGMII;
+ break;
+ case PHY_INTERFACE_MODE_RGMII:
+ case PHY_INTERFACE_MODE_RGMII_ID:
+ case PHY_INTERFACE_MODE_RGMII_RXID:
+ case PHY_INTERFACE_MODE_RGMII_TXID:
+ intf_sel = S32_PHY_INTF_SEL_RGMII;
+ break;
+ case PHY_INTERFACE_MODE_RMII:
+ intf_sel = S32_PHY_INTF_SEL_RMII;
+ break;
+ case PHY_INTERFACE_MODE_MII:
+ intf_sel = S32_PHY_INTF_SEL_MII;
+ break;
+ default:
+ dev_err(gmac->dev, "Unsupported phy interface mode: %s\n",
+ phy_modes(*gmac->intf_mode));
+ return -EINVAL;
+ }
+
if (gmac->ctrl_sts)
- writel(S32_PHY_INTF_SEL_RGMII, gmac->ctrl_sts);
+ writel(intf_sel, gmac->ctrl_sts);
else
ret = regmap_write(gmac->sts_regmap, gmac->sts_offset,
- S32_PHY_INTF_SEL_RGMII);
+ intf_sel);
dev_dbg(gmac->dev, "PHY mode set to %s\n", phy_modes(*gmac->intf_mode));
return ret;
}
+static int s32_gmac_pcs_init(struct stmmac_priv *priv)
+{
+ struct s32_priv_data *gmac = priv->plat->bsp_priv;
+ struct device_node *pcs_node;
+
+ /*
+ * pcs-handle points at the SerDes XPCS lane child node; its
+ * nxp,xpcs-instance property is what identifies the XPCS instance.
+ */
+ pcs_node = of_parse_phandle(gmac->dev->of_node, "pcs-handle", 0);
+ if (!pcs_node) {
+ dev_dbg(gmac->dev, "no 'pcs-handle' property, SGMII PCS unavailable\n");
+ return 0;
+ }
+
+ gmac->pcs = s32g_serdes_pcs_create(gmac->dev, pcs_node);
+ of_node_put(pcs_node);
+
+ if (IS_ERR(gmac->pcs)) {
+ int err = PTR_ERR(gmac->pcs);
+
+ gmac->pcs = NULL;
+ /* SerDes may not be probed yet - defer probe. */
+ return err;
+ }
+
+ dev_dbg(gmac->dev, "SGMII PCS created via SerDes XPCS\n");
+ return 0;
+}
+
+static struct phylink_pcs *s32_gmac_select_pcs(struct stmmac_priv *priv,
+ phy_interface_t interface)
+{
+ struct s32_priv_data *gmac = priv->plat->bsp_priv;
+
+ if (interface == PHY_INTERFACE_MODE_SGMII && gmac->pcs)
+ return gmac->pcs;
+
+ return NULL;
+}
+
static int s32_gmac_init(struct device *dev, void *priv)
{
struct s32_priv_data *gmac = priv;
@@ -204,6 +272,8 @@ static int s32_dwmac_probe(struct platform_device *pdev)
plat->init = s32_gmac_init;
plat->exit = s32_gmac_exit;
+ plat->pcs_init = s32_gmac_pcs_init;
+ plat->select_pcs = s32_gmac_select_pcs;
plat->clk_tx_i = gmac->tx_clk;
plat->set_clk_tx_rate = stmmac_set_clk_tx_rate;
diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig
index e417fd66f660a..7a4c0da406c96 100644
--- a/drivers/net/pcs/Kconfig
+++ b/drivers/net/pcs/Kconfig
@@ -12,6 +12,17 @@ config PCS_XPCS
This module provides a driver and helper functions for Synopsys
DesignWare XPCS controllers.
+config PCS_NXP_SERDES_XPCS
+ tristate "NXP SerDes XPCS shared core"
+ select PHYLINK
+ select REGMAP
+ help
+ Transport agnostic phylink PCS core for the Synopsys DesignWare
+ Ethernet XPCS and Ethernet PHY of the SerDes subsystems found on
+ NXP S32G and i.MX SoCs. The platform specific register transport
+ (indirect MMIO on S32G, Clause 45 MDIO on i.MX) is implemented as
+ regmap callbacks by the platform drivers selecting this core.
+
config PCS_LYNX
tristate
help
@@ -35,4 +46,18 @@ config PCS_RZN1_MIIC
Renesas RZ/N1, RZ/N2H, and RZ/T2H SoCs. This PCS converts MII to
RMII/RGMII, or can be set in pass-through mode for MII.
+config PCS_NXP_S32G_XPCS
+ tristate "NXP S32G XPCS support"
+ select PHYLINK
+ select REGMAP
+ select PCS_NXP_SERDES_XPCS
+ help
+ This option enables the NXP S32G SerDes XPCS platform glue. It
+ provides the indirect-MMIO register transport and the S32G PMA/PLL
+ bring-up sequences on top of the shared NXP SerDes xPCS core
+ (PCS_NXP_SERDES_XPCS), which supplies the phylink PCS layer for the
+ SGMII / 2500BASE-X lanes of the shared SerDes combo PHY. It is
+ driven by the S32G SerDes PHY driver. Say Y or M here if you need
+ SGMII Ethernet on an NXP S32G2 or S32G3 SoC.
+
endmenu
diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile
index 4f7920618b900..337e9b503553f 100644
--- a/drivers/net/pcs/Makefile
+++ b/drivers/net/pcs/Makefile
@@ -5,6 +5,8 @@ pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \
pcs-xpcs-nxp.o pcs-xpcs-wx.o
obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o
+obj-$(CONFIG_PCS_NXP_SERDES_XPCS) += pcs-nxp-serdes-xpcs.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
+obj-$(CONFIG_PCS_NXP_S32G_XPCS) += pcs-nxp-s32g-xpcs.o
diff --git a/drivers/net/pcs/pcs-nxp-s32g-xpcs.c b/drivers/net/pcs/pcs-nxp-s32g-xpcs.c
new file mode 100644
index 0000000000000..a44f1da54429f
--- /dev/null
+++ b/drivers/net/pcs/pcs-nxp-s32g-xpcs.c
@@ -0,0 +1,947 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2021-2026 NXP
+ *
+ * S32G SerDes XPCS platform glue for the NXP SerDes xPCS shared core.
+ *
+ * This module no longer implements its own phylink PCS. It provides the
+ * S32G specific parts the shared core (pcs-nxp-serdes-xpcs.c) consumes:
+ * - the indirect-MMIO regmap transport. The S32G flat register address
+ * 0x1fXXXX is already identical to the shared core's regmap key
+ * "(devad << 16) | reg" (devad 0x1f == MDIO_MMD_VEND2 for the VR_MII
+ * page, devad 0x1f reg 0x0000 == SR_MII_CTRL/MII_BMCR), so the same
+ * regmap serves both the S32G PMA sequences below and the shared core.
+ * - the S32G PMA/PLL bring-up sequences, exported to the SerDes PHY
+ * driver which drives the ordered dual-XPCS bring-up barrier.
+ * - a struct nxp_serdes_xpcs_desc describing the S32G revision, with a
+ * compat[] table (C37 SGMII + 2500BASE-X) and two pma_config() hooks
+ * (SGMII link-timer / CL37 override, and the 1G<->2.5G PLL switch).
+ */
+
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/pcs/pcs-nxp-s32g-xpcs.h>
+#include <linux/pcs/pcs-nxp-serdes-xpcs.h>
+#include <linux/phy.h>
+#include <linux/phylink.h>
+#include <linux/regmap.h>
+#include <linux/units.h>
+
+enum s32g_xpcs_pll {
+ S32G_XPCS_PLLA, /* Slow PLL */
+ S32G_XPCS_PLLB, /* Fast PLL */
+};
+
+struct s32g_xpcs {
+ void __iomem *base;
+ struct device *dev;
+ unsigned char id;
+ struct regmap *regmap;
+ enum s32g_xpcs_pll ref;
+ bool ext_clk;
+ bool mhz125;
+ enum s32g_xpcs_shared pcie_shared;
+ /* phylink PCS owned by the shared core, created in s32g_xpcs_create() */
+ struct phylink_pcs *pcs;
+};
+
+#define XPCS_TIMEOUT_US (300 * USEC_PER_MSEC)
+#define XPCS_POLL_SLEEP_US 100
+
+#define ADDR1_OFS 0x3fc
+
+#define SR_MII_CTRL 0x1f0000
+#define SS13 BIT(13)
+#define AN_ENABLE BIT(12)
+#define RESTART_AN BIT(9)
+#define DUPLEX_MODE BIT(8)
+#define SS6 BIT(6)
+#define SR_MII_STS 0x1f0001
+#define LINK_STS BIT(2)
+#define VR_MII_DIG_CTRL1 0x1f8000
+#define BYP_PWRUP BIT(1)
+#define EN_2_5G_MODE BIT(2)
+#define CL37_TMR_OVRRIDE BIT(3)
+#define INIT BIT(8)
+#define MAC_AUTO_SW BIT(9)
+#define VR_RST BIT(15)
+#define VR_MII_AN_CTRL 0x1f8001
+#define MII_AN_INTR_EN BIT(0)
+#define PCS_MODE_MASK GENMASK(2, 1)
+#define PCS_MODE_SGMII 2
+#define MII_CTRL BIT(8)
+#define VR_MII_AN_INTR_STS 0x1f8002
+#define CL37_ANCMPLT_INTR BIT(0)
+#define CL37_ANSGM_STS_DUPLEX BIT(1)
+#define CL37_ANSGM_STS_SPEED_MASK GENMASK(3, 2)
+#define CL37_ANSGM_10MBPS 0
+#define CL37_ANSGM_100MBPS 1
+#define CL37_ANSGM_1000MBPS 2
+#define CL37_ANSGM_STS_LINK BIT(4)
+#define VR_MII_DBG_CTRL 0x1f8005
+#define SUPPRESS_LOS_DET BIT(4)
+#define RX_DT_EN_CTL BIT(6)
+#define VR_MII_LINK_TIMER_CTRL 0x1f800a
+#define VR_MII_DIG_STS 0x1f8010
+#define PSEQ_STATE_MASK GENMASK(4, 2)
+#define POWER_GOOD_STATE 0x4
+#define VR_MII_GEN5_12G_16G_TX_GENCTRL1 0x1f8031
+#define TX_CLK_RDY_0 BIT(12)
+#define VR_MII_GEN5_12G_16G_TX_GENCTRL2 0x1f8032
+#define TX_REQ_0 BIT(0)
+#define VR_MII_GEN5_12G_16G_TX_RATE_CTRL 0x1f8034
+#define TX0_RATE_MASK GENMASK(2, 0)
+#define TX0_BAUD_DIV_1 0
+#define TX0_BAUD_DIV_4 2
+#define VR_MII_GEN5_12G_16G_TX_EQ_CTRL0 0x1f8036
+#define TX_EQ_MAIN_MASK GENMASK(13, 8)
+#define VR_MII_GEN5_12G_16G_TX_EQ_CTRL1 0x1f8037
+#define TX_EQ_OVR_RIDE BIT(6)
+#define VR_MII_CONSUMER_10G_TX_TERM_CTRL 0x1f803c
+#define TX0_TERM_MASK GENMASK(2, 0)
+#define VR_MII_GEN5_12G_16G_RX_GENCTRL1 0x1f8051
+#define RX_RST_0 BIT(4)
+#define VR_MII_GEN5_12G_16G_RX_GENCTRL2 0x1f8052
+#define RX_REQ_0 BIT(0)
+#define VR_MII_GEN5_12G_16G_RX_RATE_CTRL 0x1f8054
+#define RX0_RATE_MASK GENMASK(1, 0)
+#define RX0_BAUD_DIV_2 0x1
+#define RX0_BAUD_DIV_8 0x3
+#define VR_MII_GEN5_12G_16G_CDR_CTRL 0x1f8056
+#define VCO_LOW_FREQ_0 BIT(8)
+#define VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL 0x1f8070
+#define MPLLB_SEL_0 BIT(4)
+#define VR_MII_GEN5_12G_16G_MPLLA_CTRL0 0x1f8071
+#define MPLLA_CAL_DISABLE BIT(15)
+#define MLLA_MULTIPLIER_MASK GENMASK(7, 0)
+#define VR_MII_GEN5_12G_MPLLA_CTRL1 0x1f8072
+#define MPLLA_FRACN_CTRL_MASK GENMASK(15, 5)
+#define VR_MII_GEN5_12G_16G_MPLLA_CTRL2 0x1f8073
+#define MPLLA_TX_CLK_DIV_MASK GENMASK(13, 11)
+#define MPLLA_DIV10_CLK_EN BIT(9)
+#define VR_MII_GEN5_12G_16G_MPLLB_CTRL0 0x1f8074
+#define MPLLB_CAL_DISABLE BIT(15)
+#define MLLB_MULTIPLIER_MASK GENMASK(7, 0)
+#define VR_MII_GEN5_12G_MPLLB_CTRL1 0x1f8075
+#define MPLLB_FRACN_CTRL_MASK GENMASK(15, 5)
+#define VR_MII_GEN5_12G_16G_MPLLB_CTRL2 0x1f8076
+#define MPLLB_TX_CLK_DIV_MASK GENMASK(13, 11)
+#define MPLLB_DIV10_CLK_EN BIT(9)
+#define VR_MII_GEN5_12G_MPLLA_CTRL3 0x1f8077
+#define MPLLA_BANDWIDTH_MASK GENMASK(15, 0)
+#define VR_MII_GEN5_12G_MPLLB_CTRL3 0x1f8078
+#define MPLLB_BANDWIDTH_MASK GENMASK(15, 0)
+#define VR_MII_GEN5_12G_16G_MISC_CTRL0 0x1f8090
+#define PLL_CTRL BIT(15)
+#define VR_MII_GEN5_12G_16G_REF_CLK_CTRL 0x1f8091
+#define REF_USE_PAD BIT(1)
+#define REF_CLK_DIV2 BIT(2)
+#define REF_RANGE_MASK GENMASK(5, 3)
+#define RANGE_26_53_MHZ 0x1
+#define RANGE_52_78_MHZ 0x2
+#define REF_MPLLA_DIV2 BIT(6)
+#define REF_MPLLB_DIV2 BIT(7)
+#define VR_MII_GEN5_12G_16G_VCO_CAL_LD0 0x1f8092
+#define VCO_LD_VAL_0_MASK GENMASK(12, 0)
+#define VR_MII_GEN5_12G_VCO_CAL_REF0 0x1f8096
+#define VCO_REF_LD_0_MASK GENMASK(5, 0)
+
+typedef bool (*xpcs_poll_func_t)(struct s32g_xpcs *);
+
+/*
+ * XPCS registers can't be accessed directly and an indirect address method
+ * must be used instead. The 32-bit "reg" is the flat XPCS address and is
+ * identical to the shared core's "(devad << 16) | reg" key.
+ */
+
+static const struct regmap_range s32g_xpcs_wr_ranges[] = {
+ regmap_reg_range(0x1f0000, 0x1f0000),
+ regmap_reg_range(0x1f0004, 0x1f0004),
+ regmap_reg_range(0x1f8000, 0x1f8003),
+ regmap_reg_range(0x1f8005, 0x1f8005),
+ regmap_reg_range(0x1f800a, 0x1f800a),
+ regmap_reg_range(0x1f8012, 0x1f8012),
+ regmap_reg_range(0x1f8015, 0x1f8015),
+ regmap_reg_range(0x1f8030, 0x1f8037),
+ regmap_reg_range(0x1f803c, 0x1f803e),
+ regmap_reg_range(0x1f8050, 0x1f8058),
+ regmap_reg_range(0x1f805c, 0x1f805e),
+ regmap_reg_range(0x1f8064, 0x1f8064),
+ regmap_reg_range(0x1f806b, 0x1f806b),
+ regmap_reg_range(0x1f8070, 0x1f8078),
+ regmap_reg_range(0x1f8090, 0x1f8092),
+ regmap_reg_range(0x1f8096, 0x1f8096),
+ regmap_reg_range(0x1f8099, 0x1f8099),
+ regmap_reg_range(0x1f80a0, 0x1f80a2),
+ regmap_reg_range(0x1f80e1, 0x1f80e1),
+};
+
+static const struct regmap_access_table s32g_xpcs_wr_table = {
+ .yes_ranges = s32g_xpcs_wr_ranges,
+ .n_yes_ranges = ARRAY_SIZE(s32g_xpcs_wr_ranges),
+};
+
+static const struct regmap_range s32g_xpcs_rd_ranges[] = {
+ regmap_reg_range(0x1f0000, 0x1f0006),
+ regmap_reg_range(0x1f000f, 0x1f000f),
+ regmap_reg_range(0x1f0708, 0x1f0710),
+ regmap_reg_range(0x1f8000, 0x1f8003),
+ regmap_reg_range(0x1f8005, 0x1f8005),
+ regmap_reg_range(0x1f800a, 0x1f800a),
+ regmap_reg_range(0x1f8010, 0x1f8012),
+ regmap_reg_range(0x1f8015, 0x1f8015),
+ regmap_reg_range(0x1f8018, 0x1f8018),
+ regmap_reg_range(0x1f8020, 0x1f8020),
+ regmap_reg_range(0x1f8030, 0x1f8037),
+ regmap_reg_range(0x1f803c, 0x1f803c),
+ regmap_reg_range(0x1f8040, 0x1f8040),
+ regmap_reg_range(0x1f8050, 0x1f8058),
+ regmap_reg_range(0x1f805c, 0x1f805e),
+ regmap_reg_range(0x1f8060, 0x1f8060),
+ regmap_reg_range(0x1f8064, 0x1f8064),
+ regmap_reg_range(0x1f806b, 0x1f806b),
+ regmap_reg_range(0x1f8070, 0x1f8078),
+ regmap_reg_range(0x1f8090, 0x1f8092),
+ regmap_reg_range(0x1f8096, 0x1f8096),
+ regmap_reg_range(0x1f8098, 0x1f8099),
+ regmap_reg_range(0x1f80a0, 0x1f80a2),
+ regmap_reg_range(0x1f80e1, 0x1f80e1),
+};
+
+static const struct regmap_access_table s32g_xpcs_rd_table = {
+ .yes_ranges = s32g_xpcs_rd_ranges,
+ .n_yes_ranges = ARRAY_SIZE(s32g_xpcs_rd_ranges),
+};
+
+static int s32g_xpcs_regmap_reg_read(void *context, unsigned int reg,
+ unsigned int *result)
+{
+ struct s32g_xpcs *xpcs = context;
+ u16 ofsleft = (reg >> 8) & 0xffffU;
+ u16 ofsright = (reg & 0xffU);
+
+ writew(ofsleft, xpcs->base + ADDR1_OFS);
+ *result = readw(xpcs->base + (ofsright * 4));
+
+ return 0;
+}
+
+static int s32g_xpcs_regmap_reg_write(void *context, unsigned int reg,
+ unsigned int val)
+{
+ struct s32g_xpcs *xpcs = context;
+ u16 ofsleft = (reg >> 8) & 0xffffU;
+ u16 ofsright = (reg & 0xffU);
+
+ writew(ofsleft, xpcs->base + ADDR1_OFS);
+ writew(val, xpcs->base + (ofsright * 4));
+
+ return 0;
+}
+
+static const struct regmap_config s32g_xpcs0_regmap_config = {
+ .reg_bits = 32,
+ .val_bits = 16,
+ .reg_read = s32g_xpcs_regmap_reg_read,
+ .reg_write = s32g_xpcs_regmap_reg_write,
+ .wr_table = &s32g_xpcs_wr_table,
+ .rd_table = &s32g_xpcs_rd_table,
+ .max_register = 0x1f80e1,
+ .name = "xpcs0",
+};
+
+static const struct regmap_config s32g_xpcs1_regmap_config = {
+ .reg_bits = 32,
+ .val_bits = 16,
+ .reg_read = s32g_xpcs_regmap_reg_read,
+ .reg_write = s32g_xpcs_regmap_reg_write,
+ .wr_table = &s32g_xpcs_wr_table,
+ .rd_table = &s32g_xpcs_rd_table,
+ .max_register = 0x1f80e1,
+ .name = "xpcs1",
+};
+
+static void s32g_xpcs_write_bits(struct s32g_xpcs *xpcs, unsigned int reg,
+ unsigned int mask, unsigned int value)
+{
+ int ret = regmap_write_bits(xpcs->regmap, reg, mask, value);
+
+ if (ret)
+ dev_err(xpcs->dev, "Failed to write bits of XPCS reg: 0x%x\n", reg);
+}
+
+static void s32g_xpcs_write(struct s32g_xpcs *xpcs, unsigned int reg,
+ unsigned int value)
+{
+ int ret = regmap_write(xpcs->regmap, reg, value);
+
+ if (ret)
+ dev_err(xpcs->dev, "Failed to write XPCS reg: 0x%x\n", reg);
+}
+
+static unsigned int s32g_xpcs_read(struct s32g_xpcs *xpcs, unsigned int reg)
+{
+ unsigned int val = 0;
+ int ret;
+
+ ret = regmap_read(xpcs->regmap, reg, &val);
+ if (ret)
+ dev_err(xpcs->dev, "Failed to read XPCS reg: 0x%x\n", reg);
+
+ return val;
+}
+
+/*
+ * Internal XPCS function
+ */
+
+static int s32g_xpcs_wait(struct s32g_xpcs *xpcs, xpcs_poll_func_t func)
+{
+ bool val;
+
+ return read_poll_timeout(func, val, val, XPCS_POLL_SLEEP_US,
+ XPCS_TIMEOUT_US, false, xpcs);
+}
+
+static int s32g_xpcs_wait_bits(struct s32g_xpcs *xpcs, unsigned int reg,
+ unsigned int mask, unsigned int bits)
+{
+ unsigned int val;
+
+ return read_poll_timeout(s32g_xpcs_read, val, (val & mask) == bits,
+ XPCS_POLL_SLEEP_US, XPCS_TIMEOUT_US, false,
+ xpcs, reg);
+}
+
+static unsigned int s32g_xpcs_digital_status(struct s32g_xpcs *xpcs)
+{
+ return s32g_xpcs_read(xpcs, VR_MII_DIG_STS);
+}
+
+static int s32g_xpcs_wait_power_good_state(struct s32g_xpcs *xpcs)
+{
+ unsigned int val;
+
+ return read_poll_timeout(s32g_xpcs_digital_status, val,
+ FIELD_GET(PSEQ_STATE_MASK, val) == POWER_GOOD_STATE,
+ XPCS_POLL_SLEEP_US,
+ XPCS_TIMEOUT_US, false, xpcs);
+}
+
+void s32g_xpcs_vreset(struct s32g_xpcs *xpcs)
+{
+ /* Step 19 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, VR_RST, VR_RST);
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_vreset);
+
+static bool s32g_xpcs_is_not_in_reset(struct s32g_xpcs *xpcs)
+{
+ unsigned int val;
+
+ val = s32g_xpcs_read(xpcs, VR_MII_DIG_CTRL1);
+
+ return !(val & VR_RST);
+}
+
+int s32g_xpcs_wait_vreset(struct s32g_xpcs *xpcs)
+{
+ int ret;
+
+ /* Step 20 */
+ ret = s32g_xpcs_wait(xpcs, s32g_xpcs_is_not_in_reset);
+ if (ret)
+ dev_err(xpcs->dev, "XPCS%d is in reset\n", xpcs->id);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_wait_vreset);
+
+int s32g_xpcs_reset_rx(struct s32g_xpcs *xpcs)
+{
+ int ret = 0;
+
+ /*
+ * On the shared 1G combo lane the PMA power-up is gated by the PCIe
+ * side and BYP_PWRUP stays set, so the power sequencer never reaches
+ * POWER_GOOD on its own and the wait would always time out.
+ */
+ if (xpcs->pcie_shared != S32G_PCIE_XPCS_1G) {
+ ret = s32g_xpcs_wait_power_good_state(xpcs);
+ if (ret) {
+ dev_err(xpcs->dev, "Failed to enter in PGOOD state after vendor reset\n");
+ return ret;
+ }
+ }
+
+ /* Step 21 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL1,
+ RX_RST_0, RX_RST_0);
+
+ /* Step 22 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL1,
+ RX_RST_0, 0);
+
+ /* Step 23 */
+ /* Wait until SR_MII_STS[LINK_STS] = 1 */
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_reset_rx);
+
+static int s32g_xpcs_ref_clk_sel(struct s32g_xpcs *xpcs,
+ enum s32g_xpcs_pll ref_pll)
+{
+ switch (ref_pll) {
+ case S32G_XPCS_PLLA:
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL,
+ MPLLB_SEL_0, 0);
+ xpcs->ref = S32G_XPCS_PLLA;
+ break;
+ case S32G_XPCS_PLLB:
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLL_CMN_CTRL,
+ MPLLB_SEL_0, MPLLB_SEL_0);
+ xpcs->ref = S32G_XPCS_PLLB;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void s32g_xpcs_electrical_configure(struct s32g_xpcs *xpcs)
+{
+ /* Step 2 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_EQ_CTRL0,
+ TX_EQ_MAIN_MASK, FIELD_PREP(TX_EQ_MAIN_MASK, 0xc));
+
+ /* Step 3 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_CONSUMER_10G_TX_TERM_CTRL,
+ TX0_TERM_MASK, FIELD_PREP(TX0_TERM_MASK, 0x4));
+}
+
+static int s32g_xpcs_vco_cfg(struct s32g_xpcs *xpcs, enum s32g_xpcs_pll vco_pll)
+{
+ unsigned int vco_ld = 0;
+ unsigned int vco_ref = 0;
+ unsigned int rx_baud = 0;
+ unsigned int tx_baud = 0;
+
+ switch (vco_pll) {
+ case S32G_XPCS_PLLA:
+ if (xpcs->mhz125) {
+ vco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1360);
+ vco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 17);
+ } else {
+ vco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1350);
+ vco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 27);
+ }
+
+ rx_baud = FIELD_PREP(RX0_RATE_MASK, RX0_BAUD_DIV_8);
+ tx_baud = FIELD_PREP(TX0_RATE_MASK, TX0_BAUD_DIV_4);
+ break;
+ case S32G_XPCS_PLLB:
+ if (xpcs->mhz125) {
+ vco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1350);
+ vco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 27);
+ } else {
+ vco_ld = FIELD_PREP(VCO_LD_VAL_0_MASK, 1344);
+ vco_ref = FIELD_PREP(VCO_REF_LD_0_MASK, 43);
+ }
+
+ rx_baud = FIELD_PREP(RX0_RATE_MASK, RX0_BAUD_DIV_2);
+ tx_baud = FIELD_PREP(TX0_RATE_MASK, TX0_BAUD_DIV_1);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_VCO_CAL_LD0,
+ VCO_LD_VAL_0_MASK, vco_ld);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_VCO_CAL_REF0,
+ VCO_REF_LD_0_MASK, vco_ref);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_RATE_CTRL,
+ TX0_RATE_MASK, tx_baud);
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_RATE_CTRL,
+ RX0_RATE_MASK, rx_baud);
+
+ if (vco_pll == S32G_XPCS_PLLB) {
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_CDR_CTRL,
+ VCO_LOW_FREQ_0, VCO_LOW_FREQ_0);
+ } else {
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_CDR_CTRL,
+ VCO_LOW_FREQ_0, 0);
+ }
+
+ return 0;
+}
+
+static void s32g_xpcs_init_mplla(struct s32g_xpcs *xpcs)
+{
+ unsigned int val;
+
+ /* Step 7 */
+ val = 0;
+ if (xpcs->ext_clk)
+ val |= REF_USE_PAD;
+
+ if (xpcs->mhz125) {
+ val |= REF_MPLLA_DIV2;
+ val |= REF_CLK_DIV2;
+ val |= FIELD_PREP(REF_RANGE_MASK, RANGE_52_78_MHZ);
+ } else {
+ /*
+ * A non-125 MHz reference is 100 MHz, which falls in the
+ * 26-53 MHz range after the internal divider, so select
+ * RANGE_26_53_MHZ.
+ */
+ val |= FIELD_PREP(REF_RANGE_MASK, RANGE_26_53_MHZ);
+ }
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_REF_CLK_CTRL,
+ REF_MPLLA_DIV2 | REF_USE_PAD | REF_RANGE_MASK |
+ REF_CLK_DIV2, val);
+
+ /* Step 8 */
+ if (xpcs->mhz125)
+ val = FIELD_PREP(MLLA_MULTIPLIER_MASK, 80);
+ else
+ val = FIELD_PREP(MLLA_MULTIPLIER_MASK, 25);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLA_CTRL0,
+ MPLLA_CAL_DISABLE | MLLA_MULTIPLIER_MASK,
+ val);
+
+ /* Step 9 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLA_CTRL1,
+ MPLLA_FRACN_CTRL_MASK, 0);
+
+ /* Step 10 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLA_CTRL2,
+ MPLLA_TX_CLK_DIV_MASK | MPLLA_DIV10_CLK_EN,
+ FIELD_PREP(MPLLA_TX_CLK_DIV_MASK, 1) | MPLLA_DIV10_CLK_EN);
+
+ /* Step 11 */
+ if (xpcs->mhz125)
+ val = FIELD_PREP(MPLLA_BANDWIDTH_MASK, 43);
+ else
+ val = FIELD_PREP(MPLLA_BANDWIDTH_MASK, 357);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLA_CTRL3,
+ MPLLA_BANDWIDTH_MASK, val);
+}
+
+static void s32g_xpcs_init_mpllb(struct s32g_xpcs *xpcs)
+{
+ unsigned int val;
+
+ /* Step 7 */
+ val = 0;
+ if (xpcs->ext_clk)
+ val |= REF_USE_PAD;
+
+ if (xpcs->mhz125) {
+ val |= REF_MPLLB_DIV2;
+ val |= REF_CLK_DIV2;
+ val |= FIELD_PREP(REF_RANGE_MASK, RANGE_52_78_MHZ);
+ } else {
+ /*
+ * REF_RANGE selects the reference-clock frequency band and is
+ * shared by both PLLs. For a 100 MHz reference this is the
+ * 26-53 MHz range after the internal divider: RANGE_26_53_MHZ.
+ */
+ val |= FIELD_PREP(REF_RANGE_MASK, RANGE_26_53_MHZ);
+ }
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_REF_CLK_CTRL,
+ REF_MPLLB_DIV2 | REF_USE_PAD | REF_RANGE_MASK |
+ REF_CLK_DIV2, val);
+
+ /* Step 8 */
+ if (xpcs->mhz125)
+ val = FIELD_PREP(MLLB_MULTIPLIER_MASK, 125);
+ else
+ val = FIELD_PREP(MLLB_MULTIPLIER_MASK, 39);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLB_CTRL0,
+ MPLLB_CAL_DISABLE | MLLB_MULTIPLIER_MASK,
+ val);
+
+ /* Step 9 */
+ if (xpcs->mhz125)
+ val = FIELD_PREP(MPLLB_FRACN_CTRL_MASK, 0);
+ else
+ val = FIELD_PREP(MPLLB_FRACN_CTRL_MASK, 1044);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLB_CTRL1,
+ MPLLB_FRACN_CTRL_MASK, val);
+
+ /* Step 10 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MPLLB_CTRL2,
+ MPLLB_TX_CLK_DIV_MASK | MPLLB_DIV10_CLK_EN,
+ FIELD_PREP(MPLLB_TX_CLK_DIV_MASK, 5) | MPLLB_DIV10_CLK_EN);
+
+ /* Step 11 */
+ if (xpcs->mhz125)
+ val = FIELD_PREP(MPLLB_BANDWIDTH_MASK, 68);
+ else
+ val = FIELD_PREP(MPLLB_BANDWIDTH_MASK, 102);
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_MPLLB_CTRL3,
+ MPLLB_BANDWIDTH_MASK, val);
+}
+
+static void s32g_serdes_pma_high_freq_recovery(struct s32g_xpcs *xpcs)
+{
+ /* PCS signal protection, PLL railout recovery */
+ s32g_xpcs_write_bits(xpcs, VR_MII_DBG_CTRL, SUPPRESS_LOS_DET | RX_DT_EN_CTL,
+ SUPPRESS_LOS_DET | RX_DT_EN_CTL);
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_MISC_CTRL0,
+ PLL_CTRL, PLL_CTRL);
+}
+
+static void s32g_serdes_pma_configure_tx_eq_post(struct s32g_xpcs *xpcs)
+{
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_EQ_CTRL1,
+ TX_EQ_OVR_RIDE, TX_EQ_OVR_RIDE);
+}
+
+static int s32g_serdes_bifurcation_pll_transit(struct s32g_xpcs *xpcs,
+ enum s32g_xpcs_pll target_pll)
+{
+ int ret = 0;
+ struct device *dev = xpcs->dev;
+
+ /* Configure XPCS speed and VCO */
+ if (target_pll == S32G_XPCS_PLLA) {
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, EN_2_5G_MODE, 0);
+ s32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLA);
+ } else {
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,
+ EN_2_5G_MODE, EN_2_5G_MODE);
+ s32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLB);
+ }
+
+ /* Signal that clock are not available */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL1,
+ TX_CLK_RDY_0, 0);
+
+ /* Select PLL reference */
+ if (target_pll == S32G_XPCS_PLLA)
+ s32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLA);
+ else
+ s32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLB);
+
+ /* Initiate transmitter TX reconfiguration request */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL2,
+ TX_REQ_0, TX_REQ_0);
+
+ /* Wait for transmitter to reconfigure */
+ ret = s32g_xpcs_wait_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL2,
+ TX_REQ_0, 0);
+ if (ret) {
+ dev_err(dev, "Switch to TX_REQ_0 failed\n");
+ return ret;
+ }
+
+ /* Initiate transmitter RX reconfiguration request */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL2,
+ RX_REQ_0, RX_REQ_0);
+
+ /* Wait for receiver to reconfigure */
+ ret = s32g_xpcs_wait_bits(xpcs, VR_MII_GEN5_12G_16G_RX_GENCTRL2,
+ RX_REQ_0, 0);
+ if (ret) {
+ dev_err(dev, "Switch to RX_REQ_0 failed\n");
+ return ret;
+ }
+
+ /* Signal that clock are available */
+ s32g_xpcs_write_bits(xpcs, VR_MII_GEN5_12G_16G_TX_GENCTRL1,
+ TX_CLK_RDY_0, TX_CLK_RDY_0);
+
+ /* Flush internal logic */
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, INIT, INIT);
+
+ /* Wait for init */
+ ret = s32g_xpcs_wait_bits(xpcs, VR_MII_DIG_CTRL1, INIT, 0);
+ if (ret) {
+ dev_err(dev, "XPCS INIT failed\n");
+ return ret;
+ }
+
+ return ret;
+}
+
+/*
+ * PMA hooks, run from the shared core's pcs_config() after the generic C37
+ * SGMII / 2500BASE-X setup. The S32G context hangs off the shared
+ * nxp_serdes_xpcs priv pointer, set in s32g_xpcs_create().
+ */
+
+static int s32g_xpcs_pma_sgmii(struct nxp_serdes_xpcs *nxpcs)
+{
+ struct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);
+ int ret;
+
+ /*
+ * The shared core sets PCS_MODE_SGMII, TX_CONFIG and MAC_AUTO_SW. The
+ * link timer differs on the PCIe-shared 2.5G lane, where
+ * CL37_TMR_OVRRIDE must be set for the override value to take effect.
+ */
+ if (xpcs->pcie_shared == S32G_PCIE_XPCS_2G5) {
+ s32g_xpcs_write(xpcs, VR_MII_LINK_TIMER_CTRL, 0x2faf);
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,
+ MAC_AUTO_SW, MAC_AUTO_SW);
+ } else {
+ s32g_xpcs_write(xpcs, VR_MII_LINK_TIMER_CTRL, 0x7a1);
+
+ /*
+ * Clearing EN_2_5G_MODE does not reprogram the PMA line rate:
+ * the VCO load, the baud dividers and MPLLB_SEL stay at 2.5G if
+ * the lane last came up as 2500BASE-X. A 2.5G to 1G
+ * renegotiation then links at 1000 Mbps while the PMA keeps
+ * clocking at 3.125 Gbaud and no traffic passes, so run the
+ * full transition back to PLLA. Idempotent on a fresh 1G lane.
+ */
+ ret = s32g_serdes_bifurcation_pll_transit(xpcs,
+ S32G_XPCS_PLLA);
+ if (ret)
+ return ret;
+ }
+
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1,
+ CL37_TMR_OVRRIDE, CL37_TMR_OVRRIDE);
+
+ return 0;
+}
+
+static int s32g_xpcs_pma_2500basex(struct nxp_serdes_xpcs *nxpcs)
+{
+ struct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);
+
+ /*
+ * The shared core has set EN_2_5G_MODE (DW_VR_MII_DIG_CTRL1_2G5_EN)
+ * via nxp_serdes_xpcs_config_2500basex(). S32G additionally needs the
+ * PMA switched from the slow PLLA to the fast PLLB and re-initialised.
+ */
+ return s32g_serdes_bifurcation_pll_transit(xpcs, S32G_XPCS_PLLB);
+}
+
+static int s32g_xpcs_pma_link_up_sgmii(struct nxp_serdes_xpcs *nxpcs,
+ int speed, int duplex)
+{
+ struct s32g_xpcs *xpcs = nxp_serdes_xpcs_get_drvdata(nxpcs);
+
+ /*
+ * A 2.5G SGMII fixed-link keeps interface == SGMII and never reaches
+ * the 2500BASE-X hook, so the PMA would stay on the 1G-class PLLA that
+ * pma_sgmii() programmed at config time. Move to PLLB (which also sets
+ * EN_2_5G_MODE) once the link resolves to 2.5G; below that the
+ * config-time PLLA setting is already right.
+ */
+ if (speed != SPEED_2500)
+ return 0;
+
+ return s32g_serdes_bifurcation_pll_transit(xpcs, S32G_XPCS_PLLB);
+}
+
+static const struct nxp_serdes_xpcs_compat s32g_xpcs_compat[] = {
+ {
+ .interface = PHY_INTERFACE_MODE_SGMII,
+ .supported = nxp_serdes_xpcs_sgmii_features,
+ .an_mode = NXP_SERDES_AN_C37_SGMII,
+ .pma_config = s32g_xpcs_pma_sgmii,
+ .pma_link_up = s32g_xpcs_pma_link_up_sgmii,
+ },
+ {
+ .interface = PHY_INTERFACE_MODE_2500BASEX,
+ .supported = nxp_serdes_xpcs_2500basex_features,
+ .an_mode = NXP_SERDES_2500BASEX,
+ .pma_config = s32g_xpcs_pma_2500basex,
+ },
+ { }
+};
+
+static const struct nxp_serdes_xpcs_desc s32g_xpcs_desc = {
+ .name = "s32g-serdes-xpcs",
+ .compat = s32g_xpcs_compat,
+ /*
+ * S32G runs its own vendor reset (VR_RST) as part of the ordered
+ * dual-XPCS bring-up barrier in the SerDes PHY driver, so the shared
+ * core must not issue the generic BMCR soft reset. S32G3 does not
+ * implement the EEE VR_MII_EEE_MCTRL0/1 registers either.
+ */
+ .quirks = NXP_SERDES_QUIRK_NO_SOFT_RESET | NXP_SERDES_QUIRK_NO_EEE,
+ .reset = NULL,
+};
+
+/*
+ * Serdes functions for initializing/configuring/releasing the xpcs
+ */
+
+int s32g_xpcs_init_plls(struct s32g_xpcs *xpcs)
+{
+ int ret;
+
+ if (!xpcs->ext_clk) {
+ /* Step 1 */
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, BYP_PWRUP, BYP_PWRUP);
+ } else if (xpcs->pcie_shared == S32G_NOT_SHARED) {
+ ret = s32g_xpcs_wait_power_good_state(xpcs);
+ if (ret)
+ return ret;
+ } else if (xpcs->pcie_shared == S32G_PCIE_XPCS_2G5) {
+ ret = s32g_xpcs_wait_power_good_state(xpcs);
+ if (ret)
+ return ret;
+ /* Configure equalization */
+ s32g_serdes_pma_configure_tx_eq_post(xpcs);
+ s32g_xpcs_electrical_configure(xpcs);
+
+ /* Enable receiver recover */
+ s32g_serdes_pma_high_freq_recovery(xpcs);
+ return 0;
+ }
+
+ s32g_xpcs_electrical_configure(xpcs);
+
+ s32g_xpcs_ref_clk_sel(xpcs, S32G_XPCS_PLLA);
+ s32g_xpcs_init_mplla(xpcs);
+ s32g_xpcs_init_mpllb(xpcs);
+ s32g_xpcs_vco_cfg(xpcs, S32G_XPCS_PLLA);
+
+ /*
+ * Step 18: for an internal reference BYP_PWRUP was set in Step 1 to
+ * bypass the power-up sequencer; clear it so the PMA powers up. The
+ * shared 1G lane keeps it set - there the PCIe side drives power-up
+ * and clearing it stalls the XPCS bring-up.
+ */
+ if (!xpcs->ext_clk && xpcs->pcie_shared != S32G_PCIE_XPCS_1G)
+ s32g_xpcs_write_bits(xpcs, VR_MII_DIG_CTRL1, BYP_PWRUP, 0);
+
+ /* Will be cleared by Step 19 Vreset */
+ s32g_xpcs_write_bits(xpcs, SR_MII_CTRL, AN_ENABLE, 0);
+ s32g_xpcs_write_bits(xpcs, SR_MII_CTRL, DUPLEX_MODE, DUPLEX_MODE);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_init_plls);
+
+void s32g_xpcs_disable_an(struct s32g_xpcs *xpcs)
+{
+ s32g_xpcs_write_bits(xpcs, SR_MII_CTRL, DUPLEX_MODE, DUPLEX_MODE);
+ s32g_xpcs_write_bits(xpcs, SR_MII_CTRL, AN_ENABLE, 0);
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_disable_an);
+
+static void s32g_xpcs_pcs_destroy(void *pcs)
+{
+ nxp_serdes_xpcs_destroy(pcs);
+}
+
+/**
+ * s32g_xpcs_create() - allocate and set up one XPCS instance
+ * @dev: the SerDes device the XPCS belongs to; owns the allocation
+ * @id: XPCS instance number within the SerDes subsystem (0 or 1)
+ * @base: mapped register block of that instance
+ * @ext_clk: reference is taken from the external pad rather than internal
+ * @rate: reference clock rate, 100 or 125 MHz
+ * @pcie_shared: whether the lane shares the combo PHY with PCIe
+ *
+ * The instance is devm-allocated against @dev, so it lives as long as the
+ * SerDes device and must not be freed by the caller. The returned handle
+ * is opaque; use s32g_xpcs_pcs() to obtain the phylink PCS created on top
+ * of the NXP SerDes xPCS shared core.
+ *
+ * Return: the XPCS handle, or an ERR_PTR() on failure.
+ */
+struct s32g_xpcs *s32g_xpcs_create(struct device *dev, unsigned char id,
+ void __iomem *base, bool ext_clk,
+ unsigned long rate,
+ enum s32g_xpcs_shared pcie_shared)
+{
+ const struct regmap_config *conf;
+ struct nxp_serdes_xpcs *nxpcs;
+ struct s32g_xpcs *xpcs;
+ struct phylink_pcs *pcs;
+ int ret;
+
+ if (rate != (125 * HZ_PER_MHZ) && rate != (100 * HZ_PER_MHZ)) {
+ dev_err(dev, "XPCS cannot operate @%lu HZ\n", rate);
+ return ERR_PTR(-EINVAL);
+ }
+
+ xpcs = devm_kzalloc(dev, sizeof(*xpcs), GFP_KERNEL);
+ if (!xpcs)
+ return ERR_PTR(-ENOMEM);
+
+ xpcs->base = base;
+ xpcs->ext_clk = ext_clk;
+ xpcs->id = id;
+ xpcs->dev = dev;
+ xpcs->pcie_shared = pcie_shared;
+
+ if (rate == (125 * HZ_PER_MHZ))
+ xpcs->mhz125 = true;
+ else
+ xpcs->mhz125 = false;
+
+ if (!id)
+ conf = &s32g_xpcs0_regmap_config;
+ else
+ conf = &s32g_xpcs1_regmap_config;
+
+ xpcs->regmap = devm_regmap_init(dev, NULL, xpcs, conf);
+ if (IS_ERR(xpcs->regmap))
+ return ERR_PTR(dev_err_probe(dev, PTR_ERR(xpcs->regmap),
+ "Failed to init register map\n"));
+
+ /*
+ * Create the phylink PCS on the shared core, handing it the S32G
+ * regmap as the register transport. SGMII is the initial interface;
+ * phylink re-runs pcs_config() with the real interface at link time.
+ */
+ pcs = nxp_serdes_xpcs_create(dev, xpcs->regmap, NULL, &s32g_xpcs_desc,
+ id, PHY_INTERFACE_MODE_SGMII);
+ if (IS_ERR(pcs))
+ return ERR_PTR(dev_err_probe(dev, PTR_ERR(pcs),
+ "Failed to create SerDes xPCS\n"));
+
+ ret = devm_add_action_or_reset(dev, s32g_xpcs_pcs_destroy, pcs);
+ if (ret)
+ return ERR_PTR(ret);
+
+ /* Let the S32G PMA hooks recover their context from the shared PCS. */
+ nxpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ nxp_serdes_xpcs_set_drvdata(nxpcs, xpcs);
+
+ xpcs->pcs = pcs;
+
+ return xpcs;
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_create);
+
+/**
+ * s32g_xpcs_pcs() - the phylink PCS of an XPCS instance
+ * @xpcs: handle from s32g_xpcs_create()
+ *
+ * Return: the phylink_pcs, owned by the SerDes device.
+ */
+struct phylink_pcs *s32g_xpcs_pcs(struct s32g_xpcs *xpcs)
+{
+ return xpcs->pcs;
+}
+EXPORT_SYMBOL_GPL(s32g_xpcs_pcs);
+
+MODULE_DESCRIPTION("NXP S32G SerDes XPCS driver");
+MODULE_AUTHOR("Jan Petrous (OSS) <jan.petrous@oss.nxp.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/pcs/pcs-nxp-serdes-xpcs.c b/drivers/net/pcs/pcs-nxp-serdes-xpcs.c
new file mode 100644
index 0000000000000..cc739914496e3
--- /dev/null
+++ b/drivers/net/pcs/pcs-nxp-serdes-xpcs.c
@@ -0,0 +1,853 @@
+// SPDX-License-Identifier: GPL-2.0
+/* NXP SerDes XPCS / XPCS-PHY shared core
+ *
+ * Transport agnostic phylink PCS driver for the Ethernet XPCS and Ethernet
+ * PHY (XPCS-PHY) of the SerDes subsystems found on NXP S32G and i.MX SoCs.
+ * The platform glue provides the regmaps and a per revision descriptor
+ * with the compatibility table, quirks and PMA programming sequences.
+ *
+ * The XPCS is a Synopsys DesignWare core, so the Clause 37 / 2500BASE-X /
+ * USXGMII / 10GBASE-R register sequences below are shared with the Synopsys
+ * pcs-xpcs driver and were derived from it. This is a separate driver rather
+ * than an extension of pcs-xpcs because struct dw_xpcs is built around an
+ * mdio_device: it owns the transport, the reset and the identification of a
+ * standalone PCS. That model does not fit these SerDes subsystems, where the
+ * PMA belongs to a combo PHY shared with a PCIe controller, the bring-up is
+ * sequenced across both XPCS instances by the PHY driver, and the register
+ * transport is either indirect MMIO or Clause 45 MDIO. What is left here is
+ * the phylink PCS layer on top of a regmap.
+ *
+ * Keep the register sequences in sync with drivers/net/pcs/pcs-xpcs.c when
+ * fixes apply to both.
+ *
+ * Copyright 2023-2026 NXP
+ * Copyright (c) 2020 Synopsys, Inc. and/or its affiliates.
+ */
+
+#include <linux/device.h>
+#include <linux/ethtool.h>
+#include <linux/iopoll.h>
+#include <linux/mdio.h>
+#include <linux/mii.h>
+#include <linux/module.h>
+#include <linux/pcs/pcs-nxp-serdes-xpcs.h>
+#include <linux/phylink.h>
+
+/* SR_MII USXGMII speed selection */
+#define DW_USXGMII_RST BIT(10)
+#define DW_USXGMII_EN BIT(9)
+#define DW_USXGMII_FULL BIT(8)
+#define DW_USXGMII_SS_MASK (BIT(13) | BIT(6) | BIT(5))
+#define DW_USXGMII_10000 (BIT(13) | BIT(6))
+#define DW_USXGMII_5000 (BIT(13) | BIT(5))
+#define DW_USXGMII_2500 (BIT(5))
+#define DW_USXGMII_1000 (BIT(6))
+#define DW_USXGMII_100 (BIT(13))
+#define DW_USXGMII_10 (0)
+
+/* VR MII MMD registers offsets */
+#define DW_VR_MII_DIG_CTRL1 0x8000
+#define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW BIT(9)
+#define DW_VR_MII_DIG_CTRL1_2G5_EN BIT(2)
+
+#define DW_VR_MII_AN_CTRL 0x8001
+#define DW_VR_MII_TX_CONFIG_MASK BIT(3)
+#define DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII 0x0
+#define DW_VR_MII_PCS_MODE_MASK GENMASK(2, 1)
+#define DW_VR_MII_PCS_MODE_C37_SGMII 0x2
+#define DW_VR_MII_AN_INTR_EN BIT(0)
+
+#define DW_VR_MII_AN_INTR_STS 0x8002
+#define DW_VR_MII_AN_STS_C37_ANCMPLT_INTR BIT(0)
+#define DW_VR_MII_AN_STS_C37_ANSGM_FD BIT(1)
+#define DW_VR_MII_AN_STS_C37_ANSGM_SP GENMASK(3, 2)
+#define DW_VR_MII_C37_ANSGM_SP_10 0x0
+#define DW_VR_MII_C37_ANSGM_SP_100 0x1
+#define DW_VR_MII_C37_ANSGM_SP_1000 0x2
+#define DW_VR_MII_C37_ANSGM_SP_LNKSTS BIT(4)
+#define DW_VR_MII_USX_AN_STS_MASK GENMASK(14, 8)
+
+#define DW_VR_MII_EEE_MCTRL0 0x8006
+#define DW_VR_MII_EEE_LTX_EN BIT(0) /* LPI Tx Enable */
+#define DW_VR_MII_EEE_LRX_EN BIT(1) /* LPI Rx Enable */
+#define DW_VR_MII_EEE_TX_QUIET_EN BIT(2) /* Tx Quiet Enable */
+#define DW_VR_MII_EEE_RX_QUIET_EN BIT(3) /* Rx Quiet Enable */
+#define DW_VR_MII_EEE_TX_EN_CTRL BIT(4) /* Tx Control Enable */
+#define DW_VR_MII_EEE_RX_EN_CTRL BIT(7) /* Rx Control Enable */
+#define DW_VR_MII_EEE_MULT_FACT_100NS GENMASK(11, 8)
+
+#define DW_VR_MII_EEE_MCTRL1 0x800b
+#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */
+
+const int nxp_serdes_xpcs_usxgmii_features[] = {
+ ETHTOOL_LINK_MODE_Pause_BIT,
+ ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+ ETHTOOL_LINK_MODE_Autoneg_BIT,
+ ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
+ ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
+ ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
+ ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
+ __ETHTOOL_LINK_MODE_MASK_NBITS,
+};
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_usxgmii_features);
+
+const int nxp_serdes_xpcs_2500basex_features[] = {
+ ETHTOOL_LINK_MODE_Pause_BIT,
+ ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+ ETHTOOL_LINK_MODE_Autoneg_BIT,
+ ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
+ ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+ __ETHTOOL_LINK_MODE_MASK_NBITS,
+};
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_2500basex_features);
+
+const int nxp_serdes_xpcs_sgmii_features[] = {
+ ETHTOOL_LINK_MODE_Pause_BIT,
+ ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+ ETHTOOL_LINK_MODE_Autoneg_BIT,
+ ETHTOOL_LINK_MODE_10baseT_Half_BIT,
+ ETHTOOL_LINK_MODE_10baseT_Full_BIT,
+ ETHTOOL_LINK_MODE_100baseT_Half_BIT,
+ ETHTOOL_LINK_MODE_100baseT_Full_BIT,
+ ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+ ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+ __ETHTOOL_LINK_MODE_MASK_NBITS,
+};
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_sgmii_features);
+
+static const struct nxp_serdes_xpcs_compat *
+nxp_serdes_xpcs_find_compat(struct nxp_serdes_xpcs *xpcs,
+ phy_interface_t interface)
+{
+ const struct nxp_serdes_xpcs_compat *compat;
+
+ for (compat = xpcs->desc->compat; compat->supported; compat++)
+ if (compat->interface == interface)
+ return compat;
+
+ return NULL;
+}
+
+static void nxp_serdes_xpcs_get_interfaces(struct nxp_serdes_xpcs *xpcs,
+ unsigned long *interfaces)
+{
+ const struct nxp_serdes_xpcs_compat *compat;
+
+ for (compat = xpcs->desc->compat; compat->supported; compat++)
+ __set_bit(compat->interface, interfaces);
+}
+
+int nxp_serdes_xpcs_read(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg)
+{
+ unsigned int val;
+ int ret;
+
+ ret = regmap_read(xpcs->xpcs_regmap, (devad << 16) | (reg & 0xffff),
+ &val);
+ if (ret < 0)
+ return ret;
+
+ return val;
+}
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_read);
+
+int nxp_serdes_xpcs_write(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,
+ u16 val)
+{
+ return regmap_write(xpcs->xpcs_regmap, (devad << 16) | (reg & 0xffff),
+ val);
+}
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_write);
+
+int nxp_serdes_xpcs_modify(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,
+ u16 mask, u16 set)
+{
+ return regmap_update_bits(xpcs->xpcs_regmap,
+ (devad << 16) | (reg & 0xffff), mask, set);
+}
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_modify);
+
+static int nxp_serdes_xpcs_poll_reset(struct nxp_serdes_xpcs *xpcs, int dev)
+{
+ int ret, val;
+
+ ret = read_poll_timeout(nxp_serdes_xpcs_read, val,
+ val < 0 || !(val & BMCR_RESET),
+ 50000, 600000, true, xpcs, dev, MII_BMCR);
+ if (val < 0)
+ ret = val;
+
+ return ret;
+}
+
+static int nxp_serdes_xpcs_soft_reset(struct nxp_serdes_xpcs *xpcs,
+ const struct nxp_serdes_xpcs_compat *compat)
+{
+ int ret, dev;
+
+ switch (compat->an_mode) {
+ case NXP_SERDES_10GBASER:
+ dev = MDIO_MMD_PCS;
+ break;
+ case NXP_SERDES_AN_C37_SGMII:
+ case NXP_SERDES_AN_C37_USXGMII:
+ case NXP_SERDES_2500BASEX:
+ dev = MDIO_MMD_VEND2;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ ret = nxp_serdes_xpcs_write(xpcs, dev, MII_BMCR, BMCR_RESET);
+ if (ret < 0)
+ return ret;
+
+ return nxp_serdes_xpcs_poll_reset(xpcs, dev);
+}
+
+static int nxp_serdes_xpcs_validate(struct phylink_pcs *pcs,
+ unsigned long *supported,
+ const struct phylink_link_state *state)
+{
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(xpcs_supported) = { 0, };
+ const struct nxp_serdes_xpcs_compat *compat;
+ struct nxp_serdes_xpcs *xpcs;
+ int i;
+
+ xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ compat = nxp_serdes_xpcs_find_compat(xpcs, state->interface);
+ if (!compat)
+ return -EINVAL;
+
+ for (i = 0; compat->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++)
+ set_bit(compat->supported[i], xpcs_supported);
+
+ linkmode_and(supported, supported, xpcs_supported);
+
+ return 0;
+}
+
+static unsigned int nxp_serdes_xpcs_inband_caps(struct phylink_pcs *pcs,
+ phy_interface_t interface)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ const struct nxp_serdes_xpcs_compat *compat;
+
+ compat = nxp_serdes_xpcs_find_compat(xpcs, interface);
+ if (!compat)
+ return 0;
+
+ switch (compat->an_mode) {
+ case NXP_SERDES_AN_C37_USXGMII:
+ return LINK_INBAND_ENABLE;
+
+ case NXP_SERDES_AN_C37_SGMII:
+ return LINK_INBAND_DISABLE | LINK_INBAND_ENABLE;
+
+ case NXP_SERDES_10GBASER:
+ case NXP_SERDES_2500BASEX:
+ return LINK_INBAND_DISABLE;
+
+ default:
+ return 0;
+ }
+}
+
+static void nxp_serdes_xpcs_disable(struct phylink_pcs *pcs)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ if (xpcs->desc->reset)
+ xpcs->desc->reset(xpcs);
+}
+
+static void nxp_serdes_xpcs_pre_config(struct phylink_pcs *pcs,
+ phy_interface_t interface)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ const struct nxp_serdes_xpcs_compat *compat;
+ int ret;
+
+ if (xpcs->interface != interface) {
+ if (interface == PHY_INTERFACE_MODE_SGMII)
+ xpcs->need_reset = true;
+ xpcs->interface = interface;
+ }
+
+ if (xpcs->desc->quirks & NXP_SERDES_QUIRK_NO_POLL)
+ xpcs->pcs.poll = false;
+
+ if (xpcs->desc->quirks & NXP_SERDES_QUIRK_NO_SOFT_RESET)
+ xpcs->need_reset = false;
+
+ if (!xpcs->need_reset)
+ return;
+
+ compat = nxp_serdes_xpcs_find_compat(xpcs, interface);
+ if (!compat) {
+ dev_err(xpcs->dev, "unsupported interface %s\n",
+ phy_modes(interface));
+ return;
+ }
+
+ ret = nxp_serdes_xpcs_soft_reset(xpcs, compat);
+ if (ret)
+ dev_err(xpcs->dev, "soft reset failed: %pe\n", ERR_PTR(ret));
+
+ xpcs->need_reset = false;
+}
+
+static int nxp_serdes_xpcs_config_aneg_c37_sgmii(struct nxp_serdes_xpcs *xpcs,
+ unsigned int neg_mode)
+{
+ int ret, mdio_ctrl;
+ u16 mask, val;
+
+ /* Disable AN while PCS_MODE and TX_CONFIG are switched to C37 SGMII on
+ * the MAC side, then re-enable it for in-band mode. MAC_AUTO_SW lets
+ * the hardware apply the negotiated speed and duplex.
+ */
+ mdio_ctrl = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);
+ if (mdio_ctrl < 0)
+ return mdio_ctrl;
+
+ if (mdio_ctrl & BMCR_ANENABLE) {
+ ret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
+ mdio_ctrl & ~BMCR_ANENABLE);
+ if (ret < 0)
+ return ret;
+ }
+
+ mask = DW_VR_MII_PCS_MODE_MASK | DW_VR_MII_TX_CONFIG_MASK;
+ val = FIELD_PREP(DW_VR_MII_PCS_MODE_MASK,
+ DW_VR_MII_PCS_MODE_C37_SGMII);
+ val |= FIELD_PREP(DW_VR_MII_TX_CONFIG_MASK,
+ DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII);
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_CTRL,
+ mask, val);
+ if (ret < 0)
+ return ret;
+
+ val = 0;
+ mask = DW_VR_MII_DIG_CTRL1_2G5_EN | DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW;
+
+ if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+ val = DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW;
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,
+ mask, val);
+ if (ret < 0)
+ return ret;
+
+ if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+ ret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
+ mdio_ctrl | BMCR_ANENABLE);
+
+ return ret;
+}
+
+static int nxp_serdes_xpcs_config_2500basex(struct nxp_serdes_xpcs *xpcs)
+{
+ int ret;
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,
+ DW_VR_MII_DIG_CTRL1_2G5_EN |
+ DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW,
+ DW_VR_MII_DIG_CTRL1_2G5_EN);
+ if (ret < 0)
+ return ret;
+
+ return nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR,
+ BMCR_ANENABLE | BMCR_SPEED1000 |
+ BMCR_SPEED100, BMCR_SPEED1000);
+}
+
+static int nxp_serdes_xpcs_config_10gbaser(struct nxp_serdes_xpcs *xpcs)
+{
+ return nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1,
+ DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW, 0);
+}
+
+static int nxp_serdes_xpcs_do_config(struct nxp_serdes_xpcs *xpcs,
+ phy_interface_t interface,
+ const unsigned long *advertising,
+ unsigned int neg_mode)
+{
+ const struct nxp_serdes_xpcs_compat *compat;
+ int ret;
+
+ compat = nxp_serdes_xpcs_find_compat(xpcs, interface);
+ if (!compat)
+ return -ENODEV;
+
+ switch (compat->an_mode) {
+ case NXP_SERDES_10GBASER:
+ ret = nxp_serdes_xpcs_config_10gbaser(xpcs);
+ if (ret)
+ return ret;
+ break;
+ case NXP_SERDES_AN_C37_USXGMII:
+ break;
+ case NXP_SERDES_AN_C37_SGMII:
+ ret = nxp_serdes_xpcs_config_aneg_c37_sgmii(xpcs, neg_mode);
+ if (ret)
+ return ret;
+ break;
+ case NXP_SERDES_2500BASEX:
+ ret = nxp_serdes_xpcs_config_2500basex(xpcs);
+ if (ret)
+ return ret;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ if (compat->pma_config) {
+ ret = compat->pma_config(xpcs);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int nxp_serdes_xpcs_config(struct phylink_pcs *pcs,
+ unsigned int neg_mode,
+ phy_interface_t interface,
+ const unsigned long *advertising,
+ bool permit_pause_to_mac)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ return nxp_serdes_xpcs_do_config(xpcs, interface, advertising, neg_mode);
+}
+
+static int nxp_serdes_xpcs_get_state_c37_sgmii(struct nxp_serdes_xpcs *xpcs,
+ unsigned int neg_mode,
+ struct phylink_link_state *state)
+{
+ int ret;
+
+ state->link = false;
+ state->speed = SPEED_UNKNOWN;
+ state->duplex = DUPLEX_UNKNOWN;
+ state->pause = 0;
+
+ /* Until AN completes, the status still holds the previous SGMII word */
+ if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+ ret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);
+ if (ret < 0)
+ return ret;
+
+ if (!(ret & BMSR_ANEGCOMPLETE))
+ return 0;
+ }
+
+ ret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS);
+ if (ret < 0)
+ return ret;
+
+ state->an_complete = ret & DW_VR_MII_AN_STS_C37_ANCMPLT_INTR;
+
+ if (ret & DW_VR_MII_C37_ANSGM_SP_LNKSTS) {
+ int speed_value;
+
+ state->link = true;
+
+ speed_value = FIELD_GET(DW_VR_MII_AN_STS_C37_ANSGM_SP, ret);
+ if (speed_value == DW_VR_MII_C37_ANSGM_SP_1000)
+ state->speed = SPEED_1000;
+ else if (speed_value == DW_VR_MII_C37_ANSGM_SP_100)
+ state->speed = SPEED_100;
+ else
+ state->speed = SPEED_10;
+
+ if (ret & DW_VR_MII_AN_STS_C37_ANSGM_FD)
+ state->duplex = DUPLEX_FULL;
+ else
+ state->duplex = DUPLEX_HALF;
+ } else if (ret == DW_VR_MII_AN_STS_C37_ANCMPLT_INTR) {
+ int speed, duplex;
+
+ state->link = true;
+
+ speed = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMCR);
+ if (speed < 0)
+ return speed;
+
+ speed &= BMCR_SPEED100 | BMCR_SPEED1000;
+ if (speed == BMCR_SPEED1000)
+ state->speed = SPEED_1000;
+ else if (speed == BMCR_SPEED100)
+ state->speed = SPEED_100;
+ else if (speed == 0)
+ state->speed = SPEED_10;
+
+ duplex = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2,
+ MII_ADVERTISE);
+ if (duplex < 0)
+ return duplex;
+
+ if (duplex & ADVERTISE_1000XFULL)
+ state->duplex = DUPLEX_FULL;
+ else if (duplex & ADVERTISE_1000XHALF)
+ state->duplex = DUPLEX_HALF;
+
+ nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2,
+ DW_VR_MII_AN_INTR_STS, 0);
+ }
+
+ return 0;
+}
+
+static int nxp_serdes_xpcs_get_state_2500basex(struct nxp_serdes_xpcs *xpcs,
+ struct phylink_link_state *state)
+{
+ int ret;
+
+ ret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, MII_BMSR);
+ if (ret < 0) {
+ state->link = 0;
+ return ret;
+ }
+
+ state->link = !!(ret & BMSR_LSTATUS);
+ if (!state->link)
+ return 0;
+
+ state->speed = SPEED_2500;
+ state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;
+ state->duplex = DUPLEX_FULL;
+
+ return 0;
+}
+
+static int nxp_serdes_xpcs_get_state_c37_usxgmii(struct nxp_serdes_xpcs *xpcs,
+ struct phylink_link_state *state)
+{
+ u16 usxg_an_status;
+ int ret;
+
+ state->link = false;
+ state->speed = SPEED_UNKNOWN;
+ state->duplex = DUPLEX_UNKNOWN;
+ state->pause = 0;
+
+ ret = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_VEND2, DW_VR_MII_AN_INTR_STS);
+ if (ret < 0)
+ return ret;
+
+ usxg_an_status = FIELD_GET(DW_VR_MII_USX_AN_STS_MASK, ret);
+ if (!(usxg_an_status & BIT(6)))
+ return 0;
+
+ state->link = true;
+ state->an_complete = true;
+ phylink_decode_usxgmii_word(state, usxg_an_status << 7);
+
+ return 0;
+}
+
+static void nxp_serdes_xpcs_get_state(struct phylink_pcs *pcs,
+ unsigned int neg_mode,
+ struct phylink_link_state *state)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ const struct nxp_serdes_xpcs_compat *compat;
+ int stat1;
+ int ret;
+
+ compat = nxp_serdes_xpcs_find_compat(xpcs, state->interface);
+ if (!compat)
+ return;
+
+ switch (compat->an_mode) {
+ case NXP_SERDES_10GBASER:
+ stat1 = nxp_serdes_xpcs_read(xpcs, MDIO_MMD_PCS, MDIO_STAT1);
+ if (stat1 < 0) {
+ state->link = false;
+ break;
+ }
+
+ if (stat1 & MDIO_STAT1_FAULT)
+ nxp_serdes_xpcs_do_config(xpcs, state->interface, NULL,
+ PHYLINK_PCS_NEG_NONE);
+
+ state->link = !!(stat1 & MDIO_STAT1_LSTATUS);
+ if (state->link &&
+ state->interface == PHY_INTERFACE_MODE_10GBASER) {
+ state->speed = SPEED_10000;
+ state->duplex = DUPLEX_FULL;
+ }
+ break;
+ case NXP_SERDES_AN_C37_USXGMII:
+ ret = nxp_serdes_xpcs_get_state_c37_usxgmii(xpcs, state);
+ if (ret)
+ dev_err(xpcs->dev, "%s returned %pe\n",
+ "nxp_serdes_xpcs_get_state_c37_usxgmii",
+ ERR_PTR(ret));
+ break;
+ case NXP_SERDES_AN_C37_SGMII:
+ ret = nxp_serdes_xpcs_get_state_c37_sgmii(xpcs, neg_mode, state);
+ if (ret)
+ dev_err(xpcs->dev, "%s returned %pe\n",
+ "nxp_serdes_xpcs_get_state_c37_sgmii",
+ ERR_PTR(ret));
+ break;
+ case NXP_SERDES_2500BASEX:
+ ret = nxp_serdes_xpcs_get_state_2500basex(xpcs, state);
+ if (ret)
+ dev_err(xpcs->dev, "%s returned %pe\n",
+ "nxp_serdes_xpcs_get_state_2500basex",
+ ERR_PTR(ret));
+ break;
+ default:
+ return;
+ }
+}
+
+static void nxp_serdes_xpcs_link_up_sgmii_1000basex(struct nxp_serdes_xpcs *xpcs,
+ unsigned int neg_mode,
+ phy_interface_t interface,
+ int speed, int duplex)
+{
+ int ret;
+
+ if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+ return;
+
+ if (interface == PHY_INTERFACE_MODE_1000BASEX) {
+ if (speed != SPEED_1000) {
+ dev_err(xpcs->dev, "%s: speed %dMbps not supported\n",
+ __func__, speed);
+ return;
+ }
+
+ if (duplex != DUPLEX_FULL)
+ dev_err(xpcs->dev, "%s: half duplex not supported\n",
+ __func__);
+ }
+
+ ret = nxp_serdes_xpcs_write(xpcs, MDIO_MMD_VEND2, MII_BMCR,
+ mii_bmcr_encode_fixed(speed, duplex));
+ if (ret)
+ dev_err(xpcs->dev, "%s: write returned %pe\n",
+ __func__, ERR_PTR(ret));
+}
+
+static void nxp_serdes_xpcs_link_up_usxgmii(struct nxp_serdes_xpcs *xpcs,
+ int speed)
+{
+ int ret, speed_sel;
+
+ switch (speed) {
+ case SPEED_10:
+ speed_sel = DW_USXGMII_10;
+ break;
+ case SPEED_100:
+ speed_sel = DW_USXGMII_100;
+ break;
+ case SPEED_1000:
+ speed_sel = DW_USXGMII_1000;
+ break;
+ case SPEED_2500:
+ speed_sel = DW_USXGMII_2500;
+ break;
+ case SPEED_5000:
+ speed_sel = DW_USXGMII_5000;
+ break;
+ case SPEED_10000:
+ speed_sel = DW_USXGMII_10000;
+ break;
+ default:
+ return;
+ }
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_PCS, BIT(15) | MDIO_CTRL1,
+ DW_USXGMII_EN, DW_USXGMII_EN);
+ if (ret < 0)
+ goto out;
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR,
+ DW_USXGMII_SS_MASK,
+ speed_sel | DW_USXGMII_FULL);
+ if (ret < 0)
+ goto out;
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_PCS, BIT(15) | MDIO_CTRL1,
+ DW_USXGMII_RST, DW_USXGMII_RST);
+ if (ret < 0)
+ goto out;
+
+ return;
+
+out:
+ dev_err(xpcs->dev, "%s: XPCS access returned %pe\n",
+ __func__, ERR_PTR(ret));
+}
+
+static void nxp_serdes_xpcs_link_up(struct phylink_pcs *pcs,
+ unsigned int neg_mode,
+ phy_interface_t interface, int speed,
+ int duplex)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+ const struct nxp_serdes_xpcs_compat *compat;
+ int ret;
+
+ switch (interface) {
+ case PHY_INTERFACE_MODE_USXGMII:
+ nxp_serdes_xpcs_link_up_usxgmii(xpcs, speed);
+ break;
+
+ case PHY_INTERFACE_MODE_SGMII:
+ case PHY_INTERFACE_MODE_1000BASEX:
+ nxp_serdes_xpcs_link_up_sgmii_1000basex(xpcs, neg_mode,
+ interface, speed,
+ duplex);
+ break;
+
+ default:
+ break;
+ }
+
+ compat = nxp_serdes_xpcs_find_compat(xpcs, interface);
+ if (compat && compat->pma_link_up) {
+ ret = compat->pma_link_up(xpcs, speed, duplex);
+ if (ret)
+ dev_err(xpcs->dev, "%s: pma_link_up returned %pe\n",
+ __func__, ERR_PTR(ret));
+ }
+}
+
+static void nxp_serdes_xpcs_an_restart(struct phylink_pcs *pcs)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2, MII_BMCR, BMCR_ANRESTART,
+ BMCR_ANRESTART);
+}
+
+static int nxp_serdes_xpcs_config_eee(struct nxp_serdes_xpcs *xpcs,
+ bool enable)
+{
+ u16 mask, val;
+ int ret;
+
+ mask = DW_VR_MII_EEE_LTX_EN | DW_VR_MII_EEE_LRX_EN |
+ DW_VR_MII_EEE_TX_QUIET_EN | DW_VR_MII_EEE_RX_QUIET_EN |
+ DW_VR_MII_EEE_TX_EN_CTRL | DW_VR_MII_EEE_RX_EN_CTRL |
+ DW_VR_MII_EEE_MULT_FACT_100NS;
+
+ if (enable)
+ val = DW_VR_MII_EEE_LTX_EN | DW_VR_MII_EEE_LRX_EN |
+ DW_VR_MII_EEE_TX_QUIET_EN | DW_VR_MII_EEE_RX_QUIET_EN |
+ DW_VR_MII_EEE_TX_EN_CTRL | DW_VR_MII_EEE_RX_EN_CTRL |
+ /* No platform needs a non-default multiply factor */
+ FIELD_PREP(DW_VR_MII_EEE_MULT_FACT_100NS, 0);
+ else
+ val = 0;
+
+ ret = nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2,
+ DW_VR_MII_EEE_MCTRL0, mask, val);
+ if (ret < 0)
+ return ret;
+
+ return nxp_serdes_xpcs_modify(xpcs, MDIO_MMD_VEND2,
+ DW_VR_MII_EEE_MCTRL1,
+ DW_VR_MII_EEE_TRN_LPI,
+ enable ? DW_VR_MII_EEE_TRN_LPI : 0);
+}
+
+static void nxp_serdes_xpcs_disable_eee(struct phylink_pcs *pcs)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ if (xpcs->desc->quirks & NXP_SERDES_QUIRK_NO_EEE)
+ return;
+
+ nxp_serdes_xpcs_config_eee(xpcs, false);
+}
+
+static void nxp_serdes_xpcs_enable_eee(struct phylink_pcs *pcs)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ if (xpcs->desc->quirks & NXP_SERDES_QUIRK_NO_EEE)
+ return;
+
+ nxp_serdes_xpcs_config_eee(xpcs, true);
+}
+
+static const struct phylink_pcs_ops nxp_serdes_xpcs_phylink_ops = {
+ .pcs_validate = nxp_serdes_xpcs_validate,
+ .pcs_inband_caps = nxp_serdes_xpcs_inband_caps,
+ .pcs_pre_config = nxp_serdes_xpcs_pre_config,
+ .pcs_disable = nxp_serdes_xpcs_disable,
+ .pcs_config = nxp_serdes_xpcs_config,
+ .pcs_get_state = nxp_serdes_xpcs_get_state,
+ .pcs_an_restart = nxp_serdes_xpcs_an_restart,
+ .pcs_link_up = nxp_serdes_xpcs_link_up,
+ .pcs_disable_eee = nxp_serdes_xpcs_disable_eee,
+ .pcs_enable_eee = nxp_serdes_xpcs_enable_eee,
+};
+
+/**
+ * nxp_serdes_xpcs_create() - create a NXP SerDes XPCS phylink PCS
+ * @dev: device the PCS belongs to, used for error reporting
+ * @xpcs_regmap: regmap of the XPCS registers
+ * @phy_regmap: regmap of the XPCS-PHY registers, may be NULL
+ * @desc: revision descriptor, see &struct nxp_serdes_xpcs_desc
+ * @portid: index of the XPCS port, used to select the shared MPLL
+ * @interface: PHY interface mode used for the link
+ *
+ * The regmaps must stay valid until nxp_serdes_xpcs_destroy() has been called.
+ *
+ * Return: a pointer to a &struct phylink_pcs, or an ERR_PTR() on failure.
+ */
+struct phylink_pcs *nxp_serdes_xpcs_create(struct device *dev,
+ struct regmap *xpcs_regmap,
+ struct regmap *phy_regmap,
+ const struct nxp_serdes_xpcs_desc *desc,
+ u8 portid, phy_interface_t interface)
+{
+ struct nxp_serdes_xpcs *xpcs;
+
+ if (!desc || !desc->compat)
+ return ERR_PTR(-EINVAL);
+
+ xpcs = kzalloc_obj(struct nxp_serdes_xpcs, GFP_KERNEL);
+ if (!xpcs)
+ return ERR_PTR(-ENOMEM);
+
+ xpcs->dev = dev;
+ xpcs->xpcs_regmap = xpcs_regmap;
+ xpcs->phy_regmap = phy_regmap;
+ xpcs->desc = desc;
+ xpcs->pma_id = desc->pma_id;
+ xpcs->portid = portid;
+ xpcs->interface = interface;
+ xpcs->pcs.ops = &nxp_serdes_xpcs_phylink_ops;
+ xpcs->pcs.poll = true;
+ nxp_serdes_xpcs_get_interfaces(xpcs, xpcs->pcs.supported_interfaces);
+ xpcs->need_reset = true;
+
+ return &xpcs->pcs;
+}
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_create);
+
+void nxp_serdes_xpcs_destroy(struct phylink_pcs *pcs)
+{
+ struct nxp_serdes_xpcs *xpcs = phylink_pcs_to_nxp_serdes_xpcs(pcs);
+
+ if (!xpcs)
+ return;
+
+ kfree(xpcs);
+}
+EXPORT_SYMBOL_GPL(nxp_serdes_xpcs_destroy);
+
+MODULE_DESCRIPTION("NXP SerDes XPCS shared core");
+MODULE_AUTHOR("Clark Wang <xiaoning.wang@nxp.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig
index 7557b624be8fc..59a86597eaa0b 100644
--- a/drivers/phy/freescale/Kconfig
+++ b/drivers/phy/freescale/Kconfig
@@ -77,3 +77,12 @@ config PHY_FSL_LYNX_28G
found on NXP's Layerscape platforms such as LX2160A.
Used to change the protocol running on SerDes lanes at runtime.
Only useful for a restricted set of Ethernet protocols.
+
+config PHY_S32G_SERDES
+ tristate "NXP S32G SERDES support"
+ depends on ARCH_S32 || COMPILE_TEST
+ depends on PCS_NXP_S32G_XPCS
+ select GENERIC_PHY
+ help
+ This option enables support for S32G SerDes PHY used for
+ PCIe & Ethernet
diff --git a/drivers/phy/freescale/Makefile b/drivers/phy/freescale/Makefile
index 5b0e180d6972f..1a0aec7909178 100644
--- a/drivers/phy/freescale/Makefile
+++ b/drivers/phy/freescale/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_PHY_FSL_LYNX_CORE) += phy-fsl-lynx-core.o
obj-$(CONFIG_PHY_FSL_LYNX_10G) += phy-fsl-lynx-10g.o
obj-$(CONFIG_PHY_FSL_LYNX_28G) += phy-fsl-lynx-28g.o
obj-$(CONFIG_PHY_FSL_SAMSUNG_HDMI_PHY) += phy-fsl-samsung-hdmi.o
+obj-$(CONFIG_PHY_S32G_SERDES) += phy-nxp-s32g-serdes.o
diff --git a/drivers/phy/freescale/phy-nxp-s32g-serdes.c b/drivers/phy/freescale/phy-nxp-s32g-serdes.c
new file mode 100644
index 0000000000000..e81878137f2e1
--- /dev/null
+++ b/drivers/phy/freescale/phy-nxp-s32g-serdes.c
@@ -0,0 +1,1057 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SerDes driver for S32G SoCs
+ *
+ * Copyright 2021-2026 NXP
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/pcs/pcs-nxp-s32g-xpcs.h>
+#include <linux/phy/nxp-s32g-serdes.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/units.h>
+
+#define S32G_SERDES_XPCS_MAX 2
+
+#define EXTERNAL_CLK_NAME "ext"
+#define INTERNAL_CLK_NAME "ref"
+
+/* Serdes Sub system registers */
+
+#define S32G_PCIE_PHY_GEN_CTRL 0x0
+#define REF_USE_PAD BIT(17)
+#define RX_SRIS_MODE BIT(9)
+
+#define S32G_PCIE_PHY_MPLLA_CTRL 0x10
+#define MPLL_STATE BIT(30)
+
+#define S32G_SS_RW_REG_0 0xF0
+#define SUBMODE_MASK GENMASK(2, 0)
+#define CLKEN_MASK BIT(23)
+#define PHY0_CR_PARA_SEL BIT(9)
+
+/* PCIe phy subsystem registers */
+
+#define S32G_PHY_REG_ADDR 0x0
+#define PHY_REG_EN BIT(31)
+
+#define S32G_PHY_REG_DATA 0x4
+
+#define RAWLANE0_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN 0x3019
+#define RAWLANE1_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN 0x3119
+
+/*
+ * DesignWare PCIe PHY reference-clock architecture, passed as the submode
+ * to phy_set_mode_ext(phy, PHY_MODE_PCIE, submode).
+ *
+ * These describe how the reference clock is distributed and whether spread
+ * spectrum is used, a different axis from the role submodes in
+ * include/linux/phy/pcie.h (PHY_MODE_PCIE_RC/_EP/_BIFURCATION, 20..22), which
+ * they do not overlap. Kept driver-private until a second driver needs a
+ * non-default architecture; pcie-nxp-s32g.c always asks for CRNS.
+ */
+enum pcie_phy_mode {
+ CRNS = 0, /* Common Reference Clock, No Spread Spectrum */
+ CRSS = 1, /* Common Reference Clock, Spread Spectrum */
+ SRNS = 2, /* Separate Reference Clock, No Spread Spectrum */
+ SRIS = 3 /* Separate Reference Clock, Spread Spectrum */
+};
+
+/*
+ * SS_RW_REG_0[SUBSYS_MODE] holds the reference-manual "Mode N" number. It is
+ * not in the devicetree: it is derived from the per-lane child nodes (lane
+ * function + XPCS instance). The reference clock is validated against the
+ * result, never used to select it.
+ */
+
+enum s32g_lane_fn {
+ S32G_LANE_UNUSED = 0,
+ S32G_LANE_PCIE,
+ S32G_LANE_XPCS,
+};
+
+struct s32g_lane_desc {
+ enum s32g_lane_fn fn;
+ u32 xpcs_instance; /* valid iff fn == S32G_LANE_XPCS */
+};
+
+struct s32g_serdes_mode {
+ u32 submode; /* SS_RW_REG_0[SUBSYS_MODE] value */
+ struct s32g_lane_desc lane[2];
+ unsigned long refclk[2]; /* permitted reference clock rates (Hz), 0-terminated */
+};
+
+struct s32g_serdes_soc_data {
+ const struct s32g_serdes_mode *modes;
+ unsigned int n_modes;
+};
+
+#define S32G_LANE_IS_PCIE { .fn = S32G_LANE_PCIE }
+#define S32G_LANE_IS_XPCS(i) { .fn = S32G_LANE_XPCS, .xpcs_instance = (i) }
+
+#define S32G_REFCLK_100MHZ (100 * HZ_PER_MHZ)
+#define S32G_REFCLK_125MHZ (125 * HZ_PER_MHZ)
+
+/*
+ * Supported working modes (S32G2/S32G3, 1G). Each row has a unique lane mux.
+ * PCIe needs a 100 MHz reference, so modes 0/1/2 take 100 MHz only; the
+ * dual-XPCS mode 3 takes 100 or 125 MHz.
+ */
+static const struct s32g_serdes_mode s32g_serdes_modes[] = {
+ { 0, { S32G_LANE_IS_PCIE, S32G_LANE_IS_PCIE },
+ { S32G_REFCLK_100MHZ } },
+ { 1, { S32G_LANE_IS_PCIE, S32G_LANE_IS_XPCS(0) },
+ { S32G_REFCLK_100MHZ } },
+ { 2, { S32G_LANE_IS_PCIE, S32G_LANE_IS_XPCS(1) },
+ { S32G_REFCLK_100MHZ } },
+ { 3, { S32G_LANE_IS_XPCS(0), S32G_LANE_IS_XPCS(1) },
+ { S32G_REFCLK_100MHZ, S32G_REFCLK_125MHZ } },
+};
+
+/*
+ * S32G2 and S32G3 share this table for now but keep distinct compatibles with
+ * no fallback: the full RM mode tables differ per SoC and per SerDes instance
+ * (only S32G3 SerDes_1 has the 3.125G dual-XPCS mode 4) and will diverge once
+ * 2500BASE-X lands.
+ */
+static const struct s32g_serdes_soc_data s32g2_serdes_soc_data = {
+ .modes = s32g_serdes_modes,
+ .n_modes = ARRAY_SIZE(s32g_serdes_modes),
+};
+
+static const struct s32g_serdes_soc_data s32g3_serdes_soc_data = {
+ .modes = s32g_serdes_modes,
+ .n_modes = ARRAY_SIZE(s32g_serdes_modes),
+};
+
+struct s32g_serdes_ctrl {
+ void __iomem *ss_base;
+ struct reset_control *rst;
+ struct clk_bulk_data *clks;
+ int nclks;
+ u32 ss_mode;
+ unsigned long ref_clk_rate;
+ bool ext_clk;
+};
+
+struct s32g_pcie_ctrl {
+ void __iomem *phy_base;
+ struct reset_control *rst;
+ struct phy *phy;
+ enum pcie_phy_mode phy_mode;
+ bool powered_on;
+};
+
+struct s32g_xpcs_ctrl {
+ struct s32g_xpcs *phys[2]; /* indexed by XPCS instance */
+ void __iomem *base[2]; /* xpcs0 / xpcs1 register blocks */
+};
+
+struct s32g_serdes {
+ struct s32g_serdes_ctrl ctrl;
+ struct s32g_pcie_ctrl pcie;
+ struct s32g_xpcs_ctrl xpcs;
+ struct s32g_lane_desc lane[2];
+ const struct s32g_serdes_soc_data *soc_data;
+ struct device *dev;
+};
+
+/* PCIe phy subsystem */
+
+#define S32G_SERDES_PCIE_FREQ (100 * HZ_PER_MHZ)
+
+static int s32g_pcie_check_clk(struct s32g_serdes *serdes)
+{
+ struct s32g_serdes_ctrl *sctrl = &serdes->ctrl;
+ unsigned long rate = sctrl->ref_clk_rate;
+
+ if (rate != S32G_SERDES_PCIE_FREQ) {
+ dev_err(serdes->dev, "PCIe PHY cannot operate at %lu HZ\n", rate);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/* Serdes RM says the PHY is operational within 3.4 to 5.2 ms after reset
+ * release, depending on the reference clock (MPLL_STATE = 1).
+ */
+#define S32G_SERDES_LOCK_TIMEOUT_US (10 * USEC_PER_MSEC)
+#define S32G_SERDES_LOCK_SLEEP_US 50
+
+/*
+ * MPLL_STATE signals "PHY operational" after the subsystem reset is released.
+ * It must be observed before any PHY or XPCS PMA access in every mode, not
+ * just on the PCIe path: skipping it on the XPCS-only modes left init
+ * dependent on incidental timing, and a printk between reset release and XPCS
+ * setup was enough to break it.
+ */
+static int s32g_serdes_wait_phy_operational(struct s32g_serdes *serdes)
+{
+ void __iomem *reg = serdes->ctrl.ss_base + S32G_PCIE_PHY_MPLLA_CTRL;
+ u32 val;
+ int ret;
+
+ ret = readl_poll_timeout(reg, val, (val & MPLL_STATE),
+ S32G_SERDES_LOCK_SLEEP_US,
+ S32G_SERDES_LOCK_TIMEOUT_US);
+ if (ret)
+ dev_err(serdes->dev, "SerDes PHY not operational\n");
+
+ return ret;
+}
+
+static int s32g_pcie_phy_power_on_common(struct s32g_serdes *serdes)
+{
+ struct s32g_serdes_ctrl *sctrl = &serdes->ctrl;
+ struct s32g_pcie_ctrl *pcie = &serdes->pcie;
+ u32 reg;
+ int ret;
+
+ ret = s32g_pcie_check_clk(serdes);
+ if (ret)
+ return ret;
+
+ reg = readl(sctrl->ss_base + S32G_PCIE_PHY_GEN_CTRL);
+
+ if (pcie->phy_mode == SRIS)
+ reg |= RX_SRIS_MODE;
+ else
+ reg &= ~RX_SRIS_MODE;
+
+ if (sctrl->ext_clk)
+ reg |= REF_USE_PAD;
+ else
+ reg &= ~REF_USE_PAD;
+
+ writel(reg, sctrl->ss_base + S32G_PCIE_PHY_GEN_CTRL);
+
+ ret = s32g_serdes_wait_phy_operational(serdes);
+ if (ret)
+ return ret;
+
+ /* Set PHY register access to CR interface */
+ reg = readl(sctrl->ss_base + S32G_SS_RW_REG_0);
+ reg |= PHY0_CR_PARA_SEL;
+ writel(reg, sctrl->ss_base + S32G_SS_RW_REG_0);
+
+ return 0;
+}
+
+static void s32g_pcie_phy_write(struct s32g_serdes *serdes, u32 reg, u32 val)
+{
+ writel(PHY_REG_EN, serdes->pcie.phy_base + S32G_PHY_REG_ADDR);
+ writel(reg | PHY_REG_EN, serdes->pcie.phy_base + S32G_PHY_REG_ADDR);
+ usleep_range(100, 110);
+ writel(val, serdes->pcie.phy_base + S32G_PHY_REG_DATA);
+ usleep_range(100, 110);
+ writel(0, serdes->pcie.phy_base + S32G_PHY_REG_ADDR);
+}
+
+static int s32g_pcie_phy_power_on(struct s32g_serdes *serdes)
+{
+ struct s32g_pcie_ctrl *pcie = &serdes->pcie;
+ struct s32g_serdes_ctrl *ctrl = &serdes->ctrl;
+ u32 iq_ovrd_in;
+ int ret;
+
+ ret = s32g_pcie_phy_power_on_common(serdes);
+ if (ret)
+ return ret;
+
+ /* RX_EQ_DELTA_IQ_OVRD enable and override value for PCIe lanes */
+ iq_ovrd_in = RAWLANE0_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN;
+
+ s32g_pcie_phy_write(serdes, iq_ovrd_in, 0x3);
+ s32g_pcie_phy_write(serdes, iq_ovrd_in, 0x13);
+
+ if (ctrl->ss_mode == 0) {
+ iq_ovrd_in = RAWLANE1_DIG_PCS_XF_RX_EQ_DELTA_IQ_OVRD_IN;
+
+ s32g_pcie_phy_write(serdes, iq_ovrd_in, 0x3);
+ s32g_pcie_phy_write(serdes, iq_ovrd_in, 0x13);
+ }
+
+ pcie->powered_on = true;
+
+ return 0;
+}
+
+/* PCIe phy ops function */
+
+static int s32g_serdes_phy_power_on(struct phy *p)
+{
+ struct s32g_serdes *serdes = phy_get_drvdata(p);
+
+ return s32g_pcie_phy_power_on(serdes);
+}
+
+static int s32g_serdes_phy_power_off(struct phy *p)
+{
+ struct s32g_serdes *serdes = phy_get_drvdata(p);
+
+ serdes->pcie.powered_on = false;
+
+ return 0;
+}
+
+static inline bool is_pcie_phy_mode_valid(int mode)
+{
+ switch (mode) {
+ case CRNS:
+ case CRSS:
+ case SRNS:
+ case SRIS:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static int s32g_serdes_phy_set_mode_ext(struct phy *p,
+ enum phy_mode mode, int submode)
+{
+ struct s32g_serdes *serdes = phy_get_drvdata(p);
+
+ if (mode != PHY_MODE_PCIE)
+ return -EINVAL;
+
+ if (!is_pcie_phy_mode_valid(submode))
+ return -EINVAL;
+
+ /*
+ * Spread-spectrum and common-reference clocking both need an
+ * external shared reference, and neither may be combined with an
+ * SGMII lane on the same subsystem.
+ */
+ if ((submode == CRSS || submode == SRIS) &&
+ (serdes->ctrl.ss_mode != 0 || !serdes->ctrl.ext_clk))
+ return -EINVAL;
+
+ if (serdes->pcie.powered_on)
+ dev_warn(serdes->dev, "The phy is already powered on.\n");
+
+ serdes->pcie.phy_mode = submode;
+
+ return 0;
+}
+
+static const struct phy_ops serdes_pcie_ops = {
+ .power_on = s32g_serdes_phy_power_on,
+ .power_off = s32g_serdes_phy_power_off,
+ .set_mode = s32g_serdes_phy_set_mode_ext,
+};
+
+static struct phy *s32g_serdes_phy_xlate(struct device *dev,
+ const struct of_phandle_args *args)
+{
+ struct s32g_serdes *serdes;
+
+ serdes = dev_get_drvdata(dev);
+ if (!serdes)
+ return ERR_PTR(-EINVAL);
+
+ return serdes->pcie.phy;
+}
+
+/* XPCS subsystem */
+
+static int s32g_serdes_xpcs_setup(struct s32g_serdes *serdes, u32 instance)
+{
+ struct s32g_serdes_ctrl *ctrl = &serdes->ctrl;
+ struct s32g_xpcs_ctrl *xpcs_ctrl = &serdes->xpcs;
+ enum s32g_xpcs_shared shared = S32G_NOT_SHARED;
+ struct device *dev = serdes->dev;
+ struct s32g_xpcs *xpcs;
+
+ /*
+ * In the PCIe + SGMII modes the XPCS shares the combo PHY with the
+ * PCIe lane. The 2.5G shared variant (S32G_PCIE_XPCS_2G5) is selected at
+ * run time and is not wired up yet.
+ */
+ if (ctrl->ss_mode == 1 || ctrl->ss_mode == 2)
+ shared = S32G_PCIE_XPCS_1G;
+
+ xpcs = s32g_xpcs_create(dev, instance, xpcs_ctrl->base[instance],
+ ctrl->ext_clk, ctrl->ref_clk_rate, shared);
+ if (IS_ERR(xpcs))
+ return PTR_ERR(xpcs);
+
+ xpcs_ctrl->phys[instance] = xpcs;
+
+ return 0;
+}
+
+static int s32g_serdes_init_xpcs(struct s32g_serdes *serdes)
+{
+ struct s32g_serdes_ctrl *ctrl = &serdes->ctrl;
+ struct s32g_xpcs_ctrl *xpcs = &serdes->xpcs;
+ struct s32g_xpcs *order[2];
+ size_t i;
+ int ret;
+
+ /*
+ * Mode 3 initialises XPCS1 before XPCS0. Carried over from the vendor
+ * driver and undocumented in the RM. Do not reorder.
+ */
+ switch (ctrl->ss_mode) {
+ case 0:
+ return 0;
+ case 1:
+ order[0] = xpcs->phys[0];
+ order[1] = NULL;
+ break;
+ case 2:
+ order[0] = xpcs->phys[1];
+ order[1] = NULL;
+ break;
+ case 3:
+ order[0] = xpcs->phys[1];
+ order[1] = xpcs->phys[0];
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(order); i++) {
+ if (!order[i])
+ continue;
+
+ ret = s32g_xpcs_init_plls(order[i]);
+ if (ret)
+ return ret;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(order); i++) {
+ if (!order[i])
+ continue;
+
+ s32g_xpcs_vreset(order[i]);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(order); i++) {
+ if (!order[i])
+ continue;
+
+ ret = s32g_xpcs_wait_vreset(order[i]);
+ if (ret)
+ return ret;
+
+ ret = s32g_xpcs_reset_rx(order[i]);
+ if (ret)
+ return ret;
+
+ s32g_xpcs_disable_an(order[i]);
+ }
+
+ return 0;
+}
+
+/* Serdes subsystem */
+
+static int s32g_serdes_assert_reset(struct s32g_serdes *serdes)
+{
+ struct device *dev = serdes->dev;
+ int ret;
+
+ ret = reset_control_assert(serdes->pcie.rst);
+ if (ret) {
+ dev_err(dev, "Failed to assert PCIE reset: %d\n", ret);
+ return ret;
+ }
+
+ ret = reset_control_assert(serdes->ctrl.rst);
+ if (ret) {
+ dev_err(dev, "Failed to assert SerDes reset: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int s32g_serdes_deassert_reset(struct s32g_serdes *serdes)
+{
+ struct device *dev = serdes->dev;
+ int ret;
+
+ ret = reset_control_deassert(serdes->pcie.rst);
+ if (ret) {
+ dev_err(dev, "Failed to deassert PCIE reset: %d\n", ret);
+ return ret;
+ }
+
+ ret = reset_control_deassert(serdes->ctrl.rst);
+ if (ret) {
+ dev_err(dev, "Failed to deassert SerDes reset: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static bool s32g_serdes_lane_matches(const struct s32g_lane_desc *mode_lane,
+ const struct s32g_lane_desc *req_lane)
+{
+ if (mode_lane->fn != req_lane->fn)
+ return false;
+
+ if (mode_lane->fn == S32G_LANE_XPCS)
+ return mode_lane->xpcs_instance == req_lane->xpcs_instance;
+
+ return true;
+}
+
+static const char *s32g_lane_fn_str(const struct s32g_lane_desc *lane)
+{
+ switch (lane->fn) {
+ case S32G_LANE_PCIE:
+ return "PCIe";
+ case S32G_LANE_XPCS:
+ return lane->xpcs_instance ? "XPCS1" : "XPCS0";
+ default:
+ return "unused";
+ }
+}
+
+static int s32g_serdes_derive_mode(struct s32g_serdes *serdes)
+{
+ const struct s32g_serdes_mode *match = NULL;
+ unsigned int i;
+ bool refclk_ok = false;
+
+ for (i = 0; i < serdes->soc_data->n_modes; i++) {
+ const struct s32g_serdes_mode *m = &serdes->soc_data->modes[i];
+
+ if (s32g_serdes_lane_matches(&m->lane[0], &serdes->lane[0]) &&
+ s32g_serdes_lane_matches(&m->lane[1], &serdes->lane[1])) {
+ match = m;
+ break;
+ }
+ }
+
+ if (!match)
+ return dev_err_probe(serdes->dev, -EINVAL,
+ "No SerDes mode matches the lane configuration\n");
+
+ for (i = 0; i < ARRAY_SIZE(match->refclk) && match->refclk[i]; i++) {
+ if (serdes->ctrl.ref_clk_rate == match->refclk[i]) {
+ refclk_ok = true;
+ break;
+ }
+ }
+
+ if (!refclk_ok)
+ return dev_err_probe(serdes->dev, -EINVAL,
+ "Reference clock %lu Hz invalid for mode %u\n",
+ serdes->ctrl.ref_clk_rate, match->submode);
+
+ serdes->ctrl.ss_mode = match->submode;
+
+ dev_dbg(serdes->dev,
+ "SerDes mode %u selected: lane0=%s lane1=%s, ref-clk %lu MHz (%s)\n",
+ match->submode,
+ s32g_lane_fn_str(&serdes->lane[0]),
+ s32g_lane_fn_str(&serdes->lane[1]),
+ serdes->ctrl.ref_clk_rate / HZ_PER_MHZ,
+ serdes->ctrl.ext_clk ? "external" : "internal");
+
+ return 0;
+}
+
+static int s32g_serdes_init(struct s32g_serdes *serdes)
+{
+ struct s32g_serdes_ctrl *ctrl = &serdes->ctrl;
+ u32 reg0;
+ int ret;
+
+ ret = clk_bulk_prepare_enable(ctrl->nclks, ctrl->clks);
+ if (ret) {
+ dev_err(serdes->dev, "Failed to enable SerDes clocks\n");
+ return ret;
+ }
+
+ ret = s32g_serdes_assert_reset(serdes);
+ if (ret)
+ goto disable_clks;
+
+ /* Set serdes mode */
+ reg0 = readl(ctrl->ss_base + S32G_SS_RW_REG_0);
+ reg0 &= ~SUBMODE_MASK;
+ reg0 |= FIELD_PREP(SUBMODE_MASK, ctrl->ss_mode);
+ writel(reg0, ctrl->ss_base + S32G_SS_RW_REG_0);
+
+ /* Set Clock source: internal or external */
+ reg0 = readl(ctrl->ss_base + S32G_SS_RW_REG_0);
+ if (ctrl->ext_clk)
+ reg0 &= ~CLKEN_MASK;
+ else
+ reg0 |= CLKEN_MASK;
+
+ writel(reg0, ctrl->ss_base + S32G_SS_RW_REG_0);
+
+ /*
+ * Route the combo-PHY reference: REF_USE_PAD is 0 for the internal
+ * reference, 1 for the external pad. s32g_pcie_phy_power_on_common()
+ * programs it too, but the XPCS lane is brought up before any PCIe
+ * power-on. Left at the bootloader default the XPCS PMA never powers
+ * up, VR_RST never self-clears and every register reads back constant.
+ */
+ reg0 = readl(ctrl->ss_base + S32G_PCIE_PHY_GEN_CTRL);
+ if (ctrl->ext_clk)
+ reg0 |= REF_USE_PAD;
+ else
+ reg0 &= ~REF_USE_PAD;
+ writel(reg0, ctrl->ss_base + S32G_PCIE_PHY_GEN_CTRL);
+ dev_dbg(serdes->dev,
+ "GEN_CTRL after ref-clk route: 0x%08x (REF_USE_PAD=%d)\n",
+ reg0, !!(reg0 & REF_USE_PAD));
+
+ /* Wait for the selection of working mode (as per the manual specs) */
+ usleep_range(100, 110);
+
+ ret = s32g_serdes_deassert_reset(serdes);
+ if (ret)
+ goto disable_clks;
+
+ /*
+ * The PHY needs up to 5.2 ms after reset release to become
+ * operational. Nothing may touch the PHY or the XPCS PMA before
+ * that point.
+ */
+ ret = s32g_serdes_wait_phy_operational(serdes);
+ if (ret)
+ goto disable_clks;
+
+ ret = s32g_serdes_init_xpcs(serdes);
+ if (ret) {
+ dev_err(serdes->dev, "XPCS init failed\n");
+ goto disable_clks;
+ }
+
+ dev_info(serdes->dev, "SerDes subsystem mode %u (refclk=%lu MHz)\n",
+ ctrl->ss_mode, ctrl->ref_clk_rate / HZ_PER_MHZ);
+
+ return 0;
+
+disable_clks:
+ /* Already on an error path; ignore the return value. */
+ s32g_serdes_assert_reset(serdes);
+ clk_bulk_disable_unprepare(serdes->ctrl.nclks,
+ serdes->ctrl.clks);
+
+ return ret;
+}
+
+static void s32g_serdes_disable(void *data)
+{
+ struct s32g_serdes *serdes = data;
+
+ s32g_serdes_assert_reset(serdes);
+ clk_bulk_disable_unprepare(serdes->ctrl.nclks, serdes->ctrl.clks);
+}
+
+static int s32g_serdes_get_ctrl_resources(struct platform_device *pdev,
+ struct s32g_serdes *serdes)
+{
+ struct s32g_serdes_ctrl *ctrl = &serdes->ctrl;
+ struct device *dev = &pdev->dev;
+ int ret, idx, i;
+
+ ctrl->ss_base = devm_platform_ioremap_resource_byname(pdev, "ss-pcie");
+ if (IS_ERR(ctrl->ss_base))
+ return dev_err_probe(dev, PTR_ERR(ctrl->ss_base),
+ "Failed to map 'ss-pcie'\n");
+
+ ctrl->rst = devm_reset_control_get_exclusive(dev, "serdes");
+ if (IS_ERR(ctrl->rst))
+ return dev_err_probe(dev, PTR_ERR(ctrl->rst),
+ "Failed to get 'serdes' reset control\n");
+
+ ctrl->nclks = devm_clk_bulk_get_all(dev, &ctrl->clks);
+ if (ctrl->nclks < 1) {
+ ret = ctrl->nclks ? : -EINVAL;
+ return dev_err_probe(dev, ret,
+ "Failed to get SerDes clocks\n");
+ }
+
+ idx = -1;
+ for (i = 0; i < ctrl->nclks; i++) {
+ if (!ctrl->clks[i].id)
+ continue;
+
+ if (!strcmp(ctrl->clks[i].id, EXTERNAL_CLK_NAME)) {
+ idx = i;
+ ctrl->ext_clk = true;
+ break;
+ }
+
+ if (!strcmp(ctrl->clks[i].id, INTERNAL_CLK_NAME))
+ idx = i;
+ }
+
+ if (idx < 0) {
+ dev_err(dev, "Failed to get Phy reference clock source\n");
+ return -EINVAL;
+ }
+
+ ctrl->ref_clk_rate = clk_get_rate(ctrl->clks[idx].clk);
+ if (!ctrl->ref_clk_rate) {
+ dev_err(dev, "Failed to get Phy reference clock rate\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int s32g_serdes_get_pcie_resources(struct platform_device *pdev,
+ struct s32g_serdes *serdes)
+{
+ struct s32g_pcie_ctrl *pcie = &serdes->pcie;
+ struct device *dev = &pdev->dev;
+
+ pcie->phy_base = devm_platform_ioremap_resource_byname(pdev,
+ "pcie-phy");
+ if (IS_ERR(pcie->phy_base))
+ return dev_err_probe(dev, PTR_ERR(pcie->phy_base),
+ "Failed to map 'pcie-phy'\n");
+
+ pcie->rst = devm_reset_control_get_exclusive(dev, "pcie");
+ if (IS_ERR(pcie->rst))
+ return dev_err_probe(dev, PTR_ERR(pcie->rst),
+ "Failed to get 'pcie' reset control\n");
+
+ return 0;
+}
+
+static int s32g_serdes_get_xpcs_resources(struct platform_device *pdev,
+ struct s32g_serdes *serdes)
+{
+ struct s32g_xpcs_ctrl *xpcs = &serdes->xpcs;
+ struct device *dev = &pdev->dev;
+
+ xpcs->base[0] = devm_platform_ioremap_resource_byname(pdev, "xpcs0");
+ if (IS_ERR(xpcs->base[0]))
+ return dev_err_probe(dev, PTR_ERR(xpcs->base[0]),
+ "Failed to map 'xpcs0'\n");
+
+ xpcs->base[1] = devm_platform_ioremap_resource_byname(pdev, "xpcs1");
+ if (IS_ERR(xpcs->base[1]))
+ return dev_err_probe(dev, PTR_ERR(xpcs->base[1]),
+ "Failed to map 'xpcs1'\n");
+
+ return 0;
+}
+
+static int s32g_serdes_parse_lane(struct s32g_serdes *serdes,
+ struct device_node *child_node)
+{
+ struct device *dev = serdes->dev;
+ u32 index, instance;
+ int ret;
+
+ ret = of_property_read_u32(child_node, "reg", &index);
+ if (ret || index > 1)
+ return dev_err_probe(dev, ret ? : -EINVAL,
+ "Invalid lane index in %pOFn\n",
+ child_node);
+
+ if (serdes->lane[index].fn != S32G_LANE_UNUSED)
+ return dev_err_probe(dev, -EINVAL,
+ "Duplicate lane %u\n", index);
+
+ if (of_device_is_compatible(child_node, "nxp,s32g-serdes-pcie-phy")) {
+ serdes->lane[index].fn = S32G_LANE_PCIE;
+ return 0;
+ }
+
+ if (of_device_is_compatible(child_node, "nxp,s32g-serdes-xpcs")) {
+ ret = of_property_read_u32(child_node, "nxp,xpcs-instance",
+ &instance);
+ if (ret || instance > 1)
+ return dev_err_probe(dev, ret ? : -EINVAL,
+ "Invalid nxp,xpcs-instance in %pOFn\n",
+ child_node);
+
+ serdes->lane[index].fn = S32G_LANE_XPCS;
+ serdes->lane[index].xpcs_instance = instance;
+ return 0;
+ }
+
+ dev_warn(dev, "Skipping unknown child node %pOFn\n", child_node);
+
+ return 0;
+}
+
+static int s32g_serdes_create_pcie_phy(struct s32g_serdes *serdes,
+ struct device_node *child_node)
+{
+ struct phy_provider *phy_provider;
+ struct device *dev = serdes->dev;
+ struct phy *phy;
+
+ phy = devm_phy_create(dev, child_node, &serdes_pcie_ops);
+ if (IS_ERR(phy))
+ return PTR_ERR(phy);
+
+ phy_set_drvdata(phy, serdes);
+
+ phy->attrs.mode = PHY_MODE_PCIE;
+ serdes->pcie.phy = phy;
+
+ phy_provider = devm_of_phy_provider_register(&phy->dev,
+ s32g_serdes_phy_xlate);
+ if (IS_ERR(phy_provider))
+ return PTR_ERR(phy_provider);
+
+ return 0;
+}
+
+static int s32g_serdes_parse_lanes(struct device *dev,
+ struct s32g_serdes *serdes)
+{
+ int ret;
+
+ for_each_available_child_of_node_scoped(dev->of_node, of_port) {
+ ret = s32g_serdes_parse_lane(serdes, of_port);
+ if (ret)
+ return ret;
+ }
+
+ /*
+ * In the x2 mode both lane children are PCIe, but they form one link
+ * behind one controller, so create a single phy bound to the first
+ * PCIe child. One phy per child would register two providers for one
+ * link.
+ */
+ for_each_available_child_of_node_scoped(dev->of_node, of_port) {
+ if (!of_device_is_compatible(of_port,
+ "nxp,s32g-serdes-pcie-phy"))
+ continue;
+
+ ret = s32g_serdes_create_pcie_phy(serdes, of_port);
+ if (ret)
+ return ret;
+
+ break;
+ }
+
+ return 0;
+}
+
+static int s32g_serdes_setup_xpcs_lanes(struct s32g_serdes *serdes)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < ARRAY_SIZE(serdes->lane); i++) {
+ if (serdes->lane[i].fn != S32G_LANE_XPCS)
+ continue;
+
+ ret = s32g_serdes_xpcs_setup(serdes,
+ serdes->lane[i].xpcs_instance);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int s32g_serdes_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ const struct s32g_serdes_soc_data *soc_data;
+ struct s32g_serdes *serdes;
+ int ret;
+
+ serdes = devm_kzalloc(dev, sizeof(*serdes), GFP_KERNEL);
+ if (!serdes)
+ return -ENOMEM;
+
+ serdes->dev = dev;
+
+ soc_data = of_device_get_match_data(dev);
+ if (!soc_data)
+ return -EINVAL;
+
+ serdes->soc_data = soc_data;
+
+ ret = s32g_serdes_get_ctrl_resources(pdev, serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_get_pcie_resources(pdev, serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_get_xpcs_resources(pdev, serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_parse_lanes(dev, serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_derive_mode(serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_setup_xpcs_lanes(serdes);
+ if (ret)
+ return ret;
+
+ ret = s32g_serdes_init(serdes);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, s32g_serdes_disable, serdes);
+ if (ret)
+ return ret;
+
+ /*
+ * Publish drvdata last: s32g_serdes_pcs_create() takes a NULL drvdata
+ * as its -EPROBE_DEFER condition, so setting it earlier can hand a MAC
+ * a PCS while the PLLs are still down, or after a failed probe has
+ * released it.
+ */
+ platform_set_drvdata(pdev, serdes);
+
+ return 0;
+}
+
+static int s32g_serdes_suspend(struct device *device)
+{
+ struct s32g_serdes *serdes = dev_get_drvdata(device);
+
+ clk_bulk_disable_unprepare(serdes->ctrl.nclks, serdes->ctrl.clks);
+
+ return 0;
+}
+
+static int s32g_serdes_resume(struct device *device)
+{
+ struct s32g_serdes *serdes = dev_get_drvdata(device);
+ struct s32g_pcie_ctrl *pcie = &serdes->pcie;
+ int ret;
+
+ ret = s32g_serdes_init(serdes);
+ if (ret) {
+ dev_err(device, "Failed to initialize\n");
+ return ret;
+ }
+
+ /* Restore PCIe phy power */
+ if (pcie->powered_on) {
+ ret = s32g_pcie_phy_power_on(serdes);
+ if (ret)
+ dev_err(device, "Failed to power-on PCIe phy\n");
+ }
+
+ return ret;
+}
+
+/**
+ * s32g_serdes_pcs_create() - look up the phylink PCS for a SerDes XPCS lane
+ * @dev: the consumer (MAC) device
+ * @np: the SerDes XPCS lane child node
+ *
+ * A device link is created between @dev and the SerDes device so that the
+ * MAC is unbound before the SerDes it depends on. If the SerDes device has
+ * not probed (far enough) yet, -EPROBE_DEFER is returned so the caller
+ * retries later.
+ *
+ * Return: the phylink_pcs on success, or an ERR_PTR() on failure. The
+ * returned phylink_pcs is owned by the SerDes device and must not be freed
+ * by the caller.
+ */
+struct phylink_pcs *s32g_serdes_pcs_create(struct device *dev,
+ struct device_node *np)
+{
+ struct platform_device *pdev;
+ struct device_node *pcs_np;
+ struct s32g_serdes *serdes;
+ struct device_link *link;
+ u32 instance;
+
+ /*
+ * The lane child's unit address is the physical lane; the PCS is
+ * identified by the XPCS instance routed to that lane.
+ */
+ if (of_property_read_u32(np, "nxp,xpcs-instance", &instance))
+ return ERR_PTR(-EINVAL);
+
+ if (instance >= S32G_SERDES_XPCS_MAX)
+ return ERR_PTR(-EINVAL);
+
+ pcs_np = of_get_parent(np);
+ if (!pcs_np)
+ return ERR_PTR(-ENODEV);
+
+ if (!of_device_is_available(pcs_np)) {
+ of_node_put(pcs_np);
+ return ERR_PTR(-ENODEV);
+ }
+
+ pdev = of_find_device_by_node(pcs_np);
+ of_node_put(pcs_np);
+ if (!pdev)
+ return ERR_PTR(-EPROBE_DEFER);
+
+ serdes = platform_get_drvdata(pdev);
+ if (!serdes) {
+ put_device(&pdev->dev);
+ return ERR_PTR(-EPROBE_DEFER);
+ }
+
+ if (!serdes->xpcs.phys[instance]) {
+ put_device(&pdev->dev);
+ return ERR_PTR(-EPROBE_DEFER);
+ }
+
+ link = device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+ put_device(&pdev->dev);
+ if (!link)
+ return ERR_PTR(-EINVAL);
+
+ return s32g_xpcs_pcs(serdes->xpcs.phys[instance]);
+}
+EXPORT_SYMBOL_GPL(s32g_serdes_pcs_create);
+
+static const struct of_device_id s32g_serdes_match[] = {
+ {
+ .compatible = "nxp,s32g2-serdes",
+ .data = &s32g2_serdes_soc_data,
+ },
+ {
+ .compatible = "nxp,s32g3-serdes",
+ .data = &s32g3_serdes_soc_data,
+ },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, s32g_serdes_match);
+
+/* noirq, like the PCIe controller using this PHY */
+static const struct dev_pm_ops s32g_serdes_pm_ops = {
+ NOIRQ_SYSTEM_SLEEP_PM_OPS(s32g_serdes_suspend,
+ s32g_serdes_resume)
+};
+
+static struct platform_driver s32g_serdes_driver = {
+ .probe = s32g_serdes_probe,
+ .driver = {
+ .name = "phy-s32g-serdes",
+ .of_match_table = s32g_serdes_match,
+ .pm = pm_sleep_ptr(&s32g_serdes_pm_ops),
+ },
+};
+module_platform_driver(s32g_serdes_driver);
+
+MODULE_AUTHOR("Ghennadi Procopciuc <ghennadi.procopciuc@nxp.com>");
+MODULE_DESCRIPTION("NXP S32G SerDes driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/pcs/pcs-nxp-s32g-xpcs.h b/include/linux/pcs/pcs-nxp-s32g-xpcs.h
new file mode 100644
index 0000000000000..7e1dfb6b638f3
--- /dev/null
+++ b/include/linux/pcs/pcs-nxp-s32g-xpcs.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright 2021-2026 NXP
+ */
+#ifndef PCS_NXP_S32G_XPCS_H
+#define PCS_NXP_S32G_XPCS_H
+
+#include <linux/types.h>
+
+struct device;
+struct phylink_pcs;
+
+/*
+ * Opaque. The XPCS state, including its regmap and the embedded
+ * phylink_pcs, is private to the PCS driver; the SerDes PHY driver only
+ * ever holds pointers handed out by s32g_xpcs_create().
+ */
+struct s32g_xpcs;
+
+/*
+ * Whether the XPCS shares the combo PHY with the PCIe lane. In the shared
+ * modes the PMA power-up is driven from the PCIe side, which changes the
+ * bring-up sequence.
+ */
+enum s32g_xpcs_shared {
+ S32G_NOT_SHARED,
+ S32G_PCIE_XPCS_1G,
+ S32G_PCIE_XPCS_2G5,
+};
+
+struct s32g_xpcs *s32g_xpcs_create(struct device *dev, unsigned char id,
+ void __iomem *base, bool ext_clk,
+ unsigned long rate,
+ enum s32g_xpcs_shared pcie_shared);
+struct phylink_pcs *s32g_xpcs_pcs(struct s32g_xpcs *xpcs);
+
+/*
+ * Bring-up steps, called by the SerDes PHY driver. They are separate
+ * because the dual-XPCS mode needs cross-instance barriers: every
+ * instance must complete a step before any instance starts the next.
+ */
+int s32g_xpcs_init_plls(struct s32g_xpcs *xpcs);
+void s32g_xpcs_vreset(struct s32g_xpcs *xpcs);
+int s32g_xpcs_wait_vreset(struct s32g_xpcs *xpcs);
+int s32g_xpcs_reset_rx(struct s32g_xpcs *xpcs);
+void s32g_xpcs_disable_an(struct s32g_xpcs *xpcs);
+
+#endif /* PCS_NXP_S32G_XPCS_H */
diff --git a/include/linux/pcs/pcs-nxp-serdes-xpcs.h b/include/linux/pcs/pcs-nxp-serdes-xpcs.h
new file mode 100644
index 0000000000000..2579c6b14a61e
--- /dev/null
+++ b/include/linux/pcs/pcs-nxp-serdes-xpcs.h
@@ -0,0 +1,100 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * NXP SerDes XPCS shared core
+ * Copyright 2026 NXP
+ */
+
+#ifndef __LINUX_PCS_NXP_SERDES_XPCS_H
+#define __LINUX_PCS_NXP_SERDES_XPCS_H
+
+#include <linux/phy.h>
+#include <linux/phylink.h>
+#include <linux/regmap.h>
+
+/* AN mode values as defined by the DesignWare XPCS */
+enum nxp_serdes_an_mode {
+ NXP_SERDES_AN_C37_SGMII = 2,
+ NXP_SERDES_2500BASEX = 3,
+ NXP_SERDES_10GBASER = 5,
+ NXP_SERDES_AN_C37_USXGMII = 6,
+};
+
+/* The revision runs its own reset sequence, skip the soft reset */
+#define NXP_SERDES_QUIRK_NO_SOFT_RESET BIT(0)
+/* The revision reports the link state to the MAC, do not poll the PCS */
+#define NXP_SERDES_QUIRK_NO_POLL BIT(1)
+/* The revision does not implement the VR_MII_EEE_MCTRL0/1 registers */
+#define NXP_SERDES_QUIRK_NO_EEE BIT(2)
+
+struct nxp_serdes_xpcs;
+
+struct nxp_serdes_xpcs_compat {
+ phy_interface_t interface;
+ const int *supported;
+ enum nxp_serdes_an_mode an_mode;
+ int (*pma_config)(struct nxp_serdes_xpcs *xpcs);
+ int (*pma_link_up)(struct nxp_serdes_xpcs *xpcs, int speed,
+ int duplex);
+};
+
+/* Description of one SerDes revision, provided by the platform glue */
+struct nxp_serdes_xpcs_desc {
+ const char *name;
+ u32 pma_id;
+ const struct nxp_serdes_xpcs_compat *compat;
+ unsigned int quirks;
+ void (*reset)(struct nxp_serdes_xpcs *xpcs);
+};
+
+struct nxp_serdes_xpcs {
+ struct device *dev;
+ struct regmap *xpcs_regmap;
+ struct regmap *phy_regmap;
+ const struct nxp_serdes_xpcs_desc *desc;
+ struct phylink_pcs pcs;
+ phy_interface_t interface;
+ u32 pma_id;
+ u8 portid;
+ bool need_reset;
+ bool sgmii_internal_ref_clk;
+ void *priv;
+};
+
+#define phylink_pcs_to_nxp_serdes_xpcs(pl_pcs) \
+ container_of((pl_pcs), struct nxp_serdes_xpcs, pcs)
+
+static inline void nxp_serdes_xpcs_set_drvdata(struct nxp_serdes_xpcs *xpcs,
+ void *priv)
+{
+ xpcs->priv = priv;
+}
+
+static inline void *nxp_serdes_xpcs_get_drvdata(struct nxp_serdes_xpcs *xpcs)
+{
+ return xpcs->priv;
+}
+
+/* Feature sets for struct nxp_serdes_xpcs_compat::supported */
+extern const int nxp_serdes_xpcs_usxgmii_features[];
+extern const int nxp_serdes_xpcs_2500basex_features[];
+extern const int nxp_serdes_xpcs_sgmii_features[];
+
+struct phylink_pcs *nxp_serdes_xpcs_create(struct device *dev,
+ struct regmap *xpcs_regmap,
+ struct regmap *phy_regmap,
+ const struct nxp_serdes_xpcs_desc *desc,
+ u8 portid,
+ phy_interface_t interface);
+void nxp_serdes_xpcs_destroy(struct phylink_pcs *pcs);
+
+/* Register accesses are encoded in the regmap as "(devad << 16) | reg", with
+ * "devad" the Clause 45 device address and "reg" the 16-bit register address.
+ * Decoding both fields is up to the regmap of the platform glue.
+ */
+int nxp_serdes_xpcs_read(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg);
+int nxp_serdes_xpcs_write(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,
+ u16 val);
+int nxp_serdes_xpcs_modify(struct nxp_serdes_xpcs *xpcs, u8 devad, u32 reg,
+ u16 mask, u16 set);
+
+#endif /* __LINUX_PCS_NXP_SERDES_XPCS_H */
diff --git a/include/linux/phy/nxp-s32g-serdes.h b/include/linux/phy/nxp-s32g-serdes.h
new file mode 100644
index 0000000000000..d14fcde1d9331
--- /dev/null
+++ b/include/linux/phy/nxp-s32g-serdes.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright 2021-2026 NXP
+ */
+#ifndef PHY_NXP_S32G_SERDES_H
+#define PHY_NXP_S32G_SERDES_H
+
+#include <linux/err.h>
+
+struct device;
+struct device_node;
+struct phylink_pcs;
+
+#if IS_REACHABLE(CONFIG_PHY_S32G_SERDES)
+struct phylink_pcs *s32g_serdes_pcs_create(struct device *dev,
+ struct device_node *np);
+#else
+static inline struct phylink_pcs *
+s32g_serdes_pcs_create(struct device *dev, struct device_node *np)
+{
+ return ERR_PTR(-ENODEV);
+}
+#endif
+
+#endif /* PHY_NXP_S32G_SERDES_H */
|
| 3/2 | 2026/09/21 06:09 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60643 output: 120 thoughts: 1979 Thoughts: **Fuzzing Evaluation: NXP S32G SoC Drivers** Okay, let's break this down. My task is to determine if this patch series is suitable for fuzzing with syzkaller, keeping in mind the target architecture is amd64. I have to make a `WorthFuzzing` decision and provide a rationale. First, I review the instructions. The primary concern is reachability: can the modified code execute in a standard virtualized environment like QEMU or GCE? Unreachable code means no fuzzing. The key negative criteria focuses on structurally unreachable hardware or architecture-specific code paths. I examine the patch. It touches device tree bindings for net and PCI, various driver files (Ethernet, PHY, PCS), Kconfig files, and crucially, `arch/arm64/boot/dts/freescale/*`. Alarm bells! The Freescale prefix tells me this concerns the S32G SoC. Immediately, I recall the S32G is an ARM64 automotive SoC. Now, I re-evaluate: can this NXP S32G SerDes, PCS, or DWMAC-s32 code run on amd64 in QEMU? Absolutely not. The target architecture is explicitly stated as amd64. I go driver by driver, looking for any possible points of entry. `phy-nxp-s32g-serdes.c`, `pcs-nxp-s32g-xpcs.c`, `pcs-nxp-serdes-xpcs.c`, `dwmac-s32.c`: they're all platform drivers. Platform drivers, by definition, require a specific hardware platform to probe. Inspecting Kconfig files confirms this. Dependencies on `OF` (Device Tree) and `ARCH_S32` (which is ARM64 only) and `COMPILET_TEST` make this even more obvious. Even with compile-time testing, these drivers rely on Device Tree compatible strings: `nxp,s32g2-serdes`, `nxp,s32g3-serdes`, and so on. QEMU or GCE on amd64 does *not* emulate the NXP S32G SoC (which, again, is an ARM64 automotive SoC). No Device Tree, no platform devices instantiated. No physical S32G hardware, no driver probe. `ARCH_S32` is not even defined for the x86_64 architecture. The drivers register using module_platform_driver(s32g_serdes_driver) and their of_match_table structures: `s32g_serdes_match`, `s32_dwmac_match`. They are inherently unreachable on amd64. Considering the negative criteria laid out in the instructions, this is a clear-cut case. This code is structurally unreachable on the target architecture. It demands NXP S32G SoC hardware, which is not present or emulated in the standard virtualized testing setup. I double-check. The patch touches device tree bindings, ARM64 device trees, and drivers for the NXP S32G SoC, specifically PHY, PCS, and dwmac glue code. None of this is reachable on amd64. I'm confident. The tool call will set: * `WorthFuzzing: false` * `FocusSymbols: []` * `EnableConfigs: []` * `Reasoning:` The modified code is for NXP S32G SoC hardware and its associated device tree bindings, requiring physical S32G hardware that is not emulated in standard virtualized test environments. The code is structurally unreachable on amd64. |
| 4/2 | 2026/09/21 06:10 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch series introduces device tree bindings, ARM64 DTS changes, and drivers for the SerDes PHY and Synopsys XPCS platform glue on NXP S32G automotive SoCs (ARM64). These platform drivers require physical NXP S32G SoC hardware that is not emulated in standard virtualized QEMU/GCE environments, and the code is structurally unreachable on the target architecture (amd64).",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch series introduces device tree bindings, ARM64 DTS changes, and drivers for the SerDes PHY and Synopsys XPCS platform glue on NXP S32G automotive SoCs (ARM64). These platform drivers require physical NXP S32G SoC hardware that is not emulated in standard virtualized QEMU/GCE environments, and the code is structurally unreachable on the target architecture (amd64).",
"WorthFuzzing": false
} |
| 5/1 | 2026/09/21 06:10 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|