From: minyard@acm.org
To: Guenter Roeck <linux@roeck-us.net>,
Wim Van Sebroeck <wim@linux-watchdog.org>
Cc: linux-watchdog@vger.kernel.org, Corey Minyard <cminyard@mvista.com>
Subject: [PATCH 10/10] ipmi:watchdog: Add the op to get the current timeout
Date: Sat, 20 Jun 2020 12:49:07 -0500 [thread overview]
Message-ID: <20200620174907.20229-11-minyard@acm.org> (raw)
In-Reply-To: <20200620174907.20229-1-minyard@acm.org>
From: Corey Minyard <cminyard@mvista.com>
The function is there and it can be done, so add it to round out the
functionality.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
drivers/char/ipmi/ipmi_watchdog.c | 80 +++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 1ee884e6dcac..e0dd820af3a9 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -722,6 +722,85 @@ static int ipmi_wdog_stop(struct watchdog_device *wdd)
return 0;
}
+/*
+ * These are for fetching the current watchdog timeout. We use a
+ * separate set so we don't block a time set when getting the time.
+ */
+static DEFINE_MUTEX(ipmi_wdog_get_mutex);
+static atomic_t get_msg_tofree = ATOMIC_INIT(0);
+static DECLARE_COMPLETION(get_msg_wait);
+static void get_msg_free_smi(struct ipmi_smi_msg *msg)
+{
+ if (atomic_dec_and_test(&get_msg_tofree))
+ complete(&get_msg_wait);
+}
+static void get_msg_free_recv(struct ipmi_recv_msg *msg)
+{
+ if (atomic_dec_and_test(&get_msg_tofree))
+ complete(&get_msg_wait);
+}
+static struct ipmi_smi_msg get_smi_msg = {
+ .done = get_msg_free_smi
+};
+static struct ipmi_recv_msg get_recv_msg = {
+ .done = get_msg_free_recv
+};
+
+static unsigned int ipmi_wdog_get_timeleft(struct watchdog_device *wdd)
+{
+ struct kernel_ipmi_msg msg;
+ struct ipmi_system_interface_addr addr;
+ unsigned char *data;
+ int rv;
+ unsigned int currtime = 0;
+
+ mutex_lock(&ipmi_wdog_get_mutex);
+
+ atomic_set(&get_msg_tofree, 2);
+
+ addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
+ addr.channel = IPMI_BMC_CHANNEL;
+ addr.lun = 0;
+
+ msg.netfn = 0x06;
+ msg.cmd = IPMI_WDOG_GET_TIMER;
+ msg.data = NULL;
+ msg.data_len = 0;
+ rv = ipmi_request_supply_msgs(watchdog_user,
+ (struct ipmi_addr *) &addr,
+ 0, &msg, NULL,
+ &get_smi_msg, &get_recv_msg, 1);
+ if (rv) {
+ pr_warn("get timeout error: %d\n", rv);
+ goto out;
+ }
+
+ wait_for_completion(&get_msg_wait);
+
+ if (get_recv_msg.msg.data_len < 1) {
+ pr_warn("get timeout received zero length message\n");
+ goto out;
+ }
+
+ data = get_recv_msg.msg.data;
+ if (data[0] != 0) {
+ pr_warn("get timeout received error: 0x%x\n", data[0]);
+ goto out;
+ }
+
+ if (get_recv_msg.msg.data_len < 9) {
+ pr_warn("get timeout received message too small, expected 9, got %u\n",
+ get_recv_msg.msg.data_len);
+ goto out;
+ }
+
+ currtime = data[7] | data[8] << 8;
+ currtime /= 10;
+ out:
+ mutex_unlock(&ipmi_wdog_get_mutex);
+ return currtime;
+}
+
static ssize_t ipmi_wdog_read(struct watchdog_device *wdd,
struct file *file,
char __user *buf,
@@ -806,6 +885,7 @@ static const struct watchdog_ops ipmi_wdog_ops = {
.set_timeout = ipmi_wdog_set_timeout,
.set_pretimeout = ipmi_wdog_set_pretimeout,
.ping = ipmi_wdog_ping,
+ .get_timeleft = ipmi_wdog_get_timeleft,
.read = ipmi_wdog_read,
.poll = ipmi_wdog_poll,
.fasync = ipmi_wdog_fasync,
--
2.17.1
prev parent reply other threads:[~2020-06-20 17:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-20 17:48 [PATCH 00/10] Convert the IPMI watchdog to use the watchdog minyard
2020-06-20 17:48 ` [PATCH 01/10] watchdog: Ignore stop_on_reboot if no stop function minyard
2020-07-19 14:11 ` Guenter Roeck
2020-06-20 17:48 ` [PATCH 02/10] watchdog: Add read capability minyard
2020-06-20 17:49 ` [PATCH 03/10] watchdog: Add documentation for " minyard
2020-07-01 2:49 ` Guenter Roeck
2020-06-20 17:49 ` [PATCH 04/10] watchdog: Add functions to set the timeout and pretimeout minyard
2020-07-01 2:45 ` Guenter Roeck
2020-06-20 17:49 ` [PATCH 05/10] watchdog: Export an interface to start the watchdog minyard
2020-07-01 2:46 ` Guenter Roeck
2020-06-20 17:49 ` [PATCH 06/10] ipmi:watchdog: Convert over to the watchdog framework minyard
2020-06-20 17:49 ` [PATCH 07/10] ipmi:watchdog: Allow the reboot timeout to be specified minyard
2020-06-20 17:49 ` [PATCH 08/10] watchdog: Add a way to extend the timeout on a reboot minyard
2020-07-19 14:25 ` Guenter Roeck
2020-06-20 17:49 ` [PATCH 09/10] ipmi:watchdog: Convert over to watchdog framework reboot handling minyard
2020-06-20 17:49 ` minyard [this message]
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=20200620174907.20229-11-minyard@acm.org \
--to=minyard@acm.org \
--cc=cminyard@mvista.com \
--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).