Home | History | Annotate | Line # | Download | only in pci
adw_pci.c revision 1.3
      1 /* $NetBSD: adw_pci.c,v 1.3 2000/02/03 20:28:26 dante 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  *   Single Channel Products:
     42  *      ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
     43  */
     44 
     45 #include <sys/types.h>
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/malloc.h>
     49 #include <sys/kernel.h>
     50 #include <sys/queue.h>
     51 #include <sys/device.h>
     52 
     53 #include <machine/bus.h>
     54 #include <machine/intr.h>
     55 
     56 #include <dev/scsipi/scsi_all.h>
     57 #include <dev/scsipi/scsipi_all.h>
     58 #include <dev/scsipi/scsiconf.h>
     59 
     60 #include <dev/pci/pcireg.h>
     61 #include <dev/pci/pcivar.h>
     62 #include <dev/pci/pcidevs.h>
     63 
     64 #include <dev/ic/adwlib.h>
     65 #include <dev/ic/adw.h>
     66 
     67 /******************************************************************************/
     68 
     69 #define PCI_BASEADR_IO        0x10
     70 
     71 /******************************************************************************/
     72 
     73 int adw_pci_match __P((struct device *, struct cfdata *, void *));
     74 void adw_pci_attach __P((struct device *, struct device *, void *));
     75 
     76 struct cfattach adw_pci_ca =
     77 {
     78 	sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach
     79 };
     80 
     81 /******************************************************************************/
     82 /*
     83  * Check the slots looking for a board we recognise
     84  * If we find one, note it's address (slot) and call
     85  * the actual probe routine to check it out.
     86  */
     87 int
     88 adw_pci_match(parent, match, aux)
     89 	struct device  *parent;
     90 	struct cfdata  *match;
     91 	void           *aux;
     92 {
     93 	struct pci_attach_args *pa = aux;
     94 
     95 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
     96 		switch (PCI_PRODUCT(pa->pa_id)) {
     97 		case PCI_PRODUCT_ADVSYS_WIDE:
     98 			return (1);
     99 		case PCI_PRODUCT_ADVSYS_U2W:
    100 			return (1);
    101 		}
    102 
    103 	return 0;
    104 }
    105 
    106 
    107 void
    108 adw_pci_attach(parent, self, aux)
    109 	struct device  *parent, *self;
    110 	void           *aux;
    111 {
    112 	struct pci_attach_args *pa = aux;
    113 	ADW_SOFTC      *sc = (void *) self;
    114 	bus_space_tag_t iot;
    115 	bus_space_handle_t ioh;
    116 	pci_intr_handle_t ih;
    117 	pci_chipset_tag_t pc = pa->pa_pc;
    118 	u_int32_t       command;
    119 	const char     *intrstr;
    120 
    121 
    122 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
    123 		switch (PCI_PRODUCT(pa->pa_id)) {
    124 		case PCI_PRODUCT_ADVSYS_WIDE:
    125 			sc->chip_type = ADV_CHIP_ASC3550;
    126 			printf(": AdvanSys ASB-3940UW-00 SCSI adapter\n");
    127 			break;
    128 
    129 		case PCI_PRODUCT_ADVSYS_U2W:
    130 			sc->chip_type = ADV_CHIP_ASC38C0800;
    131 			printf(": AdvanSys ASB-3940U2W SCSI adapter\n");
    132 			break;
    133 
    134 		default:
    135 			printf(": unknown model!\n");
    136 			return;
    137 		}
    138 
    139 
    140 	/*
    141 	 * Make sure IO/MEM/MASTER are enabled
    142 	 */
    143 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    144 	if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    145 			PCI_COMMAND_MASTER_ENABLE)) !=
    146 	    (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    147 	     PCI_COMMAND_MASTER_ENABLE)) {
    148 		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    149 		 command | (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    150 			    PCI_COMMAND_MASTER_ENABLE));
    151 	}
    152 	/*
    153 	 * Latency timer settings.
    154 	 */
    155 	{
    156 		u_int32_t       bhlcr;
    157 
    158 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
    159 
    160 		if( ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) ||
    161 		     (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_U2W)) &&
    162 		     (PCI_LATTIMER(bhlcr) < 0x20)) {
    163 			bhlcr &= 0xFFFF00FFUL;
    164 			bhlcr |= 0x00002000UL;
    165 			pci_conf_write(pa->pa_pc, pa->pa_tag,
    166 				       PCI_BHLC_REG, bhlcr);
    167 		}
    168 	}
    169 
    170 
    171 	if (((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) ||
    172 	     (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_U2W)) &&
    173 	     (command & PCI_COMMAND_PARITY_ENABLE) == 0) {
    174 		sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
    175 	}
    176 	/*
    177 	 * Map Device Registers for I/O
    178 	 */
    179 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
    180 			   &iot, &ioh, NULL, NULL)) {
    181 		printf("%s: unable to map device registers\n",
    182 		       sc->sc_dev.dv_xname);
    183 		return;
    184 	}
    185 	sc->sc_iot = iot;
    186 	sc->sc_ioh = ioh;
    187 	sc->sc_dmat = pa->pa_dmat;
    188 
    189 	/*
    190 	 * Initialize the board
    191 	 */
    192 	if (adw_init(sc))
    193 		panic("adw_pci_attach: adw_init failed");
    194 
    195 	/*
    196 	 * Map Interrupt line
    197 	 */
    198 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    199 			 pa->pa_intrline, &ih)) {
    200 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    201 		return;
    202 	}
    203 	intrstr = pci_intr_string(pc, ih);
    204 
    205 	/*
    206 	 * Establish Interrupt handler
    207 	 */
    208 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc);
    209 	if (sc->sc_ih == NULL) {
    210 		printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
    211 		if (intrstr != NULL)
    212 			printf(" at %s", intrstr);
    213 		printf("\n");
    214 		return;
    215 	}
    216 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    217 
    218 	/*
    219 	 * Attach all the sub-devices we can find
    220 	 */
    221 	adw_attach(sc);
    222 }
    223 /******************************************************************************/
    224