All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: linux-watchdog@vger.kernel.org
Cc: "Wim Van Sebroeck" <wim@iguana.be>,
	linux-kernel@vger.kernel.org,
	"Timo Kokkonen" <timo.kokkonen@offcode.fi>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-doc@vger.kernel.org,
	"Doug Anderson" <dianders@chromium.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Guenter Roeck" <linux@roeck-us.net>
Subject: [PATCH v8 04/10] watchdog: Make stop function optional
Date: Sun, 28 Feb 2016 13:12:17 -0800	[thread overview]
Message-ID: <1456693943-6876-5-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1456693943-6876-1-git-send-email-linux@roeck-us.net>

Not all hardware watchdogs can be stopped. The driver for
such watchdogs would typically only set the WATCHDOG_HW_RUNNING
flag in its stop function. Make the stop function optional and set
WATCHDOG_HW_RUNNING in the watchdog core if it is not provided.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

---
v8: Split functionality from patch introducing WATCHDOG_HW_RUNNING
---
 Documentation/watchdog/watchdog-kernel-api.txt | 20 ++++++++++++--------
 drivers/watchdog/watchdog_core.c               |  2 +-
 drivers/watchdog/watchdog_dev.c                |  6 +++++-
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/Documentation/watchdog/watchdog-kernel-api.txt b/Documentation/watchdog/watchdog-kernel-api.txt
index 954134a5c4a4..9eabca1d9355 100644
--- a/Documentation/watchdog/watchdog-kernel-api.txt
+++ b/Documentation/watchdog/watchdog-kernel-api.txt
@@ -85,7 +85,8 @@ It contains following fields:
   If set, the infrastructure will send heartbeats to the watchdog driver
   if 'timeout' is larger than max_hw_heartbeat_ms, unless WDOG_ACTIVE
   is set and userspace failed to send a heartbeat for at least 'timeout'
-  seconds.
+  seconds. max_hw_heartbeat_ms must be set if a driver does not implement
+  the stop function.
 * reboot_nb: notifier block that is registered for reboot notifications, for
   internal use only. If the driver calls watchdog_stop_on_reboot, watchdog core
   will stop the watchdog on such notifications.
@@ -134,17 +135,20 @@ are:
   device.
   The routine needs a pointer to the watchdog timer device structure as a
   parameter. It returns zero on success or a negative errno code for failure.
-* stop: with this routine the watchdog timer device is being stopped.
-  The routine needs a pointer to the watchdog timer device structure as a
-  parameter. It returns zero on success or a negative errno code for failure.
-  Some watchdog timer hardware can only be started and not be stopped.
-  If a watchdog can not be stopped, the watchdog driver must set the
-  WDOG_HW_RUNNING flag in its stop function to inform the watchdog core that
-  the watchdog is still running.
 
 Not all watchdog timer hardware supports the same functionality. That's why
 all other routines/operations are optional. They only need to be provided if
 they are supported. These optional routines/operations are:
+* stop: with this routine the watchdog timer device is being stopped.
+  The routine needs a pointer to the watchdog timer device structure as a
+  parameter. It returns zero on success or a negative errno code for failure.
+  Some watchdog timer hardware can only be started and not be stopped. A
+  driver supporting such hardware does not have to implement the stop routine.
+  If a driver has no stop function, the watchdog core will set WDOG_HW_RUNNING
+  and start calling the driver's keepalive pings function after the watchdog
+  device is closed.
+  If a watchdog driver does not implement the stop function, it must set
+  max_hw_heartbeat_ms.
 * ping: this is the routine that sends a keepalive ping to the watchdog timer
   hardware.
   The routine needs a pointer to the watchdog timer device structure as a
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index e600fd93b7de..45aabbd52b02 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -199,7 +199,7 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
 		return -EINVAL;
 
 	/* Mandatory operations need to be supported */
-	if (wdd->ops->start == NULL || wdd->ops->stop == NULL)
+	if (!wdd->ops->start || (!wdd->ops->stop && !wdd->max_hw_heartbeat_ms))
 		return -EINVAL;
 
 	watchdog_check_min_max_timeout(wdd);
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 5d3a9fa4856e..5163c3eb3428 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -246,7 +246,11 @@ static int watchdog_stop(struct watchdog_device *wdd)
 		return -EBUSY;
 	}
 
-	err = wdd->ops->stop(wdd);
+	if (wdd->ops->stop)
+		err = wdd->ops->stop(wdd);
+	else
+		set_bit(WDOG_HW_RUNNING, &wdd->status);
+
 	if (err == 0) {
 		clear_bit(WDOG_ACTIVE, &wdd->status);
 		watchdog_update_worker(wdd);
-- 
2.5.0


  parent reply	other threads:[~2016-02-28 21:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-28 21:12 [PATCH v8 0/10] watchdog: Add support for keepalives triggered by infrastructure Guenter Roeck
2016-02-28 21:12 ` [PATCH v8 01/10] watchdog: Make set_timeout function optional Guenter Roeck
2016-02-28 21:12 ` [PATCH v8 02/10] watchdog: Introduce hardware maximum heartbeat in watchdog core Guenter Roeck
2016-02-28 21:12 ` [PATCH v8 03/10] watchdog: Introduce WDOG_HW_RUNNING flag Guenter Roeck
2016-02-28 21:12 ` Guenter Roeck [this message]
2016-02-28 21:12 ` [PATCH v8 05/10] watchdog: Add support for minimum time between heartbeats Guenter Roeck
2016-02-28 21:12 ` [PATCH v8 06/10] watchdog: dw_wdt: Convert to use watchdog infrastructure Guenter Roeck
2016-03-01 22:59   ` Doug Anderson
2016-03-02 19:39     ` Guenter Roeck
2016-02-28 21:12 ` [PATCH v8 07/10] watchdog: imx2: Convert to use infrastructure triggered keepalives Guenter Roeck
2016-02-28 21:12 ` [RFC PATCH v8 08/10] watchdog: retu: " Guenter Roeck
2016-02-28 21:12 ` [RFC PATCH v8 09/10] watchdog: at91sam9: " Guenter Roeck
2016-02-28 21:12 ` [RFC PATCH v8 10/10] watchdog: gpio: " Guenter Roeck
2016-03-06 10:49 ` [PATCH v8 0/10] watchdog: Add support for keepalives triggered by infrastructure Wim Van Sebroeck
2016-03-07 17:37   ` Guenter Roeck
2016-03-07 18:50     ` Wim Van Sebroeck
2016-03-08  0:39       ` Guenter Roeck
2016-03-07  3:03 ` 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=1456693943-6876-5-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=corbet@lwn.net \
    --cc=dianders@chromium.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=timo.kokkonen@offcode.fi \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wim@iguana.be \
    /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 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.