Merge branch 'fix-broken-link-with-th1520-gmac-when-linkspeed-changes'

Yao Zi says:

====================
Fix broken link with TH1520 GMAC when linkspeed changes

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.

Further testing shows perisys-apb4-hclk must be ungated for normal
access to Th1520 GMAC APB glue registers, which is neither described in
dt-binding nor acquired by the driver.

This series expands the dt-binding of TH1520's GMAC to allow an extra
"APB glue registers interface clock", instructs the driver to acquire
and enable the clock, and finally supplies CLK_PERISYS_APB4_HCLK for
TH1520's GMACs in SoC devicetree.

v2: https://lore.kernel.org/netdev/20250801091240.46114-1-ziyao@disroot.org/
v1: https://lore.kernel.org/all/20250729093734.40132-1-ziyao@disroot.org/
====================

Link: https://patch.msgid.link/20250808093655.48074-2-ziyao@disroot.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Paolo Abeni 2025-08-12 12:52:24 +02:00
commit b3e8c3dfce
3 changed files with 24 additions and 6 deletions

View file

@ -62,11 +62,13 @@ properties:
items: items:
- description: GMAC main clock - description: GMAC main clock
- description: Peripheral registers interface clock - description: Peripheral registers interface clock
- description: APB glue registers interface clock
clock-names: clock-names:
items: items:
- const: stmmaceth - const: stmmaceth
- const: pclk - const: pclk
- const: apb
interrupts: interrupts:
items: items:
@ -88,8 +90,8 @@ examples:
compatible = "thead,th1520-gmac", "snps,dwmac-3.70a"; compatible = "thead,th1520-gmac", "snps,dwmac-3.70a";
reg = <0xe7070000 0x2000>, <0xec003000 0x1000>; reg = <0xe7070000 0x2000>, <0xec003000 0x1000>;
reg-names = "dwmac", "apb"; reg-names = "dwmac", "apb";
clocks = <&clk 1>, <&clk 2>; clocks = <&clk 1>, <&clk 2>, <&clk 3>;
clock-names = "stmmaceth", "pclk"; clock-names = "stmmaceth", "pclk", "apb";
interrupts = <66>; interrupts = <66>;
interrupt-names = "macirq"; interrupt-names = "macirq";
phy-mode = "rgmii-id"; phy-mode = "rgmii-id";

View file

@ -297,8 +297,9 @@
reg-names = "dwmac", "apb"; reg-names = "dwmac", "apb";
interrupts = <67 IRQ_TYPE_LEVEL_HIGH>; interrupts = <67 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq"; interrupt-names = "macirq";
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>; clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>,
clock-names = "stmmaceth", "pclk"; <&clk CLK_PERISYS_APB4_HCLK>;
clock-names = "stmmaceth", "pclk", "apb";
snps,pbl = <32>; snps,pbl = <32>;
snps,fixed-burst; snps,fixed-burst;
snps,multicast-filter-bins = <64>; snps,multicast-filter-bins = <64>;
@ -319,8 +320,9 @@
reg-names = "dwmac", "apb"; reg-names = "dwmac", "apb";
interrupts = <66 IRQ_TYPE_LEVEL_HIGH>; interrupts = <66 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "macirq"; interrupt-names = "macirq";
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>; clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>,
clock-names = "stmmaceth", "pclk"; <&clk CLK_PERISYS_APB4_HCLK>;
clock-names = "stmmaceth", "pclk", "apb";
snps,pbl = <32>; snps,pbl = <32>;
snps,fixed-burst; snps,fixed-burst;
snps,multicast-filter-bins = <64>; snps,multicast-filter-bins = <64>;

View file

@ -211,6 +211,7 @@ static int thead_dwmac_probe(struct platform_device *pdev)
struct stmmac_resources stmmac_res; struct stmmac_resources stmmac_res;
struct plat_stmmacenet_data *plat; struct plat_stmmacenet_data *plat;
struct thead_dwmac *dwmac; struct thead_dwmac *dwmac;
struct clk *apb_clk;
void __iomem *apb; void __iomem *apb;
int ret; int ret;
@ -224,6 +225,19 @@ static int thead_dwmac_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(plat), return dev_err_probe(&pdev->dev, PTR_ERR(plat),
"dt configuration failed\n"); "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); dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
if (!dwmac) if (!dwmac)
return -ENOMEM; return -ENOMEM;