Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * IBM ASM Service Processor Device Driver
0004  *
0005  * Copyright (C) IBM Corporation, 2004
0006  *
0007  * Author: Max Asböck <amax@us.ibm.com>
0008  */
0009 
0010 #include "ibmasm.h"
0011 #include "dot_command.h"
0012 
0013 /*
0014  * Dispatch an incoming message to the specific handler for the message.
0015  * Called from interrupt context.
0016  */
0017 void ibmasm_receive_message(struct service_processor *sp, void *message, int message_size)
0018 {
0019     u32 size;
0020     struct dot_command_header *header = (struct dot_command_header *)message;
0021 
0022     if (message_size == 0)
0023         return;
0024 
0025     size = get_dot_command_size(message);
0026     if (size == 0)
0027         return;
0028 
0029     if (size > message_size)
0030         size = message_size;
0031 
0032     switch (header->type) {
0033     case sp_event:
0034         ibmasm_receive_event(sp, message, size);
0035         break;
0036     case sp_command_response:
0037         ibmasm_receive_command_response(sp, message, size);
0038         break;
0039     case sp_heartbeat:
0040         ibmasm_receive_heartbeat(sp, message, size);
0041         break;
0042     default:
0043         dev_err(sp->dev, "Received unknown message from service processor\n");
0044     }
0045 }
0046 
0047 
0048 #define INIT_BUFFER_SIZE 32
0049 
0050 
0051 /*
0052  * send the 4.3.5.10 dot command (driver VPD) to the service processor
0053  */
0054 int ibmasm_send_driver_vpd(struct service_processor *sp)
0055 {
0056     struct command *command;
0057     struct dot_command_header *header;
0058     u8 *vpd_command;
0059     u8 *vpd_data;
0060     int result = 0;
0061 
0062     command = ibmasm_new_command(sp, INIT_BUFFER_SIZE);
0063     if (command == NULL)
0064         return -ENOMEM;
0065 
0066     header = (struct dot_command_header *)command->buffer;
0067     header->type                = sp_write;
0068     header->command_size        = 4;
0069     header->data_size           = 16;
0070     header->status              = 0;
0071     header->reserved            = 0;
0072 
0073     vpd_command = command->buffer + sizeof(struct dot_command_header);
0074     vpd_command[0] = 0x4;
0075     vpd_command[1] = 0x3;
0076     vpd_command[2] = 0x5;
0077     vpd_command[3] = 0xa;
0078 
0079     vpd_data = vpd_command + header->command_size;
0080     vpd_data[0] = 0;
0081     strcat(vpd_data, IBMASM_DRIVER_VPD);
0082     vpd_data[10] = 0;
0083     vpd_data[15] = 0;
0084 
0085     ibmasm_exec_command(sp, command);
0086     ibmasm_wait_for_response(command, IBMASM_CMD_TIMEOUT_NORMAL);
0087 
0088     if (command->status != IBMASM_CMD_COMPLETE)
0089         result = -ENODEV;
0090 
0091     command_put(command);
0092 
0093     return result;
0094 }
0095 
0096 struct os_state_command {
0097     struct dot_command_header   header;
0098     unsigned char           command[3];
0099     unsigned char           data;
0100 };
0101 
0102 /*
0103  * send the 4.3.6 dot command (os state) to the service processor
0104  * During driver init this function is called with os state "up".
0105  * This causes the service processor to start sending heartbeats the
0106  * driver.
0107  * During driver exit the function is called with os state "down",
0108  * causing the service processor to stop the heartbeats.
0109  */
0110 int ibmasm_send_os_state(struct service_processor *sp, int os_state)
0111 {
0112     struct command *cmd;
0113     struct os_state_command *os_state_cmd;
0114     int result = 0;
0115 
0116     cmd = ibmasm_new_command(sp, sizeof(struct os_state_command));
0117     if (cmd == NULL)
0118         return -ENOMEM;
0119 
0120     os_state_cmd = (struct os_state_command *)cmd->buffer;
0121     os_state_cmd->header.type       = sp_write;
0122     os_state_cmd->header.command_size   = 3;
0123     os_state_cmd->header.data_size      = 1;
0124     os_state_cmd->header.status     = 0;
0125     os_state_cmd->command[0]        = 4;
0126     os_state_cmd->command[1]        = 3;
0127     os_state_cmd->command[2]        = 6;
0128     os_state_cmd->data          = os_state;
0129 
0130     ibmasm_exec_command(sp, cmd);
0131     ibmasm_wait_for_response(cmd, IBMASM_CMD_TIMEOUT_NORMAL);
0132 
0133     if (cmd->status != IBMASM_CMD_COMPLETE)
0134         result = -ENODEV;
0135 
0136     command_put(cmd);
0137     return result;
0138 }