Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: armada-38x: fix NETA lockup when repeatedly switching speeds

The mvneta hardware appears to lock up in various random ways when
repeatedly switching speeds between 1G and 2.5G, which involves
reprogramming the COMPHY. It is not entirely clear why this happens,
but best guess is that reprogramming the COMPHY glitches mvneta clocks
causing the hardware to fail. It seems that rebooting resolves the
failure, but not down/up cycling the interface alone.

Various other approaches have been tried, such as trying to cleanly
power down the COMPHY and then take it back through the power up
initialisation, but this does not seem to help.

It was finally noticed that u-boot's last step when configuring a
COMPHY for "SGMII" mode was to poke at a register described as
"GBE_CONFIGURATION_REG", which is undocumented in any external
documentation. All that we have is the fact that u-boot sets a bit
corresponding to the "SGMII" lane at the end of COMPHY initialisation.

Experimentation shows that if we clear this bit prior to changing the
speed, and then set it afterwards, mvneta does not suffer this problem
on the SolidRun Clearfog when switching speeds between 1G and 2.5G.

This problem was found while script-testing phylink.

This fix also requires the corresponding change to DT to be effective.
See "ARM: dts: armada-38x: fix NETA lockup when repeatedly switching
speeds".

Fixes: 14dc100b4411 ("phy: armada38x: add common phy support")
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/E1jxtRj-0003Tz-CG@rmk-PC.armlinux.org.uk
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Russell King and committed by
Vinod Koul
1dea06cd 6c89533d

+38 -7
+38 -7
drivers/phy/marvell/phy-armada38x-comphy.c
··· 41 41 42 42 struct a38x_comphy { 43 43 void __iomem *base; 44 + void __iomem *conf; 44 45 struct device *dev; 45 46 struct a38x_comphy_lane lane[MAX_A38X_COMPHY]; 46 47 }; ··· 54 53 { 0, 3, 0 }, 55 54 { 0, 0, 3 }, 56 55 }; 56 + 57 + static void a38x_set_conf(struct a38x_comphy_lane *lane, bool enable) 58 + { 59 + struct a38x_comphy *priv = lane->priv; 60 + u32 conf; 61 + 62 + if (priv->conf) { 63 + conf = readl_relaxed(priv->conf); 64 + if (enable) 65 + conf |= BIT(lane->port); 66 + else 67 + conf &= ~BIT(lane->port); 68 + writel(conf, priv->conf); 69 + } 70 + } 57 71 58 72 static void a38x_comphy_set_reg(struct a38x_comphy_lane *lane, 59 73 unsigned int offset, u32 mask, u32 value) ··· 113 97 { 114 98 struct a38x_comphy_lane *lane = phy_get_drvdata(phy); 115 99 unsigned int gen; 100 + int ret; 116 101 117 102 if (mode != PHY_MODE_ETHERNET) 118 103 return -EINVAL; ··· 132 115 return -EINVAL; 133 116 } 134 117 118 + a38x_set_conf(lane, false); 119 + 135 120 a38x_comphy_set_speed(lane, gen, gen); 136 121 137 - return a38x_comphy_poll(lane, COMPHY_STAT1, 138 - COMPHY_STAT1_PLL_RDY_TX | 139 - COMPHY_STAT1_PLL_RDY_RX, 140 - COMPHY_STAT1_PLL_RDY_TX | 141 - COMPHY_STAT1_PLL_RDY_RX); 122 + ret = a38x_comphy_poll(lane, COMPHY_STAT1, 123 + COMPHY_STAT1_PLL_RDY_TX | 124 + COMPHY_STAT1_PLL_RDY_RX, 125 + COMPHY_STAT1_PLL_RDY_TX | 126 + COMPHY_STAT1_PLL_RDY_RX); 127 + 128 + if (ret == 0) 129 + a38x_set_conf(lane, true); 130 + 131 + return ret; 142 132 } 143 133 144 134 static const struct phy_ops a38x_comphy_ops = { ··· 198 174 if (!priv) 199 175 return -ENOMEM; 200 176 201 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 202 - base = devm_ioremap_resource(&pdev->dev, res); 177 + base = devm_platform_ioremap_resource(pdev, 0); 203 178 if (IS_ERR(base)) 204 179 return PTR_ERR(base); 205 180 206 181 priv->dev = &pdev->dev; 207 182 priv->base = base; 183 + 184 + /* Optional */ 185 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "conf"); 186 + if (res) { 187 + priv->conf = devm_ioremap_resource(&pdev->dev, res); 188 + if (IS_ERR(priv->conf)) 189 + return PTR_ERR(priv->conf); 190 + } 208 191 209 192 for_each_available_child_of_node(pdev->dev.of_node, child) { 210 193 struct phy *phy;