ahc_pci.c revision 1.20 1 1.20 thorpej /* $NetBSD: ahc_pci.c,v 1.20 2000/01/26 06:04:41 thorpej Exp $ */
2 1.2 thorpej
3 1.1 mycroft /*
4 1.1 mycroft * Product specific probe and attach routines for:
5 1.1 mycroft * 3940, 2940, aic7880, aic7870, aic7860 and aic7850 SCSI controllers
6 1.1 mycroft *
7 1.1 mycroft * Copyright (c) 1995, 1996 Justin T. Gibbs.
8 1.1 mycroft * All rights reserved.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice immediately at the beginning of the file, without modification,
15 1.1 mycroft * this list of conditions, and the following disclaimer.
16 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
18 1.1 mycroft * documentation and/or other materials provided with the distribution.
19 1.1 mycroft * 3. The name of the author may not be used to endorse or promote products
20 1.1 mycroft * derived from this software without specific prior written permission.
21 1.1 mycroft *
22 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 1.1 mycroft * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 mycroft * SUCH DAMAGE.
33 1.3 explorer *
34 1.3 explorer * from Id: aic7870.c,v 1.37 1996/06/08 06:55:55 gibbs Exp
35 1.1 mycroft */
36 1.1 mycroft
37 1.1 mycroft #if defined(__FreeBSD__)
38 1.1 mycroft #include <pci.h>
39 1.1 mycroft #endif
40 1.1 mycroft #if NPCI > 0 || defined(__NetBSD__)
41 1.1 mycroft #include <sys/param.h>
42 1.1 mycroft #include <sys/systm.h>
43 1.1 mycroft #include <sys/malloc.h>
44 1.1 mycroft #include <sys/kernel.h>
45 1.1 mycroft #include <sys/queue.h>
46 1.1 mycroft #if defined(__NetBSD__)
47 1.1 mycroft #include <sys/device.h>
48 1.1 mycroft #include <machine/bus.h>
49 1.1 mycroft #include <machine/intr.h>
50 1.1 mycroft #endif /* defined(__NetBSD__) */
51 1.1 mycroft
52 1.16 bouyer #include <dev/scsipi/scsi_all.h>
53 1.16 bouyer #include <dev/scsipi/scsipi_all.h>
54 1.16 bouyer #if defined (__NetBSD__)
55 1.16 bouyer #endif
56 1.16 bouyer #include <dev/scsipi/scsiconf.h>
57 1.1 mycroft
58 1.1 mycroft #if defined(__FreeBSD__)
59 1.1 mycroft
60 1.1 mycroft #include <pci/pcireg.h>
61 1.1 mycroft #include <pci/pcivar.h>
62 1.1 mycroft
63 1.1 mycroft #include <machine/clock.h>
64 1.1 mycroft
65 1.1 mycroft #include <i386/scsi/aic7xxx.h>
66 1.1 mycroft #include <i386/scsi/93cx6.h>
67 1.1 mycroft
68 1.1 mycroft #include <dev/aic7xxx/aic7xxx_reg.h>
69 1.1 mycroft
70 1.1 mycroft #define PCI_BASEADR0 PCI_MAP_REG_START
71 1.1 mycroft
72 1.1 mycroft #elif defined(__NetBSD__)
73 1.1 mycroft
74 1.1 mycroft #include <dev/pci/pcireg.h>
75 1.1 mycroft #include <dev/pci/pcivar.h>
76 1.1 mycroft
77 1.1 mycroft #include <dev/ic/aic7xxxreg.h>
78 1.1 mycroft #include <dev/ic/aic7xxxvar.h>
79 1.1 mycroft
80 1.5 thorpej /*
81 1.5 thorpej * Under normal circumstances, these messages are unnecessary
82 1.5 thorpej * and not terribly cosmetic.
83 1.5 thorpej */
84 1.5 thorpej #ifdef DEBUG
85 1.1 mycroft #define bootverbose 1
86 1.5 thorpej #else
87 1.5 thorpej #define bootverbose 0
88 1.5 thorpej #endif
89 1.5 thorpej
90 1.12 cgd #define PCI_BASEADR_IO 0x10
91 1.12 cgd #define PCI_BASEADR_MEM 0x14
92 1.12 cgd
93 1.1 mycroft #endif /* defined(__NetBSD__) */
94 1.1 mycroft
95 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_3940U 0x82789004ul
96 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_2944U 0x84789004ul
97 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_2940U 0x81789004ul
98 1.19 hannken #define PCI_DEVICE_ID_ADAPTEC_2940UP 0x87789004ul
99 1.6 gibbs #define PCI_DEVICE_ID_ADAPTEC_2940AU 0x61789004ul
100 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_3940 0x72789004ul
101 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_2944 0x74789004ul
102 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_2940 0x71789004ul
103 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_AIC7880 0x80789004ul
104 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_AIC7870 0x70789004ul
105 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_AIC7860 0x60789004ul
106 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_AIC7855 0x55789004ul
107 1.1 mycroft #define PCI_DEVICE_ID_ADAPTEC_AIC7850 0x50789004ul
108 1.1 mycroft
109 1.1 mycroft #define DEVCONFIG 0x40
110 1.1 mycroft #define MPORTMODE 0x00000400ul /* aic7870 only */
111 1.1 mycroft #define RAMPSM 0x00000200ul /* aic7870 only */
112 1.1 mycroft #define VOLSENSE 0x00000100ul
113 1.1 mycroft #define SCBRAMSEL 0x00000080ul
114 1.1 mycroft #define MRDCEN 0x00000040ul
115 1.1 mycroft #define EXTSCBTIME 0x00000020ul /* aic7870 only */
116 1.1 mycroft #define EXTSCBPEN 0x00000010ul /* aic7870 only */
117 1.1 mycroft #define BERREN 0x00000008ul
118 1.1 mycroft #define DACEN 0x00000004ul
119 1.1 mycroft #define STPWLEVEL 0x00000002ul
120 1.1 mycroft #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
121 1.1 mycroft
122 1.1 mycroft #define CSIZE_LATTIME 0x0c
123 1.1 mycroft #define CACHESIZE 0x0000003ful /* only 5 bits */
124 1.1 mycroft #define LATTIME 0x0000ff00ul
125 1.1 mycroft
126 1.1 mycroft static u_char aic3940_count;
127 1.1 mycroft
128 1.1 mycroft #if defined(__FreeBSD__)
129 1.1 mycroft
130 1.1 mycroft static char* aic7870_probe __P((pcici_t tag, pcidi_t type));
131 1.1 mycroft static void aic7870_attach __P((pcici_t config_id, int unit));
132 1.1 mycroft
133 1.1 mycroft static struct pci_device ahc_pci_driver = {
134 1.1 mycroft "ahc",
135 1.1 mycroft aic7870_probe,
136 1.1 mycroft aic7870_attach,
137 1.1 mycroft &ahc_unit,
138 1.1 mycroft NULL
139 1.1 mycroft };
140 1.1 mycroft
141 1.1 mycroft DATA_SET (pcidevice_set, ahc_pci_driver);
142 1.1 mycroft
143 1.1 mycroft static char*
144 1.1 mycroft aic7870_probe (pcici_t tag, pcidi_t type)
145 1.1 mycroft {
146 1.1 mycroft switch(type) {
147 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940U:
148 1.1 mycroft return ("Adaptec 3940 Ultra SCSI host adapter");
149 1.1 mycroft break;
150 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940:
151 1.1 mycroft return ("Adaptec 3940 SCSI host adapter");
152 1.1 mycroft break;
153 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944U:
154 1.1 mycroft return ("Adaptec 2944 Ultra SCSI host adapter");
155 1.1 mycroft break;
156 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940U:
157 1.1 mycroft return ("Adaptec 2940 Ultra SCSI host adapter");
158 1.1 mycroft break;
159 1.19 hannken case PCI_DEVICE_ID_ADAPTEC_2940UP:
160 1.19 hannken return ("Adaptec 2940 Ultra SCSI Pro host adapter");
161 1.19 hannken break;
162 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944:
163 1.1 mycroft return ("Adaptec 2944 SCSI host adapter");
164 1.1 mycroft break;
165 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940:
166 1.1 mycroft return ("Adaptec 2940 SCSI host adapter");
167 1.1 mycroft break;
168 1.6 gibbs case PCI_DEVICE_ID_ADAPTEC_2940AU:
169 1.6 gibbs return ("Adaptec 2940A Ultra SCSI host adapter");
170 1.6 gibbs break;
171 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7880:
172 1.1 mycroft return ("Adaptec aic7880 Ultra SCSI host adapter");
173 1.1 mycroft break;
174 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7870:
175 1.1 mycroft return ("Adaptec aic7870 SCSI host adapter");
176 1.1 mycroft break;
177 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7860:
178 1.1 mycroft return ("Adaptec aic7860 SCSI host adapter");
179 1.1 mycroft break;
180 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7855:
181 1.1 mycroft return ("Adaptec aic7855 SCSI host adapter");
182 1.1 mycroft break;
183 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7850:
184 1.1 mycroft return ("Adaptec aic7850 SCSI host adapter");
185 1.1 mycroft break;
186 1.1 mycroft default:
187 1.1 mycroft break;
188 1.1 mycroft }
189 1.1 mycroft return (0);
190 1.1 mycroft
191 1.1 mycroft }
192 1.1 mycroft
193 1.1 mycroft #elif defined(__NetBSD__)
194 1.1 mycroft
195 1.10 cgd int ahc_pci_probe __P((struct device *, struct cfdata *, void *));
196 1.1 mycroft void ahc_pci_attach __P((struct device *, struct device *, void *));
197 1.1 mycroft
198 1.1 mycroft struct cfattach ahc_pci_ca = {
199 1.1 mycroft sizeof(struct ahc_data), ahc_pci_probe, ahc_pci_attach
200 1.1 mycroft };
201 1.1 mycroft
202 1.1 mycroft int
203 1.1 mycroft ahc_pci_probe(parent, match, aux)
204 1.1 mycroft struct device *parent;
205 1.11 cgd struct cfdata *match;
206 1.11 cgd void *aux;
207 1.1 mycroft {
208 1.1 mycroft struct pci_attach_args *pa = aux;
209 1.1 mycroft
210 1.1 mycroft switch (pa->pa_id) {
211 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940U:
212 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944U:
213 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940U:
214 1.19 hannken case PCI_DEVICE_ID_ADAPTEC_2940UP:
215 1.6 gibbs case PCI_DEVICE_ID_ADAPTEC_2940AU:
216 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940:
217 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944:
218 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940:
219 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7880:
220 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7870:
221 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7860:
222 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7855:
223 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7850:
224 1.1 mycroft return 1;
225 1.1 mycroft }
226 1.1 mycroft return 0;
227 1.1 mycroft }
228 1.1 mycroft #endif /* defined(__NetBSD__) */
229 1.1 mycroft
230 1.1 mycroft #if defined(__FreeBSD__)
231 1.1 mycroft static void
232 1.1 mycroft aic7870_attach(config_id, unit)
233 1.1 mycroft pcici_t config_id;
234 1.1 mycroft int unit;
235 1.1 mycroft #elif defined(__NetBSD__)
236 1.1 mycroft void
237 1.1 mycroft ahc_pci_attach(parent, self, aux)
238 1.1 mycroft struct device *parent, *self;
239 1.1 mycroft void *aux;
240 1.1 mycroft #endif
241 1.1 mycroft {
242 1.1 mycroft #if defined(__FreeBSD__)
243 1.1 mycroft u_long io_port;
244 1.7 christos int unit = ahc->sc_dev.dv_unit;
245 1.1 mycroft #elif defined(__NetBSD__)
246 1.1 mycroft struct pci_attach_args *pa = aux;
247 1.1 mycroft struct ahc_data *ahc = (void *)self;
248 1.13 cgd bus_space_tag_t st, iot, memt;
249 1.13 cgd bus_space_handle_t sh, ioh, memh;
250 1.13 cgd int ioh_valid, memh_valid;
251 1.1 mycroft pci_intr_handle_t ih;
252 1.1 mycroft const char *intrstr;
253 1.1 mycroft #endif
254 1.1 mycroft u_long id;
255 1.1 mycroft unsigned opri = 0;
256 1.1 mycroft ahc_type ahc_t = AHC_NONE;
257 1.1 mycroft ahc_flag ahc_f = AHC_FNONE;
258 1.1 mycroft #if defined(__FreeBSD__)
259 1.1 mycroft struct ahc_data *ahc;
260 1.1 mycroft #endif
261 1.1 mycroft u_char ultra_enb = 0;
262 1.1 mycroft u_char our_id = 0;
263 1.1 mycroft
264 1.1 mycroft #if defined(__FreeBSD__)
265 1.1 mycroft if(!(io_port = pci_conf_read(config_id, PCI_BASEADR0)))
266 1.1 mycroft return;
267 1.1 mycroft /*
268 1.1 mycroft * The first bit of PCI_BASEADR0 is always
269 1.1 mycroft * set hence we mask it off.
270 1.1 mycroft */
271 1.1 mycroft io_port &= 0xfffffffe;
272 1.1 mycroft #elif defined(__NetBSD__)
273 1.14 cgd ioh_valid = (pci_mapreg_map(pa, PCI_BASEADR_IO,
274 1.13 cgd PCI_MAPREG_TYPE_IO, 0,
275 1.13 cgd &iot, &ioh, NULL, NULL) == 0);
276 1.14 cgd memh_valid = (pci_mapreg_map(pa, PCI_BASEADR_MEM,
277 1.13 cgd PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
278 1.13 cgd &memt, &memh, NULL, NULL) == 0);
279 1.13 cgd
280 1.13 cgd if (memh_valid) {
281 1.13 cgd st = memt;
282 1.13 cgd sh = memh;
283 1.13 cgd } else if (ioh_valid) {
284 1.13 cgd st = iot;
285 1.13 cgd sh = ioh;
286 1.12 cgd } else {
287 1.13 cgd printf(": unable to map registers\n");
288 1.1 mycroft return;
289 1.12 cgd }
290 1.12 cgd printf("\n");
291 1.1 mycroft #endif
292 1.1 mycroft
293 1.1 mycroft #if defined(__FreeBSD__)
294 1.1 mycroft switch ((id = pci_conf_read(config_id, PCI_ID_REG))) {
295 1.1 mycroft #elif defined(__NetBSD__)
296 1.1 mycroft switch (id = pa->pa_id) {
297 1.1 mycroft #endif
298 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940U:
299 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_3940:
300 1.1 mycroft if (id == PCI_DEVICE_ID_ADAPTEC_3940U)
301 1.1 mycroft ahc_t = AHC_394U;
302 1.1 mycroft else
303 1.1 mycroft ahc_t = AHC_394;
304 1.1 mycroft aic3940_count++;
305 1.1 mycroft if(!(aic3940_count & 0x01))
306 1.1 mycroft /* Even count implies second channel */
307 1.1 mycroft ahc_f |= AHC_CHNLB;
308 1.1 mycroft break;
309 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944U:
310 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940U:
311 1.19 hannken case PCI_DEVICE_ID_ADAPTEC_2940UP:
312 1.1 mycroft ahc_t = AHC_294U;
313 1.1 mycroft break;
314 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2944:
315 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_2940:
316 1.1 mycroft ahc_t = AHC_294;
317 1.1 mycroft break;
318 1.6 gibbs case PCI_DEVICE_ID_ADAPTEC_2940AU:
319 1.6 gibbs ahc_t = AHC_294AU;
320 1.6 gibbs break;
321 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7880:
322 1.1 mycroft ahc_t = AHC_AIC7880;
323 1.1 mycroft break;
324 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7870:
325 1.1 mycroft ahc_t = AHC_AIC7870;
326 1.1 mycroft break;
327 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7860:
328 1.1 mycroft ahc_t = AHC_AIC7860;
329 1.1 mycroft break;
330 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7855:
331 1.1 mycroft case PCI_DEVICE_ID_ADAPTEC_AIC7850:
332 1.1 mycroft ahc_t = AHC_AIC7850;
333 1.1 mycroft break;
334 1.1 mycroft default:
335 1.1 mycroft break;
336 1.1 mycroft }
337 1.1 mycroft
338 1.1 mycroft /* On all PCI adapters, we allow SCB paging */
339 1.1 mycroft ahc_f |= AHC_PAGESCBS;
340 1.1 mycroft
341 1.1 mycroft /* Remeber how the card was setup in case there is no SEEPROM */
342 1.1 mycroft #if defined(__FreeBSD__)
343 1.1 mycroft our_id = inb(SCSIID + io_port) & OID;
344 1.1 mycroft if(ahc_t & AHC_ULTRA)
345 1.1 mycroft ultra_enb = inb(SXFRCTL0 + io_port) & ULTRAEN;
346 1.1 mycroft #else
347 1.12 cgd our_id = bus_space_read_1(st, sh, SCSIID) & OID;
348 1.1 mycroft if(ahc_t & AHC_ULTRA)
349 1.12 cgd ultra_enb = bus_space_read_1(st, sh, SXFRCTL0) & ULTRAEN;
350 1.1 mycroft #endif
351 1.1 mycroft
352 1.1 mycroft #if defined(__FreeBSD__)
353 1.1 mycroft ahc_reset(io_port);
354 1.1 mycroft #elif defined(__NetBSD__)
355 1.12 cgd ahc_reset(ahc->sc_dev.dv_xname, st, sh);
356 1.1 mycroft #endif
357 1.1 mycroft
358 1.1 mycroft if(ahc_t & AHC_AIC7870){
359 1.1 mycroft #if defined(__FreeBSD__)
360 1.1 mycroft u_long devconfig = pci_conf_read(config_id, DEVCONFIG);
361 1.1 mycroft #elif defined(__NetBSD__)
362 1.1 mycroft u_long devconfig =
363 1.1 mycroft pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
364 1.1 mycroft #endif
365 1.1 mycroft
366 1.1 mycroft if(devconfig & (RAMPSM)) {
367 1.1 mycroft /*
368 1.1 mycroft * External SRAM present. Have the probe walk
369 1.1 mycroft * the SCBs to see how much SRAM we have and set
370 1.1 mycroft * the number of SCBs accordingly. We have to
371 1.1 mycroft * turn off SCBRAMSEL to access the external
372 1.1 mycroft * SCB SRAM.
373 1.1 mycroft *
374 1.1 mycroft * It seems that early versions of the aic7870
375 1.1 mycroft * didn't use these bits, hence the hack for the
376 1.1 mycroft * 3940 above. I would guess that recent 3940s
377 1.1 mycroft * using later aic7870 or aic7880 chips do
378 1.1 mycroft * actually set RAMPSM.
379 1.1 mycroft *
380 1.1 mycroft * The documentation isn't clear, but it sounds
381 1.1 mycroft * like the value written to devconfig must not
382 1.1 mycroft * have RAMPSM set. The second sixteen bits of
383 1.1 mycroft * the register are R/O anyway, so it shouldn't
384 1.1 mycroft * affect RAMPSM either way.
385 1.1 mycroft */
386 1.1 mycroft devconfig &= ~(RAMPSM|SCBRAMSEL);
387 1.1 mycroft #if defined(__FreeBSD__)
388 1.1 mycroft pci_conf_write(config_id, DEVCONFIG, devconfig);
389 1.1 mycroft #elif defined(__NetBSD__)
390 1.1 mycroft pci_conf_write(pa->pa_pc, pa->pa_tag,
391 1.1 mycroft DEVCONFIG, devconfig);
392 1.1 mycroft #endif
393 1.1 mycroft }
394 1.1 mycroft }
395 1.1 mycroft
396 1.1 mycroft #if defined(__FreeBSD__)
397 1.1 mycroft if(!(ahc = ahc_alloc(unit, io_port, ahc_t, ahc_f)))
398 1.1 mycroft return; /* XXX PCI code should take return status */
399 1.1 mycroft
400 1.1 mycroft if(!(pci_map_int(config_id, ahc_intr, (void *)ahc, &bio_imask))) {
401 1.1 mycroft ahc_free(ahc);
402 1.1 mycroft return;
403 1.1 mycroft }
404 1.1 mycroft #elif defined(__NetBSD__)
405 1.17 leo ahc_construct(ahc, st, sh, pa->pa_dmat, ahc_t, ahc_f);
406 1.1 mycroft
407 1.1 mycroft if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
408 1.1 mycroft pa->pa_intrline, &ih)) {
409 1.8 christos printf("%s: couldn't map interrupt\n", ahc->sc_dev.dv_xname);
410 1.1 mycroft ahc_free(ahc);
411 1.1 mycroft return;
412 1.1 mycroft }
413 1.1 mycroft intrstr = pci_intr_string(pa->pa_pc, ih);
414 1.4 cgd ahc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ahc_intr, ahc);
415 1.1 mycroft if (ahc->sc_ih == NULL) {
416 1.8 christos printf("%s: couldn't establish interrupt",
417 1.1 mycroft ahc->sc_dev.dv_xname);
418 1.1 mycroft if (intrstr != NULL)
419 1.8 christos printf(" at %s", intrstr);
420 1.8 christos printf("\n");
421 1.1 mycroft ahc_free(ahc);
422 1.1 mycroft return;
423 1.1 mycroft }
424 1.1 mycroft if (intrstr != NULL)
425 1.8 christos printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
426 1.1 mycroft intrstr);
427 1.1 mycroft #endif
428 1.1 mycroft /*
429 1.1 mycroft * Protect ourself from spurrious interrupts during
430 1.1 mycroft * intialization.
431 1.1 mycroft */
432 1.1 mycroft opri = splbio();
433 1.1 mycroft
434 1.1 mycroft /*
435 1.1 mycroft * Do aic7870/aic7880/aic7850 specific initialization
436 1.1 mycroft */
437 1.1 mycroft {
438 1.1 mycroft u_char sblkctl;
439 1.1 mycroft char *id_string;
440 1.1 mycroft
441 1.1 mycroft switch(ahc->type) {
442 1.1 mycroft case AHC_394U:
443 1.1 mycroft case AHC_294U:
444 1.1 mycroft case AHC_AIC7880:
445 1.1 mycroft {
446 1.1 mycroft id_string = "aic7880 ";
447 1.20 thorpej ahc_load_seeprom(ahc);
448 1.1 mycroft break;
449 1.1 mycroft }
450 1.1 mycroft case AHC_394:
451 1.1 mycroft case AHC_294:
452 1.1 mycroft case AHC_AIC7870:
453 1.1 mycroft {
454 1.1 mycroft id_string = "aic7870 ";
455 1.20 thorpej ahc_load_seeprom(ahc);
456 1.1 mycroft break;
457 1.1 mycroft }
458 1.6 gibbs case AHC_294AU:
459 1.1 mycroft case AHC_AIC7860:
460 1.1 mycroft {
461 1.1 mycroft id_string = "aic7860 ";
462 1.20 thorpej ahc_load_seeprom(ahc);
463 1.1 mycroft break;
464 1.1 mycroft }
465 1.1 mycroft case AHC_AIC7850:
466 1.1 mycroft {
467 1.1 mycroft id_string = "aic7850 ";
468 1.1 mycroft /*
469 1.1 mycroft * Use defaults, if the chip wasn't initialized by
470 1.1 mycroft * a BIOS.
471 1.1 mycroft */
472 1.1 mycroft ahc->flags |= AHC_USEDEFAULTS;
473 1.1 mycroft break;
474 1.1 mycroft }
475 1.1 mycroft default:
476 1.1 mycroft {
477 1.8 christos printf("ahc: Unknown controller type. Ignoring.\n");
478 1.1 mycroft ahc_free(ahc);
479 1.1 mycroft splx(opri);
480 1.1 mycroft return;
481 1.1 mycroft }
482 1.1 mycroft }
483 1.1 mycroft
484 1.1 mycroft /*
485 1.1 mycroft * Take the LED out of diagnostic mode
486 1.1 mycroft */
487 1.1 mycroft sblkctl = AHC_INB(ahc, SBLKCTL);
488 1.1 mycroft AHC_OUTB(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
489 1.1 mycroft
490 1.1 mycroft /*
491 1.1 mycroft * I don't know where this is set in the SEEPROM or by the
492 1.1 mycroft * BIOS, so we default to 100%.
493 1.1 mycroft */
494 1.1 mycroft AHC_OUTB(ahc, DSPCISTATUS, DFTHRSH_100);
495 1.1 mycroft
496 1.1 mycroft if(ahc->flags & AHC_USEDEFAULTS) {
497 1.1 mycroft /*
498 1.1 mycroft * PCI Adapter default setup
499 1.1 mycroft * Should only be used if the adapter does not have
500 1.1 mycroft * an SEEPROM.
501 1.1 mycroft */
502 1.1 mycroft /* See if someone else set us up already */
503 1.1 mycroft u_long i;
504 1.1 mycroft for(i = TARG_SCRATCH; i < 0x60; i++) {
505 1.3 explorer if(AHC_INB(ahc, i) != 0x00)
506 1.1 mycroft break;
507 1.1 mycroft }
508 1.3 explorer if(i == TARG_SCRATCH) {
509 1.3 explorer /*
510 1.3 explorer * Try looking for all ones. You can get
511 1.3 explorer * either.
512 1.3 explorer */
513 1.3 explorer for (i = TARG_SCRATCH; i < 0x60; i++) {
514 1.3 explorer if(AHC_INB(ahc, i) != 0xff)
515 1.3 explorer break;
516 1.3 explorer }
517 1.3 explorer }
518 1.3 explorer if((i != 0x60) && (our_id != 0)) {
519 1.8 christos printf("%s: Using left over BIOS settings\n",
520 1.1 mycroft ahc_name(ahc));
521 1.1 mycroft ahc->flags &= ~AHC_USEDEFAULTS;
522 1.1 mycroft }
523 1.1 mycroft else
524 1.1 mycroft our_id = 0x07;
525 1.1 mycroft AHC_OUTB(ahc, SCSICONF,
526 1.1 mycroft (our_id & 0x07)|ENSPCHK|RESET_SCSI);
527 1.1 mycroft /* In case we are a wide card */
528 1.1 mycroft AHC_OUTB(ahc, SCSICONF + 1, our_id);
529 1.1 mycroft
530 1.1 mycroft if(!ultra_enb || (ahc->flags & AHC_USEDEFAULTS)) {
531 1.1 mycroft /*
532 1.1 mycroft * If there wasn't a BIOS or the board
533 1.1 mycroft * wasn't in this mode to begin with,
534 1.1 mycroft * turn off ultra.
535 1.1 mycroft */
536 1.1 mycroft ahc->type &= ~AHC_ULTRA;
537 1.1 mycroft }
538 1.1 mycroft }
539 1.1 mycroft
540 1.8 christos printf("%s: %s", ahc_name(ahc), id_string);
541 1.1 mycroft }
542 1.1 mycroft
543 1.1 mycroft if(ahc_init(ahc)){
544 1.1 mycroft ahc_free(ahc);
545 1.1 mycroft splx(opri);
546 1.1 mycroft return; /* XXX PCI code should take return status */
547 1.1 mycroft }
548 1.1 mycroft splx(opri);
549 1.1 mycroft
550 1.1 mycroft ahc_attach(ahc);
551 1.1 mycroft }
552 1.1 mycroft #endif /* NPCI > 0 */
553