siop.c revision 1.20 1 1.20 chopps /* $NetBSD: siop.c,v 1.20 1995/02/12 19:19:28 chopps Exp $ */
2 1.17 cgd
3 1.1 mw /*
4 1.8 chopps * Copyright (c) 1994 Michael L. Hitch
5 1.1 mw * Copyright (c) 1990 The Regents of the University of California.
6 1.1 mw * All rights reserved.
7 1.1 mw *
8 1.1 mw * This code is derived from software contributed to Berkeley by
9 1.1 mw * Van Jacobson of Lawrence Berkeley Laboratory.
10 1.1 mw *
11 1.1 mw * Redistribution and use in source and binary forms, with or without
12 1.1 mw * modification, are permitted provided that the following conditions
13 1.1 mw * are met:
14 1.1 mw * 1. Redistributions of source code must retain the above copyright
15 1.1 mw * notice, this list of conditions and the following disclaimer.
16 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mw * notice, this list of conditions and the following disclaimer in the
18 1.1 mw * documentation and/or other materials provided with the distribution.
19 1.1 mw * 3. All advertising materials mentioning features or use of this software
20 1.1 mw * must display the following acknowledgement:
21 1.1 mw * This product includes software developed by the University of
22 1.1 mw * California, Berkeley and its contributors.
23 1.1 mw * 4. Neither the name of the University nor the names of its contributors
24 1.1 mw * may be used to endorse or promote products derived from this software
25 1.1 mw * without specific prior written permission.
26 1.1 mw *
27 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 mw * SUCH DAMAGE.
38 1.1 mw *
39 1.1 mw * @(#)siop.c 7.5 (Berkeley) 5/4/91
40 1.1 mw */
41 1.1 mw
42 1.1 mw /*
43 1.1 mw * AMIGA 53C710 scsi adaptor driver
44 1.1 mw */
45 1.2 chopps
46 1.2 chopps /* need to know if any tapes have been configured */
47 1.2 chopps #include "st.h"
48 1.2 chopps
49 1.4 chopps #include <sys/param.h>
50 1.4 chopps #include <sys/systm.h>
51 1.8 chopps #include <sys/device.h>
52 1.20 chopps #include <sys/disklabel.h>
53 1.20 chopps #include <sys/dkstat.h>
54 1.4 chopps #include <sys/buf.h>
55 1.8 chopps #include <scsi/scsi_all.h>
56 1.8 chopps #include <scsi/scsiconf.h>
57 1.8 chopps #include <machine/cpu.h>
58 1.8 chopps #include <amiga/amiga/custom.h>
59 1.20 chopps #include <amiga/amiga/isr.h>
60 1.8 chopps #include <amiga/dev/siopreg.h>
61 1.4 chopps #include <amiga/dev/siopvar.h>
62 1.1 mw
63 1.1 mw extern u_int kvtop();
64 1.1 mw
65 1.1 mw /*
66 1.1 mw * SCSI delays
67 1.1 mw * In u-seconds, primarily for state changes on the SPC.
68 1.1 mw */
69 1.11 chopps #define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */
70 1.11 chopps #define SCSI_DATA_WAIT 500000 /* wait per data in/out step */
71 1.11 chopps #define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */
72 1.1 mw
73 1.18 chopps int siopicmd __P((struct siop_softc *, int, int, void *, int, void *, int));
74 1.8 chopps int siopgo __P((struct siop_softc *, struct scsi_xfer *));
75 1.8 chopps int siopgetsense __P((struct siop_softc *, struct scsi_xfer *));
76 1.8 chopps void siopabort __P((struct siop_softc *, siop_regmap_p, char *));
77 1.8 chopps void sioperror __P((struct siop_softc *, siop_regmap_p, u_char));
78 1.8 chopps void siopstart __P((struct siop_softc *));
79 1.8 chopps void siopreset __P((struct siop_softc *));
80 1.8 chopps void siopsetdelay __P((int));
81 1.8 chopps void siop_scsidone __P((struct siop_softc *, int));
82 1.8 chopps void siop_donextcmd __P((struct siop_softc *));
83 1.8 chopps int siopintr __P((struct siop_softc *));
84 1.1 mw
85 1.1 mw /* 53C710 script */
86 1.18 chopps #include <amiga/dev/siop_script.out>
87 1.1 mw
88 1.8 chopps /* default to not inhibit sync negotiation on any drive */
89 1.14 chopps u_char siop_inhibit_sync[8] = { 0, 0, 0, 0, 0, 0, 0 }; /* initialize, so patchable */
90 1.18 chopps u_char siop_allow_disc[8] = {0, 0, 0, 0, 0, 0, 0, 0};
91 1.8 chopps int siop_no_dma = 0;
92 1.8 chopps
93 1.18 chopps int siop_reset_delay = 250; /* delay after reset, in milleseconds */
94 1.8 chopps int siop_sync_period = 50; /* synchronous transfer period, in nanoseconds */
95 1.1 mw
96 1.1 mw int siop_cmd_wait = SCSI_CMD_WAIT;
97 1.1 mw int siop_data_wait = SCSI_DATA_WAIT;
98 1.1 mw int siop_init_wait = SCSI_INIT_WAIT;
99 1.1 mw
100 1.18 chopps /*
101 1.18 chopps * sync period transfer lookup - only valid for 66Mhz clock
102 1.18 chopps */
103 1.1 mw static struct {
104 1.1 mw unsigned char x; /* period from sync request message */
105 1.1 mw unsigned char y; /* siop_period << 4 | sbcl */
106 1.1 mw } xxx[] = {
107 1.18 chopps { 60/4, 0<<4 | 1},
108 1.18 chopps { 76/4, 1<<4 | 1},
109 1.18 chopps { 92/4, 2<<4 | 1},
110 1.18 chopps { 92/4, 0<<4 | 2},
111 1.18 chopps {108/4, 3<<4 | 1},
112 1.18 chopps {116/4, 1<<4 | 2},
113 1.18 chopps {120/4, 4<<4 | 1},
114 1.18 chopps {120/4, 0<<4 | 3},
115 1.18 chopps {136/4, 5<<4 | 1},
116 1.18 chopps {140/4, 2<<4 | 2},
117 1.18 chopps {152/4, 6<<4 | 1},
118 1.18 chopps {152/4, 1<<4 | 3},
119 1.18 chopps {164/4, 3<<4 | 2},
120 1.18 chopps {168/4, 7<<4 | 1},
121 1.18 chopps {180/4, 2<<4 | 3},
122 1.18 chopps {184/4, 4<<4 | 2},
123 1.18 chopps {208/4, 5<<4 | 2},
124 1.18 chopps {212/4, 3<<4 | 3},
125 1.18 chopps {232/4, 6<<4 | 2},
126 1.18 chopps {240/4, 4<<4 | 3},
127 1.18 chopps {256/4, 7<<4 | 2},
128 1.18 chopps {272/4, 5<<4 | 3},
129 1.18 chopps {300/4, 6<<4 | 3},
130 1.18 chopps {332/4, 7<<4 | 3}
131 1.1 mw };
132 1.1 mw
133 1.1 mw #ifdef DEBUG
134 1.8 chopps #define QPRINTF(a) if (siop_debug > 1) printf a
135 1.8 chopps /*
136 1.8 chopps * 0x01 - full debug
137 1.8 chopps * 0x02 - DMA chaining
138 1.8 chopps * 0x04 - siopintr
139 1.8 chopps * 0x08 - phase mismatch
140 1.8 chopps * 0x10 - panic on phase mismatch
141 1.15 chopps * 0x20 - panic on unhandled exceptions
142 1.18 chopps * 0x100 - disconnect/reconnect
143 1.8 chopps */
144 1.8 chopps int siop_debug = 0;
145 1.8 chopps int siopsync_debug = 0;
146 1.8 chopps int siopdma_hits = 0;
147 1.8 chopps int siopdma_misses = 0;
148 1.14 chopps int siopchain_ints = 0;
149 1.18 chopps int siopstarts = 0;
150 1.18 chopps int siopints = 0;
151 1.18 chopps int siopphmm = 0;
152 1.16 chopps #else
153 1.16 chopps #define QPRINTF(a)
154 1.1 mw #endif
155 1.8 chopps
156 1.8 chopps
157 1.8 chopps /*
158 1.8 chopps * default minphys routine for siop based controllers
159 1.8 chopps */
160 1.8 chopps void
161 1.8 chopps siop_minphys(bp)
162 1.8 chopps struct buf *bp;
163 1.8 chopps {
164 1.8 chopps /*
165 1.8 chopps * no max transfer at this level
166 1.8 chopps */
167 1.1 mw }
168 1.1 mw
169 1.8 chopps /*
170 1.8 chopps * used by specific siop controller
171 1.1 mw *
172 1.8 chopps */
173 1.8 chopps int
174 1.8 chopps siop_scsicmd(xs)
175 1.8 chopps struct scsi_xfer *xs;
176 1.8 chopps {
177 1.8 chopps struct siop_pending *pendp;
178 1.20 chopps struct siop_softc *sc;
179 1.8 chopps struct scsi_link *slp;
180 1.18 chopps int flags, s, i;
181 1.8 chopps
182 1.8 chopps slp = xs->sc_link;
183 1.20 chopps sc = slp->adapter_softc;
184 1.8 chopps flags = xs->flags;
185 1.8 chopps
186 1.8 chopps if (flags & SCSI_DATA_UIO)
187 1.8 chopps panic("siop: scsi data uio requested");
188 1.8 chopps
189 1.20 chopps if (sc->sc_xs && flags & SCSI_POLL)
190 1.8 chopps panic("siop_scsicmd: busy");
191 1.8 chopps
192 1.8 chopps s = splbio();
193 1.20 chopps pendp = &sc->sc_xsstore[slp->target][slp->lun];
194 1.8 chopps if (pendp->xs) {
195 1.8 chopps splx(s);
196 1.8 chopps return(TRY_AGAIN_LATER);
197 1.8 chopps }
198 1.8 chopps
199 1.20 chopps if (sc->sc_xs) {
200 1.8 chopps pendp->xs = xs;
201 1.20 chopps TAILQ_INSERT_TAIL(&sc->sc_xslist, pendp, link);
202 1.8 chopps splx(s);
203 1.8 chopps return(SUCCESSFULLY_QUEUED);
204 1.8 chopps }
205 1.8 chopps pendp->xs = NULL;
206 1.20 chopps sc->sc_xs = xs;
207 1.8 chopps splx(s);
208 1.8 chopps
209 1.8 chopps /*
210 1.8 chopps * nothing is pending do it now.
211 1.8 chopps */
212 1.20 chopps siop_donextcmd(sc);
213 1.8 chopps
214 1.19 chopps if (flags & SCSI_POLL)
215 1.8 chopps return(COMPLETE);
216 1.8 chopps return(SUCCESSFULLY_QUEUED);
217 1.8 chopps }
218 1.8 chopps
219 1.8 chopps /*
220 1.20 chopps * entered with sc->sc_xs pointing to the next xfer to perform
221 1.1 mw */
222 1.1 mw void
223 1.20 chopps siop_donextcmd(sc)
224 1.20 chopps struct siop_softc *sc;
225 1.8 chopps {
226 1.8 chopps struct scsi_xfer *xs;
227 1.8 chopps struct scsi_link *slp;
228 1.18 chopps int flags, stat, i;
229 1.8 chopps
230 1.20 chopps xs = sc->sc_xs;
231 1.8 chopps slp = xs->sc_link;
232 1.8 chopps flags = xs->flags;
233 1.8 chopps
234 1.8 chopps if (flags & SCSI_RESET)
235 1.20 chopps siopreset(sc);
236 1.8 chopps
237 1.18 chopps xs->cmd->bytes[0] |= slp->lun << 5;
238 1.18 chopps for (i = 0; i < 2; ++i) {
239 1.20 chopps if (sc->sc_iob[i].sc_xs == NULL) {
240 1.20 chopps sc->sc_iob[i].sc_xs = xs;
241 1.20 chopps sc->sc_cur = & sc->sc_iob[i];
242 1.20 chopps sc->sc_iob[i].sc_stat[0] = -1;
243 1.18 chopps break;
244 1.18 chopps }
245 1.18 chopps }
246 1.20 chopps if (sc->sc_cur == NULL)
247 1.18 chopps panic ("siop: too many I/O's");
248 1.20 chopps ++sc->sc_active;
249 1.8 chopps #if 0
250 1.20 chopps if (sc->sc_active > 1) {
251 1.20 chopps printf ("active count %d\n", sc->sc_active);
252 1.18 chopps }
253 1.18 chopps #endif
254 1.19 chopps if (flags & SCSI_POLL || siop_no_dma)
255 1.20 chopps stat = siopicmd(sc, slp->target, slp->lun, xs->cmd,
256 1.18 chopps xs->cmdlen, xs->data, xs->datalen);
257 1.20 chopps else if (siopgo(sc, xs) == 0)
258 1.8 chopps return;
259 1.8 chopps else
260 1.20 chopps stat = sc->sc_cur->sc_stat[0];
261 1.8 chopps
262 1.20 chopps siop_scsidone(sc, stat);
263 1.8 chopps }
264 1.8 chopps
265 1.8 chopps void
266 1.20 chopps siop_scsidone(sc, stat)
267 1.20 chopps struct siop_softc *sc;
268 1.8 chopps int stat;
269 1.1 mw {
270 1.8 chopps struct siop_pending *pendp;
271 1.8 chopps struct scsi_xfer *xs;
272 1.8 chopps int s, donext;
273 1.8 chopps
274 1.20 chopps xs = sc->sc_xs;
275 1.8 chopps #ifdef DIAGNOSTIC
276 1.8 chopps if (xs == NULL)
277 1.8 chopps panic("siop_scsidone");
278 1.8 chopps #endif
279 1.20 chopps #if 1
280 1.20 chopps if (((struct device *)(xs->sc_link->device_softc))->dv_unit < dk_ndrive)
281 1.20 chopps ++dk_xfer[((struct device *)(xs->sc_link->device_softc))->dv_unit];
282 1.20 chopps #endif
283 1.8 chopps /*
284 1.8 chopps * is this right?
285 1.8 chopps */
286 1.8 chopps xs->status = stat;
287 1.8 chopps
288 1.19 chopps if (stat == 0)
289 1.8 chopps xs->resid = 0;
290 1.8 chopps else {
291 1.8 chopps switch(stat) {
292 1.8 chopps case SCSI_CHECK:
293 1.20 chopps if (stat = siopgetsense(sc, xs))
294 1.8 chopps goto bad_sense;
295 1.8 chopps xs->error = XS_SENSE;
296 1.20 chopps if ((xs->sense.extended_flags & SSD_KEY) == 0x0b) { /* ABORTED COMMAND */
297 1.20 chopps printf ("%s: command %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
298 1.20 chopps sc->sc_dev.dv_xname,
299 1.20 chopps xs->cmd->opcode, xs->cmd->bytes[0], xs->cmd->bytes[1], xs->cmd->bytes[1],
300 1.20 chopps xs->cmd->bytes[3], xs->cmd->bytes[4], xs->cmd->bytes[5],
301 1.20 chopps xs->cmd->bytes[6], xs->cmd->bytes[7], xs->cmd->bytes[8]);
302 1.20 chopps printf ("%s: sense %02x %02x %02x %02x %02x %02x %02 extlen %02x: %02x %02x\n",
303 1.20 chopps sc->sc_dev.dv_xname,
304 1.20 chopps xs->sense.error_code, xs->sense.extended_segment,
305 1.20 chopps xs->sense.extended_flags, xs->sense.extended_info[0],
306 1.20 chopps xs->sense.extended_info[1], xs->sense.extended_info[2],
307 1.20 chopps xs->sense.extended_info[3], xs->sense.extended_extra_len,
308 1.20 chopps xs->sense.extended_extra_bytes[0], xs->sense.extended_extra_bytes[1]);
309 1.20 chopps }
310 1.8 chopps break;
311 1.8 chopps case SCSI_BUSY:
312 1.8 chopps xs->error = XS_BUSY;
313 1.8 chopps break;
314 1.8 chopps bad_sense:
315 1.8 chopps default:
316 1.8 chopps xs->error = XS_DRIVER_STUFFUP;
317 1.8 chopps QPRINTF(("siop_scsicmd() bad %x\n", stat));
318 1.8 chopps break;
319 1.8 chopps }
320 1.8 chopps }
321 1.8 chopps xs->flags |= ITSDONE;
322 1.1 mw
323 1.20 chopps --sc->sc_active;
324 1.20 chopps sc->sc_cur->sc_xs = NULL;
325 1.20 chopps sc->sc_cur = NULL;
326 1.18 chopps /*
327 1.18 chopps * if another command is already pending (i.e. it was pre-empted
328 1.18 chopps * by a reconnecting device), make it the current command and
329 1.18 chopps * continue
330 1.18 chopps */
331 1.18 chopps
332 1.8 chopps /*
333 1.8 chopps * grab next command before scsi_done()
334 1.8 chopps * this way no single device can hog scsi resources.
335 1.8 chopps */
336 1.8 chopps s = splbio();
337 1.20 chopps pendp = sc->sc_xslist.tqh_first;
338 1.8 chopps if (pendp == NULL) {
339 1.8 chopps donext = 0;
340 1.20 chopps sc->sc_xs = NULL;
341 1.1 mw } else {
342 1.8 chopps donext = 1;
343 1.20 chopps TAILQ_REMOVE(&sc->sc_xslist, pendp, link);
344 1.20 chopps sc->sc_xs = pendp->xs;
345 1.8 chopps pendp->xs = NULL;
346 1.1 mw }
347 1.8 chopps splx(s);
348 1.8 chopps scsi_done(xs);
349 1.8 chopps
350 1.8 chopps if (donext)
351 1.20 chopps siop_donextcmd(sc);
352 1.20 chopps else if (sc->sc_active && sc->sc_xs == NULL) {
353 1.20 chopps /* printf ("siop_scsidone: still active %d\n", sc->sc_active);*/
354 1.20 chopps /* sc->sc_siopp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;*/
355 1.18 chopps }
356 1.1 mw }
357 1.1 mw
358 1.8 chopps int
359 1.20 chopps siopgetsense(sc, xs)
360 1.20 chopps struct siop_softc *sc;
361 1.8 chopps struct scsi_xfer *xs;
362 1.8 chopps {
363 1.8 chopps struct scsi_sense rqs;
364 1.8 chopps struct scsi_link *slp;
365 1.8 chopps int stat;
366 1.1 mw
367 1.8 chopps slp = xs->sc_link;
368 1.8 chopps
369 1.19 chopps rqs.opcode = REQUEST_SENSE;
370 1.8 chopps rqs.byte2 = slp->lun << 5;
371 1.9 chopps #ifdef not_yet
372 1.8 chopps rqs.length = xs->req_sense_length ? xs->req_sense_length :
373 1.8 chopps sizeof(xs->sense);
374 1.9 chopps #else
375 1.9 chopps rqs.length = sizeof(xs->sense);
376 1.9 chopps #endif
377 1.8 chopps if (rqs.length > sizeof (xs->sense))
378 1.8 chopps rqs.length = sizeof (xs->sense);
379 1.8 chopps rqs.unused[0] = rqs.unused[1] = rqs.control = 0;
380 1.8 chopps
381 1.20 chopps return(siopicmd(sc, slp->target, slp->lun, &rqs, sizeof(rqs),
382 1.18 chopps &xs->sense, rqs.length));
383 1.8 chopps }
384 1.1 mw
385 1.8 chopps void
386 1.20 chopps siopabort(sc, rp, where)
387 1.20 chopps register struct siop_softc *sc;
388 1.20 chopps siop_regmap_p rp;
389 1.1 mw char *where;
390 1.1 mw {
391 1.18 chopps int i;
392 1.1 mw
393 1.8 chopps printf ("%s: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
394 1.20 chopps sc->sc_dev.dv_xname,
395 1.20 chopps where, rp->siop_dstat, rp->siop_sstat0, rp->siop_sbcl);
396 1.1 mw
397 1.20 chopps if (sc->sc_active > 0) {
398 1.1 mw #ifdef TODO
399 1.20 chopps SET_SBIC_cmd (rp, SBIC_CMD_ABORT);
400 1.20 chopps WAIT_CIP (rp);
401 1.1 mw
402 1.20 chopps GET_SBIC_asr (rp, asr);
403 1.1 mw if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
404 1.1 mw {
405 1.1 mw /* ok, get more drastic.. */
406 1.1 mw
407 1.20 chopps SET_SBIC_cmd (rp, SBIC_CMD_RESET);
408 1.11 chopps delay(25);
409 1.20 chopps SBIC_WAIT(rp, SBIC_ASR_INT, 0);
410 1.20 chopps GET_SBIC_csr (rp, csr); /* clears interrupt also */
411 1.1 mw
412 1.20 chopps sc->sc_flags &= ~SIOP_SELECTED;
413 1.1 mw return;
414 1.1 mw }
415 1.1 mw
416 1.1 mw do
417 1.1 mw {
418 1.20 chopps SBIC_WAIT (rp, SBIC_ASR_INT, 0);
419 1.20 chopps GET_SBIC_csr (rp, csr);
420 1.1 mw }
421 1.1 mw while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
422 1.1 mw && (csr != SBIC_CSR_CMD_INVALID));
423 1.1 mw #endif
424 1.1 mw
425 1.1 mw /* lets just hope it worked.. */
426 1.20 chopps sc->sc_flags &= ~SIOP_SELECTED;
427 1.18 chopps for (i = 0; i < 2; ++i) {
428 1.20 chopps if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] !=
429 1.20 chopps sc->sc_cur) {
430 1.18 chopps printf ("siopabort: cleanup!\n");
431 1.20 chopps sc->sc_iob[i].sc_xs = NULL;
432 1.18 chopps }
433 1.18 chopps }
434 1.20 chopps sc->sc_active = 0;
435 1.8 chopps }
436 1.1 mw }
437 1.1 mw
438 1.1 mw void
439 1.20 chopps siopinitialize(sc)
440 1.20 chopps struct siop_softc *sc;
441 1.12 chopps {
442 1.12 chopps /*
443 1.14 chopps * Need to check that scripts is on a long word boundary
444 1.14 chopps * and that DS is on a long word boundary.
445 1.18 chopps * Also need to verify that dev doesn't span non-contiguous
446 1.14 chopps * physical pages.
447 1.12 chopps */
448 1.20 chopps sc->sc_scriptspa = kvtop(scripts);
449 1.18 chopps #if 0
450 1.20 chopps sc->sc_dspa = kvtop(&sc->sc_ds);
451 1.20 chopps sc->sc_lunpa = kvtop(&sc->sc_msgout);
452 1.20 chopps sc->sc_statuspa = kvtop(&sc->sc_stat[0]);
453 1.20 chopps sc->sc_msgpa = kvtop(&sc->sc_msg[0]);
454 1.18 chopps #endif
455 1.20 chopps siopreset (sc);
456 1.12 chopps }
457 1.12 chopps
458 1.12 chopps void
459 1.20 chopps siopreset(sc)
460 1.20 chopps struct siop_softc *sc;
461 1.1 mw {
462 1.20 chopps siop_regmap_p rp;
463 1.1 mw u_int i, s;
464 1.18 chopps u_char my_id, dummy;
465 1.1 mw
466 1.20 chopps rp = sc->sc_siopp;
467 1.8 chopps
468 1.20 chopps if (sc->sc_flags & SIOP_ALIVE)
469 1.20 chopps siopabort(sc, rp, "reset");
470 1.1 mw
471 1.20 chopps printf("%s: ", sc->sc_dev.dv_xname); /* XXXX */
472 1.1 mw
473 1.1 mw s = splbio();
474 1.1 mw my_id = 7;
475 1.1 mw
476 1.1 mw /*
477 1.1 mw * Reset the chip
478 1.1 mw * XXX - is this really needed?
479 1.1 mw */
480 1.20 chopps rp->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
481 1.20 chopps rp->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
482 1.20 chopps rp->siop_istat &= ~SIOP_ISTAT_RST;
483 1.18 chopps /*
484 1.18 chopps * Reset SCSI bus (do we really want this?)
485 1.18 chopps */
486 1.20 chopps rp->siop_sien &= ~SIOP_SIEN_RST;
487 1.20 chopps rp->siop_scntl1 |= SIOP_SCNTL1_RST;
488 1.18 chopps delay(1);
489 1.20 chopps rp->siop_scntl1 &= ~SIOP_SCNTL1_RST;
490 1.20 chopps /* rp->siop_sien |= SIOP_SIEN_RST;*/
491 1.1 mw
492 1.1 mw /*
493 1.1 mw * Set up various chip parameters
494 1.1 mw */
495 1.20 chopps rp->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
496 1.20 chopps rp->siop_dcntl = sc->sc_clock_freq & 0xff;
497 1.20 chopps rp->siop_dmode = 0x80; /* burst length = 4 */
498 1.20 chopps rp->siop_sien = 0x00; /* don't enable interrupts yet */
499 1.20 chopps rp->siop_dien = 0x00; /* don't enable interrupts yet */
500 1.20 chopps rp->siop_scid = 1 << my_id;
501 1.20 chopps rp->siop_dwt = 0x00;
502 1.20 chopps rp->siop_ctest0 |= SIOP_CTEST0_BTD | SIOP_CTEST0_EAN;
503 1.20 chopps rp->siop_ctest7 |= (sc->sc_clock_freq >> 8) & 0xff;
504 1.1 mw
505 1.1 mw /* will need to re-negotiate sync xfers */
506 1.20 chopps bzero(&sc->sc_sync, sizeof (sc->sc_sync));
507 1.1 mw
508 1.20 chopps i = rp->siop_istat;
509 1.18 chopps if (i & SIOP_ISTAT_SIP)
510 1.20 chopps dummy = rp->siop_sstat0;
511 1.18 chopps if (i & SIOP_ISTAT_DIP)
512 1.20 chopps dummy = rp->siop_dstat;
513 1.18 chopps
514 1.1 mw splx (s);
515 1.1 mw
516 1.11 chopps delay (siop_reset_delay * 1000);
517 1.20 chopps printf("siop id %d reset V%d\n", my_id, rp->siop_ctest8 >> 4);
518 1.20 chopps sc->sc_flags |= SIOP_ALIVE;
519 1.20 chopps sc->sc_flags &= ~(SIOP_SELECTED | SIOP_DMA);
520 1.1 mw }
521 1.1 mw
522 1.1 mw /*
523 1.1 mw * Setup Data Storage for 53C710 and start SCRIPTS processing
524 1.1 mw */
525 1.1 mw
526 1.8 chopps void
527 1.20 chopps siop_setup (sc, target, lun, cbuf, clen, buf, len)
528 1.20 chopps struct siop_softc *sc;
529 1.1 mw int target;
530 1.18 chopps int lun;
531 1.1 mw u_char *cbuf;
532 1.1 mw int clen;
533 1.1 mw u_char *buf;
534 1.1 mw int len;
535 1.1 mw {
536 1.20 chopps siop_regmap_p rp = sc->sc_siopp;
537 1.1 mw int i;
538 1.1 mw int nchain;
539 1.1 mw int count, tcount;
540 1.1 mw char *addr, *dmaend;
541 1.20 chopps struct siop_iob *iob = sc->sc_cur;
542 1.1 mw
543 1.18 chopps #ifdef DEBUG
544 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
545 1.20 chopps printf ("ACK! siop was busy: rp %x script %x dsa %x\n",
546 1.20 chopps rp, &scripts, &iob->sc_ds);
547 1.18 chopps /*Debugger();*/
548 1.18 chopps }
549 1.20 chopps i = rp->siop_istat;
550 1.18 chopps if (i & SIOP_ISTAT_DIP) {
551 1.18 chopps int dstat;
552 1.20 chopps dstat = rp->siop_dstat;
553 1.18 chopps }
554 1.18 chopps if (i & SIOP_ISTAT_SIP) {
555 1.18 chopps int sstat;
556 1.20 chopps sstat = rp->siop_sstat0;
557 1.18 chopps }
558 1.18 chopps #endif
559 1.20 chopps sc->sc_istat = 0;
560 1.18 chopps iob->sc_msgout[0] = MSG_IDENTIFY | lun;
561 1.18 chopps /*
562 1.18 chopps * HACK - if no data transfer, allow disconnects
563 1.18 chopps */
564 1.18 chopps if (/*len == 0 || */ siop_allow_disc[target]) {
565 1.18 chopps iob->sc_msgout[0] = MSG_IDENTIFY_DR | lun;
566 1.20 chopps rp->siop_scntl1 |= SIOP_SCNTL1_ESR;
567 1.18 chopps }
568 1.18 chopps iob->sc_status = 0;
569 1.18 chopps iob->sc_stat[0] = -1;
570 1.18 chopps iob->sc_msg[0] = -1;
571 1.20 chopps iob->sc_ds.scsi_addr = (0x10000 << target) | (sc->sc_sync[target].period << 8);
572 1.18 chopps iob->sc_ds.idlen = 1;
573 1.18 chopps iob->sc_ds.idbuf = (char *) kvtop(&iob->sc_msgout[0]);
574 1.18 chopps iob->sc_ds.cmdlen = clen;
575 1.18 chopps iob->sc_ds.cmdbuf = (char *) kvtop(cbuf);
576 1.18 chopps iob->sc_ds.stslen = 1;
577 1.18 chopps iob->sc_ds.stsbuf = (char *) kvtop(&iob->sc_stat[0]);
578 1.18 chopps iob->sc_ds.msglen = 1;
579 1.18 chopps iob->sc_ds.msgbuf = (char *) kvtop(&iob->sc_msg[0]);
580 1.18 chopps iob->sc_msg[1] = -1;
581 1.18 chopps iob->sc_ds.msginlen = 1;
582 1.18 chopps iob->sc_ds.extmsglen = 1;
583 1.18 chopps iob->sc_ds.synmsglen = 3;
584 1.18 chopps iob->sc_ds.msginbuf = (char *) kvtop(&iob->sc_msg[1]);
585 1.18 chopps iob->sc_ds.extmsgbuf = (char *) kvtop(&iob->sc_msg[2]);
586 1.18 chopps iob->sc_ds.synmsgbuf = (char *) kvtop(&iob->sc_msg[3]);
587 1.18 chopps bzero(&iob->sc_ds.chain, sizeof (iob->sc_ds.chain));
588 1.1 mw
589 1.20 chopps if (sc->sc_sync[target].state == SYNC_START) {
590 1.8 chopps if (siop_inhibit_sync[target]) {
591 1.20 chopps sc->sc_sync[target].state = SYNC_DONE;
592 1.20 chopps sc->sc_sync[target].offset = 0;
593 1.20 chopps sc->sc_sync[target].period = 0;
594 1.1 mw #ifdef DEBUG
595 1.1 mw if (siopsync_debug)
596 1.1 mw printf ("Forcing target %d asynchronous\n", target);
597 1.1 mw #endif
598 1.1 mw }
599 1.1 mw else {
600 1.18 chopps iob->sc_msg[2] = -1;
601 1.18 chopps iob->sc_msgout[1] = MSG_EXT_MESSAGE;
602 1.18 chopps iob->sc_msgout[2] = 3;
603 1.18 chopps iob->sc_msgout[3] = MSG_SYNC_REQ;
604 1.18 chopps iob->sc_msgout[4] = siop_sync_period / 4;
605 1.18 chopps iob->sc_msgout[5] = SIOP_MAX_OFFSET;
606 1.18 chopps iob->sc_ds.idlen = 6;
607 1.20 chopps sc->sc_sync[target].state = SYNC_SENT;
608 1.1 mw #ifdef DEBUG
609 1.1 mw if (siopsync_debug)
610 1.1 mw printf ("Sending sync request to target %d\n", target);
611 1.1 mw #endif
612 1.1 mw }
613 1.1 mw }
614 1.1 mw
615 1.1 mw /*
616 1.1 mw * If length is > 1 page, check for consecutive physical pages
617 1.1 mw * Need to set up chaining if not
618 1.1 mw */
619 1.18 chopps iob->iob_buf = buf;
620 1.18 chopps iob->iob_len = len;
621 1.18 chopps iob->iob_curbuf = iob->iob_curlen = 0;
622 1.1 mw nchain = 0;
623 1.1 mw count = len;
624 1.1 mw addr = buf;
625 1.1 mw dmaend = NULL;
626 1.1 mw while (count > 0) {
627 1.18 chopps iob->sc_ds.chain[nchain].databuf = (char *) kvtop (addr);
628 1.1 mw if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
629 1.1 mw tcount = count;
630 1.18 chopps iob->sc_ds.chain[nchain].datalen = tcount;
631 1.1 mw addr += tcount;
632 1.1 mw count -= tcount;
633 1.18 chopps if (iob->sc_ds.chain[nchain].databuf == dmaend) {
634 1.18 chopps dmaend += iob->sc_ds.chain[nchain].datalen;
635 1.18 chopps iob->sc_ds.chain[--nchain].datalen += tcount;
636 1.1 mw #ifdef DEBUG
637 1.1 mw ++siopdma_hits;
638 1.1 mw #endif
639 1.1 mw }
640 1.1 mw else {
641 1.18 chopps dmaend = iob->sc_ds.chain[nchain].databuf +
642 1.18 chopps iob->sc_ds.chain[nchain].datalen;
643 1.18 chopps iob->sc_ds.chain[nchain].datalen = tcount;
644 1.1 mw #ifdef DEBUG
645 1.14 chopps if (nchain) /* Don't count miss on first one */
646 1.14 chopps ++siopdma_misses;
647 1.1 mw #endif
648 1.1 mw }
649 1.1 mw ++nchain;
650 1.1 mw }
651 1.1 mw #ifdef DEBUG
652 1.1 mw if (nchain != 1 && len != 0 && siop_debug & 3) {
653 1.1 mw printf ("DMA chaining set: %d\n", nchain);
654 1.1 mw for (i = 0; i < nchain; ++i) {
655 1.18 chopps printf (" [%d] %8x %4x\n", i, iob->sc_ds.chain[i].databuf,
656 1.18 chopps iob->sc_ds.chain[i].datalen);
657 1.1 mw }
658 1.1 mw }
659 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
660 1.20 chopps printf ("ACK! siop was busy at start: rp %x script %x dsa %x\n",
661 1.20 chopps rp, &scripts, &iob->sc_ds);
662 1.18 chopps /*Debugger();*/
663 1.18 chopps }
664 1.1 mw #endif
665 1.1 mw
666 1.18 chopps /* push data case on data the 53c710 needs to access */
667 1.20 chopps dma_cachectl (sc, sizeof (struct siop_softc));
668 1.12 chopps dma_cachectl (cbuf, clen);
669 1.12 chopps if (buf != NULL && len != 0)
670 1.12 chopps dma_cachectl (buf, len);
671 1.20 chopps if (sc->sc_active <= 1) {
672 1.20 chopps rp->siop_sbcl = sc->sc_sync[target].offset;
673 1.20 chopps rp->siop_dsa = kvtop(&iob->sc_ds);
674 1.18 chopps /* XXX if disconnected devices pending, this may not work */
675 1.20 chopps rp->siop_dsp = sc->sc_scriptspa;
676 1.18 chopps } else {
677 1.20 chopps rp->siop_istat = SIOP_ISTAT_SIGP;
678 1.18 chopps }
679 1.18 chopps #ifdef DEBUG
680 1.18 chopps ++siopstarts;
681 1.18 chopps #endif
682 1.1 mw }
683 1.1 mw
684 1.1 mw /*
685 1.1 mw * Process a DMA or SCSI interrupt from the 53C710 SIOP
686 1.1 mw */
687 1.1 mw
688 1.8 chopps int
689 1.20 chopps siop_checkintr(sc, istat, dstat, sstat0, status)
690 1.20 chopps struct siop_softc *sc;
691 1.1 mw u_char istat;
692 1.1 mw u_char dstat;
693 1.1 mw u_char sstat0;
694 1.1 mw int *status;
695 1.1 mw {
696 1.20 chopps siop_regmap_p rp = sc->sc_siopp;
697 1.20 chopps struct siop_iob *iob = sc->sc_cur;
698 1.1 mw int target;
699 1.18 chopps int dfifo, dbc, sstat1;
700 1.1 mw
701 1.20 chopps dfifo = rp->siop_dfifo;
702 1.20 chopps dbc = rp->siop_dbc0;
703 1.20 chopps sstat1 = rp->siop_sstat1;
704 1.20 chopps rp->siop_ctest8 |= SIOP_CTEST8_CLF;
705 1.20 chopps while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) == 0)
706 1.1 mw ;
707 1.20 chopps rp->siop_ctest8 &= ~SIOP_CTEST8_CLF;
708 1.1 mw #ifdef DEBUG
709 1.18 chopps ++siopints;
710 1.18 chopps if (siop_debug & 0x100) {
711 1.18 chopps DCIAS(&iob->sc_stat[0]); /* XXX */
712 1.1 mw printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
713 1.20 chopps istat, dstat, sstat0, rp->siop_dsps, rp->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
714 1.18 chopps printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
715 1.18 chopps iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
716 1.18 chopps iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
717 1.1 mw }
718 1.1 mw #endif
719 1.20 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) {
720 1.1 mw /* Normal completion status, or check condition */
721 1.20 chopps if (rp->siop_dsa != kvtop(&iob->sc_ds)) {
722 1.20 chopps printf ("siop: invalid dsa: %x %x\n", rp->siop_dsa,
723 1.18 chopps kvtop(&iob->sc_ds));
724 1.1 mw panic("*** siop DSA invalid ***");
725 1.1 mw }
726 1.20 chopps target = sc->sc_slave;
727 1.20 chopps if (sc->sc_sync[target].state == SYNC_SENT) {
728 1.1 mw #ifdef DEBUG
729 1.1 mw if (siopsync_debug)
730 1.1 mw printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
731 1.18 chopps iob->sc_msg[0], iob->sc_msg[1], iob->sc_msg[2],
732 1.18 chopps iob->sc_msg[3], iob->sc_msg[4], iob->sc_msg[5]);
733 1.1 mw #endif
734 1.18 chopps if (iob->sc_msg[1] == 0xff)
735 1.18 chopps printf ("%s: target %d ignored sync request\n",
736 1.20 chopps sc->sc_dev.dv_xname, target);
737 1.18 chopps else if (iob->sc_msg[1] == MSG_REJECT)
738 1.18 chopps printf ("%s: target %d rejected sync request\n",
739 1.20 chopps sc->sc_dev.dv_xname, target);
740 1.20 chopps sc->sc_sync[target].state = SYNC_DONE;
741 1.20 chopps sc->sc_sync[target].period = 0;
742 1.20 chopps sc->sc_sync[target].offset = 0;
743 1.18 chopps if (iob->sc_msg[2] == 3 &&
744 1.18 chopps iob->sc_msg[3] == MSG_SYNC_REQ &&
745 1.18 chopps iob->sc_msg[5] != 0) {
746 1.18 chopps if (iob->sc_msg[4] && iob->sc_msg[4] < 100 / 4) {
747 1.8 chopps #ifdef DEBUG
748 1.8 chopps printf ("%d: target %d wanted %dns period\n",
749 1.20 chopps sc->sc_dev.dv_xname, target,
750 1.18 chopps iob->sc_msg[4] * 4);
751 1.8 chopps #endif
752 1.8 chopps /*
753 1.8 chopps * Kludge for Maxtor XT8580S
754 1.8 chopps * It accepts whatever we request, even
755 1.8 chopps * though it won't work. So we ask for
756 1.8 chopps * a short period than we can handle. If
757 1.8 chopps * the device says it can do it, use 208ns.
758 1.8 chopps * If the device says it can do less than
759 1.8 chopps * 100ns, then we limit it to 100ns.
760 1.8 chopps */
761 1.18 chopps if (iob->sc_msg[4] == siop_sync_period / 4)
762 1.18 chopps iob->sc_msg[4] = 208 / 4;
763 1.8 chopps else
764 1.18 chopps iob->sc_msg[4] = 100 / 4;
765 1.8 chopps }
766 1.8 chopps printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
767 1.20 chopps sc->sc_dev.dv_xname, target,
768 1.18 chopps iob->sc_msg[4] * 4, iob->sc_msg[5]);
769 1.20 chopps scsi_period_to_siop (sc, target);
770 1.1 mw }
771 1.1 mw }
772 1.12 chopps #if 0
773 1.20 chopps DCIAS(sc->sc_statuspa); /* XXX */
774 1.12 chopps #else
775 1.18 chopps dma_cachectl(&iob->sc_stat[0], 1);
776 1.18 chopps #endif
777 1.18 chopps *status = iob->sc_stat[0];
778 1.18 chopps #ifdef DEBUG
779 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
780 1.20 chopps /*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n",
781 1.20 chopps rp, &scripts, &iob->sc_ds);*/
782 1.18 chopps /*Debugger();*/
783 1.18 chopps }
784 1.11 chopps #endif
785 1.20 chopps if (sc->sc_active > 1)
786 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
787 1.1 mw return 1;
788 1.1 mw }
789 1.1 mw if (sstat0 & SIOP_SSTAT0_M_A) { /* Phase mismatch */
790 1.1 mw #ifdef DEBUG
791 1.18 chopps ++siopphmm;
792 1.18 chopps if (iob->iob_len) {
793 1.18 chopps int adjust;
794 1.18 chopps adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
795 1.18 chopps if (sstat1 & SIOP_SSTAT1_ORF)
796 1.18 chopps ++adjust;
797 1.18 chopps if (sstat1 & SIOP_SSTAT1_OLF)
798 1.18 chopps ++adjust;
799 1.20 chopps iob->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff;
800 1.18 chopps iob->iob_curlen += adjust;
801 1.20 chopps iob->iob_curbuf = *((long *)&rp->siop_dnad);
802 1.18 chopps #ifdef DEBUG
803 1.18 chopps if (siop_debug & 0x100)
804 1.18 chopps printf ("Phase mismatch: dnad %x dbc %x dfifo %x dbc %x sstat1 %x adjust %x sbcl %x\n",
805 1.20 chopps iob->iob_curbuf, iob->iob_curlen, dfifo, dbc, sstat1, adjust, rp->siop_sbcl);
806 1.18 chopps #endif
807 1.18 chopps }
808 1.1 mw if (siop_debug & 9)
809 1.18 chopps printf ("Phase mismatch: %x dsp +%x dcmd %x\n",
810 1.20 chopps rp->siop_sbcl,
811 1.20 chopps rp->siop_dsp - sc->sc_scriptspa,
812 1.20 chopps *((long *)&rp->siop_dcmd));
813 1.8 chopps if (siop_debug & 0x10)
814 1.8 chopps panic ("53c710 phase mismatch");
815 1.1 mw #endif
816 1.20 chopps if ((rp->siop_sbcl & SIOP_REQ) == 0)
817 1.1 mw printf ("Phase mismatch: REQ not asserted! %02x\n",
818 1.20 chopps rp->siop_sbcl);
819 1.20 chopps switch (rp->siop_sbcl & 7) {
820 1.1 mw /*
821 1.1 mw * For data out and data in phase, check for DMA chaining
822 1.1 mw */
823 1.18 chopps case 0: /* data out */
824 1.18 chopps case 1: /* data in */
825 1.18 chopps case 2: /* status */
826 1.18 chopps case 3: /* command */
827 1.18 chopps case 6: /* message in */
828 1.18 chopps case 7: /* message out */
829 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
830 1.1 mw break;
831 1.1 mw default:
832 1.1 mw goto bad_phase;
833 1.1 mw }
834 1.1 mw return 0;
835 1.1 mw }
836 1.1 mw if (sstat0 & SIOP_SSTAT0_STO) { /* Select timed out */
837 1.1 mw #ifdef DEBUG
838 1.20 chopps if (rp->siop_sbcl & SIOP_BSY) {
839 1.20 chopps printf ("ACK! siop was busy at timeout: rp %x script %x dsa %x\n",
840 1.20 chopps rp, &scripts, &iob->sc_ds);
841 1.18 chopps printf(" sbcl %x sdid %x istat %x dstat %x sstat0 %x\n",
842 1.20 chopps rp->siop_sbcl, rp->siop_sdid, istat, dstat, sstat0);
843 1.20 chopps if (!(rp->siop_sbcl & SIOP_BSY)) {
844 1.18 chopps printf ("Yikes, it's not busy now!\n");
845 1.18 chopps #if 0
846 1.18 chopps *status = -1;
847 1.20 chopps if (sc->sc_active > 1)
848 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
849 1.18 chopps return 1;
850 1.1 mw #endif
851 1.18 chopps }
852 1.20 chopps /* rp->siop_dcntl |= SIOP_DCNTL_STD;*/
853 1.1 mw return (0);
854 1.18 chopps Debugger();
855 1.1 mw }
856 1.18 chopps #endif
857 1.18 chopps *status = -1;
858 1.20 chopps if (sc->sc_active > 1)
859 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
860 1.18 chopps return 1;
861 1.1 mw }
862 1.20 chopps target = sc->sc_slave;
863 1.18 chopps if (sstat0 & SIOP_SSTAT0_UDC) {
864 1.8 chopps #ifdef DEBUG
865 1.8 chopps printf ("%s: target %d disconnected unexpectedly\n",
866 1.20 chopps sc->sc_dev.dv_xname, target);
867 1.8 chopps #endif
868 1.8 chopps #if 0
869 1.20 chopps siopabort (sc, rp, "siopchkintr");
870 1.8 chopps #endif
871 1.8 chopps *status = STS_BUSY;
872 1.20 chopps if (sc->sc_active > 1)
873 1.20 chopps rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
874 1.8 chopps return 1;
875 1.8 chopps }
876 1.20 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) {
877 1.18 chopps #ifdef DEBUG
878 1.18 chopps if (siop_debug & 0x100)
879 1.18 chopps printf ("%s: ID %x disconnected TEMP %x (+%d) buf %x len %x buf %x len %x dfifo %x dbc %x sstat1 %x\n",
880 1.20 chopps sc->sc_dev.dv_xname, 1 << target, rp->siop_temp,
881 1.20 chopps rp->siop_temp - sc->sc_scriptspa,
882 1.18 chopps iob->iob_curbuf, iob->iob_curlen,
883 1.18 chopps iob->sc_ds.chain[0].databuf, iob->sc_ds.chain[0].datalen, dfifo, dbc, sstat1);
884 1.18 chopps #endif
885 1.18 chopps /*
886 1.18 chopps * HACK!
887 1.18 chopps * set current entry in disconnect state
888 1.18 chopps * clear current
889 1.18 chopps * if another iob available and another request pending,
890 1.18 chopps * start another
891 1.18 chopps */
892 1.20 chopps iob->sc_status = sc->sc_flags & (SIOP_SELECTED|SIOP_DMA);
893 1.20 chopps sc->sc_flags &= ~(SIOP_SELECTED|SIOP_DMA);
894 1.20 chopps sc->sc_cur = NULL; /* no current device */
895 1.20 chopps sc->sc_xs = NULL;
896 1.18 chopps /* continue script to wait for reconnect */
897 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
898 1.20 chopps if (sc->sc_active < 2) {
899 1.18 chopps struct siop_pending *pendp;
900 1.18 chopps int s = splbio();
901 1.18 chopps /*
902 1.18 chopps * can start another I/O, see if there are
903 1.18 chopps * any pending and start them
904 1.18 chopps */
905 1.20 chopps if (pendp = sc->sc_xslist.tqh_first) {
906 1.20 chopps TAILQ_REMOVE(&sc->sc_xslist, pendp, link);
907 1.20 chopps sc->sc_xs = pendp->xs;
908 1.18 chopps pendp->xs = NULL;
909 1.18 chopps splx(s);
910 1.18 chopps #ifdef DEBUG
911 1.18 chopps if (siop_debug & 0x100)
912 1.20 chopps printf ("starting a pending command %x\n", sc->sc_xs);
913 1.8 chopps #endif
914 1.20 chopps siop_donextcmd(sc);
915 1.18 chopps }
916 1.18 chopps splx(s);
917 1.18 chopps }
918 1.18 chopps return (0);
919 1.18 chopps }
920 1.20 chopps if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff09 ||
921 1.20 chopps rp->siop_dsps == 0xff06)) {
922 1.18 chopps int i;
923 1.18 chopps #ifdef DEBUG
924 1.18 chopps if (siop_debug & 0x100)
925 1.18 chopps printf ("%s: target reselected %x %x\n",
926 1.20 chopps sc->sc_dev.dv_xname, rp->siop_lcrc,
927 1.20 chopps rp->siop_dsps);
928 1.18 chopps #endif
929 1.20 chopps if (sc->sc_cur) {
930 1.18 chopps printf ("siop: oops - reconnect before current done\n");
931 1.18 chopps /* panic ("siop: what now?");*/
932 1.18 chopps }
933 1.18 chopps /*
934 1.18 chopps * locate iob of reconnecting device
935 1.20 chopps * set sc->sc_cur to iob
936 1.18 chopps */
937 1.18 chopps for (i = 0, iob = NULL; i < 2; ++i) {
938 1.20 chopps if (sc->sc_iob[i].sc_xs == NULL)
939 1.18 chopps continue;
940 1.20 chopps if (!sc->sc_iob[i].sc_status)
941 1.18 chopps continue;
942 1.20 chopps if (!(rp->siop_lcrc & (sc->sc_iob[i].sc_ds.scsi_addr >> 16)))
943 1.18 chopps continue;
944 1.20 chopps iob = &sc->sc_iob[i];
945 1.20 chopps sc->sc_cur = iob;
946 1.20 chopps sc->sc_xs = iob->sc_xs;
947 1.20 chopps sc->sc_flags |= iob->sc_status;
948 1.18 chopps iob->sc_status = 0;
949 1.18 chopps DCIAS(kvtop(&iob->sc_stat[0]));
950 1.20 chopps rp->siop_dsa = kvtop(&iob->sc_ds);
951 1.18 chopps if (iob->iob_curlen) {
952 1.18 chopps if (iob->iob_curbuf <= (u_long) iob->sc_ds.chain[0].databuf ||
953 1.18 chopps iob->iob_curbuf >= (u_long)(iob->sc_ds.chain[0].databuf + iob->sc_ds.chain[0].datalen))
954 1.18 chopps printf ("%s: saved data pointer not in chain[0]\n");
955 1.18 chopps iob->sc_ds.chain[0].databuf = (char *) iob->iob_curbuf;
956 1.18 chopps iob->sc_ds.chain[0].datalen = iob->iob_curlen;
957 1.18 chopps #ifdef DEBUG
958 1.18 chopps if (siop_debug & 0x100)
959 1.18 chopps printf ("%s: reselect buf %x len %x\n",
960 1.20 chopps sc->sc_dev.dv_xname, iob->iob_curbuf,
961 1.18 chopps iob->iob_curlen);
962 1.8 chopps #endif
963 1.18 chopps DCIAS(kvtop(&iob->sc_ds.chain));
964 1.18 chopps }
965 1.18 chopps }
966 1.18 chopps if (iob == NULL)
967 1.18 chopps panic("unable to find reconnecting device");
968 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
969 1.18 chopps return (0);
970 1.18 chopps }
971 1.20 chopps if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff07) {
972 1.18 chopps /* reselect was interrupted */
973 1.18 chopps #ifdef DEBUG
974 1.18 chopps if (siop_debug & 0x100 &&
975 1.20 chopps (rp->siop_sfbr & SIOP_CTEST2_SIGP) == 0)
976 1.18 chopps printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x\n",
977 1.20 chopps sc->sc_dev.dv_xname, rp->siop_scntl1, rp->siop_ctest2, rp->siop_sfbr);
978 1.18 chopps #endif
979 1.20 chopps target = sc->sc_xs->sc_link->target;
980 1.20 chopps rp->siop_dsa = kvtop(&sc->sc_cur->sc_ds);
981 1.20 chopps rp->siop_sbcl = sc->sc_sync[target].offset;
982 1.20 chopps rp->siop_dcntl |= SIOP_DCNTL_STD;
983 1.18 chopps return (0);
984 1.8 chopps }
985 1.1 mw if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
986 1.12 chopps #if 0
987 1.20 chopps DCIAS(sc->sc_statuspa);
988 1.12 chopps #else
989 1.18 chopps dma_cachectl (&iob->sc_stat[0], 1);
990 1.12 chopps #endif
991 1.1 mw printf ("SIOP interrupt: %x sts %x msg %x sbcl %x\n",
992 1.20 chopps rp->siop_dsps, iob->sc_stat[0], iob->sc_msg[0],
993 1.20 chopps rp->siop_sbcl);
994 1.20 chopps siopreset (sc);
995 1.1 mw *status = -1;
996 1.1 mw return 1;
997 1.1 mw }
998 1.15 chopps if (sstat0 & SIOP_SSTAT0_SGE)
999 1.15 chopps printf ("SIOP: SCSI Gross Error\n");
1000 1.15 chopps if (sstat0 & SIOP_SSTAT0_PAR)
1001 1.15 chopps printf ("SIOP: Parity Error\n");
1002 1.18 chopps if (dstat & SIOP_DSTAT_IID)
1003 1.18 chopps printf ("SIOP: Invalid instruction detected\n");
1004 1.1 mw bad_phase:
1005 1.15 chopps /*
1006 1.15 chopps * temporary panic for unhandled conditions
1007 1.15 chopps * displays various things about the 53C710 status and registers
1008 1.15 chopps * then panics.
1009 1.15 chopps * XXXX need to clean this up to print out the info, reset, and continue
1010 1.15 chopps */
1011 1.18 chopps printf ("siopchkintr: target %x ds %x\n", target, &iob->sc_ds);
1012 1.20 chopps printf ("scripts %x ds %x rp %x dsp %x dcmd %x\n", sc->sc_scriptspa,
1013 1.20 chopps kvtop(&sc->sc_iob), kvtop(rp), rp->siop_dsp,
1014 1.20 chopps *((long *)&rp->siop_dcmd));
1015 1.15 chopps printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x\n",
1016 1.20 chopps istat, dstat, sstat0, rp->siop_dsps, rp->siop_dsa,
1017 1.20 chopps rp->siop_sbcl, iob->sc_stat[0], iob->sc_msg[0]);
1018 1.15 chopps #ifdef DEBUG
1019 1.15 chopps if (siop_debug & 0x20)
1020 1.15 chopps panic("siopchkintr: **** temp ****");
1021 1.15 chopps #endif
1022 1.20 chopps siopreset (sc); /* hard reset */
1023 1.15 chopps *status = -1;
1024 1.15 chopps return 1;
1025 1.1 mw }
1026 1.1 mw
1027 1.1 mw /*
1028 1.1 mw * SCSI 'immediate' command: issue a command to some SCSI device
1029 1.1 mw * and get back an 'immediate' response (i.e., do programmed xfer
1030 1.1 mw * to get the response data). 'cbuf' is a buffer containing a scsi
1031 1.1 mw * command of length clen bytes. 'buf' is a buffer of length 'len'
1032 1.1 mw * bytes for data. The transfer direction is determined by the device
1033 1.1 mw * (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
1034 1.1 mw * command must supply no data. 'xferphase' is the bus phase the
1035 1.1 mw * caller expects to happen after the command is issued. It should
1036 1.1 mw * be one of DATA_IN_PHASE, DATA_OUT_PHASE or STATUS_PHASE.
1037 1.1 mw *
1038 1.1 mw * XXX - 53C710 will use DMA, but no interrupts (it's a heck of a
1039 1.1 mw * lot easier to do than to use programmed I/O).
1040 1.1 mw *
1041 1.1 mw */
1042 1.8 chopps int
1043 1.20 chopps siopicmd(sc, target, lun, cbuf, clen, buf, len)
1044 1.20 chopps struct siop_softc *sc;
1045 1.1 mw int target;
1046 1.18 chopps int lun;
1047 1.8 chopps void *cbuf;
1048 1.1 mw int clen;
1049 1.8 chopps void *buf;
1050 1.1 mw int len;
1051 1.1 mw {
1052 1.20 chopps siop_regmap_p rp = sc->sc_siopp;
1053 1.20 chopps struct siop_iob *iob = sc->sc_cur;
1054 1.1 mw int i;
1055 1.1 mw int status;
1056 1.1 mw u_char istat;
1057 1.1 mw u_char dstat;
1058 1.1 mw u_char sstat0;
1059 1.1 mw
1060 1.20 chopps if (sc->sc_flags & SIOP_SELECTED) {
1061 1.1 mw printf ("siopicmd%d: bus busy\n", target);
1062 1.1 mw return -1;
1063 1.1 mw }
1064 1.20 chopps rp->siop_sien = 0x00; /* disable SCSI and DMA interrupts */
1065 1.20 chopps rp->siop_dien = 0x00;
1066 1.20 chopps sc->sc_flags |= SIOP_SELECTED;
1067 1.20 chopps sc->sc_slave = target;
1068 1.1 mw #ifdef DEBUG
1069 1.1 mw if (siop_debug & 1)
1070 1.18 chopps printf ("siopicmd: target %x/%x cmd %02x ds %x\n", target,
1071 1.18 chopps lun, *((char *)cbuf), &iob->sc_ds);
1072 1.1 mw #endif
1073 1.20 chopps siop_setup (sc, target, lun, cbuf, clen, buf, len);
1074 1.1 mw
1075 1.1 mw for (;;) {
1076 1.1 mw /* use cmd_wait values? */
1077 1.1 mw i = siop_cmd_wait << 1;
1078 1.20 chopps while (((istat = rp->siop_istat) &
1079 1.1 mw (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
1080 1.1 mw if (--i <= 0) {
1081 1.1 mw printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x\n",
1082 1.8 chopps target, *((char *)cbuf),
1083 1.20 chopps rp->siop_sbcl, rp->siop_dsp,
1084 1.20 chopps rp->siop_dsp - sc->sc_scriptspa,
1085 1.20 chopps *((long *)&rp->siop_dcmd), &iob->sc_ds);
1086 1.1 mw i = siop_cmd_wait << 2;
1087 1.8 chopps /* XXXX need an upper limit and reset */
1088 1.1 mw }
1089 1.18 chopps delay(10);
1090 1.1 mw }
1091 1.20 chopps dstat = rp->siop_dstat;
1092 1.20 chopps sstat0 = rp->siop_sstat0;
1093 1.1 mw #ifdef DEBUG
1094 1.1 mw if (siop_debug & 1) {
1095 1.20 chopps DCIAS(kvtop(iob->sc_stat[0])); /* XXX should just invalidate sc->sc_stat */
1096 1.1 mw printf ("siopicmd: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1097 1.20 chopps istat, dstat, sstat0, rp->siop_dsps, rp->siop_sbcl,
1098 1.18 chopps iob->sc_stat[0], iob->sc_msg[0]);
1099 1.1 mw }
1100 1.1 mw #endif
1101 1.20 chopps if (siop_checkintr(sc, istat, dstat, sstat0, &status)) {
1102 1.20 chopps sc->sc_flags &= ~SIOP_SELECTED;
1103 1.1 mw return (status);
1104 1.1 mw }
1105 1.1 mw }
1106 1.1 mw }
1107 1.1 mw
1108 1.1 mw int
1109 1.20 chopps siopgo(sc, xs)
1110 1.20 chopps struct siop_softc *sc;
1111 1.8 chopps struct scsi_xfer *xs;
1112 1.1 mw {
1113 1.20 chopps siop_regmap_p rp;
1114 1.1 mw int i;
1115 1.1 mw int nchain;
1116 1.1 mw int count, tcount;
1117 1.1 mw char *addr, *dmaend;
1118 1.1 mw
1119 1.1 mw #ifdef DEBUG
1120 1.1 mw if (siop_debug & 1)
1121 1.20 chopps printf ("%s: go ", sc->sc_dev.dv_xname);
1122 1.8 chopps #if 0
1123 1.1 mw if ((cdb->cdb[1] & 1) == 0 &&
1124 1.1 mw ((cdb->cdb[0] == CMD_WRITE && cdb->cdb[2] == 0 && cdb->cdb[3] == 0) ||
1125 1.1 mw (cdb->cdb[0] == CMD_WRITE_EXT && cdb->cdb[2] == 0 && cdb->cdb[3] == 0
1126 1.1 mw && cdb->cdb[4] == 0)))
1127 1.1 mw panic ("siopgo: attempted write to block < 0x100");
1128 1.1 mw #endif
1129 1.8 chopps #endif
1130 1.8 chopps #if 0
1131 1.1 mw cdb->cdb[1] |= unit << 5;
1132 1.8 chopps #endif
1133 1.1 mw
1134 1.20 chopps if (sc->sc_flags & SIOP_SELECTED) {
1135 1.20 chopps printf ("%s: bus busy\n", sc->sc_dev.dv_xname);
1136 1.1 mw return 1;
1137 1.1 mw }
1138 1.1 mw
1139 1.20 chopps sc->sc_flags |= SIOP_SELECTED | SIOP_DMA;
1140 1.20 chopps sc->sc_slave = xs->sc_link->target;
1141 1.20 chopps rp = sc->sc_siopp;
1142 1.1 mw /* enable SCSI and DMA interrupts */
1143 1.20 chopps rp->siop_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE |
1144 1.1 mw SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
1145 1.20 chopps rp->siop_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
1146 1.18 chopps /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
1147 1.1 mw #ifdef DEBUG
1148 1.1 mw if (siop_debug & 1)
1149 1.20 chopps printf ("siopgo: target %x cmd %02x ds %x\n", sc->sc_slave,
1150 1.20 chopps xs->cmd->opcode, &sc->sc_cur->sc_ds);
1151 1.1 mw #endif
1152 1.1 mw
1153 1.20 chopps siop_setup(sc, sc->sc_slave, xs->sc_link->lun, xs->cmd, xs->cmdlen,
1154 1.20 chopps xs->data, xs->datalen);
1155 1.1 mw
1156 1.1 mw return (0);
1157 1.1 mw }
1158 1.1 mw
1159 1.1 mw /*
1160 1.8 chopps * Check for 53C710 interrupts
1161 1.1 mw */
1162 1.1 mw
1163 1.1 mw int
1164 1.20 chopps siopintr (sc)
1165 1.20 chopps register struct siop_softc *sc;
1166 1.1 mw {
1167 1.20 chopps siop_regmap_p rp;
1168 1.1 mw register u_char istat, dstat, sstat0;
1169 1.1 mw int status;
1170 1.1 mw
1171 1.20 chopps rp = sc->sc_siopp;
1172 1.20 chopps istat = sc->sc_istat;
1173 1.8 chopps if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
1174 1.8 chopps return;
1175 1.20 chopps if ((rp->siop_sien | rp->siop_dien) == 0)
1176 1.20 chopps return(0); /* no interrupts enabled */
1177 1.18 chopps /* Got a valid interrupt on this device */
1178 1.20 chopps dstat = sc->sc_dstat;
1179 1.20 chopps sstat0 = sc->sc_sstat0;
1180 1.20 chopps sc->sc_istat = 0;
1181 1.1 mw #ifdef DEBUG
1182 1.8 chopps if (siop_debug & 1)
1183 1.8 chopps printf ("%s: intr istat %x dstat %x sstat0 %x\n",
1184 1.20 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0);
1185 1.20 chopps if (!sc->sc_active) {
1186 1.18 chopps printf ("%s: spurious interrupt? istat %x dstat %x sstat0 %x status %x\n",
1187 1.20 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0, sc->sc_cur->sc_stat[0]);
1188 1.8 chopps }
1189 1.1 mw #endif
1190 1.1 mw
1191 1.1 mw #ifdef DEBUG
1192 1.8 chopps if (siop_debug & 5) {
1193 1.20 chopps DCIAS(kvtop(&sc->sc_cur->sc_stat[0]));
1194 1.20 chopps printf ("%s: intr istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
1195 1.20 chopps sc->sc_dev.dv_xname, istat, dstat, sstat0,
1196 1.20 chopps rp->siop_dsps, rp->siop_sbcl,
1197 1.20 chopps sc->sc_cur->sc_stat[0], sc->sc_cur->sc_msg[0]);
1198 1.8 chopps }
1199 1.1 mw #endif
1200 1.20 chopps if (siop_checkintr (sc, istat, dstat, sstat0, &status)) {
1201 1.1 mw #if 1
1202 1.20 chopps if (sc->sc_active <= 1) { /* more HACK */
1203 1.20 chopps rp->siop_sien = 0;
1204 1.20 chopps rp->siop_dien = 0;
1205 1.18 chopps }
1206 1.8 chopps if (status == 0xff)
1207 1.8 chopps printf ("siopintr: status == 0xff\n");
1208 1.8 chopps #endif
1209 1.20 chopps if (sc->sc_flags & SIOP_DMA) {
1210 1.20 chopps sc->sc_flags &= ~(SIOP_DMA | SIOP_SELECTED);
1211 1.20 chopps if (rp->siop_sbcl & SIOP_BSY)
1212 1.20 chopps printf ("%s: SCSI bus busy at completion\n",
1213 1.20 chopps sc->sc_dev.dv_xname);
1214 1.20 chopps siop_scsidone(sc, sc->sc_cur->sc_stat[0]);
1215 1.18 chopps }
1216 1.1 mw }
1217 1.1 mw }
1218 1.1 mw
1219 1.18 chopps /*
1220 1.18 chopps * This is based on the Progressive Peripherals Zeus driver and may
1221 1.18 chopps * not be correct for other 53c710 boards.
1222 1.18 chopps *
1223 1.18 chopps */
1224 1.20 chopps scsi_period_to_siop (sc, target)
1225 1.20 chopps struct siop_softc *sc;
1226 1.1 mw {
1227 1.8 chopps int period, offset, i, sxfer;
1228 1.1 mw
1229 1.20 chopps period = sc->sc_cur->sc_msg[4];
1230 1.20 chopps offset = sc->sc_cur->sc_msg[5];
1231 1.8 chopps sxfer = 0;
1232 1.8 chopps if (offset <= SIOP_MAX_OFFSET)
1233 1.8 chopps sxfer = offset;
1234 1.8 chopps for (i = 0; i < sizeof (xxx) / 2; ++i) {
1235 1.8 chopps if (period <= xxx[i].x) {
1236 1.8 chopps sxfer |= xxx[i].y & 0x70;
1237 1.8 chopps offset = xxx[i].y & 0x03;
1238 1.8 chopps break;
1239 1.8 chopps }
1240 1.8 chopps }
1241 1.20 chopps sc->sc_sync[target].period = sxfer;
1242 1.20 chopps sc->sc_sync[target].offset = offset;
1243 1.1 mw #ifdef DEBUG
1244 1.8 chopps printf ("sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, offset);
1245 1.1 mw #endif
1246 1.1 mw }
1247