950-0145-xhci-add-quirk-for-host-controllers-that-don-t-updat.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. From e47ad4978bde4920c1e1eb381531a6904025c852 Mon Sep 17 00:00:00 2001
  2. From: Jonathan Bell <[email protected]>
  3. Date: Thu, 11 Jul 2019 17:55:43 +0100
  4. Subject: [PATCH] xhci: add quirk for host controllers that don't
  5. update endpoint DCS
  6. Seen on a VLI VL805 PCIe to USB controller. For non-stream endpoints
  7. at least, if the xHC halts on a particular TRB due to an error then
  8. the DCS field in the Out Endpoint Context maintained by the hardware
  9. is not updated with the current cycle state.
  10. Using the quirk XHCI_EP_CTX_BROKEN_DCS and instead fetch the DCS bit
  11. from the TRB that the xHC stopped on.
  12. See: https://github.com/raspberrypi/linux/issues/3060
  13. Signed-off-by: Jonathan Bell <[email protected]>
  14. ---
  15. drivers/usb/host/xhci-pci.c | 4 +++-
  16. drivers/usb/host/xhci-ring.c | 26 +++++++++++++++++++++++++-
  17. drivers/usb/host/xhci.h | 1 +
  18. 3 files changed, 29 insertions(+), 2 deletions(-)
  19. --- a/drivers/usb/host/xhci-pci.c
  20. +++ b/drivers/usb/host/xhci-pci.c
  21. @@ -276,8 +276,10 @@ static void xhci_pci_quirks(struct devic
  22. pdev->device == 0x3432)
  23. xhci->quirks |= XHCI_BROKEN_STREAMS;
  24. - if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483)
  25. + if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
  26. xhci->quirks |= XHCI_LPM_SUPPORT;
  27. + xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS;
  28. + }
  29. if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
  30. pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI)
  31. --- a/drivers/usb/host/xhci-ring.c
  32. +++ b/drivers/usb/host/xhci-ring.c
  33. @@ -562,7 +562,10 @@ void xhci_find_new_dequeue_state(struct
  34. struct xhci_virt_ep *ep = &dev->eps[ep_index];
  35. struct xhci_ring *ep_ring;
  36. struct xhci_segment *new_seg;
  37. + struct xhci_segment *halted_seg = NULL;
  38. union xhci_trb *new_deq;
  39. + union xhci_trb *halted_trb;
  40. + int index = 0;
  41. dma_addr_t addr;
  42. u64 hw_dequeue;
  43. bool cycle_found = false;
  44. @@ -600,7 +603,28 @@ void xhci_find_new_dequeue_state(struct
  45. hw_dequeue = xhci_get_hw_deq(xhci, dev, ep_index, stream_id);
  46. new_seg = ep_ring->deq_seg;
  47. new_deq = ep_ring->dequeue;
  48. - state->new_cycle_state = hw_dequeue & 0x1;
  49. +
  50. + /*
  51. + * Quirk: xHC write-back of the DCS field in the hardware dequeue
  52. + * pointer is wrong - use the cycle state of the TRB pointed to by
  53. + * the dequeue pointer.
  54. + */
  55. + if (xhci->quirks & XHCI_EP_CTX_BROKEN_DCS &&
  56. + !(ep->ep_state & EP_HAS_STREAMS))
  57. + halted_seg = trb_in_td(xhci, cur_td->start_seg,
  58. + cur_td->first_trb, cur_td->last_trb,
  59. + hw_dequeue & ~0xf, false);
  60. + if (halted_seg) {
  61. + index = ((dma_addr_t)(hw_dequeue & ~0xf) - halted_seg->dma) /
  62. + sizeof(*halted_trb);
  63. + halted_trb = &halted_seg->trbs[index];
  64. + state->new_cycle_state = halted_trb->generic.field[3] & 0x1;
  65. + xhci_dbg(xhci, "Endpoint DCS = %d TRB index = %d cycle = %d\n",
  66. + (u8)(hw_dequeue & 0x1), index,
  67. + state->new_cycle_state);
  68. + } else {
  69. + state->new_cycle_state = hw_dequeue & 0x1;
  70. + }
  71. state->stream_id = stream_id;
  72. /*
  73. --- a/drivers/usb/host/xhci.h
  74. +++ b/drivers/usb/host/xhci.h
  75. @@ -1884,6 +1884,7 @@ struct xhci_hcd {
  76. #define XHCI_DISABLE_SPARSE BIT_ULL(38)
  77. #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39)
  78. #define XHCI_NO_SOFT_RETRY BIT_ULL(40)
  79. +#define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(41)
  80. unsigned int num_active_eps;
  81. unsigned int limit_active_eps;