diff mbox series

[17/20] net: stmmac: Add 'cause' arg to the service task executioner

Message ID 20210208140341.9271-18-Sergey.Semin@baikalelectronics.ru
State New
Headers show
Series net: stmmac: Obvious cleanups and several fixes | expand

Commit Message

Serge Semin Feb. 8, 2021, 2:03 p.m. UTC
In order to have a more descriptive and coherent service task interface
let's add the cause argument to the stmmac_service_event_schedule()
method. It will be used to test-and-set the corresponding flag in the
private device state variable, and execute the service handler if the flag
hasn't been set. By doing so we'll be able to activate the service
sub-task just by calling the stmmac_service_event_schedule() method.

Note currently there is only a single user of the service tasks interface.
It's used to handle a case of the critical device errors to cause the
interface reset. The changes provided here will also prevent the global
error handler from being called twice if the service task has already
being executed while reset sub-task still isn't started.

Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 08112b6e7afd..f3ced94b3f4e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -174,16 +174,18 @@  static void stmmac_enable_all_queues(struct stmmac_priv *priv)
 	}
 }
 
-static void stmmac_service_event_schedule(struct stmmac_priv *priv)
+static void stmmac_service_event_schedule(struct stmmac_priv *priv,
+					  unsigned long cause)
 {
-	queue_work(priv->wq, &priv->service_task);
+	if (!test_and_set_bit(cause, &priv->state))
+		queue_work(priv->wq, &priv->service_task);
 }
 
 static void stmmac_global_err(struct stmmac_priv *priv)
 {
 	netif_carrier_off(priv->dev);
-	set_bit(STMMAC_RESET_REQUESTED, &priv->state);
-	stmmac_service_event_schedule(priv);
+
+	stmmac_service_event_schedule(priv, STMMAC_RESET_REQUESTED);
 }
 
 /**
@@ -4658,8 +4660,6 @@  static const struct net_device_ops stmmac_netdev_ops = {
 
 static void stmmac_reset_subtask(struct stmmac_priv *priv)
 {
-	if (!test_and_clear_bit(STMMAC_RESET_REQUESTED, &priv->state))
-		return;
 	if (test_bit(STMMAC_DOWN, &priv->state))
 		return;
 
@@ -4680,7 +4680,8 @@  static void stmmac_service_task(struct work_struct *work)
 	struct stmmac_priv *priv = container_of(work, struct stmmac_priv,
 			service_task);
 
-	stmmac_reset_subtask(priv);
+	if (test_and_clear_bit(STMMAC_RESET_REQUESTED, &priv->state))
+		stmmac_reset_subtask(priv);
 }
 
 /**