dot_command.c 3.3 KB

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