Home | History | Annotate | Line # | Download | only in mca
esp_mca.c revision 1.15
      1  1.15  christos /*	$NetBSD: esp_mca.c,v 1.15 2007/03/04 06:02:14 christos 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.15  christos __KERNEL_RCSID(0, "$NetBSD: esp_mca.c,v 1.15 2007/03/04 06:02:14 christos 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.15  christos static int	esp_dma_setup(struct ncr53c9x_softc *, void **,
    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.14  christos esp_mca_match(
    131  1.14  christos 	struct device *parent,
    132  1.14  christos 	struct cfdata *cf,
    133  1.14  christos 	void *aux
    134  1.14  christos )
    135   1.1  jdolecek {
    136   1.1  jdolecek 	struct mca_attach_args *ma = aux;
    137   1.1  jdolecek 
    138   1.1  jdolecek 	switch (ma->ma_id) {
    139   1.1  jdolecek 	case MCA_PRODUCT_NCR53C90:
    140   1.1  jdolecek 		return 1;
    141   1.1  jdolecek 	}
    142   1.1  jdolecek 
    143   1.1  jdolecek 	return 0;
    144   1.1  jdolecek }
    145   1.1  jdolecek 
    146   1.1  jdolecek static void
    147  1.14  christos esp_mca_attach(
    148  1.14  christos 	struct device *parent,
    149  1.14  christos 	struct device *self,
    150  1.14  christos 	void *aux
    151  1.14  christos )
    152   1.1  jdolecek {
    153   1.1  jdolecek 	struct mca_attach_args *ma = aux;
    154  1.12   thorpej 	struct esp_softc *esc = device_private(self);
    155   1.1  jdolecek 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    156   1.2  jdolecek 	u_int16_t iobase;
    157   1.2  jdolecek 	int scsi_id, irq, drq, error;
    158   1.1  jdolecek 	bus_space_handle_t ioh;
    159   1.1  jdolecek 	int pos2, pos3, pos5;
    160   1.1  jdolecek 
    161   1.2  jdolecek 	static const u_int16_t ncrmca_iobase[] = {
    162   1.1  jdolecek 		0, 0x240, 0x340, 0x400, 0x420, 0x3240, 0x8240, 0xa240
    163   1.1  jdolecek 	};
    164   1.1  jdolecek 
    165   1.1  jdolecek 	/*
    166   1.1  jdolecek 	 * NCR SCSI Adapter (ADF 7f4f)
    167   1.1  jdolecek 	 *
    168   1.1  jdolecek 	 * POS register 2: (adf pos0)
    169   1.9     perry 	 *
    170   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    171   1.1  jdolecek 	 *     \_/ \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
    172   1.1  jdolecek 	 *      |      \____ I/O base (32B): 001=0x240 010=0x340 011=0x400
    173   1.1  jdolecek 	 *      |              100=0x420 101=0x3240 110=0x8240 111=0xa240
    174   1.1  jdolecek 	 *       \__________ IRQ: 00=3 01=5 10=7 11=9
    175   1.1  jdolecek 	 *
    176   1.1  jdolecek 	 * POS register 3: (adf pos1)
    177   1.9     perry 	 *
    178   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    179   1.1  jdolecek 	 * 1 1 1 | \_____/
    180   1.1  jdolecek 	 *       |       \__ DMA level
    181   1.1  jdolecek 	 *        \_________ Fairness: 1=enabled 0=disabled
    182   1.1  jdolecek 	 *
    183   1.1  jdolecek 	 * POS register 5: (adf pos3)
    184   1.9     perry 	 *
    185   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    186   1.1  jdolecek 	 * 1   |     \___/
    187   1.1  jdolecek 	 *     |         \__ Static Ram: 0xC8000-0xC87FF + XX*0x4000
    188   1.1  jdolecek 	 *      \___________ Host Adapter ID: 1=7 0=6
    189   1.1  jdolecek 	 */
    190   1.1  jdolecek 
    191   1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    192   1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    193   1.1  jdolecek 	pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
    194   1.1  jdolecek 
    195   1.1  jdolecek 	iobase = ncrmca_iobase[(pos2 & 0x0e) >> 1];
    196   1.1  jdolecek 	irq = 3 + 2*((pos2 & 0x30) >> 4);
    197   1.1  jdolecek 	drq = (pos3 & 0x0f);
    198   1.1  jdolecek 	scsi_id = 6 + ((pos5 & 0x20) ? 1 : 0);
    199   1.1  jdolecek 
    200   1.2  jdolecek 	printf(" slot %d irq %d drq %d: NCR SCSI Adapter\n",
    201   1.1  jdolecek 		ma->ma_slot + 1, irq, drq);
    202   1.1  jdolecek 
    203   1.2  jdolecek 	/* Map the 86C01 registers */
    204   1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, ESP_MCA_IOSIZE, 0, &ioh)) {
    205   1.1  jdolecek 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    206   1.1  jdolecek 		return;
    207   1.1  jdolecek 	}
    208   1.1  jdolecek 
    209   1.1  jdolecek 	esc->sc_iot = ma->ma_iot;
    210   1.1  jdolecek 	esc->sc_ioh = ioh;
    211   1.1  jdolecek 
    212   1.2  jdolecek 	/* Submap the 'esp' registers */
    213   1.2  jdolecek 	if (bus_space_subregion(ma->ma_iot, ioh, ESP_REG_OFFSET,
    214   1.2  jdolecek 	    ESP_MCA_IOSIZE-ESP_REG_OFFSET, &esc->sc_esp_ioh)) {
    215   1.2  jdolecek 		printf("%s: can't subregion i/o space\n", sc->sc_dev.dv_xname);
    216   1.2  jdolecek 		return;
    217   1.2  jdolecek 	}
    218   1.2  jdolecek 
    219   1.1  jdolecek 	/* Setup DMA map */
    220   1.1  jdolecek 	esc->sc_dmat = ma->ma_dmat;
    221   1.1  jdolecek 	if ((error = mca_dmamap_create(esc->sc_dmat, MAXPHYS,
    222   1.2  jdolecek             BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW | MCABUS_DMA_IOPORT,
    223   1.2  jdolecek 	    &esc->sc_xfer, drq)) != 0){
    224   1.1  jdolecek                 printf("%s: couldn't create DMA map - error %d\n",
    225   1.1  jdolecek                         sc->sc_dev.dv_xname, error);
    226   1.1  jdolecek                 return;
    227   1.1  jdolecek         }
    228   1.1  jdolecek 
    229   1.2  jdolecek 	/* MI code glue */
    230   1.1  jdolecek 	sc->sc_id = scsi_id;
    231  1.11     lukem 	sc->sc_freq = 25;		/* MHz */
    232   1.1  jdolecek 
    233   1.1  jdolecek 	sc->sc_glue = &esp_glue;
    234   1.1  jdolecek 
    235   1.2  jdolecek 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB; //| NCRCFG1_SLOW;
    236   1.2  jdolecek 	/* No point setting sc_cfg[2345], they won't be used */
    237   1.1  jdolecek 
    238   1.2  jdolecek 	sc->sc_rev = NCR_VARIANT_NCR53C90_86C01;
    239   1.1  jdolecek 	sc->sc_minsync = 0;
    240   1.1  jdolecek 
    241   1.1  jdolecek 	/* max 64KB DMA */
    242   1.1  jdolecek 	sc->sc_maxxfer = 64 * 1024;
    243   1.1  jdolecek 
    244   1.1  jdolecek 	/* Establish interrupt */
    245   1.1  jdolecek 	esc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_BIO, ncr53c9x_intr,
    246   1.1  jdolecek 			esc);
    247   1.1  jdolecek 	if (esc->sc_ih == NULL) {
    248   1.1  jdolecek 		printf("%s: couldn't establish interrupt\n",
    249   1.1  jdolecek 		    sc->sc_dev.dv_xname);
    250   1.1  jdolecek 		return;
    251   1.1  jdolecek 	}
    252   1.1  jdolecek 
    253   1.1  jdolecek 	/*
    254   1.2  jdolecek 	 * Massage the 86C01 chip - setup MCA DMA controller for DMA via
    255   1.2  jdolecek 	 * the 86C01 register, and enable 86C01 interrupts.
    256   1.2  jdolecek 	 */
    257   1.2  jdolecek 	mca_dma_set_ioport(drq, iobase + N86C01_PIO);
    258   1.2  jdolecek 
    259   1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE,
    260   1.2  jdolecek 		bus_space_read_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE)
    261   1.2  jdolecek 		| N86C01_INTR_ENABLE);
    262   1.2  jdolecek 
    263   1.2  jdolecek 	/*
    264   1.1  jdolecek 	 * Now try to attach all the sub-devices
    265   1.1  jdolecek 	 */
    266   1.1  jdolecek 	sc->sc_adapter.adapt_minphys = minphys;
    267   1.1  jdolecek 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    268   1.1  jdolecek 
    269   1.1  jdolecek 	/* Do the common parts of attachment. */
    270   1.1  jdolecek 	printf("%s", sc->sc_dev.dv_xname);
    271   1.1  jdolecek 	ncr53c9x_attach(sc);
    272   1.1  jdolecek }
    273   1.1  jdolecek 
    274   1.1  jdolecek /*
    275   1.1  jdolecek  * Glue functions.
    276   1.1  jdolecek  */
    277   1.1  jdolecek 
    278   1.1  jdolecek static u_char
    279   1.1  jdolecek esp_read_reg(sc, reg)
    280   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    281   1.1  jdolecek 	int reg;
    282   1.1  jdolecek {
    283   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    284   1.1  jdolecek 
    285   1.2  jdolecek 	return (bus_space_read_1(esc->sc_iot, esc->sc_esp_ioh, reg));
    286   1.1  jdolecek }
    287   1.1  jdolecek 
    288   1.1  jdolecek static void
    289   1.1  jdolecek esp_write_reg(sc, reg, val)
    290   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    291   1.1  jdolecek 	int reg;
    292   1.1  jdolecek 	u_char val;
    293   1.1  jdolecek {
    294   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    295   1.1  jdolecek 
    296   1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_esp_ioh, reg, val);
    297   1.1  jdolecek }
    298   1.1  jdolecek 
    299   1.1  jdolecek static int
    300   1.1  jdolecek esp_dma_isintr(sc)
    301   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    302   1.1  jdolecek {
    303   1.2  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    304   1.2  jdolecek 
    305   1.1  jdolecek 	DPRINTF(("[esp_dma_isintr] "));
    306   1.2  jdolecek 	return (bus_space_read_1(esc->sc_iot, esc->sc_ioh,
    307   1.2  jdolecek 		N86C01_STATUS) & N86C01_IRQ_PEND);
    308   1.1  jdolecek }
    309   1.1  jdolecek 
    310   1.1  jdolecek static void
    311   1.1  jdolecek esp_dma_reset(sc)
    312   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    313   1.1  jdolecek {
    314   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    315   1.1  jdolecek 
    316   1.1  jdolecek 	DPRINTF(("[esp_dma_reset] "));
    317   1.1  jdolecek 
    318   1.1  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    319   1.1  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    320   1.1  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    321   1.1  jdolecek 	}
    322   1.2  jdolecek 
    323   1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_ACTIVE) {
    324   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    325   1.2  jdolecek 		mca_disk_unbusy();
    326   1.2  jdolecek 	}
    327   1.1  jdolecek }
    328   1.1  jdolecek 
    329   1.1  jdolecek static int
    330   1.1  jdolecek esp_dma_intr(sc)
    331   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    332   1.1  jdolecek {
    333   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    334   1.1  jdolecek 	DPRINTF(("[esp_dma_intr] "));
    335   1.1  jdolecek 
    336   1.1  jdolecek 	if ((esc->sc_flags & ESP_XFER_ACTIVE) == 0) {
    337   1.1  jdolecek 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    338   1.1  jdolecek 		return (-1);
    339   1.1  jdolecek 	}
    340   1.1  jdolecek 
    341   1.2  jdolecek 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    342   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    343   1.2  jdolecek 		mca_disk_unbusy();
    344   1.2  jdolecek 		return (0);
    345   1.2  jdolecek 	}
    346   1.2  jdolecek 
    347   1.2  jdolecek 	sc->sc_espstat |= NCRSTAT_TC;	/* XXX */
    348   1.2  jdolecek 
    349   1.2  jdolecek 	if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
    350   1.2  jdolecek 		printf("%s: DMA not complete?\n", sc->sc_dev.dv_xname);
    351   1.2  jdolecek 		return (1);
    352   1.2  jdolecek 	}
    353   1.2  jdolecek 
    354   1.2  jdolecek 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
    355   1.2  jdolecek 		*esc->sc_xfer_len,
    356   1.2  jdolecek 		(esc->sc_flags & ESP_XFER_READ)
    357   1.2  jdolecek 			? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    358   1.9     perry 
    359   1.2  jdolecek 	bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    360   1.2  jdolecek 	esc->sc_flags &= ~ESP_XFER_LOADED;
    361   1.1  jdolecek 
    362   1.2  jdolecek 	*esc->sc_xfer_addr +=  *esc->sc_xfer_len;
    363   1.2  jdolecek 	*esc->sc_xfer_len = 0;
    364   1.1  jdolecek 
    365   1.1  jdolecek 	esc->sc_flags &= ~ESP_XFER_ACTIVE;
    366   1.2  jdolecek 	mca_disk_unbusy();
    367   1.2  jdolecek 
    368   1.1  jdolecek 	return (0);
    369   1.1  jdolecek }
    370   1.1  jdolecek 
    371   1.1  jdolecek /*
    372   1.1  jdolecek  * Setup DMA transfer.
    373   1.1  jdolecek  */
    374   1.1  jdolecek static int
    375  1.14  christos esp_dma_setup(
    376  1.14  christos 	struct ncr53c9x_softc *sc,
    377  1.15  christos 	void **addr,
    378  1.14  christos 	size_t *len,
    379  1.14  christos 	int datain,
    380  1.14  christos 	size_t *dmasize
    381  1.14  christos )
    382   1.1  jdolecek {
    383   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    384   1.1  jdolecek 	int error;
    385   1.1  jdolecek 	int fl;
    386   1.1  jdolecek 
    387   1.1  jdolecek 	DPRINTF(("[esp_dma_setup] "));
    388   1.1  jdolecek 
    389   1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    390   1.2  jdolecek 		printf("%s: esp_dma_setup: unloading leaked xfer\n",
    391   1.2  jdolecek 			sc->sc_dev.dv_xname);
    392   1.2  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    393   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    394   1.2  jdolecek 	}
    395   1.2  jdolecek 
    396   1.1  jdolecek 	/* Load the buffer for DMA transfer. */
    397   1.1  jdolecek 	fl = (datain) ? BUS_DMA_READ : BUS_DMA_WRITE;
    398   1.1  jdolecek 
    399   1.1  jdolecek 	if ((error = bus_dmamap_load(esc->sc_dmat, esc->sc_xfer, *addr,
    400   1.1  jdolecek 	    *len, NULL, BUS_DMA_STREAMING|fl))) {
    401   1.1  jdolecek 		printf("%s: esp_dma_setup: unable to load DMA buffer - error %d\n",
    402   1.1  jdolecek 			sc->sc_dev.dv_xname, error);
    403   1.1  jdolecek 		return (error);
    404   1.1  jdolecek 	}
    405   1.1  jdolecek 
    406   1.1  jdolecek 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0,
    407   1.1  jdolecek 		*len, (datain) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    408   1.9     perry 
    409   1.2  jdolecek 	esc->sc_flags |= ESP_XFER_LOADED | (datain ? ESP_XFER_READ : 0);
    410   1.2  jdolecek 	esc->sc_xfer_addr = addr;
    411   1.2  jdolecek 	esc->sc_xfer_len  = len;
    412   1.1  jdolecek 
    413   1.1  jdolecek 	return (0);
    414   1.1  jdolecek }
    415   1.1  jdolecek 
    416   1.1  jdolecek static void
    417   1.1  jdolecek esp_dma_go(sc)
    418   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    419   1.1  jdolecek {
    420   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    421   1.1  jdolecek 	DPRINTF(("[esp_dma_go] "));
    422   1.1  jdolecek 
    423   1.1  jdolecek 	esc->sc_flags |= ESP_XFER_ACTIVE;
    424   1.2  jdolecek 	mca_disk_busy();
    425   1.1  jdolecek }
    426   1.1  jdolecek 
    427   1.1  jdolecek static void
    428   1.1  jdolecek esp_dma_stop(sc)
    429   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    430   1.1  jdolecek {
    431   1.1  jdolecek 	DPRINTF(("[esp_dma_stop] "));
    432   1.1  jdolecek 
    433   1.1  jdolecek 	panic("%s: stop not yet implemented", sc->sc_dev.dv_xname);
    434   1.1  jdolecek }
    435   1.1  jdolecek 
    436   1.1  jdolecek static int
    437   1.1  jdolecek esp_dma_isactive(sc)
    438   1.1  jdolecek 	struct ncr53c9x_softc *sc;
    439   1.1  jdolecek {
    440   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *) sc;
    441   1.1  jdolecek 	DPRINTF(("[esp_dma_isactive] "));
    442   1.1  jdolecek 
    443   1.2  jdolecek 	return (esc->sc_flags & ESP_XFER_ACTIVE);
    444   1.1  jdolecek }
    445