Home | History | Annotate | Line # | Download | only in pci
adv_pci.c revision 1.4
      1 /*	$NetBSD: adv_pci.c,v 1.4 1998/08/31 17:15:25 dante Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
      5  *
      6  * Author: Baldassare Dante Profeta <dante (at) mclink.it>
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *        This product includes software developed by the NetBSD
     19  *        Foundation, Inc. and its contributors.
     20  * 4. Neither the name of The NetBSD Foundation nor the names of its
     21  *    contributors may be used to endorse or promote products derived
     22  *    from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  * POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 /*
     37  * Device probe and attach routines for the following
     38  * Advanced Systems Inc. SCSI controllers:
     39  *
     40  *    Connectivity Products:
     41  *      ABP920 - Bus-Master PCI (16 CDB)
     42  *      ABP930 - Bus-Master PCI (16 CDB)		(Footnote 2)
     43  *      ABP930U - Bus-Master PCI Ultra (16 CDB)
     44  *      ABP930UA - Bus-Master PCI Ultra (16 CDB)
     45  *      ABP960 - Bus-Master PCI MAC/PC (16 CDB)		(Footnote 1)
     46  *      ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB)	(Footnote 1)
     47  *
     48  *   Single Channel Products:
     49  *      ABP940 - Bus-Master PCI (240 CDB)
     50  *      ABP940U - Bus-Master PCI Ultra (240 CDB)
     51  *      ABP970 - Bus-Master PCI MAC/PC (240 CDB)
     52  *      ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB)
     53  *      ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
     54  *
     55  *   Multi Channel Products:
     56  *      ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel)
     57  *      ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel)
     58  *      ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel)
     59  *
     60  *   Footnotes:
     61  *     1. This board has been sold by Iomega as a Jaz Jet PCI adapter.
     62  *     2. This board has been sold by SIIG as the Fast SCSI Pro PCI.
     63  */
     64 
     65 #include <sys/types.h>
     66 #include <sys/param.h>
     67 #include <sys/systm.h>
     68 #include <sys/malloc.h>
     69 #include <sys/kernel.h>
     70 #include <sys/queue.h>
     71 #include <sys/device.h>
     72 
     73 #include <machine/bus.h>
     74 #include <machine/intr.h>
     75 
     76 #include <dev/scsipi/scsi_all.h>
     77 #include <dev/scsipi/scsipi_all.h>
     78 #include <dev/scsipi/scsiconf.h>
     79 
     80 #include <dev/pci/pcireg.h>
     81 #include <dev/pci/pcivar.h>
     82 #include <dev/pci/pcidevs.h>
     83 
     84 #include <dev/ic/adv.h>
     85 #include <dev/ic/advlib.h>
     86 
     87 /******************************************************************************/
     88 
     89 #define PCI_BASEADR_IO        0x10
     90 
     91 /******************************************************************************/
     92 
     93 int	adv_pci_match __P((struct device *, struct cfdata *, void *));
     94 void	adv_pci_attach __P((struct device *, struct device *, void *));
     95 
     96 struct cfattach adv_pci_ca =
     97 {
     98 	sizeof(ASC_SOFTC), adv_pci_match, adv_pci_attach
     99 };
    100 
    101 /******************************************************************************/
    102 /*
    103  * Check the slots looking for a board we recognise
    104  * If we find one, note it's address (slot) and call
    105  * the actual probe routine to check it out.
    106  */
    107 int
    108 adv_pci_match(parent, match, aux)
    109 	struct device *parent;
    110 	struct cfdata *match;
    111 	void *aux;
    112 {
    113 	struct pci_attach_args *pa = aux;
    114 
    115 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    116 		switch (PCI_PRODUCT(pa->pa_id)) {
    117 		case PCI_PRODUCT_ADVSYS_1200A:
    118 		case PCI_PRODUCT_ADVSYS_1200B:
    119 		case PCI_PRODUCT_ADVSYS_ULTRA:
    120 			return (1);
    121 		case PCI_PRODUCT_ADVSYS_2300:
    122 			return (0);
    123 		}
    124 
    125 	return 0;
    126 }
    127 
    128 
    129 void
    130 adv_pci_attach(parent, self, aux)
    131 	struct device *parent, *self;
    132 	void *aux;
    133 {
    134 	struct pci_attach_args *pa = aux;
    135 	ASC_SOFTC      *sc = (void *) self;
    136 	bus_space_tag_t iot;
    137 	bus_space_handle_t ioh;
    138 	pci_intr_handle_t ih;
    139 	pci_chipset_tag_t pc = pa->pa_pc;
    140 	u_int32_t       command;
    141 	const char     *intrstr;
    142 
    143 
    144 	sc->sc_flags = 0x0;
    145 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    146 		switch (PCI_PRODUCT(pa->pa_id)) {
    147 		case PCI_PRODUCT_ADVSYS_1200A:
    148 			printf(": AdvanSys ASC1200A SCSI adapter\n");
    149 			break;
    150 
    151 		case PCI_PRODUCT_ADVSYS_1200B:
    152 			printf(": AdvanSys ASC1200B SCSI adapter\n");
    153 			break;
    154 
    155 		case PCI_PRODUCT_ADVSYS_ULTRA:
    156 			switch (PCI_REVISION(pa->pa_class)) {
    157 			case ASC_PCI_REVISION_3050:
    158 				printf(": AdvanSys ABP-9xxUA SCSI adapter\n");
    159 				break;
    160 
    161 			case ASC_PCI_REVISION_3150:
    162 				printf(": AdvanSys ABP-9xxU SCSI adapter\n");
    163 				break;
    164 			}
    165 			break;
    166 
    167 		case PCI_PRODUCT_ADVSYS_2300:
    168 			sc->sc_flags |= ASC_WIDE_BOARD;
    169 			printf("adv_pci_attach: Wide boards are not"
    170 					" supported yet");
    171 			break;
    172 
    173 		default:
    174 			printf(": unknown model!\n");
    175 			return;
    176 		}
    177 
    178 
    179 	/*
    180 	 * Make sure IO/MEM/MASTER are enabled
    181 	 */
    182 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    183 	if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    184 			PCI_COMMAND_MASTER_ENABLE)) !=
    185 	    (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    186 	     PCI_COMMAND_MASTER_ENABLE)) {
    187 		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    188 		 command | (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    189 			    PCI_COMMAND_MASTER_ENABLE));
    190 	}
    191 	/*
    192 	 * Latency timer settings.
    193 	 */
    194 	{
    195 		u_int32_t       bhlcr;
    196 
    197 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    198 
    199 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A ||
    200 		    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) {
    201 			bhlcr &= 0xFFFF00FFul;
    202 			pci_conf_write(pa->pa_pc, pa->pa_tag,
    203 					PCI_BHLC_REG, bhlcr);
    204 		} else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) &&
    205 			   (PCI_LATTIMER(bhlcr) < 0x20)) {
    206 			bhlcr &= 0xFFFF00FFul;
    207 			bhlcr |= 0x00002000ul;
    208 			pci_conf_write(pa->pa_pc, pa->pa_tag,
    209 					PCI_BHLC_REG, bhlcr);
    210 		}
    211 	}
    212 
    213 
    214 	/*
    215 	 * Map Device Registers for I/O
    216 	 */
    217 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
    218 			&iot, &ioh, NULL, NULL)) {
    219 		printf("%s: unable to map device registers\n",
    220 		       sc->sc_dev.dv_xname);
    221 		return;
    222 	}
    223 	sc->sc_iot = iot;
    224 	sc->sc_ioh = ioh;
    225 	sc->sc_dmat = pa->pa_dmat;
    226 	sc->pci_device_id = pa->pa_id;
    227 	sc->bus_type = ASC_IS_PCI;
    228 
    229 	/*
    230 	 * Initialize the board
    231 	 */
    232 	if (adv_init(sc))
    233 		panic("adv_pci_attach: adv_init failed");
    234 
    235 	/*
    236 	 * Map Interrupt line
    237 	 */
    238 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    239 			 pa->pa_intrline, &ih)) {
    240 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    241 		return;
    242 	}
    243 	intrstr = pci_intr_string(pc, ih);
    244 
    245 	/*
    246 	 * Establish Interrupt handler
    247 	 */
    248 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc);
    249 	if (sc->sc_ih == NULL) {
    250 		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
    251 		if (intrstr != NULL)
    252 			printf(" at %s", intrstr);
    253 		printf("\n");
    254 		return;
    255 	}
    256 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    257 
    258 	/*
    259 	 * Attach all the sub-devices we can find
    260 	 */
    261 	adv_attach(sc);
    262 }
    263 /******************************************************************************/
    264