linux/drivers/char/ipmi/ipmi_watchdog.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * ipmi_watchdog.c
 *
 * A watchdog timer based upon the IPMI interface.
 *
 * Author: MontaVista Software, Inc.
 *         Corey Minyard <[email protected]>
 *         [email protected]
 *
 * Copyright 2002 MontaVista Software Inc.
 */

#define pr_fmt(fmt)

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/ipmi.h>
#include <linux/ipmi_smi.h>
#include <linux/mutex.h>
#include <linux/watchdog.h>
#include <linux/miscdevice.h>
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/kdebug.h>
#include <linux/kstrtox.h>
#include <linux/rwsem.h>
#include <linux/errno.h>
#include <linux/uaccess.h>
#include <linux/notifier.h>
#include <linux/nmi.h>
#include <linux/reboot.h>
#include <linux/wait.h>
#include <linux/poll.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/atomic.h>
#include <linux/sched/signal.h>

#ifdef CONFIG_X86
/*
 * This is ugly, but I've determined that x86 is the only architecture
 * that can reasonably support the IPMI NMI watchdog timeout at this
 * time.  If another architecture adds this capability somehow, it
 * will have to be a somewhat different mechanism and I have no idea
 * how it will work.  So in the unlikely event that another
 * architecture supports this, we can figure out a good generic
 * mechanism for it at that time.
 */
#include <asm/kdebug.h>
#include <asm/nmi.h>
#define HAVE_DIE_NMI
#endif

/*
 * The IPMI command/response information for the watchdog timer.
 */

/* values for byte 1 of the set command, byte 2 of the get response. */
#define WDOG_DONT_LOG
#define WDOG_DONT_STOP_ON_SET
#define WDOG_SET_TIMER_USE(byte, use)
#define WDOG_GET_TIMER_USE(byte)
#define WDOG_TIMER_USE_BIOS_FRB2
#define WDOG_TIMER_USE_BIOS_POST
#define WDOG_TIMER_USE_OS_LOAD
#define WDOG_TIMER_USE_SMS_OS
#define WDOG_TIMER_USE_OEM

/* values for byte 2 of the set command, byte 3 of the get response. */
#define WDOG_SET_PRETIMEOUT_ACT(byte, use)
#define WDOG_GET_PRETIMEOUT_ACT(byte)
#define WDOG_PRETIMEOUT_NONE
#define WDOG_PRETIMEOUT_SMI
#define WDOG_PRETIMEOUT_NMI
#define WDOG_PRETIMEOUT_MSG_INT

/* Operations that can be performed on a pretimout. */
#define WDOG_PREOP_NONE
#define WDOG_PREOP_PANIC
/* Cause data to be available to read.  Doesn't work in NMI mode. */
#define WDOG_PREOP_GIVE_DATA

/* Actions to perform on a full timeout. */
#define WDOG_SET_TIMEOUT_ACT(byte, use)
#define WDOG_GET_TIMEOUT_ACT(byte)
#define WDOG_TIMEOUT_NONE
#define WDOG_TIMEOUT_RESET
#define WDOG_TIMEOUT_POWER_DOWN
#define WDOG_TIMEOUT_POWER_CYCLE

/*
 * Byte 3 of the get command, byte 4 of the get response is the
 * pre-timeout in seconds.
 */

/* Bits for setting byte 4 of the set command, byte 5 of the get response. */
#define WDOG_EXPIRE_CLEAR_BIOS_FRB2
#define WDOG_EXPIRE_CLEAR_BIOS_POST
#define WDOG_EXPIRE_CLEAR_OS_LOAD
#define WDOG_EXPIRE_CLEAR_SMS_OS
#define WDOG_EXPIRE_CLEAR_OEM

/*
 * Setting/getting the watchdog timer value.  This is for bytes 5 and
 * 6 (the timeout time) of the set command, and bytes 6 and 7 (the
 * timeout time) and 8 and 9 (the current countdown value) of the
 * response.  The timeout value is given in seconds (in the command it
 * is 100ms intervals).
 */
