Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Jul 2008 12:35:32 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 144418 for review
Message-ID:  <200807011235.m61CZWXJ094735@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=144418

Change 144418 by hselasky@hselasky_laptop001 on 2008/07/01 12:35:00

	
	Add more debugging and fix various bugs.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/controller/at91dci_atmelarm.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/ehci2.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/ehci2_pci.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_atmelarm.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_pci.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/uhci2.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/uhci2_pci.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/usb2_controller.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci_pccard.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_config_td.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#6 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_debug.h#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#5 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#5 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_sw_transfer.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_transfer.c#6 edit
.. //depot/projects/usb/src/sys/dev/usb2/input/uhid2.c#3 edit
.. //depot/projects/usb/src/sys/modules/usb2/controller/Makefile#3 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/controller/at91dci_atmelarm.c#3 (text+ko) ====

@@ -205,7 +205,7 @@
 	if (!(sc->sc_vbus_irq_res)) {
 		goto error;
 	}
-	sc->sc_dci.sc_bus.bdev = device_add_child(dev, "usb", -1);
+	sc->sc_dci.sc_bus.bdev = device_add_child(dev, "usbus", -1);
 	if (!(sc->sc_dci.sc_bus.bdev)) {
 		goto error;
 	}

==== //depot/projects/usb/src/sys/dev/usb2/controller/ehci2.c#3 (text+ko) ====

@@ -3043,6 +3043,8 @@
 {
 	ehci_softc_t *sc = xfer->usb2_sc;
 
+	DPRINTF(0, "\n");
+
 	sc->sc_root_ctrl.xfer = xfer;
 
 	usb2_config_td_queue_command

==== //depot/projects/usb/src/sys/dev/usb2/controller/ehci2_pci.c#3 (text+ko) ====

@@ -281,7 +281,7 @@
 		device_printf(self, "Could not allocate irq\n");
 		goto error;
 	}
-	sc->sc_bus.bdev = device_add_child(self, "usb", -1);
+	sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
 	if (!sc->sc_bus.bdev) {
 		device_printf(self, "Could not add USB device\n");
 		goto error;

==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_atmelarm.c#3 (text) ====

@@ -103,7 +103,7 @@
 	if (!(sc->sc_ohci.sc_irq_res)) {
 		goto error;
 	}
-	sc->sc_ohci.sc_bus.bdev = device_add_child(dev, "usb", -1);
+	sc->sc_ohci.sc_bus.bdev = device_add_child(dev, "usbus", -1);
 	if (!(sc->sc_ohci.sc_bus.bdev)) {
 		goto error;
 	}

==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2_pci.c#3 (text+ko) ====

@@ -229,7 +229,7 @@
 		device_printf(self, "Could not allocate irq\n");
 		goto error;
 	}
