mfi_pci.c revision 1.7 1 1.7 cegger /* $NetBSD: mfi_pci.c,v 1.7 2009/05/06 10:34:32 cegger 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.7 cegger __KERNEL_RCSID(0, "$NetBSD: mfi_pci.c,v 1.7 2009/05/06 10:34:32 cegger 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.7 cegger int mfi_pci_match(device_t, cfdata_t, void *);
45 1.7 cegger void mfi_pci_attach(device_t, device_t, 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.5 xtraeme { PCI_VENDOR_DELL, 0x1f03, "Dell PERC 5/i integrated" },
75 1.4 xtraeme { 0, 0, NULL }
76 1.1 bouyer };
77 1.1 bouyer
78 1.1 bouyer static const
79 1.4 xtraeme struct mfi_pci_device {
80 1.4 xtraeme pcireg_t mpd_vendor;
81 1.4 xtraeme pcireg_t mpd_product;
82 1.4 xtraeme enum mfi_iop mpd_iop;
83 1.4 xtraeme const struct mfi_pci_subtype *mpd_subtype;
84 1.4 xtraeme } mfi_pci_devices[] = {
85 1.4 xtraeme { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_SAS,
86 1.4 xtraeme MFI_IOP_XSCALE, NULL },
87 1.1 bouyer { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_MEGARAID_VERDE_ZCR,
88 1.4 xtraeme MFI_IOP_XSCALE, NULL },
89 1.4 xtraeme { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1078,
90 1.4 xtraeme MFI_IOP_PPC, mfi_1078_subtypes },
91 1.1 bouyer { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_5,
92 1.4 xtraeme MFI_IOP_XSCALE, mfi_perc5_subtypes },
93 1.4 xtraeme { PCI_VENDOR_DELL, PCI_PRODUCT_DELL_PERC_6,
94 1.4 xtraeme MFI_IOP_PPC, mfi_1078_subtypes },
95 1.1 bouyer };
96 1.1 bouyer
97 1.4 xtraeme const struct mfi_pci_device *
98 1.4 xtraeme mfi_pci_find_device(struct pci_attach_args *pa)
99 1.4 xtraeme {
100 1.4 xtraeme const struct mfi_pci_device *mpd;
101 1.4 xtraeme int i;
102 1.4 xtraeme
103 1.4 xtraeme for (i = 0; i < __arraycount(mfi_pci_devices); i++) {
104 1.4 xtraeme mpd = &mfi_pci_devices[i];
105 1.1 bouyer
106 1.4 xtraeme if (mpd->mpd_vendor == PCI_VENDOR(pa->pa_id) &&
107 1.4 xtraeme mpd->mpd_product == PCI_PRODUCT(pa->pa_id))
108 1.4 xtraeme return mpd;
109 1.1 bouyer }
110 1.1 bouyer
111 1.4 xtraeme return NULL;
112 1.1 bouyer }
113 1.1 bouyer
114 1.1 bouyer int
115 1.7 cegger mfi_pci_match(device_t parent, cfdata_t match, void *aux)
116 1.1 bouyer {
117 1.4 xtraeme return (mfi_pci_find_device(aux) != NULL) ? 1 : 0;
118 1.1 bouyer }
119 1.1 bouyer
120 1.1 bouyer void
121 1.7 cegger mfi_pci_attach(device_t parent, device_t self, void *aux)
122 1.1 bouyer {
123 1.1 bouyer struct mfi_softc *sc = (struct mfi_softc *)self;
124 1.1 bouyer struct pci_attach_args *pa = aux;
125 1.4 xtraeme const struct mfi_pci_device *mpd;
126 1.4 xtraeme const struct mfi_pci_subtype *st;
127 1.1 bouyer const char *intrstr;
128 1.1 bouyer pci_intr_handle_t ih;
129 1.1 bouyer bus_size_t size;
130 1.1 bouyer pcireg_t csr;
131 1.4 xtraeme const char *subtype = NULL;
132 1.4 xtraeme uint32_t subsysid;
133 1.4 xtraeme
134 1.1 bouyer csr = pci_mapreg_type(pa->pa_pc, pa->pa_tag, MFI_BAR);
135 1.1 bouyer csr |= PCI_MAPREG_MEM_TYPE_32BIT;
136 1.1 bouyer if (pci_mapreg_map(pa, MFI_BAR, csr, 0,
137 1.1 bouyer &sc->sc_iot, &sc->sc_ioh, NULL, &size)) {
138 1.1 bouyer aprint_error(": can't map controller pci space\n");
139 1.1 bouyer return;
140 1.1 bouyer }
141 1.1 bouyer
142 1.1 bouyer sc->sc_dmat = pa->pa_dmat;
143 1.1 bouyer
144 1.1 bouyer if (pci_intr_map(pa, &ih)) {
145 1.1 bouyer aprint_error(": can't map interrupt\n");
146 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
147 1.1 bouyer return;
148 1.1 bouyer }
149 1.1 bouyer intrstr = pci_intr_string(pa->pa_pc, ih);
150 1.1 bouyer sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, mfi_intr, sc);
151 1.1 bouyer if (!sc->sc_ih) {
152 1.1 bouyer aprint_error(": can't establish interrupt");
153 1.1 bouyer if (intrstr)
154 1.1 bouyer aprint_error(" at %s", intrstr);
155 1.1 bouyer aprint_error("\n");
156 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
157 1.1 bouyer return;
158 1.1 bouyer }
159 1.1 bouyer
160 1.5 xtraeme mpd = mfi_pci_find_device(pa);
161 1.5 xtraeme
162 1.5 xtraeme subsysid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
163 1.5 xtraeme if (mpd->mpd_subtype != NULL) {
164 1.5 xtraeme st = mpd->mpd_subtype;
165 1.5 xtraeme while (st->st_vendor != 0) {
166 1.5 xtraeme if (PCI_VENDOR(subsysid) == st->st_vendor &&
167 1.5 xtraeme PCI_PRODUCT(subsysid) == st->st_product) {
168 1.5 xtraeme subtype = st->st_string;
169 1.5 xtraeme break;
170 1.5 xtraeme }
171 1.5 xtraeme st++;
172 1.5 xtraeme }
173 1.5 xtraeme if (subtype)
174 1.5 xtraeme aprint_normal(": %s\n", subtype);
175 1.5 xtraeme }
176 1.5 xtraeme
177 1.5 xtraeme aprint_normal("%s: interrupting at %s\n", DEVNAME(sc), intrstr);
178 1.1 bouyer
179 1.4 xtraeme if (mfi_attach(sc, mpd->mpd_iop)) {
180 1.1 bouyer aprint_error("%s: can't attach", DEVNAME(sc));
181 1.1 bouyer pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
182 1.1 bouyer sc->sc_ih = NULL;
183 1.1 bouyer bus_space_unmap(sc->sc_iot, sc->sc_ioh, size);
184 1.1 bouyer }
185 1.1 bouyer }
186