Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp913453ybf; Thu, 27 Feb 2020 01:52:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwhDiBhsBxGMxdAd/TFj9Ot3+ydlIvHqUe8egsR/OzXdX4dgBt0nmZRE5UcbPRePva3DJE/ X-Received: by 2002:aca:53c6:: with SMTP id h189mr2593008oib.11.1582797177138; Thu, 27 Feb 2020 01:52:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582797177; cv=none; d=google.com; s=arc-20160816; b=KFpyBNFR8zDA+icZ0nT/BwIjPnECf0BO4ebXtmf+WE97BYPgNRq4SVSppDhDnTxWJQ t0cCLMDFdKRimmMpXP1c87ClpGjsHzvGcg/dy1nG0tUuo5AA6BxVE4uw4FmTLjgK/h5y q1UyzHRqWu6SfHJdtsPk5TUXMpCBOK8Aj70wvBWB07N/yWijZJ8drfV/neWLLWoiFIKl ZNUKOKzQIMvJWMzrQU6TvhV+RP3A7QqNvdZej1WywL0/kSSAkvNwUCYBoc4bzfvqolC4 CGmZH8hWGjvwm2jqBwlocdj+aD03vwUmxE5yjUi3oJic5S61+UuhKNR0Wf0aGnf0CpDa GWtA== 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:mime-version :message-id:date:subject:cc:to:from; bh=0E5RMtkYLG6MtgGFF/o8ltoLg5vYhwna+Eh/JKJ1CUc=; b=L9Ro1rVNQ+3OfxjNnckf2eFvTxNa6elQyoocWuafnTCPQa1zc+C5Zno0/p3I2wqknQ I2FS7u259bPKHJxRQWeXCiWEIY/Ktl18VhUpXGj6QHd+uDI4Wb5zNfQN6nfPZR7HXdMP offEkcM1wzERmdoYpx175EcP2BtvXYb5eFwmt19C8KXZoxeskEkB+KPkWvhms+19UVgK FEqSTJYGzhmkjuwgq2zz5yf/3ZTIHzaxp4NR5qTD10zx6OrvJATGwqVRYuysTzygGfcw n7sMcOGKRQ1E2+4tM8Z9WgeEckhj7v00XGFuLhoMiO9dX7wyJX/cl3S14s7srWFOjLFp 4wfA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f18si906819oti.289.2020.02.27.01.52.44; Thu, 27 Feb 2020 01:52:57 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728752AbgB0JvI (ORCPT + 99 others); Thu, 27 Feb 2020 04:51:08 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:35879 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728653AbgB0JvI (ORCPT ); Thu, 27 Feb 2020 04:51:08 -0500 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.lab.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j7Fod-0006mu-IK; Thu, 27 Feb 2020 10:50:47 +0100 Received: from mfe by dude02.lab.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1j7FoZ-0003jq-SI; Thu, 27 Feb 2020 10:50:43 +0100 From: Marco Felsch To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, harry.pan@intel.com, nobuta.keiya@fujitsu.com, malat@debian.org, kai.heng.feng@canonical.com, chiasheng.lee@intel.com, andreyknvl@google.com, heinzelmann.david@gmail.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [RFC PATCH] USB: hub: fix port suspend/resume Date: Thu, 27 Feb 2020 10:50:40 +0100 Message-Id: <20200227095040.10208-1-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At the momemnt the usb-port driver has only runime_pm hooks. Suspending the port and turn off the VBUS supply should be triggered by the hub device suspend callback usb_port_suspend() which calls the pm_runtime_put_sync() if all pre-conditions are meet. This mechanism don't work correctly due to the global PM behaviour, for more information see [1]. According [1] I added the suspend/resume callbacks for the port device to fix this. While on it I replaced the #ifdef's by __maybe_unused. [1] https://www.spinics.net/lists/linux-usb/msg190537.html Signed-off-by: Marco Felsch --- drivers/usb/core/hub.c | 13 ------------- drivers/usb/core/port.c | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 3405b146edc9..c294484e478d 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3323,10 +3323,6 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) usb_set_device_state(udev, USB_STATE_SUSPENDED); } - if (status == 0 && !udev->do_remote_wakeup && udev->persist_enabled - && test_and_clear_bit(port1, hub->child_usage_bits)) - pm_runtime_put_sync(&port_dev->dev); - usb_mark_last_busy(hub->hdev); usb_unlock_port(port_dev); @@ -3514,15 +3510,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) int status; u16 portchange, portstatus; - if (!test_and_set_bit(port1, hub->child_usage_bits)) { - status = pm_runtime_get_sync(&port_dev->dev); - if (status < 0) { - dev_dbg(&udev->dev, "can't resume usb port, status %d\n", - status); - return status; - } - } - usb_lock_port(port_dev); /* Skip the initial Clear-Suspend step for a remote wakeup */ diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index bbbb35fa639f..9efa6b2ef31b 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -187,8 +187,7 @@ static void usb_port_device_release(struct device *dev) kfree(port_dev); } -#ifdef CONFIG_PM -static int usb_port_runtime_resume(struct device *dev) +static int __maybe_unused usb_port_runtime_resume(struct device *dev) { struct usb_port *port_dev = to_usb_port(dev); struct usb_device *hdev = to_usb_device(dev->parent->parent); @@ -244,7 +243,7 @@ static int usb_port_runtime_resume(struct device *dev) return retval; } -static int usb_port_runtime_suspend(struct device *dev) +static int __maybe_unused usb_port_runtime_suspend(struct device *dev) { struct usb_port *port_dev = to_usb_port(dev); struct usb_device *hdev = to_usb_device(dev->parent->parent); @@ -283,7 +282,33 @@ static int usb_port_runtime_suspend(struct device *dev) return retval; } -#endif + +static int __maybe_unused _usb_port_suspend(struct device *dev) +{ + struct usb_port *port_dev = to_usb_port(dev); + struct usb_device *udev = port_dev->child; + int retval; + + if (!udev->do_remote_wakeup && udev->persist_enabled) + retval = usb_port_runtime_suspend(dev); + + /* Do not force the user to enable the power-off feature */ + if (retval && retval != -EAGAIN) + return retval; + + return 0; +} + +static int __maybe_unused _usb_port_resume(struct device *dev) +{ + struct usb_port *port_dev = to_usb_port(dev); + struct usb_device *udev = port_dev->child; + + if (!udev->do_remote_wakeup && udev->persist_enabled) + return usb_port_runtime_resume(dev); + + return 0; +} static void usb_port_shutdown(struct device *dev) { @@ -294,10 +319,8 @@ static void usb_port_shutdown(struct device *dev) } static const struct dev_pm_ops usb_port_pm_ops = { -#ifdef CONFIG_PM - .runtime_suspend = usb_port_runtime_suspend, - .runtime_resume = usb_port_runtime_resume, -#endif + SET_SYSTEM_SLEEP_PM_OPS(_usb_port_suspend, _usb_port_resume) + SET_RUNTIME_PM_OPS(usb_port_runtime_suspend, usb_port_runtime_resume, NULL) }; struct device_type usb_port_device_type = { -- 2.20.1