Home | History | Annotate | Line # | Download | only in isa
esp_isa.c revision 1.5
      1 /*	$NetBSD: esp_isa.c,v 1.5 1997/10/05 18:37:01 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1994 Peter Galbavy
     42  * Copyright (c) 1995 Paul Kranenburg
     43  * All rights reserved.
     44  *
     45  * Redistribution and use in source and binary forms, with or without
     46  * modification, are permitted provided that the following conditions
     47  * are met:
     48  * 1. Redistributions of source code must retain the above copyright
     49  *    notice, this list of conditions and the following disclaimer.
     50  * 2. Redistributions in binary form must reproduce the above copyright
     51  *    notice, this list of conditions and the following disclaimer in the
     52  *    documentation and/or other materials provided with the distribution.
     53  * 3. All advertising materials mentioning features or use of this software
     54  *    must display the following acknowledgement:
     55  *	This product includes software developed by Peter Galbavy
     56  * 4. The name of the author may not be used to endorse or promote products
     57  *    derived from this software without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     60  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     61  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     62  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     63  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     64  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     65  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     67  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     68  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69  * POSSIBILITY OF SUCH DAMAGE.
     70  */
     71 
     72 /*
     73  * Based on aic6360 by Jarle Greipsland
     74  *
     75  * Acknowledgements: Many of the algorithms used in this driver are
     76  * inspired by the work of Julian Elischer (julian (at) tfs.com) and
     77  * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu).  Thanks a million!
     78  */
     79 
     80 /*
     81  * Initial m68k mac support from Allen Briggs <briggs (at) macbsd.com>
     82  * (basically consisting of the match, a bit of the attach, and the
     83  *  "DMA" glue functions).
     84  */
     85 /*
     86  * Copyright (c) 1994, 1996, 1997 Charles M. Hannum.  All rights reserved.
     87  *
     88  * Redistribution and use in source and binary forms, with or without
     89  * modification, are permitted provided that the following conditions
     90  * are met:
     91  * 1. Redistributions of source code must retain the above copyright
     92  *    notice, this list of conditions and the following disclaimer.
     93  * 2. Redistributions in binary form must reproduce the above copyright
     94  *    notice, this list of conditions and the following disclaimer in the
     95  *    documentation and/or other materials provided with the distribution.
     96  * 3. All advertising materials mentioning features or use of this software
     97  *    must display the following acknowledgement:
     98  *	This product includes software developed by Charles M. Hannum.
     99  * 4. The name of the author may not be used to endorse or promote products
    100  *    derived from this software without specific prior written permission.
    101  *
    102  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    103  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    104  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    105  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    106  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    107  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    108  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    109  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    110  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    111  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    112  */
    113 
    114 /*
    115  * Copyright (c) 1997 Eric S. Hvozda (hvozda (at) netcom.com)
    116  * All rights reserved.
    117  *
    118  * Redistribution and use in source and binary forms, with or without
    119  * modification, are permitted provided that the following conditions
    120  * are met:
    121  * 1. Redistributions of source code must retain the above copyright
    122  *    notice, this list of conditions and the following disclaimer.
    123  * 2. Redistributions in binary form must reproduce the above copyright
    124  *    notice, this list of conditions and the following disclaimer in the
    125  *    documentation and/or other materials provided with the distribution.
    126  * 3. All advertising materials mentioning features or use of this software
    127  *    must display the following acknowledgement:
    128  *      This product includes software developed by Eric S. Hvozda.
    129  * 4. The name of Eric S. Hvozda may not be used to endorse or promote products
    130  *    derived from this software without specific prior written permission.
    131  *
    132  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    133  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    134  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    135  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    136  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    137  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    138  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    139  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    140  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    141  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    142  */
    143 
    144 #include <sys/param.h>
    145 #include <sys/systm.h>
    146 #include <sys/device.h>
    147 #include <sys/buf.h>
    148 
    149 #include <machine/bus.h>
    150 #include <machine/intr.h>
    151 
    152 #include <dev/scsipi/scsi_all.h>
    153 #include <dev/scsipi/scsipi_all.h>
    154 #include <dev/scsipi/scsiconf.h>
    155 
    156 #include <dev/isa/isavar.h>
    157 #include <dev/isa/isadmavar.h>
    158 
    159 #include <dev/ic/ncr53c9xreg.h>
    160 #include <dev/ic/ncr53c9xvar.h>
    161 
    162 #include <dev/isa/espvar.h>
    163 
    164 int	esp_isa_match __P((struct device *, void *, void *));
    165 void	esp_isa_attach __P((struct device *, struct device *, void *));
    166 
    167 struct cfattach esp_isa_ca = {
    168 	sizeof(struct esp_softc), esp_isa_match, esp_isa_attach
    169 };
    170 
    171 struct cfdriver esp_cd = {
    172 	NULL, "esp", DV_DULL
    173 };
    174 
    175 struct scsipi_adapter esp_switch = {
    176 	ncr53c9x_scsi_cmd,
    177 	minphys,		/* no max at this level; handled by DMA code */
    178 	NULL,
    179 	NULL,
    180 };
    181 
    182 struct scsipi_device esp_dev = {
    183 	NULL,			/* Use default error handler */
    184 	NULL,			/* have a queue, served by this */
    185 	NULL,			/* have no async handler */
    186 	NULL,			/* Use default 'done' routine */
    187 };
    188 
    189 int esp_debug = 0;	/* ESP_SHOWTRAC | ESP_SHOWREGS | ESP_SHOWMISC */
    190 
    191 /*
    192  * Functions and the switch for the MI code.
    193  */
    194 u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    195 void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    196 int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    197 void	esp_dma_reset __P((struct ncr53c9x_softc *));
    198 int	esp_dma_intr __P((struct ncr53c9x_softc *));
    199 int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    200 	    size_t *, int, size_t *));
    201 void	esp_dma_go __P((struct ncr53c9x_softc *));
    202 void	esp_dma_stop __P((struct ncr53c9x_softc *));
    203 int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    204 
    205 struct ncr53c9x_glue esp_glue = {
    206 	esp_read_reg,
    207 	esp_write_reg,
    208 	esp_dma_isintr,
    209 	esp_dma_reset,
    210 	esp_dma_intr,
    211 	esp_dma_setup,
    212 	esp_dma_go,
    213 	esp_dma_stop,
    214 	esp_dma_isactive,
    215 	NULL,			/* gl_clear_latched_intr */
    216 };
    217 
    218 /*
    219  * Look for the board
    220  */
    221 int
    222 esp_find(iot, ioh, epd)
    223 	bus_space_tag_t iot;
    224 	bus_space_handle_t ioh;
    225 	struct esp_probe_data *epd;
    226 {
    227 	u_int vers;
    228 	u_int p1;
    229 	u_int p2;
    230 	u_int jmp;
    231 
    232 	ESP_TRACE(("[esp_find] "));
    233 
    234 	/* reset card before we probe? */
    235 
    236 	/*
    237 	 * Switch to the PIO regs and look for the bit pattern
    238 	 * we expect...
    239 	 */
    240 	bus_space_write_1(iot, ioh, NCR_CFG4,
    241 		NCRCFG4_CRS1 | bus_space_read_1(iot, ioh, NCR_CFG4));
    242 
    243 #define SIG_MASK 0x87
    244 #define REV_MASK 0x70
    245 #define	M1	 0x02
    246 #define	M2	 0x05
    247 #define ISNCR	 0x80
    248 #define ISESP406 0x40
    249 
    250 	vers = bus_space_read_1(iot, ioh, NCR_SIGNTR);
    251 	p1 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    252 	p2 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    253 
    254 	ESP_MISC(("%s: 0x%0x 0x%0x 0x%0x\n", epd->sc_dev.dv_xname,
    255 	    vers, p1, p2));
    256 
    257 	if (!((p1 == M1 && p2 == M2) || (p1 == M2 && p2 == M1)))
    258 		return 0;
    259 
    260 	/* Ok, what is it? */
    261 	epd->sc_isncr = (vers & ISNCR);
    262 	epd->sc_rev = ((vers & REV_MASK) == ISESP406) ?
    263 	    NCR_VARIANT_ESP406 : NCR_VARIANT_FAS408;
    264 
    265 	/* What do the jumpers tell us? */
    266 	jmp = bus_space_read_1(iot, ioh, NCR_JMP);
    267 
    268 	epd->sc_msize = (jmp & NCRJMP_ROMSZ) ? 0x4000 : 0x8000;
    269 	epd->sc_parity = jmp & NCRJMP_J2;
    270 	epd->sc_sync = jmp & NCRJMP_J4;
    271 	epd->sc_id = (jmp & NCRJMP_J3) ? 7 : 6;
    272 	switch (jmp & (NCRJMP_J0 | NCRJMP_J1)) {
    273 		case NCRJMP_J0 | NCRJMP_J1:
    274 			epd->sc_irq = 11;
    275 			break;
    276 		case NCRJMP_J0:
    277 			epd->sc_irq = 10;
    278 			break;
    279 		case NCRJMP_J1:
    280 			epd->sc_irq = 15;
    281 			break;
    282 		default:
    283 			epd->sc_irq = 12;
    284 			break;
    285 	}
    286 
    287 	bus_space_write_1(iot, ioh, NCR_CFG4,
    288 		~NCRCFG4_CRS1 & bus_space_read_1(iot, ioh, NCR_CFG4));
    289 
    290 	/* Try to set NCRESPCFG3_FCLK, some FAS408's don't support
    291 	 * NCRESPCFG3_FCLK even though it is documented.  A bad
    292 	 * batch of chips perhaps?
    293 	 */
    294 	bus_space_write_1(iot, ioh, NCR_ESPCFG3,
    295 	    bus_space_read_1(iot, ioh, NCR_ESPCFG3) | NCRESPCFG3_FCLK);
    296 	epd->sc_isfast = bus_space_read_1(iot, ioh, NCR_ESPCFG3)
    297 	    & NCRESPCFG3_FCLK;
    298 
    299 	return 1;
    300 }
    301 
    302 void
    303 esp_init(esc, epd)
    304 	struct esp_softc *esc;
    305 	struct esp_probe_data *epd;
    306 {
    307 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    308 
    309 	ESP_TRACE(("[esp_init] "));
    310 
    311 	/*
    312 	 * Set up the glue for MI code early; we use some of it here.
    313 	 */
    314 	sc->sc_glue = &esp_glue;
    315 
    316 	sc->sc_rev = epd->sc_rev;
    317 	sc->sc_id = epd->sc_id;
    318 
    319 	/* If we could set NCRESPCFG3_FCLK earlier, we can really move */
    320 	sc->sc_cfg3 = NCR_READ_REG(sc, NCR_ESPCFG3);
    321 	if ((epd->sc_rev == NCR_VARIANT_FAS408) && epd->sc_isfast) {
    322 		sc->sc_freq = 40;
    323 		sc->sc_cfg3 |= NCRESPCFG3_FCLK;
    324 	}
    325 	else
    326 		sc->sc_freq = 24;
    327 
    328 	/* Setup the register defaults */
    329 	sc->sc_cfg1 = sc->sc_id;
    330 	if (epd->sc_parity)
    331 		sc->sc_cfg1 |= NCRCFG1_PARENB;
    332 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    333 	sc->sc_cfg3 |= NCRESPCFG3_IDM | NCRESPCFG3_FSCSI;
    334 
    335 	/*
    336 	 * This is the value used to start sync negotiations
    337 	 * Note that the NCR register "SYNCTP" is programmed
    338 	 * in "clocks per byte", and has a minimum value of 4.
    339 	 * The SCSI period used in negotiation is one-fourth
    340 	 * of the time (in nanoseconds) needed to transfer one byte.
    341 	 * Since the chip's clock is given in MHz, we have the following
    342 	 * formula: 4 * period = (1000 / freq) * 4
    343 	 */
    344 	if (epd->sc_sync)
    345 	{
    346 #ifdef DIAGNOSTIC
    347 		printf("%s: sync requested, but not supported; will do async\n",
    348 		    sc->sc_dev.dv_xname);
    349 #endif
    350 		epd->sc_sync = 0;
    351 	}
    352 
    353 	sc->sc_minsync = 0;
    354 
    355 	/* Really no limit, but since we want to fit into the TCR... */
    356 	sc->sc_maxxfer = 64 * 1024;
    357 }
    358 
    359 /*
    360  * Check the slots looking for a board we recognise
    361  * If we find one, note it's address (slot) and call
    362  * the actual probe routine to check it out.
    363  */
    364 int
    365 esp_isa_match(parent, match, aux)
    366 	struct device *parent;
    367 	void *match, *aux;
    368 {
    369 	struct ncr53c9x_softc *sc = match;
    370 	struct isa_attach_args *ia = aux;
    371 	bus_space_tag_t iot = ia->ia_iot;
    372 	bus_space_handle_t ioh;
    373 	struct esp_probe_data epd;
    374 	int rv;
    375 
    376 	ESP_TRACE(("[esp_isa_match] "));
    377 
    378 	if (ia->ia_iobase != 0x230 && ia->ia_iobase != 0x330) {
    379 #ifdef DIAGNOSTIC
    380 		printf("%s: invalid iobase 0x%0x, device not configured\n",
    381 		    sc->sc_dev.dv_xname, ia->ia_iobase);
    382 #endif
    383 		return 0;
    384 	}
    385 
    386 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh)) {
    387 #ifdef DIAGNOSTIC
    388 		printf("%s: bus_space_map() failed!\n", sc->sc_dev.dv_xname);
    389 #endif
    390 		return 0;
    391 	}
    392 
    393 	epd.sc_dev = sc->sc_dev;
    394 	rv = esp_find(iot, ioh, &epd);
    395 
    396 	bus_space_unmap(iot, ioh, ESP_ISA_IOSIZE);
    397 
    398 	if (rv) {
    399 		if (ia->ia_irq != IRQUNK && ia->ia_irq != epd.sc_irq) {
    400 #ifdef DIAGNOSTIC
    401 		printf("%s: configured IRQ (%0d) does not match board IRQ (%0d), device not configured\n",
    402 		    sc->sc_dev.dv_xname, ia->ia_irq, epd.sc_irq);
    403 #endif
    404 			return 0;
    405 		}
    406 		ia->ia_irq = epd.sc_irq;
    407 		ia->ia_msize = 0;
    408 		ia->ia_iosize = ESP_ISA_IOSIZE;
    409 	}
    410 	return (rv);
    411 }
    412 
    413 /*
    414  * Attach this instance, and then all the sub-devices
    415  */
    416 void
    417 esp_isa_attach(parent, self, aux)
    418 	struct device *parent, *self;
    419 	void *aux;
    420 {
    421 	struct isa_attach_args *ia = aux;
    422 	struct esp_softc *esc = (void *)self;
    423 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    424 	bus_space_tag_t iot = ia->ia_iot;
    425 	bus_space_handle_t ioh;
    426 	struct esp_probe_data epd;
    427 	isa_chipset_tag_t ic = ia->ia_ic;
    428 
    429 	printf("\n");
    430 	ESP_TRACE(("[esp_isa_attach] "));
    431 
    432 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh))
    433 		panic("espattach: bus_space_map failed");
    434 
    435 	epd.sc_dev = sc->sc_dev;
    436 	if (!esp_find(iot, ioh, &epd))
    437 		panic("espattach: esp_find failed");
    438 
    439 	if (ia->ia_drq != DRQUNK)
    440 		isa_dmacascade(parent, ia->ia_drq);
    441 
    442 	esc->sc_ih = isa_intr_establish(ic, ia->ia_irq, IST_EDGE, IPL_BIO,
    443 	    (int (*)(void *))ncr53c9x_intr, esc);
    444 	if (esc->sc_ih == NULL) {
    445 		printf("%s: couldn't establish interrupt\n",
    446 		    sc->sc_dev.dv_xname);
    447 		return;
    448 	}
    449 
    450 	esp_init(esc, &epd);
    451 
    452 	esc->sc_ioh = ioh;
    453 	esc->sc_iot = iot;
    454 
    455 	printf("%s:%ssync,%sparity\n", sc->sc_dev.dv_xname,
    456 	    epd.sc_sync ? " " : " no ", epd.sc_parity ? " " : " no ");
    457 	printf("%s", sc->sc_dev.dv_xname);
    458 
    459 	/*
    460 	 * Now try to attach all the sub-devices
    461 	 */
    462 	ncr53c9x_attach(sc, &esp_switch, &esp_dev);
    463 }
    464 
    465 /*
    466  * Glue functions.
    467  */
    468 u_char
    469 esp_read_reg(sc, reg)
    470 	struct ncr53c9x_softc *sc;
    471 	int reg;
    472 {
    473 	struct esp_softc *esc = (struct esp_softc *)sc;
    474 	u_char v;
    475 
    476 	v =  bus_space_read_1(esc->sc_iot, esc->sc_ioh, reg);
    477 
    478 	ESP_REGS(("[esp_read_reg CRS%c 0x%02x=0x%02x] ",
    479 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    480 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    481 
    482 	return v;
    483 }
    484 
    485 void
    486 esp_write_reg(sc, reg, val)
    487 	struct ncr53c9x_softc *sc;
    488 	int reg;
    489 	u_char val;
    490 {
    491 	struct esp_softc *esc = (struct esp_softc *)sc;
    492 	u_char v = val;
    493 
    494 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    495 		v = NCRCMD_TRANS;
    496 	}
    497 
    498 	ESP_REGS(("[esp_write_reg CRS%c 0x%02x=0x%02x] ",
    499 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    500 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    501 
    502 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, reg, v);
    503 }
    504 
    505 int
    506 esp_dma_isintr(sc)
    507 	struct ncr53c9x_softc *sc;
    508 {
    509 	ESP_TRACE(("[esp_dma_isintr] "));
    510 
    511 	return NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT;
    512 }
    513 
    514 void
    515 esp_dma_reset(sc)
    516 	struct ncr53c9x_softc *sc;
    517 {
    518 	struct esp_softc *esc = (struct esp_softc *)sc;
    519 
    520 	ESP_TRACE(("[esp_dma_reset] "));
    521 
    522 	esc->sc_active = 0;
    523 	esc->sc_tc = 0;
    524 }
    525 
    526 int
    527 esp_dma_intr(sc)
    528 	struct ncr53c9x_softc *sc;
    529 {
    530 	struct esp_softc *esc = (struct esp_softc *)sc;
    531 	u_char	*p;
    532 	u_int	espphase, espstat, espintr;
    533 	int	cnt;
    534 
    535 	ESP_TRACE(("[esp_dma_intr] "));
    536 
    537 	if (esc->sc_active == 0) {
    538 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    539 		return -1;
    540 	}
    541 
    542 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    543 		esc->sc_active = 0;
    544 		return 0;
    545 	}
    546 
    547 	cnt = *esc->sc_pdmalen;
    548 	if (*esc->sc_pdmalen == 0) {
    549 		printf("%s: data interrupt, but no count left\n",
    550 		    sc->sc_dev.dv_xname);
    551 	}
    552 
    553 	p = *esc->sc_dmaaddr;
    554 	espphase = sc->sc_phase;
    555 	espstat = (u_int) sc->sc_espstat;
    556 	espintr = (u_int) sc->sc_espintr;
    557 	do {
    558 		if (esc->sc_datain) {
    559 			*p++ = NCR_READ_REG(sc, NCR_FIFO);
    560 			cnt--;
    561 			if (espphase == DATA_IN_PHASE) {
    562 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    563 			} else {
    564 				esc->sc_active = 0;
    565 			}
    566 	 	} else {
    567 			if (   (espphase == DATA_OUT_PHASE)
    568 			    || (espphase == MESSAGE_OUT_PHASE)) {
    569 				NCR_WRITE_REG(sc, NCR_FIFO, *p++);
    570 				cnt--;
    571 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    572 			} else {
    573 				esc->sc_active = 0;
    574 			}
    575 		}
    576 
    577 		if (esc->sc_active) {
    578 			while (!(NCR_READ_REG(sc, NCR_STAT) & 0x80));
    579 			espstat = NCR_READ_REG(sc, NCR_STAT);
    580 			espintr = NCR_READ_REG(sc, NCR_INTR);
    581 			espphase = (espintr & NCRINTR_DIS)
    582 				    ? /* Disconnected */ BUSFREE_PHASE
    583 				    : espstat & PHASE_MASK;
    584 		}
    585 	} while (esc->sc_active && espintr);
    586 	sc->sc_phase = espphase;
    587 	sc->sc_espstat = (u_char) espstat;
    588 	sc->sc_espintr = (u_char) espintr;
    589 	*esc->sc_dmaaddr = p;
    590 	*esc->sc_pdmalen = cnt;
    591 
    592 	if (*esc->sc_pdmalen == 0) {
    593 		esc->sc_tc = NCRSTAT_TC;
    594 	}
    595 	sc->sc_espstat |= esc->sc_tc;
    596 	return 0;
    597 }
    598 
    599 int
    600 esp_dma_setup(sc, addr, len, datain, dmasize)
    601 	struct ncr53c9x_softc *sc;
    602 	caddr_t *addr;
    603 	size_t *len;
    604 	int datain;
    605 	size_t *dmasize;
    606 {
    607 	struct esp_softc *esc = (struct esp_softc *)sc;
    608 
    609 	ESP_TRACE(("[esp_dma_setup] "));
    610 
    611 	esc->sc_dmaaddr = addr;
    612 	esc->sc_pdmalen = len;
    613 	esc->sc_datain = datain;
    614 	esc->sc_dmasize = *dmasize;
    615 	esc->sc_tc = 0;
    616 
    617 	return 0;
    618 }
    619 
    620 void
    621 esp_dma_go(sc)
    622 	struct ncr53c9x_softc *sc;
    623 {
    624 	struct esp_softc *esc = (struct esp_softc *)sc;
    625 
    626 	ESP_TRACE(("[esp_dma_go] "));
    627 
    628 	esc->sc_active = 1;
    629 }
    630 
    631 void
    632 esp_dma_stop(sc)
    633 	struct ncr53c9x_softc *sc;
    634 {
    635 	ESP_TRACE(("[esp_dma_stop] "));
    636 }
    637 
    638 int
    639 esp_dma_isactive(sc)
    640 	struct ncr53c9x_softc *sc;
    641 {
    642 	struct esp_softc *esc = (struct esp_softc *)sc;
    643 
    644 	ESP_TRACE(("[esp_dma_isactive] "));
    645 
    646 	return esc->sc_active;
    647 }
    648