linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe
@ 2019-11-22  8:24 Christophe Roullier
  2019-11-22 10:28 ` [Linux-stm32] " Ahmad Fatoum
  2019-11-22 10:45 ` Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: Christophe Roullier @ 2019-11-22  8:24 UTC (permalink / raw)
  To: wim, linux, mcoquelin.stm32, alexandre.torgue
  Cc: linux-watchdog, christophe.roullier, linux-kernel, linux-stm32,
	linux-arm-kernel

If the watchdog hardware is already enabled during the boot process,
when the Linux watchdog driver loads, it should start/reset the watchdog
and tell the watchdog framework. As a result, ping can be generated from
the watchdog framework (if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set),
until the userspace watchdog daemon takes over control

Fixes:4332d113c66a ("watchdog: Add STM32 IWDG driver")

Signed-off-by: Christophe Roullier <christophe.roullier@st.com>
---
Changes since v1:
According to Guenter
I follow the guidance from intel-mid_wdt.c
and I added test to check if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
because we need to be flexible (depends on customer config, but watchdog
not always start by bootloader (Uboot, ..))
I've tested some config and it is working as expected:
Watchdog enable in Uboot + HANDLE_BOOT_ENABLE is not set + daemon watchdog in userland ON ==> No reset IWDG2
Watchdog enable in Uboot + HANDLE_BOOT_ENABLE is not set ==> Reset IWDG2
Watchdog enable in Uboot + HANDLE_BOOT_ENABLE=y ==> No reset IWDG2
Watchdog enable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON puis OFF ==> Reset IWDG2
Watchdog disable in Uboot + HANDLE_BOOT_ENABLE is not set ==> No reset IWDG2
Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y ==> No reset IWDG2
Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON ==> No reset IWDG2
Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON puis OFF ==> Reset IWDG2

Thanks,
Christophe

 drivers/watchdog/stm32_iwdg.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index a3a329011a06..7f454a6e17ba 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -50,6 +50,9 @@
 #define TIMEOUT_US	100000
 #define SLEEP_US	1000
 
