Annotation of sys/dev/pci/aac_pci.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: aac_pci.c,v 1.19 2006/06/29 21:34:51 deraadt 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_2, AAC_HWIF_I960RX },
! 116: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL,
! 117: PCI_PRODUCT_DELL_PERC_3DI_3, AAC_HWIF_I960RX },
! 118: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL,
! 119: PCI_PRODUCT_DELL_PERC_3DI_SUB2, AAC_HWIF_I960RX },
! 120: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI, PCI_VENDOR_DELL,
! 121: PCI_PRODUCT_DELL_PERC_3DI_SUB3, AAC_HWIF_I960RX },
! 122: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_2, PCI_VENDOR_DELL,
! 123: PCI_PRODUCT_DELL_PERC_3DI_2_SUB, AAC_HWIF_I960RX },
! 124: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL,
! 125: PCI_PRODUCT_DELL_PERC_3DI_3_SUB, AAC_HWIF_I960RX },
! 126: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL,
! 127: PCI_PRODUCT_DELL_PERC_3DI_3_SUB2, AAC_HWIF_I960RX },
! 128: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3DI_3, PCI_VENDOR_DELL,
! 129: PCI_PRODUCT_DELL_PERC_3DI_3_SUB3, AAC_HWIF_I960RX },
! 130: /* Dell PERC 3/Si models */
! 131: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3SI, PCI_VENDOR_DELL,
! 132: PCI_PRODUCT_DELL_PERC_3SI, AAC_HWIF_I960RX },
! 133: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_3SI_2, PCI_VENDOR_DELL,
! 134: PCI_PRODUCT_DELL_PERC_3SI_2_SUB, AAC_HWIF_I960RX },
! 135: /* Adaptec SATA RAID 2 channel XXX guess */
! 136: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 137: PCI_PRODUCT_ADP2_AACADPSATA2C, AAC_HWIF_I960RX },
! 138: /* Adaptec SATA RAID 4 channel */
! 139: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 140: PCI_PRODUCT_ADP2_AACADPSATA4C, AAC_HWIF_I960RX },
! 141: /* Adaptec SATA RAID 6 channel XXX guess */
! 142: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 143: PCI_PRODUCT_ADP2_AACADPSATA6C, AAC_HWIF_I960RX },
! 144: /* Adaptec SATA RAID 8 channel XXX guess */
! 145: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 146: PCI_PRODUCT_ADP2_AACADPSATA8C, AAC_HWIF_I960RX },
! 147: /* Adaptec SATA RAID 16 channel XXX guess */
! 148: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 149: PCI_PRODUCT_ADP2_AACADPSATA16C, AAC_HWIF_I960RX },
! 150: /* Dell CERC-SATA */
! 151: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_DELL,
! 152: PCI_PRODUCT_ADP2_AACCERCSATA6C, AAC_HWIF_I960RX },
! 153: /* Dell PERC 320/DC */
! 154: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_DELL,
! 155: PCI_PRODUCT_ADP2_AACPERC320DC, AAC_HWIF_I960RX },
! 156: /* Adaptec ADP-2622 */
! 157: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AAC2622, PCI_VENDOR_ADP2,
! 158: PCI_PRODUCT_ADP2_AAC2622, AAC_HWIF_I960RX },
! 159: /* Adaptec ADP-364 */
! 160: { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2,
! 161: PCI_PRODUCT_ADP2_AAC364, AAC_HWIF_STRONGARM },
! 162: /* Adaptec ADP-3642 */
! 163: { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2,
! 164: PCI_PRODUCT_ADP2_AAC3642, AAC_HWIF_STRONGARM },
! 165: /* Dell PERC 2/QC */
! 166: { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_ADP2,
! 167: PCI_PRODUCT_ADP2_PERC_2QC, AAC_HWIF_STRONGARM },
! 168: /* HP NetRAID-4M */
! 169: { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_CPQ42XX, PCI_VENDOR_HP,
! 170: PCI_PRODUCT_HP_NETRAID_4M, AAC_HWIF_STRONGARM },
! 171: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 172: PCI_PRODUCT_ADP2_ASR2120S, AAC_HWIF_I960RX },
! 173: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_ASR2200S, PCI_VENDOR_ADP2,
! 174: PCI_PRODUCT_ADP2_ASR2200S, AAC_HWIF_I960RX },
! 175: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2120S, PCI_VENDOR_ADP2,
! 176: PCI_PRODUCT_ADP2_AACASR2130S, AAC_HWIF_RKT },
! 177: { PCI_VENDOR_ADP2, PCI_PRODUCT_ADP2_AACASR2120S, PCI_VENDOR_ADP2,
! 178: PCI_PRODUCT_ADP2_AACASR2230S, AAC_HWIF_RKT },
! 179: { 0, 0, 0, 0 }
! 180: };
! 181:
! 182: struct cfattach aac_pci_ca = {
! 183: sizeof (struct aac_softc), aac_pci_probe, aac_pci_attach
! 184: };
! 185:
! 186: /*
! 187: * Determine whether this is one of our supported adapters.
! 188: */
! 189: int
! 190: aac_pci_probe(parent, match, aux)
! 191: struct device *parent;
! 192: void *match;
! 193: void *aux;
! 194: {
! 195: struct pci_attach_args *pa = aux;
! 196: struct aac_ident *m;
! 197: u_int32_t subsysid;
! 198:
! 199: for (m = aac_identifiers; m->vendor != 0; m++)
! 200: if (m->vendor == PCI_VENDOR(pa->pa_id) &&
! 201: m->device == PCI_PRODUCT(pa->pa_id)) {
! 202: subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag,
! 203: PCI_SUBSYS_ID_REG);
! 204: if (m->subvendor == PCI_VENDOR(subsysid) &&
! 205: m->subdevice == PCI_PRODUCT(subsysid))
! 206: return (1);
! 207: }
! 208: return (0);
! 209: }
! 210:
! 211: void
! 212: aac_pci_attach(parent, self, aux)
! 213: struct device *parent, *self;
! 214: void *aux;
! 215: {
! 216: struct pci_attach_args *pa = aux;
! 217: pci_chipset_tag_t pc = pa->pa_pc;
! 218: struct aac_softc *sc = (void *)self;
! 219: bus_addr_t membase;
! 220: bus_size_t memsize;
! 221: pci_intr_handle_t ih;
! 222: const char *intrstr;
! 223: int state = 0;
! 224: struct aac_ident *m;
! 225: struct aac_sub_ident *subid;
! 226: u_int32_t subsysid;
! 227:
! 228: printf(": ");
! 229: subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
! 230: if ((PCI_VENDOR(pa->pa_id) != PCI_VENDOR(subsysid)) ||
! 231: (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT(subsysid))) {
! 232: for (subid = aac_sub_identifiers; subid->subvendor != 0;
! 233: subid++) {
! 234: if (subid->subvendor == PCI_VENDOR(subsysid) &&
! 235: subid->subdevice == PCI_PRODUCT(subsysid)) {
! 236: printf("%s ", subid->desc);
! 237: break;
! 238: }
! 239: }
! 240: }
! 241:
! 242: /*
! 243: * Map control/status registers.
! 244: */
! 245: if (pci_mapreg_map(pa, PCI_MAPREG_START,
! 246: PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->aac_memt,
! 247: &sc->aac_memh, &membase, &memsize, AAC_REGSIZE)) {
! 248: printf("can't find mem space\n");
! 249: goto bail_out;
! 250: }
! 251: state++;
! 252:
! 253: if (pci_intr_map(pa, &ih)) {
! 254: printf("couldn't map interrupt\n");
! 255: goto bail_out;
! 256: }
! 257: intrstr = pci_intr_string(pc, ih);
! 258: sc->aac_ih = pci_intr_establish(pc, ih, IPL_BIO, aac_intr, sc,
! 259: sc->aac_dev.dv_xname);
! 260: if (sc->aac_ih == NULL) {
! 261: printf("couldn't establish interrupt");
! 262: if (intrstr != NULL)
! 263: printf(" at %s", intrstr);
! 264: printf("\n");
! 265: goto bail_out;
! 266: }
! 267: state++;
! 268: if (intrstr != NULL)
! 269: printf("%s\n", intrstr);
! 270:
! 271: sc->aac_dmat = pa->pa_dmat;
! 272:
! 273: for (m = aac_identifiers; m->vendor != 0; m++)
! 274: if (m->vendor == PCI_VENDOR(pa->pa_id) &&
! 275: m->device == PCI_PRODUCT(pa->pa_id)) {
! 276: if (m->subvendor == PCI_VENDOR(subsysid) &&
! 277: m->subdevice == PCI_PRODUCT(subsysid)) {
! 278: sc->aac_hwif = m->hwif;
! 279: switch(sc->aac_hwif) {
! 280: case AAC_HWIF_I960RX:
! 281: AAC_DPRINTF(AAC_D_MISC,
! 282: ("set hardware up for i960Rx"));
! 283: sc->aac_if = aac_rx_interface;
! 284: break;
! 285: case AAC_HWIF_STRONGARM:
! 286: AAC_DPRINTF(AAC_D_MISC,
! 287: ("set hardware up for StrongARM"));
! 288: sc->aac_if = aac_sa_interface;
! 289: break;
! 290: case AAC_HWIF_FALCON:
! 291: AAC_DPRINTF(AAC_D_MISC,
! 292: ("set hardware up for Falcon/PPC"));
! 293: sc->aac_if = aac_fa_interface;
! 294: break;
! 295: case AAC_HWIF_RKT:
! 296: AAC_DPRINTF(AAC_D_MISC,
! 297: ("set hardware up for Rocket/MIPS"));
! 298: sc->aac_if = aac_rkt_interface;
! 299: break;
! 300: default:
! 301: sc->aac_hwif = AAC_HWIF_UNKNOWN;
! 302: break;
! 303: }
! 304: break;
! 305: }
! 306: }
! 307:
! 308: if (aac_attach(sc))
! 309: goto bail_out;
! 310:
! 311: return;
! 312:
! 313: bail_out:
! 314: if (state > 1)
! 315: pci_intr_disestablish(pc, sc->aac_ih);
! 316: if (state > 0)
! 317: bus_space_unmap(sc->aac_memt, sc->aac_memh, memsize);
! 318: return;
! 319: }
CVSweb