heartbeat.c 2.5 KB

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