diff mbox series

[net-next] net: phy: smsc: use phy_clear/set_bits in lan87xx_read_status

Message ID 6c4ca9e8-8b68-f730-7d88-ebb7165f6b1d@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phy: smsc: use phy_clear/set_bits in lan87xx_read_status | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 20 this patch: 20
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 51 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Heiner Kallweit March 8, 2023, 8:11 p.m. UTC
Simplify the code by using phy_clear/sert_bits().

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/smsc.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

Comments

Simon Horman March 9, 2023, 2:31 p.m. UTC | #1
On Wed, Mar 08, 2023 at 09:11:02PM +0100, Heiner Kallweit wrote:
> Simplify the code by using phy_clear/sert_bits().
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/smsc.c | 25 ++++++++++---------------
>  1 file changed, 10 insertions(+), 15 deletions(-)

The phy_clear/sert_bits changes lookg good.
But I have a few nit-pick comments.

> diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
> index af89f3ef1..5965a8afa 100644
> --- a/drivers/net/phy/smsc.c
> +++ b/drivers/net/phy/smsc.c
> @@ -204,17 +204,16 @@ static int lan95xx_config_aneg_ext(struct phy_device *phydev)
>  static int lan87xx_read_status(struct phy_device *phydev)
>  {
>  	struct smsc_phy_priv *priv = phydev->priv;
> +	int rc;
>  
> -	int err = genphy_read_status(phydev);
> +	rc = genphy_read_status(phydev);
> +	if (rc)
> +		return rc;

nit: this seems like a separate change, possibly a fix.

>  
>  	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)
> -			return rc;
> -
> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
> -			       rc & ~MII_LAN83C185_EDPWRDOWN);
> +		rc = phy_clear_bits(phydev, MII_LAN83C185_CTRL_STATUS,
> +				    MII_LAN83C185_EDPWRDOWN);
>  		if (rc < 0)
>  			return rc;
>  
> @@ -222,24 +221,20 @@ static int lan87xx_read_status(struct phy_device *phydev)
>  		 * an actual error.
>  		 */
>  		read_poll_timeout(phy_read, rc,
> -				  rc & MII_LAN83C185_ENERGYON || rc < 0,
> +				  rc < 0 || rc & MII_LAN83C185_ENERGYON,

nit: this also seems like a separate change.

>  				  10000, 640000, true, phydev,
>  				  MII_LAN83C185_CTRL_STATUS);
>  		if (rc < 0)
>  			return rc;
>  
>  		/* Re-enable EDPD */
> -		rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
> -		if (rc < 0)
> -			return rc;
> -
> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
> -			       rc | MII_LAN83C185_EDPWRDOWN);
> +		rc = phy_set_bits(phydev, MII_LAN83C185_CTRL_STATUS,
> +				  MII_LAN83C185_EDPWRDOWN);
>  		if (rc < 0)
>  			return rc;
>  	}
>  
> -	return err;
> +	return 0;
>  }
>  
>  static int smsc_get_sset_count(struct phy_device *phydev)
> -- 
> 2.39.2
>
Heiner Kallweit March 10, 2023, 8:51 p.m. UTC | #2
On 09.03.2023 15:31, Simon Horman wrote:
> On Wed, Mar 08, 2023 at 09:11:02PM +0100, Heiner Kallweit wrote:
>> Simplify the code by using phy_clear/sert_bits().
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  drivers/net/phy/smsc.c | 25 ++++++++++---------------
>>  1 file changed, 10 insertions(+), 15 deletions(-)
> 
> The phy_clear/sert_bits changes lookg good.
> But I have a few nit-pick comments.
> 
>> diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
>> index af89f3ef1..5965a8afa 100644
>> --- a/drivers/net/phy/smsc.c
>> +++ b/drivers/net/phy/smsc.c
>> @@ -204,17 +204,16 @@ static int lan95xx_config_aneg_ext(struct phy_device *phydev)
>>  static int lan87xx_read_status(struct phy_device *phydev)
>>  {
>>  	struct smsc_phy_priv *priv = phydev->priv;
>> +	int rc;
>>  
>> -	int err = genphy_read_status(phydev);
>> +	rc = genphy_read_status(phydev);
>> +	if (rc)
>> +		return rc;
> 
> nit: this seems like a separate change, possibly a fix.
> 
There's no known problem with the current code, so the need for a fix
may be questionable. But you're right, it's a separate change.
IMO it just wasn't worth it to provide it as a separate patch.

>>  
>>  	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)
>> -			return rc;
>> -
>> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
>> -			       rc & ~MII_LAN83C185_EDPWRDOWN);
>> +		rc = phy_clear_bits(phydev, MII_LAN83C185_CTRL_STATUS,
>> +				    MII_LAN83C185_EDPWRDOWN);
>>  		if (rc < 0)
>>  			return rc;
>>  
>> @@ -222,24 +221,20 @@ static int lan87xx_read_status(struct phy_device *phydev)
>>  		 * an actual error.
>>  		 */
>>  		read_poll_timeout(phy_read, rc,
>> -				  rc & MII_LAN83C185_ENERGYON || rc < 0,
>> +				  rc < 0 || rc & MII_LAN83C185_ENERGYON,
> 
> nit: this also seems like a separate change.
> 
Same as for the remark before.

>>  				  10000, 640000, true, phydev,
>>  				  MII_LAN83C185_CTRL_STATUS);
>>  		if (rc < 0)
>>  			return rc;
>>  
>>  		/* Re-enable EDPD */
>> -		rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
>> -		if (rc < 0)
>> -			return rc;
>> -
>> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
>> -			       rc | MII_LAN83C185_EDPWRDOWN);
>> +		rc = phy_set_bits(phydev, MII_LAN83C185_CTRL_STATUS,
>> +				  MII_LAN83C185_EDPWRDOWN);
>>  		if (rc < 0)
>>  			return rc;
>>  	}
>>  
>> -	return err;
>> +	return 0;
>>  }
>>  
>>  static int smsc_get_sset_count(struct phy_device *phydev)
>> -- 
>> 2.39.2
>>
Simon Horman March 13, 2023, noon UTC | #3
On Fri, Mar 10, 2023 at 09:51:37PM +0100, Heiner Kallweit wrote:
> On 09.03.2023 15:31, Simon Horman wrote:
> > On Wed, Mar 08, 2023 at 09:11:02PM +0100, Heiner Kallweit wrote:
> >> Simplify the code by using phy_clear/sert_bits().
> >>
> >> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> >> ---
> >>  drivers/net/phy/smsc.c | 25 ++++++++++---------------
> >>  1 file changed, 10 insertions(+), 15 deletions(-)
> > 
> > The phy_clear/sert_bits changes lookg good.
> > But I have a few nit-pick comments.
> > 
> >> diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
> >> index af89f3ef1..5965a8afa 100644
> >> --- a/drivers/net/phy/smsc.c
> >> +++ b/drivers/net/phy/smsc.c
> >> @@ -204,17 +204,16 @@ static int lan95xx_config_aneg_ext(struct phy_device *phydev)
> >>  static int lan87xx_read_status(struct phy_device *phydev)
> >>  {
> >>  	struct smsc_phy_priv *priv = phydev->priv;
> >> +	int rc;
> >>  
> >> -	int err = genphy_read_status(phydev);
> >> +	rc = genphy_read_status(phydev);
> >> +	if (rc)
> >> +		return rc;
> > 
> > nit: this seems like a separate change, possibly a fix.
> > 
> There's no known problem with the current code, so the need for a fix
> may be questionable. But you're right, it's a separate change.
> IMO it just wasn't worth it to provide it as a separate patch.

Ok, I don't feel strongly about this.
Though perhaps it would be nice to mention in the patch
description if a v2 materialises.

In any case, I am happy with the correctness of this patch.

Signed-off-by: Simon Horman <simon.horman@corigine.com>

> >>  
> >>  	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)
> >> -			return rc;
> >> -
> >> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
> >> -			       rc & ~MII_LAN83C185_EDPWRDOWN);
> >> +		rc = phy_clear_bits(phydev, MII_LAN83C185_CTRL_STATUS,
> >> +				    MII_LAN83C185_EDPWRDOWN);
> >>  		if (rc < 0)
> >>  			return rc;
> >>  
> >> @@ -222,24 +221,20 @@ static int lan87xx_read_status(struct phy_device *phydev)
> >>  		 * an actual error.
> >>  		 */
> >>  		read_poll_timeout(phy_read, rc,
> >> -				  rc & MII_LAN83C185_ENERGYON || rc < 0,
> >> +				  rc < 0 || rc & MII_LAN83C185_ENERGYON,
> > 
> > nit: this also seems like a separate change.
> > 
> Same as for the remark before.

Ack.

> >>  				  10000, 640000, true, phydev,
> >>  				  MII_LAN83C185_CTRL_STATUS);
> >>  		if (rc < 0)
> >>  			return rc;
> >>  
> >>  		/* Re-enable EDPD */
> >> -		rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
> >> -		if (rc < 0)
> >> -			return rc;
> >> -
> >> -		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
> >> -			       rc | MII_LAN83C185_EDPWRDOWN);
> >> +		rc = phy_set_bits(phydev, MII_LAN83C185_CTRL_STATUS,
> >> +				  MII_LAN83C185_EDPWRDOWN);
> >>  		if (rc < 0)
> >>  			return rc;
> >>  	}
> >>  
> >> -	return err;
> >> +	return 0;
> >>  }
> >>  
> >>  static int smsc_get_sset_count(struct phy_device *phydev)
> >> -- 
> >> 2.39.2
> >>
>
diff mbox series

