blob: 653a7d096a8bc3468df98566bf583d9d8c195cd5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 * IBM ASM Service Processor Device Driver
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * Copyright (C) IBM Corporation, 2004
20 *
21 * Author: Max Asböck <amax@us.ibm.com>
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/types.h>
27#include <linux/errno.h>
28#include <linux/list.h>
29#include <linux/wait.h>
30#include <linux/spinlock.h>
31#include <linux/slab.h>
32#include <linux/config.h>
33#include <linux/module.h>
34#include <linux/version.h>
35#include <linux/interrupt.h>
36#include <linux/device.h>
Max Asbock278d72a2005-06-21 17:16:34 -070037#include <linux/input.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/* Driver identification */
40#define DRIVER_NAME "ibmasm"
Max Asbock278d72a2005-06-21 17:16:34 -070041#define DRIVER_VERSION "1.0"
42#define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define DRIVER_DESC "IBM ASM Service Processor Driver"
44
45#define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
46#define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
47
Max Asbock278d72a2005-06-21 17:16:34 -070048extern int ibmasm_debug;
49#define dbg(STR, ARGS...) \
50 do { \
51 if (ibmasm_debug) \
52 printk(KERN_DEBUG STR , ##ARGS); \
53 } while (0)
54
55static inline char *get_timestamp(char *buf)
56{
57 struct timeval now;
58 do_gettimeofday(&now);
59 sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec);
60 return buf;
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define IBMASM_CMD_PENDING 0
64#define IBMASM_CMD_COMPLETE 1
65#define IBMASM_CMD_FAILED 2
66
67#define IBMASM_CMD_TIMEOUT_NORMAL 45
68#define IBMASM_CMD_TIMEOUT_EXTRA 240
69
Max Asbockf5ccc842005-06-21 17:16:32 -070070#define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#define REVERSE_HEARTBEAT_TIMEOUT 120
73
74#define HEARTBEAT_BUFFER_SIZE 0x400
75
76#ifdef IA64
77#define IBMASM_DRIVER_VPD "Lin64 6.08 "
78#else
79#define IBMASM_DRIVER_VPD "Lin32 6.08 "
80#endif
81
82#define SYSTEM_STATE_OS_UP 5
83#define SYSTEM_STATE_OS_DOWN 4
84
85#define IBMASM_NAME_SIZE 16
86
87#define IBMASM_NUM_EVENTS 10
88#define IBMASM_EVENT_MAX_SIZE 2048u
89
90
91struct command {
92 struct list_head queue_node;
93 wait_queue_head_t wait;
94 unsigned char *buffer;
95 size_t buffer_size;
96 int status;
97 struct kobject kobj;
98};
99#define to_command(c) container_of(c, struct command, kobj)
100
101static inline void command_put(struct command *cmd)
102{
103 kobject_put(&cmd->kobj);
104}
105
106static inline void command_get(struct command *cmd)
107{
108 kobject_get(&cmd->kobj);
109}
110
111
112struct ibmasm_event {
113 unsigned int serial_number;
114 unsigned int data_size;
115 unsigned char data[IBMASM_EVENT_MAX_SIZE];
116};
117
118struct event_buffer {
119 struct ibmasm_event events[IBMASM_NUM_EVENTS];
120 unsigned int next_serial_number;
121 unsigned int next_index;
122 struct list_head readers;
123};
124
125struct event_reader {
Max Asbockb8acb802005-06-21 17:16:33 -0700126 int cancelled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 unsigned int next_serial_number;
128 wait_queue_head_t wait;
129 struct list_head node;
130 unsigned int data_size;
131 unsigned char data[IBMASM_EVENT_MAX_SIZE];
132};
133
134struct reverse_heartbeat {
135 wait_queue_head_t wait;
136 unsigned int stopped;
137};
138
Max Asbock278d72a2005-06-21 17:16:34 -0700139struct ibmasm_remote {
140 struct input_dev keybd_dev;
141 struct input_dev mouse_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142};
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144struct service_processor {
145 struct list_head node;
146 spinlock_t lock;
147 void __iomem *base_address;
148 unsigned int irq;
149 struct command *current_command;
150 struct command *heartbeat;
151 struct list_head command_queue;
152 struct event_buffer *event_buffer;
153 char dirname[IBMASM_NAME_SIZE];
154 char devname[IBMASM_NAME_SIZE];
155 unsigned int number;
Max Asbock278d72a2005-06-21 17:16:34 -0700156 struct ibmasm_remote *remote;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 int serial_line;
158 struct device *dev;
159};
160
161/* command processing */
162extern struct command *ibmasm_new_command(size_t buffer_size);
163extern void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
164extern void ibmasm_wait_for_response(struct command *cmd, int timeout);
165extern void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
166
167/* event processing */
168extern int ibmasm_event_buffer_init(struct service_processor *sp);
169extern void ibmasm_event_buffer_exit(struct service_processor *sp);
170extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
171extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
172extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
173extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
Max Asbockb8acb802005-06-21 17:16:33 -0700174extern void ibmasm_cancel_next_event(struct event_reader *reader);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176/* heartbeat - from SP to OS */
177extern void ibmasm_register_panic_notifier(void);
178extern void ibmasm_unregister_panic_notifier(void);
179extern int ibmasm_heartbeat_init(struct service_processor *sp);
180extern void ibmasm_heartbeat_exit(struct service_processor *sp);
181extern void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
182
183/* reverse heartbeat - from OS to SP */
184extern void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
185extern int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
186extern void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
187
188/* dot commands */
189extern void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
190extern int ibmasm_send_driver_vpd(struct service_processor *sp);
191extern int ibmasm_send_os_state(struct service_processor *sp, int os_state);
192
193/* low level message processing */
194extern int ibmasm_send_i2o_message(struct service_processor *sp);
195extern irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id, struct pt_regs *regs);
196
197/* remote console */
Max Asbock278d72a2005-06-21 17:16:34 -0700198extern void ibmasm_handle_mouse_interrupt(struct service_processor *sp, struct pt_regs *regs);
199extern int ibmasm_init_remote_input_dev(struct service_processor *sp);
200extern void ibmasm_free_remote_input_dev(struct service_processor *sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/* file system */
203extern int ibmasmfs_register(void);
204extern void ibmasmfs_unregister(void);
205extern void ibmasmfs_add_sp(struct service_processor *sp);
206
207/* uart */
208#ifdef CONFIG_SERIAL_8250
209extern void ibmasm_register_uart(struct service_processor *sp);
210extern void ibmasm_unregister_uart(struct service_processor *sp);
211#else
212#define ibmasm_register_uart(sp) do { } while(0)
213#define ibmasm_unregister_uart(sp) do { } while(0)
214#endif