Skip to contentSkip to conversation

watchdog: qcom_wdt: set WDOG_HW_RUNNING bit when appropriate

PATCH Applied Robert Marko 5 participants 9 messages Oct 31, 2020 – Dec 29, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 watchdog: qcom_wdt: set WDOG_HW_RUNNING bit when appropriate

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

---
Changes in v4:
* Use QCOM_WDT_ENABLE macro

Changes in v3:
* Drop call to stop as start already does it
* Update commit message

Changes in v2:
* Correct authorship

 drivers/watchdog/qcom-wdt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/watchdog/qcom-wdt.c +18 -0
index ab7465d186fd..07d399c4edc4 100644
@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action,
 	return 0;
 }
 
+static int qcom_wdt_is_running(struct watchdog_device *wdd)
+{
+	struct qcom_wdt *wdt = to_qcom_wdt(wdd);
+
+	return (readl(wdt_addr(wdt, WDT_EN)) & QCOM_WDT_ENABLE);
+}
+
 static const struct watchdog_ops qcom_wdt_ops = {
 	.start		= qcom_wdt_start,
 	.stop		= qcom_wdt_stop,
@@ -294,6 +301,17 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
 	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
+	/*
+	 * If WDT is already running, call WDT start which
+	 * will stop the WDT, set timeouts as bootloader
+	 * might use different ones and set running bit
+	 * to inform the WDT subsystem to ping the WDT
+	 */
+	if (qcom_wdt_is_running(&wdt->wdd)) {
+		qcom_wdt_start(&wdt->wdd);
+		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
+	}
+
 	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret)
 		return ret;
Signature · 1 line
2.28.0
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Quoted 52 lines
Cc Luka Perkov <[email protected]>

---
Changes in v4:
* Use QCOM_WDT_ENABLE macro

Changes in v3:
* Drop call to stop as start already does it
* Update commit message

Changes in v2:
* Correct authorship

 drivers/watchdog/qcom-wdt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/watchdog/qcom-wdt.c +18 -0
index ab7465d186fd..07d399c4edc4 100644
@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action,
 	return 0;
 }
 
+static int qcom_wdt_is_running(struct watchdog_device *wdd)
+{
+	struct qcom_wdt *wdt = to_qcom_wdt(wdd);
+
+	return (readl(wdt_addr(wdt, WDT_EN)) & QCOM_WDT_ENABLE);
+}
+
 static const struct watchdog_ops qcom_wdt_ops = {
 	.start		= qcom_wdt_start,
 	.stop		= qcom_wdt_stop,
@@ -294,6 +301,17 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
 	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
+	/*
+	 * If WDT is already running, call WDT start which
+	 * will stop the WDT, set timeouts as bootloader
+	 * might use different ones and set running bit
+	 * to inform the WDT subsystem to ping the WDT
+	 */
+	if (qcom_wdt_is_running(&wdt->wdd)) {
+		qcom_wdt_start(&wdt->wdd);
+		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
+	}
+
 	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret)
 		return ret;
#2 lore raw
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Quoted 5 lines
Quoted 4 lines

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Thanks for addressing the comments and now the patch looks good to me. One more suggestion, can we make the initcall level of the driver to subsys_initcall_sync so that the driver gets registered immediately after the watchdog_core is registered and watchdog_core starts pinging the WDT?

Quoted 52 lines
Quoted 52 lines
Cc Luka Perkov <[email protected]>

---
Changes in v4:
* Use QCOM_WDT_ENABLE macro

Changes in v3:
* Drop call to stop as start already does it
* Update commit message

Changes in v2:
* Correct authorship

  drivers/watchdog/qcom-wdt.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/watchdog/qcom-wdt.c +18 -0
index ab7465d186fd..07d399c4edc4 100644
@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action,
  	return 0;
  }
 