Patch

diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index af89f3ef1..5965a8afa 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -204,17 +204,16 @@  static int lan95xx_config_aneg_ext(struct phy_device *phydev)
 static int lan87xx_read_status(struct phy_device *phydev)
 {
 	struct smsc_phy_priv *priv = phydev->priv;
+	int rc;
 
-	int err = genphy_read_status(phydev);
+	rc = genphy_read_status(phydev);
+	if (rc)
+		return rc;
 
 	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)
-			return rc;
-
-		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
-			       rc & ~MII_LAN83C185_EDPWRDOWN);
+		rc = phy_clear_bits(phydev, MII_LAN83C185_CTRL_STATUS,
+				    MII_LAN83C185_EDPWRDOWN);
 		if (rc < 0)
 			return rc;
 
@@ -222,24 +221,20 @@  static int lan87xx_read_status(struct phy_device *phydev)
 		 * an actual error.
 		 */
 		read_poll_timeout(phy_read, rc,
-				  rc & MII_LAN83C185_ENERGYON || rc < 0,
+				  rc < 0 || rc & MII_LAN83C185_ENERGYON,
 				  10000, 640000, true, phydev,
 				  MII_LAN83C185_CTRL_STATUS);
 		if (rc < 0)
 			return rc;
 
 		/* Re-enable EDPD */
-		rc = phy_read(phydev, MII_LAN83C185_CTRL_STATUS);
-		if (rc < 0)
-			return rc;
-
-		rc = phy_write(phydev, MII_LAN83C185_CTRL_STATUS,
-			       rc | MII_LAN83C185_EDPWRDOWN);
+		rc = phy_set_bits(phydev, MII_LAN83C185_CTRL_STATUS,
+				  MII_LAN83C185_EDPWRDOWN);
 		if (rc < 0)
 			return rc;
 	}
 
-	return err;
+	return 0;
 }
 
 static int smsc_get_sset_count(struct phy_device *phydev)