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