1. 17 8月, 2020 2 次提交
    • T
      usb: dwc3: gadget: Fix handling ZLP · d2ee3ff7
      Thinh Nguyen 提交于
      The usb_request->zero doesn't apply for isoc. Also, if we prepare a
      0-length (ZLP) TRB for the OUT direction, we need to prepare an extra
      TRB to pad up to the MPS alignment. Use the same bounce buffer for the
      ZLP TRB and the extra pad TRB.
      
      Cc: <stable@vger.kernel.org> # v4.5+
      Fixes: d6e5a549 ("usb: dwc3: simplify ZLP handling")
      Fixes: 04c03d10 ("usb: dwc3: gadget: handle request->zero")
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      d2ee3ff7
    • T
      usb: dwc3: gadget: Don't setup more than requested · 5d187c04
      Thinh Nguyen 提交于
      The SG list may be set up with entry size more than the requested
      length. Check the usb_request->length and make sure that we don't setup
      the TRBs to send/receive more than requested. This case may occur when
      the SG entry is allocated up to a certain minimum size, but the request
      length is less than that. It can also occur when the request is reused
      for a different request length.
      
      Cc: <stable@vger.kernel.org> # v4.18+
      Fixes: a31e63b6 ("usb: dwc3: gadget: Correct handling of scattergather lists")
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      5d187c04
  2. 24 7月, 2020 3 次提交
  3. 15 7月, 2020 1 次提交
  4. 24 6月, 2020 1 次提交
  5. 25 5月, 2020 13 次提交
    • T
      usb: dwc3: gadget: Check for prepared TRBs · 63c7bb29
      Thinh Nguyen 提交于
      There are cases where the endpoint needs to be restarted. For example,
      it may need to restart for NoStream rejection to reinitiate stream. If
      so, check and make sure we don't prepare beyond the current transfer
      when we restart the endpoint.
      
      DWC_usb32 internal burst transfer feature will look into TRBs beyond a
      transfer. Other controllers will stop on the last TRB, but not
      DWC_usb32. This may cause the controller to incorrectly process TRBs of
      a different transfer. Make sure to explicitly prevent preparing TRBs of
      a different transfer.
      
      This should only affect DWC_usb32 releases prior to v1.00a since it
      doesn't use SET_ENDPOINT_PRIME to reinitiate stream. However, it's
      better to be cautious in case users don't want to use SET_ENDPOINT_PRIME
      command. Also, it's possible other controller IPs may share the same
      features as DWC_usb32 in new releases.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      63c7bb29
    • Y
      usb: dwc3: Increase timeout for CmdAct cleared by device controller · 1c0e69ae
      Yu Chen 提交于
      If the SS PHY is in P3, there is no pipe_clk, HW may use suspend_clk
      for function, as suspend_clk is slow so EP command need more time to
      complete, e.g, imx8M suspend_clk is 32K, set ep configuration will
      take about 380us per below trace time stamp(44.286278 - 44.285897
      = 0.000381):
      
      configfs_acm.sh-822   [000] d..1    44.285896: dwc3_writel: addr
      000000006d59aae1 value 00000401
      configfs_acm.sh-822   [000] d..1    44.285897: dwc3_readl: addr
      000000006d59aae1 value 00000401
      ... ...
      configfs_acm.sh-822   [000] d..1    44.286278: dwc3_readl: addr
      000000006d59aae1 value 00000001
      configfs_acm.sh-822   [000] d..1    44.286279: dwc3_gadget_ep_cmd:
      ep0out: cmd 'Set Endpoint Configuration' [401] params 00001000
      00000500 00000000 --> status: Successful
      
      This was originally found on Hisilicon Kirin Soc that need more time
      for the device controller to clear the CmdAct of DEPCMD.
      Signed-off-by: NYu Chen <chenyu56@huawei.com>
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      Signed-off-by: NLi Jun <jun.li@nxp.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      1c0e69ae
    • T
      usb: dwc3: gadget: Use SET_EP_PRIME for NoStream · b10e1c25
      Thinh Nguyen 提交于
      DWC_usb32 v1.00a and later can use SET_EP_PRIME command to reinitiate a
      stream. Use the command to handle NoStream rejection instead of ending
      and restarting the endpoint.
      Signed-off-by: NThinh Nguyen <thinhn@synopsys.com>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      b10e1c25
    • 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
  6. 09 5月, 2020 1 次提交
    • J
      dwc3: Remove check for HWO flag in dwc3_gadget_ep_reclaim_trb_sg() · 00e21763
      John Stultz 提交于
      The check for the HWO flag in dwc3_gadget_ep_reclaim_trb_sg()
      causes us to break out of the loop before we call
      dwc3_gadget_ep_reclaim_completed_trb(), which is what likely
      should be clearing the HWO flag.
      
      This can cause odd behavior where we never reclaim all the trbs
      in the sg list, so we never call giveback on a usb req, and that
      will causes transfer stalls.
      
      This effectively resovles the adb stalls seen on HiKey960
      after userland changes started only using AIO in adbd.
      
      Cc: YongQin Liu <yongqin.liu@linaro.org>
      Cc: Anurag Kumar Vulisha <anurag.kumar.vulisha@xilinx.com>
      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: Josh Gao <jmgao@google.com>
      Cc: Todd Kjos <tkjos@google.com>
      Cc: Felipe Balbi <balbi@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: linux-usb@vger.kernel.org
      Cc: stable@vger.kernel.org #4.20+
      Signed-off-by: NJohn Stultz <john.stultz@linaro.org>
      Signed-off-by: NFelipe Balbi <balbi@kernel.org>
      00e21763
  7. 05 5月, 2020 8 次提交
  8. 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
  9. 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
  10. 15 3月, 2020 2 次提交
  11. 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
  12. 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
  13. 15 1月, 2020 3 次提交