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