Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic Added support for the chipset used on the Sun2 "s...



details:   https://anonhg.NetBSD.org/src/rev/70251f1d4c76
branches:  trunk
changeset: 508830:70251f1d4c76
user:      fredette <fredette%NetBSD.org@localhost>
date:      Fri Apr 20 16:35:22 2001 +0000

description:
Added support for the chipset used on the Sun2 "sc" SCSI adapters.
A little rough around the edges, but definitely a starting point.

diffstat:

 sys/dev/ic/sunscpal.c    |  2378 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/sunscpalreg.h |    90 +
 sys/dev/ic/sunscpalvar.h |   288 +++++
 3 files changed, 2756 insertions(+), 0 deletions(-)

diffs (truncated from 2768 to 300 lines):

diff -r f9d943a524ff -r 70251f1d4c76 sys/dev/ic/sunscpal.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/sunscpal.c     Fri Apr 20 16:35:22 2001 +0000
@@ -0,0 +1,2378 @@
+/*     $NetBSD: sunscpal.c,v 1.1 2001/04/20 16:35:22 fredette Exp $    */
+
+/*
+ * Copyright (c) 2001 Matthew Fredette
+ * Copyright (c) 1995 David Jones, Gordon W. Ross
+ * Copyright (c) 1994 Jarle Greipsland
+ * All rights reserved.
+ *
+ * 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. The name of the authors may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 4. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by
+ *      David Jones and Gordon Ross
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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 is a machine-independent driver for the Sun "sc"
+ * SCSI Bus Controller (SBC).
+ *
+ * This code should work with any memory-mapped card,
+ * and can be shared by multiple adapters that address
+ * the card with different register offset spacings.
+ * (This can happen on the atari, for example.)
+ *
+ * Credits, history:
+ *
+ * Matthew Fredette completely copied revision 1.38 of
+ * ncr5380sbc.c, and then heavily modified it to match
+ * the Sun sc PAL.  The remaining credits are for
+ * ncr5380sbc.c:
+ *
+ * David Jones is the author of most of the code that now
+ * appears in this file, and was the architect of the
+ * current overall structure (MI/MD code separation, etc.)
+ *
+ * Gordon Ross integrated the message phase code, added lots of
+ * comments about what happens when and why (re. SCSI spec.),
+ * debugged some reentrance problems, and added several new
+ * "hooks" needed for the Sun3 "si" adapters.
+ *
+ * The message in/out code was taken nearly verbatim from
+ * the aic6360 driver by Jarle Greipsland.
+ *
+ * Several other NCR5380 drivers were used for reference
+ * while developing this driver, including work by:
+ *   The Alice Group (mac68k port) namely:
+ *       Allen K. Briggs, Chris P. Caputo, Michael L. Finch,
+ *       Bradley A. Grantham, and Lawrence A. Kesteloot
+ *   Michael L. Hitch (amiga drivers: sci.c)
+ *   Leo Weppelman (atari driver: ncr5380.c)
+ * There are others too.  Thanks, everyone.
+ *
+ * Transliteration to bus_space() performed 9/17/98 by
+ * John Ruschmeyer (jruschme%exit109.com@localhost) for i386 'nca' driver.
+ * Thank you all.
+ */
+
+#include "opt_ddb.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/buf.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsipi_debug.h>
+#include <dev/scsipi/scsi_message.h>
+#include <dev/scsipi/scsiconf.h>
+
+#ifdef DDB
+#include <ddb/db_output.h>
+#endif
+
+#include <dev/ic/sunscpalreg.h>
+#include <dev/ic/sunscpalvar.h>
+
+static void    sunscpal_reset_scsibus __P((struct sunscpal_softc *));
+static void    sunscpal_sched __P((struct sunscpal_softc *));
+static void    sunscpal_done __P((struct sunscpal_softc *));
+
+static int     sunscpal_select
+       __P((struct sunscpal_softc *, struct sunscpal_req *));
+static void    sunscpal_reselect __P((struct sunscpal_softc *));
+
+static int     sunscpal_msg_in __P((struct sunscpal_softc *));
+static int     sunscpal_msg_out __P((struct sunscpal_softc *));
+static int     sunscpal_data_xfer __P((struct sunscpal_softc *, int));
+static int     sunscpal_command __P((struct sunscpal_softc *));
+static int     sunscpal_status __P((struct sunscpal_softc *));
+static void    sunscpal_machine __P((struct sunscpal_softc *));
+
+void   sunscpal_abort __P((struct sunscpal_softc *));
+void   sunscpal_cmd_timeout __P((void *));
+/*
+ * Action flags returned by the info_tranfer functions:
+ * (These determine what happens next.)
+ */
+#define ACT_CONTINUE   0x00    /* No flags: expect another phase */
+#define ACT_DISCONNECT 0x01    /* Target is disconnecting */
+#define ACT_CMD_DONE   0x02    /* Need to call scsipi_done() */
+#define ACT_RESET_BUS  0x04    /* Need bus reset (cmd timeout) */
+#define ACT_WAIT_DMA   0x10    /* Wait for DMA to complete */
+
+/*****************************************************************
+ * Debugging stuff
+ *****************************************************************/
+
+#ifndef DDB
+/* This is used only in recoverable places. */
+#ifndef Debugger
+#define Debugger() printf("Debug: sunscpal.c:%d\n", __LINE__)
+#endif
+#endif
+
+#ifdef SUNSCPAL_DEBUG
+
+#define        SUNSCPAL_DBG_BREAK      1
+#define        SUNSCPAL_DBG_CMDS       2
+#define        SUNSCPAL_DBG_DMA        4
+int sunscpal_debug = 0;
+#define        SUNSCPAL_BREAK() \
+       do { if (sunscpal_debug & SUNSCPAL_DBG_BREAK) Debugger(); } while (0)
+static void sunscpal_show_scsi_cmd __P((struct scsipi_xfer *));
+static void sunscpal_show_sense __P((struct scsipi_xfer *));
+#ifdef DDB
+void   sunscpal_clear_trace __P((void));
+void   sunscpal_show_trace __P((void));
+void   sunscpal_show_req __P((struct sunscpal_req *));
+void   sunscpal_show_state __P((void));
+#endif /* DDB */
+#else  /* SUNSCPAL_DEBUG */
+
+#define        SUNSCPAL_BREAK()                /* nada */
+#define sunscpal_show_scsi_cmd(xs) /* nada */
+#define sunscpal_show_sense(xs) /* nada */
+
+#endif /* SUNSCPAL_DEBUG */
+
+static char *
+phase_names[8] = {
+       "DATA_OUT",
+       "DATA_IN",
+       "COMMAND",
+       "STATUS",
+       "UNSPEC1",
+       "UNSPEC2",
+       "MSG_OUT",
+       "MSG_IN",
+};
+
+#ifdef SUNSCPAL_USE_BUS_DMA
+static void sunscpal_dma_alloc __P((struct sunscpal_softc *));
+static void sunscpal_dma_free __P((struct sunscpal_softc *));
+static void sunscpal_dma_setup __P((struct sunscpal_softc *));
+#else
+#define sunscpal_dma_alloc(sc) (*sc->sc_dma_alloc)(sc)
+#define sunscpal_dma_free(sc) (*sc->sc_dma_free)(sc)
+#define sunscpal_dma_setup(sc) (*sc->sc_dma_setup)(sc)
+#endif
+static void sunscpal_minphys __P((struct buf *));
+
+/*****************************************************************
+ * Actual chip control
+ *****************************************************************/
+
+/*
+ * XXX: These timeouts might need to be tuned...
+ */
+
+/* This one is used when waiting for a phase change. (X100uS.) */
+int sunscpal_wait_phase_timo = 1000 * 10 * 300;        /* 5 min. */
+
+/* These are used in the following inline functions. */
+int sunscpal_wait_req_timo = 1000 * 50;        /* X2 = 100 mS. */
+int sunscpal_wait_nrq_timo = 1000 * 25;        /* X2 =  50 mS. */
+
+static __inline int sunscpal_wait_req __P((struct sunscpal_softc *));
+static __inline int sunscpal_wait_not_req __P((struct sunscpal_softc *));
+static __inline void sunscpal_sched_msgout __P((struct sunscpal_softc *, int));
+
+/* Return zero on success. */
+static __inline int sunscpal_wait_req(sc)
+       struct sunscpal_softc *sc;
+{
+       int timo = sunscpal_wait_req_timo;
+       for (;;) {
+               if (SUNSCPAL_READ_2(sc, sunscpal_icr) & SUNSCPAL_ICR_REQUEST) {
+                       timo = 0;       /* return 0 */
+                       break;
+               }
+               if (--timo < 0)
+                       break;  /* return -1 */
+               delay(2);
+       }
+       return (timo);
+}
+
+/* Return zero on success. */
+static __inline int sunscpal_wait_not_req(sc)
+       struct sunscpal_softc *sc;
+{
+       int timo = sunscpal_wait_nrq_timo;
+       for (;;) {
+               if ((SUNSCPAL_READ_2(sc, sunscpal_icr) & SUNSCPAL_ICR_REQUEST) == 0) {
+                       timo = 0;       /* return 0 */
+                       break;
+               }
+               if (--timo < 0)
+                       break;  /* return -1 */
+               delay(2);
+       }
+       return (timo);
+}
+
+/*
+ * These functions control DMA functions in the chipset independent of
+ * the host DMA implementation.
+ */
+static void sunscpal_dma_start __P((struct sunscpal_softc *));
+static void sunscpal_dma_poll __P((struct sunscpal_softc *));
+static void sunscpal_dma_stop __P((struct sunscpal_softc *));
+
+static void
+sunscpal_dma_start(sc)
+       struct sunscpal_softc *sc;
+{
+       struct sunscpal_req *sr = sc->sc_current;
+       int xlen;
+       u_int16_t icr;
+
+       xlen = sc->sc_reqlen;
+
+       /* Let'er rip! */
+       icr = SUNSCPAL_READ_2(sc, sunscpal_icr);
+       icr |= SUNSCPAL_ICR_DMA_ENABLE |
+           ((xlen & 1) ? 0 : SUNSCPAL_ICR_WORD_MODE) | 
+           ((sr->sr_flags & SR_IMMED) ? 0 : SUNSCPAL_ICR_INTERRUPT_ENABLE);
+       SUNSCPAL_WRITE_2(sc, sunscpal_icr, icr);
+
+       sc->sc_state |= SUNSCPAL_DOINGDMA;
+
+#ifdef SUNSCPAL_DEBUG
+       if (sunscpal_debug & SUNSCPAL_DBG_DMA) {
+               printf("sunscpal_dma_start: started, flags=0x%x\n",
+                          sc->sc_state);
+       }
+#endif
+}
+
+#define        ICR_MASK (SUNSCPAL_ICR_PARITY_ERROR | SUNSCPAL_ICR_BUS_ERROR | SUNSCPAL_ICR_INTERRUPT_REQUEST)
+#define        POLL_TIMO       50000   /* X100 = 5 sec. */
+
+/*
+ * Poll (spin-wait) for DMA completion.
+ * Called right after xx_dma_start(), and
+ * xx_dma_stop() will be called next.
+ */
+static void
+sunscpal_dma_poll(sc)
+       struct sunscpal_softc *sc;
+{
+       struct sunscpal_req *sr = sc->sc_current;
+       int tmo;
+
+       /* Make sure DMA started successfully. */
+       if (sc->sc_state & SUNSCPAL_ABORTING)
+               return;
+
+       /* Wait for any "dma complete" or error bits. */



Home | Main Index | Thread Index | Old Index