From: Ole Salscheider <ole@salscheider.org>
To: linux-usb@vger.kernel.org
Cc: Mathias Nyman <mathias.nyman@intel.com>,
Ole Salscheider <ole@salscheider.org>
Subject: [PATCH] [RFC] xhci: Add Link TRB sync quirk for ASM3142
Date: Fri, 16 Apr 2021 11:37:29 +0200 [thread overview]
Message-ID: <20210416093729.41865-1-ole@salscheider.org> (raw)
This patch adds a quirk to the xhci driver so that link TRBs are only
given to the host controller once it has processed all previous TRBs on
this segment.
This quirk is necessary for me on an ASMedia ASM3142 host controller.
Without it, I get the following errors when accessing a SuperSpeed UVC
camera:
Transfer event TRB DMA ptr not part of current TD ep_index XX comp_code XX
You can find more details in my previous mail about the problem:
https://lkml.org/lkml/2021/3/31/355
This patch fixes my problem, but it is probably terribly wrong. I am not
even sure if I can rely on handle_tx_event being called before each link
TRB in the segment. Some feedback would be very welcome.
---
drivers/usb/host/xhci-pci.c | 4 +++-
drivers/usb/host/xhci-ring.c | 34 ++++++++++++++++++++++++++++++----
drivers/usb/host/xhci.h | 1 +
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 5bbccc9a0179..4b02ac34934e 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -284,8 +284,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
(pdev->device == PCI_DEVICE_ID_ASMEDIA_1142_XHCI ||
pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI ||
- pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
+ pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI)) {
xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
+ xhci->quirks |= XHCI_SYNC_ON_LINK_TRB;
+ }
if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index ce38076901e2..17f9484f1b0d 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -257,8 +257,13 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring,
next->link.control |= cpu_to_le32(chain);
}
/* Give this link TRB to the hardware */
- wmb();
- next->link.control ^= cpu_to_le32(TRB_CYCLE);
+ if (!(xhci->quirks & XHCI_SYNC_ON_LINK_TRB) ||
+ (ring->type != TYPE_BULK &&
+ ring->type != TYPE_STREAM &&
+ ring->type != TYPE_COMMAND)) {
+ wmb();
+ next->link.control ^= cpu_to_le32(TRB_CYCLE);
+ }
/* Toggle the cycle bit after the last ring segment. */
if (link_trb_toggles_cycle(next))
@@ -2530,6 +2535,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
dma_addr_t ep_trb_dma;
struct xhci_segment *ep_seg;
union xhci_trb *ep_trb;
+ union xhci_trb *next_ep_trb;
+ int next_ep_trb_idx;
int status = -EINPROGRESS;
struct xhci_ep_ctx *ep_ctx;
struct list_head *tmp;
@@ -2860,6 +2867,20 @@ static int handle_tx_event(struct xhci_hcd *xhci,
else
process_bulk_intr_td(xhci, td, ep_trb, event, ep);
cleanup:
+ if (xhci->quirks & XHCI_SYNC_ON_LINK_TRB &&
+ (ep_ring->type == TYPE_BULK ||
+ ep_ring->type == TYPE_STREAM ||
+ ep_ring->type == TYPE_COMMAND)) {
+ next_ep_trb_idx = (ep_trb_dma - ep_seg->dma) /
+ sizeof(*ep_trb) + 1;
+ next_ep_trb = ep_trb = &ep_seg->trbs[next_ep_trb_idx];
+ if (next_ep_trb_idx < TRBS_PER_SEGMENT &&
+ trb_is_link(next_ep_trb)) {
+ wmb();
+ next_ep_trb->link.control ^= cpu_to_le32(TRB_CYCLE);
+ }
+ }
+
handling_skipped_tds = ep->skip &&
trb_comp_code != COMP_MISSED_SERVICE_ERROR &&
trb_comp_code != COMP_NO_PING_RESPONSE_ERROR;
@@ -3192,8 +3213,13 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
ep_ring->enqueue->link.control |=
cpu_to_le32(TRB_CHAIN);
- wmb();
- ep_ring->enqueue->link.control ^= cpu_to_le32(TRB_CYCLE);
+ if (!(xhci->quirks & XHCI_SYNC_ON_LINK_TRB) ||
+ (ep_ring->type != TYPE_BULK &&
+ ep_ring->type != TYPE_STREAM &&
+ ep_ring->type != TYPE_COMMAND)) {
+ wmb();
+ ep_ring->enqueue->link.control ^= cpu_to_le32(TRB_CYCLE);
+ }
/* Toggle the cycle bit after the last ring segment. */
if (link_trb_toggles_cycle(ep_ring->enqueue))
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ca822ad3b65b..fd98f86cde37 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1892,6 +1892,7 @@ struct xhci_hcd {
#define XHCI_DISABLE_SPARSE BIT_ULL(38)
#define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39)
#define XHCI_NO_SOFT_RETRY BIT_ULL(40)
+#define XHCI_SYNC_ON_LINK_TRB BIT_ULL(41)
unsigned int num_active_eps;
unsigned int limit_active_eps;
--
2.25.1
next reply other threads:[~2021-04-16 9:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 9:37 Ole Salscheider [this message]
2021-04-16 9:56 ` [PATCH] [RFC] xhci: Add Link TRB sync quirk for ASM3142 Greg KH
2021-04-16 12:09 ` Mathias Nyman
2021-04-16 15:18 ` Ole Salscheider
2021-04-19 10:52 ` Ole Salscheider
2021-04-19 14:43 ` Mathias Nyman
2021-04-19 19:05 ` Ole Salscheider
2021-04-21 7:28 ` Mathias Nyman
2021-04-21 8:45 ` Ole Salscheider
2021-05-05 7:56 ` Ole Salscheider
2021-05-06 9:08 ` Mathias Nyman
2021-05-09 0:01 ` Forest Crossman
2021-05-09 7:31 ` Ole Salscheider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210416093729.41865-1-ole@salscheider.org \
--to=ole@salscheider.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).