Home | History | Annotate | Line # | Download | only in pci
adw_pci.c revision 1.8
      1 /* $NetBSD: adw_pci.c,v 1.8 2000/12/28 22:59:11 sommerfeld Exp $	 */
      2 
      3 /*
      4  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author: Baldassare Dante Profeta <dante (at) mclink.it>
      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 by the NetBSD
     20  *        Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND 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 THE FOUNDATION OR CONTRIBUTORS
     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  * Device probe and attach routines for the following
     39  * Advanced Systems Inc. SCSI controllers:
     40  *
     41  *      ABP-940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
     42  *	ABP-940UW (68)	- Bus-Master PCI Ultra-Wide (253 CDB)
     43  *	ABP-940UWD	- Bus-Master PCI Ultra-Wide (253 CDB)
     44  *	ABP-970UW	- Bus-Master PCI Ultra-Wide (253 CDB)
     45  *	ASB-3940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
     46  *	ASB-3940U2W-00	- Bus-Master PCI Ultra2-Wide (253 CDB)
     47  *	ASB-3940U3W-00	- Bus-Master PCI Ultra3-Wide (253 CDB)
     48  */
     49 
     50 #include <sys/types.h>
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/malloc.h>
     54 #include <sys/kernel.h>
     55 #include <sys/queue.h>
     56 #include <sys/device.h>
     57 
     58 #include <machine/bus.h>
     59 #include <machine/intr.h>
     60 
     61 #include <dev/scsipi/scsi_all.h>
     62 #include <dev/scsipi/scsipi_all.h>
     63 #include <dev/scsipi/scsiconf.h>
     64 
     65 #include <dev/pci/pcireg.h>
     66 #include <dev/pci/pcivar.h>
     67 #include <dev/pci/pcidevs.h>
     68 
     69 #include <dev/ic/adwlib.h>
     70 #include <dev/ic/adwmcode.h>
     71 #include <dev/ic/adw.h>
     72 
     73 /******************************************************************************/
     74 
     75 #define PCI_BASEADR_IO        0x10
     76 
     77 /******************************************************************************/
     78 
     79 static int adw_pci_match __P((struct device *, struct cfdata *, void *));
     80 static void adw_pci_attach __P((struct device *, struct device *, void *));
     81 
     82 struct cfattach adw_pci_ca =
     83 {
     84 	sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach
     85 };
     86 
     87 /******************************************************************************/
     88 /*
     89  * Check the slots looking for a board we recognise
     90  * If we find one, note it's address (slot) and call
     91  * the actual probe routine to check it out.
     92  */
     93 static int
     94 adw_pci_match(parent, match, aux)
     95 	struct device  *parent;
     96 	struct cfdata  *match;
     97 	void           *aux;
     98 {
     99 	struct pci_attach_args *pa = aux;
    100 
    101 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    102 		switch (PCI_PRODUCT(pa->pa_id)) {
    103 		case PCI_PRODUCT_ADVSYS_WIDE:
    104 		case PCI_PRODUCT_ADVSYS_U2W:
    105 		case PCI_PRODUCT_ADVSYS_U3W:
    106 			return (1);
    107 		}
    108 
    109 	return 0;
    110 }
    111 
    112 
    113 static void
    114 adw_pci_attach(parent, self, aux)
    115 	struct device  *parent, *self;
    116 	void           *aux;
    117 {
    118 	struct pci_attach_args *pa = aux;
    119 	ADW_SOFTC      *sc = (void *) self;
    120 	bus_space_tag_t iot;
    121 	bus_space_handle_t ioh;
    122 	pci_intr_handle_t ih;
    123 	pci_chipset_tag_t pc = pa->pa_pc;
    124 	u_int32_t       command;
    125 	const char     *intrstr;
    126 
    127 
    128 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    129 		switch (PCI_PRODUCT(pa->pa_id)) {
    130 		case PCI_PRODUCT_ADVSYS_WIDE:
    131 			sc->chip_type = ADW_CHIP_ASC3550;
    132 			printf(": AdvanSys ASB-3940UW-00 SCSI adapter\n");
    133 			break;
    134 
    135 		case PCI_PRODUCT_ADVSYS_U2W:
    136 			sc->chip_type = ADW_CHIP_ASC38C0800;
    137 			printf(": AdvanSys ASB-3940U2W-00 SCSI adapter\n");
    138 			break;
    139 
    140 		case PCI_PRODUCT_ADVSYS_U3W:
    141 			sc->chip_type = ADW_CHIP_ASC38C1600;
    142 			printf(": AdvanSys ASB-3940U3W-00 SCSI adapter\n");
    143 			break;
    144 
    145 		default:
    146 			printf(": unknown model!\n");
    147 			return;
    148 		}
    149 
    150 
    151 	/*
    152 	 * Make sure IO/MEM/MASTER are enabled
    153 	 */
    154 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    155 	command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    156 			PCI_COMMAND_MASTER_ENABLE;
    157 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
    158 
    159 	if ( (command & PCI_COMMAND_PARITY_ENABLE) == 0) {
    160 		sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
    161 	}
    162 	/*
    163 	 * Map Device Registers for I/O
    164 	 */
    165 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
    166 			   &iot, &ioh, NULL, NULL)) {
    167 		printf("%s: unable to map device registers\n",
    168 		       sc->sc_dev.dv_xname);
    169 		return;
    170 	}
    171 	sc->sc_iot = iot;
    172 	sc->sc_ioh = ioh;
    173 	sc->sc_dmat = pa->pa_dmat;
    174 
    175 	/*
    176 	 * Initialize the board
    177 	 */
    178 	if (adw_init(sc)) {
    179 		printf("%s: adw_init failed", sc->sc_dev.dv_xname);
    180 		return;
    181 	}
    182 
    183 	/*
    184 	 * Map Interrupt line
    185 	 */
    186 	if (pci_intr_map(pa, &ih)) {
    187 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    188 		return;
    189 	}
    190 	intrstr = pci_intr_string(pc, ih);
    191 
    192 	/*
    193 	 * Establish Interrupt handler
    194 	 */
    195 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc);
    196 	if (sc->sc_ih == NULL) {
    197 		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
    198 		if (intrstr != NULL)
    199 			printf(" at %s", intrstr);
    200 		printf("\n");
    201 		return;
    202 	}
    203 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    204 
    205 	/*
    206 	 * Attach all the sub-devices we can find
    207 	 */
    208 	adw_attach(sc);
    209 }
    210 /******************************************************************************/
    211