r_heartbeat.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "ibmasm.h"
  22. #include "dot_command.h"
  23. /*
  24. * Reverse Heartbeat, i.e. heartbeats sent from the driver to the
  25. * service processor.
  26. * These heartbeats are initiated by user level programs.
  27. */
  28. /* the reverse heartbeat dot command */
  29. #pragma pack(1)
  30. static struct {
  31. struct dot_command_header header;
  32. unsigned char command[3];
  33. } rhb_dot_cmd = {
  34. .header = {
  35. .type = sp_read,
  36. .command_size = 3,
  37. .data_size = 0,
  38. .status = 0
  39. },
  40. .command = { 4, 3, 6 }
  41. };
  42. #pragma pack()
  43. void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
  44. {
  45. init_waitqueue_head(&rhb->wait);
  46. rhb->stopped = 0;
  47. }
  48. /**
  49. * start_reverse_heartbeat
  50. * Loop forever, sending a reverse heartbeat dot command to the service
  51. * processor, then sleeping. The loop comes to an end if the service
  52. * processor fails to respond 3 times or we were interrupted.
  53. */
  54. int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb)
  55. {
  56. struct command *cmd;
  57. int times_failed = 0;
  58. int result = 1;
  59. cmd = ibmasm_new_command(sp, sizeof rhb_dot_cmd);
  60. if (!cmd)
  61. return -ENOMEM;
  62. while (times_failed < 3) {
  63. memcpy(cmd->buffer, (void *)&rhb_dot_cmd, sizeof rhb_dot_cmd);
  64. cmd->status = IBMASM_CMD_PENDING;
  65. ibmasm_exec_command(sp, cmd);
  66. ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
  67. if (cmd->status != IBMASM_CMD_COMPLETE)
  68. times_failed++;
  69. wait_event_interruptible_timeout(rhb->wait,
  70. rhb->stopped,
  71. REVERSE_HEARTBEAT_TIMEOUT * HZ);
  72. if (signal_pending(current) || rhb->stopped) {
  73. result = -EINTR;
  74. break;
  75. }
  76. }
  77. command_put(cmd);
  78. rhb->stopped = 0;
  79. return result;
  80. }
  81. void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb)
  82. {
  83. rhb->stopped = 1;
  84. wake_up_interruptible(&rhb->wait);
  85. }