+static int qcom_wdt_is_running(struct watchdog_device *wdd)
+{
+	struct qcom_wdt *wdt = to_qcom_wdt(wdd);
+
+	return (readl(wdt_addr(wdt, WDT_EN)) & QCOM_WDT_ENABLE);
+}
+
  static const struct watchdog_ops qcom_wdt_ops = {
  	.start		= qcom_wdt_start,
  	.stop		= qcom_wdt_stop,
@@ -294,6 +301,17 @@ static int qcom_wdt_probe(struct platform_device *pdev)
  	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
  	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
+	/*
+	 * If WDT is already running, call WDT start which
+	 * will stop the WDT, set timeouts as bootloader
+	 * might use different ones and set running bit
+	 * to inform the WDT subsystem to ping the WDT
+	 */
+	if (qcom_wdt_is_running(&wdt->wdd)) {
+		qcom_wdt_start(&wdt->wdd);
+		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
+	}
+
  	ret = devm_watchdog_register_device(dev, &wdt->wdd);
  	if (ret)
  		return ret;
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#3 lore raw
Quoted 9 lines · Kathiravan T
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Thanks for addressing the comments and now the patch looks good to me. One more suggestion, can we make the initcall level of the driver to subsys_initcall_sync so that the driver gets registered immediately after the watchdog_core is registered and watchdog_core starts pinging the WDT?

That would mean to replace module_platform_driver(), which would be a whole different discussion, is not widely needed, and would potentially interfere with the subsys_initcall_sync() in the watchdog core. This will require specific evidence that a problem is seen in the field, and that it is truly needed. Plus, it would have to be a different patch (which you could submit yourself, with evidence). Let's stick with one logical change per patch, please.

Guenter

#4 lore raw
Quoted 24 lines · Guenter Roeck
Quoted 8 lines · Kathiravan T
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Thanks for addressing the comments and now the patch looks good to me. One more suggestion, can we make the initcall level of the driver to subsys_initcall_sync so that the driver gets registered immediately after the watchdog_core is registered and watchdog_core starts pinging the WDT?

That would mean to replace module_platform_driver(), which would be a whole different discussion, is not widely needed, and would potentially interfere with the subsys_initcall_sync() in the watchdog core. This will require specific evidence that a problem is seen in the field, and that it is truly needed. Plus, it would have to be a different patch (which you could submit yourself, with evidence). Let's stick with one logical change per patch, please.

Quoted 1 line

Guenter

Yeah, of course I don't want to squash the initcall level change with this one. Just made a suggestion to consider it. Anyway I will try to collect some data and post the patch by own on that suggestion. Thanks Guenter.

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
#5 lore raw
Quoted 27 lines · Kathiravan T
Quoted 24 lines · Guenter Roeck
Quoted 8 lines · Kathiravan T
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Thanks for addressing the comments and now the patch looks good to me. One more suggestion, can we make the initcall level of the driver to subsys_initcall_sync so that the driver gets registered immediately after the watchdog_core is registered and watchdog_core starts pinging the WDT?

That would mean to replace module_platform_driver(), which would be a whole different discussion, is not widely needed, and would potentially interfere with the subsys_initcall_sync() in the watchdog core. This will require specific evidence that a problem is seen in the field, and that it is truly needed. Plus, it would have to be a different patch (which you could submit yourself, with evidence). Let's stick with one logical change per patch, please.

Quoted 9 lines
Quoted 1 line

Guenter

Yeah, of course I don't want to squash the initcall level change with this one. Just made a suggestion to consider it. Anyway I will try to collect some data and post the patch by own on that suggestion. Thanks Guenter.

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

Any chance this could be picked for 5.11?
I have some boards depending on it for normal boot.

Regards,
Robert

maintainer
#6 lore raw
Quoted 34 lines · Robert Marko
Quoted 33 lines · Kathiravan T
Quoted 24 lines · Guenter Roeck
Quoted 8 lines · Kathiravan T
Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Thanks for addressing the comments and now the patch looks good to me. One more suggestion, can we make the initcall level of the driver to subsys_initcall_sync so that the driver gets registered immediately after the watchdog_core is registered and watchdog_core starts pinging the WDT?

That would mean to replace module_platform_driver(), which would be a whole different discussion, is not widely needed, and would potentially interfere with the subsys_initcall_sync() in the watchdog core. This will require specific evidence that a problem is seen in the field, and that it is truly needed. Plus, it would have to be a different patch (which you could submit yourself, with evidence). Let's stick with one logical change per patch, please.

Quoted 1 line

Guenter

Yeah, of course I don't want to squash the initcall level change with this one. Just made a suggestion to consider it. Anyway I will try to collect some data and post the patch by own on that suggestion. Thanks Guenter.

Quoted 7 lines
Quoted 3 lines

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

Any chance this could be picked for 5.11?
I have some boards depending on it for normal boot.

It is queued in my watchdog-next branch, so Wim will most likely pick it up.

Guenter

Reviewed-by on v4 1/1
#7 lore raw
In reply to Robert Marko
Quoted 11 lines · Robert Marko

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

Quoted 19 lines

---
Changes in v4:
* Use QCOM_WDT_ENABLE macro

Changes in v3:
* Drop call to stop as start already does it
* Update commit message

Changes in v2:
* Correct authorship

 drivers/watchdog/qcom-wdt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/watchdog/qcom-wdt.c +0 -0
index ab7465d186fd..07d399c4edc4 100644

drivers/watchdog/qcom-wdt.c static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action, · line 159

Quoted 8 lines
drivers/watchdog/qcom-wdt.c +5 -0
@@ -152,6 +152,13 @@ static int qcom_wdt_restart(struct watchdog_device *wdd, unsigned long action,
 	return 0;
 }
 
+static int qcom_wdt_is_running(struct watchdog_device *wdd)
+{
+	struct qcom_wdt *wdt = to_qcom_wdt(wdd);
+
+	return (readl(wdt_addr(wdt, WDT_EN)) & QCOM_WDT_ENABLE);

Although, you don't need the outer () here.

Regards,
Bjorn

Quoted 26 lines
drivers/watchdog/qcom-wdt.c +13 -0
+}
+
 static const struct watchdog_ops qcom_wdt_ops = {
 	.start		= qcom_wdt_start,
 	.stop		= qcom_wdt_stop,
@@ -294,6 +301,17 @@ static int qcom_wdt_probe(struct platform_device *pdev)
 	wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
 	watchdog_init_timeout(&wdt->wdd, 0, dev);
 
+	/*
+	 * If WDT is already running, call WDT start which
+	 * will stop the WDT, set timeouts as bootloader
+	 * might use different ones and set running bit
+	 * to inform the WDT subsystem to ping the WDT
+	 */
+	if (qcom_wdt_is_running(&wdt->wdd)) {
+		qcom_wdt_start(&wdt->wdd);
+		set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
+	}
+
 	ret = devm_watchdog_register_device(dev, &wdt->wdd);
 	if (ret)
 		return ret;
Signature · 1 line
2.28.0
#8 lore raw
In reply to Robert Marko
This patch was applied to qcom/linux.git (refs/heads/for-next):

Hello:

This patch was applied to qcom/linux.git (refs/heads/for-next):

Quoted 10 lines · On Sat, 31 Oct 2020 13:11:15 +0100 you wrote:

If the watchdog hardware is enabled/running during boot, e.g. due to a boot loader configuring it, we must tell the watchdog framework about this fact so that it can ping the watchdog until userspace opens the device and takes over control.

Do so using the WDOG_HW_RUNNING flag that exists for exactly that use-case.

[...]

Here is the summary with links:
- [v4] watchdog: qcom_wdt: set WDOG_HW_RUNNING bit when appropriate

    https://git.kernel.org/qcom/c/8650d0f9e933

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