Skip to contentSkip to conversation

watchdog: Add reboot API

RFC PATCH Applied Guenter Roeck 8 participants 20 messages May 1, 2014 – May 7, 2014

Subsystems (4)

v1 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

cover watchdog: Add reboot API

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout or by writing into its watchdog register set. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback function which is then called from the architecture's reset handler.

While global and exported callback function pointers (such as arm_pm_restart) may be acceptable as long as they are used from platform and/or architecture code, using such a mechanism across subsystems and drivers is less than desirable. Ultimately, we'll need a better solution.

This patch series is an attempt to provide such a solution. It extends the watchdog subsystem to support reboot functionality, provides an API function call to trigger reboots, adds support for the new API to arm and arm64, and converts the drivers providing reboot functionality to use the new infrastructure.

The first patch in the series implements the new API. The second and third patch modify the arm and arm64 architecture reset handlers to call the added API function. The final two patches register the reboot handlers in the sunxi and moxart watchdog drivers with the watchdog subsystem.

The sunxi patche depends on the most recent patch series sumitted by Maxime Ripard.

Compile tested only.

author maintainer
#1 lore raw

RFC PATCH 1/5 watchdog: Add API to trigger reboots

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +17 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
 static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
 {
 	/*
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
 		return ret;
 	}
 
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(watchdog_register_device);
@@ -181,6 +195,9 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
 	if (wdd == NULL)
 		return;
 
+	if (wdd == wdd_reboot_dev)
+		wdd_reboot_dev = NULL;
+
 	devno = wdd->cdev.dev;
 	ret = watchdog_dev_unregister(wdd);
 	if (ret)
include/linux/watchdog.h +11 -0
index 2a3038e..0d204af 100644
@@ -12,6 +12,7 @@
 #include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/cdev.h>
+#include <linux/reboot.h>
 #include <uapi/linux/watchdog.h>
 
 struct watchdog_ops;
@@ -23,6 +24,7 @@ struct watchdog_device;
  * @start:	The routine for starting the watchdog device.
  * @stop:	The routine for stopping the watchdog device.
  * @ping:	The routine that sends a keepalive ping to the watchdog device.
+ * @reboot:	The routine for rebooting the system
  * @status:	The routine that shows the status of the watchdog device.
  * @set_timeout:The routine for setting the watchdog devices timeout value.
  * @get_timeleft:The routine that get's the time that's left before a reset.
@@ -42,6 +44,8 @@ struct watchdog_ops {
 	int (*stop)(struct watchdog_device *);
 	/* optional operations */
 	int (*ping)(struct watchdog_device *);
+	void (*reboot)(struct watchdog_device *, enum reboot_mode,
+		       const char *);
 	unsigned int (*status)(struct watchdog_device *);
 	int (*set_timeout)(struct watchdog_device *, unsigned int);
 	unsigned int (*get_timeleft)(struct watchdog_device *);
@@ -142,4 +146,11 @@ extern int watchdog_init_timeout(struct watchdog_device *wdd,
 extern int watchdog_register_device(struct watchdog_device *);
 extern void watchdog_unregister_device(struct watchdog_device *);
 
+#ifdef CONFIG_WATCHDOG_CORE
+extern void watchdog_do_reboot(enum reboot_mode mode, const char *cmd);
+#else
+static inline void watchdog_do_reboot(enum reboot_mode mode,
+				      const char *cmd) { }
+#endif
+
 #endif  /* ifndef _LINUX_WATCHDOG_H */
Signature · 1 line
1.7.9.7
author maintainer
#13 lore raw

RFC PATCH 2/5 arm64: Support reboot through watchdog subsystem

In reply to Guenter Roeck

The watchdog subsystem provides an API to perform a system reboot. Use it.

---
 arch/arm64/kernel/process.c |    3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kernel/process.c +3 -0
index 6391485..29c2bc0 100644
@@ -42,6 +42,7 @@
 #include <linux/hw_breakpoint.h>
 #include <linux/personality.h>
 #include <linux/notifier.h>
+#include <linux/watchdog.h>
 
 #include <asm/compat.h>
 #include <asm/cacheflush.h>
@@ -144,6 +145,8 @@ void machine_restart(char *cmd)
 	if (arm_pm_restart)
 		arm_pm_restart(reboot_mode, cmd);
 
+	watchdog_do_reboot(reboot_mode, cmd);
+
 	/*
 	 * Whoops - the architecture was unable to reboot.
 	 */
Signature · 1 line
1.7.9.7
author maintainer
#14 lore raw

RFC PATCH 3/5 arm: Support reboot through watchdog subsystem

In reply to Guenter Roeck

The watchdog subsystem provides an API to perform a system reboot. Use it.

With this change, the arm_pm_restart callback is now optional, so check if it is set before calling it.

---
 arch/arm/kernel/process.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm/kernel/process.c +5 -1
index 81ef686..c3b7b5e 100644
@@ -32,6 +32,7 @@
 #include <linux/hw_breakpoint.h>
 #include <linux/leds.h>
 #include <linux/reboot.h>
+#include <linux/watchdog.h>
 
 #include <asm/cacheflush.h>
 #include <asm/idmap.h>
@@ -230,7 +231,10 @@ void machine_restart(char *cmd)
 	local_irq_disable();
 	smp_send_stop();
 
-	arm_pm_restart(reboot_mode, cmd);
+	if (arm_pm_restart)
+		arm_pm_restart(reboot_mode, cmd);
+
+	watchdog_do_reboot(reboot_mode, cmd);
 
 	/* Give a grace period for failure to restart of 1s */
 	mdelay(1000);
Signature · 1 line
1.7.9.7
author maintainer
#15 lore raw

RFC PATCH 4/5 watchdog: moxart: Register reboot handler with watchdog subsystem

In reply to Guenter Roeck

The watchdog subsystem now provides an API to trigger a system reboot. Register with it.

---
 drivers/watchdog/moxart_wdt.c |   20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/watchdog/moxart_wdt.c +8 -12
index 4aa3a8a..b83646b 100644
@@ -19,8 +19,6 @@
 #include <linux/watchdog.h>
 #include <linux/moduleparam.h>
 
-#include <asm/system_misc.h>
-
 #define REG_COUNT			0x4
 #define REG_MODE			0x8
 #define REG_ENABLE			0xC
@@ -31,15 +29,16 @@ struct moxart_wdt_dev {
 	unsigned int clock_frequency;
 };
 
-static struct moxart_wdt_dev *moxart_restart_ctx;
-
 static int heartbeat;
 
-static void moxart_wdt_restart(enum reboot_mode reboot_mode, const char *cmd)
+static void moxart_wdt_reboot(struct watchdog_device *wdt_dev,
+			      enum reboot_mode mode, const char *cmd)
 {
-	writel(1, moxart_restart_ctx->base + REG_COUNT);
-	writel(0x5ab9, moxart_restart_ctx->base + REG_MODE);
-	writel(0x03, moxart_restart_ctx->base + REG_ENABLE);
+	struct moxart_wdt_dev *moxart_wdt = watchdog_get_drvdata(wdt_dev);
+
+	writel(1, moxart_wdt->base + REG_COUNT);
+	writel(0x5ab9, moxart_wdt->base + REG_MODE);
+	writel(0x03, moxart_wdt->base + REG_ENABLE);
 }
 
 static int moxart_wdt_stop(struct watchdog_device *wdt_dev)
@@ -81,6 +80,7 @@ static const struct watchdog_ops moxart_wdt_ops = {
 	.owner          = THIS_MODULE,
 	.start          = moxart_wdt_start,
 	.stop           = moxart_wdt_stop,
+	.reboot		= moxart_wdt_reboot,
 	.set_timeout    = moxart_wdt_set_timeout,
 };
 
@@ -136,9 +136,6 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	moxart_restart_ctx = moxart_wdt;
-	arm_pm_restart = moxart_wdt_restart;
-
 	dev_dbg(dev, "Watchdog enabled (heartbeat=%d sec, nowayout=%d)\n",
 		moxart_wdt->dev.timeout, nowayout);
 
@@ -149,7 +146,6 @@ static int moxart_wdt_remove(struct platform_device *pdev)
 {
 	struct moxart_wdt_dev *moxart_wdt = platform_get_drvdata(pdev);
 
-	arm_pm_restart = NULL;
 	moxart_wdt_stop(&moxart_wdt->dev);
 	watchdog_unregister_device(&moxart_wdt->dev);
 
Signature · 1 line
1.7.9.7
author maintainer
#16 lore raw

RFC PATCH 5/5 watchdog: sunxi: Register reboot handler with watchdog subsystem

In reply to Guenter Roeck

The watchdog subsystem now provides an API to trigger a system reboot. Register with it.

---
 drivers/watchdog/sunxi_wdt.c |   22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/watchdog/sunxi_wdt.c +7 -15
index c9ca343..744b6f5 100644
@@ -27,8 +27,6 @@
 #include <linux/types.h>
 #include <linux/watchdog.h>
 
-#include <asm/system_misc.h>
-
 #define WDT_MAX_TIMEOUT         16
 #define WDT_MIN_TIMEOUT         1
 #define WDT_MODE_TIMEOUT(n)     ((n) << 3)
@@ -74,27 +72,25 @@ static const int wdt_timeout_map[] = {
 	[16] = 0xB, /* 16s */
 };
 
-static struct sunxi_wdt_dev *sunxi_restart_ctx;
-
-static void sun4i_wdt_restart(enum reboot_mode mode, const char *cmd)
+static void sunxi_wdt_reboot(struct watchdog_device *wdt_dev,
+			     enum reboot_mode mode, const char *cmd)
 {
-	if (!sunxi_restart_ctx)
-		return;
+	struct sunxi_wdt_dev *sunxi_wdt = watchdog_get_drvdata(wdt_dev);
 
 	/* Enable timer and set reset bit in the watchdog */
 	writel(WDT_MODE_EN | WDT_MODE_RST_EN,
-	       sunxi_restart_ctx->wdt_base + WDT_MODE);
+	       sunxi_wdt->wdt_base + WDT_MODE);
 
 	/*
 	 * Restart the watchdog. The default (and lowest) interval
 	 * value for the watchdog is 0.5s.
 	 */
-	writel(WDT_CTRL_RELOAD, sunxi_restart_ctx->wdt_base + WDT_CTRL);
+	writel(WDT_CTRL_RELOAD, sunxi_wdt->wdt_base + WDT_CTRL);
 
 	while (1) {
 		mdelay(5);
 		writel(WDT_MODE_EN | WDT_MODE_RST_EN,
-		       sunxi_restart_ctx->wdt_base + WDT_MODE);
+		       sunxi_wdt->wdt_base + WDT_MODE);
 	}
 }
 
@@ -171,6 +167,7 @@ static const struct watchdog_ops sunxi_wdt_ops = {
 	.start		= sunxi_wdt_start,
 	.stop		= sunxi_wdt_stop,
 	.ping		= sunxi_wdt_ping,
+	.reboot		= sunxi_wdt_reboot,
 	.set_timeout	= sunxi_wdt_set_timeout,
 };
 
@@ -209,9 +206,6 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (unlikely(err))
 		return err;
 
-	sunxi_restart_ctx = sunxi_wdt;
-	arm_pm_restart = sun4i_wdt_restart;
-
 	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
 			sunxi_wdt->wdt_dev.timeout, nowayout);
 
