Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp610377rwe; Wed, 31 Aug 2022 08:06:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ScHjNF8A9pg3+CXR1mMKcZAKvhLQjzEqWuj+U9wMegI0Q+I/Cr8WiyEq35O2a9OFY7VKo X-Received: by 2002:a17:902:a583:b0:174:d767:8393 with SMTP id az3-20020a170902a58300b00174d7678393mr13413880plb.8.1661958384673; Wed, 31 Aug 2022 08:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661958384; cv=none; d=google.com; s=arc-20160816; b=BxP+6e4m0P9wUveMBmnpIceKQtV9ZT5FnBWvxxiQCIHhVC9grPmFwzloUHy1ydzTlE +AUVTBpYZ0XYWu0zt0nTECthLTNnR2Gocfrq+7ZCMZS7x3YAoLSJPWPg85+wrVZ5RC3m y3w5awR8gfvD1mEcWw2ZFXS9rZquIsokCnqtA9BLVfsc4/plEo2Nms0xre9rMzJTY79N wbng/Btz2mt9aygOjUzZeGP413uf83BQafxd4+elyGTjcj4DMgZZ5e9SMStmPIT6OayB UxpK2nYnJ7xq9zMEgUfnhd9vY7rmQgdTjezno1ZO8p5741gjLMTxd8dnyN5HtfPuq5vt pSQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=WYTINBxX3yiIzUxqEy6GIXdWAYbWJHhFYFVrR8LGFSk=; b=KApwIvxC/puBIAjLqccwyqArrcbpxPBG/5tp8DvrQEhFYv6faiZkx6VrNFx6yo1Gj4 5PNORETfgKZ9I6Mk6ayssDOMooLpXWu4USJ0DLbv8GgEqxqIPvzTv9CEaFT7ZVq9qVr5 GdjsYymktFoFgl+KD7t6jBr0Ew4Szt4SQny++HAvTE7lnX/vIs1buUcKrBpYXfwLk26b fu142s01WyfWnIBVxrgAP6P8suWX8/3vE6CxhjWpT0BqwxqSnjAqXd+DjKvrwBxgKNRD iPBSlLfFKgXJnG6p9VC26/r+JRFYbAXX9+K0cLAjU08ChYVQZNrfXh42lm9S6QIKAl+F CzVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 23-20020a630617000000b00415e477c57fsi4888003pgg.436.2022.08.31.08.06.12; Wed, 31 Aug 2022 08:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbiHaOb0 (ORCPT + 99 others); Wed, 31 Aug 2022 10:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbiHaObU (ORCPT ); Wed, 31 Aug 2022 10:31:20 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id A385F32D8A for ; Wed, 31 Aug 2022 07:31:19 -0700 (PDT) Received: (qmail 191749 invoked by uid 1000); 31 Aug 2022 10:31:18 -0400 Date: Wed, 31 Aug 2022 10:31:18 -0400 From: Alan Stern To: Yinbo Zhu Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Patchwork Bot Subject: Re: [PATCH v2] usb: ohci-platform: fix usb disconnect issue after s4 Message-ID: References: <20220831045910.12203-1-zhuyinbo@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220831045910.12203-1-zhuyinbo@loongson.cn> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 31, 2022 at 12:59:10PM +0800, Yinbo Zhu wrote: > Avoid retaining bogus hardware states during resume-from-hibernation. > Previously we had reset the hardware as part of preparing to reinstate > the snapshot image. But we can do better now with the new PM framework, > since we know exactly which resume operations are from hibernation. > > According to the commit 'cd1965db054e ("USB: ohci: move ohci_pci_{ > suspend,resume} to ohci-hcd.c")' and commit '6ec4beb5c701 ("USB: new > flag for resume-from-hibernation")', the flag "hibernated" is for > resume-from-hibernation and it should be true when usb resume from disk. > > When this flag "hibernated" is set, the drivers will reset the hardware > to get rid of any existing state and make sure resume from hibernation > re-enumerates everything for ohci. > > Signed-off-by: Yinbo Zhu > --- > Change in v2: > 1. Revise the commit log infomation. > 2. Wrap the ohci_platform_renew() function with two > helpers that are ohci_platform_renew_hibernated() > and ohci_platform_renew(). > > drivers/usb/host/ohci-platform.c | 49 ++++++++++++++++++++++++++++++-- > 1 file changed, 46 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c > index 0adae6265127..56cb424d3bb0 100644 > --- a/drivers/usb/host/ohci-platform.c > +++ b/drivers/usb/host/ohci-platform.c > @@ -289,7 +289,7 @@ static int ohci_platform_suspend(struct device *dev) > return ret; > } > > -static int ohci_platform_resume(struct device *dev) > +static int ohci_platform_renew(struct device *dev) > { > struct usb_hcd *hcd = dev_get_drvdata(dev); > struct usb_ohci_pdata *pdata = dev_get_platdata(dev); > @@ -297,6 +297,7 @@ static int ohci_platform_resume(struct device *dev) > > if (pdata->power_on) { > int err = pdata->power_on(pdev); > + > if (err < 0) > return err; > } > @@ -309,6 +310,38 @@ static int ohci_platform_resume(struct device *dev) > > return 0; > } > + > +static int ohci_platform_renew_hibernated(struct device *dev) > +{ > + struct usb_hcd *hcd = dev_get_drvdata(dev); > + struct usb_ohci_pdata *pdata = dev_get_platdata(dev); > + struct platform_device *pdev = to_platform_device(dev); > + > + if (pdata->power_on) { > + int err = pdata->power_on(pdev); > + > + if (err < 0) > + return err; > + } > + > + ohci_resume(hcd, true); > + > + pm_runtime_disable(dev); > + pm_runtime_set_active(dev); > + pm_runtime_enable(dev); > + > + return 0; > +} > + > +static int ohci_platform_resume(struct device *dev) > +{ > + return ohci_platform_renew(dev); > +} > + > +static int ohci_platform_restore(struct device *dev) > +{ > + return ohci_platform_renew_hibernated(dev); > +} I really do not see any point in these helper routines. Why not just use these names (ohci_platform_resume and ohci_platform_restore) for the actual routines and forget about the _renew names? Although if it were me, I'd do it more like this: static int ohci_platform_resume_common(struct device *dev, bool hibernated) { ... } static int ohci_platform_resume(struct device *dev) { return ohci_platform_resume_common(dev, false); } static int ohci_platform_restore(struct device *dev) { return ohci_platform_resume_common(dev, true); } Alan Stern