From patchwork Wed Jun 24 13:59:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11623231 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8C6D14E3 for ; Wed, 24 Jun 2020 13:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB64420781 for ; Wed, 24 Jun 2020 13:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403995AbgFXN4u (ORCPT ); Wed, 24 Jun 2020 09:56:50 -0400 Received: from mga02.intel.com ([134.134.136.20]:43621 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403988AbgFXN4t (ORCPT ); Wed, 24 Jun 2020 09:56:49 -0400 IronPort-SDR: bsdUCaeIpFPvR/waB7x3aHUK+rPOYm+211kl8kvCiK46AkTvzVGXsRWRRBWEo/IsE4uZDyLMdN qu6KuhnYPNdg== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="132909235" X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="132909235" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 06:56:49 -0700 IronPort-SDR: GvYDAlAvEJinW2lPbtJBxLMTCUdj0IS7x+oNC/TYNtPbxKZVyMK/R1h4VOOou2g+e66sbB/F9i ehzQwqRkXvSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="263644026" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2020 06:56:47 -0700 From: Mathias Nyman To: Cc: , Mathias Nyman , stable@vger.kernel.org Subject: [PATCH 1/5] xhci: Fix incorrect EP_STATE_MASK Date: Wed, 24 Jun 2020 16:59:45 +0300 Message-Id: <20200624135949.22611-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624135949.22611-1-mathias.nyman@linux.intel.com> References: <20200624135949.22611-1-mathias.nyman@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org EP_STATE_MASK should be 0x7 instead of 0xf xhci spec 6.2.3 shows that the EP state field in the endpoint context data structure consist of bits [2:0]. The old value included a bit from the next field which fortunately is a RsvdZ region. So hopefully this hasn't caused too much harm Cc: stable@vger.kernel.org Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 2c6c4f8d1ee1..c295e8a7f5ae 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -716,7 +716,7 @@ struct xhci_ep_ctx { * 4 - TRB error * 5-7 - reserved */ -#define EP_STATE_MASK (0xf) +#define EP_STATE_MASK (0x7) #define EP_STATE_DISABLED 0 #define EP_STATE_RUNNING 1 #define EP_STATE_HALTED 2 From patchwork Wed Jun 24 13:59:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11623233 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66D29913 for ; Wed, 24 Jun 2020 13:56:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57CEB20781 for ; Wed, 24 Jun 2020 13:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403998AbgFXN4w (ORCPT ); Wed, 24 Jun 2020 09:56:52 -0400 Received: from mga02.intel.com ([134.134.136.20]:43621 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403988AbgFXN4v (ORCPT ); Wed, 24 Jun 2020 09:56:51 -0400 IronPort-SDR: QQz8Hc5i5KjwmscPx//gt9LfU1NXeUehjYrTOYA7I8UsDILNX2LFT3yFkBtDoxMwewCZTdEUvs mjGl2DSpiulQ== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="132909248" X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="132909248" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 06:56:51 -0700 IronPort-SDR: Uxu3TMFCFHnKJdxg1E0+XmOR4Zz4FrMrAoeEiUd7ej26YP5XD5OmcddpMji3sYU00JcBl9V25N cL8Cnk1lnzAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="263644036" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2020 06:56:49 -0700 From: Mathias Nyman To: Cc: , Al Cooper , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 2/5] xhci: Fix enumeration issue when setting max packet size for FS devices. Date: Wed, 24 Jun 2020 16:59:46 +0300 Message-Id: <20200624135949.22611-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624135949.22611-1-mathias.nyman@linux.intel.com> References: <20200624135949.22611-1-mathias.nyman@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Al Cooper Unable to complete the enumeration of a USB TV Tuner device. Per XHCI spec (4.6.5), the EP state field of the input context shall be cleared for a set address command. In the special case of an FS device that has "MaxPacketSize0 = 8", the Linux XHCI driver does not do this before evaluating the context. With an XHCI controller that checks the EP state field for parameter context error this causes a problem in cases such as the device getting reset again after enumeration. When that field is cleared, the problem does not occur. This was found and fixed by Sasi Kumar. Cc: stable@vger.kernel.org Signed-off-by: Al Cooper Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index bee5deccc83d..03b64b73eb99 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1430,6 +1430,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, xhci->devs[slot_id]->out_ctx, ep_index); ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index); + ep_ctx->ep_info &= cpu_to_le32(~EP_STATE_MASK);/* must clear */ ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK); ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size)); From patchwork Wed Jun 24 13:59:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11623235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 035FC913 for ; Wed, 24 Jun 2020 13:56:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE7A920836 for ; Wed, 24 Jun 2020 13:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404000AbgFXN4y (ORCPT ); Wed, 24 Jun 2020 09:56:54 -0400 Received: from mga02.intel.com ([134.134.136.20]:43621 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403988AbgFXN4x (ORCPT ); Wed, 24 Jun 2020 09:56:53 -0400 IronPort-SDR: 3MSPoUC55S6kawWRJIWwwEm991ipDYXzGcFxkXdHlCFLN63rd0NfB3VmEJEs2qH+RXbpEADz9Q Ykd+Fakalm+g== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="132909267" X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="132909267" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 06:56:52 -0700 IronPort-SDR: QZC3rZlRDVXUALtvInsbMnADpN+lK5GiIzU3JSxxWKKAKyTS85r3WurtP7PXi4moQR3hQgMWYb iarqqjAhx59g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="263644049" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2020 06:56:51 -0700 From: Mathias Nyman To: Cc: , Macpaul Lin , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 3/5] usb: host: xhci-mtk: avoid runtime suspend when removing hcd Date: Wed, 24 Jun 2020 16:59:47 +0300 Message-Id: <20200624135949.22611-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624135949.22611-1-mathias.nyman@linux.intel.com> References: <20200624135949.22611-1-mathias.nyman@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Macpaul Lin When runtime suspend was enabled, runtime suspend might happen when xhci is removing hcd. This might cause kernel panic when hcd has been freed but runtime pm suspend related handle need to reference it. Signed-off-by: Macpaul Lin Reviewed-by: Chunfeng Yun Cc: stable@vger.kernel.org Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mtk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c index bfbdb3ceed29..4311d4c9b68d 100644 --- a/drivers/usb/host/xhci-mtk.c +++ b/drivers/usb/host/xhci-mtk.c @@ -587,6 +587,9 @@ static int xhci_mtk_remove(struct platform_device *dev) struct xhci_hcd *xhci = hcd_to_xhci(hcd); struct usb_hcd *shared_hcd = xhci->shared_hcd; + pm_runtime_put_noidle(&dev->dev); + pm_runtime_disable(&dev->dev); + usb_remove_hcd(shared_hcd); xhci->shared_hcd = NULL; device_init_wakeup(&dev->dev, false); @@ -597,8 +600,6 @@ static int xhci_mtk_remove(struct platform_device *dev) xhci_mtk_sch_exit(mtk); xhci_mtk_clks_disable(mtk); xhci_mtk_ldos_disable(mtk); - pm_runtime_put_sync(&dev->dev); - pm_runtime_disable(&dev->dev); return 0; } From patchwork Wed Jun 24 13:59:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11623237 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B729360D for ; Wed, 24 Jun 2020 13:56:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DFD320836 for ; Wed, 24 Jun 2020 13:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404003AbgFXN45 (ORCPT ); Wed, 24 Jun 2020 09:56:57 -0400 Received: from mga02.intel.com ([134.134.136.20]:43621 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403988AbgFXN44 (ORCPT ); Wed, 24 Jun 2020 09:56:56 -0400 IronPort-SDR: CHxjOlN/I2NnaeCepfCigJ0SdDWQQcUzX6Wy3fLi7T5CiYofUpLGQ97tLberabqDLNtxoYUiiB ec3C2QplRDtg== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="132909273" X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="132909273" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 06:56:54 -0700 IronPort-SDR: 7GufgUfPevYUFSYVvAr9L29Z7PKaQpp69WU9cT/WnXmMyxdxIRmoD+/fs8roW8eq/Dh0fUSoi4 ImJvbq1Ygh3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="263644059" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2020 06:56:53 -0700 From: Mathias Nyman To: Cc: , Kai-Heng Feng , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 4/5] xhci: Return if xHCI doesn't support LPM Date: Wed, 24 Jun 2020 16:59:48 +0300 Message-Id: <20200624135949.22611-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624135949.22611-1-mathias.nyman@linux.intel.com> References: <20200624135949.22611-1-mathias.nyman@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Kai-Heng Feng Just return if xHCI is quirked to disable LPM. We can save some time from reading registers and doing spinlocks. Add stable tag as we want this patch together with the next one, "Poll for U0 after disabling USB2 LPM" which fixes a suspend issue for some USB2 LPM devices Cc: stable@vger.kernel.org Signed-off-by: Kai-Heng Feng Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 03b64b73eb99..f97106e2860f 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4391,6 +4391,9 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, int hird, exit_latency; int ret; + if (xhci->quirks & XHCI_HW_LPM_DISABLE) + return -EPERM; + if (hcd->speed >= HCD_USB3 || !xhci->hw_lpm_support || !udev->lpm_capable) return -EPERM; @@ -4413,7 +4416,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", enable ? "enable" : "disable", port_num + 1); - if (enable && !(xhci->quirks & XHCI_HW_LPM_DISABLE)) { + if (enable) { /* Host supports BESL timeout instead of HIRD */ if (udev->usb2_hw_lpm_besl_capable) { /* if device doesn't have a preferred BESL value use a From patchwork Wed Jun 24 13:59:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11623239 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 436F760D for ; Wed, 24 Jun 2020 13:57:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2634520836 for ; Wed, 24 Jun 2020 13:57:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403987AbgFXN5J (ORCPT ); Wed, 24 Jun 2020 09:57:09 -0400 Received: from mga02.intel.com ([134.134.136.20]:43639 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389544AbgFXN5I (ORCPT ); Wed, 24 Jun 2020 09:57:08 -0400 IronPort-SDR: 6Nqy74fbKE+YbkzIeXmYnnQ1Jp4CP2LQ1c2RGVDDQ9KGXdd6IS5KBgujyIPlPQvOAOwRjjhIwl 03aGTM62fDiQ== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="132909282" X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="132909282" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2020 06:56:56 -0700 IronPort-SDR: A4P6iVBtT+xePkzVqnJ0pKEX+VfueRWxXSASMWyB/IAEOtr6FUfKiw5gIz/XCfUZGC/skH9KXo uFbshhT2+EQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,275,1589266800"; d="scan'208";a="263644061" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2020 06:56:55 -0700 From: Mathias Nyman To: Cc: , Kai-Heng Feng , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 5/5] xhci: Poll for U0 after disabling USB2 LPM Date: Wed, 24 Jun 2020 16:59:49 +0300 Message-Id: <20200624135949.22611-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200624135949.22611-1-mathias.nyman@linux.intel.com> References: <20200624135949.22611-1-mathias.nyman@linux.intel.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Kai-Heng Feng USB2 devices with LPM enabled may interrupt the system suspend: [ 932.510475] usb 1-7: usb suspend, wakeup 0 [ 932.510549] hub 1-0:1.0: hub_suspend [ 932.510581] usb usb1: bus suspend, wakeup 0 [ 932.510590] xhci_hcd 0000:00:14.0: port 9 not suspended [ 932.510593] xhci_hcd 0000:00:14.0: port 8 not suspended .. [ 932.520323] xhci_hcd 0000:00:14.0: Port change event, 1-7, id 7, portsc: 0x400e03 .. [ 932.591405] PM: pci_pm_suspend(): hcd_pci_suspend+0x0/0x30 returns -16 [ 932.591414] PM: dpm_run_callback(): pci_pm_suspend+0x0/0x160 returns -16 [ 932.591418] PM: Device 0000:00:14.0 failed to suspend async: error -16 During system suspend, USB core will let HC suspends the device if it doesn't have remote wakeup enabled and doesn't have any children. However, from the log above we can see that the usb 1-7 doesn't get bus suspended due to not in U0. After a while the port finished U2 -> U0 transition, interrupts the suspend process. The observation is that after disabling LPM, port doesn't transit to U0 immediately and can linger in U2. xHCI spec 4.23.5.2 states that the maximum exit latency for USB2 LPM should be BESL + 10us. The BESL for the affected device is advertised as 400us, which is still not enough based on my testing result. So let's use the maximum permitted latency, 10000, to poll for U0 status to solve the issue. Cc: stable@vger.kernel.org Signed-off-by: Kai-Heng Feng Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index f97106e2860f..ed468eed299c 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4475,6 +4475,9 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, mutex_lock(hcd->bandwidth_mutex); xhci_change_max_exit_latency(xhci, udev, 0); mutex_unlock(hcd->bandwidth_mutex); + readl_poll_timeout(ports[port_num]->addr, pm_val, + (pm_val & PORT_PLS_MASK) == XDEV_U0, + 100, 10000); return 0; } }