@@ -222,8 +216,6 @@ static int sunxi_wdt_remove(struct platform_device *pdev)
 {
 	struct sunxi_wdt_dev *sunxi_wdt = platform_get_drvdata(pdev);
 
-	arm_pm_restart = NULL;
-
 	watchdog_unregister_device(&sunxi_wdt->wdt_dev);
 	watchdog_set_drvdata(&sunxi_wdt->wdt_dev, NULL);
 
Signature · 1 line
1.7.9.7
#2 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

In reply to Guenter Roeck

Hi Guenter,

This looks pretty sensible to me (and the arm/arm64 bits look fine too), but I have one question below...

Quoted 23 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +0 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;

drivers/watchdog/watchdog_core.c line 54

Quoted 10 lines
drivers/watchdog/watchdog_core.c +9 -0
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}

What reboot_mode values would you expect a watchdog to support other than REBOOT_HARD? Also, is the cmd even useful here?

Will

author maintainer
#3 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Quoted 30 lines · Will Deacon

Hi Guenter,

This looks pretty sensible to me (and the arm/arm64 bits look fine too), but I have one question below...

Quoted 24 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
  drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
  include/linux/watchdog.h         |   11 +++++++++++
  2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +0 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
  static DEFINE_IDA(watchdog_ida);
  static struct class *watchdog_class;
 
