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