H A D | ipmi_smic_sm.c | 122 static unsigned int init_smic_data(struct si_sm_data *smic, init_smic_data() argument 125 smic->state = SMIC_IDLE; init_smic_data() 126 smic->io = io; init_smic_data() 127 smic->write_pos = 0; init_smic_data() 128 smic->write_count = 0; init_smic_data() 129 smic->orig_write_count = 0; init_smic_data() 130 smic->read_pos = 0; init_smic_data() 131 smic->error_retries = 0; init_smic_data() 132 smic->truncated = 0; init_smic_data() 133 smic->smic_timeout = SMIC_RETRY_TIMEOUT; init_smic_data() 139 static int start_smic_transaction(struct si_sm_data *smic, start_smic_transaction() argument 149 if ((smic->state != SMIC_IDLE) && (smic->state != SMIC_HOSED)) start_smic_transaction() 158 smic->error_retries = 0; start_smic_transaction() 159 memcpy(smic->write_data, data, size); start_smic_transaction() 160 smic->write_count = size; start_smic_transaction() 161 smic->orig_write_count = size; start_smic_transaction() 162 smic->write_pos = 0; start_smic_transaction() 163 smic->read_pos = 0; start_smic_transaction() 164 smic->state = SMIC_START_OP; start_smic_transaction() 165 smic->smic_timeout = SMIC_RETRY_TIMEOUT; start_smic_transaction() 169 static int smic_get_result(struct si_sm_data *smic, smic_get_result() argument 176 for (i = 0; i < smic->read_pos; i++) smic_get_result() 177 printk(" %02x", smic->read_data[i]); smic_get_result() 180 if (length < smic->read_pos) { smic_get_result() 181 smic->read_pos = length; smic_get_result() 182 smic->truncated = 1; smic_get_result() 184 memcpy(data, smic->read_data, smic->read_pos); smic_get_result() 186 if ((length >= 3) && (smic->read_pos < 3)) { smic_get_result() 188 smic->read_pos = 3; smic_get_result() 190 if (smic->truncated) { smic_get_result() 192 smic->truncated = 0; smic_get_result() 194 return smic->read_pos; smic_get_result() 197 static inline unsigned char read_smic_flags(struct si_sm_data *smic) read_smic_flags() argument 199 return smic->io->inputb(smic->io, 2); read_smic_flags() 202 static inline unsigned char read_smic_status(struct si_sm_data *smic) read_smic_status() argument 204 return smic->io->inputb(smic->io, 1); read_smic_status() 207 static inline unsigned char read_smic_data(struct si_sm_data *smic) read_smic_data() argument 209 return smic->io->inputb(smic->io, 0); read_smic_data() 212 static inline void write_smic_flags(struct si_sm_data *smic, write_smic_flags() argument 215 smic->io->outputb(smic->io, 2, flags); write_smic_flags() 218 static inline void write_smic_control(struct si_sm_data *smic, write_smic_control() argument 221 smic->io->outputb(smic->io, 1, control); write_smic_control() 224 static inline void write_si_sm_data(struct si_sm_data *smic, write_si_sm_data() argument 227 smic->io->outputb(smic->io, 0, data); write_si_sm_data() 230 static inline void start_error_recovery(struct si_sm_data *smic, char *reason) start_error_recovery() argument 232 (smic->error_retries)++; start_error_recovery() 233 if (smic->error_retries > SMIC_MAX_ERROR_RETRIES) { start_error_recovery() 236 "ipmi_smic_drv: smic hosed: %s\n", reason); start_error_recovery() 237 smic->state = SMIC_HOSED; start_error_recovery() 239 smic->write_count = smic->orig_write_count; start_error_recovery() 240 smic->write_pos = 0; start_error_recovery() 241 smic->read_pos = 0; start_error_recovery() 242 smic->state = SMIC_START_OP; start_error_recovery() 243 smic->smic_timeout = SMIC_RETRY_TIMEOUT; start_error_recovery() 247 static inline void write_next_byte(struct si_sm_data *smic) write_next_byte() argument 249 write_si_sm_data(smic, smic->write_data[smic->write_pos]); write_next_byte() 250 (smic->write_pos)++; write_next_byte() 251 (smic->write_count)--; write_next_byte() 254 static inline void read_next_byte(struct si_sm_data *smic) read_next_byte() argument 256 if (smic->read_pos >= MAX_SMIC_READ_SIZE) { read_next_byte() 257 read_smic_data(smic); read_next_byte() 258 smic->truncated = 1; read_next_byte() 260 smic->read_data[smic->read_pos] = read_smic_data(smic); read_next_byte() 261 smic->read_pos++; read_next_byte() 336 static enum si_sm_result smic_event(struct si_sm_data *smic, long time) smic_event() argument 342 if (smic->state == SMIC_HOSED) { smic_event() 343 init_smic_data(smic, smic->io); smic_event() 346 if (smic->state != SMIC_IDLE) { smic_event() 349 "smic_event - smic->smic_timeout = %ld," smic_event() 351 smic->smic_timeout, time); smic_event() 357 smic->smic_timeout -= time; smic_event() 358 if (smic->smic_timeout < 0) { smic_event() 359 start_error_recovery(smic, "smic timed out."); smic_event() 364 flags = read_smic_flags(smic); smic_event() 368 status = read_smic_status(smic); smic_event() 373 smic->state, flags, status); smic_event() 375 switch (smic->state) { smic_event() 383 /* sanity check whether smic is really idle */ smic_event() 384 write_smic_control(smic, SMIC_CC_SMS_GET_STATUS); smic_event() 385 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 386 smic->state = SMIC_OP_OK; smic_event() 392 start_error_recovery(smic, smic_event() 397 /* OK so far; smic is idle let us start ... */ smic_event() 398 write_smic_control(smic, SMIC_CC_SMS_WR_START); smic_event() 399 write_next_byte(smic); smic_event() 400 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 401 smic->state = SMIC_WRITE_START; smic_event() 406 start_error_recovery(smic, smic_event() 416 if (smic->write_count == 1) { smic_event() 418 write_smic_control(smic, SMIC_CC_SMS_WR_END); smic_event() 419 smic->state = SMIC_WRITE_END; smic_event() 421 write_smic_control(smic, SMIC_CC_SMS_WR_NEXT); smic_event() 422 smic->state = SMIC_WRITE_NEXT; smic_event() 424 write_next_byte(smic); smic_event() 425 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 432 start_error_recovery(smic, smic_event() 439 if (smic->write_count == 1) { smic_event() 440 write_smic_control(smic, SMIC_CC_SMS_WR_END); smic_event() 441 smic->state = SMIC_WRITE_END; smic_event() 443 write_smic_control(smic, SMIC_CC_SMS_WR_NEXT); smic_event() 444 smic->state = SMIC_WRITE_NEXT; smic_event() 446 write_next_byte(smic); smic_event() 447 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 454 start_error_recovery(smic, smic_event() 460 data = read_smic_data(smic); smic_event() 465 start_error_recovery(smic, smic_event() 470 smic->state = SMIC_WRITE2READ; smic_event() 479 write_smic_control(smic, SMIC_CC_SMS_RD_START); smic_event() 480 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 481 smic->state = SMIC_READ_START; smic_event() 488 start_error_recovery(smic, smic_event() 494 read_next_byte(smic); smic_event() 495 write_smic_control(smic, SMIC_CC_SMS_RD_NEXT); smic_event() 496 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 497 smic->state = SMIC_READ_NEXT; smic_event() 505 * smic tells us that this is the last byte to be read smic_event() 509 read_next_byte(smic); smic_event() 510 write_smic_control(smic, SMIC_CC_SMS_RD_END); smic_event() 511 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 512 smic->state = SMIC_READ_END; smic_event() 516 read_next_byte(smic); smic_event() 517 write_smic_control(smic, SMIC_CC_SMS_RD_NEXT); smic_event() 518 write_smic_flags(smic, flags | SMIC_FLAG_BSY); smic_event() 519 smic->state = SMIC_READ_NEXT; smic_event() 525 smic, smic_event() 534 start_error_recovery(smic, smic_event() 539 data = read_smic_data(smic); smic_event() 545 start_error_recovery(smic, smic_event() 550 smic->state = SMIC_IDLE; smic_event() 555 init_smic_data(smic, smic->io); smic_event() 560 printk(KERN_DEBUG "smic->state = %d\n", smic->state); smic_event() 561 start_error_recovery(smic, "state = UNKNOWN"); smic_event() 565 smic->smic_timeout = SMIC_RETRY_TIMEOUT; smic_event() 569 static int smic_detect(struct si_sm_data *smic) smic_detect() argument 577 if (read_smic_flags(smic) == 0xff) smic_detect()
|