* [PATCH net v3 1/3] dt-bindings: net: thead,th1520-gmac: Describe APB interface clock
2025-08-08 9:36 [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes Yao Zi
@ 2025-08-08 9:36 ` Yao Zi
2025-08-08 9:36 ` [PATCH net v3 2/3] net: stmmac: thead: Get and enable APB clock on initialization Yao Zi
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Yao Zi @ 2025-08-08 9:36 UTC (permalink / raw)
To: Drew Fustini, Guo Ren, Fu Wei, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Emil Renner Berthing, Jisheng Zhang
Cc: linux-riscv, netdev, devicetree, linux-kernel, Yao Zi,
Krzysztof Kozlowski
Besides ones for GMAC core and peripheral registers, the TH1520 GMAC
requires one more clock for configuring APB glue registers. Describe
it in the binding.
Fixes: f920ce04c399 ("dt-bindings: net: Add T-HEAD dwmac support")
Signed-off-by: Yao Zi <ziyao@disroot.org>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Drew Fustini <fustini@kernel.org>
---
.../devicetree/bindings/net/thead,th1520-gmac.yaml | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml b/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml
index 6d9de3303762..b3492a9aa4ef 100644
--- a/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml
+++ b/Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml
@@ -62,11 +62,13 @@ properties:
items:
- description: GMAC main clock
- description: Peripheral registers interface clock
+ - description: APB glue registers interface clock
clock-names:
items:
- const: stmmaceth
- const: pclk
+ - const: apb
interrupts:
items:
@@ -88,8 +90,8 @@ examples:
compatible = "thead,th1520-gmac", "snps,dwmac-3.70a";
reg = <0xe7070000 0x2000>, <0xec003000 0x1000>;
reg-names = "dwmac", "apb";
- clocks = <&clk 1>, <&clk 2>;
- clock-names = "stmmaceth", "pclk";
+ clocks = <&clk 1>, <&clk 2>, <&clk 3>;
+ clock-names = "stmmaceth", "pclk", "apb";
interrupts = <66>;
interrupt-names = "macirq";
phy-mode = "rgmii-id";
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net v3 2/3] net: stmmac: thead: Get and enable APB clock on initialization
2025-08-08 9:36 [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes Yao Zi
2025-08-08 9:36 ` [PATCH net v3 1/3] dt-bindings: net: thead,th1520-gmac: Describe APB interface clock Yao Zi
@ 2025-08-08 9:36 ` Yao Zi
2025-08-08 22:42 ` Drew Fustini
2025-08-08 9:36 ` [PATCH net v3 3/3] riscv: dts: thead: Add APB clocks for TH1520 GMACs Yao Zi
2025-08-12 12:31 ` [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes patchwork-bot+netdevbpf
3 siblings, 1 reply; 6+ messages in thread
From: Yao Zi @ 2025-08-08 9:36 UTC (permalink / raw)
To: Drew Fustini, Guo Ren, Fu Wei, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Emil Renner Berthing, Jisheng Zhang
Cc: linux-riscv, netdev, devicetree, linux-kernel, Yao Zi
It's necessary to adjust the MAC TX clock when the linkspeed changes,
but it's noted such adjustment always fails on TH1520 SoC, and reading
back from APB glue registers that control clock generation results in
garbage, causing broken link.
With some testing, it's found a clock must be ungated for access to APB
glue registers. Without any consumer, the clock is automatically
disabled during late kernel startup. Let's get and enable it if it's
described in devicetree.
For backward compatibility with older devicetrees, probing won't fail if
the APB clock isn't found. In this case, we emit a warning since the
link will break if the speed changes.
Fixes: 33a1a01e3afa ("net: stmmac: Add glue layer for T-HEAD TH1520 SoC")
Signed-off-by: Yao Zi <ziyao@disroot.org>
Tested-by: Drew Fustini <fustini@kernel.org>
---
drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
index c72ee759aae5..f2946bea0bc2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
@@ -211,6 +211,7 @@ static int thead_dwmac_probe(struct platform_device *pdev)
struct stmmac_resources stmmac_res;
struct plat_stmmacenet_data *plat;
struct thead_dwmac *dwmac;
+ struct clk *apb_clk;
void __iomem *apb;
int ret;
@@ -224,6 +225,19 @@ static int thead_dwmac_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(plat),
"dt configuration failed\n");
+ /*
+ * The APB clock is essential for accessing glue registers. However,
+ * old devicetrees don't describe it correctly. We continue to probe
+ * and emit a warning if it isn't present.
+ */
+ apb_clk = devm_clk_get_enabled(&pdev->dev, "apb");
+ if (PTR_ERR(apb_clk) == -ENOENT)
+ dev_warn(&pdev->dev,
+ "cannot get apb clock, link may break after speed changes\n");
+ else if (IS_ERR(apb_clk))
+ return dev_err_probe(&pdev->dev, PTR_ERR(apb_clk),
+ "failed to get apb clock\n");
+
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
if (!dwmac)
return -ENOMEM;
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 2/3] net: stmmac: thead: Get and enable APB clock on initialization
2025-08-08 9:36 ` [PATCH net v3 2/3] net: stmmac: thead: Get and enable APB clock on initialization Yao Zi
@ 2025-08-08 22:42 ` Drew Fustini
0 siblings, 0 replies; 6+ messages in thread
From: Drew Fustini @ 2025-08-08 22:42 UTC (permalink / raw)
To: Yao Zi
Cc: Guo Ren, Fu Wei, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Emil Renner Berthing, Jisheng Zhang, linux-riscv,
netdev, devicetree, linux-kernel
On Fri, Aug 08, 2025 at 09:36:55AM +0000, Yao Zi wrote:
> It's necessary to adjust the MAC TX clock when the linkspeed changes,
> but it's noted such adjustment always fails on TH1520 SoC, and reading
> back from APB glue registers that control clock generation results in
> garbage, causing broken link.
>
> With some testing, it's found a clock must be ungated for access to APB
> glue registers. Without any consumer, the clock is automatically
> disabled during late kernel startup. Let's get and enable it if it's
> described in devicetree.
>
> For backward compatibility with older devicetrees, probing won't fail if
> the APB clock isn't found. In this case, we emit a warning since the
> link will break if the speed changes.
>
> Fixes: 33a1a01e3afa ("net: stmmac: Add glue layer for T-HEAD TH1520 SoC")
> Signed-off-by: Yao Zi <ziyao@disroot.org>
> Tested-by: Drew Fustini <fustini@kernel.org>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
> index c72ee759aae5..f2946bea0bc2 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c
> @@ -211,6 +211,7 @@ static int thead_dwmac_probe(struct platform_device *pdev)
> struct stmmac_resources stmmac_res;
> struct plat_stmmacenet_data *plat;
> struct thead_dwmac *dwmac;
> + struct clk *apb_clk;
> void __iomem *apb;
> int ret;
>
> @@ -224,6 +225,19 @@ static int thead_dwmac_probe(struct platform_device *pdev)
> return dev_err_probe(&pdev->dev, PTR_ERR(plat),
> "dt configuration failed\n");
>
> + /*
> + * The APB clock is essential for accessing glue registers. However,
> + * old devicetrees don't describe it correctly. We continue to probe
> + * and emit a warning if it isn't present.
> + */
> + apb_clk = devm_clk_get_enabled(&pdev->dev, "apb");
> + if (PTR_ERR(apb_clk) == -ENOENT)
> + dev_warn(&pdev->dev,
> + "cannot get apb clock, link may break after speed changes\n");
> + else if (IS_ERR(apb_clk))
> + return dev_err_probe(&pdev->dev, PTR_ERR(apb_clk),
> + "failed to get apb clock\n");
> +
> dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
> if (!dwmac)
> return -ENOMEM;
> --
> 2.50.1
>
Reviewed-by: Drew Fustini <fustini@kernel.org>
Thanks for improving the commit description and adding the warning.
Drew
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v3 3/3] riscv: dts: thead: Add APB clocks for TH1520 GMACs
2025-08-08 9:36 [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes Yao Zi
2025-08-08 9:36 ` [PATCH net v3 1/3] dt-bindings: net: thead,th1520-gmac: Describe APB interface clock Yao Zi
2025-08-08 9:36 ` [PATCH net v3 2/3] net: stmmac: thead: Get and enable APB clock on initialization Yao Zi
@ 2025-08-08 9:36 ` Yao Zi
2025-08-12 12:31 ` [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: Yao Zi @ 2025-08-08 9:36 UTC (permalink / raw)
To: Drew Fustini, Guo Ren, Fu Wei, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
Albert Ou, Alexandre Ghiti, Emil Renner Berthing, Jisheng Zhang
Cc: linux-riscv, netdev, devicetree, linux-kernel, Yao Zi
Describe perisys-apb4-hclk as the APB clock for TH1520 SoC, which is
essential for accessing GMAC glue registers.
Fixes: 7e756671a664 ("riscv: dts: thead: Add TH1520 ethernet nodes")
Signed-off-by: Yao Zi <ziyao@disroot.org>
Reviewed-by: Drew Fustini <fustini@kernel.org>
Tested-by: Drew Fustini <fustini@kernel.org>
---
arch/riscv/boot/dts/thead/th1520.dtsi | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/boot/dts/thead/th1520.dtsi b/arch/riscv/boot/dts/thead/th1520.dtsi
index 42724bf7e90e..03f1d7319049 100644
--- a/arch/riscv/boot/dts/thead/th1520.dtsi
+++ b/arch/riscv/boot/dts/thead/th1520.dtsi
@@ -297,8 +297,9 @@ gmac1: ethernet@ffe7060000 {
reg-names = "dwmac", "apb";
interrupts = <67 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq";
- clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>;
- clock-names = "stmmaceth", "pclk";
+ clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>,
+ <&clk CLK_PERISYS_APB4_HCLK>;
+ clock-names = "stmmaceth", "pclk", "apb";
snps,pbl = <32>;
snps,fixed-burst;
snps,multicast-filter-bins = <64>;
@@ -319,8 +320,9 @@ gmac0: ethernet@ffe7070000 {
reg-names = "dwmac", "apb";
interrupts = <66 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq";
- clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>;
- clock-names = "stmmaceth", "pclk";
+ clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>,
+ <&clk CLK_PERISYS_APB4_HCLK>;
+ clock-names = "stmmaceth", "pclk", "apb";
snps,pbl = <32>;
snps,fixed-burst;
snps,multicast-filter-bins = <64>;
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes
2025-08-08 9:36 [PATCH net v3 0/3] Fix broken link with TH1520 GMAC when linkspeed changes Yao Zi
` (2 preceding siblings ...)
2025-08-08 9:36 ` [PATCH net v3 3/3] riscv: dts: thead: Add APB clocks for TH1520 GMACs Yao Zi
@ 2025-08-12 12:31 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-12 12:31 UTC (permalink / raw)
To: Yao Zi
Cc: fustini, guoren, wefu, andrew+netdev, davem, edumazet, kuba,
pabeni, robh, krzk+dt, conor+dt, paul.walmsley, palmer, aou, alex,
emil.renner.berthing, jszhang, linux-riscv, netdev, devicetree,
linux-kernel
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 8 Aug 2025 09:36:53 +0000 you wrote:
> It's noted that on TH1520 SoC, the GMAC's link becomes broken after
> the link speed is changed (for example, running ethtool -s eth0 speed
> 100 on the peer when negotiated to 1Gbps), but the GMAC could function
> normally if the speed is brought back to the initial.
>
> Just like many other SoCs utilizing STMMAC IP, we need to adjust the TX
> clock supplying TH1520's GMAC through some SoC-specific glue registers
> when linkspeed changes. But it's found that after the full kernel
> startup, reading from them results in garbage and writing to them makes
> no effect, which is the cause of broken link.
>
> [...]
Here is the summary with links:
- [net,v3,1/3] dt-bindings: net: thead,th1520-gmac: Describe APB interface clock
https://git.kernel.org/netdev/net/c/c8a9a619c072
- [net,v3,2/3] net: stmmac: thead: Get and enable APB clock on initialization
https://git.kernel.org/netdev/net/c/4cc339ce482b
- [net,v3,3/3] riscv: dts: thead: Add APB clocks for TH1520 GMACs
https://git.kernel.org/netdev/net/c/a7f75e2883c4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread