siop2.c revision 1.14.2.1 1 /* $NetBSD: siop2.c,v 1.14.2.1 2000/11/20 19:58:43 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 1994,1998 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 53C720/770 scsi adaptor driver
44 */
45
46 #include "opt_ddb.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/disklabel.h>
52 #include <sys/dkstat.h>
53 #include <sys/buf.h>
54 #include <sys/malloc.h>
55 #include <dev/scsipi/scsi_all.h>
56 #include <dev/scsipi/scsipi_all.h>
57 #include <dev/scsipi/scsiconf.h>
58 #include <machine/cpu.h>
59 #ifdef __m68k__
60 #include <m68k/include/cacheops.h>
61 #endif
62 #include <amiga/amiga/custom.h>
63 #include <amiga/amiga/isr.h>
64
65 #define ARCH_720
66
67 #include <amiga/dev/siopreg.h>
68 #include <amiga/dev/siopvar.h>
69
70 /*
71 * SCSI delays
72 * In u-seconds, primarily for state changes on the SPC.
73 */
74 #define SCSI_CMD_WAIT 500000 /* wait per step of 'immediate' cmds */
75 #define SCSI_DATA_WAIT 500000 /* wait per data in/out step */
76 #define SCSI_INIT_WAIT 500000 /* wait per step (both) during init */
77
78 void siopng_select __P((struct siop_softc *));
79 void siopngabort __P((struct siop_softc *, siop_regmap_p, char *));
80 void siopngerror __P((struct siop_softc *, siop_regmap_p, u_char));
81 void siopngstart __P((struct siop_softc *));
82 int siopng_checkintr __P((struct siop_softc *, u_char, u_char, u_short, int *));
83 void siopngreset __P((struct siop_softc *));
84 void siopngsetdelay __P((int));
85 void siopng_scsidone __P((struct siop_acb *, int));
86 void siopng_sched __P((struct siop_softc *));
87 int siopng_poll __P((struct siop_softc *, struct siop_acb *));
88 void siopngintr __P((struct siop_softc *));
89 void scsi_period_to_siopng __P((struct siop_softc *, int));
90 void siopng_start __P((struct siop_softc *, int, int, u_char *, int, u_char *, int));
91 void siopng_dump_acb __P((struct siop_acb *));
92
93 /* 53C720/770 script */
94 const
95 #include <amiga/dev/siop2_script.out>
96
97 /* default to not inhibit sync negotiation on any drive */
98 u_char siopng_inhibit_sync[16] = {
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
100 }; /* initialize, so patchable */
101
102 u_char siopng_inhibit_wide[16] = {
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
104 }; /* initialize, so patchable */
105
106 u_char siopng_allow_disc[16] = {
107 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
108 };
109
110 int siopng_no_dma = 0;
111
112 int siopng_reset_delay = 250; /* delay after reset, in milleseconds */
113
114 int siopng_cmd_wait = SCSI_CMD_WAIT;
115 int siopng_data_wait = SCSI_DATA_WAIT;
116 int siopng_init_wait = SCSI_INIT_WAIT;
117
118 #define DEBUG_SYNC
119
120 #ifdef DEBUG
121 /*
122 * 0x01 - full debug
123 * 0x02 - DMA chaining
124 * 0x04 - siopngintr
125 * 0x08 - phase mismatch
126 * 0x10 - <not used>
127 * 0x20 - panic on unhandled exceptions
128 * 0x100 - disconnect/reselect
129 */
130 int siopng_debug = 0;
131 int siopngsync_debug = 0;
132 int siopngdma_hits = 0;
133 int siopngdma_misses = 0;
134 int siopngchain_ints = 0;
135 int siopngstarts = 0;
136 int siopngints = 0;
137 int siopngphmm = 0;
138 #define SIOP_TRACE_SIZE 128
139 #define SIOP_TRACE(a,b,c,d) \
140 siopng_trbuf[siopng_trix] = (a); \
141 siopng_trbuf[siopng_trix+1] = (b); \
142 siopng_trbuf[siopng_trix+2] = (c); \
143 siopng_trbuf[siopng_trix+3] = (d); \
144 siopng_trix = (siopng_trix + 4) & (SIOP_TRACE_SIZE - 1);
145 u_char siopng_trbuf[SIOP_TRACE_SIZE];
146 int siopng_trix;
147 void siopng_dump __P((struct siop_softc *));
148 void siopng_dump_trace __P((void));
149 #else
150 #define SIOP_TRACE(a,b,c,d)
151 #endif
152
153
154 static char *siopng_chips[] = {
155 "720", "720SE", "770", "0x3",
156 "810A", "0x5", "0x6", "0x7",
157 "0x8", "0x9", "0xA", "0xB",
158 "0xC", "0xD", "0xE", "0xF",
159 };
160
161 /*
162 * default minphys routine for siopng based controllers
163 */
164 void
165 siopng_minphys(bp)
166 struct buf *bp;
167 {
168
169 /*
170 * No max transfer at this level.
171 */
172 minphys(bp);
173 }
174
175 /*
176 * used by specific siopng controller
177 *
178 */
179 void
180 siopng_scsipi_request(chan, req, arg)
181 struct scsipi_channel *chan;
182 scsipi_adapter_req_t req;
183 void *arg;
184 {
185 struct scsipi_xfer *xs;
186 struct scsipi_periph *periph;
187 struct siop_acb *acb;
188 struct siop_softc *sc = (void *)chan->chan_adapter->adapt_dev;
189 int flags, s;
190
191 switch (req) {
192 case ADAPTER_REQ_RUN_XFER:
193 xs = arg;
194 periph = xs->xs_periph;
195 flags = xs->xs_control;
196
197 /* XXXX ?? */
198 if (flags & XS_CTL_DATA_UIO)
199 panic("siopng: scsi data uio requested");
200
201 /* XXXX ?? */
202 if (sc->sc_nexus && flags & XS_CTL_POLL)
203 /* panic("siopng_scsicmd: busy");*/
204 printf("siopng_scsicmd: busy\n");
205
206 s = splbio();
207 acb = sc->free_list.tqh_first;
208 if (acb) {
209 TAILQ_REMOVE(&sc->free_list, acb, chain);
210 }
211 splx(s);
212
213 #ifdef DIAGNOSTIC
214 /*
215 * This should never happen as we track the resources
216 * in the mid-layer.
217 */
218 if (acb == NULL) {
219 scsipi_printaddr(periph);
220 printf("unable to allocate acb\n");
221 panic("sea_scsipi_request");
222 }
223 #endif
224 acb->flags = ACB_ACTIVE;
225 acb->xs = xs;
226 bcopy(xs->cmd, &acb->cmd, xs->cmdlen);
227 acb->clen = xs->cmdlen;
228 acb->daddr = xs->data;
229 acb->dleft = xs->datalen;
230
231 s = splbio();
232 TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain);
233
234 if (sc->sc_nexus == NULL)
235 siopng_sched(sc);
236
237 splx(s);
238
239 if (flags & XS_CTL_POLL || siopng_no_dma)
240 siopng_poll(sc, acb);
241 return;
242
243 case ADAPTER_REQ_GROW_RESOURCES:
244 return;
245
246 case ADAPTER_REQ_SET_XFER_MODE:
247 return;
248 }
249 }
250
251 int
252 siopng_poll(sc, acb)
253 struct siop_softc *sc;
254 struct siop_acb *acb;
255 {
256 siop_regmap_p rp = sc->sc_siopp;
257 struct scsipi_xfer *xs = acb->xs;
258 int i;
259 int status;
260 u_char istat;
261 u_char dstat;
262 u_short sist;
263 int s;
264 int to;
265
266 s = splbio();
267 to = xs->timeout / 1000;
268 if (sc->nexus_list.tqh_first)
269 printf("%s: siopng_poll called with disconnected device\n",
270 sc->sc_dev.dv_xname);
271 for (;;) {
272 /* use cmd_wait values? */
273 i = 50000;
274 /* XXX spl0(); */
275 while (((istat = rp->siop_istat) &
276 (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
277 if (--i <= 0) {
278 #ifdef DEBUG
279 printf ("waiting: tgt %d cmd %02x sbcl %02x istat %02x sbdl %04x\n dsp %lx (+%lx) dcmd %lx ds %p timeout %d\n",
280 xs->xs_periph->periph_target, acb->cmd.opcode,
281 rp->siop_sbcl, istat, rp->siop_sbdl, rp->siop_dsp,
282 rp->siop_dsp - sc->sc_scriptspa,
283 *((long *)&rp->siop_dcmd), &acb->ds, acb->xs->timeout);
284 #endif
285 i = 50000;
286 --to;
287 if (to <= 0) {
288 siopngreset(sc);
289 return(COMPLETE);
290 }
291 }
292 delay(20);
293 }
294 sist = rp->siop_sist;
295 dstat = rp->siop_dstat;
296 if (siopng_checkintr(sc, istat, dstat, sist, &status)) {
297 if (acb != sc->sc_nexus)
298 printf("%s: siopng_poll disconnected device completed\n",
299 sc->sc_dev.dv_xname);
300 else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
301 sc->sc_flags &= ~SIOP_INTSOFF;
302 rp->siop_sien = sc->sc_sien;
303 rp->siop_dien = sc->sc_dien;
304 }
305 siopng_scsidone(sc->sc_nexus, status);
306 }
307 if (xs->xs_status & XS_STS_DONE)
308 break;
309 }
310 splx(s);
311 return (COMPLETE);
312 }
313
314 /*
315 * start next command that's ready
316 */
317 void
318 siopng_sched(sc)
319 struct siop_softc *sc;
320 {
321 struct scsipi_periph *periph;
322 struct siop_acb *acb;
323 int i;
324
325 #ifdef DEBUG
326 if (sc->sc_nexus) {
327 printf("%s: siopng_sched- nexus %p/%d ready %p/%d\n",
328 sc->sc_dev.dv_xname, sc->sc_nexus,
329 sc->sc_nexus->xs->xs_periph->periph_target,
330 sc->ready_list.tqh_first,
331 sc->ready_list.tqh_first->xs->xs_periph->periph_target);
332 return;
333 }
334 #endif
335 for (acb = sc->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
336 periph = acb->xs->xs_periph;
337 i = periph->periph_target;
338 if(!(sc->sc_tinfo[i].lubusy & (1 << periph->periph_lun))) {
339 struct siop_tinfo *ti = &sc->sc_tinfo[i];
340
341 TAILQ_REMOVE(&sc->ready_list, acb, chain);
342 sc->sc_nexus = acb;
343 periph = acb->xs->xs_periph;
344 ti = &sc->sc_tinfo[periph->periph_target];
345 ti->lubusy |= (1 << periph->periph_lun);
346 break;
347 }
348 }
349
350 if (acb == NULL) {
351 #ifdef DEBUGXXX
352 printf("%s: siopng_sched didn't find ready command\n",
353 sc->sc_dev.dv_xname);
354 #endif
355 return;
356 }
357
358 if (acb->xs->xs_control & XS_CTL_RESET)
359 siopngreset(sc);
360
361 #if 0
362 acb->cmd.bytes[0] |= periph->periph_lun << 5; /* XXXX */
363 #endif
364 ++sc->sc_active;
365 siopng_select(sc);
366 }
367
368 void
369 siopng_scsidone(acb, stat)
370 struct siop_acb *acb;
371 int stat;
372 {
373 struct scsipi_xfer *xs;
374 struct scsipi_periph *periph;
375 struct siop_softc *sc;
376 int dosched = 0;
377
378 if (acb == NULL || (xs = acb->xs) == NULL) {
379 #ifdef DIAGNOSTIC
380 printf("siopng_scsidone: NULL acb or scsipi_xfer\n");
381 #if defined(DEBUG) && defined(DDB)
382 Debugger();
383 #endif
384 #endif
385 return;
386 }
387 periph = xs->xs_periph;
388 sc = (void *)periph->periph_chan->chan_adapter->adapt_dev;
389 /*
390 * is this right?
391 */
392 xs->status = stat;
393
394 if (xs->error == XS_NOERROR && !(acb->flags & ACB_CHKSENSE)) {
395 if (stat == SCSI_CHECK) {
396 struct scsipi_sense *ss = (void *)&acb->cmd;
397 bzero(ss, sizeof(*ss));
398 ss->opcode = REQUEST_SENSE;
399 ss->byte2 = periph->periph_lun << 5;
400 ss->length = sizeof(struct scsipi_sense_data);
401 acb->clen = sizeof(*ss);
402 acb->daddr = (char *)&xs->sense.scsi_sense;
403 acb->dleft = sizeof(struct scsipi_sense_data);
404 acb->flags = ACB_ACTIVE | ACB_CHKSENSE;
405 TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
406 --sc->sc_active;
407 sc->sc_tinfo[periph->periph_target].lubusy &=
408 ~(1 << periph->periph_lun);
409 sc->sc_tinfo[periph->periph_target].senses++;
410 if (sc->sc_nexus == acb) {
411 sc->sc_nexus = NULL;
412 siopng_sched(sc);
413 }
414 SIOP_TRACE('d','s',0,0)
415 return;
416 }
417 }
418 if (xs->error == XS_NOERROR && (acb->flags & ACB_CHKSENSE)) {
419 xs->error = XS_SENSE;
420 } else {
421 xs->resid = 0; /* XXXX */
422 }
423 #if whataboutthisone
424 case SCSI_BUSY:
425 xs->error = XS_BUSY;
426 break;
427 #endif
428 xs->xs_status |= XS_STS_DONE;
429
430 /*
431 * Remove the ACB from whatever queue it's on. We have to do a bit of
432 * a hack to figure out which queue it's on. Note that it is *not*
433 * necessary to cdr down the ready queue, but we must cdr down the
434 * nexus queue and see if it's there, so we can mark the unit as no
435 * longer busy. This code is sickening, but it works.
436 */
437 if (acb == sc->sc_nexus) {
438 sc->sc_nexus = NULL;
439 sc->sc_tinfo[periph->periph_target].lubusy &=
440 ~(1<<periph->periph_lun);
441 if (sc->ready_list.tqh_first)
442 dosched = 1; /* start next command */
443 --sc->sc_active;
444 SIOP_TRACE('d','a',stat,0)
445 } else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) {
446 TAILQ_REMOVE(&sc->ready_list, acb, chain);
447 SIOP_TRACE('d','r',stat,0)
448 } else {
449 register struct siop_acb *acb2;
450 for (acb2 = sc->nexus_list.tqh_first; acb2;
451 acb2 = acb2->chain.tqe_next)
452 if (acb2 == acb) {
453 TAILQ_REMOVE(&sc->nexus_list, acb, chain);
454 sc->sc_tinfo[periph->periph_target].lubusy
455 &= ~(1<<periph->periph_lun);
456 --sc->sc_active;
457 break;
458 }
459 if (acb2)
460 ;
461 else if (acb->chain.tqe_next) {
462 TAILQ_REMOVE(&sc->ready_list, acb, chain);
463 --sc->sc_active;
464 } else {
465 printf("%s: can't find matching acb\n",
466 sc->sc_dev.dv_xname);
467 #ifdef DDB
468 /* Debugger(); */
469 #endif
470 }
471 SIOP_TRACE('d','n',stat,0);
472 }
473 /* Put it on the free list. */
474 acb->flags = ACB_FREE;
475 TAILQ_INSERT_HEAD(&sc->free_list, acb, chain);
476
477 sc->sc_tinfo[periph->periph_target].cmds++;
478
479 scsipi_done(xs);
480
481 if (dosched && sc->sc_nexus == NULL)
482 siopng_sched(sc);
483 }
484
485 void
486 siopngabort(sc, rp, where)
487 register struct siop_softc *sc;
488 siop_regmap_p rp;
489 char *where;
490 {
491 #ifdef fix_this
492 int i;
493 #endif
494
495 printf ("%s: abort %s: dstat %02x, istat %02x sist %04x sien %04x sbcl %02x\n",
496 sc->sc_dev.dv_xname,
497 where, rp->siop_dstat, rp->siop_istat, rp->siop_sist,
498 rp->siop_sien, rp->siop_sbcl);
499 siopng_dump_registers(sc);
500
501 if (sc->sc_active > 0) {
502 #ifdef TODO
503 SET_SBIC_cmd (rp, SBIC_CMD_ABORT);
504 WAIT_CIP (rp);
505
506 GET_SBIC_asr (rp, asr);
507 if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
508 {
509 /* ok, get more drastic.. */
510
511 SET_SBIC_cmd (rp, SBIC_CMD_RESET);
512 delay(25);
513 SBIC_WAIT(rp, SBIC_ASR_INT, 0);
514 GET_SBIC_csr (rp, csr); /* clears interrupt also */
515
516 return;
517 }
518
519 do
520 {
521 SBIC_WAIT (rp, SBIC_ASR_INT, 0);
522 GET_SBIC_csr (rp, csr);
523 }
524 while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
525 && (csr != SBIC_CSR_CMD_INVALID));
526 #endif
527
528 /* lets just hope it worked.. */
529 #ifdef fix_this
530 for (i = 0; i < 2; ++i) {
531 if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] !=
532 sc->sc_cur) {
533 printf ("siopngabort: cleanup!\n");
534 sc->sc_iob[i].sc_xs = NULL;
535 }
536 }
537 #endif /* fix_this */
538 /* sc->sc_active = 0; */
539 }
540 }
541
542 void
543 siopnginitialize(sc)
544 struct siop_softc *sc;
545 {
546 int i;
547 u_int inhibit_sync;
548 extern u_long scsi_nosync;
549 extern int shift_nosync;
550
551 /*
552 * Need to check that scripts is on a long word boundary
553 * Also should verify that dev doesn't span non-contiguous
554 * physical pages.
555 */
556 sc->sc_scriptspa = kvtop((caddr_t)siopng_scripts);
557
558 /*
559 * malloc sc_acb to ensure that DS is on a long word boundary.
560 */
561
562 MALLOC(sc->sc_acb, struct siop_acb *,
563 sizeof(struct siop_acb) * SIOP_NACB, M_DEVBUF, M_NOWAIT);
564 if (sc->sc_acb == NULL)
565 panic("siopnginitialize: ACB malloc failed!");
566
567 sc->sc_tcp[1] = 1000 / sc->sc_clock_freq;
568 sc->sc_tcp[2] = 1500 / sc->sc_clock_freq;
569 sc->sc_tcp[3] = 2000 / sc->sc_clock_freq;
570 sc->sc_minsync = sc->sc_tcp[1]; /* in 4ns units */
571 if (sc->sc_minsync < 25)
572 sc->sc_minsync = 25;
573 sc->sc_minsync >>= 1; /* Using clock doubler, allow Ultra */
574 if (sc->sc_clock_freq <= 25) {
575 sc->sc_dcntl |= 0x80; /* SCLK/1 */
576 sc->sc_tcp[0] = sc->sc_tcp[1];
577 } else if (sc->sc_clock_freq <= 37) {
578 sc->sc_dcntl |= 0x40; /* SCLK/1.5 */
579 sc->sc_tcp[0] = sc->sc_tcp[2];
580 } else if (sc->sc_clock_freq <= 50) {
581 sc->sc_dcntl |= 0x00; /* SCLK/2 */
582 sc->sc_tcp[0] = sc->sc_tcp[3];
583 } else {
584 sc->sc_dcntl |= 0xc0; /* SCLK/3 */
585 sc->sc_tcp[0] = 3000 / sc->sc_clock_freq;
586 }
587
588 if (scsi_nosync) {
589 inhibit_sync = (scsi_nosync >> shift_nosync) & 0xffff;
590 shift_nosync += 16; /* XXX maxtarget */
591 #ifdef DEBUG
592 if (inhibit_sync)
593 printf("%s: Inhibiting synchronous transfer %02x\n",
594 sc->sc_dev.dv_xname, inhibit_sync);
595 #endif
596 for (i = 0; i < 16; ++i) /* XXX maxtarget */
597 if (inhibit_sync & (1 << i))
598 siopng_inhibit_sync[i] = 1;
599 }
600
601 siopngreset (sc);
602 }
603
604 void
605 siopngreset(sc)
606 struct siop_softc *sc;
607 {
608 siop_regmap_p rp;
609 u_int i, s;
610 u_short dummy;
611 struct siop_acb *acb;
612
613 rp = sc->sc_siopp;
614
615 if (sc->sc_flags & SIOP_ALIVE)
616 siopngabort(sc, rp, "reset");
617
618 printf("%s: ", sc->sc_dev.dv_xname); /* XXXX */
619
620 s = splbio();
621
622 /*
623 * Reset the chip
624 * XXX - is this really needed?
625 */
626 rp->siop_istat |= SIOP_ISTAT_ABRT; /* abort current script */
627 rp->siop_istat |= SIOP_ISTAT_RST; /* reset chip */
628 rp->siop_istat &= ~SIOP_ISTAT_RST;
629 /*
630 * Reset SCSI bus (do we really want this?)
631 */
632 rp->siop_sien = 0;
633 rp->siop_scntl1 |= SIOP_SCNTL1_RST;
634 delay(1);
635 rp->siop_scntl1 &= ~SIOP_SCNTL1_RST;
636
637 /*
638 * Set up various chip parameters
639 */
640 rp->siop_stest1 |= SIOP_STEST1_DBLEN; /* SCLK doubler enable */
641 delay(20);
642 rp->siop_stest3 |= SIOP_STEST3_HSC; /* Halt SCSI clock */
643 rp->siop_scntl3 = 0x15; /* SCF/CCF*/
644 rp->siop_stest1 |= SIOP_STEST1_DBLSEL; /* SCLK doubler select */
645 rp->siop_stest3 &= ~SIOP_STEST3_HSC; /* Clear Halt SCSI clock */
646 rp->siop_scntl0 = SIOP_ARB_FULL | /*SIOP_SCNTL0_EPC |*/ SIOP_SCNTL0_EPG;
647 rp->siop_dcntl = sc->sc_dcntl;
648 rp->siop_dmode = 0xc0; /* XXX burst length */
649 rp->siop_sien = 0x00; /* don't enable interrupts yet */
650 rp->siop_dien = 0x00; /* don't enable interrupts yet */
651 rp->siop_scid = sc->sc_channel->chan_id |
652 SIOP_SCID_RRE | SIOP_SCID_SRE;
653 rp->siop_respid = 1 << sc->channel->chan_id;
654 rp->siop_dwt = 0x00;
655 rp->siop_stime0 = 0x0c; /* XXXXX check */
656
657 /* will need to re-negotiate sync xfers */
658 bzero(&sc->sc_sync, sizeof (sc->sc_sync));
659
660 i = rp->siop_istat;
661 if (i & SIOP_ISTAT_SIP)
662 dummy = rp->siop_sist;
663 if (i & SIOP_ISTAT_DIP)
664 dummy = rp->siop_dstat;
665
666 splx (s);
667
668 delay (siopng_reset_delay * 1000);
669
670 /*
671 * is lower half unterminated?
672 */
673 if ((rp->siop_sbdl & 0x00ff) == 0x00ff) {
674 printf(" no SCSI termination, host adapter deactivated.\n");
675 sc->sc_channel->chan_ntargets = 0; /* XXX */
676 sc->sc_flags &= ~(SIOP_ALIVE|SIOP_INTDEFER|SIOP_INTSOFF);
677 /* disable SCSI and DMA interrupts */
678 sc->sc_sien = 0;
679 sc->sc_dien = 0;
680 rp->siop_sien = sc->sc_sien;
681 rp->siop_dien = sc->sc_dien;
682
683 return;
684 }
685
686 /*
687 * Check if upper half of SCSI bus is unterminated, and disallow
688 * disconnections if it appears to be unterminated.
689 */
690 if ((rp->siop_sbdl & 0xff00) == 0xff00) {
691 printf(" NO WIDE TERM");
692 /* XXX need to restrict maximum target ID as well? */
693 sc->sc_channel->chan_ntargets = 8;
694 for (i = 0; i < 16; ++i) {
695 siopng_allow_disc[i] = 0;
696 siopng_inhibit_wide[i] |= 0x80;
697 }
698 }
699
700 printf("siopng type %s id %d reset V%d\n",
701 siopng_chips[rp->siop_macntl>>4],
702 sc->sc_channel->chan_ntargets,
703 rp->siop_ctest3 >> 4);
704
705 if ((sc->sc_flags & SIOP_ALIVE) == 0) {
706 TAILQ_INIT(&sc->ready_list);
707 TAILQ_INIT(&sc->nexus_list);
708 TAILQ_INIT(&sc->free_list);
709 sc->sc_nexus = NULL;
710 acb = sc->sc_acb;
711 bzero(acb, sizeof(struct siop_acb) * SIOP_NACB);
712 for (i = 0; i < SIOP_NACB; i++) {
713 TAILQ_INSERT_TAIL(&sc->free_list, acb, chain);
714 acb++;
715 }
716 bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
717 } else {
718 if (sc->sc_nexus != NULL) {
719 sc->sc_nexus->xs->error = XS_RESET;
720 siopng_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
721 }
722 while ((acb = sc->nexus_list.tqh_first) > 0) {
723 acb->xs->error = XS_RESET;
724 siopng_scsidone(acb, acb->stat[0]);
725 }
726 }
727
728 sc->sc_flags |= SIOP_ALIVE;
729 sc->sc_flags &= ~(SIOP_INTDEFER|SIOP_INTSOFF);
730 /* enable SCSI and DMA interrupts */
731 sc->sc_sien = SIOP_SIEN_MA | SIOP_SIEN_STO | /*SIOP_SIEN_GEN |*/
732 /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE | SIOP_SIEN_UDC |
733 SIOP_SIEN_RST | SIOP_SIEN_PAR;
734 sc->sc_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
735 /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
736 rp->siop_sien = sc->sc_sien;
737 rp->siop_dien = sc->sc_dien;
738 /*siopng_dump_registers(sc);*/
739 }
740
741 /*
742 * Setup Data Storage for 53C720/770 and start SCRIPTS processing
743 */
744
745 void
746 siopng_start (sc, target, lun, cbuf, clen, buf, len)
747 struct siop_softc *sc;
748 int target;
749 int lun;
750 u_char *cbuf;
751 int clen;
752 u_char *buf;
753 int len;
754 {
755 siop_regmap_p rp = sc->sc_siopp;
756 int nchain;
757 int count, tcount;
758 char *addr, *dmaend;
759 struct siop_acb *acb = sc->sc_nexus;
760 #ifdef DEBUG
761 int i;
762 #endif
763
764 #ifdef DEBUG
765 if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
766 printf ("ACK! siopng was busy: rp %p script %p dsa %p active %ld\n",
767 rp, &siopng_scripts, &acb->ds, sc->sc_active);
768 printf ("istat %02x sfbr %02x respid %02x sien %04x dien %02x\n",
769 rp->siop_istat, rp->siop_sfbr, rp->siop_respid,
770 rp->siop_sien, rp->siop_dien);
771 #ifdef DDB
772 /*Debugger();*/
773 #endif
774 }
775 #endif
776 acb->msgout[0] = MSG_IDENTIFY | lun;
777 if (siopng_allow_disc[target] & 2 ||
778 (siopng_allow_disc[target] && len == 0))
779 acb->msgout[0] = MSG_IDENTIFY_DR | lun;
780 acb->status = 0;
781 acb->stat[0] = -1;
782 acb->msg[0] = -1;
783 acb->ds.scsi_addr = (target << 16) | (sc->sc_sync[target].sxfer << 8) |
784 (sc->sc_sync[target].scntl3 << 24);
785 acb->ds.idlen = 1;
786 acb->ds.idbuf = (char *) kvtop(&acb->msgout[0]);
787 acb->ds.cmdlen = clen;
788 acb->ds.cmdbuf = (char *) kvtop(cbuf);
789 acb->ds.stslen = 1;
790 acb->ds.stsbuf = (char *) kvtop(&acb->stat[0]);
791 acb->ds.msglen = 1;
792 acb->ds.msgbuf = (char *) kvtop(&acb->msg[0]);
793 acb->msg[1] = -1;
794 acb->ds.msginlen = 1;
795 acb->ds.extmsglen = 1;
796 acb->ds.synmsglen = 3;
797 acb->ds.msginbuf = acb->ds.msgbuf + 1;
798 acb->ds.extmsgbuf = acb->ds.msginbuf + 1;
799 acb->ds.synmsgbuf = acb->ds.extmsgbuf + 1;
800 bzero(&acb->ds.chain, sizeof (acb->ds.chain));
801
802 if (sc->sc_sync[target].state == NEG_WIDE) {
803 if (siopng_inhibit_wide[target]) {
804 sc->sc_sync[target].state = NEG_SYNC;
805 sc->sc_sync[target].scntl3 &= ~SIOP_SCNTL3_EWS;
806 #ifdef DEBUG
807 if (siopngsync_debug)
808 printf ("Forcing target %d narrow\n", target);
809 #endif
810 }
811 else {
812 sc->sc_sync[target].scntl3 = 0x15 | /* XXX */
813 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */
814 acb->msg[2] = -1;
815 acb->msgout[1] = MSG_EXT_MESSAGE;
816 acb->msgout[2] = 2;
817 acb->msgout[3] = MSG_WIDE_REQ;
818 acb->msgout[4] = 1;
819 acb->ds.idlen = 5;
820 acb->ds.synmsglen = 2;
821 sc->sc_sync[target].state = NEG_WAITW;
822 #ifdef DEBUG
823 if (siopngsync_debug)
824 printf("Sending wide request to target %d\n", target);
825 #endif
826 }
827 }
828 if (sc->sc_sync[target].state == NEG_SYNC) {
829 if (siopng_inhibit_sync[target]) {
830 sc->sc_sync[target].state = NEG_DONE;
831 sc->sc_sync[target].scntl3 = 5 | /* XXX */
832 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */
833 sc->sc_sync[target].sxfer = 0;
834 #ifdef DEBUG
835 if (siopngsync_debug)
836 printf ("Forcing target %d asynchronous\n", target);
837 #endif
838 }
839 else {
840 sc->sc_sync[target].scntl3 = 0x15 | /* XXX */
841 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */
842 acb->msg[2] = -1;
843 acb->msgout[1] = MSG_EXT_MESSAGE;
844 acb->msgout[2] = 3;
845 acb->msgout[3] = MSG_SYNC_REQ;
846 #ifdef MAXTOR_SYNC_KLUDGE
847 acb->msgout[4] = 50 / 4; /* ask for ridiculous period */
848 #else
849 acb->msgout[4] = sc->sc_minsync;
850 #endif
851 acb->msgout[5] = SIOP_MAX_OFFSET;
852 acb->ds.idlen = 6;
853 sc->sc_sync[target].state = NEG_WAITS;
854 #ifdef DEBUG
855 if (siopngsync_debug)
856 printf ("Sending sync request to target %d\n", target);
857 #endif
858 }
859 }
860
861 /*
862 * Build physical DMA addresses for scatter/gather I/O
863 */
864 acb->iob_buf = buf;
865 acb->iob_len = len;
866 acb->iob_curbuf = acb->iob_curlen = 0;
867 nchain = 0;
868 count = len;
869 addr = buf;
870 dmaend = NULL;
871 while (count > 0) {
872 acb->ds.chain[nchain].databuf = (char *) kvtop (addr);
873 if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
874 tcount = count;
875
876 #if DEBUG_ONLY_IF_DESPERATE
877 printf("chain[%d]: count %d tcount %d vaddr %p paddr %p\n",
878 nchain, count, tcount, addr,
879 acb->ds.chain[nchain].databuf);
880 #endif
881 acb->ds.chain[nchain].datalen = tcount;
882 addr += tcount;
883 count -= tcount;
884 if (acb->ds.chain[nchain].databuf == dmaend) {
885 dmaend += acb->ds.chain[nchain].datalen;
886 acb->ds.chain[nchain].datalen = 0;
887 acb->ds.chain[--nchain].datalen += tcount;
888 #ifdef DEBUG
889 ++siopngdma_hits;
890 #endif
891 }
892 else {
893 dmaend = acb->ds.chain[nchain].databuf +
894 acb->ds.chain[nchain].datalen;
895 acb->ds.chain[nchain].datalen = tcount;
896 #ifdef DEBUG
897 if (nchain) /* Don't count miss on first one */
898 ++siopngdma_misses;
899 #endif
900 }
901 ++nchain;
902 }
903 #ifdef DEBUG
904 if (nchain != 1 && len != 0 && siopng_debug & 3) {
905 printf ("DMA chaining set: %d\n", nchain);
906 for (i = 0; i < nchain; ++i) {
907 printf (" [%d] %8p %lx\n", i, acb->ds.chain[i].databuf,
908 acb->ds.chain[i].datalen);
909 }
910 }
911 #endif
912
913 /* push data cache for all data the 53c720/770 needs to access */
914 dma_cachectl ((caddr_t)acb, sizeof (struct siop_acb));
915 dma_cachectl (cbuf, clen);
916 if (buf != NULL && len != 0)
917 dma_cachectl (buf, len);
918 #ifdef DEBUG
919 if (siopng_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
920 printf ("ACK! siopng was busy at start: rp %p script %p dsa %p active %ld\n",
921 rp, &siopng_scripts, &acb->ds, sc->sc_active);
922 #ifdef DDB
923 /*Debugger();*/
924 #endif
925 }
926 #endif
927 if (sc->nexus_list.tqh_first == NULL) {
928 if (rp->siop_istat & SIOP_ISTAT_CON)
929 printf("%s: siopng_select while connected?\n",
930 sc->sc_dev.dv_xname);
931 rp->siop_temp = 0;
932 #ifndef FIXME
933 rp->siop_scntl3 = sc->sc_sync[target].scntl3;
934 #endif
935 rp->siop_dsa = kvtop((caddr_t)&acb->ds);
936 rp->siop_dsp = sc->sc_scriptspa;
937 SIOP_TRACE('s',1,0,0)
938 } else {
939 if ((rp->siop_istat & SIOP_ISTAT_CON) == 0) {
940 rp->siop_istat = SIOP_ISTAT_SIGP;
941 SIOP_TRACE('s',2,0,0);
942 }
943 else {
944 SIOP_TRACE('s',3,rp->siop_istat,0);
945 }
946 }
947 #ifdef DEBUG
948 ++siopngstarts;
949 #endif
950 }
951
952 /*
953 * Process a DMA or SCSI interrupt from the 53C720/770 SIOP
954 */
955
956 int
957 siopng_checkintr(sc, istat, dstat, sist, status)
958 struct siop_softc *sc;
959 u_char istat;
960 u_char dstat;
961 u_short sist;
962 int *status;
963 {
964 siop_regmap_p rp = sc->sc_siopp;
965 struct siop_acb *acb = sc->sc_nexus;
966 int target = 0;
967 int dfifo, dbc, sstat0, sstat1, sstat2;
968
969 dfifo = rp->siop_dfifo;
970 dbc = rp->siop_dbc0;
971 sstat0 = rp->siop_sstat0;
972 sstat1 = rp->siop_sstat1;
973 sstat2 = rp->siop_sstat2;
974 rp->siop_ctest3 |= SIOP_CTEST8_CLF;
975 while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) != SIOP_CTEST1_FMT)
976 ;
977 rp->siop_ctest3 &= ~SIOP_CTEST8_CLF;
978 #ifdef DEBUG
979 ++siopngints;
980 #if 0
981 if (siopng_debug & 0x100) {
982 DCIAS(&acb->stat[0]); /* XXX */
983 printf ("siopngchkintr: istat %x dstat %x sist %x dsps %x sbcl %x sts %x msg %x\n",
984 istat, dstat, sist, rp->siop_dsps, rp->siop_sbcl, acb->stat[0], acb->msg[0]);
985 printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
986 acb->msg[0], acb->msg[1], acb->msg[2],
987 acb->msg[3], acb->msg[4], acb->msg[5]);
988 }
989 #endif
990 if (rp->siop_dsp && (rp->siop_dsp < sc->sc_scriptspa ||
991 rp->siop_dsp >= sc->sc_scriptspa + sizeof(siopng_scripts))) {
992 printf ("%s: dsp not within script dsp %lx scripts %lx:%lx",
993 sc->sc_dev.dv_xname, rp->siop_dsp, sc->sc_scriptspa,
994 sc->sc_scriptspa + sizeof(siopng_scripts));
995 printf(" istat %x dstat %x sist %x\n",
996 istat, dstat, sist);
997 #ifdef DDB
998 Debugger();
999 #endif
1000 }
1001 #endif
1002 SIOP_TRACE('i',dstat,istat,(istat&SIOP_ISTAT_DIP)?rp->siop_dsps&0xff:sist);
1003 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) {
1004 /* Normal completion status, or check condition */
1005 #ifdef DEBUG
1006 if (rp->siop_dsa != kvtop((caddr_t)&acb->ds)) {
1007 printf ("siopng: invalid dsa: %lx %x\n", rp->siop_dsa,
1008 kvtop((caddr_t)&acb->ds));
1009 panic("*** siopng DSA invalid ***");
1010 }
1011 #endif
1012 target = acb->xs->xs_periph->periph_target;
1013 if (sc->sc_sync[target].state == NEG_WAITW) {
1014 if (acb->msg[1] == 0xff)
1015 printf ("%s: target %d ignored wide request\n",
1016 sc->sc_dev.dv_xname, target);
1017 else if (acb->msg[1] == MSG_REJECT)
1018 printf ("%s: target %d rejected wide request\n",
1019 sc->sc_dev.dv_xname, target);
1020 else {
1021 printf("%s: target %d (wide) %02x %02x %02x %02x\n",
1022 sc->sc_dev.dv_xname, target, acb->msg[1],
1023 acb->msg[2], acb->msg[3], acb->msg[4]);
1024 if (acb->msg[1] == MSG_EXT_MESSAGE &&
1025 acb->msg[2] == 2 &&
1026 acb->msg[3] == MSG_WIDE_REQ)
1027 sc->sc_sync[target].scntl3 = acb->msg[4] ?
1028 sc->sc_sync[target].scntl3 | SIOP_SCNTL3_EWS :
1029 sc->sc_sync[target].scntl3 & ~SIOP_SCNTL3_EWS;
1030 }
1031 sc->sc_sync[target].state = NEG_SYNC;
1032 }
1033 if (sc->sc_sync[target].state == NEG_WAITS) {
1034 if (acb->msg[1] == 0xff)
1035 printf ("%s: target %d ignored sync request\n",
1036 sc->sc_dev.dv_xname, target);
1037 else if (acb->msg[1] == MSG_REJECT)
1038 printf ("%s: target %d rejected sync request\n",
1039 sc->sc_dev.dv_xname, target);
1040 else
1041 /* XXX - need to set sync transfer parameters */
1042 printf("%s: target %d (sync) %02x %02x %02x\n",
1043 sc->sc_dev.dv_xname, target, acb->msg[1],
1044 acb->msg[2], acb->msg[3]);
1045 sc->sc_sync[target].state = NEG_DONE;
1046 }
1047 dma_cachectl(&acb->stat[0], 1);
1048 *status = acb->stat[0];
1049 #ifdef DEBUG
1050 if (rp->siop_sbcl & SIOP_BSY) {
1051 /*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n",
1052 rp, &siopng_scripts, &acb->ds);*/
1053 #ifdef DDB
1054 /*Debugger();*/
1055 #endif
1056 }
1057 if (acb->msg[0] != 0x00)
1058 printf("%s: message was not COMMAND COMPLETE: %x\n",
1059 sc->sc_dev.dv_xname, acb->msg[0]);
1060 #endif
1061 if (sc->nexus_list.tqh_first)
1062 rp->siop_dcntl |= SIOP_DCNTL_STD;
1063 return 1;
1064 }
1065 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0b) {
1066 target = acb->xs->xs_periph->periph_target;
1067 if (acb->msg[1] == MSG_EXT_MESSAGE && acb->msg[2] == 2 &&
1068 acb->msg[3] == MSG_WIDE_REQ) {
1069 #ifdef DEBUG
1070 if (siopngsync_debug)
1071 printf ("wide msg in: %02x %02x %02x %02x %02x %02x\n",
1072 acb->msg[0], acb->msg[1], acb->msg[2],
1073 acb->msg[3], acb->msg[4], acb->msg[5]);
1074 #endif
1075 sc->sc_sync[target].scntl3 &= ~(SIOP_SCNTL3_EWS);
1076 if (acb->msg[2] == 2 &&
1077 acb->msg[3] == MSG_WIDE_REQ &&
1078 acb->msg[4] != 0) {
1079 sc->sc_sync[target].scntl3 |= SIOP_SCNTL3_EWS;
1080 printf ("%s: target %d now wide %d\n",
1081 sc->sc_dev.dv_xname, target,
1082 acb->msg[4]);
1083 }
1084 rp->siop_scntl3 = sc->sc_sync[target].scntl3;
1085 if (sc->sc_sync[target].state == NEG_WAITW) {
1086 sc->sc_sync[target].state = NEG_SYNC;
1087 rp->siop_dsp = sc->sc_scriptspa + Ent_clear_ack;
1088 return(0);
1089 }
1090 rp->siop_dcntl |= SIOP_DCNTL_STD;
1091 sc->sc_sync[target].state = NEG_SYNC;
1092 return (0);
1093 }
1094 if (acb->msg[1] == MSG_EXT_MESSAGE && acb->msg[2] == 3 &&
1095 acb->msg[3] == MSG_SYNC_REQ) {
1096 #ifdef DEBUG
1097 if (siopngsync_debug)
1098 printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
1099 acb->msg[0], acb->msg[1], acb->msg[2],
1100 acb->msg[3], acb->msg[4], acb->msg[5]);
1101 #endif
1102 sc->sc_sync[target].sxfer = 0;
1103 sc->sc_sync[target].scntl3 = 5 | /* XXX */
1104 (sc->sc_sync[target].scntl3 & 0x88); /* XXX */
1105 if (acb->msg[2] == 3 &&
1106 acb->msg[3] == MSG_SYNC_REQ &&
1107 acb->msg[5] != 0) {
1108 #ifdef MAXTOR_KLUDGE
1109 /*
1110 * Kludge for my Maxtor XT8580S
1111 * It accepts whatever we request, even
1112 * though it won't work. So we ask for
1113 * a short period than we can handle. If
1114 * the device says it can do it, use 208ns.
1115 * If the device says it can do less than
1116 * 100ns, then we limit it to 100ns.
1117 */
1118 if (acb->msg[4] && acb->msg[4] < 100 / 4) {
1119 #ifdef DEBUG
1120 printf ("%d: target %d wanted %dns period\n",
1121 sc->sc_dev.dv_xname, target,
1122 acb->msg[4] * 4);
1123 #endif
1124 if (acb->msg[4] == 50 / 4)
1125 acb->msg[4] = 208 / 4;
1126 else
1127 acb->msg[4] = 100 / 4;
1128 }
1129 #endif /* MAXTOR_KLUDGE */
1130 printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
1131 sc->sc_dev.dv_xname, target,
1132 (acb->msg[4] == 12) ? 50 : acb->msg[4] * 4,
1133 acb->msg[5]);
1134 scsi_period_to_siopng (sc, target);
1135 }
1136 rp->siop_sxfer = sc->sc_sync[target].sxfer;
1137 rp->siop_scntl3 = sc->sc_sync[target].scntl3;
1138 if (sc->sc_sync[target].state == NEG_WAITS) {
1139 sc->sc_sync[target].state = NEG_DONE;
1140 rp->siop_dsp = sc->sc_scriptspa + Ent_clear_ack;
1141 return(0);
1142 }
1143 rp->siop_dcntl |= SIOP_DCNTL_STD;
1144 sc->sc_sync[target].state = NEG_DONE;
1145 return (0);
1146 }
1147 /* XXX - not SDTR message */
1148 }
1149 if (sist & SIOP_SIST_MA) { /* Phase mismatch */
1150 #ifdef DEBUG
1151 ++siopngphmm;
1152 if (acb == NULL)
1153 printf("%s: Phase mismatch with no active command?\n",
1154 sc->sc_dev.dv_xname);
1155 #endif
1156 if (acb->iob_len) {
1157 int adjust;
1158 adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
1159 if (sstat0 & SIOP_SSTAT0_OLF) /* sstat0 SODL lsb */
1160 ++adjust;
1161 if (sstat0 & SIOP_SSTAT0_ORF) /* sstat0 SODR lsb */
1162 ++adjust;
1163 if (sstat2 & SIOP_SSTAT2_OLF1) /* sstat2 SODL msb */
1164 ++adjust;
1165 if (sstat2 & SIOP_SSTAT2_ORF1) /* sstat2 SODR msb */
1166 ++adjust;
1167 acb->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff;
1168 acb->iob_curlen += adjust;
1169 acb->iob_curbuf = *((long *)&rp->siop_dnad) - adjust;
1170 #ifdef DEBUG
1171 if (siopng_debug & 0x100) {
1172 int i;
1173 printf ("Phase mismatch: curbuf %lx curlen %lx dfifo %x dbc %x sstat1 %x adjust %x sbcl %x starts %d acb %p\n",
1174 acb->iob_curbuf, acb->iob_curlen, dfifo,
1175 dbc, sstat1, adjust, rp->siop_sbcl, siopngstarts, acb);
1176 if (acb->ds.chain[1].datalen) {
1177 for (i = 0; acb->ds.chain[i].datalen; ++i)
1178 printf("chain[%d] addr %p len %lx\n",
1179 i, acb->ds.chain[i].databuf,
1180 acb->ds.chain[i].datalen);
1181 }
1182 }
1183 #endif
1184 dma_cachectl ((caddr_t)acb, sizeof(*acb));
1185 }
1186 #ifdef DEBUG
1187 SIOP_TRACE('m',rp->siop_sbcl,(rp->siop_dsp>>8),rp->siop_dsp);
1188 if (siopng_debug & 9)
1189 printf ("Phase mismatch: %x dsp +%lx dcmd %lx\n",
1190 rp->siop_sbcl,
1191 rp->siop_dsp - sc->sc_scriptspa,
1192 *((long *)&rp->siop_dcmd));
1193 #endif
1194 if ((rp->siop_sbcl & SIOP_REQ) == 0) {
1195 printf ("Phase mismatch: REQ not asserted! %02x dsp %lx\n",
1196 rp->siop_sbcl, rp->siop_dsp);
1197 #if defined(DEBUG) && defined(DDB)
1198 Debugger();
1199 #endif
1200 }
1201 switch (rp->siop_sbcl & 7) {
1202 case 0: /* data out */
1203 case 1: /* data in */
1204 case 2: /* status */
1205 case 3: /* command */
1206 case 6: /* message in */
1207 case 7: /* message out */
1208 rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
1209 break;
1210 default:
1211 goto bad_phase;
1212 }
1213 return 0;
1214 }
1215 if (sist & SIOP_SIST_STO) { /* Select timed out */
1216 #ifdef DEBUG
1217 if (acb == NULL)
1218 printf("%s: Select timeout with no active command?\n",
1219 sc->sc_dev.dv_xname);
1220 if (rp->siop_sbcl & SIOP_BSY) {
1221 printf ("ACK! siop was busy at timeout: rp %p script %p dsa %p\n",
1222 rp, &siopng_scripts, &acb->ds);
1223 printf(" sbcl %x sdid %x istat %x dstat %x sist %x\n",
1224 rp->siop_sbcl, rp->siop_sdid, istat, dstat, sist);
1225 if (!(rp->siop_sbcl & SIOP_BSY)) {
1226 printf ("Yikes, it's not busy now!\n");
1227 #if 0
1228 *status = -1;
1229 if (sc->nexus_list.tqh_first)
1230 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1231 return 1;
1232 #endif
1233 }
1234 /* rp->siop_dcntl |= SIOP_DCNTL_STD;*/
1235 return (0);
1236 #ifdef DDB
1237 Debugger();
1238 #endif
1239 }
1240 #endif
1241 *status = -1;
1242 acb->xs->error = XS_SELTIMEOUT;
1243 if (sc->nexus_list.tqh_first)
1244 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1245 return 1;
1246 }
1247 if (acb)
1248 target = acb->xs->xs_periph->periph_target;
1249 else
1250 target = 7;
1251 if (sist & SIOP_SIST_UDC) {
1252 #ifdef DEBUG
1253 if (acb == NULL)
1254 printf("%s: Unexpected disconnect with no active command?\n",
1255 sc->sc_dev.dv_xname);
1256 printf ("%s: target %d disconnected unexpectedly\n",
1257 sc->sc_dev.dv_xname, target);
1258 siopng_dump_registers(sc);
1259 siopng_dump(sc);
1260 #endif
1261 #if 0
1262 siopngabort (sc, rp, "siopngchkintr");
1263 #endif
1264 *status = STS_BUSY;
1265 if (sc->nexus_list.tqh_first)
1266 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1267 return (acb != NULL);
1268 }
1269 if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff01 ||
1270 rp->siop_dsps == 0xff02)) {
1271 #ifdef DEBUG
1272 if (siopng_debug & 0x100)
1273 printf ("%s: ID %02x disconnected TEMP %lx (+%lx) curbuf %lx curlen %lx buf %p len %lx dfifo %x dbc %x sstat1 %x starts %d acb %p\n",
1274 sc->sc_dev.dv_xname, 1 << target, rp->siop_temp,
1275 rp->siop_temp ? rp->siop_temp - sc->sc_scriptspa : 0,
1276 acb->iob_curbuf, acb->iob_curlen,
1277 acb->ds.chain[0].databuf, acb->ds.chain[0].datalen, dfifo, dbc, sstat1, siopngstarts, acb);
1278 #endif
1279 if (acb == NULL) {
1280 printf("%s: Disconnect with no active command?\n",
1281 sc->sc_dev.dv_xname);
1282 return (0);
1283 }
1284 /*
1285 * XXXX need to update iob_curbuf/iob_curlen to reflect
1286 * current data transferred. If device disconnected in
1287 * the middle of a DMA block, they should already be set
1288 * by the phase change interrupt. If the disconnect
1289 * occurs on a DMA block boundary, we have to figure out
1290 * which DMA block it was.
1291 */
1292 if (acb->iob_len && rp->siop_temp) {
1293 int n = rp->siop_temp - sc->sc_scriptspa;
1294
1295 if (acb->iob_curlen && acb->iob_curlen != acb->ds.chain[0].datalen)
1296 printf("%s: iob_curbuf/len already set? n %x iob %lx/%lx chain[0] %p/%lx\n",
1297 sc->sc_dev.dv_xname, n, acb->iob_curbuf, acb->iob_curlen,
1298 acb->ds.chain[0].databuf, acb->ds.chain[0].datalen);
1299 if (n < Ent_datain)
1300 n = (n - Ent_dataout) / 16;
1301 else
1302 n = (n - Ent_datain) / 16;
1303 if (n <= 0 && n > DMAMAXIO)
1304 printf("TEMP invalid %d\n", n);
1305 else {
1306 acb->iob_curbuf = (u_long)acb->ds.chain[n].databuf;
1307 acb->iob_curlen = acb->ds.chain[n].datalen;
1308 }
1309 #ifdef DEBUG
1310 if (siopng_debug & 0x100) {
1311 printf("%s: TEMP offset %d", sc->sc_dev.dv_xname, n);
1312 printf(" curbuf %lx curlen %lx\n", acb->iob_curbuf,
1313 acb->iob_curlen);
1314 }
1315 #endif
1316 }
1317 /*
1318 * If data transfer was interrupted by disconnect, iob_curbuf
1319 * and iob_curlen should reflect the point of interruption.
1320 * Adjust the DMA chain so that the data transfer begins
1321 * at the appropriate place upon reselection.
1322 * XXX This should only be done on save data pointer message?
1323 */
1324 if (acb->iob_curlen) {
1325 int i, j;
1326
1327 #ifdef DEBUG
1328 if (siopng_debug & 0x100)
1329 printf ("%s: adjusting DMA chain\n",
1330 sc->sc_dev.dv_xname);
1331 if (rp->siop_dsps == 0xff02)
1332 printf ("%s: ID %02x disconnected without Save Data Pointers\n",
1333 sc->sc_dev.dv_xname, 1 << target);
1334 #endif
1335 for (i = 0; i < DMAMAXIO; ++i) {
1336 if (acb->ds.chain[i].datalen == 0)
1337 break;
1338 if (acb->iob_curbuf >= (long)acb->ds.chain[i].databuf &&
1339 acb->iob_curbuf < (long)(acb->ds.chain[i].databuf +
1340 acb->ds.chain[i].datalen))
1341 break;
1342 }
1343 if (i >= DMAMAXIO || acb->ds.chain[i].datalen == 0) {
1344 printf("couldn't find saved data pointer: ");
1345 printf("curbuf %lx curlen %lx i %d\n",
1346 acb->iob_curbuf, acb->iob_curlen, i);
1347 #ifdef DDB
1348 Debugger();
1349 #endif
1350 }
1351 #ifdef DEBUG
1352 if (siopng_debug & 0x100)
1353 printf(" chain[0]: %p/%lx -> %lx/%lx\n",
1354 acb->ds.chain[0].databuf,
1355 acb->ds.chain[0].datalen,
1356 acb->iob_curbuf,
1357 acb->iob_curlen);
1358 #endif
1359 acb->ds.chain[0].databuf = (char *)acb->iob_curbuf;
1360 acb->ds.chain[0].datalen = acb->iob_curlen;
1361 for (j = 1, ++i; i < DMAMAXIO && acb->ds.chain[i].datalen; ++i, ++j) {
1362 #ifdef DEBUG
1363 if (siopng_debug & 0x100)
1364 printf(" chain[%d]: %p/%lx -> %p/%lx\n", j,
1365 acb->ds.chain[j].databuf,
1366 acb->ds.chain[j].datalen,
1367 acb->ds.chain[i].databuf,
1368 acb->ds.chain[i].datalen);
1369 #endif
1370 acb->ds.chain[j].databuf = acb->ds.chain[i].databuf;
1371 acb->ds.chain[j].datalen = acb->ds.chain[i].datalen;
1372 }
1373 if (j < DMAMAXIO)
1374 acb->ds.chain[j].datalen = 0;
1375 DCIAS(kvtop((caddr_t)&acb->ds.chain));
1376 }
1377 ++sc->sc_tinfo[target].dconns;
1378 /*
1379 * add nexus to waiting list
1380 * clear nexus
1381 * try to start another command for another target/lun
1382 */
1383 acb->status = sc->sc_flags & SIOP_INTSOFF;
1384 TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain);
1385 sc->sc_nexus = NULL; /* no current device */
1386 /* start script to wait for reselect */
1387 if (sc->sc_nexus == NULL)
1388 rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
1389 /* XXXX start another command ? */
1390 if (sc->ready_list.tqh_first)
1391 siopng_sched(sc);
1392 #if 0
1393 else
1394 rp->siop_dcntl |= SIOP_DCNTL_STD;
1395 #endif
1396 return (0);
1397 }
1398 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff03) {
1399 int reselid = rp->siop_scratcha & 0x7f;
1400 int reselun = rp->siop_sfbr & 0x07;
1401
1402 sc->sc_sstat1 = rp->siop_sbcl; /* XXXX save current SBCL */
1403 #ifdef DEBUG
1404 if (siopng_debug & 0x100)
1405 printf ("%s: target ID %02x reselected dsps %lx\n",
1406 sc->sc_dev.dv_xname, reselid,
1407 rp->siop_dsps);
1408 if ((rp->siop_sfbr & 0x80) == 0)
1409 printf("%s: Reselect message in was not identify: %x\n",
1410 sc->sc_dev.dv_xname, rp->siop_sfbr);
1411 #endif
1412 if (sc->sc_nexus) {
1413 #ifdef DEBUG
1414 if (siopng_debug & 0x100)
1415 printf ("%s: reselect ID %02x w/active\n",
1416 sc->sc_dev.dv_xname, reselid);
1417 #endif
1418 TAILQ_INSERT_HEAD(&sc->ready_list, sc->sc_nexus, chain);
1419 sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target].lubusy
1420 &= ~(1 << sc->sc_nexus->xs->xs_periph->periph_lun);
1421 --sc->sc_active;
1422 }
1423 /*
1424 * locate acb of reselecting device
1425 * set sc->sc_nexus to acb
1426 */
1427 for (acb = sc->nexus_list.tqh_first; acb;
1428 acb = acb->chain.tqe_next) {
1429 if (reselid != ((acb->ds.scsi_addr >> 16) & 0xff) ||
1430 reselun != (acb->msgout[0] & 0x07))
1431 continue;
1432 TAILQ_REMOVE(&sc->nexus_list, acb, chain);
1433 sc->sc_nexus = acb;
1434 sc->sc_flags |= acb->status;
1435 acb->status = 0;
1436 DCIAS(kvtop(&acb->stat[0]));
1437 rp->siop_dsa = kvtop((caddr_t)&acb->ds);
1438 rp->siop_sxfer =
1439 sc->sc_sync[acb->xs->xs_periph->periph_target].sxfer;
1440 #ifndef FIXME
1441 rp->siop_scntl3 =
1442 sc->sc_sync[acb->xs->xs_periph->periph_target].scntl3;
1443 #endif
1444 break;
1445 }
1446 if (acb == NULL) {
1447 printf("%s: target ID %02x reselect nexus_list %p\n",
1448 sc->sc_dev.dv_xname, reselid,
1449 sc->nexus_list.tqh_first);
1450 panic("unable to find reselecting device");
1451 }
1452 dma_cachectl ((caddr_t)acb, sizeof(*acb));
1453 rp->siop_temp = 0;
1454 rp->siop_dcntl |= SIOP_DCNTL_STD;
1455 return (0);
1456 }
1457 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff04) {
1458 #ifdef DEBUG
1459 u_short ctest2 = rp->siop_ctest2;
1460
1461 /* reselect was interrupted (by Sig_P or select) */
1462 if (siopng_debug & 0x100 ||
1463 (ctest2 & SIOP_CTEST2_SIGP) == 0)
1464 printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x istat %x/%x\n",
1465 sc->sc_dev.dv_xname, rp->siop_scntl1,
1466 ctest2, rp->siop_sfbr, istat, rp->siop_istat);
1467 #endif
1468 /* XXX assumes it was not select */
1469 if (sc->sc_nexus == NULL) {
1470 #ifdef DEBUG
1471 printf("%s: reselect interrupted, sc_nexus == NULL\n",
1472 sc->sc_dev.dv_xname);
1473 #if 0
1474 siopng_dump(sc);
1475 #ifdef DDB
1476 Debugger();
1477 #endif
1478 #endif
1479 #endif
1480 rp->siop_dcntl |= SIOP_DCNTL_STD;
1481 return(0);
1482 }
1483 target = sc->sc_nexus->xs->xs_periph->periph_target;
1484 rp->siop_temp = 0;
1485 rp->siop_dsa = kvtop((caddr_t)&sc->sc_nexus->ds);
1486 rp->siop_sxfer = sc->sc_sync[target].sxfer;
1487 #ifndef FIXME
1488 rp->siop_scntl3 = sc->sc_sync[target].scntl3;
1489 #endif
1490 rp->siop_dsp = sc->sc_scriptspa;
1491 return (0);
1492 }
1493 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff06) {
1494 if (acb == NULL)
1495 printf("%s: Bad message-in with no active command?\n",
1496 sc->sc_dev.dv_xname);
1497 /* Unrecognized message in byte */
1498 dma_cachectl (&acb->msg[1],1);
1499 printf ("%s: Unrecognized message in data sfbr %x msg %x sbcl %x\n",
1500 sc->sc_dev.dv_xname, rp->siop_sfbr, acb->msg[1], rp->siop_sbcl);
1501 /* what should be done here? */
1502 DCIAS(kvtop(&acb->msg[1]));
1503 rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
1504 return (0);
1505 }
1506 if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) {
1507 /* Status phase wasn't followed by message in phase? */
1508 printf ("%s: Status phase not followed by message in phase? sbcl %x sbdl %x\n",
1509 sc->sc_dev.dv_xname, rp->siop_sbcl, rp->siop_sbdl);
1510 if (rp->siop_sbcl == 0xa7) {
1511 /* It is now, just continue the script? */
1512 rp->siop_dcntl |= SIOP_DCNTL_STD;
1513 return (0);
1514 }
1515 }
1516 if (sist == 0 && dstat & SIOP_DSTAT_SIR) {
1517 dma_cachectl (&acb->stat[0], 1);
1518 dma_cachectl (&acb->msg[0], 1);
1519 printf ("SIOP interrupt: %lx sts %x msg %x %x sbcl %x\n",
1520 rp->siop_dsps, acb->stat[0], acb->msg[0], acb->msg[1],
1521 rp->siop_sbcl);
1522 siopngreset (sc);
1523 *status = -1;
1524 return 0; /* siopngreset has cleaned up */
1525 }
1526 if (sist & SIOP_SIST_SGE)
1527 printf ("SIOP: SCSI Gross Error\n");
1528 if (sist & SIOP_SIST_PAR)
1529 printf ("SIOP: Parity Error\n");
1530 if (dstat & SIOP_DSTAT_IID)
1531 printf ("SIOP: Invalid instruction detected\n");
1532 bad_phase:
1533 /*
1534 * temporary panic for unhandled conditions
1535 * displays various things about the 53C720/770 status and registers
1536 * then panics.
1537 * XXXX need to clean this up to print out the info, reset, and continue
1538 */
1539 printf ("siopngchkintr: target %x ds %p\n", target, &acb->ds);
1540 printf ("scripts %lx ds %x rp %x dsp %lx dcmd %lx\n", sc->sc_scriptspa,
1541 kvtop((caddr_t)&acb->ds), kvtop((caddr_t)rp), rp->siop_dsp,
1542 *((long *)&rp->siop_dcmd));
1543 printf ("siopngchkintr: istat %x dstat %x sist %x dsps %lx dsa %lx sbcl %x sts %x msg %x %x sfbr %x\n",
1544 istat, dstat, sist, rp->siop_dsps, rp->siop_dsa,
1545 rp->siop_sbcl, acb->stat[0], acb->msg[0], acb->msg[1], rp->siop_sfbr);
1546 #ifdef DEBUG
1547 if (siopng_debug & 0x20)
1548 panic("siopngchkintr: **** temp ****");
1549 #endif
1550 #ifdef DDB
1551 Debugger ();
1552 #endif
1553 siopngreset (sc); /* hard reset */
1554 *status = -1;
1555 return 0; /* siopngreset cleaned up */
1556 }
1557
1558 void
1559 siopng_select(sc)
1560 struct siop_softc *sc;
1561 {
1562 siop_regmap_p rp;
1563 struct siop_acb *acb = sc->sc_nexus;
1564
1565 #ifdef DEBUG
1566 if (siopng_debug & 1)
1567 printf ("%s: select ", sc->sc_dev.dv_xname);
1568 #endif
1569
1570 rp = sc->sc_siopp;
1571 if (acb->xs->xs_control & XS_CTL_POLL || siopng_no_dma) {
1572 sc->sc_flags |= SIOP_INTSOFF;
1573 sc->sc_flags &= ~SIOP_INTDEFER;
1574 if ((rp->siop_istat & 0x08) == 0) {
1575 rp->siop_sien = 0;
1576 rp->siop_dien = 0;
1577 }
1578 #if 0
1579 } else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
1580 sc->sc_flags &= ~SIOP_INTSOFF;
1581 if ((rp->siop_istat & 0x08) == 0) {
1582 rp->siop_sien = sc->sc_sien;
1583 rp->siop_dien = sc->sc_dien;
1584 }
1585 #endif
1586 }
1587 #ifdef DEBUG
1588 if (siopng_debug & 1)
1589 printf ("siopng_select: target %x cmd %02x ds %p\n",
1590 acb->xs->xs_periph->periph_target, acb->cmd.opcode,
1591 &sc->sc_nexus->ds);
1592 #endif
1593
1594 siopng_start(sc, acb->xs->xs_periph->periph_target,
1595 acb->xs->xs_periph->periph_lun,
1596 (u_char *)&acb->cmd, acb->clen, acb->daddr, acb->dleft);
1597
1598 return;
1599 }
1600
1601 /*
1602 * 53C720/770 interrupt handler
1603 */
1604
1605 void
1606 siopngintr (sc)
1607 register struct siop_softc *sc;
1608 {
1609 siop_regmap_p rp;
1610 u_char istat, dstat;
1611 u_short sist;
1612 int status;
1613 int s = splbio();
1614
1615 istat = sc->sc_istat;
1616 if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
1617 splx(s);
1618 return;
1619 }
1620
1621 /* Got a valid interrupt on this device */
1622 rp = sc->sc_siopp;
1623 dstat = sc->sc_dstat;
1624 sist = sc->sc_sist;
1625 if (dstat & SIOP_DSTAT_SIR)
1626 sc->sc_intcode = rp->siop_dsps;
1627 sc->sc_istat = 0;
1628 #ifdef DEBUG
1629 if (siopng_debug & 1)
1630 printf ("%s: intr istat %x dstat %x sist %x\n",
1631 sc->sc_dev.dv_xname, istat, dstat, sist);
1632 if (!sc->sc_active) {
1633 printf ("%s: spurious interrupt? istat %x dstat %x sist %x nexus %p status %x\n",
1634 sc->sc_dev.dv_xname, istat, dstat, sist,
1635 sc->sc_nexus, sc->sc_nexus ? sc->sc_nexus->stat[0] : 0);
1636 }
1637 #endif
1638
1639 #ifdef DEBUG
1640 if (siopng_debug & 5) {
1641 DCIAS(kvtop(&sc->sc_nexus->stat[0]));
1642 printf ("%s: intr istat %x dstat %x sist %x dsps %lx sbcl %x sts %x msg %x\n",
1643 sc->sc_dev.dv_xname, istat, dstat, sist,
1644 rp->siop_dsps, rp->siop_sbcl,
1645 sc->sc_nexus->stat[0], sc->sc_nexus->msg[0]);
1646 }
1647 #endif
1648 if (sc->sc_flags & SIOP_INTDEFER) {
1649 sc->sc_flags &= ~(SIOP_INTDEFER | SIOP_INTSOFF);
1650 rp->siop_sien = sc->sc_sien;
1651 rp->siop_dien = sc->sc_dien;
1652 }
1653 if (siopng_checkintr (sc, istat, dstat, sist, &status)) {
1654 #if 1
1655 if (status == 0xff)
1656 printf ("siopngintr: status == 0xff\n");
1657 #endif
1658 if ((sc->sc_flags & (SIOP_INTSOFF | SIOP_INTDEFER)) != SIOP_INTSOFF) {
1659 #if 0
1660 if (rp->siop_sbcl & SIOP_BSY) {
1661 printf ("%s: SCSI bus busy at completion",
1662 sc->sc_dev.dv_xname);
1663 printf(" targ %d sbcl %02x sfbr %x respid %02x dsp +%x\n",
1664 sc->sc_nexus->xs->xs_periph->periph_target,
1665 rp->siop_sbcl, rp->siop_sfbr, rp->siop_respid,
1666 rp->siop_dsp - sc->sc_scriptspa);
1667 }
1668 #endif
1669 siopng_scsidone(sc->sc_nexus, sc->sc_nexus ?
1670 sc->sc_nexus->stat[0] : -1);
1671 }
1672 }
1673 splx(s);
1674 }
1675
1676 /*
1677 * This is based on the Progressive Peripherals 33Mhz Zeus driver and will
1678 * not be correct for other 53c710 boards.
1679 *
1680 */
1681 void
1682 scsi_period_to_siopng (sc, target)
1683 struct siop_softc *sc;
1684 int target;
1685 {
1686 int period, offset, sxfer, scntl3 = 0;
1687
1688 period = sc->sc_nexus->msg[4];
1689 offset = sc->sc_nexus->msg[5];
1690 #ifdef FIXME
1691 for (scntl3 = 1; scntl3 < 4; ++scntl3) {
1692 sxfer = (period * 4 - 1) / sc->sc_tcp[scntl3] - 3;
1693 if (sxfer >= 0 && sxfer <= 7)
1694 break;
1695 }
1696 if (scntl3 > 3) {
1697 printf("siopng sync: unable to compute sync params for period %dns\n",
1698 period * 4);
1699 /*
1700 * XXX need to pick a value we can do and renegotiate
1701 */
1702 sxfer = scntl3 = 0;
1703 } else {
1704 sxfer = (sxfer << 4) | ((offset <= SIOP_MAX_OFFSET) ?
1705 offset : SIOP_MAX_OFFSET);
1706 #ifdef DEBUG_SYNC
1707 printf("siopng sync: params for period %dns: sxfer %x scntl3 %x",
1708 period * 4, sxfer, scntl3);
1709 printf(" actual period %dns\n",
1710 sc->sc_tcp[scntl3] * ((sxfer >> 4) + 4));
1711 #endif /* DEBUG_SYNC */
1712 }
1713 #else /* FIXME */
1714 sxfer = offset <= SIOP_MAX_OFFSET ? offset : SIOP_MAX_OFFSET;
1715 sxfer |= 0x20; /* XXX XFERP: 5 */
1716 #ifndef FIXME
1717 if (period <= (50 / 4)) /* XXX */
1718 scntl3 = 0x95; /* Ultra, SCF: /1, CCF: /4 */
1719 else if (period <= (100 / 4))
1720 scntl3 = 0x35; /* SCF: /2, CCF: /4 */
1721 else if (period <= (200 / 4))
1722 scntl3 = 0x55; /* SCF: /4, CCF: /4 */
1723 else
1724 scntl3 = 0xff; /* XXX ??? */
1725 #else
1726 scntl3 = 5;
1727 #endif
1728 #endif
1729 sc->sc_sync[target].sxfer = sxfer;
1730 sc->sc_sync[target].scntl3 = scntl3 |
1731 (sc->sc_sync[target].scntl3 & SIOP_SCNTL3_EWS);
1732 #ifdef DEBUG_SYNC
1733 printf ("siopng sync: siop_sxfr %02x, siop_scntl3 %02x\n", sxfer, scntl3);
1734 #endif
1735 }
1736
1737 void
1738 siopng_dump_registers(sc)
1739 struct siop_softc *sc;
1740 {
1741 siop_regmap_p rp = sc->sc_siopp;
1742
1743 printf(" scntl0 %02x scntl1 %02x scntl2 %02x scntl3 %02x\n",
1744 rp->siop_scntl0, rp->siop_scntl1, rp->siop_scntl2, rp->siop_scntl3);
1745 printf(" scid %02x sxfer %02x sdid %02x gpreg %02x\n",
1746 rp->siop_scid, rp->siop_sxfer, rp->siop_sdid, rp->siop_gpreg);
1747 printf(" sfbr %02x socl %02x ssid %02x sbcl %02x\n",
1748 rp->siop_sfbr, rp->siop_socl, rp->siop_ssid, rp->siop_sbcl);
1749 printf(" dstat %02x sstat0 %02x sstat1 %02x sstat2 %02x\n",
1750 rp->siop_dstat, rp->siop_sstat0, rp->siop_sstat1, rp->siop_sstat2);
1751 printf(" ctest0 %02x ctest1 %02x ctest2 %02x ctest3 %02x\n",
1752 rp->siop_ctest0, rp->siop_ctest1, rp->siop_ctest2, rp->siop_ctest3);
1753 printf(" dfifo %02x ctest4 %02x ctest5 %02x ctest6 %02x\n",
1754 0, rp->siop_ctest4, rp->siop_ctest5, rp->siop_ctest6);
1755 printf(" dcmd %02x dbc2 %02x dbc1 %02x dbc0 %02x\n",
1756 rp->siop_dcmd, rp->siop_dbc2, rp->siop_dbc1, rp->siop_dbc0);
1757 printf(" dmode %02x dien %02x dwt %02x dcntl %02x\n",
1758 rp->siop_dmode, rp->siop_dien, rp->siop_dwt, rp->siop_dcntl);
1759 printf(" stest0 %02x stest1 %02x stest2 %02x stest3 %02x\n",
1760 rp->siop_stest0, rp->siop_stest1, rp->siop_stest2, rp->siop_stest3);
1761 printf(" istat %02x sien %04x sist %04x respid %04x\n",
1762 rp->siop_istat, rp->siop_sien, rp->siop_sist, rp->siop_respid);
1763 printf(" sidl %04x sodl %04x sbdl %04x\n",
1764 rp->siop_sidl, rp->siop_sodl, rp->siop_sbdl);
1765 printf(" dsps %08lx dsp %08lx (+%lx)\n",
1766 rp->siop_dsps, rp->siop_dsp, rp->siop_dsp > sc->sc_scriptspa ?
1767 rp->siop_dsp - sc->sc_scriptspa : 0);
1768 printf(" dsa %08lx temp %08lx dnad %08lx\n",
1769 rp->siop_dsa, rp->siop_temp, rp->siop_dnad);
1770 printf(" scratcha %08lx scratchb %08lx adder %08lx\n",
1771 rp->siop_scratcha, rp->siop_scratchb, rp->siop_adder);
1772 }
1773
1774 #ifdef DEBUG
1775
1776 #if SIOP_TRACE_SIZE
1777 void
1778 siopng_dump_trace()
1779 {
1780 int i;
1781
1782 printf("siopng trace: next index %d\n", siopng_trix);
1783 i = siopng_trix;
1784 do {
1785 printf("%3d: '%c' %02x %02x %02x\n", i, siopng_trbuf[i],
1786 siopng_trbuf[i + 1], siopng_trbuf[i + 2], siopng_trbuf[i + 3]);
1787 i = (i + 4) & (SIOP_TRACE_SIZE - 1);
1788 } while (i != siopng_trix);
1789 }
1790 #endif
1791
1792 void
1793 siopng_dump_acb(acb)
1794 struct siop_acb *acb;
1795 {
1796 u_char *b = (u_char *) &acb->cmd;
1797 int i;
1798
1799 printf("acb@%p ", acb);
1800 if (acb->xs == NULL) {
1801 printf("<unused>\n");
1802 return;
1803 }
1804 printf("(%d:%d) flags %2x clen %2d cmd ",
1805 acb->xs->xs_periph->periph_target,
1806 acb->xs->xs_periph->periph_lun, acb->flags, acb->clen);
1807 for (i = acb->clen; i; --i)
1808 printf(" %02x", *b++);
1809 printf("\n");
1810 printf(" xs: %p data %p:%04x ", acb->xs, acb->xs->data,
1811 acb->xs->datalen);
1812 printf("va %p:%lx ", acb->iob_buf, acb->iob_len);
1813 printf("cur %lx:%lx\n", acb->iob_curbuf, acb->iob_curlen);
1814 }
1815
1816 void
1817 siopng_dump(sc)
1818 struct siop_softc *sc;
1819 {
1820 struct siop_acb *acb;
1821 siop_regmap_p rp = sc->sc_siopp;
1822 int s;
1823 int i;
1824
1825 s = splbio();
1826 #if SIOP_TRACE_SIZE
1827 siopng_dump_trace();
1828 #endif
1829 printf("%s@%p regs %p istat %x\n",
1830 sc->sc_dev.dv_xname, sc, rp, rp->siop_istat);
1831 if ((acb = sc->free_list.tqh_first) > 0) {
1832 printf("Free list:\n");
1833 while (acb) {
1834 siopng_dump_acb(acb);
1835 acb = acb->chain.tqe_next;
1836 }
1837 }
1838 if ((acb = sc->ready_list.tqh_first) > 0) {
1839 printf("Ready list:\n");
1840 while (acb) {
1841 siopng_dump_acb(acb);
1842 acb = acb->chain.tqe_next;
1843 }
1844 }
1845 if ((acb = sc->nexus_list.tqh_first) > 0) {
1846 printf("Nexus list:\n");
1847 while (acb) {
1848 siopng_dump_acb(acb);
1849 acb = acb->chain.tqe_next;
1850 }
1851 }
1852 if (sc->sc_nexus) {
1853 printf("Nexus:\n");
1854 siopng_dump_acb(sc->sc_nexus);
1855 }
1856 for (i = 0; i < 8; ++i) {
1857 if (sc->sc_tinfo[i].cmds > 2) {
1858 printf("tgt %d: cmds %d disc %d senses %d lubusy %x\n",
1859 i, sc->sc_tinfo[i].cmds,
1860 sc->sc_tinfo[i].dconns,
1861 sc->sc_tinfo[i].senses,
1862 sc->sc_tinfo[i].lubusy);
1863 }
1864 }
1865 splx(s);
1866 }
1867 #endif
1868