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