#define WDOG_SET_TIMEOUT(byte1, byte2, val)
#define WDOG_GET_TIMEOUT(byte1, byte2)

#define IPMI_WDOG_RESET_TIMER
#define IPMI_WDOG_SET_TIMER
#define IPMI_WDOG_GET_TIMER

#define IPMI_WDOG_TIMER_NOT_INIT_RESP

static DEFINE_MUTEX(ipmi_watchdog_mutex);
static bool nowayout = WATCHDOG_NOWAYOUT;

static struct ipmi_user *watchdog_user;
static int watchdog_ifnum;

/* Default the timeout to 10 seconds. */
static int timeout =;

/* The pre-timeout is disabled by default. */
static int pretimeout;

/* Default timeout to set on panic */
static int panic_wdt_timeout =;

/* Default action is to reset the board on a timeout. */
static unsigned char action_val =;

static char action[16] =;

static unsigned char preaction_val =;

static char preaction[16] =;

static unsigned char preop_val =;

static char preop[16] =;
static DEFINE_SPINLOCK(ipmi_read_lock);
static char data_to_read;
static DECLARE_WAIT_QUEUE_HEAD(read_q);
static struct fasync_struct *fasync_q;
static atomic_t pretimeout_since_last_heartbeat;
static char expect_close;

static int ifnum_to_use =;

/* Parameters to ipmi_set_timeout */
#define IPMI_SET_TIMEOUT_NO_HB
#define IPMI_SET_TIMEOUT_HB_IF_NECESSARY
#define IPMI_SET_TIMEOUT_FORCE_HB

static int ipmi_set_timeout(int do_heartbeat);
static void ipmi_register_watchdog(int ipmi_intf);
static void ipmi_unregister_watchdog(int ipmi_intf);

/*
 * If true, the driver will start running as soon as it is configured
 * and ready.
 */
static int start_now;

static int set_param_timeout(const char *val, const struct kernel_param *kp)
{}

static const struct kernel_param_ops param_ops_timeout =;
#define param_check_timeout

action_fn;

static int action_op(const char *inval, char *outval);
static int preaction_op(const char *inval, char *outval);
static int preop_op(const char *inval, char *outval);
static void check_parms(void);

static int set_param_str(const char *val, const struct kernel_param *kp)
{}

static int get_param_str(char *buffer, const struct kernel_param *kp)
{}


static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)
{}

static const struct kernel_param_ops param_ops_wdog_ifnum =;

#define param_check_wdog_ifnum

static const struct kernel_param_ops param_ops_str =;

module_param(ifnum_to_use, wdog_ifnum, 0644);
MODULE_PARM_DESC();

module_param(timeout, timeout, 0644);
MODULE_PARM_DESC();

module_param(pretimeout, timeout, 0644);
MODULE_PARM_DESC();

module_param(panic_wdt_timeout, timeout, 0644);
MODULE_PARM_DESC();

module_param_cb();
MODULE_PARM_DESC();

module_param_cb();
MODULE_PARM_DESC();

module_param_cb();
MODULE_PARM_DESC();

module_param(start_now, int, 0444);
MODULE_PARM_DESC();

module_param(nowayout, bool, 0644);
MODULE_PARM_DESC();

/* Default state of the timer. */
static unsigned char ipmi_watchdog_state =;

/* Is someone using the watchdog?  Only one user is allowed. */
static unsigned long ipmi_wdog_open;

/*
 * If set to 1, the heartbeat command will set the state to reset and
 * start the timer.  The timer doesn't normally run when the driver is
 * first opened until the heartbeat is set the first time, this
 * variable is used to accomplish this.
 */
static int ipmi_start_timer_on_heartbeat;

/* IPMI version of the BMC. */
static unsigned char ipmi_version_major;
static unsigned char ipmi_version_minor;

/* If a pretimeout occurs, this is used to allow only one panic to happen. */
static atomic_t preop_panic_excl =;

#ifdef HAVE_DIE_NMI
static int testing_nmi;
static int nmi_handler_registered;
#endif

static int __ipmi_heartbeat(void);

