Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xhci: add quirk for host controllers that don't update endpoint DCS

Seen on a VLI VL805 PCIe to USB controller. For non-stream endpoints
at least, if the xHC halts on a particular TRB due to an error then
the DCS field in the Out Endpoint Context maintained by the hardware
is not updated with the current cycle state.

Using the quirk XHCI_EP_CTX_BROKEN_DCS and instead fetch the DCS bit
from the TRB that the xHC stopped on.

[ bjorn: rebased to v5.14-rc2 ]

Link: https://github.com/raspberrypi/linux/issues/3060
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Bell <jonathan@raspberrypi.org>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20211008092547.3996295-3-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jonathan Bell and committed by
Greg Kroah-Hartman
5255660b a01ba2a3

+28 -2
+3 -1
drivers/usb/host/xhci-pci.c
··· 279 279 pdev->device == 0x3432) 280 280 xhci->quirks |= XHCI_BROKEN_STREAMS; 281 281 282 - if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) 282 + if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) { 283 283 xhci->quirks |= XHCI_LPM_SUPPORT; 284 + xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS; 285 + } 284 286 285 287 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && 286 288 pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI)
+24 -1
drivers/usb/host/xhci-ring.c
··· 559 559 struct xhci_ring *ep_ring; 560 560 struct xhci_command *cmd; 561 561 struct xhci_segment *new_seg; 562 + struct xhci_segment *halted_seg = NULL; 562 563 union xhci_trb *new_deq; 563 564 int new_cycle; 565 + union xhci_trb *halted_trb; 566 + int index = 0; 564 567 dma_addr_t addr; 565 568 u64 hw_dequeue; 566 569 bool cycle_found = false; ··· 601 598 hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id); 602 599 new_seg = ep_ring->deq_seg; 603 600 new_deq = ep_ring->dequeue; 604 - new_cycle = hw_dequeue & 0x1; 601 + 602 + /* 603 + * Quirk: xHC write-back of the DCS field in the hardware dequeue 604 + * pointer is wrong - use the cycle state of the TRB pointed to by 605 + * the dequeue pointer. 606 + */ 607 + if (xhci->quirks & XHCI_EP_CTX_BROKEN_DCS && 608 + !(ep->ep_state & EP_HAS_STREAMS)) 609 + halted_seg = trb_in_td(xhci, td->start_seg, 610 + td->first_trb, td->last_trb, 611 + hw_dequeue & ~0xf, false); 612 + if (halted_seg) { 613 + index = ((dma_addr_t)(hw_dequeue & ~0xf) - halted_seg->dma) / 614 + sizeof(*halted_trb); 615 + halted_trb = &halted_seg->trbs[index]; 616 + new_cycle = halted_trb->generic.field[3] & 0x1; 617 + xhci_dbg(xhci, "Endpoint DCS = %d TRB index = %d cycle = %d\n", 618 + (u8)(hw_dequeue & 0x1), index, new_cycle); 619 + } else { 620 + new_cycle = hw_dequeue & 0x1; 621 + } 605 622 606 623 /* 607 624 * We want to find the pointer, segment and cycle state of the new trb
+1
drivers/usb/host/xhci.h
··· 1899 1899 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39) 1900 1900 #define XHCI_NO_SOFT_RETRY BIT_ULL(40) 1901 1901 #define XHCI_BROKEN_D3COLD BIT_ULL(41) 1902 + #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42) 1902 1903 1903 1904 unsigned int num_active_eps; 1904 1905 unsigned int limit_active_eps;