0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kernel.h>
0012 #include <linux/types.h>
0013 #include <linux/errno.h>
0014 #include <linux/list.h>
0015 #include <linux/wait.h>
0016 #include <linux/spinlock.h>
0017 #include <linux/slab.h>
0018 #include <linux/module.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/kref.h>
0021 #include <linux/device.h>
0022 #include <linux/input.h>
0023 #include <linux/time64.h>
0024
0025
0026 #define DRIVER_NAME "ibmasm"
0027 #define DRIVER_VERSION "1.0"
0028 #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
0029 #define DRIVER_DESC "IBM ASM Service Processor Driver"
0030
0031 #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
0032 #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
0033
0034 extern int ibmasm_debug;
0035 #define dbg(STR, ARGS...) \
0036 do { \
0037 if (ibmasm_debug) \
0038 printk(KERN_DEBUG STR , ##ARGS); \
0039 } while (0)
0040
0041 static inline char *get_timestamp(char *buf)
0042 {
0043 struct timespec64 now;
0044
0045 ktime_get_real_ts64(&now);
0046 sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec,
0047 now.tv_nsec / NSEC_PER_USEC);
0048 return buf;
0049 }
0050
0051 #define IBMASM_CMD_PENDING 0
0052 #define IBMASM_CMD_COMPLETE 1
0053 #define IBMASM_CMD_FAILED 2
0054
0055 #define IBMASM_CMD_TIMEOUT_NORMAL 45
0056 #define IBMASM_CMD_TIMEOUT_EXTRA 240
0057
0058 #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
0059
0060 #define REVERSE_HEARTBEAT_TIMEOUT 120
0061
0062 #define HEARTBEAT_BUFFER_SIZE 0x400
0063
0064 #ifdef IA64
0065 #define IBMASM_DRIVER_VPD "Lin64 6.08 "
0066 #else
0067 #define IBMASM_DRIVER_VPD "Lin32 6.08 "
0068 #endif
0069
0070 #define SYSTEM_STATE_OS_UP 5
0071 #define SYSTEM_STATE_OS_DOWN 4
0072
0073 #define IBMASM_NAME_SIZE 16
0074
0075 #define IBMASM_NUM_EVENTS 10
0076 #define IBMASM_EVENT_MAX_SIZE 2048u
0077
0078
0079 struct command {
0080 struct list_head queue_node;
0081 wait_queue_head_t wait;
0082 unsigned char *buffer;
0083 size_t buffer_size;
0084 int status;
0085 struct kref kref;
0086 spinlock_t *lock;
0087 };
0088 #define to_command(c) container_of(c, struct command, kref)
0089
0090 void ibmasm_free_command(struct kref *kref);
0091 static inline void command_put(struct command *cmd)
0092 {
0093 unsigned long flags;
0094 spinlock_t *lock = cmd->lock;
0095
0096 spin_lock_irqsave(lock, flags);
0097 kref_put(&cmd->kref, ibmasm_free_command);
0098 spin_unlock_irqrestore(lock, flags);
0099 }
0100
0101 static inline void command_get(struct command *cmd)
0102 {
0103 kref_get(&cmd->kref);
0104 }
0105
0106
0107 struct ibmasm_event {
0108 unsigned int serial_number;
0109 unsigned int data_size;
0110 unsigned char data[IBMASM_EVENT_MAX_SIZE];
0111 };
0112
0113 struct event_buffer {
0114 struct ibmasm_event events[IBMASM_NUM_EVENTS];
0115 unsigned int next_serial_number;
0116 unsigned int next_index;
0117 struct list_head readers;
0118 };
0119
0120 struct event_reader {
0121 int cancelled;
0122 unsigned int next_serial_number;
0123 wait_queue_head_t wait;
0124 struct list_head node;
0125 unsigned int data_size;
0126 unsigned char data[IBMASM_EVENT_MAX_SIZE];
0127 };
0128
0129 struct reverse_heartbeat {
0130 wait_queue_head_t wait;
0131 unsigned int stopped;
0132 };
0133
0134 struct ibmasm_remote {
0135 struct input_dev *keybd_dev;
0136 struct input_dev *mouse_dev;
0137 };
0138
0139 struct service_processor {
0140 struct list_head node;
0141 spinlock_t lock;
0142 void __iomem *base_address;
0143 unsigned int irq;
0144 struct command *current_command;
0145 struct command *heartbeat;
0146 struct list_head command_queue;
0147 struct event_buffer *event_buffer;
0148 char dirname[IBMASM_NAME_SIZE];
0149 char devname[IBMASM_NAME_SIZE];
0150 unsigned int number;
0151 struct ibmasm_remote remote;
0152 int serial_line;
0153 struct device *dev;
0154 };
0155
0156
0157 struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
0158 void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
0159 void ibmasm_wait_for_response(struct command *cmd, int timeout);
0160 void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
0161
0162
0163 int ibmasm_event_buffer_init(struct service_processor *sp);
0164 void ibmasm_event_buffer_exit(struct service_processor *sp);
0165 void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
0166 void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
0167 void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
0168 int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
0169 void ibmasm_cancel_next_event(struct event_reader *reader);
0170
0171
0172 void ibmasm_register_panic_notifier(void);
0173 void ibmasm_unregister_panic_notifier(void);
0174 int ibmasm_heartbeat_init(struct service_processor *sp);
0175 void ibmasm_heartbeat_exit(struct service_processor *sp);
0176 void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
0177
0178
0179 void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
0180 int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
0181 void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
0182
0183
0184 void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
0185 int ibmasm_send_driver_vpd(struct service_processor *sp);
0186 int ibmasm_send_os_state(struct service_processor *sp, int os_state);
0187
0188
0189 int ibmasm_send_i2o_message(struct service_processor *sp);
0190 irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id);
0191
0192
0193 void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
0194 int ibmasm_init_remote_input_dev(struct service_processor *sp);
0195 void ibmasm_free_remote_input_dev(struct service_processor *sp);
0196
0197
0198 int ibmasmfs_register(void);
0199 void ibmasmfs_unregister(void);
0200 void ibmasmfs_add_sp(struct service_processor *sp);
0201
0202
0203 #if IS_ENABLED(CONFIG_SERIAL_8250)
0204 void ibmasm_register_uart(struct service_processor *sp);
0205 void ibmasm_unregister_uart(struct service_processor *sp);
0206 #else
0207 #define ibmasm_register_uart(sp) do { } while(0)
0208 #define ibmasm_unregister_uart(sp) do { } while(0)
0209 #endif