PERFORCE change 144747 for review

Hans Petter Selasky hselasky at FreeBSD.org
Sat Jul 5 20:52:36 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=144747

Change 144747 by hselasky at hselasky_laptop001 on 2008/07/05 20:52:05

	
	Improve autoinstall test and factor out re-enumerate code.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_generic.c#8 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_msctest.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_msctest.h#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.c#7 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.h#4 edit

Differences ...

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

@@ -880,11 +880,8 @@
 static int
 ugen_re_enumerate(struct usb2_fifo *f)
 {
-	struct usb2_device *parent_hub;
 	struct usb2_device *udev = f->udev;
 	int error;
-	uint8_t old_addr;
-	uint8_t buf[8];
 
 	if (f->fifo_index >= 2) {
 		/* control endpoint only */
@@ -893,46 +890,14 @@
 	if (suser(curthread)) {
 		return (EPERM);
 	}
-	old_addr = udev->address;
-	parent_hub = udev->parent_hub;
-	if (parent_hub == NULL) {
-		error = EINVAL;
-		goto done;
-	}
-	error = usb2_req_reset_port(parent_hub, &Giant, udev->port_no);
-	if (error) {
-		error = ENXIO;
-		goto done;
-	}
-	/*
-	 * After that the port has been reset our device should be at
-	 * address zero:
-	 */
-	udev->address = USB_START_ADDR;
+	mtx_lock(f->priv_mtx);
+	error = usb2_req_re_enumerate(udev, f->priv_mtx);
+	mtx_unlock(f->priv_mtx);
 
-	/*
-	 * It should be allowed to read some descriptors from address
-	 * zero:
-	 */
-	error = usb2_req_get_desc(udev, &Giant, buf,
-	    8, 8, 0, UDESC_DEVICE, 0, 0);
 	if (error) {
-		error = ENXIO;
-		goto done;
+		return (ENXIO);
 	}
-	/*
-	 * Restore device address:
-	 */
-	error = usb2_req_set_address(udev, &Giant, old_addr);
-	if (error) {
-		error = ENXIO;
-		goto done;
-	}
-done:
-	/* restore address */
-	udev->address = old_addr;
-
-	return (error);
+	return (0);
 }
 
 static int

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

@@ -197,6 +197,23 @@
 static void
 bbb_done(struct bbb_transfer *sc, uint8_t error)
 {
+	struct usb2_xfer *xfer;
+
+	xfer = sc->xfer[sc->state];
+
+	/* verify the error code */
+
+	if (error) {
+		switch (USB_GET_STATE(xfer)) {
+		case USB_ST_SETUP:
+		case USB_ST_TRANSFERRED:
+			error = 1;
+			break;
+		default:
+			error = 2;
+			break;
+		}
+	}
 	sc->error = error;
 	sc->state = ST_COMMAND;
 	sc->status_try = 1;
@@ -448,53 +465,6 @@
 	return (sc->error);
 }
 
-usb2_error_t
-usb2_reset_device(struct usb2_device *udev, struct mtx *mtx)
-{
-	struct usb2_device *parent_hub;
-	usb2_error_t err;
-	uint8_t old_addr;
-
-	old_addr = udev->address;
-	parent_hub = udev->parent_hub;
-	if (parent_hub == NULL) {
-		err = USB_ERR_INVAL;
-		goto done;
-	}
-	err = usb2_req_reset_port(parent_hub, mtx, udev->port_no);
-	if (err) {
-		goto done;
-	}
-	/*
-	 * After that the port has been reset our device should be at
-	 * address zero:
-	 */
-	udev->address = USB_START_ADDR;
-
-	/*
-	 * Restore device address:
-	 */
-	err = usb2_req_set_address(udev, mtx, old_addr);
-	if (err) {
-		/* XXX ignore any errors! */
-		err = 0;
-	}
-	/* allow device time to set new address */
-	usb2_pause_mtx(mtx, USB_SET_ADDRESS_SETTLE);
-
-done:
-	/* restore address */
-	udev->address = old_addr;
-
-	if (err == 0) {
-		/* restore configuration */
-		err = usb2_req_set_config(udev, mtx, udev->curr_config_no);
-		/* wait a little bit, just in case */
-		usb2_pause_mtx(mtx, 10);
-	}
-	return (err);
-}
-
 /*------------------------------------------------------------------------*
  *	usb2_test_autoinstall
  *
@@ -586,9 +556,6 @@
 	goto done;
 
 done:
-	if (mtx_owned(&(sc->mtx))) {
-		usb2_reset_device(udev, &(sc->mtx));
-	}
 	mtx_unlock(&(sc->mtx));
 	usb2_transfer_unsetup(sc->xfer, ST_MAX);
 	mtx_destroy(&(sc->mtx));

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

@@ -26,7 +26,6 @@
 #ifndef _USB2_MSCTEST_H_
 #define	_USB2_MSCTEST_H_
 
-usb2_error_t usb2_reset_device(struct usb2_device *udev, struct mtx *mtx);
 usb2_error_t usb2_test_autoinstall(struct usb2_device *udev, uint8_t iface_index);
 
 #endif					/* _USB2_MSCTEST_H_ */

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

@@ -1264,3 +1264,68 @@
 	USETW(req.wLength, 1);
 	return (usb2_do_request(udev, mtx, &req, pconf));
 }