-	sc->sc_bus.bdev = device_add_child(self, "usb", -1);
+	sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
 	if (!sc->sc_bus.bdev) {
 		device_printf(self, "Could not add USB device\n");
 		goto error;

==== //depot/projects/usb/src/sys/dev/usb2/controller/uhci2.c#3 (text+ko) ====

@@ -2532,6 +2532,8 @@
 {
 	uhci_softc_t *sc = xfer->usb2_sc;
 
+	DPRINTF(0, "\n");
+
 	sc->sc_root_ctrl.xfer = xfer;
 
 	usb2_config_td_queue_command

==== //depot/projects/usb/src/sys/dev/usb2/controller/uhci2_pci.c#3 (text+ko) ====

@@ -282,7 +282,7 @@
 		device_printf(self, "Could not allocate irq\n");
 		goto error;
 	}
-	sc->sc_bus.bdev = device_add_child(self, "usb", -1);
+	sc->sc_bus.bdev = device_add_child(self, "usbus", -1);
 	if (!sc->sc_bus.bdev) {
 		device_printf(self, "Could not add USB device\n");
 		goto error;

==== //depot/projects/usb/src/sys/dev/usb2/controller/usb2_controller.c#3 (text+ko) ====

@@ -58,9 +58,9 @@
 /* static variables */
 
 #ifdef USB_DEBUG
-static int usb2_ctrl_debug;
+static int usb2_ctrl_debug = 0;
 
-SYSCTL_NODE(_hw_usb2, OID_AUTO, ctrl, CTLFLAG_RW, 0, "USB ctrless");
+SYSCTL_NODE(_hw_usb2, OID_AUTO, ctrl, CTLFLAG_RW, 0, "USB controller");
 SYSCTL_INT(_hw_usb2_ctrl, OID_AUTO, debug, CTLFLAG_RW, &usb2_ctrl_debug, 0,
     "Debug level");
 #endif
@@ -118,7 +118,9 @@
 
 	mtx_lock(&Giant);
 	if (usb2_post_init_called) {
+		mtx_lock(&Giant);
 		usb2_attach_sub(dev, bus);
+		mtx_unlock(&Giant);
 		usb2_needs_explore(bus, 1);
 	}
 	mtx_unlock(&Giant);
@@ -139,7 +141,6 @@
 	/* Let the USB explore process detach all devices. */
 
 	mtx_lock(&(bus->mtx));
-
 	if (usb2_proc_msignal(&(bus->explore_proc),
 	    &(bus->detach_msg[0]), &(bus->detach_msg[1]))) {
 		/* ignore */
@@ -155,10 +156,12 @@
 
 	usb2_proc_unsetup(&(bus->explore_proc));
 
+	/* clear the softc */
+	device_set_softc(dev, NULL);
+
 	return (0);
 }
 
-
 /*------------------------------------------------------------------------*
  *	usb2_bus_explore
  *
@@ -219,7 +222,6 @@
 	bus->ready = 0;
 
 	mtx_unlock(&(bus->mtx));
-
 	mtx_lock(&Giant);
 
 	/* detach children first */
@@ -233,9 +235,7 @@
 	usb2_free_device(udev);
 
 	mtx_unlock(&Giant);
-
 	mtx_lock(&(bus->mtx));
-
 	return;
 }
 
@@ -347,9 +347,11 @@
 		max = devclass_get_maxunit(dc) + 1;
 		for (n = 0; n != max; n++) {
 			dev = devclass_get_device(dc, n);
-			if (dev) {
+			if (dev && device_is_attached(dev)) {
 				bus = device_get_softc(dev);
+				mtx_lock(&Giant);
 				usb2_attach_sub(dev, bus);
+				mtx_unlock(&Giant);
 			}
 		}
 	} else {

==== //depot/projects/usb/src/sys/dev/usb2/controller/uss820dci_pccard.c#3 (text+ko) ====

@@ -184,7 +184,7 @@
 	if (sc->sc_irq_res == NULL) {
 		goto error;
 	}
-	sc->sc_bus.bdev = device_add_child(dev, "usb", -1);
+	sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
 	if (!(sc->sc_bus.bdev)) {
 		goto error;
 	}

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_config_td.c#2 (text+ko) ====

@@ -38,6 +38,8 @@
 	struct usb2_config_td_item *pi = (void *)pm;
 	struct usb2_config_td *ctd = pi->p_ctd;
 
+	DPRINTF(0, "\n");
+
 	(pi->command_func) (ctd->p_softc, (void *)(pi + 1), pi->command_ref);
 
 	if (TAILQ_NEXT(pm, pm_qentry) == NULL) {
@@ -68,6 +70,8 @@
 	struct usb2_config_td_item *pi;
 	uint16_t n;
 
+	DPRINTF(0, " size=%u, count=%u \n", item_size, item_count);
+
 	if (item_count >= 256) {
 		DPRINTF(-1, "too many items!\n");
 		return (1);
@@ -83,8 +87,8 @@
 		return (1);
 	}
 	if (usb2_proc_setup(&(ctd->usb2_proc), priv_mtx, USB_PRI_MED)) {
+		free(M_USBDEV, ctd->p_msgs);
 		ctd->p_msgs = NULL;
-		free(M_USBDEV, ctd->p_msgs);
 		return (1);
 	}
 	/* initialise messages */
@@ -109,6 +113,7 @@
 void
 usb2_config_td_stop(struct usb2_config_td *ctd)
 {
+	DPRINTF(0, "\n");
 	if (ctd->p_msgs) {
 		usb2_proc_drain(&(ctd->usb2_proc));
 	}
@@ -124,6 +129,8 @@
 void
 usb2_config_td_unsetup(struct usb2_config_td *ctd)
 {
+	DPRINTF(0, "\n");
+
 	usb2_config_td_stop(ctd);
 
 	if (ctd->p_msgs) {
@@ -161,9 +168,12 @@
 	uint16_t n;
 
 	if (usb2_config_td_is_gone(ctd)) {
+		DPRINTF(0, "gone\n");
 		/* nothing more to do */
 		return;
 	}
+	DPRINTF(0, "\n");
+
 	pi = USB_ADD_BYTES(ctd->p_msgs, 0);
 	for (n = 0;; n += 2) {
 		if (n == ctd->msg_count) {
@@ -172,19 +182,28 @@
 			    __FUNCTION__, __LINE__);
 			return;
 		}
-		if ((pi->command_func == NULL) ||
-		    ((pi->command_func == command_post_func) &&
-		    (pi->command_ref == command_ref))) {
+		if (pi->command_func == NULL) {
+			/* reserve our entry */
+			pi->command_func = command_post_func;
+			pi->command_ref = command_ref;
+			pi_0 = pi;
+			pi = USB_ADD_BYTES(pi, ctd->msg_size);
+			pi->command_func = command_post_func;
+			pi->command_ref = command_ref;
+			pi_1 = pi;
+			break;
+		}
+		if ((pi->command_func == command_post_func) &&
+		    (pi->command_ref == command_ref)) {
 			/* found an entry */
+			pi_0 = pi;
+			pi = USB_ADD_BYTES(pi, ctd->msg_size);
+			pi_1 = pi;
 			break;
 		}
 		pi = USB_ADD_BYTES(pi, (2 * ctd->msg_size));
 	}
 
-	pi_0 = pi;
-	pi = USB_ADD_BYTES(pi, ctd->msg_size);
-	pi_1 = pi;
-
 	/*
 	 * We have two message structures. One of them will get
 	 * queued:
@@ -198,8 +217,6 @@
 	 * That way commands queued by the pre command will be queued after
 	 * the current command.
 	 */
-	pi->command_func = command_post_func;
-	pi->command_ref = command_ref;
 
 	/*
 	 * The job of the pre-command function is to copy the needed

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#6 (text+ko) ====

@@ -349,6 +349,7 @@
 	struct usb2_interface *iface;	/* current interface */
 	uint8_t	usb2_mode;		/* see USB_MODE_XXX */
 	uint8_t	port;
+	uint8_t use_generic;		/* hint for generic drivers */
 };
 
 /* Structure used when referring an USB device */

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_debug.h#2 (text+ko) ====

@@ -42,10 +42,10 @@
 /* Check if USB debugging is enabled. */
 #ifdef USB_DEBUG_VAR
 #ifdef USB_DEBUG
-#define	DPRINTF(n,fmt,...) do {			\
+#define	DPRINTF(n,fmt,...) do {				\
   if ((USB_DEBUG_VAR) > (n)) {				\
-    printf("%s:%u@%s: " fmt, __FILE__, __LINE__,	\
-	   __FUNCTION__,## __VA_ARGS__);		\
+    printf("%s:%u: " fmt,				\
+	   __FUNCTION__, __LINE__,## __VA_ARGS__);	\
   }							\
 } while (0)
 #else

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#5 (text+ko) ====

@@ -776,15 +776,15 @@
 	if (fp == NULL) {
 		return (ENXIO);
 	}
-	if (usb2_old_f_data != NULL) {
-		if (usb2_old_f_data != fp->f_data) {
+	if (usb2_old_f_data != fp->f_data) {
+		if (usb2_old_f_data != NULL) {
 			DPRINTF(-1, "File data mismatch!\n");
 			return (ENXIO);
 		}
 		usb2_old_f_data = fp->f_data;
 	}
-	if (usb2_old_f_ops != NULL) {
-		if (usb2_old_f_ops != fp->f_ops) {
+	if (usb2_old_f_ops != fp->f_ops) {
+		if (usb2_old_f_ops != NULL) {
 			DPRINTF(-1, "File ops mismatch!\n");
 			return (ENXIO);
 		}
@@ -981,6 +981,8 @@
 	int fflags;
 	int err;
 
+	DPRINTF(1, "\n");
+
 	err = usb2_ref_device(fp, &loc, 0);;
 
 	/* restore some file variables */
@@ -1614,10 +1616,10 @@
 		if (kern_unlink(curthread, buf, UIO_SYSSPACE)) {
 			/* ignore */
 		}
-		if (kern_symlink(curthread, buf, src, UIO_SYSSPACE)) {
+		if (kern_symlink(curthread, src, buf, UIO_SYSSPACE)) {
 			/* ignore */
 		}
-		printf("Symlink: %s -> %s\n", src, buf);
+		printf("Symlink: %s -> %s\n", buf, src);
 	}
 
 	DPRINTF(1, "attached %p/%p\n", f_tx, f_rx);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#3 (text+ko) ====

@@ -582,6 +582,7 @@
 		} else
 			selfpowered = 1;
 	}
+
 	DPRINTF(0, "udev=%p cdesc=%p (addr %d) cno=%d attr=0x%02x, "
 	    "selfpowered=%d, power=%d\n",
 	    udev, cdp,
@@ -611,8 +612,8 @@
 	udev->curr_config_index = index;
 
 	/* Set the actual configuration value. */
-	err = usb2_req_set_config(udev, &Giant,
-	    cdp->bConfigurationValue);
+	err = usb2_req_set_config(udev, &Giant, 
+cdp->bConfigurationValue);
 	if (err) {
 		goto error;
 	}
@@ -989,7 +990,7 @@
 usb2_init_attach_arg(struct usb2_device *udev,
     struct usb2_attach_arg *uaa)
 {
-	bzero(&uaa, sizeof(uaa));
+	bzero(uaa, sizeof(*uaa));
 
 	uaa->device = udev;
 	uaa->usb2_mode = udev->flags.usb2_mode;
@@ -1076,10 +1077,28 @@
 		uaa.info.bIfaceIndex = i;
 		uaa.info.bIfaceNum =
 		    iface->idesc->bInterfaceNumber;
+		uaa.use_generic = 0;
 
+		DPRINTF(1, "iclass=%u/%u/%u iindex=%u/%u\n",
+		    uaa.info.bInterfaceClass,
+		    uaa.info.bInterfaceSubClass,
+		    uaa.info.bInterfaceProtocol,
+		    uaa.info.bIfaceIndex,
+		    uaa.info.bIfaceNum);
+
+		/* try specific interface drivers first */
+
 		if (usb2_probe_and_attach_sub(udev, &uaa)) {
 			/* ignore */
 		}
+
+		/* try generic interface drivers last */
+
+		uaa.use_generic = 1;
+
+		if (usb2_probe_and_attach_sub(udev, &uaa)) {
+			/* ignore */
+		}
 	}
 
 	if (uaa.temp_dev) {
@@ -1824,7 +1843,7 @@
 uint8_t
 usb2_test_quirk(const struct usb2_attach_arg *uaa, uint16_t quirk)
 {
-	uint8_t found = 0;
+	uint8_t found;
 
 	found = (usb2_test_quirk_p) (&(uaa->info), quirk);
 	return (found);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#5 (text+ko) ====

@@ -126,7 +126,7 @@
 
 static driver_t uhub_driver =
 {
-	.name = "uhub",
+	.name = "ushub",
 	.methods = (device_method_t[]){
 		DEVMETHOD(device_probe, uhub_probe),
 		DEVMETHOD(device_attach, uhub_attach),
@@ -644,14 +644,14 @@
 	req.bRequest = UR_GET_DESCRIPTOR;
 	USETW2(req.wValue, UDESC_HUB, 0);
 	USETW(req.wIndex, 0);
-	USETW(req.wLength, sizeof(hubdesc));
+	USETW(req.wLength, 9);		/* assuming that there is one port */
 
 	err = usb2_do_request(udev, &Giant, &req, &hubdesc);
 
 	nports = hubdesc.bNbrPorts;
 
 	if (!err && (nports >= 8)) {
-		uint16_t len = (sizeof(hubdesc) - 1) + ((nports + 7) / 8);
+		uint16_t len = 8 + ((nports + 7) / 8);
 
 		USETW(req.wLength, len);
 		err = usb2_do_request(udev, &Giant, &req, &hubdesc);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.c#2 (text+ko) ====

@@ -131,7 +131,7 @@
 		pm = TAILQ_FIRST(&(up->up_qhead));
 
 		if (pm) {
-			DPRINTF(0, "Message %p,%p (enter)\n",
+			DPRINTF(0, "Message pm=%p, cb=%p (enter)\n",
 			    pm, pm->pm_callback);
 
 			(pm->pm_callback) (pm);
@@ -141,7 +141,7 @@
 				TAILQ_REMOVE(&(up->up_qhead), pm, pm_qentry);
 				pm->pm_qentry.tqe_prev = NULL;
 			}
-			DPRINTF(0, "Message %p (leave)\n", pm);
+			DPRINTF(0, "Message pm=%p (leave)\n", pm);
 
 			continue;
 		}
@@ -150,18 +150,14 @@
 			cv_broadcast(&(up->up_drain));
 		}
 		up->up_msleep = 1;
-
 		cv_wait(&(up->up_cv), up->up_mtx);
-
-		up->up_msleep = 0;
 	}
 
 	up->up_ptr = NULL;
-
 	cv_signal(&(up->up_cv));
-
 	mtx_unlock(up->up_mtx);
 
+	USB_THREAD_EXIT(0);
 	return;
 }
 
@@ -295,6 +291,8 @@
 		pm2 = NULL;		/* panic - should not happen */
 	}
 
+	DPRINTF(0, " t=%u, num=%u\n", t, up->up_msg_num);
+
 	/* Put message last on queue */
 
 	pm2->pm_num = up->up_msg_num;

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.c#3 (text+ko) ====

@@ -70,6 +70,8 @@
 {
 	;				/* workaround for a bug in "indent" */
 
+	DPRINTF(0, "st=%u\n", USB_GET_STATE(xfer));
+
 	switch (USB_GET_STATE(xfer)) {
 	case USB_ST_SETUP:
 		usb2_start_hardware(xfer);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_sw_transfer.c#2 (text+ko) ====

@@ -27,11 +27,14 @@
 #include <dev/usb2/include/usb2_standard.h>
 #include <dev/usb2/include/usb2_error.h>
 
+#define	USB_DEBUG_VAR usb2_debug
+
 #include <dev/usb2/core/usb2_core.h>
 #include <dev/usb2/core/usb2_process.h>
 #include <dev/usb2/core/usb2_busdma.h>
 #include <dev/usb2/core/usb2_transfer.h>
 #include <dev/usb2/core/usb2_sw_transfer.h>
+#include <dev/usb2/core/usb2_debug.h>
 
 /*------------------------------------------------------------------------*
  *	usb2_sw_transfer - factored out code
@@ -60,6 +63,7 @@
 	xfer = std->xfer;
 	if (xfer == NULL) {
 		/* the transfer is gone */
+		DPRINTF(0, "xfer gone\n");
 		return;
 	}
 	mtx_assert(xfer->usb2_mtx, MA_OWNED);
@@ -154,10 +158,8 @@
 		}
 	}
 done:
+	DPRINTF(0, "done err=%s\n", usb2_errstr(std->err));
 	std->state = USB_SW_TR_PRE_CALLBACK;
 	(func) (xfer, std);
-
-	/* call the USB transfer callback */
-	usb2_command_wrapper(&(xfer->usb2_root->done_q), xfer);
 	return;
 }

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_transfer.c#6 (text+ko) ====

@@ -1280,6 +1280,8 @@
 	if (!xfer->flags_int.open) {
 		xfer->flags_int.open = 1;
 
+		DPRINTF(0, "open\n");
+
 		mtx_lock(xfer->usb2_mtx);
 		(xfer->pipe->methods->open) (xfer);
 		mtx_unlock(xfer->usb2_mtx);
@@ -1415,6 +1417,8 @@
 
 	pipe = xfer->pipe;
 
+	DPRINTF(0, "enter\n");
+
 	/* enter the transfer */
 	(pipe->methods->enter) (xfer);
 
@@ -1511,11 +1515,19 @@
 	 */
 	if (xfer->flags_int.transferring) {
 		if (xfer->flags_int.can_cancel_immed) {
-			usb2_transfer_done(xfer, 0);
+			/*
+			 * The close method will be called by the
+			 * "usb2_callback_wrapper()" when it detects
+			 * that we are closed. This way we resolve
+			 * some races.
+			 */
+			usb2_transfer_done(xfer, USB_ERR_CANCELLED);
 		} else {
 			/* need to wait for the next done callback */
 		}
 	} else {
+		DPRINTF(0, "close\n");
+
 		/* close here and now */
 		(xfer->pipe->methods->close) (xfer);
 	}
@@ -1676,6 +1688,8 @@
 	 * 4) We are doing an ordinary callback
 	 */
 	DPRINTF(2, "case 1-4\n");
+	/* get next USB transfer in the queue */
+	info->done_q.curr = NULL;
 
 	mtx_unlock(xfer->usb2_mtx);
 	mtx_assert(xfer->usb2_mtx, MA_NOTOWNED);
@@ -1688,8 +1702,6 @@
 		if (usb2_callback_wrapper_sub(xfer)) {
 			/* the callback has been deferred */
 			mtx_lock(xfer->usb2_mtx);
-			/* get next USB transfer in the queue */
-			info->done_q.curr = NULL;
 			goto done;
 		}
 		xfer->flags_int.transferring = 0;
@@ -1723,18 +1735,14 @@
 	    (xfer->flags_int.started) &&
 	    (xfer->usb2_state == USB_ST_ERROR)) {
 		/* do nothing - just loop */
+		usb2_command_wrapper(&(info->done_q), xfer);
+		return;
 	} else if (xfer->flags_int.draining &&
 	    (!xfer->flags_int.transferring)) {
-		/* get next USB transfer in the queue */
-		info->done_q.curr = NULL;
 		/* "usb2_transfer_drain()" is waiting for end of transfer */
 		xfer->flags_int.draining = 0;
 		wakeup(&(xfer->flags_int));
-	} else {
-		/* get next USB transfer in the queue */
-		info->done_q.curr = NULL;
 	}
-
 done:
 	/* do the next callback, if any */
 	usb2_command_wrapper(&(info->done_q),
@@ -1828,6 +1836,16 @@
 
 	mtx_assert(xfer->usb2_mtx, MA_OWNED);
 
+	DPRINTF(0, "err=%s\n", usb2_errstr(error));
+
+	/*
+	 * If we are not transferring then just return.
+	 * This can happen during transfer cancel.
+	 */
+	if (!xfer->flags_int.transferring) {
+		DPRINTF(0, "not transferring\n");
+		return;
+	}
 	/* only set transfer error if not already set */
 	if (!xfer->error) {
 		xfer->error = error;
@@ -1902,6 +1920,8 @@
 
 	mtx_assert(xfer->usb2_mtx, MA_OWNED);
 
+	DPRINTF(0, "start\n");
+
 	/* start the transfer */
 	(pipe->methods->start) (xfer);
 
@@ -2045,6 +2065,8 @@
 			return;
 		}
 	}
+	DPRINTF(0, "start\n");
+
 	/* start USB transfer */
 	(pipe->methods->start) (xfer);
 
@@ -2105,6 +2127,7 @@
 
 	if (!xfer->flags_int.open &&
 	    !xfer->flags_int.did_close) {
+		DPRINTF(0, "close\n");
 		mtx_lock(xfer->usb2_mtx);
 		(xfer->pipe->methods->close) (xfer);
 		mtx_unlock(xfer->usb2_mtx);
@@ -2245,6 +2268,7 @@
 			usb2_transfer_enqueue(pq, xfer);
 			if (pq->curr != NULL) {
 				/* something is already processing */
+				DPRINTF(5, "busy %p\n", pq->curr);
 				return;
 			}
 		}
@@ -2272,7 +2296,9 @@
 					break;
 				}
 			}
+			DPRINTF(5, "cb %p (enter)\n", pq->curr);
 			(pq->command) (pq);
+			DPRINTF(5, "cb %p (leave)\n", pq->curr);
 
 		} while (!pq->recurse_2);
 

==== //depot/projects/usb/src/sys/dev/usb2/input/uhid2.c#3 (text+ko) ====

@@ -630,6 +630,10 @@
 	if (uaa->usb2_mode != USB_MODE_HOST) {
 		return (ENXIO);
 	}
+	if (uaa->use_generic == 0) {
+		/* give Mouse and Keyboard drivers a try first */
+		return (ENXIO);
+	}
 	if (uaa->info.bInterfaceClass != UICLASS_HID) {
 
 		/* the Xbox 360 gamepad doesn't use the HID class */

==== //depot/projects/usb/src/sys/modules/usb2/controller/Makefile#3 (text+ko) ====

@@ -7,16 +7,25 @@
 SRCS+= bus_if.h usb2_if.h device_if.h vnode_if.h 
 SRCS+= opt_usb.h pci_if.h opt_bus.h card_if.h
 
+#
+# The "usb2_controller.c" file must be first to 
+# resolve a "MODULE_DRIVER()" race.
+#
+
+SRCS+= usb2_controller.c
+
+.if defined(HAS_ATMELARM)
+SRCS+= at91dci_atmelarm.c
+SRCS+= ohci2_atmelarm.c
+.endif
+
 SRCS+= at91dci.c
-SRCS+= at91dci_atmelarm.c
 SRCS+= ehci2.c
 SRCS+= ehci2_pci.c
 SRCS+= ohci2.c
-SRCS+= ohci2_atmelarm.c
 SRCS+= ohci2_pci.c
 SRCS+= uhci2.c
 SRCS+= uhci2_pci.c
-SRCS+= usb2_controller.c
 SRCS+= uss820dci.c
 SRCS+= uss820dci_pccard.c
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807011235.m61CZWXJ094735>