All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips
@ 2022-07-28 13:17 Oleksij Rempel
  2022-07-28 13:25 ` Andrew Lunn
  0 siblings, 1 reply; 5+ messages in thread
From: Oleksij Rempel @ 2022-07-28 13:17 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

Do not try to read not existing or wrong register on chips without
GBIT_SUPPORT.

Fixes: c2e866911e25 ("net: dsa: microchip: break KSZ9477 DSA driver into two files")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index c73bb6d383ad..f6bbd9646c85 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -316,7 +316,13 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 			break;
 		}
 	} else {
-		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
+		/* No gigabit support.  Do not read wrong registers. */
+		if (!(dev->features & GBIT_SUPPORT) &&
+		    (reg == MII_CTRL1000 || reg == MII_ESTATUS ||
+		     reg == MII_STAT1000))
+			val = 0;
+		else
+			ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
 	}
 
 	*data = val;
-- 
2.30.2


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

* Re: [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips
  2022-07-28 13:17 [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips Oleksij Rempel
@ 2022-07-28 13:25 ` Andrew Lunn
  2022-07-28 13:33   ` Oleksij Rempel
  2022-07-29  9:05   ` Oleksij Rempel
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew Lunn @ 2022-07-28 13:25 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Vivien Didelot, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Thu, Jul 28, 2022 at 03:17:25PM +0200, Oleksij Rempel wrote:
> Do not try to read not existing or wrong register on chips without
> GBIT_SUPPORT.
> 
> Fixes: c2e866911e25 ("net: dsa: microchip: break KSZ9477 DSA driver into two files")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz9477.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index c73bb6d383ad..f6bbd9646c85 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -316,7 +316,13 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
>  			break;
>  		}
>  	} else {
> -		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> +		/* No gigabit support.  Do not read wrong registers. */
> +		if (!(dev->features & GBIT_SUPPORT) &&
> +		    (reg == MII_CTRL1000 || reg == MII_ESTATUS ||
> +		     reg == MII_STAT1000))

Does this actually happen?

If i remember this code correctly, it tries to make the oddly looking
PHY look like a normal PHY. phylib is then used to drive the PHY?

If i have that correct, why is phylib trying to read these registers?
It should know there is no 1G support, and should skip them.

   Andrew

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

* Re: [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips
  2022-07-28 13:25 ` Andrew Lunn
@ 2022-07-28 13:33   ` Oleksij Rempel
  2022-07-29  9:05   ` Oleksij Rempel
  1 sibling, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2022-07-28 13:33 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Woojung Huh, UNGLinuxDriver, Vivien Didelot, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Thu, Jul 28, 2022 at 03:25:35PM +0200, Andrew Lunn wrote:
> On Thu, Jul 28, 2022 at 03:17:25PM +0200, Oleksij Rempel wrote:
> > Do not try to read not existing or wrong register on chips without
> > GBIT_SUPPORT.
> > 
> > Fixes: c2e866911e25 ("net: dsa: microchip: break KSZ9477 DSA driver into two files")
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  drivers/net/dsa/microchip/ksz9477.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> > index c73bb6d383ad..f6bbd9646c85 100644
> > --- a/drivers/net/dsa/microchip/ksz9477.c
> > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > @@ -316,7 +316,13 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
> >  			break;
> >  		}
> >  	} else {
> > -		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> > +		/* No gigabit support.  Do not read wrong registers. */
> > +		if (!(dev->features & GBIT_SUPPORT) &&
> > +		    (reg == MII_CTRL1000 || reg == MII_ESTATUS ||
> > +		     reg == MII_STAT1000))
> 
> Does this actually happen?

Yes. I just discovered it after adding regmap ranges validation for
KSZ9893 chip.
> 
> If i remember this code correctly, it tries to make the oddly looking
> PHY look like a normal PHY. phylib is then used to drive the PHY?
> 
> If i have that correct, why is phylib trying to read these registers?
> It should know there is no 1G support, and should skip them.

I didn't investigated it so far. Will try to look deeper tomorrow.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips
  2022-07-28 13:25 ` Andrew Lunn
  2022-07-28 13:33   ` Oleksij Rempel
@ 2022-07-29  9:05   ` Oleksij Rempel
  2022-07-29 13:12     ` Andrew Lunn
  1 sibling, 1 reply; 5+ messages in thread
From: Oleksij Rempel @ 2022-07-29  9:05 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Woojung Huh, UNGLinuxDriver, Vivien Didelot, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Thu, Jul 28, 2022 at 03:25:35PM +0200, Andrew Lunn wrote:
> On Thu, Jul 28, 2022 at 03:17:25PM +0200, Oleksij Rempel wrote:
> > Do not try to read not existing or wrong register on chips without
> > GBIT_SUPPORT.
> > 
> > Fixes: c2e866911e25 ("net: dsa: microchip: break KSZ9477 DSA driver into two files")
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  drivers/net/dsa/microchip/ksz9477.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> > index c73bb6d383ad..f6bbd9646c85 100644
> > --- a/drivers/net/dsa/microchip/ksz9477.c
> > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > @@ -316,7 +316,13 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
> >  			break;
> >  		}
> >  	} else {
> > -		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> > +		/* No gigabit support.  Do not read wrong registers. */
> > +		if (!(dev->features & GBIT_SUPPORT) &&
> > +		    (reg == MII_CTRL1000 || reg == MII_ESTATUS ||
> > +		     reg == MII_STAT1000))
> 
> Does this actually happen?
> 
> If i remember this code correctly, it tries to make the oddly looking
> PHY look like a normal PHY. phylib is then used to drive the PHY?
> 
> If i have that correct, why is phylib trying to read these registers?
> It should know there is no 1G support, and should skip them.

It looks like currently undocumented silicon errata. According to the
data sheet, the BMSR_ESTATEN should not be set BMSR_ERCAP, but this bits
are set.

The question is what is the proper place to implement it. There is same
PHYid for most KSZ switch PHYs, it is no possible to detect it by PHYid.
I have following options:
- add chips specific quirk in the ksz9477_r_phy(), just remove
  BMSR_ESTATEN and BMSR_ERCAP.
- notify about errata over get_phy_flags and implement get_caps quirk in
  the PHY driver.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips
  2022-07-29  9:05   ` Oleksij Rempel
@ 2022-07-29 13:12     ` Andrew Lunn
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2022-07-29 13:12 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Vivien Didelot, Florian Fainelli,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 11:05:13AM +0200, Oleksij Rempel wrote:
> On Thu, Jul 28, 2022 at 03:25:35PM +0200, Andrew Lunn wrote:
> > On Thu, Jul 28, 2022 at 03:17:25PM +0200, Oleksij Rempel wrote:
> > > Do not try to read not existing or wrong register on chips without
> > > GBIT_SUPPORT.
> > > 
> > > Fixes: c2e866911e25 ("net: dsa: microchip: break KSZ9477 DSA driver into two files")
> > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > > ---
> > >  drivers/net/dsa/microchip/ksz9477.c | 8 +++++++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> > > index c73bb6d383ad..f6bbd9646c85 100644
> > > --- a/drivers/net/dsa/microchip/ksz9477.c
> > > +++ b/drivers/net/dsa/microchip/ksz9477.c
> > > @@ -316,7 +316,13 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
> > >  			break;
> > >  		}
> > >  	} else {
> > > -		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> > > +		/* No gigabit support.  Do not read wrong registers. */
> > > +		if (!(dev->features & GBIT_SUPPORT) &&
> > > +		    (reg == MII_CTRL1000 || reg == MII_ESTATUS ||
> > > +		     reg == MII_STAT1000))
> > 
> > Does this actually happen?
> > 
> > If i remember this code correctly, it tries to make the oddly looking
> > PHY look like a normal PHY. phylib is then used to drive the PHY?
> > 
> > If i have that correct, why is phylib trying to read these registers?
> > It should know there is no 1G support, and should skip them.
> 
> It looks like currently undocumented silicon errata. According to the
> data sheet, the BMSR_ESTATEN should not be set BMSR_ERCAP, but this bits
> are set.
> 
> The question is what is the proper place to implement it. There is same
> PHYid for most KSZ switch PHYs, it is no possible to detect it by PHYid.
> I have following options:
> - add chips specific quirk in the ksz9477_r_phy(), just remove
>   BMSR_ESTATEN and BMSR_ERCAP.
> - notify about errata over get_phy_flags and implement get_caps quirk in
>   the PHY driver.

I would do the first. The DSA driver is already doing some emulation
of a normal PHY, so it seems odd to push a workaround into the PHY
driver when it can be part of the emulation.

    Andrew

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

end of thread, other threads:[~2022-07-29 13:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-28 13:17 [PATCH net v1 1/1] net: dsa: microchip: don't try do read Gbit registers on non Gbit chips Oleksij Rempel
2022-07-28 13:25 ` Andrew Lunn
2022-07-28 13:33   ` Oleksij Rempel
2022-07-29  9:05   ` Oleksij Rempel
2022-07-29 13:12     ` Andrew Lunn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.