linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!)
@ 2025-01-13 11:45 Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 1/9] net: stmmac: rename stmmac_disable_sw_eee_mode() Russell King (Oracle)
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:45 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: lexandre Torgue, Andrew Lunn, David S. Miller, Eric Dumazet,
	Eric Woudstra, Jakub Kicinski, linux-arm-kernel, linux-stm32,
	Maxime Coquelin, netdev, Paolo Abeni

Hi,

This series continues the EEE cleanup of the stmmac driver, and
includes one fix.

As mentioned in the previous series, I wasn't entirely happy with the
"stmmac_disable_sw_eee_mode" name, so the first patch renames this to
"stmmac_stop_sw_lpi" instead, which I think better describes what this
function is doing - stopping the transmit of the LPI state because we
have a packet ot send.

Patch 2 corrects the priv->eee_sw_timer_en flag when EEE has been
disabled. Currently upon disable, priv->eee_enabled is set false,
but through the weird logic that was present prior to the previous
series, priv->eee_sw_timer_en was set true. This behaviour was kept
as the previous series was cleanup, not fixes. This patch fixes this.

Having fixed priv->eee_sw_timer_en to actually indicate whether
software timed EEE mode is being used, it becomes no longer necessary
to test priv->eee_enabled in addition. Patch 3 removes the redundant
test. Patch 4 also uses priv->eee_sw_timer_en before manipulating the
software EEE state in the suspend method rather than using
priv->eee_enabled, which brings consistency.

Patch 5 provides stmmac_try_to_start_sw_lpi() which complements
stmmac_stop_sw_lpi(), and allows us to move duplicated code into one
location.

Patch 6 splits stmmac_enable_eee_mode() - one part of this function
tests whether there are any queues that have unfinished work (in
other words are busy). Separate out this code into a separate function.

Patch 7 also splits out the mod_timer() for the software EEE timer
intoi a seperate function (the reason will be in patch 9.)

Patch 8 merges the remains of stmmac_enable_eee_mode() into
stmmac_try_to_start_sw_lpi().

Patch 9 fixes the delay between transmit and entering LPI. Currently,
when cleaning the transmit queues, if we discover that we have finished
cleaning up all queues, we immediately instruct the hardware to enter
LPI mode without waiting for the LPI timer. However, we should wait for
the LPI timer to expire. Therefore, the transmit cleanup path needs
to call stmmac_restart_sw_lpi_timer() instead of
stmmac_try_to_start_sw_lpi().

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 58 +++++++++++++----------
 1 file changed, 33 insertions(+), 25 deletions(-)

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH net-next 1/9] net: stmmac: rename stmmac_disable_sw_eee_mode()
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
@ 2025-01-13 11:45 ` Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 2/9] net: stmmac: correct priv->eee_sw_timer_en setting Russell King (Oracle)
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:45 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

stmmac_disable_sw_eee_mode() was not a good choice for this functions
purpose - which is to stop transmitting LPI because we want to send a
packet. Rename it to stmmac_stop_sw_lpi().

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 58b013528dea..8130b0f614d8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -427,12 +427,11 @@ static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
 }
 
 /**
- * stmmac_disable_sw_eee_mode - disable and exit from LPI mode
+ * stmmac_stop_sw_lpi - stop transmitting LPI
  * @priv: driver private structure
- * Description: this function is to exit and disable EEE in case of
- * LPI state is true. This is called by the xmit.
+ * Description: When using software-controlled LPI, stop transmitting LPI state.
  */
-static void stmmac_disable_sw_eee_mode(struct stmmac_priv *priv)
+static void stmmac_stop_sw_lpi(struct stmmac_priv *priv)
 {
 	stmmac_reset_eee_mode(priv, priv->hw);
 	del_timer_sync(&priv->eee_ctrl_timer);
@@ -4497,7 +4496,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 	first_tx = tx_q->cur_tx;
 
 	if (priv->tx_path_in_lpi_mode && priv->eee_sw_timer_en)
-		stmmac_disable_sw_eee_mode(priv);
+		stmmac_stop_sw_lpi(priv);
 
 	/* Manage oversized TCP frames for GMAC4 device */
 	if (skb_is_gso(skb) && priv->tso) {
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 2/9] net: stmmac: correct priv->eee_sw_timer_en setting
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 1/9] net: stmmac: rename stmmac_disable_sw_eee_mode() Russell King (Oracle)
@ 2025-01-13 11:45 ` Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 3/9] net: stmmac: simplify TX cleanup decision for ending sw LPI mode Russell King (Oracle)
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:45 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

