Skip to contentSkip to conversation

usb: correctly enable interrupts for xhci

PATCH Superseded Hannes Reinecke 3 participants 3 messages Mar 1, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: correctly enable interrupts for xhci

xhci might run with MSI/MSI-X only, with no support for legacy interrupts. On these devices the request_irq() call in usb_add_hcd() will fail, causing the entire device to fail.
For xhci this is especially painful as the driver will enable interrupts during xhci_run(), so the initial call to request_irq() is not required anyway.

This patch adds a flag 'msix_supported' to struct usb_hcd, which will cause usb_add_hcd() to skip interrupt setup. This flag is set in xhci-pci, so the registration will skip the first request_irq() and can proceed.

Cc Bjorn Helgaas <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Thomas Renninger <[email protected]>
Cc Yinghai Lu <[email protected]>
Cc Frederik Himpe <[email protected]>
Cc David Haerdeman <[email protected]>
drivers/usb/core/hcd.c +1 -1
index 8e64adf..e583444 100644
@@ -2536,7 +2536,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	/* enable irqs just before we start the controller,
 	 * if the BIOS provides legacy PCI irqs.
 	 */
-	if (usb_hcd_is_primary_hcd(hcd) && irqnum) {
+	if (usb_hcd_is_primary_hcd(hcd) && irqnum && !hcd->msix_supported) {
 		retval = usb_hcd_request_irqs(hcd, irqnum, irqflags);
 		if (retval)
 			goto err_request_irq;
drivers/usb/host/xhci-pci.c +6 -0
index af259e0..a08c0ee 100644
@@ -183,6 +183,12 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	 */
 	*((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci;
 
+	/*
+	 * Interrupts are setup during xhci_run(), so do not try
+	 * to request an interrupt during hcd init.
+	 */
+	hcd->msix_supported = 1;
+
 	retval = usb_add_hcd(xhci->shared_hcd, dev->irq,
 			IRQF_SHARED);
 	if (retval)
include/linux/usb/hcd.h +1 -0
index 0a78df5..eb6bf10 100644
@@ -124,6 +124,7 @@ struct usb_hcd {
 	/* Flags that get set only during HCD registration or removal. */
 	unsigned		rh_registered:1;/* is root hub registered? */
 	unsigned		rh_pollable:1;	/* may we poll the root hub? */
+	unsigned		msix_supported:1; /* driver supports MSI-X */
 	unsigned		msix_enabled:1;	/* driver has MSI-X enabled? */
 
 	/* The next flag is a stopgap, to be removed when all the HCDs
#1 lore raw
Quoted 12 lines · Hannes Reinecke

xhci might run with MSI/MSI-X only, with no support for legacy interrupts. On these devices the request_irq() call in usb_add_hcd() will fail, causing the entire device to fail.
For xhci this is especially painful as the driver will enable interrupts during xhci_run(), so the initial call to request_irq() is not required anyway.

This patch adds a flag 'msix_supported' to struct usb_hcd, which will cause usb_add_hcd() to skip interrupt setup. This flag is set in xhci-pci, so the registration will skip the first request_irq() and can proceed.

Quoted 7 lines
Cc Bjorn Helgaas <[email protected]>
Cc Oliver Neukum <[email protected]>
Cc Thomas Renninger <[email protected]>
Cc Yinghai Lu <[email protected]>
Cc Frederik Himpe <[email protected]>
Cc David Haerdeman <[email protected]>

It doesn't seem to work. I just tried applying the patch to the 3.8 kernel in Debian experimental and this was the result during boot:

[    1.203390] xhci_hcd 0000:00:14.0: can't derive routing for PCI INT A
[    1.203393] xhci_hcd 0000:00:14.0: PCI INT A: no GSI
[    1.203419] xhci_hcd 0000:00:14.0: setting latency timer to 64
[    1.203423] xhci_hcd 0000:00:14.0: xHCI Host Controller
[    1.203429] xhci_hcd 0000:00:14.0: new USB bus registered, assigned bus number 1
[    1.203533] xhci_hcd 0000:00:14.0: cache line size of 64 is not supported
[    1.203535] xhci_hcd 0000:00:14.0: request interrupt 255 failed
[    1.203580] xhci_hcd 0000:00:14.0: USB bus 1 deregistered
[    1.203598] xhci_hcd 0000:00:14.0: can't derive routing for PCI INT A
[    1.203600] xhci_hcd 0000:00:14.0: init 0000:00:14.0 fail, -22
[    1.203643] xhci_hcd: probe of 0000:00:14.0 failed with error -22

Regards,
David

#2 lore raw
In reply to Hannes Reinecke
Quoted 11 lines · Hannes Reinecke

xhci might run with MSI/MSI-X only, with no support for legacy interrupts. On these devices the request_irq() call in usb_add_hcd() will fail, causing the entire device to fail.
For xhci this is especially painful as the driver will enable interrupts during xhci_run(), so the initial call to request_irq() is not required anyway.

This patch adds a flag 'msix_supported' to struct usb_hcd, which will cause usb_add_hcd() to skip interrupt setup. This flag is set in xhci-pci, so the registration will skip the first request_irq() and can proceed.

I think it might be better to fix this in hcd-pci.c:usb_hcd_pci_probe. At that point if we see that MSI/MSI-X is available, the call to usb_add_hcd can pass 0 instead of dev->irq.

It may even be possible to do this without adding an extra flag anywhere. It also has the advantage of keeping special knowledge about MSI encapsulated in the PCI-specific parts of the code.

Alan Stern