Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1575527pxb; Tue, 8 Feb 2022 22:50:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYM+3hGL7gMMpakrlBtfi5WyNg3USfeaJA7UTQgG/8SXj95sTjJ150GN6QfGe/awQaQoOo X-Received: by 2002:aa7:9110:: with SMTP id 16mr821338pfh.41.1644389412169; Tue, 08 Feb 2022 22:50:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644389412; cv=none; d=google.com; s=arc-20160816; b=MKGc7EB6DyV3wpppOwlCIq1pWxstaO4Gz0q8IVY4RnonPmthEmpwj9DpHqai/uKkN7 f0hi53aM9Rjko3DBiTAybhdClncBzYOtGMAcRqUGvJSFV7gw9DRCdgzb1VimboNTofNF XoCjldxjfqHgGMFkuBsEf/5zZebjSAj0JTFLljjZIjTclA9bfKed3ZJNdZ/AEq0kgc6q DlV4m3VEUkOjICUCpvqKNJo5yjrgERkrcK1z5SdGIHmcgzEGR+kECY9uLF75rjTe7b3d MSKERHL7m76ig0WRTBFqAcnIFD87vZ0M5vFrGHNIObaT9/BE/2j0ZB7hDO3vgEM1tZUq 2W8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AzT2zSb2THNUuyQZXITuwOuNUzZi7qz7YcPLPaKf/rI=; b=FuJwI6fA8FGfO8k3fHr9HN/mVM+JXeR7pJaZeDps/+LG7JxXtQeN0PKftJnbWVF4ZU 20Cr1BFYlkEPBJArG1j+kwSGXZj0TAZE4BWP2ALCLwn207xLUWniSCZciINrKqD+2vxA vHcRPhFUvyrKucv9aBDJhxCDbd+R0bcvKOVRZbkGmm7baWqhQChLF4qacQ0n/ONK5H+D XvOC7wvSamgIB5mG+VRIqg53B3UqUtU0eJ8iQ/LxbLlf9mFe+IGGQ9wGjhAeoluDpwpv kpEwQyyfpMr3lboWU5rXa8sZJm6TkoKHqX2WuLarqTAK4xO3qaE5qYS+1yaeYuhCTmnh XNaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Lhm693r2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 63si4452744pgc.767.2022.02.08.22.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 22:50:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Lhm693r2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2AEE2C05BE0E; Tue, 8 Feb 2022 22:20:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbiBHHMC (ORCPT + 99 others); Tue, 8 Feb 2022 02:12:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347926AbiBHHL6 (ORCPT ); Tue, 8 Feb 2022 02:11:58 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BEB8C0401F5 for ; Mon, 7 Feb 2022 23:11:57 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id c3so13117382pls.5 for ; Mon, 07 Feb 2022 23:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AzT2zSb2THNUuyQZXITuwOuNUzZi7qz7YcPLPaKf/rI=; b=Lhm693r23Ti8wAB6bYk3E1Q2q3lTbPPIe+OT0/XGp/NvM3hMz6KA9q0SB7rouXhXdf 7aEzUb+JY9J2Mg77bkN5Oyj5qsYnl1jUHVVPP3Fyf9yWXYCxYlYcVTwHx2M0eTv0Ve7/ AWQKoZi56HQ1Ea63v4l4bx2UHAYM2awxgpMaDa/3GJxgeKWM6vDhmhi/sM56Ov58gOyZ BncDRnnBa/9tV1DFDdme4f8v72+zodrFDj8X0yFVPgFtoGDpT0RurTr9U+r/+WXtM3su +oydKlnkCLVo6d7ii1ktaTPqSbihzH5wpKPTIE1otKbBrTRWAbgdasf7C1HPdR/yb2hs 5WPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AzT2zSb2THNUuyQZXITuwOuNUzZi7qz7YcPLPaKf/rI=; b=RIOQFfqcA5YxJuUpurihXiUZ/uPaKwC4HObmFWtaQXxMhK0i5h/q5ieaem/EKUR9C6 rXkGTBB/1Az5cvbCk7qQzRcBydnNeBU0DDMr7XiPaKZdmQi0k9OdXcHsijKh4y4xbd+7 2uK57BqOx5mInPWe4VnTkL6QyRsZYFdRcRMGKOGjwY81qwxZSDEtXHfN32Pnu2ES0Vfr Fu9PRO5t4vbbRp5qI4QV8nXSiSBJSngyEel0coVZQGzOG5aF3sWJRZcYGMOdsTKdobZo XECirDdh+TGnPZpkHQu97i+DZ7wlL3LFH8+aZrDKeFfNoXX2lGEccBuclWHAttbRfKyS gDqA== X-Gm-Message-State: AOAM530DEFF69O7nBQkZfXwlUIEQKgf2NUUV1LyCHmlY+RmZB6r9uclC tHBZXzLie7pY8A8NBNxjI3+U82ZmaSvdEZfexdbADQ== X-Received: by 2002:a17:90b:4d92:: with SMTP id oj18mr2896123pjb.236.1644304315799; Mon, 07 Feb 2022 23:11:55 -0800 (PST) MIME-Version: 1.0 References: <20220129093036.488231-1-pumahsu@google.com> <413ce7e5-1c35-c3d0-a89e-a3c7f03b4db7@linux.intel.com> In-Reply-To: <413ce7e5-1c35-c3d0-a89e-a3c7f03b4db7@linux.intel.com> From: Puma Hsu Date: Tue, 8 Feb 2022 15:11:19 +0800 Message-ID: Subject: Re: [PATCH v6] xhci: re-initialize the HC during resume if HCE was set To: Mathias Nyman Cc: mathias.nyman@intel.com, Greg KH , Sergey Shtylyov , Albert Wang , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-15.3 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 Thu, Feb 3, 2022 at 3:11 AM Mathias Nyman wrote: > > On 29.1.2022 11.30, Puma Hsu wrote: > > When HCE(Host Controller Error) is set, it means an internal > > error condition has been detected. Software needs to re-initialize > > the HC, so add this check in xhci resume. > > > > Cc: stable@vger.kernel.org > > Signed-off-by: Puma Hsu > > --- > > v2: Follow Sergey Shtylyov 's comment. > > v3: Add stable@vger.kernel.org for stable release. > > v4: Refine the commit message. > > v5: Add a debug log. Follow Mathias Nyman 's comment. > > v6: Fix the missing declaration for str. > > > > drivers/usb/host/xhci.c | 7 +++++-- > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c > > index dc357cabb265..6f1198068004 100644 > > --- a/drivers/usb/host/xhci.c > > +++ b/drivers/usb/host/xhci.c > > @@ -1091,6 +1091,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) > > int retval = 0; > > bool comp_timer_running = false; > > bool pending_portevent = false; > > + char str[XHCI_MSG_MAX]; > > > > if (!hcd->state) > > return 0; > > @@ -1146,8 +1147,10 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) > > temp = readl(&xhci->op_regs->status); > > } > > > > - /* If restore operation fails, re-initialize the HC during resume */ > > - if ((temp & STS_SRE) || hibernated) { > > + /* If restore operation fails or HC error is detected, re-initialize the HC during resume */ > > + if ((temp & (STS_SRE | STS_HCE)) || hibernated) { > > + xhci_warn(xhci, "re-initialize HC during resume, USBSTS:%s\n", > > + xhci_decode_usbsts(str, temp)); > > > > if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && > > !(xhci_all_ports_seen_u0(xhci))) { > > > > Ended up modifying this patch a bit more than I first intended, > - don't print warning in hibernation case, only error. > - maybe using a lot of stack for a debug string isn't really needed. > - make sure we read the usbsts register before checking for the HCE bit. > > Does the below work for you? If yes, and you agree I'll apply it instead Hi Mathias, Yes, your patch works for me, thanks! Will you submit a new patch? or should I update to a new version? Thanks. > --- > > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c > index dc357cabb265..04ec2de158bf 100644 > --- a/drivers/usb/host/xhci.c > +++ b/drivers/usb/host/xhci.c > @@ -1091,6 +1091,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) > int retval = 0; > bool comp_timer_running = false; > bool pending_portevent = false; > + bool reinit_xhc = false; > > if (!hcd->state) > return 0; > @@ -1107,10 +1108,11 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) > set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); > > spin_lock_irq(&xhci->lock); > - if ((xhci->quirks & XHCI_RESET_ON_RESUME) || xhci->broken_suspend) > - hibernated = true; > > - if (!hibernated) { > + if (hibernated || xhci->quirks & XHCI_RESET_ON_RESUME || xhci->broken_suspend) > + reinit_xhc = true; > + > + if (!reinit_xhc) { > /* > * Some controllers might lose power during suspend, so wait > * for controller not ready bit to clear, just as in xHC init. > @@ -1143,12 +1145,17 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) > spin_unlock_irq(&xhci->lock); > return -ETIMEDOUT; > } > - temp = readl(&xhci->op_regs->status); > } > > - /* If restore operation fails, re-initialize the HC during resume */ > - if ((temp & STS_SRE) || hibernated) { > + temp = readl(&xhci->op_regs->status); > + > + /* re-initialize the HC on Restore Error, or Host Controller Error */ > + if (temp & (STS_SRE | STS_HCE)) { > + reinit_xhc = true; > + xhci_warn(xhci, "xHC error in resume, USBSTS 0x%x, Reinit\n", temp); > + } > > + if (reinit_xhc) { > if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && > !(xhci_all_ports_seen_u0(xhci))) { > del_timer_sync(&xhci->comp_mode_recovery_timer); >