From patchwork Fri Mar 9 12:47:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 131100 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp950981lja; Fri, 9 Mar 2018 04:47:11 -0800 (PST) X-Google-Smtp-Source: AG47ELtIMryU9CxRifcy2uznTNHu4njHvboExZavyHyeL5BXn3+A71dCgsI6i290L+V1R6sqTiic X-Received: by 2002:a17:902:8bc2:: with SMTP id r2-v6mr27478800plo.213.1520599631544; Fri, 09 Mar 2018 04:47:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520599631; cv=none; d=google.com; s=arc-20160816; b=xlcMSEgZb7ILIiqvmydXKn/Nj+UDukYmpZaOtMVVX0kMx89b6L8chBl9gHQDkLMMiL emA5dWuSd4DZRFI7Zl/va70y2nmHWaB0F0btBEiXxL0hccPIwXpKaUODcUaO0T41u5AD E95EuSb9i58Mpa9KbRHO+QQCcss/yG49hQuuiT+oHcmpDNh4FsZ5+BT5l/1YrR9P2qTj EMvWIHaf0uEduq92Edw1rBX+YbrPYIY9JEx5+AOQpFD8ThKhtPSzVDtzmBWsEDq0sYos dhdYBn82it625whnUEyLjGU+N9qJqKwjUOxutUEKuZJrGU28tL9uQxp56SOxEfuQh5db +Igg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=lQzyXF1BBiA1BC2Rag70y6SsLV4FukO/5jQ5JuJrXFQ=; b=lIZn8N1jqMqbbPuEao3+BFKMrtoClyhtopQ6y6MSHRnXPKVcFq+3pzFfFIo6SKF1mL vgF2j1xayOz9qPndnI1m//47Sf+9UCRImOa8oflveJwHn0tITS4MoY25hNDI6MkMSCn6 OZId12zKTWK3lIYnZFqaaeTnzxoSm4LEAEImucbc/r51FXpfqkvBd5kJPKtcd6C7K9gm Y2ESa/nck5rZnotcBVGMOotlx1xUh3n48f6Hb8FdBwkCEF1CEVLDQL8ddBSkQm8TW1Jo auwLzfliUVtv7wYISN7L0TvFEPH1HP07polnUEtlogg0r+kAPyFjTU+JiCiJiD7lUDX3 aapA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=VmswZLTP; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (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 v3si690780pgq.608.2018.03.09.04.47.10; Fri, 09 Mar 2018 04:47:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=VmswZLTP; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751106AbeCIMrJ (ORCPT + 3 others); Fri, 9 Mar 2018 07:47:09 -0500 Received: from lelnx193.ext.ti.com ([198.47.27.77]:29267 "EHLO lelnx193.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbeCIMrI (ORCPT ); Fri, 9 Mar 2018 07:47:08 -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 w29Cl6Up024378; Fri, 9 Mar 2018 06:47:06 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1520599626; bh=iYsVXSZ1R7ORjQD4Ih7v1lrUO4sTl/AyzDHNR7TIc40=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=VmswZLTPyYfI3FY1psn4YC93liXX4BkP8GDwap86HhXFVAyN0/2+Nxheb0W7au0/0 uFNVpKYgtCAV8/7rrH3GNPJ1Z8AYDsGoBrZzm2sXEPV9Xq36D6l4WeAri/kCn5R2uy nasHbypBl428ey2UMPzzRXz5/Sy1hz/TtyVnII3w= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w29Cl67A013035; Fri, 9 Mar 2018 06:47:06 -0600 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Fri, 9 Mar 2018 06:47:06 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Fri, 9 Mar 2018 06:47:06 -0600 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w29Cl46x018066; Fri, 9 Mar 2018 06:47:05 -0600 Subject: [PATCH v2] usb: dwc3: Prevent indefinite sleep in _dwc3_set_mode during suspend/resume To: CC: , , References: <1519730526-22274-1-git-send-email-rogerq@ti.com> From: Roger Quadros Message-ID: Date: Fri, 9 Mar 2018 14:47:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1519730526-22274-1-git-send-email-rogerq@ti.com> Content-Language: en-GB X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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() To fix this instead of waiting indefinitely with wait_event_lock_irq() we use wait_event_interruptible_lock_irq_timeout() and print and error message if there was a timeout. Signed-off-by: Roger Quadros --- Changelog: v2: - use wait_event_interruptible_lock_irq_timeout() instead of wait_event_lock_irq() drivers/usb/dwc3/gadget.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) -- cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2bda4eb..7c3a6e4 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1950,6 +1950,7 @@ static int dwc3_gadget_stop(struct usb_gadget *g) struct dwc3 *dwc = gadget_to_dwc(g); unsigned long flags; int epnum; + u32 tmo_eps = 0; spin_lock_irqsave(&dwc->lock, flags); @@ -1960,6 +1961,7 @@ static int dwc3_gadget_stop(struct usb_gadget *g) for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { struct dwc3_ep *dep = dwc->eps[epnum]; + int ret; if (!dep) continue; @@ -1967,9 +1969,24 @@ static int dwc3_gadget_stop(struct usb_gadget *g) if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) continue; - wait_event_lock_irq(dep->wait_end_transfer, - !(dep->flags & DWC3_EP_END_TRANSFER_PENDING), - dwc->lock); + ret = wait_event_interruptible_lock_irq_timeout(dep->wait_end_transfer, + !(dep->flags & DWC3_EP_END_TRANSFER_PENDING), + dwc->lock, msecs_to_jiffies(5)); + + if (ret <= 0) { + /* Timed out or interrupted! There's nothing much + * we can do so we just log here and print which + * endpoints timed out at the end. + */ + tmo_eps |= 1 << epnum; + dep->flags &= DWC3_EP_END_TRANSFER_PENDING; + } + } + + if (tmo_eps) { + dev_err(dwc->dev, + "end transfer timed out on endpoints 0x%x [bitmap]\n", + tmo_eps); } out: