Fix to make U-Boot work with more USB sticks
Subsystems (2)
PATCH 1/1 Fix to make U-Boot work with more USB sticks
I am sending this to the list looking for comments. Testing has been confined to just a few USB sticks - no USB hard drives, USB card readers, etc. But there are reports on the mailing list of problems with U-Boot's detection of USB mass storage devices.
We have had a lot of problems with different USB sticks, specifically the faster bulk storage devices. Two of these sticks have a problem where they do not respond to a USB descriptor submission within the allowed U-Boot timeout. This seems to only happen when a REQUEST SENSE is submitted immediately after a TEST UNIT READY fails.
There is also some oddness with reset, where some devices need more than one reset. This appears to be due to faulty reset code in U-Boot.
USB sticks where this this problem has been noticed are:
ID 13fe:3800 Kingston Technology Company Inc.
ID 0930:6545 Toshiba Corp. Kingston DataTraveler 2.0 Stick (4GB)
/ PNY Attache 4GB Stick
This problem has been reproduced on the Tegra 20 Seaboard, but it is TBD whether it happens on other ARM platforms with HS USB also.
This patch:
1. Increases the USB descriptor submission timeout to 3 seconds since the original 1 second timeout seems arbitrary
2. Replaces the delay-based reset logic with logic which waits until it sees the reset is successful, rather than blindly continuing
3. Resets and retries a USB mass storage device after it fails once, in case even 3 seconds is not enough
BUG=chromiumos-6780
TEST=tried with four different USB sticks, including two which previously failed
Change-Id: I5bd8891bff67a74b758e349f2a3b3575806eed59
--- common/usb.c | 176 ++++++++++++++++++++++++++++++++++++------- common/usb_storage.c | 55 +++++++++++--- drivers/usb/host/ehci-hcd.c | 20 ++++- include/usb.h | 11 +++ 4 files changed, 217 insertions(+), 45 deletions(-)
common/usb.c +148 -28
@@ -222,10 +222,14 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,int usb_bulk_msg (struct usb_device *dev,unsigned int pipe,void *data,int len,int *actual_length,int timeout) { +int err; +if (len <0 )return -1 ; dev->status =USB_ST_NOT_PROC ;/*not yet processed */ -submit_bulk_msg (dev, pipe, data, len); + err =submit_bulk_msg (dev, pipe, data, len); +if (err <0 ) +return err;while (timeout--) {if (!((volatile unsigned long )dev->status &USB_ST_NOT_PROC ))break ;
@@ -758,6 +762,39 @@ struct usb_device *usb_alloc_new_device(void)return &usb_dev[dev_index -1 ]; } +/* find a device's parent hub, and reset this device's port on that hub */ + +int usb_reset_device_on_hub (struct usb_device *dev) +{ +struct usb_device *parent = dev->parent; +unsigned short portstatus; +int port =-1 ; +int err; + +/* find the port number we're at */ +if (parent) { +int j; + +for (j =0 ; j < parent->maxchild; j++) { +if (parent->children[j] == dev) { + port = j; +break ; + } + } +if (port <0 ) { +printf ("usb_new_device:cannot locate device's port.\n" ); +return 1 ; + } + + err =hub_port_reset (dev->parent, port, &portstatus); +if (err <0 ) { +printf ("\n Couldn't reset port %i\n" , port); +return 1 ; + } + } +return 0 ; +} +/* * Free the newly created device node. * Called in error cases where configuring a newly attached
@@ -941,6 +978,14 @@ int usb_new_device(struct usb_device *dev)return 0 ; } +/* reset and restart a device that is misbehaving */ + +int usb_restart_device (struct usb_device *dev) +{ +usb_reset_device_on_hub (dev);/* ignore return value */ +return usb_new_device (dev); +} +/* build device Tree */ void usb_scan_devices (void ) {
@@ -1069,45 +1114,123 @@ static inline char *portspeed(int portstatus)return "12 Mb/s" ; } -static int hub_port_reset (struct usb_device *dev,int port, -unsigned short *portstat) +/* brought this in from kernel 2.6.36 as it is a problem area. Some USB +sticks do not operate properly with the previous reset code */ +#define PORT_RESET_TRIES 5 +#define SET_ADDRESS_TRIES 2 +#define GET_DESCRIPTOR_TRIES 2 +#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1)) +#define USE_NEW_SCHEME (i) ((i) / 2 == old_scheme_first) + +#define HUB_ROOT_RESET_TIME 50/* times are in msec */ +#define HUB_SHORT_RESET_TIME 10 +#define HUB_LONG_RESET_TIME 200 +#define HUB_RESET_TIMEOUT 500 + +#define ENOTCONN 107 + +static int hub_port_wait_reset (struct usb_device *dev,int port, +unsigned int delay,unsigned short *portstatus_ret) { -int tries; +int delay_time, ret;struct usb_port_status portsts;unsigned short portstatus, portchange; -USB_HUB_PRINTF ("hub_port_reset: resetting port %d...\n" , port); -for (tries =0 ; tries <MAX_TRIES ; tries++) { - -usb_set_port_feature (dev, port +1 ,USB_PORT_FEAT_RESET ); -wait_ms (200 ); +for (delay_time =0 ; + delay_time <HUB_RESET_TIMEOUT ; + delay_time += delay) { +/* wait to give the device a chance to reset */ +wait_ms (delay); -if (usb_get_port_status (dev, port +1 , &portsts) <0 ) { +/* read and decode port status */ + ret =usb_get_port_status (dev, port +1 , &portsts); +if (ret <0 ) {USB_HUB_PRINTF ("get_port_status failed status %lX\n" , dev->status); -return -1 ; +return ret; } portstatus =le16_to_cpu (portsts.wPortStatus); portchange =le16_to_cpu (portsts.wPortChange); -USB_HUB_PRINTF ("portstatus %x, change %x, %s\n" , - portstatus, portchange, -portspeed (portstatus)); +/* Device went away? */ +if (!(portstatus &USB_PORT_STAT_CONNECTION )) +return -ENOTCONN ; -USB_HUB_PRINTF ("STAT_C_CONNECTION = %d STAT_CONNECTION = %d" \ -" USB_PORT_STAT_ENABLE %d\n" , - (portchange &USB_PORT_STAT_C_CONNECTION ) ?1 :0 , - (portstatus &USB_PORT_STAT_CONNECTION ) ?1 :0 , - (portstatus &USB_PORT_STAT_ENABLE ) ?1 :0 ); +/* bomb out completely if the connection bounced */ +if ((portchange &USB_PORT_STAT_C_CONNECTION )) +return -ENOTCONN ; -if ((portchange &USB_PORT_STAT_C_CONNECTION ) || - !(portstatus &USB_PORT_STAT_CONNECTION )) -return -1 ; +/* if we`ve finished resetting, then break out of the loop */ +if (!(portstatus &USB_PORT_STAT_RESET ) && + (portstatus &USB_PORT_STAT_ENABLE )) { + *portstatus_ret = portstatus; +return 0 ; + } -if (portstatus &USB_PORT_STAT_ENABLE ) -break ; +/* switch to the long delay after two short delay failures */ +if (delay_time >=2 *HUB_SHORT_RESET_TIME ) + delay =HUB_LONG_RESET_TIME ; + +USB_HUB_PRINTF ( +"port %d not reset yet, waiting %dms\n" , + port, delay); + } + +return -1 ; +} + + +static int hub_port_reset (struct usb_device *dev,int port, +unsigned short *portstat) +{ +int tries, status; +unsigned delay =HUB_SHORT_RESET_TIME ; +int oldspeed = dev->speed; + +/* root hub ports have a slightly longer reset period +* (from USB 2.0 spec, section 7.1.7.5) +*/ +if (!dev->parent) { + delay =HUB_ROOT_RESET_TIME ; + } -wait_ms (200 ); +/* Some low speed devices have problems with the quick delay, so */ +/* be a bit pessimistic with those devices. RHbug #23670 */ +if (oldspeed ==USB_SPEED_LOW ) + delay =HUB_LONG_RESET_TIME ; + +USB_HUB_PRINTF ("hub_port_reset: resetting port %d...\n" , port); +for (tries =0 ; tries <MAX_TRIES ; tries++) { + + status =usb_set_port_feature (dev, port +1 ,USB_PORT_FEAT_RESET ); +if (status) +USB_HUB_PRINTF ("cannot reset port %d (err = %d)\n" , + port, status); +else { + status =hub_port_wait_reset (dev, port, delay, + portstat); +if (status && status != -ENOTCONN ) +USB_HUB_PRINTF ("port_wait_reset: err = %d\n" , + status); + } + +/* return on disconnect or reset */ +switch (status) { +case 0 : +/* TRSTRCY = 10 ms; plus some extra */ +wait_ms (10 +40 ); +/* FALL THROUGH */ +case -1 : +/* we have finished trying to reset, so return */ +usb_clear_port_feature (dev, + port +1 ,USB_PORT_FEAT_C_RESET ); +return 0 ; + } + +USB_HUB_PRINTF ( +"port %d not enabled, trying reset again...\n" , + port); + delay =HUB_LONG_RESET_TIME ; }if (tries ==MAX_TRIES ) {
@@ -1116,9 +1239,6 @@ static int hub_port_reset(struct usb_device *dev, int port,USB_HUB_PRINTF ("Maybe the USB cable is bad?\n" );return -1 ; } - -usb_clear_port_feature (dev, port +1 ,USB_PORT_FEAT_C_RESET ); - *portstat = portstatus;return 0 ; }
common/usb_storage.c +43 -12
119 lines not on this page · raw message
drivers/usb/host/ehci-hcd.c +15 -5
@@ -330,6 +330,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,uint32_t c, toggle;uint32_t cmd;int ret =0 ; +int result =USB_EFAIL ;#ifdef CONFIG_USB_EHCI_DATA_ALIGN /* In case ehci host requires alignment for buffers */
@@ -342,8 +343,8 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,if (!align_buf)return -1 ;if ((int )align_buf & (CONFIG_USB_EHCI_DATA_ALIGN -1 )) - buffer = (void *)((int )align_buf + -CONFIG_USB_EHCI_DATA_ALIGN - + buffer = (void *)((int )align_buf + +CONFIG_USB_EHCI_DATA_ALIGN - ((int )align_buf & (CONFIG_USB_EHCI_DATA_ALIGN -1 )));else buffer = align_buf;
@@ -475,7 +476,10 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, goto fail; } -/* Wait for TDs to be processed. */ +/* +* Wait for TDs to be processed. We wait 3s since some USB +* sticks can take a long time immediately after system reset +*/ ts =get_timer (0 ); vtd = td; do {
@@ -484,7 +488,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, token =hc32_to_cpu (vtd->qt_token);if (!(token &0x80 ))break ; - }while (get_timer (ts) <CONFIG_SYS_HZ ); + }while (get_timer (ts) <CONFIG_SYS_HZ *3 );/* Disable async schedule. */ cmd =ehci_readl (&hcor->or_usbcmd);
@@ -497,6 +501,12 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,printf ("EHCI fail timeout STD_ASS reset\n" ); goto fail; } +/* check that the TD processing happened */ +if (token &0x80 ) { +printf ("EHCI timed out on TD - token=%#x\n" , token); + result =USB_EDEVCRITICAL ; + goto fail; + } qh_list.qh_link =cpu_to_hc32 ((uint32_t )&qh_list |QH_LINK_TYPE_QH );
@@ -559,7 +569,7 @@ fail: td = (void *)hc32_to_cpu (qh->qh_overlay.qt_next); }ehci_free (qh,sizeof (*qh)); -return -1 ; +return result; }static inline int min3 (int a,int b,int c)
include/usb.h +11 -0
@@ -42,6 +42,16 @@#define USB_CNTL_TIMEOUT 100/* 100ms timeout */ +/* +* Errors we can report, e.g. return USB_EDEVCRITICAL +* Use -ve numbers to fit in with usb_storage +* U-Boot needs some unified numbers +*/ +#define USB_EOK 0/* ok, no error */ +#define USB_EFAIL -1/* general failure(!) */ +#define USB_EDEVCRITICAL -2/* must reset device on hub */ +#define USB_ENEXTFREE -3/* next free error number */ +/* device request (setup) */ struct devrequest {unsigned char requesttype;
@@ -198,6 +208,7 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum,int usb_clear_halt (struct usb_device *dev,int pipe);int usb_string (struct usb_device *dev,int index,char *buf,size_t size);int usb_set_interface (struct usb_device *dev,int interface,int alternate); +int usb_restart_device (struct usb_device *dev);/* big endian -> little endian conversion */ /* some CPUs are already little endian e.g. the ARM920T */
--
1.7.3.1
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi Simon,
2010/12/10 Simon Glass <[email protected]>:
Quoted 4 lines
I am sending this to the list looking for comments. Testing has been confined to just a few USB sticks - no USB hard drives, USB card readers, etc. But there are reports on the mailing list of problems with U-Boot's detection of USB mass storage devices.
First impression is that it looks interesting, however I have a few remarks, see below.
Quoted 10 lines
This patch:
1. Increases the USB descriptor submission timeout to 3 seconds since the original 1 second timeout seems arbitrary
2. Replaces the delay-based reset logic with logic which waits until it sees the reset is successful, rather than blindly continuing
3. Resets and retries a USB mass storage device after it fails once, in case even 3 seconds is not enough
Can you please split this patch up to multiple patches, each solving a different issue?
Quoted 25 lines
BUG=chromiumos-6780
TEST=tried with four different USB sticks, including two which previously failed
Change-Id: I5bd8891bff67a74b758e349f2a3b3575806eed59Signed-off-by Simon Glass <[email protected]>---
?common/usb.c ? ? ? ? ? ? ? ?| ?176 ++++++++++++++++++++++++++++++++++++------- ?common/usb_storage.c ? ? ? ?| ? 55 +++++++++++--- ?drivers/usb/host/ehci-hcd.c | ? 20 ++++- ?include/usb.h ? ? ? ? ? ? ? | ? 11 +++?4 files changed, 217 insertions(+), 45 deletions(-)
common/usb.c +2
-0@@ -222,10 +222,14 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, ?int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, ? ? ? ? ? ? ? ? ? ? ? ?void *data, int len, int *actual_length, int timeout) ?{ + ? ? ? int err; + ? ? ? ?if (len < 0) ? ? ? ? ? ? ? ?return -1;
Quoted 5 lines
? ? ? ?dev->status =
USB_ST_NOT_PROC; /*not yet processed */
- ? ? ?submit_bulk_msg(dev, pipe, data, len);
+ ? ? ? err =submit_bulk_msg(dev, pipe, data, len);
+ ? ? ? if (err < 0)
+ ? ? ? ? ? ? ? return err;
Seems you only focused on the ehci-hcd driver. How does this change in behaviour impact other host controller drivers like, for example, ohci?
Is any regression in those drivers possible or to be expected?
common/usb.c static inline char *portspeed(int portstatus) · line 1118
Quoted 5 lines
common/usb.c +2
-2-static int hub_port_reset (struct usb_device *dev,int port, - ? ? ? ? ? ? ? ? ? ? ? unsigned short *portstat) +/* brought this in from kernel 2.6.36 as it is a problem area. Some USB +sticks do not operate properly with the previous reset code */
Multi line comments should be written like
/*
* comment line 1
* comment line 2
*/
Please fix globally.
common/usb.c
Quoted 11 lines
common/usb.c +10
-0+#define PORT_RESET_TRIES ? ? ? 5 +#define SET_ADDRESS_TRIES ? ? ?2 +#define GET_DESCRIPTOR_TRIES ? 2 +#define SET_CONFIG_TRIES ? ? ? (2 * (use_both_schemes + 1)) +#define USE_NEW_SCHEME (i) ? ? ?((i) / 2 == old_scheme_first) + +#define HUB_ROOT_RESET_TIME ? ?50 ? ? ?/* times are in msec */ +#define HUB_SHORT_RESET_TIME ? 10 +#define HUB_LONG_RESET_TIME ? ?200 +#define HUB_RESET_TIMEOUT ? ? ?500
How are these times estimated? Are these magic, or is there a deeper thought behind them?
Quoted 11 lines
common/usb.c +5
-0+ +#define ENOTCONN 107 + +static int hub_port_wait_reset (struct usb_device *dev,int port, + ? ? ? ? ? ? ? ? ? ? ? unsigned int delay, unsigned short *portstatus_ret)?{
- ? ? ? int tries;
+ ? ? ? intdelay_time, ret;
? ? ? ?structusb_port_statusportsts;
? ? ? ?unsigned short portstatus, portchange;
Quoted 7 lines
- ? ? ?
USB_HUB_PRINTF("hub_port_reset: resetting port %d...\n", port);
- ? ? ? for (tries = 0; tries <MAX_TRIES; tries++) {
-
- ? ? ? ? ? ? ?usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET);
- ? ? ? ? ? ? ?wait_ms(200);
+ ? ? ? for (delay_time= 0;
+ ? ? ? ? ? ? ? ? ? ? ?delay_time<HUB_RESET_TIMEOUT;
You go from a 200msec timeout to a 500msec timeout. Is there a special reason for this?
Quoted 3 lines
+ ? ? ? ? ? ? ? ? ? ? ?
delay_time+= delay) {
+ ? ? ? ? ? ? ? /* wait to give the device a chance to reset */
+ ? ? ? ? ? ? ?wait_ms(delay);
The ' delay' argument of this routine is misleading since it does not specify a delay time, but the time between 2 polls on usb_get_port_status().
The maximum delay is specified by HUB_RESET_TIMEOUT here.
Quoted 39 lines
- ? ? ? ? ? ? ? if (
usb_get_port_status(dev, port + 1, &portsts)< 0) {
+ ? ? ? ? ? ? ? /* read and decode port status */
+ ? ? ? ? ? ? ? ret =usb_get_port_status(dev, port + 1, &portsts);
+ ? ? ? ? ? ? ? if (ret < 0) {
? ? ? ? ? ? ? ? ? ? ? ?USB_HUB_PRINTF("get_port_status failed status %lX\n", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?dev->status);
- ? ? ? ? ? ? ? ? ? ? ? return -1;
+ ? ? ? ? ? ? ? ? ? ? ? return ret;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?portstatus =le16_to_cpu(portsts.wPortStatus);
? ? ? ? ? ? ? ?portchange =le16_to_cpu(portsts.wPortChange);- ? ? ? ? ? ? ? USB_HUB_PRINTF("portstatus %x, change %x, %s\n",
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? portstatus, portchange,
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? portspeed(portstatus));
+ ? ? ? ? ? ? ? /* Device went away? */
+ ? ? ? ? ? ? ? if (!(portstatus &USB_PORT_STAT_CONNECTION))
+ ? ? ? ? ? ? ? ? ? ? ? return-ENOTCONN;- ? ? ? ? ? ? ? USB_HUB_PRINTF("STAT_C_CONNECTION = %d
STAT_CONNECTION= %d" \
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?" ?USB_PORT_STAT_ENABLE %d\n",
- ? ? ? ? ? ? ? ? ? ? ? (portchange &USB_PORT_STAT_C_CONNECTION) ? 1 : 0,
- ? ? ? ? ? ? ? ? ? ? ? (portstatus &USB_PORT_STAT_CONNECTION) ? 1 : 0,
- ? ? ? ? ? ? ? ? ? ? ? (portstatus &USB_PORT_STAT_ENABLE) ? 1 : 0);
+ ? ? ? ? ? ? ? /* bomb out completely if the connection bounced */
+ ? ? ? ? ? ? ? if ((portchange &USB_PORT_STAT_C_CONNECTION))
+ ? ? ? ? ? ? ? ? ? ? ? return-ENOTCONN;- ? ? ? ? ? ? ? if ((portchange &
USB_PORT_STAT_C_CONNECTION) ||
- ? ? ? ? ? ? ? ? ? !(portstatus &USB_PORT_STAT_CONNECTION))
- ? ? ? ? ? ? ? ? ? ? ? return -1;
+ ? ? ? ? ? ? ? /* if we`ve finished resetting, then break out of the loop */
+ ? ? ? ? ? ? ? if (!(portstatus &USB_PORT_STAT_RESET) &&
+ ? ? ? ? ? ? ? ? ? (portstatus &USB_PORT_STAT_ENABLE)) {
+ ? ? ? ? ? ? ? ? ? ? ?*portstatus_ret= portstatus;
+ ? ? ? ? ? ? ? ? ? ? ? return 0;
+ ? ? ? ? ? ? ? }
Quoted 5 lines
- ? ? ? ? ? ? ? if (portstatus &
USB_PORT_STAT_ENABLE)
- ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? /* switch to the long delay after two short delay failures */
+ ? ? ? ? ? ? ? if (delay_time>= 2 *HUB_SHORT_RESET_TIME)
+ ? ? ? ? ? ? ? ? ? ? ? delay =HUB_LONG_RESET_TIME;
You are changing the 'delay' routine argument here. Why even specify it on the argument list if:
* it does not do what to expect.
* it gets overridden anyway.
Quoted 3 lines
+ ? ? ? /* root hub ports have a slightly longer reset period
+ ? ? ? ?* (from USB 2.0 spec, section 7.1.7.5)
+ ? ? ? ?*/
wrong style multiline comment.
Quoted 3 lines
+ ? ? ? if (!dev->parent) {
+ ? ? ? ? ? ? ? delay =HUB_ROOT_RESET_TIME;
+ ? ? ? }
No parenthesis required.
Quoted 3 lines
- ? ? ? ? ? ? ?
wait_ms(200);
+ ? ? ? /* Some low speed devices have problems with the quick delay, so */
+ ? ? ? /* ?be a bit pessimistic with those devices. RHbug #23670 */
Multiline comment
Quoted 1 line
+ ? ? ? ? ? ? ? ? ? ? ? /* TRSTRCY = 10 ms; plus some extra */
magic plus some extra magic...
Quoted 10 lines
common/usb_storage.c +1
-0@@ -158,9 +158,10 @@ struct us_data { ?static struct us_data usb_stor[USB_MAX_STOR_DEV]; +/* start our error numbers after the USB ones */ ?#define
USB_STOR_TRANSPORT_GOOD? ? ? ? ? 0
common/usb_storage.c struct us_data {
Quoted 4 lines
common/usb_storage.c +2
-2-#define USB_STOR_TRANSPORT_FAILED -1 -#define USB_STOR_TRANSPORT_ERROR ?-2 +#define USB_STOR_TRANSPORT_FAILED (USB_ENEXTFREE) +#define USB_STOR_TRANSPORT_ERROR ?(USB_ENEXTFREE-1)
Weird way to define error codes...
Please make it clearer without magic ids that needs to match magically to some ids in a header file (USB_ENEXTFREE = -3) (enum?)
Quoted 11 lines
?int
usb_stor_get_info(struct usb_device *dev, struct us_data *us, ? ? ? ? ? ? ? ? ? ? ?block_dev_desc_t *dev_desc);common/usb_storage.c +1
-0@@ -213,6 +214,7 @@ int usb_stor_scan(int mode) ?{ ? ? ? ?unsigned char i; ? ? ? ?struct usb_device *dev; + ? ? ? int result;? ? ? ?/* GJ */
? ? ? ?memset(usb_stor_buf, 0,sizeof(usb_stor_buf));common/usb_storage.c +0
-0@@ -244,8 +246,21 @@ int usb_stor_scan(int mode)
Quoted 3 lines
? ? ? ? ? ? ? ? ? ? ? ?/* ok, it is a storage devices ? ? ? ? ? ? ? ? ? ? ? ? * get info and fill it in ? ? ? ? ? ? ? ? ? ? ? ? */
Bad style multiline comment
Quoted 5 lines
- ? ? ? ? ? ? ? ? ? ? ? if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
- ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &usb_dev_desc[usb_max_devs]) == 1)
+ ? ? ? ? ? ? ? ? ? ? ? result = usb_stor_get_info(dev, &usb_stor[usb_max_devs],
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &usb_dev_desc[usb_max_devs]);
+ ? ? ? ? ? ? ? ? ? ? ? if (result ==USB_EDEVCRITICAL) {
You are changing the behaviour for the ehci host controller only (since that one only knows USB_EDEVCRITICAL)
Please make it suitable for all other host controller drivers as well, or patch those drivers also.
The problems you are trying to fix are not likely to be for ehci only, since you modify generic code...
Quoted 4 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /*
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?* Something there, but failed badly.
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?* Retry one more time. This happens
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?* sometimes with some USB sticks,
Quoted 8 lines
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?* e.g. Patriot Rage ID 13fe:3800
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*/
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf (".");
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?usb_restart_device(dev); ?/* ignore return value */
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? result = usb_stor_get_info(dev, &usb_stor[usb_max_devs],
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &usb_dev_desc[usb_max_devs]);
+ ? ? ? ? ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? ? ? ? ? if (result == 1)
Would a switch case or ' else if' not be nicer?
Quoted 7 lines
?static int
usb_request_sense(ccb *srb, struct us_data *ss)?{
+ ? ? ? int result;
? ? ? ?char *ptr;? ? ? ?ptr = (char *)srb->pdata;
common/usb_storage.c static int usb_request_sense(ccb *srb, struct us_data *ss) · line 935
Quoted 9 lines
common/usb_storage.c +5
-1@@ -909,7 +928,12 @@ static int usb_request_sense(ccb *srb, struct us_data *ss) ? ? ? ?srb->datalen = 18; ? ? ? ?srb->pdata = &srb->sense_buf[0]; ? ? ? ?srb->cmdlen = 12; - ? ? ? ss->transport(srb, ss); + ? ? ? result = ss->transport(srb, ss); + ? ? ? if (result < 0) { + ? ? ? ? ? ? ? if (result != USB_EDEVCRITICAL) + ? ? ? ? ? ? ? ? ? ? ? USB_STOR_PRINTF("Request Sense failed\n"); + ? ? ? ? ? ? ? return result;
You are changing behaviour for ALL host controller driver types here. Are you sure you want this? (Better: again... please fix all drivers...)
Quoted 6 lines
common/usb_storage.c +1
-0+ ? ? ? } ? ? ? ?USB_STOR_PRINTF("Request Sense returned %02X %02X %02X\n", ? ? ? ? ? ? ? ? ? ? ? ?srb->sense_buf[2], srb->sense_buf[12], ? ? ? ? ? ? ? ? ? ? ? ?srb->sense_buf[13]);@@ -1372,11 +1400,14 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
Quoted 8 lines
?#endif /*
CONFIG_USB_BIN_FIXUP*/
? ? ? ?USB_STOR_PRINTF("ISO Vers %X, Response Data %X\n", usb_stor_buf[2], ? ? ? ? ? ? ? ? ? ? ? ?usb_stor_buf[3]);
- ? ? ? if (usb_test_unit_ready(pccb, ss)) {
+ ? ? ? result =usb_test_unit_ready(pccb, ss);
+ ? ? ? if (result) {
+ ? ? ? ? ? ? ? if (result ==USB_EDEVCRITICAL)
+ ? ? ? ? ? ? ? ? ? ? ? return result;
Please fix all drivers...
Quoted 34 lines
? ? ? ? ? ? ? ?printf("Device NOT ready\n"
- ? ? ? ? ? ? ? ? ? ? ?" ? Request Sense returned %02X %02X %02X\n",
- ? ? ? ? ? ? ? ? ? ? ?pccb->sense_buf[2], pccb->sense_buf[12],
- ? ? ? ? ? ? ? ? ? ? ?pccb->sense_buf[13]);
+ ? ? ? ? ? ? ? ? ? ? ? " ? Request Sense returned %02X %02X %02X\n",
+ ? ? ? ? ? ? ? pccb->sense_buf[2], pccb->sense_buf[12],
+ ? ? ? ? ? ? ? pccb->sense_buf[13]);
? ? ? ? ? ? ? ?if (dev_desc->removable== 1) {
? ? ? ? ? ? ? ? ? ? ? ?dev_desc->type = perq;
? ? ? ? ? ? ? ? ? ? ? ?return 1;drivers/usb/host/ehci-hcd.c +1
-0@@ -330,6 +330,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, ? ? ? ?uint32_t c, toggle; ? ? ? ?uint32_t cmd; ? ? ? ?int ret = 0; + ? ? ? int result = USB_EFAIL;?#ifdef
CONFIG_USB_EHCI_DATA_ALIGN
? ? ? ?/* In case ehci host requires alignment for buffers */drivers/usb/host/ehci-hcd.c +2
-2@@ -342,8 +343,8 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, ? ? ? ? ? ? ? ?if (!align_buf) ? ? ? ? ? ? ? ? ? ? ? ?return -1; ? ? ? ? ? ? ? ?if ((int)align_buf & (CONFIG_USB_EHCI_DATA_ALIGN - 1)) - ? ? ? ? ? ? ? ? ? ? ? buffer = (void *)((int)align_buf + - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CONFIG_USB_EHCI_DATA_ALIGN - + ? ? ? ? ? ? ? ? ? ? ? buffer = (void *)((int)align_buf + + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? CONFIG_USB_EHCI_DATA_ALIGN - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?((int)align_buf & (CONFIG_USB_EHCI_DATA_ALIGN - 1)));? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ?buffer =align_buf;
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 482
Quoted 8 lines
drivers/usb/host/ehci-hcd.c +4
-1@@ -475,7 +476,10 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, ? ? ? ? ? ? ? ?goto fail; ? ? ? ?} - ? ? ? /* Wait for TDs to be processed. */ + ? ? ? /* +? ? ? ?* Wait for TDs to be processed. We wait 3s since some USB +? ? ? ?* sticks can take a long time immediately after system reset +? ? ? ?*/
Cool... This multiline comment is correct ;-)
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 491
Quoted 9 lines
drivers/usb/host/ehci-hcd.c +1
-1? ? ? ?ts = get_timer(0); ? ? ? ?vtd = td; ? ? ? ?do {@@ -484,7 +488,7 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, ? ? ? ? ? ? ? ?token = hc32_to_cpu(vtd->qt_token); ? ? ? ? ? ? ? ?if (!(token & 0x80)) ? ? ? ? ? ? ? ? ? ? ? ?break; - ? ? ? } while (get_timer(ts) < CONFIG_SYS_HZ); + ? ? ? } while (get_timer(ts) < CONFIG_SYS_HZ * 3);
Same valid for other host controller drivers?
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 509
Quoted 13 lines
? ? ? ?/* Disable async schedule. */
? ? ? ?cmd =ehci_readl(&hcor->or_usbcmd);drivers/usb/host/ehci-hcd.c +6
-0@@ -497,6 +501,12 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, ? ? ? ? ? ? ? ?printf("EHCI fail timeout STD_ASS reset\n"); ? ? ? ? ? ? ? ?goto fail; ? ? ? ?} + ? ? ? /* check that the TD processing happened */ + ? ? ? if (token & 0x80) { + ? ? ? ? ? ? ? printf("EHCI timed out on TD - token=%#x\n", token); + ? ? ? ? ? ? ? result = USB_EDEVCRITICAL; + ? ? ? ? ? ? ? goto fail; + ? ? ? }
this one too...
Quoted 19 lines
drivers/usb/host/ehci-hcd.c +1
-1? ? ? ?qh_list.qh_link = cpu_to_hc32((uint32_t)&qh_list | QH_LINK_TYPE_QH);@@ -559,7 +569,7 @@ fail: ? ? ? ? ? ? ? ?td = (void *)hc32_to_cpu(qh->qh_overlay.qt_next); ? ? ? ?} ? ? ? ?ehci_free(qh, sizeof(*qh)); - ? ? ? return -1; + ? ? ? return result; ?} ?static inline int min3(int a, int b, int c)include/usb.h +0
-0@@ -42,6 +42,16 @@?#define
USB_CNTL_TIMEOUT100 /* 100ms timeout */
Quoted 3 lines
+/*
+ * Errors we can report, e.g. returnUSB_EDEVCRITICAL
+ * Use -ve numbers to fit in withusb_storage
Yak...
Quoted 16 lines
+ * U-Boot needs some unified numbers
+ */include/usb.h +5
-0+#define USB_EOK ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ?/* ok, no error */ +#define USB_EFAIL ? ? ? ? ? ? ?-1 ? ? ?/* general failure(!) */ +#define USB_EDEVCRITICAL ? ? ? -2 ? ? ?/* must reset device on hub */ +#define USB_ENEXTFREE ? ? ? ? ?-3 ? ? ?/* next free error number */ +?/* device request (setup) */
?struct devrequest {
? ? ? ?unsigned char ? requesttype;include/usb.h +1
-0@@ -198,6 +208,7 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum, ?int usb_clear_halt(struct usb_device *dev, int pipe); ?int usb_string(struct usb_device *dev, int index, char *buf, size_t size); ?int usb_set_interface(struct usb_device *dev, int interface, int alternate); +int usb_restart_device (struct usb_device *dev);
Quoted 2 lines
?/* big endian -> little endian conversion */
?/* some CPUs are already little endian e.g. the ARM920T */
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi Remy,
Thanks for the feedback. I will update the patch with your changes.
Unfortunately I don't have a lot of hardware to try, hence the list post. I will be doing some more testing in January so will come back to it then. In the meantime I am interested in views as to whether this makes a difference on OHCI, different ARM chips, etc.
Regards,
Simon
Quoted 445 lines · Remy Bohmer
Hi Simon,
2010/12/10 Simon Glass <[email protected]>:
Quoted 4 lines
I am sending this to the list looking for comments. Testing has been confined to just a few USB sticks - no USB hard drives, USB card readers, etc. But there are reports on the mailing list of problems with U-Boot's detection of USB mass storage devices.
First impression is that it looks interesting, however I have a few remarks, see below.
Quoted 10 lines
This patch:
1. Increases the USB descriptor submission timeout to 3 seconds since the original 1 second timeout seems arbitrary
2. Replaces the delay-based reset logic with logic which waits until it sees the reset is successful, rather than blindly continuing
3. Resets and retries a USB mass storage device after it fails once, in case even 3 seconds is not enough
Can you please split this patch up to multiple patches, each solving a different issue?
Quoted 8 lines
BUG=chromiumos-6780
TEST=tried with four different USB sticks, including two which previously failed
Change-Id: I5bd8891bff67a74b758e349f2a3b3575806eed59Signed-off-by Simon Glass <[email protected]>--- common/usb.c | 176++++++++++++++++++++++++++++++++++++-------
common/usb.c int usb_control_msg(struct usb_device *dev,
Quoted 10 lines
common/usb_storage.c | 55 +++++++++++--- drivers/usb/host/ehci-hcd.c | 20 ++++- include/usb.h | 11 +++ 4 files changed, 217 insertions(+), 45 deletions(-)common/usb.c +0
-0@@ -222,10 +222,14 @@ int usb_control_msg(struct usb_device *dev,unsigned int pipe,
common/usb.c int usb_control_msg(struct usb_device *dev, · line 223
Quoted 2 lines
common/usb.c +0
-0int usb_bulk_msg (struct usb_device *dev,unsigned int pipe, void *data, int len, int *actual_length, inttimeout)
common/usb.c int usb_control_msg(struct usb_device *dev, unsigned int pipe, · line 232
Quoted 10 lines
common/usb.c +5
-1{ +int err; +if (len <0 )return -1 ; dev->status =USB_ST_NOT_PROC ;/*not yet processed */ -submit_bulk_msg (dev, pipe, data, len); + err =submit_bulk_msg (dev, pipe, data, len); +if (err <0 ) +return err;Seems you only focused on the ehci-hcd driver. How does this change in behaviour impact other host controller drivers like, for example, ohci?
Is any regression in those drivers possible or to be expected?common/usb.c static inline char *portspeed(int portstatus) · line 1118
Quoted 5 lines
common/usb.c +2
-2-static int hub_port_reset (struct usb_device *dev,int port, -unsigned short *portstat) +/* brought this in from kernel 2.6.36 as it is a problem area. Some USB +sticks do not operate properly with the previous reset code */ Multi line comments should be written like
/*
* comment line 1
* comment line 2
*/
Please fix globally.common/usb.c static inline char *portspeed(int portstatus)
Quoted 11 lines
common/usb.c +10
-0+#define PORT_RESET_TRIES 5 +#define SET_ADDRESS_TRIES 2 +#define GET_DESCRIPTOR_TRIES 2 +#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1)) +#define USE_NEW_SCHEME (i) ((i) / 2 == old_scheme_first) + +#define HUB_ROOT_RESET_TIME 50/* times are in msec */ +#define HUB_SHORT_RESET_TIME 10 +#define HUB_LONG_RESET_TIME 200 +#define HUB_RESET_TIMEOUT 500How are these times estimated? Are these magic, or is there a deeper thought behind them?
common/usb.c static inline char *portspeed(int portstatus)
Quoted 5 lines
common/usb.c +5
-0+ +#define ENOTCONN 107 + +static int hub_port_wait_reset (struct usb_device *dev,int port, + unsigned int delay, unsigned short
*portstatus_ret)common/usb.c static inline char *portspeed(int portstatus) · line 1140
Quoted 13 lines
{
common/usb.c +3
-6-int tries; +int delay_time, ret;struct usb_port_status portsts;unsigned short portstatus, portchange; -USB_HUB_PRINTF ("hub_port_reset: resetting port %d...\n" , port); -for (tries =0 ; tries <MAX_TRIES ; tries++) { - -usb_set_port_feature (dev, port +1 ,USB_PORT_FEAT_RESET ); -wait_ms (200 ); + for (delay_time = 0; + delay_time < HUB_RESET_TIMEOUT;You go from a 200msec timeout to a 500msec timeout. Is there a special reason for this?
common/usb.c static inline char *portspeed(int portstatus) · line 1143
Quoted 3 lines
common/usb.c +3
-0+ delay_time += delay) { +/* wait to give the device a chance to reset */ +wait_ms (delay);The ' delay' argument of this routine is misleading since it does not specify a delay time, but the time between 2 polls on
usb_get_port_status().
The maximum delay is specified byHUB_RESET_TIMEOUThere.common/usb.c static inline char *portspeed(int portstatus)
Quoted 6 lines
common/usb.c +3
-1-if (usb_get_port_status (dev, port +1 , &portsts) <0 ) { +/* read and decode port status */ + ret =usb_get_port_status (dev, port +1 , &portsts); +if (ret <0 ) { USB_HUB_PRINTF("get_port_status failed status%lX\n",
Quoted 5 lines
dev->status);common/usb.c +1
-1-return -1 ; +return ret; } portstatus =le16_to_cpu (portsts.wPortStatus);common/usb.c static inline char *portspeed(int portstatus)
Quoted 10 lines
common/usb.c +3
-4portchange =le16_to_cpu (portsts.wPortChange); -USB_HUB_PRINTF ("portstatus %x, change %x, %s\n" , - portstatus, portchange, -portspeed (portstatus)); +/* Device went away? */ +if (!(portstatus &USB_PORT_STAT_CONNECTION )) +return -ENOTCONN ; - USB_HUB_PRINTF("STAT_C_CONNECTION = %d STAT_CONNECTION =%d" \
common/usb.c
Quoted 2 lines
common/usb.c +0
-2-" USB_PORT_STAT_ENABLE %d\n" , - (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 :0,
common/usb.c static inline char *portspeed(int portstatus)
Quoted 10 lines
common/usb.c +4
-5- (portstatus &USB_PORT_STAT_CONNECTION ) ?1 :0 , - (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0); +/* bomb out completely if the connection bounced */ +if ((portchange &USB_PORT_STAT_C_CONNECTION )) +return -ENOTCONN ; -if ((portchange &USB_PORT_STAT_C_CONNECTION ) || - !(portstatus &USB_PORT_STAT_CONNECTION )) -return -1 ; +/* if we`ve finished resetting, then break out of the loop */
common/usb.c static inline char *portspeed(int portstatus)
Quoted 9 lines
common/usb.c +6
-2+if (!(portstatus &USB_PORT_STAT_RESET ) && + (portstatus &USB_PORT_STAT_ENABLE )) { + *portstatus_ret = portstatus; +return 0 ; + } -if (portstatus &USB_PORT_STAT_ENABLE ) -break ; +/* switch to the long delay after two short delay failures */
common/usb.c
Quoted 2 lines
common/usb.c +2
-0+if (delay_time >=2 *HUB_SHORT_RESET_TIME ) + delay =HUB_LONG_RESET_TIME ;You are changing the 'delay' routine argument here. Why even specify it on the argument list if:
* it does not do what to expect.
* it gets overridden anyway.common/usb.c static inline char *portspeed(int portstatus) · line 1192
Quoted 3 lines
common/usb.c +3
-0+/* root hub ports have a slightly longer reset period +* (from USB 2.0 spec, section 7.1.7.5) +*/ wrong style multiline comment.
common/usb.c static inline char *portspeed(int portstatus) · line 1195
Quoted 3 lines
common/usb.c +3
-0+if (!dev->parent) { + delay =HUB_ROOT_RESET_TIME ; + }No parenthesis required.
common/usb.c
Quoted 2 lines
common/usb.c +1
-1-wait_ms (200 ); +/* Some low speed devices have problems with the quick delay, so */
Quoted 1 line
+ /* be a bit pessimistic with those devices. RHbug #23670 */
Multiline comment
Quoted 1 line
+ /* TRSTRCY = 10 ms; plus some extra */
magic plus some extra magic...
Quoted 5 lines
common/usb_storage.c +0
-0common/usb_storage.c struct us_data { · line 164
Quoted 9 lines
common/usb_storage.c +3
-2@@ -158,9 +158,10 @@ struct us_data {static struct us_data usb_stor[USB_MAX_STOR_DEV ]; +/* start our error numbers after the USB ones */ #define USB_STOR_TRANSPORT_GOOD 0 -#define USB_STOR_TRANSPORT_FAILED -1 -#define USB_STOR_TRANSPORT_ERROR -2 +#define USB_STOR_TRANSPORT_FAILED (USB_ENEXTFREE) +#define USB_STOR_TRANSPORT_ERROR (USB_ENEXTFREE-1)Weird way to define error codes...
Please make it clearer without magic ids that needs to match magically to some ids in a header file (USB_ENEXTFREE= -3) (enum?)Quoted 11 lines
common/usb_storage.c +1
-0int usb_stor_get_info (struct usb_device *dev,struct us_data *us,block_dev_desc_t *dev_desc);@@ -213,6 +214,7 @@ int usb_stor_scan(int mode) {unsigned char i;struct usb_device *dev; +int result;/* GJ */ memset (usb_stor_buf,0 ,sizeof (usb_stor_buf));common/usb_storage.c int usb_stor_scan(int mode) · line 248
Quoted 3 lines
common/usb_storage.c +0
-0@@ -244,8 +246,21 @@ int usb_stor_scan(int mode)/* ok, it is a storage devices * get info and fill it in */ Bad style multiline comment
common/usb_storage.c int usb_stor_scan(int mode) · line 247
Quoted 1 line
common/usb_storage.c +0
-1- if (usb_stor_get_info(dev,&usb_stor[usb_max_devs],
common/usb_storage.c int usb_stor_scan(int mode) · line 248
Quoted 1 line
common/usb_storage.c +0
-1-&usb_dev_desc[usb_max_devs]) == 1)
common/usb_storage.c int usb_stor_scan(int mode) · line 249
Quoted 1 line
common/usb_storage.c +1
-0+ result = usb_stor_get_info(dev,&usb_stor[usb_max_devs],
common/usb_storage.c int usb_stor_scan(int mode) · line 250
Quoted 1 line
common/usb_storage.c +1
-0+&usb_dev_desc[usb_max_devs]);
common/usb_storage.c int usb_stor_scan(int mode) · line 251
Quoted 1 line
common/usb_storage.c +1
-0+if (result ==USB_EDEVCRITICAL ) {You are changing the behaviour for the ehci host controller only (since that one only knows
USB_EDEVCRITICAL)
Please make it suitable for all other host controller drivers as well, or patch those drivers also.
The problems you are trying to fix are not likely to be for ehci only, since you modify generic code...common/usb_storage.c int usb_stor_scan(int mode)
Quoted 8 lines
common/usb_storage.c +8
-0+/* +* Something there, but failed badly. +* Retry one more time. This happens +* sometimes with some USB sticks, +* e.g. Patriot Rage ID 13fe:3800 +*/ +printf ("." ); +usb_restart_device (dev);/* ignore return value */
common/usb_storage.c int usb_stor_scan(int mode) · line 260
Quoted 1 line
common/usb_storage.c +1
-0+ result = usb_stor_get_info(dev,&usb_stor[usb_max_devs],
common/usb_storage.c int usb_stor_scan(int mode) · line 261
Quoted 1 line
common/usb_storage.c +1
-0+&usb_dev_desc[usb_max_devs]);
common/usb_storage.c int usb_stor_scan(int mode) · line 263
Quoted 2 lines
common/usb_storage.c +2
-0+ } +if (result ==1 )Would a switch case or ' else if' not be nicer?
common/usb_storage.c static int usb_request_sense(ccb *srb, struct
Quoted 7 lines
common/usb_storage.c +1
-0static int usb_request_sense (ccb *srb,struct us_data *ss) { +int result;char *ptr; ptr = (char *)srb->pdata;@@ -909,7 +928,12 @@ static int usb_request_sense(ccb *srb, struct
us_data*ss)common/usb_storage.c static int usb_request_sense(ccb *srb, struct us_data *ss) · line 935
Quoted 9 lines
common/usb_storage.c +5
-1srb->datalen =18 ; srb->pdata = &srb->sense_buf[0 ]; srb->cmdlen =12 ; - ss->transport (srb, ss); + result = ss->transport (srb, ss); +if (result <0 ) { +if (result !=USB_EDEVCRITICAL ) +USB_STOR_PRINTF ("Request Sense failed\n" ); +return result;You are changing behaviour for ALL host controller driver types here. Are you sure you want this? (Better: again... please fix all drivers...)
common/usb_storage.c int usb_stor_get_info(struct usb_device *dev,
Quoted 6 lines
common/usb_storage.c +1
-0+ }USB_STOR_PRINTF ("Request Sense returned %02X %02X %02X\n" , srb->sense_buf[2 ], srb->sense_buf[12 ], srb->sense_buf[13 ]);@@ -1372,11 +1400,14 @@ int usb_stor_get_info(struct usb_device *dev,struct
us_data*ss,common/usb_storage.c int usb_stor_get_info(struct usb_device *dev, · line 1401
Quoted 2 lines
common/usb_storage.c +0
-0#endif /* CONFIG_USB_BIN_FIXUP */ USB_STOR_PRINTF("ISO Vers %X, Response Data %X\n",usb_stor_buf[2],
common/usb_storage.c int usb_stor_get_info(struct usb_device *dev, struct us_data *ss, · line 1406
Quoted 6 lines
common/usb_storage.c +4
-1usb_stor_buf[3]); -if (usb_test_unit_ready (pccb, ss)) { + result =usb_test_unit_ready (pccb, ss); +if (result) { +if (result ==USB_EDEVCRITICAL ) +return result;Please fix all drivers...
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned
Quoted 15 lines
common/usb_storage.c +3
-3printf ("Device NOT ready\n" -" Request Sense returned %02X %02X %02X\n" , - pccb->sense_buf[2 ], pccb->sense_buf[12 ], - pccb->sense_buf[13 ]); +" Request Sense returned %02X %02X %02X\n" , + pccb->sense_buf[2 ], pccb->sense_buf[12 ], + pccb->sense_buf[13 ]);if (dev_desc->removable ==1 ) { dev_desc->type = perq;return 1 ;drivers/usb/host/ehci-hcd.c +0
-0@@ -330,6 +330,7 @@ ehci_submit_async(struct usb_device *dev, unsignedlong pipe, void *buffer,
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned
Quoted 8 lines
drivers/usb/host/ehci-hcd.c +1
-0uint32_t c, toggle;uint32_t cmd;int ret =0 ; +int result =USB_EFAIL ;#ifdef CONFIG_USB_EHCI_DATA_ALIGN /* In case ehci host requires alignment for buffers */ @@ -342,8 +343,8 @@ ehci_submit_async(struct usb_device *dev, unsignedlong pipe, void *buffer,
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
Quoted 8 lines
drivers/usb/host/ehci-hcd.c +2
-2if (!align_buf)return -1 ;if ((int )align_buf & (CONFIG_USB_EHCI_DATA_ALIGN -1 )) - buffer = (void *)((int)align_buf + - CONFIG_USB_EHCI_DATA_ALIGN - + buffer = (void *)((int)align_buf + + CONFIG_USB_EHCI_DATA_ALIGN - ((int)align_buf &(
CONFIG_USB_EHCI_DATA_ALIGN- 1)));drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned
Quoted 3 lines
drivers/usb/host/ehci-hcd.c +0
-0else buffer = align_buf;@@ -475,7 +476,10 @@ ehci_submit_async(struct usb_device *dev, unsignedlong pipe, void *buffer,
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 482
Quoted 8 lines
drivers/usb/host/ehci-hcd.c +4
-1goto fail; } -/* Wait for TDs to be processed. */ +/* +* Wait for TDs to be processed. We wait 3s since some USB +* sticks can take a long time immediately after system reset +*/ Cool... This multiline comment is correct ;-)
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned
Quoted 4 lines
drivers/usb/host/ehci-hcd.c +0
-0ts =get_timer (0 ); vtd = td; do {@@ -484,7 +488,7 @@ ehci_submit_async(struct usb_device *dev, unsignedlong pipe, void *buffer,
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 491
Quoted 5 lines
drivers/usb/host/ehci-hcd.c +1
-1token =hc32_to_cpu (vtd->qt_token);if (!(token &0x80 ))break ; - }while (get_timer (ts) <CONFIG_SYS_HZ ); + }while (get_timer (ts) <CONFIG_SYS_HZ *3 );Same valid for other host controller drivers?
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned
Quoted 4 lines
drivers/usb/host/ehci-hcd.c +0
-0/* Disable async schedule. */ cmd =ehci_readl (&hcor->or_usbcmd);@@ -497,6 +501,12 @@ ehci_submit_async(struct usb_device *dev, unsignedlong pipe, void *buffer,
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer, · line 509
Quoted 9 lines
drivers/usb/host/ehci-hcd.c +6
-0printf ("EHCI fail timeout STD_ASS reset\n" ); goto fail; } +/* check that the TD processing happened */ +if (token &0x80 ) { +printf ("EHCI timed out on TD - token=%#x\n" , token); + result =USB_EDEVCRITICAL ; + goto fail; + }this one too...
drivers/usb/host/ehci-hcd.c ehci_submit_async(struct usb_device *dev, unsigned · line 510
Quoted 1 line
drivers/usb/host/ehci-hcd.c +0
-0qh_list.qh_link = cpu_to_hc32((uint32_t)&qh_list |
QH_LINK_TYPE_QH);Quoted 15 lines
drivers/usb/host/ehci-hcd.c +1
-1@@ -559,7 +569,7 @@ fail: td = (void *)hc32_to_cpu (qh->qh_overlay.qt_next); }ehci_free (qh,sizeof (*qh)); -return -1 ; +return result; }static inline int min3 (int a,int b,int c)include/usb.h +0
-0include/usb.h line 47
Quoted 6 lines
include/usb.h +3
-0@@ -42,6 +42,16 @@#define USB_CNTL_TIMEOUT 100/* 100ms timeout */ +/* +* Errors we can report, e.g. return USB_EDEVCRITICAL +* Use -ve numbers to fit in with usb_storage Yak...
include/usb.h int usb_get_class_descriptor(struct usb_device *dev,
Quoted 11 lines
include/usb.h +7
-0+* U-Boot needs some unified numbers +*/ +#define USB_EOK 0/* ok, no error */ +#define USB_EFAIL -1/* general failure(!) */ +#define USB_EDEVCRITICAL -2/* must reset device on hub */ +#define USB_ENEXTFREE -3/* next free error number */ +/* device request (setup) */ struct devrequest {unsigned char requesttype;@@ -198,6 +208,7 @@ int usb_get_class_descriptor(struct usb_device *dev,int ifnum,
include/usb.h int usb_get_class_descriptor(struct usb_device *dev, · line 209
Quoted 2 lines
include/usb.h +0
-0int usb_clear_halt (struct usb_device *dev,int pipe); int usb_string(struct usb_device *dev, int index, char *buf, size_tsize);
include/usb.h int usb_get_class_descriptor(struct usb_device *dev, · line 210
Quoted 1 line
include/usb.h +0
-0int usb_set_interface(struct usb_device *dev, int interface, intalternate);
include/usb.h int usb_get_class_descriptor(struct usb_device *dev, int ifnum, · line 214
Quoted 4 lines
include/usb.h +1
-0+int usb_restart_device (struct usb_device *dev);/* big endian -> little endian conversion */ /* some CPUs are already little endian e.g. the ARM920T */ Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi Simon,
2010/12/16 Simon Glass <[email protected]>:
Quoted 4 lines
Hi Remy,
Thanks for the feedback. I will update the patch with your changes. Unfortunately I don't have a lot of hardware to try, hence the list post. I will be doing some more testing in January so will come back to it then. In
Have you made any progress about this yet?
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi,
2011/1/31 Remy Bohmer <[email protected]>:
Quoted 9 lines
Hi Simon,
2010/12/16 Simon Glass <[email protected]>:
Quoted 4 lines
Hi Remy,
Thanks for the feedback. I will update the patch with your changes. Unfortunately I don't have a lot of hardware to try, hence the list post. I will be doing some more testing in January so will come back to it then. InHave you made any progress about this yet?
FYI: I have stored this patch in my u-boot-usb testing branch after rebasing to the current mainline.
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms). Once I get to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet.
Regards,
Simon
Quoted 22 lines · Remy Bohmer
Hi,
2011/1/31 Remy Bohmer <[email protected]>:
Quoted 6 lines
Hi Simon,
2010/12/16 Simon Glass <[email protected]>:
Quoted 3 lines
Hi Remy,
Thanks for the feedback. I will update the patch with your changes. Unfortunately I don't have a lot of hardware to try, hence the listpost. I
Quoted 1 line
Quoted 1 line
will be doing some more testing in January so will come back to it then.
In
Quoted 2 lines
Have you made any progress about this yet?
FYI: I have stored this patch in my u-boot-usb testing branch after rebasing to the current mainline.
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi,
2011/2/1 Simon Glass <[email protected]>:
Quoted 7 lines
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms).?Once I get to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet. Regards,
Simon
FWIW: I tested it on Atmel at91 and it does not seem to break OHCI, it does not seem to fix some troubles USB sticks I have here either...
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
I too am interested in this. I am running EHCI and have had problems with a number of USB storage devices, one of which (the SanDisk Cruzer) causes a crash due to it reporting the maximum LUN as 1. I'm also seeing some interesting performance issues with ext2 being extremely slow compared to FAT.
Additionally, I have been trying various USB hubs with EHCI and have found that a large percentage fail to work. Hopefully I'll look into it more soon when I get ahold of our USB analyzer again.
-Aaron
Quoted 18 lines · Remy Bohmer
Hi,
2011/2/1 Simon Glass <[email protected]>:
Quoted 8 lines
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms). Once I get to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet.
Regards,
SimonFWIW: I tested it on Atmel at91 and it does not seem to break OHCI, it does not seem to fix some troubles USB sticks I have here either...
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi Aaron,
OK good. Yes I notice ext2 is slow also, but the dcache is still off so I assumed that was it.
I have had no hub problems, but have only tried two types. I do recall a LUN patch floating around. I was going to try with an uSD card to see if it is needed there.
Regards,
Simon
Quoted 34 lines · Aaron Williams
I too am interested in this. I am running EHCI and have had problems with a number of USB storage devices, one of which (the SanDisk Cruzer) causes a crash due to it reporting the maximum LUN as 1. I'm also seeing some interesting performance issues with ext2 being extremely slow compared to FAT.
Additionally, I have been trying various USB hubs with EHCI and have found that a large percentage fail to work. Hopefully I'll look into it more soon
when I get ahold of our USB analyzer again.-Aaron
Quoted 6 lines · Remy Bohmer
Hi,
2011/2/1 Simon Glass <[email protected]>:
Quoted 3 lines
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms). Once Iget
Quoted 12 lines
Quoted 5 lines
to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet.
Regards,
SimonFWIW: I tested it on Atmel at91 and it does not seem to break OHCI, it does not seem to fix some troubles USB sticks I have here either...
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
We have our cache enabled since we're a cache coherent architecture so the performance is not due to cache (otherwise FAT would also be slow).
The hub that's failing has a transaction translator built in whereas the ones that work do not. For some reason it fails trying to reset this hub.
Granted, this hub is getting a lot of poor reviews, though I suspect the hub draws a lot more power than advertized due to all of its insanely bright LEDs. At least from within Linux it seems to work fine, both the embedded board and my desktop.
http://terminus-tech.com/images/FE2.1%20Product%20Brief%20(Rev.%201.0).pdf
http://www.amazon.com/Hi-Speed-Port-USB-Power-
Adapter/dp/B000Y8EXSS/ref=sr_1_16?s=electronics&ie=UTF8&qid=1296691437&sr=1-16
# lsusb -v -s 1:12
Bus 001 Device 012: ID 1a40:0201 TERMINUS TECHNOLOGY INC. Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 9 Hub bDeviceSubClass 0 Unused bDeviceProtocol 2 TT per port bMaxPacketSize0 64 idVendor 0x1a40 TERMINUS TECHNOLOGY INC. idProduct 0x0201 bcdDevice 1.00 iManufacturer 0 iProduct 1 USB 2.0 Hub [MTT] iSerial 0 bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 1 Single TT
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 2 TT per port
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 7
wHubCharacteristic 0x0088
Ganged power switching
Per-port overcurrent protection
TT think time 8 FS bits
Port indicators
bPwrOn2PwrGood 50 * 2 milli seconds
bHubContrCurrent 100 milli Ampere
DeviceRemovable 0x00
PortPwrCtrlMask 0xff
Hub Port Status:
Port 1: 0000.0100 power
Port 2: 0000.0100 power
Port 3: 0000.0100 power
Port 4: 0000.0100 power
Port 5: 0000.0100 power
Port 6: 0000.0100 power
Port 7: 0000.0100 power
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 9 Hub bDeviceSubClass 0 Unused bDeviceProtocol 0 Full speed (or root) hub
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0001
Self Powered
Quoted 50 lines · Simon Glass
Hi Aaron,
OK good. Yes I notice ext2 is slow also, but the dcache is still off so I assumed that was it.
I have had no hub problems, but have only tried two types. I do recall a LUN patch floating around. I was going to try with an uSD card to see if it is needed there.
Regards,
SimonOn Tue, Feb 1, 2011 at 4:03 PM, Aaron Williams <
Quoted 35 lines · Aaron.Williams at caviumnetworks.com> wrote:
I too am interested in this. I am running EHCI and have had problems with a number of USB storage devices, one of which (the SanDisk Cruzer) causes a crash due to it reporting the maximum LUN as 1. I'm also seeing some interesting performance issues with ext2 being extremely slow compared to FAT.
Additionally, I have been trying various USB hubs with EHCI and have found that a large percentage fail to work. Hopefully I'll look into it more soon
when I get ahold of our USB analyzer again.-Aaron
Quoted 6 lines · Remy Bohmer
Hi,
2011/2/1 Simon Glass <[email protected]>:
Quoted 3 lines
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms). Once Iget
Quoted 12 lines
Quoted 5 lines
to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet.
Regards,
SimonFWIW: I tested it on Atmel at91 and it does not seem to break OHCI, it does not seem to fix some troubles USB sticks I have here either...
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
In reply to Remy BohmerHi Remy,
I have now tested on OHCI with AT91SAM9G45 and found that the code already includes a longer timeout and does not have the submission bug. So for now I would like to replace that patch with a new one which I will send to the list today.
For now I will drop the reset and restart parts of the patch since I don't have evidence that they are required. I still believe the reset is too ad-hoc, so am happy to resubmit that part of it if you like.
Regarding your troubled sticks, can you please advise make / model numbers and USB ID? It would be good to at least look at these problems and see what can be done.
Regards,
Simon
Quoted 18 lines · Remy Bohmer
Hi,
2011/2/1 Simon Glass <[email protected]>:
Quoted 7 lines
Hi Remy,
Still waiting on some boards to try, unfortunately. I expect it will happen in the next 2 weeks though (ARM9 and OMAP4 platforms).?Once I get to the bottom of it I will split the patches as requested. I have not seen reports from other users of U-Boot. Also working on USB host Ethernet. Regards,
SimonFWIW: I tested it on Atmel at91 and it does not seem to break OHCI, it does not seem to fix some troubles USB sticks I have here either...
Kind regards,
Remy
PATCH 1/1 Fix to make U-Boot work with more USB sticks
Hi,
2011/2/7 Simon Glass <[email protected]>:
Quoted 6 lines
Hi Remy,
I have now tested on OHCI with AT91SAM9G45 and found that the code already includes a longer timeout and does not have the submission bug. So for now I would like to replace that patch with a new one which I will send to the list today.
OK
Quoted 7 lines
For now I will drop the reset and restart parts of the patch since I don't have evidence that they are required. I still believe the reset is too ad-hoc, so am happy to resubmit that part of it if you like.
Regarding your troubled sticks, can you please advise make / model numbers and USB ID? It would be good to at least look at these problems and see what can be done.
I have for example these sticks that show problems on a OHCI host:
13fe:1a20 Kingston Technology Company Inc.
0204:6025 Chipsbank Microelectronics Co., Ltd CBM2080 Flash drive controller 2008:2018
Note that these sticks give only problems on a at91sam9261 processor if it runs on 200MHz (10MHz X-tal) and not if it runs on 198.656 MHz (18.432 MHz X-tal) One stick also stop showing the problem if it has been powered on for about 10 minutes...(Then it feels a little warmer).
I have more sticks of the same brand/type/manufacturing-date that do not show a problem at all...
Furthermore, the exact same software is being used in both cases, and same stick with same contents.
U-boot since 2010.06 seems to be more sensitive to make these sticks fail, so there seems to be some regression here.
Failure is usually being visualised as a stall of an endpoint. Sometimes failure of the stick is that hard, that a power cycle of the stick is required.
I have not had the time to hook up the USB analyser to see what exactly is going wrong, but my guts tell me that there are some tricky timing issues involved.
Kind regards,
Remy