aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/ipmi/ipmi_kcs_sm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/ipmi/ipmi_kcs_sm.c')
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c153
1 files changed, 91 insertions, 62 deletions
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index c1b8228cb7b6..80704875794c 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -60,37 +60,58 @@ MODULE_PARM_DESC(kcs_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
60 60
61/* The states the KCS driver may be in. */ 61/* The states the KCS driver may be in. */
62enum kcs_states { 62enum kcs_states {
63 KCS_IDLE, /* The KCS interface is currently 63 /* The KCS interface is currently doing nothing. */
64 doing nothing. */ 64 KCS_IDLE,
65 KCS_START_OP, /* We are starting an operation. The 65
66 data is in the output buffer, but 66 /*
67 nothing has been done to the 67 * We are starting an operation. The data is in the output
68 interface yet. This was added to 68 * buffer, but nothing has been done to the interface yet. This
69 the state machine in the spec to 69 * was added to the state machine in the spec to wait for the
70 wait for the initial IBF. */ 70 * initial IBF.
71 KCS_WAIT_WRITE_START, /* We have written a write cmd to the 71 */
72 interface. */ 72 KCS_START_OP,
73 KCS_WAIT_WRITE, /* We are writing bytes to the 73
74 interface. */ 74 /* We have written a write cmd to the interface. */
75 KCS_WAIT_WRITE_END, /* We have written the write end cmd 75 KCS_WAIT_WRITE_START,
76 to the interface, and still need to 76
77 write the last byte. */ 77 /* We are writing bytes to the interface. */
78 KCS_WAIT_READ, /* We are waiting to read data from 78 KCS_WAIT_WRITE,
79 the interface. */ 79
80 KCS_ERROR0, /* State to transition to the error 80 /*
81 handler, this was added to the 81 * We have written the write end cmd to the interface, and
82 state machine in the spec to be 82 * still need to write the last byte.
83 sure IBF was there. */ 83 */
84 KCS_ERROR1, /* First stage error handler, wait for 84 KCS_WAIT_WRITE_END,
85 the interface to respond. */ 85
86 KCS_ERROR2, /* The abort cmd has been written, 86 /* We are waiting to read data from the interface. */
87 wait for the interface to 87 KCS_WAIT_READ,
88 respond. */ 88
89 KCS_ERROR3, /* We wrote some data to the 89 /*
90 interface, wait for it to switch to 90 * State to transition to the error handler, this was added to
91 read mode. */ 91 * the state machine in the spec to be sure IBF was there.
92 KCS_HOSED /* The hardware failed to follow the 92 */
93 state machine. */ 93 KCS_ERROR0,
94
95 /*
96 * First stage error handler, wait for the interface to
97 * respond.
98 */
99 KCS_ERROR1,
100
101 /*
102 * The abort cmd has been written, wait for the interface to
103 * respond.
104 */
105 KCS_ERROR2,
106
107 /*
108 * We wrote some data to the interface, wait for it to switch
109 * to read mode.
110 */
111 KCS_ERROR3,
112
113 /* The hardware failed to follow the state machine. */
114 KCS_HOSED
94}; 115};
95 116
96#define MAX_KCS_READ_SIZE IPMI_MAX_MSG_LENGTH 117#define MAX_KCS_READ_SIZE IPMI_MAX_MSG_LENGTH
@@ -102,8 +123,7 @@ enum kcs_states {
102#define MAX_ERROR_RETRIES 10 123#define MAX_ERROR_RETRIES 10
103#define ERROR0_OBF_WAIT_JIFFIES (2*HZ) 124#define ERROR0_OBF_WAIT_JIFFIES (2*HZ)
104 125
105struct si_sm_data 126struct si_sm_data {
106{
107 enum kcs_states state; 127 enum kcs_states state;
108 struct si_sm_io *io; 128 struct si_sm_io *io;
109 unsigned char write_data[MAX_KCS_WRITE_SIZE]; 129 unsigned char write_data[MAX_KCS_WRITE_SIZE];
@@ -187,7 +207,8 @@ static inline void start_error_recovery(struct si_sm_data *kcs, char *reason)
187 (kcs->error_retries)++; 207 (kcs->error_retries)++;
188 if (kcs->error_retries > MAX_ERROR_RETRIES) { 208 if (kcs->error_retries > MAX_ERROR_RETRIES) {
189 if (kcs_debug & KCS_DEBUG_ENABLE) 209 if (kcs_debug & KCS_DEBUG_ENABLE)
190 printk(KERN_DEBUG "ipmi_kcs_sm: kcs hosed: %s\n", reason); 210 printk(KERN_DEBUG "ipmi_kcs_sm: kcs hosed: %s\n",
211 reason);
191 kcs->state = KCS_HOSED; 212 kcs->state = KCS_HOSED;
192 } else { 213 } else {
193 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES; 214 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES;
@@ -271,10 +292,9 @@ static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data,
271 292
272 if (kcs_debug & KCS_DEBUG_MSG) { 293 if (kcs_debug & KCS_DEBUG_MSG) {
273 printk(KERN_DEBUG "start_kcs_transaction -"); 294 printk(KERN_DEBUG "start_kcs_transaction -");
274 for (i = 0; i < size; i ++) { 295 for (i = 0; i < size; i++)
275 printk(" %02x", (unsigned char) (data [i])); 296 printk(" %02x", (unsigned char) (data [i]));
276 } 297 printk("\n");
277 printk ("\n");
278 } 298 }
279 kcs->error_retries = 0; 299 kcs->error_retries = 0;
280 memcpy(kcs->write_data, data, size); 300 memcpy(kcs->write_data, data, size);
@@ -305,9 +325,11 @@ static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data,
305 kcs->read_pos = 3; 325 kcs->read_pos = 3;
306 } 326 }
307 if (kcs->truncated) { 327 if (kcs->truncated) {
308 /* Report a truncated error. We might overwrite 328 /*
309 another error, but that's too bad, the user needs 329 * Report a truncated error. We might overwrite
310 to know it was truncated. */ 330 * another error, but that's too bad, the user needs
331 * to know it was truncated.
332 */
311 data[2] = IPMI_ERR_MSG_TRUNCATED; 333 data[2] = IPMI_ERR_MSG_TRUNCATED;
312 kcs->truncated = 0; 334 kcs->truncated = 0;
313 } 335 }
@@ -315,9 +337,11 @@ static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data,
315 return kcs->read_pos; 337 return kcs->read_pos;
316} 338}
317 339
318/* This implements the state machine defined in the IPMI manual, see 340/*
319 that for details on how this works. Divide that flowchart into 341 * This implements the state machine defined in the IPMI manual, see
320 sections delimited by "Wait for IBF" and this will become clear. */ 342 * that for details on how this works. Divide that flowchart into
343 * sections delimited by "Wait for IBF" and this will become clear.
344 */
321static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) 345static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
322{ 346{
323 unsigned char status; 347 unsigned char status;
@@ -388,11 +412,12 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
388 write_next_byte(kcs); 412 write_next_byte(kcs);
389 } 413 }
390 break; 414 break;
391 415
392 case KCS_WAIT_WRITE_END: 416 case KCS_WAIT_WRITE_END:
393 if (state != KCS_WRITE_STATE) { 417 if (state != KCS_WRITE_STATE) {
394 start_error_recovery(kcs, 418 start_error_recovery(kcs,
395 "Not in write state for write end"); 419 "Not in write state"
420 " for write end");
396 break; 421 break;
397 } 422 }
398 clear_obf(kcs, status); 423 clear_obf(kcs, status);
@@ -413,13 +438,15 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
413 return SI_SM_CALL_WITH_DELAY; 438 return SI_SM_CALL_WITH_DELAY;
414 read_next_byte(kcs); 439 read_next_byte(kcs);
415 } else { 440 } else {
416 /* We don't implement this exactly like the state 441 /*
417 machine in the spec. Some broken hardware 442 * We don't implement this exactly like the state
418 does not write the final dummy byte to the 443 * machine in the spec. Some broken hardware
419 read register. Thus obf will never go high 444 * does not write the final dummy byte to the
420 here. We just go straight to idle, and we 445 * read register. Thus obf will never go high
421 handle clearing out obf in idle state if it 446 * here. We just go straight to idle, and we
422 happens to come in. */ 447 * handle clearing out obf in idle state if it
448 * happens to come in.
449 */
423 clear_obf(kcs, status); 450 clear_obf(kcs, status);
424 kcs->orig_write_count = 0; 451 kcs->orig_write_count = 0;
425 kcs->state = KCS_IDLE; 452 kcs->state = KCS_IDLE;
@@ -430,7 +457,8 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
430 case KCS_ERROR0: 457 case KCS_ERROR0:
431 clear_obf(kcs, status); 458 clear_obf(kcs, status);
432 status = read_status(kcs); 459 status = read_status(kcs);
433 if (GET_STATUS_OBF(status)) /* controller isn't responding */ 460 if (GET_STATUS_OBF(status))
461 /* controller isn't responding */
434 if (time_before(jiffies, kcs->error0_timeout)) 462 if (time_before(jiffies, kcs->error0_timeout))
435 return SI_SM_CALL_WITH_TICK_DELAY; 463 return SI_SM_CALL_WITH_TICK_DELAY;
436 write_cmd(kcs, KCS_GET_STATUS_ABORT); 464 write_cmd(kcs, KCS_GET_STATUS_ABORT);
@@ -442,7 +470,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
442 write_data(kcs, 0); 470 write_data(kcs, 0);
443 kcs->state = KCS_ERROR2; 471 kcs->state = KCS_ERROR2;
444 break; 472 break;
445 473
446 case KCS_ERROR2: 474 case KCS_ERROR2:
447 if (state != KCS_READ_STATE) { 475 if (state != KCS_READ_STATE) {
448 start_error_recovery(kcs, 476 start_error_recovery(kcs,
@@ -456,7 +484,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
456 write_data(kcs, KCS_READ_BYTE); 484 write_data(kcs, KCS_READ_BYTE);
457 kcs->state = KCS_ERROR3; 485 kcs->state = KCS_ERROR3;
458 break; 486 break;
459 487
460 case KCS_ERROR3: 488 case KCS_ERROR3:
461 if (state != KCS_IDLE_STATE) { 489 if (state != KCS_IDLE_STATE) {
462 start_error_recovery(kcs, 490 start_error_recovery(kcs,
@@ -475,7 +503,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
475 return SI_SM_TRANSACTION_COMPLETE; 503 return SI_SM_TRANSACTION_COMPLETE;
476 } 504 }
477 break; 505 break;
478 506
479 case KCS_HOSED: 507 case KCS_HOSED:
480 break; 508 break;
481 } 509 }
@@ -495,10 +523,12 @@ static int kcs_size(void)
495 523
496static int kcs_detect(struct si_sm_data *kcs) 524static int kcs_detect(struct si_sm_data *kcs)
497{ 525{
498 /* It's impossible for the KCS status register to be all 1's, 526 /*
499 (assuming a properly functioning, self-initialized BMC) 527 * It's impossible for the KCS status register to be all 1's,
500 but that's what you get from reading a bogus address, so we 528 * (assuming a properly functioning, self-initialized BMC)
501 test that first. */ 529 * but that's what you get from reading a bogus address, so we
530 * test that first.
531 */
502 if (read_status(kcs) == 0xff) 532 if (read_status(kcs) == 0xff)
503 return 1; 533 return 1;
504 534
@@ -509,8 +539,7 @@ static void kcs_cleanup(struct si_sm_data *kcs)
509{ 539{
510} 540}
511 541
512struct si_sm_handlers kcs_smi_handlers = 542struct si_sm_handlers kcs_smi_handlers = {
513{
514 .init_data = init_kcs_data, 543 .init_data = init_kcs_data,
515 .start_transaction = start_kcs_transaction, 544 .start_transaction = start_kcs_transaction,
516 .get_result = get_kcs_result, 545 .get_result = get_kcs_result,