Home | History | Annotate | Line # | Download | only in dev
siop.c revision 1.27
      1 /*	$NetBSD: siop.c,v 1.27 1996/01/07 22:01:58 thorpej 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 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/device.h>
     49 #include <sys/disklabel.h>
     50 #include <sys/dkstat.h>
     51 #include <sys/buf.h>
     52 #include <scsi/scsi_all.h>
     53 #include <scsi/scsiconf.h>
     54 #include <machine/cpu.h>
     55 #include <amiga/amiga/custom.h>
     56 #include <amiga/amiga/isr.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 void siop_select __P((struct siop_softc *));
     71 void siopabort __P((struct siop_softc *, siop_regmap_p, char *));
     72 void sioperror __P((struct siop_softc *, siop_regmap_p, u_char));
     73 void siopstart __P((struct siop_softc *));
     74 void siopreset __P((struct siop_softc *));
     75 void siopsetdelay __P((int));
     76 void siop_scsidone __P((struct siop_acb *, int));
     77 void siop_sched __P((struct siop_softc *));
     78 int  siop_poll __P((struct siop_softc *, struct siop_acb *));
     79 int  siopintr __P((struct siop_softc *));
     80 
     81 /* 53C710 script */
     82 const
     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] = {3, 3, 3, 3, 3, 3, 3, 3};
     88 int siop_no_dma = 0;
     89 
     90 int siop_reset_delay = 250;	/* delay after reset, in milleseconds */
     91 
     92 int siop_cmd_wait = SCSI_CMD_WAIT;
     93 int siop_data_wait = SCSI_DATA_WAIT;
     94 int siop_init_wait = SCSI_INIT_WAIT;
     95 
     96 #ifdef DEBUG
     97 /*
     98  * sync period transfer lookup - only valid for 66Mhz clock
     99  */
    100 static struct {
    101 	unsigned char p;	/* period from sync request message */
    102 	unsigned char r;	/* siop_period << 4 | sbcl */
    103 } sync_tab[] = {
    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 #endif
    130 
    131 #ifdef DEBUG
    132 /*
    133  *	0x01 - full debug
    134  *	0x02 - DMA chaining
    135  *	0x04 - siopintr
    136  *	0x08 - phase mismatch
    137  *	0x10 - <not used>
    138  *	0x20 - panic on unhandled exceptions
    139  *	0x100 - disconnect/reselect
    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 #define SIOP_TRACE_SIZE	128
    150 #define SIOP_TRACE(a,b,c,d) \
    151 	siop_trbuf[siop_trix] = (a); \
    152 	siop_trbuf[siop_trix+1] = (b); \
    153 	siop_trbuf[siop_trix+2] = (c); \
    154 	siop_trbuf[siop_trix+3] = (d); \
    155 	siop_trix = (siop_trix + 4) & (SIOP_TRACE_SIZE - 1);
    156 u_char	siop_trbuf[SIOP_TRACE_SIZE];
    157 int	siop_trix;
    158 void siop_dump __P((struct siop_softc *));
    159 void siop_dump_trace __P((void));
    160 #else
    161 #define SIOP_TRACE(a,b,c,d)
    162 #endif
    163 
    164 
    165 /*
    166  * default minphys routine for siop based controllers
    167  */
    168 void
    169 siop_minphys(bp)
    170 	struct buf *bp;
    171 {
    172 
    173 	/*
    174 	 * No max transfer at this level.
    175 	 */
    176 	minphys(bp);
    177 }
    178 
    179 /*
    180  * used by specific siop controller
    181  *
    182  */
    183 int
    184 siop_scsicmd(xs)
    185 	struct scsi_xfer *xs;
    186 {
    187 	struct siop_acb *acb;
    188 	struct siop_softc *sc;
    189 	struct scsi_link *slp;
    190 	int flags, s, i;
    191 
    192 	slp = xs->sc_link;
    193 	sc = slp->adapter_softc;
    194 	flags = xs->flags;
    195 
    196 	/* XXXX ?? */
    197 	if (flags & SCSI_DATA_UIO)
    198 		panic("siop: scsi data uio requested");
    199 
    200 	/* XXXX ?? */
    201 	if (sc->sc_nexus && flags & SCSI_POLL)
    202 /*		panic("siop_scsicmd: busy");*/
    203 		printf("siop_scsicmd: busy\n");
    204 
    205 	s = splbio();
    206 	acb = sc->free_list.tqh_first;
    207 	if (acb) {
    208 		TAILQ_REMOVE(&sc->free_list, acb, chain);
    209 	}
    210 	splx(s);
    211 
    212 	if (acb == NULL) {
    213 		xs->error = XS_DRIVER_STUFFUP;
    214 		return(TRY_AGAIN_LATER);
    215 	}
    216 
    217 	acb->flags = ACB_ACTIVE;
    218 	acb->xs = xs;
    219 	bcopy(xs->cmd, &acb->cmd, xs->cmdlen);
    220 	acb->clen = xs->cmdlen;
    221 	acb->daddr = xs->data;
    222 	acb->dleft = xs->datalen;
    223 
    224 	s = splbio();
    225 	TAILQ_INSERT_TAIL(&sc->ready_list, acb, chain);
    226 
    227 	if (sc->sc_nexus == NULL)
    228 		siop_sched(sc);
    229 
    230 	splx(s);
    231 
    232 	if (flags & SCSI_POLL || siop_no_dma)
    233 		return(siop_poll(sc, acb));
    234 	return(SUCCESSFULLY_QUEUED);
    235 }
    236 
    237 int
    238 siop_poll(sc, acb)
    239 	struct siop_softc *sc;
    240 	struct siop_acb *acb;
    241 {
    242 	siop_regmap_p rp = sc->sc_siopp;
    243 	struct scsi_xfer *xs = acb->xs;
    244 	int i;
    245 	int status;
    246 	u_char istat;
    247 	u_char dstat;
    248 	u_char sstat0;
    249 	int s;
    250 	int to;
    251 
    252 	s = splbio();
    253 	to = xs->timeout / 1000;
    254 	if (sc->nexus_list.tqh_first)
    255 		printf("%s: siop_poll called with disconnected device\n",
    256 		    sc->sc_dev.dv_xname);
    257 	for (;;) {
    258 		/* use cmd_wait values? */
    259 		i = 50000;
    260 		spl0();
    261 		while (((istat = rp->siop_istat) &
    262 		    (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
    263 			if (--i <= 0) {
    264 #ifdef DEBUG
    265 				printf ("waiting: tgt %d cmd %02x sbcl %02x dsp %x (+%x) dcmd %x ds %x timeout %d\n",
    266 				    xs->sc_link->target, acb->cmd.opcode,
    267 				    rp->siop_sbcl, rp->siop_dsp,
    268 				    rp->siop_dsp - sc->sc_scriptspa,
    269 				    *((long *)&rp->siop_dcmd), &acb->ds, acb->xs->timeout);
    270 #endif
    271 				i = 50000;
    272 				--to;
    273 				if (to <= 0) {
    274 					siopreset(sc);
    275 					return(COMPLETE);
    276 				}
    277 			}
    278 			delay(10);
    279 		}
    280 		sstat0 = rp->siop_sstat0;
    281 		dstat = rp->siop_dstat;
    282 		if (siop_checkintr(sc, istat, dstat, sstat0, &status)) {
    283 			if (acb != sc->sc_nexus)
    284 				printf("%s: siop_poll disconnected device completed\n",
    285 				    sc->sc_dev.dv_xname);
    286 			else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
    287 				sc->sc_flags &= ~SIOP_INTSOFF;
    288 				rp->siop_sien = sc->sc_sien;
    289 				rp->siop_dien = sc->sc_dien;
    290 			}
    291 			siop_scsidone(sc->sc_nexus, status);
    292 		}
    293 		if (xs->flags & ITSDONE)
    294 			break;
    295 	}
    296 	splx(s);
    297 	return (COMPLETE);
    298 }
    299 
    300 /*
    301  * start next command that's ready
    302  */
    303 void
    304 siop_sched(sc)
    305 	struct siop_softc *sc;
    306 {
    307 	struct scsi_link *slp;
    308 	struct siop_acb *acb;
    309 	int stat, i;
    310 
    311 #ifdef DEBUG
    312 	if (sc->sc_nexus) {
    313 		printf("%s: siop_sched- nexus %x/%d ready %x/%d\n",
    314 		    sc->sc_dev.dv_xname, sc->sc_nexus,
    315 		    sc->sc_nexus->xs->sc_link->target,
    316 		    sc->ready_list.tqh_first,
    317 		    sc->ready_list.tqh_first->xs->sc_link->target);
    318 		return;
    319 	}
    320 #endif
    321 	for (acb = sc->ready_list.tqh_first; acb; acb = acb->chain.tqe_next) {
    322 		slp = acb->xs->sc_link;
    323 		i = slp->target;
    324 		if(!(sc->sc_tinfo[i].lubusy & (1 << slp->lun))) {
    325 			struct siop_tinfo *ti = &sc->sc_tinfo[i];
    326 
    327 			TAILQ_REMOVE(&sc->ready_list, acb, chain);
    328 			sc->sc_nexus = acb;
    329 			slp = acb->xs->sc_link;
    330 			ti = &sc->sc_tinfo[slp->target];
    331 			ti->lubusy |= (1 << slp->lun);
    332 			break;
    333 		}
    334 	}
    335 
    336 	if (acb == NULL) {
    337 #ifdef DEBUGXXX
    338 		printf("%s: siop_sched didn't find ready command\n",
    339 		    sc->sc_dev.dv_xname);
    340 #endif
    341 		return;
    342 	}
    343 
    344 	if (acb->xs->flags & SCSI_RESET)
    345 		siopreset(sc);
    346 
    347 #if 0
    348 	acb->cmd.bytes[0] |= slp->lun << 5;	/* XXXX */
    349 #endif
    350 	++sc->sc_active;
    351 	siop_select(sc);
    352 }
    353 
    354 void
    355 siop_scsidone(acb, stat)
    356 	struct siop_acb *acb;
    357 	int stat;
    358 {
    359 	struct scsi_xfer *xs = acb->xs;
    360 	struct scsi_link *slp = xs->sc_link;
    361 	struct siop_softc *sc = slp->adapter_softc;
    362 	int s, dosched = 0;
    363 
    364 #ifdef DIAGNOSTIC
    365 	if (acb == NULL || xs == NULL)
    366 		panic("siop_scsidone");
    367 #endif
    368 	/*
    369 	 * XXX Support old-style instrumentation for now.
    370 	 * IS THIS REALLY THE RIGHT PLACE FOR THIS?  --thorpej
    371 	 */
    372 	if (slp->device_softc &&
    373 	    ((struct device *)(slp->device_softc))->dv_unit < dk_ndrive)
    374 		++dk_xfer[((struct device *)(slp->device_softc))->dv_unit];
    375 	/*
    376 	 * is this right?
    377 	 */
    378 	xs->status = stat;
    379 
    380 	if (xs->error == XS_NOERROR && !(acb->flags & ACB_CHKSENSE)) {
    381 		if (stat == SCSI_CHECK) {
    382 			struct scsi_sense *ss = (void *)&acb->cmd;
    383 			bzero(ss, sizeof(*ss));
    384 			ss->opcode = REQUEST_SENSE;
    385 			ss->byte2 = slp->lun << 5;
    386 			ss->length = sizeof(struct scsi_sense_data);
    387 			acb->clen = sizeof(*ss);
    388 			acb->daddr = (char *)&xs->sense;
    389 			acb->dleft = sizeof(struct scsi_sense_data);
    390 			acb->flags = ACB_ACTIVE | ACB_CHKSENSE;
    391 			TAILQ_INSERT_HEAD(&sc->ready_list, acb, chain);
    392 			--sc->sc_active;
    393 			sc->sc_tinfo[slp->target].lubusy &=
    394 			    ~(1 << slp->lun);
    395 			sc->sc_tinfo[slp->target].senses++;
    396 			if (sc->sc_nexus == acb) {
    397 				sc->sc_nexus = NULL;
    398 				siop_sched(sc);
    399 			}
    400 			SIOP_TRACE('d','s',0,0)
    401 			return;
    402 		}
    403 	}
    404 	if (xs->error == XS_NOERROR && (acb->flags & ACB_CHKSENSE)) {
    405 		xs->error = XS_SENSE;
    406 	} else {
    407 		xs->resid = 0;		/* XXXX */
    408 	}
    409 #if whataboutthisone
    410 		case SCSI_BUSY:
    411 			xs->error = XS_BUSY;
    412 			break;
    413 #endif
    414 	xs->flags |= ITSDONE;
    415 
    416 	/*
    417 	 * Remove the ACB from whatever queue it's on.  We have to do a bit of
    418 	 * a hack to figure out which queue it's on.  Note that it is *not*
    419 	 * necessary to cdr down the ready queue, but we must cdr down the
    420 	 * nexus queue and see if it's there, so we can mark the unit as no
    421 	 * longer busy.  This code is sickening, but it works.
    422 	 */
    423 	if (acb == sc->sc_nexus) {
    424 		sc->sc_nexus = NULL;
    425 		sc->sc_tinfo[slp->target].lubusy &= ~(1<<slp->lun);
    426 		if (sc->ready_list.tqh_first)
    427 			dosched = 1;	/* start next command */
    428 		--sc->sc_active;
    429 		SIOP_TRACE('d','a',stat,0)
    430 	} else if (sc->ready_list.tqh_last == &acb->chain.tqe_next) {
    431 		TAILQ_REMOVE(&sc->ready_list, acb, chain);
    432 		SIOP_TRACE('d','r',stat,0)
    433 	} else {
    434 		register struct siop_acb *acb2;
    435 		for (acb2 = sc->nexus_list.tqh_first; acb2;
    436 		    acb2 = acb2->chain.tqe_next)
    437 			if (acb2 == acb) {
    438 				TAILQ_REMOVE(&sc->nexus_list, acb, chain);
    439 				sc->sc_tinfo[slp->target].lubusy
    440 					&= ~(1<<slp->lun);
    441 				--sc->sc_active;
    442 				break;
    443 			}
    444 		if (acb2)
    445 			;
    446 		else if (acb->chain.tqe_next) {
    447 			TAILQ_REMOVE(&sc->ready_list, acb, chain);
    448 			--sc->sc_active;
    449 		} else {
    450 			printf("%s: can't find matching acb\n",
    451 			    sc->sc_dev.dv_xname);
    452 #ifdef DDB
    453 /*			Debugger(); */
    454 #endif
    455 		}
    456 		SIOP_TRACE('d','n',stat,0);
    457 	}
    458 	/* Put it on the free list. */
    459 	acb->flags = ACB_FREE;
    460 	TAILQ_INSERT_HEAD(&sc->free_list, acb, chain);
    461 
    462 	sc->sc_tinfo[slp->target].cmds++;
    463 
    464 	scsi_done(xs);
    465 
    466 	if (dosched && sc->sc_nexus == NULL)
    467 		siop_sched(sc);
    468 }
    469 
    470 void
    471 siopabort(sc, rp, where)
    472 	register struct siop_softc *sc;
    473 	siop_regmap_p rp;
    474 	char *where;
    475 {
    476 	int i;
    477 
    478 	printf ("%s: abort %s: dstat %02x, sstat0 %02x sbcl %02x\n",
    479 	    sc->sc_dev.dv_xname,
    480 	    where, rp->siop_dstat, rp->siop_sstat0, rp->siop_sbcl);
    481 
    482 	if (sc->sc_active > 0) {
    483 #ifdef TODO
    484       SET_SBIC_cmd (rp, SBIC_CMD_ABORT);
    485       WAIT_CIP (rp);
    486 
    487       GET_SBIC_asr (rp, asr);
    488       if (asr & (SBIC_ASR_BSY|SBIC_ASR_LCI))
    489         {
    490           /* ok, get more drastic.. */
    491 
    492 	  SET_SBIC_cmd (rp, SBIC_CMD_RESET);
    493 	  delay(25);
    494 	  SBIC_WAIT(rp, SBIC_ASR_INT, 0);
    495 	  GET_SBIC_csr (rp, csr);       /* clears interrupt also */
    496 
    497           return;
    498         }
    499 
    500       do
    501         {
    502           SBIC_WAIT (rp, SBIC_ASR_INT, 0);
    503           GET_SBIC_csr (rp, csr);
    504         }
    505       while ((csr != SBIC_CSR_DISC) && (csr != SBIC_CSR_DISC_1)
    506 	      && (csr != SBIC_CSR_CMD_INVALID));
    507 #endif
    508 
    509 		/* lets just hope it worked.. */
    510 #ifdef fix_this
    511 		for (i = 0; i < 2; ++i) {
    512 			if (sc->sc_iob[i].sc_xs && &sc->sc_iob[i] !=
    513 			    sc->sc_cur) {
    514 				printf ("siopabort: cleanup!\n");
    515 				sc->sc_iob[i].sc_xs = NULL;
    516 			}
    517 		}
    518 #endif	/* fix_this */
    519 /*		sc->sc_active = 0; */
    520 	}
    521 }
    522 
    523 void
    524 siopinitialize(sc)
    525 	struct siop_softc *sc;
    526 {
    527 	int i;
    528 	u_int inhibit_sync;
    529 	extern u_long scsi_nosync;
    530 	extern int shift_nosync;
    531 
    532 	/*
    533 	 * Need to check that scripts is on a long word boundary
    534 	 * and that DS is on a long word boundary.
    535 	 * Also should verify that dev doesn't span non-contiguous
    536 	 * physical pages.
    537 	 */
    538 	sc->sc_scriptspa = kvtop(scripts);
    539 	sc->sc_tcp[1] = 1000 / sc->sc_clock_freq;
    540 	sc->sc_tcp[2] = 1500 / sc->sc_clock_freq;
    541 	sc->sc_tcp[3] = 2000 / sc->sc_clock_freq;
    542 	sc->sc_minsync = sc->sc_tcp[1];		/* in 4ns units */
    543 	if (sc->sc_minsync < 25)
    544 		sc->sc_minsync = 25;
    545 	if (sc->sc_clock_freq <= 25) {
    546 		sc->sc_dcntl = 0x80;		/* SCLK/1 */
    547 		sc->sc_tcp[0] = sc->sc_tcp[1];
    548 	} else if (sc->sc_clock_freq <= 37) {
    549 		sc->sc_dcntl = 0x40;		/* SCLK/1.5 */
    550 		sc->sc_tcp[0] = sc->sc_tcp[2];
    551 	} else if (sc->sc_clock_freq <= 50) {
    552 		sc->sc_dcntl = 0x00;		/* SCLK/2 */
    553 		sc->sc_tcp[0] = sc->sc_tcp[3];
    554 	} else {
    555 		sc->sc_dcntl = 0xc0;		/* SCLK/3 */
    556 		sc->sc_tcp[0] = 3000 / sc->sc_clock_freq;
    557 	}
    558 
    559 	if (scsi_nosync) {
    560 		inhibit_sync = (scsi_nosync >> shift_nosync) & 0xff;
    561 		shift_nosync += 8;
    562 #ifdef DEBUG
    563 		if (inhibit_sync)
    564 			printf("%s: Inhibiting synchronous transfer %02x\n",
    565 				sc->sc_dev.dv_xname, inhibit_sync);
    566 #endif
    567 		for (i = 0; i < 8; ++i)
    568 			if (inhibit_sync & (1 << i))
    569 				siop_inhibit_sync[i] = 1;
    570 	}
    571 
    572 	siopreset (sc);
    573 }
    574 
    575 void
    576 siopreset(sc)
    577 	struct siop_softc *sc;
    578 {
    579 	siop_regmap_p rp;
    580 	u_int i, s;
    581 	u_char  dummy;
    582 	struct siop_acb *acb;
    583 
    584 	rp = sc->sc_siopp;
    585 
    586 	if (sc->sc_flags & SIOP_ALIVE)
    587 		siopabort(sc, rp, "reset");
    588 
    589 	printf("%s: ", sc->sc_dev.dv_xname);		/* XXXX */
    590 
    591 	s = splbio();
    592 
    593 	/*
    594 	 * Reset the chip
    595 	 * XXX - is this really needed?
    596 	 */
    597 	rp->siop_istat |= SIOP_ISTAT_ABRT;	/* abort current script */
    598 	rp->siop_istat |= SIOP_ISTAT_RST;		/* reset chip */
    599 	rp->siop_istat &= ~SIOP_ISTAT_RST;
    600 	/*
    601 	 * Reset SCSI bus (do we really want this?)
    602 	 */
    603 	rp->siop_sien = 0;
    604 	rp->siop_scntl1 |= SIOP_SCNTL1_RST;
    605 	delay(1);
    606 	rp->siop_scntl1 &= ~SIOP_SCNTL1_RST;
    607 
    608 	/*
    609 	 * Set up various chip parameters
    610 	 */
    611 	rp->siop_scntl0 = SIOP_ARB_FULL | SIOP_SCNTL0_EPC | SIOP_SCNTL0_EPG;
    612 	rp->siop_scntl1 = SIOP_SCNTL1_ESR;
    613 	rp->siop_dcntl = sc->sc_dcntl;
    614 	rp->siop_dmode = 0x80;	/* burst length = 4 */
    615 	rp->siop_sien = 0x00;	/* don't enable interrupts yet */
    616 	rp->siop_dien = 0x00;	/* don't enable interrupts yet */
    617 	rp->siop_scid = 1 << sc->sc_link.adapter_target;
    618 	rp->siop_dwt = 0x00;
    619 	rp->siop_ctest0 |= SIOP_CTEST0_BTD | SIOP_CTEST0_EAN;
    620 	rp->siop_ctest7 |= sc->sc_ctest7;
    621 
    622 	/* will need to re-negotiate sync xfers */
    623 	bzero(&sc->sc_sync, sizeof (sc->sc_sync));
    624 
    625 	i = rp->siop_istat;
    626 	if (i & SIOP_ISTAT_SIP)
    627 		dummy = rp->siop_sstat0;
    628 	if (i & SIOP_ISTAT_DIP)
    629 		dummy = rp->siop_dstat;
    630 
    631 	splx (s);
    632 
    633 	delay (siop_reset_delay * 1000);
    634 	printf("siop id %d reset V%d\n", sc->sc_link.adapter_target,
    635 	    rp->siop_ctest8 >> 4);
    636 
    637 	if ((sc->sc_flags & SIOP_ALIVE) == 0) {
    638 		TAILQ_INIT(&sc->ready_list);
    639 		TAILQ_INIT(&sc->nexus_list);
    640 		TAILQ_INIT(&sc->free_list);
    641 		sc->sc_nexus = NULL;
    642 		acb = sc->sc_acb;
    643 		bzero(acb, sizeof(sc->sc_acb));
    644 		for (i = 0; i < sizeof(sc->sc_acb) / sizeof(*acb); i++) {
    645 			TAILQ_INSERT_TAIL(&sc->free_list, acb, chain);
    646 			acb++;
    647 		}
    648 		bzero(sc->sc_tinfo, sizeof(sc->sc_tinfo));
    649 	} else {
    650 		if (sc->sc_nexus != NULL) {
    651 			sc->sc_nexus->xs->error = XS_DRIVER_STUFFUP;
    652 			siop_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
    653 		}
    654 		while (acb = sc->nexus_list.tqh_first) {
    655 			acb->xs->error = XS_DRIVER_STUFFUP;
    656 			siop_scsidone(acb, acb->stat[0]);
    657 		}
    658 	}
    659 
    660 	sc->sc_flags |= SIOP_ALIVE;
    661 	sc->sc_flags &= ~(SIOP_INTDEFER|SIOP_INTSOFF);
    662 	/* enable SCSI and DMA interrupts */
    663 	sc->sc_sien = SIOP_SIEN_M_A | SIOP_SIEN_STO | /*SIOP_SIEN_SEL |*/ SIOP_SIEN_SGE |
    664 	    SIOP_SIEN_UDC | SIOP_SIEN_RST | SIOP_SIEN_PAR;
    665 	sc->sc_dien = SIOP_DIEN_BF | SIOP_DIEN_ABRT | SIOP_DIEN_SIR |
    666 	    /*SIOP_DIEN_WTD |*/ SIOP_DIEN_IID;
    667 	rp->siop_sien = sc->sc_sien;
    668 	rp->siop_dien = sc->sc_dien;
    669 }
    670 
    671 /*
    672  * Setup Data Storage for 53C710 and start SCRIPTS processing
    673  */
    674 
    675 void
    676 siop_start (sc, target, lun, cbuf, clen, buf, len)
    677 	struct siop_softc *sc;
    678 	int target;
    679 	int lun;
    680 	u_char *cbuf;
    681 	int clen;
    682 	u_char *buf;
    683 	int len;
    684 {
    685 	siop_regmap_p rp = sc->sc_siopp;
    686 	int i;
    687 	int nchain;
    688 	int count, tcount;
    689 	char *addr, *dmaend;
    690 	struct siop_acb *acb = sc->sc_nexus;
    691 
    692 #ifdef DEBUG
    693 	if (siop_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
    694 		printf ("ACK! siop was busy: rp %x script %x dsa %x active %d\n",
    695 		    rp, &scripts, &acb->ds, sc->sc_active);
    696 		printf ("istat %02x sfbr %02x lcrc %02x sien %02x dien %02x\n",
    697 		    rp->siop_istat, rp->siop_sfbr, rp->siop_lcrc,
    698 		    rp->siop_sien, rp->siop_dien);
    699 #ifdef DDB
    700 		/*Debugger();*/
    701 #endif
    702 	}
    703 #endif
    704 	acb->msgout[0] = MSG_IDENTIFY | lun;
    705 	if (siop_allow_disc[target] & 2 ||
    706 	    (siop_allow_disc[target] && len == 0))
    707 		acb->msgout[0] = MSG_IDENTIFY_DR | lun;
    708 	acb->status = 0;
    709 	acb->stat[0] = -1;
    710 	acb->msg[0] = -1;
    711 	acb->ds.scsi_addr = (0x10000 << target) | (sc->sc_sync[target].sxfer << 8);
    712 	acb->ds.idlen = 1;
    713 	acb->ds.idbuf = (char *) kvtop(&acb->msgout[0]);
    714 	acb->ds.cmdlen = clen;
    715 	acb->ds.cmdbuf = (char *) kvtop(cbuf);
    716 	acb->ds.stslen = 1;
    717 	acb->ds.stsbuf = (char *) kvtop(&acb->stat[0]);
    718 	acb->ds.msglen = 1;
    719 	acb->ds.msgbuf = (char *) kvtop(&acb->msg[0]);
    720 	acb->msg[1] = -1;
    721 	acb->ds.msginlen = 1;
    722 	acb->ds.extmsglen = 1;
    723 	acb->ds.synmsglen = 3;
    724 	acb->ds.msginbuf = (char *) kvtop(&acb->msg[1]);
    725 	acb->ds.extmsgbuf = (char *) kvtop(&acb->msg[2]);
    726 	acb->ds.synmsgbuf = (char *) kvtop(&acb->msg[3]);
    727 	bzero(&acb->ds.chain, sizeof (acb->ds.chain));
    728 
    729 	if (sc->sc_sync[target].state == SYNC_START) {
    730 		if (siop_inhibit_sync[target]) {
    731 			sc->sc_sync[target].state = SYNC_DONE;
    732 			sc->sc_sync[target].sbcl = 0;
    733 			sc->sc_sync[target].sxfer = 0;
    734 #ifdef DEBUG
    735 			if (siopsync_debug)
    736 				printf ("Forcing target %d asynchronous\n", target);
    737 #endif
    738 		}
    739 		else {
    740 			acb->msg[2] = -1;
    741 			acb->msgout[1] = MSG_EXT_MESSAGE;
    742 			acb->msgout[2] = 3;
    743 			acb->msgout[3] = MSG_SYNC_REQ;
    744 #ifdef MAXTOR_SYNC_KLUDGE
    745 			acb->msgout[4] = 50 / 4;	/* ask for ridiculous period */
    746 #else
    747 			acb->msgout[4] = sc->sc_minsync;
    748 #endif
    749 			acb->msgout[5] = SIOP_MAX_OFFSET;
    750 			acb->ds.idlen = 6;
    751 			sc->sc_sync[target].state = SYNC_SENT;
    752 #ifdef DEBUG
    753 			if (siopsync_debug)
    754 				printf ("Sending sync request to target %d\n", target);
    755 #endif
    756 		}
    757 	}
    758 
    759 /*
    760  * Build physical DMA addresses for scatter/gather I/O
    761  */
    762 	acb->iob_buf = buf;
    763 	acb->iob_len = len;
    764 	acb->iob_curbuf = acb->iob_curlen = 0;
    765 	nchain = 0;
    766 	count = len;
    767 	addr = buf;
    768 	dmaend = NULL;
    769 	while (count > 0) {
    770 		acb->ds.chain[nchain].databuf = (char *) kvtop (addr);
    771 		if (count < (tcount = NBPG - ((int) addr & PGOFSET)))
    772 			tcount = count;
    773 		acb->ds.chain[nchain].datalen = tcount;
    774 		addr += tcount;
    775 		count -= tcount;
    776 		if (acb->ds.chain[nchain].databuf == dmaend) {
    777 			dmaend += acb->ds.chain[nchain].datalen;
    778 			acb->ds.chain[nchain].datalen = 0;
    779 			acb->ds.chain[--nchain].datalen += tcount;
    780 #ifdef DEBUG
    781 			++siopdma_hits;
    782 #endif
    783 		}
    784 		else {
    785 			dmaend = acb->ds.chain[nchain].databuf +
    786 			    acb->ds.chain[nchain].datalen;
    787 			acb->ds.chain[nchain].datalen = tcount;
    788 #ifdef DEBUG
    789 			if (nchain)	/* Don't count miss on first one */
    790 				++siopdma_misses;
    791 #endif
    792 		}
    793 		++nchain;
    794 	}
    795 #ifdef DEBUG
    796 	if (nchain != 1 && len != 0 && siop_debug & 3) {
    797 		printf ("DMA chaining set: %d\n", nchain);
    798 		for (i = 0; i < nchain; ++i) {
    799 			printf ("  [%d] %8x %4x\n", i, acb->ds.chain[i].databuf,
    800 			    acb->ds.chain[i].datalen);
    801 		}
    802 	}
    803 #endif
    804 
    805 	/* push data cache for all data the 53c710 needs to access */
    806 	dma_cachectl (sc, sizeof (struct siop_softc));
    807 	dma_cachectl (cbuf, clen);
    808 	if (buf != NULL && len != 0)
    809 		dma_cachectl (buf, len);
    810 #ifdef DEBUG
    811 	if (siop_debug & 0x100 && rp->siop_sbcl & SIOP_BSY) {
    812 		printf ("ACK! siop was busy at start: rp %x script %x dsa %x active %d\n",
    813 		    rp, &scripts, &acb->ds, sc->sc_active);
    814 #ifdef DDB
    815 		/*Debugger();*/
    816 #endif
    817 	}
    818 #endif
    819 	if (sc->nexus_list.tqh_first == NULL) {
    820 		if (rp->siop_istat & SIOP_ISTAT_CON)
    821 			printf("%s: siop_select while connected?\n",
    822 			    sc->sc_dev.dv_xname);
    823 		rp->siop_temp = 0;
    824 		rp->siop_sbcl = sc->sc_sync[target].sbcl;
    825 		rp->siop_dsa = kvtop(&acb->ds);
    826 		rp->siop_dsp = sc->sc_scriptspa;
    827 		SIOP_TRACE('s',1,0,0)
    828 	} else {
    829 		if ((rp->siop_istat & SIOP_ISTAT_CON) == 0) {
    830 			rp->siop_istat = SIOP_ISTAT_SIGP;
    831 			SIOP_TRACE('s',2,0,0);
    832 		}
    833 		else {
    834 			SIOP_TRACE('s',3,rp->siop_istat,0);
    835 		}
    836 	}
    837 #ifdef DEBUG
    838 	++siopstarts;
    839 #endif
    840 }
    841 
    842 /*
    843  * Process a DMA or SCSI interrupt from the 53C710 SIOP
    844  */
    845 
    846 int
    847 siop_checkintr(sc, istat, dstat, sstat0, status)
    848 	struct	siop_softc *sc;
    849 	u_char	istat;
    850 	u_char	dstat;
    851 	u_char	sstat0;
    852 	int	*status;
    853 {
    854 	siop_regmap_p rp = sc->sc_siopp;
    855 	struct siop_acb *acb = sc->sc_nexus;
    856 	int	target;
    857 	int	dfifo, dbc, sstat1;
    858 
    859 	dfifo = rp->siop_dfifo;
    860 	dbc = rp->siop_dbc0;
    861 	sstat1 = rp->siop_sstat1;
    862 	rp->siop_ctest8 |= SIOP_CTEST8_CLF;
    863 	while ((rp->siop_ctest1 & SIOP_CTEST1_FMT) != SIOP_CTEST1_FMT)
    864 		;
    865 	rp->siop_ctest8 &= ~SIOP_CTEST8_CLF;
    866 #ifdef DEBUG
    867 	++siopints;
    868 #if 0
    869 	if (siop_debug & 0x100) {
    870 		DCIAS(&acb->stat[0]);	/* XXX */
    871 		printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
    872 		    istat, dstat, sstat0, rp->siop_dsps, rp->siop_sbcl, acb->stat[0], acb->msg[0]);
    873 		printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
    874 		    acb->msg[0], acb->msg[1], acb->msg[2],
    875 		    acb->msg[3], acb->msg[4], acb->msg[5]);
    876 	}
    877 #endif
    878 	if (rp->siop_dsp && (rp->siop_dsp < sc->sc_scriptspa ||
    879 	    rp->siop_dsp >= sc->sc_scriptspa + sizeof(scripts))) {
    880 		printf ("%s: dsp not within script dsp %x scripts %x:%x",
    881 		    sc->sc_dev.dv_xname, rp->siop_dsp, sc->sc_scriptspa,
    882 		    sc->sc_scriptspa + sizeof(scripts));
    883 		printf(" istat %x dstat %x sstat0 %x\n",
    884 		    istat, dstat, sstat0);
    885 		Debugger();
    886 	}
    887 #endif
    888 	SIOP_TRACE('i',dstat,istat,(istat&SIOP_ISTAT_DIP)?rp->siop_dsps&0xff:sstat0);
    889 	if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff00) {
    890 		/* Normal completion status, or check condition */
    891 #ifdef DEBUG
    892 		if (rp->siop_dsa != kvtop(&acb->ds)) {
    893 			printf ("siop: invalid dsa: %x %x\n", rp->siop_dsa,
    894 			    kvtop(&acb->ds));
    895 			panic("*** siop DSA invalid ***");
    896 		}
    897 #endif
    898 		target = acb->xs->sc_link->target;
    899 		if (sc->sc_sync[target].state == SYNC_SENT) {
    900 #ifdef DEBUG
    901 			if (siopsync_debug)
    902 				printf ("sync msg in: %02x %02x %02x %02x %02x %02x\n",
    903 				    acb->msg[0], acb->msg[1], acb->msg[2],
    904 				    acb->msg[3], acb->msg[4], acb->msg[5]);
    905 #endif
    906 			if (acb->msg[1] == 0xff)
    907 				printf ("%s: target %d ignored sync request\n",
    908 				    sc->sc_dev.dv_xname, target);
    909 			else if (acb->msg[1] == MSG_REJECT)
    910 				printf ("%s: target %d rejected sync request\n",
    911 				    sc->sc_dev.dv_xname, target);
    912 			sc->sc_sync[target].state = SYNC_DONE;
    913 			sc->sc_sync[target].sxfer = 0;
    914 			sc->sc_sync[target].sbcl = 0;
    915 			if (acb->msg[2] == 3 &&
    916 			    acb->msg[3] == MSG_SYNC_REQ &&
    917 			    acb->msg[5] != 0) {
    918 #ifdef MAXTOR_KLUDGE
    919 				/*
    920 				 * Kludge for my Maxtor XT8580S
    921 				 * It accepts whatever we request, even
    922 				 * though it won't work.  So we ask for
    923 				 * a short period than we can handle.  If
    924 				 * the device says it can do it, use 208ns.
    925 				 * If the device says it can do less than
    926 				 * 100ns, then we limit it to 100ns.
    927 				 */
    928 				if (acb->msg[4] && acb->msg[4] < 100 / 4) {
    929 #ifdef DEBUG
    930 					printf ("%d: target %d wanted %dns period\n",
    931 					    sc->sc_dev.dv_xname, target,
    932 					    acb->msg[4] * 4);
    933 #endif
    934 					if (acb->msg[4] == 50 / 4)
    935 						acb->msg[4] = 208 / 4;
    936 					else
    937 						acb->msg[4] = 100 / 4;
    938 				}
    939 #endif /* MAXTOR_KLUDGE */
    940 				printf ("%s: target %d now synchronous, period=%dns, offset=%d\n",
    941 				    sc->sc_dev.dv_xname, target,
    942 				    acb->msg[4] * 4, acb->msg[5]);
    943 				scsi_period_to_siop (sc, target);
    944 			}
    945 		}
    946 		dma_cachectl(&acb->stat[0], 1);
    947 		*status = acb->stat[0];
    948 #ifdef DEBUG
    949 		if (rp->siop_sbcl & SIOP_BSY) {
    950 			/*printf ("ACK! siop was busy at end: rp %x script %x dsa %x\n",
    951 			    rp, &scripts, &acb->ds);*/
    952 #ifdef DDB
    953 			/*Debugger();*/
    954 #endif
    955 		}
    956 		if (acb->msg[0] != 0x00)
    957 			printf("%s: message was not COMMAND COMPLETE: %x\n",
    958 			    sc->sc_dev.dv_xname, acb->msg[0]);
    959 #endif
    960 		if (sc->nexus_list.tqh_first)
    961 			rp->siop_dcntl |= SIOP_DCNTL_STD;
    962 		return 1;
    963 	}
    964 	if (sstat0 & SIOP_SSTAT0_M_A) {		/* Phase mismatch */
    965 #ifdef DEBUG
    966 		++siopphmm;
    967 		if (acb == NULL)
    968 			printf("%s: Phase mismatch with no active command?\n",
    969 			    sc->sc_dev.dv_xname);
    970 #endif
    971 		if (acb->iob_len) {
    972 			int adjust;
    973 			adjust = ((dfifo - (dbc & 0x7f)) & 0x7f);
    974 			if (sstat1 & SIOP_SSTAT1_ORF)
    975 				++adjust;
    976 			if (sstat1 & SIOP_SSTAT1_OLF)
    977 				++adjust;
    978 			acb->iob_curlen = *((long *)&rp->siop_dcmd) & 0xffffff;
    979 			acb->iob_curlen += adjust;
    980 			acb->iob_curbuf = *((long *)&rp->siop_dnad) - adjust;
    981 #ifdef DEBUG
    982 			if (siop_debug & 0x100) {
    983 				int i;
    984 				printf ("Phase mismatch: curbuf %x curlen %x dfifo %x dbc %x sstat1 %x adjust %x sbcl %x starts %d acb %x\n",
    985 				    acb->iob_curbuf, acb->iob_curlen, dfifo,
    986 				    dbc, sstat1, adjust, rp->siop_sbcl, siopstarts, acb);
    987 				if (acb->ds.chain[1].datalen) {
    988 					for (i = 0; acb->ds.chain[i].datalen; ++i)
    989 						printf("chain[%d] addr %x len %x\n",
    990 						    i, acb->ds.chain[i].databuf,
    991 						    acb->ds.chain[i].datalen);
    992 				}
    993 			}
    994 #endif
    995 			dma_cachectl (acb, sizeof(*acb));
    996 		}
    997 #ifdef DEBUG
    998 		SIOP_TRACE('m',rp->siop_sbcl,(rp->siop_dsp>>8),rp->siop_dsp);
    999 		if (siop_debug & 9)
   1000 			printf ("Phase mismatch: %x dsp +%x dcmd %x\n",
   1001 			    rp->siop_sbcl,
   1002 			    rp->siop_dsp - sc->sc_scriptspa,
   1003 			    *((long *)&rp->siop_dcmd));
   1004 #endif
   1005 		if ((rp->siop_sbcl & SIOP_REQ) == 0) {
   1006 			printf ("Phase mismatch: REQ not asserted! %02x dsp %x\n",
   1007 			    rp->siop_sbcl, rp->siop_dsp);
   1008 #ifdef DEBUG
   1009 			Debugger();
   1010 #endif
   1011 		}
   1012 		switch (rp->siop_sbcl & 7) {
   1013 		case 0:		/* data out */
   1014 		case 1:		/* data in */
   1015 		case 2:		/* status */
   1016 		case 3:		/* command */
   1017 		case 6:		/* message in */
   1018 		case 7:		/* message out */
   1019 			rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
   1020 			break;
   1021 		default:
   1022 			goto bad_phase;
   1023 		}
   1024 		return 0;
   1025 	}
   1026 	if (sstat0 & SIOP_SSTAT0_STO) {		/* Select timed out */
   1027 #ifdef DEBUG
   1028 		if (acb == NULL)
   1029 			printf("%s: Select timeout with no active command?\n",
   1030 			    sc->sc_dev.dv_xname);
   1031 		if (rp->siop_sbcl & SIOP_BSY) {
   1032 			printf ("ACK! siop was busy at timeout: rp %x script %x dsa %x\n",
   1033 			    rp, &scripts, &acb->ds);
   1034 			printf(" sbcl %x sdid %x istat %x dstat %x sstat0 %x\n",
   1035 			    rp->siop_sbcl, rp->siop_sdid, istat, dstat, sstat0);
   1036 			if (!(rp->siop_sbcl & SIOP_BSY)) {
   1037 				printf ("Yikes, it's not busy now!\n");
   1038 #if 0
   1039 				*status = -1;
   1040 				if (sc->nexus_list.tqh_first)
   1041 					rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
   1042 				return 1;
   1043 #endif
   1044 			}
   1045 /*			rp->siop_dcntl |= SIOP_DCNTL_STD;*/
   1046 			return (0);
   1047 #ifdef DDB
   1048 			Debugger();
   1049 #endif
   1050 		}
   1051 #endif
   1052 		*status = -1;
   1053 		acb->xs->error = XS_SELTIMEOUT;
   1054 		if (sc->nexus_list.tqh_first)
   1055 			rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
   1056 		return 1;
   1057 	}
   1058 	if (acb)
   1059 		target = acb->xs->sc_link->target;
   1060 	else
   1061 		target = 7;
   1062 	if (sstat0 & SIOP_SSTAT0_UDC) {
   1063 #ifdef DEBUG
   1064 		if (acb == NULL)
   1065 			printf("%s: Unexpected disconnect with no active command?\n",
   1066 			    sc->sc_dev.dv_xname);
   1067 		printf ("%s: target %d disconnected unexpectedly\n",
   1068 		   sc->sc_dev.dv_xname, target);
   1069 #endif
   1070 #if 0
   1071 		siopabort (sc, rp, "siopchkintr");
   1072 #endif
   1073 		*status = STS_BUSY;
   1074 		if (sc->nexus_list.tqh_first)
   1075 			rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
   1076 		return 1;
   1077 	}
   1078 	if (dstat & SIOP_DSTAT_SIR && (rp->siop_dsps == 0xff01 ||
   1079 	    rp->siop_dsps == 0xff02)) {
   1080 #ifdef DEBUG
   1081 		if (siop_debug & 0x100)
   1082 			printf ("%s: ID %02x disconnected TEMP %x (+%x) curbuf %x curlen %x buf %x len %x dfifo %x dbc %x sstat1 %x starts %d acb %x\n",
   1083 			    sc->sc_dev.dv_xname, 1 << target, rp->siop_temp,
   1084 			    rp->siop_temp ? rp->siop_temp - sc->sc_scriptspa : 0,
   1085 			    acb->iob_curbuf, acb->iob_curlen,
   1086 			    acb->ds.chain[0].databuf, acb->ds.chain[0].datalen, dfifo, dbc, sstat1, siopstarts, acb);
   1087 #endif
   1088 		if (acb == NULL) {
   1089 			printf("%s: Disconnect with no active command?\n",
   1090 			    sc->sc_dev.dv_xname);
   1091 			return (0);
   1092 		}
   1093 		/*
   1094 		 * XXXX need to update iob_curbuf/iob_curlen to reflect
   1095 		 * current data transferred.  If device disconnected in
   1096 		 * the middle of a DMA block, they should already be set
   1097 		 * by the phase change interrupt.  If the disconnect
   1098 		 * occurs on a DMA block boundary, we have to figure out
   1099 		 * which DMA block it was.
   1100 		 */
   1101 		if (acb->iob_len && rp->siop_temp) {
   1102 			int n = rp->siop_temp - sc->sc_scriptspa;
   1103 
   1104 			if (acb->iob_curlen && acb->iob_curlen != acb->ds.chain[0].datalen)
   1105 				printf("%s: iob_curbuf/len already set? n %x iob %x/%x chain[0] %x/%x\n",
   1106 				    sc->sc_dev.dv_xname, n, acb->iob_curbuf, acb->iob_curlen,
   1107 				    acb->ds.chain[0].databuf, acb->ds.chain[0].datalen);
   1108 			if (n < Ent_datain)
   1109 				n = (n - Ent_dataout) / 16;
   1110 			else
   1111 				n = (n - Ent_datain) / 16;
   1112 			if (n <= 0 && n > DMAMAXIO)
   1113 				printf("TEMP invalid %d\n", n);
   1114 			else {
   1115 				acb->iob_curbuf = (u_long)acb->ds.chain[n].databuf;
   1116 				acb->iob_curlen = acb->ds.chain[n].datalen;
   1117 			}
   1118 #ifdef DEBUG
   1119 			if (siop_debug & 0x100) {
   1120 				printf("%s: TEMP offset %d", sc->sc_dev.dv_xname, n);
   1121 				printf(" curbuf %x curlen %x\n", acb->iob_curbuf,
   1122 				    acb->iob_curlen);
   1123 			}
   1124 #endif
   1125 		}
   1126 		/*
   1127 		 * If data transfer was interrupted by disconnect, iob_curbuf
   1128 		 * and iob_curlen should reflect the point of interruption.
   1129 		 * Adjust the DMA chain so that the data transfer begins
   1130 		 * at the appropriate place upon reselection.
   1131 		 * XXX This should only be done on save data pointer message?
   1132 		 */
   1133 		if (acb->iob_curlen) {
   1134 			int i, j;
   1135 
   1136 #ifdef DEBUG
   1137 			if (siop_debug & 0x100)
   1138 				printf ("%s: adjusting DMA chain\n",
   1139 				    sc->sc_dev.dv_xname);
   1140 			if (rp->siop_dsps == 0xff02)
   1141 				printf ("%s: ID %02x disconnected without Save Data Pointers\n",
   1142 				    sc->sc_dev.dv_xname, 1 << target);
   1143 #endif
   1144 			for (i = 0; i < DMAMAXIO; ++i) {
   1145 				if (acb->ds.chain[i].datalen == 0)
   1146 					break;
   1147 				if (acb->iob_curbuf >= (long)acb->ds.chain[i].databuf &&
   1148 				    acb->iob_curbuf < (long)(acb->ds.chain[i].databuf +
   1149 				    acb->ds.chain[i].datalen))
   1150 					break;
   1151 			}
   1152 			if (i >= DMAMAXIO || acb->ds.chain[i].datalen == 0)
   1153 				printf("couldn't find saved data pointer\n");
   1154 #ifdef DEBUG
   1155 			if (siop_debug & 0x100)
   1156 				printf("  chain[0]: %x/%x -> %x/%x\n",
   1157 				    acb->ds.chain[0].databuf,
   1158 				    acb->ds.chain[0].datalen,
   1159 				    acb->iob_curbuf,
   1160 				    acb->iob_curlen);
   1161 #endif
   1162 			acb->ds.chain[0].databuf = (char *)acb->iob_curbuf;
   1163 			acb->ds.chain[0].datalen = acb->iob_curlen;
   1164 			for (j = 1, ++i; i < DMAMAXIO && acb->ds.chain[i].datalen; ++i, ++j) {
   1165 #ifdef DEBUG
   1166 			if (siop_debug & 0x100)
   1167 				printf("  chain[%d]: %x/%x -> %x/%x\n", j,
   1168 				    acb->ds.chain[j].databuf,
   1169 				    acb->ds.chain[j].datalen,
   1170 				    acb->ds.chain[i].databuf,
   1171 				    acb->ds.chain[i].datalen);
   1172 #endif
   1173 				acb->ds.chain[j].databuf = acb->ds.chain[i].databuf;
   1174 				acb->ds.chain[j].datalen = acb->ds.chain[i].datalen;
   1175 			}
   1176 			if (j < DMAMAXIO)
   1177 				acb->ds.chain[j].datalen = 0;
   1178 			DCIAS(kvtop(&acb->ds.chain));
   1179 		}
   1180 		++sc->sc_tinfo[target].dconns;
   1181 		/*
   1182 		 * add nexus to waiting list
   1183 		 * clear nexus
   1184 		 * try to start another command for another target/lun
   1185 		 */
   1186 		acb->status = sc->sc_flags & SIOP_INTSOFF;
   1187 		TAILQ_INSERT_HEAD(&sc->nexus_list, acb, chain);
   1188 		sc->sc_nexus = NULL;		/* no current device */
   1189 		/* start script to wait for reselect */
   1190 		if (sc->sc_nexus == NULL)
   1191 			rp->siop_dsp = sc->sc_scriptspa + Ent_wait_reselect;
   1192 /* XXXX start another command ? */
   1193 		if (sc->ready_list.tqh_first)
   1194 			siop_sched(sc);
   1195 		return (0);
   1196 	}
   1197 	if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff03) {
   1198 		int reselid = rp->siop_scratch & 0x7f;
   1199 		int reselun = rp->siop_sfbr & 0x07;
   1200 
   1201 		sc->sc_sstat1 = rp->siop_sbcl;	/* XXXX save current SBCL */
   1202 #ifdef DEBUG
   1203 		if (siop_debug & 0x100)
   1204 			printf ("%s: target ID %02x reselected dsps %x\n",
   1205 			     sc->sc_dev.dv_xname, reselid,
   1206 			     rp->siop_dsps);
   1207 		if ((rp->siop_sfbr & 0x80) == 0)
   1208 			printf("%s: Reselect message in was not identify: %x\n",
   1209 			    sc->sc_dev.dv_xname, rp->siop_sfbr);
   1210 #endif
   1211 		if (sc->sc_nexus) {
   1212 #ifdef DEBUG
   1213 			if (siop_debug & 0x100)
   1214 				printf ("%s: reselect ID %02x w/active\n",
   1215 				    sc->sc_dev.dv_xname, reselid);
   1216 #endif
   1217 			TAILQ_INSERT_HEAD(&sc->ready_list, sc->sc_nexus, chain);
   1218 			sc->sc_tinfo[sc->sc_nexus->xs->sc_link->target].lubusy
   1219 			    &= ~(1 << sc->sc_nexus->xs->sc_link->lun);
   1220 			--sc->sc_active;
   1221 		}
   1222 		/*
   1223 		 * locate acb of reselecting device
   1224 		 * set sc->sc_nexus to acb
   1225 		 */
   1226 		for (acb = sc->nexus_list.tqh_first; acb;
   1227 		    acb = acb->chain.tqe_next) {
   1228 			if (reselid != (acb->ds.scsi_addr >> 16) ||
   1229 			    reselun != (acb->msgout[0] & 0x07))
   1230 				continue;
   1231 			TAILQ_REMOVE(&sc->nexus_list, acb, chain);
   1232 			sc->sc_nexus = acb;
   1233 			sc->sc_flags |= acb->status;
   1234 			acb->status = 0;
   1235 			DCIAS(kvtop(&acb->stat[0]));
   1236 			rp->siop_dsa = kvtop(&acb->ds);
   1237 			rp->siop_sxfer = sc->sc_sync[acb->xs->sc_link->target].sxfer;
   1238 			rp->siop_sbcl = sc->sc_sync[acb->xs->sc_link->target].sbcl;
   1239 			break;
   1240 		}
   1241 		if (acb == NULL) {
   1242 			printf("%s: target ID %02x reselect nexus_list %x\n",
   1243 			    sc->sc_dev.dv_xname, reselid,
   1244 			    sc->nexus_list.tqh_first);
   1245 			panic("unable to find reselecting device");
   1246 		}
   1247 		dma_cachectl (acb, sizeof(*acb));
   1248 		rp->siop_temp = 0;
   1249 		rp->siop_dcntl |= SIOP_DCNTL_STD;
   1250 		return (0);
   1251 	}
   1252 	if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff04) {
   1253 		u_short ctest2 = rp->siop_ctest2;
   1254 
   1255 		/* reselect was interrupted (by Sig_P or select) */
   1256 #ifdef DEBUG
   1257 		if (siop_debug & 0x100 ||
   1258 		    (ctest2 & SIOP_CTEST2_SIGP) == 0)
   1259 			printf ("%s: reselect interrupted (Sig_P?) scntl1 %x ctest2 %x sfbr %x istat %x/%x\n",
   1260 			    sc->sc_dev.dv_xname, rp->siop_scntl1,
   1261 			    ctest2, rp->siop_sfbr, istat, rp->siop_istat);
   1262 #endif
   1263 		/* XXX assumes it was not select */
   1264 		if (sc->sc_nexus == NULL) {
   1265 			printf("%s: reselect interrupted, sc_nexus == NULL\n",
   1266 			    sc->sc_dev.dv_xname);
   1267 #if 0
   1268 			siop_dump(sc);
   1269 #ifdef DDB
   1270 			Debugger();
   1271 #endif
   1272 #endif
   1273 			rp->siop_dcntl |= SIOP_DCNTL_STD;
   1274 			return(0);
   1275 		}
   1276 		target = sc->sc_nexus->xs->sc_link->target;
   1277 		rp->siop_temp = 0;
   1278 		rp->siop_dsa = kvtop(&sc->sc_nexus->ds);
   1279 		rp->siop_sxfer = sc->sc_sync[target].sxfer;
   1280 		rp->siop_sbcl = sc->sc_sync[target].sbcl;
   1281 		rp->siop_dsp = sc->sc_scriptspa;
   1282 		return (0);
   1283 	}
   1284 	if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff06) {
   1285 		if (acb == NULL)
   1286 			printf("%s: Bad message-in with no active command?\n",
   1287 			    sc->sc_dev.dv_xname);
   1288 		/* Unrecognized message in byte */
   1289 		dma_cachectl (&acb->msg[1],1);
   1290 		printf ("%s: Unrecognized message in data sfbr %x msg %x sbcl %x\n",
   1291 			sc->sc_dev.dv_xname, rp->siop_sfbr, acb->msg[1], rp->siop_sbcl);
   1292 		/* what should be done here? */
   1293 		DCIAS(kvtop(&acb->msg[1]));
   1294 		rp->siop_dsp = sc->sc_scriptspa + Ent_switch;
   1295 		return (0);
   1296 	}
   1297 	if (dstat & SIOP_DSTAT_SIR && rp->siop_dsps == 0xff0a) {
   1298 		/* Status phase wasn't followed by message in phase? */
   1299 		printf ("%s: Status phase not followed by message in phase? sbcl %x sbdl %x\n",
   1300 			sc->sc_dev.dv_xname, rp->siop_sbcl, rp->siop_sbdl);
   1301 		if (rp->siop_sbcl == 0xa7) {
   1302 			/* It is now, just continue the script? */
   1303 			rp->siop_dcntl |= SIOP_DCNTL_STD;
   1304 			return (0);
   1305 		}
   1306 	}
   1307 	if (sstat0 == 0 && dstat & SIOP_DSTAT_SIR) {
   1308 		dma_cachectl (&acb->stat[0], 1);
   1309 		dma_cachectl (&acb->msg[0], 1);
   1310 		printf ("SIOP interrupt: %x sts %x msg %x %x sbcl %x\n",
   1311 		    rp->siop_dsps, acb->stat[0], acb->msg[0], acb->msg[1],
   1312 		    rp->siop_sbcl);
   1313 		siopreset (sc);
   1314 		*status = -1;
   1315 		return 0;	/* siopreset has cleaned up */
   1316 	}
   1317 	if (sstat0 & SIOP_SSTAT0_SGE)
   1318 		printf ("SIOP: SCSI Gross Error\n");
   1319 	if (sstat0 & SIOP_SSTAT0_PAR)
   1320 		printf ("SIOP: Parity Error\n");
   1321 	if (dstat & SIOP_DSTAT_IID)
   1322 		printf ("SIOP: Invalid instruction detected\n");
   1323 bad_phase:
   1324 	/*
   1325 	 * temporary panic for unhandled conditions
   1326 	 * displays various things about the 53C710 status and registers
   1327 	 * then panics.
   1328 	 * XXXX need to clean this up to print out the info, reset, and continue
   1329 	 */
   1330 	printf ("siopchkintr: target %x ds %x\n", target, &acb->ds);
   1331 	printf ("scripts %x ds %x rp %x dsp %x dcmd %x\n", sc->sc_scriptspa,
   1332 	    kvtop(&acb->ds), kvtop(rp), rp->siop_dsp,
   1333 	    *((long *)&rp->siop_dcmd));
   1334 	printf ("siopchkintr: istat %x dstat %x sstat0 %x dsps %x dsa %x sbcl %x sts %x msg %x %x sfbr %x\n",
   1335 	    istat, dstat, sstat0, rp->siop_dsps, rp->siop_dsa,
   1336 	     rp->siop_sbcl, acb->stat[0], acb->msg[0], acb->msg[1], rp->siop_sfbr);
   1337 #ifdef DEBUG
   1338 	if (siop_debug & 0x20)
   1339 		panic("siopchkintr: **** temp ****");
   1340 #endif
   1341 #ifdef DDB
   1342 	Debugger ();
   1343 #endif
   1344 	siopreset (sc);		/* hard reset */
   1345 	*status = -1;
   1346 	return 0;		/* siopreset cleaned up */
   1347 }
   1348 
   1349 void
   1350 siop_select(sc)
   1351 	struct siop_softc *sc;
   1352 {
   1353 	siop_regmap_p rp;
   1354 	struct siop_acb *acb = sc->sc_nexus;
   1355 
   1356 #ifdef DEBUG
   1357 	if (siop_debug & 1)
   1358 		printf ("%s: select ", sc->sc_dev.dv_xname);
   1359 #endif
   1360 
   1361 	rp = sc->sc_siopp;
   1362 	if (acb->xs->flags & SCSI_POLL || siop_no_dma) {
   1363 		sc->sc_flags |= SIOP_INTSOFF;
   1364 		sc->sc_flags &= ~SIOP_INTDEFER;
   1365 		if ((rp->siop_istat & 0x08) == 0) {
   1366 			rp->siop_sien = 0;
   1367 			rp->siop_dien = 0;
   1368 		}
   1369 #if 0
   1370 	} else if ((sc->sc_flags & SIOP_INTDEFER) == 0) {
   1371 		sc->sc_flags &= ~SIOP_INTSOFF;
   1372 		if ((rp->siop_istat & 0x08) == 0) {
   1373 			rp->siop_sien = sc->sc_sien;
   1374 			rp->siop_dien = sc->sc_dien;
   1375 		}
   1376 #endif
   1377 	}
   1378 #ifdef DEBUG
   1379 	if (siop_debug & 1)
   1380 		printf ("siop_select: target %x cmd %02x ds %x\n",
   1381 		    acb->xs->sc_link->target, acb->cmd.opcode,
   1382 		    &sc->sc_nexus->ds);
   1383 #endif
   1384 
   1385 	siop_start(sc, acb->xs->sc_link->target, acb->xs->sc_link->lun,
   1386 	    &acb->cmd, acb->clen, acb->daddr, acb->dleft);
   1387 
   1388 	return;
   1389 }
   1390 
   1391 /*
   1392  * 53C710 interrupt handler
   1393  */
   1394 
   1395 int
   1396 siopintr (sc)
   1397 	register struct siop_softc *sc;
   1398 {
   1399 	siop_regmap_p rp;
   1400 	register u_char istat, dstat, sstat0;
   1401 	int status;
   1402 	int s = splbio();
   1403 
   1404 	istat = sc->sc_istat;
   1405 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0) {
   1406 		splx(s);
   1407 		return;
   1408 	}
   1409 
   1410 	/* Got a valid interrupt on this device */
   1411 	rp = sc->sc_siopp;
   1412 	dstat = sc->sc_dstat;
   1413 	sstat0 = sc->sc_sstat0;
   1414 	if (dstat & SIOP_DSTAT_SIR)
   1415 		sc->sc_intcode = rp->siop_dsps;
   1416 	sc->sc_istat = 0;
   1417 #ifdef DEBUG
   1418 	if (siop_debug & 1)
   1419 		printf ("%s: intr istat %x dstat %x sstat0 %x\n",
   1420 		    sc->sc_dev.dv_xname, istat, dstat, sstat0);
   1421 	if (!sc->sc_active) {
   1422 		printf ("%s: spurious interrupt? istat %x dstat %x sstat0 %x status %x\n",
   1423 		    sc->sc_dev.dv_xname, istat, dstat, sstat0, sc->sc_nexus->stat[0]);
   1424 	}
   1425 #endif
   1426 
   1427 #ifdef DEBUG
   1428 	if (siop_debug & 5) {
   1429 		DCIAS(kvtop(&sc->sc_nexus->stat[0]));
   1430 		printf ("%s: intr istat %x dstat %x sstat0 %x dsps %x sbcl %x sts %x msg %x\n",
   1431 		    sc->sc_dev.dv_xname, istat, dstat, sstat0,
   1432 		    rp->siop_dsps,  rp->siop_sbcl,
   1433 		    sc->sc_nexus->stat[0], sc->sc_nexus->msg[0]);
   1434 	}
   1435 #endif
   1436 	if (sc->sc_flags & SIOP_INTDEFER) {
   1437 		sc->sc_flags &= ~(SIOP_INTDEFER | SIOP_INTSOFF);
   1438 		rp->siop_sien = sc->sc_sien;
   1439 		rp->siop_dien = sc->sc_dien;
   1440 	}
   1441 	if (siop_checkintr (sc, istat, dstat, sstat0, &status)) {
   1442 #if 1
   1443 		if (status == 0xff)
   1444 			printf ("siopintr: status == 0xff\n");
   1445 #endif
   1446 		if ((sc->sc_flags & (SIOP_INTSOFF | SIOP_INTDEFER)) != SIOP_INTSOFF) {
   1447 #if 0
   1448 			if (rp->siop_sbcl & SIOP_BSY) {
   1449 				printf ("%s: SCSI bus busy at completion",
   1450 					sc->sc_dev.dv_xname);
   1451 				printf(" targ %d sbcl %02x sfbr %x lcrc %02x dsp +%x\n",
   1452 				    sc->sc_nexus->xs->sc_link->target,
   1453 				    rp->siop_sbcl, rp->siop_sfbr, rp->siop_lcrc,
   1454 				    rp->siop_dsp - sc->sc_scriptspa);
   1455 			}
   1456 #endif
   1457 			siop_scsidone(sc->sc_nexus, sc->sc_nexus->stat[0]);
   1458 		}
   1459 	}
   1460 	splx(s);
   1461 }
   1462 
   1463 /*
   1464  * This is based on the Progressive Peripherals 33Mhz Zeus driver and will
   1465  * not be correct for other 53c710 boards.
   1466  *
   1467  */
   1468 scsi_period_to_siop (sc, target)
   1469 	struct siop_softc *sc;
   1470 {
   1471 	int period, offset, i, sxfer, sbcl;
   1472 
   1473 	period = sc->sc_nexus->msg[4];
   1474 	offset = sc->sc_nexus->msg[5];
   1475 #ifdef DEBUG
   1476 	sxfer = 0;
   1477 	if (offset <= SIOP_MAX_OFFSET)
   1478 		sxfer = offset;
   1479 	for (i = 0; i < sizeof (sync_tab) / 2; ++i) {
   1480 		if (period <= sync_tab[i].p) {
   1481 			sxfer |= sync_tab[i].r & 0x70;
   1482 			sbcl = sync_tab[i].r & 0x03;
   1483 			break;
   1484 		}
   1485 	}
   1486 	printf ("siop sync old: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, sbcl);
   1487 #endif
   1488 	for (sbcl = 1; sbcl < 4; ++sbcl) {
   1489 		sxfer = (period * 4 - 1) / sc->sc_tcp[sbcl] - 3;
   1490 		if (sxfer >= 0 && sxfer <= 7)
   1491 			break;
   1492 	}
   1493 	if (sbcl > 3) {
   1494 		printf("siop sync: unable to compute sync params for period %dns\n",
   1495 		    period * 4);
   1496 		/*
   1497 		 * XXX need to pick a value we can do and renegotiate
   1498 		 */
   1499 		sxfer = sbcl = 0;
   1500 	} else {
   1501 		sxfer = (sxfer << 4) | ((offset <= SIOP_MAX_OFFSET) ?
   1502 		    offset : SIOP_MAX_OFFSET);
   1503 		printf("siop sync: params for period %dns: sxfer %x sbcl %x",
   1504 		    period * 4, sxfer, sbcl);
   1505 		printf(" actual period %dns\n",
   1506 		    sc->sc_tcp[sbcl] * ((sxfer >> 4) + 4));
   1507 	}
   1508 	sc->sc_sync[target].sxfer = sxfer;
   1509 	sc->sc_sync[target].sbcl = sbcl;
   1510 #ifdef DEBUG
   1511 	printf ("siop sync: siop_sxfr %02x, siop_sbcl %02x\n", sxfer, sbcl);
   1512 #endif
   1513 }
   1514 
   1515 #ifdef DEBUG
   1516 
   1517 #if SIOP_TRACE_SIZE
   1518 void
   1519 siop_dump_trace()
   1520 {
   1521 	int i;
   1522 
   1523 	printf("siop trace: next index %d\n", siop_trix);
   1524 	i = siop_trix;
   1525 	do {
   1526 		printf("%3d: '%c' %02x %02x %02x\n", i, siop_trbuf[i],
   1527 		    siop_trbuf[i + 1], siop_trbuf[i + 2], siop_trbuf[i + 3]);
   1528 		i = (i + 4) & (SIOP_TRACE_SIZE - 1);
   1529 	} while (i != siop_trix);
   1530 }
   1531 #endif
   1532 
   1533 void
   1534 siop_dump_acb(acb)
   1535 	struct siop_acb *acb;
   1536 {
   1537 	u_char *b = (u_char *) &acb->cmd;
   1538 	int i;
   1539 
   1540 	printf("acb@%x ", acb);
   1541 	if (acb->xs == NULL) {
   1542 		printf("<unused>\n");
   1543 		return;
   1544 	}
   1545 	printf("(%d:%d) flags %2x clen %2d cmd ", acb->xs->sc_link->target,
   1546 	    acb->xs->sc_link->lun, acb->flags, acb->clen);
   1547 	for (i = acb->clen; i; --i)
   1548 		printf(" %02x", *b++);
   1549 	printf("\n");
   1550 	printf("  xs: %08x data %8x:%04x ", acb->xs, acb->xs->data,
   1551 	    acb->xs->datalen);
   1552 	printf("va %8x:%04x ", acb->iob_buf, acb->iob_len);
   1553 	printf("cur %8x:%04x\n", acb->iob_curbuf, acb->iob_curlen);
   1554 }
   1555 
   1556 void
   1557 siop_dump(sc)
   1558 	struct siop_softc *sc;
   1559 {
   1560 	struct siop_acb *acb;
   1561 	siop_regmap_p rp = sc->sc_siopp;
   1562 	int s;
   1563 	int i;
   1564 
   1565 	s = splbio();
   1566 #if SIOP_TRACE_SIZE
   1567 	siop_dump_trace();
   1568 #endif
   1569 	printf("%s@%x regs %x istat %x\n",
   1570 	    sc->sc_dev.dv_xname, sc, rp, rp->siop_istat);
   1571 	if (acb = sc->free_list.tqh_first) {
   1572 		printf("Free list:\n");
   1573 		while (acb) {
   1574 			siop_dump_acb(acb);
   1575 			acb = acb->chain.tqe_next;
   1576 		}
   1577 	}
   1578 	if (acb = sc->ready_list.tqh_first) {
   1579 		printf("Ready list:\n");
   1580 		while (acb) {
   1581 			siop_dump_acb(acb);
   1582 			acb = acb->chain.tqe_next;
   1583 		}
   1584 	}
   1585 	if (acb = sc->nexus_list.tqh_first) {
   1586 		printf("Nexus list:\n");
   1587 		while (acb) {
   1588 			siop_dump_acb(acb);
   1589 			acb = acb->chain.tqe_next;
   1590 		}
   1591 	}
   1592 	if (sc->sc_nexus) {
   1593 		printf("Nexus:\n");
   1594 		siop_dump_acb(sc->sc_nexus);
   1595 	}
   1596 	for (i = 0; i < 8; ++i) {
   1597 		if (sc->sc_tinfo[i].cmds > 2) {
   1598 			printf("tgt %d: cmds %d disc %d senses %d lubusy %x\n",
   1599 			    i, sc->sc_tinfo[i].cmds,
   1600 			    sc->sc_tinfo[i].dconns,
   1601 			    sc->sc_tinfo[i].senses,
   1602 			    sc->sc_tinfo[i].lubusy);
   1603 		}
   1604 	}
   1605 	splx(s);
   1606 }
   1607 #endif
   1608