diff mbox

[U-Boot,5/7] usb: hub: Increase device enumeration timeout for broken drives

Message ID 1364376543-7526-6-git-send-email-gautam.vivek@samsung.com
State Awaiting Upstream
Delegated to: Marek Vasut
Headers show

Commit Message

Vivek Gautam March 27, 2013, 9:29 a.m. UTC
Few broken usb mass storage devices can take some time to set
Current Connect Status (CCS) and Connect Status Change (CSC) in
Port status register after an attach.
So increasing some timeout when both CCS and CSC bits are not set.

Signed-off-by: Amar <amarendra.xt@samsung.com>
Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
---
 common/usb_hub.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

Comments

Marek Vasut March 28, 2013, 2:32 p.m. UTC | #1
Dear Vivek Gautam,

> Few broken usb mass storage devices can take some time to set
> Current Connect Status (CCS) and Connect Status Change (CSC) in
> Port status register after an attach.
> So increasing some timeout when both CCS and CSC bits are not set.
> 
> Signed-off-by: Amar <amarendra.xt@samsung.com>
> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>

Can we not postpone checking of these CCS and CSC bits for such broken devices? 
This'd at least allow the "good" devices to be detected quickly and while these 
are handled, this would give some time for the "bad" ones to do their job too.

Best regards,
Marek Vasut
Vivek Gautam April 2, 2013, 9:33 a.m. UTC | #2
CC: Amarendra


On Thu, Mar 28, 2013 at 8:02 PM, Marek Vasut <marex@denx.de> wrote:
> Dear Vivek Gautam,
>
>> Few broken usb mass storage devices can take some time to set
>> Current Connect Status (CCS) and Connect Status Change (CSC) in
>> Port status register after an attach.
>> So increasing some timeout when both CCS and CSC bits are not set.
>>
>> Signed-off-by: Amar <amarendra.xt@samsung.com>
>> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
>
> Can we not postpone checking of these CCS and CSC bits for such broken devices?
> This'd at least allow the "good" devices to be detected quickly and while these
> are handled, this would give some time for the "bad" ones to do their job too.
>
> Best regards,
> Marek Vasut
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
Vivek Gautam April 2, 2013, 1:53 p.m. UTC | #3
Hi Marek,


On Thu, Mar 28, 2013 at 8:02 PM, Marek Vasut <marex@denx.de> wrote:
> Dear Vivek Gautam,
>
>> Few broken usb mass storage devices can take some time to set
>> Current Connect Status (CCS) and Connect Status Change (CSC) in
>> Port status register after an attach.
>> So increasing some timeout when both CCS and CSC bits are not set.
>>
>> Signed-off-by: Amar <amarendra.xt@samsung.com>
>> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
>
> Can we not postpone checking of these CCS and CSC bits for such broken devices?
> This'd at least allow the "good" devices to be detected quickly and while these
> are handled, this would give some time for the "bad" ones to do their job too.

