Skip to contentSkip to conversation

usb, PCI: split quirk for usb host controller to four

RFC PATCH In review Yinghai Lu 3 participants 7 messages Mar 1, 2012 – Mar 2, 2012

Subsystems (3)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

RFC PATCH 1/3 usb, PCI: split quirk for usb host controller to four

so we avoid checking class again and again in that quirk.

following patches will remove disable/enable for non-xhci and nelogic vendor checking for uhci/xhci

So total lines will increase 8 at last.

need to be applied after pci/linux-next and usb/usb-next

---
 drivers/usb/host/pci-quirks.c |   64 ++++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 14 deletions(-)
drivers/usb/host/pci-quirks.c +50 -14
Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================
@@ -884,17 +884,60 @@ static void __devinit quirk_usb_handoff_
 	iounmap(base);
 }
 
-static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
+static void __devinit quirk_usb_early_handoff_uhci(struct pci_dev *pdev)
+{
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
+		return;
+
+	if (pci_enable_device(pdev) < 0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");
+		return;
+	}
+	quirk_usb_handoff_uhci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_early_handoff_uhci);
+
+static void __devinit quirk_usb_early_handoff_ohci(struct pci_dev *pdev)
 {
 	/* Skip Netlogic mips SoC's internal PCI USB controller.
 	 * This device does not need/support EHCI/OHCI handoff
 	 */
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
-	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_XHCI)
+
+	if (pci_enable_device(pdev) < 0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");
+		return;
+	}
+	quirk_usb_handoff_ohci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_OHCI, 0, quirk_usb_early_handoff_ohci);
+
+static void __devinit quirk_usb_early_handoff_ehci(struct pci_dev *pdev)
+{
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
+		return;
+
+	if (pci_enable_device(pdev) < 0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");
+		return;
+	}
+	quirk_usb_handoff_ehci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_EHCI, 0, quirk_usb_early_handoff_ehci);
+
+static void __devinit quirk_usb_early_handoff_xhci(struct pci_dev *pdev)
+{
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
 	if (pci_enable_device(pdev) < 0) {
@@ -902,15 +945,8 @@ static void __devinit quirk_usb_early_ha
 				"BIOS handoff failed.\n");
 		return;
 	}
-	if (pdev->class == PCI_CLASS_SERIAL_USB_UHCI)
-		quirk_usb_handoff_uhci(pdev);
-	else if (pdev->class == PCI_CLASS_SERIAL_USB_OHCI)
-		quirk_usb_handoff_ohci(pdev);
-	else if (pdev->class == PCI_CLASS_SERIAL_USB_EHCI)
-		quirk_usb_handoff_ehci(pdev);
-	else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI)
-		quirk_usb_handoff_xhci(pdev);
+	quirk_usb_handoff_xhci(pdev);
 	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
-			PCI_CLASS_SERIAL_USB, 8, quirk_usb_early_handoff);
+		PCI_CLASS_SERIAL_USB_XHCI, 0, quirk_usb_early_handoff_xhci);
author
#1 lore raw

RFC PATCH 2/3 usb, PCI: remove disable/enable device with non-xhci quirk

| commit cab928ee1f221c9cc48d6615070fefe2e444384a
| USB: Fix handoff when BIOS disables host PCI device.

mention only need to do disable/enable for xhci controller.

So just remove that for non-xhci controller and restore old behavior for them.

---
 drivers/usb/host/pci-quirks.c |   18 ------------------
 1 file changed, 18 deletions(-)
drivers/usb/host/pci-quirks.c +0 -18
Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================
@@ -889,13 +889,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_uhci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_early_handoff_uhci);
@@ -908,13 +902,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_ohci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_OHCI, 0, quirk_usb_early_handoff_ohci);
@@ -924,13 +912,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_ehci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_EHCI, 0, quirk_usb_early_handoff_ehci);
#2 lore raw

Re: [RFC PATCH 2/3] usb, PCI: remove disable/enable device with non-xhci quirk

Quoted 6 lines · Yinghai Lu

| commit cab928ee1f221c9cc48d6615070fefe2e444384a
| USB: Fix handoff when BIOS disables host PCI device.

mention only need to do disable/enable for xhci controller.

So just remove that for non-xhci controller and restore old behavior for them.

