From: Joakim Zhang <qiangqing.zhang@nxp.com> To: peppe.cavallaro@st.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org Cc: mcoquelin.stm32@gmail.com, linux@armlinux.org.uk, netdev@vger.kernel.org, andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com, linux-imx@nxp.com Subject: [PATCH] net: stmmac: fix MAC not working when system resume back with WoL enabled Date: Wed, 1 Sep 2021 17:02:28 +0800 [thread overview] Message-ID: <20210901090228.11308-1-qiangqing.zhang@nxp.com> (raw) We can reproduce this issue with below steps: 1) enable WoL on the host 2) host system suspended 3) remote client send out wakeup packets We can see that host system resume back, but can't work, such as ping failed. After a bit digging, this issue is introduced by the commit 46f69ded988d ("net: stmmac: Use resolved link config in mac_link_up()"), which use the finalised link parameters in mac_link_up() rather than the parameters in mac_config(). There are two scenarios for MAC suspend/resume: 1) MAC suspend with WoL disabled, stmmac_suspend() call phylink_mac_change() to notify phylink machine that a change in MAC state, then .mac_link_down callback would be invoked. Further, it will call phylink_stop() to stop the phylink instance. When MAC resume back, firstly phylink_start() is called to start the phylink instance, then call phylink_mac_change() which will finally trigger phylink machine to invoke .mac_config and .mac_link_up callback. All is fine since configuration in these two callbacks will be initialized. 2) MAC suspend with WoL enabled, phylink_mac_change() will put link down, but there is no phylink_stop() to stop the phylink instance, so it will link up again, that means .mac_config and .mac_link_up would be invoked before system suspended. After system resume back, it will do DMA initialization and SW reset which let MAC lost the hardware setting (i.e MAC_Configuration register(offset 0x0) is reset). Since link is up before system suspended, so .mac_link_up would not be invoked after system resume back, lead to there is no chance to initialize the configuration in .mac_link_up callback, as a result, MAC can't work any longer. Above description is what I found when debug this issue, this patch is just revert broken patch to workaround it, at least make MAC work when system resume back with WoL enabled. Said this is a workaround, since it has not resolve the issue completely. I just move the speed/duplex/pause etc into .mac_config callback, there are other configurations in .mac_link_up callback which also need to be initialized to work for specific functions. Fixes: 46f69ded988d ("net: stmmac: Use resolved link config in mac_link_up()") Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com> --- Broken patch cannot be reverted directly, so manually modified it. I also tried to fix in other ways, but failed to find a better solution, any suggestions would be appreciated. Thanks. Joakim --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index ed0cd3920171..c0ed4b07d24a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1007,45 +1007,6 @@ static void stmmac_validate(struct phylink_config *config, static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) -{ - /* Nothing to do, xpcs_config() handles everything */ -} - -static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up) -{ - struct stmmac_fpe_cfg *fpe_cfg = priv->plat->fpe_cfg; - enum stmmac_fpe_state *lo_state = &fpe_cfg->lo_fpe_state; - enum stmmac_fpe_state *lp_state = &fpe_cfg->lp_fpe_state; - bool *hs_enable = &fpe_cfg->hs_enable; - - if (is_up && *hs_enable) { - stmmac_fpe_send_mpacket(priv, priv->ioaddr, MPACKET_VERIFY); - } else { - *lo_state = FPE_STATE_OFF; - *lp_state = FPE_STATE_OFF; - } -} - -static void stmmac_mac_link_down(struct phylink_config *config, - unsigned int mode, phy_interface_t interface) -{ - struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); - - stmmac_mac_set(priv, priv->ioaddr, false); - priv->eee_active = false; - priv->tx_lpi_enabled = false; - stmmac_eee_init(priv); - stmmac_set_eee_pls(priv, priv->hw, false); - - if (priv->dma_cap.fpesel) - stmmac_fpe_link_state_handle(priv, false); -} - -static void stmmac_mac_link_up(struct phylink_config *config, - struct phy_device *phy, - unsigned int mode, phy_interface_t interface, - int speed, int duplex, - bool tx_pause, bool rx_pause) { struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); u32 ctrl; @@ -1053,8 +1014,8 @@ static void stmmac_mac_link_up(struct phylink_config *config, ctrl = readl(priv->ioaddr + MAC_CTRL_REG); ctrl &= ~priv->hw->link.speed_mask; - if (interface == PHY_INTERFACE_MODE_USXGMII) { - switch (speed) { + if (state->interface == PHY_INTERFACE_MODE_USXGMII) { + switch (state->speed) { case SPEED_10000: ctrl |= priv->hw->link.xgmii.speed10000; break; @@ -1067,8 +1028,8 @@ static void stmmac_mac_link_up(struct phylink_config *config, default: return; } - } else if (interface == PHY_INTERFACE_MODE_XLGMII) { - switch (speed) { + } else if (state->interface == PHY_INTERFACE_MODE_XLGMII) { + switch (state->speed) { case SPEED_100000: ctrl |= priv->hw->link.xlgmii.speed100000; break; @@ -1094,7 +1055,7 @@ static void stmmac_mac_link_up(struct phylink_config *config, return; } } else { - switch (speed) { + switch (state->speed) { case SPEED_2500: ctrl |= priv->hw->link.speed2500; break; @@ -1112,21 +1073,60 @@ static void stmmac_mac_link_up(struct phylink_config *config, } } - priv->speed = speed; + priv->speed = state->speed; if (priv->plat->fix_mac_speed) - priv->plat->fix_mac_speed(priv->plat->bsp_priv, speed); + priv->plat->fix_mac_speed(priv->plat->bsp_priv, state->speed); - if (!duplex) + if (!state->duplex) ctrl &= ~priv->hw->link.duplex; else ctrl |= priv->hw->link.duplex; /* Flow Control operation */ - if (tx_pause && rx_pause) - stmmac_mac_flow_ctrl(priv, duplex); + if (state->pause) + stmmac_mac_flow_ctrl(priv, state->duplex); writel(ctrl, priv->ioaddr + MAC_CTRL_REG); +} + +static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up) +{ + struct stmmac_fpe_cfg *fpe_cfg = priv->plat->fpe_cfg; + enum stmmac_fpe_state *lo_state = &fpe_cfg->lo_fpe_state; + enum stmmac_fpe_state *lp_state = &fpe_cfg->lp_fpe_state; + bool *hs_enable = &fpe_cfg->hs_enable; + + if (is_up && *hs_enable) { + stmmac_fpe_send_mpacket(priv, priv->ioaddr, MPACKET_VERIFY); + } else { + *lo_state = FPE_STATE_OFF; + *lp_state = FPE_STATE_OFF; + } +} + +static void stmmac_mac_link_down(struct phylink_config *config, + unsigned int mode, phy_interface_t interface) +{ + struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); + + stmmac_mac_set(priv, priv->ioaddr, false); + priv->eee_active = false; + priv->tx_lpi_enabled = false; + stmmac_eee_init(priv); + stmmac_set_eee_pls(priv, priv->hw, false); + + if (priv->dma_cap.fpesel) + stmmac_fpe_link_state_handle(priv, false); +} + +static void stmmac_mac_link_up(struct phylink_config *config, + struct phy_device *phy, + unsigned int mode, phy_interface_t interface, + int speed, int duplex, + bool tx_pause, bool rx_pause) +{ + struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); stmmac_mac_set(priv, priv->ioaddr, true); if (phy && priv->dma_cap.eee) { -- 2.17.1
next reply other threads:[~2021-09-01 9:02 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-01 9:02 Joakim Zhang [this message] 2021-09-01 9:13 ` Russell King (Oracle) 2021-09-01 10:21 ` Joakim Zhang 2021-09-01 12:56 ` Russell King (Oracle) 2021-09-02 7:01 ` Joakim Zhang 2021-09-01 15:40 ` Heiner Kallweit 2021-09-02 7:35 ` Joakim Zhang 2021-09-01 9:21 ` Vladimir Oltean 2021-09-01 10:25 ` Joakim Zhang 2021-09-01 10:56 ` Vladimir Oltean 2021-09-01 11:42 ` Joakim Zhang 2021-09-01 13:25 ` Russell King (Oracle) 2021-09-02 7:28 ` Joakim Zhang 2021-09-02 8:32 ` Russell King (Oracle) 2021-09-02 10:26 ` Joakim Zhang 2021-09-02 10:49 ` Russell King (Oracle) 2021-09-02 11:15 ` Joakim Zhang 2021-09-02 12:24 ` Andrew Lunn 2021-09-03 6:51 ` Joakim Zhang 2021-09-03 8:01 ` Russell King (Oracle) 2021-09-03 8:39 ` Joakim Zhang 2021-09-03 9:32 ` Russell King (Oracle) 2021-09-03 11:04 ` Joakim Zhang 2021-09-03 12:01 ` Russell King (Oracle) 2021-09-03 20:12 ` Russell King - ARM Linux admin 2021-09-06 2:29 ` Joakim Zhang 2021-09-06 9:34 ` Russell King (Oracle) 2021-09-06 10:41 ` Joakim Zhang 2021-09-06 11:21 ` Russell King (Oracle) 2021-09-06 13:23 ` Andrew Lunn 2021-09-07 8:52 ` Russell King (Oracle) 2021-09-06 2:21 ` Joakim Zhang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210901090228.11308-1-qiangqing.zhang@nxp.com \ --to=qiangqing.zhang@nxp.com \ --cc=alexandre.torgue@foss.st.com \ --cc=andrew@lunn.ch \ --cc=davem@davemloft.net \ --cc=f.fainelli@gmail.com \ --cc=hkallweit1@gmail.com \ --cc=joabreu@synopsys.com \ --cc=kuba@kernel.org \ --cc=linux-imx@nxp.com \ --cc=linux@armlinux.org.uk \ --cc=mcoquelin.stm32@gmail.com \ --cc=netdev@vger.kernel.org \ --cc=peppe.cavallaro@st.com \ --subject='Re: [PATCH] net: stmmac: fix MAC not working when system resume back with WoL enabled' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.