2001-04-25 21:53:04 +04:00
|
|
|
/* $NetBSD: si.c,v 1.3 2001/04/25 17:53:43 bouyer Exp $ */
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-12-09 20:46:44 +03:00
|
|
|
/*-
|
2000-07-04 03:30:33 +04:00
|
|
|
* Copyright (c) 1996,2000 The NetBSD Foundation, Inc.
|
1995-07-09 01:32:47 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1996-12-09 20:46:44 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-07-04 03:30:33 +04:00
|
|
|
* by Adam Glass, David Jones, Gordon W. Ross, Jason R. Thorpe and
|
|
|
|
* Paul Kranenburg.
|
1996-12-09 20:46:44 +03:00
|
|
|
*
|
1995-07-09 01:32:47 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1996-12-09 20:46:44 +03:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
1995-07-09 01:32:47 +04:00
|
|
|
* must display the following acknowledgement:
|
1996-12-09 20:46:44 +03:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1995-07-09 01:32:47 +04:00
|
|
|
*
|
1996-12-09 20:46:44 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1997-10-09 12:37:20 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-12-09 20:46:44 +03:00
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
1995-07-09 01:32:47 +04:00
|
|
|
*/
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
2000-07-04 03:30:33 +04:00
|
|
|
* This file contains VME bus-dependent of the `si' SCSI adapter.
|
|
|
|
* This hardware is frequently found on Sun 3 and Sun 4 machines.
|
1996-01-02 01:40:56 +03:00
|
|
|
*
|
2000-07-04 03:30:33 +04:00
|
|
|
* The SCSI machinery on this adapter is implemented by an NCR5380,
|
|
|
|
* which is taken care of by the chipset driver in /sys/dev/ic/ncr5380sbc.c
|
1996-01-02 01:40:56 +03:00
|
|
|
*
|
2000-07-04 03:30:33 +04:00
|
|
|
* The logic has a bit to enable or disable the DMA engine,
|
1996-01-02 01:40:56 +03:00
|
|
|
* but that bit also gates the interrupt line from the NCR5380!
|
|
|
|
* Therefore, in order to get any interrupt from the 5380, (i.e.
|
|
|
|
* for reselect) one must clear the DMA engine transfer count and
|
|
|
|
* then enable DMA. This has the further complication that you
|
|
|
|
* CAN NOT touch the NCR5380 while the DMA enable bit is set, so
|
|
|
|
* we have to turn DMA back off before we even look at the 5380.
|
|
|
|
*
|
|
|
|
* What wonderfully whacky hardware this is!
|
|
|
|
*
|
2000-07-04 03:30:33 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This driver originated as an MD implementation for the sun3 and sun4
|
|
|
|
* ports. The notes pertaining to that history are included below.
|
|
|
|
*
|
1996-01-02 01:40:56 +03:00
|
|
|
* David Jones wrote the initial version of this module for NetBSD/sun3,
|
|
|
|
* which included support for the VME adapter only. (no reselection).
|
|
|
|
*
|
|
|
|
* Gordon Ross added support for the Sun 3 OBIO adapter, and re-worked
|
|
|
|
* both the VME and OBIO code to support disconnect/reselect.
|
|
|
|
* (Required figuring out the hardware "features" noted above.)
|
|
|
|
*
|
|
|
|
* The autoconfiguration boilerplate came from Adam Glass.
|
|
|
|
*
|
|
|
|
* Jason R. Thorpe ported the autoconfiguration and VME portions to
|
|
|
|
* NetBSD/sparc, and added initial support for the 4/100 "SCSI Weird",
|
|
|
|
* a wacky OBIO variant of the VME SCSI-3. Many thanks to Chuck Cranor
|
|
|
|
* for lots of helpful tips and suggestions. Thanks also to Paul Kranenburg
|
|
|
|
* and Chris Torek for bits of insight needed along the way. Thanks to
|
|
|
|
* David Gilbert and Andrew Gillham who risked filesystem life-and-limb
|
1996-02-23 10:24:45 +03:00
|
|
|
* for the sake of testing. Andrew Gillham helped work out the bugs
|
2000-03-14 02:52:25 +03:00
|
|
|
* the 4/100 DMA code.
|
1996-01-02 01:40:56 +03:00
|
|
|
*/
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
1995-07-09 01:32:47 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1996-01-02 01:40:56 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1995-07-09 01:32:47 +04:00
|
|
|
#include <sys/errno.h>
|
1996-01-02 01:40:56 +03:00
|
|
|
#include <sys/device.h>
|
1995-07-09 01:32:47 +04:00
|
|
|
#include <sys/buf.h>
|
|
|
|
|
1998-01-25 19:37:08 +03:00
|
|
|
#include <machine/bus.h>
|
1999-06-30 19:18:58 +04:00
|
|
|
#include <machine/intr.h>
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-25 17:09:52 +04:00
|
|
|
#include <dev/vme/vmereg.h>
|
1998-01-25 19:37:08 +03:00
|
|
|
#include <dev/vme/vmevar.h>
|
|
|
|
|
1997-10-16 14:49:00 +04:00
|
|
|
#include <dev/scsipi/scsi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
|
|
|
#include <dev/scsipi/scsipi_debug.h>
|
|
|
|
#include <dev/scsipi/scsiconf.h>
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
#ifndef DDB
|
|
|
|
#define Debugger()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
#define DEBUG XXX
|
|
|
|
#endif
|
1995-07-09 01:32:47 +04:00
|
|
|
|
|
|
|
#include <dev/ic/ncr5380reg.h>
|
|
|
|
#include <dev/ic/ncr5380var.h>
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-07-04 05:29:14 +04:00
|
|
|
#include <dev/vme/sireg.h>
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* Transfers smaller than this are done using PIO
|
|
|
|
* (on assumption they're not worth DMA overhead)
|
|
|
|
*/
|
|
|
|
#define MIN_DMA_LEN 128
|
|
|
|
|
1995-07-09 01:32:47 +04:00
|
|
|
#ifdef DEBUG
|
1996-01-02 01:40:56 +03:00
|
|
|
int si_debug = 0;
|
1995-07-09 01:32:47 +04:00
|
|
|
#endif
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* This structure is used to keep track of mapped DMA requests.
|
|
|
|
*/
|
|
|
|
struct si_dma_handle {
|
|
|
|
int dh_flags;
|
|
|
|
#define SIDH_BUSY 0x01 /* This DH is in use */
|
|
|
|
#define SIDH_OUT 0x02 /* DMA does data out (write) */
|
|
|
|
int dh_maplen; /* Original data length */
|
1998-07-31 16:45:48 +04:00
|
|
|
bus_dmamap_t dh_dmamap;
|
|
|
|
#define dh_dvma dh_dmamap->dm_segs[0].ds_addr /* VA of buffer in DVMA space */
|
1996-01-02 01:40:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first structure member has to be the ncr5380_softc
|
|
|
|
* so we can just cast to go back and fourth between them.
|
|
|
|
*/
|
|
|
|
struct si_softc {
|
|
|
|
struct ncr5380_softc ncr_sc;
|
2000-06-25 17:09:52 +04:00
|
|
|
bus_space_tag_t sc_bustag; /* bus tags */
|
|
|
|
bus_dma_tag_t sc_dmatag;
|
|
|
|
vme_chipset_tag_t sc_vctag;
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
int sc_adapter_iv_am; /* int. vec + address modifier */
|
|
|
|
struct si_dma_handle *sc_dma;
|
|
|
|
int sc_xlen; /* length of current DMA segment. */
|
|
|
|
int sc_options; /* options for this instance. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Options. By default, DMA is enabled and DMA completion interrupts
|
|
|
|
* and reselect are disabled. You may enable additional features
|
|
|
|
* the `flags' directive in your kernel's configuration file.
|
|
|
|
*
|
|
|
|
* Alternatively, you can patch your kernel with DDB or some other
|
|
|
|
* mechanism. The sc_options member of the softc is OR'd with
|
|
|
|
* the value in si_options.
|
1996-02-23 19:29:34 +03:00
|
|
|
*
|
|
|
|
* Note, there's a separate sw_options to make life easier.
|
1996-01-02 01:40:56 +03:00
|
|
|
*/
|
|
|
|
#define SI_ENABLE_DMA 0x01 /* Use DMA (maybe polled) */
|
|
|
|
#define SI_DMA_INTR 0x02 /* DMA completion interrupts */
|
|
|
|
#define SI_DO_RESELECT 0x04 /* Allow disconnect/reselect */
|
|
|
|
#define SI_OPTIONS_MASK (SI_ENABLE_DMA|SI_DMA_INTR|SI_DO_RESELECT)
|
|
|
|
#define SI_OPTIONS_BITS "\10\3RESELECT\2DMA_INTR\1DMA"
|
2000-07-04 00:55:12 +04:00
|
|
|
int si_options = SI_ENABLE_DMA|SI_DMA_INTR|SI_DO_RESELECT;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
1996-12-11 01:54:46 +03:00
|
|
|
static int si_match __P((struct device *, struct cfdata *, void *));
|
1995-07-09 01:32:47 +04:00
|
|
|
static void si_attach __P((struct device *, struct device *, void *));
|
|
|
|
static int si_intr __P((void *));
|
1996-01-02 01:40:56 +03:00
|
|
|
static void si_reset_adapter __P((struct ncr5380_softc *));
|
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
void si_dma_alloc __P((struct ncr5380_softc *));
|
|
|
|
void si_dma_free __P((struct ncr5380_softc *));
|
|
|
|
void si_dma_poll __P((struct ncr5380_softc *));
|
1995-07-09 01:32:47 +04:00
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
void si_dma_setup __P((struct ncr5380_softc *));
|
|
|
|
void si_dma_start __P((struct ncr5380_softc *));
|
|
|
|
void si_dma_eop __P((struct ncr5380_softc *));
|
|
|
|
void si_dma_stop __P((struct ncr5380_softc *));
|
1995-07-09 01:32:47 +04:00
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
void si_intr_on __P((struct ncr5380_softc *));
|
|
|
|
void si_intr_off __P((struct ncr5380_softc *));
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-07-04 03:30:33 +04:00
|
|
|
/*
|
|
|
|
* Shorthand bus space access
|
|
|
|
* XXX - must look into endian issues here.
|
|
|
|
*/
|
2000-06-18 23:19:53 +04:00
|
|
|
#define SIREG_READ(sc, index) \
|
|
|
|
bus_space_read_2((sc)->sc_regt, (sc)->sc_regh, index)
|
|
|
|
#define SIREG_WRITE(sc, index, v) \
|
|
|
|
bus_space_write_2((sc)->sc_regt, (sc)->sc_regh, index, v)
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-07-04 03:30:33 +04:00
|
|
|
/* Auto-configuration glue. */
|
1996-03-17 05:00:30 +03:00
|
|
|
struct cfattach si_ca = {
|
|
|
|
sizeof(struct si_softc), si_match, si_attach
|
|
|
|
};
|
|
|
|
|
1998-01-25 19:37:08 +03:00
|
|
|
static int
|
|
|
|
si_match(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
1998-02-04 23:50:47 +03:00
|
|
|
struct vme_attach_args *va = aux;
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_chipset_tag_t ct = va->va_vct;
|
|
|
|
vme_am_t mod;
|
1998-02-04 23:50:47 +03:00
|
|
|
vme_addr_t vme_addr;
|
|
|
|
|
1995-07-09 01:32:47 +04:00
|
|
|
/* Make sure there is something there... */
|
2000-06-25 17:09:52 +04:00
|
|
|
mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_addr = va->r[0].offset;
|
|
|
|
|
|
|
|
if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0)
|
1995-07-09 01:32:47 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
/*
|
1996-01-02 01:40:56 +03:00
|
|
|
* If this is a VME SCSI board, we have to determine whether
|
|
|
|
* it is an "sc" (Sun2) or "si" (Sun3) SCSI board. This can
|
|
|
|
* be determined using the fact that the "sc" board occupies
|
|
|
|
* 4K bytes in VME space but the "si" board occupies 2K bytes.
|
1995-07-09 01:32:47 +04:00
|
|
|
*/
|
1999-06-30 19:18:58 +04:00
|
|
|
return (vme_probe(ct, vme_addr + 0x801, 1, mod, VME_D8, NULL, 0) != 0);
|
1998-01-25 19:37:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
si_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct si_softc *sc = (struct si_softc *) self;
|
1999-06-30 19:18:58 +04:00
|
|
|
struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
|
1998-01-25 19:37:08 +03:00
|
|
|
struct vme_attach_args *va = aux;
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_chipset_tag_t ct = va->va_vct;
|
|
|
|
bus_space_tag_t bt;
|
1998-01-25 19:37:08 +03:00
|
|
|
bus_space_handle_t bh;
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_mapresc_t resc;
|
1998-01-25 19:37:08 +03:00
|
|
|
vme_intr_handle_t ih;
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_am_t mod;
|
2000-06-26 23:54:08 +04:00
|
|
|
char bits[64];
|
|
|
|
int i;
|
1998-01-25 19:37:08 +03:00
|
|
|
|
1999-06-30 19:18:58 +04:00
|
|
|
sc->sc_dmatag = va->va_bdt;
|
2000-06-25 17:09:52 +04:00
|
|
|
sc->sc_vctag = ct;
|
1998-07-31 16:45:48 +04:00
|
|
|
|
2000-06-25 17:09:52 +04:00
|
|
|
mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
|
1995-07-09 01:32:47 +04:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
if (vme_space_map(ct, va->r[0].offset, SIREG_BANK_SZ,
|
1999-06-30 19:18:58 +04:00
|
|
|
mod, VME_D8, 0, &bt, &bh, &resc) != 0)
|
|
|
|
panic("%s: vme_space_map", ncr_sc->sc_dev.dv_xname);
|
1998-01-25 19:37:08 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
ncr_sc->sc_regt = bt;
|
|
|
|
ncr_sc->sc_regh = bh;
|
1998-01-25 19:37:08 +03:00
|
|
|
|
|
|
|
sc->sc_options = si_options;
|
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
ncr_sc->sc_dma_setup = si_dma_setup;
|
|
|
|
ncr_sc->sc_dma_start = si_dma_start;
|
|
|
|
ncr_sc->sc_dma_eop = si_dma_stop;
|
|
|
|
ncr_sc->sc_dma_stop = si_dma_stop;
|
1998-01-25 19:37:08 +03:00
|
|
|
|
1999-06-30 19:18:58 +04:00
|
|
|
vme_intr_map(ct, va->ilevel, va->ivector, &ih);
|
|
|
|
vme_intr_establish(ct, ih, IPL_BIO, si_intr, sc);
|
1998-01-25 19:37:08 +03:00
|
|
|
|
1999-06-30 19:18:58 +04:00
|
|
|
printf("\n");
|
1998-01-25 19:37:08 +03:00
|
|
|
|
1999-06-30 19:18:58 +04:00
|
|
|
sc->sc_adapter_iv_am = (mod << 8) | (va->ivector & 0xFF);
|
1998-01-25 19:37:08 +03:00
|
|
|
|
1997-01-23 05:11:23 +03:00
|
|
|
/*
|
|
|
|
* Pull in the options flags. Allow the user to completely
|
|
|
|
* override the default values.
|
|
|
|
*/
|
|
|
|
if ((ncr_sc->sc_dev.dv_cfdata->cf_flags & SI_OPTIONS_MASK) != 0)
|
|
|
|
sc->sc_options =
|
|
|
|
(ncr_sc->sc_dev.dv_cfdata->cf_flags & SI_OPTIONS_MASK);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize fields used by the MI code
|
|
|
|
*/
|
2000-06-18 23:19:53 +04:00
|
|
|
|
|
|
|
/* NCR5380 register bank offsets */
|
|
|
|
ncr_sc->sci_r0 = 0;
|
|
|
|
ncr_sc->sci_r1 = 1;
|
|
|
|
ncr_sc->sci_r2 = 2;
|
|
|
|
ncr_sc->sci_r3 = 3;
|
|
|
|
ncr_sc->sci_r4 = 4;
|
|
|
|
ncr_sc->sci_r5 = 5;
|
|
|
|
ncr_sc->sci_r6 = 6;
|
|
|
|
ncr_sc->sci_r7 = 7;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-03-25 18:27:54 +03:00
|
|
|
ncr_sc->sc_rev = NCR_VARIANT_NCR5380;
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* MD function pointers used by the MI code.
|
|
|
|
*/
|
|
|
|
ncr_sc->sc_pio_out = ncr5380_pio_out;
|
|
|
|
ncr_sc->sc_pio_in = ncr5380_pio_in;
|
|
|
|
ncr_sc->sc_dma_alloc = si_dma_alloc;
|
|
|
|
ncr_sc->sc_dma_free = si_dma_free;
|
|
|
|
ncr_sc->sc_dma_poll = si_dma_poll;
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
ncr_sc->sc_flags = 0;
|
1997-02-27 01:29:08 +03:00
|
|
|
if ((sc->sc_options & SI_DO_RESELECT) == 0)
|
|
|
|
ncr_sc->sc_no_disconnect = 0xFF;
|
1996-01-02 01:40:56 +03:00
|
|
|
if ((sc->sc_options & SI_DMA_INTR) == 0)
|
|
|
|
ncr_sc->sc_flags |= NCR5380_FORCE_POLLING;
|
|
|
|
ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* Allocate DMA handles.
|
|
|
|
*/
|
|
|
|
i = SCI_OPENINGS * sizeof(struct si_dma_handle);
|
|
|
|
sc->sc_dma = (struct si_dma_handle *)malloc(i, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->sc_dma == NULL)
|
|
|
|
panic("si: dma handle malloc failed\n");
|
2000-06-26 23:54:08 +04:00
|
|
|
|
1998-07-31 16:45:48 +04:00
|
|
|
for (i = 0; i < SCI_OPENINGS; i++) {
|
1996-01-02 01:40:56 +03:00
|
|
|
sc->sc_dma[i].dh_flags = 0;
|
|
|
|
|
1998-07-31 16:45:48 +04:00
|
|
|
/* Allocate a DMA handle */
|
2000-06-26 23:54:08 +04:00
|
|
|
if (vme_dmamap_create(
|
2000-06-25 17:09:52 +04:00
|
|
|
sc->sc_vctag, /* VME chip tag */
|
1998-07-31 16:45:48 +04:00
|
|
|
MAXPHYS, /* size */
|
2000-06-25 17:09:52 +04:00
|
|
|
VME_AM_A24, /* address modifier */
|
|
|
|
VME_D16, /* data size */
|
|
|
|
0, /* swap */
|
1998-07-31 16:45:48 +04:00
|
|
|
1, /* nsegments */
|
|
|
|
MAXPHYS, /* maxsegsz */
|
|
|
|
0, /* boundary */
|
|
|
|
BUS_DMA_NOWAIT,
|
2000-06-26 23:54:08 +04:00
|
|
|
&sc->sc_dma[i].dh_dmamap) != 0) {
|
2000-06-26 13:50:00 +04:00
|
|
|
|
1998-07-31 16:45:48 +04:00
|
|
|
printf("%s: DMA buffer map create error\n",
|
|
|
|
ncr_sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1996-01-02 01:40:56 +03:00
|
|
|
|
1996-03-14 22:44:30 +03:00
|
|
|
if (sc->sc_options) {
|
1996-11-13 09:13:39 +03:00
|
|
|
printf("%s: options=%s\n", ncr_sc->sc_dev.dv_xname,
|
|
|
|
bitmask_snprintf(sc->sc_options, SI_OPTIONS_BITS,
|
|
|
|
bits, sizeof(bits)));
|
1996-03-14 22:44:30 +03:00
|
|
|
}
|
1995-07-09 01:32:47 +04:00
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
ncr_sc->sc_channel.chan_id = 7;
|
|
|
|
ncr_sc->sc_adapter.adapt_minphys = minphys;
|
2000-03-18 19:13:22 +03:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* Initialize si board itself.
|
|
|
|
*/
|
2000-06-26 23:54:08 +04:00
|
|
|
si_reset_adapter(ncr_sc);
|
2000-03-18 19:13:22 +03:00
|
|
|
ncr5380_attach(ncr_sc);
|
2000-06-26 23:54:08 +04:00
|
|
|
|
|
|
|
if (sc->sc_options & SI_DO_RESELECT) {
|
|
|
|
/*
|
|
|
|
* Need to enable interrupts (and DMA!)
|
|
|
|
* on this H/W for reselect to work.
|
|
|
|
*/
|
|
|
|
ncr_sc->sc_intr_on = si_intr_on;
|
|
|
|
ncr_sc->sc_intr_off = si_intr_off;
|
|
|
|
}
|
1995-07-09 01:32:47 +04:00
|
|
|
}
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
#define CSR_WANT (SI_CSR_SBC_IP | SI_CSR_DMA_IP | \
|
|
|
|
SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR )
|
|
|
|
|
1995-07-09 01:32:47 +04:00
|
|
|
static int
|
1996-01-02 01:40:56 +03:00
|
|
|
si_intr(void *arg)
|
1995-07-09 01:32:47 +04:00
|
|
|
{
|
1996-01-02 01:40:56 +03:00
|
|
|
struct si_softc *sc = arg;
|
2000-06-18 23:19:53 +04:00
|
|
|
struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *)arg;
|
1996-01-02 01:40:56 +03:00
|
|
|
int dma_error, claimed;
|
|
|
|
u_short csr;
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
claimed = 0;
|
|
|
|
dma_error = 0;
|
1995-09-04 02:21:27 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/* SBC interrupt? DMA interrupt? */
|
2000-06-26 23:54:08 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
2000-06-18 23:19:53 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
NCR_TRACE("si_intr: csr=0x%x\n", csr);
|
1995-07-09 01:32:47 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
if (csr & SI_CSR_DMA_CONFLICT) {
|
|
|
|
dma_error |= SI_CSR_DMA_CONFLICT;
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_intr: DMA conflict\n");
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
if (csr & SI_CSR_DMA_BUS_ERR) {
|
|
|
|
dma_error |= SI_CSR_DMA_BUS_ERR;
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_intr: DMA bus error\n");
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
if (dma_error) {
|
|
|
|
if (sc->ncr_sc.sc_state & NCR_DOINGDMA)
|
|
|
|
sc->ncr_sc.sc_state |= NCR_ABORTING;
|
|
|
|
/* Make sure we will call the main isr. */
|
|
|
|
csr |= SI_CSR_DMA_IP;
|
|
|
|
}
|
1995-09-04 02:21:27 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
if (csr & (SI_CSR_SBC_IP | SI_CSR_DMA_IP)) {
|
|
|
|
claimed = ncr5380_intr(&sc->ncr_sc);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (!claimed) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_intr: spurious from SBC\n");
|
1996-01-02 01:40:56 +03:00
|
|
|
if (si_debug & 4) {
|
|
|
|
Debugger(); /* XXX */
|
|
|
|
}
|
1995-09-04 02:21:27 +04:00
|
|
|
}
|
1996-01-02 01:40:56 +03:00
|
|
|
#endif
|
1995-07-09 01:32:47 +04:00
|
|
|
}
|
1995-09-04 02:21:27 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
return (claimed);
|
1995-07-09 01:32:47 +04:00
|
|
|
}
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
si_reset_adapter(struct ncr5380_softc *ncr_sc)
|
1995-07-09 01:32:47 +04:00
|
|
|
{
|
1996-01-02 01:40:56 +03:00
|
|
|
struct si_softc *sc = (struct si_softc *)ncr_sc;
|
1995-07-09 01:32:47 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-01-02 01:40:56 +03:00
|
|
|
if (si_debug) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_reset_adapter\n");
|
1995-07-09 01:32:47 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*
|
|
|
|
* The SCSI3 controller has an 8K FIFO to buffer data between the
|
|
|
|
* 5380 and the DMA. Make sure it starts out empty.
|
|
|
|
*
|
|
|
|
* The reset bits in the CSR are active low.
|
|
|
|
*/
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, 0);
|
1998-01-25 19:37:08 +03:00
|
|
|
delay(10);
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR,
|
|
|
|
SI_CSR_FIFO_RES | SI_CSR_SCSI_RES | SI_CSR_INTR_EN);
|
1998-01-25 19:37:08 +03:00
|
|
|
delay(10);
|
2000-06-18 23:19:53 +04:00
|
|
|
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNT, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRL, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTL, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_IV_AM, sc->sc_adapter_iv_am);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNTH, 0);
|
1998-01-25 19:37:08 +03:00
|
|
|
|
|
|
|
SCI_CLR_INTR(ncr_sc);
|
|
|
|
}
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/*****************************************************************
|
|
|
|
* Common functions for DMA
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a DMA handle and put it in sc->sc_dma. Prepare
|
2000-07-04 03:30:33 +04:00
|
|
|
* for DMA transfer.
|
1996-01-02 01:40:56 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
si_dma_alloc(ncr_sc)
|
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
|
|
|
struct si_softc *sc = (struct si_softc *)ncr_sc;
|
|
|
|
struct sci_req *sr = ncr_sc->sc_current;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct scsipi_xfer *xs = sr->sr_xs;
|
1996-01-02 01:40:56 +03:00
|
|
|
struct si_dma_handle *dh;
|
|
|
|
int i, xlen;
|
|
|
|
u_long addr;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sr->sr_dma_hand != NULL)
|
|
|
|
panic("si_dma_alloc: already have DMA handle");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 1 /* XXX - Temporary */
|
|
|
|
/* XXX - In case we think DMA is completely broken... */
|
|
|
|
if ((sc->sc_options & SI_ENABLE_DMA) == 0)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
addr = (u_long) ncr_sc->sc_dataptr;
|
|
|
|
xlen = ncr_sc->sc_datalen;
|
|
|
|
|
|
|
|
/* If the DMA start addr is misaligned then do PIO */
|
|
|
|
if ((addr & 1) || (xlen & 1)) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_alloc: misaligned.\n");
|
1996-01-02 01:40:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure our caller checked sc_min_dma_len. */
|
|
|
|
if (xlen < MIN_DMA_LEN)
|
|
|
|
panic("si_dma_alloc: xlen=0x%x\n", xlen);
|
|
|
|
|
|
|
|
/* Find free DMA handle. Guaranteed to find one since we have
|
|
|
|
as many DMA handles as the driver has processes. */
|
|
|
|
for (i = 0; i < SCI_OPENINGS; i++) {
|
|
|
|
if ((sc->sc_dma[i].dh_flags & SIDH_BUSY) == 0)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
panic("si: no free DMA handles.");
|
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
found:
|
1996-01-02 01:40:56 +03:00
|
|
|
dh = &sc->sc_dma[i];
|
|
|
|
dh->dh_flags = SIDH_BUSY;
|
|
|
|
dh->dh_maplen = xlen;
|
|
|
|
|
|
|
|
/* Copy the "write" flag for convenience. */
|
1999-10-21 17:46:06 +04:00
|
|
|
if ((xs->xs_control & XS_CTL_DATA_OUT) != 0)
|
1996-01-02 01:40:56 +03:00
|
|
|
dh->dh_flags |= SIDH_OUT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Double-map the buffer into DVMA space. If we can't re-map
|
|
|
|
* the buffer, we print a warning and fall back to PIO mode.
|
|
|
|
*
|
|
|
|
* NOTE: it is not safe to sleep here!
|
|
|
|
*/
|
1998-07-31 16:45:48 +04:00
|
|
|
if (bus_dmamap_load(sc->sc_dmatag, dh->dh_dmamap,
|
|
|
|
(caddr_t)addr, xlen, NULL, BUS_DMA_NOWAIT) != 0) {
|
1996-01-02 01:40:56 +03:00
|
|
|
/* Can't remap segment */
|
2000-06-26 23:54:08 +04:00
|
|
|
printf("si_dma_alloc: can't remap 0x%lx/0x%x, doing PIO\n",
|
|
|
|
addr, dh->dh_maplen);
|
1996-01-02 01:40:56 +03:00
|
|
|
dh->dh_flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
1998-07-31 16:45:48 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmatag, dh->dh_dmamap, addr, xlen,
|
|
|
|
(dh->dh_flags & SIDH_OUT)
|
|
|
|
? BUS_DMASYNC_PREWRITE
|
|
|
|
: BUS_DMASYNC_PREREAD);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/* success */
|
|
|
|
sr->sr_dma_hand = dh;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
si_dma_free(ncr_sc)
|
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
1998-07-31 16:45:48 +04:00
|
|
|
struct si_softc *sc = (struct si_softc *)ncr_sc;
|
1996-01-02 01:40:56 +03:00
|
|
|
struct sci_req *sr = ncr_sc->sc_current;
|
|
|
|
struct si_dma_handle *dh = sr->sr_dma_hand;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (dh == NULL)
|
|
|
|
panic("si_dma_free: no DMA handle");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ncr_sc->sc_state & NCR_DOINGDMA)
|
|
|
|
panic("si_dma_free: free while in progress");
|
|
|
|
|
|
|
|
if (dh->dh_flags & SIDH_BUSY) {
|
|
|
|
/* Give back the DVMA space. */
|
1998-07-31 16:45:48 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmatag, dh->dh_dmamap,
|
|
|
|
dh->dh_dvma, dh->dh_maplen,
|
|
|
|
(dh->dh_flags & SIDH_OUT)
|
|
|
|
? BUS_DMASYNC_POSTWRITE
|
|
|
|
: BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->sc_dmatag, dh->dh_dmamap);
|
1996-01-02 01:40:56 +03:00
|
|
|
dh->dh_flags = 0;
|
|
|
|
}
|
|
|
|
sr->sr_dma_hand = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Poll (spin-wait) for DMA completion.
|
|
|
|
* Called right after xx_dma_start(), and
|
|
|
|
* xx_dma_stop() will be called next.
|
|
|
|
* Same for either VME or OBIO.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
si_dma_poll(ncr_sc)
|
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
|
|
|
struct sci_req *sr = ncr_sc->sc_current;
|
|
|
|
int tmo, csr_mask, csr;
|
|
|
|
|
|
|
|
/* Make sure DMA started successfully. */
|
|
|
|
if (ncr_sc->sc_state & NCR_ABORTING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
csr_mask = SI_CSR_SBC_IP | SI_CSR_DMA_IP |
|
|
|
|
SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR;
|
|
|
|
|
|
|
|
tmo = 50000; /* X100 = 5 sec. */
|
|
|
|
for (;;) {
|
2000-06-26 23:54:08 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
1996-01-02 01:40:56 +03:00
|
|
|
if (csr & csr_mask)
|
|
|
|
break;
|
|
|
|
if (--tmo <= 0) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("%s: DMA timeout (while polling)\n",
|
1996-01-02 01:40:56 +03:00
|
|
|
ncr_sc->sc_dev.dv_xname);
|
|
|
|
/* Indicate timeout as MI code would. */
|
|
|
|
sr->sr_flags |= SR_OVERDUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (si_debug) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_poll: done, csr=0x%x\n", csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* VME functions for DMA
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called when the bus is going idle,
|
|
|
|
* so we want to enable the SBC interrupts.
|
|
|
|
* That is controlled by the DMA enable!
|
|
|
|
* Who would have guessed!
|
|
|
|
* What a NASTY trick!
|
|
|
|
*/
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_intr_on(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int16_t csr;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
si_dma_setup(ncr_sc);
|
2000-06-18 23:19:53 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
|
|
|
csr |= SI_CSR_DMA_EN;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called when the bus is idle and we are
|
|
|
|
* about to start playing with the SBC chip.
|
|
|
|
*/
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_intr_off(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int16_t csr;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
|
|
|
csr &= ~SI_CSR_DMA_EN;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called during the COMMAND or MSG_IN phase
|
|
|
|
* that preceeds a DATA_IN or DATA_OUT phase, in case we need
|
|
|
|
* to setup the DMA engine before the bus enters a DATA phase.
|
|
|
|
*
|
|
|
|
* XXX: The VME adapter appears to suppress SBC interrupts
|
|
|
|
* when the FIFO is not empty or the FIFO count is non-zero!
|
|
|
|
*
|
|
|
|
* On the VME version we just clear the DMA count and address
|
|
|
|
* here (to make sure it stays idle) and do the real setup
|
|
|
|
* later, in dma_start.
|
|
|
|
*/
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_dma_setup(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int16_t csr;
|
|
|
|
|
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/* Reset the FIFO */
|
2000-06-18 23:19:53 +04:00
|
|
|
csr &= ~SI_CSR_FIFO_RES; /* active low */
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
|
|
|
csr |= SI_CSR_FIFO_RES;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/* Set direction (assume recv here) */
|
2000-06-18 23:19:53 +04:00
|
|
|
csr &= ~SI_CSR_SEND;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
/* Assume worst alignment */
|
2000-06-18 23:19:53 +04:00
|
|
|
csr |= SI_CSR_BPCON;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRL, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTL, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/* Clear FIFO counter. (also hits dma_count) */
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNTH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNT, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_dma_start(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
|
|
|
struct si_softc *sc = (struct si_softc *)ncr_sc;
|
|
|
|
struct sci_req *sr = ncr_sc->sc_current;
|
|
|
|
struct si_dma_handle *dh = sr->sr_dma_hand;
|
2000-07-04 00:55:12 +04:00
|
|
|
u_long dva;
|
1996-01-02 01:40:56 +03:00
|
|
|
int xlen;
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int mode;
|
|
|
|
u_int16_t csr;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the DVMA mapping for this segment.
|
|
|
|
*/
|
2000-07-04 00:55:12 +04:00
|
|
|
dva = (u_long)(dh->dh_dvma);
|
|
|
|
if (dva & 1)
|
|
|
|
panic("si_dma_start: bad dmaaddr=0x%lx", dva);
|
1996-01-02 01:40:56 +03:00
|
|
|
xlen = ncr_sc->sc_datalen;
|
|
|
|
xlen &= ~1;
|
|
|
|
sc->sc_xlen = xlen; /* XXX: or less... */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (si_debug & 2) {
|
2000-07-04 00:55:12 +04:00
|
|
|
printf("si_dma_start: dh=%p, dmaaddr=0x%lx, xlen=%d\n",
|
|
|
|
dh, dva, xlen);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the DMA controller.
|
|
|
|
* Note that (dh->dh_len < sc_datalen)
|
|
|
|
*/
|
2000-07-04 00:55:12 +04:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
2000-07-04 00:55:12 +04:00
|
|
|
|
|
|
|
/* Disable DMA while we're setting up the transfer */
|
|
|
|
csr &= ~SI_CSR_DMA_EN;
|
|
|
|
|
|
|
|
/* Reset FIFO (again?) */
|
2000-06-18 23:19:53 +04:00
|
|
|
csr &= ~SI_CSR_FIFO_RES; /* active low */
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
|
|
|
csr |= SI_CSR_FIFO_RES;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/* Set direction (send/recv) */
|
|
|
|
if (dh->dh_flags & SIDH_OUT) {
|
2000-06-18 23:19:53 +04:00
|
|
|
csr |= SI_CSR_SEND;
|
1996-01-02 01:40:56 +03:00
|
|
|
} else {
|
2000-06-18 23:19:53 +04:00
|
|
|
csr &= ~SI_CSR_SEND;
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-07-04 00:55:12 +04:00
|
|
|
if (dva & 2) {
|
2000-06-18 23:19:53 +04:00
|
|
|
csr |= SI_CSR_BPCON;
|
1996-01-02 01:40:56 +03:00
|
|
|
} else {
|
2000-06-18 23:19:53 +04:00
|
|
|
csr &= ~SI_CSR_BPCON;
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-04-01 02:38:29 +04:00
|
|
|
|
2000-07-04 00:55:12 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRH, (u_int16_t)(dva >> 16));
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRL, (u_int16_t)(dva & 0xFFFF));
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTH, (u_int16_t)(xlen >> 16));
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTL, (u_int16_t)(xlen & 0xFFFF));
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNTH, (u_int16_t)(xlen >> 16));
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNT, (u_int16_t)(xlen & 0xFFFF));
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Acknowledge the phase change. (After DMA setup!)
|
|
|
|
* Put the SBIC into DMA mode, and start the transfer.
|
|
|
|
*/
|
|
|
|
if (dh->dh_flags & SIDH_OUT) {
|
2000-06-18 23:19:53 +04:00
|
|
|
NCR5380_WRITE(ncr_sc, sci_tcmd, PHASE_DATA_OUT);
|
1996-01-02 01:40:56 +03:00
|
|
|
SCI_CLR_INTR(ncr_sc);
|
2000-06-18 23:19:53 +04:00
|
|
|
NCR5380_WRITE(ncr_sc, sci_icmd, SCI_ICMD_DATA);
|
|
|
|
|
|
|
|
mode = NCR5380_READ(ncr_sc, sci_mode);
|
|
|
|
mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_mode, mode);
|
|
|
|
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_dma_send, 0); /* start it */
|
1996-01-02 01:40:56 +03:00
|
|
|
} else {
|
2000-06-18 23:19:53 +04:00
|
|
|
NCR5380_WRITE(ncr_sc, sci_tcmd, PHASE_DATA_IN);
|
1996-01-02 01:40:56 +03:00
|
|
|
SCI_CLR_INTR(ncr_sc);
|
2000-06-18 23:19:53 +04:00
|
|
|
NCR5380_WRITE(ncr_sc, sci_icmd, 0);
|
|
|
|
|
|
|
|
mode = NCR5380_READ(ncr_sc, sci_mode);
|
|
|
|
mode |= (SCI_MODE_DMA | SCI_MODE_DMA_IE);
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_mode, mode);
|
|
|
|
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_irecv, 0); /* start it */
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
|
2000-07-04 00:55:12 +04:00
|
|
|
/* Enable DMA engine */
|
2000-06-18 23:19:53 +04:00
|
|
|
csr |= SI_CSR_DMA_EN;
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
ncr_sc->sc_state |= NCR_DOINGDMA;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (si_debug & 2) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_start: started, flags=0x%x\n",
|
1996-01-02 01:40:56 +03:00
|
|
|
ncr_sc->sc_state);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_dma_eop(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Not needed - DMA was stopped prior to examining sci_csr */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2000-06-26 23:54:08 +04:00
|
|
|
si_dma_stop(ncr_sc)
|
1996-01-02 01:40:56 +03:00
|
|
|
struct ncr5380_softc *ncr_sc;
|
|
|
|
{
|
|
|
|
struct si_softc *sc = (struct si_softc *)ncr_sc;
|
|
|
|
struct sci_req *sr = ncr_sc->sc_current;
|
|
|
|
struct si_dma_handle *dh = sr->sr_dma_hand;
|
|
|
|
int resid, ntrans;
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int16_t csr;
|
|
|
|
u_int mode;
|
1996-01-02 01:40:56 +03:00
|
|
|
|
|
|
|
if ((ncr_sc->sc_state & NCR_DOINGDMA) == 0) {
|
|
|
|
#ifdef DEBUG
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_stop: dma not running\n");
|
1996-01-02 01:40:56 +03:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2000-07-04 03:30:33 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
ncr_sc->sc_state &= ~NCR_DOINGDMA;
|
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
csr = SIREG_READ(ncr_sc, SIREG_CSR);
|
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
/* First, halt the DMA engine. */
|
2000-07-04 00:55:12 +04:00
|
|
|
csr &= ~SI_CSR_DMA_EN;
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_CSR, csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
if (csr & (SI_CSR_DMA_CONFLICT | SI_CSR_DMA_BUS_ERR)) {
|
|
|
|
printf("si: DMA error, csr=0x%x, reset\n", csr);
|
1996-01-02 01:40:56 +03:00
|
|
|
sr->sr_xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
ncr_sc->sc_state |= NCR_ABORTING;
|
|
|
|
si_reset_adapter(ncr_sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that timeout may have set the error flag. */
|
|
|
|
if (ncr_sc->sc_state & NCR_ABORTING)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now try to figure out how much actually transferred
|
|
|
|
*
|
|
|
|
* The fifo_count does not reflect how many bytes were
|
|
|
|
* actually transferred for VME.
|
|
|
|
*
|
|
|
|
* SCSI-3 VME interface is a little funny on writes:
|
|
|
|
* if we have a disconnect, the dma has overshot by
|
1996-02-22 10:14:53 +03:00
|
|
|
* one byte and the resid needs to be incremented.
|
|
|
|
* Only happens for partial transfers.
|
|
|
|
* (Thanks to Matt Jacob)
|
1996-01-02 01:40:56 +03:00
|
|
|
*/
|
|
|
|
|
2000-06-26 23:54:08 +04:00
|
|
|
resid = SIREG_READ(ncr_sc, SIREG_FIFO_CNTH) << 16;
|
|
|
|
resid |= SIREG_READ(ncr_sc, SIREG_FIFO_CNT) & 0xFFFF;
|
1996-02-22 10:14:53 +03:00
|
|
|
if (dh->dh_flags & SIDH_OUT)
|
|
|
|
if ((resid > 0) && (resid < sc->sc_xlen))
|
|
|
|
resid++;
|
1996-01-02 01:40:56 +03:00
|
|
|
ntrans = sc->sc_xlen - resid;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (si_debug & 2) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_stop: resid=0x%x ntrans=0x%x\n",
|
1996-01-02 01:40:56 +03:00
|
|
|
resid, ntrans);
|
|
|
|
}
|
|
|
|
#endif
|
2000-06-29 18:06:40 +04:00
|
|
|
|
1996-01-02 01:40:56 +03:00
|
|
|
if (ntrans > ncr_sc->sc_datalen)
|
|
|
|
panic("si_dma_stop: excess transfer");
|
|
|
|
|
|
|
|
/* Adjust data pointer */
|
|
|
|
ncr_sc->sc_dataptr += ntrans;
|
|
|
|
ncr_sc->sc_datalen -= ntrans;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (si_debug & 2) {
|
1996-10-13 06:59:55 +04:00
|
|
|
printf("si_dma_stop: ntrans=0x%x\n", ntrans);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After a read, we may need to clean-up
|
|
|
|
* "Left-over bytes" (yuck!)
|
|
|
|
*/
|
|
|
|
if (((dh->dh_flags & SIDH_OUT) == 0) &&
|
2000-06-18 23:19:53 +04:00
|
|
|
((csr & SI_CSR_LOB) != 0))
|
1996-01-02 01:40:56 +03:00
|
|
|
{
|
|
|
|
char *cp = ncr_sc->sc_dataptr;
|
2000-06-18 23:19:53 +04:00
|
|
|
u_int16_t bprh, bprl;
|
2000-07-04 00:55:12 +04:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
bprh = SIREG_READ(ncr_sc, SIREG_BPRH);
|
|
|
|
bprl = SIREG_READ(ncr_sc, SIREG_BPRL);
|
|
|
|
|
2000-07-04 00:55:12 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("si: got left-over bytes: bprh=%x, bprl=%x, csr=%x\n",
|
|
|
|
bprh, bprl, csr);
|
|
|
|
#endif
|
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
if (csr & SI_CSR_BPCON) {
|
1996-01-02 01:40:56 +03:00
|
|
|
/* have SI_CSR_BPCON */
|
2000-06-18 23:19:53 +04:00
|
|
|
cp[-1] = (bprl & 0xff00) >> 8;
|
1996-01-02 01:40:56 +03:00
|
|
|
} else {
|
2000-06-18 23:19:53 +04:00
|
|
|
switch (csr & SI_CSR_LOB) {
|
1996-01-02 01:40:56 +03:00
|
|
|
case SI_CSR_LOB_THREE:
|
2000-06-18 23:19:53 +04:00
|
|
|
cp[-3] = (bprh & 0xff00) >> 8;
|
|
|
|
cp[-2] = (bprh & 0x00ff);
|
|
|
|
cp[-1] = (bprl & 0xff00) >> 8;
|
1996-01-02 01:40:56 +03:00
|
|
|
break;
|
|
|
|
case SI_CSR_LOB_TWO:
|
2000-06-18 23:19:53 +04:00
|
|
|
cp[-2] = (bprh & 0xff00) >> 8;
|
|
|
|
cp[-1] = (bprh & 0x00ff);
|
1996-01-02 01:40:56 +03:00
|
|
|
break;
|
|
|
|
case SI_CSR_LOB_ONE:
|
2000-06-18 23:19:53 +04:00
|
|
|
cp[-1] = (bprh & 0xff00) >> 8;
|
1996-01-02 01:40:56 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_ADDRL, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_DMA_CNTL, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNTH, 0);
|
|
|
|
SIREG_WRITE(ncr_sc, SIREG_FIFO_CNT, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
|
2000-06-18 23:19:53 +04:00
|
|
|
mode = NCR5380_READ(ncr_sc, sci_mode);
|
1996-01-02 01:40:56 +03:00
|
|
|
/* Put SBIC back in PIO mode. */
|
2000-06-18 23:19:53 +04:00
|
|
|
mode &= ~(SCI_MODE_DMA | SCI_MODE_DMA_IE);
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_mode, mode);
|
|
|
|
NCR5380_WRITE(ncr_sc, sci_icmd, 0);
|
1996-01-02 01:40:56 +03:00
|
|
|
}
|