mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] watchdog: add option to provide fall-back restart handler
@ 2021-05-31  7:13 Ahmad Fatoum
  2021-05-31  9:50 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2021-05-31  7:13 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Some barebox ports may have a watchdog, but no restart handler, e.g.
reset happens via PMIC, which has no driver yet, but watchdog controls
reset line going to PMIC. Accommodate such setups by allowing
registration of watchdog as fall back restart handler.

As reset handling can't be disabled, this is made a default n option
to conserve binary size unless explicitly enabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/watchdog/Kconfig   |  7 +++++++
 drivers/watchdog/wd_core.c | 26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b785181c59db..542659825045 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -16,6 +16,13 @@ config WATCHDOG_POLLER
 	help
 	  Provides support for periodic watchdog feeder.
 
+config WATCHDOG_RESTART_FALLBACK
+	bool "Use Watchdog as fall-back restart handler"
+	help
+	  Say y here if you have a system without a restart handler, but which
+	  has a functional watchdog. Note that $global.system.reset will most
+	  probably not indicate RST when using this handler.
+
 config WATCHDOG_AR9344
 	bool "QCA AR9344"
 	depends on SOC_QCA_AR9344 || SOC_QCA_AR9331 || COMPILE_TEST
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 4b0ee31d5b35..55ab023d8368 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <linux/ctype.h>
 #include <watchdog.h>
+#include <restart.h>
 
 static LIST_HEAD(watchdog_list);
 
@@ -177,6 +178,24 @@ static int seconds_to_expire_get(struct param_d *p, void *priv)
 	return 0;
 }
 
+static void __noreturn watchdog_restart_handle(struct restart_handler *this)
+{
+	struct watchdog *wd = watchdog_get_default();
+	int ret = -ENODEV;
+
+	if (wd)
+		ret = watchdog_set_timeout(wd, 1);
+
+	BUG_ON(ret);
+	mdelay(2000);
+	__builtin_unreachable();
+}
+
+static struct restart_handler restart_handler = {
+	.restart = watchdog_restart_handle,
+	.name = "watchdog-restart",
+};
+
 int watchdog_register(struct watchdog *wd)
 {
 	struct param_d *p;
@@ -247,6 +266,13 @@ int watchdog_register(struct watchdog *wd)
 		goto error_unregister;
 	}
 
+	if (IS_ENABLED(CONFIG_WATCHDOG_RESTART_FALLBACK) && !restart_handler.priority) {
+		restart_handler.priority = 10; /* don't override others */
+		ret = restart_handler_register(&restart_handler);
+		if (ret)
+			dev_warn(&wd->dev, "failed to register restart handler\n");
+	}
+
 	list_add_tail(&wd->list, &watchdog_list);
 
 	pr_debug("registering watchdog %s with priority %d\n", watchdog_name(wd),
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] watchdog: add option to provide fall-back restart handler
  2021-05-31  7:13 [PATCH] watchdog: add option to provide fall-back restart handler Ahmad Fatoum
@ 2021-05-31  9:50 ` Sascha Hauer
  2021-05-31 10:17   ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2021-05-31  9:50 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, May 31, 2021 at 09:13:19AM +0200, Ahmad Fatoum wrote:
> Some barebox ports may have a watchdog, but no restart handler, e.g.
> reset happens via PMIC, which has no driver yet, but watchdog controls
> reset line going to PMIC. Accommodate such setups by allowing
> registration of watchdog as fall back restart handler.
> 
> As reset handling can't be disabled, this is made a default n option
> to conserve binary size unless explicitly enabled.

Do we really need to make this optional? The binary size overhead can't
be much more than a few bytes.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] watchdog: add option to provide fall-back restart handler
  2021-05-31  9:50 ` Sascha Hauer
@ 2021-05-31 10:17   ` Ahmad Fatoum
  0 siblings, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2021-05-31 10:17 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi,

On 31.05.21 11:50, Sascha Hauer wrote:
> On Mon, May 31, 2021 at 09:13:19AM +0200, Ahmad Fatoum wrote:
>> Some barebox ports may have a watchdog, but no restart handler, e.g.
>> reset happens via PMIC, which has no driver yet, but watchdog controls
>> reset line going to PMIC. Accommodate such setups by allowing
>> registration of watchdog as fall back restart handler.
>>
>> As reset handling can't be disabled, this is made a default n option
>> to conserve binary size unless explicitly enabled.
> 
> Do we really need to make this optional? The binary size overhead can't
> be much more than a few bytes.

I wouldn't like, if after an update, reset silently fell back to the
watchdog instead of hanging and alerting the user that something broke.

For development, it's ok, but once I have a proper reset driver, I want
either that or an error message IMO.

Cheers,
Ahmad

> 
> Sascha
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-05-31 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31  7:13 [PATCH] watchdog: add option to provide fall-back restart handler Ahmad Fatoum
2021-05-31  9:50 ` Sascha Hauer
2021-05-31 10:17   ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox