Module Name: src
Committed By: skrll
Date: Thu Apr 4 13:27:56 UTC 2013
Modified Files:
src/sys/dev/usb: ehci.c ohci.c uhci.c usbdi.c
Log Message:
Don't take the bus lock in usbd_transfer_complete when polling.
Sprinkle || polling in KASSERTsw
To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 src/sys/dev/usb/ehci.c
cvs rdiff -u -r1.239 -r1.240 src/sys/dev/usb/ohci.c
cvs rdiff -u -r1.256 -r1.257 src/sys/dev/usb/uhci.c
cvs rdiff -u -r1.151 -r1.152 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.205 src/sys/dev/usb/ehci.c:1.206
--- src/sys/dev/usb/ehci.c:1.205 Fri Feb 1 12:53:47 2013
+++ src/sys/dev/usb/ehci.c Thu Apr 4 13:27:55 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ehci.c,v 1.205 2013/02/01 12:53:47 tsutsui Exp $ */
+/* $NetBSD: ehci.c,v 1.206 2013/04/04 13:27:55 skrll Exp $ */
/*
* Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.205 2013/02/01 12:53:47 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.206 2013/04/04 13:27:55 skrll Exp $");
#include "ohci.h"
#include "uhci.h"
@@ -776,7 +776,7 @@ ehci_check_intr(ehci_softc_t *sc, struct
DPRINTFN(/*15*/2, ("ehci_check_intr: ex=%p\n", ex));
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
attr = ex->xfer.pipe->endpoint->edesc->bmAttributes;
if (UE_GET_XFERTYPE(attr) == UE_ISOCHRONOUS)
@@ -793,7 +793,7 @@ ehci_check_qh_intr(ehci_softc_t *sc, str
ehci_soft_qtd_t *sqtd, *lsqtd;
__uint32_t status;
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
if (ex->sqtdstart == NULL) {
printf("ehci_check_qh_intr: not valid sqtd\n");
@@ -911,7 +911,7 @@ ehci_idone(struct ehci_xfer *ex)
u_int32_t status = 0, nstatus = 0;
int actlen;
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
DPRINTFN(/*12*/2, ("ehci_idone: ex=%p\n", ex));
@@ -2708,7 +2708,7 @@ Static void
ehci_free_sqtd(ehci_softc_t *sc, ehci_soft_qtd_t *sqtd)
{
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
sqtd->nextqtd = sc->sc_freeqtds;
sc->sc_freeqtds = sqtd;
@@ -3859,7 +3859,7 @@ ehci_device_intr_done(usbd_xfer_handle x
DPRINTFN(10, ("ehci_device_intr_done: xfer=%p, actlen=%d\n",
xfer, xfer->actlen));
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
if (xfer->pipe->repeat) {
ehci_free_sqtd_chain(sc, ex->sqtdstart, NULL);
Index: src/sys/dev/usb/ohci.c
diff -u src/sys/dev/usb/ohci.c:1.239 src/sys/dev/usb/ohci.c:1.240
--- src/sys/dev/usb/ohci.c:1.239 Thu Apr 4 12:21:12 2013
+++ src/sys/dev/usb/ohci.c Thu Apr 4 13:27:55 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci.c,v 1.239 2013/04/04 12:21:12 skrll Exp $ */
+/* $NetBSD: ohci.c,v 1.240 2013/04/04 13:27:55 skrll Exp $ */
/*
* Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.239 2013/04/04 12:21:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.240 2013/04/04 13:27:55 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -429,6 +429,8 @@ ohci_alloc_std(ohci_softc_t *sc)
int i, offs;
usb_dma_t dma;
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
+
if (sc->sc_freetds == NULL) {
DPRINTFN(2, ("ohci_alloc_std: allocating chunk\n"));
err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
@@ -459,7 +461,8 @@ ohci_alloc_std(ohci_softc_t *sc)
void
ohci_free_std(ohci_softc_t *sc, ohci_soft_td_t *std)
{
-
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
+
ohci_hash_rem_td(sc, std);
std->nexttd = sc->sc_freetds;
sc->sc_freetds = std;
@@ -1507,7 +1510,7 @@ ohci_device_intr_done(usbd_xfer_handle x
DPRINTFN(10,("ohci_device_intr_done: xfer=%p, actlen=%d\n",
xfer, xfer->actlen));
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
usb_syncmem(&xfer->dmabuf, 0, xfer->length,
isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
@@ -1682,14 +1685,12 @@ ohci_poll(struct usbd_bus *bus)
last = new;
}
#endif
- mutex_enter(&sc->sc_lock);
sc->sc_eintrs |= OHCI_WDH;
if (OREAD4(sc, OHCI_INTERRUPT_STATUS) & sc->sc_eintrs) {
mutex_spin_enter(&sc->sc_intr_lock);
ohci_intr1(sc);
mutex_spin_exit(&sc->sc_intr_lock);
}
- mutex_exit(&sc->sc_lock);
}
usbd_status
@@ -1913,7 +1914,7 @@ ohci_hash_add_td(ohci_softc_t *sc, ohci_
{
int h = HASH(std->physaddr);
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
LIST_INSERT_HEAD(&sc->sc_hash_tds[h], std, hnext);
}
@@ -1923,7 +1924,7 @@ void
ohci_hash_rem_td(ohci_softc_t *sc, ohci_soft_td_t *std)
{
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
LIST_REMOVE(std, hnext);
}
Index: src/sys/dev/usb/uhci.c
diff -u src/sys/dev/usb/uhci.c:1.256 src/sys/dev/usb/uhci.c:1.257
--- src/sys/dev/usb/uhci.c:1.256 Fri Feb 1 12:53:47 2013
+++ src/sys/dev/usb/uhci.c Thu Apr 4 13:27:56 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: uhci.c,v 1.256 2013/02/01 12:53:47 tsutsui Exp $ */
+/* $NetBSD: uhci.c,v 1.257 2013/04/04 13:27:56 skrll Exp $ */
/*
* Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.256 2013/02/01 12:53:47 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.257 2013/04/04 13:27:56 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1912,7 +1912,7 @@ uhci_alloc_std_chain(struct uhci_pipe *u
"flags=0x%x\n", addr, UE_GET_ADDR(endpt), len,
upipe->pipe.device->speed, flags));
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
maxp = UGETW(upipe->pipe.endpoint->edesc->wMaxPacketSize);
if (maxp == 0) {
@@ -3005,7 +3005,7 @@ uhci_device_intr_done(usbd_xfer_handle x
DPRINTFN(5, ("uhci_device_intr_done: length=%d\n", xfer->actlen));
- KASSERT(mutex_owned(&sc->sc_lock));
+ KASSERT(sc->sc_bus.use_polling || mutex_owned(&sc->sc_lock));
npoll = upipe->u.intr.npoll;
for(i = 0; i < npoll; i++) {
Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.151 src/sys/dev/usb/usbdi.c:1.152
--- src/sys/dev/usb/usbdi.c:1.151 Sun Mar 24 22:38:45 2013
+++ src/sys/dev/usb/usbdi.c Thu Apr 4 13:27:56 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi.c,v 1.151 2013/03/24 22:38:45 skrll Exp $ */
+/* $NetBSD: usbdi.c,v 1.152 2013/04/04 13:27:56 skrll Exp $ */
/*
* Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.151 2013/03/24 22:38:45 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.152 2013/04/04 13:27:56 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -790,12 +790,14 @@ usb_transfer_complete(usbd_xfer_handle x
int sync = xfer->flags & USBD_SYNCHRONOUS;
int erred = xfer->status == USBD_CANCELLED ||
xfer->status == USBD_TIMEOUT;
- int repeat, polling;
+ int polling = pipe->device->bus->use_polling;
+ int repeat;
DPRINTFN(5, ("usb_transfer_complete: pipe=%p xfer=%p status=%d "
"actlen=%d\n", pipe, xfer, xfer->status, xfer->actlen));
- KASSERT(pipe->device->bus->lock == NULL || mutex_owned(pipe->device->bus->lock));
+ KASSERT(polling || pipe->device->bus->lock == NULL ||
+ mutex_owned(pipe->device->bus->lock));
#ifdef DIAGNOSTIC
if (xfer->busy_free != XFER_ONQU) {
@@ -811,7 +813,6 @@ usb_transfer_complete(usbd_xfer_handle x
}
#endif
repeat = pipe->repeat;
- polling = pipe->device->bus->use_polling;
/* XXXX */
if (polling)
pipe->running = 0;
@@ -868,7 +869,7 @@ usb_transfer_complete(usbd_xfer_handle x
if (repeat) {
if (xfer->callback) {
- if (pipe->device->bus->lock)
+ if (pipe->device->bus->lock && !polling)
mutex_exit(pipe->device->bus->lock);
if (!(pipe->flags & USBD_MPSAFE))
@@ -877,14 +878,14 @@ usb_transfer_complete(usbd_xfer_handle x
if (!(pipe->flags & USBD_MPSAFE))
KERNEL_UNLOCK_ONE(curlwp);
- if (pipe->device->bus->lock)
+ if (pipe->device->bus->lock && !polling)
mutex_enter(pipe->device->bus->lock);
}
pipe->methods->done(xfer);
} else {
pipe->methods->done(xfer);
if (xfer->callback) {
- if (pipe->device->bus->lock)
+ if (pipe->device->bus->lock && !polling)
mutex_exit(pipe->device->bus->lock);
if (!(pipe->flags & USBD_MPSAFE))
@@ -893,7 +894,7 @@ usb_transfer_complete(usbd_xfer_handle x
if (!(pipe->flags & USBD_MPSAFE))
KERNEL_UNLOCK_ONE(curlwp);
- if (pipe->device->bus->lock)
+ if (pipe->device->bus->lock && !polling)
mutex_enter(pipe->device->bus->lock);
}
}