+
+/*------------------------------------------------------------------------*
+ *	usb2_req_re_enumerate
+ *
+ * Returns:
+ *    0: Success
+ * Else: Failure
+ *------------------------------------------------------------------------*/
+usb2_error_t
+usb2_req_re_enumerate(struct usb2_device *udev, struct mtx *mtx)
+{
+	struct usb2_device_descriptor ddesc;
+	struct usb2_device *parent_hub;
+	usb2_error_t err;
+	uint8_t old_addr;
+
+	old_addr = udev->address;
+	parent_hub = udev->parent_hub;
+	if (parent_hub == NULL) {
+		err = USB_ERR_INVAL;
+		goto done;
+	}
+	err = usb2_req_reset_port(parent_hub, mtx, udev->port_no);
+	if (err) {
+		DPRINTF(-1, "addr=%d, port reset failed\n", old_addr);
+		goto done;
+	}
+	/*
+	 * After that the port has been reset our device should be at
+	 * address zero:
+	 */
+	udev->address = USB_START_ADDR;
+
+	/*
+	 * Restore device address:
+	 */
+	err = usb2_req_set_address(udev, mtx, old_addr);
+	if (err) {
+		/* XXX ignore any errors! */
+		DPRINTF(-1, "addr=%d, set address failed\n",
+		    old_addr);
+		err = 0;
+	}
+	/* allow device time to set new address */
+	usb2_pause_mtx(mtx, USB_SET_ADDRESS_SETTLE);
+
+	/* get the device descriptor */
+	err = usb2_req_get_device_desc(udev, mtx, &ddesc);
+	if (err) {
+		DPRINTF(-1, "addr=%d, getting device "
+		    "descriptor failed!\n", old_addr);
+		goto done;
+	}
+done:
+	/* restore address */
+	udev->address = old_addr;
+
+	if (err == 0) {
+		/* restore configuration */
+		err = usb2_req_set_config(udev, mtx, udev->curr_config_no);
+		/* wait a little bit, just in case */
+		usb2_pause_mtx(mtx, 10);
+	}
+	return (err);
+}

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

@@ -52,6 +52,7 @@
 usb2_error_t usb2_req_set_port_feature(struct usb2_device *udev, struct mtx *mtx, uint8_t port, uint16_t sel);
 usb2_error_t usb2_req_set_protocol(struct usb2_device *udev, struct mtx *mtx, uint8_t iface_index, uint16_t report);
 usb2_error_t usb2_req_set_report(struct usb2_device *udev, struct mtx *mtx, void *data, uint16_t len, uint8_t iface_index, uint8_t type, uint8_t id);
+usb2_error_t usb2_req_re_enumerate(struct usb2_device *udev, struct mtx *mtx);
 
 #define	usb2_do_request(u,m,r,d) \
   usb2_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT)


More information about the p4-projects mailing list