From owner-svn-src-all@FreeBSD.ORG Sat Oct 29 12:32:14 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 556EF106564A; Sat, 29 Oct 2011 12:32:14 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2B8408FC08; Sat, 29 Oct 2011 12:32:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p9TCWEHw016702; Sat, 29 Oct 2011 12:32:14 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9TCWEEL016699; Sat, 29 Oct 2011 12:32:14 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201110291232.p9TCWEEL016699@svn.freebsd.org> From: Hans Petter Selasky Date: Sat, 29 Oct 2011 12:32:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226903 - head/sys/dev/usb X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Oct 2011 12:32:14 -0000 Author: hselasky Date: Sat Oct 29 12:32:13 2011 New Revision: 226903 URL: http://svn.freebsd.org/changeset/base/226903 Log: Improve USB mass storage quirk auto detection. MFC after: 3 days Modified: head/sys/dev/usb/usb_device.c head/sys/dev/usb/usb_msctest.c Modified: head/sys/dev/usb/usb_device.c ============================================================================== --- head/sys/dev/usb/usb_device.c Sat Oct 29 08:11:18 2011 (r226902) +++ head/sys/dev/usb/usb_device.c Sat Oct 29 12:32:13 2011 (r226903) @@ -1851,7 +1851,8 @@ repeat_set_config: } } if (set_config_failed == 0 && config_index == 0 && - usb_test_quirk(&uaa, UQ_MSC_NO_SYNC_CACHE) == 0) { + usb_test_quirk(&uaa, UQ_MSC_NO_SYNC_CACHE) == 0 && + usb_test_quirk(&uaa, UQ_MSC_NO_GETMAXLUN) == 0) { /* * Try to figure out if there are any MSC quirks we Modified: head/sys/dev/usb/usb_msctest.c ============================================================================== --- head/sys/dev/usb/usb_msctest.c Sat Oct 29 08:11:18 2011 (r226902) +++ head/sys/dev/usb/usb_msctest.c Sat Oct 29 12:32:13 2011 (r226903) @@ -603,6 +603,29 @@ usb_iface_is_cdrom(struct usb_device *ud return (is_cdrom); } +static uint8_t +usb_msc_get_max_lun(struct usb_device *udev, uint8_t iface_index) +{ + struct usb_device_request req; + usb_error_t err; + uint8_t buf = 0; + + + /* The Get Max Lun command is a class-specific request. */ + req.bmRequestType = UT_READ_CLASS_INTERFACE; + req.bRequest = 0xFE; /* GET_MAX_LUN */ + USETW(req.wValue, 0); + req.wIndex[0] = iface_index; + req.wIndex[1] = 0; + USETW(req.wLength, 1); + + err = usbd_do_request(udev, NULL, &req, &buf); + if (err) + buf = 0; + + return (buf); +} + usb_error_t usb_msc_auto_quirk(struct usb_device *udev, uint8_t iface_index) { @@ -622,6 +645,11 @@ usb_msc_auto_quirk(struct usb_device *ud */ usb_pause_mtx(NULL, hz); + if (usb_msc_get_max_lun(udev, iface_index) == 0) { + DPRINTF("Device has only got one LUN.\n"); + usbd_add_dynamic_quirk(udev, UQ_MSC_NO_GETMAXLUN); + } + is_no_direct = 1; for (timeout = 4; timeout; timeout--) { err = bbb_command_start(sc, DIR_IN, 0, sc->buffer,