linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Wang Qing <wangqing@vivo.com>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-watchdog@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V5] watchdog: mtk: support dual mode when the bark irq is available
Date: Wed, 21 Apr 2021 07:11:26 -0700	[thread overview]
Message-ID: <65b0c4d4-7b01-eb4c-3b1e-0d1427e85c3e@roeck-us.net> (raw)
In-Reply-To: <1618992304-18903-1-git-send-email-wangqing@vivo.com>

On 4/21/21 1:05 AM, Wang Qing wrote:
> Support using irq handling wdt bark first instead of directly resetting.
> 
> When the watchdog timer expires in dual mode, an interrupt will be
> triggered first, then the timing restarts. The reset signal will be
> initiated when the timer expires again.
> 
> The dual mode is disabled by default.
> 

This means the real timeout is now timeout * 2. This is not what
is supposed to happen. The hard watchdog timeout needs to happen at
'timeout'.

If you want to do this, it needs to be done using pre-timeout,
only the pre-timeout time (and thus the watchdog timeout written
into the chip) must be limited to timeout / 2. Pre-timeout must
by default be disabled and only be supported if an interrupt was
provided.

I don't see a need for an additional module parameter. Providing
an interrupt implies that pre-timeout support is wanted. This needs
to be documented accordingly.

I am not lot looking at the errors reported by 0-day. Please address those.

Guenter

> V2:
> - panic() by default if WATCHDOG_PRETIMEOUT_GOV is not enabled.
> 
> V3:
> - Modify the pretimeout behavior, manually reset after the pretimeout
> - is processed and wait until timeout.
> 
> V4:
> - Remove pretimeout related processing. 
> - Add dual mode control separately.
> 
> V5:
> - Fix some formatting and printing problems.
> 
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>  drivers/watchdog/mtk_wdt.c | 36 ++++++++++++++++++++++++++++++++----
>  1 file changed, 32 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c
> index 97ca993..40122f8
> --- a/drivers/watchdog/mtk_wdt.c
> +++ b/drivers/watchdog/mtk_wdt.c
> @@ -25,6 +25,7 @@
>  #include <linux/reset-controller.h>
>  #include <linux/types.h>
>  #include <linux/watchdog.h>
> +#include <linux/interrupt.h>
>  
>  #define WDT_MAX_TIMEOUT		31
>  #define WDT_MIN_TIMEOUT		1
> @@ -57,6 +58,7 @@
>  
>  static bool nowayout = WATCHDOG_NOWAYOUT;
>  static unsigned int timeout;
> +static bool dual_mode;
>  
>  struct mtk_wdt_dev {
>  	struct watchdog_device wdt_dev;
> @@ -239,13 +241,23 @@ static int mtk_wdt_start(struct watchdog_device *wdt_dev)
>  		return ret;
>  
>  	reg = ioread32(wdt_base + WDT_MODE);
> -	reg &= ~(WDT_MODE_IRQ_EN | WDT_MODE_DUAL_EN);
> +	if (dual_mode)
> +		reg |= (WDT_MODE_IRQ_EN | WDT_MODE_DUAL_EN);
> +	else
> +		reg &= ~(WDT_MODE_IRQ_EN | WDT_MODE_DUAL_EN);
>  	reg |= (WDT_MODE_EN | WDT_MODE_KEY);
>  	iowrite32(reg, wdt_base + WDT_MODE);
>  
>  	return 0;
>  }
>  
> +static irqreturn_t mtk_wdt_isr(int irq, void *arg)
> +{
> +	panic("wdt bark!\n");
> +
> +	return IRQ_HANDLED;
> +}
> +
>  static const struct watchdog_info mtk_wdt_info = {
>  	.identity	= DRV_NAME,
>  	.options	= WDIOF_SETTIMEOUT |
> @@ -267,7 +279,7 @@ static int mtk_wdt_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct mtk_wdt_dev *mtk_wdt;
>  	const struct mtk_wdt_data *wdt_data;
> -	int err;
> +	int err, irq;
>  
>  	mtk_wdt = devm_kzalloc(dev, sizeof(*mtk_wdt), GFP_KERNEL);
>  	if (!mtk_wdt)
> @@ -279,6 +291,19 @@ static int mtk_wdt_probe(struct platform_device *pdev)
>  	if (IS_ERR(mtk_wdt->wdt_base))
>  		return PTR_ERR(mtk_wdt->wdt_base);
>  
> +	if (dual_mode) {
> +		irq = platform_get_irq(pdev, 0);
> +		if (irq > 0) {
> +			err = devm_request_irq(&pdev->dev, irq, mtk_wdt_isr, 0, "wdt_bark",
> +						&mtk_wdt->wdt_dev);
> +			if (err)
> +				return err;
> +		} else {
> +			dual_mode = 0;
> +			dev_info(&pdev->dev, "couldn't get wdt irq, set dual_mode = 0\n");
> +		}
> +	}
> +
>  	mtk_wdt->wdt_dev.info = &mtk_wdt_info;
>  	mtk_wdt->wdt_dev.ops = &mtk_wdt_ops;
>  	mtk_wdt->wdt_dev.timeout = WDT_MAX_TIMEOUT;
> @@ -299,8 +324,8 @@ static int mtk_wdt_probe(struct platform_device *pdev)
>  	if (unlikely(err))
>  		return err;
>  
> -	dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)\n",
> -		 mtk_wdt->wdt_dev.timeout, nowayout);
> +	dev_info(dev, "Watchdog enabled (timeout=%d sec, nowayout=%d,
> +		 dual_mode=%d)\n", mtk_wdt->wdt_dev.timeout, nowayout, dual_mode);
>  
>  	wdt_data = of_device_get_match_data(dev);
>  	if (wdt_data) {
> @@ -368,6 +393,9 @@ module_param(nowayout, bool, 0);
>  MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
>  			__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
>  
> +module_param(dual_mode, bool, 0);
> +MODULE_PARM_DESC(dual_mode, "Dual mode triggers irq before reset (default=0)");
> +
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Matthias Brugger <matthias.bgg@gmail.com>");
>  MODULE_DESCRIPTION("Mediatek WatchDog Timer Driver");
> 


  parent reply	other threads:[~2021-04-21 14:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21  8:05 [PATCH V5] watchdog: mtk: support dual mode when the bark irq is available Wang Qing
2021-04-21 12:45 ` kernel test robot
2021-04-21 12:45 ` kernel test robot
2021-04-21 14:11 ` Guenter Roeck [this message]
2021-04-21 15:04 ` kernel test robot

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=65b0c4d4-7b01-eb4c-3b1e-0d1427e85c3e@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=wangqing@vivo.com \
    --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).