3 * IBM ASM Service Processor Device Driver
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.
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.
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.
19 * Copyright (C) IBM Corporation, 2004
21 * Author: Max Asböck <amax@us.ibm.com>
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/module.h>
33 #include <linux/interrupt.h>
34 #include <linux/kref.h>
35 #include <linux/device.h>
36 #include <linux/input.h>
37 #include <linux/time64.h>
39 /* Driver identification */
40 #define DRIVER_NAME "ibmasm"
41 #define DRIVER_VERSION "1.0"
42 #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
43 #define DRIVER_DESC "IBM ASM Service Processor Driver"
45 #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
46 #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
48 extern int ibmasm_debug
;
49 #define dbg(STR, ARGS...) \
52 printk(KERN_DEBUG STR , ##ARGS); \
55 static inline char *get_timestamp(char *buf
)
57 struct timespec64 now
;
59 ktime_get_real_ts64(&now
);
60 sprintf(buf
, "%llu.%.08lu", (long long)now
.tv_sec
,
61 now
.tv_nsec
/ NSEC_PER_USEC
);
65 #define IBMASM_CMD_PENDING 0
66 #define IBMASM_CMD_COMPLETE 1
67 #define IBMASM_CMD_FAILED 2
69 #define IBMASM_CMD_TIMEOUT_NORMAL 45
70 #define IBMASM_CMD_TIMEOUT_EXTRA 240
72 #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
74 #define REVERSE_HEARTBEAT_TIMEOUT 120
76 #define HEARTBEAT_BUFFER_SIZE 0x400
79 #define IBMASM_DRIVER_VPD "Lin64 6.08 "
81 #define IBMASM_DRIVER_VPD "Lin32 6.08 "
84 #define SYSTEM_STATE_OS_UP 5
85 #define SYSTEM_STATE_OS_DOWN 4
87 #define IBMASM_NAME_SIZE 16
89 #define IBMASM_NUM_EVENTS 10
90 #define IBMASM_EVENT_MAX_SIZE 2048u
94 struct list_head queue_node
;
95 wait_queue_head_t wait
;
96 unsigned char *buffer
;
102 #define to_command(c) container_of(c, struct command, kref)
104 void ibmasm_free_command(struct kref
*kref
);
105 static inline void command_put(struct command
*cmd
)
108 spinlock_t
*lock
= cmd
->lock
;
110 spin_lock_irqsave(lock
, flags
);
111 kref_put(&cmd
->kref
, ibmasm_free_command
);
112 spin_unlock_irqrestore(lock
, flags
);
115 static inline void command_get(struct command
*cmd
)
117 kref_get(&cmd
->kref
);
121 struct ibmasm_event
{
122 unsigned int serial_number
;
123 unsigned int data_size
;
124 unsigned char data
[IBMASM_EVENT_MAX_SIZE
];
127 struct event_buffer
{
128 struct ibmasm_event events
[IBMASM_NUM_EVENTS
];
129 unsigned int next_serial_number
;
130 unsigned int next_index
;
131 struct list_head readers
;
134 struct event_reader
{
136 unsigned int next_serial_number
;
137 wait_queue_head_t wait
;
138 struct list_head node
;
139 unsigned int data_size
;
140 unsigned char data
[IBMASM_EVENT_MAX_SIZE
];
143 struct reverse_heartbeat
{
144 wait_queue_head_t wait
;
145 unsigned int stopped
;
148 struct ibmasm_remote
{
149 struct input_dev
*keybd_dev
;
150 struct input_dev
*mouse_dev
;
153 struct service_processor
{
154 struct list_head node
;
156 void __iomem
*base_address
;
158 struct command
*current_command
;
159 struct command
*heartbeat
;
160 struct list_head command_queue
;
161 struct event_buffer
*event_buffer
;
162 char dirname
[IBMASM_NAME_SIZE
];
163 char devname
[IBMASM_NAME_SIZE
];
165 struct ibmasm_remote remote
;
170 /* command processing */
171 struct command
*ibmasm_new_command(struct service_processor
*sp
, size_t buffer_size
);
172 void ibmasm_exec_command(struct service_processor
*sp
, struct command
*cmd
);
173 void ibmasm_wait_for_response(struct command
*cmd
, int timeout
);
174 void ibmasm_receive_command_response(struct service_processor
*sp
, void *response
, size_t size
);
176 /* event processing */
177 int ibmasm_event_buffer_init(struct service_processor
*sp
);
178 void ibmasm_event_buffer_exit(struct service_processor
*sp
);
179 void ibmasm_receive_event(struct service_processor
*sp
, void *data
, unsigned int data_size
);
180 void ibmasm_event_reader_register(struct service_processor
*sp
, struct event_reader
*reader
);
181 void ibmasm_event_reader_unregister(struct service_processor
*sp
, struct event_reader
*reader
);
182 int ibmasm_get_next_event(struct service_processor
*sp
, struct event_reader
*reader
);
183 void ibmasm_cancel_next_event(struct event_reader
*reader
);
185 /* heartbeat - from SP to OS */
186 void ibmasm_register_panic_notifier(void);
187 void ibmasm_unregister_panic_notifier(void);
188 int ibmasm_heartbeat_init(struct service_processor
*sp
);
189 void ibmasm_heartbeat_exit(struct service_processor
*sp
);
190 void ibmasm_receive_heartbeat(struct service_processor
*sp
, void *message
, size_t size
);
192 /* reverse heartbeat - from OS to SP */
193 void ibmasm_init_reverse_heartbeat(struct service_processor
*sp
, struct reverse_heartbeat
*rhb
);
194 int ibmasm_start_reverse_heartbeat(struct service_processor
*sp
, struct reverse_heartbeat
*rhb
);
195 void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat
*rhb
);
198 void ibmasm_receive_message(struct service_processor
*sp
, void *data
, int data_size
);
199 int ibmasm_send_driver_vpd(struct service_processor
*sp
);
200 int ibmasm_send_os_state(struct service_processor
*sp
, int os_state
);
202 /* low level message processing */
203 int ibmasm_send_i2o_message(struct service_processor
*sp
);
204 irqreturn_t
ibmasm_interrupt_handler(int irq
, void * dev_id
);
207 void ibmasm_handle_mouse_interrupt(struct service_processor
*sp
);
208 int ibmasm_init_remote_input_dev(struct service_processor
*sp
);
209 void ibmasm_free_remote_input_dev(struct service_processor
*sp
);
212 int ibmasmfs_register(void);
213 void ibmasmfs_unregister(void);
214 void ibmasmfs_add_sp(struct service_processor
*sp
);
217 #if IS_ENABLED(CONFIG_SERIAL_8250)
218 void ibmasm_register_uart(struct service_processor
*sp
);
219 void ibmasm_unregister_uart(struct service_processor
*sp
);
221 #define ibmasm_register_uart(sp) do { } while(0)
222 #define ibmasm_unregister_uart(sp) do { } while(0)