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