r_heartbeat.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. *
  16. * Copyright (C) IBM Corporation, 2004
  17. *
  18. * Author: Max Asböck <amax@us.ibm.com>
  19. *
  20. */
  21. #include <linux/sched.h>
  22. #include "ibmasm.h"
  23. #include "dot_command.h"
  24. /*
  25. * Reverse Heartbeat, i.e. heartbeats sent from the driver to the
  26. * service processor.
  27. * These heartbeats are initiated by user level programs.
  28. */
  29. /* the reverse heartbeat dot command */
  30. #pragma pack(1)
  31. static struct {
  32. struct dot_command_header header;
  33. unsigned char command[3];
  34. } rhb_dot_cmd = {
  35. .header = {
  36. .type = sp_read,
  37. .command_size = 3,
  38. .data_size = 0,
  39. .status = 0
  40. },
  41. .command = { 4, 3, 6 }
  42. };
  43. #pragma pack()
  44. void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
  45. {
  46. init_waitqueue_head(&rhb->wait);
  47. rhb->stopped = 0;
  48. }
  49. /**
  50. * start_reverse_heartbeat
  51. * Loop forever, sending a reverse heartbeat dot command to the service
  52. * processor, then sleeping. The loop comes to an end if the service
  53. * processor fails to respond 3 times or we were interrupted.
  54. */
  55. int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
  56. {
  57. struct command *cmd;
  58. int times_failed = 0;
  59. int result = 1;
  60. cmd = ibmasm_new_command(sp, sizeof rhb_dot_cmd);
  61. if (!cmd)
  62. return -ENOMEM;
  63. while (times_failed < 3) {
  64. memcpy(cmd->buffer, (void *)&rhb_dot_cmd, sizeof rhb_dot_cmd);
  65. cmd->status = IBMASM_CMD_PENDING;
  66. ibmasm_exec_command(sp, cmd);
  67. ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
  68. if (cmd->status != IBMASM_CMD_COMPLETE)
  69. times_failed++;
  70. wait_event_interruptible_timeout(rhb->wait,
  71. rhb->stopped,
  72. REVERSE_HEARTBEAT_TIMEOUT * HZ);
  73. if (signal_pending(current) || rhb->stopped) {
  74. result = -EINTR;
  75. break;
  76. }
  77. }
  78. command_put(cmd);
  79. rhb->stopped = 0;
  80. return result;
  81. }
  82. void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb)
  83. {
  84. rhb->stopped = 1;
  85. wake_up_interruptible(&rhb->wait);
  86. }