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