Module Name: src Committed By: matt Date: Thu Jun 9 19:08:33 UTC 2011
Modified Files: src/sys/dev/usb: ehci.c files.usb ohci.c uhci.c uhub.c usb.c usb_mem.c usb_subr.c usbdi.c Log Message: Move EHCI_DEBUG, OHCI_DEBUG, UHCI_DEBUG, USB_DEBUG, UHUB_DEBUG to opt_usb.h (ya dependencies). Cleanup usb_mem.c a little more and add block tracking code. Help find corruption problems. Comment out the SPEED check for ETTF. XXX why doesn't that work right? To generate a diff of this commit: cvs rdiff -u -r1.177 -r1.178 src/sys/dev/usb/ehci.c cvs rdiff -u -r1.105 -r1.106 src/sys/dev/usb/files.usb cvs rdiff -u -r1.215 -r1.216 src/sys/dev/usb/ohci.c cvs rdiff -u -r1.238 -r1.239 src/sys/dev/usb/uhci.c cvs rdiff -u -r1.113 -r1.114 src/sys/dev/usb/uhub.c cvs rdiff -u -r1.124 -r1.125 src/sys/dev/usb/usb.c cvs rdiff -u -r1.47 -r1.48 src/sys/dev/usb/usb_mem.c cvs rdiff -u -r1.179 -r1.180 src/sys/dev/usb/usb_subr.c cvs rdiff -u -r1.131 -r1.132 src/sys/dev/usb/usbdi.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/ehci.c diff -u src/sys/dev/usb/ehci.c:1.177 src/sys/dev/usb/ehci.c:1.178 --- src/sys/dev/usb/ehci.c:1.177 Sat May 28 15:47:17 2011 +++ src/sys/dev/usb/ehci.c Thu Jun 9 19:08:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ehci.c,v 1.177 2011/05/28 15:47:17 tsutsui Exp $ */ +/* $NetBSD: ehci.c,v 1.178 2011/06/09 19:08:31 matt Exp $ */ /* * Copyright (c) 2004-2008 The NetBSD Foundation, Inc. @@ -52,10 +52,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.177 2011/05/28 15:47:17 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.178 2011/06/09 19:08:31 matt Exp $"); #include "ohci.h" #include "uhci.h" +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> @@ -2270,9 +2271,10 @@ goto ret; } v = EOREAD4(sc, EHCI_PORTSC(index)); - DPRINTFN(8,("ehci_root_ctrl_start: port status=0x%04x\n", - v)); + DPRINTFN(8,("ehci_root_ctrl_start: port status=0x%04x\n", v)); + i = UPS_HIGH_SPEED; +#if 0 if (sc->sc_flags & EHCIF_ETTF) { /* * If we are doing embedded transaction translation, @@ -2281,9 +2283,8 @@ * the same way as in USBSTATUS. */ i = __SHIFTOUT(v, EHCI_PS_PSPD) * UPS_LOW_SPEED; - } else { - i = UPS_HIGH_SPEED; } +#endif if (v & EHCI_PS_CS) i |= UPS_CURRENT_CONNECT_STATUS; if (v & EHCI_PS_PE) i |= UPS_PORT_ENABLED; if (v & EHCI_PS_SUSP) i |= UPS_SUSPEND; @@ -2351,9 +2352,9 @@ * terminate the reset sequence so there's no need to * it. */ - if (!(sc->sc_flags & EHCIF_ETTF)) { + v = EOREAD4(sc, port); + if (v & EHCI_PS_PR) { /* Terminate reset sequence. */ - v = EOREAD4(sc, port); EOWRITE4(sc, port, v & ~EHCI_PS_PR); /* Wait for HC to complete reset. */ usb_delay_ms(&sc->sc_bus, Index: src/sys/dev/usb/files.usb diff -u src/sys/dev/usb/files.usb:1.105 src/sys/dev/usb/files.usb:1.106 --- src/sys/dev/usb/files.usb:1.105 Sun Mar 20 17:54:03 2011 +++ src/sys/dev/usb/files.usb Thu Jun 9 19:08:31 2011 @@ -1,4 +1,4 @@ -# $NetBSD: files.usb,v 1.105 2011/03/20 17:54:03 tsutsui Exp $ +# $NetBSD: files.usb,v 1.106 2011/06/09 19:08:31 matt Exp $ # # Config file and device description for machine-independent USB code. # Included by ports that need it. Ports that use it must provide @@ -6,6 +6,7 @@ defflag USBVERBOSE defflag opt_usb.h USB_FRAG_DMA_WORKAROUND +defflag opt_usb.h EHCI_DEBUG OHCI_DEBUG UHCI_DEBUG UHUB_DEBUG USB_DEBUG defflag opt_uvideo.h UVIDEO_DEBUG Index: src/sys/dev/usb/ohci.c diff -u src/sys/dev/usb/ohci.c:1.215 src/sys/dev/usb/ohci.c:1.216 --- src/sys/dev/usb/ohci.c:1.215 Sat May 28 15:47:17 2011 +++ src/sys/dev/usb/ohci.c Thu Jun 9 19:08:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ohci.c,v 1.215 2011/05/28 15:47:17 tsutsui Exp $ */ +/* $NetBSD: ohci.c,v 1.216 2011/06/09 19:08:31 matt Exp $ */ /* $FreeBSD: src/sys/dev/usb/ohci.c,v 1.22 1999/11/17 22:33:40 n_hibma Exp $ */ /* @@ -41,7 +41,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.215 2011/05/28 15:47:17 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.216 2011/06/09 19:08:31 matt Exp $"); + +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> Index: src/sys/dev/usb/uhci.c diff -u src/sys/dev/usb/uhci.c:1.238 src/sys/dev/usb/uhci.c:1.239 --- src/sys/dev/usb/uhci.c:1.238 Sat May 28 15:47:17 2011 +++ src/sys/dev/usb/uhci.c Thu Jun 9 19:08:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uhci.c,v 1.238 2011/05/28 15:47:17 tsutsui Exp $ */ +/* $NetBSD: uhci.c,v 1.239 2011/06/09 19:08:32 matt Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhci.c,v 1.33 1999/11/17 22:33:41 n_hibma Exp $ */ /* @@ -42,7 +42,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.238 2011/05/28 15:47:17 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.239 2011/06/09 19:08:32 matt Exp $"); + +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> Index: src/sys/dev/usb/uhub.c diff -u src/sys/dev/usb/uhub.c:1.113 src/sys/dev/usb/uhub.c:1.114 --- src/sys/dev/usb/uhub.c:1.113 Sun May 29 12:37:09 2011 +++ src/sys/dev/usb/uhub.c Thu Jun 9 19:08:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: uhub.c,v 1.113 2011/05/29 12:37:09 jmcneill Exp $ */ +/* $NetBSD: uhub.c,v 1.114 2011/06/09 19:08:32 matt Exp $ */ /* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ /* @@ -36,7 +36,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.113 2011/05/29 12:37:09 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.114 2011/06/09 19:08:32 matt Exp $"); + +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> @@ -546,7 +548,7 @@ dev->depth + 1, speed, port, up); /* XXX retry a few times? */ if (err) { - DPRINTFN(-1,("uhub_explore: usb_new_device failed, " + DPRINTFN(-1,("uhub_explore: usbd_new_device failed, " "error=%s\n", usbd_errstr(err))); /* Avoid addressing problems by disabling. */ /* usbd_reset_port(dev, port, &up->status); */ Index: src/sys/dev/usb/usb.c diff -u src/sys/dev/usb/usb.c:1.124 src/sys/dev/usb/usb.c:1.125 --- src/sys/dev/usb/usb.c:1.124 Mon May 23 21:50:44 2011 +++ src/sys/dev/usb/usb.c Thu Jun 9 19:08:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: usb.c,v 1.124 2011/05/23 21:50:44 joerg Exp $ */ +/* $NetBSD: usb.c,v 1.125 2011/06/09 19:08:32 matt Exp $ */ /* * Copyright (c) 1998, 2002, 2008 The NetBSD Foundation, Inc. @@ -37,9 +37,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.124 2011/05/23 21:50:44 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.125 2011/06/09 19:08:32 matt Exp $"); #include "opt_compat_netbsd.h" +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> Index: src/sys/dev/usb/usb_mem.c diff -u src/sys/dev/usb/usb_mem.c:1.47 src/sys/dev/usb/usb_mem.c:1.48 --- src/sys/dev/usb/usb_mem.c:1.47 Thu Jun 9 07:17:02 2011 +++ src/sys/dev/usb/usb_mem.c Thu Jun 9 19:08:32 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: usb_mem.c,v 1.47 2011/06/09 07:17:02 matt Exp $ */ +/* $NetBSD: usb_mem.c,v 1.48 2011/06/09 19:08:32 matt Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.47 2011/06/09 07:17:02 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.48 2011/06/09 19:08:32 matt Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -90,9 +90,16 @@ usb_dma_block_t **); Static void usb_block_freemem(usb_dma_block_t *); -Static LIST_HEAD(, usb_dma_block) usb_blk_freelist = +LIST_HEAD(usb_dma_block_qh, usb_dma_block); +Static struct usb_dma_block_qh usb_blk_freelist = LIST_HEAD_INITIALIZER(usb_blk_freelist); -Static int usb_blk_nfree = 0; +#ifdef DEBUG +Static struct usb_dma_block_qh usb_blk_fraglist = + LIST_HEAD_INITIALIZER(usb_blk_fraglist); +Static struct usb_dma_block_qh usb_blk_fulllist = + LIST_HEAD_INITIALIZER(usb_blk_fulllist); +#endif +Static u_int usb_blk_nfree = 0; /* XXX should have different free list for different tags (for speed) */ Static LIST_HEAD(, usb_frag_dma) usb_frag_freelist = LIST_HEAD_INITIALIZER(usb_frag_freelist); @@ -101,12 +108,11 @@ usb_block_allocmem(bus_dma_tag_t tag, size_t size, size_t align, usb_dma_block_t **dmap) { + usb_dma_block_t *b; int error; - usb_dma_block_t *p; int s; - DPRINTFN(5, ("usb_block_allocmem: size=%lu align=%lu\n", - (u_long)size, (u_long)align)); + DPRINTFN(5, ("usb_block_allocmem: size=%zu align=%zu\n", size, align)); #ifdef DIAGNOSTIC if (cpu_intr_p()) { @@ -117,14 +123,14 @@ s = splusb(); /* First check the free list. */ - LIST_FOREACH(p, &usb_blk_freelist, next) { - if (p->tag == tag && p->size >= size && p->align >= align) { - LIST_REMOVE(p, next); + LIST_FOREACH(b, &usb_blk_freelist, next) { + if (b->tag == tag && b->size >= size && b->align >= align) { + LIST_REMOVE(b, next); usb_blk_nfree--; splx(s); - *dmap = p; - DPRINTFN(6,("usb_block_allocmem: free list size=%lu\n", - (u_long)p->size)); + *dmap = b; + DPRINTFN(6,("usb_block_allocmem: free list size=%zu\n", + p->size)); return (USBD_NORMAL_COMPLETION); } } @@ -138,54 +144,54 @@ #endif DPRINTFN(6, ("usb_block_allocmem: no free\n")); - p = malloc(sizeof *p, M_USB, M_NOWAIT); - if (p == NULL) + b = malloc(sizeof *b, M_USB, M_NOWAIT | M_ZERO); + if (b == NULL) return (USBD_NOMEM); - p->tag = tag; - p->size = size; - p->align = align; - error = bus_dmamem_alloc(tag, p->size, align, 0, - p->segs, __arraycount(p->segs), - &p->nsegs, BUS_DMA_NOWAIT); + b->tag = tag; + b->size = size; + b->align = align; + error = bus_dmamem_alloc(tag, b->size, align, 0, + b->segs, __arraycount(b->segs), + &b->nsegs, BUS_DMA_NOWAIT); if (error) goto free0; - error = bus_dmamem_map(tag, p->segs, p->nsegs, p->size, - &p->kaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); + error = bus_dmamem_map(tag, b->segs, b->nsegs, b->size, + &b->kaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); if (error) goto free1; - error = bus_dmamap_create(tag, p->size, 1, p->size, - 0, BUS_DMA_NOWAIT, &p->map); + error = bus_dmamap_create(tag, b->size, 1, b->size, + 0, BUS_DMA_NOWAIT, &b->map); if (error) goto unmap; - error = bus_dmamap_load(tag, p->map, p->kaddr, p->size, NULL, + error = bus_dmamap_load(tag, b->map, b->kaddr, b->size, NULL, BUS_DMA_NOWAIT); if (error) goto destroy; - *dmap = p; + *dmap = b; #ifdef USB_FRAG_DMA_WORKAROUND - memset(p->kaddr, 0, p->size); + memset(b->kaddr, 0, b->size); #endif return (USBD_NORMAL_COMPLETION); destroy: - bus_dmamap_destroy(tag, p->map); + bus_dmamap_destroy(tag, b->map); unmap: - bus_dmamem_unmap(tag, p->kaddr, p->size); + bus_dmamem_unmap(tag, b->kaddr, b->size); free1: - bus_dmamem_free(tag, p->segs, p->nsegs); + bus_dmamem_free(tag, b->segs, b->nsegs); free0: - free(p, M_USB); + free(b, M_USB); return (USBD_NOMEM); } #if 0 void -usb_block_real_freemem(usb_dma_block_t *p) +usb_block_real_freemem(usb_dma_block_t *b) { #ifdef DIAGNOSTIC if (cpu_intr_p()) { @@ -193,27 +199,43 @@ return; } #endif - bus_dmamap_unload(p->tag, p->map); - bus_dmamap_destroy(p->tag, p->map); - bus_dmamem_unmap(p->tag, p->kaddr, p->size); - bus_dmamem_free(p->tag, p->segs, p->nsegs); + bus_dmamap_unload(b->tag, b->map); + bus_dmamap_destroy(b->tag, b->map); + bus_dmamem_unmap(b->tag, b->kaddr, b->size); + bus_dmamem_free(b->tag, b->segs, b->nsegs); free(p, M_USB); } #endif +#ifdef DEBUG +Static bool +usb_valid_block_p(usb_dma_block_t *b, struct usb_dma_block_qh *qh) +{ + usb_dma_block_t *xb; + LIST_FOREACH(xb, qh, next) { + if (xb == b) + return true; + } + return false; +} +#endif + /* * Do not free the memory unconditionally since we might be called * from an interrupt context and that is BAD. * XXX when should we really free? */ Static void -usb_block_freemem(usb_dma_block_t *p) +usb_block_freemem(usb_dma_block_t *b) { int s; - DPRINTFN(6, ("usb_block_freemem: size=%lu\n", (u_long)p->size)); + DPRINTFN(6, ("usb_block_freemem: size=%zu\n", b->size)); s = splusb(); - LIST_INSERT_HEAD(&usb_blk_freelist, p, next); +#ifdef DEBUG + LIST_REMOVE(b, next); +#endif + LIST_INSERT_HEAD(&usb_blk_freelist, b, next); usb_blk_nfree++; splx(s); } @@ -234,6 +256,9 @@ size = (size + USB_MEM_BLOCK - 1) & ~(USB_MEM_BLOCK - 1); err = usb_block_allocmem(tag, size, align, &p->block); if (!err) { +#ifdef DEBUG + LIST_INSERT_HEAD(&usb_blk_fulllist, p->block, next); +#endif p->block->flags = USB_DMA_FULLBLOCK; p->offs = 0; } @@ -243,6 +268,9 @@ s = splusb(); /* Check for free fragments. */ LIST_FOREACH(f, &usb_frag_freelist, next) { + KDASSERTMSG(usb_valid_block_p(f->block, &usb_blk_fraglist), + ("%s: usb frag %p: unknown block pointer %p", + __func__, f, f->block)); if (f->block->tag == tag) break; } @@ -253,6 +281,9 @@ splx(s); return (err); } +#ifdef DEBUG + LIST_INSERT_HEAD(&usb_blk_fraglist, b, next); +#endif b->flags = 0; for (i = 0; i < USB_MEM_BLOCK; i += USB_MEM_SMALL) { f = (struct usb_frag_dma *)((char *)b->kaddr + i); @@ -284,10 +315,16 @@ int s; if (p->block->flags & USB_DMA_FULLBLOCK) { + KDASSERTMSG(usb_valid_block_p(p->block, &usb_blk_fulllist), + ("%s: dma %p: invalid block pointer %p", + __func__, p, p->block)); DPRINTFN(1, ("usb_freemem: large free\n")); usb_block_freemem(p->block); return; } + KDASSERTMSG(usb_valid_block_p(p->block, &usb_blk_fraglist), + ("%s: dma %p: invalid block pointer %p", + __func__, p, p->block)); //usb_syncmem(p, 0, USB_MEM_SMALL, BUS_DMASYNC_POSTREAD); f = KERNADDR(p, 0); #ifdef USB_FRAG_DMA_WORKAROUND Index: src/sys/dev/usb/usb_subr.c diff -u src/sys/dev/usb/usb_subr.c:1.179 src/sys/dev/usb/usb_subr.c:1.180 --- src/sys/dev/usb/usb_subr.c:1.179 Fri May 27 17:19:18 2011 +++ src/sys/dev/usb/usb_subr.c Thu Jun 9 19:08:33 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: usb_subr.c,v 1.179 2011/05/27 17:19:18 drochner Exp $ */ +/* $NetBSD: usb_subr.c,v 1.180 2011/06/09 19:08:33 matt Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ /* @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.179 2011/05/27 17:19:18 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.180 2011/06/09 19:08:33 matt Exp $"); #include "opt_compat_netbsd.h" #include "opt_usbverbose.h" @@ -1161,7 +1161,7 @@ } if (err) { DPRINTFN(-1, ("usbd_new_device: addr=%d, getting first desc " - "failed\n", addr)); + "failed: %d\n", addr, err)); usbd_remove_device(dev, up); return (err); } Index: src/sys/dev/usb/usbdi.c diff -u src/sys/dev/usb/usbdi.c:1.131 src/sys/dev/usb/usbdi.c:1.132 --- src/sys/dev/usb/usbdi.c:1.131 Mon Dec 20 18:49:11 2010 +++ src/sys/dev/usb/usbdi.c Thu Jun 9 19:08:33 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi.c,v 1.131 2010/12/20 18:49:11 phx Exp $ */ +/* $NetBSD: usbdi.c,v 1.132 2011/06/09 19:08:33 matt Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */ /* @@ -32,9 +32,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.131 2010/12/20 18:49:11 phx Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.132 2011/06/09 19:08:33 matt Exp $"); #include "opt_compat_netbsd.h" +#include "opt_usb.h" #include <sys/param.h> #include <sys/systm.h> @@ -942,9 +943,9 @@ err = usbd_sync_transfer(xfer); #if defined(USB_DEBUG) || defined(DIAGNOSTIC) if (xfer->actlen > xfer->length) { - DPRINTF(("usbd_do_request: overrun addr=%d type=0x%02x req=0x" + DPRINTF(("%s: overrun addr=%d type=0x%02x req=0x" "%02x val=%d index=%d rlen=%d length=%d actlen=%d\n", - dev->address, xfer->request.bmRequestType, + __func__, dev->address, xfer->request.bmRequestType, xfer->request.bRequest, UGETW(xfer->request.wValue), UGETW(xfer->request.wIndex), UGETW(xfer->request.wLength), @@ -992,6 +993,9 @@ } bad: + if (err) { + DPRINTF(("%s: returning err=%s\n", __func__, usbd_errstr(err))); + } usbd_free_xfer(xfer); return (err); }