1. 25 5月, 2020 10 次提交
    • T
      usb: dwc3: gadget: Handle stream transfers · 140ca4cf
      Thinh Nguyen 提交于
      Overview of stream transfer requirement:
       * A transfer will have a set of TRBs of the same stream ID.
       * A transfer is started with a stream ID in START_TRANSFER command.
       * A new stream will only start when the previous completes.
      
      Overview of stream events:
       * A "prime" from host indicates that its endpoints are active
         (buffers prepared and ready to receive/transmit data). The controller
         automatically initiates stream if it sees this.
       * A "NoStream" rejection event indicates that the host isn't ready.
         Host will put the endpoint back to idle state. Device may need to
         reinitiate the stream to start transfer again.
       * A Stream Found event means host accepted device initiated stream.
         Nothing needs to be done from driver.
      
      To initiate a stream, the driver will issue START_TRANSFER command with
      a stream ID. To reinitiate the stream, the driver must issue
      END_TRANSFER and restart the transfer with START_TRANSFER command with
      the same stream ID.
      
      This implementation handles device-initated streams (e.g. UASP driver).
      It also handles some hosts' quirky behavior where they only prime each
      endpoint once.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      140ca4cf
    • T
      usb: dwc3: gadget: Don't prepare beyond a transfer · aefe3d23
      Thinh Nguyen 提交于
      Don't prepare TRBs beyond a transfer. In DWC_usb32, its transfer burst
      capability may try to read and use TRBs beyond the active transfer. For
      other controllers, they don't process the next transfer TRBs until the
      current transfer is completed. Explicitly prevent preparing TRBs ahead
      for all controllers.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      aefe3d23
    • T
      usb: dwc3: gadget: Wait for transfer completion · e0d19563
      Thinh Nguyen 提交于
      If a transfer is in-progress, any new request should not kick off
      another transfer. The driver needs to wait for the current transfer to
      complete before starting off the next transfer. Introduce a new flag
      DWC3_EP_WAIT_TRANSFER_COMPLETE for this.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      e0d19563
    • T
      usb: dwc3: gadget: Handle XferComplete for streams · 3eaecd0c
      Thinh Nguyen 提交于
      In DWC3, to prepare TRBs for streams, all the TRBs of a transfer will
      use the same stream ID. To start a new stream, the driver needs to wait
      for the current transfer to complete or ended (by END_TRANFER command).
      As a result, inform the controller of the last TRB of a transfer so that
      it knows when a transfer completes and start a new transfer of a new
      stream.
      
      Even though the transfer completion handling can be applied for other
      non-isoc endpoints, only do it for streams due to its requirement.
      It's better to keep the controller's TRB cache full than waiting for
      transfer completion and starting a new transfer.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      3eaecd0c
    • T
      usb: dwc3: gadget: Enable XferComplete event · 548f8b31
      Thinh Nguyen 提交于
      To switch from one stream to another, this requires the driver to start
      a new transfer with a specific stream ID. For a transfer to complete,
      the driver needs to indicate the last TRB of a transfer, and it needs to
      enable XferComplete event to handle completed TRBs of a transfer. Let's
      enable this event only for stream capable endpoints.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      548f8b31
    • T
      usb: dwc3: gadget: Refactor TRB completion handler · 2e6e9e4b
      Thinh Nguyen 提交于
      To prepare for handling of XferComplete event, let's refactor and split
      up dwc3_gadget_endpoint_transfer_in_progress() to handle TRBs completion
      for different events. The handling of TRBs completion will be the same,
      but the status of XferComplete event is different than XferInProgress.
      No functional change in this commit.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      2e6e9e4b
    • T
      usb: dwc3: gadget: Check for in-progress END_TRANSFER · b6842d49
      Thinh Nguyen 提交于
      While handling TRBs completion, if a END_TRANSFER command isn't
      completed, don't kick new transfer or issue END_TRANSFER command.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      b6842d49
    • T
      usb: dwc3: Get MDWIDTH for DWC_usb32 · 4244ba02
      Thinh Nguyen 提交于
      DWC_usb32 supports MDWIDTH value larger than 255 and up to 1023. The
      field HWPARAMS6[9:8] stores the upper 2-bit values of the DWC_usb32's
      MDWIDTH. Check that parameter and properly get the MDWIDTH for
      DWC_usb32.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      4244ba02
    • T
      usb: dwc3: Add support for DWC_usb32 IP · 9af21dd6
      Thinh Nguyen 提交于
      Synopsys introduces a new controller DWC_usb32. It supports dual-lane
      and speed up to 20 Gbps, and the DWC3 driver will drive this controller.
      Currently the driver uses a single field dwc->revision to ID both
      DWC_usb3 and DWC_usb31 and their version number. This was sufficient for
      two IPs, but this method doesn't work with additional IPs. As a result,
      let's separate the dwc->revision field to 2 separate fields: ip and
      revision. The ip field now stores the ID of the controller's IP while
      the revision field stores the controller's version number.
      
      This new scheme enforces DWC3 to compare the revision within the same IP
      only. As a result, we must update all the revision check of the
      controller to check its corresponding IP.
      
      To help with this enforcement, we create a few macros to help with
      the common version checks:
      
      DWC3_IP_IS(IP)
      DWC3_VER_IS(IP, VERSION)
      DWC3_VER_IS_PRIOR(IP, VERSION)
      DWC3_VER_IS_WITHIN(IP, LOWER_VERSION, UPPER_VERSION)
      DWC3_VER_TYPE_IS_WITHIN(IP, VERSION,
      			LOWER_VERSION_TYPE,
      			UPPER_VERSION_TYPE)
      
      The DWC_usb32 controller operates using the same programming model and
      with very similar configurations as its previous controllers. Please
      note that the various IP and revision checks in this patch match the
      current checks for DWC_usb31 version 1.90a. Additional configurations
      that are unique to DWC_usb32 are applied separately.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      9af21dd6
    • T
      usb: dwc3: gadget: Continue to process pending requests · d9feef97
      Thinh Nguyen 提交于
      If there are still pending requests because no TRB was available,
      prepare more when started requests are completed.
      
      Introduce dwc3_gadget_ep_should_continue() to check for incomplete and
      pending requests to resume updating new TRBs to the controller's TRB
      cache.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      d9feef97
  2. 05 5月, 2020 8 次提交
  3. 17 4月, 2020 1 次提交
    • T
      usb: dwc3: gadget: Fix request completion check · 49e0590e
      Thinh Nguyen 提交于
      A request may not be completed because not all the TRBs are prepared for
      it. This happens when we run out of available TRBs. When some TRBs are
      completed, the driver needs to prepare the rest of the TRBs for the
      request. The check dwc3_gadget_ep_request_completed() shouldn't be
      checking the amount of data received but rather the number of pending
      TRBs. Revise this request completion check.
      
      Cc: stable@vger.kernel.org
      Fixes: e0c42ce5 ("usb: dwc3: gadget: simplify IOC handling")
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      49e0590e
  4. 16 4月, 2020 3 次提交
    • T
      usb: dwc3: gadget: Do link recovery for SS and SSP · d0550cd2
      Thinh Nguyen 提交于
      The controller always supports link recovery for device in SS and SSP.
      Remove the speed limit check. Also, when the device is in RESUME or
      RESET state, it means the controller received the resume/reset request.
      The driver must send the link recovery to acknowledge the request. They
      are valid states for the driver to send link recovery.
      
      Fixes: 72246da4 ("usb: Introduce DesignWare USB3 DRD Driver")
      Fixes: ee5cd41c ("usb: dwc3: Update speed checks for SuperSpeedPlus")
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      d0550cd2
    • T
      usb: dwc3: gadget: Properly set maxpacket limit · d94ea531
      Thinh Nguyen 提交于
      Currently the calculation of max packet size limit for IN endpoints is
      too restrictive. This prevents a matching of a capable hardware endpoint
      during configuration. Below is the minimum recommended HW configuration
      to support a particular endpoint setup from the databook:
      
      For OUT endpoints, the databook recommended the minimum RxFIFO size to
      be at least 3x MaxPacketSize + 3x setup packets size (8 bytes each) +
      clock crossing margin (16 bytes).
      
      For IN endpoints, the databook recommended the minimum TxFIFO size to be
      at least 3x MaxPacketSize for endpoints that support burst. If the
      endpoint doesn't support burst or when the device is operating in USB
      2.0 mode, a minimum TxFIFO size of 2x MaxPacketSize is recommended.
      
      Base on these recommendations, we can calculate the MaxPacketSize limit
      of each endpoint. This patch revises the IN endpoint MaxPacketSize limit
      and also sets the MaxPacketSize limit for OUT endpoints.
      
      Reference: Databook 3.30a section 3.2.2 and 3.2.3
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      d94ea531
    • T
      usb: dwc3: Fix GTXFIFOSIZ.TXFDEP macro name · 586f4335
      Thinh Nguyen 提交于
      Change the macro name DWC3_GTXFIFOSIZ_TXFDEF to DWC3_GTXFIFOSIZ_TXFDEP
      to match with the register name GTXFIFOSIZ.TXFDEP.
      
      Fixes: 457e84b6 ("usb: dwc3: gadget: dynamically re-size TxFifos")
      Fixes: 0cab8d26 ("usb: dwc3: Update DWC_usb31 GTXFIFOSIZ reg fields")
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      586f4335
  5. 15 3月, 2020 2 次提交
  6. 04 3月, 2020 1 次提交
    • P
      usb: dwc3: gadget: Update chain bit correctly when using sg list · dad2aff3
      Pratham Pratap 提交于
      If scatter-gather operation is allowed, a large USB request is split
      into multiple TRBs. For preparing TRBs for sg list, driver iterates
      over the list and creates TRB for each sg and mark the chain bit to
      false for the last sg. The current IOMMU driver is clubbing the list
      of sgs which shares a page boundary into one and giving it to USB driver.
      With this the number of sgs mapped it not equal to the the number of sgs
      passed. Because of this USB driver is not marking the chain bit to false
      since it couldn't iterate to the last sg. This patch addresses this issue
      by marking the chain bit to false if it is the last mapped sg.
      
      At a practical level, this patch resolves USB transfer stalls
      seen with adb on dwc3 based db845c, pixel3 and other qcom
      hardware after functionfs gadget added scatter-gather support
      around v4.20.
      
      Credit also to Anurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>
      who implemented a very similar fix to this issue.
      
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Yang Fei <fei.yang@intel.com>
      Cc: Thinh Nguyen <thinhn@synopsys.com>
      Cc: Tejas Joglekar <tejas.joglekar@synopsys.com>
      Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
      Cc: Jack Pham <jackp@codeaurora.org>
      Cc: Todd Kjos <tkjos@google.com>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linux USB List <linux-usb@vger.kernel.org>
      Cc: stable <stable@vger.kernel.org> #4.20+
      Signed-off-by: NPratham Pratap <prathampratap@codeaurora.org>
      [jstultz: Slight tweak to remove sg_is_last() usage, reworked
                commit message, minor comment tweak]
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      Link: https://lore.kernel.org/r/20200302214443.55783-1-john.stultz@linaro.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      dad2aff3
  7. 11 2月, 2020 1 次提交
    • A
      usb: dwc3: gadget: Check for IOC/LST bit in TRB->ctrl fields · 5ee85897
      Anurag Kumar Vulisha 提交于
      The current code in dwc3_gadget_ep_reclaim_completed_trb() will
      check for IOC/LST bit in the event->status and returns if
      IOC/LST bit is set. This logic doesn't work if multiple TRBs
      are queued per request and the IOC/LST bit is set on the last
      TRB of that request.
      
      Consider an example where a queued request has multiple queued
      TRBs and IOC/LST bit is set only for the last TRB. In this case,
      the core generates XferComplete/XferInProgress events only for
      the last TRB (since IOC/LST are set only for the last TRB). As
      per the logic in dwc3_gadget_ep_reclaim_completed_trb()
      event->status is checked for IOC/LST bit and returns on the
      first TRB. This leaves the remaining TRBs left unhandled.
      
      Similarly, if the gadget function enqueues an unaligned request
      with sglist already in it, it should fail the same way, since we
      will append another TRB to something that already uses more than
      one TRB.
      
      To aviod this, this patch changes the code to check for IOC/LST
      bits in TRB->ctrl instead.
      
      At a practical level, this patch resolves USB transfer stalls seen
      with adb on dwc3 based HiKey960 after functionfs gadget added
      scatter-gather support around v4.20.
      
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Yang Fei <fei.yang@intel.com>
      Cc: Thinh Nguyen <thinhn@synopsys.com>
      Cc: Tejas Joglekar <tejas.joglekar@synopsys.com>
      Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
      Cc: Jack Pham <jackp@codeaurora.org>
      Cc: Todd Kjos <tkjos@google.com>
      Cc: Greg KH <gregkh@linuxfoundation.org>
      Cc: Linux USB List <linux-usb@vger.kernel.org>
      Cc: stable <stable@vger.kernel.org>
      Tested-by: NTejas Joglekar <tejas.joglekar@synopsys.com>
      Reviewed-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NAnurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>
      [jstultz: forward ported to mainline, reworded commit log, reworked
       to only check trb->ctrl as suggested by Felipe]
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      5ee85897
  8. 15 1月, 2020 6 次提交
  9. 31 12月, 2019 1 次提交
  10. 10 12月, 2019 2 次提交
  11. 01 11月, 2019 1 次提交
  12. 07 10月, 2019 2 次提交
  13. 30 8月, 2019 1 次提交
    • T
      usb: dwc3: gadget: Workaround Mirosoft's BESL check · 17b63704
      Thinh Nguyen 提交于
      While testing our host system using Microsoft's usb stack against our
      gadget for various BESL values, we found an issue with their usb stack
      when the recommended baseline BESL value is 0 (125us) or when the deep
      BESL is 1 or less. The Windows host will issue a usb reset immediately
      after it receives the extended BOS descriptor and the enumeration will
      fail after a few attempts.
      
      To keep compatibility with Microsoft's host usb stack, let's workaround
      this issue by using the recommended baseline BESL of 1 (or 150us)
      and clamp the deep BESL value within 2 to 15.
      
      This was tested against Windows 10 build 18956.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      17b63704
  14. 28 8月, 2019 1 次提交
    • T
      usb: dwc3: gadget: Set BESL config parameter · 54fb5ba6
      Thinh Nguyen 提交于
      When operating with LPM signals, the controller asserts the deep
      low-power signal (utmi_l1_suspend_n) to the phy when the BESL value of
      the LPM token is equal to or greater than DCTL.HIRD_Thres[3:0] (and
      with DCTL.HIRD_Thres[4] set). Otherwise, the shallow low-power signal
      (utmi_sleep_n) is asserted. Set the recommended deep BESL equal to the
      controller's DCTL.HIRD_Thres[3:0] setting, and set the baseline BESL
      to 0 for the shallow low-power signal. This maximizes the opportunity
      for L1 residency and optimizes power savings.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      54fb5ba6