heartbeat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #include "lowlevel.h"
  27. static int suspend_heartbeats = 0;
  28. /*
  29. * Once the driver indicates to the service processor that it is running
  30. * - see send_os_state() - the service processor sends periodic heartbeats
  31. * to the driver. The driver must respond to the heartbeats or else the OS
  32. * will be rebooted.
  33. * In the case of a panic the interrupt handler continues to work and thus
  34. * continues to respond to heartbeats, making the service processor believe
  35. * the OS is still running and thus preventing a reboot.
  36. * To prevent this from happening a callback is added the panic_notifier_list.
  37. * Before responding to a heartbeat the driver checks if a panic has happened,
  38. * if yes it suspends heartbeat, causing the service processor to reboot as
  39. * expected.
  40. */
  41. static int panic_happened(struct notifier_block *n, unsigned long val, void *v)
  42. {
  43. suspend_heartbeats = 1;
  44. return 0;
  45. }
  46. static struct notifier_block panic_notifier = { panic_happened, NULL, 1 };
  47. void ibmasm_register_panic_notifier(void)
  48. {
  49. notifier_chain_register(&panic_notifier_list, &panic_notifier);
  50. }
  51. void ibmasm_unregister_panic_notifier(void)
  52. {
  53. notifier_chain_unregister(&panic_notifier_list, &panic_notifier);
  54. }
  55. int ibmasm_heartbeat_init(struct service_processor *sp)
  56. {
  57. sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE);
  58. if (sp->heartbeat == NULL)
  59. return -ENOMEM;
  60. return 0;
  61. }
  62. void ibmasm_heartbeat_exit(struct service_processor *sp)
  63. {
  64. char tsbuf[32];
  65. dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf));
  66. ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL);
  67. dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf));
  68. suspend_heartbeats = 1;
  69. command_put(sp->heartbeat);
  70. }
  71. void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
  72. {
  73. struct command *cmd = sp->heartbeat;
  74. struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
  75. char tsbuf[32];
  76. dbg("%s:%d at %s\n", __FUNCTION__, __LINE__, get_timestamp(tsbuf));
  77. if (suspend_heartbeats)
  78. return;
  79. /* return the received dot command to sender */
  80. cmd->status = IBMASM_CMD_PENDING;
  81. size = min(size, cmd->buffer_size);
  82. memcpy_fromio(cmd->buffer, message, size);
  83. header->type = sp_write;
  84. ibmasm_exec_command(sp, cmd);
  85. }