Commit Graph

261 Commits

Author SHA1 Message Date
Desnes Nunes 43354ad98e usb: cdns3: Synchronise PCI IDs via common data base
JIRA: https://issues.redhat.com/browse/RHEL-78828

commit 12bbabd3cab8a7dab0ddad8ed1e671f40c7cdeeb
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue, 12 Nov 2024 18:01:25 +0200

  There are a few places in the kernel where PCI IDs for different Cadence
  USB controllers are being used. Besides different naming, they duplicate
  each other. Make this all in order by providing common definitions via
  PCI IDs database and use in all users. While doing that, rename
  definitions as Roger suggested.

  Suggested-by: Roger Quadros <rogerq@kernel.org>
  Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  Acked-by: Bjorn Helgaas <bhelgaas@google.com>
  Link: https://lore.kernel.org/r/20241112160125.2340972-1-andriy.shevchenko@linux.intel.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2025-03-19 21:24:05 -03:00
Desnes Nunes 16194f9bf4 sub: cdns3: Use predefined PCI vendor ID constant
JIRA: https://issues.redhat.com/browse/RHEL-78828

commit 68d4209158f43a558c5553ea95ab0c8975eab18c
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Fri, 13 Sep 2024 16:17:10 +0300

  The PCI vendor ID for Cadence is defined in pci_ids.h. Use it.
  While at it, move to PCI_DEVICE() macro and usual pattern for
  PCI class and device IDs.

  Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  Link: https://lore.kernel.org/r/20240913131710.3630560-1-andriy.shevchenko@linux.intel.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2025-03-19 21:24:05 -03:00
Desnes Nunes e3ae4bd504 usb: xhci: fix loss of data on Cadence xHC
JIRA: https://issues.redhat.com/browse/RHEL-59052

commit e5fa8db0be3e8757e8641600c518425a4589b85c
Author: Pawel Laszczak <pawell@cadence.com>
Date: Thu, 5 Sep 2024 07:03:28 +0000

  Streams should flush their TRB cache, re-read TRBs, and start executing
  TRBs from the beginning of the new dequeue pointer after a 'Set TR Dequeue
  Pointer' command.

  Cadence controllers may fail to start from the beginning of the dequeue
  TRB as it doesn't clear the Opaque 'RsvdO' field of the stream context
  during 'Set TR Dequeue' command. This stream context area is where xHC
  stores information about the last partially executed TD when a stream
  is stopped. xHC uses this information to resume the transfer where it left
  mid TD, when the stream is restarted.

  Patch fixes this by clearing out all RsvdO fields before initializing new
  Stream transfer using a 'Set TR Dequeue Pointer' command.

  Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
  cc: stable@vger.kernel.org
  Signed-off-by: Pawel Laszczak <pawell@cadence.com>
  Reviewed-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/PH7PR07MB95386A40146E3EC64086F409DD9D2@PH7PR07MB9538.namprd07.prod.outlook.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-12-13 11:26:39 -03:00
Desnes Nunes 612e507146 usb: cdnsp: Fix incorrect usb_request status
JIRA: https://issues.redhat.com/browse/RHEL-59052

commit 1702bec4477cc7d31adb4a760d14d33fac928b7a
Author: Pawel Laszczak <pawell@cadence.com>
Date: Fri, 6 Sep 2024 06:48:54 +0000

  Fix changes incorrect usb_request->status returned during disabling
  endpoints. Before fix the status returned during dequeuing requests
  while disabling endpoint was ECONNRESET.
  Patch change it to ESHUTDOWN.

  Patch fixes issue detected during testing UVC gadget.
  During stopping streaming the class starts dequeuing usb requests and
  controller driver returns the -ECONNRESET status. After completion
  requests the class or application "uvc-gadget" try to queue this
  request again. Changing this status to ESHUTDOWN cause that UVC assumes
  that endpoint is disabled, or device is disconnected and stops
  re-queuing usb requests.

  Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
  cc: stable@vger.kernel.org
  Signed-off-by: Pawel Laszczak <pawell@cadence.com>
  Reviewed-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/PH7PR07MB9538E8CA7A2096AAF6A3718FDD9E2@PH7PR07MB9538.namprd07.prod.outlook.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-12-13 11:26:38 -03:00
Desnes Nunes 2034f47f9b usb: cdnsp: fix for Link TRB with TC
JIRA: https://issues.redhat.com/browse/RHEL-59051

commit 740f2e2791b98e47288b3814c83a3f566518fed2
Author: Pawel Laszczak <pawell@cadence.com>
Date: Wed, 21 Aug 2024 06:07:42 +0000

  Stop Endpoint command on LINK TRB with TC bit set to 1 causes that
  internal cycle bit can have incorrect state after command complete.
  In consequence empty transfer ring can be incorrectly detected
  when EP is resumed.
  NOP TRB before LINK TRB avoid such scenario. Stop Endpoint command
  is then on NOP TRB and internal cycle bit is not changed and have
  correct value.

  Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
  cc: <stable@vger.kernel.org>
  Signed-off-by: Pawel Laszczak <pawell@cadence.com>
  Reviewed-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/PH7PR07MB953878279F375CCCE6C6F40FDD8E2@PH7PR07MB9538.namprd07.prod.outlook.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-11-07 23:01:43 -03:00
Desnes Nunes 0939ae398e usb: cdnsp: fix incorrect index in cdnsp_get_hw_deq function
JIRA: https://issues.redhat.com/browse/RHEL-59051

commit 0497a356d3c498221eb0c1edc1e8985816092f12
Author: Pawel Laszczak <pawell@cadence.com>
Date: Tue, 20 Aug 2024 08:21:19 +0000

  Patch fixes the incorrect "stream_id" table index instead of
  "ep_index" used in cdnsp_get_hw_deq function.

  Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
  cc: stable@vger.kernel.org
  Signed-off-by: Pawel Laszczak <pawell@cadence.com>
  Reviewed-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/PH7PR07MB95381F2182688811D5C711CEDD8D2@PH7PR07MB9538.namprd07.prod.outlook.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-11-07 23:01:43 -03:00
