linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tero Kristo <t-kristo@ti.com>
To: Guenter Roeck <linux@roeck-us.net>, <wim@linux-watchdog.org>,
	<linux-watchdog@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <jan.kiszka@siemens.com>
Subject: Re: [PATCHv2 4/5] watchdog: rti-wdt: attach to running watchdog during probe
Date: Mon, 13 Jul 2020 15:55:02 +0300	[thread overview]
Message-ID: <9b3f383f-b3fe-3995-7fe6-b34121e79a71@ti.com> (raw)
In-Reply-To: <8eecaa6a-2e0e-14b3-473a-0674f9b2be26@roeck-us.net>

On 05/07/2020 18:07, Guenter Roeck wrote:
> On 7/3/20 5:04 AM, Tero Kristo wrote:
>> If the RTI watchdog is running already during probe, the driver must
>> configure itself to match the HW. Window size and timeout is probed from
>> hardware, and the last keepalive ping is adjusted to match it also.
>>
>> Signed-off-by: Tero Kristo <t-kristo@ti.com>
>> ---
>>   drivers/watchdog/rti_wdt.c | 26 +++++++++++++++++++++++---
>>   1 file changed, 23 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
>> index 110bfc8d0bb3..987e5a798cb4 100644
>> --- a/drivers/watchdog/rti_wdt.c
>> +++ b/drivers/watchdog/rti_wdt.c
>> @@ -213,6 +213,7 @@ static int rti_wdt_probe(struct platform_device *pdev)
>>   	struct watchdog_device *wdd;
>>   	struct rti_wdt_device *wdt;
>>   	struct clk *clk;
>> +	u32 last_ping = 0;
>>   
>>   	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
>>   	if (!wdt)
>> @@ -258,11 +259,8 @@ static int rti_wdt_probe(struct platform_device *pdev)
>>   	wdd->min_timeout = 1;
>>   	wdd->max_hw_heartbeat_ms = (WDT_PRELOAD_MAX << WDT_PRELOAD_SHIFT) /
>>   		wdt->freq * 1000;
>> -	wdd->timeout = DEFAULT_HEARTBEAT;
> 
> What if the watchdog is not running ?

Configuring wdd->timeout seems redundant, it gets set by the 
watchdog_init_timeout call done later. I just moved that post the check 
for a running watchdog so that the same call is used for both cases.

> 
>>   	wdd->parent = dev;
>>   
>> -	watchdog_init_timeout(wdd, heartbeat, dev);
>> -
>>   	watchdog_set_drvdata(wdd, wdt);
>>   	watchdog_set_nowayout(wdd, 1);
>>   	watchdog_set_restart_priority(wdd, 128);
>> @@ -274,12 +272,34 @@ static int rti_wdt_probe(struct platform_device *pdev)
>>   		goto err_iomap;
>>   	}
>>   
>> +	if (readl(wdt->base + RTIDWDCTRL) == WDENABLE_KEY) {
>> +		u32 time_left;
>> +
>> +		set_bit(WDOG_HW_RUNNING, &wdd->status);
>> +		time_left = rti_wdt_get_timeleft(wdd);
>> +		heartbeat = readl(wdt->base + RTIDWDPRLD);
>> +		heartbeat <<= WDT_PRELOAD_SHIFT;
>> +		heartbeat /= wdt->freq;
>> +
> 
> This ignores any heartbeat configured as module parameter, which most
> people will consider unexpected. It might be worthwhile documenting that.

I'll add a dev_warn for this case.

> 
>> +		wsize = readl(wdt->base + RTIWWDSIZECTRL);
>> +		ret = rti_wdt_setup_hw_hb(wdd);
>> +		if (ret)
>> +			goto err_iomap;
>> +
>> +		last_ping = -(time_left - heartbeat) * 1000;
> 
> Why the double negation ?
> 
> 		last_ping = (heartbeat - time_left) * 1000;
> 
> seems simpler. Also, what if heartbeat - time_left is negative for whatever
> reason ?

Will fix. I'll add a dev_warn for that case and assume last ping to be zero.

> 
> I am not sure if it is a good idea to call rti_wdt_get_timeleft()
> here. It might be better to add a helper function such as
> rti_wdt_get_timeleft_ms() to return the time left in milli-seconds
> for improved accuracy.

Will add that.

-Tero

> 
>> +	}
>> +
>> +	watchdog_init_timeout(wdd, heartbeat, dev);
>> +
>>   	ret = watchdog_register_device(wdd);
>>   	if (ret) {
>>   		dev_err(dev, "cannot register watchdog device\n");
>>   		goto err_iomap;
>>   	}
>>   
>> +	if (last_ping)
>> +		watchdog_set_last_hw_keepalive(wdd, last_ping);
>> +
>>   	return 0;
>>   
>>   err_iomap:
>>
> 

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2020-07-13 12:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-03 12:04 [PATCHv2] watchdog: rti-wdt: support attaching to running wdt Tero Kristo
2020-07-03 12:04 ` [PATCHv2 1/5] watchdog: use __watchdog_ping in startup Tero Kristo
2020-07-03 12:04 ` [PATCHv2 2/5] watchdog: add support for adjusting last known HW keepalive time Tero Kristo
2020-07-05 14:58   ` Guenter Roeck
2020-07-13 12:45     ` Tero Kristo
2020-07-03 12:04 ` [PATCHv2 3/5] watchdog: rti-wdt: add support for window size configuration Tero Kristo
2020-07-05 14:49   ` Guenter Roeck
2020-07-13 12:51     ` Tero Kristo
2020-07-03 12:04 ` [PATCHv2 4/5] watchdog: rti-wdt: attach to running watchdog during probe Tero Kristo
2020-07-05 15:07   ` Guenter Roeck
2020-07-13 12:55     ` Tero Kristo [this message]
2020-07-03 12:04 ` [PATCHv2 5/5] watchdog: rti-wdt: balance pm runtime enable calls Tero Kristo
2020-07-05 15:08   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b3f383f-b3fe-3995-7fe6-b34121e79a71@ti.com \
    --to=t-kristo@ti.com \
    --cc=jan.kiszka@siemens.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@linux-watchdog.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).