aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/hub.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r--drivers/usb/core/hub.c311
1 files changed, 183 insertions, 128 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a428aa080a36..d6cc83249341 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1636,11 +1636,6 @@ void usb_disconnect(struct usb_device **pdev)
1636 int i; 1636 int i;
1637 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1637 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1638 1638
1639 if (!udev) {
1640 pr_debug ("%s nodev\n", __func__);
1641 return;
1642 }
1643
1644 /* mark the device as inactive, so any further urb submissions for 1639 /* mark the device as inactive, so any further urb submissions for
1645 * this device (and any of its children) will fail immediately. 1640 * this device (and any of its children) will fail immediately.
1646 * this quiesces everything except pending urbs. 1641 * this quiesces everything except pending urbs.
@@ -2030,11 +2025,23 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
2030 2025
2031#define HUB_ROOT_RESET_TIME 50 /* times are in msec */ 2026#define HUB_ROOT_RESET_TIME 50 /* times are in msec */
2032#define HUB_SHORT_RESET_TIME 10 2027#define HUB_SHORT_RESET_TIME 10
2028#define HUB_BH_RESET_TIME 50
2033#define HUB_LONG_RESET_TIME 200 2029#define HUB_LONG_RESET_TIME 200
2034#define HUB_RESET_TIMEOUT 500 2030#define HUB_RESET_TIMEOUT 500
2035 2031
2032static int hub_port_reset(struct usb_hub *hub, int port1,
2033 struct usb_device *udev, unsigned int delay, bool warm);
2034
2035/* Is a USB 3.0 port in the Inactive state? */
2036static bool hub_port_inactive(struct usb_hub *hub, u16 portstatus)
2037{
2038 return hub_is_superspeed(hub->hdev) &&
2039 (portstatus & USB_PORT_STAT_LINK_STATE) ==
2040 USB_SS_PORT_LS_SS_INACTIVE;
2041}
2042
2036static int hub_port_wait_reset(struct usb_hub *hub, int port1, 2043static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2037 struct usb_device *udev, unsigned int delay) 2044 struct usb_device *udev, unsigned int delay, bool warm)
2038{ 2045{
2039 int delay_time, ret; 2046 int delay_time, ret;
2040 u16 portstatus; 2047 u16 portstatus;
@@ -2051,28 +2058,71 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2051 if (ret < 0) 2058 if (ret < 0)
2052 return ret; 2059 return ret;
2053 2060
2054 /* Device went away? */ 2061 /*
2055 if (!(portstatus & USB_PORT_STAT_CONNECTION)) 2062 * Some buggy devices require a warm reset to be issued even
2056 return -ENOTCONN; 2063 * when the port appears not to be connected.
2057 2064 */
2058 /* bomb out completely if the connection bounced */ 2065 if (!warm) {
2059 if ((portchange & USB_PORT_STAT_C_CONNECTION)) 2066 /*
2060 return -ENOTCONN; 2067 * Some buggy devices can cause an NEC host controller
2061 2068 * to transition to the "Error" state after a hot port
2062 /* if we`ve finished resetting, then break out of the loop */ 2069 * reset. This will show up as the port state in
2063 if (!(portstatus & USB_PORT_STAT_RESET) && 2070 * "Inactive", and the port may also report a
2064 (portstatus & USB_PORT_STAT_ENABLE)) { 2071 * disconnect. Forcing a warm port reset seems to make
2065 if (hub_is_wusb(hub)) 2072 * the device work.
2066 udev->speed = USB_SPEED_WIRELESS; 2073 *
2067 else if (hub_is_superspeed(hub->hdev)) 2074 * See https://bugzilla.kernel.org/show_bug.cgi?id=41752
2068 udev->speed = USB_SPEED_SUPER; 2075 */
2069 else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 2076 if (hub_port_inactive(hub, portstatus)) {
2070 udev->speed = USB_SPEED_HIGH; 2077 int ret;
2071 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 2078
2072 udev->speed = USB_SPEED_LOW; 2079 if ((portchange & USB_PORT_STAT_C_CONNECTION))
2073 else 2080 clear_port_feature(hub->hdev, port1,
2074 udev->speed = USB_SPEED_FULL; 2081 USB_PORT_FEAT_C_CONNECTION);
2075 return 0; 2082 if (portchange & USB_PORT_STAT_C_LINK_STATE)
2083 clear_port_feature(hub->hdev, port1,
2084 USB_PORT_FEAT_C_PORT_LINK_STATE);
2085 if (portchange & USB_PORT_STAT_C_RESET)
2086 clear_port_feature(hub->hdev, port1,
2087 USB_PORT_FEAT_C_RESET);
2088 dev_dbg(hub->intfdev, "hot reset failed, warm reset port %d\n",
2089 port1);
2090 ret = hub_port_reset(hub, port1,
2091 udev, HUB_BH_RESET_TIME,
2092 true);
2093 if ((portchange & USB_PORT_STAT_C_CONNECTION))
2094 clear_port_feature(hub->hdev, port1,
2095 USB_PORT_FEAT_C_CONNECTION);
2096 return ret;
2097 }
2098 /* Device went away? */
2099 if (!(portstatus & USB_PORT_STAT_CONNECTION))
2100 return -ENOTCONN;
2101
2102 /* bomb out completely if the connection bounced */
2103 if ((portchange & USB_PORT_STAT_C_CONNECTION))
2104 return -ENOTCONN;
2105
2106 /* if we`ve finished resetting, then break out of
2107 * the loop
2108 */
2109 if (!(portstatus & USB_PORT_STAT_RESET) &&
2110 (portstatus & USB_PORT_STAT_ENABLE)) {
2111 if (hub_is_wusb(hub))
2112 udev->speed = USB_SPEED_WIRELESS;
2113 else if (hub_is_superspeed(hub->hdev))
2114 udev->speed = USB_SPEED_SUPER;
2115 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
2116 udev->speed = USB_SPEED_HIGH;
2117 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
2118 udev->speed = USB_SPEED_LOW;
2119 else
2120 udev->speed = USB_SPEED_FULL;
2121 return 0;
2122 }
2123 } else {
2124 if (portchange & USB_PORT_STAT_C_BH_RESET)
2125 return 0;
2076 } 2126 }
2077 2127
2078 /* switch to the long delay after two short delay failures */ 2128 /* switch to the long delay after two short delay failures */
@@ -2080,35 +2130,84 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
2080 delay = HUB_LONG_RESET_TIME; 2130 delay = HUB_LONG_RESET_TIME;
2081 2131
2082 dev_dbg (hub->intfdev, 2132 dev_dbg (hub->intfdev,
2083 "port %d not reset yet, waiting %dms\n", 2133 "port %d not %sreset yet, waiting %dms\n",
2084 port1, delay); 2134 port1, warm ? "warm " : "", delay);
2085 } 2135 }
2086 2136
2087 return -EBUSY; 2137 return -EBUSY;
2088} 2138}
2089 2139
2140static void hub_port_finish_reset(struct usb_hub *hub, int port1,
2141 struct usb_device *udev, int *status, bool warm)
2142{
2143 switch (*status) {
2144 case 0:
2145 if (!warm) {
2146 struct usb_hcd *hcd;
2147 /* TRSTRCY = 10 ms; plus some extra */
2148 msleep(10 + 40);
2149 update_devnum(udev, 0);
2150 hcd = bus_to_hcd(udev->bus);
2151 if (hcd->driver->reset_device) {
2152 *status = hcd->driver->reset_device(hcd, udev);
2153 if (*status < 0) {
2154 dev_err(&udev->dev, "Cannot reset "
2155 "HCD device state\n");
2156 break;
2157 }
2158 }
2159 }
2160 /* FALL THROUGH */
2161 case -ENOTCONN:
2162 case -ENODEV:
2163 clear_port_feature(hub->hdev,
2164 port1, USB_PORT_FEAT_C_RESET);
2165 /* FIXME need disconnect() for NOTATTACHED device */
2166 if (warm) {
2167 clear_port_feature(hub->hdev, port1,
2168 USB_PORT_FEAT_C_BH_PORT_RESET);
2169 clear_port_feature(hub->hdev, port1,
2170 USB_PORT_FEAT_C_PORT_LINK_STATE);
2171 } else {
2172 usb_set_device_state(udev, *status
2173 ? USB_STATE_NOTATTACHED
2174 : USB_STATE_DEFAULT);
2175 }
2176 break;
2177 }
2178}
2179
2180/* Handle port reset and port warm(BH) reset (for USB3 protocol ports) */
2090static int hub_port_reset(struct usb_hub *hub, int port1, 2181static int hub_port_reset(struct usb_hub *hub, int port1,
2091 struct usb_device *udev, unsigned int delay) 2182 struct usb_device *udev, unsigned int delay, bool warm)
2092{ 2183{
2093 int i, status; 2184 int i, status;
2094 struct usb_hcd *hcd;
2095 2185
2096 hcd = bus_to_hcd(udev->bus); 2186 if (!warm) {
2097 /* Block EHCI CF initialization during the port reset. 2187 /* Block EHCI CF initialization during the port reset.
2098 * Some companion controllers don't like it when they mix. 2188 * Some companion controllers don't like it when they mix.
2099 */ 2189 */
2100 down_read(&ehci_cf_port_reset_rwsem); 2190 down_read(&ehci_cf_port_reset_rwsem);
2191 } else {
2192 if (!hub_is_superspeed(hub->hdev)) {
2193 dev_err(hub->intfdev, "only USB3 hub support "
2194 "warm reset\n");
2195 return -EINVAL;
2196 }
2197 }
2101 2198
2102 /* Reset the port */ 2199 /* Reset the port */
2103 for (i = 0; i < PORT_RESET_TRIES; i++) { 2200 for (i = 0; i < PORT_RESET_TRIES; i++) {
2104 status = set_port_feature(hub->hdev, 2201 status = set_port_feature(hub->hdev, port1, (warm ?
2105 port1, USB_PORT_FEAT_RESET); 2202 USB_PORT_FEAT_BH_PORT_RESET :
2106 if (status) 2203 USB_PORT_FEAT_RESET));
2204 if (status) {
2107 dev_err(hub->intfdev, 2205 dev_err(hub->intfdev,
2108 "cannot reset port %d (err = %d)\n", 2206 "cannot %sreset port %d (err = %d)\n",
2109 port1, status); 2207 warm ? "warm " : "", port1, status);
2110 else { 2208 } else {
2111 status = hub_port_wait_reset(hub, port1, udev, delay); 2209 status = hub_port_wait_reset(hub, port1, udev, delay,
2210 warm);
2112 if (status && status != -ENOTCONN) 2211 if (status && status != -ENOTCONN)
2113 dev_dbg(hub->intfdev, 2212 dev_dbg(hub->intfdev,
2114 "port_wait_reset: err = %d\n", 2213 "port_wait_reset: err = %d\n",
@@ -2116,34 +2215,14 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2116 } 2215 }
2117 2216
2118 /* return on disconnect or reset */ 2217 /* return on disconnect or reset */
2119 switch (status) { 2218 if (status == 0 || status == -ENOTCONN || status == -ENODEV) {
2120 case 0: 2219 hub_port_finish_reset(hub, port1, udev, &status, warm);
2121 /* TRSTRCY = 10 ms; plus some extra */
2122 msleep(10 + 40);
2123 update_devnum(udev, 0);
2124 if (hcd->driver->reset_device) {
2125 status = hcd->driver->reset_device(hcd, udev);
2126 if (status < 0) {
2127 dev_err(&udev->dev, "Cannot reset "
2128 "HCD device state\n");
2129 break;
2130 }
2131 }
2132 /* FALL THROUGH */
2133 case -ENOTCONN:
2134 case -ENODEV:
2135 clear_port_feature(hub->hdev,
2136 port1, USB_PORT_FEAT_C_RESET);
2137 /* FIXME need disconnect() for NOTATTACHED device */
2138 usb_set_device_state(udev, status
2139 ? USB_STATE_NOTATTACHED
2140 : USB_STATE_DEFAULT);
2141 goto done; 2220 goto done;
2142 } 2221 }
2143 2222
2144 dev_dbg (hub->intfdev, 2223 dev_dbg (hub->intfdev,
2145 "port %d not enabled, trying reset again...\n", 2224 "port %d not enabled, trying %sreset again...\n",
2146 port1); 2225 port1, warm ? "warm " : "");
2147 delay = HUB_LONG_RESET_TIME; 2226 delay = HUB_LONG_RESET_TIME;
2148 } 2227 }
2149 2228
@@ -2151,45 +2230,11 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2151 "Cannot enable port %i. Maybe the USB cable is bad?\n", 2230 "Cannot enable port %i. Maybe the USB cable is bad?\n",
2152 port1); 2231 port1);
2153 2232
2154 done: 2233done:
2155 up_read(&ehci_cf_port_reset_rwsem); 2234 if (!warm)
2156 return status; 2235 up_read(&ehci_cf_port_reset_rwsem);
2157}
2158
2159/* Warm reset a USB3 protocol port */
2160static int hub_port_warm_reset(struct usb_hub *hub, int port)
2161{
2162 int ret;
2163 u16 portstatus, portchange;
2164
2165 if (!hub_is_superspeed(hub->hdev)) {
2166 dev_err(hub->intfdev, "only USB3 hub support warm reset\n");
2167 return -EINVAL;
2168 }
2169
2170 /* Warm reset the port */
2171 ret = set_port_feature(hub->hdev,
2172 port, USB_PORT_FEAT_BH_PORT_RESET);
2173 if (ret) {
2174 dev_err(hub->intfdev, "cannot warm reset port %d\n", port);
2175 return ret;
2176 }
2177
2178 msleep(20);
2179 ret = hub_port_status(hub, port, &portstatus, &portchange);
2180
2181 if (portchange & USB_PORT_STAT_C_RESET)
2182 clear_port_feature(hub->hdev, port, USB_PORT_FEAT_C_RESET);
2183
2184 if (portchange & USB_PORT_STAT_C_BH_RESET)
2185 clear_port_feature(hub->hdev, port,
2186 USB_PORT_FEAT_C_BH_PORT_RESET);
2187
2188 if (portchange & USB_PORT_STAT_C_LINK_STATE)
2189 clear_port_feature(hub->hdev, port,
2190 USB_PORT_FEAT_C_PORT_LINK_STATE);
2191 2236
2192 return ret; 2237 return status;
2193} 2238}
2194 2239
2195/* Check if a port is power on */ 2240/* Check if a port is power on */
@@ -2347,6 +2392,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2347 } 2392 }
2348 } 2393 }
2349 2394
2395 /* disable USB2 hardware LPM */
2396 if (udev->usb2_hw_lpm_enabled == 1)
2397 usb_set_usb2_hardware_lpm(udev, 0);
2398
2350 /* see 7.1.7.6 */ 2399 /* see 7.1.7.6 */
2351 if (hub_is_superspeed(hub->hdev)) 2400 if (hub_is_superspeed(hub->hdev))
2352 status = set_port_feature(hub->hdev, 2401 status = set_port_feature(hub->hdev,
@@ -2558,7 +2607,12 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2558 if (status < 0) { 2607 if (status < 0) {
2559 dev_dbg(&udev->dev, "can't resume, status %d\n", status); 2608 dev_dbg(&udev->dev, "can't resume, status %d\n", status);
2560 hub_port_logical_disconnect(hub, port1); 2609 hub_port_logical_disconnect(hub, port1);
2610 } else {
2611 /* Try to enable USB2 hardware LPM */
2612 if (udev->usb2_hw_lpm_capable == 1)
2613 usb_set_usb2_hardware_lpm(udev, 1);
2561 } 2614 }
2615
2562 return status; 2616 return status;
2563} 2617}
2564 2618
@@ -2798,7 +2852,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2798 int i, j, retval; 2852 int i, j, retval;
2799 unsigned delay = HUB_SHORT_RESET_TIME; 2853 unsigned delay = HUB_SHORT_RESET_TIME;
2800 enum usb_device_speed oldspeed = udev->speed; 2854 enum usb_device_speed oldspeed = udev->speed;
2801 char *speed, *type; 2855 const char *speed;
2802 int devnum = udev->devnum; 2856 int devnum = udev->devnum;
2803 2857
2804 /* root hub ports have a slightly longer reset period 2858 /* root hub ports have a slightly longer reset period
@@ -2819,7 +2873,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2819 2873
2820 /* Reset the device; full speed may morph to high speed */ 2874 /* Reset the device; full speed may morph to high speed */
2821 /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */ 2875 /* FIXME a USB 2.0 device may morph into SuperSpeed on reset. */
2822 retval = hub_port_reset(hub, port1, udev, delay); 2876 retval = hub_port_reset(hub, port1, udev, delay, false);
2823 if (retval < 0) /* error or disconnect */ 2877 if (retval < 0) /* error or disconnect */
2824 goto fail; 2878 goto fail;
2825 /* success, speed is known */ 2879 /* success, speed is known */
@@ -2858,25 +2912,16 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2858 default: 2912 default:
2859 goto fail; 2913 goto fail;
2860 } 2914 }
2861 2915
2862 type = ""; 2916 if (udev->speed == USB_SPEED_WIRELESS)
2863 switch (udev->speed) { 2917 speed = "variable speed Wireless";
2864 case USB_SPEED_LOW: speed = "low"; break; 2918 else
2865 case USB_SPEED_FULL: speed = "full"; break; 2919 speed = usb_speed_string(udev->speed);
2866 case USB_SPEED_HIGH: speed = "high"; break; 2920
2867 case USB_SPEED_SUPER:
2868 speed = "super";
2869 break;
2870 case USB_SPEED_WIRELESS:
2871 speed = "variable";
2872 type = "Wireless ";
2873 break;
2874 default: speed = "?"; break;
2875 }
2876 if (udev->speed != USB_SPEED_SUPER) 2921 if (udev->speed != USB_SPEED_SUPER)
2877 dev_info(&udev->dev, 2922 dev_info(&udev->dev,
2878 "%s %s speed %sUSB device number %d using %s\n", 2923 "%s %s USB device number %d using %s\n",
2879 (udev->config) ? "reset" : "new", speed, type, 2924 (udev->config) ? "reset" : "new", speed,
2880 devnum, udev->bus->controller->driver->name); 2925 devnum, udev->bus->controller->driver->name);
2881 2926
2882 /* Set up TT records, if needed */ 2927 /* Set up TT records, if needed */
@@ -2949,7 +2994,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2949 buf->bMaxPacketSize0; 2994 buf->bMaxPacketSize0;
2950 kfree(buf); 2995 kfree(buf);
2951 2996
2952 retval = hub_port_reset(hub, port1, udev, delay); 2997 retval = hub_port_reset(hub, port1, udev, delay, false);
2953 if (retval < 0) /* error or disconnect */ 2998 if (retval < 0) /* error or disconnect */
2954 goto fail; 2999 goto fail;
2955 if (oldspeed != udev->speed) { 3000 if (oldspeed != udev->speed) {
@@ -3023,7 +3068,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
3023 i = 512; 3068 i = 512;
3024 else 3069 else
3025 i = udev->descriptor.bMaxPacketSize0; 3070 i = udev->descriptor.bMaxPacketSize0;
3026 if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { 3071 if (usb_endpoint_maxp(&udev->ep0.desc) != i) {
3027 if (udev->speed == USB_SPEED_LOW || 3072 if (udev->speed == USB_SPEED_LOW ||
3028 !(i == 8 || i == 16 || i == 32 || i == 64)) { 3073 !(i == 8 || i == 16 || i == 32 || i == 64)) {
3029 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i); 3074 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i);
@@ -3047,6 +3092,15 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
3047 goto fail; 3092 goto fail;
3048 } 3093 }
3049 3094
3095 if (udev->wusb == 0 && le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0201) {
3096 retval = usb_get_bos_descriptor(udev);
3097 if (!retval) {
3098 if (udev->bos->ext_cap && (USB_LPM_SUPPORT &
3099 le32_to_cpu(udev->bos->ext_cap->bmAttributes)))
3100 udev->lpm_capable = 1;
3101 }
3102 }
3103
3050 retval = 0; 3104 retval = 0;
3051 /* notify HCD that we have a device connected and addressed */ 3105 /* notify HCD that we have a device connected and addressed */
3052 if (hcd->driver->update_device) 3106 if (hcd->driver->update_device)
@@ -3570,7 +3624,8 @@ static void hub_events(void)
3570 (portstatus & USB_PORT_STAT_LINK_STATE) 3624 (portstatus & USB_PORT_STAT_LINK_STATE)
3571 == USB_SS_PORT_LS_SS_INACTIVE) { 3625 == USB_SS_PORT_LS_SS_INACTIVE) {
3572 dev_dbg(hub_dev, "warm reset port %d\n", i); 3626 dev_dbg(hub_dev, "warm reset port %d\n", i);
3573 hub_port_warm_reset(hub, i); 3627 hub_port_reset(hub, i, NULL,
3628 HUB_BH_RESET_TIME, true);
3574 } 3629 }
3575 3630
3576 if (connect_change) 3631 if (connect_change)