From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
Niklas Neronin <niklas.neronin@linux.intel.com>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 16/19] xhci: rework 'xhci_try_enable_msi()' MSI and MSI-X setup code
Date: Fri, 1 Dec 2023 17:06:44 +0200 [thread overview]
Message-ID: <20231201150647.1307406-17-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20231201150647.1307406-1-mathias.nyman@linux.intel.com>
From: Niklas Neronin <niklas.neronin@linux.intel.com>
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 <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
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 2307164a1e81..398f81b0500b 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) {
--
2.25.1
next prev parent reply other threads:[~2023-12-01 15:06 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-01 15:06 [PATCH 00/19] xhci features for usb-next Mathias Nyman
2023-12-01 15:06 ` [PATCH 01/19] xhci: dbc: Drop duplicate checks for dma_free_coherent() Mathias Nyman
2023-12-01 15:06 ` [PATCH 02/19] xhci: dbc: Convert to use sysfs_streq() Mathias Nyman
2023-12-01 15:06 ` [PATCH 03/19] xhci: dbc: Use sysfs_emit() to instead of scnprintf() Mathias Nyman
2023-12-01 15:06 ` [PATCH 04/19] xhci: dbc: Use ATTRIBUTE_GROUPS() Mathias Nyman
2023-12-01 15:06 ` [PATCH 05/19] xhci: dbc: Check for errors first in xhci_dbc_stop() Mathias Nyman
2023-12-01 15:06 ` [PATCH 06/19] xhci: dbc: Don't shadow error codes in store() functions Mathias Nyman
2023-12-01 15:06 ` [PATCH 07/19] xhci: dbc: Replace custom return value with proper Linux error code Mathias Nyman
2023-12-01 15:06 ` [PATCH 08/19] xhci: dbc: Use sizeof_field() where it makes sense Mathias Nyman
2023-12-01 17:31 ` David Laight
2023-12-01 19:08 ` Andy Shevchenko
2023-12-02 15:50 ` David Laight
2023-12-04 10:23 ` Mathias Nyman
2023-12-04 10:45 ` David Laight
2023-12-01 15:06 ` [PATCH 09/19] xhci: dbc: Use sizeof(*pointer) instead of sizeof(type) Mathias Nyman
2023-12-01 15:06 ` [PATCH 10/19] xhci: dbc: Add missing headers Mathias Nyman
2023-12-01 15:06 ` [PATCH 11/19] xhci: check if legacy irq is available before using it as fallback Mathias Nyman
2023-12-01 15:06 ` [PATCH 12/19] xhci: add handler for only one interrupt line Mathias Nyman
2023-12-01 15:06 ` [PATCH 13/19] xhci: refactor static MSI-X function Mathias Nyman
2023-12-01 15:06 ` [PATCH 14/19] xhci: refactor static MSI function Mathias Nyman
2023-12-01 15:06 ` [PATCH 15/19] xhci: change 'msix_count' to encompass MSI or MSI-X vectors Mathias Nyman
2023-12-01 15:06 ` Mathias Nyman [this message]
2023-12-01 15:06 ` [PATCH 17/19] xhci: minor coding style cleanup in 'xhci_try_enable_msi()' Mathias Nyman
2023-12-01 15:06 ` [PATCH 18/19] xhci: Reconfigure endpoint 0 max packet size only during endpoint reset Mathias Nyman
2023-12-01 15:06 ` [PATCH 19/19] xhci: fix possible null pointer deref during xhci urb enqueue Mathias Nyman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231201150647.1307406-17-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=niklas.neronin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.