This is the first part of the big ipmi(4) patch I sent in another thread.
This removes complicate polling timeout code. Serial communication with BMC
is slow but considered as reliable. Communication failure is a fatal problem.
Returning error doesn't make sense.
This also removes unfinished interrupt handling. Access is always done in
polling manner.
OK?
diff --git a/sys/dev/ipmi.c b/sys/dev/ipmi.c
index a1156d8..91aa147 100644
--- a/sys/dev/ipmi.c
+++ b/sys/dev/ipmi.c
@@ -32,13 +32,11 @@
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/extent.h>
-#include <sys/timeout.h>
#include <sys/sensors.h>
#include <sys/malloc.h>
#include <sys/kthread.h>
#include <machine/bus.h>
-#include <machine/intr.h>
#include <machine/smbiosvar.h>
#include <dev/isa/isareg.h>
@@ -55,8 +53,6 @@ struct ipmi_sensor {
SLIST_ENTRY(ipmi_sensor) list;
};
-int ipmi_nintr;
-int ipmi_poll = 1;
int ipmi_enabled = 0;
#define SENSOR_REFRESH_RATE (5 * hz)
@@ -139,8 +135,6 @@ SLIST_HEAD(ipmi_sensors_head, ipmi_sensor);
struct ipmi_sensors_head ipmi_sensor_list =
SLIST_HEAD_INITIALIZER(ipmi_sensor_list);
-struct timeout ipmi_timeout;
-
void dumpb(const char *, int, const u_int8_t *);
int read_sensor(struct ipmi_softc *, struct ipmi_sensor *);
@@ -155,7 +149,6 @@ void ipmi_delay(struct ipmi_softc *, int);
int ipmi_watchdog(void *, int);
-int ipmi_intr(void *);
int ipmi_match(struct device *, void *, void *);
void ipmi_attach(struct device *, struct device *, void *);
int ipmi_activate(struct device *, int);
@@ -168,9 +161,6 @@ void ipmi_sensor_name(char *, int, u_int8_t,
u_int8_t *);
u_int8_t bmc_read(struct ipmi_softc *, int);
void bmc_write(struct ipmi_softc *, int, u_int8_t);
int bmc_io_wait(struct ipmi_softc *, int, u_int8_t, u_int8_t, const char *);
-int bmc_io_wait_cold(struct ipmi_softc *, int, u_int8_t, u_int8_t,
- const char *);
-void _bmc_io_wait(void *);
void *bt_buildmsg(struct ipmi_softc *, int, int, int, const void *, int *);
void *cmn_buildmsg(struct ipmi_softc *, int, int, int, const void *, int *);
@@ -256,66 +246,11 @@ bmc_write(struct ipmi_softc *sc, int offset, u_int8_t val)
offset * sc->sc_if_iospacing, val);
}
-void
-_bmc_io_wait(void *arg)
-{
- struct ipmi_softc *sc = arg;
- struct ipmi_bmc_args *a = sc->sc_iowait_args;
-
- *a->v = bmc_read(sc, a->offset);
- if ((*a->v & a->mask) == a->value) {
- sc->sc_wakeup = 0;
- wakeup(sc);
- return;
- }
-
- if (++sc->sc_retries > sc->sc_max_retries) {
- sc->sc_wakeup = 0;
- wakeup(sc);
- return;
- }
-
- timeout_add(&sc->sc_timeout, 1);
-}
-
int
bmc_io_wait(struct ipmi_softc *sc, int offset, u_int8_t mask, u_int8_t value,
const char *lbl)
{
volatile u_int8_t v;
- struct ipmi_bmc_args args;
-
- if (cold || sc->sc_poll)
- return (bmc_io_wait_cold(sc, offset, mask, value, lbl));
-
- sc->sc_retries = 0;
- sc->sc_wakeup = 1;
-
- args.offset = offset;
- args.mask = mask;
- args.value = value;
- args.v = &v;
- sc->sc_iowait_args = &args;
-
- _bmc_io_wait(sc);
-
- while (sc->sc_wakeup)
- tsleep(sc, PWAIT, lbl, 0);
-
- if (sc->sc_retries > sc->sc_max_retries) {
- dbg_printf(1, "%s: bmc_io_wait fails : v=%.2x m=%.2x "
- "b=%.2x %s\n", DEVNAME(sc), v, mask, value, lbl);
- return (-1);
- }
-
- return (v);
-}
-
-int
-bmc_io_wait_cold(struct ipmi_softc *sc, int offset, u_int8_t mask,
- u_int8_t value, const char *lbl)
-{
- volatile u_int8_t v;
int count = 5000000; /* == 5s XXX can be shorter */
while (count--) {
@@ -326,7 +261,7 @@ bmc_io_wait_cold(struct ipmi_softc *sc, int offset,
u_int8_t mask,
delay(1);
}
- dbg_printf(1, "%s: bmc_io_wait_cold fails : *v=%.2x m=%.2x b=%.2x %s\n",
+ dbg_printf(1, "%s: bmc_io_wait fails : *v=%.2x m=%.2x b=%.2x %s\n",
DEVNAME(sc), v, mask, value, lbl);
return (-1);
@@ -1082,11 +1017,7 @@ void
ipmi_delay(struct ipmi_softc *sc, int period)
{
/* period is in 10 ms increments */
- if (cold || sc->sc_poll)
- delay(period * 10000);
- else
- while (tsleep(sc, PWAIT, "ipmicmd", period) != EWOULDBLOCK)
- continue;
+ delay(period * 10000);
}
/* Read a partial SDR entry */
@@ -1530,27 +1461,10 @@ add_child_sensors(struct ipmi_softc *sc, u_int8_t
*psdr, int count,
return (1);
}
-/* Interrupt handler */
-int
-ipmi_intr(void *arg)
-{
- struct ipmi_softc *sc = (struct ipmi_softc *)arg;
- int v;
-
- v = bmc_read(sc, _KCS_STATUS_REGISTER);
- if (v & KCS_OBF)
- ++ipmi_nintr;
-
- return (0);
-}
-
/* Handle IPMI Timer - reread sensor values */
void
ipmi_refresh_sensors(struct ipmi_softc *sc)
{
- if (!ipmi_poll)
- return;
-
if (SLIST_EMPTY(&ipmi_sensor_list))
return;
@@ -1588,11 +1502,6 @@ ipmi_map_regs(struct ipmi_softc *sc, struct
ipmi_attach_args *ia)
sc->sc_if->nregs * sc->sc_if_iospacing, &sc->sc_ioh);
return (-1);
}
-#if 0
- if (iaa->if_if_irq != -1)
- sc->ih = isa_intr_establish(-1, iaa->if_if_irq,
- iaa->if_irqlvl, IPL_BIO, ipmi_intr, sc, DEVNAME(sc));
-#endif
return (0);
}
@@ -1757,12 +1666,6 @@ ipmi_attach(struct device *parent, struct device *self,
void *aux)
/* lock around read_sensor so that no one messes with the bmc regs */
rw_init(&sc->sc_lock, DEVNAME(sc));
-
- /* setup ticker */
- sc->sc_retries = 0;
- sc->sc_wakeup = 0;
- sc->sc_max_retries = 50; /* 50 * 1/100 = 0.5 seconds max */
- timeout_set(&sc->sc_timeout, _bmc_io_wait, sc);
}
int
@@ -1787,12 +1690,10 @@ ipmi_watchdog(void *arg, int period)
if (sc->sc_wdog_period == period) {
if (period != 0) {
s = splsoftclock();
- sc->sc_poll = 1;
/* tickle the watchdog */
rc = ipmi_sendcmd(sc, BMC_SA, BMC_LUN, APP_NETFN,
APP_RESET_WATCHDOG, 0, NULL);
rc = ipmi_recvcmd(sc, 0, &len, NULL);
- sc->sc_poll = 0;
splx(s);
}
return (period);
@@ -1802,7 +1703,6 @@ ipmi_watchdog(void *arg, int period)
period = 10;
s = splsoftclock();
- sc->sc_poll = 1;
/* XXX what to do if poking wdog fails? */
rc = ipmi_sendcmd(sc, BMC_SA, BMC_LUN, APP_NETFN,
APP_GET_WATCHDOG_TIMER, 0, NULL);
@@ -1820,7 +1720,6 @@ ipmi_watchdog(void *arg, int period)
APP_SET_WATCHDOG_TIMER, IPMI_SET_WDOG_MAX, wdog);
rc = ipmi_recvcmd(sc, 0, &len, NULL);
- sc->sc_poll = 0;
splx(s);
sc->sc_wdog_period = period;
diff --git a/sys/dev/ipmivar.h b/sys/dev/ipmivar.h
index 934faa5..c0ae492 100644
--- a/sys/dev/ipmivar.h
+++ b/sys/dev/ipmivar.h
@@ -30,7 +30,6 @@
#ifndef _IPMIVAR_H_
#define _IPMIVAR_H_
-#include <sys/timeout.h>
#include <sys/rwlock.h>
#include <sys/sensors.h>
@@ -94,19 +93,12 @@ struct ipmi_softc {
struct ipmi_thread *sc_thread;
- struct timeout sc_timeout;
- int sc_max_retries;
- int sc_retries;
- int sc_wakeup;
-
struct rwlock sc_lock;
struct ipmi_bmc_args *sc_iowait_args;
struct ipmi_sensor *current_sensor;
struct ksensordev sc_sensordev;
-
- int sc_poll;
};
struct ipmi_thread {