Index: mfi_disk.c =================================================================== --- mfi_disk.c (revision 227335) +++ mfi_disk.c (working copy) @@ -35,6 +35,7 @@ #include #include #include +#include #include #include Index: mfi_pci.c =================================================================== --- mfi_pci.c (revision 227335) +++ mfi_pci.c (working copy) @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,11 @@ DRIVER_MODULE(mfi, pci, mfi_pci_driver, mfi_devclass, 0, 0); MODULE_VERSION(mfi, 1); +static int mfi_msix = 0; +TUNABLE_INT("hw.mfi.msix", &mfi_msix); +SYSCTL_INT(_hw_mfi, OID_AUTO, msix, CTLFLAG_RDTUN, &mfi_msix, 0, + "Enable use of MSI-X interrupts"); + struct mfi_ident { uint16_t vendor; uint16_t device; @@ -169,7 +175,7 @@ struct mfi_softc *sc; struct mfi_ident *m; uint32_t command; - int error; + int count, error; sc = device_get_softc(dev); bzero(sc, sizeof(*sc)); @@ -226,6 +232,29 @@ goto out; } + /* Allocate IRQ resource. */ + sc->mfi_irq_rid = 0; + switch (pci_get_device(sc->mfi_dev)) { + case 0x0060: /* SAS1078R */ + case 0x007c: /* SAS1078DE */ + case 0x0413: /* Verde ZCR */ + /* Do not use MSI-X for these systems. */ + break; + default: + count = 1; + if (mfi_msix && pci_alloc_msix(sc->mfi_dev, &count) == 0) { + device_printf(sc->mfi_dev, "Using MSI-X\n"); + sc->mfi_irq_rid = 1; + } + break; + } + if ((sc->mfi_irq = bus_alloc_resource_any(sc->mfi_dev, SYS_RES_IRQ, + &sc->mfi_irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) { + device_printf(sc->mfi_dev, "Cannot allocate interrupt\n"); + error = EINVAL; + goto out; + } + error = mfi_attach(sc); out: if (error) { @@ -280,6 +309,8 @@ bus_release_resource(sc->mfi_dev, SYS_RES_MEMORY, sc->mfi_regs_rid, sc->mfi_regs_resource); } + if (sc->mfi_irq_rid != 0) + pci_release_msi(sc->mfi_dev); return; } Index: mfivar.h =================================================================== --- mfivar.h (revision 227335) +++ mfivar.h (working copy) @@ -395,6 +395,7 @@ (sc)->mfi_bhandle, (reg)) MALLOC_DECLARE(M_MFIBUF); +SYSCTL_DECL(_hw_mfi); #define MFI_CMD_TIMEOUT 30 #define MFI_MAXPHYS (128 * 1024) Index: mfi.c =================================================================== --- mfi.c (revision 227335) +++ mfi.c (working copy) @@ -117,7 +117,7 @@ static void mfi_issue_cmd_xscale(struct mfi_softc *sc,uint32_t bus_add,uint32_t frame_cnt); static void mfi_issue_cmd_ppc(struct mfi_softc *sc,uint32_t bus_add,uint32_t frame_cnt); -static SYSCTL_NODE(_hw, OID_AUTO, mfi, CTLFLAG_RD, 0, "MFI driver parameters"); +SYSCTL_NODE(_hw, OID_AUTO, mfi, CTLFLAG_RD, 0, "MFI driver parameters"); static int mfi_event_locale = MFI_EVT_LOCALE_ALL; TUNABLE_INT("hw.mfi.event_locale", &mfi_event_locale); SYSCTL_INT(_hw_mfi, OID_AUTO, event_locale, CTLFLAG_RW, &mfi_event_locale, @@ -157,6 +157,9 @@ mfi_enable_intr_xscale(struct mfi_softc *sc) { MFI_WRITE4(sc, MFI_OMSK, 0x01); + + /* Dummy read to force PCI flush. */ + (void)MFI_READ4(sc, MFI_OMSK); } static void @@ -168,6 +171,9 @@ } else if (sc->mfi_flags & MFI_FLAGS_GEN2) { MFI_WRITE4(sc, MFI_OMSK, ~MFI_GEN2_EIM); } + + /* Dummy read to force PCI flush. */ + (void)MFI_READ4(sc, MFI_OMSK); } static int32_t @@ -192,6 +198,9 @@ return 1; MFI_WRITE4(sc, MFI_OSTS, status); + + /* Dummy read to force PCI flush. */ + (void)MFI_READ4(sc, MFI_OSTS); return 0; } @@ -212,6 +221,9 @@ } MFI_WRITE4(sc, MFI_ODCR0, status); + + /* Dummy read to force PCI flush. */ + (void)MFI_READ4(sc, MFI_OSTS); return 0; } @@ -484,15 +496,8 @@ mtx_unlock(&sc->mfi_io_lock); /* - * Set up the interrupt handler. XXX This should happen in - * mfi_pci.c + * Set up the interrupt handler. */ - sc->mfi_irq_rid = 0; - if ((sc->mfi_irq = bus_alloc_resource_any(sc->mfi_dev, SYS_RES_IRQ, - &sc->mfi_irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) { - device_printf(sc->mfi_dev, "Cannot allocate interrupt\n"); - return (EINVAL); - } if (bus_setup_intr(sc->mfi_dev, sc->mfi_irq, INTR_MPSAFE|INTR_TYPE_BIO, NULL, mfi_intr, sc, &sc->mfi_intr)) { device_printf(sc->mfi_dev, "Cannot set up interrupt\n"); Index: mfi_cam.c =================================================================== --- mfi_cam.c (revision 227335) +++ mfi_cam.c (working copy) @@ -45,6 +45,7 @@ #include #include #include +#include #include #include