1. 19 5月, 2012 7 次提交
    • S
      USB: Add support to enable/disable USB3 link states. · 1ea7e0e8
      Sarah Sharp 提交于
      There are various functions within the USB core that will need to
      disable USB 3.0 link power states.  For example, when a USB device
      driver is being bound to an interface, we need to disable USB 3.0 LPM
      until we know if the driver will allow hub-initiated LPM transitions.
      Another example is when the USB core is switching alternate interface
      settings.  The USB 3.0 timeout values are dependent on what endpoints
      are enabled, so we want to ensure that LPM is disabled until the new alt
      setting is fully installed.
      
      Multiple functions need to disable LPM, and those functions can even be
      nested.  For example, usb_bind_interface() could disable LPM, and then
      call into the driver probe function, which may attempt to switch to a
      different alt setting.  Therefore, we need to keep a count of the number
      of functions that require LPM to be disabled at any point in time.
      
      Introduce two new USB core API calls, usb_disable_lpm() and
      usb_enable_lpm().  These functions increment and decrement a new
      variable in the usb_device, lpm_disable_count.  If usb_disable_lpm()
      fails, it will call usb_enable_lpm() in order to balance the
      lpm_disable_count.
      
      These two new functions must be called with the bandwidth_mutex locked.
      If the bandwidth_mutex is not already held by the caller, it should
      instead call usb_unlocked_disable_lpm() and usb_enable_lpm(), which take
      the bandwidth_mutex before calling usb_disable_lpm() and
      usb_enable_lpm(), respectively.
      
      Introduce a new variable (timeout) in the usb3_lpm_params structure to
      keep track of the currently enabled U1/U2 timeout values.  When
      usb_disable_lpm() is called, and the USB device has the U1 or U2
      timeouts set to a non-zero value (meaning either device-initiated or
      hub-initiated LPM is enabled), attempt to disable LPM, regardless of the
      state of the lpm_disable_count.  We want to ensure that all callers can
      be guaranteed that LPM is disabled if usb_disable_lpm() returns zero.
      
      Otherwise the following scenario could occur:
      
      1. Driver A is being bound to interface 1.  usb_probe_interface()
      disables LPM.  Driver A doesn't care if hub-initiated LPM is enabled, so
      even though usb_disable_lpm() fails, the probe of the driver continues,
      and the bandwidth mutex is dropped.
      
      2. Meanwhile, Driver B is being bound to interface 2.
      usb_probe_interface() grabs the bandwidth mutex and calls
      usb_disable_lpm().  That call should attempt to disable LPM, even
      though the lpm_disable_count is set to 1 by Driver A.
      
      For usb_enable_lpm(), we attempt to enable LPM only when the
      lpm_disable_count is zero.  If some step in enabling LPM fails, it will
      only have a minimal impact on power consumption, and all USB device
      drivers should still work properly.  Therefore don't bother to return
      any error codes.
      
      Don't enable device-initiated LPM if the device is unconfigured.  The
      USB device will only accept the U1/U2_ENABLE control transfers in the
      configured state.  Do enable hub-initiated LPM in that case, since
      devices are allowed to accept the LGO_Ux link commands in any state.
      
      Don't enable or disable LPM if the device is marked as not being LPM
      capable.  This can happen if:
       - the USB device doesn't have a SS BOS descriptor,
       - the device's parent hub has a zeroed bHeaderDecodeLatency value, or
       - the xHCI host doesn't support LPM.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Andiry Xu <andiry.xu@amd.com>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      1ea7e0e8
    • S
      USB: Calculate USB 3.0 exit latencies for LPM. · 51e0a012
      Sarah Sharp 提交于
      There are several different exit latencies associated with coming out of
      the U1 or U2 lower power link state.
      
      Device Exit Latency (DEL) is the maximum time it takes for the USB
      device to bring its upstream link into U0.  That can be found in the
      SuperSpeed Extended Capabilities BOS descriptor for the device.  The
      time it takes for a particular link in the tree to exit to U0 is the
      maximum of either the parent hub's U1/U2 DEL, or the child's U1/U2 DEL.
      
      Hubs introduce a further delay that effects how long it takes a child
      device to transition to U0.  When a USB 3.0 hub receives a header
      packet, it takes some time to decode that header and figure out which
      downstream port the packet was destined for.  If the port is not in U0,
      this hub header decode latency will cause an additional delay for
      bringing the child device to U0.  This Hub Header Decode Latency is
      found in the USB 3.0 hub descriptor.
      
      We can use DEL and the header decode latency, along with additional
      latencies imposed by each additional hub tier, to figure out the exit
      latencies for both host-initiated and device-initiated exit to U0.
      
      The Max Exit Latency (MEL) is the worst-case time it will take for a
      host-initiated exit to U0, based on whether U1 or U2 link states are
      enabled.  The ping or packet must traverse the path to the device, and
      each hub along the way incurs the hub header decode latency in order to
      figure out which device the transfer was bound for.  We say worst-case,
      because some hubs may not be in the lowest link state that is enabled.
      See the examples in section C.2.2.1.
      
      Note that "HSD" is a "host specific delay" that the power appendix
      architect has not been able to tell me how to calculate.  There's no way
      to get HSD from the xHCI registers either, so I'm simply ignoring it.
      
      The Path Exit Latency (PEL) is the worst-case time it will take for a
      device-initiate exit to U0 to place all the links from the device to the
      host into U0.
      
      The System Exit Latency (SEL) is another device-initiated exit latency.
      SEL is useful for USB 3.0 devices that need to send data to the host at
      specific intervals.  The device may send an NRDY to indicate it isn't
      ready to send data, then put its link into a lower power state.  If it
      needs to have that data transmitted at a specific time, it can use SEL
      to back calculate when it will need to bring the link back into U0 to
      meet its deadlines.
      
      SEL is the worst-case time from the device-initiated exit to U0, to when
      the device will receive a packet from the host controller.  It includes
      PEL, the time it takes for an ERDY to get to the host, a host-specific
      delay for the host to process that ERDY, and the time it takes for the
      packet to traverse the path to the device.  See Figure C-2 in the USB
      3.0 bus specification.
      
      Note: I have not been able to get good answers about what the
      host-specific delay to process the ERDY should be.  The Intel HW
      developers say it will be specific to the platform the xHCI host is
      integrated into, and they say it's negligible.  Ignore this too.
      
      Separate from these four exit latencies are the U1/U2 timeout values we
      program into the parent hubs.  These timeouts tell the hub to attempt to
      place the device into a lower power link state after the link has been
      idle for that amount of time.
      
      Create two arrays (one for U1 and one for U2) to store mel, pel, sel,
      and the timeout values.  Store the exit latency values in nanosecond
      units, since that's the smallest units used (DEL is in us, but the Hub
      Header Decode Latency is in ns).
      
      If a USB 3.0 device doesn't have a SuperSpeed Extended Capabilities BOS
      descriptor, it's highly unlikely it will be able to handle LPM requests
      properly.  So it's best to disable LPM for devices that don't have this
      descriptor, and any children beneath it, if it's a USB 3.0 hub.  Warn
      users when that happens, since it means they have a non-compliant USB
      3.0 device or hub.
      
      This patch assumes a simplified design where links deep in the tree will
      not have U1 or U2 enabled unless all their parent links have the
      corresponding LPM state enabled.  Eventually, we might want to allow a
      different policy, and we can revisit this patch when that happens.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      51e0a012
    • S
      USB: Refactor code to set LPM support flag. · d9b2099c
      Sarah Sharp 提交于
      Refactor the code that sets the usb_device flag to indicate the device
      support link power management (lpm_capable).  The current code sets
      lpm_capable unconditionally if the USB devices have a USB 2.0 Extended
      Capabilities Descriptor.  USB 3.0 devices can also have that descriptor,
      but the xHCI driver code that uses lpm_capable will not run the USB 2.0
      LPM test for devices under the USB 3.0 roothub.  Therefore, it's fine
      only set lpm_capable for high speed devices in this refactoring.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      d9b2099c
    • S
      USB: Make sure to fetch the BOS desc for roothubs. · 448b6eb1
      Sarah Sharp 提交于
      The BOS descriptor is normally fetched and stored in the usb_device->bos
      during enumeration.  USB 3.0 roothubs don't undergo enumeration, but we
      need them to have a BOS descriptor, since each xHCI host has a different
      U1 and U2 exit latency.  Make sure to fetch the BOS descriptor for USB
      3.0 roothubs.  It will be freed when the roothub usb_device is released.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Andiry Xu <andiry.xu@amd.com>
      448b6eb1
    • S
      xhci: Add roothub code to set U1/U2 timeouts. · 797b0ca5
      Sarah Sharp 提交于
      USB 3.0 hubs can be put into a mode where the hub can automatically
      request that the link go into a deeper link power state after the link
      has been idle for a specified amount of time.  Each of the new USB 3.0
      link states (U1 and U2) have their own timeout that can be programmed
      per port.
      
      Change the xHCI roothub emulation code to handle the request to set the
      U1 and U2 timeouts.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      797b0ca5
    • S
      xhci: Reset reserved command ring TRBs on cleanup. · 33b2831a
      Sarah Sharp 提交于
      When the xHCI driver needs to clean up memory (perhaps due to a failed
      register restore on resume from S3 or resume from S4), it needs to reset
      the number of reserved TRBs on the command ring to zero.  Otherwise,
      several resume cycles (about 30) with a UAS device attached will
      continually increment the number of reserved TRBs, until all command
      submissions fail because there isn't enough room on the command ring.
      
      This patch should be backported to kernels as old as 2.6.32,
      that contain the commit 913a8a34
      "USB: xhci: Change how xHCI commands are handled."
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      33b2831a
    • O
      USB: fix resource leak in xhci power loss path · f8a9e72d
      Oliver Neukum 提交于
      Some more data structures must be freed and counters
      reset if an XHCI controller has lost power. The failure
      to do so renders some chips inoperative after a certain number
      of S4 cycles.
      
      This patch should be backported to kernels as old as 3.2,
      that contain the commits c29eea62
      "xhci: Implement HS/FS/LS bandwidth checking." and
      commit 839c817c
      "xhci: Implement HS/FS/LS bandwidth checking."
      Signed-off-by: NOliver Neukum <oneukum@suse.de>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      f8a9e72d
  2. 18 5月, 2012 5 次提交
  3. 16 5月, 2012 20 次提交
  4. 15 5月, 2012 8 次提交