dot_command.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "ibmasm.h"
  24. #include "dot_command.h"
  25. /**
  26. * Dispatch an incoming message to the specific handler for the message.
  27. * Called from interrupt context.
  28. */
  29. void ibmasm_receive_message(struct service_processor *sp, void *message, int message_size)
  30. {
  31. u32 size;
  32. struct dot_command_header *header = (struct dot_command_header *)message;
  33. size = get_dot_command_size(message);
  34. if (size > message_size)
  35. size = message_size;
  36. switch (header->type) {
  37. case sp_event:
  38. ibmasm_receive_event(sp, message, size);
  39. break;
  40. case sp_command_response:
  41. ibmasm_receive_command_response(sp, message, size);
  42. break;
  43. case sp_heartbeat:
  44. ibmasm_receive_heartbeat(sp, message, size);
  45. break;
  46. default:
  47. dev_err(sp->dev, "Received unknown message from service processor\n");
  48. }
  49. }
  50. #define INIT_BUFFER_SIZE 32
  51. /**
  52. * send the 4.3.5.10 dot command (driver VPD) to the service processor
  53. */
  54. int ibmasm_send_driver_vpd(struct service_processor *sp)
  55. {
  56. struct command *command;
  57. struct dot_command_header *header;
  58. u8 *vpd_command;
  59. u8 *vpd_data;
  60. int result = 0;
  61. command = ibmasm_new_command(INIT_BUFFER_SIZE);
  62. if (command == NULL)
  63. return -ENOMEM;
  64. header = (struct dot_command_header *)command->buffer;
  65. header->type = sp_write;
  66. header->command_size = 4;
  67. header->data_size = 16;
  68. header->status = 0;
  69. header->reserved = 0;
  70. vpd_command = command->buffer + sizeof(struct dot_command_header);
  71. vpd_command[0] = 0x4;
  72. vpd_command[1] = 0x3;
  73. vpd_command[2] = 0x5;
  74. vpd_command[3] = 0xa;
  75. vpd_data = vpd_command + header->command_size;
  76. vpd_data[0] = 0;
  77. strcat(vpd_data, IBMASM_DRIVER_VPD);
  78. vpd_data[10] = 0;
  79. vpd_data[15] = 0;
  80. ibmasm_exec_command(sp, command);
  81. ibmasm_wait_for_response(command, IBMASM_CMD_TIMEOUT_NORMAL);
  82. if (command->status != IBMASM_CMD_COMPLETE)
  83. result = -ENODEV;
  84. command_put(command);
  85. return result;
  86. }
  87. struct os_state_command {
  88. struct dot_command_header header;
  89. unsigned char command[3];
  90. unsigned char data;
  91. };
  92. /**
  93. * send the 4.3.6 dot command (os state) to the service processor
  94. * During driver init this function is called with os state "up".
  95. * This causes the service processor to start sending heartbeats the
  96. * driver.
  97. * During driver exit the function is called with os state "down",
  98. * causing the service processor to stop the heartbeats.
  99. */
  100. int ibmasm_send_os_state(struct service_processor *sp, int os_state)
  101. {
  102. struct command *cmd;
  103. struct os_state_command *os_state_cmd;
  104. int result = 0;
  105. cmd = ibmasm_new_command(sizeof(struct os_state_command));
  106. if (cmd == NULL)
  107. return -ENOMEM;
  108. os_state_cmd = (struct os_state_command *)cmd->buffer;
  109. os_state_cmd->header.type = sp_write;
  110. os_state_cmd->header.command_size = 3;
  111. os_state_cmd->header.data_size = 1;
  112. os_state_cmd->header.status = 0;
  113. os_state_cmd->command[0] = 4;
  114. os_state_cmd->command[1] = 3;
  115. os_state_cmd->command[2] = 6;
  116. os_state_cmd->data = os_state;
  117. ibmasm_exec_command(sp, cmd);
  118. ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
  119. if (cmd->status != IBMASM_CMD_COMPLETE)
  120. result = -ENODEV;
  121. command_put(cmd);
  122. return result;
  123. }