Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci mofity for if_wm and if_bge to use pci_intr_alloc()



details:   https://anonhg.NetBSD.org/src/rev/66b088a74a15
branches:  trunk
changeset: 809559:66b088a74a15
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Tue Jul 21 03:15:50 2015 +0000

description:
mofity for if_wm and if_bge to use pci_intr_alloc()

diffstat:

 sys/dev/pci/if_bge.c |   63 ++++++----
 sys/dev/pci/if_wm.c  |  300 +++++++++++++++++++++-----------------------------
 2 files changed, 161 insertions(+), 202 deletions(-)

diffs (truncated from 588 to 300 lines):

diff -r 6485d11cd956 -r 66b088a74a15 sys/dev/pci/if_bge.c
--- a/sys/dev/pci/if_bge.c      Tue Jul 21 03:12:50 2015 +0000
+++ b/sys/dev/pci/if_bge.c      Tue Jul 21 03:15:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bge.c,v 1.292 2015/06/14 08:46:33 martin Exp $      */
+/*     $NetBSD: if_bge.c,v 1.293 2015/07/21 03:15:50 knakahara Exp $   */
 
 /*
  * Copyright (c) 2001 Wind River Systems
@@ -79,7 +79,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.292 2015/06/14 08:46:33 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bge.c,v 1.293 2015/07/21 03:15:50 knakahara Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -3341,6 +3341,9 @@
        pci_chipset_tag_t       pc;
 #ifndef __HAVE_PCI_MSI_MSIX
        pci_intr_handle_t       ih;
+#else
+       int counts[PCI_INTR_TYPE_SIZE];
+       pci_intr_type_t intr_type, max_type;
 #endif
        const char              *intrstr = NULL;
        uint32_t                hwcfg, hwcfg2, hwcfg3, hwcfg4, hwcfg5;
@@ -3356,9 +3359,6 @@
        int                     capmask;
        int                     mii_flags;
        int                     map_flags;
-#ifdef __HAVE_PCI_MSI_MSIX
-       int                     rv;
-#endif
        char intrbuf[PCI_INTRSTR_LEN];
 
        bp = bge_lookup(pa);
@@ -3727,27 +3727,19 @@
        }
 
 #ifdef __HAVE_PCI_MSI_MSIX
-       DPRINTFN(5, ("pci_get_capability\n"));
+       counts[PCI_INTR_TYPE_MSI] = 1;
+       counts[PCI_INTR_TYPE_INTX] = 1;
        /* Check MSI capability */
-       if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSI,
-               &sc->bge_msicap, NULL) != 0) {
-               if (bge_can_use_msi(sc) != 0)
-                       sc->bge_flags |= BGEF_MSI;
-       }
-       rv = -1;
-       if (((sc->bge_flags & BGEF_MSI) != 0) && (pci_msi_count(pa) > 0)) {
-               DPRINTFN(5, ("pci_msi_alloc\n"));
-               rv = pci_msi_alloc_exact(pa, &sc->bge_pihp, 1);
-               if (rv != 0)
-                       sc->bge_flags &= ~BGEF_MSI;
-       }
-       if (rv != 0) {
-               DPRINTFN(5, ("pci_intx_alloc\n"));
-               if (pci_intx_alloc(pa, &sc->bge_pihp)) {
-                       aprint_error_dev(self, "can't map interrupt\n");
-                       return;
-               }
-               sc->bge_flags &= ~BGEF_MSI;
+       if (bge_can_use_msi(sc) != 0) {
+               max_type = PCI_INTR_TYPE_MSI;
+               sc->bge_flags |= BGEF_MSI;
+       } else
+               max_type = PCI_INTR_TYPE_INTX;
+
+alloc_retry:
+       if (pci_intr_alloc(pa, &sc->bge_pihp, counts, max_type) != 0) {
+               aprint_error_dev(sc->bge_dev, "couldn't alloc interrupt\n");
+               return;
        }
 #else  /* !__HAVE_PCI_MSI_MSIX */
        DPRINTFN(5, ("pci_intr_map\n"));
@@ -3757,15 +3749,32 @@
        }
 #endif
 
+       DPRINTFN(5, ("pci_intr_string\n"));
 #ifdef __HAVE_PCI_MSI_MSIX
-       DPRINTFN(5, ("pci_intr_string\n"));
        intrstr = pci_intr_string(pc, sc->bge_pihp[0], intrbuf,
            sizeof(intrbuf));
        DPRINTFN(5, ("pci_intr_establish\n"));
        sc->bge_intrhand = pci_intr_establish(pc, sc->bge_pihp[0], IPL_NET,
            bge_intr, sc);
