Module Name: src Committed By: jdolecek Date: Sat Dec 1 13:24:45 UTC 2018
Modified Files: src/sys/dev/pci: nvme_pci.c Log Message: simplify the interrupt allocation - it's not necessary to do the explicit fallbacks, pci_intr_alloc() does this already internally To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/pci/nvme_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/nvme_pci.c diff -u src/sys/dev/pci/nvme_pci.c:1.21 src/sys/dev/pci/nvme_pci.c:1.22 --- src/sys/dev/pci/nvme_pci.c:1.21 Mon Sep 3 16:29:32 2018 +++ src/sys/dev/pci/nvme_pci.c Sat Dec 1 13:24:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: nvme_pci.c,v 1.21 2018/09/03 16:29:32 riastradh Exp $ */ +/* $NetBSD: nvme_pci.c,v 1.22 2018/12/01 13:24:45 jdolecek Exp $ */ /* $OpenBSD: nvme_pci.c,v 1.3 2016/04/14 11:18:32 dlg Exp $ */ /* @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.21 2018/09/03 16:29:32 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.22 2018/12/01 13:24:45 jdolecek Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -386,40 +386,24 @@ nvme_pci_setup_intr(struct pci_attach_ar { struct nvme_softc *sc = &psc->psc_nvme; int error; - int counts[PCI_INTR_TYPE_SIZE], alloced_counts[PCI_INTR_TYPE_SIZE]; + int counts[PCI_INTR_TYPE_SIZE]; pci_intr_handle_t *ihps; - int max_type, intr_type; + int intr_type; - if (nvme_pci_force_intx) { - max_type = PCI_INTR_TYPE_INTX; + memset(counts, 0, sizeof(counts)); + + if (nvme_pci_force_intx) goto force_intx; - } /* MSI-X */ - max_type = PCI_INTR_TYPE_MSIX; counts[PCI_INTR_TYPE_MSIX] = uimin(pci_msix_count(pa->pa_pc, pa->pa_tag), ncpu + 1); - if (counts[PCI_INTR_TYPE_MSIX] > 0) { - memset(alloced_counts, 0, sizeof(alloced_counts)); - alloced_counts[PCI_INTR_TYPE_MSIX] = counts[PCI_INTR_TYPE_MSIX]; - if (pci_intr_alloc(pa, &ihps, alloced_counts, - PCI_INTR_TYPE_MSIX)) { - counts[PCI_INTR_TYPE_MSIX] = 0; - } else { - counts[PCI_INTR_TYPE_MSIX] = - alloced_counts[PCI_INTR_TYPE_MSIX]; - pci_intr_release(pa->pa_pc, ihps, - alloced_counts[PCI_INTR_TYPE_MSIX]); - } - } if (counts[PCI_INTR_TYPE_MSIX] < 2) { counts[PCI_INTR_TYPE_MSIX] = 0; - max_type = PCI_INTR_TYPE_MSI; } else if (!nvme_pci_mq || !nvme_pci_mpsafe) { counts[PCI_INTR_TYPE_MSIX] = 2; /* adminq + 1 ioq */ } -retry_msi: /* MSI */ counts[PCI_INTR_TYPE_MSI] = pci_msi_count(pa->pa_pc, pa->pa_tag); if (counts[PCI_INTR_TYPE_MSI] > 0) { @@ -428,22 +412,9 @@ retry_msi: break; counts[PCI_INTR_TYPE_MSI] /= 2; } - memset(alloced_counts, 0, sizeof(alloced_counts)); - alloced_counts[PCI_INTR_TYPE_MSI] = counts[PCI_INTR_TYPE_MSI]; - if (pci_intr_alloc(pa, &ihps, alloced_counts, - PCI_INTR_TYPE_MSI)) { - counts[PCI_INTR_TYPE_MSI] = 0; - } else { - counts[PCI_INTR_TYPE_MSI] = - alloced_counts[PCI_INTR_TYPE_MSI]; - pci_intr_release(pa->pa_pc, ihps, - alloced_counts[PCI_INTR_TYPE_MSI]); - } } if (counts[PCI_INTR_TYPE_MSI] < 1) { counts[PCI_INTR_TYPE_MSI] = 0; - if (max_type == PCI_INTR_TYPE_MSI) - max_type = PCI_INTR_TYPE_INTX; } else if (!nvme_pci_mq || !nvme_pci_mpsafe) { if (counts[PCI_INTR_TYPE_MSI] > 2) counts[PCI_INTR_TYPE_MSI] = 2; /* adminq + 1 ioq */ @@ -453,42 +424,20 @@ force_intx: /* INTx */ counts[PCI_INTR_TYPE_INTX] = 1; - memcpy(alloced_counts, counts, sizeof(counts)); - error = pci_intr_alloc(pa, &ihps, alloced_counts, max_type); - if (error) { - if (max_type != PCI_INTR_TYPE_INTX) { -retry: - memset(counts, 0, sizeof(counts)); - if (max_type == PCI_INTR_TYPE_MSIX) { - max_type = PCI_INTR_TYPE_MSI; - goto retry_msi; - } else { - max_type = PCI_INTR_TYPE_INTX; - goto force_intx; - } - } + error = pci_intr_alloc(pa, &ihps, counts, PCI_INTR_TYPE_MSIX); + if (error) return error; - } intr_type = pci_intr_type(pa->pa_pc, ihps[0]); - if (alloced_counts[intr_type] < counts[intr_type]) { - if (intr_type != PCI_INTR_TYPE_INTX) { - pci_intr_release(pa->pa_pc, ihps, - alloced_counts[intr_type]); - max_type = intr_type; - goto retry; - } - return EBUSY; - } psc->psc_intrs = ihps; - psc->psc_nintrs = alloced_counts[intr_type]; + psc->psc_nintrs = counts[intr_type]; if (intr_type == PCI_INTR_TYPE_MSI) { - if (alloced_counts[intr_type] > ncpu + 1) - alloced_counts[intr_type] = ncpu + 1; + if (counts[intr_type] > ncpu + 1) + counts[intr_type] = ncpu + 1; } - sc->sc_use_mq = alloced_counts[intr_type] > 1; - sc->sc_nq = sc->sc_use_mq ? alloced_counts[intr_type] - 1 : 1; + sc->sc_use_mq = counts[intr_type] > 1; + sc->sc_nq = sc->sc_use_mq ? counts[intr_type] - 1 : 1; return 0; }