1 From 3eecda8f1b9f2cb03234208f06592bc88ededc37 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Mon, 7 Mar 2022 16:18:55 +0000
4 Subject: [PATCH] xhci: add quirk for host controllers that don't update
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Seen on a VLI VL805 PCIe to USB controller. For non-stream endpoints
11 at least, if the xHC halts on a particular TRB due to an error then
12 the DCS field in the Out Endpoint Context maintained by the hardware
13 is not updated with the current cycle state.
15 Using the quirk XHCI_EP_CTX_BROKEN_DCS and instead fetch the DCS bit
16 from the TRB that the xHC stopped on.
18 [ bjorn: rebased to v5.14-rc2 ]
20 Link: https://github.com/raspberrypi/linux/issues/3060
21 Cc: stable@vger.kernel.org
22 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.org>
23 Signed-off-by: Bjørn Mork <bjorn@mork.no>
24 Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
25 Link: https://lore.kernel.org/r/20211008092547.3996295-3-mathias.nyman@linux.intel.com
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28 drivers/usb/host/xhci-pci.c | 1 +
29 drivers/usb/host/xhci-ring.c | 23 ++++++++++++++++++++++-
30 2 files changed, 23 insertions(+), 1 deletion(-)
32 --- a/drivers/usb/host/xhci-pci.c
33 +++ b/drivers/usb/host/xhci-pci.c
34 @@ -429,6 +429,7 @@ static void xhci_pci_quirks(struct devic
35 if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == PCI_DEVICE_ID_VIA_VL805) {
36 xhci->quirks |= XHCI_LPM_SUPPORT;
37 xhci->quirks |= XHCI_TRB_OVERFETCH;
38 + xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS;
41 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
42 --- a/drivers/usb/host/xhci-ring.c
43 +++ b/drivers/usb/host/xhci-ring.c
44 @@ -638,8 +638,11 @@ static int xhci_move_dequeue_past_td(str
45 struct xhci_ring *ep_ring;
46 struct xhci_command *cmd;
47 struct xhci_segment *new_seg;
48 + struct xhci_segment *halted_seg = NULL;
49 union xhci_trb *new_deq;
51 + union xhci_trb *halted_trb;
55 bool cycle_found = false;
56 @@ -658,7 +661,25 @@ static int xhci_move_dequeue_past_td(str
57 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id);
58 new_seg = ep_ring->deq_seg;
59 new_deq = ep_ring->dequeue;
60 - new_cycle = hw_dequeue & 0x1;
63 + * Quirk: xHC write-back of the DCS field in the hardware dequeue
64 + * pointer is wrong - use the cycle state of the TRB pointed to by
65 + * the dequeue pointer.
67 + if (xhci->quirks & XHCI_EP_CTX_BROKEN_DCS &&
68 + !(ep->ep_state & EP_HAS_STREAMS))
69 + halted_seg = trb_in_td(xhci, td, hw_dequeue & ~0xf, false);
71 + index = ((dma_addr_t)(hw_dequeue & ~0xf) - halted_seg->dma) /
72 + sizeof(*halted_trb);
73 + halted_trb = &halted_seg->trbs[index];
74 + new_cycle = halted_trb->generic.field[3] & 0x1;
75 + xhci_dbg(xhci, "Endpoint DCS = %d TRB index = %d cycle = %d\n",
76 + (u8)(hw_dequeue & 0x1), index, new_cycle);
78 + new_cycle = hw_dequeue & 0x1;
82 * We want to find the pointer, segment and cycle state of the new trb