+       if (sc->bge_intrhand == NULL) {
+               intr_type = pci_intr_type(sc->bge_pihp[0]);
+               aprint_error_dev(sc->bge_dev,"unable to establish %s\n",
+                   (intr_type == PCI_INTR_TYPE_MSI) ? "MSI" : "INTx");
+               pci_intr_release(pc, sc->bge_pihp, 1);
+               switch (intr_type) {
+               case PCI_INTR_TYPE_MSI:
+                       /* The next try is for INTx: Disable MSI */
+                       max_type = PCI_INTR_TYPE_INTX;
+                       counts[PCI_INTR_TYPE_INTX] = 1;
+                       sc->bge_flags &= ~BGEF_MSI;
+                       goto alloc_retry;
+               case PCI_INTR_TYPE_INTX:
+               default:
+                       /* See below */
+                       break;
+               }
+       }
 #else  /* !__HAVE_PCI_MSI_MSIX */
-       DPRINTFN(5, ("pci_intr_string\n"));
        intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf));
 
        DPRINTFN(5, ("pci_intr_establish\n"));
diff -r 6485d11cd956 -r 66b088a74a15 sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Tue Jul 21 03:12:50 2015 +0000
+++ b/sys/dev/pci/if_wm.c       Tue Jul 21 03:15:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wm.c,v 1.339 2015/07/15 07:40:54 msaitoh Exp $      */
+/*     $NetBSD: if_wm.c,v 1.340 2015/07/21 03:15:50 knakahara Exp $    */
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.339 2015/07/15 07:40:54 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.340 2015/07/21 03:15:50 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -155,27 +155,29 @@
 #endif
 
 #ifdef __HAVE_PCI_MSI_MSIX
-#define WM_MSI_MSIX    1 /* Enable by default */
+#if 0 /* off by default */
+#define WM_MSI_MSIX    1
+#endif
 #endif
 
 /*
  * This device driver divides interrupt to TX, RX and link state.
  * Each MSI-X vector indexes are below.
  */
-#define WM_NINTR               3
-#define WM_TX_INTR_INDEX       0
-#define WM_RX_INTR_INDEX       1
-#define WM_LINK_INTR_INDEX     2
-#define WM_MAX_NINTR           WM_NINTR
+#define WM_MSIX_NINTR          3
+#define WM_MSIX_TXINTR_IDX     0
+#define WM_MSIX_RXINTR_IDX     1
+#define WM_MSIX_LINKINTR_IDX   2
+#define WM_MAX_NINTR           WM_MSIX_NINTR
 
 /*
  * This device driver set affinity to each interrupts like below (round-robin).
  * If the number CPUs is less than the number of interrupts, this driver usase
  * the same CPU for multiple interrupts.
  */
-#define WM_TX_INTR_CPUID       0
-#define WM_RX_INTR_CPUID       1
-#define WM_LINK_INTR_CPUID     2
+#define WM_MSIX_TXINTR_CPUID   0
+#define WM_MSIX_RXINTR_CPUID   1
+#define WM_MSIX_LINKINTR_CPUID 2
 
 /*
  * Transmit descriptor list size.  Due to errata, we can only have
@@ -778,6 +780,20 @@
 static void    wm_reset_mdicnfg_82580(struct wm_softc *);
 static void    wm_pll_workaround_i210(struct wm_softc *);
 
+#ifdef WM_MSI_MSIX
+struct _msix_matrix {
+       const char *intrname;
+       int(*func)(void *);
+       int intridx;
+       int cpuid;
+} msix_matrix[WM_MSIX_NINTR] = {
+       { "TX", wm_txintr_msix, WM_MSIX_TXINTR_IDX, WM_MSIX_TXINTR_CPUID },
+       { "RX", wm_rxintr_msix, WM_MSIX_RXINTR_IDX, WM_MSIX_TXINTR_CPUID },
+       { "LINK", wm_linkintr_msix, WM_MSIX_LINKINTR_IDX,
+         WM_MSIX_LINKINTR_CPUID },
+};
+#endif
+
 CFATTACH_DECL3_NEW(wm, sizeof(struct wm_softc),
     wm_match, wm_attach, wm_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
 
@@ -1406,7 +1422,8 @@
 #ifndef WM_MSI_MSIX
        pci_intr_handle_t ih;
 #else
-       bool intr_established = false;
+       int counts[PCI_INTR_TYPE_SIZE];
+       pci_intr_type_t max_type;
 #endif
        const char *intrstr = NULL;
        const char *eetype, *xname;
@@ -1597,122 +1614,71 @@
        aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
        sc->sc_nintrs = 1;
 #else /* WM_MSI_MSIX */
