/* * Start to write a request. Waits for IBF to clear and then sends the * WR_START command. */ static int kcs_start_write(struct ipmi_softc *sc) { int retry, status; for (retry = 0; retry < 10; retry++) { /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); /* Clear OBF */ kcs_clear_obf(sc, status); /* Write start to command */ OUTB(sc, KCS_CTL_STS, KCS_CONTROL_WRITE_START); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_WRITE) break; DELAY(1000000); } if (KCS_STATUS_STATE(status) != KCS_STATUS_STATE_WRITE) /* error state */ return (0); /* Clear OBF */ kcs_clear_obf(sc, status); return (1); }
int ipmi_kcs_attach(struct ipmi_softc *sc) { int status; /* Setup function pointers. */ sc->ipmi_startup = kcs_startup; sc->ipmi_enqueue_request = ipmi_polled_enqueue_request; sc->ipmi_driver_request = kcs_driver_request; /* See if we can talk to the controller. */ status = INB(sc, KCS_CTL_STS); if (status == 0xff) { device_printf(sc->ipmi_dev, "couldn't find it\n"); return (ENXIO); } #ifdef KCS_DEBUG device_printf(sc->ipmi_dev, "KCS: initial state: %02x\n", status); #endif if (status & KCS_STATUS_OBF || KCS_STATUS_STATE(status) != KCS_STATUS_STATE_IDLE) kcs_error(sc); return (0); }
/* * Read one byte of the reply message. */ static int kcs_read_byte(struct ipmi_softc *sc, u_char *data) { int status; u_char dummy; /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); /* Read State */ if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_READ) { /* Wait for OBF = 1 */ status = kcs_wait_for_obf(sc, 1); if ((status & KCS_STATUS_OBF) == 0) return (0); /* Read Data_out */ *data = INB(sc, KCS_DATA); /* Write READ into Data_in */ OUTB(sc, KCS_DATA, KCS_DATA_IN_READ); return (1); } /* Idle State */ if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_IDLE) { /* Wait for OBF = 1*/ status = kcs_wait_for_obf(sc, 1); if ((status & KCS_STATUS_OBF) == 0) return (0); /* Read Dummy */ dummy = INB(sc, KCS_DATA); return (2); } /* Error State */ return (0); }
/* * Write a byte of the request message, excluding the last byte of the * message which requires special handling. */ static int kcs_write_byte(struct ipmi_softc *sc, u_char data) { int status; /* Data to Data */ OUTB(sc, KCS_DATA, data); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); if (KCS_STATUS_STATE(status) != KCS_STATUS_STATE_WRITE) return (0); /* Clear OBF */ kcs_clear_obf(sc, status); return (1); }
/* * Write the last byte of a request message. */ static int kcs_write_last_byte(struct ipmi_softc *sc, u_char data) { int status; /* Write end to command */ OUTB(sc, KCS_CTL_STS, KCS_CONTROL_WRITE_END); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); if (KCS_STATUS_STATE(status) != KCS_STATUS_STATE_WRITE) /* error state */ return (0); /* Clear OBF */ kcs_clear_obf(sc, status); /* Send data byte to DATA. */ OUTB(sc, KCS_DATA, data); return (1); }
static inline void set_state(struct kcs_bmc *kcs_bmc, u8 state) { update_status_bits(kcs_bmc, KCS_STATUS_STATE_MASK, KCS_STATUS_STATE(state)); }
/* * Determine the alignment automatically for a PCI attachment. In this case, * any unused bytes will return 0x00 when read. We make use of the C/D bit * in the CTL_STS register to try to start a GET_STATUS transaction. When * we write the command, that bit should be set, so we should get a non-zero * value back when we read CTL_STS if the offset we are testing is the CTL_STS * register. */ int ipmi_kcs_probe_align(struct ipmi_softc *sc) { int data, status; sc->ipmi_io_spacing = 1; retry: #ifdef KCS_DEBUG device_printf(sc->ipmi_dev, "Trying KCS align %d... ", sc->ipmi_io_spacing); #endif /* Wait for IBF = 0 */ status = INB(sc, KCS_CTL_STS); while (status & KCS_STATUS_IBF) { DELAY(100); status = INB(sc, KCS_CTL_STS); } OUTB(sc, KCS_CTL_STS, KCS_CONTROL_GET_STATUS_ABORT); /* Wait for IBF = 0 */ status = INB(sc, KCS_CTL_STS); while (status & KCS_STATUS_IBF) { DELAY(100); status = INB(sc, KCS_CTL_STS); } /* If we got 0x00 back, then this must not be the CTL_STS register. */ if (status == 0) { #ifdef KCS_DEBUG printf("failed\n"); #endif sc->ipmi_io_spacing <<= 1; if (sc->ipmi_io_spacing > 4) return (0); goto retry; } #ifdef KCS_DEBUG printf("ok\n"); #endif /* Finish out the transaction. */ /* Clear OBF */ if (status & KCS_STATUS_OBF) data = INB(sc, KCS_DATA); /* 0x00 to DATA_IN */ OUTB(sc, KCS_DATA, 0); /* Wait for IBF = 0 */ status = INB(sc, KCS_CTL_STS); while (status & KCS_STATUS_IBF) { DELAY(100); status = INB(sc, KCS_CTL_STS); } if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_READ) { /* Wait for IBF = 1 */ while (!(status & KCS_STATUS_OBF)) { DELAY(100); status = INB(sc, KCS_CTL_STS); } /* Read error status. */ data = INB(sc, KCS_DATA); /* Write dummy READ to DATA_IN. */ OUTB(sc, KCS_DATA, KCS_DATA_IN_READ); /* Wait for IBF = 0 */ status = INB(sc, KCS_CTL_STS); while (status & KCS_STATUS_IBF) { DELAY(100); status = INB(sc, KCS_CTL_STS); } } if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_IDLE) { /* Wait for IBF = 1 */ while (!(status & KCS_STATUS_OBF)) { DELAY(100); status = INB(sc, KCS_CTL_STS); } /* Clear OBF */ if (status & KCS_STATUS_OBF) data = INB(sc, KCS_DATA); } else device_printf(sc->ipmi_dev, "KCS probe: end state %x\n", KCS_STATUS_STATE(status)); return (1); }
static void kcs_error(struct ipmi_softc *sc) { int retry, status; u_char data; for (retry = 0; retry < 2; retry++) { /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); /* ABORT */ OUTB(sc, KCS_CTL_STS, KCS_CONTROL_GET_STATUS_ABORT); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); /* Clear OBF */ kcs_clear_obf(sc, status); if (status & KCS_STATUS_OBF) { data = INB(sc, KCS_DATA); if (data != 0) device_printf(sc->ipmi_dev, "KCS Error Data %02x\n", data); } /* 0x00 to DATA_IN */ OUTB(sc, KCS_DATA, 0x00); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_READ) { /* Wait for OBF = 1 */ status = kcs_wait_for_obf(sc, 1); /* Read error status */ data = INB(sc, KCS_DATA); if (data != 0) device_printf(sc->ipmi_dev, "KCS error: %02x\n", data); /* Write READ into Data_in */ OUTB(sc, KCS_DATA, KCS_DATA_IN_READ); /* Wait for IBF = 0 */ status = kcs_wait_for_ibf(sc, 0); } /* IDLE STATE */ if (KCS_STATUS_STATE(status) == KCS_STATUS_STATE_IDLE) { /* Wait for OBF = 1 */ status = kcs_wait_for_obf(sc, 1); /* Clear OBF */ kcs_clear_obf(sc, status); return; } } device_printf(sc->ipmi_dev, "KCS: Error retry exhausted\n"); }