ahc_pci.c revision 1.3 1 /* $NetBSD: ahc_pci.c,v 1.3 1996/07/10 22:53:55 explorer Exp $ */
2
3 /*
4 * Product specific probe and attach routines for:
5 * 3940, 2940, aic7880, aic7870, aic7860 and aic7850 SCSI controllers
6 *
7 * Copyright (c) 1995, 1996 Justin T. Gibbs.
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 immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * from Id: aic7870.c,v 1.37 1996/06/08 06:55:55 gibbs Exp
35 */
36
37 #if defined(__FreeBSD__)
38 #include <pci.h>
39 #endif
40 #if NPCI > 0 || defined(__NetBSD__)
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/malloc.h>
44 #include <sys/kernel.h>
45 #include <sys/queue.h>
46 #if defined(__NetBSD__)
47 #include <sys/device.h>
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50 #endif /* defined(__NetBSD__) */
51
52 #include <scsi/scsi_all.h>
53 #include <scsi/scsiconf.h>
54
55 #if defined(__FreeBSD__)
56
57 #include <pci/pcireg.h>
58 #include <pci/pcivar.h>
59
60 #include <machine/clock.h>
61
62 #include <i386/scsi/aic7xxx.h>
63 #include <i386/scsi/93cx6.h>
64
65 #include <dev/aic7xxx/aic7xxx_reg.h>
66
67 #define PCI_BASEADR0 PCI_MAP_REG_START
68
69 #elif defined(__NetBSD__)
70
71 #include <dev/pci/pcireg.h>
72 #include <dev/pci/pcivar.h>
73
74 #include <dev/ic/aic7xxxreg.h>
75 #include <dev/ic/aic7xxxvar.h>
76 #include <dev/ic/smc93cx6var.h>
77
78 #define bootverbose 1
79 #define PCI_BASEADR0 PCI_MAPREG_START
80
81 #endif /* defined(__NetBSD__) */
82
83 #define PCI_DEVICE_ID_ADAPTEC_3940U 0x82789004ul
84 #define PCI_DEVICE_ID_ADAPTEC_2944U 0x84789004ul
85 #define PCI_DEVICE_ID_ADAPTEC_2940U 0x81789004ul
86 #define PCI_DEVICE_ID_ADAPTEC_3940 0x72789004ul
87 #define PCI_DEVICE_ID_ADAPTEC_2944 0x74789004ul
88 #define PCI_DEVICE_ID_ADAPTEC_2940 0x71789004ul
89 #define PCI_DEVICE_ID_ADAPTEC_AIC7880 0x80789004ul
90 #define PCI_DEVICE_ID_ADAPTEC_AIC7870 0x70789004ul
91 #define PCI_DEVICE_ID_ADAPTEC_AIC7860 0x60789004ul
92 #define PCI_DEVICE_ID_ADAPTEC_AIC7855 0x55789004ul
93 #define PCI_DEVICE_ID_ADAPTEC_AIC7850 0x50789004ul
94
95 #define DEVCONFIG 0x40
96 #define MPORTMODE 0x00000400ul /* aic7870 only */
97 #define RAMPSM 0x00000200ul /* aic7870 only */
98 #define VOLSENSE 0x00000100ul
99 #define SCBRAMSEL 0x00000080ul
100 #define MRDCEN 0x00000040ul
101 #define EXTSCBTIME 0x00000020ul /* aic7870 only */
102 #define EXTSCBPEN 0x00000010ul /* aic7870 only */
103 #define BERREN 0x00000008ul
104 #define DACEN 0x00000004ul
105 #define STPWLEVEL 0x00000002ul
106 #define DIFACTNEGEN 0x00000001ul /* aic7870 only */
107
108 #define CSIZE_LATTIME 0x0c
109 #define CACHESIZE 0x0000003ful /* only 5 bits */
110 #define LATTIME 0x0000ff00ul
111
112 /*
113 * Define the format of the aic78X0 SEEPROM registers (16 bits).
114 *
115 */
116
117 struct seeprom_config {
118
119 /*
120 * SCSI ID Configuration Flags
121 */
122 #define CFXFER 0x0007 /* synchronous transfer rate */
123 #define CFSYNCH 0x0008 /* enable synchronous transfer */
124 #define CFDISC 0x0010 /* enable disconnection */
125 #define CFWIDEB 0x0020 /* wide bus device */
126 /* UNUSED 0x00C0 */
127 #define CFSTART 0x0100 /* send start unit SCSI command */
128 #define CFINCBIOS 0x0200 /* include in BIOS scan */
129 #define CFRNFOUND 0x0400 /* report even if not found */
130 /* UNUSED 0xf800 */
131 u_int16_t device_flags[16]; /* words 0-15 */
132
133 /*
134 * BIOS Control Bits
135 */
136 #define CFSUPREM 0x0001 /* support all removeable drives */
137 #define CFSUPREMB 0x0002 /* support removeable drives for boot only */
138 #define CFBIOSEN 0x0004 /* BIOS enabled */
139 /* UNUSED 0x0008 */
140 #define CFSM2DRV 0x0010 /* support more than two drives */
141 /* UNUSED 0x0060 */
142 #define CFEXTEND 0x0080 /* extended translation enabled */
143 /* UNUSED 0xff00 */
144 u_int16_t bios_control; /* word 16 */
145
146 /*
147 * Host Adapter Control Bits
148 */
149 /* UNUSED 0x0001 */
150 #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable (Ultra cards) */
151 #define CFSTERM 0x0004 /* SCSI low byte termination (non-wide cards) */
152 #define CFWSTERM 0x0008 /* SCSI high byte termination (wide card) */
153 #define CFSPARITY 0x0010 /* SCSI parity */
154 /* UNUSED 0x0020 */
155 #define CFRESETB 0x0040 /* reset SCSI bus at IC initialization */
156 /* UNUSED 0xff80 */
157 u_int16_t adapter_control; /* word 17 */
158
159 /*
160 * Bus Release, Host Adapter ID
161 */
162 #define CFSCSIID 0x000f /* host adapter SCSI ID */
163 /* UNUSED 0x00f0 */
164 #define CFBRTIME 0xff00 /* bus release time */
165 u_int16_t brtime_id; /* word 18 */
166
167 /*
168 * Maximum targets
169 */
170 #define CFMAXTARG 0x00ff /* maximum targets */
171 /* UNUSED 0xff00 */
172 u_int16_t max_targets; /* word 19 */
173
174 u_int16_t res_1[11]; /* words 20-30 */
175 u_int16_t checksum; /* word 31 */
176 };
177
178 static void load_seeprom __P((struct ahc_data *ahc));
179 static int acquire_seeprom __P((struct seeprom_descriptor *sd));
180 static void release_seeprom __P((struct seeprom_descriptor *sd));
181
182 static u_char aic3940_count;
183
184 #if defined(__FreeBSD__)
185
186 static char* aic7870_probe __P((pcici_t tag, pcidi_t type));
187 static void aic7870_attach __P((pcici_t config_id, int unit));
188
189 static struct pci_device ahc_pci_driver = {
190 "ahc",
191 aic7870_probe,
192 aic7870_attach,
193 &ahc_unit,
194 NULL
195 };
196
197 DATA_SET (pcidevice_set, ahc_pci_driver);
198
199 static char*
200 aic7870_probe (pcici_t tag, pcidi_t type)
201 {
202 switch(type) {
203 case PCI_DEVICE_ID_ADAPTEC_3940U:
204 return ("Adaptec 3940 Ultra SCSI host adapter");
205 break;
206 case PCI_DEVICE_ID_ADAPTEC_3940:
207 return ("Adaptec 3940 SCSI host adapter");
208 break;
209 case PCI_DEVICE_ID_ADAPTEC_2944U:
210 return ("Adaptec 2944 Ultra SCSI host adapter");
211 break;
212 case PCI_DEVICE_ID_ADAPTEC_2940U:
213 return ("Adaptec 2940 Ultra SCSI host adapter");
214 break;
215 case PCI_DEVICE_ID_ADAPTEC_2944:
216 return ("Adaptec 2944 SCSI host adapter");
217 break;
218 case PCI_DEVICE_ID_ADAPTEC_2940:
219 return ("Adaptec 2940 SCSI host adapter");
220 break;
221 case PCI_DEVICE_ID_ADAPTEC_AIC7880:
222 return ("Adaptec aic7880 Ultra SCSI host adapter");
223 break;
224 case PCI_DEVICE_ID_ADAPTEC_AIC7870:
225 return ("Adaptec aic7870 SCSI host adapter");
226 break;
227 case PCI_DEVICE_ID_ADAPTEC_AIC7860:
228 return ("Adaptec aic7860 SCSI host adapter");
229 break;
230 case PCI_DEVICE_ID_ADAPTEC_AIC7855:
231 return ("Adaptec aic7855 SCSI host adapter");
232 break;
233 case PCI_DEVICE_ID_ADAPTEC_AIC7850:
234 return ("Adaptec aic7850 SCSI host adapter");
235 break;
236 default:
237 break;
238 }
239 return (0);
240
241 }
242
243 #elif defined(__NetBSD__)
244
245 int ahc_pci_probe __P((struct device *, void *, void *));
246 void ahc_pci_attach __P((struct device *, struct device *, void *));
247
248 struct cfattach ahc_pci_ca = {
249 sizeof(struct ahc_data), ahc_pci_probe, ahc_pci_attach
250 };
251
252 int
253 ahc_pci_probe(parent, match, aux)
254 struct device *parent;
255 void *match, *aux;
256 {
257 struct pci_attach_args *pa = aux;
258
259 switch (pa->pa_id) {
260 case PCI_DEVICE_ID_ADAPTEC_3940U:
261 case PCI_DEVICE_ID_ADAPTEC_2944U:
262 case PCI_DEVICE_ID_ADAPTEC_2940U:
263 case PCI_DEVICE_ID_ADAPTEC_3940:
264 case PCI_DEVICE_ID_ADAPTEC_2944:
265 case PCI_DEVICE_ID_ADAPTEC_2940:
266 case PCI_DEVICE_ID_ADAPTEC_AIC7880:
267 case PCI_DEVICE_ID_ADAPTEC_AIC7870:
268 case PCI_DEVICE_ID_ADAPTEC_AIC7860:
269 case PCI_DEVICE_ID_ADAPTEC_AIC7855:
270 case PCI_DEVICE_ID_ADAPTEC_AIC7850:
271 return 1;
272 }
273 return 0;
274 }
275 #endif /* defined(__NetBSD__) */
276
277 #if defined(__FreeBSD__)
278 static void
279 aic7870_attach(config_id, unit)
280 pcici_t config_id;
281 int unit;
282 #elif defined(__NetBSD__)
283 void
284 ahc_pci_attach(parent, self, aux)
285 struct device *parent, *self;
286 void *aux;
287 #endif
288 {
289 #if defined(__FreeBSD__)
290 u_long io_port;
291 #elif defined(__NetBSD__)
292 struct pci_attach_args *pa = aux;
293 struct ahc_data *ahc = (void *)self;
294 int unit = ahc->sc_dev.dv_unit;
295 bus_io_addr_t iobase;
296 bus_io_size_t iosize;
297 bus_io_handle_t ioh;
298 pci_intr_handle_t ih;
299 const char *intrstr;
300 #endif
301 u_long id;
302 unsigned opri = 0;
303 ahc_type ahc_t = AHC_NONE;
304 ahc_flag ahc_f = AHC_FNONE;
305 #if defined(__FreeBSD__)
306 struct ahc_data *ahc;
307 #endif
308 u_char ultra_enb = 0;
309 u_char our_id = 0;
310
311 #if defined(__FreeBSD__)
312 if(!(io_port = pci_conf_read(config_id, PCI_BASEADR0)))
313 return;
314 /*
315 * The first bit of PCI_BASEADR0 is always
316 * set hence we mask it off.
317 */
318 io_port &= 0xfffffffe;
319 #elif defined(__NetBSD__)
320 if (pci_io_find(pa->pa_pc, pa->pa_tag, PCI_BASEADR0, &iobase, &iosize))
321 return;
322 if (bus_io_map(pa->pa_bc, iobase, iosize, &ioh))
323 return;
324 #endif
325
326 #if defined(__FreeBSD__)
327 switch ((id = pci_conf_read(config_id, PCI_ID_REG))) {
328 #elif defined(__NetBSD__)
329 switch (id = pa->pa_id) {
330 #endif
331 case PCI_DEVICE_ID_ADAPTEC_3940U:
332 case PCI_DEVICE_ID_ADAPTEC_3940:
333 if (id == PCI_DEVICE_ID_ADAPTEC_3940U)
334 ahc_t = AHC_394U;
335 else
336 ahc_t = AHC_394;
337 aic3940_count++;
338 if(!(aic3940_count & 0x01))
339 /* Even count implies second channel */
340 ahc_f |= AHC_CHNLB;
341 break;
342 case PCI_DEVICE_ID_ADAPTEC_2944U:
343 case PCI_DEVICE_ID_ADAPTEC_2940U:
344 ahc_t = AHC_294U;
345 break;
346 case PCI_DEVICE_ID_ADAPTEC_2944:
347 case PCI_DEVICE_ID_ADAPTEC_2940:
348 ahc_t = AHC_294;
349 break;
350 case PCI_DEVICE_ID_ADAPTEC_AIC7880:
351 ahc_t = AHC_AIC7880;
352 break;
353 case PCI_DEVICE_ID_ADAPTEC_AIC7870:
354 ahc_t = AHC_AIC7870;
355 break;
356 case PCI_DEVICE_ID_ADAPTEC_AIC7860:
357 ahc_t = AHC_AIC7860;
358 break;
359 case PCI_DEVICE_ID_ADAPTEC_AIC7855:
360 case PCI_DEVICE_ID_ADAPTEC_AIC7850:
361 ahc_t = AHC_AIC7850;
362 break;
363 default:
364 break;
365 }
366
367 /* On all PCI adapters, we allow SCB paging */
368 ahc_f |= AHC_PAGESCBS;
369
370 /* Remeber how the card was setup in case there is no SEEPROM */
371 #if defined(__FreeBSD__)
372 our_id = inb(SCSIID + io_port) & OID;
373 if(ahc_t & AHC_ULTRA)
374 ultra_enb = inb(SXFRCTL0 + io_port) & ULTRAEN;
375 #else
376 our_id = bus_io_read_1(pa->pa_bc, ioh, SCSIID) & OID;
377 if(ahc_t & AHC_ULTRA)
378 ultra_enb = bus_io_read_1(pa->pa_bc, ioh, SXFRCTL0) & ULTRAEN;
379 #endif
380
381 #if defined(__FreeBSD__)
382 ahc_reset(io_port);
383 #elif defined(__NetBSD__)
384 printf("\n");
385 ahc_reset(ahc->sc_dev.dv_xname, pa->pa_bc, ioh);
386 #endif
387
388 if(ahc_t & AHC_AIC7870){
389 #if defined(__FreeBSD__)
390 u_long devconfig = pci_conf_read(config_id, DEVCONFIG);
391 #elif defined(__NetBSD__)
392 u_long devconfig =
393 pci_conf_read(pa->pa_pc, pa->pa_tag, DEVCONFIG);
394 #endif
395
396 if(devconfig & (RAMPSM)) {
397 /*
398 * External SRAM present. Have the probe walk
399 * the SCBs to see how much SRAM we have and set
400 * the number of SCBs accordingly. We have to
401 * turn off SCBRAMSEL to access the external
402 * SCB SRAM.
403 *
404 * It seems that early versions of the aic7870
405 * didn't use these bits, hence the hack for the
406 * 3940 above. I would guess that recent 3940s
407 * using later aic7870 or aic7880 chips do
408 * actually set RAMPSM.
409 *
410 * The documentation isn't clear, but it sounds
411 * like the value written to devconfig must not
412 * have RAMPSM set. The second sixteen bits of
413 * the register are R/O anyway, so it shouldn't
414 * affect RAMPSM either way.
415 */
416 devconfig &= ~(RAMPSM|SCBRAMSEL);
417 #if defined(__FreeBSD__)
418 pci_conf_write(config_id, DEVCONFIG, devconfig);
419 #elif defined(__NetBSD__)
420 pci_conf_write(pa->pa_pc, pa->pa_tag,
421 DEVCONFIG, devconfig);
422 #endif
423 }
424 }
425
426 #if defined(__FreeBSD__)
427 if(!(ahc = ahc_alloc(unit, io_port, ahc_t, ahc_f)))
428 return; /* XXX PCI code should take return status */
429
430 if(!(pci_map_int(config_id, ahc_intr, (void *)ahc, &bio_imask))) {
431 ahc_free(ahc);
432 return;
433 }
434 #elif defined(__NetBSD__)
435 ahc_construct(ahc, pa->pa_bc, ioh, ahc_t, ahc_f);
436
437 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
438 pa->pa_intrline, &ih)) {
439 printf("%s: couldn't map interrupt\n", ahc->sc_dev.dv_xname);
440 ahc_free(ahc);
441 return;
442 }
443 intrstr = pci_intr_string(pa->pa_pc, ih);
444 ahc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ahc_intr, ahc
445 #ifdef __OpenBSD__
446 , ahc->sc_dev.dv_xname
447 #endif
448 );
449 if (ahc->sc_ih == NULL) {
450 printf("%s: couldn't establish interrupt",
451 ahc->sc_dev.dv_xname);
452 if (intrstr != NULL)
453 printf(" at %s", intrstr);
454 printf("\n");
455 ahc_free(ahc);
456 return;
457 }
458 if (intrstr != NULL)
459 printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
460 intrstr);
461 #endif
462 /*
463 * Protect ourself from spurrious interrupts during
464 * intialization.
465 */
466 opri = splbio();
467
468 /*
469 * Do aic7870/aic7880/aic7850 specific initialization
470 */
471 {
472 u_char sblkctl;
473 char *id_string;
474
475 switch(ahc->type) {
476 case AHC_394U:
477 case AHC_294U:
478 case AHC_AIC7880:
479 {
480 id_string = "aic7880 ";
481 load_seeprom(ahc);
482 break;
483 }
484 case AHC_394:
485 case AHC_294:
486 case AHC_AIC7870:
487 {
488 id_string = "aic7870 ";
489 load_seeprom(ahc);
490 break;
491 }
492 case AHC_AIC7860:
493 {
494 id_string = "aic7860 ";
495 /*
496 * Use defaults, if the chip wasn't initialized by
497 * a BIOS.
498 */
499 ahc->flags |= AHC_USEDEFAULTS;
500 break;
501 }
502 case AHC_AIC7850:
503 {
504 id_string = "aic7850 ";
505 /*
506 * Use defaults, if the chip wasn't initialized by
507 * a BIOS.
508 */
509 ahc->flags |= AHC_USEDEFAULTS;
510 break;
511 }
512 default:
513 {
514 printf("ahc: Unknown controller type. Ignoring.\n");
515 ahc_free(ahc);
516 splx(opri);
517 return;
518 }
519 }
520
521 /*
522 * Take the LED out of diagnostic mode
523 */
524 sblkctl = AHC_INB(ahc, SBLKCTL);
525 AHC_OUTB(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
526
527 /*
528 * I don't know where this is set in the SEEPROM or by the
529 * BIOS, so we default to 100%.
530 */
531 AHC_OUTB(ahc, DSPCISTATUS, DFTHRSH_100);
532
533 if(ahc->flags & AHC_USEDEFAULTS) {
534 /*
535 * PCI Adapter default setup
536 * Should only be used if the adapter does not have
537 * an SEEPROM.
538 */
539 /* See if someone else set us up already */
540 u_long i;
541 for(i = TARG_SCRATCH; i < 0x60; i++) {
542 if(AHC_INB(ahc, i) != 0x00)
543 break;
544 }
545 if(i == TARG_SCRATCH) {
546 /*
547 * Try looking for all ones. You can get
548 * either.
549 */
550 for (i = TARG_SCRATCH; i < 0x60; i++) {
551 if(AHC_INB(ahc, i) != 0xff)
552 break;
553 }
554 }
555 if((i != 0x60) && (our_id != 0)) {
556 printf("%s: Using left over BIOS settings\n",
557 ahc_name(ahc));
558 ahc->flags &= ~AHC_USEDEFAULTS;
559 }
560 else
561 our_id = 0x07;
562 AHC_OUTB(ahc, SCSICONF,
563 (our_id & 0x07)|ENSPCHK|RESET_SCSI);
564 /* In case we are a wide card */
565 AHC_OUTB(ahc, SCSICONF + 1, our_id);
566
567 if(!ultra_enb || (ahc->flags & AHC_USEDEFAULTS)) {
568 /*
569 * If there wasn't a BIOS or the board
570 * wasn't in this mode to begin with,
571 * turn off ultra.
572 */
573 ahc->type &= ~AHC_ULTRA;
574 }
575 }
576
577 printf("%s: %s", ahc_name(ahc), id_string);
578 }
579
580 if(ahc_init(ahc)){
581 ahc_free(ahc);
582 splx(opri);
583 return; /* XXX PCI code should take return status */
584 }
585 splx(opri);
586
587 ahc_attach(ahc);
588 }
589
590 /*
591 * Read the SEEPROM. Return 0 on failure
592 */
593 void
594 load_seeprom(ahc)
595 struct ahc_data *ahc;
596 {
597 struct seeprom_descriptor sd;
598 struct seeprom_config sc;
599 u_short *scarray = (u_short *)≻
600 u_short checksum = 0;
601 u_char scsi_conf;
602 u_char host_id;
603 int have_seeprom;
604
605 #if defined(__FreeBSD__)
606 sd.sd_iobase = ahc->baseport + SEECTL;
607 #elif defined(__NetBSD__)
608 sd.sd_bc = ahc->sc_bc;
609 sd.sd_ioh = ahc->sc_ioh;
610 sd.sd_offset = SEECTL;
611 #endif
612 sd.sd_MS = SEEMS;
613 sd.sd_RDY = SEERDY;
614 sd.sd_CS = SEECS;
615 sd.sd_CK = SEECK;
616 sd.sd_DO = SEEDO;
617 sd.sd_DI = SEEDI;
618
619 if(bootverbose)
620 printf("%s: Reading SEEPROM...", ahc_name(ahc));
621 have_seeprom = acquire_seeprom(&sd);
622 if (have_seeprom) {
623 have_seeprom = read_seeprom(&sd,
624 (u_int16_t *)&sc,
625 ahc->flags & AHC_CHNLB,
626 sizeof(sc)/2);
627 release_seeprom(&sd);
628 if (have_seeprom) {
629 /* Check checksum */
630 int i;
631
632 for (i = 0;i < (sizeof(sc)/2 - 1);i = i + 1)
633 checksum = checksum + scarray[i];
634 if (checksum != sc.checksum) {
635 if(bootverbose)
636 printf ("checksum error");
637 have_seeprom = 0;
638 }
639 else if(bootverbose)
640 printf("done.\n");
641 }
642 }
643 if (!have_seeprom) {
644 if(bootverbose)
645 printf("\n%s: No SEEPROM availible\n", ahc_name(ahc));
646 ahc->flags |= AHC_USEDEFAULTS;
647 }
648 else {
649 /*
650 * Put the data we've collected down into SRAM
651 * where ahc_init will find it.
652 */
653 int i;
654 int max_targ = sc.max_targets & CFMAXTARG;
655
656 for(i = 0; i < max_targ; i++){
657 u_char target_settings;
658 target_settings = (sc.device_flags[i] & CFXFER) << 4;
659 if (sc.device_flags[i] & CFSYNCH)
660 target_settings |= SOFS;
661 if (sc.device_flags[i] & CFWIDEB)
662 target_settings |= WIDEXFER;
663 if (sc.device_flags[i] & CFDISC)
664 ahc->discenable |= (0x01 << i);
665 AHC_OUTB(ahc, TARG_SCRATCH+i, target_settings);
666 }
667 AHC_OUTB(ahc, DISC_DSB, ~(ahc->discenable & 0xff));
668 AHC_OUTB(ahc, DISC_DSB + 1, ~((ahc->discenable >> 8) & 0xff));
669
670 host_id = sc.brtime_id & CFSCSIID;
671
672 scsi_conf = (host_id & 0x7);
673 if(sc.adapter_control & CFSPARITY)
674 scsi_conf |= ENSPCHK;
675 if(sc.adapter_control & CFRESETB)
676 scsi_conf |= RESET_SCSI;
677
678 if(ahc->type & AHC_ULTRA) {
679 /* Should we enable Ultra mode? */
680 if(!(sc.adapter_control & CFULTRAEN))
681 /* Treat us as a non-ultra card */
682 ahc->type &= ~AHC_ULTRA;
683 }
684 /* Set the host ID */
685 AHC_OUTB(ahc, SCSICONF, scsi_conf);
686 /* In case we are a wide card */
687 AHC_OUTB(ahc, SCSICONF + 1, host_id);
688 }
689 }
690
691 static int
692 acquire_seeprom(sd)
693 struct seeprom_descriptor *sd;
694 {
695 int wait;
696
697 /*
698 * Request access of the memory port. When access is
699 * granted, SEERDY will go high. We use a 1 second
700 * timeout which should be near 1 second more than
701 * is needed. Reason: after the chip reset, there
702 * should be no contention.
703 */
704 SEEPROM_OUTB(sd, sd->sd_MS);
705 wait = 1000; /* 1 second timeout in msec */
706 while (--wait && ((SEEPROM_INB(sd) & sd->sd_RDY) == 0)) {
707 DELAY (1000); /* delay 1 msec */
708 }
709 if ((SEEPROM_INB(sd) & sd->sd_RDY) == 0) {
710 SEEPROM_OUTB(sd, 0);
711 return (0);
712 }
713 return(1);
714 }
715
716 static void
717 release_seeprom(sd)
718 struct seeprom_descriptor *sd;
719 {
720 /* Release access to the memory port and the serial EEPROM. */
721 SEEPROM_OUTB(sd, 0);
722 }
723
724 #endif /* NPCI > 0 */
725