Lines Matching refs:bt

70 #define BT_STATE_CHANGE(X, Y) { bt->state = X; return Y; }
108 #define BT_STATUS bt->io->inputb(bt->io, 0)
109 #define BT_CONTROL(x) bt->io->outputb(bt->io, 0, x)
111 #define BMC2HOST bt->io->inputb(bt->io, 1)
112 #define HOST2BMC(x) bt->io->outputb(bt->io, 1, x)
114 #define BT_INTMASK_R bt->io->inputb(bt->io, 2)
115 #define BT_INTMASK_W(x) bt->io->outputb(bt->io, 2, x)
140 #define STATE2TXT state2txt(bt->state)
171 static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io) in bt_init_data() argument
173 memset(bt, 0, sizeof(struct si_sm_data)); in bt_init_data()
174 if (bt->io != io) { in bt_init_data()
176 bt->io = io; in bt_init_data()
177 bt->seq = 0; in bt_init_data()
179 bt->state = BT_STATE_IDLE; /* start here */ in bt_init_data()
180 bt->complete = BT_STATE_IDLE; /* end here */ in bt_init_data()
181 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC; in bt_init_data()
182 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT; in bt_init_data()
188 static void force_result(struct si_sm_data *bt, unsigned char completion_code) in force_result() argument
190 bt->read_data[0] = 4; /* # following bytes */ in force_result()
191 bt->read_data[1] = bt->write_data[1] | 4; /* Odd NetFn/LUN */ in force_result()
192 bt->read_data[2] = bt->write_data[2]; /* seq (ignored) */ in force_result()
193 bt->read_data[3] = bt->write_data[3]; /* Command */ in force_result()
194 bt->read_data[4] = completion_code; in force_result()
195 bt->read_count = 5; in force_result()
200 static int bt_start_transaction(struct si_sm_data *bt, in bt_start_transaction() argument
211 if (bt->state == BT_STATE_LONG_BUSY) in bt_start_transaction()
214 if (bt->state != BT_STATE_IDLE) in bt_start_transaction()
224 bt->write_data[0] = size + 1; /* all data plus seq byte */ in bt_start_transaction()
225 bt->write_data[1] = *data; /* NetFn/LUN */ in bt_start_transaction()
226 bt->write_data[2] = bt->seq++; in bt_start_transaction()
227 memcpy(bt->write_data + 3, data + 1, size - 1); in bt_start_transaction()
228 bt->write_count = size + 2; in bt_start_transaction()
229 bt->error_retries = 0; in bt_start_transaction()
230 bt->nonzero_status = 0; in bt_start_transaction()
231 bt->truncated = 0; in bt_start_transaction()
232 bt->state = BT_STATE_XACTION_START; in bt_start_transaction()
233 bt->timeout = bt->BT_CAP_req2rsp; in bt_start_transaction()
234 force_result(bt, IPMI_ERR_UNSPECIFIED); in bt_start_transaction()
243 static int bt_get_result(struct si_sm_data *bt, in bt_get_result() argument
249 msg_len = bt->read_count - 2; /* account for length & seq */ in bt_get_result()
251 force_result(bt, IPMI_ERR_UNSPECIFIED); in bt_get_result()
254 data[0] = bt->read_data[1]; in bt_get_result()
255 data[1] = bt->read_data[3]; in bt_get_result()
256 if (length < msg_len || bt->truncated) { in bt_get_result()
260 memcpy(data + 2, bt->read_data + 4, msg_len - 2); in bt_get_result()
274 static void reset_flags(struct si_sm_data *bt) in reset_flags() argument
291 static void drain_BMC2HOST(struct si_sm_data *bt) in drain_BMC2HOST() argument
314 static inline void write_all_bytes(struct si_sm_data *bt) in write_all_bytes() argument
320 bt->write_count, bt->seq); in write_all_bytes()
321 for (i = 0; i < bt->write_count; i++) in write_all_bytes()
322 printk(" %02x", bt->write_data[i]); in write_all_bytes()
325 for (i = 0; i < bt->write_count; i++) in write_all_bytes()
326 HOST2BMC(bt->write_data[i]); in write_all_bytes()
329 static inline int read_all_bytes(struct si_sm_data *bt) in read_all_bytes() argument
338 bt->read_data[0] = BMC2HOST; in read_all_bytes()
339 bt->read_count = bt->read_data[0]; in read_all_bytes()
341 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { in read_all_bytes()
344 bt->read_count); in read_all_bytes()
345 bt->truncated = 1; in read_all_bytes()
348 for (i = 1; i <= bt->read_count; i++) in read_all_bytes()
349 bt->read_data[i] = BMC2HOST; in read_all_bytes()
350 bt->read_count++; /* Account internally for length byte */ in read_all_bytes()
353 int max = bt->read_count; in read_all_bytes()
356 max, bt->read_data[2]); in read_all_bytes()
360 printk(KERN_CONT " %02x", bt->read_data[i]); in read_all_bytes()
361 printk(KERN_CONT "%s\n", bt->read_count == max ? "" : " ..."); in read_all_bytes()
365 if ((bt->read_data[3] == bt->write_data[3]) && in read_all_bytes()
366 (bt->read_data[2] == bt->write_data[2]) && in read_all_bytes()
367 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8))) in read_all_bytes()
373 bt->write_data[1] | 0x04, bt->write_data[2], bt->write_data[3], in read_all_bytes()
374 bt->read_data[1], bt->read_data[2], bt->read_data[3]); in read_all_bytes()
380 static enum si_sm_result error_recovery(struct si_sm_data *bt, in error_recovery() argument
386 bt->timeout = bt->BT_CAP_req2rsp; in error_recovery()
404 (bt->error_retries)++; in error_recovery()
405 if (bt->error_retries < bt->BT_CAP_retries) { in error_recovery()
407 bt->BT_CAP_retries - bt->error_retries); in error_recovery()
408 bt->state = BT_STATE_RESTART; in error_recovery()
413 bt->BT_CAP_retries); in error_recovery()
414 if (!bt->nonzero_status) in error_recovery()
418 else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) { in error_recovery()
420 bt->state = BT_STATE_RESET1; in error_recovery()
429 bt->state = BT_STATE_IDLE; in error_recovery()
434 bt->state = BT_STATE_LONG_BUSY; in error_recovery()
440 force_result(bt, cCode); in error_recovery()
446 static enum si_sm_result bt_event(struct si_sm_data *bt, long time) in bt_event() argument
453 bt->nonzero_status |= status; in bt_event()
454 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) { in bt_event()
458 bt->timeout, in bt_event()
460 last_printed = bt->state; in bt_event()
470 if ((bt->state < BT_STATE_WRITE_BYTES) && (status & BT_B2H_ATN)) { in bt_event()
471 drain_BMC2HOST(bt); in bt_event()
475 if ((bt->state != BT_STATE_IDLE) && in bt_event()
476 (bt->state < BT_STATE_PRINTME)) { in bt_event()
478 bt->timeout -= time; in bt_event()
479 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) in bt_event()
480 return error_recovery(bt, in bt_event()
485 switch (bt->state) { in bt_event()
515 write_all_bytes(bt); in bt_event()
557 i = read_all_bytes(bt); /* true == packet seq match */ in bt_event()
562 bt->state = bt->complete; in bt_event()
563 return bt->state == BT_STATE_IDLE ? /* where to next? */ in bt_event()
569 reset_flags(bt); /* next state is now IDLE */ in bt_event()
570 bt_init_data(bt, bt->io); in bt_event()
575 reset_flags(bt); in bt_event()
576 drain_BMC2HOST(bt); in bt_event()
587 bt->timeout = BT_RESET_DELAY * USEC_PER_SEC; in bt_event()
592 if (bt->timeout > 0) in bt_event()
594 drain_BMC2HOST(bt); in bt_event()
599 bt->read_count = 0; in bt_event()
600 bt->nonzero_status = 0; in bt_event()
601 bt->timeout = bt->BT_CAP_req2rsp; in bt_event()
606 return error_recovery(bt, in bt_event()
613 static int bt_detect(struct si_sm_data *bt) in bt_detect() argument
629 reset_flags(bt); in bt_detect()
634 rv = bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP)); in bt_detect()
636 dev_warn(bt->io->dev, in bt_detect()
646 smi_result = bt_event(bt, jiffies_to_usecs(1)); in bt_detect()
648 smi_result = bt_event(bt, 0); in bt_detect()
653 rv = bt_get_result(bt, BT_CAP, sizeof(BT_CAP)); in bt_detect()
654 bt_init_data(bt, bt->io); in bt_detect()
656 dev_warn(bt->io->dev, "bt cap response too short: %d\n", rv); in bt_detect()
661 dev_warn(bt->io->dev, "Error fetching bt cap: %x\n", BT_CAP[2]); in bt_detect()
663 dev_warn(bt->io->dev, "using default values\n"); in bt_detect()
665 bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC; in bt_detect()
666 bt->BT_CAP_retries = BT_CAP[7]; in bt_detect()
669 dev_info(bt->io->dev, "req2rsp=%ld secs retries=%d\n", in bt_detect()
670 bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries); in bt_detect()
675 static void bt_cleanup(struct si_sm_data *bt) in bt_cleanup() argument