1 /*-
2 * Product specific probe and attach routines for:
3 * 27/284X and aic7770 motherboard SCSI controllers
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Copyright (c) 1994-1998, 2000, 2001 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, 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: //depot/aic7xxx/aic7xxx/aic7770.c#34 $
43 */
44
45 #include <dev/aic7xxx/aic7xxx_osm.h>
46 #include <dev/aic7xxx/aic7xxx_inline.h>
47 #include <dev/aic7xxx/aic7xxx_93cx6.h>
48
49 #define ID_AIC7770 0x04907770
50 #define ID_AHA_274x 0x04907771
51 #define ID_AHA_284xB 0x04907756 /* BIOS enabled */
52 #define ID_AHA_284x 0x04907757 /* BIOS disabled*/
53 #define ID_OLV_274x 0x04907782 /* Olivetti OEM */
54 #define ID_OLV_274xD 0x04907783 /* Olivetti OEM (Differential) */
55
56 static int aic7770_chip_init(struct ahc_softc *ahc);
57 static int aic7770_suspend(struct ahc_softc *ahc);
58 static int aic7770_resume(struct ahc_softc *ahc);
59 static int aha2840_load_seeprom(struct ahc_softc *ahc);
60 static ahc_device_setup_t ahc_aic7770_VL_setup;
61 static ahc_device_setup_t ahc_aic7770_EISA_setup; /* Really just ISA */
62 static ahc_device_setup_t ahc_aic7770_setup;
63
64 struct aic7770_identity aic7770_ident_table[] =
65 {
66 {
67 ID_AHA_274x,
68 0xFFFFFFFF,
69 "Adaptec 274X SCSI adapter",
70 ahc_aic7770_EISA_setup
71 },
72 {
73 ID_AHA_284xB,
74 0xFFFFFFFE,
75 "Adaptec 284X SCSI adapter",
76 ahc_aic7770_VL_setup
77 },
78 {
79 ID_AHA_284x,
80 0xFFFFFFFE,
81 "Adaptec 284X SCSI adapter (BIOS Disabled)",
82 ahc_aic7770_VL_setup
83 },
84 {
85 ID_OLV_274x,
86 0xFFFFFFFF,
87 "Adaptec (Olivetti OEM) 274X SCSI adapter",
88 ahc_aic7770_EISA_setup
89 },
90 {
91 ID_OLV_274xD,
92 0xFFFFFFFF,
93 "Adaptec (Olivetti OEM) 274X Differential SCSI adapter",
94 ahc_aic7770_EISA_setup
95 },
96 /* Generic chip probes for devices we don't know 'exactly' */
97 {
98 ID_AIC7770,
99 0xFFFFFFFF,
100 "Adaptec aic7770 SCSI adapter",
101 ahc_aic7770_EISA_setup
102 }
103 };
104 const int ahc_num_aic7770_devs = NUM_ELEMENTS(aic7770_ident_table);
105
106 struct aic7770_identity *
aic7770_find_device(uint32_t id)107 aic7770_find_device(uint32_t id)
108 {
109 struct aic7770_identity *entry;
110 int i;
111
112 for (i = 0; i < ahc_num_aic7770_devs; i++) {
113 entry = &aic7770_ident_table[i];
114 if (entry->full_id == (id & entry->id_mask))
115 return (entry);
116 }
117 return (NULL);
118 }
119
120 int
aic7770_config(struct ahc_softc * ahc,struct aic7770_identity * entry,u_int io)121 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
122 {
123 int error;
124 int have_seeprom;
125 u_int hostconf;
126 u_int irq;
127 u_int intdef;
128
129 error = entry->setup(ahc);
130 have_seeprom = 0;
131 if (error != 0)
132 return (error);
133
134 error = aic7770_map_registers(ahc, io);
135 if (error != 0)
136 return (error);
137
138 /*
139 * Before we continue probing the card, ensure that
140 * its interrupts are *disabled*. We don't want
141 * a misstep to hang the machine in an interrupt
142 * storm.
143 */
144 ahc_intr_enable(ahc, FALSE);
145
146 ahc->description = entry->name;
147 error = ahc_softc_init(ahc);
148 if (error != 0)
149 return (error);
150
151 ahc->bus_chip_init = aic7770_chip_init;
152 ahc->bus_suspend = aic7770_suspend;
153 ahc->bus_resume = aic7770_resume;
154
155 error = ahc_reset(ahc, /*reinit*/FALSE);
156 if (error != 0)
157 return (error);
158
159 /* Make sure we have a valid interrupt vector */
160 intdef = ahc_inb(ahc, INTDEF);
161 irq = intdef & VECTOR;
162 switch (irq) {
163 case 9:
164 case 10:
165 case 11:
166 case 12:
167 case 14:
168 case 15:
169 break;
170 default:
171 printf("aic7770_config: invalid irq setting %d\n", intdef);
172 return (ENXIO);
173 }
174
175 if ((intdef & EDGE_TRIG) != 0)
176 ahc->flags |= AHC_EDGE_INTERRUPT;
177
178 switch (ahc->chip & (AHC_EISA|AHC_VL)) {
179 case AHC_EISA:
180 {
181 u_int biosctrl;
182 u_int scsiconf;
183 u_int scsiconf1;
184
185 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
186 scsiconf = ahc_inb(ahc, SCSICONF);
187 scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
188
189 /* Get the primary channel information */
190 if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
191 ahc->flags |= 1;
192
193 if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
194 ahc->flags |= AHC_USEDEFAULTS;
195 } else {
196 if ((ahc->features & AHC_WIDE) != 0) {
197 ahc->our_id = scsiconf1 & HWSCSIID;
198 if (scsiconf & TERM_ENB)
199 ahc->flags |= AHC_TERM_ENB_A;
200 } else {
201 ahc->our_id = scsiconf & HSCSIID;
202 ahc->our_id_b = scsiconf1 & HSCSIID;
203 if (scsiconf & TERM_ENB)
204 ahc->flags |= AHC_TERM_ENB_A;
205 if (scsiconf1 & TERM_ENB)
206 ahc->flags |= AHC_TERM_ENB_B;
207 }
208 }
209 if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
210 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
211 break;
212 }
213 case AHC_VL:
214 {
215 have_seeprom = aha2840_load_seeprom(ahc);
216 break;
217 }
218 default:
219 break;
220 }
221 if (have_seeprom == 0) {
222 free(ahc->seep_config, M_DEVBUF);
223 ahc->seep_config = NULL;
224 }
225
226 /*
227 * Ensure autoflush is enabled
228 */
229 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
230
231 /* Setup the FIFO threshold and the bus off time */
232 hostconf = ahc_inb(ahc, HOSTCONF);
233 ahc_outb(ahc, BUSSPD, hostconf & DFTHRSH);
234 ahc_outb(ahc, BUSTIME, (hostconf << 2) & BOFF);
235
236 ahc->bus_softc.aic7770_softc.busspd = hostconf & DFTHRSH;
237 ahc->bus_softc.aic7770_softc.bustime = (hostconf << 2) & BOFF;
238
239 /*
240 * Generic aic7xxx initialization.
241 */
242 error = ahc_init(ahc);
243 if (error != 0)
244 return (error);
245
246 error = aic7770_map_int(ahc, irq);
247 if (error != 0)
248 return (error);
249
250 ahc_lock(ahc);
251 /*
252 * Link this softc in with all other ahc instances.
253 */
254 ahc_softc_insert(ahc);
255
256 /*
257 * Enable the board's BUS drivers
258 */
259 ahc_outb(ahc, BCTL, ENABLE);
260
261 ahc_unlock(ahc);
262
263 return (0);
264 }
265
266 static int
aic7770_chip_init(struct ahc_softc * ahc)267 aic7770_chip_init(struct ahc_softc *ahc)
268 {
269 ahc_outb(ahc, BUSSPD, ahc->bus_softc.aic7770_softc.busspd);
270 ahc_outb(ahc, BUSTIME, ahc->bus_softc.aic7770_softc.bustime);
271 ahc_outb(ahc, SBLKCTL, ahc_inb(ahc, SBLKCTL) & ~AUTOFLUSHDIS);
272 ahc_outb(ahc, BCTL, ENABLE);
273 return (ahc_chip_init(ahc));
274 }
275
276 static int
aic7770_suspend(struct ahc_softc * ahc)277 aic7770_suspend(struct ahc_softc *ahc)
278 {
279 return (ahc_suspend(ahc));
280 }
281
282 static int
aic7770_resume(struct ahc_softc * ahc)283 aic7770_resume(struct ahc_softc *ahc)
284 {
285 return (ahc_resume(ahc));
286 }
287
288 /*
289 * Read the 284x SEEPROM.
290 */
291 static int
aha2840_load_seeprom(struct ahc_softc * ahc)292 aha2840_load_seeprom(struct ahc_softc *ahc)
293 {
294 struct seeprom_descriptor sd;
295 struct seeprom_config *sc;
296 int have_seeprom;
297 uint8_t scsi_conf;
298
299 sd.sd_ahc = ahc;
300 sd.sd_control_offset = SEECTL_2840;
301 sd.sd_status_offset = STATUS_2840;
302 sd.sd_dataout_offset = STATUS_2840;
303 sd.sd_chip = C46;
304 sd.sd_MS = 0;
305 sd.sd_RDY = EEPROM_TF;
306 sd.sd_CS = CS_2840;
307 sd.sd_CK = CK_2840;
308 sd.sd_DO = DO_2840;
309 sd.sd_DI = DI_2840;
310 sc = ahc->seep_config;
311
312 if (bootverbose)
313 printf("%s: Reading SEEPROM...", ahc_name(ahc));
314 have_seeprom = ahc_read_seeprom(&sd, (uint16_t *)sc,
315 /*start_addr*/0, sizeof(*sc)/2);
316
317 if (have_seeprom) {
318 if (ahc_verify_cksum(sc) == 0) {
319 if(bootverbose)
320 printf ("checksum error\n");
321 have_seeprom = 0;
322 } else if (bootverbose) {
323 printf("done.\n");
324 }
325 }
326
327 if (!have_seeprom) {
328 if (bootverbose)
329 printf("%s: No SEEPROM available\n", ahc_name(ahc));
330 ahc->flags |= AHC_USEDEFAULTS;
331 } else {
332 /*
333 * Put the data we've collected down into SRAM
334 * where ahc_init will find it.
335 */
336 int i;
337 int max_targ;
338 uint16_t discenable;
339
340 max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
341 discenable = 0;
342 for (i = 0; i < max_targ; i++){
343 uint8_t target_settings;
344
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);
353 }
354 ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
355 ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
356
357 ahc->our_id = sc->brtime_id & CFSCSIID;
358
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;
364
365 if (sc->bios_control & CF284XEXTEND)
366 ahc->flags |= AHC_EXTENDED_TRANS_A;
367 /* Set SCSICONF info */
368 ahc_outb(ahc, SCSICONF, scsi_conf);
369
370 if (sc->adapter_control & CF284XSTERM)
371 ahc->flags |= AHC_TERM_ENB_A;
372 }
373 return (have_seeprom);
374 }
375
376 static int
ahc_aic7770_VL_setup(struct ahc_softc * ahc)377 ahc_aic7770_VL_setup(struct ahc_softc *ahc)
378 {
379 int error;
380
381 error = ahc_aic7770_setup(ahc);
382 ahc->chip |= AHC_VL;
383 return (error);
384 }
385
386 static int
ahc_aic7770_EISA_setup(struct ahc_softc * ahc)387 ahc_aic7770_EISA_setup(struct ahc_softc *ahc)
388 {
389 int error;
390
391 error = ahc_aic7770_setup(ahc);
392 ahc->chip |= AHC_EISA;
393 return (error);
394 }
395
396 static int
ahc_aic7770_setup(struct ahc_softc * ahc)397 ahc_aic7770_setup(struct ahc_softc *ahc)
398 {
399 ahc->channel = 'A';
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;
406 return (0);
407 }
408