netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
  2023-11-28  9:45 [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available Maxime Chevallier
@ 2023-11-28  9:18 ` Thomas Petazzoni
  2023-11-28 10:20   ` Maxime Chevallier
  2023-11-28 16:37 ` Andrew Lunn
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Petazzoni @ 2023-11-28  9:18 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: davem, netdev, linux-kernel, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni, linux-arm-kernel, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Simon Horman, linux-stm32, alexis.lothore

On Tue, 28 Nov 2023 10:45:37 +0100
Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:

> The SGMII adapter isn't present on all dwmac-socfpga implementations.
> Make sure we don't try to configure it if we don't have this adapter.
> 
> Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver")
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> index ba2ce776bd4d..ae120792e1b6 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
>  {
>  	u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
>  
> -	writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
> +	if (dwmac->sgmii_adapter_base)
> +		writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
>  }
>  
>  static int socfpga_set_phy_mode_common(int phymode, u32 *val)

Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

As a follow-up improvement, there's an open-coded version of
socfpga_sgmii_config() in socfpga_dwmac_fix_mac_speed(), which could be
rewritten as such:

	socfpga_sgmii_config(dwmac, false);

	if (splitter_base) {
		val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG);
		val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK;

		switch (speed) {
		case 1000:
			val |= EMAC_SPLITTER_CTRL_SPEED_1000;
			break;
		case 100:
			val |= EMAC_SPLITTER_CTRL_SPEED_100;
			break;
		case 10:
			val |= EMAC_SPLITTER_CTRL_SPEED_10;
			break;
		default:
			return;
		}
		writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG);
	}

	if (phy_dev)
		socfpga_sgmii_config(dwmac, true);

But of course, that's not a fix so it should be a separate improvement.

Best regards,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com

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

* [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
@ 2023-11-28  9:45 Maxime Chevallier
  2023-11-28  9:18 ` Thomas Petazzoni
  2023-11-28 16:37 ` Andrew Lunn
  0 siblings, 2 replies; 5+ messages in thread
From: Maxime Chevallier @ 2023-11-28  9:45 UTC (permalink / raw)
  To: davem
  Cc: Maxime Chevallier, netdev, linux-kernel, thomas.petazzoni,
	Jakub Kicinski, Eric Dumazet, Paolo Abeni, linux-arm-kernel,
	Alexandre Torgue, Jose Abreu, Maxime Coquelin, Simon Horman,
	linux-stm32, alexis.lothore

The SGMII adapter isn't present on all dwmac-socfpga implementations.
Make sure we don't try to configure it if we don't have this adapter.

Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index ba2ce776bd4d..ae120792e1b6 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
 {
 	u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
 
-	writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
+	if (dwmac->sgmii_adapter_base)
+		writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
 }
 
 static int socfpga_set_phy_mode_common(int phymode, u32 *val)
-- 
2.42.0


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

* Re: [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
  2023-11-28  9:18 ` Thomas Petazzoni
@ 2023-11-28 10:20   ` Maxime Chevallier
  0 siblings, 0 replies; 5+ messages in thread
From: Maxime Chevallier @ 2023-11-28 10:20 UTC (permalink / raw)
  To: Thomas Petazzoni
  Cc: davem, netdev, linux-kernel, Jakub Kicinski, Eric Dumazet,
	Paolo Abeni, linux-arm-kernel, Alexandre Torgue, Jose Abreu,
	Maxime Coquelin, Simon Horman, linux-stm32, alexis.lothore

Hello Thomas,

On Tue, 28 Nov 2023 10:18:41 +0100
Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:

> On Tue, 28 Nov 2023 10:45:37 +0100
> Maxime Chevallier <maxime.chevallier@bootlin.com> wrote:
> 
> > The SGMII adapter isn't present on all dwmac-socfpga implementations.
> > Make sure we don't try to configure it if we don't have this adapter.
> > 
> > Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver")
> > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> > index ba2ce776bd4d..ae120792e1b6 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> > @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
> >  {
> >  	u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
> >  
> > -	writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
> > +	if (dwmac->sgmii_adapter_base)
> > +		writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
> >  }
> >  
> >  static int socfpga_set_phy_mode_common(int phymode, u32 *val)  
> 
> Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> 
> As a follow-up improvement, there's an open-coded version of
> socfpga_sgmii_config() in socfpga_dwmac_fix_mac_speed(), which could be
> rewritten as such:
> 
> 	socfpga_sgmii_config(dwmac, false);
>
> 	if (splitter_base) {
> 		val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG);
> 		val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK;
 [...]

I did saw this, but as this is merely a non-functional rework, I'd
like to target this to net-next, so I'll wait for the fix to land and
follow-up with this rework indeed.

Thanks for the review,

Maxime

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

* Re: [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
  2023-11-28  9:45 [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available Maxime Chevallier
  2023-11-28  9:18 ` Thomas Petazzoni
@ 2023-11-28 16:37 ` Andrew Lunn
  2023-11-28 17:26   ` Maxime Chevallier
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2023-11-28 16:37 UTC (permalink / raw)
  To: Maxime Chevallier
  Cc: davem, netdev, linux-kernel, thomas.petazzoni, Jakub Kicinski,
	Eric Dumazet, Paolo Abeni, linux-arm-kernel, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Simon Horman, linux-stm32,
	alexis.lothore

On Tue, Nov 28, 2023 at 10:45:37AM +0100, Maxime Chevallier wrote:
> The SGMII adapter isn't present on all dwmac-socfpga implementations.
> Make sure we don't try to configure it if we don't have this adapter.

If it does not exist, why even try to call socfpga_sgmii_config()?

It seems like this test needs moving up the call stack. socfpga_gen5_set_phy_mode():

	if (phymode == PHY_INTERFACE_MODE_SGMII)
		if (dwmac->sgmii_adapter_base)
			socfpga_sgmii_config(dwmac, true);
		else
			return -EINVAL;
			
Same in socfpga_gen10_set_phy_mode()?

     Andrew

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

* Re: [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
  2023-11-28 16:37 ` Andrew Lunn
@ 2023-11-28 17:26   ` Maxime Chevallier
  0 siblings, 0 replies; 5+ messages in thread
From: Maxime Chevallier @ 2023-11-28 17:26 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: davem, netdev, linux-kernel, thomas.petazzoni, Jakub Kicinski,
	Eric Dumazet, Paolo Abeni, linux-arm-kernel, Alexandre Torgue,
	Jose Abreu, Maxime Coquelin, Simon Horman, linux-stm32,
	alexis.lothore

Hi Andrew,

On Tue, 28 Nov 2023 17:37:30 +0100
Andrew Lunn <andrew@lunn.ch> wrote:

> On Tue, Nov 28, 2023 at 10:45:37AM +0100, Maxime Chevallier wrote:
> > The SGMII adapter isn't present on all dwmac-socfpga implementations.
> > Make sure we don't try to configure it if we don't have this adapter.  
> 
> If it does not exist, why even try to call socfpga_sgmii_config()?
> 
> It seems like this test needs moving up the call stack. socfpga_gen5_set_phy_mode():
> 
> 	if (phymode == PHY_INTERFACE_MODE_SGMII)
> 		if (dwmac->sgmii_adapter_base)
> 			socfpga_sgmii_config(dwmac, true);
> 		else
> 			return -EINVAL;

I don't have access to a platform with the SGMII adapter available, but
my understanding is that we shouldn't error-out when we don't have the
adapter, as some other component (like the lynx PCS) might be there to
handle that mode.

However you have a valid point in that we might want to check if we
have either an SGMII adapter or a PCS, and if we have none of these we
error-out. Thanks for the suggestion, I'll address that :)

Maxime

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

end of thread, other threads:[~2023-11-28 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-28  9:45 [PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available Maxime Chevallier
2023-11-28  9:18 ` Thomas Petazzoni
2023-11-28 10:20   ` Maxime Chevallier
2023-11-28 16:37 ` Andrew Lunn
2023-11-28 17:26   ` Maxime Chevallier

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