From a9909bdaab85a509ae49d3904d8cbeca5929de15 Mon Sep 17 00:00:00 2001 From: Nick Hibma Date: Sun, 28 Nov 1999 21:01:06 +0000 Subject: [PATCH] Synchronisation with NetBSD 1999/11/27 - more req[uest]->xfer changes. - get the corresponding NetBSD Id's right ohci.c - move untimeout above print statement - remove usb_delay that panics the system (tsleep in intr context) when ohcidebug > 5. ugen.c - create the devices for endpoints with make_dev. uhub.c - change from using usbdebug to uhubdebug - add more debugging statements --- sys/dev/usb/ohci.c | 63 ++++++++++++++--------------- sys/dev/usb/ugen.c | 86 +++++++++++++++++++++++++--------------- sys/dev/usb/uhci.c | 45 +++++++++++---------- sys/dev/usb/uhub.c | 34 ++++++++++------ sys/dev/usb/ulpt.c | 8 ++-- sys/dev/usb/usbdi.c | 71 +++++++++++++++++---------------- sys/dev/usb/usbdi.h | 14 +++---- sys/dev/usb/usbdi_util.c | 8 ++-- 8 files changed, 184 insertions(+), 145 deletions(-) diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c index b09e0290d597..543f3558fb23 100644 --- a/sys/dev/usb/ohci.c +++ b/sys/dev/usb/ohci.c @@ -1,4 +1,4 @@ -/* $NetBSD: ohci.c,v 1.52 1999/10/13 08:10:55 augustss Exp $ */ +/* $NetBSD: ohci.c,v 1.55 1999/11/18 23:32:26 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -57,7 +57,7 @@ #include #include #include -#if defined(DIAGNOSTIC) && defined(__i386__) +#if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__) #include #endif #endif @@ -91,7 +91,7 @@ struct cfdriver ohci_cd = { #ifdef OHCI_DEBUG #define DPRINTF(x) if (ohcidebug) logprintf x #define DPRINTFN(n,x) if (ohcidebug>(n)) logprintf x -int ohcidebug = 1; +int ohcidebug = 0; #else #define DPRINTF(x) #define DPRINTFN(n,x) @@ -109,10 +109,10 @@ int ohcidebug = 1; struct ohci_pipe; -static ohci_soft_ed_t *ohci_alloc_sed __P((ohci_softc_t *)); +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 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 @@ -135,11 +135,11 @@ static void ohci_process_done __P((ohci_softc_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 *, +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 *, +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 *, @@ -193,9 +193,9 @@ 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, +static void ohci_abort_xfer __P((usbd_xfer_handle xfer, usbd_status status)); -static void ohci_abort_req_end __P((void *)); +static void ohci_abort_xfer_end __P((void *)); static void ohci_device_clear_toggle __P((usbd_pipe_handle pipe)); static void ohci_noop __P((usbd_pipe_handle pipe)); @@ -524,27 +524,29 @@ ohci_init(sc) u_int32_t s, ctl, ival, hcr, fm, per; DPRINTF(("ohci_init: start\n")); - rev = OREAD4(sc, OHCI_REVISION); #if defined(__OpenBSD__) printf(","); #else - printf("%s", USBDEVNAME(sc->sc_bus.bdev)); + printf("%s:", USBDEVNAME(sc->sc_bus.bdev)); #endif + rev = OREAD4(sc, OHCI_REVISION); 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)); + sc->sc_bus.usbrev = USBREV_UNKNOWN; return (USBD_INVAL); } + sc->sc_bus.usbrev = USBREV_1_0; for (i = 0; i < OHCI_HASH_SIZE; i++) LIST_INIT(&sc->sc_hash_tds[i]); /* Allocate the HCCA area. */ err = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE, - OHCI_HCCA_ALIGN, &sc->sc_hccadma); + OHCI_HCCA_ALIGN, &sc->sc_hccadma); if (err) return (err); sc->sc_hcca = (struct ohci_hcca *)KERNADDR(&sc->sc_hccadma); @@ -801,7 +803,7 @@ ohci_intr(p) if (sc->sc_bus.use_polling) return (0); - return (ohci_intr1(sc)); + return (ohci_intr1(sc)); } static int @@ -943,12 +945,12 @@ ohci_process_done(sc, done) #endif for (std = sdone; std; std = stdnext) { - xfer = std->xfer; stdnext = std->dnext; + xfer = std->xfer; + usb_untimeout(ohci_timeout, xfer, xfer->timo_handle); 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, xfer, xfer->timo_handle); if (xfer->status == USBD_CANCELLED || xfer->status == USBD_TIMEOUT) { DPRINTF(("ohci_process_done: cancel/timeout %p\n", @@ -1284,7 +1286,6 @@ ohci_device_request(xfer) #ifdef OHCI_DEBUG if (ohcidebug > 5) { - usb_delay_ms(&sc->sc_bus, 5); DPRINTF(("ohci_device_request: status=%x\n", OREAD4(sc, OHCI_COMMAND_STATUS))); ohci_dump_ed(sed); @@ -1382,7 +1383,7 @@ ohci_hash_find_td(sc, a) ohci_soft_td_t *std; for (std = LIST_FIRST(&sc->sc_hash_tds[h]); - std != NULL; + std != NULL; std = LIST_NEXT(std, hnext)) if (std->physaddr == a) return (std); @@ -1400,7 +1401,7 @@ ohci_timeout(addr) s = splusb(); xfer->device->bus->intr_context++; - ohci_abort_req(xfer, USBD_TIMEOUT); + ohci_abort_xfer(xfer, USBD_TIMEOUT); xfer->device->bus->intr_context--; splx(s); } @@ -1554,7 +1555,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 != NULL; + std != NULL; std = LIST_NEXT(std, hnext)) if (std->physaddr == td) break; @@ -1585,38 +1586,38 @@ ohci_close_pipe(pipe, head) * interrupt processing to process it. */ void -ohci_abort_req(xfer, status) +ohci_abort_xfer(xfer, status) usbd_xfer_handle xfer; usbd_status status; { struct ohci_pipe *opipe = (struct ohci_pipe *)xfer->pipe; ohci_soft_ed_t *sed; - DPRINTF(("ohci_abort_req: xfer=%p pipe=%p\n", xfer, opipe)); + DPRINTF(("ohci_abort_xfer: xfer=%p pipe=%p\n", xfer, opipe)); xfer->status = status; usb_untimeout(ohci_timeout, xfer, xfer->timo_handle); sed = opipe->sed; - DPRINTFN(1,("ohci_abort_req: stop ed=%p\n", sed)); + DPRINTFN(1,("ohci_abort_xfer: stop ed=%p\n", sed)); sed->ed.ed_flags |= LE(OHCI_ED_SKIP); /* force hardware skip */ 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); + timeout(ohci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND); } else { -#if defined(DIAGNOSTIC) && defined(__i386__) +#if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__) 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); + ohci_abort_xfer_end(xfer); } } void -ohci_abort_req_end(v) +ohci_abort_xfer_end(v) void *v; { usbd_xfer_handle xfer = v; @@ -1631,7 +1632,7 @@ ohci_abort_req_end(v) p = xfer->hcpriv; #ifdef DIAGNOSTIC if (p == NULL) { - printf("ohci_abort_req: hcpriv==0\n"); + printf("ohci_abort_xfer: hcpriv==0\n"); return; } #endif @@ -1642,7 +1643,7 @@ ohci_abort_req_end(v) } sed = opipe->sed; - DPRINTFN(2,("ohci_abort_req: set hd=%x, tl=%x\n", + DPRINTFN(2,("ohci_abort_xfer: set hd=%x, tl=%x\n", (int)LE(p->physaddr), (int)LE(sed->ed.ed_tailp))); sed->ed.ed_headp = p->physaddr; /* unlink TDs */ sed->ed.ed_flags &= LE(~OHCI_ED_SKIP); /* remove hardware skip */ @@ -2169,7 +2170,7 @@ ohci_device_ctrl_abort(xfer) usbd_xfer_handle xfer; { DPRINTF(("ohci_device_ctrl_abort: xfer=%p\n", xfer)); - ohci_abort_req(xfer, USBD_CANCELLED); + ohci_abort_xfer(xfer, USBD_CANCELLED); } /* Close a device control pipe. */ @@ -2312,7 +2313,7 @@ ohci_device_bulk_abort(xfer) usbd_xfer_handle xfer; { DPRINTF(("ohci_device_bulk_abort: xfer=%p\n", xfer)); - ohci_abort_req(xfer, USBD_CANCELLED); + ohci_abort_xfer(xfer, USBD_CANCELLED); } /* @@ -2431,7 +2432,7 @@ ohci_device_intr_abort(xfer) DPRINTF(("ohci_device_intr_abort: remove\n")); xfer->pipe->intrxfer = NULL; } - ohci_abort_req(xfer, USBD_CANCELLED); + ohci_abort_xfer(xfer, USBD_CANCELLED); } /* Close a device interrupt pipe. */ diff --git a/sys/dev/usb/ugen.c b/sys/dev/usb/ugen.c index cd0e6cc9dfa4..83a814f6dc60 100644 --- a/sys/dev/usb/ugen.c +++ b/sys/dev/usb/ugen.c @@ -149,7 +149,6 @@ static usb_config_descriptor_t *ugen_get_cdesc __P((struct ugen_softc *sc, static usbd_status ugen_set_interface __P((struct ugen_softc *, int, int)); static int ugen_get_alt_index __P((struct ugen_softc *sc, int ifaceidx)); -#define UGENENDPMAX 16 /* maximum number of endpoints, see usb spec */ #define UGENUNIT(n) ((minor(n) >> 4) & 0xf) #define UGENENDPOINT(n) (minor(n) & 0xf) #define UGENDEV(u, e) (makedev(UGEN_CDEV_MAJOR, ((u) << 4) | (e))) @@ -187,16 +186,6 @@ USB_ATTACH(ugen) USB_ATTACH_ERROR_RETURN; } -#ifdef __FreeBSD__ - { - static int global_init_done = 0; - if (!global_init_done) { - cdevsw_add(&ugen_cdevsw); - global_init_done = 1; - } - } -#endif - USB_ATTACH_SUCCESS_RETURN; } @@ -237,18 +226,42 @@ ugen_set_config(sc, configno) return (err); for (endptno = 0; endptno < nendpt; endptno++) { ed = usbd_interface2endpoint_descriptor(iface,endptno); - endpt = ed->bEndpointAddress; - dir = UE_GET_DIR(endpt) == UE_DIR_IN ? IN : OUT; - sce = &sc->sc_endpoints[UE_GET_ADDR(endpt)][dir]; + endpt = UE_GET_ADDR(ed->bEndpointAddress); + dir = UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN? + IN : OUT; + + sce = &sc->sc_endpoints[endpt][dir]; DPRINTFN(1,("ugen_set_config: endptno %d, endpt=0x%02x" "(%d,%d), sce=%p\n", - endptno, endpt, UE_GET_ADDR(endpt), - UE_GET_DIR(endpt), sce)); + endptno, endpt, endpt, dir, sce)); + sce->sc = sc; sce->edesc = ed; sce->iface = iface; } } + + +#if defined(__FreeBSD__) + for (endptno = 0; endptno < USB_MAX_ENDPOINTS; endptno++) { + if (sc->sc_endpoints[endptno][IN].sc != NULL || + sc->sc_endpoints[endptno][OUT].sc != NULL ) { + /* endpt can be 0x81 and 0x01, representing + * endpoint address 0x01 and IN/OUT directions. + * We map both endpts to the same device, + * IN is reading from it, OUT is writing to it. + * + * In the if clause above we check whether one + * of the structs is populated. + */ + make_dev(&ugen_cdevsw, endptno, + UID_ROOT, GID_OPERATOR, 0644, + "ugen%d.%d", + USBDEVUNIT(sc->sc_dev), endptno); + } + } +#endif + return (USBD_NORMAL_COMPLETION); } @@ -409,9 +422,7 @@ ugen_do_read(sc, endpt, uio, flag) int error = 0; u_char buffer[UGEN_CHUNK]; -#ifdef __NetBSD__ - DPRINTFN(5, ("ugenread: %d:%d\n", sc->sc_dev.dv_unit, endpt)); -#endif + DPRINTFN(5, ("%s: ugenread: %d\n", USBDEVNAME(sc->sc_dev), endpt)); if (sc->sc_dying) return (EIO); @@ -469,7 +480,7 @@ ugen_do_read(sc, endpt, uio, flag) } break; case UE_BULK: - xfer = usbd_alloc_request(sc->sc_udev); + xfer = usbd_alloc_xfer(sc->sc_udev); if (xfer == 0) return (ENOMEM); while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) { @@ -494,7 +505,7 @@ ugen_do_read(sc, endpt, uio, flag) if (error || tn < n) break; } - usbd_free_request(xfer); + usbd_free_xfer(xfer); break; default: return (ENXIO); @@ -556,7 +567,7 @@ ugen_do_write(sc, endpt, uio, flag) switch (sce->edesc->bmAttributes & UE_XFERTYPE) { case UE_BULK: - xfer = usbd_alloc_request(sc->sc_udev); + xfer = usbd_alloc_xfer(sc->sc_udev); if (xfer == 0) return (EIO); while ((n = min(UGEN_BBSIZE, uio->uio_resid)) != 0) { @@ -574,7 +585,7 @@ ugen_do_write(sc, endpt, uio, flag) break; } } - usbd_free_request(xfer); + usbd_free_xfer(xfer); break; default: return (ENXIO); @@ -631,9 +642,9 @@ USB_DETACH(ugen) #if defined(__NetBSD__) || defined(__OpenBSD__) int maj, mn; #elif defined(__FreeBSD__) - struct vnode *vp; + int endptno; dev_t dev; - int endpt; + struct vnode *vp; #endif #if defined(__NetBSD__) || defined(__OpenBSD__) @@ -672,11 +683,24 @@ USB_DETACH(ugen) mn = self->dv_unit * USB_MAX_ENDPOINTS; vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR); #elif defined(__FreeBSD__) - for (endpt = 0; endpt < UGENENDPMAX; endpt++) { - dev = UGENDEV(device_get_unit(self), endpt); - vp = SLIST_FIRST(&dev->si_hlist); - if (vp) - VOP_REVOKE(vp, REVOKEALL); + for (endptno = 0; endptno < USB_MAX_ENDPOINTS; endptno++) { + if (sc->sc_endpoints[endptno][IN].sc != NULL || + sc->sc_endpoints[endptno][OUT].sc != NULL ) { + /* endpt can be 0x81 and 0x01, representing + * endpoint address 0x01 and IN/OUT directions. + * We map both endpoint addresses to the same device, + * IN is reading from it, OUT is writing to it. + * + * In the if clause above we check whether one + * of the structs is populated. + */ + dev = UGENDEV(USBDEVUNIT(sc->sc_dev), endptno); + vp = SLIST_FIRST(&dev->si_hlist); + if (vp) + VOP_REVOKE(vp, REVOKEALL); + + destroy_dev(dev); + } } #endif @@ -703,7 +727,7 @@ ugenintr(xfer, addr, status) return; } - usbd_get_request_status(xfer, 0, 0, &count, 0); + usbd_get_xfer_status(xfer, 0, 0, &count, 0); ibuf = sce->ibuf; DPRINTFN(5, ("ugenintr: xfer=%p status=%d count=%d\n", diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c index db8726af7329..92fd1af9338b 100644 --- a/sys/dev/usb/uhci.c +++ b/sys/dev/usb/uhci.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhci.c,v 1.63 1999/11/12 00:34:57 augustss Exp $ */ +/* $NetBSD: uhci.c,v 1.67 1999/11/18 23:32:28 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -162,12 +162,12 @@ static uhci_intr_info_t *uhci_alloc_intr_info __P((uhci_softc_t *)); static void uhci_free_intr_info __P((uhci_intr_info_t *ii)); #if 0 static void uhci_enter_ctl_q __P((uhci_softc_t *, uhci_soft_qh_t *, - uhci_intr_info_t *)); + uhci_intr_info_t *)); static void uhci_exit_ctl_q __P((uhci_softc_t *, uhci_soft_qh_t *)); #endif static void uhci_free_std_chain __P((uhci_softc_t *, - uhci_soft_td_t *, uhci_soft_td_t *)); + uhci_soft_td_t *, uhci_soft_td_t *)); static usbd_status uhci_alloc_std_chain __P((struct uhci_pipe *, uhci_softc_t *, int, int, int, usb_dma_t *, uhci_soft_td_t **, uhci_soft_td_t **)); @@ -177,9 +177,9 @@ static void uhci_waitintr __P((uhci_softc_t *, static void uhci_check_intr __P((uhci_softc_t *, uhci_intr_info_t *)); static void uhci_idone __P((uhci_intr_info_t *)); -static void uhci_abort_req __P((usbd_xfer_handle, +static void uhci_abort_xfer __P((usbd_xfer_handle, usbd_status status)); -static void uhci_abort_req_end __P((void *v)); +static void uhci_abort_xfer_end __P((void *v)); static void uhci_timeout __P((void *)); static void uhci_lock_frames __P((uhci_softc_t *)); static void uhci_unlock_frames __P((uhci_softc_t *)); @@ -188,6 +188,7 @@ static void uhci_add_bulk __P((uhci_softc_t *, uhci_soft_qh_t *)); static void uhci_remove_ctrl __P((uhci_softc_t *,uhci_soft_qh_t *)); static void uhci_remove_bulk __P((uhci_softc_t *,uhci_soft_qh_t *)); static int uhci_str __P((usb_string_descriptor_t *, int, char *)); + static usbd_status uhci_setup_isoc __P((usbd_pipe_handle pipe)); static void uhci_device_isoc_enter __P((usbd_xfer_handle)); @@ -480,7 +481,7 @@ uhci_allocm(bus, dma, size) u_int32_t size; { return (usb_allocmem(&((struct uhci_softc *)bus)->sc_bus, size, 0, - dma)); + dma)); } void @@ -561,7 +562,7 @@ uhci_power(why, v) } splx(s); } -#endif /* defined(__NetBSD__) */ +#endif #ifdef UHCI_DEBUG static void @@ -1064,7 +1065,8 @@ uhci_idone(ii) } #ifdef UHCI_DEBUG - DPRINTFN(10, ("uhci_idone: ii=%p ready\n", ii)); + DPRINTFN(10, ("uhci_idone: ii=%p, xfer=%p, pipe=%p ready\n", + ii, xfer, upipe)); if (uhcidebug > 10) uhci_dump_tds(ii->stdstart); #endif @@ -1125,7 +1127,7 @@ uhci_timeout(addr) #endif ii->xfer->device->bus->intr_context++; - uhci_abort_req(ii->xfer, USBD_TIMEOUT); + uhci_abort_xfer(ii->xfer, USBD_TIMEOUT); ii->xfer->device->bus->intr_context--; } @@ -1253,7 +1255,7 @@ uhci_alloc_std(sc) return (0); for(i = 0; i < UHCI_STD_CHUNK; i++) { offs = i * UHCI_STD_SIZE; - std = (uhci_soft_td_t *)((char *)KERNADDR(&dma) + offs); + std = (uhci_soft_td_t *)((char *)KERNADDR(&dma) +offs); std->physaddr = DMAADDR(&dma) + offs; std->link.std = sc->sc_freetds; sc->sc_freetds = std; @@ -1541,11 +1543,11 @@ uhci_device_bulk_abort(xfer) usbd_xfer_handle xfer; { DPRINTF(("uhci_device_bulk_abort:\n")); - uhci_abort_req(xfer, USBD_CANCELLED); + uhci_abort_xfer(xfer, USBD_CANCELLED); } void -uhci_abort_req(xfer, status) +uhci_abort_xfer(xfer, status) usbd_xfer_handle xfer; usbd_status status; { @@ -1553,6 +1555,8 @@ uhci_abort_req(xfer, status) uhci_intr_info_t *ii = upipe->iinfo; uhci_soft_td_t *std; + DPRINTFN(1,("uhci_abort_xfer: xfer=%p, status=%d\n", xfer, status)); + /* Make interrupt routine ignore it, */ xfer->status = status; @@ -1568,20 +1572,20 @@ uhci_abort_req(xfer, status) /* make sure hardware has completed, */ if (xfer->device->bus->intr_context) { /* We have no process context, so we can't use tsleep(). */ - timeout(uhci_abort_req_end, xfer, hz / USB_FRAMES_PER_SECOND); + timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND); } else { -#if defined(DIAGNOSTIC) && defined(__i386__) +#if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__) KASSERT(intr_nesting_level == 0, ("ohci_abort_req in interrupt context")); #endif usb_delay_ms(xfer->pipe->device->bus, 1); /* and call final part of interrupt handler. */ - uhci_abort_req_end(xfer); + uhci_abort_xfer_end(xfer); } } void -uhci_abort_req_end(v) +uhci_abort_xfer_end(v) void *v; { usbd_xfer_handle xfer = v; @@ -1735,7 +1739,7 @@ uhci_device_ctrl_abort(xfer) usbd_xfer_handle xfer; { DPRINTF(("uhci_device_ctrl_abort:\n")); - uhci_abort_req(xfer, USBD_CANCELLED); + uhci_abort_xfer(xfer, USBD_CANCELLED); } /* Close a device control pipe. */ @@ -1759,7 +1763,7 @@ uhci_device_intr_abort(xfer) DPRINTFN(1,("uhci_device_intr_abort: remove\n")); xfer->pipe->intrxfer = 0; } - uhci_abort_req(xfer, USBD_CANCELLED); + uhci_abort_xfer(xfer, USBD_CANCELLED); } /* Close a device interrupt pipe. */ @@ -1971,6 +1975,7 @@ uhci_device_isoc_enter(xfer) if (xfer->status == USBD_IN_PROGRESS) { /* This request has already been entered into the frame list */ + /* XXX */ } #ifdef DIAGNOSTIC @@ -2087,11 +2092,11 @@ uhci_device_isoc_abort(xfer) /* make sure hardware has completed, */ if (xfer->device->bus->intr_context) { /* We have no process context, so we can't use tsleep(). */ - timeout(uhci_abort_req_end, xfer, hz / USB_FRAMES_PER_SECOND); + timeout(uhci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND); } else { usb_delay_ms(xfer->pipe->device->bus, 1); /* and call final part of interrupt handler. */ - uhci_abort_req_end(xfer); + uhci_abort_xfer_end(xfer); } } diff --git a/sys/dev/usb/uhub.c b/sys/dev/usb/uhub.c index 015dce995ed6..f8d9c2acd4cb 100644 --- a/sys/dev/usb/uhub.c +++ b/sys/dev/usb/uhub.c @@ -1,4 +1,4 @@ -/* $NetBSD: uhub.c,v 1.32 1999/10/13 08:10:56 augustss Exp $ */ +/* $NetBSD: uhub.c,v 1.34 1999/11/18 23:32:29 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -63,9 +63,9 @@ #include #ifdef UHUB_DEBUG -#define DPRINTF(x) if (usbdebug) logprintf x -#define DPRINTFN(n,x) if (usbdebug>(n)) logprintf x -extern int usbdebug; +#define DPRINTF(x) if (uhubdebug) logprintf x +#define DPRINTFN(n,x) if (uhubdebug>(n)) logprintf x +int uhubdebug; #else #define DPRINTF(x) #define DPRINTFN(n,x) @@ -81,7 +81,7 @@ struct uhub_softc { static usbd_status uhub_init_port __P((struct usbd_port *)); static usbd_status uhub_explore __P((usbd_device_handle hub)); -static void uhub_intr __P((usbd_xfer_handle, usbd_private_handle, usbd_status)); +static void uhub_intr __P((usbd_xfer_handle, usbd_private_handle,usbd_status)); #if defined(__FreeBSD__) static bus_child_detached_t uhub_child_detached; @@ -95,7 +95,7 @@ static bus_child_detached_t uhub_child_detached; */ #if defined(__NetBSD__) || defined(__OpenBSD__) -USB_DECLARE_DRIVER(uhub) +USB_DECLARE_DRIVER(uhub); /* Create the driver instance for the hub connected to hub case */ struct cfattach uhub_uhub_ca = { @@ -236,7 +236,7 @@ USB_ATTACH(uhub) } err = usbd_open_pipe_intr(iface, ed->bEndpointAddress, - USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status, + USBD_SHORT_XFER_OK, &sc->sc_ipipe, sc, sc->sc_status, sizeof(sc->sc_status), uhub_intr); if (err) { printf("%s: cannot open interrupt pipe\n", @@ -364,9 +364,10 @@ uhub_explore(dev) } status = UGETW(up->status.wPortStatus); change = UGETW(up->status.wPortChange); - DPRINTFN(5, ("uhub_explore: port %d status 0x%04x 0x%04x\n", - port, status, change)); + DPRINTFN(3,("uhub_explore: port %d status 0x%04x 0x%04x\n", + port, status, change)); if (change & UPS_C_PORT_ENABLED) { + DPRINTF(("uhub_explore: C_PORT_ENABLED\n")); usbd_clear_port_feature(dev, port, UHF_C_PORT_ENABLE); if (status & UPS_PORT_ENABLED) { printf("%s: illegal enable change, port %d\n", @@ -386,6 +387,8 @@ uhub_explore(dev) } } if (!(change & UPS_C_CONNECT_STATUS)) { + DPRINTFN(3,("uhub_explore: port=%d !C_CONNECT_" + "STATUS\n", port)); /* No status change, just do recursive explore. */ if (up->device && up->device->hub) up->device->hub->explore(up->device); @@ -405,14 +408,17 @@ uhub_explore(dev) disco: if (up->device != NULL) { /* Disconnected */ - DPRINTF(("uhub_explore: device %d disappeared " + DPRINTF(("uhub_explore: device addr=%d disappeared " "on port %d\n", up->device->address, port)); usb_disconnect_port(up, USBDEV(sc->sc_dev)); usbd_clear_port_feature(dev, port, UHF_C_PORT_CONNECTION); } - if (!(status & UPS_CURRENT_CONNECT_STATUS)) + if (!(status & UPS_CURRENT_CONNECT_STATUS)) { + DPRINTFN(3,("uhub_explore: port=%d !CURRENT_CONNECT" + "_STATUS\n", port)); continue; + } /* Connected */ up->restartcnt = 0; @@ -421,9 +427,11 @@ uhub_explore(dev) usbd_delay_ms(dev, USB_PORT_POWERUP_DELAY); /* Reset port, which implies enabling it. */ - if (usbd_reset_port(dev, port, &up->status) != - USBD_NORMAL_COMPLETION) + if (usbd_reset_port(dev, port, &up->status)) { + DPRINTF(("uhub_explore: port=%d reset failed\n", + port)); continue; + } /* Get device info and set its address. */ err = usbd_new_device(USBDEV(sc->sc_dev), dev->bus, diff --git a/sys/dev/usb/ulpt.c b/sys/dev/usb/ulpt.c index 8747d9b2d026..2388f3028cef 100644 --- a/sys/dev/usb/ulpt.c +++ b/sys/dev/usb/ulpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: ulpt.c,v 1.27 1999/10/13 08:10:57 augustss Exp $ */ +/* $NetBSD: ulpt.c,v 1.29 1999/11/17 23:00:50 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -502,12 +502,12 @@ ulpt_do_write(sc, uio, flags) usbd_status err; DPRINTF(("ulptwrite\n")); - xfer = usbd_alloc_request(sc->sc_udev); + xfer = usbd_alloc_xfer(sc->sc_udev); if (xfer == NULL) return (ENOMEM); bufp = usbd_alloc_buffer(xfer, ULPT_BSIZE); if (bufp == NULL) { - usbd_free_request(xfer); + usbd_free_xfer(xfer); return (ENOMEM); } while ((n = min(ULPT_BSIZE, uio->uio_resid)) != 0) { @@ -524,7 +524,7 @@ ulpt_do_write(sc, uio, flags) break; } } - usbd_free_request(xfer); + usbd_free_xfer(xfer); return (error); } diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c index c7aa594eebb3..bbd5f930f4b0 100644 --- a/sys/dev/usb/usbdi.c +++ b/sys/dev/usb/usbdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi.c,v 1.47 1999/10/13 23:46:10 augustss Exp $ */ +/* $NetBSD: usbdi.c,v 1.51 1999/11/18 23:32:33 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -81,8 +81,8 @@ static void usbd_do_request_async_cb __P((usbd_xfer_handle, usbd_private_handle, usbd_status)); static void usbd_start_next __P((usbd_pipe_handle pipe)); -static SIMPLEQ_HEAD(, usbd_xfer) usbd_free_requests = - SIMPLEQ_HEAD_INITIALIZER(usbd_free_requests); +static SIMPLEQ_HEAD(, usbd_xfer) usbd_free_xfers = + SIMPLEQ_HEAD_INITIALIZER(usbd_free_xfers); static int usbd_nbuses = 0; @@ -98,12 +98,12 @@ usbd_finish() usbd_xfer_handle xfer; if (--usbd_nbuses == 0) { - /* Last controller is gone, free all requests. */ + /* Last controller is gone, free all xfers. */ for (;;) { - xfer = SIMPLEQ_FIRST(&usbd_free_requests); + xfer = SIMPLEQ_FIRST(&usbd_free_xfers); if (xfer == NULL) break; - SIMPLEQ_REMOVE_HEAD(&usbd_free_requests, xfer, next); + SIMPLEQ_REMOVE_HEAD(&usbd_free_xfers, xfer, next); free(xfer, M_USB); } } @@ -153,6 +153,8 @@ usbd_open_pipe(iface, address, flags, pipe) for (i = 0; i < iface->idesc->bNumEndpoints; i++) { ep = &iface->endpoints[i]; + if (ep->edesc == NULL) + return (USBD_IOERROR); if (ep->edesc->bEndpointAddress == address) goto found; } @@ -187,12 +189,12 @@ usbd_open_pipe_intr(iface, address, flags, pipe, priv, buffer, length, cb) err = usbd_open_pipe(iface, address, USBD_EXCLUSIVE_USE, &ipipe); if (err) return (err); - xfer = usbd_alloc_request(iface->device); + xfer = usbd_alloc_xfer(iface->device); if (xfer == NULL) { err = USBD_NOMEM; goto bad1; } - usbd_setup_request(xfer, ipipe, priv, buffer, length, flags, + usbd_setup_xfer(xfer, ipipe, priv, buffer, length, flags, USBD_NO_TIMEOUT, cb); ipipe->intrxfer = xfer; ipipe->repeat = 1; @@ -205,7 +207,7 @@ usbd_open_pipe_intr(iface, address, flags, pipe, priv, buffer, length, cb) bad2: ipipe->intrxfer = NULL; ipipe->repeat = 0; - usbd_free_request(xfer); + usbd_free_xfer(xfer); bad1: usbd_close_pipe(ipipe); return (err); @@ -230,7 +232,7 @@ usbd_close_pipe(pipe) pipe->endpoint->refcnt--; pipe->methods->close(pipe); if (pipe->intrxfer != NULL) - usbd_free_request(pipe->intrxfer); + usbd_free_xfer(pipe->intrxfer); free(pipe, M_USB); return (USBD_NORMAL_COMPLETION); } @@ -349,37 +351,37 @@ usbd_get_buffer(xfer) } usbd_xfer_handle -usbd_alloc_request(dev) +usbd_alloc_xfer(dev) usbd_device_handle dev; { usbd_xfer_handle xfer; - xfer = SIMPLEQ_FIRST(&usbd_free_requests); + xfer = SIMPLEQ_FIRST(&usbd_free_xfers); if (xfer != NULL) - SIMPLEQ_REMOVE_HEAD(&usbd_free_requests, xfer, next); + SIMPLEQ_REMOVE_HEAD(&usbd_free_xfers, xfer, next); else xfer = malloc(sizeof(*xfer), M_USB, M_NOWAIT); if (xfer == NULL) return (0); memset(xfer, 0, sizeof *xfer); xfer->device = dev; - DPRINTFN(5,("usbd_alloc_request() = %p\n", xfer)); + DPRINTFN(5,("usbd_alloc_xfer() = %p\n", xfer)); return (xfer); } usbd_status -usbd_free_request(xfer) +usbd_free_xfer(xfer) usbd_xfer_handle xfer; { - DPRINTFN(5,("usbd_free_request: %p\n", xfer)); + DPRINTFN(5,("usbd_free_xfer: %p\n", xfer)); if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF)) usbd_free_buffer(xfer); - SIMPLEQ_INSERT_HEAD(&usbd_free_requests, xfer, next); + SIMPLEQ_INSERT_HEAD(&usbd_free_xfers, xfer, next); return (USBD_NORMAL_COMPLETION); } void -usbd_setup_request(xfer, pipe, priv, buffer, length, flags, timeout, callback) +usbd_setup_xfer(xfer, pipe, priv, buffer, length, flags, timeout, callback) usbd_xfer_handle xfer; usbd_pipe_handle pipe; usbd_private_handle priv; @@ -405,7 +407,7 @@ usbd_setup_request(xfer, pipe, priv, buffer, length, flags, timeout, callback) } void -usbd_setup_default_request(xfer, dev, priv, timeout, req, buffer, +usbd_setup_default_xfer(xfer, dev, priv, timeout, req, buffer, length, flags, callback) usbd_xfer_handle xfer; usbd_device_handle dev; @@ -434,7 +436,7 @@ usbd_setup_default_request(xfer, dev, priv, timeout, req, buffer, } void -usbd_setup_isoc_request(xfer, pipe, priv, frlengths, nframes, flags, callback) +usbd_setup_isoc_xfer(xfer, pipe, priv, frlengths, nframes, flags, callback) usbd_xfer_handle xfer; usbd_pipe_handle pipe; usbd_private_handle priv; @@ -458,7 +460,7 @@ usbd_setup_isoc_request(xfer, pipe, priv, frlengths, nframes, flags, callback) } void -usbd_get_request_status(xfer, priv, buffer, count, status) +usbd_get_xfer_status(xfer, priv, buffer, count, status) usbd_xfer_handle xfer; usbd_private_handle *priv; void **buffer; @@ -789,11 +791,10 @@ usb_transfer_complete(xfer) [pipe->endpoint->edesc->bmAttributes & UE_XFERTYPE]; xfer->done = 1; - if (xfer->status == USBD_NORMAL_COMPLETION && - xfer->actlen < xfer->length && + if (!xfer->status && xfer->actlen < xfer->length && !(xfer->flags & USBD_SHORT_XFER_OK)) { - DPRINTFN(-1, ("usbd_transfer_cb: short transfer %d<%d\n", - xfer->actlen, xfer->length)); + DPRINTFN(-1,("usbd_transfer_cb: short transfer %d<%d\n", + xfer->actlen, xfer->length)); xfer->status = USBD_SHORT_XFER; } @@ -892,7 +893,7 @@ usbd_do_request_flags(dev, req, data, flags, actlen) usbd_status err; #ifdef DIAGNOSTIC -#if defined(__i386__) +#if defined(__i386__) && defined(__FreeBSD__) KASSERT(intr_nesting_level == 0, ("ohci_abort_req in interrupt context")); #endif @@ -902,10 +903,10 @@ usbd_do_request_flags(dev, req, data, flags, actlen) } #endif - xfer = usbd_alloc_request(dev); + xfer = usbd_alloc_xfer(dev); if (xfer == NULL) return (USBD_NOMEM); - usbd_setup_default_request(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, req, + usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, req, data, UGETW(req->wLength), flags, 0); err = usbd_sync_transfer(xfer); #if defined(USB_DEBUG) || defined(DIAGNOSTIC) @@ -936,7 +937,7 @@ usbd_do_request_flags(dev, req, data, flags, actlen) USETW(treq.wValue, 0); USETW(treq.wIndex, 0); USETW(treq.wLength, sizeof(usb_status_t)); - usbd_setup_default_request(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, + usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, &treq, &status,sizeof(usb_status_t), 0, 0); nerr = usbd_sync_transfer(xfer); @@ -951,7 +952,7 @@ usbd_do_request_flags(dev, req, data, flags, actlen) USETW(treq.wValue, UF_ENDPOINT_HALT); USETW(treq.wIndex, 0); USETW(treq.wLength, 0); - usbd_setup_default_request(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, + usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, &treq, &status, 0, 0, 0); nerr = usbd_sync_transfer(xfer); if (nerr) @@ -959,7 +960,7 @@ usbd_do_request_flags(dev, req, data, flags, actlen) } bad: - usbd_free_request(xfer); + usbd_free_xfer(xfer); return (err); } @@ -980,7 +981,7 @@ usbd_do_request_async_cb(xfer, priv, status) UGETW(xfer->request.wLength), xfer->length, xfer->actlen)); #endif - usbd_free_request(xfer); + usbd_free_xfer(xfer); } /* @@ -996,14 +997,14 @@ usbd_do_request_async(dev, req, data) usbd_xfer_handle xfer; usbd_status err; - xfer = usbd_alloc_request(dev); + xfer = usbd_alloc_xfer(dev); if (xfer == NULL) return (USBD_NOMEM); - usbd_setup_default_request(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, req, + usbd_setup_default_xfer(xfer, dev, 0, USBD_DEFAULT_TIMEOUT, req, data, UGETW(req->wLength), 0, usbd_do_request_async_cb); err = usbd_transfer(xfer); if (err != USBD_IN_PROGRESS) { - usbd_free_request(xfer); + usbd_free_xfer(xfer); return (err); } return (USBD_NORMAL_COMPLETION); diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index fef131d93665..e9795433effd 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi.h,v 1.31 1999/10/13 08:10:58 augustss Exp $ */ +/* $NetBSD: usbdi.h,v 1.33 1999/11/17 23:00:50 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -95,23 +95,23 @@ usbd_status usbd_open_pipe u_int8_t flags, usbd_pipe_handle *pipe)); usbd_status usbd_close_pipe __P((usbd_pipe_handle pipe)); usbd_status usbd_transfer __P((usbd_xfer_handle req)); -usbd_xfer_handle usbd_alloc_request __P((usbd_device_handle)); -usbd_status usbd_free_request __P((usbd_xfer_handle xfer)); -void usbd_setup_request +usbd_xfer_handle usbd_alloc_xfer __P((usbd_device_handle)); +usbd_status usbd_free_xfer __P((usbd_xfer_handle xfer)); +void usbd_setup_xfer __P((usbd_xfer_handle xfer, usbd_pipe_handle pipe, usbd_private_handle priv, void *buffer, u_int32_t length, u_int16_t flags, u_int32_t timeout, usbd_callback)); -void usbd_setup_default_request +void usbd_setup_default_xfer __P((usbd_xfer_handle xfer, usbd_device_handle dev, usbd_private_handle priv, u_int32_t timeout, usb_device_request_t *req, void *buffer, u_int32_t length, u_int16_t flags, usbd_callback)); -void usbd_setup_isoc_request +void usbd_setup_isoc_xfer __P((usbd_xfer_handle xfer, usbd_pipe_handle pipe, usbd_private_handle priv, u_int16_t *frlengths, u_int32_t nframes, u_int16_t flags, usbd_callback)); -void usbd_get_request_status +void usbd_get_xfer_status __P((usbd_xfer_handle xfer, usbd_private_handle *priv, void **buffer, u_int32_t *count, usbd_status *status)); usb_endpoint_descriptor_t *usbd_interface2endpoint_descriptor diff --git a/sys/dev/usb/usbdi_util.c b/sys/dev/usb/usbdi_util.c index ab54b1381c90..1bdef6e53fa3 100644 --- a/sys/dev/usb/usbdi_util.c +++ b/sys/dev/usb/usbdi_util.c @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi_util.c,v 1.22 1999/10/13 08:10:59 augustss Exp $ */ +/* $NetBSD: usbdi_util.c,v 1.24 1999/11/17 23:00:50 augustss Exp $ */ /* $FreeBSD$ */ /* @@ -504,8 +504,8 @@ usbd_bulk_transfer(xfer, pipe, flags, timeout, buf, size, lbl) usbd_status err; int s, error; - usbd_setup_request(xfer, pipe, 0, buf, *size, - flags, timeout, usbd_bulk_transfer_cb); + usbd_setup_xfer(xfer, pipe, 0, buf, *size, + flags, timeout, usbd_bulk_transfer_cb); DPRINTFN(1, ("usbd_bulk_transfer: start transfer %d bytes\n", *size)); s = splusb(); /* don't want callback until tsleep() */ err = usbd_transfer(xfer); @@ -520,7 +520,7 @@ usbd_bulk_transfer(xfer, pipe, flags, timeout, buf, size, lbl) usbd_abort_pipe(pipe); return (USBD_INTERRUPTED); } - usbd_get_request_status(xfer, 0, 0, size, &err); + usbd_get_xfer_status(xfer, 0, 0, size, &err); DPRINTFN(1,("usbd_bulk_transfer: transferred %d\n", *size)); if (err) { DPRINTF(("usbd_bulk_transfer: error=%d\n", err));