1. 15 11月, 2011 1 次提交
    • A
      USB: Remove the SAW_IRQ hcd flag · 968b822c
      Alan Stern 提交于
      The HCD_FLAG_SAW_IRQ flag was introduced in order to catch IRQ routing
      errors: If an URB was unlinked and the host controller hadn't gotten
      any IRQs, it seemed likely that the IRQs were directed to the wrong
      vector.
      
      This warning hasn't come up in many years, as far as I know; interrupt
      routing now seems to be well under control.  Therefore there's no
      reason to keep the flag around any more.  This patch (as1495) finally
      removes it.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      968b822c
  2. 27 9月, 2011 4 次提交
  3. 20 9月, 2011 1 次提交
    • A
      USB: xHCI: prevent infinite loop when processing MSE event · c2d7b49f
      Andiry Xu 提交于
      When a xHC host is unable to handle isochronous transfer in the
      interval, it reports a Missed Service Error event and skips some tds.
      
      Currently xhci driver handles MSE event in the following ways:
      
      1. When encounter a MSE event, set ep->skip flag, update event ring
         dequeue pointer and return.
      
      2. When encounter the next event on this ep, the driver will run the
         do-while loop, fetch td from ep's td_list to find the td
         corresponding to this event.  All tds missed are marked as short
         transfer(-EXDEV).
      
      The do-while loop will end in two ways:
      
      1. If the td pointed by the event trb is found;
      
      2. If the ep ring's td_list is empty.
      
      However, if a buggy HW reports some unpredicted event (for example, an
      overrun event following a MSE event while the ep ring is actually not
      empty), the driver will never find the td, and it will loop until the
      td_list is empty.
      
      Unfortunately, the spinlock is dropped when give back a urb in the
      do-while loop.  During the spinlock released period, the class driver
      may still submit urbs and add tds to the td_list.  This may cause
      disaster, since the td_list will never be empty and the loop never ends,
      and the system hangs.
      
      To fix this, count the number of TDs on the ep ring before skipping TDs,
      and quit the loop when skipped that number of tds.  This guarantees the
      do-while loop will end after certain number of cycles, and driver will
      not be trapped in an infinite loop.
      Signed-off-by: NAndiry Xu <andiry.xu@amd.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c2d7b49f
  4. 10 9月, 2011 1 次提交
    • S
      xhci: Don't print short isoc packets. · fd984d24
      Sarah Sharp 提交于
      Now that the xHCI driver always return a status value of zero for isochronous
      URBs, when the last TD of an isochronous URB is short, the local variable
      "status" stays set to -EINPROGRESS.  When xHCI driver debugging is turned on,
      this causes the log file to fill with messages like this:
      
      [   38.859282] xhci_hcd 0000:00:14.0: Giveback URB ffff88013ad47800, len = 1408, expected = 580, status = -115
      
      Don't print out the status of an URB for isochronous URBs.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      fd984d24
  5. 24 8月, 2011 1 次提交
    • K
      USB: use usb_endpoint_maxp() instead of le16_to_cpu() · 29cc8897
      Kuninori Morimoto 提交于
      Now ${LINUX}/drivers/usb/* can use usb_endpoint_maxp(desc) to get maximum packet size
      instead of le16_to_cpu(desc->wMaxPacketSize).
      This patch fix it up
      
      Cc: Armin Fuerst <fuerst@in.tum.de>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Johannes Erdfelt <johannes@erdfelt.com>
      Cc: Vojtech Pavlik <vojtech@suse.cz>
      Cc: Oliver Neukum <oliver@neukum.name>
      Cc: David Kubicek <dave@awk.cz>
      Cc: Johan Hovold <jhovold@gmail.com>
      Cc: Brad Hards <bhards@bigpond.net.au>
      Acked-by: NFelipe Balbi <balbi@ti.com>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc: Thomas Dahlmann <dahlmann.thomas@arcor.de>
      Cc: David Brownell <david-b@pacbell.net>
      Cc: David Lopo <dlopo@chipidea.mips.com>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
      Cc: Xie Xiaobo <X.Xie@freescale.com>
      Cc: Li Yang <leoli@freescale.com>
      Cc: Jiang Bo <tanya.jiang@freescale.com>
      Cc: Yuan-hsin Chen <yhchen@faraday-tech.com>
      Cc: Darius Augulis <augulis.darius@gmail.com>
      Cc: Xiaochen Shen <xiaochen.shen@intel.com>
      Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
      Cc: OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>
      Cc: Robert Jarzmik <robert.jarzmik@free.fr>
      Cc: Ben Dooks <ben@simtec.co.uk>
      Cc: Thomas Abraham <thomas.ab@samsung.com>
      Cc: Herbert Pötzl <herbert@13thfloor.at>
      Cc: Arnaud Patard <arnaud.patard@rtp-net.org>
      Cc: Roman Weissgaerber <weissg@vienna.at>
      Acked-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Tony Olech <tony.olech@elandigitalsystems.com>
      Cc: Florian Floe Echtler <echtler@fs.tum.de>
      Cc: Christian Lucht <lucht@codemercs.com>
      Cc: Juergen Stuber <starblue@sourceforge.net>
      Cc: Georges Toth <g.toth@e-biz.lu>
      Cc: Bill Ryder <bryder@sgi.com>
      Cc: Kuba Ober <kuba@mareimbrium.org>
      Cc: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
      Signed-off-by: NKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      29cc8897
  6. 17 8月, 2011 1 次提交
    • S
      xhci: Handle zero-length isochronous packets. · 48df4a6f
      Sarah Sharp 提交于
      For a long time, the xHCI driver has had this note:
      	/* FIXME: Ignoring zero-length packets, can those happen? */
      
      It turns out that, yes, there are drivers that need to queue zero-length
      transfers for isochronous OUT transfers.  Without this patch, users will
      see kernel hang messages when a driver attempts to enqueue an isochronous
      URB with a zero length transfer (because count_isoc_trbs_needed will return
      zero for that TD, xhci_td->last_trb will never be set, and updating the
      dequeue pointer will cause an infinite loop).
      
      Matěj ran into this issue when using an NI Audio4DJ USB soundcard
      with the snd-usb-caiaq driver.  See
      	https://bugzilla.kernel.org/show_bug.cgi?id=40702
      
      Fix count_isoc_trbs_needed() to return 1 for zero-length transfers (thanks
      Alan on the math help).  Update the various TRB field calculations to deal
      with zero-length transfers.  We're still transferring one packet with a
      zero-length data payload, so the total_packet_count should be 1. The
      Transfer Burst Count (TBC) and Transfer Last Burst Packet Count (TLBPC)
      fields should be set to zero.
      
      This patch should be backported to kernels as old as 2.6.36.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Tested-by: NMatěj Laitl <matej@laitl.cz>
      Cc: Daniel Mack <zonque@gmail.com>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: stable@kernel.org
      48df4a6f
  7. 10 8月, 2011 3 次提交
    • S
      xhci: Remove TDs from TD lists when URBs are canceled. · 585df1d9
      Sarah Sharp 提交于
      When a driver tries to cancel an URB, and the host controller is dying,
      xhci_urb_dequeue will giveback the URB without removing the xhci_tds
      that comprise that URB from the td_list or the cancelled_td_list.  This
      can cause a race condition between the driver calling URB dequeue and
      the stop endpoint command watchdog timer.
      
      If the timer fires on a dying host, and a driver attempts to resubmit
      while the watchdog timer has dropped the xhci->lock to giveback a
      cancelled URB, URBs may be given back by the xhci_urb_dequeue() function.
      At that point, the URB's priv pointer will be freed and set to NULL, but
      the TDs will remain on the td_list.  This will cause an oops in
      xhci_giveback_urb_in_irq() when the watchdog timer attempts to loop
      through the endpoints' td_lists, giving back killed URBs.
      
      Make sure that xhci_urb_dequeue() removes TDs from the TD lists and
      canceled TD lists before it gives back the URB.
      
      This patch should be backported to kernels as old as 2.6.36.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Andiry Xu <andiry.xu@amd.com>
      Cc: stable@kernel.org
      585df1d9
    • S
      xhci: Fix failed enqueue in the middle of isoch TD. · 522989a2
      Sarah Sharp 提交于
      When an isochronous transfer is enqueued, xhci_queue_isoc_tx_prepare()
      will ensure that there is enough room on the transfer rings for all of the
      isochronous TDs for that URB.  However, when xhci_queue_isoc_tx() is
      enqueueing individual isoc TDs, the prepare_transfer() function can fail
      if the endpoint state has changed to disabled, error, or some other
      unknown state.
      
      With the current code, if Nth TD (not the first TD) fails, the ring is
      left in a sorry state.  The partially enqueued TDs are left on the ring,
      and the first TRB of the TD is not given back to the hardware.  The
      enqueue pointer is left on the TRB after the last successfully enqueued
      TD.  This means the ring is basically useless.  Any new transfers will be
      enqueued after the failed TDs, which the hardware will never read because
      the cycle bit indicates it does not own them.  The ring will fill up with
      untransferred TDs, and the endpoint will be basically unusable.
      
      The untransferred TDs will also remain on the TD list.  Since the td_list
      is a FIFO, this basically means the ring handler will be waiting on TDs
      that will never be completed (or worse, dereference memory that doesn't
      exist any more).
      
      Change the code to clean up the isochronous ring after a failed transfer.
      If the first TD failed, simply return and allow the xhci_urb_enqueue
      function to free the urb_priv.  If the Nth TD failed, first remove the TDs
      from the td_list.  Then convert the TRBs that were enqueued into No-op
      TRBs.  Make sure to flip the cycle bit on all enqueued TRBs (including any
      link TRBs in the middle or between TDs), but leave the cycle bit of the
      first TRB (which will show software-owned) intact.  Then move the ring
      enqueue pointer back to the first TRB and make sure to change the
      xhci_ring's cycle state to what is appropriate for that ring segment.
      
      This ensures that the No-op TRBs will be overwritten by subsequent TDs,
      and the hardware will not start executing random TRBs because the cycle
      bit was left as hardware-owned.
      
      This bug is unlikely to be hit, but it was something I noticed while
      tracking down the watchdog timer issue.  I verified that the fix works by
      injecting some errors on the 250th isochronous URB queued, although I
      could not verify that the ring is in the correct state because uvcvideo
      refused to talk to the device after the first usb_submit_urb() failed.
      Ring debugging shows that the ring looks correct, however.
      
      This patch should be backported to kernels as old as 2.6.36.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Andiry Xu <andiry.xu@amd.com>
      Cc: stable@kernel.org
      522989a2
    • S
      xhci: Fix memory leak during failed enqueue. · d13565c1
      Sarah Sharp 提交于
      When the isochronous transfer support was introduced, and the xHCI driver
      switched to using urb->hcpriv to store an "urb_priv" pointer, a couple of
      memory leaks were introduced into the URB enqueue function in its error
      handling paths.
      
      xhci_urb_enqueue allocates urb_priv, but it doesn't free it if changing
      the control endpoint's max packet size fails or the bulk endpoint is in
      the middle of allocating or deallocating streams.
      
      xhci_urb_enqueue also doesn't free urb_priv if any of the four endpoint
      types' enqueue functions fail.  Instead, it expects those functions to
      free urb_priv if an error occurs.  However, the bulk, control, and
      interrupt enqueue functions do not free urb_priv if the endpoint ring is
      NULL.  It will, however, get freed if prepare_transfer() fails in those
      enqueue functions.
      
      Several of the error paths in the isochronous endpoint enqueue function
      also fail to free it.  xhci_queue_isoc_tx_prepare() doesn't free urb_priv
      if prepare_ring() indicates there is not enough room for all the
      isochronous TDs in this URB.  If individual isochronous TDs fail to be
      queued (perhaps due to an endpoint state change), urb_priv is also leaked.
      
      This argues that the freeing of urb_priv should be done in the function
      that allocated it, xhci_urb_enqueue.
      
      This patch looks rather ugly, but refactoring the code will have to wait
      because this patch needs to be backported to stable kernels.
      
      This patch should be backported to kernels as old as 2.6.36.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Andiry Xu <andiry.xu@amd.com>
      Cc: stable@kernel.org
      d13565c1
  8. 18 6月, 2011 2 次提交
    • S
      xhci: Always set urb->status to zero for isoc endpoints. · b3df3f9c
      Sarah Sharp 提交于
      When the xHCI driver encounters a Missed Service Interval event for an
      isochronous endpoint ring, it means the host controller skipped over
      one or more isochronous TDs.  For TD that is skipped, skip_isoc_td() is
      called.  This sets the frame descriptor status to -EXDEV, and also sets
      the value stored in the int pointed to by status to -EXDEV.
      
      If the isochronous TD happens to be the last TD in an URB,
      handle_tx_event() will use the status variable to give back the URB to
      the USB core.  That means drivers will see urb->status as -EXDEV.
      
      It turns out that EHCI, UHCI, and OHCI always set urb->status to zero for
      an isochronous urb, regardless of what the frame status is.  See
      itd_complete() in ehci-sched.c:
      
                      } else {
                              /* URB was too late */
                              desc->status = -EXDEV;
                      }
              }
      
              /* handle completion now? */
              if (likely ((urb_index + 1) != urb->number_of_packets))
                      goto done;
      
              /* ASSERT: it's really the last itd for this urb
              list_for_each_entry (itd, &stream->td_list, itd_list)
                      BUG_ON (itd->urb == urb);
               */
      
              /* give urb back to the driver; completion often (re)submits */
              dev = urb->dev;
              ehci_urb_done(ehci, urb, 0);
      
      ehci_urb_done() completes the URB with the status of the third argument, which
      is always zero in this case.
      
      It turns out that many USB webcam drivers, such as uvcvideo, cannot
      handle urb->status set to a non-zero value.  They will not resubmit
      their isochronous URBs in that case, and userspace will see a frozen
      video.
      
      Change the xHCI driver to be consistent with the EHCI and UHCI driver,
      and always set urb->status to 0 for isochronous URBs.
      
      This patch should be backported to kernels as old as 2.6.36
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: "Xu, Andiry" <Andiry.Xu@amd.com>
      Cc: stable@kernel.org
      b3df3f9c
    • A
      xHCI 1.0: Incompatible Device Error · f6ba6fe2
      Alex He 提交于
      It is one new TRB Completion Code for the xHCI spec v1.0.
      Asserted if the xHC detects a problem with a device that does not allow it to
      be successfully accessed, e.g. due to a device compliance or compatibility
      problem. This error may be returned by any command or transfer, and is fatal
      as far as the Slot is concerned. Return -EPROTO by urb->status or frame->status
      of ISOC for transfer case. And return -ENODEV for configure endpoint command,
      evaluate context command and address device command if there is an incompatible
      Device Error. The error codes will be sent back to the USB core to decide how
      to do. It's unnecessary for other commands because after the three commands run
      successfully means that the device has been accepted.
      Signed-off-by: NAlex He <alex.he@amd.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      f6ba6fe2
  9. 16 6月, 2011 1 次提交
    • A
      xHCI 1.0: Force Stopped Event(FSE) · e1cf486d
      Alex He 提交于
      FSE shall occur on the TD natural boundary. The software ep_ring dequeue pointer
      exceed the hardware ep_ring dequeue pointer in these cases of Table-3. As a
      result, the event_trb(pointed by hardware dequeue pointer) of the FSE can't be
      found in the current TD(pointed by software dequeue pointer). What should we do
      is to figured out the FSE case and skip over it.
      Signed-off-by: NAlex He <alex.he@amd.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      e1cf486d
  10. 03 6月, 2011 1 次提交
  11. 02 6月, 2011 1 次提交
  12. 28 5月, 2011 2 次提交
    • S
      Intel xhci: Limit number of active endpoints to 64. · 2cf95c18
      Sarah Sharp 提交于
      The Panther Point chipset has an xHCI host controller that has a limit to
      the number of active endpoints it can handle.  Ideally, it would signal
      that it can't handle anymore endpoints by returning a Resource Error for
      the Configure Endpoint command, but they don't.  Instead it needs software
      to keep track of the number of active endpoints, across configure endpoint
      commands, reset device commands, disable slot commands, and address device
      commands.
      
      Add a new endpoint context counter, xhci_hcd->num_active_eps, and use it
      to track the number of endpoints the xHC has active.  This gets a little
      tricky, because commands to change the number of active endpoints can
      fail.  This patch adds a new xHCI quirk for these Intel hosts, and the new
      code should not have any effect on other xHCI host controllers.
      
      Fail a new device allocation if we don't have room for the new default
      control endpoint.  Use the endpoint ring pointers to determine what
      endpoints were active before a Reset Device command or a Disable Slot
      command, and drop those once the command completes.
      
      Fail a configure endpoint command if it would add too many new endpoints.
      We have to be a bit over zealous here, and only count the number of new
      endpoints to be added, without subtracting the number of dropped
      endpoints.  That's because a second configure endpoint command for a
      different device could sneak in before we know if the first command is
      completed.  If the first command dropped resources, the host controller
      fails the command for some reason, and we're nearing the limit of
      endpoints, we could end up oversubscribing the host.
      
      To fix this race condition, when evaluating whether a configure endpoint
      command will fix in our bandwidth budget, only add the new endpoints to
      xhci->num_active_eps, and don't subtract the dropped endpoints.  Ignore
      changed endpoints (ones that are dropped and then re-added), as that
      shouldn't effect the host's endpoint resources.  When the configure
      endpoint command completes, subtract off the dropped endpoints.
      
      This may mean some configuration changes may temporarily fail, but it's
      always better to under-subscribe than over-subscribe resources.
      
      (Originally my plan had been to push the resource allocation down into the
      ring allocation functions.  However, that would cause us to allocate
      unnecessary resources when endpoints were changed, because the xHCI driver
      allocates a new ring for the changed endpoint, and only deletes the old
      ring once the Configure Endpoint command succeeds.  A further complication
      would have been dealing with the per-device endpoint ring cache.)
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      2cf95c18
    • S
      Intel xhci: Ignore spurious successful event. · ad808333
      Sarah Sharp 提交于
      The xHCI host controller in the Panther Point chipset sometimes produces
      spurious events on the event ring.  If it receives a short packet, it
      first puts a Transfer Event with a short transfer completion code on the
      event ring.  Then it puts a Transfer Event with a successful completion
      code on the ring for the same TD.  The xHCI driver correctly processes the
      short transfer completion code, gives the URB back to the driver, and then
      prints a warning in dmesg about the spurious event.  These warning
      messages really fill up dmesg when an HD webcam is plugged into xHCI.
      
      This spurious successful event behavior isn't technically disallowed by
      the xHCI specification, so make the xHCI driver just ignore the spurious
      completion event.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      ad808333
  13. 26 5月, 2011 4 次提交
    • S
      xhci: STFU: Be quieter during URB submission and completion. · f444ff27
      Sarah Sharp 提交于
      Unsurprisingly, URBs get submitted and completed a lot in the xHCI
      driver.  If we have to print 10 lines of debug for every URB submitted
      or completed, then that can cause the whole system to stay in the
      interrupt handler too long, and can cause Missed Service completion
      codes for isochronous transfers.
      
      Cut down the debugging in the URB submission and completion paths:
       - Don't squawk about successful transfers, only unsuccessful ones.
       - Only print the number of bytes transferred if this was a short
         transfer.
       - Don't print the endpoint index for successful transfers (will add
         more debug to failed transfers to show endpoint index there later).
       - Stop printing MMIO writes.  This debugging shows up when the endpoint
         doorbell is rung a to start a transfer (basically for every URB).
       - Don't print out the ring enqueue and dequeue pointers
       - Stop printing when we're pointing to a link TRB.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      f444ff27
    • S
      xhci: STFU: Don't print event ring dequeue pointer. · 5153b7b3
      Sarah Sharp 提交于
      Stop printing out the event ring dequeue pointer and status register in
      the operational register set.  The host will report an OK status 99% of
      the time the interrupt handler is called, and usually when it's really
      hosed, a host controller won't even call the interrupt handler.  So the
      line is really useless.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      5153b7b3
    • S
      xhci: STFU: Remove function tracing. · 380032c3
      Sarah Sharp 提交于
      Remove unnecessary debugging from the xHCI driver.  We don't need to
      know what function we're calling or returning from.  Now I know how to
      use markup-oops.pl to de-mystify stack dumps of crashes.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      380032c3
    • S
      xhci: Clear stopped_td when Stop Endpoint command completes. · 0714a57c
      Sarah Sharp 提交于
      When an URB is cancelled, the xHCI driver issues a Stop Endpoint command
      so that it can manipulate the ring and remove the transfer.  The xHC
      hardware then places a transfer event with the completion code "Stopped"
      or "Stopped Invalid" to let the driver know what TD it was in the middle
      of processing.  This TD and TRB is stored in ep->stopped_td and
      ep->stopped_trb.  These pointers are also used in handling stalled
      endpoints.
      
      By design, the Stop Endpoint command can race with URB completion.  By
      the time the Stop Endpoint command is handled, the URBs to be cancelled
      may have been given back to the driver.  Unfortunately, the stopped_td
      and stopped_trb pointers were not getting cleared in this case.
      
      The USB core unconditionally tries to reset the toggle bits on any
      endpoints when a new alternate interface setting is installed.  When the
      xHCI driver saw that ep->stopped_td was still set from the Stop Endpoint
      command, xhci_reset_endpoint assumed the endpoint was actually stalled,
      and attempted to clean up the endpoint rings.  This would manifest
      itself in a failed Reset Endpoint command and failed Set TR dequeue
      Pointer command after a successful Configure Endpoint command.  It may
      have also been causing driver oops when the stopped_td was accessed.
      
      This patch should be backported to stable kernels since 2.6.31.  Before
      2.6.33, stopped_td was found in the xhci_endpoint_ring, not the
      xhci_virt_ep.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      0714a57c
  14. 12 5月, 2011 1 次提交
    • S
      xhci: Fix bug in control transfer cancellation. · 3abeca99
      Sarah Sharp 提交于
      When the xHCI driver attempts to cancel a transfer, it issues a Stop
      Endpoint command and waits for the host controller to indicate which TRB
      it was in the middle of processing.  The host will put an event TRB with
      completion code COMP_STOP on the event ring if it stops on a control
      transfer TRB (or other types of transfer TRBs).  The ring handling code
      is supposed to set ep->stopped_trb to the TRB that the host stopped on
      when this happens.
      
      Unfortunately, there is a long-standing bug in the control transfer
      completion code.  It doesn't actually check to see if COMP_STOP is set
      before attempting to process the transfer based on which part of the
      control TD completed.  So when we get an event on the data phase of the
      control TRB with COMP_STOP set, it thinks it's a normal completion of
      the transfer and doesn't set ep->stopped_td or ep->stopped_trb.
      
      When the ring handling code goes on to process the completion of the Stop
      Endpoint command, it sees that ep->stopped_trb is not a part of the TD
      it's trying to cancel.  It thinks the hardware has its enqueue pointer
      somewhere further up in the ring, and thinks it's safe to turn the control
      TRBs into no-op TRBs.  Since the hardware was in the middle of the control
      TRBs to be cancelled, the proper software behavior is to issue a Set TR
      dequeue pointer command.
      
      It turns out that the NEC host controllers can handle active TRBs being
      set to no-op TRBs after a stop endpoint command, but other host
      controllers have issues with this out-of-spec software behavior.  Fix this
      behavior.
      
      This patch should be backported to kernels as far back as 2.6.31, but it
      may be a bit challenging, since process_ctrl_td() was introduced in some
      refactoring done in 2.6.36, and some endian-safe patches added in 2.6.40
      that touch the same lines.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: stable@kernel.org
      3abeca99
  15. 10 5月, 2011 2 次提交
  16. 03 5月, 2011 7 次提交
    • S
      xhci 1.0: Set transfer burst last packet count field. · b61d378f
      Sarah Sharp 提交于
      The xHCI 1.0 specification defines a new isochronous TRB field, called
      transfer burst last packet count (TBLPC).  This field defines the number
      of packets in the last "burst" of packets in a TD.  Only SuperSpeed
      endpoints can handle more than one burst, so this is set to the number for
      packets in a TD for all non-SuperSpeed devices (minus one, since the field
      is zero based).
      
      This patch should have no effect on host controllers that don't advertise
      the xHCI 1.0 (0x100) version number in their hci_version field.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      b61d378f
    • S
      xhci 1.0: Set transfer burst count field. · 5cd43e33
      Sarah Sharp 提交于
      The xHCI 1.0 specification adds a new field to the fourth dword in an
      isochronous TRB: the transfer burst count (TBC).  This field is only
      non-zero for SuperSpeed devices.  Each SS endpoint sets the bMaxBurst
      field in the SuperSpeed endpoint companion descriptor, which indicates how
      many max-packet-sized "bursts" it can handle in one service interval.  The
      device driver may choose to burst less max packet sized chunks each
      service interval (which is defined by one TD).  The xHCI driver indicates
      to the host controller how many bursts it needs to schedule through the
      transfer burst count field.
      
      This patch will only effect xHCI hosts that advertise 1.0 support (0x100)
      in the HCI version field of their capabilities register.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      5cd43e33
    • S
      xhci 1.0: Update TD size field format. · 4da6e6f2
      Sarah Sharp 提交于
      The xHCI 1.0 specification changes the format of the TD size field in
      Normal and Isochronous TRBs.  The field in control TRBs is still set to
      reserved zero.  Instead of representing the number of bytes left to
      transfer in the TD (including the current TRB's buffer), it now represents
      the number of packets left to transfer (*not* including this TRB).
      
      See section 4.11.2.4 of the xHCI 1.0 specification for details.  The math
      is basically copied straight from there.
      
      Create a new function, xhci_v1_0_td_remainder(), that should be called for
      all xHCI 1.0 host controllers.  The field location and maximum value is
      still the same, so reuse the old function, xhci_td_remainder(), to handle
      the bit shifting.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      4da6e6f2
    • S
      xhci 1.0: Only interrupt on short packet for IN EPs. · af8b9e63
      Sarah Sharp 提交于
      It doesn't make sense to set the interrupt on short packet (TRB_ISP) flag
      for TRBs queued to endpoints that only receive packets from the host
      controller (i.e. OUT endpoints).  Packets can only be short when they are
      sent from a USB device.  Plus, the xHCI 1.0 specification forbids setting
      the flag for anything but IN endpoints.
      
      While we're at it, remove some of my snide remarks about the inefficiency
      of event data TRBs.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      af8b9e63
    • M
      xhci: Remove recursive call to xhci_handle_event · 9dee9a21
      Matt Evans 提交于
      Make the caller loop while there are events to handle, instead.
      Signed-off-by: NMatt Evans <matt@ozlabs.org>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      9dee9a21
    • M
      xhci: Add rmb() between reading event validity & event data access. · 92a3da41
      Matt Evans 提交于
      On weakly-ordered systems, the reading of an event's content must occur
      after reading the event's validity.
      Signed-off-by: NMatt Evans <matt@ozlabs.org>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      92a3da41
    • M
      xhci: Make xHCI driver endian-safe · 28ccd296
      Matt Evans 提交于
      This patch changes the struct members defining access to xHCI device-visible
      memory to use __le32/__le64 where appropriate, and then adds swaps where
      required.  Checked with sparse that all accesses are correct.
      
      MMIO accesses use readl/writel so already are performed LE, but prototypes
      now reflect this with __le*.
      
      There were a couple of (debug) instances of DMA pointers being truncated to
      32bits which have been fixed too.
      Signed-off-by: NMatt Evans <matt@ozlabs.org>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      28ccd296
  17. 14 4月, 2011 5 次提交
    • A
      xHCI: Implement AMD PLL quirk · c41136b0
      Andiry Xu 提交于
      This patch disable the optional PM feature inside the Hudson3 platform under
      the following conditions:
      
      1. If an isochronous device is connected to xHCI port and is active;
      2. Optional PM feature that powers down the internal Bus PLL when the link is
         in low power state is enabled.
      
      The PM feature needs to be disabled to eliminate PLL startup delays when the
      link comes out of low power state. The performance of DMA data transfer could
      be impacted if system delay were encountered and in addition to the PLL start
      up delays. Disabling the PM would leave room for unpredictable system delays
      in order to guarantee uninterrupted data transfer to isochronous audio or
      video stream devices that require time sensitive information. If data in an
      audio/video stream was interrupted then erratic audio or video performance
      may be encountered.
      
      AMD PLL quirk is already implemented in OHCI/EHCI driver. After moving the
      quirk code to pci-quirks.c and export them, xHCI driver can call it directly
      without having the quirk implementation in itself.
      Signed-off-by: NAndiry Xu <andiry.xu@amd.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      c41136b0
    • S
      xhci: Fix NULL pointer deref in handle_port_status() · 386139d7
      Sarah Sharp 提交于
      When we get a port status change event, we need to figure out what type of
      port it came from: a USB 3.0 port, or a USB 2.0/1.1 port.  We can't know
      which usb_hcd to use until that point, so hcd will be NULL for part of the
      function.  Unfortunately, if any of the sanity checks fail, we'll jump to
      the cleanup label before hcd is set to a valid pointer, and then we'll
      attempt to tell the USB core to kick the hcd, which is NULL.
      
      Skip kicking the roothub if the sanity checks fail.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      386139d7
    • D
      USB: xhci: simplify logic of skipping missed isoc TDs · 926008c9
      Dmitry Torokhov 提交于
      The logic of the handling Missed Service Error Events was pretty
      confusing as we were checking the same condition several times.
      In addition, it caused compiler warning since the compiler could
      not figure out that event_trb is actually unused in case we are
      skipping current TD.
      
      Fix that by rearranging "skip" condition checks, and factor out
      skip_isoc_td() so that it is called explicitly.
      Signed-off-by: NDmitry Torokhov <dtor@vmware.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      926008c9
    • D
      USB: xhci - remove excessive 'inline' markings · 575688e1
      Dmitry Torokhov 提交于
      Remove 'inline' markings from file-local functions and let compiler
      do its job and inline what makes sense for given architecture.
      Signed-off-by: NDmitry Torokhov <dtor@vmware.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      575688e1
    • D
      USB: xhci: unsigned char never equals -1 · 22e04870
      Dan Carpenter 提交于
      There were some places that compared port_speed == -1 where port_speed
      is a u8.  This doesn't work unless we cast the -1 to u8.  Some places
      did it correctly.
      
      Instead of using -1 directly, I've created a DUPLICATE_ENTRY define
      which does the cast and is more descriptive as well.
      Signed-off-by: NDan Carpenter <error27@gmail.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      22e04870
  18. 14 3月, 2011 2 次提交
    • S
      xhci: Clean up cycle bit math used during stalls. · ba0a4d9a
      Sarah Sharp 提交于
      Use XOR to invert the cycle bit, instead of a more complicated
      calculation.  Eliminate a check for the link TRB type in find_trb_seg().
      We know that there will always be a link TRB at the end of a segment, so
      xhci_segment->trbs[TRBS_PER_SEGMENT - 1] will always have a link TRB type.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Tested-by: NTakashi Iwai <tiwai@suse.de>
      ba0a4d9a
    • S
      xhci: Fix cycle bit calculation during stall handling. · 01a1fdb9
      Sarah Sharp 提交于
      When an endpoint stalls, we need to update the xHCI host's internal
      dequeue pointer to move it past the stalled transfer.  This includes
      updating the cycle bit (TRB ownership bit) if we have moved the dequeue
      pointer past a link TRB with the toggle cycle bit set.
      
      When we're trying to find the new dequeue segment, find_trb_seg() is
      supposed to keep track of whether we've passed any link TRBs with the
      toggle cycle bit set.  However, this while loop's body
      
      	while (cur_seg->trbs > trb ||
      			&cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
      
      Will never get executed if the ring only contains one segment.
      find_trb_seg() will return immediately, without updating the new cycle
      bit.  Since find_trb_seg() has no idea where in the segment the TD that
      stalled was, make the caller, xhci_find_new_dequeue_state(), check for
      this special case and update the cycle bit accordingly.
      
      This patch should be queued to kernels all the way back to 2.6.31.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Tested-by: NTakashi Iwai <tiwai@suse.de>
      Cc: stable@kernel.org
      01a1fdb9