1. 01 5月, 2010 1 次提交
    • S
      USB: xhci: properly set endpoint context fields for periodic eps. · 9238f25d
      Sarah Sharp 提交于
      For periodic endpoints, we must let the xHCI hardware know the maximum
      payload an endpoint can transfer in one service interval.  The xHCI
      specification refers to this as the Maximum Endpoint Service Interval Time
      Payload (Max ESIT Payload).  This is used by the hardware for bandwidth
      management and scheduling of packets.
      
      For SuperSpeed endpoints, the maximum is calculated by multiplying the max
      packet size by the number of bursts and the number of opportunities to
      transfer within a service interval (the Mult field of the SuperSpeed
      Endpoint companion descriptor).  Devices advertise this in the
      wBytesPerInterval field of their SuperSpeed Endpoint Companion Descriptor.
      
      For high speed devices, this is taken by multiplying the max packet size by the
      "number of additional transaction opportunities per microframe" (the high
      bits of the wMaxPacketSize field in the endpoint descriptor).
      
      For FS/LS devices, this is just the max packet size.
      
      The other thing we must set in the endpoint context is the Average TRB
      Length.  This is supposed to be the average of the total bytes in the
      transfer descriptor (TD), divided by the number of transfer request blocks
      (TRBs) it takes to describe the TD.  This gives the host controller an
      indication of whether the driver will be enqueuing a scatter gather list
      with many entries comprised of small buffers, or one contiguous buffer.
      
      It also takes into account the number of extra TRBs you need for every TD.
      This includes No-op TRBs and Link TRBs used to link ring segments
      together.  Some drivers may choose to chain an Event Data TRB on the end
      of every TD, thus increasing the average number of TRBs per TD.  The Linux
      xHCI driver does not use Event Data TRBs.
      
      In theory, if there was an API to allow drivers to state what their
      bandwidth requirements are, we could set this field accurately.  For now,
      we set it to the same number as the Max ESIT payload.
      
      The Average TRB Length should also be set for bulk and control endpoints,
      but I have no idea how to guess what it should be.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      
      9238f25d
  2. 03 3月, 2010 6 次提交
  3. 12 12月, 2009 6 次提交
    • S
      USB: xhci: Make reverting an alt setting "unfailable". · 74f9fe21
      Sarah Sharp 提交于
      When a driver wants to switch to a different alternate setting for an
      interface, the USB core will (soon) check whether there is enough
      bandwidth.  Once the new alternate setting is installed in the xHCI
      hardware, the USB core will send a USB_REQ_SET_INTERFACE control
      message.  That can fail in various ways, and the USB core needs to be
      able to reinstate the old alternate setting.
      
      With the old code, reinstating the old alt setting could fail if the
      there's not enough memory to allocate new endpoint rings.  Keep
      around a cache of (at most 31) endpoint rings for this case.  When we
      successfully switch the xHCI hardware to the new alt setting, the old
      alt setting's rings will be stored in the cache.  Therefore we'll
      always have enough rings to satisfy a conversion back to a previous
      device setting.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      74f9fe21
    • S
      USB: xhci: Set transfer descriptor size field correctly. · 04dd950d
      Sarah Sharp 提交于
      The transfer descriptor (TD) is a series of transfer request buffers
      (TRBs) that describe the buffer pointer, length, and other
      characteristics.  The xHCI controllers want to know an estimate of how
      long the TD is, for caching reasons.  In each TRB, there is a "TD size"
      field that provides a rough estimate of the remaining buffers to be
      transmitted, including the buffer pointed to by that TRB.
      
      The TD size is 5 bits long, and contains the remaining size in bytes,
      right shifted by 10 bits.  So a remaining TD size less than 1024 would get
      a zero in the TD size field, and a remaining size greater than 32767 would
      get 31 in the field.
      
      This patches fixes a bug in the TD_REMAINDER macro that is triggered when
      the URB has a scatter gather list with a size bigger than 32767 bytes.
      Not all host controllers pay attention to the TD size field, so the bug
      will not appear on all USB 3.0 hosts.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      04dd950d
    • S
      USB: xhci: Add tests for TRB address translation. · 6648f29d
      Sarah Sharp 提交于
      It's not surprising that the transfer request buffer (TRB) physical to
      virtual address translation function has bugs in it, since I wrote most of
      it at 4am last October.  Add a test suite to check the TRB math.  This
      runs at memory initialization time, and causes the driver to fail to load
      if the TRB math fails.
      
      Please excuse the excessively long lines in the test vectors; they can't
      really be made shorter and still be readable.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      6648f29d
    • S
      USB: xhci: Add watchdog timer for URB cancellation. · 6f5165cf
      Sarah Sharp 提交于
      In order to giveback a canceled URB, we must ensure that the xHCI
      hardware will not access the buffer in an URB.  We can't modify the
      buffer pointers on endpoint rings without issuing and waiting for a stop
      endpoint command.  Since URBs can be canceled in interrupt context, we
      can't wait on that command.  The old code trusted that the host
      controller would respond to the command, and would giveback the URBs in
      the event handler.  If the hardware never responds to the stop endpoint
      command, the URBs will never be completed, and we might hang the USB
      subsystem.
      
      Implement a watchdog timer that is spawned whenever a stop endpoint
      command is queued.  If a stop endpoint command event is found on the
      event ring during an interrupt, we need to stop the watchdog timer with
      del_timer().  Since del_timer() can fail if the timer is running and
      waiting on the xHCI lock, we need a way to signal to the timer that
      everything is fine and it should exit.  If we simply clear
      EP_HALT_PENDING, a new stop endpoint command could sneak in and set it
      before the watchdog timer can grab the lock.
      
      Instead we use a combination of the EP_HALT_PENDING flag and a counter
      for the number of pending stop endpoint commands
      (xhci_virt_ep->stop_cmds_pending).  If we need to cancel the watchdog
      timer and del_timer() succeeds, we decrement the number of pending stop
      endpoint commands.  If del_timer() fails, we leave the number of pending
      stop endpoint commands alone.  In either case, we clear the
      EP_HALT_PENDING flag.
      
      The timer will decrement the number of pending stop endpoint commands
      once it obtains the lock.  If the timer is the tail end of the last stop
      endpoint command (xhci_virt_ep->stop_cmds_pending == 0), and the
      endpoint's command is still pending (EP_HALT_PENDING is set), we assume
      the host is dying.  The watchdog timer will set XHCI_STATE_DYING, try to
      halt the xHCI host, and give back all pending URBs.
      
      Various other places in the driver need to check whether the xHCI host
      is dying.  If the interrupt handler ever notices, it should immediately
      stop processing events.  The URB enqueue function should also return
      -ESHUTDOWN.  The URB dequeue function should simply return the value
      of usb_hcd_check_unlink_urb() and the watchdog timer will take care of
      giving the URB back.  When a device is disconnected, the xHCI hardware
      structures should be freed without issuing a disable slot command (since
      the hardware probably won't respond to it anyway).  The debugging
      polling loop should stop polling if the host is dying.
      
      When a device is disconnected, any pending watchdog timers are killed
      with del_timer_sync().  It must be synchronous so that the watchdog
      timer doesn't attempt to access the freed endpoint structures.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      6f5165cf
    • S
      USB: xhci: Re-purpose xhci_quiesce(). · 4f0f0bae
      Sarah Sharp 提交于
      xhci_quiesce() is basically a no-op right now.  It's only called if
      HC_IS_RUNNING() is true, and the body of the function consists of a
      BUG_ON if HC_IS_RUNNING() is false.  For the new xHCI watchdog timer, we
      need a new function that clears the xHCI running bit in the command
      register, but doesn't wait for the halt status to show up in the status
      register.  Re-purpose xhci_quiesce() to do that.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      4f0f0bae
    • S
      USB: xhci: Handle URB cancel, complete and resubmit race. · 678539cf
      Sarah Sharp 提交于
      In the old code, there was a race condition between the stop endpoint
      command and the URB submission process.  When the stop endpoint command is
      handled by the event handler, the endpoint ring is assumed to be stopped.
      When a stop endpoint command is queued, URB submissions are to not ring
      the doorbell.  The old code would check the number of pending URBs to be
      canceled, and would not ring the doorbell if it was non-zero.
      
      However, the following race condition could occur with the old code:
      
      1. Cancel an URB, add it to the list of URBs to be canceled, queue the stop
         endpoint command, and increment ep->cancels_pending to 1.
      2. The URB finishes on the HW, and an event is enqueued to the event ring
         (at the same time as 1).
      3. The stop endpoint command finishes, and the endpoint is halted.  An
         event is queued to the event ring.
      4. The event handler sees the finished URB, notices it was to be
         canceled, decrements ep->cancels_pending to 0, and removes it from the to
         be canceled list.
      5. The event handler drops the lock and gives back the URB.  The
         completion handler requeues the URB (or a different driver enqueues a new
         URB).  This causes the endpoint's doorbell to be rung, since
         ep->cancels_pending == 0.  The endpoint is now running.
      6. A second URB is canceled, and it's added to the canceled list.
         Since ep->cancels_pending == 0, a new stop endpoint command is queued, and
         ep->cancels_pending is incremented to 1.
      7. The event handler then sees the completed stop endpoint command.  The
         handler assumes the endpoint is stopped, but it isn't.  It attempts to
         move the dequeue pointer or change TDs to cancel the second URB, while the
         hardware is actively accessing the endpoint ring.
      
      To eliminate this race condition, a new endpoint state bit is introduced,
      EP_HALT_PENDING.  When this bit is set, a stop endpoint command has been
      queued, and the command handler has not begun to process the URB
      cancellation list yet.  The endpoint doorbell should not be rung when this
      is set.  Set this when a stop endpoint command is queued, clear it when
      the handler for that command runs, and check if it's set before ringing a
      doorbell.  ep->cancels_pending is eliminated, because it is no longer
      used.
      
      Make sure to ring the doorbell for an endpoint when the stop endpoint
      command handler runs, even if the canceled URB list is empty.  All
      canceled URBs could have completed and new URBs could have been enqueued
      without the doorbell being rung before the command was handled.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      678539cf
  4. 23 9月, 2009 9 次提交
    • S
      USB: xhci: Support USB hubs. · ac1c1b7f
      Sarah Sharp 提交于
      For a USB hub to work under an xHCI host controller, the xHC's internal
      scheduler must be made aware of the hub's characteristics.  Add an xHCI
      hook that the USB core will call after it fetches the hub descriptor.
      This hook will add hub information to the slot context for that device,
      including whether it has multiple TTs or a single TT, the number of ports
      on the hub, and TT think time.
      
      Setting up the slot context for the device is different for 0.95 and 0.96
      xHCI host controllers.
      
      Some of the slot context reserved fields in the 0.95 specification were
      changed into hub fields in the 0.96 specification.  Don't set the TT think
      time or number of ports for a hub if we're dealing with a 0.95-compliant
      xHCI host controller.
      
      The 0.95 xHCI specification says that to modify the hub flag, we need to
      issue an evaluate context command.  The 0.96 specification says that flag
      can be set with a configure endpoint command.  Issue the correct command
      based on the version reported by the hardware.
      
      This patch does not add support for multi-TT hubs.  Multi-TT hubs expose
      a single TT on alt setting 0, and multi-TT on alt setting 1.  The xHCI
      driver can't handle setting alternate interfaces yet.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ac1c1b7f
    • S
      USB: xhci: Change how xHCI commands are handled. · 913a8a34
      Sarah Sharp 提交于
      Some commands to the xHCI hardware cannot be allowed to fail due to out of
      memory issues or the command ring being full.
      
      Add a way to reserve a TRB on the command ring, and make all command
      queueing functions indicate whether they are using a reserved TRB.
      
      Add a way to pre-allocate all the memory a command might need.  A command
      needs an input context, a variable to store the status, and (optionally) a
      completion for the caller to wait on.  Change all code that assumes the
      input device context, status, and completion for a command is stored in
      the xhci virtual USB device structure (xhci_virt_device).
      
      Store pending completions in a FIFO in xhci_virt_device.  Make the event
      handler for a configure endpoint command check to see whether a pending
      command in the list has completed.  We need to use separate input device
      contexts for some configure endpoint commands, since multiple drivers can
      submit requests at the same time that require a configure endpoint
      command.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      913a8a34
    • S
      USB: xhci: Endpoint representation refactoring. · 63a0d9ab
      Sarah Sharp 提交于
      The xhci_ring structure contained information that is really related to an
      endpoint, not a ring.  This will cause problems later when endpoint
      streams are supported and there are multiple rings per endpoint.
      
      Move the endpoint state and cancellation information into a new virtual
      endpoint structure, xhci_virt_ep.  The list of TRBs to be cancelled should
      be per endpoint, not per ring, for easy access.  There can be only one TRB
      that the endpoint stopped on after a stop endpoint command (even with
      streams enabled); move the stopped TRB information into the new virtual
      endpoint structure.  Also move the 31 endpoint rings and temporary ring
      storage from the virtual device structure (xhci_virt_device) into the
      virtual endpoint structure (xhci_virt_ep).
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      63a0d9ab
    • S
      USB: xhci: Support interrupt transfers. · 624defa1
      Sarah Sharp 提交于
      Interrupt transfers are submitted to the xHCI hardware using the same TRB
      type as bulk transfers.  Re-use the bulk transfer enqueueing code to
      enqueue interrupt transfers.
      
      Interrupt transfers are a bit different than bulk transfers.  When the
      interrupt endpoint is to be serviced, the xHC will consume (at most) one
      TD.  A TD (comprised of sg list entries) can take several service
      intervals to transmit.  The important thing for device drivers to note is
      that if they use the scatter gather interface to submit interrupt
      requests, they will not get data sent from two different scatter gather
      lists in the same service interval.
      
      For now, the xHCI driver will use the service interval from the endpoint's
      descriptor (bInterval).  Drivers will need a hook to poll at a more
      frequent interval.  Set urb->interval to the interval that the xHCI
      hardware will use.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      624defa1
    • S
      USB: xhci: Add quirk for Fresco Logic xHCI hardware. · ac9d8fe7
      Sarah Sharp 提交于
      This Fresco Logic xHCI host controller chip revision puts bad data into
      the output endpoint context after a Reset Endpoint command.  It needs a
      Configure Endpoint command (instead of a Set TR Dequeue Pointer command)
      after the reset endpoint command.
      
      Set up the input context before issuing the Reset Endpoint command so we
      don't copy bad data from the output endpoint context.  The HW also can't
      handle two commands queued at once, so submit the TRB for the Configure
      Endpoint command in the event handler for the Reset Endpoint command.
      
      Devices that stall on control endpoints before a configuration is selected
      will not work under this Fresco Logic xHCI host controller revision.
      
      This patch is for prototype hardware that will be given to other companies
      for evaluation purposes only, and should not reach consumer hands.  Fresco
      Logic's next chip rev should have this bug fixed.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ac9d8fe7
    • S
      USB: xhci: Handle stalled control endpoints. · 82d1009f
      Sarah Sharp 提交于
      When a control endpoint stalls, the next control transfer will clear the
      stall.  The USB core doesn't call down to the host controller driver's
      endpoint_reset() method when control endpoints stall, so the xHCI driver
      has to do all its stall handling for internal state in its interrupt handler.
      
      When the host stalls on a control endpoint, it may stop on the data phase
      or status phase of the control transfer.  Like other stalled endpoints,
      the xHCI driver needs to queue a Reset Endpoint command and move the
      hardware's control endpoint ring dequeue pointer past the failed control
      transfer (with a Set TR Dequeue Pointer or a Configure Endpoint command).
      
      Since the USB core doesn't call usb_hcd_reset_endpoint() for control
      endpoints, we need to do this in interrupt context when we get notified of
      the stalled transfer.  URBs may be queued to the hardware before these two
      commands complete.  The endpoint queue will be restarted once both
      commands complete.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      82d1009f
    • S
      USB: xhci: Support full speed devices. · 2d3f1fac
      Sarah Sharp 提交于
      Full speed devices have varying max packet sizes (8, 16, 32, or 64) for
      endpoint 0.  The xHCI hardware needs to know the real max packet size
      that the USB core discovers after it fetches the first 8 bytes of the
      device descriptor.
      
      In order to fix this without adding a new hook to host controller drivers,
      the xHCI driver looks for an updated max packet size for control
      endpoints.  If it finds an updated size, it issues an evaluate context
      command and waits for that command to finish.  This should only happen in
      the initialization and device descriptor fetching steps in the khubd
      thread, so blocking should be fine.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      2d3f1fac
    • S
      USB: xhci: Configure endpoint code refactoring. · f2217e8e
      Sarah Sharp 提交于
      Refactor out the code issue, wait for, and parse the event completion code
      for a configure endpoint command.  Modify it to support the evaluate
      context command, which has a very similar submission process.  Add
      functions to copy parts of the output context into the input context
      (which will be used in the evaluate context command).
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f2217e8e
    • S
      USB: xhci: Work around for chain bit in link TRBs. · b0567b3f
      Sarah Sharp 提交于
      Different sections of the xHCI 0.95 specification had opposing
      requirements for the chain bit in a link transaction request buffer (TRB).
      The chain bit is used to designate that adjacent TRBs are all part of the
      same scatter gather list that should be sent to the device.  Link TRBs can
      be in the middle, or at the beginning or end of these chained TRBs.
      
      Sections 4.11.5.1 and 6.4.4.1 both stated the link TRB "shall have the
      chain bit set to 1", meaning it is always chained to the next TRB.
      However, section 4.6.9 on the stop endpoint command has specific cases for
      what the hardware must do for a link TRB with the chain bit set to 0.  The
      0.96 specification errata later cleared up this issue by fixing the
      4.11.5.1 and 6.4.4.1 sections to state that a link TRB can have the chain
      bit set to 1 or 0.
      
      The problem is that the xHCI cancellation code depends on the chain bit of
      the link TRB being cleared when it's at the end of a TD, and some 0.95
      xHCI hardware simply stops processing the ring when it encounters a link
      TRB with the chain bit cleared.
      
      Allow users who are testing 0.95 xHCI prototypes to set a module parameter
      (link_quirk) to turn on this link TRB work around.  Cancellation may not
      work if the ring is stopped exactly on a link TRB with chain bit set, but
      cancellation should be a relatively uncommon case.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Cc: stable <stable@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b0567b3f
  5. 21 9月, 2009 1 次提交
  6. 29 7月, 2009 7 次提交
    • S
      USB: xhci: Stall handling bug fixes. · c92bcfa7
      Sarah Sharp 提交于
      Correct the xHCI code to handle stalls on USB endpoints.  We need to move
      the endpoint ring's dequeue pointer past the stalled transfer, or the HW
      will try to restart the transfer the next time the doorbell is rung.
      
      Don't attempt to clear a halt on an endpoint if we haven't seen a stalled
      transfer for it.  The USB core will attempt to clear a halt on all
      endpoints when it selects a new configuration.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      c92bcfa7
    • J
      USB: xhci: Support for 64-byte contexts · d115b048
      John Youn 提交于
      Adds support for controllers that use 64-byte contexts.  The following context
      data structures are affected by this: Device, Input, Input Control, Endpoint,
      and Slot.  To accommodate the use of either 32 or 64-byte contexts, a Device or
      Input context can only be accessed through functions which look-up and return
      pointers to their contained contexts.
      Signed-off-by: NJohn Youn <johnyoun@synopsys.com>
      Acked-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d115b048
    • S
      USB: xhci: Always align output device contexts to 64 bytes. · 28c2d2ef
      Sarah Sharp 提交于
      Make sure the xHCI output device context is 64-byte aligned.  Previous
      code was using the same structure for both the output device context and
      the input control context.  Since the structure had 32 bytes of flags
      before the device context, the output device context wouldn't be 64-byte
      aligned.  Define a new structure to use for the output device context and
      clean up the debugging for these two structures.
      
      The copy of the device context in the input control context does *not*
      need to be 64-byte aligned.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      28c2d2ef
    • J
      USB: xhci: Scratchpad buffer allocation · 254c80a3
      John Youn 提交于
      Allocates and initializes the scratchpad buffer array (XHCI 4.20).  This is an
      array of 64-bit DMA addresses to scratch pages that the controller may use
      during operation.  The number of pages is specified in the "Max Scratchpad
      Buffers" field of HCSPARAMS2.  The DMA address of this array is written into
      slot 0 of the DCBAA.
      Signed-off-by: NJohn Youn <johnyoun@synopsys.com>
      Acked-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      254c80a3
    • S
      USB: xhci: Make debugging more verbose. · 66e49d87
      Sarah Sharp 提交于
      Add more debugging to the irq handler, slot context initialization, ring
      operations, URB cancellation, and MMIO writes.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      66e49d87
    • S
      USB: xhci: Represent 64-bit addresses with one u64. · 8e595a5d
      Sarah Sharp 提交于
      There are several xHCI data structures that use two 32-bit fields to
      represent a 64-bit address.  Since some architectures don't support 64-bit
      PCI writes, the fields need to be written in two 32-bit writes.  The xHCI
      specification says that if a platform is incapable of generating 64-bit
      writes, software must write the low 32-bits first, then the high 32-bits.
      Hardware that supports 64-bit addressing will wait for the high 32-bit
      write before reading the revised value, and hardware that only supports
      32-bit writes will ignore the high 32-bit write.
      
      Previous xHCI code represented 64-bit addresses with two u32 values.  This
      lead to buggy code that would write the 32-bits in the wrong order, or
      forget to write the upper 32-bits.  Change the two u32s to one u64 and
      create a function call to write all 64-bit addresses in the proper order.
      This new function could be modified in the future if all platforms support
      64-bit writes.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      8e595a5d
    • S
      USB: xhci: Deal with stalled endpoints. · a1587d97
      Sarah Sharp 提交于
      When an endpoint on a device under an xHCI host controller stalls, the
      host controller driver must let the hardware know that the USB core has
      successfully cleared the halt condition.  The HCD submits a Reset Endpoint
      Command, which will clear the toggle bit for USB 2.0 devices, and set the
      sequence number to zero for USB 3.0 devices.
      
      The xHCI urb_enqueue will accept new URBs while the endpoint is halted,
      and will queue them to the hardware rings.  However, the endpoint doorbell
      will not be rung until the Reset Endpoint Command completes.
      
      Don't queue a reset endpoint command for root hubs.  khubd clears halt
      conditions on the roothub during the initialization process, but the roothub
      isn't a real device, so the xHCI host controller doesn't need to know about the
      cleared halt.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      a1587d97
  7. 16 6月, 2009 10 次提交
    • S
      USB: xhci: Respect critical sections. · f88ba78d
      Sarah Sharp 提交于
      Narrow down time spent holding the xHCI spinlock so that it's only used to
      protect the xHCI rings, not as mutual exclusion.  Stop allocating memory
      while holding the spinlock and calling xhci_alloc_virt_device() and
      xhci_endpoint_init().
      
      The USB core should have locking in it to prevent device state to be
      manipulated by more than one kernel thread.  E.g. you can't free a device
      while you're in the middle of setting a new configuration.  So removing
      the locks from the sections where xhci_alloc_dev() and
      xhci_reset_bandwidth() touch xHCI's representation of the device should be
      OK.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f88ba78d
    • S
      USB: xhci: Remove packed attribute from structures. · 98441973
      Sarah Sharp 提交于
      The packed attribute allows gcc to muck with the alignment of data
      structures, which may lead to byte-wise writes that break atomicity of
      writes.  Packed should only be used when the compile may add undesired
      padding to the structure.  Each element of the structure will be aligned
      by C based on its size and the size of the elements around it.  E.g. a u64
      would be aligned on an 8 byte boundary, the next u32 would be aligned on a
      four byte boundary, etc.
      
      Since most of the xHCI structures contain only u32 bit values, removing
      the packed attribute for them should be harmless.  (A future patch will
      change some of the twin 32-bit address fields to one 64-bit field, but all
      those places have an even number of 32-bit fields before them, so the
      alignment should be correct.)  Add BUILD_BUG_ON statements to check that
      the compiler doesn't add padding to the data structures that have a
      hardware-defined layout.
      
      While we're modifying the registers, change the name of intr_reg to
      xhci_intr_reg to avoid global conflicts.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      98441973
    • S
      USB: xhci: Avoid global namespace pollution. · 23e3be11
      Sarah Sharp 提交于
      Make all globally visible functions start with xhci_ and mark functions as
      static if they're only called within the same C file.  Fix some long lines
      while we're at it.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      23e3be11
    • G
      USB: xhci: fix some compiler warnings in xhci.h · 045f123d
      Greg Kroah-Hartman 提交于
      This fixes the warning:
      drivers/usb/host/xhci.h:1083: warning: passing argument 1 of ‘xhci_to_hcd’ discards qualifiers from pointer target type
      drivers/usb/host/xhci.h:1083: warning: passing argument 1 of ‘xhci_to_hcd’ discards qualifiers from pointer target type
      Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
      Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      045f123d
    • S
      USB: xhci: use xhci_handle_event instead of handle_event · b7258a4a
      Stephen Rothwell 提交于
      The former is way to generic for a global symbol.
      
      Fixes this build error:
      
      drivers/usb/built-in.o: In function `.handle_event': (.text+0x67dd0): multiple definition of `.handle_event'
      drivers/pcmcia/built-in.o:(.text+0xcfcc): first defined here
      drivers/usb/built-in.o: In function `handle_event': (.opd+0x5bc8): multiple definition of `handle_event'
      drivers/pcmcia/built-in.o:(.opd+0xed0): first defined here
      Signed-off-by: NStephen Rothwell <sfr@canb.auug.org.au>
      Cc: Sarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b7258a4a
    • S
      USB: xhci: URB cancellation support. · ae636747
      Sarah Sharp 提交于
      Add URB cancellation support to the xHCI host controller driver.  This
      currently supports cancellation for endpoints that do not have streams
      enabled.
      
      An URB is represented by a number of Transaction Request Buffers (TRBs),
      that are chained together to make one (or more) Transaction Descriptors
      (TDs) on an endpoint ring.  The ring is comprised of contiguous segments,
      linked together with Link TRBs (which may or may not be chained into a TD).
      
      To cancel an URB, we must stop the endpoint ring, make the hardware skip
      over the TDs in the URB (either by turning them into No-op TDs, or by
      moving the hardware's ring dequeue pointer past the last TRB in the last
      TD), and then restart the ring.
      
      There are times when we must drop the xHCI lock during this process, like
      when we need to complete cancelled URBs.  We must ensure that additional
      URBs can be marked as cancelled, and that new URBs can be enqueued (since
      the URB completion handlers can do either).  The new endpoint ring
      variables cancels_pending and state (which can only be modified while
      holding the xHCI lock) ensure that future cancellation and enqueueing do
      not interrupt any pending cancellation code.
      
      To facilitate cancellation, we must keep track of the starting ring
      segment, first TRB, and last TRB for each URB.  We also need to keep track
      of the list of TDs that have been marked as cancelled, separate from the
      list of TDs that are queued for this endpoint.  The new variables and
      cancellation list are stored in the xhci_td structure.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      ae636747
    • S
      USB: xhci: Bulk transfer support · b10de142
      Sarah Sharp 提交于
      Allow device drivers to submit URBs to bulk endpoints on devices under an
      xHCI host controller.  Share code between the control and bulk enqueueing
      functions when it makes sense.
      
      To get the best performance out of bulk transfers, SuperSpeed devices must
      have the bMaxBurst size copied from their endpoint companion controller
      into the xHCI device context.  This allows the host controller to "burst"
      up to 16 packets before it has to wait for the device to acknowledge the
      first packet.
      
      The buffers in Transfer Request Blocks (TRBs) can cross page boundaries,
      but they cannot cross 64KB boundaries.  The buffer must be broken into
      multiple TRBs if a 64KB boundary is crossed.
      
      The sum of buffer lengths in all the TRBs in a Transfer Descriptor (TD)
      cannot exceed 64MB.  To work around this, the enqueueing code must enqueue
      multiple TDs.  The transfer event handler may incorrectly give back the
      URB in this case, if it gets a transfer event that points somewhere in the
      first TD.  FIXME later.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      b10de142
    • S
      USB: xhci: Bandwidth allocation support · f94e0186
      Sarah Sharp 提交于
      Since the xHCI host controller hardware (xHC) has an internal schedule, it
      needs a better representation of what devices are consuming bandwidth on
      the bus.  Each device is represented by a device context, with data about
      the device, endpoints, and pointers to each endpoint ring.
      
      We need to update the endpoint information for a device context before a
      new configuration or alternate interface setting is selected.  We setup an
      input device context with modified endpoint information and newly
      allocated endpoint rings, and then submit a Configure Endpoint Command to
      the hardware.
      
      The host controller can reject the new configuration if it exceeds the bus
      bandwidth, or the host controller doesn't have enough internal resources
      for the configuration.  If the command fails, we still have the older
      device context with the previous configuration.  If the command succeeds,
      we free the old endpoint rings.
      
      The root hub isn't a real device, so always say yes to any bandwidth
      changes for it.
      
      The USB core will enable, disable, and then enable endpoint 0 several
      times during the initialization sequence.  The device will always have an
      endpoint ring for endpoint 0 and bandwidth allocated for that, unless the
      device is disconnected or gets a SetAddress 0 request.  So we don't pay
      attention for when xhci_check_bandwidth() is called for a re-add of
      endpoint 0.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      f94e0186
    • S
      USB: xhci: Control transfer support. · d0e96f5a
      Sarah Sharp 提交于
      Allow device drivers to enqueue URBs to control endpoints on devices under
      an xHCI host controller.  Each control transfer is represented by a
      series of Transfer Descriptors (TDs) written to an endpoint ring.  There
      is one TD for the Setup phase, (optionally) one TD for the Data phase, and
      one TD for the Status phase.
      
      Enqueue these TDs onto the endpoint ring that represents the control
      endpoint.  The host controller hardware will return an event on the event
      ring that points to the (DMA) address of one of the TDs on the endpoint
      ring.  If the transfer was successful, the transfer event TRB will have a
      completion code of success, and it will point to the Status phase TD.
      Anything else is considered an error.
      
      This should work for control endpoints besides the default endpoint, but
      that hasn't been tested.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      d0e96f5a
    • S
      USB: xhci: Allocate and address USB devices · 3ffbba95
      Sarah Sharp 提交于
      xHCI needs to get a "Slot ID" from the host controller and allocate other
      data structures for every USB device.  Make usb_alloc_dev() and
      usb_release_dev() allocate and free these device structures.  After
      setting up the xHC device structures, usb_alloc_dev() must wait for the
      hardware to respond to an Enable Slot command.  usb_alloc_dev() fires off
      a Disable Slot command and does not wait for it to complete.
      
      When the USB core wants to choose an address for the device, the xHCI
      driver must issue a Set Address command and wait for an event for that
      command.
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      3ffbba95