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