Home | History | Annotate | Line # | Download | only in pci
siop_pci_common.c revision 1.2
      1  1.2  bouyer /*	$NetBSD: siop_pci_common.c,v 1.2 2000/05/25 10:10:56 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 Manuel Bouyer
     17  1.1  bouyer  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  bouyer  *    derived from this software without specific prior written permission.
     19  1.1  bouyer  *
     20  1.1  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  bouyer  */
     31  1.1  bouyer 
     32  1.1  bouyer /* SYM53c8xx PCI-SCSI I/O Processors driver: PCI front-end */
     33  1.1  bouyer 
     34  1.1  bouyer #include <sys/param.h>
     35  1.1  bouyer #include <sys/systm.h>
     36  1.1  bouyer #include <sys/device.h>
     37  1.1  bouyer #include <sys/malloc.h>
     38  1.1  bouyer #include <sys/buf.h>
     39  1.1  bouyer #include <sys/kernel.h>
     40  1.1  bouyer 
     41  1.1  bouyer #include <machine/endian.h>
     42  1.1  bouyer 
     43  1.1  bouyer #include <dev/pci/pcireg.h>
     44  1.1  bouyer #include <dev/pci/pcivar.h>
     45  1.1  bouyer #include <dev/pci/pcidevs.h>
     46  1.1  bouyer 
     47  1.1  bouyer #include <dev/scsipi/scsipi_all.h>
     48  1.1  bouyer #include <dev/scsipi/scsipiconf.h>
     49  1.1  bouyer 
     50  1.1  bouyer #include <dev/ic/siopreg.h>
     51  1.1  bouyer #include <dev/ic/siopvar.h>
     52  1.1  bouyer #include <dev/pci/siop_pci_common.h>
     53  1.1  bouyer 
     54  1.1  bouyer /* List (array, really :) of chips we know how to handle */
     55  1.1  bouyer const struct siop_product_desc siop_products[] = {
     56  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     57  1.1  bouyer 	0x00,
     58  1.1  bouyer 	"Symbios Logic 53c810 (fast scsi)",
     59  1.1  bouyer 	SF_PCI_RL | SF_CHIP_LS,
     60  1.1  bouyer 	4, 8, 3, 250
     61  1.1  bouyer 	},
     62  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_810,
     63  1.1  bouyer 	0x10,
     64  1.1  bouyer 	"Symbios Logic 53c810a (fast scsi)",
     65  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_CHIP_PF | SF_CHIP_LS,
     66  1.1  bouyer 	4, 8, 3, 250
     67  1.1  bouyer 	},
     68  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_815,
     69  1.1  bouyer 	0x00,
     70  1.1  bouyer 	"Symbios Logic 53c815 (fast scsi)",
     71  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF,
     72  1.1  bouyer 	4, 8, 3, 250
     73  1.1  bouyer 	},
     74  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_820,
     75  1.1  bouyer 	0x00,
     76  1.1  bouyer 	"Symbios Logic 53c820 (fast wide scsi)",
     77  1.1  bouyer 	SF_PCI_RL | SF_CHIP_LS | SF_BUS_WIDE,
     78  1.1  bouyer 	4, 8, 3, 250
     79  1.1  bouyer 	},
     80  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
     81  1.1  bouyer 	0x00,
     82  1.1  bouyer 	"Symbios Logic 53c825 (fast wide scsi)",
     83  1.1  bouyer 	SF_PCI_RL | SF_PCI_BOF | SF_BUS_WIDE,
     84  1.1  bouyer 	4, 8, 3, 250
     85  1.1  bouyer 	},
     86  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_825,
     87  1.1  bouyer 	0x10,
     88  1.1  bouyer 	"Symbios Logic 53c825a (fast wide scsi)",
     89  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
     90  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_LS | SF_CHIP_10REGS |
     91  1.1  bouyer 	SF_BUS_WIDE,
     92  1.1  bouyer 	7, 8, 3, 250
     93  1.1  bouyer 	},
     94  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_860,
     95  1.1  bouyer 	0x00,
     96  1.1  bouyer 	"Symbios Logic 53c860 (ultra scsi)",
     97  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
     98  1.1  bouyer 	SF_CHIP_PF | SF_CHIP_LS |
     99  1.1  bouyer 	SF_BUS_ULTRA,
    100  1.1  bouyer 	4, 8, 5, 125
    101  1.1  bouyer 	},
    102  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    103  1.1  bouyer 	0x00,
    104  1.1  bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    105  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    106  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_LS | SF_CHIP_10REGS |
    107  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    108  1.1  bouyer 	7, 16, 5, 125
    109  1.1  bouyer 	},
    110  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875,
    111  1.1  bouyer 	0x02,
    112  1.1  bouyer 	"Symbios Logic 53c875 (ultra-wide scsi)",
    113  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    114  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    115  1.1  bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    116  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    117  1.1  bouyer 	7, 16, 5, 125
    118  1.1  bouyer 	},
    119  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_875J,
    120  1.1  bouyer 	0x00,
    121  1.1  bouyer 	"Symbios Logic 53c875j (ultra-wide scsi)",
    122  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    123  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    124  1.1  bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    125  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    126  1.1  bouyer 	7, 16, 5, 125
    127  1.1  bouyer 	},
    128  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_885,
    129  1.1  bouyer 	0x00,
    130  1.1  bouyer 	"Symbios Logic 53c885 (ultra-wide scsi)",
    131  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    132  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
    133  1.1  bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    134  1.1  bouyer 	SF_BUS_ULTRA | SF_BUS_WIDE,
    135  1.1  bouyer 	7, 16, 5, 125
    136  1.1  bouyer 	},
    137  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_895,
    138  1.1  bouyer 	0x00,
    139  1.1  bouyer 	"Symbios Logic 53c895 (ultra2-wide scsi)",
    140  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    141  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    142  1.1  bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    143  1.1  bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    144  1.1  bouyer 	7, 31, 7, 62
    145  1.1  bouyer 	},
    146  1.1  bouyer 	{ PCI_PRODUCT_SYMBIOS_896,
    147  1.1  bouyer 	0x00,
    148  1.1  bouyer 	"Symbios Logic 53c896 (ultra2-wide scsi)",
    149  1.1  bouyer 	SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
    150  1.1  bouyer 	SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
    151  1.1  bouyer 	SF_CHIP_LS | SF_CHIP_10REGS |
    152  1.1  bouyer 	SF_BUS_ULTRA2 | SF_BUS_WIDE,
    153  1.1  bouyer 	7, 31, 7, 62
    154  1.1  bouyer 	},
    155  1.1  bouyer 	{ 0,
    156  1.1  bouyer 	0x00,
    157  1.1  bouyer 	NULL,
    158  1.1  bouyer 	0x00,
    159  1.1  bouyer 	0, 0, 0, 0
    160  1.1  bouyer 	},
    161  1.1  bouyer };
    162  1.1  bouyer 
    163  1.1  bouyer const struct siop_product_desc *
    164  1.1  bouyer siop_lookup_product(id, rev)
    165  1.1  bouyer 	u_int32_t id;
    166  1.1  bouyer 	int rev;
    167  1.1  bouyer {
    168  1.1  bouyer 	const struct siop_product_desc *pp;
    169  1.1  bouyer 	const struct siop_product_desc *rp = NULL;
    170  1.1  bouyer 
    171  1.1  bouyer 	if (PCI_VENDOR(id) != PCI_VENDOR_SYMBIOS)
    172  1.1  bouyer 		return NULL;
    173  1.1  bouyer 
    174  1.1  bouyer 	for (pp = siop_products; pp->name != NULL; pp++) {
    175  1.1  bouyer 		if (PCI_PRODUCT(id) == pp->product && pp->revision <= rev)
    176  1.1  bouyer 			if (rp == NULL || pp->revision > rp->revision)
    177  1.1  bouyer 				rp = pp;
    178  1.1  bouyer 	}
    179  1.1  bouyer 	return rp;
    180  1.1  bouyer }
    181  1.1  bouyer 
    182  1.1  bouyer int
    183  1.1  bouyer siop_pci_attach_common(sc, pa)
    184  1.1  bouyer 	struct siop_pci_softc *sc;
    185  1.1  bouyer 	struct pci_attach_args *pa;
    186  1.1  bouyer {
    187  1.1  bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    188  1.1  bouyer 	pcitag_t tag = pa->pa_tag;
    189  1.1  bouyer 	const char *intrstr;
    190  1.1  bouyer 	pci_intr_handle_t intrhandle;
    191  1.1  bouyer 	bus_space_tag_t iot, memt;
    192  1.1  bouyer 	bus_space_handle_t ioh, memh;
    193  1.1  bouyer 	pcireg_t memtype;
    194  1.1  bouyer 	int memh_valid, ioh_valid;
    195  1.1  bouyer 	bus_addr_t ioaddr, memaddr;
    196  1.1  bouyer 
    197  1.1  bouyer 	sc->sc_pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
    198  1.1  bouyer 	if (sc->sc_pp == NULL) {
    199  1.1  bouyer 		printf("sym: broken match/attach!!\n");
    200  1.1  bouyer 		return 0;
    201  1.1  bouyer 	}
    202  1.2  bouyer 	/* copy interesting infos about the chip */
    203  1.2  bouyer 	sc->siop.features = sc->sc_pp->features;
    204  1.2  bouyer 	sc->siop.maxburst = sc->sc_pp->maxburst;
    205  1.2  bouyer 	sc->siop.maxoff = sc->sc_pp->maxoff;
    206  1.2  bouyer 	sc->siop.clock_div = sc->sc_pp->clock_div;
    207  1.2  bouyer 	sc->siop.clock_period = sc->sc_pp->clock_period;
    208  1.2  bouyer 
    209  1.2  bouyer 	sc->siop.sc_reset = siop_pci_reset;
    210  1.1  bouyer 	printf(": %s\n", sc->sc_pp->name);
    211  1.1  bouyer 	sc->sc_pc = pc;
    212  1.1  bouyer 	sc->sc_tag = tag;
    213  1.1  bouyer 	sc->siop.sc_dmat = pa->pa_dmat;
    214  1.1  bouyer 
    215  1.1  bouyer 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, 0x14);
    216  1.1  bouyer 	switch (memtype) {
    217  1.1  bouyer 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
    218  1.1  bouyer 	case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
    219  1.1  bouyer 		memh_valid = (pci_mapreg_map(pa, 0x14, memtype, 0,
    220  1.1  bouyer 		    &memt, &memh, &memaddr, NULL) == 0);
    221  1.1  bouyer 		break;
    222  1.1  bouyer 	default:
    223  1.1  bouyer 		memh_valid = 0;
    224  1.1  bouyer 	}
    225  1.1  bouyer 
    226  1.1  bouyer 	ioh_valid = (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0,
    227  1.1  bouyer 	    &iot, &ioh, &ioaddr, NULL) == 0);
    228  1.1  bouyer 
    229  1.1  bouyer 	if (memh_valid) {
    230  1.1  bouyer 		sc->siop.sc_rt = memt;
    231  1.1  bouyer 		sc->siop.sc_rh = memh;
    232  1.1  bouyer 		sc->siop.sc_raddr = memaddr;
    233  1.1  bouyer 	} else if (ioh_valid) {
    234  1.1  bouyer 		sc->siop.sc_rt = iot;
    235  1.1  bouyer 		sc->siop.sc_rh = ioh;
    236  1.1  bouyer 		sc->siop.sc_raddr = ioaddr;
    237  1.1  bouyer 	} else {
    238  1.1  bouyer 		printf("%s: unable to map device registers\n",
    239  1.1  bouyer 		    sc->siop.sc_dev.dv_xname);
    240  1.1  bouyer 		return 0;
    241  1.1  bouyer 	}
    242  1.1  bouyer 
    243  1.2  bouyer 	if (sc->siop.features & SF_CHIP_RAM) {
    244  1.2  bouyer 		if (pci_mapreg_map(pa, 0x18,
    245  1.2  bouyer 		    PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
    246  1.2  bouyer                     &sc->siop.sc_ramt, &sc->siop.sc_ramh,
    247  1.2  bouyer 		    &sc->siop.sc_scriptaddr, NULL) == 0) {
    248  1.2  bouyer 			printf("%s: using on-board RAM\n",
    249  1.2  bouyer 			    sc->siop.sc_dev.dv_xname);
    250  1.2  bouyer 		} else {
    251  1.2  bouyer 			printf("%s: can't map on-board RAM\n",
    252  1.2  bouyer 			    sc->siop.sc_dev.dv_xname);
    253  1.2  bouyer 			sc->siop.features &= ~SF_CHIP_RAM;
    254  1.2  bouyer 		}
    255  1.2  bouyer 	}
    256  1.2  bouyer 
    257  1.1  bouyer 	if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
    258  1.1  bouyer 	    pa->pa_intrline, &intrhandle) != 0) {
    259  1.1  bouyer 		printf("%s: couldn't map interrupt\n",
    260  1.1  bouyer 		    sc->siop.sc_dev.dv_xname);
    261  1.1  bouyer 		return 0;
    262  1.1  bouyer 	}
    263  1.1  bouyer 	intrstr = pci_intr_string(pa->pa_pc, intrhandle);
    264  1.1  bouyer 	sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_BIO,
    265  1.1  bouyer 	    siop_intr, &sc->siop);
    266  1.1  bouyer 	if (sc->sc_ih != NULL) {
    267  1.1  bouyer 		printf("%s: interrupting at %s\n",
    268  1.1  bouyer 		    sc->siop.sc_dev.dv_xname,
    269  1.1  bouyer 		    intrstr ? intrstr : "unknown interrupt");
    270  1.1  bouyer 	} else {
    271  1.1  bouyer 		printf("%s: couldn't establish interrupt",
    272  1.1  bouyer 		    sc->siop.sc_dev.dv_xname);
    273  1.1  bouyer 		if (intrstr != NULL)
    274  1.1  bouyer 			printf(" at %s", intrstr);
    275  1.1  bouyer 		printf("\n");
    276  1.1  bouyer 		return 0;
    277  1.1  bouyer 	}
    278  1.1  bouyer 	return 1;
    279  1.1  bouyer }
    280  1.1  bouyer 
    281  1.1  bouyer void
    282  1.1  bouyer siop_pci_reset(sc)
    283  1.1  bouyer 	struct siop_softc *sc;
    284  1.1  bouyer {
    285  1.1  bouyer 	int dmode;
    286  1.1  bouyer 
    287  1.1  bouyer 	dmode = bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_DMODE);
    288  1.1  bouyer 	if (sc->features & SF_PCI_RL)
    289  1.1  bouyer 		dmode |= DMODE_ERL;
    290  1.1  bouyer 	if (sc->features & SF_PCI_RM)
    291  1.1  bouyer 		dmode |= DMODE_ERMP;
    292  1.1  bouyer 	if (sc->features & SF_PCI_BOF)
    293  1.1  bouyer 		dmode |= DMODE_BOF;
    294  1.1  bouyer 	if (sc->features & SF_PCI_CLS)
    295  1.1  bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DCNTL,
    296  1.1  bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_DCNTL) |
    297  1.1  bouyer 		    DCNTL_CLSE);
    298  1.1  bouyer 	if (sc->features & SF_PCI_WRI)
    299  1.1  bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3,
    300  1.1  bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST3) |
    301  1.1  bouyer 		    CTEST3_WRIE);
    302  1.1  bouyer 	if (sc->maxburst) {
    303  1.1  bouyer 		int ctest5 = bus_space_read_1(sc->sc_rt, sc->sc_rh,
    304  1.1  bouyer 		    SIOP_CTEST5);
    305  1.1  bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4,
    306  1.1  bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4) &
    307  1.1  bouyer 		    ~CTEST4_BDIS);
    308  1.1  bouyer 		dmode &= ~DMODE_BL_MASK;
    309  1.1  bouyer 		dmode |= ((sc->maxburst - 1) << DMODE_BL_SHIFT) & DMODE_BL_MASK;
    310  1.1  bouyer 		ctest5 &= ~CTEST5_BBCK;
    311  1.1  bouyer 		ctest5 |= (sc->maxburst - 1) & CTEST5_BBCK;
    312  1.1  bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST5, ctest5);
    313  1.1  bouyer 	} else {
    314  1.1  bouyer 		bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4,
    315  1.1  bouyer 		    bus_space_read_1(sc->sc_rt, sc->sc_rh, SIOP_CTEST4) |
    316  1.1  bouyer 		    CTEST4_BDIS);
    317  1.1  bouyer 	}
    318  1.1  bouyer 	bus_space_write_1(sc->sc_rt, sc->sc_rh, SIOP_DMODE, dmode);
    319  1.1  bouyer }
    320