summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/uhci.c
diff options
context:
space:
mode:
authoraaron <aaron@openbsd.org>2000-03-26 08:39:45 +0000
committeraaron <aaron@openbsd.org>2000-03-26 08:39:45 +0000
commiteff3e1aa6fc1b31383da181b5125bd29955f38f4 (patch)
tree339732deb0b865b5e3ea4d6d6932f1205e344cfb /sys/dev/usb/uhci.c
parentRegen. (diff)
downloadwireguard-openbsd-eff3e1aa6fc1b31383da181b5125bd29955f38f4.tar.xz
wireguard-openbsd-eff3e1aa6fc1b31383da181b5125bd29955f38f4.zip
Sync with NetBSD.
Diffstat (limited to 'sys/dev/usb/uhci.c')
-rw-r--r--sys/dev/usb/uhci.c1071
1 files changed, 642 insertions, 429 deletions
diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c
index a92739a62c5..14c9c56b562 100644
--- a/sys/dev/usb/uhci.c
+++ b/sys/dev/usb/uhci.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: uhci.c,v 1.6 1999/11/07 21:30:19 fgsch Exp $ */
-/* $NetBSD: uhci.c,v 1.62 1999/10/23 00:21:01 augustss Exp $ */
+/* $OpenBSD: uhci.c,v 1.7 2000/03/26 08:39:45 aaron Exp $ */
+/* $NetBSD: uhci.c,v 1.87 2000/02/29 21:37:01 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -42,10 +42,10 @@
* USB Universal Host Controller driver.
* Handles e.g. PIIX3 and PIIX4.
*
- * Data sheets: ftp://download.intel.com/design/intarch/datashts/29055002.pdf
- * ftp://download.intel.com/design/intarch/datashts/29056201.pdf
* UHCI spec: http://www.intel.com/design/usb/uhci11d.pdf
* USB spec: http://www.usb.org/developers/data/usb11.pdf
+ * PIIXn spec: ftp://download.intel.com/design/intarch/datashts/29055002.pdf
+ * ftp://download.intel.com/design/intarch/datashts/29056201.pdf
*/
#include <sys/param.h>
@@ -54,17 +54,18 @@
#include <sys/malloc.h>
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/device.h>
+#include <sys/select.h>
#elif defined(__FreeBSD__)
#include <sys/module.h>
#include <sys/bus.h>
+#include <machine/bus_pio.h>
+#if defined(DIAGNOSTIC) && defined(__i386)
+#include <machine/cpu.h>
+#endif
#endif
#include <sys/proc.h>
#include <sys/queue.h>
-#include <sys/select.h>
-#if defined(__FreeBSD__)
-#include <machine/bus_pio.h>
-#endif
#include <machine/bus.h>
#include <machine/endian.h>
@@ -91,10 +92,10 @@ struct cfdriver uhci_cd = {
};
#endif
-#ifdef USB_DEBUG
+#ifdef UHCI_DEBUG
#define DPRINTF(x) if (uhcidebug) printf x
#define DPRINTFN(n,x) if (uhcidebug>(n)) printf x
-extern int uhcidebug;
+int uhcidebug = 0;
#else
#define DPRINTF(x)
#define DPRINTFN(n,x)
@@ -149,6 +150,7 @@ struct uhci_pipe {
LIST_HEAD(, uhci_intr_info) uhci_ii_free;
void uhci_busreset __P((uhci_softc_t *));
+void uhci_shutdown __P((void *v));
void uhci_power __P((int, void *));
usbd_status uhci_run __P((uhci_softc_t *, int run));
uhci_soft_td_t *uhci_alloc_std __P((uhci_softc_t *));
@@ -166,15 +168,15 @@ void uhci_exit_ctl_q __P((uhci_softc_t *, uhci_soft_qh_t *));
void uhci_free_std_chain __P((uhci_softc_t *,
uhci_soft_td_t *, uhci_soft_td_t *));
usbd_status uhci_alloc_std_chain __P((struct uhci_pipe *, uhci_softc_t *,
- int, int, int, usb_dma_t *,
+ int, int, u_int16_t, usb_dma_t *,
uhci_soft_td_t **,
uhci_soft_td_t **));
void uhci_timo __P((void *));
-void uhci_waitintr __P((uhci_softc_t *, usbd_request_handle));
+void uhci_waitintr __P((uhci_softc_t *, usbd_xfer_handle));
void uhci_check_intr __P((uhci_softc_t *, uhci_intr_info_t *));
void uhci_idone __P((uhci_intr_info_t *));
-void uhci_abort_req __P((usbd_request_handle, usbd_status status));
-void uhci_abort_req_end __P((void *v));
+void uhci_abort_xfer __P((usbd_xfer_handle, usbd_status status));
+void uhci_abort_xfer_end __P((void *v));
void uhci_timeout __P((void *));
void uhci_wakeup_ctrl __P((void *, int, int, void *, int));
void uhci_lock_frames __P((uhci_softc_t *));
@@ -184,53 +186,59 @@ void uhci_add_bulk __P((uhci_softc_t *, uhci_soft_qh_t *));
void uhci_remove_ctrl __P((uhci_softc_t *, uhci_soft_qh_t *));
void uhci_remove_bulk __P((uhci_softc_t *, uhci_soft_qh_t *));
int uhci_str __P((usb_string_descriptor_t *, int, char *));
+
usbd_status uhci_setup_isoc __P((usbd_pipe_handle pipe));
-void uhci_device_isoc_enter __P((usbd_request_handle));
+void uhci_device_isoc_enter __P((usbd_xfer_handle));
-void uhci_wakeup_cb __P((usbd_request_handle reqh));
+void uhci_wakeup_cb __P((usbd_xfer_handle xfer));
usbd_status uhci_allocm __P((struct usbd_bus *, usb_dma_t *, u_int32_t));
void uhci_freem __P((struct usbd_bus *, usb_dma_t *));
-usbd_status uhci_device_ctrl_transfer __P((usbd_request_handle));
-usbd_status uhci_device_ctrl_start __P((usbd_request_handle));
-void uhci_device_ctrl_abort __P((usbd_request_handle));
+usbd_xfer_handle uhci_allocx __P((struct usbd_bus *));
+void uhci_freex __P((struct usbd_bus *, usbd_xfer_handle));
+
+usbd_status uhci_device_ctrl_transfer __P((usbd_xfer_handle));
+usbd_status uhci_device_ctrl_start __P((usbd_xfer_handle));
+void uhci_device_ctrl_abort __P((usbd_xfer_handle));
void uhci_device_ctrl_close __P((usbd_pipe_handle));
-void uhci_device_ctrl_done __P((usbd_request_handle));
+void uhci_device_ctrl_done __P((usbd_xfer_handle));
-usbd_status uhci_device_intr_transfer __P((usbd_request_handle));
-usbd_status uhci_device_intr_start __P((usbd_request_handle));
-void uhci_device_intr_abort __P((usbd_request_handle));
+usbd_status uhci_device_intr_transfer __P((usbd_xfer_handle));
+usbd_status uhci_device_intr_start __P((usbd_xfer_handle));
+void uhci_device_intr_abort __P((usbd_xfer_handle));
void uhci_device_intr_close __P((usbd_pipe_handle));
-void uhci_device_intr_done __P((usbd_request_handle));
+void uhci_device_intr_done __P((usbd_xfer_handle));
-usbd_status uhci_device_bulk_transfer __P((usbd_request_handle));
-usbd_status uhci_device_bulk_start __P((usbd_request_handle));
-void uhci_device_bulk_abort __P((usbd_request_handle));
+usbd_status uhci_device_bulk_transfer __P((usbd_xfer_handle));
+usbd_status uhci_device_bulk_start __P((usbd_xfer_handle));
+void uhci_device_bulk_abort __P((usbd_xfer_handle));
void uhci_device_bulk_close __P((usbd_pipe_handle));
-void uhci_device_bulk_done __P((usbd_request_handle));
+void uhci_device_bulk_done __P((usbd_xfer_handle));
-usbd_status uhci_device_isoc_transfer __P((usbd_request_handle));
-usbd_status uhci_device_isoc_start __P((usbd_request_handle));
-void uhci_device_isoc_abort __P((usbd_request_handle));
+usbd_status uhci_device_isoc_transfer __P((usbd_xfer_handle));
+usbd_status uhci_device_isoc_start __P((usbd_xfer_handle));
+void uhci_device_isoc_abort __P((usbd_xfer_handle));
void uhci_device_isoc_close __P((usbd_pipe_handle));
-void uhci_device_isoc_done __P((usbd_request_handle));
+void uhci_device_isoc_done __P((usbd_xfer_handle));
-usbd_status uhci_root_ctrl_transfer __P((usbd_request_handle));
-usbd_status uhci_root_ctrl_start __P((usbd_request_handle));
-void uhci_root_ctrl_abort __P((usbd_request_handle));
+usbd_status uhci_root_ctrl_transfer __P((usbd_xfer_handle));
+usbd_status uhci_root_ctrl_start __P((usbd_xfer_handle));
+void uhci_root_ctrl_abort __P((usbd_xfer_handle));
void uhci_root_ctrl_close __P((usbd_pipe_handle));
+void uhci_root_ctrl_done __P((usbd_xfer_handle));
-usbd_status uhci_root_intr_transfer __P((usbd_request_handle));
-usbd_status uhci_root_intr_start __P((usbd_request_handle));
-void uhci_root_intr_abort __P((usbd_request_handle));
+usbd_status uhci_root_intr_transfer __P((usbd_xfer_handle));
+usbd_status uhci_root_intr_start __P((usbd_xfer_handle));
+void uhci_root_intr_abort __P((usbd_xfer_handle));
void uhci_root_intr_close __P((usbd_pipe_handle));
-void uhci_root_intr_done __P((usbd_request_handle));
+void uhci_root_intr_done __P((usbd_xfer_handle));
usbd_status uhci_open __P((usbd_pipe_handle));
void uhci_poll __P((struct usbd_bus *));
+void uhci_softintr __P((struct usbd_bus *));
-usbd_status uhci_device_request __P((usbd_request_handle reqh));
+usbd_status uhci_device_request __P((usbd_xfer_handle xfer));
void uhci_add_intr __P((uhci_softc_t *, int, uhci_soft_qh_t *));
void uhci_remove_intr __P((uhci_softc_t *, int, uhci_soft_qh_t *));
@@ -242,12 +250,14 @@ void uhci_noop __P((usbd_pipe_handle pipe));
#ifdef UHCI_DEBUG
static void uhci_dumpregs __P((uhci_softc_t *));
-void uhci_dump_tds __P((uhci_soft_td_t *));
+void uhci_dump_qhs __P((uhci_soft_qh_t *));
void uhci_dump_qh __P((uhci_soft_qh_t *));
void uhci_dump __P((void));
+void uhci_dump_tds __P((uhci_soft_td_t *));
void uhci_dump_td __P((uhci_soft_td_t *));
#endif
+#define UWRITE1(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
#define UWRITE2(sc, r, x) bus_space_write_2((sc)->iot, (sc)->ioh, (r), (x))
#define UWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
#define UREAD1(sc, r) bus_space_read_1((sc)->iot, (sc)->ioh, (r))
@@ -265,9 +275,12 @@ void uhci_dump_td __P((uhci_soft_td_t *));
struct usbd_bus_methods uhci_bus_methods = {
uhci_open,
+ uhci_softintr,
uhci_poll,
uhci_allocm,
uhci_freem,
+ uhci_allocx,
+ uhci_freex,
};
struct usbd_pipe_methods uhci_root_ctrl_methods = {
@@ -276,7 +289,7 @@ struct usbd_pipe_methods uhci_root_ctrl_methods = {
uhci_root_ctrl_abort,
uhci_root_ctrl_close,
uhci_noop,
- 0,
+ uhci_root_ctrl_done,
};
struct usbd_pipe_methods uhci_root_intr_methods = {
@@ -337,14 +350,14 @@ usbd_status
uhci_init(sc)
uhci_softc_t *sc;
{
- usbd_status r;
+ usbd_status err;
int i, j;
uhci_soft_qh_t *csqh, *bsqh, *sqh;
uhci_soft_td_t *std;
DPRINTFN(1,("uhci_init: start\n"));
-#if defined(UHCI_DEBUG)
+#ifdef UHCI_DEBUG
if (uhcidebug > 2)
uhci_dumpregs(sc);
#endif
@@ -355,18 +368,18 @@ uhci_init(sc)
uhci_busreset(sc);
/* Allocate and initialize real frame array. */
- r = usb_allocmem(&sc->sc_bus,
+ err = usb_allocmem(&sc->sc_bus,
UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t),
UHCI_FRAMELIST_ALIGN, &sc->sc_dma);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ if (err)
+ return (err);
sc->sc_pframes = KERNADDR(&sc->sc_dma);
UWRITE2(sc, UHCI_FRNUM, 0); /* set frame number to 0 */
UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma)); /* set frame list*/
/* Allocate the dummy QH where bulk traffic will be queued. */
bsqh = uhci_alloc_sqh(sc);
- if (!bsqh)
+ if (bsqh == NULL)
return (USBD_NOMEM);
bsqh->qh.qh_hlink = LE(UHCI_PTR_T); /* end of QH chain */
bsqh->qh.qh_elink = LE(UHCI_PTR_T);
@@ -374,7 +387,7 @@ uhci_init(sc)
/* Allocate the dummy QH where control traffic will be queued. */
csqh = uhci_alloc_sqh(sc);
- if (!csqh)
+ if (csqh == NULL)
return (USBD_NOMEM);
csqh->hlink = bsqh;
csqh->qh.qh_hlink = LE(bsqh->physaddr | UHCI_PTR_Q);
@@ -389,7 +402,7 @@ uhci_init(sc)
for(i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
std = uhci_alloc_std(sc);
sqh = uhci_alloc_sqh(sc);
- if (!std || !sqh)
+ if (std == NULL || sqh == NULL)
return (USBD_NOMEM);
std->link.sqh = sqh;
std->td.td_link = LE(sqh->physaddr | UHCI_PTR_Q);
@@ -412,6 +425,8 @@ uhci_init(sc)
LIST_INIT(&sc->sc_intrhead);
+ SIMPLEQ_INIT(&sc->sc_free_xfers);
+
/* Set up the bus struct. */
sc->sc_bus.methods = &uhci_bus_methods;
sc->sc_bus.pipe_size = sizeof(struct uhci_pipe);
@@ -419,13 +434,18 @@ uhci_init(sc)
sc->sc_suspend = PWR_RESUME;
sc->sc_powerhook = powerhook_establish(uhci_power, sc);
+ sc->sc_shutdownhook = shutdownhook_establish(uhci_shutdown, sc);
+
DPRINTFN(1,("uhci_init: enabling\n"));
UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */
+ UHCICMD(sc, UHCI_CMD_MAXP); /* Assume 64 byte packets at frame end */
+
return (uhci_run(sc, 1)); /* and here we go... */
}
+#if defined(__NetBSD__) || defined(__OpenBSD__)
int
uhci_activate(self, act)
device_ptr_t self;
@@ -452,6 +472,7 @@ uhci_detach(sc, flags)
struct uhci_softc *sc;
int flags;
{
+ usbd_xfer_handle xfer;
int rv = 0;
if (sc->sc_child != NULL)
@@ -461,10 +482,22 @@ uhci_detach(sc, flags)
return (rv);
powerhook_disestablish(sc->sc_powerhook);
- /* free data structures XXX */
+ shutdownhook_disestablish(sc->sc_shutdownhook);
+
+ /* Free all xfers associated with this HC. */
+ for (;;) {
+ xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+ if (xfer == NULL)
+ break;
+ SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
+ free(xfer, M_USB);
+ }
+
+ /* XXX free other data structures XXX */
return (rv);
}
+#endif
usbd_status
uhci_allocm(bus, dma, size)
@@ -472,11 +505,8 @@ uhci_allocm(bus, dma, size)
usb_dma_t *dma;
u_int32_t size;
{
-#if defined(__NetBSD__) || defined(__OpenBSD__)
- struct uhci_softc *sc = (struct uhci_softc *)bus;
-#endif
-
- return (usb_allocmem(&sc->sc_bus, size, 0, dma));
+ return (usb_allocmem(&((struct uhci_softc *)bus)->sc_bus, size, 0,
+ dma));
}
void
@@ -484,14 +514,49 @@ uhci_freem(bus, dma)
struct usbd_bus *bus;
usb_dma_t *dma;
{
-#if defined(__NetBSD__) || defined(__OpenBSD__)
+ usb_freemem(&((struct uhci_softc *)bus)->sc_bus, dma);
+}
+
+usbd_xfer_handle
+uhci_allocx(bus)
+ struct usbd_bus *bus;
+{
struct uhci_softc *sc = (struct uhci_softc *)bus;
-#endif
+ usbd_xfer_handle xfer;
- usb_freemem(&sc->sc_bus, dma);
+ xfer = SIMPLEQ_FIRST(&sc->sc_free_xfers);
+ if (xfer != NULL)
+ SIMPLEQ_REMOVE_HEAD(&sc->sc_free_xfers, xfer, next);
+ else
+ xfer = malloc(sizeof(*xfer), M_USB, M_NOWAIT);
+ if (xfer != NULL)
+ memset(xfer, 0, sizeof *xfer);
+ return (xfer);
+}
+
+void
+uhci_freex(bus, xfer)
+ struct usbd_bus *bus;
+ usbd_xfer_handle xfer;
+{
+ struct uhci_softc *sc = (struct uhci_softc *)bus;
+
+ SIMPLEQ_INSERT_HEAD(&sc->sc_free_xfers, xfer, next);
+}
+
+/*
+ * Shut down the controller when the system is going down.
+ */
+void
+uhci_shutdown(v)
+ void *v;
+{
+ uhci_softc_t *sc = v;
+
+ DPRINTF(("uhci_shutdown: stopping the HC\n"));
+ uhci_run(sc, 0); /* stop the controller */
}
-#if defined(__NetBSD__) || defined(__OpenBSD__)
/*
* Handle suspend/resume.
*
@@ -515,26 +580,26 @@ uhci_power(why, v)
sc, why, sc->sc_suspend, cmd));
if (why != PWR_RESUME) {
-#if defined(UHCI_DEBUG)
+#ifdef UHCI_DEBUG
if (uhcidebug > 2)
uhci_dumpregs(sc);
#endif
- if (sc->sc_has_timo)
+ if (sc->sc_has_timo != NULL)
usb_untimeout(uhci_timo, sc->sc_has_timo,
sc->sc_has_timo->timo_handle);
sc->sc_bus.use_polling++;
uhci_run(sc, 0); /* stop the controller */
+
+ /* save some state if BIOS doesn't */
+ sc->sc_saved_frnum = UREAD2(sc, UHCI_FRNUM);
+ sc->sc_saved_sof = UREAD1(sc, UHCI_SOF);
+
UHCICMD(sc, cmd | UHCI_CMD_EGSM); /* enter global suspend */
usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
sc->sc_suspend = why;
sc->sc_bus.use_polling--;
DPRINTF(("uhci_power: cmd=0x%x\n", UREAD2(sc, UHCI_CMD)));
} else {
- /*
- * XXX We should really do much more here in case the
- * controller registers have been lost and BIOS has
- * not restored them.
- */
#ifdef DIAGNOSTIC
if (sc->sc_suspend == PWR_RESUME)
printf("uhci_power: weird, resume without suspend.\n");
@@ -543,6 +608,12 @@ uhci_power(why, v)
sc->sc_suspend = why;
if (cmd & UHCI_CMD_RS)
uhci_run(sc, 0); /* in case BIOS has started it */
+
+ /* restore saved state */
+ UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(&sc->sc_dma));
+ UWRITE2(sc, UHCI_FRNUM, sc->sc_saved_frnum);
+ UWRITE1(sc, UHCI_SOF, sc->sc_saved_sof);
+
UHCICMD(sc, cmd | UHCI_CMD_FGR); /* force global resume */
usb_delay_ms(&sc->sc_bus, USB_RESUME_DELAY);
UHCICMD(sc, cmd & ~UHCI_CMD_EGSM); /* back to normal */
@@ -551,17 +622,16 @@ uhci_power(why, v)
uhci_run(sc, 1); /* and start traffic again */
usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY);
sc->sc_bus.use_polling--;
- if (sc->sc_has_timo)
+ if (sc->sc_has_timo != NULL)
usb_timeout(uhci_timo, sc->sc_has_timo,
sc->sc_ival, sc->sc_has_timo->timo_handle);
-#if defined(UHCI_DEBUG)
+#ifdef UHCI_DEBUG
if (uhcidebug > 2)
uhci_dumpregs(sc);
#endif
}
splx(s);
}
-#endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
#ifdef UHCI_DEBUG
static void
@@ -609,14 +679,13 @@ uhci_dump_td(p)
}
void
-uhci_dump_qh(p)
- uhci_soft_qh_t *p;
+uhci_dump_qh(sqh)
+ uhci_soft_qh_t *sqh;
{
- DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", p,
- (int)p->physaddr, LE(p->qh.qh_hlink), LE(p->qh.qh_elink)));
+ DPRINTFN(-1,("QH(%p) at %08x: hlink=%08x elink=%08x\n", sqh,
+ (int)sqh->physaddr, LE(sqh->qh.qh_hlink), LE(sqh->qh.qh_elink)));
}
-
#if 0
void
uhci_dump()
@@ -631,13 +700,53 @@ uhci_dump()
#endif
void
+uhci_dump_qhs(sqh)
+ uhci_soft_qh_t *sqh;
+{
+ uhci_dump_qh(sqh);
+
+ /* uhci_dump_sqh displays all the QHs and TDs from the given QH onwards
+ * Traverses sideways first, then down.
+ *
+ * QH1
+ * QH2
+ * No QH
+ * TD2.1
+ * TD2.2
+ * TD1.1
+ * etc.
+ *
+ * TD2.x being the TDs queued at QH2 and QH1 being referenced from QH1.
+ */
+
+ if (sqh->hlink != NULL && !(sqh->qh.qh_hlink & UHCI_PTR_T))
+ uhci_dump_qhs(sqh->hlink);
+ else
+ DPRINTF(("No QH\n"));
+
+ if (sqh->elink != NULL && !(sqh->qh.qh_elink & UHCI_PTR_T))
+ uhci_dump_tds(sqh->elink);
+ else
+ DPRINTF(("No TD\n"));
+}
+
+void
uhci_dump_tds(std)
uhci_soft_td_t *std;
{
- uhci_soft_td_t *p;
+ uhci_soft_td_t *td;
+
+ for(td = std; td != NULL; td = td->link.std) {
+ uhci_dump_td(td);
- for(p = std; p; p = p->link.std)
- uhci_dump_td(p);
+ /* Check whether the link pointer in this TD marks
+ * the link pointer as end of queue. This avoids
+ * printing the free list in case the queue/TD has
+ * already been moved there (seatbelt).
+ */
+ if (td->td.td_link & UHCI_PTR_T || td->td.td_link == 0)
+ break;
+ }
}
#endif
@@ -649,17 +758,17 @@ void
uhci_timo(addr)
void *addr;
{
- usbd_request_handle reqh = addr;
- usbd_pipe_handle pipe = reqh->pipe;
+ usbd_xfer_handle xfer = addr;
+ usbd_pipe_handle pipe = xfer->pipe;
uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
int s;
u_char *p;
- DPRINTFN(15, ("uhci_timo\n"));
+ DPRINTFN(20, ("uhci_timo\n"));
- usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timo_handle);
+ usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
- p = KERNADDR(&reqh->dmabuf);
+ p = KERNADDR(&xfer->dmabuf);
p[0] = 0;
if (UREAD2(sc, UHCI_PORTSC1) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
p[0] |= 1<<1;
@@ -669,19 +778,25 @@ uhci_timo(addr)
/* No change, try again in a while */
return;
- reqh->actlen = 1;
- reqh->status = USBD_NORMAL_COMPLETION;
+ xfer->actlen = 1;
+ xfer->status = USBD_NORMAL_COMPLETION;
s = splusb();
- reqh->hcpriv = 0;
- reqh->device->bus->intr_context++;
- usb_transfer_complete(reqh);
- reqh->device->bus->intr_context--;
+ xfer->hcpriv = 0;
+ xfer->device->bus->intr_context++;
+ usb_transfer_complete(xfer);
+ xfer->device->bus->intr_context--;
splx(s);
}
void
-uhci_root_intr_done(reqh)
- usbd_request_handle reqh;
+uhci_root_intr_done(xfer)
+ usbd_xfer_handle xfer;
+{
+}
+
+void
+uhci_root_ctrl_done(xfer)
+ usbd_xfer_handle xfer;
{
}
@@ -691,7 +806,8 @@ uhci_lock_frames(sc)
uhci_softc_t *sc;
{
int s = splusb();
- while (sc->sc_vflock) {
+
+ while (sc->sc_vflock & UHCI_HAS_LOCK) {
sc->sc_vflock |= UHCI_WANT_LOCK;
tsleep(&sc->sc_vflock, PRIBIO, "uhcqhl", 0);
}
@@ -704,6 +820,7 @@ uhci_unlock_frames(sc)
uhci_softc_t *sc;
{
int s = splusb();
+
sc->sc_vflock &= ~UHCI_HAS_LOCK;
if (sc->sc_vflock & UHCI_WANT_LOCK)
wakeup(&sc->sc_vflock);
@@ -838,9 +955,8 @@ uhci_intr(arg)
uhci_softc_t *sc = arg;
int status;
int ack;
- uhci_intr_info_t *ii;
-#if defined(UHCI_DEBUG)
+#ifdef UHCI_DEBUG
if (uhcidebug > 15) {
DPRINTF(("%s: uhci_intr\n", USBDEVNAME(sc->sc_bus.bdev)));
uhci_dumpregs(sc);
@@ -867,17 +983,18 @@ uhci_intr(arg)
}
if (status & UHCI_STS_HSE) {
ack |= UHCI_STS_HSE;
- printf("%s: host controller process error\n",
- USBDEVNAME(sc->sc_bus.bdev));
+ printf("%s: host system error\n", USBDEVNAME(sc->sc_bus.bdev));
}
if (status & UHCI_STS_HCPE) {
ack |= UHCI_STS_HCPE;
- printf("%s: host system error\n", USBDEVNAME(sc->sc_bus.bdev));
+ printf("%s: host controller process error\n",
+ USBDEVNAME(sc->sc_bus.bdev));
}
if (status & UHCI_STS_HCH) {
/* no acknowledge needed */
printf("%s: host controller halted\n",
USBDEVNAME(sc->sc_bus.bdev));
+ sc->sc_dying = 1;
}
if (ack) /* acknowledge the ints */
@@ -885,8 +1002,24 @@ uhci_intr(arg)
else /* nothing to acknowledge */
return (0);
- sc->sc_bus.intr_context++;
sc->sc_bus.no_intrs++;
+ usb_schedsoftintr(&sc->sc_bus);
+
+ DPRINTFN(10, ("%s: uhci_intr: exit\n", USBDEVNAME(sc->sc_bus.bdev)));
+
+ return (1);
+}
+
+void
+uhci_softintr(bus)
+ struct usbd_bus *bus;
+{
+ uhci_softc_t *sc = (uhci_softc_t *)bus;
+ uhci_intr_info_t *ii;
+
+ DPRINTFN(10,("%s: uhci_softintr\n", USBDEVNAME(sc->sc_bus.bdev)));
+
+ sc->sc_bus.intr_context++;
/*
* Interrupts on UHCI really suck. When the host controller
@@ -902,11 +1035,7 @@ uhci_intr(arg)
for (ii = LIST_FIRST(&sc->sc_intrhead); ii; ii = LIST_NEXT(ii, list))
uhci_check_intr(sc, ii);
- DPRINTFN(10, ("uhci_intr: exit\n"));
-
sc->sc_bus.intr_context--;
-
- return (1);
}
/* Check for an interrupt. */
@@ -920,16 +1049,16 @@ uhci_check_intr(sc, ii)
DPRINTFN(15, ("uhci_check_intr: ii=%p\n", ii));
#ifdef DIAGNOSTIC
- if (!ii) {
+ if (ii == NULL) {
printf("uhci_check_intr: no ii? %p\n", ii);
return;
}
#endif
- if (!ii->stdstart)
+ if (ii->stdstart == NULL)
return;
lstd = ii->stdend;
#ifdef DIAGNOSTIC
- if (!lstd) {
+ if (lstd == NULL) {
printf("uhci_check_intr: std==0\n");
return;
}
@@ -943,9 +1072,16 @@ uhci_check_intr(sc, ii)
DPRINTFN(15, ("uhci_check_intr: active ii=%p\n", ii));
for (std = ii->stdstart; std != lstd; std = std->link.std) {
status = LE(std->td.td_status);
- if ((status & UHCI_TD_STALLED) ||
- (status & (UHCI_TD_SPD | UHCI_TD_ACTIVE)) ==
- UHCI_TD_SPD)
+ /* If there's an active TD the xfer isn't done. */
+ if (status & UHCI_TD_ACTIVE)
+ break;
+ /* Any kind of error makes the xfer done. */
+ if (status & UHCI_TD_STALLED)
+ goto done;
+ /* We want short packets, and it is short: it's done */
+ if ((status & UHCI_TD_SPD) &&
+ UHCI_TD_GET_ACTLEN(status) <
+ UHCI_TD_GET_MAXLEN(LE(std->td.td_token)))
goto done;
}
DPRINTFN(15, ("uhci_check_intr: ii=%p std=%p still active\n",
@@ -953,6 +1089,7 @@ uhci_check_intr(sc, ii)
return;
}
done:
+ DPRINTFN(15, ("uhci_check_intr: ii=%p done\n", ii));
usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
uhci_idone(ii);
}
@@ -962,10 +1099,10 @@ void
uhci_idone(ii)
uhci_intr_info_t *ii;
{
- usbd_request_handle reqh = ii->reqh;
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ usbd_xfer_handle xfer = ii->xfer;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
uhci_soft_td_t *std;
- u_int32_t status;
+ u_int32_t status = 0, nstatus;
int actlen;
#ifdef DIAGNOSTIC
@@ -981,22 +1118,22 @@ uhci_idone(ii)
}
#endif
- if (reqh->status == USBD_CANCELLED ||
- reqh->status == USBD_TIMEOUT) {
- DPRINTF(("uhci_idone: aborted reqh=%p\n", reqh));
+ if (xfer->status == USBD_CANCELLED ||
+ xfer->status == USBD_TIMEOUT) {
+ DPRINTF(("uhci_idone: aborted xfer=%p\n", xfer));
return;
}
- if (reqh->nframes) {
+ if (xfer->nframes != 0) {
/* Isoc transfer, do things differently. */
uhci_soft_td_t **stds = upipe->u.iso.stds;
int i, n, nframes;
DPRINTFN(5,("uhci_idone: ii=%p isoc ready\n", ii));
- nframes = reqh->nframes;
+ nframes = xfer->nframes;
actlen = 0;
- n = reqh->hcprivint;
+ n = xfer->hcprivint;
for (i = 0; i < nframes; i++) {
std = stds[n];
#ifdef UHCI_DEBUG
@@ -1011,15 +1148,16 @@ uhci_idone(ii)
actlen += UHCI_TD_GET_ACTLEN(status);
}
upipe->u.iso.inuse -= nframes;
- reqh->actlen = actlen;
- reqh->status = USBD_NORMAL_COMPLETION;
- reqh->hcpriv = ii;
- usb_transfer_complete(reqh);
+ xfer->actlen = actlen;
+ xfer->status = USBD_NORMAL_COMPLETION;
+ xfer->hcpriv = ii;
+ usb_transfer_complete(xfer);
return;
}
#ifdef UHCI_DEBUG
- DPRINTFN(10, ("uhci_idone: ii=%p ready\n", ii));
+ DPRINTFN(10, ("uhci_idone: ii=%p, xfer=%p, pipe=%p ready\n",
+ ii, xfer, upipe));
if (uhcidebug > 10)
uhci_dump_tds(ii->stdstart);
#endif
@@ -1027,40 +1165,41 @@ uhci_idone(ii)
/* The transfer is done, compute actual length and status. */
/* XXX Is this correct for control xfers? */
actlen = 0;
- for (std = ii->stdstart; std; std = std->link.std) {
- status = LE(std->td.td_status);
- if (status & UHCI_TD_ACTIVE)
+ for (std = ii->stdstart; std != NULL; std = std->link.std) {
+ nstatus = LE(std->td.td_status);
+ if (nstatus & UHCI_TD_ACTIVE)
break;
- if (UHCI_TD_GET_PID(LE(std->td.td_token)) !=
- UHCI_TD_PID_SETUP)
+
+ status = nstatus;
+ if (UHCI_TD_GET_PID(LE(std->td.td_token)) != UHCI_TD_PID_SETUP)
actlen += UHCI_TD_GET_ACTLEN(status);
}
/* If there are left over TDs we need to update the toggle. */
- if (std)
+ if (std != NULL)
upipe->nexttoggle = UHCI_TD_GET_DT(LE(std->td.td_token));
status &= UHCI_TD_ERROR;
DPRINTFN(10, ("uhci_check_intr: actlen=%d, status=0x%x\n",
actlen, status));
- reqh->actlen = actlen;
+ xfer->actlen = actlen;
if (status != 0) {
- DPRINTFN(-1+((status&UHCI_TD_STALLED)!=0),
+ DPRINTFN((status == UHCI_TD_STALLED)*10,
("uhci_idone: error, addr=%d, endpt=0x%02x, "
"status 0x%b\n",
- reqh->pipe->device->address,
- reqh->pipe->endpoint->edesc->bEndpointAddress,
+ xfer->pipe->device->address,
+ xfer->pipe->endpoint->edesc->bEndpointAddress,
(int)status,
"\20\22BITSTUFF\23CRCTO\24NAK\25BABBLE\26DBUFFER\27"
"STALLED\30ACTIVE"));
if (status == UHCI_TD_STALLED)
- reqh->status = USBD_STALLED;
+ xfer->status = USBD_STALLED;
else
- reqh->status = USBD_IOERROR; /* more info XXX */
+ xfer->status = USBD_IOERROR; /* more info XXX */
} else {
- reqh->status = USBD_NORMAL_COMPLETION;
+ xfer->status = USBD_NORMAL_COMPLETION;
}
- reqh->hcpriv = ii;
- usb_transfer_complete(reqh);
+ xfer->hcpriv = ii;
+ usb_transfer_complete(xfer);
}
/*
@@ -1074,9 +1213,14 @@ uhci_timeout(addr)
DPRINTF(("uhci_timeout: ii=%p\n", ii));
- ii->reqh->device->bus->intr_context++;
- uhci_abort_req(ii->reqh, USBD_TIMEOUT);
- ii->reqh->device->bus->intr_context--;
+#ifdef UHCI_DEBUG
+ if (uhcidebug > 10)
+ uhci_dump_tds(ii->stdstart);
+#endif
+
+ ii->xfer->device->bus->intr_context++;
+ uhci_abort_xfer(ii->xfer, USBD_TIMEOUT);
+ ii->xfer->device->bus->intr_context--;
}
/*
@@ -1086,22 +1230,22 @@ uhci_timeout(addr)
* Only used during boot when interrupts are not enabled yet.
*/
void
-uhci_waitintr(sc, reqh)
+uhci_waitintr(sc, xfer)
uhci_softc_t *sc;
- usbd_request_handle reqh;
+ usbd_xfer_handle xfer;
{
- int timo = reqh->timeout;
+ int timo = xfer->timeout;
uhci_intr_info_t *ii;
DPRINTFN(10,("uhci_waitintr: timeout = %dms\n", timo));
- reqh->status = USBD_IN_PROGRESS;
+ xfer->status = USBD_IN_PROGRESS;
for (; timo >= 0; timo--) {
usb_delay_ms(&sc->sc_bus, 1);
DPRINTFN(20,("uhci_waitintr: 0x%04x\n", UREAD2(sc, UHCI_STS)));
if (UREAD2(sc, UHCI_STS) & UHCI_STS_USBINT) {
uhci_intr(sc);
- if (reqh->status != USBD_IN_PROGRESS)
+ if (xfer->status != USBD_IN_PROGRESS)
return;
}
}
@@ -1109,11 +1253,11 @@ uhci_waitintr(sc, reqh)
/* Timeout */
DPRINTF(("uhci_waitintr: timeout\n"));
for (ii = LIST_FIRST(&sc->sc_intrhead);
- ii && ii->reqh != reqh;
+ ii != NULL && ii->xfer != xfer;
ii = LIST_NEXT(ii, list))
;
#ifdef DIAGNOSTIC
- if (!ii)
+ if (ii == NULL)
panic("uhci_waitintr: lost intr_info\n");
#endif
uhci_idone(ii);
@@ -1154,11 +1298,17 @@ uhci_run(sc, run)
int run;
{
int s, n, running;
+ u_int16_t cmd;
run = run != 0;
s = splusb();
DPRINTF(("uhci_run: setting run=%d\n", run));
- UHCICMD(sc, run ? UHCI_CMD_RS : 0);
+ cmd = UREAD2(sc, UHCI_CMD);
+ if (run)
+ cmd |= UHCI_CMD_RS;
+ else
+ cmd &= ~UHCI_CMD_RS;
+ UHCICMD(sc, cmd);
for(n = 0; n < 10; n++) {
running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH);
/* return when we've entered the state we want */
@@ -1191,15 +1341,15 @@ uhci_alloc_std(sc)
uhci_softc_t *sc;
{
uhci_soft_td_t *std;
- usbd_status r;
+ usbd_status err;
int i, offs;
usb_dma_t dma;
- if (!sc->sc_freetds) {
+ if (sc->sc_freetds == NULL) {
DPRINTFN(2,("uhci_alloc_std: allocating chunk\n"));
- r = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
+ err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
UHCI_TD_ALIGN, &dma);
- if (r != USBD_NORMAL_COMPLETION)
+ if (err)
return (0);
for(i = 0; i < UHCI_STD_CHUNK; i++) {
offs = i * UHCI_STD_SIZE;
@@ -1222,7 +1372,7 @@ uhci_free_std(sc, std)
{
#ifdef DIAGNOSTIC
#define TD_IS_FREE 0x12345678
- if (LE(std->td.td_token) == TD_IS_FREE) {
+ if (std->td.td_token == LE(TD_IS_FREE)) {
printf("uhci_free_std: freeing free TD %p\n", std);
return;
}
@@ -1237,15 +1387,15 @@ uhci_alloc_sqh(sc)
uhci_softc_t *sc;
{
uhci_soft_qh_t *sqh;
- usbd_status r;
+ usbd_status err;
int i, offs;
usb_dma_t dma;
- if (!sc->sc_freeqhs) {
+ if (sc->sc_freeqhs == NULL) {
DPRINTFN(2, ("uhci_alloc_sqh: allocating chunk\n"));
- r = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
+ err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
UHCI_QH_ALIGN, &dma);
- if (r != USBD_NORMAL_COMPLETION)
+ if (err)
return 0;
for(i = 0; i < UHCI_SQH_CHUNK; i++) {
offs = i * UHCI_SQH_SIZE;
@@ -1301,10 +1451,11 @@ uhci_free_std_chain(sc, std, stdend)
}
usbd_status
-uhci_alloc_std_chain(upipe, sc, len, rd, shortok, dma, sp, ep)
+uhci_alloc_std_chain(upipe, sc, len, rd, flags, dma, sp, ep)
struct uhci_pipe *upipe;
uhci_softc_t *sc;
- int len, rd, shortok;
+ int len, rd;
+ u_int16_t flags;
usb_dma_t *dma;
uhci_soft_td_t **sp, **ep;
{
@@ -1316,20 +1467,22 @@ uhci_alloc_std_chain(upipe, sc, len, rd, shortok, dma, sp, ep)
int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
DPRINTFN(8, ("uhci_alloc_std_chain: addr=%d endpt=%d len=%d ls=%d "
- "shortok=%d\n", addr, UE_GET_ADDR(endpt), len,
- upipe->pipe.device->lowspeed, shortok));
- if (len == 0) {
- *sp = *ep = 0;
- DPRINTFN(-1,("uhci_alloc_std_chain: len=0\n"));
- return (USBD_NORMAL_COMPLETION);
- }
+ "flags=0x%x\n", addr, UE_GET_ADDR(endpt), len,
+ upipe->pipe.device->lowspeed, flags));
maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize);
if (maxp == 0) {
printf("uhci_alloc_std_chain: maxp=0\n");
return (USBD_INVAL);
}
ntd = (len + maxp - 1) / maxp;
+ if ((flags & USBD_FORCE_SHORT_XFER) && len % maxp == 0)
+ ntd++;
DPRINTFN(10, ("uhci_alloc_std_chain: maxp=%d ntd=%d\n", maxp, ntd));
+ if (ntd == 0) {
+ *sp = *ep = 0;
+ DPRINTFN(-1,("uhci_alloc_std_chain: ntd=0\n"));
+ return (USBD_NORMAL_COMPLETION);
+ }
tog = upipe->nexttoggle;
if (ntd % 2 == 0)
tog ^= 1;
@@ -1340,23 +1493,27 @@ uhci_alloc_std_chain(upipe, sc, len, rd, shortok, dma, sp, ep)
status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(3) | UHCI_TD_ACTIVE);
if (upipe->pipe.device->lowspeed)
status |= UHCI_TD_LS;
- if (shortok)
+ if (flags & USBD_SHORT_XFER_OK)
status |= UHCI_TD_SPD;
for (i = ntd; i >= 0; i--) {
p = uhci_alloc_std(sc);
- if (!p) {
+ if (p == NULL) {
uhci_free_std_chain(sc, lastp, 0);
return (USBD_NOMEM);
}
p->link.std = lastp;
- p->td.td_link = LE(lastlink);
+ if (lastlink == UHCI_PTR_T)
+ p->td.td_link = LE(lastlink);
+ else
+ p->td.td_link = LE(lastlink|UHCI_PTR_VF);
lastp = p;
lastlink = p->physaddr;
p->td.td_status = LE(status);
if (i == ntd) {
/* last TD */
l = len % maxp;
- if (l == 0) l = maxp;
+ if (l == 0 && !(flags & USBD_FORCE_SHORT_XFER))
+ l = maxp;
*ep = p;
} else
l = maxp;
@@ -1387,55 +1544,59 @@ uhci_noop(pipe)
}
usbd_status
-uhci_device_bulk_transfer(reqh)
- usbd_request_handle reqh;
+uhci_device_bulk_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
/* Insert last in queue. */
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- /* Pipe isn't running, start first */
- return (uhci_device_bulk_start(SIMPLEQ_FIRST(&reqh->pipe->queue)));
+ /* Pipe isn't running (otherwise err would be USBD_INPROG),
+ * start first
+ */
+ return (uhci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
usbd_status
-uhci_device_bulk_start(reqh)
- usbd_request_handle reqh;
+uhci_device_bulk_start(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
uhci_intr_info_t *ii = upipe->iinfo;
uhci_soft_td_t *data, *dataend;
uhci_soft_qh_t *sqh;
- usbd_status r;
+ usbd_status err;
int len, isread, endpt;
int s;
- DPRINTFN(3, ("uhci_device_bulk_transfer: reqh=%p len=%d flags=%d\n",
- reqh, reqh->length, reqh->flags));
+ DPRINTFN(3, ("uhci_device_bulk_transfer: xfer=%p len=%d flags=%d\n",
+ xfer, xfer->length, xfer->flags));
+
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
#ifdef DIAGNOSTIC
- if (reqh->rqflags & URQ_REQUEST)
+ if (xfer->rqflags & URQ_REQUEST)
panic("uhci_device_bulk_transfer: a request\n");
#endif
- len = reqh->length;
- endpt = reqh->pipe->endpoint->edesc->bEndpointAddress;
+ len = xfer->length;
+ endpt = xfer->pipe->endpoint->edesc->bEndpointAddress;
isread = UE_GET_DIR(endpt) == UE_DIR_IN;
sqh = upipe->u.bulk.sqh;
upipe->u.bulk.isread = isread;
upipe->u.bulk.length = len;
- r = uhci_alloc_std_chain(upipe, sc, len, isread,
- reqh->flags & USBD_SHORT_XFER_OK,
- &reqh->dmabuf, &data, &dataend);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
+ &xfer->dmabuf, &data, &dataend);
+ if (err)
+ return (err);
dataend->td.td_status |= LE(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
@@ -1446,13 +1607,16 @@ uhci_device_bulk_start(reqh)
#endif
/* Set up interrupt info. */
- ii->reqh = reqh;
+ ii->xfer = xfer;
ii->stdstart = data;
ii->stdend = dataend;
#if defined(__FreeBSD__)
callout_handle_init(&ii->timeout_handle);
#endif
#ifdef DIAGNOSTIC
+ if (!ii->isdone) {
+ printf("uhci_device_bulk_transfer: not done, ii=%p\n", ii);
+ }
ii->isdone = 0;
#endif
@@ -1464,8 +1628,8 @@ uhci_device_bulk_start(reqh)
uhci_add_bulk(sc, sqh);
LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
- if (reqh->timeout && !sc->sc_bus.use_polling) {
- usb_timeout(uhci_timeout, ii, MS_TO_TICKS(reqh->timeout),
+ if (xfer->timeout && !sc->sc_bus.use_polling) {
+ usb_timeout(uhci_timeout, ii, MS_TO_TICKS(xfer->timeout),
ii->timeout_handle);
}
splx(s);
@@ -1478,31 +1642,33 @@ uhci_device_bulk_start(reqh)
#endif
if (sc->sc_bus.use_polling)
- uhci_waitintr(sc, reqh);
+ uhci_waitintr(sc, xfer);
return (USBD_IN_PROGRESS);
}
/* Abort a device bulk request. */
void
-uhci_device_bulk_abort(reqh)
- usbd_request_handle reqh;
+uhci_device_bulk_abort(xfer)
+ usbd_xfer_handle xfer;
{
DPRINTF(("uhci_device_bulk_abort:\n"));
- uhci_abort_req(reqh, USBD_CANCELLED);
+ uhci_abort_xfer(xfer, USBD_CANCELLED);
}
void
-uhci_abort_req(reqh, status)
- usbd_request_handle reqh;
+uhci_abort_xfer(xfer, status)
+ usbd_xfer_handle xfer;
usbd_status status;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
uhci_intr_info_t *ii = upipe->iinfo;
uhci_soft_td_t *std;
+ DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status));
+
/* Make interrupt routine ignore it, */
- reqh->status = status;
+ xfer->status = status;
/* don't timeout, */
usb_untimeout(uhci_timeout, ii, ii->timeout_handle);
@@ -1511,28 +1677,37 @@ uhci_abort_req(reqh, status)
for (std = ii->stdstart; std != 0; std = std->link.std)
std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
- reqh->hcpriv = ii;
+ xfer->hcpriv = ii;
- /* make sure hardware has completed, */
- if (reqh->device->bus->intr_context) {
+#if 1
+ /* Make sure hardware has completed, */
+ if (xfer->device->bus->intr_context) {
/* We have no process context, so we can't use tsleep(). */
- timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+ timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
} else {
- usb_delay_ms(reqh->pipe->device->bus, 1);
+#if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__)
+ KASSERT(intr_nesting_level == 0,
+ ("ohci_abort_req in interrupt context"));
+#endif
+ usb_delay_ms(xfer->pipe->device->bus, 1);
/* and call final part of interrupt handler. */
- uhci_abort_req_end(reqh);
+ uhci_abort_xfer_end(xfer);
}
+#else
+ delay(1000);
+ uhci_abort_xfer_end(xfer);
+#endif
}
void
-uhci_abort_req_end(v)
+uhci_abort_xfer_end(v)
void *v;
{
- usbd_request_handle reqh = v;
+ usbd_xfer_handle xfer = v;
int s;
s = splusb();
- usb_transfer_complete(reqh);
+ usb_transfer_complete(xfer);
splx(s);
}
@@ -1547,86 +1722,95 @@ uhci_device_bulk_close(pipe)
uhci_free_sqh(sc, upipe->u.bulk.sqh);
uhci_free_intr_info(upipe->iinfo);
- /* XXX free other resources */
+ /* XXX free other resources? */
}
usbd_status
-uhci_device_ctrl_transfer(reqh)
- usbd_request_handle reqh;
+uhci_device_ctrl_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
/* Insert last in queue. */
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- /* Pipe isn't running, start first */
- return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&reqh->pipe->queue)));
+ /* Pipe isn't running (otherwise err would be USBD_INPROG),
+ * start first
+ */
+ return (uhci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
usbd_status
-uhci_device_ctrl_start(reqh)
- usbd_request_handle reqh;
+uhci_device_ctrl_start(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_softc_t *sc = (uhci_softc_t *)reqh->pipe->device->bus;
- usbd_status r;
+ uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
+ usbd_status err;
+
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST))
+ if (!(xfer->rqflags & URQ_REQUEST))
panic("uhci_device_ctrl_transfer: not a request\n");
#endif
- r = uhci_device_request(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = uhci_device_request(xfer);
+ if (err)
+ return (err);
if (sc->sc_bus.use_polling)
- uhci_waitintr(sc, reqh);
+ uhci_waitintr(sc, xfer);
return (USBD_IN_PROGRESS);
}
usbd_status
-uhci_device_intr_transfer(reqh)
- usbd_request_handle reqh;
+uhci_device_intr_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
/* Insert last in queue. */
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- /* Pipe isn't running, start first */
- return (uhci_device_intr_start(SIMPLEQ_FIRST(&reqh->pipe->queue)));
+ /* Pipe isn't running (otherwise err would be USBD_INPROG),
+ * start first
+ */
+ return (uhci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
usbd_status
-uhci_device_intr_start(reqh)
- usbd_request_handle reqh;
+uhci_device_intr_start(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
uhci_intr_info_t *ii = upipe->iinfo;
uhci_soft_td_t *data, *dataend;
uhci_soft_qh_t *sqh;
- usbd_status r;
+ usbd_status err;
int i, s;
- DPRINTFN(3,("uhci_device_intr_transfer: reqh=%p len=%d flags=%d\n",
- reqh, reqh->length, reqh->flags));
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
+
+ DPRINTFN(3,("uhci_device_intr_transfer: xfer=%p len=%d flags=%d\n",
+ xfer, xfer->length, xfer->flags));
#ifdef DIAGNOSTIC
- if (reqh->rqflags & URQ_REQUEST)
+ if (xfer->rqflags & URQ_REQUEST)
panic("uhci_device_intr_transfer: a request\n");
#endif
- r = uhci_alloc_std_chain(upipe, sc, reqh->length, 1,
- reqh->flags & USBD_SHORT_XFER_OK,
- &reqh->dmabuf, &data, &dataend);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
+ &xfer->dmabuf, &data, &dataend);
+ if (err)
+ return (err);
dataend->td.td_status |= LE(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
@@ -1639,13 +1823,16 @@ uhci_device_intr_start(reqh)
s = splusb();
/* Set up interrupt info. */
- ii->reqh = reqh;
+ ii->xfer = xfer;
ii->stdstart = data;
ii->stdend = dataend;
#if defined(__FreeBSD__)
callout_handle_init(&ii->timeout_handle);
#endif
#ifdef DIAGNOSTIC
+ if (!ii->isdone) {
+ printf("uhci_device_intr_transfer: not done, ii=%p\n", ii);
+ }
ii->isdone = 0;
#endif
@@ -1671,11 +1858,11 @@ uhci_device_intr_start(reqh)
/* Abort a device control request. */
void
-uhci_device_ctrl_abort(reqh)
- usbd_request_handle reqh;
+uhci_device_ctrl_abort(xfer)
+ usbd_xfer_handle xfer;
{
DPRINTF(("uhci_device_ctrl_abort:\n"));
- uhci_abort_req(reqh, USBD_CANCELLED);
+ uhci_abort_xfer(xfer, USBD_CANCELLED);
}
/* Close a device control pipe. */
@@ -1691,15 +1878,15 @@ uhci_device_ctrl_close(pipe)
/* Abort a device interrupt request. */
void
-uhci_device_intr_abort(reqh)
- usbd_request_handle reqh;
+uhci_device_intr_abort(xfer)
+ usbd_xfer_handle xfer;
{
- DPRINTFN(1,("uhci_device_intr_abort: reqh=%p\n", reqh));
- if (reqh->pipe->intrreqh == reqh) {
+ DPRINTFN(1,("uhci_device_intr_abort: xfer=%p\n", xfer));
+ if (xfer->pipe->intrxfer == xfer) {
DPRINTFN(1,("uhci_device_intr_abort: remove\n"));
- reqh->pipe->intrreqh = 0;
+ xfer->pipe->intrxfer = 0;
}
- uhci_abort_req(reqh, USBD_CANCELLED);
+ uhci_abort_xfer(xfer, USBD_CANCELLED);
}
/* Close a device interrupt pipe. */
@@ -1740,11 +1927,11 @@ uhci_device_intr_close(pipe)
}
usbd_status
-uhci_device_request(reqh)
- usbd_request_handle reqh;
+uhci_device_request(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
- usb_device_request_t *req = &reqh->request;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
+ usb_device_request_t *req = &xfer->request;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
int addr = dev->address;
@@ -1754,7 +1941,7 @@ uhci_device_request(reqh)
uhci_soft_qh_t *sqh;
int len;
u_int32_t ls;
- usbd_status r;
+ usbd_status err;
int isread;
int s;
@@ -1775,14 +1962,13 @@ uhci_device_request(reqh)
/* Set up data transaction */
if (len != 0) {
upipe->nexttoggle = 1;
- r = uhci_alloc_std_chain(upipe, sc, len, isread,
- reqh->flags & USBD_SHORT_XFER_OK,
- &reqh->dmabuf, &data, &dataend);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = uhci_alloc_std_chain(upipe, sc, len, isread, xfer->flags,
+ &xfer->dmabuf, &data, &dataend);
+ if (err)
+ return (err);
next = data;
dataend->link.std = stat;
- dataend->td.td_link = LE(stat->physaddr);
+ dataend->td.td_link = LE(stat->physaddr | UHCI_PTR_VF);
} else {
next = stat;
}
@@ -1791,7 +1977,7 @@ uhci_device_request(reqh)
memcpy(KERNADDR(&upipe->u.ctl.reqdma), req, sizeof *req);
setup->link.std = next;
- setup->td.td_link = LE(next->physaddr);
+ setup->td.td_link = LE(next->physaddr | UHCI_PTR_VF);
setup->td.td_status = LE(UHCI_TD_SET_ERRCNT(3) | ls | UHCI_TD_ACTIVE);
setup->td.td_token = LE(UHCI_TD_SETUP(sizeof *req, endpt, addr));
setup->td.td_buffer = LE(DMAADDR(&upipe->u.ctl.reqdma));
@@ -1806,20 +1992,23 @@ uhci_device_request(reqh)
stat->td.td_buffer = LE(0);
#ifdef UHCI_DEBUG
- if (uhcidebug > 20) {
+ if (uhcidebug > 10) {
DPRINTF(("uhci_device_request: before transfer\n"));
uhci_dump_tds(setup);
}
#endif
/* Set up interrupt info. */
- ii->reqh = reqh;
+ ii->xfer = xfer;
ii->stdstart = setup;
ii->stdend = stat;
#if defined(__FreeBSD__)
callout_handle_init(&ii->timeout_handle);
#endif
#ifdef DIAGNOSTIC
+ if (!ii->isdone) {
+ printf("uhci_device_request: not done, ii=%p\n", ii);
+ }
ii->isdone = 0;
#endif
@@ -1844,21 +2033,22 @@ uhci_device_request(reqh)
link = LE(std->td.td_link);
uhci_dump_td(std);
}
- for (sxqh = xqh = (uhci_soft_qh_t *)std;
- xqh;
+ sxqh = (uhci_soft_qh_t *)std;
+ uhci_dump_qh(sxqh);
+ for (xqh = sxqh;
+ xqh != NULL;
xqh = (maxqh++ == 5 || xqh->hlink==sxqh ||
xqh->hlink==xqh ? NULL : xqh->hlink)) {
uhci_dump_qh(xqh);
- uhci_dump_qh(sxqh);
}
DPRINTF(("Enqueued QH:\n"));
uhci_dump_qh(sqh);
uhci_dump_tds(sqh->elink);
}
#endif
- if (reqh->timeout && !sc->sc_bus.use_polling) {
+ if (xfer->timeout && !sc->sc_bus.use_polling) {
usb_timeout(uhci_timeout, ii,
- MS_TO_TICKS(reqh->timeout), ii->timeout_handle);
+ MS_TO_TICKS(xfer->timeout), ii->timeout_handle);
}
splx(s);
@@ -1866,37 +2056,37 @@ uhci_device_request(reqh)
}
usbd_status
-uhci_device_isoc_transfer(reqh)
- usbd_request_handle reqh;
+uhci_device_isoc_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
- DPRINTFN(5,("uhci_device_isoc_transfer: reqh=%p\n", reqh));
+ DPRINTFN(5,("uhci_device_isoc_transfer: xfer=%p\n", xfer));
/* Put it on our queue, */
- r = usb_insert_transfer(reqh);
+ err = usb_insert_transfer(xfer);
/* bail out on error, */
- if (r != USBD_NORMAL_COMPLETION && r != USBD_IN_PROGRESS)
- return (r);
+ if (err && err != USBD_IN_PROGRESS)
+ return (err);
/* XXX should check inuse here */
/* insert into schedule, */
- uhci_device_isoc_enter(reqh);
+ uhci_device_isoc_enter(xfer);
/* and put on interrupt list if the pipe wasn't running */
- if (r == USBD_NORMAL_COMPLETION)
- uhci_device_isoc_start(SIMPLEQ_FIRST(&reqh->pipe->queue));
+ if (!err)
+ uhci_device_isoc_start(SIMPLEQ_FIRST(&xfer->pipe->queue));
- return (r);
+ return (err);
}
void
-uhci_device_isoc_enter(reqh)
- usbd_request_handle reqh;
+uhci_device_isoc_enter(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
struct iso *iso = &upipe->u.iso;
@@ -1904,12 +2094,16 @@ uhci_device_isoc_enter(reqh)
u_int32_t buf, len, status;
int s, i, next, nframes;
- DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d reqh=%p "
+ DPRINTFN(5,("uhci_device_isoc_enter: used=%d next=%d xfer=%p "
"nframes=%d\n",
- iso->inuse, iso->next, reqh, reqh->nframes));
+ iso->inuse, iso->next, xfer, xfer->nframes));
+
+ if (sc->sc_dying)
+ return;
- if (reqh->status == USBD_IN_PROGRESS) {
+ if (xfer->status == USBD_IN_PROGRESS) {
/* This request has already been entered into the frame list */
+ /* XXX */
}
#ifdef DIAGNOSTIC
@@ -1924,20 +2118,20 @@ uhci_device_isoc_enter(reqh)
DPRINTFN(2,("uhci_device_isoc_enter: start next=%d\n", next));
}
- reqh->status = USBD_IN_PROGRESS;
- reqh->hcprivint = next;
+ xfer->status = USBD_IN_PROGRESS;
+ xfer->hcprivint = next;
- buf = DMAADDR(&reqh->dmabuf);
+ buf = DMAADDR(&xfer->dmabuf);
status = LE(UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) |
UHCI_TD_ACTIVE |
UHCI_TD_IOS));
- nframes = reqh->nframes;
+ nframes = xfer->nframes;
s = splusb();
for (i = 0; i < nframes; i++) {
std = iso->stds[next];
if (++next >= UHCI_VFRAMELIST_COUNT)
next = 0;
- len = reqh->frlengths[i];
+ len = xfer->frlengths[i];
std->td.td_buffer = LE(buf);
if (i == nframes - 1)
status |= LE(UHCI_TD_IOC);
@@ -1953,28 +2147,31 @@ uhci_device_isoc_enter(reqh)
buf += len;
}
iso->next = next;
- iso->inuse += reqh->nframes;
+ iso->inuse += xfer->nframes;
splx(s);
}
usbd_status
-uhci_device_isoc_start(reqh)
- usbd_request_handle reqh;
+uhci_device_isoc_start(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
uhci_softc_t *sc = (uhci_softc_t *)upipe->pipe.device->bus;
uhci_intr_info_t *ii = upipe->iinfo;
uhci_soft_td_t *end;
int s, i;
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
+
#ifdef DIAGNOSTIC
- if (reqh->status != USBD_IN_PROGRESS)
- printf("uhci_device_isoc_start: not in progress %p\n", reqh);
+ if (xfer->status != USBD_IN_PROGRESS)
+ printf("uhci_device_isoc_start: not in progress %p\n", xfer);
#endif
/* Find the last TD */
- i = reqh->hcprivint + reqh->nframes;
+ i = xfer->hcprivint + xfer->nframes;
if (i >= UHCI_VFRAMELIST_COUNT)
i -= UHCI_VFRAMELIST_COUNT;
end = upipe->u.iso.stds[i];
@@ -1982,13 +2179,16 @@ uhci_device_isoc_start(reqh)
s = splusb();
/* Set up interrupt info. */
- ii->reqh = reqh;
+ ii->xfer = xfer;
ii->stdstart = end;
ii->stdend = end;
#if defined(__FreeBSD__)
callout_handle_init(&ii->timeout_handle);
#endif
#ifdef DIAGNOSTIC
+ if (!ii->isdone) {
+ printf("uhci_device_isoc_start: not done, ii=%p\n", ii);
+ }
ii->isdone = 0;
#endif
LIST_INSERT_HEAD(&sc->sc_intrhead, ii, list);
@@ -1999,21 +2199,21 @@ uhci_device_isoc_start(reqh)
}
void
-uhci_device_isoc_abort(reqh)
- usbd_request_handle reqh;
+uhci_device_isoc_abort(xfer)
+ usbd_xfer_handle xfer;
{
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
uhci_intr_info_t *ii = upipe->iinfo;
uhci_soft_td_t **stds = upipe->u.iso.stds;
uhci_soft_td_t *std;
int i, n, nframes;
/* Make interrupt routine ignore it, */
- reqh->status = USBD_CANCELLED;
+ xfer->status = USBD_CANCELLED;
/* make hardware ignore it, */
- nframes = reqh->nframes;
- n = reqh->hcprivint;
+ nframes = xfer->nframes;
+ n = xfer->hcprivint;
for (i = 0; i < nframes; i++) {
std = stds[n];
std->td.td_status &= LE(~(UHCI_TD_ACTIVE | UHCI_TD_IOC));
@@ -2021,16 +2221,16 @@ uhci_device_isoc_abort(reqh)
n = 0;
}
- reqh->hcpriv = ii;
+ xfer->hcpriv = ii;
/* make sure hardware has completed, */
- if (reqh->device->bus->intr_context) {
+ if (xfer->device->bus->intr_context) {
/* We have no process context, so we can't use tsleep(). */
- timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+ timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
} else {
- usb_delay_ms(reqh->pipe->device->bus, 1);
+ usb_delay_ms(xfer->pipe->device->bus, 1);
/* and call final part of interrupt handler. */
- uhci_abort_req_end(reqh);
+ uhci_abort_xfer_end(xfer);
}
}
@@ -2061,10 +2261,10 @@ uhci_device_isoc_close(pipe)
for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
std = iso->stds[i];
for (vstd = sc->sc_vframes[i].htd;
- vstd && vstd->link.std != std;
+ vstd != NULL && vstd->link.std != std;
vstd = vstd->link.std)
;
- if (!vstd) {
+ if (vstd == NULL) {
/*panic*/
printf("uhci_device_isoc_close: %p not found\n", std);
uhci_unlock_frames(sc);
@@ -2136,12 +2336,12 @@ uhci_setup_isoc(pipe)
}
void
-uhci_device_isoc_done(reqh)
- usbd_request_handle reqh;
+uhci_device_isoc_done(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_intr_info_t *ii = reqh->hcpriv;
+ uhci_intr_info_t *ii = xfer->hcpriv;
- DPRINTFN(4, ("uhci_isoc_done: length=%d\n", reqh->actlen));
+ DPRINTFN(4, ("uhci_isoc_done: length=%d\n", xfer->actlen));
/* Turn off the interrupt since it is active even if the TD is not. */
ii->stdend->td.td_status &= LE(~UHCI_TD_IOC);
@@ -2150,16 +2350,16 @@ uhci_device_isoc_done(reqh)
}
void
-uhci_device_intr_done(reqh)
- usbd_request_handle reqh;
+uhci_device_intr_done(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_intr_info_t *ii = reqh->hcpriv;
+ uhci_intr_info_t *ii = xfer->hcpriv;
uhci_softc_t *sc = ii->sc;
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
uhci_soft_qh_t *sqh;
int i, npoll;
- DPRINTFN(5, ("uhci_intr_done: length=%d\n", reqh->actlen));
+ DPRINTFN(5, ("uhci_intr_done: length=%d\n", xfer->actlen));
npoll = upipe->u.intr.npoll;
for(i = 0; i < npoll; i++) {
@@ -2170,13 +2370,12 @@ uhci_device_intr_done(reqh)
uhci_free_std_chain(sc, ii->stdstart, 0);
/* XXX Wasteful. */
- if (reqh->pipe->repeat) {
+ if (xfer->pipe->repeat) {
uhci_soft_td_t *data, *dataend;
/* This alloc cannot fail since we freed the chain above. */
- uhci_alloc_std_chain(upipe, sc, reqh->length, 1,
- reqh->flags & USBD_SHORT_XFER_OK,
- &reqh->dmabuf, &data, &dataend);
+ uhci_alloc_std_chain(upipe, sc, xfer->length, 1, xfer->flags,
+ &xfer->dmabuf, &data, &dataend);
dataend->td.td_status |= LE(UHCI_TD_IOC);
#ifdef UHCI_DEBUG
@@ -2193,6 +2392,9 @@ uhci_device_intr_done(reqh)
callout_handle_init(&ii->timeout_handle);
#endif
#ifdef DIAGNOSTIC
+ if (!ii->isdone) {
+ printf("uhci_device_intr_done: not done, ii=%p\n", ii);
+ }
ii->isdone = 0;
#endif
for (i = 0; i < npoll; i++) {
@@ -2207,15 +2409,15 @@ uhci_device_intr_done(reqh)
/* Deallocate request data structures */
void
-uhci_device_ctrl_done(reqh)
- usbd_request_handle reqh;
+uhci_device_ctrl_done(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_intr_info_t *ii = reqh->hcpriv;
+ uhci_intr_info_t *ii = xfer->hcpriv;
uhci_softc_t *sc = ii->sc;
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST))
+ if (!(xfer->rqflags & URQ_REQUEST))
panic("uhci_ctrl_done: not a request\n");
#endif
@@ -2226,17 +2428,17 @@ uhci_device_ctrl_done(reqh)
if (upipe->u.ctl.length != 0)
uhci_free_std_chain(sc, ii->stdstart->link.std, ii->stdend);
- DPRINTFN(5, ("uhci_ctrl_done: length=%d\n", reqh->actlen));
+ DPRINTFN(5, ("uhci_ctrl_done: length=%d\n", xfer->actlen));
}
/* Deallocate request data structures */
void
-uhci_device_bulk_done(reqh)
- usbd_request_handle reqh;
+uhci_device_bulk_done(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_intr_info_t *ii = reqh->hcpriv;
+ uhci_intr_info_t *ii = xfer->hcpriv;
uhci_softc_t *sc = ii->sc;
- struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe;
LIST_REMOVE(ii, list); /* remove from active list */
@@ -2244,7 +2446,7 @@ uhci_device_bulk_done(reqh)
uhci_free_std_chain(sc, ii->stdstart, 0);
- DPRINTFN(5, ("uhci_bulk_done: length=%d\n", reqh->actlen));
+ DPRINTFN(5, ("uhci_bulk_done: length=%d\n", xfer->actlen));
}
/* Add interrupt QH, called with vflock. */
@@ -2368,7 +2570,8 @@ uhci_open(pipe)
uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc;
- usbd_status r;
+ usbd_status err;
+ int ival;
DPRINTFN(1, ("uhci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
pipe, pipe->device->address,
@@ -2392,23 +2595,23 @@ uhci_open(pipe)
case UE_CONTROL:
pipe->methods = &uhci_device_ctrl_methods;
upipe->u.ctl.sqh = uhci_alloc_sqh(sc);
- if (upipe->u.ctl.sqh == 0)
+ if (upipe->u.ctl.sqh == NULL)
goto bad;
upipe->u.ctl.setup = uhci_alloc_std(sc);
- if (upipe->u.ctl.setup == 0) {
+ if (upipe->u.ctl.setup == NULL) {
uhci_free_sqh(sc, upipe->u.ctl.sqh);
goto bad;
}
upipe->u.ctl.stat = uhci_alloc_std(sc);
- if (upipe->u.ctl.stat == 0) {
+ if (upipe->u.ctl.stat == NULL) {
uhci_free_sqh(sc, upipe->u.ctl.sqh);
uhci_free_std(sc, upipe->u.ctl.setup);
goto bad;
}
- r = usb_allocmem(&sc->sc_bus,
+ err = usb_allocmem(&sc->sc_bus,
sizeof(usb_device_request_t),
0, &upipe->u.ctl.reqdma);
- if (r != USBD_NORMAL_COMPLETION) {
+ if (err) {
uhci_free_sqh(sc, upipe->u.ctl.sqh);
uhci_free_std(sc, upipe->u.ctl.setup);
uhci_free_std(sc, upipe->u.ctl.stat);
@@ -2417,14 +2620,17 @@ uhci_open(pipe)
break;
case UE_INTERRUPT:
pipe->methods = &uhci_device_intr_methods;
- return (uhci_device_setintr(sc, upipe, ed->bInterval));
+ ival = pipe->interval;
+ if (ival == USBD_DEFAULT_INTERVAL)
+ ival = ed->bInterval;
+ return (uhci_device_setintr(sc, upipe, ival));
case UE_ISOCHRONOUS:
pipe->methods = &uhci_device_isoc_methods;
return (uhci_setup_isoc(pipe));
case UE_BULK:
pipe->methods = &uhci_device_bulk_methods;
upipe->u.bulk.sqh = uhci_alloc_sqh(sc);
- if (upipe->u.bulk.sqh == 0)
+ if (upipe->u.bulk.sqh == NULL)
goto bad;
break;
}
@@ -2443,8 +2649,8 @@ usb_device_descriptor_t uhci_devd = {
USB_DEVICE_DESCRIPTOR_SIZE,
UDESC_DEVICE, /* type */
{0x00, 0x01}, /* USB version */
- UCLASS_HUB, /* class */
- USUBCLASS_HUB, /* subclass */
+ UDCLASS_HUB, /* class */
+ UDSUBCLASS_HUB, /* subclass */
0, /* protocol */
64, /* max packet */
{0},{0},{0x00,0x01}, /* device id */
@@ -2471,8 +2677,8 @@ usb_interface_descriptor_t uhci_ifcd = {
0,
0,
1,
- UCLASS_HUB,
- USUBCLASS_HUB,
+ UICLASS_HUB,
+ UISUBCLASS_HUB,
0,
0
};
@@ -2520,37 +2726,42 @@ uhci_str(p, l, s)
* Simulate a hardware hub by handling all the necessary requests.
*/
usbd_status
-uhci_root_ctrl_transfer(reqh)
- usbd_request_handle reqh;
+uhci_root_ctrl_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
/* Insert last in queue. */
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- /* Pipe isn't running, start first */
- return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&reqh->pipe->queue)));
+ /* Pipe isn't running (otherwise err would be USBD_INPROG),
+ * start first
+ */
+ return (uhci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
usbd_status
-uhci_root_ctrl_start(reqh)
- usbd_request_handle reqh;
+uhci_root_ctrl_start(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_softc_t *sc = (uhci_softc_t *)reqh->pipe->device->bus;
+ uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
usb_device_request_t *req;
void *buf = NULL;
int port, x;
int s, len, value, index, status, change, l, totlen = 0;
usb_port_status_t ps;
- usbd_status r;
+ usbd_status err;
+
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST))
+ if (!(xfer->rqflags & URQ_REQUEST))
panic("uhci_root_ctrl_transfer: not a request\n");
#endif
- req = &reqh->request;
+ req = &xfer->request;
DPRINTFN(2,("uhci_root_ctrl_control type=0x%02x request=%02x\n",
req->bmRequestType, req->bRequest));
@@ -2560,7 +2771,7 @@ uhci_root_ctrl_start(reqh)
index = UGETW(req->wIndex);
if (len != 0)
- buf = KERNADDR(&reqh->dmabuf);
+ buf = KERNADDR(&xfer->dmabuf);
#define C(x,y) ((x) | ((y) << 8))
switch(C(req->bRequest, req->bmRequestType)) {
@@ -2583,7 +2794,7 @@ uhci_root_ctrl_start(reqh)
switch(value >> 8) {
case UDESC_DEVICE:
if ((value & 0xff) != 0) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
@@ -2592,7 +2803,7 @@ uhci_root_ctrl_start(reqh)
break;
case UDESC_CONFIG:
if ((value & 0xff) != 0) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
totlen = l = min(len, USB_CONFIG_DESCRIPTOR_SIZE);
@@ -2623,7 +2834,7 @@ uhci_root_ctrl_start(reqh)
}
break;
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
break;
@@ -2648,14 +2859,14 @@ uhci_root_ctrl_start(reqh)
break;
case C(UR_SET_ADDRESS, UT_WRITE_DEVICE):
if (value >= USB_MAX_DEVICES) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
sc->sc_addr = value;
break;
case C(UR_SET_CONFIG, UT_WRITE_DEVICE):
if (value != 0 && value != 1) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
sc->sc_conf = value;
@@ -2665,7 +2876,7 @@ uhci_root_ctrl_start(reqh)
case C(UR_SET_FEATURE, UT_WRITE_DEVICE):
case C(UR_SET_FEATURE, UT_WRITE_INTERFACE):
case C(UR_SET_FEATURE, UT_WRITE_ENDPOINT):
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
case C(UR_SET_INTERFACE, UT_WRITE_INTERFACE):
break;
@@ -2683,7 +2894,7 @@ uhci_root_ctrl_start(reqh)
else if (index == 2)
port = UHCI_PORTSC2;
else {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
switch(value) {
@@ -2713,7 +2924,7 @@ uhci_root_ctrl_start(reqh)
break;
case UHF_C_PORT_RESET:
sc->sc_isreset = 0;
- r = USBD_NORMAL_COMPLETION;
+ err = USBD_NORMAL_COMPLETION;
goto ret;
case UHF_PORT_CONNECTION:
case UHF_PORT_OVER_CURRENT:
@@ -2721,7 +2932,7 @@ uhci_root_ctrl_start(reqh)
case UHF_PORT_LOW_SPEED:
case UHF_C_PORT_SUSPEND:
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
break;
@@ -2731,7 +2942,7 @@ uhci_root_ctrl_start(reqh)
else if (index == 2)
port = UHCI_PORTSC2;
else {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
if (len > 0) {
@@ -2743,7 +2954,7 @@ uhci_root_ctrl_start(reqh)
break;
case C(UR_GET_DESCRIPTOR, UT_READ_CLASS_DEVICE):
if (value != 0) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
l = min(len, USB_HUB_DESCRIPTOR_SIZE);
@@ -2752,7 +2963,7 @@ uhci_root_ctrl_start(reqh)
break;
case C(UR_GET_STATUS, UT_READ_CLASS_DEVICE):
if (len != 4) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
memset(buf, 0, len);
@@ -2764,11 +2975,11 @@ uhci_root_ctrl_start(reqh)
else if (index == 2)
port = UHCI_PORTSC2;
else {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
if (len != 4) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
x = UREAD2(sc, port);
@@ -2799,7 +3010,7 @@ uhci_root_ctrl_start(reqh)
totlen = l;
break;
case C(UR_SET_DESCRIPTOR, UT_WRITE_CLASS_DEVICE):
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
case C(UR_SET_FEATURE, UT_WRITE_CLASS_DEVICE):
break;
@@ -2809,7 +3020,7 @@ uhci_root_ctrl_start(reqh)
else if (index == 2)
port = UHCI_PORTSC2;
else {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
switch(value) {
@@ -2844,31 +3055,31 @@ uhci_root_ctrl_start(reqh)
case UHF_C_PORT_SUSPEND:
case UHF_C_PORT_RESET:
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
break;
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
- reqh->actlen = totlen;
- r = USBD_NORMAL_COMPLETION;
+ xfer->actlen = totlen;
+ err = USBD_NORMAL_COMPLETION;
ret:
- reqh->status = r;
- reqh->hcpriv = 0;
+ xfer->status = err;
+ xfer->hcpriv = 0;
s = splusb();
- usb_transfer_complete(reqh);
+ usb_transfer_complete(xfer);
splx(s);
return (USBD_IN_PROGRESS);
}
/* Abort a root control request. */
void
-uhci_root_ctrl_abort(reqh)
- usbd_request_handle reqh;
+uhci_root_ctrl_abort(xfer)
+ usbd_xfer_handle xfer;
{
- /* Nothing to do, all transfers are syncronous. */
+ /* Nothing to do, all transfers are synchronous. */
}
/* Close the root pipe. */
@@ -2876,59 +3087,61 @@ void
uhci_root_ctrl_close(pipe)
usbd_pipe_handle pipe;
{
- uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
-
- sc->sc_has_timo = 0;
DPRINTF(("uhci_root_ctrl_close\n"));
}
/* Abort a root interrupt request. */
void
-uhci_root_intr_abort(reqh)
- usbd_request_handle reqh;
+uhci_root_intr_abort(xfer)
+ usbd_xfer_handle xfer;
{
- uhci_softc_t *sc = (uhci_softc_t *)reqh->pipe->device->bus;
+ uhci_softc_t *sc = (uhci_softc_t *)xfer->pipe->device->bus;
- usb_untimeout(uhci_timo, reqh, reqh->timo_handle);
- sc->sc_has_timo = 0;
+ usb_untimeout(uhci_timo, xfer, xfer->timo_handle);
+ sc->sc_has_timo = NULL;
- if (reqh->pipe->intrreqh == reqh) {
+ if (xfer->pipe->intrxfer == xfer) {
DPRINTF(("uhci_root_intr_abort: remove\n"));
- reqh->pipe->intrreqh = 0;
+ xfer->pipe->intrxfer = 0;
}
- reqh->status = USBD_CANCELLED;
- usb_transfer_complete(reqh);
+ xfer->status = USBD_CANCELLED;
+ usb_transfer_complete(xfer);
}
usbd_status
-uhci_root_intr_transfer(reqh)
- usbd_request_handle reqh;
+uhci_root_intr_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
/* Insert last in queue. */
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- /* Pipe isn't running, start first */
- return (uhci_root_intr_start(SIMPLEQ_FIRST(&reqh->pipe->queue)));
+ /* Pipe isn't running (otherwise err would be USBD_INPROG),
+ * start first
+ */
+ return (uhci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
/* Start a transfer on the root interrupt pipe */
usbd_status
-uhci_root_intr_start(reqh)
- usbd_request_handle reqh;
+uhci_root_intr_start(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_pipe_handle pipe = reqh->pipe;
+ usbd_pipe_handle pipe = xfer->pipe;
uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
- DPRINTFN(3, ("uhci_root_intr_transfer: reqh=%p len=%d flags=%d\n",
- reqh, reqh->length, reqh->flags));
+ DPRINTFN(3, ("uhci_root_intr_transfer: xfer=%p len=%d flags=%d\n",
+ xfer, xfer->length, xfer->flags));
+
+ if (sc->sc_dying)
+ return (USBD_IOERROR);
- sc->sc_ival = MS_TO_TICKS(reqh->pipe->endpoint->edesc->bInterval);
- usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timo_handle);
- sc->sc_has_timo = reqh;
+ sc->sc_ival = MS_TO_TICKS(xfer->pipe->endpoint->edesc->bInterval);
+ usb_timeout(uhci_timo, xfer, sc->sc_ival, xfer->timo_handle);
+ sc->sc_has_timo = xfer;
return (USBD_IN_PROGRESS);
}
@@ -2939,8 +3152,8 @@ uhci_root_intr_close(pipe)
{
uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
- usb_untimeout(uhci_timo, pipe->intrreqh, pipe->intrreqh->timo_handle);
- sc->sc_has_timo = 0;
+ usb_untimeout(uhci_timo, pipe->intrxfer, pipe->intrxfer->timo_handle);
+ sc->sc_has_timo = NULL;
DPRINTF(("uhci_root_intr_close\n"));
}