From patchwork Fri Apr 8 13:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 12806777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7380AC433EF for ; Fri, 8 Apr 2022 13:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236479AbiDHNsp (ORCPT ); Fri, 8 Apr 2022 09:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbiDHNsn (ORCPT ); Fri, 8 Apr 2022 09:48:43 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C13F60CEF for ; Fri, 8 Apr 2022 06:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649425599; x=1680961599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=136wie3i/bYsT6DVEB+wKLiTRysIqDsROC7NtcicCrc=; b=ZZEFiQvV0gocePNRMuYA0oNqUdvqGxEYyX6Q1nB3V0IEfgmVPNzl2ZJf EzoeTIB519sK/bHHuDSMmMBDU3Tn4MEqeNu/HS6iZavbYnzBTC9ZOtkAl 7sZLweijw/hgnCNsAeafnKeyEWmUwTcgtruzern28k0RPWJFNWKzIwzFq OBF6Fh3zryVPsm1vTC7Gt4MTW0lPkXZsfyu+X+tfUU5e0OfeS/tjkNIKp 9vj0PUiIxBpaOQ4OEvgEudj/X8jMX/c3opzMgpdWm+1M7K0qLBUgcEPpx GQavxwRyybStIfuGV3htbDXvXg2PevNgM+qeaZ+rHaR3+Zz0YdGes5pP+ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="260432083" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="260432083" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:46:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="653263282" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmsmga002.fm.intel.com with ESMTP; 08 Apr 2022 06:46:37 -0700 From: Mathias Nyman To: Cc: , Weitao Wang , Peter Chen , Mathias Nyman Subject: [PATCH 1/3] USB: Fix xhci event ring dequeue pointer ERDP update issue Date: Fri, 8 Apr 2022 16:48:21 +0300 Message-Id: <20220408134823.2527272-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> References: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Weitao Wang In some situations software handles TRB events slower than adding TRBs. If the number of TRB events to be processed in a given interrupt is exactly the same as the event ring size 256, then the local variable "event_ring_deq" that holds the initial dequeue position is equal to software_dequeue after handling all 256 interrupts. It will cause driver to not update ERDP to hardware, Software dequeue pointer is out of sync with ERDP on interrupt exit. On the next interrupt, the event ring may full but driver will not update ERDP as software_dequeue is equal to ERDP. [ 536.377115] xhci_hcd 0000:00:12.0: ERROR unknown event type 37 [ 566.933173] sd 8:0:0:0: [sdb] tag#27 uas_eh_abort_handler 0 uas-tag 7 inflight: CMD OUT [ 566.933181] sd 8:0:0:0: [sdb] tag#27 CDB: Write(10) 2a 00 17 71 e6 78 00 00 08 00 [ 572.041186] xhci_hcd On some situataions,the0000:00:12.0: xHCI host not responding to stop endpoint command. [ 572.057193] xhci_hcd 0000:00:12.0: Host halt failed, -110 [ 572.057196] xhci_hcd 0000:00:12.0: xHCI host controller not responding, assume dead [ 572.057236] sd 8:0:0:0: [sdb] tag#26 uas_eh_abort_handler 0 uas-tag 6 inflight: CMD [ 572.057240] sd 8:0:0:0: [sdb] tag#26 CDB: Write(10) 2a 00 38 eb cc d8 00 00 08 00 [ 572.057244] sd 8:0:0:0: [sdb] tag#25 uas_eh_abort_handler 0 uas-tag 5 inflight: CMD Hardware ERDP is updated mid event handling if there are more than 128 events in an interrupt (half of ring size). Fix this by updating the software local variable at the same time as hardware ERDP. [commit message rewording -Mathias] Fixes: dc0ffbea5729 ("usb: host: xhci: update event ring dequeue pointer on purpose") Signed-off-by: Weitao Wang Reviewed-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d0b6806275e0..f9707997969d 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3141,6 +3141,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd) if (event_loop++ < TRBS_PER_SEGMENT / 2) continue; xhci_update_erst_dequeue(xhci, event_ring_deq); + event_ring_deq = xhci->event_ring->dequeue; /* ring is half-full, force isoc trbs to interrupt more often */ if (xhci->isoc_bei_interval > AVOID_BEI_INTERVAL_MIN) From patchwork Fri Apr 8 13:48:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 12806779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0E46C433F5 for ; Fri, 8 Apr 2022 13:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236483AbiDHNsq (ORCPT ); Fri, 8 Apr 2022 09:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236478AbiDHNso (ORCPT ); Fri, 8 Apr 2022 09:48:44 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DFE460CEF; Fri, 8 Apr 2022 06:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649425601; x=1680961601; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2RsBxvZgX52mmyvnnY0IE8cn0uckQN1XXAvC+D/+vJU=; b=PGinHrV924gbEGL2gBBl0MGxH4PC4nRwU4fRJQtfze28igfPHDevDBt9 QswiQ2Hvbfc0yCphj5uTQdtdJBMfhe4tGWC3SSQpmMUnclk/D1MnwXxHw uDCssu5m9m0AcZNKLiTFY3Z4vq7WwSvJuP3YyshI+kffWURGFjZm4RE4U 8lXiVtRpRYozGb+uokoBTdpFkEI7uyjLJAM/MPuomtnCVoSOunXH5YlRX IzfhCtNw7LhwCyujsmbvDVE+bhaAFBtjKTvjW43gp0XUO3qMXpAol58my 4rrpUtqhyHHrAdNectONvJtq5SvD09v+PqNOmYsjAKBHTgbLqeYj/aWXo Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="260432091" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="260432091" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:46:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="653263290" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmsmga002.fm.intel.com with ESMTP; 08 Apr 2022 06:46:39 -0700 From: Mathias Nyman To: Cc: , Henry Lin , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 2/3] xhci: stop polling roothubs after shutdown Date: Fri, 8 Apr 2022 16:48:22 +0300 Message-Id: <20220408134823.2527272-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> References: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Henry Lin While rebooting, XHCI controller and its bus device will be shut down in order by .shutdown callback. Stopping roothubs polling in xhci_shutdown() can prevent XHCI driver from accessing port status after its bus device shutdown. Take PCIe XHCI controller as example, if XHCI driver doesn't stop roothubs polling, XHCI driver may access PCIe BAR register for port status after parent PCIe root port driver is shutdown and cause PCIe bus error. [check shared hcd exist before stopping its roothub polling -Mathias] Cc: stable@vger.kernel.org Signed-off-by: Henry Lin Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 642610c78f58..25b87e99b4dd 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -781,6 +781,17 @@ void xhci_shutdown(struct usb_hcd *hcd) if (xhci->quirks & XHCI_SPURIOUS_REBOOT) usb_disable_xhci_ports(to_pci_dev(hcd->self.sysdev)); + /* Don't poll the roothubs after shutdown. */ + xhci_dbg(xhci, "%s: stopping usb%d port polling.\n", + __func__, hcd->self.busnum); + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); + del_timer_sync(&hcd->rh_timer); + + if (xhci->shared_hcd) { + clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); + del_timer_sync(&xhci->shared_hcd->rh_timer); + } + spin_lock_irq(&xhci->lock); xhci_halt(xhci); /* Workaround for spurious wakeups at shutdown with HSW */ From patchwork Fri Apr 8 13:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 12806778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5150C43217 for ; Fri, 8 Apr 2022 13:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236488AbiDHNss (ORCPT ); Fri, 8 Apr 2022 09:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236481AbiDHNsq (ORCPT ); Fri, 8 Apr 2022 09:48:46 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD0E8BF4F; Fri, 8 Apr 2022 06:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649425602; x=1680961602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=l4VBFcXc3qAqGn+1Yb4l3Fd2gPYj10oSRfyXmwYf1JQ=; b=HFswPf9erbKAZXdZA9yx0u/FTDIlTUOMIHOCTEcjhvlDQVGDkaFUk6N9 JsG+nhpRPxcVdFbDA86N64k/90OElu0rzYyN3Tpx0lLrxCTBOzftJQISM aapgtqHAj1t/svw1+Pqea3I7wFfnO3YUpC/k7NuHKUnWsu+ih67KRoG8h +SQXfBObNDW8KVKcTfhcz7DsBq23iDFJfCn0QUmkk7Sq9qB8XE+sHgN0y 4YtlNgGy+QW17+5csUvdHaae2S+uzavvtTmeBpgRd5zkzwDr6HmFAQCdP 5HFCmIOGSMLQjpiEGqM3jV3IL4cxXTvLTmDGND/aI5cV3Ta4femu6Ylcd A==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="260432095" X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="260432095" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 06:46:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,245,1643702400"; d="scan'208";a="653263292" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmsmga002.fm.intel.com with ESMTP; 08 Apr 2022 06:46:41 -0700 From: Mathias Nyman To: Cc: , Mathias Nyman , stable@vger.kernel.org Subject: [PATCH 3/3] xhci: increase usb U3 -> U0 link resume timeout from 100ms to 500ms Date: Fri, 8 Apr 2022 16:48:23 +0300 Message-Id: <20220408134823.2527272-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> References: <20220408134823.2527272-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The first U3 wake signal by the host may be lost if the USB 3 connection is tunneled over USB4, with a runtime suspended USB4 host, and firmware implemented connection manager. Specs state the host must wait 100ms (tU3WakeupRetryDelay) before resending a U3 wake signal if device doesn't respond, leading to U3 -> U0 link transition times around 270ms in the tunneled case. Cc: stable@vger.kernel.org Fixes: 0200b9f790b0 ("xhci: Wait until link state trainsits to U0 after setting USB_SS_PORT_LS_U0") Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-hub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 1e7dc130c39a..f65f1ba2b592 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1434,7 +1434,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, } spin_unlock_irqrestore(&xhci->lock, flags); if (!wait_for_completion_timeout(&bus_state->u3exit_done[wIndex], - msecs_to_jiffies(100))) + msecs_to_jiffies(500))) xhci_dbg(xhci, "missing U0 port change event for port %d-%d\n", hcd->self.busnum, wIndex + 1); spin_lock_irqsave(&xhci->lock, flags);