If we are disabling EEE/LPI, then we should not be enabling software
mode. The only time when we should is if EEE is active, and we are
wanting to use software-timed EEE mode.

Therefore, in the disable path of stmmac_eee_init(), ensure that
priv->eee_sw_timer_en is set false as we are going to be calling
del_timer_sync() on the timer.

This will allow us to simplify some fast-path tests in later patches.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8130b0f614d8..f1e416b03349 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -478,7 +478,7 @@ static void stmmac_eee_init(struct stmmac_priv *priv, bool active)
 	if (!priv->eee_active) {
 		if (priv->eee_enabled) {
 			netdev_dbg(priv->dev, "disable EEE\n");
-			priv->eee_sw_timer_en = true;
+			priv->eee_sw_timer_en = false;
 			stmmac_disable_hw_lpi_timer(priv);
 			del_timer_sync(&priv->eee_ctrl_timer);
 			stmmac_set_eee_timer(priv, priv->hw, 0,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 3/9] net: stmmac: simplify TX cleanup decision for ending sw LPI mode
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 1/9] net: stmmac: rename stmmac_disable_sw_eee_mode() Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 2/9] net: stmmac: correct priv->eee_sw_timer_en setting Russell King (Oracle)
@ 2025-01-13 11:45 ` Russell King (Oracle)
  2025-01-13 11:45 ` [PATCH net-next 4/9] net: stmmac: check priv->eee_sw_timer_en in suspend path Russell King (Oracle)
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:45 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

As mentioned in "net: stmmac: correct priv->eee_sw_timer_en setting",
we can simplify some fast-path tests.

The transmit cleaning path checks whether EEE is enabled, the transmit
path is not in LPI mode, and that we're using software timed mode.
Since the above mentioned commit, checking whether EEE is enabled is
no longer necessary as priv->eee_sw_timer_en will be false when EEE is
disabled. Simplify this test.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f1e416b03349..e8667848e0ee 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2782,8 +2782,7 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue,
 			xmits = budget;
 	}
 
-	if (priv->eee_enabled && !priv->tx_path_in_lpi_mode &&
-	    priv->eee_sw_timer_en) {
+	if (priv->eee_sw_timer_en && !priv->tx_path_in_lpi_mode) {
 		if (stmmac_enable_eee_mode(priv))
 			mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
 	}
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 4/9] net: stmmac: check priv->eee_sw_timer_en in suspend path
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (2 preceding siblings ...)
  2025-01-13 11:45 ` [PATCH net-next 3/9] net: stmmac: simplify TX cleanup decision for ending sw LPI mode Russell King (Oracle)
@ 2025-01-13 11:45 ` Russell King (Oracle)
  2025-01-13 11:46 ` [PATCH net-next 5/9] net: stmmac: add stmmac_try_to_start_sw_lpi() Russell King (Oracle)
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:45 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

The suspend path uses priv->eee_enabled when cleaning up the software
timed LPI mode. Use priv->eee_sw_timer_en instead so we're consistently
using a single control for software-based timer handling.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e8667848e0ee..26ff1ded4e3d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7719,7 +7719,7 @@ int stmmac_suspend(struct device *dev)
 	for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++)
 		hrtimer_cancel(&priv->dma_conf.tx_queue[chan].txtimer);
 
-	if (priv->eee_enabled) {
+	if (priv->eee_sw_timer_en) {
 		priv->tx_path_in_lpi_mode = false;
 		del_timer_sync(&priv->eee_ctrl_timer);
 	}
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 5/9] net: stmmac: add stmmac_try_to_start_sw_lpi()
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (3 preceding siblings ...)
  2025-01-13 11:45 ` [PATCH net-next 4/9] net: stmmac: check priv->eee_sw_timer_en in suspend path Russell King (Oracle)
@ 2025-01-13 11:46 ` Russell King (Oracle)
  2025-01-13 11:46 ` [PATCH net-next 6/9] net: stmmac: provide stmmac_eee_tx_busy() Russell King (Oracle)
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:46 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

There are two places which call stmmac_enable_eee_mode() and follow it
immediately by modifying the expiry of priv->eee_ctrl_timer. Both code
paths are trying to enable LPI mode. Remove this duplication by
providing a function for this.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c    | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 26ff1ded4e3d..2bb61757e320 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -426,6 +426,13 @@ static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
 	return 0;
 }
 
