From patchwork Fri Sep 18 13:17:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11785051 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 DF1C359D for ; Fri, 18 Sep 2020 13:14:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4D7B23788 for ; Fri, 18 Sep 2020 13:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbgIRNO3 (ORCPT ); Fri, 18 Sep 2020 09:14:29 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNO2 (ORCPT ); Fri, 18 Sep 2020 09:14:28 -0400 IronPort-SDR: gEDQL9VD8jol2OfErpMH6+RRXfWU0liKFOXIrGt6c2I7/irj4Dgzyc55JVBsI4SJHSTVbYwdD2 l88lKnRFyssg== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849945" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849945" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:27 -0700 IronPort-SDR: ysztfmWIuF69AnpuLWP6jjBkE3tH51bjhnvZvgAThZ7JSWUxyr3PfGawYwAWayqc6c/yaAJUa+ XgS+j4SrzF9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871158" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:26 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 01/10] usb: host: xhci-plat: add platform data support Date: Fri, 18 Sep 2020 16:17:43 +0300 Message-Id: <20200918131752.16488-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen Some xhci hosts (eg dwc3 and cdns3) do not use OF to create platform device, they create xhci-plat platform device runtime. And these platforms may also have quirks, and the quirks could be supplied by their parent device through platform data. Reviewed-by: Jun Li Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 3057cfc76d6a..c7f98edc5678 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -264,7 +264,11 @@ static int xhci_plat_probe(struct platform_device *pdev) if (ret) goto disable_reg_clk; - priv_match = of_device_get_match_data(&pdev->dev); + if (pdev->dev.of_node) + priv_match = of_device_get_match_data(&pdev->dev); + else + priv_match = dev_get_platdata(&pdev->dev); + if (priv_match) { struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); From patchwork Fri Sep 18 13:17:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11785053 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 DDF2E59D for ; Fri, 18 Sep 2020 13:14:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCD4323788 for ; Fri, 18 Sep 2020 13:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbgIRNOa (ORCPT ); Fri, 18 Sep 2020 09:14:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNO3 (ORCPT ); Fri, 18 Sep 2020 09:14:29 -0400 IronPort-SDR: 8tW64YAtgP/jQDbMJwRRR44xHKYEDyN5iA+gZTx4zwnuCPcJKYfaPE0MKLmRmLIR72KO8RTlSN X0usEGd6uetA== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849948" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849948" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:29 -0700 IronPort-SDR: xWYWt+s48lITgirP+vDf0EmGOB2EoyANp2MXo43RVsu+xShkW4ptfB5c4x4BcUDXGNqlrLub2H QWeZJID56Oew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871165" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:27 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 02/10] usb: host: xhci-plat: add .suspend_quirk for struct xhci_plat_priv Date: Fri, 18 Sep 2020 16:17:44 +0300 Message-Id: <20200918131752.16488-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen Some platforms (eg cdns3) may have special sequences between xhci_bus_suspend and xhci_suspend, add .suspend_quick for it. Reviewed-by: Jun Li Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 19 +++++++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index c7f98edc5678..c3ce4d762adf 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -54,6 +54,16 @@ static int xhci_priv_init_quirk(struct usb_hcd *hcd) return priv->init_quirk(hcd); } +static int xhci_priv_suspend_quirk(struct usb_hcd *hcd) +{ + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + + if (!priv->suspend_quirk) + return 0; + + return priv->suspend_quirk(hcd); +} + static int xhci_priv_resume_quirk(struct usb_hcd *hcd) { struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); @@ -401,7 +411,11 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); + int ret; + ret = xhci_priv_suspend_quirk(hcd); + if (ret) + return ret; /* * xhci_suspend() needs `do_wakeup` to know whether host is allowed * to do wakeup during suspend. Since xhci_plat_suspend is currently @@ -438,6 +452,11 @@ static int __maybe_unused xhci_plat_runtime_suspend(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); + int ret; + + ret = xhci_priv_suspend_quirk(hcd); + if (ret) + return ret; return xhci_suspend(xhci, true); } diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h index b49f6447bd3a..1fb149d1fbce 100644 --- a/drivers/usb/host/xhci-plat.h +++ b/drivers/usb/host/xhci-plat.h @@ -15,6 +15,7 @@ struct xhci_plat_priv { unsigned long long quirks; void (*plat_start)(struct usb_hcd *); int (*init_quirk)(struct usb_hcd *); + int (*suspend_quirk)(struct usb_hcd *); int (*resume_quirk)(struct usb_hcd *); }; From patchwork Fri Sep 18 13:17: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: 11785055 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 94B4759D for ; Fri, 18 Sep 2020 13:14:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85D7A23788 for ; Fri, 18 Sep 2020 13:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726738AbgIRNOc (ORCPT ); Fri, 18 Sep 2020 09:14:32 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOb (ORCPT ); Fri, 18 Sep 2020 09:14:31 -0400 IronPort-SDR: Xo5Wb7Xwb3vWvRC/yltQ7JRYn8iU2JvHPTaS86Kriusx+akJ9FwSNz1olAwLPrkLnyoiWOUPRo wmiGE1F00FmQ== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849953" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849953" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:30 -0700 IronPort-SDR: mw0rLfuDwGvVckYxwJIeiZ4gorUJhyp+p0sue/LnohiwOSAfD23grT5xItpSGYhW3CnlCrq1Vu 5VGGj+gKKang== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871168" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:29 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 03/10] usb: host: xhci-plat: delete the unnecessary code Date: Fri, 18 Sep 2020 16:17:45 +0300 Message-Id: <20200918131752.16488-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen The if {} condition is duplicated with outer if {} condition. Reviewed-by: Jun Li Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index c3ce4d762adf..07ca000a0084 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -283,8 +283,7 @@ static int xhci_plat_probe(struct platform_device *pdev) struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); /* Just copy data for now */ - if (priv_match) - *priv = *priv_match; + *priv = *priv_match; } device_wakeup_enable(hcd->self.controller); From patchwork Fri Sep 18 13:17: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: 11785057 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 D82E86CB for ; Fri, 18 Sep 2020 13:14:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C639423888 for ; Fri, 18 Sep 2020 13:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726742AbgIRNOd (ORCPT ); Fri, 18 Sep 2020 09:14:33 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOc (ORCPT ); Fri, 18 Sep 2020 09:14:32 -0400 IronPort-SDR: hWV27ymzmFlZrqm+iklputjND8J8h/IOKfK7kQpKxJAnutwYbxlY+ESGiFmITnQAJdkuDYST3w ykXogkBlaPZQ== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849954" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849954" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:32 -0700 IronPort-SDR: Ac1877wMp6CldLIZx4OdHc7f640o0x/8RECYZL/Dn4FQr5YwtYSa7MbpGsQFSfAj2mWcQTAapm K6LToGHY0DPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871177" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:31 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 04/10] usb: host: xhci-plat: add priv quirk for skip PHY initialization Date: Fri, 18 Sep 2020 16:17:46 +0300 Message-Id: <20200918131752.16488-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen Some DRD controllers (eg, dwc3 & cdns3) have PHY management at their own driver to cover both device and host mode, so add one priv quirk for such users to skip PHY management from HCD core. Reviewed-by: Jun Li Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 8 ++++++-- drivers/usb/host/xhci.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 07ca000a0084..14ff65a387e8 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -183,6 +183,8 @@ static int xhci_plat_probe(struct platform_device *pdev) struct usb_hcd *hcd; int ret; int irq; + struct xhci_plat_priv *priv = NULL; + if (usb_disabled()) return -ENODEV; @@ -280,8 +282,7 @@ static int xhci_plat_probe(struct platform_device *pdev) priv_match = dev_get_platdata(&pdev->dev); if (priv_match) { - struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); - + priv = hcd_to_xhci_priv(hcd); /* Just copy data for now */ *priv = *priv_match; } @@ -329,6 +330,9 @@ static int xhci_plat_probe(struct platform_device *pdev) hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node); xhci->shared_hcd->tpl_support = hcd->tpl_support; + if (priv && (priv->quirks & XHCI_SKIP_PHY_INIT)) + hcd->skip_phy_initialization = 1; + ret = usb_add_hcd(hcd, irq, IRQF_SHARED); if (ret) goto disable_usb_phy; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index ea1754f185a2..7658abdfca28 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1874,6 +1874,7 @@ struct xhci_hcd { #define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34) #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35) #define XHCI_RENESAS_FW_QUIRK BIT_ULL(36) +#define XHCI_SKIP_PHY_INIT BIT_ULL(37) unsigned int num_active_eps; unsigned int limit_active_eps; From patchwork Fri Sep 18 13:17: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: 11785059 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 671C16CB for ; Fri, 18 Sep 2020 13:14:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53B7723788 for ; Fri, 18 Sep 2020 13:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbgIRNOe (ORCPT ); Fri, 18 Sep 2020 09:14:34 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOe (ORCPT ); Fri, 18 Sep 2020 09:14:34 -0400 IronPort-SDR: SKw8aj6FP3429yBo/BvJN6M/GJw9QmlzEHHYYf9Au9fbZnbDmNA5FhnyFw5PF+vjQoNdixAd3R urRDOZ3Vin9Q== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849959" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849959" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:34 -0700 IronPort-SDR: lyjibG8zQ9Fuh+KatKzqA2RA/WZDUjftB662lTly4vdB1UPLtAK+DNByqAY0lBvGzIXEUMeU5j eAIwMq7TWCrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871184" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:32 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 05/10] usb: host: xhci-plat: add wakeup entry at sysfs Date: Fri, 18 Sep 2020 16:17:47 +0300 Message-Id: <20200918131752.16488-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen With this change, there will be a wakeup entry at /sys/../power/wakeup, and the user could use this entry to choose whether enable xhci wakeup features (wake up system from suspend) or not. Signed-off-by: Peter Chen Reviewed-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 14ff65a387e8..cfca6fc8947c 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -287,7 +287,7 @@ static int xhci_plat_probe(struct platform_device *pdev) *priv = *priv_match; } - device_wakeup_enable(hcd->self.controller); + device_set_wakeup_capable(&pdev->dev, true); xhci->main_hcd = hcd; xhci->shared_hcd = __usb_create_hcd(driver, sysdev, &pdev->dev, From patchwork Fri Sep 18 13:17: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: 11785061 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 DB89959D for ; Fri, 18 Sep 2020 13:14:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C47B123788 for ; Fri, 18 Sep 2020 13:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbgIRNOg (ORCPT ); Fri, 18 Sep 2020 09:14:36 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOf (ORCPT ); Fri, 18 Sep 2020 09:14:35 -0400 IronPort-SDR: byL6yYH74iIT0C/DgjH1LPCc3xI/lspS7fGacrZ4+s51AvQ7wKJgsKqA8WjKCzHXEeLzejeHmL bhdxHsEYTBYQ== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849965" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849965" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:35 -0700 IronPort-SDR: UzCoSO+VPNeKiKI+1zvF9Z1JF23E7O90+2/ol5GUklorwqJgvJBlLVczAEl3VVTB99cCru0CHh 2TLu0dUwuDMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871196" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:34 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 06/10] usb: host: xhci-plat: improve the comments for xhci_plat_suspend Date: Fri, 18 Sep 2020 16:17:48 +0300 Message-Id: <20200918131752.16488-7-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen To reflect the current code status. Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-plat.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index cfca6fc8947c..aa2d35f98200 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -421,11 +421,7 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev) return ret; /* * xhci_suspend() needs `do_wakeup` to know whether host is allowed - * to do wakeup during suspend. Since xhci_plat_suspend is currently - * only designed for system suspend, device_may_wakeup() is enough - * to dertermine whether host is allowed to do wakeup. Need to - * reconsider this when xhci_plat_suspend enlarges its scope, e.g., - * also applies to runtime suspend. + * to do wakeup during suspend. */ return xhci_suspend(xhci, device_may_wakeup(dev)); } From patchwork Fri Sep 18 13:17: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: 11785063 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 0FDC26CB for ; Fri, 18 Sep 2020 13:14:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E51F923787 for ; Fri, 18 Sep 2020 13:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgIRNOi (ORCPT ); Fri, 18 Sep 2020 09:14:38 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOi (ORCPT ); Fri, 18 Sep 2020 09:14:38 -0400 IronPort-SDR: ig+Q+s7FMlUoM8tFd7nFIPylDOfMsJNodKHulCbvZjU5BHwE0k/XVYLdFiIKUaOZdxcBCLbzCa tCKCJjJsUydA== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849967" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849967" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:37 -0700 IronPort-SDR: GMcRzRAIM2sYi2zRKE03961rS1iG5Zr1EIY0ocwh6oTNzxUPx6AJKomanMjNPavc8Io0Br9qIa AQ2+pBETEe/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871204" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:35 -0700 From: Mathias Nyman To: Cc: , Peter Chen , Mathias Nyman Subject: [PATCH 07/10] usb: xhci: omit duplicate actions when suspending a runtime suspended host. Date: Fri, 18 Sep 2020 16:17:49 +0300 Message-Id: <20200918131752.16488-8-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen If the xhci-plat.c is the platform driver, after the runtime pm is enabled, the xhci_suspend is called if nothing is connected on the port. When the system goes to suspend, it will call xhci_suspend again if USB wakeup is enabled. Since the runtime suspend wakeup setting is not always the same as system suspend wakeup setting, eg, at runtime suspend we always need wakeup if the controller is in low power mode; but at system suspend, we may not need wakeup. So, we move the judgement after changing wakeup setting. [commit message rewording -Mathias] Reviewed-by: Jun Li Signed-off-by: Peter Chen Signed-off-by: Mathias Nyman --- 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 f4cedcaee14b..4cfb95104c26 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -982,12 +982,15 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup) xhci->shared_hcd->state != HC_STATE_SUSPENDED) return -EINVAL; - xhci_dbc_suspend(xhci); - /* Clear root port wake on bits if wakeup not allowed. */ if (!do_wakeup) xhci_disable_port_wake_on_bits(xhci); + if (!HCD_HW_ACCESSIBLE(hcd)) + return 0; + + xhci_dbc_suspend(xhci); + /* Don't poll the roothubs on bus suspend. */ xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); From patchwork Fri Sep 18 13:17:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11785065 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 02A0D6CB for ; Fri, 18 Sep 2020 13:14:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E6EF923787 for ; Fri, 18 Sep 2020 13:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgIRNOj (ORCPT ); Fri, 18 Sep 2020 09:14:39 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOi (ORCPT ); Fri, 18 Sep 2020 09:14:38 -0400 IronPort-SDR: ottVCoIS71WMvDqIqdO0Lhpfd7vKpaUkSG6RhPXailHV9a3kmBi+eM88EsuEVMmgI08LNzXtO0 MbsfKr/YSFFQ== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849970" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849970" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:38 -0700 IronPort-SDR: 86Cxok5xpr8haSRG+59vvlZFjtKgcP1nLkqAgZUUxIQyqH5q0dbcM8j7bI+AkXVA8V4w3hdSYP TfhVv4Thmakg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871208" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:37 -0700 From: Mathias Nyman To: Cc: , Mathias Nyman Subject: [PATCH 08/10] xhci: Tune interrupt blocking for isochronous transfers Date: Fri, 18 Sep 2020 16:17:50 +0300 Message-Id: <20200918131752.16488-9-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org controllers with XHCI_AVOID_BEI quirk cause too frequent interrupts and affect power management. To avoid interrupting on every isochronous interval the BEI (Block Event Interrupt) flag is set for all except the last Isoch TRB in a URB. This lead to event ring filling up in case several isoc URB were queued and cancelled rapidly, which some controllers didn't handle well, and thus the XHCI_AVOID_BEI quirk was introduced. see commit 227a4fd801c8 ("usb: xhci: apply XHCI_AVOID_BEI quirk to all Intel xHCI controllers") With the XHCI_AVOID_BEI quirk each Isoch TRB will trigger an interrupt. This can cause up to 8000 interrupts per second for isochronous transfers with HD USB3 cameras, affecting power saving. The event ring fits 256 events, instead of interrupting on every isochronous TRB if XHCI_AVOID_BEI is set we make sure at least every 8th Isochronous TRB asserts an interrupt, clearing the event ring. Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-ring.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a741a38a4c69..167dae117f73 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3736,6 +3736,24 @@ static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci, return start_frame; } +/* Check if we should generate event interrupt for a TD in an isoc URB */ +static bool trb_block_event_intr(struct xhci_hcd *xhci, int num_tds, int i) +{ + if (xhci->hci_version < 0x100) + return false; + /* always generate an event interrupt for the last TD */ + if (i == num_tds - 1) + return false; + /* + * If AVOID_BEI is set the host handles full event rings poorly, + * generate an event at least every 8th TD to clear the event ring + */ + if (i && xhci->quirks & XHCI_AVOID_BEI) + return !!(i % 8); + + return true; +} + /* This is for isoc transfer */ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, int slot_id, unsigned int ep_index) @@ -3843,10 +3861,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, more_trbs_coming = false; td->last_trb = ep_ring->enqueue; field |= TRB_IOC; - /* set BEI, except for the last TD */ - if (xhci->hci_version >= 0x100 && - !(xhci->quirks & XHCI_AVOID_BEI) && - i < num_tds - 1) + if (trb_block_event_intr(xhci, num_tds, i)) field |= TRB_BEI; } /* Calculate TRB length */ From patchwork Fri Sep 18 13:17:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11785067 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 6803659D for ; Fri, 18 Sep 2020 13:14:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E65823719 for ; Fri, 18 Sep 2020 13:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgIRNOk (ORCPT ); Fri, 18 Sep 2020 09:14:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIRNOk (ORCPT ); Fri, 18 Sep 2020 09:14:40 -0400 IronPort-SDR: TSwUB3PVQUtS4IDd5CEgxBP+HPCElrWgvQ7hdeJ+957n4UbzxDRa1PGomEZ7YIC6pkAwvW2b3d pRuNpCHLXw+A== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849976" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849976" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:40 -0700 IronPort-SDR: TKFYOvKGsPPJLJGAFSLHJ5T/6lY51BWrV/6YwTXp7uUmO8fJN+L3BImCkJkC7GOz8cm3WxAab5 nb0zSz4dLFVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871209" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:38 -0700 From: Mathias Nyman To: Cc: , Mathias Nyman , stable@vger.kernel.org Subject: [PATCH 09/10] xhci: don't create endpoint debugfs entry before ring buffer is set. Date: Fri, 18 Sep 2020 16:17:51 +0300 Message-Id: <20200918131752.16488-10-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure xHC completes the configure endpoint command and xhci driver sets the ring pointers correctly before we create the user readable debugfs file. In theory there was a small gap where a user could have read the debugfs file and cause a NULL pointer dereference error as ring pointer was not yet set, in practise we want this change to simplify the upcoming streams debugfs support. Fixes: 02b6fdc2a153 ("usb: xhci: Add debugfs interface for xHCI driver") Cc: stable@vger.kernel.org #v4.19+ Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 4cfb95104c26..e88f4f953995 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1918,8 +1918,6 @@ static int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); trace_xhci_add_endpoint(ep_ctx); - xhci_debugfs_create_endpoint(xhci, virt_dev, ep_index); - xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", (unsigned int) ep->desc.bEndpointAddress, udev->slot_id, @@ -2952,6 +2950,7 @@ static int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) xhci_check_bw_drop_ep_streams(xhci, virt_dev, i); virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; virt_dev->eps[i].new_ring = NULL; + xhci_debugfs_create_endpoint(xhci, virt_dev, i); } command_cleanup: kfree(command->completion); From patchwork Fri Sep 18 13:17:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11785069 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 DA3A859D for ; Fri, 18 Sep 2020 13:14:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAC8723788 for ; Fri, 18 Sep 2020 13:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726309AbgIRNOn (ORCPT ); Fri, 18 Sep 2020 09:14:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:46076 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbgIRNOn (ORCPT ); Fri, 18 Sep 2020 09:14:43 -0400 IronPort-SDR: yWdNevWn7opA84Y0fGqbj3IEgV7eHBPe+Qfd2atNfZB1S5nS8sOi5S9rjr8UWCZsOsZrJJhzCz KajlWg8qM/8w== X-IronPort-AV: E=McAfee;i="6000,8403,9747"; a="160849978" X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="160849978" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2020 06:14:41 -0700 IronPort-SDR: DlDxQZZkxnzXOl5GTc289RoEcSIiCsa438vWyKSiWgtwsbSf7DenU+Acu5E1zOYcT4DWpFYyki pf7PG9UZjceA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,274,1596524400"; d="scan'208";a="508871214" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by fmsmga005.fm.intel.com with ESMTP; 18 Sep 2020 06:14:40 -0700 From: Mathias Nyman To: Cc: , Li Jun , Mathias Nyman Subject: [PATCH 10/10] usb: xhci: add debugfs support for ep with stream Date: Fri, 18 Sep 2020 16:17:52 +0300 Message-Id: <20200918131752.16488-11-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200918131752.16488-1-mathias.nyman@linux.intel.com> References: <20200918131752.16488-1-mathias.nyman@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Li Jun To show the trb ring of streams, use the exsiting ring files of bulk ep to show trb ring of one specific stream ID, which stream ID's trb ring will be shown, is controlled by a new debugfs file stream_id, this is to avoid to create a large number of dir for every allocate stream IDs, another debugfs file stream_context_array is created to show all the allocated stream context array entries. Signed-off-by: Li Jun Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-debugfs.c | 109 +++++++++++++++++++++++++++++++- drivers/usb/host/xhci-debugfs.h | 10 +++ drivers/usb/host/xhci.c | 1 + 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c index c88bffd68742..2c0fda57869e 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -451,9 +451,11 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci, if (!epriv) return; + epriv->show_ring = dev->eps[ep_index].ring; + snprintf(epriv->name, sizeof(epriv->name), "ep%02d", ep_index); epriv->root = xhci_debugfs_create_ring_dir(xhci, - &dev->eps[ep_index].ring, + &epriv->show_ring, epriv->name, spriv->root); spriv->eps[ep_index] = epriv; @@ -475,6 +477,111 @@ void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, kfree(epriv); } +static int xhci_stream_id_show(struct seq_file *s, void *unused) +{ + struct xhci_ep_priv *epriv = s->private; + + if (!epriv->stream_info) + return -EPERM; + + seq_printf(s, "Show stream ID %d trb ring, supported [1 - %d]\n", + epriv->stream_id, epriv->stream_info->num_streams - 1); + + return 0; +} + +static int xhci_stream_id_open(struct inode *inode, struct file *file) +{ + return single_open(file, xhci_stream_id_show, inode->i_private); +} + +static ssize_t xhci_stream_id_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct seq_file *s = file->private_data; + struct xhci_ep_priv *epriv = s->private; + int ret; + u16 stream_id; /* MaxPStreams + 1 <= 16 */ + + if (!epriv->stream_info) + return -EPERM; + + /* Decimal number */ + ret = kstrtou16_from_user(ubuf, count, 10, &stream_id); + if (ret) + return ret; + + if (stream_id == 0 || stream_id >= epriv->stream_info->num_streams) + return -EINVAL; + + epriv->stream_id = stream_id; + epriv->show_ring = epriv->stream_info->stream_rings[stream_id]; + + return count; +} + +static const struct file_operations stream_id_fops = { + .open = xhci_stream_id_open, + .write = xhci_stream_id_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int xhci_stream_context_array_show(struct seq_file *s, void *unused) +{ + struct xhci_ep_priv *epriv = s->private; + struct xhci_stream_ctx *stream_ctx; + dma_addr_t dma; + int id; + + if (!epriv->stream_info) + return -EPERM; + + seq_printf(s, "Allocated %d streams and %d stream context array entries\n", + epriv->stream_info->num_streams, + epriv->stream_info->num_stream_ctxs); + + for (id = 0; id < epriv->stream_info->num_stream_ctxs; id++) { + stream_ctx = epriv->stream_info->stream_ctx_array + id; + dma = epriv->stream_info->ctx_array_dma + id * 16; + if (id < epriv->stream_info->num_streams) + seq_printf(s, "%pad stream id %d deq %016llx\n", &dma, + id, le64_to_cpu(stream_ctx->stream_ring)); + else + seq_printf(s, "%pad stream context entry not used deq %016llx\n", + &dma, le64_to_cpu(stream_ctx->stream_ring)); + } + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(xhci_stream_context_array); + +void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci, + struct xhci_virt_device *dev, + int ep_index) +{ + struct xhci_slot_priv *spriv = dev->debugfs_private; + struct xhci_ep_priv *epriv; + + if (!spriv || !spriv->eps[ep_index] || + !dev->eps[ep_index].stream_info) + return; + + epriv = spriv->eps[ep_index]; + epriv->stream_info = dev->eps[ep_index].stream_info; + + /* Show trb ring of stream ID 1 by default */ + epriv->stream_id = 1; + epriv->show_ring = epriv->stream_info->stream_rings[1]; + debugfs_create_file("stream_id", 0644, + epriv->root, epriv, + &stream_id_fops); + debugfs_create_file("stream_context_array", 0444, + epriv->root, epriv, + &xhci_stream_context_array_fops); +} + void xhci_debugfs_create_slot(struct xhci_hcd *xhci, int slot_id) { struct xhci_slot_priv *priv; diff --git a/drivers/usb/host/xhci-debugfs.h b/drivers/usb/host/xhci-debugfs.h index 56db635fcd6e..7c074b4be819 100644 --- a/drivers/usb/host/xhci-debugfs.h +++ b/drivers/usb/host/xhci-debugfs.h @@ -91,6 +91,9 @@ struct xhci_file_map { struct xhci_ep_priv { char name[DEBUGFS_NAMELEN]; struct dentry *root; + struct xhci_stream_info *stream_info; + struct xhci_ring *show_ring; + unsigned int stream_id; }; struct xhci_slot_priv { @@ -113,6 +116,9 @@ void xhci_debugfs_create_endpoint(struct xhci_hcd *xhci, void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, int ep_index); +void xhci_debugfs_create_stream_files(struct xhci_hcd *xhci, + struct xhci_virt_device *virt_dev, + int ep_index); #else static inline void xhci_debugfs_init(struct xhci_hcd *xhci) { } static inline void xhci_debugfs_exit(struct xhci_hcd *xhci) { } @@ -128,6 +134,10 @@ static inline void xhci_debugfs_remove_endpoint(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, int ep_index) { } +static inline void +xhci_debugfs_create_stream_files(struct xhci_hcd *xhci, + struct xhci_virt_device *virt_dev, + int ep_index) { } #endif /* CONFIG_DEBUG_FS */ #endif /* __LINUX_XHCI_DEBUGFS_H */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index e88f4f953995..482fe8c5e3b4 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3533,6 +3533,7 @@ static int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", udev->slot_id, ep_index); vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; + xhci_debugfs_create_stream_files(xhci, vdev, ep_index); } xhci_free_command(xhci, config_cmd); spin_unlock_irqrestore(&xhci->lock, flags);