adwlib.c revision 1.13 1 1.13 dante /* $NetBSD: adwlib.c,v 1.13 2000/05/14 18:25:49 dante Exp $ */
2 1.1 dante
3 1.1 dante /*
4 1.1 dante * Low level routines for the Advanced Systems Inc. SCSI controllers chips
5 1.1 dante *
6 1.7 dante * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
7 1.1 dante * All rights reserved.
8 1.1 dante *
9 1.1 dante * Author: Baldassare Dante Profeta <dante (at) mclink.it>
10 1.1 dante *
11 1.1 dante * Redistribution and use in source and binary forms, with or without
12 1.1 dante * modification, are permitted provided that the following conditions
13 1.1 dante * are met:
14 1.1 dante * 1. Redistributions of source code must retain the above copyright
15 1.1 dante * notice, this list of conditions and the following disclaimer.
16 1.1 dante * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 dante * notice, this list of conditions and the following disclaimer in the
18 1.1 dante * documentation and/or other materials provided with the distribution.
19 1.1 dante * 3. All advertising materials mentioning features or use of this software
20 1.1 dante * must display the following acknowledgement:
21 1.1 dante * This product includes software developed by the NetBSD
22 1.1 dante * Foundation, Inc. and its contributors.
23 1.1 dante * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 dante * contributors may be used to endorse or promote products derived
25 1.1 dante * from this software without specific prior written permission.
26 1.1 dante *
27 1.1 dante * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 dante * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 dante * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 dante * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 dante * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 dante * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 dante * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 dante * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 dante * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 dante * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 dante * POSSIBILITY OF SUCH DAMAGE.
38 1.1 dante */
39 1.1 dante /*
40 1.1 dante * Ported from:
41 1.1 dante */
42 1.1 dante /*
43 1.1 dante * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
44 1.7 dante *
45 1.10 dante * Copyright (c) 1995-2000 Advanced System Products, Inc.
46 1.1 dante * All Rights Reserved.
47 1.1 dante *
48 1.1 dante * Redistribution and use in source and binary forms, with or without
49 1.1 dante * modification, are permitted provided that redistributions of source
50 1.1 dante * code retain the above copyright notice and this comment without
51 1.1 dante * modification.
52 1.1 dante */
53 1.1 dante
54 1.1 dante #include <sys/types.h>
55 1.1 dante #include <sys/param.h>
56 1.1 dante #include <sys/systm.h>
57 1.1 dante #include <sys/malloc.h>
58 1.1 dante #include <sys/kernel.h>
59 1.1 dante #include <sys/queue.h>
60 1.1 dante #include <sys/device.h>
61 1.1 dante
62 1.1 dante #include <machine/bus.h>
63 1.1 dante #include <machine/intr.h>
64 1.1 dante
65 1.1 dante #include <dev/scsipi/scsi_all.h>
66 1.1 dante #include <dev/scsipi/scsipi_all.h>
67 1.1 dante #include <dev/scsipi/scsiconf.h>
68 1.1 dante
69 1.7 dante #include <dev/pci/pcidevs.h>
70 1.7 dante
71 1.1 dante #include <vm/vm.h>
72 1.1 dante #include <vm/vm_param.h>
73 1.1 dante #include <vm/pmap.h>
74 1.1 dante
75 1.1 dante #include <dev/ic/adwlib.h>
76 1.1 dante #include <dev/ic/adw.h>
77 1.1 dante #include <dev/ic/adwmcode.h>
78 1.1 dante
79 1.1 dante
80 1.1 dante /* Static Functions */
81 1.1 dante
82 1.7 dante static u_int16_t AdvGet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
83 1.7 dante ADW_EEP_3550_CONFIG *));
84 1.7 dante static u_int16_t AdvGet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
85 1.7 dante ADW_EEP_38C0800_CONFIG *));
86 1.10 dante static u_int16_t AdvGet38C1600EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
87 1.10 dante ADW_EEP_38C1600_CONFIG *));
88 1.7 dante static u_int16_t AdvReadEEPWord __P((bus_space_tag_t, bus_space_handle_t, int));
89 1.1 dante static void AdvWaitEEPCmd __P((bus_space_tag_t, bus_space_handle_t));
90 1.7 dante static void AdvSet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
91 1.7 dante ADW_EEP_3550_CONFIG *));
92 1.7 dante static void AdvSet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
93 1.7 dante ADW_EEP_38C0800_CONFIG *));
94 1.10 dante static void AdvSet38C1600EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
95 1.10 dante ADW_EEP_38C1600_CONFIG *));
96 1.1 dante static void AdvInquiryHandling __P((ADW_SOFTC *, ADW_SCSI_REQ_Q *));
97 1.1 dante
98 1.7 dante static void AdvSleepMilliSecond __P((u_int32_t));
99 1.7 dante static void AdvDelayMicroSecond __P((u_int32_t));
100 1.1 dante
101 1.1 dante
102 1.1 dante /*
103 1.1 dante * EEPROM Configuration.
104 1.1 dante *
105 1.1 dante * All drivers should use this structure to set the default EEPROM
106 1.1 dante * configuration. The BIOS now uses this structure when it is built.
107 1.1 dante * Additional structure information can be found in advlib.h where
108 1.1 dante * the structure is defined.
109 1.1 dante */
110 1.7 dante static ADW_EEP_3550_CONFIG
111 1.7 dante Default_3550_EEPROM_Config = {
112 1.7 dante ADW_EEPROM_BIOS_ENABLE, /* cfg_lsw */
113 1.7 dante 0x0000, /* cfg_msw */
114 1.7 dante 0xFFFF, /* disc_enable */
115 1.7 dante 0xFFFF, /* wdtr_able */
116 1.7 dante 0xFFFF, /* sdtr_able */
117 1.7 dante 0xFFFF, /* start_motor */
118 1.7 dante 0xFFFF, /* tagqng_able */
119 1.7 dante 0xFFFF, /* bios_scan */
120 1.7 dante 0, /* scam_tolerant */
121 1.7 dante 7, /* adapter_scsi_id */
122 1.7 dante 0, /* bios_boot_delay */
123 1.7 dante 3, /* scsi_reset_delay */
124 1.7 dante 0, /* bios_id_lun */
125 1.7 dante 0, /* termination */
126 1.7 dante 0, /* reserved1 */
127 1.7 dante 0xFFE7, /* bios_ctrl */
128 1.7 dante 0xFFFF, /* ultra_able */
129 1.7 dante 0, /* reserved2 */
130 1.2 dante ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
131 1.2 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
132 1.7 dante 0, /* dvc_cntl */
133 1.7 dante 0, /* bug_fix */
134 1.7 dante 0, /* serial_number_word1 */
135 1.7 dante 0, /* serial_number_word2 */
136 1.7 dante 0, /* serial_number_word3 */
137 1.7 dante 0, /* check_sum */
138 1.11 dante { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* oem_name[16] */
139 1.7 dante 0, /* dvc_err_code */
140 1.7 dante 0, /* adv_err_code */
141 1.7 dante 0, /* adv_err_addr */
142 1.7 dante 0, /* saved_dvc_err_code */
143 1.7 dante 0, /* saved_adv_err_code */
144 1.7 dante 0, /* saved_adv_err_addr */
145 1.7 dante 0 /* num_of_err */
146 1.7 dante };
147 1.7 dante
148 1.7 dante static ADW_EEP_38C0800_CONFIG
149 1.7 dante Default_38C0800_EEPROM_Config = {
150 1.7 dante ADW_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
151 1.7 dante 0x0000, /* 01 cfg_msw */
152 1.7 dante 0xFFFF, /* 02 disc_enable */
153 1.7 dante 0xFFFF, /* 03 wdtr_able */
154 1.7 dante 0x4444, /* 04 sdtr_speed1 */
155 1.7 dante 0xFFFF, /* 05 start_motor */
156 1.7 dante 0xFFFF, /* 06 tagqng_able */
157 1.7 dante 0xFFFF, /* 07 bios_scan */
158 1.7 dante 0, /* 08 scam_tolerant */
159 1.7 dante 7, /* 09 adapter_scsi_id */
160 1.7 dante 0, /* bios_boot_delay */
161 1.7 dante 3, /* 10 scsi_reset_delay */
162 1.7 dante 0, /* bios_id_lun */
163 1.7 dante 0, /* 11 termination_se */
164 1.7 dante 0, /* termination_lvd */
165 1.7 dante 0xFFE7, /* 12 bios_ctrl */
166 1.7 dante 0x4444, /* 13 sdtr_speed2 */
167 1.7 dante 0x4444, /* 14 sdtr_speed3 */
168 1.7 dante ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
169 1.7 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
170 1.7 dante 0, /* 16 dvc_cntl */
171 1.7 dante 0x4444, /* 17 sdtr_speed4 */
172 1.7 dante 0, /* 18 serial_number_word1 */
173 1.7 dante 0, /* 19 serial_number_word2 */
174 1.7 dante 0, /* 20 serial_number_word3 */
175 1.7 dante 0, /* 21 check_sum */
176 1.7 dante { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
177 1.7 dante 0, /* 30 dvc_err_code */
178 1.7 dante 0, /* 31 adv_err_code */
179 1.7 dante 0, /* 32 adv_err_addr */
180 1.7 dante 0, /* 33 saved_dvc_err_code */
181 1.7 dante 0, /* 34 saved_adv_err_code */
182 1.7 dante 0, /* 35 saved_adv_err_addr */
183 1.7 dante 0, /* 36 reserved */
184 1.7 dante 0, /* 37 reserved */
185 1.7 dante 0, /* 38 reserved */
186 1.7 dante 0, /* 39 reserved */
187 1.7 dante 0, /* 40 reserved */
188 1.7 dante 0, /* 41 reserved */
189 1.7 dante 0, /* 42 reserved */
190 1.7 dante 0, /* 43 reserved */
191 1.7 dante 0, /* 44 reserved */
192 1.7 dante 0, /* 45 reserved */
193 1.7 dante 0, /* 46 reserved */
194 1.7 dante 0, /* 47 reserved */
195 1.7 dante 0, /* 48 reserved */
196 1.7 dante 0, /* 49 reserved */
197 1.7 dante 0, /* 50 reserved */
198 1.7 dante 0, /* 51 reserved */
199 1.7 dante 0, /* 52 reserved */
200 1.7 dante 0, /* 53 reserved */
201 1.7 dante 0, /* 54 reserved */
202 1.7 dante 0, /* 55 reserved */
203 1.7 dante 0, /* 56 cisptr_lsw */
204 1.7 dante 0, /* 57 cisprt_msw */
205 1.7 dante PCI_VENDOR_ADVSYS, /* 58 subsysvid */
206 1.7 dante PCI_PRODUCT_ADVSYS_U2W, /* 59 subsysid */
207 1.7 dante 0, /* 60 reserved */
208 1.7 dante 0, /* 61 reserved */
209 1.7 dante 0, /* 62 reserved */
210 1.7 dante 0 /* 63 reserved */
211 1.1 dante };
212 1.1 dante
213 1.10 dante static ADW_EEP_38C1600_CONFIG
214 1.10 dante Default_38C1600_EEPROM_Config = {
215 1.10 dante ADW_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
216 1.10 dante 0x0000, /* 01 cfg_msw */
217 1.10 dante 0xFFFF, /* 02 disc_enable */
218 1.10 dante 0xFFFF, /* 03 wdtr_able */
219 1.10 dante 0x5555, /* 04 sdtr_speed1 */
220 1.10 dante 0xFFFF, /* 05 start_motor */
221 1.10 dante 0xFFFF, /* 06 tagqng_able */
222 1.10 dante 0xFFFF, /* 07 bios_scan */
223 1.10 dante 0, /* 08 scam_tolerant */
224 1.10 dante 7, /* 09 adapter_scsi_id */
225 1.10 dante 0, /* bios_boot_delay */
226 1.10 dante 3, /* 10 scsi_reset_delay */
227 1.10 dante 0, /* bios_id_lun */
228 1.10 dante 0, /* 11 termination_se */
229 1.10 dante 0, /* termination_lvd */
230 1.10 dante 0xFFE7, /* 12 bios_ctrl */
231 1.10 dante 0x5555, /* 13 sdtr_speed2 */
232 1.10 dante 0x5555, /* 14 sdtr_speed3 */
233 1.10 dante ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
234 1.10 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
235 1.10 dante 0, /* 16 dvc_cntl */
236 1.10 dante 0x5555, /* 17 sdtr_speed4 */
237 1.10 dante 0, /* 18 serial_number_word1 */
238 1.10 dante 0, /* 19 serial_number_word2 */
239 1.10 dante 0, /* 20 serial_number_word3 */
240 1.10 dante 0, /* 21 check_sum */
241 1.10 dante { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
242 1.10 dante 0, /* 30 dvc_err_code */
243 1.10 dante 0, /* 31 adv_err_code */
244 1.10 dante 0, /* 32 adv_err_addr */
245 1.10 dante 0, /* 33 saved_dvc_err_code */
246 1.10 dante 0, /* 34 saved_adv_err_code */
247 1.10 dante 0, /* 35 saved_adv_err_addr */
248 1.10 dante 0, /* 36 reserved */
249 1.10 dante 0, /* 37 reserved */
250 1.10 dante 0, /* 38 reserved */
251 1.10 dante 0, /* 39 reserved */
252 1.10 dante 0, /* 40 reserved */
253 1.10 dante 0, /* 41 reserved */
254 1.10 dante 0, /* 42 reserved */
255 1.10 dante 0, /* 43 reserved */
256 1.10 dante 0, /* 44 reserved */
257 1.10 dante 0, /* 45 reserved */
258 1.10 dante 0, /* 46 reserved */
259 1.10 dante 0, /* 47 reserved */
260 1.10 dante 0, /* 48 reserved */
261 1.10 dante 0, /* 49 reserved */
262 1.10 dante 0, /* 50 reserved */
263 1.10 dante 0, /* 51 reserved */
264 1.10 dante 0, /* 52 reserved */
265 1.10 dante 0, /* 53 reserved */
266 1.10 dante 0, /* 54 reserved */
267 1.10 dante 0, /* 55 reserved */
268 1.10 dante 0, /* 56 cisptr_lsw */
269 1.10 dante 0, /* 57 cisprt_msw */
270 1.10 dante PCI_VENDOR_ADVSYS, /* 58 subsysvid */
271 1.10 dante PCI_PRODUCT_ADVSYS_U3W, /* 59 subsysid */
272 1.10 dante 0, /* 60 reserved */
273 1.10 dante 0, /* 61 reserved */
274 1.10 dante 0, /* 62 reserved */
275 1.10 dante 0 /* 63 reserved */
276 1.10 dante };
277 1.10 dante
278 1.1 dante /*
279 1.1 dante * Initialize the ASC3550.
280 1.1 dante *
281 1.1 dante * On failure set the ADW_SOFTC field 'err_code' and return ADW_ERROR.
282 1.1 dante *
283 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
284 1.1 dante * then 0 is returned.
285 1.1 dante */
286 1.1 dante int
287 1.1 dante AdvInitAsc3550Driver(sc)
288 1.2 dante ADW_SOFTC *sc;
289 1.1 dante {
290 1.2 dante bus_space_tag_t iot = sc->sc_iot;
291 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
292 1.7 dante u_int16_t warn_code;
293 1.7 dante u_int32_t sum;
294 1.7 dante int begin_addr;
295 1.7 dante int end_addr;
296 1.7 dante u_int16_t code_sum;
297 1.7 dante int word;
298 1.7 dante int i, j;
299 1.7 dante int adv_asc3550_expanded_size;
300 1.7 dante u_int16_t scsi_cfg1;
301 1.7 dante u_int8_t tid;
302 1.7 dante u_int16_t bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory
303 1.7 dante 0x40-0x8F. */
304 1.7 dante u_int16_t wdtr_able = 0, sdtr_able, tagqng_able;
305 1.7 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
306 1.1 dante
307 1.1 dante
308 1.1 dante warn_code = 0;
309 1.1 dante
310 1.1 dante /*
311 1.1 dante * Save the RISC memory BIOS region before writing the microcode.
312 1.1 dante * The BIOS may already be loaded and using its RISC LRAM region
313 1.1 dante * so its region must be saved and restored.
314 1.1 dante *
315 1.1 dante * Note: This code makes the assumption, which is currently true,
316 1.1 dante * that a chip reset does not clear RISC LRAM.
317 1.1 dante */
318 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
319 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM+(2*i), bios_mem[i]);
320 1.7 dante }
321 1.7 dante
322 1.7 dante /*
323 1.7 dante * Save current per TID negotiated values.
324 1.7 dante */
325 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA) {
326 1.7 dante
327 1.7 dante u_int16_t bios_version, major, minor;
328 1.7 dante
329 1.7 dante bios_version = bios_mem[(ASC_MC_BIOS_VERSION-ASC_MC_BIOSMEM)/2];
330 1.7 dante major = (bios_version >> 12) & 0xF;
331 1.7 dante minor = (bios_version >> 8) & 0xF;
332 1.7 dante if (major < 3 || (major == 3 && minor == 1)) {
333 1.7 dante /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
334 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, 0x120, wdtr_able);
335 1.7 dante } else {
336 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
337 1.7 dante }
338 1.7 dante }
339 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
340 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
341 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
342 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
343 1.7 dante max_cmd[tid]);
344 1.1 dante }
345 1.1 dante
346 1.1 dante /*
347 1.1 dante * Load the Microcode
348 1.1 dante *
349 1.1 dante * Write the microcode image to RISC memory starting at address 0.
350 1.1 dante */
351 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
352 1.7 dante
353 1.7 dante /* Assume the following compressed format of the microcode buffer:
354 1.7 dante *
355 1.7 dante * 254 word (508 byte) table indexed by byte code followed
356 1.7 dante * by the following byte codes:
357 1.7 dante *
358 1.7 dante * 1-Byte Code:
359 1.7 dante * 00: Emit word 0 in table.
360 1.7 dante * 01: Emit word 1 in table.
361 1.7 dante * .
362 1.7 dante * FD: Emit word 253 in table.
363 1.7 dante *
364 1.7 dante * Multi-Byte Code:
365 1.7 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
366 1.7 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
367 1.7 dante */
368 1.7 dante word = 0;
369 1.7 dante for (i = 253 * 2; i < adv_asc3550_mcode_size; i++) {
370 1.7 dante if (adv_asc3550_mcode[i] == 0xff) {
371 1.7 dante for (j = 0; j < adv_asc3550_mcode[i + 1]; j++) {
372 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
373 1.7 dante (((u_int16_t)adv_asc3550_mcode[i + 3] << 8) |
374 1.7 dante adv_asc3550_mcode[i + 2]));
375 1.7 dante word++;
376 1.7 dante }
377 1.7 dante i += 3;
378 1.7 dante } else if (adv_asc3550_mcode[i] == 0xfe) {
379 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
380 1.7 dante (((u_int16_t)adv_asc3550_mcode[i + 2] << 8) |
381 1.7 dante adv_asc3550_mcode[i + 1]));
382 1.7 dante i += 2;
383 1.7 dante word++;
384 1.7 dante } else {
385 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
386 1.10 dante adv_asc3550_mcode[(adv_asc3550_mcode[i] * 2) + 1] <<8)|
387 1.7 dante adv_asc3550_mcode[adv_asc3550_mcode[i] * 2]));
388 1.7 dante word++;
389 1.7 dante }
390 1.1 dante }
391 1.1 dante
392 1.1 dante /*
393 1.7 dante * Set 'word' for later use to clear the rest of memory and save
394 1.7 dante * the expanded mcode size.
395 1.7 dante */
396 1.7 dante word *= 2;
397 1.7 dante adv_asc3550_expanded_size = word;
398 1.7 dante
399 1.7 dante /*
400 1.7 dante * Clear the rest of ASC-3550 Internal RAM (8KB).
401 1.1 dante */
402 1.7 dante for (; word < ADV_3550_MEMSIZE; word += 2) {
403 1.1 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
404 1.1 dante }
405 1.1 dante
406 1.1 dante /*
407 1.1 dante * Verify the microcode checksum.
408 1.1 dante */
409 1.1 dante sum = 0;
410 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
411 1.7 dante
412 1.7 dante for (word = 0; word < adv_asc3550_expanded_size; word += 2) {
413 1.1 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
414 1.1 dante }
415 1.1 dante
416 1.7 dante if (sum != adv_asc3550_mcode_chksum) {
417 1.1 dante return ASC_IERR_MCODE_CHKSUM;
418 1.7 dante }
419 1.1 dante
420 1.1 dante /*
421 1.1 dante * Restore the RISC memory BIOS region.
422 1.1 dante */
423 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
424 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i),
425 1.7 dante bios_mem[i]);
426 1.1 dante }
427 1.1 dante
428 1.1 dante /*
429 1.1 dante * Calculate and write the microcode code checksum to the microcode
430 1.2 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
431 1.1 dante */
432 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
433 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
434 1.1 dante code_sum = 0;
435 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
436 1.1 dante for (word = begin_addr; word < end_addr; word += 2) {
437 1.7 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
438 1.1 dante }
439 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
440 1.1 dante
441 1.1 dante /*
442 1.7 dante * Read and save microcode version and date.
443 1.1 dante */
444 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE,
445 1.7 dante sc->cfg.mcode_date);
446 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM,
447 1.7 dante sc->cfg.mcode_version);
448 1.1 dante
449 1.1 dante /*
450 1.7 dante * Set the chip type to indicate the ASC3550.
451 1.1 dante */
452 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
453 1.1 dante
454 1.1 dante /*
455 1.1 dante * If the PCI Configuration Command Register "Parity Error Response
456 1.1 dante * Control" Bit was clear (0), then set the microcode variable
457 1.1 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
458 1.1 dante * to ignore DMA parity errors.
459 1.1 dante */
460 1.1 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
461 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
462 1.1 dante word |= CONTROL_FLAG_IGNORE_PERR;
463 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
464 1.1 dante }
465 1.7 dante
466 1.1 dante /*
467 1.7 dante * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
468 1.7 dante * threshold of 128 bytes. This register is only accessible to the host.
469 1.1 dante */
470 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
471 1.7 dante START_CTL_EMFU | READ_CMD_MRM);
472 1.7 dante
473 1.7 dante /*
474 1.7 dante * Microcode operating variables for WDTR, SDTR, and command tag
475 1.7 dante * queuing will be set in AdvInquiryHandling() based on what a
476 1.7 dante * device reports it is capable of in Inquiry byte 7.
477 1.7 dante *
478 1.7 dante * If SCSI Bus Resets haev been disabled, then directly set
479 1.7 dante * SDTR and WDTR from the EEPROM configuration. This will allow
480 1.7 dante * the BIOS and warm boot to work without a SCSI bus hang on
481 1.7 dante * the Inquiry caused by host and target mismatched DTR values.
482 1.7 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
483 1.7 dante * be assumed to be in Asynchronous, Narrow mode.
484 1.7 dante */
485 1.7 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
486 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
487 1.7 dante sc->wdtr_able);
488 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
489 1.7 dante sc->sdtr_able);
490 1.7 dante }
491 1.7 dante
492 1.7 dante /*
493 1.7 dante * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
494 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
495 1.7 dante * bitmask. These values determine the maximum SDTR speed negotiated
496 1.7 dante * with a device.
497 1.7 dante *
498 1.7 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
499 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
500 1.7 dante * without determining here whether the device supports SDTR.
501 1.7 dante *
502 1.7 dante * 4-bit speed SDTR speed name
503 1.7 dante * =========== ===============
504 1.7 dante * 0000b (0x0) SDTR disabled
505 1.7 dante * 0001b (0x1) 5 Mhz
506 1.7 dante * 0010b (0x2) 10 Mhz
507 1.7 dante * 0011b (0x3) 20 Mhz (Ultra)
508 1.7 dante * 0100b (0x4) 40 Mhz (LVD/Ultra2)
509 1.7 dante * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
510 1.7 dante * 0110b (0x6) Undefined
511 1.7 dante * .
512 1.7 dante * 1111b (0xF) Undefined
513 1.7 dante */
514 1.7 dante word = 0;
515 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
516 1.7 dante if (ADW_TID_TO_TIDMASK(tid) & sc->ultra_able) {
517 1.7 dante /* Set Ultra speed for TID 'tid'. */
518 1.7 dante word |= (0x3 << (4 * (tid % 4)));
519 1.7 dante } else {
520 1.7 dante /* Set Fast speed for TID 'tid'. */
521 1.7 dante word |= (0x2 << (4 * (tid % 4)));
522 1.7 dante }
523 1.7 dante /* Check if done with sdtr_speed1. */
524 1.7 dante if (tid == 3) {
525 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED1, word);
526 1.7 dante word = 0;
527 1.7 dante /* Check if done with sdtr_speed2. */
528 1.7 dante } else if (tid == 7) {
529 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED2, word);
530 1.7 dante word = 0;
531 1.7 dante /* Check if done with sdtr_speed3. */
532 1.7 dante } else if (tid == 11) {
533 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED3, word);
534 1.7 dante word = 0;
535 1.7 dante /* Check if done with sdtr_speed4. */
536 1.7 dante } else if (tid == 15) {
537 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED4, word);
538 1.7 dante /* End of loop. */
539 1.7 dante }
540 1.7 dante }
541 1.1 dante
542 1.1 dante /*
543 1.7 dante * Set microcode operating variable for the disconnect per TID bitmask.
544 1.1 dante */
545 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
546 1.1 dante
547 1.1 dante
548 1.1 dante /*
549 1.1 dante * Set SCSI_CFG0 Microcode Default Value.
550 1.1 dante *
551 1.1 dante * The microcode will set the SCSI_CFG0 register using this value
552 1.1 dante * after it is started below.
553 1.1 dante */
554 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
555 1.10 dante ADW_PARITY_EN | ADW_QUEUE_128 | ADW_SEL_TMO_LONG |
556 1.10 dante ADW_OUR_ID_EN | sc->chip_scsi_id);
557 1.2 dante
558 1.1 dante /*
559 1.1 dante * Determine SCSI_CFG1 Microcode Default Value.
560 1.1 dante *
561 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
562 1.1 dante * after it is started below.
563 1.1 dante */
564 1.1 dante
565 1.1 dante /* Read current SCSI_CFG1 Register value. */
566 1.1 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
567 1.1 dante
568 1.1 dante /*
569 1.1 dante * If all three connectors are in use, return an error.
570 1.1 dante */
571 1.1 dante if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
572 1.10 dante (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
573 1.1 dante return ASC_IERR_ILLEGAL_CONNECTION;
574 1.1 dante }
575 1.7 dante
576 1.1 dante /*
577 1.1 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
578 1.1 dante * register signals will be set. Check for and return an error if
579 1.1 dante * this condition is found.
580 1.1 dante */
581 1.2 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
582 1.2 dante 0x3F07) {
583 1.1 dante return ASC_IERR_REVERSED_CABLE;
584 1.2 dante }
585 1.1 dante
586 1.1 dante /*
587 1.1 dante * If this is a differential board and a single-ended device
588 1.1 dante * is attached to one of the connectors, return an error.
589 1.1 dante */
590 1.7 dante if ((scsi_cfg1 & ADW_DIFF_MODE) && (scsi_cfg1 & ADW_DIFF_SENSE) == 0) {
591 1.1 dante return ASC_IERR_SINGLE_END_DEVICE;
592 1.7 dante }
593 1.1 dante
594 1.1 dante /*
595 1.1 dante * If automatic termination control is enabled, then set the
596 1.7 dante * termination value based on a table listed in a_condor.h.
597 1.1 dante *
598 1.1 dante * If manual termination was specified with an EEPROM setting
599 1.7 dante * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
600 1.1 dante * is ready to be 'ored' into SCSI_CFG1.
601 1.1 dante */
602 1.1 dante if (sc->cfg.termination == 0) {
603 1.1 dante /*
604 1.10 dante * The software always controls termination by setting
605 1.10 dante * TERM_CTL_SEL.
606 1.10 dante * If TERM_CTL_SEL were set to 0, the hardware would set
607 1.10 dante * termination.
608 1.1 dante */
609 1.1 dante sc->cfg.termination |= ADW_TERM_CTL_SEL;
610 1.1 dante
611 1.7 dante switch(scsi_cfg1 & ADW_CABLE_DETECT) {
612 1.7 dante /* TERM_CTL_H: on, TERM_CTL_L: on */
613 1.10 dante case 0x3: case 0x7: case 0xB:
614 1.10 dante case 0xD: case 0xE: case 0xF:
615 1.10 dante sc->cfg.termination |=
616 1.10 dante (ADW_TERM_CTL_H | ADW_TERM_CTL_L);
617 1.7 dante break;
618 1.7 dante
619 1.7 dante /* TERM_CTL_H: on, TERM_CTL_L: off */
620 1.7 dante case 0x1: case 0x5: case 0x9: case 0xA: case 0xC:
621 1.7 dante sc->cfg.termination |= ADW_TERM_CTL_H;
622 1.7 dante break;
623 1.7 dante
624 1.7 dante /* TERM_CTL_H: off, TERM_CTL_L: off */
625 1.7 dante case 0x2: case 0x6:
626 1.7 dante break;
627 1.1 dante }
628 1.1 dante }
629 1.7 dante
630 1.1 dante /*
631 1.7 dante * Clear any set TERM_CTL_H and TERM_CTL_L bits.
632 1.1 dante */
633 1.1 dante scsi_cfg1 &= ~ADW_TERM_CTL;
634 1.1 dante
635 1.1 dante /*
636 1.7 dante * Invert the TERM_CTL_H and TERM_CTL_L bits and then
637 1.7 dante * set 'scsi_cfg1'. The TERM_POL bit does not need to be
638 1.1 dante * referenced, because the hardware internally inverts
639 1.7 dante * the Termination High and Low bits if TERM_POL is set.
640 1.1 dante */
641 1.1 dante scsi_cfg1 |= (ADW_TERM_CTL_SEL | (~sc->cfg.termination & ADW_TERM_CTL));
642 1.1 dante
643 1.1 dante /*
644 1.1 dante * Set SCSI_CFG1 Microcode Default Value
645 1.1 dante *
646 1.1 dante * Set filter value and possibly modified termination control
647 1.1 dante * bits in the Microcode SCSI_CFG1 Register Value.
648 1.1 dante *
649 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
650 1.1 dante * after it is started below.
651 1.1 dante */
652 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1,
653 1.7 dante ADW_FLTR_DISABLE | scsi_cfg1);
654 1.7 dante
655 1.7 dante /*
656 1.7 dante * Set MEM_CFG Microcode Default Value
657 1.7 dante *
658 1.7 dante * The microcode will set the MEM_CFG register using this value
659 1.7 dante * after it is started below.
660 1.7 dante *
661 1.7 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
662 1.7 dante * are defined.
663 1.7 dante *
664 1.7 dante * ASC-3550 has 8KB internal memory.
665 1.7 dante */
666 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_MEM_CFG,
667 1.7 dante ADW_BIOS_EN | ADW_RAM_SZ_8KB);
668 1.1 dante
669 1.1 dante /*
670 1.1 dante * Set SEL_MASK Microcode Default Value
671 1.1 dante *
672 1.1 dante * The microcode will set the SEL_MASK register using this value
673 1.1 dante * after it is started below.
674 1.1 dante */
675 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
676 1.7 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
677 1.7 dante
678 1.7 dante
679 1.7 dante /*
680 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
681 1.7 dante */
682 1.7 dante
683 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
684 1.7 dante return ASC_IERR_NO_CARRIER;
685 1.7 dante }
686 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
687 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
688 1.7 dante
689 1.7 dante /*
690 1.7 dante * The first command issued will be placed in the stopper carrier.
691 1.7 dante */
692 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
693 1.1 dante
694 1.1 dante /*
695 1.7 dante * Set RISC ICQ physical address start value.
696 1.7 dante */
697 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_ICQ, sc->icq_sp->carr_ba);
698 1.7 dante
699 1.7 dante /*
700 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
701 1.1 dante */
702 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
703 1.7 dante return ASC_IERR_NO_CARRIER;
704 1.1 dante }
705 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
706 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
707 1.1 dante
708 1.1 dante /*
709 1.7 dante * The first command completed by the RISC will be placed in
710 1.7 dante * the stopper.
711 1.1 dante *
712 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
713 1.7 dante * completed the RISC will set the ASC_RQ_STOPPER bit.
714 1.1 dante */
715 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
716 1.1 dante
717 1.1 dante /*
718 1.7 dante * Set RISC IRQ physical address start value.
719 1.1 dante */
720 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IRQ, sc->irq_sp->carr_ba);
721 1.7 dante sc->carr_pending_cnt = 0;
722 1.1 dante
723 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
724 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
725 1.1 dante
726 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
727 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
728 1.1 dante
729 1.1 dante /* finally, finally, gentlemen, start your engine */
730 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
731 1.2 dante
732 1.7 dante /*
733 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
734 1.7 dante * Resets should be performed. The RISC has to be running
735 1.7 dante * to issue a SCSI Bus Reset.
736 1.7 dante */
737 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
738 1.7 dante {
739 1.7 dante /*
740 1.7 dante * If the BIOS Signature is present in memory, restore the
741 1.7 dante * BIOS Handshake Configuration Table and do not perform
742 1.7 dante * a SCSI Bus Reset.
743 1.7 dante */
744 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] ==
745 1.7 dante 0x55AA) {
746 1.7 dante /*
747 1.7 dante * Restore per TID negotiated values.
748 1.7 dante */
749 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
750 1.7 dante wdtr_able);
751 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
752 1.7 dante sdtr_able);
753 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
754 1.7 dante tagqng_able);
755 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
756 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
757 1.7 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
758 1.7 dante max_cmd[tid]);
759 1.7 dante }
760 1.7 dante } else {
761 1.7 dante if (AdvResetCCB(sc) != ADW_TRUE) {
762 1.7 dante warn_code = ASC_WARN_BUSRESET_ERROR;
763 1.7 dante }
764 1.7 dante }
765 1.7 dante }
766 1.7 dante
767 1.7 dante return warn_code;
768 1.1 dante }
769 1.1 dante
770 1.1 dante /*
771 1.7 dante * Initialize the ASC-38C0800.
772 1.1 dante *
773 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
774 1.1 dante *
775 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
776 1.1 dante * then 0 is returned.
777 1.1 dante */
778 1.1 dante int
779 1.7 dante AdvInitAsc38C0800Driver(sc)
780 1.7 dante ADW_SOFTC *sc;
781 1.1 dante {
782 1.2 dante bus_space_tag_t iot = sc->sc_iot;
783 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
784 1.7 dante u_int16_t warn_code;
785 1.7 dante u_int32_t sum;
786 1.7 dante int begin_addr;
787 1.7 dante int end_addr;
788 1.7 dante u_int16_t code_sum;
789 1.7 dante int word;
790 1.7 dante int i, j;
791 1.7 dante int adv_asc38C0800_expanded_size;
792 1.7 dante u_int16_t scsi_cfg1;
793 1.7 dante u_int8_t byte;
794 1.7 dante u_int8_t tid;
795 1.7 dante u_int16_t bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory
796 1.7 dante 0x40-0x8F. */
797 1.7 dante u_int16_t wdtr_able, sdtr_able, tagqng_able;
798 1.7 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
799 1.1 dante
800 1.1 dante
801 1.1 dante warn_code = 0;
802 1.1 dante
803 1.1 dante /*
804 1.7 dante * Save the RISC memory BIOS region before writing the microcode.
805 1.7 dante * The BIOS may already be loaded and using its RISC LRAM region
806 1.7 dante * so its region must be saved and restored.
807 1.1 dante *
808 1.7 dante * Note: This code makes the assumption, which is currently true,
809 1.7 dante * that a chip reset does not clear RISC LRAM.
810 1.7 dante */
811 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
812 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
813 1.7 dante }
814 1.7 dante
815 1.7 dante /*
816 1.7 dante * Save current per TID negotiated values.
817 1.1 dante */
818 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
819 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
820 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
821 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
822 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
823 1.7 dante max_cmd[tid]);
824 1.7 dante }
825 1.2 dante
826 1.7 dante /*
827 1.7 dante * RAM BIST (RAM Built-In Self Test)
828 1.7 dante *
829 1.7 dante * Address : I/O base + offset 0x38h register (byte).
830 1.7 dante * Function: Bit 7-6(RW) : RAM mode
831 1.7 dante * Normal Mode : 0x00
832 1.7 dante * Pre-test Mode : 0x40
833 1.7 dante * RAM Test Mode : 0x80
834 1.7 dante * Bit 5 : unused
835 1.7 dante * Bit 4(RO) : Done bit
836 1.7 dante * Bit 3-0(RO) : Status
837 1.7 dante * Host Error : 0x08
838 1.7 dante * Int_RAM Error : 0x04
839 1.7 dante * RISC Error : 0x02
840 1.7 dante * SCSI Error : 0x01
841 1.7 dante * No Error : 0x00
842 1.7 dante *
843 1.7 dante * Note: RAM BIST code should be put right here, before loading the
844 1.7 dante * microcode and after saving the RISC memory BIOS region.
845 1.7 dante */
846 1.1 dante
847 1.7 dante /*
848 1.7 dante * LRAM Pre-test
849 1.7 dante *
850 1.7 dante * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
851 1.7 dante * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
852 1.7 dante * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
853 1.7 dante * to NORMAL_MODE, return an error too.
854 1.7 dante */
855 1.7 dante for (i = 0; i < 2; i++) {
856 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, PRE_TEST_MODE);
857 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
858 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
859 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) !=
860 1.7 dante PRE_TEST_VALUE) {
861 1.7 dante return ASC_IERR_BIST_PRE_TEST;
862 1.1 dante }
863 1.1 dante
864 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
865 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
866 1.7 dante if (ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST)
867 1.7 dante != NORMAL_VALUE) {
868 1.7 dante return ASC_IERR_BIST_PRE_TEST;
869 1.7 dante }
870 1.1 dante }
871 1.7 dante
872 1.1 dante /*
873 1.7 dante * LRAM Test - It takes about 1.5 ms to run through the test.
874 1.1 dante *
875 1.7 dante * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
876 1.7 dante * If Done bit not set or Status not 0, save register byte, set the
877 1.7 dante * err_code, and return an error.
878 1.1 dante */
879 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, RAM_TEST_MODE);
880 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before checking status. */
881 1.7 dante
882 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
883 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
884 1.7 dante /* Get here if Done bit not set or Status not 0. */
885 1.7 dante return ASC_IERR_BIST_RAM_TEST;
886 1.7 dante }
887 1.7 dante
888 1.7 dante /* We need to reset back to normal mode after LRAM test passes. */
889 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
890 1.1 dante
891 1.1 dante /*
892 1.7 dante * Load the Microcode
893 1.7 dante *
894 1.7 dante * Write the microcode image to RISC memory starting at address 0.
895 1.7 dante *
896 1.1 dante */
897 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
898 1.7 dante
899 1.7 dante /* Assume the following compressed format of the microcode buffer:
900 1.7 dante *
901 1.7 dante * 254 word (508 byte) table indexed by byte code followed
902 1.7 dante * by the following byte codes:
903 1.7 dante *
904 1.7 dante * 1-Byte Code:
905 1.7 dante * 00: Emit word 0 in table.
906 1.7 dante * 01: Emit word 1 in table.
907 1.7 dante * .
908 1.7 dante * FD: Emit word 253 in table.
909 1.7 dante *
910 1.7 dante * Multi-Byte Code:
911 1.7 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
912 1.7 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
913 1.7 dante */
914 1.7 dante word = 0;
915 1.7 dante for (i = 253 * 2; i < adv_asc38C0800_mcode_size; i++) {
916 1.7 dante if (adv_asc38C0800_mcode[i] == 0xff) {
917 1.7 dante for (j = 0; j < adv_asc38C0800_mcode[i + 1]; j++) {
918 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
919 1.7 dante (((u_int16_t)
920 1.7 dante adv_asc38C0800_mcode[i + 3] << 8) |
921 1.7 dante adv_asc38C0800_mcode[i + 2]));
922 1.7 dante word++;
923 1.7 dante }
924 1.7 dante i += 3;
925 1.7 dante } else if (adv_asc38C0800_mcode[i] == 0xfe) {
926 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
927 1.7 dante adv_asc38C0800_mcode[i + 2] << 8) |
928 1.7 dante adv_asc38C0800_mcode[i + 1]));
929 1.7 dante i += 2;
930 1.7 dante word++;
931 1.1 dante } else {
932 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
933 1.7 dante adv_asc38C0800_mcode[(adv_asc38C0800_mcode[i] * 2) + 1] << 8) |
934 1.7 dante adv_asc38C0800_mcode[adv_asc38C0800_mcode[i] * 2]));
935 1.7 dante word++;
936 1.1 dante }
937 1.1 dante }
938 1.7 dante
939 1.7 dante /*
940 1.7 dante * Set 'word' for later use to clear the rest of memory and save
941 1.7 dante * the expanded mcode size.
942 1.7 dante */
943 1.7 dante word *= 2;
944 1.7 dante adv_asc38C0800_expanded_size = word;
945 1.7 dante
946 1.1 dante /*
947 1.7 dante * Clear the rest of ASC-38C0800 Internal RAM (16KB).
948 1.1 dante */
949 1.7 dante for (; word < ADV_38C0800_MEMSIZE; word += 2) {
950 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
951 1.1 dante }
952 1.7 dante
953 1.1 dante /*
954 1.7 dante * Verify the microcode checksum.
955 1.1 dante */
956 1.7 dante sum = 0;
957 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
958 1.7 dante
959 1.7 dante for (word = 0; word < adv_asc38C0800_expanded_size; word += 2) {
960 1.7 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
961 1.7 dante }
962 1.1 dante
963 1.7 dante if (sum != adv_asc38C0800_mcode_chksum) {
964 1.7 dante return ASC_IERR_MCODE_CHKSUM;
965 1.7 dante }
966 1.1 dante
967 1.1 dante /*
968 1.7 dante * Restore the RISC memory BIOS region.
969 1.1 dante */
970 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
971 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i),
972 1.7 dante bios_mem[i]);
973 1.7 dante }
974 1.1 dante
975 1.7 dante /*
976 1.7 dante * Calculate and write the microcode code checksum to the microcode
977 1.7 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
978 1.7 dante */
979 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
980 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
981 1.7 dante code_sum = 0;
982 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
983 1.7 dante for (word = begin_addr; word < end_addr; word += 2) {
984 1.7 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
985 1.1 dante }
986 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
987 1.1 dante
988 1.7 dante /*
989 1.7 dante * Read microcode version and date.
990 1.7 dante */
991 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE,
992 1.7 dante sc->cfg.mcode_date);
993 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM,
994 1.7 dante sc->cfg.mcode_version);
995 1.1 dante
996 1.7 dante /*
997 1.7 dante * Set the chip type to indicate the ASC38C0800.
998 1.7 dante */
999 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
1000 1.1 dante
1001 1.7 dante /*
1002 1.7 dante * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
1003 1.7 dante * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
1004 1.7 dante * cable detection and then we are able to read C_DET[3:0].
1005 1.7 dante *
1006 1.7 dante * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
1007 1.7 dante * Microcode Default Value' section below.
1008 1.7 dante */
1009 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1010 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1,
1011 1.7 dante scsi_cfg1 | ADW_DIS_TERM_DRV);
1012 1.7 dante
1013 1.7 dante /*
1014 1.7 dante * If the PCI Configuration Command Register "Parity Error Response
1015 1.7 dante * Control" Bit was clear (0), then set the microcode variable
1016 1.7 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
1017 1.7 dante * to ignore DMA parity errors.
1018 1.7 dante */
1019 1.7 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
1020 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1021 1.7 dante word |= CONTROL_FLAG_IGNORE_PERR;
1022 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1023 1.7 dante }
1024 1.7 dante
1025 1.7 dante /*
1026 1.11 dante * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and
1027 1.11 dante * START_CTL_TH [3:2] bits for the default FIFO threshold.
1028 1.7 dante *
1029 1.7 dante * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
1030 1.7 dante *
1031 1.7 dante * For DMA Errata #4 set the BC_THRESH_ENB bit.
1032 1.7 dante */
1033 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
1034 1.7 dante BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
1035 1.7 dante
1036 1.7 dante /*
1037 1.7 dante * Microcode operating variables for WDTR, SDTR, and command tag
1038 1.7 dante * queuing will be set in AdvInquiryHandling() based on what a
1039 1.7 dante * device reports it is capable of in Inquiry byte 7.
1040 1.7 dante *
1041 1.7 dante * If SCSI Bus Resets have been disabled, then directly set
1042 1.7 dante * SDTR and WDTR from the EEPROM configuration. This will allow
1043 1.7 dante * the BIOS and warm boot to work without a SCSI bus hang on
1044 1.7 dante * the Inquiry caused by host and target mismatched DTR values.
1045 1.7 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
1046 1.7 dante * be assumed to be in Asynchronous, Narrow mode.
1047 1.7 dante */
1048 1.7 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
1049 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, sc->wdtr_able);
1050 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sc->sdtr_able);
1051 1.7 dante }
1052 1.7 dante
1053 1.7 dante /*
1054 1.7 dante * Set microcode operating variables for DISC and SDTR_SPEED1,
1055 1.7 dante * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
1056 1.7 dante * configuration values.
1057 1.7 dante *
1058 1.7 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
1059 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
1060 1.7 dante * without determining here whether the device supports SDTR.
1061 1.7 dante */
1062 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
1063 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED1, sc->sdtr_speed1);
1064 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED2, sc->sdtr_speed2);
1065 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED3, sc->sdtr_speed3);
1066 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED4, sc->sdtr_speed4);
1067 1.7 dante
1068 1.7 dante /*
1069 1.7 dante * Set SCSI_CFG0 Microcode Default Value.
1070 1.7 dante *
1071 1.7 dante * The microcode will set the SCSI_CFG0 register using this value
1072 1.7 dante * after it is started below.
1073 1.7 dante */
1074 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
1075 1.10 dante ADW_PARITY_EN | ADW_QUEUE_128 | ADW_SEL_TMO_LONG |
1076 1.10 dante ADW_OUR_ID_EN | sc->chip_scsi_id);
1077 1.7 dante
1078 1.7 dante /*
1079 1.7 dante * Determine SCSI_CFG1 Microcode Default Value.
1080 1.7 dante *
1081 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1082 1.7 dante * after it is started below.
1083 1.7 dante */
1084 1.7 dante
1085 1.7 dante /* Read current SCSI_CFG1 Register value. */
1086 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1087 1.7 dante
1088 1.7 dante /*
1089 1.7 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
1090 1.7 dante * register signals will be set. Check for and return an error if
1091 1.7 dante * this condition is found.
1092 1.7 dante */
1093 1.7 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
1094 1.7 dante 0x3F07) {
1095 1.7 dante return ASC_IERR_REVERSED_CABLE;
1096 1.7 dante }
1097 1.7 dante
1098 1.7 dante /*
1099 1.7 dante * All kind of combinations of devices attached to one of four connectors
1100 1.7 dante * are acceptable except HVD device attached. For example, LVD device can
1101 1.7 dante * be attached to SE connector while SE device attached to LVD connector.
1102 1.7 dante * If LVD device attached to SE connector, it only runs up to Ultra speed.
1103 1.7 dante *
1104 1.7 dante * If an HVD device is attached to one of LVD connectors, return an error.
1105 1.7 dante * However, there is no way to detect HVD device attached to SE connectors.
1106 1.7 dante */
1107 1.7 dante if (scsi_cfg1 & ADW_HVD) {
1108 1.7 dante return ASC_IERR_HVD_DEVICE;
1109 1.7 dante }
1110 1.7 dante
1111 1.7 dante /*
1112 1.7 dante * If either SE or LVD automatic termination control is enabled, then
1113 1.7 dante * set the termination value based on a table listed in a_condor.h.
1114 1.7 dante *
1115 1.7 dante * If manual termination was specified with an EEPROM setting then
1116 1.7 dante * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready to
1117 1.7 dante * be 'ored' into SCSI_CFG1.
1118 1.7 dante */
1119 1.7 dante if ((sc->cfg.termination & ADW_TERM_SE) == 0) {
1120 1.7 dante /* SE automatic termination control is enabled. */
1121 1.7 dante switch(scsi_cfg1 & ADW_C_DET_SE) {
1122 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: on */
1123 1.7 dante case 0x1: case 0x2: case 0x3:
1124 1.7 dante sc->cfg.termination |= ADW_TERM_SE;
1125 1.7 dante break;
1126 1.7 dante
1127 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: off */
1128 1.7 dante case 0x0:
1129 1.7 dante sc->cfg.termination |= ADW_TERM_SE_HI;
1130 1.7 dante break;
1131 1.7 dante }
1132 1.7 dante }
1133 1.7 dante
1134 1.7 dante if ((sc->cfg.termination & ADW_TERM_LVD) == 0) {
1135 1.7 dante /* LVD automatic termination control is enabled. */
1136 1.7 dante switch(scsi_cfg1 & ADW_C_DET_LVD) {
1137 1.7 dante /* TERM_LVD_HI: on, TERM_LVD_LO: on */
1138 1.7 dante case 0x4: case 0x8: case 0xC:
1139 1.7 dante sc->cfg.termination |= ADW_TERM_LVD;
1140 1.7 dante break;
1141 1.7 dante
1142 1.7 dante /* TERM_LVD_HI: off, TERM_LVD_LO: off */
1143 1.7 dante case 0x0:
1144 1.7 dante break;
1145 1.7 dante }
1146 1.7 dante }
1147 1.7 dante
1148 1.7 dante /*
1149 1.7 dante * Clear any set TERM_SE and TERM_LVD bits.
1150 1.7 dante */
1151 1.7 dante scsi_cfg1 &= (~ADW_TERM_SE & ~ADW_TERM_LVD);
1152 1.7 dante
1153 1.7 dante /*
1154 1.7 dante * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
1155 1.7 dante */
1156 1.7 dante scsi_cfg1 |= (~sc->cfg.termination & 0xF0);
1157 1.7 dante
1158 1.7 dante /*
1159 1.7 dante * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
1160 1.7 dante * and set possibly modified termination control bits in the Microcode
1161 1.7 dante * SCSI_CFG1 Register Value.
1162 1.7 dante */
1163 1.7 dante scsi_cfg1 &= (~ADW_BIG_ENDIAN & ~ADW_DIS_TERM_DRV &
1164 1.7 dante ~ADW_TERM_POL & ~ADW_HVD_LVD_SE);
1165 1.7 dante
1166 1.7 dante /*
1167 1.7 dante * Set SCSI_CFG1 Microcode Default Value
1168 1.7 dante *
1169 1.7 dante * Set possibly modified termination control and reset DIS_TERM_DRV
1170 1.7 dante * bits in the Microcode SCSI_CFG1 Register Value.
1171 1.7 dante *
1172 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1173 1.7 dante * after it is started below.
1174 1.7 dante */
1175 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
1176 1.7 dante
1177 1.7 dante /*
1178 1.7 dante * Set MEM_CFG Microcode Default Value
1179 1.7 dante *
1180 1.7 dante * The microcode will set the MEM_CFG register using this value
1181 1.7 dante * after it is started below.
1182 1.7 dante *
1183 1.7 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
1184 1.7 dante * are defined.
1185 1.7 dante *
1186 1.7 dante * ASC-38C0800 has 16KB internal memory.
1187 1.7 dante */
1188 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_MEM_CFG,
1189 1.7 dante ADW_BIOS_EN | ADW_RAM_SZ_16KB);
1190 1.7 dante
1191 1.7 dante /*
1192 1.7 dante * Set SEL_MASK Microcode Default Value
1193 1.7 dante *
1194 1.7 dante * The microcode will set the SEL_MASK register using this value
1195 1.7 dante * after it is started below.
1196 1.7 dante */
1197 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
1198 1.7 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
1199 1.7 dante
1200 1.7 dante
1201 1.7 dante /*
1202 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
1203 1.7 dante */
1204 1.7 dante
1205 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
1206 1.7 dante return ASC_IERR_NO_CARRIER;
1207 1.7 dante }
1208 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1209 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
1210 1.7 dante
1211 1.7 dante /*
1212 1.7 dante * The first command issued will be placed in the stopper carrier.
1213 1.7 dante */
1214 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
1215 1.7 dante
1216 1.7 dante /*
1217 1.7 dante * Set RISC ICQ physical address start value.
1218 1.7 dante */
1219 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_ICQ, sc->icq_sp->carr_ba);
1220 1.7 dante
1221 1.7 dante /*
1222 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
1223 1.7 dante */
1224 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
1225 1.7 dante return ASC_IERR_NO_CARRIER;
1226 1.7 dante }
1227 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1228 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
1229 1.7 dante
1230 1.7 dante /*
1231 1.7 dante * The first command completed by the RISC will be placed in
1232 1.7 dante * the stopper.
1233 1.7 dante *
1234 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
1235 1.7 dante * completed the RISC will set the ASC_RQ_STOPPER bit.
1236 1.7 dante */
1237 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
1238 1.7 dante
1239 1.7 dante /*
1240 1.7 dante * Set RISC IRQ physical address start value.
1241 1.7 dante */
1242 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IRQ, sc->irq_sp->carr_ba);
1243 1.7 dante sc->carr_pending_cnt = 0;
1244 1.7 dante
1245 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
1246 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
1247 1.12 dante
1248 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
1249 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
1250 1.7 dante
1251 1.7 dante /* finally, finally, gentlemen, start your engine */
1252 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
1253 1.7 dante
1254 1.7 dante /*
1255 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
1256 1.7 dante * Resets should be performed. The RISC has to be running
1257 1.7 dante * to issue a SCSI Bus Reset.
1258 1.7 dante */
1259 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
1260 1.7 dante /*
1261 1.7 dante * If the BIOS Signature is present in memory, restore the
1262 1.7 dante * BIOS Handshake Configuration Table and do not perform
1263 1.7 dante * a SCSI Bus Reset.
1264 1.7 dante */
1265 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] ==
1266 1.7 dante 0x55AA) {
1267 1.7 dante /*
1268 1.7 dante * Restore per TID negotiated values.
1269 1.7 dante */
1270 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
1271 1.10 dante wdtr_able);
1272 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
1273 1.10 dante sdtr_able);
1274 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
1275 1.10 dante tagqng_able);
1276 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1277 1.10 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1278 1.10 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
1279 1.10 dante max_cmd[tid]);
1280 1.10 dante }
1281 1.10 dante } else {
1282 1.10 dante if (AdvResetCCB(sc) != ADW_TRUE) {
1283 1.10 dante warn_code = ASC_WARN_BUSRESET_ERROR;
1284 1.10 dante }
1285 1.10 dante }
1286 1.10 dante }
1287 1.10 dante
1288 1.10 dante return warn_code;
1289 1.10 dante }
1290 1.10 dante
1291 1.10 dante
1292 1.10 dante /*
1293 1.10 dante * Initialize the ASC-38C1600.
1294 1.10 dante *
1295 1.10 dante * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
1296 1.10 dante *
1297 1.10 dante * For a non-fatal error return a warning code. If there are no warnings
1298 1.10 dante * then 0 is returned.
1299 1.10 dante */
1300 1.10 dante int
1301 1.10 dante AdvInitAsc38C1600Driver(sc)
1302 1.10 dante ADW_SOFTC *sc;
1303 1.10 dante {
1304 1.10 dante bus_space_tag_t iot = sc->sc_iot;
1305 1.10 dante bus_space_handle_t ioh = sc->sc_ioh;
1306 1.10 dante u_int16_t warn_code;
1307 1.10 dante u_int32_t sum;
1308 1.10 dante int begin_addr;
1309 1.10 dante int end_addr;
1310 1.10 dante u_int16_t code_sum;
1311 1.10 dante int word;
1312 1.10 dante int i, j;
1313 1.10 dante int adv_asc38C1600_expanded_size;
1314 1.10 dante u_int16_t scsi_cfg1;
1315 1.10 dante u_int8_t byte;
1316 1.10 dante u_int8_t tid;
1317 1.10 dante u_int16_t bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory
1318 1.10 dante 0x40-0x8F. */
1319 1.10 dante u_int16_t wdtr_able, sdtr_able, ppr_able, tagqng_able;
1320 1.10 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
1321 1.10 dante
1322 1.10 dante
1323 1.10 dante warn_code = 0;
1324 1.10 dante
1325 1.10 dante
1326 1.10 dante /*
1327 1.10 dante * Save the RISC memory BIOS region before writing the microcode.
1328 1.10 dante * The BIOS may already be loaded and using its RISC LRAM region
1329 1.10 dante * so its region must be saved and restored.
1330 1.10 dante *
1331 1.10 dante * Note: This code makes the assumption, which is currently true,
1332 1.10 dante * that a chip reset does not clear RISC LRAM.
1333 1.10 dante */
1334 1.10 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
1335 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
1336 1.10 dante }
1337 1.10 dante
1338 1.10 dante /*
1339 1.10 dante * Save current per TID negotiated values.
1340 1.10 dante */
1341 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
1342 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
1343 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE, ppr_able);
1344 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
1345 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1346 1.10 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
1347 1.10 dante max_cmd[tid]);
1348 1.10 dante }
1349 1.10 dante
1350 1.10 dante /*
1351 1.10 dante * RAM BIST (RAM Built-In Self Test)
1352 1.10 dante *
1353 1.10 dante * Address : I/O base + offset 0x38h register (byte).
1354 1.10 dante * Function: Bit 7-6(RW) : RAM mode
1355 1.10 dante * Normal Mode : 0x00
1356 1.10 dante * Pre-test Mode : 0x40
1357 1.10 dante * RAM Test Mode : 0x80
1358 1.10 dante * Bit 5 : unused
1359 1.10 dante * Bit 4(RO) : Done bit
1360 1.10 dante * Bit 3-0(RO) : Status
1361 1.10 dante * Host Error : 0x08
1362 1.10 dante * Int_RAM Error : 0x04
1363 1.10 dante * RISC Error : 0x02
1364 1.10 dante * SCSI Error : 0x01
1365 1.10 dante * No Error : 0x00
1366 1.10 dante *
1367 1.10 dante * Note: RAM BIST code should be put right here, before loading the
1368 1.10 dante * microcode and after saving the RISC memory BIOS region.
1369 1.10 dante */
1370 1.10 dante
1371 1.10 dante /*
1372 1.10 dante * LRAM Pre-test
1373 1.10 dante *
1374 1.10 dante * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
1375 1.10 dante * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
1376 1.10 dante * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
1377 1.10 dante * to NORMAL_MODE, return an error too.
1378 1.10 dante */
1379 1.10 dante for (i = 0; i < 2; i++) {
1380 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, PRE_TEST_MODE);
1381 1.10 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
1382 1.10 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
1383 1.10 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) !=
1384 1.10 dante PRE_TEST_VALUE) {
1385 1.10 dante return ASC_IERR_BIST_PRE_TEST;
1386 1.10 dante }
1387 1.10 dante
1388 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
1389 1.10 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
1390 1.10 dante if (ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST)
1391 1.10 dante != NORMAL_VALUE) {
1392 1.10 dante return ASC_IERR_BIST_PRE_TEST;
1393 1.10 dante }
1394 1.10 dante }
1395 1.10 dante
1396 1.10 dante /*
1397 1.10 dante * LRAM Test - It takes about 1.5 ms to run through the test.
1398 1.10 dante *
1399 1.10 dante * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
1400 1.10 dante * If Done bit not set or Status not 0, save register byte, set the
1401 1.10 dante * err_code, and return an error.
1402 1.10 dante */
1403 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, RAM_TEST_MODE);
1404 1.10 dante AdvSleepMilliSecond(10); /* Wait for 10ms before checking status. */
1405 1.10 dante
1406 1.10 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
1407 1.10 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
1408 1.10 dante /* Get here if Done bit not set or Status not 0. */
1409 1.10 dante return ASC_IERR_BIST_RAM_TEST;
1410 1.10 dante }
1411 1.10 dante
1412 1.10 dante /* We need to reset back to normal mode after LRAM test passes. */
1413 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
1414 1.10 dante
1415 1.10 dante
1416 1.10 dante /*
1417 1.10 dante * Load the Microcode
1418 1.10 dante *
1419 1.10 dante * Write the microcode image to RISC memory starting at address 0.
1420 1.10 dante *
1421 1.10 dante */
1422 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
1423 1.10 dante
1424 1.10 dante /* Assume the following compressed format of the microcode buffer:
1425 1.10 dante *
1426 1.10 dante * 254 word (508 byte) table indexed by byte code followed
1427 1.10 dante * by the following byte codes:
1428 1.10 dante *
1429 1.10 dante * 1-Byte Code:
1430 1.10 dante * 00: Emit word 0 in table.
1431 1.10 dante * 01: Emit word 1 in table.
1432 1.10 dante * .
1433 1.10 dante * FD: Emit word 253 in table.
1434 1.10 dante *
1435 1.10 dante * Multi-Byte Code:
1436 1.10 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
1437 1.10 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
1438 1.10 dante */
1439 1.10 dante word = 0;
1440 1.10 dante for (i = 253 * 2; i < adv_asc38C1600_mcode_size; i++) {
1441 1.10 dante if (adv_asc38C1600_mcode[i] == 0xff) {
1442 1.10 dante for (j = 0; j < adv_asc38C1600_mcode[i + 1]; j++) {
1443 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
1444 1.10 dante (((u_int16_t)
1445 1.10 dante adv_asc38C1600_mcode[i + 3] << 8) |
1446 1.10 dante adv_asc38C1600_mcode[i + 2]));
1447 1.10 dante word++;
1448 1.10 dante }
1449 1.10 dante i += 3;
1450 1.10 dante } else if (adv_asc38C1600_mcode[i] == 0xfe) {
1451 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
1452 1.10 dante adv_asc38C1600_mcode[i + 2] << 8) |
1453 1.10 dante adv_asc38C1600_mcode[i + 1]));
1454 1.10 dante i += 2;
1455 1.10 dante word++;
1456 1.10 dante } else {
1457 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
1458 1.10 dante adv_asc38C1600_mcode[(adv_asc38C1600_mcode[i] * 2) + 1] << 8) |
1459 1.10 dante adv_asc38C1600_mcode[adv_asc38C1600_mcode[i] * 2]));
1460 1.10 dante word++;
1461 1.10 dante }
1462 1.10 dante }
1463 1.10 dante
1464 1.10 dante /*
1465 1.10 dante * Set 'word' for later use to clear the rest of memory and save
1466 1.10 dante * the expanded mcode size.
1467 1.10 dante */
1468 1.10 dante word *= 2;
1469 1.10 dante adv_asc38C1600_expanded_size = word;
1470 1.10 dante
1471 1.10 dante /*
1472 1.10 dante * Clear the rest of ASC-38C0800 Internal RAM (16KB).
1473 1.10 dante */
1474 1.10 dante for (; word < ADV_38C1600_MEMSIZE; word += 2) {
1475 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
1476 1.10 dante }
1477 1.10 dante
1478 1.10 dante /*
1479 1.10 dante * Verify the microcode checksum.
1480 1.10 dante */
1481 1.10 dante sum = 0;
1482 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
1483 1.10 dante
1484 1.10 dante for (word = 0; word < adv_asc38C1600_expanded_size; word += 2) {
1485 1.10 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
1486 1.10 dante }
1487 1.10 dante
1488 1.10 dante if (sum != adv_asc38C1600_mcode_chksum) {
1489 1.10 dante return ASC_IERR_MCODE_CHKSUM;
1490 1.10 dante }
1491 1.10 dante
1492 1.10 dante /*
1493 1.10 dante * Restore the RISC memory BIOS region.
1494 1.10 dante */
1495 1.10 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
1496 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i),
1497 1.10 dante bios_mem[i]);
1498 1.10 dante }
1499 1.10 dante
1500 1.10 dante /*
1501 1.10 dante * Calculate and write the microcode code checksum to the microcode
1502 1.10 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
1503 1.10 dante */
1504 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
1505 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
1506 1.10 dante code_sum = 0;
1507 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
1508 1.10 dante for (word = begin_addr; word < end_addr; word += 2) {
1509 1.10 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
1510 1.10 dante }
1511 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
1512 1.10 dante
1513 1.10 dante /*
1514 1.10 dante * Read microcode version and date.
1515 1.10 dante */
1516 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE,
1517 1.10 dante sc->cfg.mcode_date);
1518 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM,
1519 1.10 dante sc->cfg.mcode_version);
1520 1.10 dante
1521 1.10 dante /*
1522 1.10 dante * Set the chip type to indicate the ASC38C1600.
1523 1.10 dante */
1524 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
1525 1.10 dante
1526 1.10 dante /*
1527 1.10 dante * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
1528 1.10 dante * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
1529 1.10 dante * cable detection and then we are able to read C_DET[3:0].
1530 1.10 dante *
1531 1.10 dante * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
1532 1.10 dante * Microcode Default Value' section below.
1533 1.10 dante */
1534 1.10 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1535 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1,
1536 1.10 dante scsi_cfg1 | ADW_DIS_TERM_DRV);
1537 1.10 dante
1538 1.10 dante /*
1539 1.10 dante * If the PCI Configuration Command Register "Parity Error Response
1540 1.10 dante * Control" Bit was clear (0), then set the microcode variable
1541 1.10 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
1542 1.10 dante * to ignore DMA parity errors.
1543 1.10 dante */
1544 1.10 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
1545 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1546 1.10 dante word |= CONTROL_FLAG_IGNORE_PERR;
1547 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1548 1.10 dante }
1549 1.10 dante
1550 1.10 dante /*
1551 1.10 dante * If the BIOS control flag AIPP (Asynchronous Information
1552 1.10 dante * Phase Protection) disable bit is not set, then set the firmware
1553 1.10 dante * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
1554 1.10 dante * AIPP checking and encoding.
1555 1.10 dante */
1556 1.10 dante if ((sc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
1557 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1558 1.10 dante word |= CONTROL_FLAG_ENABLE_AIPP;
1559 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
1560 1.10 dante }
1561 1.10 dante
1562 1.10 dante /*
1563 1.10 dante * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
1564 1.10 dante * and START_CTL_TH [3:2].
1565 1.10 dante */
1566 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
1567 1.10 dante FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
1568 1.10 dante
1569 1.10 dante /*
1570 1.10 dante * Microcode operating variables for WDTR, SDTR, and command tag
1571 1.10 dante * queuing will be set in AdvInquiryHandling() based on what a
1572 1.10 dante * device reports it is capable of in Inquiry byte 7.
1573 1.10 dante *
1574 1.10 dante * If SCSI Bus Resets have been disabled, then directly set
1575 1.10 dante * SDTR and WDTR from the EEPROM configuration. This will allow
1576 1.10 dante * the BIOS and warm boot to work without a SCSI bus hang on
1577 1.10 dante * the Inquiry caused by host and target mismatched DTR values.
1578 1.10 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
1579 1.10 dante * be assumed to be in Asynchronous, Narrow mode.
1580 1.10 dante */
1581 1.10 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
1582 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, sc->wdtr_able);
1583 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sc->sdtr_able);
1584 1.10 dante }
1585 1.10 dante
1586 1.10 dante /*
1587 1.10 dante * Set microcode operating variables for DISC and SDTR_SPEED1,
1588 1.10 dante * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
1589 1.10 dante * configuration values.
1590 1.10 dante *
1591 1.10 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
1592 1.10 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
1593 1.10 dante * without determining here whether the device supports SDTR.
1594 1.10 dante */
1595 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
1596 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED1, sc->sdtr_speed1);
1597 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED2, sc->sdtr_speed2);
1598 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED3, sc->sdtr_speed3);
1599 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED4, sc->sdtr_speed4);
1600 1.10 dante
1601 1.10 dante /*
1602 1.10 dante * Set SCSI_CFG0 Microcode Default Value.
1603 1.10 dante *
1604 1.10 dante * The microcode will set the SCSI_CFG0 register using this value
1605 1.10 dante * after it is started below.
1606 1.10 dante */
1607 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
1608 1.10 dante ADW_PARITY_EN | ADW_QUEUE_128 | ADW_SEL_TMO_LONG |
1609 1.10 dante ADW_OUR_ID_EN | sc->chip_scsi_id);
1610 1.10 dante
1611 1.10 dante /*
1612 1.10 dante * Calculate SCSI_CFG1 Microcode Default Value.
1613 1.10 dante *
1614 1.10 dante * The microcode will set the SCSI_CFG1 register using this value
1615 1.10 dante * after it is started below.
1616 1.10 dante *
1617 1.10 dante * Each ASC-38C1600 function has only two cable detect bits.
1618 1.10 dante * The bus mode override bits are in IOPB_SOFT_OVER_WR.
1619 1.10 dante */
1620 1.10 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1621 1.10 dante
1622 1.10 dante /*
1623 1.10 dante * If the cable is reversed all of the SCSI_CTRL register signals
1624 1.10 dante * will be set. Check for and return an error if this condition is
1625 1.10 dante * found.
1626 1.10 dante */
1627 1.10 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
1628 1.10 dante 0x3F07) {
1629 1.10 dante return ASC_IERR_REVERSED_CABLE;
1630 1.10 dante }
1631 1.10 dante
1632 1.10 dante /*
1633 1.10 dante * Each ASC-38C1600 function has two connectors. Only an HVD device
1634 1.10 dante * can not be connected to either connector. An LVD device or SE device
1635 1.10 dante * may be connected to either connecor. If an SE device is connected,
1636 1.10 dante * then at most Ultra speed (20 Mhz) can be used on both connectors.
1637 1.10 dante *
1638 1.10 dante * If an HVD device is attached, return an error.
1639 1.10 dante */
1640 1.10 dante if (scsi_cfg1 & ADW_HVD) {
1641 1.10 dante return ASC_IERR_HVD_DEVICE;
1642 1.10 dante }
1643 1.10 dante
1644 1.10 dante /*
1645 1.10 dante * Each function in the ASC-38C1600 uses only the SE cable detect and
1646 1.10 dante * termination because there are two connectors for each function. Each
1647 1.10 dante * function may use either LVD or SE mode. Corresponding the SE automatic
1648 1.10 dante * termination control EEPROM bits are used for each function. Each
1649 1.10 dante * function has its own EEPROM. If SE automatic control is enabled for
1650 1.10 dante * the function, then set the termination value based on a table listed
1651 1.10 dante * in a_condor.h.
1652 1.10 dante *
1653 1.10 dante * If manual termination is specified in the EEPROM for the function,
1654 1.10 dante * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
1655 1.10 dante * ready to be 'ored' into SCSI_CFG1.
1656 1.10 dante */
1657 1.10 dante if ((sc->cfg.termination & ADW_TERM_SE) == 0) {
1658 1.10 dante /* SE automatic termination control is enabled. */
1659 1.10 dante switch(scsi_cfg1 & ADW_C_DET_SE) {
1660 1.10 dante /* TERM_SE_HI: on, TERM_SE_LO: on */
1661 1.10 dante case 0x1: case 0x2: case 0x3:
1662 1.10 dante sc->cfg.termination |= ADW_TERM_SE;
1663 1.10 dante break;
1664 1.10 dante
1665 1.10 dante case 0x0:
1666 1.10 dante /* !!!!TODO!!!! */
1667 1.10 dante // if (ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) == 0) {
1668 1.10 dante /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
1669 1.10 dante // }
1670 1.10 dante // else
1671 1.10 dante // {
1672 1.10 dante /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
1673 1.10 dante sc->cfg.termination |= ADW_TERM_SE_HI;
1674 1.10 dante // }
1675 1.10 dante break;
1676 1.10 dante }
1677 1.10 dante }
1678 1.10 dante
1679 1.10 dante /*
1680 1.10 dante * Clear any set TERM_SE bits.
1681 1.10 dante */
1682 1.10 dante scsi_cfg1 &= ~ADW_TERM_SE;
1683 1.10 dante
1684 1.10 dante /*
1685 1.10 dante * Invert the TERM_SE bits and then set 'scsi_cfg1'.
1686 1.10 dante */
1687 1.10 dante scsi_cfg1 |= (~sc->cfg.termination & ADW_TERM_SE);
1688 1.10 dante
1689 1.10 dante /*
1690 1.10 dante * Clear Big Endian and Terminator Polarity bits and set possibly
1691 1.10 dante * modified termination control bits in the Microcode SCSI_CFG1
1692 1.10 dante * Register Value.
1693 1.10 dante */
1694 1.10 dante scsi_cfg1 &= (~ADW_BIG_ENDIAN & ~ADW_DIS_TERM_DRV & ~ADW_TERM_POL);
1695 1.10 dante
1696 1.10 dante /*
1697 1.10 dante * Set SCSI_CFG1 Microcode Default Value
1698 1.10 dante *
1699 1.10 dante * Set possibly modified termination control bits in the Microcode
1700 1.10 dante * SCSI_CFG1 Register Value.
1701 1.10 dante *
1702 1.10 dante * The microcode will set the SCSI_CFG1 register using this value
1703 1.10 dante * after it is started below.
1704 1.10 dante */
1705 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
1706 1.10 dante
1707 1.10 dante /*
1708 1.10 dante * Set MEM_CFG Microcode Default Value
1709 1.10 dante *
1710 1.10 dante * The microcode will set the MEM_CFG register using this value
1711 1.10 dante * after it is started below.
1712 1.10 dante *
1713 1.10 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
1714 1.10 dante * are defined.
1715 1.10 dante *
1716 1.10 dante * ASC-38C1600 has 32KB internal memory.
1717 1.10 dante */
1718 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_MEM_CFG,
1719 1.10 dante ADW_BIOS_EN | ADW_RAM_SZ_32KB);
1720 1.10 dante
1721 1.10 dante /*
1722 1.10 dante * Set SEL_MASK Microcode Default Value
1723 1.10 dante *
1724 1.10 dante * The microcode will set the SEL_MASK register using this value
1725 1.10 dante * after it is started below.
1726 1.10 dante */
1727 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
1728 1.10 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
1729 1.10 dante
1730 1.10 dante /*
1731 1.10 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
1732 1.10 dante */
1733 1.10 dante
1734 1.10 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
1735 1.10 dante return ASC_IERR_NO_CARRIER;
1736 1.10 dante }
1737 1.10 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1738 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
1739 1.10 dante
1740 1.10 dante /*
1741 1.10 dante * The first command issued will be placed in the stopper carrier.
1742 1.10 dante */
1743 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
1744 1.10 dante
1745 1.10 dante /*
1746 1.10 dante * Set RISC ICQ physical address start value. Initialize the
1747 1.10 dante * COMMA register to the same value otherwise the RISC will
1748 1.10 dante * prematurely detect a command is available.
1749 1.10 dante */
1750 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_ICQ, sc->icq_sp->carr_ba);
1751 1.12 dante ADW_WRITE_DWORD_REGISTER(iot, ioh, IOPDW_COMMA, sc->icq_sp->carr_ba);
1752 1.10 dante
1753 1.10 dante /*
1754 1.10 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
1755 1.10 dante */
1756 1.10 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
1757 1.10 dante return ASC_IERR_NO_CARRIER;
1758 1.10 dante }
1759 1.10 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1760 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
1761 1.10 dante
1762 1.10 dante /*
1763 1.10 dante * The first command completed by the RISC will be placed in
1764 1.10 dante * the stopper.
1765 1.10 dante *
1766 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
1767 1.10 dante * completed the RISC will set the ASC_RQ_STOPPER bit.
1768 1.10 dante */
1769 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
1770 1.10 dante
1771 1.10 dante /*
1772 1.10 dante * Set RISC IRQ physical address start value.
1773 1.10 dante */
1774 1.12 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IRQ, sc->irq_sp->carr_ba);
1775 1.10 dante sc->carr_pending_cnt = 0;
1776 1.10 dante
1777 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
1778 1.10 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
1779 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
1780 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
1781 1.10 dante
1782 1.10 dante /* finally, finally, gentlemen, start your engine */
1783 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
1784 1.10 dante
1785 1.10 dante /*
1786 1.10 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
1787 1.10 dante * Resets should be performed. The RISC has to be running
1788 1.10 dante * to issue a SCSI Bus Reset.
1789 1.10 dante */
1790 1.10 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
1791 1.10 dante /*
1792 1.10 dante * If the BIOS Signature is present in memory, restore the
1793 1.10 dante * per TID microcode operating variables.
1794 1.10 dante */
1795 1.10 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] ==
1796 1.10 dante 0x55AA) {
1797 1.10 dante /*
1798 1.10 dante * Restore per TID negotiated values.
1799 1.10 dante */
1800 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
1801 1.10 dante wdtr_able);
1802 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
1803 1.10 dante sdtr_able);
1804 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE,
1805 1.10 dante ppr_able);
1806 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
1807 1.10 dante tagqng_able);
1808 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1809 1.10 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1810 1.10 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
1811 1.10 dante max_cmd[tid]);
1812 1.10 dante }
1813 1.10 dante } else {
1814 1.10 dante if (AdvResetCCB(sc) != ADW_TRUE) {
1815 1.10 dante warn_code = ASC_WARN_BUSRESET_ERROR;
1816 1.10 dante }
1817 1.10 dante }
1818 1.10 dante }
1819 1.10 dante
1820 1.10 dante return warn_code;
1821 1.10 dante }
1822 1.10 dante
1823 1.10 dante
1824 1.10 dante /*
1825 1.10 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
1826 1.10 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
1827 1.10 dante * all of this is done.
1828 1.10 dante *
1829 1.10 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
1830 1.10 dante *
1831 1.10 dante * For a non-fatal error return a warning code. If there are no warnings
1832 1.10 dante * then 0 is returned.
1833 1.10 dante *
1834 1.10 dante * Note: Chip is stopped on entry.
1835 1.10 dante */
1836 1.10 dante int
1837 1.10 dante AdvInitFrom3550EEP(sc)
1838 1.10 dante ADW_SOFTC *sc;
1839 1.10 dante {
1840 1.10 dante bus_space_tag_t iot = sc->sc_iot;
1841 1.10 dante bus_space_handle_t ioh = sc->sc_ioh;
1842 1.10 dante u_int16_t warn_code;
1843 1.10 dante ADW_EEP_3550_CONFIG eep_config;
1844 1.10 dante int i;
1845 1.10 dante
1846 1.10 dante
1847 1.10 dante warn_code = 0;
1848 1.10 dante
1849 1.10 dante /*
1850 1.10 dante * Read the board's EEPROM configuration.
1851 1.10 dante *
1852 1.10 dante * Set default values if a bad checksum is found.
1853 1.10 dante *
1854 1.10 dante * XXX - Don't handle big-endian access to EEPROM yet.
1855 1.10 dante */
1856 1.10 dante if (AdvGet3550EEPConfig(iot, ioh, &eep_config) != eep_config.check_sum){
1857 1.10 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
1858 1.10 dante
1859 1.10 dante /*
1860 1.10 dante * Set EEPROM default values.
1861 1.10 dante */
1862 1.10 dante for (i = 0; i < sizeof(ADW_EEP_3550_CONFIG); i++) {
1863 1.10 dante *((u_int8_t *) &eep_config + i) =
1864 1.10 dante *((u_int8_t *) &Default_3550_EEPROM_Config + i);
1865 1.10 dante }
1866 1.10 dante
1867 1.10 dante /*
1868 1.10 dante * Assume the 6 byte board serial number that was read
1869 1.10 dante * from EEPROM is correct even if the EEPROM checksum
1870 1.10 dante * failed.
1871 1.10 dante */
1872 1.10 dante eep_config.serial_number_word3 =
1873 1.10 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
1874 1.10 dante
1875 1.10 dante eep_config.serial_number_word2 =
1876 1.10 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
1877 1.10 dante
1878 1.10 dante eep_config.serial_number_word1 =
1879 1.10 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
1880 1.10 dante
1881 1.10 dante AdvSet3550EEPConfig(iot, ioh, &eep_config);
1882 1.10 dante }
1883 1.10 dante /*
1884 1.10 dante * Set sc and sc->cfg variables from the EEPROM configuration
1885 1.10 dante * that was read.
1886 1.10 dante *
1887 1.10 dante * This is the mapping of EEPROM fields to Adv Library fields.
1888 1.10 dante */
1889 1.10 dante sc->wdtr_able = eep_config.wdtr_able;
1890 1.10 dante sc->sdtr_able = eep_config.sdtr_able;
1891 1.10 dante sc->ultra_able = eep_config.ultra_able;
1892 1.10 dante sc->tagqng_able = eep_config.tagqng_able;
1893 1.10 dante sc->cfg.disc_enable = eep_config.disc_enable;
1894 1.10 dante sc->max_host_qng = eep_config.max_host_qng;
1895 1.10 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1896 1.10 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
1897 1.10 dante sc->start_motor = eep_config.start_motor;
1898 1.10 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
1899 1.10 dante sc->bios_ctrl = eep_config.bios_ctrl;
1900 1.10 dante sc->no_scam = eep_config.scam_tolerant;
1901 1.10 dante sc->cfg.serial1 = eep_config.serial_number_word1;
1902 1.10 dante sc->cfg.serial2 = eep_config.serial_number_word2;
1903 1.10 dante sc->cfg.serial3 = eep_config.serial_number_word3;
1904 1.10 dante
1905 1.10 dante /*
1906 1.10 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
1907 1.10 dante * maximum queuing (max. 63, min. 4).
1908 1.10 dante */
1909 1.10 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
1910 1.10 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1911 1.10 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
1912 1.10 dante {
1913 1.10 dante /* If the value is zero, assume it is uninitialized. */
1914 1.10 dante if (eep_config.max_host_qng == 0) {
1915 1.10 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1916 1.10 dante } else {
1917 1.10 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
1918 1.10 dante }
1919 1.10 dante }
1920 1.10 dante
1921 1.10 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
1922 1.10 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1923 1.10 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
1924 1.10 dante /* If the value is zero, assume it is uninitialized. */
1925 1.10 dante if (eep_config.max_dvc_qng == 0) {
1926 1.10 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1927 1.10 dante } else {
1928 1.10 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
1929 1.10 dante }
1930 1.10 dante }
1931 1.10 dante
1932 1.10 dante /*
1933 1.10 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
1934 1.10 dante * set 'max_dvc_qng' to 'max_host_qng'.
1935 1.10 dante */
1936 1.10 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
1937 1.10 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
1938 1.10 dante }
1939 1.10 dante
1940 1.10 dante /*
1941 1.10 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
1942 1.10 dante * values based on possibly adjusted EEPROM values.
1943 1.10 dante */
1944 1.10 dante sc->max_host_qng = eep_config.max_host_qng;
1945 1.10 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1946 1.10 dante
1947 1.10 dante
1948 1.10 dante /*
1949 1.10 dante * If the EEPROM 'termination' field is set to automatic (0), then set
1950 1.10 dante * the ADV_DVC_CFG 'termination' field to automatic also.
1951 1.10 dante *
1952 1.10 dante * If the termination is specified with a non-zero 'termination'
1953 1.10 dante * value check that a legal value is set and set the ADV_DVC_CFG
1954 1.10 dante * 'termination' field appropriately.
1955 1.10 dante */
1956 1.10 dante
1957 1.10 dante sc->cfg.termination = 0; /* auto termination */
1958 1.10 dante switch(eep_config.termination) {
1959 1.10 dante case 3:
1960 1.10 dante /* Enable manual control with low on / high on. */
1961 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_L;
1962 1.10 dante case 2:
1963 1.10 dante /* Enable manual control with low off / high on. */
1964 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_H;
1965 1.10 dante case 1:
1966 1.10 dante /* Enable manual control with low off / high off. */
1967 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_SEL;
1968 1.10 dante case 0:
1969 1.10 dante break;
1970 1.10 dante default:
1971 1.10 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
1972 1.7 dante }
1973 1.7 dante
1974 1.7 dante return warn_code;
1975 1.7 dante }
1976 1.7 dante
1977 1.7 dante
1978 1.7 dante /*
1979 1.7 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
1980 1.7 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
1981 1.7 dante * all of this is done.
1982 1.7 dante *
1983 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
1984 1.7 dante *
1985 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
1986 1.7 dante * then 0 is returned.
1987 1.7 dante *
1988 1.7 dante * Note: Chip is stopped on entry.
1989 1.7 dante */
1990 1.7 dante int
1991 1.10 dante AdvInitFrom38C0800EEP(sc)
1992 1.7 dante ADW_SOFTC *sc;
1993 1.7 dante {
1994 1.7 dante bus_space_tag_t iot = sc->sc_iot;
1995 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
1996 1.7 dante u_int16_t warn_code;
1997 1.10 dante ADW_EEP_38C0800_CONFIG eep_config;
1998 1.7 dante int i;
1999 1.10 dante u_int8_t tid, termination;
2000 1.10 dante u_int16_t sdtr_speed = 0;
2001 1.7 dante
2002 1.7 dante
2003 1.7 dante warn_code = 0;
2004 1.7 dante
2005 1.7 dante /*
2006 1.7 dante * Read the board's EEPROM configuration.
2007 1.7 dante *
2008 1.7 dante * Set default values if a bad checksum is found.
2009 1.7 dante */
2010 1.10 dante if (AdvGet38C0800EEPConfig(iot, ioh, &eep_config) !=
2011 1.10 dante eep_config.check_sum) {
2012 1.7 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
2013 1.7 dante
2014 1.7 dante /*
2015 1.7 dante * Set EEPROM default values.
2016 1.7 dante */
2017 1.10 dante for (i = 0; i < sizeof(ADW_EEP_38C0800_CONFIG); i++) {
2018 1.7 dante *((u_int8_t *) &eep_config + i) =
2019 1.10 dante *((u_int8_t *)&Default_38C0800_EEPROM_Config+i);
2020 1.7 dante }
2021 1.7 dante
2022 1.7 dante /*
2023 1.7 dante * Assume the 6 byte board serial number that was read
2024 1.7 dante * from EEPROM is correct even if the EEPROM checksum
2025 1.7 dante * failed.
2026 1.7 dante */
2027 1.7 dante eep_config.serial_number_word3 =
2028 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
2029 1.7 dante
2030 1.7 dante eep_config.serial_number_word2 =
2031 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
2032 1.7 dante
2033 1.7 dante eep_config.serial_number_word1 =
2034 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
2035 1.7 dante
2036 1.10 dante AdvSet38C0800EEPConfig(iot, ioh, &eep_config);
2037 1.7 dante }
2038 1.7 dante /*
2039 1.10 dante * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
2040 1.7 dante * EEPROM configuration that was read.
2041 1.7 dante *
2042 1.7 dante * This is the mapping of EEPROM fields to Adv Library fields.
2043 1.7 dante */
2044 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
2045 1.10 dante sc->sdtr_speed1 = eep_config.sdtr_speed1;
2046 1.10 dante sc->sdtr_speed2 = eep_config.sdtr_speed2;
2047 1.10 dante sc->sdtr_speed3 = eep_config.sdtr_speed3;
2048 1.10 dante sc->sdtr_speed4 = eep_config.sdtr_speed4;
2049 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
2050 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
2051 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2052 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2053 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
2054 1.7 dante sc->start_motor = eep_config.start_motor;
2055 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
2056 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
2057 1.7 dante sc->no_scam = eep_config.scam_tolerant;
2058 1.7 dante sc->cfg.serial1 = eep_config.serial_number_word1;
2059 1.7 dante sc->cfg.serial2 = eep_config.serial_number_word2;
2060 1.7 dante sc->cfg.serial3 = eep_config.serial_number_word3;
2061 1.7 dante
2062 1.7 dante /*
2063 1.10 dante * For every Target ID if any of its 'sdtr_speed[1234]' bits
2064 1.10 dante * are set, then set an 'sdtr_able' bit for it.
2065 1.10 dante */
2066 1.10 dante sc->sdtr_able = 0;
2067 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
2068 1.10 dante if (tid == 0) {
2069 1.10 dante sdtr_speed = sc->sdtr_speed1;
2070 1.10 dante } else if (tid == 4) {
2071 1.10 dante sdtr_speed = sc->sdtr_speed2;
2072 1.10 dante } else if (tid == 8) {
2073 1.10 dante sdtr_speed = sc->sdtr_speed3;
2074 1.10 dante } else if (tid == 12) {
2075 1.10 dante sdtr_speed = sc->sdtr_speed4;
2076 1.10 dante }
2077 1.10 dante if (sdtr_speed & ADW_MAX_TID) {
2078 1.10 dante sc->sdtr_able |= (1 << tid);
2079 1.10 dante }
2080 1.10 dante sdtr_speed >>= 4;
2081 1.10 dante }
2082 1.10 dante
2083 1.10 dante /*
2084 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
2085 1.7 dante * maximum queuing (max. 63, min. 4).
2086 1.7 dante */
2087 1.7 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
2088 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
2089 1.10 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
2090 1.7 dante /* If the value is zero, assume it is uninitialized. */
2091 1.7 dante if (eep_config.max_host_qng == 0) {
2092 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
2093 1.7 dante } else {
2094 1.7 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
2095 1.7 dante }
2096 1.7 dante }
2097 1.7 dante
2098 1.7 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
2099 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
2100 1.7 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
2101 1.7 dante /* If the value is zero, assume it is uninitialized. */
2102 1.7 dante if (eep_config.max_dvc_qng == 0) {
2103 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
2104 1.7 dante } else {
2105 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
2106 1.7 dante }
2107 1.7 dante }
2108 1.7 dante
2109 1.7 dante /*
2110 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
2111 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
2112 1.7 dante */
2113 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
2114 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
2115 1.7 dante }
2116 1.7 dante
2117 1.7 dante /*
2118 1.7 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
2119 1.7 dante * values based on possibly adjusted EEPROM values.
2120 1.7 dante */
2121 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2122 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2123 1.7 dante
2124 1.7 dante /*
2125 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
2126 1.7 dante * the ADV_DVC_CFG 'termination' field to automatic also.
2127 1.7 dante *
2128 1.7 dante * If the termination is specified with a non-zero 'termination'
2129 1.7 dante * value check that a legal value is set and set the ADV_DVC_CFG
2130 1.7 dante * 'termination' field appropriately.
2131 1.7 dante */
2132 1.10 dante
2133 1.10 dante switch(eep_config.termination_se) {
2134 1.10 dante case 0:
2135 1.10 dante /* auto termination for SE */
2136 1.10 dante termination = 0;
2137 1.10 dante break;
2138 1.10 dante case 1:
2139 1.7 dante /* Enable manual control with low off / high off. */
2140 1.10 dante termination = 0;
2141 1.10 dante break;
2142 1.10 dante case 2:
2143 1.10 dante /* Enable manual control with low off / high on. */
2144 1.10 dante termination = ADW_TERM_SE_HI;
2145 1.10 dante break;
2146 1.10 dante case 3:
2147 1.10 dante /* Enable manual control with low on / high on. */
2148 1.10 dante termination = ADW_TERM_SE;
2149 1.10 dante break;
2150 1.10 dante default:
2151 1.10 dante /*
2152 1.10 dante * The EEPROM 'termination_se' field contains a bad value.
2153 1.10 dante * Use automatic termination instead.
2154 1.10 dante */
2155 1.10 dante termination = 0;
2156 1.10 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
2157 1.10 dante }
2158 1.7 dante
2159 1.10 dante switch(eep_config.termination_lvd) {
2160 1.10 dante case 0:
2161 1.10 dante /* auto termination for LVD */
2162 1.10 dante sc->cfg.termination = termination;
2163 1.10 dante break;
2164 1.10 dante case 1:
2165 1.10 dante /* Enable manual control with low off / high off. */
2166 1.10 dante sc->cfg.termination = termination;
2167 1.10 dante break;
2168 1.10 dante case 2:
2169 1.7 dante /* Enable manual control with low off / high on. */
2170 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD_HI;
2171 1.10 dante break;
2172 1.10 dante case 3:
2173 1.7 dante /* Enable manual control with low on / high on. */
2174 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD;
2175 1.10 dante break;
2176 1.10 dante default:
2177 1.10 dante /*
2178 1.10 dante * The EEPROM 'termination_lvd' field contains a bad value.
2179 1.10 dante * Use automatic termination instead.
2180 1.10 dante */
2181 1.10 dante sc->cfg.termination = termination;
2182 1.10 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
2183 1.7 dante }
2184 1.7 dante
2185 1.7 dante return warn_code;
2186 1.7 dante }
2187 1.7 dante
2188 1.7 dante
2189 1.7 dante /*
2190 1.10 dante * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
2191 1.10 dante * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
2192 1.7 dante * all of this is done.
2193 1.7 dante *
2194 1.10 dante * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
2195 1.7 dante *
2196 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
2197 1.7 dante * then 0 is returned.
2198 1.7 dante *
2199 1.7 dante * Note: Chip is stopped on entry.
2200 1.7 dante */
2201 1.7 dante int
2202 1.10 dante AdvInitFrom38C1600EEP(sc)
2203 1.7 dante ADW_SOFTC *sc;
2204 1.7 dante {
2205 1.7 dante bus_space_tag_t iot = sc->sc_iot;
2206 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
2207 1.7 dante u_int16_t warn_code;
2208 1.10 dante ADW_EEP_38C1600_CONFIG eep_config;
2209 1.7 dante int i;
2210 1.7 dante u_int8_t tid, termination;
2211 1.7 dante u_int16_t sdtr_speed = 0;
2212 1.7 dante
2213 1.7 dante
2214 1.7 dante warn_code = 0;
2215 1.7 dante
2216 1.7 dante /*
2217 1.7 dante * Read the board's EEPROM configuration.
2218 1.7 dante *
2219 1.7 dante * Set default values if a bad checksum is found.
2220 1.7 dante */
2221 1.10 dante if (AdvGet38C1600EEPConfig(iot, ioh, &eep_config) !=
2222 1.7 dante eep_config.check_sum) {
2223 1.7 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
2224 1.7 dante
2225 1.7 dante /*
2226 1.7 dante * Set EEPROM default values.
2227 1.7 dante */
2228 1.10 dante for (i = 0; i < sizeof(ADW_EEP_38C1600_CONFIG); i++) {
2229 1.10 dante /* !!!!TODO!!!! */
2230 1.10 dante // if (i == 1 && ASC_PCI_ID2FUNC(sc->cfg.pci_slot_info) != 0) {
2231 1.10 dante if (i == 1 ) {
2232 1.10 dante /*
2233 1.10 dante * Set Function 1 EEPROM Word 0 MSB
2234 1.10 dante *
2235 1.10 dante * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
2236 1.10 dante * EEPROM bits.
2237 1.10 dante *
2238 1.10 dante * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
2239 1.10 dante * old Mac system booting problem. The Expansion ROM must
2240 1.10 dante * be disabled in Function 1 for these systems.
2241 1.10 dante *
2242 1.10 dante */
2243 1.10 dante *((u_int8_t *) &eep_config + i) =
2244 1.10 dante ((*((u_int8_t *) &Default_38C1600_EEPROM_Config + i)) &
2245 1.10 dante (~(((ADW_EEPROM_BIOS_ENABLE | ADW_EEPROM_INTAB) >> 8) &
2246 1.10 dante 0xFF)));
2247 1.10 dante
2248 1.10 dante /*
2249 1.10 dante * Set the INTAB (bit 11) if the GPIO 0 input
2250 1.10 dante * indicates the Function 1 interrupt line is
2251 1.10 dante * wired to INTA.
2252 1.10 dante *
2253 1.10 dante * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
2254 1.10 dante * 1 - Function 1 interrupt line wired to INT A.
2255 1.10 dante * 0 - Function 1 interrupt line wired to INT B.
2256 1.10 dante *
2257 1.10 dante * Note: Adapter boards always have Function 0
2258 1.10 dante * wired to INTA.
2259 1.10 dante * Put all 5 GPIO bits in input mode and then
2260 1.10 dante * read their input values.
2261 1.10 dante */
2262 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
2263 1.10 dante IOPB_GPIO_CNTL, 0);
2264 1.10 dante if (ADW_READ_BYTE_REGISTER(iot, ioh,
2265 1.10 dante IOPB_GPIO_DATA) & 0x01) {
2266 1.10 dante /* Function 1 interrupt wired to INTA;
2267 1.10 dante Set EEPROM bit. */
2268 1.10 dante *((u_int8_t *) &eep_config + i) |=
2269 1.10 dante ((ADW_EEPROM_INTAB >> 8) &0xFF);
2270 1.10 dante }
2271 1.10 dante } else {
2272 1.10 dante *((u_int8_t *)&eep_config + i) =
2273 1.10 dante *((u_int8_t *)&Default_38C1600_EEPROM_Config+i);
2274 1.10 dante }
2275 1.7 dante }
2276 1.7 dante
2277 1.7 dante /*
2278 1.7 dante * Assume the 6 byte board serial number that was read
2279 1.7 dante * from EEPROM is correct even if the EEPROM checksum
2280 1.7 dante * failed.
2281 1.7 dante */
2282 1.7 dante eep_config.serial_number_word3 =
2283 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
2284 1.7 dante
2285 1.7 dante eep_config.serial_number_word2 =
2286 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
2287 1.7 dante
2288 1.7 dante eep_config.serial_number_word1 =
2289 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
2290 1.7 dante
2291 1.10 dante AdvSet38C1600EEPConfig(iot, ioh, &eep_config);
2292 1.7 dante }
2293 1.10 dante
2294 1.7 dante /*
2295 1.10 dante * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
2296 1.7 dante * EEPROM configuration that was read.
2297 1.7 dante *
2298 1.7 dante * This is the mapping of EEPROM fields to Adv Library fields.
2299 1.7 dante */
2300 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
2301 1.7 dante sc->sdtr_speed1 = eep_config.sdtr_speed1;
2302 1.7 dante sc->sdtr_speed2 = eep_config.sdtr_speed2;
2303 1.7 dante sc->sdtr_speed3 = eep_config.sdtr_speed3;
2304 1.7 dante sc->sdtr_speed4 = eep_config.sdtr_speed4;
2305 1.10 dante sc->ppr_able = 0;
2306 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
2307 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
2308 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2309 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2310 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
2311 1.7 dante sc->start_motor = eep_config.start_motor;
2312 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
2313 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
2314 1.7 dante sc->no_scam = eep_config.scam_tolerant;
2315 1.7 dante
2316 1.7 dante /*
2317 1.7 dante * For every Target ID if any of its 'sdtr_speed[1234]' bits
2318 1.7 dante * are set, then set an 'sdtr_able' bit for it.
2319 1.7 dante */
2320 1.7 dante sc->sdtr_able = 0;
2321 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
2322 1.7 dante if (tid == 0) {
2323 1.7 dante sdtr_speed = sc->sdtr_speed1;
2324 1.7 dante } else if (tid == 4) {
2325 1.7 dante sdtr_speed = sc->sdtr_speed2;
2326 1.7 dante } else if (tid == 8) {
2327 1.7 dante sdtr_speed = sc->sdtr_speed3;
2328 1.7 dante } else if (tid == 12) {
2329 1.7 dante sdtr_speed = sc->sdtr_speed4;
2330 1.7 dante }
2331 1.7 dante if (sdtr_speed & ADW_MAX_TID) {
2332 1.7 dante sc->sdtr_able |= (1 << tid);
2333 1.7 dante }
2334 1.7 dante sdtr_speed >>= 4;
2335 1.7 dante }
2336 1.7 dante
2337 1.7 dante /*
2338 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
2339 1.7 dante * maximum queuing (max. 63, min. 4).
2340 1.7 dante */
2341 1.7 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
2342 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
2343 1.7 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
2344 1.7 dante /* If the value is zero, assume it is uninitialized. */
2345 1.7 dante if (eep_config.max_host_qng == 0) {
2346 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
2347 1.7 dante } else {
2348 1.7 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
2349 1.7 dante }
2350 1.7 dante }
2351 1.7 dante
2352 1.7 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
2353 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
2354 1.7 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
2355 1.7 dante /* If the value is zero, assume it is uninitialized. */
2356 1.7 dante if (eep_config.max_dvc_qng == 0) {
2357 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
2358 1.7 dante } else {
2359 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
2360 1.7 dante }
2361 1.7 dante }
2362 1.7 dante
2363 1.7 dante /*
2364 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
2365 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
2366 1.7 dante */
2367 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
2368 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
2369 1.7 dante }
2370 1.7 dante
2371 1.7 dante /*
2372 1.10 dante * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
2373 1.7 dante * values based on possibly adjusted EEPROM values.
2374 1.7 dante */
2375 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2376 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2377 1.7 dante
2378 1.7 dante /*
2379 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
2380 1.10 dante * the ASC_DVC_CFG 'termination' field to automatic also.
2381 1.7 dante *
2382 1.7 dante * If the termination is specified with a non-zero 'termination'
2383 1.10 dante * value check that a legal value is set and set the ASC_DVC_CFG
2384 1.7 dante * 'termination' field appropriately.
2385 1.7 dante */
2386 1.7 dante
2387 1.10 dante switch(eep_config.termination_se) {
2388 1.10 dante case 0: /* auto termination for SE */
2389 1.10 dante termination = 0;
2390 1.10 dante break;
2391 1.10 dante case 1: /* Enable manual control with low off / high off. */
2392 1.10 dante termination = 0;
2393 1.10 dante break;
2394 1.10 dante case 2: /* Enable manual control with low off / high on. */
2395 1.10 dante termination = ADW_TERM_SE_HI;
2396 1.10 dante break;
2397 1.10 dante case 3: /* Enable manual control with low on / high on. */
2398 1.10 dante termination = ADW_TERM_SE;
2399 1.10 dante break;
2400 1.10 dante default:
2401 1.10 dante /*
2402 1.10 dante * The EEPROM 'termination_se' field contains a bad value.
2403 1.10 dante * Use automatic termination instead.
2404 1.10 dante */
2405 1.10 dante termination = 0;
2406 1.10 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
2407 1.7 dante }
2408 1.7 dante
2409 1.10 dante switch(eep_config.termination_lvd) {
2410 1.10 dante case 0: /* auto termination for LVD */
2411 1.10 dante sc->cfg.termination = termination;
2412 1.10 dante break;
2413 1.10 dante case 1: /* Enable manual control with low off / high off. */
2414 1.10 dante sc->cfg.termination = termination;
2415 1.10 dante break;
2416 1.10 dante case 2: /* Enable manual control with low off / high on. */
2417 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD_HI;
2418 1.10 dante break;
2419 1.10 dante case 3: /* Enable manual control with low on / high on. */
2420 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD;
2421 1.10 dante break;
2422 1.10 dante default:
2423 1.10 dante /*
2424 1.10 dante * The EEPROM 'termination_lvd' field contains a bad value.
2425 1.10 dante * Use automatic termination instead.
2426 1.10 dante */
2427 1.7 dante sc->cfg.termination = termination;
2428 1.10 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
2429 1.7 dante }
2430 1.7 dante
2431 1.7 dante return warn_code;
2432 1.7 dante }
2433 1.7 dante
2434 1.7 dante
2435 1.7 dante /*
2436 1.7 dante * Read EEPROM configuration into the specified buffer.
2437 1.7 dante *
2438 1.7 dante * Return a checksum based on the EEPROM configuration read.
2439 1.7 dante */
2440 1.7 dante static u_int16_t
2441 1.7 dante AdvGet3550EEPConfig(iot, ioh, cfg_buf)
2442 1.7 dante bus_space_tag_t iot;
2443 1.7 dante bus_space_handle_t ioh;
2444 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
2445 1.7 dante {
2446 1.7 dante u_int16_t wval, chksum;
2447 1.7 dante u_int16_t *wbuf;
2448 1.7 dante int eep_addr;
2449 1.7 dante
2450 1.7 dante
2451 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2452 1.7 dante chksum = 0;
2453 1.7 dante
2454 1.7 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2455 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2456 1.10 dante eep_addr++, wbuf++) {
2457 1.7 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
2458 1.7 dante chksum += wval;
2459 1.7 dante *wbuf = wval;
2460 1.7 dante }
2461 1.7 dante
2462 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2463 1.7 dante wbuf++;
2464 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2465 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2466 1.7 dante eep_addr++, wbuf++) {
2467 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2468 1.7 dante }
2469 1.7 dante
2470 1.7 dante return chksum;
2471 1.7 dante }
2472 1.7 dante
2473 1.7 dante
2474 1.7 dante /*
2475 1.7 dante * Read EEPROM configuration into the specified buffer.
2476 1.7 dante *
2477 1.7 dante * Return a checksum based on the EEPROM configuration read.
2478 1.7 dante */
2479 1.7 dante static u_int16_t
2480 1.7 dante AdvGet38C0800EEPConfig(iot, ioh, cfg_buf)
2481 1.7 dante bus_space_tag_t iot;
2482 1.7 dante bus_space_handle_t ioh;
2483 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
2484 1.7 dante {
2485 1.7 dante u_int16_t wval, chksum;
2486 1.7 dante u_int16_t *wbuf;
2487 1.7 dante int eep_addr;
2488 1.7 dante
2489 1.7 dante
2490 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2491 1.7 dante chksum = 0;
2492 1.1 dante
2493 1.1 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2494 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2495 1.10 dante eep_addr++, wbuf++) {
2496 1.10 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
2497 1.10 dante chksum += wval;
2498 1.10 dante *wbuf = wval;
2499 1.10 dante }
2500 1.10 dante
2501 1.10 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2502 1.10 dante wbuf++;
2503 1.10 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2504 1.10 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2505 1.7 dante eep_addr++, wbuf++) {
2506 1.10 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2507 1.10 dante }
2508 1.10 dante
2509 1.10 dante return chksum;
2510 1.10 dante }
2511 1.10 dante
2512 1.10 dante
2513 1.10 dante /*
2514 1.10 dante * Read EEPROM configuration into the specified buffer.
2515 1.10 dante *
2516 1.10 dante * Return a checksum based on the EEPROM configuration read.
2517 1.10 dante */
2518 1.10 dante static u_int16_t
2519 1.10 dante AdvGet38C1600EEPConfig(iot, ioh, cfg_buf)
2520 1.10 dante bus_space_tag_t iot;
2521 1.10 dante bus_space_handle_t ioh;
2522 1.10 dante ADW_EEP_38C1600_CONFIG *cfg_buf;
2523 1.10 dante {
2524 1.10 dante u_int16_t wval, chksum;
2525 1.10 dante u_int16_t *wbuf;
2526 1.10 dante int eep_addr;
2527 1.10 dante
2528 1.10 dante
2529 1.10 dante wbuf = (u_int16_t *) cfg_buf;
2530 1.10 dante chksum = 0;
2531 1.10 dante
2532 1.10 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2533 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2534 1.10 dante eep_addr++, wbuf++) {
2535 1.1 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
2536 1.1 dante chksum += wval;
2537 1.1 dante *wbuf = wval;
2538 1.1 dante }
2539 1.7 dante
2540 1.1 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2541 1.1 dante wbuf++;
2542 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2543 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2544 1.7 dante eep_addr++, wbuf++) {
2545 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
2546 1.7 dante }
2547 1.7 dante
2548 1.7 dante return chksum;
2549 1.7 dante }
2550 1.7 dante
2551 1.7 dante
2552 1.7 dante /*
2553 1.7 dante * Read the EEPROM from specified location
2554 1.7 dante */
2555 1.7 dante static u_int16_t
2556 1.7 dante AdvReadEEPWord(iot, ioh, eep_word_addr)
2557 1.7 dante bus_space_tag_t iot;
2558 1.7 dante bus_space_handle_t ioh;
2559 1.7 dante int eep_word_addr;
2560 1.7 dante {
2561 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2562 1.7 dante ASC_EEP_CMD_READ | eep_word_addr);
2563 1.7 dante AdvWaitEEPCmd(iot, ioh);
2564 1.7 dante
2565 1.7 dante return ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_DATA);
2566 1.7 dante }
2567 1.7 dante
2568 1.7 dante
2569 1.7 dante /*
2570 1.7 dante * Wait for EEPROM command to complete
2571 1.7 dante */
2572 1.7 dante static void
2573 1.7 dante AdvWaitEEPCmd(iot, ioh)
2574 1.7 dante bus_space_tag_t iot;
2575 1.7 dante bus_space_handle_t ioh;
2576 1.7 dante {
2577 1.7 dante int eep_delay_ms;
2578 1.7 dante
2579 1.7 dante
2580 1.7 dante for (eep_delay_ms = 0; eep_delay_ms < ASC_EEP_DELAY_MS; eep_delay_ms++){
2581 1.7 dante if (ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD) &
2582 1.7 dante ASC_EEP_CMD_DONE) {
2583 1.7 dante break;
2584 1.7 dante }
2585 1.7 dante AdvSleepMilliSecond(1);
2586 1.7 dante }
2587 1.7 dante
2588 1.7 dante ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD);
2589 1.7 dante }
2590 1.7 dante
2591 1.7 dante
2592 1.7 dante /*
2593 1.7 dante * Write the EEPROM from 'cfg_buf'.
2594 1.7 dante */
2595 1.7 dante static void
2596 1.7 dante AdvSet3550EEPConfig(iot, ioh, cfg_buf)
2597 1.7 dante bus_space_tag_t iot;
2598 1.7 dante bus_space_handle_t ioh;
2599 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
2600 1.7 dante {
2601 1.7 dante u_int16_t *wbuf;
2602 1.7 dante u_int16_t addr, chksum;
2603 1.7 dante
2604 1.7 dante
2605 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2606 1.7 dante chksum = 0;
2607 1.7 dante
2608 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2609 1.7 dante AdvWaitEEPCmd(iot, ioh);
2610 1.7 dante
2611 1.7 dante /*
2612 1.7 dante * Write EEPROM from word 0 to word 20
2613 1.7 dante */
2614 1.7 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2615 1.7 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2616 1.7 dante chksum += *wbuf;
2617 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2618 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2619 1.7 dante ASC_EEP_CMD_WRITE | addr);
2620 1.7 dante AdvWaitEEPCmd(iot, ioh);
2621 1.7 dante AdvSleepMilliSecond(ASC_EEP_DELAY_MS);
2622 1.7 dante }
2623 1.7 dante
2624 1.7 dante /*
2625 1.7 dante * Write EEPROM checksum at word 21
2626 1.7 dante */
2627 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2628 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2629 1.7 dante ASC_EEP_CMD_WRITE | addr);
2630 1.7 dante AdvWaitEEPCmd(iot, ioh);
2631 1.7 dante wbuf++; /* skip over check_sum */
2632 1.7 dante
2633 1.7 dante /*
2634 1.7 dante * Write EEPROM OEM name at words 22 to 29
2635 1.7 dante */
2636 1.7 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2637 1.7 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2638 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2639 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2640 1.7 dante ASC_EEP_CMD_WRITE | addr);
2641 1.7 dante AdvWaitEEPCmd(iot, ioh);
2642 1.1 dante }
2643 1.1 dante
2644 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2645 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
2646 1.4 thorpej AdvWaitEEPCmd(iot, ioh);
2647 1.1 dante
2648 1.1 dante return;
2649 1.1 dante }
2650 1.1 dante
2651 1.7 dante
2652 1.1 dante /*
2653 1.1 dante * Write the EEPROM from 'cfg_buf'.
2654 1.1 dante */
2655 1.1 dante static void
2656 1.7 dante AdvSet38C0800EEPConfig(iot, ioh, cfg_buf)
2657 1.7 dante bus_space_tag_t iot;
2658 1.7 dante bus_space_handle_t ioh;
2659 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
2660 1.1 dante {
2661 1.7 dante u_int16_t *wbuf;
2662 1.7 dante u_int16_t addr, chksum;
2663 1.7 dante
2664 1.1 dante
2665 1.1 dante wbuf = (u_int16_t *) cfg_buf;
2666 1.1 dante chksum = 0;
2667 1.1 dante
2668 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2669 1.1 dante AdvWaitEEPCmd(iot, ioh);
2670 1.1 dante
2671 1.1 dante /*
2672 1.7 dante * Write EEPROM from word 0 to word 20
2673 1.1 dante */
2674 1.1 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2675 1.2 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2676 1.1 dante chksum += *wbuf;
2677 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2678 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2679 1.7 dante ASC_EEP_CMD_WRITE | addr);
2680 1.1 dante AdvWaitEEPCmd(iot, ioh);
2681 1.7 dante AdvSleepMilliSecond(ASC_EEP_DELAY_MS);
2682 1.1 dante }
2683 1.1 dante
2684 1.1 dante /*
2685 1.7 dante * Write EEPROM checksum at word 21
2686 1.1 dante */
2687 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2688 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2689 1.7 dante ASC_EEP_CMD_WRITE | addr);
2690 1.1 dante AdvWaitEEPCmd(iot, ioh);
2691 1.7 dante wbuf++; /* skip over check_sum */
2692 1.1 dante
2693 1.1 dante /*
2694 1.7 dante * Write EEPROM OEM name at words 22 to 29
2695 1.1 dante */
2696 1.1 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2697 1.2 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2698 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2699 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2700 1.7 dante ASC_EEP_CMD_WRITE | addr);
2701 1.1 dante AdvWaitEEPCmd(iot, ioh);
2702 1.1 dante }
2703 1.7 dante
2704 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2705 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
2706 1.1 dante AdvWaitEEPCmd(iot, ioh);
2707 1.7 dante
2708 1.1 dante return;
2709 1.1 dante }
2710 1.1 dante
2711 1.7 dante
2712 1.1 dante /*
2713 1.10 dante * Write the EEPROM from 'cfg_buf'.
2714 1.10 dante */
2715 1.10 dante static void
2716 1.10 dante AdvSet38C1600EEPConfig(iot, ioh, cfg_buf)
2717 1.10 dante bus_space_tag_t iot;
2718 1.10 dante bus_space_handle_t ioh;
2719 1.10 dante ADW_EEP_38C1600_CONFIG *cfg_buf;
2720 1.10 dante {
2721 1.10 dante u_int16_t *wbuf;
2722 1.10 dante u_int16_t addr, chksum;
2723 1.10 dante
2724 1.10 dante
2725 1.10 dante wbuf = (u_int16_t *) cfg_buf;
2726 1.10 dante chksum = 0;
2727 1.10 dante
2728 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2729 1.10 dante AdvWaitEEPCmd(iot, ioh);
2730 1.10 dante
2731 1.10 dante /*
2732 1.10 dante * Write EEPROM from word 0 to word 20
2733 1.10 dante */
2734 1.10 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2735 1.10 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2736 1.10 dante chksum += *wbuf;
2737 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2738 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2739 1.10 dante ASC_EEP_CMD_WRITE | addr);
2740 1.10 dante AdvWaitEEPCmd(iot, ioh);
2741 1.10 dante AdvSleepMilliSecond(ASC_EEP_DELAY_MS);
2742 1.10 dante }
2743 1.10 dante
2744 1.10 dante /*
2745 1.10 dante * Write EEPROM checksum at word 21
2746 1.10 dante */
2747 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2748 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2749 1.10 dante ASC_EEP_CMD_WRITE | addr);
2750 1.10 dante AdvWaitEEPCmd(iot, ioh);
2751 1.10 dante wbuf++; /* skip over check_sum */
2752 1.10 dante
2753 1.10 dante /*
2754 1.10 dante * Write EEPROM OEM name at words 22 to 29
2755 1.10 dante */
2756 1.10 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2757 1.10 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2758 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2759 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2760 1.10 dante ASC_EEP_CMD_WRITE | addr);
2761 1.10 dante AdvWaitEEPCmd(iot, ioh);
2762 1.10 dante }
2763 1.10 dante
2764 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2765 1.10 dante ASC_EEP_CMD_WRITE_DISABLE);
2766 1.10 dante AdvWaitEEPCmd(iot, ioh);
2767 1.10 dante
2768 1.10 dante return;
2769 1.10 dante }
2770 1.10 dante
2771 1.10 dante
2772 1.10 dante /*
2773 1.7 dante * AdvExeScsiQueue() - Send a request to the RISC microcode program.
2774 1.7 dante *
2775 1.7 dante * Allocate a carrier structure, point the carrier to the ADW_SCSI_REQ_Q,
2776 1.7 dante * add the carrier to the ICQ (Initiator Command Queue), and tickle the
2777 1.7 dante * RISC to notify it a new command is ready to be executed.
2778 1.1 dante *
2779 1.7 dante * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
2780 1.7 dante * set to SCSI_MAX_RETRY.
2781 1.1 dante *
2782 1.7 dante * Return:
2783 1.7 dante * ADW_SUCCESS(1) - The request was successfully queued.
2784 1.7 dante * ADW_BUSY(0) - Resource unavailable; Retry again after pending
2785 1.7 dante * request completes.
2786 1.7 dante * ADW_ERROR(-1) - Invalid ADW_SCSI_REQ_Q request structure
2787 1.7 dante * host IC error.
2788 1.1 dante */
2789 1.7 dante int
2790 1.7 dante AdvExeScsiQueue(sc, scsiq)
2791 1.7 dante ADW_SOFTC *sc;
2792 1.7 dante ADW_SCSI_REQ_Q *scsiq;
2793 1.1 dante {
2794 1.7 dante bus_space_tag_t iot = sc->sc_iot;
2795 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
2796 1.7 dante ADW_CCB *ccb;
2797 1.7 dante long req_size;
2798 1.7 dante u_int32_t req_paddr;
2799 1.10 dante ADW_CARRIER *new_carrp;
2800 1.7 dante
2801 1.7 dante /*
2802 1.7 dante * The ADW_SCSI_REQ_Q 'target_id' field should never exceed ADW_MAX_TID.
2803 1.7 dante */
2804 1.7 dante if (scsiq->target_id > ADW_MAX_TID) {
2805 1.7 dante scsiq->host_status = QHSTA_M_INVALID_DEVICE;
2806 1.7 dante scsiq->done_status = QD_WITH_ERROR;
2807 1.7 dante return ADW_ERROR;
2808 1.7 dante }
2809 1.7 dante
2810 1.10 dante /*
2811 1.10 dante * Begin of CRITICAL SECTION: Must be protected within splbio/splx pair
2812 1.10 dante */
2813 1.10 dante
2814 1.7 dante ccb = adw_ccb_phys_kv(sc, scsiq->ccb_ptr);
2815 1.7 dante
2816 1.7 dante /*
2817 1.7 dante * Allocate a carrier ensuring at least one carrier always
2818 1.7 dante * remains on the freelist and initialize fields.
2819 1.7 dante */
2820 1.7 dante if ((new_carrp = sc->carr_freelist) == NULL) {
2821 1.7 dante return ADW_BUSY;
2822 1.7 dante }
2823 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
2824 1.12 dante ASC_GET_CARRP(new_carrp->next_ba));
2825 1.7 dante sc->carr_pending_cnt++;
2826 1.7 dante
2827 1.7 dante /*
2828 1.12 dante * Set the carrier to be a stopper by setting 'next_ba'
2829 1.7 dante * to the stopper value. The current stopper will be changed
2830 1.7 dante * below to point to the new stopper.
2831 1.7 dante */
2832 1.12 dante new_carrp->next_ba = ASC_CQ_STOPPER;
2833 1.7 dante
2834 1.7 dante req_size = sizeof(ADW_SCSI_REQ_Q);
2835 1.7 dante req_paddr = sc->sc_dmamap_control->dm_segs[0].ds_addr +
2836 1.7 dante ADW_CCB_OFF(ccb) + offsetof(struct adw_ccb, scsiq);
2837 1.7 dante
2838 1.7 dante /* Save physical address of ADW_SCSI_REQ_Q and Carrier. */
2839 1.7 dante scsiq->scsiq_rptr = req_paddr;
2840 1.7 dante
2841 1.7 dante /*
2842 1.12 dante * Every ADV_CARR_T.carr_ba is byte swapped to little-endian
2843 1.7 dante * order during initialization.
2844 1.7 dante */
2845 1.12 dante scsiq->carr_ba = sc->icq_sp->carr_ba;
2846 1.12 dante scsiq->carr_va = sc->icq_sp->carr_ba;
2847 1.1 dante
2848 1.7 dante /*
2849 1.7 dante * Use the current stopper to send the ADW_SCSI_REQ_Q command to
2850 1.7 dante * the microcode. The newly allocated stopper will become the new
2851 1.7 dante * stopper.
2852 1.7 dante */
2853 1.12 dante sc->icq_sp->areq_ba = req_paddr;
2854 1.1 dante
2855 1.1 dante /*
2856 1.12 dante * Set the 'next_ba' pointer for the old stopper to be the
2857 1.7 dante * physical address of the new stopper. The RISC can only
2858 1.7 dante * follow physical addresses.
2859 1.1 dante */
2860 1.12 dante sc->icq_sp->next_ba = new_carrp->carr_ba;
2861 1.1 dante
2862 1.12 dante #if ADW_DEBUG
2863 1.12 dante printf("icq 0x%x, 0x%x, 0x%x, 0x%x\n",
2864 1.12 dante sc->icq_sp->carr_id,
2865 1.12 dante sc->icq_sp->carr_ba,
2866 1.12 dante sc->icq_sp->areq_ba,
2867 1.12 dante sc->icq_sp->next_ba);
2868 1.12 dante #endif
2869 1.1 dante /*
2870 1.7 dante * Set the host adapter stopper pointer to point to the new carrier.
2871 1.1 dante */
2872 1.7 dante sc->icq_sp = new_carrp;
2873 1.11 dante
2874 1.10 dante if (sc->chip_type == ADV_CHIP_ASC3550 ||
2875 1.11 dante sc->chip_type == ADV_CHIP_ASC38C0800) {
2876 1.7 dante /*
2877 1.10 dante * Tickle the RISC to tell it to read its Command Queue Head
2878 1.10 dante * pointer.
2879 1.10 dante */
2880 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_A);
2881 1.11 dante if (sc->chip_type == ADV_CHIP_ASC3550) {
2882 1.10 dante /*
2883 1.10 dante * Clear the tickle value. In the ASC-3550 the RISC flag
2884 1.10 dante * command 'clr_tickle_a' does not work unless the host
2885 1.10 dante * value is cleared.
2886 1.10 dante */
2887 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE,
2888 1.10 dante ADV_TICKLE_NOP);
2889 1.10 dante }
2890 1.10 dante } else if (sc->chip_type == ADV_CHIP_ASC38C1600) {
2891 1.10 dante /*
2892 1.10 dante * Notify the RISC a carrier is ready by writing the physical
2893 1.10 dante * address of the new carrier stopper to the COMMA register.
2894 1.7 dante */
2895 1.10 dante ADW_WRITE_DWORD_REGISTER(iot, ioh, IOPDW_COMMA,
2896 1.12 dante new_carrp->carr_ba);
2897 1.7 dante }
2898 1.7 dante
2899 1.10 dante /*
2900 1.10 dante * End of CRITICAL SECTION: Must be protected within splbio/splx pair
2901 1.10 dante */
2902 1.10 dante
2903 1.7 dante return ADW_SUCCESS;
2904 1.1 dante }
2905 1.1 dante
2906 1.7 dante
2907 1.7 dante void
2908 1.7 dante AdvResetChip(iot, ioh)
2909 1.7 dante bus_space_tag_t iot;
2910 1.7 dante bus_space_handle_t ioh;
2911 1.1 dante {
2912 1.7 dante
2913 1.7 dante /*
2914 1.7 dante * Reset Chip.
2915 1.7 dante */
2916 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2917 1.7 dante ADW_CTRL_REG_CMD_RESET);
2918 1.7 dante AdvSleepMilliSecond(100);
2919 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2920 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
2921 1.1 dante }
2922 1.1 dante
2923 1.7 dante
2924 1.1 dante /*
2925 1.1 dante * Reset SCSI Bus and purge all outstanding requests.
2926 1.1 dante *
2927 1.1 dante * Return Value:
2928 1.7 dante * ADW_TRUE(1) - All requests are purged and SCSI Bus is reset.
2929 1.7 dante * ADW_FALSE(0) - Microcode command failed.
2930 1.7 dante * ADW_ERROR(-1) - Microcode command timed-out. Microcode or IC
2931 1.7 dante * may be hung which requires driver recovery.
2932 1.1 dante */
2933 1.1 dante int
2934 1.1 dante AdvResetCCB(sc)
2935 1.7 dante ADW_SOFTC *sc;
2936 1.1 dante {
2937 1.7 dante int status;
2938 1.7 dante
2939 1.7 dante /*
2940 1.7 dante * Send the SCSI Bus Reset idle start idle command which asserts
2941 1.7 dante * the SCSI Bus Reset signal.
2942 1.7 dante */
2943 1.7 dante status = AdvSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_START, 0L);
2944 1.11 dante if (status != ADW_TRUE) {
2945 1.7 dante return status;
2946 1.7 dante }
2947 1.7 dante
2948 1.7 dante /*
2949 1.7 dante * Delay for the specified SCSI Bus Reset hold time.
2950 1.7 dante *
2951 1.7 dante * The hold time delay is done on the host because the RISC has no
2952 1.7 dante * microsecond accurate timer.
2953 1.7 dante */
2954 1.7 dante AdvDelayMicroSecond((u_int16_t) ASC_SCSI_RESET_HOLD_TIME_US);
2955 1.1 dante
2956 1.7 dante /*
2957 1.7 dante * Send the SCSI Bus Reset end idle command which de-asserts
2958 1.7 dante * the SCSI Bus Reset signal and purges any pending requests.
2959 1.7 dante */
2960 1.7 dante status = AdvSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_END, 0L);
2961 1.11 dante if (status != ADW_TRUE) {
2962 1.7 dante return status;
2963 1.7 dante }
2964 1.1 dante
2965 1.7 dante AdvSleepMilliSecond((u_int32_t) sc->scsi_reset_wait * 1000);
2966 1.1 dante
2967 1.1 dante return status;
2968 1.1 dante }
2969 1.1 dante
2970 1.7 dante
2971 1.1 dante /*
2972 1.7 dante * Reset chip and SCSI Bus.
2973 1.7 dante *
2974 1.7 dante * Return Value:
2975 1.7 dante * ADW_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
2976 1.7 dante * ADW_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
2977 1.1 dante */
2978 1.7 dante int
2979 1.1 dante AdvResetSCSIBus(sc)
2980 1.7 dante ADW_SOFTC *sc;
2981 1.1 dante {
2982 1.2 dante bus_space_tag_t iot = sc->sc_iot;
2983 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
2984 1.7 dante int status;
2985 1.10 dante u_int16_t wdtr_able, sdtr_able, ppr_able, tagqng_able;
2986 1.7 dante u_int8_t tid, max_cmd[ADW_MAX_TID + 1];
2987 1.7 dante u_int16_t bios_sig;
2988 1.7 dante
2989 1.7 dante
2990 1.7 dante /*
2991 1.7 dante * Save current per TID negotiated values.
2992 1.7 dante */
2993 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
2994 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
2995 1.10 dante if (sc->chip_type == ADV_CHIP_ASC38C1600) {
2996 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE, ppr_able);
2997 1.10 dante }
2998 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
2999 1.11 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
3000 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
3001 1.7 dante max_cmd[tid]);
3002 1.7 dante }
3003 1.7 dante
3004 1.7 dante /*
3005 1.7 dante * Force the AdvInitAsc3550/38C0800Driver() function to
3006 1.7 dante * perform a SCSI Bus Reset by clearing the BIOS signature word.
3007 1.7 dante * The initialization functions assumes a SCSI Bus Reset is not
3008 1.7 dante * needed if the BIOS signature word is present.
3009 1.7 dante */
3010 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, bios_sig);
3011 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, 0);
3012 1.7 dante
3013 1.7 dante /*
3014 1.7 dante * Stop chip and reset it.
3015 1.7 dante */
3016 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_STOP);
3017 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
3018 1.7 dante ADW_CTRL_REG_CMD_RESET);
3019 1.7 dante AdvSleepMilliSecond(100);
3020 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
3021 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
3022 1.7 dante
3023 1.7 dante /*
3024 1.7 dante * Reset Adv Library error code, if any, and try
3025 1.7 dante * re-initializing the chip.
3026 1.7 dante */
3027 1.10 dante if (sc->chip_type == ADV_CHIP_ASC38C1600) {
3028 1.10 dante status = AdvInitAsc38C1600Driver(sc);
3029 1.10 dante } else if (sc->chip_type == ADV_CHIP_ASC38C0800) {
3030 1.7 dante status = AdvInitAsc38C0800Driver(sc);
3031 1.7 dante } else {
3032 1.7 dante status = AdvInitAsc3550Driver(sc);
3033 1.7 dante }
3034 1.1 dante
3035 1.7 dante /* Translate initialization return value to status value. */
3036 1.13 dante status = (status == 0)? ADW_TRUE : ADW_FALSE;
3037 1.1 dante
3038 1.7 dante /*
3039 1.7 dante * Restore the BIOS signature word.
3040 1.7 dante */
3041 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, bios_sig);
3042 1.1 dante
3043 1.1 dante /*
3044 1.7 dante * Restore per TID negotiated values.
3045 1.1 dante */
3046 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
3047 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
3048 1.10 dante if (sc->chip_type == ADV_CHIP_ASC38C1600) {
3049 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE, ppr_able);
3050 1.10 dante }
3051 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
3052 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
3053 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
3054 1.7 dante max_cmd[tid]);
3055 1.7 dante }
3056 1.1 dante
3057 1.7 dante return status;
3058 1.1 dante }
3059 1.1 dante
3060 1.1 dante
3061 1.1 dante /*
3062 1.1 dante * Adv Library Interrupt Service Routine
3063 1.1 dante *
3064 1.1 dante * This function is called by a driver's interrupt service routine.
3065 1.1 dante * The function disables and re-enables interrupts.
3066 1.1 dante *
3067 1.7 dante * When a microcode idle command is completed, the ADV_DVC_VAR
3068 1.1 dante * 'idle_cmd_done' field is set to ADW_TRUE.
3069 1.1 dante *
3070 1.1 dante * Note: AdvISR() can be called when interrupts are disabled or even
3071 1.1 dante * when there is no hardware interrupt condition present. It will
3072 1.1 dante * always check for completed idle commands and microcode requests.
3073 1.1 dante * This is an important feature that shouldn't be changed because it
3074 1.1 dante * allows commands to be completed from polling mode loops.
3075 1.1 dante *
3076 1.1 dante * Return:
3077 1.1 dante * ADW_TRUE(1) - interrupt was pending
3078 1.1 dante * ADW_FALSE(0) - no interrupt was pending
3079 1.1 dante */
3080 1.1 dante int
3081 1.1 dante AdvISR(sc)
3082 1.7 dante ADW_SOFTC *sc;
3083 1.1 dante {
3084 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3085 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3086 1.7 dante u_int8_t int_stat;
3087 1.7 dante u_int16_t target_bit;
3088 1.7 dante ADW_CARRIER *free_carrp/*, *ccb_carr*/;
3089 1.7 dante u_int32_t irq_next_pa;
3090 1.7 dante ADW_SCSI_REQ_Q *scsiq;
3091 1.7 dante ADW_CCB *ccb;
3092 1.11 dante int s;
3093 1.11 dante
3094 1.1 dante
3095 1.11 dante s = splbio();
3096 1.1 dante
3097 1.1 dante /* Reading the register clears the interrupt. */
3098 1.1 dante int_stat = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_INTR_STATUS_REG);
3099 1.1 dante
3100 1.7 dante if ((int_stat & (ADW_INTR_STATUS_INTRA | ADW_INTR_STATUS_INTRB |
3101 1.7 dante ADW_INTR_STATUS_INTRC)) == 0) {
3102 1.11 dante splx(s);
3103 1.7 dante return ADW_FALSE;
3104 1.1 dante }
3105 1.7 dante
3106 1.7 dante /*
3107 1.7 dante * Notify the driver of an asynchronous microcode condition by
3108 1.7 dante * calling the ADV_DVC_VAR.async_callback function. The function
3109 1.7 dante * is passed the microcode ASC_MC_INTRB_CODE byte value.
3110 1.1 dante */
3111 1.7 dante if (int_stat & ADW_INTR_STATUS_INTRB) {
3112 1.7 dante u_int8_t intrb_code;
3113 1.7 dante
3114 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_INTRB_CODE, intrb_code);
3115 1.10 dante
3116 1.10 dante if (sc->chip_type == ADV_CHIP_ASC3550 ||
3117 1.10 dante sc->chip_type == ADV_CHIP_ASC38C0800) {
3118 1.10 dante if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
3119 1.10 dante sc->carr_pending_cnt != 0) {
3120 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
3121 1.10 dante IOPB_TICKLE, ADV_TICKLE_A);
3122 1.10 dante if (sc->chip_type == ADV_CHIP_ASC3550) {
3123 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
3124 1.10 dante IOPB_TICKLE, ADV_TICKLE_NOP);
3125 1.10 dante }
3126 1.10 dante }
3127 1.7 dante }
3128 1.7 dante
3129 1.7 dante if (sc->async_callback != 0) {
3130 1.7 dante (*(ADW_ASYNC_CALLBACK)sc->async_callback)(sc, intrb_code);
3131 1.1 dante }
3132 1.1 dante }
3133 1.7 dante
3134 1.1 dante /*
3135 1.7 dante * Check if the IRQ stopper carrier contains a completed request.
3136 1.1 dante */
3137 1.12 dante while (((irq_next_pa = sc->irq_sp->next_ba) & ASC_RQ_DONE) != 0)
3138 1.7 dante {
3139 1.12 dante #if ADW_DEBUG
3140 1.12 dante printf("irq 0x%x, 0x%x, 0x%x, 0x%x\n",
3141 1.12 dante sc->irq_sp->carr_id,
3142 1.12 dante sc->irq_sp->carr_ba,
3143 1.12 dante sc->irq_sp->areq_ba,
3144 1.12 dante sc->irq_sp->next_ba);
3145 1.12 dante #endif
3146 1.7 dante /*
3147 1.10 dante * Get a pointer to the newly completed ADW_SCSI_REQ_Q
3148 1.10 dante * structure.
3149 1.12 dante * The RISC will have set 'areq_ba' to a virtual address.
3150 1.7 dante *
3151 1.7 dante * The firmware will have copied the ASC_SCSI_REQ_Q.ccb_ptr
3152 1.12 dante * field to the carrier ADV_CARR_T.areq_ba field.
3153 1.10 dante * The conversion below complements the conversion of
3154 1.10 dante * ASC_SCSI_REQ_Q.scsiq_ptr' in AdvExeScsiQueue().
3155 1.7 dante */
3156 1.12 dante ccb = adw_ccb_phys_kv(sc, sc->irq_sp->areq_ba);
3157 1.7 dante scsiq = &ccb->scsiq;
3158 1.12 dante scsiq->ccb_ptr = sc->irq_sp->areq_ba;
3159 1.7 dante
3160 1.10 dante /*
3161 1.10 dante * Request finished with good status and the queue was not
3162 1.10 dante * DMAed to host memory by the firmware. Set all status fields
3163 1.10 dante * to indicate good status.
3164 1.10 dante */
3165 1.10 dante if ((irq_next_pa & ASC_RQ_GOOD) != 0) {
3166 1.10 dante scsiq->done_status = QD_NO_ERROR;
3167 1.10 dante scsiq->host_status = scsiq->scsi_status = 0;
3168 1.10 dante scsiq->data_cnt = 0L;
3169 1.7 dante }
3170 1.1 dante
3171 1.1 dante /*
3172 1.7 dante * Advance the stopper pointer to the next carrier
3173 1.7 dante * ignoring the lower four bits. Free the previous
3174 1.7 dante * stopper carrier.
3175 1.1 dante */
3176 1.7 dante free_carrp = sc->irq_sp;
3177 1.7 dante sc->irq_sp = adw_carrier_phys_kv(sc, ASC_GET_CARRP(irq_next_pa));
3178 1.7 dante
3179 1.12 dante free_carrp->next_ba = sc->carr_freelist->carr_ba;
3180 1.7 dante sc->carr_freelist = free_carrp;
3181 1.7 dante sc->carr_pending_cnt--;
3182 1.1 dante
3183 1.1 dante
3184 1.1 dante target_bit = ADW_TID_TO_TIDMASK(scsiq->target_id);
3185 1.1 dante
3186 1.1 dante /*
3187 1.1 dante * Clear request microcode control flag.
3188 1.1 dante */
3189 1.1 dante scsiq->cntl = 0;
3190 1.1 dante
3191 1.1 dante /*
3192 1.1 dante * Check Condition handling
3193 1.1 dante */
3194 1.1 dante /*
3195 1.1 dante * If the command that completed was a SCSI INQUIRY and
3196 1.1 dante * LUN 0 was sent the command, then process the INQUIRY
3197 1.1 dante * command information for the device.
3198 1.1 dante */
3199 1.7 dante if (scsiq->done_status == QD_NO_ERROR &&
3200 1.10 dante scsiq->cdb[0] == INQUIRY &&
3201 1.10 dante scsiq->target_lun == 0) {
3202 1.1 dante AdvInquiryHandling(sc, scsiq);
3203 1.1 dante }
3204 1.1 dante
3205 1.1 dante /*
3206 1.1 dante * Notify the driver of the completed request by passing
3207 1.1 dante * the ADW_SCSI_REQ_Q pointer to its callback function.
3208 1.1 dante */
3209 1.7 dante (*(ADW_ISR_CALLBACK)sc->isr_callback)(sc, scsiq);
3210 1.1 dante /*
3211 1.1 dante * Note: After the driver callback function is called, 'scsiq'
3212 1.1 dante * can no longer be referenced.
3213 1.1 dante *
3214 1.1 dante * Fall through and continue processing other completed
3215 1.1 dante * requests...
3216 1.1 dante */
3217 1.1 dante }
3218 1.11 dante
3219 1.11 dante splx(s);
3220 1.7 dante
3221 1.7 dante return ADW_TRUE;
3222 1.1 dante }
3223 1.1 dante
3224 1.7 dante
3225 1.1 dante /*
3226 1.1 dante * Send an idle command to the chip and wait for completion.
3227 1.1 dante *
3228 1.7 dante * Command completion is polled for once per microsecond.
3229 1.7 dante *
3230 1.7 dante * The function can be called from anywhere including an interrupt handler.
3231 1.10 dante * But the function is not re-entrant, so it uses the splbio/splx()
3232 1.7 dante * functions to prevent reentrancy.
3233 1.1 dante *
3234 1.1 dante * Return Values:
3235 1.1 dante * ADW_TRUE - command completed successfully
3236 1.1 dante * ADW_FALSE - command failed
3237 1.7 dante * ADW_ERROR - command timed out
3238 1.1 dante */
3239 1.1 dante int
3240 1.7 dante AdvSendIdleCmd(sc, idle_cmd, idle_cmd_parameter)
3241 1.7 dante ADW_SOFTC *sc;
3242 1.7 dante u_int16_t idle_cmd;
3243 1.7 dante u_int32_t idle_cmd_parameter;
3244 1.1 dante {
3245 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3246 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3247 1.13 dante u_int16_t result;
3248 1.10 dante u_int32_t i, j, s;
3249 1.1 dante
3250 1.10 dante s = splbio();
3251 1.7 dante
3252 1.7 dante /*
3253 1.7 dante * Clear the idle command status which is set by the microcode
3254 1.7 dante * to a non-zero value to indicate when the command is completed.
3255 1.7 dante */
3256 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_STATUS, (u_int16_t) 0);
3257 1.1 dante
3258 1.1 dante /*
3259 1.1 dante * Write the idle command value after the idle command parameter
3260 1.1 dante * has been written to avoid a race condition. If the order is not
3261 1.1 dante * followed, the microcode may process the idle command before the
3262 1.1 dante * parameters have been written to LRAM.
3263 1.1 dante */
3264 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_PARAMETER,
3265 1.13 dante idle_cmd_parameter);
3266 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD, idle_cmd);
3267 1.1 dante
3268 1.1 dante /*
3269 1.7 dante * Tickle the RISC to tell it to process the idle command.
3270 1.1 dante */
3271 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_B);
3272 1.7 dante if (sc->chip_type == ADV_CHIP_ASC3550) {
3273 1.1 dante /*
3274 1.7 dante * Clear the tickle value. In the ASC-3550 the RISC flag
3275 1.7 dante * command 'clr_tickle_b' does not work unless the host
3276 1.7 dante * value is cleared.
3277 1.1 dante */
3278 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_NOP);
3279 1.7 dante }
3280 1.1 dante
3281 1.7 dante /* Wait for up to 100 millisecond for the idle command to timeout. */
3282 1.7 dante for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
3283 1.7 dante /* Poll once each microsecond for command completion. */
3284 1.7 dante for (j = 0; j < SCSI_US_PER_MSEC; j++) {
3285 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_STATUS, result);
3286 1.7 dante if (result != 0) {
3287 1.10 dante splx(s);
3288 1.7 dante return result;
3289 1.7 dante }
3290 1.7 dante AdvDelayMicroSecond(1);
3291 1.7 dante }
3292 1.1 dante }
3293 1.1 dante
3294 1.10 dante splx(s);
3295 1.7 dante return ADW_ERROR;
3296 1.1 dante }
3297 1.1 dante
3298 1.1 dante
3299 1.1 dante /*
3300 1.1 dante * Inquiry Information Byte 7 Handling
3301 1.1 dante *
3302 1.1 dante * Handle SCSI Inquiry Command information for a device by setting
3303 1.2 dante * microcode operating variables that affect WDTR, SDTR, and Tag
3304 1.1 dante * Queuing.
3305 1.1 dante */
3306 1.1 dante static void
3307 1.1 dante AdvInquiryHandling(sc, scsiq)
3308 1.7 dante ADW_SOFTC *sc;
3309 1.7 dante ADW_SCSI_REQ_Q *scsiq;
3310 1.1 dante {
3311 1.9 dante #ifndef FAILSAFE
3312 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3313 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3314 1.7 dante u_int8_t tid;
3315 1.13 dante struct scsipi_inquiry_data *inq;
3316 1.7 dante u_int16_t tidmask;
3317 1.7 dante u_int16_t cfg_word;
3318 1.7 dante
3319 1.1 dante
3320 1.1 dante /*
3321 1.1 dante * AdvInquiryHandling() requires up to INQUIRY information Byte 7
3322 1.1 dante * to be available.
3323 1.1 dante *
3324 1.1 dante * If less than 8 bytes of INQUIRY information were requested or less
3325 1.1 dante * than 8 bytes were transferred, then return. cdb[4] is the request
3326 1.1 dante * length and the ADW_SCSI_REQ_Q 'data_cnt' field is set by the
3327 1.1 dante * microcode to the transfer residual count.
3328 1.1 dante */
3329 1.7 dante
3330 1.2 dante if (scsiq->cdb[4] < 8 || (scsiq->cdb[4] - scsiq->data_cnt) < 8) {
3331 1.1 dante return;
3332 1.1 dante }
3333 1.7 dante
3334 1.1 dante tid = scsiq->target_id;
3335 1.7 dante
3336 1.13 dante inq = (struct scsipi_inquiry_data *) scsiq->vdata_addr;
3337 1.1 dante
3338 1.1 dante /*
3339 1.1 dante * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
3340 1.1 dante */
3341 1.13 dante if (((inq->response_format & SID_RespDataFmt) < 2) /*SCSI-1 | CCS*/ &&
3342 1.13 dante ((inq->version & SID_ANSII) < 2)) {
3343 1.1 dante return;
3344 1.2 dante } else {
3345 1.1 dante /*
3346 1.1 dante * INQUIRY Byte 7 Handling
3347 1.1 dante *
3348 1.1 dante * Use a device's INQUIRY byte 7 to determine whether it
3349 1.1 dante * supports WDTR, SDTR, and Tag Queuing. If the feature
3350 1.1 dante * is enabled in the EEPROM and the device supports the
3351 1.1 dante * feature, then enable it in the microcode.
3352 1.1 dante */
3353 1.1 dante
3354 1.1 dante tidmask = ADW_TID_TO_TIDMASK(tid);
3355 1.7 dante
3356 1.1 dante /*
3357 1.1 dante * Wide Transfers
3358 1.1 dante *
3359 1.1 dante * If the EEPROM enabled WDTR for the device and the device
3360 1.1 dante * supports wide bus (16 bit) transfers, then turn on the
3361 1.1 dante * device's 'wdtr_able' bit and write the new value to the
3362 1.1 dante * microcode.
3363 1.1 dante */
3364 1.7 dante #ifdef SCSI_ADW_WDTR_DISABLE
3365 1.8 dante if(!(tidmask & SCSI_ADW_WDTR_DISABLE))
3366 1.7 dante #endif /* SCSI_ADW_WDTR_DISABLE */
3367 1.13 dante if ((sc->wdtr_able & tidmask) && (inq->flags3 & SID_WBus16)) {
3368 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
3369 1.7 dante cfg_word);
3370 1.2 dante if ((cfg_word & tidmask) == 0) {
3371 1.1 dante cfg_word |= tidmask;
3372 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
3373 1.7 dante cfg_word);
3374 1.1 dante
3375 1.1 dante /*
3376 1.7 dante * Clear the microcode "SDTR negotiation" and "WDTR
3377 1.7 dante * negotiation" done indicators for the target to cause
3378 1.7 dante * it to negotiate with the new setting set above.
3379 1.7 dante * WDTR when accepted causes the target to enter
3380 1.7 dante * asynchronous mode, so SDTR must be negotiated.
3381 1.1 dante */
3382 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
3383 1.7 dante cfg_word);
3384 1.7 dante cfg_word &= ~tidmask;
3385 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
3386 1.7 dante cfg_word);
3387 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
3388 1.7 dante cfg_word);
3389 1.1 dante cfg_word &= ~tidmask;
3390 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
3391 1.7 dante cfg_word);
3392 1.1 dante }
3393 1.1 dante }
3394 1.7 dante
3395 1.1 dante /*
3396 1.1 dante * Synchronous Transfers
3397 1.1 dante *
3398 1.1 dante * If the EEPROM enabled SDTR for the device and the device
3399 1.1 dante * supports synchronous transfers, then turn on the device's
3400 1.1 dante * 'sdtr_able' bit. Write the new value to the microcode.
3401 1.1 dante */
3402 1.7 dante #ifdef SCSI_ADW_SDTR_DISABLE
3403 1.8 dante if(!(tidmask & SCSI_ADW_SDTR_DISABLE))
3404 1.7 dante #endif /* SCSI_ADW_SDTR_DISABLE */
3405 1.13 dante if ((sc->sdtr_able & tidmask) && (inq->flags3 & SID_Sync)) {
3406 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, cfg_word);
3407 1.2 dante if ((cfg_word & tidmask) == 0) {
3408 1.1 dante cfg_word |= tidmask;
3409 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
3410 1.7 dante cfg_word);
3411 1.1 dante
3412 1.1 dante /*
3413 1.7 dante * Clear the microcode "SDTR negotiation" done indicator
3414 1.7 dante * for the target to cause it to negotiate with the new
3415 1.7 dante * setting set above.
3416 1.1 dante */
3417 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
3418 1.7 dante cfg_word);
3419 1.1 dante cfg_word &= ~tidmask;
3420 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
3421 1.7 dante cfg_word);
3422 1.10 dante }
3423 1.10 dante }
3424 1.10 dante /*
3425 1.10 dante * If the Inquiry data included enough space for the SPI-3
3426 1.10 dante * Clocking field, then check if DT mode is supported.
3427 1.10 dante */
3428 1.10 dante if (sc->chip_type == ADV_CHIP_ASC38C1600 &&
3429 1.10 dante (scsiq->cdb[4] >= 57 ||
3430 1.10 dante (scsiq->cdb[4] - scsiq->data_cnt) >= 57)) {
3431 1.10 dante /*
3432 1.10 dante * PPR (Parallel Protocol Request) Capable
3433 1.10 dante *
3434 1.10 dante * If the device supports DT mode, then it must be
3435 1.10 dante * PPR capable.
3436 1.10 dante * The PPR message will be used in place of the SDTR
3437 1.10 dante * and WDTR messages to negotiate synchronous speed
3438 1.10 dante * and offset, transfer width, and protocol options.
3439 1.10 dante */
3440 1.13 dante if ((inq->flags4 & SID_Cloacking) &
3441 1.13 dante SIDV_CLOCKING_DT_ONLY)
3442 1.10 dante {
3443 1.10 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE,
3444 1.10 dante sc->ppr_able);
3445 1.10 dante sc->ppr_able |= tidmask;
3446 1.10 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_PPR_ABLE,
3447 1.10 dante sc->ppr_able);
3448 1.1 dante }
3449 1.1 dante }
3450 1.7 dante
3451 1.1 dante /*
3452 1.7 dante * If the EEPROM enabled Tag Queuing for the device and the
3453 1.7 dante * device supports Tag Queueing, then turn on the device's
3454 1.1 dante * 'tagqng_enable' bit in the microcode and set the microcode
3455 1.7 dante * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
3456 1.1 dante * value.
3457 1.1 dante *
3458 1.1 dante * Tag Queuing is disabled for the BIOS which runs in polled
3459 1.1 dante * mode and would see no benefit from Tag Queuing. Also by
3460 1.1 dante * disabling Tag Queuing in the BIOS devices with Tag Queuing
3461 1.1 dante * bugs will at least work with the BIOS.
3462 1.1 dante */
3463 1.7 dante #ifdef SCSI_ADW_TAGQ_DISABLE
3464 1.8 dante if(!(tidmask & SCSI_ADW_TAGQ_DISABLE))
3465 1.7 dante #endif /* SCSI_ADW_TAGQ_DISABLE */
3466 1.13 dante if ((sc->tagqng_able & tidmask) && (inq->flags3 & SID_CmdQue)) {
3467 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
3468 1.7 dante cfg_word);
3469 1.1 dante cfg_word |= tidmask;
3470 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
3471 1.7 dante cfg_word);
3472 1.7 dante
3473 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
3474 1.7 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
3475 1.7 dante sc->max_dvc_qng);
3476 1.1 dante }
3477 1.9 dante }
3478 1.7 dante #endif /* FAILSAFE */
3479 1.1 dante }
3480 1.1 dante
3481 1.7 dante
3482 1.1 dante static void
3483 1.7 dante AdvSleepMilliSecond(n)
3484 1.7 dante u_int32_t n;
3485 1.1 dante {
3486 1.1 dante
3487 1.1 dante DELAY(n * 1000);
3488 1.1 dante }
3489 1.1 dante
3490 1.7 dante
3491 1.1 dante static void
3492 1.7 dante AdvDelayMicroSecond(n)
3493 1.7 dante u_int32_t n;
3494 1.1 dante {
3495 1.1 dante
3496 1.1 dante DELAY(n);
3497 1.1 dante }
3498 1.7 dante
3499