From owner-p4-projects@FreeBSD.ORG Thu Jul 3 13:50:35 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 07FE710656AB; Thu, 3 Jul 2008 13:50:35 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A49CD106567D for ; Thu, 3 Jul 2008 13:50:34 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8C48C8FC32 for ; Thu, 3 Jul 2008 13:50:34 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m63DoYSX065275 for ; Thu, 3 Jul 2008 13:50:34 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m63DoYhq065273 for perforce@freebsd.org; Thu, 3 Jul 2008 13:50:34 GMT (envelope-from hselasky@FreeBSD.org) Date: Thu, 3 Jul 2008 13:50:34 GMT Message-Id: <200807031350.m63DoYhq065273@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 144550 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jul 2008 13:50:35 -0000 http://perforce.freebsd.org/chv.cgi?CH=144550 Change 144550 by hselasky@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 #include #include +#include #include @@ -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