Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xhci: Move functions to setup msi to xhci-pci

Move functions to setup msi from xhci.c to xhci-pci.c to decouple
PCI specific code from generic xhci code.

No functional changes, functions are an exact copy

[commit message rewording -Mathias]

Signed-off-by: Josue David Hernandez Gutierrez <josue.d.hernandez.gutierrez@intel.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20230317154715.535523-11-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Josue David Hernandez Gutierrez and committed by
Greg Kroah-Hartman
fabbd95c 944e7deb

+131 -135
+129
drivers/usb/host/xhci-pci.c
··· 88 88 .update_hub_device = xhci_pci_update_hub_device, 89 89 }; 90 90 91 + /* 92 + * Set up MSI 93 + */ 94 + static int xhci_setup_msi(struct xhci_hcd *xhci) 95 + { 96 + int ret; 97 + /* 98 + * TODO:Check with MSI Soc for sysdev 99 + */ 100 + struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 101 + 102 + ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); 103 + if (ret < 0) { 104 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, 105 + "failed to allocate MSI entry"); 106 + return ret; 107 + } 108 + 109 + ret = request_irq(pdev->irq, xhci_msi_irq, 110 + 0, "xhci_hcd", xhci_to_hcd(xhci)); 111 + if (ret) { 112 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, 113 + "disable MSI interrupt"); 114 + pci_free_irq_vectors(pdev); 115 + } 116 + 117 + return ret; 118 + } 119 + 120 + /* 121 + * Set up MSI-X 122 + */ 123 + static int xhci_setup_msix(struct xhci_hcd *xhci) 124 + { 125 + int i, ret; 126 + struct usb_hcd *hcd = xhci_to_hcd(xhci); 127 + struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 128 + 129 + /* 130 + * calculate number of msi-x vectors supported. 131 + * - HCS_MAX_INTRS: the max number of interrupts the host can handle, 132 + * with max number of interrupters based on the xhci HCSPARAMS1. 133 + * - num_online_cpus: maximum msi-x vectors per CPUs core. 134 + * Add additional 1 vector to ensure always available interrupt. 135 + */ 136 + xhci->msix_count = min(num_online_cpus() + 1, 137 + HCS_MAX_INTRS(xhci->hcs_params1)); 138 + 139 + ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, 140 + PCI_IRQ_MSIX); 141 + if (ret < 0) { 142 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, 143 + "Failed to enable MSI-X"); 144 + return ret; 145 + } 146 + 147 + for (i = 0; i < xhci->msix_count; i++) { 148 + ret = request_irq(pci_irq_vector(pdev, i), xhci_msi_irq, 0, 149 + "xhci_hcd", xhci_to_hcd(xhci)); 150 + if (ret) 151 + goto disable_msix; 152 + } 153 + 154 + hcd->msix_enabled = 1; 155 + return ret; 156 + 157 + disable_msix: 158 + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); 159 + while (--i >= 0) 160 + free_irq(pci_irq_vector(pdev, i), xhci_to_hcd(xhci)); 161 + pci_free_irq_vectors(pdev); 162 + return ret; 163 + } 164 + 165 + static int xhci_try_enable_msi(struct usb_hcd *hcd) 166 + { 167 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 168 + struct pci_dev *pdev; 169 + int ret; 170 + 171 + /* The xhci platform device has set up IRQs through usb_add_hcd. */ 172 + if (xhci->quirks & XHCI_PLAT) 173 + return 0; 174 + 175 + pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 176 + /* 177 + * Some Fresco Logic host controllers advertise MSI, but fail to 178 + * generate interrupts. Don't even try to enable MSI. 179 + */ 180 + if (xhci->quirks & XHCI_BROKEN_MSI) 181 + goto legacy_irq; 182 + 183 + /* unregister the legacy interrupt */ 184 + if (hcd->irq) 185 + free_irq(hcd->irq, hcd); 186 + hcd->irq = 0; 187 + 188 + ret = xhci_setup_msix(xhci); 189 + if (ret) 190 + /* fall back to msi*/ 191 + ret = xhci_setup_msi(xhci); 192 + 193 + if (!ret) { 194 + hcd->msi_enabled = 1; 195 + return 0; 196 + } 197 + 198 + if (!pdev->irq) { 199 + xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); 200 + return -EINVAL; 201 + } 202 + 203 + legacy_irq: 204 + if (!strlen(hcd->irq_descr)) 205 + snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", 206 + hcd->driver->description, hcd->self.busnum); 207 + 208 + /* fall back to legacy interrupt*/ 209 + ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 210 + hcd->irq_descr, hcd); 211 + if (ret) { 212 + xhci_err(xhci, "request interrupt %d failed\n", 213 + pdev->irq); 214 + return ret; 215 + } 216 + hcd->irq = pdev->irq; 217 + return 0; 218 + } 219 + 91 220 static int xhci_pci_run(struct usb_hcd *hcd) 92 221 { 93 222 int ret;
+1
drivers/usb/host/xhci-ring.c
··· 3106 3106 { 3107 3107 return xhci_irq(hcd); 3108 3108 } 3109 + EXPORT_SYMBOL_GPL(xhci_msi_irq); 3109 3110 3110 3111 /**** Endpoint Ring Operations ****/ 3111 3112
+1
drivers/usb/host/xhci-trace.c
··· 12 12 #include "xhci-trace.h" 13 13 14 14 EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_quirks); 15 + EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_init);
-134
drivers/usb/host/xhci.c
··· 319 319 } 320 320 321 321 #ifdef CONFIG_USB_PCI 322 - /* 323 - * Set up MSI 324 - */ 325 - static int xhci_setup_msi(struct xhci_hcd *xhci) 326 - { 327 - int ret; 328 - /* 329 - * TODO:Check with MSI Soc for sysdev 330 - */ 331 - struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 332 - 333 - ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_MSI); 334 - if (ret < 0) { 335 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 336 - "failed to allocate MSI entry"); 337 - return ret; 338 - } 339 - 340 - ret = request_irq(pdev->irq, xhci_msi_irq, 341 - 0, "xhci_hcd", xhci_to_hcd(xhci)); 342 - if (ret) { 343 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 344 - "disable MSI interrupt"); 345 - pci_free_irq_vectors(pdev); 346 - } 347 - 348 - return ret; 349 - } 350 - 351 - /* 352 - * Set up MSI-X 353 - */ 354 - static int xhci_setup_msix(struct xhci_hcd *xhci) 355 - { 356 - int i, ret; 357 - struct usb_hcd *hcd = xhci_to_hcd(xhci); 358 - struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 359 - 360 - /* 361 - * calculate number of msi-x vectors supported. 362 - * - HCS_MAX_INTRS: the max number of interrupts the host can handle, 363 - * with max number of interrupters based on the xhci HCSPARAMS1. 364 - * - num_online_cpus: maximum msi-x vectors per CPUs core. 365 - * Add additional 1 vector to ensure always available interrupt. 366 - */ 367 - xhci->msix_count = min(num_online_cpus() + 1, 368 - HCS_MAX_INTRS(xhci->hcs_params1)); 369 - 370 - ret = pci_alloc_irq_vectors(pdev, xhci->msix_count, xhci->msix_count, 371 - PCI_IRQ_MSIX); 372 - if (ret < 0) { 373 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, 374 - "Failed to enable MSI-X"); 375 - return ret; 376 - } 377 - 378 - for (i = 0; i < xhci->msix_count; i++) { 379 - ret = request_irq(pci_irq_vector(pdev, i), xhci_msi_irq, 0, 380 - "xhci_hcd", xhci_to_hcd(xhci)); 381 - if (ret) 382 - goto disable_msix; 383 - } 384 - 385 - hcd->msix_enabled = 1; 386 - return ret; 387 - 388 - disable_msix: 389 - xhci_dbg_trace(xhci, trace_xhci_dbg_init, "disable MSI-X interrupt"); 390 - while (--i >= 0) 391 - free_irq(pci_irq_vector(pdev, i), xhci_to_hcd(xhci)); 392 - pci_free_irq_vectors(pdev); 393 - return ret; 394 - } 395 322 396 323 /* Free any IRQs and disable MSI-X */ 397 324 static void xhci_cleanup_msix(struct xhci_hcd *xhci) ··· 359 432 } 360 433 } 361 434 362 - int xhci_try_enable_msi(struct usb_hcd *hcd) 363 - { 364 - struct xhci_hcd *xhci = hcd_to_xhci(hcd); 365 - struct pci_dev *pdev; 366 - int ret; 367 - 368 - /* The xhci platform device has set up IRQs through usb_add_hcd. */ 369 - if (xhci->quirks & XHCI_PLAT) 370 - return 0; 371 - 372 - pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 373 - /* 374 - * Some Fresco Logic host controllers advertise MSI, but fail to 375 - * generate interrupts. Don't even try to enable MSI. 376 - */ 377 - if (xhci->quirks & XHCI_BROKEN_MSI) 378 - goto legacy_irq; 379 - 380 - /* unregister the legacy interrupt */ 381 - if (hcd->irq) 382 - free_irq(hcd->irq, hcd); 383 - hcd->irq = 0; 384 - 385 - ret = xhci_setup_msix(xhci); 386 - if (ret) 387 - /* fall back to msi*/ 388 - ret = xhci_setup_msi(xhci); 389 - 390 - if (!ret) { 391 - hcd->msi_enabled = 1; 392 - return 0; 393 - } 394 - 395 - if (!pdev->irq) { 396 - xhci_err(xhci, "No msi-x/msi found and no IRQ in BIOS\n"); 397 - return -EINVAL; 398 - } 399 - 400 - legacy_irq: 401 - if (!strlen(hcd->irq_descr)) 402 - snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", 403 - hcd->driver->description, hcd->self.busnum); 404 - 405 - /* fall back to legacy interrupt*/ 406 - ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 407 - hcd->irq_descr, hcd); 408 - if (ret) { 409 - xhci_err(xhci, "request interrupt %d failed\n", 410 - pdev->irq); 411 - return ret; 412 - } 413 - hcd->irq = pdev->irq; 414 - return 0; 415 - } 416 - EXPORT_SYMBOL_GPL(xhci_try_enable_msi); 417 - 418 435 #else 419 - 420 - static inline int xhci_try_enable_msi(struct usb_hcd *hcd) 421 - { 422 - return 0; 423 - } 424 436 425 437 static inline void xhci_cleanup_msix(struct xhci_hcd *xhci) 426 438 {
-1
drivers/usb/host/xhci.h
··· 2143 2143 2144 2144 irqreturn_t xhci_irq(struct usb_hcd *hcd); 2145 2145 irqreturn_t xhci_msi_irq(int irq, void *hcd); 2146 - int xhci_try_enable_msi(struct usb_hcd *hcd); 2147 2146 int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 2148 2147 int xhci_alloc_tt_info(struct xhci_hcd *xhci, 2149 2148 struct xhci_virt_device *virt_dev,