2 * Product specific probe and attach routines for:
3 * 27/284X and aic7770 motherboard SCSI controllers
5 * Copyright (c) 1994-1998, 2000, 2001 Justin T. Gibbs.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * substantially similar to the "NO WARRANTY" disclaimer below
16 * ("Disclaimer") and any redistribution must be conditioned upon
17 * including a substantially similar Disclaimer requirement for further
18 * binary redistribution.
19 * 3. Neither the names of the above-listed copyright holders nor the names
20 * of any contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * Alternatively, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") version 2 as published by the Free
25 * Software Foundation.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES.
40 * $Id: //depot/aic7xxx/aic7xxx/aic7770.c#32 $
46 #include "aic7xxx_osm.h"
47 #include "aic7xxx_inline.h"
48 #include "aic7xxx_93cx6.h"
50 #include <dev/aic7xxx/aic7xxx_osm.h>
51 #include <dev/aic7xxx/aic7xxx_inline.h>
52 #include <dev/aic7xxx/aic7xxx_93cx6.h>
55 #define ID_AIC7770 0x04907770
56 #define ID_AHA_274x 0x04907771
57 #define ID_AHA_284xB 0x04907756 /* BIOS enabled */
58 #define ID_AHA_284x 0x04907757 /* BIOS disabled*/
59 #define ID_OLV_274x 0x04907782 /* Olivetti OEM */
60 #define ID_OLV_274xD 0x04907783 /* Olivetti OEM (Differential) */
62 static int aic7770_chip_init(struct ahc_softc *ahc);
63 static int aic7770_suspend(struct ahc_softc *ahc);
64 static int aic7770_resume(struct ahc_softc *ahc);
65 static int aha2840_load_seeprom(struct ahc_softc *ahc);
66 static ahc_device_setup_t ahc_aic7770_VL_setup;
67 static ahc_device_setup_t ahc_aic7770_EISA_setup;
68 static ahc_device_setup_t ahc_aic7770_setup;
70 struct aic7770_identity aic7770_ident_table[] =
75 "Adaptec 274X SCSI adapter",
76 ahc_aic7770_EISA_setup
81 "Adaptec 284X SCSI adapter",
87 "Adaptec 284X SCSI adapter (BIOS Disabled)",
93 "Adaptec (Olivetti OEM) 274X SCSI adapter",
94 ahc_aic7770_EISA_setup
99 "Adaptec (Olivetti OEM) 274X Differential SCSI adapter",
100 ahc_aic7770_EISA_setup
102 /* Generic chip probes for devices we don't know 'exactly' */
106 "Adaptec aic7770 SCSI adapter",
107 ahc_aic7770_EISA_setup
110 const int ahc_num_aic7770_devs = ARRAY_SIZE(aic7770_ident_table);
112 struct aic7770_identity *
113 aic7770_find_device(uint32_t id)
115 struct aic7770_identity *entry;
118 for (i = 0; i < ahc_num_aic7770_devs; i++) {
119 entry = &aic7770_ident_table[i];
120 if (entry->full_id == (id & entry->id_mask))
127 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
135 error = entry->setup(ahc);
140 error = aic7770_map_registers(ahc, io);
145 * Before we continue probing the card, ensure that
146 * its interrupts are *disabled*. We don't want
147 * a misstep to hang the machine in an interrupt
150 ahc_intr_enable(ahc, FALSE);
152 ahc->description = entry->name;
153 error = ahc_softc_init(ahc);
157 ahc->bus_chip_init = aic7770_chip_init;
158 ahc->bus_suspend = aic7770_suspend;
159 ahc->bus_resume = aic7770_resume;
161 error = ahc_reset(ahc, /*reinit*/FALSE);
165 /* Make sure we have a valid interrupt vector */
166 intdef = ahc_inb(ahc, INTDEF);
167 irq = intdef & VECTOR;
177 printf("aic7770_config: invalid irq setting %d\n", intdef);
181 if ((intdef & EDGE_TRIG) != 0)
182 ahc->flags |= AHC_EDGE_INTERRUPT;
184 switch (ahc->chip & (AHC_EISA|AHC_VL)) {
191 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
192 scsiconf = ahc_inb(ahc, SCSICONF);
193 scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
195 /* Get the primary channel information */
196 if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
199 if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
200 ahc->flags |= AHC_USEDEFAULTS;
202 if ((ahc->features & AHC_WIDE) != 0) {
203 ahc->our_id = scsiconf1 & HWSCSIID;
204 if (scsiconf & TERM_ENB)
205 ahc->flags |= AHC_TERM_ENB_A;
207 ahc->our_id = scsiconf & HSCSIID;
208 ahc->our_id_b = scsiconf1 & HSCSIID;
209 if (scsiconf & TERM_ENB)
210 ahc->flags |= AHC_TERM_ENB_A;
211 if (scsiconf1 & TERM_ENB)
212 ahc->flags |= AHC_TERM_ENB_B;
215 if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
216 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
221 have_seeprom = aha2840_load_seeprom(ahc);
227 if (have_seeprom == 0) {
228 free(ahc->seep_config, M_DEVBUF);
229 ahc->seep_config = NULL;
233 * Ensure autoflush is enabled
235 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
237 /* Setup the FIFO threshold and the bus off time */
238 hostconf = ahc_inb(ahc, HOSTCONF);
239 ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
240 ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
242 ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH;
243 ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF;
246 * Generic aic7xxx initialization.
248 error = ahc_init(ahc);
252 error = aic7770_map_int(ahc, irq);
259 * Enable the board's BUS drivers
261 ahc_outb(ahc, BCTL, ENABLE);
266 aic7770_chip_init(struct ahc_softc *ahc)
268 ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd);
269 ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime);
270 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
271 ahc_outb(ahc, BCTL, ENABLE);
272 return (ahc_chip_init(ahc));
276 aic7770_suspend(struct ahc_softc *ahc)
278 return (ahc_suspend(ahc));
282 aic7770_resume(struct ahc_softc *ahc)
284 return (ahc_resume(ahc));
288 * Read the 284x SEEPROM.
291 aha2840_load_seeprom(struct ahc_softc *ahc)
293 struct seeprom_descriptor sd;
294 struct seeprom_config *sc;
299 sd.sd_control_offset = SEECTL_2840;
300 sd.sd_status_offset = STATUS_2840;
301 sd.sd_dataout_offset = STATUS_2840;
304 sd.sd_RDY = EEPROM_TF;
309 sc = ahc->seep_config;
312 printf("%s: Reading SEEPROM...", ahc_name(ahc));
313 have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
314 /*start_addr*/0, sizeof(*sc)/2);
318 if (ahc_verify_cksum(sc) == 0) {
320 printf ("checksum error\n");
322 } else if (bootverbose) {
329 printf("%s: No SEEPROM available\n", ahc_name(ahc));
330 ahc->flags |= AHC_USEDEFAULTS;
333 * Put the data we've collected down into SRAM
334 * where ahc_init will find it.
340 max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
342 for (i = 0; i < max_targ; i++){
343 uint8_t target_settings;
345 target_settings = (sc->device_flags[i] & CFXFER) << 4;
346 if (sc->device_flags[i] & CFSYNCH)
347 target_settings |= SOFS;
348 if (sc->device_flags[i] & CFWIDEB)
349 target_settings |= WIDEXFER;
350 if (sc->device_flags[i] & CFDISC)
351 discenable |= (0x01 << i);
352 ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
354 ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
355 ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
357 ahc->our_id = sc->brtime_id & CFSCSIID;
359 scsi_conf = (ahc->our_id & 0x7);
360 if (sc->adapter_control & CFSPARITY)
361 scsi_conf |= ENSPCHK;
362 if (sc->adapter_control & CFRESETB)
363 scsi_conf |= RESET_SCSI;
365 if (sc->bios_control & CF284XEXTEND)
366 ahc->flags |= AHC_EXTENDED_TRANS_A;
367 /* Set SCSICONF info */
368 ahc_outb(ahc, SCSICONF, scsi_conf);
370 if (sc->adapter_control & CF284XSTERM)
371 ahc->flags |= AHC_TERM_ENB_A;
373 return (have_seeprom);
377 ahc_aic7770_VL_setup(struct ahc_softc *ahc)
381 error = ahc_aic7770_setup(ahc);
387 ahc_aic7770_EISA_setup(struct ahc_softc *ahc)
391 error = ahc_aic7770_setup(ahc);
392 ahc->chip |= AHC_EISA;
397 ahc_aic7770_setup(struct ahc_softc *ahc)
400 ahc->channel_b = 'B';
401 ahc->chip = AHC_AIC7770;
402 ahc->features = AHC_AIC7770_FE;
403 ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
404 ahc->flags |= AHC_PAGESCBS;
405 ahc->instruction_ram_size = 448;