Lines Matching refs:bt
72 #define BT_STATE_CHANGE(X, Y) { bt->state = X; return Y; }
110 #define BT_STATUS bt->io->inputb(bt->io, 0)
111 #define BT_CONTROL(x) bt->io->outputb(bt->io, 0, x)
113 #define BMC2HOST bt->io->inputb(bt->io, 1)
114 #define HOST2BMC(x) bt->io->outputb(bt->io, 1, x)
116 #define BT_INTMASK_R bt->io->inputb(bt->io, 2)
117 #define BT_INTMASK_W(x) bt->io->outputb(bt->io, 2, x)
142 #define STATE2TXT state2txt(bt->state)
173 static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io) in bt_init_data() argument
175 memset(bt, 0, sizeof(struct si_sm_data)); in bt_init_data()
176 if (bt->io != io) { in bt_init_data()
178 bt->io = io; in bt_init_data()
179 bt->seq = 0; in bt_init_data()
181 bt->state = BT_STATE_IDLE; /* start here */ in bt_init_data()
182 bt->complete = BT_STATE_IDLE; /* end here */ in bt_init_data()
183 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC; in bt_init_data()
184 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT; in bt_init_data()
190 static void force_result(struct si_sm_data *bt, unsigned char completion_code) in force_result() argument
192 bt->read_data[0] = 4; /* # following bytes */ in force_result()
193 bt->read_data[1] = bt->write_data[1] | 4; /* Odd NetFn/LUN */ in force_result()
194 bt->read_data[2] = bt->write_data[2]; /* seq (ignored) */ in force_result()
195 bt->read_data[3] = bt->write_data[3]; /* Command */ in force_result()
196 bt->read_data[4] = completion_code; in force_result()
197 bt->read_count = 5; in force_result()
202 static int bt_start_transaction(struct si_sm_data *bt, in bt_start_transaction() argument
213 if (bt->state == BT_STATE_LONG_BUSY) in bt_start_transaction()
216 if (bt->state != BT_STATE_IDLE) in bt_start_transaction()
220 dev_dbg(bt->io->dev, "+++++++++++++++++ New command\n"); in bt_start_transaction()
221 dev_dbg(bt->io->dev, "NetFn/LUN CMD [%d data]:", size - 2); in bt_start_transaction()
226 bt->write_data[0] = size + 1; /* all data plus seq byte */ in bt_start_transaction()
227 bt->write_data[1] = *data; /* NetFn/LUN */ in bt_start_transaction()
228 bt->write_data[2] = bt->seq++; in bt_start_transaction()
229 memcpy(bt->write_data + 3, data + 1, size - 1); in bt_start_transaction()
230 bt->write_count = size + 2; in bt_start_transaction()
231 bt->error_retries = 0; in bt_start_transaction()
232 bt->nonzero_status = 0; in bt_start_transaction()
233 bt->truncated = 0; in bt_start_transaction()
234 bt->state = BT_STATE_XACTION_START; in bt_start_transaction()
235 bt->timeout = bt->BT_CAP_req2rsp; in bt_start_transaction()
236 force_result(bt, IPMI_ERR_UNSPECIFIED); in bt_start_transaction()
245 static int bt_get_result(struct si_sm_data *bt, in bt_get_result() argument
251 msg_len = bt->read_count - 2; /* account for length & seq */ in bt_get_result()
253 force_result(bt, IPMI_ERR_UNSPECIFIED); in bt_get_result()
256 data[0] = bt->read_data[1]; in bt_get_result()
257 data[1] = bt->read_data[3]; in bt_get_result()
258 if (length < msg_len || bt->truncated) { in bt_get_result()
262 memcpy(data + 2, bt->read_data + 4, msg_len - 2); in bt_get_result()
265 dev_dbg(bt->io->dev, "result %d bytes:", msg_len); in bt_get_result()
276 static void reset_flags(struct si_sm_data *bt) in reset_flags() argument
279 dev_dbg(bt->io->dev, "flag reset %s\n", status2txt(BT_STATUS)); in reset_flags()
292 static void drain_BMC2HOST(struct si_sm_data *bt) in drain_BMC2HOST() argument
305 dev_dbg(bt->io->dev, "stale response %s; ", in drain_BMC2HOST()
315 static inline void write_all_bytes(struct si_sm_data *bt) in write_all_bytes() argument
320 dev_dbg(bt->io->dev, "write %d bytes seq=0x%02X", in write_all_bytes()
321 bt->write_count, bt->seq); in write_all_bytes()
322 for (i = 0; i < bt->write_count; i++) in write_all_bytes()
323 pr_cont(" %02x", bt->write_data[i]); in write_all_bytes()
326 for (i = 0; i < bt->write_count; i++) in write_all_bytes()
327 HOST2BMC(bt->write_data[i]); in write_all_bytes()
330 static inline int read_all_bytes(struct si_sm_data *bt) in read_all_bytes() argument
339 bt->read_data[0] = BMC2HOST; in read_all_bytes()
340 bt->read_count = bt->read_data[0]; in read_all_bytes()
342 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) { in read_all_bytes()
344 dev_dbg(bt->io->dev, in read_all_bytes()
345 "bad raw rsp len=%d\n", bt->read_count); in read_all_bytes()
346 bt->truncated = 1; in read_all_bytes()
349 for (i = 1; i <= bt->read_count; i++) in read_all_bytes()
350 bt->read_data[i] = BMC2HOST; in read_all_bytes()
351 bt->read_count++; /* Account internally for length byte */ in read_all_bytes()
354 int max = bt->read_count; in read_all_bytes()
356 dev_dbg(bt->io->dev, in read_all_bytes()
357 "got %d bytes seq=0x%02X", max, bt->read_data[2]); in read_all_bytes()
361 pr_cont(" %02x", bt->read_data[i]); in read_all_bytes()
362 pr_cont("%s\n", bt->read_count == max ? "" : " ..."); in read_all_bytes()
366 if ((bt->read_data[3] == bt->write_data[3]) && in read_all_bytes()
367 (bt->read_data[2] == bt->write_data[2]) && in read_all_bytes()
368 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8))) in read_all_bytes()
372 dev_dbg(bt->io->dev, in read_all_bytes()
374 bt->write_data[1] | 0x04, bt->write_data[2], in read_all_bytes()
375 bt->write_data[3], in read_all_bytes()
376 bt->read_data[1], bt->read_data[2], bt->read_data[3]); in read_all_bytes()
382 static enum si_sm_result error_recovery(struct si_sm_data *bt, in error_recovery() argument
388 bt->timeout = bt->BT_CAP_req2rsp; in error_recovery()
399 dev_warn(bt->io->dev, "IPMI BT: %s in %s %s ", /* open-ended line */ in error_recovery()
406 (bt->error_retries)++; in error_recovery()
407 if (bt->error_retries < bt->BT_CAP_retries) { in error_recovery()
409 bt->BT_CAP_retries - bt->error_retries); in error_recovery()
410 bt->state = BT_STATE_RESTART; in error_recovery()
414 dev_warn(bt->io->dev, "failed %d retries, sending error response\n", in error_recovery()
415 bt->BT_CAP_retries); in error_recovery()
416 if (!bt->nonzero_status) in error_recovery()
417 dev_err(bt->io->dev, "stuck, try power cycle\n"); in error_recovery()
420 else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) { in error_recovery()
421 dev_warn(bt->io->dev, "BT reset (takes 5 secs)\n"); in error_recovery()
422 bt->state = BT_STATE_RESET1; in error_recovery()
431 bt->state = BT_STATE_IDLE; in error_recovery()
436 bt->state = BT_STATE_LONG_BUSY; in error_recovery()
442 force_result(bt, cCode); in error_recovery()
448 static enum si_sm_result bt_event(struct si_sm_data *bt, long time) in bt_event() argument
455 bt->nonzero_status |= status; in bt_event()
456 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) { in bt_event()
457 dev_dbg(bt->io->dev, "BT: %s %s TO=%ld - %ld\n", in bt_event()
460 bt->timeout, in bt_event()
462 last_printed = bt->state; in bt_event()
472 if ((bt->state < BT_STATE_WRITE_BYTES) && (status & BT_B2H_ATN)) { in bt_event()
473 drain_BMC2HOST(bt); in bt_event()
477 if ((bt->state != BT_STATE_IDLE) && in bt_event()
478 (bt->state < BT_STATE_PRINTME)) { in bt_event()
480 bt->timeout -= time; in bt_event()
481 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) in bt_event()
482 return error_recovery(bt, in bt_event()
487 switch (bt->state) { in bt_event()
517 write_all_bytes(bt); in bt_event()
559 i = read_all_bytes(bt); /* true == packet seq match */ in bt_event()
564 bt->state = bt->complete; in bt_event()
565 return bt->state == BT_STATE_IDLE ? /* where to next? */ in bt_event()
571 reset_flags(bt); /* next state is now IDLE */ in bt_event()
572 bt_init_data(bt, bt->io); in bt_event()
577 reset_flags(bt); in bt_event()
578 drain_BMC2HOST(bt); in bt_event()
589 bt->timeout = BT_RESET_DELAY * USEC_PER_SEC; in bt_event()
594 if (bt->timeout > 0) in bt_event()
596 drain_BMC2HOST(bt); in bt_event()
601 bt->read_count = 0; in bt_event()
602 bt->nonzero_status = 0; in bt_event()
603 bt->timeout = bt->BT_CAP_req2rsp; in bt_event()
608 return error_recovery(bt, in bt_event()
615 static int bt_detect(struct si_sm_data *bt) in bt_detect() argument
631 reset_flags(bt); in bt_detect()
636 rv = bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP)); in bt_detect()
638 dev_warn(bt->io->dev, in bt_detect()
648 smi_result = bt_event(bt, jiffies_to_usecs(1)); in bt_detect()
650 smi_result = bt_event(bt, 0); in bt_detect()
655 rv = bt_get_result(bt, BT_CAP, sizeof(BT_CAP)); in bt_detect()
656 bt_init_data(bt, bt->io); in bt_detect()
658 dev_warn(bt->io->dev, "bt cap response too short: %d\n", rv); in bt_detect()
663 dev_warn(bt->io->dev, "Error fetching bt cap: %x\n", BT_CAP[2]); in bt_detect()
665 dev_warn(bt->io->dev, "using default values\n"); in bt_detect()
667 bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC; in bt_detect()
668 bt->BT_CAP_retries = BT_CAP[7]; in bt_detect()
671 dev_info(bt->io->dev, "req2rsp=%ld secs retries=%d\n", in bt_detect()
672 bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries); in bt_detect()
677 static void bt_cleanup(struct si_sm_data *bt) in bt_cleanup() argument