1. 20 5月, 2014 2 次提交
  2. 05 3月, 2014 5 次提交
    • H
      xhci: The trb_address_map radix tree expects 1KB segment memory aligment · 84c1e40f
      Hans de Goede 提交于
      If we align segment dma pool memory to 64 bytes, then a segment can be located
      at 0x10000040 - 0x1000043f, and a segment from another ring at 0x10000440 -
      0x1000083f. The last trb in the first segment at 0x10000430 will then translate
      to the same radix tree key as the first trb of the second segment, while they
      are in different rings!
      
      This patches fixes this by changing the alignment of the dma pool to be 1KB
      rather then 64 bytes. An alternative fix would be to reduce the shift used
      to calculate the radix tree keys, but that would (slighlty) grow the radix
      trees so I believe this is the better fix.
      
      Note this patch is mostly theoretical since in practice I've not seen
      the dma_pool actually return not 1KB aligned memory.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      84c1e40f
    • H
      xhci: xhci_mem_cleanup: make sure cmd_ring_reserved_trbs really is 0 · 127329d7
      Hans de Goede 提交于
      cmd_ring_reserved_trbs gets decremented by xhci_free_stream_info(), so set it
      to 0 after freeing all rings, otherwise it wraps around to a very large value
      when rings with streams are free-ed.
      
      Before this patch the wrap-around could be triggered when xhci_resume
      calls xhci_mem_cleanup if the controller resume fails.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      127329d7
    • S
      xhci: Remove segments from radix tree on failed insert. · d5734223
      Sarah Sharp 提交于
      If we're expanding a stream ring, we want to make sure we can add those
      ring segments to the radix tree that maps segments to ring pointers.
      Try the radix tree insert after the new ring segments have been allocated
      (the last segment in the new ring chunk will point to the first newly
      allocated segment), but before the new ring segments are linked into the
      old ring.
      
      If insert fails on any one segment, remove each segment from the radix
      tree, deallocate the new segments, and return.  Otherwise, link the new
      segments into the tree.
      
      HdG: Add a check to only update stream mappings in xhci_ring_expansion when
      the ring is a stream ring.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      d5734223
    • H
      xhci: Check size rather then number of streams when allocating stream ctxs · ee4aa54b
      Hans de Goede 提交于
      Before this a device needing ie 32 stream ctxs would end up with an entry from
      the small_streams_pool which has 256 bytes entries, where as 32 stream ctxs
      need 512 bytes. Things actually keep running for a surprisingly long time
      before crashing because of this.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      ee4aa54b
    • G
      xhci: fix usb3 streams · 15341303
      Gerd Hoffmann 提交于
      xhci maintains a radix tree for each stream endpoint because it must
      be able to map a trb address to the stream ring.  Each ring segment
      must be added to the ring for this to work.  Currently xhci sticks
      only the first segment of each stream ring into the radix tree.
      
      Result is that things work initially, but as soon as the first segment
      is full xhci can't map the trb address from the completion event to the
      stream ring any more -> BOOM.  You'll find this message in the logs:
      
        ERROR Transfer event for disabled endpoint or incorrect stream ring
      
      This patch adds a helper function to update the radix tree, and a
      function to remove ring segments from the tree.  Both functions loop
      over the segment list and handles all segments instead of just the
      first.
      
      [Note: Sarah changed this patch to add radix_tree_maybe_preload() and
      radix_tree_preload_end() calls around the radix tree insert, since we
      can now insert entries in interrupt context.  There are now two helper
      functions to make the code cleaner, and those functions are moved to
      make them static.]
      Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      15341303
  3. 31 1月, 2014 1 次提交
  4. 30 1月, 2014 1 次提交
    • S
      Revert "xhci: replace xhci_write_64() with writeq()" · 477632df
      Sarah Sharp 提交于
      This reverts commit 7dd09a1a.
      
      Many xHCI host controllers can only handle 32-bit addresses, and writing
      64-bits at a time causes them to fail.  Rafał reports that USB devices
      simply do not enumerate, and reverting this patch helps.  Branimir
      reports that his host controller doesn't respond to an Enable Slot
      command and dies:
      
      [   75.576160] xhci_hcd 0000:03:00.0: Timeout while waiting for a slot
      [   88.991634] xhci_hcd 0000:03:00.0: Stopped the command ring failed, maybe the host is dead
      [   88.991748] xhci_hcd 0000:03:00.0: Abort command ring failed
      [   88.991845] xhci_hcd 0000:03:00.0: HC died; cleaning up
      [   93.985489] xhci_hcd 0000:03:00.0: Timeout while waiting for a slot
      [   93.985494] xhci_hcd 0000:03:00.0: Abort the command ring, but the xHCI is dead.
      [   98.982586] xhci_hcd 0000:03:00.0: Timeout while waiting for a slot
      [   98.982591] xhci_hcd 0000:03:00.0: Abort the command ring, but the xHCI is dead.
      [  103.979696] xhci_hcd 0000:03:00.0: Timeout while waiting for a slot
      [  103.979702] xhci_hcd 0000:03:00.0: Abort the command ring, but the xHCI is dead
      Signed-off-by: NSarah Sharp <sarah.a.sharp@intel.com>
      Reported-by: NRafał Miłecki <zajec5@gmail.com>
      Reported-by: NBranimir Maksimovic <branimir.maksimovic@gmail.com>
      Cc: Xenia Ragiadakou <burzalodowa@gmail.com>
      477632df
  5. 03 12月, 2013 7 次提交
  6. 17 10月, 2013 1 次提交
    • S
      usb: Don't enable USB 2.0 Link PM by default. · de68bab4
      Sarah Sharp 提交于
      How it's supposed to work:
      --------------------------
      
      USB 2.0 Link PM is a lower power state that some newer USB 2.0 devices
      support.  USB 3.0 devices certified by the USB-IF are required to
      support it if they are plugged into a USB 2.0 only port, or a USB 2.0
      cable is used.  USB 2.0 Link PM requires both a USB device and a host
      controller that supports USB 2.0 hardware-enabled LPM.
      
      USB 2.0 Link PM is designed to be enabled once by software, and the host
      hardware handles transitions to the L1 state automatically.  The premise
      of USB 2.0 Link PM is to be able to put the device into a lower power
      link state when the bus is idle or the device NAKs USB IN transfers for
      a specified amount of time.
      
      ...but hardware is broken:
      --------------------------
      
      It turns out many USB 3.0 devices claim to support USB 2.0 Link PM (by
      setting the LPM bit in their USB 2.0 BOS descriptor), but they don't
      actually implement it correctly.  This manifests as the USB device
      refusing to respond to transfers when it is plugged into a USB 2.0 only
      port under the Haswell-ULT/Lynx Point LP xHCI host.
      
      These devices pass the xHCI driver's simple test to enable USB 2.0 Link
      PM, wait for the port to enter L1, and then bring it back into L0.  They
      only start to break when L1 entry is interleaved with transfers.
      
      Some devices then fail to respond to the next control transfer (usually
      a Set Configuration).  This results in devices never enumerating.
      
      Other mass storage devices (such as a later model Western Digital My
      Passport USB 3.0 hard drive) respond fine to going into L1 between
      control transfers.  They ACK the entry, come out of L1 when the host
      needs to send a control transfer, and respond properly to those control
      transfers.  However, when the first READ10 SCSI command is sent, the
      device NAKs the data phase while it's reading from the spinning disk.
      Eventually, the host requests to put the link into L1, and the device
      ACKs that request.  Then it never responds to the data phase of the
      READ10 command.  This results in not being able to read from the drive.
      
      Some mass storage devices (like the Corsair Survivor USB 3.0 flash
      drive) are well behaved.  They ACK the entry into L1 during control
      transfers, and when SCSI commands start coming in, they NAK the requests
      to go into L1, because they need to be at full power.
      
      Not all USB 3.0 devices advertise USB 2.0 link PM support.  My Point
      Grey USB 3.0 webcam advertises itself as a USB 2.1 device, but doesn't
      have a USB 2.0 BOS descriptor, so we don't enable USB 2.0 Link PM.  I
      suspect that means the device isn't certified.
      
      What do we do about it?
      -----------------------
      
      There's really no good way for the kernel to test these devices.
      Therefore, the kernel needs to disable USB 2.0 Link PM by default, and
      distros will have to enable it by writing 1 to the sysfs file
      /sys/bus/usb/devices/../power/usb2_hardware_lpm.  Rip out the xHCI Link
      PM test, since it's not sufficient to detect these buggy devices, and
      don't automatically enable LPM after the device is addressed.
      
      This patch should be backported to kernels as old as 3.11, that
      contain the commit a558ccdc "usb: xhci:
      add USB2 Link power management BESL support".  Without this fix, some
      USB 3.0 devices will not enumerate or work properly under USB 2.0 ports
      on Haswell-ULT systems.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      de68bab4
  7. 24 9月, 2013 1 次提交
    • S
      usb: Fix xHCI host issues on remote wakeup. · 8b3d4570
      Sarah Sharp 提交于
      When a device signals remote wakeup on a roothub, and the suspend change
      bit is set, the host controller driver must not give control back to the
      USB core until the port goes back into the active state.
      
      EHCI accomplishes this by waiting in the get port status function until
      the PORT_RESUME bit is cleared:
      
                              /* stop resume signaling */
                              temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
                              ehci_writel(ehci, temp, status_reg);
                              clear_bit(wIndex, &ehci->resuming_ports);
                              retval = ehci_handshake(ehci, status_reg,
                                              PORT_RESUME, 0, 2000 /* 2msec */);
      
      Similarly, the xHCI host should wait until the port goes into U0, before
      passing control up to the USB core.  When the port transitions from the
      RExit state to U0, the xHCI driver will get a port status change event.
      We need to wait for that event before passing control up to the USB
      core.
      
      After the port transitions to the active state, the USB core should time
      a recovery interval before it talks to the device.  The length of that
      recovery interval is TRSMRCY, 10 ms, mentioned in the USB 2.0 spec,
      section 7.1.7.7.  The previous xHCI code (which did not wait for the
      port to go into U0) would cause the USB core to violate that recovery
      interval.
      
      This bug caused numerous USB device disconnects on remote wakeup under
      ChromeOS and a Lynx Point LP xHCI host that takes up to 20 ms to move
      from RExit to U0.  ChromeOS is very aggressive about power savings, and
      sets the autosuspend_delay to 100 ms, and disables USB persist.
      
      I attempted to replicate this bug with Ubuntu 12.04, but could not.  I
      used Ubuntu 12.04 on the same platform, with the same BIOS that the bug
      was triggered on ChromeOS with.  I also changed the USB sysfs settings
      as described above, but still could not reproduce the bug under Ubuntu.
      It may be that ChromeOS userspace triggers this bug through additional
      settings.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      8b3d4570
  8. 14 8月, 2013 4 次提交
  9. 01 8月, 2013 1 次提交
    • J
      usb: xhci: add missing dma-mapping.h includes · 008eb957
      James Hogan 提交于
      A randconfig build hit the following build errors because xhci.c and
      xhci-mem.c use dma mapping functions but don't include
      <linux/dma-mapping.h>. Add the missing includes to fix the build errors.
      
      drivers/usb/host/xhci.c In function 'xhci_gen_setup':
      drivers/usb/host/xhci.c +4872 : error: implicit declaration of function 'dma_set_mask'
      drivers/usb/host/xhci.c +4872 : error: implicit declaration of function 'DMA_BIT_MASK'
      
      drivers/usb/host/xhci-mem.c In function 'xhci_free_stream_ctx':
      drivers/usb/host/xhci-mem.c +435 : error: implicit declaration of function 'dma_free_coherent'
      drivers/usb/host/xhci-mem.c In function 'xhci_alloc_stream_ctx':
      drivers/usb/host/xhci-mem.c +463 : error: implicit declaration of function 'dma_alloc_coherent'
      Signed-off-by: NJames Hogan <james.hogan@imgtec.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: linux-usb@vger.kernel.org
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      008eb957
  10. 19 6月, 2013 1 次提交
  11. 15 6月, 2013 4 次提交
  12. 06 6月, 2013 1 次提交
  13. 25 5月, 2013 2 次提交
  14. 16 5月, 2013 1 次提交
    • A
      USB: xHCI: override bogus bulk wMaxPacketSize values · e4f47e36
      Alan Stern 提交于
      This patch shortens the logic in xhci_endpoint_init() by moving common
      calculations involving max_packet and max_burst outside the switch
      statement, rather than repeating the same code in multiple
      case-specific statements.  It also replaces two usages of max_packet
      which were clearly intended to be max_burst all along.
      
      More importantly, it compensates for a common bug in high-speed bulk
      endpoint descriptors.  In many devices there is a bulk endpoint having
      a wMaxPacketSize value smaller than 512, which is forbidden by the USB
      spec.  Some xHCI controllers can't handle this and refuse to accept
      the endpoint.  This patch changes the max_packet value to 512, which
      allows the controller to use the endpoint properly.
      
      In practice the bogus maxpacket size doesn't matter, because none of
      the transfers sent via these endpoints are longer than the maxpacket
      value anyway.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-and-tested-by: N"Aurélien Leblond" <blablack@gmail.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e4f47e36
  15. 04 4月, 2013 1 次提交
  16. 26 3月, 2013 1 次提交
    • L
      usb: add find_raw_port_number callback to struct hc_driver() · 3f5eb141
      Lan Tianyu 提交于
      xhci driver divides the root hub into two logical hubs which work
      respectively for usb 2.0 and usb 3.0 devices. They are independent
      devices in the usb core. But in the ACPI table, it's one device node
      and all usb2.0 and usb3.0 ports are under it. Binding usb port with
      its acpi node needs the raw port number which is reflected in the xhci
      extended capabilities table. This patch is to add find_raw_port_number
      callback to struct hc_driver(), fill it with xhci_find_raw_port_number()
      which will return raw port number and add a wrap usb_hcd_find_raw_port_number().
      
      Otherwise, refactor xhci_find_real_port_number(). Using
      xhci_find_raw_port_number() to get real index in the HW port status
      registers instead of scanning through the xHCI roothub port array.
      This can help to speed up.
      
      All addresses in xhci->usb2_ports and xhci->usb3_ports array are
      kown good ports and don't include following bad ports in the extended
      capabilities talbe.
           (1) root port that doesn't have an entry
           (2) root port with unknown speed
           (3) root port that is listed twice and with different speeds.
      
      So xhci_find_raw_port_number() will only return port num of good ones
      and never touch bad ports above.
      Signed-off-by: NLan Tianyu <tianyu.lan@intel.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      3f5eb141
  17. 04 1月, 2013 1 次提交
    • S
      xhci: Handle HS bulk/ctrl endpoints that don't NAK. · 55c1945e
      Sarah Sharp 提交于
      A high speed control or bulk endpoint may have bInterval set to zero,
      which means it does not NAK.  If bInterval is non-zero, it means the
      endpoint NAKs at a rate of 2^(bInterval - 1).
      
      The xHCI code to compute the NAK interval does not handle the special
      case of zero properly.  The current code unconditionally subtracts one
      from bInterval and uses it as an exponent.  This causes a very large
      bInterval to be used, and warning messages like these will be printed:
      
      usb 1-1: ep 0x1 - rounding interval to 32768 microframes, ep desc says 0 microframes
      
      This may cause the xHCI host hardware to reject the Configure Endpoint
      command, which means the HS device will be unusable under xHCI ports.
      
      This patch should be backported to kernels as old as 2.6.31, that contain
      commit dfa49c4a "USB: xhci - fix math in
      xhci_get_endpoint_interval()".
      Reported-by: NVincent Pelletier <plr.vincent@gmail.com>
      Suggested-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      55c1945e
  18. 13 11月, 2012 1 次提交
    • J
      xhci: fix null-pointer dereference when destroying half-built segment rings · 68e5254a
      Julius Werner 提交于
      xhci_alloc_segments_for_ring() builds a list of xhci_segments and links
      the tail to head at the end (forming a ring). When it bails out for OOM
      reasons half-way through, it tries to destroy its half-built list with
      xhci_free_segments_for_ring(), even though it is not a ring yet. This
      causes a null-pointer dereference upon hitting the last element.
      
      Furthermore, one of its callers (xhci_ring_alloc()) mistakenly believes
      the output parameters to be valid upon this kind of OOM failure, and
      calls xhci_ring_free() on them. Since the (incomplete) list/ring should
      already be destroyed in that case, this would lead to a use after free.
      
      This patch fixes those issues by having xhci_alloc_segments_for_ring()
      destroy its half-built, non-circular list manually and destroying the
      invalid struct xhci_ring in xhci_ring_alloc() with a plain kfree().
      
      This patch should be backported to kernels as old as 2.6.31, that
      contains the commit 0ebbab37 "USB: xhci:
      Ring allocation and initialization."
      
      A separate patch will need to be developed for kernels older than 3.4,
      since the ring allocation code was refactored in that kernel.
      Signed-off-by: NJulius Werner <jwerner@chromium.org>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable@vger.kernel.org
      68e5254a
  19. 14 9月, 2012 1 次提交
    • E
      xHCI: add aborting command ring function · b92cc66c
      Elric Fu 提交于
      Software have to abort command ring and cancel command
      when a command is failed or hang. Otherwise, the command
      ring will hang up and can't handle the others. An example
      of a command that may hang is the Address Device Command,
      because waiting for a SET_ADDRESS request to be acknowledged
      by a USB device is outside of the xHC's ability to control.
      
      To cancel a command, software will initialize a command
      descriptor for the cancel command, and add it into a
      cancel_cmd_list of xhci.
      
      Sarah: Fixed missing newline on "Have the command ring been stopped?"
      debugging statement.
      
      This patch should be backported to kernels as old as 3.0, that contain
      the commit 7ed603ec "xhci: Add an
      assertion to check for virt_dev=0 bug." That commit papers over a NULL
      pointer dereference, and this patch fixes the underlying issue that
      caused the NULL pointer dereference.
      Signed-off-by: NElric Fu <elricfu1@gmail.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Tested-by: NMiroslav Sabljic <miroslav.sabljic@avl.com>
      Cc: stable@vger.kernel.org
      b92cc66c
  20. 14 6月, 2012 2 次提交
    • T
      xhci: Don't free endpoints in xhci_mem_cleanup() · 32f1d2c5
      Takashi Iwai 提交于
      This patch fixes a few issues introduced in the recent fix
      [f8a9e72d: USB: fix resource leak in xhci power loss path]
      
      - The endpoints listed in bw table are just links and each entry is an
       array member of dev->eps[].  But the commit above adds a kfree() call
       to these instances, and thus it results in memory corruption.
      
      - It clears only the first entry of rh_bw[], but there can be multiple
        ports.
      
      - It'd be safer to clear the list_head of ep as well, not only
        removing from the list, as it's checked in
        xhci_discover_or_reset_device().
      
      This patch should be backported to kernels as old as 3.2, that contain
      the commit 839c817c "xhci: Store
      information about roothubs and TTs."
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Reviewed-by: NOliver Neukum <oneukum@suse.de>
      Cc: <stable@vger.kernel.org>
      32f1d2c5
    • T
      xhci: Fix invalid loop check in xhci_free_tt_info() · 46ed8f00
      Takashi Iwai 提交于
      xhci_free_tt_info() may access the invalid memory when it removes the
      last entry but the list is not empty.  Then tt_next reaches to the
      list head but it still tries to check the tt_info of that entry.
      
      This patch fixes the bug and cleans up the messy code by rewriting
      with a simple list_for_each_entry_safe().
      
      This patch should be backported to kernels as old as 3.2, that contain
      the commit 839c817c "xhci: Store
      information about roothubs and TTs."
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Reviewed-by: NOliver Neukum <oneukum@suse.de>
      Cc: <stable@vger.kernel.org>
      46ed8f00
  21. 19 5月, 2012 1 次提交
    • S
      xhci: Reserve one command for USB3 LPM disable. · dbc33303
      Sarah Sharp 提交于
      We want to do everything we can to ensure that USB 3.0 Link Power
      Management (LPM) can be disabled when it is enabled.  If LPM can't be
      disabled, we can't suspend USB 3.0 devices, or reset them.  To make sure
      we can submit the command to disable LPM, allocate a command in the
      xhci_hcd structure, and reserve one TRB on the command ring.
      
      We only need one command per xHCI driver instance, because LPM is only
      disabled or enabled while the USB core is holding the bandwidth_mutex
      that is shared between the xHCI USB 2.0 and USB 3.0 roothubs.  The
      bandwidth_mutex will be held until the command completes, or times out.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      dbc33303