As I said, we do need to do the enable/disable for all USB hosts. Jesse Barnes confirms that the PCI core doesn't do that for us, so we can't rely on the BIOS always enabling the PCI device. I don't think we need this patch, because we should always be doing the enable/disable for all USB hosts. We just never had a BIOS that caused this bug to be discovered until the xHCI BIOS for the Intel system in question.

Quoted 52 lines
---
 drivers/usb/host/pci-quirks.c |   18 ------------------
 1 file changed, 18 deletions(-)

Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================

drivers/usb/host/pci-quirks.c +0 -18
@@ -889,13 +889,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_uhci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_early_handoff_uhci);
@@ -908,13 +902,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_ohci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_OHCI, 0, quirk_usb_early_handoff_ohci);
@@ -924,13 +912,7 @@ static void __devinit quirk_usb_early_ha
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
 
-	if (pci_enable_device(pdev) < 0) {
-		dev_warn(&pdev->dev, "Can't enable PCI device, "
-				"BIOS handoff failed.\n");
-		return;
-	}
 	quirk_usb_handoff_ehci(pdev);
-	pci_disable_device(pdev);
 }
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
 		PCI_CLASS_SERIAL_USB_EHCI, 0, quirk_usb_early_handoff_ehci);
author
#3 lore raw

Re: [RFC PATCH 2/3] usb, PCI: remove disable/enable device with non-xhci quirk

Quoted 6 lines · Sarah Sharp
Quoted 5 lines · Yinghai Lu

| commit cab928ee1f221c9cc48d6615070fefe2e444384a |    USB: Fix handoff when BIOS disables host PCI device.

mention only need to do disable/enable for xhci controller.

Quoted 8 lines
Quoted 1 line

So just remove that for non-xhci controller and restore old behavior for them.

As I said, we do need to do the enable/disable for all USB hosts.  Jesse Barnes confirms that the PCI core doesn't do that for us, so we can't rely on the BIOS always enabling the PCI device.  I don't think we need this patch, because we should always be doing the enable/disable for all USB hosts.  We just never had a BIOS that caused this bug to be discovered until the xHCI BIOS for the Intel system in question.

ok

after
-DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID,

                                                quirk_usb_early_handoff);
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
                        PCI_CLASS_SERIAL_USB, 8, quirk_usb_early_handoff);

in pci-next get merged,

how about following change ?

drivers/usb/host/pci-quirks.c +0 -5
Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================
@@ -891,11 +891,6 @@ static void __devinit quirk_usb_early_ha
 	 */
 	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
 		return;
