Home | History | Annotate | Line # | Download | only in obio
esp.c revision 1.21
      1 /*	$NetBSD: esp.c,v 1.21 1999/06/01 03:40:12 briggs Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Jason R. Thorpe.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed for the NetBSD Project
     18  *	by Jason R. Thorpe.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 /*
     35  * Copyright (c) 1994 Peter Galbavy
     36  * All rights reserved.
     37  *
     38  * Redistribution and use in source and binary forms, with or without
     39  * modification, are permitted provided that the following conditions
     40  * are met:
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  * 2. Redistributions in binary form must reproduce the above copyright
     44  *    notice, this list of conditions and the following disclaimer in the
     45  *    documentation and/or other materials provided with the distribution.
     46  * 3. All advertising materials mentioning features or use of this software
     47  *    must display the following acknowledgement:
     48  *	This product includes software developed by Peter Galbavy
     49  * 4. The name of the author may not be used to endorse or promote products
     50  *    derived from this software without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     54  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     55  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     56  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     57  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     58  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     60  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     61  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     62  * POSSIBILITY OF SUCH DAMAGE.
     63  */
     64 
     65 /*
     66  * Based on aic6360 by Jarle Greipsland
     67  *
     68  * Acknowledgements: Many of the algorithms used in this driver are
     69  * inspired by the work of Julian Elischer (julian (at) tfs.com) and
     70  * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu).  Thanks a million!
     71  */
     72 
     73 /*
     74  * Initial m68k mac support from Allen Briggs <briggs (at) macbsd.com>
     75  * (basically consisting of the match, a bit of the attach, and the
     76  *  "DMA" glue functions).
     77  */
     78 
     79 #include <sys/types.h>
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <sys/kernel.h>
     83 #include <sys/errno.h>
     84 #include <sys/ioctl.h>
     85 #include <sys/device.h>
     86 #include <sys/buf.h>
     87 #include <sys/proc.h>
     88 #include <sys/user.h>
     89 #include <sys/queue.h>
     90 
     91 #include <dev/scsipi/scsi_all.h>
     92 #include <dev/scsipi/scsipi_all.h>
     93 #include <dev/scsipi/scsiconf.h>
     94 #include <dev/scsipi/scsi_message.h>
     95 
     96 #include <machine/cpu.h>
     97 #include <machine/bus.h>
     98 #include <machine/param.h>
     99 
    100 #include <dev/ic/ncr53c9xreg.h>
    101 #include <dev/ic/ncr53c9xvar.h>
    102 
    103 #include <machine/viareg.h>
    104 
    105 #include <mac68k/obio/espvar.h>
    106 #include <mac68k/obio/obiovar.h>
    107 
    108 void	espattach	__P((struct device *, struct device *, void *));
    109 int	espmatch	__P((struct device *, struct cfdata *, void *));
    110 
    111 /* Linkup to the rest of the kernel */
    112 struct cfattach esp_ca = {
    113 	sizeof(struct esp_softc), espmatch, espattach
    114 };
    115 
    116 struct scsipi_device esp_dev = {
    117 	NULL,			/* Use default error handler */
    118 	NULL,			/* have a queue, served by this */
    119 	NULL,			/* have no async handler */
    120 	NULL,			/* Use default 'done' routine */
    121 };
    122 
    123 /*
    124  * Functions and the switch for the MI code.
    125  */
    126 u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    127 void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    128 int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    129 void	esp_dma_reset __P((struct ncr53c9x_softc *));
    130 int	esp_dma_intr __P((struct ncr53c9x_softc *));
    131 int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    132 	    size_t *, int, size_t *));
    133 void	esp_dma_go __P((struct ncr53c9x_softc *));
    134 void	esp_dma_stop __P((struct ncr53c9x_softc *));
    135 int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    136 void	esp_quick_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    137 int	esp_quick_dma_intr __P((struct ncr53c9x_softc *));
    138 int	esp_quick_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    139 	    size_t *, int, size_t *));
    140 void	esp_quick_dma_go __P((struct ncr53c9x_softc *));
    141 
    142 int	esp_dualbus_intr __P((register struct ncr53c9x_softc *sc));
    143 static struct esp_softc		*esp0 = NULL, *esp1 = NULL;
    144 
    145 static __inline__ int esp_dafb_have_dreq __P((struct esp_softc *esc));
    146 static __inline__ int esp_iosb_have_dreq __P((struct esp_softc *esc));
    147 int (*esp_have_dreq) __P((struct esp_softc *esc));
    148 
    149 struct ncr53c9x_glue esp_glue = {
    150 	esp_read_reg,
    151 	esp_write_reg,
    152 	esp_dma_isintr,
    153 	esp_dma_reset,
    154 	esp_dma_intr,
    155 	esp_dma_setup,
    156 	esp_dma_go,
    157 	esp_dma_stop,
    158 	esp_dma_isactive,
    159 	NULL,			/* gl_clear_latched_intr */
    160 };
    161 
    162 int
    163 espmatch(parent, cf, aux)
    164 	struct device *parent;
    165 	struct cfdata *cf;
    166 	void *aux;
    167 {
    168 	int	found = 0;
    169 
    170 	if ((cf->cf_unit == 0) && mac68k_machine.scsi96) {
    171 		found = 1;
    172 	}
    173 	if ((cf->cf_unit == 1) && mac68k_machine.scsi96_2) {
    174 		found = 1;
    175 	}
    176 
    177 	return found;
    178 }
    179 
    180 /*
    181  * Attach this instance, and then all the sub-devices
    182  */
    183 void
    184 espattach(parent, self, aux)
    185 	struct device *parent, *self;
    186 	void *aux;
    187 {
    188 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    189 	extern vaddr_t		SCSIBase;
    190 	struct esp_softc	*esc = (void *)self;
    191 	struct ncr53c9x_softc	*sc = &esc->sc_ncr53c9x;
    192 	int			quick = 0;
    193 	unsigned long		reg_offset;
    194 
    195 	reg_offset = SCSIBase - IOBase;
    196 	esc->sc_tag = oa->oa_tag;
    197 	/*
    198 	 * For Wombat, Primus and Optimus motherboards, DREQ is
    199 	 * visible on bit 0 of the IOSB's emulated VIA2 vIFR (and
    200 	 * the scsi registers are offset 0x1000 bytes from IOBase).
    201 	 *
    202 	 * For the Q700/900/950 it's at f9800024 for bus 0 and
    203 	 * f9800028 for bus 1 (900/950).  For these machines, that is also
    204 	 * a (12-bit) configuration register for DAFB's control of the
    205 	 * pseudo-DMA timing.  The default value is 0x1d1.
    206 	 */
    207 	esp_have_dreq = esp_dafb_have_dreq;
    208 	if (sc->sc_dev.dv_unit == 0) {
    209 		if (reg_offset == 0x10000) {
    210 			quick = 1;
    211 			esp_have_dreq = esp_iosb_have_dreq;
    212 		} else if (reg_offset == 0x18000) {
    213 			quick = 0;
    214 		} else {
    215 			if (bus_space_map(esc->sc_tag, 0xf9800024,
    216 					  4, 0, &esc->sc_bsh)) {
    217 				printf("failed to map 4 at 0xf9800024.\n");
    218 			} else {
    219 				quick = 1;
    220 				bus_space_write_4(esc->sc_tag,
    221 						  esc->sc_bsh, 0, 0x1d1);
    222 			}
    223 		}
    224 	} else {
    225 		if (bus_space_map(esc->sc_tag, 0xf9800028,
    226 				  4, 0, &esc->sc_bsh)) {
    227 			printf("failed to map 4 at 0xf9800028.\n");
    228 		} else {
    229 			quick = 1;
    230 			bus_space_write_4(esc->sc_tag, esc->sc_bsh, 0, 0x1d1);
    231 		}
    232 	}
    233 	if (quick) {
    234 		esp_glue.gl_write_reg = esp_quick_write_reg;
    235 		esp_glue.gl_dma_intr = esp_quick_dma_intr;
    236 		esp_glue.gl_dma_setup = esp_quick_dma_setup;
    237 		esp_glue.gl_dma_go = esp_quick_dma_go;
    238 	}
    239 
    240 	/*
    241 	 * Set up the glue for MI code early; we use some of it here.
    242 	 */
    243 	sc->sc_glue = &esp_glue;
    244 
    245 	/*
    246 	 * Save the regs
    247 	 */
    248 	if (sc->sc_dev.dv_unit == 0) {
    249 		esp0 = esc;
    250 
    251 		esc->sc_reg = (volatile u_char *) SCSIBase;
    252 		via2_register_irq(VIA2_SCSIIRQ,
    253 		    (void (*)(void *))ncr53c9x_intr, esc);
    254 		esc->irq_mask = V2IF_SCSIIRQ;
    255 		if (reg_offset == 0x10000) {
    256 			sc->sc_freq = 16500000;
    257 		} else {
    258 			sc->sc_freq = 25000000;
    259 		}
    260 
    261 		if (esp_glue.gl_dma_go == esp_quick_dma_go) {
    262 			printf(" (quick)");
    263 		}
    264 	} else {
    265 		esp1 = esc;
    266 
    267 		esc->sc_reg = (volatile u_char *) SCSIBase + 0x402;
    268 		via2_register_irq(VIA2_SCSIIRQ,
    269 		    (void (*)(void *))esp_dualbus_intr, NULL);
    270 		esc->irq_mask = 0;
    271 		sc->sc_freq = 25000000;
    272 
    273 		if (esp_glue.gl_dma_go == esp_quick_dma_go) {
    274 			printf(" (quick)");
    275 		}
    276 	}
    277 
    278 	printf(": address %p", esc->sc_reg);
    279 
    280 	sc->sc_id = 7;
    281 
    282 	/* gimme Mhz */
    283 	sc->sc_freq /= 1000000;
    284 
    285 	/*
    286 	 * It is necessary to try to load the 2nd config register here,
    287 	 * to find out what rev the esp chip is, else the esp_reset
    288 	 * will not set up the defaults correctly.
    289 	 */
    290 	sc->sc_cfg1 = sc->sc_id; /* | NCRCFG1_PARENB; */
    291 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    292 	sc->sc_cfg3 = 0;
    293 	sc->sc_rev = NCR_VARIANT_NCR53C96;
    294 
    295 	/*
    296 	 * This is the value used to start sync negotiations
    297 	 * Note that the NCR register "SYNCTP" is programmed
    298 	 * in "clocks per byte", and has a minimum value of 4.
    299 	 * The SCSI period used in negotiation is one-fourth
    300 	 * of the time (in nanoseconds) needed to transfer one byte.
    301 	 * Since the chip's clock is given in MHz, we have the following
    302 	 * formula: 4 * period = (1000 / freq) * 4
    303 	 */
    304 	sc->sc_minsync = 1000 / sc->sc_freq;
    305 
    306 	sc->sc_minsync = 0;	/* No synchronous xfers w/o DMA */
    307 	/* Really no limit, but since we want to fit into the TCR... */
    308 	sc->sc_maxxfer = 8 * 1024; /*64 * 1024; XXX */
    309 
    310 	/*
    311 	 * Now try to attach all the sub-devices
    312 	 */
    313 	sc->sc_adapter.scsipi_cmd = ncr53c9x_scsi_cmd;
    314 	sc->sc_adapter.scsipi_minphys = minphys;
    315 	ncr53c9x_attach(sc, &esp_dev);
    316 
    317 	/*
    318 	 * Configure interrupts.
    319 	 */
    320 	if (esc->irq_mask) {
    321 		via2_reg(vPCR) = 0x22;
    322 		via2_reg(vIFR) = esc->irq_mask;
    323 		via2_reg(vIER) = 0x80 | esc->irq_mask;
    324 	}
    325 }
    326 
    327 /*
    328  * Glue functions.
    329  */
    330 
    331 u_char
    332 esp_read_reg(sc, reg)
    333 	struct ncr53c9x_softc *sc;
    334 	int reg;
    335 {
    336 	struct esp_softc *esc = (struct esp_softc *)sc;
    337 	u_char	v;
    338 	int	s;
    339 
    340 	s = splhigh();
    341 	v = esc->sc_reg[reg * 16];
    342 	splx(s);
    343 	return v;
    344 }
    345 
    346 void
    347 esp_write_reg(sc, reg, val)
    348 	struct ncr53c9x_softc *sc;
    349 	int reg;
    350 	u_char val;
    351 {
    352 	struct esp_softc *esc = (struct esp_softc *)sc;
    353 	u_char	v = val;
    354 	int	s;
    355 
    356 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    357 		v = NCRCMD_TRANS;
    358 	}
    359 	s = splhigh();
    360 	esc->sc_reg[reg * 16] = v;
    361 	splx(s);
    362 }
    363 
    364 void
    365 esp_dma_stop(sc)
    366 	struct ncr53c9x_softc *sc;
    367 {
    368 }
    369 
    370 int
    371 esp_dma_isactive(sc)
    372 	struct ncr53c9x_softc *sc;
    373 {
    374 	struct esp_softc *esc = (struct esp_softc *)sc;
    375 
    376 	return esc->sc_active;
    377 }
    378 
    379 int
    380 esp_dma_isintr(sc)
    381 	struct ncr53c9x_softc *sc;
    382 {
    383 	struct esp_softc *esc = (struct esp_softc *)sc;
    384 
    385 	return esc->sc_reg[NCR_STAT * 16] & 0x80;
    386 }
    387 
    388 void
    389 esp_dma_reset(sc)
    390 	struct ncr53c9x_softc *sc;
    391 {
    392 	struct esp_softc *esc = (struct esp_softc *)sc;
    393 
    394 	esc->sc_active = 0;
    395 	esc->sc_tc = 0;
    396 }
    397 
    398 int
    399 esp_dma_intr(sc)
    400 	struct ncr53c9x_softc *sc;
    401 {
    402 	register struct esp_softc *esc = (struct esp_softc *)sc;
    403 	register u_char	*p;
    404 	volatile u_char *cmdreg, *intrreg, *statreg, *fiforeg;
    405 	register u_int	espphase, espstat, espintr;
    406 	register int	cnt;
    407 
    408 	if (esc->sc_active == 0) {
    409 		printf("dma_intr--inactive DMA\n");
    410 		return -1;
    411 	}
    412 
    413 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    414 		esc->sc_active = 0;
    415 		return 0;
    416 	}
    417 
    418 	cnt = *esc->sc_dmalen;
    419 	if (*esc->sc_dmalen == 0) {
    420 		printf("data interrupt, but no count left.");
    421 	}
    422 
    423 	p = *esc->sc_dmaaddr;
    424 	espphase = sc->sc_phase;
    425 	espstat = (u_int) sc->sc_espstat;
    426 	espintr = (u_int) sc->sc_espintr;
    427 	cmdreg = esc->sc_reg + NCR_CMD * 16;
    428 	fiforeg = esc->sc_reg + NCR_FIFO * 16;
    429 	statreg = esc->sc_reg + NCR_STAT * 16;
    430 	intrreg = esc->sc_reg + NCR_INTR * 16;
    431 	do {
    432 		if (esc->sc_datain) {
    433 			*p++ = *fiforeg;
    434 			cnt--;
    435 			if (espphase == DATA_IN_PHASE) {
    436 				*cmdreg = NCRCMD_TRANS;
    437 			} else {
    438 				esc->sc_active = 0;
    439 			}
    440 	 	} else {
    441 			if (   (espphase == DATA_OUT_PHASE)
    442 			    || (espphase == MESSAGE_OUT_PHASE)) {
    443 				*fiforeg = *p++;
    444 				cnt--;
    445 				*cmdreg = NCRCMD_TRANS;
    446 			} else {
    447 				esc->sc_active = 0;
    448 			}
    449 		}
    450 
    451 		if (esc->sc_active) {
    452 			while (!(*statreg & 0x80));
    453 			espstat = *statreg;
    454 			espintr = *intrreg;
    455 			espphase = (espintr & NCRINTR_DIS)
    456 				    ? /* Disconnected */ BUSFREE_PHASE
    457 				    : espstat & PHASE_MASK;
    458 		}
    459 	} while (esc->sc_active && (espintr & NCRINTR_BS));
    460 	sc->sc_phase = espphase;
    461 	sc->sc_espstat = (u_char) espstat;
    462 	sc->sc_espintr = (u_char) espintr;
    463 	*esc->sc_dmaaddr = p;
    464 	*esc->sc_dmalen = cnt;
    465 
    466 	if (*esc->sc_dmalen == 0) {
    467 		esc->sc_tc = NCRSTAT_TC;
    468 	}
    469 	sc->sc_espstat |= esc->sc_tc;
    470 	return 0;
    471 }
    472 
    473 int
    474 esp_dma_setup(sc, addr, len, datain, dmasize)
    475 	struct ncr53c9x_softc *sc;
    476 	caddr_t *addr;
    477 	size_t *len;
    478 	int datain;
    479 	size_t *dmasize;
    480 {
    481 	struct esp_softc *esc = (struct esp_softc *)sc;
    482 
    483 	esc->sc_dmaaddr = addr;
    484 	esc->sc_dmalen = len;
    485 	esc->sc_datain = datain;
    486 	esc->sc_dmasize = *dmasize;
    487 	esc->sc_tc = 0;
    488 
    489 	return 0;
    490 }
    491 
    492 void
    493 esp_dma_go(sc)
    494 	struct ncr53c9x_softc *sc;
    495 {
    496 	struct esp_softc *esc = (struct esp_softc *)sc;
    497 
    498 	if (esc->sc_datain == 0) {
    499 		esc->sc_reg[NCR_FIFO * 16] = **esc->sc_dmaaddr;
    500 		(*esc->sc_dmalen)--;
    501 		(*esc->sc_dmaaddr)++;
    502 	}
    503 	esc->sc_active = 1;
    504 }
    505 
    506 void
    507 esp_quick_write_reg(sc, reg, val)
    508 	struct ncr53c9x_softc *sc;
    509 	int reg;
    510 	u_char val;
    511 {
    512 	struct esp_softc *esc = (struct esp_softc *)sc;
    513 	u_char	v = val;
    514 	int	s;
    515 
    516 	s = splhigh();
    517 	esc->sc_reg[reg * 16] = v;
    518 	splx(s);
    519 }
    520 
    521 int
    522 esp_quick_dma_intr(sc)
    523 	struct ncr53c9x_softc *sc;
    524 {
    525 	struct esp_softc *esc = (struct esp_softc *)sc;
    526 	int trans=0, resid=0;
    527 
    528 	if (esc->sc_active == 0)
    529 		panic("dma_intr--inactive DMA\n");
    530 
    531 	esc->sc_active = 0;
    532 
    533 	if (esc->sc_dmasize == 0) {
    534 		int	res;
    535 
    536 		res = 65536;
    537 		res -= NCR_READ_REG(sc, NCR_TCL);
    538 		res -= NCR_READ_REG(sc, NCR_TCM) << 8;
    539 		printf("dmaintr: discarded %d b (last transfer was %d b).\n",
    540 			res, esc->sc_prevdmasize);
    541 		return 0;
    542 	}
    543 
    544 	if (esc->sc_datain &&
    545 	    (resid = (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)) != 0) {
    546 		printf("dmaintr: empty FIFO of %d\n", resid);
    547 		DELAY(1);
    548 	}
    549 
    550 	if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
    551 		resid += NCR_READ_REG(sc, NCR_TCL);
    552 		resid += NCR_READ_REG(sc, NCR_TCM) << 8;
    553 
    554 		if (resid == 0)
    555 			resid = 65536;
    556 	}
    557 
    558 	trans = esc->sc_dmasize - resid;
    559 	if (trans < 0) {
    560 		printf("dmaintr: trans < 0????");
    561 		trans = esc->sc_dmasize;
    562 	}
    563 
    564 	NCR_DMA(("dmaintr: trans %d, resid %d.\n", trans, resid));
    565 	*esc->sc_dmaaddr += trans;
    566 	*esc->sc_dmalen -= trans;
    567 
    568 	return 0;
    569 }
    570 
    571 int
    572 esp_quick_dma_setup(sc, addr, len, datain, dmasize)
    573 	struct ncr53c9x_softc *sc;
    574 	caddr_t *addr;
    575 	size_t *len;
    576 	int datain;
    577 	size_t *dmasize;
    578 {
    579 	struct esp_softc *esc = (struct esp_softc *)sc;
    580 
    581 	esc->sc_dmaaddr = addr;
    582 	esc->sc_dmalen = len;
    583 
    584 	esc->sc_pdmaddr = (u_int16_t *) *addr;
    585 	esc->sc_pdmalen = *len;
    586 	if (esc->sc_pdmalen & 1) {
    587 		esc->sc_pdmalen--;
    588 		esc->sc_pad = 1;
    589 	} else {
    590 		esc->sc_pad = 0;
    591 	}
    592 
    593 	esc->sc_datain = datain;
    594 	esc->sc_prevdmasize = esc->sc_dmasize;
    595 	esc->sc_dmasize = *dmasize;
    596 
    597 	return 0;
    598 }
    599 
    600 static __inline__ int
    601 esp_dafb_have_dreq(esc)
    602 	struct esp_softc *esc;
    603 {
    604 	u_int32_t r;
    605 
    606 	r = bus_space_read_4(esc->sc_tag, esc->sc_bsh, 0);
    607 	return (r & 0x200);
    608 }
    609 
    610 static __inline__ int
    611 esp_iosb_have_dreq(esc)
    612 	struct esp_softc *esc;
    613 {
    614 	return (via2_reg(vIFR) & V2IF_SCSIDRQ);
    615 }
    616 
    617 static int espspl=-1;
    618 #define __splx(s) __asm __volatile ("movew %0,sr" : : "di" (s));
    619 #define __spl2()  __splx(PSL_S|PSL_IPL2)
    620 #define __spl6()  __splx(PSL_S|PSL_IPL6)
    621 
    622 void
    623 esp_quick_dma_go(sc)
    624 	struct ncr53c9x_softc *sc;
    625 {
    626 	struct esp_softc *esc = (struct esp_softc *)sc;
    627 	extern int *nofault;
    628 	label_t faultbuf;
    629 	u_int16_t volatile *pdma;
    630 	u_char volatile *statreg;
    631 
    632 	esc->sc_active = 1;
    633 
    634 	espspl = spl2();
    635 
    636 restart_dmago:
    637 	nofault = (int *) &faultbuf;
    638 	if (setjmp((label_t *) nofault)) {
    639 		int	i=0;
    640 
    641 		nofault = (int *) 0;
    642 		statreg = esc->sc_reg + NCR_STAT * 16;
    643 		for (;;) {
    644 			if (*statreg & 0x80) {
    645 				goto gotintr;
    646 			}
    647 
    648 			if (esp_have_dreq(esc)) {
    649 				break;
    650 			}
    651 
    652 			DELAY(1);
    653 			if (i++ > 10000)
    654 				panic("esp_dma_go: Argh!");
    655 		}
    656 		goto restart_dmago;
    657 	}
    658 
    659 	statreg = esc->sc_reg + NCR_STAT * 16;
    660 	pdma = (u_int16_t *) (esc->sc_reg + 0x100);
    661 
    662 #define WAIT while (!esp_have_dreq(esc)) if (*statreg & 0x80) goto gotintr
    663 
    664 	if (esc->sc_datain == 0) {
    665 		while (esc->sc_pdmalen) {
    666 			WAIT;
    667 			__spl6(); *pdma = *(esc->sc_pdmaddr)++; __spl2()
    668 			esc->sc_pdmalen -= 2;
    669 		}
    670 		if (esc->sc_pad) {
    671 			unsigned short	us;
    672 			unsigned char	*c;
    673 			c = (unsigned char *) esc->sc_pdmaddr;
    674 			us = *c;
    675 			WAIT;
    676 			__spl6(); *pdma = us; __spl2()
    677 		}
    678 	} else {
    679 		while (esc->sc_pdmalen) {
    680 			WAIT;
    681 			__spl6(); *(esc->sc_pdmaddr)++ = *pdma; __spl2()
    682 			esc->sc_pdmalen -= 2;
    683 		}
    684 		if (esc->sc_pad) {
    685 			unsigned short	us;
    686 			unsigned char	*c;
    687 			WAIT;
    688 			__spl6(); us = *pdma; __spl2()
    689 			c = (unsigned char *) esc->sc_pdmaddr;
    690 			*c = us & 0xff;
    691 		}
    692 	}
    693 #undef WAIT
    694 
    695 	nofault = (int *) 0;
    696 
    697 	if ((*statreg & 0x80) == 0) {
    698 		if (espspl != -1) splx(espspl); espspl = -1;
    699 		return;
    700 	}
    701 
    702 gotintr:
    703 	ncr53c9x_intr(sc);
    704 	if (espspl != -1) splx(espspl); espspl = -1;
    705 }
    706 
    707 int
    708 esp_dualbus_intr(sc)
    709 	register struct ncr53c9x_softc *sc;
    710 {
    711 	if (esp0 && (esp0->sc_reg[NCR_STAT * 16] & 0x80))
    712 		ncr53c9x_intr((struct ncr53c9x_softc *) esp0);
    713 
    714 	if (esp1 && (esp1->sc_reg[NCR_STAT * 16] & 0x80))
    715 		ncr53c9x_intr((struct ncr53c9x_softc *) esp1);
    716 
    717 	return 0;
    718 }
    719