From patchwork Fri Aug 21 09:15: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: 11728671 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 8DF5F14F6 for ; Fri, 21 Aug 2020 09:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BDD12087D for ; Fri, 21 Aug 2020 09:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbgHUJMp (ORCPT ); Fri, 21 Aug 2020 05:12:45 -0400 Received: from mga18.intel.com ([134.134.136.126]:65060 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbgHUJMo (ORCPT ); Fri, 21 Aug 2020 05:12:44 -0400 IronPort-SDR: eKNFLZc2P+Jnmh/4il2TmdyXHKcq/epj+JobJyk23hVqpSCpdsv8eqGKy7Uk+NZiRIEb/y10E6 HNUqnHCipzwQ== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="143128378" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="143128378" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 02:12:43 -0700 IronPort-SDR: L1ZHWVWUhHwtoxg4o5YprUVrPG06hB6Cvi1y4bPasQYrTqFfnLZT1G/jr1j1kK6sI6hzLuVw4k /7Nhmxm05Ogw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="321194890" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga004.fm.intel.com with ESMTP; 21 Aug 2020 02:12:42 -0700 From: Mathias Nyman To: Cc: , Li Jun , stable , Mathias Nyman Subject: [PATCH 1/3] usb: host: xhci: fix ep context print mismatch in debugfs Date: Fri, 21 Aug 2020 12:15:47 +0300 Message-Id: <20200821091549.20556-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200821091549.20556-1-mathias.nyman@linux.intel.com> References: <20200821091549.20556-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: Li Jun dci is 0 based and xhci_get_ep_ctx() will do ep index increment to get the ep context. [rename dci to ep_index -Mathias] Cc: stable # v4.15+ Fixes: 02b6fdc2a153 ("usb: xhci: Add debugfs interface for xHCI driver") Signed-off-by: Li Jun Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-debugfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index 92e25a62fdb5..c88bffd68742 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -274,7 +274,7 @@ static int xhci_slot_context_show(struct seq_file *s, void *unused) static int xhci_endpoint_context_show(struct seq_file *s, void *unused) { - int dci; + int ep_index; dma_addr_t dma; struct xhci_hcd *xhci; struct xhci_ep_ctx *ep_ctx; @@ -283,9 +283,9 @@ static int xhci_endpoint_context_show(struct seq_file *s, void *unused) xhci = hcd_to_xhci(bus_to_hcd(dev->udev->bus)); - for (dci = 1; dci < 32; dci++) { - ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, dci); - dma = dev->out_ctx->dma + dci * CTX_SIZE(xhci->hcc_params); + for (ep_index = 0; ep_index < 31; ep_index++) { + ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); + dma = dev->out_ctx->dma + (ep_index + 1) * CTX_SIZE(xhci->hcc_params); seq_printf(s, "%pad: %s\n", &dma, xhci_decode_ep_context(le32_to_cpu(ep_ctx->ep_info), le32_to_cpu(ep_ctx->ep_info2), From patchwork Fri Aug 21 09:15: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: 11728675 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 12B7C14F6 for ; Fri, 21 Aug 2020 09:12:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFA88208DB for ; Fri, 21 Aug 2020 09:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727987AbgHUJMs (ORCPT ); Fri, 21 Aug 2020 05:12:48 -0400 Received: from mga18.intel.com ([134.134.136.126]:65060 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727780AbgHUJMr (ORCPT ); Fri, 21 Aug 2020 05:12:47 -0400 IronPort-SDR: YsSiN+7ZdFMhZV3q41L6suoPN4aBKx2Jgntd7L6iRiPAMmXjoK6AIudp3g/iVN4DQMtTVxhcB+ ucfuAuYYU13A== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="143128379" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="143128379" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 02:12:47 -0700 IronPort-SDR: ApBpiIXPkEePgPrHMGK3xbzaDGFSZZrywAoIP2j3jTV6XQCcHib55P9PbQnp1UN8tuu7Sp8sBB VKCJ53B+opFw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="321194900" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga004.fm.intel.com with ESMTP; 21 Aug 2020 02:12:44 -0700 From: Mathias Nyman To: Cc: , Kai-Heng Feng , stable , Mathias Nyman Subject: [PATCH 2/3] xhci: Do warm-reset when both CAS and XDEV_RESUME are set Date: Fri, 21 Aug 2020 12:15:48 +0300 Message-Id: <20200821091549.20556-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200821091549.20556-1-mathias.nyman@linux.intel.com> References: <20200821091549.20556-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 Sometimes re-plugging a USB device during system sleep renders the device useless: [ 173.418345] xhci_hcd 0000:00:14.0: Get port status 2-4 read: 0x14203e2, return 0x10262 ... [ 176.496485] usb 2-4: Waited 2000ms for CONNECT [ 176.496781] usb usb2-port4: status 0000.0262 after resume, -19 [ 176.497103] usb 2-4: can't resume, status -19 [ 176.497438] usb usb2-port4: logical disconnect Because PLS equals to XDEV_RESUME, xHCI driver reports U3 to usbcore, despite of CAS bit is flagged. So proritize CAS over XDEV_RESUME to let usbcore handle warm-reset for the port. Cc: stable Signed-off-by: Kai-Heng Feng Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-hub.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index c3554e37e09f..4e14e164cb68 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -740,15 +740,6 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, { u32 pls = status_reg & PORT_PLS_MASK; - /* resume state is a xHCI internal state. - * Do not report it to usb core, instead, pretend to be U3, - * thus usb core knows it's not ready for transfer - */ - if (pls == XDEV_RESUME) { - *status |= USB_SS_PORT_LS_U3; - return; - } - /* When the CAS bit is set then warm reset * should be performed on port */ @@ -770,6 +761,16 @@ static void xhci_hub_report_usb3_link_state(struct xhci_hcd *xhci, */ pls |= USB_PORT_STAT_CONNECTION; } else { + /* + * Resume state is an xHCI internal state. Do not report it to + * usb core, instead, pretend to be U3, thus usb core knows + * it's not ready for transfer. + */ + if (pls == XDEV_RESUME) { + *status |= USB_SS_PORT_LS_U3; + return; + } + /* * If CAS bit isn't set but the Port is already at * Compliance Mode, fake a connection so the USB core From patchwork Fri Aug 21 09:15: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: 11728673 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 0535A14F6 for ; Fri, 21 Aug 2020 09:12:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2F3E2177B for ; Fri, 21 Aug 2020 09:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727909AbgHUJMr (ORCPT ); Fri, 21 Aug 2020 05:12:47 -0400 Received: from mga12.intel.com ([192.55.52.136]:18835 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbgHUJMr (ORCPT ); Fri, 21 Aug 2020 05:12:47 -0400 IronPort-SDR: u4d8Fd2yVH1CX3OiGtLr+7/JW5Hav2nLgQe2trSXmaPqItcr5Gdq+OAhW6VnSl/9lpneTsW8Jl C9YHSII7LjtQ== X-IronPort-AV: E=McAfee;i="6000,8403,9719"; a="135030350" X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="135030350" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 02:12:46 -0700 IronPort-SDR: 5edi+br547/00TzYXlNZS3wWA82DdxUEtmUQS17uugRd7FXzR1hgm0ceGVAdkkYaRJr3tWtTjB kUeH2zXVg49A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,335,1592895600"; d="scan'208";a="321194905" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga004.fm.intel.com with ESMTP; 21 Aug 2020 02:12:46 -0700 From: Mathias Nyman To: Cc: , Ding Hui , stable , Mathias Nyman Subject: [PATCH 3/3] xhci: Always restore EP_SOFT_CLEAR_TOGGLE even if ep reset failed Date: Fri, 21 Aug 2020 12:15:49 +0300 Message-Id: <20200821091549.20556-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200821091549.20556-1-mathias.nyman@linux.intel.com> References: <20200821091549.20556-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: Ding Hui Some device drivers call libusb_clear_halt when target ep queue is not empty. (eg. spice client connected to qemu for usb redir) Before commit f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset"), that works well. But now, we got the error log: EP not empty, refuse reset xhci_endpoint_reset failed and left ep_state's EP_SOFT_CLEAR_TOGGLE bit still set So all the subsequent urb sumbits to the ep will fail with the warn log: Can't enqueue URB while manually clearing toggle We need to clear ep_state EP_SOFT_CLEAR_TOGGLE bit after xhci_endpoint_reset, even if it failed. Fixes: f5249461b504 ("xhci: Clear the host side toggle manually when endpoint is soft reset" Cc: stable # v4.17+ Signed-off-by: Ding Hui Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 3c41b14ecce7..e9884ae9c77d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3236,10 +3236,11 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, wait_for_completion(cfg_cmd->completion); - ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; xhci_free_command(xhci, cfg_cmd); cleanup: xhci_free_command(xhci, stop_cmd); + if (ep->ep_state & EP_SOFT_CLEAR_TOGGLE) + ep->ep_state &= ~EP_SOFT_CLEAR_TOGGLE; } static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,