1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * IBM ASM Service Processor Device Driver
6 * Copyright (C) IBM Corporation, 2004
11 #include <linux/notifier.h>
12 #include <linux/panic_notifier.h>
14 #include "dot_command.h"
17 static int suspend_heartbeats = 0;
20 * Once the driver indicates to the service processor that it is running
21 * - see send_os_state() - the service processor sends periodic heartbeats
22 * to the driver. The driver must respond to the heartbeats or else the OS
24 * In the case of a panic the interrupt handler continues to work and thus
25 * continues to respond to heartbeats, making the service processor believe
26 * the OS is still running and thus preventing a reboot.
27 * To prevent this from happening a callback is added the panic_notifier_list.
28 * Before responding to a heartbeat the driver checks if a panic has happened,
29 * if yes it suspends heartbeat, causing the service processor to reboot as
32 static int panic_happened(struct notifier_block *n, unsigned long val, void *v)
34 suspend_heartbeats = 1;
38 static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
40 void ibmasm_register_panic_notifier(void)
42 atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);
45 void ibmasm_unregister_panic_notifier(void)
47 atomic_notifier_chain_unregister(&panic_notifier_list,
52 int ibmasm_heartbeat_init(struct service_processor *sp)
54 sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE);
55 if (sp->heartbeat == NULL)
61 void ibmasm_heartbeat_exit(struct service_processor *sp)
65 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
66 ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL);
67 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
68 suspend_heartbeats = 1;
69 command_put(sp->heartbeat);
72 void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
74 struct command *cmd = sp->heartbeat;
75 struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
78 dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
79 if (suspend_heartbeats)
82 /* return the received dot command to sender */
83 cmd->status = IBMASM_CMD_PENDING;
84 size = min(size, cmd->buffer_size);
85 memcpy_fromio(cmd->buffer, message, size);
86 header->type = sp_write;
87 ibmasm_exec_command(sp, cmd);