From patchwork Mon Jan 22 13:01:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 125415 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1143281ljf; Mon, 22 Jan 2018 05:02:04 -0800 (PST) X-Google-Smtp-Source: AH8x226OumVN73YtTdoODE4ddAC4Q9fphfU0HeeLEZMsKmQyslpxbQNH8fyWFRo8+uq5LQEUFu/e X-Received: by 2002:a17:902:8f87:: with SMTP id z7-v6mr3539474plo.242.1516626124734; Mon, 22 Jan 2018 05:02:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516626124; cv=none; d=google.com; s=arc-20160816; b=Q+05r5+kWZ7a5OKlctfKCMavvT879Phc01pQ/t/us+ktCv69XrBT3i+6yRlr8E2N4g nD9ggXkylyaWmgaqOP2OGHA/0NwCUKc/EBkCeBfL+VuJZsaTyeiWAWpuu5P3zvDFpzAk kcp12azlU6Q+iFgg2Q2GmtCvWnP0Bwm5vdcR65YRGBOQzN99OC74Ub3d3qmTVGhJEO12 aeARqDYuwd5kkQhJ6scPs/lag1z5CWHl+0T/Y0U2rwjBPap7icObTcrr8KOB6wpqb2tx /zIJhkmeLvWlkGLlxdQljLZAWXr1wWFm4UzUrAyXP8IrA9QV8UelLtCcroFik4rr13Ax FpJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=4GGvGvPjVS98NrkL7gu7bxJz93hod9TfTvJ1XqK1yUs=; b=JXzxdM3vOpEaaQ3ACVpGM/kYerGyu3TcKcYAs8xev0WUrlL3lYleLvHlqk0o695lB3 RrlSXwdW76Hx+w3ybUdl6kpaBgvic3JUbncpSJspKAm2L5Zr1K5MaIRWgo3REo6jyxfK xh8BTFFlvvcNVff/m64u7iK+J+OPG+u/otqqXrT6WIT/HI6E/H6Utf+8hQEYyh5BBHWG uV8AXslqSXQn0itqGHBfmcMijZpRUxaotS4PwPaFFAr81bvjRebiFeWOuXF7yOhtI8ta /QUQufyCvEfJAU6K6l8Q/YlGjafpBBl7GbEFSuiyUclfBnExJKq0ey0hFrP+zypQWugt +o5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=H5BgBqM2; 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 1si153600pfn.311.2018.01.22.05.02.04; Mon, 22 Jan 2018 05:02:04 -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=H5BgBqM2; 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 S1751297AbeAVNCA (ORCPT + 28 others); Mon, 22 Jan 2018 08:02:00 -0500 Received: from lelnx194.ext.ti.com ([198.47.27.80]:18158 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751086AbeAVNB5 (ORCPT ); Mon, 22 Jan 2018 08:01:57 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w0MD1t0K005281; Mon, 22 Jan 2018 07:01:55 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1516626115; bh=JKmLh8WqmX2dqTaEDCw/wYVkCqtvw4extRRS7UryPgk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=H5BgBqM2QYnk7N3X+KyG5Ffk8LLH/PNJKv6rPrGVdTYrhy6b7kEzEVS+gUSsaq7Qe hAyNoRvyp6I6DLS7nDhwbg4Jn5ihPN6LYXsBW515ZqLf63cCbK0b0aTQObsNM2sTcp +jj812ercJzgRWSQWGbMZ0zrDXlDF1AA4izEE0Ao= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0MD1tXY005218; Mon, 22 Jan 2018 07:01:55 -0600 Received: from DLEE113.ent.ti.com (157.170.170.24) 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; Mon, 22 Jan 2018 07:01:55 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Mon, 22 Jan 2018 07:01:55 -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 w0MD1scE010758; Mon, 22 Jan 2018 07:01:55 -0600 Received: from lta0400828d.ti.com (vboxa0400828d.emea.dhcp.ti.com [172.22.235.94]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0MD1oWa029287; Mon, 22 Jan 2018 07:01:53 -0600 From: Roger Quadros To: CC: , , Roger Quadros Subject: [PATCH 2/2] usb: dwc3: drd: Fix lock-up on ID change during system suspend/resume Date: Mon, 22 Jan 2018 15:01:43 +0200 Message-ID: <1516626103-1969-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516626103-1969-1-git-send-email-rogerq@ti.com> References: <1516626103-1969-1-git-send-email-rogerq@ti.com> 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 Adding/removing host/gadget controller before .pm_complete() causes a lock-up. Let's prevent any dual-role state change between .pm_prepare() and .pm_complete() to fix this. Signed-off-by: Roger Quadros --- drivers/usb/dwc3/core.c | 31 +++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 5 +++++ drivers/usb/dwc3/drd.c | 10 ++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) -- 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/core.c b/drivers/usb/dwc3/core.c index 42379cc..85388dd 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1414,6 +1414,33 @@ static int dwc3_runtime_idle(struct device *dev) #endif /* CONFIG_PM */ #ifdef CONFIG_PM_SLEEP +static int dwc3_prepare(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + unsigned long flags; + + if (dwc->dr_mode == USB_DR_MODE_OTG) { + spin_lock_irqsave(&dwc->lock, flags); + dwc->dr_keep_role = true; + spin_unlock_irqrestore(&dwc->lock, flags); + } + + return 0; +} + +static void dwc3_complete(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + unsigned long flags; + + if (dwc->dr_mode == USB_DR_MODE_OTG) { + spin_lock_irqsave(&dwc->lock, flags); + dwc->dr_keep_role = false; + spin_unlock_irqrestore(&dwc->lock, flags); + dwc3_drd_update(dwc); + } +} + static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); @@ -1451,6 +1478,10 @@ static const struct dev_pm_ops dwc3_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, dwc3_runtime_idle) +#ifdef CONFIG_PM_SLEEP + .prepare = dwc3_prepare, + .complete = dwc3_complete, +#endif }; #ifdef CONFIG_OF diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4a4a4c9..f5eb474 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -786,6 +786,7 @@ struct dwc3_scratchpad_array { * @dr_mode: requested mode of operation * @current_dr_role: current role of operation when in dual-role mode * @desired_dr_role: desired role of operation when in dual-role mode + * @dr_keep_role: keep the current dual-role irrespective of ID changes * @edev: extcon handle * @edev_nb: extcon notifier * @hsphy_mode: UTMI phy mode, one of following: @@ -901,6 +902,7 @@ struct dwc3 { enum usb_dr_mode dr_mode; u32 current_dr_role; u32 desired_dr_role; + bool dr_keep_role; struct extcon_dev *edev; struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; @@ -1227,11 +1229,14 @@ static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc, #if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) int dwc3_drd_init(struct dwc3 *dwc); void dwc3_drd_exit(struct dwc3 *dwc); +void dwc3_drd_update(struct dwc3 *dwc); #else static inline int dwc3_drd_init(struct dwc3 *dwc) { return 0; } static inline void dwc3_drd_exit(struct dwc3 *dwc) { } +static inline void dwc3_drd_update(struct dwc3 *dwc); +{ } #endif /* power management interface */ diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index cc8ab9a..177a8be 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -13,7 +13,7 @@ #include "core.h" #include "gadget.h" -static void dwc3_drd_update(struct dwc3 *dwc) +void dwc3_drd_update(struct dwc3 *dwc) { int id; @@ -31,9 +31,11 @@ static int dwc3_drd_notifier(struct notifier_block *nb, { struct dwc3 *dwc = container_of(nb, struct dwc3, edev_nb); - dwc3_set_mode(dwc, event ? - DWC3_GCTL_PRTCAP_HOST : - DWC3_GCTL_PRTCAP_DEVICE); + if (!dwc->dr_keep_role) { + dwc3_set_mode(dwc, event ? + DWC3_GCTL_PRTCAP_HOST : + DWC3_GCTL_PRTCAP_DEVICE); + } return NOTIFY_DONE; }