Desnes Nunes 8e174502e4 usb: cdns3-ti: Add workaround for Errata i2409
JIRA: https://issues.redhat.com/browse/RHEL-59051

commit b50a2da03bd95784541b3f9058e452cc38f9ba05
Author: Roger Quadros <rogerq@kernel.org>
Date: Thu, 16 May 2024 10:15:37 +0530

  TI USB2 PHY is known to have a lockup issue on very short
  suspend intervals. Enable the Suspend Residency quirk flag to
  workaround this as described in Errata i2409 [1].

  [1] - https://www.ti.com/lit/er/sprz457h/sprz457h.pdf

  Signed-off-by: Roger Quadros <rogerq@kernel.org>
  Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com>
  Acked-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/20240516044537.16801-3-r-gunasekaran@ti.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-11-07 23:01:28 -03:00
Desnes Nunes 1e0128ba68 usb: cdns3: Add quirk flag to enable suspend residency
JIRA: https://issues.redhat.com/browse/RHEL-59051

commit 0aca19e4037a4143273e90f1b44666b78b4dde9b
Author: Roger Quadros <rogerq@kernel.org>
Date: Thu, 16 May 2024 10:15:36 +0530

  Some platforms (e.g. ti,j721e-usb, ti,am64-usb) require
  this bit to be set to workaround a lockup issue with PHY
  short suspend intervals [1]. Add a platform quirk flag
  to indicate if Suspend Residency should be enabled.

  [1] - https://www.ti.com/lit/er/sprz457h/sprz457h.pdf
  i2409 - USB: USB2 PHY locks up due to short suspend

  Signed-off-by: Roger Quadros <rogerq@kernel.org>
  Signed-off-by: Ravi Gunasekaran <r-gunasekaran@ti.com>
  Acked-by: Peter Chen <peter.chen@kernel.org>
  Link: https://lore.kernel.org/r/20240516044537.16801-2-r-gunasekaran@ti.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2024-11-07 23:01:28 -03:00
Myron Stowe 0c4df2c357 PCI: Use array for .id_table consistently
JIRA: https://issues.redhat.com/browse/RHEL-59033
Upstream Status: 7d2ebbc33d9f65a492d8a41fd33036e411366341

Conflict(s):
  RHEL does not have the following files, thus their respective patch
  hunks were skipped:
    Documentation/translations/zh_CN/PCI/pciebus-howto.rst
    drivers/usb/gadget/udc/cdns2/cdns2-pci.c


commit 7d2ebbc33d9f65a492d8a41fd33036e411366341
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Fri May 17 21:04:58 2024 +0900

    PCI: Use array for .id_table consistently

    While 'x' and '&x[0]' are equivalent, most of the PCI drivers use the
    former form for the .id_table.

    Update some drivers and documentation for consistency.

    Link: https://lore.kernel.org/r/20240517120458.1260489-1-masahiroy@kernel.org
    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Signed-off-by: Myron Stowe <mstowe@redhat.com>
2024-10-05 10:59:19 -06:00
Martin McConnell 103c99274a usb: cdns3: Fix spelling mistake "supporte" -> "supported"
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 654298aeac7c78f44f00658738e5c77e685366af
Author: Colin Ian King <colin.i.king@gmail.com>
Date:   Tue Feb 20 08:06:17 2024 +0000

    usb: cdns3: Fix spelling mistake "supporte" -> "supported"

    There is a spelling mistake in a dev_err message. Fix it.

    Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
    Link: https://lore.kernel.org/r/20240220080617.2674613-1-colin.i.king@gmail.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:52 +01:00
