40 #include <linux/kernel.h>
41 #include <linux/module.h>
43 #include <linux/string.h>
53 #define KCS_DEBUG_STATES 4
54 #define KCS_DEBUG_MSG 2
55 #define KCS_DEBUG_ENABLE 1
59 MODULE_PARM_DESC(kcs_debug,
"debug bitmask, 1=enable, 2=messages, 4=states");
117 #define MAX_KCS_READ_SIZE IPMI_MAX_MSG_LENGTH
118 #define MAX_KCS_WRITE_SIZE IPMI_MAX_MSG_LENGTH
121 #define IBF_RETRY_TIMEOUT 5000000
122 #define OBF_RETRY_TIMEOUT 5000000
123 #define MAX_ERROR_RETRIES 10
124 #define ERROR0_OBF_WAIT_JIFFIES (2*HZ)
143 static unsigned int init_kcs_data(
struct si_sm_data *kcs,
161 static inline unsigned char read_status(
struct si_sm_data *kcs)
163 return kcs->
io->inputb(kcs->
io, 1);
166 static inline unsigned char read_data(
struct si_sm_data *kcs)
168 return kcs->
io->inputb(kcs->
io, 0);
171 static inline void write_cmd(
struct si_sm_data *kcs,
unsigned char data)
173 kcs->
io->outputb(kcs->
io, 1, data);
176 static inline void write_data(
struct si_sm_data *kcs,
unsigned char data)
178 kcs->
io->outputb(kcs->
io, 0, data);
182 #define KCS_GET_STATUS_ABORT 0x60
183 #define KCS_WRITE_START 0x61
184 #define KCS_WRITE_END 0x62
185 #define KCS_READ_BYTE 0x68
188 #define GET_STATUS_STATE(status) (((status) >> 6) & 0x03)
189 #define KCS_IDLE_STATE 0
190 #define KCS_READ_STATE 1
191 #define KCS_WRITE_STATE 2
192 #define KCS_ERROR_STATE 3
193 #define GET_STATUS_ATN(status) ((status) & 0x04)
194 #define GET_STATUS_IBF(status) ((status) & 0x02)
195 #define GET_STATUS_OBF(status) ((status) & 0x01)
198 static inline void write_next_byte(
struct si_sm_data *kcs)
205 static inline void start_error_recovery(
struct si_sm_data *kcs,
char *
reason)
219 static inline void read_next_byte(
struct si_sm_data *kcs)
238 start_error_recovery(kcs,
"IBF not ready in time");
248 static inline int check_obf(
struct si_sm_data *kcs,
unsigned char status,
254 start_error_recovery(kcs,
"OBF not ready in time");
263 static void clear_obf(
struct si_sm_data *kcs,
unsigned char status)
269 static void restart_kcs_transaction(
struct si_sm_data *kcs)
280 static int start_kcs_transaction(
struct si_sm_data *kcs,
unsigned char *data,
295 for (i = 0; i <
size; i++)
296 printk(
" %02x", (
unsigned char) (data [i]));
311 static int get_kcs_result(
struct si_sm_data *kcs,
unsigned char *data,
314 if (length < kcs->read_pos) {
321 if ((length >= 3) && (kcs->
read_pos < 3)) {
350 status = read_status(kcs);
356 if (!check_ibf(kcs, status, time))
362 switch (kcs->
state) {
365 clear_obf(kcs, status);
374 start_error_recovery(kcs,
375 "State machine not idle at start");
379 clear_obf(kcs, status);
386 start_error_recovery(
388 "Not in write state at write start");
396 write_next_byte(kcs);
403 start_error_recovery(kcs,
404 "Not in write state for write");
407 clear_obf(kcs, status);
412 write_next_byte(kcs);
418 start_error_recovery(kcs,
423 clear_obf(kcs, status);
424 write_next_byte(kcs);
430 start_error_recovery(
432 "Not in read or idle in read state");
437 if (!check_obf(kcs, status, time))
450 clear_obf(kcs, status);
458 clear_obf(kcs, status);
459 status = read_status(kcs);
469 clear_obf(kcs, status);
476 start_error_recovery(kcs,
477 "Not in read state for error2");
480 if (!check_obf(kcs, status, time))
483 clear_obf(kcs, status);
490 start_error_recovery(kcs,
491 "Not in idle state for error3");
495 if (!check_obf(kcs, status, time))
498 clear_obf(kcs, status);
500 restart_kcs_transaction(kcs);
512 init_kcs_data(kcs, kcs->
io);
519 static int kcs_size(
void)
532 if (read_status(kcs) == 0xff)
538 static void kcs_cleanup(
struct si_sm_data *kcs)
543 .init_data = init_kcs_data,
544 .start_transaction = start_kcs_transaction,
545 .get_result = get_kcs_result,
547 .detect = kcs_detect,
548 .cleanup = kcs_cleanup,