linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/phy: micrel: Add workaround for bad autoneg
@ 2015-10-21 19:17 Nathan Sullivan
  2015-10-21 19:20 ` Florian Fainelli
  2015-10-23  9:57 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Nathan Sullivan @ 2015-10-21 19:17 UTC (permalink / raw)
  To: f.fainelli; +Cc: netdev, linux-kernel, Nathan Sullivan

Very rarely, the KSZ9031 will appear to complete autonegotiation, but
will drop all traffic afterwards.  When this happens, the idle error
count will read 0xFF after autonegotiation completes.  Reset the PHY
when in that state.

Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
---
 drivers/net/phy/micrel.c |   23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 499185e..cf6312f 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -514,6 +514,27 @@ static int ksz8873mll_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int ksz9031_read_status(struct phy_device *phydev)
+{
+	int err;
+	int regval;
+
+	err = genphy_read_status(phydev);
+	if (err)
+		return err;
+
+	/* Make sure the PHY is not broken. Read idle error count,
+	 * and reset the PHY if it is maxed out.
+	 */
+	regval = phy_read(phydev, MII_STAT1000);
+	if ((regval & 0xFF) == 0xFF) {
+		phy_init_hw(phydev);
+		phydev->link = 0;
+	}
+
+	return 0;
+}
+
 static int ksz8873mll_config_aneg(struct phy_device *phydev)
 {
 	return 0;
@@ -772,7 +793,7 @@ static struct phy_driver ksphy_driver[] = {
 	.driver_data	= &ksz9021_type,
 	.config_init	= ksz9031_config_init,
 	.config_aneg	= genphy_config_aneg,
-	.read_status	= genphy_read_status,
+	.read_status	= ksz9031_read_status,
 	.ack_interrupt	= kszphy_ack_interrupt,
 	.config_intr	= kszphy_config_intr,
 	.suspend	= genphy_suspend,
-- 
1.7.10.4


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

* Re: [PATCH] net/phy: micrel: Add workaround for bad autoneg
  2015-10-21 19:17 [PATCH] net/phy: micrel: Add workaround for bad autoneg Nathan Sullivan
@ 2015-10-21 19:20 ` Florian Fainelli
  2015-10-21 19:42   ` Nathan Sullivan
  2015-10-23  9:57 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2015-10-21 19:20 UTC (permalink / raw)
  To: Nathan Sullivan; +Cc: netdev, linux-kernel

2015-10-21 12:17 GMT-07:00 Nathan Sullivan <nathan.sullivan@ni.com>:
> Very rarely, the KSZ9031 will appear to complete autonegotiation, but
> will drop all traffic afterwards.  When this happens, the idle error
> count will read 0xFF after autonegotiation completes.  Reset the PHY
> when in that state.
>
> Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
> ---
>  drivers/net/phy/micrel.c |   23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> index 499185e..cf6312f 100644
> --- a/drivers/net/phy/micrel.c
> +++ b/drivers/net/phy/micrel.c
> @@ -514,6 +514,27 @@ static int ksz8873mll_read_status(struct phy_device *phydev)
>         return 0;
>  }
>
> +static int ksz9031_read_status(struct phy_device *phydev)
> +{
> +       int err;
> +       int regval;
> +
> +       err = genphy_read_status(phydev);
> +       if (err)
> +               return err;
> +
> +       /* Make sure the PHY is not broken. Read idle error count,
> +        * and reset the PHY if it is maxed out.
> +        */
> +       regval = phy_read(phydev, MII_STAT1000);
> +       if ((regval & 0xFF) == 0xFF) {

Don't you also need to set phydev->state to PHY_READY here to force
the state machine to restart?

> +               phy_init_hw(phydev);
> +               phydev->link = 0;
> +       }
> +
> +       return 0;
> +}
> +
>  static int ksz8873mll_config_aneg(struct phy_device *phydev)
>  {
>         return 0;
> @@ -772,7 +793,7 @@ static struct phy_driver ksphy_driver[] = {
>         .driver_data    = &ksz9021_type,
>         .config_init    = ksz9031_config_init,
>         .config_aneg    = genphy_config_aneg,
> -       .read_status    = genphy_read_status,
> +       .read_status    = ksz9031_read_status,
>         .ack_interrupt  = kszphy_ack_interrupt,
>         .config_intr    = kszphy_config_intr,
>         .suspend        = genphy_suspend,
> --
> 1.7.10.4
>



-- 
Florian

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

* Re: [PATCH] net/phy: micrel: Add workaround for bad autoneg
  2015-10-21 19:20 ` Florian Fainelli
@ 2015-10-21 19:42   ` Nathan Sullivan
  2015-10-21 21:46     ` Florian Fainelli
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Sullivan @ 2015-10-21 19:42 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev, linux-kernel

