Home | History | Annotate | Line # | Download | only in isa
esp_isa.c revision 1.11
      1 /*	$NetBSD: esp_isa.c,v 1.11 1998/06/25 19:18:05 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 *, struct cfdata *, 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 scsipi_adapter esp_switch = {
    172 	ncr53c9x_scsi_cmd,
    173 	minphys,		/* no max at this level; handled by DMA code */
    174 	NULL,
    175 	NULL,
    176 };
    177 
    178 struct scsipi_device esp_dev = {
    179 	NULL,			/* Use default error handler */
    180 	NULL,			/* have a queue, served by this */
    181 	NULL,			/* have no async handler */
    182 	NULL,			/* Use default 'done' routine */
    183 };
    184 
    185 int esp_debug = 0;	/* ESP_SHOWTRAC | ESP_SHOWREGS | ESP_SHOWMISC */
    186 
    187 /*
    188  * Functions and the switch for the MI code.
    189  */
    190 u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    191 void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    192 int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    193 void	esp_dma_reset __P((struct ncr53c9x_softc *));
    194 int	esp_dma_intr __P((struct ncr53c9x_softc *));
    195 int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    196 	    size_t *, int, size_t *));
    197 void	esp_dma_go __P((struct ncr53c9x_softc *));
    198 void	esp_dma_stop __P((struct ncr53c9x_softc *));
    199 int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    200 
    201 struct ncr53c9x_glue esp_glue = {
    202 	esp_read_reg,
    203 	esp_write_reg,
    204 	esp_dma_isintr,
    205 	esp_dma_reset,
    206 	esp_dma_intr,
    207 	esp_dma_setup,
    208 	esp_dma_go,
    209 	esp_dma_stop,
    210 	esp_dma_isactive,
    211 	NULL,			/* gl_clear_latched_intr */
    212 };
    213 
    214 /*
    215  * Look for the board
    216  */
    217 int
    218 esp_find(iot, ioh, epd)
    219 	bus_space_tag_t iot;
    220 	bus_space_handle_t ioh;
    221 	struct esp_probe_data *epd;
    222 {
    223 	u_int vers;
    224 	u_int p1;
    225 	u_int p2;
    226 	u_int jmp;
    227 
    228 	ESP_TRACE(("[esp_find] "));
    229 
    230 	/* reset card before we probe? */
    231 
    232 	/*
    233 	 * Switch to the PIO regs and look for the bit pattern
    234 	 * we expect...
    235 	 */
    236 	bus_space_write_1(iot, ioh, NCR_CFG4,
    237 		NCRCFG4_CRS1 | bus_space_read_1(iot, ioh, NCR_CFG4));
    238 
    239 #define SIG_MASK 0x87
    240 #define REV_MASK 0x70
    241 #define	M1	 0x02
    242 #define	M2	 0x05
    243 #define ISNCR	 0x80
    244 #define ISESP406 0x40
    245 
    246 	vers = bus_space_read_1(iot, ioh, NCR_SIGNTR);
    247 	p1 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    248 	p2 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    249 
    250 	ESP_MISC(("esp_find: 0x%0x 0x%0x 0x%0x\n", vers, p1, p2));
    251 
    252 	if (!((p1 == M1 && p2 == M2) || (p1 == M2 && p2 == M1)))
    253 		return 0;
    254 
    255 	/* Ok, what is it? */
    256 	epd->sc_isncr = (vers & ISNCR);
    257 	epd->sc_rev = ((vers & REV_MASK) == ISESP406) ?
    258 	    NCR_VARIANT_ESP406 : NCR_VARIANT_FAS408;
    259 
    260 	/* What do the jumpers tell us? */
    261 	jmp = bus_space_read_1(iot, ioh, NCR_JMP);
    262 
    263 	epd->sc_msize = (jmp & NCRJMP_ROMSZ) ? 0x4000 : 0x8000;
    264 	epd->sc_parity = jmp & NCRJMP_J2;
    265 	epd->sc_sync = jmp & NCRJMP_J4;
    266 	epd->sc_id = (jmp & NCRJMP_J3) ? 7 : 6;
    267 	switch (jmp & (NCRJMP_J0 | NCRJMP_J1)) {
    268 		case NCRJMP_J0 | NCRJMP_J1:
    269 			epd->sc_irq = 11;
    270 			break;
    271 		case NCRJMP_J0:
    272 			epd->sc_irq = 10;
    273 			break;
    274 		case NCRJMP_J1:
    275 			epd->sc_irq = 15;
    276 			break;
    277 		default:
    278 			epd->sc_irq = 12;
    279 			break;
    280 	}
    281 
    282 	bus_space_write_1(iot, ioh, NCR_CFG4,
    283 		~NCRCFG4_CRS1 & bus_space_read_1(iot, ioh, NCR_CFG4));
    284 
    285 	/* Try to set NCRESPCFG3_FCLK, some FAS408's don't support
    286 	 * NCRESPCFG3_FCLK even though it is documented.  A bad
    287 	 * batch of chips perhaps?
    288 	 */
    289 	bus_space_write_1(iot, ioh, NCR_ESPCFG3,
    290 	    bus_space_read_1(iot, ioh, NCR_ESPCFG3) | NCRESPCFG3_FCLK);
    291 	epd->sc_isfast = bus_space_read_1(iot, ioh, NCR_ESPCFG3)
    292 	    & NCRESPCFG3_FCLK;
    293 
    294 	return 1;
    295 }
    296 
    297 void
    298 esp_init(esc, epd)
    299 	struct esp_softc *esc;
    300 	struct esp_probe_data *epd;
    301 {
    302 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    303 
    304 	ESP_TRACE(("[esp_init] "));
    305 
    306 	/*
    307 	 * Set up the glue for MI code early; we use some of it here.
    308 	 */
    309 	sc->sc_glue = &esp_glue;
    310 
    311 	sc->sc_rev = epd->sc_rev;
    312 	sc->sc_id = epd->sc_id;
    313 
    314 	/* If we could set NCRESPCFG3_FCLK earlier, we can really move */
    315 	sc->sc_cfg3 = NCR_READ_REG(sc, NCR_ESPCFG3);
    316 	if ((epd->sc_rev == NCR_VARIANT_FAS408) && epd->sc_isfast) {
    317 		sc->sc_freq = 40;
    318 		sc->sc_cfg3 |= NCRESPCFG3_FCLK;
    319 	}
    320 	else
    321 		sc->sc_freq = 24;
    322 
    323 	/* Setup the register defaults */
    324 	sc->sc_cfg1 = sc->sc_id;
    325 	if (epd->sc_parity)
    326 		sc->sc_cfg1 |= NCRCFG1_PARENB;
    327 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    328 	sc->sc_cfg3 |= NCRESPCFG3_IDM | NCRESPCFG3_FSCSI;
    329 
    330 	/*
    331 	 * This is the value used to start sync negotiations
    332 	 * Note that the NCR register "SYNCTP" is programmed
    333 	 * in "clocks per byte", and has a minimum value of 4.
    334 	 * The SCSI period used in negotiation is one-fourth
    335 	 * of the time (in nanoseconds) needed to transfer one byte.
    336 	 * Since the chip's clock is given in MHz, we have the following
    337 	 * formula: 4 * period = (1000 / freq) * 4
    338 	 */
    339 	if (epd->sc_sync)
    340 	{
    341 #ifdef DIAGNOSTIC
    342 		printf("%s: sync requested, but not supported; will do async\n",
    343 		    sc->sc_dev.dv_xname);
    344 #endif
    345 		epd->sc_sync = 0;
    346 	}
    347 
    348 	sc->sc_minsync = 0;
    349 
    350 	/* Really no limit, but since we want to fit into the TCR... */
    351 	sc->sc_maxxfer = 64 * 1024;
    352 }
    353 
    354 /*
    355  * Check the slots looking for a board we recognise
    356  * If we find one, note it's address (slot) and call
    357  * the actual probe routine to check it out.
    358  */
    359 int
    360 esp_isa_match(parent, match, aux)
    361 	struct device *parent;
    362 	struct cfdata *match;
    363 	void *aux;
    364 {
    365 	struct isa_attach_args *ia = aux;
    366 	bus_space_tag_t iot = ia->ia_iot;
    367 	bus_space_handle_t ioh;
    368 	struct esp_probe_data epd;
    369 	int rv;
    370 
    371 	ESP_TRACE(("[esp_isa_match] "));
    372 
    373 	if (ia->ia_iobase != 0x230 && ia->ia_iobase != 0x330)
    374 		return 0;
    375 
    376 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh))
    377 		return 0;
    378 
    379 	rv = esp_find(iot, ioh, &epd);
    380 
    381 	bus_space_unmap(iot, ioh, ESP_ISA_IOSIZE);
    382 
    383 	if (rv) {
    384 		if (ia->ia_irq != IRQUNK && ia->ia_irq != epd.sc_irq) {
    385 #ifdef DIAGNOSTIC
    386 		printf("esp_isa_match: configured IRQ (%0d) does not "
    387 		       "match board IRQ (%0d), device not configured\n",
    388 		       ia->ia_irq, epd.sc_irq);
    389 #endif
    390 			return 0;
    391 		}
    392 		ia->ia_irq = epd.sc_irq;
    393 		ia->ia_msize = 0;
    394 		ia->ia_iosize = ESP_ISA_IOSIZE;
    395 	}
    396 	return (rv);
    397 }
    398 
    399 /*
    400  * Attach this instance, and then all the sub-devices
    401  */
    402 void
    403 esp_isa_attach(parent, self, aux)
    404 	struct device *parent, *self;
    405 	void *aux;
    406 {
    407 	struct isa_attach_args *ia = aux;
    408 	struct esp_softc *esc = (void *)self;
    409 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    410 	bus_space_tag_t iot = ia->ia_iot;
    411 	bus_space_handle_t ioh;
    412 	struct esp_probe_data epd;
    413 	isa_chipset_tag_t ic = ia->ia_ic;
    414 	int error;
    415 
    416 	printf("\n");
    417 	ESP_TRACE(("[esp_isa_attach] "));
    418 
    419 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh)) {
    420 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    421 		return;
    422 	}
    423 
    424 	if (!esp_find(iot, ioh, &epd)) {
    425 		printf("%s: esp_find failed\n", sc->sc_dev.dv_xname);
    426 		return;
    427 	}
    428 
    429 	if (ia->ia_drq != DRQUNK) {
    430 		if ((error = isa_dmacascade(ic, ia->ia_drq)) != 0) {
    431 			printf("%s: unable to cascade DRQ, error = %d\n",
    432 			    sc->sc_dev.dv_xname, error);
    433 			return;
    434 		}
    435 	}
    436 
    437 	esc->sc_ih = isa_intr_establish(ic, ia->ia_irq, IST_EDGE, IPL_BIO,
    438 	    (int (*)(void *))ncr53c9x_intr, esc);
    439 	if (esc->sc_ih == NULL) {
    440 		printf("%s: couldn't establish interrupt\n",
    441 		    sc->sc_dev.dv_xname);
    442 		return;
    443 	}
    444 
    445 	esp_init(esc, &epd);
    446 
    447 	esc->sc_ioh = ioh;
    448 	esc->sc_iot = iot;
    449 
    450 	printf("%s:%ssync,%sparity\n", sc->sc_dev.dv_xname,
    451 	    epd.sc_sync ? " " : " no ", epd.sc_parity ? " " : " no ");
    452 	printf("%s", sc->sc_dev.dv_xname);
    453 
    454 	/*
    455 	 * Now try to attach all the sub-devices
    456 	 */
    457 	ncr53c9x_attach(sc, &esp_switch, &esp_dev);
    458 }
    459 
    460 /*
    461  * Glue functions.
    462  */
    463 u_char
    464 esp_read_reg(sc, reg)
    465 	struct ncr53c9x_softc *sc;
    466 	int reg;
    467 {
    468 	struct esp_softc *esc = (struct esp_softc *)sc;
    469 	u_char v;
    470 
    471 	v =  bus_space_read_1(esc->sc_iot, esc->sc_ioh, reg);
    472 
    473 	ESP_REGS(("[esp_read_reg CRS%c 0x%02x=0x%02x] ",
    474 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    475 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    476 
    477 	return v;
    478 }
    479 
    480 void
    481 esp_write_reg(sc, reg, val)
    482 	struct ncr53c9x_softc *sc;
    483 	int reg;
    484 	u_char val;
    485 {
    486 	struct esp_softc *esc = (struct esp_softc *)sc;
    487 	u_char v = val;
    488 
    489 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    490 		v = NCRCMD_TRANS;
    491 	}
    492 
    493 	ESP_REGS(("[esp_write_reg CRS%c 0x%02x=0x%02x] ",
    494 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    495 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    496 
    497 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, reg, v);
    498 }
    499 
    500 int
    501 esp_dma_isintr(sc)
    502 	struct ncr53c9x_softc *sc;
    503 {
    504 	ESP_TRACE(("[esp_dma_isintr] "));
    505 
    506 	return NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT;
    507 }
    508 
    509 void
    510 esp_dma_reset(sc)
    511 	struct ncr53c9x_softc *sc;
    512 {
    513 	struct esp_softc *esc = (struct esp_softc *)sc;
    514 
    515 	ESP_TRACE(("[esp_dma_reset] "));
    516 
    517 	esc->sc_active = 0;
    518 	esc->sc_tc = 0;
    519 }
    520 
    521 int
    522 esp_dma_intr(sc)
    523 	struct ncr53c9x_softc *sc;
    524 {
    525 	struct esp_softc *esc = (struct esp_softc *)sc;
    526 	u_char	*p;
    527 	u_int	espphase, espstat, espintr;
    528 	int	cnt;
    529 
    530 	ESP_TRACE(("[esp_dma_intr] "));
    531 
    532 	if (esc->sc_active == 0) {
    533 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    534 		return -1;
    535 	}
    536 
    537 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    538 		esc->sc_active = 0;
    539 		return 0;
    540 	}
    541 
    542 	cnt = *esc->sc_pdmalen;
    543 	if (*esc->sc_pdmalen == 0) {
    544 		printf("%s: data interrupt, but no count left\n",
    545 		    sc->sc_dev.dv_xname);
    546 	}
    547 
    548 	p = *esc->sc_dmaaddr;
    549 	espphase = sc->sc_phase;
    550 	espstat = (u_int) sc->sc_espstat;
    551 	espintr = (u_int) sc->sc_espintr;
    552 	do {
    553 		if (esc->sc_datain) {
    554 			*p++ = NCR_READ_REG(sc, NCR_FIFO);
    555 			cnt--;
    556 			if (espphase == DATA_IN_PHASE) {
    557 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    558 			} else {
    559 				esc->sc_active = 0;
    560 			}
    561 	 	} else {
    562 			if (   (espphase == DATA_OUT_PHASE)
    563 			    || (espphase == MESSAGE_OUT_PHASE)) {
    564 				NCR_WRITE_REG(sc, NCR_FIFO, *p++);
    565 				cnt--;
    566 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    567 			} else {
    568 				esc->sc_active = 0;
    569 			}
    570 		}
    571 
    572 		if (esc->sc_active) {
    573 			while (!(NCR_READ_REG(sc, NCR_STAT) & 0x80));
    574 			espstat = NCR_READ_REG(sc, NCR_STAT);
    575 			espintr = NCR_READ_REG(sc, NCR_INTR);
    576 			espphase = (espintr & NCRINTR_DIS)
    577 				    ? /* Disconnected */ BUSFREE_PHASE
    578 				    : espstat & PHASE_MASK;
    579 		}
    580 	} while (esc->sc_active && espintr);
    581 	sc->sc_phase = espphase;
    582 	sc->sc_espstat = (u_char) espstat;
    583 	sc->sc_espintr = (u_char) espintr;
    584 	*esc->sc_dmaaddr = p;
    585 	*esc->sc_pdmalen = cnt;
    586 
    587 	if (*esc->sc_pdmalen == 0) {
    588 		esc->sc_tc = NCRSTAT_TC;
    589 	}
    590 	sc->sc_espstat |= esc->sc_tc;
    591 	return 0;
    592 }
    593 
    594 int
    595 esp_dma_setup(sc, addr, len, datain, dmasize)
    596 	struct ncr53c9x_softc *sc;
    597 	caddr_t *addr;
    598 	size_t *len;
    599 	int datain;
    600 	size_t *dmasize;
    601 {
    602 	struct esp_softc *esc = (struct esp_softc *)sc;
    603 
    604 	ESP_TRACE(("[esp_dma_setup] "));
    605 
    606 	esc->sc_dmaaddr = addr;
    607 	esc->sc_pdmalen = len;
    608 	esc->sc_datain = datain;
    609 	esc->sc_dmasize = *dmasize;
    610 	esc->sc_tc = 0;
    611 
    612 	return 0;
    613 }
    614 
    615 void
    616 esp_dma_go(sc)
    617 	struct ncr53c9x_softc *sc;
    618 {
    619 	struct esp_softc *esc = (struct esp_softc *)sc;
    620 
    621 	ESP_TRACE(("[esp_dma_go] "));
    622 
    623 	esc->sc_active = 1;
    624 }
    625 
    626 void
    627 esp_dma_stop(sc)
    628 	struct ncr53c9x_softc *sc;
    629 {
    630 	ESP_TRACE(("[esp_dma_stop] "));
    631 }
    632 
    633 int
    634 esp_dma_isactive(sc)
    635 	struct ncr53c9x_softc *sc;
    636 {
    637 	struct esp_softc *esc = (struct esp_softc *)sc;
    638 
    639 	ESP_TRACE(("[esp_dma_isactive] "));
    640 
    641 	return esc->sc_active;
    642 }
    643