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