PERFORCE change 144550 for review

Hans Petter Selasky hselasky at FreeBSD.org
Thu Jul 3 13:50:35 UTC 2008


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

Change 144550 by hselasky at hselasky_laptop001 on 2008/07/03 13:49:34

	
	More and more USB devices come with autoinstall. Most of the
	time we just want to ignore these autoinstall disks. This
	patch implements a small SCSI driver that will look for
	mass storage devices in the first USB configuration. If
	it finds a USB CD-ROM USB device and there are more
	USB configurations, it will skip this configuration.
	
	Potentially we could also use this small SCSI driver
	to automatically test for USB mass storage quirks.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#8 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_msctest.c#1 add
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_msctest.h#1 add
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_parse.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_parse.h#2 edit
.. //depot/projects/usb/src/sys/modules/usb2/core/Makefile#4 edit

Differences ...

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

@@ -44,6 +44,7 @@
 #include <dev/usb2/core/usb2_util.h>
 #include <dev/usb2/core/usb2_mbuf.h>
 #include <dev/usb2/core/usb2_dev.h>
+#include <dev/usb2/core/usb2_msctest.h>
 
 #include <dev/usb2/quirk/usb2_quirk.h>
 
@@ -1507,23 +1508,36 @@
 
 	if (udev->flags.usb2_mode == USB_MODE_HOST) {
 		uint8_t config_index;
+		uint8_t config_quirk;
 
 		/*
-		 * most USB devices should attach to config index 0 by
+		 * Most USB devices should attach to config index 0 by
 		 * default
 		 */
-		if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_1)) {
+		if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_0)) {
+			config_index = 1;
+			config_quirk = 1;
+		} else if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_1)) {
 			config_index = 1;
+			config_quirk = 1;
 		} else if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_2)) {
 			config_index = 2;
+			config_quirk = 1;
 		} else if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_3)) {
 			config_index = 3;
+			config_quirk = 1;
 		} else if (usb2_test_quirk(&uaa, UQ_CFG_INDEX_4)) {
 			config_index = 4;
+			config_quirk = 1;
 		} else {
 			config_index = 0;
+			config_quirk = 0;
 		}
 
+repeat_set_config:
+
+		DPRINTF(0, "setting config %u\n", config_index);
+
 		/* get the USB device configured */
 		sx_xlock(udev->default_sx + 1);
 		err = usb2_set_config_index(udev, config_index);
@@ -1533,8 +1547,34 @@
 			    "configuration index %u: %s, port %u, addr %u\n",
 			    config_index, usb2_errstr(err), udev->port_no,
 			    udev->address);
+
+		} else if ((!config_quirk) &&
+		    ((config_index + 1) < udev->ddesc.bNumConfigurations)) {
+
+			if ((udev->cdesc->bNumInterface < 2) &&
+			    (usb2_get_no_endpoints(udev->cdesc) == 0)) {
+				DPRINTF(-1, "Found no endpoints "
+				    "(trying next config)!\n");
+				config_index++;
+				goto repeat_set_config;
+			}
+			if (config_index == 0) {
+				/*
+				 * Try to figure out if we have an
+				 * auto-install disk there:
+				 */
+				if (usb2_test_autoinstall(udev, 0) == 0) {
+					DPRINTF(-1, "Found possible auto-install "
+					    "disk (trying next config)\n");
+					config_index++;
+					goto repeat_set_config;
+				}
+			}
 		}
+	} else {
+		err = 0;		/* set success */
 	}
+
 	DPRINTF(0, "new dev (addr %d), udev=%p, parent_hub=%p\n",
 	    udev->address, udev, udev->parent_hub);
 
@@ -1542,8 +1582,6 @@
 	usb2_bus_port_set_device(bus, parent_hub ?
 	    parent_hub->hub->ports + port_index : NULL, udev, device_index);
 
-	err = 0;			/* set success */
-
 done:
 	if (err) {
 		/* free device  */

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

@@ -159,6 +159,25 @@
 }
 
 /*------------------------------------------------------------------------*
+ *	usb2_get_no_endpoints
+ *
+ * This function will count the total number of endpoints available.
+ *------------------------------------------------------------------------*/
+uint16_t
+usb2_get_no_endpoints(struct usb2_config_descriptor *cd)
+{
+	struct usb2_descriptor *desc = NULL;
+	uint16_t count = 0;
+
+	while ((desc = usb2_desc_foreach(cd, desc))) {
+		if (desc->bDescriptorType == UDESC_ENDPOINT) {
+			count++;
+		}
+	}
+	return (count);
+}
+
+/*------------------------------------------------------------------------*
  *	usb2_get_no_alts
  *
  * Return value:

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

@@ -29,6 +29,7 @@
 struct usb2_descriptor *usb2_desc_foreach(struct usb2_config_descriptor *cd, struct usb2_descriptor *desc);
 struct usb2_interface_descriptor *usb2_find_idesc(struct usb2_config_descriptor *cd, uint8_t iface_index, uint8_t alt_index);
 struct usb2_endpoint_descriptor *usb2_find_edesc(struct usb2_config_descriptor *cd, uint8_t iface_index, uint8_t alt_index, uint8_t ep_index);
+uint16_t usb2_get_no_endpoints(struct usb2_config_descriptor *cd);
 uint16_t usb2_get_no_alts(struct usb2_config_descriptor *cd, uint8_t ifaceno);
 
 #endif					/* _USB2_PARSE_H_ */

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

@@ -5,6 +5,7 @@
 KMOD=  usb2_core
 SRCS= 
 SRCS+= bus_if.h usb2_if.h device_if.h vnode_if.h opt_usb.h opt_bus.h
+SRCS+= usb2_if.c
 SRCS+= usb2_busdma.c
 SRCS+= usb2_compat_linux.c
 SRCS+= usb2_config_td.c
@@ -19,6 +20,7 @@
 SRCS+= usb2_hub.c
 SRCS+= usb2_lookup.c
 SRCS+= usb2_mbuf.c
+SRCS+= usb2_msctest.c
 SRCS+= usb2_parse.c
 SRCS+= usb2_process.c
 SRCS+= usb2_request.c


More information about the p4-projects mailing list