History

net: stmmac: resume PHY before hardware setup when opening the interface

Since the referenced commit, changing the MTU on a running interface no longer disconnects and reconnects the PHY; __stmmac_release() merely stops phylink, which also suspends the PHY (BMCR power-down) when WoL is not enabled. __stmmac_open() then performs the DMA software reset in stmmac_hw_setup() before phylink_start() resumes the PHY again. IEEE 802.3 22.2.4.1.5 allows a PHY to stop its receive clock while powered down, and stmmac requires a running receive clock for the DMA software reset to complete (the phylink config sets mac_requires_rxc). On such setups, e.g. the RK3566-based Home Assistant Green with an RTL8211F-VD PHY in RGMII mode, any runtime MTU change now times out and leaves the interface dead: rk_gmac-dwmac fe010000.ethernet end0: Failed to reset the dma rk_gmac-dwmac fe010000.ethernet end0: stmmac_hw_setup: DMA engine initialization failed rk_gmac-dwmac fe010000.ethernet end0: __stmmac_open: Hw setup failed rk_gmac-dwmac fe010000.ethernet end0: failed reopening the interface after MTU change In the field this is triggered by NetworkManager applying an MTU while activating the connection, breaking networking entirely. The same regression has also been reported on i.MX8MP and reproduced on SoCFPGA based systems. Resume the PHY in __stmmac_open() before the hardware setup, making it the counterpart of the phylink_stop() in __stmmac_release(), like stmmac_resume() already does for the same reason. phylink_start() also resumes the PHY, but only after stmmac_hw_setup(), and it cannot be moved before the hardware setup since it may bring the link up immediately from a workqueue, racing with the initialization (see the comment in stmmac_resume()). For the regular ndo_open path the PHY has just been attached and is not suspended, in which case phylink_prepare_resume() does nothing.

Stefan Agner committed 3 months ago

Commit 06232cb1 parent e3142061 file · +9 −0Browse files

Unified · Split

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c+9−0
@@ -4134,6 +4134,15 @@ static int __stmmac_open(struct net_device *dev, · 4133 unmodified lines
4134 dma_conf->tx_queue[i].tbs = priv->dma_conf.tx_queue[i].tbs;4134 dma_conf->tx_queue[i].tbs = priv->dma_conf.tx_queue[i].tbs;
4135 memcpy(&priv->dma_conf, dma_conf, sizeof(*dma_conf));4135 memcpy(&priv->dma_conf, dma_conf, sizeof(*dma_conf));
4136 4136
4137 /* The PHY is suspended when the interface is reopened without
4138 * disconnecting the PHY, e.g. on MTU change. IEEE 802.3 allows PHYs
4139 * to stop their receive clock while powered down, but the DMA
4140 * software reset in stmmac_hw_setup() requires a running receive
4141 * clock, and phylink_start() below resumes the PHY only after the
4142 * hardware setup. Resume a suspended PHY here first.
4143 */
4144 phylink_prepare_resume(priv->phylink);
4145
4137 stmmac_reset_queues_param(priv);4146 stmmac_reset_queues_param(priv);
4138 4147
4139 ret = stmmac_hw_setup(dev);4148 ret = stmmac_hw_setup(dev);