1 /* $OpenBSD: adv_pci.c,v 1.13 2020/02/18 20:24:52 krw Exp $ */ 2 /* $NetBSD: adv_pci.c,v 1.5 1998/09/26 15:52:55 dante Exp $ */ 3 4 /* 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 6 * 7 * Author: Baldassare Dante Profeta <dante@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 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 /* 31 * Device probe and attach routines for the following 32 * Advanced Systems Inc. SCSI controllers: 33 * 34 * Connectivity Products: 35 * ABP920 - Bus-Master PCI (16 CDB) 36 * ABP930 - Bus-Master PCI (16 CDB) (Footnote 1) 37 * ABP930U - Bus-Master PCI Ultra (16 CDB) 38 * ABP930UA - Bus-Master PCI Ultra (16 CDB) 39 * ABP960 - Bus-Master PCI MAC/PC (16 CDB) (Footnote 2) 40 * ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB) (Footnote 2) 41 * 42 * Single Channel Products: 43 * ABP940 - Bus-Master PCI (240 CDB) 44 * ABP940U - Bus-Master PCI Ultra (240 CDB) 45 * ABP970 - Bus-Master PCI MAC/PC (240 CDB) 46 * ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB) 47 * 48 * Multi Channel Products: 49 * ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel) 50 * ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel) 51 * ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel) 52 * 53 * Footnotes: 54 * 1. This board has been sold by SIIG as the Fast SCSI Pro PCI. 55 * 2. This board has been sold by Iomega as a Jaz Jet PCI adapter. 56 */ 57 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/malloc.h> 61 #include <sys/kernel.h> 62 #include <sys/queue.h> 63 #include <sys/device.h> 64 65 #include <machine/bus.h> 66 #include <machine/intr.h> 67 68 #include <scsi/scsi_all.h> 69 #include <scsi/scsiconf.h> 70 71 #include <dev/pci/pcireg.h> 72 #include <dev/pci/pcivar.h> 73 #include <dev/pci/pcidevs.h> 74 75 #include <dev/ic/adv.h> 76 #include <dev/ic/advlib.h> 77 78 /******************************************************************************/ 79 80 #define PCI_CBIO 0x10 81 82 /******************************************************************************/ 83 84 int adv_pci_match(struct device *, void *, void *); 85 void adv_pci_attach(struct device *, struct device *, void *); 86 87 struct cfattach adv_pci_ca = 88 { 89 sizeof(ASC_SOFTC), adv_pci_match, adv_pci_attach 90 }; 91 92 const struct pci_matchid adv_pci_devices[] = { 93 { PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200A }, 94 { PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200B }, 95 { PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_ULTRA }, 96 }; 97 98 /******************************************************************************/ 99 /* 100 * Check the slots looking for a board we recognise 101 * If we find one, note its address (slot) and call 102 * the actual probe routine to check it out. 103 */ 104 int 105 adv_pci_match(parent, match, aux) 106 struct device *parent; 107 void *match, *aux; 108 { 109 return (pci_matchbyid((struct pci_attach_args *)aux, adv_pci_devices, 110 nitems(adv_pci_devices))); 111 } 112 113 114 void 115 adv_pci_attach(parent, self, aux) 116 struct device *parent, *self; 117 void *aux; 118 { 119 struct pci_attach_args *pa = aux; 120 ASC_SOFTC *sc = (void *) self; 121 bus_space_handle_t ioh; 122 bus_size_t advsize; 123 pci_intr_handle_t ih; 124 pci_chipset_tag_t pc = pa->pa_pc; 125 const char *intrstr; 126 int retval; 127 128 sc->sc_flags = 0x0; 129 130 /* 131 * Latency timer settings. 132 */ 133 { 134 u_int32_t bhlcr; 135 136 bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG); 137 138 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A || 139 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) { 140 bhlcr &= 0xFFFF00FFul; 141 pci_conf_write(pa->pa_pc, pa->pa_tag, 142 PCI_BHLC_REG, bhlcr); 143 } else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) && 144 (PCI_LATTIMER(bhlcr) < 0x20)) { 145 bhlcr &= 0xFFFF00FFul; 146 bhlcr |= 0x00002000ul; 147 pci_conf_write(pa->pa_pc, pa->pa_tag, 148 PCI_BHLC_REG, bhlcr); 149 } 150 } 151 152 153 /* 154 * Map Device Registers for I/O 155 */ 156 retval = pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 157 &sc->sc_iot, &ioh, NULL, &advsize, 0); 158 if (retval) { 159 printf(": unable to map device registers\n"); 160 return; 161 } 162 sc->sc_ioh = ioh; 163 sc->sc_dmat = pa->pa_dmat; 164 sc->pci_device_id = pa->pa_id; 165 sc->bus_type = ASC_IS_PCI; 166 167 /* 168 * Initialize the board 169 */ 170 if (adv_init(sc)) { 171 printf(": adv_init failed\n"); 172 bus_space_unmap(sc->sc_iot, ioh, advsize); 173 return; 174 } 175 176 /* 177 * Map Interrupt line 178 */ 179 if (pci_intr_map(pa, &ih)) { 180 printf(": couldn't map interrupt\n"); 181 bus_space_unmap(sc->sc_iot, ioh, advsize); 182 return; 183 } 184 intrstr = pci_intr_string(pc, ih); 185 186 /* 187 * Establish Interrupt handler 188 */ 189 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc, 190 sc->sc_dev.dv_xname); 191 if (sc->sc_ih == NULL) { 192 printf(": couldn't establish interrupt"); 193 if (intrstr != NULL) 194 printf(" at %s", intrstr); 195 printf("\n"); 196 bus_space_unmap(sc->sc_iot, ioh, advsize); 197 return; 198 } 199 printf(": %s\n", intrstr); 200 201 /* 202 * Attach all the sub-devices we can find 203 */ 204 adv_attach(sc); 205 } 206 /******************************************************************************/ 207