net: ethernet: fsl: don't en/disable refclk on open/close
PATCH 1/1 net: ethernet: fsl: don't en/disable refclk on open/close
From: Richard Leitner <[email protected]>
From: Richard Leitner <[email protected]>
Some PHYs (for example the LAN8710) doesn't allow turning the ethernet ref clocks off and on again without reset (according to their datasheet). Exactly this behaviour was introduced for power saving reasons by commit e8fcfcd5684a ("net: fec: optimize the clock management to save...") Therefore remove those en/disables of the refclk during probe, open and close of the fec.
Generally speaking is this issue only be relevant if the ref clk for the PHY is generated by the SoC. In our specific case (PCB) this problem does occur at about every 10th to 50th POR of an LAN8710 connected to an i.MX6 SoC. The typical symptom of this problem is a "swinging" ethernet link. Similar issues were experienced by users of the NXP forum:
https://community.nxp.com/thread/389902 https://community.nxp.com/message/309354
With this patch applied the issue didn't occur for at least a few thousand PORs of our board.
--- drivers/net/ethernet/freescale/fec_main.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +0 -7
@@ -2844,9 +2844,6 @@ fec_enet_open(struct net_device *ndev)return ret;pinctrl_pm_select_default_state (&fep->pdev->dev); - ret =fec_enet_clk_enable (ndev, true); -if (ret) - goto clk_enable;/* I should reset the ring buffers here, but I don't yet know * a simple way to do that.
@@ -2879,8 +2876,6 @@ fec_enet_open(struct net_device *ndev) err_enet_mii_probe:fec_enet_free_buffers (ndev); err_enet_alloc: -fec_enet_clk_enable (ndev, false); -clk_enable:pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);pinctrl_pm_select_sleep_state (&fep->pdev->dev);
@@ -2907,7 +2902,6 @@ fec_enet_close(struct net_device *ndev)fec_enet_update_ethtool_stats (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&fep->pdev->dev);pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);
@@ -3495,7 +3489,6 @@ fec_probe(struct platform_device *pdev)/* Carrier starts down, phylib will bring it up */ netif_carrier_off (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&pdev->dev); ret =register_netdev (ndev);
Signature · 1 line
2.11.0
Quoted 8 lines · Richard Leitner
From: Richard Leitner <[email protected]>
From: Richard Leitner <[email protected]>
Some PHYs (for example the LAN8710) doesn't allow turning the ethernet ref clocks off and on again without reset (according to their datasheet). Exactly this behaviour was introduced for power saving reasons by commit
e8fcfcd5684a("net: fec: optimize the clock management to save...")
Please don't truncate the commit subject, put it in full length.
Quoted 8 lines
Therefore remove those en/disables of the refclk during probe, open and close of the fec.
Generally speaking is this issue only be relevant if the ref clk for the PHY is generated by the SoC. In our specific case (PCB) this problem does occur at about every 10th to 50th POR of an LAN8710 connected to an i.MX6 SoC. The typical symptom of this problem is a "swinging" ethernet link. Similar issues were experienced by users of the NXP forum:
Quoted 4 lines
https://community.nxp.com/thread/389902 https://community.nxp.com/message/309354With this patch applied the issue didn't occur for at least a few thousand PORs of our board.
FWIW, this is a common problem on most Ethernet systems attached to a PHY because of the clock dependencies between the MAC and PHY, in either direction really. We recently stumbled across a similar problem on the MAC side (using bcmgenet) where after shutting down the PHY in ndo_stop() we would not get enough clock cycles for the MAC to cleanly shutdown and upon subsequent ndo_open() we could get the MAC in an invalid state.
Quoted 2 lines
Fixes e8fcfcd5684a ("net: fec: optimize the clock management to sa...")
Likewise here, not truncation of the commit subject necessary.
Quoted 1 line
netdev patches are handled directly by David Miller, see netdev-FAQ for details.
Quoted 45 lines
Signed-off-by Richard Leitner <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 7 ------- 1 file changed, 7 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-7@@ -2844,9 +2844,6 @@ fec_enet_open(struct net_device *ndev)return ret;pinctrl_pm_select_default_state (&fep->pdev->dev); - ret =fec_enet_clk_enable (ndev, true); -if (ret) - goto clk_enable;/* I should reset the ring buffers here, but I don't yet know * a simple way to do that. @@ -2879,8 +2876,6 @@ fec_enet_open(struct net_device *ndev) err_enet_mii_probe:fec_enet_free_buffers (ndev); err_enet_alloc: -fec_enet_clk_enable (ndev, false); -clk_enable:pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);pinctrl_pm_select_sleep_state (&fep->pdev->dev);@@ -2907,7 +2902,6 @@ fec_enet_close(struct net_device *ndev)fec_enet_update_ethtool_stats (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&fep->pdev->dev);pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);@@ -3495,7 +3489,6 @@ fec_probe(struct platform_device *pdev)/* Carrier starts down, phylib will bring it up */ netif_carrier_off (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&pdev->dev); ret =register_netdev (ndev);
Signature · 1 line
Florian
Quoted 4 lines · Florian Fainelli
Quoted 2 lines · Richard Leitner
From: Richard Leitner <[email protected]>
Quoted 8 lines
Quoted 6 lines
From: Richard Leitner <[email protected]>
Some PHYs (for example the LAN8710) doesn't allow turning the ethernet ref clocks off and on again without reset (according to their datasheet). Exactly this behaviour was introduced for power saving reasons by commit
e8fcfcd5684a("net: fec: optimize the clock management to save...")Please don't truncate the commit subject, put it in full length.
Ok. So I can then ignore the checkpatch.pl error complaining about too long lines?
Quoted 14 lines
Quoted 9 lines
Therefore remove those en/disables of the refclk during probe, open and close of the fec.
Generally speaking is this issue only be relevant if the ref clk for the PHY is generated by the SoC. In our specific case (PCB) this problem does occur at about every 10th to 50th POR of an LAN8710 connected to an i.MX6 SoC. The typical symptom of this problem is a "swinging" ethernet link. Similar issues were experienced by users of the NXP forum:
Quoted 4 lines
https://community.nxp.com/thread/389902 https://community.nxp.com/message/309354With this patch applied the issue didn't occur for at least a few thousand PORs of our board.
Quoted 7 lines
FWIW, this is a common problem on most Ethernet systems attached to a PHY because of the clock dependencies between the MAC and PHY, in either direction really. We recently stumbled across a similar problem on the MAC side (using bcmgenet) where after shutting down the PHY in
ndo_stop()we would not get enough clock cycles for the MAC to cleanly shutdown and upon subsequentndo_open()we could get the MAC in an invalid state.
Hmm... So I'm not the only one struggling with this... Was there already discussion/ideas on how to solve this issue once and for all across the kernel?
Andrew Lunn suggested to make the PHY driver a clock driver and let it export the refclk... But IMHO that "feels" a bit strange. Due to the fact in our case the clock is generated by the SoC and the PHY is an external chip which only consumes it.
But back to this patch: Is it OK the way it fixes the issue?
Quoted 10 lines
Quoted 3 lines
Fixes e8fcfcd5684a ("net: fec: optimize the clock management to sa...")Likewise here, not truncation of the commit subject necessary.
Quoted 1 line
netdev patches are handled directly by David Miller, see netdev-FAQ for details.
Ok. So I shouldn't post them to [email protected] at all?
Quoted 47 lines
Quoted 46 lines
Signed-off-by Richard Leitner <[email protected]>--- drivers/net/ethernet/freescale/fec_main.c | 7 ------- 1 file changed, 7 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-7@@ -2844,9 +2844,6 @@ fec_enet_open(struct net_device *ndev)return ret;pinctrl_pm_select_default_state (&fep->pdev->dev); - ret =fec_enet_clk_enable (ndev, true); -if (ret) - goto clk_enable;/* I should reset the ring buffers here, but I don't yet know * a simple way to do that. @@ -2879,8 +2876,6 @@ fec_enet_open(struct net_device *ndev) err_enet_mii_probe:fec_enet_free_buffers (ndev); err_enet_alloc: -fec_enet_clk_enable (ndev, false); -clk_enable:pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);pinctrl_pm_select_sleep_state (&fep->pdev->dev);@@ -2907,7 +2902,6 @@ fec_enet_close(struct net_device *ndev)fec_enet_update_ethtool_stats (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&fep->pdev->dev);pm_runtime_mark_last_busy (&fep->pdev->dev);pm_runtime_put_autosuspend (&fep->pdev->dev);@@ -3495,7 +3489,6 @@ fec_probe(struct platform_device *pdev)/* Carrier starts down, phylib will bring it up */ netif_carrier_off (ndev); -fec_enet_clk_enable (ndev, false);pinctrl_pm_select_sleep_state (&pdev->dev); ret =register_netdev (ndev);
Quoted 15 lines · Richard Leitner
Quoted 13 lines · Florian Fainelli
Quoted 10 lines · Richard Leitner
From: Richard Leitner <[email protected]>
From: Richard Leitner <[email protected]>
Some PHYs (for example the LAN8710) doesn't allow turning the ethernet ref clocks off and on again without reset (according to their datasheet).
Exactly this behaviour was introduced for power saving reasons by commite8fcfcd5684a("net: fec: optimize the clock management to save...")
Quoted 4 lines
Quoted 1 line
Please don't truncate the commit subject, put it in full length.
Ok. So I can then ignore the checkpatch.pl error complaining about too long lines?
Yes absolutely it's just a tool, not the absolute reference.
Quoted 23 lines
Quoted 15 lines
Quoted 5 lines
Therefore remove those en/disables of the refclk during probe, open and close of the fec.
Quoted 9 lines
Generally speaking is this issue only be relevant if the ref clk for the PHY is generated by the SoC. In our specific case (PCB) this problem does occur at about every 10th to 50th POR of an LAN8710 connected to an i.MX6 SoC. The typical symptom of this problem is a "swinging" ethernet link. Similar issues were experienced by users of the NXP forum:
https://community.nxp.com/thread/389902
https://community.nxp.com/message/309354
With this patch applied the issue didn't occur for at least a few thousand PORs of our board.Quoted 7 lines
FWIW, this is a common problem on most Ethernet systems attached to a PHY because of the clock dependencies between the MAC and PHY, in either direction really. We recently stumbled across a similar problem on the MAC side (using bcmgenet) where after shutting down the PHY in
ndo_stop()we would not get enough clock cycles for the MAC to cleanly shutdown and upon subsequentndo_open()we could get the MAC in an invalid state.
Quoted 3 lines
Hmm... So I'm not the only one struggling with this... Was there already discussion/ideas on how to solve this issue once and for all across the kernel?
Not really, there is not unfortunately a one size fits all solution.
Quoted 5 lines
Andrew Lunn suggested to make the PHY driver a clock driver and let it export the refclk... But IMHO that "feels" a bit strange. Due to the fact in our case the clock is generated by the SoC and the PHY is an external chip which only consumes it.
It depends which *MII mode you use. Unless you are using reverse MII, the PHY supplies the RX clock and the MAC supplies the RX clock, so solving this for all modes becomes quite tricky. Andrew's suggestion makes sense, but considering that the MAC and PHY need to be connected to each other, it may be tricky to request the PHY's clock before you actually attached to the PHY...
Quoted 2 lines
But back to this patch: Is it OK the way it fixes the issue?
Fugang and Andrew probably know this hardware a lot better, I would have to look at the code path a bit more to understand if an alternative solution is possible. It sounds like your patch could create a power consumption regression, so maybe add a check for the PHY ID that is problematic by doing something like:
if (priv->phydev->drv && priv->phydev->drv->phy_id == XXXX_XXXX) where XXXX_XXXX is the LAN870 PHY ID (obtained from MII register 2 & 3).
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes e8fcfcd5684a ("net: fec: optimize the clock management to sa...")
Quoted 8 lines
Quoted 6 lines
Likewise here, not truncation of the commit subject necessary.
Quoted 1 line
netdev patches are handled directly by David Miller, see netdev-FAQ for details.
Ok. So I shouldn't post them to [email protected] at all?
Nope.
Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Signed-off-by Richard Leitner <[email protected]>---
drivers/net/ethernet/freescale/fec_main.c| 7 -------1 file changed, 7 deletions(-)drivers/net/ethernet/freescale/fec_main.c +0
-3@@ -2844,9 +2844,6 @@ fec_enet_open(struct net_device *ndev) return ret; pinctrl_pm_select_default_state(&fep->pdev->dev); - ret = fec_enet_clk_enable(ndev, true); - if (ret) - goto clk_enable; /* I should reset the ring buffers here, but I don't yet know* a simple way to do that. @@ -2879,8 +2876,6 @@ fec_enet_open(struct net_device *ndev)
err_enet_mii_probe:
fec_enet_free_buffers(ndev);err_enet_alloc:
-fec_enet_clk_enable(ndev, false); -clk_enable:
pm_runtime_mark_last_busy(&fep->pdev->dev);pm_runtime_put_autosuspend(&fep->pdev->dev);pinctrl_pm_select_sleep_state(&fep->pdev->dev);drivers/net/ethernet/freescale/fec_main.c +0
-1@@ -2907,7 +2902,6 @@ fec_enet_close(struct net_device *ndev) fec_enet_update_ethtool_stats(ndev); - fec_enet_clk_enable(ndev, false); pinctrl_pm_select_sleep_state(&fep->pdev->dev); pm_runtime_mark_last_busy(&fep->pdev->dev); pm_runtime_put_autosuspend(&fep->pdev->dev);@@ -3495,7 +3489,6 @@ fec_probe(struct platform_device *pdev) /* Carrier starts down, phylib will bring it up */ netif_carrier_off(ndev); - fec_enet_clk_enable(ndev, false); pinctrl_pm_select_sleep_state(&pdev->dev); ret = register_netdev(ndev);
Signature · 1 line
Florian
Quoted 2 lines · Richard Leitner
Quoted 2 lines · Florian Fainelli
Quoted 1 line · Richard Leitner
...
Quoted 14 lines
Quoted 4 lines
Andrew Lunn suggested to make the PHY driver a clock driver and let it export the refclk... But IMHO that "feels" a bit strange. Due to the fact in our case the clock is generated by the SoC and the PHY is an external chip which only consumes it.
It depends which *MII mode you use. Unless you are using reverse MII, the PHY supplies the RX clock and the MAC supplies the RX clock, so solving this for all modes becomes quite tricky. Andrew's suggestion makes sense, but considering that the MAC and PHY need to be connected to each other, it may be tricky to request the PHY's clock before you actually attached to the PHY...
Quoted 2 lines
But back to this patch: Is it OK the way it fixes the issue?
Quoted 8 lines
Fugang and Andrew probably know this hardware a lot better, I would have to look at the code path a bit more to understand if an alternative solution is possible. It sounds like your patch could create a power consumption regression, so maybe add a check for the PHY ID that is problematic by doing something like:
if (
priv->phydev->drv&&priv->phydev->drv->phy_id==XXXX_XXXX) whereXXXX_XXXXis the LAN870 PHY ID (obtained from MII register 2 & 3).
I already had a patch which does this check and triggers a reset of the PHY after the refclk was enabled (in fec_enet_clk_enable) in case the phy_id matches. This would IMHO avoid all power consumption regressions... It was something like:
switch (priv->phydev->drv->phy_id) {
case XXXX:
case XXXX:
ret = fec_reset_phy(ndev);
if (ret)
goto failed_reset;
if (ndev->phydev) {
ret = phy_init_hw(ndev->phydev);
if (ret)
goto failed_reset;
}
}Would that be better?
Basically I'm fine with any kind of solution... It's up to you guys... You're the experts ;-)
Quoted 4 lines · Richard Leitner
On 10/23/2017 12:48 AM, Florian Fainelli wrote
Quoted 3 lines · Richard Leitner
Quoted 2 lines · Florian Fainelli
Quoted 1 line · Richard Leitner
...
Quoted 13 lines
Quoted 10 lines
Quoted 1 line
But back to this patch: Is it OK the way it fixes the issue?
Fugang and Andrew probably know this hardware a lot better, I would have to look at the code path a bit more to understand if an alternative solution is possible. It sounds like your patch could create a power consumption regression, so maybe add a check for the PHY ID that is problematic by doing something like:
if (
priv->phydev->drv&&priv->phydev->drv->phy_id==XXXX_XXXX) whereXXXX_XXXXis the LAN870 PHY ID (obtained from MII register 2 & 3).I already had a patch which does this check and triggers a reset of the PHY after the refclk was enabled (in
fec_enet_clk_enable) in case thephy_idmatches. This would IMHO avoid all power consumption regressions... It was something like:
Quoted 12 lines
switch (
priv->phydev->drv->phy_id) {
case XXXX:
case XXXX:
ret =fec_reset_phy(ndev);
if (ret)
gotofailed_reset;
if (ndev->phydev) {
ret =phy_init_hw(ndev->phydev);
if (ret)
gotofailed_reset;
}
}
Another possible solution that came to my mind is to add a flag called something like "PHY_RST_AFTER_CLK_EN" to the flags variable in struct phy_driver. This flag could then be set in the smsc PHY driver for affected PHYs.
Then instead of comparing the phy_id in the MAC driver this flag could be checked:
if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) {
ret = fec_reset_phy(ndev);
if (ret)
goto failed_reset;
if (ndev->phydev) {
ret = phy_init_hw(ndev->phydev);
if (ret)
goto failed_reset;
}
}This approach would IMHO also be easier and less prune to erros for porting to other MAC drivers (if needed).
So what would be the better approach in your opinion and how should I procede here?
kind regards,
Richard.L