From 8224b79008c1bcc349e2d565c24e11aa78672ea8 Mon Sep 17 00:00:00 2001 From: William Wu Date: Fri, 4 Jan 2019 11:30:20 +0800 Subject: [PATCH] usb: dwc3: add a new xhci trb ent quirk for xHCI On some xHCI controllers (e.g. Rockchip RK3399/RK3328/RK1808), which are integrated in DWC3 IP, need to enable the Evaluate Next TRB(ENT) flag in the TRB data structure to force xHC to pre-fetch the next TRB of a TD. It's useful for the stability of xHCI when transfer large data. I have verify this patch on the following three cases: Case 1: On RK3399/RK3399Pro platforms, I found that when USB 3.0 read/write at the same time in the following test case, it may easily fail without this patch. Host transfer: 1024B, 4MB, 4MB, 4MB Device transfer: 1024B, 4MB, 4MB, 4MB Both Host and Device transfer "24B, 4MB, 4MB, 4M" Repeatedly until transfer fail. Case 2: On RK3399 platform, Type-C1 USB 3.0 port connects with HUB and Orbbec USB 3.0 Camera with the enumeration information: usb 5-1: new high-speed USB device number 2 using xhci-hcd usb 5-1: New USB device found, idVendor=05e3, idProduct=0610 usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 5-1: Product: USB2.1 Hub usb 5-1: Manufacturer: GenesysLogic hub 5-1:1.0: USB hub found hub 5-1:1.0: 2 ports detected usb 6-1: new SuperSpeed USB device number 2 using xhci-hcd usb 6-1: New USB device found, idVendor=05e3, idProduct=0620 usb 6-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 6-1: Product: USB3.1 Hub usb 6-1: Manufacturer: GenesysLogic hub 6-1:1.0: USB hub found hub 6-1:1.0: 2 ports detected usb 5-1.2: new high-speed USB device number 3 using xhci-hcd usb 5-1.2: New USB device found, idVendor=2bc5, idProduct=050d usb 5-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=3 usb 5-1.2: Product: USB usb 5-1.2: Manufacturer: USB usb 5-1.2: SerialNumber: USB uvcvideo: Found UVC 1.00 device USB (2bc5:050d) usb 6-1.2: new SuperSpeed USB device number 3 using xhci-hcd usb 6-1.2: New USB device found, idVendor=2bc5, idProduct=060d usb 6-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 6-1.2: Product: Orbbec(R) Astra(TM) usb 6-1.2: Manufacturer: Orbbec(R) Without this patch, it's possible to fail to open the Orbbec USB 3.0 camera or fail to preview image. Case3: On RK3399Pro platform, transfer the NPU data between the NPU USB 3.0 device and RK3399 USB 3.0 host. Change-Id: I87b1d8b8b6912d77b988362f2f6dcd7766da8b0e Signed-off-by: William Wu --- drivers/usb/dwc3/core.c | 2 ++ drivers/usb/dwc3/core.h | 4 ++++ drivers/usb/dwc3/host.c | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 79b789444fee..fa6df9fbf005 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1289,6 +1289,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) "snps,dis-tx-ipgap-linecheck-quirk"); dwc->xhci_slow_suspend_quirk = device_property_read_bool(dev, "snps,xhci-slow-suspend-quirk"); + dwc->xhci_trb_ent_quirk = device_property_read_bool(dev, + "snps,xhci-trb-ent-quirk"); dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, "snps,tx_de_emphasis_quirk"); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 232ccd02a775..f286396d6efb 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -995,6 +995,9 @@ struct dwc3_scratchpad_array { * @xhci_slow_suspend_quirk: set if need an extraordinary delay to wait * for xHC enter the Halted state after the Run/Stop * (R/S) bit is cleared to '0'. + * @xhci_trb_ent_quirk: set if need to enable the Evaluate Next TRB(ENT) + flag in the TRB data structure to force xHC to + pre-fetch the next TRB of a TD. * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk * @tx_de_emphasis: Tx de-emphasis value * 0 - -6dB de-emphasis @@ -1168,6 +1171,7 @@ struct dwc3 { unsigned dis_del_phy_power_chg_quirk:1; unsigned dis_tx_ipgap_linecheck_quirk:1; unsigned xhci_slow_suspend_quirk:1; + unsigned xhci_trb_ent_quirk:1; unsigned tx_de_emphasis_quirk:1; unsigned tx_de_emphasis:2; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 3c3b3ba4b50f..b50c410ec71b 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -46,7 +46,7 @@ out: int dwc3_host_init(struct dwc3 *dwc) { - struct property_entry props[3]; + struct property_entry props[4]; struct platform_device *xhci; int ret, irq; struct resource *res; @@ -96,6 +96,9 @@ int dwc3_host_init(struct dwc3 *dwc) if (dwc->xhci_slow_suspend_quirk) props[prop_idx++].name = "xhci-slow-suspend"; + if (dwc->xhci_trb_ent_quirk) + props[prop_idx++].name = "xhci-trb-ent-quirk"; + /** * WORKAROUND: dwc3 revisions <=3.00a have a limitation * where Port Disable command doesn't work.