Module Name:    src
Committed By:   jdolecek
Date:           Fri Nov 30 17:47:54 UTC 2018

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

Log Message:
simplify intr establish code - rely on pci_intr_alloc() to allow
also MSI-X, and to return interrupt types which are possible for
pci_intr_establish(); remove fallbacks to retry with MSI/MSI-X
explicitly disabled

discussed on tech-kern@

https://mail-index.netbsd.org/tech-kern/2018/11/27/msg024240.html


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/pci/ahcisata_pci.c
cvs rdiff -u -r1.17 -r1.18 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/ahcisata_pci.c
diff -u src/sys/dev/pci/ahcisata_pci.c:1.47 src/sys/dev/pci/ahcisata_pci.c:1.48
--- src/sys/dev/pci/ahcisata_pci.c:1.47	Mon Nov 26 21:56:04 2018
+++ src/sys/dev/pci/ahcisata_pci.c	Fri Nov 30 17:47:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_pci.c,v 1.47 2018/11/26 21:56:04 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_pci.c,v 1.48 2018/11/30 17:47:54 jdolecek Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.47 2018/11/26 21:56:04 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_pci.c,v 1.48 2018/11/30 17:47:54 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ahcisata_pci.h"
@@ -311,21 +311,8 @@ ahci_pci_attach(device_t parent, device_
 
 	pci_aprint_devinfo(pa, "AHCI disk controller");
 
-
-	/* Allocation settings */
-	int counts[PCI_INTR_TYPE_SIZE] = {
-		[PCI_INTR_TYPE_INTX] = 1,
-#ifndef AHCISATA_DISABLE_MSI
-		[PCI_INTR_TYPE_MSI] = 1,
-#endif
-#ifndef AHCISATA_DISABLE_MSIX
-		[PCI_INTR_TYPE_MSIX] = 1,
-#endif
-	};
-
-alloc_retry:
 	/* Allocate and establish the interrupt. */
-	if (pci_intr_alloc(pa, &psc->sc_pihp, counts, PCI_INTR_TYPE_MSIX)) {
+	if (pci_intr_alloc(pa, &psc->sc_pihp, NULL, 0)) {
 		aprint_error_dev(self, "can't allocate handler\n");
 		goto fail;
 	}
@@ -335,37 +322,13 @@ alloc_retry:
 	psc->sc_ih = pci_intr_establish_xname(pa->pa_pc, psc->sc_pihp[0],
 	    IPL_BIO, ahci_intr, sc, device_xname(sc->sc_atac.atac_dev));
 	if (psc->sc_ih == NULL) {
-		const pci_intr_type_t intr_type = pci_intr_type(pa->pa_pc,
-		    psc->sc_pihp[0]);
 		pci_intr_release(pa->pa_pc, psc->sc_pihp, 1);
 		psc->sc_ih = NULL;
-		switch (intr_type) {
-#ifndef AHCISATA_DISABLE_MSIX
-		case PCI_INTR_TYPE_MSIX:
-			/* The next try is for MSI: Disable MSIX */
-			counts[PCI_INTR_TYPE_INTX] = 1;
-#ifndef AHCISATA_DISABLE_MSI
-			counts[PCI_INTR_TYPE_MSI] = 1;
-#endif
-			counts[PCI_INTR_TYPE_MSIX] = 0;
-			goto alloc_retry;
-#endif
-#ifndef AHCISATA_DISABLE_MSI
-		case PCI_INTR_TYPE_MSI:
-			/* The next try is for INTx: Disable MSI */
-			counts[PCI_INTR_TYPE_MSI] = 0;
-			counts[PCI_INTR_TYPE_INTX] = 1;
-			goto alloc_retry;
-#endif
-		case PCI_INTR_TYPE_INTX:
-		default:
-			counts[PCI_INTR_TYPE_INTX] = 1;
-			aprint_error_dev(self, "couldn't establish interrupt");
-			if (intrstr != NULL)
-				aprint_error(" at %s", intrstr);
-			aprint_error("\n");
-			goto fail;
-		}
+		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);
 

Index: src/sys/dev/pci/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.17 src/sys/dev/pci/xhci_pci.c:1.18
--- src/sys/dev/pci/xhci_pci.c:1.17	Sat Nov 24 14:50:04 2018
+++ src/sys/dev/pci/xhci_pci.c	Fri Nov 30 17:47:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci_pci.c,v 1.17 2018/11/24 14:50:04 skrll Exp $	*/
+/*	$NetBSD: xhci_pci.c,v 1.18 2018/11/30 17:47:54 jdolecek 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.17 2018/11/24 14:50:04 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.18 2018/11/30 17:47:54 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_xhci_pci.h"
@@ -123,7 +123,6 @@ 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, usbrev;
 	int err;
@@ -177,20 +176,8 @@ xhci_pci_attach(device_t parent, device_
 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG,
 		       csr | PCI_COMMAND_MASTER_ENABLE);
 
-	/* Allocation settings */
-	int counts[PCI_INTR_TYPE_SIZE] = {
-		[PCI_INTR_TYPE_INTX] = 1,
-#ifndef XHCI_DISABLE_MSI
-		[PCI_INTR_TYPE_MSI] = 1,
-#endif
-#ifndef XHCI_DISABLE_MSIX
-		[PCI_INTR_TYPE_MSIX] = 1,
-#endif
-	};
-
-alloc_retry:
 	/* Allocate and establish the interrupt. */
-	if (pci_intr_alloc(pa, &psc->sc_pihp, counts, PCI_INTR_TYPE_MSIX)) {
+	if (pci_intr_alloc(pa, &psc->sc_pihp, NULL, 0)) {
 		aprint_error_dev(self, "can't allocate handler\n");
 		goto fail;
 	}
@@ -199,35 +186,13 @@ alloc_retry:
 	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) {
-		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) {
-#ifndef XHCI_DISABLE_MSIX
-		case PCI_INTR_TYPE_MSIX:
-			/* The next try is for MSI: Disable MSIX */
-			counts[PCI_INTR_TYPE_MSIX] = 0;
-#ifndef XHCI_DISABLE_MSI
-			counts[PCI_INTR_TYPE_MSI] = 1;
-#endif
-			counts[PCI_INTR_TYPE_INTX] = 1;
-			goto alloc_retry;
-#endif
-#ifndef XHCI_DISABLE_MSI
-		case PCI_INTR_TYPE_MSI:
-			/* The next try is for INTx: Disable MSI */
-			counts[PCI_INTR_TYPE_MSI] = 0;
-			counts[PCI_INTR_TYPE_INTX] = 1;
-			goto alloc_retry;
-#endif
-		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_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);
 

Reply via email to