From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751074AbdKEUdn convert rfc822-to-8bit (ORCPT ); Sun, 5 Nov 2017 15:33:43 -0500 Received: from mx18-out11.antispamcloud.com ([207.244.64.180]:38194 "EHLO mx18-out11.antispamcloud.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750724AbdKEUdl (ORCPT ); Sun, 5 Nov 2017 15:33:41 -0500 X-Greylist: delayed 5575 seconds by postgrey-1.27 at vger.kernel.org; Sun, 05 Nov 2017 15:33:40 EST Subject: Re: [PATCH][RFC] usb: hub: Cycle HUB power when initialization fails To: Alan Stern CC: , , , References: From: Mike Looijmans Organization: Topic Message-ID: Date: Sun, 5 Nov 2017 19:41:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8BIT X-Originating-IP: [85.150.144.104] X-EXCLAIMER-MD-CONFIG: 9833cda7-5b21-4d34-9a38-8d025ddc3664 X-EXCLAIMER-MD-BIFURCATION-INSTANCE: 0 X-Originating-IP: 37.74.225.130 X-SpamExperts-Domain: topic.nl X-SpamExperts-Username: 37.74.225.128/28 Authentication-Results: antispamcloud.com; auth=pass smtp.auth=37.74.225.128/28@topic.nl X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00378003009383) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ry/b4Tk6AFO3EExwkF5FPDj1g3/PwYZaTCzSym8uE9Hh15/smD9m40g xPWPaAAVbKT5USbtC9lEZO5oQplHHXYPGItd6/qQ+JobPExdzv/BmFhtq7FwnOWqyWC5OA2FMInT JYQp6P0LGGk5YcssJBnrsrCWpww+oFc6iWi1hsMdl6HqiPr6+VUjsc5FaSt6bU2TKo2fbQFpqpjX NjYEe5Ppki7bb2RWmsr4eoyYil7mCNkMkPiMYC+wMzHEMLPorZaJFqxk8AMyKj0q9fxGHiyl10lI 8mQYzInvb1o7SZ8ekzOftIKdWl5oa21WXHYTqyERbInMiTBIUBbQ/Dy6Ip5zgEuj6Q6gp2ms55LW KeaAtpJs0x8NnXXpGpHHcQLvTZKJMBfkTM4kJjo+L1ngT+t/RydXBvDHIzJmcIMmYKJ5EtnxREWu K+B3CM5CtFT7UXXdE9umsSj7w6MkmuXWo29pUkNWYp4Omv1q/J57AtZI2P9fTjbIZ/WGBD5nnHiS tdYOAgjxF5x1A+MR2WWBD8UifL76GD10kuo3nOZaoX+gyrcF1xgNjczbfkFXAZgbKMjx7v77N42Z /zX3DQBtZa/r7okvCK9Q3j6IPcfRucweER9E+btGG8Xk1uugE/FU4J9TrjYo22Tif+7yfJXbGyP7 4O4hBSz/kkmPgL+fgIgua+2OC9Cy2sn/uMkA71csyOLyAJMtTc1YTlrqdRqNqvM3RuESFJcYW1qN 8myONmDZEUzItZTZq0ndPqhhYebjsV+5w1uNPEg5H3VvFyTa+8tZJ6nQJhK7FPvylaKrneV0ERWe KKG4PAQYNyavp7c49MBQlcJSq6eEL6RjPa2+R3LW+29E9fzdTmCjz10y8H8+uK5Xu2kK6BamDFbW oySgomoLtCeyovbKqAK+h76w3827ITqwtxCfTG40lAgk8Hydi1bk7uhB4IvqowXQ3yvXPRpW6anL 7tC8sZz8vH3+AmWi+sbz2kQkFBUePH60ZjQUMC0RrojGu/TPp47Nf3SHfZnckpWaLvahyBjmQxBK Ozu4VQ9aiX/F2wgrcsHmO+ktlkwyDAsEI+oNRVVeJ6MJhjEvuGslKTrRIXcXpFg5ivY= X-Report-Abuse-To: spam@quarantine2.antispamcloud.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03-11-17 18:27, Alan Stern wrote: > On Fri, 3 Nov 2017, Mike Looijmans wrote: > >> Sometimes the USB device gets confused about the state of the initialization and >> the connection fails. In particular, the device thinks that it's already set up >> and running while the host thinks the device still needs to be configured. To > > How do you know that this is really the issue? How can the device > think it's already set if it doesn't have an assigned address? It seems to me that the device just doesn't react at all on the host requests to assign an address. I've seen this happen with various custom mass-storage like appliances, but also DVB tuners and such. The device won't return to a working state until you unplug it and put it back, or, and that's what the patch does, just power-cycle the USB port, which has the same effect. >> work around this issue, power-cycle the hub's output to issue a sort of "reset" >> to the device. This makes the device restart its state machine and then the >> initialization succeeds. >> >> This fixes problems where the kernel reports a list of errors like this: >> >> usb 1-1.3: device not accepting address 19, error -71 >> >> The end result is a non-functioning device. After this patch, the sequence >> becomes like this: >> >> usb 1-1.3: new high-speed USB device number 18 using ci_hdrc >> usb 1-1.3: device not accepting address 18, error -71 >> usb 1-1.3: new high-speed USB device number 19 using ci_hdrc >> usb 1-1.3: device not accepting address 19, error -71 >> usb 1-1-port3: attempt power cycle >> usb 1-1.3: new high-speed USB device number 21 using ci_hdrc >> usb-storage 1-1.3:1.2: USB Mass Storage device detected >> >> Signed-off-by: Mike Looijmans >> --- >> This is a fix I did for a customer which might be appropriate for upstream. What do you think? >> >> drivers/usb/core/hub.c | 13 ++++++++++--- >> 1 file changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c >> index e9ce6bb..a30c1e7 100644 >> --- a/drivers/usb/core/hub.c >> +++ b/drivers/usb/core/hub.c >> @@ -2611,7 +2611,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub) >> #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 SET_CONFIG_TRIES (4 * (use_both_schemes + 1)) > > We already have too many retry loops. I am not keen on the idea of > adding even more. How about leaving this value the same and adding the > power cycle? I'm fine with that as well. > The ideal, however, would be to find out what is wrong with the device > and see what needs to be done to fix it properly. This change won't > work on many computers (desktops and laptops) because they don't have > real USB port-power switching. A lot of hubs don't have it either. I'm pretty sure it's the device's fault, but they're out there and probably not upgradable anyway if you could get the manufacturer to pick up the phone. On desktop/laptop machines the problem isn't as pressing since there's a often a user there who can unplug the thing. It's really nasty on embedded systems, and they tend to have the USB power wired through a supply limiter/switch. I'm thinking worst that could happen on desktops is that the patch won't have any effect at all. So what do you think, is this worth a v2 patch for general consumption or should I keep this a "private" patch for systems that have demonstrated to benefit from it? >> #define USE_NEW_SCHEME(i) ((i) / 2 == (int)old_scheme_first) >> >> #define HUB_ROOT_RESET_TIME 60 /* times are in msec */ >> @@ -4805,7 +4805,6 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, >> >> status = 0; >> for (i = 0; i < SET_CONFIG_TRIES; i++) { >> - > > Gratuitous whitespace change. > >> /* reallocate for each attempt, since references >> * to the previous one can escape in various ways >> */ >> @@ -4935,6 +4934,15 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus, >> usb_put_dev(udev); >> if ((status == -ENOTCONN) || (status == -ENOTSUPP)) >> break; >> + >> + /* When halfway through our retry count, power-cycle the port */ >> + if (i == (SET_CONFIG_TRIES / 2) - 1) { >> + dev_info(&port_dev->dev, "attempt power cycle\n"); >> + usb_hub_set_port_power(hdev, hub, port1, false); >> + msleep(800); >> + usb_hub_set_port_power(hdev, hub, port1, true); >> + msleep(hub_power_on_good_delay(hub)); >> + } >> } >> if (hub->hdev->parent || >> !hcd->driver->port_handed_over || >> @@ -5476,7 +5484,6 @@ static int usb_reset_and_verify_device(struct usb_device *udev) >> udev->bos = NULL; >> >> for (i = 0; i < SET_CONFIG_TRIES; ++i) { >> - > > Another gratuitous change. > >> /* ep0 maxpacket size may change; let the HCD know about it. >> * Other endpoints will be handled by re-enumeration. */ >> usb_ep0_reinit(udev); > > Alan Stern > -- Mike Looijmans Kind regards, Mike Looijmans System Expert TOPIC Products Materiaalweg 4, NL-5681 RJ Best Postbus 440, NL-5680 AK Best Telefoon: +31 (0) 499 33 69 79 E-mail: mike.looijmans@topicproducts.com Website: www.topicproducts.com Please consider the environment before printing this e-mail