+static void stmmac_try_to_start_sw_lpi(struct stmmac_priv *priv)
+{
+	if (stmmac_enable_eee_mode(priv))
+		mod_timer(&priv->eee_ctrl_timer,
+			  STMMAC_LPI_T(priv->tx_lpi_timer));
+}
+
 /**
  * stmmac_stop_sw_lpi - stop transmitting LPI
  * @priv: driver private structure
@@ -449,8 +456,7 @@ static void stmmac_eee_ctrl_timer(struct timer_list *t)
 {
 	struct stmmac_priv *priv = from_timer(priv, t, eee_ctrl_timer);
 
-	if (stmmac_enable_eee_mode(priv))
-		mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
+	stmmac_try_to_start_sw_lpi(priv);
 }
 
 /**
@@ -2782,10 +2788,8 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue,
 			xmits = budget;
 	}
 
-	if (priv->eee_sw_timer_en && !priv->tx_path_in_lpi_mode) {
-		if (stmmac_enable_eee_mode(priv))
-			mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
-	}
+	if (priv->eee_sw_timer_en && !priv->tx_path_in_lpi_mode)
+		stmmac_try_to_start_sw_lpi(priv);
 
 	/* We still have pending packets, let's call for a new scheduling */
 	if (tx_q->dirty_tx != tx_q->cur_tx)
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 6/9] net: stmmac: provide stmmac_eee_tx_busy()
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (4 preceding siblings ...)
  2025-01-13 11:46 ` [PATCH net-next 5/9] net: stmmac: add stmmac_try_to_start_sw_lpi() Russell King (Oracle)
@ 2025-01-13 11:46 ` Russell King (Oracle)
  2025-01-13 11:46 ` [PATCH net-next 7/9] net: stmmac: provide function for restarting sw LPI timer Russell King (Oracle)
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:46 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

Extract the code which checks whether there's still work to do on any
of the stmmac transmit queues. This will allow us to combine
stmmac_enable_eee_mode() with stmmac_try_to_start_sw_lpi() in the
next patch.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 24 ++++++++++++-------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 2bb61757e320..ddbcbe3886c0 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -400,13 +400,7 @@ static void stmmac_enable_hw_lpi_timer(struct stmmac_priv *priv)
 	stmmac_set_eee_lpi_timer(priv, priv->hw, priv->tx_lpi_timer);
 }
 
-/**
- * stmmac_enable_eee_mode - check and enter in LPI mode
- * @priv: driver private structure
- * Description: this function is to verify and enter in LPI mode in case of
- * EEE.
- */
-static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
+static bool stmmac_eee_tx_busy(struct stmmac_priv *priv)
 {
 	u32 tx_cnt = priv->plat->tx_queues_to_use;
 	u32 queue;
@@ -416,9 +410,23 @@ static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
 		struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
 
 		if (tx_q->dirty_tx != tx_q->cur_tx)
-			return -EBUSY; /* still unfinished work */
+			return true; /* still unfinished work */
 	}
 
+	return false;
+}
+
+/**
+ * stmmac_enable_eee_mode - check and enter in LPI mode
+ * @priv: driver private structure
+ * Description: this function is to verify and enter in LPI mode in case of
+ * EEE.
+ */
+static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
+{
+	if (stmmac_eee_tx_busy(priv))
+		return -EBUSY; /* still unfinished work */
+
 	/* Check and enter in LPI mode */
 	if (!priv->tx_path_in_lpi_mode)
 		stmmac_set_eee_mode(priv, priv->hw,
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 7/9] net: stmmac: provide function for restarting sw LPI timer
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (5 preceding siblings ...)
  2025-01-13 11:46 ` [PATCH net-next 6/9] net: stmmac: provide stmmac_eee_tx_busy() Russell King (Oracle)
@ 2025-01-13 11:46 ` Russell King (Oracle)
  2025-01-13 11:46 ` [PATCH net-next 8/9] net: stmmac: combine stmmac_enable_eee_mode() Russell King (Oracle)
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:46 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

Provide a function that encapsulates restarting the software LPI
timer when we have determined that the transmit path is busy, or
whether the EEE parameters have changed.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ddbcbe3886c0..677a2172a85f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -416,6 +416,11 @@ static bool stmmac_eee_tx_busy(struct stmmac_priv *priv)
 	return false;
 }
 
