2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 * PCI bus interface and resource allocation.
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/module.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
53 #include <dev/pci/pcireg.h>
54 #include <dev/pci/pcivar.h>
56 #include <dev/aac/aacreg.h>
57 #include <sys/aac_ioctl.h>
58 #include <dev/aac/aacvar.h>
60 static int aac_pci_probe(device_t dev);
61 static int aac_pci_attach(device_t dev);
63 static device_method_t aac_methods[] = {
64 /* Device interface */
65 DEVMETHOD(device_probe, aac_pci_probe),
66 DEVMETHOD(device_attach, aac_pci_attach),
67 DEVMETHOD(device_detach, aac_detach),
68 DEVMETHOD(device_suspend, aac_suspend),
69 DEVMETHOD(device_resume, aac_resume),
71 DEVMETHOD(bus_print_child, bus_generic_print_child),
72 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
76 static driver_t aac_pci_driver = {
79 sizeof(struct aac_softc)
82 static devclass_t aac_devclass;
84 DRIVER_MODULE(aac, pci, aac_pci_driver, aac_devclass, 0, 0);
95 } aac_identifiers[] = {
96 {0x1028, 0x0001, 0x1028, 0x0001, AAC_HWIF_I960RX, 0,
98 {0x1028, 0x0002, 0x1028, 0x0002, AAC_HWIF_I960RX, 0,
100 {0x1028, 0x0003, 0x1028, 0x0003, AAC_HWIF_I960RX, 0,
102 {0x1028, 0x0004, 0x1028, 0x00d0, AAC_HWIF_I960RX, 0,
104 {0x1028, 0x0002, 0x1028, 0x00d1, AAC_HWIF_I960RX, 0,
106 {0x1028, 0x0002, 0x1028, 0x00d9, AAC_HWIF_I960RX, 0,
108 {0x1028, 0x000a, 0x1028, 0x0106, AAC_HWIF_I960RX, 0,
110 {0x1028, 0x000a, 0x1028, 0x011b, AAC_HWIF_I960RX, 0,
112 {0x1028, 0x000a, 0x1028, 0x0121, AAC_HWIF_I960RX, 0,
114 {0x1011, 0x0046, 0x9005, 0x0364, AAC_HWIF_STRONGARM, 0,
116 {0x1011, 0x0046, 0x9005, 0x0365, AAC_HWIF_STRONGARM,
117 AAC_FLAGS_BROKEN_MEMMAP, "Adaptec SCSI RAID 5400S"},
118 {0x1011, 0x0046, 0x9005, 0x1364, AAC_HWIF_STRONGARM, AAC_FLAGS_PERC2QC,
120 {0x1011, 0x0046, 0x103c, 0x10c2, AAC_HWIF_STRONGARM, 0,
122 {0x9005, 0x0285, 0x9005, 0x0285, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
123 AAC_FLAGS_256FIBS, "Adaptec SCSI RAID 2200S"},
124 {0x9005, 0x0285, 0x1028, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
125 AAC_FLAGS_256FIBS, "Dell PERC 320/DC"},
126 {0x9005, 0x0285, 0x9005, 0x0286, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
127 AAC_FLAGS_256FIBS, "Adaptec SCSI RAID 2120S"},
128 {0x9005, 0x0285, 0x9005, 0x0290, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
129 "Adaptec SCSI RAID 2410SA"},
130 {0x9005, 0x0285, 0x1028, 0x0291, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
131 "Dell CERC SATA RAID 2"},
132 {0x9005, 0x0285, 0x9005, 0x0292, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
133 "Adaptec SCSI RAID 2810SA"},
134 {0x9005, 0x0285, 0x9005, 0x0293, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
135 "Adaptec SCSI RAID 21610SA"},
136 {0x9005, 0x0285, 0x103c, 0x3227, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
137 "HP ML110 G2 (Adaptec 2610SA)"},
138 {0x9005, 0x0286, 0x9005, 0x028c, AAC_HWIF_RKT, 0,
139 "Adaptec SCSI RAID 2230S"},
140 {0x9005, 0x0286, 0x9005, 0x028d, AAC_HWIF_RKT, 0,
141 "Adaptec SCSI RAID 2130S"},
143 {0x9005, 0x0285, 0x9005, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
144 AAC_FLAGS_256FIBS, "Adaptec SCSI RAID 2200S"},
145 {0x9005, 0x0285, 0x17aa, 0x0286, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
146 AAC_FLAGS_256FIBS, "Legend S220"},
147 {0x9005, 0x0285, 0x17aa, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
148 AAC_FLAGS_256FIBS, "Legend S230"},
149 {0x9005, 0x0285, 0x9005, 0x0288, AAC_HWIF_I960RX, 0,
150 "Adaptec SCSI RAID 3230S"},
151 {0x9005, 0x0285, 0x9005, 0x0289, AAC_HWIF_I960RX, 0,
152 "Adaptec SCSI RAID 3240S"},
153 {0x9005, 0x0285, 0x9005, 0x028a, AAC_HWIF_I960RX, 0,
154 "Adaptec SCSI RAID 2020ZCR"},
155 {0x9005, 0x0285, 0x9005, 0x028b, AAC_HWIF_I960RX, 0,
156 "Adaptec SCSI RAID 2025ZCR"},
157 {0x9005, 0x0286, 0x9005, 0x029b, AAC_HWIF_RKT, 0,
158 "Adaptec SATA RAID 2820SA"},
159 {0x9005, 0x0286, 0x9005, 0x029c, AAC_HWIF_RKT, 0,
160 "Adaptec SATA RAID 2620SA"},
161 {0x9005, 0x0286, 0x9005, 0x029d, AAC_HWIF_RKT, 0,
162 "Adaptec SATA RAID 2420SA"},
163 {0x9005, 0x0286, 0x9005, 0x029e, AAC_HWIF_RKT, 0,
164 "ICP9024RO SATA RAID"},
165 {0x9005, 0x0286, 0x9005, 0x029f, AAC_HWIF_RKT, 0,
166 "ICP9014RO SATA RAID"},
167 {0x9005, 0x0285, 0x9005, 0x0294, AAC_HWIF_I960RX, 0,
168 "Adaptec SATA RAID 2026ZCR"},
169 {0x9005, 0x0285, 0x103c, 0x3227, AAC_HWIF_I960RX, 0,
170 "Adaptec SATA RAID 2610SA"},
171 {0x9005, 0x0285, 0x9005, 0x0296, AAC_HWIF_I960RX, 0,
172 "Adaptec SCSI RAID 2240S"},
173 {0x9005, 0x0285, 0x9005, 0x0297, AAC_HWIF_I960RX, 0,
174 "Adaptec SAS RAID 4005SAS"},
175 {0x9005, 0x0285, 0x1014, 0x02f2, AAC_HWIF_I960RX, 0,
177 {0x9005, 0x0285, 0x9005, 0x0298, AAC_HWIF_I960RX, 0,
178 "Adaptec SAS RAID 4000SAS"},
179 {0x9005, 0x0285, 0x9005, 0x0299, AAC_HWIF_I960RX, 0,
180 "Adaptec SAS RAID 4800SAS"},
181 {0x9005, 0x0285, 0x9005, 0x029a, AAC_HWIF_I960RX, 0,
182 "Adaptec SAS RAID 4805SAS"},
183 {0x9005, 0x0285, 0x9005, 0x028e, AAC_HWIF_I960RX, 0,
184 "Adaptec SATA RAID 2020SA ZCR"},
185 {0x9005, 0x0285, 0x9005, 0x028f, AAC_HWIF_I960RX, 0,
186 "Adaptec SATA RAID 2025SA ZCR"},
187 {0x9005, 0x0285, 0x9005, 0x02a4, AAC_HWIF_I960RX, 0,
188 "ICP 9085LI SAS RAID"},
189 {0x9005, 0x0285, 0x9005, 0x02a5, AAC_HWIF_I960RX, 0,
190 "ICP 5085BR SAS RAID"},
191 {0x9005, 0x0286, 0x9005, 0x02a0, AAC_HWIF_RKT, 0,
192 "ICP9047MA SATA RAID"},
193 {0x9005, 0x0286, 0x9005, 0x02a1, AAC_HWIF_RKT, 0,
194 "ICP9087MA SATA RAID"},
195 {0, 0, 0, 0, 0, 0, 0}
199 * Determine whether this is one of our supported adapters.
202 aac_pci_probe(device_t dev)
208 for (m = aac_identifiers; m->vendor != 0; m++) {
209 if ((m->vendor == pci_get_vendor(dev)) &&
210 (m->device == pci_get_device(dev)) &&
211 ((m->subvendor == 0) || (m->subvendor ==
212 pci_get_subvendor(dev))) &&
213 ((m->subdevice == 0) || ((m->subdevice ==
214 pci_get_subdevice(dev))))) {
216 device_set_desc(dev, m->desc);
217 return(BUS_PROBE_DEFAULT);
224 * Allocate resources for our device, set up the bus interface.
227 aac_pci_attach(device_t dev)
229 struct aac_softc *sc;
238 sc = device_get_softc(dev);
239 bzero(sc, sizeof(*sc));
242 /* assume failure is 'not configured' */
246 * Verify that the adapter is correctly set up in PCI space.
248 command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2);
249 command |= PCIM_CMD_BUSMASTEREN;
250 pci_write_config(dev, PCIR_COMMAND, command, 2);
251 command = pci_read_config(sc->aac_dev, PCIR_COMMAND, 2);
252 if (!(command & PCIM_CMD_BUSMASTEREN)) {
253 device_printf(sc->aac_dev, "can't enable bus-master feature\n");
256 if ((command & PCIM_CMD_MEMEN) == 0) {
257 device_printf(sc->aac_dev, "memory window not available\n");
262 * Allocate the PCI register window.
264 sc->aac_regs_rid = PCIR_BAR(0);
265 if ((sc->aac_regs_resource = bus_alloc_resource_any(sc->aac_dev,
270 device_printf(sc->aac_dev,
271 "couldn't allocate register window\n");
274 sc->aac_btag = rman_get_bustag(sc->aac_regs_resource);
275 sc->aac_bhandle = rman_get_bushandle(sc->aac_regs_resource);
277 /* assume failure is 'out of memory' */
281 * Allocate the parent bus DMA tag appropriate for our PCI interface.
283 * Note that some of these controllers are 64-bit capable.
285 if (bus_dma_tag_create(NULL, /* parent */
286 PAGE_SIZE, 0, /* algnmnt, boundary */
287 BUS_SPACE_MAXADDR, /* lowaddr */
288 BUS_SPACE_MAXADDR, /* highaddr */
289 NULL, NULL, /* filter, filterarg */
290 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
291 BUS_SPACE_UNRESTRICTED, /* nsegments */
292 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
294 NULL, NULL, /* No locking needed */
295 &sc->aac_parent_dmat)) {
296 device_printf(sc->aac_dev, "can't allocate parent DMA tag\n");
301 * Detect the hardware interface version, set up the bus interface
304 for (i = 0; aac_identifiers[i].vendor != 0; i++) {
305 if ((aac_identifiers[i].vendor == pci_get_vendor(dev)) &&
306 (aac_identifiers[i].device == pci_get_device(dev)) &&
307 (aac_identifiers[i].subvendor == pci_get_subvendor(dev)) &&
308 (aac_identifiers[i].subdevice == pci_get_subdevice(dev))) {
309 sc->aac_hwif = aac_identifiers[i].hwif;
310 switch(sc->aac_hwif) {
311 case AAC_HWIF_I960RX:
312 debug(2, "set hardware up for i960Rx");
313 sc->aac_if = aac_rx_interface;
315 case AAC_HWIF_STRONGARM:
316 debug(2, "set hardware up for StrongARM");
317 sc->aac_if = aac_sa_interface;
319 case AAC_HWIF_FALCON:
320 debug(2, "set hardware up for Falcon/PPC");
321 sc->aac_if = aac_fa_interface;
324 debug(2, "set hardware up for Rocket/MIPS");
325 sc->aac_if = aac_rkt_interface;
328 sc->aac_hwif = AAC_HWIF_UNKNOWN;
333 sc->flags = aac_identifiers[i].quirks;
338 if (sc->aac_hwif == AAC_HWIF_UNKNOWN) {
339 device_printf(sc->aac_dev, "unknown hardware type\n");
346 * Do bus-independent initialisation.
348 error = aac_attach(sc);
357 * Do nothing driver that will attach to the SCSI channels of a Dell PERC
358 * controller. This is needed to keep the power management subsystem from
359 * trying to power down these devices.
361 static int aacch_probe(device_t dev);
362 static int aacch_attach(device_t dev);
363 static int aacch_detach(device_t dev);
365 static device_method_t aacch_methods[] = {
366 /* Device interface */
367 DEVMETHOD(device_probe, aacch_probe),
368 DEVMETHOD(device_attach, aacch_attach),
369 DEVMETHOD(device_detach, aacch_detach),
377 static driver_t aacch_driver = {
380 sizeof(struct aacch_softc)
383 static devclass_t aacch_devclass;
384 DRIVER_MODULE(aacch, pci, aacch_driver, aacch_devclass, 0, 0);
387 aacch_probe(device_t dev)
390 if ((pci_get_vendor(dev) != 0x9005) ||
391 (pci_get_device(dev) != 0x00c5))
394 device_set_desc(dev, "AAC RAID Channel");
399 aacch_attach(device_t dev)
401 struct aacch_softc *sc;
403 sc = device_get_softc(dev);
411 aacch_detach(device_t dev)