All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/14] usb: Only get 64 bytes device descriptor for full speed devices
Date: Mon, 18 Sep 2017 06:40:42 -0700	[thread overview]
Message-ID: <1505742050-5697-7-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1505742050-5697-1-git-send-email-bmeng.cn@gmail.com>

Full speed device endpoint 0 can have 8/16/32/64 bMaxPacketSize0.
Other speed devices report fixed value per USB spec. So it only
makes sense if we send a get device descriptor with 64 bytes to
full speed devices.

While we are here, update the comment block to be within 80 cols.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 common/usb.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/common/usb.c b/common/usb.c
index 6cb92ef..88cee81 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -970,23 +970,24 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
 	dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0;
 	dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0;
 
-	if (do_read) {
+	if (do_read && dev->speed == USB_SPEED_FULL) {
 		int err;
 
 		/*
-		 * Validate we've received only at least 8 bytes, not that we've
-		 * received the entire descriptor. The reasoning is:
-		 * - The code only uses fields in the first 8 bytes, so that's all we
-		 *   need to have fetched at this stage.
-		 * - The smallest maxpacket size is 8 bytes. Before we know the actual
-		 *   maxpacket the device uses, the USB controller may only accept a
-		 *   single packet. Consequently we are only guaranteed to receive 1
-		 *   packet (at least 8 bytes) even in a non-error case.
+		 * Validate we've received only at least 8 bytes, not that
+		 * we've received the entire descriptor. The reasoning is:
+		 * - The code only uses fields in the first 8 bytes, so
+		 *   that's all we need to have fetched at this stage.
+		 * - The smallest maxpacket size is 8 bytes. Before we know
+		 *   the actual maxpacket the device uses, the USB controller
+		 *   may only accept a single packet. Consequently we are only
+		 *   guaranteed to receive 1 packet (at least 8 bytes) even in
+		 *   a non-error case.
 		 *
-		 * At least the DWC2 controller needs to be programmed with the number
-		 * of packets in addition to the number of bytes. A request for 64
-		 * bytes of data with the maxpacket guessed as 64 (above) yields a
-		 * request for 1 packet.
+		 * At least the DWC2 controller needs to be programmed with
+		 * the number of packets in addition to the number of bytes.
+		 * A request for 64 bytes of data with the maxpacket guessed
+		 * as 64 (above) yields a request for 1 packet.
 		 */
 		err = get_descriptor_len(dev, 64, 8);
 		if (err)
@@ -1009,7 +1010,7 @@ static int usb_setup_descriptor(struct usb_device *dev, bool do_read)
 		dev->maxpacketsize = PACKET_SIZE_64;
 		break;
 	default:
-		printf("usb_new_device: invalid max packet size\n");
+		printf("%s: invalid max packet size\n", __func__);
 		return -EIO;
 	}
 
-- 
2.9.2

  parent reply	other threads:[~2017-09-18 13:40 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-18 13:40 [U-Boot] [PATCH 00/14] usb: xhci: Add interrupt transfer support and full speed device support Bin Meng
2017-09-18 13:40 ` [U-Boot] [PATCH 01/14] dm: usb: Fix broken usb_stop() Bin Meng
2017-09-22  4:56   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 02/14] dm: usb: Remove no longer needed blk_unbind_all() Bin Meng
2017-09-22  4:57   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 03/14] usb: xhci: Don't assume LS/FS devices are always behind a HS hub Bin Meng
2017-09-22  4:58   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 04/14] usb: Handle audio extension endpoint descriptor in usb_parse_config() Bin Meng
2017-09-22  4:59   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 05/14] usb: xhci: Add interrupt transfer support Bin Meng
2017-09-22  5:00   ` Stefan Roese
2017-09-18 13:40 ` Bin Meng [this message]
2017-09-22  5:01   ` [U-Boot] [PATCH 06/14] usb: Only get 64 bytes device descriptor for full speed devices Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 07/14] usb: Read device descriptor after device is addressed for xHCI Bin Meng
2017-09-22  5:01   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 08/14] usb: xhci: Fix max packet size for full speed device endpoint 0 Bin Meng
2017-09-22  5:02   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 09/14] usb: hub: Clear port reset before usb_hub_port_connect_change() Bin Meng
2017-09-22  5:03   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 10/14] usb: hub: Clear BH reset status change for a 3.0 hub Bin Meng
2017-09-22  5:04   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 11/14] usb: xhci: Honor endpoint's interval Bin Meng
2017-09-22  5:06   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 12/14] usb: xhci: Program max burst size for endpoint Bin Meng
2017-09-22  5:11   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 13/14] usb: xhci: Set 'Error Count' to 0 for isoch endpoints Bin Meng
2017-09-22  5:12   ` Stefan Roese
2017-09-18 13:40 ` [U-Boot] [PATCH 14/14] usb: xhci: Set 'Average TRB Length' to 8 for control endpoints Bin Meng
2017-09-22  5:13   ` Stefan Roese
2017-09-18 15:13 ` [U-Boot] [PATCH 00/14] usb: xhci: Add interrupt transfer support and full speed device support Marek Vasut
2017-09-18 15:26   ` Stefan Roese
2017-09-18 15:33     ` Marek Vasut
2017-09-18 15:38     ` Stefan Roese
2017-09-19  1:38       ` Bin Meng
2017-09-19  4:54         ` Stefan Roese
2017-09-19  4:58           ` Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1505742050-5697-7-git-send-email-bmeng.cn@gmail.com \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.