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