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