Home | History | Annotate | Line # | Download | only in dev
flsc.c revision 1.27.8.2
      1  1.27.8.2  nathanw /*	$NetBSD: flsc.c,v 1.27.8.2 2002/02/28 04:06:36 nathanw Exp $ */
      2  1.27.8.2  nathanw 
      3  1.27.8.2  nathanw /*
      4  1.27.8.2  nathanw  * Copyright (c) 1997 Michael L. Hitch
      5  1.27.8.2  nathanw  * Copyright (c) 1995 Daniel Widenfalk
      6  1.27.8.2  nathanw  * Copyright (c) 1994 Christian E. Hopps
      7  1.27.8.2  nathanw  * Copyright (c) 1982, 1990 The Regents of the University of California.
      8  1.27.8.2  nathanw  * All rights reserved.
      9  1.27.8.2  nathanw  *
     10  1.27.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.27.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.27.8.2  nathanw  * are met:
     13  1.27.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.27.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.27.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.27.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.27.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.27.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.27.8.2  nathanw  *    must display the following acknowledgement:
     20  1.27.8.2  nathanw  *	This product includes software developed by Daniel Widenfalk
     21  1.27.8.2  nathanw  *	and Michael L. Hitch.
     22  1.27.8.2  nathanw  * 4. Neither the name of the University nor the names of its contributors
     23  1.27.8.2  nathanw  *    may be used to endorse or promote products derived from this software
     24  1.27.8.2  nathanw  *    without specific prior written permission.
     25  1.27.8.2  nathanw  *
     26  1.27.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.27.8.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.27.8.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.27.8.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.27.8.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.27.8.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.27.8.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.27.8.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.27.8.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.27.8.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.27.8.2  nathanw  * SUCH DAMAGE.
     37  1.27.8.2  nathanw  */
     38  1.27.8.2  nathanw 
     39  1.27.8.2  nathanw /*
     40  1.27.8.2  nathanw  * Initial amiga Fastlane driver by Daniel Widenfalk.  Conversion to
     41  1.27.8.2  nathanw  * 53c9x MI driver by Michael L. Hitch (mhitch (at) montana.edu).
     42  1.27.8.2  nathanw  */
     43  1.27.8.2  nathanw 
     44  1.27.8.2  nathanw #include "opt_ddb.h"
     45  1.27.8.2  nathanw 
     46  1.27.8.2  nathanw #include <sys/cdefs.h>
     47  1.27.8.2  nathanw __KERNEL_RCSID(0, "$NetBSD: flsc.c,v 1.27.8.2 2002/02/28 04:06:36 nathanw Exp $");
     48  1.27.8.2  nathanw 
     49  1.27.8.2  nathanw #include <sys/types.h>
     50  1.27.8.2  nathanw #include <sys/param.h>
     51  1.27.8.2  nathanw #include <sys/systm.h>
     52  1.27.8.2  nathanw #include <sys/kernel.h>
     53  1.27.8.2  nathanw #include <sys/errno.h>
     54  1.27.8.2  nathanw #include <sys/ioctl.h>
     55  1.27.8.2  nathanw #include <sys/device.h>
     56  1.27.8.2  nathanw #include <sys/buf.h>
     57  1.27.8.2  nathanw #include <sys/proc.h>
     58  1.27.8.2  nathanw #include <sys/user.h>
     59  1.27.8.2  nathanw #include <sys/queue.h>
     60  1.27.8.2  nathanw 
     61  1.27.8.2  nathanw #include <dev/scsipi/scsi_all.h>
     62  1.27.8.2  nathanw #include <dev/scsipi/scsipi_all.h>
     63  1.27.8.2  nathanw #include <dev/scsipi/scsiconf.h>
     64  1.27.8.2  nathanw #include <dev/scsipi/scsi_message.h>
     65  1.27.8.2  nathanw 
     66  1.27.8.2  nathanw #include <machine/cpu.h>
     67  1.27.8.2  nathanw #include <machine/param.h>
     68  1.27.8.2  nathanw 
     69  1.27.8.2  nathanw #include <dev/ic/ncr53c9xreg.h>
     70  1.27.8.2  nathanw #include <dev/ic/ncr53c9xvar.h>
     71  1.27.8.2  nathanw 
     72  1.27.8.2  nathanw #include <amiga/amiga/isr.h>
     73  1.27.8.2  nathanw #include <amiga/dev/flscvar.h>
     74  1.27.8.2  nathanw #include <amiga/dev/zbusvar.h>
     75  1.27.8.2  nathanw 
     76  1.27.8.2  nathanw void	flscattach(struct device *, struct device *, void *);
     77  1.27.8.2  nathanw int	flscmatch(struct device *, struct cfdata *, void *);
     78  1.27.8.2  nathanw 
     79  1.27.8.2  nathanw /* Linkup to the rest of the kernel */
     80  1.27.8.2  nathanw struct cfattach flsc_ca = {
     81  1.27.8.2  nathanw 	sizeof(struct flsc_softc), flscmatch, flscattach
     82  1.27.8.2  nathanw };
     83  1.27.8.2  nathanw 
     84  1.27.8.2  nathanw /*
     85  1.27.8.2  nathanw  * Functions and the switch for the MI code.
     86  1.27.8.2  nathanw  */
     87  1.27.8.2  nathanw u_char	flsc_read_reg(struct ncr53c9x_softc *, int);
     88  1.27.8.2  nathanw void	flsc_write_reg(struct ncr53c9x_softc *, int, u_char);
     89  1.27.8.2  nathanw int	flsc_dma_isintr(struct ncr53c9x_softc *);
     90  1.27.8.2  nathanw void	flsc_dma_reset(struct ncr53c9x_softc *);
     91  1.27.8.2  nathanw int	flsc_dma_intr(struct ncr53c9x_softc *);
     92  1.27.8.2  nathanw int	flsc_dma_setup(struct ncr53c9x_softc *, caddr_t *,
     93  1.27.8.2  nathanw 	    size_t *, int, size_t *);
     94  1.27.8.2  nathanw void	flsc_dma_go(struct ncr53c9x_softc *);
     95  1.27.8.2  nathanw void	flsc_dma_stop(struct ncr53c9x_softc *);
     96  1.27.8.2  nathanw int	flsc_dma_isactive(struct ncr53c9x_softc *);
     97  1.27.8.2  nathanw void	flsc_clear_latched_intr(struct ncr53c9x_softc *);
     98  1.27.8.2  nathanw 
     99  1.27.8.2  nathanw struct ncr53c9x_glue flsc_glue = {
    100  1.27.8.2  nathanw 	flsc_read_reg,
    101  1.27.8.2  nathanw 	flsc_write_reg,
    102  1.27.8.2  nathanw 	flsc_dma_isintr,
    103  1.27.8.2  nathanw 	flsc_dma_reset,
    104  1.27.8.2  nathanw 	flsc_dma_intr,
    105  1.27.8.2  nathanw 	flsc_dma_setup,
    106  1.27.8.2  nathanw 	flsc_dma_go,
    107  1.27.8.2  nathanw 	flsc_dma_stop,
    108  1.27.8.2  nathanw 	flsc_dma_isactive,
    109  1.27.8.2  nathanw 	flsc_clear_latched_intr,
    110  1.27.8.2  nathanw };
    111  1.27.8.2  nathanw 
    112  1.27.8.2  nathanw /* Maximum DMA transfer length to reduce impact on high-speed serial input */
    113  1.27.8.2  nathanw u_long flsc_max_dma = 1024;
    114  1.27.8.2  nathanw extern int ser_open_speed;
    115  1.27.8.2  nathanw 
    116  1.27.8.2  nathanw extern int ncr53c9x_debug;
    117  1.27.8.2  nathanw extern u_long scsi_nosync;
    118  1.27.8.2  nathanw extern int shift_nosync;
    119  1.27.8.2  nathanw 
    120  1.27.8.2  nathanw /*
    121  1.27.8.2  nathanw  * if we are an Advanced Systems & Software FastlaneZ3
    122  1.27.8.2  nathanw  */
    123  1.27.8.2  nathanw int
    124  1.27.8.2  nathanw flscmatch(struct device *parent, struct cfdata *cf, void *aux)
    125  1.27.8.2  nathanw {
    126  1.27.8.2  nathanw 	struct zbus_args *zap;
    127  1.27.8.2  nathanw 
    128  1.27.8.2  nathanw 	if (!is_a4000() && !is_a3000())
    129  1.27.8.2  nathanw 		return(0);
    130  1.27.8.2  nathanw 
    131  1.27.8.2  nathanw 	zap = aux;
    132  1.27.8.2  nathanw 	if (zap->manid == 0x2140 && zap->prodid == 11
    133  1.27.8.2  nathanw 	    && iszthreepa(zap->pa))
    134  1.27.8.2  nathanw 		return(1);
    135  1.27.8.2  nathanw 
    136  1.27.8.2  nathanw 	return(0);
    137  1.27.8.2  nathanw }
    138  1.27.8.2  nathanw 
    139  1.27.8.2  nathanw /*
    140  1.27.8.2  nathanw  * Attach this instance, and then all the sub-devices
    141  1.27.8.2  nathanw  */
    142  1.27.8.2  nathanw void
    143  1.27.8.2  nathanw flscattach(struct device *parent, struct device *self, void *aux)
    144  1.27.8.2  nathanw {
    145  1.27.8.2  nathanw 	struct flsc_softc *fsc = (void *)self;
    146  1.27.8.2  nathanw 	struct ncr53c9x_softc *sc = &fsc->sc_ncr53c9x;
    147  1.27.8.2  nathanw 	struct zbus_args  *zap;
    148  1.27.8.2  nathanw 
    149  1.27.8.2  nathanw 	/*
    150  1.27.8.2  nathanw 	 * Set up the glue for MI code early; we use some of it here.
    151  1.27.8.2  nathanw 	 */
    152  1.27.8.2  nathanw 	sc->sc_glue = &flsc_glue;
    153  1.27.8.2  nathanw 
    154  1.27.8.2  nathanw 	/*
    155  1.27.8.2  nathanw 	 * Save the regs
    156  1.27.8.2  nathanw 	 */
    157  1.27.8.2  nathanw 	zap = aux;
    158  1.27.8.2  nathanw 	fsc->sc_dmabase = (volatile u_char *)zap->va;
    159  1.27.8.2  nathanw 	fsc->sc_reg = &((volatile u_char *)zap->va)[0x1000001];
    160  1.27.8.2  nathanw 
    161  1.27.8.2  nathanw 	sc->sc_freq = 40;		/* Clocked at 40Mhz */
    162  1.27.8.2  nathanw 
    163  1.27.8.2  nathanw 	printf(": address %p", fsc->sc_reg);
    164  1.27.8.2  nathanw 
    165  1.27.8.2  nathanw 	sc->sc_id = 7;
    166  1.27.8.2  nathanw 
    167  1.27.8.2  nathanw 	/*
    168  1.27.8.2  nathanw 	 * It is necessary to try to load the 2nd config register here,
    169  1.27.8.2  nathanw 	 * to find out what rev the flsc chip is, else the flsc_reset
    170  1.27.8.2  nathanw 	 * will not set up the defaults correctly.
    171  1.27.8.2  nathanw 	 */
    172  1.27.8.2  nathanw 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
    173  1.27.8.2  nathanw 	sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_FE;
    174  1.27.8.2  nathanw 	sc->sc_cfg3 = 0x08 /*FCLK*/ | NCRESPCFG3_FSCSI | NCRESPCFG3_CDB;
    175  1.27.8.2  nathanw 	sc->sc_rev = NCR_VARIANT_FAS216;
    176  1.27.8.2  nathanw 
    177  1.27.8.2  nathanw 	/*
    178  1.27.8.2  nathanw 	 * This is the value used to start sync negotiations
    179  1.27.8.2  nathanw 	 * Note that the NCR register "SYNCTP" is programmed
    180  1.27.8.2  nathanw 	 * in "clocks per byte", and has a minimum value of 4.
    181  1.27.8.2  nathanw 	 * The SCSI period used in negotiation is one-fourth
    182  1.27.8.2  nathanw 	 * of the time (in nanoseconds) needed to transfer one byte.
    183  1.27.8.2  nathanw 	 * Since the chip's clock is given in MHz, we have the following
    184  1.27.8.2  nathanw 	 * formula: 4 * period = (1000 / freq) * 4
    185  1.27.8.2  nathanw 	 */
    186  1.27.8.2  nathanw 	sc->sc_minsync = 1000 / sc->sc_freq;
    187  1.27.8.2  nathanw 
    188  1.27.8.2  nathanw 	if (((scsi_nosync >> shift_nosync) & 0xff00) == 0xff00)
    189  1.27.8.2  nathanw 		sc->sc_minsync = 0;
    190  1.27.8.2  nathanw 
    191  1.27.8.2  nathanw 	/* Really no limit, but since we want to fit into the TCR... */
    192  1.27.8.2  nathanw 	sc->sc_maxxfer = 64 * 1024;
    193  1.27.8.2  nathanw 
    194  1.27.8.2  nathanw 	fsc->sc_portbits = 0xa0 | FLSC_PB_EDI | FLSC_PB_ESI;
    195  1.27.8.2  nathanw 	fsc->sc_hardbits = fsc->sc_reg[0x40];
    196  1.27.8.2  nathanw 
    197  1.27.8.2  nathanw 	fsc->sc_alignbuf = (char *)((u_long)fsc->sc_unalignbuf & -4);
    198  1.27.8.2  nathanw 
    199  1.27.8.2  nathanw 	sc->sc_dev.dv_cfdata->cf_flags |= (scsi_nosync >> shift_nosync) & 0xffff;
    200  1.27.8.2  nathanw 	shift_nosync += 16;
    201  1.27.8.2  nathanw 	ncr53c9x_debug |= (scsi_nosync >> shift_nosync) & 0xffff;
    202  1.27.8.2  nathanw 	shift_nosync += 16;
    203  1.27.8.2  nathanw 
    204  1.27.8.2  nathanw 	/*
    205  1.27.8.2  nathanw 	 * Configure interrupts.
    206  1.27.8.2  nathanw 	 */
    207  1.27.8.2  nathanw 	fsc->sc_isr.isr_intr = ncr53c9x_intr;
    208  1.27.8.2  nathanw 	fsc->sc_isr.isr_arg  = sc;
    209  1.27.8.2  nathanw 	fsc->sc_isr.isr_ipl  = 2;
    210  1.27.8.2  nathanw 	add_isr(&fsc->sc_isr);
    211  1.27.8.2  nathanw 
    212  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    213  1.27.8.2  nathanw 
    214  1.27.8.2  nathanw 	/*
    215  1.27.8.2  nathanw 	 * Now try to attach all the sub-devices
    216  1.27.8.2  nathanw 	 */
    217  1.27.8.2  nathanw 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    218  1.27.8.2  nathanw 	sc->sc_adapter.adapt_minphys = minphys;
    219  1.27.8.2  nathanw 	ncr53c9x_attach(sc);
    220  1.27.8.2  nathanw }
    221  1.27.8.2  nathanw 
    222  1.27.8.2  nathanw /*
    223  1.27.8.2  nathanw  * Glue functions.
    224  1.27.8.2  nathanw  */
    225  1.27.8.2  nathanw 
    226  1.27.8.2  nathanw u_char
    227  1.27.8.2  nathanw flsc_read_reg(struct ncr53c9x_softc *sc, int reg)
    228  1.27.8.2  nathanw {
    229  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    230  1.27.8.2  nathanw 
    231  1.27.8.2  nathanw 	return fsc->sc_reg[reg * 4];
    232  1.27.8.2  nathanw }
    233  1.27.8.2  nathanw 
    234  1.27.8.2  nathanw void
    235  1.27.8.2  nathanw flsc_write_reg(struct ncr53c9x_softc *sc, int reg, u_char val)
    236  1.27.8.2  nathanw {
    237  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    238  1.27.8.2  nathanw 	struct ncr53c9x_tinfo *ti;
    239  1.27.8.2  nathanw 	u_char v = val;
    240  1.27.8.2  nathanw 
    241  1.27.8.2  nathanw 	if (fsc->sc_piomode && reg == NCR_CMD &&
    242  1.27.8.2  nathanw 	    v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    243  1.27.8.2  nathanw 		v = NCRCMD_TRANS;
    244  1.27.8.2  nathanw 	}
    245  1.27.8.2  nathanw 	/*
    246  1.27.8.2  nathanw 	 * Can't do synchronous transfers in XS_CTL_POLL mode:
    247  1.27.8.2  nathanw 	 * If starting XS_CTL_POLL command, clear defer sync negotiation
    248  1.27.8.2  nathanw 	 * by clearing the T_NEGOTIATE flag.  If starting XS_CTL_POLL and
    249  1.27.8.2  nathanw 	 * the device is currently running synchronous, force another
    250  1.27.8.2  nathanw 	 * T_NEGOTIATE with 0 offset.
    251  1.27.8.2  nathanw 	 */
    252  1.27.8.2  nathanw 	if (reg == NCR_SELID) {
    253  1.27.8.2  nathanw 		ti = &sc->sc_tinfo[
    254  1.27.8.2  nathanw 		    sc->sc_nexus->xs->xs_periph->periph_target];
    255  1.27.8.2  nathanw 		if (sc->sc_nexus->xs->xs_control & XS_CTL_POLL) {
    256  1.27.8.2  nathanw 			if (ti->flags & T_SYNCMODE) {
    257  1.27.8.2  nathanw 				ti->flags ^= T_SYNCMODE | T_NEGOTIATE;
    258  1.27.8.2  nathanw 			} else if (ti->flags & T_NEGOTIATE) {
    259  1.27.8.2  nathanw 				ti->flags ^= T_NEGOTIATE | T_SYNCHOFF;
    260  1.27.8.2  nathanw 				/* save T_NEGOTIATE in private flags? */
    261  1.27.8.2  nathanw 			}
    262  1.27.8.2  nathanw 		} else {
    263  1.27.8.2  nathanw 			/*
    264  1.27.8.2  nathanw 			 * If we haven't attempted sync negotiation yet,
    265  1.27.8.2  nathanw 			 * do it now.
    266  1.27.8.2  nathanw 			 */
    267  1.27.8.2  nathanw 			if ((ti->flags & (T_SYNCMODE | T_SYNCHOFF)) ==
    268  1.27.8.2  nathanw 			    T_SYNCHOFF &&
    269  1.27.8.2  nathanw 			    sc->sc_minsync != 0)	/* XXX */
    270  1.27.8.2  nathanw 				ti->flags ^= T_NEGOTIATE | T_SYNCHOFF;
    271  1.27.8.2  nathanw 		}
    272  1.27.8.2  nathanw 	}
    273  1.27.8.2  nathanw 	if (reg == NCR_CMD && v == NCRCMD_SETATN  &&
    274  1.27.8.2  nathanw 	    sc->sc_flags & NCR_SYNCHNEGO &&
    275  1.27.8.2  nathanw 	     sc->sc_nexus->xs->xs_control & XS_CTL_POLL) {
    276  1.27.8.2  nathanw 		ti = &sc->sc_tinfo[
    277  1.27.8.2  nathanw 		    sc->sc_nexus->xs->xs_periph->periph_target];
    278  1.27.8.2  nathanw 		ti->offset = 0;
    279  1.27.8.2  nathanw 	}
    280  1.27.8.2  nathanw 	fsc->sc_reg[reg * 4] = v;
    281  1.27.8.2  nathanw }
    282  1.27.8.2  nathanw 
    283  1.27.8.2  nathanw int
    284  1.27.8.2  nathanw flsc_dma_isintr(struct ncr53c9x_softc *sc)
    285  1.27.8.2  nathanw {
    286  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    287  1.27.8.2  nathanw 	unsigned hardbits;
    288  1.27.8.2  nathanw 
    289  1.27.8.2  nathanw 	hardbits = fsc->sc_reg[0x40];
    290  1.27.8.2  nathanw 	if (hardbits & FLSC_HB_IACT)
    291  1.27.8.2  nathanw 		return (fsc->sc_csr = 0);
    292  1.27.8.2  nathanw 
    293  1.27.8.2  nathanw 	if (sc->sc_state == NCR_CONNECTED || sc->sc_state == NCR_SELECTING)
    294  1.27.8.2  nathanw 		fsc->sc_portbits |= FLSC_PB_LED;
    295  1.27.8.2  nathanw 	else
    296  1.27.8.2  nathanw 		fsc->sc_portbits &= ~FLSC_PB_LED;
    297  1.27.8.2  nathanw 
    298  1.27.8.2  nathanw 	if ((hardbits & FLSC_HB_CREQ) && !(hardbits & FLSC_HB_MINT) &&
    299  1.27.8.2  nathanw 	    fsc->sc_reg[NCR_STAT * 4] & NCRSTAT_INT) {
    300  1.27.8.2  nathanw 		return 1;
    301  1.27.8.2  nathanw 	}
    302  1.27.8.2  nathanw 	/* Do I still need this? */
    303  1.27.8.2  nathanw 	if (fsc->sc_piomode && fsc->sc_reg[NCR_STAT * 4] & NCRSTAT_INT &&
    304  1.27.8.2  nathanw 	    !(hardbits & FLSC_HB_MINT))
    305  1.27.8.2  nathanw 		return 1;
    306  1.27.8.2  nathanw 
    307  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits & ~FLSC_PB_INT_BITS;
    308  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    309  1.27.8.2  nathanw 	return 0;
    310  1.27.8.2  nathanw }
    311  1.27.8.2  nathanw 
    312  1.27.8.2  nathanw void
    313  1.27.8.2  nathanw flsc_clear_latched_intr(struct ncr53c9x_softc *sc)
    314  1.27.8.2  nathanw {
    315  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    316  1.27.8.2  nathanw 
    317  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits & ~FLSC_PB_INT_BITS;
    318  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    319  1.27.8.2  nathanw }
    320  1.27.8.2  nathanw 
    321  1.27.8.2  nathanw void
    322  1.27.8.2  nathanw flsc_dma_reset(struct ncr53c9x_softc *sc)
    323  1.27.8.2  nathanw {
    324  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    325  1.27.8.2  nathanw struct ncr53c9x_tinfo *ti;
    326  1.27.8.2  nathanw 
    327  1.27.8.2  nathanw if (sc->sc_nexus)
    328  1.27.8.2  nathanw   ti = &sc->sc_tinfo[sc->sc_nexus->xs->xs_periph->periph_target];
    329  1.27.8.2  nathanw else
    330  1.27.8.2  nathanw   ti = &sc->sc_tinfo[1];	/* XXX */
    331  1.27.8.2  nathanw if (fsc->sc_active) {
    332  1.27.8.2  nathanw   printf("dmaaddr %p dmasize %d stat %x flags %x off %d per %d ff %x",
    333  1.27.8.2  nathanw      *fsc->sc_dmaaddr, fsc->sc_dmasize, fsc->sc_reg[NCR_STAT * 4],
    334  1.27.8.2  nathanw      ti->flags, ti->offset, ti->period, fsc->sc_reg[NCR_FFLAG * 4]);
    335  1.27.8.2  nathanw   printf(" intr %x\n", fsc->sc_reg[NCR_INTR * 4]);
    336  1.27.8.2  nathanw #ifdef DDB
    337  1.27.8.2  nathanw   Debugger();
    338  1.27.8.2  nathanw #endif
    339  1.27.8.2  nathanw }
    340  1.27.8.2  nathanw 	fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    341  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    342  1.27.8.2  nathanw 	fsc->sc_reg[0x80] = 0;
    343  1.27.8.2  nathanw 	*((u_long *)fsc->sc_dmabase) = 0;
    344  1.27.8.2  nathanw 	fsc->sc_active = 0;
    345  1.27.8.2  nathanw 	fsc->sc_piomode = 0;
    346  1.27.8.2  nathanw }
    347  1.27.8.2  nathanw 
    348  1.27.8.2  nathanw int
    349  1.27.8.2  nathanw flsc_dma_intr(struct ncr53c9x_softc *sc)
    350  1.27.8.2  nathanw {
    351  1.27.8.2  nathanw 	register struct flsc_softc *fsc = (struct flsc_softc *)sc;
    352  1.27.8.2  nathanw 	register u_char	*p;
    353  1.27.8.2  nathanw 	volatile u_char *cmdreg, *intrreg, *statreg, *fiforeg;
    354  1.27.8.2  nathanw 	register u_int	flscphase, flscstat, flscintr;
    355  1.27.8.2  nathanw 	register int	cnt;
    356  1.27.8.2  nathanw 
    357  1.27.8.2  nathanw 	NCR_DMA(("flsc_dma_intr: pio %d cnt %d int %x stat %x fifo %d ",
    358  1.27.8.2  nathanw 	    fsc->sc_piomode, fsc->sc_dmasize, sc->sc_espintr, sc->sc_espstat,
    359  1.27.8.2  nathanw 	    fsc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF));
    360  1.27.8.2  nathanw 	if (!(fsc->sc_reg[0x40] & FLSC_HB_CREQ))
    361  1.27.8.2  nathanw 		printf("flsc_dma_intr: csr %x stat %x intr %x\n", fsc->sc_csr,
    362  1.27.8.2  nathanw 		    sc->sc_espstat, sc->sc_espintr);
    363  1.27.8.2  nathanw 	if (fsc->sc_active == 0) {
    364  1.27.8.2  nathanw 		printf("flsc_intr--inactive DMA\n");
    365  1.27.8.2  nathanw 		return -1;
    366  1.27.8.2  nathanw 	}
    367  1.27.8.2  nathanw 
    368  1.27.8.2  nathanw /* if DMA transfer, update sc_dmaaddr and sc_pdmalen, else PIO xfer */
    369  1.27.8.2  nathanw 	if (fsc->sc_piomode == 0) {
    370  1.27.8.2  nathanw 		fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    371  1.27.8.2  nathanw 		fsc->sc_reg[0x40] = fsc->sc_portbits;
    372  1.27.8.2  nathanw 		fsc->sc_reg[0x80] = 0;
    373  1.27.8.2  nathanw 		*((u_long *)fsc->sc_dmabase) = 0;
    374  1.27.8.2  nathanw 		cnt = fsc->sc_reg[NCR_TCL * 4];
    375  1.27.8.2  nathanw 		cnt += fsc->sc_reg[NCR_TCM * 4] << 8;
    376  1.27.8.2  nathanw 		cnt += fsc->sc_reg[NCR_TCH * 4] << 16;
    377  1.27.8.2  nathanw 		if (!fsc->sc_datain) {
    378  1.27.8.2  nathanw 			cnt += fsc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF;
    379  1.27.8.2  nathanw 			fsc->sc_reg[NCR_CMD * 4] = NCRCMD_FLUSH;
    380  1.27.8.2  nathanw 		}
    381  1.27.8.2  nathanw 		cnt = fsc->sc_dmasize - cnt;	/* number of bytes transferred */
    382  1.27.8.2  nathanw 		NCR_DMA(("DMA xferred %d\n", cnt));
    383  1.27.8.2  nathanw 		if (fsc->sc_xfr_align) {
    384  1.27.8.2  nathanw 			int i;
    385  1.27.8.2  nathanw 			for (i = 0; i < cnt; ++i)
    386  1.27.8.2  nathanw 				(*fsc->sc_dmaaddr)[i] = fsc->sc_alignbuf[i];
    387  1.27.8.2  nathanw 			fsc->sc_xfr_align = 0;
    388  1.27.8.2  nathanw 		}
    389  1.27.8.2  nathanw 		*fsc->sc_dmaaddr += cnt;
    390  1.27.8.2  nathanw 		*fsc->sc_pdmalen -= cnt;
    391  1.27.8.2  nathanw 		fsc->sc_active = 0;
    392  1.27.8.2  nathanw 		return 0;
    393  1.27.8.2  nathanw 	}
    394  1.27.8.2  nathanw 
    395  1.27.8.2  nathanw 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    396  1.27.8.2  nathanw 		fsc->sc_active = 0;
    397  1.27.8.2  nathanw 		fsc->sc_piomode = 0;
    398  1.27.8.2  nathanw 		NCR_DMA(("no NCRINTR_BS\n"));
    399  1.27.8.2  nathanw 		return 0;
    400  1.27.8.2  nathanw 	}
    401  1.27.8.2  nathanw 
    402  1.27.8.2  nathanw 	cnt = fsc->sc_dmasize;
    403  1.27.8.2  nathanw #if 0
    404  1.27.8.2  nathanw 	if (cnt == 0) {
    405  1.27.8.2  nathanw 		printf("data interrupt, but no count left.");
    406  1.27.8.2  nathanw 	}
    407  1.27.8.2  nathanw #endif
    408  1.27.8.2  nathanw 
    409  1.27.8.2  nathanw 	p = *fsc->sc_dmaaddr;
    410  1.27.8.2  nathanw 	flscphase = sc->sc_phase;
    411  1.27.8.2  nathanw 	flscstat = (u_int) sc->sc_espstat;
    412  1.27.8.2  nathanw 	flscintr = (u_int) sc->sc_espintr;
    413  1.27.8.2  nathanw 	cmdreg = fsc->sc_reg + NCR_CMD * 4;
    414  1.27.8.2  nathanw 	fiforeg = fsc->sc_reg + NCR_FIFO * 4;
    415  1.27.8.2  nathanw 	statreg = fsc->sc_reg + NCR_STAT * 4;
    416  1.27.8.2  nathanw 	intrreg = fsc->sc_reg + NCR_INTR * 4;
    417  1.27.8.2  nathanw 	NCR_DMA(("PIO %d datain %d phase %d stat %x intr %x\n",
    418  1.27.8.2  nathanw 	    cnt, fsc->sc_datain, flscphase, flscstat, flscintr));
    419  1.27.8.2  nathanw 	do {
    420  1.27.8.2  nathanw 		if (fsc->sc_datain) {
    421  1.27.8.2  nathanw 			*p++ = *fiforeg;
    422  1.27.8.2  nathanw 			cnt--;
    423  1.27.8.2  nathanw 			if (flscphase == DATA_IN_PHASE) {
    424  1.27.8.2  nathanw 				*cmdreg = NCRCMD_TRANS;
    425  1.27.8.2  nathanw 			} else {
    426  1.27.8.2  nathanw 				fsc->sc_active = 0;
    427  1.27.8.2  nathanw 			}
    428  1.27.8.2  nathanw 	 	} else {
    429  1.27.8.2  nathanw NCR_DMA(("flsc_dma_intr: PIO out- phase %d cnt %d active %d\n", flscphase, cnt,
    430  1.27.8.2  nathanw     fsc->sc_active));
    431  1.27.8.2  nathanw 			if (   (flscphase == DATA_OUT_PHASE)
    432  1.27.8.2  nathanw 			    || (flscphase == MESSAGE_OUT_PHASE)) {
    433  1.27.8.2  nathanw 				int n;
    434  1.27.8.2  nathanw 				n = 16 - (fsc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF);
    435  1.27.8.2  nathanw 				if (n > cnt)
    436  1.27.8.2  nathanw 					n = cnt;
    437  1.27.8.2  nathanw 				cnt -= n;
    438  1.27.8.2  nathanw 				while (n-- > 0)
    439  1.27.8.2  nathanw 					*fiforeg = *p++;
    440  1.27.8.2  nathanw 				*cmdreg = NCRCMD_TRANS;
    441  1.27.8.2  nathanw 			} else {
    442  1.27.8.2  nathanw 				fsc->sc_active = 0;
    443  1.27.8.2  nathanw 			}
    444  1.27.8.2  nathanw 		}
    445  1.27.8.2  nathanw 
    446  1.27.8.2  nathanw 		if (fsc->sc_active && cnt) {
    447  1.27.8.2  nathanw 			while (!(*statreg & 0x80));
    448  1.27.8.2  nathanw 			flscstat = *statreg;
    449  1.27.8.2  nathanw 			flscintr = *intrreg;
    450  1.27.8.2  nathanw 			flscphase = (flscintr & NCRINTR_DIS)
    451  1.27.8.2  nathanw 				    ? /* Disconnected */ BUSFREE_PHASE
    452  1.27.8.2  nathanw 				    : flscstat & PHASE_MASK;
    453  1.27.8.2  nathanw 		}
    454  1.27.8.2  nathanw 	} while (cnt && fsc->sc_active && (flscintr & NCRINTR_BS));
    455  1.27.8.2  nathanw #if 1
    456  1.27.8.2  nathanw if (fsc->sc_dmasize < 8 && cnt)
    457  1.27.8.2  nathanw   printf("flsc_dma_intr: short transfer: dmasize %d cnt %d\n",
    458  1.27.8.2  nathanw     fsc->sc_dmasize, cnt);
    459  1.27.8.2  nathanw #endif
    460  1.27.8.2  nathanw 	NCR_DMA(("flsc_dma_intr: PIO transfer [%d], %d->%d phase %d stat %x intr %x\n",
    461  1.27.8.2  nathanw 	    *fsc->sc_pdmalen, fsc->sc_dmasize, cnt, flscphase, flscstat, flscintr));
    462  1.27.8.2  nathanw 	sc->sc_phase = flscphase;
    463  1.27.8.2  nathanw 	sc->sc_espstat = (u_char) flscstat;
    464  1.27.8.2  nathanw 	sc->sc_espintr = (u_char) flscintr;
    465  1.27.8.2  nathanw 	*fsc->sc_dmaaddr = p;
    466  1.27.8.2  nathanw 	*fsc->sc_pdmalen -= fsc->sc_dmasize - cnt;
    467  1.27.8.2  nathanw 	fsc->sc_dmasize = cnt;
    468  1.27.8.2  nathanw 
    469  1.27.8.2  nathanw 	if (*fsc->sc_pdmalen == 0) {
    470  1.27.8.2  nathanw 		sc->sc_espstat |= NCRSTAT_TC;
    471  1.27.8.2  nathanw 		fsc->sc_piomode = 0;
    472  1.27.8.2  nathanw 	}
    473  1.27.8.2  nathanw 	return 0;
    474  1.27.8.2  nathanw }
    475  1.27.8.2  nathanw 
    476  1.27.8.2  nathanw int
    477  1.27.8.2  nathanw flsc_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, size_t *len,
    478  1.27.8.2  nathanw                int datain, size_t *dmasize)
    479  1.27.8.2  nathanw {
    480  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    481  1.27.8.2  nathanw 	paddr_t pa;
    482  1.27.8.2  nathanw 	u_char *ptr;
    483  1.27.8.2  nathanw 	size_t xfer;
    484  1.27.8.2  nathanw 
    485  1.27.8.2  nathanw 	fsc->sc_dmaaddr = addr;
    486  1.27.8.2  nathanw 	fsc->sc_pdmalen = len;
    487  1.27.8.2  nathanw 	fsc->sc_datain = datain;
    488  1.27.8.2  nathanw 	fsc->sc_dmasize = *dmasize;
    489  1.27.8.2  nathanw 	if (sc->sc_nexus->xs->xs_control & XS_CTL_POLL) {
    490  1.27.8.2  nathanw 		/* polling mode, use PIO */
    491  1.27.8.2  nathanw 		*dmasize = fsc->sc_dmasize;
    492  1.27.8.2  nathanw 		NCR_DMA(("pfsc_dma_setup: PIO %p/%d [%d]\n", *addr,
    493  1.27.8.2  nathanw 		    fsc->sc_dmasize, *len));
    494  1.27.8.2  nathanw 		fsc->sc_piomode = 1;
    495  1.27.8.2  nathanw 		if (datain == 0) {
    496  1.27.8.2  nathanw 			int n;
    497  1.27.8.2  nathanw 			n = fsc->sc_dmasize;
    498  1.27.8.2  nathanw 			if (n > 16)
    499  1.27.8.2  nathanw 				n = 16;
    500  1.27.8.2  nathanw 			while (n-- > 0) {
    501  1.27.8.2  nathanw 				fsc->sc_reg[NCR_FIFO * 4] = **fsc->sc_dmaaddr;
    502  1.27.8.2  nathanw 				(*fsc->sc_pdmalen)--;
    503  1.27.8.2  nathanw 				(*fsc->sc_dmaaddr)++;
    504  1.27.8.2  nathanw 				--fsc->sc_dmasize;
    505  1.27.8.2  nathanw 			}
    506  1.27.8.2  nathanw 		}
    507  1.27.8.2  nathanw 		return 0;
    508  1.27.8.2  nathanw 	}
    509  1.27.8.2  nathanw 	/*
    510  1.27.8.2  nathanw 	 * DMA can be nasty for high-speed serial input, so limit the
    511  1.27.8.2  nathanw 	 * size of this DMA operation if the serial port is running at
    512  1.27.8.2  nathanw 	 * a high speed (higher than 19200 for now - should be adjusted
    513  1.27.8.2  nathanw 	 * based on cpu type and speed?).
    514  1.27.8.2  nathanw 	 * XXX - add serial speed check XXX
    515  1.27.8.2  nathanw 	 */
    516  1.27.8.2  nathanw 	if (ser_open_speed > 19200 && flsc_max_dma != 0 &&
    517  1.27.8.2  nathanw 	    fsc->sc_dmasize > flsc_max_dma)
    518  1.27.8.2  nathanw 		fsc->sc_dmasize = flsc_max_dma;
    519  1.27.8.2  nathanw 	ptr = *addr;			/* Kernel virtual address */
    520  1.27.8.2  nathanw 	pa = kvtop(ptr);		/* Physical address of DMA */
    521  1.27.8.2  nathanw 	xfer = min(fsc->sc_dmasize, NBPG - (pa & (NBPG - 1)));
    522  1.27.8.2  nathanw 	fsc->sc_xfr_align = 0;
    523  1.27.8.2  nathanw 	fsc->sc_piomode = 0;
    524  1.27.8.2  nathanw 	fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    525  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    526  1.27.8.2  nathanw 	fsc->sc_reg[0x80] = 0;
    527  1.27.8.2  nathanw 	*((u_long *)fsc->sc_dmabase) = 0;
    528  1.27.8.2  nathanw 
    529  1.27.8.2  nathanw 	/*
    530  1.27.8.2  nathanw 	 * If output and length < 16, copy to fifo
    531  1.27.8.2  nathanw 	 */
    532  1.27.8.2  nathanw 	if (datain == 0 && fsc->sc_dmasize < 16) {
    533  1.27.8.2  nathanw 		int n;
    534  1.27.8.2  nathanw 		for (n = 0; n < fsc->sc_dmasize; ++n)
    535  1.27.8.2  nathanw 			fsc->sc_reg[NCR_FIFO * 4] = *ptr++;
    536  1.27.8.2  nathanw 		NCR_DMA(("flsc_dma_setup: %d bytes written to fifo\n", n));
    537  1.27.8.2  nathanw 		fsc->sc_piomode = 1;
    538  1.27.8.2  nathanw 		fsc->sc_active = 1;
    539  1.27.8.2  nathanw 		*fsc->sc_pdmalen -= fsc->sc_dmasize;
    540  1.27.8.2  nathanw 		*fsc->sc_dmaaddr += fsc->sc_dmasize;
    541  1.27.8.2  nathanw 		*dmasize = fsc->sc_dmasize;
    542  1.27.8.2  nathanw 		fsc->sc_dmasize = 0;
    543  1.27.8.2  nathanw 		return 0;		/* All done */
    544  1.27.8.2  nathanw 	}
    545  1.27.8.2  nathanw 	/*
    546  1.27.8.2  nathanw 	 * If output and unaligned, copy unaligned data to fifo
    547  1.27.8.2  nathanw 	 */
    548  1.27.8.2  nathanw 	else if (datain == 0 && (int)ptr & 3) {
    549  1.27.8.2  nathanw 		int n = 4 - ((int)ptr & 3);
    550  1.27.8.2  nathanw 		NCR_DMA(("flsc_dma_setup: align %d bytes written to fifo\n", n));
    551  1.27.8.2  nathanw 		pa += n;
    552  1.27.8.2  nathanw 		xfer -= n;
    553  1.27.8.2  nathanw 		while (n--)
    554  1.27.8.2  nathanw 			fsc->sc_reg[NCR_FIFO * 4] = *ptr++;
    555  1.27.8.2  nathanw 	}
    556  1.27.8.2  nathanw 	/*
    557  1.27.8.2  nathanw 	 * If unaligned address, read unaligned bytes into alignment buffer
    558  1.27.8.2  nathanw 	 */
    559  1.27.8.2  nathanw 	else if ((int)ptr & 3 || xfer & 3) {
    560  1.27.8.2  nathanw 		pa = kvtop((caddr_t)fsc->sc_alignbuf);
    561  1.27.8.2  nathanw 		xfer = fsc->sc_dmasize = min(xfer, sizeof (fsc->sc_unalignbuf));
    562  1.27.8.2  nathanw 		NCR_DMA(("flsc_dma_setup: align read by %d bytes\n", xfer));
    563  1.27.8.2  nathanw 		fsc->sc_xfr_align = 1;
    564  1.27.8.2  nathanw 	}
    565  1.27.8.2  nathanw 	/*
    566  1.27.8.2  nathanw 	 * If length smaller than longword, read into alignment buffer
    567  1.27.8.2  nathanw 	 * XXX doesn't work for 1 or 2 bytes !!!!
    568  1.27.8.2  nathanw 	 */
    569  1.27.8.2  nathanw 	else if (fsc->sc_dmasize < 4) {
    570  1.27.8.2  nathanw 		NCR_DMA(("flsc_dma_setup: read remaining %d bytes\n",
    571  1.27.8.2  nathanw 		    fsc->sc_dmasize));
    572  1.27.8.2  nathanw 		pa = kvtop((caddr_t)fsc->sc_alignbuf);
    573  1.27.8.2  nathanw 		fsc->sc_xfr_align = 1;
    574  1.27.8.2  nathanw 	}
    575  1.27.8.2  nathanw 	/*
    576  1.27.8.2  nathanw 	 * Finally, limit transfer length to multiple of 4 bytes.
    577  1.27.8.2  nathanw 	 */
    578  1.27.8.2  nathanw 	else {
    579  1.27.8.2  nathanw 		fsc->sc_dmasize &= -4;
    580  1.27.8.2  nathanw 		xfer &= -4;
    581  1.27.8.2  nathanw 	}
    582  1.27.8.2  nathanw 
    583  1.27.8.2  nathanw 	while (xfer < fsc->sc_dmasize) {
    584  1.27.8.2  nathanw 		if ((pa + xfer) != kvtop(*addr + xfer))
    585  1.27.8.2  nathanw 			break;
    586  1.27.8.2  nathanw 		if ((fsc->sc_dmasize - xfer) < NBPG)
    587  1.27.8.2  nathanw 			xfer = fsc->sc_dmasize;
    588  1.27.8.2  nathanw 		else
    589  1.27.8.2  nathanw 			xfer += NBPG;
    590  1.27.8.2  nathanw 	}
    591  1.27.8.2  nathanw 
    592  1.27.8.2  nathanw 	fsc->sc_dmasize = xfer;
    593  1.27.8.2  nathanw 	*dmasize = fsc->sc_dmasize;
    594  1.27.8.2  nathanw 	fsc->sc_pa = pa;
    595  1.27.8.2  nathanw #if defined(M68040) || defined(M68060)
    596  1.27.8.2  nathanw 	if (mmutype == MMU_68040) {
    597  1.27.8.2  nathanw 		if (fsc->sc_xfr_align) {
    598  1.27.8.2  nathanw 			int n;
    599  1.27.8.2  nathanw 			for (n = 0; n < sizeof (fsc->sc_unalignbuf); ++n)
    600  1.27.8.2  nathanw 				fsc->sc_alignbuf[n] = n | 0x80;
    601  1.27.8.2  nathanw 			dma_cachectl(fsc->sc_alignbuf,
    602  1.27.8.2  nathanw 			    sizeof(fsc->sc_unalignbuf));
    603  1.27.8.2  nathanw 		}
    604  1.27.8.2  nathanw 		else
    605  1.27.8.2  nathanw 			dma_cachectl(*fsc->sc_dmaaddr, fsc->sc_dmasize);
    606  1.27.8.2  nathanw 	}
    607  1.27.8.2  nathanw #endif
    608  1.27.8.2  nathanw 	fsc->sc_reg[0x80] = 0;
    609  1.27.8.2  nathanw 	*((u_long *)(fsc->sc_dmabase + (pa & 0x00fffffc))) = pa;
    610  1.27.8.2  nathanw 	fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    611  1.27.8.2  nathanw 	fsc->sc_portbits |= FLSC_PB_ENABLE_DMA |
    612  1.27.8.2  nathanw 	    (fsc->sc_datain ? FLSC_PB_DMA_READ : FLSC_PB_DMA_WRITE);
    613  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    614  1.27.8.2  nathanw 	NCR_DMA(("flsc_dma_setup: DMA %p->%lx/%d [%d]\n",
    615  1.27.8.2  nathanw 	    ptr, pa, fsc->sc_dmasize, *len));
    616  1.27.8.2  nathanw 	fsc->sc_active = 1;
    617  1.27.8.2  nathanw 	return 0;
    618  1.27.8.2  nathanw }
    619  1.27.8.2  nathanw 
    620  1.27.8.2  nathanw void
    621  1.27.8.2  nathanw flsc_dma_go(struct ncr53c9x_softc *sc)
    622  1.27.8.2  nathanw {
    623  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    624  1.27.8.2  nathanw 
    625  1.27.8.2  nathanw 	NCR_DMA(("flsc_dma_go: datain %d size %d\n", fsc->sc_datain,
    626  1.27.8.2  nathanw 	    fsc->sc_dmasize));
    627  1.27.8.2  nathanw 	if (sc->sc_nexus->xs->xs_control & XS_CTL_POLL) {
    628  1.27.8.2  nathanw 		fsc->sc_active = 1;
    629  1.27.8.2  nathanw 		return;
    630  1.27.8.2  nathanw 	} else if (fsc->sc_piomode == 0) {
    631  1.27.8.2  nathanw 		fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    632  1.27.8.2  nathanw 		fsc->sc_portbits |= FLSC_PB_ENABLE_DMA |
    633  1.27.8.2  nathanw 		    (fsc->sc_datain ? FLSC_PB_DMA_READ : FLSC_PB_DMA_WRITE);
    634  1.27.8.2  nathanw 		fsc->sc_reg[0x40] = fsc->sc_portbits;
    635  1.27.8.2  nathanw 	}
    636  1.27.8.2  nathanw }
    637  1.27.8.2  nathanw 
    638  1.27.8.2  nathanw void
    639  1.27.8.2  nathanw flsc_dma_stop(struct ncr53c9x_softc *sc)
    640  1.27.8.2  nathanw {
    641  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    642  1.27.8.2  nathanw 
    643  1.27.8.2  nathanw 	fsc->sc_portbits &= ~FLSC_PB_DMA_BITS;
    644  1.27.8.2  nathanw 	fsc->sc_reg[0x40] = fsc->sc_portbits;
    645  1.27.8.2  nathanw 
    646  1.27.8.2  nathanw 	fsc->sc_reg[0x80] = 0;
    647  1.27.8.2  nathanw 	*((u_long *)fsc->sc_dmabase) = 0;
    648  1.27.8.2  nathanw 	fsc->sc_piomode = 0;
    649  1.27.8.2  nathanw }
    650  1.27.8.2  nathanw 
    651  1.27.8.2  nathanw int
    652  1.27.8.2  nathanw flsc_dma_isactive(struct ncr53c9x_softc *sc)
    653  1.27.8.2  nathanw {
    654  1.27.8.2  nathanw 	struct flsc_softc *fsc = (struct flsc_softc *)sc;
    655  1.27.8.2  nathanw 
    656  1.27.8.2  nathanw 	return fsc->sc_active;
    657  1.27.8.2  nathanw }
    658