^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * IBM ASM Service Processor Device Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) IBM Corporation, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author: Max Asböck <amax@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ibmasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "dot_command.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "lowlevel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int suspend_heartbeats = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Once the driver indicates to the service processor that it is running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * - see send_os_state() - the service processor sends periodic heartbeats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * to the driver. The driver must respond to the heartbeats or else the OS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * will be rebooted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * In the case of a panic the interrupt handler continues to work and thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * continues to respond to heartbeats, making the service processor believe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * the OS is still running and thus preventing a reboot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * To prevent this from happening a callback is added the panic_notifier_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Before responding to a heartbeat the driver checks if a panic has happened,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * if yes it suspends heartbeat, causing the service processor to reboot as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int panic_happened(struct notifier_block *n, unsigned long val, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) suspend_heartbeats = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void ibmasm_register_panic_notifier(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void ibmasm_unregister_panic_notifier(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) atomic_notifier_chain_unregister(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) &panic_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int ibmasm_heartbeat_init(struct service_processor *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (sp->heartbeat == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void ibmasm_heartbeat_exit(struct service_processor *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) char tsbuf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) suspend_heartbeats = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) command_put(sp->heartbeat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct command *cmd = sp->heartbeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) char tsbuf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (suspend_heartbeats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* return the received dot command to sender */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) cmd->status = IBMASM_CMD_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) size = min(size, cmd->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) memcpy_fromio(cmd->buffer, message, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) header->type = sp_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ibmasm_exec_command(sp, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }