mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Doug Berger <opendmb@gmail.com>
To: Russell King - ARM Linux admin <linux@armlinux.org.uk>
Cc: "David S. Miller" <davem@davemloft.net>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 4/4] net: bcmgenet: add support for ethtool flow control
Date: Wed, 13 May 2020 15:00:37 -0700	[thread overview]
Message-ID: <ce0c0cd6-3532-be90-1307-5ccd8e3b02a4@gmail.com> (raw)
In-Reply-To: <20200513095246.GH1551@shell.armlinux.org.uk>

On 5/13/2020 2:52 AM, Russell King - ARM Linux admin wrote:
> On Mon, May 11, 2020 at 05:24:10PM -0700, Doug Berger wrote:
>> diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
>> index 511d553a4d11..788da1ecea0c 100644
>> --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
>> +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
>> @@ -25,6 +25,21 @@
>>  
>>  #include "bcmgenet.h"
>>  
>> +static u32 _flow_control_autoneg(struct phy_device *phydev)
>> +{
>> +	bool tx_pause, rx_pause;
>> +	u32 cmd_bits = 0;
>> +
>> +	phy_get_pause(phydev, &tx_pause, &rx_pause);
>> +
>> +	if (!tx_pause)
>> +		cmd_bits |= CMD_TX_PAUSE_IGNORE;
>> +	if (!rx_pause)
>> +		cmd_bits |= CMD_RX_PAUSE_IGNORE;
>> +
>> +	return cmd_bits;
>> +}
>> +
>>  /* setup netdev link state when PHY link status change and
>>   * update UMAC and RGMII block when link up
>>   */
>> @@ -71,12 +86,20 @@ void bcmgenet_mii_setup(struct net_device *dev)
>>  		cmd_bits <<= CMD_SPEED_SHIFT;
>>  
>>  		/* duplex */
>> -		if (phydev->duplex != DUPLEX_FULL)
>> -			cmd_bits |= CMD_HD_EN;
>> -
>> -		/* pause capability */
>> -		if (!phydev->pause)
>> -			cmd_bits |= CMD_RX_PAUSE_IGNORE | CMD_TX_PAUSE_IGNORE;
>> +		if (phydev->duplex != DUPLEX_FULL) {
>> +			cmd_bits |= CMD_HD_EN |
>> +				CMD_RX_PAUSE_IGNORE | CMD_TX_PAUSE_IGNORE;
> 
> phy_get_pause() already takes account of whether the PHY is in half
> duplex mode.  So:
> 
> 		bool tx_pause, rx_pause;
> 
> 		if (phydev->autoneg && priv->autoneg_pause) {
> 			phy_get_pause(phydev, &tx_pause, &rx_pause);
> 		} else if (phydev->duplex == DUPLEX_FULL) {
> 			tx_pause = priv->tx_pause;
> 			rx_pause = priv->rx_pause;
> 		} else {
> 			tx_pause = false;
> 			rx_pause = false;
> 		}
> 
> 		if (!tx_pause)
> 			cmd_bits |= CMD_TX_PAUSE_IGNORE;
> 		if (!rx_pause)
> 			cmd_bits |= CMD_RX_PAUSE_IGNORE;
> 
> would be entirely sufficient here.
I need to check the duplex to configure the HD bit in the same register
with the pause controls so I am covering both with one compare.

This also includes a bug here that I mentioned in one of my responses to
the first patch of the set. The call to phy_get_pause() should only be
conditioned on phydev->autoneg_pause here.

The idea is that both directions of pause default to on, but if
autoneg_pause is on then phy_get_pause() has an opportunity to disable
any direction if the capability can't be negotiated for that direction.
Finally, the pause feature can be explicitly disabled by the tx_pause
and rx_pause parameters.
> I wonder whether your implementation (which mine follows) is really
> correct though.  Consider this:
> 
> # ethtool -A eth0 autoneg on tx on rx on
> # ethtool -s eth0 autoneg off speed 1000 duplex full
> 
> At this point, what do you expect the resulting pause state to be?  It
> may not be what you actually think it should be - it will be tx and rx
> pause enabled (it's easier to see why that happens with my rewritten
> version of your implementation, which is functionally identical.)
> 
> If we take the view that if link autoneg is disabled, and therefore the
> link partner's advertisement is zero, shouldn't it result in tx and rx
> pause being disabled?
So with the bug fixed as described above, after these commands
autoneg_pause would be on and autoneg would be off. The logic would call
phy_get_pause() which should return tx_pause = rx_pause = false turning
pause off in both directions.


  reply	other threads:[~2020-05-13 21:57 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12  0:24 [PATCH net-next 0/4] Extend phylib implementation of pause support Doug Berger
2020-05-12  0:24 ` [PATCH net-next 1/4] net: ethernet: validate pause autoneg setting Doug Berger
2020-05-12  0:47   ` Andrew Lunn
2020-05-12 18:31     ` Doug Berger
2020-05-12 18:37       ` Andrew Lunn
2020-05-12 18:55       ` Russell King - ARM Linux admin
2020-05-13  3:48         ` Doug Berger
2020-05-13  5:34           ` Russell King - ARM Linux admin
2020-05-13  9:20             ` Russell King - ARM Linux admin
2020-05-13 13:49               ` Andrew Lunn
2020-05-13 14:59                 ` Michal Kubecek
2020-05-13 17:14                 ` Russell King - ARM Linux admin
2020-05-13 22:09                 ` Doug Berger
2020-05-13 21:31               ` Doug Berger
2020-05-13 21:27             ` Doug Berger
2020-05-12 19:08       ` Michal Kubecek
2020-05-13  2:37         ` Doug Berger
2020-05-12  3:16   ` Florian Fainelli
2020-05-12  0:24 ` [PATCH net-next 2/4] net: add autoneg parameter to linkmode_set_pause Doug Berger
2020-05-12  0:24 ` [PATCH net-next 3/4] net: ethernet: introduce phy_set_pause Doug Berger
2020-05-12  0:51   ` Andrew Lunn
2020-05-12 18:46     ` Doug Berger
2020-05-12  3:22   ` Florian Fainelli
2020-05-13  9:42   ` Russell King - ARM Linux admin
2020-05-13 21:39     ` Doug Berger
2020-05-12  0:24 ` [PATCH net-next 4/4] net: bcmgenet: add support for ethtool flow control Doug Berger
2020-05-12  3:24   ` Florian Fainelli
2020-05-13  9:52   ` Russell King - ARM Linux admin
2020-05-13 22:00     ` Doug Berger [this message]
2021-09-26  3:21 [PATCH net-next 0/4] net: bcmgenet: support for " Florian Fainelli
2021-09-26  3:21 ` [PATCH net-next 4/4] net: bcmgenet: add support for ethtool " Florian Fainelli
2021-09-26 14:26   ` Andrew Lunn
2021-10-12 19:13     ` Doug Berger
2021-10-25 17:15       ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ce0c0cd6-3532-be90-1307-5ccd8e3b02a4@gmail.com \
    --to=opendmb@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome