aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2012-11-14 19:42:32 -0500
committerSarah Sharp <sarah.a.sharp@linux.intel.com>2013-01-03 17:10:23 -0500
commit41e7e056cdc662f704fa9262e5c6e213b4ab45dd (patch)
tree10a8d18c4bc50e829721875cc18d6040b97b6246 /drivers
parent8b8132bc3d1cc3d4c0687e4d638a482fa920d98a (diff)
USB: Allow USB 3.0 ports to be disabled.
If hot and warm reset fails, or a port remains in the Compliance Mode, the USB core needs to be able to disable a USB 3.0 port. Unlike USB 2.0 ports, once the port is placed into the Disabled link state, it will not report any new device connects. To get device connect notifications, we need to put the link into the Disabled state, and then the RxDetect state. The xHCI driver needs to atomically clear all change bits on USB 3.0 port disable, so that we get Port Status Change Events for future port changes. We could technically do this in the USB core instead of in the xHCI roothub code, since the port state machine can't advance out of the disabled state until we set the link state to RxDetect. However, external USB 3.0 hubs don't need this code. They are level-triggered, not edge-triggered like xHCI, so they will continue to send interrupt events when any change bit is set. Therefore it doesn't make sense to put this code in the USB core. This patch is part of a series to fix several reports of infinite loops on device enumeration failure. This includes John, when he boots with a USB 3.0 device (Roseweil eusb3 enclosure) attached to his NEC 0.96 host controller. The fix requires warm reset support, so it does not make sense to backport this patch to stable kernels without warm reset support. This patch should be backported to kernels as old as 3.2, contain the commit ID 75d7cf72ab9fa01dc70877aa5c68e8ef477229dc "usbcore: refine warm reset logic" Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Reported-by: John Covici <covici@ccs.covici.com> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/core/hub.c63
-rw-r--r--drivers/usb/host/xhci-hub.c31
2 files changed, 90 insertions, 4 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 3bc50fc110e..968ec37a0f0 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -877,6 +877,60 @@ static int hub_hub_status(struct usb_hub *hub,
877 return ret; 877 return ret;
878} 878}
879 879
880static int hub_set_port_link_state(struct usb_hub *hub, int port1,
881 unsigned int link_status)
882{
883 return set_port_feature(hub->hdev,
884 port1 | (link_status << 3),
885 USB_PORT_FEAT_LINK_STATE);
886}
887
888/*
889 * If USB 3.0 ports are placed into the Disabled state, they will no longer
890 * detect any device connects or disconnects. This is generally not what the
891 * USB core wants, since it expects a disabled port to produce a port status
892 * change event when a new device connects.
893 *
894 * Instead, set the link state to Disabled, wait for the link to settle into
895 * that state, clear any change bits, and then put the port into the RxDetect
896 * state.
897 */
898static int hub_usb3_port_disable(struct usb_hub *hub, int port1)
899{
900 int ret;
901 int total_time;
902 u16 portchange, portstatus;
903
904 if (!hub_is_superspeed(hub->hdev))
905 return -EINVAL;
906
907 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED);
908 if (ret) {
909 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
910 port1, ret);
911 return ret;
912 }
913
914 /* Wait for the link to enter the disabled state. */
915 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) {
916 ret = hub_port_status(hub, port1, &portstatus, &portchange);
917 if (ret < 0)
918 return ret;
919
920 if ((portstatus & USB_PORT_STAT_LINK_STATE) ==
921 USB_SS_PORT_LS_SS_DISABLED)
922 break;
923 if (total_time >= HUB_DEBOUNCE_TIMEOUT)
924 break;
925 msleep(HUB_DEBOUNCE_STEP);
926 }
927 if (total_time >= HUB_DEBOUNCE_TIMEOUT)
928 dev_warn(hub->intfdev, "Could not disable port %d after %d ms\n",
929 port1, total_time);
930
931 return hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_RX_DETECT);
932}
933
880static int hub_port_disable(struct usb_hub *hub, int port1, int set_state) 934static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
881{ 935{
882 struct usb_device *hdev = hub->hdev; 936 struct usb_device *hdev = hub->hdev;
@@ -885,8 +939,13 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
885 if (hub->ports[port1 - 1]->child && set_state) 939 if (hub->ports[port1 - 1]->child && set_state)
886 usb_set_device_state(hub->ports[port1 - 1]->child, 940 usb_set_device_state(hub->ports[port1 - 1]->child,
887 USB_STATE_NOTATTACHED); 941 USB_STATE_NOTATTACHED);
888 if (!hub->error && !hub_is_superspeed(hub->hdev)) 942 if (!hub->error) {
889 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); 943 if (hub_is_superspeed(hub->hdev))
944 ret = hub_usb3_port_disable(hub, port1);
945 else
946 ret = clear_port_feature(hdev, port1,
947 USB_PORT_FEAT_ENABLE);
948 }
890 if (ret) 949 if (ret)
891 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 950 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
892 port1, ret); 951 port1, ret);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index a686cf4905b..a7dd4f311e1 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -761,12 +761,39 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
761 break; 761 break;
762 case USB_PORT_FEAT_LINK_STATE: 762 case USB_PORT_FEAT_LINK_STATE:
763 temp = xhci_readl(xhci, port_array[wIndex]); 763 temp = xhci_readl(xhci, port_array[wIndex]);
764
765 /* Disable port */
766 if (link_state == USB_SS_PORT_LS_SS_DISABLED) {
767 xhci_dbg(xhci, "Disable port %d\n", wIndex);
768 temp = xhci_port_state_to_neutral(temp);
769 /*
770 * Clear all change bits, so that we get a new
771 * connection event.
772 */
773 temp |= PORT_CSC | PORT_PEC | PORT_WRC |
774 PORT_OCC | PORT_RC | PORT_PLC |
775 PORT_CEC;
776 xhci_writel(xhci, temp | PORT_PE,
777 port_array[wIndex]);
778 temp = xhci_readl(xhci, port_array[wIndex]);
779 break;
780 }
781
782 /* Put link in RxDetect (enable port) */
783 if (link_state == USB_SS_PORT_LS_RX_DETECT) {
784 xhci_dbg(xhci, "Enable port %d\n", wIndex);
785 xhci_set_link_state(xhci, port_array, wIndex,
786 link_state);
787 temp = xhci_readl(xhci, port_array[wIndex]);
788 break;
789 }
790
764 /* Software should not attempt to set 791 /* Software should not attempt to set
765 * port link state above '5' (Rx.Detect) and the port 792 * port link state above '3' (U3) and the port
766 * must be enabled. 793 * must be enabled.
767 */ 794 */
768 if ((temp & PORT_PE) == 0 || 795 if ((temp & PORT_PE) == 0 ||
769 (link_state > USB_SS_PORT_LS_RX_DETECT)) { 796 (link_state > USB_SS_PORT_LS_U3)) {
770 xhci_warn(xhci, "Cannot set link state.\n"); 797 xhci_warn(xhci, "Cannot set link state.\n");
771 goto error; 798 goto error;
772 } 799 }