From fd408a440f2f1c211f4a8a0988c24cb49cdb9c06 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Wed, 12 Jun 2024 16:11:19 +0100
Subject: [PATCH] lan78xx: Return tx_lpi_timer even if disabled

Disabling tx_lpi or eee should not cause the value of tx_lpi_timer to
be lost, even though it is not useful until they are re-enabled.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 drivers/net/usb/lan78xx.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -1818,15 +1818,34 @@ exit_pm_put:
 static int lan78xx_get_eee(struct net_device *net, struct ethtool_keee *edata)
 {
 	struct lan78xx_net *dev = netdev_priv(net);
+	u32 buf;
+	int ret;
 
-	return phylink_ethtool_get_eee(dev->phylink, edata);
+	ret = phylink_ethtool_get_eee(dev->phylink, edata);
+	if (ret < 0)
+		return ret;
+
+	ret = lan78xx_read_reg(dev, EEE_TX_LPI_REQ_DLY, &buf);
+	if (ret >= 0)
+		edata->tx_lpi_timer = buf;
+	else
+		edata->tx_lpi_timer = 0;
+
+	return 0;
 }
 
 static int lan78xx_set_eee(struct net_device *net, struct ethtool_keee *edata)
 {
 	struct lan78xx_net *dev = netdev_priv(net);
+	u32 buf;
+	int ret;
+
+	ret = phylink_ethtool_set_eee(dev->phylink, edata);
+	if (ret < 0)
+		return ret;
 
-	return phylink_ethtool_set_eee(dev->phylink, edata);
+	buf = (u32)edata->tx_lpi_timer;
+	return lan78xx_write_reg(dev, EEE_TX_LPI_REQ_DLY, buf);
 }
 
 static void lan78xx_get_drvinfo(struct net_device *net,
