[{"id":1773263,"web_url":"http://patchwork.ozlabs.org/comment/1773263/","msgid":"<ab3f45a6-2397-0f5d-da18-1cce23c42a83@denx.de>","list_archive_url":null,"date":"2017-09-22T05:01:02","subject":"Re: [U-Boot] [PATCH 06/14] usb: Only get 64 bytes device descriptor\n\tfor full speed devices","submitter":{"id":13,"url":"http://patchwork.ozlabs.org/api/people/13/","name":"Stefan Roese","email":"sr@denx.de"},"content":"On 18.09.2017 15:40, Bin Meng wrote:\n> Full speed device endpoint 0 can have 8/16/32/64 bMaxPacketSize0.\n> Other speed devices report fixed value per USB spec. So it only\n> makes sense if we send a get device descriptor with 64 bytes to\n> full speed devices.\n> \n> While we are here, update the comment block to be within 80 cols.\n> \n> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>\n> ---\n> \n>   common/usb.c | 29 +++++++++++++++--------------\n>   1 file changed, 15 insertions(+), 14 deletions(-)\n> \n> diff --git a/common/usb.c b/common/usb.c\n> index 6cb92ef..88cee81 100644\n> --- a/common/usb.c\n> +++ b/common/usb.c\n> @@ -970,23 +970,24 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)\n>   \tdev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;\n>   \tdev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;\n>   \n> -\tif (do_read) {\n> +\tif (do_read && dev->speed == USB_SPEED_FULL) {\n>   \t\tint err;\n>   \n>   \t\t/*\n> -\t\t * Validate we've received only at least 8 bytes, not that we've\n> -\t\t * received the entire descriptor. The reasoning is:\n> -\t\t * - The code only uses fields in the first 8 bytes, so that's all we\n> -\t\t *   need to have fetched at this stage.\n> -\t\t * - The smallest maxpacket size is 8 bytes. Before we know the actual\n> -\t\t *   maxpacket the device uses, the USB controller may only accept a\n> -\t\t *   single packet. Consequently we are only guaranteed to receive 1\n> -\t\t *   packet (at least 8 bytes) even in a non-error case.\n> +\t\t * Validate we've received only at least 8 bytes, not that\n> +\t\t * we've received the entire descriptor. The reasoning is:\n> +\t\t * - The code only uses fields in the first 8 bytes, so\n> +\t\t *   that's all we need to have fetched at this stage.\n> +\t\t * - The smallest maxpacket size is 8 bytes. Before we know\n> +\t\t *   the actual maxpacket the device uses, the USB controller\n> +\t\t *   may only accept a single packet. Consequently we are only\n> +\t\t *   guaranteed to receive 1 packet (at least 8 bytes) even in\n> +\t\t *   a non-error case.\n>   \t\t *\n> -\t\t * At least the DWC2 controller needs to be programmed with the number\n> -\t\t * of packets in addition to the number of bytes. A request for 64\n> -\t\t * bytes of data with the maxpacket guessed as 64 (above) yields a\n> -\t\t * request for 1 packet.\n> +\t\t * At least the DWC2 controller needs to be programmed with\n> +\t\t * the number of packets in addition to the number of bytes.\n> +\t\t * A request for 64 bytes of data with the maxpacket guessed\n> +\t\t * as 64 (above) yields a request for 1 packet.\n>   \t\t */\n>   \t\terr = get_descriptor_len(dev, 64, 8);\n>   \t\tif (err)\n> @@ -1009,7 +1010,7 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)\n>   \t\tdev->maxpacketsize = PACKET_SIZE_64;\n>   \t\tbreak;\n>   \tdefault:\n> -\t\tprintf(\"usb_new_device: invalid max packet size\\n\");\n> +\t\tprintf(\"%s: invalid max packet size\\n\", __func__);\n>   \t\treturn -EIO;\n>   \t}\n>   \n> \n\nReviewed-by: Stefan Roese <sr@denx.de>\nTested-by: Stefan Roese <sr@denx.de>\n\nThanks,\nStefan","headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xz1YB042tz9sPm\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 15:01:49 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid C2BB7C21F4B; Fri, 22 Sep 2017 05:01:30 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 3EFD2C21C29;\n\tFri, 22 Sep 2017 05:01:28 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 5CC5AC21C29; Fri, 22 Sep 2017 05:01:27 +0000 (UTC)","from mx2.mailbox.org (mx2.mailbox.org [80.241.60.215])\n\tby lists.denx.de (Postfix) with ESMTPS id 0F27FC21C26\n\tfor <u-boot@lists.denx.de>; Fri, 22 Sep 2017 05:01:27 +0000 (UTC)","from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby mx2.mailbox.org (Postfix) with ESMTPS id D9CAB4B6E7;\n\tFri, 22 Sep 2017 07:01:26 +0200 (CEST)","from smtp1.mailbox.org ([80.241.60.240])\n\tby spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de\n\t[80.241.56.117]) (amavisd-new, port 10030)\n\twith ESMTP id wvRXtaHaPIrT; Fri, 22 Sep 2017 07:01:02 +0200 (CEST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW\n\tautolearn=unavailable autolearn_force=no version=3.4.0","X-Virus-Scanned":"amavisd-new at heinlein-support.de","To":"Bin Meng <bmeng.cn@gmail.com>, Marek Vasut <marex@denx.de>,\n\tU-Boot Mailing List <u-boot@lists.denx.de>","References":"<1505742050-5697-1-git-send-email-bmeng.cn@gmail.com>\n\t<1505742050-5697-7-git-send-email-bmeng.cn@gmail.com>","From":"Stefan Roese <sr@denx.de>","Message-ID":"<ab3f45a6-2397-0f5d-da18-1cce23c42a83@denx.de>","Date":"Fri, 22 Sep 2017 07:01:02 +0200","MIME-Version":"1.0","In-Reply-To":"<1505742050-5697-7-git-send-email-bmeng.cn@gmail.com>","Content-Language":"en-US","Subject":"Re: [U-Boot] [PATCH 06/14] usb: Only get 64 bytes device descriptor\n\tfor full speed devices","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Transfer-Encoding":"base64","Content-Type":"text/plain; charset=\"utf-8\"; Format=\"flowed\"","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"}}]