Skip to contentSkip to conversation

net: fec: fix refclk enable for SMSC LAN8710/20

PATCH Superseded Richard Leitner 5 participants 15 messages Dec 5, 2017 – Dec 6, 2017

Subsystems (6)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: fec: fix refclk enable for SMSC LAN8710/20

From: Richard Leitner <[email protected]>

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(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/4 phylib: Add device reset delay support

From: Richard Leitner <[email protected]>

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/
---
 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(-)
Documentation/devicetree/bindings/net/phy.txt +10 -0
index c05479f5ac7c..72860ce7f610 100644
@@ -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 {
@@ -62,4 +68,8 @@ ethernet-phy@0 {
 	interrupt-parent = <&PIC>;
 	interrupts = <35 IRQ_TYPE_EDGE_RISING>;
 	reg = <0>;
+
+	reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
+	reset-delay-us = <1000>;
+	reset-post-delay-us = <2000>;
 };
drivers/net/phy/mdio_device.c +11 -2
index 75d97dd9fb28..ca3ff43f8ee8 100644
@@ -24,6 +24,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/unistd.h>
+#include <linux/delay.h>
 
 void mdio_device_free(struct mdio_device *mdiodev)
 {
@@ -118,8 +119,16 @@ EXPORT_SYMBOL(mdio_device_remove);
 
 void mdio_device_reset(struct mdio_device *mdiodev, int value)
 {
-	if (mdiodev->reset)
-		gpiod_set_value(mdiodev->reset, value);
+	if (!mdiodev->reset)
+		return;
+
+	gpiod_set_value(mdiodev->reset, value);
+
+	if (value && mdiodev->reset_delay)
+		usleep_range(mdiodev->reset_delay, mdiodev->reset_delay + 100);
+	else if (!value && mdiodev->reset_post_delay)
+		usleep_range(mdiodev->reset_post_delay,
+			     mdiodev->reset_post_delay + 100);
 }
 EXPORT_SYMBOL(mdio_device_reset);
 
drivers/of/of_mdio.c +8 -0
index 98258583abb0..fb56486dfaa0 100644
@@ -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
 	 * can be looked up later */
 	of_node_get(child);
include/linux/mdio.h +2 -0
index 92d4e55ffe67..e37c21d8eb19 100644
@@ -41,6 +41,8 @@ struct mdio_device {
 	int addr;
 	int flags;
 	struct gpio_desc *reset;
+	unsigned int reset_delay;
+	unsigned int reset_post_delay;
 };
 #define to_mdio_device(d) container_of(d, struct mdio_device, dev)
 
Signature · 1 line
2.11.0
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH net-next v3 1/4] phylib: Add device reset delay support

Hi Richard,

Quoted 6 lines · Richard Leitner

From: Richard Leitner <[email protected]>

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.

Thanks for your patch!

Quoted 3 lines

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/

The above paragraph belongs under the "---" line below, as it is not intended to be preserved in the eternal git history.

Quoted 1 line

Although I have a few suggestions below:

Quoted 8 lines
drivers/net/phy/mdio_device.c +0 -2
@@ -118,8 +119,16 @@ EXPORT_SYMBOL(mdio_device_remove);
 
 void mdio_device_reset(struct mdio_device *mdiodev, int value)
 {
-       if (mdiodev->reset)
-               gpiod_set_value(mdiodev->reset, value);

drivers/net/phy/mdio_device.c EXPORT_SYMBOL(mdio_device_remove); · line 131

Quoted 10 lines
drivers/net/phy/mdio_device.c +10 -0
+       if (!mdiodev->reset)
+               return;
+
+       gpiod_set_value(mdiodev->reset, value);
+
+       if (value && mdiodev->reset_delay)
+               usleep_range(mdiodev->reset_delay, mdiodev->reset_delay + 100);
+       else if (!value && mdiodev->reset_post_delay)
+               usleep_range(mdiodev->reset_post_delay,
+                            mdiodev->reset_post_delay + 100);

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)"?

drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, · line 86

Quoted 13 lines
drivers/of/of_mdio.c +7 -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;

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 -- [email protected]

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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH net-next v3 1/4] phylib: Add device reset delay support

Hi Geert,

Quoted 10 lines · Geert Uytterhoeven

Hi Richard,

Quoted 6 lines · Richard Leitner

From: Richard Leitner <[email protected]>

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.

Quoted 8 lines

Thanks for your patch!

Quoted 3 lines

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/

The above paragraph belongs under the "---" line below, as it is not intended to be preserved in the eternal git history.

Ok. Thanks. That makes sense. I'll take it into account for v4.

Quoted 6 lines
Quoted 2 lines

Although I have a few suggestions below:

Thank you for your review and suggestions (they make the code look way more neater). I'll adapt v4 accordingly.

Quoted 49 lines
Quoted 9 lines
drivers/net/phy/mdio_device.c +0 -2
@@ -118,8 +119,16 @@ EXPORT_SYMBOL(mdio_device_remove);
 
 void mdio_device_reset(struct mdio_device *mdiodev, int value)
 {
-       if (mdiodev->reset)
-               gpiod_set_value(mdiodev->reset, value);

drivers/net/phy/mdio_device.c EXPORT_SYMBOL(mdio_device_remove); · line 131

Quoted 10 lines
drivers/net/phy/mdio_device.c +10 -0
+       if (!mdiodev->reset)
+               return;
+
+       gpiod_set_value(mdiodev->reset, value);
+
+       if (value && mdiodev->reset_delay)
+               usleep_range(mdiodev->reset_delay, mdiodev->reset_delay + 100);
+       else if (!value && mdiodev->reset_post_delay)
+               usleep_range(mdiodev->reset_post_delay,
+                            mdiodev->reset_post_delay + 100);

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)"?

drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, · line 86

Quoted 13 lines
drivers/of/of_mdio.c +7 -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;

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:

Quoted 3 lines
        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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

Re: [PATCH net-next v3 1/4] phylib: Add device reset delay support

In reply to Richard Leitner

Hi Richard

drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, · line 86

Quoted 12 lines

+++ b/drivers/of/of_mdio.c

drivers/of/of_mdio.c +7 -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;

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
#5 lore raw

Re: [PATCH net-next v3 1/4] phylib: Add device reset delay support

Hi Andrew,

Quoted 18 lines · Andrew Lunn

Hi Richard

drivers/of/of_mdio.c static int of_mdiobus_register_phy(struct mii_bus *mdio, · line 86

Quoted 12 lines

+++ b/drivers/of/of_mdio.c

drivers/of/of_mdio.c +7 -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;

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:

Quoted 8 lines
	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.

Quoted 9 lines · Geert Uytterhoeven
Quoted 8 lines

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

#6 lore raw

PATCH v3 2/4 phylib: add reset after clk enable support

In reply to Richard Leitner

From: Richard Leitner <[email protected]>

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/

---
 drivers/net/phy/phy_device.c | 24 ++++++++++++++++++++++++
 include/linux/phy.h          |  2 ++
 2 files changed, 26 insertions(+)
drivers/net/phy/phy_device.c +24 -0
index 1de5e242b8b4..462c17ed87b8 100644
@@ -1218,6 +1218,30 @@ int phy_loopback(struct phy_device *phydev, bool enable)
 }
 EXPORT_SYMBOL(phy_loopback);
 
+/**
+ * phy_reset_after_clk_enable - perform a PHY reset if needed
+ * @phydev: target phy_device struct
+ *
+ * Description: Some PHYs are known to need a reset after their refclk was
+ *   enabled. This function evaluates the flags and perform the reset if it's
+ *   needed. Returns < 0 on error, 0 if the phy wasn't reset and 1 if the phy
+ *   was reset.
+ */
+int phy_reset_after_clk_enable(struct phy_device *phydev)
+{
+	if (!phydev || !phydev->drv)
+		return -ENODEV;
+
+	if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) {
+		phy_device_reset(phydev, 1);
+		phy_device_reset(phydev, 0);
+		return 1;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(phy_reset_after_clk_enable);
+
 /* Generic PHY support and helper functions */
 
 /**
include/linux/phy.h +2 -0
index 2bcbe894eb10..5c05fc73af70 100644
@@ -59,6 +59,7 @@
 
 #define PHY_HAS_INTERRUPT	0x00000001
 #define PHY_IS_INTERNAL		0x00000002
+#define PHY_RST_AFTER_CLK_EN	0x00000004
 #define MDIO_DEVICE_IS_PHY	0x80000000
 
 /* Interface Mode definitions */
@@ -839,6 +840,7 @@ int phy_aneg_done(struct phy_device *phydev);
 
 int phy_stop_interrupts(struct phy_device *phydev);
 int phy_restart_aneg(struct phy_device *phydev);
+int phy_reset_after_clk_enable(struct phy_device *phydev);
 
 static inline void phy_device_reset(struct phy_device *phydev, int value)
 {
Signature · 1 line
2.11.0
maintainer Reviewed-by on v3 2/4
#7 lore raw

Re: [PATCH net-next v3 2/4] phylib: add reset after clk enable support

Quoted 13 lines · Richard Leitner

From: Richard Leitner <[email protected]>

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.

Quoted 7 lines

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/

Hi Richard

Same comment about moving text below the ---

Andrew

#8 lore raw

Re: [PATCH net-next v3 2/4] phylib: add reset after clk enable support

Hi Andrew,

Quoted 17 lines · Andrew Lunn
Quoted 16 lines · Richard Leitner

From: Richard Leitner <[email protected]>

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].

Quoted 8 lines
Quoted 4 lines

[1] commit e8fcfcd5684a ("net: fec: optimize the clock management to save power")
[2] https://patchwork.kernel.org/patch/10090149/

Hi Richard

Same comment about moving text below the ---

Ok. Thanks for your feedback and review.

Quoted 3 lines

regards;Richard.L

Quoted 2 lines

Andrew

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

PATCH v3 3/4 net: phy: smsc: LAN8710/20: add PHY_RST_AFTER_CLK_EN flag

In reply to Richard Leitner

From: Richard Leitner <[email protected]>

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

---
 drivers/net/phy/smsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/smsc.c +1 -1
index a1961ba87e2b..be399d645224 100644
@@ -312,7 +312,7 @@ static struct phy_driver smsc_phy_driver[] = {
 	.name		= "SMSC LAN8710/LAN8720",
 
 	.features	= PHY_BASIC_FEATURES,
-	.flags		= PHY_HAS_INTERRUPT,
+	.flags		= PHY_HAS_INTERRUPT | PHY_RST_AFTER_CLK_EN,
 
 	.probe		= smsc_phy_probe,
 
Signature · 1 line
2.11.0
maintainer Reviewed-by on v3 3/4
#10 lore raw

Re: [PATCH net-next v3 3/4] net: phy: smsc: LAN8710/20: add PHY_RST_AFTER_CLK_EN flag

Quoted 10 lines · Richard Leitner

From: Richard Leitner <[email protected]>

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

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

PATCH v3 4/4 net: fec: add phy_reset_after_clk_enable() support

In reply to Richard Leitner

From: Richard Leitner <[email protected]>

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/389902
	https://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")
---
 drivers/net/ethernet/freescale/fec_main.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +7 -0
index 610573855213..8c3d0fb7db20 100644
@@ -1862,6 +1862,8 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
 		ret = clk_prepare_enable(fep->clk_ref);
 		if (ret)
 			goto failed_clk_ref;
+
+		phy_reset_after_clk_enable(ndev->phydev);
 	} else {
 		clk_disable_unprepare(fep->clk_ahb);
 		clk_disable_unprepare(fep->clk_enet_out);
@@ -2860,6 +2862,11 @@ fec_enet_open(struct net_device *ndev)
 	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);
+
 	if (fep->quirks & FEC_QUIRK_ERR006687)
 		imx6q_cpuidle_fec_irqs_used();
 
Signature · 1 line
2.11.0
#12 lore raw

RE: [PATCH net-next v3 4/4] net: fec: add phy_reset_after_clk_enable() support

From: Richard Leitner <dev-M/[email protected]> Sent: Tuesday, December 05, 2017 9:26 PM

Quoted 50 lines

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")

---
drivers/net/ethernet/freescale/fec_main.c | 7 +++++++

1 file changed, 7 insertions(+)
drivers/net/ethernet/freescale/fec_main.c +2 -0
index 610573855213..8c3d0fb7db20 100644
@@ -1862,6 +1862,8 @@ static int fec_enet_clk_enable(struct net_device
 *ndev, bool enable)
 		ret = clk_prepare_enable(fep->clk_ref);
 		if (ret)
 			goto failed_clk_ref;
+
+		phy_reset_after_clk_enable(ndev->phydev);
 	} else {
 		clk_disable_unprepare(fep->clk_ahb);
		clk_disable_unprepare(fep->clk_enet_out);

drivers/net/ethernet/freescale/fec_main.c fec_enet_open(struct net_device *ndev) · line 2869

Quoted 8 lines
drivers/net/ethernet/freescale/fec_main.c +5 -0
@@ -2860,6 +2862,11 @@ fec_enet_open(struct net_device *ndev)
 	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.

Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +0 -1
 	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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH net-next v3 4/4] net: fec: add phy_reset_after_clk_enable() support

Hi Andy,

Quoted 8 lines · Andy Duan

From: Richard Leitner <dev-M/[email protected]> Sent: Tuesday, December 05, 2017 9:26 PM

Quoted 7 lines

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.

...

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/freescale/fec_main.c +2 -0
index 610573855213..8c3d0fb7db20 100644
@@ -1862,6 +1862,8 @@ static int fec_enet_clk_enable(struct net_device
 *ndev, bool enable)
 		ret = clk_prepare_enable(fep->clk_ref);
 		if (ret)
 			goto failed_clk_ref;
+
+		phy_reset_after_clk_enable(ndev->phydev);
 	} else {
 		clk_disable_unprepare(fep->clk_ahb);
		clk_disable_unprepare(fep->clk_enet_out);
drivers/net/ethernet/freescale/fec_main.c +0 -0
@@ -2860,6 +2862,11 @@ fec_enet_open(struct net_device *ndev)
 	if (ret)
 		goto err_enet_mii_probe;
 
Quoted 8 lines

drivers/net/ethernet/freescale/fec_main.c fec_enet_open(struct net_device *ndev) · line 2869

Quoted 5 lines
drivers/net/ethernet/freescale/fec_main.c +5 -0
+	/* 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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

RE: [PATCH net-next v3 4/4] net: fec: add phy_reset_after_clk_enable() support

RnJvbTogUmljaGFyZCBMZWl0bmVyIDxyaWNoYXJkLmxlaXRuZXJAc2tpZGF0YS5jb20+IFNlbnQ6 IFdlZG5lc2RheSwgRGVjZW1iZXIgMDYsIDIwMTcgNDoxMiBQTQ0KPlRvOiBBbmR5IER1YW4gPGZ1 Z2FuZy5kdWFuQG54cC5jb20+OyBSaWNoYXJkIExlaXRuZXIgPGRldkBnMGhsMW4ubmV0PjsNCj5y b2JoK2R0QGtlcm5lbC5vcmc7IG1hcmsucnV0bGFuZEBhcm0uY29tOyBhbmRyZXdAbHVubi5jaDsN Cj5mLmZhaW5lbGxpQGdtYWlsLmNvbTsgZnJvd2FuZC5saXN0QGdtYWlsLmNvbQ0KPkNjOiBkYXZl bUBkYXZlbWxvZnQubmV0OyBnZWVydCtyZW5lc2FzQGdsaWRlci5iZTsNCj5zZXJnZWkuc2h0eWx5 b3ZAY29nZW50ZW1iZWRkZWQuY29tOyBiYXJ1Y2hAdGtvcy5jby5pbDsgZGF2aWQud3VAcm9jay0N Cj5jaGlwcy5jb207IGx1a21hQGRlbnguZGU7IG5ldGRldkB2Z2VyLmtlcm5lbC5vcmc7DQo+ZGV2 aWNldHJlZUB2Z2VyLmtlcm5lbC5vcmc7IGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmcNCj5T dWJqZWN0OiBSZTogW1BBVENIIG5ldC1uZXh0IHYzIDQvNF0gbmV0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GV2KTsNCj4+PiArDQo+Pg0KPj4gVGhlIHBhdGNoIHNlcmllcyBsb29r IGJldHRlci4NCj4+IEJ1dCB3aHkgZG9lcyBpdCBuZWVkIHRvIHJlc2V0IHBoeSBoZXJlIHNpbmNl IHBoeSBhbHJlYWR5IGlzIGhhcmQgcmVzZXQgYWZ0ZXINCj5jbG9jayBlbmFibGUuDQo+DQo+VGhl IHByb2JsZW0gaGVyZSBpcyB0aGF0IGluIGZlY19lbmV0X29wZW4oKSB0aGUgZmVjX2VuZXRfY2xr X2VuYWJsZSgpIGNhbGwgaXMNCj5kb25lIGJlZm9yZSB0aGUgcGh5IGlzIHByb2JlZC4gVGhlcmVm b3JlIChhcyBtZW50aW9uZWQgaW4gdGhlDQo+Y29tbWVudCkgdGhlcmUncyBubyBsaW5rIGZyb20g dGhlIG5ldF9kZXZpY2UgKG5kZXYpIHRvIHRoZSBwaHlfZHJpdmVyDQo+KHdoaWNoIGhvbGRzIHRo ZSBmbGFncykuDQo+DQo+QW55IHN1Z2dlc3Rpb25zIGZvciBhIGJldHRlciBzb2x1dGlvbiBhcmUg aGlnaGx5IGFwcHJlY2lhdGVkIGhlcmUhIFRoYW5rcyENCj4NCj5yZWdhcmRzO1JpY2hhcmQuTA0K DQpPa2F5LCBJIHNlZS4NCg0KRm9yIHRoZSBwYXRjaDogQWNrZWQtYnk6IEZ1Z2FuZyBEdWFuIDxm dWdhbmcuZHVhbkBueHAuY29tPg0K
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html