Home | History | Annotate | Line # | Download | only in pci
mpt_pci.c revision 1.20.16.1
      1 /*	$NetBSD: mpt_pci.c,v 1.20.16.1 2012/02/18 07:34:45 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2003 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Additional contributions by Garrett D'Amore on behalf of TELES AG.
     40  */
     41 
     42 /*
     43  * mpt_pci.c:
     44  *
     45  * NetBSD PCI-specific routines for LSI Fusion adapters.
     46  */
     47 
     48 #include <sys/cdefs.h>
     49 __KERNEL_RCSID(0, "$NetBSD: mpt_pci.c,v 1.20.16.1 2012/02/18 07:34:45 mrg Exp $");
     50 
     51 #include <dev/ic/mpt.h>			/* pulls in all headers */
     52 
     53 #include <dev/pci/pcireg.h>
     54 #include <dev/pci/pcivar.h>
     55 #include <dev/pci/pcidevs.h>
     56 
     57 #define	MPT_PCI_MMBA		(PCI_MAPREG_START+0x04)
     58 
     59 struct mpt_pci_softc {
     60 	mpt_softc_t sc_mpt;
     61 
     62 	pci_chipset_tag_t sc_pc;
     63 	pcitag_t sc_tag;
     64 
     65 	void *sc_ih;
     66 
     67 	/* Saved volatile PCI configuration registers. */
     68 	pcireg_t sc_pci_csr;
     69 	pcireg_t sc_pci_bhlc;
     70 	pcireg_t sc_pci_io_bar;
     71 	pcireg_t sc_pci_mem0_bar[2];
     72 	pcireg_t sc_pci_mem1_bar[2];
     73 	pcireg_t sc_pci_rom_bar;
     74 	pcireg_t sc_pci_int;
     75 	pcireg_t sc_pci_pmcsr;
     76 };
     77 
     78 #define	MPP_F_FC	0x01	/* Fibre Channel adapter */
     79 #define	MPP_F_DUAL	0x02	/* Dual port adapter */
     80 
     81 static const struct mpt_pci_product {
     82 	pci_vendor_id_t		mpp_vendor;
     83 	pci_product_id_t	mpp_product;
     84 } mpt_pci_products[] = {
     85 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_1030 },
     86 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC909 },
     87 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC909A },
     88 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC929 },
     89 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC929_1 },
     90 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC919 },
     91 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC919_1},
     92 	{ PCI_VENDOR_SYMBIOS,   PCI_PRODUCT_SYMBIOS_FC929X },
     93 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC919X },
     94 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC929X },
     95 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC939X },
     96 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_FC949X },
     97 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1064 },
     98 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1064A },
     99 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1064E },
    100 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1064E_2 },
    101 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1066 },
    102 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1066E },
    103 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1068 },
    104 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1068_2 },
    105 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1068E },
    106 	{ PCI_VENDOR_SYMBIOS,	PCI_PRODUCT_SYMBIOS_SAS1068E_2 },
    107 	{ 0,			0 }
    108 };
    109 
    110 static int
    111 mpt_pci_match(device_t parent, cfdata_t cf, void *aux)
    112 {
    113 	struct pci_attach_args *pa = aux;
    114 	const struct mpt_pci_product *mpp;
    115 
    116 	for (mpp = mpt_pci_products; mpp->mpp_vendor != 0; mpp++) {
    117 		if (PCI_VENDOR(pa->pa_id) == mpp->mpp_vendor &&
    118 		    PCI_PRODUCT(pa->pa_id) == mpp->mpp_product)
    119 			return (1);
    120 	}
    121 
    122 	return (0);
    123 }
    124 
    125 static void
    126 mpt_pci_attach(device_t parent, device_t self, void *aux)
    127 {
    128 	struct mpt_pci_softc *psc = device_private(self);
    129 	mpt_softc_t *mpt = &psc->sc_mpt;
    130 	struct pci_attach_args *pa = aux;
    131 	pci_intr_handle_t ih;
    132 	const char *intrstr;
    133 	pcireg_t reg, memtype;
    134 	bus_space_tag_t memt;
    135 	bus_space_handle_t memh;
    136 	int memh_valid;
    137 
    138 	pci_aprint_devinfo(pa, NULL);
    139 
    140 	psc->sc_pc = pa->pa_pc;
    141 	psc->sc_tag = pa->pa_tag;
    142 
    143 	mpt->sc_dmat = pa->pa_dmat;
    144 
    145 	/*
    146 	 * Map the device.
    147 	 */
    148 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, MPT_PCI_MMBA);
    149 	switch (memtype) {
    150 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
    151 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
    152 		memh_valid = (pci_mapreg_map(pa, MPT_PCI_MMBA,
    153 		    memtype, 0, &memt, &memh, NULL, NULL) == 0);
    154 		break;
    155 
    156 	default:
    157 		memh_valid = 0;
    158 	}
    159 
    160 	if (memh_valid) {
    161 		mpt->sc_st = memt;
    162 		mpt->sc_sh = memh;
    163 	} else {
    164 		aprint_error_dev(&mpt->sc_dev, "unable to map device registers\n");
    165 		return;
    166 	}
    167 
    168 	/*
    169 	 * Make sure the PCI command register is properly configured.
    170 	 */
    171 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    172 	reg |= PCI_COMMAND_MASTER_ENABLE;
    173 	/* XXX PCI_COMMAND_INVALIDATE_ENABLE */
    174 	/* XXX PCI_COMMAND_PARITY_ENABLE */
    175 	/* XXX PCI_COMMAND_SERR_ENABLE */
    176 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
    177 
    178 	/*
    179 	 * Disable split transactions on the 53c1020 and 53c1030 for
    180 	 * revisions older than 8.
    181 	 */
    182 	if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SYMBIOS_1030) &&
    183 	    (PCI_REVISION(pa->pa_class) < 0x08)) {
    184 		aprint_normal_dev(&mpt->sc_dev, "applying 1030 quirk\n");
    185 		reg = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x68);
    186 		reg &= 0x8fffff;
    187 		pci_conf_write(pa->pa_pc, pa->pa_tag, 0x68, reg);
    188 	}
    189 
    190 	/*
    191 	 * Ensure that the ROM is disabled.
    192 	 */
    193 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
    194 	reg &= ~1;
    195 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, reg);
    196 
    197 	/*
    198 	 * Map and establish our interrupt.
    199 	 */
    200 	if (pci_intr_map(pa, &ih) != 0) {
    201 		aprint_error_dev(&mpt->sc_dev, "unable to map interrupt\n");
    202 		return;
    203 	}
    204 	intrstr = pci_intr_string(pa->pa_pc, ih);
    205 	psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, mpt_intr, mpt);
    206 	if (psc->sc_ih == NULL) {
    207 		aprint_error_dev(&mpt->sc_dev, "unable to establish interrupt");
    208 		if (intrstr != NULL)
    209 			aprint_error(" at %s", intrstr);
    210 		aprint_error("\n");
    211 		return;
    212 	}
    213 	aprint_normal_dev(&mpt->sc_dev, "interrupting at %s\n",
    214 	    intrstr);
    215 
    216 	/* Disable interrupts on the part. */
    217 	mpt_disable_ints(mpt);
    218 
    219 	/* Allocate DMA memory. */
    220 	if (mpt_dma_mem_alloc(mpt) != 0) {
    221 		aprint_error_dev(&mpt->sc_dev, "unable to allocate DMA memory\n");
    222 		return;
    223 	}
    224 
    225 	/* Initialize the hardware. */
    226 	if (mpt_init(mpt, MPT_DB_INIT_HOST) != 0) {
    227 		/* Error message already printed. */
    228 		return;
    229 	}
    230 
    231 	/* Attach to scsipi. */
    232 	mpt_scsipi_attach(mpt);
    233 }
    234 
    235 CFATTACH_DECL(mpt_pci, sizeof(struct mpt_pci_softc),
    236     mpt_pci_match, mpt_pci_attach, NULL, NULL);
    237 
    238