+static void stmmac_restart_sw_lpi_timer(struct stmmac_priv *priv)
+{
+	mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(priv->tx_lpi_timer));
+}
+
 /**
  * stmmac_enable_eee_mode - check and enter in LPI mode
  * @priv: driver private structure
@@ -437,8 +442,7 @@ static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
 static void stmmac_try_to_start_sw_lpi(struct stmmac_priv *priv)
 {
 	if (stmmac_enable_eee_mode(priv))
-		mod_timer(&priv->eee_ctrl_timer,
-			  STMMAC_LPI_T(priv->tx_lpi_timer));
+		stmmac_restart_sw_lpi_timer(priv);
 }
 
 /**
@@ -526,8 +530,7 @@ static void stmmac_eee_init(struct stmmac_priv *priv, bool active)
 		/* Use software LPI mode */
 		priv->eee_sw_timer_en = true;
 		stmmac_disable_hw_lpi_timer(priv);
-		mod_timer(&priv->eee_ctrl_timer,
-			  STMMAC_LPI_T(priv->tx_lpi_timer));
+		stmmac_restart_sw_lpi_timer(priv);
 	}
 
 	priv->eee_enabled = true;
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 8/9] net: stmmac: combine stmmac_enable_eee_mode()
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (6 preceding siblings ...)
  2025-01-13 11:46 ` [PATCH net-next 7/9] net: stmmac: provide function for restarting sw LPI timer Russell King (Oracle)
@ 2025-01-13 11:46 ` Russell King (Oracle)
  2025-01-13 11:46 ` [PATCH net-next 9/9] net: stmmac: restart LPI timer after cleaning transmit descriptors Russell King (Oracle)
  2025-01-15  2:50 ` [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) patchwork-bot+netdevbpf
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:46 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

Combine stmmac_enable_eee_mode() with stmmac_try_to_start_sw_lpi()
which makes the code easier to read and the flow more logical. We
can now trivially see that if the transmit queues are busy, we
(re-)start the eee_ctrl_timer. Otherwise, if the transmit path is
not already in LPI mode, we ask the hardware to enter LPI mode.

I believe that now we can see better what is going on here, this
shows that there is a bug with the software LPI timer implementation.

The LPI timer is supposed to define how long after the last
transmittion completed before we start signalling LPI. However,
this code structure shows that if all transmit queues are empty,
and stmmac_try_to_start_sw_lpi() is called immediately after cleaning
the transmit queue, we will instruct the hardware to start signalling
LPI immediately.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c   | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 677a2172a85f..72f270013086 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -422,27 +422,22 @@ static void stmmac_restart_sw_lpi_timer(struct stmmac_priv *priv)
 }
 
 /**
- * stmmac_enable_eee_mode - check and enter in LPI mode
+ * stmmac_try_to_start_sw_lpi - check and enter in LPI mode
  * @priv: driver private structure
  * Description: this function is to verify and enter in LPI mode in case of
  * EEE.
  */
-static int stmmac_enable_eee_mode(struct stmmac_priv *priv)
+static void stmmac_try_to_start_sw_lpi(struct stmmac_priv *priv)
 {
-	if (stmmac_eee_tx_busy(priv))
-		return -EBUSY; /* still unfinished work */
+	if (stmmac_eee_tx_busy(priv)) {
+		stmmac_restart_sw_lpi_timer(priv);
+		return;
+	}
 
 	/* Check and enter in LPI mode */
 	if (!priv->tx_path_in_lpi_mode)
 		stmmac_set_eee_mode(priv, priv->hw,
 			priv->plat->flags & STMMAC_FLAG_EN_TX_LPI_CLOCKGATING);
-	return 0;
-}
-
-static void stmmac_try_to_start_sw_lpi(struct stmmac_priv *priv)
-{
-	if (stmmac_enable_eee_mode(priv))
-		stmmac_restart_sw_lpi_timer(priv);
 }
 
 /**
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 9/9] net: stmmac: restart LPI timer after cleaning transmit descriptors
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (7 preceding siblings ...)
  2025-01-13 11:46 ` [PATCH net-next 8/9] net: stmmac: combine stmmac_enable_eee_mode() Russell King (Oracle)
@ 2025-01-13 11:46 ` Russell King (Oracle)
  2025-01-15  2:50 ` [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) patchwork-bot+netdevbpf
  9 siblings, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2025-01-13 11:46 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: Eric Woudstra, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Maxime Coquelin, Alexandre Torgue,
	netdev, linux-stm32, linux-arm-kernel

Fix a bug in the LPI handling, where it is possible to immediately
enter LPI mode after cleaning the transmit descriptors when all queues
are empty rather than waiting for the LPI timeout to expire.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 72f270013086..acd6994c1764 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2795,7 +2795,7 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue,
 	}
 
 	if (priv->eee_sw_timer_en && !priv->tx_path_in_lpi_mode)
-		stmmac_try_to_start_sw_lpi(priv);
+		stmmac_restart_sw_lpi_timer(priv);
 
 	/* We still have pending packets, let's call for a new scheduling */
 	if (tx_q->dirty_tx != tx_q->cur_tx)
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!)
  2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
                   ` (8 preceding siblings ...)
  2025-01-13 11:46 ` [PATCH net-next 9/9] net: stmmac: restart LPI timer after cleaning transmit descriptors Russell King (Oracle)
