Lines Matching +full:ipmi +full:- +full:bt

1 // SPDX-License-Identifier: GPL-2.0+
5 * The state machine for an Open IPMI BT sub-driver under ipmi_si.c, part
35 * Typical "Get BT Capabilities" values are 2-3 retries, 5-10 seconds,
38 * Since the Open IPMI architecture is single-message oriented at this
39 * stage, the queue depth of BT is of no concern.
48 * multiple rows of the state table discussion in the IPMI spec.
64 BT_STATE_LONG_BUSY /* BT doesn't get hosed :-) */
72 #define BT_STATE_CHANGE(X, Y) { bt->state = X; return Y; }
78 unsigned char seq; /* BT sequence number */
93 #define BT_CLR_WR_PTR 0x01 /* See IPMI 1.5 table 11.6.4 */
107 * variable "bt" is hardcoded into these macros.
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)
120 * Convenience routines for debugging. These are not multi-open safe!
142 #define STATE2TXT state2txt(bt->state)
173 static unsigned int bt_init_data(struct si_sm_data *bt, struct si_sm_io *io)
175 memset(bt, 0, sizeof(struct si_sm_data));
176 if (bt->io != io) {
177 /* external: one-time only things */
178 bt->io = io;
179 bt->seq = 0;
181 bt->state = BT_STATE_IDLE; /* start here */
182 bt->complete = BT_STATE_IDLE; /* end here */
183 bt->BT_CAP_req2rsp = BT_NORMAL_TIMEOUT * USEC_PER_SEC;
184 bt->BT_CAP_retries = BT_NORMAL_RETRY_LIMIT;
190 static void force_result(struct si_sm_data *bt, unsigned char completion_code)
192 bt->read_data[0] = 4; /* # following bytes */
193 bt->read_data[1] = bt->write_data[1] | 4; /* Odd NetFn/LUN */
194 bt->read_data[2] = bt->write_data[2]; /* seq (ignored) */
195 bt->read_data[3] = bt->write_data[3]; /* Command */
196 bt->read_data[4] = completion_code;
197 bt->read_count = 5;
202 static int bt_start_transaction(struct si_sm_data *bt,
213 if (bt->state == BT_STATE_LONG_BUSY)
216 if (bt->state != BT_STATE_IDLE) {
217 dev_warn(bt->io->dev, "BT in invalid state %d\n", bt->state);
222 dev_dbg(bt->io->dev, "+++++++++++++++++ New command\n");
223 dev_dbg(bt->io->dev, "NetFn/LUN CMD [%d data]:", size - 2);
228 bt->write_data[0] = size + 1; /* all data plus seq byte */
229 bt->write_data[1] = *data; /* NetFn/LUN */
230 bt->write_data[2] = bt->seq++;
231 memcpy(bt->write_data + 3, data + 1, size - 1);
232 bt->write_count = size + 2;
233 bt->error_retries = 0;
234 bt->nonzero_status = 0;
235 bt->truncated = 0;
236 bt->state = BT_STATE_XACTION_START;
237 bt->timeout = bt->BT_CAP_req2rsp;
238 force_result(bt, IPMI_ERR_UNSPECIFIED);
247 static int bt_get_result(struct si_sm_data *bt,
253 msg_len = bt->read_count - 2; /* account for length & seq */
255 force_result(bt, IPMI_ERR_UNSPECIFIED);
258 data[0] = bt->read_data[1];
259 data[1] = bt->read_data[3];
260 if (length < msg_len || bt->truncated) {
264 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
267 dev_dbg(bt->io->dev, "result %d bytes:", msg_len);
278 static void reset_flags(struct si_sm_data *bt)
281 dev_dbg(bt->io->dev, "flag reset %s\n", status2txt(BT_STATUS));
294 static void drain_BMC2HOST(struct si_sm_data *bt)
307 dev_dbg(bt->io->dev, "stale response %s; ",
317 static inline void write_all_bytes(struct si_sm_data *bt)
322 dev_dbg(bt->io->dev, "write %d bytes seq=0x%02X",
323 bt->write_count, bt->seq);
324 for (i = 0; i < bt->write_count; i++)
325 pr_cont(" %02x", bt->write_data[i]);
328 for (i = 0; i < bt->write_count; i++)
329 HOST2BMC(bt->write_data[i]);
332 static inline int read_all_bytes(struct si_sm_data *bt)
341 bt->read_data[0] = BMC2HOST;
342 bt->read_count = bt->read_data[0];
344 if (bt->read_count < 4 || bt->read_count >= IPMI_MAX_MSG_LENGTH) {
346 dev_dbg(bt->io->dev,
347 "bad raw rsp len=%d\n", bt->read_count);
348 bt->truncated = 1;
351 for (i = 1; i <= bt->read_count; i++)
352 bt->read_data[i] = BMC2HOST;
353 bt->read_count++; /* Account internally for length byte */
356 int max = bt->read_count;
358 dev_dbg(bt->io->dev,
359 "got %d bytes seq=0x%02X", max, bt->read_data[2]);
363 pr_cont(" %02x", bt->read_data[i]);
364 pr_cont("%s\n", bt->read_count == max ? "" : " ...");
368 if ((bt->read_data[3] == bt->write_data[3]) &&
369 (bt->read_data[2] == bt->write_data[2]) &&
370 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8)))
374 dev_dbg(bt->io->dev,
375 "IPMI BT: bad packet: want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n",
376 bt->write_data[1] | 0x04, bt->write_data[2],
377 bt->write_data[3],
378 bt->read_data[1], bt->read_data[2], bt->read_data[3]);
384 static enum si_sm_result error_recovery(struct si_sm_data *bt,
390 bt->timeout = bt->BT_CAP_req2rsp;
401 dev_warn(bt->io->dev, "IPMI BT: %s in %s %s ", /* open-ended line */
405 * Per the IPMI spec, retries are based on the sequence number
408 (bt->error_retries)++;
409 if (bt->error_retries < bt->BT_CAP_retries) {
411 bt->BT_CAP_retries - bt->error_retries);
412 bt->state = BT_STATE_RESTART;
416 dev_warn(bt->io->dev, "failed %d retries, sending error response\n",
417 bt->BT_CAP_retries);
418 if (!bt->nonzero_status)
419 dev_err(bt->io->dev, "stuck, try power cycle\n");
422 else if (bt->seq <= (unsigned char)(bt->BT_CAP_retries & 0xFF)) {
423 dev_warn(bt->io->dev, "BT reset (takes 5 secs)\n");
424 bt->state = BT_STATE_RESET1;
433 bt->state = BT_STATE_IDLE;
438 bt->state = BT_STATE_LONG_BUSY;
444 force_result(bt, cCode);
450 static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
457 bt->nonzero_status |= status;
458 if ((bt_debug & BT_DEBUG_STATES) && (bt->state != last_printed)) {
459 dev_dbg(bt->io->dev, "BT: %s %s TO=%ld - %ld\n",
462 bt->timeout,
464 last_printed = bt->state;
471 * it will be rejected by its (now-forgotten) seq number.
474 if ((bt->state < BT_STATE_WRITE_BYTES) && (status & BT_B2H_ATN)) {
475 drain_BMC2HOST(bt);
479 if ((bt->state != BT_STATE_IDLE) &&
480 (bt->state < BT_STATE_PRINTME)) {
482 bt->timeout -= time;
483 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1))
484 return error_recovery(bt,
489 switch (bt->state) {
519 write_all_bytes(bt);
539 * some BMCs don't clear B2H_ATN with one hit. Fast-path a
561 i = read_all_bytes(bt); /* true == packet seq match */
566 bt->state = bt->complete;
567 return bt->state == BT_STATE_IDLE ? /* where to next? */
573 reset_flags(bt); /* next state is now IDLE */
574 bt_init_data(bt, bt->io);
579 reset_flags(bt);
580 drain_BMC2HOST(bt);
591 bt->timeout = BT_RESET_DELAY * USEC_PER_SEC;
596 if (bt->timeout > 0)
598 drain_BMC2HOST(bt);
603 bt->read_count = 0;
604 bt->nonzero_status = 0;
605 bt->timeout = bt->BT_CAP_req2rsp;
610 return error_recovery(bt,
617 static int bt_detect(struct si_sm_data *bt)
625 * It's impossible for the BT status and interrupt registers to be
626 * all 1's, (assuming a properly functioning, self-initialized BMC)
633 reset_flags(bt);
636 * Try getting the BT capabilities here.
638 rv = bt_start_transaction(bt, GetBT_CAP, sizeof(GetBT_CAP));
640 dev_warn(bt->io->dev,
650 smi_result = bt_event(bt, jiffies_to_usecs(1));
652 smi_result = bt_event(bt, 0);
657 rv = bt_get_result(bt, BT_CAP, sizeof(BT_CAP));
658 bt_init_data(bt, bt->io);
660 dev_warn(bt->io->dev, "bt cap response too short: %d\n", rv);
665 dev_warn(bt->io->dev, "Error fetching bt cap: %x\n", BT_CAP[2]);
667 dev_warn(bt->io->dev, "using default values\n");
669 bt->BT_CAP_req2rsp = BT_CAP[6] * USEC_PER_SEC;
670 bt->BT_CAP_retries = BT_CAP[7];
673 dev_info(bt->io->dev, "req2rsp=%ld secs retries=%d\n",
674 bt->BT_CAP_req2rsp / USEC_PER_SEC, bt->BT_CAP_retries);
679 static void bt_cleanup(struct si_sm_data *bt)