Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1251189

[PATCH 3.4 16/65] usb: core: Fix USB 3.0 devices lost in NOTATTACHED state after a hub port reset

From lizf@kernel.org
Newsgroups linux.kernel
Subject [PATCH 3.4 16/65] usb: core: Fix USB 3.0 devices lost in NOTATTACHED state after a hub port reset
Date 2015-10-20 02:50 +0200
Message-ID <qlthM-4kA-31@gated-at.bofh.it> (permalink)
References <qlthL-4kA-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Robert Schlabbach <Robert.Schlabbach@gmx.net>

3.4.110-rc1 review patch.  If anyone has any objections, please let me know.

------------------


commit fb6d1f7df5d25299fd7b3e84b72b8851d3634764 upstream.

Fix USB 3.0 devices lost in NOTATTACHED state after a hub port reset.

Dissolve the function hub_port_finish_reset() completely and divide the
actions to be taken into those which need to be done after each reset
attempt and those which need to be done after the full procedure is
complete, and place them in the appropriate places in hub_port_reset().
Also, remove an unneeded forward declaration of hub_port_reset().

Verbose Problem Description:

USB 3.0 devices may be "lost for good" during a hub port reset.
This makes Linux unable to boot from USB 3.0 devices in certain
constellations of host controllers and devices, because the USB device is
lost during initialization, preventing the rootfs from being mounted.

The underlying problem is that in the affected constellations, during the
processing inside hub_port_reset(), the hub link state goes from 0 to
SS.inactive after the initial reset, and back to 0 again only after the
following "warm" reset.

However, hub_port_finish_reset() is called after each reset attempt and
sets the state the connected USB device based on the "preliminary" status
of the hot reset to USB_STATE_NOTATTACHED due to SS.inactive, yet when
the following warm reset is complete and hub_port_finish_reset() is
called again, its call to set the device to USB_STATE_DEFAULT is blocked
by usb_set_device_state() which does not allow taking USB devices out of
USB_STATE_NOTATTACHED state.

Thanks to Alan Stern for guiding me to the proper solution and how to
submit it.

Link: http://lkml.kernel.org/r/trinity-25981484-72a9-4d46-bf17-9c1cf9301a31-1432073240136%20()%203capp-gmx-bs27
Signed-off-by: Robert Schlabbach <robert_s@gmx.net>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[lizf: Backported to 3.4:
 - adjust context
 - s/usb_clear_port_feature/clear_port_feature
 - hub_port_warm_reset_required() takes only two arguments]
Signed-off-by: Zefan Li <lizefan@huawei.com>
---
 drivers/usb/core/hub.c | 81 ++++++++++++++++++++------------------------------
 1 file changed, 32 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 93f2538..62ea924 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2176,9 +2176,6 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
 #define HUB_LONG_RESET_TIME	200
 #define HUB_RESET_TIMEOUT	800
 
-static int hub_port_reset(struct usb_hub *hub, int port1,
-			struct usb_device *udev, unsigned int delay, bool warm);
-
 /* Is a USB 3.0 port in the Inactive or Complinance Mode state?
  * Port worm reset is required to recover
  */
@@ -2258,44 +2255,6 @@ delay:
 	return -EBUSY;
 }
 
-static void hub_port_finish_reset(struct usb_hub *hub, int port1,
-			struct usb_device *udev, int *status)
-{
-	switch (*status) {
-	case 0:
-		/* TRSTRCY = 10 ms; plus some extra */
-		msleep(10 + 40);
-		if (udev) {
-			struct usb_hcd *hcd = bus_to_hcd(udev->bus);
-
-			update_devnum(udev, 0);
-			/* The xHC may think the device is already reset,
-			 * so ignore the status.
-			 */
-			if (hcd->driver->reset_device)
-				hcd->driver->reset_device(hcd, udev);
-		}
-		/* FALL THROUGH */
-	case -ENOTCONN:
-	case -ENODEV:
-		clear_port_feature(hub->hdev,
-				port1, USB_PORT_FEAT_C_RESET);
-		if (hub_is_superspeed(hub->hdev)) {
-			clear_port_feature(hub->hdev, port1,
-					USB_PORT_FEAT_C_BH_PORT_RESET);
-			clear_port_feature(hub->hdev, port1,
-					USB_PORT_FEAT_C_PORT_LINK_STATE);
-			clear_port_feature(hub->hdev, port1,
-					USB_PORT_FEAT_C_CONNECTION);
-		}
-		if (udev)
-			usb_set_device_state(udev, *status
-					? USB_STATE_NOTATTACHED
-					: USB_STATE_DEFAULT);
-		break;
-	}
-}
-
 /* Handle port reset and port warm(BH) reset (for USB3 protocol ports) */
 static int hub_port_reset(struct usb_hub *hub, int port1,
 			struct usb_device *udev, unsigned int delay, bool warm)