-	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_OHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_EHCI &&
-			pdev->class != PCI_CLASS_SERIAL_USB_XHCI)
-		return;
 
 	if (pci_enable_device(pdev) < 0) {
 		dev_warn(&pdev->dev, "Can't enable PCI device, "
author
#4 lore raw

RFC PATCH 3/3 usb, PCI: remove vendor checking for netlogic with uhci/xhci

In reply to Yinghai Lu
| commit e4436a7c17ac2b5e138f93f83a541cba9b311685
|    usb: Skip PCI USB quirk handling for Netlogic XLP
|    The Netlogic XLP SoC's on-chip USB controller appears as a PCI
|    USB device, but does not need the EHCI/OHCI handoff done in
|    usb/host/pci-quirks.c.

so only do that checking for EHCI and OHCI.

Cc Jayachandran C <[email protected]>
---
 drivers/usb/host/pci-quirks.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/usb/host/pci-quirks.c +1 -11
Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================
@@ -884,15 +884,8 @@ static void __devinit quirk_usb_handoff_
 	iounmap(base);
 }
 
-static void __devinit quirk_usb_early_handoff_uhci(struct pci_dev *pdev)
-{
-	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
-		return;
-
-	quirk_usb_handoff_uhci(pdev);
-}
 DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
-		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_early_handoff_uhci);
+		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_handoff_uhci);
 
 static void __devinit quirk_usb_early_handoff_ohci(struct pci_dev *pdev)
 {
@@ -919,9 +912,6 @@ DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID
 
 static void __devinit quirk_usb_early_handoff_xhci(struct pci_dev *pdev)
 {
-	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
-		return;
-
 	if (pci_enable_device(pdev) < 0) {
 		dev_warn(&pdev->dev, "Can't enable PCI device, "
 				"BIOS handoff failed.\n");
#5 lore raw
In reply to Yinghai Lu

Hello.

Quoted 4 lines · Yinghai Lu

so we avoid checking class again and again in that quirk.

following patches will remove disable/enable for non-xhci and nelogic vendor checking for uhci/xhci

Why add them in the first place?

Quoted 15 lines

So total lines will increase 8 at last.

need to be applied after pci/linux-next and usb/usb-next

---
  drivers/usb/host/pci-quirks.c |   64 ++++++++++++++++++++++++++++++++----------
  1 file changed, 50 insertions(+), 14 deletions(-)

Index: linux-2.6/drivers/usb/host/pci-quirks.c
===================================================================

drivers/usb/host/pci-quirks.c static void __devinit quirk_usb_handoff_ · line 890

Quoted 8 lines
drivers/usb/host/pci-quirks.c +4 -1
@@ -884,17 +884,60 @@ static void __devinit quirk_usb_handoff_
  	iounmap(base);
  }
 
-static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
+static void __devinit quirk_usb_early_handoff_uhci(struct pci_dev *pdev)
+{
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
+		return;

NetLogic vendor check should be only in quirk_usb_early_handoff_ohci() and
quirk_usb_early_handoff_ehci() according to the comment below.

Quoted 27 lines
drivers/usb/host/pci-quirks.c +17 -4
+
+	if (pci_enable_device(pdev)<  0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");
+		return;
+	}
+	quirk_usb_handoff_uhci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_UHCI, 0, quirk_usb_early_handoff_uhci);
+
+static void __devinit quirk_usb_early_handoff_ohci(struct pci_dev *pdev)
  {
  	/* Skip Netlogic mips SoC's internal PCI USB controller.
  	 * This device does not need/support EHCI/OHCI handoff
  	 */
  	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
  		return;
-	if (pdev->class != PCI_CLASS_SERIAL_USB_UHCI&&
-			pdev->class != PCI_CLASS_SERIAL_USB_OHCI&&
-			pdev->class != PCI_CLASS_SERIAL_USB_EHCI&&
-			pdev->class != PCI_CLASS_SERIAL_USB_XHCI)
+
+	if (pci_enable_device(pdev)<  0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");

drivers/usb/host/pci-quirks.c static void __devinit quirk_usb_handoff_ · line 923

Quoted 10 lines
drivers/usb/host/pci-quirks.c +10 -0
+		return;
+	}
+	quirk_usb_handoff_ohci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_OHCI, 0, quirk_usb_early_handoff_ohci);
+
+static void __devinit quirk_usb_early_handoff_ehci(struct pci_dev *pdev)
+{

The NetLogic comment should probably be repeated here.

Quoted 7 lines
drivers/usb/host/pci-quirks.c +7 -0
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */
+		return;
+
+	if (pci_enable_device(pdev)<  0) {
+		dev_warn(&pdev->dev, "Can't enable PCI device, "
+				"BIOS handoff failed.\n");
+		return;

drivers/usb/host/pci-quirks.c static void __devinit quirk_usb_handoff_ · line 940

Quoted 10 lines
drivers/usb/host/pci-quirks.c +10 -0
+	}
+	quirk_usb_handoff_ehci(pdev);
+	pci_disable_device(pdev);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+		PCI_CLASS_SERIAL_USB_EHCI, 0, quirk_usb_early_handoff_ehci);
+
+static void __devinit quirk_usb_early_handoff_xhci(struct pci_dev *pdev)
+{
+	if (pdev->vendor == 0x184e)	/* vendor Netlogic */

Not needed.

WBR, Sergei

author
#6 lore raw
Quoted 5 lines · Sergei Shtylyov

Hello.

On 01-03-2012 23:24, Yinghai Lu wrote:

Quoted 9 lines
Quoted 5 lines

so we avoid checking class again and again in that quirk.

following patches will remove disable/enable for non-xhci and nelogic vendor checking for uhci/xhci

  Why add them in the first place?

never mind, just drop those patches, sarah had some different view and want to keep disable/enable
device for all usb host controller instead of only xhci.

Thanks

Yinghai