+static bool handle_boot_enabled =
+	IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED);
+
 struct stm32_iwdg_data {
 	bool has_pclk;
 	u32 max_prescaler;
@@ -262,6 +265,24 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
 	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
 	watchdog_init_timeout(wdd, 0, dev);
 
+	/*
+	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
+	 * (Means U-Boot/bootloaders leaves the watchdog running)
+	 * When we get here we should make a decision to prevent
+	 * any side effects before user space daemon will take care of it.
+	 * The best option, taking into consideration that there is no
+	 * way to read values back from hardware, is to enforce watchdog
+	 * being run with deterministic values.
+	 */
+	if (handle_boot_enabled) {
+		ret = stm32_iwdg_start(wdd);
+		if (ret)
+			return ret;
+
+		/* Make sure the watchdog is serviced */
+		set_bit(WDOG_HW_RUNNING, &wdd->status);
+	}
+
 	ret = devm_watchdog_register_device(dev, wdd);
 	if (ret)
 		return ret;
-- 
2.17.1


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

* Re: [Linux-stm32] [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe
  2019-11-22  8:24 [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe Christophe Roullier
@ 2019-11-22 10:28 ` Ahmad Fatoum
  2019-11-22 13:15   ` Christophe ROULLIER
  2019-11-22 10:45 ` Guenter Roeck
  1 sibling, 1 reply; 5+ messages in thread
From: Ahmad Fatoum @ 2019-11-22 10:28 UTC (permalink / raw)
  To: Christophe Roullier, wim, linux, mcoquelin.stm32, alexandre.torgue
  Cc: linux-kernel, linux-stm32, linux-watchdog, linux-arm-kernel, kernel

Hello Christophe,

On 11/22/19 9:24 AM, Christophe Roullier wrote:
> +	/*
> +	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
> +	 * (Means U-Boot/bootloaders leaves the watchdog running)
> +	 * When we get here we should make a decision to prevent
> +	 * any side effects before user space daemon will take care of it.
> +	 * The best option, taking into consideration that there is no
> +	 * way to read values back from hardware, is to enforce watchdog
> +	 * being run with deterministic values.

What about the "ONF: Watchdog enable status bit" in the IWDG_SR register?

Cheers
Ahmad

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

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

* Re: [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe
  2019-11-22  8:24 [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe Christophe Roullier
  2019-11-22 10:28 ` [Linux-stm32] " Ahmad Fatoum
@ 2019-11-22 10:45 ` Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2019-11-22 10:45 UTC (permalink / raw)
  To: Christophe Roullier, wim, mcoquelin.stm32, alexandre.torgue
  Cc: linux-watchdog, linux-kernel, linux-stm32, linux-arm-kernel

On 11/22/19 12:24 AM, Christophe Roullier wrote:
> If the watchdog hardware is already enabled during the boot process,
> when the Linux watchdog driver loads, it should start/reset the watchdog
> and tell the watchdog framework. As a result, ping can be generated from
> the watchdog framework (if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set),
> until the userspace watchdog daemon takes over control
> 
> Fixes:4332d113c66a ("watchdog: Add STM32 IWDG driver")
> 
> Signed-off-by: Christophe Roullier <christophe.roullier@st.com>
> ---
> Changes since v1:
> According to Guenter
> I follow the guidance from intel-mid_wdt.c
> and I added test to check if CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
> because we need to be flexible (depends on customer config, but watchdog
> not always start by bootloader (Uboot, ..))
> I've tested some config and it is working as expected:
> Watchdog enable in Uboot + HANDLE_BOOT_ENABLE is not set + daemon watchdog in userland ON ==> No reset IWDG2
> Watchdog enable in Uboot + HANDLE_BOOT_ENABLE is not set ==> Reset IWDG2
> Watchdog enable in Uboot + HANDLE_BOOT_ENABLE=y ==> No reset IWDG2
> Watchdog enable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON puis OFF ==> Reset IWDG2
> Watchdog disable in Uboot + HANDLE_BOOT_ENABLE is not set ==> No reset IWDG2
> Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y ==> No reset IWDG2
> Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON ==> No reset IWDG2
> Watchdog disable in Uboot + HANDLE_BOOT_ENABLE=y + daemon watchdog in userland ON puis OFF ==> Reset IWDG2
> 
> Thanks,
> Christophe
> 
>   drivers/watchdog/stm32_iwdg.c | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
> index a3a329011a06..7f454a6e17ba 100644
> --- a/drivers/watchdog/stm32_iwdg.c
> +++ b/drivers/watchdog/stm32_iwdg.c
> @@ -50,6 +50,9 @@
>   #define TIMEOUT_US	100000
>   #define SLEEP_US	1000
>   
> +static bool handle_boot_enabled =
> +	IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED);
> +
>   struct stm32_iwdg_data {
>   	bool has_pclk;
>   	u32 max_prescaler;
> @@ -262,6 +265,24 @@ static int stm32_iwdg_probe(struct platform_device *pdev)
>   	watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT);
>   	watchdog_init_timeout(wdd, 0, dev);
>   
> +	/*
> +	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
> +	 * (Means U-Boot/bootloaders leaves the watchdog running)
> +	 * When we get here we should make a decision to prevent
> +	 * any side effects before user space daemon will take care of it.
> +	 * The best option, taking into consideration that there is no
> +	 * way to read values back from hardware, is to enforce watchdog
> +	 * being run with deterministic values.
> +	 */
> +	if (handle_boot_enabled) {

You don't need that variable. Just use
	if (IS_ENABLED(CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED)) {
directly.

> +		ret = stm32_iwdg_start(wdd);
> +		if (ret)
> +			return ret;
> +
> +		/* Make sure the watchdog is serviced */
> +		set_bit(WDOG_HW_RUNNING, &wdd->status);
> +	}
> +
>   	ret = devm_watchdog_register_device(dev, wdd);
>   	if (ret)
>   		return ret;
> 


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

* Re: [Linux-stm32] [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe
  2019-11-22 10:28 ` [Linux-stm32] " Ahmad Fatoum
@ 2019-11-22 13:15   ` Christophe ROULLIER
  2019-11-22 13:31     ` Ahmad Fatoum
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe ROULLIER @ 2019-11-22 13:15 UTC (permalink / raw)
  To: Ahmad Fatoum, wim, linux, mcoquelin.stm32, Alexandre TORGUE
  Cc: linux-kernel, linux-stm32, linux-watchdog, linux-arm-kernel, kernel


On 11/22/19 11:28 AM, Ahmad Fatoum wrote:
> Hello Christophe,
>
> On 11/22/19 9:24 AM, Christophe Roullier wrote:
>> +	/*
>> +	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
>> +	 * (Means U-Boot/bootloaders leaves the watchdog running)
>> +	 * When we get here we should make a decision to prevent
>> +	 * any side effects before user space daemon will take care of it.
>> +	 * The best option, taking into consideration that there is no
>> +	 * way to read values back from hardware, is to enforce watchdog
>> +	 * being run with deterministic values.
> What about the "ONF: Watchdog enable status bit" in the IWDG_SR register?
>
> Cheers
> Ahmad
>
Hi,

Thanks Ahmad for your feedback, it is a mistake in our ref manual. This 
bit is not present

in our iwdg IP, we will update our documentation accordingly.

Regards,

Christophe

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

* Re: [Linux-stm32] [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe
  2019-11-22 13:15   ` Christophe ROULLIER
@ 2019-11-22 13:31     ` Ahmad Fatoum
  0 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2019-11-22 13:31 UTC (permalink / raw)
  To: Christophe ROULLIER, wim, linux, mcoquelin.stm32, Alexandre TORGUE
  Cc: linux-kernel, linux-stm32, linux-watchdog, linux-arm-kernel, kernel

Hello Christophe,

On 11/22/19 2:15 PM, Christophe ROULLIER wrote:
>> On 11/22/19 9:24 AM, Christophe Roullier wrote:
>>> +	/*
>>> +	 * In case of CONFIG_WATCHDOG_HANDLE_BOOT_ENABLED is set
>>> +	 * (Means U-Boot/bootloaders leaves the watchdog running)
>>> +	 * When we get here we should make a decision to prevent
>>> +	 * any side effects before user space daemon will take care of it.
>>> +	 * The best option, taking into consideration that there is no
>>> +	 * way to read values back from hardware, is to enforce watchdog
>>> +	 * being run with deterministic values.
>> What about the "ONF: Watchdog enable status bit" in the IWDG_SR register?

> Thanks Ahmad for your feedback, it is a mistake in our ref manual. This 
> bit is not present
> 
> in our iwdg IP, we will update our documentation accordingly.

Thanks for the info. I think it would be nice to have this information in
the driver as well, something like:

* The best option, taking into consideration that that the ONF
* watchdog status bit is non-functional, is to enforce watchdog
* being run with deterministic values.

This way it's clear that it's a deliberate choice to do it this way.

Cheers
Ahmad



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

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

end of thread, other threads:[~2019-11-22 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22  8:24 [PATCH v2 1/1] drivers: watchdog: stm32_iwdg: set WDOG_HW_RUNNING at probe Christophe Roullier
2019-11-22 10:28 ` [Linux-stm32] " Ahmad Fatoum
2019-11-22 13:15   ` Christophe ROULLIER
2019-11-22 13:31     ` Ahmad Fatoum
2019-11-22 10:45 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).