From: Wim Van Sebroeck <wim@iguana.be>
To: LKML <linux-kernel@vger.kernel.org>,
Linux Watchdog Mailing List <linux-watchdog@vger.kernel.org>
Cc: Wim Van Sebroeck <wim@iguana.be>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Arnd Bergmann <arnd@arndb.de>,
Wolfram Sang <w.sang@pengutronix.de>
Subject: [PATCH 4/9] watchdog: WatchDog Timer Driver Core - Add WDIOC_SETOPTIONS ioctl
Date: Wed, 27 Jul 2011 20:16:35 +0000 [thread overview]
Message-ID: <1311797800-2706-4-git-send-email-wim@iguana.be> (raw)
In-Reply-To: <1311797800-2706-1-git-send-email-wim@iguana.be>
This part add's the WDIOC_SETOPTIONS ioctl functionality
to the WatchDog Timer Driver Core framework.
Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
---
Documentation/watchdog/watchdog-kernel-api.txt | 9 ++-
drivers/watchdog/watchdog_dev.c | 79 +++++++++++++++++++++--
include/linux/watchdog.h | 1 +
3 files changed, 80 insertions(+), 9 deletions(-)
diff --git a/Documentation/watchdog/watchdog-kernel-api.txt b/Documentation/watchdog/watchdog-kernel-api.txt
index abbcf2c..429f81b 100644
--- a/Documentation/watchdog/watchdog-kernel-api.txt
+++ b/Documentation/watchdog/watchdog-kernel-api.txt
@@ -56,8 +56,9 @@ It contains following fields:
This data should only be accessed via the watchdog_set_drvadata and
watchdog_get_drvdata routines.
* status: this field contains a number of status bits that give extra
- information about the status of the device (Like: is the device opened via
- the /dev/watchdog interface or not, ...).
+ information about the status of the device (Like: is the watchdog timer
+ running/active, is the device opened via the /dev/watchdog interface or not,
+ ...).
The list of watchdog operations is defined as:
@@ -109,6 +110,10 @@ they are supported. These optional routines/operations are:
The status bits should (preferably) be set with the set_bit and clear_bit alike
bit-operations. The status bits that are defined are:
+* WDOG_ACTIVE: this status bit indicates whether or not a watchdog timer device
+ is active or not. When the watchdog is active after booting, then you should
+ set this status bit (Note: when you register the watchdog timer device with
+ this bit set, then opening /dev/watchdog will skip the start operation)
* WDOG_DEV_OPEN: this status bit shows whether or not the watchdog device
was opened via /dev/watchdog.
(This bit should only be used by the WatchDog Timer Driver Core).
diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 2fb4cec..9f5550e 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -54,14 +54,64 @@ static struct watchdog_device *wdd;
* If the watchdog has no own ping operation then it needs to be
* restarted via the start operation. This wrapper function does
* exactly that.
+ * We only ping when the watchdog device is running.
*/
static int watchdog_ping(struct watchdog_device *wddev)
{
- if (wddev->ops->ping)
- return wddev->ops->ping(wddev); /* ping the watchdog */
- else
- return wddev->ops->start(wddev); /* restart the watchdog */
+ if (test_bit(WDOG_ACTIVE, &wdd->status)) {
+ if (wddev->ops->ping)
+ return wddev->ops->ping(wddev); /* ping the watchdog */
+ else
+ return wddev->ops->start(wddev); /* restart watchdog */
+ }
+ return 0;
+}
+
+/*
+ * watchdog_start: wrapper to start the watchdog.
+ * @wddev: the watchdog device to start
+ *
+ * Start the watchdog if it is not active and mark it active.
+ * This function returns zero on success or a negative errno code for
+ * failure.
+ */
+
+static int watchdog_start(struct watchdog_device *wddev)
+{
+ int err;
+
+ if (!test_bit(WDOG_ACTIVE, &wdd->status)) {
+ err = wddev->ops->start(wddev);
+ if (err < 0)
+ return err;
+
+ set_bit(WDOG_ACTIVE, &wdd->status);
+ }
+ return 0;
+}
+
+/*
+ * watchdog_stop: wrapper to stop the watchdog.
+ * @wddev: the watchdog device to stop
+ *
+ * Stop the watchdog if it is still active and unmark it active.
+ * This function returns zero on success or a negative errno code for
+ * failure.
+ */
+
+static int watchdog_stop(struct watchdog_device *wddev)
+{
+ int err;
+
+ if (test_bit(WDOG_ACTIVE, &wdd->status)) {
+ err = wddev->ops->stop(wddev);
+ if (err < 0)
+ return err;
+
+ clear_bit(WDOG_ACTIVE, &wdd->status);
+ }
+ return 0;
}
/*
@@ -110,6 +160,7 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd,
void __user *argp = (void __user *)arg;
int __user *p = argp;
unsigned int val;
+ int err;
switch (cmd) {
case WDIOC_GETSUPPORT:
@@ -120,6 +171,20 @@ static long watchdog_ioctl(struct file *file, unsigned int cmd,
return put_user(val, p);
case WDIOC_GETBOOTSTATUS:
return put_user(wdd->bootstatus, p);
+ case WDIOC_SETOPTIONS:
+ if (get_user(val, p))
+ return -EFAULT;
+ if (val & WDIOS_DISABLECARD) {
+ err = watchdog_stop(wdd);
+ if (err < 0)
+ return err;
+ }
+ if (val & WDIOS_ENABLECARD) {
+ err = watchdog_start(wdd);
+ if (err < 0)
+ return err;
+ }
+ return 0;
case WDIOC_KEEPALIVE:
if (!(wdd->info->options & WDIOF_KEEPALIVEPING))
return -EOPNOTSUPP;
@@ -155,7 +220,7 @@ static int watchdog_open(struct inode *inode, struct file *file)
if (!try_module_get(wdd->ops->owner))
goto out;
- err = wdd->ops->start(wdd);
+ err = watchdog_start(wdd);
if (err < 0)
goto out_mod;
@@ -181,8 +246,8 @@ static int watchdog_release(struct inode *inode, struct file *file)
{
int err;
- err = wdd->ops->stop(wdd);
- if (err != 0) {
+ err = watchdog_stop(wdd);
+ if (err < 0) {
pr_crit("%s: watchdog did not stop!\n", wdd->info->identity);
watchdog_ping(wdd);
}
diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h
index 29ff808..db46fe8 100644
--- a/include/linux/watchdog.h
+++ b/include/linux/watchdog.h
@@ -106,6 +106,7 @@ struct watchdog_device {
void *driver_data;
unsigned long status;
/* Bit numbers for status flags */
+#define WDOG_ACTIVE 0 /* Is the watchdog running/active */
#define WDOG_DEV_OPEN 1 /* Opened via /dev/watchdog ? */
};
--
1.7.6
next prev parent reply other threads:[~2011-07-27 20:18 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-11 13:50 [PATCH 0/11 v3] Generic Watchdog Timer Driver Wim Van Sebroeck
2011-07-11 14:19 ` [PATCH 01/11] watchdog: WatchDog Timer Driver Core - Add basic framework Wim Van Sebroeck
2011-07-11 14:21 ` [PATCH 02/11] watchdog: WatchDog Timer Driver Core - Add basic ioctl functionality Wim Van Sebroeck
2011-07-11 21:32 ` Wolfram Sang
2011-07-11 14:21 ` [PATCH 03/11] watchdog: WatchDog Timer Driver Core - Add WDIOC_KEEPALIVE ioctl Wim Van Sebroeck
2011-07-11 14:22 ` [PATCH 04/11] watchdog: WatchDog Timer Driver Core - Add WDIOC_SETOPTIONS ioctl Wim Van Sebroeck
2011-07-11 21:32 ` Wolfram Sang
2011-07-22 19:26 ` Wim Van Sebroeck
2011-07-11 14:22 ` [PATCH 05/11] watchdog: WatchDog Timer Driver Core - Add WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT ioctl Wim Van Sebroeck
2011-07-11 21:34 ` Wolfram Sang
2011-07-11 14:22 ` [PATCH 06/11] watchdog: WatchDog Timer Driver Core - Add Magic Close feature Wim Van Sebroeck
2011-07-11 21:35 ` Wolfram Sang
2011-07-11 14:23 ` [PATCH 07/11] watchdog: WatchDog Timer Driver Core - Add nowayout feature Wim Van Sebroeck
2011-07-11 14:23 ` [PATCH 09/11] watchdog: WatchDog Timer Driver Core - Add ioctl call Wim Van Sebroeck
2011-07-11 14:24 ` [PATCH 08/11] watchdog: WatchDog Timer Driver Core - Add parent device Wim Van Sebroeck
2011-07-11 14:24 ` [PATCH 10/11] watchdog: WatchDog Timer Driver Core - Add minimum and max timeout Wim Van Sebroeck
2011-07-11 14:24 ` [PATCH 11/11] watchdog: WatchDog Timer Driver Core - Remove llseek Wim Van Sebroeck
2011-07-11 21:35 ` Wolfram Sang
2011-07-11 21:48 ` Arnd Bergmann
2011-07-11 21:32 ` [PATCH 01/11] watchdog: WatchDog Timer Driver Core - Add basic framework Wolfram Sang
2011-07-11 23:02 ` Lars-Peter Clausen
2011-07-22 19:24 ` Wim Van Sebroeck
2011-07-11 23:00 ` Lars-Peter Clausen
2011-07-11 23:53 ` Mark Brown
2011-07-12 9:24 ` Alan Cox
2011-07-22 19:32 ` Wim Van Sebroeck
2011-07-24 3:58 ` Lars-Peter Clausen
2011-07-27 20:24 ` Wim Van Sebroeck
2011-07-29 9:24 ` Lars-Peter Clausen
2011-08-04 20:25 ` Wim Van Sebroeck
2011-07-11 21:31 ` [PATCH 0/11 v3] Generic Watchdog Timer Driver Wolfram Sang
2011-07-22 19:18 ` Wim Van Sebroeck
2011-07-22 19:38 ` Wim Van Sebroeck
2011-07-27 20:15 ` [PATCH 0/9 v4] " Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 1/9] watchdog: WatchDog Timer Driver Core - Add basic framework Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 2/9] watchdog: WatchDog Timer Driver Core - Add basic ioctl functionality Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 3/9] watchdog: WatchDog Timer Driver Core - Add WDIOC_KEEPALIVE ioctl Wim Van Sebroeck
2011-07-27 20:16 ` Wim Van Sebroeck [this message]
2011-07-27 20:16 ` [PATCH 5/9] watchdog: WatchDog Timer Driver Core - Add WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT ioctl Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 6/9] watchdog: WatchDog Timer Driver Core - Add Magic Close feature Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 7/9] watchdog: WatchDog Timer Driver Core - Add nowayout feature Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 8/9] watchdog: WatchDog Timer Driver Core - Add ioctl call Wim Van Sebroeck
2011-07-27 20:16 ` [PATCH 9/9] watchdog: WatchDog Timer Driver Core - Add minimum and max timeout Wim Van Sebroeck
2011-07-28 21:29 ` [PATCH 1/9] watchdog: WatchDog Timer Driver Core - Add basic framework Joe Perches
2011-07-30 8:40 ` Arnd Bergmann
2011-07-12 18:43 ` [PATCH 0/11 v3] Generic Watchdog Timer Driver Arnd Bergmann
2011-07-22 20:48 ` Arnaud Lacombe
2011-07-22 21:31 ` Wim Van Sebroeck
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=1311797800-2706-4-git-send-email-wim@iguana.be \
--to=wim@iguana.be \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=w.sang@pengutronix.de \
/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
all inboxes | Powered by JetHome®