Serdes: s32g: Add support for serdes subsystem
Subsystems (5)
cover Serdes: s32g: Add support for serdes subsystem
s32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and a shared Phy. The Phy got 2 lanes that can be configured to output PCIe lanes and/or SGMII.
Implement PCIe phy and XPCS support.
Vincent Guittot (4):
dt-bindings: serdes: s32g: Add NXP serdes subsystem
phy: s32g: Add serdes subsystem phy
phy: s32g: Add serdes xpcs subsystem
MAINTAINERS: Add MAINTAINER for NXP S32G Serdes driver
.../bindings/phy/nxp,s32g-serdes.yaml | 154 +++ MAINTAINERS | 9 + drivers/phy/freescale/Kconfig | 10 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-nxp-s32g-serdes.c | 926 ++++++++++++++ drivers/phy/freescale/phy-nxp-s32g-xpcs.c | 1082 +++++++++++++++++ drivers/phy/freescale/phy-nxp-s32g-xpcs.h | 47 + include/linux/pcs/pcs-nxp-xpcs.h | 13 + 8 files changed, 2242 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml create mode 100644 drivers/phy/freescale/phy-nxp-s32g-serdes.c create mode 100644 drivers/phy/freescale/phy-nxp-s32g-xpcs.c create mode 100644 drivers/phy/freescale/phy-nxp-s32g-xpcs.h create mode 100644 include/linux/pcs/pcs-nxp-xpcs.h
Signature · 1 line
2.43.0
PATCH 1/4 dt-bindings: serdes: s32g: Add NXP serdes subsystem
Describe the serdes subsystem available on the S32G platforms.
--- .../bindings/phy/nxp,s32g-serdes.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml new file +154 -0
@@ -0,0 +1,154 @@ +# 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 <[email protected]> + +description: | + The SerDes subsystem on S32G SoC Family includes two types of PHYs: + - One PCIe PHY: Supports various PCIe operation modes + - Two Ethernet Physical Coding Sublayer (XPCS) controllers + + SerDes operation mode selects the enabled PHYs and speeds. Clock frequency + must be adapted accordingly. Below table describes all possible operation + modes. + + Mode PCIe XPCS0 XPCS1 PHY clock Description + SGMII SGMII (MHz) + ------------------------------------------------------------------------- + 0 Gen3 N/A N/A 100 Single PCIe + 1 Gen2 1.25Gbps N/A 100 PCIe/SGMII + 2 Gen2 N/A 1.25Gbps 100 PCIe/SGMII + 3 N/A 1.25Gbps 1.25Gbps 100,125 SGMII + 4 N/A 3.125/1.25Gbps 3.125/1.25Gbps 125 SGMII + 5 Gen2 N/A 3.125Gbps 100 PCIe/SGMII + +properties: + compatible: + oneOf: + - enum: + - nxp,s32g2-serdes + - items: + - const: nxp,s32g3-serdes + - const: nxp,s32g2-serdes + + reg: + maxItems: 4 + + reg-names: + items: + - const: ss_pcie + - const: pcie_phy + - const: xpcs0 + - const: xpcs1 + + clocks: + minItems: 4 + maxItems: 5 + + clock-names: + items: + - const: axi + - const: aux + - const: apb + - const: ref + - const: ext + minItems: 4 + + resets: + maxItems: 2 + + reset-names: + items: + - const: serdes + - const: pcie + + nxp,sys-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + SerDes operational mode. See above table for possible values. + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + '^serdes[0,1]_lane@[0,1]$': + description: + Describe a serdes lane. + type: object + + properties: + compatible: + enum: + - nxp,s32g2-serdes-pcie-phy + - nxp,s32g2-serdes-xpcs + + reg: + maxItems: 1 + + '#phy-cells': + const: 0 + + required: + - reg + - compatible + + unevaluatedProperties: false + +required: + - compatible + - reg + - reg-names + - clocks + - clock-names + - resets + - reset-names + - nxp,sys-mode + - '#address-cells' + - '#size-cells' + +additionalProperties: false + +examples: + - | + bus { + #address-cells = <2>; + #size-cells = <2>; + serdes0: serdes@40480000 { + compatible = "nxp,s32g3-serdes", "nxp,s32g2-serdes"; + reg = <0x0 0x40480000 0x0 0x108>, + <0x0 0x40483008 0x0 0x10>, + <0x0 0x40482000 0x0 0x800>, + <0x0 0x40482800 0x0 0x800>; + reg-names = "ss_pcie", "pcie_phy", "xpcs0", "xpcs1"; + clocks = <&clks 1>, + <&clks 2>, + <&clks 3>, + <&clks 4>, + <&serdes_100_ext>; + clock-names = "axi", "aux", "apb", "ref", "ext"; + resets = <&reset 9>, + <&reset 8>; + reset-names = "serdes", "pcie"; + nxp,sys-mode = <1>; + #address-cells = <1>; + #size-cells = <0>; + phy_pcie0: serdes0_lane@0 { + compatible = "nxp,s32g2-serdes-pcie-phy"; + #phy-cells = <0>; + reg = <0>; + }; + phy_xpcs0_0: serdes0_lane@1 { + compatible = "nxp,s32g2-serdes-xpcs"; + reg = <0>; + }; + }; + };
Signature · 1 line
2.43.0
Re: [PATCH 1/4] dt-bindings: serdes: s32g: Add NXP serdes subsystem
Quoted 33 lines · Vincent Guittot
Describe the serdes subsystem available on the S32G platforms.
Signed-off-by Vincent Guittot <[email protected]>--- .../bindings/phy/nxp,s32g-serdes.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yamlDocumentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml new file +19
-0@@ -0,0 +1,154 @@ +# 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 <[email protected]> + +description: | + The SerDes subsystem on S32G SoC Family includes two types of PHYs: + - One PCIe PHY: Supports various PCIe operation modes + - Two Ethernet Physical Coding Sublayer (XPCS) controllers + + SerDes operation mode selects the enabled PHYs and speeds. Clock frequency + must be adapted accordingly. Below table describes all possible operation + modes.
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml line 29
Quoted 10 lines
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml new file +10
-0+ + Mode PCIe XPCS0 XPCS1 PHY clock Description + SGMII SGMII (MHz) + ------------------------------------------------------------------------- + 0 Gen3 N/A N/A 100 Single PCIe + 1 Gen2 1.25Gbps N/A 100 PCIe/SGMII + 2 Gen2 N/A 1.25Gbps 100 PCIe/SGMII + 3 N/A 1.25Gbps 1.25Gbps 100,125 SGMII + 4 N/A 3.125/1.25Gbps 3.125/1.25Gbps 125 SGMII + 5 Gen2 N/A 3.125Gbps 100 PCIe/SGMII
Shouldn't the mode be configured via phy_set_mode_ext()?
This identifies whether it is operating as PCIe or for networking and in the case of networking, the PHY interface mode should be passed as the submode.
Have a look at include/linux/phy/pcie.h to see the submodes that may be appropriate to pass to phy_set_mode_ext() - but talk to the PHY subsystem maintainers.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 1/4] dt-bindings: serdes: s32g: Add NXP serdes subsystem
Quoted 39 lines · Russell King (Oracle)
Quoted 37 lines · Vincent Guittot
Describe the serdes subsystem available on the S32G platforms.
Signed-off-by Vincent Guittot <[email protected]>--- .../bindings/phy/nxp,s32g-serdes.yaml | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yamlDocumentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml new file +23
-0@@ -0,0 +1,154 @@ +# 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 <[email protected]> + +description: | + The SerDes subsystem on S32G SoC Family includes two types of PHYs: + - One PCIe PHY: Supports various PCIe operation modes + - Two Ethernet Physical Coding Sublayer (XPCS) controllers + + SerDes operation mode selects the enabled PHYs and speeds. Clock frequency + must be adapted accordingly. Below table describes all possible operation + modes. + + Mode PCIe XPCS0 XPCS1 PHY clock Description + SGMII SGMII (MHz) + -------------------------------------------------------------------------
Quoted 8 lines
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml line 29
Quoted 6 lines
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml new file +6
-0+ 0 Gen3 N/A N/A 100 Single PCIe + 1 Gen2 1.25Gbps N/A 100 PCIe/SGMII + 2 Gen2 N/A 1.25Gbps 100 PCIe/SGMII + 3 N/A 1.25Gbps 1.25Gbps 100,125 SGMII + 4 N/A 3.125/1.25Gbps 3.125/1.25Gbps 125 SGMII + 5 Gen2 N/A 3.125Gbps 100 PCIe/SGMIIShouldn't the mode be configured via
phy_set_mode_ext()?
There is a phy for only pcie only. In mode 3 to 5 there is no generic phy created
Quoted 12 lines
This identifies whether it is operating as PCIe or for networking and in the case of networking, the PHY interface mode should be passed as the submode.
Have a look at
include/linux/phy/pcie.hto see the submodes that may be appropriate to pass tophy_set_mode_ext()- but talk to the PHY subsystem maintainers.--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH 2/4 phy: s32g: Add serdes subsystem phy
In reply to Vincent Guittots32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Implement PCIe phy support
--- drivers/phy/freescale/Kconfig | 9 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-nxp-s32g-serdes.c | 569 ++++++++++++++++++++ 3 files changed, 579 insertions(+) create mode 100644 drivers/phy/freescale/phy-nxp-s32g-serdes.c
drivers/phy/freescale/Kconfig +9 -0
@@ -61,3 +61,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 + select GENERIC_PHY + help + This option enables support for S23G SerDes PHY used for + PCIe & Ethernet +
drivers/phy/freescale/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_PHY_FSL_IMX8M_PCIE) += phy-fsl-imx8m-pcie.o obj-$(CONFIG_PHY_FSL_IMX8QM_HSIO) += phy-fsl-imx8qm-hsio.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
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +569 -0
569 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 24 lines · Vincent Guittot
s32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Implement PCIe phy support
Co-developed-by Ciprian Marian Costea <[email protected]>Signed-off-by Ciprian Marian Costea <[email protected]>Co-developed-by Alexandru-Catalin Ionita <[email protected]>Signed-off-by Alexandru-Catalin Ionita <[email protected]>Co-developed-by Ghennadi Procopciuc <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Co-developed-by Ionut Vicovan <[email protected]>Signed-off-by Ionut Vicovan <[email protected]>Co-developed-by Bogdan Roman <[email protected]>Signed-off-by Bogdan Roman <[email protected]>Signed-off-by Vincent Guittot <[email protected]>--- drivers/phy/freescale/Kconfig | 9 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-nxp-s32g-serdes.c | 569 ++++++++++++++++++++ 3 files changed, 579 insertions(+) create mode 100644 drivers/phy/freescale/phy-nxp-s32g-serdes.c
[...]
Quoted 6 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +0
-0@@ -0,0 +1,569 @@
[...]
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +2
-0+static int s32g_serdes_get_ctrl_resources (struct platform_device *pdev,struct s32g_serdes *serdes) +{
[...]
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 386
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +1
-0+ ctrl->rst =devm_reset_control_get (dev,"serdes" );
Please use devm_reset_control_get_exclusive() directly.
[...]
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +2
-0+static int s32g_serdes_get_pcie_resources (struct platform_device *pdev,struct s32g_serdes *serdes) +{
[...]
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 428
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +1
-0+ pcie->rst =devm_reset_control_get (dev,"pcie" );
Same here.
regards
Philipp
Signature · 3 lines
linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 34 lines · Philipp Zabel
Quoted 24 lines · Vincent Guittot
s32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Implement PCIe phy support
Co-developed-by Ciprian Marian Costea <[email protected]>Signed-off-by Ciprian Marian Costea <[email protected]>Co-developed-by Alexandru-Catalin Ionita <[email protected]>Signed-off-by Alexandru-Catalin Ionita <[email protected]>Co-developed-by Ghennadi Procopciuc <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Co-developed-by Ionut Vicovan <[email protected]>Signed-off-by Ionut Vicovan <[email protected]>Co-developed-by Bogdan Roman <[email protected]>Signed-off-by Bogdan Roman <[email protected]>Signed-off-by Vincent Guittot <[email protected]>--- drivers/phy/freescale/Kconfig | 9 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-nxp-s32g-serdes.c | 569 ++++++++++++++++++++ 3 files changed, 579 insertions(+) create mode 100644 drivers/phy/freescale/phy-nxp-s32g-serdes.c[...]
Quoted 6 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +0
-0@@ -0,0 +1,569 @@[...]
Quoted 6 lines
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +2
-0+static int s32g_serdes_get_ctrl_resources (struct platform_device *pdev,struct s32g_serdes *serdes) +{[...]
Quoted 1 line
+
ctrl->rst=devm_reset_control_get(dev, "serdes");Please use
devm_reset_control_get_exclusive()directly.
Okay
Quoted 11 lines
[...]
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +2
-0+static int s32g_serdes_get_pcie_resources (struct platform_device *pdev,struct s32g_serdes *serdes) +{[...]
Quoted 1 line
+
pcie->rst=devm_reset_control_get(dev, "pcie");Same here.
regards
Philipp
Simon Horman
reviewerRe: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
In reply to Vincent GuittotOn Mon, Jan 26, 2026 at 10:21:57AM +0100, Vincent Guittot wrote:
...
Quoted 6 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +0
-0
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 10
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0@@ -0,0 +1,569 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* SerDes driver for S32G SoCs +* +* Copyright 2021-2026 NXP +*/ + +#include <dt-bindings/phy/phy.h> +#include <linux/clk.h> +#include <linux/delay.h>
Hi Vincent, all,
I think that you also need:
#include <linux/iopoll.h>
So that read_poll_timeout() is declared.
Else this patch causes a transient build failure
(for x86_64 allmodconfig)
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +8
-0+#include <linux/module.h> +#include <linux/of_platform.h> +#include <linux/of_address.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/processor.h> +#include <linux/reset.h> +#include <linux/units.h>
...
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 221
Quoted 7 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +7
-0+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 ;
This is part of an AI Generated review.
I have looked over it and I think it warrants investigation. For information on how to reproduce locally, as I did, please see [1].
[1] https://netdev-ai.bots.linux.dev/ai-local.html
This returns error if mode IS PHY_MODE_PCIE, but this is a PCIe PHY! This looks like a typo. Should be !=.
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+ +if (!is_pcie_phy_mode_valid (submode)) +return -EINVAL ; + +/* +* Do not configure SRIS or CRSS PHY MODE in conjunction +* with any SGMII mode on the same SerDes subsystem +*/ +if ((submode ==CRSS || submode ==SRIS ) && + serdes->ctrl.ss_mode !=0 )
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 241
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+return -EINVAL ; + +/* +* Internal reference clock cannot be used with either Common clock +* or Spread spectrum, leaving only SRNSS +*/ +if (submode !=SRNS && !serdes->ctrl.ext_clk) +return -EINVAL ; + + serdes->pcie.phy_mode = submode;
The AI review also suggested that it may be unsafe to set the submode after s32g_serdes_phy_power_on() has been called. And that there is nothing preventing that.
TBH, I am unsure if either of those statements are true. But it seems worth validating with you.
Quoted 3 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +3
-0+ +return 0 ; +}
...
Quoted 24 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +24
-0+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; + + ret =of_property_read_u32 (dev->of_node,"nxp,sys-mode" , + &ctrl->ss_mode); +if (ret) { +dev_err (dev,"Failed to get SerDes subsystem mode\n" ); +return -EINVAL ; + } + +if (ctrl->ss_mode >S32G_SERDES_MODE_MAX ) { +dev_err (dev,"Invalid SerDes subsystem mode %u\n" , + ctrl->ss_mode); +return -EINVAL ; + } + + ctrl->ss_base =devm_platform_ioremap_resource_byname (pdev,"ss_pcie" ); +if (IS_ERR (ctrl->ss_base)) { +dev_err (dev,"Failed to map 'ss_pcie'\n" ); +return PTR_ERR (ctrl->ss_base); + }
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 394
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+ + ctrl->rst =devm_reset_control_get (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 ) +return dev_err_probe (dev, ctrl->nclks, +"Failed to get SerDes clocks\n" );
If devm_clk_bulk_get_all returns 0 then this value will be passed to dev_err_probe(). And 0 will, in turn be returned by dev_err_probe() and this function. However, that will be treated as success by the caller, even though this is an error condition.
Perhaps something like this is more appropriate if ctrl->nclks must be greater than 0. (Completely untested!)
if (ctrl->nclks < 1) {
ret = ctrl->nclks ? : -EINVAL;
return dev_err_probe(dev, ret,
"Failed to get SerDes clocks\n");
}Flagged by Smatch.
...
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 480
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +11
-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 =s32g2_serdes_create_phy (serdes, of_port); +if (ret) +break ; + } + +return ret;
Perhaps it cannot occur.
But if the loop above iterates zero times,
then ret will be used uninitialised here.
Also flagged by Smatch.
Quoted 16 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +16
-0+} + +static int s32g_serdes_probe (struct platform_device *pdev) +{ +struct s32g_serdes *serdes; +struct device *dev = &pdev->dev; +int ret; + + serdes =devm_kzalloc (dev,sizeof (*serdes),GFP_KERNEL ); +if (!serdes) +return -ENOMEM ; + +platform_set_drvdata (pdev, serdes); + serdes->dev = dev; + + ret =s32g_serdes_get_ctrl_resources (pdev, serdes);
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 506
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+if (ret) +return ret; + + ret =s32g_serdes_get_pcie_resources (pdev, serdes); +if (ret) +return ret; + + ret =s32g_serdes_parse_lanes (dev, serdes); +if (ret) +return ret;
The I review also says:
The probe function calls s32g_serdes_init() which enables clocks, configures hardware, and deasserts reset. However, s32g_serdes_parse_lanes() creates PHY providers via devm_of_phy_provider_register().
Problem: PHY consumers can start calling PHY ops (like power_on) as soon as the provider is registered, but the hardware isn't initialized until s32g_serdes_init() runs afterward. This creates a race window.
Recommendation: Move s32g_serdes_init() before s32g_serdes_parse_lanes().
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 510
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +4
-0+ + ret =s32g_serdes_init (serdes); + +return ret;
nit: This could be more succinctly written as:
return s32g_serdes_init(serdes);
Quoted 1 line
+}
...
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 24 lines · Simon Horman
On Mon, Jan 26, 2026 at 10:21:57AM +0100, Vincent Guittot wrote:
...
Quoted 6 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +0
-0drivers/phy/freescale/phy-nxp-s32g-serdes.c line 10
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0@@ -0,0 +1,569 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* SerDes driver for S32G SoCs +* +* Copyright 2021-2026 NXP +*/ + +#include <dt-bindings/phy/phy.h> +#include <linux/clk.h> +#include <linux/delay.h> Hi Vincent, all,
Quoted 7 lines
I think that you also need:
#include <
linux/iopoll.h>So that
read_poll_timeout()is declared.
Else this patch causes a transient build failure
(forx86_64allmodconfig)
ok, i will add it
Quoted 24 lines
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +8
-0+#include <linux/module.h> +#include <linux/of_platform.h> +#include <linux/of_address.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/processor.h> +#include <linux/reset.h> +#include <linux/units.h> ...
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 221
Quoted 7 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +7
-0+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 ;This is part of an AI Generated review.
I have looked over it and I think it warrants investigation. For information on how to reproduce locally, as I did, please see [1].
Quoted 4 lines
[1] https://netdev-ai.bots.linux.dev/ai-local.html
This returns error if mode IS
PHY_MODE_PCIE, but this is a PCIe PHY! This looks like a typo. Should be !=.
yes don't know what happened here but it should be !=
Quoted 26 lines
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+ +if (!is_pcie_phy_mode_valid (submode)) +return -EINVAL ; + +/* +* Do not configure SRIS or CRSS PHY MODE in conjunction +* with any SGMII mode on the same SerDes subsystem +*/ +if ((submode ==CRSS || submode ==SRIS ) && + serdes->ctrl.ss_mode !=0 )drivers/phy/freescale/phy-nxp-s32g-serdes.c line 241
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+return -EINVAL ; + +/* +* Internal reference clock cannot be used with either Common clock +* or Spread spectrum, leaving only SRNSS +*/ +if (submode !=SRNS && !serdes->ctrl.ext_clk) +return -EINVAL ; + + serdes->pcie.phy_mode = submode;The AI review also suggested that it may be unsafe to set the submode after
s32g_serdes_phy_power_on()has been called. And that there is nothing preventing that.
Quoted 2 lines
TBH, I am unsure if either of those statements are true. But it seems worth validating with you.
yes, the usual pattern is :
- phy_set_mode_ext()
- then phy_power_on()
but I can add an additional check
Quoted 50 lines
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +3
-0+ +return 0 ; +}...
Quoted 24 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +24
-0+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; + + ret =of_property_read_u32 (dev->of_node,"nxp,sys-mode" , + &ctrl->ss_mode); +if (ret) { +dev_err (dev,"Failed to get SerDes subsystem mode\n" ); +return -EINVAL ; + } + +if (ctrl->ss_mode >S32G_SERDES_MODE_MAX ) { +dev_err (dev,"Invalid SerDes subsystem mode %u\n" , + ctrl->ss_mode); +return -EINVAL ; + } + + ctrl->ss_base =devm_platform_ioremap_resource_byname (pdev,"ss_pcie" ); +if (IS_ERR (ctrl->ss_base)) { +dev_err (dev,"Failed to map 'ss_pcie'\n" ); +return PTR_ERR (ctrl->ss_base); + }drivers/phy/freescale/phy-nxp-s32g-serdes.c line 394
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+ + ctrl->rst =devm_reset_control_get (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 ) +return dev_err_probe (dev, ctrl->nclks, +"Failed to get SerDes clocks\n" );If
devm_clk_bulk_get_allreturns 0 then this value will be passed todev_err_probe(). And 0 will, in turn be returned bydev_err_probe()and this function. However, that will be treated as success by the caller, even though this is an error condition.Perhaps something like this is more appropriate if
ctrl->nclksmust be greater than 0. (Completely untested!)
Quoted 7 lines
if (ctrl->nclks < 1) { ret = ctrl->nclks ? : -EINVAL; return dev_err_probe(dev, ret, "Failed to get SerDes clocks\n"); }Flagged by Smatch.
okay
Quoted 18 lines
...
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 480
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +11
-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 =s32g2_serdes_create_phy (serdes, of_port); +if (ret) +break ; + } + +return ret;Perhaps it cannot occur.
But if the loop above iterates zero times,
then ret will be used uninitialised here.
should not but will fix it
Quoted 37 lines
Also flagged by Smatch.
Quoted 16 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +16
-0+} + +static int s32g_serdes_probe (struct platform_device *pdev) +{ +struct s32g_serdes *serdes; +struct device *dev = &pdev->dev; +int ret; + + serdes =devm_kzalloc (dev,sizeof (*serdes),GFP_KERNEL ); +if (!serdes) +return -ENOMEM ; + +platform_set_drvdata (pdev, serdes); + serdes->dev = dev; + + ret =s32g_serdes_get_ctrl_resources (pdev, serdes);drivers/phy/freescale/phy-nxp-s32g-serdes.c line 506
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+if (ret) +return ret; + + ret =s32g_serdes_get_pcie_resources (pdev, serdes); +if (ret) +return ret; + + ret =s32g_serdes_parse_lanes (dev, serdes); +if (ret) +return ret;The I review also says:
The probe function calls
s32g_serdes_init()which enables clocks, configures hardware, and deasserts reset. However,s32g_serdes_parse_lanes()creates PHY providers viadevm_of_phy_provider_register().
Quoted 5 lines
Problem: PHY consumers can start calling PHY ops (like
power_on) as soon as the provider is registered, but the hardware isn't initialized untils32g_serdes_init()runs afterward. This creates a race window.Recommendation: Move
s32g_serdes_init()befores32g_serdes_parse_lanes().
I will look at this more deeply but part of s32g_serdes_init() needs lanes to be parsed for configuring clock
Quoted 7 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 510
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +4
-0+ + ret =s32g_serdes_init (serdes); + +return ret;nit: This could be more succinctly written as:
fair enough
Quoted 6 lines
return s32g_serdes_init(serdes);Quoted 1 line
+}
...
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional check
Please read Documentation/driver-api/phy/phy.rst section "Order of API calls" which suggests phy_set_mode_ext() after phy_power_on().
Having different requirements for different SerDes PHYs quickly becomes annoying for users of the SerDes PHYs.
E.g. I'm trying to add SerDes PHY support to stmmac, which is used across different platforms. Having all SerDes PHY drivers behave the same as far as their PHY API calls are concerned means that the whole point of having an abstracted interface is maintained. Otherwise, it's completely pointless.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 9 lines · Russell King (Oracle)
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional checkPlease read
Documentation/driver-api/phy/phy.rstsection "Order of API calls" which suggestsphy_set_mode_ext()afterphy_power_on().
Fair enough.
That being said, all pcie drivers that use phy_set_mode_ext(), call it before phy_power_on()
Quoted 13 lines
Having different requirements for different SerDes PHYs quickly becomes annoying for users of the SerDes PHYs.
E.g. I'm trying to add SerDes PHY support to stmmac, which is used across different platforms. Having all SerDes PHY drivers behave the same as far as their PHY API calls are concerned means that the whole point of having an abstracted interface is maintained. Otherwise, it's completely pointless.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 9 lines · Vincent Guittot
Quoted 7 lines · Russell King (Oracle)
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional check
Quoted 6 lines
Quoted 2 lines
Please read
Documentation/driver-api/phy/phy.rstsection "Order of API calls" which suggestsphy_set_mode_ext()afterphy_power_on().Fair enough.
That being said, all pcie drivers that usephy_set_mode_ext(), call it beforephy_power_on()
It looks like many ethernet drivers do the same, so I think maybe the generic PHY documentation is incorrect or misleading, or is expressing a preference that almost no one follows. Something for the generic PHY maintainers to look at and/or comment on.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Vinod Koul
maintainerRe: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 13 lines · Russell King (Oracle)
Quoted 12 lines · Vincent Guittot
Quoted 9 lines · Russell King (Oracle)
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional checkPlease read
Documentation/driver-api/phy/phy.rstsection "Order of API calls" which suggestsphy_set_mode_ext()afterphy_power_on().
Quoted 8 lines
Quoted 3 lines
Fair enough.
That being said, all pcie drivers that usephy_set_mode_ext(), call it beforephy_power_on()It looks like many ethernet drivers do the same, so I think maybe the generic PHY documentation is incorrect or misleading, or is expressing a preference that almost no one follows. Something for the generic PHY maintainers to look at and/or comment on.
I would feel it makes sense to configure the mode first and then power the phy up. As commented above yes it looks like apart from one tegra driver rest seem to do it this way.
Lets update the documentation
Signature · 1 line
~Vinod
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 23 lines · Vinod Koul
Quoted 13 lines · Russell King (Oracle)
Quoted 12 lines · Vincent Guittot
Quoted 9 lines · Russell King (Oracle)
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional checkPlease read
Documentation/driver-api/phy/phy.rstsection "Order of API calls" which suggestsphy_set_mode_ext()afterphy_power_on().Quoted 8 lines
Quoted 3 lines
Fair enough.
That being said, all pcie drivers that usephy_set_mode_ext(), call it beforephy_power_on()It looks like many ethernet drivers do the same, so I think maybe the generic PHY documentation is incorrect or misleading, or is expressing a preference that almost no one follows. Something for the generic PHY maintainers to look at and/or comment on.
Quoted 5 lines
I would feel it makes sense to configure the mode first and then power the phy up. As commented above yes it looks like apart from one tegra driver rest seem to do it this way.
Lets update the documentation
Please also indicate in the documentation whether changing the submode of the serdes (particularly for ethernet) is permitted without doing a phy_power_down()..phy_power_up() dance around the phy_set_mode_ext() call.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 28 lines · Russell King (Oracle)
Quoted 27 lines · Vinod Koul
Quoted 13 lines · Russell King (Oracle)
Quoted 12 lines · Vincent Guittot
Quoted 9 lines · Russell King (Oracle)
Quoted 4 lines · Vincent Guittot
yes, the usual pattern is :
-phy_set_mode_ext()
- thenphy_power_on()
but I can add an additional checkPlease read
Documentation/driver-api/phy/phy.rstsection "Order of API calls" which suggestsphy_set_mode_ext()afterphy_power_on().Quoted 8 lines
Quoted 3 lines
Fair enough.
That being said, all pcie drivers that usephy_set_mode_ext(), call it beforephy_power_on()It looks like many ethernet drivers do the same, so I think maybe the generic PHY documentation is incorrect or misleading, or is expressing a preference that almost no one follows. Something for the generic PHY maintainers to look at and/or comment on.
I would feel it makes sense to configure the mode first and then power the phy up. As commented above yes it looks like apart from one tegra driver rest seem to do it this way.
Quoted 6 lines
Quoted 1 line
Lets update the documentation
Please also indicate in the documentation whether changing the submode of the serdes (particularly for ethernet) is permitted without doing a phy_power_down()..phy_power_up() dance around the
phy_set_mode_ext()call.
Maybe something like this, which simply alters the documentation to indicate that phy_set_mode*() is permissible prior to phy_power_on(), and should be used at that point where drivers know the mode which will be used.
Leaving the existing phy_set_mode*() in the sequence also indicates that it's permissible to call this while the PHY is still powered on.
For drivers such as stmmac, it will be important that details such as whether phy_est_mode*() can be called with the PHY powered on are riveted down and not left up to the generic PHY driver author - without that, generic PHYs basically aren't usable from SoC/platform independent code, and stmmac has bazillions of platform specific glue already because of (a) bad code structuring and (b) lack of generalisation through standardised interfaces that abstract platform differences.
I want to be able for core stmmac code, or even phylink code (which is even more platform generic) to be able to make use of generic PHY stuff, but if the calls that can be made into generic PHY are platform dependent, that is a blocking issue against that, and makes me question why we have the generic PHY subsystem... it's not very generic if it exposes the differences of each implementation to users of its interfaces.
I think generic PHY has had the idea that its interfaces will only be used from platform specific code that knows about the behaviour of it's generic PHY driver, but as can be seen above, this will not remain the case given that we have hardware designs where the core of the driver is one vendor's IP that gets re-used across many different platforms, but the SerDes PHY is one of many other vendor's IP.
Documentation/driver-api/phy/phy.rst +2 -1
@@ -142,6 +142,7 @@ Order of API calls [devm_][of_]phy_get() phy_init() + [phy_set_mode[_ext]()] phy_power_on() [phy_set_mode[_ext]()] ...
@@ -154,7 +155,7 @@ but controllers should always call these functions to be compatible with other PHYs. Some PHYs may require :c:func:`phy_set_mode <phy_set_mode_ext>`, while others may use a default mode (typically configured via devicetree or other firmware). For compatibility, you should always call this function if you know -what mode you will be using. Generally, this function should be called after +what mode you will be using. Generally, this function should be called before :c:func:`phy_power_on`, although some PHY drivers may allow it at any time. Releasing a reference to the PHY
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
In reply to Vincent Guittotdrivers/phy/freescale/phy-nxp-s32g-serdes.c line 58
Quoted 10 lines · Vincent Guittot
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+/* +* Until now, there is no generic way to describe and set PCIe clock mode. +* PCIe controller uses the default CRNS = 0 mode. +*/ +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 */ +};
So this is a PCIe thing. If it's part of the driver's API, then it should be common and not driver-private.
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 213
Quoted 12 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +12
-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; + } +}
This checks that the submode is one of the PCIe private modes that this driver wants to see.
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 224
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +11
-0+ +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 ;
This checks for the PCIe submode, but notice the test immediately above. PCIE mode is being rejected. So, this driver supports everything else but PCIe.
That doesn't seem right.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 2/4] phy: s32g: Add serdes subsystem phy
Quoted 48 lines · Russell King (Oracle)
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 58
Quoted 10 lines · Vincent Guittot
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +10
-0+/* +* Until now, there is no generic way to describe and set PCIe clock mode. +* PCIe controller uses the default CRNS = 0 mode. +*/ +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 */ +};So this is a PCIe thing. If it's part of the driver's API, then it should be common and not driver-private.
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 213
Quoted 12 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +12
-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; + } +}This checks that the submode is one of the PCIe private modes that this driver wants to see.
drivers/phy/freescale/phy-nxp-s32g-serdes.c line 224
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c new file +11
-0+ +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 ;This checks for the PCIe submode, but notice the test immediately above. PCIE mode is being rejected. So, this driver supports everything else but PCIe.
Quoted 1 line
That doesn't seem right.
It's a mistake
Quoted 4 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH 3/4 phy: s32g: Add serdes xpcs subsystem
In reply to Vincent Guittots32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Add XPCS and SGMII support.
--- drivers/phy/freescale/Kconfig | 1 + drivers/phy/freescale/Makefile | 2 +- drivers/phy/freescale/phy-nxp-s32g-serdes.c | 361 ++++++- drivers/phy/freescale/phy-nxp-s32g-xpcs.c | 1082 +++++++++++++++++++ drivers/phy/freescale/phy-nxp-s32g-xpcs.h | 47 + include/linux/pcs/pcs-nxp-xpcs.h | 13 + 6 files changed, 1503 insertions(+), 3 deletions(-) create mode 100644 drivers/phy/freescale/phy-nxp-s32g-xpcs.c create mode 100644 drivers/phy/freescale/phy-nxp-s32g-xpcs.h create mode 100644 include/linux/pcs/pcs-nxp-xpcs.h
drivers/phy/freescale/Kconfig +1 -0
@@ -66,6 +66,7 @@ config PHY_S32G_SERDES tristate "NXP S32G SERDES support" depends on ARCH_S32 || COMPILE_TEST select GENERIC_PHY + select REGMAP help This option enables support for S23G SerDes PHY used for PCIe & Ethernet
drivers/phy/freescale/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-$(CONFIG_PHY_FSL_IMX8M_PCIE) += phy-fsl-imx8m-pcie.o obj-$(CONFIG_PHY_FSL_IMX8QM_HSIO) += phy-fsl-imx8qm-hsio.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 +obj-$(CONFIG_PHY_S32G_SERDES) += phy-nxp-s32g-serdes.o phy-nxp-s32g-xpcs.o
drivers/phy/freescale/phy-nxp-s32g-serdes.c +359 -2
448 lines not on this page · raw message
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +1082 -0
1,082 lines not on this page · raw message
drivers/phy/freescale/phy-nxp-s32g-xpcs.h new file +47 -0
47 lines not on this page · raw message
include/linux/pcs/pcs-nxp-xpcs.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/** +* Copyright 2026 NXP +*/ + +#ifndef __LINUX_PCS_NXP_XPCS_H +#define __LINUX_PCS_NXP_XPCS_H + +#include <linux/phylink.h> + +struct phylink_pcs *s32g_serdes_pcs_create (struct device *dev,struct device_node *np); + +#endif /* __LINUX_PCS_XPCS_H */
Signature · 1 line
2.43.0
Simon Horman
reviewerRe: [PATCH 3/4] phy: s32g: Add serdes xpcs subsystem
On Mon, Jan 26, 2026 at 10:21:58AM +0100, Vincent Guittot wrote:
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c +0
-0
...
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 369
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +9
-0+static void s32g_serdes_prepare_pma_mode5 (struct s32g_serdes *serdes) +{ +u32 val; +/* Configure TX_VBOOST_LVL and TX_TERM_CTRL */ + val =readl (serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 ); + val &= ~(EXT_TX_VBOOST_LVL_MASK |EXT_TX_TERM_CTRL_MASK ); + val |=FIELD_PREP (EXT_TX_VBOOST_LVL_MASK ,0x3 ) | +FIELD_PREP (EXT_TX_TERM_CTRL_MASK ,0x4 ); +writel (val, serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 );
This is part of an AI Generated review.
I have looked over it and I think it warrants investigation. For information on how to reproduce locally, as I did, please see [1].
The entire s32g_serdes_prepare_pma_mode5() function is ~70 lines of magic numbers with zero explanation. These appear to be hardware-specific PLL/PHY tuning parameters for 2.5G mode.
Please consider using #defines, to give values names.
...
Quoted 19 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +19
-0+static int s32g_serdes_init_clks (struct s32g_serdes *serdes) +{ +struct s32g_serdes_ctrl *ctrl = &serdes->ctrl; +struct s32g_xpcs_ctrl *xpcs = &serdes->xpcs; +int ret, order[2 ], xpcs_id; +size_t i; + +switch (ctrl->ss_mode) { +case 0 : +return 0 ; +case 1 : + order[0 ] =0 ; + order[1 ] =XPCS_DISABLED ; +break ; +case 2 : +case 5 : + order[0 ] =1 ; + order[1 ] =XPCS_DISABLED ; +break ;
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 462
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +10
-0+case 3 : + order[0 ] =1 ; + order[1 ] =0 ; +break ; +case 4 : + order[0 ] =0 ; + order[1 ] =1 ; +break ; +default : +return -EINVAL ;
AI review also flags that s32g_serdes_get_ctrl_resources() ensures that ss_mode is <= 5. So this check is unnecessary.
Quoted 7 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +7
-0+ } + +for (i =0 ; i <ARRAY_SIZE (order); i++) { + xpcs_id = order[i]; + +if (xpcs_id ==XPCS_DISABLED ) +continue ;
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 479
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +10
-0+ + ret =s32g_xpcs_init_plls (xpcs->phys[xpcs_id]); +if (ret) +return ret; + } + +if (ctrl->ss_mode ==5 ) { +s32g_serdes_prepare_pma_mode5 (serdes); + + ret =s32g_xpcs_pre_pcie_2g5 (xpcs->phys[1 ]);
Also from the AI review:
In mode 5, code directly accesses xpcs->phys[1] without checking if it was created. If XPCS1 wasn't created for some reason (DT misconfiguration, probe failure), this NULL dereferences.
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c +0
-0@@ -460,6 +741,41 @@ static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod
...
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod · line 769
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +5
-0+ xpcs =devm_kmalloc (dev,sizeof (*xpcs),GFP_KERNEL ); +if (IS_ERR (xpcs)) { +dev_err (dev,"Failed to allocate xpcs\n" ); +return -ENOMEM ; + }
AI review also flags:
devm_kmalloc() returns NULL on failure, not an error pointer. This check will never trigger.
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod · line 773
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +4
-0+ + xpcs_ctrl->phys[port] = xpcs; + + xpcs->an =of_property_read_bool (dev->of_node,"nxp,xpcs_an" );
AI review flags that nxp,xpcs_an is not part of the binding.
...
Quoted 22 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +22
-0+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; +u32 port; + +if (of_property_read_u32 (np,"reg" , &port)) +return ERR_PTR (-EINVAL ); + +if (port >S32G_SERDES_XPCS_MAX ) +return ERR_PTR (-EINVAL ); + +/* The PCS pdev is attached to the parent node */ + 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 ); + }
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int __maybe_unused s32g_serdes_resume(struct device *device) · line 895
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +10
-0+ + pdev =of_find_device_by_node (pcs_np); +of_node_put (pcs_np); +if (!pdev || !platform_get_drvdata (pdev)) { +if (pdev) +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + } + + serdes =platform_get_drvdata (pdev);
Also from the AI review:
On success, the function gets a reference to pdev but never releases it. This leaks a device reference every time a MAC driver calls s32g_serdes_pcs_create().
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int __maybe_unused s32g_serdes_resume(struct device *device) · line 897
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +2
-0+ +return &serdes->xpcs.phys[port]->pcs;
Also from the AI review:
The check port > S32G_SERDES_XPCS_MAX allows port=2, but array only has indices 0 and 1.
Also I'm not seeing bounds checking on port in s32g2_serdes_create_phy which uses port as an index for the same array both directly and indirectly via s32g_serdes_xpcs_init().
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +0
-0
...
Quoted 25 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +25
-0+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 ; +}
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 237
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +10
-0+ +static const struct regmap_config s32g_xpcs_regmap_config = { + .reg_bits =16 , + .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 , +};
AI review also flags that s32g_xpcs_regmap_reg_read and s32g_xpcs_regmap_reg_write do not protect against concurrent access.
...
Re: [PATCH 3/4] phy: s32g: Add serdes xpcs subsystem
Quoted 23 lines · Simon Horman
On Mon, Jan 26, 2026 at 10:21:58AM +0100, Vincent Guittot wrote:
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c +0
-0...
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 369
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +9
-0+static void s32g_serdes_prepare_pma_mode5 (struct s32g_serdes *serdes) +{ +u32 val; +/* Configure TX_VBOOST_LVL and TX_TERM_CTRL */ + val =readl (serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 ); + val &= ~(EXT_TX_VBOOST_LVL_MASK |EXT_TX_TERM_CTRL_MASK ); + val |=FIELD_PREP (EXT_TX_VBOOST_LVL_MASK ,0x3 ) | +FIELD_PREP (EXT_TX_TERM_CTRL_MASK ,0x4 ); +writel (val, serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 );This is part of an AI Generated review.
I have looked over it and I think it warrants investigation. For information on how to reproduce locally, as I did, please see [1].
Quoted 3 lines
The entire
s32g_serdes_prepare_pma_mode5()function is ~70 lines of magic numbers with zero explanation. These appear to be hardware-specific PLL/PHY tuning parameters for 2.5G mode.
Unfortunately there is no additional information in the reference manual other than
*step 4:
- Write 3h to EXT_TX_VBOOST_LVL.
- Write 4h to EXT_TX_TERM_CTRL
Quoted 29 lines
Please consider using #defines, to give values names.
...
Quoted 24 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +24
-0+static int s32g_serdes_init_clks (struct s32g_serdes *serdes) +{ +struct s32g_serdes_ctrl *ctrl = &serdes->ctrl; +struct s32g_xpcs_ctrl *xpcs = &serdes->xpcs; +int ret, order[2 ], xpcs_id; +size_t i; + +switch (ctrl->ss_mode) { +case 0 : +return 0 ; +case 1 : + order[0 ] =0 ; + order[1 ] =XPCS_DISABLED ; +break ; +case 2 : +case 5 : + order[0 ] =1 ; + order[1 ] =XPCS_DISABLED ; +break ; +case 3 : + order[0 ] =1 ; + order[1 ] =0 ; +break ; +case 4 :
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 462
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +5
-0+ order[0 ] =0 ; + order[1 ] =1 ; +break ; +default : +return -EINVAL ;AI review also flags that
s32g_serdes_get_ctrl_resources()ensures thatss_modeis <= 5. So this check is unnecessary.
okay but providing a default seems a good practice
Quoted 21 lines
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +7
-0+ } + +for (i =0 ; i <ARRAY_SIZE (order); i++) { + xpcs_id = order[i]; + +if (xpcs_id ==XPCS_DISABLED ) +continue ;drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 479
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +10
-0+ + ret =s32g_xpcs_init_plls (xpcs->phys[xpcs_id]); +if (ret) +return ret; + } + +if (ctrl->ss_mode ==5 ) { +s32g_serdes_prepare_pma_mode5 (serdes); + + ret =s32g_xpcs_pre_pcie_2g5 (xpcs->phys[1 ]);Also from the AI review:
Quoted 3 lines
In mode 5, code directly accesses xpcs->phys[1] without checking if it was created. If XPCS1 wasn't created for some reason (DT misconfiguration, probe failure), this NULL dereferences.
I will add a check
Quoted 13 lines
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c +0
-0@@ -460,6 +741,41 @@ static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod...
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod · line 769
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +5
-0+ xpcs =devm_kmalloc (dev,sizeof (*xpcs),GFP_KERNEL ); +if (IS_ERR (xpcs)) { +dev_err (dev,"Failed to allocate xpcs\n" ); +return -ENOMEM ; + }
Quoted 4 lines
AI review also flags:
devm_kmalloc()returns NULL on failure, not an error pointer. This check will never trigger.
okay
Quoted 9 lines
[1] https://netdev-ai.bots.linux.dev/ai-local.html
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int s32g2_serdes_create_phy(struct s32g_serdes *serdes, struct device_nod · line 773
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +4
-0+ + xpcs_ctrl->phys[port] = xpcs; + + xpcs->an =of_property_read_bool (dev->of_node,"nxp,xpcs_an" );AI review flags that nxp,xpcs_an is not part of the binding.
That's a leftover that should be removed
Quoted 38 lines
...
Quoted 22 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +22
-0+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; +u32 port; + +if (of_property_read_u32 (np,"reg" , &port)) +return ERR_PTR (-EINVAL ); + +if (port >S32G_SERDES_XPCS_MAX ) +return ERR_PTR (-EINVAL ); + +/* The PCS pdev is attached to the parent node */ + 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 ); + }drivers/phy/freescale/phy-nxp-s32g-serdes.c static int __maybe_unused s32g_serdes_resume(struct device *device) · line 895
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +10
-0+ + pdev =of_find_device_by_node (pcs_np); +of_node_put (pcs_np); +if (!pdev || !platform_get_drvdata (pdev)) { +if (pdev) +put_device (&pdev->dev); +return ERR_PTR (-EPROBE_DEFER ); + } + + serdes =platform_get_drvdata (pdev);Also from the AI review:
Quoted 3 lines
On success, the function gets a reference to pdev but never releases it. This leaks a device reference every time a MAC driver calls
s32g_serdes_pcs_create().
will fix it
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c static int __maybe_unused s32g_serdes_resume(struct device *device) · line 897
Quoted 3 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +2
-0+ +return &serdes->xpcs.phys[port]->pcs;
Quoted 8 lines
Also from the AI review:
The check port >
S32G_SERDES_XPCS_MAXallows port=2, but array only has indices 0 and 1.Also I'm not seeing bounds checking on port in
s32g2_serdes_create_phywhich uses port as an index for the same array both directly and indirectly vias32g_serdes_xpcs_init().
will add it
Quoted 37 lines
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +0
-0...
Quoted 30 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +30
-0+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_xpcs_regmap_config = { + .reg_bits =16 , + .val_bits =16 , + .reg_read = s32g_xpcs_regmap_reg_read,
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 237
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c +5
-0+ .reg_write = s32g_xpcs_regmap_reg_write, + .wr_table = &s32g_xpcs_wr_table, + .rd_table = &s32g_xpcs_rd_table, + .max_register = 0x1F80E1, +};AI review also flags that
s32g_xpcs_regmap_reg_readands32g_xpcs_regmap_reg_writedo not protect against concurrent access.
but regmap framework should
Quoted 2 lines
...
Simon Horman
reviewerRe: [PATCH 3/4] phy: s32g: Add serdes xpcs subsystem
Quoted 28 lines · Vincent Guittot
Quoted 23 lines · Simon Horman
On Mon, Jan 26, 2026 at 10:21:58AM +0100, Vincent Guittot wrote:
...
Quoted 1 line
drivers/phy/freescale/phy-nxp-s32g-serdes.c +0
-0...
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 369
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +9
-0+static void s32g_serdes_prepare_pma_mode5 (struct s32g_serdes *serdes) +{ +u32 val; +/* Configure TX_VBOOST_LVL and TX_TERM_CTRL */ + val =readl (serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 ); + val &= ~(EXT_TX_VBOOST_LVL_MASK |EXT_TX_TERM_CTRL_MASK ); + val |=FIELD_PREP (EXT_TX_VBOOST_LVL_MASK ,0x3 ) | +FIELD_PREP (EXT_TX_TERM_CTRL_MASK ,0x4 ); +writel (val, serdes->ctrl.ss_base +S32G_PCIE_PHY_EXT_MISC_CTRL_2 );This is part of an AI Generated review.
I have looked over it and I think it warrants investigation. For information on how to reproduce locally, as I did, please see [1].Quoted 3 lines
The entire
s32g_serdes_prepare_pma_mode5()function is ~70 lines of magic numbers with zero explanation. These appear to be hardware-specific PLL/PHY tuning parameters for 2.5G mode.
Quoted 5 lines
Unfortunately there is no additional information in the reference manual other than
*step 4:
- Write 3h toEXT_TX_VBOOST_LVL.
- Write 4h toEXT_TX_TERM_CTRL
Understood. Sometimes you have the play the hand you're dealt.
Quoted 39 lines
Quoted 30 lines
Please consider using #defines, to give values names.
...
Quoted 24 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +24
-0+static int s32g_serdes_init_clks (struct s32g_serdes *serdes) +{ +struct s32g_serdes_ctrl *ctrl = &serdes->ctrl; +struct s32g_xpcs_ctrl *xpcs = &serdes->xpcs; +int ret, order[2 ], xpcs_id; +size_t i; + +switch (ctrl->ss_mode) { +case 0 : +return 0 ; +case 1 : + order[0 ] =0 ; + order[1 ] =XPCS_DISABLED ; +break ; +case 2 : +case 5 : + order[0 ] =1 ; + order[1 ] =XPCS_DISABLED ; +break ; +case 3 : + order[0 ] =1 ; + order[1 ] =0 ; +break ; +case 4 :Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c static struct phy *s32g_serdes_phy_xlate(struct device *dev, · line 462
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-serdes.c +5
-0+ order[0 ] =0 ; + order[1 ] =1 ; +break ; +default : +return -EINVAL ;AI review also flags that
s32g_serdes_get_ctrl_resources()ensures thatss_modeis <= 5. So this check is unnecessary.
Quoted 1 line
okay but providing a default seems a good practice
Yeah, I was of two minds about forwarding on this part of the report.
...
Quoted 4 lines
Quoted 2 lines
AI review also flags that
s32g_xpcs_regmap_reg_readands32g_xpcs_regmap_reg_writedo not protect against concurrent access.but regmap framework should
If it does, then I agree there is no problem here.
Re: [PATCH 3/4] phy: s32g: Add serdes xpcs subsystem
In reply to Vincent GuittotQuoted 6 lines · Vincent Guittot
s32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Add XPCS and SGMII support.
Quoted 11 lines
Co-developed-by Ciprian Marian Costea <[email protected]>Signed-off-by Ciprian Marian Costea <[email protected]>Co-developed-by Alexandru-Catalin Ionita <[email protected]>Signed-off-by Alexandru-Catalin Ionita <[email protected]>Co-developed-by Ghennadi Procopciuc <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Co-developed-by Ionut Vicovan <[email protected]>Signed-off-by Ionut Vicovan <[email protected]>Co-developed-by Bogdan Roman <[email protected]>Signed-off-by Bogdan Roman <[email protected]>Signed-off-by Vincent Guittot <[email protected]>
I'm not doing a full review for this patch yet.
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +11
-0+/* +* Note: This function should be compatible with phylink. +* That means it should only modify link, duplex, speed +* an_complete, pause. +*/ +static int s32g_xpcs_get_state (struct s32g_xpcs *xpcs, +struct phylink_link_state *state) +{ +struct device *dev = xpcs->dev; +unsigned int mii_ctrl, val, ss; +bool ss6, ss13, an_enabled, intr_en;
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 702
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ + mii_ctrl =s32g_xpcs_read (xpcs,SR_MII_CTRL ); + an_enabled = !!(mii_ctrl &AN_ENABLE ); + intr_en = !!(s32g_xpcs_read (xpcs,VR_MII_AN_CTRL ) &MII_AN_INTR_EN ); + +/* Check this important condition */ +if (an_enabled && !intr_en) { +dev_err (dev,"Invalid SGMII AN config interrupt is disabled\n" ); +return -EINVAL ; + }
This isn't an interrupt handler. Phylink calls it from the state resolver, which _may_ be triggered by an interrupt handler, but will also be called at other times.
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 710
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+ +if (an_enabled) { +/* MLO_AN_INBAND */ + state->speed =SPEED_UNKNOWN ; + state->link =0 ; + state->duplex =DUPLEX_UNKNOWN ; + state->an_complete =0 ; + state->pause =MLO_PAUSE_NONE ;
Have you looked at the initial state that phylink sets up before calling the .pcs_get_state() method? See phylink_mac_pcs_get_state().
speed/duplex/pause/an_complete are already setup like that for you if autoneg is enabled. link is the only member you'd need to touch.
Quoted 14 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +14
-0+ val =s32g_xpcs_read (xpcs,VR_MII_AN_INTR_STS ); + +/* Interrupt is raised with each SGMII AN that is in cases +* Link down - Every SGMII link timer expire +* Link up - Once before link goes up +* So either linkup or raised interrupt mean AN was completed +*/ +if ((val &CL37_ANCMPLT_INTR ) || (val &CL37_ANSGM_STS_LINK )) { + state->an_complete =1 ; +if (val &CL37_ANSGM_STS_LINK ) + state->link =1 ; +else +return 0 ; +if (val &CL37_ANSGM_STS_DUPLEX )
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 734
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ state->duplex =DUPLEX_FULL ; + else + state->duplex = DUPLEX_HALF; + ss =FIELD_GET (CL37_ANSGM_STS_SPEED_MASK , val); + }else { +return 0 ; + } + + }else { +/* MLO_AN_FIXED, MLO_AN_PHY */
This function won't be called in those modes, so this is a misleading comment. It can be called in MLO_AN_INBAND but when autoneg is disabled.
Quoted 50 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +50
-0+ val =s32g_xpcs_read (xpcs,SR_MII_STS ); + state->link = !!(val &LINK_STS ); + state->an_complete =0 ; + state->pause =MLO_PAUSE_NONE ; + +if (mii_ctrl &DUPLEX_MODE ) + state->duplex =DUPLEX_FULL ; +else + state->duplex =DUPLEX_HALF ; + +/* +* Build similar value as CL37_ANSGM_STS_SPEED with +* SS6 and SS13 of SR_MII_CTRL: +* - 0 for 10 Mbps +* - 1 for 100 Mbps +* - 2 for 1000 Mbps +*/ + ss6 = !!(mii_ctrl &SS6 ); + ss13 = !!(mii_ctrl &SS13 ); + ss = ss6 <<1 | ss13; + } + +switch (ss) { +case CL37_ANSGM_10MBPS : + state->speed =SPEED_10 ; +break ; +case CL37_ANSGM_100MBPS : + state->speed =SPEED_100 ; +break ; +case CL37_ANSGM_1000MBPS : + state->speed =SPEED_1000 ; +break ; +default : +dev_err (dev,"Failed to interpret the value of SR_MII_CTRL\n" ); +break ; + } + + val =s32g_xpcs_read (xpcs,VR_MII_DIG_CTRL1 ); +if ((val &EN_2_5G_MODE ) && state->speed ==SPEED_1000 ) + state->speed =SPEED_2500 ; + +/* Cover SGMII AN inability to distigunish between 1G and 2.5G */ +if ((val &EN_2_5G_MODE ) && + state->speed !=SPEED_2500 && an_enabled) { +dev_err (dev,"Speed not supported in SGMII AN mode\n" ); +return -EINVAL ; + } + +return 0 ; +}
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 794
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ +static int s32g_xpcs_config_an (struct s32g_xpcs *xpcs, +const struct phylink_link_state state) +{ +bool an_enabled = false; + + an_enabled =linkmode_test_bit (ETHTOOL_LINK_MODE_Autoneg_BIT, + state.advertising); +if (!an_enabled) +return 0 ;
Don't check the autoneg bit. This is the media-side autoneg, not the PCS autoneg.
Quoted 33 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +33
-0+ +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 , +CL37_TMR_OVRRIDE ,CL37_TMR_OVRRIDE ); + +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL , +PCS_MODE_MASK |MII_AN_INTR_EN , +FIELD_PREP (PCS_MODE_MASK ,PCS_MODE_SGMII ) |MII_AN_INTR_EN ); +/* Enable SGMII AN */ +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,AN_ENABLE ,AN_ENABLE ); +/* Enable SGMII AUTO SW */ +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 , +MAC_AUTO_SW ,MAC_AUTO_SW ); + +return 0 ; +} + +static int s32g_xpcs_config (struct s32g_xpcs *xpcs, +const struct phylink_link_state state) +{ +struct device *dev = xpcs->dev; +unsigned int val =0 , duplex =0 ; +int ret =0 ; +int speed = state.speed; +bool an_enabled; + +/* Configure adaptive MII width */ +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL ,MII_CTRL ,0 ); + + an_enabled = !!(s32g_xpcs_read (xpcs,SR_MII_CTRL ) &AN_ENABLE ); + +dev_dbg (dev,"xpcs_%d: speed=%u duplex=%d an=%d\n" , xpcs->id, + speed, state.duplex, an_enabled); +
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 837
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+if (an_enabled) { +switch (speed) { +case SPEED_10 : +case SPEED_100 : +case SPEED_1000 : +s32g_xpcs_write (xpcs,VR_MII_LINK_TIMER_CTRL ,0x2faf ); +break ; +case SPEED_2500 : +s32g_xpcs_write (xpcs,VR_MII_LINK_TIMER_CTRL ,0x7a1 ); +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 ,MAC_AUTO_SW ,0 );
Configuring the link timer _after_ the link has already come up looks completely wrong to me... this should be done when .pcs_config() detects that the PHY interface mode has changed.
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 844
Quoted 7 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +7
-0+break ; +default : +dev_err (dev,"Speed not recognized. Can't setup xpcs\n" ); +return -EINVAL ; + } + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,RESTART_AN ,RESTART_AN );
As this is called from the .pcs_link_up() method, expect the link to go bouncey bouncy bouncy if you restart AN _after_ the link has come up.
Quoted 41 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +41
-0+ + ret =s32g_xpcs_wait_an_done (xpcs); +if (ret) +dev_warn (dev,"AN did not finish for XPCS%d" , xpcs->id); + +/* Clear the AN CMPL intr */ +s32g_xpcs_write_bits (xpcs,VR_MII_AN_INTR_STS ,CL37_ANCMPLT_INTR ,0 ); + }else { +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,AN_ENABLE ,0 ); +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL ,MII_AN_INTR_EN ,0 ); + +switch (speed) { +case SPEED_10 : +break ; +case SPEED_100 : + val =SS13 ; +break ; +case SPEED_1000 : + val =SS6 ; +break ; +case SPEED_2500 : + val =SS6 ; +break ; +default : +dev_err (dev,"Speed not supported\n" ); +break ; + } + +if (state.duplex ==DUPLEX_FULL ) + duplex =DUPLEX_MODE ; + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,DUPLEX_MODE , duplex); + +if (speed ==SPEED_2500 ) { + ret =s32g_serdes_bifurcation_pll_transit (xpcs,XPCS_PLLB ); +if (ret) +dev_err (dev,"Switch to PLLB failed\n" ); + }else { + ret =s32g_serdes_bifurcation_pll_transit (xpcs,XPCS_PLLA ); +if (ret) +dev_err (dev,"Switch to PLLA failed\n" );
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 895
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ } + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,SS6 |SS13 , val); + } + +return 0 ; +} + +/* +* phylink_pcs_ops fops
They are not "fops" which commonly refers to struct file_operations
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 904
Quoted 9 lines
+ */
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+ +static void s32cc_phylink_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode, +struct phylink_link_state *state) +{ +struct s32g_xpcs *xpcs =phylink_pcs_to_s32g_xpcs (pcs); + +s32g_xpcs_get_state (xpcs, state); +}
Seems to me a pointless wrapper.
Quoted 6 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +6
-0+ +static int s32cc_phylink_pcs_config (struct phylink_pcs *pcs, +unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac)
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 920
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+{ +struct s32g_xpcs *xpcs =phylink_pcs_to_s32g_xpcs (pcs); +struct phylink_link_state state = {0 }; + +if (!(neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )) +return 0 ; + +linkmode_copy (state.advertising, advertising); + +return s32g_xpcs_config_an (xpcs, state);
Given this is the only callsite for this function, and the only thing you pass is the advertising mask, why pass a struct phylink_link_state rather than the advertising mask?
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+} + +static void s32cc_phylink_pcs_restart_an (struct phylink_pcs *pcs) +{ +/* Not yet */ +} + +static void s32cc_phylink_pcs_link_up(struct phylink_pcs *pcs,
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 938
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+unsigned int neg_mode, + phy_interface_t interface, int speed, + int duplex) +{ + struct s32g_xpcs *xpcs = phylink_pcs_to_s32g_xpcs(pcs); +struct phylink_link_state state = {0 }; + + state.speed = speed; + state.duplex = duplex; + state.an_complete = false;
an_complete is never an "input" to drivers. It's a state from PCS drivers back to phylink. Also, s32g_xpcs_config never looks at this.
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 940
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +2
-0+ +s32g_xpcs_config (xpcs, state);
Again, the only things that this function uses are the speed and duplex, so why wrap them up into a struct?
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 948
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+} + +static const struct phylink_pcs_ops s32cc_phylink_pcs_ops = { + .pcs_get_state = s32cc_phylink_pcs_get_state, + .pcs_config = s32cc_phylink_pcs_config, + .pcs_an_restart = s32cc_phylink_pcs_restart_an, + .pcs_link_up = s32cc_phylink_pcs_link_up, +};
Please implement .pcs_inband_caps. As you don't support disabling inband for SGMII, that means you can't support MLO_AN_PHY mode reliably.
Also note that there are PHYs out there that do _not_ provide SGMII inband, which means if you have it enabled, and you're relying on it to complete, you won't be able to interface with those PHYs. There's such a PHY on a SFP module.
If this driver is purely for a network PCS, then please locate it in drivers/net/pcs.
I'm pretty sure there's other stuff I've missed as far as the phylink API goes, so please expect further review once you've addressed the comments above.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [PATCH 3/4] phy: s32g: Add serdes xpcs subsystem
Quoted 57 lines · Russell King (Oracle)
Quoted 6 lines · Vincent Guittot
s32g SoC family includes 2 serdes subsystems which are made of one PCIe controller, 2 XPCS and one Phy. The Phy got 2 lanes that can be configure to output PCIe lanes and/or SGMII.
Add XPCS and SGMII support.
Quoted 11 lines
Co-developed-by Ciprian Marian Costea <[email protected]>Signed-off-by Ciprian Marian Costea <[email protected]>Co-developed-by Alexandru-Catalin Ionita <[email protected]>Signed-off-by Alexandru-Catalin Ionita <[email protected]>Co-developed-by Ghennadi Procopciuc <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Co-developed-by Ionut Vicovan <[email protected]>Signed-off-by Ionut Vicovan <[email protected]>Co-developed-by Bogdan Roman <[email protected]>Signed-off-by Bogdan Roman <[email protected]>Signed-off-by Vincent Guittot <[email protected]>I'm not doing a full review for this patch yet.
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +11
-0+/* +* Note: This function should be compatible with phylink. +* That means it should only modify link, duplex, speed +* an_complete, pause. +*/ +static int s32g_xpcs_get_state (struct s32g_xpcs *xpcs, +struct phylink_link_state *state) +{ +struct device *dev = xpcs->dev; +unsigned int mii_ctrl, val, ss; +bool ss6, ss13, an_enabled, intr_en;drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 702
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ + mii_ctrl =s32g_xpcs_read (xpcs,SR_MII_CTRL ); + an_enabled = !!(mii_ctrl &AN_ENABLE ); + intr_en = !!(s32g_xpcs_read (xpcs,VR_MII_AN_CTRL ) &MII_AN_INTR_EN ); + +/* Check this important condition */ +if (an_enabled && !intr_en) { +dev_err (dev,"Invalid SGMII AN config interrupt is disabled\n" ); +return -EINVAL ; + }This isn't an interrupt handler. Phylink calls it from the state resolver, which _may_ be triggered by an interrupt handler, but will also be called at other times.
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 710
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+ +if (an_enabled) { +/* MLO_AN_INBAND */ + state->speed =SPEED_UNKNOWN ; + state->link =0 ; + state->duplex =DUPLEX_UNKNOWN ; + state->an_complete =0 ; + state->pause =MLO_PAUSE_NONE ;
Quoted 2 lines
Have you looked at the initial state that phylink sets up before calling the .pcs_get_state() method? See
phylink_mac_pcs_get_state().
okay, I'm going to have a look
Quoted 3 lines
speed/duplex/pause/an_complete are already setup like that for you if autoneg is enabled. link is the only member you'd need to touch.
Okay
Quoted 20 lines
Quoted 20 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +19
-0+ val =s32g_xpcs_read (xpcs,VR_MII_AN_INTR_STS ); + +/* Interrupt is raised with each SGMII AN that is in cases +* Link down - Every SGMII link timer expire +* Link up - Once before link goes up +* So either linkup or raised interrupt mean AN was completed +*/ +if ((val &CL37_ANCMPLT_INTR ) || (val &CL37_ANSGM_STS_LINK )) { + state->an_complete =1 ; +if (val &CL37_ANSGM_STS_LINK ) + state->link =1 ; +else +return 0 ; +if (val &CL37_ANSGM_STS_DUPLEX ) + state->duplex =DUPLEX_FULL ; +else + state->duplex =DUPLEX_HALF ; + ss =FIELD_GET (CL37_ANSGM_STS_SPEED_MASK , val); + }else {
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 734
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +5
-0+return 0 ; + } + + }else { +/* MLO_AN_FIXED, MLO_AN_PHY */ This function won't be called in those modes, so this is a misleading comment. It can be called in
MLO_AN_INBANDbut when autoneg is disabled.
Okay
Quoted 56 lines
Quoted 56 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +55
-0+ val =s32g_xpcs_read (xpcs,SR_MII_STS ); + state->link = !!(val &LINK_STS ); + state->an_complete =0 ; + state->pause =MLO_PAUSE_NONE ; + +if (mii_ctrl &DUPLEX_MODE ) + state->duplex =DUPLEX_FULL ; +else + state->duplex =DUPLEX_HALF ; + +/* +* Build similar value as CL37_ANSGM_STS_SPEED with +* SS6 and SS13 of SR_MII_CTRL: +* - 0 for 10 Mbps +* - 1 for 100 Mbps +* - 2 for 1000 Mbps +*/ + ss6 = !!(mii_ctrl &SS6 ); + ss13 = !!(mii_ctrl &SS13 ); + ss = ss6 <<1 | ss13; + } + +switch (ss) { +case CL37_ANSGM_10MBPS : + state->speed =SPEED_10 ; +break ; +case CL37_ANSGM_100MBPS : + state->speed =SPEED_100 ; +break ; +case CL37_ANSGM_1000MBPS : + state->speed =SPEED_1000 ; +break ; +default : +dev_err (dev,"Failed to interpret the value of SR_MII_CTRL\n" ); +break ; + } + + val =s32g_xpcs_read (xpcs,VR_MII_DIG_CTRL1 ); +if ((val &EN_2_5G_MODE ) && state->speed ==SPEED_1000 ) + state->speed =SPEED_2500 ; + +/* Cover SGMII AN inability to distigunish between 1G and 2.5G */ +if ((val &EN_2_5G_MODE ) && + state->speed !=SPEED_2500 && an_enabled) { +dev_err (dev,"Speed not supported in SGMII AN mode\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static int s32g_xpcs_config_an (struct s32g_xpcs *xpcs, +const struct phylink_link_state state) +{ +bool an_enabled = false;
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 794
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +5
-0+ + an_enabled =linkmode_test_bit (ETHTOOL_LINK_MODE_Autoneg_BIT, + state.advertising); +if (!an_enabled) +return 0 ;Don't check the autoneg bit. This is the media-side autoneg, not the PCS autoneg.
Okay
Quoted 40 lines
Quoted 40 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +39
-0+ +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 , +CL37_TMR_OVRRIDE ,CL37_TMR_OVRRIDE ); + +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL , +PCS_MODE_MASK |MII_AN_INTR_EN , +FIELD_PREP (PCS_MODE_MASK ,PCS_MODE_SGMII ) |MII_AN_INTR_EN ); +/* Enable SGMII AN */ +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,AN_ENABLE ,AN_ENABLE ); +/* Enable SGMII AUTO SW */ +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 , +MAC_AUTO_SW ,MAC_AUTO_SW ); + +return 0 ; +} + +static int s32g_xpcs_config (struct s32g_xpcs *xpcs, +const struct phylink_link_state state) +{ +struct device *dev = xpcs->dev; +unsigned int val =0 , duplex =0 ; +int ret =0 ; +int speed = state.speed; +bool an_enabled; + +/* Configure adaptive MII width */ +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL ,MII_CTRL ,0 ); + + an_enabled = !!(s32g_xpcs_read (xpcs,SR_MII_CTRL ) &AN_ENABLE ); + +dev_dbg (dev,"xpcs_%d: speed=%u duplex=%d an=%d\n" , xpcs->id, + speed, state.duplex, an_enabled); + +if (an_enabled) { +switch (speed) { +case SPEED_10 : +case SPEED_100 : +case SPEED_1000 : +s32g_xpcs_write (xpcs,VR_MII_LINK_TIMER_CTRL ,0x2faf );
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 837
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +4
-0+break ; +case SPEED_2500 : +s32g_xpcs_write (xpcs,VR_MII_LINK_TIMER_CTRL ,0x7a1 ); +s32g_xpcs_write_bits (xpcs,VR_MII_DIG_CTRL1 ,MAC_AUTO_SW ,0 );Configuring the link timer _after_ the link has already come up looks completely wrong to me... this should be done when .pcs_config() detects that the PHY interface mode has changed.
Okay
Quoted 67 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 844
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +7
-0+break ; +default : +dev_err (dev,"Speed not recognized. Can't setup xpcs\n" ); +return -EINVAL ; + } + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,RESTART_AN ,RESTART_AN );As this is called from the .pcs_link_up() method, expect the link to go bouncey bouncy bouncy if you restart AN _after_ the link has come up.
Quoted 41 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +41
-0+ + ret =s32g_xpcs_wait_an_done (xpcs); +if (ret) +dev_warn (dev,"AN did not finish for XPCS%d" , xpcs->id); + +/* Clear the AN CMPL intr */ +s32g_xpcs_write_bits (xpcs,VR_MII_AN_INTR_STS ,CL37_ANCMPLT_INTR ,0 ); + }else { +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,AN_ENABLE ,0 ); +s32g_xpcs_write_bits (xpcs,VR_MII_AN_CTRL ,MII_AN_INTR_EN ,0 ); + +switch (speed) { +case SPEED_10 : +break ; +case SPEED_100 : + val =SS13 ; +break ; +case SPEED_1000 : + val =SS6 ; +break ; +case SPEED_2500 : + val =SS6 ; +break ; +default : +dev_err (dev,"Speed not supported\n" ); +break ; + } + +if (state.duplex ==DUPLEX_FULL ) + duplex =DUPLEX_MODE ; + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,DUPLEX_MODE , duplex); + +if (speed ==SPEED_2500 ) { + ret =s32g_serdes_bifurcation_pll_transit (xpcs,XPCS_PLLB ); +if (ret) +dev_err (dev,"Switch to PLLB failed\n" ); + }else { + ret =s32g_serdes_bifurcation_pll_transit (xpcs,XPCS_PLLA ); +if (ret) +dev_err (dev,"Switch to PLLA failed\n" );drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 895
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+ } + +s32g_xpcs_write_bits (xpcs,SR_MII_CTRL ,SS6 |SS13 , val); + } + +return 0 ; +} + +/* +* phylink_pcs_ops fops They are not "fops" which commonly refers to struct
file_operations
Quoted 11 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 904
Quoted 9 lines
+ */
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+ +static void s32cc_phylink_pcs_get_state (struct phylink_pcs *pcs,unsigned int neg_mode, +struct phylink_link_state *state) +{ +struct s32g_xpcs *xpcs =phylink_pcs_to_s32g_xpcs (pcs); + +s32g_xpcs_get_state (xpcs, state); +}Seems to me a pointless wrapper.
okay
Quoted 13 lines
Quoted 13 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +12
-0+ +static int s32cc_phylink_pcs_config (struct phylink_pcs *pcs, +unsigned int neg_mode, +phy_interface_t interface, +const unsigned long *advertising, +bool permit_pause_to_mac) +{ +struct s32g_xpcs *xpcs =phylink_pcs_to_s32g_xpcs (pcs); +struct phylink_link_state state = {0 }; + +if (!(neg_mode ==PHYLINK_PCS_NEG_INBAND_ENABLED )) +return 0 ;
Quoted 8 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 920
Quoted 4 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +4
-0+ +linkmode_copy (state.advertising, advertising); + +return s32g_xpcs_config_an (xpcs, state);Given this is the only callsite for this function, and the only thing you pass is the advertising mask, why pass a struct
phylink_link_staterather than the advertising mask?
fair enough
Quoted 23 lines
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+} + +static void s32cc_phylink_pcs_restart_an (struct phylink_pcs *pcs) +{ +/* Not yet */ +} + +static void s32cc_phylink_pcs_link_up(struct phylink_pcs *pcs,drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 938
Quoted 10 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +10
-0+unsigned int neg_mode, + phy_interface_t interface, int speed, + int duplex) +{ + struct s32g_xpcs *xpcs = phylink_pcs_to_s32g_xpcs(pcs); +struct phylink_link_state state = {0 }; + + state.speed = speed; + state.duplex = duplex; + state.an_complete = false;
an_completeis never an "input" to drivers. It's a state from PCS drivers back to phylink. Also,s32g_xpcs_confignever looks at this.
Quoted 5 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 940
Quoted 2 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +2
-0+ +s32g_xpcs_config (xpcs, state);Again, the only things that this function uses are the speed and duplex, so why wrap them up into a struct?
will clean this
Quoted 13 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c line 948
Quoted 9 lines
drivers/phy/freescale/phy-nxp-s32g-xpcs.c new file +8
-0+} + +static const struct phylink_pcs_ops s32cc_phylink_pcs_ops = { + .pcs_get_state = s32cc_phylink_pcs_get_state, + .pcs_config = s32cc_phylink_pcs_config, + .pcs_an_restart = s32cc_phylink_pcs_restart_an, + .pcs_link_up = s32cc_phylink_pcs_link_up, +};Please implement .pcs_inband_caps. As you don't support disabling inband for SGMII, that means you can't support
MLO_AN_PHYmode reliably.
okay
Quoted 8 lines
Also note that there are PHYs out there that do _not_ provide SGMII inband, which means if you have it enabled, and you're relying on it to complete, you won't be able to interface with those PHYs. There's such a PHY on a SFP module.
If this driver is purely for a network PCS, then please locate it in
drivers/net/pcs.
That was an one open point for me because the content of this file is only called bydrivers/phy/freescale/phy-nxp-s32g-xpcs.c
So locating both in the same place looked reasonable but I can but files in different dir
Quoted 4 lines
I'm pretty sure there's other stuff I've missed as far as the phylink API goes, so please expect further review once you've addressed the comments above.
Thanks
Quoted 4 lines
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH 4/4 MAINTAINERS: Add MAINTAINER for NXP S32G Serdes driver
In reply to Vincent GuittotAdd a new entry for S32G Serdes driver.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -3202,6 +3202,15 @@ S: Maintained F: Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml F: drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +ARM/NXP S32G SERDES DRIVER +M: Ciprian Marian Costea <[email protected]> +R: NXP S32 Linux Team <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/pci/nxp,s32g-serdes.yaml +F: drivers/phy/freescale/phy-nxp-s32g-* +F: include/linux/pcs/pcs-nxp-xpcs.h + ARM/Orion SoC/Technologic Systems TS-78xx platform support M: Alexander Clouter <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.43.0
Simon Horman
reviewerRe: [PATCH 4/4] MAINTAINERS: Add MAINTAINER for NXP S32G Serdes driver
Quoted 12 lines · Vincent Guittot
Add a new entry for S32G Serdes driver.
Signed-off-by Vincent Guittot <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0
MAINTAINERS S: Maintained · line 3210
Quoted 9 lines
MAINTAINERS +6
-0@@ -3202,6 +3202,15 @@ S: Maintained F: Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml F: drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +ARM/NXP S32G SERDES DRIVER +M: Ciprian Marian Costea <[email protected]> +R: NXP S32 Linux Team <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/pci/nxp,s32g-serdes.yaml
This patchset adds the following file, not the one above:
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
^^^
Quoted 9 lines
MAINTAINERS +3
-0+F: drivers/phy/freescale/phy-nxp-s32g-* +F: include/linux/pcs/pcs-nxp-xpcs.h + ARM/Orion SoC/Technologic Systems TS-78xx platform support M: Alexander Clouter <[email protected]> L: [email protected] (moderated for non-subscribers)Signature · 1 line
2.43.0
Re: [PATCH 4/4] MAINTAINERS: Add MAINTAINER for NXP S32G Serdes driver
Quoted 26 lines · Simon Horman
Quoted 12 lines · Vincent Guittot
Add a new entry for S32G Serdes driver.
Signed-off-by Vincent Guittot <[email protected]>--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)MAINTAINERS +0
-0MAINTAINERS S: Maintained · line 3210
Quoted 9 lines
MAINTAINERS +6
-0@@ -3202,6 +3202,15 @@ S: Maintained F: Documentation/devicetree/bindings/net/nxp,s32-dwmac.yaml F: drivers/net/ethernet/stmicro/stmmac/dwmac-s32.c +ARM/NXP S32G SERDES DRIVER +M: Ciprian Marian Costea <[email protected]> +R: NXP S32 Linux Team <[email protected]> +L: [email protected] (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/pci/nxp,s32g-serdes.yamlThis patchset adds the following file, not the one above:
Quoted 1 line
Documentation/devicetree/bindings/phy/nxp,s32g-serdes.yaml
yes, that's a typo.
Quoted 11 lines
^^^Quoted 9 lines
MAINTAINERS +3
-1+F: drivers/phy/freescale/phy-nxp-s32g-* +F: include/linux/pcs/pcs-nxp-xpcs.h + ARM/Orion SoC/Technologic Systems TS-78xx platform support M: Alexander Clouter <[email protected]> L: [email protected] (moderated for non-subscribers) --2.43.0
Please drop these addresses from future patch series:
[email protected]
host nxp-com.mail.protection.outlook.com [2a01:111:f403:ca09::7] SMTP error from remote mail server after RCPT TO:<alexandru-catalin.ionita@n
xp.com>:
550 5.4.1 Recipient address rejected: Access denied. For more information se
e https://aka.ms/EXOSmtpErrors [AM4PEPF00027A62.eurprd04.prod.outlook.com 2026-0 1-29T12:31:01.197Z 08DE5971FB66165F]
[email protected]
host nxp-com.mail.protection.outlook.com [2a01:111:f403:ca09::6] SMTP error from remote mail server after RCPT TO:<[email protected]
om>:
550 5.4.1 Recipient address rejected: Access denied. For more information se
e https://aka.ms/EXOSmtpErrors [AM3PEPF0000A798.eurprd04.prod.outlook.com 2026-0 1-29T12:31:00.781Z 08DE596525364766]
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Quoted 2 lines · Russell King (Oracle)
Please drop these addresses from future patch series:
Yes, will dorp for next version
Quoted 19 lines
[email protected]
host nxp-com.mail.protection.outlook.com [2a01:111:f403:ca09::7] SMTP error from remote mail server after RCPT TO:<alexandru-catalin.ionita@n
xp.com>:
550 5.4.1 Recipient address rejected: Access denied. For more information se
e https://aka.ms/EXOSmtpErrors [AM4PEPF00027A62.eurprd04.prod.outlook.com 2026-0 1-29T12:31:01.197Z 08DE5971FB66165F]
[email protected]
host nxp-com.mail.protection.outlook.com [2a01:111:f403:ca09::6] SMTP error from remote mail server after RCPT TO:<[email protected]
om>:
550 5.4.1 Recipient address rejected: Access denied. For more information se
e https://aka.ms/EXOSmtpErrors [AM3PEPF0000A798.eurprd04.prod.outlook.com 2026-0 1-29T12:31:00.781Z 08DE596525364766]--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!