1 /* $OpenBSD: aac_pci.c,v 1.21 2008/06/03 10:32:19 brad Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 Michael Smith 5 * Copyright (c) 2000 BSDi 6 * Copyright (c) 2000 Niklas Hallqvist 7 * All rights reserved. 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD: /c/ncvs/src/sys/dev/aac/aac_pci.c,v 1.1 2000/09/13 03:20:34 msmith Exp $ 31 */ 32 33 /* 34 * This driver would not have rewritten for OpenBSD if it was not for the 35 * hardware donation from Nocom. I want to thank them for their support. 36 * Of course, credit should go to Mike Smith for the original work he did 37 * in the FreeBSD driver where I found lots of inspiration. 38 * - Niklas Hallqvist 39 */ 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/device.h> 44 #include <sys/kernel.h> 45 #include <sys/malloc.h> 46 #include <sys/queue.h> 47 #include <sys/selinfo.h> 48 #include <sys/rwlock.h> 49 50 #include <machine/bus.h> 51 #include <machine/endian.h> 52 #include <machine/intr.h> 53 54 #include <scsi/scsi_all.h> 55 #include <scsi/scsiconf.h> 56 57 #include <dev/pci/pcidevs.h> 58 #include <dev/pci/pcireg.h> 59 #include <dev/pci/pcivar.h> 60 61 #include <dev/ic/aacreg.h> 62 #include <dev/ic/aacvar.h> 63 64 int aac_pci_probe(struct device *, void *, void *); 65 void aac_pci_attach(struct device *, struct device *, void *); 66 67 /* Adaptec */ 68 #define PCI_PRODUCT_ADP2_AACASR2200S 0x0285 69 #define PCI_PRODUCT_ADP2_AACASR2120S 0x0286 70 #define PCI_PRODUCT_ADP2_AACADPSATA2C 0x0289 71 #define PCI_PRODUCT_ADP2_AACASR2230S 0x028c 72 #define PCI_PRODUCT_ADP2_AACASR2130S 0x028d 73 #define PCI_PRODUCT_ADP2_AACADPSATA4C 0x0290 74 #define PCI_PRODUCT_ADP2_AACADPSATA6C 0x0291 75 #define PCI_PRODUCT_ADP2_AACADPSATA8C 0x0292 76 #define PCI_PRODUCT_ADP2_AACADPSATA16C 0x0293 77 78 /* Dell */ 79 #define PCI_PRODUCT_ADP2_AACCERCSATA6C 0x0291 80 #define PCI_PRODUCT_ADP2_AACPERC320DC 0x0287 81 82 struct aac_sub_ident { 83 u_int16_t subvendor; 84 u_int16_t subdevice; 85 char *desc; 86 } aac_sub_identifiers[] = { 87 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACADPSATA2C, "Adaptec 1210SA" }, /* guess */ 88 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2130S, "Adaptec 2130S" }, 89 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2230S, "Adaptec 2230S" }, 90 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACADPSATA4C, "Adaptec 2410SA" }, 91 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACADPSATA6C, "Adaptec 2610SA" }, 92 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACADPSATA8C, "Adaptec 2810SA" }, /* guess */ 93 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACADPSATA16C, "Adaptec 21610SA" }, /* guess */ 94 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2120S, "Adaptec 2120S" }, 95 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2200S, "Adaptec 2200S" }, 96 { PCI_VENDOR_DELL, PCI_PRODUCT_ADP2_AACCERCSATA6C, "Dell CERC-SATA" }, 97 { PCI_VENDOR_DELL, PCI_PRODUCT_ADP2_AACPERC320DC, "Dell PERC 320/DC" }, 98 { 0, 0, "" } 99 }; 100 101 struct aac_ident { 102 u_int16_t vendor; 103 u_int16_t device; 104 u_int16_t subvendor; 105 u_int16_t subdevice; 106 int hwif; 107 } aac_identifiers[] = { 108 /* Dell PERC 2/Si models */ 109 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_2SI, PCI_VENDOR_DELL, 110 PCI_PRODUCT_DELL_PERC_2SI, AAC_HWIF_I960RX }, 111 /* Dell PERC 3/Di models */ 112 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL, 113 PCI_PRODUCT_DELL_PERC_3DI, AAC_HWIF_I960RX }, 114 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL, 115 PCI_PRODUCT_DELL_PERC_3DI_3, AAC_HWIF_I960RX }, 116 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL, 117 PCI_PRODUCT_DELL_PERC_3DI_SUB2, AAC_HWIF_I960RX }, 118 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL, 119 PCI_PRODUCT_DELL_PERC_3DI_SUB3, AAC_HWIF_I960RX }, 120 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL, 121 PCI_PRODUCT_DELL_PERC_3DI_3_SUB, AAC_HWIF_I960RX }, 122 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL, 123 PCI_PRODUCT_DELL_PERC_3DI_3_SUB2, AAC_HWIF_I960RX }, 124 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL, 125 PCI_PRODUCT_DELL_PERC_3DI_3_SUB3, AAC_HWIF_I960RX }, 126 /* Dell PERC 3/Si models */ 127 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3SI, PCI_VENDOR_DELL, 128 PCI_PRODUCT_DELL_PERC_3SI, AAC_HWIF_I960RX }, 129 { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3SI_2, PCI_VENDOR_DELL, 130 PCI_PRODUCT_DELL_PERC_3SI_2_SUB, AAC_HWIF_I960RX }, 131 /* Adaptec SATA RAID 2 channel XXX guess */ 132 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 133 PCI_PRODUCT_ADP2_AACADPSATA2C, AAC_HWIF_I960RX }, 134 /* Adaptec SATA RAID 4 channel */ 135 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 136 PCI_PRODUCT_ADP2_AACADPSATA4C, AAC_HWIF_I960RX }, 137 /* Adaptec SATA RAID 6 channel XXX guess */ 138 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 139 PCI_PRODUCT_ADP2_AACADPSATA6C, AAC_HWIF_I960RX }, 140 /* Adaptec SATA RAID 8 channel XXX guess */ 141 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 142 PCI_PRODUCT_ADP2_AACADPSATA8C, AAC_HWIF_I960RX }, 143 /* Adaptec SATA RAID 16 channel XXX guess */ 144 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 145 PCI_PRODUCT_ADP2_AACADPSATA16C, AAC_HWIF_I960RX }, 146 /* Dell CERC-SATA */ 147 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_DELL, 148 PCI_PRODUCT_ADP2_AACCERCSATA6C, AAC_HWIF_I960RX }, 149 /* Dell PERC 320/DC */ 150 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_DELL, 151 PCI_PRODUCT_ADP2_AACPERC320DC, AAC_HWIF_I960RX }, 152 /* Adaptec ADP-2622 */ 153 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AAC2622, PCI_VENDOR_ADP2, 154 PCI_PRODUCT_ADP2_AAC2622, AAC_HWIF_I960RX }, 155 /* Adaptec ADP-364 */ 156 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2, 157 PCI_PRODUCT_ADP2_AAC364, AAC_HWIF_STRONGARM }, 158 /* Adaptec ADP-3642 */ 159 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2, 160 PCI_PRODUCT_ADP2_AAC3642, AAC_HWIF_STRONGARM }, 161 /* Dell PERC 2/QC */ 162 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2, 163 PCI_PRODUCT_ADP2_PERC_2QC, AAC_HWIF_STRONGARM }, 164 /* HP NetRAID-4M */ 165 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_HP, 166 PCI_PRODUCT_HP_NETRAID_4M, AAC_HWIF_STRONGARM }, 167 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 168 PCI_PRODUCT_ADP2_ASR2120S, AAC_HWIF_I960RX }, 169 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2, 170 PCI_PRODUCT_ADP2_ASR2200S, AAC_HWIF_I960RX }, 171 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2120S, PCI_VENDOR_ADP2, 172 PCI_PRODUCT_ADP2_AACASR2130S, AAC_HWIF_RKT }, 173 { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2120S, PCI_VENDOR_ADP2, 174 PCI_PRODUCT_ADP2_AACASR2230S, AAC_HWIF_RKT }, 175 { 0, 0, 0, 0 } 176 }; 177 178 struct cfattach aac_pci_ca = { 179 sizeof (struct aac_softc), aac_pci_probe, aac_pci_attach 180 }; 181 182 /* 183 * Determine whether this is one of our supported adapters. 184 */ 185 int 186 aac_pci_probe(parent, match, aux) 187 struct device *parent; 188 void *match; 189 void *aux; 190 { 191 struct pci_attach_args *pa = aux; 192 struct aac_ident *m; 193 u_int32_t subsysid; 194 195 for (m = aac_identifiers; m->vendor != 0; m++) 196 if (m->vendor == PCI_VENDOR(pa->pa_id) && 197 m->device == PCI_PRODUCT(pa->pa_id)) { 198 subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag, 199 PCI_SUBSYS_ID_REG); 200 if (m->subvendor == PCI_VENDOR(subsysid) && 201 m->subdevice == PCI_PRODUCT(subsysid)) 202 return (1); 203 } 204 return (0); 205 } 206 207 void 208 aac_pci_attach(parent, self, aux) 209 struct device *parent, *self; 210 void *aux; 211 { 212 struct pci_attach_args *pa = aux; 213 pci_chipset_tag_t pc = pa->pa_pc; 214 struct aac_softc *sc = (void *)self; 215 bus_addr_t membase; 216 bus_size_t memsize; 217 pci_intr_handle_t ih; 218 const char *intrstr; 219 int state = 0; 220 struct aac_ident *m; 221 struct aac_sub_ident *subid; 222 u_int32_t subsysid; 223 pcireg_t memtype; 224 225 printf(": "); 226 subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG); 227 if ((PCI_VENDOR(pa->pa_id) != PCI_VENDOR(subsysid)) || 228 (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT(subsysid))) { 229 for (subid = aac_sub_identifiers; subid->subvendor != 0; 230 subid++) { 231 if (subid->subvendor == PCI_VENDOR(subsysid) && 232 subid->subdevice == PCI_PRODUCT(subsysid)) { 233 printf("%s ", subid->desc); 234 break; 235 } 236 } 237 } 238 239 /* 240 * Map control/status registers. 241 */ 242 memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START); 243 if (pci_mapreg_map(pa, PCI_MAPREG_START, memtype, 0, &sc->aac_memt, 244 &sc->aac_memh, &membase, &memsize, AAC_REGSIZE)) { 245 printf("can't find mem space\n"); 246 goto bail_out; 247 } 248 state++; 249 250 if (pci_intr_map(pa, &ih)) { 251 printf("couldn't map interrupt\n"); 252 goto bail_out; 253 } 254 intrstr = pci_intr_string(pc, ih); 255 sc->aac_ih = pci_intr_establish(pc, ih, IPL_BIO, aac_intr, sc, 256 sc->aac_dev.dv_xname); 257 if (sc->aac_ih == NULL) { 258 printf("couldn't establish interrupt"); 259 if (intrstr != NULL) 260 printf(" at %s", intrstr); 261 printf("\n"); 262 goto bail_out; 263 } 264 state++; 265 if (intrstr != NULL) 266 printf("%s\n", intrstr); 267 268 sc->aac_dmat = pa->pa_dmat; 269 270 for (m = aac_identifiers; m->vendor != 0; m++) 271 if (m->vendor == PCI_VENDOR(pa->pa_id) && 272 m->device == PCI_PRODUCT(pa->pa_id)) { 273 if (m->subvendor == PCI_VENDOR(subsysid) && 274 m->subdevice == PCI_PRODUCT(subsysid)) { 275 sc->aac_hwif = m->hwif; 276 switch(sc->aac_hwif) { 277 case AAC_HWIF_I960RX: 278 AAC_DPRINTF(AAC_D_MISC, 279 ("set hardware up for i960Rx")); 280 sc->aac_if = aac_rx_interface; 281 break; 282 case AAC_HWIF_STRONGARM: 283 AAC_DPRINTF(AAC_D_MISC, 284 ("set hardware up for StrongARM")); 285 sc->aac_if = aac_sa_interface; 286 break; 287 case AAC_HWIF_FALCON: 288 AAC_DPRINTF(AAC_D_MISC, 289 ("set hardware up for Falcon/PPC")); 290 sc->aac_if = aac_fa_interface; 291 break; 292 case AAC_HWIF_RKT: 293 AAC_DPRINTF(AAC_D_MISC, 294 ("set hardware up for Rocket/MIPS")); 295 sc->aac_if = aac_rkt_interface; 296 break; 297 default: 298 sc->aac_hwif = AAC_HWIF_UNKNOWN; 299 break; 300 } 301 break; 302 } 303 } 304 305 if (aac_attach(sc)) 306 goto bail_out; 307 308 return; 309 310 bail_out: 311 if (state > 1) 312 pci_intr_disestablish(pc, sc->aac_ih); 313 if (state > 0) 314 bus_space_unmap(sc->aac_memt, sc->aac_memh, memsize); 315 return; 316 } 317