@ 2025-01-15  2:50 ` patchwork-bot+netdevbpf
  9 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-01-15  2:50 UTC (permalink / raw)
  To: Russell King
  Cc: andrew, hkallweit1, alexandre.torgue, andrew+netdev, davem,
	edumazet, ericwouds, kuba, linux-arm-kernel, linux-stm32,
	mcoquelin.stm32, netdev, pabeni

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 13 Jan 2025 11:45:37 +0000 you wrote:
> Hi,
> 
> This series continues the EEE cleanup of the stmmac driver, and
> includes one fix.
> 
> As mentioned in the previous series, I wasn't entirely happy with the
> "stmmac_disable_sw_eee_mode" name, so the first patch renames this to
> "stmmac_stop_sw_lpi" instead, which I think better describes what this
> function is doing - stopping the transmit of the LPI state because we
> have a packet ot send.
> 
> [...]

Here is the summary with links:
  - [net-next,1/9] net: stmmac: rename stmmac_disable_sw_eee_mode()
    https://git.kernel.org/netdev/net-next/c/900782a029e5
  - [net-next,2/9] net: stmmac: correct priv->eee_sw_timer_en setting
    https://git.kernel.org/netdev/net-next/c/4fe09a0d64d5
  - [net-next,3/9] net: stmmac: simplify TX cleanup decision for ending sw LPI mode
    https://git.kernel.org/netdev/net-next/c/bfa9e131c9b2
  - [net-next,4/9] net: stmmac: check priv->eee_sw_timer_en in suspend path
    https://git.kernel.org/netdev/net-next/c/c920e6402523
  - [net-next,5/9] net: stmmac: add stmmac_try_to_start_sw_lpi()
    https://git.kernel.org/netdev/net-next/c/0cf44bd0c118
  - [net-next,6/9] net: stmmac: provide stmmac_eee_tx_busy()
    https://git.kernel.org/netdev/net-next/c/82f2025dda76
  - [net-next,7/9] net: stmmac: provide function for restarting sw LPI timer
    https://git.kernel.org/netdev/net-next/c/af5dc22bdb5f
  - [net-next,8/9] net: stmmac: combine stmmac_enable_eee_mode()
    https://git.kernel.org/netdev/net-next/c/ec8553673b1f
  - [net-next,9/9] net: stmmac: restart LPI timer after cleaning transmit descriptors
    https://git.kernel.org/netdev/net-next/c/d28e89244978

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-01-15  2:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-13 11:45 [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) Russell King (Oracle)
2025-01-13 11:45 ` [PATCH net-next 1/9] net: stmmac: rename stmmac_disable_sw_eee_mode() Russell King (Oracle)
2025-01-13 11:45 ` [PATCH net-next 2/9] net: stmmac: correct priv->eee_sw_timer_en setting Russell King (Oracle)
2025-01-13 11:45 ` [PATCH net-next 3/9] net: stmmac: simplify TX cleanup decision for ending sw LPI mode Russell King (Oracle)
2025-01-13 11:45 ` [PATCH net-next 4/9] net: stmmac: check priv->eee_sw_timer_en in suspend path Russell King (Oracle)
2025-01-13 11:46 ` [PATCH net-next 5/9] net: stmmac: add stmmac_try_to_start_sw_lpi() Russell King (Oracle)
2025-01-13 11:46 ` [PATCH net-next 6/9] net: stmmac: provide stmmac_eee_tx_busy() Russell King (Oracle)
2025-01-13 11:46 ` [PATCH net-next 7/9] net: stmmac: provide function for restarting sw LPI timer Russell King (Oracle)
2025-01-13 11:46 ` [PATCH net-next 8/9] net: stmmac: combine stmmac_enable_eee_mode() Russell King (Oracle)
2025-01-13 11:46 ` [PATCH net-next 9/9] net: stmmac: restart LPI timer after cleaning transmit descriptors Russell King (Oracle)
2025-01-15  2:50 ` [PATCH net-next 0/9] net: stmmac: further EEE cleanups (and one fix!) patchwork-bot+netdevbpf

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).