Home | History | Annotate | Line # | Download | only in dev
si_sebuf.c revision 1.14.6.3
      1  1.14.6.3  thorpej /*	$NetBSD: si_sebuf.c,v 1.14.6.3 2002/12/29 19:41:38 thorpej Exp $	*/
      2  1.14.6.2  nathanw 
      3  1.14.6.2  nathanw /*-
      4  1.14.6.2  nathanw  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  1.14.6.2  nathanw  * All rights reserved.
      6  1.14.6.2  nathanw  *
      7  1.14.6.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.14.6.2  nathanw  * by Gordon W. Ross.
      9  1.14.6.2  nathanw  *
     10  1.14.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.14.6.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.14.6.2  nathanw  * are met:
     13  1.14.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.14.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.14.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.14.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.14.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.14.6.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.14.6.2  nathanw  *    must display the following acknowledgement:
     20  1.14.6.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.14.6.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.14.6.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.14.6.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.14.6.2  nathanw  *    from this software without specific prior written permission.
     25  1.14.6.2  nathanw  *
     26  1.14.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.14.6.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.14.6.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.14.6.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.14.6.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.14.6.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.14.6.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.14.6.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.14.6.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.14.6.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.14.6.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.14.6.2  nathanw  */
     38  1.14.6.2  nathanw 
     39  1.14.6.2  nathanw /*
     40  1.14.6.2  nathanw  * Sun3/E SCSI driver (machine-dependent portion).
     41  1.14.6.2  nathanw  * The machine-independent parts are in ncr5380sbc.c
     42  1.14.6.2  nathanw  *
     43  1.14.6.2  nathanw  * XXX - Mostly from the si driver.  Merge?
     44  1.14.6.2  nathanw  */
     45  1.14.6.2  nathanw 
     46  1.14.6.2  nathanw #include <sys/param.h>
     47  1.14.6.2  nathanw #include <sys/systm.h>
     48  1.14.6.2  nathanw #include <sys/errno.h>
     49  1.14.6.2  nathanw #include <sys/kernel.h>
     50  1.14.6.2  nathanw #include <sys/malloc.h>
     51  1.14.6.2  nathanw #include <sys/device.h>
     52  1.14.6.2  nathanw #include <sys/buf.h>
     53  1.14.6.2  nathanw #include <sys/proc.h>
     54  1.14.6.2  nathanw #include <sys/user.h>
     55  1.14.6.2  nathanw 
     56  1.14.6.2  nathanw #include <dev/scsipi/scsi_all.h>
     57  1.14.6.2  nathanw #include <dev/scsipi/scsipi_all.h>
     58  1.14.6.2  nathanw #include <dev/scsipi/scsipi_debug.h>
     59  1.14.6.2  nathanw #include <dev/scsipi/scsiconf.h>
     60  1.14.6.2  nathanw 
     61  1.14.6.2  nathanw #include <machine/autoconf.h>
     62  1.14.6.2  nathanw 
     63  1.14.6.2  nathanw /* #define DEBUG XXX */
     64  1.14.6.2  nathanw 
     65  1.14.6.2  nathanw #include <dev/ic/ncr5380reg.h>
     66  1.14.6.2  nathanw #include <dev/ic/ncr5380var.h>
     67  1.14.6.2  nathanw 
     68  1.14.6.2  nathanw #include "sereg.h"
     69  1.14.6.2  nathanw #include "sevar.h"
     70  1.14.6.2  nathanw 
     71  1.14.6.2  nathanw /*
     72  1.14.6.2  nathanw  * Transfers smaller than this are done using PIO
     73  1.14.6.2  nathanw  * (on assumption they're not worth DMA overhead)
     74  1.14.6.2  nathanw  */
     75  1.14.6.2  nathanw #define	MIN_DMA_LEN 128
     76  1.14.6.2  nathanw 
     77  1.14.6.2  nathanw /*
     78  1.14.6.2  nathanw  * Transfers lager than 65535 bytes need to be split-up.
     79  1.14.6.2  nathanw  * (Some of the FIFO logic has only 16 bits counters.)
     80  1.14.6.2  nathanw  * Make the size an integer multiple of the page size
     81  1.14.6.2  nathanw  * to avoid buf/cluster remap problems.  (paranoid?)
     82  1.14.6.2  nathanw  */
     83  1.14.6.2  nathanw #define	MAX_DMA_LEN 0xE000
     84  1.14.6.2  nathanw 
     85  1.14.6.2  nathanw /*
     86  1.14.6.2  nathanw  * This structure is used to keep track of mapped DMA requests.
     87  1.14.6.2  nathanw  */
     88  1.14.6.2  nathanw struct se_dma_handle {
     89  1.14.6.2  nathanw 	int 		dh_flags;
     90  1.14.6.2  nathanw #define	SIDH_BUSY	1		/* This DH is in use */
     91  1.14.6.2  nathanw #define	SIDH_OUT	2		/* DMA does data out (write) */
     92  1.14.6.2  nathanw 	u_char *	dh_addr;	/* KVA of start of buffer */
     93  1.14.6.2  nathanw 	int 		dh_maplen;	/* Length of KVA mapping. */
     94  1.14.6.2  nathanw 	long		dh_dma; 	/* Offset in DMA buffer. */
     95  1.14.6.2  nathanw };
     96  1.14.6.2  nathanw 
     97  1.14.6.2  nathanw /*
     98  1.14.6.2  nathanw  * The first structure member has to be the ncr5380_softc
     99  1.14.6.2  nathanw  * so we can just cast to go back and fourth between them.
    100  1.14.6.2  nathanw  */
    101  1.14.6.2  nathanw struct se_softc {
    102  1.14.6.2  nathanw 	struct ncr5380_softc	ncr_sc;
    103  1.14.6.2  nathanw 	volatile struct se_regs	*sc_regs;
    104  1.14.6.2  nathanw 	int		sc_adapter_type;
    105  1.14.6.2  nathanw 	int		sc_adapter_iv;		/* int. vec */
    106  1.14.6.2  nathanw 	int 	sc_options;			/* options for this instance */
    107  1.14.6.2  nathanw 	int 	sc_reqlen;  		/* requested transfer length */
    108  1.14.6.2  nathanw 	struct se_dma_handle *sc_dma;
    109  1.14.6.2  nathanw 	/* DMA command block for the OBIO controller. */
    110  1.14.6.2  nathanw 	void *sc_dmacmd;
    111  1.14.6.2  nathanw };
    112  1.14.6.2  nathanw 
    113  1.14.6.2  nathanw /* Options for disconnect/reselect, DMA, and interrupts. */
    114  1.14.6.2  nathanw #define SE_NO_DISCONNECT    0xff
    115  1.14.6.2  nathanw #define SE_NO_PARITY_CHK  0xff00
    116  1.14.6.2  nathanw #define SE_FORCE_POLLING 0x10000
    117  1.14.6.2  nathanw #define SE_DISABLE_DMA   0x20000
    118  1.14.6.2  nathanw 
    119  1.14.6.2  nathanw void se_dma_alloc __P((struct ncr5380_softc *));
    120  1.14.6.2  nathanw void se_dma_free __P((struct ncr5380_softc *));
    121  1.14.6.2  nathanw void se_dma_poll __P((struct ncr5380_softc *));
    122  1.14.6.2  nathanw 
    123  1.14.6.2  nathanw void se_dma_setup __P((struct ncr5380_softc *));
    124  1.14.6.2  nathanw void se_dma_start __P((struct ncr5380_softc *));
    125  1.14.6.2  nathanw void se_dma_eop __P((struct ncr5380_softc *));
    126  1.14.6.2  nathanw void se_dma_stop __P((struct ncr5380_softc *));
    127  1.14.6.2  nathanw 
    128  1.14.6.2  nathanw void se_intr_on  __P((struct ncr5380_softc *));
    129  1.14.6.2  nathanw void se_intr_off __P((struct ncr5380_softc *));
    130  1.14.6.2  nathanw 
    131  1.14.6.2  nathanw static int  se_intr __P((void *));
    132  1.14.6.2  nathanw static void se_reset __P((struct ncr5380_softc *));
    133  1.14.6.2  nathanw 
    134  1.14.6.2  nathanw /*
    135  1.14.6.2  nathanw  * New-style autoconfig attachment
    136  1.14.6.2  nathanw  */
    137  1.14.6.2  nathanw 
    138  1.14.6.2  nathanw static int	se_match __P((struct device *, struct cfdata *, void *));
    139  1.14.6.2  nathanw static void	se_attach __P((struct device *, struct device *, void *));
    140  1.14.6.2  nathanw 
    141  1.14.6.2  nathanw CFATTACH_DECL(si_sebuf, sizeof(struct se_softc),
    142  1.14.6.2  nathanw     se_match, se_attach, NULL, NULL);
    143  1.14.6.2  nathanw 
    144  1.14.6.2  nathanw static void	se_minphys __P((struct buf *));
    145  1.14.6.2  nathanw 
    146  1.14.6.2  nathanw /* Options for disconnect/reselect, DMA, and interrupts. */
    147  1.14.6.2  nathanw int se_options = SE_DISABLE_DMA | SE_FORCE_POLLING | 0xff;
    148  1.14.6.2  nathanw 
    149  1.14.6.2  nathanw /* How long to wait for DMA before declaring an error. */
    150  1.14.6.2  nathanw int se_dma_intr_timo = 500;	/* ticks (sec. X 100) */
    151  1.14.6.2  nathanw 
    152  1.14.6.2  nathanw int se_debug = 0;
    153  1.14.6.2  nathanw 
    154  1.14.6.2  nathanw static int
    155  1.14.6.2  nathanw se_match(parent, cf, args)
    156  1.14.6.2  nathanw 	struct device	*parent;
    157  1.14.6.2  nathanw 	struct cfdata *cf;
    158  1.14.6.2  nathanw 	void *args;
    159  1.14.6.2  nathanw {
    160  1.14.6.2  nathanw 	struct sebuf_attach_args *aa = args;
    161  1.14.6.2  nathanw 
    162  1.14.6.2  nathanw 	/* Match by name. */
    163  1.14.6.2  nathanw 	if (strcmp(aa->name, "se"))
    164  1.14.6.2  nathanw 		return (0);
    165  1.14.6.2  nathanw 
    166  1.14.6.2  nathanw 	/* Anyting else to check? */
    167  1.14.6.2  nathanw 
    168  1.14.6.2  nathanw 	return (1);
    169  1.14.6.2  nathanw }
    170  1.14.6.2  nathanw 
    171  1.14.6.2  nathanw static void
    172  1.14.6.2  nathanw se_attach(parent, self, args)
    173  1.14.6.2  nathanw 	struct device	*parent, *self;
    174  1.14.6.2  nathanw 	void		*args;
    175  1.14.6.2  nathanw {
    176  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *) self;
    177  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
    178  1.14.6.2  nathanw 	struct cfdata *cf = self->dv_cfdata;
    179  1.14.6.2  nathanw 	struct sebuf_attach_args *aa = args;
    180  1.14.6.2  nathanw 	volatile struct se_regs *regs;
    181  1.14.6.2  nathanw 	int i;
    182  1.14.6.2  nathanw 
    183  1.14.6.2  nathanw 	/* Get options from config flags if specified. */
    184  1.14.6.2  nathanw 	if (cf->cf_flags)
    185  1.14.6.2  nathanw 		sc->sc_options = cf->cf_flags;
    186  1.14.6.2  nathanw 	else
    187  1.14.6.2  nathanw 		sc->sc_options = se_options;
    188  1.14.6.2  nathanw 
    189  1.14.6.2  nathanw 	printf(": options=0x%x\n", sc->sc_options);
    190  1.14.6.2  nathanw 
    191  1.14.6.2  nathanw 	sc->sc_adapter_type = aa->ca.ca_bustype;
    192  1.14.6.2  nathanw 	sc->sc_adapter_iv = aa->ca.ca_intvec;
    193  1.14.6.2  nathanw 	sc->sc_regs = regs = aa->regs;
    194  1.14.6.2  nathanw 
    195  1.14.6.2  nathanw 	/*
    196  1.14.6.2  nathanw 	 * MD function pointers used by the MI code.
    197  1.14.6.2  nathanw 	 */
    198  1.14.6.2  nathanw 	ncr_sc->sc_pio_out = ncr5380_pio_out;
    199  1.14.6.2  nathanw 	ncr_sc->sc_pio_in =  ncr5380_pio_in;
    200  1.14.6.2  nathanw 
    201  1.14.6.2  nathanw #if 0	/* XXX - not yet... */
    202  1.14.6.2  nathanw 	ncr_sc->sc_dma_alloc = se_dma_alloc;
    203  1.14.6.2  nathanw 	ncr_sc->sc_dma_free  = se_dma_free;
    204  1.14.6.2  nathanw 	ncr_sc->sc_dma_setup = se_dma_setup;
    205  1.14.6.2  nathanw 	ncr_sc->sc_dma_start = se_dma_start;
    206  1.14.6.2  nathanw 	ncr_sc->sc_dma_poll  = se_dma_poll;
    207  1.14.6.2  nathanw 	ncr_sc->sc_dma_eop   = se_dma_eop;
    208  1.14.6.2  nathanw 	ncr_sc->sc_dma_stop  = se_dma_stop;
    209  1.14.6.2  nathanw 	ncr_sc->sc_intr_on   = se_intr_on;
    210  1.14.6.2  nathanw 	ncr_sc->sc_intr_off  = se_intr_off;
    211  1.14.6.2  nathanw #endif	/* XXX */
    212  1.14.6.2  nathanw 
    213  1.14.6.2  nathanw 	/* Attach interrupt handler. */
    214  1.14.6.2  nathanw 	isr_add_vectored(se_intr, (void *)sc,
    215  1.14.6.2  nathanw 		aa->ca.ca_intpri, aa->ca.ca_intvec);
    216  1.14.6.2  nathanw 
    217  1.14.6.2  nathanw 	/* Reset the hardware. */
    218  1.14.6.2  nathanw 	se_reset(ncr_sc);
    219  1.14.6.2  nathanw 
    220  1.14.6.2  nathanw 	/* Do the common attach stuff. */
    221  1.14.6.2  nathanw 
    222  1.14.6.2  nathanw 	/*
    223  1.14.6.2  nathanw 	 * Support the "options" (config file flags).
    224  1.14.6.2  nathanw 	 * Disconnect/reselect is a per-target mask.
    225  1.14.6.2  nathanw 	 * Interrupts and DMA are per-controller.
    226  1.14.6.2  nathanw 	 */
    227  1.14.6.2  nathanw 	ncr_sc->sc_no_disconnect =
    228  1.14.6.2  nathanw 		(sc->sc_options & SE_NO_DISCONNECT);
    229  1.14.6.2  nathanw 	ncr_sc->sc_parity_disable =
    230  1.14.6.2  nathanw 		(sc->sc_options & SE_NO_PARITY_CHK) >> 8;
    231  1.14.6.2  nathanw 	if (sc->sc_options & SE_FORCE_POLLING)
    232  1.14.6.2  nathanw 		ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
    233  1.14.6.2  nathanw 
    234  1.14.6.2  nathanw #if 1	/* XXX - Temporary */
    235  1.14.6.2  nathanw 	/* XXX - In case we think DMA is completely broken... */
    236  1.14.6.2  nathanw 	if (sc->sc_options & SE_DISABLE_DMA) {
    237  1.14.6.2  nathanw 		/* Override this function pointer. */
    238  1.14.6.2  nathanw 		ncr_sc->sc_dma_alloc = NULL;
    239  1.14.6.2  nathanw 	}
    240  1.14.6.2  nathanw #endif
    241  1.14.6.2  nathanw 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    242  1.14.6.2  nathanw 
    243  1.14.6.2  nathanw 	/*
    244  1.14.6.2  nathanw 	 * Initialize fields used by the MI code
    245  1.14.6.2  nathanw 	 */
    246  1.14.6.2  nathanw 	ncr_sc->sci_r0 = &regs->ncrregs[0];
    247  1.14.6.2  nathanw 	ncr_sc->sci_r1 = &regs->ncrregs[1];
    248  1.14.6.2  nathanw 	ncr_sc->sci_r2 = &regs->ncrregs[2];
    249  1.14.6.2  nathanw 	ncr_sc->sci_r3 = &regs->ncrregs[3];
    250  1.14.6.2  nathanw 	ncr_sc->sci_r4 = &regs->ncrregs[4];
    251  1.14.6.2  nathanw 	ncr_sc->sci_r5 = &regs->ncrregs[5];
    252  1.14.6.2  nathanw 	ncr_sc->sci_r6 = &regs->ncrregs[6];
    253  1.14.6.2  nathanw 	ncr_sc->sci_r7 = &regs->ncrregs[7];
    254  1.14.6.2  nathanw 
    255  1.14.6.2  nathanw 	ncr_sc->sc_rev = NCR_VARIANT_NCR5380;
    256  1.14.6.2  nathanw 
    257  1.14.6.2  nathanw 	/*
    258  1.14.6.2  nathanw 	 * Allocate DMA handles.
    259  1.14.6.2  nathanw 	 */
    260  1.14.6.2  nathanw 	i = SCI_OPENINGS * sizeof(struct se_dma_handle);
    261  1.14.6.2  nathanw 	sc->sc_dma = (struct se_dma_handle *)
    262  1.14.6.2  nathanw 		malloc(i, M_DEVBUF, M_WAITOK);
    263  1.14.6.2  nathanw 	if (sc->sc_dma == NULL)
    264  1.14.6.2  nathanw 		panic("se: dma_malloc failed");
    265  1.14.6.2  nathanw 	for (i = 0; i < SCI_OPENINGS; i++)
    266  1.14.6.2  nathanw 		sc->sc_dma[i].dh_flags = 0;
    267  1.14.6.2  nathanw 
    268  1.14.6.2  nathanw 	ncr_sc->sc_channel.chan_id = 7;
    269  1.14.6.2  nathanw 	ncr_sc->sc_adapter.adapt_minphys = se_minphys;
    270  1.14.6.2  nathanw 
    271  1.14.6.2  nathanw 	/*
    272  1.14.6.2  nathanw 	 *  Initialize se board itself.
    273  1.14.6.2  nathanw 	 */
    274  1.14.6.2  nathanw 	ncr5380_attach(ncr_sc);
    275  1.14.6.2  nathanw }
    276  1.14.6.2  nathanw 
    277  1.14.6.2  nathanw static void
    278  1.14.6.2  nathanw se_reset(struct ncr5380_softc *ncr_sc)
    279  1.14.6.2  nathanw {
    280  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    281  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    282  1.14.6.2  nathanw 
    283  1.14.6.2  nathanw #ifdef	DEBUG
    284  1.14.6.2  nathanw 	if (se_debug) {
    285  1.14.6.2  nathanw 		printf("se_reset\n");
    286  1.14.6.2  nathanw 	}
    287  1.14.6.2  nathanw #endif
    288  1.14.6.2  nathanw 
    289  1.14.6.2  nathanw 	/* The reset bits in the CSR are active low. */
    290  1.14.6.2  nathanw 	se->se_csr = 0;
    291  1.14.6.2  nathanw 	delay(10);
    292  1.14.6.2  nathanw 	se->se_csr = SE_CSR_SCSI_RES /* | SE_CSR_INTR_EN */ ;
    293  1.14.6.2  nathanw 	delay(10);
    294  1.14.6.2  nathanw 
    295  1.14.6.2  nathanw 	/* Make sure the DMA engine is stopped. */
    296  1.14.6.2  nathanw 	se->dma_addr = 0;
    297  1.14.6.2  nathanw 	se->dma_cntr = 0;
    298  1.14.6.2  nathanw 	se->se_ivec = sc->sc_adapter_iv;
    299  1.14.6.2  nathanw }
    300  1.14.6.2  nathanw 
    301  1.14.6.2  nathanw /*
    302  1.14.6.2  nathanw  * This is called when the bus is going idle,
    303  1.14.6.2  nathanw  * so we want to enable the SBC interrupts.
    304  1.14.6.2  nathanw  * That is controlled by the DMA enable!
    305  1.14.6.2  nathanw  * Who would have guessed!
    306  1.14.6.2  nathanw  * What a NASTY trick!
    307  1.14.6.2  nathanw  */
    308  1.14.6.2  nathanw void
    309  1.14.6.2  nathanw se_intr_on(ncr_sc)
    310  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    311  1.14.6.2  nathanw {
    312  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    313  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    314  1.14.6.2  nathanw 
    315  1.14.6.2  nathanw 	/* receive mode should be safer */
    316  1.14.6.2  nathanw 	se->se_csr &= ~SE_CSR_SEND;
    317  1.14.6.2  nathanw 
    318  1.14.6.2  nathanw 	/* Clear the count so nothing happens. */
    319  1.14.6.2  nathanw 	se->dma_cntr = 0;
    320  1.14.6.2  nathanw 
    321  1.14.6.2  nathanw 	/* Clear the start address too. (paranoid?) */
    322  1.14.6.2  nathanw 	se->dma_addr = 0;
    323  1.14.6.2  nathanw 
    324  1.14.6.2  nathanw 	/* Finally, enable the DMA engine. */
    325  1.14.6.2  nathanw 	se->se_csr |= SE_CSR_INTR_EN;
    326  1.14.6.2  nathanw }
    327  1.14.6.2  nathanw 
    328  1.14.6.2  nathanw /*
    329  1.14.6.2  nathanw  * This is called when the bus is idle and we are
    330  1.14.6.2  nathanw  * about to start playing with the SBC chip.
    331  1.14.6.2  nathanw  */
    332  1.14.6.2  nathanw void
    333  1.14.6.2  nathanw se_intr_off(ncr_sc)
    334  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    335  1.14.6.2  nathanw {
    336  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    337  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    338  1.14.6.2  nathanw 
    339  1.14.6.2  nathanw 	se->se_csr &= ~SE_CSR_INTR_EN;
    340  1.14.6.2  nathanw }
    341  1.14.6.2  nathanw 
    342  1.14.6.2  nathanw /*
    343  1.14.6.2  nathanw  * This function is called during the COMMAND or MSG_IN phase
    344  1.14.6.2  nathanw  * that precedes a DATA_IN or DATA_OUT phase, in case we need
    345  1.14.6.2  nathanw  * to setup the DMA engine before the bus enters a DATA phase.
    346  1.14.6.2  nathanw  *
    347  1.14.6.2  nathanw  * On the VME version, setup the start addres, but clear the
    348  1.14.6.2  nathanw  * count (to make sure it stays idle) and set that later.
    349  1.14.6.2  nathanw  * XXX: The VME adapter appears to suppress SBC interrupts
    350  1.14.6.2  nathanw  * when the FIFO is not empty or the FIFO count is non-zero!
    351  1.14.6.2  nathanw  * XXX: Need to copy data into the DMA buffer...
    352  1.14.6.2  nathanw  */
    353  1.14.6.2  nathanw void
    354  1.14.6.2  nathanw se_dma_setup(ncr_sc)
    355  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    356  1.14.6.2  nathanw {
    357  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    358  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    359  1.14.6.2  nathanw 	struct se_dma_handle *dh = sr->sr_dma_hand;
    360  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    361  1.14.6.2  nathanw 	long data_pa;
    362  1.14.6.2  nathanw 	int xlen;
    363  1.14.6.2  nathanw 
    364  1.14.6.2  nathanw 	/*
    365  1.14.6.2  nathanw 	 * Get the DMA mapping for this segment.
    366  1.14.6.2  nathanw 	 * XXX - Should separate allocation and mapin.
    367  1.14.6.2  nathanw 	 */
    368  1.14.6.2  nathanw 	data_pa = 0; /* XXX se_dma_kvtopa(dh->dh_dma); */
    369  1.14.6.2  nathanw 	data_pa += (ncr_sc->sc_dataptr - dh->dh_addr);
    370  1.14.6.2  nathanw 	if (data_pa & 1)
    371  1.14.6.2  nathanw 		panic("se_dma_start: bad pa=0x%lx", data_pa);
    372  1.14.6.2  nathanw 	xlen = ncr_sc->sc_datalen;
    373  1.14.6.2  nathanw 	xlen &= ~1;				/* XXX: necessary? */
    374  1.14.6.2  nathanw 	sc->sc_reqlen = xlen; 	/* XXX: or less? */
    375  1.14.6.2  nathanw 
    376  1.14.6.2  nathanw #ifdef	DEBUG
    377  1.14.6.2  nathanw 	if (se_debug & 2) {
    378  1.14.6.2  nathanw 		printf("se_dma_setup: dh=%p, pa=0x%lx, xlen=0x%x\n",
    379  1.14.6.2  nathanw 			   dh, data_pa, xlen);
    380  1.14.6.2  nathanw 	}
    381  1.14.6.2  nathanw #endif
    382  1.14.6.2  nathanw 
    383  1.14.6.2  nathanw 	/* Set direction (send/recv) */
    384  1.14.6.2  nathanw 	if (dh->dh_flags & SIDH_OUT) {
    385  1.14.6.2  nathanw 		se->se_csr |= SE_CSR_SEND;
    386  1.14.6.2  nathanw 	} else {
    387  1.14.6.2  nathanw 		se->se_csr &= ~SE_CSR_SEND;
    388  1.14.6.2  nathanw 	}
    389  1.14.6.2  nathanw 
    390  1.14.6.2  nathanw 	/* Load the start address. */
    391  1.14.6.2  nathanw 	se->dma_addr = (ushort)(data_pa & 0xFFFF);
    392  1.14.6.2  nathanw 
    393  1.14.6.2  nathanw 	/*
    394  1.14.6.2  nathanw 	 * Keep the count zero or it may start early!
    395  1.14.6.2  nathanw 	 */
    396  1.14.6.2  nathanw 	se->dma_cntr = 0;
    397  1.14.6.2  nathanw }
    398  1.14.6.2  nathanw 
    399  1.14.6.2  nathanw 
    400  1.14.6.2  nathanw void
    401  1.14.6.2  nathanw se_dma_start(ncr_sc)
    402  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    403  1.14.6.2  nathanw {
    404  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    405  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    406  1.14.6.2  nathanw 	struct se_dma_handle *dh = sr->sr_dma_hand;
    407  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    408  1.14.6.2  nathanw 	int s, xlen;
    409  1.14.6.2  nathanw 
    410  1.14.6.2  nathanw 	xlen = sc->sc_reqlen;
    411  1.14.6.2  nathanw 
    412  1.14.6.2  nathanw 	/* This MAY be time critical (not sure). */
    413  1.14.6.2  nathanw 	s = splhigh();
    414  1.14.6.2  nathanw 
    415  1.14.6.2  nathanw 	se->dma_cntr = (ushort)(xlen & 0xFFFF);
    416  1.14.6.2  nathanw 
    417  1.14.6.2  nathanw 	/*
    418  1.14.6.2  nathanw 	 * Acknowledge the phase change.  (After DMA setup!)
    419  1.14.6.2  nathanw 	 * Put the SBIC into DMA mode, and start the transfer.
    420  1.14.6.2  nathanw 	 */
    421  1.14.6.2  nathanw 	if (dh->dh_flags & SIDH_OUT) {
    422  1.14.6.2  nathanw 		*ncr_sc->sci_tcmd = PHASE_DATA_OUT;
    423  1.14.6.2  nathanw 		SCI_CLR_INTR(ncr_sc);
    424  1.14.6.2  nathanw 		*ncr_sc->sci_icmd = SCI_ICMD_DATA;
    425  1.14.6.2  nathanw 		*ncr_sc->sci_mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
    426  1.14.6.2  nathanw 		*ncr_sc->sci_dma_send = 0;	/* start it */
    427  1.14.6.2  nathanw 	} else {
    428  1.14.6.2  nathanw 		*ncr_sc->sci_tcmd = PHASE_DATA_IN;
    429  1.14.6.2  nathanw 		SCI_CLR_INTR(ncr_sc);
    430  1.14.6.2  nathanw 		*ncr_sc->sci_icmd = 0;
    431  1.14.6.2  nathanw 		*ncr_sc->sci_mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
    432  1.14.6.2  nathanw 		*ncr_sc->sci_irecv = 0;	/* start it */
    433  1.14.6.2  nathanw 	}
    434  1.14.6.2  nathanw 
    435  1.14.6.2  nathanw 	/* Let'er rip! */
    436  1.14.6.2  nathanw 	se->se_csr |= SE_CSR_INTR_EN;
    437  1.14.6.2  nathanw 
    438  1.14.6.2  nathanw 	splx(s);
    439  1.14.6.2  nathanw 	ncr_sc->sc_state |= NCR_DOINGDMA;
    440  1.14.6.2  nathanw 
    441  1.14.6.2  nathanw #ifdef	DEBUG
    442  1.14.6.2  nathanw 	if (se_debug & 2) {
    443  1.14.6.2  nathanw 		printf("se_dma_start: started, flags=0x%x\n",
    444  1.14.6.2  nathanw 			   ncr_sc->sc_state);
    445  1.14.6.2  nathanw 	}
    446  1.14.6.2  nathanw #endif
    447  1.14.6.2  nathanw }
    448  1.14.6.2  nathanw 
    449  1.14.6.2  nathanw 
    450  1.14.6.2  nathanw void
    451  1.14.6.2  nathanw se_dma_eop(ncr_sc)
    452  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    453  1.14.6.2  nathanw {
    454  1.14.6.2  nathanw 
    455  1.14.6.2  nathanw 	/* Not needed - DMA was stopped prior to examining sci_csr */
    456  1.14.6.2  nathanw }
    457  1.14.6.2  nathanw 
    458  1.14.6.2  nathanw 
    459  1.14.6.2  nathanw void
    460  1.14.6.2  nathanw se_dma_stop(ncr_sc)
    461  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    462  1.14.6.2  nathanw {
    463  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    464  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    465  1.14.6.2  nathanw 	struct se_dma_handle *dh = sr->sr_dma_hand;
    466  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    467  1.14.6.2  nathanw 	int resid, ntrans;
    468  1.14.6.2  nathanw 
    469  1.14.6.2  nathanw 	if ((ncr_sc->sc_state & NCR_DOINGDMA) == 0) {
    470  1.14.6.2  nathanw #ifdef	DEBUG
    471  1.14.6.2  nathanw 		printf("se_dma_stop: dma not running\n");
    472  1.14.6.2  nathanw #endif
    473  1.14.6.2  nathanw 		return;
    474  1.14.6.2  nathanw 	}
    475  1.14.6.2  nathanw 	ncr_sc->sc_state &= ~NCR_DOINGDMA;
    476  1.14.6.2  nathanw 
    477  1.14.6.2  nathanw 	/* First, halt the DMA engine. */
    478  1.14.6.2  nathanw 	se->se_csr &= ~SE_CSR_INTR_EN;	/* VME only */
    479  1.14.6.2  nathanw 
    480  1.14.6.2  nathanw 	/* Set an impossible phase to prevent data movement? */
    481  1.14.6.2  nathanw 	*ncr_sc->sci_tcmd = PHASE_INVALID;
    482  1.14.6.2  nathanw 
    483  1.14.6.2  nathanw 	/* Note that timeout may have set the error flag. */
    484  1.14.6.2  nathanw 	if (ncr_sc->sc_state & NCR_ABORTING)
    485  1.14.6.2  nathanw 		goto out;
    486  1.14.6.2  nathanw 
    487  1.14.6.2  nathanw 	/* XXX: Wait for DMA to actually finish? */
    488  1.14.6.2  nathanw 
    489  1.14.6.2  nathanw 	/*
    490  1.14.6.2  nathanw 	 * Now try to figure out how much actually transferred
    491  1.14.6.2  nathanw 	 */
    492  1.14.6.2  nathanw 	resid = se->dma_cntr & 0xFFFF;
    493  1.14.6.2  nathanw 	if (dh->dh_flags & SIDH_OUT)
    494  1.14.6.2  nathanw 		if ((resid > 0) && (resid < sc->sc_reqlen))
    495  1.14.6.2  nathanw 			resid++;
    496  1.14.6.2  nathanw 	ntrans = sc->sc_reqlen - resid;
    497  1.14.6.2  nathanw 
    498  1.14.6.2  nathanw #ifdef	DEBUG
    499  1.14.6.2  nathanw 	if (se_debug & 2) {
    500  1.14.6.2  nathanw 		printf("se_dma_stop: resid=0x%x ntrans=0x%x\n",
    501  1.14.6.2  nathanw 		       resid, ntrans);
    502  1.14.6.2  nathanw 	}
    503  1.14.6.2  nathanw #endif
    504  1.14.6.2  nathanw 
    505  1.14.6.2  nathanw 	if (ntrans < MIN_DMA_LEN) {
    506  1.14.6.2  nathanw 		printf("se: fifo count: 0x%x\n", resid);
    507  1.14.6.2  nathanw 		ncr_sc->sc_state |= NCR_ABORTING;
    508  1.14.6.2  nathanw 		goto out;
    509  1.14.6.2  nathanw 	}
    510  1.14.6.2  nathanw 	if (ntrans > ncr_sc->sc_datalen)
    511  1.14.6.2  nathanw 		panic("se_dma_stop: excess transfer");
    512  1.14.6.2  nathanw 
    513  1.14.6.2  nathanw 	/* Adjust data pointer */
    514  1.14.6.2  nathanw 	ncr_sc->sc_dataptr += ntrans;
    515  1.14.6.2  nathanw 	ncr_sc->sc_datalen -= ntrans;
    516  1.14.6.2  nathanw 
    517  1.14.6.2  nathanw out:
    518  1.14.6.2  nathanw 	se->dma_addr = 0;
    519  1.14.6.2  nathanw 	se->dma_cntr = 0;
    520  1.14.6.2  nathanw 
    521  1.14.6.2  nathanw 	/* Put SBIC back in PIO mode. */
    522  1.14.6.2  nathanw 	*ncr_sc->sci_mode &= ~(SCI_MODE_DMA | SCI_MODE_DMA_IE);
    523  1.14.6.2  nathanw 	*ncr_sc->sci_icmd = 0;
    524  1.14.6.2  nathanw }
    525  1.14.6.2  nathanw 
    526  1.14.6.2  nathanw /*****************************************************************/
    527  1.14.6.2  nathanw 
    528  1.14.6.2  nathanw static void
    529  1.14.6.2  nathanw se_minphys(struct buf *bp)
    530  1.14.6.2  nathanw {
    531  1.14.6.2  nathanw 
    532  1.14.6.2  nathanw 	if (bp->b_bcount > MAX_DMA_LEN)
    533  1.14.6.2  nathanw 		bp->b_bcount = MAX_DMA_LEN;
    534  1.14.6.2  nathanw 
    535  1.14.6.3  thorpej 	minphys(bp);
    536  1.14.6.2  nathanw }
    537  1.14.6.2  nathanw 
    538  1.14.6.2  nathanw 
    539  1.14.6.2  nathanw int
    540  1.14.6.2  nathanw se_intr(void *arg)
    541  1.14.6.2  nathanw {
    542  1.14.6.2  nathanw 	struct se_softc *sc = arg;
    543  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    544  1.14.6.2  nathanw 	int dma_error, claimed;
    545  1.14.6.2  nathanw 	u_short csr;
    546  1.14.6.2  nathanw 
    547  1.14.6.2  nathanw 	claimed = 0;
    548  1.14.6.2  nathanw 	dma_error = 0;
    549  1.14.6.2  nathanw 
    550  1.14.6.2  nathanw 	/* SBC interrupt? DMA interrupt? */
    551  1.14.6.2  nathanw 	csr = se->se_csr;
    552  1.14.6.2  nathanw 	NCR_TRACE("se_intr: csr=0x%x\n", csr);
    553  1.14.6.2  nathanw 
    554  1.14.6.2  nathanw 	if (csr & SE_CSR_SBC_IP) {
    555  1.14.6.2  nathanw 		claimed = ncr5380_intr(&sc->ncr_sc);
    556  1.14.6.2  nathanw #ifdef	DEBUG
    557  1.14.6.2  nathanw 		if (!claimed) {
    558  1.14.6.2  nathanw 			printf("se_intr: spurious from SBC\n");
    559  1.14.6.2  nathanw 		}
    560  1.14.6.2  nathanw #endif
    561  1.14.6.2  nathanw 		/* Yes, we DID cause this interrupt. */
    562  1.14.6.2  nathanw 		claimed = 1;
    563  1.14.6.2  nathanw 	}
    564  1.14.6.2  nathanw 
    565  1.14.6.2  nathanw 	return (claimed);
    566  1.14.6.2  nathanw }
    567  1.14.6.2  nathanw 
    568  1.14.6.2  nathanw 
    569  1.14.6.2  nathanw /*****************************************************************
    570  1.14.6.2  nathanw  * Common functions for DMA
    571  1.14.6.2  nathanw  ****************************************************************/
    572  1.14.6.2  nathanw 
    573  1.14.6.2  nathanw /*
    574  1.14.6.2  nathanw  * Allocate a DMA handle and put it in sc->sc_dma.  Prepare
    575  1.14.6.2  nathanw  * for DMA transfer.  On the Sun3/E, this means we have to
    576  1.14.6.2  nathanw  * allocate space in the DMA buffer for this transfer.
    577  1.14.6.2  nathanw  */
    578  1.14.6.2  nathanw void
    579  1.14.6.2  nathanw se_dma_alloc(ncr_sc)
    580  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    581  1.14.6.2  nathanw {
    582  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    583  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    584  1.14.6.2  nathanw 	struct scsipi_xfer *xs = sr->sr_xs;
    585  1.14.6.2  nathanw 	struct se_dma_handle *dh;
    586  1.14.6.2  nathanw 	int i, xlen;
    587  1.14.6.2  nathanw 	u_long addr;
    588  1.14.6.2  nathanw 
    589  1.14.6.2  nathanw #ifdef	DIAGNOSTIC
    590  1.14.6.2  nathanw 	if (sr->sr_dma_hand != NULL)
    591  1.14.6.2  nathanw 		panic("se_dma_alloc: already have DMA handle");
    592  1.14.6.2  nathanw #endif
    593  1.14.6.2  nathanw 
    594  1.14.6.2  nathanw 	addr = (u_long) ncr_sc->sc_dataptr;
    595  1.14.6.2  nathanw 	xlen = ncr_sc->sc_datalen;
    596  1.14.6.2  nathanw 
    597  1.14.6.2  nathanw 	/* If the DMA start addr is misaligned then do PIO */
    598  1.14.6.2  nathanw 	if ((addr & 1) || (xlen & 1)) {
    599  1.14.6.2  nathanw 		printf("se_dma_alloc: misaligned.\n");
    600  1.14.6.2  nathanw 		return;
    601  1.14.6.2  nathanw 	}
    602  1.14.6.2  nathanw 
    603  1.14.6.2  nathanw 	/* Make sure our caller checked sc_min_dma_len. */
    604  1.14.6.2  nathanw 	if (xlen < MIN_DMA_LEN)
    605  1.14.6.2  nathanw 		panic("se_dma_alloc: xlen=0x%x", xlen);
    606  1.14.6.2  nathanw 
    607  1.14.6.2  nathanw 	/*
    608  1.14.6.2  nathanw 	 * Never attempt single transfers of more than 63k, because
    609  1.14.6.2  nathanw 	 * our count register may be only 16 bits (an OBIO adapter).
    610  1.14.6.2  nathanw 	 * This should never happen since already bounded by minphys().
    611  1.14.6.2  nathanw 	 * XXX - Should just segment these...
    612  1.14.6.2  nathanw 	 */
    613  1.14.6.2  nathanw 	if (xlen > MAX_DMA_LEN) {
    614  1.14.6.2  nathanw 		printf("se_dma_alloc: excessive xlen=0x%x\n", xlen);
    615  1.14.6.2  nathanw 		ncr_sc->sc_datalen = xlen = MAX_DMA_LEN;
    616  1.14.6.2  nathanw 	}
    617  1.14.6.2  nathanw 
    618  1.14.6.2  nathanw 	/* Find free DMA handle.  Guaranteed to find one since we have
    619  1.14.6.2  nathanw 	   as many DMA handles as the driver has processes. */
    620  1.14.6.2  nathanw 	for (i = 0; i < SCI_OPENINGS; i++) {
    621  1.14.6.2  nathanw 		if ((sc->sc_dma[i].dh_flags & SIDH_BUSY) == 0)
    622  1.14.6.2  nathanw 			goto found;
    623  1.14.6.2  nathanw 	}
    624  1.14.6.2  nathanw 	panic("se: no free DMA handles.");
    625  1.14.6.2  nathanw found:
    626  1.14.6.2  nathanw 
    627  1.14.6.2  nathanw 	dh = &sc->sc_dma[i];
    628  1.14.6.2  nathanw 	dh->dh_flags = SIDH_BUSY;
    629  1.14.6.2  nathanw 
    630  1.14.6.2  nathanw 	/* Copy the "write" flag for convenience. */
    631  1.14.6.2  nathanw 	if (xs->xs_control & XS_CTL_DATA_OUT)
    632  1.14.6.2  nathanw 		dh->dh_flags |= SIDH_OUT;
    633  1.14.6.2  nathanw 
    634  1.14.6.2  nathanw 	dh->dh_addr = (u_char*) addr;
    635  1.14.6.2  nathanw 	dh->dh_maplen  = xlen;
    636  1.14.6.2  nathanw 	dh->dh_dma = 0;	/* XXX - Allocate space in DMA buffer. */
    637  1.14.6.2  nathanw 	/* XXX: dh->dh_dma = alloc(xlen) */
    638  1.14.6.2  nathanw 	if (!dh->dh_dma) {
    639  1.14.6.2  nathanw 		/* Can't remap segment */
    640  1.14.6.2  nathanw 		printf("se_dma_alloc: can't remap %p/0x%x\n",
    641  1.14.6.2  nathanw 			dh->dh_addr, dh->dh_maplen);
    642  1.14.6.2  nathanw 		dh->dh_flags = 0;
    643  1.14.6.2  nathanw 		return;
    644  1.14.6.2  nathanw 	}
    645  1.14.6.2  nathanw 
    646  1.14.6.2  nathanw 	/* success */
    647  1.14.6.2  nathanw 	sr->sr_dma_hand = dh;
    648  1.14.6.2  nathanw 
    649  1.14.6.2  nathanw 	return;
    650  1.14.6.2  nathanw }
    651  1.14.6.2  nathanw 
    652  1.14.6.2  nathanw 
    653  1.14.6.2  nathanw void
    654  1.14.6.2  nathanw se_dma_free(ncr_sc)
    655  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    656  1.14.6.2  nathanw {
    657  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    658  1.14.6.2  nathanw 	struct se_dma_handle *dh = sr->sr_dma_hand;
    659  1.14.6.2  nathanw 
    660  1.14.6.2  nathanw #ifdef	DIAGNOSTIC
    661  1.14.6.2  nathanw 	if (dh == NULL)
    662  1.14.6.2  nathanw 		panic("se_dma_free: no DMA handle");
    663  1.14.6.2  nathanw #endif
    664  1.14.6.2  nathanw 
    665  1.14.6.2  nathanw 	if (ncr_sc->sc_state & NCR_DOINGDMA)
    666  1.14.6.2  nathanw 		panic("se_dma_free: free while in progress");
    667  1.14.6.2  nathanw 
    668  1.14.6.2  nathanw 	if (dh->dh_flags & SIDH_BUSY) {
    669  1.14.6.2  nathanw 		/* XXX: Should separate allocation and mapping. */
    670  1.14.6.2  nathanw 		/* XXX: Give back the DMA space. */
    671  1.14.6.2  nathanw 		/* XXX: free((caddr_t)dh->dh_dma, dh->dh_maplen); */
    672  1.14.6.2  nathanw 		dh->dh_dma = 0;
    673  1.14.6.2  nathanw 		dh->dh_flags = 0;
    674  1.14.6.2  nathanw 	}
    675  1.14.6.2  nathanw 	sr->sr_dma_hand = NULL;
    676  1.14.6.2  nathanw }
    677  1.14.6.2  nathanw 
    678  1.14.6.2  nathanw 
    679  1.14.6.2  nathanw #define	CSR_MASK SE_CSR_SBC_IP
    680  1.14.6.2  nathanw #define	POLL_TIMO	50000	/* X100 = 5 sec. */
    681  1.14.6.2  nathanw 
    682  1.14.6.2  nathanw /*
    683  1.14.6.2  nathanw  * Poll (spin-wait) for DMA completion.
    684  1.14.6.2  nathanw  * Called right after xx_dma_start(), and
    685  1.14.6.2  nathanw  * xx_dma_stop() will be called next.
    686  1.14.6.2  nathanw  * Same for either VME or OBIO.
    687  1.14.6.2  nathanw  */
    688  1.14.6.2  nathanw void
    689  1.14.6.2  nathanw se_dma_poll(ncr_sc)
    690  1.14.6.2  nathanw 	struct ncr5380_softc *ncr_sc;
    691  1.14.6.2  nathanw {
    692  1.14.6.2  nathanw 	struct se_softc *sc = (struct se_softc *)ncr_sc;
    693  1.14.6.2  nathanw 	struct sci_req *sr = ncr_sc->sc_current;
    694  1.14.6.2  nathanw 	volatile struct se_regs *se = sc->sc_regs;
    695  1.14.6.2  nathanw 	int tmo;
    696  1.14.6.2  nathanw 
    697  1.14.6.2  nathanw 	/* Make sure DMA started successfully. */
    698  1.14.6.2  nathanw 	if (ncr_sc->sc_state & NCR_ABORTING)
    699  1.14.6.2  nathanw 		return;
    700  1.14.6.2  nathanw 
    701  1.14.6.2  nathanw 	/*
    702  1.14.6.2  nathanw 	 * XXX: The Sun driver waits for ~SE_CSR_DMA_ACTIVE here
    703  1.14.6.2  nathanw 	 * XXX: (on obio) or even worse (on vme) a 10mS. delay!
    704  1.14.6.2  nathanw 	 * XXX: I really doubt that is necessary...
    705  1.14.6.2  nathanw 	 */
    706  1.14.6.2  nathanw 
    707  1.14.6.2  nathanw 	/* Wait for any "dma complete" or error bits. */
    708  1.14.6.2  nathanw 	tmo = POLL_TIMO;
    709  1.14.6.2  nathanw 	for (;;) {
    710  1.14.6.2  nathanw 		if (se->se_csr & CSR_MASK)
    711  1.14.6.2  nathanw 			break;
    712  1.14.6.2  nathanw 		if (--tmo <= 0) {
    713  1.14.6.2  nathanw 			printf("se: DMA timeout (while polling)\n");
    714  1.14.6.2  nathanw 			/* Indicate timeout as MI code would. */
    715  1.14.6.2  nathanw 			sr->sr_flags |= SR_OVERDUE;
    716  1.14.6.2  nathanw 			break;
    717  1.14.6.2  nathanw 		}
    718  1.14.6.2  nathanw 		delay(100);
    719  1.14.6.2  nathanw 	}
    720  1.14.6.2  nathanw 	NCR_TRACE("se_dma_poll: waited %d\n",
    721  1.14.6.2  nathanw 			  POLL_TIMO - tmo);
    722  1.14.6.2  nathanw 
    723  1.14.6.2  nathanw #ifdef	DEBUG
    724  1.14.6.2  nathanw 	if (se_debug & 2) {
    725  1.14.6.2  nathanw 		printf("se_dma_poll: done, csr=0x%x\n", se->se_csr);
    726  1.14.6.2  nathanw 	}
    727  1.14.6.2  nathanw #endif
    728  1.14.6.2  nathanw }
    729  1.14.6.2  nathanw 
    730