mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 21:51:40 +00:00
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>
This commit is contained in:
parent
944e7deb42
commit
fabbd95cc4
@ -88,6 +88,135 @@ static const struct xhci_driver_overrides xhci_pci_overrides __initconst = {
|
|||||||
.update_hub_device = xhci_pci_update_hub_device,
|
.update_hub_device = xhci_pci_update_hub_device,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up MSI-X
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* Add additional 1 vector to ensure always available interrupt.
|
||||||
|
*/
|
||||||
|
xhci->msix_count = 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_dbg_trace(xhci, trace_xhci_dbg_init,
|
||||||
|
"Failed to enable MSI-X");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
|
||||||
|
struct pci_dev *pdev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* The xhci platform device has set up IRQs through usb_add_hcd. */
|
||||||
|
if (xhci->quirks & XHCI_PLAT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
hcd->msi_enabled = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
hcd->irq = pdev->irq;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int xhci_pci_run(struct usb_hcd *hcd)
|
static int xhci_pci_run(struct usb_hcd *hcd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -3106,6 +3106,7 @@ irqreturn_t xhci_msi_irq(int irq, void *hcd)
|
|||||||
{
|
{
|
||||||
return xhci_irq(hcd);
|
return xhci_irq(hcd);
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(xhci_msi_irq);
|
||||||
|
|
||||||
/**** Endpoint Ring Operations ****/
|
/**** Endpoint Ring Operations ****/
|
||||||
|
|
||||||
|
@ -12,3 +12,4 @@
|
|||||||
#include "xhci-trace.h"
|
#include "xhci-trace.h"
|
||||||
|
|
||||||
EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_quirks);
|
EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_quirks);
|
||||||
|
EXPORT_TRACEPOINT_SYMBOL_GPL(xhci_dbg_init);
|
||||||
|
@ -319,79 +319,6 @@ static int xhci_disable_interrupter(struct xhci_interrupter *ir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_USB_PCI
|
#ifdef CONFIG_USB_PCI
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up MSI-X
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
* Add additional 1 vector to ensure always available interrupt.
|
|
||||||
*/
|
|
||||||
xhci->msix_count = 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_dbg_trace(xhci, trace_xhci_dbg_init,
|
|
||||||
"Failed to enable MSI-X");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free any IRQs and disable MSI-X */
|
/* Free any IRQs and disable MSI-X */
|
||||||
static void xhci_cleanup_msix(struct xhci_hcd *xhci)
|
static void xhci_cleanup_msix(struct xhci_hcd *xhci)
|
||||||
@ -432,69 +359,8 @@ static void __maybe_unused xhci_msix_sync_irqs(struct xhci_hcd *xhci)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int xhci_try_enable_msi(struct usb_hcd *hcd)
|
|
||||||
{
|
|
||||||
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
|
|
||||||
struct pci_dev *pdev;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* The xhci platform device has set up IRQs through usb_add_hcd. */
|
|
||||||
if (xhci->quirks & XHCI_PLAT)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
hcd->msi_enabled = 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
hcd->irq = pdev->irq;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(xhci_try_enable_msi);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline int xhci_try_enable_msi(struct usb_hcd *hcd)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void xhci_cleanup_msix(struct xhci_hcd *xhci)
|
static inline void xhci_cleanup_msix(struct xhci_hcd *xhci)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -2143,7 +2143,6 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
|
|||||||
|
|
||||||
irqreturn_t xhci_irq(struct usb_hcd *hcd);
|
irqreturn_t xhci_irq(struct usb_hcd *hcd);
|
||||||
irqreturn_t xhci_msi_irq(int irq, void *hcd);
|
irqreturn_t xhci_msi_irq(int irq, void *hcd);
|
||||||
int xhci_try_enable_msi(struct usb_hcd *hcd);
|
|
||||||
int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
|
int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
|
||||||
int xhci_alloc_tt_info(struct xhci_hcd *xhci,
|
int xhci_alloc_tt_info(struct xhci_hcd *xhci,
|
||||||
struct xhci_virt_device *virt_dev,
|
struct xhci_virt_device *virt_dev,
|
||||||
|
Loading…
Reference in New Issue
Block a user