Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci simplify the interrupt allocation - it's not nec...



details:   https://anonhg.NetBSD.org/src/rev/eb9d69519184
branches:  trunk
changeset: 446347:eb9d69519184
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat Dec 01 13:24:45 2018 +0000

description:
simplify the interrupt allocation - it's not necessary to do the explicit
fallbacks, pci_intr_alloc() does this already internally

diffstat:

 sys/dev/pci/nvme_pci.c |  79 ++++++++-----------------------------------------
 1 files changed, 14 insertions(+), 65 deletions(-)

diffs (137 lines):

diff -r c9d48978164b -r eb9d69519184 sys/dev/pci/nvme_pci.c
--- a/sys/dev/pci/nvme_pci.c    Sat Dec 01 13:01:57 2018 +0000
+++ b/sys/dev/pci/nvme_pci.c    Sat Dec 01 13:24:45 2018 +0000
@@ -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 @@
 {
        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 @@
                                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 @@
        /* 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;
 }



Home | Main Index | Thread Index | Old Index