adwlib.c revision 1.9 1 1.9 dante /* $NetBSD: adwlib.c,v 1.9 2000/02/04 16:23:14 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.7 dante * Copyright (c) 1995-1999 Advanced System Products, Inc.
46 1.1 dante * All Rights Reserved.
47 1.1 dante *
48 1.1 dante * Redistribution and use in source and binary forms, with or without
49 1.1 dante * modification, are permitted provided that redistributions of source
50 1.1 dante * code retain the above copyright notice and this comment without
51 1.1 dante * modification.
52 1.1 dante */
53 1.1 dante
54 1.1 dante #include <sys/types.h>
55 1.1 dante #include <sys/param.h>
56 1.1 dante #include <sys/systm.h>
57 1.1 dante #include <sys/malloc.h>
58 1.1 dante #include <sys/kernel.h>
59 1.1 dante #include <sys/queue.h>
60 1.1 dante #include <sys/device.h>
61 1.1 dante
62 1.1 dante #include <machine/bus.h>
63 1.1 dante #include <machine/intr.h>
64 1.1 dante
65 1.1 dante #include <dev/scsipi/scsi_all.h>
66 1.1 dante #include <dev/scsipi/scsipi_all.h>
67 1.1 dante #include <dev/scsipi/scsiconf.h>
68 1.1 dante
69 1.7 dante #include <dev/pci/pcidevs.h>
70 1.7 dante
71 1.1 dante #include <vm/vm.h>
72 1.1 dante #include <vm/vm_param.h>
73 1.1 dante #include <vm/pmap.h>
74 1.1 dante
75 1.1 dante #include <dev/ic/adwlib.h>
76 1.1 dante #include <dev/ic/adw.h>
77 1.1 dante #include <dev/ic/adwmcode.h>
78 1.1 dante
79 1.1 dante
80 1.1 dante /* Static Functions */
81 1.1 dante
82 1.7 dante static u_int16_t AdvGet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
83 1.7 dante ADW_EEP_3550_CONFIG *));
84 1.7 dante static u_int16_t AdvGet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
85 1.7 dante ADW_EEP_38C0800_CONFIG *));
86 1.7 dante static u_int16_t AdvReadEEPWord __P((bus_space_tag_t, bus_space_handle_t, int));
87 1.1 dante static void AdvWaitEEPCmd __P((bus_space_tag_t, bus_space_handle_t));
88 1.7 dante static void AdvSet3550EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
89 1.7 dante ADW_EEP_3550_CONFIG *));
90 1.7 dante static void AdvSet38C0800EEPConfig __P((bus_space_tag_t, bus_space_handle_t,
91 1.7 dante ADW_EEP_38C0800_CONFIG *));
92 1.1 dante static void AdvInquiryHandling __P((ADW_SOFTC *, ADW_SCSI_REQ_Q *));
93 1.1 dante
94 1.7 dante static void AdvSleepMilliSecond __P((u_int32_t));
95 1.7 dante static void AdvDelayMicroSecond __P((u_int32_t));
96 1.1 dante
97 1.1 dante
98 1.1 dante /*
99 1.1 dante * EEPROM Configuration.
100 1.1 dante *
101 1.1 dante * All drivers should use this structure to set the default EEPROM
102 1.1 dante * configuration. The BIOS now uses this structure when it is built.
103 1.1 dante * Additional structure information can be found in advlib.h where
104 1.1 dante * the structure is defined.
105 1.1 dante */
106 1.7 dante static ADW_EEP_3550_CONFIG
107 1.7 dante Default_3550_EEPROM_Config = {
108 1.7 dante ADW_EEPROM_BIOS_ENABLE, /* cfg_lsw */
109 1.7 dante 0x0000, /* cfg_msw */
110 1.7 dante 0xFFFF, /* disc_enable */
111 1.7 dante 0xFFFF, /* wdtr_able */
112 1.7 dante 0xFFFF, /* sdtr_able */
113 1.7 dante 0xFFFF, /* start_motor */
114 1.7 dante 0xFFFF, /* tagqng_able */
115 1.7 dante 0xFFFF, /* bios_scan */
116 1.7 dante 0, /* scam_tolerant */
117 1.7 dante 7, /* adapter_scsi_id */
118 1.7 dante 0, /* bios_boot_delay */
119 1.7 dante 3, /* scsi_reset_delay */
120 1.7 dante 0, /* bios_id_lun */
121 1.7 dante 0, /* termination */
122 1.7 dante 0, /* reserved1 */
123 1.7 dante 0xFFE7, /* bios_ctrl */
124 1.7 dante 0xFFFF, /* ultra_able */
125 1.7 dante 0, /* reserved2 */
126 1.2 dante ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
127 1.2 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
128 1.7 dante 0, /* dvc_cntl */
129 1.7 dante 0, /* bug_fix */
130 1.7 dante 0, /* serial_number_word1 */
131 1.7 dante 0, /* serial_number_word2 */
132 1.7 dante 0, /* serial_number_word3 */
133 1.7 dante 0, /* check_sum */
134 1.2 dante {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* oem_name[16] */
135 1.7 dante 0, /* dvc_err_code */
136 1.7 dante 0, /* adv_err_code */
137 1.7 dante 0, /* adv_err_addr */
138 1.7 dante 0, /* saved_dvc_err_code */
139 1.7 dante 0, /* saved_adv_err_code */
140 1.7 dante 0, /* saved_adv_err_addr */
141 1.7 dante 0 /* num_of_err */
142 1.7 dante };
143 1.7 dante
144 1.7 dante static ADW_EEP_38C0800_CONFIG
145 1.7 dante Default_38C0800_EEPROM_Config = {
146 1.7 dante ADW_EEPROM_BIOS_ENABLE, /* 00 cfg_lsw */
147 1.7 dante 0x0000, /* 01 cfg_msw */
148 1.7 dante 0xFFFF, /* 02 disc_enable */
149 1.7 dante 0xFFFF, /* 03 wdtr_able */
150 1.7 dante 0x4444, /* 04 sdtr_speed1 */
151 1.7 dante 0xFFFF, /* 05 start_motor */
152 1.7 dante 0xFFFF, /* 06 tagqng_able */
153 1.7 dante 0xFFFF, /* 07 bios_scan */
154 1.7 dante 0, /* 08 scam_tolerant */
155 1.7 dante 7, /* 09 adapter_scsi_id */
156 1.7 dante 0, /* bios_boot_delay */
157 1.7 dante 3, /* 10 scsi_reset_delay */
158 1.7 dante 0, /* bios_id_lun */
159 1.7 dante 0, /* 11 termination_se */
160 1.7 dante 0, /* termination_lvd */
161 1.7 dante 0xFFE7, /* 12 bios_ctrl */
162 1.7 dante 0x4444, /* 13 sdtr_speed2 */
163 1.7 dante 0x4444, /* 14 sdtr_speed3 */
164 1.7 dante ASC_DEF_MAX_HOST_QNG, /* 15 max_host_qng */
165 1.7 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
166 1.7 dante 0, /* 16 dvc_cntl */
167 1.7 dante 0x4444, /* 17 sdtr_speed4 */
168 1.7 dante 0, /* 18 serial_number_word1 */
169 1.7 dante 0, /* 19 serial_number_word2 */
170 1.7 dante 0, /* 20 serial_number_word3 */
171 1.7 dante 0, /* 21 check_sum */
172 1.7 dante { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
173 1.7 dante 0, /* 30 dvc_err_code */
174 1.7 dante 0, /* 31 adv_err_code */
175 1.7 dante 0, /* 32 adv_err_addr */
176 1.7 dante 0, /* 33 saved_dvc_err_code */
177 1.7 dante 0, /* 34 saved_adv_err_code */
178 1.7 dante 0, /* 35 saved_adv_err_addr */
179 1.7 dante 0, /* 36 reserved */
180 1.7 dante 0, /* 37 reserved */
181 1.7 dante 0, /* 38 reserved */
182 1.7 dante 0, /* 39 reserved */
183 1.7 dante 0, /* 40 reserved */
184 1.7 dante 0, /* 41 reserved */
185 1.7 dante 0, /* 42 reserved */
186 1.7 dante 0, /* 43 reserved */
187 1.7 dante 0, /* 44 reserved */
188 1.7 dante 0, /* 45 reserved */
189 1.7 dante 0, /* 46 reserved */
190 1.7 dante 0, /* 47 reserved */
191 1.7 dante 0, /* 48 reserved */
192 1.7 dante 0, /* 49 reserved */
193 1.7 dante 0, /* 50 reserved */
194 1.7 dante 0, /* 51 reserved */
195 1.7 dante 0, /* 52 reserved */
196 1.7 dante 0, /* 53 reserved */
197 1.7 dante 0, /* 54 reserved */
198 1.7 dante 0, /* 55 reserved */
199 1.7 dante 0, /* 56 cisptr_lsw */
200 1.7 dante 0, /* 57 cisprt_msw */
201 1.7 dante PCI_VENDOR_ADVSYS, /* 58 subsysvid */
202 1.7 dante PCI_PRODUCT_ADVSYS_U2W, /* 59 subsysid */
203 1.7 dante 0, /* 60 reserved */
204 1.7 dante 0, /* 61 reserved */
205 1.7 dante 0, /* 62 reserved */
206 1.7 dante 0 /* 63 reserved */
207 1.1 dante };
208 1.1 dante
209 1.1 dante /*
210 1.1 dante * Initialize the ASC3550.
211 1.1 dante *
212 1.1 dante * On failure set the ADW_SOFTC field 'err_code' and return ADW_ERROR.
213 1.1 dante *
214 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
215 1.1 dante * then 0 is returned.
216 1.1 dante */
217 1.1 dante int
218 1.1 dante AdvInitAsc3550Driver(sc)
219 1.2 dante ADW_SOFTC *sc;
220 1.1 dante {
221 1.2 dante bus_space_tag_t iot = sc->sc_iot;
222 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
223 1.7 dante u_int16_t warn_code;
224 1.7 dante u_int32_t sum;
225 1.7 dante int begin_addr;
226 1.7 dante int end_addr;
227 1.7 dante u_int16_t code_sum;
228 1.7 dante int word;
229 1.7 dante int i, j;
230 1.7 dante int adv_asc3550_expanded_size;
231 1.7 dante u_int16_t scsi_cfg1;
232 1.7 dante u_int8_t tid;
233 1.7 dante u_int16_t bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory
234 1.7 dante 0x40-0x8F. */
235 1.7 dante u_int16_t wdtr_able = 0, sdtr_able, tagqng_able;
236 1.7 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
237 1.1 dante
238 1.1 dante
239 1.1 dante warn_code = 0;
240 1.1 dante
241 1.1 dante /*
242 1.1 dante * Save the RISC memory BIOS region before writing the microcode.
243 1.1 dante * The BIOS may already be loaded and using its RISC LRAM region
244 1.1 dante * so its region must be saved and restored.
245 1.1 dante *
246 1.1 dante * Note: This code makes the assumption, which is currently true,
247 1.1 dante * that a chip reset does not clear RISC LRAM.
248 1.1 dante */
249 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
250 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2*i), bios_mem[i]);
251 1.7 dante }
252 1.7 dante
253 1.7 dante /*
254 1.7 dante * Save current per TID negotiated values.
255 1.7 dante */
256 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA) {
257 1.7 dante
258 1.7 dante u_int16_t bios_version, major, minor;
259 1.7 dante
260 1.7 dante bios_version = bios_mem[(ASC_MC_BIOS_VERSION-ASC_MC_BIOSMEM)/2];
261 1.7 dante major = (bios_version >> 12) & 0xF;
262 1.7 dante minor = (bios_version >> 8) & 0xF;
263 1.7 dante if (major < 3 || (major == 3 && minor == 1)) {
264 1.7 dante /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
265 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, 0x120, wdtr_able);
266 1.7 dante } else {
267 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
268 1.7 dante }
269 1.7 dante }
270 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
271 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
272 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
273 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
274 1.7 dante max_cmd[tid]);
275 1.1 dante }
276 1.1 dante
277 1.1 dante /*
278 1.1 dante * Load the Microcode
279 1.1 dante *
280 1.1 dante * Write the microcode image to RISC memory starting at address 0.
281 1.1 dante */
282 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
283 1.7 dante
284 1.7 dante /* Assume the following compressed format of the microcode buffer:
285 1.7 dante *
286 1.7 dante * 254 word (508 byte) table indexed by byte code followed
287 1.7 dante * by the following byte codes:
288 1.7 dante *
289 1.7 dante * 1-Byte Code:
290 1.7 dante * 00: Emit word 0 in table.
291 1.7 dante * 01: Emit word 1 in table.
292 1.7 dante * .
293 1.7 dante * FD: Emit word 253 in table.
294 1.7 dante *
295 1.7 dante * Multi-Byte Code:
296 1.7 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
297 1.7 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
298 1.7 dante */
299 1.7 dante word = 0;
300 1.7 dante for (i = 253 * 2; i < adv_asc3550_mcode_size; i++) {
301 1.7 dante if (adv_asc3550_mcode[i] == 0xff) {
302 1.7 dante for (j = 0; j < adv_asc3550_mcode[i + 1]; j++) {
303 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
304 1.7 dante (((u_int16_t)adv_asc3550_mcode[i + 3] << 8) |
305 1.7 dante adv_asc3550_mcode[i + 2]));
306 1.7 dante word++;
307 1.7 dante }
308 1.7 dante i += 3;
309 1.7 dante } else if (adv_asc3550_mcode[i] == 0xfe) {
310 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
311 1.7 dante (((u_int16_t)adv_asc3550_mcode[i + 2] << 8) |
312 1.7 dante adv_asc3550_mcode[i + 1]));
313 1.7 dante i += 2;
314 1.7 dante word++;
315 1.7 dante } else {
316 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
317 1.7 dante adv_asc3550_mcode[(adv_asc3550_mcode[i] * 2) + 1] <<8) |
318 1.7 dante adv_asc3550_mcode[adv_asc3550_mcode[i] * 2]));
319 1.7 dante word++;
320 1.7 dante }
321 1.1 dante }
322 1.1 dante
323 1.1 dante /*
324 1.7 dante * Set 'word' for later use to clear the rest of memory and save
325 1.7 dante * the expanded mcode size.
326 1.7 dante */
327 1.7 dante word *= 2;
328 1.7 dante adv_asc3550_expanded_size = word;
329 1.7 dante
330 1.7 dante /*
331 1.7 dante * Clear the rest of ASC-3550 Internal RAM (8KB).
332 1.1 dante */
333 1.7 dante for (; word < ADV_3550_MEMSIZE; word += 2) {
334 1.1 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
335 1.1 dante }
336 1.1 dante
337 1.1 dante /*
338 1.1 dante * Verify the microcode checksum.
339 1.1 dante */
340 1.1 dante sum = 0;
341 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
342 1.7 dante
343 1.7 dante for (word = 0; word < adv_asc3550_expanded_size; word += 2) {
344 1.1 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
345 1.1 dante }
346 1.1 dante
347 1.7 dante if (sum != adv_asc3550_mcode_chksum) {
348 1.1 dante return ASC_IERR_MCODE_CHKSUM;
349 1.7 dante }
350 1.1 dante
351 1.1 dante /*
352 1.1 dante * Restore the RISC memory BIOS region.
353 1.1 dante */
354 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
355 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i),
356 1.7 dante bios_mem[i]);
357 1.1 dante }
358 1.1 dante
359 1.1 dante /*
360 1.1 dante * Calculate and write the microcode code checksum to the microcode
361 1.2 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
362 1.1 dante */
363 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
364 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
365 1.1 dante code_sum = 0;
366 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
367 1.1 dante for (word = begin_addr; word < end_addr; word += 2) {
368 1.7 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
369 1.1 dante }
370 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
371 1.1 dante
372 1.1 dante /*
373 1.7 dante * Read and save microcode version and date.
374 1.1 dante */
375 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE,
376 1.7 dante sc->cfg.mcode_date);
377 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM,
378 1.7 dante sc->cfg.mcode_version);
379 1.1 dante
380 1.1 dante /*
381 1.7 dante * Set the chip type to indicate the ASC3550.
382 1.1 dante */
383 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
384 1.1 dante
385 1.1 dante /*
386 1.1 dante * If the PCI Configuration Command Register "Parity Error Response
387 1.1 dante * Control" Bit was clear (0), then set the microcode variable
388 1.1 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
389 1.1 dante * to ignore DMA parity errors.
390 1.1 dante */
391 1.1 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
392 1.7 dante /*
393 1.7 dante * Note: Don't remove the use of a temporary variable in
394 1.7 dante * the following code, otherwise some C compiler
395 1.7 dante * might turn the following lines into a no-op.
396 1.7 dante */
397 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
398 1.1 dante word |= CONTROL_FLAG_IGNORE_PERR;
399 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
400 1.1 dante }
401 1.7 dante
402 1.1 dante /*
403 1.7 dante * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
404 1.7 dante * threshold of 128 bytes. This register is only accessible to the host.
405 1.1 dante */
406 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
407 1.7 dante START_CTL_EMFU | READ_CMD_MRM);
408 1.7 dante
409 1.7 dante /*
410 1.7 dante * Microcode operating variables for WDTR, SDTR, and command tag
411 1.7 dante * queuing will be set in AdvInquiryHandling() based on what a
412 1.7 dante * device reports it is capable of in Inquiry byte 7.
413 1.7 dante *
414 1.7 dante * If SCSI Bus Resets haev been disabled, then directly set
415 1.7 dante * SDTR and WDTR from the EEPROM configuration. This will allow
416 1.7 dante * the BIOS and warm boot to work without a SCSI bus hang on
417 1.7 dante * the Inquiry caused by host and target mismatched DTR values.
418 1.7 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
419 1.7 dante * be assumed to be in Asynchronous, Narrow mode.
420 1.7 dante */
421 1.7 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
422 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
423 1.7 dante sc->wdtr_able);
424 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
425 1.7 dante sc->sdtr_able);
426 1.7 dante }
427 1.7 dante
428 1.7 dante /*
429 1.7 dante * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
430 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
431 1.7 dante * bitmask. These values determine the maximum SDTR speed negotiated
432 1.7 dante * with a device.
433 1.7 dante *
434 1.7 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
435 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
436 1.7 dante * without determining here whether the device supports SDTR.
437 1.7 dante *
438 1.7 dante * 4-bit speed SDTR speed name
439 1.7 dante * =========== ===============
440 1.7 dante * 0000b (0x0) SDTR disabled
441 1.7 dante * 0001b (0x1) 5 Mhz
442 1.7 dante * 0010b (0x2) 10 Mhz
443 1.7 dante * 0011b (0x3) 20 Mhz (Ultra)
444 1.7 dante * 0100b (0x4) 40 Mhz (LVD/Ultra2)
445 1.7 dante * 0101b (0x5) 80 Mhz (LVD2/Ultra3)
446 1.7 dante * 0110b (0x6) Undefined
447 1.7 dante * .
448 1.7 dante * 1111b (0xF) Undefined
449 1.7 dante */
450 1.7 dante word = 0;
451 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
452 1.7 dante if (ADW_TID_TO_TIDMASK(tid) & sc->ultra_able) {
453 1.7 dante /* Set Ultra speed for TID 'tid'. */
454 1.7 dante word |= (0x3 << (4 * (tid % 4)));
455 1.7 dante } else {
456 1.7 dante /* Set Fast speed for TID 'tid'. */
457 1.7 dante word |= (0x2 << (4 * (tid % 4)));
458 1.7 dante }
459 1.7 dante /* Check if done with sdtr_speed1. */
460 1.7 dante if (tid == 3) {
461 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED1, word);
462 1.7 dante word = 0;
463 1.7 dante /* Check if done with sdtr_speed2. */
464 1.7 dante } else if (tid == 7) {
465 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED2, word);
466 1.7 dante word = 0;
467 1.7 dante /* Check if done with sdtr_speed3. */
468 1.7 dante } else if (tid == 11) {
469 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED3, word);
470 1.7 dante word = 0;
471 1.7 dante /* Check if done with sdtr_speed4. */
472 1.7 dante } else if (tid == 15) {
473 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED4, word);
474 1.7 dante /* End of loop. */
475 1.7 dante }
476 1.7 dante }
477 1.1 dante
478 1.1 dante /*
479 1.7 dante * Set microcode operating variable for the disconnect per TID bitmask.
480 1.1 dante */
481 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
482 1.1 dante
483 1.1 dante
484 1.1 dante /*
485 1.1 dante * Set SCSI_CFG0 Microcode Default Value.
486 1.1 dante *
487 1.1 dante * The microcode will set the SCSI_CFG0 register using this value
488 1.1 dante * after it is started below.
489 1.1 dante */
490 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
491 1.7 dante ADW_PARITY_EN | ADW_SEL_TMO_LONG | ADW_OUR_ID_EN |
492 1.7 dante sc->chip_scsi_id);
493 1.2 dante
494 1.1 dante /*
495 1.1 dante * Determine SCSI_CFG1 Microcode Default Value.
496 1.1 dante *
497 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
498 1.1 dante * after it is started below.
499 1.1 dante */
500 1.1 dante
501 1.1 dante /* Read current SCSI_CFG1 Register value. */
502 1.1 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
503 1.1 dante
504 1.1 dante /*
505 1.1 dante * If all three connectors are in use, return an error.
506 1.1 dante */
507 1.1 dante if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
508 1.7 dante (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
509 1.1 dante return ASC_IERR_ILLEGAL_CONNECTION;
510 1.1 dante }
511 1.7 dante
512 1.1 dante /*
513 1.1 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
514 1.1 dante * register signals will be set. Check for and return an error if
515 1.1 dante * this condition is found.
516 1.1 dante */
517 1.2 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
518 1.2 dante 0x3F07) {
519 1.1 dante return ASC_IERR_REVERSED_CABLE;
520 1.2 dante }
521 1.1 dante
522 1.1 dante /*
523 1.1 dante * If this is a differential board and a single-ended device
524 1.1 dante * is attached to one of the connectors, return an error.
525 1.1 dante */
526 1.7 dante if ((scsi_cfg1 & ADW_DIFF_MODE) && (scsi_cfg1 & ADW_DIFF_SENSE) == 0) {
527 1.1 dante return ASC_IERR_SINGLE_END_DEVICE;
528 1.7 dante }
529 1.1 dante
530 1.1 dante /*
531 1.1 dante * If automatic termination control is enabled, then set the
532 1.7 dante * termination value based on a table listed in a_condor.h.
533 1.1 dante *
534 1.1 dante * If manual termination was specified with an EEPROM setting
535 1.7 dante * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
536 1.1 dante * is ready to be 'ored' into SCSI_CFG1.
537 1.1 dante */
538 1.1 dante if (sc->cfg.termination == 0) {
539 1.1 dante /*
540 1.7 dante * The software always controls termination by setting TERM_CTL_SEL.
541 1.7 dante * If TERM_CTL_SEL were set to 0, the hardware would set termination.
542 1.1 dante */
543 1.1 dante sc->cfg.termination |= ADW_TERM_CTL_SEL;
544 1.1 dante
545 1.7 dante switch(scsi_cfg1 & ADW_CABLE_DETECT) {
546 1.7 dante /* TERM_CTL_H: on, TERM_CTL_L: on */
547 1.7 dante case 0x3: case 0x7: case 0xB: case 0xD: case 0xE: case 0xF:
548 1.7 dante sc->cfg.termination |= (ADW_TERM_CTL_H | ADW_TERM_CTL_L);
549 1.7 dante break;
550 1.7 dante
551 1.7 dante /* TERM_CTL_H: on, TERM_CTL_L: off */
552 1.7 dante case 0x1: case 0x5: case 0x9: case 0xA: case 0xC:
553 1.7 dante sc->cfg.termination |= ADW_TERM_CTL_H;
554 1.7 dante break;
555 1.7 dante
556 1.7 dante /* TERM_CTL_H: off, TERM_CTL_L: off */
557 1.7 dante case 0x2: case 0x6:
558 1.7 dante break;
559 1.1 dante }
560 1.1 dante }
561 1.7 dante
562 1.1 dante /*
563 1.7 dante * Clear any set TERM_CTL_H and TERM_CTL_L bits.
564 1.1 dante */
565 1.1 dante scsi_cfg1 &= ~ADW_TERM_CTL;
566 1.1 dante
567 1.1 dante /*
568 1.7 dante * Invert the TERM_CTL_H and TERM_CTL_L bits and then
569 1.7 dante * set 'scsi_cfg1'. The TERM_POL bit does not need to be
570 1.1 dante * referenced, because the hardware internally inverts
571 1.7 dante * the Termination High and Low bits if TERM_POL is set.
572 1.1 dante */
573 1.1 dante scsi_cfg1 |= (ADW_TERM_CTL_SEL | (~sc->cfg.termination & ADW_TERM_CTL));
574 1.1 dante
575 1.1 dante /*
576 1.1 dante * Set SCSI_CFG1 Microcode Default Value
577 1.1 dante *
578 1.1 dante * Set filter value and possibly modified termination control
579 1.1 dante * bits in the Microcode SCSI_CFG1 Register Value.
580 1.1 dante *
581 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
582 1.1 dante * after it is started below.
583 1.1 dante */
584 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1,
585 1.7 dante ADW_FLTR_DISABLE | scsi_cfg1);
586 1.7 dante
587 1.7 dante /*
588 1.7 dante * Set MEM_CFG Microcode Default Value
589 1.7 dante *
590 1.7 dante * The microcode will set the MEM_CFG register using this value
591 1.7 dante * after it is started below.
592 1.7 dante *
593 1.7 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
594 1.7 dante * are defined.
595 1.7 dante *
596 1.7 dante * ASC-3550 has 8KB internal memory.
597 1.7 dante */
598 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_MEM_CFG,
599 1.7 dante ADW_BIOS_EN | ADW_RAM_SZ_8KB);
600 1.1 dante
601 1.1 dante /*
602 1.1 dante * Set SEL_MASK Microcode Default Value
603 1.1 dante *
604 1.1 dante * The microcode will set the SEL_MASK register using this value
605 1.1 dante * after it is started below.
606 1.1 dante */
607 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
608 1.7 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
609 1.7 dante
610 1.7 dante
611 1.7 dante /*
612 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
613 1.7 dante */
614 1.7 dante
615 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
616 1.7 dante return ASC_IERR_NO_CARRIER;
617 1.7 dante }
618 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
619 1.7 dante ASC_GET_CARRP(sc->icq_sp->next_vpa));
620 1.7 dante
621 1.7 dante /*
622 1.7 dante * The first command issued will be placed in the stopper carrier.
623 1.7 dante */
624 1.7 dante sc->icq_sp->next_vpa = ASC_CQ_STOPPER;
625 1.1 dante
626 1.1 dante /*
627 1.7 dante * Set RISC ICQ physical address start value.
628 1.7 dante */
629 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_ICQ, sc->icq_sp->carr_pa);
630 1.7 dante
631 1.7 dante /*
632 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
633 1.1 dante */
634 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
635 1.7 dante return ASC_IERR_NO_CARRIER;
636 1.1 dante }
637 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
638 1.7 dante ASC_GET_CARRP(sc->irq_sp->next_vpa));
639 1.1 dante
640 1.1 dante /*
641 1.7 dante * The first command completed by the RISC will be placed in
642 1.7 dante * the stopper.
643 1.1 dante *
644 1.7 dante * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
645 1.7 dante * completed the RISC will set the ASC_RQ_STOPPER bit.
646 1.1 dante */
647 1.7 dante sc->irq_sp->next_vpa = ASC_CQ_STOPPER;
648 1.1 dante
649 1.1 dante /*
650 1.7 dante * Set RISC IRQ physical address start value.
651 1.1 dante */
652 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IRQ, sc->irq_sp->carr_pa);
653 1.7 dante sc->carr_pending_cnt = 0;
654 1.1 dante
655 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
656 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
657 1.1 dante
658 1.7 dante /*
659 1.7 dante * Note: Don't remove the use of a temporary variable in
660 1.7 dante * the following code, otherwise some C compiler
661 1.7 dante * might turn the following lines into a no-op.
662 1.7 dante */
663 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
664 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
665 1.1 dante
666 1.1 dante /* finally, finally, gentlemen, start your engine */
667 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
668 1.2 dante
669 1.7 dante /*
670 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
671 1.7 dante * Resets should be performed. The RISC has to be running
672 1.7 dante * to issue a SCSI Bus Reset.
673 1.7 dante */
674 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
675 1.7 dante {
676 1.7 dante /*
677 1.7 dante * If the BIOS Signature is present in memory, restore the
678 1.7 dante * BIOS Handshake Configuration Table and do not perform
679 1.7 dante * a SCSI Bus Reset.
680 1.7 dante */
681 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] ==
682 1.7 dante 0x55AA) {
683 1.7 dante /*
684 1.7 dante * Restore per TID negotiated values.
685 1.7 dante */
686 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
687 1.7 dante wdtr_able);
688 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
689 1.7 dante sdtr_able);
690 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
691 1.7 dante tagqng_able);
692 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
693 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
694 1.7 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
695 1.7 dante max_cmd[tid]);
696 1.7 dante }
697 1.7 dante } else {
698 1.7 dante if (AdvResetCCB(sc) != ADW_TRUE) {
699 1.7 dante warn_code = ASC_WARN_BUSRESET_ERROR;
700 1.7 dante }
701 1.7 dante }
702 1.7 dante }
703 1.7 dante
704 1.7 dante return warn_code;
705 1.1 dante }
706 1.1 dante
707 1.1 dante /*
708 1.7 dante * Initialize the ASC-38C0800.
709 1.1 dante *
710 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
711 1.1 dante *
712 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
713 1.1 dante * then 0 is returned.
714 1.1 dante */
715 1.1 dante int
716 1.7 dante AdvInitAsc38C0800Driver(sc)
717 1.7 dante ADW_SOFTC *sc;
718 1.1 dante {
719 1.2 dante bus_space_tag_t iot = sc->sc_iot;
720 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
721 1.7 dante u_int16_t warn_code;
722 1.7 dante u_int32_t sum;
723 1.7 dante int begin_addr;
724 1.7 dante int end_addr;
725 1.7 dante u_int16_t code_sum;
726 1.7 dante int word;
727 1.7 dante int i, j;
728 1.7 dante int adv_asc38C0800_expanded_size;
729 1.7 dante u_int16_t scsi_cfg1;
730 1.7 dante u_int8_t byte;
731 1.7 dante u_int8_t tid;
732 1.7 dante u_int16_t bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory
733 1.7 dante 0x40-0x8F. */
734 1.7 dante u_int16_t wdtr_able, sdtr_able, tagqng_able;
735 1.7 dante u_int8_t max_cmd[ADW_MAX_TID + 1];
736 1.1 dante
737 1.1 dante
738 1.1 dante warn_code = 0;
739 1.1 dante
740 1.1 dante /*
741 1.7 dante * Save the RISC memory BIOS region before writing the microcode.
742 1.7 dante * The BIOS may already be loaded and using its RISC LRAM region
743 1.7 dante * so its region must be saved and restored.
744 1.1 dante *
745 1.7 dante * Note: This code makes the assumption, which is currently true,
746 1.7 dante * that a chip reset does not clear RISC LRAM.
747 1.7 dante */
748 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
749 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
750 1.7 dante }
751 1.7 dante
752 1.7 dante /*
753 1.7 dante * Save current per TID negotiated values.
754 1.1 dante */
755 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
756 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
757 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
758 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
759 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
760 1.7 dante max_cmd[tid]);
761 1.7 dante }
762 1.2 dante
763 1.7 dante /*
764 1.7 dante * RAM BIST (RAM Built-In Self Test)
765 1.7 dante *
766 1.7 dante * Address : I/O base + offset 0x38h register (byte).
767 1.7 dante * Function: Bit 7-6(RW) : RAM mode
768 1.7 dante * Normal Mode : 0x00
769 1.7 dante * Pre-test Mode : 0x40
770 1.7 dante * RAM Test Mode : 0x80
771 1.7 dante * Bit 5 : unused
772 1.7 dante * Bit 4(RO) : Done bit
773 1.7 dante * Bit 3-0(RO) : Status
774 1.7 dante * Host Error : 0x08
775 1.7 dante * Int_RAM Error : 0x04
776 1.7 dante * RISC Error : 0x02
777 1.7 dante * SCSI Error : 0x01
778 1.7 dante * No Error : 0x00
779 1.7 dante *
780 1.7 dante * Note: RAM BIST code should be put right here, before loading the
781 1.7 dante * microcode and after saving the RISC memory BIOS region.
782 1.7 dante */
783 1.1 dante
784 1.7 dante /*
785 1.7 dante * LRAM Pre-test
786 1.7 dante *
787 1.7 dante * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
788 1.7 dante * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
789 1.7 dante * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
790 1.7 dante * to NORMAL_MODE, return an error too.
791 1.7 dante */
792 1.7 dante for (i = 0; i < 2; i++) {
793 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, PRE_TEST_MODE);
794 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
795 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
796 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) !=
797 1.7 dante PRE_TEST_VALUE) {
798 1.7 dante return ASC_IERR_BIST_PRE_TEST;
799 1.1 dante }
800 1.1 dante
801 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
802 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before reading back. */
803 1.7 dante if (ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST)
804 1.7 dante != NORMAL_VALUE) {
805 1.7 dante return ASC_IERR_BIST_PRE_TEST;
806 1.7 dante }
807 1.1 dante }
808 1.7 dante
809 1.1 dante /*
810 1.7 dante * LRAM Test - It takes about 1.5 ms to run through the test.
811 1.1 dante *
812 1.7 dante * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
813 1.7 dante * If Done bit not set or Status not 0, save register byte, set the
814 1.7 dante * err_code, and return an error.
815 1.1 dante */
816 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, RAM_TEST_MODE);
817 1.7 dante AdvSleepMilliSecond(10); /* Wait for 10ms before checking status. */
818 1.7 dante
819 1.7 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST);
820 1.7 dante if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0) {
821 1.7 dante /* Get here if Done bit not set or Status not 0. */
822 1.7 dante return ASC_IERR_BIST_RAM_TEST;
823 1.7 dante }
824 1.7 dante
825 1.7 dante /* We need to reset back to normal mode after LRAM test passes. */
826 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_RAM_BIST, NORMAL_MODE);
827 1.1 dante
828 1.1 dante /*
829 1.7 dante * Load the Microcode
830 1.7 dante *
831 1.7 dante * Write the microcode image to RISC memory starting at address 0.
832 1.7 dante *
833 1.1 dante */
834 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
835 1.7 dante
836 1.7 dante /* Assume the following compressed format of the microcode buffer:
837 1.7 dante *
838 1.7 dante * 254 word (508 byte) table indexed by byte code followed
839 1.7 dante * by the following byte codes:
840 1.7 dante *
841 1.7 dante * 1-Byte Code:
842 1.7 dante * 00: Emit word 0 in table.
843 1.7 dante * 01: Emit word 1 in table.
844 1.7 dante * .
845 1.7 dante * FD: Emit word 253 in table.
846 1.7 dante *
847 1.7 dante * Multi-Byte Code:
848 1.7 dante * FE WW WW: (3 byte code) Word to emit is the next word WW WW.
849 1.7 dante * FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
850 1.7 dante */
851 1.7 dante word = 0;
852 1.7 dante for (i = 253 * 2; i < adv_asc38C0800_mcode_size; i++) {
853 1.7 dante if (adv_asc38C0800_mcode[i] == 0xff) {
854 1.7 dante for (j = 0; j < adv_asc38C0800_mcode[i + 1]; j++) {
855 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
856 1.7 dante (((u_int16_t)
857 1.7 dante adv_asc38C0800_mcode[i + 3] << 8) |
858 1.7 dante adv_asc38C0800_mcode[i + 2]));
859 1.7 dante word++;
860 1.7 dante }
861 1.7 dante i += 3;
862 1.7 dante } else if (adv_asc38C0800_mcode[i] == 0xfe) {
863 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
864 1.7 dante adv_asc38C0800_mcode[i + 2] << 8) |
865 1.7 dante adv_asc38C0800_mcode[i + 1]));
866 1.7 dante i += 2;
867 1.7 dante word++;
868 1.1 dante } else {
869 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, (((u_int16_t)
870 1.7 dante adv_asc38C0800_mcode[(adv_asc38C0800_mcode[i] * 2) + 1] << 8) |
871 1.7 dante adv_asc38C0800_mcode[adv_asc38C0800_mcode[i] * 2]));
872 1.7 dante word++;
873 1.1 dante }
874 1.1 dante }
875 1.7 dante
876 1.7 dante /*
877 1.7 dante * Set 'word' for later use to clear the rest of memory and save
878 1.7 dante * the expanded mcode size.
879 1.7 dante */
880 1.7 dante word *= 2;
881 1.7 dante adv_asc38C0800_expanded_size = word;
882 1.7 dante
883 1.1 dante /*
884 1.7 dante * Clear the rest of ASC-38C0800 Internal RAM (16KB).
885 1.1 dante */
886 1.7 dante for (; word < ADV_38C0800_MEMSIZE; word += 2) {
887 1.7 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
888 1.1 dante }
889 1.7 dante
890 1.1 dante /*
891 1.7 dante * Verify the microcode checksum.
892 1.1 dante */
893 1.7 dante sum = 0;
894 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
895 1.7 dante
896 1.7 dante for (word = 0; word < adv_asc38C0800_expanded_size; word += 2) {
897 1.7 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
898 1.7 dante }
899 1.1 dante
900 1.7 dante if (sum != adv_asc38C0800_mcode_chksum) {
901 1.7 dante return ASC_IERR_MCODE_CHKSUM;
902 1.7 dante }
903 1.1 dante
904 1.1 dante /*
905 1.7 dante * Restore the RISC memory BIOS region.
906 1.1 dante */
907 1.7 dante for (i = 0; i < ASC_MC_BIOSLEN/2; i++) {
908 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOSMEM + (2 * i),
909 1.7 dante bios_mem[i]);
910 1.7 dante }
911 1.1 dante
912 1.7 dante /*
913 1.7 dante * Calculate and write the microcode code checksum to the microcode
914 1.7 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
915 1.7 dante */
916 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
917 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
918 1.7 dante code_sum = 0;
919 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, begin_addr);
920 1.7 dante for (word = begin_addr; word < end_addr; word += 2) {
921 1.7 dante code_sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
922 1.1 dante }
923 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
924 1.1 dante
925 1.7 dante /*
926 1.7 dante * Read microcode version and date.
927 1.7 dante */
928 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE,
929 1.7 dante sc->cfg.mcode_date);
930 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM,
931 1.7 dante sc->cfg.mcode_version);
932 1.1 dante
933 1.7 dante /*
934 1.7 dante * Set the chip type to indicate the ASC38C0800.
935 1.7 dante */
936 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
937 1.1 dante
938 1.7 dante /*
939 1.7 dante * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
940 1.7 dante * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
941 1.7 dante * cable detection and then we are able to read C_DET[3:0].
942 1.7 dante *
943 1.7 dante * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
944 1.7 dante * Microcode Default Value' section below.
945 1.7 dante */
946 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
947 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1,
948 1.7 dante scsi_cfg1 | ADW_DIS_TERM_DRV);
949 1.7 dante
950 1.7 dante /*
951 1.7 dante * If the PCI Configuration Command Register "Parity Error Response
952 1.7 dante * Control" Bit was clear (0), then set the microcode variable
953 1.7 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
954 1.7 dante * to ignore DMA parity errors.
955 1.7 dante */
956 1.7 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
957 1.7 dante /*
958 1.7 dante * Note: Don't remove the use of a temporary variable in
959 1.7 dante * the following code, otherwise some C compiler
960 1.7 dante * might turn the following lines into a no-op.
961 1.7 dante */
962 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
963 1.7 dante word |= CONTROL_FLAG_IGNORE_PERR;
964 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
965 1.7 dante }
966 1.7 dante
967 1.7 dante /*
968 1.7 dante * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
969 1.7 dante * bits for the default FIFO threshold.
970 1.7 dante *
971 1.7 dante * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
972 1.7 dante *
973 1.7 dante * For DMA Errata #4 set the BC_THRESH_ENB bit.
974 1.7 dante */
975 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
976 1.7 dante BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
977 1.7 dante
978 1.7 dante /*
979 1.7 dante * Microcode operating variables for WDTR, SDTR, and command tag
980 1.7 dante * queuing will be set in AdvInquiryHandling() based on what a
981 1.7 dante * device reports it is capable of in Inquiry byte 7.
982 1.7 dante *
983 1.7 dante * If SCSI Bus Resets have been disabled, then directly set
984 1.7 dante * SDTR and WDTR from the EEPROM configuration. This will allow
985 1.7 dante * the BIOS and warm boot to work without a SCSI bus hang on
986 1.7 dante * the Inquiry caused by host and target mismatched DTR values.
987 1.7 dante * Without the SCSI Bus Reset, before an Inquiry a device can't
988 1.7 dante * be assumed to be in Asynchronous, Narrow mode.
989 1.7 dante */
990 1.7 dante if ((sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0) {
991 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, sc->wdtr_able);
992 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sc->sdtr_able);
993 1.7 dante }
994 1.7 dante
995 1.7 dante /*
996 1.7 dante * Set microcode operating variables for DISC and SDTR_SPEED1,
997 1.7 dante * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
998 1.7 dante * configuration values.
999 1.7 dante *
1000 1.7 dante * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
1001 1.7 dante * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
1002 1.7 dante * without determining here whether the device supports SDTR.
1003 1.7 dante */
1004 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
1005 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED1, sc->sdtr_speed1);
1006 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED2, sc->sdtr_speed2);
1007 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED3, sc->sdtr_speed3);
1008 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_SPEED4, sc->sdtr_speed4);
1009 1.7 dante
1010 1.7 dante /*
1011 1.7 dante * Set SCSI_CFG0 Microcode Default Value.
1012 1.7 dante *
1013 1.7 dante * The microcode will set the SCSI_CFG0 register using this value
1014 1.7 dante * after it is started below.
1015 1.7 dante */
1016 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
1017 1.7 dante ADW_PARITY_EN | ADW_SEL_TMO_LONG | ADW_OUR_ID_EN |
1018 1.7 dante sc->chip_scsi_id);
1019 1.7 dante
1020 1.7 dante /*
1021 1.7 dante * Determine SCSI_CFG1 Microcode Default Value.
1022 1.7 dante *
1023 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1024 1.7 dante * after it is started below.
1025 1.7 dante */
1026 1.7 dante
1027 1.7 dante /* Read current SCSI_CFG1 Register value. */
1028 1.7 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
1029 1.7 dante
1030 1.7 dante /*
1031 1.7 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
1032 1.7 dante * register signals will be set. Check for and return an error if
1033 1.7 dante * this condition is found.
1034 1.7 dante */
1035 1.7 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
1036 1.7 dante 0x3F07) {
1037 1.7 dante return ASC_IERR_REVERSED_CABLE;
1038 1.7 dante }
1039 1.7 dante
1040 1.7 dante /*
1041 1.7 dante * All kind of combinations of devices attached to one of four connectors
1042 1.7 dante * are acceptable except HVD device attached. For example, LVD device can
1043 1.7 dante * be attached to SE connector while SE device attached to LVD connector.
1044 1.7 dante * If LVD device attached to SE connector, it only runs up to Ultra speed.
1045 1.7 dante *
1046 1.7 dante * If an HVD device is attached to one of LVD connectors, return an error.
1047 1.7 dante * However, there is no way to detect HVD device attached to SE connectors.
1048 1.7 dante */
1049 1.7 dante if (scsi_cfg1 & ADW_HVD) {
1050 1.7 dante return ASC_IERR_HVD_DEVICE;
1051 1.7 dante }
1052 1.7 dante
1053 1.7 dante /*
1054 1.7 dante * If either SE or LVD automatic termination control is enabled, then
1055 1.7 dante * set the termination value based on a table listed in a_condor.h.
1056 1.7 dante *
1057 1.7 dante * If manual termination was specified with an EEPROM setting then
1058 1.7 dante * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready to
1059 1.7 dante * be 'ored' into SCSI_CFG1.
1060 1.7 dante */
1061 1.7 dante if ((sc->cfg.termination & ADW_TERM_SE) == 0) {
1062 1.7 dante /* SE automatic termination control is enabled. */
1063 1.7 dante switch(scsi_cfg1 & ADW_C_DET_SE) {
1064 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: on */
1065 1.7 dante case 0x1: case 0x2: case 0x3:
1066 1.7 dante sc->cfg.termination |= ADW_TERM_SE;
1067 1.7 dante break;
1068 1.7 dante
1069 1.7 dante /* TERM_SE_HI: on, TERM_SE_LO: off */
1070 1.7 dante case 0x0:
1071 1.7 dante sc->cfg.termination |= ADW_TERM_SE_HI;
1072 1.7 dante break;
1073 1.7 dante }
1074 1.7 dante }
1075 1.7 dante
1076 1.7 dante if ((sc->cfg.termination & ADW_TERM_LVD) == 0) {
1077 1.7 dante /* LVD automatic termination control is enabled. */
1078 1.7 dante switch(scsi_cfg1 & ADW_C_DET_LVD) {
1079 1.7 dante /* TERM_LVD_HI: on, TERM_LVD_LO: on */
1080 1.7 dante case 0x4: case 0x8: case 0xC:
1081 1.7 dante sc->cfg.termination |= ADW_TERM_LVD;
1082 1.7 dante break;
1083 1.7 dante
1084 1.7 dante /* TERM_LVD_HI: off, TERM_LVD_LO: off */
1085 1.7 dante case 0x0:
1086 1.7 dante break;
1087 1.7 dante }
1088 1.7 dante }
1089 1.7 dante
1090 1.7 dante /*
1091 1.7 dante * Clear any set TERM_SE and TERM_LVD bits.
1092 1.7 dante */
1093 1.7 dante scsi_cfg1 &= (~ADW_TERM_SE & ~ADW_TERM_LVD);
1094 1.7 dante
1095 1.7 dante /*
1096 1.7 dante * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
1097 1.7 dante */
1098 1.7 dante scsi_cfg1 |= (~sc->cfg.termination & 0xF0);
1099 1.7 dante
1100 1.7 dante /*
1101 1.7 dante * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
1102 1.7 dante * and set possibly modified termination control bits in the Microcode
1103 1.7 dante * SCSI_CFG1 Register Value.
1104 1.7 dante */
1105 1.7 dante scsi_cfg1 &= (~ADW_BIG_ENDIAN & ~ADW_DIS_TERM_DRV &
1106 1.7 dante ~ADW_TERM_POL & ~ADW_HVD_LVD_SE);
1107 1.7 dante
1108 1.7 dante /*
1109 1.7 dante * Set SCSI_CFG1 Microcode Default Value
1110 1.7 dante *
1111 1.7 dante * Set possibly modified termination control and reset DIS_TERM_DRV
1112 1.7 dante * bits in the Microcode SCSI_CFG1 Register Value.
1113 1.7 dante *
1114 1.7 dante * The microcode will set the SCSI_CFG1 register using this value
1115 1.7 dante * after it is started below.
1116 1.7 dante */
1117 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
1118 1.7 dante
1119 1.7 dante /*
1120 1.7 dante * Set MEM_CFG Microcode Default Value
1121 1.7 dante *
1122 1.7 dante * The microcode will set the MEM_CFG register using this value
1123 1.7 dante * after it is started below.
1124 1.7 dante *
1125 1.7 dante * MEM_CFG may be accessed as a word or byte, but only bits 0-7
1126 1.7 dante * are defined.
1127 1.7 dante *
1128 1.7 dante * ASC-38C0800 has 16KB internal memory.
1129 1.7 dante */
1130 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_MEM_CFG,
1131 1.7 dante ADW_BIOS_EN | ADW_RAM_SZ_16KB);
1132 1.7 dante
1133 1.7 dante /*
1134 1.7 dante * Set SEL_MASK Microcode Default Value
1135 1.7 dante *
1136 1.7 dante * The microcode will set the SEL_MASK register using this value
1137 1.7 dante * after it is started below.
1138 1.7 dante */
1139 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
1140 1.7 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
1141 1.7 dante
1142 1.7 dante
1143 1.7 dante /*
1144 1.7 dante * Set-up the Host->RISC Initiator Command Queue (ICQ).
1145 1.7 dante */
1146 1.7 dante
1147 1.7 dante if ((sc->icq_sp = sc->carr_freelist) == NULL) {
1148 1.7 dante return ASC_IERR_NO_CARRIER;
1149 1.7 dante }
1150 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1151 1.7 dante ASC_GET_CARRP(sc->icq_sp->next_vpa));
1152 1.7 dante
1153 1.7 dante
1154 1.7 dante /*
1155 1.7 dante * The first command issued will be placed in the stopper carrier.
1156 1.7 dante */
1157 1.7 dante sc->icq_sp->next_vpa = ASC_CQ_STOPPER;
1158 1.7 dante
1159 1.7 dante /*
1160 1.7 dante * Set RISC ICQ physical address start value.
1161 1.7 dante */
1162 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_ICQ, sc->icq_sp->carr_pa);
1163 1.7 dante
1164 1.7 dante /*
1165 1.7 dante * Set-up the RISC->Host Initiator Response Queue (IRQ).
1166 1.7 dante */
1167 1.7 dante if ((sc->irq_sp = sc->carr_freelist) == NULL) {
1168 1.7 dante return ASC_IERR_NO_CARRIER;
1169 1.7 dante }
1170 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1171 1.7 dante ASC_GET_CARRP(sc->irq_sp->next_vpa));
1172 1.7 dante
1173 1.7 dante /*
1174 1.7 dante * The first command completed by the RISC will be placed in
1175 1.7 dante * the stopper.
1176 1.7 dante *
1177 1.7 dante * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
1178 1.7 dante * completed the RISC will set the ASC_RQ_STOPPER bit.
1179 1.7 dante */
1180 1.7 dante sc->irq_sp->next_vpa = ASC_CQ_STOPPER;
1181 1.7 dante
1182 1.7 dante /*
1183 1.7 dante * Set RISC IRQ physical address start value.
1184 1.7 dante */
1185 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IRQ, sc->irq_sp->carr_pa);
1186 1.7 dante sc->carr_pending_cnt = 0;
1187 1.7 dante
1188 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
1189 1.7 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
1190 1.7 dante /*
1191 1.7 dante * Note: Don't remove the use of a temporary variable in
1192 1.7 dante * the following code, otherwise some C compiler
1193 1.7 dante * might turn the following lines into a no-op.
1194 1.7 dante */
1195 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
1196 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
1197 1.7 dante
1198 1.7 dante /* finally, finally, gentlemen, start your engine */
1199 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
1200 1.7 dante
1201 1.7 dante /*
1202 1.7 dante * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
1203 1.7 dante * Resets should be performed. The RISC has to be running
1204 1.7 dante * to issue a SCSI Bus Reset.
1205 1.7 dante */
1206 1.7 dante if (sc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) {
1207 1.7 dante /*
1208 1.7 dante * If the BIOS Signature is present in memory, restore the
1209 1.7 dante * BIOS Handshake Configuration Table and do not perform
1210 1.7 dante * a SCSI Bus Reset.
1211 1.7 dante */
1212 1.7 dante if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] ==
1213 1.7 dante 0x55AA) {
1214 1.7 dante /*
1215 1.7 dante * Restore per TID negotiated values.
1216 1.7 dante */
1217 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
1218 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
1219 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
1220 1.7 dante tagqng_able);
1221 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1222 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1223 1.7 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
1224 1.7 dante max_cmd[tid]);
1225 1.7 dante }
1226 1.7 dante } else {
1227 1.7 dante if (AdvResetCCB(sc) != ADW_TRUE) {
1228 1.7 dante warn_code = ASC_WARN_BUSRESET_ERROR;
1229 1.7 dante }
1230 1.7 dante }
1231 1.7 dante }
1232 1.7 dante
1233 1.7 dante return warn_code;
1234 1.7 dante }
1235 1.7 dante
1236 1.7 dante
1237 1.7 dante /*
1238 1.7 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
1239 1.7 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
1240 1.7 dante * all of this is done.
1241 1.7 dante *
1242 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
1243 1.7 dante *
1244 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
1245 1.7 dante * then 0 is returned.
1246 1.7 dante *
1247 1.7 dante * Note: Chip is stopped on entry.
1248 1.7 dante */
1249 1.7 dante int
1250 1.7 dante AdvInitFrom3550EEP(sc)
1251 1.7 dante ADW_SOFTC *sc;
1252 1.7 dante {
1253 1.7 dante bus_space_tag_t iot = sc->sc_iot;
1254 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
1255 1.7 dante u_int16_t warn_code;
1256 1.7 dante ADW_EEP_3550_CONFIG eep_config;
1257 1.7 dante int i;
1258 1.7 dante
1259 1.7 dante
1260 1.7 dante warn_code = 0;
1261 1.7 dante
1262 1.7 dante /*
1263 1.7 dante * Read the board's EEPROM configuration.
1264 1.7 dante *
1265 1.7 dante * Set default values if a bad checksum is found.
1266 1.7 dante */
1267 1.7 dante if (AdvGet3550EEPConfig(iot, ioh, &eep_config) != eep_config.check_sum){
1268 1.7 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
1269 1.7 dante
1270 1.7 dante /*
1271 1.7 dante * Set EEPROM default values.
1272 1.7 dante */
1273 1.7 dante for (i = 0; i < sizeof(ADW_EEP_3550_CONFIG); i++) {
1274 1.7 dante *((u_int8_t *) &eep_config + i) =
1275 1.7 dante *((u_int8_t *) &Default_3550_EEPROM_Config + i);
1276 1.7 dante }
1277 1.7 dante
1278 1.7 dante /*
1279 1.7 dante * Assume the 6 byte board serial number that was read
1280 1.7 dante * from EEPROM is correct even if the EEPROM checksum
1281 1.7 dante * failed.
1282 1.7 dante */
1283 1.7 dante eep_config.serial_number_word3 =
1284 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
1285 1.7 dante
1286 1.7 dante eep_config.serial_number_word2 =
1287 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
1288 1.7 dante
1289 1.7 dante eep_config.serial_number_word1 =
1290 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
1291 1.7 dante
1292 1.7 dante AdvSet3550EEPConfig(iot, ioh, &eep_config);
1293 1.7 dante }
1294 1.7 dante /*
1295 1.7 dante * Set sc_VAR and sc_CFG variables from the
1296 1.7 dante * EEPROM configuration that was read.
1297 1.7 dante *
1298 1.7 dante * This is the mapping of EEPROM fields to Adv Library fields.
1299 1.7 dante */
1300 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
1301 1.7 dante sc->sdtr_able = eep_config.sdtr_able;
1302 1.7 dante sc->ultra_able = eep_config.ultra_able;
1303 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
1304 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
1305 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
1306 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1307 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
1308 1.7 dante sc->start_motor = eep_config.start_motor;
1309 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
1310 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
1311 1.7 dante sc->no_scam = eep_config.scam_tolerant;
1312 1.7 dante sc->cfg.serial1 = eep_config.serial_number_word1;
1313 1.7 dante sc->cfg.serial2 = eep_config.serial_number_word2;
1314 1.7 dante sc->cfg.serial3 = eep_config.serial_number_word3;
1315 1.7 dante
1316 1.7 dante /*
1317 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
1318 1.7 dante * maximum queuing (max. 63, min. 4).
1319 1.7 dante */
1320 1.7 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
1321 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1322 1.7 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
1323 1.7 dante {
1324 1.7 dante /* If the value is zero, assume it is uninitialized. */
1325 1.7 dante if (eep_config.max_host_qng == 0) {
1326 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1327 1.7 dante } else {
1328 1.7 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
1329 1.7 dante }
1330 1.7 dante }
1331 1.7 dante
1332 1.7 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
1333 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1334 1.7 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
1335 1.7 dante /* If the value is zero, assume it is uninitialized. */
1336 1.7 dante if (eep_config.max_dvc_qng == 0) {
1337 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1338 1.7 dante } else {
1339 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
1340 1.7 dante }
1341 1.7 dante }
1342 1.7 dante
1343 1.7 dante /*
1344 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
1345 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
1346 1.7 dante */
1347 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
1348 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
1349 1.7 dante }
1350 1.7 dante
1351 1.7 dante /*
1352 1.7 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
1353 1.7 dante * values based on possibly adjusted EEPROM values.
1354 1.7 dante */
1355 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
1356 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1357 1.7 dante
1358 1.7 dante
1359 1.7 dante /*
1360 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
1361 1.7 dante * the ADV_DVC_CFG 'termination' field to automatic also.
1362 1.7 dante *
1363 1.7 dante * If the termination is specified with a non-zero 'termination'
1364 1.7 dante * value check that a legal value is set and set the ADV_DVC_CFG
1365 1.7 dante * 'termination' field appropriately.
1366 1.7 dante */
1367 1.7 dante if (eep_config.termination == 0) {
1368 1.7 dante sc->cfg.termination = 0; /* auto termination */
1369 1.7 dante } else {
1370 1.7 dante /* Enable manual control with low off / high off. */
1371 1.7 dante if (eep_config.termination == 1) {
1372 1.7 dante sc->cfg.termination = ADW_TERM_CTL_SEL;
1373 1.7 dante
1374 1.7 dante /* Enable manual control with low off / high on. */
1375 1.7 dante } else if (eep_config.termination == 2) {
1376 1.7 dante sc->cfg.termination = ADW_TERM_CTL_SEL | ADW_TERM_CTL_H;
1377 1.7 dante
1378 1.7 dante /* Enable manual control with low on / high on. */
1379 1.7 dante } else if (eep_config.termination == 3) {
1380 1.7 dante sc->cfg.termination = ADW_TERM_CTL_SEL |
1381 1.7 dante ADW_TERM_CTL_H | ADW_TERM_CTL_L;
1382 1.7 dante } else {
1383 1.7 dante /*
1384 1.7 dante * The EEPROM 'termination' field contains a bad value. Use
1385 1.7 dante * automatic termination instead.
1386 1.7 dante */
1387 1.7 dante sc->cfg.termination = 0;
1388 1.7 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
1389 1.7 dante }
1390 1.7 dante }
1391 1.7 dante
1392 1.7 dante return warn_code;
1393 1.7 dante }
1394 1.7 dante
1395 1.7 dante
1396 1.7 dante /*
1397 1.7 dante * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
1398 1.7 dante * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
1399 1.7 dante * all of this is done.
1400 1.7 dante *
1401 1.7 dante * On failure set the ADV_DVC_VAR field 'err_code' and return ADW_ERROR.
1402 1.7 dante *
1403 1.7 dante * For a non-fatal error return a warning code. If there are no warnings
1404 1.7 dante * then 0 is returned.
1405 1.7 dante *
1406 1.7 dante * Note: Chip is stopped on entry.
1407 1.7 dante */
1408 1.7 dante int
1409 1.7 dante AdvInitFrom38C0800EEP(sc)
1410 1.7 dante ADW_SOFTC *sc;
1411 1.7 dante {
1412 1.7 dante bus_space_tag_t iot = sc->sc_iot;
1413 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
1414 1.7 dante u_int16_t warn_code;
1415 1.7 dante ADW_EEP_38C0800_CONFIG eep_config;
1416 1.7 dante int i;
1417 1.7 dante u_int8_t tid, termination;
1418 1.7 dante u_int16_t sdtr_speed = 0;
1419 1.7 dante
1420 1.7 dante
1421 1.7 dante warn_code = 0;
1422 1.7 dante
1423 1.7 dante /*
1424 1.7 dante * Read the board's EEPROM configuration.
1425 1.7 dante *
1426 1.7 dante * Set default values if a bad checksum is found.
1427 1.7 dante */
1428 1.7 dante if (AdvGet38C0800EEPConfig(iot, ioh, &eep_config) !=
1429 1.7 dante eep_config.check_sum) {
1430 1.7 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
1431 1.7 dante
1432 1.7 dante /*
1433 1.7 dante * Set EEPROM default values.
1434 1.7 dante */
1435 1.7 dante for (i = 0; i < sizeof(ADW_EEP_38C0800_CONFIG); i++) {
1436 1.7 dante *((u_int8_t *) &eep_config + i) =
1437 1.7 dante *((u_int8_t *)&Default_38C0800_EEPROM_Config+i);
1438 1.7 dante }
1439 1.7 dante
1440 1.7 dante /*
1441 1.7 dante * Assume the 6 byte board serial number that was read
1442 1.7 dante * from EEPROM is correct even if the EEPROM checksum
1443 1.7 dante * failed.
1444 1.7 dante */
1445 1.7 dante eep_config.serial_number_word3 =
1446 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
1447 1.7 dante
1448 1.7 dante eep_config.serial_number_word2 =
1449 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
1450 1.7 dante
1451 1.7 dante eep_config.serial_number_word1 =
1452 1.7 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
1453 1.7 dante
1454 1.7 dante AdvSet38C0800EEPConfig(iot, ioh, &eep_config);
1455 1.7 dante }
1456 1.7 dante /*
1457 1.7 dante * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
1458 1.7 dante * EEPROM configuration that was read.
1459 1.7 dante *
1460 1.7 dante * This is the mapping of EEPROM fields to Adv Library fields.
1461 1.7 dante */
1462 1.7 dante sc->wdtr_able = eep_config.wdtr_able;
1463 1.7 dante sc->sdtr_speed1 = eep_config.sdtr_speed1;
1464 1.7 dante sc->sdtr_speed2 = eep_config.sdtr_speed2;
1465 1.7 dante sc->sdtr_speed3 = eep_config.sdtr_speed3;
1466 1.7 dante sc->sdtr_speed4 = eep_config.sdtr_speed4;
1467 1.7 dante sc->tagqng_able = eep_config.tagqng_able;
1468 1.7 dante sc->cfg.disc_enable = eep_config.disc_enable;
1469 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
1470 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1471 1.7 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
1472 1.7 dante sc->start_motor = eep_config.start_motor;
1473 1.7 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
1474 1.7 dante sc->bios_ctrl = eep_config.bios_ctrl;
1475 1.7 dante sc->no_scam = eep_config.scam_tolerant;
1476 1.7 dante sc->cfg.serial1 = eep_config.serial_number_word1;
1477 1.7 dante sc->cfg.serial2 = eep_config.serial_number_word2;
1478 1.7 dante sc->cfg.serial3 = eep_config.serial_number_word3;
1479 1.7 dante
1480 1.7 dante /*
1481 1.7 dante * For every Target ID if any of its 'sdtr_speed[1234]' bits
1482 1.7 dante * are set, then set an 'sdtr_able' bit for it.
1483 1.7 dante */
1484 1.7 dante sc->sdtr_able = 0;
1485 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
1486 1.7 dante if (tid == 0) {
1487 1.7 dante sdtr_speed = sc->sdtr_speed1;
1488 1.7 dante } else if (tid == 4) {
1489 1.7 dante sdtr_speed = sc->sdtr_speed2;
1490 1.7 dante } else if (tid == 8) {
1491 1.7 dante sdtr_speed = sc->sdtr_speed3;
1492 1.7 dante } else if (tid == 12) {
1493 1.7 dante sdtr_speed = sc->sdtr_speed4;
1494 1.7 dante }
1495 1.7 dante if (sdtr_speed & ADW_MAX_TID) {
1496 1.7 dante sc->sdtr_able |= (1 << tid);
1497 1.7 dante }
1498 1.7 dante sdtr_speed >>= 4;
1499 1.7 dante }
1500 1.7 dante
1501 1.7 dante /*
1502 1.7 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
1503 1.7 dante * maximum queuing (max. 63, min. 4).
1504 1.7 dante */
1505 1.7 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
1506 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1507 1.7 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
1508 1.7 dante /* If the value is zero, assume it is uninitialized. */
1509 1.7 dante if (eep_config.max_host_qng == 0) {
1510 1.7 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
1511 1.7 dante } else {
1512 1.7 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
1513 1.7 dante }
1514 1.7 dante }
1515 1.7 dante
1516 1.7 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
1517 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1518 1.7 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
1519 1.7 dante /* If the value is zero, assume it is uninitialized. */
1520 1.7 dante if (eep_config.max_dvc_qng == 0) {
1521 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
1522 1.7 dante } else {
1523 1.7 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
1524 1.7 dante }
1525 1.7 dante }
1526 1.7 dante
1527 1.7 dante /*
1528 1.7 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
1529 1.7 dante * set 'max_dvc_qng' to 'max_host_qng'.
1530 1.7 dante */
1531 1.7 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
1532 1.7 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
1533 1.7 dante }
1534 1.7 dante
1535 1.7 dante /*
1536 1.7 dante * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
1537 1.7 dante * values based on possibly adjusted EEPROM values.
1538 1.7 dante */
1539 1.7 dante sc->max_host_qng = eep_config.max_host_qng;
1540 1.7 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
1541 1.7 dante
1542 1.7 dante /*
1543 1.7 dante * If the EEPROM 'termination' field is set to automatic (0), then set
1544 1.7 dante * the ADV_DVC_CFG 'termination' field to automatic also.
1545 1.7 dante *
1546 1.7 dante * If the termination is specified with a non-zero 'termination'
1547 1.7 dante * value check that a legal value is set and set the ADV_DVC_CFG
1548 1.7 dante * 'termination' field appropriately.
1549 1.7 dante */
1550 1.7 dante if (eep_config.termination_se == 0) {
1551 1.7 dante termination = 0; /* auto termination for SE */
1552 1.7 dante } else {
1553 1.7 dante /* Enable manual control with low off / high off. */
1554 1.7 dante if (eep_config.termination_se == 1) {
1555 1.7 dante termination = 0;
1556 1.7 dante
1557 1.7 dante /* Enable manual control with low off / high on. */
1558 1.7 dante } else if (eep_config.termination_se == 2) {
1559 1.7 dante termination = ADW_TERM_SE_HI;
1560 1.7 dante
1561 1.7 dante /* Enable manual control with low on / high on. */
1562 1.7 dante } else if (eep_config.termination_se == 3) {
1563 1.7 dante termination = ADW_TERM_SE;
1564 1.7 dante } else {
1565 1.7 dante /*
1566 1.7 dante * The EEPROM 'termination_se' field contains
1567 1.7 dante * a bad value.
1568 1.7 dante * Use automatic termination instead.
1569 1.7 dante */
1570 1.7 dante termination = 0;
1571 1.7 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
1572 1.7 dante }
1573 1.7 dante }
1574 1.7 dante
1575 1.7 dante if (eep_config.termination_lvd == 0) {
1576 1.7 dante /* auto termination for LVD */
1577 1.7 dante sc->cfg.termination = termination;
1578 1.7 dante } else
1579 1.7 dante {
1580 1.7 dante /* Enable manual control with low off / high off. */
1581 1.7 dante if (eep_config.termination_lvd == 1) {
1582 1.7 dante sc->cfg.termination = termination;
1583 1.7 dante
1584 1.7 dante /* Enable manual control with low off / high on. */
1585 1.7 dante } else if (eep_config.termination_lvd == 2) {
1586 1.7 dante sc->cfg.termination = termination | ADW_TERM_LVD_HI;
1587 1.7 dante
1588 1.7 dante /* Enable manual control with low on / high on. */
1589 1.7 dante } else if (eep_config.termination_lvd == 3) {
1590 1.7 dante sc->cfg.termination = termination | ADW_TERM_LVD;
1591 1.7 dante } else {
1592 1.7 dante /*
1593 1.7 dante * The EEPROM 'termination_lvd' field contains a bad value.
1594 1.7 dante * Use automatic termination instead.
1595 1.7 dante */
1596 1.7 dante sc->cfg.termination = termination;
1597 1.7 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
1598 1.7 dante }
1599 1.7 dante }
1600 1.7 dante
1601 1.7 dante return warn_code;
1602 1.7 dante }
1603 1.7 dante
1604 1.7 dante
1605 1.7 dante /*
1606 1.7 dante * Read EEPROM configuration into the specified buffer.
1607 1.7 dante *
1608 1.7 dante * Return a checksum based on the EEPROM configuration read.
1609 1.7 dante */
1610 1.7 dante static u_int16_t
1611 1.7 dante AdvGet3550EEPConfig(iot, ioh, cfg_buf)
1612 1.7 dante bus_space_tag_t iot;
1613 1.7 dante bus_space_handle_t ioh;
1614 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
1615 1.7 dante {
1616 1.7 dante u_int16_t wval, chksum;
1617 1.7 dante u_int16_t *wbuf;
1618 1.7 dante int eep_addr;
1619 1.7 dante
1620 1.7 dante
1621 1.7 dante wbuf = (u_int16_t *) cfg_buf;
1622 1.7 dante chksum = 0;
1623 1.7 dante
1624 1.7 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
1625 1.7 dante eep_addr < ASC_EEP_DVC_CFG_END;
1626 1.7 dante eep_addr++, wbuf++) {
1627 1.7 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
1628 1.7 dante chksum += wval;
1629 1.7 dante *wbuf = wval;
1630 1.7 dante }
1631 1.7 dante
1632 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
1633 1.7 dante wbuf++;
1634 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
1635 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
1636 1.7 dante eep_addr++, wbuf++) {
1637 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
1638 1.7 dante }
1639 1.7 dante
1640 1.7 dante return chksum;
1641 1.7 dante }
1642 1.7 dante
1643 1.7 dante
1644 1.7 dante /*
1645 1.7 dante * Read EEPROM configuration into the specified buffer.
1646 1.7 dante *
1647 1.7 dante * Return a checksum based on the EEPROM configuration read.
1648 1.7 dante */
1649 1.7 dante static u_int16_t
1650 1.7 dante AdvGet38C0800EEPConfig(iot, ioh, cfg_buf)
1651 1.7 dante bus_space_tag_t iot;
1652 1.7 dante bus_space_handle_t ioh;
1653 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
1654 1.7 dante {
1655 1.7 dante u_int16_t wval, chksum;
1656 1.7 dante u_int16_t *wbuf;
1657 1.7 dante int eep_addr;
1658 1.7 dante
1659 1.7 dante
1660 1.7 dante wbuf = (u_int16_t *) cfg_buf;
1661 1.7 dante chksum = 0;
1662 1.1 dante
1663 1.1 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
1664 1.7 dante eep_addr < ASC_EEP_DVC_CFG_END;
1665 1.7 dante eep_addr++, wbuf++) {
1666 1.1 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
1667 1.1 dante chksum += wval;
1668 1.1 dante *wbuf = wval;
1669 1.1 dante }
1670 1.7 dante
1671 1.1 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
1672 1.1 dante wbuf++;
1673 1.7 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
1674 1.7 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
1675 1.7 dante eep_addr++, wbuf++) {
1676 1.7 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
1677 1.7 dante }
1678 1.7 dante
1679 1.7 dante return chksum;
1680 1.7 dante }
1681 1.7 dante
1682 1.7 dante
1683 1.7 dante /*
1684 1.7 dante * Read the EEPROM from specified location
1685 1.7 dante */
1686 1.7 dante static u_int16_t
1687 1.7 dante AdvReadEEPWord(iot, ioh, eep_word_addr)
1688 1.7 dante bus_space_tag_t iot;
1689 1.7 dante bus_space_handle_t ioh;
1690 1.7 dante int eep_word_addr;
1691 1.7 dante {
1692 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1693 1.7 dante ASC_EEP_CMD_READ | eep_word_addr);
1694 1.7 dante AdvWaitEEPCmd(iot, ioh);
1695 1.7 dante
1696 1.7 dante return ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_DATA);
1697 1.7 dante }
1698 1.7 dante
1699 1.7 dante
1700 1.7 dante /*
1701 1.7 dante * Wait for EEPROM command to complete
1702 1.7 dante */
1703 1.7 dante static void
1704 1.7 dante AdvWaitEEPCmd(iot, ioh)
1705 1.7 dante bus_space_tag_t iot;
1706 1.7 dante bus_space_handle_t ioh;
1707 1.7 dante {
1708 1.7 dante int eep_delay_ms;
1709 1.7 dante
1710 1.7 dante
1711 1.7 dante for (eep_delay_ms = 0; eep_delay_ms < ASC_EEP_DELAY_MS; eep_delay_ms++){
1712 1.7 dante if (ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD) &
1713 1.7 dante ASC_EEP_CMD_DONE) {
1714 1.7 dante break;
1715 1.7 dante }
1716 1.7 dante AdvSleepMilliSecond(1);
1717 1.7 dante }
1718 1.7 dante
1719 1.7 dante ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD);
1720 1.7 dante }
1721 1.7 dante
1722 1.7 dante
1723 1.7 dante /*
1724 1.7 dante * Write the EEPROM from 'cfg_buf'.
1725 1.7 dante */
1726 1.7 dante static void
1727 1.7 dante AdvSet3550EEPConfig(iot, ioh, cfg_buf)
1728 1.7 dante bus_space_tag_t iot;
1729 1.7 dante bus_space_handle_t ioh;
1730 1.7 dante ADW_EEP_3550_CONFIG *cfg_buf;
1731 1.7 dante {
1732 1.7 dante u_int16_t *wbuf;
1733 1.7 dante u_int16_t addr, chksum;
1734 1.7 dante
1735 1.7 dante
1736 1.7 dante wbuf = (u_int16_t *) cfg_buf;
1737 1.7 dante chksum = 0;
1738 1.7 dante
1739 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
1740 1.7 dante AdvWaitEEPCmd(iot, ioh);
1741 1.7 dante
1742 1.7 dante /*
1743 1.7 dante * Write EEPROM from word 0 to word 20
1744 1.7 dante */
1745 1.7 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
1746 1.7 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
1747 1.7 dante chksum += *wbuf;
1748 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
1749 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1750 1.7 dante ASC_EEP_CMD_WRITE | addr);
1751 1.7 dante AdvWaitEEPCmd(iot, ioh);
1752 1.7 dante AdvSleepMilliSecond(ASC_EEP_DELAY_MS);
1753 1.7 dante }
1754 1.7 dante
1755 1.7 dante /*
1756 1.7 dante * Write EEPROM checksum at word 21
1757 1.7 dante */
1758 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
1759 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1760 1.7 dante ASC_EEP_CMD_WRITE | addr);
1761 1.7 dante AdvWaitEEPCmd(iot, ioh);
1762 1.7 dante wbuf++; /* skip over check_sum */
1763 1.7 dante
1764 1.7 dante /*
1765 1.7 dante * Write EEPROM OEM name at words 22 to 29
1766 1.7 dante */
1767 1.7 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
1768 1.7 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
1769 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
1770 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1771 1.7 dante ASC_EEP_CMD_WRITE | addr);
1772 1.7 dante AdvWaitEEPCmd(iot, ioh);
1773 1.1 dante }
1774 1.1 dante
1775 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1776 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
1777 1.4 thorpej AdvWaitEEPCmd(iot, ioh);
1778 1.1 dante
1779 1.1 dante return;
1780 1.1 dante }
1781 1.1 dante
1782 1.7 dante
1783 1.1 dante /*
1784 1.1 dante * Write the EEPROM from 'cfg_buf'.
1785 1.1 dante */
1786 1.1 dante static void
1787 1.7 dante AdvSet38C0800EEPConfig(iot, ioh, cfg_buf)
1788 1.7 dante bus_space_tag_t iot;
1789 1.7 dante bus_space_handle_t ioh;
1790 1.7 dante ADW_EEP_38C0800_CONFIG *cfg_buf;
1791 1.1 dante {
1792 1.7 dante u_int16_t *wbuf;
1793 1.7 dante u_int16_t addr, chksum;
1794 1.7 dante
1795 1.1 dante
1796 1.1 dante wbuf = (u_int16_t *) cfg_buf;
1797 1.1 dante chksum = 0;
1798 1.1 dante
1799 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
1800 1.1 dante AdvWaitEEPCmd(iot, ioh);
1801 1.1 dante
1802 1.1 dante /*
1803 1.7 dante * Write EEPROM from word 0 to word 20
1804 1.1 dante */
1805 1.1 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
1806 1.2 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
1807 1.1 dante chksum += *wbuf;
1808 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
1809 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1810 1.7 dante ASC_EEP_CMD_WRITE | addr);
1811 1.1 dante AdvWaitEEPCmd(iot, ioh);
1812 1.7 dante AdvSleepMilliSecond(ASC_EEP_DELAY_MS);
1813 1.1 dante }
1814 1.1 dante
1815 1.1 dante /*
1816 1.7 dante * Write EEPROM checksum at word 21
1817 1.1 dante */
1818 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
1819 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1820 1.7 dante ASC_EEP_CMD_WRITE | addr);
1821 1.1 dante AdvWaitEEPCmd(iot, ioh);
1822 1.7 dante wbuf++; /* skip over check_sum */
1823 1.1 dante
1824 1.1 dante /*
1825 1.7 dante * Write EEPROM OEM name at words 22 to 29
1826 1.1 dante */
1827 1.1 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
1828 1.2 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
1829 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
1830 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1831 1.7 dante ASC_EEP_CMD_WRITE | addr);
1832 1.1 dante AdvWaitEEPCmd(iot, ioh);
1833 1.1 dante }
1834 1.7 dante
1835 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
1836 1.7 dante ASC_EEP_CMD_WRITE_DISABLE);
1837 1.1 dante AdvWaitEEPCmd(iot, ioh);
1838 1.7 dante
1839 1.1 dante return;
1840 1.1 dante }
1841 1.1 dante
1842 1.7 dante
1843 1.1 dante /*
1844 1.7 dante * AdvExeScsiQueue() - Send a request to the RISC microcode program.
1845 1.7 dante *
1846 1.7 dante * Allocate a carrier structure, point the carrier to the ADW_SCSI_REQ_Q,
1847 1.7 dante * add the carrier to the ICQ (Initiator Command Queue), and tickle the
1848 1.7 dante * RISC to notify it a new command is ready to be executed.
1849 1.1 dante *
1850 1.7 dante * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
1851 1.7 dante * set to SCSI_MAX_RETRY.
1852 1.1 dante *
1853 1.7 dante * Return:
1854 1.7 dante * ADW_SUCCESS(1) - The request was successfully queued.
1855 1.7 dante * ADW_BUSY(0) - Resource unavailable; Retry again after pending
1856 1.7 dante * request completes.
1857 1.7 dante * ADW_ERROR(-1) - Invalid ADW_SCSI_REQ_Q request structure
1858 1.7 dante * host IC error.
1859 1.1 dante */
1860 1.7 dante int
1861 1.7 dante AdvExeScsiQueue(sc, scsiq)
1862 1.7 dante ADW_SOFTC *sc;
1863 1.7 dante ADW_SCSI_REQ_Q *scsiq;
1864 1.1 dante {
1865 1.7 dante bus_space_tag_t iot = sc->sc_iot;
1866 1.7 dante bus_space_handle_t ioh = sc->sc_ioh;
1867 1.7 dante ADW_CCB *ccb;
1868 1.7 dante long req_size;
1869 1.7 dante u_int32_t req_paddr;
1870 1.7 dante ADW_CARRIER *new_carrp/*, *ccb_carr;
1871 1.7 dante int i*/;
1872 1.7 dante
1873 1.7 dante
1874 1.7 dante /*
1875 1.7 dante * The ADW_SCSI_REQ_Q 'target_id' field should never exceed ADW_MAX_TID.
1876 1.7 dante */
1877 1.7 dante if (scsiq->target_id > ADW_MAX_TID) {
1878 1.7 dante scsiq->host_status = QHSTA_M_INVALID_DEVICE;
1879 1.7 dante scsiq->done_status = QD_WITH_ERROR;
1880 1.7 dante return ADW_ERROR;
1881 1.7 dante }
1882 1.7 dante
1883 1.7 dante ccb = adw_ccb_phys_kv(sc, scsiq->ccb_ptr);
1884 1.7 dante ccb->carr_list = sc->icq_sp;
1885 1.7 dante
1886 1.7 dante /*
1887 1.7 dante * Allocate a carrier ensuring at least one carrier always
1888 1.7 dante * remains on the freelist and initialize fields.
1889 1.7 dante */
1890 1.7 dante if ((new_carrp = sc->carr_freelist) == NULL) {
1891 1.7 dante return ADW_BUSY;
1892 1.7 dante }
1893 1.7 dante sc->carr_freelist = adw_carrier_phys_kv(sc,
1894 1.7 dante ASC_GET_CARRP(new_carrp->next_vpa));
1895 1.7 dante sc->carr_pending_cnt++;
1896 1.7 dante
1897 1.7 dante /*
1898 1.7 dante * Set the carrier to be a stopper by setting 'next_vpa'
1899 1.7 dante * to the stopper value. The current stopper will be changed
1900 1.7 dante * below to point to the new stopper.
1901 1.7 dante */
1902 1.7 dante new_carrp->next_vpa = ASC_CQ_STOPPER;
1903 1.7 dante
1904 1.7 dante req_size = sizeof(ADW_SCSI_REQ_Q);
1905 1.7 dante req_paddr = sc->sc_dmamap_control->dm_segs[0].ds_addr +
1906 1.7 dante ADW_CCB_OFF(ccb) + offsetof(struct adw_ccb, scsiq);
1907 1.7 dante
1908 1.7 dante /* Save physical address of ADW_SCSI_REQ_Q and Carrier. */
1909 1.7 dante scsiq->scsiq_rptr = req_paddr;
1910 1.7 dante
1911 1.7 dante /*
1912 1.7 dante * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
1913 1.7 dante * order during initialization.
1914 1.7 dante */
1915 1.7 dante scsiq->carr_pa = sc->icq_sp->carr_pa;
1916 1.7 dante scsiq->carr_va = sc->icq_sp->carr_pa;
1917 1.1 dante
1918 1.7 dante /*
1919 1.7 dante * Use the current stopper to send the ADW_SCSI_REQ_Q command to
1920 1.7 dante * the microcode. The newly allocated stopper will become the new
1921 1.7 dante * stopper.
1922 1.7 dante */
1923 1.7 dante sc->icq_sp->areq_vpa = req_paddr;
1924 1.1 dante
1925 1.1 dante /*
1926 1.7 dante * Set the 'next_vpa' pointer for the old stopper to be the
1927 1.7 dante * physical address of the new stopper. The RISC can only
1928 1.7 dante * follow physical addresses.
1929 1.1 dante */
1930 1.7 dante sc->icq_sp->next_vpa = new_carrp->carr_pa;
1931 1.1 dante
1932 1.1 dante /*
1933 1.7 dante * Set the host adapter stopper pointer to point to the new carrier.
1934 1.1 dante */
1935 1.7 dante sc->icq_sp = new_carrp;
1936 1.7 dante
1937 1.7 dante /* ccb_carr = ccb->carr_list;
1938 1.7 dante while(ccb_carr != ASC_CQ_STOPPER) {
1939 1.7 dante bus_dmamap_load(sc->sc_dmat, ccb_carr->dmamap_xfer,
1940 1.7 dante ccb_carr, ADW_CARRIER_SIZE,
1941 1.7 dante NULL, BUS_DMA_NOWAIT);
1942 1.7 dante bus_dmamap_sync(sc->sc_dmat, ccb_carr->dmamap_xfer, 0,
1943 1.7 dante ccb_carr->dmamap_xfer->dm_mapsize,
1944 1.7 dante BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1945 1.7 dante ccb_carr = adw_carrier_phys_kv(sc,
1946 1.7 dante ASC_GET_CARRP(ccb_carr->next_vpa));
1947 1.7 dante }
1948 1.1 dante
1949 1.7 dante ccb_carr = sc->irq_sp;
1950 1.7 dante for(i=0; i<2 && ccb_carr != ASC_CQ_STOPPER; i++) {
1951 1.7 dante bus_dmamap_load(sc->sc_dmat, ccb_carr->dmamap_xfer,
1952 1.7 dante ccb_carr, ADW_CARRIER_SIZE,
1953 1.7 dante NULL, BUS_DMA_NOWAIT);
1954 1.7 dante bus_dmamap_sync(sc->sc_dmat, ccb_carr->dmamap_xfer, 0,
1955 1.7 dante ccb_carr->dmamap_xfer->dm_mapsize,
1956 1.7 dante BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1957 1.7 dante ccb_carr = adw_carrier_phys_kv(sc,
1958 1.7 dante ASC_GET_CARRP(ccb_carr->next_vpa));
1959 1.7 dante }
1960 1.7 dante */
1961 1.7 dante bus_dmamap_load(sc->sc_dmat, sc->sc_control->dmamap_xfer,
1962 1.7 dante sc->sc_control->carriers, ADW_CARRIER_SIZE * ADW_MAX_CARRIER,
1963 1.7 dante NULL, BUS_DMA_NOWAIT);
1964 1.7 dante bus_dmamap_sync(sc->sc_dmat, sc->sc_control->dmamap_xfer, 0,
1965 1.7 dante sc->sc_control->dmamap_xfer->dm_mapsize,
1966 1.7 dante BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
1967 1.1 dante
1968 1.1 dante /*
1969 1.7 dante * Tickle the RISC to tell it to read its Command Queue Head pointer.
1970 1.1 dante */
1971 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_A);
1972 1.7 dante if (sc->chip_type == ADV_CHIP_ASC3550)
1973 1.7 dante {
1974 1.7 dante /*
1975 1.7 dante * Clear the tickle value. In the ASC-3550 the RISC flag
1976 1.7 dante * command 'clr_tickle_a' does not work unless the host
1977 1.7 dante * value is cleared.
1978 1.7 dante */
1979 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_NOP);
1980 1.7 dante }
1981 1.7 dante
1982 1.7 dante return ADW_SUCCESS;
1983 1.1 dante }
1984 1.1 dante
1985 1.7 dante
1986 1.7 dante void
1987 1.7 dante AdvResetChip(iot, ioh)
1988 1.7 dante bus_space_tag_t iot;
1989 1.7 dante bus_space_handle_t ioh;
1990 1.1 dante {
1991 1.7 dante
1992 1.7 dante /*
1993 1.7 dante * Reset Chip.
1994 1.7 dante */
1995 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
1996 1.7 dante ADW_CTRL_REG_CMD_RESET);
1997 1.7 dante AdvSleepMilliSecond(100);
1998 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
1999 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
2000 1.1 dante }
2001 1.1 dante
2002 1.7 dante
2003 1.1 dante /*
2004 1.1 dante * Reset SCSI Bus and purge all outstanding requests.
2005 1.1 dante *
2006 1.1 dante * Return Value:
2007 1.7 dante * ADW_TRUE(1) - All requests are purged and SCSI Bus is reset.
2008 1.7 dante * ADW_FALSE(0) - Microcode command failed.
2009 1.7 dante * ADW_ERROR(-1) - Microcode command timed-out. Microcode or IC
2010 1.7 dante * may be hung which requires driver recovery.
2011 1.1 dante */
2012 1.1 dante int
2013 1.1 dante AdvResetCCB(sc)
2014 1.7 dante ADW_SOFTC *sc;
2015 1.1 dante {
2016 1.7 dante int status;
2017 1.7 dante
2018 1.7 dante /*
2019 1.7 dante * Send the SCSI Bus Reset idle start idle command which asserts
2020 1.7 dante * the SCSI Bus Reset signal.
2021 1.7 dante */
2022 1.7 dante status = AdvSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_START, 0L);
2023 1.7 dante if (status != ADW_TRUE)
2024 1.7 dante {
2025 1.7 dante return status;
2026 1.7 dante }
2027 1.7 dante
2028 1.7 dante /*
2029 1.7 dante * Delay for the specified SCSI Bus Reset hold time.
2030 1.7 dante *
2031 1.7 dante * The hold time delay is done on the host because the RISC has no
2032 1.7 dante * microsecond accurate timer.
2033 1.7 dante */
2034 1.7 dante AdvDelayMicroSecond((u_int16_t) ASC_SCSI_RESET_HOLD_TIME_US);
2035 1.1 dante
2036 1.7 dante /*
2037 1.7 dante * Send the SCSI Bus Reset end idle command which de-asserts
2038 1.7 dante * the SCSI Bus Reset signal and purges any pending requests.
2039 1.7 dante */
2040 1.7 dante status = AdvSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET_END, 0L);
2041 1.7 dante if (status != ADW_TRUE)
2042 1.7 dante {
2043 1.7 dante return status;
2044 1.7 dante }
2045 1.1 dante
2046 1.7 dante AdvSleepMilliSecond((u_int32_t) sc->scsi_reset_wait * 1000);
2047 1.1 dante
2048 1.1 dante return status;
2049 1.1 dante }
2050 1.1 dante
2051 1.7 dante
2052 1.1 dante /*
2053 1.7 dante * Reset chip and SCSI Bus.
2054 1.7 dante *
2055 1.7 dante * Return Value:
2056 1.7 dante * ADW_TRUE(1) - Chip re-initialization and SCSI Bus Reset successful.
2057 1.7 dante * ADW_FALSE(0) - Chip re-initialization and SCSI Bus Reset failure.
2058 1.1 dante */
2059 1.7 dante int
2060 1.1 dante AdvResetSCSIBus(sc)
2061 1.7 dante ADW_SOFTC *sc;
2062 1.1 dante {
2063 1.2 dante bus_space_tag_t iot = sc->sc_iot;
2064 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
2065 1.7 dante int status;
2066 1.7 dante u_int16_t wdtr_able, sdtr_able, tagqng_able;
2067 1.7 dante u_int8_t tid, max_cmd[ADW_MAX_TID + 1];
2068 1.7 dante u_int16_t bios_sig;
2069 1.7 dante
2070 1.7 dante
2071 1.7 dante /*
2072 1.7 dante * Save current per TID negotiated values.
2073 1.7 dante */
2074 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
2075 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
2076 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
2077 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++)
2078 1.7 dante {
2079 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
2080 1.7 dante max_cmd[tid]);
2081 1.7 dante }
2082 1.7 dante
2083 1.7 dante /*
2084 1.7 dante * Force the AdvInitAsc3550/38C0800Driver() function to
2085 1.7 dante * perform a SCSI Bus Reset by clearing the BIOS signature word.
2086 1.7 dante * The initialization functions assumes a SCSI Bus Reset is not
2087 1.7 dante * needed if the BIOS signature word is present.
2088 1.7 dante */
2089 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, bios_sig);
2090 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, 0);
2091 1.7 dante
2092 1.7 dante /*
2093 1.7 dante * Stop chip and reset it.
2094 1.7 dante */
2095 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_STOP);
2096 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2097 1.7 dante ADW_CTRL_REG_CMD_RESET);
2098 1.7 dante AdvSleepMilliSecond(100);
2099 1.7 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
2100 1.7 dante ADW_CTRL_REG_CMD_WR_IO_REG);
2101 1.7 dante
2102 1.7 dante /*
2103 1.7 dante * Reset Adv Library error code, if any, and try
2104 1.7 dante * re-initializing the chip.
2105 1.7 dante */
2106 1.7 dante if (sc->chip_type == ADV_CHIP_ASC38C0800) {
2107 1.7 dante status = AdvInitAsc38C0800Driver(sc);
2108 1.7 dante } else {
2109 1.7 dante status = AdvInitAsc3550Driver(sc);
2110 1.7 dante }
2111 1.1 dante
2112 1.7 dante /* Translate initialization return value to status value. */
2113 1.7 dante if (status == 0) {
2114 1.7 dante status = ADW_TRUE;
2115 1.7 dante } else {
2116 1.7 dante status = ADW_FALSE;
2117 1.7 dante }
2118 1.1 dante
2119 1.7 dante /*
2120 1.7 dante * Restore the BIOS signature word.
2121 1.7 dante */
2122 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_BIOS_SIGNATURE, bios_sig);
2123 1.1 dante
2124 1.1 dante /*
2125 1.7 dante * Restore per TID negotiated values.
2126 1.1 dante */
2127 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE, wdtr_able);
2128 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, sdtr_able);
2129 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE, tagqng_able);
2130 1.7 dante for (tid = 0; tid <= ADW_MAX_TID; tid++) {
2131 1.7 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_NUMBER_OF_MAX_CMD + tid,
2132 1.7 dante max_cmd[tid]);
2133 1.7 dante }
2134 1.1 dante
2135 1.7 dante return status;
2136 1.1 dante }
2137 1.1 dante
2138 1.1 dante
2139 1.1 dante /*
2140 1.1 dante * Adv Library Interrupt Service Routine
2141 1.1 dante *
2142 1.1 dante * This function is called by a driver's interrupt service routine.
2143 1.1 dante * The function disables and re-enables interrupts.
2144 1.1 dante *
2145 1.7 dante * When a microcode idle command is completed, the ADV_DVC_VAR
2146 1.1 dante * 'idle_cmd_done' field is set to ADW_TRUE.
2147 1.1 dante *
2148 1.1 dante * Note: AdvISR() can be called when interrupts are disabled or even
2149 1.1 dante * when there is no hardware interrupt condition present. It will
2150 1.1 dante * always check for completed idle commands and microcode requests.
2151 1.1 dante * This is an important feature that shouldn't be changed because it
2152 1.1 dante * allows commands to be completed from polling mode loops.
2153 1.1 dante *
2154 1.1 dante * Return:
2155 1.1 dante * ADW_TRUE(1) - interrupt was pending
2156 1.1 dante * ADW_FALSE(0) - no interrupt was pending
2157 1.1 dante */
2158 1.1 dante int
2159 1.1 dante AdvISR(sc)
2160 1.7 dante ADW_SOFTC *sc;
2161 1.1 dante {
2162 1.2 dante bus_space_tag_t iot = sc->sc_iot;
2163 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
2164 1.7 dante u_int8_t int_stat;
2165 1.7 dante u_int16_t target_bit;
2166 1.7 dante ADW_CARRIER *free_carrp/*, *ccb_carr*/;
2167 1.7 dante u_int32_t irq_next_pa;
2168 1.7 dante ADW_SCSI_REQ_Q *scsiq;
2169 1.7 dante ADW_CCB *ccb;
2170 1.7 dante // int i;
2171 1.1 dante
2172 1.1 dante
2173 1.1 dante /* Reading the register clears the interrupt. */
2174 1.1 dante int_stat = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_INTR_STATUS_REG);
2175 1.1 dante
2176 1.7 dante if ((int_stat & (ADW_INTR_STATUS_INTRA | ADW_INTR_STATUS_INTRB |
2177 1.7 dante ADW_INTR_STATUS_INTRC)) == 0) {
2178 1.7 dante return ADW_FALSE;
2179 1.1 dante }
2180 1.7 dante
2181 1.7 dante bus_dmamap_sync(sc->sc_dmat, sc->sc_control->dmamap_xfer, 0,
2182 1.7 dante sc->sc_control->dmamap_xfer->dm_mapsize,
2183 1.7 dante BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2184 1.7 dante bus_dmamap_unload(sc->sc_dmat, sc->sc_control->dmamap_xfer);
2185 1.7 dante
2186 1.7 dante /* ccb_carr = sc->irq_sp;
2187 1.7 dante for(i=0; i<2 && ccb_carr != ASC_CQ_STOPPER; i++) {
2188 1.7 dante bus_dmamap_sync(sc->sc_dmat, ccb_carr->dmamap_xfer, 0,
2189 1.7 dante ccb_carr->dmamap_xfer->dm_mapsize,
2190 1.7 dante BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2191 1.7 dante bus_dmamap_unload(sc->sc_dmat, ccb_carr->dmamap_xfer);
2192 1.7 dante ccb_carr = adw_carrier_phys_kv(sc,
2193 1.7 dante ASC_GET_CARRP(ccb_carr->next_vpa));
2194 1.7 dante }
2195 1.7 dante */
2196 1.7 dante /*
2197 1.7 dante * Notify the driver of an asynchronous microcode condition by
2198 1.7 dante * calling the ADV_DVC_VAR.async_callback function. The function
2199 1.7 dante * is passed the microcode ASC_MC_INTRB_CODE byte value.
2200 1.1 dante */
2201 1.7 dante if (int_stat & ADW_INTR_STATUS_INTRB) {
2202 1.7 dante u_int8_t intrb_code;
2203 1.7 dante
2204 1.7 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_INTRB_CODE, intrb_code);
2205 1.7 dante if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
2206 1.7 dante sc->carr_pending_cnt != 0) {
2207 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_A);
2208 1.7 dante if (sc->chip_type == ADV_CHIP_ASC3550) {
2209 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_NOP);
2210 1.7 dante }
2211 1.7 dante }
2212 1.7 dante
2213 1.7 dante if (sc->async_callback != 0) {
2214 1.7 dante (*(ADW_ASYNC_CALLBACK)sc->async_callback)(sc, intrb_code);
2215 1.1 dante }
2216 1.1 dante }
2217 1.7 dante
2218 1.1 dante /*
2219 1.7 dante * Check if the IRQ stopper carrier contains a completed request.
2220 1.1 dante */
2221 1.7 dante while (((irq_next_pa = sc->irq_sp->next_vpa) & ASC_RQ_DONE) != 0)
2222 1.7 dante {
2223 1.7 dante /*
2224 1.7 dante * Get a pointer to the newly completed ADW_SCSI_REQ_Q structure.
2225 1.7 dante * The RISC will have set 'areq_vpa' to a virtual address.
2226 1.7 dante *
2227 1.7 dante * The firmware will have copied the ASC_SCSI_REQ_Q.ccb_ptr
2228 1.7 dante * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
2229 1.7 dante * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
2230 1.7 dante * in AdvExeScsiQueue().
2231 1.7 dante */
2232 1.7 dante ccb = adw_ccb_phys_kv(sc, sc->irq_sp->areq_vpa);
2233 1.7 dante scsiq = &ccb->scsiq;
2234 1.7 dante scsiq->ccb_ptr = sc->irq_sp->areq_vpa;
2235 1.7 dante
2236 1.7 dante /* ccb_carr = ccb->carr_list;
2237 1.7 dante while(ccb_carr != ASC_CQ_STOPPER) {
2238 1.7 dante bus_dmamap_sync(sc->sc_dmat, ccb_carr->dmamap_xfer, 0,
2239 1.7 dante ccb_carr->dmamap_xfer->dm_mapsize,
2240 1.7 dante BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2241 1.7 dante bus_dmamap_unload(sc->sc_dmat, ccb_carr->dmamap_xfer);
2242 1.7 dante ccb_carr = adw_carrier_phys_kv(sc,
2243 1.7 dante ASC_GET_CARRP(ccb_carr->next_vpa));
2244 1.7 dante }
2245 1.1 dante
2246 1.7 dante bus_dmamap_sync(sc->sc_dmat, sc->irq_sp->dmamap_xfer, 0,
2247 1.7 dante sc->irq_sp->dmamap_xfer->dm_mapsize,
2248 1.7 dante BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
2249 1.7 dante bus_dmamap_unload(sc->sc_dmat, sc->irq_sp->dmamap_xfer);
2250 1.7 dante */
2251 1.1 dante /*
2252 1.7 dante * Advance the stopper pointer to the next carrier
2253 1.7 dante * ignoring the lower four bits. Free the previous
2254 1.7 dante * stopper carrier.
2255 1.1 dante */
2256 1.7 dante free_carrp = sc->irq_sp;
2257 1.7 dante sc->irq_sp = adw_carrier_phys_kv(sc, ASC_GET_CARRP(irq_next_pa));
2258 1.7 dante
2259 1.7 dante free_carrp->next_vpa = sc->carr_freelist->carr_pa;
2260 1.7 dante sc->carr_freelist = free_carrp;
2261 1.7 dante sc->carr_pending_cnt--;
2262 1.1 dante
2263 1.1 dante
2264 1.1 dante target_bit = ADW_TID_TO_TIDMASK(scsiq->target_id);
2265 1.1 dante
2266 1.1 dante /*
2267 1.1 dante * Clear request microcode control flag.
2268 1.1 dante */
2269 1.1 dante scsiq->cntl = 0;
2270 1.1 dante
2271 1.1 dante /*
2272 1.1 dante * Check Condition handling
2273 1.1 dante */
2274 1.1 dante /*
2275 1.1 dante * If the command that completed was a SCSI INQUIRY and
2276 1.1 dante * LUN 0 was sent the command, then process the INQUIRY
2277 1.1 dante * command information for the device.
2278 1.1 dante */
2279 1.7 dante if (scsiq->done_status == QD_NO_ERROR &&
2280 1.7 dante scsiq->cdb[0] == INQUIRY &&
2281 1.7 dante scsiq->target_lun == 0) {
2282 1.1 dante AdvInquiryHandling(sc, scsiq);
2283 1.1 dante }
2284 1.1 dante
2285 1.1 dante /*
2286 1.1 dante * Notify the driver of the completed request by passing
2287 1.1 dante * the ADW_SCSI_REQ_Q pointer to its callback function.
2288 1.1 dante */
2289 1.7 dante (*(ADW_ISR_CALLBACK)sc->isr_callback)(sc, scsiq);
2290 1.1 dante /*
2291 1.1 dante * Note: After the driver callback function is called, 'scsiq'
2292 1.1 dante * can no longer be referenced.
2293 1.1 dante *
2294 1.1 dante * Fall through and continue processing other completed
2295 1.1 dante * requests...
2296 1.1 dante */
2297 1.1 dante }
2298 1.7 dante
2299 1.7 dante return ADW_TRUE;
2300 1.1 dante }
2301 1.1 dante
2302 1.7 dante
2303 1.1 dante /*
2304 1.1 dante * Send an idle command to the chip and wait for completion.
2305 1.1 dante *
2306 1.7 dante * Command completion is polled for once per microsecond.
2307 1.7 dante *
2308 1.7 dante * The function can be called from anywhere including an interrupt handler.
2309 1.7 dante * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
2310 1.7 dante * functions to prevent reentrancy.
2311 1.1 dante *
2312 1.1 dante * Return Values:
2313 1.1 dante * ADW_TRUE - command completed successfully
2314 1.1 dante * ADW_FALSE - command failed
2315 1.7 dante * ADW_ERROR - command timed out
2316 1.1 dante */
2317 1.1 dante int
2318 1.7 dante AdvSendIdleCmd(sc, idle_cmd, idle_cmd_parameter)
2319 1.7 dante ADW_SOFTC *sc;
2320 1.7 dante u_int16_t idle_cmd;
2321 1.7 dante u_int32_t idle_cmd_parameter;
2322 1.1 dante {
2323 1.2 dante bus_space_tag_t iot = sc->sc_iot;
2324 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
2325 1.7 dante int result;
2326 1.7 dante u_int32_t i, j;
2327 1.1 dante
2328 1.7 dante
2329 1.7 dante /*
2330 1.7 dante * Clear the idle command status which is set by the microcode
2331 1.7 dante * to a non-zero value to indicate when the command is completed.
2332 1.7 dante * The non-zero result is one of the IDLE_CMD_STATUS_* values
2333 1.7 dante * defined in a_advlib.h.
2334 1.7 dante */
2335 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_STATUS, (u_int16_t) 0);
2336 1.1 dante
2337 1.1 dante /*
2338 1.1 dante * Write the idle command value after the idle command parameter
2339 1.1 dante * has been written to avoid a race condition. If the order is not
2340 1.1 dante * followed, the microcode may process the idle command before the
2341 1.1 dante * parameters have been written to LRAM.
2342 1.1 dante */
2343 1.7 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_PARAMETER,
2344 1.7 dante idle_cmd_parameter);
2345 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD, idle_cmd);
2346 1.1 dante
2347 1.1 dante /*
2348 1.7 dante * Tickle the RISC to tell it to process the idle command.
2349 1.1 dante */
2350 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_B);
2351 1.7 dante if (sc->chip_type == ADV_CHIP_ASC3550) {
2352 1.1 dante /*
2353 1.7 dante * Clear the tickle value. In the ASC-3550 the RISC flag
2354 1.7 dante * command 'clr_tickle_b' does not work unless the host
2355 1.7 dante * value is cleared.
2356 1.1 dante */
2357 1.7 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_TICKLE, ADV_TICKLE_NOP);
2358 1.7 dante }
2359 1.1 dante
2360 1.7 dante /* Wait for up to 100 millisecond for the idle command to timeout. */
2361 1.7 dante for (i = 0; i < SCSI_WAIT_100_MSEC; i++) {
2362 1.7 dante /* Poll once each microsecond for command completion. */
2363 1.7 dante for (j = 0; j < SCSI_US_PER_MSEC; j++) {
2364 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD_STATUS, result);
2365 1.7 dante if (result != 0) {
2366 1.7 dante return result;
2367 1.7 dante }
2368 1.7 dante AdvDelayMicroSecond(1);
2369 1.7 dante }
2370 1.1 dante }
2371 1.1 dante
2372 1.7 dante return ADW_ERROR;
2373 1.1 dante }
2374 1.1 dante
2375 1.1 dante
2376 1.1 dante /*
2377 1.1 dante * Inquiry Information Byte 7 Handling
2378 1.1 dante *
2379 1.1 dante * Handle SCSI Inquiry Command information for a device by setting
2380 1.2 dante * microcode operating variables that affect WDTR, SDTR, and Tag
2381 1.1 dante * Queuing.
2382 1.1 dante */
2383 1.1 dante static void
2384 1.1 dante AdvInquiryHandling(sc, scsiq)
2385 1.7 dante ADW_SOFTC *sc;
2386 1.7 dante ADW_SCSI_REQ_Q *scsiq;
2387 1.1 dante {
2388 1.9 dante #ifndef FAILSAFE
2389 1.2 dante bus_space_tag_t iot = sc->sc_iot;
2390 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
2391 1.7 dante u_int8_t tid;
2392 1.7 dante ADW_SCSI_INQUIRY *inq;
2393 1.7 dante u_int16_t tidmask;
2394 1.7 dante u_int16_t cfg_word;
2395 1.7 dante
2396 1.1 dante
2397 1.1 dante /*
2398 1.1 dante * AdvInquiryHandling() requires up to INQUIRY information Byte 7
2399 1.1 dante * to be available.
2400 1.1 dante *
2401 1.1 dante * If less than 8 bytes of INQUIRY information were requested or less
2402 1.1 dante * than 8 bytes were transferred, then return. cdb[4] is the request
2403 1.1 dante * length and the ADW_SCSI_REQ_Q 'data_cnt' field is set by the
2404 1.1 dante * microcode to the transfer residual count.
2405 1.1 dante */
2406 1.7 dante
2407 1.2 dante if (scsiq->cdb[4] < 8 || (scsiq->cdb[4] - scsiq->data_cnt) < 8) {
2408 1.1 dante return;
2409 1.1 dante }
2410 1.7 dante
2411 1.1 dante tid = scsiq->target_id;
2412 1.7 dante
2413 1.7 dante inq = (ADW_SCSI_INQUIRY *) scsiq->vdata_addr;
2414 1.1 dante
2415 1.1 dante /*
2416 1.1 dante * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
2417 1.1 dante */
2418 1.7 dante if (inq->rsp_data_fmt < 2 && inq->ansi_apr_ver < 2) {
2419 1.1 dante return;
2420 1.2 dante } else {
2421 1.1 dante /*
2422 1.1 dante * INQUIRY Byte 7 Handling
2423 1.1 dante *
2424 1.1 dante * Use a device's INQUIRY byte 7 to determine whether it
2425 1.1 dante * supports WDTR, SDTR, and Tag Queuing. If the feature
2426 1.1 dante * is enabled in the EEPROM and the device supports the
2427 1.1 dante * feature, then enable it in the microcode.
2428 1.1 dante */
2429 1.1 dante
2430 1.1 dante tidmask = ADW_TID_TO_TIDMASK(tid);
2431 1.7 dante
2432 1.1 dante /*
2433 1.1 dante * Wide Transfers
2434 1.1 dante *
2435 1.1 dante * If the EEPROM enabled WDTR for the device and the device
2436 1.1 dante * supports wide bus (16 bit) transfers, then turn on the
2437 1.1 dante * device's 'wdtr_able' bit and write the new value to the
2438 1.1 dante * microcode.
2439 1.1 dante */
2440 1.7 dante #ifdef SCSI_ADW_WDTR_DISABLE
2441 1.8 dante if(!(tidmask & SCSI_ADW_WDTR_DISABLE))
2442 1.7 dante #endif /* SCSI_ADW_WDTR_DISABLE */
2443 1.7 dante if ((sc->wdtr_able & tidmask) && inq->WBus16) {
2444 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
2445 1.7 dante cfg_word);
2446 1.2 dante if ((cfg_word & tidmask) == 0) {
2447 1.1 dante cfg_word |= tidmask;
2448 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
2449 1.7 dante cfg_word);
2450 1.1 dante
2451 1.1 dante /*
2452 1.7 dante * Clear the microcode "SDTR negotiation" and "WDTR
2453 1.7 dante * negotiation" done indicators for the target to cause
2454 1.7 dante * it to negotiate with the new setting set above.
2455 1.7 dante * WDTR when accepted causes the target to enter
2456 1.7 dante * asynchronous mode, so SDTR must be negotiated.
2457 1.1 dante */
2458 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
2459 1.7 dante cfg_word);
2460 1.7 dante cfg_word &= ~tidmask;
2461 1.7 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
2462 1.7 dante cfg_word);
2463 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
2464 1.7 dante cfg_word);
2465 1.1 dante cfg_word &= ~tidmask;
2466 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
2467 1.7 dante cfg_word);
2468 1.1 dante }
2469 1.1 dante }
2470 1.7 dante
2471 1.1 dante /*
2472 1.1 dante * Synchronous Transfers
2473 1.1 dante *
2474 1.1 dante * If the EEPROM enabled SDTR for the device and the device
2475 1.1 dante * supports synchronous transfers, then turn on the device's
2476 1.1 dante * 'sdtr_able' bit. Write the new value to the microcode.
2477 1.1 dante */
2478 1.7 dante #ifdef SCSI_ADW_SDTR_DISABLE
2479 1.8 dante if(!(tidmask & SCSI_ADW_SDTR_DISABLE))
2480 1.7 dante #endif /* SCSI_ADW_SDTR_DISABLE */
2481 1.7 dante if ((sc->sdtr_able & tidmask) && inq->Sync) {
2482 1.7 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE, cfg_word);
2483 1.2 dante if ((cfg_word & tidmask) == 0) {
2484 1.1 dante cfg_word |= tidmask;
2485 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
2486 1.7 dante cfg_word);
2487 1.1 dante
2488 1.1 dante /*
2489 1.7 dante * Clear the microcode "SDTR negotiation" done indicator
2490 1.7 dante * for the target to cause it to negotiate with the new
2491 1.7 dante * setting set above.
2492 1.1 dante */
2493 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
2494 1.7 dante cfg_word);
2495 1.1 dante cfg_word &= ~tidmask;
2496 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
2497 1.7 dante cfg_word);
2498 1.1 dante }
2499 1.1 dante }
2500 1.7 dante
2501 1.1 dante /*
2502 1.7 dante * If the EEPROM enabled Tag Queuing for the device and the
2503 1.7 dante * device supports Tag Queueing, then turn on the device's
2504 1.1 dante * 'tagqng_enable' bit in the microcode and set the microcode
2505 1.7 dante * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
2506 1.1 dante * value.
2507 1.1 dante *
2508 1.1 dante * Tag Queuing is disabled for the BIOS which runs in polled
2509 1.1 dante * mode and would see no benefit from Tag Queuing. Also by
2510 1.1 dante * disabling Tag Queuing in the BIOS devices with Tag Queuing
2511 1.1 dante * bugs will at least work with the BIOS.
2512 1.1 dante */
2513 1.7 dante #ifdef SCSI_ADW_TAGQ_DISABLE
2514 1.8 dante if(!(tidmask & SCSI_ADW_TAGQ_DISABLE))
2515 1.7 dante #endif /* SCSI_ADW_TAGQ_DISABLE */
2516 1.7 dante if ((sc->tagqng_able & tidmask) && inq->CmdQue) {
2517 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
2518 1.7 dante cfg_word);
2519 1.1 dante cfg_word |= tidmask;
2520 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
2521 1.7 dante cfg_word);
2522 1.7 dante
2523 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
2524 1.7 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
2525 1.7 dante sc->max_dvc_qng);
2526 1.1 dante }
2527 1.9 dante }
2528 1.7 dante #endif /* FAILSAFE */
2529 1.1 dante }
2530 1.1 dante
2531 1.7 dante
2532 1.1 dante static void
2533 1.7 dante AdvSleepMilliSecond(n)
2534 1.7 dante u_int32_t n;
2535 1.1 dante {
2536 1.1 dante
2537 1.1 dante DELAY(n * 1000);
2538 1.1 dante }
2539 1.1 dante
2540 1.7 dante
2541 1.1 dante static void
2542 1.7 dante AdvDelayMicroSecond(n)
2543 1.7 dante u_int32_t n;
2544 1.1 dante {
2545 1.1 dante
2546 1.1 dante DELAY(n);
2547 1.1 dante }
2548 1.7 dante
2549