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