adwlib.c revision 1.2 1 1.2 dante /* $NetBSD: adwlib.c,v 1.2 1998/09/26 19:54:22 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.1 dante * Copyright (c) 1998 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.1 dante *
45 1.1 dante * Copyright (c) 1995-1998 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.1 dante #include <vm/vm.h>
70 1.1 dante #include <vm/vm_param.h>
71 1.1 dante #include <vm/pmap.h>
72 1.1 dante
73 1.1 dante #include <dev/ic/adwlib.h>
74 1.1 dante #include <dev/ic/adw.h>
75 1.1 dante #include <dev/ic/adwmcode.h>
76 1.1 dante
77 1.1 dante
78 1.1 dante /* Static Functions */
79 1.1 dante
80 1.1 dante static u_int16_t AdvGetEEPConfig __P((bus_space_tag_t, bus_space_handle_t,
81 1.2 dante ADWEEP_CONFIG *));
82 1.2 dante static u_int16_t AdvReadEEPWord __P((bus_space_tag_t, bus_space_handle_t,
83 1.2 dante int));
84 1.1 dante static void AdvWaitEEPCmd __P((bus_space_tag_t, bus_space_handle_t));
85 1.1 dante static void AdvSetEEPConfig __P((bus_space_tag_t, bus_space_handle_t,
86 1.2 dante ADWEEP_CONFIG *));
87 1.1 dante static int AdvSendScsiCmd __P((ADW_SOFTC *, ADW_SCSI_REQ_Q *));
88 1.1 dante static void AdvInquiryHandling __P((ADW_SOFTC *, ADW_SCSI_REQ_Q *));
89 1.1 dante
90 1.2 dante static void DvcSleepMilliSecond __P((ulong));
91 1.2 dante static void DvcDelayMicroSecond __P((ulong));
92 1.1 dante
93 1.1 dante
94 1.1 dante /*
95 1.1 dante * EEPROM Configuration.
96 1.1 dante *
97 1.1 dante * All drivers should use this structure to set the default EEPROM
98 1.1 dante * configuration. The BIOS now uses this structure when it is built.
99 1.1 dante * Additional structure information can be found in advlib.h where
100 1.1 dante * the structure is defined.
101 1.1 dante */
102 1.1 dante static ADWEEP_CONFIG
103 1.1 dante Default_EEPROM_Config = {
104 1.2 dante ADW_EEPROM_BIOS_ENABLE, /* cfg_msw */
105 1.2 dante 0x0000, /* cfg_lsw */
106 1.2 dante 0xFFFF, /* disc_enable */
107 1.2 dante 0xFFFF, /* wdtr_able */
108 1.2 dante 0xFFFF, /* sdtr_able */
109 1.2 dante 0xFFFF, /* start_motor */
110 1.2 dante 0xFFFF, /* tagqng_able */
111 1.2 dante 0xFFFF, /* bios_scan */
112 1.2 dante 0, /* scam_tolerant */
113 1.2 dante 7, /* adapter_scsi_id */
114 1.2 dante 0, /* bios_boot_delay */
115 1.2 dante 3, /* scsi_reset_delay */
116 1.2 dante 0, /* bios_id_lun */
117 1.2 dante 0, /* termination */
118 1.2 dante 0, /* reserved1 */
119 1.2 dante 0xFFEF, /* bios_ctrl */
120 1.2 dante 0xFFFF, /* ultra_able */
121 1.2 dante 0, /* reserved2 */
122 1.2 dante ASC_DEF_MAX_HOST_QNG, /* max_host_qng */
123 1.2 dante ASC_DEF_MAX_DVC_QNG, /* max_dvc_qng */
124 1.2 dante 0, /* dvc_cntl */
125 1.2 dante 0, /* bug_fix */
126 1.2 dante 0, /* serial_number_word1 */
127 1.2 dante 0, /* serial_number_word2 */
128 1.2 dante 0, /* serial_number_word3 */
129 1.2 dante 0, /* check_sum */
130 1.2 dante {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* oem_name[16] */
131 1.2 dante 0, /* dvc_err_code */
132 1.2 dante 0, /* adv_err_code */
133 1.2 dante 0, /* adv_err_addr */
134 1.2 dante 0, /* saved_dvc_err_code */
135 1.2 dante 0, /* saved_adv_err_code */
136 1.2 dante 0, /* saved_adv_err_addr */
137 1.2 dante 0 /* num_of_err */
138 1.1 dante };
139 1.1 dante
140 1.1 dante /*
141 1.1 dante * Initialize the ASC3550.
142 1.1 dante *
143 1.1 dante * On failure set the ADW_SOFTC field 'err_code' and return ADW_ERROR.
144 1.1 dante *
145 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
146 1.1 dante * then 0 is returned.
147 1.1 dante */
148 1.1 dante int
149 1.1 dante AdvInitAsc3550Driver(sc)
150 1.2 dante ADW_SOFTC *sc;
151 1.1 dante {
152 1.2 dante bus_space_tag_t iot = sc->sc_iot;
153 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
154 1.2 dante u_int16_t warn_code;
155 1.2 dante u_int32_t sum;
156 1.2 dante int begin_addr;
157 1.2 dante int end_addr;
158 1.2 dante int code_sum;
159 1.2 dante int word;
160 1.2 dante int rql_addr; /* RISC Queue List address */
161 1.2 dante int i;
162 1.2 dante u_int16_t scsi_cfg1;
163 1.2 dante u_int8_t biosmem[ASC_MC_BIOSLEN]; /* BIOS RISC Memory
164 1.2 dante * 0x40-0x8F */
165 1.1 dante
166 1.1 dante
167 1.1 dante warn_code = 0;
168 1.1 dante
169 1.1 dante /*
170 1.1 dante * Save the RISC memory BIOS region before writing the microcode.
171 1.1 dante * The BIOS may already be loaded and using its RISC LRAM region
172 1.1 dante * so its region must be saved and restored.
173 1.1 dante *
174 1.1 dante * Note: This code makes the assumption, which is currently true,
175 1.1 dante * that a chip reset does not clear RISC LRAM.
176 1.1 dante */
177 1.1 dante for (i = 0; i < ASC_MC_BIOSLEN; i++) {
178 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_BIOSMEM + i, biosmem[i]);
179 1.1 dante }
180 1.1 dante
181 1.1 dante /*
182 1.1 dante * Load the Microcode
183 1.1 dante *
184 1.1 dante * Write the microcode image to RISC memory starting at address 0.
185 1.1 dante */
186 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
187 1.1 dante for (word = 0; word < adv_mcode_size; word += 2) {
188 1.1 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh,
189 1.2 dante *((u_int16_t *) (&adv_mcode[word])));
190 1.1 dante }
191 1.1 dante
192 1.1 dante /*
193 1.1 dante * Clear the rest of Condor's Internal RAM (8KB).
194 1.1 dante */
195 1.1 dante for (; word < ADW_CONDOR_MEMSIZE; word += 2) {
196 1.1 dante ADW_WRITE_WORD_AUTO_INC_LRAM(iot, ioh, 0);
197 1.1 dante }
198 1.1 dante
199 1.1 dante /*
200 1.1 dante * Verify the microcode checksum.
201 1.1 dante */
202 1.1 dante sum = 0;
203 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RAM_ADDR, 0);
204 1.1 dante for (word = 0; word < adv_mcode_size; word += 2) {
205 1.1 dante sum += ADW_READ_WORD_AUTO_INC_LRAM(iot, ioh);
206 1.1 dante }
207 1.1 dante
208 1.1 dante if (sum != adv_mcode_chksum)
209 1.1 dante return ASC_IERR_MCODE_CHKSUM;
210 1.1 dante
211 1.1 dante /*
212 1.1 dante * Restore the RISC memory BIOS region.
213 1.1 dante */
214 1.1 dante for (i = 0; i < ASC_MC_BIOSLEN; i++) {
215 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_BIOSMEM + i, biosmem[i]);
216 1.1 dante }
217 1.1 dante
218 1.1 dante /*
219 1.1 dante * Calculate and write the microcode code checksum to the microcode
220 1.2 dante * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
221 1.1 dante */
222 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
223 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_END_ADDR, end_addr);
224 1.1 dante code_sum = 0;
225 1.1 dante for (word = begin_addr; word < end_addr; word += 2) {
226 1.1 dante code_sum += *((u_int16_t *) (&adv_mcode[word]));
227 1.1 dante }
228 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CODE_CHK_SUM, code_sum);
229 1.1 dante
230 1.1 dante /*
231 1.1 dante * Read microcode version and date.
232 1.1 dante */
233 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_DATE, sc->cfg.mcode_date);
234 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_VERSION_NUM, sc->cfg.mcode_version);
235 1.1 dante
236 1.1 dante /*
237 1.1 dante * Initialize microcode operating variables
238 1.1 dante */
239 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_ADAPTER_SCSI_ID,
240 1.2 dante sc->chip_scsi_id);
241 1.1 dante
242 1.1 dante /*
243 1.1 dante * If the PCI Configuration Command Register "Parity Error Response
244 1.1 dante * Control" Bit was clear (0), then set the microcode variable
245 1.1 dante * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
246 1.1 dante * to ignore DMA parity errors.
247 1.1 dante */
248 1.1 dante if (sc->cfg.control_flag & CONTROL_FLAG_IGNORE_PERR) {
249 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
250 1.1 dante word |= CONTROL_FLAG_IGNORE_PERR;
251 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_CONTROL_FLAG, word);
252 1.1 dante }
253 1.1 dante /*
254 1.1 dante * Set default microcode operating variables for WDTR, SDTR, and
255 1.1 dante * command tag queuing based on the EEPROM configuration values.
256 1.1 dante *
257 1.1 dante * These ADW_DVC_VAR fields and the microcode variables will be
258 1.1 dante * changed in AdvInquiryHandling() if it is found a device is
259 1.1 dante * incapable of a particular feature.
260 1.1 dante */
261 1.1 dante
262 1.1 dante /*
263 1.1 dante * Set the microcode ULTRA target mask from EEPROM value. The
264 1.1 dante * SDTR target mask overrides the ULTRA target mask in the
265 1.1 dante * microcode so it is safe to set this value without determining
266 1.1 dante * whether the device supports SDTR.
267 1.2 dante *
268 1.1 dante * Note: There is no way to know whether a device supports ULTRA
269 1.1 dante * speed without attempting a SDTR ULTRA speed negotiation with
270 1.1 dante * the device. The device will reject the speed if it does not
271 1.1 dante * support it by responding with an SDTR message containing a
272 1.1 dante * slower speed.
273 1.1 dante */
274 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_ULTRA_ABLE, sc->ultra_able);
275 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DISC_ENABLE, sc->cfg.disc_enable);
276 1.1 dante
277 1.1 dante
278 1.1 dante /*
279 1.1 dante * Set SCSI_CFG0 Microcode Default Value.
280 1.1 dante *
281 1.1 dante * The microcode will set the SCSI_CFG0 register using this value
282 1.1 dante * after it is started below.
283 1.1 dante */
284 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG0,
285 1.2 dante ADW_PARITY_EN | ADW_SEL_TMO_LONG | ADW_OUR_ID_EN | sc->chip_scsi_id);
286 1.2 dante
287 1.1 dante /*
288 1.1 dante * Determine SCSI_CFG1 Microcode Default Value.
289 1.1 dante *
290 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
291 1.1 dante * after it is started below.
292 1.1 dante */
293 1.1 dante
294 1.1 dante /* Read current SCSI_CFG1 Register value. */
295 1.1 dante scsi_cfg1 = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
296 1.1 dante
297 1.1 dante /*
298 1.1 dante * If all three connectors are in use, return an error.
299 1.1 dante */
300 1.1 dante if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
301 1.2 dante (scsi_cfg1 & CABLE_ILLEGAL_B) == 0) {
302 1.1 dante return ASC_IERR_ILLEGAL_CONNECTION;
303 1.1 dante }
304 1.1 dante /*
305 1.1 dante * If the internal narrow cable is reversed all of the SCSI_CTRL
306 1.1 dante * register signals will be set. Check for and return an error if
307 1.1 dante * this condition is found.
308 1.1 dante */
309 1.2 dante if ((ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL) & 0x3F07) ==
310 1.2 dante 0x3F07) {
311 1.2 dante
312 1.1 dante return ASC_IERR_REVERSED_CABLE;
313 1.2 dante }
314 1.1 dante
315 1.1 dante /*
316 1.1 dante * If this is a differential board and a single-ended device
317 1.1 dante * is attached to one of the connectors, return an error.
318 1.1 dante */
319 1.1 dante if ((scsi_cfg1 & ADW_DIFF_MODE) && (scsi_cfg1 & ADW_DIFF_SENSE) == 0)
320 1.1 dante return ASC_IERR_SINGLE_END_DEVICE;
321 1.1 dante
322 1.1 dante /*
323 1.1 dante * If automatic termination control is enabled, then set the
324 1.1 dante * termination value based on a table listed in advlib.h.
325 1.1 dante *
326 1.1 dante * If manual termination was specified with an EEPROM setting
327 1.1 dante * then 'termination' was set-up in AdvInitFromEEP() and
328 1.1 dante * is ready to be 'ored' into SCSI_CFG1.
329 1.1 dante */
330 1.1 dante if (sc->cfg.termination == 0) {
331 1.1 dante /*
332 1.2 dante * The software always controls termination by setting
333 1.2 dante * ADW_TERM_CTL_SEL.
334 1.2 dante * If ADW_TERM_CTL_SEL were set to 0, the hardware would
335 1.2 dante * set termination.
336 1.1 dante */
337 1.1 dante sc->cfg.termination |= ADW_TERM_CTL_SEL;
338 1.1 dante
339 1.2 dante switch (scsi_cfg1 & ADW_CABLE_DETECT) {
340 1.1 dante /* ADW_TERM_CTL_H: on, ADW_TERM_CTL_L: on */
341 1.2 dante case 0x3:
342 1.2 dante case 0x7:
343 1.2 dante case 0xB:
344 1.2 dante case 0xD:
345 1.2 dante case 0xE:
346 1.2 dante case 0xF:
347 1.2 dante sc->cfg.termination |= (ADW_TERM_CTL_H |
348 1.2 dante ADW_TERM_CTL_L);
349 1.2 dante break;
350 1.1 dante
351 1.1 dante /* ADW_TERM_CTL_H: on, ADW_TERM_CTL_L: off */
352 1.2 dante case 0x1:
353 1.2 dante case 0x5:
354 1.2 dante case 0x9:
355 1.2 dante case 0xA:
356 1.2 dante case 0xC:
357 1.2 dante sc->cfg.termination |= ADW_TERM_CTL_H;
358 1.2 dante break;
359 1.1 dante
360 1.1 dante /* ADW_TERM_CTL_H: off, ADW_TERM_CTL_L: off */
361 1.2 dante case 0x2:
362 1.2 dante case 0x6:
363 1.2 dante break;
364 1.1 dante }
365 1.1 dante }
366 1.1 dante /*
367 1.1 dante * Clear any set ADW_TERM_CTL_H and ADW_TERM_CTL_L bits.
368 1.1 dante */
369 1.1 dante scsi_cfg1 &= ~ADW_TERM_CTL;
370 1.1 dante
371 1.1 dante /*
372 1.1 dante * Invert the ADW_TERM_CTL_H and ADW_TERM_CTL_L bits and then
373 1.1 dante * set 'scsi_cfg1'. The ADW_TERM_POL bit does not need to be
374 1.1 dante * referenced, because the hardware internally inverts
375 1.1 dante * the Termination High and Low bits if ADW_TERM_POL is set.
376 1.1 dante */
377 1.1 dante scsi_cfg1 |= (ADW_TERM_CTL_SEL | (~sc->cfg.termination & ADW_TERM_CTL));
378 1.1 dante
379 1.1 dante /*
380 1.1 dante * Set SCSI_CFG1 Microcode Default Value
381 1.1 dante *
382 1.1 dante * Set filter value and possibly modified termination control
383 1.1 dante * bits in the Microcode SCSI_CFG1 Register Value.
384 1.1 dante *
385 1.1 dante * The microcode will set the SCSI_CFG1 register using this value
386 1.1 dante * after it is started below.
387 1.1 dante */
388 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SCSI_CFG1,
389 1.2 dante ADW_FLTR_11_TO_20NS | scsi_cfg1);
390 1.1 dante
391 1.1 dante /*
392 1.1 dante * Set SEL_MASK Microcode Default Value
393 1.1 dante *
394 1.1 dante * The microcode will set the SEL_MASK register using this value
395 1.1 dante * after it is started below.
396 1.1 dante */
397 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_DEFAULT_SEL_MASK,
398 1.2 dante ADW_TID_TO_TIDMASK(sc->chip_scsi_id));
399 1.1 dante
400 1.1 dante /*
401 1.1 dante * Link all the RISC Queue Lists together in a doubly-linked
402 1.1 dante * NULL terminated list.
403 1.1 dante *
404 1.1 dante * Skip the NULL (0) queue which is not used.
405 1.1 dante */
406 1.2 dante for (i = 1, rql_addr = ASC_MC_RISC_Q_LIST_BASE+ASC_MC_RISC_Q_LIST_SIZE;
407 1.2 dante i < ASC_MC_RISC_Q_TOTAL_CNT;
408 1.2 dante i++, rql_addr += ASC_MC_RISC_Q_LIST_SIZE) {
409 1.1 dante /*
410 1.2 dante * Set the current RISC Queue List's RQL_FWD and
411 1.2 dante * RQL_BWD pointers in a one word write and set
412 1.2 dante * the state (RQL_STATE) to free.
413 1.1 dante */
414 1.2 dante ADW_WRITE_WORD_LRAM(iot, ioh, rql_addr,
415 1.2 dante ((i + 1) + ((i - 1) << 8)));
416 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, rql_addr + RQL_STATE,
417 1.2 dante ASC_MC_QS_FREE);
418 1.1 dante }
419 1.1 dante
420 1.1 dante /*
421 1.1 dante * Set the Host and RISC Queue List pointers.
422 1.1 dante *
423 1.1 dante * Both sets of pointers are initialized with the same values:
424 1.1 dante * ASC_MC_RISC_Q_FIRST(0x01) and ASC_MC_RISC_Q_LAST (0xFF).
425 1.1 dante */
426 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_READY,
427 1.2 dante ASC_MC_RISC_Q_FIRST);
428 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_DONE,
429 1.2 dante ASC_MC_RISC_Q_LAST);
430 1.2 dante
431 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_RISC_NEXT_READY,
432 1.2 dante ASC_MC_RISC_Q_FIRST);
433 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_RISC_NEXT_DONE,
434 1.2 dante ASC_MC_RISC_Q_LAST);
435 1.1 dante
436 1.1 dante /*
437 1.1 dante * Finally, set up the last RISC Queue List (255) with
438 1.1 dante * a NULL forward pointer.
439 1.1 dante */
440 1.2 dante ADW_WRITE_WORD_LRAM(iot, ioh, rql_addr,
441 1.2 dante (ASC_MC_NULL_Q + ((i - 1) << 8)));
442 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh, rql_addr + RQL_STATE, ASC_MC_QS_FREE);
443 1.1 dante
444 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_INTR_ENABLES,
445 1.1 dante (ADW_INTR_ENABLE_HOST_INTR | ADW_INTR_ENABLE_GLOBAL_INTR));
446 1.1 dante
447 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_CODE_BEGIN_ADDR, word);
448 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_PC, word);
449 1.1 dante
450 1.1 dante /* finally, finally, gentlemen, start your engine */
451 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_RISC_CSR, ADW_RISC_CSR_RUN);
452 1.2 dante
453 1.1 dante return warn_code;
454 1.1 dante }
455 1.1 dante
456 1.1 dante /*
457 1.1 dante * Read the board's EEPROM configuration. Set fields in ADW_SOFTC and
458 1.1 dante * ADW_DVC_CFG based on the EEPROM settings. The chip is stopped while
459 1.1 dante * all of this is done.
460 1.1 dante *
461 1.1 dante * On failure set the ADW_DVC_VAR field 'err_code' and return ADW_ERROR.
462 1.1 dante *
463 1.1 dante * For a non-fatal error return a warning code. If there are no warnings
464 1.1 dante * then 0 is returned.
465 1.1 dante *
466 1.1 dante * Note: Chip is stopped on entry.
467 1.1 dante */
468 1.1 dante int
469 1.1 dante AdvInitFromEEP(sc)
470 1.2 dante ADW_SOFTC *sc;
471 1.1 dante {
472 1.2 dante bus_space_tag_t iot = sc->sc_iot;
473 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
474 1.2 dante u_int16_t warn_code;
475 1.2 dante ADWEEP_CONFIG eep_config;
476 1.2 dante int eep_chksum, i;
477 1.1 dante
478 1.1 dante
479 1.1 dante warn_code = 0;
480 1.1 dante
481 1.1 dante /*
482 1.1 dante * Read the board's EEPROM configuration.
483 1.1 dante *
484 1.1 dante * Set default values if a bad checksum is found.
485 1.1 dante */
486 1.1 dante eep_chksum = AdvGetEEPConfig(iot, ioh, &eep_config);
487 1.2 dante
488 1.2 dante if (eep_chksum != eep_config.check_sum) {
489 1.1 dante warn_code |= ASC_WARN_EEPROM_CHKSUM;
490 1.1 dante
491 1.1 dante /*
492 1.1 dante * Set EEPROM default values.
493 1.1 dante */
494 1.1 dante for (i = 0; i < sizeof(ADWEEP_CONFIG); i++) {
495 1.2 dante *((u_int8_t *) & eep_config + i) =
496 1.2 dante *((u_int8_t *) & Default_EEPROM_Config + i);
497 1.1 dante }
498 1.1 dante
499 1.1 dante /*
500 1.1 dante * Assume the 6 byte board serial number that was read
501 1.1 dante * from EEPROM is correct even if the EEPROM checksum
502 1.1 dante * failed.
503 1.1 dante */
504 1.1 dante eep_config.serial_number_word3 =
505 1.1 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 1);
506 1.1 dante eep_config.serial_number_word2 =
507 1.1 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 2);
508 1.1 dante eep_config.serial_number_word1 =
509 1.1 dante AdvReadEEPWord(iot, ioh, ASC_EEP_DVC_CFG_END - 3);
510 1.1 dante AdvSetEEPConfig(iot, ioh, &eep_config);
511 1.1 dante }
512 1.1 dante /*
513 1.1 dante * Set ADW_DVC_VAR and ADW_DVC_CFG variables from the
514 1.1 dante * EEPROM configuration that was read.
515 1.1 dante *
516 1.1 dante * This is the mapping of EEPROM fields to Adv Library fields.
517 1.1 dante */
518 1.1 dante sc->wdtr_able = eep_config.wdtr_able;
519 1.1 dante sc->sdtr_able = eep_config.sdtr_able;
520 1.1 dante sc->ultra_able = eep_config.ultra_able;
521 1.1 dante sc->tagqng_able = eep_config.tagqng_able;
522 1.1 dante sc->cfg.disc_enable = eep_config.disc_enable;
523 1.1 dante sc->max_host_qng = eep_config.max_host_qng;
524 1.1 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
525 1.1 dante sc->chip_scsi_id = (eep_config.adapter_scsi_id & ADW_MAX_TID);
526 1.1 dante sc->start_motor = eep_config.start_motor;
527 1.1 dante sc->scsi_reset_wait = eep_config.scsi_reset_delay;
528 1.1 dante sc->cfg.bios_boot_wait = eep_config.bios_boot_delay;
529 1.1 dante sc->bios_ctrl = eep_config.bios_ctrl;
530 1.1 dante sc->no_scam = eep_config.scam_tolerant;
531 1.1 dante sc->cfg.serial1 = eep_config.serial_number_word1;
532 1.1 dante sc->cfg.serial2 = eep_config.serial_number_word2;
533 1.1 dante sc->cfg.serial3 = eep_config.serial_number_word3;
534 1.1 dante
535 1.1 dante /*
536 1.1 dante * Set the host maximum queuing (max. 253, min. 16) and the per device
537 1.1 dante * maximum queuing (max. 63, min. 4).
538 1.1 dante */
539 1.1 dante if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG) {
540 1.1 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
541 1.1 dante } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG) {
542 1.1 dante /* If the value is zero, assume it is uninitialized. */
543 1.1 dante if (eep_config.max_host_qng == 0) {
544 1.1 dante eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
545 1.1 dante } else {
546 1.1 dante eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
547 1.1 dante }
548 1.1 dante }
549 1.2 dante if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG) {
550 1.1 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
551 1.2 dante } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG) {
552 1.1 dante /* If the value is zero, assume it is uninitialized. */
553 1.2 dante if (eep_config.max_dvc_qng == 0) {
554 1.1 dante eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
555 1.2 dante } else {
556 1.1 dante eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
557 1.1 dante }
558 1.1 dante }
559 1.1 dante /*
560 1.1 dante * If 'max_dvc_qng' is greater than 'max_host_qng', then
561 1.1 dante * set 'max_dvc_qng' to 'max_host_qng'.
562 1.1 dante */
563 1.2 dante if (eep_config.max_dvc_qng > eep_config.max_host_qng) {
564 1.1 dante eep_config.max_dvc_qng = eep_config.max_host_qng;
565 1.1 dante }
566 1.1 dante /*
567 1.1 dante * Set ADW_DVC_VAR 'max_host_qng' and ADW_DVC_CFG 'max_dvc_qng'
568 1.1 dante * values based on possibly adjusted EEPROM values.
569 1.1 dante */
570 1.1 dante sc->max_host_qng = eep_config.max_host_qng;
571 1.1 dante sc->max_dvc_qng = eep_config.max_dvc_qng;
572 1.1 dante
573 1.1 dante
574 1.1 dante /*
575 1.1 dante * If the EEPROM 'termination' field is set to automatic (0), then set
576 1.1 dante * the ADW_DVC_CFG 'termination' field to automatic also.
577 1.1 dante *
578 1.1 dante * If the termination is specified with a non-zero 'termination'
579 1.1 dante * value check that a legal value is set and set the ADW_DVC_CFG
580 1.1 dante * 'termination' field appropriately.
581 1.1 dante */
582 1.2 dante if (eep_config.termination == 0) {
583 1.1 dante sc->cfg.termination = 0; /* auto termination */
584 1.2 dante } else {
585 1.1 dante /* Enable manual control with low off / high off. */
586 1.2 dante if (eep_config.termination == 1) {
587 1.1 dante sc->cfg.termination = ADW_TERM_CTL_SEL;
588 1.1 dante
589 1.2 dante /* Enable manual control with low off / high on. */
590 1.2 dante } else if (eep_config.termination == 2) {
591 1.1 dante sc->cfg.termination = ADW_TERM_CTL_SEL | ADW_TERM_CTL_H;
592 1.1 dante
593 1.2 dante /* Enable manual control with low on / high on. */
594 1.2 dante } else if (eep_config.termination == 3) {
595 1.2 dante sc->cfg.termination = ADW_TERM_CTL_SEL |
596 1.2 dante ADW_TERM_CTL_H | ADW_TERM_CTL_L;
597 1.2 dante } else {
598 1.1 dante /*
599 1.2 dante * The EEPROM 'termination' field contains a bad value.
600 1.2 dante * Use automatic termination instead.
601 1.1 dante */
602 1.1 dante sc->cfg.termination = 0;
603 1.1 dante warn_code |= ASC_WARN_EEPROM_TERMINATION;
604 1.1 dante }
605 1.1 dante }
606 1.1 dante
607 1.1 dante return warn_code;
608 1.1 dante }
609 1.1 dante
610 1.1 dante /*
611 1.1 dante * Read EEPROM configuration into the specified buffer.
612 1.1 dante *
613 1.1 dante * Return a checksum based on the EEPROM configuration read.
614 1.1 dante */
615 1.2 dante static u_int16_t
616 1.1 dante AdvGetEEPConfig(iot, ioh, cfg_buf)
617 1.2 dante bus_space_tag_t iot;
618 1.2 dante bus_space_handle_t ioh;
619 1.2 dante ADWEEP_CONFIG *cfg_buf;
620 1.1 dante {
621 1.2 dante u_int16_t wval, chksum;
622 1.2 dante u_int16_t *wbuf;
623 1.2 dante int eep_addr;
624 1.1 dante
625 1.1 dante wbuf = (u_int16_t *) cfg_buf;
626 1.1 dante chksum = 0;
627 1.1 dante
628 1.1 dante for (eep_addr = ASC_EEP_DVC_CFG_BEGIN;
629 1.2 dante eep_addr < ASC_EEP_DVC_CFG_END;
630 1.2 dante eep_addr++, wbuf++) {
631 1.1 dante wval = AdvReadEEPWord(iot, ioh, eep_addr);
632 1.1 dante chksum += wval;
633 1.1 dante *wbuf = wval;
634 1.1 dante }
635 1.1 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
636 1.1 dante wbuf++;
637 1.1 dante for (eep_addr = ASC_EEP_DVC_CTL_BEGIN;
638 1.2 dante eep_addr < ASC_EEP_MAX_WORD_ADDR;
639 1.2 dante eep_addr++, wbuf++) {
640 1.1 dante *wbuf = AdvReadEEPWord(iot, ioh, eep_addr);
641 1.1 dante }
642 1.1 dante return chksum;
643 1.1 dante }
644 1.1 dante
645 1.1 dante /*
646 1.1 dante * Read the EEPROM from specified location
647 1.1 dante */
648 1.2 dante static u_int16_t
649 1.1 dante AdvReadEEPWord(iot, ioh, eep_word_addr)
650 1.2 dante bus_space_tag_t iot;
651 1.2 dante bus_space_handle_t ioh;
652 1.2 dante int eep_word_addr;
653 1.1 dante {
654 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
655 1.2 dante ASC_EEP_CMD_READ | eep_word_addr);
656 1.2 dante AdvWaitEEPCmd(iot, iot);
657 1.2 dante return ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_DATA);
658 1.1 dante }
659 1.1 dante
660 1.1 dante /*
661 1.1 dante * Wait for EEPROM command to complete
662 1.1 dante */
663 1.1 dante static void
664 1.1 dante AdvWaitEEPCmd(iot, ioh)
665 1.2 dante bus_space_tag_t iot;
666 1.2 dante bus_space_handle_t ioh;
667 1.1 dante {
668 1.1 dante DvcSleepMilliSecond(1);
669 1.1 dante
670 1.2 dante for (;;) {
671 1.1 dante if (ADW_READ_WORD_REGISTER(iot, ioh, IOPW_EE_CMD) &
672 1.2 dante ASC_EEP_CMD_DONE) {
673 1.1 dante break;
674 1.1 dante }
675 1.1 dante DvcSleepMilliSecond(1);
676 1.1 dante }
677 1.1 dante
678 1.1 dante return;
679 1.1 dante }
680 1.1 dante
681 1.1 dante /*
682 1.1 dante * Write the EEPROM from 'cfg_buf'.
683 1.1 dante */
684 1.1 dante static void
685 1.1 dante AdvSetEEPConfig(iot, ioh, cfg_buf)
686 1.2 dante bus_space_tag_t iot;
687 1.2 dante bus_space_handle_t ioh;
688 1.2 dante ADWEEP_CONFIG *cfg_buf;
689 1.1 dante {
690 1.2 dante u_int16_t *wbuf;
691 1.2 dante u_int16_t addr, chksum;
692 1.1 dante
693 1.1 dante wbuf = (u_int16_t *) cfg_buf;
694 1.1 dante chksum = 0;
695 1.1 dante
696 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
697 1.1 dante AdvWaitEEPCmd(iot, ioh);
698 1.1 dante
699 1.1 dante /*
700 1.1 dante * Write EEPROM from word 0 to word 15
701 1.1 dante */
702 1.1 dante for (addr = ASC_EEP_DVC_CFG_BEGIN;
703 1.2 dante addr < ASC_EEP_DVC_CFG_END; addr++, wbuf++) {
704 1.1 dante chksum += *wbuf;
705 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
706 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh,
707 1.2 dante IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
708 1.1 dante AdvWaitEEPCmd(iot, ioh);
709 1.1 dante DvcSleepMilliSecond(ASC_EEP_DELAY_MS);
710 1.1 dante }
711 1.1 dante
712 1.1 dante /*
713 1.1 dante * Write EEPROM checksum at word 18
714 1.1 dante */
715 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, chksum);
716 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
717 1.2 dante ASC_EEP_CMD_WRITE | addr);
718 1.1 dante AdvWaitEEPCmd(iot, ioh);
719 1.2 dante wbuf++; /* skip over check_sum */
720 1.1 dante
721 1.1 dante /*
722 1.2 dante * Write EEPROM OEM name at words 19 to 26
723 1.1 dante */
724 1.1 dante for (addr = ASC_EEP_DVC_CTL_BEGIN;
725 1.2 dante addr < ASC_EEP_MAX_WORD_ADDR; addr++, wbuf++) {
726 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_DATA, *wbuf);
727 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh,
728 1.2 dante IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
729 1.1 dante AdvWaitEEPCmd(iot, ioh);
730 1.1 dante }
731 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_EE_CMD,
732 1.2 dante ASC_EEP_CMD_WRITE_DISABLE);
733 1.1 dante AdvWaitEEPCmd(iot, ioh);
734 1.1 dante return;
735 1.1 dante }
736 1.1 dante
737 1.1 dante /*
738 1.1 dante * This function resets the chip and SCSI bus
739 1.1 dante *
740 1.1 dante * It is up to the caller to add a delay to let the bus settle after
741 1.1 dante * calling this function.
742 1.1 dante *
743 1.1 dante * The SCSI_CFG0, SCSI_CFG1, and MEM_CFG registers are set-up in
744 1.1 dante * AdvInitAsc3550Driver(). Here when doing a write to one of these
745 1.1 dante * registers read first and then write.
746 1.1 dante *
747 1.1 dante * Note: A SCSI Bus Reset can not be done until after the EEPROM
748 1.1 dante * configuration is read to determine whether SCSI Bus Resets
749 1.1 dante * should be performed.
750 1.1 dante */
751 1.1 dante void
752 1.1 dante AdvResetChip(iot, ioh)
753 1.2 dante bus_space_tag_t iot;
754 1.2 dante bus_space_handle_t ioh;
755 1.1 dante {
756 1.2 dante u_int16_t word;
757 1.2 dante u_int8_t byte;
758 1.1 dante
759 1.1 dante
760 1.1 dante /*
761 1.1 dante * Reset Chip.
762 1.1 dante */
763 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
764 1.2 dante ADW_CTRL_REG_CMD_RESET);
765 1.1 dante DvcSleepMilliSecond(100);
766 1.2 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_CTRL_REG,
767 1.2 dante ADW_CTRL_REG_CMD_WR_IO_REG);
768 1.1 dante
769 1.1 dante /*
770 1.1 dante * Initialize Chip registers.
771 1.2 dante *
772 1.1 dante * Note: Don't remove the use of a temporary variable in the following
773 1.2 dante * code, otherwise the Microsoft C compiler will turn the following
774 1.2 dante * lines into a no-op.
775 1.1 dante */
776 1.1 dante byte = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_MEM_CFG);
777 1.1 dante byte |= RAM_SZ_8KB;
778 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_MEM_CFG, byte);
779 1.1 dante
780 1.1 dante word = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1);
781 1.1 dante word &= ~BIG_ENDIAN;
782 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CFG1, word);
783 1.1 dante
784 1.1 dante /*
785 1.1 dante * Setting the START_CTL_EMFU 3:2 bits sets a FIFO threshold
786 1.1 dante * of 128 bytes. This register is only accessible to the host.
787 1.1 dante */
788 1.1 dante ADW_WRITE_BYTE_REGISTER(iot, ioh, IOPB_DMA_CFG0,
789 1.2 dante START_CTL_EMFU | READ_CMD_MRM);
790 1.1 dante }
791 1.1 dante
792 1.1 dante /*
793 1.1 dante * Description:
794 1.1 dante * Send a SCSI request to the ASC3550 chip
795 1.1 dante *
796 1.1 dante * If there is no SG list for the request, set 'sg_entry_cnt' to 0.
797 1.1 dante *
798 1.1 dante * If 'sg_real_addr' is non-zero on entry, AscGetSGList() will not be
799 1.1 dante * called. It is assumed the caller has already initialized 'sg_real_addr'.
800 1.1 dante *
801 1.1 dante * Return:
802 1.1 dante * ADW_SUCCESS(1) - the request is in the mailbox
803 1.1 dante * ADW_BUSY(0) - total request count > 253, try later
804 1.1 dante * ADW_ERROR(-1) - invalid scsi request Q
805 1.1 dante */
806 1.1 dante int
807 1.1 dante AdvExeScsiQueue(sc, scsiq)
808 1.2 dante ADW_SOFTC *sc;
809 1.2 dante ADW_SCSI_REQ_Q *scsiq;
810 1.1 dante {
811 1.2 dante return AdvSendScsiCmd(sc, scsiq);
812 1.1 dante }
813 1.1 dante
814 1.1 dante /*
815 1.1 dante * Reset SCSI Bus and purge all outstanding requests.
816 1.1 dante *
817 1.1 dante * Return Value:
818 1.1 dante * ADW_TRUE(1) - All requests are purged and SCSI Bus is reset.
819 1.1 dante *
820 1.1 dante * Note: Should always return ADW_TRUE.
821 1.1 dante */
822 1.1 dante int
823 1.1 dante AdvResetCCB(sc)
824 1.2 dante ADW_SOFTC *sc;
825 1.1 dante {
826 1.2 dante int status;
827 1.1 dante
828 1.1 dante status = AdvSendIdleCmd(sc, (u_int16_t) IDLE_CMD_SCSI_RESET, 0L, 0);
829 1.1 dante
830 1.1 dante AdvResetSCSIBus(sc);
831 1.1 dante
832 1.1 dante return status;
833 1.1 dante }
834 1.1 dante
835 1.1 dante /*
836 1.1 dante * Reset SCSI Bus and delay.
837 1.1 dante */
838 1.1 dante void
839 1.1 dante AdvResetSCSIBus(sc)
840 1.2 dante ADW_SOFTC *sc;
841 1.1 dante {
842 1.2 dante bus_space_tag_t iot = sc->sc_iot;
843 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
844 1.2 dante u_int16_t scsi_ctrl;
845 1.1 dante
846 1.1 dante
847 1.1 dante
848 1.1 dante /*
849 1.1 dante * The microcode currently sets the SCSI Bus Reset signal while
850 1.1 dante * handling the AdvSendIdleCmd() IDLE_CMD_SCSI_RESET command above.
851 1.2 dante * But the SCSI Bus Reset Hold Time in the uCode is not deterministic
852 1.1 dante * (it may in fact be for less than the SCSI Spec. minimum of 25 us).
853 1.1 dante * Therefore on return the Adv Library sets the SCSI Bus Reset signal
854 1.1 dante * for ASC_SCSI_RESET_HOLD_TIME_US, which is defined to be greater
855 1.1 dante * than 25 us.
856 1.1 dante */
857 1.1 dante scsi_ctrl = ADW_READ_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL);
858 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL,
859 1.2 dante scsi_ctrl | ADW_SCSI_CTRL_RSTOUT);
860 1.2 dante DvcDelayMicroSecond((u_int16_t) ASC_SCSI_RESET_HOLD_TIME_US);
861 1.1 dante ADW_WRITE_WORD_REGISTER(iot, ioh, IOPW_SCSI_CTRL,
862 1.2 dante scsi_ctrl & ~ADW_SCSI_CTRL_RSTOUT);
863 1.1 dante
864 1.1 dante DvcSleepMilliSecond((ulong) sc->scsi_reset_wait * 1000);
865 1.1 dante }
866 1.1 dante
867 1.1 dante
868 1.1 dante /*
869 1.1 dante * Adv Library Interrupt Service Routine
870 1.1 dante *
871 1.1 dante * This function is called by a driver's interrupt service routine.
872 1.1 dante * The function disables and re-enables interrupts.
873 1.1 dante *
874 1.1 dante * When a microcode idle command is completed, the ADW_DVC_VAR
875 1.1 dante * 'idle_cmd_done' field is set to ADW_TRUE.
876 1.1 dante *
877 1.1 dante * Note: AdvISR() can be called when interrupts are disabled or even
878 1.1 dante * when there is no hardware interrupt condition present. It will
879 1.1 dante * always check for completed idle commands and microcode requests.
880 1.1 dante * This is an important feature that shouldn't be changed because it
881 1.1 dante * allows commands to be completed from polling mode loops.
882 1.1 dante *
883 1.1 dante * Return:
884 1.1 dante * ADW_TRUE(1) - interrupt was pending
885 1.1 dante * ADW_FALSE(0) - no interrupt was pending
886 1.1 dante */
887 1.1 dante int
888 1.1 dante AdvISR(sc)
889 1.2 dante ADW_SOFTC *sc;
890 1.1 dante {
891 1.2 dante bus_space_tag_t iot = sc->sc_iot;
892 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
893 1.2 dante u_int8_t int_stat;
894 1.2 dante u_int16_t next_done_loc, target_bit;
895 1.2 dante int completed_q;
896 1.2 dante ADW_SCSI_REQ_Q *scsiq;
897 1.2 dante ASC_REQ_SENSE *sense_data;
898 1.2 dante int ret;
899 1.1 dante
900 1.1 dante
901 1.2 dante ret = (ADW_IS_INT_PENDING(iot, ioh)) ? ADW_TRUE : ADW_FALSE;
902 1.1 dante
903 1.1 dante /* Reading the register clears the interrupt. */
904 1.1 dante int_stat = ADW_READ_BYTE_REGISTER(iot, ioh, IOPB_INTR_STATUS_REG);
905 1.1 dante
906 1.2 dante if (int_stat & ADW_INTR_STATUS_INTRB) {
907 1.1 dante sc->idle_cmd_done = ADW_TRUE;
908 1.1 dante }
909 1.1 dante /*
910 1.1 dante * Notify the driver of a hardware detected SCSI Bus Reset.
911 1.1 dante */
912 1.2 dante if (int_stat & ADW_INTR_STATUS_INTRC) {
913 1.2 dante if (sc->sbreset_callback) {
914 1.2 dante (*(ADW_SBRESET_CALLBACK) sc->sbreset_callback) (sc);
915 1.1 dante }
916 1.1 dante }
917 1.1 dante /*
918 1.1 dante * ASC_MC_HOST_NEXT_DONE (0x129) is actually the last completed RISC
919 1.1 dante * Queue List request. Its forward pointer (RQL_FWD) points to the
920 1.1 dante * current completed RISC Queue List request.
921 1.1 dante */
922 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_DONE, next_done_loc);
923 1.1 dante next_done_loc = ASC_MC_RISC_Q_LIST_BASE +
924 1.1 dante (next_done_loc * ASC_MC_RISC_Q_LIST_SIZE) + RQL_FWD;
925 1.1 dante
926 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh, next_done_loc, completed_q);
927 1.1 dante
928 1.1 dante /* Loop until all completed Q's are processed. */
929 1.2 dante while (completed_q != ASC_MC_NULL_Q) {
930 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_DONE,
931 1.2 dante completed_q);
932 1.1 dante
933 1.1 dante next_done_loc = ASC_MC_RISC_Q_LIST_BASE +
934 1.2 dante (completed_q * ASC_MC_RISC_Q_LIST_SIZE);
935 1.1 dante
936 1.1 dante /*
937 1.1 dante * Read the ADW_SCSI_REQ_Q virtual address pointer from
938 1.1 dante * the RISC list entry. The microcode has changed the
939 1.1 dante * ADW_SCSI_REQ_Q physical address to its virtual address.
940 1.1 dante *
941 1.1 dante * Refer to comments at the end of AdvSendScsiCmd() for
942 1.1 dante * more information on the RISC list structure.
943 1.1 dante */
944 1.1 dante {
945 1.2 dante ushort lsw, msw;
946 1.1 dante ADW_READ_WORD_LRAM(iot, ioh,
947 1.2 dante next_done_loc + RQL_PHYADDR, lsw);
948 1.1 dante ADW_READ_WORD_LRAM(iot, ioh,
949 1.2 dante next_done_loc + RQL_PHYADDR + 2, msw);
950 1.1 dante
951 1.1 dante scsiq = (ADW_SCSI_REQ_Q *)
952 1.2 dante (((u_int32_t) msw << 16) | lsw);
953 1.1 dante }
954 1.1 dante
955 1.1 dante target_bit = ADW_TID_TO_TIDMASK(scsiq->target_id);
956 1.1 dante
957 1.1 dante /*
958 1.1 dante * Clear request microcode control flag.
959 1.1 dante */
960 1.1 dante scsiq->cntl = 0;
961 1.1 dante
962 1.1 dante /*
963 1.1 dante * Check Condition handling
964 1.1 dante */
965 1.1 dante if ((scsiq->done_status == QD_WITH_ERROR) &&
966 1.2 dante (scsiq->scsi_status == SS_CHK_CONDITION) &&
967 1.2 dante (sense_data = (ASC_REQ_SENSE *) scsiq->vsense_addr) != 0 &&
968 1.2 dante (scsiq->orig_sense_len - scsiq->sense_len) >=
969 1.2 dante ASC_MIN_SENSE_LEN) {
970 1.1 dante /*
971 1.1 dante * Command returned with a check condition and valid
972 1.1 dante * sense data.
973 1.1 dante */
974 1.1 dante }
975 1.1 dante /*
976 1.1 dante * If the command that completed was a SCSI INQUIRY and
977 1.1 dante * LUN 0 was sent the command, then process the INQUIRY
978 1.1 dante * command information for the device.
979 1.1 dante */
980 1.1 dante else if (scsiq->done_status == QD_NO_ERROR &&
981 1.2 dante scsiq->cdb[0] == INQUIRY &&
982 1.2 dante scsiq->target_lun == 0) {
983 1.1 dante AdvInquiryHandling(sc, scsiq);
984 1.1 dante }
985 1.1 dante /* Change the RISC Queue List state to free. */
986 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
987 1.2 dante next_done_loc + RQL_STATE, ASC_MC_QS_FREE);
988 1.1 dante
989 1.1 dante /* Get the RISC Queue List forward pointer. */
990 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh,
991 1.2 dante next_done_loc + RQL_FWD, completed_q);
992 1.1 dante
993 1.1 dante /*
994 1.1 dante * Notify the driver of the completed request by passing
995 1.1 dante * the ADW_SCSI_REQ_Q pointer to its callback function.
996 1.1 dante */
997 1.1 dante sc->cur_host_qng--;
998 1.1 dante scsiq->a_flag |= ADW_SCSIQ_DONE;
999 1.2 dante (*(ADW_ISR_CALLBACK) sc->isr_callback) (sc, scsiq);
1000 1.1 dante /*
1001 1.1 dante * Note: After the driver callback function is called, 'scsiq'
1002 1.1 dante * can no longer be referenced.
1003 1.1 dante *
1004 1.1 dante * Fall through and continue processing other completed
1005 1.1 dante * requests...
1006 1.1 dante */
1007 1.1 dante }
1008 1.1 dante return ret;
1009 1.1 dante }
1010 1.1 dante
1011 1.1 dante /*
1012 1.1 dante * Send an idle command to the chip and wait for completion.
1013 1.1 dante *
1014 1.1 dante * Interrupts do not have to be enabled on entry.
1015 1.1 dante *
1016 1.1 dante * Return Values:
1017 1.1 dante * ADW_TRUE - command completed successfully
1018 1.1 dante * ADW_FALSE - command failed
1019 1.1 dante */
1020 1.1 dante int
1021 1.1 dante AdvSendIdleCmd(sc, idle_cmd, idle_cmd_parameter, flags)
1022 1.2 dante ADW_SOFTC *sc;
1023 1.2 dante u_int16_t idle_cmd;
1024 1.2 dante u_int32_t idle_cmd_parameter;
1025 1.2 dante int flags;
1026 1.1 dante {
1027 1.2 dante bus_space_tag_t iot = sc->sc_iot;
1028 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
1029 1.2 dante u_int32_t i;
1030 1.2 dante int ret;
1031 1.1 dante
1032 1.1 dante sc->idle_cmd_done = 0;
1033 1.1 dante
1034 1.1 dante /*
1035 1.1 dante * Write the idle command value after the idle command parameter
1036 1.1 dante * has been written to avoid a race condition. If the order is not
1037 1.1 dante * followed, the microcode may process the idle command before the
1038 1.1 dante * parameters have been written to LRAM.
1039 1.1 dante */
1040 1.1 dante ADW_WRITE_DWORD_LRAM(iot, ioh, ASC_MC_IDLE_PARA_STAT,
1041 1.2 dante idle_cmd_parameter);
1042 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_IDLE_CMD, idle_cmd);
1043 1.1 dante
1044 1.1 dante /*
1045 1.1 dante * If the 'flags' argument contains the ADW_NOWAIT flag, then
1046 1.1 dante * return with success.
1047 1.1 dante */
1048 1.1 dante if (flags & ADW_NOWAIT)
1049 1.1 dante return ADW_TRUE;
1050 1.1 dante
1051 1.2 dante for (i = 0; i < SCSI_WAIT_10_SEC * SCSI_MS_PER_SEC; i++) {
1052 1.1 dante /*
1053 1.1 dante * 'idle_cmd_done' is set by AdvISR().
1054 1.1 dante */
1055 1.1 dante if (sc->idle_cmd_done)
1056 1.1 dante break;
1057 1.1 dante
1058 1.1 dante DvcSleepMilliSecond(1);
1059 1.1 dante
1060 1.1 dante /*
1061 1.1 dante * If interrupts were disabled on entry to AdvSendIdleCmd(),
1062 1.1 dante * then they will still be disabled here. Call AdvISR() to
1063 1.1 dante * check for the idle command completion.
1064 1.1 dante */
1065 1.1 dante (void) AdvISR(sc);
1066 1.1 dante }
1067 1.1 dante
1068 1.2 dante if (sc->idle_cmd_done == ADW_FALSE) {
1069 1.1 dante return ADW_FALSE;
1070 1.2 dante } else {
1071 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_IDLE_PARA_STAT, ret);
1072 1.1 dante return ret;
1073 1.1 dante }
1074 1.1 dante }
1075 1.1 dante
1076 1.1 dante /*
1077 1.1 dante * Send the SCSI request block to the adapter
1078 1.1 dante *
1079 1.1 dante * Each of the 255 Adv Library/Microcode RISC Lists or mailboxes has the
1080 1.1 dante * following structure:
1081 1.1 dante *
1082 1.1 dante * 0: RQL_FWD - RISC list forward pointer (1 byte)
1083 1.1 dante * 1: RQL_BWD - RISC list backward pointer (1 byte)
1084 1.1 dante * 2: RQL_STATE - RISC list state byte - free, ready, done, aborted (1 byte)
1085 1.1 dante * 3: RQL_TID - request target id (1 byte)
1086 1.1 dante * 4: RQL_PHYADDR - ADW_SCSI_REQ_Q physical pointer (4 bytes)
1087 1.1 dante *
1088 1.1 dante * Return:
1089 1.1 dante * ADW_SUCCESS(1) - the request is in the mailbox
1090 1.1 dante * ADW_BUSY(0) - total request count > 253, try later
1091 1.1 dante */
1092 1.1 dante static int
1093 1.1 dante AdvSendScsiCmd(sc, scsiq)
1094 1.2 dante ADW_SOFTC *sc;
1095 1.2 dante ADW_SCSI_REQ_Q *scsiq;
1096 1.1 dante {
1097 1.2 dante bus_space_tag_t iot = sc->sc_iot;
1098 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
1099 1.2 dante ADW_CCB *ccb = (ADW_CCB *) scsiq->ccb_ptr;
1100 1.2 dante u_int16_t next_ready_loc;
1101 1.2 dante u_int8_t next_ready_loc_fwd;
1102 1.2 dante long req_size;
1103 1.2 dante u_int32_t q_phy_addr;
1104 1.1 dante
1105 1.1 dante
1106 1.2 dante if (sc->cur_host_qng >= sc->max_host_qng) {
1107 1.1 dante return ADW_BUSY;
1108 1.2 dante } else {
1109 1.1 dante sc->cur_host_qng++;
1110 1.1 dante }
1111 1.1 dante
1112 1.1 dante /*
1113 1.1 dante * Clear the ADW_SCSI_REQ_Q done flag.
1114 1.1 dante */
1115 1.1 dante scsiq->a_flag &= ~ADW_SCSIQ_DONE;
1116 1.1 dante
1117 1.1 dante /*
1118 1.1 dante * Save the original sense buffer length.
1119 1.1 dante *
1120 1.1 dante * After the request completes 'sense_len' will be set to the residual
1121 1.1 dante * byte count of the Auto-Request Sense if a command returns CHECK
1122 1.1 dante * CONDITION and the Sense Data is valid indicated by 'host_status' not
1123 1.1 dante * being set to QHSTA_M_AUTO_REQ_SENSE_FAIL. To determine the valid
1124 1.1 dante * Sense Data Length subtract 'sense_len' from 'orig_sense_len'.
1125 1.1 dante */
1126 1.1 dante scsiq->orig_sense_len = scsiq->sense_len;
1127 1.1 dante
1128 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_READY, next_ready_loc);
1129 1.1 dante next_ready_loc = ASC_MC_RISC_Q_LIST_BASE +
1130 1.1 dante (next_ready_loc * ASC_MC_RISC_Q_LIST_SIZE);
1131 1.1 dante
1132 1.1 dante /*
1133 1.1 dante * Write the physical address of the Q to the mailbox.
1134 1.1 dante * We need to skip the first four bytes, because the microcode
1135 1.1 dante * uses them internally for linking Q's together.
1136 1.1 dante */
1137 1.1 dante req_size = sizeof(ADW_SCSI_REQ_Q);
1138 1.1 dante q_phy_addr = sc->sc_dmamap_control->dm_segs[0].ds_addr +
1139 1.1 dante ADW_CCB_OFF(ccb) + offsetof(struct adw_ccb, scsiq);
1140 1.1 dante
1141 1.1 dante scsiq->scsiq_ptr = scsiq;
1142 1.1 dante
1143 1.1 dante /*
1144 1.1 dante * The RISC list structure, which 'next_ready_loc' is a pointer
1145 1.1 dante * to in microcode LRAM, has the format detailed in the comment
1146 1.1 dante * header for this function.
1147 1.1 dante *
1148 1.2 dante * Write the ADW_SCSI_REQ_Q physical pointer to
1149 1.2 dante * 'next_ready_loc' request.
1150 1.1 dante */
1151 1.2 dante ADW_WRITE_DWORD_LRAM(iot, ioh, next_ready_loc + RQL_PHYADDR,
1152 1.2 dante q_phy_addr);
1153 1.1 dante
1154 1.1 dante /* Write target_id to 'next_ready_loc' request. */
1155 1.2 dante ADW_WRITE_BYTE_LRAM(iot, ioh, next_ready_loc + RQL_TID,
1156 1.2 dante scsiq->target_id);
1157 1.1 dante
1158 1.1 dante /*
1159 1.1 dante * Set the ASC_MC_HOST_NEXT_READY (0x128) microcode variable to
1160 1.1 dante * the 'next_ready_loc' request forward pointer.
1161 1.1 dante *
1162 1.1 dante * Do this *before* changing the 'next_ready_loc' queue to QS_READY.
1163 1.1 dante * After the state is changed to QS_READY 'RQL_FWD' will be changed
1164 1.1 dante * by the microcode.
1165 1.1 dante *
1166 1.1 dante * NOTE: The temporary variable 'next_ready_loc_fwd' is required to
1167 1.1 dante * prevent some compilers from optimizing out 'AdvReadByteLram()' if
1168 1.1 dante * it were used as the 3rd argument to 'AdvWriteByteLram()'.
1169 1.1 dante */
1170 1.1 dante ADW_READ_BYTE_LRAM(iot, ioh, next_ready_loc + RQL_FWD,
1171 1.2 dante next_ready_loc_fwd);
1172 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh, ASC_MC_HOST_NEXT_READY,
1173 1.2 dante next_ready_loc_fwd);
1174 1.1 dante
1175 1.1 dante /*
1176 1.1 dante * Change the state of 'next_ready_loc' request from QS_FREE to
1177 1.1 dante * QS_READY which will cause the microcode to pick it up and
1178 1.1 dante * execute it.
1179 1.1 dante *
1180 1.1 dante * Can't reference 'next_ready_loc' after changing the request
1181 1.1 dante * state to QS_READY. The microcode now owns the request.
1182 1.1 dante */
1183 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh, next_ready_loc + RQL_STATE,
1184 1.2 dante ASC_MC_QS_READY);
1185 1.1 dante
1186 1.1 dante return ADW_SUCCESS;
1187 1.1 dante }
1188 1.1 dante
1189 1.1 dante /*
1190 1.1 dante * Inquiry Information Byte 7 Handling
1191 1.1 dante *
1192 1.1 dante * Handle SCSI Inquiry Command information for a device by setting
1193 1.2 dante * microcode operating variables that affect WDTR, SDTR, and Tag
1194 1.1 dante * Queuing.
1195 1.1 dante */
1196 1.1 dante static void
1197 1.1 dante AdvInquiryHandling(sc, scsiq)
1198 1.2 dante ADW_SOFTC *sc;
1199 1.2 dante ADW_SCSI_REQ_Q *scsiq;
1200 1.1 dante {
1201 1.2 dante bus_space_tag_t iot = sc->sc_iot;
1202 1.2 dante bus_space_handle_t ioh = sc->sc_ioh;
1203 1.2 dante ASC_SCSI_INQUIRY *inq;
1204 1.2 dante u_int16_t cfg_word;
1205 1.2 dante u_int16_t tidmask;
1206 1.2 dante u_int8_t tid;
1207 1.1 dante
1208 1.1 dante /*
1209 1.1 dante * AdvInquiryHandling() requires up to INQUIRY information Byte 7
1210 1.1 dante * to be available.
1211 1.1 dante *
1212 1.1 dante * If less than 8 bytes of INQUIRY information were requested or less
1213 1.1 dante * than 8 bytes were transferred, then return. cdb[4] is the request
1214 1.1 dante * length and the ADW_SCSI_REQ_Q 'data_cnt' field is set by the
1215 1.1 dante * microcode to the transfer residual count.
1216 1.1 dante */
1217 1.2 dante if (scsiq->cdb[4] < 8 || (scsiq->cdb[4] - scsiq->data_cnt) < 8) {
1218 1.1 dante return;
1219 1.1 dante }
1220 1.1 dante tid = scsiq->target_id;
1221 1.1 dante inq = (ASC_SCSI_INQUIRY *) scsiq->vdata_addr;
1222 1.1 dante
1223 1.1 dante /*
1224 1.1 dante * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
1225 1.1 dante */
1226 1.2 dante if (inq->byte3.rsp_data_fmt < 2 && inq->byte2.ansi_apr_ver < 2) {
1227 1.1 dante return;
1228 1.2 dante } else {
1229 1.1 dante /*
1230 1.1 dante * INQUIRY Byte 7 Handling
1231 1.1 dante *
1232 1.1 dante * Use a device's INQUIRY byte 7 to determine whether it
1233 1.1 dante * supports WDTR, SDTR, and Tag Queuing. If the feature
1234 1.1 dante * is enabled in the EEPROM and the device supports the
1235 1.1 dante * feature, then enable it in the microcode.
1236 1.1 dante */
1237 1.1 dante
1238 1.1 dante tidmask = ADW_TID_TO_TIDMASK(tid);
1239 1.1 dante /*
1240 1.1 dante * Wide Transfers
1241 1.1 dante *
1242 1.1 dante * If the EEPROM enabled WDTR for the device and the device
1243 1.1 dante * supports wide bus (16 bit) transfers, then turn on the
1244 1.1 dante * device's 'wdtr_able' bit and write the new value to the
1245 1.1 dante * microcode.
1246 1.1 dante */
1247 1.2 dante if ((sc->wdtr_able & tidmask) && inq->byte7.WBus16) {
1248 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
1249 1.2 dante cfg_word);
1250 1.2 dante if ((cfg_word & tidmask) == 0) {
1251 1.1 dante cfg_word |= tidmask;
1252 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_ABLE,
1253 1.2 dante cfg_word);
1254 1.1 dante
1255 1.1 dante /*
1256 1.2 dante * Clear the microcode "WDTR negotiation" done
1257 1.2 dante * indicator for the target to cause it
1258 1.2 dante * to negotiate with the new setting set above.
1259 1.1 dante */
1260 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
1261 1.2 dante cfg_word);
1262 1.1 dante cfg_word &= ~tidmask;
1263 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_WDTR_DONE,
1264 1.2 dante cfg_word);
1265 1.1 dante }
1266 1.1 dante }
1267 1.1 dante /*
1268 1.1 dante * Synchronous Transfers
1269 1.1 dante *
1270 1.1 dante * If the EEPROM enabled SDTR for the device and the device
1271 1.1 dante * supports synchronous transfers, then turn on the device's
1272 1.1 dante * 'sdtr_able' bit. Write the new value to the microcode.
1273 1.1 dante */
1274 1.2 dante if ((sc->sdtr_able & tidmask) && inq->byte7.Sync) {
1275 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
1276 1.2 dante cfg_word);
1277 1.2 dante if ((cfg_word & tidmask) == 0) {
1278 1.1 dante cfg_word |= tidmask;
1279 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_ABLE,
1280 1.2 dante cfg_word);
1281 1.1 dante
1282 1.1 dante /*
1283 1.2 dante * Clear the microcode "SDTR negotiation" done
1284 1.2 dante * indicator for the target to cause it
1285 1.2 dante * to negotiate with the new setting set above.
1286 1.1 dante */
1287 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
1288 1.2 dante cfg_word);
1289 1.1 dante cfg_word &= ~tidmask;
1290 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_SDTR_DONE,
1291 1.2 dante cfg_word);
1292 1.1 dante }
1293 1.1 dante }
1294 1.1 dante /*
1295 1.1 dante * If the EEPROM enabled Tag Queuing for device and the
1296 1.1 dante * device supports Tag Queuing, then turn on the device's
1297 1.1 dante * 'tagqng_enable' bit in the microcode and set the microcode
1298 1.1 dante * maximum command count to the ADW_DVC_VAR 'max_dvc_qng'
1299 1.1 dante * value.
1300 1.1 dante *
1301 1.1 dante * Tag Queuing is disabled for the BIOS which runs in polled
1302 1.1 dante * mode and would see no benefit from Tag Queuing. Also by
1303 1.1 dante * disabling Tag Queuing in the BIOS devices with Tag Queuing
1304 1.1 dante * bugs will at least work with the BIOS.
1305 1.1 dante */
1306 1.2 dante if ((sc->tagqng_able & tidmask) && inq->byte7.CmdQue) {
1307 1.1 dante ADW_READ_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
1308 1.2 dante cfg_word);
1309 1.1 dante cfg_word |= tidmask;
1310 1.1 dante ADW_WRITE_WORD_LRAM(iot, ioh, ASC_MC_TAGQNG_ABLE,
1311 1.2 dante cfg_word);
1312 1.1 dante ADW_WRITE_BYTE_LRAM(iot, ioh,
1313 1.2 dante ASC_MC_NUMBER_OF_MAX_CMD + tid,
1314 1.2 dante sc->max_dvc_qng);
1315 1.1 dante }
1316 1.1 dante }
1317 1.1 dante }
1318 1.1 dante
1319 1.1 dante static void
1320 1.1 dante DvcSleepMilliSecond(n)
1321 1.2 dante ulong n;
1322 1.1 dante {
1323 1.1 dante
1324 1.1 dante DELAY(n * 1000);
1325 1.1 dante }
1326 1.1 dante
1327 1.1 dante static void
1328 1.1 dante DvcDelayMicroSecond(n)
1329 1.2 dante ulong n;
1330 1.1 dante {
1331 1.1 dante
1332 1.1 dante DELAY(n);
1333 1.1 dante }
1334