Quoted 13 lines

drivers/watchdog/watchdog_core.c line 54

Quoted 9 lines
drivers/watchdog/watchdog_core.c +9 -0
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}

What reboot_mode values would you expect a watchdog to support other than REBOOT_HARD? Also, is the cmd even useful here?

Answer is "I don't know" in both cases. I thought about dropping the parameters, but then I thought it does not hurt to have them around either. I am open to suggestions and to dropping the parameters if everyone agrees that they are useless.

Guenter

#4 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

In reply to Guenter Roeck

Hi Guenter,

Quoted 39 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +11 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
 static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
 {
 	/*

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 6 lines
drivers/watchdog/watchdog_core.c +3 -0
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
 		return ret;
 	}
 
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

Or maybe we can just use the start callback, with the min timeout already registered, and prevent the user to kick the watchdog.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140502/06282447/attachment.sig>
author maintainer
#5 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Quoted 45 lines · Maxime Ripard

Hi Guenter,

Quoted 42 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +11 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
 static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
 {
 	/*
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
 		return ret;
 	}
 
Quoted 13 lines

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 3 lines
drivers/watchdog/watchdog_core.c +3 -0
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

I thought about that, but how likely (or unlikely) is that to ever happen ? So I figured it is not worth the effort, and would just add complexity without real gain. We could always add the list later if we ever encounter a situation where two watchdogs in the same system provide a reboot callback.

Quoted 3 lines

Or maybe we can just use the start callback, with the min timeout already registered, and prevent the user to kick the watchdog.

Doesn't always work, unfortunately, even now. The moxart driver causes an explicit and immediate reset. Also, some watchdogs don't reset the system directly but get an interrupt, which then calls the reset handler. Which, in our case, would call the start callback again, and you would have an endless loop.

Guenter

#6 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Quoted 13 lines · Guenter Roeck
Quoted 4 lines

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 3 lines
drivers/watchdog/watchdog_core.c +3 -0
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+
Quoted 9 lines

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

Quoted 4 lines

I thought about that, but how likely (or unlikely) is that to ever happen ? So I figured it is not worth the effort, and would just add complexity without real gain. We could always add the list later if we ever encounter a situation where two watchdogs in the same system provide a reboot callback.

The A31 we were discussing about in the other thread that doesn't have a watchdog driver yet has four, identical, watchogs. I'm not really concerned about the mentionned issue, since they will never be removed, but the situation might happen with an on-SoC watchdog and an i2c one (if that even exists).

But yes, right, that can be postponed.

Quoted 8 lines
Quoted 3 lines

Or maybe we can just use the start callback, with the min timeout already registered, and prevent the user to kick the watchdog.

Doesn't always work, unfortunately, even now. The moxart driver causes an explicit and immediate reset. Also, some watchdogs don't reset the system directly but get an interrupt, which then calls the reset handler. Which, in our case, would call the start callback again, and you would have an endless loop.

Ok. You have my Acked-by then.

Thanks!
Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140504/399fa054/attachment.sig>
Acked-by on the v1 series
#17 lore raw
In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout or by writing into its watchdog register set. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback function which is then called from the architecture's reset handler.

Looks very nice to me, thanks for starting this!

Arnd

#11 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

In reply to Guenter Roeck
Quoted 21 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +0 -0
index cec9b55..4ec6e2f 100644

drivers/watchdog/watchdog_core.c line 51

Quoted 9 lines
drivers/watchdog/watchdog_core.c +6 -0
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)

you can decrease one level of indentation:

	if (wdd_reboot_dev && wdd_reboot_dev->ops->reboot)

also, shouldn't you test if 'ops' is valid too ? In that case:

	if (wdd_reboot_dev && wdd_reboot_dev->ops &&
		wdd_reboot_dev->ops->reboot)
Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140505/117d29bc/attachment.sig>
author maintainer
#12 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Quoted 34 lines · Felipe Balbi
Quoted 21 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +0 -0
index cec9b55..4ec6e2f 100644

drivers/watchdog/watchdog_core.c line 51

Quoted 9 lines
drivers/watchdog/watchdog_core.c +6 -0
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)

you can decrease one level of indentation:

Quoted 7 lines
	if (wdd_reboot_dev && wdd_reboot_dev->ops->reboot)

also, shouldn't you test if 'ops' is valid too ? In that case:

	if (wdd_reboot_dev && wdd_reboot_dev->ops &&
		wdd_reboot_dev->ops->reboot)

Hmmm ... makes me think.

If ops->reboot is not set, wdd_reboot_dev should be NULL to start with, since it is only initialized if ops->reboot is not NULL.

It is not common in the Linux kernel to re-check pointers if the condition can not occur, so I don't think it should be done here.

In other words, I should probably remove the ops check as well.

Guenter

Acked-by on the v1 series
#19 lore raw
In reply to Guenter Roeck

Am Donnerstag, 1. Mai 2014, 08:41:28 schrieb Guenter Roeck:

Quoted 17 lines

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout or by writing into its watchdog register set. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback function which is then called from the architecture's reset handler.

While global and exported callback function pointers (such as arm_pm_restart) may be acceptable as long as they are used from platform and/or architecture code, using such a mechanism across subsystems and drivers is less than desirable. Ultimately, we'll need a better solution.

This patch series is an attempt to provide such a solution. It extends the watchdog subsystem to support reboot functionality, provides an API function call to trigger reboots, adds support for the new API to arm and arm64, and converts the drivers providing reboot functionality to use the new infrastructure.

Quoted 7 lines

The first patch in the series implements the new API. The second and third patch modify the arm and arm64 architecture reset handlers to call the added API function. The final two patches register the reboot handlers in the sunxi and moxart watchdog drivers with the watchdog subsystem.

The sunxi patche depends on the most recent patch series sumitted by Maxime Ripard.

a lot of Samsung architectures use a watchdog based reset too (among them some of the s3c24xx I care about) and this series looks really great for this, so

#7 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

In reply to Guenter Roeck

Hi Guenter,

Am Freitag, den 02.05.2014, 21:29 -0700 schrieb Guenter Roeck:

Quoted 59 lines · Maxime Ripard
Quoted 45 lines

Hi Guenter,

Quoted 42 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
 drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
 include/linux/watchdog.h         |   11 +++++++++++
 2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +11 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
 static DEFINE_IDA(watchdog_ida);
 static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
 static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
 {
 	/*
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
 		return ret;
 	}
 
Quoted 13 lines

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 3 lines
drivers/watchdog/watchdog_core.c +3 -0
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

Quoted 5 lines

I thought about that, but how likely (or unlikely) is that to ever happen ? So I figured it is not worth the effort, and would just add complexity without real gain. We could always add the list later if we ever encounter a situation where two watchdogs in the same system provide a reboot callback.

While this is not directly related to the issue you are fixing with this series, I would like to have it considered when talking about a watchdog system reboot API.

On i.MX we have the same situation where we have to reboot through the SoC watchdog. This works, but may leave the external components of the system (those not integrated in the SoC) in an undefined state. So if we have a PMIC with integrated watchdog we would rather like to this one to reboot the system, as it the reset is then much more closer to a power-on-reset.

This means we could have multiple watchdogs in the system, where we really want a specific one (maybe designated through a DT property) to do the reset. This isn't compatible with the "last watchdog that registers a handler wins the system reset" logic in your patch.

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
author maintainer
#8 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Quoted 79 lines · Lucas Stach

Hi Guenter,

Am Freitag, den 02.05.2014, 21:29 -0700 schrieb Guenter Roeck:

Quoted 59 lines · Maxime Ripard
Quoted 45 lines

Hi Guenter,

Quoted 42 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
  drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
  include/linux/watchdog.h         |   11 +++++++++++
  2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +11 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
  static DEFINE_IDA(watchdog_ida);
  static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
  static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
  {
  	/*
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
  		return ret;
  	}
 
Quoted 13 lines

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 3 lines
drivers/watchdog/watchdog_core.c +3 -0
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

Quoted 5 lines

I thought about that, but how likely (or unlikely) is that to ever happen ? So I figured it is not worth the effort, and would just add complexity without real gain. We could always add the list later if we ever encounter a situation where two watchdogs in the same system provide a reboot callback.

While this is not directly related to the issue you are fixing with this series, I would like to have it considered when talking about a watchdog system reboot API.

On i.MX we have the same situation where we have to reboot through the SoC watchdog. This works, but may leave the external components of the system (those not integrated in the SoC) in an undefined state. So if we have a PMIC with integrated watchdog we would rather like to this one to reboot the system, as it the reset is then much more closer to a power-on-reset.

Quoted 5 lines

This means we could have multiple watchdogs in the system, where we really want a specific one (maybe designated through a DT property) to do the reset. This isn't compatible with the "last watchdog that registers a handler wins the system reset" logic in your patch.

Wouldn't the order in which watchdogs are configured in dt define that ? The last one wins.

Thanks,
Guenter

#9 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

Am Mittwoch, den 07.05.2014, 06:01 -0700 schrieb Guenter Roeck:

Quoted 80 lines · Lucas Stach
Quoted 79 lines

Hi Guenter,

Am Freitag, den 02.05.2014, 21:29 -0700 schrieb Guenter Roeck:

Quoted 59 lines · Maxime Ripard
Quoted 45 lines

Hi Guenter,

Quoted 42 lines · Guenter Roeck

Some hardware implements reboot through its watchdog hardware, for example by triggering a watchdog timeout. Platform specific code starts to spread into watchdog drivers, typically by setting pointers to a callback functions which is then called from the platform reset handler.

To simplify code and provide a unified API to trigger reboots by watchdog drivers, provide a single API to trigger such reboots through the watchdog subsystem.

---
  drivers/watchdog/watchdog_core.c |   17 +++++++++++++++++
  include/linux/watchdog.h         |   11 +++++++++++
  2 files changed, 28 insertions(+)
drivers/watchdog/watchdog_core.c +11 -0
index cec9b55..4ec6e2f 100644
@@ -43,6 +43,17 @@
  static DEFINE_IDA(watchdog_ida);
  static struct class *watchdog_class;
 
+static struct watchdog_device *wdd_reboot_dev;
+
+void watchdog_do_reboot(enum reboot_mode mode, const char *cmd)
+{
+	if (wdd_reboot_dev) {
+		if (wdd_reboot_dev->ops->reboot)
+			wdd_reboot_dev->ops->reboot(wdd_reboot_dev, mode, cmd);
+	}
+}
+EXPORT_SYMBOL(watchdog_do_reboot);
+
  static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
  {
  	/*
@@ -162,6 +173,9 @@ int watchdog_register_device(struct watchdog_device *wdd)
  		return ret;
  	}
 
Quoted 13 lines

drivers/watchdog/watchdog_core.c int watchdog_register_device(struct watchdog_device *wdd) · line 178

Quoted 3 lines
drivers/watchdog/watchdog_core.c +3 -0
+	if (wdd->ops->reboot)
+		wdd_reboot_dev = wdd;
+

Overall, it looks really great, but I guess we can make it a list. Otherwise, we might end up in a situation where we could not reboot anymore, like this one for example:
- a first watchdog is probed, registers a reboot function
- a second watchdog is probed, registers a reboot function that overwrites the first one.
- then, the second watchdog disappears for some reason, and the reboot is set to NULL

Quoted 5 lines

I thought about that, but how likely (or unlikely) is that to ever happen ? So I figured it is not worth the effort, and would just add complexity without real gain. We could always add the list later if we ever encounter a situation where two watchdogs in the same system provide a reboot callback.

While this is not directly related to the issue you are fixing with this series, I would like to have it considered when talking about a watchdog system reboot API.

On i.MX we have the same situation where we have to reboot through the SoC watchdog. This works, but may leave the external components of the system (those not integrated in the SoC) in an undefined state. So if we have a PMIC with integrated watchdog we would rather like to this one to reboot the system, as it the reset is then much more closer to a power-on-reset.

Quoted 8 lines
Quoted 5 lines

This means we could have multiple watchdogs in the system, where we really want a specific one (maybe designated through a DT property) to do the reset. This isn't compatible with the "last watchdog that registers a handler wins the system reset" logic in your patch.

Wouldn't the order in which watchdogs are configured in dt define that ? The last one wins.

That sounds rather fragile to me. I would like to have a more explicit property to control this behavior.

Regards,
Lucas

Signature · 2 lines
Pengutronix e.K.             | Lucas Stach                 |
Industrial Linux Solutions   | http://www.pengutronix.de/  |
#10 lore raw

Re: [RFC PATCH 1/5] watchdog: Add API to trigger reboots

In reply to Guenter Roeck
Quoted 8 lines · Guenter Roeck
Quoted 5 lines

This means we could have multiple watchdogs in the system, where we really want a specific one (maybe designated through a DT property) to do the reset. This isn't compatible with the "last watchdog that registers a handler wins the system reset" logic in your patch.

Wouldn't the order in which watchdogs are configured in dt define that ? The last one wins.

It doesn't work, because the DT nodes are usually ordered by physical address.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140507/9e08ff51/attachment.sig>