heartbeat.c 2.5 KB

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