ahc_pci.c revision 1.39 1 /*
2 * Product specific probe and attach routines for:
3 * 3940, 2940, aic7895, aic7890, aic7880,
4 * aic7870, aic7860 and aic7850 SCSI controllers
5 *
6 * Copyright (c) 1994-2001 Justin T. Gibbs.
7 * Copyright (c) 2000-2001 Adaptec Inc.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
17 * substantially similar to the "NO WARRANTY" disclaimer below
18 * ("Disclaimer") and any redistribution must be conditioned upon
19 * including a substantially similar Disclaimer requirement for further
20 * binary redistribution.
21 * 3. Neither the names of the above-listed copyright holders nor the names
22 * of any contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * Alternatively, this software may be distributed under the terms of the
26 * GNU General Public License ("GPL") version 2 as published by the Free
27 * Software Foundation.
28 *
29 * NO WARRANTY
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGES.
41 *
42 * $Id: ahc_pci.c,v 1.39 2003/04/19 19:34:23 fvdl Exp $
43 *
44 * //depot/aic7xxx/aic7xxx/aic7xxx_pci.c#57 $
45 *
46 * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx_pci.c,v 1.22 2003/01/20 20:44:55 gibbs Exp $
47 */
48 /*
49 * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
50 */
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/malloc.h>
55 #include <sys/kernel.h>
56 #include <sys/queue.h>
57 #include <sys/device.h>
58 #include <sys/reboot.h>
59
60 #include <machine/bus.h>
61 #include <machine/intr.h>
62
63 #include <dev/pci/pcireg.h>
64 #include <dev/pci/pcivar.h>
65
66 #define AHC_PCI_IOADDR PCI_MAPREG_START /* I/O Address */
67 #define AHC_PCI_MEMADDR (PCI_MAPREG_START + 4) /* Mem I/O Address */
68
69 #include <dev/ic/aic7xxx_osm.h>
70 #include <dev/ic/aic7xxx_inline.h>
71
72 #include <dev/ic/smc93cx6var.h>
73
74
75 static __inline uint64_t
76 ahc_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
77 {
78 uint64_t id;
79
80 id = subvendor
81 | (subdevice << 16)
82 | ((uint64_t)vendor << 32)
83 | ((uint64_t)device << 48);
84
85 return (id);
86 }
87
88 #define ID_ALL_MASK 0xFFFFFFFFFFFFFFFFull
89 #define ID_DEV_VENDOR_MASK 0xFFFFFFFF00000000ull
90 #define ID_9005_GENERIC_MASK 0xFFF0FFFF00000000ull
91 #define ID_9005_SISL_MASK 0x000FFFFF00000000ull
92 #define ID_9005_SISL_ID 0x0005900500000000ull
93 #define ID_AIC7850 0x5078900400000000ull
94 #define ID_AHA_2902_04_10_15_20_30C 0x5078900478509004ull
95 #define ID_AIC7855 0x5578900400000000ull
96 #define ID_AIC7859 0x3860900400000000ull
97 #define ID_AHA_2930CU 0x3860900438699004ull
98 #define ID_AIC7860 0x6078900400000000ull
99 #define ID_AIC7860C 0x6078900478609004ull
100 #define ID_AHA_1480A 0x6075900400000000ull
101 #define ID_AHA_2940AU_0 0x6178900400000000ull
102 #define ID_AHA_2940AU_1 0x6178900478619004ull
103 #define ID_AHA_2940AU_CN 0x2178900478219004ull
104 #define ID_AHA_2930C_VAR 0x6038900438689004ull
105
106 #define ID_AIC7870 0x7078900400000000ull
107 #define ID_AHA_2940 0x7178900400000000ull
108 #define ID_AHA_3940 0x7278900400000000ull
109 #define ID_AHA_398X 0x7378900400000000ull
110 #define ID_AHA_2944 0x7478900400000000ull
111 #define ID_AHA_3944 0x7578900400000000ull
112 #define ID_AHA_4944 0x7678900400000000ull
113
114 #define ID_AIC7880 0x8078900400000000ull
115 #define ID_AIC7880_B 0x8078900478809004ull
116 #define ID_AHA_2940U 0x8178900400000000ull
117 #define ID_AHA_3940U 0x8278900400000000ull
118 #define ID_AHA_2944U 0x8478900400000000ull
119 #define ID_AHA_3944U 0x8578900400000000ull
120 #define ID_AHA_398XU 0x8378900400000000ull
121 #define ID_AHA_4944U 0x8678900400000000ull
122 #define ID_AHA_2940UB 0x8178900478819004ull
123 #define ID_AHA_2930U 0x8878900478889004ull
124 #define ID_AHA_2940U_PRO 0x8778900478879004ull
125 #define ID_AHA_2940U_CN 0x0078900478009004ull
126
127 #define ID_AIC7895 0x7895900478959004ull
128 #define ID_AIC7895_ARO 0x7890900478939004ull
129 #define ID_AIC7895_ARO_MASK 0xFFF0FFFFFFFFFFFFull
130 #define ID_AHA_2940U_DUAL 0x7895900478919004ull
131 #define ID_AHA_3940AU 0x7895900478929004ull
132 #define ID_AHA_3944AU 0x7895900478949004ull
133
134 #define ID_AIC7890 0x001F9005000F9005ull
135 #define ID_AIC7890_ARO 0x00139005000F9005ull
136 #define ID_AAA_131U2 0x0013900500039005ull
137 #define ID_AHA_2930U2 0x0011900501819005ull
138 #define ID_AHA_2940U2B 0x00109005A1009005ull
139 #define ID_AHA_2940U2_OEM 0x0010900521809005ull
140 #define ID_AHA_2940U2 0x00109005A1809005ull
141 #define ID_AHA_2950U2B 0x00109005E1009005ull
142
143 #define ID_AIC7892 0x008F9005FFFF9005ull
144 #define ID_AIC7892_ARO 0x00839005FFFF9005ull
145 #define ID_AHA_29160 0x00809005E2A09005ull
146 #define ID_AHA_29160_CPQ 0x00809005E2A00E11ull
147 #define ID_AHA_29160N 0x0080900562A09005ull
148 #define ID_AHA_29160C 0x0080900562209005ull
149 #define ID_AHA_29160B 0x00809005E2209005ull
150 #define ID_AHA_19160B 0x0081900562A19005ull
151
152 #define ID_AIC7896 0x005F9005FFFF9005ull
153 #define ID_AIC7896_ARO 0x00539005FFFF9005ull
154 #define ID_AHA_3950U2B_0 0x00509005FFFF9005ull
155 #define ID_AHA_3950U2B_1 0x00509005F5009005ull
156 #define ID_AHA_3950U2D_0 0x00519005FFFF9005ull
157 #define ID_AHA_3950U2D_1 0x00519005B5009005ull
158
159 #define ID_AIC7899 0x00CF9005FFFF9005ull
160 #define ID_AIC7899_ARO 0x00C39005FFFF9005ull
161 #define ID_AHA_3960D 0x00C09005F6209005ull
162 #define ID_AHA_3960D_CPQ 0x00C09005F6200E11ull
163
164 #define ID_AIC7810 0x1078900400000000ull
165 #define ID_AIC7815 0x7815900400000000ull
166
167 #define DEVID_9005_TYPE(id) ((id) & 0xF)
168 #define DEVID_9005_TYPE_HBA 0x0 /* Standard Card */
169 #define DEVID_9005_TYPE_AAA 0x3 /* RAID Card */
170 #define DEVID_9005_TYPE_SISL 0x5 /* Container ROMB */
171 #define DEVID_9005_TYPE_MB 0xF /* On Motherboard */
172
173 #define DEVID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
174 #define DEVID_9005_MAXRATE_U160 0x0
175 #define DEVID_9005_MAXRATE_ULTRA2 0x1
176 #define DEVID_9005_MAXRATE_ULTRA 0x2
177 #define DEVID_9005_MAXRATE_FAST 0x3
178
179 #define DEVID_9005_MFUNC(id) (((id) & 0x40) >> 6)
180
181 #define DEVID_9005_CLASS(id) (((id) & 0xFF00) >> 8)
182 #define DEVID_9005_CLASS_SPI 0x0 /* Parallel SCSI */
183
184 #define SUBID_9005_TYPE(id) ((id) & 0xF)
185 #define SUBID_9005_TYPE_MB 0xF /* On Motherboard */
186 #define SUBID_9005_TYPE_CARD 0x0 /* Standard Card */
187 #define SUBID_9005_TYPE_LCCARD 0x1 /* Low Cost Card */
188 #define SUBID_9005_TYPE_RAID 0x3 /* Combined with Raid */
189
190 #define SUBID_9005_TYPE_KNOWN(id) \
191 ((((id) & 0xF) == SUBID_9005_TYPE_MB) \
192 || (((id) & 0xF) == SUBID_9005_TYPE_CARD) \
193 || (((id) & 0xF) == SUBID_9005_TYPE_LCCARD) \
194 || (((id) & 0xF) == SUBID_9005_TYPE_RAID))
195
196 #define SUBID_9005_MAXRATE(id) (((id) & 0x30) >> 4)
197 #define SUBID_9005_MAXRATE_ULTRA2 0x0
198 #define SUBID_9005_MAXRATE_ULTRA 0x1
199 #define SUBID_9005_MAXRATE_U160 0x2
200 #define SUBID_9005_MAXRATE_RESERVED 0x3
201
202 #define SUBID_9005_SEEPTYPE(id) \
203 ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
204 ? ((id) & 0xC0) >> 6 \
205 : ((id) & 0x300) >> 8)
206 #define SUBID_9005_SEEPTYPE_NONE 0x0
207 #define SUBID_9005_SEEPTYPE_1K 0x1
208 #define SUBID_9005_SEEPTYPE_2K_4K 0x2
209 #define SUBID_9005_SEEPTYPE_RESERVED 0x3
210 #define SUBID_9005_AUTOTERM(id) \
211 ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
212 ? (((id) & 0x400) >> 10) == 0 \
213 : (((id) & 0x40) >> 6) == 0)
214
215 #define SUBID_9005_NUMCHAN(id) \
216 ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
217 ? ((id) & 0x300) >> 8 \
218 : ((id) & 0xC00) >> 10)
219
220 #define SUBID_9005_LEGACYCONN(id) \
221 ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
222 ? 0 \
223 : ((id) & 0x80) >> 7)
224
225 #define SUBID_9005_MFUNCENB(id) \
226 ((SUBID_9005_TYPE(id) == SUBID_9005_TYPE_MB) \
227 ? ((id) & 0x800) >> 11 \
228 : ((id) & 0x1000) >> 12)
229 /*
230 * Informational only. Should use chip register to be
231 * certain, but may be use in identification strings.
232 */
233 #define SUBID_9005_CARD_SCSIWIDTH_MASK 0x2000
234 #define SUBID_9005_CARD_PCIWIDTH_MASK 0x4000
235 #define SUBID_9005_CARD_SEDIFF_MASK 0x8000
236
237 static ahc_device_setup_t ahc_aic785X_setup;
238 static ahc_device_setup_t ahc_aic7860_setup;
239 static ahc_device_setup_t ahc_apa1480_setup;
240 static ahc_device_setup_t ahc_aic7870_setup;
241 static ahc_device_setup_t ahc_aha394X_setup;
242 static ahc_device_setup_t ahc_aha494X_setup;
243 static ahc_device_setup_t ahc_aha398X_setup;
244 static ahc_device_setup_t ahc_aic7880_setup;
245 static ahc_device_setup_t ahc_aha2940Pro_setup;
246 static ahc_device_setup_t ahc_aha394XU_setup;
247 static ahc_device_setup_t ahc_aha398XU_setup;
248 static ahc_device_setup_t ahc_aic7890_setup;
249 static ahc_device_setup_t ahc_aic7892_setup;
250 static ahc_device_setup_t ahc_aic7895_setup;
251 static ahc_device_setup_t ahc_aic7896_setup;
252 static ahc_device_setup_t ahc_aic7899_setup;
253 static ahc_device_setup_t ahc_aha29160C_setup;
254 static ahc_device_setup_t ahc_raid_setup;
255 static ahc_device_setup_t ahc_aha394XX_setup;
256 static ahc_device_setup_t ahc_aha494XX_setup;
257 static ahc_device_setup_t ahc_aha398XX_setup;
258
259 struct ahc_pci_identity ahc_pci_ident_table [] =
260 {
261 /* aic7850 based controllers */
262 {
263 ID_AHA_2902_04_10_15_20_30C,
264 ID_ALL_MASK,
265 "Adaptec 2902/04/10/15/20/30C SCSI adapter",
266 ahc_aic785X_setup
267 },
268 /* aic7860 based controllers */
269 {
270 ID_AHA_2930CU,
271 ID_ALL_MASK,
272 "Adaptec 2930CU SCSI adapter",
273 ahc_aic7860_setup
274 },
275 {
276 ID_AHA_1480A & ID_DEV_VENDOR_MASK,
277 ID_DEV_VENDOR_MASK,
278 "Adaptec 1480A Ultra SCSI adapter",
279 ahc_apa1480_setup
280 },
281 {
282 ID_AHA_2940AU_0 & ID_DEV_VENDOR_MASK,
283 ID_DEV_VENDOR_MASK,
284 "Adaptec 2940A Ultra SCSI adapter",
285 ahc_aic7860_setup
286 },
287 {
288 ID_AHA_2940AU_CN & ID_DEV_VENDOR_MASK,
289 ID_DEV_VENDOR_MASK,
290 "Adaptec 2940A/CN Ultra SCSI adapter",
291 ahc_aic7860_setup
292 },
293 {
294 ID_AHA_2930C_VAR & ID_DEV_VENDOR_MASK,
295 ID_DEV_VENDOR_MASK,
296 "Adaptec 2930C Ultra SCSI adapter (VAR)",
297 ahc_aic7860_setup
298 },
299 /* aic7870 based controllers */
300 {
301 ID_AHA_2940,
302 ID_ALL_MASK,
303 "Adaptec 2940 SCSI adapter",
304 ahc_aic7870_setup
305 },
306 {
307 ID_AHA_3940,
308 ID_ALL_MASK,
309 "Adaptec 3940 SCSI adapter",
310 ahc_aha394X_setup
311 },
312 {
313 ID_AHA_398X,
314 ID_ALL_MASK,
315 "Adaptec 398X SCSI RAID adapter",
316 ahc_aha398X_setup
317 },
318 {
319 ID_AHA_2944,
320 ID_ALL_MASK,
321 "Adaptec 2944 SCSI adapter",
322 ahc_aic7870_setup
323 },
324 {
325 ID_AHA_3944,
326 ID_ALL_MASK,
327 "Adaptec 3944 SCSI adapter",
328 ahc_aha394X_setup
329 },
330 {
331 ID_AHA_4944,
332 ID_ALL_MASK,
333 "Adaptec 4944 SCSI adapter",
334 ahc_aha494X_setup
335 },
336 /* aic7880 based controllers */
337 {
338 ID_AHA_2940U & ID_DEV_VENDOR_MASK,
339 ID_DEV_VENDOR_MASK,
340 "Adaptec 2940 Ultra SCSI adapter",
341 ahc_aic7880_setup
342 },
343 {
344 ID_AHA_3940U & ID_DEV_VENDOR_MASK,
345 ID_DEV_VENDOR_MASK,
346 "Adaptec 3940 Ultra SCSI adapter",
347 ahc_aha394XU_setup
348 },
349 {
350 ID_AHA_2944U & ID_DEV_VENDOR_MASK,
351 ID_DEV_VENDOR_MASK,
352 "Adaptec 2944 Ultra SCSI adapter",
353 ahc_aic7880_setup
354 },
355 {
356 ID_AHA_3944U & ID_DEV_VENDOR_MASK,
357 ID_DEV_VENDOR_MASK,
358 "Adaptec 3944 Ultra SCSI adapter",
359 ahc_aha394XU_setup
360 },
361 {
362 ID_AHA_398XU & ID_DEV_VENDOR_MASK,
363 ID_DEV_VENDOR_MASK,
364 "Adaptec 398X Ultra SCSI RAID adapter",
365 ahc_aha398XU_setup
366 },
367 {
368 /*
369 * XXX Don't know the slot numbers
370 * so we can't identify channels
371 */
372 ID_AHA_4944U & ID_DEV_VENDOR_MASK,
373 ID_DEV_VENDOR_MASK,
374 "Adaptec 4944 Ultra SCSI adapter",
375 ahc_aic7880_setup
376 },
377 {
378 ID_AHA_2930U & ID_DEV_VENDOR_MASK,
379 ID_DEV_VENDOR_MASK,
380 "Adaptec 2930 Ultra SCSI adapter",
381 ahc_aic7880_setup
382 },
383 {
384 ID_AHA_2940U_PRO & ID_DEV_VENDOR_MASK,
385 ID_DEV_VENDOR_MASK,
386 "Adaptec 2940 Pro Ultra SCSI adapter",
387 ahc_aha2940Pro_setup
388 },
389 {
390 ID_AHA_2940U_CN & ID_DEV_VENDOR_MASK,
391 ID_DEV_VENDOR_MASK,
392 "Adaptec 2940/CN Ultra SCSI adapter",
393 ahc_aic7880_setup
394 },
395 /* Ignore all SISL (AAC on MB) based controllers. */
396 {
397 ID_9005_SISL_ID,
398 ID_9005_SISL_MASK,
399 NULL,
400 NULL
401 },
402 /* aic7890 based controllers */
403 {
404 ID_AHA_2930U2,
405 ID_ALL_MASK,
406 "Adaptec 2930 Ultra2 SCSI adapter",
407 ahc_aic7890_setup
408 },
409 {
410 ID_AHA_2940U2B,
411 ID_ALL_MASK,
412 "Adaptec 2940B Ultra2 SCSI adapter",
413 ahc_aic7890_setup
414 },
415 {
416 ID_AHA_2940U2_OEM,
417 ID_ALL_MASK,
418 "Adaptec 2940 Ultra2 SCSI adapter (OEM)",
419 ahc_aic7890_setup
420 },
421 {
422 ID_AHA_2940U2,
423 ID_ALL_MASK,
424 "Adaptec 2940 Ultra2 SCSI adapter",
425 ahc_aic7890_setup
426 },
427 {
428 ID_AHA_2950U2B,
429 ID_ALL_MASK,
430 "Adaptec 2950 Ultra2 SCSI adapter",
431 ahc_aic7890_setup
432 },
433 {
434 ID_AIC7890_ARO,
435 ID_ALL_MASK,
436 "Adaptec aic7890/91 Ultra2 SCSI adapter (ARO)",
437 ahc_aic7890_setup
438 },
439 {
440 ID_AAA_131U2,
441 ID_ALL_MASK,
442 "Adaptec AAA-131 Ultra2 RAID adapter",
443 ahc_aic7890_setup
444 },
445 /* aic7892 based controllers */
446 {
447 ID_AHA_29160,
448 ID_ALL_MASK,
449 "Adaptec 29160 Ultra160 SCSI adapter",
450 ahc_aic7892_setup
451 },
452 {
453 ID_AHA_29160_CPQ,
454 ID_ALL_MASK,
455 "Adaptec (Compaq OEM) 29160 Ultra160 SCSI adapter",
456 ahc_aic7892_setup
457 },
458 {
459 ID_AHA_29160N,
460 ID_ALL_MASK,
461 "Adaptec 29160N Ultra160 SCSI adapter",
462 ahc_aic7892_setup
463 },
464 {
465 ID_AHA_29160C,
466 ID_ALL_MASK,
467 "Adaptec 29160C Ultra160 SCSI adapter",
468 ahc_aha29160C_setup
469 },
470 {
471 ID_AHA_29160B,
472 ID_ALL_MASK,
473 "Adaptec 29160B Ultra160 SCSI adapter",
474 ahc_aic7892_setup
475 },
476 {
477 ID_AHA_19160B,
478 ID_ALL_MASK,
479 "Adaptec 19160B Ultra160 SCSI adapter",
480 ahc_aic7892_setup
481 },
482 {
483 ID_AIC7892_ARO,
484 ID_ALL_MASK,
485 "Adaptec aic7892 Ultra160 SCSI adapter (ARO)",
486 ahc_aic7892_setup
487 },
488 /* aic7895 based controllers */
489 {
490 ID_AHA_2940U_DUAL,
491 ID_ALL_MASK,
492 "Adaptec 2940/DUAL Ultra SCSI adapter",
493 ahc_aic7895_setup
494 },
495 {
496 ID_AHA_3940AU,
497 ID_ALL_MASK,
498 "Adaptec 3940A Ultra SCSI adapter",
499 ahc_aic7895_setup
500 },
501 {
502 ID_AHA_3944AU,
503 ID_ALL_MASK,
504 "Adaptec 3944A Ultra SCSI adapter",
505 ahc_aic7895_setup
506 },
507 {
508 ID_AIC7895_ARO,
509 ID_AIC7895_ARO_MASK,
510 "Adaptec aic7895 Ultra SCSI adapter (ARO)",
511 ahc_aic7895_setup
512 },
513 /* aic7896/97 based controllers */
514 {
515 ID_AHA_3950U2B_0,
516 ID_ALL_MASK,
517 "Adaptec 3950B Ultra2 SCSI adapter",
518 ahc_aic7896_setup
519 },
520 {
521 ID_AHA_3950U2B_1,
522 ID_ALL_MASK,
523 "Adaptec 3950B Ultra2 SCSI adapter",
524 ahc_aic7896_setup
525 },
526 {
527 ID_AHA_3950U2D_0,
528 ID_ALL_MASK,
529 "Adaptec 3950D Ultra2 SCSI adapter",
530 ahc_aic7896_setup
531 },
532 {
533 ID_AHA_3950U2D_1,
534 ID_ALL_MASK,
535 "Adaptec 3950D Ultra2 SCSI adapter",
536 ahc_aic7896_setup
537 },
538 {
539 ID_AIC7896_ARO,
540 ID_ALL_MASK,
541 "Adaptec aic7896/97 Ultra2 SCSI adapter (ARO)",
542 ahc_aic7896_setup
543 },
544 /* aic7899 based controllers */
545 {
546 ID_AHA_3960D,
547 ID_ALL_MASK,
548 "Adaptec 3960D Ultra160 SCSI adapter",
549 ahc_aic7899_setup
550 },
551 {
552 ID_AHA_3960D_CPQ,
553 ID_ALL_MASK,
554 "Adaptec (Compaq OEM) 3960D Ultra160 SCSI adapter",
555 ahc_aic7899_setup
556 },
557 {
558 ID_AIC7899_ARO,
559 ID_ALL_MASK,
560 "Adaptec aic7899 Ultra160 SCSI adapter (ARO)",
561 ahc_aic7899_setup
562 },
563 /* Generic chip probes for devices we don't know 'exactly' */
564 {
565 ID_AIC7850 & ID_DEV_VENDOR_MASK,
566 ID_DEV_VENDOR_MASK,
567 "Adaptec aic7850 SCSI adapter",
568 ahc_aic785X_setup
569 },
570 {
571 ID_AIC7855 & ID_DEV_VENDOR_MASK,
572 ID_DEV_VENDOR_MASK,
573 "Adaptec aic7855 SCSI adapter",
574 ahc_aic785X_setup
575 },
576 {
577 ID_AIC7859 & ID_DEV_VENDOR_MASK,
578 ID_DEV_VENDOR_MASK,
579 "Adaptec aic7859 SCSI adapter",
580 ahc_aic7860_setup
581 },
582 {
583 ID_AIC7860 & ID_DEV_VENDOR_MASK,
584 ID_DEV_VENDOR_MASK,
585 "Adaptec aic7860 Ultra SCSI adapter",
586 ahc_aic7860_setup
587 },
588 {
589 ID_AIC7870 & ID_DEV_VENDOR_MASK,
590 ID_DEV_VENDOR_MASK,
591 "Adaptec aic7870 SCSI adapter",
592 ahc_aic7870_setup
593 },
594 {
595 ID_AIC7880 & ID_DEV_VENDOR_MASK,
596 ID_DEV_VENDOR_MASK,
597 "Adaptec aic7880 Ultra SCSI adapter",
598 ahc_aic7880_setup
599 },
600 {
601 ID_AIC7890 & ID_9005_GENERIC_MASK,
602 ID_9005_GENERIC_MASK,
603 "Adaptec aic7890/91 Ultra2 SCSI adapter",
604 ahc_aic7890_setup
605 },
606 {
607 ID_AIC7892 & ID_9005_GENERIC_MASK,
608 ID_9005_GENERIC_MASK,
609 "Adaptec aic7892 Ultra160 SCSI adapter",
610 ahc_aic7892_setup
611 },
612 {
613 ID_AIC7895 & ID_DEV_VENDOR_MASK,
614 ID_DEV_VENDOR_MASK,
615 "Adaptec aic7895 Ultra SCSI adapter",
616 ahc_aic7895_setup
617 },
618 {
619 ID_AIC7896 & ID_9005_GENERIC_MASK,
620 ID_9005_GENERIC_MASK,
621 "Adaptec aic7896/97 Ultra2 SCSI adapter",
622 ahc_aic7896_setup
623 },
624 {
625 ID_AIC7899 & ID_9005_GENERIC_MASK,
626 ID_9005_GENERIC_MASK,
627 "Adaptec aic7899 Ultra160 SCSI adapter",
628 ahc_aic7899_setup
629 },
630 {
631 ID_AIC7810 & ID_DEV_VENDOR_MASK,
632 ID_DEV_VENDOR_MASK,
633 "Adaptec aic7810 RAID memory controller",
634 ahc_raid_setup
635 },
636 {
637 ID_AIC7815 & ID_DEV_VENDOR_MASK,
638 ID_DEV_VENDOR_MASK,
639 "Adaptec aic7815 RAID memory controller",
640 ahc_raid_setup
641 }
642 };
643
644 const u_int ahc_num_pci_devs = NUM_ELEMENTS(ahc_pci_ident_table);
645
646 #define AHC_394X_SLOT_CHANNEL_A 4
647 #define AHC_394X_SLOT_CHANNEL_B 5
648
649 #define AHC_398X_SLOT_CHANNEL_A 4
650 #define AHC_398X_SLOT_CHANNEL_B 8
651 #define AHC_398X_SLOT_CHANNEL_C 12
652
653 #define AHC_494X_SLOT_CHANNEL_A 4
654 #define AHC_494X_SLOT_CHANNEL_B 5
655 #define AHC_494X_SLOT_CHANNEL_C 6
656 #define AHC_494X_SLOT_CHANNEL_D 7
657
658 #define DEVCONFIG 0x40
659 #define PCIERRGENDIS 0x80000000ul
660 #define SCBSIZE32 0x00010000ul /* aic789X only */
661 #define REXTVALID 0x00001000ul /* ultra cards only */
662 #define MPORTMODE 0x00000400ul /* aic7870+ only */
663 #define RAMPSM 0x00000200ul /* aic7870+ only */
664 #define VOLSENSE 0x00000100ul
665 #define PCI64BIT 0x00000080ul /* 64Bit PCI bus (Ultra2 Only)*/
666 #define SCBRAMSEL 0x00000080ul
667 #define MRDCEN 0x00000040ul
668 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
669 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
670 #define BERREN 0x00000008ul
671 #define DACEN 0x00000004ul
672 #define STPWLEVEL 0x00000002ul
673 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
674
675 #define CSIZE_LATTIME 0x0c
676 #define CACHESIZE 0x0000003ful /* only 5 bits */
677 #define LATTIME 0x0000ff00ul
678
679 /* PCI STATUS definitions */
680 #define DPE 0x80
681 #define SSE 0x40
682 #define RMA 0x20
683 #define RTA 0x10
684 #define STA 0x08
685 #define DPR 0x01
686
687 static int ahc_9005_subdevinfo_valid(uint16_t vendor, uint16_t device,
688 uint16_t subvendor, uint16_t subdevice);
689 static int ahc_ext_scbram_present(struct ahc_softc *ahc);
690 static void ahc_scbram_config(struct ahc_softc *ahc, int enable,
691 int pcheck, int fast, int large);
692 static void ahc_probe_ext_scbram(struct ahc_softc *ahc);
693
694 int ahc_pci_probe __P((struct device *, struct cfdata *, void *));
695 void ahc_pci_attach __P((struct device *, struct device *, void *));
696
697
698 CFATTACH_DECL(ahc_pci, sizeof(struct ahc_softc),
699 ahc_pci_probe, ahc_pci_attach, NULL, NULL);
700
701 const struct ahc_pci_identity *
702 ahc_find_pci_device(id, subid, func)
703 pcireg_t id, subid;
704 u_int func;
705 {
706 u_int64_t full_id;
707 const struct ahc_pci_identity *entry;
708 u_int i;
709
710 full_id = ahc_compose_id(PCI_PRODUCT(id), PCI_VENDOR(id),
711 PCI_PRODUCT(subid), PCI_VENDOR(subid));
712
713 /*
714 * If the second function is not hooked up, ignore it.
715 * Unfortunately, not all MB vendors implement the
716 * subdevice ID as per the Adaptec spec, so do our best
717 * to sanity check it prior to accepting the subdevice
718 * ID as valid.
719 */
720 if (func > 0
721 && ahc_9005_subdevinfo_valid(PCI_VENDOR(id), PCI_PRODUCT(id),
722 PCI_VENDOR(subid), PCI_PRODUCT(subid))
723 && SUBID_9005_MFUNCENB(PCI_PRODUCT(subid)) == 0)
724 return (NULL);
725
726 for (i = 0; i < ahc_num_pci_devs; i++) {
727 entry = &ahc_pci_ident_table[i];
728 if (entry->full_id == (full_id & entry->id_mask))
729 return (entry);
730 }
731 return (NULL);
732 }
733
734 int
735 ahc_pci_probe(parent, match, aux)
736 struct device *parent;
737 struct cfdata *match;
738 void *aux;
739 {
740 struct pci_attach_args *pa = aux;
741 const struct ahc_pci_identity *entry;
742 pcireg_t subid;
743
744 subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
745 entry = ahc_find_pci_device(pa->pa_id, subid, pa->pa_function);
746 return entry != NULL ? 1 : 0;
747 }
748
749 void
750 ahc_pci_attach(parent, self, aux)
751 struct device *parent, *self;
752 void *aux;
753 {
754 struct pci_attach_args *pa = aux;
755 const struct ahc_pci_identity *entry;
756 struct ahc_softc *ahc = (void *)self;
757 pcireg_t command;
758 u_int our_id = 0;
759 u_int sxfrctl1;
760 u_int scsiseq;
761 u_int sblkctl;
762 uint8_t dscommand0;
763 uint32_t devconfig;
764 int error;
765 pcireg_t subid;
766 int ioh_valid, memh_valid;
767 bus_space_tag_t st, iot;
768 bus_space_handle_t sh, ioh;
769 #ifdef AHC_ALLOW_MEMIO
770 bus_space_tag_t memt;
771 bus_space_handle_t memh;
772 pcireg_t memtype;
773 #endif
774 pci_intr_handle_t ih;
775 const char *intrstr;
776 struct ahc_pci_busdata *bd;
777
778 ahc_set_name(ahc, ahc->sc_dev.dv_xname);
779 ahc->parent_dmat = pa->pa_dmat;
780
781 command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
782 subid = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
783 entry = ahc_find_pci_device(pa->pa_id, subid, pa->pa_function);
784 if (entry == NULL)
785 return;
786
787 /* Keep information about the PCI bus */
788 bd = malloc(sizeof (struct ahc_pci_busdata), M_DEVBUF, M_NOWAIT);
789 if (bd == NULL) {
790 printf("%s: unable to allocate bus-specific data\n", ahc_name(ahc));
791 return;
792 }
793 memset(bd, 0, sizeof(struct ahc_pci_busdata));
794
795 bd->pc = pa->pa_pc;
796 bd->tag = pa->pa_tag;
797 bd->func = pa->pa_function;
798 bd->dev = pa->pa_device;
799 bd->class = pa->pa_class;
800
801 ahc->bd = bd;
802
803 ahc->description = entry->name;
804
805 error = entry->setup(ahc);
806 if (error != 0)
807 return;
808
809 ioh_valid = memh_valid = 0;
810
811 #ifdef AHC_ALLOW_MEMIO
812 memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, AHC_PCI_MEMADDR);
813 switch (memtype) {
814 case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
815 case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
816 memh_valid = (pci_mapreg_map(pa, AHC_PCI_MEMADDR,
817 memtype, 0, &memt, &memh, NULL, NULL) == 0);
818 break;
819 default:
820 memh_valid = 0;
821 }
822 #endif
823 ioh_valid = (pci_mapreg_map(pa, AHC_PCI_IOADDR,
824 PCI_MAPREG_TYPE_IO, 0, &iot,
825 &ioh, NULL, NULL) == 0);
826 #if 0
827 printf("%s: mem mapping: memt 0x%x, memh 0x%x, iot 0x%x, ioh 0x%lx\n",
828 ahc_name(ahc), memt, (u_int32_t)memh, (u_int32_t)iot, ioh);
829 #endif
830
831 if (ioh_valid) {
832 st = iot;
833 sh = ioh;
834 #ifdef AHC_ALLOW_MEMIO
835 } else if (memh_valid) {
836 st = memt;
837 sh = memh;
838 #endif
839 } else {
840 printf(": unable to map registers\n");
841 return;
842 }
843 ahc->tag = st;
844 ahc->bsh = sh;
845
846 ahc->chip |= AHC_PCI;
847 /*
848 * Before we continue probing the card, ensure that
849 * its interrupts are *disabled*. We don't want
850 * a misstep to hang the machine in an interrupt
851 * storm.
852 */
853 ahc_intr_enable(ahc, FALSE);
854
855 devconfig = pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
856
857 /*
858 * If we need to support high memory, enable dual
859 * address cycles. This bit must be set to enable
860 * high address bit generation even if we are on a
861 * 64bit bus (PCI64BIT set in devconfig).
862 */
863 if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
864
865 if (1/*bootverbose*/)
866 printf("%s: Enabling 39Bit Addressing\n",
867 ahc_name(ahc));
868 devconfig |= DACEN;
869 }
870
871 /* Ensure that pci error generation, a test feature, is disabled. */
872 devconfig |= PCIERRGENDIS;
873
874 pci_conf_write(pa->pa_pc, pa->pa_tag, DEVCONFIG, devconfig);
875
876 /* Ensure busmastering is enabled */
877 command |= PCI_COMMAND_MASTER_ENABLE;;
878 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
879
880 /*
881 * Disable PCI parity error reporting. Users typically
882 * do this to work around broken PCI chipsets that get
883 * the parity timing wrong and thus generate lots of spurious
884 * errors.
885 */
886 if ((ahc->flags & AHC_DISABLE_PCI_PERR) != 0)
887 command &= ~PCI_COMMAND_PARITY_ENABLE;
888 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
889
890 /* On all PCI adapters, we allow SCB paging */
891 ahc->flags |= AHC_PAGESCBS;
892 error = ahc_softc_init(ahc);
893 if (error != 0)
894 goto error_out;
895
896 ahc->bus_intr = ahc_pci_intr;
897
898 /* Remember how the card was setup in case there is no SEEPROM */
899 if ((ahc_inb(ahc, HCNTRL) & POWRDN) == 0) {
900 ahc_pause(ahc);
901 if ((ahc->features & AHC_ULTRA2) != 0)
902 our_id = ahc_inb(ahc, SCSIID_ULTRA2) & OID;
903 else
904 our_id = ahc_inb(ahc, SCSIID) & OID;
905 sxfrctl1 = ahc_inb(ahc, SXFRCTL1) & STPWEN;
906 scsiseq = ahc_inb(ahc, SCSISEQ);
907 } else {
908 sxfrctl1 = STPWEN;
909 our_id = 7;
910 scsiseq = 0;
911 }
912
913 error = ahc_reset(ahc);
914 if (error != 0)
915 goto error_out;
916
917 if ((ahc->features & AHC_DT) != 0) {
918 u_int sfunct;
919
920 /* Perform ALT-Mode Setup */
921 sfunct = ahc_inb(ahc, SFUNCT) & ~ALT_MODE;
922 ahc_outb(ahc, SFUNCT, sfunct | ALT_MODE);
923 ahc_outb(ahc, OPTIONMODE,
924 OPTIONMODE_DEFAULTS|AUTOACKEN|BUSFREEREV|EXPPHASEDIS);
925 ahc_outb(ahc, SFUNCT, sfunct);
926
927 /* Normal mode setup */
928 ahc_outb(ahc, CRCCONTROL1, CRCVALCHKEN|CRCENDCHKEN|CRCREQCHKEN
929 |TARGCRCENDEN);
930 }
931
932 if (pci_intr_map(pa, &ih)) {
933 printf("%s: couldn't map interrupt\n", ahc_name(ahc));
934 ahc_free(ahc);
935 return;
936 }
937 intrstr = pci_intr_string(pa->pa_pc, ih);
938 ahc->ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ahc_intr, ahc);
939 if (ahc->ih == NULL) {
940 printf("%s: couldn't establish interrupt",
941 ahc->sc_dev.dv_xname);
942 if (intrstr != NULL)
943 printf(" at %s", intrstr);
944 printf("\n");
945 ahc_free(ahc);
946 return;
947 }
948 printf("\n");
949 if (intrstr != NULL)
950 printf("%s: interrupting at %s\n", ahc_name(ahc), intrstr);
951
952 dscommand0 = ahc_inb(ahc, DSCOMMAND0);
953 dscommand0 |= MPARCKEN|CACHETHEN;
954 if ((ahc->features & AHC_ULTRA2) != 0) {
955
956 /*
957 * DPARCKEN doesn't work correctly on
958 * some MBs so don't use it.
959 */
960 dscommand0 &= ~DPARCKEN;
961 }
962
963 /*
964 * Handle chips that must have cache line
965 * streaming (dis/en)abled.
966 */
967 if ((ahc->bugs & AHC_CACHETHEN_DIS_BUG) != 0)
968 dscommand0 |= CACHETHEN;
969
970 if ((ahc->bugs & AHC_CACHETHEN_BUG) != 0)
971 dscommand0 &= ~CACHETHEN;
972
973 ahc_outb(ahc, DSCOMMAND0, dscommand0);
974
975 ahc->pci_cachesize =
976 pci_conf_read(pa->pa_pc, pa->pa_tag, CSIZE_LATTIME) & CACHESIZE;
977 ahc->pci_cachesize *= 4;
978
979 if ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0
980 && ahc->pci_cachesize == 4) {
981 pci_conf_write(pa->pa_pc, pa->pa_tag, CSIZE_LATTIME, 0);
982 ahc->pci_cachesize = 0;
983 }
984
985 /*
986 * We cannot perform ULTRA speeds without the presence
987 * of the external precision resistor.
988 */
989 if ((ahc->features & AHC_ULTRA) != 0) {
990 uint32_t devconfig;
991
992 devconfig = pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
993 if ((devconfig & REXTVALID) == 0)
994 ahc->features &= ~AHC_ULTRA;
995 }
996
997 ahc->seep_config = malloc(sizeof(*ahc->seep_config),
998 M_DEVBUF, M_NOWAIT);
999 if (ahc->seep_config == NULL)
1000 goto error_out;
1001
1002 memset(ahc->seep_config, 0, sizeof(*ahc->seep_config));
1003
1004 /* See if we have a SEEPROM and perform auto-term */
1005 ahc_check_extport(ahc, &sxfrctl1);
1006
1007 /*
1008 * Take the LED out of diagnostic mode
1009 */
1010 sblkctl = ahc_inb(ahc, SBLKCTL);
1011 ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
1012
1013 if ((ahc->features & AHC_ULTRA2) != 0) {
1014 ahc_outb(ahc, DFF_THRSH, RD_DFTHRSH_MAX|WR_DFTHRSH_MAX);
1015 } else {
1016 ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
1017 }
1018
1019 if (ahc->flags & AHC_USEDEFAULTS) {
1020 /*
1021 * PCI Adapter default setup
1022 * Should only be used if the adapter does not have
1023 * a SEEPROM.
1024 */
1025 /* See if someone else set us up already */
1026 if ((ahc->flags & AHC_NO_BIOS_INIT) == 0
1027 && scsiseq != 0) {
1028 printf("%s: Using left over BIOS settings\n",
1029 ahc_name(ahc));
1030 ahc->flags &= ~AHC_USEDEFAULTS;
1031 ahc->flags |= AHC_BIOS_ENABLED;
1032 } else {
1033 /*
1034 * Assume only one connector and always turn
1035 * on termination.
1036 */
1037 our_id = 0x07;
1038 sxfrctl1 = STPWEN;
1039 }
1040 ahc_outb(ahc, SCSICONF, our_id|ENSPCHK|RESET_SCSI);
1041
1042 ahc->our_id = our_id;
1043 }
1044
1045 /*
1046 * Take a look to see if we have external SRAM.
1047 * We currently do not attempt to use SRAM that is
1048 * shared among multiple controllers.
1049 */
1050 ahc_probe_ext_scbram(ahc);
1051
1052 /*
1053 * Record our termination setting for the
1054 * generic initialization routine.
1055 */
1056 if ((sxfrctl1 & STPWEN) != 0)
1057 ahc->flags |= AHC_TERM_ENB_A;
1058
1059 if (ahc_init(ahc))
1060 goto error_out;
1061
1062 ahc_attach(ahc);
1063
1064 return;
1065
1066 error_out:
1067 ahc_free(ahc);
1068 return;
1069 }
1070
1071 static int
1072 ahc_9005_subdevinfo_valid(uint16_t device, uint16_t vendor,
1073 uint16_t subdevice, uint16_t subvendor)
1074 {
1075 int result;
1076
1077 /* Default to invalid. */
1078 result = 0;
1079 if (vendor == 0x9005
1080 && subvendor == 0x9005
1081 && subdevice != device
1082 && SUBID_9005_TYPE_KNOWN(subdevice) != 0) {
1083
1084 switch (SUBID_9005_TYPE(subdevice)) {
1085 case SUBID_9005_TYPE_MB:
1086 break;
1087 case SUBID_9005_TYPE_CARD:
1088 case SUBID_9005_TYPE_LCCARD:
1089 /*
1090 * Currently only trust Adaptec cards to
1091 * get the sub device info correct.
1092 */
1093 if (DEVID_9005_TYPE(device) == DEVID_9005_TYPE_HBA)
1094 result = 1;
1095 break;
1096 case SUBID_9005_TYPE_RAID:
1097 break;
1098 default:
1099 break;
1100 }
1101 }
1102 return (result);
1103 }
1104
1105
1106 /*
1107 * Test for the presense of external sram in an
1108 * "unshared" configuration.
1109 */
1110 static int
1111 ahc_ext_scbram_present(struct ahc_softc *ahc)
1112 {
1113 u_int chip;
1114 int ramps;
1115 int single_user;
1116 uint32_t devconfig;
1117
1118 chip = ahc->chip & AHC_CHIPID_MASK;
1119 devconfig = pci_conf_read(ahc->bd->pc, ahc->bd->tag, DEVCONFIG);
1120 single_user = (devconfig & MPORTMODE) != 0;
1121
1122 if ((ahc->features & AHC_ULTRA2) != 0)
1123 ramps = (ahc_inb(ahc, DSCOMMAND0) & RAMPS) != 0;
1124 else if (chip == AHC_AIC7895 || chip == AHC_AIC7895C)
1125 /*
1126 * External SCBRAM arbitration is flakey
1127 * on these chips. Unfortunately this means
1128 * we don't use the extra SCB ram space on the
1129 * 3940AUW.
1130 */
1131 ramps = 0;
1132 else if (chip >= AHC_AIC7870)
1133 ramps = (devconfig & RAMPSM) != 0;
1134 else
1135 ramps = 0;
1136
1137 if (ramps && single_user)
1138 return (1);
1139 return (0);
1140 }
1141
1142 /*
1143 * Enable external scbram.
1144 */
1145 static void
1146 ahc_scbram_config(struct ahc_softc *ahc, int enable, int pcheck,
1147 int fast, int large)
1148 {
1149 uint32_t devconfig;
1150
1151 if (ahc->features & AHC_MULTI_FUNC) {
1152 /*
1153 * Set the SCB Base addr (highest address bit)
1154 * depending on which channel we are.
1155 */
1156 ahc_outb(ahc, SCBBADDR, ahc->bd->func);
1157 }
1158
1159 ahc->flags &= ~AHC_LSCBS_ENABLED;
1160 if (large)
1161 ahc->flags |= AHC_LSCBS_ENABLED;
1162 devconfig = pci_conf_read(ahc->bd->pc, ahc->bd->tag, DEVCONFIG);
1163 if ((ahc->features & AHC_ULTRA2) != 0) {
1164 u_int dscommand0;
1165
1166 dscommand0 = ahc_inb(ahc, DSCOMMAND0);
1167 if (enable)
1168 dscommand0 &= ~INTSCBRAMSEL;
1169 else
1170 dscommand0 |= INTSCBRAMSEL;
1171 if (large)
1172 dscommand0 &= ~USCBSIZE32;
1173 else
1174 dscommand0 |= USCBSIZE32;
1175 ahc_outb(ahc, DSCOMMAND0, dscommand0);
1176 } else {
1177 if (fast)
1178 devconfig &= ~EXTSCBTIME;
1179 else
1180 devconfig |= EXTSCBTIME;
1181 if (enable)
1182 devconfig &= ~SCBRAMSEL;
1183 else
1184 devconfig |= SCBRAMSEL;
1185 if (large)
1186 devconfig &= ~SCBSIZE32;
1187 else
1188 devconfig |= SCBSIZE32;
1189 }
1190 if (pcheck)
1191 devconfig |= EXTSCBPEN;
1192 else
1193 devconfig &= ~EXTSCBPEN;
1194
1195 pci_conf_write(ahc->bd->pc, ahc->bd->tag, DEVCONFIG, devconfig);
1196 }
1197
1198 /*
1199 * Take a look to see if we have external SRAM.
1200 * We currently do not attempt to use SRAM that is
1201 * shared among multiple controllers.
1202 */
1203 static void
1204 ahc_probe_ext_scbram(struct ahc_softc *ahc)
1205 {
1206 int num_scbs;
1207 int test_num_scbs;
1208 int enable;
1209 int pcheck;
1210 int fast;
1211 int large;
1212
1213 enable = FALSE;
1214 pcheck = FALSE;
1215 fast = FALSE;
1216 large = FALSE;
1217 num_scbs = 0;
1218
1219 if (ahc_ext_scbram_present(ahc) == 0)
1220 goto done;
1221
1222 /*
1223 * Probe for the best parameters to use.
1224 */
1225 ahc_scbram_config(ahc, /*enable*/TRUE, pcheck, fast, large);
1226 num_scbs = ahc_probe_scbs(ahc);
1227 if (num_scbs == 0) {
1228 /* The SRAM wasn't really present. */
1229 goto done;
1230 }
1231 enable = TRUE;
1232
1233 /*
1234 * Clear any outstanding parity error
1235 * and ensure that parity error reporting
1236 * is enabled.
1237 */
1238 ahc_outb(ahc, SEQCTL, 0);
1239 ahc_outb(ahc, CLRINT, CLRPARERR);
1240 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
1241
1242 /* Now see if we can do parity */
1243 ahc_scbram_config(ahc, enable, /*pcheck*/TRUE, fast, large);
1244 num_scbs = ahc_probe_scbs(ahc);
1245 if ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
1246 || (ahc_inb(ahc, ERROR) & MPARERR) == 0)
1247 pcheck = TRUE;
1248
1249 /* Clear any resulting parity error */
1250 ahc_outb(ahc, CLRINT, CLRPARERR);
1251 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
1252
1253 /* Now see if we can do fast timing */
1254 ahc_scbram_config(ahc, enable, pcheck, /*fast*/TRUE, large);
1255 test_num_scbs = ahc_probe_scbs(ahc);
1256 if (test_num_scbs == num_scbs
1257 && ((ahc_inb(ahc, INTSTAT) & BRKADRINT) == 0
1258 || (ahc_inb(ahc, ERROR) & MPARERR) == 0))
1259 fast = TRUE;
1260
1261 /*
1262 * See if we can use large SCBs and still maintain
1263 * the same overall count of SCBs.
1264 */
1265 if ((ahc->features & AHC_LARGE_SCBS) != 0) {
1266 ahc_scbram_config(ahc, enable, pcheck, fast, /*large*/TRUE);
1267 test_num_scbs = ahc_probe_scbs(ahc);
1268 if (test_num_scbs >= num_scbs) {
1269 large = TRUE;
1270 num_scbs = test_num_scbs;
1271 if (num_scbs >= 64) {
1272 /*
1273 * We have enough space to move the
1274 * "busy targets table" into SCB space
1275 * and make it qualify all the way to the
1276 * lun level.
1277 */
1278 ahc->flags |= AHC_SCB_BTT;
1279 }
1280 }
1281 }
1282 done:
1283 /*
1284 * Disable parity error reporting until we
1285 * can load instruction ram.
1286 */
1287 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
1288 /* Clear any latched parity error */
1289 ahc_outb(ahc, CLRINT, CLRPARERR);
1290 ahc_outb(ahc, CLRINT, CLRBRKADRINT);
1291 if (1/*bootverbose*/ && enable) {
1292 printf("%s: External SRAM, %s access%s, %dbytes/SCB\n",
1293 ahc_name(ahc), fast ? "fast" : "slow",
1294 pcheck ? ", parity checking enabled" : "",
1295 large ? 64 : 32);
1296 }
1297 ahc_scbram_config(ahc, enable, pcheck, fast, large);
1298 }
1299
1300 #if 0
1301 /*
1302 * Perform some simple tests that should catch situations where
1303 * our registers are invalidly mapped.
1304 */
1305 int
1306 ahc_pci_test_register_access(struct ahc_softc *ahc)
1307 {
1308 int error;
1309 u_int status1;
1310 uint32_t cmd;
1311 uint8_t hcntrl;
1312
1313 error = EIO;
1314
1315 /*
1316 * Enable PCI error interrupt status, but suppress NMIs
1317 * generated by SERR raised due to target aborts.
1318 */
1319 cmd = pci_conf_read(ahc->bd->pc, ahc->bd->tag, PCIR_COMMAND);
1320 pci_conf_write(ahc->bd->pc, ahc->bd->tag, PCIR_COMMAND,
1321 cmd & ~PCIM_CMD_SERRESPEN);
1322
1323 /*
1324 * First a simple test to see if any
1325 * registers can be read. Reading
1326 * HCNTRL has no side effects and has
1327 * at least one bit that is guaranteed to
1328 * be zero so it is a good register to
1329 * use for this test.
1330 */
1331 hcntrl = ahc_inb(ahc, HCNTRL);
1332 if (hcntrl == 0xFF)
1333 goto fail;
1334
1335 /*
1336 * Next create a situation where write combining
1337 * or read prefetching could be initiated by the
1338 * CPU or host bridge. Our device does not support
1339 * either, so look for data corruption and/or flagged
1340 * PCI errors.
1341 */
1342 ahc_outb(ahc, HCNTRL, hcntrl|PAUSE);
1343 while (ahc_is_paused(ahc) == 0)
1344 ;
1345 ahc_outb(ahc, SEQCTL, PERRORDIS);
1346 ahc_outb(ahc, SCBPTR, 0);
1347 ahc_outl(ahc, SCB_BASE, 0x5aa555aa);
1348 if (ahc_inl(ahc, SCB_BASE) != 0x5aa555aa)
1349 goto fail;
1350
1351 status1 = pci_conf_read(ahc->bd->pc, ahc->bd->tag,
1352 PCI_COMMAND_STATUS_REG + 1);
1353 if ((status1 & STA) != 0)
1354 goto fail;
1355
1356 error = 0;
1357
1358 fail:
1359 /* Silently clear any latched errors. */
1360 status1 = pci_conf_read(ahc->bd->pc, ahc->bd->tag, PCI_COMMAND_STATUS_REG + 1);
1361 ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
1362 status1, /*bytes*/1);
1363 ahc_outb(ahc, CLRINT, CLRPARERR);
1364 ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
1365 ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
1366 return (error);
1367 }
1368 #endif
1369
1370 void
1371 ahc_pci_intr(struct ahc_softc *ahc)
1372 {
1373 u_int error;
1374 u_int status1;
1375
1376 error = ahc_inb(ahc, ERROR);
1377 if ((error & PCIERRSTAT) == 0)
1378 return;
1379
1380 status1 = pci_conf_read(ahc->bd->pc, ahc->bd->tag, PCI_COMMAND_STATUS_REG);
1381
1382 printf("%s: PCI error Interrupt at seqaddr = 0x%x\n",
1383 ahc_name(ahc),
1384 ahc_inb(ahc, SEQADDR0) | (ahc_inb(ahc, SEQADDR1) << 8));
1385
1386 if (status1 & DPE) {
1387 printf("%s: Data Parity Error Detected during address "
1388 "or write data phase\n", ahc_name(ahc));
1389 }
1390 if (status1 & SSE) {
1391 printf("%s: Signal System Error Detected\n", ahc_name(ahc));
1392 }
1393 if (status1 & RMA) {
1394 printf("%s: Received a Master Abort\n", ahc_name(ahc));
1395 }
1396 if (status1 & RTA) {
1397 printf("%s: Received a Target Abort\n", ahc_name(ahc));
1398 }
1399 if (status1 & STA) {
1400 printf("%s: Signaled a Target Abort\n", ahc_name(ahc));
1401 }
1402 if (status1 & DPR) {
1403 printf("%s: Data Parity Error has been reported via PERR#\n",
1404 ahc_name(ahc));
1405 }
1406
1407 /* Clear latched errors. */
1408 pci_conf_write(ahc->bd->pc, ahc->bd->tag, PCI_COMMAND_STATUS_REG, status1);
1409
1410 if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
1411 printf("%s: Latched PCIERR interrupt with "
1412 "no status bits set\n", ahc_name(ahc));
1413 } else {
1414 ahc_outb(ahc, CLRINT, CLRPARERR);
1415 }
1416
1417 ahc_unpause(ahc);
1418 }
1419
1420 static int
1421 ahc_aic785X_setup(struct ahc_softc *ahc)
1422 {
1423 uint8_t rev;
1424
1425 ahc->channel = 'A';
1426 ahc->chip = AHC_AIC7850;
1427 ahc->features = AHC_AIC7850_FE;
1428 ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
1429 rev = PCI_REVISION(ahc->bd->class);
1430 if (rev >= 1)
1431 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
1432 return (0);
1433 }
1434
1435 static int
1436 ahc_aic7860_setup(struct ahc_softc *ahc)
1437 {
1438 uint8_t rev;
1439
1440 ahc->channel = 'A';
1441 ahc->chip = AHC_AIC7860;
1442 ahc->features = AHC_AIC7860_FE;
1443 ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
1444 rev = PCI_REVISION(ahc->bd->class);
1445 if (rev >= 1)
1446 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
1447 return (0);
1448 }
1449
1450 static int
1451 ahc_apa1480_setup(struct ahc_softc *ahc)
1452 {
1453 int error;
1454
1455 error = ahc_aic7860_setup(ahc);
1456 if (error != 0)
1457 return (error);
1458 ahc->features |= AHC_REMOVABLE;
1459 return (0);
1460 }
1461
1462 static int
1463 ahc_aic7870_setup(struct ahc_softc *ahc)
1464 {
1465
1466 ahc->channel = 'A';
1467 ahc->chip = AHC_AIC7870;
1468 ahc->features = AHC_AIC7870_FE;
1469 ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
1470 return (0);
1471 }
1472
1473 static int
1474 ahc_aha394X_setup(struct ahc_softc *ahc)
1475 {
1476 int error;
1477
1478 error = ahc_aic7870_setup(ahc);
1479 if (error == 0)
1480 error = ahc_aha394XX_setup(ahc);
1481 return (error);
1482 }
1483
1484 static int
1485 ahc_aha398X_setup(struct ahc_softc *ahc)
1486 {
1487 int error;
1488
1489 error = ahc_aic7870_setup(ahc);
1490 if (error == 0)
1491 error = ahc_aha398XX_setup(ahc);
1492 return (error);
1493 }
1494
1495 static int
1496 ahc_aha494X_setup(struct ahc_softc *ahc)
1497 {
1498 int error;
1499
1500 error = ahc_aic7870_setup(ahc);
1501 if (error == 0)
1502 error = ahc_aha494XX_setup(ahc);
1503 return (error);
1504 }
1505
1506 static int
1507 ahc_aic7880_setup(struct ahc_softc *ahc)
1508 {
1509 uint8_t rev;
1510
1511 ahc->channel = 'A';
1512 ahc->chip = AHC_AIC7880;
1513 ahc->features = AHC_AIC7880_FE;
1514 ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
1515 rev = PCI_REVISION(ahc->bd->class);
1516 if (rev >= 1) {
1517 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
1518 } else {
1519 ahc->bugs |= AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
1520 }
1521 return (0);
1522 }
1523
1524 static int
1525 ahc_aha2940Pro_setup(struct ahc_softc *ahc)
1526 {
1527
1528 ahc->flags |= AHC_INT50_SPEEDFLEX;
1529 return (ahc_aic7880_setup(ahc));
1530 }
1531
1532 static int
1533 ahc_aha394XU_setup(struct ahc_softc *ahc)
1534 {
1535 int error;
1536
1537 error = ahc_aic7880_setup(ahc);
1538 if (error == 0)
1539 error = ahc_aha394XX_setup(ahc);
1540 return (error);
1541 }
1542
1543 static int
1544 ahc_aha398XU_setup(struct ahc_softc *ahc)
1545 {
1546 int error;
1547
1548 error = ahc_aic7880_setup(ahc);
1549 if (error == 0)
1550 error = ahc_aha398XX_setup(ahc);
1551 return (error);
1552 }
1553
1554 static int
1555 ahc_aic7890_setup(struct ahc_softc *ahc)
1556 {
1557 uint8_t rev;
1558
1559 ahc->channel = 'A';
1560 ahc->chip = AHC_AIC7890;
1561 ahc->features = AHC_AIC7890_FE;
1562 ahc->flags |= AHC_NEWEEPROM_FMT;
1563 rev = PCI_REVISION(ahc->bd->class);
1564 if (rev == 0)
1565 ahc->bugs |= AHC_AUTOFLUSH_BUG|AHC_CACHETHEN_BUG;
1566 return (0);
1567 }
1568
1569 static int
1570 ahc_aic7892_setup(struct ahc_softc *ahc)
1571 {
1572
1573 ahc->channel = 'A';
1574 ahc->chip = AHC_AIC7892;
1575 ahc->features = AHC_AIC7892_FE;
1576 ahc->flags |= AHC_NEWEEPROM_FMT;
1577 ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
1578 return (0);
1579 }
1580
1581 static int
1582 ahc_aic7895_setup(struct ahc_softc *ahc)
1583 {
1584 uint8_t rev;
1585
1586 ahc->channel = (ahc->bd->func == 1) ? 'B' : 'A';
1587 /*
1588 * The 'C' revision of the aic7895 has a few additional features.
1589 */
1590 rev = PCI_REVISION(ahc->bd->class);
1591 if (rev >= 4) {
1592 ahc->chip = AHC_AIC7895C;
1593 ahc->features = AHC_AIC7895C_FE;
1594 } else {
1595 u_int command;
1596
1597 ahc->chip = AHC_AIC7895;
1598 ahc->features = AHC_AIC7895_FE;
1599
1600 /*
1601 * The BIOS disables the use of MWI transactions
1602 * since it does not have the MWI bug work around
1603 * we have. Disabling MWI reduces performance, so
1604 * turn it on again.
1605 */
1606 command = pci_conf_read(ahc->bd->pc, ahc->bd->tag, PCI_COMMAND_STATUS_REG);
1607 command |= PCI_COMMAND_INVALIDATE_ENABLE;
1608 pci_conf_write(ahc->bd->pc, ahc->bd->tag, PCI_COMMAND_STATUS_REG, command);
1609 ahc->bugs |= AHC_PCI_MWI_BUG;
1610 }
1611 /*
1612 * XXX Does CACHETHEN really not work??? What about PCI retry?
1613 * on C level chips. Need to test, but for now, play it safe.
1614 */
1615 ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_PCI_2_1_RETRY_BUG
1616 | AHC_CACHETHEN_BUG;
1617
1618 #if 0
1619 uint32_t devconfig;
1620
1621 /*
1622 * Cachesize must also be zero due to stray DAC
1623 * problem when sitting behind some bridges.
1624 */
1625 pci_conf_write(ahc->bd->pc, ahc->bd->tag, CSIZE_LATTIME, 0);
1626 devconfig = pci_conf_read(ahc->bd->pc, ahc->bd->tag, DEVCONFIG);
1627 devconfig |= MRDCEN;
1628 pci_conf_write(ahc->bd->pc, ahc->bd->tag, DEVCONFIG, devconfig);
1629 #endif
1630 ahc->flags |= AHC_NEWEEPROM_FMT;
1631 return (0);
1632 }
1633
1634 static int
1635 ahc_aic7896_setup(struct ahc_softc *ahc)
1636 {
1637 ahc->channel = (ahc->bd->func == 1) ? 'B' : 'A';
1638 ahc->chip = AHC_AIC7896;
1639 ahc->features = AHC_AIC7896_FE;
1640 ahc->flags |= AHC_NEWEEPROM_FMT;
1641 ahc->bugs |= AHC_CACHETHEN_DIS_BUG;
1642 return (0);
1643 }
1644
1645 static int
1646 ahc_aic7899_setup(struct ahc_softc *ahc)
1647 {
1648 ahc->channel = (ahc->bd->func == 1) ? 'B' : 'A';
1649 ahc->chip = AHC_AIC7899;
1650 ahc->features = AHC_AIC7899_FE;
1651 ahc->flags |= AHC_NEWEEPROM_FMT;
1652 ahc->bugs |= AHC_SCBCHAN_UPLOAD_BUG;
1653 return (0);
1654 }
1655
1656 static int
1657 ahc_aha29160C_setup(struct ahc_softc *ahc)
1658 {
1659 int error;
1660
1661 error = ahc_aic7899_setup(ahc);
1662 if (error != 0)
1663 return (error);
1664 ahc->features |= AHC_REMOVABLE;
1665 return (0);
1666 }
1667
1668 static int
1669 ahc_raid_setup(struct ahc_softc *ahc)
1670 {
1671 printf("RAID functionality unsupported\n");
1672 return (ENXIO);
1673 }
1674
1675 static int
1676 ahc_aha394XX_setup(struct ahc_softc *ahc)
1677 {
1678
1679 switch (ahc->bd->dev) {
1680 case AHC_394X_SLOT_CHANNEL_A:
1681 ahc->channel = 'A';
1682 break;
1683 case AHC_394X_SLOT_CHANNEL_B:
1684 ahc->channel = 'B';
1685 break;
1686 default:
1687 printf("adapter at unexpected slot %d\n"
1688 "unable to map to a channel\n",
1689 ahc->bd->dev);
1690 ahc->channel = 'A';
1691 }
1692 return (0);
1693 }
1694
1695 static int
1696 ahc_aha398XX_setup(struct ahc_softc *ahc)
1697 {
1698
1699 switch (ahc->bd->dev) {
1700 case AHC_398X_SLOT_CHANNEL_A:
1701 ahc->channel = 'A';
1702 break;
1703 case AHC_398X_SLOT_CHANNEL_B:
1704 ahc->channel = 'B';
1705 break;
1706 case AHC_398X_SLOT_CHANNEL_C:
1707 ahc->channel = 'C';
1708 break;
1709 default:
1710 printf("adapter at unexpected slot %d\n"
1711 "unable to map to a channel\n",
1712 ahc->bd->dev);
1713 ahc->channel = 'A';
1714 break;
1715 }
1716 ahc->flags |= AHC_LARGE_SEEPROM;
1717 return (0);
1718 }
1719
1720 static int
1721 ahc_aha494XX_setup(struct ahc_softc *ahc)
1722 {
1723
1724 switch (ahc->bd->dev) {
1725 case AHC_494X_SLOT_CHANNEL_A:
1726 ahc->channel = 'A';
1727 break;
1728 case AHC_494X_SLOT_CHANNEL_B:
1729 ahc->channel = 'B';
1730 break;
1731 case AHC_494X_SLOT_CHANNEL_C:
1732 ahc->channel = 'C';
1733 break;
1734 case AHC_494X_SLOT_CHANNEL_D:
1735 ahc->channel = 'D';
1736 break;
1737 default:
1738 printf("adapter at unexpected slot %d\n"
1739 "unable to map to a channel\n",
1740 ahc->bd->dev);
1741 ahc->channel = 'A';
1742 }
1743 ahc->flags |= AHC_LARGE_SEEPROM;
1744 return (0);
1745 }
1746