@@ -2318,13 +2277,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
 		 * If the caller hasn't explicitly requested a warm reset,
 		 * double check and see if one is needed.
 		 */
-		status = hub_port_status(hub, port1,
-					&portstatus, &portchange);
-		if (status < 0)
-			goto done;
-
-		if (hub_port_warm_reset_required(hub, portstatus))
-			warm = true;
+		if (hub_port_status(hub, port1, &portstatus, &portchange) == 0)
+			if (hub_port_warm_reset_required(hub, portstatus))
+				warm = true;
 	}
 
 	/* Reset the port */
@@ -2347,11 +2302,19 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
 
 		/* Check for disconnect or reset */
 		if (status == 0 || status == -ENOTCONN || status == -ENODEV) {
-			hub_port_finish_reset(hub, port1, udev, &status);
+			clear_port_feature(hub->hdev, port1,
+					USB_PORT_FEAT_C_RESET);
 
 			if (!hub_is_superspeed(hub->hdev))
 				goto done;
 
+			clear_port_feature(hub->hdev, port1,
+					USB_PORT_FEAT_C_BH_PORT_RESET);
+			clear_port_feature(hub->hdev, port1,
+					USB_PORT_FEAT_C_PORT_LINK_STATE);
+			clear_port_feature(hub->hdev, port1,
+					USB_PORT_FEAT_C_CONNECTION);
+
 			/*
 			 * If a USB 3.0 device migrates from reset to an error
 			 * state, re-issue the warm reset.
@@ -2385,6 +2348,26 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
 		port1);
 
 done:
+	if (status == 0) {
+		/* TRSTRCY = 10 ms; plus some extra */
+		msleep(10 + 40);
+		if (udev) {
+			struct usb_hcd *hcd = bus_to_hcd(udev->bus);
+
+			update_devnum(udev, 0);
+			/* The xHC may think the device is already reset,
+			 * so ignore the status.
+			 */
+			if (hcd->driver->reset_device)
+				hcd->driver->reset_device(hcd, udev);
+
+			usb_set_device_state(udev, USB_STATE_DEFAULT);
+		}
+	} else {
+		if (udev)
+			usb_set_device_state(udev, USB_STATE_NOTATTACHED);
+	}
+
 	if (!hub_is_superspeed(hub->hdev))
 		up_read(&ehci_cf_port_reset_rwsem);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3.4 00/65] 3.4.110-rc1 review lizf@kernel.org - 2015-10-20 02:50 +0200
  [PATCH 3.4 16/65] usb: core: Fix USB 3.0 devices lost in NOTATTACHED state after a hub port reset lizf@kernel.org - 2015-10-20 02:50 +0200
  [PATCH 3.4 50/65] crush: fix a bug in tree bucket decode lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 54/65] KVM: x86: properly restore LVT0 lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 56/65] Revert "drm/i915: Don't skip request retirement if the active list is empty" lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 43/65] stmmac: troubleshoot unexpected bits in des0 & des1 lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 35/65] nfs: increase size of EXCHANGE_ID name string buffer lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 55/65] 9p: forgetting to cancel request on interrupted zero-copy RPC lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 46/65] tracing/filter: Do not WARN on operand count going below zero lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 61/65] usb: dwc3: Reset the transfer resource index on SET_INTERFACE lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 24/65] x86/PCI: Use host bridge _CRS info on Foxconn K8M890-8237A lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 44/65] mm: kmemleak: allow safe memory scanning during kmemleak disabling lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 23/65] regulator: core: fix constraints output buffer lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 60/65] ARM: Fix incorrect backport of 0b59d8806a31 lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 40/65] ext4: don't retry file block mapping on bigalloc fs with non-extent file lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 30/65] jbd2: use GFP_NOFS in jbd2_cleanup_journal_tail() lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 63/65] IB/qib: Change lkey table allocation to support more MRs lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 65/65] vfs: Test for and handle paths that are unreachable from their mnt_root lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 62/65] jbd2: avoid infinite loop when destroying aborted journal lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 37/65] ext4: call sync_blockdev() before invalidate_bdev() in put_super() lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 48/65] __bitmap_parselist: fix bug in empty string handling lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 59/65] crypto: s390/ghash: Fix incorrect backport of a1cae34e23b1 lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 47/65] tracing/filter: Do not allow infix to exceed end of string lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 58/65] drm/radeon: partially revert "fix VM_CONTEXT*_PAGE_TABLE_END_ADDR handling" lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 52/65] ACPICA: Tables: Fix an issue that FACS initialization is performed twice lizf@kernel.org - 2015-10-20 03:00 +0200
    RE: [PATCH 3.4 52/65] ACPICA: Tables: Fix an issue that FACS  initialization is performed twice "Moore, Robert" <robert.moore@intel.com> - 2015-10-20 15:40 +0200
      RE: [PATCH 3.4 52/65] ACPICA: Tables: Fix an issue that FACS  initialization is performed twice "Zheng, Lv" <lv.zheng@intel.com> - 2015-10-21 03:30 +0200
  [PATCH 3.4 53/65] KVM: x86: make vapics_in_nmi_mode atomic lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 34/65] mmc: card: Fixup request missing in mmc_blk_issue_rw_rq lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 42/65] bridge: multicast: restore router configuration on port link down/up lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 64/65] dcache: Handle escaped paths in prepend_path lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 36/65] bridge: fix br_stp_set_bridge_priority race conditions lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 51/65] fuse: initialize fc->release before calling it lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 38/65] packet: read num_members once in packet_rcv_fanout() lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 57/65] Revert "drm/radeon: Use drm_calloc_ab for CS relocs" lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 49/65] agp/intel: Fix typo in needs_ilk_vtd_wa() lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 27/65] ext4: fix race between truncate and __ext4_journalled_writepage() lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 39/65] packet: avoid out of bounds read in round robin fanout lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 45/65] dell-laptop: Fix allocating & freeing SMI buffer page lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 41/65] watchdog: omap: assert the counter being stopped before reprogramming lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 25/65] dmaengine: mv_xor: bug fix for racing condition in descriptors cleanup lizf@kernel.org - 2015-10-20 03:00 +0200
  [PATCH 3.4 33/65] ideapad: fix software rfkill setting lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 19/65] SUNRPC: Fix a memory leak in the backchannel code lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 10/65] rndis_wlan: harmless issue calling set_bit() lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 32/65] jbd2: fix ocfs2 corrupt when updating journal superblock fails lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 12/65] usb: dwc3: gadget: return error if command sent to DEPCMD register fails lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 20/65] ipr: Increase default adapter init stage change timeout lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 26/65] ASoC: wm8960: the enum of "DAC Polarity" should be wm8960_enum[1] lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 06/65] ASoC: wm8955: Fix setting wrong register for WM8955_K_8_0_MASK bits lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 01/65] hrtimer: Allow concurrent hrtimer_start() for self restarting timers lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 09/65] tty/serial: at91: RS485 mode: 0 is valid for delay_rts_after_send lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 28/65] Disable write buffering on Toshiba ToPIC95 lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 13/65] rcu: Correctly handle non-empty Tiny RCU callback list with none ready lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 22/65] ath9k: fix DMA stop sequence for AR9003+ lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 31/65] regmap: Fix regmap_bulk_read in BE mode lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 15/65] staging: rtl8712: prevent buffer overrun in recvbuf2recvframe lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 02/65] mtd: fix: avoid race condition when accessing mtd->usecount lizf@kernel.org - 2015-10-20 03:10 +0200
  [PATCH 3.4 29/65] sctp: fix ASCONF list handling lizf@kernel.org - 2015-10-20 03:10 +0200
  Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Guenter Roeck <linux@roeck-us.net> - 2015-10-20 04:20 +0200
    Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Geert Uytterhoeven <geert@linux-m68k.org> - 2015-10-20 09:10 +0200
      Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Geert Uytterhoeven <geert@linux-m68k.org> - 2015-10-20 11:10 +0200
        Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Guenter Roeck <linux@roeck-us.net> - 2015-10-20 15:00 +0200
        Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Guenter Roeck <linux@roeck-us.net> - 2015-10-20 15:20 +0200
          Re: [PATCH 3.4 00/65] 3.4.110-rc1 review Zefan Li <lizefan@huawei.com> - 2015-10-21 10:10 +0200

csiph-web