Home | History | Annotate | Line # | Download | only in pci
siop_pci.c revision 1.1
      1  1.1  bouyer /*	$NetBSD: siop_pci.c,v 1.1 2000/04/21 17:57:00 bouyer Exp $	*/
      2  1.1  bouyer 
      3  1.1  bouyer /*
      4  1.1  bouyer  * Copyright (c) 2000 Manuel Bouyer.
      5  1.1  bouyer  *
      6  1.1  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.1  bouyer  * modification, are permitted provided that the following conditions
      8  1.1  bouyer  * are met:
      9  1.1  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.1  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.1  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.1  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.1  bouyer  *    must display the following acknowledgement:
     16  1.1  bouyer  *	This product includes software developed by the University of
     17  1.1  bouyer  *	California, Berkeley and its contributors.
     18  1.1  bouyer  * 4. Neither the name of the University nor the names of its contributors
     19  1.1  bouyer  *    may be used to endorse or promote products derived from this software
     20  1.1  bouyer  *    without specific prior written permission.
     21  1.1  bouyer  *
     22  1.1  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  bouyer  * SUCH DAMAGE.
     33  1.1  bouyer  *
     34  1.1  bouyer  */
     35  1.1  bouyer 
     36  1.1  bouyer /* SYM53c8xx PCI-SCSI I/O Processors driver: PCI front-end */
     37  1.1  bouyer 
     38  1.1  bouyer #include <sys/param.h>
     39  1.1  bouyer #include <sys/systm.h>
     40  1.1  bouyer #include <sys/device.h>
     41  1.1  bouyer #include <sys/malloc.h>
     42  1.1  bouyer #include <sys/buf.h>
     43  1.1  bouyer #include <sys/kernel.h>
     44  1.1  bouyer 
     45  1.1  bouyer #include <machine/endian.h>
     46  1.1  bouyer 
     47  1.1  bouyer #include <dev/pci/pcireg.h>
     48  1.1  bouyer #include <dev/pci/pcivar.h>
     49  1.1  bouyer #include <dev/pci/pcidevs.h>
     50  1.1  bouyer 
     51  1.1  bouyer #include <dev/scsipi/scsipi_all.h>
     52  1.1  bouyer #include <dev/scsipi/scsipiconf.h>
     53  1.1  bouyer 
     54  1.1  bouyer #include <dev/ic/siopvar.h>
     55  1.1  bouyer 
     56  1.1  bouyer /* structure describing each chip */
     57  1.1  bouyer struct siop_product_desc {
     58  1.1  bouyer 	u_int32_t product;
     59  1.1  bouyer 	int	revision;
     60  1.1  bouyer 	const char *name;
     61  1.1  bouyer 	int	features; /* features are defined in siopvar.h */
     62  1.1  bouyer 	u_int8_t maxburst;
     63  1.1  bouyer 	u_int8_t maxoff;
     64  1.1  bouyer 	u_int8_t clock_div;
     65  1.1  bouyer };
     66  1.1  bouyer 
     67  1.1  bouyer /* List (array, really :) of chips we know how to handle */
     68  1.1  bouyer const struct siop_product_desc siop_products[] = {
     69  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     70  1.1  bouyer 	0x00,
     71  1.1  bouyer 	"Symbios Logic 53c810 (fast scsi)",
     72  1.1  bouyer 	SF_PCI_RL,
     73  1.1  bouyer 	4, 8, 4
     74  1.1  bouyer 	},
     75  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     76  1.1  bouyer 	0x10,
     77  1.1  bouyer 	"Symbios Logic 53c810a (fast scsi)",
     78  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_CHIP_PF,
     79  1.1  bouyer 	4, 8, 4
     80  1.1  bouyer 	},
     81  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_815,
     82  1.1  bouyer 	0x00,
     83  1.1  bouyer 	"Symbios Logic 53c815 (fast scsi)",
     84  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF,
     85  1.1  bouyer 	4, 8, 4
     86  1.1  bouyer 	},
     87  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_820,
     88  1.1  bouyer 	0x00,
     89  1.1  bouyer 	"Symbios Logic 53c820 (fast wide scsi)",
     90  1.1  bouyer 	SF_PCI_RL | SF_BUS_WIDE,
     91  1.1  bouyer 	4, 8, 4
     92  1.1  bouyer 	},
     93  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
     94  1.1  bouyer 	0x00,
     95  1.1  bouyer 	"Symbios Logic 53c825 (fast wide scsi)",
     96  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_BUS_WIDE,
     97  1.1  bouyer 	4, 8, 4
     98  1.1  bouyer 	},
     99  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
    100  1.1  bouyer 	0x10,
    101  1.1  bouyer 	"Symbios Logic 53c825a (fast wide scsi)",
    102  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    103  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
    104  1.1  bouyer 	SF_BUS_WIDE,
    105  1.1  bouyer 	7, 8, 4
    106  1.1  bouyer 	},
    107  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_860,
    108  1.1  bouyer 	0x00,
    109  1.1  bouyer 	"Symbios Logic 53c860 (ultra scsi)",
    110  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    111  1.1  bouyer 	SF_CHIP_PF | SF_CHIP_CLK80 |
    112  1.1  bouyer 	SF_BUS_ULTRA,
    113  1.1  bouyer 	4, 8, 5
    114  1.1  bouyer 	},
    115  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    116  1.1  bouyer 	0x00,
    117  1.1  bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    118  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    119  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_CLK80 |
    120  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    121  1.1  bouyer 	7, 16, 5
    122  1.1  bouyer 	},
    123  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    124  1.1  bouyer 	0x02,
    125  1.1  bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    126  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    127  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    128  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    129  1.1  bouyer 	7, 16, 5
    130  1.1  bouyer 	},
    131  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875J,
    132  1.1  bouyer 	0x00,
    133  1.1  bouyer 	"Symbios Logic 53c875j (ultra-wide scsi)",
    134  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    135  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    136  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    137  1.1  bouyer 	7, 16, 5
    138  1.1  bouyer 	},
    139  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_885,
    140  1.1  bouyer 	0x00,
    141  1.1  bouyer 	"Symbios Logic 53c885 (ultra-wide scsi)",
    142  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    143  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    144  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    145  1.1  bouyer 	7, 16, 5
    146  1.1  bouyer 	},
    147  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_895,
    148  1.1  bouyer 	0x00,
    149  1.1  bouyer 	"Symbios Logic 53c895 (ultra2-wide scsi)",
    150  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    151  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    152  1.1  bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    153  1.1  bouyer 	7, 31, 7
    154  1.1  bouyer 	},
    155  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_896,
    156  1.1  bouyer 	0x00,
    157  1.1  bouyer 	"Symbios Logic 53c896 (ultra2-wide scsi)",
    158  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    159  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    160  1.1  bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    161  1.1  bouyer 	7, 31, 7
    162  1.1  bouyer 	},
    163  1.1  bouyer 	{ 0,
    164  1.1  bouyer 	0x00,
    165  1.1  bouyer 	NULL,
    166  1.1  bouyer 	0x00,
    167  1.1  bouyer 	7, 31, 7
    168  1.1  bouyer 	},
    169  1.1  bouyer };
    170  1.1  bouyer 
    171  1.1  bouyer const struct siop_product_desc * siop_lookup_product __P((u_int32_t, int));
    172  1.1  bouyer 
    173  1.1  bouyer const struct siop_product_desc *
    174  1.1  bouyer siop_lookup_product(id, rev)
    175  1.1  bouyer 	u_int32_t id;
    176  1.1  bouyer 	int rev;
    177  1.1  bouyer {
    178  1.1  bouyer 	const struct siop_product_desc *pp;
    179  1.1  bouyer 	const struct siop_product_desc *rp = NULL;
    180  1.1  bouyer 	for (pp = siop_products; pp->name != NULL; pp++) {
    181  1.1  bouyer 		if (PCI_PRODUCT(id) == pp->product && pp->revision <= rev)
    182  1.1  bouyer 			if (rp == NULL || pp->revision > rp->revision)
    183  1.1  bouyer 				rp = pp;
    184  1.1  bouyer 	}
    185  1.1  bouyer 	return rp;
    186  1.1  bouyer }
    187  1.1  bouyer 
    188  1.1  bouyer /* Driver internal state */
    189  1.1  bouyer struct siop_pci_softc {
    190  1.1  bouyer 	struct siop_softc siop;
    191  1.1  bouyer 	pci_chipset_tag_t	sc_pc;	/* PCI registers info */
    192  1.1  bouyer 	pcitag_t		sc_tag;
    193  1.1  bouyer 	void			*sc_ih;	/* PCI interrupt handle */
    194  1.1  bouyer 	const struct siop_product_desc *sc_pp; /* Adapter description */
    195  1.1  bouyer };
    196  1.1  bouyer 
    197  1.1  bouyer int     siop_pci_match __P((struct device *, struct cfdata *, void *));
    198  1.1  bouyer void    siop_pci_attach __P((struct device *, struct device *, void *));
    199  1.1  bouyer 
    200  1.1  bouyer struct cfattach siop_pci_ca = {
    201  1.1  bouyer 	sizeof(struct siop_pci_softc), siop_pci_match, siop_pci_attach
    202  1.1  bouyer };
    203  1.1  bouyer 
    204  1.1  bouyer int
    205  1.1  bouyer siop_pci_match(parent, match, aux)
    206  1.1  bouyer 	struct device *parent;
    207  1.1  bouyer 	struct cfdata *match;
    208  1.1  bouyer 	void *aux;
    209  1.1  bouyer {
    210  1.1  bouyer 	struct pci_attach_args *pa = aux;
    211  1.1  bouyer 	const struct siop_product_desc *pp;
    212  1.1  bouyer 
    213  1.1  bouyer 	/* look if it's a known product */
    214  1.1  bouyer 	pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
    215  1.1  bouyer 	if (pp)
    216  1.1  bouyer 		return 1;
    217  1.1  bouyer 	return 0;
    218  1.1  bouyer }
    219  1.1  bouyer 
    220  1.1  bouyer void
    221  1.1  bouyer siop_pci_attach(parent, self, aux)
    222  1.1  bouyer 	struct device *parent, *self;
    223  1.1  bouyer 	void *aux;
    224  1.1  bouyer {
    225  1.1  bouyer 	struct pci_attach_args *pa = aux;
    226  1.1  bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    227  1.1  bouyer 	pcitag_t tag = pa->pa_tag;
    228  1.1  bouyer 	struct siop_pci_softc *sc = (struct siop_pci_softc *)self;
    229  1.1  bouyer 	const char *intrstr;
    230  1.1  bouyer 	pci_intr_handle_t intrhandle;
    231  1.1  bouyer 
    232  1.1  bouyer 	sc->sc_pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
    233  1.1  bouyer 	if (sc->sc_pp == NULL) {
    234  1.1  bouyer 		printf("sym: broken match/attach!!\n");
    235  1.1  bouyer 		return;
    236  1.1  bouyer 	}
    237  1.1  bouyer 	printf(": %s\n", sc->sc_pp->name);
    238  1.1  bouyer 	sc->sc_pc = pc;
    239  1.1  bouyer 	sc->sc_tag = tag;
    240  1.1  bouyer 	sc->siop.sc_dmat = pa->pa_dmat;
    241  1.1  bouyer 	if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0,
    242  1.1  bouyer 	    &sc->siop.sc_rt, &sc->siop.sc_rh, &sc->siop.sc_raddr, NULL) != 0) {
    243  1.1  bouyer 		/* Try to map memory addr */
    244  1.1  bouyer 		if (pci_mapreg_map(pa, 0x14,
    245  1.1  bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    246  1.1  bouyer 		    &sc->siop.sc_rt, &sc->siop.sc_rh,
    247  1.1  bouyer 			&sc->siop.sc_raddr, NULL) != 0) {
    248  1.1  bouyer 			printf("%s: unable to map device registers\n",
    249  1.1  bouyer 			    sc->siop.sc_dev.dv_xname);
    250  1.1  bouyer 		}
    251  1.1  bouyer 	}
    252  1.1  bouyer 	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    253  1.1  bouyer 	    pa->pa_intrline, &intrhandle) != 0) {
    254  1.1  bouyer 		printf("%s: couldn't map native-PCI interrupt\n",
    255  1.1  bouyer 		    sc->siop.sc_dev.dv_xname);
    256  1.1  bouyer 		return;
    257  1.1  bouyer 	}
    258  1.1  bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    259  1.1  bouyer 	sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_BIO,
    260  1.1  bouyer 	    siop_intr, &sc->siop);
    261  1.1  bouyer 	if (sc->sc_ih != NULL) {
    262  1.1  bouyer 		printf("%s: using %s for native-PCI interrupt\n",
    263  1.1  bouyer 		    sc->siop.sc_dev.dv_xname,
    264  1.1  bouyer 		    intrstr ? intrstr : "unknown interrupt");
    265  1.1  bouyer 	} else {
    266  1.1  bouyer 		printf("%s: couldn't establish interrupt",
    267  1.1  bouyer 		    sc->siop.sc_dev.dv_xname);
    268  1.1  bouyer 		if (intrstr != NULL)
    269  1.1  bouyer 			printf(" at %s", intrstr);
    270  1.1  bouyer 		printf("\n");
    271  1.1  bouyer 		return;
    272  1.1  bouyer 	}
    273  1.1  bouyer 	/* copy interesting infos about the chip */
    274  1.1  bouyer 	sc->siop.features = sc->sc_pp->features;
    275  1.1  bouyer 	sc->siop.maxburst = sc->sc_pp->maxburst;
    276  1.1  bouyer 	sc->siop.maxoff = sc->sc_pp->maxoff;
    277  1.1  bouyer 	sc->siop.clock_div = sc->sc_pp->clock_div;
    278  1.1  bouyer 	/* attach generic code */
    279  1.1  bouyer 	siop_attach(&sc->siop);
    280  1.1  bouyer }
    281