Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/sys/dev/vme New in netbsd-1-5: si.c revision 1.2; sireg...
details: https://anonhg.NetBSD.org/src/rev/6fd9704cb504
branches: netbsd-1-5
changeset: 488664:6fd9704cb504
user: pk <pk%NetBSD.org@localhost>
date: Sat Jul 22 21:08:23 2000 +0000
description:
New in netbsd-1-5: si.c revision 1.2; sireg.h revision 1.1
The `si' driver has been transformed into an MI VME frontend.
diffstat:
sys/dev/vme/si.c | 949 ++++++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/vme/sireg.h | 136 +++++++
2 files changed, 1085 insertions(+), 0 deletions(-)
diffs (truncated from 1093 to 300 lines):
diff -r ced660a6c273 -r 6fd9704cb504 sys/dev/vme/si.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/vme/si.c Sat Jul 22 21:08:23 2000 +0000
@@ -0,0 +1,949 @@
+/* $NetBSD: si.c,v 1.2.2.2 2000/07/22 21:08:23 pk Exp $ */
+
+/*-
+ * Copyright (c) 1996,2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Adam Glass, David Jones, Gordon W. Ross, Jason R. Thorpe and
+ * Paul Kranenburg.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * 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.
+ *
+ * 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
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * 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.
+ */
+
+/*
+ * This file contains VME bus-dependent of the `si' SCSI adapter.
+ * This hardware is frequently found on Sun 3 and Sun 4 machines.
+ *
+ * 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
+ *
+ * The logic has a bit to enable or disable the DMA engine,
+ * 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!
+ *
+ */
+
+/*
+ * This driver originated as an MD implementation for the sun3 and sun4
+ * ports. The notes pertaining to that history are included below.
+ *
+ * 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
+ * for the sake of testing. Andrew Gillham helped work out the bugs
+ * the 4/100 DMA code.
+ */
+
+#include "opt_ddb.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+#include <sys/buf.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/vme/vmereg.h>
+#include <dev/vme/vmevar.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsipi_debug.h>
+#include <dev/scsipi/scsiconf.h>
+
+#ifndef DDB
+#define Debugger()
+#endif
+
+#ifndef DEBUG
+#define DEBUG XXX
+#endif
+
+#include <dev/ic/ncr5380reg.h>
+#include <dev/ic/ncr5380var.h>
+
+#include <dev/vme/sireg.h>
+
+/*
+ * Transfers smaller than this are done using PIO
+ * (on assumption they're not worth DMA overhead)
+ */
+#define MIN_DMA_LEN 128
+
+#ifdef DEBUG
+int si_debug = 0;
+static int si_link_flags = 0 /* | SDEV_DB2 */ ;
+#endif
+
+/*
+ * 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 */
+ bus_dmamap_t dh_dmamap;
+#define dh_dvma dh_dmamap->dm_segs[0].ds_addr /* VA of buffer in DVMA space */
+};
+
+/*
+ * 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;
+ bus_space_tag_t sc_bustag; /* bus tags */
+ bus_dma_tag_t sc_dmatag;
+ vme_chipset_tag_t sc_vctag;
+
+ 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.
+ *
+ * Note, there's a separate sw_options to make life easier.
+ */
+#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"
+int si_options = SI_ENABLE_DMA|SI_DMA_INTR|SI_DO_RESELECT;
+
+static int si_match __P((struct device *, struct cfdata *, void *));
+static void si_attach __P((struct device *, struct device *, void *));
+static int si_intr __P((void *));
+static void si_reset_adapter __P((struct ncr5380_softc *));
+
+void si_dma_alloc __P((struct ncr5380_softc *));
+void si_dma_free __P((struct ncr5380_softc *));
+void si_dma_poll __P((struct ncr5380_softc *));
+
+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 *));
+
+void si_intr_on __P((struct ncr5380_softc *));
+void si_intr_off __P((struct ncr5380_softc *));
+
+/*
+ * Shorthand bus space access
+ * XXX - must look into endian issues here.
+ */
+#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)
+
+
+/* Auto-configuration glue. */
+struct cfattach si_ca = {
+ sizeof(struct si_softc), si_match, si_attach
+};
+
+static int
+si_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct vme_attach_args *va = aux;
+ vme_chipset_tag_t ct = va->va_vct;
+ vme_am_t mod;
+ vme_addr_t vme_addr;
+
+ /* Make sure there is something there... */
+ mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
+ vme_addr = va->r[0].offset;
+
+ if (vme_probe(ct, vme_addr, 1, mod, VME_D8, NULL, 0) != 0)
+ return (0);
+
+ /*
+ * 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.
+ */
+ return (vme_probe(ct, vme_addr + 0x801, 1, mod, VME_D8, NULL, 0) != 0);
+}
+
+static void
+si_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct si_softc *sc = (struct si_softc *) self;
+ struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
+ struct vme_attach_args *va = aux;
+ vme_chipset_tag_t ct = va->va_vct;
+ bus_space_tag_t bt;
+ bus_space_handle_t bh;
+ vme_mapresc_t resc;
+ vme_intr_handle_t ih;
+ vme_am_t mod;
+ char bits[64];
+ int i;
+
+ sc->sc_dmatag = va->va_bdt;
+ sc->sc_vctag = ct;
+
+ mod = VME_AM_A24 | VME_AM_MBO | VME_AM_SUPER | VME_AM_DATA;
+
+ if (vme_space_map(ct, va->r[0].offset, SIREG_BANK_SZ,
+ mod, VME_D8, 0, &bt, &bh, &resc) != 0)
+ panic("%s: vme_space_map", ncr_sc->sc_dev.dv_xname);
+
+ ncr_sc->sc_regt = bt;
+ ncr_sc->sc_regh = bh;
+
+ sc->sc_options = si_options;
+
+ 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;
+
+ vme_intr_map(ct, va->ilevel, va->ivector, &ih);
+ vme_intr_establish(ct, ih, IPL_BIO, si_intr, sc);
+
+ printf("\n");
+
+ sc->sc_adapter_iv_am = (mod << 8) | (va->ivector & 0xFF);
+
+ /*
+ * 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);
+
+ /*
+ * Initialize fields used by the MI code
+ */
+
+ /* 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;
Home |
Main Index |
Thread Index |
Old Index