Module Name: src Committed By: skrll Date: Fri Sep 27 21:39:34 UTC 2013
Modified Files: src/sys/external/bsd/dwc2: dwc2.c dwc2var.h src/sys/external/bsd/dwc2/dist: dwc2_coreintr.c dwc2_hcdintr.c Log Message: Use the hsotg->lock spin lock solely To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/dwc2/dwc2.c cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/dwc2/dwc2var.h cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c \ src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.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/external/bsd/dwc2/dwc2.c diff -u src/sys/external/bsd/dwc2/dwc2.c:1.2 src/sys/external/bsd/dwc2/dwc2.c:1.3 --- src/sys/external/bsd/dwc2/dwc2.c:1.2 Sat Sep 21 13:17:00 2013 +++ src/sys/external/bsd/dwc2/dwc2.c Fri Sep 27 21:39:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: dwc2.c,v 1.2 2013/09/21 13:17:00 skrll Exp $ */ +/* $NetBSD: dwc2.c,v 1.3 2013/09/27 21:39:34 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.2 2013/09/21 13:17:00 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwc2.c,v 1.3 2013/09/27 21:39:34 skrll Exp $"); #include "opt_usb.h" @@ -326,11 +326,12 @@ dwc2_softintr(void *v) { struct usbd_bus *bus = v; struct dwc2_softc *sc = DWC2_BUS2SC(bus); + struct dwc2_hsotg *hsotg = sc->sc_hsotg; struct dwc2_xfer *dxfer; KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock)); - mutex_spin_enter(&sc->sc_intr_lock); + mutex_spin_enter(&hsotg->lock); while ((dxfer = TAILQ_FIRST(&sc->sc_complete)) != NULL) { /* * dwc2_abort_xfer will remove this transfer from the @@ -346,11 +347,11 @@ dwc2_softintr(void *v) /* XXXNH Already done - can I assert this? */ callout_stop(&dxfer->xfer.timeout_handle); - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); usb_transfer_complete(&dxfer->xfer); - mutex_spin_enter(&sc->sc_intr_lock); + mutex_spin_enter(&hsotg->lock); } - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); } Static void @@ -370,9 +371,9 @@ dwc2_waitintr(struct dwc2_softc *sc, usb DPRINTFN(15, "0x%08x\n", intrs); if (intrs) { - mutex_spin_enter(&sc->sc_intr_lock); + mutex_spin_enter(&hsotg->lock); dwc2_interrupt(sc); - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); if (xfer->status != USBD_IN_PROGRESS) return; } @@ -491,10 +492,11 @@ Static void dwc2_poll(struct usbd_bus *bus) { struct dwc2_softc *sc = DWC2_BUS2SC(bus); + struct dwc2_hsotg *hsotg = sc->sc_hsotg; - mutex_spin_enter(&sc->sc_intr_lock); + mutex_spin_enter(&hsotg->lock); dwc2_interrupt(sc); - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); } /* @@ -522,7 +524,6 @@ dwc2_abort_xfer(usbd_xfer_handle xfer, u struct dwc2_softc *sc = DWC2_XFER2SC(xfer); struct dwc2_hsotg *hsotg = sc->sc_hsotg; struct dwc2_xfer *d, *tmp; - unsigned long flags; bool wake; int err; @@ -553,14 +554,12 @@ dwc2_abort_xfer(usbd_xfer_handle xfer, u /* * Step 1: Make the stack ignore it and stop the callout. */ - mutex_spin_enter(&sc->sc_intr_lock); + mutex_spin_enter(&hsotg->lock); xfer->hcflags |= UXFER_ABORTING; xfer->status = status; /* make software ignore it */ callout_stop(&xfer->timeout_handle); - spin_lock_irqsave(&hsotg->lock, flags); - /* XXXNH suboptimal */ TAILQ_FOREACH_SAFE(d, &sc->sc_complete, xnext, tmp) { if (d == dxfer) { @@ -573,8 +572,7 @@ dwc2_abort_xfer(usbd_xfer_handle xfer, u DPRINTF("dwc2_hcd_urb_dequeue failed\n"); } - spin_unlock(&hsotg->lock); - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); /* * Step 2: Execute callback. @@ -1226,10 +1224,10 @@ dwc2_device_start(usbd_xfer_handle xfer) if (xfertype == UE_ISOCHRONOUS || xfertype == UE_INTERRUPT) { - spin_lock_irqsave(&hsotg->lock, flags); + mutex_spin_enter(&hsotg->lock); if (!dwc2_hcd_is_bandwidth_allocated(hsotg, xfer)) alloc_bandwidth = 1; - spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_spin_exit(&hsotg->lock); } /* @@ -1400,18 +1398,19 @@ Debugger(); int dwc2_intr(void *p) { struct dwc2_softc *sc = p; + struct dwc2_hsotg *hsotg; int ret = 0; if (sc == NULL) return 0; - mutex_spin_enter(&sc->sc_intr_lock); + hsotg = sc->sc_hsotg; + mutex_spin_enter(&hsotg->lock); if (sc->sc_dying || !device_has_power(sc->sc_dev)) goto done; if (sc->sc_bus.use_polling) { - struct dwc2_hsotg *hsotg = sc->sc_hsotg; uint32_t intrs; intrs = dwc2_read_core_intr(hsotg); @@ -1421,7 +1420,7 @@ int dwc2_intr(void *p) } done: - mutex_spin_exit(&sc->sc_intr_lock); + mutex_spin_exit(&hsotg->lock); return ret; } @@ -1514,7 +1513,6 @@ dwc2_init(struct dwc2_softc *sc) sc->sc_hcdenabled = false; mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); - mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); TAILQ_INIT(&sc->sc_complete); @@ -1719,11 +1717,9 @@ void dwc2_host_complete(struct dwc2_hsot int _dwc2_hcd_start(struct dwc2_hsotg *hsotg) { - unsigned long flags; - dev_dbg(hsotg->dev, "DWC OTG HCD START\n"); - spin_lock_irqsave(&hsotg->lock, flags); + mutex_spin_enter(&hsotg->lock); hsotg->op_state = OTG_STATE_A_HOST; @@ -1732,6 +1728,6 @@ _dwc2_hcd_start(struct dwc2_hsotg *hsotg /*XXXNH*/ delay(50); - spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_spin_exit(&hsotg->lock); return 0; } Index: src/sys/external/bsd/dwc2/dwc2var.h diff -u src/sys/external/bsd/dwc2/dwc2var.h:1.1 src/sys/external/bsd/dwc2/dwc2var.h:1.2 --- src/sys/external/bsd/dwc2/dwc2var.h:1.1 Thu Sep 5 20:25:27 2013 +++ src/sys/external/bsd/dwc2/dwc2var.h Fri Sep 27 21:39:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: dwc2var.h,v 1.1 2013/09/05 20:25:27 skrll Exp $ */ +/* $NetBSD: dwc2var.h,v 1.2 2013/09/27 21:39:34 skrll Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -87,7 +87,6 @@ typedef struct dwc2_softc { struct dwc2_hsotg *sc_hsotg; kmutex_t sc_lock; - kmutex_t sc_intr_lock; bool sc_hcdenabled; void *sc_rhc_si; Index: src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c diff -u src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c:1.3 src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c:1.4 --- src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c:1.3 Wed Sep 25 06:19:22 2013 +++ src/sys/external/bsd/dwc2/dist/dwc2_coreintr.c Fri Sep 27 21:39:34 2013 @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dwc2_coreintr.c,v 1.3 2013/09/25 06:19:22 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwc2_coreintr.c,v 1.4 2013/09/27 21:39:34 skrll Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -467,7 +467,7 @@ irqreturn_t dwc2_handle_common_intr(void goto out; } - spin_lock(&hsotg->lock); + KASSERT(mutex_owned(&hsotg->lock)); gintsts = dwc2_read_common_intr(hsotg); if (gintsts & ~GINTSTS_PRTINT) @@ -502,7 +502,6 @@ irqreturn_t dwc2_handle_common_intr(void } } - spin_unlock(&hsotg->lock); out: return retval; } Index: src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c diff -u src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.3 src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.4 --- src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c:1.3 Wed Sep 25 06:19:22 2013 +++ src/sys/external/bsd/dwc2/dist/dwc2_hcdintr.c Fri Sep 27 21:39:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: dwc2_hcdintr.c,v 1.3 2013/09/25 06:19:22 skrll Exp $ */ +/* $NetBSD: dwc2_hcdintr.c,v 1.4 2013/09/27 21:39:34 skrll Exp $ */ /* * hcd_intr.c - DesignWare HS OTG Controller host-mode interrupt handling @@ -40,7 +40,7 @@ * This file contains the interrupt handlers for Host mode */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dwc2_hcdintr.c,v 1.3 2013/09/25 06:19:22 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwc2_hcdintr.c,v 1.4 2013/09/27 21:39:34 skrll Exp $"); #include <sys/types.h> #include <sys/pool.h> @@ -2071,13 +2071,12 @@ irqreturn_t dwc2_handle_hcd_intr(struct return retval; } - spin_lock(&hsotg->lock); + KASSERT(mutex_owned(&hsotg->lock)); /* Check if HOST Mode */ if (dwc2_is_host_mode(hsotg)) { gintsts = dwc2_read_core_intr(hsotg); if (!gintsts) { - spin_unlock(&hsotg->lock); return retval; } @@ -2120,7 +2119,5 @@ irqreturn_t dwc2_handle_hcd_intr(struct } } - spin_unlock(&hsotg->lock); - return retval; }