1aad970f1SDavid E. O'Brien /*- 2eae4a35fSMatt Jacob * PCI specific probe and attach routines for LSI Fusion Adapters 39b631363SMatt Jacob * FreeBSD Version. 49b631363SMatt Jacob * 59b631363SMatt Jacob * Copyright (c) 2000, 2001 by Greg Ansley 69b631363SMatt Jacob * Partially derived from Matt Jacob's ISP driver. 7aad970f1SDavid E. O'Brien * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 by Matthew Jacob 8aad970f1SDavid E. O'Brien * Feral Software 9aad970f1SDavid E. O'Brien * All rights reserved. 109b631363SMatt Jacob * 119b631363SMatt Jacob * Redistribution and use in source and binary forms, with or without 129b631363SMatt Jacob * modification, are permitted provided that the following conditions 139b631363SMatt Jacob * are met: 149b631363SMatt Jacob * 1. Redistributions of source code must retain the above copyright 159b631363SMatt Jacob * notice immediately at the beginning of the file, without modification, 169b631363SMatt Jacob * this list of conditions, and the following disclaimer. 179b631363SMatt Jacob * 2. The name of the author may not be used to endorse or promote products 189b631363SMatt Jacob * derived from this software without specific prior written permission. 199b631363SMatt Jacob * 209b631363SMatt Jacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 219b631363SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 229b631363SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 239b631363SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 249b631363SMatt Jacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 259b631363SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 269b631363SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 279b631363SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 289b631363SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 299b631363SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 309b631363SMatt Jacob * SUCH DAMAGE. 319b631363SMatt Jacob */ 32b0a2fdeeSScott Long /* 33b0a2fdeeSScott Long * Copyright (c) 2004, Avid Technology, Inc. and its contributors. 34b0a2fdeeSScott Long * Copyright (c) 2005, WHEEL Sp. z o.o. 35b0a2fdeeSScott Long * Copyright (c) 2004, 2005 Justin T. Gibbs 36b0a2fdeeSScott Long * All rights reserved. 37b0a2fdeeSScott Long * 38b0a2fdeeSScott Long * Redistribution and use in source and binary forms, with or without 39b0a2fdeeSScott Long * modification, are permitted provided that the following conditions are 40b0a2fdeeSScott Long * met: 41b0a2fdeeSScott Long * 1. Redistributions of source code must retain the above copyright 42b0a2fdeeSScott Long * notice, this list of conditions and the following disclaimer. 43b0a2fdeeSScott Long * 2. Redistributions in binary form must reproduce at minimum a disclaimer 44b0a2fdeeSScott Long * substantially similar to the "NO WARRANTY" disclaimer below 45b0a2fdeeSScott Long * ("Disclaimer") and any redistribution must be conditioned upon including 46b0a2fdeeSScott Long * a substantially similar Disclaimer requirement for further binary 47b0a2fdeeSScott Long * redistribution. 48b0a2fdeeSScott Long * 3. Neither the name of the LSI Logic Corporation nor the names of its 49b0a2fdeeSScott Long * contributors may be used to endorse or promote products derived from 50b0a2fdeeSScott Long * this software without specific prior written permission. 51b0a2fdeeSScott Long * 52b0a2fdeeSScott Long * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 53b0a2fdeeSScott Long * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54b0a2fdeeSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55b0a2fdeeSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 56b0a2fdeeSScott Long * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 57b0a2fdeeSScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 58b0a2fdeeSScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 59b0a2fdeeSScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 60b0a2fdeeSScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 61b0a2fdeeSScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT 62b0a2fdeeSScott Long * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63b0a2fdeeSScott Long */ 64aad970f1SDavid E. O'Brien 65aad970f1SDavid E. O'Brien #include <sys/cdefs.h> 66aad970f1SDavid E. O'Brien __FBSDID("$FreeBSD$"); 679b631363SMatt Jacob 68b0a2fdeeSScott Long #include <dev/mpt/mpt.h> 69b0a2fdeeSScott Long #include <dev/mpt/mpt_cam.h> 70b0a2fdeeSScott Long #include <dev/mpt/mpt_raid.h> 717104aeefSMatt Jacob 72b0a2fdeeSScott Long #if __FreeBSD_version < 500000 73b0a2fdeeSScott Long #include <pci/pcireg.h> 74b0a2fdeeSScott Long #include <pci/pcivar.h> 75b0a2fdeeSScott Long #else 7638d8c994SWarner Losh #include <dev/pci/pcireg.h> 7738d8c994SWarner Losh #include <dev/pci/pcivar.h> 78b0a2fdeeSScott Long #endif 799b631363SMatt Jacob 809b631363SMatt Jacob #ifndef PCI_VENDOR_LSI 819b631363SMatt Jacob #define PCI_VENDOR_LSI 0x1000 829b631363SMatt Jacob #endif 839b631363SMatt Jacob 849b631363SMatt Jacob #ifndef PCI_PRODUCT_LSI_FC909 859b631363SMatt Jacob #define PCI_PRODUCT_LSI_FC909 0x0620 869b631363SMatt Jacob #endif 879b631363SMatt Jacob 88eae4a35fSMatt Jacob #ifndef PCI_PRODUCT_LSI_FC909A 89eae4a35fSMatt Jacob #define PCI_PRODUCT_LSI_FC909A 0x0621 90eae4a35fSMatt Jacob #endif 91eae4a35fSMatt Jacob 92aca01e38SMatt Jacob #ifndef PCI_PRODUCT_LSI_FC919 93aca01e38SMatt Jacob #define PCI_PRODUCT_LSI_FC919 0x0624 94aca01e38SMatt Jacob #endif 95aca01e38SMatt Jacob 969b631363SMatt Jacob #ifndef PCI_PRODUCT_LSI_FC929 979b631363SMatt Jacob #define PCI_PRODUCT_LSI_FC929 0x0622 989b631363SMatt Jacob #endif 999b631363SMatt Jacob 1009b631363SMatt Jacob #ifndef PCI_PRODUCT_LSI_1030 1019b631363SMatt Jacob #define PCI_PRODUCT_LSI_1030 0x0030 1029b631363SMatt Jacob #endif 1039b631363SMatt Jacob 104019717e0SMatt Jacob #ifndef PCIM_CMD_SERRESPEN 105019717e0SMatt Jacob #define PCIM_CMD_SERRESPEN 0x0100 106019717e0SMatt Jacob #endif 107019717e0SMatt Jacob 1089b631363SMatt Jacob 1099b631363SMatt Jacob 110b0a2fdeeSScott Long #define MPT_IO_BAR 0 111b0a2fdeeSScott Long #define MPT_MEM_BAR 1 1129b631363SMatt Jacob 113b0a2fdeeSScott Long static int mpt_pci_probe(device_t); 114b0a2fdeeSScott Long static int mpt_pci_attach(device_t); 115b0a2fdeeSScott Long static void mpt_free_bus_resources(struct mpt_softc *mpt); 116b0a2fdeeSScott Long static int mpt_pci_detach(device_t); 117b0a2fdeeSScott Long static int mpt_pci_shutdown(device_t); 118b0a2fdeeSScott Long static int mpt_dma_mem_alloc(struct mpt_softc *mpt); 119b0a2fdeeSScott Long static void mpt_dma_mem_free(struct mpt_softc *mpt); 120b0a2fdeeSScott Long static void mpt_read_config_regs(struct mpt_softc *mpt); 1217104aeefSMatt Jacob static void mpt_pci_intr(void *); 1229b631363SMatt Jacob 1239b631363SMatt Jacob static device_method_t mpt_methods[] = { 1249b631363SMatt Jacob /* Device interface */ 125b0a2fdeeSScott Long DEVMETHOD(device_probe, mpt_pci_probe), 126b0a2fdeeSScott Long DEVMETHOD(device_attach, mpt_pci_attach), 127b0a2fdeeSScott Long DEVMETHOD(device_detach, mpt_pci_detach), 128b0a2fdeeSScott Long DEVMETHOD(device_shutdown, mpt_pci_shutdown), 1299b631363SMatt Jacob { 0, 0 } 1309b631363SMatt Jacob }; 1319b631363SMatt Jacob 1329b631363SMatt Jacob static driver_t mpt_driver = { 133b0a2fdeeSScott Long "mpt", mpt_methods, sizeof(struct mpt_softc) 1349b631363SMatt Jacob }; 1359b631363SMatt Jacob static devclass_t mpt_devclass; 1369b631363SMatt Jacob DRIVER_MODULE(mpt, pci, mpt_driver, mpt_devclass, 0, 0); 1379b631363SMatt Jacob MODULE_VERSION(mpt, 1); 1389b631363SMatt Jacob 1399b631363SMatt Jacob static int 140b0a2fdeeSScott Long mpt_pci_probe(device_t dev) 1419b631363SMatt Jacob { 1429b631363SMatt Jacob char *desc; 1439b631363SMatt Jacob 1449b631363SMatt Jacob if (pci_get_vendor(dev) != PCI_VENDOR_LSI) 1459b631363SMatt Jacob return (ENXIO); 1469b631363SMatt Jacob 1479b631363SMatt Jacob switch ((pci_get_device(dev) & ~1)) { 1489b631363SMatt Jacob case PCI_PRODUCT_LSI_FC909: 1499b631363SMatt Jacob desc = "LSILogic FC909 FC Adapter"; 1509b631363SMatt Jacob break; 151eae4a35fSMatt Jacob case PCI_PRODUCT_LSI_FC909A: 152eae4a35fSMatt Jacob desc = "LSILogic FC909A FC Adapter"; 153eae4a35fSMatt Jacob break; 154aca01e38SMatt Jacob case PCI_PRODUCT_LSI_FC919: 155aca01e38SMatt Jacob desc = "LSILogic FC919 FC Adapter"; 156aca01e38SMatt Jacob break; 1579b631363SMatt Jacob case PCI_PRODUCT_LSI_FC929: 1589b631363SMatt Jacob desc = "LSILogic FC929 FC Adapter"; 1599b631363SMatt Jacob break; 1609b631363SMatt Jacob case PCI_PRODUCT_LSI_1030: 1619b631363SMatt Jacob desc = "LSILogic 1030 Ultra4 Adapter"; 1629b631363SMatt Jacob break; 1639b631363SMatt Jacob default: 1649b631363SMatt Jacob return (ENXIO); 1659b631363SMatt Jacob } 1669b631363SMatt Jacob 1679b631363SMatt Jacob device_set_desc(dev, desc); 168b0a2fdeeSScott Long return (0); 1699b631363SMatt Jacob } 1709b631363SMatt Jacob 1719b631363SMatt Jacob #ifdef RELENG_4 1729b631363SMatt Jacob static void 173b0a2fdeeSScott Long mpt_set_options(struct mpt_softc *mpt) 1749b631363SMatt Jacob { 1759b631363SMatt Jacob int bitmap; 1769b631363SMatt Jacob 1779b631363SMatt Jacob bitmap = 0; 1789b631363SMatt Jacob if (getenv_int("mpt_disable", &bitmap)) { 1799b631363SMatt Jacob if (bitmap & (1 << mpt->unit)) { 1809b631363SMatt Jacob mpt->disabled = 1; 1819b631363SMatt Jacob } 1829b631363SMatt Jacob } 1839b631363SMatt Jacob 1849b631363SMatt Jacob bitmap = 0; 1859b631363SMatt Jacob if (getenv_int("mpt_debug", &bitmap)) { 1869b631363SMatt Jacob if (bitmap & (1 << mpt->unit)) { 187b0a2fdeeSScott Long mpt->verbose = MPT_PRT_DEBUG; 1889b631363SMatt Jacob } 1899b631363SMatt Jacob } 1909b631363SMatt Jacob 1919b631363SMatt Jacob } 1929b631363SMatt Jacob #else 1939b631363SMatt Jacob static void 194b0a2fdeeSScott Long mpt_set_options(struct mpt_softc *mpt) 1959b631363SMatt Jacob { 1969b631363SMatt Jacob int tval; 1979b631363SMatt Jacob 1989b631363SMatt Jacob tval = 0; 1999b631363SMatt Jacob if (resource_int_value(device_get_name(mpt->dev), 2009b631363SMatt Jacob device_get_unit(mpt->dev), "disable", &tval) == 0 && tval != 0) { 2019b631363SMatt Jacob mpt->disabled = 1; 2029b631363SMatt Jacob } 2039b631363SMatt Jacob tval = 0; 2049b631363SMatt Jacob if (resource_int_value(device_get_name(mpt->dev), 2059b631363SMatt Jacob device_get_unit(mpt->dev), "debug", &tval) == 0 && tval != 0) { 2069b631363SMatt Jacob mpt->verbose += tval; 2079b631363SMatt Jacob } 2089b631363SMatt Jacob } 2099b631363SMatt Jacob #endif 2109b631363SMatt Jacob 2119b631363SMatt Jacob 212019717e0SMatt Jacob static void 213b0a2fdeeSScott Long mpt_link_peer(struct mpt_softc *mpt) 214019717e0SMatt Jacob { 215b0a2fdeeSScott Long struct mpt_softc *mpt2; 216019717e0SMatt Jacob 217b0a2fdeeSScott Long if (mpt->unit == 0) 218019717e0SMatt Jacob return; 219019717e0SMatt Jacob 220019717e0SMatt Jacob /* 221019717e0SMatt Jacob * XXX: depends on probe order 222019717e0SMatt Jacob */ 223b0a2fdeeSScott Long mpt2 = (struct mpt_softc *)devclass_get_softc(mpt_devclass,mpt->unit-1); 224019717e0SMatt Jacob 225019717e0SMatt Jacob if (mpt2 == NULL) { 226019717e0SMatt Jacob return; 227019717e0SMatt Jacob } 228019717e0SMatt Jacob if (pci_get_vendor(mpt2->dev) != pci_get_vendor(mpt->dev)) { 229019717e0SMatt Jacob return; 230019717e0SMatt Jacob } 231019717e0SMatt Jacob if (pci_get_device(mpt2->dev) != pci_get_device(mpt->dev)) { 232019717e0SMatt Jacob return; 233019717e0SMatt Jacob } 234019717e0SMatt Jacob mpt->mpt2 = mpt2; 235019717e0SMatt Jacob mpt2->mpt2 = mpt; 236b0a2fdeeSScott Long if (mpt->verbose >= MPT_PRT_DEBUG) { 237b0a2fdeeSScott Long mpt_prt(mpt, "linking with peer (mpt%d)\n", 238019717e0SMatt Jacob device_get_unit(mpt2->dev)); 239019717e0SMatt Jacob } 240019717e0SMatt Jacob } 241019717e0SMatt Jacob 242019717e0SMatt Jacob 2439b631363SMatt Jacob static int 244b0a2fdeeSScott Long mpt_pci_attach(device_t dev) 2459b631363SMatt Jacob { 246b0a2fdeeSScott Long struct mpt_softc *mpt; 2479b631363SMatt Jacob int iqd; 248b0a2fdeeSScott Long uint32_t data, cmd; 2499b631363SMatt Jacob 2509b631363SMatt Jacob /* Allocate the softc structure */ 251b0a2fdeeSScott Long mpt = (struct mpt_softc*)device_get_softc(dev); 2529b631363SMatt Jacob if (mpt == NULL) { 2539b631363SMatt Jacob device_printf(dev, "cannot allocate softc\n"); 2549b631363SMatt Jacob return (ENOMEM); 2559b631363SMatt Jacob } 256b0a2fdeeSScott Long bzero(mpt, sizeof(struct mpt_softc)); 2579b631363SMatt Jacob switch ((pci_get_device(dev) & ~1)) { 2589b631363SMatt Jacob case PCI_PRODUCT_LSI_FC909: 259eae4a35fSMatt Jacob case PCI_PRODUCT_LSI_FC909A: 260aca01e38SMatt Jacob case PCI_PRODUCT_LSI_FC919: 2619b631363SMatt Jacob case PCI_PRODUCT_LSI_FC929: 2629b631363SMatt Jacob mpt->is_fc = 1; 2639b631363SMatt Jacob break; 2649b631363SMatt Jacob default: 2659b631363SMatt Jacob break; 2669b631363SMatt Jacob } 2679b631363SMatt Jacob mpt->dev = dev; 2689b631363SMatt Jacob mpt->unit = device_get_unit(dev); 269b0a2fdeeSScott Long mpt->raid_resync_rate = MPT_RAID_RESYNC_RATE_DEFAULT; 270b0a2fdeeSScott Long mpt->raid_mwce_setting = MPT_RAID_MWCE_DEFAULT; 271b0a2fdeeSScott Long mpt->raid_queue_depth = MPT_RAID_QUEUE_DEPTH_DEFAULT; 2729b631363SMatt Jacob mpt_set_options(mpt); 273b0a2fdeeSScott Long mpt->verbose = MPT_PRT_INFO; 2749b631363SMatt Jacob mpt->verbose += (bootverbose != 0)? 1 : 0; 2759b631363SMatt Jacob 2769b631363SMatt Jacob /* Make sure memory access decoders are enabled */ 2779b631363SMatt Jacob cmd = pci_read_config(dev, PCIR_COMMAND, 2); 2789b631363SMatt Jacob if ((cmd & PCIM_CMD_MEMEN) == 0) { 2799b631363SMatt Jacob device_printf(dev, "Memory accesses disabled"); 2809b631363SMatt Jacob goto bad; 2819b631363SMatt Jacob } 2829b631363SMatt Jacob 2839b631363SMatt Jacob /* 2849b631363SMatt Jacob * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER are set. 2859b631363SMatt Jacob */ 2869b631363SMatt Jacob cmd |= 2879b631363SMatt Jacob PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN | 2889b631363SMatt Jacob PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN; 2899b631363SMatt Jacob pci_write_config(dev, PCIR_COMMAND, cmd, 2); 2909b631363SMatt Jacob 2919b631363SMatt Jacob /* 2929b631363SMatt Jacob * Make sure we've disabled the ROM. 2939b631363SMatt Jacob */ 2949b631363SMatt Jacob data = pci_read_config(dev, PCIR_BIOS, 4); 2959b631363SMatt Jacob data &= ~1; 2969b631363SMatt Jacob pci_write_config(dev, PCIR_BIOS, data, 4); 2979b631363SMatt Jacob 298019717e0SMatt Jacob /* 299019717e0SMatt Jacob * Is this part a dual? 300019717e0SMatt Jacob * If so, link with our partner (around yet) 301019717e0SMatt Jacob */ 302019717e0SMatt Jacob if ((pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_FC929 || 303019717e0SMatt Jacob (pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_1030) { 304019717e0SMatt Jacob mpt_link_peer(mpt); 3059b631363SMatt Jacob } 3069b631363SMatt Jacob 307b0a2fdeeSScott Long /* 308b0a2fdeeSScott Long * Set up register access. PIO mode is required for 309b0a2fdeeSScott Long * certain reset operations. 310b0a2fdeeSScott Long */ 311b0a2fdeeSScott Long mpt->pci_pio_rid = PCIR_BAR(MPT_IO_BAR); 312b0a2fdeeSScott Long mpt->pci_pio_reg = bus_alloc_resource(dev, SYS_RES_IOPORT, 313b0a2fdeeSScott Long &mpt->pci_pio_rid, 0, ~0, 0, RF_ACTIVE); 314b0a2fdeeSScott Long if (mpt->pci_pio_reg == NULL) { 315b0a2fdeeSScott Long device_printf(dev, "unable to map registers in PIO mode\n"); 3169b631363SMatt Jacob goto bad; 3179b631363SMatt Jacob } 318b0a2fdeeSScott Long mpt->pci_pio_st = rman_get_bustag(mpt->pci_pio_reg); 319b0a2fdeeSScott Long mpt->pci_pio_sh = rman_get_bushandle(mpt->pci_pio_reg); 320b0a2fdeeSScott Long 321b0a2fdeeSScott Long /* Allocate kernel virtual memory for the 9x9's Mem0 region */ 322b0a2fdeeSScott Long mpt->pci_mem_rid = PCIR_BAR(MPT_MEM_BAR); 323b0a2fdeeSScott Long mpt->pci_reg = bus_alloc_resource(dev, SYS_RES_MEMORY, 324b0a2fdeeSScott Long &mpt->pci_mem_rid, 0, ~0, 0, RF_ACTIVE); 325b0a2fdeeSScott Long if (mpt->pci_reg == NULL) { 326b0a2fdeeSScott Long device_printf(dev, "Unable to memory map registers.\n"); 327b0a2fdeeSScott Long device_printf(dev, "Falling back to PIO mode.\n"); 328b0a2fdeeSScott Long mpt->pci_st = mpt->pci_pio_st; 329b0a2fdeeSScott Long mpt->pci_sh = mpt->pci_pio_sh; 330b0a2fdeeSScott Long } else { 3319b631363SMatt Jacob mpt->pci_st = rman_get_bustag(mpt->pci_reg); 3329b631363SMatt Jacob mpt->pci_sh = rman_get_bushandle(mpt->pci_reg); 333b0a2fdeeSScott Long } 3349b631363SMatt Jacob 3359b631363SMatt Jacob /* Get a handle to the interrupt */ 3369b631363SMatt Jacob iqd = 0; 337b0a2fdeeSScott Long #if __FreeBSD_version < 500000 338b0a2fdeeSScott Long mpt->pci_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &iqd, 0, ~0, 1, 339b0a2fdeeSScott Long RF_ACTIVE | RF_SHAREABLE); 340b0a2fdeeSScott Long #else 3415f96beb9SNate Lawson mpt->pci_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &iqd, 3425f96beb9SNate Lawson RF_ACTIVE | RF_SHAREABLE); 343b0a2fdeeSScott Long #endif 3449b631363SMatt Jacob if (mpt->pci_irq == NULL) { 3459b631363SMatt Jacob device_printf(dev, "could not allocate interrupt\n"); 3469b631363SMatt Jacob goto bad; 3479b631363SMatt Jacob } 3489b631363SMatt Jacob 3497104aeefSMatt Jacob MPT_LOCK_SETUP(mpt); 3507104aeefSMatt Jacob 3519b631363SMatt Jacob /* Disable interrupts at the part */ 3529b631363SMatt Jacob mpt_disable_ints(mpt); 3539b631363SMatt Jacob 354b0a2fdeeSScott Long /* Register the interrupt handler */ 355b0a2fdeeSScott Long if (bus_setup_intr(dev, mpt->pci_irq, MPT_IFLAGS, mpt_pci_intr, 356b0a2fdeeSScott Long mpt, &mpt->ih)) { 357b0a2fdeeSScott Long device_printf(dev, "could not setup interrupt\n"); 358b0a2fdeeSScott Long goto bad; 359b0a2fdeeSScott Long } 360b0a2fdeeSScott Long 3619b631363SMatt Jacob /* Allocate dma memory */ 362b0a2fdeeSScott Long /* XXX JGibbs -Should really be done based on IOCFacts. */ 3639b631363SMatt Jacob if (mpt_dma_mem_alloc(mpt)) { 3649b631363SMatt Jacob device_printf(dev, "Could not allocate DMA memory\n"); 3659b631363SMatt Jacob goto bad; 3669b631363SMatt Jacob } 3679b631363SMatt Jacob 3687104aeefSMatt Jacob /* 3697104aeefSMatt Jacob * Save the PCI config register values 3707104aeefSMatt Jacob * 3717104aeefSMatt Jacob * Hard resets are known to screw up the BAR for diagnostic 3727104aeefSMatt Jacob * memory accesses (Mem1). 3737104aeefSMatt Jacob * 3747104aeefSMatt Jacob * Using Mem1 is known to make the chip stop responding to 3757104aeefSMatt Jacob * configuration space transfers, so we need to save it now 3767104aeefSMatt Jacob */ 3779b631363SMatt Jacob 3789b631363SMatt Jacob mpt_read_config_regs(mpt); 3799b631363SMatt Jacob 3809b631363SMatt Jacob /* Initialize the hardware */ 3819b631363SMatt Jacob if (mpt->disabled == 0) { 3827104aeefSMatt Jacob MPT_LOCK(mpt); 383b0a2fdeeSScott Long if (mpt_attach(mpt) != 0) { 3847104aeefSMatt Jacob MPT_UNLOCK(mpt); 3859b631363SMatt Jacob goto bad; 3869b631363SMatt Jacob } 3877104aeefSMatt Jacob } 3887104aeefSMatt Jacob 3899b631363SMatt Jacob return (0); 3909b631363SMatt Jacob 3919b631363SMatt Jacob bad: 3929b631363SMatt Jacob mpt_dma_mem_free(mpt); 3939b631363SMatt Jacob mpt_free_bus_resources(mpt); 3949b631363SMatt Jacob 3959b631363SMatt Jacob /* 3969b631363SMatt Jacob * but return zero to preserve unit numbering 3979b631363SMatt Jacob */ 3989b631363SMatt Jacob return (0); 3999b631363SMatt Jacob } 4009b631363SMatt Jacob 4017104aeefSMatt Jacob /* 4029b631363SMatt Jacob * Free bus resources 4039b631363SMatt Jacob */ 4049b631363SMatt Jacob static void 405b0a2fdeeSScott Long mpt_free_bus_resources(struct mpt_softc *mpt) 4069b631363SMatt Jacob { 4079b631363SMatt Jacob if (mpt->ih) { 4089b631363SMatt Jacob bus_teardown_intr(mpt->dev, mpt->pci_irq, mpt->ih); 4099b631363SMatt Jacob mpt->ih = 0; 4109b631363SMatt Jacob } 4119b631363SMatt Jacob 4129b631363SMatt Jacob if (mpt->pci_irq) { 4139b631363SMatt Jacob bus_release_resource(mpt->dev, SYS_RES_IRQ, 0, mpt->pci_irq); 4149b631363SMatt Jacob mpt->pci_irq = 0; 4159b631363SMatt Jacob } 4169b631363SMatt Jacob 417b0a2fdeeSScott Long if (mpt->pci_pio_reg) { 418b0a2fdeeSScott Long bus_release_resource(mpt->dev, SYS_RES_IOPORT, mpt->pci_pio_rid, 419b0a2fdeeSScott Long mpt->pci_pio_reg); 420b0a2fdeeSScott Long mpt->pci_pio_reg = 0; 421b0a2fdeeSScott Long } 4229b631363SMatt Jacob if (mpt->pci_reg) { 423b0a2fdeeSScott Long bus_release_resource(mpt->dev, SYS_RES_MEMORY, mpt->pci_mem_rid, 4249b631363SMatt Jacob mpt->pci_reg); 4259b631363SMatt Jacob mpt->pci_reg = 0; 4269b631363SMatt Jacob } 4277104aeefSMatt Jacob MPT_LOCK_DESTROY(mpt); 4289b631363SMatt Jacob } 4299b631363SMatt Jacob 4309b631363SMatt Jacob 4317104aeefSMatt Jacob /* 4329b631363SMatt Jacob * Disconnect ourselves from the system. 4339b631363SMatt Jacob */ 4349b631363SMatt Jacob static int 435b0a2fdeeSScott Long mpt_pci_detach(device_t dev) 4369b631363SMatt Jacob { 437b0a2fdeeSScott Long struct mpt_softc *mpt; 4389b631363SMatt Jacob 439b0a2fdeeSScott Long mpt = (struct mpt_softc*)device_get_softc(dev); 440b0a2fdeeSScott Long mpt_prt(mpt, "mpt_detach\n"); 4419b631363SMatt Jacob 4429b631363SMatt Jacob if (mpt) { 4439b631363SMatt Jacob mpt_disable_ints(mpt); 444b0a2fdeeSScott Long mpt_detach(mpt); 445b0a2fdeeSScott Long mpt_reset(mpt, /*reinit*/FALSE); 4469b631363SMatt Jacob mpt_dma_mem_free(mpt); 4479b631363SMatt Jacob mpt_free_bus_resources(mpt); 448b0a2fdeeSScott Long if (mpt->raid_volumes != NULL 449b0a2fdeeSScott Long && mpt->ioc_page2 != NULL) { 450b0a2fdeeSScott Long int i; 451b0a2fdeeSScott Long 452b0a2fdeeSScott Long for (i = 0; i < mpt->ioc_page2->MaxVolumes; i++) { 453b0a2fdeeSScott Long struct mpt_raid_volume *mpt_vol; 454b0a2fdeeSScott Long 455b0a2fdeeSScott Long mpt_vol = &mpt->raid_volumes[i]; 456b0a2fdeeSScott Long if (mpt_vol->config_page) 457b0a2fdeeSScott Long free(mpt_vol->config_page, M_DEVBUF); 458b0a2fdeeSScott Long } 459b0a2fdeeSScott Long } 460b0a2fdeeSScott Long if (mpt->ioc_page2 != NULL) 461b0a2fdeeSScott Long free(mpt->ioc_page2, M_DEVBUF); 462b0a2fdeeSScott Long if (mpt->ioc_page3 != NULL) 463b0a2fdeeSScott Long free(mpt->ioc_page3, M_DEVBUF); 464b0a2fdeeSScott Long if (mpt->raid_volumes != NULL) 465b0a2fdeeSScott Long free(mpt->raid_volumes, M_DEVBUF); 466b0a2fdeeSScott Long if (mpt->raid_disks != NULL) 467b0a2fdeeSScott Long free(mpt->raid_disks, M_DEVBUF); 468b0a2fdeeSScott Long if (mpt->eh != NULL) 469b0a2fdeeSScott Long EVENTHANDLER_DEREGISTER(shutdown_final, mpt->eh); 4709b631363SMatt Jacob } 4719b631363SMatt Jacob return(0); 4729b631363SMatt Jacob } 4739b631363SMatt Jacob 4749b631363SMatt Jacob 4757104aeefSMatt Jacob /* 4769b631363SMatt Jacob * Disable the hardware 477b0a2fdeeSScott Long * XXX - Called too early by New Bus!!! ??? 4789b631363SMatt Jacob */ 4799b631363SMatt Jacob static int 480b0a2fdeeSScott Long mpt_pci_shutdown(device_t dev) 4819b631363SMatt Jacob { 482b0a2fdeeSScott Long struct mpt_softc *mpt; 4839b631363SMatt Jacob 484b0a2fdeeSScott Long mpt = (struct mpt_softc *)device_get_softc(dev); 485b0a2fdeeSScott Long if (mpt) 486b0a2fdeeSScott Long return (mpt_shutdown(mpt)); 4879b631363SMatt Jacob return(0); 4889b631363SMatt Jacob } 4899b631363SMatt Jacob 4909b631363SMatt Jacob static int 491b0a2fdeeSScott Long mpt_dma_mem_alloc(struct mpt_softc *mpt) 4929b631363SMatt Jacob { 4939b631363SMatt Jacob int i, error; 494b0a2fdeeSScott Long uint8_t *vptr; 495b0a2fdeeSScott Long uint32_t pptr, end; 4967dec90bcSMatt Jacob size_t len; 497b0a2fdeeSScott Long struct mpt_map_info mi; 4989b631363SMatt Jacob device_t dev = mpt->dev; 4999b631363SMatt Jacob 5009b631363SMatt Jacob /* Check if we alreay have allocated the reply memory */ 501a89ec05eSPeter Wemm if (mpt->reply_phys != 0) { 5029b631363SMatt Jacob return 0; 5037dec90bcSMatt Jacob } 5047dec90bcSMatt Jacob 505b0a2fdeeSScott Long len = sizeof (request_t) * MPT_MAX_REQUESTS(mpt); 5067dec90bcSMatt Jacob #ifdef RELENG_4 507a163d034SWarner Losh mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK); 5087dec90bcSMatt Jacob if (mpt->request_pool == NULL) { 5097dec90bcSMatt Jacob device_printf(dev, "cannot allocate request pool\n"); 5107dec90bcSMatt Jacob return (1); 5117dec90bcSMatt Jacob } 5127dec90bcSMatt Jacob bzero(mpt->request_pool, len); 5137dec90bcSMatt Jacob #else 514b0a2fdeeSScott Long mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK|M_ZERO); 5157dec90bcSMatt Jacob if (mpt->request_pool == NULL) { 5167dec90bcSMatt Jacob device_printf(dev, "cannot allocate request pool\n"); 5177dec90bcSMatt Jacob return (1); 5187dec90bcSMatt Jacob } 5197dec90bcSMatt Jacob #endif 5209b631363SMatt Jacob 5219b631363SMatt Jacob /* 522b0a2fdeeSScott Long * Create a parent dma tag for this device 5239b631363SMatt Jacob * 524b0a2fdeeSScott Long * Align at byte boundaries, limit to 32-bit addressing 5259b631363SMatt Jacob * (The chip supports 64-bit addressing, but this driver doesn't) 5269b631363SMatt Jacob */ 527b0a2fdeeSScott Long if (mpt_dma_tag_create(mpt, /*parent*/NULL, /*alignment*/1, 528b0a2fdeeSScott Long /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, 529b0a2fdeeSScott Long /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, 530b0a2fdeeSScott Long /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, 531b0a2fdeeSScott Long /*nsegments*/BUS_SPACE_MAXSIZE_32BIT, 532b0a2fdeeSScott Long /*maxsegsz*/BUS_SPACE_UNRESTRICTED, /*flags*/0, 533b0a2fdeeSScott Long &mpt->parent_dmat) != 0) { 5349b631363SMatt Jacob device_printf(dev, "cannot create parent dma tag\n"); 5359b631363SMatt Jacob return (1); 5369b631363SMatt Jacob } 5379b631363SMatt Jacob 5389b631363SMatt Jacob /* Create a child tag for reply buffers */ 539b0a2fdeeSScott Long if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 5409b631363SMatt Jacob 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 5419b631363SMatt Jacob NULL, NULL, PAGE_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, 0, 542b0a2fdeeSScott Long &mpt->reply_dmat) != 0) { 5439b631363SMatt Jacob device_printf(dev, "cannot create a dma tag for replies\n"); 5449b631363SMatt Jacob return (1); 5459b631363SMatt Jacob } 5469b631363SMatt Jacob 5479b631363SMatt Jacob /* Allocate some DMA accessable memory for replies */ 5489b631363SMatt Jacob if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply, 5499b631363SMatt Jacob BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) { 550cc2f8c60SDavid E. O'Brien device_printf(dev, "cannot allocate %lu bytes of reply memory\n", 551cc2f8c60SDavid E. O'Brien (u_long)PAGE_SIZE); 5529b631363SMatt Jacob return (1); 5539b631363SMatt Jacob } 5549b631363SMatt Jacob 555b0a2fdeeSScott Long mi.mpt = mpt; 556b0a2fdeeSScott Long mi.error = 0; 5579b631363SMatt Jacob 5589b631363SMatt Jacob /* Load and lock it into "bus space" */ 5599b631363SMatt Jacob bus_dmamap_load(mpt->reply_dmat, mpt->reply_dmap, mpt->reply, 560b0a2fdeeSScott Long PAGE_SIZE, mpt_map_rquest, &mi, 0); 5619b631363SMatt Jacob 562b0a2fdeeSScott Long if (mi.error) { 5639b631363SMatt Jacob device_printf(dev, 564b0a2fdeeSScott Long "error %d loading dma map for DMA reply queue\n", mi.error); 5659b631363SMatt Jacob return (1); 5669b631363SMatt Jacob } 567b0a2fdeeSScott Long mpt->reply_phys = mi.phys; 5689b631363SMatt Jacob 5699b631363SMatt Jacob /* Create a child tag for data buffers */ 570b0a2fdeeSScott Long if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 5719b631363SMatt Jacob 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 5729b631363SMatt Jacob NULL, NULL, MAXBSIZE, MPT_SGL_MAX, BUS_SPACE_MAXSIZE_32BIT, 0, 573b0a2fdeeSScott Long &mpt->buffer_dmat) != 0) { 5749b631363SMatt Jacob device_printf(dev, 5759b631363SMatt Jacob "cannot create a dma tag for data buffers\n"); 5769b631363SMatt Jacob return (1); 5779b631363SMatt Jacob } 5789b631363SMatt Jacob 5799b631363SMatt Jacob /* Create a child tag for request buffers */ 580b0a2fdeeSScott Long if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 5819b631363SMatt Jacob 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 5827dec90bcSMatt Jacob NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0, 583b0a2fdeeSScott Long &mpt->request_dmat) != 0) { 5849b631363SMatt Jacob device_printf(dev, "cannot create a dma tag for requests\n"); 5859b631363SMatt Jacob return (1); 5869b631363SMatt Jacob } 5879b631363SMatt Jacob 5889b631363SMatt Jacob /* Allocate some DMA accessable memory for requests */ 5899b631363SMatt Jacob if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request, 5909b631363SMatt Jacob BUS_DMA_NOWAIT, &mpt->request_dmap) != 0) { 5919b631363SMatt Jacob device_printf(dev, 5929b631363SMatt Jacob "cannot allocate %d bytes of request memory\n", 5937dec90bcSMatt Jacob MPT_REQ_MEM_SIZE(mpt)); 5949b631363SMatt Jacob return (1); 5959b631363SMatt Jacob } 5969b631363SMatt Jacob 597b0a2fdeeSScott Long mi.mpt = mpt; 598b0a2fdeeSScott Long mi.error = 0; 5999b631363SMatt Jacob 6009b631363SMatt Jacob /* Load and lock it into "bus space" */ 6019b631363SMatt Jacob bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request, 602b0a2fdeeSScott Long MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &mi, 0); 6039b631363SMatt Jacob 604b0a2fdeeSScott Long if (mi.error) { 6059b631363SMatt Jacob device_printf(dev, 6069b631363SMatt Jacob "error %d loading dma map for DMA request queue\n", 607b0a2fdeeSScott Long mi.error); 6089b631363SMatt Jacob return (1); 6099b631363SMatt Jacob } 610b0a2fdeeSScott Long mpt->request_phys = mi.phys; 6119b631363SMatt Jacob 6129b631363SMatt Jacob i = 0; 6139b631363SMatt Jacob pptr = mpt->request_phys; 6149b631363SMatt Jacob vptr = mpt->request; 6157dec90bcSMatt Jacob end = pptr + MPT_REQ_MEM_SIZE(mpt); 6169b631363SMatt Jacob while(pptr < end) { 6177dec90bcSMatt Jacob request_t *req = &mpt->request_pool[i]; 6189b631363SMatt Jacob req->index = i++; 6199b631363SMatt Jacob 6209b631363SMatt Jacob /* Store location of Request Data */ 6219b631363SMatt Jacob req->req_pbuf = pptr; 6229b631363SMatt Jacob req->req_vbuf = vptr; 6239b631363SMatt Jacob 6249b631363SMatt Jacob pptr += MPT_REQUEST_AREA; 6259b631363SMatt Jacob vptr += MPT_REQUEST_AREA; 6269b631363SMatt Jacob 6279b631363SMatt Jacob req->sense_pbuf = (pptr - MPT_SENSE_SIZE); 6289b631363SMatt Jacob req->sense_vbuf = (vptr - MPT_SENSE_SIZE); 6299b631363SMatt Jacob 6309b631363SMatt Jacob error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap); 6319b631363SMatt Jacob if (error) { 6329b631363SMatt Jacob device_printf(dev, 6339b631363SMatt Jacob "error %d creating per-cmd DMA maps\n", error); 6349b631363SMatt Jacob return (1); 6359b631363SMatt Jacob } 6369b631363SMatt Jacob } 6379b631363SMatt Jacob return (0); 6389b631363SMatt Jacob } 6399b631363SMatt Jacob 6409b631363SMatt Jacob 6419b631363SMatt Jacob 6429b631363SMatt Jacob /* Deallocate memory that was allocated by mpt_dma_mem_alloc 6439b631363SMatt Jacob */ 6449b631363SMatt Jacob static void 645b0a2fdeeSScott Long mpt_dma_mem_free(struct mpt_softc *mpt) 6469b631363SMatt Jacob { 6479b631363SMatt Jacob int i; 6489b631363SMatt Jacob 6499b631363SMatt Jacob /* Make sure we aren't double destroying */ 6509b631363SMatt Jacob if (mpt->reply_dmat == 0) { 651b0a2fdeeSScott Long if (mpt->verbose >= MPT_PRT_DEBUG) 6529b631363SMatt Jacob device_printf(mpt->dev,"Already released dma memory\n"); 6539b631363SMatt Jacob return; 6549b631363SMatt Jacob } 6559b631363SMatt Jacob 6567dec90bcSMatt Jacob for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) { 6577dec90bcSMatt Jacob bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap); 6589b631363SMatt Jacob } 6599b631363SMatt Jacob bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap); 6609b631363SMatt Jacob bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap); 6619b631363SMatt Jacob bus_dma_tag_destroy(mpt->request_dmat); 6629b631363SMatt Jacob bus_dma_tag_destroy(mpt->buffer_dmat); 6639b631363SMatt Jacob bus_dmamap_unload(mpt->reply_dmat, mpt->reply_dmap); 6649b631363SMatt Jacob bus_dmamem_free(mpt->reply_dmat, mpt->reply, mpt->reply_dmap); 6659b631363SMatt Jacob bus_dma_tag_destroy(mpt->reply_dmat); 6669b631363SMatt Jacob bus_dma_tag_destroy(mpt->parent_dmat); 6679b631363SMatt Jacob mpt->reply_dmat = 0; 6687dec90bcSMatt Jacob free(mpt->request_pool, M_DEVBUF); 6697dec90bcSMatt Jacob mpt->request_pool = 0; 6709b631363SMatt Jacob 6719b631363SMatt Jacob } 6729b631363SMatt Jacob 6739b631363SMatt Jacob 6749b631363SMatt Jacob 6759b631363SMatt Jacob /* Reads modifiable (via PCI transactions) config registers */ 6769b631363SMatt Jacob static void 677b0a2fdeeSScott Long mpt_read_config_regs(struct mpt_softc *mpt) 6789b631363SMatt Jacob { 6799b631363SMatt Jacob mpt->pci_cfg.Command = pci_read_config(mpt->dev, PCIR_COMMAND, 2); 6809b631363SMatt Jacob mpt->pci_cfg.LatencyTimer_LineSize = 6819b631363SMatt Jacob pci_read_config(mpt->dev, PCIR_CACHELNSZ, 2); 682e27951b2SJohn Baldwin mpt->pci_cfg.IO_BAR = pci_read_config(mpt->dev, PCIR_BAR(0), 4); 683e27951b2SJohn Baldwin mpt->pci_cfg.Mem0_BAR[0] = pci_read_config(mpt->dev, PCIR_BAR(1), 4); 684e27951b2SJohn Baldwin mpt->pci_cfg.Mem0_BAR[1] = pci_read_config(mpt->dev, PCIR_BAR(2), 4); 685e27951b2SJohn Baldwin mpt->pci_cfg.Mem1_BAR[0] = pci_read_config(mpt->dev, PCIR_BAR(3), 4); 686e27951b2SJohn Baldwin mpt->pci_cfg.Mem1_BAR[1] = pci_read_config(mpt->dev, PCIR_BAR(4), 4); 6879b631363SMatt Jacob mpt->pci_cfg.ROM_BAR = pci_read_config(mpt->dev, PCIR_BIOS, 4); 6889b631363SMatt Jacob mpt->pci_cfg.IntLine = pci_read_config(mpt->dev, PCIR_INTLINE, 1); 6899b631363SMatt Jacob mpt->pci_cfg.PMCSR = pci_read_config(mpt->dev, 0x44, 4); 6909b631363SMatt Jacob } 6919b631363SMatt Jacob 6929b631363SMatt Jacob /* Sets modifiable config registers */ 6939b631363SMatt Jacob void 694b0a2fdeeSScott Long mpt_set_config_regs(struct mpt_softc *mpt) 6959b631363SMatt Jacob { 696b0a2fdeeSScott Long uint32_t val; 6979b631363SMatt Jacob 6989b631363SMatt Jacob #define MPT_CHECK(reg, offset, size) \ 6999b631363SMatt Jacob val = pci_read_config(mpt->dev, offset, size); \ 7009b631363SMatt Jacob if (mpt->pci_cfg.reg != val) { \ 701301472c2SMatt Jacob mpt_prt(mpt, \ 7029b631363SMatt Jacob "Restoring " #reg " to 0x%X from 0x%X\n", \ 7039b631363SMatt Jacob mpt->pci_cfg.reg, val); \ 7049b631363SMatt Jacob } 7059b631363SMatt Jacob 706b0a2fdeeSScott Long if (mpt->verbose >= MPT_PRT_DEBUG) { 7079b631363SMatt Jacob MPT_CHECK(Command, PCIR_COMMAND, 2); 7089b631363SMatt Jacob MPT_CHECK(LatencyTimer_LineSize, PCIR_CACHELNSZ, 2); 709e27951b2SJohn Baldwin MPT_CHECK(IO_BAR, PCIR_BAR(0), 4); 710e27951b2SJohn Baldwin MPT_CHECK(Mem0_BAR[0], PCIR_BAR(1), 4); 711e27951b2SJohn Baldwin MPT_CHECK(Mem0_BAR[1], PCIR_BAR(2), 4); 712e27951b2SJohn Baldwin MPT_CHECK(Mem1_BAR[0], PCIR_BAR(3), 4); 713e27951b2SJohn Baldwin MPT_CHECK(Mem1_BAR[1], PCIR_BAR(4), 4); 7149b631363SMatt Jacob MPT_CHECK(ROM_BAR, PCIR_BIOS, 4); 7159b631363SMatt Jacob MPT_CHECK(IntLine, PCIR_INTLINE, 1); 7169b631363SMatt Jacob MPT_CHECK(PMCSR, 0x44, 4); 7179b631363SMatt Jacob } 7189b631363SMatt Jacob #undef MPT_CHECK 7199b631363SMatt Jacob 7209b631363SMatt Jacob pci_write_config(mpt->dev, PCIR_COMMAND, mpt->pci_cfg.Command, 2); 7219b631363SMatt Jacob pci_write_config(mpt->dev, PCIR_CACHELNSZ, 7229b631363SMatt Jacob mpt->pci_cfg.LatencyTimer_LineSize, 2); 723e27951b2SJohn Baldwin pci_write_config(mpt->dev, PCIR_BAR(0), mpt->pci_cfg.IO_BAR, 4); 724e27951b2SJohn Baldwin pci_write_config(mpt->dev, PCIR_BAR(1), mpt->pci_cfg.Mem0_BAR[0], 4); 725e27951b2SJohn Baldwin pci_write_config(mpt->dev, PCIR_BAR(2), mpt->pci_cfg.Mem0_BAR[1], 4); 726e27951b2SJohn Baldwin pci_write_config(mpt->dev, PCIR_BAR(3), mpt->pci_cfg.Mem1_BAR[0], 4); 727e27951b2SJohn Baldwin pci_write_config(mpt->dev, PCIR_BAR(4), mpt->pci_cfg.Mem1_BAR[1], 4); 7289b631363SMatt Jacob pci_write_config(mpt->dev, PCIR_BIOS, mpt->pci_cfg.ROM_BAR, 4); 7299b631363SMatt Jacob pci_write_config(mpt->dev, PCIR_INTLINE, mpt->pci_cfg.IntLine, 1); 7309b631363SMatt Jacob pci_write_config(mpt->dev, 0x44, mpt->pci_cfg.PMCSR, 4); 7319b631363SMatt Jacob } 7327104aeefSMatt Jacob 7337104aeefSMatt Jacob static void 7347104aeefSMatt Jacob mpt_pci_intr(void *arg) 7357104aeefSMatt Jacob { 736b0a2fdeeSScott Long struct mpt_softc *mpt; 737b0a2fdeeSScott Long 738b0a2fdeeSScott Long mpt = (struct mpt_softc *)arg; 7397104aeefSMatt Jacob MPT_LOCK(mpt); 740b0a2fdeeSScott Long mpt_intr(mpt); 7417104aeefSMatt Jacob MPT_UNLOCK(mpt); 7427104aeefSMatt Jacob } 743