From c314b82018c15bc31eac5a4d838b5268a60f5f24 Mon Sep 17 00:00:00 2001 From: mpi Date: Sun, 27 Apr 2014 14:48:10 +0000 Subject: [PATCH] Start de-obfuscating the HC drivers. Since pipe methods have an xfer argument, always use it to get acces to various data structure (pipe, bus, device) instead of having a different way to get a pointer to these descriptors in every function. Also kill the {E,U}XFER() macro and use a consistent name accross all the methods for {e,u}hci_xfer. --- sys/dev/usb/ehci.c | 232 +++++++++++++++++++----------------------- sys/dev/usb/ehcivar.h | 4 +- sys/dev/usb/ohci.c | 34 +++---- sys/dev/usb/uhci.c | 217 +++++++++++++++++++-------------------- sys/dev/usb/uhcivar.h | 4 +- 5 files changed, 227 insertions(+), 264 deletions(-) diff --git a/sys/dev/usb/ehci.c b/sys/dev/usb/ehci.c index 195e0caef31..027fec3bdfe 100644 --- a/sys/dev/usb/ehci.c +++ b/sys/dev/usb/ehci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ehci.c,v 1.146 2014/03/25 20:27:37 mpi Exp $ */ +/* $OpenBSD: ehci.c,v 1.147 2014/04/27 14:48:10 mpi Exp $ */ /* $NetBSD: ehci.c,v 1.66 2004/06/30 03:11:56 mycroft Exp $ */ /* @@ -177,13 +177,12 @@ void ehci_free_sqtd(struct ehci_softc *, struct ehci_soft_qtd *); usbd_status ehci_alloc_sqtd_chain(struct ehci_pipe *, struct ehci_softc *, u_int, int, struct usbd_xfer *, struct ehci_soft_qtd **, struct ehci_soft_qtd **); -void ehci_free_sqtd_chain(struct ehci_softc *, - struct ehci_xfer *exfer); +void ehci_free_sqtd_chain(struct ehci_softc *, struct ehci_xfer *); struct ehci_soft_itd *ehci_alloc_itd(struct ehci_softc *sc); void ehci_free_itd(struct ehci_softc *sc, struct ehci_soft_itd *itd); void ehci_rem_free_itd_chain(struct ehci_softc *sc, - struct ehci_xfer *exfer); + struct ehci_xfer *); void ehci_abort_isoc_xfer(struct usbd_xfer *xfer, usbd_status status); @@ -1197,9 +1196,9 @@ ehci_allocx(struct usbd_bus *bus) if (xfer != NULL) { memset(xfer, 0, sizeof(struct ehci_xfer)); - EXFER(xfer)->ehci_xfer_flags = 0; + ((struct ehci_xfer *)xfer)->ehci_xfer_flags = 0; #ifdef DIAGNOSTIC - EXFER(xfer)->isdone = 1; + ((struct ehci_xfer *)xfer)->isdone = 1; xfer->busy_free = XFER_BUSY; #endif } @@ -1218,7 +1217,7 @@ ehci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer) return; } xfer->busy_free = XFER_FREE; - if (!EXFER(xfer)->isdone) { + if (!((struct ehci_xfer *)xfer)->isdone) { printf("ehci_freex: !isdone\n"); return; } @@ -1742,16 +1741,16 @@ ehci_sync_hc(struct ehci_softc *sc) /*Call at splusb*/ void -ehci_rem_free_itd_chain(struct ehci_softc *sc, struct ehci_xfer *exfer) +ehci_rem_free_itd_chain(struct ehci_softc *sc, struct ehci_xfer *ex) { struct ehci_soft_itd *itd, *prev; prev = NULL; - if (exfer->itdstart == NULL || exfer->itdend == NULL) + if (ex->itdstart == NULL || ex->itdend == NULL) panic("ehci isoc xfer being freed, but with no itd chain"); - for (itd = exfer->itdstart; itd != NULL; itd = itd->xfer_next) { + for (itd = ex->itdstart; itd != NULL; itd = itd->xfer_next) { prev = itd->u.frame_list.prev; /* Unlink itd from hardware chain, or frame array */ if (prev == NULL) { /* We're at the table head */ @@ -1780,15 +1779,15 @@ ehci_rem_free_itd_chain(struct ehci_softc *sc, struct ehci_xfer *exfer) } prev = NULL; - for (itd = exfer->itdstart; itd != NULL; itd = itd->xfer_next) { + for (itd = ex->itdstart; itd != NULL; itd = itd->xfer_next) { if (prev != NULL) ehci_free_itd(sc, prev); prev = itd; } if (prev) ehci_free_itd(sc, prev); - exfer->itdstart = NULL; - exfer->itdend = NULL; + ex->itdstart = NULL; + ex->itdend = NULL; } /***********/ @@ -2466,7 +2465,7 @@ ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, struct ehci_softc *sc, DPRINTFN(alen<4*4096,("ehci_alloc_sqtd_chain: start len=%d\n", alen)); len = alen; - iscontrol = (epipe->pipe.endpoint->edesc->bmAttributes & UE_XFERTYPE) == + iscontrol = (xfer->pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE) == UE_CONTROL; dataphys = DMAADDR(dma, 0); @@ -2474,7 +2473,7 @@ ehci_alloc_sqtd_chain(struct ehci_pipe *epipe, struct ehci_softc *sc, qtdstatus = EHCI_QTD_ACTIVE | EHCI_QTD_SET_PID(rd ? EHCI_QTD_PID_IN : EHCI_QTD_PID_OUT) | EHCI_QTD_SET_CERR(3); /* IOC and BYTES set below */ - mps = UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize); + mps = UGETW(xfer->pipe->endpoint->edesc->wMaxPacketSize); forceshort = ((xfer->flags & USBD_FORCE_SHORT_XFER) || len == 0) && len % mps == 0; /* @@ -2724,9 +2723,9 @@ ehci_close_pipe(struct usbd_pipe *pipe) void ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) { -#define exfer EXFER(xfer) + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; - struct ehci_softc *sc = (struct ehci_softc *)epipe->pipe.device->bus; + struct ehci_xfer *ex = (struct ehci_xfer*)xfer; struct ehci_soft_qh *sqh = epipe->sqh; struct ehci_soft_qtd *sqtd; int s; @@ -2738,7 +2737,7 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) s = splusb(); xfer->status = status; /* make software ignore it */ timeout_del(&xfer->timeout_handle); - usb_rem_task(epipe->pipe.device, &xfer->abort_task); + usb_rem_task(xfer->device, &xfer->abort_task); usb_transfer_complete(xfer); splx(s); return; @@ -2751,7 +2750,7 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) * If an abort is already in progress then just wait for it to * complete and return. */ - if (exfer->ehci_xfer_flags & EHCI_XFER_ABORTING) { + if (ex->ehci_xfer_flags & EHCI_XFER_ABORTING) { DPRINTFN(2, ("ehci_abort_xfer: already aborting\n")); /* No need to wait if we're aborting from a timeout. */ if (status == USBD_TIMEOUT) @@ -2759,9 +2758,9 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) /* Override the status which might be USBD_TIMEOUT. */ xfer->status = status; DPRINTFN(2, ("ehci_abort_xfer: waiting for abort to finish\n")); - exfer->ehci_xfer_flags |= EHCI_XFER_ABORTWAIT; - while (exfer->ehci_xfer_flags & EHCI_XFER_ABORTING) - tsleep(&exfer->ehci_xfer_flags, PZERO, "ehciaw", 0); + ex->ehci_xfer_flags |= EHCI_XFER_ABORTWAIT; + while (ex->ehci_xfer_flags & EHCI_XFER_ABORTING) + tsleep(&ex->ehci_xfer_flags, PZERO, "ehciaw", 0); return; } @@ -2769,10 +2768,10 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) * Step 1: Make interrupt routine and timeouts ignore xfer. */ s = splusb(); - exfer->ehci_xfer_flags |= EHCI_XFER_ABORTING; + ex->ehci_xfer_flags |= EHCI_XFER_ABORTING; xfer->status = status; /* make software ignore it */ timeout_del(&xfer->timeout_handle); - usb_rem_task(epipe->pipe.device, &xfer->abort_task); + usb_rem_task(xfer->device, &xfer->abort_task); splx(s); /* @@ -2789,7 +2788,7 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) sizeof(sqh->qh.qh_qtd.qtd_status), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); - for (sqtd = exfer->sqtdstart; sqtd != NULL; sqtd = sqtd->nextqtd) { + for (sqtd = ex->sqtdstart; sqtd != NULL; sqtd = sqtd->nextqtd) { usb_syncmem(&sqtd->dma, sqtd->offs + offsetof(struct ehci_qtd, qtd_status), sizeof(sqtd->qtd.qtd_status), @@ -2814,47 +2813,42 @@ ehci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) tsleep(&sc->sc_softwake, PZERO, "ehciab", 0); #ifdef DIAGNOSTIC - exfer->isdone = 1; + ex->isdone = 1; #endif /* Do the wakeup first to avoid touching the xfer after the callback. */ - exfer->ehci_xfer_flags &= ~EHCI_XFER_ABORTING; - if (exfer->ehci_xfer_flags & EHCI_XFER_ABORTWAIT) { - exfer->ehci_xfer_flags &= ~EHCI_XFER_ABORTWAIT; - wakeup(&exfer->ehci_xfer_flags); + ex->ehci_xfer_flags &= ~EHCI_XFER_ABORTING; + if (ex->ehci_xfer_flags & EHCI_XFER_ABORTWAIT) { + ex->ehci_xfer_flags &= ~EHCI_XFER_ABORTWAIT; + wakeup(&ex->ehci_xfer_flags); } usb_transfer_complete(xfer); splx(s); -#undef exfer } void ehci_abort_isoc_xfer(struct usbd_xfer *xfer, usbd_status status) { + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; ehci_isoc_trans_t trans_status; - struct ehci_pipe *epipe; - struct ehci_xfer *exfer; - struct ehci_softc *sc; struct ehci_soft_itd *itd; int s, i, wake; - epipe = (struct ehci_pipe *) xfer->pipe; - exfer = EXFER(xfer); - sc = (struct ehci_softc *)epipe->pipe.device->bus; - DPRINTF(("ehci_abort_isoc_xfer: xfer %p pipe %p\n", xfer, epipe)); + DPRINTF(("ehci_abort_isoc_xfer: xfer %p pipe %p\n", xfer, xfer->pipe)); if (sc->sc_bus.dying) { s = splusb(); xfer->status = status; timeout_del(&xfer->timeout_handle); - usb_rem_task(epipe->pipe.device, &xfer->abort_task); + usb_rem_task(xfer->device, &xfer->abort_task); usb_transfer_complete(xfer); splx(s); return; } - if (exfer->ehci_xfer_flags & EHCI_XFER_ABORTING) { + if (ex->ehci_xfer_flags & EHCI_XFER_ABORTING) { DPRINTFN(2, ("ehci_abort_isoc_xfer: already aborting\n")); #ifdef DIAGNOSTIC @@ -2864,19 +2858,19 @@ ehci_abort_isoc_xfer(struct usbd_xfer *xfer, usbd_status status) xfer->status = status; DPRINTFN(2, ("ehci_abort_xfer: waiting for abort to finish\n")); - exfer->ehci_xfer_flags |= EHCI_XFER_ABORTING; - while (exfer->ehci_xfer_flags & EHCI_XFER_ABORTING) - tsleep(&exfer->ehci_xfer_flags, PZERO, "ehciiaw", 0); + ex->ehci_xfer_flags |= EHCI_XFER_ABORTING; + while (ex->ehci_xfer_flags & EHCI_XFER_ABORTING) + tsleep(&ex->ehci_xfer_flags, PZERO, "ehciiaw", 0); return; } - exfer->ehci_xfer_flags |= EHCI_XFER_ABORTING; + ex->ehci_xfer_flags |= EHCI_XFER_ABORTING; xfer->status = status; timeout_del(&xfer->timeout_handle); - usb_rem_task(epipe->pipe.device, &xfer->abort_task); + usb_rem_task(xfer->device, &xfer->abort_task); s = splusb(); - for (itd = exfer->itdstart; itd != NULL; itd = itd->xfer_next) { + for (itd = ex->itdstart; itd != NULL; itd = itd->xfer_next) { for (i = 0; i < 8; i++) { trans_status = letoh32(itd->itd.itd_ctl[i]); trans_status &= ~EHCI_ITD_ACTIVE; @@ -2892,13 +2886,13 @@ ehci_abort_isoc_xfer(struct usbd_xfer *xfer, usbd_status status) splx(s); #ifdef DIAGNOSTIC - exfer->isdone = 1; + ex->isdone = 1; #endif - wake = exfer->ehci_xfer_flags & EHCI_XFER_ABORTING; - exfer->ehci_xfer_flags &= ~(EHCI_XFER_ABORTING | EHCI_XFER_ABORTWAIT); + wake = ex->ehci_xfer_flags & EHCI_XFER_ABORTING; + ex->ehci_xfer_flags &= ~(EHCI_XFER_ABORTING | EHCI_XFER_ABORTWAIT); usb_transfer_complete(xfer); if (wake) - wakeup(&exfer->ehci_xfer_flags); + wakeup(&ex->ehci_xfer_flags); return; } @@ -3004,9 +2998,8 @@ ehci_device_ctrl_start(struct usbd_xfer *xfer) void ehci_device_ctrl_done(struct usbd_xfer *xfer) { - struct ehci_xfer *ex = EXFER(xfer); struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; - /*struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe;*/ + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; DPRINTFN(10,("ehci_ctrl_done: xfer=%p\n", xfer)); @@ -3043,11 +3036,10 @@ ehci_device_ctrl_close(struct usbd_pipe *pipe) usbd_status ehci_device_request(struct usbd_xfer *xfer) { -#define exfer EXFER(xfer) + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; usb_device_request_t *req = &xfer->request; - struct usbd_device *dev = epipe->pipe.device; - struct ehci_softc *sc = (struct ehci_softc *)dev->bus; struct ehci_soft_qtd *setup, *stat, *next; struct ehci_soft_qh *sqh; int isread; @@ -3061,8 +3053,8 @@ ehci_device_request(struct usbd_xfer *xfer) DPRINTFN(3,("ehci_device_request: type=0x%02x, request=0x%02x, " "wValue=0x%04x, wIndex=0x%04x len=%u, addr=%d, endpt=%d\n", req->bmRequestType, req->bRequest, UGETW(req->wValue), - UGETW(req->wIndex), len, dev->address, - epipe->pipe.endpoint->edesc->bEndpointAddress)); + UGETW(req->wIndex), len, xfer->device->address, + xfer->pipe->endpoint->edesc->bEndpointAddress)); setup = ehci_alloc_sqtd(sc); if (setup == NULL) { @@ -3136,13 +3128,13 @@ ehci_device_request(struct usbd_xfer *xfer) } #endif - exfer->sqtdstart = setup; - exfer->sqtdend = stat; + ex->sqtdstart = setup; + ex->sqtdend = stat; #ifdef DIAGNOSTIC - if (!exfer->isdone) { - printf("ehci_device_request: not done, exfer=%p\n", exfer); + if (!ex->isdone) { + printf("ehci_device_request: not done, ex=%p\n", ex); } - exfer->isdone = 0; + ex->isdone = 0; #endif /* Insert qTD in QH list. */ @@ -3153,7 +3145,7 @@ ehci_device_request(struct usbd_xfer *xfer) timeout_set(&xfer->timeout_handle, ehci_timeout, xfer); timeout_add_msec(&xfer->timeout_handle, xfer->timeout); } - ehci_add_intr_list(sc, exfer); + ehci_add_intr_list(sc, ex); xfer->status = USBD_IN_PROGRESS; splx(s); @@ -3180,7 +3172,6 @@ ehci_device_request(struct usbd_xfer *xfer) xfer->status = err; usb_transfer_complete(xfer); return (err); -#undef exfer } /************************/ @@ -3202,10 +3193,9 @@ ehci_device_bulk_transfer(struct usbd_xfer *xfer) usbd_status ehci_device_bulk_start(struct usbd_xfer *xfer) { -#define exfer EXFER(xfer) + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; - struct usbd_device *dev = epipe->pipe.device; - struct ehci_softc *sc = (struct ehci_softc *)dev->bus; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; struct ehci_soft_qtd *data, *dataend; struct ehci_soft_qh *sqh; usbd_status err; @@ -3225,7 +3215,7 @@ ehci_device_bulk_start(struct usbd_xfer *xfer) #endif len = xfer->length; - endpt = epipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; sqh = epipe->sqh; @@ -3249,13 +3239,13 @@ ehci_device_bulk_start(struct usbd_xfer *xfer) #endif /* Set up interrupt info. */ - exfer->sqtdstart = data; - exfer->sqtdend = dataend; + ex->sqtdstart = data; + ex->sqtdend = dataend; #ifdef DIAGNOSTIC - if (!exfer->isdone) { - printf("ehci_device_bulk_start: not done, ex=%p\n", exfer); + if (!ex->isdone) { + printf("ehci_device_bulk_start: not done, ex=%p\n", ex); } - exfer->isdone = 0; + ex->isdone = 0; #endif s = splusb(); @@ -3265,7 +3255,7 @@ ehci_device_bulk_start(struct usbd_xfer *xfer) timeout_set(&xfer->timeout_handle, ehci_timeout, xfer); timeout_add_msec(&xfer->timeout_handle, xfer->timeout); } - ehci_add_intr_list(sc, exfer); + ehci_add_intr_list(sc, ex); xfer->status = USBD_IN_PROGRESS; splx(s); @@ -3289,7 +3279,6 @@ ehci_device_bulk_start(struct usbd_xfer *xfer) ehci_waitintr(sc, xfer); return (USBD_IN_PROGRESS); -#undef exfer } void @@ -3312,10 +3301,9 @@ ehci_device_bulk_close(struct usbd_pipe *pipe) void ehci_device_bulk_done(struct usbd_xfer *xfer) { - struct ehci_xfer *ex = EXFER(xfer); struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; - struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; - int endpt = epipe->pipe.endpoint->edesc->bEndpointAddress; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; + int endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; int rd = UE_GET_DIR(endpt) == UE_DIR_IN; DPRINTFN(10,("ehci_bulk_done: xfer=%p, actlen=%d\n", @@ -3375,10 +3363,9 @@ ehci_device_intr_transfer(struct usbd_xfer *xfer) usbd_status ehci_device_intr_start(struct usbd_xfer *xfer) { -#define exfer EXFER(xfer) + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; - struct usbd_device *dev = xfer->device; - struct ehci_softc *sc = (struct ehci_softc *)dev->bus; struct ehci_soft_qtd *data, *dataend; struct ehci_soft_qh *sqh; usbd_status err; @@ -3398,7 +3385,7 @@ ehci_device_intr_start(struct usbd_xfer *xfer) #endif len = xfer->length; - endpt = epipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; sqh = epipe->sqh; @@ -3422,12 +3409,12 @@ ehci_device_intr_start(struct usbd_xfer *xfer) #endif /* Set up interrupt info. */ - exfer->sqtdstart = data; - exfer->sqtdend = dataend; + ex->sqtdstart = data; + ex->sqtdend = dataend; #ifdef DIAGNOSTIC - if (!exfer->isdone) - printf("ehci_device_intr_start: not done, ex=%p\n", exfer); - exfer->isdone = 0; + if (!ex->isdone) + printf("ehci_device_intr_start: not done, ex=%p\n", ex); + ex->isdone = 0; #endif s = splusb(); @@ -3437,7 +3424,7 @@ ehci_device_intr_start(struct usbd_xfer *xfer) timeout_set(&xfer->timeout_handle, ehci_timeout, xfer); timeout_add_msec(&xfer->timeout_handle, xfer->timeout); } - ehci_add_intr_list(sc, exfer); + ehci_add_intr_list(sc, ex); xfer->status = USBD_IN_PROGRESS; splx(s); @@ -3457,7 +3444,6 @@ ehci_device_intr_start(struct usbd_xfer *xfer) ehci_waitintr(sc, xfer); return (USBD_IN_PROGRESS); -#undef exfer } void @@ -3486,10 +3472,9 @@ ehci_device_intr_close(struct usbd_pipe *pipe) void ehci_device_intr_done(struct usbd_xfer *xfer) { -#define exfer EXFER(xfer) - struct ehci_xfer *ex = EXFER(xfer); struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; struct ehci_soft_qtd *data, *dataend; struct ehci_soft_qh *sqh; usbd_status err; @@ -3504,7 +3489,7 @@ ehci_device_intr_done(struct usbd_xfer *xfer) len = epipe->u.intr.length; xfer->length = len; - endpt = epipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; usb_syncmem(&xfer->dmabuf, 0, len, isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); @@ -3519,14 +3504,14 @@ ehci_device_intr_done(struct usbd_xfer *xfer) } /* Set up interrupt info. */ - exfer->sqtdstart = data; - exfer->sqtdend = dataend; + ex->sqtdstart = data; + ex->sqtdend = dataend; #ifdef DIAGNOSTIC - if (!exfer->isdone) { + if (!ex->isdone) { printf("ehci_device_intr_done: not done, ex=%p\n", - exfer); + ex); } - exfer->isdone = 0; + ex->isdone = 0; #endif s = splusb(); @@ -3542,12 +3527,11 @@ ehci_device_intr_done(struct usbd_xfer *xfer) } else if (xfer->status != USBD_NOMEM && ehci_active_intr_list(ex)) { ehci_del_intr_list(sc, ex); /* remove from active list */ ehci_free_sqtd_chain(sc, ex); - endpt = epipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; usb_syncmem(&xfer->dmabuf, 0, xfer->length, isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE); } -#undef exfer } /************************/ @@ -3567,9 +3551,9 @@ ehci_device_isoc_transfer(struct usbd_xfer *xfer) usbd_status ehci_device_isoc_start(struct usbd_xfer *xfer) { - struct ehci_pipe *epipe; - struct ehci_softc *sc; - struct ehci_xfer *exfer; + struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; + struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; struct ehci_soft_itd *itd, *prev, *start, *stop; struct usb_dma *dma_buf; int i, j, k, frames, uframes, ufrperframe; @@ -3580,9 +3564,6 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) prev = NULL; itd = NULL; trans_count = 0; - exfer = (struct ehci_xfer *) xfer; - sc = (struct ehci_softc *)xfer->device->bus; - epipe = (struct ehci_pipe *)xfer->pipe; /* * To allow continuous transfers, above we start all transfers @@ -3591,7 +3572,7 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) * in progress or not */ - if (exfer->itdstart != NULL) + if (ex->itdstart != NULL) return (USBD_IN_PROGRESS); DPRINTFN(2, ("ehci_device_isoc_start: xfer %p len %u flags %d\n", @@ -3605,7 +3586,7 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) * the entire frame table. To within 4 frames, to allow some leeway * on either side of where the hc currently is. */ - if ((1 << (epipe->pipe.endpoint->edesc->bInterval - 1)) * + if ((1 << (xfer->pipe->endpoint->edesc->bInterval - 1)) * xfer->nframes >= (sc->sc_flsize - 4) * 8) { printf("ehci: isoc descriptor requested that spans the entire " "frametable, too many frames\n"); @@ -3616,9 +3597,9 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) if (xfer->rqflags & URQ_REQUEST) panic("ehci_device_isoc_start: request"); - if (!exfer->isdone) - printf("ehci_device_isoc_start: not done, ex = %p\n", exfer); - exfer->isdone = 0; + if (!ex->isdone) + printf("ehci_device_isoc_start: not done, ex = %p\n", ex); + ex->isdone = 0; #endif /* @@ -3627,7 +3608,7 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) * multiple microframes per frame. */ - i = epipe->pipe.endpoint->edesc->bInterval; + i = xfer->pipe->endpoint->edesc->bInterval; if (i > 16 || i == 0) { /* Spec page 271 says intervals > 16 are invalid */ DPRINTF(("ehci_device_isoc_start: bInvertal %d invalid\n", i)); @@ -3731,14 +3712,14 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) * Other special values */ - k = epipe->pipe.endpoint->edesc->bEndpointAddress; + k = xfer->pipe->endpoint->edesc->bEndpointAddress; itd->itd.itd_bufr[0] |= htole32(EHCI_ITD_SET_EP(UE_GET_ADDR(k)) | - EHCI_ITD_SET_DADDR(epipe->pipe.device->address)); + EHCI_ITD_SET_DADDR(xfer->pipe->device->address)); - k = (UE_GET_DIR(epipe->pipe.endpoint->edesc->bEndpointAddress)) + k = (UE_GET_DIR(xfer->pipe->endpoint->edesc->bEndpointAddress)) ? 1 : 0; - j = UGETW(epipe->pipe.endpoint->edesc->wMaxPacketSize); + j = UGETW(xfer->pipe->endpoint->edesc->wMaxPacketSize); itd->itd.itd_bufr[1] |= htole32(EHCI_ITD_SET_DIR(k) | EHCI_ITD_SET_MAXPKT(UE_GET_SIZE(j))); @@ -3773,7 +3754,7 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) frindex &= (sc->sc_flsize - 1); /* Whats the frame interval? */ - i = (1 << (epipe->pipe.endpoint->edesc->bInterval - 1)); + i = (1 << (xfer->pipe->endpoint->edesc->bInterval - 1)); if (i / 8 == 0) i = 1; else @@ -3809,12 +3790,12 @@ ehci_device_isoc_start(struct usbd_xfer *xfer) epipe->u.isoc.cur_xfers++; epipe->u.isoc.next_frame = frindex; - exfer->itdstart = start; - exfer->itdend = stop; - exfer->sqtdstart = NULL; - exfer->sqtdend = NULL; + ex->itdstart = start; + ex->itdend = stop; + ex->sqtdstart = NULL; + ex->sqtdend = NULL; - ehci_add_intr_list(sc, exfer); + ehci_add_intr_list(sc, ex); xfer->status = USBD_IN_PROGRESS; xfer->done = 0; splx(s); @@ -3843,17 +3824,16 @@ ehci_device_isoc_close(struct usbd_pipe *pipe) void ehci_device_isoc_done(struct usbd_xfer *xfer) { - struct ehci_xfer *exfer = EXFER(xfer); struct ehci_softc *sc = (struct ehci_softc *)xfer->device->bus; struct ehci_pipe *epipe = (struct ehci_pipe *)xfer->pipe; + struct ehci_xfer *ex = (struct ehci_xfer *)xfer; int s; - s = splusb(); epipe->u.isoc.cur_xfers--; - if (xfer->status != USBD_NOMEM && ehci_active_intr_list(exfer)) { - ehci_del_intr_list(sc, exfer); - ehci_rem_free_itd_chain(sc, exfer); + if (xfer->status != USBD_NOMEM && ehci_active_intr_list(ex)) { + ehci_del_intr_list(sc, ex); + ehci_rem_free_itd_chain(sc, ex); } splx(s); } diff --git a/sys/dev/usb/ehcivar.h b/sys/dev/usb/ehcivar.h index 98a90e71539..10d60dd1d8d 100644 --- a/sys/dev/usb/ehcivar.h +++ b/sys/dev/usb/ehcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ehcivar.h,v 1.29 2014/03/25 20:27:37 mpi Exp $ */ +/* $OpenBSD: ehcivar.h,v 1.30 2014/04/27 14:48:10 mpi Exp $ */ /* $NetBSD: ehcivar.h,v 1.19 2005/04/29 15:04:29 augustss Exp $ */ /* @@ -91,8 +91,6 @@ struct ehci_xfer { #define EHCI_XFER_ABORTING 0x0001 /* xfer is aborting. */ #define EHCI_XFER_ABORTWAIT 0x0002 /* abort completion is being awaited. */ -#define EXFER(xfer) ((struct ehci_xfer *)(xfer)) - /* Information about an entry in the interrupt list. */ struct ehci_soft_islot { struct ehci_soft_qh *sqh; /* Queue Head. */ diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c index 9134bffbc1c..dc30c41744f 100644 --- a/sys/dev/usb/ohci.c +++ b/sys/dev/usb/ohci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ohci.c,v 1.124 2014/03/25 20:27:37 mpi Exp $ */ +/* $OpenBSD: ohci.c,v 1.125 2014/04/27 14:48:10 mpi Exp $ */ /* $NetBSD: ohci.c,v 1.139 2003/02/22 05:24:16 tsutsui Exp $ */ /* $FreeBSD: src/sys/dev/usb/ohci.c,v 1.22 1999/11/17 22:33:40 n_hibma Exp $ */ @@ -1450,8 +1450,8 @@ ohci_device_ctrl_done(struct usbd_xfer *xfer) void ohci_device_intr_done(struct usbd_xfer *xfer) { - struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe; struct ohci_softc *sc = (struct ohci_softc *)xfer->device->bus; + struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe; struct ohci_soft_ed *sed = opipe->sed; struct ohci_soft_td *data, *tail; @@ -1594,10 +1594,9 @@ ohci_poll(struct usbd_bus *bus) usbd_status ohci_device_request(struct usbd_xfer *xfer) { + struct ohci_softc *sc = (struct ohci_softc *)xfer->device->bus; struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe; usb_device_request_t *req = &xfer->request; - struct usbd_device *dev = xfer->device; - struct ohci_softc *sc = (struct ohci_softc *)dev->bus; struct ohci_soft_td *setup, *stat, *next, *tail; struct ohci_soft_ed *sed; int isread; @@ -1611,8 +1610,8 @@ ohci_device_request(struct usbd_xfer *xfer) DPRINTFN(3,("ohci_device_control type=0x%02x, request=0x%02x, " "wValue=0x%04x, wIndex=0x%04x len=%u, addr=%d, endpt=%d\n", req->bmRequestType, req->bRequest, UGETW(req->wValue), - UGETW(req->wIndex), len, dev->address, - opipe->pipe.endpoint->edesc->bEndpointAddress)); + UGETW(req->wIndex), len, xfer->device->address, + xfer->pipe->endpoint->edesc->bEndpointAddress)); setup = opipe->tail.td; stat = ohci_alloc_std(sc); @@ -1935,14 +1934,12 @@ ohci_dump_ed(struct ohci_soft_ed *sed) usbd_status ohci_open(struct usbd_pipe *pipe) { - struct usbd_device *dev = pipe->device; - struct ohci_softc *sc = (struct ohci_softc *)dev->bus; + struct ohci_softc *sc = (struct ohci_softc *)pipe->device->bus; usb_endpoint_descriptor_t *ed = pipe->endpoint->edesc; struct ohci_pipe *opipe = (struct ohci_pipe *)pipe; - u_int8_t addr = dev->address; u_int8_t xfertype = ed->bmAttributes & UE_XFERTYPE; - struct ohci_soft_ed *sed; - struct ohci_soft_td *std; + struct ohci_soft_ed *sed = NULL; + struct ohci_soft_td *std = NULL; struct ohci_soft_itd *sitd; ohci_physaddr_t tdphys; u_int32_t fmt; @@ -1951,14 +1948,11 @@ ohci_open(struct usbd_pipe *pipe) int ival; DPRINTFN(1, ("ohci_open: pipe=%p, addr=%d, endpt=%d\n", - pipe, addr, ed->bEndpointAddress)); + pipe, pipe->device->address, ed->bEndpointAddress)); if (sc->sc_bus.dying) return (USBD_IOERROR); - std = NULL; - sed = NULL; - /* Root Hub */ if (pipe->device->depth == 0) { switch (ed->bEndpointAddress) { @@ -1996,9 +1990,10 @@ ohci_open(struct usbd_pipe *pipe) fmt = OHCI_ED_FORMAT_GEN | OHCI_ED_DIR_TD; } sed->ed.ed_flags = htole32( - OHCI_ED_SET_FA(addr) | + OHCI_ED_SET_FA(pipe->device->address) | OHCI_ED_SET_EN(UE_GET_ADDR(ed->bEndpointAddress)) | - (dev->speed == USB_SPEED_LOW ? OHCI_ED_SPEED : 0) | + (pipe->device->speed == USB_SPEED_LOW ? + OHCI_ED_SPEED : 0) | fmt | OHCI_ED_SET_MAXP(UGETW(ed->wMaxPacketSize))); sed->ed.ed_headp = htole32(tdphys | (pipe->endpoint->savedtoggle ? OHCI_TOGGLECARRY : 0)); @@ -2071,7 +2066,7 @@ ohci_close_pipe(struct usbd_pipe *pipe, struct ohci_soft_ed *head) (int)letoh32(sed->ed.ed_tailp), pipe, std); #ifdef USB_DEBUG - usbd_dump_pipe(&opipe->pipe); + usbd_dump_pipe(pipe); #endif #ifdef OHCI_DEBUG ohci_dump_ed(sed); @@ -2628,8 +2623,7 @@ ohci_root_intr_transfer(struct usbd_xfer *xfer) usbd_status ohci_root_intr_start(struct usbd_xfer *xfer) { - struct usbd_pipe *pipe = xfer->pipe; - struct ohci_softc *sc = (struct ohci_softc *)pipe->device->bus; + struct ohci_softc *sc = (struct ohci_softc *)xfer->device->bus; if (sc->sc_bus.dying) return (USBD_IOERROR); diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c index 78ae7fd2765..cc3e930f1bb 100644 --- a/sys/dev/usb/uhci.c +++ b/sys/dev/usb/uhci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhci.c,v 1.110 2014/03/25 20:27:37 mpi Exp $ */ +/* $OpenBSD: uhci.c,v 1.111 2014/04/27 14:48:10 mpi Exp $ */ /* $NetBSD: uhci.c,v 1.172 2003/02/23 04:19:26 simonb Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.33 1999/11/17 22:33:41 n_hibma Exp $ */ @@ -625,7 +625,7 @@ uhci_allocx(struct usbd_bus *bus) if (xfer != NULL) { memset(xfer, 0, sizeof (struct uhci_xfer)); #ifdef DIAGNOSTIC - UXFER(xfer)->isdone = 1; + ((struct uhci_xfer *)xfer)->isdone = 1; xfer->busy_free = XFER_BUSY; #endif } @@ -644,7 +644,7 @@ uhci_freex(struct usbd_bus *bus, struct usbd_xfer *xfer) return; } xfer->busy_free = XFER_FREE; - if (!UXFER(xfer)->isdone) { + if (!((struct uhci_xfer *)xfer)->isdone) { printf("uhci_freex: !isdone\n"); return; } @@ -1235,29 +1235,29 @@ uhci_check_intr(struct uhci_softc *sc, struct uhci_xfer *ex) /* Called at splusb() */ void -uhci_idone(struct uhci_xfer *ex) +uhci_idone(struct uhci_xfer *ux) { - struct usbd_xfer *xfer = &ex->xfer; + struct usbd_xfer *xfer = &ux->xfer; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; struct uhci_soft_td *std; u_int32_t status = 0, nstatus; int actlen; - DPRINTFN(12, ("uhci_idone: ex=%p\n", ex)); + DPRINTFN(12, ("uhci_idone: ux=%p\n", ux)); #ifdef DIAGNOSTIC { int s = splhigh(); - if (ex->isdone) { + if (ux->isdone) { splx(s); #ifdef UHCI_DEBUG - printf("uhci_idone: ex is done!\n "); - uhci_dump_xfer(ex); + printf("uhci_idone: ux is done!\n "); + uhci_dump_xfer(ux); #else - printf("uhci_idone: ex=%p is done!\n", ex); + printf("uhci_idone: ux=%p is done!\n", ux); #endif return; } - ex->isdone = 1; + ux->isdone = 1; splx(s); } #endif @@ -1267,11 +1267,11 @@ uhci_idone(struct uhci_xfer *ex) struct uhci_soft_td **stds = upipe->u.iso.stds; int i, n, nframes, len; - DPRINTFN(5,("uhci_idone: ex=%p isoc ready\n", ex)); + DPRINTFN(5,("uhci_idone: ux=%p isoc ready\n", ux)); nframes = xfer->nframes; actlen = 0; - n = UXFER(xfer)->curframe; + n = ux->curframe; for (i = 0; i < nframes; i++) { std = stds[n]; #ifdef UHCI_DEBUG @@ -1294,15 +1294,15 @@ uhci_idone(struct uhci_xfer *ex) } #ifdef UHCI_DEBUG - DPRINTFN(10, ("uhci_idone: ex=%p, xfer=%p, pipe=%p ready\n", - ex, xfer, upipe)); + DPRINTFN(10, ("uhci_idone: ux=%p, xfer=%p, pipe=%p ready\n", + ux, xfer, upipe)); if (uhcidebug > 10) - uhci_dump_tds(ex->stdstart); + uhci_dump_tds(ux->stdstart); #endif /* The transfer is done, compute actual length and status. */ actlen = 0; - for (std = ex->stdstart; std != NULL; std = std->link.std) { + for (std = ux->stdstart; std != NULL; std = std->link.std) { nstatus = letoh32(std->td.td_status); if (nstatus & UHCI_TD_ACTIVE) break; @@ -1356,7 +1356,7 @@ uhci_idone(struct uhci_xfer *ex) end: usb_transfer_complete(xfer); - DPRINTFN(12, ("uhci_idone: ex=%p done\n", ex)); + DPRINTFN(12, ("uhci_idone: ux=%p done\n", ux)); } void @@ -1689,10 +1689,9 @@ uhci_device_bulk_transfer(struct usbd_xfer *xfer) usbd_status uhci_device_bulk_start(struct usbd_xfer *xfer) { + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; - struct uhci_xfer *ex = UXFER(xfer); + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_soft_td *data, *dataend; struct uhci_soft_qh *sqh; usbd_status err; @@ -1700,8 +1699,8 @@ uhci_device_bulk_start(struct usbd_xfer *xfer) int isread, endpt; int s; - DPRINTFN(3, ("uhci_device_bulk_start: xfer=%p len=%u flags=%d ex=%p\n", - xfer, xfer->length, xfer->flags, ex)); + DPRINTFN(3, ("uhci_device_bulk_start: xfer=%p len=%u flags=%d ux=%p\n", + xfer, xfer->length, xfer->flags, ux)); if (sc->sc_bus.dying) return (USBD_IOERROR); @@ -1712,7 +1711,7 @@ uhci_device_bulk_start(struct usbd_xfer *xfer) #endif len = xfer->length; - endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; sqh = upipe->u.bulk.sqh; @@ -1733,13 +1732,13 @@ uhci_device_bulk_start(struct usbd_xfer *xfer) #endif /* Set up interrupt info. */ - ex->stdstart = data; - ex->stdend = dataend; + ux->stdstart = data; + ux->stdend = dataend; #ifdef DIAGNOSTIC - if (!ex->isdone) { - printf("uhci_device_bulk_start: not done, ex=%p\n", ex); + if (!ux->isdone) { + printf("uhci_device_bulk_start: not done, ux=%p\n", ux); } - ex->isdone = 0; + ux->isdone = 0; #endif sqh->elink = data; @@ -1747,11 +1746,11 @@ uhci_device_bulk_start(struct usbd_xfer *xfer) s = splusb(); uhci_add_bulk(sc, sqh); - uhci_add_intr_list(sc, ex); + uhci_add_intr_list(sc, ux); if (xfer->timeout && !sc->sc_bus.use_polling) { timeout_del(&xfer->timeout_handle); - timeout_set(&xfer->timeout_handle, uhci_timeout, ex); + timeout_set(&xfer->timeout_handle, uhci_timeout, xfer); timeout_add_msec(&xfer->timeout_handle, xfer->timeout); } xfer->status = USBD_IN_PROGRESS; @@ -1791,9 +1790,8 @@ uhci_device_bulk_abort(struct usbd_xfer *xfer) void uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) { - struct uhci_xfer *ex = UXFER(xfer); - struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; - struct uhci_softc *sc = (struct uhci_softc *)upipe->pipe.device->bus; + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_soft_td *std; int s; @@ -1820,8 +1818,8 @@ uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) xfer->status = status; /* make software ignore it */ timeout_del(&xfer->timeout_handle); usb_rem_task(xfer->device, &xfer->abort_task); - DPRINTFN(1,("uhci_abort_xfer: stop ex=%p\n", ex)); - for (std = ex->stdstart; std != NULL; std = std->link.std) + DPRINTFN(1,("uhci_abort_xfer: stop ux=%p\n", ux)); + for (std = ux->stdstart; std != NULL; std = std->link.std) std->td.td_status &= htole32(~(UHCI_TD_ACTIVE | UHCI_TD_IOC)); splx(s); @@ -1830,7 +1828,7 @@ uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) * use of the xfer. Also make sure the soft interrupt routine * has run. */ - usb_delay_ms(upipe->pipe.device->bus, 2); /* Hardware finishes in 1ms */ + usb_delay_ms(&sc->sc_bus, 2); /* Hardware finishes in 1ms */ s = splusb(); sc->sc_softwake = 1; usb_schedsoftintr(&sc->sc_bus); @@ -1844,7 +1842,7 @@ uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) DPRINTFN(1,("uhci_abort_xfer: callback\n")); s = splusb(); #ifdef DIAGNOSTIC - ex->isdone = 1; + ux->isdone = 1; #endif usb_transfer_complete(xfer); splx(s); @@ -1854,9 +1852,8 @@ uhci_abort_xfer(struct usbd_xfer *xfer, usbd_status status) void uhci_device_bulk_close(struct usbd_pipe *pipe) { + struct uhci_softc *sc = (struct uhci_softc *)pipe->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; uhci_free_sqh(sc, upipe->u.bulk.sqh); pipe->endpoint->savedtoggle = upipe->nexttoggle; @@ -1923,10 +1920,9 @@ uhci_device_intr_transfer(struct usbd_xfer *xfer) usbd_status uhci_device_intr_start(struct usbd_xfer *xfer) { + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; - struct uhci_xfer *ex = UXFER(xfer); + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_soft_td *data, *dataend; struct uhci_soft_qh *sqh; usbd_status err; @@ -1944,7 +1940,7 @@ uhci_device_intr_start(struct usbd_xfer *xfer) panic("uhci_device_intr_start: a request"); #endif - endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; + endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; isread = UE_GET_DIR(endpt) == UE_DIR_IN; upipe->u.intr.isread = isread; @@ -1967,13 +1963,13 @@ uhci_device_intr_start(struct usbd_xfer *xfer) s = splusb(); /* Set up interrupt info. */ - ex->stdstart = data; - ex->stdend = dataend; + ux->stdstart = data; + ux->stdend = dataend; #ifdef DIAGNOSTIC - if (!ex->isdone) { - printf("uhci_device_intr_transfer: not done, ex=%p\n", ex); + if (!ux->isdone) { + printf("uhci_device_intr_transfer: not done, ux=%p\n", ux); } - ex->isdone = 0; + ux->isdone = 0; #endif DPRINTFN(10,("uhci_device_intr_start: qhs[0]=%p\n", @@ -1983,7 +1979,7 @@ uhci_device_intr_start(struct usbd_xfer *xfer) sqh->elink = data; sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); } - uhci_add_intr_list(sc, ex); + uhci_add_intr_list(sc, ux); xfer->status = USBD_IN_PROGRESS; splx(s); @@ -2059,13 +2055,12 @@ uhci_device_intr_close(struct usbd_pipe *pipe) usbd_status uhci_device_request(struct usbd_xfer *xfer) { + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; usb_device_request_t *req = &xfer->request; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; - int addr = dev->address; - int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; - struct uhci_xfer *ex = UXFER(xfer); + int addr = xfer->device->address; + int endpt = xfer->pipe->endpoint->edesc->bEndpointAddress; struct uhci_soft_td *setup, *data, *stat, *next, *dataend; struct uhci_soft_qh *sqh; u_int len; @@ -2080,7 +2075,7 @@ uhci_device_request(struct usbd_xfer *xfer) UGETW(req->wIndex), UGETW(req->wLength), addr, endpt)); - ls = dev->speed == USB_SPEED_LOW ? UHCI_TD_LS : 0; + ls = xfer->device->speed == USB_SPEED_LOW ? UHCI_TD_LS : 0; isread = req->bmRequestType & UT_READ; len = UGETW(req->wLength); @@ -2129,24 +2124,24 @@ uhci_device_request(struct usbd_xfer *xfer) #endif /* Set up interrupt info. */ - ex->stdstart = setup; - ex->stdend = stat; + ux->stdstart = setup; + ux->stdend = stat; #ifdef DIAGNOSTIC - if (!ex->isdone) { - printf("uhci_device_request: not done, ex=%p\n", ex); + if (!ux->isdone) { + printf("%s: not done, ux=%p\n", __func__, ux); } - ex->isdone = 0; + ux->isdone = 0; #endif sqh->elink = setup; sqh->qh.qh_elink = htole32(setup->physaddr | UHCI_PTR_TD); s = splusb(); - if (dev->speed == USB_SPEED_LOW) + if (xfer->device->speed == USB_SPEED_LOW) uhci_add_ls_ctrl(sc, sqh); else uhci_add_hs_ctrl(sc, sqh); - uhci_add_intr_list(sc, ex); + uhci_add_intr_list(sc, ux); #ifdef UHCI_DEBUG if (uhcidebug > 12) { struct uhci_soft_td *std; @@ -2176,7 +2171,7 @@ uhci_device_request(struct usbd_xfer *xfer) #endif if (xfer->timeout && !sc->sc_bus.use_polling) { timeout_del(&xfer->timeout_handle); - timeout_set(&xfer->timeout_handle, uhci_timeout, ex); + timeout_set(&xfer->timeout_handle, uhci_timeout, xfer); timeout_add_msec(&xfer->timeout_handle, xfer->timeout); } xfer->status = USBD_IN_PROGRESS; @@ -2214,9 +2209,8 @@ uhci_device_isoc_transfer(struct usbd_xfer *xfer) void uhci_device_isoc_enter(struct usbd_xfer *xfer) { + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; struct iso *iso = &upipe->u.iso; struct uhci_soft_td *std; u_int32_t buf, len, status; @@ -2248,7 +2242,7 @@ uhci_device_isoc_enter(struct usbd_xfer *xfer) } xfer->status = USBD_IN_PROGRESS; - UXFER(xfer)->curframe = next; + ((struct uhci_xfer *)xfer)->curframe = next; buf = DMAADDR(&xfer->dmabuf, 0); status = UHCI_TD_ZERO_ACTLEN(UHCI_TD_SET_ERRCNT(0) | @@ -2284,9 +2278,9 @@ uhci_device_isoc_enter(struct usbd_xfer *xfer) usbd_status uhci_device_isoc_start(struct usbd_xfer *xfer) { + struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; - struct uhci_softc *sc = (struct uhci_softc *)upipe->pipe.device->bus; - struct uhci_xfer *ex = UXFER(xfer); + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_soft_td *end; int s, i; @@ -2301,7 +2295,7 @@ uhci_device_isoc_start(struct usbd_xfer *xfer) #endif /* Find the last TD */ - i = UXFER(xfer)->curframe + xfer->nframes; + i = ux->curframe + xfer->nframes; if (i >= UHCI_VFRAMELIST_COUNT) i -= UHCI_VFRAMELIST_COUNT; end = upipe->u.iso.stds[i]; @@ -2316,14 +2310,14 @@ uhci_device_isoc_start(struct usbd_xfer *xfer) s = splusb(); /* Set up interrupt info. */ - ex->stdstart = end; - ex->stdend = end; + ux->stdstart = end; + ux->stdend = end; #ifdef DIAGNOSTIC - if (!ex->isdone) - printf("uhci_device_isoc_start: not done, ex=%p\n", ex); - ex->isdone = 0; + if (!ux->isdone) + printf("%s: not done, ux=%p\n", __func__, ux); + ux->isdone = 0; #endif - uhci_add_intr_list(sc, ex); + uhci_add_intr_list(sc, ux); splx(s); @@ -2338,6 +2332,7 @@ uhci_device_isoc_start(struct usbd_xfer *xfer) void uhci_device_isoc_abort(struct usbd_xfer *xfer) { + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; struct uhci_soft_td **stds = upipe->u.iso.stds; struct uhci_soft_td *std; @@ -2357,7 +2352,7 @@ uhci_device_isoc_abort(struct usbd_xfer *xfer) /* make hardware ignore it, */ nframes = xfer->nframes; - n = UXFER(xfer)->curframe; + n = ux->curframe; maxlen = 0; for (i = 0; i < nframes; i++) { std = stds[n]; @@ -2373,7 +2368,7 @@ uhci_device_isoc_abort(struct usbd_xfer *xfer) delay(maxlen); #ifdef DIAGNOSTIC - UXFER(xfer)->isdone = 1; + ux->isdone = 1; #endif /* Run callback and remove from interrupt list. */ usb_transfer_complete(xfer); @@ -2384,9 +2379,8 @@ uhci_device_isoc_abort(struct usbd_xfer *xfer) void uhci_device_isoc_close(struct usbd_pipe *pipe) { + struct uhci_softc *sc = (struct uhci_softc *)pipe->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; struct uhci_soft_td *std, *vstd; struct iso *iso; int i, s; @@ -2428,11 +2422,10 @@ uhci_device_isoc_close(struct usbd_pipe *pipe) usbd_status uhci_setup_isoc(struct usbd_pipe *pipe) { + struct uhci_softc *sc = (struct uhci_softc *)pipe->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)pipe; - struct usbd_device *dev = upipe->pipe.device; - struct uhci_softc *sc = (struct uhci_softc *)dev->bus; - int addr = upipe->pipe.device->address; - int endpt = upipe->pipe.endpoint->edesc->bEndpointAddress; + int addr = pipe->device->address; + int endpt = pipe->endpoint->edesc->bEndpointAddress; int rd = UE_GET_DIR(endpt) == UE_DIR_IN; struct uhci_soft_td *std, *vstd; u_int32_t token; @@ -2484,11 +2477,11 @@ uhci_setup_isoc(struct usbd_pipe *pipe) void uhci_device_isoc_done(struct usbd_xfer *xfer) { - struct uhci_xfer *ex = UXFER(xfer); + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; DPRINTFN(4, ("uhci_device_isoc_done: length=%d\n", xfer->actlen)); - if (!uhci_active_intr_list(ex)) + if (!uhci_active_intr_list(ux)) return; #ifdef DIAGNOSTIC @@ -2497,27 +2490,27 @@ uhci_device_isoc_done(struct usbd_xfer *xfer) return; } - if (ex->stdend == NULL) { + if (ux->stdend == NULL) { printf("uhci_device_isoc_done: xfer=%p stdend==NULL\n", xfer); #ifdef UHCI_DEBUG - uhci_dump_xfer(ex); + uhci_dump_xfer(ux); #endif return; } #endif /* Turn off the interrupt since it is active even if the TD is not. */ - ex->stdend->td.td_status &= htole32(~UHCI_TD_IOC); + ux->stdend->td.td_status &= htole32(~UHCI_TD_IOC); - uhci_del_intr_list(ex); /* remove from active list */ + uhci_del_intr_list(ux); /* remove from active list */ } void uhci_device_intr_done(struct usbd_xfer *xfer) { - struct uhci_xfer *ex = UXFER(xfer); struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; struct uhci_soft_qh *sqh; int i, npoll; @@ -2529,7 +2522,7 @@ uhci_device_intr_done(struct usbd_xfer *xfer) sqh->elink = NULL; sqh->qh.qh_elink = htole32(UHCI_PTR_T); } - uhci_free_std_chain(sc, ex->stdstart, NULL); + uhci_free_std_chain(sc, ux->stdstart, NULL); /* XXX Wasteful. */ if (xfer->pipe->repeat) { @@ -2551,13 +2544,13 @@ uhci_device_intr_done(struct usbd_xfer *xfer) } #endif - ex->stdstart = data; - ex->stdend = dataend; + ux->stdstart = data; + ux->stdend = dataend; #ifdef DIAGNOSTIC - if (!ex->isdone) { - printf("uhci_device_intr_done: not done, ex=%p\n", ex); + if (!ux->isdone) { + printf("%s: not done, ux=%p\n", __func__, ux); } - ex->isdone = 0; + ux->isdone = 0; #endif for (i = 0; i < npoll; i++) { sqh = upipe->u.intr.qhs[i]; @@ -2565,11 +2558,11 @@ uhci_device_intr_done(struct usbd_xfer *xfer) sqh->qh.qh_elink = htole32(data->physaddr | UHCI_PTR_TD); } xfer->status = USBD_IN_PROGRESS; - /* The ex is already on the examined list, just leave it. */ + /* The ux is already on the examined list, just leave it. */ } else { DPRINTFN(5,("uhci_device_intr_done: removing\n")); - if (uhci_active_intr_list(ex)) - uhci_del_intr_list(ex); + if (uhci_active_intr_list(ux)) + uhci_del_intr_list(ux); } } @@ -2577,27 +2570,27 @@ uhci_device_intr_done(struct usbd_xfer *xfer) void uhci_device_ctrl_done(struct usbd_xfer *xfer) { - struct uhci_xfer *ex = UXFER(xfer); struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; #ifdef DIAGNOSTIC if (!(xfer->rqflags & URQ_REQUEST)) panic("uhci_device_ctrl_done: not a request"); #endif - if (!uhci_active_intr_list(ex)) + if (!uhci_active_intr_list(ux)) return; - uhci_del_intr_list(ex); /* remove from active list */ + uhci_del_intr_list(ux); /* remove from active list */ - if (upipe->pipe.device->speed == USB_SPEED_LOW) + if (xfer->device->speed == USB_SPEED_LOW) uhci_remove_ls_ctrl(sc, upipe->u.ctl.sqh); else uhci_remove_hs_ctrl(sc, upipe->u.ctl.sqh); if (upipe->u.ctl.length != 0) - uhci_free_std_chain(sc, ex->stdstart->link.std, ex->stdend); + uhci_free_std_chain(sc, ux->stdstart->link.std, ux->stdend); DPRINTFN(5, ("uhci_device_ctrl_done: length=%d\n", xfer->actlen)); } @@ -2606,21 +2599,21 @@ uhci_device_ctrl_done(struct usbd_xfer *xfer) void uhci_device_bulk_done(struct usbd_xfer *xfer) { - struct uhci_xfer *ex = UXFER(xfer); struct uhci_softc *sc = (struct uhci_softc *)xfer->device->bus; struct uhci_pipe *upipe = (struct uhci_pipe *)xfer->pipe; + struct uhci_xfer *ux = (struct uhci_xfer *)xfer; - DPRINTFN(5,("uhci_device_bulk_done: xfer=%p ex=%p sc=%p upipe=%p\n", - xfer, ex, sc, upipe)); + DPRINTFN(5,("uhci_device_bulk_done: xfer=%p ux=%p sc=%p upipe=%p\n", + xfer, ux, sc, upipe)); - if (!uhci_active_intr_list(ex)) + if (!uhci_active_intr_list(ux)) return; - uhci_del_intr_list(ex); /* remove from active list */ + uhci_del_intr_list(ux); /* remove from active list */ uhci_remove_bulk(sc, upipe->u.bulk.sqh); - uhci_free_std_chain(sc, ex->stdstart, NULL); + uhci_free_std_chain(sc, ux->stdstart, NULL); DPRINTFN(5, ("uhci_device_bulk_done: length=%d\n", xfer->actlen)); } @@ -3344,7 +3337,7 @@ uhci_root_intr_abort(struct usbd_xfer *xfer) } xfer->status = USBD_CANCELLED; #ifdef DIAGNOSTIC - UXFER(xfer)->isdone = 1; + ((struct uhci_xfer *)xfer)->isdone = 1; #endif usb_transfer_complete(xfer); } diff --git a/sys/dev/usb/uhcivar.h b/sys/dev/usb/uhcivar.h index 4f042657363..a078d127ff6 100644 --- a/sys/dev/usb/uhcivar.h +++ b/sys/dev/usb/uhcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uhcivar.h,v 1.29 2014/03/25 20:27:37 mpi Exp $ */ +/* $OpenBSD: uhcivar.h,v 1.30 2014/04/27 14:48:10 mpi Exp $ */ /* $NetBSD: uhcivar.h,v 1.36 2002/12/31 00:39:11 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.14 1999/11/17 22:33:42 n_hibma Exp $ */ @@ -74,8 +74,6 @@ struct uhci_xfer { #endif }; -#define UXFER(xfer) ((struct uhci_xfer *)(xfer)) - /* * Extra information that we need for a TD. */ -- 2.20.1