Module Name:    src
Committed By:   msaitoh
Date:           Mon Dec 25 08:39:38 UTC 2017

Modified Files:
        src/sys/dev/pci: xhci_pci.c

Log Message:
- Fix a panic while cleaning PCI interrupt.
- Fallback to INTx if MSI allocation succeeded but the establish failed.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/xhci_pci.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.9 src/sys/dev/pci/xhci_pci.c:1.10
--- src/sys/dev/pci/xhci_pci.c:1.9	Tue Sep  5 08:01:43 2017
+++ src/sys/dev/pci/xhci_pci.c	Mon Dec 25 08:39:38 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci_pci.c,v 1.9 2017/09/05 08:01:43 skrll Exp $	*/
+/*	$NetBSD: xhci_pci.c,v 1.10 2017/12/25 08:39:38 msaitoh Exp $	*/
 /*	OpenBSD: xhci_pci.c,v 1.4 2014/07/12 17:38:51 yuo Exp	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.9 2017/09/05 08:01:43 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.10 2017/12/25 08:39:38 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xhci_pci.h"
@@ -123,6 +123,7 @@ xhci_pci_attach(device_t parent, device_
 	struct pci_attach_args *const pa = (struct pci_attach_args *)aux;
 	const pci_chipset_tag_t pc = pa->pa_pc;
 	const pcitag_t tag = pa->pa_tag;
+	pci_intr_type_t intr_type;
 	char const *intrstr;
 	pcireg_t csr, memtype;
 	int err;
@@ -185,6 +186,7 @@ xhci_pci_attach(device_t parent, device_
 #endif
 	};
 
+alloc_retry:
 	/* Allocate and establish the interrupt. */
 	if (pci_intr_alloc(pa, &psc->sc_pihp, counts, PCI_INTR_TYPE_MSIX)) {
 		aprint_error_dev(self, "can't allocate handler\n");
@@ -195,11 +197,22 @@ xhci_pci_attach(device_t parent, device_
 	psc->sc_ih = pci_intr_establish_xname(pc, psc->sc_pihp[0], IPL_USB,
 	    xhci_intr, sc, device_xname(sc->sc_dev));
 	if (psc->sc_ih == NULL) {
-		aprint_error_dev(self, "couldn't establish interrupt");
-		if (intrstr != NULL)
-			aprint_error(" at %s", intrstr);
-		aprint_error("\n");
-		goto fail;
+		intr_type = pci_intr_type(pc, psc->sc_pihp[0]);
+		pci_intr_release(pc, psc->sc_pihp, 1);
+		psc->sc_ih = NULL;
+		switch (intr_type) {
+		case PCI_INTR_TYPE_MSI:
+			/* The next try is for INTx: Disable MSI */
+			counts[PCI_INTR_TYPE_MSI] = 0;
+			goto alloc_retry;
+		case PCI_INTR_TYPE_INTX:
+		default:
+			aprint_error_dev(self, "couldn't establish interrupt");
+			if (intrstr != NULL)
+				aprint_error(" at %s", intrstr);
+			aprint_error("\n");
+			goto fail;
+		}
 	}
 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
 
@@ -238,10 +251,14 @@ xhci_pci_attach(device_t parent, device_
 	return;
 
 fail:
-	if (psc->sc_ih) {
-		pci_intr_release(psc->sc_pc, psc->sc_pihp, 1);
+	if (psc->sc_ih != NULL) {
+		pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
 		psc->sc_ih = NULL;
 	}
+	if (psc->sc_pihp != NULL) {
+		pci_intr_release(psc->sc_pc, psc->sc_pihp, 1);
+		psc->sc_pihp = NULL;
+	}
 	if (sc->sc_ios) {
 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
 		sc->sc_ios = 0;
@@ -273,9 +290,13 @@ xhci_pci_detach(device_t self, int flags
 	}
 
 	if (psc->sc_ih != NULL) {
-		pci_intr_release(psc->sc_pc, psc->sc_pihp, 1);
+		pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
 		psc->sc_ih = NULL;
 	}
+	if (psc->sc_pihp != NULL) {
+		pci_intr_release(psc->sc_pc, psc->sc_pihp, 1);
+		psc->sc_pihp = NULL;
+	}
 	if (sc->sc_ios) {
 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios);
 		sc->sc_ios = 0;

Reply via email to