summaryrefslogtreecommitdiff
path: root/sys/dev/usb
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/ohci.c98
-rw-r--r--sys/dev/usb/uhci.c345
-rw-r--r--sys/dev/usb/usb_subr.c86
-rw-r--r--sys/dev/usb/usbdi.c66
-rw-r--r--sys/dev/usb/usbdivar.h6
5 files changed, 520 insertions, 81 deletions
diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c
index 6329dc09b57..a1ef621ec12 100644
--- a/sys/dev/usb/ohci.c
+++ b/sys/dev/usb/ohci.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci.c,v 1.16 1998/12/28 12:56:19 augustss Exp $ */
+/* $NetBSD: ohci.c,v 1.17 1998/12/28 20:13:59 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -114,22 +114,27 @@ 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_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));
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));
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));
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));
usbd_status ohci_device_setintr __P((ohci_softc_t *sc,
@@ -196,6 +201,7 @@ struct ohci_pipe {
struct usbd_methods ohci_root_ctrl_methods = {
ohci_root_ctrl_transfer,
+ ohci_root_ctrl_start,
ohci_root_ctrl_abort,
ohci_root_ctrl_close,
0,
@@ -203,6 +209,7 @@ struct usbd_methods ohci_root_ctrl_methods = {
struct usbd_methods ohci_root_intr_methods = {
ohci_root_intr_transfer,
+ ohci_root_intr_start,
ohci_root_intr_abort,
ohci_root_intr_close,
0,
@@ -210,6 +217,7 @@ struct usbd_methods ohci_root_intr_methods = {
struct usbd_methods ohci_device_ctrl_methods = {
ohci_device_ctrl_transfer,
+ ohci_device_ctrl_start,
ohci_device_ctrl_abort,
ohci_device_ctrl_close,
0,
@@ -217,12 +225,14 @@ struct usbd_methods ohci_device_ctrl_methods = {
struct usbd_methods ohci_device_intr_methods = {
ohci_device_intr_transfer,
+ ohci_device_intr_start,
ohci_device_intr_abort,
ohci_device_intr_close,
};
struct usbd_methods ohci_device_bulk_methods = {
ohci_device_bulk_transfer,
+ ohci_device_bulk_start,
ohci_device_bulk_abort,
ohci_device_bulk_close,
0,
@@ -746,15 +756,18 @@ ohci_ii_done(sc, reqh)
switch (reqh->pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE) {
case UE_CONTROL:
ohci_ctrl_done(sc, reqh);
+ usb_start_next(reqh->pipe);
break;
case UE_INTERRUPT:
ohci_intr_done(sc, reqh);
break;
case UE_BULK:
ohci_bulk_done(sc, reqh);
+ usb_start_next(reqh->pipe);
break;
case UE_ISOCHRONOUS:
printf("ohci_process_done: ISO done?\n");
+ usb_start_next(reqh->pipe);
break;
}
@@ -831,6 +844,7 @@ ohci_intr_done(sc, reqh)
opipe->tail = tail;
} else {
usb_freemem(sc->sc_dmatag, dma);
+ usb_start_next(reqh->pipe);
}
}
@@ -891,6 +905,7 @@ ohci_rhsc(sc, reqh)
if (reqh->pipe->intrreqh != reqh) {
sc->sc_intrreqh = 0;
usb_freemem(sc->sc_dmatag, &opipe->u.intr.datadma);
+ usb_start_next(reqh->pipe);
}
}
@@ -1395,6 +1410,22 @@ usbd_status
ohci_root_ctrl_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (ohci_root_ctrl_start(reqh));
+}
+
+usbd_status
+ohci_root_ctrl_start(reqh)
+ usbd_request_handle reqh;
+{
ohci_softc_t *sc = (ohci_softc_t *)reqh->pipe->device->bus;
usb_device_request_t *req;
void *buf;
@@ -1679,6 +1710,7 @@ ohci_root_ctrl_transfer(reqh)
ret:
reqh->status = r;
reqh->xfercb(reqh);
+ usb_start_next(reqh->pipe);
return (USBD_IN_PROGRESS);
}
@@ -1702,6 +1734,22 @@ usbd_status
ohci_root_intr_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (ohci_root_intr_start(reqh));
+}
+
+usbd_status
+ohci_root_intr_start(reqh)
+ usbd_request_handle reqh;
+{
usbd_pipe_handle pipe = reqh->pipe;
ohci_softc_t *sc = (ohci_softc_t *)pipe->device->bus;
struct ohci_pipe *upipe = (struct ohci_pipe *)pipe;
@@ -1747,6 +1795,22 @@ usbd_status
ohci_device_ctrl_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (ohci_device_ctrl_start(reqh));
+}
+
+usbd_status
+ohci_device_ctrl_start(reqh)
+ usbd_request_handle reqh;
+{
ohci_softc_t *sc = (ohci_softc_t *)reqh->pipe->device->bus;
usbd_status r;
@@ -1802,6 +1866,22 @@ usbd_status
ohci_device_bulk_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (ohci_device_bulk_start(reqh));
+}
+
+usbd_status
+ohci_device_bulk_start(reqh)
+ usbd_request_handle reqh;
+{
struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = (ohci_softc_t *)dev->bus;
@@ -1918,6 +1998,22 @@ usbd_status
ohci_device_intr_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (ohci_device_intr_start(reqh));
+}
+
+usbd_status
+ohci_device_intr_start(reqh)
+ usbd_request_handle reqh;
+{
struct ohci_pipe *opipe = (struct ohci_pipe *)reqh->pipe;
usbd_device_handle dev = opipe->pipe.device;
ohci_softc_t *sc = (ohci_softc_t *)dev->bus;
diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c
index 93f43848f08..f93f278c564 100644
--- a/sys/dev/usb/uhci.c
+++ b/sys/dev/usb/uhci.c
@@ -1,4 +1,4 @@
-/* $NetBSD: uhci.c,v 1.15 1998/12/28 16:13:44 augustss Exp $ */
+/* $NetBSD: uhci.c,v 1.16 1998/12/28 20:14:00 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@ struct uhci_pipe {
uhci_soft_qh_t *sqh;
usb_dma_t reqdma;
usb_dma_t datadma;
- uhci_soft_td_t *setup, *stat, *xferend;
+ uhci_soft_td_t *setup, *stat;
u_int length;
} ctl;
/* Interrupt pipe */
@@ -108,6 +108,13 @@ struct uhci_pipe {
u_int length;
int isread;
} bulk;
+ /* Iso pipe */
+ struct iso {
+ u_int bufsize;
+ u_int nbuf;
+ usb_dma_t *bufs;
+ uhci_soft_td_t **stds;
+ } iso;
} u;
};
@@ -118,16 +125,18 @@ struct uhci_pipe {
LIST_HEAD(, uhci_intr_info) uhci_ii_free;
void uhci_busreset __P((uhci_softc_t *));
-void uhci_run __P((uhci_softc_t *, int run));
+usbd_status uhci_run __P((uhci_softc_t *, int run));
uhci_soft_td_t *uhci_alloc_std __P((uhci_softc_t *));
void uhci_free_std __P((uhci_softc_t *, uhci_soft_td_t *));
uhci_soft_qh_t *uhci_alloc_sqh __P((uhci_softc_t *));
void uhci_free_sqh __P((uhci_softc_t *, uhci_soft_qh_t *));
uhci_intr_info_t *uhci_alloc_intr_info __P((uhci_softc_t *));
void uhci_free_intr_info __P((uhci_intr_info_t *ii));
+#if 0
void uhci_enter_ctl_q __P((uhci_softc_t *, uhci_soft_qh_t *,
uhci_intr_info_t *));
void uhci_exit_ctl_q __P((uhci_softc_t *, uhci_soft_qh_t *));
+#endif
void uhci_free_std_chain __P((uhci_softc_t *,
uhci_soft_td_t *, uhci_soft_td_t *));
@@ -149,24 +158,32 @@ 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 *));
-void uhci_device_close __P((struct uhci_pipe *));
-
void uhci_wakeup_cb __P((usbd_request_handle reqh));
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));
void uhci_device_ctrl_close __P((usbd_pipe_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));
void uhci_device_intr_close __P((usbd_pipe_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));
void uhci_device_bulk_close __P((usbd_pipe_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));
+void uhci_device_isoc_close __P((usbd_pipe_handle));
+usbd_status uhci_device_isoc_setbuf __P((usbd_pipe_handle, u_int, u_int));
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));
void uhci_root_ctrl_close __P((usbd_pipe_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));
void uhci_root_intr_close __P((usbd_pipe_handle));
@@ -182,6 +199,7 @@ void uhci_remove_intr __P((uhci_softc_t *, int, uhci_soft_qh_t *));
usbd_status uhci_device_setintr __P((uhci_softc_t *sc,
struct uhci_pipe *pipe, int ival));
void uhci_intr_done __P((uhci_intr_info_t *ii));
+void uhci_isoc_done __P((uhci_intr_info_t *ii));
#ifdef USB_DEBUG
static void uhci_dumpregs __P((uhci_softc_t *));
@@ -207,8 +225,6 @@ void uhci_dump_td __P((uhci_soft_td_t *));
#define UHCISTS(sc) UREAD2(sc, UHCI_STS)
#define UHCI_RESET_TIMEOUT 100 /* reset timeout */
-#define UHCI_CTRL_TIMEOUT 500 /* control transaction timeout */
-#define UHCI_ISO_DELAY 50 /* delay of start of iso */
#define UHCI_CURFRAME(sc) (UREAD2(sc, UHCI_FRNUM) & UHCI_FRNUM_MASK)
@@ -216,6 +232,7 @@ void uhci_dump_td __P((uhci_soft_td_t *));
struct usbd_methods uhci_root_ctrl_methods = {
uhci_root_ctrl_transfer,
+ uhci_root_ctrl_start,
uhci_root_ctrl_abort,
uhci_root_ctrl_close,
0,
@@ -223,6 +240,7 @@ struct usbd_methods uhci_root_ctrl_methods = {
struct usbd_methods uhci_root_intr_methods = {
uhci_root_intr_transfer,
+ uhci_root_intr_start,
uhci_root_intr_abort,
uhci_root_intr_close,
0,
@@ -230,6 +248,7 @@ struct usbd_methods uhci_root_intr_methods = {
struct usbd_methods uhci_device_ctrl_methods = {
uhci_device_ctrl_transfer,
+ uhci_device_ctrl_start,
uhci_device_ctrl_abort,
uhci_device_ctrl_close,
0,
@@ -237,6 +256,7 @@ struct usbd_methods uhci_device_ctrl_methods = {
struct usbd_methods uhci_device_intr_methods = {
uhci_device_intr_transfer,
+ uhci_device_intr_start,
uhci_device_intr_abort,
uhci_device_intr_close,
0,
@@ -244,11 +264,20 @@ struct usbd_methods uhci_device_intr_methods = {
struct usbd_methods uhci_device_bulk_methods = {
uhci_device_bulk_transfer,
+ uhci_device_bulk_start,
uhci_device_bulk_abort,
uhci_device_bulk_close,
0,
};
+struct usbd_methods uhci_device_isoc_methods = {
+ uhci_device_isoc_transfer,
+ uhci_device_isoc_start,
+ uhci_device_isoc_abort,
+ uhci_device_isoc_close,
+ uhci_device_isoc_setbuf,
+};
+
void
uhci_busreset(sc)
uhci_softc_t *sc;
@@ -353,8 +382,7 @@ uhci_init(sc)
UWRITE2(sc, UHCI_INTR, UHCI_INTR_TOCRCIE | UHCI_INTR_RIE |
UHCI_INTR_IOCE | UHCI_INTR_SPIE); /* enable interrupts */
- uhci_run(sc, 1); /* and here we go... */
- return (USBD_NORMAL_COMPLETION);
+ return (uhci_run(sc, 1)); /* and here we go... */
}
#ifdef USB_DEBUG
@@ -460,18 +488,19 @@ uhci_timo(addr)
p[0] |= 1<<1;
if (UREAD2(sc, UHCI_PORTSC2) & (UHCI_PORTSC_CSC|UHCI_PORTSC_OCIC))
p[0] |= 1<<2;
+ s = splusb();
if (p[0] != 0) {
reqh->actlen = 1;
reqh->status = USBD_NORMAL_COMPLETION;
- s = splusb();
reqh->xfercb(reqh);
- splx(s);
}
if (reqh->pipe->intrreqh == reqh) {
usb_timeout(uhci_timo, reqh, sc->sc_ival, reqh->timo_handle);
} else {
usb_freemem(sc->sc_dmatag, &upipe->u.intr.datadma);
+ usb_start_next(reqh->pipe);
}
+ splx(s);
}
@@ -722,7 +751,7 @@ uhci_ii_done(ii, timo)
usbd_request_handle reqh = ii->reqh;
uhci_soft_td_t *std;
u_int32_t tst;
- int len, status;
+ int len, status, attr;
DPRINTFN(10, ("uhci_ii_done: ii=%p ready %d\n", ii, timo));
@@ -779,15 +808,19 @@ uhci_ii_done(ii, timo)
}
DPRINTFN(5, ("uhci_ii_done: calling handler ii=%p\n", ii));
- switch (reqh->pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE) {
+ attr = reqh->pipe->endpoint->edesc->bmAttributes;
+ switch (attr & UE_XFERTYPE) {
case UE_CONTROL:
uhci_ctrl_done(ii);
+ usb_start_next(reqh->pipe);
break;
case UE_ISOCHRONOUS:
- printf("uhci_ii_done: ISO??\n");
+ uhci_isoc_done(ii);
+ usb_start_next(reqh->pipe);
break;
case UE_BULK:
uhci_bulk_done(ii);
+ usb_start_next(reqh->pipe);
break;
case UE_INTERRUPT:
uhci_intr_done(ii);
@@ -883,7 +916,7 @@ uhci_reset(p)
}
#endif
-void
+usbd_status
uhci_run(sc, run)
uhci_softc_t *sc;
int run;
@@ -891,11 +924,11 @@ uhci_run(sc, run)
int s, n, running;
run = run != 0;
- s = splusb(); /* XXX really? */
+ s = splusb();
running = !(UREAD2(sc, UHCI_STS) & UHCI_STS_HCH);
if (run == running) {
splx(s);
- return;
+ return (USBD_NORMAL_COMPLETION);
}
UWRITE2(sc, UHCI_CMD, run ? UHCI_CMD_RS : 0);
for(n = 0; n < 10; n++) {
@@ -903,13 +936,14 @@ uhci_run(sc, run)
/* return when we've entered the state we want */
if (run == running) {
splx(s);
- return;
+ return (USBD_NORMAL_COMPLETION);
}
usbd_delay_ms(&sc->sc_bus, 1);
}
splx(s);
printf("%s: cannot %s\n", USBDEVNAME(sc->sc_bus.bdev),
run ? "start" : "stop");
+ return (USBD_IOERROR);
}
/*
@@ -919,7 +953,7 @@ uhci_run(sc, run)
* These two routines do their own free list management,
* partly for speed, partly because allocating DMAable memory
* has page size granularaity so much memory would be wasted if
- * only one TD/QH (32 bytes) was placed in each alloacted chunk.
+ * only one TD/QH (32 bytes) was placed in each allocated chunk.
*/
uhci_soft_td_t *
@@ -936,16 +970,15 @@ uhci_alloc_std(sc)
std = malloc(sizeof(uhci_soft_td_t) * UHCI_TD_CHUNK,
M_USBDEV, M_NOWAIT);
if (!std)
- return 0;
+ return (0);
r = usb_allocmem(sc->sc_dmatag, UHCI_TD_SIZE * UHCI_TD_CHUNK,
UHCI_TD_ALIGN, &dma);
if (r != USBD_NORMAL_COMPLETION) {
free(std, M_USBDEV);
- return 0;
+ return (0);
}
for(i = 0; i < UHCI_TD_CHUNK; i++, std++) {
- std->physaddr = DMAADDR(&dma) +
- i * UHCI_TD_SIZE;
+ std->physaddr = DMAADDR(&dma) + i * UHCI_TD_SIZE;
std->td = (uhci_td_t *)
((char *)KERNADDR(&dma) + i * UHCI_TD_SIZE);
std->td->link.std = sc->sc_freetds;
@@ -1008,7 +1041,7 @@ uhci_alloc_sqh(sc)
sqh = sc->sc_freeqhs;
sc->sc_freeqhs = sqh->qh->hlink;
memset(sqh->qh, 0, UHCI_QH_SIZE);
- return sqh;
+ return (sqh);
}
void
@@ -1020,6 +1053,7 @@ uhci_free_sqh(sc, sqh)
sc->sc_freeqhs = sqh;
}
+#if 0
/*
* Enter a list of transfers onto a control queue.
* Called at splusb()
@@ -1033,6 +1067,7 @@ uhci_enter_ctl_q(sc, sqh, ii)
DPRINTFN(5, ("uhci_enter_ctl_q: sqh=%p\n", sqh));
}
+#endif
void
uhci_free_std_chain(sc, std, stdend)
@@ -1118,6 +1153,22 @@ usbd_status
uhci_device_bulk_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (uhci_device_bulk_start(reqh));
+}
+
+usbd_status
+uhci_device_bulk_start(reqh)
+ usbd_request_handle reqh;
+{
struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
@@ -1229,6 +1280,22 @@ usbd_status
uhci_device_ctrl_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (uhci_device_ctrl_start(reqh));
+}
+
+usbd_status
+uhci_device_ctrl_start(reqh)
+ usbd_request_handle reqh;
+{
uhci_softc_t *sc = (uhci_softc_t *)reqh->pipe->device->bus;
usbd_status r;
@@ -1248,6 +1315,22 @@ usbd_status
uhci_device_intr_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (uhci_device_intr_start(reqh));
+}
+
+usbd_status
+uhci_device_intr_start(reqh)
+ usbd_request_handle reqh;
+{
struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
usbd_device_handle dev = upipe->pipe.device;
uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
@@ -1447,11 +1530,9 @@ uhci_device_request(reqh)
xferend->td->link.std = stat;
xferend->td->td_link = stat->physaddr;
} else {
- xfer = 0;
next = stat;
}
upipe->u.ctl.length = len;
- upipe->u.ctl.xferend = xferend;
memcpy(KERNADDR(&upipe->u.ctl.reqdma), req, sizeof *req);
if (!isread && len != 0)
@@ -1537,6 +1618,177 @@ uhci_device_request(reqh)
return (r);
}
+usbd_status
+uhci_device_isoc_transfer(reqh)
+ usbd_request_handle reqh;
+{
+ struct uhci_pipe *upipe = (struct uhci_pipe *)reqh->pipe;
+ usbd_device_handle dev = upipe->pipe.device;
+ uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
+
+ DPRINTFN(1,("uhci_device_isoc_transfer: sc=%p\n", sc));
+ if (upipe->u.iso.bufsize == 0)
+ return (USBD_INVAL);
+
+ /* XXX copy data */
+ return (USBD_XXX);
+}
+
+usbd_status
+uhci_device_isoc_start(reqh)
+ usbd_request_handle reqh;
+{
+ return (USBD_XXX);
+}
+
+void
+uhci_device_isoc_abort(reqh)
+ usbd_request_handle reqh;
+{
+ /* XXX Can't abort a single request. */
+}
+
+void
+uhci_device_isoc_close(pipe)
+ usbd_pipe_handle pipe;
+{
+ struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
+ usbd_device_handle dev = upipe->pipe.device;
+ uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
+ struct iso *iso;
+ int i;
+
+ /*
+ * Make sure all TDs are marked as inactive.
+ * Wait for completion.
+ * Unschedule.
+ * Deallocate.
+ */
+ iso = &upipe->u.iso;
+
+ for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++)
+ iso->stds[i]->td->td_status &= ~UHCI_TD_ACTIVE;
+ usbd_delay_ms(&sc->sc_bus, 2); /* wait for completion */
+
+ uhci_lock_frames(sc);
+ for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
+ uhci_soft_td_t *std, *vstd;
+
+ std = iso->stds[i];
+ for (vstd = sc->sc_vframes[i % UHCI_VFRAMELIST_COUNT].htd;
+ vstd && vstd->td->link.std != std;
+ vstd = vstd->td->link.std)
+ ;
+ if (!vstd) {
+ /*panic*/
+ printf("uhci_device_isoc_close: %p not found\n", std);
+ uhci_unlock_frames(sc);
+ return;
+ }
+ vstd->td->link = std->td->link;
+ vstd->td->td_link = std->td->td_link;
+ uhci_free_std(sc, std);
+ }
+ uhci_unlock_frames(sc);
+
+ for (i = 0; i < iso->nbuf; i++)
+ usb_freemem(sc->sc_dmatag, &iso->bufs[i]);
+ free(iso->stds, M_USB);
+ free(iso->bufs, M_USB);
+
+ /* XXX what else? */
+}
+
+usbd_status
+uhci_device_isoc_setbuf(pipe, bufsize, nbuf)
+ usbd_pipe_handle pipe;
+ u_int bufsize;
+ u_int nbuf;
+{
+ struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
+ usbd_device_handle dev = upipe->pipe.device;
+ uhci_softc_t *sc = (uhci_softc_t *)dev->bus;
+ int addr = upipe->pipe.device->address;
+ int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress;
+ int rd = upipe->pipe.endpoint->edesc->bEndpointAddress & UE_IN;
+ struct iso *iso;
+ int i;
+ usbd_status r;
+
+ /*
+ * For simplicity the number of buffers must fit nicely in the frame
+ * list.
+ */
+ if (UHCI_VFRAMELIST_COUNT % nbuf != 0)
+ return (USBD_INVAL);
+
+ iso = &upipe->u.iso;
+ iso->bufsize = bufsize;
+ iso->nbuf = nbuf;
+
+ /* Allocate memory for buffers. */
+ iso->bufs = malloc(nbuf * sizeof(usb_dma_t), M_USB, M_WAITOK);
+ iso->stds = malloc(UHCI_VFRAMELIST_COUNT * sizeof (uhci_soft_td_t *),
+ M_USB, M_WAITOK);
+
+ for (i = 0; i < nbuf; i++) {
+ r = usb_allocmem(sc->sc_dmatag, bufsize, 0, &iso->bufs[i]);
+ if (r != USBD_NORMAL_COMPLETION) {
+ nbuf = i;
+ goto bad1;
+ }
+ }
+
+ /* Allocate the TDs. */
+ for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
+ iso->stds[i] = uhci_alloc_std(sc);
+ if (iso->stds[i] == 0)
+ goto bad2;
+ }
+
+ /* XXX check schedule */
+
+ /* XXX interrupts */
+
+ /* Insert TDs into schedule, all marked inactive. */
+ uhci_lock_frames(sc);
+ for (i = 0; i < UHCI_VFRAMELIST_COUNT; i++) {
+ uhci_soft_td_t *std, *vstd;
+
+ std = iso->stds[i];
+ std->td->td_status = UHCI_TD_IOS; /* iso, inactive */
+ std->td->td_token =
+ rd ? UHCI_TD_IN (0, endpt, addr, 0) :
+ UHCI_TD_OUT(0, endpt, addr, 0);
+ std->td->td_buffer = DMAADDR(&iso->bufs[i % nbuf]);
+
+ vstd = sc->sc_vframes[i % UHCI_VFRAMELIST_COUNT].htd;
+ std->td->link = vstd->td->link;
+ std->td->td_link = vstd->td->td_link;
+ vstd->td->link.std = std;
+ vstd->td->td_link = std->physaddr;
+ }
+ uhci_unlock_frames(sc);
+
+ return (USBD_NORMAL_COMPLETION);
+
+ bad2:
+ while (--i >= 0)
+ uhci_free_std(sc, iso->stds[i]);
+ bad1:
+ for (i = 0; i < nbuf; i++)
+ usb_freemem(sc->sc_dmatag, &iso->bufs[i]);
+ free(iso->stds, M_USB);
+ free(iso->bufs, M_USB);
+ return (USBD_NOMEM);
+}
+
+void
+uhci_isoc_done(ii)
+ uhci_intr_info_t *ii;
+{
+}
+
void
uhci_intr_done(ii)
uhci_intr_info_t *ii;
@@ -1590,6 +1842,7 @@ uhci_intr_done(ii)
} else {
usb_freemem(sc->sc_dmatag, dma);
ii->stdstart = 0; /* mark as inactive */
+ usb_start_next(reqh->pipe);
}
}
@@ -1823,8 +2076,9 @@ uhci_open(pipe)
pipe->methods = &uhci_device_intr_methods;
return (uhci_device_setintr(sc, upipe, ed->bInterval));
case UE_ISOCHRONOUS:
- printf("uhci_open: iso not implemented\n");
- return (USBD_XXX);
+ pipe->methods = &uhci_device_isoc_methods;
+ upipe->u.iso.nbuf = 0;
+ return (USBD_NORMAL_COMPLETION);
case UE_BULK:
pipe->methods = &uhci_device_bulk_methods;
upipe->u.bulk.sqh = uhci_alloc_sqh(sc);
@@ -1927,6 +2181,22 @@ usbd_status
uhci_root_ctrl_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (uhci_root_ctrl_start(reqh));
+}
+
+usbd_status
+uhci_root_ctrl_start(reqh)
+ usbd_request_handle reqh;
+{
uhci_softc_t *sc = (uhci_softc_t *)reqh->pipe->device->bus;
usb_device_request_t *req;
void *buf;
@@ -2240,6 +2510,7 @@ uhci_root_ctrl_transfer(reqh)
ret:
reqh->status = r;
reqh->xfercb(reqh);
+ usb_start_next(reqh->pipe);
return (USBD_IN_PROGRESS);
}
@@ -2268,11 +2539,27 @@ uhci_root_intr_abort(reqh)
usb_untimeout(uhci_timo, reqh, reqh->timo_handle);
}
-/* Start a transfer on the root interrupt pipe */
usbd_status
uhci_root_intr_transfer(reqh)
usbd_request_handle reqh;
{
+ int s;
+ usbd_status r;
+
+ s = splusb();
+ r = usb_insert_transfer(reqh);
+ splx(s);
+ if (r != USBD_NORMAL_COMPLETION)
+ return (r);
+ else
+ return (uhci_root_intr_start(reqh));
+}
+
+/* Start a transfer on the root interrupt pipe */
+usbd_status
+uhci_root_intr_start(reqh)
+ usbd_request_handle reqh;
+{
usbd_pipe_handle pipe = reqh->pipe;
uhci_softc_t *sc = (uhci_softc_t *)pipe->device->bus;
struct uhci_pipe *upipe = (struct uhci_pipe *)pipe;
diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c
index 273ca31a367..cc675c4eee8 100644
--- a/sys/dev/usb/usb_subr.c
+++ b/sys/dev/usb/usb_subr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_subr.c,v 1.18 1998/12/26 12:53:03 augustss Exp $ */
+/* $NetBSD: usb_subr.c,v 1.19 1998/12/28 20:14:00 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -326,9 +326,9 @@ usbd_find_idesc(cd, ifaceidx, altidx)
char *p = (char *)cd;
char *end = p + UGETW(cd->wTotalLength);
usb_interface_descriptor_t *d;
- int curidx, lastno, curaidx = 0;
+ int curidx, lastidx, curaidx = 0;
- for (curidx = lastno = -1; p < end; ) {
+ for (curidx = lastidx = -1; p < end; ) {
d = (usb_interface_descriptor_t *)p;
DPRINTFN(4,("usbd_find_idesc: idx=%d(%d) altidx=%d(%d) len=%d "
"type=%d\n",
@@ -338,8 +338,8 @@ usbd_find_idesc(cd, ifaceidx, altidx)
break;
p += d->bLength;
if (p <= end && d->bDescriptorType == UDESC_INTERFACE) {
- if (d->bInterfaceNumber != lastno) {
- lastno = d->bInterfaceNumber;
+ if (d->bInterfaceNumber != lastidx) {
+ lastidx = d->bInterfaceNumber;
curidx++;
curaidx = 0;
} else
@@ -394,7 +394,6 @@ usbd_fill_iface_data(dev, ifaceidx, altidx)
int altidx;
{
usbd_interface_handle ifc = &dev->ifaces[ifaceidx];
- usb_endpoint_descriptor_t *ed;
char *p, *end;
int endpt, nendpt;
usbd_status r;
@@ -403,10 +402,10 @@ usbd_fill_iface_data(dev, ifaceidx, altidx)
ifaceidx, altidx));
ifc->device = dev;
ifc->idesc = usbd_find_idesc(dev->cdesc, ifaceidx, altidx);
- ifc->index = ifaceidx;
- ifc->altindex = altidx;
if (ifc->idesc == 0)
return (USBD_INVAL);
+ ifc->index = ifaceidx;
+ ifc->altindex = altidx;
nendpt = ifc->idesc->bNumEndpoints;
DPRINTFN(10,("usbd_fill_iface_data: found idesc n=%d\n", nendpt));
if (nendpt != 0) {
@@ -419,6 +418,7 @@ usbd_fill_iface_data(dev, ifaceidx, altidx)
ifc->priv = 0;
p = (char *)ifc->idesc + ifc->idesc->bLength;
end = (char *)dev->cdesc + UGETW(dev->cdesc->wTotalLength);
+#define ed ((usb_endpoint_descriptor_t *)p)
for (endpt = 0; endpt < nendpt; endpt++) {
DPRINTFN(10,("usbd_fill_iface_data: endpt=%d\n", endpt));
for (; p < end; p += ed->bLength) {
@@ -428,18 +428,19 @@ usbd_fill_iface_data(dev, ifaceidx, altidx)
p, end, ed->bLength, ed->bDescriptorType));
if (p + ed->bLength <= end &&
ed->bDescriptorType == UDESC_ENDPOINT)
- goto found;
- if (ed->bDescriptorType == UDESC_INTERFACE)
break;
+ if (ed->bDescriptorType == UDESC_INTERFACE ||
+ ed->bLength == 0) {
+ r = USBD_INVAL;
+ goto bad;
+ }
}
- r = USBD_INVAL;
- goto bad;
- found:
ifc->endpoints[endpt].edesc = ed;
ifc->endpoints[endpt].state = USBD_ENDPOINT_ACTIVE;
ifc->endpoints[endpt].refcnt = 0;
ifc->endpoints[endpt].toggle = 0;
}
+#undef ed
LIST_INIT(&ifc->pipes);
ifc->state = USBD_INTERFACE_ACTIVE;
return (USBD_NORMAL_COMPLETION);
@@ -656,7 +657,8 @@ usbd_setup_pipe(dev, iface, ep, pipe)
SIMPLEQ_INIT(&p->queue);
r = dev->bus->open_pipe(p);
if (r != USBD_NORMAL_COMPLETION) {
- DPRINTF(("usbd_setup_pipe: endpoint=%d failed, error=%d(%s)\n",
+ DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error=%d"
+ "(%s)\n",
ep->edesc->bEndpointAddress, r, usbd_error_strs[r]));
free(p, M_USB);
return (r);
@@ -836,7 +838,7 @@ usbd_new_device(parent, bus, depth, lowspeed, port, up)
r = usbd_setup_pipe(dev, 0, &dev->def_ep, &dev->default_pipe);
if (r != USBD_NORMAL_COMPLETION) {
usbd_remove_device(dev, up);
- return r;
+ return (r);
}
up->device = dev;
@@ -998,6 +1000,60 @@ usbd_bus_print_child(device_t bus, device_t dev)
}
#endif
+usbd_status
+usb_insert_transfer(reqh)
+ usbd_request_handle reqh;
+{
+ usbd_pipe_handle pipe = reqh->pipe;
+ usbd_interface_handle iface = pipe->iface;
+
+ if (pipe->state == USBD_PIPE_IDLE ||
+ (iface && iface->state == USBD_INTERFACE_IDLE))
+ return (USBD_IS_IDLE);
+ SIMPLEQ_INSERT_TAIL(&pipe->queue, reqh, next);
+ if (pipe->state != USBD_PIPE_ACTIVE ||
+ (iface && iface->state != USBD_INTERFACE_ACTIVE))
+ return (USBD_NOT_STARTED);
+ if (pipe->running)
+ return (USBD_IN_PROGRESS);
+ pipe->running = 1;
+ return (USBD_NORMAL_COMPLETION);
+}
+
+void
+usb_start_next(pipe)
+ usbd_pipe_handle pipe;
+{
+ usbd_request_handle reqh;
+ usbd_status r;
+
+#ifdef DIAGNOSTIC
+ if (SIMPLEQ_FIRST(&pipe->queue) == 0) {
+ printf("usb_start_next: empty\n");
+ return;
+ }
+#endif
+
+ /* First remove remove old */
+ SIMPLEQ_REMOVE_HEAD(&pipe->queue, SIMPLEQ_FIRST(&pipe->queue), next);
+ if (pipe->state != USBD_PIPE_ACTIVE) {
+ pipe->running = 0;
+ return;
+ }
+ reqh = SIMPLEQ_FIRST(&pipe->queue);
+ DPRINTFN(5, ("usb_start_next: start reqh=%p\n", reqh));
+ if (!reqh)
+ pipe->running = 0;
+ else {
+ r = pipe->methods->start(reqh);
+ if (r != USBD_IN_PROGRESS) {
+ printf("usb_start_next: error=%d\n", r);
+ pipe->running = 0;
+ /* XXX do what? */
+ }
+ }
+}
+
void
usbd_fill_deviceinfo(dev, di)
usbd_device_handle dev;
diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c
index 9af92aa186f..83ca47623c2 100644
--- a/sys/dev/usb/usbdi.c
+++ b/sys/dev/usb/usbdi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi.c,v 1.15 1998/12/26 12:53:04 augustss Exp $ */
+/* $NetBSD: usbdi.c,v 1.16 1998/12/28 20:14:00 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -70,7 +70,6 @@ static usbd_status usbd_ar_iface __P((usbd_interface_handle iface));
static void usbd_transfer_cb __P((usbd_request_handle reqh));
static void usbd_sync_transfer_cb __P((usbd_request_handle reqh));
static usbd_status usbd_do_transfer __P((usbd_request_handle reqh));
-static usbd_status usbd_start __P((usbd_pipe_handle pipe));
void usbd_do_request_async_cb
__P((usbd_request_handle, usbd_private_handle, usbd_status));
@@ -217,9 +216,18 @@ usbd_do_transfer(reqh)
usbd_request_handle reqh;
{
usbd_pipe_handle pipe = reqh->pipe;
- usbd_interface_handle iface = pipe->iface;
- usbd_status r;
- int s;
+
+ DPRINTFN(10,("usbd_do_transfer: reqh=%p\n", reqh));
+ reqh->done = 0;
+ return (pipe->methods->transfer(reqh));
+}
+
+#if 0
+static usbd_status
+usbd_do_transfer(reqh)
+ usbd_request_handle reqh;
+{
+ usbd_pipe_handle pipe = reqh->pipe;
DPRINTFN(10,("usbd_do_transfer: reqh=%p\n", reqh));
reqh->done = 0;
@@ -261,7 +269,7 @@ usbd_start(pipe)
pipe->curreqh = reqh;
return (pipe->methods->transfer(reqh));
}
-
+#endif
usbd_request_handle
usbd_alloc_request()
@@ -560,6 +568,8 @@ usbd_set_pipe_state(pipe, state)
usbd_pipe_state state;
{
int s;
+ usbd_status r;
+ usbd_request_handle reqh;
if (pipe->iface->state != USBD_INTERFACE_ACTIVE)
return (USBD_INTERFACE_NOT_ACTIVE);
@@ -568,12 +578,21 @@ usbd_set_pipe_state(pipe, state)
state != USBD_PIPE_IDLE)
return (USBD_INVAL);
pipe->state = state;
+ r = USBD_NORMAL_COMPLETION;
if (state == USBD_PIPE_ACTIVE) {
s = splusb();
- usbd_start(pipe);
- splx(s);
+ if (!pipe->running) {
+ reqh = SIMPLEQ_FIRST(&pipe->queue);
+ if (reqh != 0) {
+ pipe->running = 1;
+ splx(s);
+ r = pipe->methods->start(reqh);
+ } else
+ splx(s);
+ } else
+ splx(s);
}
- return (USBD_NORMAL_COMPLETION);
+ return (r);
}
usbd_status
@@ -839,7 +858,8 @@ usbd_set_interface(iface, altidx)
if (LIST_FIRST(&iface->pipes) != 0)
return (USBD_IN_USE);
- free(iface->endpoints, M_USB);
+ if (iface->endpoints)
+ free(iface->endpoints, M_USB);
iface->endpoints = 0;
iface->idesc = 0;
iface->state = USBD_INTERFACE_IDLE;
@@ -851,7 +871,7 @@ usbd_set_interface(iface, altidx)
req.bmRequestType = UT_WRITE_INTERFACE;
req.bRequest = UR_SET_INTERFACE;
USETW(req.wValue, iface->idesc->bAlternateSetting);
- USETW(req.wIndex, iface->idesc->iInterface);
+ USETW(req.wIndex, iface->idesc->bInterfaceNumber);
USETW(req.wLength, 0);
return usbd_do_request(iface->device, &req, 0);
}
@@ -893,7 +913,7 @@ usbd_get_interface(iface, aiface)
req.bmRequestType = UT_READ_INTERFACE;
req.bRequest = UR_GET_INTERFACE;
USETW(req.wValue, 0);
- USETW(req.wIndex, iface->idesc->iInterface);
+ USETW(req.wIndex, iface->idesc->bInterfaceNumber);
USETW(req.wLength, 1);
return usbd_do_request(iface->device, &req, aiface);
}
@@ -907,9 +927,6 @@ usbd_ar_pipe(pipe)
{
usbd_request_handle reqh;
- if (pipe->curreqh != 0)
- pipe->methods->abort(pipe->curreqh);
-
for (;;) {
reqh = SIMPLEQ_FIRST(&pipe->queue);
if (reqh == 0)
@@ -963,8 +980,6 @@ usbd_transfer_cb(reqh)
usbd_request_handle reqh;
{
usbd_pipe_handle pipe = reqh->pipe;
- usbd_request_handle nreqh;
- usbd_status r;
/* Count completed transfers. */
++pipe->device->bus->stats.requests
@@ -979,25 +994,8 @@ usbd_transfer_cb(reqh)
reqh->actlen, reqh->length));
reqh->status = USBD_SHORT_XFER;
}
- pipe->curreqh = 0;
if (reqh->callback)
reqh->callback(reqh, reqh->priv, reqh->status);
-
- if (pipe->state != USBD_PIPE_ACTIVE) {
- pipe->running = 0;
- return;
- }
- nreqh = SIMPLEQ_FIRST(&pipe->queue);
- DPRINTFN(5, ("usbd_transfer_cb: nreqh=%p\n", nreqh));
- if (!nreqh)
- pipe->running = 0;
- else {
- SIMPLEQ_REMOVE_HEAD(&pipe->queue, nreqh, next);
- pipe->curreqh = nreqh;
- r = pipe->methods->transfer(nreqh);
- if (r != USBD_IN_PROGRESS)
- printf("usbd_transfer_cb: error=%d\n", r);
- }
}
static void
diff --git a/sys/dev/usb/usbdivar.h b/sys/dev/usb/usbdivar.h
index a6b3a82cae1..1a5a14f9555 100644
--- a/sys/dev/usb/usbdivar.h
+++ b/sys/dev/usb/usbdivar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdivar.h,v 1.11 1998/12/26 12:53:04 augustss Exp $ */
+/* $NetBSD: usbdivar.h,v 1.12 1998/12/28 20:14:00 augustss Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -51,6 +51,7 @@ typedef void (*usbd_xfercb)__P((usbd_request_handle req));
struct usbd_methods {
usbd_status (*transfer)__P((usbd_request_handle reqh));
+ usbd_status (*start)__P((usbd_request_handle reqh));
void (*abort)__P((usbd_request_handle reqh));
void (*close)__P((usbd_pipe_handle pipe));
usbd_status (*isobuf)__P((usbd_pipe_handle pipe,
@@ -139,7 +140,6 @@ struct usbd_pipe {
void *discoarg;
usbd_request_handle intrreqh; /* used for repeating requests */
- usbd_request_handle curreqh; /* currently running request */
/* Filled by HC driver. */
struct usbd_methods *methods;
@@ -191,6 +191,8 @@ usbd_status usbd_new_device __P((bdevice *parent,
void usbd_remove_device __P((usbd_device_handle,
struct usbd_port *));
int usbd_printBCD __P((char *cp, int bcd));
+usbd_status usb_insert_transfer __P((usbd_request_handle reqh));
+void usb_start_next __P((usbd_pipe_handle pipe));
usbd_status usbd_fill_iface_data __P((usbd_device_handle dev,
int i, int a));