From: Richard Leitner <hidden> Date: 2017-12-05 13:27:44
From: Richard Leitner <richard.leitner@skidata.com>
This patch series fixes the use of the SMSC LAN8710/20 with a Freescale ETH
when the refclk is generated by the FSL.
This patch depends on the "phylib: Add device reset GPIO support" patch
submitted by Geert Uytterhoeven/Sergei Shtylyov, see:
https://patchwork.kernel.org/patch/10090149/
Changes v3:
- use phylib to hard-reset the PHY
- implement reset delays in phylib
- add new phylib API & flag (PHY_RST_AFTER_CLK_EN) to determine if a PHY
is affected
Changes v2:
- simplify and fix fec_reset_phy function to support multiple calls
- include: linux: phy: harmonize phy_id{,_mask} type
- reset the phy instead of not turning the clock on and off
(which would have caused a power consumption regression)
Richard Leitner (4):
phylib: Add device reset delay support
phylib: add reset after clk enable support
net: phy: smsc: LAN8710/20: add PHY_RST_AFTER_CLK_EN flag
net: fec: add phy_reset_after_clk_enable() support
Documentation/devicetree/bindings/net/phy.txt | 10 ++++++++++
drivers/net/ethernet/freescale/fec_main.c | 7 +++++++
drivers/net/phy/mdio_device.c | 13 +++++++++++--
drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++
drivers/net/phy/smsc.c | 2 +-
drivers/of/of_mdio.c | 8 ++++++++
include/linux/mdio.h | 2 ++
include/linux/phy.h | 2 ++
8 files changed, 65 insertions(+), 3 deletions(-)
--
2.11.0
From: Richard Leitner <hidden> Date: 2017-12-05 13:26:41
From: Richard Leitner <richard.leitner@skidata.com>
Some PHYs need a minimum time after the reset gpio was asserted and/or
deasserted. To ensure we meet these timing requirements add two new
optional devicetree parameters for the phy: reset-delay-us and
reset-post-delay-us.
This patch depends on the "phylib: Add device reset GPIO support" patch
submitted by Geert Uytterhoeven/Sergei Shtylyov, see:
https://patchwork.kernel.org/patch/10090149/
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
---
Documentation/devicetree/bindings/net/phy.txt | 10 ++++++++++
drivers/net/phy/mdio_device.c | 13 +++++++++++--
drivers/of/of_mdio.c | 8 ++++++++
include/linux/mdio.h | 2 ++
4 files changed, 31 insertions(+), 2 deletions(-)
@@ -55,6 +55,12 @@ Optional Properties: - reset-gpios: The GPIO phandle and specifier for the PHY reset signal.+- reset-delay-us: Delay after the reset was asserted in microseconds.+ If this property is missing the delay will be skipped.++- reset-post-delay-us: Delay after the reset was deasserted in microseconds.+ If this property is missing the delay will be skipped.+ Example: ethernet-phy@0 {
@@ -77,6 +77,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,if(of_property_read_bool(child,"broken-turn-around"))mdio->phy_ignore_ta_mask|=1<<addr;+if(of_property_read_u32(child,"reset-delay-us",+&phy->mdio.reset_delay))+phy->mdio.reset_delay=0;++if(of_property_read_u32(child,"reset-post-delay-us",+&phy->mdio.reset_post_delay))+phy->mdio.reset_post_delay=0;+/* Associate the OF node with the device structure so it*canbelookeduplater*/of_node_get(child);
From: Richard Leitner <hidden> Date: 2017-12-05 13:26:43
From: Richard Leitner <richard.leitner@skidata.com>
Some PHYs need the refclk to be a continuous clock. Therefore they don't
allow turning it off and on again during operation. Nonetheless such a
clock switching is performed by some ETH drivers (namely FEC [1]) for
power saving reasons. An example for an affected PHY is the
SMSC/Microchip LAN8720 in "REF_CLK In Mode".
In order to provide a uniform method to overcome this problem this patch
adds a new phy_driver flag (PHY_RST_AFTER_CLK_EN) and corresponding
function phy_reset_after_clk_enable() to the phylib. These should be
used to trigger reset of the PHY after the refclk is switched on again.
This patch depends on the "phylib: Add device reset GPIO support" patch
submitted by Geert Uytterhoeven/Sergei Shtylyov [2].
[1] commit e8fcfcd5684a ("net: fec: optimize the clock management to save power")
[2] https://patchwork.kernel.org/patch/10090149/
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
---
drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++
include/linux/phy.h | 2 ++
2 files changed, 26 insertions(+)
From: Richard Leitner <hidden> Date: 2017-12-05 13:26:46
From: Richard Leitner <richard.leitner@skidata.com>
The Microchip/SMSC LAN8710/LAN8720 PHYs need (according to their
datasheet [1]) a continuous REF_CLK when configured to "REF_CLK In Mode".
Therefore set the PHY_RST_AFTER_CLK_EN flag for those PHYs to let the
ETH driver reset them after the REF_CLK is enabled.
[1] http://ww1.microchip.com/downloads/en/DeviceDoc/00002165B.pdf
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
---
drivers/net/phy/smsc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Richard Leitner <hidden> Date: 2017-12-05 13:27:18
From: Richard Leitner <richard.leitner@skidata.com>
Some PHYs (for example the SMSC LAN8710/LAN8720) doesn't allow turning
the refclk on and off again during operation (according to their
datasheet). Nonetheless exactly this behaviour was introduced for power
saving reasons by commit e8fcfcd5684a ("net: fec: optimize the clock management to save power").
Therefore add support for the phy_reset_after_clk_enable function from
phylib to mitigate this issue.
Generally speaking this issue is only relevant if the ref clk for the
PHY is generated by the SoC and therefore the PHY is configured to
"REF_CLK In Mode". In our specific case (PCB) this problem does occur at
about every 10th to 50th POR of an LAN8710 connected to an i.MX6SOLO
SoC. The typical symptom of this problem is a "swinging" ethernet link.
Similar issues were reported by users of the NXP forum:
https://community.nxp.com/thread/389902https://community.nxp.com/message/309354
With this patch applied the issue didn't occur for at least a few
hundret PORs of our board.
Fixes: e8fcfcd5684a ("net: fec: optimize the clock management to save power")
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
---
drivers/net/ethernet/freescale/fec_main.c | 7 +++++++
1 file changed, 7 insertions(+)
@@ -2860,6 +2862,11 @@ fec_enet_open(struct net_device *ndev)if(ret)gotoerr_enet_mii_probe;+/* reset phy if needed here, due to the fact this is the first time we+*havethenet_devicetophy_driverlink+*/+phy_reset_after_clk_enable(ndev->phydev);+if(fep->quirks&FEC_QUIRK_ERR006687)imx6q_cpuidle_fec_irqs_used();
Hi Richard,
On Tue, Dec 5, 2017 at 2:25 PM, Richard Leitner [off-list ref] wrote:
From: Richard Leitner <redacted>
Some PHYs need a minimum time after the reset gpio was asserted and/or
deasserted. To ensure we meet these timing requirements add two new
optional devicetree parameters for the phy: reset-delay-us and
reset-post-delay-us.
I think this can be written simpler using e.g.:
unsigned int delay;
...
delay = value ? mdiodev->reset_delay : mdiodev->reset_post_delay;
if (delay)
usleep_range(delay, delay + 100);
Perhaps the range extension should be relative, e.g.
"delay + min(delay / 10, 100)"?
@@ -77,6 +77,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,if(of_property_read_bool(child,"broken-turn-around"))mdio->phy_ignore_ta_mask|=1<<addr;+if(of_property_read_u32(child,"reset-delay-us",+&phy->mdio.reset_delay))+phy->mdio.reset_delay=0;++if(of_property_read_u32(child,"reset-post-delay-us",+&phy->mdio.reset_post_delay))+phy->mdio.reset_post_delay=0;
If of_property_read_u32() fails, it doesn't write to its output parameter.
As the structure should be zeroed during allocation, you can just write:
of_property_read_u32(child, "reset-delay-us", &phy->mdio.reset_delay);
of_property_read_u32(child, "reset-post-delay-us",
&phy->mdio.reset_post_delay);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Richard Leitner <richard.leitner@skidata.com> Date: 2017-12-05 15:07:12
Hi Geert,
On 12/05/2017 02:54 PM, Geert Uytterhoeven wrote:
Hi Richard,
On Tue, Dec 5, 2017 at 2:25 PM, Richard Leitner [off-list ref] wrote:
quoted
From: Richard Leitner <redacted>
Some PHYs need a minimum time after the reset gpio was asserted and/or
deasserted. To ensure we meet these timing requirements add two new
optional devicetree parameters for the phy: reset-delay-us and
reset-post-delay-us.
I think this can be written simpler using e.g.:
unsigned int delay;
...
delay = value ? mdiodev->reset_delay : mdiodev->reset_post_delay;
if (delay)
usleep_range(delay, delay + 100);
Perhaps the range extension should be relative, e.g.
"delay + min(delay / 10, 100)"?
@@ -77,6 +77,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,if(of_property_read_bool(child,"broken-turn-around"))mdio->phy_ignore_ta_mask|=1<<addr;+if(of_property_read_u32(child,"reset-delay-us",+&phy->mdio.reset_delay))+phy->mdio.reset_delay=0;++if(of_property_read_u32(child,"reset-post-delay-us",+&phy->mdio.reset_post_delay))+phy->mdio.reset_post_delay=0;
If of_property_read_u32() fails, it doesn't write to its output parameter.
As the structure should be zeroed during allocation, you can just write:
of_property_read_u32(child, "reset-delay-us", &phy->mdio.reset_delay);
of_property_read_u32(child, "reset-post-delay-us",
&phy->mdio.reset_post_delay);
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andrew Lunn <andrew@lunn.ch> Date: 2017-12-05 17:29:13
Hi Richard
quoted hunk
+++ b/drivers/of/of_mdio.c
@@ -77,6 +77,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,if(of_property_read_bool(child,"broken-turn-around"))mdio->phy_ignore_ta_mask|=1<<addr;+if(of_property_read_u32(child,"reset-delay-us",+&phy->mdio.reset_delay))+phy->mdio.reset_delay=0;++if(of_property_read_u32(child,"reset-post-delay-us",+&phy->mdio.reset_post_delay))+phy->mdio.reset_post_delay=0;
of_property_read_u32() should not change the variable you pass to it,
if it does not find the property. So you can change this to:
phy->mdio.reset_delay = 0;
phy->mdio.reset_post_delay = 0;
of_property_read_u32(child, "reset-delay-us",
&phy->mdio.reset_delay);
of_property_read_u32(child, "reset-post-delay-us",
&phy->mdio.reset_post_delay);
Andrew
From: Andrew Lunn <andrew@lunn.ch> Date: 2017-12-05 17:34:22
On Tue, Dec 05, 2017 at 02:25:58PM +0100, Richard Leitner wrote:
From: Richard Leitner <richard.leitner@skidata.com>
Some PHYs need the refclk to be a continuous clock. Therefore they don't
allow turning it off and on again during operation. Nonetheless such a
clock switching is performed by some ETH drivers (namely FEC [1]) for
power saving reasons. An example for an affected PHY is the
SMSC/Microchip LAN8720 in "REF_CLK In Mode".
In order to provide a uniform method to overcome this problem this patch
adds a new phy_driver flag (PHY_RST_AFTER_CLK_EN) and corresponding
function phy_reset_after_clk_enable() to the phylib. These should be
used to trigger reset of the PHY after the refclk is switched on again.
This patch depends on the "phylib: Add device reset GPIO support" patch
submitted by Geert Uytterhoeven/Sergei Shtylyov [2].
[1] commit e8fcfcd5684a ("net: fec: optimize the clock management to save power")
[2] https://patchwork.kernel.org/patch/10090149/
Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
Hi Richard
Same comment about moving text below the ---
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
From: Andrew Lunn <andrew@lunn.ch> Date: 2017-12-05 17:36:01
On Tue, Dec 05, 2017 at 02:25:59PM +0100, Richard Leitner wrote:
From: Richard Leitner <redacted>
The Microchip/SMSC LAN8710/LAN8720 PHYs need (according to their
datasheet [1]) a continuous REF_CLK when configured to "REF_CLK In Mode".
Therefore set the PHY_RST_AFTER_CLK_EN flag for those PHYs to let the
ETH driver reset them after the REF_CLK is enabled.
[1] http://ww1.microchip.com/downloads/en/DeviceDoc/00002165B.pdf
Signed-off-by: Richard Leitner <redacted>
Reviewed-by: Andrew Lunn <redacted>
Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Richard Leitner <richard.leitner@skidata.com> Date: 2017-12-05 18:06:44
Hi Andrew,
On 12/05/2017 06:28 PM, Andrew Lunn wrote:
Hi Richard
quoted
+++ b/drivers/of/of_mdio.c
@@ -77,6 +77,14 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,if(of_property_read_bool(child,"broken-turn-around"))mdio->phy_ignore_ta_mask|=1<<addr;+if(of_property_read_u32(child,"reset-delay-us",+&phy->mdio.reset_delay))+phy->mdio.reset_delay=0;++if(of_property_read_u32(child,"reset-post-delay-us",+&phy->mdio.reset_post_delay))+phy->mdio.reset_post_delay=0;
of_property_read_u32() should not change the variable you pass to it,
if it does not find the property. So you can change this to:
phy->mdio.reset_delay = 0;
phy->mdio.reset_post_delay = 0;
of_property_read_u32(child, "reset-delay-us",
&phy->mdio.reset_delay);
of_property_read_u32(child, "reset-post-delay-us",
&phy->mdio.reset_post_delay);
Geert already pointed this out, but he said it's possible to omit also the zeroing of the variables.
On 12/05/2017 02:54 PM, Geert Uytterhoeven wrote:
quoted
If of_property_read_u32() fails, it doesn't write to its output
parameter.
As the structure should be zeroed during allocation, you can just
write:
of_property_read_u32(child, "reset-delay-us",&phy->mdio.reset_delay);
of_property_read_u32(child, "reset-post-delay-us",
&phy->mdio.reset_post_delay);
If that's ok I'll take the shorter (Geerts) suggestion for v4.
Nonetheless thanks for your quick feedback!
regards;Richard.L
From: Richard Leitner <richard.leitner@skidata.com> Date: 2017-12-05 18:08:13
Hi Andrew,
On 12/05/2017 06:34 PM, Andrew Lunn wrote:
On Tue, Dec 05, 2017 at 02:25:58PM +0100, Richard Leitner wrote:
quoted
From: Richard Leitner <redacted>
Some PHYs need the refclk to be a continuous clock. Therefore they don't
allow turning it off and on again during operation. Nonetheless such a
clock switching is performed by some ETH drivers (namely FEC [1]) for
power saving reasons. An example for an affected PHY is the
SMSC/Microchip LAN8720 in "REF_CLK In Mode".
In order to provide a uniform method to overcome this problem this patch
adds a new phy_driver flag (PHY_RST_AFTER_CLK_EN) and corresponding
function phy_reset_after_clk_enable() to the phylib. These should be
used to trigger reset of the PHY after the refclk is switched on again.
This patch depends on the "phylib: Add device reset GPIO support" patch
submitted by Geert Uytterhoeven/Sergei Shtylyov [2].
[1] commit e8fcfcd5684a ("net: fec: optimize the clock management to save power")
[2] https://patchwork.kernel.org/patch/10090149/
Signed-off-by: Richard Leitner <redacted>
Hi Richard
Same comment about moving text below the ---
Ok. Thanks for your feedback and review.
Reviewed-by: Andrew Lunn <redacted>
regards;Richard.L
Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Duan <hidden> Date: 2017-12-06 01:50:23
From: Richard Leitner <dev-M/VWbR8SM2SsTnJN9+BGXg@public.gmane.org> Sent: Tuesday, December 05, 2017 9:26 PM
quoted hunk
Some PHYs (for example the SMSC LAN8710/LAN8720) doesn't allow turning
the refclk on and off again during operation (according to their datasheet).
Nonetheless exactly this behaviour was introduced for power saving reasons
by commit e8fcfcd5684a ("net: fec: optimize the clock management to save
power").
Therefore add support for the phy_reset_after_clk_enable function from
phylib to mitigate this issue.
Generally speaking this issue is only relevant if the ref clk for the PHY is
generated by the SoC and therefore the PHY is configured to "REF_CLK In
Mode". In our specific case (PCB) this problem does occur at about every 10th
to 50th POR of an LAN8710 connected to an i.MX6SOLO SoC. The typical
symptom of this problem is a "swinging" ethernet link.
Similar issues were reported by users of the NXP forum:
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F
%2Fcommunity.nxp.com%2Fthread%2F389902&data=02%7C01%7Cfugang.du
an%40nxp.com%7C7f9fee272fc44662c2a108d53be3d1ee%7C686ea1d3bc2b4c6
fa92cd99c5c301635%7C0%7C0%7C636480772022331090&sdata=7RdUsoWVWu
o1nM5zKwLt7%2F6U3dxgDJtBDGlQCUWC6IM%3D&reserved=0
https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F
%2Fcommunity.nxp.com%2Fmessage%2F309354&data=02%7C01%7Cfugang.d
uan%40nxp.com%7C7f9fee272fc44662c2a108d53be3d1ee%7C686ea1d3bc2b4
c6fa92cd99c5c301635%7C0%7C0%7C636480772022331090&sdata=D56KilGWD3
kLABxc0yOI%2B44Y%2FhLfrGtdAvupCEyvI%2BI%3D&reserved=0
With this patch applied the issue didn't occur for at least a few hundret PORs
of our board.
Fixes: e8fcfcd5684a ("net: fec: optimize the clock management to save
power")
Signed-off-by: Richard Leitner <redacted>
---
drivers/net/ethernet/freescale/fec_main.c | 7 +++++++
1 file changed, 7 insertions(+)
if (ret)
goto err_enet_mii_probe;
+ /* reset phy if needed here, due to the fact this is the first time we
+ * have the net_device to phy_driver link
+ */
+ phy_reset_after_clk_enable(ndev->phydev);
+
The patch series look better.
But why does it need to reset phy here since phy already is hard reset after clock enable.
if (fep->quirks & FEC_QUIRK_ERR006687)
imx6q_cpuidle_fec_irqs_used();
--
2.11.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Richard Leitner <richard.leitner@skidata.com> Date: 2017-12-06 08:23:25
Hi Andy,
On 12/06/2017 02:50 AM, Andy Duan wrote:
From: Richard Leitner <dev-M/VWbR8SM2SsTnJN9+BGXg@public.gmane.org> Sent: Tuesday, December 05, 2017 9:26 PM
quoted
Some PHYs (for example the SMSC LAN8710/LAN8720) doesn't allow turning
the refclk on and off again during operation (according to their datasheet).
Nonetheless exactly this behaviour was introduced for power saving reasons
by commit e8fcfcd5684a ("net: fec: optimize the clock management to save
power").
Therefore add support for the phy_reset_after_clk_enable function from
phylib to mitigate this issue.
if (ret)
goto err_enet_mii_probe;
+ /* reset phy if needed here, due to the fact this is the first time we
+ * have the net_device to phy_driver link
+ */
+ phy_reset_after_clk_enable(ndev->phydev);
+
The patch series look better.
But why does it need to reset phy here since phy already is hard reset after clock enable.
The problem here is that in fec_enet_open() the fec_enet_clk_enable()
call is done before the phy is probed. Therefore (as mentioned in the
comment) there's no link from the net_device (ndev) to the phy_driver
(which holds the flags).
Any suggestions for a better solution are highly appreciated here! Thanks!
regards;Richard.L
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Andy Duan <hidden> Date: 2017-12-06 08:41:12
From: Richard Leitner <richard.leitner@skidata.com> Sent: Wednesday, December 06, 2017 4:12 PM
To: Andy Duan <redacted>; Richard Leitner <redacted>;
robh+dt@kernel.org; mark.rutland@arm.com; andrew@lunn.ch;
f.fainelli@gmail.com; frowand.list@gmail.com
Cc: davem@davemloft.net; geert+renesas@glider.be;
sergei.shtylyov@cogentembedded.com; baruch@tkos.co.il; david.wu@rock-
chips.com; lukma@denx.de; netdev@vger.kernel.org;
devicetree@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3 4/4] net: fec: add
phy_reset_after_clk_enable() support
Hi Andy,
On 12/06/2017 02:50 AM, Andy Duan wrote:
quoted
From: Richard Leitner <redacted> Sent: Tuesday, December 05,
2017 9:26 PM
quoted
Some PHYs (for example the SMSC LAN8710/LAN8720) doesn't allow
turning the refclk on and off again during operation (according to their
datasheet).
quoted
quoted
Nonetheless exactly this behaviour was introduced for power saving
reasons by commit e8fcfcd5684a ("net: fec: optimize the clock
management to save power").
Therefore add support for the phy_reset_after_clk_enable function
from phylib to mitigate this issue.
if (ret)
goto err_enet_mii_probe;
+ /* reset phy if needed here, due to the fact this is the first time we
+ * have the net_device to phy_driver link
+ */
+ phy_reset_after_clk_enable(ndev->phydev);
+
The patch series look better.
But why does it need to reset phy here since phy already is hard reset after
clock enable.
The problem here is that in fec_enet_open() the fec_enet_clk_enable() call is
done before the phy is probed. Therefore (as mentioned in the
comment) there's no link from the net_device (ndev) to the phy_driver
(which holds the flags).
Any suggestions for a better solution are highly appreciated here! Thanks!
regards;Richard.L
Okay, I see.
For the patch: Acked-by: Fugang Duan [off-list ref]
N�����r��y���b�X��ǧv�^�){.n�+���z��z��z)���w*jg���
�����ݢj.�۰\��M��gj��a����' ��ޢ�
���j:+v���w�j�m��������zZ+�����ݢj"��!�i