adwlib.c revision 1.16 1 1.16 dante /* $NetBSD: adwlib.c,v 1.16 2000/05/26 15:13:43 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.16 dante #include <dev/ic/adwmcode.h>
77 1.1 dante #include <dev/ic/adw.h>
78 1.1 dante
79 1.1 dante
80 1.1 dante /* Static Functions */
81 1.1 dante
82 1.16 dante static u_int16_t AdwGet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
83 1.7 dante ADW_EEP_3550_CONFIG *));
84 1.16 dante static u_int16_t AdwGet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
85 1.7 dante ADW_EEP_38C0800_CONFIG *));
86 1.16 dante static u_int16_t AdwGet38C1600EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
87 1.10 dante ADW_EEP_38C1600_CONFIG *));
88 1.16 dante static u_int16_t AdwReadEEPWord __P((bus_space_tag_t, bus_space_handle_t, int));
89 1.16 dante static void AdwWaitEEPCmd __P((bus_space_tag_t, bus_space_handle_t));
90 1.16 dante static void AdwSet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
91 1.7 dante ADW_EEP_3550_CONFIG *));
92 1.16 dante static void AdwSet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
93 1.7 dante ADW_EEP_38C0800_CONFIG *));
94 1.16 dante static void AdwSet38C1600EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
95 1.10 dante ADW_EEP_38C1600_CONFIG *));
96 1.16 dante static void AdwInquiryHandling __P((ADW_SOFTC *, ADW_SCSI_REQ_Q *));
97 1.1 dante
98 1.16 dante static void AdwSleepMilliSecond __P((u_int32_t));
99 1.16 dante static void AdwDelayMicroSecond __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.16 dante * Additional structure information can be found in adwlib.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.16 dante ADW_DEF_MAX_HOST_QNG, /* max_host_qng */
131 1.16 dante ADW_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.16 dante ADW_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
169 1.16 dante ADW_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.16 dante ADW_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
234 1.16 dante ADW_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.16 dante AdwInitAsc3550Driver(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.16 dante u_int16_t bios_mem[ADW_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.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
319 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_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.16 dante if (bios_mem[(ADW_MC_BIOS_SIGNATURE - ADW_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.16 dante bios_version = bios_mem[(ADW_MC_BIOS_VERSION-ADW_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.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, wdtr_able);
337 1.7 dante }
338 1.7 dante }
339 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sdtr_able);
340 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE, tagqng_able);
341 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
342 1.16 dante ADW_READ_BYTE_LRAM(iot, ioh, ADW_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.16 dante for (i = 253 * 2; i < adw_asc3550_mcode_data.mcode_size; i++) {
370 1.16 dante if (adw_asc3550_mcode_data.mcode_data[i] == 0xff) {
371 1.16 dante for (j = 0; j < adw_asc3550_mcode_data.mcode_data[i + 1]; j++) {
372 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
373 1.16 dante (((u_int16_t)adw_asc3550_mcode_data.mcode_data[i + 3] << 8) |
374 1.16 dante adw_asc3550_mcode_data.mcode_data[i + 2]));
375 1.7 dante word++;
376 1.7 dante }
377 1.7 dante i += 3;
378 1.16 dante } else if (adw_asc3550_mcode_data.mcode_data[i] == 0xfe) {
379 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
380 1.16 dante (((u_int16_t)adw_asc3550_mcode_data.mcode_data[i + 2] << 8) |
381 1.16 dante adw_asc3550_mcode_data.mcode_data[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.16 dante adw_asc3550_mcode_data.mcode_data[(adw_asc3550_mcode_data.mcode_data[i] * 2) + 1] <<8)|
387 1.16 dante adw_asc3550_mcode_data.mcode_data[adw_asc3550_mcode_data.mcode_data[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.16 dante for (; word < ADW_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.16 dante if (sum != adw_asc3550_mcode_data.mcode_chksum) {
417 1.16 dante return ADW_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.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
424 1.16 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ADW_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.16 dante * code checksum location ADW_MC_CODE_CHK_SUM (0x2C).
431 1.1 dante */
432 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, begin_addr);
433 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_VERSION_DATE,
445 1.7 dante sc->cfg.mcode_date);
446 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CHIP_TYPE, ADW_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.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
462 1.1 dante word |= CONTROL_FLAG_IGNORE_PERR;
463 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante * queuing will be set in AdwInquiryHandling() based on what a
476 1.7 dante * device reports it is capable of in Inquiry byte 7.
477 1.7 dante *
478 1.16 dante * If SCSI Bus Resets have 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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
487 1.7 dante sc->wdtr_able);
488 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante return ADW_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.16 dante return ADW_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.16 dante return ADW_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.16 dante * then 'termination' was set-up in AdwInitFrom3550EEPROM() 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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_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.16 dante i = AdwInitCarriers(sc->sc_dmamap_carrier,
680 1.16 dante sc->sc_control->carriers, &sc->carr_freelist);
681 1.16 dante if (i == 0) {
682 1.16 dante return ADW_IERR_NO_CARRIER; /* (ENOMEM) */ ;
683 1.16 dante } else if (i != ADW_MAX_CARRIER) {
684 1.16 dante printf("%s: WARNING: only %d of %d Carriers created\n",
685 1.16 dante sc->sc_dev.dv_xname, i, ADW_MAX_CARRIER);
686 1.16 dante }
687 1.16 dante
688 1.7 dante /*
689 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
690 1.7 dante */
691 1.7 dante
692 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
693 1.16 dante return ADW_IERR_NO_CARRIER;
694 1.7 dante }
695 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
696 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
697 1.7 dante
698 1.7 dante /*
699 1.7 dante * The first command issued will be placed in the stopper carrier.
700 1.7 dante */
701 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
702 1.1 dante
703 1.1 dante /*
704 1.7 dante * Set RISC ICQ physical address start value.
705 1.7 dante */
706 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_ICQ, sc->icq_sp->carr_ba);
707 1.7 dante
708 1.7 dante /*
709 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
710 1.1 dante */
711 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
712 1.16 dante return ADW_IERR_NO_CARRIER;
713 1.1 dante }
714 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
715 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
716 1.1 dante
717 1.1 dante /*
718 1.7 dante * The first command completed by the RISC will be placed in
719 1.7 dante * the stopper.
720 1.1 dante *
721 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
722 1.16 dante * completed the RISC will set the ASC_RQ_DONE bit.
723 1.1 dante */
724 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
725 1.1 dante
726 1.1 dante /*
727 1.7 dante * Set RISC IRQ physical address start value.
728 1.1 dante */
729 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_IRQ, sc->irq_sp->carr_ba);
730 1.7 dante sc->carr_pending_cnt = 0;
731 1.1 dante
732 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
733 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
734 1.1 dante
735 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, word);
736 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
737 1.1 dante
738 1.1 dante /* finally, finally, gentlemen, start your engine */
739 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
740 1.2 dante
741 1.7 dante /*
742 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
743 1.7 dante * Resets should be performed. The RISC has to be running
744 1.7 dante * to issue a SCSI Bus Reset.
745 1.7 dante */
746 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
747 1.7 dante {
748 1.7 dante /*
749 1.7 dante * If the BIOS Signature is present in memory, restore the
750 1.7 dante * BIOS Handshake Configuration Table and do not perform
751 1.7 dante * a SCSI Bus Reset.
752 1.7 dante */
753 1.16 dante if (bios_mem[(ADW_MC_BIOS_SIGNATURE - ADW_MC_BIOSMEM)/2] ==
754 1.7 dante 0x55AA) {
755 1.7 dante /*
756 1.7 dante * Restore per TID negotiated values.
757 1.7 dante */
758 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
759 1.7 dante wdtr_able);
760 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE,
761 1.7 dante sdtr_able);
762 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE,
763 1.7 dante tagqng_able);
764 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
765 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
766 1.16 dante ADW_MC_NUMBER_OF_MAX_CMD + tid,
767 1.7 dante max_cmd[tid]);
768 1.7 dante }
769 1.7 dante } else {
770 1.16 dante if (AdwResetCCB(sc) != ADW_TRUE) {
771 1.16 dante warn_code = ADW_WARN_BUSRESET_ERROR;
772 1.7 dante }
773 1.7 dante }
774 1.7 dante }
775 1.7 dante
776 1.7 dante return warn_code;
777 1.1 dante }
778 1.1 dante
779 1.1 dante /*
780 1.7 dante * Initialize the ASC-38C0800.
781 1.1 dante *
782 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
783 1.1 dante *
784 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
785 1.1 dante * then 0 is returned.
786 1.1 dante */
787 1.1 dante int
788 1.16 dante AdwInitAsc38C0800Driver(sc)
789 1.7 dante ADW_SOFTC *sc;
790 1.1 dante {
791 1.2 dante bus_space_tag_t iot = sc->sc_iot;
792 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
793 1.7 dante u_int16_t warn_code;
794 1.7 dante u_int32_t sum;
795 1.7 dante int begin_addr;
796 1.7 dante int end_addr;
797 1.7 dante u_int16_t code_sum;
798 1.7 dante int word;
799 1.7 dante int i, j;
800 1.7 dante int adv_asc38C0800_expanded_size;
801 1.7 dante u_int16_t scsi_cfg1;
802 1.7 dante u_int8_t byte;
803 1.7 dante u_int8_t tid;
804 1.16 dante u_int16_t bios_mem[ADW_MC_BIOSLEN/2]; /* BIOS RISC Memory
805 1.7 dante 0x40-0x8F. */
806 1.7 dante u_int16_t wdtr_able, sdtr_able, tagqng_able;
807 1.7 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
808 1.1 dante
809 1.1 dante
810 1.1 dante warn_code = 0;
811 1.1 dante
812 1.1 dante /*
813 1.7 dante * Save the RISC memory BIOS region before writing the microcode.
814 1.7 dante * The BIOS may already be loaded and using its RISC LRAM region
815 1.7 dante * so its region must be saved and restored.
816 1.1 dante *
817 1.7 dante * Note: This code makes the assumption, which is currently true,
818 1.7 dante * that a chip reset does not clear RISC LRAM.
819 1.7 dante */
820 1.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
821 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_BIOSMEM + (2 * i), bios_mem[i]);
822 1.7 dante }
823 1.7 dante
824 1.7 dante /*
825 1.7 dante * Save current per TID negotiated values.
826 1.1 dante */
827 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, wdtr_able);
828 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sdtr_able);
829 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE, tagqng_able);
830 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
831 1.16 dante ADW_READ_BYTE_LRAM(iot, ioh, ADW_MC_NUMBER_OF_MAX_CMD + tid,
832 1.7 dante max_cmd[tid]);
833 1.7 dante }
834 1.2 dante
835 1.7 dante /*
836 1.7 dante * RAM BIST (RAM Built-In Self Test)
837 1.7 dante *
838 1.7 dante * Address : I/O base + offset 0x38h register (byte).
839 1.7 dante * Function: Bit 7-6(RW) : RAM mode
840 1.7 dante * Normal Mode : 0x00
841 1.7 dante * Pre-test Mode : 0x40
842 1.7 dante * RAM Test Mode : 0x80
843 1.7 dante * Bit 5 : unused
844 1.7 dante * Bit 4(RO) : Done bit
845 1.7 dante * Bit 3-0(RO) : Status
846 1.7 dante * Host Error : 0x08
847 1.7 dante * Int_RAM Error : 0x04
848 1.7 dante * RISC Error : 0x02
849 1.7 dante * SCSI Error : 0x01
850 1.7 dante * No Error : 0x00
851 1.7 dante *
852 1.7 dante * Note: RAM BIST code should be put right here, before loading the
853 1.7 dante * microcode and after saving the RISC memory BIOS region.
854 1.7 dante */
855 1.1 dante
856 1.7 dante /*
857 1.7 dante * LRAM Pre-test
858 1.7 dante *
859 1.7 dante * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
860 1.7 dante * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
861 1.7 dante * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
862 1.7 dante * to NORMAL_MODE, return an error too.
863 1.7 dante */
864 1.7 dante for (i = 0; i < 2; i++) {
865 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, PRE_TEST_MODE);
866 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before reading back. */
867 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
868 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) !=
869 1.7 dante PRE_TEST_VALUE) {
870 1.16 dante return ADW_IERR_BIST_PRE_TEST;
871 1.1 dante }
872 1.1 dante
873 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
874 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before reading back. */
875 1.7 dante if (ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST)
876 1.7 dante != NORMAL_VALUE) {
877 1.16 dante return ADW_IERR_BIST_PRE_TEST;
878 1.7 dante }
879 1.1 dante }
880 1.7 dante
881 1.1 dante /*
882 1.7 dante * LRAM Test - It takes about 1.5 ms to run through the test.
883 1.1 dante *
884 1.7 dante * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
885 1.7 dante * If Done bit not set or Status not 0, save register byte, set the
886 1.7 dante * err_code, and return an error.
887 1.1 dante */
888 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, RAM_TEST_MODE);
889 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before checking status. */
890 1.7 dante
891 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
892 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
893 1.7 dante /* Get here if Done bit not set or Status not 0. */
894 1.16 dante return ADW_IERR_BIST_RAM_TEST;
895 1.7 dante }
896 1.7 dante
897 1.7 dante /* We need to reset back to normal mode after LRAM test passes. */
898 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
899 1.1 dante
900 1.1 dante /*
901 1.7 dante * Load the Microcode
902 1.7 dante *
903 1.7 dante * Write the microcode image to RISC memory starting at address 0.
904 1.7 dante *
905 1.1 dante */
906 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
907 1.7 dante
908 1.7 dante /* Assume the following compressed format of the microcode buffer:
909 1.7 dante *
910 1.7 dante * 254 word (508 byte) table indexed by byte code followed
911 1.7 dante * by the following byte codes:
912 1.7 dante *
913 1.7 dante * 1-Byte Code:
914 1.7 dante * 00: Emit word 0 in table.
915 1.7 dante * 01: Emit word 1 in table.
916 1.7 dante * .
917 1.7 dante * FD: Emit word 253 in table.
918 1.7 dante *
919 1.7 dante * Multi-Byte Code:
920 1.7 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
921 1.7 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
922 1.7 dante */
923 1.7 dante word = 0;
924 1.16 dante for (i = 253 * 2; i < adw_asc38C0800_mcode_data.mcode_size; i++) {
925 1.16 dante if (adw_asc38C0800_mcode_data.mcode_data[i] == 0xff) {
926 1.16 dante for (j = 0; j < adw_asc38C0800_mcode_data.mcode_data[i + 1]; j++) {
927 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
928 1.7 dante (((u_int16_t)
929 1.16 dante adw_asc38C0800_mcode_data.mcode_data[i + 3] << 8) |
930 1.16 dante adw_asc38C0800_mcode_data.mcode_data[i + 2]));
931 1.7 dante word++;
932 1.7 dante }
933 1.7 dante i += 3;
934 1.16 dante } else if (adw_asc38C0800_mcode_data.mcode_data[i] == 0xfe) {
935 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
936 1.16 dante adw_asc38C0800_mcode_data.mcode_data[i + 2] << 8) |
937 1.16 dante adw_asc38C0800_mcode_data.mcode_data[i + 1]));
938 1.7 dante i += 2;
939 1.7 dante word++;
940 1.1 dante } else {
941 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
942 1.16 dante adw_asc38C0800_mcode_data.mcode_data[(adw_asc38C0800_mcode_data.mcode_data[i] * 2) + 1] << 8) |
943 1.16 dante adw_asc38C0800_mcode_data.mcode_data[adw_asc38C0800_mcode_data.mcode_data[i] * 2]));
944 1.7 dante word++;
945 1.1 dante }
946 1.1 dante }
947 1.7 dante
948 1.7 dante /*
949 1.7 dante * Set 'word' for later use to clear the rest of memory and save
950 1.7 dante * the expanded mcode size.
951 1.7 dante */
952 1.7 dante word *= 2;
953 1.7 dante adv_asc38C0800_expanded_size = word;
954 1.7 dante
955 1.1 dante /*
956 1.7 dante * Clear the rest of ASC-38C0800 Internal RAM (16KB).
957 1.1 dante */
958 1.16 dante for (; word < ADW_38C0800_MEMSIZE; word += 2) {
959 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
960 1.1 dante }
961 1.7 dante
962 1.1 dante /*
963 1.7 dante * Verify the microcode checksum.
964 1.1 dante */
965 1.7 dante sum = 0;
966 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
967 1.7 dante
968 1.7 dante for (word = 0; word < adv_asc38C0800_expanded_size; word += 2) {
969 1.7 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
970 1.7 dante }
971 1.1 dante
972 1.16 dante if (sum != adw_asc38C0800_mcode_data.mcode_chksum) {
973 1.16 dante return ADW_IERR_MCODE_CHKSUM;
974 1.7 dante }
975 1.1 dante
976 1.1 dante /*
977 1.7 dante * Restore the RISC memory BIOS region.
978 1.1 dante */
979 1.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
980 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_BIOSMEM + (2 * i),
981 1.7 dante bios_mem[i]);
982 1.7 dante }
983 1.1 dante
984 1.7 dante /*
985 1.7 dante * Calculate and write the microcode code checksum to the microcode
986 1.16 dante * code checksum location ADW_MC_CODE_CHK_SUM (0x2C).
987 1.7 dante */
988 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, begin_addr);
989 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_END_ADDR, end_addr);
990 1.7 dante code_sum = 0;
991 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
992 1.7 dante for (word = begin_addr; word < end_addr; word += 2) {
993 1.7 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
994 1.1 dante }
995 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CODE_CHK_SUM, code_sum);
996 1.1 dante
997 1.7 dante /*
998 1.7 dante * Read microcode version and date.
999 1.7 dante */
1000 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_VERSION_DATE,
1001 1.7 dante sc->cfg.mcode_date);
1002 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_VERSION_NUM,
1003 1.7 dante sc->cfg.mcode_version);
1004 1.1 dante
1005 1.7 dante /*
1006 1.7 dante * Set the chip type to indicate the ASC38C0800.
1007 1.7 dante */
1008 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CHIP_TYPE, ADW_CHIP_ASC38C0800);
1009 1.1 dante
1010 1.7 dante /*
1011 1.7 dante * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
1012 1.7 dante * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
1013 1.7 dante * cable detection and then we are able to read C_DET[3:0].
1014 1.7 dante *
1015 1.7 dante * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
1016 1.7 dante * Microcode Default Value' section below.
1017 1.7 dante */
1018 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1019 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1,
1020 1.7 dante scsi_cfg1 | ADW_DIS_TERM_DRV);
1021 1.7 dante
1022 1.7 dante /*
1023 1.7 dante * If the PCI Configuration Command Register "Parity Error Response
1024 1.7 dante * Control" Bit was clear (0), then set the microcode variable
1025 1.7 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
1026 1.7 dante * to ignore DMA parity errors.
1027 1.7 dante */
1028 1.7 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
1029 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1030 1.7 dante word |= CONTROL_FLAG_IGNORE_PERR;
1031 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1032 1.7 dante }
1033 1.7 dante
1034 1.7 dante /*
1035 1.11 dante * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and
1036 1.11 dante * START_CTL_TH [3:2] bits for the default FIFO threshold.
1037 1.7 dante *
1038 1.7 dante * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
1039 1.7 dante *
1040 1.7 dante * For DMA Errata #4 set the BC_THRESH_ENB bit.
1041 1.7 dante */
1042 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
1043 1.7 dante BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
1044 1.7 dante
1045 1.7 dante /*
1046 1.7 dante * Microcode operating variables for WDTR, SDTR, and command tag
1047 1.16 dante * queuing will be set in AdwInquiryHandling() based on what a
1048 1.7 dante * device reports it is capable of in Inquiry byte 7.
1049 1.7 dante *
1050 1.7 dante * If SCSI Bus Resets have been disabled, then directly set
1051 1.7 dante * SDTR and WDTR from the EEPROM configuration. This will allow
1052 1.7 dante * the BIOS and warm boot to work without a SCSI bus hang on
1053 1.7 dante * the Inquiry caused by host and target mismatched DTR values.
1054 1.7 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
1055 1.7 dante * be assumed to be in Asynchronous, Narrow mode.
1056 1.7 dante */
1057 1.7 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
1058 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, sc->wdtr_able);
1059 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sc->sdtr_able);
1060 1.7 dante }
1061 1.7 dante
1062 1.7 dante /*
1063 1.7 dante * Set microcode operating variables for DISC and SDTR_SPEED1,
1064 1.7 dante * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
1065 1.7 dante * configuration values.
1066 1.7 dante *
1067 1.7 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
1068 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
1069 1.7 dante * without determining here whether the device supports SDTR.
1070 1.7 dante */
1071 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DISC_ENABLE, sc->cfg.disc_enable);
1072 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED1, sc->sdtr_speed1);
1073 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED2, sc->sdtr_speed2);
1074 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED3, sc->sdtr_speed3);
1075 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED4, sc->sdtr_speed4);
1076 1.7 dante
1077 1.7 dante /*
1078 1.7 dante * Set SCSI_CFG0 Microcode Default Value.
1079 1.7 dante *
1080 1.7 dante * The microcode will set the SCSI_CFG0 register using this value
1081 1.7 dante * after it is started below.
1082 1.7 dante */
1083 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SCSI_CFG0,
1084 1.10 dante ADW_PARITY_EN | ADW_QUEUE_128 | ADW_SEL_TMO_LONG |
1085 1.10 dante ADW_OUR_ID_EN | sc->chip_scsi_id);
1086 1.7 dante
1087 1.7 dante /*
1088 1.7 dante * Determine SCSI_CFG1 Microcode Default Value.
1089 1.7 dante *
1090 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1091 1.7 dante * after it is started below.
1092 1.7 dante */
1093 1.7 dante
1094 1.7 dante /* Read current SCSI_CFG1 Register value. */
1095 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1096 1.7 dante
1097 1.7 dante /*
1098 1.7 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
1099 1.7 dante * register signals will be set. Check for and return an error if
1100 1.7 dante * this condition is found.
1101 1.7 dante */
1102 1.7 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
1103 1.7 dante 0x3F07) {
1104 1.16 dante return ADW_IERR_REVERSED_CABLE;
1105 1.7 dante }
1106 1.7 dante
1107 1.7 dante /*
1108 1.7 dante * All kind of combinations of devices attached to one of four connectors
1109 1.7 dante * are acceptable except HVD device attached. For example, LVD device can
1110 1.7 dante * be attached to SE connector while SE device attached to LVD connector.
1111 1.7 dante * If LVD device attached to SE connector, it only runs up to Ultra speed.
1112 1.7 dante *
1113 1.7 dante * If an HVD device is attached to one of LVD connectors, return an error.
1114 1.7 dante * However, there is no way to detect HVD device attached to SE connectors.
1115 1.7 dante */
1116 1.7 dante if (scsi_cfg1 & ADW_HVD) {
1117 1.16 dante return ADW_IERR_HVD_DEVICE;
1118 1.7 dante }
1119 1.7 dante
1120 1.7 dante /*
1121 1.7 dante * If either SE or LVD automatic termination control is enabled, then
1122 1.7 dante * set the termination value based on a table listed in a_condor.h.
1123 1.7 dante *
1124 1.7 dante * If manual termination was specified with an EEPROM setting then
1125 1.16 dante * 'termination' was set-up in AdwInitFrom38C0800EEPROM() and is ready to
1126 1.7 dante * be 'ored' into SCSI_CFG1.
1127 1.7 dante */
1128 1.7 dante if ((sc->cfg.termination & ADW_TERM_SE) == 0) {
1129 1.7 dante /* SE automatic termination control is enabled. */
1130 1.7 dante switch(scsi_cfg1 & ADW_C_DET_SE) {
1131 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: on */
1132 1.7 dante case 0x1: case 0x2: case 0x3:
1133 1.7 dante sc->cfg.termination |= ADW_TERM_SE;
1134 1.7 dante break;
1135 1.7 dante
1136 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: off */
1137 1.7 dante case 0x0:
1138 1.7 dante sc->cfg.termination |= ADW_TERM_SE_HI;
1139 1.7 dante break;
1140 1.7 dante }
1141 1.7 dante }
1142 1.7 dante
1143 1.7 dante if ((sc->cfg.termination & ADW_TERM_LVD) == 0) {
1144 1.7 dante /* LVD automatic termination control is enabled. */
1145 1.7 dante switch(scsi_cfg1 & ADW_C_DET_LVD) {
1146 1.7 dante /* TERM_LVD_HI: on, TERM_LVD_LO: on */
1147 1.7 dante case 0x4: case 0x8: case 0xC:
1148 1.7 dante sc->cfg.termination |= ADW_TERM_LVD;
1149 1.7 dante break;
1150 1.7 dante
1151 1.7 dante /* TERM_LVD_HI: off, TERM_LVD_LO: off */
1152 1.7 dante case 0x0:
1153 1.7 dante break;
1154 1.7 dante }
1155 1.7 dante }
1156 1.7 dante
1157 1.7 dante /*
1158 1.7 dante * Clear any set TERM_SE and TERM_LVD bits.
1159 1.7 dante */
1160 1.7 dante scsi_cfg1 &= (~ADW_TERM_SE & ~ADW_TERM_LVD);
1161 1.7 dante
1162 1.7 dante /*
1163 1.7 dante * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
1164 1.7 dante */
1165 1.7 dante scsi_cfg1 |= (~sc->cfg.termination & 0xF0);
1166 1.7 dante
1167 1.7 dante /*
1168 1.7 dante * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
1169 1.7 dante * and set possibly modified termination control bits in the Microcode
1170 1.7 dante * SCSI_CFG1 Register Value.
1171 1.7 dante */
1172 1.7 dante scsi_cfg1 &= (~ADW_BIG_ENDIAN & ~ADW_DIS_TERM_DRV &
1173 1.7 dante ~ADW_TERM_POL & ~ADW_HVD_LVD_SE);
1174 1.7 dante
1175 1.7 dante /*
1176 1.7 dante * Set SCSI_CFG1 Microcode Default Value
1177 1.7 dante *
1178 1.7 dante * Set possibly modified termination control and reset DIS_TERM_DRV
1179 1.7 dante * bits in the Microcode SCSI_CFG1 Register Value.
1180 1.7 dante *
1181 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1182 1.7 dante * after it is started below.
1183 1.7 dante */
1184 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
1185 1.7 dante
1186 1.7 dante /*
1187 1.7 dante * Set MEM_CFG Microcode Default Value
1188 1.7 dante *
1189 1.7 dante * The microcode will set the MEM_CFG register using this value
1190 1.7 dante * after it is started below.
1191 1.7 dante *
1192 1.7 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
1193 1.7 dante * are defined.
1194 1.7 dante *
1195 1.7 dante * ASC-38C0800 has 16KB internal memory.
1196 1.7 dante */
1197 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_MEM_CFG,
1198 1.7 dante ADW_BIOS_EN | ADW_RAM_SZ_16KB);
1199 1.7 dante
1200 1.7 dante /*
1201 1.7 dante * Set SEL_MASK Microcode Default Value
1202 1.7 dante *
1203 1.7 dante * The microcode will set the SEL_MASK register using this value
1204 1.7 dante * after it is started below.
1205 1.7 dante */
1206 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SEL_MASK,
1207 1.7 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
1208 1.7 dante
1209 1.7 dante
1210 1.16 dante i = AdwInitCarriers(sc->sc_dmamap_carrier,
1211 1.16 dante sc->sc_control->carriers, &sc->carr_freelist);
1212 1.16 dante if (i == 0) {
1213 1.16 dante return ADW_IERR_NO_CARRIER; /* (ENOMEM) */ ;
1214 1.16 dante } else if (i != ADW_MAX_CARRIER) {
1215 1.16 dante printf("%s: WARNING: only %d of %d Carriers created\n",
1216 1.16 dante sc->sc_dev.dv_xname, i, ADW_MAX_CARRIER);
1217 1.16 dante }
1218 1.16 dante
1219 1.7 dante /*
1220 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
1221 1.7 dante */
1222 1.7 dante
1223 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
1224 1.16 dante return ADW_IERR_NO_CARRIER;
1225 1.7 dante }
1226 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
1227 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
1228 1.7 dante
1229 1.7 dante /*
1230 1.7 dante * The first command issued will be placed in the stopper carrier.
1231 1.7 dante */
1232 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
1233 1.7 dante
1234 1.7 dante /*
1235 1.7 dante * Set RISC ICQ physical address start value.
1236 1.7 dante */
1237 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_ICQ, sc->icq_sp->carr_ba);
1238 1.7 dante
1239 1.7 dante /*
1240 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
1241 1.7 dante */
1242 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
1243 1.16 dante return ADW_IERR_NO_CARRIER;
1244 1.7 dante }
1245 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
1246 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
1247 1.7 dante
1248 1.7 dante /*
1249 1.7 dante * The first command completed by the RISC will be placed in
1250 1.7 dante * the stopper.
1251 1.7 dante *
1252 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
1253 1.16 dante * completed the RISC will set the ASC_RQ_DONE bit.
1254 1.7 dante */
1255 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
1256 1.7 dante
1257 1.7 dante /*
1258 1.7 dante * Set RISC IRQ physical address start value.
1259 1.7 dante */
1260 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_IRQ, sc->irq_sp->carr_ba);
1261 1.7 dante sc->carr_pending_cnt = 0;
1262 1.7 dante
1263 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
1264 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
1265 1.12 dante
1266 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, word);
1267 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
1268 1.7 dante
1269 1.7 dante /* finally, finally, gentlemen, start your engine */
1270 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
1271 1.7 dante
1272 1.7 dante /*
1273 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
1274 1.7 dante * Resets should be performed. The RISC has to be running
1275 1.7 dante * to issue a SCSI Bus Reset.
1276 1.7 dante */
1277 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
1278 1.7 dante /*
1279 1.7 dante * If the BIOS Signature is present in memory, restore the
1280 1.7 dante * BIOS Handshake Configuration Table and do not perform
1281 1.7 dante * a SCSI Bus Reset.
1282 1.7 dante */
1283 1.16 dante if (bios_mem[(ADW_MC_BIOS_SIGNATURE - ADW_MC_BIOSMEM)/2] ==
1284 1.7 dante 0x55AA) {
1285 1.7 dante /*
1286 1.7 dante * Restore per TID negotiated values.
1287 1.7 dante */
1288 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
1289 1.10 dante wdtr_able);
1290 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE,
1291 1.10 dante sdtr_able);
1292 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE,
1293 1.10 dante tagqng_able);
1294 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1295 1.10 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1296 1.16 dante ADW_MC_NUMBER_OF_MAX_CMD + tid,
1297 1.10 dante max_cmd[tid]);
1298 1.10 dante }
1299 1.10 dante } else {
1300 1.16 dante if (AdwResetCCB(sc) != ADW_TRUE) {
1301 1.16 dante warn_code = ADW_WARN_BUSRESET_ERROR;
1302 1.10 dante }
1303 1.10 dante }
1304 1.10 dante }
1305 1.10 dante
1306 1.10 dante return warn_code;
1307 1.10 dante }
1308 1.10 dante
1309 1.10 dante
1310 1.10 dante /*
1311 1.10 dante * Initialize the ASC-38C1600.
1312 1.10 dante *
1313 1.10 dante * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
1314 1.10 dante *
1315 1.10 dante * For a non-fatal error return a warning code. If there are no warnings
1316 1.10 dante * then 0 is returned.
1317 1.10 dante */
1318 1.10 dante int
1319 1.16 dante AdwInitAsc38C1600Driver(sc)
1320 1.10 dante ADW_SOFTC *sc;
1321 1.10 dante {
1322 1.10 dante bus_space_tag_t iot = sc->sc_iot;
1323 1.10 dante bus_space_handle_t ioh = sc->sc_ioh;
1324 1.10 dante u_int16_t warn_code;
1325 1.10 dante u_int32_t sum;
1326 1.10 dante int begin_addr;
1327 1.10 dante int end_addr;
1328 1.10 dante u_int16_t code_sum;
1329 1.10 dante int word;
1330 1.10 dante int i, j;
1331 1.10 dante int adv_asc38C1600_expanded_size;
1332 1.10 dante u_int16_t scsi_cfg1;
1333 1.10 dante u_int8_t byte;
1334 1.10 dante u_int8_t tid;
1335 1.16 dante u_int16_t bios_mem[ADW_MC_BIOSLEN/2]; /* BIOS RISC Memory
1336 1.10 dante 0x40-0x8F. */
1337 1.10 dante u_int16_t wdtr_able, sdtr_able, ppr_able, tagqng_able;
1338 1.10 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
1339 1.10 dante
1340 1.10 dante
1341 1.10 dante warn_code = 0;
1342 1.10 dante
1343 1.10 dante
1344 1.10 dante /*
1345 1.10 dante * Save the RISC memory BIOS region before writing the microcode.
1346 1.10 dante * The BIOS may already be loaded and using its RISC LRAM region
1347 1.10 dante * so its region must be saved and restored.
1348 1.10 dante *
1349 1.10 dante * Note: This code makes the assumption, which is currently true,
1350 1.10 dante * that a chip reset does not clear RISC LRAM.
1351 1.10 dante */
1352 1.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
1353 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_BIOSMEM + (2 * i), bios_mem[i]);
1354 1.10 dante }
1355 1.10 dante
1356 1.10 dante /*
1357 1.10 dante * Save current per TID negotiated values.
1358 1.10 dante */
1359 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, wdtr_able);
1360 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sdtr_able);
1361 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE, ppr_able);
1362 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE, tagqng_able);
1363 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1364 1.16 dante ADW_READ_BYTE_LRAM(iot, ioh, ADW_MC_NUMBER_OF_MAX_CMD + tid,
1365 1.10 dante max_cmd[tid]);
1366 1.10 dante }
1367 1.10 dante
1368 1.10 dante /*
1369 1.10 dante * RAM BIST (RAM Built-In Self Test)
1370 1.10 dante *
1371 1.10 dante * Address : I/O base + offset 0x38h register (byte).
1372 1.10 dante * Function: Bit 7-6(RW) : RAM mode
1373 1.10 dante * Normal Mode : 0x00
1374 1.10 dante * Pre-test Mode : 0x40
1375 1.10 dante * RAM Test Mode : 0x80
1376 1.10 dante * Bit 5 : unused
1377 1.10 dante * Bit 4(RO) : Done bit
1378 1.10 dante * Bit 3-0(RO) : Status
1379 1.10 dante * Host Error : 0x08
1380 1.10 dante * Int_RAM Error : 0x04
1381 1.10 dante * RISC Error : 0x02
1382 1.10 dante * SCSI Error : 0x01
1383 1.10 dante * No Error : 0x00
1384 1.10 dante *
1385 1.10 dante * Note: RAM BIST code should be put right here, before loading the
1386 1.10 dante * microcode and after saving the RISC memory BIOS region.
1387 1.10 dante */
1388 1.10 dante
1389 1.10 dante /*
1390 1.10 dante * LRAM Pre-test
1391 1.10 dante *
1392 1.10 dante * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
1393 1.10 dante * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
1394 1.10 dante * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
1395 1.10 dante * to NORMAL_MODE, return an error too.
1396 1.10 dante */
1397 1.10 dante for (i = 0; i < 2; i++) {
1398 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, PRE_TEST_MODE);
1399 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before reading back. */
1400 1.10 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
1401 1.10 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) !=
1402 1.10 dante PRE_TEST_VALUE) {
1403 1.16 dante return ADW_IERR_BIST_PRE_TEST;
1404 1.10 dante }
1405 1.10 dante
1406 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
1407 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before reading back. */
1408 1.10 dante if (ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST)
1409 1.10 dante != NORMAL_VALUE) {
1410 1.16 dante return ADW_IERR_BIST_PRE_TEST;
1411 1.10 dante }
1412 1.10 dante }
1413 1.10 dante
1414 1.10 dante /*
1415 1.10 dante * LRAM Test - It takes about 1.5 ms to run through the test.
1416 1.10 dante *
1417 1.10 dante * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
1418 1.10 dante * If Done bit not set or Status not 0, save register byte, set the
1419 1.10 dante * err_code, and return an error.
1420 1.10 dante */
1421 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, RAM_TEST_MODE);
1422 1.16 dante AdwSleepMilliSecond(10); /* Wait for 10ms before checking status. */
1423 1.10 dante
1424 1.10 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
1425 1.10 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
1426 1.10 dante /* Get here if Done bit not set or Status not 0. */
1427 1.16 dante return ADW_IERR_BIST_RAM_TEST;
1428 1.10 dante }
1429 1.10 dante
1430 1.10 dante /* We need to reset back to normal mode after LRAM test passes. */
1431 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
1432 1.10 dante
1433 1.10 dante
1434 1.10 dante /*
1435 1.10 dante * Load the Microcode
1436 1.10 dante *
1437 1.10 dante * Write the microcode image to RISC memory starting at address 0.
1438 1.10 dante *
1439 1.10 dante */
1440 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
1441 1.10 dante
1442 1.10 dante /* Assume the following compressed format of the microcode buffer:
1443 1.10 dante *
1444 1.10 dante * 254 word (508 byte) table indexed by byte code followed
1445 1.10 dante * by the following byte codes:
1446 1.10 dante *
1447 1.10 dante * 1-Byte Code:
1448 1.10 dante * 00: Emit word 0 in table.
1449 1.10 dante * 01: Emit word 1 in table.
1450 1.10 dante * .
1451 1.10 dante * FD: Emit word 253 in table.
1452 1.10 dante *
1453 1.10 dante * Multi-Byte Code:
1454 1.10 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
1455 1.10 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
1456 1.10 dante */
1457 1.10 dante word = 0;
1458 1.16 dante for (i = 253 * 2; i < adw_asc38C1600_mcode_data.mcode_size; i++) {
1459 1.16 dante if (adw_asc38C1600_mcode_data.mcode_data[i] == 0xff) {
1460 1.16 dante for (j = 0; j < adw_asc38C1600_mcode_data.mcode_data[i + 1]; j++) {
1461 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
1462 1.10 dante (((u_int16_t)
1463 1.16 dante adw_asc38C1600_mcode_data.mcode_data[i + 3] << 8) |
1464 1.16 dante adw_asc38C1600_mcode_data.mcode_data[i + 2]));
1465 1.10 dante word++;
1466 1.10 dante }
1467 1.10 dante i += 3;
1468 1.16 dante } else if (adw_asc38C1600_mcode_data.mcode_data[i] == 0xfe) {
1469 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
1470 1.16 dante adw_asc38C1600_mcode_data.mcode_data[i + 2] << 8) |
1471 1.16 dante adw_asc38C1600_mcode_data.mcode_data[i + 1]));
1472 1.10 dante i += 2;
1473 1.10 dante word++;
1474 1.10 dante } else {
1475 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
1476 1.16 dante adw_asc38C1600_mcode_data.mcode_data[(adw_asc38C1600_mcode_data.mcode_data[i] * 2) + 1] << 8) |
1477 1.16 dante adw_asc38C1600_mcode_data.mcode_data[adw_asc38C1600_mcode_data.mcode_data[i] * 2]));
1478 1.10 dante word++;
1479 1.10 dante }
1480 1.10 dante }
1481 1.10 dante
1482 1.10 dante /*
1483 1.10 dante * Set 'word' for later use to clear the rest of memory and save
1484 1.10 dante * the expanded mcode size.
1485 1.10 dante */
1486 1.10 dante word *= 2;
1487 1.10 dante adv_asc38C1600_expanded_size = word;
1488 1.10 dante
1489 1.10 dante /*
1490 1.10 dante * Clear the rest of ASC-38C0800 Internal RAM (16KB).
1491 1.10 dante */
1492 1.16 dante for (; word < ADW_38C1600_MEMSIZE; word += 2) {
1493 1.10 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
1494 1.10 dante }
1495 1.10 dante
1496 1.10 dante /*
1497 1.10 dante * Verify the microcode checksum.
1498 1.10 dante */
1499 1.10 dante sum = 0;
1500 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
1501 1.10 dante
1502 1.10 dante for (word = 0; word < adv_asc38C1600_expanded_size; word += 2) {
1503 1.10 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
1504 1.10 dante }
1505 1.10 dante
1506 1.16 dante if (sum != adw_asc38C1600_mcode_data.mcode_chksum) {
1507 1.16 dante return ADW_IERR_MCODE_CHKSUM;
1508 1.10 dante }
1509 1.10 dante
1510 1.10 dante /*
1511 1.10 dante * Restore the RISC memory BIOS region.
1512 1.10 dante */
1513 1.16 dante for (i = 0; i < ADW_MC_BIOSLEN/2; i++) {
1514 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_BIOSMEM + (2 * i),
1515 1.10 dante bios_mem[i]);
1516 1.10 dante }
1517 1.10 dante
1518 1.10 dante /*
1519 1.10 dante * Calculate and write the microcode code checksum to the microcode
1520 1.16 dante * code checksum location ADW_MC_CODE_CHK_SUM (0x2C).
1521 1.10 dante */
1522 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, begin_addr);
1523 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_END_ADDR, end_addr);
1524 1.10 dante code_sum = 0;
1525 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
1526 1.10 dante for (word = begin_addr; word < end_addr; word += 2) {
1527 1.10 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
1528 1.10 dante }
1529 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CODE_CHK_SUM, code_sum);
1530 1.10 dante
1531 1.10 dante /*
1532 1.10 dante * Read microcode version and date.
1533 1.10 dante */
1534 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_VERSION_DATE,
1535 1.10 dante sc->cfg.mcode_date);
1536 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_VERSION_NUM,
1537 1.10 dante sc->cfg.mcode_version);
1538 1.10 dante
1539 1.10 dante /*
1540 1.10 dante * Set the chip type to indicate the ASC38C1600.
1541 1.10 dante */
1542 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CHIP_TYPE, ADW_CHIP_ASC38C1600);
1543 1.10 dante
1544 1.10 dante /*
1545 1.10 dante * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
1546 1.10 dante * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
1547 1.10 dante * cable detection and then we are able to read C_DET[3:0].
1548 1.10 dante *
1549 1.10 dante * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
1550 1.10 dante * Microcode Default Value' section below.
1551 1.10 dante */
1552 1.10 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1553 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1,
1554 1.10 dante scsi_cfg1 | ADW_DIS_TERM_DRV);
1555 1.10 dante
1556 1.10 dante /*
1557 1.10 dante * If the PCI Configuration Command Register "Parity Error Response
1558 1.10 dante * Control" Bit was clear (0), then set the microcode variable
1559 1.10 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
1560 1.10 dante * to ignore DMA parity errors.
1561 1.10 dante */
1562 1.10 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
1563 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1564 1.10 dante word |= CONTROL_FLAG_IGNORE_PERR;
1565 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1566 1.10 dante }
1567 1.10 dante
1568 1.10 dante /*
1569 1.10 dante * If the BIOS control flag AIPP (Asynchronous Information
1570 1.10 dante * Phase Protection) disable bit is not set, then set the firmware
1571 1.10 dante * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
1572 1.10 dante * AIPP checking and encoding.
1573 1.10 dante */
1574 1.10 dante if ((sc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0) {
1575 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1576 1.10 dante word |= CONTROL_FLAG_ENABLE_AIPP;
1577 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_CONTROL_FLAG, word);
1578 1.10 dante }
1579 1.10 dante
1580 1.10 dante /*
1581 1.10 dante * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
1582 1.10 dante * and START_CTL_TH [3:2].
1583 1.10 dante */
1584 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
1585 1.10 dante FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
1586 1.10 dante
1587 1.10 dante /*
1588 1.10 dante * Microcode operating variables for WDTR, SDTR, and command tag
1589 1.16 dante * queuing will be set in AdwInquiryHandling() based on what a
1590 1.10 dante * device reports it is capable of in Inquiry byte 7.
1591 1.10 dante *
1592 1.10 dante * If SCSI Bus Resets have been disabled, then directly set
1593 1.10 dante * SDTR and WDTR from the EEPROM configuration. This will allow
1594 1.10 dante * the BIOS and warm boot to work without a SCSI bus hang on
1595 1.10 dante * the Inquiry caused by host and target mismatched DTR values.
1596 1.10 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
1597 1.10 dante * be assumed to be in Asynchronous, Narrow mode.
1598 1.10 dante */
1599 1.10 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
1600 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, sc->wdtr_able);
1601 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sc->sdtr_able);
1602 1.10 dante }
1603 1.10 dante
1604 1.10 dante /*
1605 1.10 dante * Set microcode operating variables for DISC and SDTR_SPEED1,
1606 1.10 dante * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
1607 1.10 dante * configuration values.
1608 1.10 dante *
1609 1.10 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
1610 1.10 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
1611 1.10 dante * without determining here whether the device supports SDTR.
1612 1.10 dante */
1613 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DISC_ENABLE, sc->cfg.disc_enable);
1614 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED1, sc->sdtr_speed1);
1615 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED2, sc->sdtr_speed2);
1616 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED3, sc->sdtr_speed3);
1617 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_SPEED4, sc->sdtr_speed4);
1618 1.10 dante
1619 1.10 dante /*
1620 1.10 dante * Set SCSI_CFG0 Microcode Default Value.
1621 1.10 dante *
1622 1.10 dante * The microcode will set the SCSI_CFG0 register using this value
1623 1.10 dante * after it is started below.
1624 1.10 dante */
1625 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SCSI_CFG0,
1626 1.10 dante ADW_PARITY_EN | ADW_QUEUE_128 | ADW_SEL_TMO_LONG |
1627 1.10 dante ADW_OUR_ID_EN | sc->chip_scsi_id);
1628 1.10 dante
1629 1.10 dante /*
1630 1.10 dante * Calculate SCSI_CFG1 Microcode Default Value.
1631 1.10 dante *
1632 1.10 dante * The microcode will set the SCSI_CFG1 register using this value
1633 1.10 dante * after it is started below.
1634 1.10 dante *
1635 1.10 dante * Each ASC-38C1600 function has only two cable detect bits.
1636 1.10 dante * The bus mode override bits are in IOPB_SOFT_OVER_WR.
1637 1.10 dante */
1638 1.10 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1639 1.10 dante
1640 1.10 dante /*
1641 1.10 dante * If the cable is reversed all of the SCSI_CTRL register signals
1642 1.10 dante * will be set. Check for and return an error if this condition is
1643 1.10 dante * found.
1644 1.10 dante */
1645 1.10 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
1646 1.10 dante 0x3F07) {
1647 1.16 dante return ADW_IERR_REVERSED_CABLE;
1648 1.10 dante }
1649 1.10 dante
1650 1.10 dante /*
1651 1.10 dante * Each ASC-38C1600 function has two connectors. Only an HVD device
1652 1.10 dante * can not be connected to either connector. An LVD device or SE device
1653 1.10 dante * may be connected to either connecor. If an SE device is connected,
1654 1.10 dante * then at most Ultra speed (20 Mhz) can be used on both connectors.
1655 1.10 dante *
1656 1.10 dante * If an HVD device is attached, return an error.
1657 1.10 dante */
1658 1.10 dante if (scsi_cfg1 & ADW_HVD) {
1659 1.16 dante return ADW_IERR_HVD_DEVICE;
1660 1.10 dante }
1661 1.10 dante
1662 1.10 dante /*
1663 1.10 dante * Each function in the ASC-38C1600 uses only the SE cable detect and
1664 1.10 dante * termination because there are two connectors for each function. Each
1665 1.10 dante * function may use either LVD or SE mode. Corresponding the SE automatic
1666 1.10 dante * termination control EEPROM bits are used for each function. Each
1667 1.10 dante * function has its own EEPROM. If SE automatic control is enabled for
1668 1.10 dante * the function, then set the termination value based on a table listed
1669 1.10 dante * in a_condor.h.
1670 1.10 dante *
1671 1.10 dante * If manual termination is specified in the EEPROM for the function,
1672 1.10 dante * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
1673 1.10 dante * ready to be 'ored' into SCSI_CFG1.
1674 1.10 dante */
1675 1.10 dante if ((sc->cfg.termination & ADW_TERM_SE) == 0) {
1676 1.10 dante /* SE automatic termination control is enabled. */
1677 1.10 dante switch(scsi_cfg1 & ADW_C_DET_SE) {
1678 1.10 dante /* TERM_SE_HI: on, TERM_SE_LO: on */
1679 1.10 dante case 0x1: case 0x2: case 0x3:
1680 1.10 dante sc->cfg.termination |= ADW_TERM_SE;
1681 1.10 dante break;
1682 1.10 dante
1683 1.10 dante case 0x0:
1684 1.10 dante /* !!!!TODO!!!! */
1685 1.10 dante // if (ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) == 0) {
1686 1.10 dante /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
1687 1.10 dante // }
1688 1.10 dante // else
1689 1.10 dante // {
1690 1.10 dante /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
1691 1.10 dante sc->cfg.termination |= ADW_TERM_SE_HI;
1692 1.10 dante // }
1693 1.10 dante break;
1694 1.10 dante }
1695 1.10 dante }
1696 1.10 dante
1697 1.10 dante /*
1698 1.10 dante * Clear any set TERM_SE bits.
1699 1.10 dante */
1700 1.10 dante scsi_cfg1 &= ~ADW_TERM_SE;
1701 1.10 dante
1702 1.10 dante /*
1703 1.10 dante * Invert the TERM_SE bits and then set 'scsi_cfg1'.
1704 1.10 dante */
1705 1.10 dante scsi_cfg1 |= (~sc->cfg.termination & ADW_TERM_SE);
1706 1.10 dante
1707 1.10 dante /*
1708 1.10 dante * Clear Big Endian and Terminator Polarity bits and set possibly
1709 1.10 dante * modified termination control bits in the Microcode SCSI_CFG1
1710 1.10 dante * Register Value.
1711 1.10 dante */
1712 1.10 dante scsi_cfg1 &= (~ADW_BIG_ENDIAN & ~ADW_DIS_TERM_DRV & ~ADW_TERM_POL);
1713 1.10 dante
1714 1.10 dante /*
1715 1.10 dante * Set SCSI_CFG1 Microcode Default Value
1716 1.10 dante *
1717 1.10 dante * Set possibly modified termination control bits in the Microcode
1718 1.10 dante * SCSI_CFG1 Register Value.
1719 1.10 dante *
1720 1.10 dante * The microcode will set the SCSI_CFG1 register using this value
1721 1.10 dante * after it is started below.
1722 1.10 dante */
1723 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
1724 1.10 dante
1725 1.10 dante /*
1726 1.10 dante * Set MEM_CFG Microcode Default Value
1727 1.10 dante *
1728 1.10 dante * The microcode will set the MEM_CFG register using this value
1729 1.10 dante * after it is started below.
1730 1.10 dante *
1731 1.10 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
1732 1.10 dante * are defined.
1733 1.10 dante *
1734 1.10 dante * ASC-38C1600 has 32KB internal memory.
1735 1.10 dante */
1736 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_MEM_CFG,
1737 1.10 dante ADW_BIOS_EN | ADW_RAM_SZ_32KB);
1738 1.10 dante
1739 1.10 dante /*
1740 1.10 dante * Set SEL_MASK Microcode Default Value
1741 1.10 dante *
1742 1.10 dante * The microcode will set the SEL_MASK register using this value
1743 1.10 dante * after it is started below.
1744 1.10 dante */
1745 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_DEFAULT_SEL_MASK,
1746 1.10 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
1747 1.10 dante
1748 1.16 dante
1749 1.16 dante i = AdwInitCarriers(sc->sc_dmamap_carrier,
1750 1.16 dante sc->sc_control->carriers, &sc->carr_freelist);
1751 1.16 dante if (i == 0) {
1752 1.16 dante return ADW_IERR_NO_CARRIER; /* (ENOMEM) */ ;
1753 1.16 dante } else if (i != ADW_MAX_CARRIER) {
1754 1.16 dante printf("%s: WARNING: only %d of %d Carriers created\n",
1755 1.16 dante sc->sc_dev.dv_xname, i, ADW_MAX_CARRIER);
1756 1.16 dante }
1757 1.16 dante
1758 1.10 dante /*
1759 1.10 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
1760 1.10 dante */
1761 1.10 dante
1762 1.10 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
1763 1.16 dante return ADW_IERR_NO_CARRIER;
1764 1.10 dante }
1765 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
1766 1.12 dante ASC_GET_CARRP(sc->icq_sp->next_ba));
1767 1.10 dante
1768 1.10 dante /*
1769 1.10 dante * The first command issued will be placed in the stopper carrier.
1770 1.10 dante */
1771 1.12 dante sc->icq_sp->next_ba = ASC_CQ_STOPPER;
1772 1.10 dante
1773 1.10 dante /*
1774 1.10 dante * Set RISC ICQ physical address start value. Initialize the
1775 1.10 dante * COMMA register to the same value otherwise the RISC will
1776 1.10 dante * prematurely detect a command is available.
1777 1.10 dante */
1778 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_ICQ, sc->icq_sp->carr_ba);
1779 1.12 dante ADW_WRITE_DWORD_REGISTER(iot, ioh, IOPDW_COMMA, sc->icq_sp->carr_ba);
1780 1.10 dante
1781 1.10 dante /*
1782 1.10 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
1783 1.10 dante */
1784 1.10 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
1785 1.16 dante return ADW_IERR_NO_CARRIER;
1786 1.10 dante }
1787 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
1788 1.12 dante ASC_GET_CARRP(sc->irq_sp->next_ba));
1789 1.10 dante
1790 1.10 dante /*
1791 1.10 dante * The first command completed by the RISC will be placed in
1792 1.10 dante * the stopper.
1793 1.10 dante *
1794 1.12 dante * Note: Set 'next_ba' to ASC_CQ_STOPPER. When the request is
1795 1.16 dante * completed the RISC will set the ASC_RQ_DONE bit.
1796 1.10 dante */
1797 1.12 dante sc->irq_sp->next_ba = ASC_CQ_STOPPER;
1798 1.10 dante
1799 1.10 dante /*
1800 1.10 dante * Set RISC IRQ physical address start value.
1801 1.10 dante */
1802 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_IRQ, sc->irq_sp->carr_ba);
1803 1.10 dante sc->carr_pending_cnt = 0;
1804 1.10 dante
1805 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
1806 1.10 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
1807 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_CODE_BEGIN_ADDR, word);
1808 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
1809 1.10 dante
1810 1.10 dante /* finally, finally, gentlemen, start your engine */
1811 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
1812 1.10 dante
1813 1.10 dante /*
1814 1.10 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
1815 1.10 dante * Resets should be performed. The RISC has to be running
1816 1.10 dante * to issue a SCSI Bus Reset.
1817 1.10 dante */
1818 1.10 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
1819 1.10 dante /*
1820 1.10 dante * If the BIOS Signature is present in memory, restore the
1821 1.10 dante * per TID microcode operating variables.
1822 1.10 dante */
1823 1.16 dante if (bios_mem[(ADW_MC_BIOS_SIGNATURE - ADW_MC_BIOSMEM)/2] ==
1824 1.10 dante 0x55AA) {
1825 1.10 dante /*
1826 1.10 dante * Restore per TID negotiated values.
1827 1.10 dante */
1828 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
1829 1.10 dante wdtr_able);
1830 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE,
1831 1.10 dante sdtr_able);
1832 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE,
1833 1.10 dante ppr_able);
1834 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE,
1835 1.10 dante tagqng_able);
1836 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1837 1.10 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1838 1.16 dante ADW_MC_NUMBER_OF_MAX_CMD + tid,
1839 1.10 dante max_cmd[tid]);
1840 1.10 dante }
1841 1.10 dante } else {
1842 1.16 dante if (AdwResetCCB(sc) != ADW_TRUE) {
1843 1.16 dante warn_code = ADW_WARN_BUSRESET_ERROR;
1844 1.10 dante }
1845 1.10 dante }
1846 1.10 dante }
1847 1.10 dante
1848 1.10 dante return warn_code;
1849 1.10 dante }
1850 1.10 dante
1851 1.10 dante
1852 1.10 dante /*
1853 1.10 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
1854 1.10 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
1855 1.10 dante * all of this is done.
1856 1.10 dante *
1857 1.10 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
1858 1.10 dante *
1859 1.10 dante * For a non-fatal error return a warning code. If there are no warnings
1860 1.10 dante * then 0 is returned.
1861 1.10 dante *
1862 1.10 dante * Note: Chip is stopped on entry.
1863 1.10 dante */
1864 1.10 dante int
1865 1.16 dante AdwInitFrom3550EEP(sc)
1866 1.10 dante ADW_SOFTC *sc;
1867 1.10 dante {
1868 1.10 dante bus_space_tag_t iot = sc->sc_iot;
1869 1.10 dante bus_space_handle_t ioh = sc->sc_ioh;
1870 1.10 dante u_int16_t warn_code;
1871 1.10 dante ADW_EEP_3550_CONFIG eep_config;
1872 1.10 dante int i;
1873 1.10 dante
1874 1.10 dante
1875 1.10 dante warn_code = 0;
1876 1.10 dante
1877 1.10 dante /*
1878 1.10 dante * Read the board's EEPROM configuration.
1879 1.10 dante *
1880 1.10 dante * Set default values if a bad checksum is found.
1881 1.10 dante *
1882 1.10 dante * XXX - Don't handle big-endian access to EEPROM yet.
1883 1.10 dante */
1884 1.16 dante if (AdwGet3550EEPConfig(iot, ioh, &eep_config) != eep_config.check_sum){
1885 1.16 dante warn_code |= ADW_WARN_EEPROM_CHKSUM;
1886 1.10 dante
1887 1.10 dante /*
1888 1.10 dante * Set EEPROM default values.
1889 1.10 dante */
1890 1.10 dante for (i = 0; i < sizeof(ADW_EEP_3550_CONFIG); i++) {
1891 1.10 dante *((u_int8_t *) &eep_config + i) =
1892 1.10 dante *((u_int8_t *) &Default_3550_EEPROM_Config + i);
1893 1.10 dante }
1894 1.10 dante
1895 1.10 dante /*
1896 1.10 dante * Assume the 6 byte board serial number that was read
1897 1.10 dante * from EEPROM is correct even if the EEPROM checksum
1898 1.10 dante * failed.
1899 1.10 dante */
1900 1.10 dante eep_config.serial_number_word3 =
1901 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
1902 1.10 dante
1903 1.10 dante eep_config.serial_number_word2 =
1904 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
1905 1.10 dante
1906 1.10 dante eep_config.serial_number_word1 =
1907 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
1908 1.10 dante
1909 1.16 dante AdwSet3550EEPConfig(iot, ioh, &eep_config);
1910 1.10 dante }
1911 1.10 dante /*
1912 1.10 dante * Set sc and sc->cfg variables from the EEPROM configuration
1913 1.10 dante * that was read.
1914 1.10 dante *
1915 1.16 dante * This is the mapping of EEPROM fields to Adw Library fields.
1916 1.10 dante */
1917 1.10 dante sc->wdtr_able = eep_config.wdtr_able;
1918 1.10 dante sc->sdtr_able = eep_config.sdtr_able;
1919 1.10 dante sc->ultra_able = eep_config.ultra_able;
1920 1.10 dante sc->tagqng_able = eep_config.tagqng_able;
1921 1.10 dante sc->cfg.disc_enable = eep_config.disc_enable;
1922 1.10 dante sc->max_host_qng = eep_config.max_host_qng;
1923 1.10 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1924 1.10 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
1925 1.10 dante sc->start_motor = eep_config.start_motor;
1926 1.10 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
1927 1.10 dante sc->bios_ctrl = eep_config.bios_ctrl;
1928 1.10 dante sc->no_scam = eep_config.scam_tolerant;
1929 1.10 dante sc->cfg.serial1 = eep_config.serial_number_word1;
1930 1.10 dante sc->cfg.serial2 = eep_config.serial_number_word2;
1931 1.10 dante sc->cfg.serial3 = eep_config.serial_number_word3;
1932 1.10 dante
1933 1.10 dante /*
1934 1.10 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
1935 1.10 dante * maximum queuing (max. 63, min. 4).
1936 1.10 dante */
1937 1.16 dante if (eep_config.max_host_qng > ADW_DEF_MAX_HOST_QNG) {
1938 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
1939 1.16 dante } else if (eep_config.max_host_qng < ADW_DEF_MIN_HOST_QNG)
1940 1.10 dante {
1941 1.10 dante /* If the value is zero, assume it is uninitialized. */
1942 1.10 dante if (eep_config.max_host_qng == 0) {
1943 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
1944 1.10 dante } else {
1945 1.16 dante eep_config.max_host_qng = ADW_DEF_MIN_HOST_QNG;
1946 1.10 dante }
1947 1.10 dante }
1948 1.10 dante
1949 1.16 dante if (eep_config.max_dvc_qng > ADW_DEF_MAX_DVC_QNG) {
1950 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
1951 1.16 dante } else if (eep_config.max_dvc_qng < ADW_DEF_MIN_DVC_QNG) {
1952 1.10 dante /* If the value is zero, assume it is uninitialized. */
1953 1.10 dante if (eep_config.max_dvc_qng == 0) {
1954 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
1955 1.10 dante } else {
1956 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MIN_DVC_QNG;
1957 1.10 dante }
1958 1.10 dante }
1959 1.10 dante
1960 1.10 dante /*
1961 1.10 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
1962 1.10 dante * set 'max_dvc_qng' to 'max_host_qng'.
1963 1.10 dante */
1964 1.10 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
1965 1.10 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
1966 1.10 dante }
1967 1.10 dante
1968 1.10 dante /*
1969 1.10 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
1970 1.10 dante * values based on possibly adjusted EEPROM values.
1971 1.10 dante */
1972 1.10 dante sc->max_host_qng = eep_config.max_host_qng;
1973 1.10 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1974 1.10 dante
1975 1.10 dante
1976 1.10 dante /*
1977 1.10 dante * If the EEPROM 'termination' field is set to automatic (0), then set
1978 1.10 dante * the ADV_DVC_CFG 'termination' field to automatic also.
1979 1.10 dante *
1980 1.10 dante * If the termination is specified with a non-zero 'termination'
1981 1.10 dante * value check that a legal value is set and set the ADV_DVC_CFG
1982 1.10 dante * 'termination' field appropriately.
1983 1.10 dante */
1984 1.10 dante
1985 1.10 dante sc->cfg.termination = 0; /* auto termination */
1986 1.10 dante switch(eep_config.termination) {
1987 1.10 dante case 3:
1988 1.10 dante /* Enable manual control with low on / high on. */
1989 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_L;
1990 1.10 dante case 2:
1991 1.10 dante /* Enable manual control with low off / high on. */
1992 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_H;
1993 1.10 dante case 1:
1994 1.10 dante /* Enable manual control with low off / high off. */
1995 1.10 dante sc->cfg.termination |= ADW_TERM_CTL_SEL;
1996 1.10 dante case 0:
1997 1.10 dante break;
1998 1.10 dante default:
1999 1.16 dante warn_code |= ADW_WARN_EEPROM_TERMINATION;
2000 1.7 dante }
2001 1.7 dante
2002 1.7 dante return warn_code;
2003 1.7 dante }
2004 1.7 dante
2005 1.7 dante
2006 1.7 dante /*
2007 1.7 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
2008 1.7 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
2009 1.7 dante * all of this is done.
2010 1.7 dante *
2011 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
2012 1.7 dante *
2013 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
2014 1.7 dante * then 0 is returned.
2015 1.7 dante *
2016 1.7 dante * Note: Chip is stopped on entry.
2017 1.7 dante */
2018 1.7 dante int
2019 1.16 dante AdwInitFrom38C0800EEP(sc)
2020 1.7 dante ADW_SOFTC *sc;
2021 1.7 dante {
2022 1.7 dante bus_space_tag_t iot = sc->sc_iot;
2023 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
2024 1.7 dante u_int16_t warn_code;
2025 1.10 dante ADW_EEP_38C0800_CONFIG eep_config;
2026 1.7 dante int i;
2027 1.10 dante u_int8_t tid, termination;
2028 1.10 dante u_int16_t sdtr_speed = 0;
2029 1.7 dante
2030 1.7 dante
2031 1.7 dante warn_code = 0;
2032 1.7 dante
2033 1.7 dante /*
2034 1.7 dante * Read the board's EEPROM configuration.
2035 1.7 dante *
2036 1.7 dante * Set default values if a bad checksum is found.
2037 1.7 dante */
2038 1.16 dante if (AdwGet38C0800EEPConfig(iot, ioh, &eep_config) !=
2039 1.10 dante eep_config.check_sum) {
2040 1.16 dante warn_code |= ADW_WARN_EEPROM_CHKSUM;
2041 1.7 dante
2042 1.7 dante /*
2043 1.7 dante * Set EEPROM default values.
2044 1.7 dante */
2045 1.10 dante for (i = 0; i < sizeof(ADW_EEP_38C0800_CONFIG); i++) {
2046 1.7 dante *((u_int8_t *) &eep_config + i) =
2047 1.10 dante *((u_int8_t *)&Default_38C0800_EEPROM_Config+i);
2048 1.7 dante }
2049 1.7 dante
2050 1.7 dante /*
2051 1.7 dante * Assume the 6 byte board serial number that was read
2052 1.7 dante * from EEPROM is correct even if the EEPROM checksum
2053 1.7 dante * failed.
2054 1.7 dante */
2055 1.7 dante eep_config.serial_number_word3 =
2056 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
2057 1.7 dante
2058 1.7 dante eep_config.serial_number_word2 =
2059 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
2060 1.7 dante
2061 1.7 dante eep_config.serial_number_word1 =
2062 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
2063 1.7 dante
2064 1.16 dante AdwSet38C0800EEPConfig(iot, ioh, &eep_config);
2065 1.7 dante }
2066 1.7 dante /*
2067 1.10 dante * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
2068 1.7 dante * EEPROM configuration that was read.
2069 1.7 dante *
2070 1.16 dante * This is the mapping of EEPROM fields to Adw Library fields.
2071 1.7 dante */
2072 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
2073 1.10 dante sc->sdtr_speed1 = eep_config.sdtr_speed1;
2074 1.10 dante sc->sdtr_speed2 = eep_config.sdtr_speed2;
2075 1.10 dante sc->sdtr_speed3 = eep_config.sdtr_speed3;
2076 1.10 dante sc->sdtr_speed4 = eep_config.sdtr_speed4;
2077 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
2078 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
2079 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2080 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2081 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
2082 1.7 dante sc->start_motor = eep_config.start_motor;
2083 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
2084 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
2085 1.7 dante sc->no_scam = eep_config.scam_tolerant;
2086 1.7 dante sc->cfg.serial1 = eep_config.serial_number_word1;
2087 1.7 dante sc->cfg.serial2 = eep_config.serial_number_word2;
2088 1.7 dante sc->cfg.serial3 = eep_config.serial_number_word3;
2089 1.7 dante
2090 1.7 dante /*
2091 1.10 dante * For every Target ID if any of its 'sdtr_speed[1234]' bits
2092 1.10 dante * are set, then set an 'sdtr_able' bit for it.
2093 1.10 dante */
2094 1.10 dante sc->sdtr_able = 0;
2095 1.10 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
2096 1.10 dante if (tid == 0) {
2097 1.10 dante sdtr_speed = sc->sdtr_speed1;
2098 1.10 dante } else if (tid == 4) {
2099 1.10 dante sdtr_speed = sc->sdtr_speed2;
2100 1.10 dante } else if (tid == 8) {
2101 1.10 dante sdtr_speed = sc->sdtr_speed3;
2102 1.10 dante } else if (tid == 12) {
2103 1.10 dante sdtr_speed = sc->sdtr_speed4;
2104 1.10 dante }
2105 1.10 dante if (sdtr_speed & ADW_MAX_TID) {
2106 1.10 dante sc->sdtr_able |= (1 << tid);
2107 1.10 dante }
2108 1.10 dante sdtr_speed >>= 4;
2109 1.10 dante }
2110 1.10 dante
2111 1.10 dante /*
2112 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
2113 1.7 dante * maximum queuing (max. 63, min. 4).
2114 1.7 dante */
2115 1.16 dante if (eep_config.max_host_qng > ADW_DEF_MAX_HOST_QNG) {
2116 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
2117 1.16 dante } else if (eep_config.max_host_qng < ADW_DEF_MIN_HOST_QNG) {
2118 1.7 dante /* If the value is zero, assume it is uninitialized. */
2119 1.7 dante if (eep_config.max_host_qng == 0) {
2120 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
2121 1.7 dante } else {
2122 1.16 dante eep_config.max_host_qng = ADW_DEF_MIN_HOST_QNG;
2123 1.7 dante }
2124 1.7 dante }
2125 1.7 dante
2126 1.16 dante if (eep_config.max_dvc_qng > ADW_DEF_MAX_DVC_QNG) {
2127 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
2128 1.16 dante } else if (eep_config.max_dvc_qng < ADW_DEF_MIN_DVC_QNG) {
2129 1.7 dante /* If the value is zero, assume it is uninitialized. */
2130 1.7 dante if (eep_config.max_dvc_qng == 0) {
2131 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
2132 1.7 dante } else {
2133 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MIN_DVC_QNG;
2134 1.7 dante }
2135 1.7 dante }
2136 1.7 dante
2137 1.7 dante /*
2138 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
2139 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
2140 1.7 dante */
2141 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
2142 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
2143 1.7 dante }
2144 1.7 dante
2145 1.7 dante /*
2146 1.7 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
2147 1.7 dante * values based on possibly adjusted EEPROM values.
2148 1.7 dante */
2149 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2150 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2151 1.7 dante
2152 1.7 dante /*
2153 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
2154 1.7 dante * the ADV_DVC_CFG 'termination' field to automatic also.
2155 1.7 dante *
2156 1.7 dante * If the termination is specified with a non-zero 'termination'
2157 1.7 dante * value check that a legal value is set and set the ADV_DVC_CFG
2158 1.7 dante * 'termination' field appropriately.
2159 1.7 dante */
2160 1.10 dante
2161 1.10 dante switch(eep_config.termination_se) {
2162 1.10 dante case 0:
2163 1.10 dante /* auto termination for SE */
2164 1.10 dante termination = 0;
2165 1.10 dante break;
2166 1.10 dante case 1:
2167 1.7 dante /* Enable manual control with low off / high off. */
2168 1.10 dante termination = 0;
2169 1.10 dante break;
2170 1.10 dante case 2:
2171 1.10 dante /* Enable manual control with low off / high on. */
2172 1.10 dante termination = ADW_TERM_SE_HI;
2173 1.10 dante break;
2174 1.10 dante case 3:
2175 1.10 dante /* Enable manual control with low on / high on. */
2176 1.10 dante termination = ADW_TERM_SE;
2177 1.10 dante break;
2178 1.10 dante default:
2179 1.10 dante /*
2180 1.10 dante * The EEPROM 'termination_se' field contains a bad value.
2181 1.10 dante * Use automatic termination instead.
2182 1.10 dante */
2183 1.10 dante termination = 0;
2184 1.16 dante warn_code |= ADW_WARN_EEPROM_TERMINATION;
2185 1.10 dante }
2186 1.7 dante
2187 1.10 dante switch(eep_config.termination_lvd) {
2188 1.10 dante case 0:
2189 1.10 dante /* auto termination for LVD */
2190 1.10 dante sc->cfg.termination = termination;
2191 1.10 dante break;
2192 1.10 dante case 1:
2193 1.10 dante /* Enable manual control with low off / high off. */
2194 1.10 dante sc->cfg.termination = termination;
2195 1.10 dante break;
2196 1.10 dante case 2:
2197 1.7 dante /* Enable manual control with low off / high on. */
2198 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD_HI;
2199 1.10 dante break;
2200 1.10 dante case 3:
2201 1.7 dante /* Enable manual control with low on / high on. */
2202 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD;
2203 1.10 dante break;
2204 1.10 dante default:
2205 1.10 dante /*
2206 1.10 dante * The EEPROM 'termination_lvd' field contains a bad value.
2207 1.10 dante * Use automatic termination instead.
2208 1.10 dante */
2209 1.10 dante sc->cfg.termination = termination;
2210 1.16 dante warn_code |= ADW_WARN_EEPROM_TERMINATION;
2211 1.7 dante }
2212 1.7 dante
2213 1.7 dante return warn_code;
2214 1.7 dante }
2215 1.7 dante
2216 1.7 dante
2217 1.7 dante /*
2218 1.10 dante * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
2219 1.10 dante * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
2220 1.7 dante * all of this is done.
2221 1.7 dante *
2222 1.10 dante * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
2223 1.7 dante *
2224 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
2225 1.7 dante * then 0 is returned.
2226 1.7 dante *
2227 1.7 dante * Note: Chip is stopped on entry.
2228 1.7 dante */
2229 1.7 dante int
2230 1.16 dante AdwInitFrom38C1600EEP(sc)
2231 1.7 dante ADW_SOFTC *sc;
2232 1.7 dante {
2233 1.7 dante bus_space_tag_t iot = sc->sc_iot;
2234 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
2235 1.7 dante u_int16_t warn_code;
2236 1.10 dante ADW_EEP_38C1600_CONFIG eep_config;
2237 1.7 dante int i;
2238 1.7 dante u_int8_t tid, termination;
2239 1.7 dante u_int16_t sdtr_speed = 0;
2240 1.7 dante
2241 1.7 dante
2242 1.7 dante warn_code = 0;
2243 1.7 dante
2244 1.7 dante /*
2245 1.7 dante * Read the board's EEPROM configuration.
2246 1.7 dante *
2247 1.7 dante * Set default values if a bad checksum is found.
2248 1.7 dante */
2249 1.16 dante if (AdwGet38C1600EEPConfig(iot, ioh, &eep_config) !=
2250 1.7 dante eep_config.check_sum) {
2251 1.16 dante warn_code |= ADW_WARN_EEPROM_CHKSUM;
2252 1.7 dante
2253 1.7 dante /*
2254 1.7 dante * Set EEPROM default values.
2255 1.7 dante */
2256 1.10 dante for (i = 0; i < sizeof(ADW_EEP_38C1600_CONFIG); i++) {
2257 1.10 dante /* !!!!TODO!!!! */
2258 1.10 dante // if (i == 1 && ASC_PCI_ID2FUNC(sc->cfg.pci_slot_info) != 0) {
2259 1.10 dante if (i == 1 ) {
2260 1.10 dante /*
2261 1.10 dante * Set Function 1 EEPROM Word 0 MSB
2262 1.10 dante *
2263 1.10 dante * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
2264 1.10 dante * EEPROM bits.
2265 1.10 dante *
2266 1.10 dante * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
2267 1.10 dante * old Mac system booting problem. The Expansion ROM must
2268 1.10 dante * be disabled in Function 1 for these systems.
2269 1.10 dante *
2270 1.10 dante */
2271 1.10 dante *((u_int8_t *) &eep_config + i) =
2272 1.10 dante ((*((u_int8_t *) &Default_38C1600_EEPROM_Config + i)) &
2273 1.10 dante (~(((ADW_EEPROM_BIOS_ENABLE | ADW_EEPROM_INTAB) >> 8) &
2274 1.10 dante 0xFF)));
2275 1.10 dante
2276 1.10 dante /*
2277 1.10 dante * Set the INTAB (bit 11) if the GPIO 0 input
2278 1.10 dante * indicates the Function 1 interrupt line is
2279 1.10 dante * wired to INTA.
2280 1.10 dante *
2281 1.10 dante * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
2282 1.10 dante * 1 - Function 1 interrupt line wired to INT A.
2283 1.10 dante * 0 - Function 1 interrupt line wired to INT B.
2284 1.10 dante *
2285 1.10 dante * Note: Adapter boards always have Function 0
2286 1.10 dante * wired to INTA.
2287 1.10 dante * Put all 5 GPIO bits in input mode and then
2288 1.10 dante * read their input values.
2289 1.10 dante */
2290 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
2291 1.10 dante IOPB_GPIO_CNTL, 0);
2292 1.10 dante if (ADW_READ_BYTE_REGISTER(iot, ioh,
2293 1.10 dante IOPB_GPIO_DATA) & 0x01) {
2294 1.10 dante /* Function 1 interrupt wired to INTA;
2295 1.10 dante Set EEPROM bit. */
2296 1.10 dante *((u_int8_t *) &eep_config + i) |=
2297 1.10 dante ((ADW_EEPROM_INTAB >> 8) &0xFF);
2298 1.10 dante }
2299 1.10 dante } else {
2300 1.10 dante *((u_int8_t *)&eep_config + i) =
2301 1.10 dante *((u_int8_t *)&Default_38C1600_EEPROM_Config+i);
2302 1.10 dante }
2303 1.7 dante }
2304 1.7 dante
2305 1.7 dante /*
2306 1.7 dante * Assume the 6 byte board serial number that was read
2307 1.7 dante * from EEPROM is correct even if the EEPROM checksum
2308 1.7 dante * failed.
2309 1.7 dante */
2310 1.7 dante eep_config.serial_number_word3 =
2311 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
2312 1.7 dante
2313 1.7 dante eep_config.serial_number_word2 =
2314 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
2315 1.7 dante
2316 1.7 dante eep_config.serial_number_word1 =
2317 1.16 dante AdwReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
2318 1.7 dante
2319 1.16 dante AdwSet38C1600EEPConfig(iot, ioh, &eep_config);
2320 1.7 dante }
2321 1.10 dante
2322 1.7 dante /*
2323 1.10 dante * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
2324 1.7 dante * EEPROM configuration that was read.
2325 1.7 dante *
2326 1.16 dante * This is the mapping of EEPROM fields to Adw Library fields.
2327 1.7 dante */
2328 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
2329 1.7 dante sc->sdtr_speed1 = eep_config.sdtr_speed1;
2330 1.7 dante sc->sdtr_speed2 = eep_config.sdtr_speed2;
2331 1.7 dante sc->sdtr_speed3 = eep_config.sdtr_speed3;
2332 1.7 dante sc->sdtr_speed4 = eep_config.sdtr_speed4;
2333 1.10 dante sc->ppr_able = 0;
2334 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
2335 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
2336 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2337 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2338 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
2339 1.7 dante sc->start_motor = eep_config.start_motor;
2340 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
2341 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
2342 1.7 dante sc->no_scam = eep_config.scam_tolerant;
2343 1.7 dante
2344 1.7 dante /*
2345 1.7 dante * For every Target ID if any of its 'sdtr_speed[1234]' bits
2346 1.7 dante * are set, then set an 'sdtr_able' bit for it.
2347 1.7 dante */
2348 1.7 dante sc->sdtr_able = 0;
2349 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
2350 1.7 dante if (tid == 0) {
2351 1.7 dante sdtr_speed = sc->sdtr_speed1;
2352 1.7 dante } else if (tid == 4) {
2353 1.7 dante sdtr_speed = sc->sdtr_speed2;
2354 1.7 dante } else if (tid == 8) {
2355 1.7 dante sdtr_speed = sc->sdtr_speed3;
2356 1.7 dante } else if (tid == 12) {
2357 1.7 dante sdtr_speed = sc->sdtr_speed4;
2358 1.7 dante }
2359 1.7 dante if (sdtr_speed & ADW_MAX_TID) {
2360 1.7 dante sc->sdtr_able |= (1 << tid);
2361 1.7 dante }
2362 1.7 dante sdtr_speed >>= 4;
2363 1.7 dante }
2364 1.7 dante
2365 1.7 dante /*
2366 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
2367 1.7 dante * maximum queuing (max. 63, min. 4).
2368 1.7 dante */
2369 1.16 dante if (eep_config.max_host_qng > ADW_DEF_MAX_HOST_QNG) {
2370 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
2371 1.16 dante } else if (eep_config.max_host_qng < ADW_DEF_MIN_HOST_QNG) {
2372 1.7 dante /* If the value is zero, assume it is uninitialized. */
2373 1.7 dante if (eep_config.max_host_qng == 0) {
2374 1.16 dante eep_config.max_host_qng = ADW_DEF_MAX_HOST_QNG;
2375 1.7 dante } else {
2376 1.16 dante eep_config.max_host_qng = ADW_DEF_MIN_HOST_QNG;
2377 1.7 dante }
2378 1.7 dante }
2379 1.7 dante
2380 1.16 dante if (eep_config.max_dvc_qng > ADW_DEF_MAX_DVC_QNG) {
2381 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
2382 1.16 dante } else if (eep_config.max_dvc_qng < ADW_DEF_MIN_DVC_QNG) {
2383 1.7 dante /* If the value is zero, assume it is uninitialized. */
2384 1.7 dante if (eep_config.max_dvc_qng == 0) {
2385 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MAX_DVC_QNG;
2386 1.7 dante } else {
2387 1.16 dante eep_config.max_dvc_qng = ADW_DEF_MIN_DVC_QNG;
2388 1.7 dante }
2389 1.7 dante }
2390 1.7 dante
2391 1.7 dante /*
2392 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
2393 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
2394 1.7 dante */
2395 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
2396 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
2397 1.7 dante }
2398 1.7 dante
2399 1.7 dante /*
2400 1.10 dante * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
2401 1.7 dante * values based on possibly adjusted EEPROM values.
2402 1.7 dante */
2403 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
2404 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
2405 1.7 dante
2406 1.7 dante /*
2407 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
2408 1.10 dante * the ASC_DVC_CFG 'termination' field to automatic also.
2409 1.7 dante *
2410 1.7 dante * If the termination is specified with a non-zero 'termination'
2411 1.10 dante * value check that a legal value is set and set the ASC_DVC_CFG
2412 1.7 dante * 'termination' field appropriately.
2413 1.7 dante */
2414 1.7 dante
2415 1.10 dante switch(eep_config.termination_se) {
2416 1.10 dante case 0: /* auto termination for SE */
2417 1.10 dante termination = 0;
2418 1.10 dante break;
2419 1.10 dante case 1: /* Enable manual control with low off / high off. */
2420 1.10 dante termination = 0;
2421 1.10 dante break;
2422 1.10 dante case 2: /* Enable manual control with low off / high on. */
2423 1.10 dante termination = ADW_TERM_SE_HI;
2424 1.10 dante break;
2425 1.10 dante case 3: /* Enable manual control with low on / high on. */
2426 1.10 dante termination = ADW_TERM_SE;
2427 1.10 dante break;
2428 1.10 dante default:
2429 1.10 dante /*
2430 1.10 dante * The EEPROM 'termination_se' field contains a bad value.
2431 1.10 dante * Use automatic termination instead.
2432 1.10 dante */
2433 1.10 dante termination = 0;
2434 1.16 dante warn_code |= ADW_WARN_EEPROM_TERMINATION;
2435 1.7 dante }
2436 1.7 dante
2437 1.10 dante switch(eep_config.termination_lvd) {
2438 1.10 dante case 0: /* auto termination for LVD */
2439 1.10 dante sc->cfg.termination = termination;
2440 1.10 dante break;
2441 1.10 dante case 1: /* Enable manual control with low off / high off. */
2442 1.10 dante sc->cfg.termination = termination;
2443 1.10 dante break;
2444 1.10 dante case 2: /* Enable manual control with low off / high on. */
2445 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD_HI;
2446 1.10 dante break;
2447 1.10 dante case 3: /* Enable manual control with low on / high on. */
2448 1.10 dante sc->cfg.termination = termination | ADW_TERM_LVD;
2449 1.10 dante break;
2450 1.10 dante default:
2451 1.10 dante /*
2452 1.10 dante * The EEPROM 'termination_lvd' field contains a bad value.
2453 1.10 dante * Use automatic termination instead.
2454 1.10 dante */
2455 1.7 dante sc->cfg.termination = termination;
2456 1.16 dante warn_code |= ADW_WARN_EEPROM_TERMINATION;
2457 1.7 dante }
2458 1.7 dante
2459 1.7 dante return warn_code;
2460 1.7 dante }
2461 1.7 dante
2462 1.7 dante
2463 1.7 dante /*
2464 1.7 dante * Read EEPROM configuration into the specified buffer.
2465 1.7 dante *
2466 1.7 dante * Return a checksum based on the EEPROM configuration read.
2467 1.7 dante */
2468 1.7 dante static u_int16_t
2469 1.16 dante AdwGet3550EEPConfig(iot, ioh, cfg_buf)
2470 1.7 dante bus_space_tag_t iot;
2471 1.7 dante bus_space_handle_t ioh;
2472 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
2473 1.7 dante {
2474 1.7 dante u_int16_t wval, chksum;
2475 1.7 dante u_int16_t *wbuf;
2476 1.7 dante int eep_addr;
2477 1.7 dante
2478 1.7 dante
2479 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2480 1.7 dante chksum = 0;
2481 1.7 dante
2482 1.7 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2483 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2484 1.10 dante eep_addr++, wbuf++) {
2485 1.16 dante wval = AdwReadEEPWord(iot, ioh, eep_addr);
2486 1.7 dante chksum += wval;
2487 1.7 dante *wbuf = wval;
2488 1.7 dante }
2489 1.7 dante
2490 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2491 1.7 dante wbuf++;
2492 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2493 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2494 1.7 dante eep_addr++, wbuf++) {
2495 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2496 1.7 dante }
2497 1.7 dante
2498 1.7 dante return chksum;
2499 1.7 dante }
2500 1.7 dante
2501 1.7 dante
2502 1.7 dante /*
2503 1.7 dante * Read EEPROM configuration into the specified buffer.
2504 1.7 dante *
2505 1.7 dante * Return a checksum based on the EEPROM configuration read.
2506 1.7 dante */
2507 1.7 dante static u_int16_t
2508 1.16 dante AdwGet38C0800EEPConfig(iot, ioh, cfg_buf)
2509 1.7 dante bus_space_tag_t iot;
2510 1.7 dante bus_space_handle_t ioh;
2511 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
2512 1.7 dante {
2513 1.7 dante u_int16_t wval, chksum;
2514 1.7 dante u_int16_t *wbuf;
2515 1.7 dante int eep_addr;
2516 1.7 dante
2517 1.7 dante
2518 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2519 1.7 dante chksum = 0;
2520 1.1 dante
2521 1.1 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2522 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2523 1.10 dante eep_addr++, wbuf++) {
2524 1.16 dante wval = AdwReadEEPWord(iot, ioh, eep_addr);
2525 1.10 dante chksum += wval;
2526 1.10 dante *wbuf = wval;
2527 1.10 dante }
2528 1.10 dante
2529 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2530 1.10 dante wbuf++;
2531 1.10 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2532 1.10 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2533 1.7 dante eep_addr++, wbuf++) {
2534 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2535 1.10 dante }
2536 1.10 dante
2537 1.10 dante return chksum;
2538 1.10 dante }
2539 1.10 dante
2540 1.10 dante
2541 1.10 dante /*
2542 1.10 dante * Read EEPROM configuration into the specified buffer.
2543 1.10 dante *
2544 1.10 dante * Return a checksum based on the EEPROM configuration read.
2545 1.10 dante */
2546 1.10 dante static u_int16_t
2547 1.16 dante AdwGet38C1600EEPConfig(iot, ioh, cfg_buf)
2548 1.10 dante bus_space_tag_t iot;
2549 1.10 dante bus_space_handle_t ioh;
2550 1.10 dante ADW_EEP_38C1600_CONFIG *cfg_buf;
2551 1.10 dante {
2552 1.10 dante u_int16_t wval, chksum;
2553 1.10 dante u_int16_t *wbuf;
2554 1.10 dante int eep_addr;
2555 1.10 dante
2556 1.10 dante
2557 1.10 dante wbuf = (u_int16_t *) cfg_buf;
2558 1.10 dante chksum = 0;
2559 1.10 dante
2560 1.10 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
2561 1.10 dante eep_addr < ASC_EEP_DVC_CFG_END;
2562 1.10 dante eep_addr++, wbuf++) {
2563 1.16 dante wval = AdwReadEEPWord(iot, ioh, eep_addr);
2564 1.1 dante chksum += wval;
2565 1.1 dante *wbuf = wval;
2566 1.1 dante }
2567 1.7 dante
2568 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2569 1.1 dante wbuf++;
2570 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
2571 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
2572 1.7 dante eep_addr++, wbuf++) {
2573 1.16 dante *wbuf = AdwReadEEPWord(iot, ioh, eep_addr);
2574 1.7 dante }
2575 1.7 dante
2576 1.7 dante return chksum;
2577 1.7 dante }
2578 1.7 dante
2579 1.7 dante
2580 1.7 dante /*
2581 1.7 dante * Read the EEPROM from specified location
2582 1.7 dante */
2583 1.7 dante static u_int16_t
2584 1.16 dante AdwReadEEPWord(iot, ioh, eep_word_addr)
2585 1.7 dante bus_space_tag_t iot;
2586 1.7 dante bus_space_handle_t ioh;
2587 1.7 dante int eep_word_addr;
2588 1.7 dante {
2589 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2590 1.7 dante ASC_EEP_CMD_READ | eep_word_addr);
2591 1.16 dante AdwWaitEEPCmd(iot, ioh);
2592 1.7 dante
2593 1.7 dante return ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_DATA);
2594 1.7 dante }
2595 1.7 dante
2596 1.7 dante
2597 1.7 dante /*
2598 1.7 dante * Wait for EEPROM command to complete
2599 1.7 dante */
2600 1.7 dante static void
2601 1.16 dante AdwWaitEEPCmd(iot, ioh)
2602 1.7 dante bus_space_tag_t iot;
2603 1.7 dante bus_space_handle_t ioh;
2604 1.7 dante {
2605 1.7 dante int eep_delay_ms;
2606 1.7 dante
2607 1.7 dante
2608 1.7 dante for (eep_delay_ms = 0; eep_delay_ms < ASC_EEP_DELAY_MS; eep_delay_ms++){
2609 1.7 dante if (ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD) &
2610 1.7 dante ASC_EEP_CMD_DONE) {
2611 1.7 dante break;
2612 1.7 dante }
2613 1.16 dante AdwSleepMilliSecond(1);
2614 1.7 dante }
2615 1.7 dante
2616 1.7 dante ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD);
2617 1.7 dante }
2618 1.7 dante
2619 1.7 dante
2620 1.7 dante /*
2621 1.7 dante * Write the EEPROM from 'cfg_buf'.
2622 1.7 dante */
2623 1.7 dante static void
2624 1.16 dante AdwSet3550EEPConfig(iot, ioh, cfg_buf)
2625 1.7 dante bus_space_tag_t iot;
2626 1.7 dante bus_space_handle_t ioh;
2627 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
2628 1.7 dante {
2629 1.7 dante u_int16_t *wbuf;
2630 1.7 dante u_int16_t addr, chksum;
2631 1.7 dante
2632 1.7 dante
2633 1.7 dante wbuf = (u_int16_t *) cfg_buf;
2634 1.7 dante chksum = 0;
2635 1.7 dante
2636 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2637 1.16 dante AdwWaitEEPCmd(iot, ioh);
2638 1.7 dante
2639 1.7 dante /*
2640 1.7 dante * Write EEPROM from word 0 to word 20
2641 1.7 dante */
2642 1.7 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2643 1.7 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2644 1.7 dante chksum += *wbuf;
2645 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2646 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2647 1.7 dante ASC_EEP_CMD_WRITE | addr);
2648 1.16 dante AdwWaitEEPCmd(iot, ioh);
2649 1.16 dante AdwSleepMilliSecond(ASC_EEP_DELAY_MS);
2650 1.7 dante }
2651 1.7 dante
2652 1.7 dante /*
2653 1.7 dante * Write EEPROM checksum at word 21
2654 1.7 dante */
2655 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2656 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2657 1.7 dante ASC_EEP_CMD_WRITE | addr);
2658 1.16 dante AdwWaitEEPCmd(iot, ioh);
2659 1.7 dante wbuf++; /* skip over check_sum */
2660 1.7 dante
2661 1.7 dante /*
2662 1.7 dante * Write EEPROM OEM name at words 22 to 29
2663 1.7 dante */
2664 1.7 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2665 1.7 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2666 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2667 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2668 1.7 dante ASC_EEP_CMD_WRITE | addr);
2669 1.16 dante AdwWaitEEPCmd(iot, ioh);
2670 1.1 dante }
2671 1.1 dante
2672 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2673 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
2674 1.16 dante AdwWaitEEPCmd(iot, ioh);
2675 1.1 dante
2676 1.1 dante return;
2677 1.1 dante }
2678 1.1 dante
2679 1.7 dante
2680 1.1 dante /*
2681 1.1 dante * Write the EEPROM from 'cfg_buf'.
2682 1.1 dante */
2683 1.1 dante static void
2684 1.16 dante AdwSet38C0800EEPConfig(iot, ioh, cfg_buf)
2685 1.7 dante bus_space_tag_t iot;
2686 1.7 dante bus_space_handle_t ioh;
2687 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
2688 1.1 dante {
2689 1.7 dante u_int16_t *wbuf;
2690 1.7 dante u_int16_t addr, chksum;
2691 1.7 dante
2692 1.1 dante
2693 1.1 dante wbuf = (u_int16_t *) cfg_buf;
2694 1.1 dante chksum = 0;
2695 1.1 dante
2696 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2697 1.16 dante AdwWaitEEPCmd(iot, ioh);
2698 1.1 dante
2699 1.1 dante /*
2700 1.7 dante * Write EEPROM from word 0 to word 20
2701 1.1 dante */
2702 1.1 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2703 1.2 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2704 1.1 dante chksum += *wbuf;
2705 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2706 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2707 1.7 dante ASC_EEP_CMD_WRITE | addr);
2708 1.16 dante AdwWaitEEPCmd(iot, ioh);
2709 1.16 dante AdwSleepMilliSecond(ASC_EEP_DELAY_MS);
2710 1.1 dante }
2711 1.1 dante
2712 1.1 dante /*
2713 1.7 dante * Write EEPROM checksum at word 21
2714 1.1 dante */
2715 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2716 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2717 1.7 dante ASC_EEP_CMD_WRITE | addr);
2718 1.16 dante AdwWaitEEPCmd(iot, ioh);
2719 1.7 dante wbuf++; /* skip over check_sum */
2720 1.1 dante
2721 1.1 dante /*
2722 1.7 dante * Write EEPROM OEM name at words 22 to 29
2723 1.1 dante */
2724 1.1 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2725 1.2 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2726 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2727 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2728 1.7 dante ASC_EEP_CMD_WRITE | addr);
2729 1.16 dante AdwWaitEEPCmd(iot, ioh);
2730 1.1 dante }
2731 1.7 dante
2732 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2733 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
2734 1.16 dante AdwWaitEEPCmd(iot, ioh);
2735 1.7 dante
2736 1.1 dante return;
2737 1.1 dante }
2738 1.1 dante
2739 1.7 dante
2740 1.1 dante /*
2741 1.10 dante * Write the EEPROM from 'cfg_buf'.
2742 1.10 dante */
2743 1.10 dante static void
2744 1.16 dante AdwSet38C1600EEPConfig(iot, ioh, cfg_buf)
2745 1.10 dante bus_space_tag_t iot;
2746 1.10 dante bus_space_handle_t ioh;
2747 1.10 dante ADW_EEP_38C1600_CONFIG *cfg_buf;
2748 1.10 dante {
2749 1.10 dante u_int16_t *wbuf;
2750 1.10 dante u_int16_t addr, chksum;
2751 1.10 dante
2752 1.10 dante
2753 1.10 dante wbuf = (u_int16_t *) cfg_buf;
2754 1.10 dante chksum = 0;
2755 1.10 dante
2756 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
2757 1.16 dante AdwWaitEEPCmd(iot, ioh);
2758 1.10 dante
2759 1.10 dante /*
2760 1.10 dante * Write EEPROM from word 0 to word 20
2761 1.10 dante */
2762 1.10 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
2763 1.10 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
2764 1.10 dante chksum += *wbuf;
2765 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2766 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2767 1.10 dante ASC_EEP_CMD_WRITE | addr);
2768 1.16 dante AdwWaitEEPCmd(iot, ioh);
2769 1.16 dante AdwSleepMilliSecond(ASC_EEP_DELAY_MS);
2770 1.10 dante }
2771 1.10 dante
2772 1.10 dante /*
2773 1.10 dante * Write EEPROM checksum at word 21
2774 1.10 dante */
2775 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
2776 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2777 1.10 dante ASC_EEP_CMD_WRITE | addr);
2778 1.16 dante AdwWaitEEPCmd(iot, ioh);
2779 1.10 dante wbuf++; /* skip over check_sum */
2780 1.10 dante
2781 1.10 dante /*
2782 1.10 dante * Write EEPROM OEM name at words 22 to 29
2783 1.10 dante */
2784 1.10 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
2785 1.10 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
2786 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
2787 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2788 1.10 dante ASC_EEP_CMD_WRITE | addr);
2789 1.16 dante AdwWaitEEPCmd(iot, ioh);
2790 1.10 dante }
2791 1.10 dante
2792 1.10 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
2793 1.10 dante ASC_EEP_CMD_WRITE_DISABLE);
2794 1.16 dante AdwWaitEEPCmd(iot, ioh);
2795 1.10 dante
2796 1.10 dante return;
2797 1.10 dante }
2798 1.10 dante
2799 1.10 dante
2800 1.10 dante /*
2801 1.16 dante * AdwExeScsiQueue() - Send a request to the RISC microcode program.
2802 1.7 dante *
2803 1.7 dante * Allocate a carrier structure, point the carrier to the ADW_SCSI_REQ_Q,
2804 1.7 dante * add the carrier to the ICQ (Initiator Command Queue), and tickle the
2805 1.7 dante * RISC to notify it a new command is ready to be executed.
2806 1.1 dante *
2807 1.7 dante * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
2808 1.7 dante * set to SCSI_MAX_RETRY.
2809 1.1 dante *
2810 1.7 dante * Return:
2811 1.7 dante * ADW_SUCCESS(1) - The request was successfully queued.
2812 1.7 dante * ADW_BUSY(0) - Resource unavailable; Retry again after pending
2813 1.7 dante * request completes.
2814 1.7 dante * ADW_ERROR(-1) - Invalid ADW_SCSI_REQ_Q request structure
2815 1.7 dante * host IC error.
2816 1.1 dante */
2817 1.7 dante int
2818 1.16 dante AdwExeScsiQueue(sc, scsiq)
2819 1.7 dante ADW_SOFTC *sc;
2820 1.7 dante ADW_SCSI_REQ_Q *scsiq;
2821 1.1 dante {
2822 1.7 dante bus_space_tag_t iot = sc->sc_iot;
2823 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
2824 1.7 dante ADW_CCB *ccb;
2825 1.7 dante long req_size;
2826 1.7 dante u_int32_t req_paddr;
2827 1.10 dante ADW_CARRIER *new_carrp;
2828 1.7 dante
2829 1.7 dante /*
2830 1.7 dante * The ADW_SCSI_REQ_Q 'target_id' field should never exceed ADW_MAX_TID.
2831 1.7 dante */
2832 1.7 dante if (scsiq->target_id > ADW_MAX_TID) {
2833 1.7 dante scsiq->host_status = QHSTA_M_INVALID_DEVICE;
2834 1.7 dante scsiq->done_status = QD_WITH_ERROR;
2835 1.7 dante return ADW_ERROR;
2836 1.7 dante }
2837 1.7 dante
2838 1.10 dante /*
2839 1.10 dante * Begin of CRITICAL SECTION: Must be protected within splbio/splx pair
2840 1.10 dante */
2841 1.10 dante
2842 1.7 dante ccb = adw_ccb_phys_kv(sc, scsiq->ccb_ptr);
2843 1.7 dante
2844 1.7 dante /*
2845 1.16 dante * Allocate a carrier and initialize fields.
2846 1.7 dante */
2847 1.7 dante if ((new_carrp = sc->carr_freelist) == NULL) {
2848 1.7 dante return ADW_BUSY;
2849 1.7 dante }
2850 1.16 dante sc->carr_freelist = ADW_CARRIER_VADDR(sc,
2851 1.12 dante ASC_GET_CARRP(new_carrp->next_ba));
2852 1.7 dante sc->carr_pending_cnt++;
2853 1.7 dante
2854 1.7 dante /*
2855 1.12 dante * Set the carrier to be a stopper by setting 'next_ba'
2856 1.7 dante * to the stopper value. The current stopper will be changed
2857 1.7 dante * below to point to the new stopper.
2858 1.7 dante */
2859 1.12 dante new_carrp->next_ba = ASC_CQ_STOPPER;
2860 1.7 dante
2861 1.7 dante req_size = sizeof(ADW_SCSI_REQ_Q);
2862 1.7 dante req_paddr = sc->sc_dmamap_control->dm_segs[0].ds_addr +
2863 1.7 dante ADW_CCB_OFF(ccb) + offsetof(struct adw_ccb, scsiq);
2864 1.7 dante
2865 1.7 dante /* Save physical address of ADW_SCSI_REQ_Q and Carrier. */
2866 1.7 dante scsiq->scsiq_rptr = req_paddr;
2867 1.7 dante
2868 1.7 dante /*
2869 1.12 dante * Every ADV_CARR_T.carr_ba is byte swapped to little-endian
2870 1.7 dante * order during initialization.
2871 1.7 dante */
2872 1.12 dante scsiq->carr_ba = sc->icq_sp->carr_ba;
2873 1.12 dante scsiq->carr_va = sc->icq_sp->carr_ba;
2874 1.1 dante
2875 1.7 dante /*
2876 1.7 dante * Use the current stopper to send the ADW_SCSI_REQ_Q command to
2877 1.7 dante * the microcode. The newly allocated stopper will become the new
2878 1.7 dante * stopper.
2879 1.7 dante */
2880 1.12 dante sc->icq_sp->areq_ba = req_paddr;
2881 1.1 dante
2882 1.1 dante /*
2883 1.12 dante * Set the 'next_ba' pointer for the old stopper to be the
2884 1.7 dante * physical address of the new stopper. The RISC can only
2885 1.7 dante * follow physical addresses.
2886 1.1 dante */
2887 1.12 dante sc->icq_sp->next_ba = new_carrp->carr_ba;
2888 1.1 dante
2889 1.12 dante #if ADW_DEBUG
2890 1.12 dante printf("icq 0x%x, 0x%x, 0x%x, 0x%x\n",
2891 1.12 dante sc->icq_sp->carr_id,
2892 1.12 dante sc->icq_sp->carr_ba,
2893 1.12 dante sc->icq_sp->areq_ba,
2894 1.12 dante sc->icq_sp->next_ba);
2895 1.12 dante #endif
2896 1.1 dante /*
2897 1.7 dante * Set the host adapter stopper pointer to point to the new carrier.
2898 1.1 dante */
2899 1.7 dante sc->icq_sp = new_carrp;
2900 1.11 dante
2901 1.16 dante if (sc->chip_type == ADW_CHIP_ASC3550 ||
2902 1.16 dante sc->chip_type == ADW_CHIP_ASC38C0800) {
2903 1.7 dante /*
2904 1.10 dante * Tickle the RISC to tell it to read its Command Queue Head
2905 1.10 dante * pointer.
2906 1.10 dante */
2907 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_A);
2908 1.16 dante if (sc->chip_type == ADW_CHIP_ASC3550) {
2909 1.10 dante /*
2910 1.10 dante * Clear the tickle value. In the ASC-3550 the RISC flag
2911 1.10 dante * command 'clr_tickle_a' does not work unless the host
2912 1.10 dante * value is cleared.
2913 1.10 dante */
2914 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE,
2915 1.10 dante ADV_TICKLE_NOP);
2916 1.10 dante }
2917 1.16 dante } else if (sc->chip_type == ADW_CHIP_ASC38C1600) {
2918 1.10 dante /*
2919 1.10 dante * Notify the RISC a carrier is ready by writing the physical
2920 1.10 dante * address of the new carrier stopper to the COMMA register.
2921 1.7 dante */
2922 1.10 dante ADW_WRITE_DWORD_REGISTER(iot, ioh, IOPDW_COMMA,
2923 1.12 dante new_carrp->carr_ba);
2924 1.7 dante }
2925 1.7 dante
2926 1.10 dante /*
2927 1.10 dante * End of CRITICAL SECTION: Must be protected within splbio/splx pair
2928 1.10 dante */
2929 1.10 dante
2930 1.7 dante return ADW_SUCCESS;
2931 1.1 dante }
2932 1.1 dante
2933 1.7 dante
2934 1.7 dante void
2935 1.16 dante AdwResetChip(iot, ioh)
2936 1.7 dante bus_space_tag_t iot;
2937 1.7 dante bus_space_handle_t ioh;
2938 1.1 dante {
2939 1.7 dante
2940 1.7 dante /*
2941 1.7 dante * Reset Chip.
2942 1.7 dante */
2943 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2944 1.7 dante ADW_CTRL_REG_CMD_RESET);
2945 1.16 dante AdwSleepMilliSecond(100);
2946 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2947 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
2948 1.1 dante }
2949 1.1 dante
2950 1.7 dante
2951 1.1 dante /*
2952 1.1 dante * Reset SCSI Bus and purge all outstanding requests.
2953 1.1 dante *
2954 1.1 dante * Return Value:
2955 1.7 dante * ADW_TRUE(1) - All requests are purged and SCSI Bus is reset.
2956 1.7 dante * ADW_FALSE(0) - Microcode command failed.
2957 1.7 dante * ADW_ERROR(-1) - Microcode command timed-out. Microcode or IC
2958 1.7 dante * may be hung which requires driver recovery.
2959 1.1 dante */
2960 1.1 dante int
2961 1.16 dante AdwResetCCB(sc)
2962 1.7 dante ADW_SOFTC *sc;
2963 1.1 dante {
2964 1.7 dante int status;
2965 1.7 dante
2966 1.7 dante /*
2967 1.7 dante * Send the SCSI Bus Reset idle start idle command which asserts
2968 1.7 dante * the SCSI Bus Reset signal.
2969 1.7 dante */
2970 1.16 dante status = AdwSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_START, 0L);
2971 1.11 dante if (status != ADW_TRUE) {
2972 1.7 dante return status;
2973 1.7 dante }
2974 1.7 dante
2975 1.7 dante /*
2976 1.7 dante * Delay for the specified SCSI Bus Reset hold time.
2977 1.7 dante *
2978 1.7 dante * The hold time delay is done on the host because the RISC has no
2979 1.7 dante * microsecond accurate timer.
2980 1.7 dante */
2981 1.16 dante AdwDelayMicroSecond((u_int16_t) ASC_SCSI_RESET_HOLD_TIME_US);
2982 1.1 dante
2983 1.7 dante /*
2984 1.7 dante * Send the SCSI Bus Reset end idle command which de-asserts
2985 1.7 dante * the SCSI Bus Reset signal and purges any pending requests.
2986 1.7 dante */
2987 1.16 dante status = AdwSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_END, 0L);
2988 1.11 dante if (status != ADW_TRUE) {
2989 1.7 dante return status;
2990 1.7 dante }
2991 1.1 dante
2992 1.16 dante AdwSleepMilliSecond((u_int32_t) sc->scsi_reset_wait * 1000);
2993 1.1 dante
2994 1.1 dante return status;
2995 1.1 dante }
2996 1.1 dante
2997 1.7 dante
2998 1.1 dante /*
2999 1.7 dante * Reset chip and SCSI Bus.
3000 1.7 dante *
3001 1.7 dante * Return Value:
3002 1.7 dante * ADW_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
3003 1.7 dante * ADW_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
3004 1.1 dante */
3005 1.7 dante int
3006 1.16 dante AdwResetSCSIBus(sc)
3007 1.7 dante ADW_SOFTC *sc;
3008 1.1 dante {
3009 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3010 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3011 1.7 dante int status;
3012 1.10 dante u_int16_t wdtr_able, sdtr_able, ppr_able, tagqng_able;
3013 1.7 dante u_int8_t tid, max_cmd[ADW_MAX_TID + 1];
3014 1.7 dante u_int16_t bios_sig;
3015 1.7 dante
3016 1.7 dante
3017 1.7 dante /*
3018 1.7 dante * Save current per TID negotiated values.
3019 1.7 dante */
3020 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, wdtr_able);
3021 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sdtr_able);
3022 1.16 dante if (sc->chip_type == ADW_CHIP_ASC38C1600) {
3023 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE, ppr_able);
3024 1.10 dante }
3025 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE, tagqng_able);
3026 1.11 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
3027 1.16 dante ADW_READ_BYTE_LRAM(iot, ioh, ADW_MC_NUMBER_OF_MAX_CMD + tid,
3028 1.7 dante max_cmd[tid]);
3029 1.7 dante }
3030 1.7 dante
3031 1.7 dante /*
3032 1.16 dante * Force the AdwInitAsc3550/38C0800Driver() function to
3033 1.7 dante * perform a SCSI Bus Reset by clearing the BIOS signature word.
3034 1.7 dante * The initialization functions assumes a SCSI Bus Reset is not
3035 1.7 dante * needed if the BIOS signature word is present.
3036 1.7 dante */
3037 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_BIOS_SIGNATURE, bios_sig);
3038 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_BIOS_SIGNATURE, 0);
3039 1.7 dante
3040 1.7 dante /*
3041 1.7 dante * Stop chip and reset it.
3042 1.7 dante */
3043 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_STOP);
3044 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
3045 1.7 dante ADW_CTRL_REG_CMD_RESET);
3046 1.16 dante AdwSleepMilliSecond(100);
3047 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
3048 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
3049 1.7 dante
3050 1.7 dante /*
3051 1.7 dante * Reset Adv Library error code, if any, and try
3052 1.7 dante * re-initializing the chip.
3053 1.7 dante */
3054 1.16 dante if (sc->chip_type == ADW_CHIP_ASC38C1600) {
3055 1.16 dante status = AdwInitAsc38C1600Driver(sc);
3056 1.16 dante } else if (sc->chip_type == ADW_CHIP_ASC38C0800) {
3057 1.16 dante status = AdwInitAsc38C0800Driver(sc);
3058 1.7 dante } else {
3059 1.16 dante status = AdwInitAsc3550Driver(sc);
3060 1.7 dante }
3061 1.1 dante
3062 1.7 dante /* Translate initialization return value to status value. */
3063 1.13 dante status = (status == 0)? ADW_TRUE : ADW_FALSE;
3064 1.1 dante
3065 1.7 dante /*
3066 1.7 dante * Restore the BIOS signature word.
3067 1.7 dante */
3068 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_BIOS_SIGNATURE, bios_sig);
3069 1.1 dante
3070 1.1 dante /*
3071 1.7 dante * Restore per TID negotiated values.
3072 1.1 dante */
3073 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE, wdtr_able);
3074 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, sdtr_able);
3075 1.16 dante if (sc->chip_type == ADW_CHIP_ASC38C1600) {
3076 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE, ppr_able);
3077 1.10 dante }
3078 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE, tagqng_able);
3079 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
3080 1.16 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ADW_MC_NUMBER_OF_MAX_CMD + tid,
3081 1.7 dante max_cmd[tid]);
3082 1.7 dante }
3083 1.1 dante
3084 1.7 dante return status;
3085 1.1 dante }
3086 1.1 dante
3087 1.1 dante
3088 1.1 dante /*
3089 1.1 dante * Adv Library Interrupt Service Routine
3090 1.1 dante *
3091 1.1 dante * This function is called by a driver's interrupt service routine.
3092 1.1 dante * The function disables and re-enables interrupts.
3093 1.1 dante *
3094 1.7 dante * When a microcode idle command is completed, the ADV_DVC_VAR
3095 1.1 dante * 'idle_cmd_done' field is set to ADW_TRUE.
3096 1.1 dante *
3097 1.16 dante * Note: AdwISR() can be called when interrupts are disabled or even
3098 1.1 dante * when there is no hardware interrupt condition present. It will
3099 1.1 dante * always check for completed idle commands and microcode requests.
3100 1.1 dante * This is an important feature that shouldn't be changed because it
3101 1.1 dante * allows commands to be completed from polling mode loops.
3102 1.1 dante *
3103 1.1 dante * Return:
3104 1.1 dante * ADW_TRUE(1) - interrupt was pending
3105 1.1 dante * ADW_FALSE(0) - no interrupt was pending
3106 1.1 dante */
3107 1.1 dante int
3108 1.16 dante AdwISR(sc)
3109 1.7 dante ADW_SOFTC *sc;
3110 1.1 dante {
3111 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3112 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3113 1.7 dante u_int8_t int_stat;
3114 1.7 dante u_int16_t target_bit;
3115 1.7 dante ADW_CARRIER *free_carrp/*, *ccb_carr*/;
3116 1.7 dante u_int32_t irq_next_pa;
3117 1.7 dante ADW_SCSI_REQ_Q *scsiq;
3118 1.7 dante ADW_CCB *ccb;
3119 1.11 dante int s;
3120 1.11 dante
3121 1.1 dante
3122 1.11 dante s = splbio();
3123 1.1 dante
3124 1.1 dante /* Reading the register clears the interrupt. */
3125 1.1 dante int_stat = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_INTR_STATUS_REG);
3126 1.1 dante
3127 1.7 dante if ((int_stat & (ADW_INTR_STATUS_INTRA | ADW_INTR_STATUS_INTRB |
3128 1.7 dante ADW_INTR_STATUS_INTRC)) == 0) {
3129 1.11 dante splx(s);
3130 1.7 dante return ADW_FALSE;
3131 1.1 dante }
3132 1.7 dante
3133 1.7 dante /*
3134 1.7 dante * Notify the driver of an asynchronous microcode condition by
3135 1.7 dante * calling the ADV_DVC_VAR.async_callback function. The function
3136 1.16 dante * is passed the microcode ADW_MC_INTRB_CODE byte value.
3137 1.1 dante */
3138 1.7 dante if (int_stat & ADW_INTR_STATUS_INTRB) {
3139 1.7 dante u_int8_t intrb_code;
3140 1.7 dante
3141 1.16 dante ADW_READ_BYTE_LRAM(iot, ioh, ADW_MC_INTRB_CODE, intrb_code);
3142 1.10 dante
3143 1.16 dante if (sc->chip_type == ADW_CHIP_ASC3550 ||
3144 1.16 dante sc->chip_type == ADW_CHIP_ASC38C0800) {
3145 1.10 dante if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
3146 1.10 dante sc->carr_pending_cnt != 0) {
3147 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
3148 1.10 dante IOPB_TICKLE, ADV_TICKLE_A);
3149 1.16 dante if (sc->chip_type == ADW_CHIP_ASC3550) {
3150 1.10 dante ADW_WRITE_BYTE_REGISTER(iot, ioh,
3151 1.10 dante IOPB_TICKLE, ADV_TICKLE_NOP);
3152 1.10 dante }
3153 1.10 dante }
3154 1.7 dante }
3155 1.7 dante
3156 1.7 dante if (sc->async_callback != 0) {
3157 1.7 dante (*(ADW_ASYNC_CALLBACK)sc->async_callback)(sc, intrb_code);
3158 1.1 dante }
3159 1.1 dante }
3160 1.7 dante
3161 1.1 dante /*
3162 1.7 dante * Check if the IRQ stopper carrier contains a completed request.
3163 1.1 dante */
3164 1.12 dante while (((irq_next_pa = sc->irq_sp->next_ba) & ASC_RQ_DONE) != 0)
3165 1.7 dante {
3166 1.12 dante #if ADW_DEBUG
3167 1.12 dante printf("irq 0x%x, 0x%x, 0x%x, 0x%x\n",
3168 1.12 dante sc->irq_sp->carr_id,
3169 1.12 dante sc->irq_sp->carr_ba,
3170 1.12 dante sc->irq_sp->areq_ba,
3171 1.12 dante sc->irq_sp->next_ba);
3172 1.12 dante #endif
3173 1.7 dante /*
3174 1.10 dante * Get a pointer to the newly completed ADW_SCSI_REQ_Q
3175 1.10 dante * structure.
3176 1.12 dante * The RISC will have set 'areq_ba' to a virtual address.
3177 1.7 dante *
3178 1.7 dante * The firmware will have copied the ASC_SCSI_REQ_Q.ccb_ptr
3179 1.12 dante * field to the carrier ADV_CARR_T.areq_ba field.
3180 1.10 dante * The conversion below complements the conversion of
3181 1.16 dante * ASC_SCSI_REQ_Q.scsiq_ptr' in AdwExeScsiQueue().
3182 1.7 dante */
3183 1.12 dante ccb = adw_ccb_phys_kv(sc, sc->irq_sp->areq_ba);
3184 1.7 dante scsiq = &ccb->scsiq;
3185 1.12 dante scsiq->ccb_ptr = sc->irq_sp->areq_ba;
3186 1.7 dante
3187 1.10 dante /*
3188 1.10 dante * Request finished with good status and the queue was not
3189 1.10 dante * DMAed to host memory by the firmware. Set all status fields
3190 1.10 dante * to indicate good status.
3191 1.10 dante */
3192 1.10 dante if ((irq_next_pa & ASC_RQ_GOOD) != 0) {
3193 1.10 dante scsiq->done_status = QD_NO_ERROR;
3194 1.10 dante scsiq->host_status = scsiq->scsi_status = 0;
3195 1.10 dante scsiq->data_cnt = 0L;
3196 1.7 dante }
3197 1.1 dante
3198 1.1 dante /*
3199 1.7 dante * Advance the stopper pointer to the next carrier
3200 1.7 dante * ignoring the lower four bits. Free the previous
3201 1.7 dante * stopper carrier.
3202 1.1 dante */
3203 1.7 dante free_carrp = sc->irq_sp;
3204 1.16 dante sc->irq_sp = ADW_CARRIER_VADDR(sc, ASC_GET_CARRP(irq_next_pa));
3205 1.7 dante
3206 1.16 dante free_carrp->next_ba = (sc->carr_freelist == NULL)? NULL
3207 1.16 dante : sc->carr_freelist->carr_ba;
3208 1.7 dante sc->carr_freelist = free_carrp;
3209 1.7 dante sc->carr_pending_cnt--;
3210 1.1 dante
3211 1.1 dante
3212 1.1 dante target_bit = ADW_TID_TO_TIDMASK(scsiq->target_id);
3213 1.1 dante
3214 1.1 dante /*
3215 1.1 dante * Clear request microcode control flag.
3216 1.1 dante */
3217 1.1 dante scsiq->cntl = 0;
3218 1.1 dante
3219 1.1 dante /*
3220 1.1 dante * Check Condition handling
3221 1.1 dante */
3222 1.1 dante /*
3223 1.1 dante * If the command that completed was a SCSI INQUIRY and
3224 1.1 dante * LUN 0 was sent the command, then process the INQUIRY
3225 1.1 dante * command information for the device.
3226 1.1 dante */
3227 1.7 dante if (scsiq->done_status == QD_NO_ERROR &&
3228 1.10 dante scsiq->cdb[0] == INQUIRY &&
3229 1.10 dante scsiq->target_lun == 0) {
3230 1.16 dante AdwInquiryHandling(sc, scsiq);
3231 1.1 dante }
3232 1.1 dante
3233 1.1 dante /*
3234 1.1 dante * Notify the driver of the completed request by passing
3235 1.1 dante * the ADW_SCSI_REQ_Q pointer to its callback function.
3236 1.1 dante */
3237 1.7 dante (*(ADW_ISR_CALLBACK)sc->isr_callback)(sc, scsiq);
3238 1.1 dante /*
3239 1.1 dante * Note: After the driver callback function is called, 'scsiq'
3240 1.1 dante * can no longer be referenced.
3241 1.1 dante *
3242 1.1 dante * Fall through and continue processing other completed
3243 1.1 dante * requests...
3244 1.1 dante */
3245 1.1 dante }
3246 1.11 dante
3247 1.11 dante splx(s);
3248 1.7 dante
3249 1.7 dante return ADW_TRUE;
3250 1.1 dante }
3251 1.1 dante
3252 1.7 dante
3253 1.1 dante /*
3254 1.1 dante * Send an idle command to the chip and wait for completion.
3255 1.1 dante *
3256 1.7 dante * Command completion is polled for once per microsecond.
3257 1.7 dante *
3258 1.7 dante * The function can be called from anywhere including an interrupt handler.
3259 1.10 dante * But the function is not re-entrant, so it uses the splbio/splx()
3260 1.7 dante * functions to prevent reentrancy.
3261 1.1 dante *
3262 1.1 dante * Return Values:
3263 1.1 dante * ADW_TRUE - command completed successfully
3264 1.1 dante * ADW_FALSE - command failed
3265 1.7 dante * ADW_ERROR - command timed out
3266 1.1 dante */
3267 1.1 dante int
3268 1.16 dante AdwSendIdleCmd(sc, idle_cmd, idle_cmd_parameter)
3269 1.7 dante ADW_SOFTC *sc;
3270 1.7 dante u_int16_t idle_cmd;
3271 1.7 dante u_int32_t idle_cmd_parameter;
3272 1.1 dante {
3273 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3274 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3275 1.13 dante u_int16_t result;
3276 1.10 dante u_int32_t i, j, s;
3277 1.1 dante
3278 1.10 dante s = splbio();
3279 1.7 dante
3280 1.7 dante /*
3281 1.7 dante * Clear the idle command status which is set by the microcode
3282 1.7 dante * to a non-zero value to indicate when the command is completed.
3283 1.7 dante */
3284 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_IDLE_CMD_STATUS, (u_int16_t) 0);
3285 1.1 dante
3286 1.1 dante /*
3287 1.1 dante * Write the idle command value after the idle command parameter
3288 1.1 dante * has been written to avoid a race condition. If the order is not
3289 1.1 dante * followed, the microcode may process the idle command before the
3290 1.1 dante * parameters have been written to LRAM.
3291 1.1 dante */
3292 1.16 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ADW_MC_IDLE_CMD_PARAMETER,
3293 1.13 dante idle_cmd_parameter);
3294 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_IDLE_CMD, idle_cmd);
3295 1.1 dante
3296 1.1 dante /*
3297 1.7 dante * Tickle the RISC to tell it to process the idle command.
3298 1.1 dante */
3299 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_B);
3300 1.16 dante if (sc->chip_type == ADW_CHIP_ASC3550) {
3301 1.1 dante /*
3302 1.7 dante * Clear the tickle value. In the ASC-3550 the RISC flag
3303 1.7 dante * command 'clr_tickle_b' does not work unless the host
3304 1.7 dante * value is cleared.
3305 1.1 dante */
3306 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_NOP);
3307 1.7 dante }
3308 1.1 dante
3309 1.7 dante /* Wait for up to 100 millisecond for the idle command to timeout. */
3310 1.7 dante for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
3311 1.7 dante /* Poll once each microsecond for command completion. */
3312 1.7 dante for (j = 0; j < SCSI_US_PER_MSEC; j++) {
3313 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_IDLE_CMD_STATUS, result);
3314 1.7 dante if (result != 0) {
3315 1.10 dante splx(s);
3316 1.7 dante return result;
3317 1.7 dante }
3318 1.16 dante AdwDelayMicroSecond(1);
3319 1.7 dante }
3320 1.1 dante }
3321 1.1 dante
3322 1.10 dante splx(s);
3323 1.7 dante return ADW_ERROR;
3324 1.1 dante }
3325 1.1 dante
3326 1.1 dante
3327 1.1 dante /*
3328 1.1 dante * Inquiry Information Byte 7 Handling
3329 1.1 dante *
3330 1.1 dante * Handle SCSI Inquiry Command information for a device by setting
3331 1.2 dante * microcode operating variables that affect WDTR, SDTR, and Tag
3332 1.1 dante * Queuing.
3333 1.1 dante */
3334 1.1 dante static void
3335 1.16 dante AdwInquiryHandling(sc, scsiq)
3336 1.7 dante ADW_SOFTC *sc;
3337 1.7 dante ADW_SCSI_REQ_Q *scsiq;
3338 1.1 dante {
3339 1.9 dante #ifndef FAILSAFE
3340 1.2 dante bus_space_tag_t iot = sc->sc_iot;
3341 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
3342 1.7 dante u_int8_t tid;
3343 1.13 dante struct scsipi_inquiry_data *inq;
3344 1.7 dante u_int16_t tidmask;
3345 1.7 dante u_int16_t cfg_word;
3346 1.7 dante
3347 1.1 dante
3348 1.1 dante /*
3349 1.16 dante * AdwInquiryHandling() requires up to INQUIRY information Byte 7
3350 1.1 dante * to be available.
3351 1.1 dante *
3352 1.1 dante * If less than 8 bytes of INQUIRY information were requested or less
3353 1.1 dante * than 8 bytes were transferred, then return. cdb[4] is the request
3354 1.1 dante * length and the ADW_SCSI_REQ_Q 'data_cnt' field is set by the
3355 1.1 dante * microcode to the transfer residual count.
3356 1.1 dante */
3357 1.7 dante
3358 1.2 dante if (scsiq->cdb[4] < 8 || (scsiq->cdb[4] - scsiq->data_cnt) < 8) {
3359 1.1 dante return;
3360 1.1 dante }
3361 1.7 dante
3362 1.1 dante tid = scsiq->target_id;
3363 1.7 dante
3364 1.13 dante inq = (struct scsipi_inquiry_data *) scsiq->vdata_addr;
3365 1.1 dante
3366 1.1 dante /*
3367 1.1 dante * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
3368 1.1 dante */
3369 1.13 dante if (((inq->response_format & SID_RespDataFmt) < 2) /*SCSI-1 | CCS*/ &&
3370 1.13 dante ((inq->version & SID_ANSII) < 2)) {
3371 1.1 dante return;
3372 1.2 dante } else {
3373 1.1 dante /*
3374 1.1 dante * INQUIRY Byte 7 Handling
3375 1.1 dante *
3376 1.1 dante * Use a device's INQUIRY byte 7 to determine whether it
3377 1.1 dante * supports WDTR, SDTR, and Tag Queuing. If the feature
3378 1.1 dante * is enabled in the EEPROM and the device supports the
3379 1.1 dante * feature, then enable it in the microcode.
3380 1.1 dante */
3381 1.1 dante
3382 1.1 dante tidmask = ADW_TID_TO_TIDMASK(tid);
3383 1.7 dante
3384 1.1 dante /*
3385 1.1 dante * Wide Transfers
3386 1.1 dante *
3387 1.1 dante * If the EEPROM enabled WDTR for the device and the device
3388 1.1 dante * supports wide bus (16 bit) transfers, then turn on the
3389 1.1 dante * device's 'wdtr_able' bit and write the new value to the
3390 1.1 dante * microcode.
3391 1.1 dante */
3392 1.7 dante #ifdef SCSI_ADW_WDTR_DISABLE
3393 1.8 dante if(!(tidmask & SCSI_ADW_WDTR_DISABLE))
3394 1.7 dante #endif /* SCSI_ADW_WDTR_DISABLE */
3395 1.13 dante if ((sc->wdtr_able & tidmask) && (inq->flags3 & SID_WBus16)) {
3396 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
3397 1.7 dante cfg_word);
3398 1.2 dante if ((cfg_word & tidmask) == 0) {
3399 1.1 dante cfg_word |= tidmask;
3400 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_ABLE,
3401 1.7 dante cfg_word);
3402 1.1 dante
3403 1.1 dante /*
3404 1.16 dante * Clear the microcode "SDTR negotiation" and
3405 1.16 dante * "WDTR negotiation" done indicators for the
3406 1.16 dante * target to cause it to negotiate with the new
3407 1.16 dante * setting set above.
3408 1.7 dante * WDTR when accepted causes the target to enter
3409 1.16 dante * asynchronous mode, so SDTR must be negotiated
3410 1.1 dante */
3411 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_DONE,
3412 1.7 dante cfg_word);
3413 1.7 dante cfg_word &= ~tidmask;
3414 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_DONE,
3415 1.7 dante cfg_word);
3416 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_WDTR_DONE,
3417 1.7 dante cfg_word);
3418 1.1 dante cfg_word &= ~tidmask;
3419 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_WDTR_DONE,
3420 1.7 dante cfg_word);
3421 1.1 dante }
3422 1.1 dante }
3423 1.7 dante
3424 1.1 dante /*
3425 1.1 dante * Synchronous Transfers
3426 1.1 dante *
3427 1.1 dante * If the EEPROM enabled SDTR for the device and the device
3428 1.1 dante * supports synchronous transfers, then turn on the device's
3429 1.1 dante * 'sdtr_able' bit. Write the new value to the microcode.
3430 1.1 dante */
3431 1.7 dante #ifdef SCSI_ADW_SDTR_DISABLE
3432 1.8 dante if(!(tidmask & SCSI_ADW_SDTR_DISABLE))
3433 1.7 dante #endif /* SCSI_ADW_SDTR_DISABLE */
3434 1.13 dante if ((sc->sdtr_able & tidmask) && (inq->flags3 & SID_Sync)) {
3435 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE, cfg_word);
3436 1.2 dante if ((cfg_word & tidmask) == 0) {
3437 1.1 dante cfg_word |= tidmask;
3438 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_ABLE,
3439 1.7 dante cfg_word);
3440 1.1 dante
3441 1.1 dante /*
3442 1.16 dante * Clear the microcode "SDTR negotiation"
3443 1.16 dante * done indicator for the target to cause it
3444 1.16 dante * to negotiate with the new setting set above.
3445 1.1 dante */
3446 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_SDTR_DONE,
3447 1.7 dante cfg_word);
3448 1.1 dante cfg_word &= ~tidmask;
3449 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_SDTR_DONE,
3450 1.7 dante cfg_word);
3451 1.10 dante }
3452 1.10 dante }
3453 1.10 dante /*
3454 1.10 dante * If the Inquiry data included enough space for the SPI-3
3455 1.10 dante * Clocking field, then check if DT mode is supported.
3456 1.10 dante */
3457 1.16 dante if (sc->chip_type == ADW_CHIP_ASC38C1600 &&
3458 1.10 dante (scsiq->cdb[4] >= 57 ||
3459 1.10 dante (scsiq->cdb[4] - scsiq->data_cnt) >= 57)) {
3460 1.10 dante /*
3461 1.10 dante * PPR (Parallel Protocol Request) Capable
3462 1.10 dante *
3463 1.10 dante * If the device supports DT mode, then it must be
3464 1.10 dante * PPR capable.
3465 1.10 dante * The PPR message will be used in place of the SDTR
3466 1.10 dante * and WDTR messages to negotiate synchronous speed
3467 1.10 dante * and offset, transfer width, and protocol options.
3468 1.10 dante */
3469 1.15 dante if((inq->flags4 & SID_Clocking) & SID_CLOCKING_DT_ONLY){
3470 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE,
3471 1.10 dante sc->ppr_able);
3472 1.10 dante sc->ppr_able |= tidmask;
3473 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_PPR_ABLE,
3474 1.10 dante sc->ppr_able);
3475 1.1 dante }
3476 1.1 dante }
3477 1.7 dante
3478 1.1 dante /*
3479 1.7 dante * If the EEPROM enabled Tag Queuing for the device and the
3480 1.7 dante * device supports Tag Queueing, then turn on the device's
3481 1.1 dante * 'tagqng_enable' bit in the microcode and set the microcode
3482 1.7 dante * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
3483 1.1 dante * value.
3484 1.1 dante *
3485 1.1 dante * Tag Queuing is disabled for the BIOS which runs in polled
3486 1.1 dante * mode and would see no benefit from Tag Queuing. Also by
3487 1.1 dante * disabling Tag Queuing in the BIOS devices with Tag Queuing
3488 1.1 dante * bugs will at least work with the BIOS.
3489 1.1 dante */
3490 1.7 dante #ifdef SCSI_ADW_TAGQ_DISABLE
3491 1.8 dante if(!(tidmask & SCSI_ADW_TAGQ_DISABLE))
3492 1.7 dante #endif /* SCSI_ADW_TAGQ_DISABLE */
3493 1.13 dante if ((sc->tagqng_able & tidmask) && (inq->flags3 & SID_CmdQue)) {
3494 1.16 dante ADW_READ_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE,
3495 1.7 dante cfg_word);
3496 1.1 dante cfg_word |= tidmask;
3497 1.16 dante ADW_WRITE_WORD_LRAM(iot, ioh, ADW_MC_TAGQNG_ABLE,
3498 1.7 dante cfg_word);
3499 1.7 dante
3500 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
3501 1.16 dante ADW_MC_NUMBER_OF_MAX_CMD + tid,
3502 1.7 dante sc->max_dvc_qng);
3503 1.1 dante }
3504 1.9 dante }
3505 1.7 dante #endif /* FAILSAFE */
3506 1.1 dante }
3507 1.1 dante
3508 1.7 dante
3509 1.1 dante static void
3510 1.16 dante AdwSleepMilliSecond(n)
3511 1.7 dante u_int32_t n;
3512 1.1 dante {
3513 1.1 dante
3514 1.1 dante DELAY(n * 1000);
3515 1.1 dante }
3516 1.1 dante
3517 1.7 dante
3518 1.1 dante static void
3519 1.16 dante AdwDelayMicroSecond(n)
3520 1.7 dante u_int32_t n;
3521 1.1 dante {
3522 1.1 dante
3523 1.1 dante DELAY(n);
3524 1.1 dante }
3525 1.7 dante
3526