Skip to contentSkip to conversation

watchdog: iTCO_wdt: No need to stop the timer in probe

PATCH In review Mika Westerberg 3 participants 4 messages Sep 21, 2021 – Jul 11, 2023 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 watchdog: iTCO_wdt: No need to stop the timer in probe

The watchdog core can handle pinging of the watchdog before userspace opens the device. For this reason instead of stopping the timer, just mark it as running and let the watchdog core take care of it.

---
Changes from v1:

- Only set the WDOG_HW_RUNNING flag.

 drivers/watchdog/iTCO_wdt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/watchdog/iTCO_wdt.c +11 -2
index 643c6c2d0b72..a0e8ad3901a4 100644
@@ -430,6 +430,16 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
 	return time_left;
 }
 
+static void iTCO_wdt_set_running(struct iTCO_wdt_private *p)
+{
+	u16 val;
+
+	/* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
+	val = inw(TCO1_CNT(p));
+	if (!(val & BIT(11)))
+		set_bit(WDOG_HW_RUNNING, &p->wddev.status);
+}
+
 /*
  *	Kernel Interfaces
  */
@@ -572,8 +582,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&p->wddev, p);
 	platform_set_drvdata(pdev, p);
 
-	/* Make sure the watchdog is not running */
-	iTCO_wdt_stop(&p->wddev);
+	iTCO_wdt_set_running(p);
 
 	/* Check that the heartbeat value is within it's range;
 	   if not reset to the default */
Signature · 1 line
2.33.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Mika Westerberg

The watchdog core can handle pinging of the watchdog before userspace opens the device. For this reason instead of stopping the timer, just mark it as running and let the watchdog core take care of it.

Quoted 42 lines

---
Changes from v1:

- Only set the WDOG_HW_RUNNING flag.

 drivers/watchdog/iTCO_wdt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/watchdog/iTCO_wdt.c +11 -2
index 643c6c2d0b72..a0e8ad3901a4 100644
@@ -430,6 +430,16 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
 	return time_left;
 }
 
+static void iTCO_wdt_set_running(struct iTCO_wdt_private *p)
+{
+	u16 val;
+
+	/* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
+	val = inw(TCO1_CNT(p));
+	if (!(val & BIT(11)))
+		set_bit(WDOG_HW_RUNNING, &p->wddev.status);
+}
+
 /*
  *	Kernel Interfaces
  */
@@ -572,8 +582,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&p->wddev, p);
 	platform_set_drvdata(pdev, p);
 
-	/* Make sure the watchdog is not running */
-	iTCO_wdt_stop(&p->wddev);
+	iTCO_wdt_set_running(p);
 
 	/* Check that the heartbeat value is within it's range;
 	   if not reset to the default */
Signature · 1 line
2.33.0
#2 lore raw
In reply to Mika Westerberg
Quoted 36 lines · Mika Westerberg

The watchdog core can handle pinging of the watchdog before userspace opens the device. For this reason instead of stopping the timer, just mark it as running and let the watchdog core take care of it.

---
Changes from v1:

- Only set the WDOG_HW_RUNNING flag.

 drivers/watchdog/iTCO_wdt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/watchdog/iTCO_wdt.c +10 -0
index 643c6c2d0b72..a0e8ad3901a4 100644
@@ -430,6 +430,16 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
 	return time_left;
 }
 
+static void iTCO_wdt_set_running(struct iTCO_wdt_private *p)
+{
+	u16 val;
+
+	/* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
+	val = inw(TCO1_CNT(p));
+	if (!(val & BIT(11)))
+		set_bit(WDOG_HW_RUNNING, &p->wddev.status);
+}
+
 /*
  *	Kernel Interfaces
  */

drivers/watchdog/iTCO_wdt.c static int iTCO_wdt_probe(struct platform_device *pdev) · line 588

Quoted 9 lines
drivers/watchdog/iTCO_wdt.c +1 -2
@@ -572,8 +582,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&p->wddev, p);
 	platform_set_drvdata(pdev, p);
 
-	/* Make sure the watchdog is not running */
-	iTCO_wdt_stop(&p->wddev);
+	iTCO_wdt_set_running(p);
 
 	/* Check that the heartbeat value is within it's range;
 	   if not reset to the default */

This turned out to be not just a cleanup, it's a fix for watchdog.handle_boot_enabled=0 as well. The issue is subtle, but this fix is critical when trying to establish monitoring for unattended early boot (OTA update scenarios). Can we still get this into stable trees, along with [1] then? I've tested these two over 5.10 so far, can look into older ones as well.

Jan

[1]
https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#3 lore raw
Quoted 54 lines · Jan Kiszka
Quoted 36 lines · Mika Westerberg

The watchdog core can handle pinging of the watchdog before userspace opens the device. For this reason instead of stopping the timer, just mark it as running and let the watchdog core take care of it.

---
Changes from v1:

- Only set the WDOG_HW_RUNNING flag.

 drivers/watchdog/iTCO_wdt.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/watchdog/iTCO_wdt.c +10 -0
index 643c6c2d0b72..a0e8ad3901a4 100644
@@ -430,6 +430,16 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
 	return time_left;
 }
 
+static void iTCO_wdt_set_running(struct iTCO_wdt_private *p)
+{
+	u16 val;
+
+	/* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
+	val = inw(TCO1_CNT(p));
+	if (!(val & BIT(11)))
+		set_bit(WDOG_HW_RUNNING, &p->wddev.status);
+}
+
 /*
  *	Kernel Interfaces
  */

drivers/watchdog/iTCO_wdt.c static int iTCO_wdt_probe(struct platform_device *pdev) · line 588

Quoted 9 lines
drivers/watchdog/iTCO_wdt.c +1 -2
@@ -572,8 +582,7 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
 	watchdog_set_drvdata(&p->wddev, p);
 	platform_set_drvdata(pdev, p);
 
-	/* Make sure the watchdog is not running */
-	iTCO_wdt_stop(&p->wddev);
+	iTCO_wdt_set_running(p);
 
 	/* Check that the heartbeat value is within it's range;
 	   if not reset to the default */

This turned out to be not just a cleanup, it's a fix for watchdog.handle_boot_enabled=0 as well. The issue is subtle, but this fix is critical when trying to establish monitoring for unattended early boot (OTA update scenarios). Can we still get this into stable trees, along with [1] then? I've tested these two over 5.10 so far, can look into older ones as well.

Quoted 5 lines

Jan

[1]
https://patchwork.kernel.org/project/linux-watchdog/patch/[email protected]/

Any opinions about this?

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux