Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D253C433F5 for ; Fri, 30 Sep 2022 22:02:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 218D384DBB; Sat, 1 Oct 2022 00:02:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1664575335; bh=qS/wpDkPKRro9GI6ArDSf9DGc1YleAavAFLol9DXxeE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=D5avFSNmqqV1i+35lHZE8Hy+wdE3pPwRCN6qZupC5H594uFef2wPW5YM1+M/OXobi sViY3lEyTP2IS6ix7VBd0fBKKTJmJeHdGa4Ns3gw8ek8ocgMwwJOX8hTwWTfRTm60o mlks8/s9pX4X2ZijspoTYhP4UpbwZCp3NQGKG0a+t+YAQMzR7yOpfMO0evNXA4petc 3zpdTpCJZ5hPUpNwgl0cftwco64c6WjKd6I9roTKoIxVIMs3A/ho4/nM85W9iSc1HW +T6RgXZOjBMBgOzYSkwUi479EpXHH5nuPilpFSBGqXlaNI6M3GAx8TgmVxXRTWIyk1 CIs7rx94dLSJw== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C9C1684DBB; Sat, 1 Oct 2022 00:02:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1664575334; bh=qS/wpDkPKRro9GI6ArDSf9DGc1YleAavAFLol9DXxeE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bDvaw8N1b0/0h2Kkul3ydwiey2dI1PXKnfkL/6+GGWh4mwB+6VHudGbTk94rBYqB9 gAC7+6KIw1EmEPHRSBb1Ly+YxBIEd1aIfQdOig5/mRj7bcAntNnjcVZK4y39Cgn+Vd vhDWzbLo3HRc0NgebEnW6OaZ/JW+Eq3rPwG+JqA+mZA8RFAEXdAPqkOG1+eFpmHxd3 hxXwQ55cLcNwYsLVhK0hfsGgx7xy3GNMULSikyWzNPGAsg2fdtvLsc/clXsfx2dQEl oWOcxuD5Zwrn1gkd2yEN966SvaF+zYRX9QMvQStKTam6C07v6urAtGkOKgGvdBCYvY GvGmGQIV4R7vQ== Message-ID: Date: Sat, 1 Oct 2022 00:02:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH] usb: common: Detect USB storage media with "miscellaneous" USB devices To: =?UTF-8?Q?Christian_Kohlsch=c3=bctter?= Cc: u-boot@lists.denx.de, Lukasz Majewski References: <20220925144609.11727-1-christian@kohlschutter.com> <31608852-c693-5ff3-3ba2-f61b60b9bcd5@denx.de> <6CEF1818-04C9-49E6-A643-C8D92731931F@kohlschutter.com> <1C60C8D5-530B-455A-B574-E95DA19D3860@kohlschutter.com> Content-Language: en-US From: Marek Vasut In-Reply-To: <1C60C8D5-530B-455A-B574-E95DA19D3860@kohlschutter.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 9/30/22 23:58, Christian Kohlschütter wrote: >> On 30. Sep 2022, at 04:42, Marek Vasut wrote: >> >> On 9/26/22 23:55, Christian Kohlschütter wrote: >>> On 26. Sep 2022, at 01:45, Marek Vasut wrote: >>>> >>>> On 9/25/22 16:46, Christian Kohlschütter wrote: >>>>> When detecting USB storage devices, we currently skip everything that is >>>>> not marked as "undefined device class". >>>>> Composite devices such as tinyusb's CDC+MSC identify as "miscellaneous" >>>>> (class 0xEF). >>>>> Introduce a new constant, USB_CLASS_MISC (0xEF), and allow the detection >>>>> process to proceed for USB devices with this device class. >>>> >>>> What does Linux do with such a device , is there a specific quirk or does it simply not check the bDeviceClass at all ? >>> I didn't see any relevant checks in drivers/usb/storage, however changing the bDeviceClass from "MISC" (0xEF) to "UNSPECIFIED"/"PER_INTERFACE" (0x00) causes the device to be no longer detected by either Linux or macOS, but it would work with U-Boot (i.e., without the change). >>> macOS' USB prober would report the USB device as "unconfigured". On Linux, using usbutils but not busybox, lsusb would actually hang. >>> I think it's a good idea to keep the set of permitted device classes to a minimum (0x00 / 0xEF) and abort early in all other cases. This way, we can skip the more elaborate checks in usb_storage_probe for devices that are definitely not supported. >> >> I think the check in the usb_storage.c is actually correct as-is and the device you have might be odd. >> >> https://www.usb.org/sites/default/files/usbmassbulk_10.pdf >> >> " >> 4.1 Device Descriptor >> Each USB device has one device descriptor (per USB Specification). The device shall specify the device class and subclass codes in the interface descriptor, and not in the device descriptor. >> ... >> 4 | bDeviceClass | Byte | 00h | Class is specified in the interface descriptor. >> ... >> NOTE: Information in this table is from the USB Specification version 1.1 table 9-7. Bold text has been added for clarifications when using these descriptors with this specification. >> " >> >> And then >> >> " >> 4.3 Interface Descriptors >> The device shall support at least one interface, known herein as the Bulk-Only Data Interface. The Bulk-Only Data Interface uses three endpoints. >> Composite mass storage devices may support additional interfaces, to provide other features such as audio or video capabilities. This specification does not define such interfaces. >> The interface may have multiple alternate settings. The host shall examine each of the alternate settings to look for the bInterfaceProtocol and bInterfaceSubClass it supports optimally. >> " >> >> If I read this right, then such a composite device like you have should have bDeviceClass=0x00 and two Interface descriptors, one for the mass storage device and one for CDC ? > > See https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/src/usb_descriptors.c for an example of such a device. It has one mass storage device and one CDC. > > Changing the device class to 0x00 breaks support on Linux and macOS (I didn't try Windows). The question is -- does the aforementioned device conform to the USB-IF specification ? I think it does not, but luckily it could be fixed in software on the tinyusb side.