heartbeat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. atomic_notifier_chain_register(&panic_notifier_list, &panic_notifier);
  50. }
  51. void ibmasm_unregister_panic_notifier(void)
  52. {
  53. atomic_notifier_chain_unregister(&panic_notifier_list,
  54. &panic_notifier);
  55. }
  56. int ibmasm_heartbeat_init(struct service_processor *sp)
  57. {
  58. sp->heartbeat = ibmasm_new_command(sp, HEARTBEAT_BUFFER_SIZE);
  59. if (sp->heartbeat == NULL)
  60. return -ENOMEM;
  61. return 0;
  62. }
  63. void ibmasm_heartbeat_exit(struct service_processor *sp)
  64. {
  65. char tsbuf[32];
  66. dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
  67. ibmasm_wait_for_response(sp->heartbeat, IBMASM_CMD_TIMEOUT_NORMAL);
  68. dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
  69. suspend_heartbeats = 1;
  70. command_put(sp->heartbeat);
  71. }
  72. void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size)
  73. {
  74. struct command *cmd = sp->heartbeat;
  75. struct dot_command_header *header = (struct dot_command_header *)cmd->buffer;
  76. char tsbuf[32];
  77. dbg("%s:%d at %s\n", __func__, __LINE__, get_timestamp(tsbuf));
  78. if (suspend_heartbeats)
  79. return;
  80. /* return the received dot command to sender */
  81. cmd->status = IBMASM_CMD_PENDING;
  82. size = min(size, cmd->buffer_size);
  83. memcpy_fromio(cmd->buffer, message, size);
  84. header->type = sp_write;
  85. ibmasm_exec_command(sp, cmd);
  86. }