-       if (pci_msix_alloc_exact(pa, &sc->sc_intrs, WM_NINTR) == 0) {
-               /* 1st, try to use MSI-X */
+       /* Allocation settings */
+       max_type = PCI_INTR_TYPE_MSIX;
+       counts[PCI_INTR_TYPE_MSIX] = WM_MAX_NINTR;
+       counts[PCI_INTR_TYPE_MSI] = 1;
+       counts[PCI_INTR_TYPE_INTX] = 1;
+
+alloc_retry:
+       if (pci_intr_alloc(pa, &sc->sc_intrs, counts, max_type) != 0) {
+               aprint_error_dev(sc->sc_dev, "failed to allocate interrupt\n");
+               return;
+       }
+
+       if (pci_intr_type(sc->sc_intrs[0]) == PCI_INTR_TYPE_MSIX) {
                void *vih;
                kcpuset_t *affinity;
 
                kcpuset_create(&affinity, false);
 
-               /*
-                * for TX
-                */
-               intrstr = pci_intr_string(pc, sc->sc_intrs[WM_TX_INTR_INDEX],
-                   intrbuf, sizeof(intrbuf));
+               for (i = 0; i < WM_MSIX_NINTR; i++) {
+                       intrstr = pci_intr_string(pc,
+                           sc->sc_intrs[msix_matrix[i].intridx], intrbuf,
+                           sizeof(intrbuf));
 #ifdef WM_MPSAFE
-               pci_intr_setattr(pc, &sc->sc_intrs[WM_TX_INTR_INDEX],
-                   PCI_INTR_MPSAFE, true);
-#endif
-               vih = pci_intr_establish(pc, sc->sc_intrs[WM_TX_INTR_INDEX],
-                   IPL_NET, wm_txintr_msix, sc);
-               if (vih == NULL) {
-                       aprint_error_dev(sc->sc_dev,
-                           "unable to establish MSI-X(for TX)%s%s\n",
-                           intrstr ? " at " : "", intrstr ? intrstr : "");
-                       pci_intr_release(sc->sc_pc, sc->sc_intrs,
-                           WM_NINTR);
-                       goto msi;
-               }
-               kcpuset_zero(affinity);
-               /* Round-robin affinity */
-               kcpuset_set(affinity, WM_TX_INTR_CPUID % ncpu);
-               error = pci_intr_distribute(vih, affinity, NULL);
-               if (error == 0) {
-                       aprint_normal_dev(sc->sc_dev,
-                           "for TX interrupting at %s affinity to %u\n",
-                           intrstr, WM_TX_INTR_CPUID % ncpu);
-               } else {
-                       aprint_normal_dev(sc->sc_dev,
-                           "for TX interrupting at %s\n",
-                           intrstr);
-               }
-               sc->sc_ihs[WM_TX_INTR_INDEX] = vih;
-
-               /*
-                * for RX
-                */
-               intrstr = pci_intr_string(pc, sc->sc_intrs[WM_RX_INTR_INDEX],
-                   intrbuf, sizeof(intrbuf));
-#ifdef WM_MPSAFE
-               pci_intr_setattr(pc, &sc->sc_intrs[WM_RX_INTR_INDEX],
-                   PCI_INTR_MPSAFE, true);
+                       pci_intr_setattr(pc,
+                           &sc->sc_intrs[msix_matrix[i].intridx],
+                           PCI_INTR_MPSAFE, true);
 #endif
-               vih = pci_intr_establish(pc, sc->sc_intrs[WM_RX_INTR_INDEX],
-                   IPL_NET, wm_rxintr_msix, sc);
-               if (vih == NULL) {
-                       aprint_error_dev(sc->sc_dev,
-                           "unable to establish MSI-X(for RX)%s%s\n",
-                           intrstr ? " at " : "", intrstr ? intrstr : "");
-                       pci_intr_release(sc->sc_pc, sc->sc_intrs,
-                           WM_NINTR);
-                       goto msi;
-               }
-               kcpuset_zero(affinity);
-               kcpuset_set(affinity, WM_RX_INTR_CPUID % ncpu);
-               error = pci_intr_distribute(vih, affinity, NULL);
-               if (error == 0) {
-                       aprint_normal_dev(sc->sc_dev,
-                           "for RX interrupting at %s affinity to %u\n",
-                           intrstr, WM_RX_INTR_CPUID % ncpu);
-               } else {
-                       aprint_normal_dev(sc->sc_dev,
-                           "for RX interrupting at %s\n",
-                           intrstr);
-               }
-               sc->sc_ihs[WM_RX_INTR_INDEX] = vih;
-
-               /*



Home | Main Index | Thread Index | Old Index