Clean up the namespace of <sys/timeb.h>.
[dragonfly.git] / sys / dev / raid / aac / aac_pci.c
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 *
b4df2201 29 * $FreeBSD: head/sys/dev/aac/aac_pci.c 254005 2013-08-06 19:14:02Z marius $
984263bc
MD
30 */
31
32/*
33 * PCI bus interface and resource allocation.
34 */
35
36#include "opt_aac.h"
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/kernel.h>
d9773475 41#include <sys/module.h>
984263bc 42
e9ae7f4f 43#include <sys/bio.h>
984263bc
MD
44#include <sys/bus.h>
45#include <sys/conf.h>
984263bc 46#include <sys/disk.h>
e9ae7f4f 47
984263bc
MD
48#include <sys/rman.h>
49
1f2de5d4
MD
50#include <bus/pci/pcireg.h>
51#include <bus/pci/pcivar.h>
984263bc 52
e9ae7f4f
SW
53#include <dev/raid/aac/aacreg.h>
54#include <dev/raid/aac/aac_ioctl.h>
55#include <dev/raid/aac/aacvar.h>
984263bc
MD
56
57static int aac_pci_probe(device_t dev);
58static int aac_pci_attach(device_t dev);
59
b4df2201
SW
60static int aac_msi_enable = 1;
61TUNABLE_INT("hw.mfi.msi.enable", &aac_msi_enable);
62
984263bc
MD
63static 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),
70
d3c9c58e 71 DEVMETHOD_END
984263bc
MD
72};
73
74static driver_t aac_pci_driver = {
75 "aac",
76 aac_methods,
77 sizeof(struct aac_softc)
78};
79
e9ae7f4f 80static devclass_t aac_devclass;
984263bc 81
aa2b9d05 82DRIVER_MODULE(aac, pci, aac_pci_driver, aac_devclass, NULL, NULL);
e9ae7f4f
SW
83MODULE_DEPEND(aac, pci, 1, 1, 1);
84
984263bc 85
b4df2201 86static const struct aac_ident
984263bc
MD
87{
88 u_int16_t vendor;
89 u_int16_t device;
90 u_int16_t subvendor;
91 u_int16_t subdevice;
92 int hwif;
93 int quirks;
b4df2201 94 const char *desc;
984263bc
MD
95} aac_identifiers[] = {
96 {0x1028, 0x0001, 0x1028, 0x0001, AAC_HWIF_I960RX, 0,
97 "Dell PERC 2/Si"},
98 {0x1028, 0x0002, 0x1028, 0x0002, AAC_HWIF_I960RX, 0,
99 "Dell PERC 3/Di"},
100 {0x1028, 0x0003, 0x1028, 0x0003, AAC_HWIF_I960RX, 0,
101 "Dell PERC 3/Si"},
102 {0x1028, 0x0004, 0x1028, 0x00d0, AAC_HWIF_I960RX, 0,
103 "Dell PERC 3/Si"},
104 {0x1028, 0x0002, 0x1028, 0x00d1, AAC_HWIF_I960RX, 0,
105 "Dell PERC 3/Di"},
106 {0x1028, 0x0002, 0x1028, 0x00d9, AAC_HWIF_I960RX, 0,
107 "Dell PERC 3/Di"},
984263bc
MD
108 {0x1028, 0x000a, 0x1028, 0x0106, AAC_HWIF_I960RX, 0,
109 "Dell PERC 3/Di"},
110 {0x1028, 0x000a, 0x1028, 0x011b, AAC_HWIF_I960RX, 0,
111 "Dell PERC 3/Di"},
112 {0x1028, 0x000a, 0x1028, 0x0121, AAC_HWIF_I960RX, 0,
113 "Dell PERC 3/Di"},
114 {0x1011, 0x0046, 0x9005, 0x0364, AAC_HWIF_STRONGARM, 0,
115 "Adaptec AAC-364"},
d9773475
PA
116 {0x1011, 0x0046, 0x9005, 0x0365, AAC_HWIF_STRONGARM,
117 AAC_FLAGS_BROKEN_MEMMAP, "Adaptec SCSI RAID 5400S"},
984263bc 118 {0x1011, 0x0046, 0x9005, 0x1364, AAC_HWIF_STRONGARM, AAC_FLAGS_PERC2QC,
e9ae7f4f 119 "Dell PERC 2/QC"},
984263bc 120 {0x1011, 0x0046, 0x103c, 0x10c2, AAC_HWIF_STRONGARM, 0,
e9ae7f4f
SW
121 "HP NetRaid-4M"},
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"},
158dbeb8 128 {0x9005, 0x0285, 0x9005, 0x0290, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
d9773475 129 "Adaptec SATA RAID 2410SA"},
158dbeb8
MD
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,
d9773475
PA
133 "Adaptec SATA RAID 2810SA"},
134 {0x9005, 0x0285, 0x9005, 0x0293, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
135 "Adaptec SATA RAID 21610SA"},
136 {0x9005, 0x0285, 0x103c, 0x3227, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB,
137 "HP ML110 G2 (Adaptec 2610SA)"},
b4df2201 138 {0x9005, 0x0286, 0x9005, 0x028c, AAC_HWIF_RKT, AAC_FLAGS_NOMSI,
d9773475
PA
139 "Adaptec SCSI RAID 2230S"},
140 {0x9005, 0x0286, 0x9005, 0x028d, AAC_HWIF_RKT, 0,
141 "Adaptec SCSI RAID 2130S"},
d9773475
PA
142 {0x9005, 0x0285, 0x9005, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
143 AAC_FLAGS_256FIBS, "Adaptec SCSI RAID 2200S"},
144 {0x9005, 0x0285, 0x17aa, 0x0286, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
145 AAC_FLAGS_256FIBS, "Legend S220"},
146 {0x9005, 0x0285, 0x17aa, 0x0287, AAC_HWIF_I960RX, AAC_FLAGS_NO4GB |
147 AAC_FLAGS_256FIBS, "Legend S230"},
148 {0x9005, 0x0285, 0x9005, 0x0288, AAC_HWIF_I960RX, 0,
149 "Adaptec SCSI RAID 3230S"},
150 {0x9005, 0x0285, 0x9005, 0x0289, AAC_HWIF_I960RX, 0,
151 "Adaptec SCSI RAID 3240S"},
152 {0x9005, 0x0285, 0x9005, 0x028a, AAC_HWIF_I960RX, 0,
153 "Adaptec SCSI RAID 2020ZCR"},
154 {0x9005, 0x0285, 0x9005, 0x028b, AAC_HWIF_I960RX, 0,
155 "Adaptec SCSI RAID 2025ZCR"},
b4df2201 156 {0x9005, 0x0286, 0x9005, 0x029b, AAC_HWIF_RKT, AAC_FLAGS_NOMSI,
d9773475
PA
157 "Adaptec SATA RAID 2820SA"},
158 {0x9005, 0x0286, 0x9005, 0x029c, AAC_HWIF_RKT, 0,
159 "Adaptec SATA RAID 2620SA"},
160 {0x9005, 0x0286, 0x9005, 0x029d, AAC_HWIF_RKT, 0,
161 "Adaptec SATA RAID 2420SA"},
162 {0x9005, 0x0286, 0x9005, 0x029e, AAC_HWIF_RKT, 0,
163 "ICP ICP9024RO SCSI RAID"},
164 {0x9005, 0x0286, 0x9005, 0x029f, AAC_HWIF_RKT, 0,
165 "ICP ICP9014RO SCSI RAID"},
166 {0x9005, 0x0285, 0x9005, 0x0294, AAC_HWIF_I960RX, 0,
167 "Adaptec SATA RAID 2026ZCR"},
d9773475
PA
168 {0x9005, 0x0285, 0x9005, 0x0296, AAC_HWIF_I960RX, 0,
169 "Adaptec SCSI RAID 2240S"},
170 {0x9005, 0x0285, 0x9005, 0x0297, AAC_HWIF_I960RX, 0,
171 "Adaptec SAS RAID 4005SAS"},
172 {0x9005, 0x0285, 0x1014, 0x02f2, AAC_HWIF_I960RX, 0,
173 "IBM ServeRAID 8i"},
e9ae7f4f
SW
174 {0x9005, 0x0285, 0x1014, 0x0312, AAC_HWIF_I960RX, 0,
175 "IBM ServeRAID 8i"},
d9773475 176 {0x9005, 0x0285, 0x9005, 0x0298, AAC_HWIF_I960RX, 0,
e9ae7f4f 177 "Adaptec RAID 4000"},
d9773475
PA
178 {0x9005, 0x0285, 0x9005, 0x0299, AAC_HWIF_I960RX, 0,
179 "Adaptec SAS RAID 4800SAS"},
180 {0x9005, 0x0285, 0x9005, 0x029a, AAC_HWIF_I960RX, 0,
181 "Adaptec SAS RAID 4805SAS"},
182 {0x9005, 0x0285, 0x9005, 0x028e, AAC_HWIF_I960RX, 0,
183 "Adaptec SATA RAID 2020SA ZCR"},
184 {0x9005, 0x0285, 0x9005, 0x028f, AAC_HWIF_I960RX, 0,
185 "Adaptec SATA RAID 2025SA ZCR"},
186 {0x9005, 0x0285, 0x9005, 0x02a4, AAC_HWIF_I960RX, 0,
187 "ICP ICP9085LI SAS RAID"},
188 {0x9005, 0x0285, 0x9005, 0x02a5, AAC_HWIF_I960RX, 0,
189 "ICP ICP5085BR SAS RAID"},
190 {0x9005, 0x0286, 0x9005, 0x02a0, AAC_HWIF_RKT, 0,
191 "ICP ICP9047MA SATA RAID"},
192 {0x9005, 0x0286, 0x9005, 0x02a1, AAC_HWIF_RKT, 0,
193 "ICP ICP9087MA SATA RAID"},
e9ae7f4f
SW
194 {0x9005, 0x0286, 0x9005, 0x02a6, AAC_HWIF_RKT, 0,
195 "ICP9067MA SATA RAID"},
196 {0x9005, 0x0285, 0x9005, 0x02b5, AAC_HWIF_I960RX, 0,
197 "Adaptec RAID 5445"},
198 {0x9005, 0x0285, 0x9005, 0x02b6, AAC_HWIF_I960RX, 0,
199 "Adaptec RAID 5805"},
200 {0x9005, 0x0285, 0x9005, 0x02b7, AAC_HWIF_I960RX, 0,
201 "Adaptec RAID 5085"},
202 {0x9005, 0x0285, 0x9005, 0x02b8, AAC_HWIF_I960RX, 0,
203 "ICP RAID ICP5445SL"},
204 {0x9005, 0x0285, 0x9005, 0x02b9, AAC_HWIF_I960RX, 0,
205 "ICP RAID ICP5085SL"},
206 {0x9005, 0x0285, 0x9005, 0x02ba, AAC_HWIF_I960RX, 0,
207 "ICP RAID ICP5805SL"},
d9773475
PA
208 {0x9005, 0x0285, 0x9005, 0x02bb, AAC_HWIF_I960RX, 0,
209 "Adaptec RAID 3405"},
210 {0x9005, 0x0285, 0x9005, 0x02bc, AAC_HWIF_I960RX, 0,
211 "Adaptec RAID 3805"},
e9ae7f4f
SW
212 {0x9005, 0x0285, 0x9005, 0x02bd, AAC_HWIF_I960RX, 0,
213 "Adaptec RAID 31205"},
214 {0x9005, 0x0285, 0x9005, 0x02be, AAC_HWIF_I960RX, 0,
215 "Adaptec RAID 31605"},
216 {0x9005, 0x0285, 0x9005, 0x02bf, AAC_HWIF_I960RX, 0,
217 "ICP RAID ICP5045BL"},
218 {0x9005, 0x0285, 0x9005, 0x02c0, AAC_HWIF_I960RX, 0,
219 "ICP RAID ICP5085BL"},
220 {0x9005, 0x0285, 0x9005, 0x02c1, AAC_HWIF_I960RX, 0,
221 "ICP RAID ICP5125BR"},
222 {0x9005, 0x0285, 0x9005, 0x02c2, AAC_HWIF_I960RX, 0,
223 "ICP RAID ICP5165BR"},
224 {0x9005, 0x0285, 0x9005, 0x02c3, AAC_HWIF_I960RX, 0,
225 "Adaptec RAID 51205"},
226 {0x9005, 0x0285, 0x9005, 0x02c4, AAC_HWIF_I960RX, 0,
227 "Adaptec RAID 51605"},
228 {0x9005, 0x0285, 0x9005, 0x02c5, AAC_HWIF_I960RX, 0,
229 "ICP RAID ICP5125SL"},
230 {0x9005, 0x0285, 0x9005, 0x02c6, AAC_HWIF_I960RX, 0,
231 "ICP RAID ICP5165SL"},
232 {0x9005, 0x0285, 0x9005, 0x02c7, AAC_HWIF_I960RX, 0,
233 "Adaptec RAID 3085"},
234 {0x9005, 0x0285, 0x9005, 0x02c8, AAC_HWIF_I960RX, 0,
235 "ICP RAID ICP5805BL"},
236 {0x9005, 0x0285, 0x9005, 0x02ce, AAC_HWIF_I960RX, 0,
237 "Adaptec RAID 51245"},
238 {0x9005, 0x0285, 0x9005, 0x02cf, AAC_HWIF_I960RX, 0,
239 "Adaptec RAID 51645"},
240 {0x9005, 0x0285, 0x9005, 0x02d0, AAC_HWIF_I960RX, 0,
241 "Adaptec RAID 52445"},
d2274d62
MN
242 {0x9005, 0x0285, 0x9005, 0x02d1, AAC_HWIF_I960RX, 0,
243 "Adaptec RAID 5405"},
e9ae7f4f
SW
244 {0x9005, 0x0285, 0x9005, 0x02d4, AAC_HWIF_I960RX, 0,
245 "Adaptec RAID 2045"},
246 {0x9005, 0x0285, 0x9005, 0x02d5, AAC_HWIF_I960RX, 0,
247 "Adaptec RAID 2405"},
248 {0x9005, 0x0285, 0x9005, 0x02d6, AAC_HWIF_I960RX, 0,
249 "Adaptec RAID 2445"},
250 {0x9005, 0x0285, 0x9005, 0x02d7, AAC_HWIF_I960RX, 0,
251 "Adaptec RAID 2805"},
d9773475
PA
252 {0x9005, 0x0286, 0x1014, 0x9580, AAC_HWIF_RKT, 0,
253 "IBM ServeRAID-8k"},
e9ae7f4f
SW
254 {0x9005, 0x0285, 0x1014, 0x034d, AAC_HWIF_I960RX, 0,
255 "IBM ServeRAID 8s"},
256 {0x9005, 0x0285, 0x108e, 0x7aac, AAC_HWIF_I960RX, 0,
257 "Sun STK RAID REM"},
258 {0x9005, 0x0285, 0x108e, 0x7aae, AAC_HWIF_I960RX, 0,
259 "Sun STK RAID EM"},
260 {0x9005, 0x0285, 0x108e, 0x286, AAC_HWIF_I960RX, 0,
261 "SG-XPCIESAS-R-IN"},
262 {0x9005, 0x0285, 0x108e, 0x287, AAC_HWIF_I960RX, 0,
263 "SG-XPCIESAS-R-EX"},
264 {0x9005, 0x0285, 0x15d9, 0x2b5, AAC_HWIF_I960RX, 0,
265 "AOC-USAS-S4i"},
266 {0x9005, 0x0285, 0x15d9, 0x2b6, AAC_HWIF_I960RX, 0,
267 "AOC-USAS-S8i"},
268 {0x9005, 0x0285, 0x15d9, 0x2c9, AAC_HWIF_I960RX, 0,
269 "AOC-USAS-S4iR"},
270 {0x9005, 0x0285, 0x15d9, 0x2ca, AAC_HWIF_I960RX, 0,
271 "AOC-USAS-S8iR"},
272 {0x9005, 0x0285, 0x15d9, 0x2d2, AAC_HWIF_I960RX, 0,
273 "AOC-USAS-S8i-LP"},
274 {0x9005, 0x0285, 0x15d9, 0x2d3, AAC_HWIF_I960RX, 0,
275 "AOC-USAS-S8iR-LP"},
276 {0, 0, 0, 0, 0, 0, 0}
277};
b4df2201
SW
278
279static const struct aac_ident
e9ae7f4f
SW
280aac_family_identifiers[] = {
281 {0x9005, 0x0285, 0, 0, AAC_HWIF_I960RX, 0,
282 "Adaptec RAID Controller"},
283 {0x9005, 0x0286, 0, 0, AAC_HWIF_RKT, 0,
284 "Adaptec RAID Controller"},
984263bc
MD
285 {0, 0, 0, 0, 0, 0, 0}
286};
287
b4df2201 288static const struct aac_ident *
d9773475
PA
289aac_find_ident(device_t dev)
290{
b4df2201 291 const struct aac_ident *m;
e9ae7f4f
SW
292 u_int16_t vendid, devid, sub_vendid, sub_devid;
293
294 vendid = pci_get_vendor(dev);
295 devid = pci_get_device(dev);
296 sub_vendid = pci_get_subvendor(dev);
297 sub_devid = pci_get_subdevice(dev);
d9773475
PA
298
299 for (m = aac_identifiers; m->vendor != 0; m++) {
e9ae7f4f
SW
300 if ((m->vendor == vendid) && (m->device == devid) &&
301 (m->subvendor == sub_vendid) &&
302 (m->subdevice == sub_devid))
303 return (m);
304 }
305
306 for (m = aac_family_identifiers; m->vendor != 0; m++) {
307 if ((m->vendor == vendid) && (m->device == devid))
308 return (m);
d9773475 309 }
d9773475
PA
310 return (NULL);
311}
312
984263bc
MD
313/*
314 * Determine whether this is one of our supported adapters.
315 */
316static int
317aac_pci_probe(device_t dev)
318{
b4df2201 319 const struct aac_ident *id;
984263bc 320
e9ae7f4f 321 fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
984263bc 322
d9773475
PA
323 if ((id = aac_find_ident(dev)) != NULL) {
324 device_set_desc(dev, id->desc);
325 return(BUS_PROBE_DEFAULT);
984263bc
MD
326 }
327 return(ENXIO);
328}
329
330/*
331 * Allocate resources for our device, set up the bus interface.
332 */
333static int
334aac_pci_attach(device_t dev)
335{
336 struct aac_softc *sc;
b4df2201
SW
337 const struct aac_ident *id;
338 int error, rid;
339 u_int irq_flags;
984263bc 340
e9ae7f4f 341 fwprintf(NULL, HBA_FLAGS_DBG_FUNCTION_ENTRY_B, "");
984263bc
MD
342
343 /*
344 * Initialise softc.
345 */
346 sc = device_get_softc(dev);
984263bc
MD
347 sc->aac_dev = dev;
348
349 /* assume failure is 'not configured' */
350 error = ENXIO;
351
e9ae7f4f 352 /*
984263bc
MD
353 * Verify that the adapter is correctly set up in PCI space.
354 */
b4df2201
SW
355 pci_enable_busmaster(dev);
356 if (!(pci_read_config(dev, PCIR_COMMAND, 2) & PCIM_CMD_BUSMASTEREN)) {
357 device_printf(dev, "can't enable bus-master feature\n");
984263bc
MD
358 goto out;
359 }
b4df2201
SW
360
361 /*
362 * Detect the hardware interface version, set up the bus interface
363 * indirection.
364 */
365 id = aac_find_ident(dev);
366 sc->aac_hwif = id->hwif;
367 switch(sc->aac_hwif) {
368 case AAC_HWIF_I960RX:
369 case AAC_HWIF_NARK:
370 fwprintf(sc, HBA_FLAGS_DBG_INIT_B,
371 "set hardware up for i960Rx/NARK");
372 sc->aac_if = &aac_rx_interface;
373 break;
374 case AAC_HWIF_STRONGARM:
375 fwprintf(sc, HBA_FLAGS_DBG_INIT_B,
376 "set hardware up for StrongARM");
377 sc->aac_if = &aac_sa_interface;
378 break;
379 case AAC_HWIF_RKT:
380 fwprintf(sc, HBA_FLAGS_DBG_INIT_B,
381 "set hardware up for Rocket/MIPS");
382 sc->aac_if = &aac_rkt_interface;
383 break;
384 default:
385 sc->aac_hwif = AAC_HWIF_UNKNOWN;
386 device_printf(dev, "unknown hardware type\n");
984263bc
MD
387 goto out;
388 }
389
b4df2201
SW
390 /* Set up quirks */
391 sc->flags = id->quirks;
392
984263bc 393 /*
b4df2201 394 * Allocate the PCI register window(s).
984263bc 395 */
b4df2201
SW
396 rid = PCIR_BAR(0);
397 if ((sc->aac_regs_res0 = bus_alloc_resource_any(dev,
398 SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
399 device_printf(dev, "can't allocate register window 0\n");
984263bc
MD
400 goto out;
401 }
e9ae7f4f
SW
402 sc->aac_btag0 = rman_get_bustag(sc->aac_regs_res0);
403 sc->aac_bhandle0 = rman_get_bushandle(sc->aac_regs_res0);
404
405 if (sc->aac_hwif == AAC_HWIF_NARK) {
b4df2201
SW
406 rid = PCIR_BAR(1);
407 if ((sc->aac_regs_res1 = bus_alloc_resource_any(dev,
408 SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
409 device_printf(dev,
410 "can't allocate register window 1\n");
e9ae7f4f
SW
411 goto out;
412 }
413 sc->aac_btag1 = rman_get_bustag(sc->aac_regs_res1);
414 sc->aac_bhandle1 = rman_get_bushandle(sc->aac_regs_res1);
415 } else {
416 sc->aac_regs_res1 = sc->aac_regs_res0;
e9ae7f4f
SW
417 sc->aac_btag1 = sc->aac_btag0;
418 sc->aac_bhandle1 = sc->aac_bhandle0;
419 }
984263bc 420
b4df2201
SW
421 /*
422 * Allocate the interrupt.
423 */
424 sc->aac_irq_rid = 0;
425 if ((sc->flags & AAC_FLAGS_NOMSI) != 0)
426 aac_msi_enable = 0;
427 sc->aac_irq_type = pci_alloc_1intr(sc->aac_dev, aac_msi_enable,
428 &sc->aac_irq_rid, &irq_flags);
429 if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ,
430 &sc->aac_irq_rid, irq_flags)) == NULL) {
431 device_printf(dev, "can't allocate interrupt\n");
432 goto out;
433 }
434
984263bc
MD
435 /*
436 * Allocate the parent bus DMA tag appropriate for our PCI interface.
e9ae7f4f 437 *
984263bc
MD
438 * Note that some of these controllers are 64-bit capable.
439 */
b4df2201 440 if (bus_dma_tag_create(bus_get_dma_tag(dev), /* parent */
984263bc 441 PAGE_SIZE, 0, /* algnmnt, boundary */
d9773475 442 BUS_SPACE_MAXADDR, /* lowaddr */
984263bc
MD
443 BUS_SPACE_MAXADDR, /* highaddr */
444 NULL, NULL, /* filter, filterarg */
445 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
d9773475 446 BUS_SPACE_UNRESTRICTED, /* nsegments */
984263bc
MD
447 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
448 0, /* flags */
449 &sc->aac_parent_dmat)) {
b4df2201 450 device_printf(dev, "can't allocate parent DMA tag\n");
984263bc
MD
451 goto out;
452 }
453
984263bc
MD
454 /*
455 * Do bus-independent initialisation.
456 */
457 error = aac_attach(sc);
d9773475 458
984263bc
MD
459out:
460 if (error)
461 aac_free(sc);
462 return(error);
463}
d9773475
PA
464
465/*
466 * Do nothing driver that will attach to the SCSI channels of a Dell PERC
467 * controller. This is needed to keep the power management subsystem from
468 * trying to power down these devices.
469 */
470static int aacch_probe(device_t dev);
471static int aacch_attach(device_t dev);
472static int aacch_detach(device_t dev);
473
474static device_method_t aacch_methods[] = {
475 /* Device interface */
476 DEVMETHOD(device_probe, aacch_probe),
477 DEVMETHOD(device_attach, aacch_attach),
478 DEVMETHOD(device_detach, aacch_detach),
d3c9c58e 479 DEVMETHOD_END
d9773475
PA
480};
481
482struct aacch_softc {
483 device_t dev;
484};
485
486static driver_t aacch_driver = {
487 "aacch",
488 aacch_methods,
489 sizeof(struct aacch_softc)
490};
491
492static devclass_t aacch_devclass;
aa2b9d05 493DRIVER_MODULE(aacch, pci, aacch_driver, aacch_devclass, NULL, NULL);
d9773475
PA
494
495static int
496aacch_probe(device_t dev)
497{
498
499 if ((pci_get_vendor(dev) != 0x9005) ||
500 (pci_get_device(dev) != 0x00c5))
501 return (ENXIO);
502
503 device_set_desc(dev, "AAC RAID Channel");
504 return (-10);
505}
506
507static int
b4df2201 508aacch_attach(device_t dev __unused)
d9773475 509{
d9773475
PA
510
511 return (0);
512}
513
514static int
b4df2201 515aacch_detach(device_t dev __unused)
d9773475
PA
516{
517
518 return (0);
519}