netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	andrew@lunn.ch, horms@kernel.org, hkallweit1@gmail.com,
	richardcochran@gmail.com, rdunlap@infradead.org,
	Bryan.Whitehead@microchip.com, edumazet@google.com,
	pabeni@redhat.com, linux-kernel@vger.kernel.org,
	UNGLinuxDriver@microchip.com
Subject: Re: [PATCH net-next V3 4/4] net: lan743x: Add support to ethtool phylink get and set settings
Date: Tue, 30 Jul 2024 16:11:11 +0100	[thread overview]
Message-ID: <ZqkCj9gENW5ILWED@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240730140619.80650-5-Raju.Lakkaraju@microchip.com>

On Tue, Jul 30, 2024 at 07:36:19PM +0530, Raju Lakkaraju wrote:
> diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c
> index 3a63ec091413..a649ea7442a4 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c
> +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c
> @@ -1058,61 +1058,48 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev,
>  				   struct ethtool_keee *eee)
>  {
>  	struct lan743x_adapter *adapter = netdev_priv(netdev);
> -	struct phy_device *phydev = netdev->phydev;
> -	u32 buf;
> -	int ret;
> -
> -	if (!phydev)
> -		return -EIO;
> -	if (!phydev->drv) {
> -		netif_err(adapter, drv, adapter->netdev,
> -			  "Missing PHY Driver\n");
> -		return -EIO;
> -	}
>  
> -	ret = phy_ethtool_get_eee(phydev, eee);
> -	if (ret < 0)
> -		return ret;
> -
> -	buf = lan743x_csr_read(adapter, MAC_CR);
> -	if (buf & MAC_CR_EEE_EN_) {
> -		/* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */
> -		buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
> -		eee->tx_lpi_timer = buf;
> -	} else {
> -		eee->tx_lpi_timer = 0;
> -	}
> +	eee->tx_lpi_timer = lan743x_csr_read(adapter,
> +					     MAC_EEE_TX_LPI_REQ_DLY_CNT);
> +	eee->eee_enabled = adapter->eee_enabled;
> +	eee->eee_active = adapter->eee_active;
> +	eee->tx_lpi_enabled = adapter->tx_lpi_enabled;

You really need to start paying attention to the commits other people
make as a result of development to other parts of the kernel.

First, see:

commit ef460a8986fa0dae1cdcb158a06127f7af27c92d
Author: Andrew Lunn <andrew@lunn.ch>
Date:   Sat Apr 6 15:16:00 2024 -0500

    net: lan743x: Fixup EEE

and note that the assignment of eee->eee_enabled, eee->eee_active, and
eee->tx_lpi_enabled were all removed.

Next...

>  
> -	return 0;
> +	return phylink_ethtool_get_eee(adapter->phylink, eee);

phylink_ethtool_get_eee() will call phy_ethtool_get_eee(), which
in turn calls genphy_c45_ethtool_get_eee() and eeecfg_to_eee().

genphy_c45_ethtool_get_eee() will do this:

        data->eee_enabled = is_enabled;
        data->eee_active = ret;

thus overwriting your assignment to eee->eee_enabled and
eee->eee_active.

eeecfg_to_eee() will overwrite eee->tx_lpi_enabled and
eee->eee_enabled.

Thus, writing to these fields and then calling
phylink_ethtool_get_eee() results in these fields being overwritten.

>  static int lan743x_ethtool_set_eee(struct net_device *netdev,
>  				   struct ethtool_keee *eee)
>  {
> -	struct lan743x_adapter *adapter;
> -	struct phy_device *phydev;
> -	u32 buf = 0;
> +	struct lan743x_adapter *adapter = netdev_priv(netdev);
>  
> -	if (!netdev)
> -		return -EINVAL;
> -	adapter = netdev_priv(netdev);
> -	if (!adapter)
> -		return -EINVAL;
> -	phydev = netdev->phydev;
> -	if (!phydev)
> -		return -EIO;
> -	if (!phydev->drv) {
> -		netif_err(adapter, drv, adapter->netdev,
> -			  "Missing PHY Driver\n");
> -		return -EIO;
> -	}
> +	if (eee->tx_lpi_enabled)
> +		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT,
> +				  eee->tx_lpi_timer);
> +	else
> +		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, 0);
>  
> -	if (eee->eee_enabled) {
> -		buf = (u32)eee->tx_lpi_timer;
> -		lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
> -	}
> +	adapter->eee_enabled = eee->eee_enabled;
> +	adapter->tx_lpi_enabled = eee->tx_lpi_enabled;

Given that phylib stores these and overwrites your copies in the get_eee
method above, do you need to store these?

> @@ -3013,7 +3025,12 @@ static void lan743x_phylink_mac_link_down(struct phylink_config *config,
>  					  unsigned int link_an_mode,
>  					  phy_interface_t interface)
>  {
> +	struct net_device *netdev = to_net_dev(config->dev);
> +	struct lan743x_adapter *adapter = netdev_priv(netdev);
> +
>  	netif_tx_stop_all_queues(to_net_dev(config->dev));
> +	adapter->eee_active = false;

phylib tracks this for you.

> +	lan743x_set_eee(adapter, false);
>  }
>  
>  static void lan743x_phylink_mac_link_up(struct phylink_config *config,
> @@ -3055,6 +3072,14 @@ static void lan743x_phylink_mac_link_up(struct phylink_config *config,
>  					  cap & FLOW_CTRL_TX,
>  					  cap & FLOW_CTRL_RX);
>  
> +	if (phydev && adapter->eee_enabled) {
> +		bool enable;
> +
> +		adapter->eee_active = phy_init_eee(phydev, false) >= 0;
> +		enable = adapter->eee_active && adapter->tx_lpi_enabled;

No need. Your enable should be conditional on phydev->enable_tx_lpi
here. See Andrew's commit and understand his changes, rather than
just ignoring Andrew's work and continuing with your old pattern of
EEE support. Things have moved forward.

Thanks.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  reply	other threads:[~2024-07-30 15:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-30 14:06 [PATCH net-next V3 0/4] Add support to PHYLINK for LAN743x/PCI11x1x chips Raju Lakkaraju
2024-07-30 14:06 ` [PATCH net-next V3 1/4] net: lan743x: Create separate PCS power reset function Raju Lakkaraju
2024-07-30 14:06 ` [PATCH net-next V3 2/4] net: lan743x: Create separate Link Speed Duplex state function Raju Lakkaraju
2024-07-30 14:06 ` [PATCH net-next V3 3/4] net: lan743x: Migrate phylib to phylink Raju Lakkaraju
2024-07-30 14:56   ` Russell King (Oracle)
2024-08-01 11:03     ` Raju Lakkaraju
2024-08-01 16:27       ` Russell King (Oracle)
2024-08-01 23:46         ` Ronnie.Kunin
2024-08-02  8:37           ` Russell King (Oracle)
2024-08-08 20:23             ` Ronnie.Kunin
2024-08-08 21:07               ` Russell King (Oracle)
2024-08-16 17:38                 ` Raju Lakkaraju
2024-08-17 11:42                   ` Russell King (Oracle)
2024-07-30 14:06 ` [PATCH net-next V3 4/4] net: lan743x: Add support to ethtool phylink get and set settings Raju Lakkaraju
2024-07-30 15:11   ` Russell King (Oracle) [this message]
2024-08-01 11:05     ` Raju Lakkaraju

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=ZqkCj9gENW5ILWED@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=Bryan.Whitehead@microchip.com \
    --cc=Raju.Lakkaraju@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).