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