Wed Apr 5 21:46:09 2023 UTC ()
s/esssentially/essentially/ in comment.


(andvar)
diff -r1.105 -r1.106 src/sys/dev/ic/aic6360.c

cvs diff -r1.105 -r1.106 src/sys/dev/ic/aic6360.c (switch to unified diff)

--- src/sys/dev/ic/aic6360.c 2022/01/01 21:07:14 1.105
+++ src/sys/dev/ic/aic6360.c 2023/04/05 21:46:09 1.106
@@ -1,2218 +1,2218 @@ @@ -1,2218 +1,2218 @@
1/* $NetBSD: aic6360.c,v 1.105 2022/01/01 21:07:14 andvar Exp $ */ 1/* $NetBSD: aic6360.c,v 1.106 2023/04/05 21:46:09 andvar Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995, 1996 Charles M. Hannum. All rights reserved. 4 * Copyright (c) 1994, 1995, 1996 Charles M. Hannum. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software 14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement: 15 * must display the following acknowledgement:
16 * This product includes software developed by Charles M. Hannum. 16 * This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products 17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission. 18 * derived from this software without specific prior written permission.
19 * 19 *
20 * Copyright (c) 1994 Jarle Greipsland 20 * Copyright (c) 1994 Jarle Greipsland
21 * All rights reserved. 21 * All rights reserved.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
26 * 1. Redistributions of source code must retain the above copyright 26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer. 27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright 28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution. 30 * documentation and/or other materials provided with the distribution.
31 * 3. The name of the author may not be used to endorse or promote products 31 * 3. The name of the author may not be used to endorse or promote products
32 * derived from this software without specific prior written permission. 32 * derived from this software without specific prior written permission.
33 * 33 *
34 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 34 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 37 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 43 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 * POSSIBILITY OF SUCH DAMAGE. 44 * POSSIBILITY OF SUCH DAMAGE.
45 */ 45 */
46 46
47/* 47/*
48 * Acknowledgements: Many of the algorithms used in this driver are 48 * Acknowledgements: Many of the algorithms used in this driver are
49 * inspired by the work of Julian Elischer (julian@tfs.com) and 49 * inspired by the work of Julian Elischer (julian@tfs.com) and
50 * Charles Hannum (mycroft@duality.gnu.ai.mit.edu). Thanks a million! 50 * Charles Hannum (mycroft@duality.gnu.ai.mit.edu). Thanks a million!
51 */ 51 */
52 52
53/* TODO list: 53/* TODO list:
54 * 1) Get the DMA stuff working. 54 * 1) Get the DMA stuff working.
55 * 2) Get the iov/uio stuff working. Is this a good thing ??? 55 * 2) Get the iov/uio stuff working. Is this a good thing ???
56 * 3) Get the synch stuff working. 56 * 3) Get the synch stuff working.
57 * 4) Rewrite it to use malloc for the acb structs instead of static alloc.? 57 * 4) Rewrite it to use malloc for the acb structs instead of static alloc.?
58 */ 58 */
59 59
60#include <sys/cdefs.h> 60#include <sys/cdefs.h>
61__KERNEL_RCSID(0, "$NetBSD: aic6360.c,v 1.105 2022/01/01 21:07:14 andvar Exp $"); 61__KERNEL_RCSID(0, "$NetBSD: aic6360.c,v 1.106 2023/04/05 21:46:09 andvar Exp $");
62 62
63#include "opt_ddb.h" 63#include "opt_ddb.h"
64 64
65/* 65/*
66 * A few customizable items: 66 * A few customizable items:
67 */ 67 */
68 68
69/* Use doubleword transfers to/from SCSI chip. Note: This requires 69/* Use doubleword transfers to/from SCSI chip. Note: This requires
70 * motherboard support. Basically, some motherboard chipsets are able to 70 * motherboard support. Basically, some motherboard chipsets are able to
71 * split a 32 bit I/O operation into two 16 bit I/O operations, 71 * split a 32 bit I/O operation into two 16 bit I/O operations,
72 * transparently to the processor. This speeds up some things, notably long 72 * transparently to the processor. This speeds up some things, notably long
73 * data transfers. 73 * data transfers.
74 */ 74 */
75#define AIC_USE_DWORDS 0 75#define AIC_USE_DWORDS 0
76 76
77/* Synchronous data transfers? */ 77/* Synchronous data transfers? */
78#define AIC_USE_SYNCHRONOUS 0 78#define AIC_USE_SYNCHRONOUS 0
79#define AIC_SYNC_REQ_ACK_OFS 8 79#define AIC_SYNC_REQ_ACK_OFS 8
80 80
81/* Wide data transfers? */ 81/* Wide data transfers? */
82#define AIC_USE_WIDE 0 82#define AIC_USE_WIDE 0
83#define AIC_MAX_WIDTH 0 83#define AIC_MAX_WIDTH 0
84 84
85/* Max attempts made to transmit a message */ 85/* Max attempts made to transmit a message */
86#define AIC_MSG_MAX_ATTEMPT 3 /* Not used now XXX */ 86#define AIC_MSG_MAX_ATTEMPT 3 /* Not used now XXX */
87 87
88/* Use DMA (else we do programmed I/O using string instructions) (not yet!)*/ 88/* Use DMA (else we do programmed I/O using string instructions) (not yet!)*/
89#define AIC_USE_EISA_DMA 0 89#define AIC_USE_EISA_DMA 0
90#define AIC_USE_ISA_DMA 0 90#define AIC_USE_ISA_DMA 0
91 91
92/* How to behave on the (E)ISA bus when/if DMAing (on<<4) + off in us */ 92/* How to behave on the (E)ISA bus when/if DMAing (on<<4) + off in us */
93#define EISA_BRST_TIM ((15<<4) + 1) /* 15us on, 1us off */ 93#define EISA_BRST_TIM ((15<<4) + 1) /* 15us on, 1us off */
94 94
95/* Some spin loop parameters (essentially how long to wait some places) 95/* Some spin loop parameters (essentially how long to wait some places)
96 * The problem(?) is that sometimes we expect either to be able to transmit a 96 * The problem(?) is that sometimes we expect either to be able to transmit a
97 * byte or to get a new one from the SCSI bus pretty soon. In order to avoid 97 * byte or to get a new one from the SCSI bus pretty soon. In order to avoid
98 * returning from the interrupt just to get yanked back for the next byte we 98 * returning from the interrupt just to get yanked back for the next byte we
99 * may spin in the interrupt routine waiting for this byte to come. How long? 99 * may spin in the interrupt routine waiting for this byte to come. How long?
100 * This is really (SCSI) device and processor dependent. Tuneable, I guess. 100 * This is really (SCSI) device and processor dependent. Tuneable, I guess.
101 */ 101 */
102#define AIC_MSGIN_SPIN 1 /* Will spinwait upto ?ms for a new msg byte */ 102#define AIC_MSGIN_SPIN 1 /* Will spinwait upto ?ms for a new msg byte */
103#define AIC_MSGOUT_SPIN 1 103#define AIC_MSGOUT_SPIN 1
104 104
105/* Include debug functions? At the end of this file there are a bunch of 105/* Include debug functions? At the end of this file there are a bunch of
106 * functions that will print out various information regarding queued SCSI 106 * functions that will print out various information regarding queued SCSI
107 * commands, driver state and chip contents. You can call them from the 107 * commands, driver state and chip contents. You can call them from the
108 * kernel debugger. If you set AIC_DEBUG to 0 they are not included (the 108 * kernel debugger. If you set AIC_DEBUG to 0 they are not included (the
109 * kernel uses less memory) but you lose the debugging facilities. 109 * kernel uses less memory) but you lose the debugging facilities.
110 */ 110 */
111#define AIC_DEBUG 1 111#define AIC_DEBUG 1
112 112
113#define AIC_ABORT_TIMEOUT 2000 /* time to wait for abort */ 113#define AIC_ABORT_TIMEOUT 2000 /* time to wait for abort */
114 114
115/* End of customizable parameters */ 115/* End of customizable parameters */
116 116
117#if AIC_USE_EISA_DMA || AIC_USE_ISA_DMA 117#if AIC_USE_EISA_DMA || AIC_USE_ISA_DMA
118#error "I said not yet! Start paying attention... grumble" 118#error "I said not yet! Start paying attention... grumble"
119#endif 119#endif
120 120
121#include <sys/param.h> 121#include <sys/param.h>
122#include <sys/systm.h> 122#include <sys/systm.h>
123#include <sys/callout.h> 123#include <sys/callout.h>
124#include <sys/kernel.h> 124#include <sys/kernel.h>
125#include <sys/errno.h> 125#include <sys/errno.h>
126#include <sys/ioctl.h> 126#include <sys/ioctl.h>
127#include <sys/device.h> 127#include <sys/device.h>
128#include <sys/buf.h> 128#include <sys/buf.h>
129#include <sys/proc.h> 129#include <sys/proc.h>
130#include <sys/queue.h> 130#include <sys/queue.h>
131 131
132#include <sys/bus.h> 132#include <sys/bus.h>
133#include <sys/intr.h> 133#include <sys/intr.h>
134 134
135#include <dev/scsipi/scsi_spc.h> 135#include <dev/scsipi/scsi_spc.h>
136#include <dev/scsipi/scsi_all.h> 136#include <dev/scsipi/scsi_all.h>
137#include <dev/scsipi/scsipi_all.h> 137#include <dev/scsipi/scsipi_all.h>
138#include <dev/scsipi/scsi_message.h> 138#include <dev/scsipi/scsi_message.h>
139#include <dev/scsipi/scsiconf.h> 139#include <dev/scsipi/scsiconf.h>
140 140
141#include <dev/ic/aic6360reg.h> 141#include <dev/ic/aic6360reg.h>
142#include <dev/ic/aic6360var.h> 142#include <dev/ic/aic6360var.h>
143 143
144#include "ioconf.h" 144#include "ioconf.h"
145 145
146#ifndef DDB 146#ifndef DDB
147#define Debugger() panic("should call debugger here (aic6360.c)") 147#define Debugger() panic("should call debugger here (aic6360.c)")
148#endif /* ! DDB */ 148#endif /* ! DDB */
149 149
150#if AIC_DEBUG 150#if AIC_DEBUG
151int aic_debug = 0x00; /* AIC_SHOWSTART|AIC_SHOWMISC|AIC_SHOWTRACE; */ 151int aic_debug = 0x00; /* AIC_SHOWSTART|AIC_SHOWMISC|AIC_SHOWTRACE; */
152#endif 152#endif
153 153
154static void aic_minphys(struct buf *); 154static void aic_minphys(struct buf *);
155static void aic_done(struct aic_softc *, struct aic_acb *); 155static void aic_done(struct aic_softc *, struct aic_acb *);
156static void aic_dequeue(struct aic_softc *, struct aic_acb *); 156static void aic_dequeue(struct aic_softc *, struct aic_acb *);
157static void aic_scsipi_request(struct scsipi_channel *, 157static void aic_scsipi_request(struct scsipi_channel *,
158 scsipi_adapter_req_t, void *); 158 scsipi_adapter_req_t, void *);
159static int aic_poll(struct aic_softc *, struct scsipi_xfer *, int); 159static int aic_poll(struct aic_softc *, struct scsipi_xfer *, int);
160static void aic_select(struct aic_softc *, struct aic_acb *); 160static void aic_select(struct aic_softc *, struct aic_acb *);
161static void aic_timeout(void *); 161static void aic_timeout(void *);
162static void aic_sched(struct aic_softc *); 162static void aic_sched(struct aic_softc *);
163static void aic_scsi_reset(struct aic_softc *); 163static void aic_scsi_reset(struct aic_softc *);
164static void aic_reset(struct aic_softc *); 164static void aic_reset(struct aic_softc *);
165static void aic_free_acb(struct aic_softc *, struct aic_acb *); 165static void aic_free_acb(struct aic_softc *, struct aic_acb *);
166static struct aic_acb* aic_get_acb(struct aic_softc *); 166static struct aic_acb* aic_get_acb(struct aic_softc *);
167static int aic_reselect(struct aic_softc *, int); 167static int aic_reselect(struct aic_softc *, int);
168static void aic_sense(struct aic_softc *, struct aic_acb *); 168static void aic_sense(struct aic_softc *, struct aic_acb *);
169static void aic_msgin(struct aic_softc *); 169static void aic_msgin(struct aic_softc *);
170static void aic_abort(struct aic_softc *, struct aic_acb *); 170static void aic_abort(struct aic_softc *, struct aic_acb *);
171static void aic_msgout(struct aic_softc *); 171static void aic_msgout(struct aic_softc *);
172static int aic_dataout_pio(struct aic_softc *, u_char *, int); 172static int aic_dataout_pio(struct aic_softc *, u_char *, int);
173static int aic_datain_pio(struct aic_softc *, u_char *, int); 173static int aic_datain_pio(struct aic_softc *, u_char *, int);
174static void aic_update_xfer_mode(struct aic_softc *, int); 174static void aic_update_xfer_mode(struct aic_softc *, int);
175#if AIC_DEBUG 175#if AIC_DEBUG
176static void aic_print_acb(struct aic_acb *); 176static void aic_print_acb(struct aic_acb *);
177void aic_dump_driver(struct aic_softc *); 177void aic_dump_driver(struct aic_softc *);
178void aic_dump6360(struct aic_softc *); 178void aic_dump6360(struct aic_softc *);
179static void aic_show_scsi_cmd(struct aic_acb *); 179static void aic_show_scsi_cmd(struct aic_acb *);
180void aic_print_active_acb(void); 180void aic_print_active_acb(void);
181#endif 181#endif
182 182
183/* 183/*
184 * INITIALIZATION ROUTINES (probe, attach ++) 184 * INITIALIZATION ROUTINES (probe, attach ++)
185 */ 185 */
186 186
187/* Do the real search-for-device. 187/* Do the real search-for-device.
188 * Prerequisite: sc->sc_iobase should be set to the proper value 188 * Prerequisite: sc->sc_iobase should be set to the proper value
189 */ 189 */
190int 190int
191aic_find(bus_space_tag_t iot, bus_space_handle_t ioh) 191aic_find(bus_space_tag_t iot, bus_space_handle_t ioh)
192{ 192{
193 char chip_id[sizeof(IDSTRING)]; /* For chips that support it */ 193 char chip_id[sizeof(IDSTRING)]; /* For chips that support it */
194 int i; 194 int i;
195 195
196 /* Remove aic6360 from possible powerdown mode */ 196 /* Remove aic6360 from possible powerdown mode */
197 bus_space_write_1(iot, ioh, DMACNTRL0, 0); 197 bus_space_write_1(iot, ioh, DMACNTRL0, 0);
198 198
199 /* Thanks to mark@aggregate.com for the new method for detecting 199 /* Thanks to mark@aggregate.com for the new method for detecting
200 * whether the chip is present or not. Bonus: may also work for 200 * whether the chip is present or not. Bonus: may also work for
201 * the AIC-6260! 201 * the AIC-6260!
202 */ 202 */
203 AIC_TRACE(("aic: probing for aic-chip\n")); 203 AIC_TRACE(("aic: probing for aic-chip\n"));
204 /* 204 /*
205 * Linux also init's the stack to 1-16 and then clears it, 205 * Linux also init's the stack to 1-16 and then clears it,
206 * 6260's don't appear to have an ID reg - mpg 206 * 6260's don't appear to have an ID reg - mpg
207 */ 207 */
208 /* Push the sequence 0,1,..,15 on the stack */ 208 /* Push the sequence 0,1,..,15 on the stack */
209#define STSIZE 16 209#define STSIZE 16
210 bus_space_write_1(iot, ioh, DMACNTRL1, 0); /* Reset stack pointer */ 210 bus_space_write_1(iot, ioh, DMACNTRL1, 0); /* Reset stack pointer */
211 for (i = 0; i < STSIZE; i++) 211 for (i = 0; i < STSIZE; i++)
212 bus_space_write_1(iot, ioh, STACK, i); 212 bus_space_write_1(iot, ioh, STACK, i);
213 213
214 /* See if we can pull out the same sequence */ 214 /* See if we can pull out the same sequence */
215 bus_space_write_1(iot, ioh, DMACNTRL1, 0); 215 bus_space_write_1(iot, ioh, DMACNTRL1, 0);
216 for (i = 0; i < STSIZE && bus_space_read_1(iot, ioh, STACK) == i; i++) 216 for (i = 0; i < STSIZE && bus_space_read_1(iot, ioh, STACK) == i; i++)
217 ; 217 ;
218 if (i != STSIZE) { 218 if (i != STSIZE) {
219 AIC_START(("STACK futzed at %d.\n", i)); 219 AIC_START(("STACK futzed at %d.\n", i));
220 return 0; 220 return 0;
221 } 221 }
222 222
223 /* See if we can pull the id string out of the ID register, 223 /* See if we can pull the id string out of the ID register,
224 * now only used for informational purposes. 224 * now only used for informational purposes.
225 */ 225 */
226 memset(chip_id, 0, sizeof(chip_id)); 226 memset(chip_id, 0, sizeof(chip_id));
227 bus_space_read_multi_1(iot, ioh, ID, chip_id, sizeof(IDSTRING) - 1); 227 bus_space_read_multi_1(iot, ioh, ID, chip_id, sizeof(IDSTRING) - 1);
228 AIC_START(("AIC found ID: %s ",chip_id)); 228 AIC_START(("AIC found ID: %s ",chip_id));
229 AIC_START(("chip revision %d\n", 229 AIC_START(("chip revision %d\n",
230 (int)bus_space_read_1(iot, ioh, REV))); 230 (int)bus_space_read_1(iot, ioh, REV)));
231 231
232 return 1; 232 return 1;
233} 233}
234 234
235/* 235/*
236 * Attach the AIC6360, fill out some high and low level data structures 236 * Attach the AIC6360, fill out some high and low level data structures
237 */ 237 */
238void 238void
239aicattach(struct aic_softc *sc) 239aicattach(struct aic_softc *sc)
240{ 240{
241 struct scsipi_adapter *adapt = &sc->sc_adapter; 241 struct scsipi_adapter *adapt = &sc->sc_adapter;
242 struct scsipi_channel *chan = &sc->sc_channel; 242 struct scsipi_channel *chan = &sc->sc_channel;
243 243
244 AIC_TRACE(("aicattach ")); 244 AIC_TRACE(("aicattach "));
245 sc->sc_state = AIC_INIT; 245 sc->sc_state = AIC_INIT;
246 246
247 sc->sc_initiator = 7; 247 sc->sc_initiator = 7;
248 sc->sc_freq = 20; /* XXXX Assume 20 MHz. */ 248 sc->sc_freq = 20; /* XXXX Assume 20 MHz. */
249 249
250 /* 250 /*
251 * These are the bounds of the sync period, based on the frequency of 251 * These are the bounds of the sync period, based on the frequency of
252 * the chip's clock input and the size and offset of the sync period 252 * the chip's clock input and the size and offset of the sync period
253 * register. 253 * register.
254 * 254 *
255 * For a 20MHz clock, this gives us 25, or 100nS, or 10MB/s, as a 255 * For a 20MHz clock, this gives us 25, or 100nS, or 10MB/s, as a
256 * maximum transfer rate, and 112.5, or 450nS, or 2.22MB/s, as a 256 * maximum transfer rate, and 112.5, or 450nS, or 2.22MB/s, as a
257 * minimum transfer rate. 257 * minimum transfer rate.
258 */ 258 */
259 sc->sc_minsync = (2 * 250) / sc->sc_freq; 259 sc->sc_minsync = (2 * 250) / sc->sc_freq;
260 sc->sc_maxsync = (9 * 250) / sc->sc_freq; 260 sc->sc_maxsync = (9 * 250) / sc->sc_freq;
261 261
262 /* 262 /*
263 * Fill in the scsipi_adapter. 263 * Fill in the scsipi_adapter.
264 */ 264 */
265 adapt->adapt_dev = sc->sc_dev; 265 adapt->adapt_dev = sc->sc_dev;
266 adapt->adapt_nchannels = 1; 266 adapt->adapt_nchannels = 1;
267 adapt->adapt_openings = 8; 267 adapt->adapt_openings = 8;
268 adapt->adapt_max_periph = 1; 268 adapt->adapt_max_periph = 1;
269 adapt->adapt_request = aic_scsipi_request; 269 adapt->adapt_request = aic_scsipi_request;
270 adapt->adapt_minphys = aic_minphys; 270 adapt->adapt_minphys = aic_minphys;
271 271
272 /* 272 /*
273 * Fill in the scsipi_channel. 273 * Fill in the scsipi_channel.
274 */ 274 */
275 chan->chan_adapter = adapt; 275 chan->chan_adapter = adapt;
276 chan->chan_bustype = &scsi_bustype; 276 chan->chan_bustype = &scsi_bustype;
277 chan->chan_channel = 0; 277 chan->chan_channel = 0;
278 chan->chan_ntargets = 8; 278 chan->chan_ntargets = 8;
279 chan->chan_nluns = 8; 279 chan->chan_nluns = 8;
280 chan->chan_id = sc->sc_initiator; 280 chan->chan_id = sc->sc_initiator;
281 281
282 /* 282 /*
283 * Add reference to adapter so that we drop the reference after 283 * Add reference to adapter so that we drop the reference after
284 * config_found() to make sure the adapter is disabled. 284 * config_found() to make sure the adapter is disabled.
285 */ 285 */
286 if (scsipi_adapter_addref(adapt) != 0) { 286 if (scsipi_adapter_addref(adapt) != 0) {
287 aprint_error_dev(sc->sc_dev, "unable to enable controller\n"); 287 aprint_error_dev(sc->sc_dev, "unable to enable controller\n");
288 return; 288 return;
289 } 289 }
290 290
291 aic_init(sc, 1); /* Init chip and driver */ 291 aic_init(sc, 1); /* Init chip and driver */
292 292
293 /* 293 /*
294 * Ask the adapter what subunits are present 294 * Ask the adapter what subunits are present
295 */ 295 */
296 sc->sc_child = config_found(sc->sc_dev, &sc->sc_channel, scsiprint, 296 sc->sc_child = config_found(sc->sc_dev, &sc->sc_channel, scsiprint,
297 CFARGS_NONE); 297 CFARGS_NONE);
298 scsipi_adapter_delref(adapt); 298 scsipi_adapter_delref(adapt);
299} 299}
300 300
301int 301int
302aic_detach(device_t self, int flags) 302aic_detach(device_t self, int flags)
303{ 303{
304 struct aic_softc *sc = device_private(self); 304 struct aic_softc *sc = device_private(self);
305 int rv = 0; 305 int rv = 0;
306 306
307 if (sc->sc_child != NULL) 307 if (sc->sc_child != NULL)
308 rv = config_detach(sc->sc_child, flags); 308 rv = config_detach(sc->sc_child, flags);
309 309
310 return (rv); 310 return (rv);
311} 311}
312 312
313/* Initialize AIC6360 chip itself 313/* Initialize AIC6360 chip itself
314 * The following conditions should hold: 314 * The following conditions should hold:
315 * aic_isa_probe should have succeeded, i.e. the iobase address in aic_softc 315 * aic_isa_probe should have succeeded, i.e. the iobase address in aic_softc
316 * must be valid. 316 * must be valid.
317 */ 317 */
318static void 318static void
319aic_reset(struct aic_softc *sc) 319aic_reset(struct aic_softc *sc)
320{ 320{
321 bus_space_tag_t iot = sc->sc_iot; 321 bus_space_tag_t iot = sc->sc_iot;
322 bus_space_handle_t ioh = sc->sc_ioh; 322 bus_space_handle_t ioh = sc->sc_ioh;
323 323
324 /* 324 /*
325 * Doc. recommends to clear these two registers before 325 * Doc. recommends to clear these two registers before
326 * operations commence 326 * operations commence
327 */ 327 */
328 bus_space_write_1(iot, ioh, SCSITEST, 0); 328 bus_space_write_1(iot, ioh, SCSITEST, 0);
329 bus_space_write_1(iot, ioh, TEST, 0); 329 bus_space_write_1(iot, ioh, TEST, 0);
330 330
331 /* Reset SCSI-FIFO and abort any transfers */ 331 /* Reset SCSI-FIFO and abort any transfers */
332 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRCH | CLRSTCNT); 332 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRCH | CLRSTCNT);
333 333
334 /* Reset DMA-FIFO */ 334 /* Reset DMA-FIFO */
335 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO); 335 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO);
336 bus_space_write_1(iot, ioh, DMACNTRL1, 0); 336 bus_space_write_1(iot, ioh, DMACNTRL1, 0);
337 337
338 /* Disable all selection features */ 338 /* Disable all selection features */
339 bus_space_write_1(iot, ioh, SCSISEQ, 0); 339 bus_space_write_1(iot, ioh, SCSISEQ, 0);
340 bus_space_write_1(iot, ioh, SXFRCTL1, 0); 340 bus_space_write_1(iot, ioh, SXFRCTL1, 0);
341 341
342 /* Disable some interrupts */ 342 /* Disable some interrupts */
343 bus_space_write_1(iot, ioh, SIMODE0, 0x00); 343 bus_space_write_1(iot, ioh, SIMODE0, 0x00);
344 /* Clear a slew of interrupts */ 344 /* Clear a slew of interrupts */
345 bus_space_write_1(iot, ioh, CLRSINT0, 0x7f); 345 bus_space_write_1(iot, ioh, CLRSINT0, 0x7f);
346 346
347 /* Disable some more interrupts */ 347 /* Disable some more interrupts */
348 bus_space_write_1(iot, ioh, SIMODE1, 0x00); 348 bus_space_write_1(iot, ioh, SIMODE1, 0x00);
349 /* Clear another slew of interrupts */ 349 /* Clear another slew of interrupts */
350 bus_space_write_1(iot, ioh, CLRSINT1, 0xef); 350 bus_space_write_1(iot, ioh, CLRSINT1, 0xef);
351 351
352 /* Disable synchronous transfers */ 352 /* Disable synchronous transfers */
353 bus_space_write_1(iot, ioh, SCSIRATE, 0); 353 bus_space_write_1(iot, ioh, SCSIRATE, 0);
354 354
355 /* Haven't seen ant errors (yet) */ 355 /* Haven't seen ant errors (yet) */
356 bus_space_write_1(iot, ioh, CLRSERR, 0x07); 356 bus_space_write_1(iot, ioh, CLRSERR, 0x07);
357 357
358 /* Set our SCSI-ID */ 358 /* Set our SCSI-ID */
359 bus_space_write_1(iot, ioh, SCSIID, sc->sc_initiator << OID_S); 359 bus_space_write_1(iot, ioh, SCSIID, sc->sc_initiator << OID_S);
360 bus_space_write_1(iot, ioh, BRSTCNTRL, EISA_BRST_TIM); 360 bus_space_write_1(iot, ioh, BRSTCNTRL, EISA_BRST_TIM);
361} 361}
362 362
363/* Pull the SCSI RST line for 500 us */ 363/* Pull the SCSI RST line for 500 us */
364static void 364static void
365aic_scsi_reset(struct aic_softc *sc) 365aic_scsi_reset(struct aic_softc *sc)
366{ 366{
367 bus_space_tag_t iot = sc->sc_iot; 367 bus_space_tag_t iot = sc->sc_iot;
368 bus_space_handle_t ioh = sc->sc_ioh; 368 bus_space_handle_t ioh = sc->sc_ioh;
369 369
370 bus_space_write_1(iot, ioh, SCSISEQ, SCSIRSTO); 370 bus_space_write_1(iot, ioh, SCSISEQ, SCSIRSTO);
371 delay(500); 371 delay(500);
372 bus_space_write_1(iot, ioh, SCSISEQ, 0); 372 bus_space_write_1(iot, ioh, SCSISEQ, 0);
373 delay(50); 373 delay(50);
374} 374}
375 375
376/* 376/*
377 * Initialize aic SCSI driver. 377 * Initialize aic SCSI driver.
378 */ 378 */
379void 379void
380aic_init(struct aic_softc *sc, int bus_reset) 380aic_init(struct aic_softc *sc, int bus_reset)
381{ 381{
382 struct aic_acb *acb; 382 struct aic_acb *acb;
383 int r; 383 int r;
384 384
385 if (bus_reset) { 385 if (bus_reset) {
386 aic_reset(sc); 386 aic_reset(sc);
387 aic_scsi_reset(sc); 387 aic_scsi_reset(sc);
388 } 388 }
389 aic_reset(sc); 389 aic_reset(sc);
390 390
391 if (sc->sc_state == AIC_INIT) { 391 if (sc->sc_state == AIC_INIT) {
392 /* First time through; initialize. */ 392 /* First time through; initialize. */
393 TAILQ_INIT(&sc->ready_list); 393 TAILQ_INIT(&sc->ready_list);
394 TAILQ_INIT(&sc->nexus_list); 394 TAILQ_INIT(&sc->nexus_list);
395 TAILQ_INIT(&sc->free_list); 395 TAILQ_INIT(&sc->free_list);
396 sc->sc_nexus = NULL; 396 sc->sc_nexus = NULL;
397 acb = sc->sc_acb; 397 acb = sc->sc_acb;
398 memset(acb, 0, sizeof(sc->sc_acb)); 398 memset(acb, 0, sizeof(sc->sc_acb));
399 for (r = 0; r < sizeof(sc->sc_acb) / sizeof(*acb); r++) { 399 for (r = 0; r < sizeof(sc->sc_acb) / sizeof(*acb); r++) {
400 TAILQ_INSERT_TAIL(&sc->free_list, acb, chain); 400 TAILQ_INSERT_TAIL(&sc->free_list, acb, chain);
401 acb++; 401 acb++;
402 } 402 }
403 memset(&sc->sc_tinfo, 0, sizeof(sc->sc_tinfo)); 403 memset(&sc->sc_tinfo, 0, sizeof(sc->sc_tinfo));
404 } else { 404 } else {
405 /* Cancel any active commands. */ 405 /* Cancel any active commands. */
406 sc->sc_state = AIC_CLEANING; 406 sc->sc_state = AIC_CLEANING;
407 if ((acb = sc->sc_nexus) != NULL) { 407 if ((acb = sc->sc_nexus) != NULL) {
408 acb->xs->error = XS_DRIVER_STUFFUP; 408 acb->xs->error = XS_DRIVER_STUFFUP;
409 callout_stop(&acb->xs->xs_callout); 409 callout_stop(&acb->xs->xs_callout);
410 aic_done(sc, acb); 410 aic_done(sc, acb);
411 } 411 }
412 while ((acb = sc->nexus_list.tqh_first) != NULL) { 412 while ((acb = sc->nexus_list.tqh_first) != NULL) {
413 acb->xs->error = XS_DRIVER_STUFFUP; 413 acb->xs->error = XS_DRIVER_STUFFUP;
414 callout_stop(&acb->xs->xs_callout); 414 callout_stop(&acb->xs->xs_callout);
415 aic_done(sc, acb); 415 aic_done(sc, acb);
416 } 416 }
417 } 417 }
418 418
419 sc->sc_prevphase = PH_INVALID; 419 sc->sc_prevphase = PH_INVALID;
420 for (r = 0; r < 8; r++) { 420 for (r = 0; r < 8; r++) {
421 struct aic_tinfo *ti = &sc->sc_tinfo[r]; 421 struct aic_tinfo *ti = &sc->sc_tinfo[r];
422 422
423 ti->flags = 0; 423 ti->flags = 0;
424 ti->period = ti->offset = 0; 424 ti->period = ti->offset = 0;
425 ti->width = 0; 425 ti->width = 0;
426 } 426 }
427 427
428 sc->sc_state = AIC_IDLE; 428 sc->sc_state = AIC_IDLE;
429 bus_space_write_1(sc->sc_iot, sc->sc_ioh, DMACNTRL0, INTEN); 429 bus_space_write_1(sc->sc_iot, sc->sc_ioh, DMACNTRL0, INTEN);
430} 430}
431 431
432static void 432static void
433aic_free_acb(struct aic_softc *sc, struct aic_acb *acb) 433aic_free_acb(struct aic_softc *sc, struct aic_acb *acb)
434{ 434{
435 int s; 435 int s;
436 436
437 s = splbio(); 437 s = splbio();
438 acb->flags = 0; 438 acb->flags = 0;
439 TAILQ_INSERT_HEAD(&sc->free_list, acb, chain); 439 TAILQ_INSERT_HEAD(&sc->free_list, acb, chain);
440 splx(s); 440 splx(s);
441} 441}
442 442
443static struct aic_acb * 443static struct aic_acb *
444aic_get_acb(struct aic_softc *sc) 444aic_get_acb(struct aic_softc *sc)
445{ 445{
446 struct aic_acb *acb; 446 struct aic_acb *acb;
447 int s; 447 int s;
448 448
449 s = splbio(); 449 s = splbio();
450 acb = TAILQ_FIRST(&sc->free_list); 450 acb = TAILQ_FIRST(&sc->free_list);
451 if (acb != NULL) { 451 if (acb != NULL) {
452 TAILQ_REMOVE(&sc->free_list, acb, chain); 452 TAILQ_REMOVE(&sc->free_list, acb, chain);
453 acb->flags |= ACB_ALLOC; 453 acb->flags |= ACB_ALLOC;
454 } 454 }
455 splx(s); 455 splx(s);
456 return (acb); 456 return (acb);
457} 457}
458 458
459/* 459/*
460 * DRIVER FUNCTIONS CALLABLE FROM HIGHER LEVEL DRIVERS 460 * DRIVER FUNCTIONS CALLABLE FROM HIGHER LEVEL DRIVERS
461 */ 461 */
462 462
463/* 463/*
464 * Expected sequence: 464 * Expected sequence:
465 * 1) Command inserted into ready list 465 * 1) Command inserted into ready list
466 * 2) Command selected for execution 466 * 2) Command selected for execution
467 * 3) Command won arbitration and has selected target device 467 * 3) Command won arbitration and has selected target device
468 * 4) Send message out (identify message, eventually also sync.negotiations) 468 * 4) Send message out (identify message, eventually also sync.negotiations)
469 * 5) Send command 469 * 5) Send command
470 * 5a) Receive disconnect message, disconnect. 470 * 5a) Receive disconnect message, disconnect.
471 * 5b) Reselected by target 471 * 5b) Reselected by target
472 * 5c) Receive identify message from target. 472 * 5c) Receive identify message from target.
473 * 6) Send or receive data 473 * 6) Send or receive data
474 * 7) Receive status 474 * 7) Receive status
475 * 8) Receive message (command complete etc.) 475 * 8) Receive message (command complete etc.)
476 * 9) If status == SCSI_CHECK construct a synthetic request sense SCSI cmd. 476 * 9) If status == SCSI_CHECK construct a synthetic request sense SCSI cmd.
477 * Repeat 2-8 (no disconnects please...) 477 * Repeat 2-8 (no disconnects please...)
478 */ 478 */
479 479
480/* 480/*
481 * Perform a request from the SCSIPI midlayer. 481 * Perform a request from the SCSIPI midlayer.
482 */ 482 */
483static void 483static void
484aic_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req, 484aic_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
485 void *arg) 485 void *arg)
486{ 486{
487 struct scsipi_xfer *xs; 487 struct scsipi_xfer *xs;
488 struct scsipi_periph *periph; 488 struct scsipi_periph *periph;
489 struct aic_softc *sc = device_private(chan->chan_adapter->adapt_dev); 489 struct aic_softc *sc = device_private(chan->chan_adapter->adapt_dev);
490 struct aic_acb *acb; 490 struct aic_acb *acb;
491 int s, flags; 491 int s, flags;
492 492
493 AIC_TRACE(("aic_request ")); 493 AIC_TRACE(("aic_request "));
494 494
495 switch (req) { 495 switch (req) {
496 case ADAPTER_REQ_RUN_XFER: 496 case ADAPTER_REQ_RUN_XFER:
497 xs = arg; 497 xs = arg;
498 periph = xs->xs_periph; 498 periph = xs->xs_periph;
499 499
500 AIC_CMDS(("[0x%x, %d]->%d ", (int)xs->cmd->opcode, xs->cmdlen, 500 AIC_CMDS(("[0x%x, %d]->%d ", (int)xs->cmd->opcode, xs->cmdlen,
501 periph->periph_target)); 501 periph->periph_target));
502 502
503 if (!device_is_active(sc->sc_dev)) { 503 if (!device_is_active(sc->sc_dev)) {
504 xs->error = XS_DRIVER_STUFFUP; 504 xs->error = XS_DRIVER_STUFFUP;
505 scsipi_done(xs); 505 scsipi_done(xs);
506 return; 506 return;
507 } 507 }
508 508
509 flags = xs->xs_control; 509 flags = xs->xs_control;
510 acb = aic_get_acb(sc); 510 acb = aic_get_acb(sc);
511#ifdef DIAGNOSTIC 511#ifdef DIAGNOSTIC
512 /* 512 /*
513 * This should never happen as we track the resources 513 * This should never happen as we track the resources
514 * in the mid-layer. 514 * in the mid-layer.
515 */ 515 */
516 if (acb == NULL) { 516 if (acb == NULL) {
517 scsipi_printaddr(periph); 517 scsipi_printaddr(periph);
518 printf("unable to allocate acb\n"); 518 printf("unable to allocate acb\n");
519 panic("aic_scsipi_request"); 519 panic("aic_scsipi_request");
520 } 520 }
521#endif 521#endif
522 522
523 /* Initialize acb */ 523 /* Initialize acb */
524 acb->xs = xs; 524 acb->xs = xs;
525 acb->timeout = xs->timeout; 525 acb->timeout = xs->timeout;
526 526
527 if (xs->xs_control & XS_CTL_RESET) { 527 if (xs->xs_control & XS_CTL_RESET) {
528 acb->flags |= ACB_RESET; 528 acb->flags |= ACB_RESET;
529 acb->scsipi_cmd_length = 0; 529 acb->scsipi_cmd_length = 0;
530 acb->data_length = 0; 530 acb->data_length = 0;
531 } else { 531 } else {
532 memcpy(&acb->scsipi_cmd, xs->cmd, xs->cmdlen); 532 memcpy(&acb->scsipi_cmd, xs->cmd, xs->cmdlen);
533 acb->scsipi_cmd_length = xs->cmdlen; 533 acb->scsipi_cmd_length = xs->cmdlen;
534 acb->data_addr = xs->data; 534 acb->data_addr = xs->data;
535 acb->data_length = xs->datalen; 535 acb->data_length = xs->datalen;
536 } 536 }
537 acb->target_stat = 0; 537 acb->target_stat = 0;
538 538
539 s = splbio(); 539 s = splbio();
540 540
541 TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain); 541 TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain);
542 if (sc->sc_state == AIC_IDLE) 542 if (sc->sc_state == AIC_IDLE)
543 aic_sched(sc); 543 aic_sched(sc);
544 544
545 splx(s); 545 splx(s);
546 546
547 if ((flags & XS_CTL_POLL) == 0) 547 if ((flags & XS_CTL_POLL) == 0)
548 return; 548 return;
549 549
550 /* Not allowed to use interrupts, use polling instead */ 550 /* Not allowed to use interrupts, use polling instead */
551 if (aic_poll(sc, xs, acb->timeout)) { 551 if (aic_poll(sc, xs, acb->timeout)) {
552 aic_timeout(acb); 552 aic_timeout(acb);
553 if (aic_poll(sc, xs, acb->timeout)) 553 if (aic_poll(sc, xs, acb->timeout))
554 aic_timeout(acb); 554 aic_timeout(acb);
555 } 555 }
556 return; 556 return;
557 557
558 case ADAPTER_REQ_GROW_RESOURCES: 558 case ADAPTER_REQ_GROW_RESOURCES:
559 /* XXX Not supported. */ 559 /* XXX Not supported. */
560 return; 560 return;
561 561
562 case ADAPTER_REQ_SET_XFER_MODE: 562 case ADAPTER_REQ_SET_XFER_MODE:
563 { 563 {
564 struct aic_tinfo *ti; 564 struct aic_tinfo *ti;
565 struct scsipi_xfer_mode *xm = arg; 565 struct scsipi_xfer_mode *xm = arg;
566 566
567 ti = &sc->sc_tinfo[xm->xm_target]; 567 ti = &sc->sc_tinfo[xm->xm_target];
568 ti->flags &= ~(DO_SYNC|DO_WIDE); 568 ti->flags &= ~(DO_SYNC|DO_WIDE);
569 ti->period = 0; 569 ti->period = 0;
570 ti->offset = 0; 570 ti->offset = 0;
571 571
572#if AIC_USE_SYNCHRONOUS 572#if AIC_USE_SYNCHRONOUS
573 if (xm->xm_mode & PERIPH_CAP_SYNC) { 573 if (xm->xm_mode & PERIPH_CAP_SYNC) {
574 ti->flags |= DO_SYNC; 574 ti->flags |= DO_SYNC;
575 ti->period = sc->sc_minsync; 575 ti->period = sc->sc_minsync;
576 ti->offset = AIC_SYNC_REQ_ACK_OFS; 576 ti->offset = AIC_SYNC_REQ_ACK_OFS;
577 } 577 }
578#endif 578#endif
579#if AIC_USE_WIDE 579#if AIC_USE_WIDE
580 if (xm->xm_mode & PERIPH_CAP_WIDE16) { 580 if (xm->xm_mode & PERIPH_CAP_WIDE16) {
581 ti->flags |= DO_WIDE; 581 ti->flags |= DO_WIDE;
582 ti->width = AIC_MAX_WIDTH; 582 ti->width = AIC_MAX_WIDTH;
583 } 583 }
584#endif 584#endif
585 /* 585 /*
586 * If we're not going to negotiate, send the notification 586 * If we're not going to negotiate, send the notification
587 * now, since it won't happen later. 587 * now, since it won't happen later.
588 */ 588 */
589 if ((ti->flags & (DO_SYNC|DO_WIDE)) == 0) 589 if ((ti->flags & (DO_SYNC|DO_WIDE)) == 0)
590 aic_update_xfer_mode(sc, xm->xm_target); 590 aic_update_xfer_mode(sc, xm->xm_target);
591 return; 591 return;
592 } 592 }
593 } 593 }
594} 594}
595 595
596static void 596static void
597aic_update_xfer_mode(struct aic_softc *sc, int target) 597aic_update_xfer_mode(struct aic_softc *sc, int target)
598{ 598{
599 struct scsipi_xfer_mode xm; 599 struct scsipi_xfer_mode xm;
600 struct aic_tinfo *ti = &sc->sc_tinfo[target]; 600 struct aic_tinfo *ti = &sc->sc_tinfo[target];
601 601
602 xm.xm_target = target; 602 xm.xm_target = target;
603 xm.xm_mode = 0; 603 xm.xm_mode = 0;
604 xm.xm_period = 0; 604 xm.xm_period = 0;
605 xm.xm_offset = 0; 605 xm.xm_offset = 0;
606 606
607 if (ti->offset != 0) { 607 if (ti->offset != 0) {
608 xm.xm_mode |= PERIPH_CAP_SYNC; 608 xm.xm_mode |= PERIPH_CAP_SYNC;
609 xm.xm_period = ti->period; 609 xm.xm_period = ti->period;
610 xm.xm_offset = ti->offset; 610 xm.xm_offset = ti->offset;
611 } 611 }
612 switch (ti->width) { 612 switch (ti->width) {
613 case 2: 613 case 2:
614 xm.xm_mode |= PERIPH_CAP_WIDE32; 614 xm.xm_mode |= PERIPH_CAP_WIDE32;
615 break; 615 break;
616 case 1: 616 case 1:
617 xm.xm_mode |= PERIPH_CAP_WIDE16; 617 xm.xm_mode |= PERIPH_CAP_WIDE16;
618 break; 618 break;
619 } 619 }
620 620
621 scsipi_async_event(&sc->sc_channel, ASYNC_EVENT_XFER_MODE, &xm); 621 scsipi_async_event(&sc->sc_channel, ASYNC_EVENT_XFER_MODE, &xm);
622} 622}
623 623
624/* 624/*
625 * Adjust transfer size in buffer structure 625 * Adjust transfer size in buffer structure
626 */ 626 */
627static void 627static void
628aic_minphys(struct buf *bp) 628aic_minphys(struct buf *bp)
629{ 629{
630 630
631 AIC_TRACE(("aic_minphys ")); 631 AIC_TRACE(("aic_minphys "));
632 if (bp->b_bcount > (AIC_NSEG << PGSHIFT)) 632 if (bp->b_bcount > (AIC_NSEG << PGSHIFT))
633 bp->b_bcount = (AIC_NSEG << PGSHIFT); 633 bp->b_bcount = (AIC_NSEG << PGSHIFT);
634 minphys(bp); 634 minphys(bp);
635} 635}
636 636
637/* 637/*
638 * Used when interrupt driven I/O isn't allowed, e.g. during boot. 638 * Used when interrupt driven I/O isn't allowed, e.g. during boot.
639 */ 639 */
640static int 640static int
641aic_poll(struct aic_softc *sc, struct scsipi_xfer *xs, int count) 641aic_poll(struct aic_softc *sc, struct scsipi_xfer *xs, int count)
642{ 642{
643 bus_space_tag_t iot = sc->sc_iot; 643 bus_space_tag_t iot = sc->sc_iot;
644 bus_space_handle_t ioh = sc->sc_ioh; 644 bus_space_handle_t ioh = sc->sc_ioh;
645 645
646 AIC_TRACE(("aic_poll ")); 646 AIC_TRACE(("aic_poll "));
647 while (count) { 647 while (count) {
648 /* 648 /*
649 * If we had interrupts enabled, would we 649 * If we had interrupts enabled, would we
650 * have got an interrupt? 650 * have got an interrupt?
651 */ 651 */
652 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT) != 0) 652 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT) != 0)
653 aicintr(sc); 653 aicintr(sc);
654 if ((xs->xs_status & XS_STS_DONE) != 0) 654 if ((xs->xs_status & XS_STS_DONE) != 0)
655 return 0; 655 return 0;
656 delay(1000); 656 delay(1000);
657 count--; 657 count--;
658 } 658 }
659 return 1; 659 return 1;
660} 660}
661 661
662/* 662/*
663 * LOW LEVEL SCSI UTILITIES 663 * LOW LEVEL SCSI UTILITIES
664 */ 664 */
665 665
666static inline void 666static inline void
667aic_sched_msgout(struct aic_softc *sc, u_char m) 667aic_sched_msgout(struct aic_softc *sc, u_char m)
668{ 668{
669 bus_space_tag_t iot = sc->sc_iot; 669 bus_space_tag_t iot = sc->sc_iot;
670 bus_space_handle_t ioh = sc->sc_ioh; 670 bus_space_handle_t ioh = sc->sc_ioh;
671 671
672 if (sc->sc_msgpriq == 0) 672 if (sc->sc_msgpriq == 0)
673 bus_space_write_1(iot, ioh, SCSISIG, sc->sc_phase | ATNO); 673 bus_space_write_1(iot, ioh, SCSISIG, sc->sc_phase | ATNO);
674 sc->sc_msgpriq |= m; 674 sc->sc_msgpriq |= m;
675} 675}
676 676
677/* 677/*
678 * Set synchronous transfer offset and period. 678 * Set synchronous transfer offset and period.
679 */ 679 */
680#if !AIC_USE_SYNCHRONOUS 680#if !AIC_USE_SYNCHRONOUS
681/* ARGSUSED */ 681/* ARGSUSED */
682#endif 682#endif
683static inline void 683static inline void
684aic_setsync(struct aic_softc *sc, struct aic_tinfo *ti) 684aic_setsync(struct aic_softc *sc, struct aic_tinfo *ti)
685{ 685{
686#if AIC_USE_SYNCHRONOUS 686#if AIC_USE_SYNCHRONOUS
687 bus_space_tag_t iot = sc->sc_iot; 687 bus_space_tag_t iot = sc->sc_iot;
688 bus_space_handle_t ioh = sc->sc_ioh; 688 bus_space_handle_t ioh = sc->sc_ioh;
689 689
690 if (ti->offset != 0) 690 if (ti->offset != 0)
691 bus_space_write_1(iot, ioh, SCSIRATE, 691 bus_space_write_1(iot, ioh, SCSIRATE,
692 ((ti->period * sc->sc_freq) / 250 - 2) << 4 | ti->offset); 692 ((ti->period * sc->sc_freq) / 250 - 2) << 4 | ti->offset);
693 else 693 else
694 bus_space_write_1(iot, ioh, SCSIRATE, 0); 694 bus_space_write_1(iot, ioh, SCSIRATE, 0);
695#endif 695#endif
696} 696}
697 697
698/* 698/*
699 * Start a selection. This is used by aic_sched() to select an idle target, 699 * Start a selection. This is used by aic_sched() to select an idle target,
700 * and by aic_done() to immediately reselect a target to get sense information. 700 * and by aic_done() to immediately reselect a target to get sense information.
701 */ 701 */
702static void 702static void
703aic_select(struct aic_softc *sc, struct aic_acb *acb) 703aic_select(struct aic_softc *sc, struct aic_acb *acb)
704{ 704{
705 struct scsipi_periph *periph = acb->xs->xs_periph; 705 struct scsipi_periph *periph = acb->xs->xs_periph;
706 int target = periph->periph_target; 706 int target = periph->periph_target;
707 struct aic_tinfo *ti = &sc->sc_tinfo[target]; 707 struct aic_tinfo *ti = &sc->sc_tinfo[target];
708 bus_space_tag_t iot = sc->sc_iot; 708 bus_space_tag_t iot = sc->sc_iot;
709 bus_space_handle_t ioh = sc->sc_ioh; 709 bus_space_handle_t ioh = sc->sc_ioh;
710 710
711 bus_space_write_1(iot, ioh, SCSIID, 711 bus_space_write_1(iot, ioh, SCSIID,
712 sc->sc_initiator << OID_S | target); 712 sc->sc_initiator << OID_S | target);
713 aic_setsync(sc, ti); 713 aic_setsync(sc, ti);
714 bus_space_write_1(iot, ioh, SXFRCTL1, STIMO_256ms | ENSTIMER); 714 bus_space_write_1(iot, ioh, SXFRCTL1, STIMO_256ms | ENSTIMER);
715 715
716 /* Always enable reselections. */ 716 /* Always enable reselections. */
717 bus_space_write_1(iot, ioh, SIMODE0, ENSELDI | ENSELDO); 717 bus_space_write_1(iot, ioh, SIMODE0, ENSELDI | ENSELDO);
718 bus_space_write_1(iot, ioh, SIMODE1, ENSCSIRST | ENSELTIMO); 718 bus_space_write_1(iot, ioh, SIMODE1, ENSCSIRST | ENSELTIMO);
719 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI | ENSELO | ENAUTOATNO); 719 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI | ENSELO | ENAUTOATNO);
720 720
721 sc->sc_state = AIC_SELECTING; 721 sc->sc_state = AIC_SELECTING;
722} 722}
723 723
724static int 724static int
725aic_reselect(struct aic_softc *sc, int message) 725aic_reselect(struct aic_softc *sc, int message)
726{ 726{
727 u_char selid, target, lun; 727 u_char selid, target, lun;
728 struct aic_acb *acb; 728 struct aic_acb *acb;
729 struct scsipi_periph *periph; 729 struct scsipi_periph *periph;
730 struct aic_tinfo *ti; 730 struct aic_tinfo *ti;
731 731
732 /* 732 /*
733 * The SCSI chip made a snapshot of the data bus while the reselection 733 * The SCSI chip made a snapshot of the data bus while the reselection
734 * was being negotiated. This enables us to determine which target did 734 * was being negotiated. This enables us to determine which target did
735 * the reselect. 735 * the reselect.
736 */ 736 */
737 selid = sc->sc_selid & ~(1 << sc->sc_initiator); 737 selid = sc->sc_selid & ~(1 << sc->sc_initiator);
738 if (selid & (selid - 1)) { 738 if (selid & (selid - 1)) {
739 aprint_error_dev(sc->sc_dev, 739 aprint_error_dev(sc->sc_dev,
740 "reselect with invalid selid %02x; " 740 "reselect with invalid selid %02x; "
741 "sending DEVICE RESET\n", selid); 741 "sending DEVICE RESET\n", selid);
742 AIC_BREAK(); 742 AIC_BREAK();
743 goto reset; 743 goto reset;
744 } 744 }
745 745
746 /* Search wait queue for disconnected cmd 746 /* Search wait queue for disconnected cmd
747 * The list should be short, so I haven't bothered with 747 * The list should be short, so I haven't bothered with
748 * any more sophisticated structures than a simple 748 * any more sophisticated structures than a simple
749 * singly linked list. 749 * singly linked list.
750 */ 750 */
751 target = ffs(selid) - 1; 751 target = ffs(selid) - 1;
752 lun = message & 0x07; 752 lun = message & 0x07;
753 for (acb = sc->nexus_list.tqh_first; acb != NULL; 753 for (acb = sc->nexus_list.tqh_first; acb != NULL;
754 acb = acb->chain.tqe_next) { 754 acb = acb->chain.tqe_next) {
755 periph = acb->xs->xs_periph; 755 periph = acb->xs->xs_periph;
756 if (periph->periph_target == target && 756 if (periph->periph_target == target &&
757 periph->periph_lun == lun) 757 periph->periph_lun == lun)
758 break; 758 break;
759 } 759 }
760 if (acb == NULL) { 760 if (acb == NULL) {
761 printf("%s: reselect from target %d lun %d with no nexus; " 761 printf("%s: reselect from target %d lun %d with no nexus; "
762 "sending ABORT\n", device_xname(sc->sc_dev), target, lun); 762 "sending ABORT\n", device_xname(sc->sc_dev), target, lun);
763 AIC_BREAK(); 763 AIC_BREAK();
764 goto abort; 764 goto abort;
765 } 765 }
766 766
767 /* Make this nexus active again. */ 767 /* Make this nexus active again. */
768 TAILQ_REMOVE(&sc->nexus_list, acb, chain); 768 TAILQ_REMOVE(&sc->nexus_list, acb, chain);
769 sc->sc_state = AIC_CONNECTED; 769 sc->sc_state = AIC_CONNECTED;
770 sc->sc_nexus = acb; 770 sc->sc_nexus = acb;
771 ti = &sc->sc_tinfo[target]; 771 ti = &sc->sc_tinfo[target];
772 ti->lubusy |= (1 << lun); 772 ti->lubusy |= (1 << lun);
773 aic_setsync(sc, ti); 773 aic_setsync(sc, ti);
774 774
775 if (acb->flags & ACB_RESET) 775 if (acb->flags & ACB_RESET)
776 aic_sched_msgout(sc, SEND_DEV_RESET); 776 aic_sched_msgout(sc, SEND_DEV_RESET);
777 else if (acb->flags & ACB_ABORT) 777 else if (acb->flags & ACB_ABORT)
778 aic_sched_msgout(sc, SEND_ABORT); 778 aic_sched_msgout(sc, SEND_ABORT);
779 779
780 /* Do an implicit RESTORE POINTERS. */ 780 /* Do an implicit RESTORE POINTERS. */
781 sc->sc_dp = acb->data_addr; 781 sc->sc_dp = acb->data_addr;
782 sc->sc_dleft = acb->data_length; 782 sc->sc_dleft = acb->data_length;
783 sc->sc_cp = (u_char *)&acb->scsipi_cmd; 783 sc->sc_cp = (u_char *)&acb->scsipi_cmd;
784 sc->sc_cleft = acb->scsipi_cmd_length; 784 sc->sc_cleft = acb->scsipi_cmd_length;
785 785
786 return (0); 786 return (0);
787 787
788reset: 788reset:
789 aic_sched_msgout(sc, SEND_DEV_RESET); 789 aic_sched_msgout(sc, SEND_DEV_RESET);
790 return (1); 790 return (1);
791 791
792abort: 792abort:
793 aic_sched_msgout(sc, SEND_ABORT); 793 aic_sched_msgout(sc, SEND_ABORT);
794 return (1); 794 return (1);
795} 795}
796 796
797/* 797/*
798 * Schedule a SCSI operation. This has now been pulled out of the interrupt 798 * Schedule a SCSI operation. This has now been pulled out of the interrupt
799 * handler so that we may call it from aic_scsipi_request and aic_done. This 799 * handler so that we may call it from aic_scsipi_request and aic_done. This
800 * may save us an unnecessary interrupt just to get things going. Should only 800 * may save us an unnecessary interrupt just to get things going. Should only
801 * be called when state == AIC_IDLE and at bio pl. 801 * be called when state == AIC_IDLE and at bio pl.
802 */ 802 */
803static void 803static void
804aic_sched(struct aic_softc *sc) 804aic_sched(struct aic_softc *sc)
805{ 805{
806 struct aic_acb *acb; 806 struct aic_acb *acb;
807 struct scsipi_periph *periph; 807 struct scsipi_periph *periph;
808 struct aic_tinfo *ti; 808 struct aic_tinfo *ti;
809 bus_space_tag_t iot = sc->sc_iot; 809 bus_space_tag_t iot = sc->sc_iot;
810 bus_space_handle_t ioh = sc->sc_ioh; 810 bus_space_handle_t ioh = sc->sc_ioh;
811 811
812 if (!device_is_active(sc->sc_dev)) 812 if (!device_is_active(sc->sc_dev))
813 return; 813 return;
814 814
815 /* 815 /*
816 * Find first acb in ready queue that is for a target/lunit pair that 816 * Find first acb in ready queue that is for a target/lunit pair that
817 * is not busy. 817 * is not busy.
818 */ 818 */
819 bus_space_write_1(iot, ioh, CLRSINT1, 819 bus_space_write_1(iot, ioh, CLRSINT1,
820 CLRSELTIMO | CLRBUSFREE | CLRSCSIPERR); 820 CLRSELTIMO | CLRBUSFREE | CLRSCSIPERR);
821 for (acb = sc->ready_list.tqh_first; acb != NULL; 821 for (acb = sc->ready_list.tqh_first; acb != NULL;
822 acb = acb->chain.tqe_next) { 822 acb = acb->chain.tqe_next) {
823 periph = acb->xs->xs_periph; 823 periph = acb->xs->xs_periph;
824 ti = &sc->sc_tinfo[periph->periph_target]; 824 ti = &sc->sc_tinfo[periph->periph_target];
825 if ((ti->lubusy & (1 << periph->periph_lun)) == 0) { 825 if ((ti->lubusy & (1 << periph->periph_lun)) == 0) {
826 AIC_MISC(("selecting %d:%d ", 826 AIC_MISC(("selecting %d:%d ",
827 periph->periph_target, periph->periph_lun)); 827 periph->periph_target, periph->periph_lun));
828 TAILQ_REMOVE(&sc->ready_list, acb, chain); 828 TAILQ_REMOVE(&sc->ready_list, acb, chain);
829 sc->sc_nexus = acb; 829 sc->sc_nexus = acb;
830 aic_select(sc, acb); 830 aic_select(sc, acb);
831 return; 831 return;
832 } else 832 } else
833 AIC_MISC(("%d:%d busy\n", 833 AIC_MISC(("%d:%d busy\n",
834 periph->periph_target, periph->periph_lun)); 834 periph->periph_target, periph->periph_lun));
835 } 835 }
836 AIC_MISC(("idle ")); 836 AIC_MISC(("idle "));
837 /* Nothing to start; just enable reselections and wait. */ 837 /* Nothing to start; just enable reselections and wait. */
838 bus_space_write_1(iot, ioh, SIMODE0, ENSELDI); 838 bus_space_write_1(iot, ioh, SIMODE0, ENSELDI);
839 bus_space_write_1(iot, ioh, SIMODE1, ENSCSIRST); 839 bus_space_write_1(iot, ioh, SIMODE1, ENSCSIRST);
840 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI); 840 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI);
841} 841}
842 842
843static void 843static void
844aic_sense(struct aic_softc *sc, struct aic_acb *acb) 844aic_sense(struct aic_softc *sc, struct aic_acb *acb)
845{ 845{
846 struct scsipi_xfer *xs = acb->xs; 846 struct scsipi_xfer *xs = acb->xs;
847 struct scsipi_periph *periph = xs->xs_periph; 847 struct scsipi_periph *periph = xs->xs_periph;
848 struct aic_tinfo *ti = &sc->sc_tinfo[periph->periph_target]; 848 struct aic_tinfo *ti = &sc->sc_tinfo[periph->periph_target];
849 struct scsi_request_sense *ss = (void *)&acb->scsipi_cmd; 849 struct scsi_request_sense *ss = (void *)&acb->scsipi_cmd;
850 850
851 AIC_MISC(("requesting sense ")); 851 AIC_MISC(("requesting sense "));
852 /* Next, setup a request sense command block */ 852 /* Next, setup a request sense command block */
853 memset(ss, 0, sizeof(*ss)); 853 memset(ss, 0, sizeof(*ss));
854 ss->opcode = SCSI_REQUEST_SENSE; 854 ss->opcode = SCSI_REQUEST_SENSE;
855 ss->byte2 = periph->periph_lun << 5; 855 ss->byte2 = periph->periph_lun << 5;
856 ss->length = sizeof(struct scsi_sense_data); 856 ss->length = sizeof(struct scsi_sense_data);
857 acb->scsipi_cmd_length = sizeof(*ss); 857 acb->scsipi_cmd_length = sizeof(*ss);
858 acb->data_addr = (char *)&xs->sense.scsi_sense; 858 acb->data_addr = (char *)&xs->sense.scsi_sense;
859 acb->data_length = sizeof(struct scsi_sense_data); 859 acb->data_length = sizeof(struct scsi_sense_data);
860 acb->flags |= ACB_SENSE; 860 acb->flags |= ACB_SENSE;
861 ti->senses++; 861 ti->senses++;
862 if (acb->flags & ACB_NEXUS) 862 if (acb->flags & ACB_NEXUS)
863 ti->lubusy &= ~(1 << periph->periph_lun); 863 ti->lubusy &= ~(1 << periph->periph_lun);
864 if (acb == sc->sc_nexus) { 864 if (acb == sc->sc_nexus) {
865 aic_select(sc, acb); 865 aic_select(sc, acb);
866 } else { 866 } else {
867 aic_dequeue(sc, acb); 867 aic_dequeue(sc, acb);
868 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain); 868 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
869 if (sc->sc_state == AIC_IDLE) 869 if (sc->sc_state == AIC_IDLE)
870 aic_sched(sc); 870 aic_sched(sc);
871 } 871 }
872} 872}
873 873
874/* 874/*
875 * POST PROCESSING OF SCSI_CMD (usually current) 875 * POST PROCESSING OF SCSI_CMD (usually current)
876 */ 876 */
877static void 877static void
878aic_done(struct aic_softc *sc, struct aic_acb *acb) 878aic_done(struct aic_softc *sc, struct aic_acb *acb)
879{ 879{
880 struct scsipi_xfer *xs = acb->xs; 880 struct scsipi_xfer *xs = acb->xs;
881 struct scsipi_periph *periph = xs->xs_periph; 881 struct scsipi_periph *periph = xs->xs_periph;
882 struct aic_tinfo *ti = &sc->sc_tinfo[periph->periph_target]; 882 struct aic_tinfo *ti = &sc->sc_tinfo[periph->periph_target];
883 883
884 AIC_TRACE(("aic_done ")); 884 AIC_TRACE(("aic_done "));
885 885
886 /* 886 /*
887 * Now, if we've come here with no error code, i.e. we've kept the 887 * Now, if we've come here with no error code, i.e. we've kept the
888 * initial XS_NOERROR, and the status code signals that we should 888 * initial XS_NOERROR, and the status code signals that we should
889 * check sense, we'll need to set up a request sense cmd block and 889 * check sense, we'll need to set up a request sense cmd block and
890 * push the command back into the ready queue *before* any other 890 * push the command back into the ready queue *before* any other
891 * commands for this target/lunit, else we lose the sense info. 891 * commands for this target/lunit, else we lose the sense info.
892 * We don't support chk sense conditions for the request sense cmd. 892 * We don't support chk sense conditions for the request sense cmd.
893 */ 893 */
894 if (xs->error == XS_NOERROR) { 894 if (xs->error == XS_NOERROR) {
895 if (acb->flags & ACB_ABORT) { 895 if (acb->flags & ACB_ABORT) {
896 xs->error = XS_DRIVER_STUFFUP; 896 xs->error = XS_DRIVER_STUFFUP;
897 } else if (acb->flags & ACB_SENSE) { 897 } else if (acb->flags & ACB_SENSE) {
898 xs->error = XS_SENSE; 898 xs->error = XS_SENSE;
899 } else if (acb->target_stat == SCSI_CHECK) { 899 } else if (acb->target_stat == SCSI_CHECK) {
900 /* First, save the return values */ 900 /* First, save the return values */
901 xs->resid = acb->data_length; 901 xs->resid = acb->data_length;
902 xs->status = acb->target_stat; 902 xs->status = acb->target_stat;
903 aic_sense(sc, acb); 903 aic_sense(sc, acb);
904 return; 904 return;
905 } else { 905 } else {
906 xs->resid = acb->data_length; 906 xs->resid = acb->data_length;
907 } 907 }
908 } 908 }
909 909
910#if AIC_DEBUG 910#if AIC_DEBUG
911 if ((aic_debug & AIC_SHOWMISC) != 0) { 911 if ((aic_debug & AIC_SHOWMISC) != 0) {
912 if (xs->resid != 0) 912 if (xs->resid != 0)
913 printf("resid=%d ", xs->resid); 913 printf("resid=%d ", xs->resid);
914 if (xs->error == XS_SENSE) 914 if (xs->error == XS_SENSE)
915 printf("sense=0x%02x\n", xs->sense.scsi_sense.response_code); 915 printf("sense=0x%02x\n", xs->sense.scsi_sense.response_code);
916 else 916 else
917 printf("error=%d\n", xs->error); 917 printf("error=%d\n", xs->error);
918 } 918 }
919#endif 919#endif
920 920
921 /* 921 /*
922 * Remove the ACB from whatever queue it happens to be on. 922 * Remove the ACB from whatever queue it happens to be on.
923 */ 923 */
924 if (acb->flags & ACB_NEXUS) 924 if (acb->flags & ACB_NEXUS)
925 ti->lubusy &= ~(1 << periph->periph_lun); 925 ti->lubusy &= ~(1 << periph->periph_lun);
926 if (acb == sc->sc_nexus) { 926 if (acb == sc->sc_nexus) {
927 sc->sc_nexus = NULL; 927 sc->sc_nexus = NULL;
928 sc->sc_state = AIC_IDLE; 928 sc->sc_state = AIC_IDLE;
929 aic_sched(sc); 929 aic_sched(sc);
930 } else 930 } else
931 aic_dequeue(sc, acb); 931 aic_dequeue(sc, acb);
932 932
933 aic_free_acb(sc, acb); 933 aic_free_acb(sc, acb);
934 ti->cmds++; 934 ti->cmds++;
935 scsipi_done(xs); 935 scsipi_done(xs);
936} 936}
937 937
938static void 938static void
939aic_dequeue(struct aic_softc *sc, struct aic_acb *acb) 939aic_dequeue(struct aic_softc *sc, struct aic_acb *acb)
940{ 940{
941 941
942 if (acb->flags & ACB_NEXUS) { 942 if (acb->flags & ACB_NEXUS) {
943 TAILQ_REMOVE(&sc->nexus_list, acb, chain); 943 TAILQ_REMOVE(&sc->nexus_list, acb, chain);
944 } else { 944 } else {
945 TAILQ_REMOVE(&sc->ready_list, acb, chain); 945 TAILQ_REMOVE(&sc->ready_list, acb, chain);
946 } 946 }
947} 947}
948 948
949/* 949/*
950 * INTERRUPT/PROTOCOL ENGINE 950 * INTERRUPT/PROTOCOL ENGINE
951 */ 951 */
952 952
953/* 953/*
954 * Precondition: 954 * Precondition:
955 * The SCSI bus is already in the MSGI phase and there is a message byte 955 * The SCSI bus is already in the MSGI phase and there is a message byte
956 * on the bus, along with an asserted REQ signal. 956 * on the bus, along with an asserted REQ signal.
957 */ 957 */
958static void 958static void
959aic_msgin(struct aic_softc *sc) 959aic_msgin(struct aic_softc *sc)
960{ 960{
961 bus_space_tag_t iot = sc->sc_iot; 961 bus_space_tag_t iot = sc->sc_iot;
962 bus_space_handle_t ioh = sc->sc_ioh; 962 bus_space_handle_t ioh = sc->sc_ioh;
963 u_char sstat1; 963 u_char sstat1;
964 int n; 964 int n;
965 965
966 AIC_TRACE(("aic_msgin ")); 966 AIC_TRACE(("aic_msgin "));
967 967
968 if (sc->sc_prevphase == PH_MSGIN) { 968 if (sc->sc_prevphase == PH_MSGIN) {
969 /* This is a continuation of the previous message. */ 969 /* This is a continuation of the previous message. */
970 n = sc->sc_imp - sc->sc_imess; 970 n = sc->sc_imp - sc->sc_imess;
971 goto nextbyte; 971 goto nextbyte;
972 } 972 }
973 973
974 /* This is a new MESSAGE IN phase. Clean up our state. */ 974 /* This is a new MESSAGE IN phase. Clean up our state. */
975 sc->sc_flags &= ~AIC_DROP_MSGIN; 975 sc->sc_flags &= ~AIC_DROP_MSGIN;
976 976
977nextmsg: 977nextmsg:
978 n = 0; 978 n = 0;
979 sc->sc_imp = &sc->sc_imess[n]; 979 sc->sc_imp = &sc->sc_imess[n];
980 980
981nextbyte: 981nextbyte:
982 /* 982 /*
983 * Read a whole message, but don't ack the last byte. If we reject the 983 * Read a whole message, but don't ack the last byte. If we reject the
984 * message, we have to assert ATN during the message transfer phase 984 * message, we have to assert ATN during the message transfer phase
985 * itself. 985 * itself.
986 */ 986 */
987 for (;;) { 987 for (;;) {
988 for (;;) { 988 for (;;) {
989 sstat1 = bus_space_read_1(iot, ioh, SSTAT1); 989 sstat1 = bus_space_read_1(iot, ioh, SSTAT1);
990 if ((sstat1 & (REQINIT | PHASECHG | BUSFREE)) != 0) 990 if ((sstat1 & (REQINIT | PHASECHG | BUSFREE)) != 0)
991 break; 991 break;
992 /* Wait for REQINIT. XXX Need timeout. */ 992 /* Wait for REQINIT. XXX Need timeout. */
993 } 993 }
994 if ((sstat1 & (PHASECHG | BUSFREE)) != 0) { 994 if ((sstat1 & (PHASECHG | BUSFREE)) != 0) {
995 /* 995 /*
996 * Target left MESSAGE IN, probably because it 996 * Target left MESSAGE IN, probably because it
997 * a) noticed our ATN signal, or 997 * a) noticed our ATN signal, or
998 * b) ran out of messages. 998 * b) ran out of messages.
999 */ 999 */
1000 goto out; 1000 goto out;
1001 } 1001 }
1002 1002
1003 /* If parity error, just dump everything on the floor. */ 1003 /* If parity error, just dump everything on the floor. */
1004 if ((sstat1 & SCSIPERR) != 0) { 1004 if ((sstat1 & SCSIPERR) != 0) {
1005 sc->sc_flags |= AIC_DROP_MSGIN; 1005 sc->sc_flags |= AIC_DROP_MSGIN;
1006 aic_sched_msgout(sc, SEND_PARITY_ERROR); 1006 aic_sched_msgout(sc, SEND_PARITY_ERROR);
1007 } 1007 }
1008 1008
1009 /* Gather incoming message bytes if needed. */ 1009 /* Gather incoming message bytes if needed. */
1010 if ((sc->sc_flags & AIC_DROP_MSGIN) == 0) { 1010 if ((sc->sc_flags & AIC_DROP_MSGIN) == 0) {
1011 if (n >= AIC_MAX_MSG_LEN) { 1011 if (n >= AIC_MAX_MSG_LEN) {
1012 (void) bus_space_read_1(iot, ioh, SCSIDAT); 1012 (void) bus_space_read_1(iot, ioh, SCSIDAT);
1013 sc->sc_flags |= AIC_DROP_MSGIN; 1013 sc->sc_flags |= AIC_DROP_MSGIN;
1014 aic_sched_msgout(sc, SEND_REJECT); 1014 aic_sched_msgout(sc, SEND_REJECT);
1015 } else { 1015 } else {
1016 *sc->sc_imp++ = bus_space_read_1(iot, ioh, 1016 *sc->sc_imp++ = bus_space_read_1(iot, ioh,
1017 SCSIDAT); 1017 SCSIDAT);
1018 n++; 1018 n++;
1019 /* 1019 /*
1020 * This testing is suboptimal, but most 1020 * This testing is suboptimal, but most
1021 * messages will be of the one byte variety, so 1021 * messages will be of the one byte variety, so
1022 * it should not affect performance 1022 * it should not affect performance
1023 * significantly. 1023 * significantly.
1024 */ 1024 */
1025 if (n == 1 && MSG_IS1BYTE(sc->sc_imess[0])) 1025 if (n == 1 && MSG_IS1BYTE(sc->sc_imess[0]))
1026 break; 1026 break;
1027 if (n == 2 && MSG_IS2BYTE(sc->sc_imess[0])) 1027 if (n == 2 && MSG_IS2BYTE(sc->sc_imess[0]))
1028 break; 1028 break;
1029 if (n >= 3 && MSG_ISEXTENDED(sc->sc_imess[0]) && 1029 if (n >= 3 && MSG_ISEXTENDED(sc->sc_imess[0]) &&
1030 n == sc->sc_imess[1] + 2) 1030 n == sc->sc_imess[1] + 2)
1031 break; 1031 break;
1032 } 1032 }
1033 } else 1033 } else
1034 (void) bus_space_read_1(iot, ioh, SCSIDAT); 1034 (void) bus_space_read_1(iot, ioh, SCSIDAT);
1035 1035
1036 /* 1036 /*
1037 * If we reach this spot we're either: 1037 * If we reach this spot we're either:
1038 * a) in the middle of a multi-byte message, or 1038 * a) in the middle of a multi-byte message, or
1039 * b) dropping bytes. 1039 * b) dropping bytes.
1040 */ 1040 */
1041 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN); 1041 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN);
1042 /* Ack the last byte read. */ 1042 /* Ack the last byte read. */
1043 (void) bus_space_read_1(iot, ioh, SCSIDAT); 1043 (void) bus_space_read_1(iot, ioh, SCSIDAT);
1044 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 1044 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
1045 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0) 1045 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0)
1046 ; 1046 ;
1047 } 1047 }
1048 1048
1049 AIC_MISC(("n=%d imess=0x%02x ", n, sc->sc_imess[0])); 1049 AIC_MISC(("n=%d imess=0x%02x ", n, sc->sc_imess[0]));
1050 1050
1051 /* We now have a complete message. Parse it. */ 1051 /* We now have a complete message. Parse it. */
1052 switch (sc->sc_state) { 1052 switch (sc->sc_state) {
1053 struct aic_acb *acb; 1053 struct aic_acb *acb;
1054 struct aic_tinfo *ti; 1054 struct aic_tinfo *ti;
1055 1055
1056 case AIC_CONNECTED: 1056 case AIC_CONNECTED:
1057 AIC_ASSERT(sc->sc_nexus != NULL); 1057 AIC_ASSERT(sc->sc_nexus != NULL);
1058 acb = sc->sc_nexus; 1058 acb = sc->sc_nexus;
1059 ti = &sc->sc_tinfo[acb->xs->xs_periph->periph_target]; 1059 ti = &sc->sc_tinfo[acb->xs->xs_periph->periph_target];
1060 1060
1061 switch (sc->sc_imess[0]) { 1061 switch (sc->sc_imess[0]) {
1062 case MSG_CMDCOMPLETE: 1062 case MSG_CMDCOMPLETE:
1063#if 0 1063#if 0
1064 /* impossible dleft is unsigned */ 1064 /* impossible dleft is unsigned */
1065 if (sc->sc_dleft < 0) { 1065 if (sc->sc_dleft < 0) {
1066 periph = acb->xs->xs_periph; 1066 periph = acb->xs->xs_periph;
1067 printf("%s: %ld extra bytes from %d:%d\n", 1067 printf("%s: %ld extra bytes from %d:%d\n",
1068 device_xname(sc->sc_dev), 1068 device_xname(sc->sc_dev),
1069 (long)-sc->sc_dleft, 1069 (long)-sc->sc_dleft,
1070 periph->periph_target, periph->periph_lun); 1070 periph->periph_target, periph->periph_lun);
1071 sc->sc_dleft = 0; 1071 sc->sc_dleft = 0;
1072 } 1072 }
1073#endif 1073#endif
1074 acb->xs->resid = acb->data_length = sc->sc_dleft; 1074 acb->xs->resid = acb->data_length = sc->sc_dleft;
1075 sc->sc_state = AIC_CMDCOMPLETE; 1075 sc->sc_state = AIC_CMDCOMPLETE;
1076 break; 1076 break;
1077 1077
1078 case MSG_PARITY_ERROR: 1078 case MSG_PARITY_ERROR:
1079 /* Resend the last message. */ 1079 /* Resend the last message. */
1080 aic_sched_msgout(sc, sc->sc_lastmsg); 1080 aic_sched_msgout(sc, sc->sc_lastmsg);
1081 break; 1081 break;
1082 1082
1083 case MSG_MESSAGE_REJECT: 1083 case MSG_MESSAGE_REJECT:
1084 AIC_MISC(("message rejected %02x ", sc->sc_lastmsg)); 1084 AIC_MISC(("message rejected %02x ", sc->sc_lastmsg));
1085 switch (sc->sc_lastmsg) { 1085 switch (sc->sc_lastmsg) {
1086#if AIC_USE_SYNCHRONOUS + AIC_USE_WIDE 1086#if AIC_USE_SYNCHRONOUS + AIC_USE_WIDE
1087 case SEND_IDENTIFY: 1087 case SEND_IDENTIFY:
1088 ti->flags &= ~(DO_SYNC | DO_WIDE); 1088 ti->flags &= ~(DO_SYNC | DO_WIDE);
1089 ti->period = ti->offset = 0; 1089 ti->period = ti->offset = 0;
1090 aic_setsync(sc, ti); 1090 aic_setsync(sc, ti);
1091 ti->width = 0; 1091 ti->width = 0;
1092 break; 1092 break;
1093#endif 1093#endif
1094#if AIC_USE_SYNCHRONOUS 1094#if AIC_USE_SYNCHRONOUS
1095 case SEND_SDTR: 1095 case SEND_SDTR:
1096 ti->flags &= ~DO_SYNC; 1096 ti->flags &= ~DO_SYNC;
1097 ti->period = ti->offset = 0; 1097 ti->period = ti->offset = 0;
1098 aic_setsync(sc, ti); 1098 aic_setsync(sc, ti);
1099 aic_update_xfer_mode(sc, 1099 aic_update_xfer_mode(sc,
1100 acb->xs->xs_periph->periph_target); 1100 acb->xs->xs_periph->periph_target);
1101 break; 1101 break;
1102#endif 1102#endif
1103#if AIC_USE_WIDE 1103#if AIC_USE_WIDE
1104 case SEND_WDTR: 1104 case SEND_WDTR:
1105 ti->flags &= ~DO_WIDE; 1105 ti->flags &= ~DO_WIDE;
1106 ti->width = 0; 1106 ti->width = 0;
1107 aic_update_xfer_mode(sc, 1107 aic_update_xfer_mode(sc,
1108 acb->xs->xs_periph->periph_target); 1108 acb->xs->xs_periph->periph_target);
1109 break; 1109 break;
1110#endif 1110#endif
1111 case SEND_INIT_DET_ERR: 1111 case SEND_INIT_DET_ERR:
1112 aic_sched_msgout(sc, SEND_ABORT); 1112 aic_sched_msgout(sc, SEND_ABORT);
1113 break; 1113 break;
1114 } 1114 }
1115 break; 1115 break;
1116 1116
1117 case MSG_NOOP: 1117 case MSG_NOOP:
1118 break; 1118 break;
1119 1119
1120 case MSG_DISCONNECT: 1120 case MSG_DISCONNECT:
1121 ti->dconns++; 1121 ti->dconns++;
1122 sc->sc_state = AIC_DISCONNECT; 1122 sc->sc_state = AIC_DISCONNECT;
1123 break; 1123 break;
1124 1124
1125 case MSG_SAVEDATAPOINTER: 1125 case MSG_SAVEDATAPOINTER:
1126 acb->data_addr = sc->sc_dp; 1126 acb->data_addr = sc->sc_dp;
1127 acb->data_length = sc->sc_dleft; 1127 acb->data_length = sc->sc_dleft;
1128 break; 1128 break;
1129 1129
1130 case MSG_RESTOREPOINTERS: 1130 case MSG_RESTOREPOINTERS:
1131 sc->sc_dp = acb->data_addr; 1131 sc->sc_dp = acb->data_addr;
1132 sc->sc_dleft = acb->data_length; 1132 sc->sc_dleft = acb->data_length;
1133 sc->sc_cp = (u_char *)&acb->scsipi_cmd; 1133 sc->sc_cp = (u_char *)&acb->scsipi_cmd;
1134 sc->sc_cleft = acb->scsipi_cmd_length; 1134 sc->sc_cleft = acb->scsipi_cmd_length;
1135 break; 1135 break;
1136 1136
1137 case MSG_EXTENDED: 1137 case MSG_EXTENDED:
1138 switch (sc->sc_imess[2]) { 1138 switch (sc->sc_imess[2]) {
1139#if AIC_USE_SYNCHRONOUS 1139#if AIC_USE_SYNCHRONOUS
1140 case MSG_EXT_SDTR: 1140 case MSG_EXT_SDTR:
1141 if (sc->sc_imess[1] != 3) 1141 if (sc->sc_imess[1] != 3)
1142 goto reject; 1142 goto reject;
1143 ti->period = sc->sc_imess[3]; 1143 ti->period = sc->sc_imess[3];
1144 ti->offset = sc->sc_imess[4]; 1144 ti->offset = sc->sc_imess[4];
1145 ti->flags &= ~DO_SYNC; 1145 ti->flags &= ~DO_SYNC;
1146 if (ti->offset == 0) { 1146 if (ti->offset == 0) {
1147 } else if (ti->period < sc->sc_minsync || 1147 } else if (ti->period < sc->sc_minsync ||
1148 ti->period > sc->sc_maxsync || 1148 ti->period > sc->sc_maxsync ||
1149 ti->offset > 8) { 1149 ti->offset > 8) {
1150 ti->period = ti->offset = 0; 1150 ti->period = ti->offset = 0;
1151 aic_sched_msgout(sc, SEND_SDTR); 1151 aic_sched_msgout(sc, SEND_SDTR);
1152 } else { 1152 } else {
1153 aic_update_xfer_mode(sc, 1153 aic_update_xfer_mode(sc,
1154 acb->xs->xs_periph->periph_target); 1154 acb->xs->xs_periph->periph_target);
1155 } 1155 }
1156 aic_setsync(sc, ti); 1156 aic_setsync(sc, ti);
1157 break; 1157 break;
1158#endif 1158#endif
1159 1159
1160#if AIC_USE_WIDE 1160#if AIC_USE_WIDE
1161 case MSG_EXT_WDTR: 1161 case MSG_EXT_WDTR:
1162 if (sc->sc_imess[1] != 2) 1162 if (sc->sc_imess[1] != 2)
1163 goto reject; 1163 goto reject;
1164 ti->width = sc->sc_imess[3]; 1164 ti->width = sc->sc_imess[3];
1165 ti->flags &= ~DO_WIDE; 1165 ti->flags &= ~DO_WIDE;
1166 if (ti->width == 0) { 1166 if (ti->width == 0) {
1167 } else if (ti->width > AIC_MAX_WIDTH) { 1167 } else if (ti->width > AIC_MAX_WIDTH) {
1168 ti->width = 0; 1168 ti->width = 0;
1169 aic_sched_msgout(sc, SEND_WDTR); 1169 aic_sched_msgout(sc, SEND_WDTR);
1170 } else { 1170 } else {
1171 aic_update_xfer_mode(sc, 1171 aic_update_xfer_mode(sc,
1172 acb->xs->xs_periph->periph_target); 1172 acb->xs->xs_periph->periph_target);
1173 } 1173 }
1174 break; 1174 break;
1175#endif 1175#endif
1176 1176
1177 default: 1177 default:
1178 printf("%s: unrecognized MESSAGE EXTENDED; " 1178 printf("%s: unrecognized MESSAGE EXTENDED; "
1179 "sending REJECT\n", 1179 "sending REJECT\n",
1180 device_xname(sc->sc_dev)); 1180 device_xname(sc->sc_dev));
1181 AIC_BREAK(); 1181 AIC_BREAK();
1182 goto reject; 1182 goto reject;
1183 } 1183 }
1184 break; 1184 break;
1185 1185
1186 default: 1186 default:
1187 printf("%s: unrecognized MESSAGE; sending REJECT\n", 1187 printf("%s: unrecognized MESSAGE; sending REJECT\n",
1188 device_xname(sc->sc_dev)); 1188 device_xname(sc->sc_dev));
1189 AIC_BREAK(); 1189 AIC_BREAK();
1190 reject: 1190 reject:
1191 aic_sched_msgout(sc, SEND_REJECT); 1191 aic_sched_msgout(sc, SEND_REJECT);
1192 break; 1192 break;
1193 } 1193 }
1194 break; 1194 break;
1195 1195
1196 case AIC_RESELECTED: 1196 case AIC_RESELECTED:
1197 if (!MSG_ISIDENTIFY(sc->sc_imess[0])) { 1197 if (!MSG_ISIDENTIFY(sc->sc_imess[0])) {
1198 printf("%s: reselect without IDENTIFY; " 1198 printf("%s: reselect without IDENTIFY; "
1199 "sending DEVICE RESET\n", device_xname(sc->sc_dev)); 1199 "sending DEVICE RESET\n", device_xname(sc->sc_dev));
1200 AIC_BREAK(); 1200 AIC_BREAK();
1201 goto reset; 1201 goto reset;
1202 } 1202 }
1203 1203
1204 (void) aic_reselect(sc, sc->sc_imess[0]); 1204 (void) aic_reselect(sc, sc->sc_imess[0]);
1205 break; 1205 break;
1206 1206
1207 default: 1207 default:
1208 aprint_error_dev(sc->sc_dev, 1208 aprint_error_dev(sc->sc_dev,
1209 "unexpected MESSAGE IN; sending DEVICE RESET\n"); 1209 "unexpected MESSAGE IN; sending DEVICE RESET\n");
1210 AIC_BREAK(); 1210 AIC_BREAK();
1211 reset: 1211 reset:
1212 aic_sched_msgout(sc, SEND_DEV_RESET); 1212 aic_sched_msgout(sc, SEND_DEV_RESET);
1213 break; 1213 break;
1214 1214
1215#ifdef notdef 1215#ifdef notdef
1216 abort: 1216 abort:
1217 aic_sched_msgout(sc, SEND_ABORT); 1217 aic_sched_msgout(sc, SEND_ABORT);
1218 break; 1218 break;
1219#endif 1219#endif
1220 } 1220 }
1221 1221
1222 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN); 1222 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN);
1223 /* Ack the last message byte. */ 1223 /* Ack the last message byte. */
1224 (void) bus_space_read_1(iot, ioh, SCSIDAT); 1224 (void) bus_space_read_1(iot, ioh, SCSIDAT);
1225 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 1225 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
1226 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0) 1226 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0)
1227 ; 1227 ;
1228 1228
1229 /* Go get the next message, if any. */ 1229 /* Go get the next message, if any. */
1230 goto nextmsg; 1230 goto nextmsg;
1231 1231
1232out: 1232out:
1233 AIC_MISC(("n=%d imess=0x%02x ", n, sc->sc_imess[0])); 1233 AIC_MISC(("n=%d imess=0x%02x ", n, sc->sc_imess[0]));
1234} 1234}
1235 1235
1236/* 1236/*
1237 * Send the highest priority, scheduled message. 1237 * Send the highest priority, scheduled message.
1238 */ 1238 */
1239static void 1239static void
1240aic_msgout(struct aic_softc *sc) 1240aic_msgout(struct aic_softc *sc)
1241{ 1241{
1242 bus_space_tag_t iot = sc->sc_iot; 1242 bus_space_tag_t iot = sc->sc_iot;
1243 bus_space_handle_t ioh = sc->sc_ioh; 1243 bus_space_handle_t ioh = sc->sc_ioh;
1244#if AIC_USE_SYNCHRONOUS 1244#if AIC_USE_SYNCHRONOUS
1245 struct aic_tinfo *ti; 1245 struct aic_tinfo *ti;
1246#endif 1246#endif
1247 u_char sstat1; 1247 u_char sstat1;
1248 int n; 1248 int n;
1249 1249
1250 AIC_TRACE(("aic_msgout ")); 1250 AIC_TRACE(("aic_msgout "));
1251 1251
1252 /* Reset the FIFO. */ 1252 /* Reset the FIFO. */
1253 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO); 1253 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO);
1254 /* Enable REQ/ACK protocol. */ 1254 /* Enable REQ/ACK protocol. */
1255 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN); 1255 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN);
1256 1256
1257 if (sc->sc_prevphase == PH_MSGOUT) { 1257 if (sc->sc_prevphase == PH_MSGOUT) {
1258 if (sc->sc_omp == sc->sc_omess) { 1258 if (sc->sc_omp == sc->sc_omess) {
1259 /* 1259 /*
1260 * This is a retransmission. 1260 * This is a retransmission.
1261 * 1261 *
1262 * We get here if the target stayed in MESSAGE OUT 1262 * We get here if the target stayed in MESSAGE OUT
1263 * phase. Section 5.1.9.2 of the SCSI 2 spec indicates 1263 * phase. Section 5.1.9.2 of the SCSI 2 spec indicates
1264 * that all of the previously transmitted messages must 1264 * that all of the previously transmitted messages must
1265 * be sent again, in the same order. Therefore, we 1265 * be sent again, in the same order. Therefore, we
1266 * requeue all the previously transmitted messages, and 1266 * requeue all the previously transmitted messages, and
1267 * start again from the top. Our simple priority 1267 * start again from the top. Our simple priority
1268 * scheme keeps the messages in the right order. 1268 * scheme keeps the messages in the right order.
1269 */ 1269 */
1270 AIC_MISC(("retransmitting ")); 1270 AIC_MISC(("retransmitting "));
1271 sc->sc_msgpriq |= sc->sc_msgoutq; 1271 sc->sc_msgpriq |= sc->sc_msgoutq;
1272 /* 1272 /*
1273 * Set ATN. If we're just sending a trivial 1-byte 1273 * Set ATN. If we're just sending a trivial 1-byte
1274 * message, we'll clear ATN later on anyway. 1274 * message, we'll clear ATN later on anyway.
1275 */ 1275 */
1276 bus_space_write_1(iot, ioh, SCSISIG, PH_MSGOUT | ATNO); 1276 bus_space_write_1(iot, ioh, SCSISIG, PH_MSGOUT | ATNO);
1277 } else { 1277 } else {
1278 /* This is a continuation of the previous message. */ 1278 /* This is a continuation of the previous message. */
1279 n = sc->sc_omp - sc->sc_omess; 1279 n = sc->sc_omp - sc->sc_omess;
1280 goto nextbyte; 1280 goto nextbyte;
1281 } 1281 }
1282 } 1282 }
1283 1283
1284 /* No messages transmitted so far. */ 1284 /* No messages transmitted so far. */
1285 sc->sc_msgoutq = 0; 1285 sc->sc_msgoutq = 0;
1286 sc->sc_lastmsg = 0; 1286 sc->sc_lastmsg = 0;
1287 1287
1288nextmsg: 1288nextmsg:
1289 /* Pick up highest priority message. */ 1289 /* Pick up highest priority message. */
1290 sc->sc_currmsg = sc->sc_msgpriq & -sc->sc_msgpriq; 1290 sc->sc_currmsg = sc->sc_msgpriq & -sc->sc_msgpriq;
1291 sc->sc_msgpriq &= ~sc->sc_currmsg; 1291 sc->sc_msgpriq &= ~sc->sc_currmsg;
1292 sc->sc_msgoutq |= sc->sc_currmsg; 1292 sc->sc_msgoutq |= sc->sc_currmsg;
1293 1293
1294 /* Build the outgoing message data. */ 1294 /* Build the outgoing message data. */
1295 switch (sc->sc_currmsg) { 1295 switch (sc->sc_currmsg) {
1296 case SEND_IDENTIFY: 1296 case SEND_IDENTIFY:
1297 AIC_ASSERT(sc->sc_nexus != NULL); 1297 AIC_ASSERT(sc->sc_nexus != NULL);
1298 sc->sc_omess[0] = 1298 sc->sc_omess[0] =
1299 MSG_IDENTIFY(sc->sc_nexus->xs->xs_periph->periph_lun, 1); 1299 MSG_IDENTIFY(sc->sc_nexus->xs->xs_periph->periph_lun, 1);
1300 n = 1; 1300 n = 1;
1301 break; 1301 break;
1302 1302
1303#if AIC_USE_SYNCHRONOUS 1303#if AIC_USE_SYNCHRONOUS
1304 case SEND_SDTR: 1304 case SEND_SDTR:
1305 AIC_ASSERT(sc->sc_nexus != NULL); 1305 AIC_ASSERT(sc->sc_nexus != NULL);
1306 ti = &sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target]; 1306 ti = &sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target];
1307 sc->sc_omess[4] = MSG_EXTENDED; 1307 sc->sc_omess[4] = MSG_EXTENDED;
1308 sc->sc_omess[3] = 3; 1308 sc->sc_omess[3] = 3;
1309 sc->sc_omess[2] = MSG_EXT_SDTR; 1309 sc->sc_omess[2] = MSG_EXT_SDTR;
1310 sc->sc_omess[1] = ti->period >> 2; 1310 sc->sc_omess[1] = ti->period >> 2;
1311 sc->sc_omess[0] = ti->offset; 1311 sc->sc_omess[0] = ti->offset;
1312 n = 5; 1312 n = 5;
1313 break; 1313 break;
1314#endif 1314#endif
1315 1315
1316#if AIC_USE_WIDE 1316#if AIC_USE_WIDE
1317 case SEND_WDTR: 1317 case SEND_WDTR:
1318 AIC_ASSERT(sc->sc_nexus != NULL); 1318 AIC_ASSERT(sc->sc_nexus != NULL);
1319 ti = &sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target]; 1319 ti = &sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target];
1320 sc->sc_omess[3] = MSG_EXTENDED; 1320 sc->sc_omess[3] = MSG_EXTENDED;
1321 sc->sc_omess[2] = 2; 1321 sc->sc_omess[2] = 2;
1322 sc->sc_omess[1] = MSG_EXT_WDTR; 1322 sc->sc_omess[1] = MSG_EXT_WDTR;
1323 sc->sc_omess[0] = ti->width; 1323 sc->sc_omess[0] = ti->width;
1324 n = 4; 1324 n = 4;
1325 break; 1325 break;
1326#endif 1326#endif
1327 1327
1328 case SEND_DEV_RESET: 1328 case SEND_DEV_RESET:
1329 sc->sc_flags |= AIC_ABORTING; 1329 sc->sc_flags |= AIC_ABORTING;
1330 sc->sc_omess[0] = MSG_BUS_DEV_RESET; 1330 sc->sc_omess[0] = MSG_BUS_DEV_RESET;
1331 n = 1; 1331 n = 1;
1332 break; 1332 break;
1333 1333
1334 case SEND_REJECT: 1334 case SEND_REJECT:
1335 sc->sc_omess[0] = MSG_MESSAGE_REJECT; 1335 sc->sc_omess[0] = MSG_MESSAGE_REJECT;
1336 n = 1; 1336 n = 1;
1337 break; 1337 break;
1338 1338
1339 case SEND_PARITY_ERROR: 1339 case SEND_PARITY_ERROR:
1340 sc->sc_omess[0] = MSG_PARITY_ERROR; 1340 sc->sc_omess[0] = MSG_PARITY_ERROR;
1341 n = 1; 1341 n = 1;
1342 break; 1342 break;
1343 1343
1344 case SEND_INIT_DET_ERR: 1344 case SEND_INIT_DET_ERR:
1345 sc->sc_omess[0] = MSG_INITIATOR_DET_ERR; 1345 sc->sc_omess[0] = MSG_INITIATOR_DET_ERR;
1346 n = 1; 1346 n = 1;
1347 break; 1347 break;
1348 1348
1349 case SEND_ABORT: 1349 case SEND_ABORT:
1350 sc->sc_flags |= AIC_ABORTING; 1350 sc->sc_flags |= AIC_ABORTING;
1351 sc->sc_omess[0] = MSG_ABORT; 1351 sc->sc_omess[0] = MSG_ABORT;
1352 n = 1; 1352 n = 1;
1353 break; 1353 break;
1354 1354
1355 default: 1355 default:
1356 aprint_error_dev(sc->sc_dev, 1356 aprint_error_dev(sc->sc_dev,
1357 "unexpected MESSAGE OUT; sending NOOP\n"); 1357 "unexpected MESSAGE OUT; sending NOOP\n");
1358 AIC_BREAK(); 1358 AIC_BREAK();
1359 sc->sc_omess[0] = MSG_NOOP; 1359 sc->sc_omess[0] = MSG_NOOP;
1360 n = 1; 1360 n = 1;
1361 break; 1361 break;
1362 } 1362 }
1363 sc->sc_omp = &sc->sc_omess[n]; 1363 sc->sc_omp = &sc->sc_omess[n];
1364 1364
1365nextbyte: 1365nextbyte:
1366 /* Send message bytes. */ 1366 /* Send message bytes. */
1367 for (;;) { 1367 for (;;) {
1368 for (;;) { 1368 for (;;) {
1369 sstat1 = bus_space_read_1(iot, ioh, SSTAT1); 1369 sstat1 = bus_space_read_1(iot, ioh, SSTAT1);
1370 if ((sstat1 & (REQINIT | PHASECHG | BUSFREE)) != 0) 1370 if ((sstat1 & (REQINIT | PHASECHG | BUSFREE)) != 0)
1371 break; 1371 break;
1372 /* Wait for REQINIT. XXX Need timeout. */ 1372 /* Wait for REQINIT. XXX Need timeout. */
1373 } 1373 }
1374 if ((sstat1 & (PHASECHG | BUSFREE)) != 0) { 1374 if ((sstat1 & (PHASECHG | BUSFREE)) != 0) {
1375 /* 1375 /*
1376 * Target left MESSAGE OUT, possibly to reject 1376 * Target left MESSAGE OUT, possibly to reject
1377 * our message. 1377 * our message.
1378 * 1378 *
1379 * If this is the last message being sent, then we 1379 * If this is the last message being sent, then we
1380 * deassert ATN, since either the target is going to 1380 * deassert ATN, since either the target is going to
1381 * ignore this message, or it's going to ask for a 1381 * ignore this message, or it's going to ask for a
1382 * retransmission via MESSAGE PARITY ERROR (in which 1382 * retransmission via MESSAGE PARITY ERROR (in which
1383 * case we reassert ATN anyway). 1383 * case we reassert ATN anyway).
1384 */ 1384 */
1385 if (sc->sc_msgpriq == 0) 1385 if (sc->sc_msgpriq == 0)
1386 bus_space_write_1(iot, ioh, CLRSINT1, CLRATNO); 1386 bus_space_write_1(iot, ioh, CLRSINT1, CLRATNO);
1387 goto out; 1387 goto out;
1388 } 1388 }
1389 1389
1390 /* Clear ATN before last byte if this is the last message. */ 1390 /* Clear ATN before last byte if this is the last message. */
1391 if (n == 1 && sc->sc_msgpriq == 0) 1391 if (n == 1 && sc->sc_msgpriq == 0)
1392 bus_space_write_1(iot, ioh, CLRSINT1, CLRATNO); 1392 bus_space_write_1(iot, ioh, CLRSINT1, CLRATNO);
1393 /* Send message byte. */ 1393 /* Send message byte. */
1394 bus_space_write_1(iot, ioh, SCSIDAT, *--sc->sc_omp); 1394 bus_space_write_1(iot, ioh, SCSIDAT, *--sc->sc_omp);
1395 --n; 1395 --n;
1396 /* Keep track of the last message we've sent any bytes of. */ 1396 /* Keep track of the last message we've sent any bytes of. */
1397 sc->sc_lastmsg = sc->sc_currmsg; 1397 sc->sc_lastmsg = sc->sc_currmsg;
1398 /* Wait for ACK to be negated. XXX Need timeout. */ 1398 /* Wait for ACK to be negated. XXX Need timeout. */
1399 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0) 1399 while ((bus_space_read_1(iot, ioh, SCSISIG) & ACKI) != 0)
1400 ; 1400 ;
1401 1401
1402 if (n == 0) 1402 if (n == 0)
1403 break; 1403 break;
1404 } 1404 }
1405 1405
1406 /* We get here only if the entire message has been transmitted. */ 1406 /* We get here only if the entire message has been transmitted. */
1407 if (sc->sc_msgpriq != 0) { 1407 if (sc->sc_msgpriq != 0) {
1408 /* There are more outgoing messages. */ 1408 /* There are more outgoing messages. */
1409 goto nextmsg; 1409 goto nextmsg;
1410 } 1410 }
1411 1411
1412 /* 1412 /*
1413 * The last message has been transmitted. We need to remember the last 1413 * The last message has been transmitted. We need to remember the last
1414 * message transmitted (in case the target switches to MESSAGE IN phase 1414 * message transmitted (in case the target switches to MESSAGE IN phase
1415 * and sends a MESSAGE REJECT), and the list of messages transmitted 1415 * and sends a MESSAGE REJECT), and the list of messages transmitted
1416 * this time around (in case the target stays in MESSAGE OUT phase to 1416 * this time around (in case the target stays in MESSAGE OUT phase to
1417 * request a retransmit). 1417 * request a retransmit).
1418 */ 1418 */
1419 1419
1420out: 1420out:
1421 /* Disable REQ/ACK protocol. */ 1421 /* Disable REQ/ACK protocol. */
1422 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 1422 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
1423} 1423}
1424 1424
1425/* aic_dataout_pio: perform a data transfer using the FIFO datapath in the 1425/* aic_dataout_pio: perform a data transfer using the FIFO datapath in the
1426 * aic6360 1426 * aic6360
1427 * Precondition: The SCSI bus should be in the DOUT phase, with REQ asserted 1427 * Precondition: The SCSI bus should be in the DOUT phase, with REQ asserted
1428 * and ACK deasserted (i.e. waiting for a data byte) 1428 * and ACK deasserted (i.e. waiting for a data byte)
1429 * This new revision has been optimized (I tried) to make the common case fast, 1429 * This new revision has been optimized (I tried) to make the common case fast,
1430 * and the rarer cases (as a result) somewhat more complex 1430 * and the rarer cases (as a result) somewhat more complex
1431 */ 1431 */
1432static int 1432static int
1433aic_dataout_pio(struct aic_softc *sc, u_char *p, int n) 1433aic_dataout_pio(struct aic_softc *sc, u_char *p, int n)
1434{ 1434{
1435 bus_space_tag_t iot = sc->sc_iot; 1435 bus_space_tag_t iot = sc->sc_iot;
1436 bus_space_handle_t ioh = sc->sc_ioh; 1436 bus_space_handle_t ioh = sc->sc_ioh;
1437 u_char dmastat = 0; 1437 u_char dmastat = 0;
1438 int out = 0; 1438 int out = 0;
1439#define DOUTAMOUNT 128 /* Full FIFO */ 1439#define DOUTAMOUNT 128 /* Full FIFO */
1440 1440
1441 AIC_MISC(("%02x%02x ", bus_space_read_1(iot, ioh, FIFOSTAT), 1441 AIC_MISC(("%02x%02x ", bus_space_read_1(iot, ioh, FIFOSTAT),
1442 bus_space_read_1(iot, ioh, SSTAT2))); 1442 bus_space_read_1(iot, ioh, SSTAT2)));
1443 1443
1444 /* Clear host FIFO and counter. */ 1444 /* Clear host FIFO and counter. */
1445 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO | WRITE); 1445 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO | WRITE);
1446 /* Enable FIFOs. */ 1446 /* Enable FIFOs. */
1447 bus_space_write_1(iot, ioh, DMACNTRL0, ENDMA | DWORDPIO | WRITE); 1447 bus_space_write_1(iot, ioh, DMACNTRL0, ENDMA | DWORDPIO | WRITE);
1448 bus_space_write_1(iot, ioh, SXFRCTL0, SCSIEN | DMAEN | CHEN); 1448 bus_space_write_1(iot, ioh, SXFRCTL0, SCSIEN | DMAEN | CHEN);
1449 1449
1450 /* Turn off ENREQINIT for now. */ 1450 /* Turn off ENREQINIT for now. */
1451 bus_space_write_1(iot, ioh, SIMODE1, 1451 bus_space_write_1(iot, ioh, SIMODE1,
1452 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENPHASECHG); 1452 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENPHASECHG);
1453 1453
1454 /* I have tried to make the main loop as tight as possible. This 1454 /* I have tried to make the main loop as tight as possible. This
1455 * means that some of the code following the loop is a bit more 1455 * means that some of the code following the loop is a bit more
1456 * complex than otherwise. 1456 * complex than otherwise.
1457 */ 1457 */
1458 while (n > 0) { 1458 while (n > 0) {
1459 for (;;) { 1459 for (;;) {
1460 dmastat = bus_space_read_1(iot, ioh, DMASTAT); 1460 dmastat = bus_space_read_1(iot, ioh, DMASTAT);
1461 if ((dmastat & (DFIFOEMP | INTSTAT)) != 0) 1461 if ((dmastat & (DFIFOEMP | INTSTAT)) != 0)
1462 break; 1462 break;
1463 } 1463 }
1464 1464
1465 if ((dmastat & INTSTAT) != 0) 1465 if ((dmastat & INTSTAT) != 0)
1466 goto phasechange; 1466 goto phasechange;
1467 1467
1468 if (n >= DOUTAMOUNT) { 1468 if (n >= DOUTAMOUNT) {
1469 n -= DOUTAMOUNT; 1469 n -= DOUTAMOUNT;
1470 out += DOUTAMOUNT; 1470 out += DOUTAMOUNT;
1471 1471
1472#if AIC_USE_DWORDS 1472#if AIC_USE_DWORDS
1473 bus_space_write_multi_4(iot, ioh, DMADATALONG, 1473 bus_space_write_multi_4(iot, ioh, DMADATALONG,
1474 (u_int32_t *) p, DOUTAMOUNT >> 2); 1474 (u_int32_t *) p, DOUTAMOUNT >> 2);
1475#else 1475#else
1476 bus_space_write_multi_2(iot, ioh, DMADATA, 1476 bus_space_write_multi_2(iot, ioh, DMADATA,
1477 (u_int16_t *) p, DOUTAMOUNT >> 1); 1477 (u_int16_t *) p, DOUTAMOUNT >> 1);
1478#endif 1478#endif
1479 1479
1480 p += DOUTAMOUNT; 1480 p += DOUTAMOUNT;
1481 } else { 1481 } else {
1482 int xfer; 1482 int xfer;
1483 1483
1484 xfer = n; 1484 xfer = n;
1485 AIC_MISC(("%d> ", xfer)); 1485 AIC_MISC(("%d> ", xfer));
1486 1486
1487 n -= xfer; 1487 n -= xfer;
1488 out += xfer; 1488 out += xfer;
1489 1489
1490#if AIC_USE_DWORDS 1490#if AIC_USE_DWORDS
1491 if (xfer >= 12) { 1491 if (xfer >= 12) {
1492 bus_space_write_multi_4(iot, ioh, DMADATALONG, 1492 bus_space_write_multi_4(iot, ioh, DMADATALONG,
1493 (u_int32_t *) p, xfer >> 2); 1493 (u_int32_t *) p, xfer >> 2);
1494 p += xfer & ~3; 1494 p += xfer & ~3;
1495 xfer &= 3; 1495 xfer &= 3;
1496 } 1496 }
1497#else 1497#else
1498 if (xfer >= 8) { 1498 if (xfer >= 8) {
1499 bus_space_write_multi_2(iot, ioh, DMADATA, 1499 bus_space_write_multi_2(iot, ioh, DMADATA,
1500 (u_int16_t *) p, xfer >> 1); 1500 (u_int16_t *) p, xfer >> 1);
1501 p += xfer & ~1; 1501 p += xfer & ~1;
1502 xfer &= 1; 1502 xfer &= 1;
1503 } 1503 }
1504#endif 1504#endif
1505 1505
1506 if (xfer > 0) { 1506 if (xfer > 0) {
1507 bus_space_write_1(iot, ioh, DMACNTRL0, 1507 bus_space_write_1(iot, ioh, DMACNTRL0,
1508 ENDMA | B8MODE | WRITE); 1508 ENDMA | B8MODE | WRITE);
1509 bus_space_write_multi_1(iot, ioh, DMADATA, 1509 bus_space_write_multi_1(iot, ioh, DMADATA,
1510 p, xfer); 1510 p, xfer);
1511 p += xfer; 1511 p += xfer;
1512 bus_space_write_1(iot, ioh, DMACNTRL0, 1512 bus_space_write_1(iot, ioh, DMACNTRL0,
1513 ENDMA | DWORDPIO | WRITE); 1513 ENDMA | DWORDPIO | WRITE);
1514 } 1514 }
1515 } 1515 }
1516 } 1516 }
1517 1517
1518 if (out == 0) { 1518 if (out == 0) {
1519 bus_space_write_1(iot, ioh, SXFRCTL1, BITBUCKET); 1519 bus_space_write_1(iot, ioh, SXFRCTL1, BITBUCKET);
1520 for (;;) { 1520 for (;;) {
1521 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT) 1521 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT)
1522 != 0) 1522 != 0)
1523 break; 1523 break;
1524 } 1524 }
1525 bus_space_write_1(iot, ioh, SXFRCTL1, 0); 1525 bus_space_write_1(iot, ioh, SXFRCTL1, 0);
1526 AIC_MISC(("extra data ")); 1526 AIC_MISC(("extra data "));
1527 } else { 1527 } else {
1528 /* See the bytes off chip */ 1528 /* See the bytes off chip */
1529 for (;;) { 1529 for (;;) {
1530 dmastat = bus_space_read_1(iot, ioh, DMASTAT); 1530 dmastat = bus_space_read_1(iot, ioh, DMASTAT);
1531 if ((dmastat & INTSTAT) != 0) 1531 if ((dmastat & INTSTAT) != 0)
1532 goto phasechange; 1532 goto phasechange;
1533 if ((dmastat & DFIFOEMP) != 0 && 1533 if ((dmastat & DFIFOEMP) != 0 &&
1534 (bus_space_read_1(iot, ioh, SSTAT2) & SEMPTY) != 0) 1534 (bus_space_read_1(iot, ioh, SSTAT2) & SEMPTY) != 0)
1535 break; 1535 break;
1536 } 1536 }
1537 } 1537 }
1538 1538
1539phasechange: 1539phasechange:
1540 if ((dmastat & INTSTAT) != 0) { 1540 if ((dmastat & INTSTAT) != 0) {
1541 /* Some sort of phase change. */ 1541 /* Some sort of phase change. */
1542 int amount; 1542 int amount;
1543 1543
1544 /* Stop transfers, do some accounting */ 1544 /* Stop transfers, do some accounting */
1545 amount = bus_space_read_1(iot, ioh, FIFOSTAT) 1545 amount = bus_space_read_1(iot, ioh, FIFOSTAT)
1546 + (bus_space_read_1(iot, ioh, SSTAT2) & 15); 1546 + (bus_space_read_1(iot, ioh, SSTAT2) & 15);
1547 if (amount > 0) { 1547 if (amount > 0) {
1548 out -= amount; 1548 out -= amount;
1549 bus_space_write_1(iot, ioh, DMACNTRL0, 1549 bus_space_write_1(iot, ioh, DMACNTRL0,
1550 RSTFIFO | WRITE); 1550 RSTFIFO | WRITE);
1551 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRCH); 1551 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRCH);
1552 AIC_MISC(("+%d ", amount)); 1552 AIC_MISC(("+%d ", amount));
1553 } 1553 }
1554 } 1554 }
1555 1555
1556 /* Turn on ENREQINIT again. */ 1556 /* Turn on ENREQINIT again. */
1557 bus_space_write_1(iot, ioh, SIMODE1, 1557 bus_space_write_1(iot, ioh, SIMODE1,
1558 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT | ENPHASECHG); 1558 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT | ENPHASECHG);
1559 1559
1560 /* Stop the FIFO data path. */ 1560 /* Stop the FIFO data path. */
1561 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 1561 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
1562 bus_space_write_1(iot, ioh, DMACNTRL0, 0); 1562 bus_space_write_1(iot, ioh, DMACNTRL0, 0);
1563 1563
1564 return out; 1564 return out;
1565} 1565}
1566 1566
1567/* aic_datain_pio: perform data transfers using the FIFO datapath in the 1567/* aic_datain_pio: perform data transfers using the FIFO datapath in the
1568 * aic6360 1568 * aic6360
1569 * Precondition: The SCSI bus should be in the DIN phase, with REQ asserted 1569 * Precondition: The SCSI bus should be in the DIN phase, with REQ asserted
1570 * and ACK deasserted (i.e. at least one byte is ready). 1570 * and ACK deasserted (i.e. at least one byte is ready).
1571 * For now, uses a pretty dumb algorithm, hangs around until all data has been 1571 * For now, uses a pretty dumb algorithm, hangs around until all data has been
1572 * transferred. This, is OK for fast targets, but not so smart for slow 1572 * transferred. This, is OK for fast targets, but not so smart for slow
1573 * targets which don't disconnect or for huge transfers. 1573 * targets which don't disconnect or for huge transfers.
1574 */ 1574 */
1575static int 1575static int
1576aic_datain_pio(struct aic_softc *sc, u_char *p, int n) 1576aic_datain_pio(struct aic_softc *sc, u_char *p, int n)
1577{ 1577{
1578 bus_space_tag_t iot = sc->sc_iot; 1578 bus_space_tag_t iot = sc->sc_iot;
1579 bus_space_handle_t ioh = sc->sc_ioh; 1579 bus_space_handle_t ioh = sc->sc_ioh;
1580 u_char dmastat; 1580 u_char dmastat;
1581 int in = 0; 1581 int in = 0;
1582#define DINAMOUNT 128 /* Full FIFO */ 1582#define DINAMOUNT 128 /* Full FIFO */
1583 1583
1584 AIC_MISC(("%02x%02x ", bus_space_read_1(iot, ioh, FIFOSTAT), 1584 AIC_MISC(("%02x%02x ", bus_space_read_1(iot, ioh, FIFOSTAT),
1585 bus_space_read_1(iot, ioh, SSTAT2))); 1585 bus_space_read_1(iot, ioh, SSTAT2)));
1586 1586
1587 /* Clear host FIFO and counter. */ 1587 /* Clear host FIFO and counter. */
1588 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO); 1588 bus_space_write_1(iot, ioh, DMACNTRL0, RSTFIFO);
1589 /* Enable FIFOs. */ 1589 /* Enable FIFOs. */
1590 bus_space_write_1(iot, ioh, DMACNTRL0, ENDMA | DWORDPIO); 1590 bus_space_write_1(iot, ioh, DMACNTRL0, ENDMA | DWORDPIO);
1591 bus_space_write_1(iot, ioh, SXFRCTL0, SCSIEN | DMAEN | CHEN); 1591 bus_space_write_1(iot, ioh, SXFRCTL0, SCSIEN | DMAEN | CHEN);
1592 1592
1593 /* Turn off ENREQINIT for now. */ 1593 /* Turn off ENREQINIT for now. */
1594 bus_space_write_1(iot, ioh, SIMODE1, 1594 bus_space_write_1(iot, ioh, SIMODE1,
1595 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENPHASECHG); 1595 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENPHASECHG);
1596 1596
1597 /* We leave this loop if one or more of the following is true: 1597 /* We leave this loop if one or more of the following is true:
1598 * a) phase != PH_DATAIN && FIFOs are empty 1598 * a) phase != PH_DATAIN && FIFOs are empty
1599 * b) SCSIRSTI is set (a reset has occurred) or busfree is detected. 1599 * b) SCSIRSTI is set (a reset has occurred) or busfree is detected.
1600 */ 1600 */
1601 while (n > 0) { 1601 while (n > 0) {
1602 /* Wait for fifo half full or phase mismatch */ 1602 /* Wait for fifo half full or phase mismatch */
1603 for (;;) { 1603 for (;;) {
1604 dmastat = bus_space_read_1(iot, ioh, DMASTAT); 1604 dmastat = bus_space_read_1(iot, ioh, DMASTAT);
1605 if ((dmastat & (DFIFOFULL | INTSTAT)) != 0) 1605 if ((dmastat & (DFIFOFULL | INTSTAT)) != 0)
1606 break; 1606 break;
1607 } 1607 }
1608 1608
1609 if ((dmastat & DFIFOFULL) != 0) { 1609 if ((dmastat & DFIFOFULL) != 0) {
1610 n -= DINAMOUNT; 1610 n -= DINAMOUNT;
1611 in += DINAMOUNT; 1611 in += DINAMOUNT;
1612 1612
1613#if AIC_USE_DWORDS 1613#if AIC_USE_DWORDS
1614 bus_space_read_multi_4(iot, ioh, DMADATALONG, 1614 bus_space_read_multi_4(iot, ioh, DMADATALONG,
1615 (u_int32_t *) p, DINAMOUNT >> 2); 1615 (u_int32_t *) p, DINAMOUNT >> 2);
1616#else 1616#else
1617 bus_space_read_multi_2(iot, ioh, DMADATA, 1617 bus_space_read_multi_2(iot, ioh, DMADATA,
1618 (u_int16_t *) p, DINAMOUNT >> 1); 1618 (u_int16_t *) p, DINAMOUNT >> 1);
1619#endif 1619#endif
1620 1620
1621 p += DINAMOUNT; 1621 p += DINAMOUNT;
1622 } else { 1622 } else {
1623 int xfer; 1623 int xfer;
1624 1624
1625 xfer = uimin(bus_space_read_1(iot, ioh, FIFOSTAT), n); 1625 xfer = uimin(bus_space_read_1(iot, ioh, FIFOSTAT), n);
1626 AIC_MISC((">%d ", xfer)); 1626 AIC_MISC((">%d ", xfer));
1627 1627
1628 n -= xfer; 1628 n -= xfer;
1629 in += xfer; 1629 in += xfer;
1630 1630
1631#if AIC_USE_DWORDS 1631#if AIC_USE_DWORDS
1632 if (xfer >= 12) { 1632 if (xfer >= 12) {
1633 bus_space_read_multi_4(iot, ioh, DMADATALONG, 1633 bus_space_read_multi_4(iot, ioh, DMADATALONG,
1634 (u_int32_t *) p, xfer >> 2); 1634 (u_int32_t *) p, xfer >> 2);
1635 p += xfer & ~3; 1635 p += xfer & ~3;
1636 xfer &= 3; 1636 xfer &= 3;
1637 } 1637 }
1638#else 1638#else
1639 if (xfer >= 8) { 1639 if (xfer >= 8) {
1640 bus_space_read_multi_2(iot, ioh, DMADATA, 1640 bus_space_read_multi_2(iot, ioh, DMADATA,
1641 (u_int16_t *) p, xfer >> 1); 1641 (u_int16_t *) p, xfer >> 1);
1642 p += xfer & ~1; 1642 p += xfer & ~1;
1643 xfer &= 1; 1643 xfer &= 1;
1644 } 1644 }
1645#endif 1645#endif
1646 1646
1647 if (xfer > 0) { 1647 if (xfer > 0) {
1648 bus_space_write_1(iot, ioh, DMACNTRL0, 1648 bus_space_write_1(iot, ioh, DMACNTRL0,
1649 ENDMA | B8MODE); 1649 ENDMA | B8MODE);
1650 bus_space_read_multi_1(iot, ioh, DMADATA, 1650 bus_space_read_multi_1(iot, ioh, DMADATA,
1651 p, xfer); 1651 p, xfer);
1652 p += xfer; 1652 p += xfer;
1653 bus_space_write_1(iot, ioh, DMACNTRL0, 1653 bus_space_write_1(iot, ioh, DMACNTRL0,
1654 ENDMA | DWORDPIO); 1654 ENDMA | DWORDPIO);
1655 } 1655 }
1656 } 1656 }
1657 1657
1658 if ((dmastat & INTSTAT) != 0) 1658 if ((dmastat & INTSTAT) != 0)
1659 goto phasechange; 1659 goto phasechange;
1660 } 1660 }
1661 1661
1662 /* Some SCSI-devices are rude enough to transfer more data than what 1662 /* Some SCSI-devices are rude enough to transfer more data than what
1663 * was requested, e.g. 2048 bytes from a CD-ROM instead of the 1663 * was requested, e.g. 2048 bytes from a CD-ROM instead of the
1664 * requested 512. Test for progress, i.e. real transfers. If no real 1664 * requested 512. Test for progress, i.e. real transfers. If no real
1665 * transfers have been performed (n is probably already zero) and the 1665 * transfers have been performed (n is probably already zero) and the
1666 * FIFO is not empty, waste some bytes.... 1666 * FIFO is not empty, waste some bytes....
1667 */ 1667 */
1668 if (in == 0) { 1668 if (in == 0) {
1669 bus_space_write_1(iot, ioh, SXFRCTL1, BITBUCKET); 1669 bus_space_write_1(iot, ioh, SXFRCTL1, BITBUCKET);
1670 for (;;) { 1670 for (;;) {
1671 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT) 1671 if ((bus_space_read_1(iot, ioh, DMASTAT) & INTSTAT)
1672 != 0) 1672 != 0)
1673 break; 1673 break;
1674 } 1674 }
1675 bus_space_write_1(iot, ioh, SXFRCTL1, 0); 1675 bus_space_write_1(iot, ioh, SXFRCTL1, 0);
1676 AIC_MISC(("extra data ")); 1676 AIC_MISC(("extra data "));
1677 } 1677 }
1678 1678
1679phasechange: 1679phasechange:
1680 /* Turn on ENREQINIT again. */ 1680 /* Turn on ENREQINIT again. */
1681 bus_space_write_1(iot, ioh, SIMODE1, 1681 bus_space_write_1(iot, ioh, SIMODE1,
1682 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT | ENPHASECHG); 1682 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT | ENPHASECHG);
1683 1683
1684 /* Stop the FIFO data path. */ 1684 /* Stop the FIFO data path. */
1685 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 1685 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
1686 bus_space_write_1(iot, ioh, DMACNTRL0, 0); 1686 bus_space_write_1(iot, ioh, DMACNTRL0, 0);
1687 1687
1688 return in; 1688 return in;
1689} 1689}
1690 1690
1691/* 1691/*
1692 * This is the workhorse routine of the driver. 1692 * This is the workhorse routine of the driver.
1693 * Deficiencies (for now): 1693 * Deficiencies (for now):
1694 * 1) always uses programmed I/O 1694 * 1) always uses programmed I/O
1695 */ 1695 */
1696int 1696int
1697aicintr(void *arg) 1697aicintr(void *arg)
1698{ 1698{
1699 struct aic_softc *sc = arg; 1699 struct aic_softc *sc = arg;
1700 bus_space_tag_t iot = sc->sc_iot; 1700 bus_space_tag_t iot = sc->sc_iot;
1701 bus_space_handle_t ioh = sc->sc_ioh; 1701 bus_space_handle_t ioh = sc->sc_ioh;
1702 u_char sstat0, sstat1; 1702 u_char sstat0, sstat1;
1703 struct aic_acb *acb; 1703 struct aic_acb *acb;
1704 struct scsipi_periph *periph; 1704 struct scsipi_periph *periph;
1705 struct aic_tinfo *ti; 1705 struct aic_tinfo *ti;
1706 int n; 1706 int n;
1707 1707
1708 if (!device_is_active(sc->sc_dev)) 1708 if (!device_is_active(sc->sc_dev))
1709 return (0); 1709 return (0);
1710 1710
1711 /* 1711 /*
1712 * Clear INTEN. We enable it again before returning. This makes the 1712 * Clear INTEN. We enable it again before returning. This makes the
1713 * interrupt esssentially level-triggered. 1713 * interrupt essentially level-triggered.
1714 */ 1714 */
1715 bus_space_write_1(iot, ioh, DMACNTRL0, 0); 1715 bus_space_write_1(iot, ioh, DMACNTRL0, 0);
1716 1716
1717 AIC_TRACE(("aicintr ")); 1717 AIC_TRACE(("aicintr "));
1718 1718
1719loop: 1719loop:
1720 /* 1720 /*
1721 * First check for abnormal conditions, such as reset. 1721 * First check for abnormal conditions, such as reset.
1722 */ 1722 */
1723 sstat1 = bus_space_read_1(iot, ioh, SSTAT1); 1723 sstat1 = bus_space_read_1(iot, ioh, SSTAT1);
1724 AIC_MISC(("sstat1:0x%02x ", sstat1)); 1724 AIC_MISC(("sstat1:0x%02x ", sstat1));
1725 1725
1726 if ((sstat1 & SCSIRSTI) != 0) { 1726 if ((sstat1 & SCSIRSTI) != 0) {
1727 printf("%s: SCSI bus reset\n", device_xname(sc->sc_dev)); 1727 printf("%s: SCSI bus reset\n", device_xname(sc->sc_dev));
1728 goto reset; 1728 goto reset;
1729 } 1729 }
1730 1730
1731 /* 1731 /*
1732 * Check for less serious errors. 1732 * Check for less serious errors.
1733 */ 1733 */
1734 if ((sstat1 & SCSIPERR) != 0) { 1734 if ((sstat1 & SCSIPERR) != 0) {
1735 printf("%s: SCSI bus parity error\n", device_xname(sc->sc_dev)); 1735 printf("%s: SCSI bus parity error\n", device_xname(sc->sc_dev));
1736 bus_space_write_1(iot, ioh, CLRSINT1, CLRSCSIPERR); 1736 bus_space_write_1(iot, ioh, CLRSINT1, CLRSCSIPERR);
1737 if (sc->sc_prevphase == PH_MSGIN) { 1737 if (sc->sc_prevphase == PH_MSGIN) {
1738 sc->sc_flags |= AIC_DROP_MSGIN; 1738 sc->sc_flags |= AIC_DROP_MSGIN;
1739 aic_sched_msgout(sc, SEND_PARITY_ERROR); 1739 aic_sched_msgout(sc, SEND_PARITY_ERROR);
1740 } else 1740 } else
1741 aic_sched_msgout(sc, SEND_INIT_DET_ERR); 1741 aic_sched_msgout(sc, SEND_INIT_DET_ERR);
1742 } 1742 }
1743 1743
1744 /* 1744 /*
1745 * If we're not already busy doing something test for the following 1745 * If we're not already busy doing something test for the following
1746 * conditions: 1746 * conditions:
1747 * 1) We have been reselected by something 1747 * 1) We have been reselected by something
1748 * 2) We have selected something successfully 1748 * 2) We have selected something successfully
1749 * 3) Our selection process has timed out 1749 * 3) Our selection process has timed out
1750 * 4) This is really a bus free interrupt just to get a new command 1750 * 4) This is really a bus free interrupt just to get a new command
1751 * going? 1751 * going?
1752 * 5) Spurious interrupt? 1752 * 5) Spurious interrupt?
1753 */ 1753 */
1754 switch (sc->sc_state) { 1754 switch (sc->sc_state) {
1755 case AIC_IDLE: 1755 case AIC_IDLE:
1756 case AIC_SELECTING: 1756 case AIC_SELECTING:
1757 sstat0 = bus_space_read_1(iot, ioh, SSTAT0); 1757 sstat0 = bus_space_read_1(iot, ioh, SSTAT0);
1758 AIC_MISC(("sstat0:0x%02x ", sstat0)); 1758 AIC_MISC(("sstat0:0x%02x ", sstat0));
1759 1759
1760 if ((sstat0 & TARGET) != 0) { 1760 if ((sstat0 & TARGET) != 0) {
1761 /* 1761 /*
1762 * We don't currently support target mode. 1762 * We don't currently support target mode.
1763 */ 1763 */
1764 printf("%s: target mode selected; going to BUS FREE\n", 1764 printf("%s: target mode selected; going to BUS FREE\n",
1765 device_xname(sc->sc_dev)); 1765 device_xname(sc->sc_dev));
1766 bus_space_write_1(iot, ioh, SCSISIG, 0); 1766 bus_space_write_1(iot, ioh, SCSISIG, 0);
1767 1767
1768 goto sched; 1768 goto sched;
1769 } else if ((sstat0 & SELDI) != 0) { 1769 } else if ((sstat0 & SELDI) != 0) {
1770 AIC_MISC(("reselected ")); 1770 AIC_MISC(("reselected "));
1771 1771
1772 /* 1772 /*
1773 * If we're trying to select a target ourselves, 1773 * If we're trying to select a target ourselves,
1774 * push our command back into the ready list. 1774 * push our command back into the ready list.
1775 */ 1775 */
1776 if (sc->sc_state == AIC_SELECTING) { 1776 if (sc->sc_state == AIC_SELECTING) {
1777 AIC_MISC(("backoff selector ")); 1777 AIC_MISC(("backoff selector "));
1778 AIC_ASSERT(sc->sc_nexus != NULL); 1778 AIC_ASSERT(sc->sc_nexus != NULL);
1779 acb = sc->sc_nexus; 1779 acb = sc->sc_nexus;
1780 sc->sc_nexus = NULL; 1780 sc->sc_nexus = NULL;
1781 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain); 1781 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
1782 } 1782 }
1783 1783
1784 /* Save reselection ID. */ 1784 /* Save reselection ID. */
1785 sc->sc_selid = bus_space_read_1(iot, ioh, SELID); 1785 sc->sc_selid = bus_space_read_1(iot, ioh, SELID);
1786 1786
1787 sc->sc_state = AIC_RESELECTED; 1787 sc->sc_state = AIC_RESELECTED;
1788 } else if ((sstat0 & SELDO) != 0) { 1788 } else if ((sstat0 & SELDO) != 0) {
1789 AIC_MISC(("selected ")); 1789 AIC_MISC(("selected "));
1790 1790
1791 /* We have selected a target. Things to do: 1791 /* We have selected a target. Things to do:
1792 * a) Determine what message(s) to send. 1792 * a) Determine what message(s) to send.
1793 * b) Verify that we're still selecting the target. 1793 * b) Verify that we're still selecting the target.
1794 * c) Mark device as busy. 1794 * c) Mark device as busy.
1795 */ 1795 */
1796 if (sc->sc_state != AIC_SELECTING) { 1796 if (sc->sc_state != AIC_SELECTING) {
1797 printf("%s: selection out while idle; " 1797 printf("%s: selection out while idle; "
1798 "resetting\n", device_xname(sc->sc_dev)); 1798 "resetting\n", device_xname(sc->sc_dev));
1799 AIC_BREAK(); 1799 AIC_BREAK();
1800 goto reset; 1800 goto reset;
1801 } 1801 }
1802 AIC_ASSERT(sc->sc_nexus != NULL); 1802 AIC_ASSERT(sc->sc_nexus != NULL);
1803 acb = sc->sc_nexus; 1803 acb = sc->sc_nexus;
1804 periph = acb->xs->xs_periph; 1804 periph = acb->xs->xs_periph;
1805 ti = &sc->sc_tinfo[periph->periph_target]; 1805 ti = &sc->sc_tinfo[periph->periph_target];
1806 1806
1807 sc->sc_msgpriq = SEND_IDENTIFY; 1807 sc->sc_msgpriq = SEND_IDENTIFY;
1808 if (acb->flags & ACB_RESET) 1808 if (acb->flags & ACB_RESET)
1809 sc->sc_msgpriq |= SEND_DEV_RESET; 1809 sc->sc_msgpriq |= SEND_DEV_RESET;
1810 else if (acb->flags & ACB_ABORT) 1810 else if (acb->flags & ACB_ABORT)
1811 sc->sc_msgpriq |= SEND_ABORT; 1811 sc->sc_msgpriq |= SEND_ABORT;
1812 else { 1812 else {
1813#if AIC_USE_SYNCHRONOUS 1813#if AIC_USE_SYNCHRONOUS
1814 if ((ti->flags & DO_SYNC) != 0) 1814 if ((ti->flags & DO_SYNC) != 0)
1815 sc->sc_msgpriq |= SEND_SDTR; 1815 sc->sc_msgpriq |= SEND_SDTR;
1816#endif 1816#endif
1817#if AIC_USE_WIDE 1817#if AIC_USE_WIDE
1818 if ((ti->flags & DO_WIDE) != 0) 1818 if ((ti->flags & DO_WIDE) != 0)
1819 sc->sc_msgpriq |= SEND_WDTR; 1819 sc->sc_msgpriq |= SEND_WDTR;
1820#endif 1820#endif
1821 } 1821 }
1822 1822
1823 acb->flags |= ACB_NEXUS; 1823 acb->flags |= ACB_NEXUS;
1824 ti->lubusy |= (1 << periph->periph_lun); 1824 ti->lubusy |= (1 << periph->periph_lun);
1825 1825
1826 /* Do an implicit RESTORE POINTERS. */ 1826 /* Do an implicit RESTORE POINTERS. */
1827 sc->sc_dp = acb->data_addr; 1827 sc->sc_dp = acb->data_addr;
1828 sc->sc_dleft = acb->data_length; 1828 sc->sc_dleft = acb->data_length;
1829 sc->sc_cp = (u_char *)&acb->scsipi_cmd; 1829 sc->sc_cp = (u_char *)&acb->scsipi_cmd;
1830 sc->sc_cleft = acb->scsipi_cmd_length; 1830 sc->sc_cleft = acb->scsipi_cmd_length;
1831 1831
1832 /* On our first connection, schedule a timeout. */ 1832 /* On our first connection, schedule a timeout. */
1833 if ((acb->xs->xs_control & XS_CTL_POLL) == 0) 1833 if ((acb->xs->xs_control & XS_CTL_POLL) == 0)
1834 callout_reset(&acb->xs->xs_callout, 1834 callout_reset(&acb->xs->xs_callout,
1835 mstohz(acb->timeout), aic_timeout, acb); 1835 mstohz(acb->timeout), aic_timeout, acb);
1836 1836
1837 sc->sc_state = AIC_CONNECTED; 1837 sc->sc_state = AIC_CONNECTED;
1838 } else if ((sstat1 & SELTO) != 0) { 1838 } else if ((sstat1 & SELTO) != 0) {
1839 AIC_MISC(("selection timeout ")); 1839 AIC_MISC(("selection timeout "));
1840 1840
1841 if (sc->sc_state != AIC_SELECTING) { 1841 if (sc->sc_state != AIC_SELECTING) {
1842 printf("%s: selection timeout while idle; " 1842 printf("%s: selection timeout while idle; "
1843 "resetting\n", device_xname(sc->sc_dev)); 1843 "resetting\n", device_xname(sc->sc_dev));
1844 AIC_BREAK(); 1844 AIC_BREAK();
1845 goto reset; 1845 goto reset;
1846 } 1846 }
1847 AIC_ASSERT(sc->sc_nexus != NULL); 1847 AIC_ASSERT(sc->sc_nexus != NULL);
1848 acb = sc->sc_nexus; 1848 acb = sc->sc_nexus;
1849 1849
1850 bus_space_write_1(iot, ioh, SXFRCTL1, 0); 1850 bus_space_write_1(iot, ioh, SXFRCTL1, 0);
1851 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI); 1851 bus_space_write_1(iot, ioh, SCSISEQ, ENRESELI);
1852 bus_space_write_1(iot, ioh, CLRSINT1, CLRSELTIMO); 1852 bus_space_write_1(iot, ioh, CLRSINT1, CLRSELTIMO);
1853 delay(250); 1853 delay(250);
1854 1854
1855 acb->xs->error = XS_SELTIMEOUT; 1855 acb->xs->error = XS_SELTIMEOUT;
1856 goto finish; 1856 goto finish;
1857 } else { 1857 } else {
1858 if (sc->sc_state != AIC_IDLE) { 1858 if (sc->sc_state != AIC_IDLE) {
1859 printf("%s: BUS FREE while not idle; " 1859 printf("%s: BUS FREE while not idle; "
1860 "state=%d\n", 1860 "state=%d\n",
1861 device_xname(sc->sc_dev), sc->sc_state); 1861 device_xname(sc->sc_dev), sc->sc_state);
1862 AIC_BREAK(); 1862 AIC_BREAK();
1863 goto out; 1863 goto out;
1864 } 1864 }
1865 1865
1866 goto sched; 1866 goto sched;
1867 } 1867 }
1868 1868
1869 /* 1869 /*
1870 * Turn off selection stuff, and prepare to catch bus free 1870 * Turn off selection stuff, and prepare to catch bus free
1871 * interrupts, parity errors, and phase changes. 1871 * interrupts, parity errors, and phase changes.
1872 */ 1872 */
1873 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRSTCNT | CLRCH); 1873 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | CLRSTCNT | CLRCH);
1874 bus_space_write_1(iot, ioh, SXFRCTL1, 0); 1874 bus_space_write_1(iot, ioh, SXFRCTL1, 0);
1875 bus_space_write_1(iot, ioh, SCSISEQ, ENAUTOATNP); 1875 bus_space_write_1(iot, ioh, SCSISEQ, ENAUTOATNP);
1876 bus_space_write_1(iot, ioh, CLRSINT0, CLRSELDI | CLRSELDO); 1876 bus_space_write_1(iot, ioh, CLRSINT0, CLRSELDI | CLRSELDO);
1877 bus_space_write_1(iot, ioh, CLRSINT1, 1877 bus_space_write_1(iot, ioh, CLRSINT1,
1878 CLRBUSFREE | CLRPHASECHG); 1878 CLRBUSFREE | CLRPHASECHG);
1879 bus_space_write_1(iot, ioh, SIMODE0, 0); 1879 bus_space_write_1(iot, ioh, SIMODE0, 0);
1880 bus_space_write_1(iot, ioh, SIMODE1, 1880 bus_space_write_1(iot, ioh, SIMODE1,
1881 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT | 1881 ENSCSIRST | ENSCSIPERR | ENBUSFREE | ENREQINIT |
1882 ENPHASECHG); 1882 ENPHASECHG);
1883 1883
1884 sc->sc_flags = 0; 1884 sc->sc_flags = 0;
1885 sc->sc_prevphase = PH_INVALID; 1885 sc->sc_prevphase = PH_INVALID;
1886 goto dophase; 1886 goto dophase;
1887 } 1887 }
1888 1888
1889 if ((sstat1 & BUSFREE) != 0) { 1889 if ((sstat1 & BUSFREE) != 0) {
1890 /* We've gone to BUS FREE phase. */ 1890 /* We've gone to BUS FREE phase. */
1891 bus_space_write_1(iot, ioh, CLRSINT1, 1891 bus_space_write_1(iot, ioh, CLRSINT1,
1892 CLRBUSFREE | CLRPHASECHG); 1892 CLRBUSFREE | CLRPHASECHG);
1893 1893
1894 switch (sc->sc_state) { 1894 switch (sc->sc_state) {
1895 case AIC_RESELECTED: 1895 case AIC_RESELECTED:
1896 goto sched; 1896 goto sched;
1897 1897
1898 case AIC_CONNECTED: 1898 case AIC_CONNECTED:
1899 AIC_ASSERT(sc->sc_nexus != NULL); 1899 AIC_ASSERT(sc->sc_nexus != NULL);
1900 acb = sc->sc_nexus; 1900 acb = sc->sc_nexus;
1901 1901
1902#if AIC_USE_SYNCHRONOUS + AIC_USE_WIDE 1902#if AIC_USE_SYNCHRONOUS + AIC_USE_WIDE
1903 if (sc->sc_prevphase == PH_MSGOUT) { 1903 if (sc->sc_prevphase == PH_MSGOUT) {
1904 /* 1904 /*
1905 * If the target went to BUS FREE phase during 1905 * If the target went to BUS FREE phase during
1906 * or immediately after sending a SDTR or WDTR 1906 * or immediately after sending a SDTR or WDTR
1907 * message, disable negotiation. 1907 * message, disable negotiation.
1908 */ 1908 */
1909 periph = acb->xs->xs_periph; 1909 periph = acb->xs->xs_periph;
1910 ti = &sc->sc_tinfo[periph->periph_target]; 1910 ti = &sc->sc_tinfo[periph->periph_target];
1911 switch (sc->sc_lastmsg) { 1911 switch (sc->sc_lastmsg) {
1912#if AIC_USE_SYNCHRONOUS 1912#if AIC_USE_SYNCHRONOUS
1913 case SEND_SDTR: 1913 case SEND_SDTR:
1914 ti->flags &= ~DO_SYNC; 1914 ti->flags &= ~DO_SYNC;
1915 ti->period = ti->offset = 0; 1915 ti->period = ti->offset = 0;
1916 break; 1916 break;
1917#endif 1917#endif
1918#if AIC_USE_WIDE 1918#if AIC_USE_WIDE
1919 case SEND_WDTR: 1919 case SEND_WDTR:
1920 ti->flags &= ~DO_WIDE; 1920 ti->flags &= ~DO_WIDE;
1921 ti->width = 0; 1921 ti->width = 0;
1922 break; 1922 break;
1923#endif 1923#endif
1924 } 1924 }
1925 } 1925 }
1926#endif 1926#endif
1927 1927
1928 if ((sc->sc_flags & AIC_ABORTING) == 0) { 1928 if ((sc->sc_flags & AIC_ABORTING) == 0) {
1929 /* 1929 /*
1930 * Section 5.1.1 of the SCSI 2 spec suggests 1930 * Section 5.1.1 of the SCSI 2 spec suggests
1931 * issuing a REQUEST SENSE following an 1931 * issuing a REQUEST SENSE following an
1932 * unexpected disconnect. Some devices go into 1932 * unexpected disconnect. Some devices go into
1933 * a contingent allegiance condition when 1933 * a contingent allegiance condition when
1934 * disconnecting, and this is necessary to 1934 * disconnecting, and this is necessary to
1935 * clean up their state. 1935 * clean up their state.
1936 */ 1936 */
1937 aprint_error_dev(sc->sc_dev, 1937 aprint_error_dev(sc->sc_dev,
1938 "unexpected disconnect; " 1938 "unexpected disconnect; "
1939 "sending REQUEST SENSE\n"); 1939 "sending REQUEST SENSE\n");
1940 AIC_BREAK(); 1940 AIC_BREAK();
1941 aic_sense(sc, acb); 1941 aic_sense(sc, acb);
1942 goto out; 1942 goto out;
1943 } 1943 }
1944 1944
1945 acb->xs->error = XS_DRIVER_STUFFUP; 1945 acb->xs->error = XS_DRIVER_STUFFUP;
1946 goto finish; 1946 goto finish;
1947 1947
1948 case AIC_DISCONNECT: 1948 case AIC_DISCONNECT:
1949 AIC_ASSERT(sc->sc_nexus != NULL); 1949 AIC_ASSERT(sc->sc_nexus != NULL);
1950 acb = sc->sc_nexus; 1950 acb = sc->sc_nexus;
1951#if 1 /* XXXX */ 1951#if 1 /* XXXX */
1952 acb->data_addr = sc->sc_dp; 1952 acb->data_addr = sc->sc_dp;
1953 acb->data_length = sc->sc_dleft; 1953 acb->data_length = sc->sc_dleft;
1954#endif 1954#endif
1955 TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain); 1955 TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain);
1956 sc->sc_nexus = NULL; 1956 sc->sc_nexus = NULL;
1957 goto sched; 1957 goto sched;
1958 1958
1959 case AIC_CMDCOMPLETE: 1959 case AIC_CMDCOMPLETE:
1960 AIC_ASSERT(sc->sc_nexus != NULL); 1960 AIC_ASSERT(sc->sc_nexus != NULL);
1961 acb = sc->sc_nexus; 1961 acb = sc->sc_nexus;
1962 goto finish; 1962 goto finish;
1963 } 1963 }
1964 } 1964 }
1965 1965
1966 bus_space_write_1(iot, ioh, CLRSINT1, CLRPHASECHG); 1966 bus_space_write_1(iot, ioh, CLRSINT1, CLRPHASECHG);
1967 1967
1968dophase: 1968dophase:
1969 if ((sstat1 & REQINIT) == 0) { 1969 if ((sstat1 & REQINIT) == 0) {
1970 /* Wait for REQINIT. */ 1970 /* Wait for REQINIT. */
1971 goto out; 1971 goto out;
1972 } 1972 }
1973 1973
1974 sc->sc_phase = bus_space_read_1(iot, ioh, SCSISIG) & PH_MASK; 1974 sc->sc_phase = bus_space_read_1(iot, ioh, SCSISIG) & PH_MASK;
1975 bus_space_write_1(iot, ioh, SCSISIG, sc->sc_phase); 1975 bus_space_write_1(iot, ioh, SCSISIG, sc->sc_phase);
1976 1976
1977 switch (sc->sc_phase) { 1977 switch (sc->sc_phase) {
1978 case PH_MSGOUT: 1978 case PH_MSGOUT:
1979 if (sc->sc_state != AIC_CONNECTED && 1979 if (sc->sc_state != AIC_CONNECTED &&
1980 sc->sc_state != AIC_RESELECTED) 1980 sc->sc_state != AIC_RESELECTED)
1981 break; 1981 break;
1982 aic_msgout(sc); 1982 aic_msgout(sc);
1983 sc->sc_prevphase = PH_MSGOUT; 1983 sc->sc_prevphase = PH_MSGOUT;
1984 goto loop; 1984 goto loop;
1985 1985
1986 case PH_MSGIN: 1986 case PH_MSGIN:
1987 if (sc->sc_state != AIC_CONNECTED && 1987 if (sc->sc_state != AIC_CONNECTED &&
1988 sc->sc_state != AIC_RESELECTED) 1988 sc->sc_state != AIC_RESELECTED)
1989 break; 1989 break;
1990 aic_msgin(sc); 1990 aic_msgin(sc);
1991 sc->sc_prevphase = PH_MSGIN; 1991 sc->sc_prevphase = PH_MSGIN;
1992 goto loop; 1992 goto loop;
1993 1993
1994 case PH_CMD: 1994 case PH_CMD:
1995 if (sc->sc_state != AIC_CONNECTED) 1995 if (sc->sc_state != AIC_CONNECTED)
1996 break; 1996 break;
1997#if AIC_DEBUG 1997#if AIC_DEBUG
1998 if ((aic_debug & AIC_SHOWMISC) != 0) { 1998 if ((aic_debug & AIC_SHOWMISC) != 0) {
1999 AIC_ASSERT(sc->sc_nexus != NULL); 1999 AIC_ASSERT(sc->sc_nexus != NULL);
2000 acb = sc->sc_nexus; 2000 acb = sc->sc_nexus;
2001 printf("cmd=0x%02x+%d ", 2001 printf("cmd=0x%02x+%d ",
2002 acb->scsipi_cmd.opcode, acb->scsipi_cmd_length-1); 2002 acb->scsipi_cmd.opcode, acb->scsipi_cmd_length-1);
2003 } 2003 }
2004#endif 2004#endif
2005 n = aic_dataout_pio(sc, sc->sc_cp, sc->sc_cleft); 2005 n = aic_dataout_pio(sc, sc->sc_cp, sc->sc_cleft);
2006 sc->sc_cp += n; 2006 sc->sc_cp += n;
2007 sc->sc_cleft -= n; 2007 sc->sc_cleft -= n;
2008 sc->sc_prevphase = PH_CMD; 2008 sc->sc_prevphase = PH_CMD;
2009 goto loop; 2009 goto loop;
2010 2010
2011 case PH_DATAOUT: 2011 case PH_DATAOUT:
2012 if (sc->sc_state != AIC_CONNECTED) 2012 if (sc->sc_state != AIC_CONNECTED)
2013 break; 2013 break;
2014 AIC_MISC(("dataout %ld ", (long)sc->sc_dleft)); 2014 AIC_MISC(("dataout %ld ", (long)sc->sc_dleft));
2015 n = aic_dataout_pio(sc, sc->sc_dp, sc->sc_dleft); 2015 n = aic_dataout_pio(sc, sc->sc_dp, sc->sc_dleft);
2016 sc->sc_dp += n; 2016 sc->sc_dp += n;
2017 sc->sc_dleft -= n; 2017 sc->sc_dleft -= n;
2018 sc->sc_prevphase = PH_DATAOUT; 2018 sc->sc_prevphase = PH_DATAOUT;
2019 goto loop; 2019 goto loop;
2020 2020
2021 case PH_DATAIN: 2021 case PH_DATAIN:
2022 if (sc->sc_state != AIC_CONNECTED) 2022 if (sc->sc_state != AIC_CONNECTED)
2023 break; 2023 break;
2024 AIC_MISC(("datain %ld ", (long)sc->sc_dleft)); 2024 AIC_MISC(("datain %ld ", (long)sc->sc_dleft));
2025 n = aic_datain_pio(sc, sc->sc_dp, sc->sc_dleft); 2025 n = aic_datain_pio(sc, sc->sc_dp, sc->sc_dleft);
2026 sc->sc_dp += n; 2026 sc->sc_dp += n;
2027 sc->sc_dleft -= n; 2027 sc->sc_dleft -= n;
2028 sc->sc_prevphase = PH_DATAIN; 2028 sc->sc_prevphase = PH_DATAIN;
2029 goto loop; 2029 goto loop;
2030 2030
2031 case PH_STAT: 2031 case PH_STAT:
2032 if (sc->sc_state != AIC_CONNECTED) 2032 if (sc->sc_state != AIC_CONNECTED)
2033 break; 2033 break;
2034 AIC_ASSERT(sc->sc_nexus != NULL); 2034 AIC_ASSERT(sc->sc_nexus != NULL);
2035 acb = sc->sc_nexus; 2035 acb = sc->sc_nexus;
2036 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN); 2036 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN | SPIOEN);
2037 acb->target_stat = bus_space_read_1(iot, ioh, SCSIDAT); 2037 acb->target_stat = bus_space_read_1(iot, ioh, SCSIDAT);
2038 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN); 2038 bus_space_write_1(iot, ioh, SXFRCTL0, CHEN);
2039 AIC_MISC(("target_stat=0x%02x ", acb->target_stat)); 2039 AIC_MISC(("target_stat=0x%02x ", acb->target_stat));
2040 sc->sc_prevphase = PH_STAT; 2040 sc->sc_prevphase = PH_STAT;
2041 goto loop; 2041 goto loop;
2042 } 2042 }
2043 2043
2044 aprint_error_dev(sc->sc_dev, "unexpected bus phase; resetting\n"); 2044 aprint_error_dev(sc->sc_dev, "unexpected bus phase; resetting\n");
2045 AIC_BREAK(); 2045 AIC_BREAK();
2046reset: 2046reset:
2047 aic_init(sc, 1); 2047 aic_init(sc, 1);
2048 return 1; 2048 return 1;
2049 2049
2050finish: 2050finish:
2051 callout_stop(&acb->xs->xs_callout); 2051 callout_stop(&acb->xs->xs_callout);
2052 aic_done(sc, acb); 2052 aic_done(sc, acb);
2053 goto out; 2053 goto out;
2054 2054
2055sched: 2055sched:
2056 sc->sc_state = AIC_IDLE; 2056 sc->sc_state = AIC_IDLE;
2057 aic_sched(sc); 2057 aic_sched(sc);
2058 goto out; 2058 goto out;
2059 2059
2060out: 2060out:
2061 bus_space_write_1(iot, ioh, DMACNTRL0, INTEN); 2061 bus_space_write_1(iot, ioh, DMACNTRL0, INTEN);
2062 return 1; 2062 return 1;
2063} 2063}
2064 2064
2065static void 2065static void
2066aic_abort(struct aic_softc *sc, struct aic_acb *acb) 2066aic_abort(struct aic_softc *sc, struct aic_acb *acb)
2067{ 2067{
2068 2068
2069 /* 2 secs for the abort */ 2069 /* 2 secs for the abort */
2070 acb->timeout = AIC_ABORT_TIMEOUT; 2070 acb->timeout = AIC_ABORT_TIMEOUT;
2071 acb->flags |= ACB_ABORT; 2071 acb->flags |= ACB_ABORT;
2072 2072
2073 if (acb == sc->sc_nexus) { 2073 if (acb == sc->sc_nexus) {
2074 /* 2074 /*
2075 * If we're still selecting, the message will be scheduled 2075 * If we're still selecting, the message will be scheduled
2076 * after selection is complete. 2076 * after selection is complete.
2077 */ 2077 */
2078 if (sc->sc_state == AIC_CONNECTED) 2078 if (sc->sc_state == AIC_CONNECTED)
2079 aic_sched_msgout(sc, SEND_ABORT); 2079 aic_sched_msgout(sc, SEND_ABORT);
2080 } else { 2080 } else {
2081 aic_dequeue(sc, acb); 2081 aic_dequeue(sc, acb);
2082 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain); 2082 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
2083 if (sc->sc_state == AIC_IDLE) 2083 if (sc->sc_state == AIC_IDLE)
2084 aic_sched(sc); 2084 aic_sched(sc);
2085 } 2085 }
2086} 2086}
2087 2087
2088static void 2088static void
2089aic_timeout(void *arg) 2089aic_timeout(void *arg)
2090{ 2090{
2091 struct aic_acb *acb = arg; 2091 struct aic_acb *acb = arg;
2092 struct scsipi_xfer *xs = acb->xs; 2092 struct scsipi_xfer *xs = acb->xs;
2093 struct scsipi_periph *periph = xs->xs_periph; 2093 struct scsipi_periph *periph = xs->xs_periph;
2094 struct aic_softc *sc = 2094 struct aic_softc *sc =
2095 device_private(periph->periph_channel->chan_adapter->adapt_dev); 2095 device_private(periph->periph_channel->chan_adapter->adapt_dev);
2096 int s; 2096 int s;
2097 2097
2098 scsipi_printaddr(periph); 2098 scsipi_printaddr(periph);
2099 printf("timed out"); 2099 printf("timed out");
2100 2100
2101 s = splbio(); 2101 s = splbio();
2102 2102
2103 if (acb->flags & ACB_ABORT) { 2103 if (acb->flags & ACB_ABORT) {
2104 /* abort timed out */ 2104 /* abort timed out */
2105 printf(" AGAIN\n"); 2105 printf(" AGAIN\n");
2106 /* XXX Must reset! */ 2106 /* XXX Must reset! */
2107 } else { 2107 } else {
2108 /* abort the operation that has timed out */ 2108 /* abort the operation that has timed out */
2109 printf("\n"); 2109 printf("\n");
2110 acb->xs->error = XS_TIMEOUT; 2110 acb->xs->error = XS_TIMEOUT;
2111 aic_abort(sc, acb); 2111 aic_abort(sc, acb);
2112 } 2112 }
2113 2113
2114 splx(s); 2114 splx(s);
2115} 2115}
2116 2116
2117#ifdef AIC_DEBUG 2117#ifdef AIC_DEBUG
2118/* 2118/*
2119 * The following functions are mostly used for debugging purposes, either 2119 * The following functions are mostly used for debugging purposes, either
2120 * directly called from the driver or from the kernel debugger. 2120 * directly called from the driver or from the kernel debugger.
2121 */ 2121 */
2122 2122
2123static void 2123static void
2124aic_show_scsi_cmd(struct aic_acb *acb) 2124aic_show_scsi_cmd(struct aic_acb *acb)
2125{ 2125{
2126 u_char *b = (u_char *)&acb->scsipi_cmd; 2126 u_char *b = (u_char *)&acb->scsipi_cmd;
2127 struct scsipi_periph *periph = acb->xs->xs_periph; 2127 struct scsipi_periph *periph = acb->xs->xs_periph;
2128 int i; 2128 int i;
2129 2129
2130 scsipi_printaddr(periph); 2130 scsipi_printaddr(periph);
2131 if ((acb->xs->xs_control & XS_CTL_RESET) == 0) { 2131 if ((acb->xs->xs_control & XS_CTL_RESET) == 0) {
2132 for (i = 0; i < acb->scsipi_cmd_length; i++) { 2132 for (i = 0; i < acb->scsipi_cmd_length; i++) {
2133 if (i) 2133 if (i)
2134 printf(","); 2134 printf(",");
2135 printf("%x", b[i]); 2135 printf("%x", b[i]);
2136 } 2136 }
2137 printf("\n"); 2137 printf("\n");
2138 } else 2138 } else
2139 printf("RESET\n"); 2139 printf("RESET\n");
2140} 2140}
2141 2141
2142static void 2142static void
2143aic_print_acb(struct aic_acb *acb) 2143aic_print_acb(struct aic_acb *acb)
2144{ 2144{
2145 2145
2146 printf("acb@%p xs=%p flags=%x", acb, acb->xs, acb->flags); 2146 printf("acb@%p xs=%p flags=%x", acb, acb->xs, acb->flags);
2147 printf(" dp=%p dleft=%d target_stat=%x\n", 2147 printf(" dp=%p dleft=%d target_stat=%x\n",
2148 acb->data_addr, acb->data_length, acb->target_stat); 2148 acb->data_addr, acb->data_length, acb->target_stat);
2149 aic_show_scsi_cmd(acb); 2149 aic_show_scsi_cmd(acb);
2150} 2150}
2151 2151
2152void 2152void
2153aic_print_active_acb(void) 2153aic_print_active_acb(void)
2154{ 2154{
2155 struct aic_acb *acb; 2155 struct aic_acb *acb;
2156 struct aic_softc *sc = device_lookup_private(&aic_cd, 0); 2156 struct aic_softc *sc = device_lookup_private(&aic_cd, 0);
2157 2157
2158 printf("ready list:\n"); 2158 printf("ready list:\n");
2159 for (acb = sc->ready_list.tqh_first; acb != NULL; 2159 for (acb = sc->ready_list.tqh_first; acb != NULL;
2160 acb = acb->chain.tqe_next) 2160 acb = acb->chain.tqe_next)
2161 aic_print_acb(acb); 2161 aic_print_acb(acb);
2162 printf("nexus:\n"); 2162 printf("nexus:\n");
2163 if (sc->sc_nexus != NULL) 2163 if (sc->sc_nexus != NULL)
2164 aic_print_acb(sc->sc_nexus); 2164 aic_print_acb(sc->sc_nexus);
2165 printf("nexus list:\n"); 2165 printf("nexus list:\n");
2166 for (acb = sc->nexus_list.tqh_first; acb != NULL; 2166 for (acb = sc->nexus_list.tqh_first; acb != NULL;
2167 acb = acb->chain.tqe_next) 2167 acb = acb->chain.tqe_next)
2168 aic_print_acb(acb); 2168 aic_print_acb(acb);
2169} 2169}
2170 2170
2171void 2171void
2172aic_dump6360(struct aic_softc *sc) 2172aic_dump6360(struct aic_softc *sc)
2173{ 2173{
2174 bus_space_tag_t iot = sc->sc_iot; 2174 bus_space_tag_t iot = sc->sc_iot;
2175 bus_space_handle_t ioh = sc->sc_ioh; 2175 bus_space_handle_t ioh = sc->sc_ioh;
2176 2176
2177 printf("aic6360: SCSISEQ=%x SXFRCTL0=%x SXFRCTL1=%x SCSISIG=%x\n", 2177 printf("aic6360: SCSISEQ=%x SXFRCTL0=%x SXFRCTL1=%x SCSISIG=%x\n",
2178 bus_space_read_1(iot, ioh, SCSISEQ), 2178 bus_space_read_1(iot, ioh, SCSISEQ),
2179 bus_space_read_1(iot, ioh, SXFRCTL0), 2179 bus_space_read_1(iot, ioh, SXFRCTL0),
2180 bus_space_read_1(iot, ioh, SXFRCTL1), 2180 bus_space_read_1(iot, ioh, SXFRCTL1),
2181 bus_space_read_1(iot, ioh, SCSISIG)); 2181 bus_space_read_1(iot, ioh, SCSISIG));
2182 printf(" SSTAT0=%x SSTAT1=%x SSTAT2=%x SSTAT3=%x SSTAT4=%x\n", 2182 printf(" SSTAT0=%x SSTAT1=%x SSTAT2=%x SSTAT3=%x SSTAT4=%x\n",
2183 bus_space_read_1(iot, ioh, SSTAT0), 2183 bus_space_read_1(iot, ioh, SSTAT0),
2184 bus_space_read_1(iot, ioh, SSTAT1), 2184 bus_space_read_1(iot, ioh, SSTAT1),
2185 bus_space_read_1(iot, ioh, SSTAT2), 2185 bus_space_read_1(iot, ioh, SSTAT2),
2186 bus_space_read_1(iot, ioh, SSTAT3), 2186 bus_space_read_1(iot, ioh, SSTAT3),
2187 bus_space_read_1(iot, ioh, SSTAT4)); 2187 bus_space_read_1(iot, ioh, SSTAT4));
2188 printf(" SIMODE0=%x SIMODE1=%x DMACNTRL0=%x DMACNTRL1=%x " 2188 printf(" SIMODE0=%x SIMODE1=%x DMACNTRL0=%x DMACNTRL1=%x "
2189 "DMASTAT=%x\n", 2189 "DMASTAT=%x\n",
2190 bus_space_read_1(iot, ioh, SIMODE0), 2190 bus_space_read_1(iot, ioh, SIMODE0),
2191 bus_space_read_1(iot, ioh, SIMODE1), 2191 bus_space_read_1(iot, ioh, SIMODE1),
2192 bus_space_read_1(iot, ioh, DMACNTRL0), 2192 bus_space_read_1(iot, ioh, DMACNTRL0),
2193 bus_space_read_1(iot, ioh, DMACNTRL1), 2193 bus_space_read_1(iot, ioh, DMACNTRL1),
2194 bus_space_read_1(iot, ioh, DMASTAT)); 2194 bus_space_read_1(iot, ioh, DMASTAT));
2195 printf(" FIFOSTAT=%d SCSIBUS=0x%x\n", 2195 printf(" FIFOSTAT=%d SCSIBUS=0x%x\n",
2196 bus_space_read_1(iot, ioh, FIFOSTAT), 2196 bus_space_read_1(iot, ioh, FIFOSTAT),
2197 bus_space_read_1(iot, ioh, SCSIBUS)); 2197 bus_space_read_1(iot, ioh, SCSIBUS));
2198} 2198}
2199 2199
2200void 2200void
2201aic_dump_driver(struct aic_softc *sc) 2201aic_dump_driver(struct aic_softc *sc)
2202{ 2202{
2203 struct aic_tinfo *ti; 2203 struct aic_tinfo *ti;
2204 int i; 2204 int i;
2205 2205
2206 printf("nexus=%p prevphase=%x\n", sc->sc_nexus, sc->sc_prevphase); 2206 printf("nexus=%p prevphase=%x\n", sc->sc_nexus, sc->sc_prevphase);
2207 printf("state=%x msgin=%x msgpriq=%x msgoutq=%x lastmsg=%x " 2207 printf("state=%x msgin=%x msgpriq=%x msgoutq=%x lastmsg=%x "
2208 "currmsg=%x\n", 2208 "currmsg=%x\n",
2209 sc->sc_state, sc->sc_imess[0], 2209 sc->sc_state, sc->sc_imess[0],
2210 sc->sc_msgpriq, sc->sc_msgoutq, sc->sc_lastmsg, sc->sc_currmsg); 2210 sc->sc_msgpriq, sc->sc_msgoutq, sc->sc_lastmsg, sc->sc_currmsg);
2211 for (i = 0; i < 7; i++) { 2211 for (i = 0; i < 7; i++) {
2212 ti = &sc->sc_tinfo[i]; 2212 ti = &sc->sc_tinfo[i];
2213 printf("tinfo%d: %d cmds %d disconnects %d timeouts", 2213 printf("tinfo%d: %d cmds %d disconnects %d timeouts",
2214 i, ti->cmds, ti->dconns, ti->touts); 2214 i, ti->cmds, ti->dconns, ti->touts);
2215 printf(" %d senses flags=%x\n", ti->senses, ti->flags); 2215 printf(" %d senses flags=%x\n", ti->senses, ti->flags);
2216 } 2216 }
2217} 2217}
2218#endif 2218#endif