Message ID | 20231113-j7200-usb-suspend-v1-4-ad1ee714835c@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1238257vqg; Mon, 13 Nov 2023 06:27:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnqGbcd1+a1M2WqaBA2PkqoLYwjLf3LOLoDkJPPQeSEojclwlizlMCj82t3jAKDVcdA0UZ X-Received: by 2002:aa7:8512:0:b0:6c6:2885:82c7 with SMTP id v18-20020aa78512000000b006c6288582c7mr6754717pfn.25.1699885660341; Mon, 13 Nov 2023 06:27:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699885660; cv=none; d=google.com; s=arc-20160816; b=SZEXWZ5VQlqmLOigTaZYEaZe20eVmdB0HAECVHsGeHyepjTWTT0UACBl6td5WfUNe5 vIVXnItcKO0swyoQl/rORgsKt3Kty9KbvW57ECv2MLKs0E7BdWcLLWLYKC4igNpy3GHZ aPAv3yMfKLSefW2kZCQOgc+DKiUr9iHmob+lukw37UoO9ZTqlEXhPFdsv2vHwaja69i9 GlrnoW1HxAwgd5wHDKiR5m2HzHlLo57f6KJ0Rbl7ynL/AVf8MZL/bhzotw4puRbgZ1g/ POPryJkhXAW6mPSikC53jleAlm+pOBrmVQoMWddSZMB5txxjdTzysfs1JdWQl2CHh+FF bprw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=cnUtq32WECjfa76r/drw3nv80tgUh5X0WPjXLzFlw28=; fh=16DCl5XFH1WL+t9Nj2yh7FiMyRP+/MtGOeDFkjBs21w=; b=bpQcSa4Xm/1lAe75mhUmwGkCxRJ0HgQqdP8sIYOiKspGs74ceTGLum0FRHzzJseqk/ M3XHOLcb6aUTWoGbWbn/3vi1sjqn/LQUhwRaPLTXiLHBz4yeD8PNgxnmckkOOXHEh55G 5gnyZtaTfc8h2C28iodNfLsPrZu/v8f/p3j499deL8UyUembuDxSBMLsUBoNpaW034n4 oVf1W/d2C27oHU6/t/AiJuddPfxOwJjp5qeQBAhOR2g3RGHTI6kcfdQsp6ZB5R4YmRJ+ OloFSFX17URs6V8XxWs7MJlj/ndMQ5MGlhERb2MQRrz0ujhOtEdc40hF9lD2ee/f2DGF aWTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dkrLrBm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k64-20020a638443000000b005bdbeb537bcsi5589310pgd.37.2023.11.13.06.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 06:27:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dkrLrBm0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id A2A7F8055743; Mon, 13 Nov 2023 06:27:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231254AbjKMO1O (ORCPT <rfc822;heyuhang3455@gmail.com> + 29 others); Mon, 13 Nov 2023 09:27:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjKMO1H (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 13 Nov 2023 09:27:07 -0500 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7BA4D6E; Mon, 13 Nov 2023 06:27:03 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id F36D91C0006; Mon, 13 Nov 2023 14:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1699885622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cnUtq32WECjfa76r/drw3nv80tgUh5X0WPjXLzFlw28=; b=dkrLrBm0G6WnQIfo4v7EkNmhc1fxeqZv1l6opb3gjHwULojiv5p/NaJkGUcgKv6etaoTPi 0ADc6WeA4CdTabdx64+7Gy6f75FiUnUNQLtLQseNQx/zupfA/EeObKE/1sR3HGVLTDLlHM Z7kk8kfQ1SjxnzJwKIPBztWSCscdZ887WmLlRhjPQw8cKbTzt9uJ1yImGdhxThhyNu2gcI mNkXD5ji2f8B+Vz9TPGfvS9qEzz+GHVuLlueiKEMLpXbzezYnSKIVFa21m+qkzSOiKy7Ic 4YXN4WaS+eim3Llkje2kUE2pwefMyWZL7qdftfkh4ktna5b+quJLChPti4S6Ew== From: =?utf-8?q?Th=C3=A9o_Lebrun?= <theo.lebrun@bootlin.com> Date: Mon, 13 Nov 2023 15:26:59 +0100 Subject: [PATCH 4/6] usb: cdns3: support power-off of controller when in host role MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231113-j7200-usb-suspend-v1-4-ad1ee714835c@bootlin.com> References: <20231113-j7200-usb-suspend-v1-0-ad1ee714835c@bootlin.com> In-Reply-To: <20231113-j7200-usb-suspend-v1-0-ad1ee714835c@bootlin.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Roger Quadros <rogerq@kernel.org>, Peter Chen <peter.chen@kernel.org>, Pawel Laszczak <pawell@cadence.com>, Nishanth Menon <nm@ti.com>, Vignesh Raghavendra <vigneshr@ti.com>, Tero Kristo <kristo@kernel.org> Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?q?Th=C3=A9o_Lebrun?= <theo.lebrun@bootlin.com> X-Mailer: b4 0.12.3 X-GND-Sasl: theo.lebrun@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 13 Nov 2023 06:27:34 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782459306031973291 X-GMAIL-MSGID: 1782459306031973291 |
Series |
usb: cdns: fix suspend on J7200 by assuming reset on resume
|
|
Commit Message
Théo Lebrun
Nov. 13, 2023, 2:26 p.m. UTC
The controller is not being reconfigured at resume. Change resume to
redo hardware config if quirk CDNS3_RESET_ON_RESUME is active.
Platform data comes from the parent driver (eg cdns3-ti).
The quirk should be passed if the platform driver knows that the
controller might be in reset state at resume. We do NOT reconfigure the
hardware without this quirk to avoid losing state if we did a suspend
without reset.
If the quirk is on, we notify the xHCI subsystem that:
1. We reset on resume. It will therefore redo the xHC init & trigger
such message as "root hub lost power or was reset" in dmesg.
2. It should disable/enable clocks on suspend/resume. This does not
matter on our platform as xhci-plat does not get access to any clock
but it would be the right thing to do if we indeed had such clocks.
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/usb/cdns3/core.h | 1 +
drivers/usb/cdns3/host.c | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
Comments
On 23-11-13 15:26:59, Théo Lebrun wrote: > The controller is not being reconfigured at resume. Change resume to > redo hardware config if quirk CDNS3_RESET_ON_RESUME is active. Current logic has power off judgement, see cdns3_controller_resume for detail. > > Platform data comes from the parent driver (eg cdns3-ti). > > The quirk should be passed if the platform driver knows that the > controller might be in reset state at resume. We do NOT reconfigure the > hardware without this quirk to avoid losing state if we did a suspend > without reset. > > If the quirk is on, we notify the xHCI subsystem that: > > 1. We reset on resume. It will therefore redo the xHC init & trigger > such message as "root hub lost power or was reset" in dmesg. > > 2. It should disable/enable clocks on suspend/resume. This does not > matter on our platform as xhci-plat does not get access to any clock > but it would be the right thing to do if we indeed had such clocks. > > Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> > --- > drivers/usb/cdns3/core.h | 1 + > drivers/usb/cdns3/host.c | 20 ++++++++++++++++++++ > 2 files changed, 21 insertions(+) > > diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h > index 81a9c9d6be08..7487067ba23f 100644 > --- a/drivers/usb/cdns3/core.h > +++ b/drivers/usb/cdns3/core.h > @@ -44,6 +44,7 @@ struct cdns3_platform_data { > bool suspend, bool wakeup); > unsigned long quirks; > #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) > +#define CDNS3_RESET_ON_RESUME BIT(1) > }; > > /** > diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c > index 6164fc4c96a4..a81019a7c8cc 100644 > --- a/drivers/usb/cdns3/host.c > +++ b/drivers/usb/cdns3/host.c > @@ -88,6 +88,9 @@ static int __cdns_host_init(struct cdns *cdns) > goto err1; > } > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) > + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; > + If you set this flag, how could you support the USB remote wakeup request? In that case, the USB bus does not expect re-enumeration. > if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)) > cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; > > @@ -124,6 +127,18 @@ static void cdns_host_exit(struct cdns *cdns) > cdns_drd_host_off(cdns); > } > > +static int cdns_host_suspend(struct cdns *cdns, bool do_wakeup) > +{ > + if (!do_wakeup) > + cdns_drd_host_off(cdns); > + return 0; > +} > + > +static int cdns_host_resume(struct cdns *cdns, bool hibernated) > +{ > + return cdns_drd_host_on(cdns); This one will redo if controller's power is off, please consider both on and power situation. > +} > + > int cdns_host_init(struct cdns *cdns) > { > struct cdns_role_driver *rdrv; > @@ -137,6 +152,11 @@ int cdns_host_init(struct cdns *cdns) > rdrv->state = CDNS_ROLE_STATE_INACTIVE; > rdrv->name = "host"; > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) { > + rdrv->suspend = cdns_host_suspend; > + rdrv->resume = cdns_host_resume; > + } > + > cdns->roles[USB_ROLE_HOST] = rdrv; > > return 0; > > -- > 2.41.0 >
Hello, On Tue Nov 14, 2023 at 9:38 AM CET, Peter Chen wrote: > On 23-11-13 15:26:59, Théo Lebrun wrote: > > The controller is not being reconfigured at resume. Change resume to > > redo hardware config if quirk CDNS3_RESET_ON_RESUME is active. > > Current logic has power off judgement, see cdns3_controller_resume for > detail. Indeed! Thanks for the pointer. I had not noticed that, those patches come from an older kernel which didn't have it. That'll make for less changes; patches 4 & 5 can go away. > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) > > + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; > > + > > If you set this flag, how could you support the USB remote wakeup > request? In that case, the USB bus does not expect re-enumeration. We didn't support remote USB wakeup. Only S2R mattered in our case and USB remote wakeup wasn't a possibility. > > +static int cdns_host_resume(struct cdns *cdns, bool hibernated) > > +{ > > + return cdns_drd_host_on(cdns); > > This one will redo if controller's power is off, please consider both > on and power situation. Clearly. Can see that at runtime. Thanks for the review! -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On 23-11-14 12:10:18, Théo Lebrun wrote: > Hello, > > On Tue Nov 14, 2023 at 9:38 AM CET, Peter Chen wrote: > > On 23-11-13 15:26:59, Théo Lebrun wrote: > > > The controller is not being reconfigured at resume. Change resume to > > > redo hardware config if quirk CDNS3_RESET_ON_RESUME is active. > > > > Current logic has power off judgement, see cdns3_controller_resume for > > detail. > > Indeed! Thanks for the pointer. I had not noticed that, those patches > come from an older kernel which didn't have it. That'll make for less > changes; patches 4 & 5 can go away. > > > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) > > > + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; > > > + > > > > If you set this flag, how could you support the USB remote wakeup > > request? In that case, the USB bus does not expect re-enumeration. > > We didn't support remote USB wakeup. Only S2R mattered in our case and > USB remote wakeup wasn't a possibility. Without this patch, will below be hit for your platform: /* re-initialize the HC on Restore Error, or Host Controller Error */ if (temp & (STS_SRE | STS_HCE)) { reinit_xhc = true; if (!xhci->broken_suspend) xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); }
Hello, On Fri Nov 17, 2023 at 4:38 AM CET, Peter Chen wrote: > On 23-11-14 12:10:18, Théo Lebrun wrote: > > Hello, > > > > On Tue Nov 14, 2023 at 9:38 AM CET, Peter Chen wrote: > > > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) > > > > + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; > > > > + > > > > > > If you set this flag, how could you support the USB remote wakeup > > > request? In that case, the USB bus does not expect re-enumeration. > > > > We didn't support remote USB wakeup. Only S2R mattered in our case and > > USB remote wakeup wasn't a possibility. > > Without this patch, will below be hit for your platform: > > /* re-initialize the HC on Restore Error, or Host Controller Error */ > if (temp & (STS_SRE | STS_HCE)) { > reinit_xhc = true; > if (!xhci->broken_suspend) > xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); > } Yes it hits. The warning as well. How big of an issue is that? My understanding is that this is the expected behavior with reset on resume if we don't explicitely pass the flag XHCI_RESET_ON_RESUME. I don't think we should be having the broken_suspend bit set as its mentioning some specific quirk on AMD hardware. Is the only expected difference inbetween having CDNS3_RESET_ON_RESUME & not having it is resume time? For reference, the status read is 0x411 ie STS_HALT | STS_PCD | STS_SRE. xhc_state is zero. Regards, -- Théo Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On 23-11-17 10:58:12, Théo Lebrun wrote: > Hello, > > On Fri Nov 17, 2023 at 4:38 AM CET, Peter Chen wrote: > > On 23-11-14 12:10:18, Théo Lebrun wrote: > > > Hello, > > > > > > On Tue Nov 14, 2023 at 9:38 AM CET, Peter Chen wrote: > > > > > + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) > > > > > + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; > > > > > + > > > > > > > > If you set this flag, how could you support the USB remote wakeup > > > > request? In that case, the USB bus does not expect re-enumeration. > > > > > > We didn't support remote USB wakeup. Only S2R mattered in our case and > > > USB remote wakeup wasn't a possibility. > > > > Without this patch, will below be hit for your platform: > > > > /* re-initialize the HC on Restore Error, or Host Controller Error */ > > if (temp & (STS_SRE | STS_HCE)) { > > reinit_xhc = true; > > if (!xhci->broken_suspend) > > xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); > > } > > Yes it hits. The warning as well. How big of an issue is that? > > My understanding is that this is the expected behavior with reset on > resume if we don't explicitely pass the flag XHCI_RESET_ON_RESUME. I > don't think we should be having the broken_suspend bit set as its > mentioning some specific quirk on AMD hardware. > > Is the only expected difference inbetween having CDNS3_RESET_ON_RESUME & > not having it is resume time? For reference, the status read is 0x411 > ie STS_HALT | STS_PCD | STS_SRE. xhc_state is zero. > Yes. I know some xHCI controllers have powered off during suspend will hit it, just would like to confirm if it is the same with yours. If you don't want remote wakeup, it is most probably the same with quirks you set.
diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h index 81a9c9d6be08..7487067ba23f 100644 --- a/drivers/usb/cdns3/core.h +++ b/drivers/usb/cdns3/core.h @@ -44,6 +44,7 @@ struct cdns3_platform_data { bool suspend, bool wakeup); unsigned long quirks; #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) +#define CDNS3_RESET_ON_RESUME BIT(1) }; /** diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c index 6164fc4c96a4..a81019a7c8cc 100644 --- a/drivers/usb/cdns3/host.c +++ b/drivers/usb/cdns3/host.c @@ -88,6 +88,9 @@ static int __cdns_host_init(struct cdns *cdns) goto err1; } + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) + cdns->xhci_plat_data->quirks |= XHCI_RESET_ON_RESUME | XHCI_SUSPEND_RESUME_CLKS; + if (cdns->pdata && (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)) cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; @@ -124,6 +127,18 @@ static void cdns_host_exit(struct cdns *cdns) cdns_drd_host_off(cdns); } +static int cdns_host_suspend(struct cdns *cdns, bool do_wakeup) +{ + if (!do_wakeup) + cdns_drd_host_off(cdns); + return 0; +} + +static int cdns_host_resume(struct cdns *cdns, bool hibernated) +{ + return cdns_drd_host_on(cdns); +} + int cdns_host_init(struct cdns *cdns) { struct cdns_role_driver *rdrv; @@ -137,6 +152,11 @@ int cdns_host_init(struct cdns *cdns) rdrv->state = CDNS_ROLE_STATE_INACTIVE; rdrv->name = "host"; + if (cdns->pdata && cdns->pdata->quirks & CDNS3_RESET_ON_RESUME) { + rdrv->suspend = cdns_host_suspend; + rdrv->resume = cdns_host_resume; + } + cdns->roles[USB_ROLE_HOST] = rdrv; return 0;