Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: hub: Add Kconfig option to reduce number of port initialization retries

Description based on one by Yasushi Asano:

According to 6.7.22 A-UUT “Device No Response” for connection timeout
of USB OTG and EH automated compliance plan v1.2, enumeration failure
has to be detected within 30 seconds. However, the old and new
enumeration schemes each make a total of 12 attempts, and each attempt
can take 5 seconds to time out, so the PET test fails.

This patch adds a new Kconfig option (CONFIG_USB_FEW_INIT_RETRIES);
when the option is set all the initialization retry loops except the
outermost are reduced to a single iteration. This reduces the total
number of attempts to four, allowing Linux hosts to pass the PET test.

The new option is disabled by default to preserve the existing
behavior. The reduced number of retries may fail to initialize a few
devices that currently do work, but for the most part there should be
no change. And in cases where the initialization does fail, it will
fail much more quickly.

Reported-and-tested-by: yasushi asano <yazzep@gmail.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20200928152217.GB134701@rowland.harvard.edu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
fb6f076d 19502e69

+26 -1
+14
drivers/usb/core/Kconfig
··· 32 32 If you have any questions about this, say Y here, only say N 33 33 if you know exactly what you are doing. 34 34 35 + config USB_FEW_INIT_RETRIES 36 + bool "Limit USB device initialization to only a few retries" 37 + help 38 + When a new USB device is detected, the kernel tries very hard 39 + to initialize and enumerate it, with lots of nested retry loops. 40 + This almost always works, but when it fails it can take a long time. 41 + This option tells the kernel to make only a few retry attempts, 42 + so that the total time required for a failed initialization is 43 + no more than 30 seconds (as required by the USB OTG spec). 44 + 45 + Say N here unless you require new-device enumeration failure to 46 + occur within 30 seconds (as might be needed in an embedded 47 + application). 48 + 35 49 config USB_DYNAMIC_MINORS 36 50 bool "Dynamic USB minor allocation" 37 51 help
+12 -1
drivers/usb/core/hub.c
··· 2705 2705 } 2706 2706 2707 2707 2708 + #ifdef CONFIG_USB_FEW_INIT_RETRIES 2709 + #define PORT_RESET_TRIES 2 2710 + #define SET_ADDRESS_TRIES 1 2711 + #define GET_DESCRIPTOR_TRIES 1 2712 + #define GET_MAXPACKET0_TRIES 1 2713 + #define PORT_INIT_TRIES 4 2714 + 2715 + #else 2708 2716 #define PORT_RESET_TRIES 5 2709 2717 #define SET_ADDRESS_TRIES 2 2710 2718 #define GET_DESCRIPTOR_TRIES 2 2719 + #define GET_MAXPACKET0_TRIES 3 2711 2720 #define PORT_INIT_TRIES 4 2721 + #endif /* CONFIG_USB_FEW_INIT_RETRIES */ 2712 2722 2713 2723 #define HUB_ROOT_RESET_TIME 60 /* times are in msec */ 2714 2724 #define HUB_SHORT_RESET_TIME 10 ··· 4701 4691 * 255 is for WUSB devices, we actually need to use 4702 4692 * 512 (WUSB1.0[4.8.1]). 4703 4693 */ 4704 - for (operations = 0; operations < 3; ++operations) { 4694 + for (operations = 0; operations < GET_MAXPACKET0_TRIES; 4695 + ++operations) { 4705 4696 buf->bMaxPacketSize0 = 0; 4706 4697 r = usb_control_msg(udev, usb_rcvaddr0pipe(), 4707 4698 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,