summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb/ohci.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/usb/ohci.c')
-rw-r--r--sys/dev/usb/ohci.c1192
1 files changed, 692 insertions, 500 deletions
diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c
index 0c5855c..b09e029 100644
--- a/sys/dev/usb/ohci.c
+++ b/sys/dev/usb/ohci.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci.c,v 1.43 1999/09/11 08:19:26 augustss Exp $ */
+/* $NetBSD: ohci.c,v 1.52 1999/10/13 08:10:55 augustss Exp $ */
/* $FreeBSD$ */
/*
@@ -47,22 +47,22 @@
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/kernel.h>
#include <sys/malloc.h>
#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/select.h>
#elif defined(__FreeBSD__)
#include <sys/module.h>
#include <sys/bus.h>
-#endif
-#include <sys/proc.h>
-#include <sys/queue.h>
-
-#if defined(__FreeBSD__)
#include <machine/bus_pio.h>
#include <machine/bus_memio.h>
+#if defined(DIAGNOSTIC) && defined(__i386__)
+#include <machine/cpu.h>
+#endif
#endif
+#include <sys/proc.h>
+#include <sys/queue.h>
#include <machine/bus.h>
#include <machine/endian.h>
@@ -82,6 +82,12 @@
#define delay(d) DELAY(d)
#endif
+#if defined(__OpenBSD__)
+struct cfdriver ohci_cd = {
+ NULL, "ohci", DV_DULL
+};
+#endif
+
#ifdef OHCI_DEBUG
#define DPRINTF(x) if (ohcidebug) logprintf x
#define DPRINTFN(n,x) if (ohcidebug>(n)) logprintf x
@@ -91,13 +97,6 @@ int ohcidebug = 1;
#define DPRINTFN(n,x)
#endif
-
-#if defined(__OpenBSD__)
-struct cfdriver ohci_cd = {
- NULL, "ohci", DV_DULL
-};
-#endif
-
/*
* The OHCI controller is little endian, so on big endian machines
* the data strored in memory needs to be swapped.
@@ -110,87 +109,102 @@ struct cfdriver ohci_cd = {
struct ohci_pipe;
-ohci_soft_ed_t *ohci_alloc_sed __P((ohci_softc_t *));
-void ohci_free_sed __P((ohci_softc_t *, ohci_soft_ed_t *));
-
-ohci_soft_td_t *ohci_alloc_std __P((ohci_softc_t *));
-void ohci_free_std __P((ohci_softc_t *, ohci_soft_td_t *));
-
-void ohci_power __P((int, void *));
-usbd_status ohci_open __P((usbd_pipe_handle));
-void ohci_poll __P((struct usbd_bus *));
-void ohci_waitintr __P((ohci_softc_t *, usbd_request_handle));
-void ohci_rhsc __P((ohci_softc_t *, usbd_request_handle));
-void ohci_process_done __P((ohci_softc_t *, ohci_physaddr_t));
-
-usbd_status ohci_device_request __P((usbd_request_handle reqh));
-void ohci_add_ed __P((ohci_soft_ed_t *, ohci_soft_ed_t *));
-void ohci_rem_ed __P((ohci_soft_ed_t *, ohci_soft_ed_t *));
-void ohci_hash_add_td __P((ohci_softc_t *, ohci_soft_td_t *));
-void ohci_hash_rem_td __P((ohci_softc_t *, ohci_soft_td_t *));
-ohci_soft_td_t *ohci_hash_find_td __P((ohci_softc_t *, ohci_physaddr_t));
-
-usbd_status ohci_allocm __P((struct usbd_bus *, usb_dma_t *, u_int32_t));
-void ohci_freem __P((struct usbd_bus *, usb_dma_t *));
-
-usbd_status ohci_root_ctrl_transfer __P((usbd_request_handle));
-usbd_status ohci_root_ctrl_start __P((usbd_request_handle));
-void ohci_root_ctrl_abort __P((usbd_request_handle));
-void ohci_root_ctrl_close __P((usbd_pipe_handle));
-
-usbd_status ohci_root_intr_transfer __P((usbd_request_handle));
-usbd_status ohci_root_intr_start __P((usbd_request_handle));
-void ohci_root_intr_abort __P((usbd_request_handle));
-void ohci_root_intr_close __P((usbd_pipe_handle));
-void ohci_root_intr_done __P((usbd_request_handle));
-
-usbd_status ohci_device_ctrl_transfer __P((usbd_request_handle));
-usbd_status ohci_device_ctrl_start __P((usbd_request_handle));
-void ohci_device_ctrl_abort __P((usbd_request_handle));
-void ohci_device_ctrl_close __P((usbd_pipe_handle));
-void ohci_device_ctrl_done __P((usbd_request_handle));
-
-usbd_status ohci_device_bulk_transfer __P((usbd_request_handle));
-usbd_status ohci_device_bulk_start __P((usbd_request_handle));
-void ohci_device_bulk_abort __P((usbd_request_handle));
-void ohci_device_bulk_close __P((usbd_pipe_handle));
-void ohci_device_bulk_done __P((usbd_request_handle));
-
-usbd_status ohci_device_intr_transfer __P((usbd_request_handle));
-usbd_status ohci_device_intr_start __P((usbd_request_handle));
-void ohci_device_intr_abort __P((usbd_request_handle));
-void ohci_device_intr_close __P((usbd_pipe_handle));
-void ohci_device_intr_done __P((usbd_request_handle));
-
-usbd_status ohci_device_isoc_transfer __P((usbd_request_handle));
-usbd_status ohci_device_isoc_start __P((usbd_request_handle));
-void ohci_device_isoc_abort __P((usbd_request_handle));
-void ohci_device_isoc_close __P((usbd_pipe_handle));
-void ohci_device_isoc_done __P((usbd_request_handle));
-
-usbd_status ohci_device_setintr __P((ohci_softc_t *sc,
- struct ohci_pipe *pipe, int ival));
-
-int ohci_str __P((usb_string_descriptor_t *, int, char *));
-
-void ohci_timeout __P((void *));
-void ohci_rhsc_able __P((ohci_softc_t *, int));
-
-void ohci_close_pipe __P((usbd_pipe_handle pipe,
- ohci_soft_ed_t *head));
-void ohci_abort_req __P((usbd_request_handle reqh,
- usbd_status status));
-void ohci_abort_req_end __P((void *));
-
-void ohci_device_clear_toggle __P((usbd_pipe_handle pipe));
-void ohci_noop __P((usbd_pipe_handle pipe));
+static ohci_soft_ed_t *ohci_alloc_sed __P((ohci_softc_t *));
+static void ohci_free_sed __P((ohci_softc_t *, ohci_soft_ed_t *));
+
+static ohci_soft_td_t *ohci_alloc_std __P((ohci_softc_t *));
+static void ohci_free_std __P((ohci_softc_t *, ohci_soft_td_t *));
+
+#if 0
+static void ohci_free_std_chain __P((ohci_softc_t *,
+ ohci_soft_td_t *, ohci_soft_td_t *));
+#endif
+static usbd_status ohci_alloc_std_chain __P((struct ohci_pipe *,
+ ohci_softc_t *, int, int, int, usb_dma_t *,
+ ohci_soft_td_t *, ohci_soft_td_t **));
+
+static void ohci_power __P((int, void *));
+static usbd_status ohci_open __P((usbd_pipe_handle));
+static void ohci_poll __P((struct usbd_bus *));
+static void ohci_waitintr __P((ohci_softc_t *,
+ usbd_xfer_handle));
+static void ohci_rhsc __P((ohci_softc_t *, usbd_xfer_handle));
+static void ohci_process_done __P((ohci_softc_t *,
+ ohci_physaddr_t));
+
+static usbd_status ohci_device_request __P((usbd_xfer_handle xfer));
+static void ohci_add_ed __P((ohci_soft_ed_t *, ohci_soft_ed_t *));
+static void ohci_rem_ed __P((ohci_soft_ed_t *, ohci_soft_ed_t *));
+static void ohci_hash_add_td __P((ohci_softc_t *,
+ ohci_soft_td_t *));
+static void ohci_hash_rem_td __P((ohci_softc_t *,
+ ohci_soft_td_t *));
+static ohci_soft_td_t *ohci_hash_find_td __P((ohci_softc_t *,
+ ohci_physaddr_t));
+
+static usbd_status ohci_allocm __P((struct usbd_bus *, usb_dma_t *,
+ u_int32_t));
+static void ohci_freem __P((struct usbd_bus *, usb_dma_t *));
+
+static usbd_status ohci_root_ctrl_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_root_ctrl_start __P((usbd_xfer_handle));
+static void ohci_root_ctrl_abort __P((usbd_xfer_handle));
+static void ohci_root_ctrl_close __P((usbd_pipe_handle));
+
+static usbd_status ohci_root_intr_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_root_intr_start __P((usbd_xfer_handle));
+static void ohci_root_intr_abort __P((usbd_xfer_handle));
+static void ohci_root_intr_close __P((usbd_pipe_handle));
+static void ohci_root_intr_done __P((usbd_xfer_handle));
+
+static usbd_status ohci_device_ctrl_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_device_ctrl_start __P((usbd_xfer_handle));
+static void ohci_device_ctrl_abort __P((usbd_xfer_handle));
+static void ohci_device_ctrl_close __P((usbd_pipe_handle));
+static void ohci_device_ctrl_done __P((usbd_xfer_handle));
+
+static usbd_status ohci_device_bulk_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_device_bulk_start __P((usbd_xfer_handle));
+static void ohci_device_bulk_abort __P((usbd_xfer_handle));
+static void ohci_device_bulk_close __P((usbd_pipe_handle));
+static void ohci_device_bulk_done __P((usbd_xfer_handle));
+
+static usbd_status ohci_device_intr_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_device_intr_start __P((usbd_xfer_handle));
+static void ohci_device_intr_abort __P((usbd_xfer_handle));
+static void ohci_device_intr_close __P((usbd_pipe_handle));
+static void ohci_device_intr_done __P((usbd_xfer_handle));
+
+#if 0
+static usbd_status ohci_device_isoc_transfer __P((usbd_xfer_handle));
+static usbd_status ohci_device_isoc_start __P((usbd_xfer_handle));
+static void ohci_device_isoc_abort __P((usbd_xfer_handle));
+static void ohci_device_isoc_close __P((usbd_pipe_handle));
+static void ohci_device_isoc_done __P((usbd_xfer_handle));
+#endif
+
+static usbd_status ohci_device_setintr __P((ohci_softc_t *sc,
+ struct ohci_pipe *pipe, int ival));
+
+static int ohci_str __P((usb_string_descriptor_t *, int, char *));
+
+static void ohci_timeout __P((void *));
+static void ohci_rhsc_able __P((ohci_softc_t *, int));
+
+static void ohci_close_pipe __P((usbd_pipe_handle pipe,
+ ohci_soft_ed_t *head));
+static void ohci_abort_req __P((usbd_xfer_handle xfer,
+ usbd_status status));
+static void ohci_abort_req_end __P((void *));
+
+static void ohci_device_clear_toggle __P((usbd_pipe_handle pipe));
+static void ohci_noop __P((usbd_pipe_handle pipe));
#ifdef OHCI_DEBUG
-ohci_softc_t *thesc;
-void ohci_dumpregs __P((ohci_softc_t *));
-void ohci_dump_tds __P((ohci_soft_td_t *));
-void ohci_dump_td __P((ohci_soft_td_t *));
-void ohci_dump_ed __P((ohci_soft_ed_t *));
+static void ohci_dumpregs __P((ohci_softc_t *));
+static void ohci_dump_tds __P((ohci_soft_td_t *));
+static void ohci_dump_td __P((ohci_soft_td_t *));
+static void ohci_dump_ed __P((ohci_soft_ed_t *));
#endif
#define OWRITE4(sc, r, x) bus_space_write_4((sc)->iot, (sc)->ioh, (r), (x))
@@ -214,7 +228,7 @@ struct ohci_pipe {
struct {
usb_dma_t reqdma;
u_int length;
- ohci_soft_td_t *setup, *xfer, *stat;
+ ohci_soft_td_t *setup, *data, *stat;
} ctl;
/* Interrupt pipe */
struct {
@@ -235,14 +249,14 @@ struct ohci_pipe {
#define OHCI_INTR_ENDPT 1
-struct usbd_bus_methods ohci_bus_methods = {
+static struct usbd_bus_methods ohci_bus_methods = {
ohci_open,
ohci_poll,
ohci_allocm,
ohci_freem,
};
-struct usbd_pipe_methods ohci_root_ctrl_methods = {
+static struct usbd_pipe_methods ohci_root_ctrl_methods = {
ohci_root_ctrl_transfer,
ohci_root_ctrl_start,
ohci_root_ctrl_abort,
@@ -251,7 +265,7 @@ struct usbd_pipe_methods ohci_root_ctrl_methods = {
0,
};
-struct usbd_pipe_methods ohci_root_intr_methods = {
+static struct usbd_pipe_methods ohci_root_intr_methods = {
ohci_root_intr_transfer,
ohci_root_intr_start,
ohci_root_intr_abort,
@@ -260,7 +274,7 @@ struct usbd_pipe_methods ohci_root_intr_methods = {
ohci_root_intr_done,
};
-struct usbd_pipe_methods ohci_device_ctrl_methods = {
+static struct usbd_pipe_methods ohci_device_ctrl_methods = {
ohci_device_ctrl_transfer,
ohci_device_ctrl_start,
ohci_device_ctrl_abort,
@@ -269,7 +283,7 @@ struct usbd_pipe_methods ohci_device_ctrl_methods = {
ohci_device_ctrl_done,
};
-struct usbd_pipe_methods ohci_device_intr_methods = {
+static struct usbd_pipe_methods ohci_device_intr_methods = {
ohci_device_intr_transfer,
ohci_device_intr_start,
ohci_device_intr_abort,
@@ -278,7 +292,7 @@ struct usbd_pipe_methods ohci_device_intr_methods = {
ohci_device_intr_done,
};
-struct usbd_pipe_methods ohci_device_bulk_methods = {
+static struct usbd_pipe_methods ohci_device_bulk_methods = {
ohci_device_bulk_transfer,
ohci_device_bulk_start,
ohci_device_bulk_abort,
@@ -288,7 +302,7 @@ struct usbd_pipe_methods ohci_device_bulk_methods = {
};
#if 0
-struct usbd_pipe_methods ohci_device_isoc_methods = {
+static struct usbd_pipe_methods ohci_device_isoc_methods = {
ohci_device_isoc_transfer,
ohci_device_isoc_start,
ohci_device_isoc_abort,
@@ -298,20 +312,62 @@ struct usbd_pipe_methods ohci_device_isoc_methods = {
};
#endif
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+int
+ohci_activate(self, act)
+ device_ptr_t self;
+ enum devact act;
+{
+ struct ohci_softc *sc = (struct ohci_softc *)self;
+ int rv = 0;
+
+ switch (act) {
+ case DVACT_ACTIVATE:
+ return (EOPNOTSUPP);
+ break;
+
+ case DVACT_DEACTIVATE:
+ if (sc->sc_child != NULL)
+ rv = config_deactivate(sc->sc_child);
+ break;
+ }
+ return (rv);
+}
+
+int
+ohci_detach(sc, flags)
+ struct ohci_softc *sc;
+ int flags;
+{
+ int rv = 0;
+
+ if (sc->sc_child != NULL)
+ rv = config_detach(sc->sc_child, flags);
+
+ if (rv != 0)
+ return (rv);
+
+ powerhook_disestablish(sc->sc_powerhook);
+ /* free data structures XXX */
+
+ return (rv);
+}
+#endif
+
ohci_soft_ed_t *
ohci_alloc_sed(sc)
ohci_softc_t *sc;
{
ohci_soft_ed_t *sed;
- usbd_status r;
+ usbd_status err;
int i, offs;
usb_dma_t dma;
- if (!sc->sc_freeeds) {
+ if (sc->sc_freeeds == NULL) {
DPRINTFN(2, ("ohci_alloc_sed: allocating chunk\n"));
- r = usb_allocmem(sc->sc_dmatag, OHCI_SED_SIZE * OHCI_SED_CHUNK,
- OHCI_ED_ALIGN, &dma);
- if (r != USBD_NORMAL_COMPLETION)
+ err = usb_allocmem(&sc->sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK,
+ OHCI_ED_ALIGN, &dma);
+ if (err)
return (0);
for(i = 0; i < OHCI_SED_CHUNK; i++) {
offs = i * OHCI_SED_SIZE;
@@ -342,15 +398,15 @@ ohci_alloc_std(sc)
ohci_softc_t *sc;
{
ohci_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, ("ohci_alloc_std: allocating chunk\n"));
- r = usb_allocmem(sc->sc_dmatag, OHCI_STD_SIZE * OHCI_STD_CHUNK,
- OHCI_TD_ALIGN, &dma);
- if (r != USBD_NORMAL_COMPLETION)
+ err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
+ OHCI_TD_ALIGN, &dma);
+ if (err)
return (0);
for(i = 0; i < OHCI_STD_CHUNK; i++) {
offs = i * OHCI_STD_SIZE;
@@ -377,11 +433,92 @@ ohci_free_std(sc, std)
}
usbd_status
+ohci_alloc_std_chain(upipe, sc, len, rd, shortok, dma, sp, ep)
+ struct ohci_pipe *upipe;
+ ohci_softc_t *sc;
+ int len, rd, shortok;
+ usb_dma_t *dma;
+ ohci_soft_td_t *sp, **ep;
+{
+ ohci_soft_td_t *next, *cur;
+ ohci_physaddr_t dataphys, dataphysend;
+ u_int32_t intr;
+ int curlen;
+
+ DPRINTFN(len < 4096,("ohci_alloc_std_chain: start len=%d\n", len));
+ cur = sp;
+ dataphys = DMAADDR(dma);
+ dataphysend = OHCI_PAGE(dataphys + len - 1);
+ for (;;) {
+ next = ohci_alloc_std(sc);
+ if (next == 0) {
+ /* XXX free chain */
+ return (USBD_NOMEM);
+ }
+
+ /* The OHCI hardware can handle at most one page crossing. */
+ if (OHCI_PAGE(dataphys) == dataphysend ||
+ OHCI_PAGE(dataphys) + OHCI_PAGE_SIZE == dataphysend) {
+ /* we can handle it in this TD */
+ curlen = len;
+ } else {
+ /* must use multiple TDs, fill as much as possible. */
+ curlen = 2 * OHCI_PAGE_SIZE -
+ (dataphys & (OHCI_PAGE_SIZE-1));
+ }
+ DPRINTFN(4,("ohci_alloc_std_chain: dataphys=0x%08x "
+ "dataphysend=0x%08x len=%d curlen=%d\n",
+ dataphys, dataphysend,
+ len, curlen));
+ len -= curlen;
+
+ intr = len == 0 ? OHCI_TD_SET_DI(1) : OHCI_TD_NOINTR;
+ cur->td.td_flags = LE(
+ (rd ? OHCI_TD_IN : OHCI_TD_OUT) | OHCI_TD_NOCC |
+ intr | OHCI_TD_TOGGLE_CARRY |
+ (shortok ? OHCI_TD_R : 0));
+ cur->td.td_cbp = LE(dataphys);
+ cur->nexttd = next;
+ cur->td.td_nexttd = LE(next->physaddr);
+ cur->td.td_be = LE(dataphys + curlen - 1);
+ cur->len = curlen;
+ cur->flags = OHCI_ADD_LEN;
+ DPRINTFN(10,("ohci_alloc_std_chain: cbp=0x%08x be=0x%08x\n",
+ dataphys, dataphys + curlen - 1));
+ if (len == 0)
+ break;
+ DPRINTFN(10,("ohci_alloc_std_chain: extend chain\n"));
+ dataphys += curlen;
+ cur = next;
+ }
+ cur->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
+ *ep = next;
+
+ return (USBD_NORMAL_COMPLETION);
+}
+
+#if 0
+static void
+ohci_free_std_chain(sc, std, stdend)
+ ohci_softc_t *sc;
+ ohci_soft_td_t *std;
+ ohci_soft_td_t *stdend;
+{
+ ohci_soft_td_t *p;
+
+ for (; std != stdend; std = p) {
+ p = std->nexttd;
+ ohci_free_std(sc, std);
+ }
+}
+#endif
+
+usbd_status
ohci_init(sc)
ohci_softc_t *sc;
{
ohci_soft_ed_t *sed, *psed;
- usbd_status r;
+ usbd_status err;
int rev;
int i;
u_int32_t s, ctl, ival, hcr, fm, per;
@@ -389,12 +526,13 @@ ohci_init(sc)
DPRINTF(("ohci_init: start\n"));
rev = OREAD4(sc, OHCI_REVISION);
#if defined(__OpenBSD__)
- printf(", OHCI version %d.%d%s\n",
+ printf(",");
#else
- printf("%s: OHCI version %d.%d%s\n", USBDEVNAME(sc->sc_bus.bdev),
+ printf("%s", USBDEVNAME(sc->sc_bus.bdev));
#endif
- OHCI_REV_HI(rev), OHCI_REV_LO(rev),
+ printf(" OHCI version %d.%d%s\n", OHCI_REV_HI(rev), OHCI_REV_LO(rev),
OHCI_REV_LEGACY(rev) ? ", legacy support" : "");
+
if (OHCI_REV_HI(rev) != 1 || OHCI_REV_LO(rev) != 0) {
printf("%s: unsupported OHCI revision\n",
USBDEVNAME(sc->sc_bus.bdev));
@@ -405,25 +543,25 @@ ohci_init(sc)
LIST_INIT(&sc->sc_hash_tds[i]);
/* Allocate the HCCA area. */
- r = usb_allocmem(sc->sc_dmatag, OHCI_HCCA_SIZE,
- OHCI_HCCA_ALIGN, &sc->sc_hccadma);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE,
+ OHCI_HCCA_ALIGN, &sc->sc_hccadma);
+ if (err)
+ return (err);
sc->sc_hcca = (struct ohci_hcca *)KERNADDR(&sc->sc_hccadma);
memset(sc->sc_hcca, 0, OHCI_HCCA_SIZE);
sc->sc_eintrs = OHCI_NORMAL_INTRS;
sc->sc_ctrl_head = ohci_alloc_sed(sc);
- if (!sc->sc_ctrl_head) {
- r = USBD_NOMEM;
+ if (sc->sc_ctrl_head == NULL) {
+ err = USBD_NOMEM;
goto bad1;
}
sc->sc_ctrl_head->ed.ed_flags |= LE(OHCI_ED_SKIP);
sc->sc_bulk_head = ohci_alloc_sed(sc);
- if (!sc->sc_bulk_head) {
- r = USBD_NOMEM;
+ if (sc->sc_bulk_head == NULL) {
+ err = USBD_NOMEM;
goto bad2;
}
sc->sc_bulk_head->ed.ed_flags |= LE(OHCI_ED_SKIP);
@@ -431,10 +569,10 @@ ohci_init(sc)
/* Allocate all the dummy EDs that make up the interrupt tree. */
for (i = 0; i < OHCI_NO_EDS; i++) {
sed = ohci_alloc_sed(sc);
- if (!sed) {
+ if (sed == NULL) {
while (--i >= 0)
ohci_free_sed(sc, sc->sc_eds[i]);
- r = USBD_NOMEM;
+ err = USBD_NOMEM;
goto bad3;
}
/* All ED fields are set to 0. */
@@ -462,7 +600,7 @@ ohci_init(sc)
s = OREAD4(sc, OHCI_COMMAND_STATUS);
OWRITE4(sc, OHCI_COMMAND_STATUS, s | OHCI_OCR);
for (i = 0; i < 100 && (ctl & OHCI_IR); i++) {
- delay(1000);
+ usb_delay_ms(&sc->sc_bus, 1);
ctl = OREAD4(sc, OHCI_CONTROL);
}
if ((ctl & OHCI_IR) == 0) {
@@ -476,13 +614,13 @@ ohci_init(sc)
DPRINTF(("ohci_init: BIOS active\n"));
if ((ctl & OHCI_HCFS_MASK) != OHCI_HCFS_OPERATIONAL) {
OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_OPERATIONAL);
- delay(USB_RESUME_DELAY * 1000);
+ usb_delay_ms(&sc->sc_bus, USB_RESUME_DELAY);
}
} else {
DPRINTF(("ohci_init: cold started\n"));
reset:
/* Controller was cold started. */
- delay(USB_BUS_RESET_DELAY * 1000);
+ usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY);
}
/*
@@ -491,7 +629,7 @@ ohci_init(sc)
*/
DPRINTF(("%s: resetting\n", USBDEVNAME(sc->sc_bus.bdev)));
OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_RESET);
- delay(USB_BUS_RESET_DELAY * 1000);
+ usb_delay_ms(&sc->sc_bus, USB_BUS_RESET_DELAY);
/* We now own the host controller and the bus has been reset. */
ival = OHCI_GET_IVAL(OREAD4(sc, OHCI_FM_INTERVAL));
@@ -506,11 +644,10 @@ ohci_init(sc)
}
if (hcr) {
printf("%s: reset timeout\n", USBDEVNAME(sc->sc_bus.bdev));
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto bad3;
}
#ifdef OHCI_DEBUG
- thesc = sc;
if (ohcidebug > 15)
ohci_dumpregs(sc);
#endif
@@ -521,8 +658,10 @@ ohci_init(sc)
OWRITE4(sc, OHCI_HCCA, DMAADDR(&sc->sc_hccadma));
OWRITE4(sc, OHCI_CONTROL_HEAD_ED, sc->sc_ctrl_head->physaddr);
OWRITE4(sc, OHCI_BULK_HEAD_ED, sc->sc_bulk_head->physaddr);
+ /* disable all interrupts and then switch on all desired interrupts */
OWRITE4(sc, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS);
OWRITE4(sc, OHCI_INTERRUPT_ENABLE, sc->sc_eintrs | OHCI_MIE);
+ /* switch on desired functional features */
ctl = OREAD4(sc, OHCI_CONTROL);
ctl &= ~(OHCI_CBSR_MASK | OHCI_LES | OHCI_HCFS_MASK | OHCI_IR);
ctl |= OHCI_PLE | OHCI_IE | OHCI_CLE | OHCI_BLE |
@@ -554,9 +693,7 @@ ohci_init(sc)
sc->sc_bus.methods = &ohci_bus_methods;
sc->sc_bus.pipe_size = sizeof(struct ohci_pipe);
-#if defined(__NetBSD__)
- powerhook_establish(ohci_power, sc);
-#endif
+ sc->sc_powerhook = powerhook_establish(ohci_power, sc);
return (USBD_NORMAL_COMPLETION);
@@ -565,8 +702,8 @@ ohci_init(sc)
bad2:
ohci_free_sed(sc, sc->sc_bulk_head);
bad1:
- usb_freemem(sc->sc_dmatag, &sc->sc_hccadma);
- return (r);
+ usb_freemem(&sc->sc_bus, &sc->sc_hccadma);
+ return (err);
}
usbd_status
@@ -579,7 +716,7 @@ ohci_allocm(bus, dma, size)
struct ohci_softc *sc = (struct ohci_softc *)bus;
#endif
- return (usb_allocmem(sc->sc_dmatag, size, 0, dma));
+ return (usb_allocmem(&sc->sc_bus, size, 0, dma));
}
void
@@ -591,7 +728,7 @@ ohci_freem(bus, dma)
struct ohci_softc *sc = (struct ohci_softc *)bus;
#endif
- usb_freemem(sc->sc_dmatag, dma);
+ usb_freemem(&sc->sc_bus, dma);
}
#if defined(__NetBSD__)
@@ -608,12 +745,9 @@ ohci_power(why, v)
ohci_dumpregs(sc);
#endif
}
-#endif /* !defined(__OpenBSD__) */
+#endif /* defined(__NetBSD__) */
#ifdef OHCI_DEBUG
-void ohcidump(void);
-void ohcidump(void) { ohci_dumpregs(thesc); }
-
void
ohci_dumpregs(sc)
ohci_softc_t *sc;
@@ -655,11 +789,25 @@ ohci_dumpregs(sc)
}
#endif
+static int ohci_intr1 __P((ohci_softc_t *));
+
int
ohci_intr(p)
void *p;
{
ohci_softc_t *sc = p;
+
+ /* If we get an interrupt while polling, then just ignore it. */
+ if (sc->sc_bus.use_polling)
+ return (0);
+
+ return (ohci_intr1(sc));
+}
+
+static int
+ohci_intr1(sc)
+ ohci_softc_t *sc;
+{
u_int32_t intrs, eintrs;
ohci_physaddr_t done;
@@ -681,15 +829,18 @@ ohci_intr(p)
intrs |= OREAD4(sc, OHCI_INTERRUPT_STATUS);
} else
intrs = OREAD4(sc, OHCI_INTERRUPT_STATUS);
+
if (!intrs)
return (0);
+
intrs &= ~OHCI_MIE;
OWRITE4(sc, OHCI_INTERRUPT_STATUS, intrs); /* Acknowledge */
eintrs = intrs & sc->sc_eintrs;
if (!eintrs)
return (0);
- sc->sc_intrs++;
+ sc->sc_bus.intr_context++;
+ sc->sc_bus.no_intrs++;
DPRINTFN(7, ("ohci_intr: sc=%p intrs=%x(%x) eintr=%x\n",
sc, (u_int)intrs, OREAD4(sc, OHCI_INTERRUPT_STATUS),
(u_int)eintrs));
@@ -714,7 +865,7 @@ ohci_intr(p)
/* XXX what else */
}
if (eintrs & OHCI_RHSC) {
- ohci_rhsc(sc, sc->sc_intrreqh);
+ ohci_rhsc(sc, sc->sc_intrxfer);
intrs &= ~OHCI_RHSC;
/*
@@ -724,6 +875,8 @@ ohci_intr(p)
ohci_rhsc_able(sc, 0);
}
+ sc->sc_bus.intr_context--;
+
/* Block unprocessed interrupts. XXX */
OWRITE4(sc, OHCI_INTERRUPT_DISABLE, intrs);
sc->sc_eintrs &= ~intrs;
@@ -769,8 +922,8 @@ ohci_process_done(sc, done)
ohci_softc_t *sc;
ohci_physaddr_t done;
{
- ohci_soft_td_t *std, *sdone;
- usbd_request_handle reqh;
+ ohci_soft_td_t *std, *sdone, *stdnext;
+ usbd_xfer_handle xfer;
int len, cc;
DPRINTFN(10,("ohci_process_done: done=0x%08lx\n", (u_long)done));
@@ -789,133 +942,138 @@ ohci_process_done(sc, done)
}
#endif
- for (std = sdone; std; std = std->dnext) {
- reqh = std->reqh;
- DPRINTFN(10, ("ohci_process_done: std=%p reqh=%p hcpriv=%p\n",
- std, reqh, reqh->hcpriv));
+ for (std = sdone; std; std = stdnext) {
+ xfer = std->xfer;
+ stdnext = std->dnext;
+ DPRINTFN(10, ("ohci_process_done: std=%p xfer=%p hcpriv=%p\n",
+ std, xfer, xfer->hcpriv));
cc = OHCI_TD_GET_CC(LE(std->td.td_flags));
- usb_untimeout(ohci_timeout, reqh, reqh->timo_handle);
- if (reqh->status == USBD_CANCELLED ||
- reqh->status == USBD_TIMEOUT) {
+ usb_untimeout(ohci_timeout, xfer, xfer->timo_handle);
+ if (xfer->status == USBD_CANCELLED ||
+ xfer->status == USBD_TIMEOUT) {
DPRINTF(("ohci_process_done: cancel/timeout %p\n",
- reqh));
+ xfer));
/* Handled by abort routine. */
- continue;
} else if (cc == OHCI_CC_NO_ERROR) {
len = std->len;
if (std->td.td_cbp != 0)
len -= LE(std->td.td_be) -
LE(std->td.td_cbp) + 1;
- if (std->flags & OHCI_SET_LEN)
- reqh->actlen = len;
+ if (std->flags & OHCI_ADD_LEN)
+ xfer->actlen += len;
if (std->flags & OHCI_CALL_DONE) {
- reqh->status = USBD_NORMAL_COMPLETION;
- usb_transfer_complete(reqh);
+ xfer->status = USBD_NORMAL_COMPLETION;
+ usb_transfer_complete(xfer);
}
+ ohci_hash_rem_td(sc, std);
+ ohci_free_std(sc, std);
} else {
- ohci_soft_td_t *p, *n;
- struct ohci_pipe *opipe =
- (struct ohci_pipe *)reqh->pipe;
- DPRINTFN(-1,("ohci_process_done: error cc=%d (%s)\n",
- OHCI_TD_GET_CC(LE(std->td.td_flags)),
- ohci_cc_strs[OHCI_TD_GET_CC(LE(std->td.td_flags))]));
/*
* Endpoint is halted. First unlink all the TDs
* belonging to the failed transfer, and then restart
* the endpoint.
*/
- for (p = std->nexttd; p->reqh == reqh; p = n) {
+ ohci_soft_td_t *p, *n;
+ struct ohci_pipe *opipe =
+ (struct ohci_pipe *)xfer->pipe;
+
+ DPRINTF(("ohci_process_done: error cc=%d (%s)\n",
+ OHCI_TD_GET_CC(LE(std->td.td_flags)),
+ ohci_cc_strs[OHCI_TD_GET_CC(LE(std->td.td_flags))]));
+
+ /* remove TDs */
+ for (p = std; p->xfer == xfer; p = n) {
n = p->nexttd;
ohci_hash_rem_td(sc, p);
ohci_free_std(sc, p);
}
+
/* clear halt */
opipe->sed->ed.ed_headp = LE(p->physaddr);
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
-
+
if (cc == OHCI_CC_STALL)
- reqh->status = USBD_STALLED;
+ xfer->status = USBD_STALLED;
else
- reqh->status = USBD_IOERROR;
- usb_transfer_complete(reqh);
+ xfer->status = USBD_IOERROR;
+ usb_transfer_complete(xfer);
}
- ohci_hash_rem_td(sc, std);
- ohci_free_std(sc, std);
}
}
void
-ohci_device_ctrl_done(reqh)
- usbd_request_handle reqh;
+ohci_device_ctrl_done(xfer)
+ usbd_xfer_handle xfer;
{
- DPRINTFN(10,("ohci_ctrl_done: reqh=%p\n", reqh));
+ DPRINTFN(10,("ohci_ctrl_done: xfer=%p\n", xfer));
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST)) {
+ if (!(xfer->rqflags & URQ_REQUEST)) {
panic("ohci_ctrl_done: not a request\n");
}
#endif
- reqh->hcpriv = 0;
+ xfer->hcpriv = NULL;
}
void
-ohci_device_intr_done(reqh)
- usbd_request_handle reqh;
+ohci_device_intr_done(xfer)
+ usbd_xfer_handle xfer;
{
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
ohci_softc_t *sc = (ohci_softc_t *)opipe->pipe.device->bus;
ohci_soft_ed_t *sed = opipe->sed;
- ohci_soft_td_t *xfer, *tail;
+ ohci_soft_td_t *data, *tail;
- DPRINTFN(10,("ohci_intr_done: reqh=%p, actlen=%d\n",
- reqh, reqh->actlen));
+ DPRINTFN(10,("ohci_intr_done: xfer=%p, actlen=%d\n",
+ xfer, xfer->actlen));
- reqh->hcpriv = 0;
+ xfer->hcpriv = NULL;
- if (reqh->pipe->repeat) {
- xfer = opipe->tail;
+ if (xfer->pipe->repeat) {
+ data = opipe->tail;
tail = ohci_alloc_std(sc); /* XXX should reuse TD */
- if (!tail) {
- reqh->status = USBD_NOMEM;
+ if (tail == NULL) {
+ xfer->status = USBD_NOMEM;
return;
}
- tail->reqh = 0;
+ tail->xfer = NULL;
- xfer->td.td_flags = LE(
+ data->td.td_flags = LE(
OHCI_TD_IN | OHCI_TD_NOCC |
OHCI_TD_SET_DI(1) | OHCI_TD_TOGGLE_CARRY);
- if (reqh->flags & USBD_SHORT_XFER_OK)
- xfer->td.td_flags |= LE(OHCI_TD_R);
- xfer->td.td_cbp = LE(DMAADDR(&reqh->dmabuf));
- xfer->nexttd = tail;
- xfer->td.td_nexttd = LE(tail->physaddr);
- xfer->td.td_be = LE(LE(xfer->td.td_cbp) + reqh->length - 1);
- xfer->len = reqh->length;
- xfer->reqh = reqh;
- xfer->flags = OHCI_CALL_DONE | OHCI_SET_LEN;
- reqh->hcpriv = xfer;
-
- ohci_hash_add_td(sc, xfer);
+ if (xfer->flags & USBD_SHORT_XFER_OK)
+ data->td.td_flags |= LE(OHCI_TD_R);
+ data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->nexttd = tail;
+ data->td.td_nexttd = LE(tail->physaddr);
+ data->td.td_be = LE(LE(data->td.td_cbp) + xfer->length - 1);
+ data->len = xfer->length;
+ data->xfer = xfer;
+ data->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
+ xfer->hcpriv = data;
+ xfer->actlen = 0;
+
+ ohci_hash_add_td(sc, data);
sed->ed.ed_tailp = LE(tail->physaddr);
opipe->tail = tail;
}
}
void
-ohci_device_bulk_done(reqh)
- usbd_request_handle reqh;
+ohci_device_bulk_done(xfer)
+ usbd_xfer_handle xfer;
{
- DPRINTFN(10,("ohci_bulk_done: reqh=%p, actlen=%d\n",
- reqh, reqh->actlen));
+ DPRINTFN(10,("ohci_bulk_done: xfer=%p, actlen=%d\n",
+ xfer, xfer->actlen));
- reqh->hcpriv = 0;
+ xfer->hcpriv = NULL;
}
void
-ohci_rhsc(sc, reqh)
+ohci_rhsc(sc, xfer)
ohci_softc_t *sc;
- usbd_request_handle reqh;
+ usbd_xfer_handle xfer;
{
usbd_pipe_handle pipe;
struct ohci_pipe *opipe;
@@ -924,36 +1082,36 @@ ohci_rhsc(sc, reqh)
int hstatus;
hstatus = OREAD4(sc, OHCI_RH_STATUS);
- DPRINTF(("ohci_rhsc: sc=%p reqh=%p hstatus=0x%08x\n",
- sc, reqh, hstatus));
+ DPRINTF(("ohci_rhsc: sc=%p xfer=%p hstatus=0x%08x\n",
+ sc, xfer, hstatus));
- if (reqh == 0) {
+ if (xfer == NULL) {
/* Just ignore the change. */
return;
}
- pipe = reqh->pipe;
+ pipe = xfer->pipe;
opipe = (struct ohci_pipe *)pipe;
- p = KERNADDR(&reqh->dmabuf);
- m = min(sc->sc_noport, reqh->length * 8 - 1);
- memset(p, 0, reqh->length);
+ p = KERNADDR(&xfer->dmabuf);
+ m = min(sc->sc_noport, xfer->length * 8 - 1);
+ memset(p, 0, xfer->length);
for (i = 1; i <= m; i++) {
if (OREAD4(sc, OHCI_RH_PORT_STATUS(i)) >> 16)
p[i/8] |= 1 << (i%8);
}
DPRINTF(("ohci_rhsc: change=0x%02x\n", *p));
- reqh->actlen = reqh->length;
- reqh->status = USBD_NORMAL_COMPLETION;
+ xfer->actlen = xfer->length;
+ xfer->status = USBD_NORMAL_COMPLETION;
- usb_transfer_complete(reqh);
+ usb_transfer_complete(xfer);
}
void
-ohci_root_intr_done(reqh)
- usbd_request_handle reqh;
+ohci_root_intr_done(xfer)
+ usbd_xfer_handle xfer;
{
- reqh->hcpriv = 0;
+ xfer->hcpriv = NULL;
}
/*
@@ -962,15 +1120,15 @@ ohci_root_intr_done(reqh)
* too long.
*/
void
-ohci_waitintr(sc, reqh)
+ohci_waitintr(sc, xfer)
ohci_softc_t *sc;
- usbd_request_handle reqh;
+ usbd_xfer_handle xfer;
{
- int timo = reqh->timeout;
+ int timo = xfer->timeout;
int usecs;
u_int32_t intrs;
- reqh->status = USBD_IN_PROGRESS;
+ xfer->status = USBD_IN_PROGRESS;
for (usecs = timo * 1000000 / hz; usecs > 0; usecs -= 1000) {
usb_delay_ms(&sc->sc_bus, 1);
intrs = OREAD4(sc, OHCI_INTERRUPT_STATUS) & sc->sc_eintrs;
@@ -980,16 +1138,16 @@ ohci_waitintr(sc, reqh)
ohci_dumpregs(sc);
#endif
if (intrs) {
- ohci_intr(sc);
- if (reqh->status != USBD_IN_PROGRESS)
+ ohci_intr1(sc);
+ if (xfer->status != USBD_IN_PROGRESS)
return;
}
}
/* Timeout */
DPRINTF(("ohci_waitintr: timeout\n"));
- reqh->status = USBD_TIMEOUT;
- usb_transfer_complete(reqh);
+ xfer->status = USBD_TIMEOUT;
+ usb_transfer_complete(xfer);
/* XXX should free TD */
}
@@ -1000,23 +1158,23 @@ ohci_poll(bus)
ohci_softc_t *sc = (ohci_softc_t *)bus;
if (OREAD4(sc, OHCI_INTERRUPT_STATUS) & sc->sc_eintrs)
- ohci_intr(sc);
+ ohci_intr1(sc);
}
usbd_status
-ohci_device_request(reqh)
- usbd_request_handle reqh;
+ohci_device_request(xfer)
+ usbd_xfer_handle xfer;
{
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
- usb_device_request_t *req = &reqh->request;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
+ usb_device_request_t *req = &xfer->request;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = (ohci_softc_t *)dev->bus;
int addr = dev->address;
- ohci_soft_td_t *setup, *xfer = 0, *stat, *next, *tail;
+ ohci_soft_td_t *setup, *data = 0, *stat, *next, *tail;
ohci_soft_ed_t *sed;
int isread;
int len;
- usbd_status r;
+ usbd_status err;
int s;
isread = req->bmRequestType & UT_READ;
@@ -1030,16 +1188,16 @@ ohci_device_request(reqh)
setup = opipe->tail;
stat = ohci_alloc_std(sc);
- if (!stat) {
- r = USBD_NOMEM;
+ if (stat == NULL) {
+ err = USBD_NOMEM;
goto bad1;
}
tail = ohci_alloc_std(sc);
- if (!tail) {
- r = USBD_NOMEM;
+ if (tail == NULL) {
+ err = USBD_NOMEM;
goto bad2;
}
- tail->reqh = 0;
+ tail->xfer = NULL;
sed = opipe->sed;
opipe->u.ctl.length = len;
@@ -1053,28 +1211,29 @@ ohci_device_request(reqh)
/* Set up data transaction */
if (len != 0) {
- xfer = ohci_alloc_std(sc);
- if (!xfer) {
- r = USBD_NOMEM;
+ data = ohci_alloc_std(sc);
+ if (data == NULL) {
+ err = USBD_NOMEM;
goto bad3;
}
- xfer->td.td_flags = LE(
+ data->td.td_flags = LE(
(isread ? OHCI_TD_IN : OHCI_TD_OUT) | OHCI_TD_NOCC |
OHCI_TD_TOGGLE_1 | OHCI_TD_NOINTR |
- (reqh->flags & USBD_SHORT_XFER_OK ? OHCI_TD_R : 0));
- xfer->td.td_cbp = LE(DMAADDR(&reqh->dmabuf));
- xfer->nexttd = stat;
- xfer->td.td_nexttd = LE(stat->physaddr);
- xfer->td.td_be = LE(LE(xfer->td.td_cbp) + len - 1);
- xfer->len = len;
- xfer->reqh = reqh;
- xfer->flags = OHCI_SET_LEN;
-
- next = xfer;
+ (xfer->flags & USBD_SHORT_XFER_OK ? OHCI_TD_R : 0));
+ data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->nexttd = stat;
+ data->td.td_nexttd = LE(stat->physaddr);
+ data->td.td_be = LE(LE(data->td.td_cbp) + len - 1);
+ data->len = len;
+ data->xfer = xfer;
+ data->flags = OHCI_ADD_LEN;
+
+ next = data;
stat->flags = OHCI_CALL_DONE;
} else {
next = stat;
- stat->flags = OHCI_CALL_DONE | OHCI_SET_LEN;
+ /* XXX ADD_LEN? */
+ stat->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
}
memcpy(KERNADDR(&opipe->u.ctl.reqdma), req, sizeof *req);
@@ -1086,9 +1245,9 @@ ohci_device_request(reqh)
setup->td.td_nexttd = LE(next->physaddr);
setup->td.td_be = LE(LE(setup->td.td_cbp) + sizeof *req - 1);
setup->len = 0; /* XXX The number of byte we count */
- setup->reqh = reqh;
+ setup->xfer = xfer;
setup->flags = 0;
- reqh->hcpriv = setup;
+ xfer->hcpriv = setup;
stat->td.td_flags = LE(
(isread ? OHCI_TD_OUT : OHCI_TD_IN) | OHCI_TD_NOCC |
@@ -1098,7 +1257,7 @@ ohci_device_request(reqh)
stat->td.td_nexttd = LE(tail->physaddr);
stat->td.td_be = 0;
stat->len = 0;
- stat->reqh = reqh;
+ stat->xfer = xfer;
#ifdef OHCI_DEBUG
if (ohcidebug > 5) {
@@ -1112,31 +1271,26 @@ ohci_device_request(reqh)
s = splusb();
ohci_hash_add_td(sc, setup);
if (len != 0)
- ohci_hash_add_td(sc, xfer);
+ ohci_hash_add_td(sc, data);
ohci_hash_add_td(sc, stat);
sed->ed.ed_tailp = LE(tail->physaddr);
opipe->tail = tail;
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
- if (reqh->timeout && !sc->sc_bus.use_polling) {
- usb_timeout(ohci_timeout, reqh,
- MS_TO_TICKS(reqh->timeout), reqh->timo_handle);
+ if (xfer->timeout && !sc->sc_bus.use_polling) {
+ usb_timeout(ohci_timeout, xfer,
+ MS_TO_TICKS(xfer->timeout), xfer->timo_handle);
}
splx(s);
-#if 0
- This goes horribly wrong, printing thousands of descriptors,
- because false references are followed due to the fact that the
- TD is gone.
#ifdef OHCI_DEBUG
if (ohcidebug > 5) {
- delay(5000);
+ usb_delay_ms(&sc->sc_bus, 5);
DPRINTF(("ohci_device_request: status=%x\n",
OREAD4(sc, OHCI_COMMAND_STATUS)));
ohci_dump_ed(sed);
ohci_dump_tds(setup);
}
#endif
-#endif
return (USBD_NORMAL_COMPLETION);
@@ -1145,7 +1299,7 @@ ohci_device_request(reqh)
bad2:
ohci_free_std(sc, stat);
bad1:
- return (r);
+ return (err);
}
/*
@@ -1156,6 +1310,7 @@ ohci_add_ed(sed, head)
ohci_soft_ed_t *sed;
ohci_soft_ed_t *head;
{
+ SPLUSBCHECK;
sed->next = head->next;
sed->ed.ed_nexted = head->ed.ed_nexted;
head->next = sed;
@@ -1172,10 +1327,12 @@ ohci_rem_ed(sed, head)
{
ohci_soft_ed_t *p;
+ SPLUSBCHECK;
+
/* XXX */
- for (p = head; p && p->next != sed; p = p->next)
+ for (p = head; p == NULL && p->next != sed; p = p->next)
;
- if (!p)
+ if (p == NULL)
panic("ohci_rem_ed: ED not found\n");
p->next = sed->next;
p->ed.ed_nexted = sed->ed.ed_nexted;
@@ -1200,6 +1357,8 @@ ohci_hash_add_td(sc, std)
{
int h = HASH(std->physaddr);
+ SPLUSBCHECK;
+
LIST_INSERT_HEAD(&sc->sc_hash_tds[h], std, hnext);
}
@@ -1209,6 +1368,8 @@ ohci_hash_rem_td(sc, std)
ohci_softc_t *sc;
ohci_soft_td_t *std;
{
+ SPLUSBCHECK;
+
LIST_REMOVE(std, hnext);
}
@@ -1221,7 +1382,7 @@ ohci_hash_find_td(sc, a)
ohci_soft_td_t *std;
for (std = LIST_FIRST(&sc->sc_hash_tds[h]);
- std != 0;
+ std != NULL;
std = LIST_NEXT(std, hnext))
if (std->physaddr == a)
return (std);
@@ -1232,10 +1393,16 @@ void
ohci_timeout(addr)
void *addr;
{
- usbd_request_handle reqh = addr;
+ usbd_xfer_handle xfer = addr;
+ int s;
+
+ DPRINTF(("ohci_timeout: xfer=%p\n", xfer));
- DPRINTF(("ohci_timeout: reqh=%p\n", reqh));
- ohci_abort_req(reqh, USBD_TIMEOUT);
+ s = splusb();
+ xfer->device->bus->intr_context++;
+ ohci_abort_req(xfer, USBD_TIMEOUT);
+ xfer->device->bus->intr_context--;
+ splx(s);
}
#ifdef OHCI_DEBUG
@@ -1276,7 +1443,7 @@ ohci_dump_ed(sed)
(int)LE(sed->ed.ed_flags),
"\20\14OUT\15IN\16LOWSPEED\17SKIP\20ISO",
(u_long)LE(sed->ed.ed_tailp),
- (int)LE(sed->ed.ed_headp),
+ (u_long)LE(sed->ed.ed_headp),
"\20\1HALT\2CARRY",
(u_long)LE(sed->ed.ed_nexted)));
}
@@ -1293,7 +1460,7 @@ ohci_open(pipe)
u_int8_t addr = dev->address;
ohci_soft_ed_t *sed;
ohci_soft_td_t *std;
- usbd_status r;
+ usbd_status err;
int s;
DPRINTFN(1, ("ohci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
@@ -1311,10 +1478,10 @@ ohci_open(pipe)
}
} else {
sed = ohci_alloc_sed(sc);
- if (sed == 0)
+ if (sed == NULL)
goto bad0;
std = ohci_alloc_std(sc);
- if (std == 0)
+ if (std == NULL)
goto bad1;
opipe->sed = sed;
opipe->tail = std;
@@ -1331,10 +1498,10 @@ ohci_open(pipe)
switch (ed->bmAttributes & UE_XFERTYPE) {
case UE_CONTROL:
pipe->methods = &ohci_device_ctrl_methods;
- r = usb_allocmem(sc->sc_dmatag,
- sizeof(usb_device_request_t),
- 0, &opipe->u.ctl.reqdma);
- if (r != USBD_NORMAL_COMPLETION)
+ err = usb_allocmem(&sc->sc_bus,
+ sizeof(usb_device_request_t),
+ 0, &opipe->u.ctl.reqdma);
+ if (err)
goto bad;
s = splusb();
ohci_add_ed(sed, sc->sc_ctrl_head);
@@ -1387,7 +1554,7 @@ ohci_close_pipe(pipe, head)
ohci_physaddr_t td = sed->ed.ed_headp;
ohci_soft_td_t *std;
for (std = LIST_FIRST(&sc->sc_hash_tds[HASH(td)]);
- std != 0;
+ std != NULL;
std = LIST_NEXT(std, hnext))
if (std->physaddr == td)
break;
@@ -1418,28 +1585,33 @@ ohci_close_pipe(pipe, head)
* interrupt processing to process it.
*/
void
-ohci_abort_req(reqh, status)
- usbd_request_handle reqh;
+ohci_abort_req(xfer, status)
+ usbd_xfer_handle xfer;
usbd_status status;
{
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
ohci_soft_ed_t *sed;
- DPRINTF(("ohci_abort_req: reqh=%p pipe=%p\n", reqh, opipe));
+ DPRINTF(("ohci_abort_req: xfer=%p pipe=%p\n", xfer, opipe));
- reqh->status = status;
+ xfer->status = status;
- usb_untimeout(ohci_timeout, reqh, reqh->timo_handle);
+ usb_untimeout(ohci_timeout, xfer, xfer->timo_handle);
sed = opipe->sed;
DPRINTFN(1,("ohci_abort_req: stop ed=%p\n", sed));
sed->ed.ed_flags |= LE(OHCI_ED_SKIP); /* force hardware skip */
- if (curproc) {
- usb_delay_ms(opipe->pipe.device->bus, 1);
- ohci_abort_req_end(reqh);
+ if (xfer->device->bus->intr_context) {
+ /* We have no process context, so we can't use tsleep(). */
+ timeout(ohci_abort_req_end, xfer, hz / USB_FRAMES_PER_SECOND);
} else {
- timeout(ohci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+#if defined(DIAGNOSTIC) && defined(__i386__)
+ KASSERT(intr_nesting_level == 0,
+ ("ohci_abort_req in interrupt context"));
+#endif
+ usb_delay_ms(opipe->pipe.device->bus, 1);
+ ohci_abort_req_end(xfer);
}
}
@@ -1447,8 +1619,8 @@ void
ohci_abort_req_end(v)
void *v;
{
- usbd_request_handle reqh = v;
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
+ usbd_xfer_handle xfer = v;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
ohci_softc_t *sc = (ohci_softc_t *)opipe->pipe.device->bus;
ohci_soft_ed_t *sed;
ohci_soft_td_t *p, *n;
@@ -1456,14 +1628,14 @@ ohci_abort_req_end(v)
s = splusb();
- p = reqh->hcpriv;
+ p = xfer->hcpriv;
#ifdef DIAGNOSTIC
- if (!p) {
+ if (p == NULL) {
printf("ohci_abort_req: hcpriv==0\n");
return;
}
#endif
- for (; p->reqh == reqh; p = n) {
+ for (; p->xfer == xfer; p = n) {
n = p->nexttd;
ohci_hash_rem_td(sc, p);
ohci_free_std(sc, p);
@@ -1475,7 +1647,7 @@ ohci_abort_req_end(v)
sed->ed.ed_headp = p->physaddr; /* unlink TDs */
sed->ed.ed_flags &= LE(~OHCI_ED_SKIP); /* remove hardware skip */
- usb_transfer_complete(reqh);
+ usb_transfer_complete(xfer);
splx(s);
}
@@ -1483,7 +1655,7 @@ ohci_abort_req_end(v)
/*
* Data structures and routines to emulate the root hub.
*/
-usb_device_descriptor_t ohci_devd = {
+static usb_device_descriptor_t ohci_devd = {
USB_DEVICE_DESCRIPTOR_SIZE,
UDESC_DEVICE, /* type */
{0x00, 0x01}, /* USB version */
@@ -1496,7 +1668,7 @@ usb_device_descriptor_t ohci_devd = {
1 /* # of configurations */
};
-usb_config_descriptor_t ohci_confd = {
+static usb_config_descriptor_t ohci_confd = {
USB_CONFIG_DESCRIPTOR_SIZE,
UDESC_CONFIG,
{USB_CONFIG_DESCRIPTOR_SIZE +
@@ -1509,7 +1681,7 @@ usb_config_descriptor_t ohci_confd = {
0 /* max power */
};
-usb_interface_descriptor_t ohci_ifcd = {
+static usb_interface_descriptor_t ohci_ifcd = {
USB_INTERFACE_DESCRIPTOR_SIZE,
UDESC_INTERFACE,
0,
@@ -1521,7 +1693,7 @@ usb_interface_descriptor_t ohci_ifcd = {
0
};
-usb_endpoint_descriptor_t ohci_endpd = {
+static usb_endpoint_descriptor_t ohci_endpd = {
USB_ENDPOINT_DESCRIPTOR_SIZE,
UDESC_ENDPOINT,
UE_DIR_IN | OHCI_INTR_ENDPT,
@@ -1530,7 +1702,7 @@ usb_endpoint_descriptor_t ohci_endpd = {
255
};
-usb_hub_descriptor_t ohci_hubd = {
+static usb_hub_descriptor_t ohci_hubd = {
USB_HUB_DESCRIPTOR_SIZE,
UDESC_HUB,
0,
@@ -1540,7 +1712,7 @@ usb_hub_descriptor_t ohci_hubd = {
{0},
};
-int
+static int
ohci_str(p, l, s)
usb_string_descriptor_t *p;
int l;
@@ -1563,39 +1735,41 @@ ohci_str(p, l, s)
/*
* Simulate a hardware hub by handling all the necessary requests.
*/
-usbd_status
-ohci_root_ctrl_transfer(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_root_ctrl_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
+
+ /* Insert last in queue. */
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
- else
- return (ohci_root_ctrl_start(reqh));
+ /* Pipe isn't running, start first */
+ return (ohci_root_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
-usbd_status
-ohci_root_ctrl_start(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_root_ctrl_start(xfer)
+ usbd_xfer_handle xfer;
{
- ohci_softc_t *sc = (ohci_softc_t *)reqh->pipe->device->bus;
+ ohci_softc_t *sc = (ohci_softc_t *)xfer->pipe->device->bus;
usb_device_request_t *req;
void *buf = NULL;
int port, i;
- int len, value, index, l, totlen = 0;
+ int s, len, value, index, l, totlen = 0;
usb_port_status_t ps;
usb_hub_descriptor_t hubd;
- usbd_status r;
+ usbd_status err;
u_int32_t v;
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST))
+ if (!(xfer->rqflags & URQ_REQUEST))
/* XXX panic */
return (USBD_INVAL);
#endif
- req = &reqh->request;
+ req = &xfer->request;
DPRINTFN(4,("ohci_root_ctrl_control type=0x%02x request=%02x\n",
req->bmRequestType, req->bRequest));
@@ -1605,7 +1779,7 @@ ohci_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)) {
@@ -1628,7 +1802,7 @@ ohci_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);
@@ -1637,7 +1811,7 @@ ohci_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);
@@ -1668,7 +1842,7 @@ ohci_root_ctrl_start(reqh)
}
break;
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
break;
@@ -1693,14 +1867,14 @@ ohci_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;
@@ -1710,7 +1884,7 @@ ohci_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;
@@ -1724,7 +1898,7 @@ ohci_root_ctrl_start(reqh)
"port=%d feature=%d\n",
index, value));
if (index < 1 || index > sc->sc_noport) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
port = OHCI_RH_PORT_STATUS(index);
@@ -1754,7 +1928,7 @@ ohci_root_ctrl_start(reqh)
OWRITE4(sc, port, UPS_C_PORT_RESET << 16);
break;
default:
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
switch(value) {
@@ -1773,7 +1947,7 @@ ohci_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;
}
v = OREAD4(sc, OHCI_RH_DESCRIPTOR_A);
@@ -1795,7 +1969,7 @@ ohci_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); /* ? XXX */
@@ -1805,11 +1979,11 @@ ohci_root_ctrl_start(reqh)
DPRINTFN(8,("ohci_root_ctrl_transfer: get port status i=%d\n",
index));
if (index < 1 || index > sc->sc_noport) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
if (len != 4) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
v = OREAD4(sc, OHCI_RH_PORT_STATUS(index));
@@ -1822,13 +1996,13 @@ ohci_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;
case C(UR_SET_FEATURE, UT_WRITE_CLASS_OTHER):
if (index < 1 || index > sc->sc_noport) {
- r = USBD_IOERROR;
+ err = USBD_IOERROR;
goto ret;
}
port = OHCI_RH_PORT_STATUS(index);
@@ -1857,32 +2031,34 @@ ohci_root_ctrl_start(reqh)
OWRITE4(sc, port, UPS_PORT_POWER);
break;
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;
- usb_transfer_complete(reqh);
+ xfer->status = err;
+ s = splusb();
+ usb_transfer_complete(xfer);
+ splx(s);
return (USBD_IN_PROGRESS);
}
/* Abort a root control request. */
-void
-ohci_root_ctrl_abort(reqh)
- usbd_request_handle reqh;
+static void
+ohci_root_ctrl_abort(xfer)
+ usbd_xfer_handle xfer;
{
/* Nothing to do, all transfers are synchronous. */
}
/* Close the root pipe. */
-void
+static void
ohci_root_ctrl_close(pipe)
usbd_pipe_handle pipe;
{
@@ -1890,41 +2066,52 @@ ohci_root_ctrl_close(pipe)
/* Nothing to do. */
}
-usbd_status
-ohci_root_intr_transfer(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_root_intr_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
+
+ /* Insert last in queue. */
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
- else
- return (ohci_root_intr_start(reqh));
+ /* Pipe isn't running, start first */
+ return (ohci_root_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
-usbd_status
-ohci_root_intr_start(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_root_intr_start(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_pipe_handle pipe = reqh->pipe;
+ usbd_pipe_handle pipe = xfer->pipe;
ohci_softc_t *sc = (ohci_softc_t *)pipe->device->bus;
- sc->sc_intrreqh = reqh;
+ sc->sc_intrxfer = xfer;
return (USBD_IN_PROGRESS);
}
/* Abort a root interrupt request. */
-void
-ohci_root_intr_abort(reqh)
- usbd_request_handle reqh;
+static void
+ohci_root_intr_abort(xfer)
+ usbd_xfer_handle xfer;
{
- /* No need to abort. */
+ int s;
+
+ if (xfer->pipe->intrxfer == xfer) {
+ DPRINTF(("ohci_root_intr_abort: remove\n"));
+ xfer->pipe->intrxfer = NULL;
+ }
+ xfer->status = USBD_CANCELLED;
+ s = splusb();
+ usb_transfer_complete(xfer);
+ splx(s);
}
/* Close the root pipe. */
-void
+static void
ohci_root_intr_close(pipe)
usbd_pipe_handle pipe;
{
@@ -1932,59 +2119,61 @@ ohci_root_intr_close(pipe)
DPRINTF(("ohci_root_intr_close\n"));
- sc->sc_intrreqh = 0;
+ sc->sc_intrxfer = NULL;
}
/************************/
-usbd_status
-ohci_device_ctrl_transfer(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_ctrl_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
- else
- return (ohci_device_ctrl_start(reqh));
+ /* Insert last in queue. */
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
+
+ /* Pipe isn't running, start first */
+ return (ohci_device_ctrl_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
-usbd_status
-ohci_device_ctrl_start(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_ctrl_start(xfer)
+ usbd_xfer_handle xfer;
{
- ohci_softc_t *sc = (ohci_softc_t *)reqh->pipe->device->bus;
- usbd_status r;
+ ohci_softc_t *sc = (ohci_softc_t *)xfer->pipe->device->bus;
+ usbd_status err;
#ifdef DIAGNOSTIC
- if (!(reqh->rqflags & URQ_REQUEST)) {
+ if (!(xfer->rqflags & URQ_REQUEST)) {
/* XXX panic */
printf("ohci_device_ctrl_transfer: not a request\n");
return (USBD_INVAL);
}
#endif
- r = ohci_device_request(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
+ err = ohci_device_request(xfer);
+ if (err)
+ return (err);
if (sc->sc_bus.use_polling)
- ohci_waitintr(sc, reqh);
+ ohci_waitintr(sc, xfer);
return (USBD_IN_PROGRESS);
}
/* Abort a device control request. */
-void
-ohci_device_ctrl_abort(reqh)
- usbd_request_handle reqh;
+static void
+ohci_device_ctrl_abort(xfer)
+ usbd_xfer_handle xfer;
{
- DPRINTF(("ohci_device_ctrl_abort: reqh=%p\n", reqh));
- ohci_abort_req(reqh, USBD_CANCELLED);
+ DPRINTF(("ohci_device_ctrl_abort: xfer=%p\n", xfer));
+ ohci_abort_req(xfer, USBD_CANCELLED);
}
/* Close a device control pipe. */
-void
+static void
ohci_device_ctrl_close(pipe)
usbd_pipe_handle pipe;
{
@@ -1996,7 +2185,7 @@ ohci_device_ctrl_close(pipe)
/************************/
-void
+static void
ohci_device_clear_toggle(pipe)
usbd_pipe_handle pipe;
{
@@ -2005,113 +2194,111 @@ ohci_device_clear_toggle(pipe)
opipe->sed->ed.ed_tailp &= LE(~OHCI_TOGGLECARRY);
}
-void
+static void
ohci_noop(pipe)
usbd_pipe_handle pipe;
{
}
-usbd_status
-ohci_device_bulk_transfer(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_bulk_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
- else
- return (ohci_device_bulk_start(reqh));
+ /* Insert last in queue. */
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
+
+ /* Pipe isn't running, start first */
+ return (ohci_device_bulk_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
-usbd_status
-ohci_device_bulk_start(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_bulk_start(xfer)
+ usbd_xfer_handle xfer;
{
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = (ohci_softc_t *)dev->bus;
int addr = dev->address;
- ohci_soft_td_t *xfer, *tail;
+ ohci_soft_td_t *data, *tail, *tdp;
ohci_soft_ed_t *sed;
int s, len, isread, endpt;
+ usbd_status err;
#ifdef DIAGNOSTIC
- if (reqh->rqflags & URQ_REQUEST) {
+ if (xfer->rqflags & URQ_REQUEST) {
/* XXX panic */
printf("ohci_device_bulk_start: a request\n");
return (USBD_INVAL);
}
#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;
sed = opipe->sed;
- DPRINTFN(4,("ohci_device_bulk_start: reqh=%p len=%d isread=%d "
- "flags=%d endpt=%d\n", reqh, len, isread, reqh->flags,
+ DPRINTFN(4,("ohci_device_bulk_start: xfer=%p len=%d isread=%d "
+ "flags=%d endpt=%d\n", xfer, len, isread, xfer->flags,
endpt));
opipe->u.bulk.isread = isread;
opipe->u.bulk.length = len;
- tail = ohci_alloc_std(sc);
- if (!tail)
- return (USBD_NOMEM);
- tail->reqh = 0;
-
/* Update device address */
sed->ed.ed_flags = LE(
(LE(sed->ed.ed_flags) & ~OHCI_ED_ADDRMASK) |
OHCI_ED_SET_FA(addr));
- /* Set up data transaction */
- xfer = opipe->tail;
- xfer->td.td_flags = LE(
- (isread ? OHCI_TD_IN : OHCI_TD_OUT) | OHCI_TD_NOCC |
- OHCI_TD_SET_DI(1) | OHCI_TD_TOGGLE_CARRY |
- (reqh->flags & USBD_SHORT_XFER_OK ? OHCI_TD_R : 0));
- xfer->td.td_cbp = LE(DMAADDR(&reqh->dmabuf));
- xfer->nexttd = tail;
- xfer->td.td_nexttd = LE(tail->physaddr);
- xfer->td.td_be = LE(LE(xfer->td.td_cbp) + len - 1);
- xfer->len = len;
- xfer->reqh = reqh;
- xfer->flags = OHCI_CALL_DONE | OHCI_SET_LEN;
- reqh->hcpriv = xfer;
+ /* Allocate a chain of new TDs (including a new tail). */
+ data = opipe->tail;
+ err = ohci_alloc_std_chain(opipe, sc, len, isread,
+ xfer->flags & USBD_SHORT_XFER_OK,
+ &xfer->dmabuf, data, &tail);
+ if (err)
+ return (err);
+
+ tail->xfer = NULL;
+ xfer->hcpriv = data;
DPRINTFN(4,("ohci_device_bulk_start: ed_flags=0x%08x td_flags=0x%08x "
"td_cbp=0x%08x td_be=0x%08x\n",
- (int)LE(sed->ed.ed_flags), (int)LE(xfer->td.td_flags),
- (int)LE(xfer->td.td_cbp), (int)LE(xfer->td.td_be)));
+ (int)LE(sed->ed.ed_flags), (int)LE(data->td.td_flags),
+ (int)LE(data->td.td_cbp), (int)LE(data->td.td_be)));
#ifdef OHCI_DEBUG
if (ohcidebug > 4) {
ohci_dump_ed(sed);
- ohci_dump_tds(xfer);
+ ohci_dump_tds(data);
}
#endif
/* Insert ED in schedule */
s = splusb();
- ohci_hash_add_td(sc, xfer);
+ for (tdp = data; tdp != tail; tdp = tdp->nexttd) {
+ tdp->xfer = xfer;
+ ohci_hash_add_td(sc, tdp);
+ }
sed->ed.ed_tailp = LE(tail->physaddr);
opipe->tail = tail;
sed->ed.ed_flags &= LE(~OHCI_ED_SKIP);
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_BLF);
- if (reqh->timeout && !sc->sc_bus.use_polling) {
- usb_timeout(ohci_timeout, reqh,
- MS_TO_TICKS(reqh->timeout), reqh->timo_handle);
+ if (xfer->timeout && !sc->sc_bus.use_polling) {
+ usb_timeout(ohci_timeout, xfer,
+ MS_TO_TICKS(xfer->timeout), xfer->timo_handle);
}
-#ifdef OHCI_DEBUG
+#if 0
+/* This goes wrong if we are too slow. */
if (ohcidebug > 5) {
- delay(5000);
+ usb_delay_ms(&sc->sc_bus, 5);
DPRINTF(("ohci_device_intr_transfer: status=%x\n",
OREAD4(sc, OHCI_COMMAND_STATUS)));
ohci_dump_ed(sed);
- ohci_dump_tds(xfer);
+ ohci_dump_tds(data);
}
#endif
@@ -2120,18 +2307,18 @@ ohci_device_bulk_start(reqh)
return (USBD_IN_PROGRESS);
}
-void
-ohci_device_bulk_abort(reqh)
- usbd_request_handle reqh;
+static void
+ohci_device_bulk_abort(xfer)
+ usbd_xfer_handle xfer;
{
- DPRINTF(("ohci_device_bulk_abort: reqh=%p\n", reqh));
- ohci_abort_req(reqh, USBD_CANCELLED);
+ DPRINTF(("ohci_device_bulk_abort: xfer=%p\n", xfer));
+ ohci_abort_req(xfer, USBD_CANCELLED);
}
/*
* Close a device bulk pipe.
*/
-void
+static void
ohci_device_bulk_close(pipe)
usbd_pipe_handle pipe;
{
@@ -2143,108 +2330,112 @@ ohci_device_bulk_close(pipe)
/************************/
-usbd_status
-ohci_device_intr_transfer(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_intr_transfer(xfer)
+ usbd_xfer_handle xfer;
{
- usbd_status r;
+ usbd_status err;
- r = usb_insert_transfer(reqh);
- if (r != USBD_NORMAL_COMPLETION)
- return (r);
- else
- return (ohci_device_intr_start(reqh));
+ /* Insert last in queue. */
+ err = usb_insert_transfer(xfer);
+ if (err)
+ return (err);
+
+ /* Pipe isn't running, start first */
+ return (ohci_device_intr_start(SIMPLEQ_FIRST(&xfer->pipe->queue)));
}
-usbd_status
-ohci_device_intr_start(reqh)
- usbd_request_handle reqh;
+static usbd_status
+ohci_device_intr_start(xfer)
+ usbd_xfer_handle xfer;
{
- struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
+ struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = (ohci_softc_t *)dev->bus;
ohci_soft_ed_t *sed = opipe->sed;
- ohci_soft_td_t *xfer, *tail;
+ ohci_soft_td_t *data, *tail;
int len;
int s;
- DPRINTFN(3, ("ohci_device_intr_transfer: reqh=%p len=%d "
+ DPRINTFN(3, ("ohci_device_intr_transfer: xfer=%p len=%d "
"flags=%d priv=%p\n",
- reqh, reqh->length, reqh->flags, reqh->priv));
+ xfer, xfer->length, xfer->flags, xfer->priv));
#ifdef DIAGNOSTIC
- if (reqh->rqflags & URQ_REQUEST)
+ if (xfer->rqflags & URQ_REQUEST)
panic("ohci_device_intr_transfer: a request\n");
#endif
- len = reqh->length;
+ len = xfer->length;
- xfer = opipe->tail;
+ data = opipe->tail;
tail = ohci_alloc_std(sc);
- if (!tail)
+ if (tail == NULL)
return (USBD_NOMEM);
- tail->reqh = 0;
+ tail->xfer = NULL;
- xfer->td.td_flags = LE(
+ data->td.td_flags = LE(
OHCI_TD_IN | OHCI_TD_NOCC |
OHCI_TD_SET_DI(1) | OHCI_TD_TOGGLE_CARRY);
- if (reqh->flags & USBD_SHORT_XFER_OK)
- xfer->td.td_flags |= LE(OHCI_TD_R);
- xfer->td.td_cbp = LE(DMAADDR(&reqh->dmabuf));
- xfer->nexttd = tail;
- xfer->td.td_nexttd = LE(tail->physaddr);
- xfer->td.td_be = LE(LE(xfer->td.td_cbp) + len - 1);
- xfer->len = len;
- xfer->reqh = reqh;
- xfer->flags = OHCI_CALL_DONE | OHCI_SET_LEN;
- reqh->hcpriv = xfer;
+ if (xfer->flags & USBD_SHORT_XFER_OK)
+ data->td.td_flags |= LE(OHCI_TD_R);
+ data->td.td_cbp = LE(DMAADDR(&xfer->dmabuf));
+ data->nexttd = tail;
+ data->td.td_nexttd = LE(tail->physaddr);
+ data->td.td_be = LE(LE(data->td.td_cbp) + len - 1);
+ data->len = len;
+ data->xfer = xfer;
+ data->flags = OHCI_CALL_DONE | OHCI_ADD_LEN;
+ xfer->hcpriv = data;
#ifdef OHCI_DEBUG
if (ohcidebug > 5) {
DPRINTF(("ohci_device_intr_transfer:\n"));
ohci_dump_ed(sed);
- ohci_dump_tds(xfer);
+ ohci_dump_tds(data);
}
#endif
/* Insert ED in schedule */
s = splusb();
- ohci_hash_add_td(sc, xfer);
+ ohci_hash_add_td(sc, data);
sed->ed.ed_tailp = LE(tail->physaddr);
opipe->tail = tail;
sed->ed.ed_flags &= LE(~OHCI_ED_SKIP);
#if 0
- this goes wrong if we are too slow with dumping the TDs
-#ifdef OHCI_DEBUG
+/*
+ * This goes horribly wrong, printing thousands of descriptors,
+ * because false references are followed due to the fact that the
+ * TD is gone.
+ */
if (ohcidebug > 5) {
- delay(5000);
+ usb_delay_ms(&sc->sc_bus, 5);
DPRINTF(("ohci_device_intr_transfer: status=%x\n",
OREAD4(sc, OHCI_COMMAND_STATUS)));
ohci_dump_ed(sed);
- ohci_dump_tds(xfer);
+ ohci_dump_tds(data);
}
#endif
-#endif
splx(s);
return (USBD_IN_PROGRESS);
}
/* Abort a device control request. */
-void
-ohci_device_intr_abort(reqh)
- usbd_request_handle reqh;
+static void
+ohci_device_intr_abort(xfer)
+ usbd_xfer_handle xfer;
{
- if (reqh->pipe->intrreqh == reqh) {
+ if (xfer->pipe->intrxfer == xfer) {
DPRINTF(("ohci_device_intr_abort: remove\n"));
- reqh->pipe->intrreqh = 0;
+ xfer->pipe->intrxfer = NULL;
}
- ohci_abort_req(reqh, USBD_CANCELLED);
+ ohci_abort_req(xfer, USBD_CANCELLED);
}
/* Close a device interrupt pipe. */
-void
+static void
ohci_device_intr_close(pipe)
usbd_pipe_handle pipe;
{
@@ -2266,8 +2457,10 @@ ohci_device_intr_close(pipe)
for (p = sc->sc_eds[pos]; p && p->next != sed; p = p->next)
;
- if (!p)
+#ifdef DIAGNOSTIC
+ if (p == NULL)
panic("ohci_device_intr_close: ED not found\n");
+#endif
p->next = sed->next;
p->ed.ed_nexted = sed->ed.ed_nexted;
splx(s);
@@ -2279,7 +2472,7 @@ ohci_device_intr_close(pipe)
ohci_free_sed(sc, opipe->sed);
}
-usbd_status
+static usbd_status
ohci_device_setintr(sc, opipe, ival)
ohci_softc_t *sc;
struct ohci_pipe *opipe;
@@ -2343,4 +2536,3 @@ ohci_device_setintr(sc, opipe, ival)
DPRINTFN(5, ("ohci_setintr: returns %p\n", opipe));
return (USBD_NORMAL_COMPLETION);
}
-
OpenPOWER on IntegriCloud