Home | History | Annotate | Line # | Download | only in mca
esp_mca.c revision 1.12.10.1
      1  1.12.10.1      yamt /*	$NetBSD: esp_mca.c,v 1.12.10.1 2006/10/22 06:06:12 yamt Exp $	*/
      2        1.1  jdolecek 
      3        1.1  jdolecek /*-
      4        1.3  jdolecek  * Copyright (c) 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.3  jdolecek  * by Jaromir Dolecek <jdolecek (at) NetBSD.org>.
      9        1.1  jdolecek  *
     10        1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11        1.1  jdolecek  * modification, are permitted provided that the following conditions
     12        1.1  jdolecek  * are met:
     13        1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15        1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18        1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19        1.1  jdolecek  *    must display the following acknowledgement:
     20        1.1  jdolecek  *	This product includes software developed by the NetBSD
     21        1.1  jdolecek  *	Foundation, Inc. and its contributors.
     22        1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     24        1.1  jdolecek  *    from this software without specific prior written permission.
     25        1.1  jdolecek  *
     26        1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37        1.1  jdolecek  */
     38        1.1  jdolecek 
     39        1.1  jdolecek /*
     40        1.2  jdolecek  * Driver for NCR 53c90, MCA version, with 86c01 DMA controller chip.
     41        1.9     perry  *
     42        1.2  jdolecek  * Some of the information used to write this driver was taken
     43        1.2  jdolecek  * from Tymm Twillman <tymm (at) computer.org>'s Linux MCA NC53c90 driver,
     44        1.2  jdolecek  * in drivers/scsi/mca_53c9x.c
     45        1.1  jdolecek  */
     46        1.7     lukem 
     47        1.7     lukem #include <sys/cdefs.h>
     48  1.12.10.1      yamt __KERNEL_RCSID(0, "$NetBSD: esp_mca.c,v 1.12.10.1 2006/10/22 06:06:12 yamt Exp $");
     49        1.1  jdolecek 
     50        1.1  jdolecek #include <sys/types.h>
     51        1.1  jdolecek #include <sys/param.h>
     52        1.1  jdolecek #include <sys/systm.h>
     53        1.1  jdolecek #include <sys/kernel.h>
     54        1.1  jdolecek #include <sys/errno.h>
     55        1.1  jdolecek #include <sys/ioctl.h>
     56        1.1  jdolecek #include <sys/device.h>
     57        1.1  jdolecek #include <sys/buf.h>
     58        1.1  jdolecek #include <sys/proc.h>
     59        1.1  jdolecek #include <sys/user.h>
     60        1.1  jdolecek #include <sys/queue.h>
     61        1.1  jdolecek 
     62        1.1  jdolecek #include <dev/scsipi/scsi_all.h>
     63        1.1  jdolecek #include <dev/scsipi/scsipi_all.h>
     64        1.1  jdolecek #include <dev/scsipi/scsiconf.h>
     65        1.1  jdolecek #include <dev/scsipi/scsi_message.h>
     66        1.1  jdolecek 
     67        1.1  jdolecek #include <machine/bus.h>
     68        1.1  jdolecek #include <machine/cpu.h>
     69        1.1  jdolecek 
     70        1.1  jdolecek #include <dev/ic/ncr53c9xreg.h>
     71        1.1  jdolecek #include <dev/ic/ncr53c9xvar.h>
     72        1.1  jdolecek 
     73        1.1  jdolecek #include <dev/mca/espvar.h>
     74        1.2  jdolecek #include <dev/mca/espreg.h>
     75        1.1  jdolecek 
     76        1.1  jdolecek #include <dev/mca/mcavar.h>
     77        1.1  jdolecek #include <dev/mca/mcareg.h>
     78        1.1  jdolecek #include <dev/mca/mcadevs.h>
     79        1.1  jdolecek 
     80        1.2  jdolecek #if 0
     81        1.1  jdolecek #if defined(DEBUG) && !defined(NCR53C9X_DEBUG)
     82        1.1  jdolecek #define NCR53C9X_DEBUG
     83        1.1  jdolecek #endif
     84        1.2  jdolecek #endif
     85        1.1  jdolecek 
     86        1.1  jdolecek #ifdef NCR53C9X_DEBUG
     87        1.2  jdolecek static int esp_mca_debug = 0;
     88        1.1  jdolecek #define DPRINTF(x) if (esp_mca_debug) printf x;
     89        1.1  jdolecek #else
     90        1.1  jdolecek #define DPRINTF(x)
     91        1.1  jdolecek #endif
     92        1.1  jdolecek 
     93        1.1  jdolecek #define ESP_MCA_IOSIZE  0x20
     94        1.2  jdolecek #define ESP_REG_OFFSET	0x10
     95        1.1  jdolecek 
     96        1.8     perry static void	esp_mca_attach(struct device *, struct device *, void *);
     97        1.8     perry static int	esp_mca_match(struct device *, struct cfdata *, void *);
     98        1.1  jdolecek 
     99        1.5   thorpej CFATTACH_DECL(esp_mca, sizeof(struct esp_softc),
    100        1.6   thorpej     esp_mca_match, esp_mca_attach, NULL, NULL);
    101        1.1  jdolecek 
    102        1.1  jdolecek /*
    103        1.1  jdolecek  * Functions and the switch for the MI code.
    104        1.1  jdolecek  */
    105        1.8     perry static u_char	esp_read_reg(struct ncr53c9x_softc *, int);
    106        1.8     perry static void	esp_write_reg(struct ncr53c9x_softc *, int, u_char);
    107        1.8     perry static int	esp_dma_isintr(struct ncr53c9x_softc *);
    108        1.8     perry static void	esp_dma_reset(struct ncr53c9x_softc *);
    109        1.8     perry static int	esp_dma_intr(struct ncr53c9x_softc *);
    110        1.8     perry static int	esp_dma_setup(struct ncr53c9x_softc *, caddr_t *,
    111        1.8     perry 	    size_t *, int, size_t *);
    112        1.8     perry static void	esp_dma_go(struct ncr53c9x_softc *);
    113        1.8     perry static void	esp_dma_stop(struct ncr53c9x_softc *);
    114        1.8     perry static int	esp_dma_isactive(struct ncr53c9x_softc *);
    115        1.1  jdolecek 
    116        1.1  jdolecek static struct ncr53c9x_glue esp_glue = {
    117        1.1  jdolecek 	esp_read_reg,
    118        1.1  jdolecek 	esp_write_reg,
    119        1.1  jdolecek 	esp_dma_isintr,
    120        1.1  jdolecek 	esp_dma_reset,
    121        1.1  jdolecek 	esp_dma_intr,
    122        1.1  jdolecek 	esp_dma_setup,
    123        1.1  jdolecek 	esp_dma_go,
    124        1.1  jdolecek 	esp_dma_stop,
    125        1.1  jdolecek 	esp_dma_isactive,
    126        1.1  jdolecek 	NULL,			/* gl_clear_latched_intr */
    127        1.1  jdolecek };
    128        1.1  jdolecek 
    129        1.1  jdolecek static int
    130        1.1  jdolecek esp_mca_match(parent, cf, aux)
    131  1.12.10.1      yamt 	struct device *parent __unused;
    132  1.12.10.1      yamt 	struct cfdata *cf __unused;
    133        1.1  jdolecek 	void *aux;
    134        1.1  jdolecek {
    135        1.1  jdolecek 	struct mca_attach_args *ma = aux;
    136        1.1  jdolecek 
    137        1.1  jdolecek 	switch (ma->ma_id) {
    138        1.1  jdolecek 	case MCA_PRODUCT_NCR53C90:
    139        1.1  jdolecek 		return 1;
    140        1.1  jdolecek 	}
    141        1.1  jdolecek 
    142        1.1  jdolecek 	return 0;
    143        1.1  jdolecek }
    144        1.1  jdolecek 
    145        1.1  jdolecek static void
    146        1.1  jdolecek esp_mca_attach(parent, self, aux)
    147  1.12.10.1      yamt 	struct device *parent __unused;
    148  1.12.10.1      yamt 	struct device *self;
    149        1.1  jdolecek 	void *aux;
    150        1.1  jdolecek {
    151        1.1  jdolecek 	struct mca_attach_args *ma = aux;
    152       1.12   thorpej 	struct esp_softc *esc = device_private(self);
    153        1.1  jdolecek 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    154        1.2  jdolecek 	u_int16_t iobase;
    155        1.2  jdolecek 	int scsi_id, irq, drq, error;
    156        1.1  jdolecek 	bus_space_handle_t ioh;
    157        1.1  jdolecek 	int pos2, pos3, pos5;
    158        1.1  jdolecek 
    159        1.2  jdolecek 	static const u_int16_t ncrmca_iobase[] = {
    160        1.1  jdolecek 		0, 0x240, 0x340, 0x400, 0x420, 0x3240, 0x8240, 0xa240
    161        1.1  jdolecek 	};
    162        1.1  jdolecek 
    163        1.1  jdolecek 	/*
    164        1.1  jdolecek 	 * NCR SCSI Adapter (ADF 7f4f)
    165        1.1  jdolecek 	 *
    166        1.1  jdolecek 	 * POS register 2: (adf pos0)
    167        1.9     perry 	 *
    168        1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    169        1.1  jdolecek 	 *     \_/ \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
    170        1.1  jdolecek 	 *      |      \____ I/O base (32B): 001=0x240 010=0x340 011=0x400
    171        1.1  jdolecek 	 *      |              100=0x420 101=0x3240 110=0x8240 111=0xa240
    172        1.1  jdolecek 	 *       \__________ IRQ: 00=3 01=5 10=7 11=9
    173        1.1  jdolecek 	 *
    174        1.1  jdolecek 	 * POS register 3: (adf pos1)
    175        1.9     perry 	 *
    176        1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    177        1.1  jdolecek 	 * 1 1 1 | \_____/
    178        1.1  jdolecek 	 *       |       \__ DMA level
    179        1.1  jdolecek 	 *        \_________ Fairness: 1=enabled 0=disabled
    180        1.1  jdolecek 	 *
    181        1.1  jdolecek 	 * POS register 5: (adf pos3)
    182        1.9     perry 	 *
    183        1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    184        1.1  jdolecek 	 * 1   |     \___/
    185        1.1  jdolecek 	 *     |         \__ Static Ram: 0xC8000-0xC87FF + XX*0x4000
    186        1.1  jdolecek 	 *      \___________ Host Adapter ID: 1=7 0=6
    187        1.1  jdolecek 	 */
    188        1.1  jdolecek 
    189        1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    190        1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    191        1.1  jdolecek 	pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
    192        1.1  jdolecek 
    193        1.1  jdolecek 	iobase = ncrmca_iobase[(pos2 & 0x0e) >> 1];
    194        1.1  jdolecek 	irq = 3 + 2*((pos2 & 0x30) >> 4);
    195        1.1  jdolecek 	drq = (pos3 & 0x0f);
    196        1.1  jdolecek 	scsi_id = 6 + ((pos5 & 0x20) ? 1 : 0);
    197        1.1  jdolecek 
    198        1.2  jdolecek 	printf(" slot %d irq %d drq %d: NCR SCSI Adapter\n",
    199        1.1  jdolecek 		ma->ma_slot + 1, irq, drq);
    200        1.1  jdolecek 
    201        1.2  jdolecek 	/* Map the 86C01 registers */
    202        1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, ESP_MCA_IOSIZE, 0, &ioh)) {
    203        1.1  jdolecek 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    204        1.1  jdolecek 		return;
    205        1.1  jdolecek 	}
    206        1.1  jdolecek 
    207        1.1  jdolecek 	esc->sc_iot = ma->ma_iot;
    208        1.1  jdolecek 	esc->sc_ioh = ioh;
    209        1.1  jdolecek 
    210        1.2  jdolecek 	/* Submap the 'esp' registers */
    211        1.2  jdolecek 	if (bus_space_subregion(ma->ma_iot, ioh, ESP_REG_OFFSET,
    212        1.2  jdolecek 	    ESP_MCA_IOSIZE-ESP_REG_OFFSET, &esc->sc_esp_ioh)) {
    213        1.2  jdolecek 		printf("%s: can't subregion i/o space\n", sc->sc_dev.dv_xname);
    214        1.2  jdolecek 		return;
    215        1.2  jdolecek 	}
    216        1.2  jdolecek 
    217        1.1  jdolecek 	/* Setup DMA map */
    218        1.1  jdolecek 	esc->sc_dmat = ma->ma_dmat;
    219        1.1  jdolecek 	if ((error = mca_dmamap_create(esc->sc_dmat, MAXPHYS,
    220        1.2  jdolecek             BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW | MCABUS_DMA_IOPORT,
    221        1.2  jdolecek 	    &esc->sc_xfer, drq)) != 0){
    222        1.1  jdolecek                 printf("%s: couldn't create DMA map - error %d\n",
    223        1.1  jdolecek                         sc->sc_dev.dv_xname, error);
    224        1.1  jdolecek                 return;
    225        1.1  jdolecek         }
    226        1.1  jdolecek 
    227        1.2  jdolecek 	/* MI code glue */
    228        1.1  jdolecek 	sc->sc_id = scsi_id;
    229       1.11     lukem 	sc->sc_freq = 25;		/* MHz */
    230        1.1  jdolecek 
    231        1.1  jdolecek 	sc->sc_glue = &esp_glue;
    232        1.1  jdolecek 
    233        1.2  jdolecek 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB; //| NCRCFG1_SLOW;
    234        1.2  jdolecek 	/* No point setting sc_cfg[2345], they won't be used */
    235        1.1  jdolecek 
    236        1.2  jdolecek 	sc->sc_rev = NCR_VARIANT_NCR53C90_86C01;
    237        1.1  jdolecek 	sc->sc_minsync = 0;
    238        1.1  jdolecek 
    239        1.1  jdolecek 	/* max 64KB DMA */
    240        1.1  jdolecek 	sc->sc_maxxfer = 64 * 1024;
    241        1.1  jdolecek 
    242        1.1  jdolecek 	/* Establish interrupt */
    243        1.1  jdolecek 	esc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_BIO, ncr53c9x_intr,
    244        1.1  jdolecek 			esc);
    245        1.1  jdolecek 	if (esc->sc_ih == NULL) {
    246        1.1  jdolecek 		printf("%s: couldn't establish interrupt\n",
    247        1.1  jdolecek 		    sc->sc_dev.dv_xname);
    248        1.1  jdolecek 		return;
    249        1.1  jdolecek 	}
    250        1.1  jdolecek 
    251        1.1  jdolecek 	/*
    252        1.2  jdolecek 	 * Massage the 86C01 chip - setup MCA DMA controller for DMA via
    253        1.2  jdolecek 	 * the 86C01 register, and enable 86C01 interrupts.
    254        1.2  jdolecek 	 */
    255        1.2  jdolecek 	mca_dma_set_ioport(drq, iobase + N86C01_PIO);
    256        1.2  jdolecek 
    257        1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE,
    258        1.2  jdolecek 		bus_space_read_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE)
    259        1.2  jdolecek 		| N86C01_INTR_ENABLE);
    260        1.2  jdolecek 
    261        1.2  jdolecek 	/*
    262        1.1  jdolecek 	 * Now try to attach all the sub-devices
    263        1.1  jdolecek 	 */
    264        1.1  jdolecek 	sc->sc_adapter.adapt_minphys = minphys;
    265        1.1  jdolecek 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    266        1.1  jdolecek 
    267        1.1  jdolecek 	/* Do the common parts of attachment. */
    268        1.1  jdolecek 	printf("%s", sc->sc_dev.dv_xname);
    269        1.1  jdolecek 	ncr53c9x_attach(sc);
    270        1.1  jdolecek }
    271        1.1  jdolecek 
    272        1.1  jdolecek /*
    273        1.1  jdolecek  * Glue functions.
    274        1.1  jdolecek  */
    275        1.1  jdolecek 
    276        1.1  jdolecek static u_char
    277        1.1  jdolecek esp_read_reg(sc, reg)
    278        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    279        1.1  jdolecek 	int reg;
    280        1.1  jdolecek {
    281        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    282        1.1  jdolecek 
    283        1.2  jdolecek 	return (bus_space_read_1(esc->sc_iot, esc->sc_esp_ioh, reg));
    284        1.1  jdolecek }
    285        1.1  jdolecek 
    286        1.1  jdolecek static void
    287        1.1  jdolecek esp_write_reg(sc, reg, val)
    288        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    289        1.1  jdolecek 	int reg;
    290        1.1  jdolecek 	u_char val;
    291        1.1  jdolecek {
    292        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    293        1.1  jdolecek 
    294        1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_esp_ioh, reg, val);
    295        1.1  jdolecek }
    296        1.1  jdolecek 
    297        1.1  jdolecek static int
    298        1.1  jdolecek esp_dma_isintr(sc)
    299        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    300        1.1  jdolecek {
    301        1.2  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    302        1.2  jdolecek 
    303        1.1  jdolecek 	DPRINTF(("[esp_dma_isintr] "));
    304        1.2  jdolecek 	return (bus_space_read_1(esc->sc_iot, esc->sc_ioh,
    305        1.2  jdolecek 		N86C01_STATUS) & N86C01_IRQ_PEND);
    306        1.1  jdolecek }
    307        1.1  jdolecek 
    308        1.1  jdolecek static void
    309        1.1  jdolecek esp_dma_reset(sc)
    310        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    311        1.1  jdolecek {
    312        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    313        1.1  jdolecek 
    314        1.1  jdolecek 	DPRINTF(("[esp_dma_reset] "));
    315        1.1  jdolecek 
    316        1.1  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    317        1.1  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    318        1.1  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    319        1.1  jdolecek 	}
    320        1.2  jdolecek 
    321        1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_ACTIVE) {
    322        1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    323        1.2  jdolecek 		mca_disk_unbusy();
    324        1.2  jdolecek 	}
    325        1.1  jdolecek }
    326        1.1  jdolecek 
    327        1.1  jdolecek static int
    328        1.1  jdolecek esp_dma_intr(sc)
    329        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    330        1.1  jdolecek {
    331        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    332        1.1  jdolecek 	DPRINTF(("[esp_dma_intr] "));
    333        1.1  jdolecek 
    334        1.1  jdolecek 	if ((esc->sc_flags & ESP_XFER_ACTIVE) == 0) {
    335        1.1  jdolecek 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    336        1.1  jdolecek 		return (-1);
    337        1.1  jdolecek 	}
    338        1.1  jdolecek 
    339        1.2  jdolecek 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    340        1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    341        1.2  jdolecek 		mca_disk_unbusy();
    342        1.2  jdolecek 		return (0);
    343        1.2  jdolecek 	}
    344        1.2  jdolecek 
    345        1.2  jdolecek 	sc->sc_espstat |= NCRSTAT_TC;	/* XXX */
    346        1.2  jdolecek 
    347        1.2  jdolecek 	if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
    348        1.2  jdolecek 		printf("%s: DMA not complete?\n", sc->sc_dev.dv_xname);
    349        1.2  jdolecek 		return (1);
    350        1.2  jdolecek 	}
    351        1.2  jdolecek 
    352        1.2  jdolecek 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
    353        1.2  jdolecek 		*esc->sc_xfer_len,
    354        1.2  jdolecek 		(esc->sc_flags & ESP_XFER_READ)
    355        1.2  jdolecek 			? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    356        1.9     perry 
    357        1.2  jdolecek 	bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    358        1.2  jdolecek 	esc->sc_flags &= ~ESP_XFER_LOADED;
    359        1.1  jdolecek 
    360        1.2  jdolecek 	*esc->sc_xfer_addr +=  *esc->sc_xfer_len;
    361        1.2  jdolecek 	*esc->sc_xfer_len = 0;
    362        1.1  jdolecek 
    363        1.1  jdolecek 	esc->sc_flags &= ~ESP_XFER_ACTIVE;
    364        1.2  jdolecek 	mca_disk_unbusy();
    365        1.2  jdolecek 
    366        1.1  jdolecek 	return (0);
    367        1.1  jdolecek }
    368        1.1  jdolecek 
    369        1.1  jdolecek /*
    370        1.1  jdolecek  * Setup DMA transfer.
    371        1.1  jdolecek  */
    372        1.1  jdolecek static int
    373        1.1  jdolecek esp_dma_setup(sc, addr, len, datain, dmasize)
    374        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    375        1.1  jdolecek 	caddr_t *addr;
    376        1.1  jdolecek 	size_t *len;
    377        1.1  jdolecek 	int datain;
    378  1.12.10.1      yamt 	size_t *dmasize __unused;
    379        1.1  jdolecek {
    380        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    381        1.1  jdolecek 	int error;
    382        1.1  jdolecek 	int fl;
    383        1.1  jdolecek 
    384        1.1  jdolecek 	DPRINTF(("[esp_dma_setup] "));
    385        1.1  jdolecek 
    386        1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    387        1.2  jdolecek 		printf("%s: esp_dma_setup: unloading leaked xfer\n",
    388        1.2  jdolecek 			sc->sc_dev.dv_xname);
    389        1.2  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    390        1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    391        1.2  jdolecek 	}
    392        1.2  jdolecek 
    393        1.1  jdolecek 	/* Load the buffer for DMA transfer. */
    394        1.1  jdolecek 	fl = (datain) ? BUS_DMA_READ : BUS_DMA_WRITE;
    395        1.1  jdolecek 
    396        1.1  jdolecek 	if ((error = bus_dmamap_load(esc->sc_dmat, esc->sc_xfer, *addr,
    397        1.1  jdolecek 	    *len, NULL, BUS_DMA_STREAMING|fl))) {
    398        1.1  jdolecek 		printf("%s: esp_dma_setup: unable to load DMA buffer - error %d\n",
    399        1.1  jdolecek 			sc->sc_dev.dv_xname, error);
    400        1.1  jdolecek 		return (error);
    401        1.1  jdolecek 	}
    402        1.1  jdolecek 
    403        1.1  jdolecek 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
    404        1.1  jdolecek 		*len, (datain) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    405        1.9     perry 
    406        1.2  jdolecek 	esc->sc_flags |= ESP_XFER_LOADED | (datain ? ESP_XFER_READ : 0);
    407        1.2  jdolecek 	esc->sc_xfer_addr = addr;
    408        1.2  jdolecek 	esc->sc_xfer_len  = len;
    409        1.1  jdolecek 
    410        1.1  jdolecek 	return (0);
    411        1.1  jdolecek }
    412        1.1  jdolecek 
    413        1.1  jdolecek static void
    414        1.1  jdolecek esp_dma_go(sc)
    415        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    416        1.1  jdolecek {
    417        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    418        1.1  jdolecek 	DPRINTF(("[esp_dma_go] "));
    419        1.1  jdolecek 
    420        1.1  jdolecek 	esc->sc_flags |= ESP_XFER_ACTIVE;
    421        1.2  jdolecek 	mca_disk_busy();
    422        1.1  jdolecek }
    423        1.1  jdolecek 
    424        1.1  jdolecek static void
    425        1.1  jdolecek esp_dma_stop(sc)
    426        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    427        1.1  jdolecek {
    428        1.1  jdolecek 	DPRINTF(("[esp_dma_stop] "));
    429        1.1  jdolecek 
    430        1.1  jdolecek 	panic("%s: stop not yet implemented", sc->sc_dev.dv_xname);
    431        1.1  jdolecek }
    432        1.1  jdolecek 
    433        1.1  jdolecek static int
    434        1.1  jdolecek esp_dma_isactive(sc)
    435        1.1  jdolecek 	struct ncr53c9x_softc *sc;
    436        1.1  jdolecek {
    437        1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    438        1.1  jdolecek 	DPRINTF(("[esp_dma_isactive] "));
    439        1.1  jdolecek 
    440        1.2  jdolecek 	return (esc->sc_flags & ESP_XFER_ACTIVE);
    441        1.1  jdolecek }
    442