1 /* $OpenBSD: adw_pci.c,v 1.9 2001/07/11 17:31:24 krw Exp $ */ 2 /* $NetBSD: adw_pci.c,v 1.7 2000/05/26 15:13:46 dante Exp $ */ 3 4 /* 5 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * Author: Baldassare Dante Profeta <dante@mclink.it> 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 /* 39 * Device probe and attach routines for the following 40 * Advanced Systems Inc. SCSI controllers: 41 * 42 * ABP-940UW - Bus-Master PCI Ultra-Wide (253 CDB) 43 * ABP-940UW (68) - Bus-Master PCI Ultra-Wide (253 CDB) 44 * ABP-940UWD - Bus-Master PCI Ultra-Wide (253 CDB) 45 * ABP-970UW - Bus-Master PCI Ultra-Wide (253 CDB) 46 * ASB-3940UW - Bus-Master PCI Ultra-Wide (253 CDB) 47 * ASB-3940U2W-00 - Bus-Master PCI Ultra2-Wide (253 CDB) 48 * ASB-3940U3W-00 - Bus-Master PCI Ultra3-Wide (253 CDB) 49 */ 50 51 #include <sys/types.h> 52 #include <sys/param.h> 53 #include <sys/systm.h> 54 #include <sys/malloc.h> 55 #include <sys/kernel.h> 56 #include <sys/queue.h> 57 #include <sys/device.h> 58 #include <sys/timeout.h> 59 60 #include <machine/bus.h> 61 #include <machine/intr.h> 62 63 #include <scsi/scsi_all.h> 64 #include <scsi/scsiconf.h> 65 66 #include <dev/pci/pcireg.h> 67 #include <dev/pci/pcivar.h> 68 #include <dev/pci/pcidevs.h> 69 70 #include <dev/ic/adwlib.h> 71 #include <dev/microcode/adw/adwmcode.h> 72 #include <dev/ic/adw.h> 73 74 /******************************************************************************/ 75 76 #define PCI_BASEADR_IO 0x10 77 78 /******************************************************************************/ 79 80 int adw_pci_match __P((struct device *, void *, void *)); 81 void adw_pci_attach __P((struct device *, struct device *, void *)); 82 83 struct cfattach adw_pci_ca = 84 { 85 sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach 86 }; 87 88 /******************************************************************************/ 89 /* 90 * Check the slots looking for a board we recognise 91 * If we find one, note it's address (slot) and call 92 * the actual probe routine to check it out. 93 */ 94 int 95 adw_pci_match(parent, match, aux) 96 struct device *parent; 97 void *match; 98 void *aux; 99 { 100 struct pci_attach_args *pa = aux; 101 102 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS) 103 switch (PCI_PRODUCT(pa->pa_id)) { 104 case PCI_PRODUCT_ADVSYS_WIDE: 105 case PCI_PRODUCT_ADVSYS_U2W: 106 case PCI_PRODUCT_ADVSYS_U3W: 107 return (1); 108 } 109 110 return 0; 111 } 112 113 114 void 115 adw_pci_attach(parent, self, aux) 116 struct device *parent, *self; 117 void *aux; 118 { 119 struct pci_attach_args *pa = aux; 120 ADW_SOFTC *sc = (void *) self; 121 bus_space_tag_t iot; 122 bus_space_handle_t ioh; 123 pci_intr_handle_t ih; 124 pci_chipset_tag_t pc = pa->pa_pc; 125 u_int32_t command; 126 const char *intrstr; 127 128 /* 129 * Set chip type 130 */ 131 switch (PCI_PRODUCT(pa->pa_id)) { 132 case PCI_PRODUCT_ADVSYS_WIDE: 133 sc->chip_type = ADW_CHIP_ASC3550; 134 break; 135 136 case PCI_PRODUCT_ADVSYS_U2W: 137 sc->chip_type = ADW_CHIP_ASC38C0800; 138 break; 139 140 case PCI_PRODUCT_ADVSYS_U3W: 141 sc->chip_type = ADW_CHIP_ASC38C1600; 142 break; 143 144 default: 145 printf("\n%s: unknown model: %d\n", sc->sc_dev.dv_xname, 146 PCI_PRODUCT(pa->pa_id)); 147 return; 148 } 149 150 /* 151 * Make sure IO/MEM/MASTER are enabled 152 */ 153 command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 154 command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | 155 PCI_COMMAND_MASTER_ENABLE; 156 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); 157 158 if ( (command & PCI_COMMAND_PARITY_ENABLE) == 0) { 159 sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR; 160 } 161 /* 162 * Map Device Registers for I/O 163 */ 164 if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0, 165 &iot, &ioh, NULL, NULL, 0)) { 166 printf("\n%s: unable to map device registers\n", 167 sc->sc_dev.dv_xname); 168 return; 169 } 170 sc->sc_iot = iot; 171 sc->sc_ioh = ioh; 172 sc->sc_dmat = pa->pa_dmat; 173 174 /* 175 * Initialize the board 176 */ 177 if (adw_init(sc)) { 178 printf("%s: adw_init failed", sc->sc_dev.dv_xname); 179 return; 180 } 181 182 /* 183 * Map Interrupt line 184 */ 185 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 186 pa->pa_intrline, &ih)) { 187 printf("\n%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 sc->sc_dev.dv_xname); 197 if (sc->sc_ih == NULL) { 198 printf("\n%s: couldn't establish interrupt", sc->sc_dev.dv_xname); 199 if (intrstr != NULL) 200 printf(" at %s", intrstr); 201 printf("\n"); 202 return; 203 } 204 printf(": %s\n", intrstr); 205 206 /* 207 * Attach all the sub-devices we can find 208 */ 209 adw_attach(sc); 210 } 211 /******************************************************************************/ 212