netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode
@ 2022-06-20 11:04 Lukas Wunner
  2022-06-20 17:03 ` Florian Fainelli
  2022-06-22  5:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Lukas Wunner @ 2022-06-20 11:04 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
  Cc: netdev, linux-usb, Steve Glendinning, UNGLinuxDriver,
	Oliver Neukum, Andre Edich, Oleksij Rempel, Martyn Welch,
	Gabriel Hojda, Christoph Fritz, Lino Sanfilippo,
	Philipp Rosenberger, Simon Han, Heiner Kallweit, Andrew Lunn,
	Russell King, Ferry Toth, Marek Szyprowski, Krzysztof Kozlowski,
	linux-samsung-soc

Simon reports that if two LAN9514 USB adapters are directly connected
without an intermediate switch, the link fails to come up and link LEDs
remain dark.  The issue was introduced by commit 1ce8b37241ed ("usbnet:
smsc95xx: Forward PHY interrupts to PHY driver to avoid polling").

The PHY suffers from a known erratum wherein link detection becomes
unreliable if Energy Detect Power-Down is used.  In poll mode, the
driver works around the erratum by briefly disabling EDPD for 640 msec
to detect a neighbor, then re-enabling it to save power.

In interrupt mode, no interrupt is signaled if EDPD is used by both link
partners, so it must not be enabled at all.

We'll recoup the power savings by enabling SUSPEND1 mode on affected
LAN95xx chips in a forthcoming commit.

Fixes: 1ce8b37241ed ("usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling")
Reported-by: Simon Han <z.han@kunbus.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
 drivers/net/phy/smsc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 1b54684b68a0..96d3c40932d8 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -110,7 +110,7 @@ static int smsc_phy_config_init(struct phy_device *phydev)
 	struct smsc_phy_priv *priv = phydev->priv;
 	int rc;
 
-	if (!priv->energy_enable)
+	if (!priv->energy_enable || phydev->irq != PHY_POLL)
 		return 0;
 
 	rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
@@ -210,6 +210,8 @@ static int lan95xx_config_aneg_ext(struct phy_device *phydev)
  * response on link pulses to detect presence of plugged Ethernet cable.
  * The Energy Detect Power-Down mode is enabled again in the end of procedure to
  * save approximately 220 mW of power if cable is unplugged.
+ * The workaround is only applicable to poll mode. Energy Detect Power-Down may
+ * not be used in interrupt mode lest link change detection becomes unreliable.
  */
 static int lan87xx_read_status(struct phy_device *phydev)
 {
@@ -217,7 +219,7 @@ static int lan87xx_read_status(struct phy_device *phydev)
 
 	int err = genphy_read_status(phydev);
 
-	if (!phydev->link && priv->energy_enable) {
+	if (!phydev->link && priv->energy_enable && phydev->irq == PHY_POLL) {
 		/* Disable EDPD to wake up PHY */
 		int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
 		if (rc < 0)
-- 
2.35.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode
  2022-06-20 11:04 [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode Lukas Wunner
@ 2022-06-20 17:03 ` Florian Fainelli
  2022-06-20 19:33   ` Lukas Wunner
  2022-06-22  5:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2022-06-20 17:03 UTC (permalink / raw)
  To: Lukas Wunner, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Eric Dumazet
  Cc: netdev, linux-usb, Steve Glendinning, UNGLinuxDriver,
	Oliver Neukum, Andre Edich, Oleksij Rempel, Martyn Welch,
	Gabriel Hojda, Christoph Fritz, Lino Sanfilippo,
	Philipp Rosenberger, Simon Han, Heiner Kallweit, Andrew Lunn,
	Russell King, Ferry Toth, Marek Szyprowski, Krzysztof Kozlowski,
	linux-samsung-soc

On 6/20/22 04:04, Lukas Wunner wrote:
> Simon reports that if two LAN9514 USB adapters are directly connected
> without an intermediate switch, the link fails to come up and link LEDs
> remain dark.  The issue was introduced by commit 1ce8b37241ed ("usbnet:
> smsc95xx: Forward PHY interrupts to PHY driver to avoid polling").
> 
> The PHY suffers from a known erratum wherein link detection becomes
> unreliable if Energy Detect Power-Down is used.  In poll mode, the
> driver works around the erratum by briefly disabling EDPD for 640 msec
> to detect a neighbor, then re-enabling it to save power.
> 
> In interrupt mode, no interrupt is signaled if EDPD is used by both link
> partners, so it must not be enabled at all.
> 
> We'll recoup the power savings by enabling SUSPEND1 mode on affected
> LAN95xx chips in a forthcoming commit.
> 
> Fixes: 1ce8b37241ed ("usbnet: smsc95xx: Forward PHY interrupts to PHY driver to avoid polling")
> Reported-by: Simon Han <z.han@kunbus.com>
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> ---
>   drivers/net/phy/smsc.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
> index 1b54684b68a0..96d3c40932d8 100644
> --- a/drivers/net/phy/smsc.c
> +++ b/drivers/net/phy/smsc.c
> @@ -110,7 +110,7 @@ static int smsc_phy_config_init(struct phy_device *phydev)
>   	struct smsc_phy_priv *priv = phydev->priv;
>   	int rc;
>   
> -	if (!priv->energy_enable)
> +	if (!priv->energy_enable || phydev->irq != PHY_POLL)

phy_interrupt_is_valid() may be more appropriate, since you are assuming 
that you either have PHY_POLL or valid "external" PHY interrupt but 
there is also the special case of PHY_MAC_INTERRUPT that is not dealt with.

>   		return 0;
>   
>   	rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
> @@ -210,6 +210,8 @@ static int lan95xx_config_aneg_ext(struct phy_device *phydev)
>    * response on link pulses to detect presence of plugged Ethernet cable.
>    * The Energy Detect Power-Down mode is enabled again in the end of procedure to
>    * save approximately 220 mW of power if cable is unplugged.
> + * The workaround is only applicable to poll mode. Energy Detect Power-Down may
> + * not be used in interrupt mode lest link change detection becomes unreliable.
>    */
>   static int lan87xx_read_status(struct phy_device *phydev)
>   {
> @@ -217,7 +219,7 @@ static int lan87xx_read_status(struct phy_device *phydev)
>   
>   	int err = genphy_read_status(phydev);
>   
> -	if (!phydev->link && priv->energy_enable) {
> +	if (!phydev->link && priv->energy_enable && phydev->irq == PHY_POLL) {

phy_polling_mode()?

>   		/* Disable EDPD to wake up PHY */
>   		int rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
>   		if (rc < 0)


-- 
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode
  2022-06-20 17:03 ` Florian Fainelli
