drivers/char/ipmi/ipmi_watchdog.c
Source file repositories/reference/linux-study-clean/drivers/char/ipmi/ipmi_watchdog.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ipmi/ipmi_watchdog.c- Extension
.c- Size
- 32192 bytes
- Lines
- 1326
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/moduleparam.hlinux/ipmi.hlinux/ipmi_smi.hlinux/mutex.hlinux/watchdog.hlinux/miscdevice.hlinux/init.hlinux/completion.hlinux/kdebug.hlinux/kstrtox.hlinux/rwsem.hlinux/errno.hlinux/uaccess.hlinux/notifier.hlinux/nmi.hlinux/reboot.hlinux/wait.hlinux/poll.hlinux/string.hlinux/ctype.hlinux/delay.hlinux/atomic.hlinux/sched/signal.hasm/kdebug.hasm/nmi.h
Detected Declarations
function set_param_timeoutfunction set_param_strfunction get_param_strfunction set_param_wdog_ifnumfunction msg_free_smifunction msg_free_recvfunction __ipmi_set_timeoutfunction _ipmi_set_timeoutfunction ipmi_set_timeoutfunction panic_halt_ipmi_heartbeatfunction panic_halt_ipmi_set_timeoutfunction __ipmi_heartbeatfunction _ipmi_heartbeatfunction ipmi_heartbeatfunction ipmi_ioctlfunction ipmi_unlocked_ioctlfunction ipmi_writefunction ipmi_readfunction ipmi_openfunction ipmi_pollfunction ipmi_fasyncfunction ipmi_closefunction ipmi_wdog_msg_handlerfunction ipmi_wdog_pretimeout_handlerfunction ipmi_wdog_panic_handlerfunction ipmi_register_watchdogfunction ipmi_unregister_watchdogfunction ipmi_nmifunction wdog_reboot_handlerfunction ipmi_new_smifunction ipmi_smi_gonefunction action_op_set_valfunction action_opfunction preaction_op_set_valfunction preaction_opfunction preop_op_set_valfunction preop_opfunction check_parmsfunction ipmi_wdog_initfunction ipmi_wdog_exitmodule init ipmi_wdog_init
Annotated Snippet
static const struct file_operations ipmi_wdog_fops = {
.owner = THIS_MODULE,
.read = ipmi_read,
.poll = ipmi_poll,
.write = ipmi_write,
.unlocked_ioctl = ipmi_unlocked_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = ipmi_open,
.release = ipmi_close,
.fasync = ipmi_fasync,
};
static struct miscdevice ipmi_wdog_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &ipmi_wdog_fops
};
static void ipmi_wdog_msg_handler(struct ipmi_recv_msg *msg,
void *handler_data)
{
if (msg->msg.cmd == IPMI_WDOG_RESET_TIMER &&
msg->msg.data[0] == IPMI_WDOG_TIMER_NOT_INIT_RESP)
pr_info("response: The IPMI controller appears to have been reset, will attempt to reinitialize the watchdog timer\n");
else if (msg->msg.data[0] != 0)
pr_err("response: Error %x on cmd %x\n",
msg->msg.data[0],
msg->msg.cmd);
ipmi_free_recv_msg(msg);
}
static void ipmi_wdog_pretimeout_handler(void *handler_data)
{
if (preaction_val != WDOG_PRETIMEOUT_NONE) {
if (preop_val == WDOG_PREOP_PANIC) {
if (atomic_inc_and_test(&preop_panic_excl))
panic("Watchdog pre-timeout");
} else if (preop_val == WDOG_PREOP_GIVE_DATA) {
mutex_lock(&ipmi_read_mutex);
data_to_read = 1;
wake_up_interruptible(&read_q);
kill_fasync(&fasync_q, SIGIO, POLL_IN);
mutex_unlock(&ipmi_read_mutex);
}
}
/*
* On some machines, the heartbeat will give an error and not
* work unless we re-enable the timer. So do so.
*/
atomic_set(&pretimeout_since_last_heartbeat, 1);
}
static void ipmi_wdog_panic_handler(void *user_data)
{
static int panic_event_handled;
/*
* On a panic, if we have a panic timeout, make sure to extend
* the watchdog timer to a reasonable value to complete the
* panic, if the watchdog timer is running. Plus the
* pretimeout is meaningless at panic time.
*/
if (watchdog_user && !panic_event_handled &&
ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
/* Make sure we do this only once. */
panic_event_handled = 1;
timeout = panic_wdt_timeout;
pretimeout = 0;
panic_halt_ipmi_set_timeout();
}
}
static const struct ipmi_user_hndl ipmi_hndlrs = {
.ipmi_recv_hndl = ipmi_wdog_msg_handler,
.ipmi_watchdog_pretimeout = ipmi_wdog_pretimeout_handler,
.ipmi_panic_handler = ipmi_wdog_panic_handler
};
static void ipmi_register_watchdog(int ipmi_intf)
{
int rv = -EBUSY;
if (watchdog_user)
goto out;
if ((ifnum_to_use >= 0) && (ifnum_to_use != ipmi_intf))
goto out;
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/ipmi.h`, `linux/ipmi_smi.h`, `linux/mutex.h`, `linux/watchdog.h`, `linux/miscdevice.h`, `linux/init.h`.
- Detected declarations: `function set_param_timeout`, `function set_param_str`, `function get_param_str`, `function set_param_wdog_ifnum`, `function msg_free_smi`, `function msg_free_recv`, `function __ipmi_set_timeout`, `function _ipmi_set_timeout`, `function ipmi_set_timeout`, `function panic_halt_ipmi_heartbeat`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.