Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc Medium sized code overhaul:



details:   https://anonhg.NetBSD.org/src/rev/d4ea63320df1
branches:  trunk
changeset: 480832:d4ea63320df1
user:      pk <pk%NetBSD.org@localhost>
date:      Fri Jan 21 13:22:01 2000 +0000

description:
Medium sized code overhaul:
* Improve communication between the `hard' and `soft' interrupt handlers
  to better distinguish various interrupt sources.
* Eliminate several race conditions where we would set a time out handler
  only after starting the command on the hardware.
* Handle most timeouts by resetting the controller; there isn't much chance
  of recovery in any other way.  Currently, the exception is a timeout
  on I/O, in which case we first try to pulse the controller's TC line
  in order to abort the pseudo-dma sequence.  Apparently, "normal"
  conditions can induce such a timeout when there's no disk in the drive.
* Reduce the formatting gap parameter to 0x54.
* On the obio bus, interpret the `status' attribute.
* Minimize console diagnostic output if the errors we get appear to be
  caused by the absence of a disk.

diffstat:

 sys/arch/sparc/dev/fd.c           |  465 +++++++++++++++++++++++++------------
 sys/arch/sparc/dev/fdvar.h        |   22 +-
 sys/arch/sparc/sparc/bsd_fdintr.s |   36 +-
 3 files changed, 343 insertions(+), 180 deletions(-)

diffs (truncated from 1005 to 300 lines):

diff -r 3ba321c719aa -r d4ea63320df1 sys/arch/sparc/dev/fd.c
--- a/sys/arch/sparc/dev/fd.c   Fri Jan 21 12:32:54 2000 +0000
+++ b/sys/arch/sparc/dev/fd.c   Fri Jan 21 13:22:01 2000 +0000
@@ -1,4 +1,40 @@
-/*     $NetBSD: fd.c,v 1.70 2000/01/17 16:57:15 pk Exp $       */
+/*     $NetBSD: fd.c,v 1.71 2000/01/21 13:22:02 pk Exp $       */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by 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.
+ */
 
 /*-
  * Copyright (c) 1993, 1994, 1995 Charles M. Hannum.
@@ -90,21 +126,23 @@
 
 enum fdc_state {
        DEVIDLE = 0,
-       MOTORWAIT,
-       DOSEEK,
-       SEEKWAIT,
-       SEEKTIMEDOUT,
-       SEEKCOMPLETE,
-       DOIO,
-       IOCOMPLETE,
-       IOTIMEDOUT,
-       DORESET,
-       RESETCOMPLETE,
-       RESETTIMEDOUT,
-       DORECAL,
-       RECALWAIT,
-       RECALTIMEDOUT,
-       RECALCOMPLETE,
+       MOTORWAIT,      /*  1 */
+       DOSEEK,         /*  2 */
+       SEEKWAIT,       /*  3 */
+       SEEKTIMEDOUT,   /*  4 */
+       SEEKCOMPLETE,   /*  5 */
+       DOIO,           /*  6 */
+       IOCOMPLETE,     /*  7 */
+       IOTIMEDOUT,     /*  8 */
+       IOCLEANUPWAIT,  /*  9 */
+       IOCLEANUPTIMEDOUT,/*10 */
+       DORESET,        /* 11 */
+       RESETCOMPLETE,  /* 12 */
+       RESETTIMEDOUT,  /* 13 */
+       DORECAL,        /* 14 */
+       RECALWAIT,      /* 15 */
+       RECALTIMEDOUT,  /* 16 */
+       RECALCOMPLETE,  /* 17 */
 };
 
 /* software state, per controller */
@@ -128,7 +166,8 @@
 #define sc_reg_fifo    sc_io.fdcio_reg_fifo
 #define sc_reg_dor     sc_io.fdcio_reg_dor
 #define sc_reg_drs     sc_io.fdcio_reg_msr
-#define sc_istate      sc_io.fdcio_istate
+#define sc_itask       sc_io.fdcio_itask
+#define sc_istatus     sc_io.fdcio_istatus
 #define sc_data                sc_io.fdcio_data
 #define sc_tc          sc_io.fdcio_tc
 #define sc_nstat       sc_io.fdcio_nstat
@@ -136,6 +175,7 @@
 #define sc_intrcnt     sc_io.fdcio_intrcnt
 };
 
+#undef FDC_C_HANDLER
 #ifndef FDC_C_HANDLER
 extern struct fdcio    *fdciop;
 #endif
@@ -181,7 +221,7 @@
 
 /* The order of entries in the following table is important -- BEWARE! */
 struct fd_type fd_types[] = {
-       { 18,2,36,2,0xff,0xcf,0x1b,0x6c,80,2880,1,FDC_500KBPS,0xf6,1, "1.44MB"    }, /* 1.44MB diskette */
+       { 18,2,36,2,0xff,0xcf,0x1b,0x54,80,2880,1,FDC_500KBPS,0xf6,1, "1.44MB"    }, /* 1.44MB diskette */
        {  9,2,18,2,0xff,0xdf,0x2a,0x50,80,1440,1,FDC_250KBPS,0xf6,1, "720KB"    }, /* 3.5" 720kB diskette */
        {  9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,2,FDC_250KBPS,0xf6,1, "360KB/x"  }, /* 360kB in 720kB drive */
        {  8,2,16,3,0xff,0xdf,0x35,0x74,77,1232,1,FDC_500KBPS,0xf6,1, "1.2MB/NEC" } /* 1.2 MB japanese format */
@@ -239,14 +279,14 @@
 void   fd_motor_off __P((void *arg));
 void   fd_motor_on __P((void *arg));
 int    fdcresult __P((struct fdc_softc *fdc));
-int    out_fdc __P((struct fdc_softc *fdc, u_char x));
+int    fdc_wrfifo __P((struct fdc_softc *fdc, u_char x));
 void   fdcstart __P((struct fdc_softc *fdc));
-void   fdcstatus __P((struct device *dv, int n, char *s));
+void   fdcstatus __P((struct fdc_softc *fdc, char *s));
 void   fdc_reset __P((struct fdc_softc *fdc));
 void   fdctimeout __P((void *arg));
 void   fdcpseudointr __P((void *arg));
 #ifdef FDC_C_HANDLER
-int    fdchwintr __P((void *));
+int    fdc_c_hwintr __P((void *));
 #else
 void   fdchwintr __P((void));
 #endif
@@ -282,7 +322,7 @@
                ienab_bis(IE_L4);       \
 } while(0)
 #else
-#define AUDIO_SET_SWINTR ienab_bis(IE_FDSOFT)
+#define FD_SET_SWINTR ienab_bis(IE_FDSOFT)
 #endif /* defined(SUN4M) */
 #endif /* FDC_C_HANDLER */
 
@@ -423,13 +463,17 @@
        return (QUIET);
 }
 
+/*
+ * Configure several parameters and features on the FDC.
+ * Return 0 on success.
+ */
 static int
 fdconf(fdc)
        struct fdc_softc *fdc;
 {
        int     vroom;
 
-       if (out_fdc(fdc, NE7CMD_DUMPREG) || fdcresult(fdc) != 10)
+       if (fdc_wrfifo(fdc, NE7CMD_DUMPREG) || fdcresult(fdc) != 10)
                return (-1);
 
        /*
@@ -440,16 +484,20 @@
                vroom = 0x64;
 
        /* Configure controller to use FIFO and Implied Seek */
-       out_fdc(fdc, NE7CMD_CFG);
-       out_fdc(fdc, vroom);
-       out_fdc(fdc, fdc->sc_cfg);
-       out_fdc(fdc, 0); /* PRETRK */
+       if (fdc_wrfifo(fdc, NE7CMD_CFG) != 0)
+               return (-1);
+       if (fdc_wrfifo(fdc, vroom) != 0)
+               return (-1);
+       if (fdc_wrfifo(fdc, fdc->sc_cfg) != 0)
+               return (-1);
+       if (fdc_wrfifo(fdc, 0) != 0)    /* PRETRK */
+               return (-1);
        /* No result phase for the NE7CMD_CFG command */
 
        if ((fdc->sc_flags & FDC_82077) != 0) {
                /* Lock configuration across soft resets. */
-               out_fdc(fdc, NE7CMD_LOCK | CFG_LOCK);
-               if (fdcresult(fdc) != 1) {
+               if (fdc_wrfifo(fdc, NE7CMD_LOCK | CFG_LOCK) != 0 ||
+                   fdcresult(fdc) != 1) {
 #ifdef DEBUG
                        printf("fdconf: CFGLOCK failed");
 #endif
@@ -459,7 +507,7 @@
 
        return (0);
 #if 0
-       if (out_fdc(fdc, NE7CMD_VERSION) == 0 &&
+       if (fdc_wrfifo(fdc, NE7CMD_VERSION) == 0 &&
            fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x90) {
                if (fdc_debug)
                        printf("[version cmd]");
@@ -467,11 +515,6 @@
 #endif
 }
 
-       /*
-        * Controller and drives are represented by one and the same
-        * Openprom node, so we can as well check for the floppy boots here.
-        */
-
 void
 fdcattach_mainbus(parent, self, aux)
        struct device *parent, *self;
@@ -541,6 +584,11 @@
                            sa->sa_size,
                            fdc->sc_handle);
 
+       if (strcmp(getpropstring(sa->sa_node, "status"), "disabled") == 0) {
+               printf(": no drives attached\n");
+               return;
+       }
+
        if (sa->sa_nintr != 0)
                fdcattach(fdc, sa->sa_pri);
 }
@@ -554,7 +602,8 @@
        char code;
 
        fdc->sc_state = DEVIDLE;
-       fdc->sc_istate = ISTATE_IDLE;
+       fdc->sc_itask = FDC_ITASK_NONE;
+       fdc->sc_istatus = FDC_ISTATUS_NONE;
        fdc->sc_flags |= FDC_EIS;
        TAILQ_INIT(&fdc->sc_drives);
 
@@ -584,7 +633,7 @@
 
 #ifdef FDC_C_HANDLER
        (void)bus_intr_establish(fdc->sc_bustag, pri, 0,
-                                fdchwintr, fdc);
+                                fdc_c_hwintr, fdc);
 #else
        fdciop = &fdc->sc_io;
        (void)bus_intr_establish(fdc->sc_bustag, pri,
@@ -632,8 +681,8 @@
                auxregbisc(AUXIO4C_FDS, 0);
        }
        fdc->sc_nstat = 0;
-       out_fdc(fdc, NE7CMD_RECAL);
-       out_fdc(fdc, drive);
+       fdc_wrfifo(fdc, NE7CMD_RECAL);
+       fdc_wrfifo(fdc, drive);
 
        /* Wait for recalibration to complete */
        for (n = 0; n < 10000; n++) {
@@ -644,7 +693,7 @@
                if ((v & (NE7_RQM|NE7_DIO|NE7_CB)) == NE7_RQM) {
                        /* wait a bit longer till device *really* is ready */
                        delay(100000);
-                       if (out_fdc(fdc, NE7CMD_SENSEI))
+                       if (fdc_wrfifo(fdc, NE7CMD_SENSEI))
                                break;
                        if (fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x80)
                                /*
@@ -706,9 +755,9 @@
        fd->sc_deftype = type;
        fdc->sc_fd[drive] = fd;
 
-       out_fdc(fdc, NE7CMD_SPECIFY);
-       out_fdc(fdc, type->steprate);
-       out_fdc(fdc, 6 | NE7_SPECIFY_NODMA);
+       fdc_wrfifo(fdc, NE7CMD_SPECIFY);
+       fdc_wrfifo(fdc, type->steprate);
+       fdc_wrfifo(fdc, 6 | NE7_SPECIFY_NODMA);
 
        /*
         * Initialize and attach the disk structure.
@@ -952,16 +1001,20 @@
        splx(s);
 }
 
+/*
+ * Get status bytes off the FDC after a command has finished
+ * Returns the number of status bytes read; -1 on error.
+ * The return value is also stored in `sc_nstat'.
+ */
 int
 fdcresult(fdc)
        struct fdc_softc *fdc;
 {
        bus_space_tag_t t = fdc->sc_bustag;
        bus_space_handle_t h = fdc->sc_handle;
-       int j = 100000,
-           n = 0;
+       int j, n = 0;
 
-       for (; j; j--) {
+       for (j = 10000; j; j--) {
                u_int8_t v = bus_space_read_1(t, h, fdc->sc_reg_msr);
                v &= (NE7_DIO | NE7_RQM | NE7_CB);
                if (v == NE7_RQM)
@@ -974,14 +1027,18 @@
                        fdc->sc_status[n++] =
                                bus_space_read_1(t, h, fdc->sc_reg_fifo);
                } else
-                       delay(10);
+                       delay(1);
        }



Home | Main Index | Thread Index | Old Index