diff mbox series

[net-next,2/2] net: phy: improve phy_set_sym_pause and phy_set_asym_pause

Message ID f5521d12-bc72-8ed7-eeda-888185c6cee6@gmail.com
State Superseded
Delegated to: David Miller
Headers show
Series net: phy: improve pause handling | expand

Commit Message

Heiner Kallweit April 29, 2019, 8:14 p.m. UTC
We should consider what is supported, and we shouldn't mess with
phydev->supported. In addition make sure that phy_set_sym_pause()
clears the asym pause bit in phydev->advertising.
In phy_set_sym_pause() use the same mechanism as in
phy_set_asym_pause() to restart autoneg if needed.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/phy_device.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

Comments

Andrew Lunn April 29, 2019, 9:52 p.m. UTC | #1
> @@ -2078,6 +2089,11 @@ EXPORT_SYMBOL(phy_set_sym_pause);
>  void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>  {
>  	__ETHTOOL_DECLARE_LINK_MODE_MASK(oldadv);
> +	bool asym_pause_supported;
> +
> +	asym_pause_supported =
> +		linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
> +				  phydev->supported);
>  
>  	linkmode_copy(oldadv, phydev->advertising);
>  
> @@ -2086,14 +2102,14 @@ void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>  	linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>  			   phydev->advertising);
>  
> -	if (rx) {
> +	if (rx && asym_pause_supported) {
>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
>  				 phydev->advertising);
>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>  				 phydev->advertising);
>  	}
>  
> -	if (tx)
> +	if (tx && asym_pause_supported)
>  		linkmode_change_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>  				    phydev->advertising);

Hi Heiner

If the PHY only supports Pause, not Asym Pause, i wounder if we should
fall back to Pause here?

     Andrew
Heiner Kallweit April 30, 2019, 5:06 a.m. UTC | #2
On 29.04.2019 23:52, Andrew Lunn wrote:
>> @@ -2078,6 +2089,11 @@ EXPORT_SYMBOL(phy_set_sym_pause);
>>  void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>>  {
>>  	__ETHTOOL_DECLARE_LINK_MODE_MASK(oldadv);
>> +	bool asym_pause_supported;
>> +
>> +	asym_pause_supported =
>> +		linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>> +				  phydev->supported);
>>  
>>  	linkmode_copy(oldadv, phydev->advertising);
>>  
>> @@ -2086,14 +2102,14 @@ void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>>  	linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>  			   phydev->advertising);
>>  
>> -	if (rx) {
>> +	if (rx && asym_pause_supported) {
>>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
>>  				 phydev->advertising);
>>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>  				 phydev->advertising);
>>  	}
>>  
>> -	if (tx)
>> +	if (tx && asym_pause_supported)
>>  		linkmode_change_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>  				    phydev->advertising);
> 
> Hi Heiner
> 
Hi Andrew,

> If the PHY only supports Pause, not Asym Pause, i wounder if we should
> fall back to Pause here?
> 
I wasn't sure about whether a silent fallback is the expected behavior.
Also open is whether we can rely on a set_pause callback having called
phy_validate_pause() before. Another option could be to change the
return type to int and return an error like -EOPNOTSUPP if the requested
mode isn't supported.

>      Andrew
> 
Heiner
Heiner Kallweit May 1, 2019, 7:32 p.m. UTC | #3
On 30.04.2019 07:06, Heiner Kallweit wrote:
> On 29.04.2019 23:52, Andrew Lunn wrote:
>>> @@ -2078,6 +2089,11 @@ EXPORT_SYMBOL(phy_set_sym_pause);
>>>  void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>>>  {
>>>  	__ETHTOOL_DECLARE_LINK_MODE_MASK(oldadv);
>>> +	bool asym_pause_supported;
>>> +
>>> +	asym_pause_supported =
>>> +		linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>> +				  phydev->supported);
>>>  
>>>  	linkmode_copy(oldadv, phydev->advertising);
>>>  
>>> @@ -2086,14 +2102,14 @@ void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
>>>  	linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>>  			   phydev->advertising);
>>>  
>>> -	if (rx) {
>>> +	if (rx && asym_pause_supported) {
>>>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
>>>  				 phydev->advertising);
>>>  		linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>>  				 phydev->advertising);
>>>  	}
>>>  
>>> -	if (tx)
>>> +	if (tx && asym_pause_supported)
>>>  		linkmode_change_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
>>>  				    phydev->advertising);
>>
>> Hi Heiner
>>
> Hi Andrew,
> 
>> If the PHY only supports Pause, not Asym Pause, i wounder if we should
>> fall back to Pause here?
>>
> I wasn't sure about whether a silent fallback is the expected behavior.
> Also open is whether we can rely on a set_pause callback having called
> phy_validate_pause() before. Another option could be to change the
> return type to int and return an error like -EOPNOTSUPP if the requested
> mode isn't supported.
> 
Most drivers call phy_validate_pause() first, this seems to be the
expected pattern. Therefore I will remove patch 2. However there seems to
be an error in phy_validate_pause(), the fix I will submit separately.

>>      Andrew
>>
> Heiner
>
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 544b98b34..eb430f2a8 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2054,13 +2054,24 @@  EXPORT_SYMBOL(phy_support_asym_pause);
 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx,
 		       bool autoneg)
 {
-	linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(oldadv);
+	bool sym_pause_supported;
+
+	sym_pause_supported = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
+						phydev->supported);
+
+	linkmode_copy(oldadv, phydev->advertising);
 
-	if (rx && tx && autoneg)
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->advertising);
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+			   phydev->advertising);
+
+	if (rx && tx && autoneg && sym_pause_supported)
 		linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
-				 phydev->supported);
+				 phydev->advertising);
 
-	linkmode_copy(phydev->advertising, phydev->supported);
+	if (!linkmode_equal(oldadv, phydev->advertising) && phydev->autoneg)
+		phy_start_aneg(phydev);
 }
 EXPORT_SYMBOL(phy_set_sym_pause);
 
@@ -2078,6 +2089,11 @@  EXPORT_SYMBOL(phy_set_sym_pause);
 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
 {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(oldadv);
+	bool asym_pause_supported;
+
+	asym_pause_supported =
+		linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+				  phydev->supported);
 
 	linkmode_copy(oldadv, phydev->advertising);
 
@@ -2086,14 +2102,14 @@  void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx)
 	linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
 			   phydev->advertising);
 
-	if (rx) {
+	if (rx && asym_pause_supported) {
 		linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT,
 				 phydev->advertising);
 		linkmode_set_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
 				 phydev->advertising);
 	}
 
-	if (tx)
+	if (tx && asym_pause_supported)
 		linkmode_change_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
 				    phydev->advertising);