Subject: Re: uhci0: host controller halted
To: None <>
From: Iain Hibbert <>
List: tech-kern
Date: 03/03/2006 21:33:25
On Thu, 26 Jan 2006, Iain Hibbert wrote:

>    Am getting the above message printed sometimes on system shutdown after
> I've been using a USB bluetooth device. Then the system just stops instead
> of rebooting or powering down or whatever.

Preliminary indications are, I think I found the problem.

After much searching, it seems that the shutdown hook in uhci.c is called,
which calls "uhci_run(sc, 0)" in order to shut down the uhci device. Alas,
uhci_run() calls usb_delay_ms() in a loop waiting for the shutdown which
optionally uses tsleep(usbdly) which causes a context switch but we are
never rescheduled as the system is being shut down.

So, when the system is being shutdown and it hangs, I enter DDB and find
that the reboot process is indeed lost in "wait usbdly" state.

I think the fix then is to not tsleep at this stage, uhci_power() does a
similar thing when shutting the HC down, by setting polling mode, and thus
the following patch works for me..  I dont know if the splhardusb() is
strictly necessary to protect the increment/decrement, but uhci_run() does
it almost right away anyway so it can't hurt.

I think the following PR's are most likely related.

is there an USB expert in the house?


--- /usr/src/sys/dev/usb/uhci.c	2006-01-17 10:23:15.000000000 +0000
+++ src/sys/dev/usb/uhci.c	2006-03-03 21:16:11.000000000 +0000
@@ -698,9 +698,19 @@
 uhci_shutdown(void *v)
 	uhci_softc_t *sc = v;
+	int s;

 	DPRINTF(("uhci_shutdown: stopping the HC\n"));
+	/*
+	 * use polling mode to prevent the interrupts shutting
+	 * us down before we shut them down
+	 */
+	s = splhardusb();
+	sc->sc_bus.use_polling++;
 	uhci_run(sc, 0); /* stop the controller */
+	sc->sc_bus.use_polling--;
+	splx(s);