mfi_pci.c revision 1.4 1 1.4 xtraeme /* $NetBSD: mfi_pci.c,v 1.4 2008/02/25 10:46:02 xtraeme Exp $ */
2 1.1 bouyer /* $OpenBSD: mfi_pci.c,v 1.11 2006/08/06 04:40:08 brad Exp $ */
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2006 Marco Peereboom <marco (at) peereboom.us>
5 1.1 bouyer *
6 1.1 bouyer * Permission to use, copy, modify, and distribute this software for any
7 1.1 bouyer * purpose with or without fee is hereby granted, provided that the above
8 1.1 bouyer * copyright notice and this permission notice appear in all copies.
9 1.1 bouyer *
10 1.1 bouyer * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 1.1 bouyer * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 1.1 bouyer * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 1.1 bouyer * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 1.1 bouyer * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 1.1 bouyer * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 1.1 bouyer * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 1.1 bouyer */
18 1.1 bouyer
19 1.2 bouyer #include <sys/cdefs.h>
20 1.4 xtraeme __KERNEL_RCSID(0, "$NetBSD: mfi_pci.c,v 1.4 2008/02/25 10:46:02 xtraeme Exp $");
21 1.2 bouyer
22 1.1 bouyer #include <sys/param.h>
23 1.1 bouyer #include <sys/systm.h>
24 1.1 bouyer #include <sys/kernel.h>
25 1.1 bouyer #include <sys/malloc.h>
26 1.1 bouyer #include <sys/device.h>
27 1.1 bouyer
28 1.1 bouyer #include <dev/pci/pcidevs.h>
29 1.1 bouyer #include <dev/pci/pcivar.h>
30 1.1 bouyer
31 1.3 ad #include <sys/bus.h>
32 1.1 bouyer
33 1.1 bouyer #include <dev/scsipi/scsipi_all.h>
34 1.1 bouyer #include <dev/scsipi/scsipi_disk.h>
35 1.1 bouyer #include <dev/scsipi/scsiconf.h>
36 1.1 bouyer
37 1.1 bouyer #include <dev/ic/mfireg.h>
38 1.1 bouyer #include <dev/ic/mfivar.h>
39 1.1 bouyer
40 1.1 bouyer #define MFI_BAR 0x10
41 1.1 bouyer #define MFI_PCI_MEMSIZE 0x2000 /* 8k */
42 1.1 bouyer
43 1.4 xtraeme const struct mfi_pci_device *mfi_pci_find_device(struct pci_attach_args *);
44 1.1 bouyer int mfi_pci_match(struct device *, struct cfdata *, void *);
45 1.1 bouyer void mfi_pci_attach(struct device *, struct device *, void *);
46 1.1 bouyer
47 1.1 bouyer CFATTACH_DECL(mfi_pci, sizeof(struct mfi_softc),
48 1.1 bouyer mfi_pci_match, mfi_pci_attach, NULL, NULL);
49 1.1 bouyer
50 1.4 xtraeme struct mfi_pci_subtype {
51 1.4 xtraeme pcireg_t st_vendor;
52 1.4 xtraeme pcireg_t st_product;
53 1.4 xtraeme const char *st_string;
54 1.4 xtraeme };
55 1.4 xtraeme
56 1.4 xtraeme static const struct mfi_pci_subtype mfi_1078_subtypes[] = {
57 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x1006, "SAS 8888ELP" },
58 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x100a, "SAS 8708ELP" },
59 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x100f, "SAS 8708E" },
60 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x1012, "SAS 8704ELP" },
61 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x1013, "SAS 8708EM2" },
62 1.4 xtraeme { PCI_VENDOR_SYMBIOS, 0x1016, "SAS 8880EM2" },
63 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f0a, "Dell PERC 6/e" },
64 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f0b, "Dell PERC 6/i" },
65 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f0c, "Dell PERC 6/i integrated" },
66 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f0d, "Dell CERC 6/i" },
67 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f11, "Dell CERC 6/i integrated" },
68 1.4 xtraeme { 0, 0, NULL }
69 1.4 xtraeme };
70 1.4 xtraeme
71 1.4 xtraeme static const struct mfi_pci_subtype mfi_perc5_subtypes[] = {
72 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f01, "Dell PERC 5/e" },
73 1.4 xtraeme { PCI_VENDOR_DELL, 0x1f02, "Dell PERC 5/i" },
74 1.4 xtraeme { 0, 0, NULL }
75 1.1 bouyer };
76 1.1 bouyer
77 1.1 bouyer static const
78 1.4 xtraeme struct mfi_pci_device {
79 1.4 xtraeme pcireg_t mpd_vendor;
80 1.4 xtraeme pcireg_t mpd_product;
81 1.4 xtraeme enum mfi_iop mpd_iop;
82 1.4 xtraeme const struct mfi_pci_subtype *mpd_subtype;
83 1.4 xtraeme } mfi_pci_devices[] = {
84 1.4 xtraeme { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_SAS,
85 1.4 xtraeme MFI_IOP_XSCALE, NULL },
86 1.1 bouyer { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_VERDE_ZCR,
87 1.4 xtraeme MFI_IOP_XSCALE, NULL },
88 1.4 xtraeme { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1078,
89 1.4 xtraeme MFI_IOP_PPC, mfi_1078_subtypes },
90 1.1 bouyer { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_5,
91 1.4 xtraeme MFI_IOP_XSCALE, mfi_perc5_subtypes },
92 1.4 xtraeme { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_6,
93 1.4 xtraeme MFI_IOP_PPC, mfi_1078_subtypes },
94 1.1 bouyer };
95 1.1 bouyer
96 1.4 xtraeme const struct mfi_pci_device *
97 1.4 xtraeme mfi_pci_find_device(struct pci_attach_args *pa)
98 1.4 xtraeme {
99 1.4 xtraeme const struct mfi_pci_device *mpd;
100 1.4 xtraeme int i;
101 1.4 xtraeme
102 1.4 xtraeme for (i = 0; i < __arraycount(mfi_pci_devices); i++) {
103 1.4 xtraeme mpd = &mfi_pci_devices[i];
104 1.1 bouyer
105 1.4 xtraeme if (mpd->mpd_vendor == PCI_VENDOR(pa->pa_id) &&
106 1.4 xtraeme mpd->mpd_product == PCI_PRODUCT(pa->pa_id))
107 1.4 xtraeme return mpd;
108 1.1 bouyer }
109 1.1 bouyer
110 1.4 xtraeme return NULL;
111 1.1 bouyer }
112 1.1 bouyer
113 1.1 bouyer int
114 1.1 bouyer mfi_pci_match(struct device *parent, struct cfdata *match, void *aux)
115 1.1 bouyer {
116 1.4 xtraeme return (mfi_pci_find_device(aux) != NULL) ? 1 : 0;
117 1.1 bouyer }
118 1.1 bouyer
119 1.1 bouyer void
120 1.1 bouyer mfi_pci_attach(struct device *parent, struct device *self, void *aux)
121 1.1 bouyer {
122 1.1 bouyer struct mfi_softc *sc = (struct mfi_softc *)self;
123 1.1 bouyer struct pci_attach_args *pa = aux;
124 1.4 xtraeme const struct mfi_pci_device *mpd;
125 1.4 xtraeme const struct mfi_pci_subtype *st;
126 1.1 bouyer const char *intrstr;
127 1.1 bouyer pci_intr_handle_t ih;
128 1.1 bouyer bus_size_t size;
129 1.1 bouyer pcireg_t csr;
130 1.4 xtraeme const char *subtype = NULL;
131 1.4 xtraeme uint32_t subsysid;
132 1.4 xtraeme
133 1.4 xtraeme mpd = mfi_pci_find_device(pa);
134 1.1 bouyer
135 1.1 bouyer subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
136 1.4 xtraeme if (mpd->mpd_subtype != NULL) {
137 1.4 xtraeme st = mpd->mpd_subtype;
138 1.4 xtraeme while (st->st_vendor != 0) {
139 1.4 xtraeme if (PCI_VENDOR(subsysid) == st->st_vendor &&
140 1.4 xtraeme PCI_PRODUCT(subsysid) == st->st_product) {
141 1.4 xtraeme subtype = st->st_string;
142 1.1 bouyer break;
143 1.4 xtraeme }
144 1.4 xtraeme st++;
145 1.1 bouyer }
146 1.4 xtraeme aprint_normal(", %s", subtype);
147 1.4 xtraeme }
148 1.1 bouyer
149 1.1 bouyer csr = pci_mapreg_type(pa->pa_pc, pa->pa_tag, MFI_BAR);
150 1.1 bouyer csr |= PCI_MAPREG_MEM_TYPE_32BIT;
151 1.1 bouyer if (pci_mapreg_map(pa, MFI_BAR, csr, 0,
152 1.1 bouyer &sc->sc_iot, &sc->sc_ioh, NULL, &size)) {
153 1.1 bouyer aprint_error(": can't map controller pci space\n");
154 1.1 bouyer return;
155 1.1 bouyer }
156 1.1 bouyer
157 1.1 bouyer sc->sc_dmat = pa->pa_dmat;
158 1.1 bouyer
159 1.1 bouyer if (pci_intr_map(pa, &ih)) {
160 1.1 bouyer aprint_error(": can't map interrupt\n");
161 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
162 1.1 bouyer return;
163 1.1 bouyer }
164 1.1 bouyer intrstr = pci_intr_string(pa->pa_pc, ih);
165 1.1 bouyer sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, mfi_intr, sc);
166 1.1 bouyer if (!sc->sc_ih) {
167 1.1 bouyer aprint_error(": can't establish interrupt");
168 1.1 bouyer if (intrstr)
169 1.1 bouyer aprint_error(" at %s", intrstr);
170 1.1 bouyer aprint_error("\n");
171 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
172 1.1 bouyer return;
173 1.1 bouyer }
174 1.1 bouyer
175 1.1 bouyer aprint_normal(": %s\n", intrstr);
176 1.1 bouyer
177 1.4 xtraeme if (mfi_attach(sc, mpd->mpd_iop)) {
178 1.1 bouyer aprint_error("%s: can't attach", DEVNAME(sc));
179 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
180 1.1 bouyer sc->sc_ih = NULL;
181 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
182 1.1 bouyer }
183 1.1 bouyer }
184