@ 2022-06-20 19:33   ` Lukas Wunner
  0 siblings, 0 replies; 4+ messages in thread
From: Lukas Wunner @ 2022-06-20 19:33 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: David S. Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet,
	netdev, linux-usb, Steve Glendinning, UNGLinuxDriver,
	Oliver Neukum, Andre Edich, Oleksij Rempel, Martyn Welch,
	Gabriel Hojda, Christoph Fritz, Lino Sanfilippo,
	Philipp Rosenberger, Simon Han, Heiner Kallweit, Andrew Lunn,
	Russell King, Ferry Toth, Marek Szyprowski, Krzysztof Kozlowski,
	linux-samsung-soc

On Mon, Jun 20, 2022 at 10:03:26AM -0700, Florian Fainelli wrote:
> On 6/20/22 04:04, Lukas Wunner wrote:
> > --- a/drivers/net/phy/smsc.c
> > +++ b/drivers/net/phy/smsc.c
> > @@ -110,7 +110,7 @@ static int smsc_phy_config_init(struct phy_device *phydev)
> >   	struct smsc_phy_priv *priv = phydev->priv;
> >   	int rc;
> > -	if (!priv->energy_enable)
> > +	if (!priv->energy_enable || phydev->irq != PHY_POLL)
> 
> phy_interrupt_is_valid() may be more appropriate, since you are assuming
> that you either have PHY_POLL or valid "external" PHY interrupt but there is
> also the special case of PHY_MAC_INTERRUPT that is not dealt with.

I deliberately disable EDPD for PHY_MAC_INTERRUPT as well.

That's a proper interrupt, i.e. the PHY signals interrupts
to the MAC (e.g. through an interrupt pin on the MAC),
which forwards the interrupts to phylib.  EDPD cannot
be used in that situation either.


> > @@ -217,7 +219,7 @@ static int lan87xx_read_status(struct phy_device *phydev)
> >   	int err = genphy_read_status(phydev);
> > -	if (!phydev->link && priv->energy_enable) {
> > +	if (!phydev->link && priv->energy_enable && phydev->irq == PHY_POLL) {
> 
> phy_polling_mode()?

Personally I think checking for PHY_POLL is succinct,
but if you or anyone else feels strongly about it
I'll be happy to add such a static inline to
include/linux/phy.h.

Thanks,

Lukas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode
  2022-06-20 11:04 [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode Lukas Wunner
  2022-06-20 17:03 ` Florian Fainelli
@ 2022-06-22  5:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-22  5:50 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: davem, kuba, pabeni, edumazet, netdev, linux-usb,
	steve.glendinning, UNGLinuxDriver, oneukum, andre.edich, linux,
	martyn.welch, ghojda, chf.fritz, LinoSanfilippo, p.rosenberger,
	z.han, hkallweit1, andrew, linux, fntoth, m.szyprowski, krzk,
	linux-samsung-soc

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 20 Jun 2022 13:04:50 +0200 you wrote:
> Simon reports that if two LAN9514 USB adapters are directly connected
> without an intermediate switch, the link fails to come up and link LEDs
> remain dark.  The issue was introduced by commit 1ce8b37241ed ("usbnet:
> smsc95xx: Forward PHY interrupts to PHY driver to avoid polling").
> 
> The PHY suffers from a known erratum wherein link detection becomes
> unreliable if Energy Detect Power-Down is used.  In poll mode, the
> driver works around the erratum by briefly disabling EDPD for 640 msec
> to detect a neighbor, then re-enabling it to save power.
> 
> [...]

Here is the summary with links:
  - [net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode
    https://git.kernel.org/netdev/net/c/2642cc6c3bbe

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-22  5:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-20 11:04 [PATCH net] net: phy: smsc: Disable Energy Detect Power-Down in interrupt mode Lukas Wunner
2022-06-20 17:03 ` Florian Fainelli
2022-06-20 19:33   ` Lukas Wunner
2022-06-22  5:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).