/*
 * We use a mutex to make sure that only one thing can send a set a
 * message at one time.  The mutex is claimed when a message is sent
 * and freed when both the send and receive messages are free.
 */
static atomic_t msg_tofree =;
static DECLARE_COMPLETION(msg_wait);
static void msg_free_smi(struct ipmi_smi_msg *msg)
{}
static void msg_free_recv(struct ipmi_recv_msg *msg)
{}
static struct ipmi_smi_msg smi_msg =;
static struct ipmi_recv_msg recv_msg =;

static int __ipmi_set_timeout(struct ipmi_smi_msg  *smi_msg,
			      struct ipmi_recv_msg *recv_msg,
			      int                  *send_heartbeat_now)
{}

static int _ipmi_set_timeout(int do_heartbeat)
{}

static int ipmi_set_timeout(int do_heartbeat)
{}

static atomic_t panic_done_count =;

static void panic_smi_free(struct ipmi_smi_msg *msg)
{}
static void panic_recv_free(struct ipmi_recv_msg *msg)
{}

static struct ipmi_smi_msg panic_halt_heartbeat_smi_msg =;
static struct ipmi_recv_msg panic_halt_heartbeat_recv_msg =;

static void panic_halt_ipmi_heartbeat(void)
{}

static struct ipmi_smi_msg panic_halt_smi_msg =;
static struct ipmi_recv_msg panic_halt_recv_msg =;

/*
 * Special call, doesn't claim any locks.  This is only to be called
 * at panic or halt time, in run-to-completion mode, when the caller
 * is the only CPU and the only thing that will be going is these IPMI
 * calls.
 */
static void panic_halt_ipmi_set_timeout(void)
{}

static int __ipmi_heartbeat(void)
{}

static int _ipmi_heartbeat(void)
{}

static int ipmi_heartbeat(void)
{}

static const struct watchdog_info ident =;

static int ipmi_ioctl(struct file *file,
		      unsigned int cmd, unsigned long arg)
{}

static long ipmi_unlocked_ioctl(struct file *file,
				unsigned int cmd,
				unsigned long arg)
{}

static ssize_t ipmi_write(struct file *file,
			  const char  __user *buf,
			  size_t      len,
			  loff_t      *ppos)
{}

static ssize_t ipmi_read(struct file *file,
			 char        __user *buf,
			 size_t      count,
			 loff_t      *ppos)
{}

static int ipmi_open(struct inode *ino, struct file *filep)
{}

static __poll_t ipmi_poll(struct file *file, poll_table *wait)
{}

static int ipmi_fasync(int fd, struct file *file, int on)
{}

static int ipmi_close(struct inode *ino, struct file *filep)
{}

static const struct file_operations ipmi_wdog_fops =;

static struct miscdevice ipmi_wdog_miscdev =;

static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
				  void                 *handler_data)
{}

static void ipmi_wdog_pretimeout_handler(void *handler_data)
{}

static void ipmi_wdog_panic_handler(void *user_data)
{}

static const struct ipmi_user_hndl ipmi_hndlrs =;

static void ipmi_register_watchdog(int ipmi_intf)
{}

static void ipmi_unregister_watchdog(int ipmi_intf)
{}

#ifdef HAVE_DIE_NMI
static int
ipmi_nmi(unsigned int val, struct pt_regs *regs)
{}
#endif

static int wdog_reboot_handler(struct notifier_block *this,
			       unsigned long         code,
			       void                  *unused)
{}

static struct notifier_block wdog_reboot_notifier =;

static void ipmi_new_smi(int if_num, struct device *device)
{}

static void ipmi_smi_gone(int if_num)
{}

static struct ipmi_smi_watcher smi_watcher =;

static int action_op(const char *inval, char *outval)
{}

static int preaction_op(const char *inval, char *outval)
{}

static int preop_op(const char *inval, char *outval)
{}

static void check_parms(void)
{}

static int __init ipmi_wdog_init(void)
{}

static void __exit ipmi_wdog_exit(void)
{}
module_exit(ipmi_wdog_exit);
module_init();
MODULE_LICENSE();
MODULE_AUTHOR();
MODULE_DESCRIPTION();