Skip to content

Commit b3e8c3d

Browse files
author
Paolo Abeni
committed
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/[email protected]/ v1: https://lore.kernel.org/all/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 8ea2527 + a7f75e2 commit b3e8c3d

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Documentation/devicetree/bindings/net/thead,th1520-gmac.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ properties:
6262
items:
6363
- description: GMAC main clock
6464
- description: Peripheral registers interface clock
65+
- description: APB glue registers interface clock
6566

6667
clock-names:
6768
items:
6869
- const: stmmaceth
6970
- const: pclk
71+
- const: apb
7072

7173
interrupts:
7274
items:
@@ -88,8 +90,8 @@ examples:
8890
compatible = "thead,th1520-gmac", "snps,dwmac-3.70a";
8991
reg = <0xe7070000 0x2000>, <0xec003000 0x1000>;
9092
reg-names = "dwmac", "apb";
91-
clocks = <&clk 1>, <&clk 2>;
92-
clock-names = "stmmaceth", "pclk";
93+
clocks = <&clk 1>, <&clk 2>, <&clk 3>;
94+
clock-names = "stmmaceth", "pclk", "apb";
9395
interrupts = <66>;
9496
interrupt-names = "macirq";
9597
phy-mode = "rgmii-id";

arch/riscv/boot/dts/thead/th1520.dtsi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@
297297
reg-names = "dwmac", "apb";
298298
interrupts = <67 IRQ_TYPE_LEVEL_HIGH>;
299299
interrupt-names = "macirq";
300-
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>;
301-
clock-names = "stmmaceth", "pclk";
300+
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC1>,
301+
<&clk CLK_PERISYS_APB4_HCLK>;
302+
clock-names = "stmmaceth", "pclk", "apb";
302303
snps,pbl = <32>;
303304
snps,fixed-burst;
304305
snps,multicast-filter-bins = <64>;
@@ -319,8 +320,9 @@
319320
reg-names = "dwmac", "apb";
320321
interrupts = <66 IRQ_TYPE_LEVEL_HIGH>;
321322
interrupt-names = "macirq";
322-
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>;
323-
clock-names = "stmmaceth", "pclk";
323+
clocks = <&clk CLK_GMAC_AXI>, <&clk CLK_GMAC0>,
324+
<&clk CLK_PERISYS_APB4_HCLK>;
325+
clock-names = "stmmaceth", "pclk", "apb";
324326
snps,pbl = <32>;
325327
snps,fixed-burst;
326328
snps,multicast-filter-bins = <64>;

drivers/net/ethernet/stmicro/stmmac/dwmac-thead.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static int thead_dwmac_probe(struct platform_device *pdev)
211211
struct stmmac_resources stmmac_res;
212212
struct plat_stmmacenet_data *plat;
213213
struct thead_dwmac *dwmac;
214+
struct clk *apb_clk;
214215
void __iomem *apb;
215216
int ret;
216217

@@ -224,6 +225,19 @@ static int thead_dwmac_probe(struct platform_device *pdev)
224225
return dev_err_probe(&pdev->dev, PTR_ERR(plat),
225226
"dt configuration failed\n");
226227

228+
/*
229+
* The APB clock is essential for accessing glue registers. However,
230+
* old devicetrees don't describe it correctly. We continue to probe
231+
* and emit a warning if it isn't present.
232+
*/
233+
apb_clk = devm_clk_get_enabled(&pdev->dev, "apb");
234+
if (PTR_ERR(apb_clk) == -ENOENT)
235+
dev_warn(&pdev->dev,
236+
"cannot get apb clock, link may break after speed changes\n");
237+
else if (IS_ERR(apb_clk))
238+
return dev_err_probe(&pdev->dev, PTR_ERR(apb_clk),
239+
"failed to get apb clock\n");
240+
227241
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
228242
if (!dwmac)
229243
return -ENOMEM;

0 commit comments

Comments
 (0)