Martin McConnell 5ed7e92c59 usb: cdns3: fixed memory use after free at cdns3_gadget_ep_disable()
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit cd45f99034b0c8c9cb346dd0d6407a95ca3d36f6
Author: Frank Li <Frank.Li@nxp.com>
Date:   Fri Feb 2 10:42:16 2024 -0500

    usb: cdns3: fixed memory use after free at cdns3_gadget_ep_disable()

      ...
      cdns3_gadget_ep_free_request(&priv_ep->endpoint, &priv_req->request);
      list_del_init(&priv_req->list);
      ...

    'priv_req' actually free at cdns3_gadget_ep_free_request(). But
    list_del_init() use priv_req->list after it.

    [ 1542.642868][  T534] BUG: KFENCE: use-after-free read in __list_del_entry_valid+0x10/0xd4
    [ 1542.642868][  T534]
    [ 1542.653162][  T534] Use-after-free read at 0x000000009ed0ba99 (in kfence-#3):
    [ 1542.660311][  T534]  __list_del_entry_valid+0x10/0xd4
    [ 1542.665375][  T534]  cdns3_gadget_ep_disable+0x1f8/0x388 [cdns3]
    [ 1542.671571][  T534]  usb_ep_disable+0x44/0xe4
    [ 1542.675948][  T534]  ffs_func_eps_disable+0x64/0xc8
    [ 1542.680839][  T534]  ffs_func_set_alt+0x74/0x368
    [ 1542.685478][  T534]  ffs_func_disable+0x18/0x28

    Move list_del_init() before cdns3_gadget_ep_free_request() to resolve this
    problem.

    Cc: stable@vger.kernel.org
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Reviewed-by: Roger Quadros <rogerq@kernel.org>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20240202154217.661867-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:51 +01:00
Martin McConnell c1d2085009 usb: cdns3: fix memory double free when handle zero packet
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 5fd9e45f1ebcd57181358af28506e8a661a260b3
Author: Frank Li <Frank.Li@nxp.com>
Date:   Fri Feb 2 10:42:17 2024 -0500

    usb: cdns3: fix memory double free when handle zero packet

    829  if (request->complete) {
    830          spin_unlock(&priv_dev->lock);
    831          usb_gadget_giveback_request(&priv_ep->endpoint,
    832                                    request);
    833          spin_lock(&priv_dev->lock);
    834  }
    835
    836  if (request->buf == priv_dev->zlp_buf)
    837      cdns3_gadget_ep_free_request(&priv_ep->endpoint, request);

    Driver append an additional zero packet request when queue a packet, which
    length mod max packet size is 0. When transfer complete, run to line 831,
    usb_gadget_giveback_request() will free this requestion. 836 condition is
    true, so cdns3_gadget_ep_free_request() free this request again.

    Log:

    [ 1920.140696][  T150] BUG: KFENCE: use-after-free read in cdns3_gadget_giveback+0x134/0x2c0 [cdns3]
    [ 1920.140696][  T150]
    [ 1920.151837][  T150] Use-after-free read at 0x000000003d1cd10b (in kfence-#36):
    [ 1920.159082][  T150]  cdns3_gadget_giveback+0x134/0x2c0 [cdns3]
    [ 1920.164988][  T150]  cdns3_transfer_completed+0x438/0x5f8 [cdns3]

    Add check at line 829, skip call usb_gadget_giveback_request() if it is
    additional zero length packet request. Needn't call
    usb_gadget_giveback_request() because it is allocated in this driver.

    Cc: stable@vger.kernel.org
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Reviewed-by: Roger Quadros <rogerq@kernel.org>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20240202154217.661867-2-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:51 +01:00
Martin McConnell f8ecaed808 usb: cdnsp: fixed issue with incorrect detecting CDNSP family controllers
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 47625b018c6bc788bc10dd654c82696eb0a5ef11
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Feb 15 13:16:09 2024 +0100

    usb: cdnsp: fixed issue with incorrect detecting CDNSP family controllers

    Cadence have several controllers from 0x000403xx family but current
    driver suuport detecting only one with DID equal 0x0004034E.
    It causes that if someone uses different CDNSP controller then driver
    will use incorrect version and register space.
    Patch fix this issue.

    cc: stable@vger.kernel.org
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20240215121609.259772-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:50 +01:00
Martin McConnell 2cba874ef0 usb: cdnsp: blocked some cdns3 specific code
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 18a6be674306c9acb05c08e5c3fd376ef50a917c
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Tue Feb 6 11:40:18 2024 +0100

    usb: cdnsp: blocked some cdns3 specific code

    host.c file has some parts of code that were introduced for CDNS3 driver
    and should not be used with CDNSP driver.
    This patch blocks using these parts of codes by CDNSP driver.
    These elements include:
    - xhci_plat_cdns3_xhci object
    - cdns3 specific XECP_PORT_CAP_REG register
    - cdns3 specific XECP_AUX_CTRL_REG1 register

    cc: stable@vger.kernel.org
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20240206104018.48272-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:49 +01:00
Martin McConnell d9becbafb6 usb: cdns3: Fix uvc fail when DMA cross 4k boundery since sg enabled
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 40c304109e866a7dc123661a5c8ca72f6b5e14e0
Author: Frank Li <Frank.Li@nxp.com>
Date:   Sun Dec 24 10:38:15 2023 -0500

    usb: cdns3: Fix uvc fail when DMA cross 4k boundery since sg enabled

    Supposed DMA cross 4k bounder problem should be fixed at DEV_VER_V2, but
    still met problem when do ISO transfer if sg enabled.

    Data pattern likes below when sg enabled, package size is 1k and mult is 2
            [UVC Header(8B) ] [data(3k - 8)] ...

    The received data at offset 0xd000 will get 0xc000 data, len 0x70. Error
    happen position as below pattern:
            0xd000: wrong
            0xe000: wrong
            0xf000: correct
            0x10000: wrong
            0x11000: wrong
            0x12000: correct
            ...

    To avoid DMA cross 4k bounder at ISO transfer, reduce burst len according
    to start DMA address's alignment.

    Cc:  <stable@vger.kernel.org>
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20231224153816.1664687-4-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:49 +01:00
Martin McConnell c0e0f5fed9 usb: cdns3: fix iso transfer error when mult is not zero
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 92f02efa1d86d7dcaef7f38a5fe3396c4e88a93c
Author: Frank Li <Frank.Li@nxp.com>
Date:   Sun Dec 24 10:38:14 2023 -0500

    usb: cdns3: fix iso transfer error when mult is not zero

    ISO basic transfer is
            ITP(SOF) Package_0 Package_1 ... Package_n

    CDNS3 DMA start dma transfer from memmory to internal FIFO when get SOF,
    controller will transfer data to usb bus from internal FIFO when get IN
    token.

    According USB spec defination:
            Maximum number of packets = (bMaxBurst + 1) * (Mult + 1)

    Internal memory should be the same as (bMaxBurst + 1) * (Mult + 1). DMA
    don't fetch data advance when ISO transfer, so only reserve
    (bMaxBurst + 1) * (Mult + 1) internal memory for ISO transfer.

    Need save Mult and bMaxBurst information and set it into EP_CFG register,
    otherwise only 1 package is sent by controller, other package will be
    lost.

    Cc:  <stable@vger.kernel.org>
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20231224153816.1664687-3-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:48 +01:00
Martin McConnell 75d79d472e usb: cdns3: fix uvc failure work since sg support enabled
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 1b8be5ecff26201bafb0a554c74e91571299fb94
Author: Frank Li <Frank.Li@nxp.com>
Date:   Sun Dec 24 10:38:13 2023 -0500

    usb: cdns3: fix uvc failure work since sg support enabled

    When IP version >= DEV_VER_V2, gadget:sg_supported is true. So uvc gadget
    function driver will use sg to equeue data, first is 8bytes header, the
    second is 1016bytes data.

        cdns3_prepare_trb: ep2in: trb 0000000000ac755f, dma buf: 0xbf455000, size: 8, burst: 128 ctrl: 0x00000415 (C=1, T=0, ISP, CHAIN, Normal)
        cdns3_prepare_trb: ep2in: trb 00000000a574e693, dma buf: 0xc0200fe0, size: 1016, burst: 128 ctrl: 0x00000405 (C=1, T=0, ISP, Normal)

    But cdns3_ep_run_transfer() can't correctly handle this case, which only
    support one TRB for ISO transfer.

    The controller requires duplicate the TD for each SOF if priv_ep->interval
    is not 1. DMA will read data from DDR to internal FIFO when get SOF. Send
    data to bus when receive IN token. DMA always refill FIFO when get SOF
    regardless host send IN token or not. If host send IN token later, some
    frames data will be lost.

    Fixed it by below major steps:

    1. Calculate numembers of TRB base on sg_nums and priv_ep->interval.
    2. Remove CHAIN flags for each end TRB of TD when duplicate TD.
    3. The controller requires LINK TRB must be first TRB of TD. When check
    there are not enough TRBs lefts, just fill LINK TRB for left TRBs.

    .... CHAIN_TRB DATA_TRB, CHAIN_TRB DATA_TRB,  LINK_TRB ... LINK_TRB
                                                               ^End of TRB List

    Cc:  <stable@vger.kernel.org>
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20231224153816.1664687-2-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:48 +01:00
Martin McConnell 36d663a32d usb: cdns3: Use dev_err_probe
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 776630be36935be3a51e5ecfa7fc7614c4d4e46e
Author: Alexander Stein <alexander.stein@ew.tq-group.com>
Date:   Thu Dec 14 15:40:11 2023 +0100

    usb: cdns3: Use dev_err_probe

    Create an error message or upon deferral add a description for sysfs.

    Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
    Link: https://lore.kernel.org/r/20231214144011.1987586-1-alexander.stein@ew.tq-group.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:47 +01:00
Martin McConnell 0671cb69f0 usb: cdns3: starfive: don't misuse /** comment
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 5cc623a4edaf383eea39546104084b089f3035ca
Author: Randy Dunlap <rdunlap@infradead.org>
Date:   Wed Dec 6 10:13:17 2023 -0800

    usb: cdns3: starfive: don't misuse /** comment

    Use a common C comment "/*" instead of "/**" to prevent a warning
    from scripts/kernel-doc.

    cdns3-starfive.c:23: warning: expecting prototype for cdns3(). Prototype was for USB_STRAP_HOST() instead

    Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
    Cc: Minda Chen <minda.chen@starfivetech.com>
    Cc: Peter Chen <peter.chen@kernel.org>
    Cc: Pawel Laszczak <pawell@cadence.com>
    Cc: Roger Quadros <rogerq@kernel.org>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc:  <linux-usb@vger.kernel.org>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20231206181317.27515-1-rdunlap@infradead.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:46 +01:00
Martin McConnell 43e0521f1c usb: cdnsp: Replace snprintf() with the safer scnprintf() variant
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit b385ef088c7aab20a2c0dc20d390d69a6620f0f3
Author: Lee Jones <lee@kernel.org>
Date:   Thu Nov 30 10:54:36 2023 +0000

    usb: cdnsp: Replace snprintf() with the safer scnprintf() variant

    There is a general misunderstanding amongst engineers that {v}snprintf()
    returns the length of the data *actually* encoded into the destination
    array.  However, as per the C99 standard {v}snprintf() really returns
    the length of the data that *would have been* written if there were
    enough space for it.  This misunderstanding has led to buffer-overruns
    in the past.  It's generally considered safer to use the {v}scnprintf()
    variants in their place (or even sprintf() in simple cases).  So let's
    do that.

    The uses in this file all seem to assume that data *has been* written!

    Link: https://lwn.net/Articles/69419/
    Link: https://github.com/KSPP/linux/issues/105
    Cc: Pawel Laszczak <pawell@cadence.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: linux-usb@vger.kernel.org
    Signed-off-by: Lee Jones <lee@kernel.org>
    Link: https://lore.kernel.org/r/20231130105459.3208986-3-lee@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:46 +01:00
Martin McConnell d6b454b89c usb: cdns3: skip set TRB_IOC when usb_request: no_interrupt is true
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 7836be3b100cfc6db3db7ddeb985254bfe1775e4
Author: Frank Li <Frank.Li@nxp.com>
Date:   Fri Oct 27 14:39:19 2023 -0400

    usb: cdns3: skip set TRB_IOC when usb_request: no_interrupt is true

    No completion irq is needed if no_interrupt is true. Needn't set TRB_IOC
    at this case.

    Check usb_request: no_interrupt and set/skip TRB_IOC in
    cdns3_ep_run_transfer().

    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20231027183919.664271-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:45 +01:00
Martin McConnell 13cefbe9cd usb: cdnsp: Fix deadlock issue during using NCM gadget
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 58f2fcb3a845fcbbad2f3196bb37d744e0506250
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Wed Nov 8 10:31:25 2023 +0100

    usb: cdnsp: Fix deadlock issue during using NCM gadget

    The interrupt service routine registered for the gadget is a primary
    handler which mask the interrupt source and a threaded handler which
    handles the source of the interrupt. Since the threaded handler is
    voluntary threaded, the IRQ-core does not disable bottom halves before
    invoke the handler like it does for the forced-threaded handler.

    Due to changes in networking it became visible that a network gadget's
    completions handler may schedule a softirq which remains unprocessed.
    The gadget's completion handler is usually invoked either in hard-IRQ or
    soft-IRQ context. In this context it is enough to just raise the softirq
    because the softirq itself will be handled once that context is left.
    In the case of the voluntary threaded handler, there is nothing that
    will process pending softirqs. Which means it remain queued until
    another random interrupt (on this CPU) fires and handles it on its exit
    path or another thread locks and unlocks a lock with the bh suffix.
    Worst case is that the CPU goes idle and the NOHZ complains about
    unhandled softirqs.

    Disable bottom halves before acquiring the lock (and disabling
    interrupts) and enable them after dropping the lock. This ensures that
    any pending softirqs will handled right away.

    cc: stable@vger.kernel.org
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20231108093125.224963-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:45 +01:00
Martin McConnell 783b8e110a usb:cdnsp: remove TRB_FLUSH_ENDPOINT command
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 2998874736bca1031ca84b0a3235a2cd09dfa426
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Oct 26 09:37:37 2023 +0200

    usb:cdnsp: remove TRB_FLUSH_ENDPOINT command

    Patch removes TRB_FLUSH_ENDPOINT command from driver.
    This command is not supported by controller and
    USBSSP returns TRB Error completion code for it.

    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20231026073737.165450-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:44 +01:00
Martin McConnell c62d3b9a61 usb: cdns3: Modify the return value of cdns_set_active () to void when CONFIG_PM_SLEEP is disabled
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 9f35d612da5592f1bf1cae44ec1e023df37bea12
Author: Xiaolei Wang <xiaolei.wang@windriver.com>
Date:   Tue Sep 26 15:53:33 2023 +0800

    usb: cdns3: Modify the return value of cdns_set_active () to void when CONFIG_PM_SLEEP is disabled

    The return type of cdns_set_active () is inconsistent
    depending on whether CONFIG_PM_SLEEP is enabled, so the
    return value is modified to void type.

    Reported-by: Pavel Machek <pavel@denx.de>
    Closes: https://lore.kernel.org/all/ZP7lIKUzD68XA91j@duo.ucw.cz/
    Fixes: 2319b9c87fe2 ("usb: cdns3: Put the cdns set active part outside the spin lock")
    Cc: stable@vger.kernel.org
    Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
    Reviewed-by: Pavel Machek <pavel@denx.de>
    Reviewed-by: Roger Quadros <rogerq@kernel.org>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20230926075333.1791011-1-xiaolei.wang@windriver.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:43 +01:00
Martin McConnell 1c9bfbb988 usb: cdnsp: Fixes issue with dequeuing not queued requests
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 34f08eb0ba6e4869bbfb682bf3d7d0494ffd2f87
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Jul 13 04:14:29 2023 -0400

    usb: cdnsp: Fixes issue with dequeuing not queued requests

    Gadget ACM while unloading module try to dequeue not queued usb
    request which causes the kernel to crash.
    Patch adds extra condition to check whether usb request is processed
    by CDNSP driver.

    cc: stable@vger.kernel.org
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20230713081429.326660-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:43 +01:00
Martin McConnell 6395ee84f1 usb: cdns3: Add PHY mode switch to usb2 PHY
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 26910f977c3f966ce0e513ada42c741f243085ce
Author: Minda Chen <minda.chen@starfivetech.com>
Date:   Fri Jul 21 17:59:23 2023 +0800

    usb: cdns3: Add PHY mode switch to usb2 PHY

    cdns3 just set PHY mode switch for USB3.0 PHY.
    If USB 2.0 PHY contains PHY mode switch setting,
    USB 2.0 PHY mode function can't be called.
    So add PHY mode switch function for USB 2.0 PHY.

    Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
    Reviewed-by: Roger Quadros <rogerq@kernel.org>
    Link: https://lore.kernel.org/r/20230721095923.20445-1-minda.chen@starfivetech.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:42 +01:00
Martin McConnell 8cdffeb4a3 usb: cdns3: starfive: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 48cb8ff3e250301a5a48925281a7096969ab3a48
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Fri Jul 7 09:36:53 2023 +0200

    usb: cdns3: starfive: Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is ignored (apart
    from emitting a warning) and this typically results in resource leaks.
    To improve here there is a quest to make the remove callback return
    void. In the first step of this quest all drivers are converted to
    .remove_new() which already returns void. Eventually after all drivers
    are converted, .remove_new() is renamed to .remove().

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Acked-by: Roger Quadros <rogerq@kernel.org>
    Link: https://lore.kernel.org/r/20230707073653.3396988-1-u.kleine-koenig@pengutronix.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:42 +01:00
Martin McConnell 2504d09ab5 usb: cdns3: Put the cdns set active part outside the spin lock
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 2319b9c87fe243327285f2fefd7374ffd75a65fc
Author: Xiaolei Wang <xiaolei.wang@windriver.com>
Date:   Fri Jun 16 10:19:51 2023 +0800

    usb: cdns3: Put the cdns set active part outside the spin lock

    The device may be scheduled during the resume process,
    so this cannot appear in atomic operations. Since
    pm_runtime_set_active will resume suppliers, put set
    active outside the spin lock, which is only used to
    protect the struct cdns data structure, otherwise the
    kernel will report the following warning:

      BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:1163
      in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 651, name: sh
      preempt_count: 1, expected: 0
      RCU nest depth: 0, expected: 0
      CPU: 0 PID: 651 Comm: sh Tainted: G        WC         6.1.20 #1
      Hardware name: Freescale i.MX8QM MEK (DT)
      Call trace:
        dump_backtrace.part.0+0xe0/0xf0
        show_stack+0x18/0x30
        dump_stack_lvl+0x64/0x80
        dump_stack+0x1c/0x38
        __might_resched+0x1fc/0x240
        __might_sleep+0x68/0xc0
        __pm_runtime_resume+0x9c/0xe0
        rpm_get_suppliers+0x68/0x1b0
        __pm_runtime_set_status+0x298/0x560
        cdns_resume+0xb0/0x1c0
        cdns3_controller_resume.isra.0+0x1e0/0x250
        cdns3_plat_resume+0x28/0x40

    Signed-off-by: Xiaolei Wang <xiaolei.wang@windriver.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20230616021952.1025854-1-xiaolei.wang@windriver.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:41 +01:00
Martin McConnell 693269e7fd usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 2627335a1329a0d39d8d277994678571c4f21800
Author: Frank Li <Frank.Li@nxp.com>
Date:   Fri Jul 7 19:00:15 2023 -0400

    usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config

    Previously, the cdns3_gadget_check_config() function in the cdns3 driver
    mistakenly calculated the ep_buf_size by considering only one
    configuration's endpoint information because "claimed" will be clear after
    call usb_gadget_check_config().

    The fix involves checking the private flags EP_CLAIMED instead of relying
    on the "claimed" flag.

    Fixes: dce49449e04f ("usb: cdns3: allocate TX FIFO size according to composite EP number")
    Cc: stable <stable@kernel.org>
    Reported-by: Ravi Gunasekaran <r-gunasekaran@ti.com>
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Tested-by: Ravi Gunasekaran <r-gunasekaran@ti.com>
    Link: https://lore.kernel.org/r/20230707230015.494999-2-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:40 +01:00
Martin McConnell 1228c38250 usb: cdns3: imx: Rework system PM to avoid duplicated operations
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit db3c4e366287cc2ed7b15e74a85bc5a12f5be4b8
Author: Shenwei Wang <shenwei.wang@nxp.com>
Date:   Tue May 23 13:44:12 2023 -0500

    usb: cdns3: imx: Rework system PM to avoid duplicated operations

    The current implementation uses the same callbacks for system PM and
    runtime PM suspend/resume without any state checking. This can cause the
    clocks to be prepared/unprepared twice, leading to kernel warning issues.

    This patch resolves the double prepare/unprepare issues by separating the
    runtime PM and system PM handling.

    Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
    Reviewed-by: Frank Li <frank.li@nxp.com>
    Link: https://lore.kernel.org/r/20230523184412.204582-1-shenwei.wang@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:40 +01:00
Martin McConnell 7f51d6f494 usb: cdns3: optimize OUT transfer by copying only actual received data
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 3124387537bc94251e65c2841062d14736380ec4
Author: Frank Li <Frank.Li@nxp.com>
Date:   Thu May 18 16:49:46 2023 -0400

    usb: cdns3: optimize OUT transfer by copying only actual received data

    Previously, the entire length of the request, which is equal to or greater
    than the actual data, was dma synced and memcpy when using the bounce
    buffer. Actually only the actual data indicated by request->actual need be
    synced and copied.

    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20230518204947.3770236-2-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:39 +01:00
Martin McConnell 6f7bec44e9 usb: cdns3: improve handling of unaligned address case
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 2a1c4639d6d6bcee27f74e38f83ffb43579c4733
Author: Frank Li <Frank.Li@nxp.com>
Date:   Thu May 18 16:49:45 2023 -0400

    usb: cdns3: improve handling of unaligned address case

    When the address of a request was not aligned with an 8-byte boundary, the
    USB DMA was unable to process it, necessitating the use of an internal
    bounce buffer.

    In these cases, the request->buf had to be copied to/from this bounce
    buffer. However, if this unaligned address scenario arises, it is
    unnecessary to perform heavy cache maintenance operations like
    usb_gadget_map(unmap)_request_by_dev() on the request->buf, as the DMA
    does not utilize it at all. it can be skipped at this case.

    iperf3 tests on the rndis case:

    Transmit speed (TX): Improved from 299Mbps to 440Mbps
    Receive speed (RX): Improved from 290Mbps to 500Mbps

    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20230518204947.3770236-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:39 +01:00
Martin McConnell 7a5f2aa6b7 usb: cdns3: Add StarFive JH7110 USB driver
JIRA: https://issues.redhat.com/browse/RHEL-54566

Conflicts: MAINTAINERS: Integrate new StarFive JH71x0 usb driver entry

commit bfb46b424652a3396b92ca3c96c169ade9b45b8d
Author: Minda Chen <minda.chen@starfivetech.com>
Date:   Thu May 18 19:27:49 2023 +0800

    usb: cdns3: Add StarFive JH7110 USB driver

    Adds Specific Glue layer to support USB peripherals on
    StarFive JH7110 SoC.
    There is a Cadence USB3 core for JH7110 SoCs, the cdns
    core is the child of this USB wrapper module device.

    Signed-off-by: Minda Chen <minda.chen@starfivetech.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Reviewed-by: Roger Quadros <rogerq@kernel.org>
    Link: https://lore.kernel.org/r/20230518112750.57924-7-minda.chen@starfivetech.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:21:15 +01:00
Martin McConnell b51ed85ed8 usb: cdns3: imx: simplify clock name usage
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 7a053bf2b36622996356018a7a224c20d0ddcea9
Author: Frank Li <Frank.Li@nxp.com>
Date:   Wed May 17 11:25:44 2023 -0400

    usb: cdns3: imx: simplify clock name usage

    Simplifies the clock names in imx_cdns3_core_clks[]. Such as, renaming
    "usb3_lpm_clk" to "lpm". The "usb3" prefix and "clk" suffix were
    redundant.

    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20230517152545.3404508-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:43 +01:00
Martin McConnell 180f0c5487 usb: cdns3: fix NCM gadget RX speed 20x slow than expection at iMX8QM
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit dbe678f6192f27879ac9ff6bc7a1036aad85aae9
Author: Frank Li <Frank.Li@nxp.com>
Date:   Thu May 18 11:49:45 2023 -0400

    usb: cdns3: fix NCM gadget RX speed 20x slow than expection at iMX8QM

    At iMX8QM platform, enable NCM gadget and run 'iperf3 -s'.
    At host, run 'iperf3 -V -c fe80::6863:98ff:feef:3e0%enxc6e147509498'

    [  5]   0.00-1.00   sec  1.55 MBytes  13.0 Mbits/sec   90   4.18 KBytes
    [  5]   1.00-2.00   sec  1.44 MBytes  12.0 Mbits/sec   75   4.18 KBytes
    [  5]   2.00-3.00   sec  1.48 MBytes  12.4 Mbits/sec   75   4.18 KBytes

    Expected speed should be bigger than 300Mbits/sec.

    The root cause of this performance drop was found to be data corruption
    happening at 4K borders in some Ethernet packets, leading to TCP
    checksum errors. This corruption occurs from the position
    (4K - (address & 0x7F)) to 4K. The u_ether function's allocation of
    skb_buff reserves 64B, meaning all RX addresses resemble 0xXXXX0040.

    Force trb_burst_size to 16 can fix this problem.

    Cc: stable@vger.kernel.org
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Link: https://lore.kernel.org/r/20230518154946.3666662-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:43 +01:00
Martin McConnell 6b884c2a40 usb: cdns3-ti: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit defbfca6945ec5f3362e15ee4ec15180117240c3
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Thu May 18 01:01:06 2023 +0200

    usb: cdns3-ti: Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is ignored (apart from
    emitting a warning) and this typically results in resource leaks. To improve
    here there is a quest to make the remove callback return void. In the first
    step of this quest all drivers are converted to .remove_new() which already
    returns void. Eventually after all drivers are converted, .remove_new() is
    renamed to .remove().

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Link: https://lore.kernel.org/r/20230517230239.187727-5-u.kleine-koenig@pengutronix.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:42 +01:00
Martin McConnell a34e200104 usb: cdns3-plat: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 5411fa0ec65626180e3eddeb30633fc5e2313c01
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Thu May 18 01:01:05 2023 +0200

    usb: cdns3-plat: Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is ignored (apart from
    emitting a warning) and this typically results in resource leaks. To improve
    here there is a quest to make the remove callback return void. In the first
    step of this quest all drivers are converted to .remove_new() which already
    returns void. Eventually after all drivers are converted, .remove_new() is
    renamed to .remove().

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Link: https://lore.kernel.org/r/20230517230239.187727-4-u.kleine-koenig@pengutronix.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:41 +01:00
Martin McConnell d9580d59ac usb: cdns3-imx: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit cfab1b8be9ab744d4b1064a8af59c758a2084b1d
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Thu May 18 01:01:04 2023 +0200

    usb: cdns3-imx: Convert to platform remove callback returning void

    The .remove() callback for a platform driver returns an int which makes
    many driver authors wrongly assume it's possible to do error handling by
    returning an error code. However the value returned is ignored (apart from
    emitting a warning) and this typically results in resource leaks. To improve
    here there is a quest to make the remove callback return void. In the first
    step of this quest all drivers are converted to .remove_new() which already
    returns void. Eventually after all drivers are converted, .remove_new() is
    renamed to .remove().

    Trivially convert this driver from always returning zero in the remove
    callback to the void returning variant.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Link: https://lore.kernel.org/r/20230517230239.187727-3-u.kleine-koenig@pengutronix.de
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:41 +01:00
Martin McConnell 4f829abb11 usb: cdnsp: Fixes error: uninitialized symbol 'len'
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 1edf48991a783d00a3a18dc0d27c88139e4030a2
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Fri Mar 31 05:06:00 2023 -0400

    usb: cdnsp: Fixes error: uninitialized symbol 'len'

    The patch 5bc38d33a5a1: "usb: cdnsp: Fixes issue with redundant
    Status Stage" leads to the following Smatch static checker warning:

      drivers/usb/cdns3/cdnsp-ep0.c:470 cdnsp_setup_analyze()
      error: uninitialized symbol 'len'.

    cc: <stable@vger.kernel.org>
    Fixes: 5bc38d33a5a1 ("usb: cdnsp: Fixes issue with redundant Status Stage")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20230331090600.454674-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:40 +01:00
Martin McConnell 95058af0bb usb: cdnsp: changes PCI Device ID to fix conflict with CNDS3 driver
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 96b96b2a567fb34dd41c87e6cf01f6902ce8cae4
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Mar 9 01:30:48 2023 -0500

    usb: cdnsp: changes PCI Device ID to fix conflict with CNDS3 driver

    Patch changes CDNS_DEVICE_ID in USBSSP PCI Glue driver to remove
    the conflict with Cadence USBSS driver.

    cc: <stable@vger.kernel.org>
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20230309063048.299378-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:40 +01:00
Martin McConnell 233806c7ac usb: cdns3: Fix issue with using incorrect PCI device function
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 1272fd652a226ccb34e9f47371b6121948048438
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Wed Mar 8 07:44:27 2023 -0500

    usb: cdns3: Fix issue with using incorrect PCI device function

    PCI based platform can have more than two PCI functions.
    USBSS PCI Glue driver during initialization should
    consider only DRD/HOST/DEVICE PCI functions and
    all other should be ignored. This patch adds additional
    condition which causes that only DRD and HOST/DEVICE
    function will be accepted.

    cc: <stable@vger.kernel.org>
    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20230308124427.311245-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:39 +01:00
Martin McConnell a8164564f2 usb: cdnsp: Fixes issue with redundant Status Stage
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 5bc38d33a5a1209fd4de65101d1ae8255ea12c6e
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Tue Mar 7 06:14:20 2023 -0500

    usb: cdnsp: Fixes issue with redundant Status Stage

    In some cases, driver trees to send Status Stage twice.
    The first one from upper layer of gadget usb subsystem and
    second time from controller driver.
    This patch fixes this issue and remove tricky handling of
    SET_INTERFACE from controller driver which is no longer
    needed.

    cc: <stable@vger.kernel.org>
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20230307111420.376056-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:38 +01:00
Martin McConnell 887b5b1df1 usb: cdns3: change some trace event __dynamic_array() to __get_buf()
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 47ebfd604f9b48e44d2f88caf527180463a2fb2c
Author: Linyu Yuan <quic_linyyuan@quicinc.com>
Date:   Mon Feb 27 10:44:08 2023 +0800

    usb: cdns3: change some trace event __dynamic_array() to __get_buf()

    some __dynamic_array() buffer will only used at trace event output time,
    change to __get_buf() which will allocate tempary trace seq buffer for
    output purpose.

    Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
    Link: https://lore.kernel.org/r/1677465850-1396-3-git-send-email-quic_linyyuan@quicinc.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:38 +01:00
Martin McConnell ba91922095 usb: cdns3: change trace event cdns3_ring() operation
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 195a58cb3617d46f274a8cb47ee151d74d39ce0e
Author: Linyu Yuan <quic_linyyuan@quicinc.com>
Date:   Mon Feb 27 10:44:07 2023 +0800

    usb: cdns3: change trace event cdns3_ring() operation

    the original design seem have several problems, first during trace event
    output stage, cdns3_dbg_ring() still refer to priv_ep->trb_pool which
    data content may changed during runtime, second when ring number is
    greater than TRBS_PER_SEGMENT, it has no change to show "too big" message,
    third in cdns3_log_ring event class definition, it allocate too much trace
    event buffer.

    change cdns3_dbg_ring() to be called at trace event fast assign time, and
    change trace buffer real dynamic according ring numbers.

    Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
    Link: https://lore.kernel.org/r/1677465850-1396-2-git-send-email-quic_linyyuan@quicinc.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:37 +01:00
Martin McConnell 17e1c751eb usb: cdnsp: : add scatter gather support for ISOC endpoint
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 82b0417e4bfc5af8c1710996913374f09f4a2a03
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Dec 22 04:09:34 2022 -0500

    usb: cdnsp: : add scatter gather support for ISOC endpoint

    Patch implements scatter gather support for isochronous endpoint.
    This fix is forced by 'commit e81e7f9a0eb9
    ("usb: gadget: uvc: add scatter gather support")'.
    After this fix CDNSP driver stop working with UVC class.

    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Reviewed-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20221222090934.145140-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:37 +01:00
Martin McConnell adaebb64de usb: cdns3: remove fetched trb from cache before dequeuing
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 1301c7b9f7efad2f11ef924e317c18ebd714fc9a
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Tue Nov 15 05:00:39 2022 -0500

    usb: cdns3: remove fetched trb from cache before dequeuing

    After doorbell DMA fetches the TRB. If during dequeuing request
    driver changes NORMAL TRB to LINK TRB but doesn't delete it from
    controller cache then controller will handle cached TRB and packet
    can be lost.

    The example scenario for this issue looks like:
    1. queue request - set doorbell
    2. dequeue request
    3. send OUT data packet from host
    4. Device will accept this packet which is unexpected
    5. queue new request - set doorbell
    6. Device lost the expected packet.

    By setting DFLUSH controller clears DRDY bit and stop DMA transfer.

    Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
    cc: <stable@vger.kernel.org>
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Acked-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20221115100039.441295-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:36 +01:00
Martin McConnell ebd7aa2163 usb: cdnsp: fix lack of ZLP for ep0
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit ae423ef5d095e09970f52c08020fdbf7f9d87c22
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Tue Nov 22 03:51:38 2022 -0500

    usb: cdnsp: fix lack of ZLP for ep0

    Patch implements the handling of ZLP for control transfer.
    To send the ZLP driver must prepare the extra TRB in TD with
    length set to zero and TRB type to TRB_NORMAL.
    The first TRB must have set TRB_CHAIN flag, TD_SIZE = 1
    and TRB type to TRB_DATA.

    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    cc: <stable@vger.kernel.org>
    Reviewed-by: Peter Chen <peter.chen@kernel.org>
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20221122085138.332434-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:35 +01:00
Martin McConnell 487b12085b usb: cdnsp: fix issue with ZLP - added TD_SIZE = 1
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 7a21b27aafa3edead79ed97e6f22236be6b9f447
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Tue Nov 15 04:22:18 2022 -0500

    usb: cdnsp: fix issue with ZLP - added TD_SIZE = 1

    Patch modifies the TD_SIZE in TRB before ZLP TRB.
    The TD_SIZE in TRB before ZLP TRB must be set to 1 to force
    processing ZLP TRB by controller.

    cc: <stable@vger.kernel.org>
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Reviewed-by: Peter Chen <peter.chen@kernel.org>
    Link: https://lore.kernel.org/r/20221115092218.421267-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:35 +01:00
Martin McConnell ba6da6882f usb: cdnsp: Fix issue with Clear Feature Halt Endpoint
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit b25264f22b498dff3fa5c70c9bea840e83fff0d1
Author: Pawel Laszczak <pawell@cadence.com>
Date:   Thu Nov 10 01:30:05 2022 -0500

    usb: cdnsp: Fix issue with Clear Feature Halt Endpoint

    During handling Clear Halt Endpoint Feature request, driver invokes
    Reset Endpoint command. Because this command has some issue with
    transition endpoint from Running to Idle state the driver must
    stop the endpoint by using Stop Endpoint command.

    cc: <stable@vger.kernel.org>
    Fixes: 3d82904559 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
    Reviewed-by: Peter Chen <peter.chen@kernel.org>
    Signed-off-by: Pawel Laszczak <pawell@cadence.com>
    Link: https://lore.kernel.org/r/20221110063005.370656-1-pawell@cadence.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:34 +01:00
Martin McConnell daccb910fb usb: cdns3: host: fix endless superspeed hub port reset
JIRA: https://issues.redhat.com/browse/RHEL-54566

commit 9d5333c931347005352d5b8beaa43528c94cfc9c
Author: Li Jun <jun.li@nxp.com>
Date:   Wed Oct 26 15:07:49 2022 -0400

    usb: cdns3: host: fix endless superspeed hub port reset

    When usb 3.0 hub connect with one USB 2.0 device and NO USB 3.0 device,
    some usb hub reports endless port reset message.

    [  190.324169] usb 2-1: new SuperSpeed USB device number 88 using xhci-hcd
    [  190.352834] hub 2-1:1.0: USB hub found
    [  190.356995] hub 2-1:1.0: 4 ports detected
    [  190.700056] usb 2-1: USB disconnect, device number 88
    [  192.472139] usb 2-1: new SuperSpeed USB device number 89 using xhci-hcd
    [  192.500820] hub 2-1:1.0: USB hub found
    [  192.504977] hub 2-1:1.0: 4 ports detected
    [  192.852066] usb 2-1: USB disconnect, device number 89

    The reason is the runtime pm state of USB2.0 port is active and
    USB 3.0 port is suspend, so parent device is active state.

     cat /sys/bus/platform/devices/5b110000.usb/5b130000.usb/xhci-hcd.1.auto/usb2/power/runtime_status

     suspended

     cat /sys/bus/platform/devices/5b110000.usb/5b130000.usb/xhci-hcd.1.auto/usb1/power/runtime_status

     active

     cat /sys/bus/platform/devices/5b110000.usb/5b130000.usb/xhci-hcd.1.auto/power/runtime_status

     active

     cat /sys/bus/platform/devices/5b110000.usb/5b130000.usb/power/runtime_status

     active

    So xhci_cdns3_suspend_quirk() have not called. U3 configure is not applied.

    move U3 configure into host start. Reinit again in resume function in case
    controller power lost during suspend.

    Cc: stable@vger.kernel.org 5.10
    Signed-off-by: Li Jun <jun.li@nxp.com>
    Signed-off-by: Frank Li <Frank.Li@nxp.com>
    Reviewed-by: Peter Chen <peter.chen@kernel.org>
    Acked-by: Alexander Stein <alexander.stein@ew.tq-group.com>
    Link: https://lore.kernel.org/r/20221026190749.2280367-1-Frank.Li@nxp.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Martin McConnell <mmcconne@redhat.com>
2024-08-30 12:20:34 +01:00