Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936760AbdLSKfY (ORCPT ); Tue, 19 Dec 2017 05:35:24 -0500 Received: from mail-bl2nam02on0082.outbound.protection.outlook.com ([104.47.38.82]:43722 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932699AbdLSKfT (ORCPT ); Tue, 19 Dec 2017 05:35:19 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: To: Felipe Balbi , Greg Kroah-Hartman , Mathias Nyman , "open list:DESIGNWARE USB3 DRD IP DRIVER" , open list CC: , , , "yinbo . zhu" Subject: [PATCH v4 1/3] usb: host: Implement workaround for Erratum A-007463 Date: Tue, 19 Dec 2017 18:16:16 +0800 Message-ID: <20171219101618.45650-1-yinbo.zhu@nxp.com> X-Mailer: git-send-email 2.14.1 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131581533048970423;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(336005)(376002)(39380400002)(346002)(396003)(39860400002)(2980300002)(1110001)(1109001)(339900001)(189003)(199004)(54906003)(5660300001)(86362001)(97736004)(498600001)(36756003)(68736007)(53936002)(50466002)(51416003)(8676002)(575784001)(8656006)(85426001)(81156014)(81166006)(305945005)(356003)(4326008)(104016004)(59450400001)(551934003)(105606002)(106466001)(86152003)(2906002)(48376002)(1076002)(47776003)(8936002)(316002)(2876002)(50226002)(16586007)(110136005)(77096006);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB2363;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD027;1:eGtdLckNZG6RXtbCcTmvhrkpdCH6+8ugudiAP89wYcJ+rknzpyvaifnJb06bjluD6ZAUKwZIpUJbv3hw7v8c7v4ey3KZ6FujKG+H7r/jVdKvYPD0ClnhsAbcqt4wkeU6 MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 4a9c6952-bb97-40f0-9cb7-08d546cc2ad9 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4628075)(201703131517081)(2017052603307);SRVR:CY1PR03MB2363; X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2363;3:VNsoYGe/hDA5jg8TZz4m+zsnk+bxkDUsVtr9Wxnm8M1bOsfU0/x45gwpA3ib0KYbW3fw4g6CqV8HxVx0Gvi6CrYNHki6pRWuUtJo7QSEOgClNK69IRlq0efpgNjuXntfIPXIzdCA2npr6qiPm3KYBsQOv5hdJ4sPuUrU86raHJA2JngzCAMnetAsKJaj240BCbAd0OCWY2EI8VtQeORUBeEPACLqfuZwDt9FXX3VfC2FGnOG0/dUNy6qsTimraqegV9R+ZSpoBrJ38+UW9TkV6xKWGBMFA8MqjHyoM+6BptULWxrDG3NG6yQrZsBVWSOIvZ50pmn5kGM4MpobWgCge2wDeZBp5nO/e872T5kOUA=;25:jdS6qye2JtLDcRoMH/F4r1hV7iSbdCgNhTC8avzBj5DPZiIU9TRhUAPlMbywcgonBlEjasULZtf1IK+UgRa9rGVU+z7+boPaDUTkbIT7x5W3YwB5f8YIMOpMEF+gfxAgT03qVmgTNxdCRM2mJ/EVtCm2xDpxIJX2df0v8DlsmRDxZG6yRoTswjwji28zDT9/sdVKCe+vHDwOe9Q7u/bCkRbYKQ6nVhxQ8ude90HPettdX42NRVNoiTLmN0lnYtGz/BHevFm6VKP3XK6DzXrAy/l1fBrtpUhCqwK3/a/Wt6eRrXYaXslSRI9hDUUGSainTpMNxox4KaaHbzqGZt9F//c/o1kTY8bb2ETt68nwAHw= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY1PR03MB2363: X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2363;31:SfETkSfbl1g4VwloI7IOt8rcysYZVZHy13ENO+5qxgX5dhz4gnY8J5b26GVlKsswu962ylYakgH6EWzyttHGFmWPpOkvkvPSGHKl4kfV+hGOaJSm++8KlO/ZSzLEmhdFHVO7MZb4V3MxXTyRxkSwsa+DEQY9fHCFOoyfGUOwwovRPAn+ndJLGaFfLlzWu2XC3M6kqEElLuALqR8Tjy8MfQJ4kzVVZpsShbDRaj7YHcQ=;4:UPFRzy7/7Fimq2y5XyT4GZ4eLRB4jvhBmKZKyl/FSPvuKLmxk3U3Y3vKbMnFRIMKHNCv3sxxa3KLrb0O+gCQ20A/BkCbXEG8azpGmLlbqoVAnOuSHjjJnG0Bm9jZegNucZyUZIcQ7R92V9mL80ct8IQ8VuP+dF4jLZSDsKr7l5+CGR1GEXAvqKraM+g3+epGnv6pdH84Gl85MGjPyi3DrjWkMnrqLRVidviAYNfj3mh1bHP4FXrLBpCe2yzeS3xiAbclUFYL2TGpeo6QyprnTGOmpEayQVzuJcDDm4vDw94cTDEqPPlgilATBYelZtEfkAuvWnpqwFGrCvs6Z2AnoKWKSdEUigfUJfo+qgw1768= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(20558992708506)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095135)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3231023)(3002001)(6055026)(6096035)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123556025)(20161123565025)(20161123561025)(20161123563025)(201708071742011);SRVR:CY1PR03MB2363;BCL:0;PCL:0;RULEID:(100000803101)(100110400095)(400006);SRVR:CY1PR03MB2363; X-Forefront-PRVS: 052670E5A4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR03MB2363;23:pdli5+yGhNp6u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hfob0nBgbBaNkjzvvU1VWhHXuTAR7cgN+rYG8hHl8wrlMTjxiuzKIqtkSfO8CvPXGIud9CV/FhqqpJhepThPvasH60gfk3GfBHqzZp2PNgEo20WvPL84ty4Qp1LI27n0dylo1umtyoy2IG+r9g239iIRTZFVgz/crQM1H9iWIxQrVlKdXn9Y4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2017 10:35:04.7254 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a9c6952-bb97-40f0-9cb7-08d546cc2ad9 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2363 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8951 Lines: 220 From: yinbo.zhu When a transaction error (defined in Section 4.10.2.3, "USB Transaction Error" of the xHCI Specification) occurs on the USB, the host controller reports this through a transfer event with the completion code "USB Transaction Error". When this happens, the endpoint is placed in the Halted state. In response, software must issue a Reset Endpoint command to transition the endpoint to the Stopped state. In order to restart the transfer, the driver can perform either of the following: a) Ring the doorbell again, which restarts the transfer from where it stopped, or b) Issue a Set TR (Transfer Ring) Dequeue Pointer command for the endpoint to start the transfer form a different Transfer Ring pointer Consider the following scenario: 1. The xHCI driver prepares a control transfer read to one of the device's control endpoints; 2. During the IN data stage, a transaction error occurs on the USB, causing a transfer event with the completion code "USB Transaction Error"; 3. The driver issues a Reset Endpoint command; 4. The driver rings the doorbell of the control endpoint to resume the transfer. In this scenario, the controller may reverse the direction of the data stage from IN to OUT. Instead of sending an ACK to the endpoint to poll for read data, it sends a Data Packet (DP) to the endpoint. It fetches the data from the data stage Transfer Request Block (TRB) that is being resumed, even though the data buffer is setup to receive data and not transmit it. NOTE This issue occurs only if the transaction error happens during an IN data stage. There is no issue if the transaction error happens during an OUT data stage. Impact: When this issue occurs, the device likely responds in one of the following ways: a) The device responds with a STALL because the data stage has unexpectedly changed directions. The controller then generates a Stall Error transfer event, to which software must issue a Reset Endpoint command followed by a Set TR Dequeue Pointer command pointing to a new Setup TRB to clear the STALL condition. b) The device does not respond to the inverted data stage and the transaction times out. The controller generates another USB Transaction Error transfer event, to which software likely performs a USB Reset to the device because it is unresponsive. It is not expected that any of these recovery steps will cause instability in the system because this recovery is part of a standard xHCI driver and could happen regardless of the defect. Another possible system-level impact is that the controller attempts to read from the memory location pointed at by the Data Stage TRB or a Normal TRB chained to it. associated with this TRB is intended to be written by the controller, but the controller reads from it instead. Normally, this does not cause a problem. However, if the system has some type of memory protection where this unexpected read is treated as a bus error, a problem. However, if the system has some type of memory it may cause the system to become unstable or to crash. Workaround: If a USB Transaction Error occurs during the IN data phase of a control transfer, the driver must use the Set TR Dequeue Pointer command to either restart the data Phase or restart the entire control transfer from the Setup phase. Configs Affected: LS1021-20-22A-R1.0, LS1021-20-22A-R2.007463 Signed-off-by: yinbo zhu --- Change in v4: Remove the point in "yinbo.zhu" drivers/usb/dwc3/core.c | 2 ++ drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/host.c | 3 +++ drivers/usb/host/xhci-plat.c | 3 +++ drivers/usb/host/xhci-ring.c | 28 +++++++++++++++++++++++----- drivers/usb/host/xhci.h | 3 ++- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 0783250..6613bc0 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1055,6 +1055,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->tx_de_emphasis_quirk = device_property_read_bool(dev, "snps,tx_de_emphasis_quirk"); + dwc->quirk_reverse_in_out = device_property_read_bool(dev, + "snps,quirk_reverse_in_out"); device_property_read_u8(dev, "snps,tx_de_emphasis", &tx_de_emphasis); device_property_read_string(dev, "snps,hsphy_interface", diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4a4a4c9..a263fdc 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -857,6 +857,7 @@ struct dwc3_scratchpad_array { * 1 - -3.5dB de-emphasis * 2 - No de-emphasis * 3 - Reserved + * @quirk_reverse_in_out: prevent tx fifo reverse the data direction * @imod_interval: set the interrupt moderation interval in 250ns * increments or 0 to disable. */ @@ -1009,6 +1010,7 @@ struct dwc3 { unsigned tx_de_emphasis_quirk:1; unsigned tx_de_emphasis:2; + unsigned quirk_reverse_in_out:1; u16 imod_interval; }; diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 1a3878a..dab5f49 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -90,6 +90,9 @@ int dwc3_host_init(struct dwc3 *dwc) memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props)); + if (dwc->quirk_reverse_in_out) + props[prop_idx++].name = "quirk-reverse-in-out"; + if (dwc->usb3_lpm_capable) props[prop_idx++].name = "usb3-lpm-capable"; diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 6f03830..fe71b92 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -266,6 +266,9 @@ static int xhci_plat_probe(struct platform_device *pdev) if (device_property_read_bool(sysdev, "usb3-lpm-capable")) xhci->quirks |= XHCI_LPM_SUPPORT; + if (device_property_read_bool(&pdev->dev, "quirk-reverse-in-out")) + xhci->quirks |= XHCI_REVERSE_IN_OUT; + if (device_property_read_bool(&pdev->dev, "quirk-broken-port-ped")) xhci->quirks |= XHCI_BROKEN_PORT_PED; diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index c629a0b..cac355a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1925,10 +1925,12 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, union xhci_trb *ep_trb, struct xhci_transfer_event *event, struct xhci_virt_ep *ep, int *status) { + struct xhci_dequeue_state deq_state; struct xhci_virt_device *xdev; struct xhci_ep_ctx *ep_ctx; struct xhci_ring *ep_ring; unsigned int slot_id; + u32 remaining; u32 trb_comp_code; int ep_index; @@ -1951,14 +1953,30 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, if (trb_comp_code == COMP_STALL_ERROR || xhci_requires_manual_halt_cleanup(xhci, ep_ctx, trb_comp_code)) { - /* Issue a reset endpoint command to clear the host side - * halt, followed by a set dequeue command to move the - * dequeue pointer past the TD. - * The class driver clears the device side halt later. + /*erratum A-007463: + *After transaction error, controller switches control transfer + *data stage from IN to OUT direction. */ - xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index, + remaining = EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)); + if (remaining && xhci_requires_manual_halt_cleanup(xhci, ep_ctx, + trb_comp_code) && + (xhci->quirks & XHCI_REVERSE_IN_OUT)) { + memset(&deq_state, 0, sizeof(deq_state)); + xhci_find_new_dequeue_state(xhci, slot_id, + ep_index, td->urb->stream_id, td, &deq_state); + xhci_queue_new_dequeue_state(xhci, slot_id, ep_index, + &deq_state); + xhci_ring_cmd_db(xhci); + } else { + /* Issue a reset endpoint command to clear the host side + * halt, followed by a set dequeue command to move the + * dequeue pointer past the TD. + * The class driver clears the device side halt later. + */ + xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index, ep_ring->stream_id, td, ep_trb, EP_HARD_RESET); + } } else { /* Update ring dequeue pointer */ while (ep_ring->dequeue != td->last_trb) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 96099a2..9f133a9 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1783,7 +1783,7 @@ struct xhci_hcd { #define XHCI_STATE_DYING (1 << 0) #define XHCI_STATE_HALTED (1 << 1) #define XHCI_STATE_REMOVING (1 << 2) - unsigned int quirks; + u64 quirks; #define XHCI_LINK_TRB_QUIRK (1 << 0) #define XHCI_RESET_EP_QUIRK (1 << 1) #define XHCI_NEC_HOST (1 << 2) @@ -1819,6 +1819,7 @@ struct xhci_hcd { #define XHCI_SSIC_PORT_UNUSED (1 << 22) #define XHCI_NO_64BIT_SUPPORT (1 << 23) #define XHCI_MISSING_CAS (1 << 24) +#define XHCI_REVERSE_IN_OUT BIT(32) /* For controller with a broken Port Disable implementation */ #define XHCI_BROKEN_PORT_PED (1 << 25) #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26) -- 1.7.1