44 #include <linux/kernel.h>
45 #include <linux/string.h>
46 #include <linux/module.h>
56 #define SMIC_DEBUG_STATES 4
57 #define SMIC_DEBUG_MSG 2
58 #define SMIC_DEBUG_ENABLE 1
60 static int smic_debug = 1;
62 MODULE_PARM_DESC(smic_debug,
"debug bitmask, 1=enable, 2=messages, 4=states");
78 #define MAX_SMIC_READ_SIZE 80
79 #define MAX_SMIC_WRITE_SIZE 80
80 #define SMIC_MAX_ERROR_RETRIES 3
83 #define SMIC_RETRY_TIMEOUT 2000000
86 #define SMIC_RX_DATA_READY 0x80
87 #define SMIC_TX_DATA_READY 0x40
96 #define SMIC_EVM_DATA_AVAIL 0x08
97 #define SMIC_SMS_DATA_AVAIL 0x04
98 #define SMIC_FLAG_BSY 0x01
101 #define EC_NO_ERROR 0x00
102 #define EC_ABORTED 0x01
103 #define EC_ILLEGAL_CONTROL 0x02
104 #define EC_NO_RESPONSE 0x03
105 #define EC_ILLEGAL_COMMAND 0x04
106 #define EC_BUFFER_FULL 0x05
122 static unsigned int init_smic_data(
struct si_sm_data *smic,
139 static int start_smic_transaction(
struct si_sm_data *smic,
140 unsigned char *
data,
unsigned int size)
154 for (i = 0; i <
size; i++)
155 printk(
" %02x", (
unsigned char) data[i]);
169 static int smic_get_result(
struct si_sm_data *smic,
170 unsigned char *data,
unsigned int length)
174 if (smic_debug & SMIC_DEBUG_MSG) {
176 for (i = 0; i < smic->
read_pos; i++)
180 if (length < smic->read_pos) {
186 if ((length >= 3) && (smic->
read_pos < 3)) {
197 static inline unsigned char read_smic_flags(
struct si_sm_data *smic)
199 return smic->
io->inputb(smic->
io, 2);
202 static inline unsigned char read_smic_status(
struct si_sm_data *smic)
204 return smic->
io->inputb(smic->
io, 1);
207 static inline unsigned char read_smic_data(
struct si_sm_data *smic)
209 return smic->
io->inputb(smic->
io, 0);
212 static inline void write_smic_flags(
struct si_sm_data *smic,
215 smic->
io->outputb(smic->
io, 2, flags);
218 static inline void write_smic_control(
struct si_sm_data *smic,
221 smic->
io->outputb(smic->
io, 1, control);
224 static inline void write_si_sm_data(
struct si_sm_data *smic,
227 smic->
io->outputb(smic->
io, 0, data);
230 static inline void start_error_recovery(
struct si_sm_data *smic,
char *
reason)
236 "ipmi_smic_drv: smic hosed: %s\n", reason);
247 static inline void write_next_byte(
struct si_sm_data *smic)
254 static inline void read_next_byte(
struct si_sm_data *smic)
257 read_smic_data(smic);
266 #define SMIC_GET_STATUS 0x00
267 #define SMIC_READY 0x00
268 #define SMIC_WR_START 0x01
269 #define SMIC_WR_NEXT 0x02
270 #define SMIC_WR_END 0x03
271 #define SMIC_RD_START 0x04
272 #define SMIC_RD_NEXT 0x05
273 #define SMIC_RD_END 0x06
274 #define SMIC_CODE_MASK 0x0f
276 #define SMIC_CONTROL 0x00
277 #define SMIC_STATUS 0x80
278 #define SMIC_CS_MASK 0x80
280 #define SMIC_SMS 0x40
281 #define SMIC_SMM 0x60
282 #define SMIC_STREAM_MASK 0x60
285 #define SMIC_CC_SMS_GET_STATUS (SMIC_CONTROL|SMIC_SMS|SMIC_GET_STATUS)
286 #define SMIC_CC_SMS_WR_START (SMIC_CONTROL|SMIC_SMS|SMIC_WR_START)
287 #define SMIC_CC_SMS_WR_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_WR_NEXT)
288 #define SMIC_CC_SMS_WR_END (SMIC_CONTROL|SMIC_SMS|SMIC_WR_END)
289 #define SMIC_CC_SMS_RD_START (SMIC_CONTROL|SMIC_SMS|SMIC_RD_START)
290 #define SMIC_CC_SMS_RD_NEXT (SMIC_CONTROL|SMIC_SMS|SMIC_RD_NEXT)
291 #define SMIC_CC_SMS_RD_END (SMIC_CONTROL|SMIC_SMS|SMIC_RD_END)
293 #define SMIC_CC_SMM_GET_STATUS (SMIC_CONTROL|SMIC_SMM|SMIC_GET_STATUS)
294 #define SMIC_CC_SMM_WR_START (SMIC_CONTROL|SMIC_SMM|SMIC_WR_START)
295 #define SMIC_CC_SMM_WR_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_WR_NEXT)
296 #define SMIC_CC_SMM_WR_END (SMIC_CONTROL|SMIC_SMM|SMIC_WR_END)
297 #define SMIC_CC_SMM_RD_START (SMIC_CONTROL|SMIC_SMM|SMIC_RD_START)
298 #define SMIC_CC_SMM_RD_NEXT (SMIC_CONTROL|SMIC_SMM|SMIC_RD_NEXT)
299 #define SMIC_CC_SMM_RD_END (SMIC_CONTROL|SMIC_SMM|SMIC_RD_END)
302 #define SMIC_SC_SMS_READY (SMIC_STATUS|SMIC_SMS|SMIC_READY)
303 #define SMIC_SC_SMS_WR_START (SMIC_STATUS|SMIC_SMS|SMIC_WR_START)
304 #define SMIC_SC_SMS_WR_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_WR_NEXT)
305 #define SMIC_SC_SMS_WR_END (SMIC_STATUS|SMIC_SMS|SMIC_WR_END)
306 #define SMIC_SC_SMS_RD_START (SMIC_STATUS|SMIC_SMS|SMIC_RD_START)
307 #define SMIC_SC_SMS_RD_NEXT (SMIC_STATUS|SMIC_SMS|SMIC_RD_NEXT)
308 #define SMIC_SC_SMS_RD_END (SMIC_STATUS|SMIC_SMS|SMIC_RD_END)
310 #define SMIC_SC_SMM_READY (SMIC_STATUS|SMIC_SMM|SMIC_READY)
311 #define SMIC_SC_SMM_WR_START (SMIC_STATUS|SMIC_SMM|SMIC_WR_START)
312 #define SMIC_SC_SMM_WR_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_WR_NEXT)
313 #define SMIC_SC_SMM_WR_END (SMIC_STATUS|SMIC_SMM|SMIC_WR_END)
314 #define SMIC_SC_SMM_RD_START (SMIC_STATUS|SMIC_SMM|SMIC_RD_START)
315 #define SMIC_SC_SMM_RD_NEXT (SMIC_STATUS|SMIC_SMM|SMIC_RD_NEXT)
316 #define SMIC_SC_SMM_RD_END (SMIC_STATUS|SMIC_SMM|SMIC_RD_END)
343 init_smic_data(smic, smic->
io);
349 "smic_event - smic->smic_timeout = %ld,"
359 start_error_recovery(smic,
"smic timed out.");
364 flags = read_smic_flags(smic);
368 status = read_smic_status(smic);
371 "smic_event - state = %d, flags = 0x%02x,"
372 " status = 0x%02x\n",
373 smic->
state, flags, status);
375 switch (smic->
state) {
385 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
392 start_error_recovery(smic,
393 "state = SMIC_OP_OK,"
394 " status != SMIC_SC_SMS_READY");
399 write_next_byte(smic);
400 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
406 start_error_recovery(smic,
407 "state = SMIC_WRITE_START, "
408 "status != SMIC_SC_SMS_WR_START");
424 write_next_byte(smic);
425 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
432 start_error_recovery(smic,
433 "state = SMIC_WRITE_NEXT, "
434 "status != SMIC_SC_SMS_WR_NEXT");
438 if (flags & SMIC_TX_DATA_READY) {
446 write_next_byte(smic);
447 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
454 start_error_recovery(smic,
455 "state = SMIC_WRITE_END, "
456 "status != SMIC_SC_SMS_WR_END");
460 data = read_smic_data(smic);
464 "SMIC_WRITE_END: data = %02x\n", data);
465 start_error_recovery(smic,
466 "state = SMIC_WRITE_END, "
480 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
488 start_error_recovery(smic,
489 "state = SMIC_READ_START, "
490 "status != SMIC_SC_SMS_RD_START");
493 if (flags & SMIC_RX_DATA_READY) {
494 read_next_byte(smic);
496 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
509 read_next_byte(smic);
511 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
515 if (flags & SMIC_RX_DATA_READY) {
516 read_next_byte(smic);
518 write_smic_flags(smic, flags | SMIC_FLAG_BSY);
524 start_error_recovery(
526 "state = SMIC_READ_NEXT, "
527 "status != SMIC_SC_SMS_RD_(NEXT|END)");
534 start_error_recovery(smic,
535 "state = SMIC_READ_END, "
536 "status != SMIC_SC_SMS_READY");
539 data = read_smic_data(smic);
544 "SMIC_READ_END: data = %02x\n", data);
545 start_error_recovery(smic,
546 "state = SMIC_READ_END, "
555 init_smic_data(smic, smic->
io);
561 start_error_recovery(smic,
"state = UNKNOWN");
569 static int smic_detect(
struct si_sm_data *smic)
577 if (read_smic_flags(smic) == 0xff)
583 static void smic_cleanup(
struct si_sm_data *kcs)
587 static int smic_size(
void)
593 .init_data = init_smic_data,
594 .start_transaction = start_smic_transaction,
595 .get_result = smic_get_result,
597 .detect = smic_detect,
598 .cleanup = smic_cleanup,