Home | History | Annotate | Line # | Download | only in mca
esp_mca.c revision 1.1
      1  1.1  jdolecek /*	$NetBSD: esp_mca.c,v 1.1 2001/12/01 10:42:38 jdolecek Exp $	*/
      2  1.1  jdolecek 
      3  1.1  jdolecek /*-
      4  1.1  jdolecek  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
      5  1.1  jdolecek  * All rights reserved.
      6  1.1  jdolecek  *
      7  1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  jdolecek  * by Charles M. Hannum, Jason R. Thorpe of the Numerical Aerospace
      9  1.1  jdolecek  * Simulation Facility, NASA Ames Research Center and Jaromir Dolecek.
     10  1.1  jdolecek  *
     11  1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     12  1.1  jdolecek  * modification, are permitted provided that the following conditions
     13  1.1  jdolecek  * are met:
     14  1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     15  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     16  1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     19  1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     20  1.1  jdolecek  *    must display the following acknowledgement:
     21  1.1  jdolecek  *	This product includes software developed by the NetBSD
     22  1.1  jdolecek  *	Foundation, Inc. and its contributors.
     23  1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     25  1.1  jdolecek  *    from this software without specific prior written permission.
     26  1.1  jdolecek  *
     27  1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  jdolecek  */
     39  1.1  jdolecek 
     40  1.1  jdolecek /*
     41  1.1  jdolecek  * Copyright (c) 1994 Peter Galbavy
     42  1.1  jdolecek  * All rights reserved.
     43  1.1  jdolecek  *
     44  1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     45  1.1  jdolecek  * modification, are permitted provided that the following conditions
     46  1.1  jdolecek  * are met:
     47  1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     48  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     49  1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     51  1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     52  1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     53  1.1  jdolecek  *    must display the following acknowledgement:
     54  1.1  jdolecek  *	This product includes software developed by Peter Galbavy
     55  1.1  jdolecek  * 4. The name of the author may not be used to endorse or promote products
     56  1.1  jdolecek  *    derived from this software without specific prior written permission.
     57  1.1  jdolecek  *
     58  1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  1.1  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     60  1.1  jdolecek  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     61  1.1  jdolecek  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     62  1.1  jdolecek  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     63  1.1  jdolecek  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     64  1.1  jdolecek  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     66  1.1  jdolecek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     67  1.1  jdolecek  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     68  1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     69  1.1  jdolecek  */
     70  1.1  jdolecek 
     71  1.1  jdolecek /*
     72  1.1  jdolecek  * Based on aic6360 by Jarle Greipsland
     73  1.1  jdolecek  *
     74  1.1  jdolecek  * Acknowledgements: Many of the algorithms used in this driver are
     75  1.1  jdolecek  * inspired by the work of Julian Elischer (julian (at) tfs.com) and
     76  1.1  jdolecek  * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu).  Thanks a million!
     77  1.1  jdolecek  */
     78  1.1  jdolecek 
     79  1.1  jdolecek /*
     80  1.1  jdolecek  * Grabbed from the sparc port at revision 1.73 for the NeXT.
     81  1.1  jdolecek  * Darrin B. Jewell <dbj (at) netbsd.org>  Sat Jul  4 15:41:32 1998
     82  1.1  jdolecek  */
     83  1.1  jdolecek 
     84  1.1  jdolecek /*
     85  1.1  jdolecek  * XXX This MCA attachment for NCR 53C90 does not work yet.
     86  1.1  jdolecek  * After attach, the NCR_INTR gets set according to previously
     87  1.1  jdolecek  * done Bus Reset, but interrupts are generated later on, so this
     88  1.1  jdolecek  * stalls on boot waiting for the device detection stuff to finish.
     89  1.1  jdolecek  * It seem like the device needs some special EOI handling, to tell
     90  1.1  jdolecek  * it that it can send another interrupt. I need real NCR53C90 docs,
     91  1.1  jdolecek  * which I don't have currently.
     92  1.1  jdolecek  * jdolecek 20011201
     93  1.1  jdolecek  */
     94  1.1  jdolecek #error this driver does not work
     95  1.1  jdolecek 
     96  1.1  jdolecek #include <sys/types.h>
     97  1.1  jdolecek #include <sys/param.h>
     98  1.1  jdolecek #include <sys/systm.h>
     99  1.1  jdolecek #include <sys/kernel.h>
    100  1.1  jdolecek #include <sys/errno.h>
    101  1.1  jdolecek #include <sys/ioctl.h>
    102  1.1  jdolecek #include <sys/device.h>
    103  1.1  jdolecek #include <sys/buf.h>
    104  1.1  jdolecek #include <sys/proc.h>
    105  1.1  jdolecek #include <sys/user.h>
    106  1.1  jdolecek #include <sys/queue.h>
    107  1.1  jdolecek 
    108  1.1  jdolecek #include <dev/scsipi/scsi_all.h>
    109  1.1  jdolecek #include <dev/scsipi/scsipi_all.h>
    110  1.1  jdolecek #include <dev/scsipi/scsiconf.h>
    111  1.1  jdolecek #include <dev/scsipi/scsi_message.h>
    112  1.1  jdolecek 
    113  1.1  jdolecek #include <machine/bus.h>
    114  1.1  jdolecek #include <machine/cpu.h>
    115  1.1  jdolecek 
    116  1.1  jdolecek #include <dev/ic/ncr53c9xreg.h>
    117  1.1  jdolecek #include <dev/ic/ncr53c9xvar.h>
    118  1.1  jdolecek 
    119  1.1  jdolecek #include <dev/mca/espvar.h>
    120  1.1  jdolecek 
    121  1.1  jdolecek #include <dev/mca/mcavar.h>
    122  1.1  jdolecek #include <dev/mca/mcareg.h>
    123  1.1  jdolecek #include <dev/mca/mcadevs.h>
    124  1.1  jdolecek 
    125  1.1  jdolecek #if defined(DEBUG) && !defined(NCR53C9X_DEBUG)
    126  1.1  jdolecek #define NCR53C9X_DEBUG
    127  1.1  jdolecek #endif
    128  1.1  jdolecek 
    129  1.1  jdolecek #ifdef NCR53C9X_DEBUG
    130  1.1  jdolecek static int esp_mca_debug = 1;
    131  1.1  jdolecek #define DPRINTF(x) if (esp_mca_debug) printf x;
    132  1.1  jdolecek #else
    133  1.1  jdolecek #define DPRINTF(x)
    134  1.1  jdolecek #endif
    135  1.1  jdolecek 
    136  1.1  jdolecek #define ESP_MCA_IOSIZE  0x20
    137  1.1  jdolecek 
    138  1.1  jdolecek static void	esp_mca_attach	__P((struct device *, struct device *, void *));
    139  1.1  jdolecek static int	esp_mca_match	__P((struct device *, struct cfdata *, void *));
    140  1.1  jdolecek 
    141  1.1  jdolecek /* Linkup to the rest of the kernel */
    142  1.1  jdolecek struct cfattach esp_mca_ca = {
    143  1.1  jdolecek 	sizeof(struct esp_softc), esp_mca_match, esp_mca_attach
    144  1.1  jdolecek };
    145  1.1  jdolecek 
    146  1.1  jdolecek /*
    147  1.1  jdolecek  * Functions and the switch for the MI code.
    148  1.1  jdolecek  */
    149  1.1  jdolecek static u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    150  1.1  jdolecek static void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    151  1.1  jdolecek static int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    152  1.1  jdolecek static void	esp_dma_reset __P((struct ncr53c9x_softc *));
    153  1.1  jdolecek static int	esp_dma_intr __P((struct ncr53c9x_softc *));
    154  1.1  jdolecek static int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    155  1.1  jdolecek 	    size_t *, int, size_t *));
    156  1.1  jdolecek static void	esp_dma_go __P((struct ncr53c9x_softc *));
    157  1.1  jdolecek static void	esp_dma_stop __P((struct ncr53c9x_softc *));
    158  1.1  jdolecek static int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    159  1.1  jdolecek 
    160  1.1  jdolecek static struct ncr53c9x_glue esp_glue = {
    161  1.1  jdolecek 	esp_read_reg,
    162  1.1  jdolecek 	esp_write_reg,
    163  1.1  jdolecek 	esp_dma_isintr,
    164  1.1  jdolecek 	esp_dma_reset,
    165  1.1  jdolecek 	esp_dma_intr,
    166  1.1  jdolecek 	esp_dma_setup,
    167  1.1  jdolecek 	esp_dma_go,
    168  1.1  jdolecek 	esp_dma_stop,
    169  1.1  jdolecek 	esp_dma_isactive,
    170  1.1  jdolecek 	NULL,			/* gl_clear_latched_intr */
    171  1.1  jdolecek };
    172  1.1  jdolecek 
    173  1.1  jdolecek static int
    174  1.1  jdolecek esp_mca_match(parent, cf, aux)
    175  1.1  jdolecek 	struct device *parent;
    176  1.1  jdolecek 	struct cfdata *cf;
    177  1.1  jdolecek 	void *aux;
    178  1.1  jdolecek {
    179  1.1  jdolecek 	struct mca_attach_args *ma = aux;
    180  1.1  jdolecek 
    181  1.1  jdolecek 	switch (ma->ma_id) {
    182  1.1  jdolecek 	case MCA_PRODUCT_NCR53C90:
    183  1.1  jdolecek 		return 1;
    184  1.1  jdolecek 	}
    185  1.1  jdolecek 
    186  1.1  jdolecek 	return 0;
    187  1.1  jdolecek }
    188  1.1  jdolecek 
    189  1.1  jdolecek static void
    190  1.1  jdolecek esp_mca_attach(parent, self, aux)
    191  1.1  jdolecek 	struct device *parent, *self;
    192  1.1  jdolecek 	void *aux;
    193  1.1  jdolecek {
    194  1.1  jdolecek 	struct mca_attach_args *ma = aux;
    195  1.1  jdolecek 	struct esp_softc *esc = (void *)self;
    196  1.1  jdolecek 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    197  1.1  jdolecek 	int iobase, scsi_id, irq, drq, error;
    198  1.1  jdolecek 	bus_space_handle_t ioh;
    199  1.1  jdolecek 	int pos2, pos3, pos5;
    200  1.1  jdolecek 
    201  1.1  jdolecek 	static const int ncrmca_iobase[] = {
    202  1.1  jdolecek 		0, 0x240, 0x340, 0x400, 0x420, 0x3240, 0x8240, 0xa240
    203  1.1  jdolecek 	};
    204  1.1  jdolecek 
    205  1.1  jdolecek 	/*
    206  1.1  jdolecek 	 * NCR SCSI Adapter (ADF 7f4f)
    207  1.1  jdolecek 	 *
    208  1.1  jdolecek 	 * POS register 2: (adf pos0)
    209  1.1  jdolecek 	 *
    210  1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    211  1.1  jdolecek 	 *     \_/ \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
    212  1.1  jdolecek 	 *      |      \____ I/O base (32B): 001=0x240 010=0x340 011=0x400
    213  1.1  jdolecek 	 *      |              100=0x420 101=0x3240 110=0x8240 111=0xa240
    214  1.1  jdolecek 	 *       \__________ IRQ: 00=3 01=5 10=7 11=9
    215  1.1  jdolecek 	 *
    216  1.1  jdolecek 	 * POS register 3: (adf pos1)
    217  1.1  jdolecek 	 *
    218  1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    219  1.1  jdolecek 	 * 1 1 1 | \_____/
    220  1.1  jdolecek 	 *       |       \__ DMA level
    221  1.1  jdolecek 	 *        \_________ Fairness: 1=enabled 0=disabled
    222  1.1  jdolecek 	 *
    223  1.1  jdolecek 	 * POS register 5: (adf pos3)
    224  1.1  jdolecek 	 *
    225  1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    226  1.1  jdolecek 	 * 1   |     \___/
    227  1.1  jdolecek 	 *     |         \__ Static Ram: 0xC8000-0xC87FF + XX*0x4000
    228  1.1  jdolecek 	 *      \___________ Host Adapter ID: 1=7 0=6
    229  1.1  jdolecek 	 */
    230  1.1  jdolecek 
    231  1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    232  1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    233  1.1  jdolecek 	pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
    234  1.1  jdolecek 
    235  1.1  jdolecek 	iobase = ncrmca_iobase[(pos2 & 0x0e) >> 1];
    236  1.1  jdolecek 	irq = 3 + 2*((pos2 & 0x30) >> 4);
    237  1.1  jdolecek 	drq = (pos3 & 0x0f);
    238  1.1  jdolecek 	scsi_id = 6 + ((pos5 & 0x20) ? 1 : 0);
    239  1.1  jdolecek 
    240  1.1  jdolecek 	printf(" slot %d irq %d drq %d: NCR SCSI Adapter (53C90)\n",
    241  1.1  jdolecek 		ma->ma_slot + 1, irq, drq);
    242  1.1  jdolecek 
    243  1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, ESP_MCA_IOSIZE, 0, &ioh)) {
    244  1.1  jdolecek 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    245  1.1  jdolecek 		return;
    246  1.1  jdolecek 	}
    247  1.1  jdolecek 
    248  1.1  jdolecek 	esc->sc_iot = ma->ma_iot;
    249  1.1  jdolecek 	esc->sc_ioh = ioh;
    250  1.1  jdolecek 
    251  1.1  jdolecek 	/* Setup DMA map */
    252  1.1  jdolecek 	esc->sc_dmat = ma->ma_dmat;
    253  1.1  jdolecek 	if ((error = mca_dmamap_create(esc->sc_dmat, MAXPHYS,
    254  1.1  jdolecek             BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &esc->sc_xfer, drq)) != 0){
    255  1.1  jdolecek                 printf("%s: couldn't create DMA map - error %d\n",
    256  1.1  jdolecek                         sc->sc_dev.dv_xname, error);
    257  1.1  jdolecek                 return;
    258  1.1  jdolecek         }
    259  1.1  jdolecek 
    260  1.1  jdolecek 	sc->sc_id = scsi_id;
    261  1.1  jdolecek 	sc->sc_freq = 20;		/* Mhz */
    262  1.1  jdolecek 
    263  1.1  jdolecek 	/*
    264  1.1  jdolecek 	 * Set up glue for MI code early; we use some of it here.
    265  1.1  jdolecek 	 */
    266  1.1  jdolecek 	sc->sc_glue = &esp_glue;
    267  1.1  jdolecek 
    268  1.1  jdolecek 	/*
    269  1.1  jdolecek 	 * It is necessary to try to load the 2nd config register here,
    270  1.1  jdolecek 	 * to find out what rev the esp chip is, else the ncr53c9x_reset
    271  1.1  jdolecek 	 * will not set up the defaults correctly.
    272  1.1  jdolecek 	 */
    273  1.1  jdolecek 	sc->sc_cfg1 = sc->sc_id;
    274  1.1  jdolecek 	sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE | NCRCFG2_DPE;
    275  1.1  jdolecek 	/* No point setting sc_cfg[345], they won't be used */
    276  1.1  jdolecek 
    277  1.1  jdolecek 	sc->sc_rev = NCR_VARIANT_ESP100;
    278  1.1  jdolecek 	sc->sc_minsync = 0;
    279  1.1  jdolecek 
    280  1.1  jdolecek 	/* max 64KB DMA */
    281  1.1  jdolecek 	sc->sc_maxxfer = 64 * 1024;
    282  1.1  jdolecek 
    283  1.1  jdolecek 	/* Establish interrupt */
    284  1.1  jdolecek 	esc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_BIO, ncr53c9x_intr,
    285  1.1  jdolecek 			esc);
    286  1.1  jdolecek 	if (esc->sc_ih == NULL) {
    287  1.1  jdolecek 		printf("%s: couldn't establish interrupt\n",
    288  1.1  jdolecek 		    sc->sc_dev.dv_xname);
    289  1.1  jdolecek 		return;
    290  1.1  jdolecek 	}
    291  1.1  jdolecek 
    292  1.1  jdolecek 	/*
    293  1.1  jdolecek 	 * Now try to attach all the sub-devices
    294  1.1  jdolecek 	 */
    295  1.1  jdolecek 	sc->sc_adapter.adapt_minphys = minphys;
    296  1.1  jdolecek 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    297  1.1  jdolecek 
    298  1.1  jdolecek 	/* Do the common parts of attachment. */
    299  1.1  jdolecek 	printf("%s", sc->sc_dev.dv_xname);
    300  1.1  jdolecek 	ncr53c9x_attach(sc);
    301  1.1  jdolecek 
    302  1.1  jdolecek 	/* Wait until the SCSI Bus Reset completes */
    303  1.1  jdolecek 	while((NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT) == 0)
    304  1.1  jdolecek 		DELAY(10);
    305  1.1  jdolecek 	ncr53c9x_intr(sc);
    306  1.1  jdolecek }
    307  1.1  jdolecek 
    308  1.1  jdolecek /*
    309  1.1  jdolecek  * Glue functions.
    310  1.1  jdolecek  */
    311  1.1  jdolecek 
    312  1.1  jdolecek static u_char
    313  1.1  jdolecek esp_read_reg(sc, reg)
    314  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    315  1.1  jdolecek 	int reg;
    316  1.1  jdolecek {
    317  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    318  1.1  jdolecek 
    319  1.1  jdolecek 	return (bus_space_read_1(esc->sc_iot, esc->sc_ioh, reg));
    320  1.1  jdolecek }
    321  1.1  jdolecek 
    322  1.1  jdolecek static void
    323  1.1  jdolecek esp_write_reg(sc, reg, val)
    324  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    325  1.1  jdolecek 	int reg;
    326  1.1  jdolecek 	u_char val;
    327  1.1  jdolecek {
    328  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    329  1.1  jdolecek 
    330  1.1  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, reg, val);
    331  1.1  jdolecek }
    332  1.1  jdolecek 
    333  1.1  jdolecek static int
    334  1.1  jdolecek esp_dma_isintr(sc)
    335  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    336  1.1  jdolecek {
    337  1.1  jdolecek 	DPRINTF(("[esp_dma_isintr] "));
    338  1.1  jdolecek 	return (NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT);
    339  1.1  jdolecek }
    340  1.1  jdolecek 
    341  1.1  jdolecek static void
    342  1.1  jdolecek esp_dma_reset(sc)
    343  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    344  1.1  jdolecek {
    345  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    346  1.1  jdolecek 
    347  1.1  jdolecek 	DPRINTF(("[esp_dma_reset] "));
    348  1.1  jdolecek 
    349  1.1  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    350  1.1  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    351  1.1  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    352  1.1  jdolecek 	}
    353  1.1  jdolecek }
    354  1.1  jdolecek 
    355  1.1  jdolecek static int
    356  1.1  jdolecek esp_dma_intr(sc)
    357  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    358  1.1  jdolecek {
    359  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    360  1.1  jdolecek 	DPRINTF(("[esp_dma_intr] "));
    361  1.1  jdolecek 
    362  1.1  jdolecek 	if ((esc->sc_flags & ESP_XFER_ACTIVE) == 0) {
    363  1.1  jdolecek 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    364  1.1  jdolecek 		return (-1);
    365  1.1  jdolecek 	}
    366  1.1  jdolecek 
    367  1.1  jdolecek 	if ((sc->sc_espintr & NCRINTR_BS) == 0)
    368  1.1  jdolecek 		goto ok;
    369  1.1  jdolecek 
    370  1.1  jdolecek 	/* do something */
    371  1.1  jdolecek 
    372  1.1  jdolecek     ok:
    373  1.1  jdolecek 	esc->sc_flags &= ~ESP_XFER_ACTIVE;
    374  1.1  jdolecek 	return (0);
    375  1.1  jdolecek }
    376  1.1  jdolecek 
    377  1.1  jdolecek /*
    378  1.1  jdolecek  * Setup DMA transfer.
    379  1.1  jdolecek  */
    380  1.1  jdolecek static int
    381  1.1  jdolecek esp_dma_setup(sc, addr, len, datain, dmasize)
    382  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    383  1.1  jdolecek 	caddr_t *addr;
    384  1.1  jdolecek 	size_t *len;
    385  1.1  jdolecek 	int datain;
    386  1.1  jdolecek 	size_t *dmasize;
    387  1.1  jdolecek {
    388  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    389  1.1  jdolecek 	int error;
    390  1.1  jdolecek 	int fl;
    391  1.1  jdolecek 
    392  1.1  jdolecek 	DPRINTF(("[esp_dma_setup] "));
    393  1.1  jdolecek 
    394  1.1  jdolecek 	/* Load the buffer for DMA transfer. */
    395  1.1  jdolecek 	fl = (datain) ? BUS_DMA_READ : BUS_DMA_WRITE;
    396  1.1  jdolecek 
    397  1.1  jdolecek 	if ((error = bus_dmamap_load(esc->sc_dmat, esc->sc_xfer, *addr,
    398  1.1  jdolecek 	    *len, NULL, BUS_DMA_STREAMING|fl))) {
    399  1.1  jdolecek 		printf("%s: esp_dma_setup: unable to load DMA buffer - error %d\n",
    400  1.1  jdolecek 			sc->sc_dev.dv_xname, error);
    401  1.1  jdolecek 		return (error);
    402  1.1  jdolecek 	}
    403  1.1  jdolecek 
    404  1.1  jdolecek 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
    405  1.1  jdolecek 		*len, (datain) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    406  1.1  jdolecek 
    407  1.1  jdolecek 	esc->sc_flags |= ESP_XFER_LOADED;
    408  1.1  jdolecek 
    409  1.1  jdolecek 	return (0);
    410  1.1  jdolecek }
    411  1.1  jdolecek 
    412  1.1  jdolecek static void
    413  1.1  jdolecek esp_dma_go(sc)
    414  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    415  1.1  jdolecek {
    416  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    417  1.1  jdolecek 	DPRINTF(("[esp_dma_go] "));
    418  1.1  jdolecek 
    419  1.1  jdolecek 	esc->sc_flags |= ESP_XFER_ACTIVE;
    420  1.1  jdolecek }
    421  1.1  jdolecek 
    422  1.1  jdolecek static void
    423  1.1  jdolecek esp_dma_stop(sc)
    424  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    425  1.1  jdolecek {
    426  1.1  jdolecek 	DPRINTF(("[esp_dma_stop] "));
    427  1.1  jdolecek 
    428  1.1  jdolecek 	panic("%s: stop not yet implemented", sc->sc_dev.dv_xname);
    429  1.1  jdolecek }
    430  1.1  jdolecek 
    431  1.1  jdolecek static int
    432  1.1  jdolecek esp_dma_isactive(sc)
    433  1.1  jdolecek 	struct ncr53c9x_softc *sc;
    434  1.1  jdolecek {
    435  1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    436  1.1  jdolecek 	DPRINTF(("[esp_dma_isactive] "));
    437  1.1  jdolecek 
    438  1.1  jdolecek 	return ((esc->sc_flags & ESP_XFER_ACTIVE) != 0);
    439  1.1  jdolecek }
    440