From patchwork Tue Oct 31 12:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 740003 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53130110E for ; Tue, 31 Oct 2023 12:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ILnuI18r" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0876A2 for ; Tue, 31 Oct 2023 05:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754284; x=1730290284; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ndh9sL2FMfUpxyjsp7RVfhRUSNmjBdDr7oEmIySVC2c=; b=ILnuI18rQlxL1hpwggJhELI1am8ud1ZTUZyLgY8aZOPsZj0+fJdYA725 rRsu5/lLUJP7c+UD2FH9dcCno93+qqs5ee86q4YC/ZqeJRFeUDhcjEJd4 Pv8BLovYxfDoSeJlZosma/Csgd1r8ZhhIVq5yXSoRQMKlUnW72oiNKmw7 e6+/McFKYoLjLdEjHxBt9qar4EkV9vnMXinaHbxP75FLMJ94a8RVnrM7K nAjMMfsamefA6DGyUqCbKIQWuGIB3PI4cVHU3/VMuOdgk3yHmrdQF+El3 Zm5J/u2neweB86MUrNTGb+0LINhEKsq2AriABW+v6U4LdR6Ot7Cu4Cj1I A==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="1163595" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="1163595" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:11:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="754120436" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="754120436" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 31 Oct 2023 05:11:12 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id C76754A0; Tue, 31 Oct 2023 14:11:10 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 1/7] xhci: check if legacy irq is available before using it as fallback Date: Tue, 31 Oct 2023 14:10:11 +0200 Message-ID: <20231031121017.41487-2-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the error check "No MSI-X/MSI found and no IRQ in BIOS" inside 'goto legacy'. It is better to check if the IRQ interrupt is available, before trying to add a handler. Additionally the aforementioned error message is much more clear. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index b9ae5c2a2527..afbee93d1cf8 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -228,12 +228,12 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) return 0; } +legacy_irq: if (!pdev->irq) { xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); return -EINVAL; } - legacy_irq: if (!strlen(hcd->irq_descr)) snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", hcd->driver->description, hcd->self.busnum); From patchwork Tue Oct 31 12:10:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 741232 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0646A110E for ; Tue, 31 Oct 2023 12:11:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="G39hKvCq" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFC7F98 for ; Tue, 31 Oct 2023 05:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754294; x=1730290294; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uMefFzni53TdKdaKjoHykOffFo4wQcDKogaptJNXwPo=; b=G39hKvCqKZr5Vz7Z9xCi2mBaCTw1xfw6yv2asdW1W2lYFYA5u0M48lvG PKM5mNNGQtUAVDq0voP5DtmONkvasJn65T7esgdyuO2vQF4hAcA2RVEAZ kU3e0G7hnsEsbJctBHUANJtLlnk/ST/UEZF0Zwwp/DsLLljWIgGn9nyYw n3FTkTM1WD4iW/+FMQNDGH6/U9m8x4mBtlhZ9RrzdxopEOP9lPxnhyCMb wRCbRf1RVRN7jc1eGfa93NjzyYR0C6t2idv4DV596aSY6571e1de1nDMy wSHPwupgahEjkrdppKoLY5z0JcN/UXhHTprhEq1LtnLRxWkR9Gze/U3at Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="1163626" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="1163626" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:11:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="754120551" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="754120551" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 31 Oct 2023 05:11:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 594164A0; Tue, 31 Oct 2023 14:11:31 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 2/7] xhci: add handler for only one interrupt line Date: Tue, 31 Oct 2023 14:10:12 +0200 Message-ID: <20231031121017.41487-3-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Current xHCI driver only supports one "interrupter", meaning we will only use one MSI/MSI-X interrupt line. Thus, add handler only to the first interrupt line. Co-developed-by: Mathias Nyman Signed-off-by: Mathias Nyman Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index afbee93d1cf8..d37463a80a5d 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -95,10 +95,9 @@ static void xhci_msix_sync_irqs(struct xhci_hcd *xhci) if (hcd->msix_enabled) { struct pci_dev *pdev = to_pci_dev(hcd->self.controller); - int i; - for (i = 0; i < xhci->msix_count; i++) - synchronize_irq(pci_irq_vector(pdev, i)); + /* for now, the driver only supports one primary interrupter */ + synchronize_irq(pci_irq_vector(pdev, 0)); } } @@ -112,15 +111,7 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci) if (hcd->irq > 0) return; - if (hcd->msix_enabled) { - int i; - - for (i = 0; i < xhci->msix_count; i++) - free_irq(pci_irq_vector(pdev, i), xhci_to_hcd(xhci)); - } else { - free_irq(pci_irq_vector(pdev, 0), xhci_to_hcd(xhci)); - } - + free_irq(pci_irq_vector(pdev, 0), xhci_to_hcd(xhci)); pci_free_irq_vectors(pdev); hcd->msix_enabled = 0; } @@ -159,9 +150,9 @@ static int xhci_setup_msi(struct xhci_hcd *xhci) */ static int xhci_setup_msix(struct xhci_hcd *xhci) { - int i, ret; struct usb_hcd *hcd = xhci_to_hcd(xhci); struct pci_dev *pdev = to_pci_dev(hcd->self.controller); + int ret; /* * calculate number of msi-x vectors supported. @@ -181,22 +172,16 @@ static int xhci_setup_msix(struct xhci_hcd *xhci) return ret; } - for (i = 0; i < xhci->msix_count; i++) { - ret = request_irq(pci_irq_vector(pdev, i), xhci_msi_irq, 0, - "xhci_hcd", xhci_to_hcd(xhci)); - if (ret) - goto disable_msix; + ret = request_irq(pci_irq_vector(pdev, 0), xhci_msi_irq, 0, "xhci_hcd", + xhci_to_hcd(xhci)); + if (ret) { + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); + pci_free_irq_vectors(pdev); + return ret; } hcd->msix_enabled = 1; return ret; - -disable_msix: - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); - while (--i >= 0) - free_irq(pci_irq_vector(pdev, i), xhci_to_hcd(xhci)); - pci_free_irq_vectors(pdev); - return ret; } static int xhci_try_enable_msi(struct usb_hcd *hcd) From patchwork Tue Oct 31 12:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 740000 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF64A1DA41 for ; Tue, 31 Oct 2023 12:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VRTqgAsP" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A3D197 for ; Tue, 31 Oct 2023 05:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754673; x=1730290673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eP5nuDPuXi7utfCvqljL1DyfvnpqqLeSl14ReboOCy4=; b=VRTqgAsPcvdjRRKxSNvgAe6quTW/x/I5NIWfBGPEymasZczczvo4p3Ga B+Lw0WdSOIR8aJoPzP/dzHnf7ewRBXppMDPhw2uhZlTSQSRW3fg+SFG/0 YJDSIEYPF+Vk0+MKp+f+5lcG2PyLhaglay7dxXYhJseyLdvO8XnVUbLhw wqAU1qgTLxyNlj4WD9oDWNiB7IhNNFI27WdGpWhYziyMFGRlhal/76Etc cwVJVW/Eq7UmEJl7pc+u6aQ+ydJeq255eNGA1bf1ar1WBn0kfR/k4xEX9 RvnaQovRPHKP4FkwqgC7+6YTjV4it5lX53hRAtXX0t7VLS8nEnccV5U9y A==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="368480392" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="368480392" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:17:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="934088585" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="934088585" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 31 Oct 2023 05:17:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id A18274A0; Tue, 31 Oct 2023 14:11:58 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 3/7] xhci: refactor static MSI-X function Date: Tue, 31 Oct 2023 14:10:13 +0200 Message-ID: <20231031121017.41487-4-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current way the xhci driver sets up MSI/MSI-X interrupts is overly complex and messy. The whole MSI/MSI-X setup can be done in one simple function. Start refactoring this by incorporating 'xhci_setup_msix()' into 'xhci_try_enable_msi()'. 'xhci_setup_msix()' is a static function which is only called by 'xhci_try_enable_msi()'. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 68 +++++++++++++++---------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index d37463a80a5d..9e8ee737c2f1 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -145,31 +145,40 @@ static int xhci_setup_msi(struct xhci_hcd *xhci) return ret; } -/* - * Set up MSI-X - */ -static int xhci_setup_msix(struct xhci_hcd *xhci) +static int xhci_try_enable_msi(struct usb_hcd *hcd) { - struct usb_hcd *hcd = xhci_to_hcd(xhci); - struct pci_dev *pdev = to_pci_dev(hcd->self.controller); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + struct pci_dev *pdev; int ret; + pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); /* - * calculate number of msi-x vectors supported. + * Some Fresco Logic host controllers advertise MSI, but fail to + * generate interrupts. Don't even try to enable MSI. + */ + if (xhci->quirks & XHCI_BROKEN_MSI) + goto legacy_irq; + + /* unregister the legacy interrupt */ + if (hcd->irq) + free_irq(hcd->irq, hcd); + hcd->irq = 0; + + /* + * calculate number of MSI-X vectors supported. * - HCS_MAX_INTRS: the max number of interrupts the host can handle, * with max number of interrupters based on the xhci HCSPARAMS1. - * - num_online_cpus: maximum msi-x vectors per CPUs core. + * - num_online_cpus: maximum MSI-X vectors per CPUs core. * Add additional 1 vector to ensure always available interrupt. */ xhci->msix_count = min(num_online_cpus() + 1, - HCS_MAX_INTRS(xhci->hcs_params1)); + HCS_MAX_INTRS(xhci->hcs_params1)); ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, - PCI_IRQ_MSIX); + PCI_IRQ_MSIX); if (ret < 0) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "Failed to enable MSI-X"); - return ret; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Failed to enable MSI-X"); + goto setup_msi; } ret = request_irq(pci_irq_vector(pdev, 0), xhci_msi_irq, 0, "xhci_hcd", @@ -177,37 +186,16 @@ static int xhci_setup_msix(struct xhci_hcd *xhci) if (ret) { xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); pci_free_irq_vectors(pdev); - return ret; + goto setup_msi; } + hcd->msi_enabled = 1; hcd->msix_enabled = 1; - return ret; -} - -static int xhci_try_enable_msi(struct usb_hcd *hcd) -{ - struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct pci_dev *pdev; - int ret; - - pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); - /* - * Some Fresco Logic host controllers advertise MSI, but fail to - * generate interrupts. Don't even try to enable MSI. - */ - if (xhci->quirks & XHCI_BROKEN_MSI) - goto legacy_irq; - - /* unregister the legacy interrupt */ - if (hcd->irq) - free_irq(hcd->irq, hcd); - hcd->irq = 0; - - ret = xhci_setup_msix(xhci); - if (ret) - /* fall back to msi*/ - ret = xhci_setup_msi(xhci); + return 0; +setup_msi: + /* fall back to MSI */ + ret = xhci_setup_msi(xhci); if (!ret) { hcd->msi_enabled = 1; return 0; From patchwork Tue Oct 31 12:10:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 740002 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 622B61DA4B for ; Tue, 31 Oct 2023 12:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="T384LMPT" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE389A2 for ; Tue, 31 Oct 2023 05:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754330; x=1730290330; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L0Gl+BPtK71pToNy+mDYRg/VUg72GFnzuZVfY4iT3TY=; b=T384LMPTJUfwYCRxgnO05vMG2soF2CEkMcsi5STtAC1CZPtuFt3Ylu81 xVyAu7OaJAyEwT9ySCBQFigiwLzGDZQj7414fkXhPpvVWVxaZArBDUFvs r9AxZMbd3TggLG3lgLbPkwaFjsR4R5WXLZMC1T3yHAuqirQiZMHcJ0zvN iRecJAPDj8InllvYZEQEQ0qkPm+/F7QAxWTY+qvpI8AEBnBcePxas5yAR F+B7ZCl8Ph0/7rqCl3athzP+kS/9MtGbdXTD0JHwWwKZykA7MLUT0W8ub XuWCIBqLFMqG08/OhZK33TnGRtCr5/5G9Iprkw7e2g0ziqIfghxxs+Wd8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385463739" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385463739" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:12:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="764224539" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="764224539" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 31 Oct 2023 05:12:02 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 96EB651D; Tue, 31 Oct 2023 14:12:02 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 4/7] xhci: refactor static MSI function Date: Tue, 31 Oct 2023 14:10:14 +0200 Message-ID: <20231031121017.41487-5-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current way the xhci driver sets up MSI interrupts is overly complex and messy. The whole MSI setup can be done in one simple function. Continue refactoring MSI/MSI-X setup by incorporating 'xhci_setup_msi()' into 'xhci_try_enable_msi()'. Now all interrupt enabling is contained in one function, which should make it easier to rework. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 49 ++++++++++++------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 9e8ee737c2f1..79c4eccd7ae3 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -116,35 +116,6 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci) hcd->msix_enabled = 0; } -/* - * Set up MSI - */ -static int xhci_setup_msi(struct xhci_hcd *xhci) -{ - int ret; - /* - * TODO:Check with MSI Soc for sysdev - */ - struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); - - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); - if (ret < 0) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "failed to allocate MSI entry"); - return ret; - } - - ret = request_irq(pdev->irq, xhci_msi_irq, - 0, "xhci_hcd", xhci_to_hcd(xhci)); - if (ret) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "disable MSI interrupt"); - pci_free_irq_vectors(pdev); - } - - return ret; -} - static int xhci_try_enable_msi(struct usb_hcd *hcd) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -194,13 +165,23 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) return 0; setup_msi: - /* fall back to MSI */ - ret = xhci_setup_msi(xhci); - if (!ret) { - hcd->msi_enabled = 1; - return 0; + /* TODO: Check with MSI Soc for sysdev */ + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); + if (ret < 0) { + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "failed to allocate MSI entry"); + goto legacy_irq; } + ret = request_irq(pdev->irq, xhci_msi_irq, 0, "xhci_hcd", xhci_to_hcd(xhci)); + if (ret) { + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI interrupt"); + pci_free_irq_vectors(pdev); + goto legacy_irq; + } + + hcd->msi_enabled = 1; + return 0; + legacy_irq: if (!pdev->irq) { xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); From patchwork Tue Oct 31 12:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 741230 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC94E1D53B for ; Tue, 31 Oct 2023 12:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P7uzoast" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 923C2BB for ; Tue, 31 Oct 2023 05:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754672; x=1730290672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XSKu3NhlILhnD0kGRCHtejpj2/bd9tHd95I6BAi7F7E=; b=P7uzoastHFu9yFSVUH1Lh2xhGIIXe0d4ixe9gp66NVgTpcIqvZQOFMVE iVApyzEBUvaRheKSIpKmqKx5AWfQheYE1TqwftKFwFpcxueK82GcKbmSv VgIISJ7S+V/7nz/8n0p+geoPntc6TD4dKUNcXPSgvWxOoIqMr1AteMm+t ONhII/TZ6KSVZ7EaJpjGSbcGWb4AK9J+3P1fYouDTQG2NzbbrbnMhuVqt vL4WqalC0WKTIz3FPdryESeqncoDi4YlNFFz3SVQ/ryknXV+Shw9jb5hO befspYXYceQ9gyC+6L8cBCzwXaJElgJZar9zyCzlPt2wzvuQDyqGkclY7 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="368480391" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="368480391" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:17:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="934088584" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="934088584" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 31 Oct 2023 05:17:51 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id ACB1052A; Tue, 31 Oct 2023 14:12:03 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 5/7] xhci: change 'msix_count' to encompass MSI or MSI-X vectors Date: Tue, 31 Oct 2023 14:10:15 +0200 Message-ID: <20231031121017.41487-6-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of variable 'msix_count' containing the number of MSI-X vectors, now it can contains MSI or MSI-X vector amount. Because both interrupt methods allow several vectors. Thus, 'msix_count' is renamed to 'nvecs'. Additionally, instead of storing the maximum possible vector amount, now it stores the amount of successfully allocated vectors, or negative integer on allocation failure. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 14 +++++++------- drivers/usb/host/xhci.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 79c4eccd7ae3..3ee3943db867 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -142,12 +142,12 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) * - num_online_cpus: maximum MSI-X vectors per CPUs core. * Add additional 1 vector to ensure always available interrupt. */ - xhci->msix_count = min(num_online_cpus() + 1, - HCS_MAX_INTRS(xhci->hcs_params1)); + xhci->nvecs = min(num_online_cpus() + 1, + HCS_MAX_INTRS(xhci->hcs_params1)); - ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, - PCI_IRQ_MSIX); - if (ret < 0) { + xhci->nvecs = pci_alloc_irq_vectors(pdev, xhci->nvecs, xhci->nvecs, + PCI_IRQ_MSIX); + if (xhci->nvecs < 0) { xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Failed to enable MSI-X"); goto setup_msi; } @@ -166,8 +166,8 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) setup_msi: /* TODO: Check with MSI Soc for sysdev */ - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); - if (ret < 0) { + xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); + if (xhci->nvecs < 0) { xhci_dbg_trace(xhci, trace_xhci_dbg_init, "failed to allocate MSI entry"); goto legacy_irq; } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 5df370482521..999914711ef5 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1790,8 +1790,8 @@ struct xhci_hcd { int page_size; /* Valid values are 12 to 20, inclusive */ int page_shift; - /* msi-x vectors */ - int msix_count; + /* MSI-X/MSI vectors */ + int nvecs; /* optional clocks */ struct clk *clk; struct clk *reg_clk; From patchwork Tue Oct 31 12:10:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 741231 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCC6D19BB1 for ; Tue, 31 Oct 2023 12:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZKPj8vyL" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A1E9F for ; Tue, 31 Oct 2023 05:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754347; x=1730290347; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B963KNSUtjvbdlLPxFBxkkuWoSEYJCbSM864H9HdfMc=; b=ZKPj8vyLPlyd7dc7FEpf9lBaWN+mJP4LrFE+u07nY5edXyGFdsELDE1q 2nzfD4Ns26OWiCGcWQ6A2y/5QAB+3/XJhWGhhze/jYhfkzFIoMgiQOGI3 hwlY8zWxriW2hQ20J3ycaO6A0c9m22pNCBe7blY9ZRM9FO3pJK6wEE1tm 7f1IeWQI9nHL/8Kdqy97jnm3EhzfIAJpSD4DcSXykVEs4dUrqf0tSttPm q6cH8mEAQAxRSUBoOaP5BlvS+Pk7J6P1eN+XNrQ1aRoguzIG/6czBJrd0 BdF9asr2OSFIaIfufZMzXvBmYgiXqMpOEM1c+smUg3TgryUodideRFtFe w==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="385463767" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="385463767" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:12:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="764224610" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="764224610" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga007.fm.intel.com with ESMTP; 31 Oct 2023 05:12:25 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id 8A06B51D; Tue, 31 Oct 2023 14:12:25 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 6/7] xhci: rework 'xhci_try_enable_msi()' MSI and MSI-X setup code Date: Tue, 31 Oct 2023 14:10:16 +0200 Message-ID: <20231031121017.41487-7-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify 'xhci_try_enable_msi()' and reduce unnecessary function calls. xHCI driver first tries to allocate 'num_online_cpu()' number of MSI-X vectors, if that fails it falls back to a single MSI vector. There is no good reason for this, we currently only support a primary interrupter. However, we are still interested in knowing if there are more vectors available, which will be utilized once we get secondary interrupter support. Call 'pci_alloc_irq_vectors()' once (with MSI-X and MSI flag), instead of separately for MSI-X and MSI. And accept any number of MSI-X or MSI vectors between 1 and 'num_online_cpu()'. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 44 +++++++++++++------------------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 3ee3943db867..742dd7f026e9 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -116,13 +116,13 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci) hcd->msix_enabled = 0; } +/* Try enabling MSI-X with MSI and legacy IRQ as fallback */ static int xhci_try_enable_msi(struct usb_hcd *hcd) { + struct pci_dev *pdev = to_pci_dev(hcd->self.controller); struct xhci_hcd *xhci = hcd_to_xhci(hcd); - struct pci_dev *pdev; int ret; - pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); /* * Some Fresco Logic host controllers advertise MSI, but fail to * generate interrupts. Don't even try to enable MSI. @@ -145,42 +145,28 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) xhci->nvecs = min(num_online_cpus() + 1, HCS_MAX_INTRS(xhci->hcs_params1)); - xhci->nvecs = pci_alloc_irq_vectors(pdev, xhci->nvecs, xhci->nvecs, - PCI_IRQ_MSIX); + /* TODO: Check with MSI Soc for sysdev */ + xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, xhci->nvecs, + PCI_IRQ_MSIX | PCI_IRQ_MSI); if (xhci->nvecs < 0) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Failed to enable MSI-X"); - goto setup_msi; + xhci_dbg_trace(xhci, trace_xhci_dbg_init, + "failed to allocate IRQ vectors"); + goto legacy_irq; } ret = request_irq(pci_irq_vector(pdev, 0), xhci_msi_irq, 0, "xhci_hcd", xhci_to_hcd(xhci)); - if (ret) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); - pci_free_irq_vectors(pdev); - goto setup_msi; - } + if (ret) + goto free_irq_vectors; hcd->msi_enabled = 1; - hcd->msix_enabled = 1; + hcd->msix_enabled = pdev->msix_enabled; return 0; -setup_msi: - /* TODO: Check with MSI Soc for sysdev */ - xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); - if (xhci->nvecs < 0) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "failed to allocate MSI entry"); - goto legacy_irq; - } - - ret = request_irq(pdev->irq, xhci_msi_irq, 0, "xhci_hcd", xhci_to_hcd(xhci)); - if (ret) { - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI interrupt"); - pci_free_irq_vectors(pdev); - goto legacy_irq; - } - - hcd->msi_enabled = 1; - return 0; +free_irq_vectors: + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable %s interrupt", + pdev->msix_enabled ? "MSI-X" : "MSI"); + pci_free_irq_vectors(pdev); legacy_irq: if (!pdev->irq) { From patchwork Tue Oct 31 12:10:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neronin, Niklas" X-Patchwork-Id: 740001 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10CB119BB1 for ; Tue, 31 Oct 2023 12:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kGWnSfcf" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E49E6A2 for ; Tue, 31 Oct 2023 05:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698754354; x=1730290354; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BfzqNsJ/81n9XCew6EOx1KwzUAG5X91XrMLw+53+eM0=; b=kGWnSfcflFnDpEROqBW8xo2Rqq60VfwQEhiK6OhJKHznpQVf/MTEd9pZ l67kfJ9+kcJMHTRvxFNZ+gAduMD4yj5I6tAmb4bEdVdQGnlr10cdq3Uud W83CFGe7EHJ2wWKvk4NN5bBy3jOd671wTuAEmQgXj1fXXxvbVgsF9Sl+X 02+yO2Ssx2MmblOvM5vZrmGLQsHkse4WTnuEaJpWnEMwDt1PVlC05jVaB NLy7Pjnq2Lns+HIMhywUgmNhdLVRilE95VGVKF2RDw80rJt+3DBAuHKxd tAeJmwd5JU2eLw5eNNYMs4p4L9CvJ9AP1jVEvfLnXjkyLTZMH9XQrlTFB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="419383539" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="419383539" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 05:12:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="851226145" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208";a="851226145" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 31 Oct 2023 05:12:33 -0700 Received: by black.fi.intel.com (Postfix, from userid 1058) id B32E552F; Tue, 31 Oct 2023 14:12:32 +0200 (EET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org Subject: [PATCH 7/7] xhci: minor coding style cleanup in 'xhci_try_enable_msi()' Date: Tue, 31 Oct 2023 14:10:17 +0200 Message-ID: <20231031121017.41487-8-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031121017.41487-2-niklas.neronin@linux.intel.com> References: <20231031121017.41487-2-niklas.neronin@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove extra spaces/indentation and add spaces where required. This commit does not change any functionality. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-pci.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 742dd7f026e9..7fc6797c17ac 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -178,12 +178,10 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd) snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", hcd->driver->description, hcd->self.busnum); - /* fall back to legacy interrupt*/ - ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, - hcd->irq_descr, hcd); + /* fall back to legacy interrupt */ + ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, hcd->irq_descr, hcd); if (ret) { - xhci_err(xhci, "request interrupt %d failed\n", - pdev->irq); + xhci_err(xhci, "request interrupt %d failed\n", pdev->irq); return ret; } hcd->irq = pdev->irq;