On Wed, Oct 21, 2015 at 12:20:21PM -0700, Florian Fainelli wrote:
> 2015-10-21 12:17 GMT-07:00 Nathan Sullivan <nathan.sullivan@ni.com>:
> > Very rarely, the KSZ9031 will appear to complete autonegotiation, but
> > will drop all traffic afterwards.  When this happens, the idle error
> > count will read 0xFF after autonegotiation completes.  Reset the PHY
> > when in that state.
> >
> > Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
> > ---
> >  drivers/net/phy/micrel.c |   23 ++++++++++++++++++++++-
> >  1 file changed, 22 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> > index 499185e..cf6312f 100644
> > --- a/drivers/net/phy/micrel.c
> > +++ b/drivers/net/phy/micrel.c
> > @@ -514,6 +514,27 @@ static int ksz8873mll_read_status(struct phy_device *phydev)
> >         return 0;
> >  }
> >
> > +static int ksz9031_read_status(struct phy_device *phydev)
> > +{
> > +       int err;
> > +       int regval;
> > +
> > +       err = genphy_read_status(phydev);
> > +       if (err)
> > +               return err;
> > +
> > +       /* Make sure the PHY is not broken. Read idle error count,
> > +        * and reset the PHY if it is maxed out.
> > +        */
> > +       regval = phy_read(phydev, MII_STAT1000);
> > +       if ((regval & 0xFF) == 0xFF) {
> 
> Don't you also need to set phydev->state to PHY_READY here to force
> the state machine to restart?
>

I don't think so, we stay in the PHY_AN state since phy_init_hw will restart
autonegotiation.  Setting link=0 will go through PHY_NOLINK then back to
PHY_AN, so we wait for autoneg to complete again.

> > +               phy_init_hw(phydev);
> > +               phydev->link = 0;
> > +       }
> > +
> > +       return 0;
> > +}
> > +
> >  static int ksz8873mll_config_aneg(struct phy_device *phydev)
> >  {
> >         return 0;
> > @@ -772,7 +793,7 @@ static struct phy_driver ksphy_driver[] = {
> >         .driver_data    = &ksz9021_type,
> >         .config_init    = ksz9031_config_init,
> >         .config_aneg    = genphy_config_aneg,
> > -       .read_status    = genphy_read_status,
> > +       .read_status    = ksz9031_read_status,
> >         .ack_interrupt  = kszphy_ack_interrupt,
> >         .config_intr    = kszphy_config_intr,
> >         .suspend        = genphy_suspend,
> > --
> > 1.7.10.4
> >
> 
> 
> 
> -- 
> Florian

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

* Re: [PATCH] net/phy: micrel: Add workaround for bad autoneg
  2015-10-21 19:42   ` Nathan Sullivan
@ 2015-10-21 21:46     ` Florian Fainelli
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Fainelli @ 2015-10-21 21:46 UTC (permalink / raw)
  To: Nathan Sullivan; +Cc: netdev, linux-kernel

On 21/10/15 12:42, Nathan Sullivan wrote:
> On Wed, Oct 21, 2015 at 12:20:21PM -0700, Florian Fainelli wrote:
>> 2015-10-21 12:17 GMT-07:00 Nathan Sullivan <nathan.sullivan@ni.com>:
>>> Very rarely, the KSZ9031 will appear to complete autonegotiation, but
>>> will drop all traffic afterwards.  When this happens, the idle error
>>> count will read 0xFF after autonegotiation completes.  Reset the PHY
>>> when in that state.
>>>
>>> Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>
>>> ---
>>>  drivers/net/phy/micrel.c |   23 ++++++++++++++++++++++-
>>>  1 file changed, 22 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
>>> index 499185e..cf6312f 100644
>>> --- a/drivers/net/phy/micrel.c
>>> +++ b/drivers/net/phy/micrel.c
>>> @@ -514,6 +514,27 @@ static int ksz8873mll_read_status(struct phy_device *phydev)
>>>         return 0;
>>>  }
>>>
>>> +static int ksz9031_read_status(struct phy_device *phydev)
>>> +{
>>> +       int err;
>>> +       int regval;
>>> +
>>> +       err = genphy_read_status(phydev);
>>> +       if (err)
>>> +               return err;
>>> +
>>> +       /* Make sure the PHY is not broken. Read idle error count,
>>> +        * and reset the PHY if it is maxed out.
>>> +        */
>>> +       regval = phy_read(phydev, MII_STAT1000);
>>> +       if ((regval & 0xFF) == 0xFF) {
>>
>> Don't you also need to set phydev->state to PHY_READY here to force
>> the state machine to restart?
>>
> 
> I don't think so, we stay in the PHY_AN state since phy_init_hw will restart
> autonegotiation.  Setting link=0 will go through PHY_NOLINK then back to
> PHY_AN, so we wait for autoneg to complete again.

Good point, thanks for clarifiying that part.
-- 
Florian

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

* Re: [PATCH] net/phy: micrel: Add workaround for bad autoneg
  2015-10-21 19:17 [PATCH] net/phy: micrel: Add workaround for bad autoneg Nathan Sullivan
  2015-10-21 19:20 ` Florian Fainelli
@ 2015-10-23  9:57 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2015-10-23  9:57 UTC (permalink / raw)
  To: nathan.sullivan; +Cc: f.fainelli, netdev, linux-kernel

From: Nathan Sullivan <nathan.sullivan@ni.com>
Date: Wed, 21 Oct 2015 14:17:04 -0500

> Very rarely, the KSZ9031 will appear to complete autonegotiation, but
> will drop all traffic afterwards.  When this happens, the idle error
> count will read 0xFF after autonegotiation completes.  Reset the PHY
> when in that state.
> 
> Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com>

Applied, thanks.

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

end of thread, other threads:[~2015-10-23  9:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21 19:17 [PATCH] net/phy: micrel: Add workaround for bad autoneg Nathan Sullivan
2015-10-21 19:20 ` Florian Fainelli
2015-10-21 19:42   ` Nathan Sullivan
2015-10-21 21:46     ` Florian Fainelli
2015-10-23  9:57 ` David Miller

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