Annotation of sys/dev/pci/ami_pci.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: ami_pci.c,v 1.42 2007/01/27 05:09:51 dlg Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2001 Michael Shalayeff
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: *
! 16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 19: * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
! 20: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 21: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 22: * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 24: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
! 25: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
! 26: * THE POSSIBILITY OF SUCH DAMAGE.
! 27: */
! 28:
! 29: #include <sys/param.h>
! 30: #include <sys/systm.h>
! 31: #include <sys/kernel.h>
! 32: #include <sys/malloc.h>
! 33: #include <sys/device.h>
! 34: #include <sys/rwlock.h>
! 35:
! 36: #include <dev/pci/pcidevs.h>
! 37: #include <dev/pci/pcivar.h>
! 38:
! 39: #include <machine/bus.h>
! 40:
! 41: #include <scsi/scsi_all.h>
! 42: #include <scsi/scsi_disk.h>
! 43: #include <scsi/scsiconf.h>
! 44:
! 45: #include <dev/ic/amireg.h>
! 46: #include <dev/ic/amivar.h>
! 47:
! 48: #define AMI_BAR PCI_MAPREG_START
! 49: #define AMI_PCI_MEMSIZE 0x1000
! 50:
! 51: /* "Quartz" i960 Config space */
! 52: #define AMI_PCI_INIT 0x9c
! 53: #define AMI_INITSTAT(i) (((i) >> 8) & 0xff)
! 54: #define AMI_INITTARG(i) (((i) >> 16) & 0xff)
! 55: #define AMI_INITCHAN(i) (((i) >> 24) & 0xff)
! 56: #define AMI_PCI_SIG 0xa0
! 57: #define AMI_SIGNATURE_1 0xcccc /* older adapters */
! 58: #define AMI_SIGNATURE_2 0x3344 /* newer adapters */
! 59: #define AMI_PCI_SGL 0xa4
! 60: #define AMI_SGL_LHC 0x00000299
! 61: #define AMI_SGL_HLC 0x00000199
! 62:
! 63: int ami_pci_find_device(void *);
! 64: int ami_pci_match(struct device *, void *, void *);
! 65: void ami_pci_attach(struct device *, struct device *, void *);
! 66:
! 67: struct cfattach ami_pci_ca = {
! 68: sizeof(struct ami_softc), ami_pci_match, ami_pci_attach
! 69: };
! 70:
! 71: static const
! 72: struct ami_pci_device {
! 73: int vendor;
! 74: int product;
! 75: int flags;
! 76: } ami_pci_devices[] = {
! 77: { PCI_VENDOR_AMI, PCI_PRODUCT_AMI_MEGARAID, 0 },
! 78: { PCI_VENDOR_AMI, PCI_PRODUCT_AMI_MEGARAID428, AMI_BROKEN },
! 79: { PCI_VENDOR_AMI, PCI_PRODUCT_AMI_MEGARAID434, AMI_BROKEN },
! 80: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_4DI, 0 },
! 81: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_4DI_2, 0 },
! 82: { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_4EDI, 0 },
! 83: { PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_80960RP_ATU,
! 84: AMI_CHECK_SIGN | AMI_BROKEN },
! 85: { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID, 0 },
! 86: { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_320, 0 },
! 87: { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_3202E, 0 },
! 88: { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_SATA, 0 },
! 89: { 0 }
! 90: };
! 91:
! 92: static const
! 93: struct ami_pci_subsys {
! 94: pcireg_t id;
! 95: const char *name;
! 96: int flags;
! 97: } ami_pci_subsys[] = {
! 98: /* only those of a special name or quirk are listed here */
! 99: { 0x004d1025, "ACER MegaRAID ROMB-2E", 0},
! 100: { 0x0511101e, "AMI MegaRAID i4", AMI_BROKEN },
! 101: { 0x04931028, "Dell PERC3/DC", 0 },
! 102: { 0x05181028, "Dell PERC4/DC", 0 },
! 103: { 0x09a0101e, "Dell 466v1", 0 },
! 104: { 0x11111111, "Dell 466v2", 0 },
! 105: { 0x11121111, "Dell 438", 0 },
! 106: { 0x11111028, "Dell 466v3", 0 },
! 107: { 0x10651734, "FSC MegaRAID PCI Express ROMB", 0 },
! 108: { 0x10c6103c, "HP 438", 0 },
! 109: { 0x10c7103c, "HP T5/T6", 0 },
! 110: { 0x10cc103c, "HP T7", 0 },
! 111: { 0x10cd103c, "HP 466", 0 },
! 112: { 0x45231000, "LSI 523", 0 },
! 113: { 0x05328086, "Intel RAID SRCU42X", 0 },
! 114: { 0x05238086, "Intel RAID SRCS16", 0 },
! 115: { 0x00028086, "Intel RAID SRCU42E", 0 },
! 116: { 0x05308086, "Intel RAID SRCZCRX", 0 },
! 117: { 0x30088086, "Intel RAID SRCS28X", 0 },
! 118: { 0x34318086, "Intel RAID SROMBU42E", 0 },
! 119: { 0x34998086, "Intel RAID SROMBU42E", 0 },
! 120: { 0x05208086, "Intel RAID SRCU51L", 0 },
! 121: { 0x82871033, "NEC MegaRAID PCI Express ROMB", 0 },
! 122: { 0, NULL, 0 }
! 123: };
! 124:
! 125: static const
! 126: struct ami_pci_vendor {
! 127: u_int16_t id;
! 128: char name[8];
! 129: } ami_pci_vendors[] = {
! 130: { 0x101e, "AMI" },
! 131: { 0x1028, "Dell" },
! 132: { 0x103c, "HP" },
! 133: { 0x1000, "LSI" },
! 134: { 0x8086, "Intel" },
! 135: { 0 }
! 136: };
! 137:
! 138: int
! 139: ami_pci_find_device(void *aux)
! 140: {
! 141: struct pci_attach_args *pa = aux;
! 142: int i;
! 143:
! 144: for (i = 0; ami_pci_devices[i].vendor; i++) {
! 145: if (ami_pci_devices[i].vendor == PCI_VENDOR(pa->pa_id) &&
! 146: ami_pci_devices[i].product == PCI_PRODUCT(pa->pa_id)) {
! 147: #ifdef AMI_DEBUG
! 148: printf(" apfd %i ", i);
! 149: #endif /* AMI_DEBUG */
! 150: return (i);
! 151: }
! 152: }
! 153:
! 154: return (-1);
! 155: }
! 156:
! 157: int
! 158: ami_pci_match(struct device *parent, void *match, void *aux)
! 159: {
! 160: struct pci_attach_args *pa = aux;
! 161: pcireg_t sig;
! 162: int i;
! 163:
! 164: if (PCI_CLASS(pa->pa_class) == PCI_CLASS_I2O)
! 165: return (0);
! 166:
! 167: if ((i = ami_pci_find_device(aux)) != -1) {
! 168: #ifdef AMI_DEBUG
! 169: printf("\nvendor: %04x product: %04x\n",
! 170: ami_pci_devices[i].vendor,
! 171: ami_pci_devices[i].product);
! 172: #endif /* AMI_DEBUG */
! 173:
! 174: if (!(ami_pci_devices[i].flags & AMI_CHECK_SIGN))
! 175: return (1);
! 176: /* some cards have 0x11223344, but some only 16bit */
! 177: sig = pci_conf_read(pa->pa_pc, pa->pa_tag,
! 178: AMI_PCI_SIG) & 0xffff;
! 179: if (sig == AMI_SIGNATURE_1 ||
! 180: sig == AMI_SIGNATURE_2)
! 181: return (1);
! 182: }
! 183:
! 184: return (0);
! 185: }
! 186:
! 187: void
! 188: ami_pci_attach(struct device *parent, struct device *self, void *aux)
! 189: {
! 190: struct ami_softc *sc = (struct ami_softc *)self;
! 191: struct pci_attach_args *pa = aux;
! 192: pci_intr_handle_t ih;
! 193: const char *intrstr, *model = NULL, *lhc;
! 194: const struct ami_pci_subsys *ssp;
! 195: bus_size_t size;
! 196: pcireg_t csr;
! 197: int i;
! 198:
! 199: csr = pci_mapreg_type(pa->pa_pc, pa->pa_tag, AMI_BAR);
! 200: if (pci_mapreg_map(pa, AMI_BAR, csr, 0,
! 201: &sc->sc_iot, &sc->sc_ioh, NULL, &size, AMI_PCI_MEMSIZE)) {
! 202: printf(": can't map controller pci space\n");
! 203: return;
! 204: }
! 205:
! 206: if (PCI_MAPREG_TYPE(csr) == PCI_MAPREG_TYPE_IO) {
! 207: sc->sc_init = ami_schwartz_init;
! 208: sc->sc_exec = ami_schwartz_exec;
! 209: sc->sc_done = ami_schwartz_done;
! 210: sc->sc_poll = ami_schwartz_poll;
! 211: } else {
! 212: sc->sc_init = ami_quartz_init;
! 213: sc->sc_exec = ami_quartz_exec;
! 214: sc->sc_done = ami_quartz_done;
! 215: sc->sc_poll = ami_quartz_poll;
! 216: sc->sc_flags |= AMI_QUARTZ;
! 217: }
! 218: sc->sc_dmat = pa->pa_dmat;
! 219:
! 220: if (pci_intr_map(pa, &ih)) {
! 221: printf(": can't map interrupt\n");
! 222: bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
! 223: return;
! 224: }
! 225: intrstr = pci_intr_string(pa->pa_pc, ih);
! 226: sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ami_intr, sc,
! 227: sc->sc_dev.dv_xname);
! 228: if (!sc->sc_ih) {
! 229: printf(": can't establish interrupt");
! 230: if (intrstr)
! 231: printf(" at %s", intrstr);
! 232: printf("\n");
! 233: bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
! 234: return;
! 235: }
! 236:
! 237: printf(": %s\n", intrstr);
! 238:
! 239: csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
! 240: for (ssp = ami_pci_subsys; ssp->id; ssp++) {
! 241: if (ssp->id == csr) {
! 242: model = ssp->name;
! 243: sc->sc_flags |= ssp->flags;
! 244: break;
! 245: }
! 246: }
! 247:
! 248: if (!model && PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMI) {
! 249: switch (PCI_PRODUCT(pa->pa_id)) {
! 250: case PCI_PRODUCT_AMI_MEGARAID428:
! 251: model = "AMI 428";
! 252: break;
! 253: case PCI_PRODUCT_AMI_MEGARAID434:
! 254: model = "AMI 434";
! 255: break;
! 256: }
! 257: }
! 258:
! 259: /*
! 260: * XXX 438 is netraid 3si for hp cards, but we get to know
! 261: * they are hp too late in md code
! 262: */
! 263: if (!model) {
! 264: const struct ami_pci_vendor *vp;
! 265: static char modelbuf[32];
! 266:
! 267: for (vp = ami_pci_vendors;
! 268: vp->id && vp->id != (csr & 0xffff); vp++);
! 269: if (vp->id)
! 270: snprintf(modelbuf, sizeof(modelbuf), "%s %x", vp->name,
! 271: (csr >> 16) & 0xffff);
! 272: else
! 273: snprintf(modelbuf, sizeof(modelbuf), "unknown 0x%08x",
! 274: csr);
! 275: model = modelbuf;
! 276: }
! 277:
! 278: switch (pci_conf_read(pa->pa_pc, pa->pa_tag, AMI_PCI_SGL)) {
! 279: case AMI_SGL_LHC: lhc = "64b/lhc"; break;
! 280: case AMI_SGL_HLC: lhc = "64b/hlc"; break;
! 281: default: lhc = "32b";
! 282: }
! 283:
! 284: if ((i = ami_pci_find_device(aux)) != -1) {
! 285: if (ami_pci_devices[i].flags & AMI_BROKEN)
! 286: sc->sc_flags |= AMI_BROKEN;
! 287: } else {
! 288: /* this device existed at _match() should never happen */
! 289: panic("ami device dissapeared between match() and attach()");
! 290: }
! 291:
! 292: printf("%s: %s, %s", sc->sc_dev.dv_xname, model, lhc);
! 293:
! 294: if (ami_attach(sc)) {
! 295: pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
! 296: sc->sc_ih = NULL;
! 297: bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
! 298: }
! 299: }
CVSweb