heartbeat.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * IBM ASM Service Processor Device Driver
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright (C) IBM Corporation, 2004
  19. *
  20. * Author: Max Asböck <amax@us.ibm.com>
  21. *
  22. */
  23. #include <linux/notifier.h>
  24. #include "ibmasm.h"
  25. #include "dot_command.h"
  26. static int suspend_heartbeats = 0;
  27. /*
  28. * Once the driver indicates to the service processor that it is running
  29. * - see send_os_state() - the service processor sends periodic heartbeats
  30. * to the driver. The driver must respond to the heartbeats or else the OS
  31. * will be rebooted.
  32. * In the case of a panic the interrupt handler continues to work and thus
  33. * continues to respond to heartbeats, making the service processor believe
  34. * the OS is still running and thus preventing a reboot.
  35. * To prevent this from happening a callback is added the panic_notifier_list.
  36. * Before responding to a heartbeat the driver checks if a panic has happened,
  37. * if yes it suspends heartbeat, causing the service processor to reboot as
  38. * expected.
  39. */
  40. static int panic_happened(struct notifier_block *n, unsigned long val, void *v)
  41. {
  42. suspend_heartbeats = 1;
  43. return 0;
  44. }
  45. static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
  46. void ibmasm_register_panic_notifier(void)
  47. {
  48. notifier_chain_register(&panic_notifier_list, &panic_notifier);
  49. }
  50. void ibmasm_unregister_panic_notifier(void)
  51. {
  52. notifier_chain_unregister(&panic_notifier_list, &panic_notifier);
  53. }
  54. int ibmasm_heartbeat_init(struct service_processor *sp)
  55. {
  56. sp->heartbeat = ibmasm_new_command(HEARTBEAT_BUFFER_SIZE);
  57. if (sp->heartbeat == NULL)
  58. return -ENOMEM;
  59. return 0;
  60. }
  61. void ibmasm_heartbeat_exit(struct service_processor *sp)
  62. {
  63. command_put(sp->heartbeat);
  64. }
  65. void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
  66. {
  67. struct command *cmd = sp->heartbeat;
  68. struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
  69. if (suspend_heartbeats)
  70. return;
  71. /* return the received dot command to sender */
  72. cmd->status = IBMASM_CMD_PENDING;
  73. size = min(size, cmd->buffer_size);
  74. memcpy(cmd->buffer, message, size);
  75. header->type = sp_write;
  76. ibmasm_exec_command(sp, cmd);
  77. }