Skip to content

Commit b75d91f

Browse files
cminyardtorvalds
authored andcommitted
ipmi_watchdog: restore settings when BMC reset
If the BMC gets reset, it will return 0x80 response errors. In less than a week # grep "Error 80 on cmd 22" /var/log/kernel |wc -l 378681 In this case, it is probably a good idea to restore the IPMI settings. Signed-off-by: Corey Minyard <cminyard@mvista.com> Tested-by: Arkadiusz Miśkiewicz <a.miskiewicz@gmail.com> Reported-by: Arkadiusz Miśkiewicz <a.miskiewicz@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ff05b6f commit b75d91f

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

‎drivers/char/ipmi/ipmi_watchdog.c‎

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@
139139
#define IPMI_WDOG_SET_TIMER 0x24
140140
#define IPMI_WDOG_GET_TIMER 0x25
141141

142+
#define IPMI_WDOG_TIMER_NOT_INIT_RESP 0x80
143+
142144
/* These are here until the real ones get into the watchdog.h interface. */
143145
#ifndef WDIOC_GETTIMEOUT
144146
#define WDIOC_GETTIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 20, int)
@@ -596,6 +598,7 @@ static int ipmi_heartbeat(void)
596598
struct kernel_ipmi_msg msg;
597599
int rv;
598600
struct ipmi_system_interface_addr addr;
601+
int timeout_retries = 0;
599602

600603
if (ipmi_ignore_heartbeat)
601604
return 0;
@@ -616,6 +619,7 @@ static int ipmi_heartbeat(void)
616619

617620
mutex_lock(&heartbeat_lock);
618621

622+
restart:
619623
atomic_set(&heartbeat_tofree, 2);
620624

621625
/*
@@ -653,7 +657,33 @@ static int ipmi_heartbeat(void)
653657
/* Wait for the heartbeat to be sent. */
654658
wait_for_completion(&heartbeat_wait);
655659

656-
if (heartbeat_recv_msg.msg.data[0] != 0) {
660+
if (heartbeat_recv_msg.msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP) {
661+
timeout_retries++;
662+
if (timeout_retries > 3) {
663+
printk(KERN_ERR PFX ": Unable to restore the IPMI"
664+
" watchdog's settings, giving up.\n");
665+
rv = -EIO;
666+
goto out_unlock;
667+
}
668+
669+
/*
670+
* The timer was not initialized, that means the BMC was
671+
* probably reset and lost the watchdog information. Attempt
672+
* to restore the timer's info. Note that we still hold
673+
* the heartbeat lock, to keep a heartbeat from happening
674+
* in this process, so must say no heartbeat to avoid a
675+
* deadlock on this mutex.
676+
*/
677+
rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
678+
if (rv) {
679+
printk(KERN_ERR PFX ": Unable to send the command to"
680+
" set the watchdog's settings, giving up.\n");
681+
goto out_unlock;
682+
}
683+
684+
/* We might need a new heartbeat, so do it now */
685+
goto restart;
686+
} else if (heartbeat_recv_msg.msg.data[0] != 0) {
657687
/*
658688
* Got an error in the heartbeat response. It was already
659689
* reported in ipmi_wdog_msg_handler, but we should return
@@ -662,6 +692,7 @@ static int ipmi_heartbeat(void)
662692
rv = -EINVAL;
663693
}
664694

695+
out_unlock:
665696
mutex_unlock(&heartbeat_lock);
666697

667698
return rv;
@@ -922,11 +953,15 @@ static struct miscdevice ipmi_wdog_miscdev = {
922953
static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
923954
void *handler_data)
924955
{
925-
if (msg->msg.data[0] != 0) {
956+
if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER &&
957+
msg->msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP)
958+
printk(KERN_INFO PFX "response: The IPMI controller appears"
959+
" to have been reset, will attempt to reinitialize"
960+
" the watchdog timer\n");
961+
else if (msg->msg.data[0] != 0)
926962
printk(KERN_ERR PFX "response: Error %x on cmd %x\n",
927963
msg->msg.data[0],
928964
msg->msg.cmd);
929-
}
930965

931966
ipmi_free_recv_msg(msg);
932967
}

0 commit comments

Comments
 (0)