sbic.c revision 1.1.6.4 1 1.1.6.4 jdolecek /* $NetBSD: sbic.c,v 1.1.6.4 2002/10/10 18:30:31 jdolecek Exp $ */
2 1.1.6.2 thorpej
3 1.1.6.2 thorpej /*
4 1.1.6.2 thorpej * Copyright (c) 2001 Richard Earnshaw
5 1.1.6.2 thorpej * All rights reserved.
6 1.1.6.2 thorpej *
7 1.1.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
8 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer.
9 1.1.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
10 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
11 1.1.6.2 thorpej * documentation and/or other materials provided with the distribution.
12 1.1.6.2 thorpej * 3. The name of the company nor the name of the author may be used to
13 1.1.6.2 thorpej * endorse or promote products derived from this software without specific
14 1.1.6.2 thorpej * prior written permission.
15 1.1.6.2 thorpej *
16 1.1.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 1.1.6.2 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 1.1.6.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.6.2 thorpej * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 1.1.6.2 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1.6.2 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1.6.2 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1.6.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1.6.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1.6.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1.6.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
27 1.1.6.2 thorpej *
28 1.1.6.2 thorpej *
29 1.1.6.2 thorpej * Copyright (c) 1994 Christian E. Hopps
30 1.1.6.2 thorpej * Copyright (c) 1990 The Regents of the University of California.
31 1.1.6.2 thorpej * All rights reserved.
32 1.1.6.2 thorpej *
33 1.1.6.2 thorpej * This code is derived from software contributed to Berkeley by
34 1.1.6.2 thorpej * Van Jacobson of Lawrence Berkeley Laboratory.
35 1.1.6.2 thorpej *
36 1.1.6.2 thorpej * Redistribution and use in source and binary forms, with or without
37 1.1.6.2 thorpej * modification, are permitted provided that the following conditions
38 1.1.6.2 thorpej * are met:
39 1.1.6.2 thorpej * 1. Redistributions of source code must retain the above copyright
40 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer.
41 1.1.6.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
42 1.1.6.2 thorpej * notice, this list of conditions and the following disclaimer in the
43 1.1.6.2 thorpej * documentation and/or other materials provided with the distribution.
44 1.1.6.2 thorpej * 3. All advertising materials mentioning features or use of this software
45 1.1.6.2 thorpej * must display the following acknowledgement:
46 1.1.6.2 thorpej * This product includes software developed by the University of
47 1.1.6.2 thorpej * California, Berkeley and its contributors.
48 1.1.6.2 thorpej * 4. Neither the name of the University nor the names of its contributors
49 1.1.6.2 thorpej * may be used to endorse or promote products derived from this software
50 1.1.6.2 thorpej * without specific prior written permission.
51 1.1.6.2 thorpej *
52 1.1.6.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 1.1.6.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1.6.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1.6.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 1.1.6.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1.6.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1.6.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1.6.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1.6.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1.6.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1.6.2 thorpej * SUCH DAMAGE.
63 1.1.6.2 thorpej *
64 1.1.6.2 thorpej * from: sbic.c,v 1.21 1996/01/07 22:01:54
65 1.1.6.2 thorpej */
66 1.1.6.2 thorpej
67 1.1.6.2 thorpej /*
68 1.1.6.2 thorpej * WD 33C93 scsi adaptor driver
69 1.1.6.2 thorpej */
70 1.1.6.2 thorpej
71 1.1.6.2 thorpej #if 0
72 1.1.6.2 thorpej /*
73 1.1.6.2 thorpej * The UPROTECTED_CSR code is bogus. It can read the csr (SCSI Status
74 1.1.6.2 thorpej * register) at times when an interrupt may be pending. Doing this will
75 1.1.6.2 thorpej * clear the interrupt, so we won't see it at times when we really need
76 1.1.6.2 thorpej * to.
77 1.1.6.2 thorpej */
78 1.1.6.2 thorpej #define UNPROTECTED_CSR
79 1.1.6.2 thorpej #endif
80 1.1.6.2 thorpej
81 1.1.6.2 thorpej #define DEBUG
82 1.1.6.2 thorpej /* #define SBIC_DEBUG(a) a */
83 1.1.6.2 thorpej
84 1.1.6.2 thorpej #include "opt_ddb.h"
85 1.1.6.2 thorpej
86 1.1.6.2 thorpej #include <sys/param.h>
87 1.1.6.3 jdolecek
88 1.1.6.4 jdolecek __KERNEL_RCSID(0, "$NetBSD: sbic.c,v 1.1.6.4 2002/10/10 18:30:31 jdolecek Exp $");
89 1.1.6.3 jdolecek
90 1.1.6.2 thorpej #include <sys/systm.h>
91 1.1.6.2 thorpej #include <sys/callout.h>
92 1.1.6.2 thorpej #include <sys/kernel.h> /* For hz */
93 1.1.6.2 thorpej #include <sys/device.h>
94 1.1.6.2 thorpej #include <sys/buf.h>
95 1.1.6.2 thorpej
96 1.1.6.2 thorpej #include <uvm/uvm_extern.h>
97 1.1.6.2 thorpej
98 1.1.6.2 thorpej #include <machine/bus.h>
99 1.1.6.2 thorpej #include <machine/intr.h>
100 1.1.6.2 thorpej
101 1.1.6.2 thorpej #include <dev/scsipi/scsi_all.h>
102 1.1.6.2 thorpej #include <dev/scsipi/scsipi_all.h>
103 1.1.6.2 thorpej #include <dev/scsipi/scsiconf.h>
104 1.1.6.2 thorpej
105 1.1.6.2 thorpej #include <acorn32/podulebus/sbicreg.h>
106 1.1.6.2 thorpej #include <acorn32/podulebus/sbicvar.h>
107 1.1.6.2 thorpej
108 1.1.6.2 thorpej /*
109 1.1.6.2 thorpej * SCSI delays
110 1.1.6.2 thorpej * In u-seconds, primarily for state changes on the SPC.
111 1.1.6.2 thorpej */
112 1.1.6.2 thorpej #define SBIC_CMD_WAIT 50000 /* wait per step of 'immediate' cmds */
113 1.1.6.2 thorpej #define SBIC_DATA_WAIT 50000 /* wait per data in/out step */
114 1.1.6.2 thorpej #define SBIC_INIT_WAIT 50000 /* wait per step (both) during init */
115 1.1.6.2 thorpej
116 1.1.6.2 thorpej #define SBIC_WAIT(regs, until, timeo) sbicwait(regs, until, timeo, __LINE__)
117 1.1.6.2 thorpej
118 1.1.6.2 thorpej static int sbicicmd (struct sbic_softc *, int, int,
119 1.1.6.2 thorpej struct sbic_acb *);
120 1.1.6.2 thorpej static int sbicgo (struct sbic_softc *, struct scsipi_xfer *);
121 1.1.6.2 thorpej static int sbicwait (sbic_regmap_p, char, int , int);
122 1.1.6.2 thorpej static int sbicselectbus (struct sbic_softc *, sbic_regmap_p, u_char,
123 1.1.6.2 thorpej u_char, u_char);
124 1.1.6.2 thorpej static int sbicxfstart (sbic_regmap_p, int, u_char, int);
125 1.1.6.2 thorpej static int sbicxfout (sbic_regmap_p regs, int, void *, int);
126 1.1.6.2 thorpej static int sbicfromscsiperiod (struct sbic_softc *, sbic_regmap_p, int);
127 1.1.6.2 thorpej static int sbictoscsiperiod (struct sbic_softc *, sbic_regmap_p, int);
128 1.1.6.2 thorpej static int sbicpoll (struct sbic_softc *);
129 1.1.6.2 thorpej static int sbicnextstate (struct sbic_softc *, u_char, u_char);
130 1.1.6.2 thorpej static int sbicmsgin (struct sbic_softc *);
131 1.1.6.2 thorpej static int sbicxfin (sbic_regmap_p regs, int, void *);
132 1.1.6.2 thorpej static int sbicabort (struct sbic_softc *, sbic_regmap_p, char *);
133 1.1.6.2 thorpej static void sbicxfdone (struct sbic_softc *, sbic_regmap_p, int);
134 1.1.6.2 thorpej static void sbicerror (struct sbic_softc *, sbic_regmap_p, u_char);
135 1.1.6.2 thorpej static void sbicreset (struct sbic_softc *);
136 1.1.6.2 thorpej static void sbic_scsidone (struct sbic_acb *, int);
137 1.1.6.2 thorpej static void sbic_sched (struct sbic_softc *);
138 1.1.6.2 thorpej static void sbic_save_ptrs (struct sbic_softc *, sbic_regmap_p);
139 1.1.6.2 thorpej
140 1.1.6.2 thorpej /*
141 1.1.6.2 thorpej * Synch xfer parameters, and timing conversions
142 1.1.6.2 thorpej */
143 1.1.6.2 thorpej int sbic_min_period = SBIC_SYN_MIN_PERIOD; /* in cycles = f(ICLK,FSn) */
144 1.1.6.2 thorpej int sbic_max_offset = SBIC_SYN_MAX_OFFSET; /* pure number */
145 1.1.6.2 thorpej
146 1.1.6.2 thorpej int sbic_cmd_wait = SBIC_CMD_WAIT;
147 1.1.6.2 thorpej int sbic_data_wait = SBIC_DATA_WAIT;
148 1.1.6.2 thorpej int sbic_init_wait = SBIC_INIT_WAIT;
149 1.1.6.2 thorpej
150 1.1.6.2 thorpej /*
151 1.1.6.2 thorpej * was broken before.. now if you want this you get it for all drives
152 1.1.6.2 thorpej * on sbic controllers.
153 1.1.6.2 thorpej */
154 1.1.6.2 thorpej u_char sbic_inhibit_sync[8];
155 1.1.6.2 thorpej int sbic_enable_reselect = 1;
156 1.1.6.2 thorpej int sbic_clock_override = 0;
157 1.1.6.2 thorpej int sbic_no_dma = 1; /* was 0 */
158 1.1.6.2 thorpej int sbic_parallel_operations = 1;
159 1.1.6.2 thorpej
160 1.1.6.2 thorpej #ifdef DEBUG
161 1.1.6.2 thorpej sbic_regmap_p debug_sbic_regs;
162 1.1.6.2 thorpej int sbicdma_ops = 0; /* total DMA operations */
163 1.1.6.2 thorpej int sbicdma_saves = 0;
164 1.1.6.2 thorpej #define QPRINTF(a) if (sbic_debug > 1) printf a
165 1.1.6.2 thorpej #define DBGPRINTF(x,p) if (p) printf x
166 1.1.6.2 thorpej #define DBG(x) x
167 1.1.6.2 thorpej int sbic_debug = 0;
168 1.1.6.2 thorpej int sync_debug = 0;
169 1.1.6.2 thorpej int sbic_dma_debug = 0;
170 1.1.6.2 thorpej int reselect_debug = 0;
171 1.1.6.2 thorpej int data_pointer_debug = 0;
172 1.1.6.2 thorpej u_char debug_asr, debug_csr, routine;
173 1.1.6.2 thorpej
174 1.1.6.3 jdolecek void sbicdumpstate (void);
175 1.1.6.2 thorpej void sbictimeout (struct sbic_softc *);
176 1.1.6.2 thorpej void sbic_dump (struct sbic_softc *);
177 1.1.6.2 thorpej void sbic_dump_acb (struct sbic_acb *);
178 1.1.6.2 thorpej
179 1.1.6.2 thorpej #define CSR_TRACE_SIZE 32
180 1.1.6.2 thorpej #if CSR_TRACE_SIZE
181 1.1.6.2 thorpej #define CSR_TRACE(w,c,a,x) do { \
182 1.1.6.2 thorpej int s = splbio(); \
183 1.1.6.2 thorpej csr_trace[csr_traceptr].whr = (w); csr_trace[csr_traceptr].csr = (c); \
184 1.1.6.2 thorpej csr_trace[csr_traceptr].asr = (a); csr_trace[csr_traceptr].xtn = (x); \
185 1.1.6.2 thorpej csr_traceptr = (csr_traceptr + 1) & (CSR_TRACE_SIZE - 1); \
186 1.1.6.2 thorpej splx(s); \
187 1.1.6.2 thorpej } while (0)
188 1.1.6.2 thorpej int csr_traceptr;
189 1.1.6.2 thorpej int csr_tracesize = CSR_TRACE_SIZE;
190 1.1.6.2 thorpej struct {
191 1.1.6.2 thorpej u_char whr;
192 1.1.6.2 thorpej u_char csr;
193 1.1.6.2 thorpej u_char asr;
194 1.1.6.2 thorpej u_char xtn;
195 1.1.6.2 thorpej } csr_trace[CSR_TRACE_SIZE];
196 1.1.6.2 thorpej #else
197 1.1.6.2 thorpej #define CSR_TRACE
198 1.1.6.2 thorpej #endif
199 1.1.6.2 thorpej
200 1.1.6.2 thorpej #define SBIC_TRACE_SIZE 0
201 1.1.6.2 thorpej #if SBIC_TRACE_SIZE
202 1.1.6.2 thorpej #define SBIC_TRACE(dev) do { \
203 1.1.6.2 thorpej int s = splbio(); \
204 1.1.6.2 thorpej sbic_trace[sbic_traceptr].sp = &s; \
205 1.1.6.2 thorpej sbic_trace[sbic_traceptr].line = __LINE__; \
206 1.1.6.2 thorpej sbic_trace[sbic_traceptr].sr = s; \
207 1.1.6.2 thorpej sbic_trace[sbic_traceptr].csr = csr_traceptr; \
208 1.1.6.2 thorpej sbic_traceptr = (sbic_traceptr + 1) & (SBIC_TRACE_SIZE - 1); \
209 1.1.6.2 thorpej splx(s); \
210 1.1.6.2 thorpej } while (0)
211 1.1.6.2 thorpej int sbic_traceptr;
212 1.1.6.2 thorpej int sbic_tracesize = SBIC_TRACE_SIZE;
213 1.1.6.2 thorpej struct {
214 1.1.6.2 thorpej void *sp;
215 1.1.6.2 thorpej u_short line;
216 1.1.6.2 thorpej u_short sr;
217 1.1.6.2 thorpej int csr;
218 1.1.6.2 thorpej } sbic_trace[SBIC_TRACE_SIZE];
219 1.1.6.2 thorpej #else
220 1.1.6.2 thorpej #define SBIC_TRACE(dev)
221 1.1.6.2 thorpej #endif
222 1.1.6.2 thorpej
223 1.1.6.2 thorpej #else
224 1.1.6.2 thorpej #define QPRINTF(a)
225 1.1.6.2 thorpej #define DBGPRINTF(x,p)
226 1.1.6.2 thorpej #define DBG(x)
227 1.1.6.2 thorpej #define CSR_TRACE
228 1.1.6.2 thorpej #define SBIC_TRACE
229 1.1.6.2 thorpej #endif
230 1.1.6.2 thorpej
231 1.1.6.2 thorpej #ifndef SBIC_DEBUG
232 1.1.6.2 thorpej #define SBIC_DEBUG(x)
233 1.1.6.2 thorpej #endif
234 1.1.6.2 thorpej
235 1.1.6.2 thorpej /*
236 1.1.6.2 thorpej * default minphys routine for sbic based controllers
237 1.1.6.2 thorpej */
238 1.1.6.2 thorpej void
239 1.1.6.2 thorpej sbic_minphys(struct buf *bp)
240 1.1.6.2 thorpej {
241 1.1.6.2 thorpej /*
242 1.1.6.2 thorpej * No max transfer at this level.
243 1.1.6.2 thorpej */
244 1.1.6.2 thorpej minphys(bp);
245 1.1.6.2 thorpej }
246 1.1.6.2 thorpej
247 1.1.6.2 thorpej /*
248 1.1.6.2 thorpej * Save DMA pointers. Take into account partial transfer. Shut down DMA.
249 1.1.6.2 thorpej */
250 1.1.6.2 thorpej static void
251 1.1.6.2 thorpej sbic_save_ptrs(struct sbic_softc *dev, sbic_regmap_p regs)
252 1.1.6.2 thorpej {
253 1.1.6.2 thorpej int count, asr, s;
254 1.1.6.2 thorpej struct sbic_acb* acb;
255 1.1.6.2 thorpej
256 1.1.6.2 thorpej SBIC_TRACE(dev);
257 1.1.6.2 thorpej if (!(dev->sc_flags & SBICF_INDMA))
258 1.1.6.2 thorpej return; /* DMA not active */
259 1.1.6.2 thorpej
260 1.1.6.2 thorpej s = splbio();
261 1.1.6.2 thorpej
262 1.1.6.2 thorpej acb = dev->sc_nexus;
263 1.1.6.2 thorpej if (acb == NULL) {
264 1.1.6.2 thorpej splx(s);
265 1.1.6.2 thorpej return;
266 1.1.6.2 thorpej }
267 1.1.6.2 thorpej count = -1;
268 1.1.6.2 thorpej do {
269 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
270 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR) {
271 1.1.6.2 thorpej printf("sbic_save_ptrs: asr %02x canceled!\n", asr);
272 1.1.6.2 thorpej splx(s);
273 1.1.6.2 thorpej SBIC_TRACE(dev);
274 1.1.6.2 thorpej return;
275 1.1.6.2 thorpej }
276 1.1.6.2 thorpej } while (asr & (SBIC_ASR_BSY | SBIC_ASR_CIP));
277 1.1.6.2 thorpej
278 1.1.6.2 thorpej /* Save important state */
279 1.1.6.2 thorpej /* must be done before dmastop */
280 1.1.6.2 thorpej SBIC_TC_GET(regs, count);
281 1.1.6.2 thorpej
282 1.1.6.2 thorpej /* Shut down DMA ====CAREFUL==== */
283 1.1.6.2 thorpej dev->sc_dmastop(dev->sc_dmah, dev->sc_dmat, acb);
284 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_INDMA;
285 1.1.6.2 thorpej #ifdef DIAGNOSTIC
286 1.1.6.2 thorpej {
287 1.1.6.2 thorpej int count2;
288 1.1.6.2 thorpej
289 1.1.6.2 thorpej SBIC_TC_GET(regs, count2);
290 1.1.6.2 thorpej if (count2 != count)
291 1.1.6.2 thorpej panic("sbic_save_ptrs: DMA was still active(%d,%d)",
292 1.1.6.2 thorpej count, count2);
293 1.1.6.2 thorpej }
294 1.1.6.2 thorpej #endif
295 1.1.6.2 thorpej /* Note where we got to before stopping. We need this to resume
296 1.1.6.2 thorpej later. */
297 1.1.6.2 thorpej acb->offset += acb->sc_tcnt - count;
298 1.1.6.2 thorpej SBIC_TC_PUT(regs, 0);
299 1.1.6.2 thorpej
300 1.1.6.2 thorpej DBGPRINTF(("SBIC saving tgt %d data pointers: Offset now %d ASR:%02x",
301 1.1.6.2 thorpej dev->target, acb->offset, asr), data_pointer_debug >= 1);
302 1.1.6.2 thorpej
303 1.1.6.2 thorpej acb->sc_tcnt = 0;
304 1.1.6.2 thorpej
305 1.1.6.2 thorpej DBG(sbicdma_saves++);
306 1.1.6.2 thorpej splx(s);
307 1.1.6.2 thorpej SBIC_TRACE(dev);
308 1.1.6.2 thorpej }
309 1.1.6.2 thorpej
310 1.1.6.2 thorpej /*
311 1.1.6.2 thorpej * used by specific sbic controller
312 1.1.6.2 thorpej *
313 1.1.6.2 thorpej * it appears that the higher level code does nothing with LUN's
314 1.1.6.2 thorpej * so I will too. I could plug it in, however so could they
315 1.1.6.2 thorpej * in scsi_scsi_cmd().
316 1.1.6.2 thorpej */
317 1.1.6.2 thorpej void
318 1.1.6.2 thorpej sbic_scsi_request(struct scsipi_channel *chan,
319 1.1.6.2 thorpej scsipi_adapter_req_t req, void *arg)
320 1.1.6.2 thorpej {
321 1.1.6.2 thorpej struct scsipi_xfer *xs;
322 1.1.6.2 thorpej struct sbic_acb *acb;
323 1.1.6.2 thorpej struct sbic_softc *dev = (void *)chan->chan_adapter->adapt_dev;
324 1.1.6.2 thorpej struct scsipi_periph *periph;
325 1.1.6.2 thorpej int flags, s, stat;
326 1.1.6.2 thorpej
327 1.1.6.2 thorpej switch (req) {
328 1.1.6.2 thorpej case ADAPTER_REQ_RUN_XFER:
329 1.1.6.2 thorpej xs = arg;
330 1.1.6.2 thorpej periph = xs->xs_periph;
331 1.1.6.2 thorpej SBIC_TRACE(dev);
332 1.1.6.2 thorpej flags = xs->xs_control;
333 1.1.6.2 thorpej
334 1.1.6.2 thorpej if (flags & XS_CTL_DATA_UIO)
335 1.1.6.2 thorpej panic("sbic: scsi data uio requested");
336 1.1.6.2 thorpej
337 1.1.6.2 thorpej if (dev->sc_nexus && (flags & XS_CTL_POLL))
338 1.1.6.2 thorpej panic("sbic_scsicmd: busy");
339 1.1.6.2 thorpej
340 1.1.6.2 thorpej s = splbio();
341 1.1.6.2 thorpej acb = dev->free_list.tqh_first;
342 1.1.6.2 thorpej if (acb)
343 1.1.6.2 thorpej TAILQ_REMOVE(&dev->free_list, acb, chain);
344 1.1.6.2 thorpej splx(s);
345 1.1.6.2 thorpej
346 1.1.6.2 thorpej if (acb == NULL) {
347 1.1.6.2 thorpej DBG(printf("sbic_scsicmd: unable to queue request for "
348 1.1.6.2 thorpej "target %d\n", periph->periph_target));
349 1.1.6.2 thorpej #if defined(DDB) && defined(DEBUG)
350 1.1.6.2 thorpej Debugger();
351 1.1.6.2 thorpej #endif
352 1.1.6.2 thorpej xs->error = XS_RESOURCE_SHORTAGE;
353 1.1.6.2 thorpej SBIC_TRACE(dev);
354 1.1.6.2 thorpej scsipi_done(xs);
355 1.1.6.2 thorpej return;
356 1.1.6.2 thorpej }
357 1.1.6.2 thorpej
358 1.1.6.2 thorpej acb->flags = ACB_ACTIVE;
359 1.1.6.2 thorpej if (flags & XS_CTL_DATA_IN)
360 1.1.6.2 thorpej acb->flags |= ACB_DATAIN;
361 1.1.6.2 thorpej acb->xs = xs;
362 1.1.6.2 thorpej memcpy(&acb->cmd, xs->cmd, xs->cmdlen);
363 1.1.6.2 thorpej acb->clen = xs->cmdlen;
364 1.1.6.2 thorpej acb->data = xs->data;
365 1.1.6.2 thorpej acb->datalen = xs->datalen;
366 1.1.6.2 thorpej
367 1.1.6.2 thorpej QPRINTF(("sbic_scsi_request: Cmd %02x (len %d), Data %p(%d)\n",
368 1.1.6.2 thorpej (unsigned) acb->cmd.opcode, acb->clen, xs->data,
369 1.1.6.2 thorpej xs->datalen));
370 1.1.6.2 thorpej if (flags & XS_CTL_POLL) {
371 1.1.6.2 thorpej s = splbio();
372 1.1.6.2 thorpej /*
373 1.1.6.2 thorpej * This has major side effects -- it locks up the
374 1.1.6.2 thorpej * machine.
375 1.1.6.2 thorpej */
376 1.1.6.2 thorpej
377 1.1.6.2 thorpej dev->sc_flags |= SBICF_ICMD;
378 1.1.6.2 thorpej do {
379 1.1.6.2 thorpej while (dev->sc_nexus)
380 1.1.6.2 thorpej sbicpoll(dev);
381 1.1.6.2 thorpej dev->sc_nexus = acb;
382 1.1.6.2 thorpej dev->sc_stat[0] = -1;
383 1.1.6.2 thorpej dev->target = periph->periph_target;
384 1.1.6.2 thorpej dev->lun = periph->periph_lun;
385 1.1.6.2 thorpej stat = sbicicmd(dev, periph->periph_target,
386 1.1.6.2 thorpej periph->periph_lun, acb);
387 1.1.6.2 thorpej } while (dev->sc_nexus != acb);
388 1.1.6.2 thorpej
389 1.1.6.2 thorpej sbic_scsidone(acb, stat);
390 1.1.6.2 thorpej splx(s);
391 1.1.6.2 thorpej SBIC_TRACE(dev);
392 1.1.6.2 thorpej return;
393 1.1.6.2 thorpej }
394 1.1.6.2 thorpej
395 1.1.6.2 thorpej s = splbio();
396 1.1.6.2 thorpej TAILQ_INSERT_TAIL(&dev->ready_list, acb, chain);
397 1.1.6.2 thorpej
398 1.1.6.2 thorpej if (dev->sc_nexus) {
399 1.1.6.2 thorpej splx(s);
400 1.1.6.2 thorpej SBIC_TRACE(dev);
401 1.1.6.2 thorpej return;
402 1.1.6.2 thorpej }
403 1.1.6.2 thorpej
404 1.1.6.2 thorpej /*
405 1.1.6.2 thorpej * Nothing is active, try to start it now.
406 1.1.6.2 thorpej */
407 1.1.6.2 thorpej sbic_sched(dev);
408 1.1.6.2 thorpej splx(s);
409 1.1.6.2 thorpej
410 1.1.6.2 thorpej SBIC_TRACE(dev);
411 1.1.6.2 thorpej /* TODO: add sbic_poll to do XS_CTL_POLL operations */
412 1.1.6.2 thorpej return;
413 1.1.6.2 thorpej
414 1.1.6.2 thorpej case ADAPTER_REQ_GROW_RESOURCES:
415 1.1.6.2 thorpej case ADAPTER_REQ_SET_XFER_MODE:
416 1.1.6.2 thorpej /* XXX Not supported. */
417 1.1.6.2 thorpej return;
418 1.1.6.2 thorpej }
419 1.1.6.2 thorpej }
420 1.1.6.2 thorpej
421 1.1.6.2 thorpej /*
422 1.1.6.2 thorpej * attempt to start the next available command
423 1.1.6.2 thorpej */
424 1.1.6.2 thorpej static void
425 1.1.6.2 thorpej sbic_sched(struct sbic_softc *dev)
426 1.1.6.2 thorpej {
427 1.1.6.2 thorpej struct scsipi_xfer *xs;
428 1.1.6.2 thorpej struct scsipi_periph *periph;
429 1.1.6.2 thorpej struct sbic_acb *acb;
430 1.1.6.2 thorpej int flags, /*phase,*/ stat, i;
431 1.1.6.2 thorpej
432 1.1.6.2 thorpej SBIC_TRACE(dev);
433 1.1.6.2 thorpej if (dev->sc_nexus)
434 1.1.6.2 thorpej return; /* a command is current active */
435 1.1.6.2 thorpej
436 1.1.6.2 thorpej SBIC_TRACE(dev);
437 1.1.6.2 thorpej for (acb = dev->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
438 1.1.6.2 thorpej periph = acb->xs->xs_periph;
439 1.1.6.2 thorpej i = periph->periph_target;
440 1.1.6.2 thorpej if (!(dev->sc_tinfo[i].lubusy & (1 << periph->periph_lun))) {
441 1.1.6.2 thorpej struct sbic_tinfo *ti = &dev->sc_tinfo[i];
442 1.1.6.2 thorpej
443 1.1.6.2 thorpej TAILQ_REMOVE(&dev->ready_list, acb, chain);
444 1.1.6.2 thorpej dev->sc_nexus = acb;
445 1.1.6.2 thorpej periph = acb->xs->xs_periph;
446 1.1.6.2 thorpej ti = &dev->sc_tinfo[periph->periph_target];
447 1.1.6.2 thorpej ti->lubusy |= (1 << periph->periph_lun);
448 1.1.6.2 thorpej break;
449 1.1.6.2 thorpej }
450 1.1.6.2 thorpej }
451 1.1.6.2 thorpej
452 1.1.6.2 thorpej SBIC_TRACE(dev);
453 1.1.6.2 thorpej if (acb == NULL)
454 1.1.6.2 thorpej return; /* did not find an available command */
455 1.1.6.2 thorpej
456 1.1.6.2 thorpej xs = acb->xs;
457 1.1.6.2 thorpej periph = xs->xs_periph;
458 1.1.6.2 thorpej flags = xs->xs_control;
459 1.1.6.2 thorpej
460 1.1.6.2 thorpej if (flags & XS_CTL_RESET)
461 1.1.6.2 thorpej sbicreset(dev);
462 1.1.6.2 thorpej
463 1.1.6.2 thorpej DBGPRINTF(("sbic_sched(%d,%d)\n", periph->periph_target,
464 1.1.6.2 thorpej periph->periph_lun), data_pointer_debug > 1);
465 1.1.6.2 thorpej DBG(if (data_pointer_debug > 1) sbic_dump_acb(acb));
466 1.1.6.2 thorpej dev->sc_stat[0] = -1;
467 1.1.6.2 thorpej dev->target = periph->periph_target;
468 1.1.6.2 thorpej dev->lun = periph->periph_lun;
469 1.1.6.2 thorpej
470 1.1.6.2 thorpej /* Decide if we can use DMA for this transfer. */
471 1.1.6.2 thorpej if ((flags & XS_CTL_POLL) == 0
472 1.1.6.2 thorpej && !sbic_no_dma
473 1.1.6.2 thorpej && dev->sc_dmaok(dev->sc_dmah, dev->sc_dmat, acb))
474 1.1.6.2 thorpej acb->flags |= ACB_DMA;
475 1.1.6.2 thorpej
476 1.1.6.2 thorpej if ((flags & XS_CTL_POLL) ||
477 1.1.6.2 thorpej (!sbic_parallel_operations && (acb->flags & ACB_DMA) == 0))
478 1.1.6.2 thorpej stat = sbicicmd(dev, periph->periph_target,
479 1.1.6.2 thorpej periph->periph_lun, acb);
480 1.1.6.2 thorpej else if (sbicgo(dev, xs) == 0 && xs->error != XS_SELTIMEOUT) {
481 1.1.6.2 thorpej SBIC_TRACE(dev);
482 1.1.6.2 thorpej return;
483 1.1.6.2 thorpej } else
484 1.1.6.2 thorpej stat = dev->sc_stat[0];
485 1.1.6.2 thorpej
486 1.1.6.2 thorpej sbic_scsidone(acb, stat);
487 1.1.6.2 thorpej SBIC_TRACE(dev);
488 1.1.6.2 thorpej }
489 1.1.6.2 thorpej
490 1.1.6.2 thorpej static void
491 1.1.6.2 thorpej sbic_scsidone(struct sbic_acb *acb, int stat)
492 1.1.6.2 thorpej {
493 1.1.6.2 thorpej struct scsipi_xfer *xs;
494 1.1.6.2 thorpej struct scsipi_periph *periph;
495 1.1.6.2 thorpej struct sbic_softc *dev;
496 1.1.6.2 thorpej /* int s;*/
497 1.1.6.2 thorpej int dosched = 0;
498 1.1.6.2 thorpej
499 1.1.6.2 thorpej xs = acb->xs;
500 1.1.6.2 thorpej periph = xs->xs_periph;
501 1.1.6.2 thorpej dev = (void *)periph->periph_channel->chan_adapter->adapt_dev;
502 1.1.6.2 thorpej SBIC_TRACE(dev);
503 1.1.6.2 thorpej #ifdef DIAGNOSTIC
504 1.1.6.2 thorpej if (acb == NULL || xs == NULL) {
505 1.1.6.2 thorpej printf("sbic_scsidone -- (%d,%d) no scsipi_xfer\n",
506 1.1.6.2 thorpej dev->target, dev->lun);
507 1.1.6.2 thorpej #ifdef DDB
508 1.1.6.2 thorpej Debugger();
509 1.1.6.2 thorpej #endif
510 1.1.6.2 thorpej return;
511 1.1.6.2 thorpej }
512 1.1.6.2 thorpej #endif
513 1.1.6.2 thorpej
514 1.1.6.2 thorpej DBGPRINTF(("scsidone: (%d,%d)->(%d,%d)%02x acbfl=%x\n",
515 1.1.6.2 thorpej periph->periph_target, periph->periph_lun,
516 1.1.6.2 thorpej dev->target, dev->lun, stat, acb->flags),
517 1.1.6.2 thorpej data_pointer_debug > 1);
518 1.1.6.2 thorpej DBG(if (xs->xs_periph->periph_target == dev->sc_channel.chan_id)
519 1.1.6.2 thorpej panic("target == hostid"));
520 1.1.6.2 thorpej
521 1.1.6.2 thorpej xs->status = stat;
522 1.1.6.2 thorpej xs->resid = 0;
523 1.1.6.2 thorpej if (xs->error == XS_NOERROR) {
524 1.1.6.2 thorpej if (stat == SCSI_CHECK || stat == SCSI_BUSY)
525 1.1.6.2 thorpej xs->error = XS_BUSY;
526 1.1.6.2 thorpej }
527 1.1.6.2 thorpej
528 1.1.6.2 thorpej /*
529 1.1.6.2 thorpej * Remove the ACB from whatever queue it's on. We have to do a bit of
530 1.1.6.2 thorpej * a hack to figure out which queue it's on. Note that it is *not*
531 1.1.6.2 thorpej * necessary to cdr down the ready queue, but we must cdr down the
532 1.1.6.2 thorpej * nexus queue and see if it's there, so we can mark the unit as no
533 1.1.6.2 thorpej * longer busy. This code is sickening, but it works.
534 1.1.6.2 thorpej */
535 1.1.6.2 thorpej if (acb == dev->sc_nexus) {
536 1.1.6.2 thorpej dev->sc_nexus = NULL;
537 1.1.6.2 thorpej dev->sc_tinfo[periph->periph_target].lubusy &=
538 1.1.6.2 thorpej ~(1 << periph->periph_lun);
539 1.1.6.2 thorpej if (dev->ready_list.tqh_first)
540 1.1.6.2 thorpej dosched = 1; /* start next command */
541 1.1.6.2 thorpej } else if (dev->ready_list.tqh_last == &acb->chain.tqe_next) {
542 1.1.6.2 thorpej TAILQ_REMOVE(&dev->ready_list, acb, chain);
543 1.1.6.2 thorpej } else {
544 1.1.6.2 thorpej register struct sbic_acb *acb2;
545 1.1.6.2 thorpej for (acb2 = dev->nexus_list.tqh_first; acb2;
546 1.1.6.2 thorpej acb2 = acb2->chain.tqe_next) {
547 1.1.6.2 thorpej if (acb2 == acb) {
548 1.1.6.2 thorpej TAILQ_REMOVE(&dev->nexus_list, acb, chain);
549 1.1.6.2 thorpej dev->sc_tinfo[periph->periph_target].lubusy
550 1.1.6.2 thorpej &= ~(1 << periph->periph_lun);
551 1.1.6.2 thorpej break;
552 1.1.6.2 thorpej }
553 1.1.6.2 thorpej }
554 1.1.6.2 thorpej if (acb2)
555 1.1.6.2 thorpej ;
556 1.1.6.2 thorpej else if (acb->chain.tqe_next) {
557 1.1.6.2 thorpej TAILQ_REMOVE(&dev->ready_list, acb, chain);
558 1.1.6.2 thorpej } else {
559 1.1.6.2 thorpej printf("%s: can't find matching acb\n",
560 1.1.6.2 thorpej dev->sc_dev.dv_xname);
561 1.1.6.2 thorpej #ifdef DDB
562 1.1.6.2 thorpej Debugger();
563 1.1.6.2 thorpej #endif
564 1.1.6.2 thorpej }
565 1.1.6.2 thorpej }
566 1.1.6.2 thorpej /* Put it on the free list. */
567 1.1.6.2 thorpej acb->flags = ACB_FREE;
568 1.1.6.2 thorpej TAILQ_INSERT_HEAD(&dev->free_list, acb, chain);
569 1.1.6.2 thorpej
570 1.1.6.2 thorpej dev->sc_tinfo[periph->periph_target].cmds++;
571 1.1.6.2 thorpej
572 1.1.6.2 thorpej scsipi_done(xs);
573 1.1.6.2 thorpej
574 1.1.6.2 thorpej if (dosched)
575 1.1.6.2 thorpej sbic_sched(dev);
576 1.1.6.2 thorpej SBIC_TRACE(dev);
577 1.1.6.2 thorpej }
578 1.1.6.2 thorpej
579 1.1.6.2 thorpej static int
580 1.1.6.2 thorpej sbicwait(sbic_regmap_p regs, char until, int timeo, int line)
581 1.1.6.2 thorpej {
582 1.1.6.2 thorpej u_char val;
583 1.1.6.2 thorpej int csr;
584 1.1.6.2 thorpej
585 1.1.6.2 thorpej SBIC_TRACE((struct sbic_softc *)0);
586 1.1.6.2 thorpej if (timeo == 0)
587 1.1.6.2 thorpej timeo = 1000000; /* some large value.. */
588 1.1.6.2 thorpej
589 1.1.6.2 thorpej GET_SBIC_asr(regs,val);
590 1.1.6.2 thorpej while ((val & until) == 0) {
591 1.1.6.2 thorpej if (timeo-- == 0) {
592 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
593 1.1.6.2 thorpej printf("sbicwait TIMEO @%d with asr=x%x csr=x%x\n",
594 1.1.6.2 thorpej line, val, csr);
595 1.1.6.2 thorpej #if defined(DDB) && defined(DEBUG)
596 1.1.6.2 thorpej Debugger();
597 1.1.6.2 thorpej #endif
598 1.1.6.2 thorpej return val; /* Maybe I should abort */
599 1.1.6.2 thorpej break;
600 1.1.6.2 thorpej }
601 1.1.6.2 thorpej DELAY(1);
602 1.1.6.2 thorpej GET_SBIC_asr(regs,val);
603 1.1.6.2 thorpej }
604 1.1.6.2 thorpej SBIC_TRACE((struct sbic_softc *)0);
605 1.1.6.2 thorpej return val;
606 1.1.6.2 thorpej }
607 1.1.6.2 thorpej
608 1.1.6.2 thorpej static int
609 1.1.6.2 thorpej sbicabort(struct sbic_softc *dev, sbic_regmap_p regs, char *where)
610 1.1.6.2 thorpej {
611 1.1.6.2 thorpej u_char csr, asr;
612 1.1.6.2 thorpej
613 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
614 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
615 1.1.6.2 thorpej
616 1.1.6.2 thorpej printf ("%s: abort %s: csr = 0x%02x, asr = 0x%02x\n",
617 1.1.6.2 thorpej dev->sc_dev.dv_xname, where, csr, asr);
618 1.1.6.2 thorpej
619 1.1.6.2 thorpej
620 1.1.6.2 thorpej #if 0
621 1.1.6.2 thorpej /* Clean up running command */
622 1.1.6.2 thorpej if (dev->sc_nexus != NULL) {
623 1.1.6.2 thorpej dev->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
624 1.1.6.2 thorpej sbic_scsidone(dev->sc_nexus, dev->sc_stat[0]);
625 1.1.6.2 thorpej }
626 1.1.6.2 thorpej while (acb = dev->nexus_list.tqh_first) {
627 1.1.6.2 thorpej acb->xs->error = XS_DRIVER_STUFFUP;
628 1.1.6.2 thorpej sbic_scsidone(acb, -1 /*acb->stat[0]*/);
629 1.1.6.2 thorpej }
630 1.1.6.2 thorpej #endif
631 1.1.6.2 thorpej
632 1.1.6.2 thorpej /* Clean up chip itself */
633 1.1.6.2 thorpej if (dev->sc_flags & SBICF_SELECTED) {
634 1.1.6.2 thorpej while (asr & SBIC_ASR_DBR) {
635 1.1.6.2 thorpej /* sbic is jammed w/data. need to clear it */
636 1.1.6.2 thorpej /* But we don't know what direction it needs to go */
637 1.1.6.2 thorpej GET_SBIC_data(regs, asr);
638 1.1.6.2 thorpej printf("%s: abort %s: clearing data buffer 0x%02x\n",
639 1.1.6.2 thorpej dev->sc_dev.dv_xname, where, asr);
640 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
641 1.1.6.2 thorpej /* Not the read direction, then */
642 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR)
643 1.1.6.2 thorpej SET_SBIC_data(regs, asr);
644 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
645 1.1.6.2 thorpej }
646 1.1.6.2 thorpej WAIT_CIP(regs);
647 1.1.6.2 thorpej printf("%s: sbicabort - sending ABORT command\n",
648 1.1.6.2 thorpej dev->sc_dev.dv_xname);
649 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
650 1.1.6.2 thorpej WAIT_CIP(regs);
651 1.1.6.2 thorpej
652 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
653 1.1.6.2 thorpej if (asr & (SBIC_ASR_BSY | SBIC_ASR_LCI)) {
654 1.1.6.2 thorpej /* ok, get more drastic.. */
655 1.1.6.2 thorpej
656 1.1.6.2 thorpej printf("%s: sbicabort - asr %x, trying to reset\n",
657 1.1.6.2 thorpej dev->sc_dev.dv_xname, asr);
658 1.1.6.2 thorpej sbicreset(dev);
659 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
660 1.1.6.2 thorpej return -1;
661 1.1.6.2 thorpej }
662 1.1.6.2 thorpej printf("%s: sbicabort - sending DISC command\n",
663 1.1.6.2 thorpej dev->sc_dev.dv_xname);
664 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_DISC);
665 1.1.6.2 thorpej
666 1.1.6.2 thorpej do {
667 1.1.6.2 thorpej asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
668 1.1.6.2 thorpej GET_SBIC_csr (regs, csr);
669 1.1.6.2 thorpej CSR_TRACE('a',csr,asr,0);
670 1.1.6.2 thorpej } while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
671 1.1.6.2 thorpej && (csr != SBIC_CSR_CMD_INVALID));
672 1.1.6.2 thorpej
673 1.1.6.2 thorpej /* lets just hope it worked.. */
674 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
675 1.1.6.2 thorpej }
676 1.1.6.2 thorpej return -1;
677 1.1.6.2 thorpej }
678 1.1.6.2 thorpej
679 1.1.6.2 thorpej
680 1.1.6.2 thorpej /*
681 1.1.6.2 thorpej * Initialize driver-private structures
682 1.1.6.2 thorpej */
683 1.1.6.2 thorpej
684 1.1.6.2 thorpej int
685 1.1.6.2 thorpej sbicinit(struct sbic_softc *dev)
686 1.1.6.2 thorpej {
687 1.1.6.2 thorpej sbic_regmap_p regs;
688 1.1.6.2 thorpej u_int i;
689 1.1.6.2 thorpej /* u_int my_id, s;*/
690 1.1.6.2 thorpej /* u_char csr;*/
691 1.1.6.2 thorpej struct sbic_acb *acb;
692 1.1.6.2 thorpej u_int inhibit_sync;
693 1.1.6.2 thorpej
694 1.1.6.2 thorpej extern u_long scsi_nosync;
695 1.1.6.2 thorpej extern int shift_nosync;
696 1.1.6.2 thorpej
697 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicinit:\n"));
698 1.1.6.2 thorpej
699 1.1.6.2 thorpej regs = &dev->sc_sbicp;
700 1.1.6.2 thorpej
701 1.1.6.2 thorpej if ((dev->sc_flags & SBICF_ALIVE) == 0) {
702 1.1.6.2 thorpej TAILQ_INIT(&dev->ready_list);
703 1.1.6.2 thorpej TAILQ_INIT(&dev->nexus_list);
704 1.1.6.2 thorpej TAILQ_INIT(&dev->free_list);
705 1.1.6.2 thorpej callout_init(&dev->sc_timo_ch);
706 1.1.6.2 thorpej dev->sc_nexus = NULL;
707 1.1.6.2 thorpej acb = dev->sc_acb;
708 1.1.6.2 thorpej memset(acb, 0, sizeof(dev->sc_acb));
709 1.1.6.2 thorpej
710 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicinit: %d\n", __LINE__));
711 1.1.6.2 thorpej
712 1.1.6.2 thorpej for (i = 0; i < sizeof(dev->sc_acb) / sizeof(*acb); i++) {
713 1.1.6.2 thorpej TAILQ_INSERT_TAIL(&dev->free_list, acb, chain);
714 1.1.6.2 thorpej acb++;
715 1.1.6.2 thorpej }
716 1.1.6.2 thorpej memset(dev->sc_tinfo, 0, sizeof(dev->sc_tinfo));
717 1.1.6.2 thorpej /* make sure timeout is really not needed */
718 1.1.6.2 thorpej DBG(callout_reset(&dev->sc_timo_ch, 30 * hz,
719 1.1.6.2 thorpej (void *)sbictimeout, dev));
720 1.1.6.2 thorpej } else
721 1.1.6.2 thorpej panic("sbic: reinitializing driver!");
722 1.1.6.2 thorpej
723 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicinit: %d\n", __LINE__));
724 1.1.6.2 thorpej
725 1.1.6.2 thorpej dev->sc_flags |= SBICF_ALIVE;
726 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
727 1.1.6.2 thorpej
728 1.1.6.2 thorpej /* initialize inhibit array */
729 1.1.6.2 thorpej if (scsi_nosync) {
730 1.1.6.2 thorpej
731 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicinit: %d\n", __LINE__));
732 1.1.6.2 thorpej
733 1.1.6.2 thorpej inhibit_sync = (scsi_nosync >> shift_nosync) & 0xff;
734 1.1.6.2 thorpej shift_nosync += 8;
735 1.1.6.2 thorpej
736 1.1.6.2 thorpej DBGPRINTF(("%s: Inhibiting synchronous transfer %02x\n",
737 1.1.6.2 thorpej dev->sc_dev.dv_xname, inhibit_sync), inhibit_sync);
738 1.1.6.2 thorpej
739 1.1.6.2 thorpej for (i = 0; i < 8; ++i)
740 1.1.6.2 thorpej if (inhibit_sync & (1 << i))
741 1.1.6.2 thorpej sbic_inhibit_sync[i] = 1;
742 1.1.6.2 thorpej }
743 1.1.6.2 thorpej
744 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicinit: %d\n", __LINE__));
745 1.1.6.2 thorpej
746 1.1.6.2 thorpej sbicreset(dev);
747 1.1.6.2 thorpej return 0;
748 1.1.6.2 thorpej }
749 1.1.6.2 thorpej
750 1.1.6.2 thorpej static void
751 1.1.6.2 thorpej sbicreset(struct sbic_softc *dev)
752 1.1.6.2 thorpej {
753 1.1.6.2 thorpej sbic_regmap_p regs;
754 1.1.6.2 thorpej u_int my_id, s;
755 1.1.6.2 thorpej /* u_int i;*/
756 1.1.6.2 thorpej u_char csr;
757 1.1.6.2 thorpej /* struct sbic_acb *acb;*/
758 1.1.6.2 thorpej
759 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: %d\n", __LINE__));
760 1.1.6.2 thorpej
761 1.1.6.2 thorpej regs = &dev->sc_sbicp;
762 1.1.6.2 thorpej
763 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: regs = %08x\n", regs));
764 1.1.6.2 thorpej
765 1.1.6.2 thorpej #if 0
766 1.1.6.2 thorpej if (dev->sc_flags & SBICF_ALIVE) {
767 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
768 1.1.6.2 thorpej WAIT_CIP(regs);
769 1.1.6.2 thorpej }
770 1.1.6.2 thorpej #else
771 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_ABORT);
772 1.1.6.2 thorpej
773 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: %d\n", __LINE__));
774 1.1.6.2 thorpej
775 1.1.6.2 thorpej WAIT_CIP(regs);
776 1.1.6.2 thorpej
777 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: %d\n", __LINE__));
778 1.1.6.2 thorpej #endif
779 1.1.6.2 thorpej s = splbio();
780 1.1.6.2 thorpej my_id = dev->sc_channel.chan_id & SBIC_ID_MASK;
781 1.1.6.2 thorpej
782 1.1.6.2 thorpej /* Enable advanced mode */
783 1.1.6.2 thorpej my_id |= SBIC_ID_EAF /*| SBIC_ID_EHP*/ ;
784 1.1.6.2 thorpej SET_SBIC_myid(regs, my_id);
785 1.1.6.2 thorpej
786 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: %d\n", __LINE__));
787 1.1.6.2 thorpej
788 1.1.6.2 thorpej /*
789 1.1.6.2 thorpej * Disable interrupts (in dmainit) then reset the chip
790 1.1.6.2 thorpej */
791 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_RESET);
792 1.1.6.2 thorpej DELAY(25);
793 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
794 1.1.6.2 thorpej GET_SBIC_csr(regs, csr); /* clears interrupt also */
795 1.1.6.2 thorpej
796 1.1.6.2 thorpej if (dev->sc_clkfreq < 110)
797 1.1.6.2 thorpej my_id |= SBIC_ID_FS_8_10;
798 1.1.6.2 thorpej else if (dev->sc_clkfreq < 160)
799 1.1.6.2 thorpej my_id |= SBIC_ID_FS_12_15;
800 1.1.6.2 thorpej else if (dev->sc_clkfreq < 210)
801 1.1.6.2 thorpej my_id |= SBIC_ID_FS_16_20;
802 1.1.6.2 thorpej
803 1.1.6.2 thorpej SET_SBIC_myid(regs, my_id);
804 1.1.6.2 thorpej
805 1.1.6.2 thorpej SBIC_DEBUG(printf("sbicreset: %d\n", __LINE__));
806 1.1.6.2 thorpej
807 1.1.6.2 thorpej /*
808 1.1.6.2 thorpej * Set up various chip parameters
809 1.1.6.2 thorpej */
810 1.1.6.2 thorpej SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI /* | SBIC_CTL_HSP */
811 1.1.6.2 thorpej | dev->sc_dmamode);
812 1.1.6.2 thorpej /*
813 1.1.6.2 thorpej * don't allow (re)selection (SBIC_RID_ES)
814 1.1.6.2 thorpej * until we can handle target mode!!
815 1.1.6.2 thorpej */
816 1.1.6.2 thorpej SET_SBIC_rselid(regs, SBIC_RID_ER);
817 1.1.6.2 thorpej SET_SBIC_syn(regs, 0); /* asynch for now */
818 1.1.6.2 thorpej
819 1.1.6.2 thorpej /*
820 1.1.6.2 thorpej * anything else was zeroed by reset
821 1.1.6.2 thorpej */
822 1.1.6.2 thorpej splx(s);
823 1.1.6.2 thorpej
824 1.1.6.2 thorpej #if 0
825 1.1.6.2 thorpej if ((dev->sc_flags & SBICF_ALIVE) == 0) {
826 1.1.6.2 thorpej TAILQ_INIT(&dev->ready_list);
827 1.1.6.2 thorpej TAILQ_INIT(&dev->nexus_list);
828 1.1.6.2 thorpej TAILQ_INIT(&dev->free_list);
829 1.1.6.2 thorpej dev->sc_nexus = NULL;
830 1.1.6.2 thorpej acb = dev->sc_acb;
831 1.1.6.2 thorpej memset(acb, 0, sizeof(dev->sc_acb));
832 1.1.6.2 thorpej for (i = 0; i < sizeof(dev->sc_acb) / sizeof(*acb); i++) {
833 1.1.6.2 thorpej TAILQ_INSERT_TAIL(&dev->free_list, acb, chain);
834 1.1.6.2 thorpej acb++;
835 1.1.6.2 thorpej }
836 1.1.6.2 thorpej memset(dev->sc_tinfo, 0, sizeof(dev->sc_tinfo));
837 1.1.6.2 thorpej } else {
838 1.1.6.2 thorpej if (dev->sc_nexus != NULL) {
839 1.1.6.2 thorpej dev->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
840 1.1.6.2 thorpej sbic_scsidone(dev->sc_nexus, dev->sc_stat[0]);
841 1.1.6.2 thorpej }
842 1.1.6.2 thorpej while (acb = dev->nexus_list.tqh_first) {
843 1.1.6.2 thorpej acb->xs->error = XS_DRIVER_STUFFUP;
844 1.1.6.2 thorpej sbic_scsidone(acb, -1 /*acb->stat[0]*/);
845 1.1.6.2 thorpej }
846 1.1.6.2 thorpej }
847 1.1.6.2 thorpej
848 1.1.6.2 thorpej dev->sc_flags |= SBICF_ALIVE;
849 1.1.6.2 thorpej #endif
850 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
851 1.1.6.2 thorpej }
852 1.1.6.2 thorpej
853 1.1.6.2 thorpej static void
854 1.1.6.2 thorpej sbicerror(struct sbic_softc *dev, sbic_regmap_p regs, u_char csr)
855 1.1.6.2 thorpej {
856 1.1.6.2 thorpej #ifdef DIAGNOSTIC
857 1.1.6.2 thorpej if (dev->sc_nexus == NULL)
858 1.1.6.2 thorpej panic("sbicerror");
859 1.1.6.2 thorpej #endif
860 1.1.6.2 thorpej if (dev->sc_nexus->xs->xs_control & XS_CTL_SILENT)
861 1.1.6.2 thorpej return;
862 1.1.6.2 thorpej
863 1.1.6.2 thorpej printf("%s: ", dev->sc_dev.dv_xname);
864 1.1.6.2 thorpej printf("csr == 0x%02x\n", csr); /* XXX */
865 1.1.6.2 thorpej }
866 1.1.6.2 thorpej
867 1.1.6.2 thorpej /*
868 1.1.6.2 thorpej * select the bus, return when selected or error.
869 1.1.6.2 thorpej */
870 1.1.6.2 thorpej static int
871 1.1.6.2 thorpej sbicselectbus(struct sbic_softc *dev, sbic_regmap_p regs, u_char target,
872 1.1.6.2 thorpej u_char lun, u_char our_addr)
873 1.1.6.2 thorpej {
874 1.1.6.2 thorpej u_char asr, csr, id;
875 1.1.6.2 thorpej
876 1.1.6.2 thorpej SBIC_TRACE(dev);
877 1.1.6.2 thorpej QPRINTF(("sbicselectbus %d\n", target));
878 1.1.6.2 thorpej
879 1.1.6.2 thorpej /*
880 1.1.6.2 thorpej * if we're already selected, return (XXXX panic maybe?)
881 1.1.6.2 thorpej */
882 1.1.6.2 thorpej if (dev->sc_flags & SBICF_SELECTED) {
883 1.1.6.2 thorpej SBIC_TRACE(dev);
884 1.1.6.2 thorpej return 1;
885 1.1.6.2 thorpej }
886 1.1.6.2 thorpej
887 1.1.6.2 thorpej /*
888 1.1.6.2 thorpej * issue select
889 1.1.6.2 thorpej */
890 1.1.6.2 thorpej SBIC_TC_PUT(regs, 0);
891 1.1.6.2 thorpej SET_SBIC_selid(regs, target);
892 1.1.6.2 thorpej SET_SBIC_timeo(regs, SBIC_TIMEOUT(250,dev->sc_clkfreq));
893 1.1.6.2 thorpej
894 1.1.6.2 thorpej /*
895 1.1.6.2 thorpej * set sync or async
896 1.1.6.2 thorpej */
897 1.1.6.2 thorpej if (dev->sc_sync[target].state == SYNC_DONE)
898 1.1.6.2 thorpej SET_SBIC_syn(regs, SBIC_SYN (dev->sc_sync[target].offset,
899 1.1.6.2 thorpej dev->sc_sync[target].period));
900 1.1.6.2 thorpej else
901 1.1.6.2 thorpej SET_SBIC_syn(regs, SBIC_SYN (0, sbic_min_period));
902 1.1.6.2 thorpej
903 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
904 1.1.6.2 thorpej if (asr & (SBIC_ASR_INT | SBIC_ASR_BSY)) {
905 1.1.6.2 thorpej /* This means we got ourselves reselected upon */
906 1.1.6.2 thorpej /* printf("sbicselectbus: INT/BSY asr %02x\n", asr);*/
907 1.1.6.2 thorpej #ifdef DDB
908 1.1.6.2 thorpej /* Debugger();*/
909 1.1.6.2 thorpej #endif
910 1.1.6.2 thorpej SBIC_TRACE(dev);
911 1.1.6.2 thorpej return 1;
912 1.1.6.2 thorpej }
913 1.1.6.2 thorpej
914 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN);
915 1.1.6.2 thorpej
916 1.1.6.2 thorpej /*
917 1.1.6.2 thorpej * wait for select (merged from separate function may need
918 1.1.6.2 thorpej * cleanup)
919 1.1.6.2 thorpej */
920 1.1.6.2 thorpej WAIT_CIP(regs);
921 1.1.6.2 thorpej do {
922 1.1.6.2 thorpej asr = SBIC_WAIT(regs, SBIC_ASR_INT | SBIC_ASR_LCI, 0);
923 1.1.6.2 thorpej if (asr & SBIC_ASR_LCI) {
924 1.1.6.2 thorpej
925 1.1.6.2 thorpej DBGPRINTF(("sbicselectbus: late LCI asr %02x\n", asr),
926 1.1.6.2 thorpej reselect_debug);
927 1.1.6.2 thorpej
928 1.1.6.2 thorpej SBIC_TRACE(dev);
929 1.1.6.2 thorpej return 1;
930 1.1.6.2 thorpej }
931 1.1.6.2 thorpej GET_SBIC_csr (regs, csr);
932 1.1.6.2 thorpej CSR_TRACE('s',csr,asr,target);
933 1.1.6.2 thorpej QPRINTF(("%02x ", csr));
934 1.1.6.2 thorpej if (csr == SBIC_CSR_RSLT_NI || csr == SBIC_CSR_RSLT_IFY) {
935 1.1.6.2 thorpej
936 1.1.6.2 thorpej DBGPRINTF(("sbicselectbus: reselected asr %02x\n",
937 1.1.6.2 thorpej asr), reselect_debug);
938 1.1.6.2 thorpej
939 1.1.6.2 thorpej /* We need to handle this now so we don't lock
940 1.1.6.2 thorpej up later */
941 1.1.6.2 thorpej sbicnextstate(dev, csr, asr);
942 1.1.6.2 thorpej SBIC_TRACE(dev);
943 1.1.6.2 thorpej return 1;
944 1.1.6.2 thorpej }
945 1.1.6.2 thorpej if (csr == SBIC_CSR_SLT || csr == SBIC_CSR_SLT_ATN) {
946 1.1.6.2 thorpej panic("sbicselectbus: target issued select!");
947 1.1.6.2 thorpej return 1;
948 1.1.6.2 thorpej }
949 1.1.6.2 thorpej } while (csr != (SBIC_CSR_MIS_2 | MESG_OUT_PHASE) &&
950 1.1.6.2 thorpej csr != (SBIC_CSR_MIS_2 | CMD_PHASE) &&
951 1.1.6.2 thorpej csr != SBIC_CSR_SEL_TIMEO);
952 1.1.6.2 thorpej
953 1.1.6.2 thorpej /* Enable (or not) reselection */
954 1.1.6.2 thorpej if (!sbic_enable_reselect && dev->nexus_list.tqh_first == NULL)
955 1.1.6.2 thorpej SET_SBIC_rselid (regs, 0);
956 1.1.6.2 thorpej else
957 1.1.6.2 thorpej SET_SBIC_rselid (regs, SBIC_RID_ER);
958 1.1.6.2 thorpej
959 1.1.6.2 thorpej if (csr == (SBIC_CSR_MIS_2 | CMD_PHASE)) {
960 1.1.6.2 thorpej dev->sc_flags |= SBICF_SELECTED; /* device ignored ATN */
961 1.1.6.2 thorpej GET_SBIC_selid(regs, id);
962 1.1.6.2 thorpej dev->target = id;
963 1.1.6.2 thorpej GET_SBIC_tlun(regs,dev->lun);
964 1.1.6.2 thorpej if (dev->lun & SBIC_TLUN_VALID)
965 1.1.6.2 thorpej dev->lun &= SBIC_TLUN_MASK;
966 1.1.6.2 thorpej else
967 1.1.6.2 thorpej dev->lun = lun;
968 1.1.6.2 thorpej } else if (csr == (SBIC_CSR_MIS_2 | MESG_OUT_PHASE)) {
969 1.1.6.2 thorpej /*
970 1.1.6.2 thorpej * Send identify message
971 1.1.6.2 thorpej * (SCSI-2 requires an identify msg (?))
972 1.1.6.2 thorpej */
973 1.1.6.2 thorpej GET_SBIC_selid(regs, id);
974 1.1.6.2 thorpej dev->target = id;
975 1.1.6.2 thorpej GET_SBIC_tlun(regs,dev->lun);
976 1.1.6.2 thorpej if (dev->lun & SBIC_TLUN_VALID)
977 1.1.6.2 thorpej dev->lun &= SBIC_TLUN_MASK;
978 1.1.6.2 thorpej else
979 1.1.6.2 thorpej dev->lun = lun;
980 1.1.6.2 thorpej /*
981 1.1.6.2 thorpej * handle drives that don't want to be asked
982 1.1.6.2 thorpej * whether to go sync at all.
983 1.1.6.2 thorpej */
984 1.1.6.2 thorpej if (sbic_inhibit_sync[id]
985 1.1.6.2 thorpej && dev->sc_sync[id].state == SYNC_START) {
986 1.1.6.2 thorpej DBGPRINTF(("Forcing target %d asynchronous.\n", id),
987 1.1.6.2 thorpej sync_debug);
988 1.1.6.2 thorpej
989 1.1.6.2 thorpej dev->sc_sync[id].offset = 0;
990 1.1.6.2 thorpej dev->sc_sync[id].period = sbic_min_period;
991 1.1.6.2 thorpej dev->sc_sync[id].state = SYNC_DONE;
992 1.1.6.2 thorpej }
993 1.1.6.2 thorpej
994 1.1.6.2 thorpej
995 1.1.6.2 thorpej if (dev->sc_sync[id].state != SYNC_START){
996 1.1.6.2 thorpej if ((dev->sc_nexus->xs->xs_control & XS_CTL_POLL)
997 1.1.6.2 thorpej || (dev->sc_flags & SBICF_ICMD)
998 1.1.6.2 thorpej || !sbic_enable_reselect)
999 1.1.6.2 thorpej SEND_BYTE(regs, MSG_IDENTIFY | lun);
1000 1.1.6.2 thorpej else
1001 1.1.6.2 thorpej SEND_BYTE(regs, MSG_IDENTIFY_DR | lun);
1002 1.1.6.2 thorpej } else {
1003 1.1.6.2 thorpej /*
1004 1.1.6.2 thorpej * try to initiate a sync transfer.
1005 1.1.6.2 thorpej * So compose the sync message we're going
1006 1.1.6.2 thorpej * to send to the target
1007 1.1.6.2 thorpej */
1008 1.1.6.2 thorpej
1009 1.1.6.2 thorpej DBGPRINTF(("Sending sync request to target %d ... ",
1010 1.1.6.2 thorpej id), sync_debug);
1011 1.1.6.2 thorpej
1012 1.1.6.2 thorpej /*
1013 1.1.6.2 thorpej * setup scsi message sync message request
1014 1.1.6.2 thorpej */
1015 1.1.6.2 thorpej dev->sc_msg[0] = MSG_IDENTIFY | lun;
1016 1.1.6.2 thorpej dev->sc_msg[1] = MSG_EXT_MESSAGE;
1017 1.1.6.2 thorpej dev->sc_msg[2] = 3;
1018 1.1.6.2 thorpej dev->sc_msg[3] = MSG_SYNC_REQ;
1019 1.1.6.2 thorpej dev->sc_msg[4] = sbictoscsiperiod(dev, regs,
1020 1.1.6.2 thorpej sbic_min_period);
1021 1.1.6.2 thorpej dev->sc_msg[5] = sbic_max_offset;
1022 1.1.6.2 thorpej
1023 1.1.6.2 thorpej if (sbicxfstart(regs, 6, MESG_OUT_PHASE,
1024 1.1.6.2 thorpej sbic_cmd_wait))
1025 1.1.6.2 thorpej sbicxfout(regs, 6, dev->sc_msg,
1026 1.1.6.2 thorpej MESG_OUT_PHASE);
1027 1.1.6.2 thorpej
1028 1.1.6.2 thorpej dev->sc_sync[id].state = SYNC_SENT;
1029 1.1.6.2 thorpej
1030 1.1.6.2 thorpej DBGPRINTF(("sent\n"), sync_debug);
1031 1.1.6.2 thorpej }
1032 1.1.6.2 thorpej
1033 1.1.6.2 thorpej asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
1034 1.1.6.2 thorpej GET_SBIC_csr (regs, csr);
1035 1.1.6.2 thorpej CSR_TRACE('y',csr,asr,target);
1036 1.1.6.2 thorpej QPRINTF(("[%02x]", csr));
1037 1.1.6.2 thorpej
1038 1.1.6.2 thorpej DBGPRINTF(("csr-result of last msgout: 0x%x\n", csr),
1039 1.1.6.2 thorpej sync_debug && dev->sc_sync[id].state == SYNC_SENT);
1040 1.1.6.2 thorpej
1041 1.1.6.2 thorpej if (csr != SBIC_CSR_SEL_TIMEO)
1042 1.1.6.2 thorpej dev->sc_flags |= SBICF_SELECTED;
1043 1.1.6.2 thorpej }
1044 1.1.6.2 thorpej if (csr == SBIC_CSR_SEL_TIMEO)
1045 1.1.6.2 thorpej dev->sc_nexus->xs->error = XS_SELTIMEOUT;
1046 1.1.6.2 thorpej
1047 1.1.6.2 thorpej QPRINTF(("\n"));
1048 1.1.6.2 thorpej
1049 1.1.6.2 thorpej SBIC_TRACE(dev);
1050 1.1.6.2 thorpej return csr == SBIC_CSR_SEL_TIMEO;
1051 1.1.6.2 thorpej }
1052 1.1.6.2 thorpej
1053 1.1.6.2 thorpej static int
1054 1.1.6.2 thorpej sbicxfstart(sbic_regmap_p regs, int len, u_char phase, int wait)
1055 1.1.6.2 thorpej {
1056 1.1.6.2 thorpej u_char id;
1057 1.1.6.2 thorpej
1058 1.1.6.2 thorpej switch (phase) {
1059 1.1.6.2 thorpej case DATA_IN_PHASE:
1060 1.1.6.2 thorpej case MESG_IN_PHASE:
1061 1.1.6.2 thorpej GET_SBIC_selid (regs, id);
1062 1.1.6.2 thorpej id |= SBIC_SID_FROM_SCSI;
1063 1.1.6.2 thorpej SET_SBIC_selid (regs, id);
1064 1.1.6.2 thorpej SBIC_TC_PUT (regs, (unsigned)len);
1065 1.1.6.2 thorpej break;
1066 1.1.6.2 thorpej case DATA_OUT_PHASE:
1067 1.1.6.2 thorpej case MESG_OUT_PHASE:
1068 1.1.6.2 thorpej case CMD_PHASE:
1069 1.1.6.2 thorpej GET_SBIC_selid (regs, id);
1070 1.1.6.2 thorpej id &= ~SBIC_SID_FROM_SCSI;
1071 1.1.6.2 thorpej SET_SBIC_selid (regs, id);
1072 1.1.6.2 thorpej SBIC_TC_PUT (regs, (unsigned)len);
1073 1.1.6.2 thorpej break;
1074 1.1.6.2 thorpej default:
1075 1.1.6.2 thorpej SBIC_TC_PUT (regs, 0);
1076 1.1.6.2 thorpej }
1077 1.1.6.2 thorpej QPRINTF(("sbicxfstart %d, %d, %d\n", len, phase, wait));
1078 1.1.6.2 thorpej
1079 1.1.6.2 thorpej return 1;
1080 1.1.6.2 thorpej }
1081 1.1.6.2 thorpej
1082 1.1.6.2 thorpej static int
1083 1.1.6.2 thorpej sbicxfout(sbic_regmap_p regs, int len, void *bp, int phase)
1084 1.1.6.2 thorpej {
1085 1.1.6.2 thorpej #ifdef UNPROTECTED_CSR
1086 1.1.6.2 thorpej u_char orig_csr
1087 1.1.6.2 thorpej #endif
1088 1.1.6.2 thorpej u_char asr, *buf;
1089 1.1.6.2 thorpej /* u_char csr;*/
1090 1.1.6.2 thorpej int wait;
1091 1.1.6.2 thorpej
1092 1.1.6.2 thorpej buf = bp;
1093 1.1.6.2 thorpej wait = sbic_data_wait;
1094 1.1.6.2 thorpej
1095 1.1.6.2 thorpej QPRINTF(("sbicxfout {%d} %02x %02x %02x %02x %02x "
1096 1.1.6.2 thorpej "%02x %02x %02x %02x %02x\n", len, buf[0], buf[1], buf[2],
1097 1.1.6.2 thorpej buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]));
1098 1.1.6.2 thorpej
1099 1.1.6.2 thorpej #ifdef UNPROTECTED_CSR
1100 1.1.6.2 thorpej GET_SBIC_csr (regs, orig_csr);
1101 1.1.6.2 thorpej CSR_TRACE('>',orig_csr,0,0);
1102 1.1.6.2 thorpej #endif
1103 1.1.6.2 thorpej
1104 1.1.6.2 thorpej /*
1105 1.1.6.2 thorpej * sigh.. WD-PROTO strikes again.. sending the command in one go
1106 1.1.6.2 thorpej * causes the chip to lock up if talking to certain (misbehaving?)
1107 1.1.6.2 thorpej * targets. Anyway, this procedure should work for all targets, but
1108 1.1.6.2 thorpej * it's slightly slower due to the overhead
1109 1.1.6.2 thorpej */
1110 1.1.6.2 thorpej WAIT_CIP (regs);
1111 1.1.6.2 thorpej SET_SBIC_cmd (regs, SBIC_CMD_XFER_INFO);
1112 1.1.6.2 thorpej for (;len > 0; len--) {
1113 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1114 1.1.6.2 thorpej while ((asr & SBIC_ASR_DBR) == 0) {
1115 1.1.6.2 thorpej if ((asr & SBIC_ASR_INT) || --wait < 0) {
1116 1.1.6.2 thorpej
1117 1.1.6.2 thorpej DBGPRINTF(("sbicxfout fail: l%d i%x w%d\n",
1118 1.1.6.2 thorpej len, asr, wait), sbic_debug);
1119 1.1.6.2 thorpej
1120 1.1.6.2 thorpej return len;
1121 1.1.6.2 thorpej }
1122 1.1.6.2 thorpej /* DELAY(1);*/
1123 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1124 1.1.6.2 thorpej }
1125 1.1.6.2 thorpej
1126 1.1.6.2 thorpej SET_SBIC_data (regs, *buf);
1127 1.1.6.2 thorpej buf++;
1128 1.1.6.2 thorpej }
1129 1.1.6.2 thorpej SBIC_TC_GET(regs, len);
1130 1.1.6.2 thorpej QPRINTF(("sbicxfout done %d bytes\n", len));
1131 1.1.6.2 thorpej /*
1132 1.1.6.2 thorpej * this leaves with one csr to be read
1133 1.1.6.2 thorpej */
1134 1.1.6.2 thorpej return 0;
1135 1.1.6.2 thorpej }
1136 1.1.6.2 thorpej
1137 1.1.6.2 thorpej /* returns # bytes left to read */
1138 1.1.6.2 thorpej static int
1139 1.1.6.2 thorpej sbicxfin(sbic_regmap_p regs, int len, void *bp)
1140 1.1.6.2 thorpej {
1141 1.1.6.2 thorpej int wait;
1142 1.1.6.2 thorpej /* int read;*/
1143 1.1.6.2 thorpej u_char *obp, *buf;
1144 1.1.6.2 thorpej #ifdef UNPROTECTED_CSR
1145 1.1.6.2 thorpej u_char orig_csr, csr;
1146 1.1.6.2 thorpej #endif
1147 1.1.6.2 thorpej u_char asr;
1148 1.1.6.2 thorpej
1149 1.1.6.2 thorpej wait = sbic_data_wait;
1150 1.1.6.2 thorpej obp = bp;
1151 1.1.6.2 thorpej buf = bp;
1152 1.1.6.2 thorpej
1153 1.1.6.2 thorpej #ifdef UNPROTECTED_CSR
1154 1.1.6.2 thorpej GET_SBIC_csr (regs, orig_csr);
1155 1.1.6.2 thorpej CSR_TRACE('<',orig_csr,0,0);
1156 1.1.6.2 thorpej
1157 1.1.6.2 thorpej QPRINTF(("sbicxfin %d, csr=%02x\n", len, orig_csr));
1158 1.1.6.2 thorpej #endif
1159 1.1.6.2 thorpej
1160 1.1.6.2 thorpej WAIT_CIP (regs);
1161 1.1.6.2 thorpej SET_SBIC_cmd (regs, SBIC_CMD_XFER_INFO);
1162 1.1.6.2 thorpej for (;len > 0; len--) {
1163 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1164 1.1.6.2 thorpej if ((asr & SBIC_ASR_PE)) {
1165 1.1.6.2 thorpej DBG(printf("sbicxfin parity error: l%d i%x w%d\n",
1166 1.1.6.2 thorpej len, asr, wait));
1167 1.1.6.2 thorpej #if defined(DDB) && defined(DEBUG)
1168 1.1.6.2 thorpej Debugger();
1169 1.1.6.2 thorpej #endif
1170 1.1.6.2 thorpej DBG(return ((unsigned long)buf - (unsigned long)bp));
1171 1.1.6.2 thorpej }
1172 1.1.6.2 thorpej while ((asr & SBIC_ASR_DBR) == 0) {
1173 1.1.6.2 thorpej if ((asr & SBIC_ASR_INT) || --wait < 0) {
1174 1.1.6.2 thorpej
1175 1.1.6.2 thorpej DBG(if (sbic_debug) {
1176 1.1.6.2 thorpej QPRINTF(("sbicxfin fail:{%d} %02x %02x %02x %02x %02x %02x "
1177 1.1.6.2 thorpej "%02x %02x %02x %02x\n", len, obp[0], obp[1], obp[2],
1178 1.1.6.2 thorpej obp[3], obp[4], obp[5], obp[6], obp[7], obp[8], obp[9]));
1179 1.1.6.2 thorpej printf("sbicxfin fail: l%d i%x w%d\n", len, asr, wait); });
1180 1.1.6.2 thorpej
1181 1.1.6.2 thorpej return len;
1182 1.1.6.2 thorpej }
1183 1.1.6.2 thorpej
1184 1.1.6.2 thorpej #ifdef UNPROTECTED_CSR
1185 1.1.6.2 thorpej if (!(asr & SBIC_ASR_BSY)) {
1186 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1187 1.1.6.2 thorpej CSR_TRACE('<',csr,asr,len);
1188 1.1.6.2 thorpej QPRINTF(("[CSR%02xASR%02x]", csr, asr));
1189 1.1.6.2 thorpej }
1190 1.1.6.2 thorpej #endif
1191 1.1.6.2 thorpej
1192 1.1.6.2 thorpej /* DELAY(1);*/
1193 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1194 1.1.6.2 thorpej }
1195 1.1.6.2 thorpej
1196 1.1.6.2 thorpej GET_SBIC_data (regs, *buf);
1197 1.1.6.2 thorpej /* QPRINTF(("asr=%02x, csr=%02x, data=%02x\n", asr, csr, *buf));*/
1198 1.1.6.2 thorpej buf++;
1199 1.1.6.2 thorpej }
1200 1.1.6.2 thorpej
1201 1.1.6.2 thorpej QPRINTF(("sbicxfin {%d} %02x %02x %02x %02x %02x %02x "
1202 1.1.6.2 thorpej "%02x %02x %02x %02x\n", len, obp[0], obp[1], obp[2],
1203 1.1.6.2 thorpej obp[3], obp[4], obp[5], obp[6], obp[7], obp[8], obp[9]));
1204 1.1.6.2 thorpej
1205 1.1.6.2 thorpej /* this leaves with one csr to be read */
1206 1.1.6.2 thorpej return len;
1207 1.1.6.2 thorpej }
1208 1.1.6.2 thorpej
1209 1.1.6.2 thorpej /*
1210 1.1.6.2 thorpej * SCSI 'immediate' command: issue a command to some SCSI device
1211 1.1.6.2 thorpej * and get back an 'immediate' response (i.e., do programmed xfer
1212 1.1.6.2 thorpej * to get the response data). 'cbuf' is a buffer containing a scsi
1213 1.1.6.2 thorpej * command of length clen bytes. 'buf' is a buffer of length 'len'
1214 1.1.6.2 thorpej * bytes for data. The transfer direction is determined by the device
1215 1.1.6.2 thorpej * (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
1216 1.1.6.2 thorpej * command must supply no data.
1217 1.1.6.2 thorpej */
1218 1.1.6.2 thorpej static int
1219 1.1.6.2 thorpej sbicicmd(struct sbic_softc *dev, int target, int lun, struct sbic_acb *acb)
1220 1.1.6.2 thorpej {
1221 1.1.6.2 thorpej sbic_regmap_p regs;
1222 1.1.6.2 thorpej u_char phase, csr, asr;
1223 1.1.6.2 thorpej int wait;
1224 1.1.6.2 thorpej /* int newtarget, cmd_sent, parity_err;*/
1225 1.1.6.2 thorpej
1226 1.1.6.2 thorpej /* int discon;*/
1227 1.1.6.2 thorpej int i;
1228 1.1.6.2 thorpej
1229 1.1.6.2 thorpej void *cbuf, *buf;
1230 1.1.6.2 thorpej int clen, len;
1231 1.1.6.2 thorpej
1232 1.1.6.2 thorpej #define CSR_LOG_BUF_SIZE 0
1233 1.1.6.2 thorpej #if CSR_LOG_BUF_SIZE
1234 1.1.6.2 thorpej int bufptr;
1235 1.1.6.2 thorpej int csrbuf[CSR_LOG_BUF_SIZE];
1236 1.1.6.2 thorpej bufptr = 0;
1237 1.1.6.2 thorpej #endif
1238 1.1.6.2 thorpej
1239 1.1.6.2 thorpej cbuf = &acb->cmd;
1240 1.1.6.2 thorpej clen = acb->clen;
1241 1.1.6.2 thorpej buf = acb->data;
1242 1.1.6.2 thorpej len = acb->datalen;
1243 1.1.6.2 thorpej
1244 1.1.6.2 thorpej SBIC_TRACE(dev);
1245 1.1.6.2 thorpej regs = &dev->sc_sbicp;
1246 1.1.6.2 thorpej
1247 1.1.6.2 thorpej acb->sc_tcnt = 0;
1248 1.1.6.2 thorpej
1249 1.1.6.2 thorpej DBG(routine = 3);
1250 1.1.6.2 thorpej DBG(debug_sbic_regs = regs); /* store this to allow debug calls */
1251 1.1.6.2 thorpej DBGPRINTF(("sbicicmd(%d,%d):%d\n", target, lun, len),
1252 1.1.6.2 thorpej data_pointer_debug > 1);
1253 1.1.6.2 thorpej
1254 1.1.6.2 thorpej /*
1255 1.1.6.2 thorpej * set the sbic into non-DMA mode
1256 1.1.6.2 thorpej */
1257 1.1.6.2 thorpej SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI /*| SBIC_CTL_HSP*/);
1258 1.1.6.2 thorpej
1259 1.1.6.2 thorpej dev->sc_stat[0] = 0xff;
1260 1.1.6.2 thorpej dev->sc_msg[0] = 0xff;
1261 1.1.6.2 thorpej i = 1; /* pre-load */
1262 1.1.6.2 thorpej
1263 1.1.6.2 thorpej /* We're stealing the SCSI bus */
1264 1.1.6.2 thorpej dev->sc_flags |= SBICF_ICMD;
1265 1.1.6.2 thorpej
1266 1.1.6.2 thorpej do {
1267 1.1.6.2 thorpej /*
1268 1.1.6.2 thorpej * select the SCSI bus (it's an error if bus isn't free)
1269 1.1.6.2 thorpej */
1270 1.1.6.2 thorpej if (!(dev->sc_flags & SBICF_SELECTED)
1271 1.1.6.2 thorpej && sbicselectbus(dev, regs, target, lun,
1272 1.1.6.2 thorpej dev->sc_scsiaddr)) {
1273 1.1.6.2 thorpej /*printf("sbicicmd trying to select busy bus!\n");*/
1274 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_ICMD;
1275 1.1.6.2 thorpej return -1;
1276 1.1.6.2 thorpej }
1277 1.1.6.2 thorpej
1278 1.1.6.2 thorpej /*
1279 1.1.6.2 thorpej * Wait for a phase change (or error) then let the
1280 1.1.6.2 thorpej * device sequence us through the various SCSI phases.
1281 1.1.6.2 thorpej */
1282 1.1.6.2 thorpej
1283 1.1.6.2 thorpej wait = sbic_cmd_wait;
1284 1.1.6.2 thorpej
1285 1.1.6.2 thorpej asr = GET_SBIC_asr (regs, asr);
1286 1.1.6.2 thorpej GET_SBIC_csr (regs, csr);
1287 1.1.6.2 thorpej CSR_TRACE('I',csr,asr,target);
1288 1.1.6.2 thorpej QPRINTF((">ASR:%02xCSR:%02x<", asr, csr));
1289 1.1.6.2 thorpej
1290 1.1.6.2 thorpej #if CSR_LOG_BUF_SIZE
1291 1.1.6.2 thorpej csrbuf[bufptr++] = csr;
1292 1.1.6.2 thorpej #endif
1293 1.1.6.2 thorpej
1294 1.1.6.2 thorpej
1295 1.1.6.2 thorpej switch (csr) {
1296 1.1.6.2 thorpej case SBIC_CSR_S_XFERRED:
1297 1.1.6.2 thorpej case SBIC_CSR_DISC:
1298 1.1.6.2 thorpej case SBIC_CSR_DISC_1:
1299 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
1300 1.1.6.2 thorpej GET_SBIC_cmd_phase (regs, phase);
1301 1.1.6.2 thorpej if (phase == 0x60) {
1302 1.1.6.2 thorpej GET_SBIC_tlun (regs, dev->sc_stat[0]);
1303 1.1.6.2 thorpej i = 0; /* done */
1304 1.1.6.2 thorpej /* break;*/ /* Bypass all the state gobldygook */
1305 1.1.6.2 thorpej } else {
1306 1.1.6.2 thorpej DBGPRINTF(("sbicicmd: handling disconnect\n"),
1307 1.1.6.2 thorpej reselect_debug > 1);
1308 1.1.6.2 thorpej
1309 1.1.6.2 thorpej i = SBIC_STATE_DISCONNECT;
1310 1.1.6.2 thorpej }
1311 1.1.6.2 thorpej break;
1312 1.1.6.2 thorpej
1313 1.1.6.2 thorpej case SBIC_CSR_XFERRED | CMD_PHASE:
1314 1.1.6.2 thorpej case SBIC_CSR_MIS | CMD_PHASE:
1315 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | CMD_PHASE:
1316 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | CMD_PHASE:
1317 1.1.6.2 thorpej if (sbicxfstart(regs, clen, CMD_PHASE, sbic_cmd_wait))
1318 1.1.6.2 thorpej if (sbicxfout(regs, clen,
1319 1.1.6.2 thorpej cbuf, CMD_PHASE))
1320 1.1.6.2 thorpej i = sbicabort(dev, regs,
1321 1.1.6.2 thorpej "icmd sending cmd");
1322 1.1.6.2 thorpej #if 0
1323 1.1.6.2 thorpej GET_SBIC_csr(regs, csr); /* Lets us reload tcount */
1324 1.1.6.2 thorpej WAIT_CIP(regs);
1325 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1326 1.1.6.2 thorpej CSR_TRACE('I',csr,asr,target);
1327 1.1.6.2 thorpej if (asr & (SBIC_ASR_BSY | SBIC_ASR_LCI | SBIC_ASR_CIP))
1328 1.1.6.2 thorpej printf("next: cmd sent asr %02x, csr %02x\n",
1329 1.1.6.2 thorpej asr, csr);
1330 1.1.6.2 thorpej #endif
1331 1.1.6.2 thorpej break;
1332 1.1.6.2 thorpej
1333 1.1.6.2 thorpej #if 0
1334 1.1.6.2 thorpej case SBIC_CSR_XFERRED | DATA_OUT_PHASE:
1335 1.1.6.2 thorpej case SBIC_CSR_XFERRED | DATA_IN_PHASE:
1336 1.1.6.2 thorpej case SBIC_CSR_MIS | DATA_OUT_PHASE:
1337 1.1.6.2 thorpej case SBIC_CSR_MIS | DATA_IN_PHASE:
1338 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | DATA_OUT_PHASE:
1339 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | DATA_IN_PHASE:
1340 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | DATA_OUT_PHASE:
1341 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | DATA_IN_PHASE:
1342 1.1.6.2 thorpej if (acb->datalen <= 0)
1343 1.1.6.2 thorpej i = sbicabort(dev, regs, "icmd out of data");
1344 1.1.6.2 thorpej else {
1345 1.1.6.2 thorpej wait = sbic_data_wait;
1346 1.1.6.2 thorpej if (sbicxfstart(regs, acb->datalen,
1347 1.1.6.2 thorpej SBIC_PHASE(csr), wait))
1348 1.1.6.2 thorpej if (csr & 0x01)
1349 1.1.6.2 thorpej /* data in? */
1350 1.1.6.2 thorpej i = sbicxfin(regs, acb->datalen, acb->data);
1351 1.1.6.2 thorpej else
1352 1.1.6.2 thorpej i = sbicxfout(regs, acb->datalen, acb->data,
1353 1.1.6.2 thorpej SBIC_PHASE(csr));
1354 1.1.6.2 thorpej acb->data += acb->datalen - i;
1355 1.1.6.2 thorpej acb->datalen = i;
1356 1.1.6.2 thorpej i = 1;
1357 1.1.6.2 thorpej }
1358 1.1.6.2 thorpej break;
1359 1.1.6.2 thorpej
1360 1.1.6.2 thorpej #endif
1361 1.1.6.2 thorpej case SBIC_CSR_XFERRED | STATUS_PHASE:
1362 1.1.6.2 thorpej case SBIC_CSR_MIS | STATUS_PHASE:
1363 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | STATUS_PHASE:
1364 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | STATUS_PHASE:
1365 1.1.6.2 thorpej /*
1366 1.1.6.2 thorpej * the sbic does the status/cmd-complete reading ok,
1367 1.1.6.2 thorpej * so do this with its hi-level commands.
1368 1.1.6.2 thorpej */
1369 1.1.6.2 thorpej DBGPRINTF(("SBICICMD status phase\n"), sbic_debug);
1370 1.1.6.2 thorpej
1371 1.1.6.2 thorpej SBIC_TC_PUT(regs, 0);
1372 1.1.6.2 thorpej SET_SBIC_cmd_phase(regs, 0x46);
1373 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN_XFER);
1374 1.1.6.2 thorpej break;
1375 1.1.6.2 thorpej
1376 1.1.6.2 thorpej #if THIS_IS_A_RESERVED_STATE
1377 1.1.6.2 thorpej case BUS_FREE_PHASE: /* This is not legal */
1378 1.1.6.2 thorpej if (dev->sc_stat[0] != 0xff)
1379 1.1.6.2 thorpej goto out;
1380 1.1.6.2 thorpej break;
1381 1.1.6.2 thorpej #endif
1382 1.1.6.2 thorpej
1383 1.1.6.2 thorpej default:
1384 1.1.6.2 thorpej i = sbicnextstate(dev, csr, asr);
1385 1.1.6.2 thorpej }
1386 1.1.6.2 thorpej
1387 1.1.6.2 thorpej /*
1388 1.1.6.2 thorpej * make sure the last command was taken,
1389 1.1.6.2 thorpej * ie. we're not hunting after an ignored command..
1390 1.1.6.2 thorpej */
1391 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1392 1.1.6.2 thorpej
1393 1.1.6.2 thorpej /* tapes may take a loooong time.. */
1394 1.1.6.2 thorpej while (asr & SBIC_ASR_BSY){
1395 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR) {
1396 1.1.6.2 thorpej printf("sbicicmd: Waiting while sbic is "
1397 1.1.6.2 thorpej "jammed, CSR:%02x,ASR:%02x\n",
1398 1.1.6.2 thorpej csr, asr);
1399 1.1.6.2 thorpej #ifdef DDB
1400 1.1.6.2 thorpej Debugger();
1401 1.1.6.2 thorpej #endif
1402 1.1.6.2 thorpej /* SBIC is jammed */
1403 1.1.6.2 thorpej /* DUNNO which direction */
1404 1.1.6.2 thorpej /* Try old direction */
1405 1.1.6.2 thorpej GET_SBIC_data(regs,i);
1406 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1407 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR) /* Wants us to write */
1408 1.1.6.2 thorpej SET_SBIC_data(regs,i);
1409 1.1.6.2 thorpej }
1410 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1411 1.1.6.2 thorpej }
1412 1.1.6.2 thorpej
1413 1.1.6.2 thorpej /*
1414 1.1.6.2 thorpej * wait for last command to complete
1415 1.1.6.2 thorpej */
1416 1.1.6.2 thorpej if (asr & SBIC_ASR_LCI) {
1417 1.1.6.2 thorpej printf("sbicicmd: last command ignored\n");
1418 1.1.6.2 thorpej }
1419 1.1.6.2 thorpej else if (i == 1) /* Bsy */
1420 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, wait);
1421 1.1.6.2 thorpej
1422 1.1.6.2 thorpej /*
1423 1.1.6.2 thorpej * do it again
1424 1.1.6.2 thorpej */
1425 1.1.6.2 thorpej } while (i > 0 && dev->sc_stat[0] == 0xff);
1426 1.1.6.2 thorpej
1427 1.1.6.2 thorpej /* Sometimes we need to do an extra read of the CSR */
1428 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1429 1.1.6.2 thorpej CSR_TRACE('I',csr,asr,0xff);
1430 1.1.6.2 thorpej
1431 1.1.6.2 thorpej #if CSR_LOG_BUF_SIZE
1432 1.1.6.2 thorpej if (reselect_debug > 1)
1433 1.1.6.2 thorpej for (i = 0; i < bufptr; i++)
1434 1.1.6.2 thorpej printf("CSR:%02x", csrbuf[i]);
1435 1.1.6.2 thorpej #endif
1436 1.1.6.2 thorpej
1437 1.1.6.2 thorpej DBGPRINTF(("sbicicmd done(%d,%d):%d =%d=\n",
1438 1.1.6.2 thorpej dev->target, lun,
1439 1.1.6.2 thorpej acb->datalen,
1440 1.1.6.2 thorpej dev->sc_stat[0]),
1441 1.1.6.2 thorpej data_pointer_debug > 1);
1442 1.1.6.2 thorpej
1443 1.1.6.2 thorpej QPRINTF(("=STS:%02x=", dev->sc_stat[0]));
1444 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_ICMD;
1445 1.1.6.2 thorpej
1446 1.1.6.2 thorpej SBIC_TRACE(dev);
1447 1.1.6.2 thorpej return dev->sc_stat[0];
1448 1.1.6.2 thorpej }
1449 1.1.6.2 thorpej
1450 1.1.6.2 thorpej /*
1451 1.1.6.2 thorpej * Finish SCSI xfer command: After the completion interrupt from
1452 1.1.6.2 thorpej * a read/write operation, sequence through the final phases in
1453 1.1.6.2 thorpej * programmed i/o. This routine is a lot like sbicicmd except we
1454 1.1.6.2 thorpej * skip (and don't allow) the select, cmd out and data in/out phases.
1455 1.1.6.2 thorpej */
1456 1.1.6.2 thorpej static void
1457 1.1.6.2 thorpej sbicxfdone(struct sbic_softc *dev, sbic_regmap_p regs, int target)
1458 1.1.6.2 thorpej {
1459 1.1.6.2 thorpej u_char phase, asr, csr;
1460 1.1.6.2 thorpej int s;
1461 1.1.6.2 thorpej
1462 1.1.6.2 thorpej SBIC_TRACE(dev);
1463 1.1.6.2 thorpej QPRINTF(("{"));
1464 1.1.6.2 thorpej s = splbio();
1465 1.1.6.2 thorpej
1466 1.1.6.2 thorpej /*
1467 1.1.6.2 thorpej * have the sbic complete on its own
1468 1.1.6.2 thorpej */
1469 1.1.6.2 thorpej SBIC_TC_PUT(regs, 0);
1470 1.1.6.2 thorpej SET_SBIC_cmd_phase(regs, 0x46);
1471 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SEL_ATN_XFER);
1472 1.1.6.2 thorpej
1473 1.1.6.2 thorpej do {
1474 1.1.6.2 thorpej asr = SBIC_WAIT (regs, SBIC_ASR_INT, 0);
1475 1.1.6.2 thorpej GET_SBIC_csr (regs, csr);
1476 1.1.6.2 thorpej CSR_TRACE('f',csr,asr,target);
1477 1.1.6.2 thorpej QPRINTF(("%02x:", csr));
1478 1.1.6.2 thorpej } while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
1479 1.1.6.2 thorpej && (csr != SBIC_CSR_S_XFERRED));
1480 1.1.6.2 thorpej
1481 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_SELECTED;
1482 1.1.6.2 thorpej
1483 1.1.6.2 thorpej GET_SBIC_cmd_phase (regs, phase);
1484 1.1.6.2 thorpej QPRINTF(("}%02x", phase));
1485 1.1.6.2 thorpej if (phase == 0x60)
1486 1.1.6.2 thorpej GET_SBIC_tlun(regs, dev->sc_stat[0]);
1487 1.1.6.2 thorpej else
1488 1.1.6.2 thorpej sbicerror(dev, regs, csr);
1489 1.1.6.2 thorpej
1490 1.1.6.2 thorpej QPRINTF(("=STS:%02x=\n", dev->sc_stat[0]));
1491 1.1.6.2 thorpej splx(s);
1492 1.1.6.2 thorpej SBIC_TRACE(dev);
1493 1.1.6.2 thorpej }
1494 1.1.6.2 thorpej
1495 1.1.6.2 thorpej /*
1496 1.1.6.2 thorpej * No DMA chains
1497 1.1.6.2 thorpej */
1498 1.1.6.2 thorpej
1499 1.1.6.2 thorpej static int
1500 1.1.6.2 thorpej sbicgo(struct sbic_softc *dev, struct scsipi_xfer *xs)
1501 1.1.6.2 thorpej {
1502 1.1.6.2 thorpej int i, usedma;
1503 1.1.6.2 thorpej /* int dmaflags, count; */
1504 1.1.6.2 thorpej /* int wait;*/
1505 1.1.6.2 thorpej /* u_char cmd;*/
1506 1.1.6.2 thorpej u_char asr = 0, csr = 0;
1507 1.1.6.2 thorpej /* u_char *addr; */
1508 1.1.6.2 thorpej sbic_regmap_p regs;
1509 1.1.6.2 thorpej struct sbic_acb *acb;
1510 1.1.6.2 thorpej
1511 1.1.6.2 thorpej SBIC_TRACE(dev);
1512 1.1.6.2 thorpej dev->target = xs->xs_periph->periph_target;
1513 1.1.6.2 thorpej dev->lun = xs->xs_periph->periph_lun;
1514 1.1.6.2 thorpej acb = dev->sc_nexus;
1515 1.1.6.2 thorpej regs = &dev->sc_sbicp;
1516 1.1.6.2 thorpej
1517 1.1.6.2 thorpej usedma = acb->flags & ACB_DMA;
1518 1.1.6.2 thorpej
1519 1.1.6.2 thorpej DBG(routine = 1);
1520 1.1.6.2 thorpej DBG(debug_sbic_regs = regs); /* store this to allow debug calls */
1521 1.1.6.2 thorpej DBGPRINTF(("sbicgo(%d,%d)\n", dev->target, dev->lun),
1522 1.1.6.2 thorpej data_pointer_debug > 1);
1523 1.1.6.2 thorpej
1524 1.1.6.2 thorpej /*
1525 1.1.6.2 thorpej * set the sbic into DMA mode
1526 1.1.6.2 thorpej */
1527 1.1.6.2 thorpej if (usedma)
1528 1.1.6.2 thorpej SET_SBIC_control(regs,
1529 1.1.6.2 thorpej SBIC_CTL_EDI | SBIC_CTL_IDI | dev->sc_dmamode);
1530 1.1.6.2 thorpej else
1531 1.1.6.2 thorpej SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
1532 1.1.6.2 thorpej
1533 1.1.6.2 thorpej
1534 1.1.6.2 thorpej /*
1535 1.1.6.2 thorpej * select the SCSI bus (it's an error if bus isn't free)
1536 1.1.6.2 thorpej */
1537 1.1.6.2 thorpej if (sbicselectbus(dev, regs, dev->target, dev->lun,
1538 1.1.6.2 thorpej dev->sc_scsiaddr)) {
1539 1.1.6.2 thorpej /* printf("sbicgo: Trying to select busy bus!\n"); */
1540 1.1.6.2 thorpej SBIC_TRACE(dev);
1541 1.1.6.2 thorpej /* Not done: may need to be rescheduled */
1542 1.1.6.2 thorpej return 0;
1543 1.1.6.2 thorpej }
1544 1.1.6.2 thorpej dev->sc_stat[0] = 0xff;
1545 1.1.6.2 thorpej
1546 1.1.6.2 thorpej /*
1547 1.1.6.2 thorpej * Allocate the DMA chain
1548 1.1.6.2 thorpej */
1549 1.1.6.2 thorpej
1550 1.1.6.2 thorpej /* Mark end of segment */
1551 1.1.6.2 thorpej acb->sc_tcnt = 0;
1552 1.1.6.2 thorpej
1553 1.1.6.2 thorpej SBIC_TRACE(dev);
1554 1.1.6.2 thorpej /* Enable interrupts */
1555 1.1.6.2 thorpej dev->sc_enintr(dev);
1556 1.1.6.2 thorpej if (usedma) {
1557 1.1.6.2 thorpej int tcnt;
1558 1.1.6.2 thorpej
1559 1.1.6.2 thorpej acb->offset = 0;
1560 1.1.6.2 thorpej acb->sc_tcnt = 0;
1561 1.1.6.2 thorpej /* Note, this does not start DMA */
1562 1.1.6.2 thorpej tcnt = dev->sc_dmasetup(dev->sc_dmah, dev->sc_dmat, acb,
1563 1.1.6.2 thorpej (acb->flags & ACB_DATAIN) != 0);
1564 1.1.6.2 thorpej
1565 1.1.6.2 thorpej DBG(dev->sc_dmatimo = tcnt ? 1 : 0);
1566 1.1.6.2 thorpej DBG(++sbicdma_ops); /* count total DMA operations */
1567 1.1.6.2 thorpej }
1568 1.1.6.2 thorpej
1569 1.1.6.2 thorpej SBIC_TRACE(dev);
1570 1.1.6.2 thorpej
1571 1.1.6.2 thorpej /*
1572 1.1.6.2 thorpej * enintr() also enables interrupts for the sbic
1573 1.1.6.2 thorpej */
1574 1.1.6.2 thorpej DBG(debug_asr = asr);
1575 1.1.6.2 thorpej DBG(debug_csr = csr);
1576 1.1.6.2 thorpej
1577 1.1.6.2 thorpej /*
1578 1.1.6.2 thorpej * Lets cycle a while then let the interrupt handler take over
1579 1.1.6.2 thorpej */
1580 1.1.6.2 thorpej
1581 1.1.6.2 thorpej asr = GET_SBIC_asr(regs, asr);
1582 1.1.6.2 thorpej do {
1583 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1584 1.1.6.2 thorpej CSR_TRACE('g', csr, asr, dev->target);
1585 1.1.6.2 thorpej
1586 1.1.6.2 thorpej DBG(debug_csr = csr);
1587 1.1.6.2 thorpej DBG(routine = 1);
1588 1.1.6.2 thorpej
1589 1.1.6.2 thorpej QPRINTF(("go[0x%x]", csr));
1590 1.1.6.2 thorpej
1591 1.1.6.2 thorpej i = sbicnextstate(dev, csr, asr);
1592 1.1.6.2 thorpej
1593 1.1.6.2 thorpej WAIT_CIP(regs);
1594 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1595 1.1.6.2 thorpej
1596 1.1.6.2 thorpej DBG(debug_asr = asr);
1597 1.1.6.2 thorpej
1598 1.1.6.2 thorpej if (asr & SBIC_ASR_LCI)
1599 1.1.6.2 thorpej printf("sbicgo: LCI asr:%02x csr:%02x\n", asr, csr);
1600 1.1.6.2 thorpej } while (i == SBIC_STATE_RUNNING &&
1601 1.1.6.2 thorpej (asr & (SBIC_ASR_INT | SBIC_ASR_LCI)));
1602 1.1.6.2 thorpej
1603 1.1.6.2 thorpej CSR_TRACE('g',csr,asr,i<<4);
1604 1.1.6.2 thorpej SBIC_TRACE(dev);
1605 1.1.6.2 thorpej if (i == SBIC_STATE_DONE && dev->sc_stat[0] == 0xff)
1606 1.1.6.2 thorpej printf("sbicgo: done & stat = 0xff\n");
1607 1.1.6.2 thorpej if (i == SBIC_STATE_DONE && dev->sc_stat[0] != 0xff) {
1608 1.1.6.2 thorpej /* if (i == SBIC_STATE_DONE && dev->sc_stat[0]) { */
1609 1.1.6.2 thorpej /* Did we really finish that fast? */
1610 1.1.6.2 thorpej return 1;
1611 1.1.6.2 thorpej }
1612 1.1.6.2 thorpej return 0;
1613 1.1.6.2 thorpej }
1614 1.1.6.2 thorpej
1615 1.1.6.2 thorpej
1616 1.1.6.2 thorpej int
1617 1.1.6.2 thorpej sbicintr(struct sbic_softc *dev)
1618 1.1.6.2 thorpej {
1619 1.1.6.2 thorpej sbic_regmap_p regs;
1620 1.1.6.2 thorpej u_char asr, csr;
1621 1.1.6.2 thorpej /* u_char *tmpaddr;*/
1622 1.1.6.2 thorpej /* struct sbic_acb *acb;*/
1623 1.1.6.2 thorpej int i;
1624 1.1.6.2 thorpej /* int newtarget, newlun;*/
1625 1.1.6.2 thorpej /* unsigned tcnt;*/
1626 1.1.6.2 thorpej
1627 1.1.6.2 thorpej regs = &dev->sc_sbicp;
1628 1.1.6.2 thorpej
1629 1.1.6.2 thorpej /*
1630 1.1.6.2 thorpej * pending interrupt?
1631 1.1.6.2 thorpej */
1632 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1633 1.1.6.2 thorpej if ((asr & SBIC_ASR_INT) == 0)
1634 1.1.6.2 thorpej return 0;
1635 1.1.6.2 thorpej
1636 1.1.6.2 thorpej SBIC_TRACE(dev);
1637 1.1.6.2 thorpej do {
1638 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1639 1.1.6.2 thorpej CSR_TRACE('i',csr,asr,dev->target);
1640 1.1.6.2 thorpej
1641 1.1.6.2 thorpej DBG(debug_csr = csr);
1642 1.1.6.2 thorpej DBG(routine = 2);
1643 1.1.6.2 thorpej
1644 1.1.6.2 thorpej QPRINTF(("intr[0x%x]", csr));
1645 1.1.6.2 thorpej
1646 1.1.6.2 thorpej i = sbicnextstate(dev, csr, asr);
1647 1.1.6.2 thorpej
1648 1.1.6.2 thorpej WAIT_CIP(regs);
1649 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1650 1.1.6.2 thorpej
1651 1.1.6.2 thorpej DBG(debug_asr = asr);
1652 1.1.6.2 thorpej
1653 1.1.6.2 thorpej #if 0
1654 1.1.6.2 thorpej if (asr & SBIC_ASR_LCI)
1655 1.1.6.2 thorpej printf("sbicintr: LCI asr:%02x csr:%02x\n", asr, csr);
1656 1.1.6.2 thorpej #endif
1657 1.1.6.2 thorpej } while (i == SBIC_STATE_RUNNING &&
1658 1.1.6.2 thorpej (asr & (SBIC_ASR_INT | SBIC_ASR_LCI)));
1659 1.1.6.2 thorpej CSR_TRACE('i', csr, asr, i << 4);
1660 1.1.6.2 thorpej SBIC_TRACE(dev);
1661 1.1.6.2 thorpej return 1;
1662 1.1.6.2 thorpej }
1663 1.1.6.2 thorpej
1664 1.1.6.2 thorpej /*
1665 1.1.6.2 thorpej * Run commands and wait for disconnect
1666 1.1.6.2 thorpej */
1667 1.1.6.2 thorpej static int
1668 1.1.6.2 thorpej sbicpoll(struct sbic_softc *dev)
1669 1.1.6.2 thorpej {
1670 1.1.6.2 thorpej sbic_regmap_p regs;
1671 1.1.6.2 thorpej u_char asr, csr;
1672 1.1.6.2 thorpej /* struct sbic_pending* pendp;*/
1673 1.1.6.2 thorpej int i;
1674 1.1.6.2 thorpej /* unsigned tcnt;*/
1675 1.1.6.2 thorpej
1676 1.1.6.2 thorpej SBIC_TRACE(dev);
1677 1.1.6.2 thorpej regs = &dev->sc_sbicp;
1678 1.1.6.2 thorpej
1679 1.1.6.2 thorpej do {
1680 1.1.6.2 thorpej GET_SBIC_asr (regs, asr);
1681 1.1.6.2 thorpej
1682 1.1.6.2 thorpej DBG(debug_asr = asr);
1683 1.1.6.2 thorpej
1684 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1685 1.1.6.2 thorpej CSR_TRACE('p', csr, asr, dev->target);
1686 1.1.6.2 thorpej
1687 1.1.6.2 thorpej DBG(debug_csr = csr);
1688 1.1.6.2 thorpej DBG(routine = 2);
1689 1.1.6.2 thorpej
1690 1.1.6.2 thorpej QPRINTF(("poll[0x%x]", csr));
1691 1.1.6.2 thorpej
1692 1.1.6.2 thorpej i = sbicnextstate(dev, csr, asr);
1693 1.1.6.2 thorpej
1694 1.1.6.2 thorpej WAIT_CIP(regs);
1695 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1696 1.1.6.2 thorpej /* tapes may take a loooong time.. */
1697 1.1.6.2 thorpej while (asr & SBIC_ASR_BSY){
1698 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR) {
1699 1.1.6.2 thorpej printf("sbipoll: Waiting while sbic is "
1700 1.1.6.2 thorpej "jammed, CSR:%02x,ASR:%02x\n",
1701 1.1.6.2 thorpej csr, asr);
1702 1.1.6.2 thorpej #ifdef DDB
1703 1.1.6.2 thorpej Debugger();
1704 1.1.6.2 thorpej #endif
1705 1.1.6.2 thorpej /* SBIC is jammed */
1706 1.1.6.2 thorpej /* DUNNO which direction */
1707 1.1.6.2 thorpej /* Try old direction */
1708 1.1.6.2 thorpej GET_SBIC_data(regs,i);
1709 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1710 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR) /* Wants us to write */
1711 1.1.6.2 thorpej SET_SBIC_data(regs,i);
1712 1.1.6.2 thorpej }
1713 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1714 1.1.6.2 thorpej }
1715 1.1.6.2 thorpej
1716 1.1.6.2 thorpej if (asr & SBIC_ASR_LCI)
1717 1.1.6.2 thorpej printf("sbicpoll: LCI asr:%02x csr:%02x\n", asr, csr);
1718 1.1.6.2 thorpej else if (i == 1) /* BSY */
1719 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, sbic_cmd_wait);
1720 1.1.6.2 thorpej } while (i == SBIC_STATE_RUNNING);
1721 1.1.6.2 thorpej CSR_TRACE('p', csr, asr, i << 4);
1722 1.1.6.2 thorpej SBIC_TRACE(dev);
1723 1.1.6.2 thorpej return 1;
1724 1.1.6.2 thorpej }
1725 1.1.6.2 thorpej
1726 1.1.6.2 thorpej /*
1727 1.1.6.2 thorpej * Handle a single msgin
1728 1.1.6.2 thorpej */
1729 1.1.6.2 thorpej
1730 1.1.6.2 thorpej static int
1731 1.1.6.2 thorpej sbicmsgin(struct sbic_softc *dev)
1732 1.1.6.2 thorpej {
1733 1.1.6.2 thorpej sbic_regmap_p regs;
1734 1.1.6.2 thorpej int recvlen;
1735 1.1.6.2 thorpej u_char asr, csr, *tmpaddr;
1736 1.1.6.2 thorpej
1737 1.1.6.2 thorpej regs = &dev->sc_sbicp;
1738 1.1.6.2 thorpej
1739 1.1.6.2 thorpej dev->sc_msg[0] = 0xff;
1740 1.1.6.2 thorpej dev->sc_msg[1] = 0xff;
1741 1.1.6.2 thorpej
1742 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1743 1.1.6.2 thorpej
1744 1.1.6.2 thorpej DBGPRINTF(("sbicmsgin asr=%02x\n", asr), reselect_debug > 1);
1745 1.1.6.2 thorpej
1746 1.1.6.2 thorpej sbic_save_ptrs(dev, regs);
1747 1.1.6.2 thorpej
1748 1.1.6.2 thorpej GET_SBIC_selid (regs, csr);
1749 1.1.6.2 thorpej SET_SBIC_selid (regs, csr | SBIC_SID_FROM_SCSI);
1750 1.1.6.2 thorpej
1751 1.1.6.2 thorpej SBIC_TC_PUT(regs, 0);
1752 1.1.6.2 thorpej tmpaddr = dev->sc_msg;
1753 1.1.6.2 thorpej recvlen = 1;
1754 1.1.6.2 thorpej do {
1755 1.1.6.2 thorpej while (recvlen--) {
1756 1.1.6.2 thorpej asr = GET_SBIC_asr(regs, asr);
1757 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1758 1.1.6.2 thorpej QPRINTF(("sbicmsgin ready to go (csr,asr)=(%02x,%02x)\n",
1759 1.1.6.2 thorpej csr, asr));
1760 1.1.6.2 thorpej
1761 1.1.6.2 thorpej RECV_BYTE(regs, *tmpaddr);
1762 1.1.6.2 thorpej CSR_TRACE('m', csr, asr, *tmpaddr);
1763 1.1.6.2 thorpej #if 1
1764 1.1.6.2 thorpej /*
1765 1.1.6.2 thorpej * get the command completion interrupt, or we
1766 1.1.6.2 thorpej * can't send a new command (LCI)
1767 1.1.6.2 thorpej */
1768 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
1769 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1770 1.1.6.2 thorpej CSR_TRACE('X', csr, asr, dev->target);
1771 1.1.6.2 thorpej #else
1772 1.1.6.2 thorpej WAIT_CIP(regs);
1773 1.1.6.2 thorpej do {
1774 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1775 1.1.6.2 thorpej csr = 0xff;
1776 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1777 1.1.6.2 thorpej CSR_TRACE('X', csr, asr, dev->target);
1778 1.1.6.2 thorpej if (csr == 0xff)
1779 1.1.6.2 thorpej printf("sbicmsgin waiting: csr %02x "
1780 1.1.6.2 thorpej "asr %02x\n", csr, asr);
1781 1.1.6.2 thorpej } while (csr == 0xff);
1782 1.1.6.2 thorpej #endif
1783 1.1.6.2 thorpej
1784 1.1.6.2 thorpej DBGPRINTF(("sbicmsgin: got %02x csr %02x asr %02x\n",
1785 1.1.6.2 thorpej *tmpaddr, csr, asr), reselect_debug > 1);
1786 1.1.6.2 thorpej
1787 1.1.6.2 thorpej #if do_parity_check
1788 1.1.6.2 thorpej if (asr & SBIC_ASR_PE) {
1789 1.1.6.2 thorpej printf("Parity error");
1790 1.1.6.2 thorpej /* This code simply does not work. */
1791 1.1.6.2 thorpej WAIT_CIP(regs);
1792 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
1793 1.1.6.2 thorpej WAIT_CIP(regs);
1794 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1795 1.1.6.2 thorpej WAIT_CIP(regs);
1796 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
1797 1.1.6.2 thorpej WAIT_CIP(regs);
1798 1.1.6.2 thorpej if (!(asr & SBIC_ASR_LCI))
1799 1.1.6.2 thorpej /* Target wants to send garbled msg*/
1800 1.1.6.2 thorpej continue;
1801 1.1.6.2 thorpej printf("--fixing\n");
1802 1.1.6.2 thorpej /* loop until a msgout phase occurs on
1803 1.1.6.2 thorpej target */
1804 1.1.6.2 thorpej while ((csr & 0x07) != MESG_OUT_PHASE) {
1805 1.1.6.2 thorpej while ((asr & SBIC_ASR_BSY) &&
1806 1.1.6.2 thorpej !(asr &
1807 1.1.6.2 thorpej (SBIC_ASR_DBR | SBIC_ASR_INT)))
1808 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1809 1.1.6.2 thorpej if (asr & SBIC_ASR_DBR)
1810 1.1.6.4 jdolecek panic("msgin: jammed again!");
1811 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1812 1.1.6.2 thorpej CSR_TRACE('e', csr, asr, dev->target);
1813 1.1.6.2 thorpej if ((csr & 0x07) != MESG_OUT_PHASE) {
1814 1.1.6.2 thorpej sbicnextstate(dev, csr, asr);
1815 1.1.6.2 thorpej sbic_save_ptrs(dev, regs);
1816 1.1.6.2 thorpej }
1817 1.1.6.2 thorpej }
1818 1.1.6.2 thorpej /* Should be msg out by now */
1819 1.1.6.2 thorpej SEND_BYTE(regs, MSG_PARITY_ERROR);
1820 1.1.6.2 thorpej }
1821 1.1.6.2 thorpej else
1822 1.1.6.2 thorpej #endif
1823 1.1.6.2 thorpej tmpaddr++;
1824 1.1.6.2 thorpej
1825 1.1.6.2 thorpej if (recvlen) {
1826 1.1.6.2 thorpej /* Clear ACK */
1827 1.1.6.2 thorpej WAIT_CIP(regs);
1828 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1829 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1830 1.1.6.2 thorpej CSR_TRACE('X',csr,asr,dev->target);
1831 1.1.6.2 thorpej QPRINTF(("sbicmsgin pre byte CLR_ACK (csr,asr)=(%02x,%02x)\n",
1832 1.1.6.2 thorpej csr, asr));
1833 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
1834 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
1835 1.1.6.2 thorpej }
1836 1.1.6.2 thorpej
1837 1.1.6.2 thorpej };
1838 1.1.6.2 thorpej
1839 1.1.6.2 thorpej if (dev->sc_msg[0] == 0xff) {
1840 1.1.6.2 thorpej printf("sbicmsgin: sbic swallowed our message\n");
1841 1.1.6.2 thorpej break;
1842 1.1.6.2 thorpej }
1843 1.1.6.2 thorpej
1844 1.1.6.2 thorpej DBGPRINTF(("msgin done csr 0x%x asr 0x%x msg 0x%x\n",
1845 1.1.6.2 thorpej csr, asr, dev->sc_msg[0]), sync_debug);
1846 1.1.6.2 thorpej
1847 1.1.6.2 thorpej /*
1848 1.1.6.2 thorpej * test whether this is a reply to our sync
1849 1.1.6.2 thorpej * request
1850 1.1.6.2 thorpej */
1851 1.1.6.2 thorpej if (MSG_ISIDENTIFY(dev->sc_msg[0])) {
1852 1.1.6.2 thorpej QPRINTF(("IFFY"));
1853 1.1.6.2 thorpej /* Got IFFY msg -- ack it */
1854 1.1.6.2 thorpej } else if (dev->sc_msg[0] == MSG_REJECT
1855 1.1.6.2 thorpej && dev->sc_sync[dev->target].state == SYNC_SENT) {
1856 1.1.6.2 thorpej QPRINTF(("REJECT of SYN"));
1857 1.1.6.2 thorpej
1858 1.1.6.2 thorpej DBGPRINTF(("target %d rejected sync, going async\n",
1859 1.1.6.2 thorpej dev->target), sync_debug);
1860 1.1.6.2 thorpej
1861 1.1.6.2 thorpej dev->sc_sync[dev->target].period = sbic_min_period;
1862 1.1.6.2 thorpej dev->sc_sync[dev->target].offset = 0;
1863 1.1.6.2 thorpej dev->sc_sync[dev->target].state = SYNC_DONE;
1864 1.1.6.2 thorpej SET_SBIC_syn(regs,
1865 1.1.6.2 thorpej SBIC_SYN(dev->sc_sync[dev->target].offset,
1866 1.1.6.2 thorpej dev->sc_sync[dev->target].period));
1867 1.1.6.2 thorpej } else if ((dev->sc_msg[0] == MSG_REJECT)) {
1868 1.1.6.2 thorpej QPRINTF(("REJECT"));
1869 1.1.6.2 thorpej /*
1870 1.1.6.2 thorpej * we'll never REJECt a REJECT message..
1871 1.1.6.2 thorpej */
1872 1.1.6.2 thorpej } else if ((dev->sc_msg[0] == MSG_SAVE_DATA_PTR)) {
1873 1.1.6.2 thorpej QPRINTF(("MSG_SAVE_DATA_PTR"));
1874 1.1.6.2 thorpej /*
1875 1.1.6.2 thorpej * don't reject this either.
1876 1.1.6.2 thorpej */
1877 1.1.6.2 thorpej } else if ((dev->sc_msg[0] == MSG_DISCONNECT)) {
1878 1.1.6.2 thorpej QPRINTF(("DISCONNECT"));
1879 1.1.6.2 thorpej
1880 1.1.6.2 thorpej DBGPRINTF(("sbicmsgin: got disconnect msg %s\n",
1881 1.1.6.2 thorpej (dev->sc_flags & SBICF_ICMD) ? "rejecting" : ""),
1882 1.1.6.2 thorpej reselect_debug > 1 &&
1883 1.1.6.2 thorpej dev->sc_msg[0] == MSG_DISCONNECT);
1884 1.1.6.2 thorpej
1885 1.1.6.2 thorpej if (dev->sc_flags & SBICF_ICMD) {
1886 1.1.6.2 thorpej /* We're in immediate mode. Prevent
1887 1.1.6.2 thorpej disconnects. */
1888 1.1.6.2 thorpej /* prepare to reject the message, NACK */
1889 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
1890 1.1.6.2 thorpej WAIT_CIP(regs);
1891 1.1.6.2 thorpej }
1892 1.1.6.2 thorpej } else if (dev->sc_msg[0] == MSG_CMD_COMPLETE) {
1893 1.1.6.2 thorpej QPRINTF(("CMD_COMPLETE"));
1894 1.1.6.2 thorpej /* !! KLUDGE ALERT !! quite a few drives don't seem to
1895 1.1.6.2 thorpej * really like the current way of sending the
1896 1.1.6.2 thorpej * sync-handshake together with the ident-message, and
1897 1.1.6.2 thorpej * they react by sending command-complete and
1898 1.1.6.2 thorpej * disconnecting right after returning the valid sync
1899 1.1.6.2 thorpej * handshake. So, all I can do is reselect the drive,
1900 1.1.6.2 thorpej * and hope it won't disconnect again. I don't think
1901 1.1.6.2 thorpej * this is valid behavior, but I can't help fixing a
1902 1.1.6.2 thorpej * problem that apparently exists.
1903 1.1.6.2 thorpej *
1904 1.1.6.2 thorpej * Note: we should not get here on `normal' command
1905 1.1.6.2 thorpej * completion, as that condition is handled by the
1906 1.1.6.2 thorpej * high-level sel&xfer resume command used to walk
1907 1.1.6.2 thorpej * thru status/cc-phase.
1908 1.1.6.2 thorpej */
1909 1.1.6.2 thorpej
1910 1.1.6.2 thorpej DBGPRINTF(("GOT MSG %d! target %d acting weird.."
1911 1.1.6.2 thorpej " waiting for disconnect...\n",
1912 1.1.6.2 thorpej dev->sc_msg[0], dev->target), sync_debug);
1913 1.1.6.2 thorpej
1914 1.1.6.2 thorpej /* Check to see if sbic is handling this */
1915 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1916 1.1.6.2 thorpej if (asr & SBIC_ASR_BSY)
1917 1.1.6.2 thorpej return SBIC_STATE_RUNNING;
1918 1.1.6.2 thorpej
1919 1.1.6.2 thorpej /* Let's try this: Assume it works and set
1920 1.1.6.2 thorpej status to 00 */
1921 1.1.6.2 thorpej dev->sc_stat[0] = 0;
1922 1.1.6.2 thorpej } else if (dev->sc_msg[0] == MSG_EXT_MESSAGE
1923 1.1.6.2 thorpej && tmpaddr == &dev->sc_msg[1]) {
1924 1.1.6.2 thorpej QPRINTF(("ExtMSG\n"));
1925 1.1.6.2 thorpej /* Read in whole extended message */
1926 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
1927 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
1928 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1929 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1930 1.1.6.2 thorpej QPRINTF(("CLR ACK asr %02x, csr %02x\n", asr, csr));
1931 1.1.6.2 thorpej RECV_BYTE(regs, *tmpaddr);
1932 1.1.6.2 thorpej CSR_TRACE('x',csr,asr,*tmpaddr);
1933 1.1.6.2 thorpej /* Wait for command completion IRQ */
1934 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
1935 1.1.6.2 thorpej recvlen = *tmpaddr++;
1936 1.1.6.2 thorpej QPRINTF(("Recving ext msg, asr %02x csr %02x len %02x\n",
1937 1.1.6.2 thorpej asr, csr, recvlen));
1938 1.1.6.2 thorpej } else if (dev->sc_msg[0] == MSG_EXT_MESSAGE &&
1939 1.1.6.2 thorpej dev->sc_msg[1] == 3 &&
1940 1.1.6.2 thorpej dev->sc_msg[2] == MSG_SYNC_REQ) {
1941 1.1.6.2 thorpej QPRINTF(("SYN"));
1942 1.1.6.2 thorpej dev->sc_sync[dev->target].period =
1943 1.1.6.2 thorpej sbicfromscsiperiod(dev,
1944 1.1.6.2 thorpej regs, dev->sc_msg[3]);
1945 1.1.6.2 thorpej dev->sc_sync[dev->target].offset = dev->sc_msg[4];
1946 1.1.6.2 thorpej dev->sc_sync[dev->target].state = SYNC_DONE;
1947 1.1.6.2 thorpej SET_SBIC_syn(regs,
1948 1.1.6.2 thorpej SBIC_SYN(dev->sc_sync[dev->target].offset,
1949 1.1.6.2 thorpej dev->sc_sync[dev->target].period));
1950 1.1.6.2 thorpej printf("%s: target %d now synchronous,"
1951 1.1.6.2 thorpej " period=%dns, offset=%d.\n",
1952 1.1.6.2 thorpej dev->sc_dev.dv_xname, dev->target,
1953 1.1.6.2 thorpej dev->sc_msg[3] * 4, dev->sc_msg[4]);
1954 1.1.6.2 thorpej } else {
1955 1.1.6.2 thorpej
1956 1.1.6.2 thorpej DBGPRINTF(("sbicmsgin: Rejecting message 0x%02x\n",
1957 1.1.6.2 thorpej dev->sc_msg[0]), sbic_debug || sync_debug);
1958 1.1.6.2 thorpej
1959 1.1.6.2 thorpej /* prepare to reject the message, NACK */
1960 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_SET_ATN);
1961 1.1.6.2 thorpej WAIT_CIP(regs);
1962 1.1.6.2 thorpej }
1963 1.1.6.2 thorpej /* Clear ACK */
1964 1.1.6.2 thorpej WAIT_CIP(regs);
1965 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
1966 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
1967 1.1.6.2 thorpej CSR_TRACE('X',csr,asr,dev->target);
1968 1.1.6.2 thorpej QPRINTF(("sbicmsgin pre CLR_ACK (csr,asr)=(%02x,%02x)%d\n",
1969 1.1.6.2 thorpej csr, asr, recvlen));
1970 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
1971 1.1.6.2 thorpej SBIC_WAIT(regs, SBIC_ASR_INT, 0);
1972 1.1.6.2 thorpej }
1973 1.1.6.2 thorpej #if 0
1974 1.1.6.2 thorpej while ((csr == SBIC_CSR_MSGIN_W_ACK) ||
1975 1.1.6.2 thorpej (SBIC_PHASE(csr) == MESG_IN_PHASE));
1976 1.1.6.2 thorpej #else
1977 1.1.6.2 thorpej while (recvlen > 0);
1978 1.1.6.2 thorpej #endif
1979 1.1.6.2 thorpej
1980 1.1.6.2 thorpej QPRINTF(("sbicmsgin finished: csr %02x, asr %02x\n",csr, asr));
1981 1.1.6.2 thorpej
1982 1.1.6.2 thorpej /* Should still have one CSR to read */
1983 1.1.6.2 thorpej return SBIC_STATE_RUNNING;
1984 1.1.6.2 thorpej }
1985 1.1.6.2 thorpej
1986 1.1.6.2 thorpej
1987 1.1.6.2 thorpej /*
1988 1.1.6.2 thorpej * sbicnextstate()
1989 1.1.6.2 thorpej * return:
1990 1.1.6.2 thorpej * 0 == done
1991 1.1.6.2 thorpej * 1 == working
1992 1.1.6.2 thorpej * 2 == disconnected
1993 1.1.6.2 thorpej * -1 == error
1994 1.1.6.2 thorpej */
1995 1.1.6.2 thorpej static int
1996 1.1.6.2 thorpej sbicnextstate(struct sbic_softc *dev, u_char csr, u_char asr)
1997 1.1.6.2 thorpej {
1998 1.1.6.2 thorpej sbic_regmap_p regs;
1999 1.1.6.2 thorpej struct sbic_acb *acb;
2000 1.1.6.2 thorpej /* int i;*/
2001 1.1.6.2 thorpej int newtarget, newlun, wait;
2002 1.1.6.2 thorpej /* unsigned tcnt;*/
2003 1.1.6.2 thorpej
2004 1.1.6.2 thorpej SBIC_TRACE(dev);
2005 1.1.6.2 thorpej regs = &dev->sc_sbicp;
2006 1.1.6.2 thorpej acb = dev->sc_nexus;
2007 1.1.6.2 thorpej
2008 1.1.6.2 thorpej QPRINTF(("next[%02x,%02x]",asr,csr));
2009 1.1.6.2 thorpej
2010 1.1.6.2 thorpej switch (csr) {
2011 1.1.6.2 thorpej case SBIC_CSR_XFERRED | CMD_PHASE:
2012 1.1.6.2 thorpej case SBIC_CSR_MIS | CMD_PHASE:
2013 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | CMD_PHASE:
2014 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | CMD_PHASE:
2015 1.1.6.2 thorpej sbic_save_ptrs(dev, regs);
2016 1.1.6.2 thorpej if (sbicxfstart(regs, acb->clen, CMD_PHASE, sbic_cmd_wait))
2017 1.1.6.2 thorpej if (sbicxfout(regs, acb->clen,
2018 1.1.6.2 thorpej &acb->cmd, CMD_PHASE))
2019 1.1.6.2 thorpej goto abort;
2020 1.1.6.2 thorpej break;
2021 1.1.6.2 thorpej
2022 1.1.6.2 thorpej case SBIC_CSR_XFERRED | STATUS_PHASE:
2023 1.1.6.2 thorpej case SBIC_CSR_MIS | STATUS_PHASE:
2024 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | STATUS_PHASE:
2025 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | STATUS_PHASE:
2026 1.1.6.2 thorpej /*
2027 1.1.6.2 thorpej * this should be the normal i/o completion case.
2028 1.1.6.2 thorpej * get the status & cmd complete msg then let the
2029 1.1.6.2 thorpej * device driver look at what happened.
2030 1.1.6.2 thorpej */
2031 1.1.6.2 thorpej sbicxfdone(dev,regs,dev->target);
2032 1.1.6.2 thorpej
2033 1.1.6.2 thorpej if (acb->flags & ACB_DMA) {
2034 1.1.6.2 thorpej DBG(dev->sc_dmatimo = 0);
2035 1.1.6.2 thorpej
2036 1.1.6.2 thorpej dev->sc_dmafinish(dev->sc_dmah, dev->sc_dmat, acb);
2037 1.1.6.2 thorpej
2038 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_INDMA;
2039 1.1.6.2 thorpej }
2040 1.1.6.2 thorpej sbic_scsidone(acb, dev->sc_stat[0]);
2041 1.1.6.2 thorpej SBIC_TRACE(dev);
2042 1.1.6.2 thorpej return SBIC_STATE_DONE;
2043 1.1.6.2 thorpej
2044 1.1.6.2 thorpej case SBIC_CSR_XFERRED | DATA_OUT_PHASE:
2045 1.1.6.2 thorpej case SBIC_CSR_XFERRED | DATA_IN_PHASE:
2046 1.1.6.2 thorpej case SBIC_CSR_MIS | DATA_OUT_PHASE:
2047 1.1.6.2 thorpej case SBIC_CSR_MIS | DATA_IN_PHASE:
2048 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | DATA_OUT_PHASE:
2049 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | DATA_IN_PHASE:
2050 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | DATA_OUT_PHASE:
2051 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | DATA_IN_PHASE:
2052 1.1.6.2 thorpej {
2053 1.1.6.2 thorpej int i = 0;
2054 1.1.6.2 thorpej
2055 1.1.6.2 thorpej if ((acb->xs->xs_control & XS_CTL_POLL) ||
2056 1.1.6.2 thorpej (dev->sc_flags & SBICF_ICMD) ||
2057 1.1.6.2 thorpej (acb->flags & ACB_DMA) == 0) {
2058 1.1.6.2 thorpej /* Do PIO */
2059 1.1.6.2 thorpej SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
2060 1.1.6.2 thorpej if (acb->datalen <= 0) {
2061 1.1.6.2 thorpej printf("sbicnextstate:xfer count %d asr%x csr%x\n",
2062 1.1.6.2 thorpej acb->datalen, asr, csr);
2063 1.1.6.2 thorpej goto abort;
2064 1.1.6.2 thorpej }
2065 1.1.6.2 thorpej wait = sbic_data_wait;
2066 1.1.6.2 thorpej if (sbicxfstart(regs, acb->datalen,
2067 1.1.6.2 thorpej SBIC_PHASE(csr), wait)) {
2068 1.1.6.2 thorpej if (SBIC_PHASE(csr) == DATA_IN_PHASE)
2069 1.1.6.2 thorpej /* data in? */
2070 1.1.6.2 thorpej i = sbicxfin(regs, acb->datalen,
2071 1.1.6.2 thorpej acb->data);
2072 1.1.6.2 thorpej else
2073 1.1.6.2 thorpej i = sbicxfout(regs, acb->datalen,
2074 1.1.6.2 thorpej acb->data, SBIC_PHASE(csr));
2075 1.1.6.2 thorpej }
2076 1.1.6.2 thorpej acb->data += acb->datalen - i;
2077 1.1.6.2 thorpej acb->datalen = i;
2078 1.1.6.2 thorpej } else {
2079 1.1.6.2 thorpej /* Transfer = using DMA */
2080 1.1.6.2 thorpej /*
2081 1.1.6.2 thorpej * do scatter-gather dma
2082 1.1.6.2 thorpej * hacking the controller chip, ouch..
2083 1.1.6.2 thorpej */
2084 1.1.6.2 thorpej SET_SBIC_control(regs,
2085 1.1.6.2 thorpej SBIC_CTL_EDI | SBIC_CTL_IDI | dev->sc_dmamode);
2086 1.1.6.2 thorpej /*
2087 1.1.6.2 thorpej * set next dma addr and dec count
2088 1.1.6.2 thorpej */
2089 1.1.6.2 thorpej sbic_save_ptrs(dev, regs);
2090 1.1.6.2 thorpej
2091 1.1.6.2 thorpej if (acb->offset >= acb->datalen) {
2092 1.1.6.2 thorpej printf("sbicnextstate:xfer offset %d asr%x csr%x\n",
2093 1.1.6.2 thorpej acb->offset, asr, csr);
2094 1.1.6.2 thorpej goto abort;
2095 1.1.6.2 thorpej }
2096 1.1.6.2 thorpej DBGPRINTF(("next dmanext: %d(offset %d)\n",
2097 1.1.6.2 thorpej dev->target, acb->offset),
2098 1.1.6.2 thorpej data_pointer_debug > 1);
2099 1.1.6.2 thorpej DBG(dev->sc_dmatimo = 1);
2100 1.1.6.2 thorpej
2101 1.1.6.2 thorpej acb->sc_tcnt =
2102 1.1.6.2 thorpej dev->sc_dmanext(dev->sc_dmah, dev->sc_dmat,
2103 1.1.6.2 thorpej acb, acb->offset);
2104 1.1.6.2 thorpej DBGPRINTF(("dmanext transfering %ld bytes\n",
2105 1.1.6.2 thorpej acb->sc_tcnt), data_pointer_debug);
2106 1.1.6.2 thorpej SBIC_TC_PUT(regs, (unsigned)acb->sc_tcnt);
2107 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_XFER_INFO);
2108 1.1.6.2 thorpej dev->sc_flags |= SBICF_INDMA;
2109 1.1.6.2 thorpej }
2110 1.1.6.2 thorpej break;
2111 1.1.6.2 thorpej }
2112 1.1.6.2 thorpej case SBIC_CSR_XFERRED | MESG_IN_PHASE:
2113 1.1.6.2 thorpej case SBIC_CSR_MIS | MESG_IN_PHASE:
2114 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | MESG_IN_PHASE:
2115 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | MESG_IN_PHASE:
2116 1.1.6.2 thorpej SBIC_TRACE(dev);
2117 1.1.6.2 thorpej return sbicmsgin(dev);
2118 1.1.6.2 thorpej
2119 1.1.6.2 thorpej case SBIC_CSR_MSGIN_W_ACK:
2120 1.1.6.2 thorpej /* Dunno what I'm ACKing */
2121 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
2122 1.1.6.2 thorpej printf("Acking unknown msgin CSR:%02x",csr);
2123 1.1.6.2 thorpej break;
2124 1.1.6.2 thorpej
2125 1.1.6.2 thorpej case SBIC_CSR_XFERRED | MESG_OUT_PHASE:
2126 1.1.6.2 thorpej case SBIC_CSR_MIS | MESG_OUT_PHASE:
2127 1.1.6.2 thorpej case SBIC_CSR_MIS_1 | MESG_OUT_PHASE:
2128 1.1.6.2 thorpej case SBIC_CSR_MIS_2 | MESG_OUT_PHASE:
2129 1.1.6.2 thorpej
2130 1.1.6.2 thorpej DBGPRINTF(("sending REJECT msg to last msg.\n"), sync_debug);
2131 1.1.6.2 thorpej
2132 1.1.6.2 thorpej sbic_save_ptrs(dev, regs);
2133 1.1.6.2 thorpej /*
2134 1.1.6.2 thorpej * Should only get here on reject, since it's always
2135 1.1.6.2 thorpej * US that initiate a sync transfer.
2136 1.1.6.2 thorpej */
2137 1.1.6.2 thorpej SEND_BYTE(regs, MSG_REJECT);
2138 1.1.6.2 thorpej WAIT_CIP(regs);
2139 1.1.6.2 thorpej if (asr & (SBIC_ASR_BSY | SBIC_ASR_LCI | SBIC_ASR_CIP))
2140 1.1.6.2 thorpej printf("next: REJECT sent asr %02x\n", asr);
2141 1.1.6.2 thorpej SBIC_TRACE(dev);
2142 1.1.6.2 thorpej return SBIC_STATE_RUNNING;
2143 1.1.6.2 thorpej
2144 1.1.6.2 thorpej case SBIC_CSR_DISC:
2145 1.1.6.2 thorpej case SBIC_CSR_DISC_1:
2146 1.1.6.2 thorpej dev->sc_flags &= ~(SBICF_INDMA | SBICF_SELECTED);
2147 1.1.6.2 thorpej
2148 1.1.6.2 thorpej /* Try to schedule another target */
2149 1.1.6.2 thorpej DBGPRINTF(("sbicnext target %d disconnected\n", dev->target),
2150 1.1.6.2 thorpej reselect_debug > 1);
2151 1.1.6.2 thorpej
2152 1.1.6.2 thorpej TAILQ_INSERT_HEAD(&dev->nexus_list, acb, chain);
2153 1.1.6.2 thorpej ++dev->sc_tinfo[dev->target].dconns;
2154 1.1.6.2 thorpej dev->sc_nexus = NULL;
2155 1.1.6.2 thorpej
2156 1.1.6.2 thorpej if ((acb->xs->xs_control & XS_CTL_POLL)
2157 1.1.6.2 thorpej || (dev->sc_flags & SBICF_ICMD)
2158 1.1.6.2 thorpej || (!sbic_parallel_operations)) {
2159 1.1.6.2 thorpej SBIC_TRACE(dev);
2160 1.1.6.2 thorpej return SBIC_STATE_DISCONNECT;
2161 1.1.6.2 thorpej }
2162 1.1.6.2 thorpej sbic_sched(dev);
2163 1.1.6.2 thorpej SBIC_TRACE(dev);
2164 1.1.6.2 thorpej return SBIC_STATE_DISCONNECT;
2165 1.1.6.2 thorpej
2166 1.1.6.2 thorpej case SBIC_CSR_RSLT_NI:
2167 1.1.6.2 thorpej case SBIC_CSR_RSLT_IFY:
2168 1.1.6.2 thorpej GET_SBIC_rselid(regs, newtarget);
2169 1.1.6.2 thorpej /* check SBIC_RID_SIV? */
2170 1.1.6.2 thorpej newtarget &= SBIC_RID_MASK;
2171 1.1.6.2 thorpej if (csr == SBIC_CSR_RSLT_IFY) {
2172 1.1.6.2 thorpej /* Read IFY msg to avoid lockup */
2173 1.1.6.2 thorpej GET_SBIC_data(regs, newlun);
2174 1.1.6.2 thorpej WAIT_CIP(regs);
2175 1.1.6.2 thorpej newlun &= SBIC_TLUN_MASK;
2176 1.1.6.2 thorpej CSR_TRACE('r',csr,asr,newtarget);
2177 1.1.6.2 thorpej } else {
2178 1.1.6.2 thorpej /* Need to get IFY message */
2179 1.1.6.2 thorpej for (newlun = 256; newlun; --newlun) {
2180 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
2181 1.1.6.2 thorpej if (asr & SBIC_ASR_INT)
2182 1.1.6.2 thorpej break;
2183 1.1.6.2 thorpej delay(1);
2184 1.1.6.2 thorpej }
2185 1.1.6.2 thorpej newlun = 0; /* XXXX */
2186 1.1.6.2 thorpej if ((asr & SBIC_ASR_INT) == 0) {
2187 1.1.6.2 thorpej
2188 1.1.6.2 thorpej DBGPRINTF(("RSLT_NI - no IFFY message? asr %x\n",
2189 1.1.6.2 thorpej asr), reselect_debug);
2190 1.1.6.2 thorpej
2191 1.1.6.2 thorpej } else {
2192 1.1.6.2 thorpej GET_SBIC_csr(regs,csr);
2193 1.1.6.2 thorpej CSR_TRACE('n',csr,asr,newtarget);
2194 1.1.6.2 thorpej if ((csr == (SBIC_CSR_MIS | MESG_IN_PHASE)) ||
2195 1.1.6.2 thorpej (csr == (SBIC_CSR_MIS_1 | MESG_IN_PHASE)) ||
2196 1.1.6.2 thorpej (csr == (SBIC_CSR_MIS_2 | MESG_IN_PHASE))) {
2197 1.1.6.2 thorpej sbicmsgin(dev);
2198 1.1.6.2 thorpej newlun = dev->sc_msg[0] & 7;
2199 1.1.6.2 thorpej } else {
2200 1.1.6.2 thorpej printf("RSLT_NI - not MESG_IN_PHASE %x\n",
2201 1.1.6.2 thorpej csr);
2202 1.1.6.2 thorpej }
2203 1.1.6.2 thorpej }
2204 1.1.6.2 thorpej }
2205 1.1.6.2 thorpej
2206 1.1.6.2 thorpej DBGPRINTF(("sbicnext: reselect %s from targ %d lun %d\n",
2207 1.1.6.2 thorpej csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY",
2208 1.1.6.2 thorpej newtarget, newlun),
2209 1.1.6.2 thorpej reselect_debug > 1 ||
2210 1.1.6.2 thorpej (reselect_debug && csr == SBIC_CSR_RSLT_NI));
2211 1.1.6.2 thorpej
2212 1.1.6.2 thorpej if (dev->sc_nexus) {
2213 1.1.6.2 thorpej DBGPRINTF(("%s: reselect %s with active command\n",
2214 1.1.6.2 thorpej dev->sc_dev.dv_xname,
2215 1.1.6.2 thorpej csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY"),
2216 1.1.6.2 thorpej reselect_debug > 1);
2217 1.1.6.2 thorpej #if defined(DDB) && defined (DEBUG)
2218 1.1.6.2 thorpej /* Debugger();*/
2219 1.1.6.2 thorpej #endif
2220 1.1.6.2 thorpej
2221 1.1.6.2 thorpej TAILQ_INSERT_HEAD(&dev->ready_list, dev->sc_nexus,
2222 1.1.6.2 thorpej chain);
2223 1.1.6.2 thorpej dev->sc_tinfo[dev->target].lubusy &= ~(1 << dev->lun);
2224 1.1.6.2 thorpej dev->sc_nexus = NULL;
2225 1.1.6.2 thorpej }
2226 1.1.6.2 thorpej /* Reload sync values for this target */
2227 1.1.6.2 thorpej if (dev->sc_sync[newtarget].state == SYNC_DONE)
2228 1.1.6.2 thorpej SET_SBIC_syn(regs,
2229 1.1.6.2 thorpej SBIC_SYN(dev->sc_sync[newtarget].offset,
2230 1.1.6.2 thorpej dev->sc_sync[newtarget].period));
2231 1.1.6.2 thorpej else
2232 1.1.6.2 thorpej SET_SBIC_syn(regs, SBIC_SYN (0, sbic_min_period));
2233 1.1.6.2 thorpej for (acb = dev->nexus_list.tqh_first; acb;
2234 1.1.6.2 thorpej acb = acb->chain.tqe_next) {
2235 1.1.6.2 thorpej if (acb->xs->xs_periph->periph_target != newtarget ||
2236 1.1.6.2 thorpej acb->xs->xs_periph->periph_lun != newlun)
2237 1.1.6.2 thorpej continue;
2238 1.1.6.2 thorpej TAILQ_REMOVE(&dev->nexus_list, acb, chain);
2239 1.1.6.2 thorpej dev->sc_nexus = acb;
2240 1.1.6.2 thorpej dev->sc_flags |= SBICF_SELECTED;
2241 1.1.6.2 thorpej dev->target = newtarget;
2242 1.1.6.2 thorpej dev->lun = newlun;
2243 1.1.6.2 thorpej break;
2244 1.1.6.2 thorpej }
2245 1.1.6.2 thorpej if (acb == NULL) {
2246 1.1.6.2 thorpej printf("%s: reselect %s targ %d not in nexus_list %p\n",
2247 1.1.6.2 thorpej dev->sc_dev.dv_xname,
2248 1.1.6.2 thorpej csr == SBIC_CSR_RSLT_NI ? "NI" : "IFY", newtarget,
2249 1.1.6.2 thorpej &dev->nexus_list.tqh_first);
2250 1.1.6.2 thorpej panic("bad reselect in sbic");
2251 1.1.6.2 thorpej }
2252 1.1.6.2 thorpej if (csr == SBIC_CSR_RSLT_IFY)
2253 1.1.6.2 thorpej SET_SBIC_cmd(regs, SBIC_CMD_CLR_ACK);
2254 1.1.6.2 thorpej break;
2255 1.1.6.2 thorpej
2256 1.1.6.2 thorpej default:
2257 1.1.6.2 thorpej abort:
2258 1.1.6.2 thorpej /*
2259 1.1.6.2 thorpej * Something unexpected happened -- deal with it.
2260 1.1.6.2 thorpej */
2261 1.1.6.2 thorpej printf("sbicnextstate: aborting csr %02x asr %02x\n", csr,
2262 1.1.6.2 thorpej asr);
2263 1.1.6.2 thorpej #ifdef DDB
2264 1.1.6.2 thorpej Debugger();
2265 1.1.6.2 thorpej #endif
2266 1.1.6.2 thorpej DBG(dev->sc_dmatimo = 0);
2267 1.1.6.2 thorpej
2268 1.1.6.2 thorpej if (dev->sc_flags & SBICF_INDMA) {
2269 1.1.6.2 thorpej dev->sc_dmafinish(dev->sc_dmah, dev->sc_dmat, acb);
2270 1.1.6.2 thorpej dev->sc_flags &= ~SBICF_INDMA;
2271 1.1.6.2 thorpej DBG(dev->sc_dmatimo = 0);
2272 1.1.6.2 thorpej }
2273 1.1.6.2 thorpej SET_SBIC_control(regs, SBIC_CTL_EDI | SBIC_CTL_IDI);
2274 1.1.6.2 thorpej sbicerror(dev, regs, csr);
2275 1.1.6.2 thorpej sbicabort(dev, regs, "next");
2276 1.1.6.2 thorpej sbic_scsidone(acb, -1);
2277 1.1.6.2 thorpej SBIC_TRACE(dev);
2278 1.1.6.2 thorpej return SBIC_STATE_ERROR;
2279 1.1.6.2 thorpej }
2280 1.1.6.2 thorpej
2281 1.1.6.2 thorpej SBIC_TRACE(dev);
2282 1.1.6.2 thorpej return SBIC_STATE_RUNNING;
2283 1.1.6.2 thorpej }
2284 1.1.6.2 thorpej
2285 1.1.6.2 thorpej static int
2286 1.1.6.2 thorpej sbictoscsiperiod(struct sbic_softc *dev, sbic_regmap_p regs, int a)
2287 1.1.6.2 thorpej {
2288 1.1.6.2 thorpej unsigned int fs;
2289 1.1.6.2 thorpej
2290 1.1.6.2 thorpej /*
2291 1.1.6.2 thorpej * cycle = DIV / (2*CLK)
2292 1.1.6.2 thorpej * DIV = FS+2
2293 1.1.6.2 thorpej * best we can do is 200ns at 20Mhz, 2 cycles
2294 1.1.6.2 thorpej */
2295 1.1.6.2 thorpej
2296 1.1.6.2 thorpej GET_SBIC_myid(regs,fs);
2297 1.1.6.2 thorpej fs = (fs >> 6) + 2; /* DIV */
2298 1.1.6.2 thorpej fs = (fs * 10000) / (dev->sc_clkfreq << 1); /* Cycle, in ns */
2299 1.1.6.2 thorpej if (a < 2)
2300 1.1.6.2 thorpej a = 8; /* map to Cycles */
2301 1.1.6.2 thorpej return (fs * a) >> 2; /* in 4 ns units */
2302 1.1.6.2 thorpej }
2303 1.1.6.2 thorpej
2304 1.1.6.2 thorpej static int
2305 1.1.6.2 thorpej sbicfromscsiperiod(struct sbic_softc *dev, sbic_regmap_p regs, int p)
2306 1.1.6.2 thorpej {
2307 1.1.6.2 thorpej register unsigned int fs, ret;
2308 1.1.6.2 thorpej
2309 1.1.6.2 thorpej /* Just the inverse of the above */
2310 1.1.6.2 thorpej
2311 1.1.6.2 thorpej GET_SBIC_myid(regs, fs);
2312 1.1.6.2 thorpej fs = (fs >> 6) + 2; /* DIV */
2313 1.1.6.2 thorpej fs = (fs * 10000) / (dev->sc_clkfreq << 1); /* Cycle, in ns */
2314 1.1.6.2 thorpej
2315 1.1.6.2 thorpej ret = p << 2; /* in ns units */
2316 1.1.6.2 thorpej ret = ret / fs; /* in Cycles */
2317 1.1.6.2 thorpej if (ret < sbic_min_period)
2318 1.1.6.2 thorpej return sbic_min_period;
2319 1.1.6.2 thorpej
2320 1.1.6.2 thorpej /* verify rounding */
2321 1.1.6.2 thorpej if (sbictoscsiperiod(dev, regs, ret) < p)
2322 1.1.6.2 thorpej ret++;
2323 1.1.6.2 thorpej return (ret >= 8) ? 0 : ret;
2324 1.1.6.2 thorpej }
2325 1.1.6.2 thorpej
2326 1.1.6.2 thorpej #ifdef DEBUG
2327 1.1.6.2 thorpej
2328 1.1.6.2 thorpej void
2329 1.1.6.2 thorpej sbicdumpstate()
2330 1.1.6.2 thorpej {
2331 1.1.6.2 thorpej u_char csr, asr;
2332 1.1.6.2 thorpej
2333 1.1.6.2 thorpej GET_SBIC_asr(debug_sbic_regs,asr);
2334 1.1.6.2 thorpej GET_SBIC_csr(debug_sbic_regs,csr);
2335 1.1.6.2 thorpej printf("%s: asr:csr(%02x:%02x)->(%02x:%02x)\n",
2336 1.1.6.2 thorpej (routine == 1) ? "sbicgo" :
2337 1.1.6.2 thorpej (routine == 2) ? "sbicintr" :
2338 1.1.6.2 thorpej (routine == 3) ? "sbicicmd" :
2339 1.1.6.2 thorpej (routine == 4) ? "sbicnext" : "unknown",
2340 1.1.6.2 thorpej debug_asr, debug_csr, asr, csr);
2341 1.1.6.2 thorpej
2342 1.1.6.2 thorpej }
2343 1.1.6.2 thorpej
2344 1.1.6.2 thorpej void
2345 1.1.6.2 thorpej sbictimeout(struct sbic_softc *dev)
2346 1.1.6.2 thorpej {
2347 1.1.6.2 thorpej int s, asr;
2348 1.1.6.2 thorpej
2349 1.1.6.2 thorpej s = splbio();
2350 1.1.6.2 thorpej if (dev->sc_dmatimo) {
2351 1.1.6.2 thorpej if (dev->sc_dmatimo > 1) {
2352 1.1.6.2 thorpej printf("%s: dma timeout #%d\n",
2353 1.1.6.2 thorpej dev->sc_dev.dv_xname, dev->sc_dmatimo - 1);
2354 1.1.6.2 thorpej GET_SBIC_asr(&dev->sc_sbicp, asr);
2355 1.1.6.2 thorpej if (asr & SBIC_ASR_INT) {
2356 1.1.6.2 thorpej /* We need to service a missed IRQ */
2357 1.1.6.2 thorpej printf("Servicing a missed int:(%02x,%02x)->(%02x,??)\n",
2358 1.1.6.2 thorpej debug_asr, debug_csr, asr);
2359 1.1.6.2 thorpej sbicintr(dev);
2360 1.1.6.2 thorpej }
2361 1.1.6.2 thorpej sbicdumpstate();
2362 1.1.6.2 thorpej }
2363 1.1.6.2 thorpej dev->sc_dmatimo++;
2364 1.1.6.2 thorpej }
2365 1.1.6.2 thorpej splx(s);
2366 1.1.6.2 thorpej callout_reset(&dev->sc_timo_ch, 30 * hz,
2367 1.1.6.2 thorpej (void *)sbictimeout, dev);
2368 1.1.6.2 thorpej }
2369 1.1.6.2 thorpej
2370 1.1.6.2 thorpej void
2371 1.1.6.2 thorpej sbic_dump_acb(struct sbic_acb *acb)
2372 1.1.6.2 thorpej {
2373 1.1.6.2 thorpej u_char *b = (u_char *) &acb->cmd;
2374 1.1.6.2 thorpej int i;
2375 1.1.6.2 thorpej
2376 1.1.6.2 thorpej printf("acb@%p ", acb);
2377 1.1.6.2 thorpej if (acb->xs == NULL) {
2378 1.1.6.2 thorpej printf("<unused>\n");
2379 1.1.6.2 thorpej return;
2380 1.1.6.2 thorpej }
2381 1.1.6.2 thorpej printf("(%d:%d) flags %2x clen %2d cmd ",
2382 1.1.6.2 thorpej acb->xs->xs_periph->periph_target,
2383 1.1.6.2 thorpej acb->xs->xs_periph->periph_lun, acb->flags, acb->clen);
2384 1.1.6.2 thorpej for (i = acb->clen; i; --i)
2385 1.1.6.2 thorpej printf(" %02x", *b++);
2386 1.1.6.2 thorpej printf("\n");
2387 1.1.6.2 thorpej printf(" xs: %8p data %8p:%04x ", acb->xs, acb->xs->data,
2388 1.1.6.2 thorpej acb->xs->datalen);
2389 1.1.6.2 thorpej printf("tcnt %lx\n", acb->sc_tcnt);
2390 1.1.6.2 thorpej }
2391 1.1.6.2 thorpej
2392 1.1.6.2 thorpej void
2393 1.1.6.2 thorpej sbic_dump(struct sbic_softc *dev)
2394 1.1.6.2 thorpej {
2395 1.1.6.2 thorpej sbic_regmap_p regs;
2396 1.1.6.2 thorpej u_char csr, asr;
2397 1.1.6.2 thorpej struct sbic_acb *acb;
2398 1.1.6.2 thorpej int s;
2399 1.1.6.2 thorpej int i;
2400 1.1.6.2 thorpej
2401 1.1.6.2 thorpej s = splbio();
2402 1.1.6.2 thorpej regs = &dev->sc_sbicp;
2403 1.1.6.2 thorpej #if CSR_TRACE_SIZE
2404 1.1.6.2 thorpej printf("csr trace: ");
2405 1.1.6.2 thorpej i = csr_traceptr;
2406 1.1.6.2 thorpej do {
2407 1.1.6.2 thorpej printf("%c%02x%02x%02x ", csr_trace[i].whr,
2408 1.1.6.2 thorpej csr_trace[i].csr, csr_trace[i].asr, csr_trace[i].xtn);
2409 1.1.6.2 thorpej switch(csr_trace[i].whr) {
2410 1.1.6.2 thorpej case 'g':
2411 1.1.6.2 thorpej printf("go "); break;
2412 1.1.6.2 thorpej case 's':
2413 1.1.6.2 thorpej printf("select "); break;
2414 1.1.6.2 thorpej case 'y':
2415 1.1.6.2 thorpej printf("select+ "); break;
2416 1.1.6.2 thorpej case 'i':
2417 1.1.6.2 thorpej printf("intr "); break;
2418 1.1.6.2 thorpej case 'f':
2419 1.1.6.2 thorpej printf("finish "); break;
2420 1.1.6.2 thorpej case '>':
2421 1.1.6.2 thorpej printf("out "); break;
2422 1.1.6.2 thorpej case '<':
2423 1.1.6.2 thorpej printf("in "); break;
2424 1.1.6.2 thorpej case 'm':
2425 1.1.6.2 thorpej printf("msgin "); break;
2426 1.1.6.2 thorpej case 'x':
2427 1.1.6.2 thorpej printf("msginx "); break;
2428 1.1.6.2 thorpej case 'X':
2429 1.1.6.2 thorpej printf("msginX "); break;
2430 1.1.6.2 thorpej case 'r':
2431 1.1.6.2 thorpej printf("reselect "); break;
2432 1.1.6.2 thorpej case 'I':
2433 1.1.6.2 thorpej printf("icmd "); break;
2434 1.1.6.2 thorpej case 'a':
2435 1.1.6.2 thorpej printf("abort "); break;
2436 1.1.6.2 thorpej default:
2437 1.1.6.2 thorpej printf("? ");
2438 1.1.6.2 thorpej }
2439 1.1.6.2 thorpej switch(csr_trace[i].csr) {
2440 1.1.6.2 thorpej case 0x11:
2441 1.1.6.2 thorpej printf("INITIATOR"); break;
2442 1.1.6.2 thorpej case 0x16:
2443 1.1.6.2 thorpej printf("S_XFERRED"); break;
2444 1.1.6.2 thorpej case 0x20:
2445 1.1.6.2 thorpej printf("MSGIN_ACK"); break;
2446 1.1.6.2 thorpej case 0x41:
2447 1.1.6.2 thorpej printf("DISC"); break;
2448 1.1.6.2 thorpej case 0x42:
2449 1.1.6.2 thorpej printf("SEL_TIMEO"); break;
2450 1.1.6.2 thorpej case 0x80:
2451 1.1.6.2 thorpej printf("RSLT_NI"); break;
2452 1.1.6.2 thorpej case 0x81:
2453 1.1.6.2 thorpej printf("RSLT_IFY"); break;
2454 1.1.6.2 thorpej case 0x85:
2455 1.1.6.2 thorpej printf("DISC_1"); break;
2456 1.1.6.2 thorpej case 0x18: case 0x19: case 0x1a:
2457 1.1.6.2 thorpej case 0x1b: case 0x1e: case 0x1f:
2458 1.1.6.2 thorpej case 0x28: case 0x29: case 0x2a:
2459 1.1.6.2 thorpej case 0x2b: case 0x2e: case 0x2f:
2460 1.1.6.2 thorpej case 0x48: case 0x49: case 0x4a:
2461 1.1.6.2 thorpej case 0x4b: case 0x4e: case 0x4f:
2462 1.1.6.2 thorpej case 0x88: case 0x89: case 0x8a:
2463 1.1.6.2 thorpej case 0x8b: case 0x8e: case 0x8f:
2464 1.1.6.2 thorpej switch(csr_trace[i].csr & 0xf0) {
2465 1.1.6.2 thorpej case 0x10:
2466 1.1.6.2 thorpej printf("DONE_"); break;
2467 1.1.6.2 thorpej case 0x20:
2468 1.1.6.2 thorpej printf("STOP_"); break;
2469 1.1.6.2 thorpej case 0x40:
2470 1.1.6.2 thorpej printf("ERR_"); break;
2471 1.1.6.2 thorpej case 0x80:
2472 1.1.6.2 thorpej printf("REQ_"); break;
2473 1.1.6.2 thorpej }
2474 1.1.6.2 thorpej switch(csr_trace[i].csr & 7) {
2475 1.1.6.2 thorpej case 0:
2476 1.1.6.2 thorpej printf("DATA_OUT"); break;
2477 1.1.6.2 thorpej case 1:
2478 1.1.6.2 thorpej printf("DATA_IN"); break;
2479 1.1.6.2 thorpej case 2:
2480 1.1.6.2 thorpej printf("CMD"); break;
2481 1.1.6.2 thorpej case 3:
2482 1.1.6.2 thorpej printf("STATUS"); break;
2483 1.1.6.2 thorpej case 6:
2484 1.1.6.2 thorpej printf("MSG_OUT"); break;
2485 1.1.6.2 thorpej case 7:
2486 1.1.6.2 thorpej printf("MSG_IN"); break;
2487 1.1.6.2 thorpej default:
2488 1.1.6.2 thorpej printf("invld phs");
2489 1.1.6.2 thorpej }
2490 1.1.6.2 thorpej break;
2491 1.1.6.2 thorpej default: printf("****"); break;
2492 1.1.6.2 thorpej }
2493 1.1.6.2 thorpej if (csr_trace[i].asr & SBIC_ASR_INT)
2494 1.1.6.2 thorpej printf(" ASR_INT");
2495 1.1.6.2 thorpej if (csr_trace[i].asr & SBIC_ASR_LCI)
2496 1.1.6.2 thorpej printf(" ASR_LCI");
2497 1.1.6.2 thorpej if (csr_trace[i].asr & SBIC_ASR_BSY)
2498 1.1.6.2 thorpej printf(" ASR_BSY");
2499 1.1.6.2 thorpej if (csr_trace[i].asr & SBIC_ASR_CIP)
2500 1.1.6.2 thorpej printf(" ASR_CIP");
2501 1.1.6.2 thorpej printf("\n");
2502 1.1.6.2 thorpej i = (i + 1) & (CSR_TRACE_SIZE - 1);
2503 1.1.6.2 thorpej } while (i != csr_traceptr);
2504 1.1.6.2 thorpej #endif
2505 1.1.6.2 thorpej GET_SBIC_asr(regs, asr);
2506 1.1.6.2 thorpej if ((asr & SBIC_ASR_INT) == 0)
2507 1.1.6.2 thorpej GET_SBIC_csr(regs, csr);
2508 1.1.6.2 thorpej else
2509 1.1.6.2 thorpej csr = 0;
2510 1.1.6.2 thorpej printf("%s@%p regs %p asr %x csr %x\n", dev->sc_dev.dv_xname,
2511 1.1.6.2 thorpej dev, regs, asr, csr);
2512 1.1.6.2 thorpej if ((acb = dev->free_list.tqh_first)) {
2513 1.1.6.2 thorpej printf("Free list:\n");
2514 1.1.6.2 thorpej while (acb) {
2515 1.1.6.2 thorpej sbic_dump_acb(acb);
2516 1.1.6.2 thorpej acb = acb->chain.tqe_next;
2517 1.1.6.2 thorpej }
2518 1.1.6.2 thorpej }
2519 1.1.6.2 thorpej if ((acb = dev->ready_list.tqh_first)) {
2520 1.1.6.2 thorpej printf("Ready list:\n");
2521 1.1.6.2 thorpej while (acb) {
2522 1.1.6.2 thorpej sbic_dump_acb(acb);
2523 1.1.6.2 thorpej acb = acb->chain.tqe_next;
2524 1.1.6.2 thorpej }
2525 1.1.6.2 thorpej }
2526 1.1.6.2 thorpej if ((acb = dev->nexus_list.tqh_first)) {
2527 1.1.6.2 thorpej printf("Nexus list:\n");
2528 1.1.6.2 thorpej while (acb) {
2529 1.1.6.2 thorpej sbic_dump_acb(acb);
2530 1.1.6.2 thorpej acb = acb->chain.tqe_next;
2531 1.1.6.2 thorpej }
2532 1.1.6.2 thorpej }
2533 1.1.6.2 thorpej if (dev->sc_nexus) {
2534 1.1.6.2 thorpej printf("nexus:\n");
2535 1.1.6.2 thorpej sbic_dump_acb(dev->sc_nexus);
2536 1.1.6.2 thorpej }
2537 1.1.6.2 thorpej printf("targ %d lun %d flags %x\n",
2538 1.1.6.2 thorpej dev->target, dev->lun, dev->sc_flags);
2539 1.1.6.2 thorpej for (i = 0; i < 8; ++i) {
2540 1.1.6.2 thorpej if (dev->sc_tinfo[i].cmds > 2) {
2541 1.1.6.2 thorpej printf("tgt %d: cmds %d disc %d lubusy %x\n",
2542 1.1.6.2 thorpej i, dev->sc_tinfo[i].cmds,
2543 1.1.6.2 thorpej dev->sc_tinfo[i].dconns,
2544 1.1.6.2 thorpej dev->sc_tinfo[i].lubusy);
2545 1.1.6.2 thorpej }
2546 1.1.6.2 thorpej }
2547 1.1.6.2 thorpej splx(s);
2548 1.1.6.2 thorpej }
2549 1.1.6.2 thorpej
2550 1.1.6.2 thorpej #endif
2551