All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: phy: at803x: disable WOL at probe
@ 2022-05-25 10:36 Viorel Suman (OSS)
  2022-05-27  4:00 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Viorel Suman (OSS) @ 2022-05-25 10:36 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Luo Jie, netdev,
	linux-kernel
  Cc: linux-imx, Viorel Suman

From: Viorel Suman <viorel.suman@nxp.com>

Before 7beecaf7d507b ("net: phy: at803x: improve the WOL feature") patch
"at803x_get_wol" implementation used AT803X_INTR_ENABLE_WOL value to set
WAKE_MAGIC flag, and now AT803X_WOL_EN value is used for the same purpose.
The problem here is that the value of these two bits is different after
hardware reset: AT803X_INTR_ENABLE_WOL=0 after hardware reset, but
AT803X_WOL_EN=1. So now, if called right after boot, "at803x_get_wol" will
set WAKE_MAGIC flag, even if WOL function is not enabled via
"at803x_set_wol" call. The patch disables WOL function on probe using
"at803x_set_wol" call thus the behavior is consistent.

Fixes: 7beecaf7d507b ("net: phy: at803x: improve the WOL feature")
Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
---
 drivers/net/phy/at803x.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index 73926006d319..6277d1b1d814 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -443,10 +443,10 @@ static int at803x_set_wol(struct phy_device *phydev,
 		AT803X_LOC_MAC_ADDR_0_15_OFFSET,
 	};
 
-	if (!ndev)
-		return -ENODEV;
-
 	if (wol->wolopts & WAKE_MAGIC) {
+		if (!ndev)
+			return -ENODEV;
+
 		mac = (const u8 *) ndev->dev_addr;
 
 		if (!is_valid_ether_addr(mac))
@@ -857,6 +857,9 @@ static int at803x_probe(struct phy_device *phydev)
 	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
 		int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
 		int mode_cfg;
+		struct ethtool_wolinfo wol = {
+			.wolopts = 0,
+		};
 
 		if (ccr < 0)
 			goto err;
@@ -872,6 +875,13 @@ static int at803x_probe(struct phy_device *phydev)
 			priv->is_fiber = true;
 			break;
 		}
+
+		/* Disable WOL by default */
+		ret = at803x_set_wol(phydev, &wol);
+		if (ret < 0) {
+			phydev_err(phydev, "failed to disable WOL on probe: %d\n", ret);
+			return ret;
+		}
 	}
 
 	return 0;
-- 
2.35.3


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

* Re: [PATCH] net: phy: at803x: disable WOL at probe
  2022-05-25 10:36 [PATCH] net: phy: at803x: disable WOL at probe Viorel Suman (OSS)
@ 2022-05-27  4:00 ` Jakub Kicinski
  2022-05-27  9:50   ` Viorel Suman
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2022-05-27  4:00 UTC (permalink / raw)
  To: Viorel Suman (OSS)
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Paolo Abeni, Luo Jie, netdev, linux-kernel,
	linux-imx, Viorel Suman

On Wed, 25 May 2022 13:36:57 +0300 Viorel Suman (OSS) wrote:
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index 73926006d319..6277d1b1d814 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -443,10 +443,10 @@ static int at803x_set_wol(struct phy_device *phydev,
>  		AT803X_LOC_MAC_ADDR_0_15_OFFSET,
>  	};
>  
> -	if (!ndev)
> -		return -ENODEV;
> -
>  	if (wol->wolopts & WAKE_MAGIC) {
> +		if (!ndev)
> +			return -ENODEV;

Please move the ndev variable into the scope.
It'll make it clear that it can't be used elsewhere
in this function.

>  		mac = (const u8 *) ndev->dev_addr;
>  
>  		if (!is_valid_ether_addr(mac))
> @@ -857,6 +857,9 @@ static int at803x_probe(struct phy_device *phydev)
>  	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
>  		int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
>  		int mode_cfg;
> +		struct ethtool_wolinfo wol = {
> +			.wolopts = 0,
> +		};
>  
>  		if (ccr < 0)
>  			goto err;
> @@ -872,6 +875,13 @@ static int at803x_probe(struct phy_device *phydev)
>  			priv->is_fiber = true;
>  			break;
>  		}
> +
> +		/* Disable WOL by default */
> +		ret = at803x_set_wol(phydev, &wol);
> +		if (ret < 0) {
> +			phydev_err(phydev, "failed to disable WOL on probe: %d\n", ret);
> +			return ret;

Don't you need to goto err; here?

> +		}
>  	}
>  
>  	return 0;

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

* Re: [PATCH] net: phy: at803x: disable WOL at probe
  2022-05-27  4:00 ` Jakub Kicinski
@ 2022-05-27  9:50   ` Viorel Suman
  0 siblings, 0 replies; 3+ messages in thread
From: Viorel Suman @ 2022-05-27  9:50 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Viorel Suman (OSS),
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Paolo Abeni, Luo Jie, netdev, linux-kernel,
	dl-linux-imx

On 22-05-26 21:00:44, Jakub Kicinski wrote:
> On Wed, 25 May 2022 13:36:57 +0300 Viorel Suman (OSS) wrote:
> > diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> > index 73926006d319..6277d1b1d814 100644
> > --- a/drivers/net/phy/at803x.c
> > +++ b/drivers/net/phy/at803x.c
> > @@ -443,10 +443,10 @@ static int at803x_set_wol(struct phy_device *phydev,
> >  		AT803X_LOC_MAC_ADDR_0_15_OFFSET,
> >  	};
> >  
> > -	if (!ndev)
> > -		return -ENODEV;
> > -
> >  	if (wol->wolopts & WAKE_MAGIC) {
> > +		if (!ndev)
> > +			return -ENODEV;
> 
> Please move the ndev variable into the scope.
> It'll make it clear that it can't be used elsewhere
> in this function.

Thank you for review, done in v2.

> 
> >  		mac = (const u8 *) ndev->dev_addr;
> >  
> >  		if (!is_valid_ether_addr(mac))
> > @@ -857,6 +857,9 @@ static int at803x_probe(struct phy_device *phydev)
> >  	if (phydev->drv->phy_id == ATH8031_PHY_ID) {
> >  		int ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
> >  		int mode_cfg;
> > +		struct ethtool_wolinfo wol = {
> > +			.wolopts = 0,
> > +		};
> >  
> >  		if (ccr < 0)
> >  			goto err;
> > @@ -872,6 +875,13 @@ static int at803x_probe(struct phy_device *phydev)
> >  			priv->is_fiber = true;
> >  			break;
> >  		}
> > +
> > +		/* Disable WOL by default */
> > +		ret = at803x_set_wol(phydev, &wol);
> > +		if (ret < 0) {
> > +			phydev_err(phydev, "failed to disable WOL on probe: %d\n", ret);
> > +			return ret;
> 
> Don't you need to goto err; here?

Missed err section indeed, thanks. Fixed in v2.

> 
> > +		}
> >  	}
> >  
> >  	return 0;

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

end of thread, other threads:[~2022-05-27  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 10:36 [PATCH] net: phy: at803x: disable WOL at probe Viorel Suman (OSS)
2022-05-27  4:00 ` Jakub Kicinski
2022-05-27  9:50   ` Viorel Suman

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.