We are thinking of one approach here.
Iterating over all the ports once, so that we find 'good' ports and 'bad' ports
By 'bad' port we mean that either the device connected to it is bad or
nothing is connected
to this port.
Once we are done with "usb_hub_port_connect_change()" and other jobs
for 'good' ports,
we iterate once again on bad ports.
Not sure how good this approach :-(.  Any suggestions ?
Marek Vasut April 4, 2013, 3:58 a.m. UTC | #4
Dear Vivek Gautam,

> Hi Marek,
> 
> On Thu, Mar 28, 2013 at 8:02 PM, Marek Vasut <marex@denx.de> wrote:
> > Dear Vivek Gautam,
> > 
> >> Few broken usb mass storage devices can take some time to set
> >> Current Connect Status (CCS) and Connect Status Change (CSC) in
> >> Port status register after an attach.
> >> So increasing some timeout when both CCS and CSC bits are not set.
> >> 
> >> Signed-off-by: Amar <amarendra.xt@samsung.com>
> >> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
> > 
> > Can we not postpone checking of these CCS and CSC bits for such broken
> > devices? This'd at least allow the "good" devices to be detected quickly
> > and while these are handled, this would give some time for the "bad"
> > ones to do their job too.
> 
> We are thinking of one approach here.
> Iterating over all the ports once, so that we find 'good' ports and 'bad'
> ports By 'bad' port we mean that either the device connected to it is bad
> or nothing is connected
> to this port.
> Once we are done with "usb_hub_port_connect_change()" and other jobs
> for 'good' ports,
> we iterate once again on bad ports.
> Not sure how good this approach :-(.  Any suggestions ?

That might just work, but I wonder if it's worth it. It's a pity we can't make a 
list of those as they're not even probed yet :(

Best regards,
Marek Vasut
Vivek Gautam April 4, 2013, 10:57 a.m. UTC | #5
Hi Marek,


On Thu, Apr 4, 2013 at 9:28 AM, Marek Vasut <marex@denx.de> wrote:
> Dear Vivek Gautam,
>
>> Hi Marek,
>>
>> On Thu, Mar 28, 2013 at 8:02 PM, Marek Vasut <marex@denx.de> wrote:
>> > Dear Vivek Gautam,
>> >
>> >> Few broken usb mass storage devices can take some time to set
>> >> Current Connect Status (CCS) and Connect Status Change (CSC) in
>> >> Port status register after an attach.
>> >> So increasing some timeout when both CCS and CSC bits are not set.
>> >>
>> >> Signed-off-by: Amar <amarendra.xt@samsung.com>
>> >> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
>> >
>> > Can we not postpone checking of these CCS and CSC bits for such broken
>> > devices? This'd at least allow the "good" devices to be detected quickly
>> > and while these are handled, this would give some time for the "bad"
>> > ones to do their job too.
>>
>> We are thinking of one approach here.
>> Iterating over all the ports once, so that we find 'good' ports and 'bad'
>> ports By 'bad' port we mean that either the device connected to it is bad
>> or nothing is connected
>> to this port.
>> Once we are done with "usb_hub_port_connect_change()" and other jobs
>> for 'good' ports,
>> we iterate once again on bad ports.
>> Not sure how good this approach :-(.  Any suggestions ?
>
> That might just work, but I wonder if it's worth it. It's a pity we can't make a
> list of those as they're not even probed yet :(

True, but at this point of time atleast the CSC and CCS bits tell us
about whether something is connected or not. Right ?
So lets make the ports on which nothing is connected 'bad' and probe
them later so that if something is connected to these,
job can be done.

If you are fine i may drop this patch from this series for now and
come back with a solution.
By the time i can update the patch-series.
Marek Vasut April 14, 2013, 5:17 p.m. UTC | #6
Dear Vivek Gautam,

> Hi Marek,
> 
> On Thu, Apr 4, 2013 at 9:28 AM, Marek Vasut <marex@denx.de> wrote:
> > Dear Vivek Gautam,
> > 
> >> Hi Marek,
> >> 
> >> On Thu, Mar 28, 2013 at 8:02 PM, Marek Vasut <marex@denx.de> wrote:
> >> > Dear Vivek Gautam,
> >> > 
> >> >> Few broken usb mass storage devices can take some time to set
> >> >> Current Connect Status (CCS) and Connect Status Change (CSC) in
> >> >> Port status register after an attach.
> >> >> So increasing some timeout when both CCS and CSC bits are not set.
> >> >> 
> >> >> Signed-off-by: Amar <amarendra.xt@samsung.com>
> >> >> Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
> >> > 
> >> > Can we not postpone checking of these CCS and CSC bits for such broken
> >> > devices? This'd at least allow the "good" devices to be detected
> >> > quickly and while these are handled, this would give some time for
> >> > the "bad" ones to do their job too.
> >> 
> >> We are thinking of one approach here.
> >> Iterating over all the ports once, so that we find 'good' ports and
> >> 'bad' ports By 'bad' port we mean that either the device connected to
> >> it is bad or nothing is connected
> >> to this port.
> >> Once we are done with "usb_hub_port_connect_change()" and other jobs
> >> for 'good' ports,
> >> we iterate once again on bad ports.
> >> Not sure how good this approach :-(.  Any suggestions ?
> > 
> > That might just work, but I wonder if it's worth it. It's a pity we can't
> > make a list of those as they're not even probed yet :(
> 
> True, but at this point of time atleast the CSC and CCS bits tell us
> about whether something is connected or not. Right ?
> So lets make the ports on which nothing is connected 'bad' and probe
> them later so that if something is connected to these,
> job can be done.
> 
> If you are fine i may drop this patch from this series for now and
> come back with a solution.
> By the time i can update the patch-series.

Sorry for the late reply again. I think the best way around here would be to 
make the delay configurable, possibly as an argument to "usb reset" with some 
reasonable default value, what do you think?

Best regards,
Marek Vasut
diff mbox

Patch

diff --git a/common/usb_hub.c b/common/usb_hub.c
index d77f98d..8ba7a0d 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -416,6 +416,7 @@  static int usb_hub_configure(struct usb_device *dev)
 		unsigned short portstatus, portchange;
 		int ret;
 		ulong start = get_timer(0);
+		ulong ts = 0;
 
 		/*
 		 * Wait for (whichever finishes first)
@@ -436,9 +437,23 @@  static int usb_hub_configure(struct usb_device *dev)
 			portchange = le16_to_cpu(portsts->wPortChange);
 
 			if ((portchange & USB_PORT_STAT_C_CONNECTION) ==
-				(portstatus & USB_PORT_STAT_CONNECTION))
-				break;
-
+			    (portstatus & USB_PORT_STAT_CONNECTION)) {
+				/*
+				 * Few brokern pen drives can take some
+				 * time to even report CSC or CCS state after
+				 * an attach. So giving this time lag so that
+				 * the CCS or CSC state can be changed and
+				 * reflected in Port status register.
+				 * XXX: This approach however has a drawback,
+				 * with this we are going to wait for 1 sec
+				 * even for ports on which nothing is connected.
+				 */
+				if (ts == 0)
+					ts = get_timer(0);
+				if ((portchange & USB_PORT_STAT_C_CONNECTION) ||
+				    (get_timer(ts) > CONFIG_SYS_HZ * 1))
+					break;
+			}
 		} while (get_timer(start) < CONFIG_SYS_HZ * 10);
 
 		if (ret < 0)