summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-04-30 22:53:10 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-04-30 22:53:10 +0000
commit99beccf5f8090559ad8dfc7fbbd1161bdadf4c1a (patch)
treea0f2f636d63898b8f7ee391b9f3ceab6a6acc658
parent27dd3f05c143da3802ebf2a95074c9c83675ce54 (diff)
better handling of the firmware state madness
-rw-r--r--sys/dev/pci/if_nx.c68
-rw-r--r--sys/dev/pci/if_nxreg.h18
2 files changed, 56 insertions, 30 deletions
diff --git a/sys/dev/pci/if_nx.c b/sys/dev/pci/if_nx.c
index 11d426accfe..df6247a5f2a 100644
--- a/sys/dev/pci/if_nx.c
+++ b/sys/dev/pci/if_nx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_nx.c,v 1.29 2007/04/30 22:09:16 reyk Exp $ */
+/* $OpenBSD: if_nx.c,v 1.30 2007/04/30 22:53:09 reyk Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org>
@@ -155,7 +155,7 @@ struct nx_softc {
int nxb_match(struct device *, void *, void *);
void nxb_attach(struct device *, struct device *, void *);
int nxb_query(struct nxb_softc *sc);
-int nxb_booted(struct nxb_softc *sc);
+int nxb_newstate(struct nxb_softc *, int);
void nxb_mountroot(void *);
int nxb_loadfirmware(struct nxb_softc *, struct nxb_firmware_header *,
u_int8_t **, size_t *);
@@ -505,31 +505,51 @@ nxb_query(struct nxb_softc *sc)
free(nu, M_TEMP);
/*
- * Initialize and bootstrap the device
- */
- nxb_write(sc, NXSW_CMD_PRODUCER_OFF, 0);
- nxb_write(sc, NXSW_CMD_CONSUMER_OFF, 0);
- nxb_write(sc, NXSW_CMD_ADDR_LO, 0);
-
- /*
* bootstrap the firmware, the status will be polled in the
* mountroot hook.
*/
- nxb_write(sc, NXROMUSB_GLB_PEGTUNE, NXROMUSB_GLB_PEGTUNE_DONE);
- sc->sc_state = NX_S_BOOTING;
+ nxb_newstate(sc, NX_S_BOOT);
return (0);
}
int
-nxb_booted(struct nxb_softc *sc)
+nxb_newstate(struct nxb_softc *sc, int newstate)
{
- if (nxb_wait(sc, NXSW_CMDPEG_STATE,
- NXSW_CMDPEG_INIT_DONE, NXSW_CMDPEG_STATE_M, 1, 2000000) != 0) {
- printf("%s: bootstrap failed, code 0x%x\n",
- sc->sc_dev.dv_xname, nxb_read(sc, NXSW_CMDPEG_STATE));
- return (-1);
+ int oldstate = sc->sc_state;
+
+ switch (newstate) {
+ case NX_S_BOOT:
+ /*
+ * Initialize and bootstrap the device
+ */
+ nxb_write(sc, NXSW_CMD_PRODUCER_OFF, 0);
+ nxb_write(sc, NXSW_CMD_CONSUMER_OFF, 0);
+ nxb_write(sc, NXSW_CMD_ADDR_LO, 0);
+ nxb_write(sc, NXROMUSB_GLB_PEGTUNE, NXROMUSB_GLB_PEGTUNE_DONE);
+ break;
+ case NX_S_LOADED:
+ /*
+ * Wait for the device to become ready
+ */
+ assert(oldstate == NX_S_BOOT);
+ if (nxb_wait(sc, NXSW_CMDPEG_STATE, NXSW_CMDPEG_INIT_DONE,
+ NXSW_CMDPEG_STATE_M, 1, 2000000) != 0) {
+ printf("%s: bootstrap failed, code 0x%x\n",
+ sc->sc_dev.dv_xname,
+ nxb_read(sc, NXSW_CMDPEG_STATE));
+ sc->sc_state = NX_S_FAIL;
+ return (-1);
+ }
+ break;
+ case NX_S_READY:
+ break;
+ default:
+ /* no action */
+ break;
}
+ sc->sc_state = newstate;
+
return (0);
}
@@ -538,12 +558,10 @@ nxb_mountroot(void *arg)
{
struct nxb_softc *sc = (struct nxb_softc *)arg;
- assert(sc->sc_state == NX_S_BOOTING);
-
/*
* Poll the status of the running firmware.
*/
- if (nxb_booted(sc) != 0)
+ if (nxb_newstate(sc, NX_S_LOADED) != 0)
return;
/*
@@ -568,7 +586,7 @@ nxb_mountroot(void *arg)
printf("\n");
/* Firmware is ready for operation, allow interrupts etc. */
- sc->sc_state = NX_S_READY;
+ nxb_newstate(sc, NX_S_READY);
}
int
@@ -738,17 +756,17 @@ nxb_reset(struct nxb_softc *sc)
/*
* bootstrap the newly loaded firmware and wait for completion
*/
- nxb_write(sc, NXROMUSB_GLB_PEGTUNE, NXROMUSB_GLB_PEGTUNE_DONE);
- if (nxb_booted(sc) != 0)
+ nxb_newstate(sc, NX_S_BOOT);
+ if (nxb_newstate(sc, NX_S_LOADED) != 0)
goto fail;
/* Firmware is ready for operation, allow interrupts etc. */
- sc->sc_state = NX_S_READY;
+ nxb_newstate(sc, NX_S_READY);
goto done;
fail1:
printf("%s: failed to reset firmware\n", sc->sc_dev.dv_xname);
fail:
- sc->sc_state = NX_S_FAIL;
+ nxb_newstate(sc, NX_S_FAIL);
done:
if (fw != NULL)
free(fw, M_DEVBUF);
diff --git a/sys/dev/pci/if_nxreg.h b/sys/dev/pci/if_nxreg.h
index b293b2248be..aff4f1809b2 100644
--- a/sys/dev/pci/if_nxreg.h
+++ b/sys/dev/pci/if_nxreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_nxreg.h,v 1.13 2007/04/30 21:22:56 reyk Exp $ */
+/* $OpenBSD: if_nxreg.h,v 1.14 2007/04/30 22:53:09 reyk Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@openbsd.org>
@@ -43,7 +43,8 @@
enum nx_state {
NX_S_FAIL = -1, /* Failed to initialize the device */
NX_S_OFFLINE = 0, /* Firmware is not active yet */
- NX_S_BOOTING = 1, /* Chipset is booting the firmware */
+ NX_S_BOOT = 1, /* Chipset is booting the firmware */
+ NX_S_LOADED = 2, /* Firmware is loaded but not initialized */
NX_S_READY = 3 /* Device has been initialized and is ready */
};
@@ -276,13 +277,20 @@ struct nx_statusdesc {
* Software defined registers (used by the firmware or the driver)
*/
-/* Lock ID registers */
+/* Chipset state registers */
#define NXSW_ROM_LOCK_ID NXSW(0x2100) /* Used for locking the ROM */
#define NXSW_ROM_LOCK_DRV 0x0d417340 /* Driver ROM lock ID */
#define NXSW_PHY_LOCK_ID NXSW(0x2120) /* Used for locking the PHY */
#define NXSW_PHY_LOCK_DRV 0x44524956 /* Driver PHY lock ID */
-
-/* Boot loader configuration */
+#define NXSW_TEMP NXSW(0x01b4) /* Temperature sensor */
+#define NXSW_TEMP_STATE_M 0x0000ffff /* Temp state mask */
+#define NXSW_TEMP_STATE_S 0 /* Temp state shift */
+#define NXSW_TEMP_STATE_NONE 0x0000 /* Temp state is UNSPEC */
+#define NXSW_TEMP_STATE_OK 0x0001 /* Temp state is OK */
+#define NXSW_TEMP_STATE_WARN 0x0002 /* Temp state is WARNING */
+#define NXSW_TEMP_STATE_CRIT 0x0003 /* Temp state is CRITICAL */
+#define NXSW_TEMP_VAL_M 0xffff0000 /* Temp deg celsius mask */
+#define NXSW_TEMP_VAL_S 16 /* Temp deg celsius shift */
#define NXSW_BOOTLD_CONFIG NXSW(0x01fc)
#define NXSW_BOOTLD_CONFIG_ROM 0x00000000 /* Load firmware from flasg */
#define NXSW_BOOTLD_CONFIG_RAM 0x12345678 /* Load firmware from memory */