From patchwork Sat Oct 13 13:14:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anurag Kumar Vulisha X-Patchwork-Id: 10640141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41CDF933 for ; Sat, 13 Oct 2018 13:15:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D2ED2AF4D for ; Sat, 13 Oct 2018 13:15:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E50C2AF52; Sat, 13 Oct 2018 13:15:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96C302AF4D for ; Sat, 13 Oct 2018 13:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726911AbeJMUwm (ORCPT ); Sat, 13 Oct 2018 16:52:42 -0400 Received: from mail-eopbgr690048.outbound.protection.outlook.com ([40.107.69.48]:6146 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726399AbeJMUwj (ORCPT ); Sat, 13 Oct 2018 16:52:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MHrVLkNN0xdPfRpHRQ+2pGAHilJKSlasnaYCxqr8070=; b=WlHHN3OU1ft6TDEHHQQ2BuzNSFz5lrTFBRjuMKhJk/E+8cBMXQaqsSfqTq2hFCtI6NHDk+FInmHuhR1Zh1hL4SfiCEmPknPSmS+2cisKHJwulDaBHA2LUtotAhFsa+LbbyaGwI57aOCsW565OHuhSH83aCDGe1piViiwWv27wek= Received: from BN7PR02CA0028.namprd02.prod.outlook.com (2603:10b6:408:20::41) by DM5PR0201MB3510.namprd02.prod.outlook.com (2603:10b6:4:77::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.21; Sat, 13 Oct 2018 13:15:27 +0000 Received: from CY1NAM02FT027.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::204) by BN7PR02CA0028.outlook.office365.com (2603:10b6:408:20::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1228.23 via Frontend Transport; Sat, 13 Oct 2018 13:15:26 +0000 Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by CY1NAM02FT027.mail.protection.outlook.com (10.152.75.159) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.1250.11 via Frontend Transport; Sat, 13 Oct 2018 13:15:20 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:58073 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1gBJlH-0001Gh-Lg; Sat, 13 Oct 2018 06:15:19 -0700 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1gBJlC-0007wb-Eo; Sat, 13 Oct 2018 06:15:14 -0700 Received: from xsj-pvapsmtp01 (xsj-smtp1.xilinx.com [149.199.38.66]) by xsj-smtp-dlp2.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id w9DDF5bs019356; Sat, 13 Oct 2018 06:15:05 -0700 Received: from [172.23.64.8] (helo=xhdvnc108.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1gBJl2-0007oM-QO; Sat, 13 Oct 2018 06:15:05 -0700 Received: by xhdvnc108.xilinx.com (Postfix, from userid 15427) id CC47960503; Sat, 13 Oct 2018 18:45:03 +0530 (IST) From: Anurag Kumar Vulisha To: Felipe Balbi , Greg Kroah-Hartman , Alan Stern , Johan Hovold , Jaejoong Kim , Benjamin Herrenschmidt , Roger Quadros CC: , , , Thinh Nguyen , Tejas Joglekar , Ajay Yugalkishore Pandey , Anurag Kumar Vulisha Subject: [PATCH V6 02/10] usb: dwc3: gadget: Add stream timeout handler for avoiding deadlock Date: Sat, 13 Oct 2018 18:44:49 +0530 Message-ID: <1539436498-24892-3-git-send-email-anurag.kumar.vulisha@xilinx.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1539436498-24892-1-git-send-email-anurag.kumar.vulisha@xilinx.com> References: <1539436498-24892-1-git-send-email-anurag.kumar.vulisha@xilinx.com> X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.2.0.1013-23620.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(376002)(136003)(39860400002)(346002)(2980300002)(438002)(189003)(199004)(50226002)(76176011)(26005)(186003)(305945005)(6346003)(106002)(16586007)(54906003)(110136005)(81166006)(81156014)(8936002)(51416003)(8676002)(478600001)(107886003)(103686004)(4326008)(42186006)(50466002)(39060400002)(316002)(48376002)(2906002)(336012)(7416002)(47776003)(2616005)(446003)(476003)(11346002)(126002)(486006)(426003)(6666004)(356004)(63266004)(2171002)(6266002)(106466001)(36386004)(90966002)(52956003)(5660300001)(14444005)(36756003)(107986001)(5001870100001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR0201MB3510;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;LANG:en;PTR:xapps1.xilinx.com,unknown-60-100.xilinx.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;CY1NAM02FT027;1:yMa9+HZQ7gIbeVYXpOkoohNk4cE4QvLNnjYQHsV6/D+YowuoLBe73XzrHGMv4yGaDNc8a5ixkeliHB+5TMuLboPliFcpLqfoTMHMQLzAYSaJzDPFmu0hD0tLPe/WD+ri MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b15cb990-65d2-417b-7f03-08d6310deff4 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4608076)(2017052603328)(7153060);SRVR:DM5PR0201MB3510; X-Microsoft-Exchange-Diagnostics: 1;DM5PR0201MB3510;3:QBY0kpSulyhMctRUT5v86Uw3Chli+sFO1PQ4VK6UMCb9ALthP9bslIzvqhUkXOuf7E729Q4D3AeROk+fAxMjr0Koxos3SmnSoPwJk2Vqib7bR+ozgGLp9q7aoVwZ3UKMa6Pa+AhGCYYEnDwOk3R6fWNdBBSF4sfWWM/6XIHYsrBFdNBF3X+02X6iOLeRtWclfS2MLRWcEzylDTlY5AmrhRIoHdWL/Vz35cfd3nzBE5janlq67yFlDOsoUyIoTAvwG/l+Fc3dgmKujIS4aS+IiPtHe7v2RmXyFPmlIVRQM2pjpcS1sN/juVZljAF3M+rXsq5vCHYFX5hh3j7CcpYsBdr+uWb8tNmfSAXkN+70TgM=;25:HJVhs6SCP5XjZqxTQndY99sLPA98cFUhXSGQCCeNO1qdivqD4jODjcc0f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fDQulwxVMFyEtBd9d+iTliW7ZdxuD X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231355)(944501410)(52105095)(10201501046)(93006095)(93004095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(201708071742011)(7699051)(76991067);SRVR:DM5PR0201MB3510;BCL:0;PCL:0;RULEID:;SRVR:DM5PR0201MB3510; X-Microsoft-Exchange-Diagnostics: 1;DM5PR0201MB3510;4:OgYfVw7WRsobZ3GnBd0krkiCYD85H8qRewrfkPC8mEIeqJULUlSXr4mvx4X/K5/BqYMoq0rpe7mZyzZL+J7QcpaozQ7HO/ah/9KPsOzfKYfMkb16tbQ8MgkwBnY8Drzf8M/PVw6JtLL+SMz+/7mIwNOXtXZ0JSPv//elHb3ggdqTdaCbqmOzx7s/zHbCD29CX1SpFUqXhjUXLeZMjwl1jIBrF4aOs7E8eZyuwY4t6HFgq5me1tHyL2qcICIVoAfd0KSvyyrkMDKwFYfWY1gm1qH+4k939bm8IFF/o/d3nFa9tS3KUm9m1CNcYF+8nX3B X-Forefront-PRVS: 082465FB26 X-Microsoft-Exchange-Diagnostics: 1;DM5PR0201MB3510;23:cN7Iq2sgNFwXMYP+Kfru+/lbkHq45krJFAXtDmSh/vvPU1pR1YLBIKUOmvthtt4jYRa1vKAjgtNqGLRWqtGWDv7HUJf2l7l6EKnxA5qZcm2mHQIcxyk48VSGDZhR43aFwJJMsZa/UqGYqcVQM/3vufiUpcW4/S55OZpSXlzRsCGvoQCkFcecRRUztXocPYLmJhrEJ8JWRHsAP2IS+4nVsBsO/HcWG+9FRSt5PUkRvytmEGfQ0F4gABmK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yhQIwwjSr3hJcgy/i/KTxxW0uHJVQ4+KDIfaWNgT7WUFHiG9SbGrqvaTynJ2w2qpAb3L2XZNynqtQ9+qXhgRCRXEl7bVyg2K+MKNidorh+QYsNovYNAWqyH2Z66JBCwEBNubJH4L23VLpAVUmCFL3VV6jB578xtnDnvNB0Wu5XR620knGp64GSXV0/Mi4q9XnkNhzOTGO6XMZN0QYpt SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2018 13:15:20.5241 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b15cb990-65d2-417b-7f03-08d6310deff4 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0201MB3510 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to dwc3 databook when streams are enabled, it may be possible for the host and gadget to become out of sync, where gadget may wait for host to issue prime transcation and host may wait for gadget to issue ERDY. To avoid such potential deadlock conditions, a timer is implemented in udc/core.c and which is started after queuing a valid request in usb_ep_queue(). This timer would be stopped by the gadget driver when a valid stream event is found, otherwise the timer gets expired after STREAM_TIMEOUT_MS value and stream_timeout_function() which is registered as a callback function to usb_ep->ops->stream_timeout is called by udc core. As a part of recovery mechanism, the stream_timeout_function() stops the active transfer on the endpoint and starts the transfer again on the endpoint. Doing so, will reset the stream into ready state and ERDY is sent to the host, thus the deadlock is avoided. Signed-off-by: Anurag Kumar Vulisha --- Changes in v6: 1. This patch is newly added in this series --- drivers/usb/dwc3/gadget.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 032ea7d..aab2970 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -573,6 +573,7 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action) params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE | DWC3_DEPCFG_STREAM_EVENT_EN; dep->stream_capable = true; + dep->endpoint.stream_capable = true; } if (!usb_endpoint_xfer_control(desc)) @@ -1535,6 +1536,18 @@ static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep) return ret; } +static void stream_timeout_function(struct usb_ep *ep) +{ + struct dwc3_ep *dep = to_dwc3_ep(ep); + struct dwc3 *dwc = dep->dwc; + unsigned long flags; + + spin_lock_irqsave(&dwc->lock, flags); + dwc3_stop_active_transfer(dep, true); + __dwc3_gadget_kick_transfer(dep); + spin_unlock_irqrestore(&dwc->lock, flags); +} + /* -------------------------------------------------------------------------- */ static struct usb_endpoint_descriptor dwc3_gadget_ep0_desc = { @@ -1563,6 +1576,7 @@ static const struct usb_ep_ops dwc3_gadget_ep_ops = { .dequeue = dwc3_gadget_ep_dequeue, .set_halt = dwc3_gadget_ep_set_halt, .set_wedge = dwc3_gadget_ep_set_wedge, + .stream_timeout = stream_timeout_function, }; /* -------------------------------------------------------------------------- */ @@ -2469,6 +2483,10 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc, } break; case DWC3_DEPEVT_STREAMEVT: + if ((event->status == DEPEVT_STREAMEVT_FOUND) && + timer_pending(&dep->endpoint.stream_timeout_timer)) + del_timer(&dep->endpoint.stream_timeout_timer); + case DWC3_DEPEVT_XFERCOMPLETE: case DWC3_DEPEVT_RXTXFIFOEVT: break;