From patchwork Tue Feb 27 11:22:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 129771 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1273078lja; Tue, 27 Feb 2018 03:22:27 -0800 (PST) X-Google-Smtp-Source: AH8x224gM9DicFgJaX0WAG6FZNkhk4K65eCPOsDe300RZM0dIOqdJgH+pheJakfXKRLyu37wPAE+ X-Received: by 10.98.12.11 with SMTP id u11mr13900386pfi.192.1519730547050; Tue, 27 Feb 2018 03:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519730547; cv=none; d=google.com; s=arc-20160816; b=09TZ52/EE1VW2uzSTC+4D4WpwMA8bj75pymzSiFaQ5SIsF6gqvDlHnsHzLiKjOTW9E mFIC1n28Id0dOLOkSEMSdPqcmtmBSaazqMG05Fid+uJaAf3aIHwwPgKrsANYucEWcKF+ qAOZpz2QxCyooI+oaxtWO7YcAvNqJA50k5UvPsjpgZLtO5nrUCDf/ocy50boH7py1jwb rHIV/pG6ZgOL1uz1lbfQcM/VBLxGPFcA2EGadgUZBTfhLyUQLyulZLxnSsafmKViXXJN 5CIaXA7B79b1tgNJDKen83i3xgRxTWnNl9sye4H+OjoOIF1LSUKPAeiUXdc+zwvDOtvC XBbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=lR8gUZFRgHGO/z0Yc+6z4vni2Dg10osIq944orfVQ88=; b=CY3EAQtNT0vgFqfetMiQePCRlcDnwFhIPWC3mar7EMRMVY12xaOrxihXUmQSyXJ9kV 2fVHPrte55mkDmM10uCma9p5XcPrarDPp+j63+kNvv5EJqT87g+Zf5Rz2P4aAkpcudmg zrHMO+vZMsh2B7rsyqami5RzRntG2KumZDhWrmxabL84R8bqdkaf0sQbuqE5w3trvCfO 55ZuyhxPJIc2YmBsPvM9O4DsFBFejPAkJXULeFE+sMLTxT2Q3fK1zkzOZzo4PZNd/zME Je3Eo5O62iW5BMehnQpl5YS4lgXm8R83T8TXmBVSQGxEXddgkz1VLFiKRq6eBuGz/yHe n8MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=xNTjg7Kf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13si8411182pfi.53.2018.02.27.03.22.26; Tue, 27 Feb 2018 03:22:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=xNTjg7Kf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752783AbeB0LWX (ORCPT + 28 others); Tue, 27 Feb 2018 06:22:23 -0500 Received: from lelnx193.ext.ti.com ([198.47.27.77]:24032 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752049AbeB0LWV (ORCPT ); Tue, 27 Feb 2018 06:22:21 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx193.ext.ti.com (8.15.1/8.15.1) with ESMTP id w1RBMK4O001173; Tue, 27 Feb 2018 05:22:20 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1519730540; bh=chb60JRe5UZ7NApznGlrRFEa+t+Cyxmox7ZeFQRE52c=; h=From:To:CC:Subject:Date; b=xNTjg7KfAz0sw536CppCGBPiI6x7Je5IPoWywyyI9hn5uGgOlyoF8Mla94p2vSJYL ZRVpV//cRCgguAt2tq7Kc8jNoxoXU1h8RH1sUw2UbwtWoga/qO7TqCirjXiiWo6HLH cx46z2zuszFEKK/5B9X8zUV50ZsLrxGVKEYZec6U= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w1RBMKJC013936; Tue, 27 Feb 2018 05:22:20 -0600 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Tue, 27 Feb 2018 05:22:19 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Tue, 27 Feb 2018 05:22:19 -0600 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w1RBMJbX018808; Tue, 27 Feb 2018 05:22:19 -0600 Received: from lta0400828d.ti.com (vboxa0400828d.emea.dhcp.ti.com [172.22.233.227]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id w1RBMHn6022055; Tue, 27 Feb 2018 05:22:18 -0600 From: Roger Quadros To: CC: , , Roger Quadros Subject: [PATCH] usb: dwc3: Prevent indefinite sleep in _dwc3_set_mode during suspend/resume Date: Tue, 27 Feb 2018 13:22:06 +0200 Message-ID: <1519730526-22274-1-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the following test we get stuck by sleeping forever in _dwc3_set_mode() after which dual-role switching doesn't work. On dra7-evm's dual-role port, - Load g_zero gadget driver and enumerate to host - suspend to mem - disconnect USB cable to host and connect otg cable with Pen drive in it. - resume system - we sleep indefinitely in _dwc3_set_mode due to. dwc3_gadget_exit()->usb_del_gadget_udc()->udc_stop()-> dwc3_gadget_stop()->wait_event_lock_irq() Let's clear the DWC3_EP_END_TRANSFER_PENDING flag on all endpoints so we don't wait in dwc3_gadget_stop(). Signed-off-by: Roger Quadros --- drivers/usb/dwc3/gadget.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2bda4eb..0a360da 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3273,6 +3273,20 @@ int dwc3_gadget_init(struct dwc3 *dwc) void dwc3_gadget_exit(struct dwc3 *dwc) { + int epnum; + unsigned long flags; + + spin_lock_irqsave(&dwc->lock, flags); + for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { + struct dwc3_ep *dep = dwc->eps[epnum]; + + if (!dep) + continue; + + dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; + } + spin_unlock_irqrestore(&dwc->lock, flags); + usb_del_gadget_udc(&dwc->gadget); dwc3_gadget_free_endpoints(dwc); dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce,