Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 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 | * |
Dmitry Torokhov | 3110dc7 | 2007-07-17 04:03:58 -0700 | [diff] [blame^] | 21 | * Author: Max Asböck <amax@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/device.h> |
Max Asbock | 278d72a | 2005-06-21 17:16:34 -0700 | [diff] [blame] | 35 | #include <linux/input.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | /* Driver identification */ |
| 38 | #define DRIVER_NAME "ibmasm" |
Max Asbock | 278d72a | 2005-06-21 17:16:34 -0700 | [diff] [blame] | 39 | #define DRIVER_VERSION "1.0" |
| 40 | #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define DRIVER_DESC "IBM ASM Service Processor Driver" |
| 42 | |
| 43 | #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME) |
| 44 | #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME) |
| 45 | |
Max Asbock | 278d72a | 2005-06-21 17:16:34 -0700 | [diff] [blame] | 46 | extern int ibmasm_debug; |
| 47 | #define dbg(STR, ARGS...) \ |
| 48 | do { \ |
| 49 | if (ibmasm_debug) \ |
| 50 | printk(KERN_DEBUG STR , ##ARGS); \ |
| 51 | } while (0) |
| 52 | |
| 53 | static inline char *get_timestamp(char *buf) |
| 54 | { |
| 55 | struct timeval now; |
| 56 | do_gettimeofday(&now); |
| 57 | sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec); |
| 58 | return buf; |
| 59 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Dmitry Torokhov | 3110dc7 | 2007-07-17 04:03:58 -0700 | [diff] [blame^] | 61 | #define IBMASM_CMD_PENDING 0 |
| 62 | #define IBMASM_CMD_COMPLETE 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define IBMASM_CMD_FAILED 2 |
| 64 | |
| 65 | #define IBMASM_CMD_TIMEOUT_NORMAL 45 |
| 66 | #define IBMASM_CMD_TIMEOUT_EXTRA 240 |
| 67 | |
Max Asbock | f5ccc84 | 2005-06-21 17:16:32 -0700 | [diff] [blame] | 68 | #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | #define REVERSE_HEARTBEAT_TIMEOUT 120 |
| 71 | |
| 72 | #define HEARTBEAT_BUFFER_SIZE 0x400 |
| 73 | |
| 74 | #ifdef IA64 |
| 75 | #define IBMASM_DRIVER_VPD "Lin64 6.08 " |
| 76 | #else |
| 77 | #define IBMASM_DRIVER_VPD "Lin32 6.08 " |
| 78 | #endif |
| 79 | |
| 80 | #define SYSTEM_STATE_OS_UP 5 |
| 81 | #define SYSTEM_STATE_OS_DOWN 4 |
| 82 | |
| 83 | #define IBMASM_NAME_SIZE 16 |
| 84 | |
| 85 | #define IBMASM_NUM_EVENTS 10 |
| 86 | #define IBMASM_EVENT_MAX_SIZE 2048u |
| 87 | |
| 88 | |
| 89 | struct command { |
| 90 | struct list_head queue_node; |
| 91 | wait_queue_head_t wait; |
| 92 | unsigned char *buffer; |
| 93 | size_t buffer_size; |
| 94 | int status; |
| 95 | struct kobject kobj; |
Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 96 | spinlock_t *lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | #define to_command(c) container_of(c, struct command, kobj) |
| 99 | |
| 100 | static inline void command_put(struct command *cmd) |
| 101 | { |
Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 102 | unsigned long flags; |
Max Asbock | 6a88231 | 2006-03-09 17:33:48 -0800 | [diff] [blame] | 103 | spinlock_t *lock = cmd->lock; |
Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 104 | |
Max Asbock | 6a88231 | 2006-03-09 17:33:48 -0800 | [diff] [blame] | 105 | spin_lock_irqsave(lock, flags); |
| 106 | kobject_put(&cmd->kobj); |
| 107 | spin_unlock_irqrestore(lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static inline void command_get(struct command *cmd) |
| 111 | { |
Max Asbock | 6a88231 | 2006-03-09 17:33:48 -0800 | [diff] [blame] | 112 | kobject_get(&cmd->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | struct ibmasm_event { |
| 117 | unsigned int serial_number; |
| 118 | unsigned int data_size; |
| 119 | unsigned char data[IBMASM_EVENT_MAX_SIZE]; |
| 120 | }; |
| 121 | |
| 122 | struct event_buffer { |
| 123 | struct ibmasm_event events[IBMASM_NUM_EVENTS]; |
| 124 | unsigned int next_serial_number; |
| 125 | unsigned int next_index; |
| 126 | struct list_head readers; |
| 127 | }; |
| 128 | |
| 129 | struct event_reader { |
Max Asbock | b8acb80 | 2005-06-21 17:16:33 -0700 | [diff] [blame] | 130 | int cancelled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | unsigned int next_serial_number; |
| 132 | wait_queue_head_t wait; |
| 133 | struct list_head node; |
| 134 | unsigned int data_size; |
| 135 | unsigned char data[IBMASM_EVENT_MAX_SIZE]; |
| 136 | }; |
| 137 | |
| 138 | struct reverse_heartbeat { |
| 139 | wait_queue_head_t wait; |
| 140 | unsigned int stopped; |
| 141 | }; |
| 142 | |
Max Asbock | 278d72a | 2005-06-21 17:16:34 -0700 | [diff] [blame] | 143 | struct ibmasm_remote { |
Vernon Mauery | 736ce43 | 2006-01-07 11:35:05 -0500 | [diff] [blame] | 144 | struct input_dev *keybd_dev; |
| 145 | struct input_dev *mouse_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | struct service_processor { |
| 149 | struct list_head node; |
| 150 | spinlock_t lock; |
| 151 | void __iomem *base_address; |
| 152 | unsigned int irq; |
| 153 | struct command *current_command; |
| 154 | struct command *heartbeat; |
| 155 | struct list_head command_queue; |
| 156 | struct event_buffer *event_buffer; |
| 157 | char dirname[IBMASM_NAME_SIZE]; |
| 158 | char devname[IBMASM_NAME_SIZE]; |
| 159 | unsigned int number; |
Vernon Mauery | 736ce43 | 2006-01-07 11:35:05 -0500 | [diff] [blame] | 160 | struct ibmasm_remote remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | int serial_line; |
| 162 | struct device *dev; |
| 163 | }; |
| 164 | |
| 165 | /* command processing */ |
Max Asbock | 8818760 | 2005-06-21 17:16:36 -0700 | [diff] [blame] | 166 | extern struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | extern void ibmasm_exec_command(struct service_processor *sp, struct command *cmd); |
| 168 | extern void ibmasm_wait_for_response(struct command *cmd, int timeout); |
| 169 | extern void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size); |
| 170 | |
| 171 | /* event processing */ |
| 172 | extern int ibmasm_event_buffer_init(struct service_processor *sp); |
| 173 | extern void ibmasm_event_buffer_exit(struct service_processor *sp); |
| 174 | extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size); |
| 175 | extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader); |
| 176 | extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader); |
| 177 | extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader); |
Max Asbock | b8acb80 | 2005-06-21 17:16:33 -0700 | [diff] [blame] | 178 | extern void ibmasm_cancel_next_event(struct event_reader *reader); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* heartbeat - from SP to OS */ |
| 181 | extern void ibmasm_register_panic_notifier(void); |
| 182 | extern void ibmasm_unregister_panic_notifier(void); |
| 183 | extern int ibmasm_heartbeat_init(struct service_processor *sp); |
| 184 | extern void ibmasm_heartbeat_exit(struct service_processor *sp); |
| 185 | extern void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size); |
| 186 | |
| 187 | /* reverse heartbeat - from OS to SP */ |
| 188 | extern void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb); |
| 189 | extern int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb); |
| 190 | extern void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb); |
| 191 | |
| 192 | /* dot commands */ |
| 193 | extern void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size); |
| 194 | extern int ibmasm_send_driver_vpd(struct service_processor *sp); |
| 195 | extern int ibmasm_send_os_state(struct service_processor *sp, int os_state); |
| 196 | |
| 197 | /* low level message processing */ |
| 198 | extern int ibmasm_send_i2o_message(struct service_processor *sp); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 199 | extern irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | /* remote console */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 202 | extern void ibmasm_handle_mouse_interrupt(struct service_processor *sp); |
Max Asbock | 278d72a | 2005-06-21 17:16:34 -0700 | [diff] [blame] | 203 | extern int ibmasm_init_remote_input_dev(struct service_processor *sp); |
| 204 | extern void ibmasm_free_remote_input_dev(struct service_processor *sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | /* file system */ |
| 207 | extern int ibmasmfs_register(void); |
| 208 | extern void ibmasmfs_unregister(void); |
| 209 | extern void ibmasmfs_add_sp(struct service_processor *sp); |
| 210 | |
| 211 | /* uart */ |
| 212 | #ifdef CONFIG_SERIAL_8250 |
| 213 | extern void ibmasm_register_uart(struct service_processor *sp); |
| 214 | extern void ibmasm_unregister_uart(struct service_processor *sp); |
| 215 | #else |
| 216 | #define ibmasm_register_uart(sp) do { } while(0) |
| 217 | #define ibmasm_unregister_uart(sp) do { } while(0) |
| 218 | #endif |