All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: sp5100_tco: Immediately trigger upon starting.
@ 2023-03-01 19:50 Gregory Oakes
  2023-03-02 20:00 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Gregory Oakes @ 2023-03-01 19:50 UTC (permalink / raw)
  To: linux-watchdog; +Cc: terry.bowman, Gregory Oakes

The watchdog countdown is supposed to begin when the device file is
opened. Instead, it would begin countdown upon the first write to or
close of the device file. Now, the ping operation is called within the
start operation which ensures the countdown begins. From experimenation,
it does not appear possible to do this with a single write including
both the start bit and the trigger bit. So, it is done as two distinct
writes.

Signed-off-by: Gregory Oakes <gregory.oakes@amd.com>
---

I tested on several AMD client devices. I verified the countdown begins
immediately upon the open ioctl and resets upon subsequent write ioctl's.

 drivers/watchdog/sp5100_tco.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
index fb426b7d81da..18ab0e096f99 100644
--- a/drivers/watchdog/sp5100_tco.c
+++ b/drivers/watchdog/sp5100_tco.c
@@ -86,6 +86,8 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
  * Some TCO specific functions
  */
 
+static int tco_timer_ping(struct watchdog_device *wdd);
+
 static enum tco_reg_layout tco_reg_layout(struct pci_dev *dev)
 {
 	if (dev->vendor == PCI_VENDOR_ID_ATI &&
@@ -115,7 +117,7 @@ static int tco_timer_start(struct watchdog_device *wdd)
 	val |= SP5100_WDT_START_STOP_BIT;
 	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
 
-	return 0;
+	return tco_timer_ping(wdd);
 }
 
 static int tco_timer_stop(struct watchdog_device *wdd)
-- 
2.39.1


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

* Re: [PATCH] watchdog: sp5100_tco: Immediately trigger upon starting.
  2023-03-01 19:50 [PATCH] watchdog: sp5100_tco: Immediately trigger upon starting Gregory Oakes
@ 2023-03-02 20:00 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2023-03-02 20:00 UTC (permalink / raw)
  To: Gregory Oakes, linux-watchdog; +Cc: terry.bowman

On 3/1/23 11:50, Gregory Oakes wrote:
> The watchdog countdown is supposed to begin when the device file is
> opened. Instead, it would begin countdown upon the first write to or
> close of the device file. Now, the ping operation is called within the
> start operation which ensures the countdown begins. From experimenation,
> it does not appear possible to do this with a single write including
> both the start bit and the trigger bit. So, it is done as two distinct
> writes.
> 
> Signed-off-by: Gregory Oakes <gregory.oakes@amd.com>
> ---
> 
> I tested on several AMD client devices. I verified the countdown begins
> immediately upon the open ioctl and resets upon subsequent write ioctl's.
> 
>   drivers/watchdog/sp5100_tco.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
> index fb426b7d81da..18ab0e096f99 100644
> --- a/drivers/watchdog/sp5100_tco.c
> +++ b/drivers/watchdog/sp5100_tco.c
> @@ -86,6 +86,8 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
>    * Some TCO specific functions
>    */
>   
> +static int tco_timer_ping(struct watchdog_device *wdd);
> +
>   static enum tco_reg_layout tco_reg_layout(struct pci_dev *dev)
>   {
>   	if (dev->vendor == PCI_VENDOR_ID_ATI &&
> @@ -115,7 +117,7 @@ static int tco_timer_start(struct watchdog_device *wdd)
>   	val |= SP5100_WDT_START_STOP_BIT;
>   	writel(val, SP5100_WDT_CONTROL(tco->tcobase));
>   
> -	return 0;
> +	return tco_timer_ping(wdd);

I think something like

	val = readl(SP5100_WDT_CONTROL(tco->tcobase));
         val |= SP5100_WDT_START_STOP_BIT;
         writel(val, SP5100_WDT_CONTROL(tco->tcobase));
	val |= SP5100_WDT_TRIGGER_BIT;
	writel(val, SP5100_WDT_CONTROL(tco->tcobase));

would be better here to avoid the extra read operation.

Also please add a comment into the code explaining that a single
write operation is insufficient to avoid someone stepping in later
and trying to "optimize" the code.

Thanks,
Guenter

>   }
>   
>   static int tco_timer_stop(struct watchdog_device *wdd)


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

end of thread, other threads:[~2023-03-02 20:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 19:50 [PATCH] watchdog: sp5100_tco: Immediately trigger upon starting Gregory Oakes
2023-03-02 20:00 ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.