clk: en7523: Add support for selecting SCU serdes
Subsystems (2)
cover clk: en7523: Add support for selecting SCU serdes
This small series is a split from the Airoha AN7581 USB PHY series [1].
[1] https://lore.kernel.org/all/[email protected]/
Christian Marangi (2):
dt-bindings: clock: airoha: Add PHY binding for Serdes port
clk: en7523: Add support for selecting the Serdes port in SCU
.../bindings/clock/airoha,en7523-scu.yaml | 24 +- drivers/clk/Kconfig | 1 + drivers/clk/clk-en7523.c | 218 +++++++++++++++++- include/dt-bindings/soc/airoha,scu-ssr.h | 11 + 4 files changed, 248 insertions(+), 6 deletions(-) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.h
Signature · 1 line
2.53.0
PATCH 1/2 dt-bindings: clock: airoha: Add PHY binding for Serdes port
Add PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
- PCIe1 Serdes can support PCIe or Ethernet mode.
- PCIe2 Serdes can support PCIe or Ethernet mode.
- USB1 Serdes can support USB3 or HSGMII mode.
- USB2 Serdes can support USB3 or PCIe mode.
Add bindings to permit correct reference of the Serdes ports in DT. Values are just symbolic and enumerates the Serdes port with a specific number for precise reference.
The available Serdes port can be selected following the dt-binding header in [2].
[2] <include/dt-bindings/soc/airoha,scu-ssr.h>
--- .../bindings/clock/airoha,en7523-scu.yaml | 24 ++++++++++++++++--- include/dt-bindings/soc/airoha,scu-ssr.h | 11 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.h
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +21 -3
@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.
@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg
@@ -65,12 +72,23 @@ allOf: reg: minItems: 2 + '#phy-cells': false + + - if: + properties: + compatible: + const: econet,en751221-scu + then: + properties: + reg: + maxItems: 1 + + '#phy-cells': false + - if: properties: compatible: - enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:
include/dt-bindings/soc/airoha,scu-ssr.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ + +#ifndef __DT_BINDINGS_AIROHA_SCU_SSR_H +#define __DT_BINDINGS_AIROHA_SCU_SSR_H + +#define AIROHA_SCU_SERDES_PCIE1 0 +#define AIROHA_SCU_SERDES_PCIE2 1 +#define AIROHA_SCU_SERDES_USB1 2 +#define AIROHA_SCU_SERDES_USB2 3 + +#endif /* __DT_BINDINGS_AIROHA_SCU_SSR_H */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The patch introduces PHY provider capabilities for the `airoha,en7581-scu` variant by adding the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch introduces PHY provider capabilities for the airoha,en7581-scu variant by adding the #phy-cells property, but fails to make it a required property for its compatible string and does not update the example. --
--- Patch [1]: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port --- commit 5719603a01527297dc730214337f813a27ac01a3
Author: Christian Marangi <[email protected]>
dt-bindings: clock: airoha: Add PHY binding for Serdes port
This commit introduces a #phy-cells property for the airoha,en7581-scu compatible string to support Serdes port selection. It also defines the available Serdes ports in a new dt-bindings header file.
Quoted 4 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +0
-0
[ ... ]
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 94
Quoted 10 lines
- if:
properties:
compatible:Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-3- enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:
[Severity: Medium]
Should #phy-cells be added to a required list in this conditional block?
If the property is omitted for the airoha,en7581-scu hardware, device trees will silently pass schema validation despite being incomplete, which can lead to runtime failures when dependent drivers attempt to use the PHY functionality.
Additionally, does the airoha,en7581-scu example further down in the file need to be updated with #phy-cells = <1>; to satisfy validation once the property is required?
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml:examples
scuclk: clock-controller@1fb00000 {
compatible = "airoha,en7581-scu";
reg = <0x0 0x1fb00000 0x0 0x970>;
#clock-cells = <1>;
#reset-cells = <1>;
};Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
In reply to Christian MarangiHi Christian,
Quoted 68 lines · Christian Marangi
Add PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
- PCIe1 Serdes can support PCIe or Ethernet mode.
- PCIe2 Serdes can support PCIe or Ethernet mode.
- USB1 Serdes can support USB3 or HSGMII mode.
- USB2 Serdes can support USB3 or PCIe mode.Add bindings to permit correct reference of the Serdes ports in DT. Values are just symbolic and enumerates the Serdes port with a specific number for precise reference.
The available Serdes port can be selected following the dt-binding header in [2].
[2] <
include/dt-bindings/soc/airoha,scu-ssr.h>Signed-off-by Christian Marangi <[email protected]>--- .../bindings/clock/airoha,en7523-scu.yaml | 24 ++++++++++++++++--- include/dt-bindings/soc/airoha,scu-ssr.h | 11 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.hDocumentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +20
-0@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg@@ -65,12 +72,23 @@ allOf: reg: minItems: 2 + '#phy-cells': false + + - if: + properties: + compatible: + const: econet,en751221-scu + then: + properties: + reg: + maxItems: 1 + + '#phy-cells': false +
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 94
Quoted 10 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-3- if: properties: compatible: - enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:
This chunk is new since the split out v10 series[1]. I see that you dropped krzk's Reviewed-by presumably because of the new chunk. However I don't see a changelog.
I'm collecting patches up for a clk pull to Stephen. (I'm not sure if he's going to pull but I'm going to try.) I'm not going to include this series until I see a Reviewed-by by one of the dt maintainers on the new patch.
https://lore.kernel.org/all/[email protected]/
Brian
Re: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
Quoted 86 lines · Brian Masney
Hi Christian,
Quoted 68 lines · Christian Marangi
Add PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
- PCIe1 Serdes can support PCIe or Ethernet mode.
- PCIe2 Serdes can support PCIe or Ethernet mode.
- USB1 Serdes can support USB3 or HSGMII mode.
- USB2 Serdes can support USB3 or PCIe mode.Add bindings to permit correct reference of the Serdes ports in DT. Values are just symbolic and enumerates the Serdes port with a specific number for precise reference.
The available Serdes port can be selected following the dt-binding header in [2].
[2] <
include/dt-bindings/soc/airoha,scu-ssr.h>Signed-off-by Christian Marangi <[email protected]>--- .../bindings/clock/airoha,en7523-scu.yaml | 24 ++++++++++++++++--- include/dt-bindings/soc/airoha,scu-ssr.h | 11 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.hDocumentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +20
-0@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg@@ -65,12 +72,23 @@ allOf: reg: minItems: 2 + '#phy-cells': false + + - if: + properties: + compatible: + const: econet,en751221-scu + then: + properties: + reg: + maxItems: 1 + + '#phy-cells': false +Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 94
Quoted 10 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-3- if: properties: compatible: - enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:This chunk is new since the split out v10 series[1]. I see that you dropped krzk's Reviewed-by presumably because of the new chunk. However I don't see a changelog.
Quoted 7 lines
I'm collecting patches up for a clk pull to Stephen. (I'm not sure if he's going to pull but I'm going to try.) I'm not going to include this series until I see a Reviewed-by by one of the dt maintainers on the new patch.
Hi Brian,
yes all correct. I dropped as the patch changed (change is trivial but not correct)
It's ok as long as stuff gets eventually picked ahahah
Signature · 1 line
Ansuel
Re: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
Quoted 64 lines · Christian Marangi
Quoted 63 lines · Brian Masney
Quoted 42 lines · Christian Marangi
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +20
-0@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg@@ -65,12 +72,23 @@ allOf: reg: minItems: 2 + '#phy-cells': false + + - if: + properties: + compatible: + const: econet,en751221-scu + then: + properties: + reg: + maxItems: 1 + + '#phy-cells': false +Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 94
Quoted 10 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-3- if: properties: compatible: - enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:This chunk is new since the split out v10 series[1]. I see that you dropped krzk's Reviewed-by presumably because of the new chunk. However I don't see a changelog.
I'm collecting patches up for a clk pull to Stephen. (I'm not sure if he's going to pull but I'm going to try.) I'm not going to include this series until I see a Reviewed-by by one of the dt maintainers on the new patch.
Quoted 7 lines
Quoted 2 lines
Hi Brian,
yes all correct. I dropped as the patch changed (change is trivial but not correct)
But not correct? Do you need to post a new version of this series?
If this version is correct, then I suggest including a changelog here for krzk.
Brian
Re: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
Quoted 68 lines · Brian Masney
Quoted 67 lines · Christian Marangi
Quoted 65 lines · Brian Masney
Quoted 42 lines · Christian Marangi
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +20
-0@@ -23,6 +23,7 @@ description: | All these identifiers can be found in: [1]: <include/dt-bindings/clock/en7523-clk.h>. + [2]: <include/dt-bindings/soc/airoha,scu-ssr.h>. The clocks are provided inside a system controller node.@@ -50,6 +51,12 @@ properties: description: ID of the controller reset line const: 1 + '#phy-cells': + description: + The first cell indicates the serdes phy number, see [2] for the + available serdes port. + const: 1 + required: - compatible - reg@@ -65,12 +72,23 @@ allOf: reg: minItems: 2 + '#phy-cells': false + + - if: + properties: + compatible: + const: econet,en751221-scu + then: + properties: + reg: + maxItems: 1 + + '#phy-cells': false +Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml allOf: · line 94
Quoted 10 lines
Documentation/devicetree/bindings/clock/airoha,en7523-scu.yaml +1
-3- if: properties: compatible: - enum: - - airoha,en7581-scu - - econet,en751221-scu + const: airoha,en7581-scu then: properties: reg:This chunk is new since the split out v10 series[1]. I see that you dropped krzk's Reviewed-by presumably because of the new chunk. However I don't see a changelog.
I'm collecting patches up for a clk pull to Stephen. (I'm not sure if he's going to pull but I'm going to try.) I'm not going to include this series until I see a Reviewed-by by one of the dt maintainers on the new patch.
Quoted 7 lines
Quoted 4 lines
Hi Brian,
yes all correct. I dropped as the patch changed (change is trivial but not correct)
But not correct? Do you need to post a new version of this series?
Also the previous one was O.K.. This is just better.
Quoted 3 lines
If this version is correct, then I suggest including a changelog here for krzk.
Let me add the changelog here so he can quickly check the change:
Changelog from v10 series:
- Rework if condition and reject #phy-cells for
econet,en751221-scu compatible.
Signature · 1 line
Ansuel
Re: [PATCH 1/2] dt-bindings: clock: airoha: Add PHY binding for Serdes port
In reply to Christian MarangiQuoted 17 lines · Christian Marangi
Add PHY cell property for Serdes port selection. Currently supported only for Airoha AN7581 SoC, that support up to 4 Serdes port.
The Serdes port can support both PCIe, USB3 or Ethernet mode.
- PCIe1 Serdes can support PCIe or Ethernet mode.
- PCIe2 Serdes can support PCIe or Ethernet mode.
- USB1 Serdes can support USB3 or HSGMII mode.
- USB2 Serdes can support USB3 or PCIe mode.Add bindings to permit correct reference of the Serdes ports in DT. Values are just symbolic and enumerates the Serdes port with a specific number for precise reference.
The available Serdes port can be selected following the dt-binding header in [2].
Quoted 9 lines
[2] <
include/dt-bindings/soc/airoha,scu-ssr.h>Signed-off-by Christian Marangi <[email protected]>--- .../bindings/clock/airoha,en7523-scu.yaml | 24 ++++++++++++++++--- include/dt-bindings/soc/airoha,scu-ssr.h | 11 +++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 include/dt-bindings/soc/airoha,scu-ssr.h
PATCH 2/2 clk: en7523: Add support for selecting the Serdes port in SCU
In reply to Christian MarangiIn the SCU register for clock and reset, there are also some register to select the Serdes port mode. The Airoha AN7581 SoC have 4 different Serdes that can switch between PCIe, USB or Ethernet mode.
Add a simple PHY provider that expose the .set_mode OP to toggle the requested mode for the Serdes port.
--- drivers/clk/Kconfig | 1 + drivers/clk/clk-en7523.c | 218 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 216 insertions(+), 3 deletions(-)
drivers/clk/Kconfig +1 -0
@@ -221,6 +221,7 @@ config COMMON_CLK_EN7523 bool "Clock driver for Airoha/EcoNet SoC system clocks" depends on OF depends on ARCH_AIROHA || ECONET || COMPILE_TEST + select GENERIC_PHY default ARCH_AIROHA help This driver provides the fixed clocks and gates present on Airoha
drivers/clk/clk-en7523.c +215 -3
293 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH 2/2] clk: en7523: Add support for selecting the Serdes port in SCU
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The PHY set_mode callback incorrectly rejects USB host and OTG modes, breaking USB host functionality.
Pre-existing issues:
- [High] Missing spinlock in reset operations allows concurrent reset assertions to corrupt shared reset control registers.
- [High] Probe failure leaves unregistered clocks in the clock core, causing a Use-After-Free and memory leak when devres frees the clock structures. --
--- Patch [2]: [PATCH 2/2] clk: en7523: Add support for selecting the Serdes port in SCU --- commit e81bbf2efd265f6528ea23e2f2c71e904963fc17
Author: Christian Marangi <[email protected]>
clk: en7523: Add support for selecting the Serdes port in SCU
In the SCU register for clock and reset, there are also some register to select the Serdes port mode. The Airoha AN7581 SoC have 4 different Serdes that can switch between PCIe, USB or Ethernet mode.
Add a simple PHY provider that expose the .set_mode OP to toggle the requested mode for the Serdes port.
Quoted 4 lines
drivers/clk/clk-en7523.c +0
-0
[ ... ]
Quoted 7 lines
drivers/clk/clk-en7523.c +3
-0@@ -830,12 +861,179 @@ static int en7581_reset_register(struct device *dev, void __iomem *base,return devm_reset_controller_register (dev, &rst_data->rcdev); } +static int en7581_serdes_phy_set_mode (struct phy *phy,enum phy_mode mode, +int submode) +{
[ ... ]
drivers/clk/clk-en7523.c static int en7581_reset_register(struct device *dev, void __iomem *base, · line 931
Quoted 7 lines
drivers/clk/clk-en7523.c +7
-0+case AIROHA_SCU_SERDES_USB1 : + reg =REG_NP_SCU_SSR3 ; + mask =REG_SSUSB_HSGMII_SEL_MASK ; + +if (mode !=PHY_MODE_ETHERNET && mode !=PHY_MODE_USB_DEVICE && + mode !=PHY_MODE_USB_DEVICE_SS ) +return -EINVAL ;
[Severity: High]
Does this validation block USB host and OTG operations for the USB1 port?
If a USB controller driver calls phy_set_mode(phy, PHY_MODE_USB_HOST) or PHY_MODE_USB_OTG during initialization, it appears this check will reject it and return -EINVAL, bypassing the register write and leaving the Serdes lanes uninitialized.
Quoted 4 lines
drivers/clk/clk-en7523.c +4
-0+ +if (mode ==PHY_MODE_ETHERNET ) + sel =REG_SSUSB_HSGMII_SEL_HSGMII ; +else
drivers/clk/clk-en7523.c static int en7581_reset_register(struct device *dev, void __iomem *base, · line 945
Quoted 10 lines
drivers/clk/clk-en7523.c +10
-0+ sel =REG_SSUSB_HSGMII_SEL_USB ; + +break ; +case AIROHA_SCU_SERDES_USB2 : + reg =REG_NP_SCU_SSTR ; + mask =REG_USB_PCIE_SEL_MASK ; + +if (mode !=PHY_MODE_PCIE && mode !=PHY_MODE_USB_DEVICE && + mode !=PHY_MODE_USB_DEVICE_SS ) +return -EINVAL ;
[Severity: High]
Similarly, does this logic improperly reject PHY_MODE_USB_HOST and PHY_MODE_USB_OTG for the USB2 Serdes port?
[ ... ]
drivers/clk/clk-en7523.c static int en7581_clk_hw_init(struct platform_device *pdev, · line 1057
Quoted 9 lines
drivers/clk/clk-en7523.c +2
-3@@ -853,9 +1053,12 @@ static int en7581_clk_hw_init(struct platform_device *pdev, val =readl (base +REG_NP_SCU_PCIC );writel (val |3 , base +REG_NP_SCU_PCIC ); -return en7581_reset_register (&pdev->dev, base, en7581_rst_map, -ARRAY_SIZE (en7581_rst_map), - en7581_rst_ofs); + ret =en7581_reset_register (&pdev->dev, base, en7581_rst_map, +ARRAY_SIZE (en7581_rst_map), en7581_rst_ofs);
[Severity: High]
This is a pre-existing issue, but does the lack of a spinlock in the reset operations allow concurrent reset assertions to corrupt shared registers?
If multiple driver probes (e.g., PCIe, USB, Ethernet) call en7523_reset_update() or en7523_pci_prepare() concurrently, both functions perform unlocked read-modify-write sequences on REG_RESET_CONTROL1:
en7523_reset_update() {
...
val = readl(addr);
if (assert)
val |= BIT(id % RST_NR_PER_BANK);
else
val &= ~BIT(id % RST_NR_PER_BANK);
writel(val, addr);
}Could a race condition here cause one IP block to be wedged in reset because its update was lost?
drivers/clk/clk-en7523.c static int en7581_clk_hw_init(struct platform_device *pdev, · line 1061
Quoted 4 lines
drivers/clk/clk-en7523.c +4
-0+if (ret) +return ret; + +return en7581_serdes_phy_register (&pdev->dev);
[Severity: High]
This is a pre-existing issue, but does this new error path expose a memory leak and use-after-free of struct en_clk_gate in the clock core?
The clocks are allocated with devres but registered with unmanaged APIs:
en7523_register_pcie_clk() {
...
cg = devm_kzalloc(dev, sizeof(*cg), GFP_KERNEL);
...
err = clk_hw_register(dev, hw);
}If en7581_serdes_phy_register() returns an error here, the probe fails and devres will automatically free cg. However, because clk_hw_register() was used, the clock remains registered in CCF.
Would this leave a dangling pointer in the clock core that causes a crash on subsequent access to /sys/kernel/debug/clk?
Quoted 3 lines
drivers/clk/clk-en7523.c +0
-0}static enum en_hir get_hw_id (void __iomem *np_base)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2