Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * ipmi_watchdog.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * A watchdog timer based upon the IPMI interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Author: MontaVista Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *         Corey Minyard <minyard@mvista.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *         source@mvista.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Copyright 2002 MontaVista Software Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #define pr_fmt(fmt) "IPMI Watchdog: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/ipmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/ipmi_smi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #ifdef CONFIG_X86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * This is ugly, but I've determined that x86 is the only architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * that can reasonably support the IPMI NMI watchdog timeout at this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  * time.  If another architecture adds this capability somehow, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  * will have to be a somewhat different mechanism and I have no idea
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * how it will work.  So in the unlikely event that another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * architecture supports this, we can figure out a good generic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  * mechanism for it at that time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <asm/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <asm/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  * The IPMI command/response information for the watchdog timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) /* values for byte 1 of the set command, byte 2 of the get response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define WDOG_DONT_LOG		(1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define WDOG_DONT_STOP_ON_SET	(1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define WDOG_SET_TIMER_USE(byte, use) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	byte = ((byte) & 0xf8) | ((use) & 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define WDOG_GET_TIMER_USE(byte) ((byte) & 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define WDOG_TIMER_USE_BIOS_FRB2	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #define WDOG_TIMER_USE_BIOS_POST	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define WDOG_TIMER_USE_OS_LOAD		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #define WDOG_TIMER_USE_SMS_OS		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define WDOG_TIMER_USE_OEM		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) /* values for byte 2 of the set command, byte 3 of the get response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define WDOG_SET_PRETIMEOUT_ACT(byte, use) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	byte = ((byte) & 0x8f) | (((use) & 0x7) << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #define WDOG_GET_PRETIMEOUT_ACT(byte) (((byte) >> 4) & 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define WDOG_PRETIMEOUT_NONE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define WDOG_PRETIMEOUT_SMI		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define WDOG_PRETIMEOUT_NMI		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define WDOG_PRETIMEOUT_MSG_INT		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) /* Operations that can be performed on a pretimout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define WDOG_PREOP_NONE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define WDOG_PREOP_PANIC	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) /* Cause data to be available to read.  Doesn't work in NMI mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define WDOG_PREOP_GIVE_DATA	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) /* Actions to perform on a full timeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define WDOG_SET_TIMEOUT_ACT(byte, use) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	byte = ((byte) & 0xf8) | ((use) & 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #define WDOG_GET_TIMEOUT_ACT(byte) ((byte) & 0x7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define WDOG_TIMEOUT_NONE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define WDOG_TIMEOUT_RESET		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define WDOG_TIMEOUT_POWER_DOWN		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define WDOG_TIMEOUT_POWER_CYCLE	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * Byte 3 of the get command, byte 4 of the get response is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * pre-timeout in seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) /* Bits for setting byte 4 of the set command, byte 5 of the get response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define WDOG_EXPIRE_CLEAR_BIOS_FRB2	(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define WDOG_EXPIRE_CLEAR_BIOS_POST	(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define WDOG_EXPIRE_CLEAR_OS_LOAD	(1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #define WDOG_EXPIRE_CLEAR_SMS_OS	(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define WDOG_EXPIRE_CLEAR_OEM		(1 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * Setting/getting the watchdog timer value.  This is for bytes 5 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * 6 (the timeout time) of the set command, and bytes 6 and 7 (the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * timeout time) and 8 and 9 (the current countdown value) of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * response.  The timeout value is given in seconds (in the command it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * is 100ms intervals).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) #define WDOG_SET_TIMEOUT(byte1, byte2, val) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	(byte1) = (((val) * 10) & 0xff), (byte2) = (((val) * 10) >> 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) #define WDOG_GET_TIMEOUT(byte1, byte2) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	(((byte1) | ((byte2) << 8)) / 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) #define IPMI_WDOG_RESET_TIMER		0x22
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #define IPMI_WDOG_SET_TIMER		0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #define IPMI_WDOG_GET_TIMER		0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #define IPMI_WDOG_TIMER_NOT_INIT_RESP	0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) static DEFINE_MUTEX(ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static bool nowayout = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static struct ipmi_user *watchdog_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static int watchdog_ifnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) /* Default the timeout to 10 seconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) static int timeout = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) /* The pre-timeout is disabled by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static int pretimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) /* Default timeout to set on panic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static int panic_wdt_timeout = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) /* Default action is to reset the board on a timeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) static unsigned char action_val = WDOG_TIMEOUT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static char action[16] = "reset";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static unsigned char preaction_val = WDOG_PRETIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static char preaction[16] = "pre_none";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) static unsigned char preop_val = WDOG_PREOP_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) static char preop[16] = "preop_none";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) static DEFINE_SPINLOCK(ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static char data_to_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static DECLARE_WAIT_QUEUE_HEAD(read_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static struct fasync_struct *fasync_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static atomic_t pretimeout_since_last_heartbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static char expect_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) static int ifnum_to_use = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) /* Parameters to ipmi_set_timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define IPMI_SET_TIMEOUT_NO_HB			0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define IPMI_SET_TIMEOUT_HB_IF_NECESSARY	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) #define IPMI_SET_TIMEOUT_FORCE_HB		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) static int ipmi_set_timeout(int do_heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) static void ipmi_register_watchdog(int ipmi_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static void ipmi_unregister_watchdog(int ipmi_intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  * If true, the driver will start running as soon as it is configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  * and ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) static int start_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static int set_param_timeout(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	char *endp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	int  l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	int  rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	l = simple_strtoul(val, &endp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	if (endp == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	*((int *)kp->arg) = l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	if (watchdog_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) static const struct kernel_param_ops param_ops_timeout = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	.set = set_param_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.get = param_get_int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #define param_check_timeout param_check_int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) typedef int (*action_fn)(const char *intval, char *outval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static int action_op(const char *inval, char *outval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) static int preaction_op(const char *inval, char *outval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) static int preop_op(const char *inval, char *outval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static void check_parms(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) static int set_param_str(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	action_fn  fn = (action_fn) kp->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	int        rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	char       valcp[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	char       *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	strncpy(valcp, val, 15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	valcp[15] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	s = strstrip(valcp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	rv = fn(s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	check_parms();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	if (watchdog_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) static int get_param_str(char *buffer, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	action_fn fn = (action_fn) kp->arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	int rv, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	rv = fn(NULL, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	len = strlen(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	buffer[len++] = '\n';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	buffer[len] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	int rv = param_set_int(val, kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if ((ifnum_to_use < 0) || (ifnum_to_use == watchdog_ifnum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	ipmi_unregister_watchdog(watchdog_ifnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	ipmi_register_watchdog(ifnum_to_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static const struct kernel_param_ops param_ops_wdog_ifnum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	.set = set_param_wdog_ifnum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	.get = param_get_int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) #define param_check_wdog_ifnum param_check_int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) static const struct kernel_param_ops param_ops_str = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	.set = set_param_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	.get = get_param_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) module_param(ifnum_to_use, wdog_ifnum, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		 "timer.  Setting to -1 defaults to the first registered "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		 "interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) module_param(timeout, timeout, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) module_param(pretimeout, timeout, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) module_param(panic_wdt_timeout, timeout, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) MODULE_PARM_DESC(panic_wdt_timeout, "Timeout value on kernel panic in seconds.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) module_param_cb(action, &param_ops_str, action_op, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) MODULE_PARM_DESC(action, "Timeout action. One of: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		 "reset, none, power_cycle, power_off.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) module_param_cb(preaction, &param_ops_str, preaction_op, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) MODULE_PARM_DESC(preaction, "Pretimeout action.  One of: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		 "pre_none, pre_smi, pre_nmi, pre_int.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) module_param_cb(preop, &param_ops_str, preop_op, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) MODULE_PARM_DESC(preop, "Pretimeout driver operation.  One of: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		 "preop_none, preop_panic, preop_give_data.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) module_param(start_now, int, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) MODULE_PARM_DESC(start_now, "Set to 1 to start the watchdog as"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		 "soon as the driver is loaded.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) module_param(nowayout, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		 "(default=CONFIG_WATCHDOG_NOWAYOUT)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) /* Default state of the timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) /* Is someone using the watchdog?  Only one user is allowed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) static unsigned long ipmi_wdog_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  * If set to 1, the heartbeat command will set the state to reset and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)  * start the timer.  The timer doesn't normally run when the driver is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  * first opened until the heartbeat is set the first time, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)  * variable is used to accomplish this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) static int ipmi_start_timer_on_heartbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) /* IPMI version of the BMC. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) static unsigned char ipmi_version_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) static unsigned char ipmi_version_minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) /* If a pretimeout occurs, this is used to allow only one panic to happen. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) static atomic_t preop_panic_excl = ATOMIC_INIT(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) static int testing_nmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static int nmi_handler_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static int __ipmi_heartbeat(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337)  * We use a mutex to make sure that only one thing can send a set a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338)  * message at one time.  The mutex is claimed when a message is sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339)  * and freed when both the send and receive messages are free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) static atomic_t msg_tofree = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) static DECLARE_COMPLETION(msg_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) static void msg_free_smi(struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	if (atomic_dec_and_test(&msg_tofree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		if (!oops_in_progress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			complete(&msg_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) static void msg_free_recv(struct ipmi_recv_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	if (atomic_dec_and_test(&msg_tofree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		if (!oops_in_progress)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			complete(&msg_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) static struct ipmi_smi_msg smi_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	.done = msg_free_smi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) static struct ipmi_recv_msg recv_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	.done = msg_free_recv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) static int __ipmi_set_timeout(struct ipmi_smi_msg  *smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			      struct ipmi_recv_msg *recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			      int                  *send_heartbeat_now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	struct kernel_ipmi_msg            msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	unsigned char                     data[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	int                               rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	struct ipmi_system_interface_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	int                               hbnow = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	data[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	WDOG_SET_TIMER_USE(data[0], WDOG_TIMER_USE_SMS_OS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	if (ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		if ((ipmi_version_major > 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		    ((ipmi_version_major == 1) && (ipmi_version_minor >= 5))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			/* This is an IPMI 1.5-only feature. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			data[0] |= WDOG_DONT_STOP_ON_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			 * In ipmi 1.0, setting the timer stops the watchdog, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			 * need to start it back up again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			hbnow = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	data[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	WDOG_SET_TIMEOUT_ACT(data[1], ipmi_watchdog_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	if ((pretimeout > 0) && (ipmi_watchdog_state != WDOG_TIMEOUT_NONE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	    WDOG_SET_PRETIMEOUT_ACT(data[1], preaction_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	    data[2] = pretimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	    WDOG_SET_PRETIMEOUT_ACT(data[1], WDOG_PRETIMEOUT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	    data[2] = 0; /* No pretimeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	data[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	WDOG_SET_TIMEOUT(data[4], data[5], timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	addr.channel = IPMI_BMC_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	addr.lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	msg.netfn = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	msg.cmd = IPMI_WDOG_SET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	msg.data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	msg.data_len = sizeof(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	rv = ipmi_request_supply_msgs(watchdog_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 				      (struct ipmi_addr *) &addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				      0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 				      &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 				      NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 				      smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 				      recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				      1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		pr_warn("set timeout error: %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	else if (send_heartbeat_now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		*send_heartbeat_now = hbnow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) static int _ipmi_set_timeout(int do_heartbeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	int send_heartbeat_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	if (!watchdog_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	atomic_set(&msg_tofree, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	rv = __ipmi_set_timeout(&smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 				&recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 				&send_heartbeat_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		atomic_set(&msg_tofree, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	wait_for_completion(&msg_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if ((do_heartbeat == IPMI_SET_TIMEOUT_FORCE_HB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		|| ((send_heartbeat_now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		    && (do_heartbeat == IPMI_SET_TIMEOUT_HB_IF_NECESSARY)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		rv = __ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) static int ipmi_set_timeout(int do_heartbeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	mutex_lock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	rv = _ipmi_set_timeout(do_heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	mutex_unlock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) static atomic_t panic_done_count = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) static void panic_smi_free(struct ipmi_smi_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	atomic_dec(&panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) static void panic_recv_free(struct ipmi_recv_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	atomic_dec(&panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) static struct ipmi_smi_msg panic_halt_heartbeat_smi_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	.done = panic_smi_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) static struct ipmi_recv_msg panic_halt_heartbeat_recv_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	.done = panic_recv_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) static void panic_halt_ipmi_heartbeat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	struct kernel_ipmi_msg             msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct ipmi_system_interface_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	 * Don't reset the timer if we have the timer turned off, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	 * re-enables the watchdog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	addr.channel = IPMI_BMC_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	addr.lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	msg.netfn = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	msg.cmd = IPMI_WDOG_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	msg.data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	msg.data_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	atomic_add(1, &panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	rv = ipmi_request_supply_msgs(watchdog_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 				      (struct ipmi_addr *) &addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 				      0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 				      &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 				      NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 				      &panic_halt_heartbeat_smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 				      &panic_halt_heartbeat_recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 				      1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		atomic_sub(1, &panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) static struct ipmi_smi_msg panic_halt_smi_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	.done = panic_smi_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static struct ipmi_recv_msg panic_halt_recv_msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	.done = panic_recv_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)  * Special call, doesn't claim any locks.  This is only to be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  * at panic or halt time, in run-to-completion mode, when the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  * is the only CPU and the only thing that will be going is these IPMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  * calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) static void panic_halt_ipmi_set_timeout(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	int send_heartbeat_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	/* Wait for the messages to be free. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	while (atomic_read(&panic_done_count) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		ipmi_poll_interface(watchdog_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	atomic_add(1, &panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	rv = __ipmi_set_timeout(&panic_halt_smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 				&panic_halt_recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 				&send_heartbeat_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		atomic_sub(1, &panic_done_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		pr_warn("Unable to extend the watchdog timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		if (send_heartbeat_now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			panic_halt_ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	while (atomic_read(&panic_done_count) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		ipmi_poll_interface(watchdog_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) static int __ipmi_heartbeat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	struct kernel_ipmi_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	struct ipmi_system_interface_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	int timeout_retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	 * Don't reset the timer if we have the timer turned off, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	 * re-enables the watchdog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	atomic_set(&msg_tofree, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	addr.channel = IPMI_BMC_CHANNEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	addr.lun = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	msg.netfn = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	msg.cmd = IPMI_WDOG_RESET_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	msg.data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	msg.data_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	rv = ipmi_request_supply_msgs(watchdog_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 				      (struct ipmi_addr *) &addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 				      0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 				      &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 				      NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 				      &smi_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 				      &recv_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 				      1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		atomic_set(&msg_tofree, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		pr_warn("heartbeat send failure: %d\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	/* Wait for the heartbeat to be sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	wait_for_completion(&msg_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	if (recv_msg.msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		timeout_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		if (timeout_retries > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			pr_err("Unable to restore the IPMI watchdog's settings, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			rv = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		 * The timer was not initialized, that means the BMC was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		 * probably reset and lost the watchdog information.  Attempt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		 * to restore the timer's info.  Note that we still hold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		 * the heartbeat lock, to keep a heartbeat from happening
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		 * in this process, so must say no heartbeat to avoid a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		 * deadlock on this mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			pr_err("Unable to send the command to set the watchdog's settings, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		/* Might need a heartbeat send, go ahead and do it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	} else if (recv_msg.msg.data[0] != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		 * Got an error in the heartbeat response.  It was already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		 * reported in ipmi_wdog_msg_handler, but we should return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		 * an error here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		rv = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) static int _ipmi_heartbeat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	if (!watchdog_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	if (ipmi_start_timer_on_heartbeat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		ipmi_start_timer_on_heartbeat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		ipmi_watchdog_state = action_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	} else if (atomic_cmpxchg(&pretimeout_since_last_heartbeat, 1, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		 * A pretimeout occurred, make sure we set the timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		 * We don't want to set the action, though, we want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		 * leave that alone (thus it can't be combined with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		 * above operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		rv = _ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		rv = __ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) static int ipmi_heartbeat(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	mutex_lock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	rv = _ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	mutex_unlock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) static struct watchdog_info ident = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	.options	= 0,	/* WDIOF_SETTIMEOUT, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	.firmware_version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	.identity	= "IPMI"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static int ipmi_ioctl(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		      unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	case WDIOC_GETSUPPORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		i = copy_to_user(argp, &ident, sizeof(ident));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		return i ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	case WDIOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		i = copy_from_user(&val, argp, sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		timeout = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		return _ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	case WDIOC_GETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		i = copy_to_user(argp, &timeout, sizeof(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	case WDIOC_SETPRETIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		i = copy_from_user(&val, argp, sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		pretimeout = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		return _ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	case WDIOC_GETPRETIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		i = copy_to_user(argp, &pretimeout, sizeof(pretimeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	case WDIOC_KEEPALIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		return _ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	case WDIOC_SETOPTIONS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		i = copy_from_user(&val, argp, sizeof(int));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		if (val & WDIOS_DISABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			_ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			ipmi_start_timer_on_heartbeat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		if (val & WDIOS_ENABLECARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			ipmi_watchdog_state = action_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 			_ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	case WDIOC_GETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		i = copy_to_user(argp, &val, sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) static long ipmi_unlocked_ioctl(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 				unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	mutex_lock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	ret = ipmi_ioctl(file, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	mutex_unlock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) static ssize_t ipmi_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			  const char  __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 			  size_t      len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			  loff_t      *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		if (!nowayout) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 			size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			/* In case it was set long ago */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 			expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			for (i = 0; i != len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 				char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 				if (get_user(c, buf + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 					return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 				if (c == 'V')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 					expect_close = 42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		rv = ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) static ssize_t ipmi_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			 char        __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 			 size_t      count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			 loff_t      *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	int          rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	wait_queue_entry_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (count <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 * Reading returns if the pretimeout has gone off, and it only does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * it once per pretimeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	spin_lock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	if (!data_to_read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		if (file->f_flags & O_NONBLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			rv = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		init_waitqueue_entry(&wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		add_wait_queue(&read_q, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		while (!data_to_read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			spin_unlock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			spin_lock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		remove_wait_queue(&read_q, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			rv = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	data_to_read = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	spin_unlock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (rv == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		if (copy_to_user(buf, &data_to_read, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			rv = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			rv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) static int ipmi_open(struct inode *ino, struct file *filep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	switch (iminor(ino)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	case WATCHDOG_MINOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		if (test_and_set_bit(0, &ipmi_wdog_open))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		 * Don't start the timer now, let it start on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		 * first heartbeat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		ipmi_start_timer_on_heartbeat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		return stream_open(ino, filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		return (-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) static __poll_t ipmi_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	__poll_t mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	poll_wait(file, &read_q, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	spin_lock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	if (data_to_read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		mask |= (EPOLLIN | EPOLLRDNORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	spin_unlock_irq(&ipmi_read_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) static int ipmi_fasync(int fd, struct file *file, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	result = fasync_helper(fd, file, on, &fasync_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	return (result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) static int ipmi_close(struct inode *ino, struct file *filep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (iminor(ino) == WATCHDOG_MINOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		if (expect_close == 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			mutex_lock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 			_ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 			mutex_unlock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			pr_crit("Unexpected close, not stopping watchdog!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			ipmi_heartbeat();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		clear_bit(0, &ipmi_wdog_open);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	expect_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) static const struct file_operations ipmi_wdog_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	.owner   = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	.read    = ipmi_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	.poll    = ipmi_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	.write   = ipmi_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	.unlocked_ioctl = ipmi_unlocked_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	.compat_ioctl	= compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	.open    = ipmi_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	.release = ipmi_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	.fasync  = ipmi_fasync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	.llseek  = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) static struct miscdevice ipmi_wdog_miscdev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	.minor		= WATCHDOG_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	.name		= "watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	.fops		= &ipmi_wdog_fops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 				  void                 *handler_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 			msg->msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		pr_info("response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	else if (msg->msg.data[0] != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		pr_err("response: Error %x on cmd %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		       msg->msg.data[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		       msg->msg.cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	ipmi_free_recv_msg(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) static void ipmi_wdog_pretimeout_handler(void *handler_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	if (preaction_val != WDOG_PRETIMEOUT_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		if (preop_val == WDOG_PREOP_PANIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			if (atomic_inc_and_test(&preop_panic_excl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 				panic("Watchdog pre-timeout");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		} else if (preop_val == WDOG_PREOP_GIVE_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			spin_lock_irqsave(&ipmi_read_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			data_to_read = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			wake_up_interruptible(&read_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			kill_fasync(&fasync_q, SIGIO, POLL_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			spin_unlock_irqrestore(&ipmi_read_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	 * On some machines, the heartbeat will give an error and not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	 * work unless we re-enable the timer.  So do so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	atomic_set(&pretimeout_since_last_heartbeat, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) static void ipmi_wdog_panic_handler(void *user_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	static int panic_event_handled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	 * On a panic, if we have a panic timeout, make sure to extend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	 * the watchdog timer to a reasonable value to complete the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	 * panic, if the watchdog timer is running.  Plus the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	 * pretimeout is meaningless at panic time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	if (watchdog_user && !panic_event_handled &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	    ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		/* Make sure we do this only once. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		panic_event_handled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		timeout = panic_wdt_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		pretimeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		panic_halt_ipmi_set_timeout();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) static const struct ipmi_user_hndl ipmi_hndlrs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	.ipmi_recv_hndl           = ipmi_wdog_msg_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	.ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	.ipmi_panic_handler       = ipmi_wdog_panic_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) static void ipmi_register_watchdog(int ipmi_intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	int rv = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (watchdog_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if ((ifnum_to_use >= 0) && (ifnum_to_use != ipmi_intf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	watchdog_ifnum = ipmi_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	rv = ipmi_create_user(ipmi_intf, &ipmi_hndlrs, NULL, &watchdog_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		pr_crit("Unable to register with ipmi\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	rv = ipmi_get_version(watchdog_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 			      &ipmi_version_major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			      &ipmi_version_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		pr_warn("Unable to get IPMI version, assuming 1.0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		ipmi_version_major = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		ipmi_version_minor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	rv = misc_register(&ipmi_wdog_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	if (rv < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		ipmi_destroy_user(watchdog_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		watchdog_user = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		pr_crit("Unable to register misc device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (nmi_handler_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		int old_pretimeout = pretimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		int old_timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		int old_preop_val = preop_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		 * Set the pretimeout to go off in a second and give
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		 * ourselves plenty of time to stop the timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		ipmi_watchdog_state = WDOG_TIMEOUT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		preop_val = WDOG_PREOP_NONE; /* Make sure nothing happens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		pretimeout = 99;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		timeout = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		testing_nmi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		rv = ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			pr_warn("Error starting timer to test NMI: 0x%x.  The NMI pretimeout will likely not work\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			goto out_restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		msleep(1500);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		if (testing_nmi != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			pr_warn("IPMI NMI didn't seem to occur.  The NMI pretimeout will likely not work\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)  out_restore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		testing_nmi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		preop_val = old_preop_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		pretimeout = old_pretimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		timeout = old_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if ((start_now) && (rv == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		/* Run from startup, so start the timer now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		start_now = 0; /* Disable this function after first startup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		ipmi_watchdog_state = action_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		ipmi_set_timeout(IPMI_SET_TIMEOUT_FORCE_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		pr_info("Starting now!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		/* Stop the timer now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) static void ipmi_unregister_watchdog(int ipmi_intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	struct ipmi_user *loc_user = watchdog_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	if (!loc_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	if (watchdog_ifnum != ipmi_intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	/* Make sure no one can call us any more. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	misc_deregister(&ipmi_wdog_miscdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	watchdog_user = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	 * Wait to make sure the message makes it out.  The lower layer has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	 * pointers to our buffers, we want to make sure they are done before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	 * we release our memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	while (atomic_read(&msg_tofree))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		msg_free_smi(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	mutex_lock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	/* Disconnect from IPMI. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	rv = ipmi_destroy_user(loc_user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		pr_warn("error unlinking from IPMI: %d\n",  rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	/* If it comes back, restart it properly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	ipmi_start_timer_on_heartbeat = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	mutex_unlock(&ipmi_watchdog_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) ipmi_nmi(unsigned int val, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	 * If we get here, it's an NMI that's not a memory or I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	 * error.  We can't truly tell if it's from IPMI or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	 * without sending a message, and sending a message is almost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	 * impossible because of locking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	if (testing_nmi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		testing_nmi = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		return NMI_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	/* If we are not expecting a timeout, ignore it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		return NMI_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if (preaction_val != WDOG_PRETIMEOUT_NMI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		return NMI_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	 * If no one else handled the NMI, we assume it was the IPMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	 * watchdog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (preop_val == WDOG_PREOP_PANIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		/* On some machines, the heartbeat will give
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		   an error and not work unless we re-enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		   the timer.   So do so. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		atomic_set(&pretimeout_since_last_heartbeat, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		if (atomic_inc_and_test(&preop_panic_excl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			nmi_panic(regs, "pre-timeout");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	return NMI_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static int wdog_reboot_handler(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 			       unsigned long         code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 			       void                  *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	static int reboot_event_handled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if ((watchdog_user) && (!reboot_event_handled)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		/* Make sure we only do this once. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		reboot_event_handled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		if (code == SYS_POWER_OFF || code == SYS_HALT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			/* Disable the WDT if we are shutting down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 			ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 			ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		} else if (ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 			/* Set a long timer to let the reboot happen or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			   reset if it hangs, but only if the watchdog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 			   timer was already running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 			if (timeout < 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 				timeout = 120;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			pretimeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 			ipmi_watchdog_state = WDOG_TIMEOUT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 			ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) static struct notifier_block wdog_reboot_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	.notifier_call	= wdog_reboot_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	.next		= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	.priority	= 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) static void ipmi_new_smi(int if_num, struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	ipmi_register_watchdog(if_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static void ipmi_smi_gone(int if_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	ipmi_unregister_watchdog(if_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) static struct ipmi_smi_watcher smi_watcher = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	.owner    = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	.new_smi  = ipmi_new_smi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	.smi_gone = ipmi_smi_gone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) static int action_op(const char *inval, char *outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	if (outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		strcpy(outval, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	if (!inval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	if (strcmp(inval, "reset") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		action_val = WDOG_TIMEOUT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	else if (strcmp(inval, "none") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		action_val = WDOG_TIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	else if (strcmp(inval, "power_cycle") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		action_val = WDOG_TIMEOUT_POWER_CYCLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	else if (strcmp(inval, "power_off") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		action_val = WDOG_TIMEOUT_POWER_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	strcpy(action, inval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) static int preaction_op(const char *inval, char *outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	if (outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		strcpy(outval, preaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	if (!inval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	if (strcmp(inval, "pre_none") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		preaction_val = WDOG_PRETIMEOUT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	else if (strcmp(inval, "pre_smi") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		preaction_val = WDOG_PRETIMEOUT_SMI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	else if (strcmp(inval, "pre_nmi") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		preaction_val = WDOG_PRETIMEOUT_NMI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	else if (strcmp(inval, "pre_int") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		preaction_val = WDOG_PRETIMEOUT_MSG_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	strcpy(preaction, inval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) static int preop_op(const char *inval, char *outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		strcpy(outval, preop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	if (!inval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	if (strcmp(inval, "preop_none") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		preop_val = WDOG_PREOP_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	else if (strcmp(inval, "preop_panic") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		preop_val = WDOG_PREOP_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	else if (strcmp(inval, "preop_give_data") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		preop_val = WDOG_PREOP_GIVE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	strcpy(preop, inval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static void check_parms(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	int do_nmi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	if (preaction_val == WDOG_PRETIMEOUT_NMI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		do_nmi = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		if (preop_val == WDOG_PREOP_GIVE_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 			pr_warn("Pretimeout op is to give data but NMI pretimeout is enabled, setting pretimeout op to none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 			preop_op("preop_none", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			do_nmi = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	if (do_nmi && !nmi_handler_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		rv = register_nmi_handler(NMI_UNKNOWN, ipmi_nmi, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 						"ipmi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 			pr_warn("Can't register nmi handler\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 			nmi_handler_registered = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	} else if (!do_nmi && nmi_handler_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		unregister_nmi_handler(NMI_UNKNOWN, "ipmi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		nmi_handler_registered = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) static int __init ipmi_wdog_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	if (action_op(action, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		action_op("reset", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		pr_info("Unknown action '%s', defaulting to reset\n", action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	if (preaction_op(preaction, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		preaction_op("pre_none", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		pr_info("Unknown preaction '%s', defaulting to none\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 			preaction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	if (preop_op(preop, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		preop_op("preop_none", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		pr_info("Unknown preop '%s', defaulting to none\n", preop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	check_parms();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	register_reboot_notifier(&wdog_reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	rv = ipmi_smi_watcher_register(&smi_watcher);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		if (nmi_handler_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			unregister_nmi_handler(NMI_UNKNOWN, "ipmi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		unregister_reboot_notifier(&wdog_reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		pr_warn("can't register smi watcher\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	pr_info("driver initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static void __exit ipmi_wdog_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	ipmi_smi_watcher_unregister(&smi_watcher);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	ipmi_unregister_watchdog(watchdog_ifnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) #ifdef HAVE_DIE_NMI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	if (nmi_handler_registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		unregister_nmi_handler(NMI_UNKNOWN, "ipmi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	unregister_reboot_notifier(&wdog_reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) module_exit(ipmi_wdog_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) module_init(ipmi_wdog_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) MODULE_DESCRIPTION("watchdog timer based upon the IPMI interface.");