From a2adaeb68cdecc2bc1185613a11b7d49915883ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Mon, 12 Aug 2013 00:09:21 +0300 Subject: usbdebug: Only test two possible USB device numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After an USB device sees USB bus reset on the bus, it will reset to device number 0. Per the EHCI debug port specification, a debug dongle device may reset to the fixed debug device number of 127 instead. Thus there is no need to try device numbers from 1 to 126. Do a sanity-check on a returned debug descriptor as I experienced some USB flash memory to respond on this request with zero-fill data. Change-Id: I78d58f3dc049cd8c20c6e2aa3a4207ad7e6a6d33 Signed-off-by: Kyösti Mälkki Reviewed-on: http://review.coreboot.org/3861 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/lib/usbdebug.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib/usbdebug.c b/src/lib/usbdebug.c index a9a7e17597..4a1228f158 100644 --- a/src/lib/usbdebug.c +++ b/src/lib/usbdebug.c @@ -540,24 +540,28 @@ try_next_port: dbgp_mdelay(100); /* Find the debug device and make it device number 127 */ - for (devnum = 0; devnum <= 127; devnum++) { - ret = dbgp_control_msg(ehci_debug, devnum, - USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0, - &dbgp_desc, sizeof(dbgp_desc)); - if (ret > 0) - break; + devnum = 0; +debug_dev_retry: + memset(&dbgp_desc, 0, sizeof(dbgp_desc)); + ret = dbgp_control_msg(ehci_debug, devnum, + USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, + USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0, + &dbgp_desc, sizeof(dbgp_desc)); + if (ret == sizeof(dbgp_desc)) { + if (dbgp_desc.bLength == sizeof(dbgp_desc) && dbgp_desc.bDescriptorType==USB_DT_DEBUG) + goto debug_dev_found; + else + dprintk(BIOS_INFO, "Invalid debug device descriptor.\n"); } - if (devnum > 127) { + if (devnum == 0) { + devnum = USB_DEBUG_DEVNUM; + goto debug_dev_retry; + } else { dprintk(BIOS_INFO, "Could not find attached debug device.\n"); ret = -5; goto err; } - if (ret < 0) { - dprintk(BIOS_INFO, "Attached device is not a debug device.\n"); - ret = -6; - goto err; - } +debug_dev_found: /* Move the device to 127 if it isn't already there */ if (devnum != USB_DEBUG_DEVNUM) { -- cgit v1.2.3