xhci: refactor static MSI-X function
authorNiklas Neronin <niklas.neronin@linux.intel.com>
Fri, 1 Dec 2023 15:06:41 +0000 (17:06 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 4 Dec 2023 06:50:40 +0000 (07:50 +0100)
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 <niklas.neronin@linux.intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20231201150647.1307406-14-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-pci.c

index 59bbae69f97c87ad32ce419054da5e6c79872f0c..370943c048815878b8124300372d2b1c076ec286 100644 (file)
@@ -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;