BSD 4_4 release
[unix-history] / usr / src / sys / luna68k / dev / st.c
index 0c04b5a..8e1709d 100644 (file)
@@ -1,14 +1,40 @@
 /*
  * Copyright (c) 1992 OMRON Corporation.
 /*
  * Copyright (c) 1992 OMRON Corporation.
- * Copyright (c) 1992 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * OMRON Corporation.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * OMRON Corporation.
  *
- * %sccs.include.redist.c%
+ * 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 University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)st.c        7.3 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *     @(#)st.c        8.1 (Berkeley) 6/10/93
  */
 
 /*
  */
 
 /*
 #include "st.h"
 #if NST > 0
 
 #include "st.h"
 #if NST > 0
 
-#include "sys/param.h"
-#include "sys/systm.h"
-#include "sys/buf.h"
-#include "sys/file.h"
-#include "sys/proc.h"
-#include "sys/mtio.h"
-#include "sys/tprintf.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/buf.h>
+#include <sys/file.h>
+#include <sys/proc.h>
+#include <sys/mtio.h>
+#include <sys/tprintf.h>
 
 
-#include "device.h"
-#include "scsireg.h"
-#include "scsivar.h"
+#include <luna68k/dev/device.h>
+#include <luna68k/dev/scsireg.h>
+#include <luna68k/dev/scsivar.h>
 
 extern int scsi_test_unit_rdy();
 extern int scsi_request_sense();
 
 extern int scsi_test_unit_rdy();
 extern int scsi_request_sense();
@@ -102,7 +128,10 @@ stinit(hd)
        register struct hp_device *hd;
 {
        register struct st_softc *sc = &st_softc[hd->hp_unit];
        register struct hp_device *hd;
 {
        register struct st_softc *sc = &st_softc[hd->hp_unit];
+       register struct buf *bp;
 
 
+       for (bp = sttab; bp < &sttab[NST]; bp++)
+               bp->b_actb = &bp->b_actf;
        sc->sc_hd = hd;
        sc->sc_punit = stpunit(hd->hp_flags);
        sc->sc_type = stident(sc, hd);
        sc->sc_hd = hd;
        sc->sc_punit = stpunit(hd->hp_flags);
        sc->sc_type = stident(sc, hd);
@@ -197,25 +226,29 @@ stopen(dev, flag, type, p)
        if (sc->sc_flags & STF_OPEN)
                return(-1);
 
        if (sc->sc_flags & STF_OPEN)
                return(-1);
 
+       sc->sc_ctty = tprintf_open(p);
+
        /* drive ready ? */
        while ((stat = scsi_test_unit_rdy(ctlr, slave, 0)) != 0) {
                scsi_request_sense(ctlr, slave, 0, sp, 8);
 
                if (stat != STS_CHECKCOND) {
        /* drive ready ? */
        while ((stat = scsi_test_unit_rdy(ctlr, slave, 0)) != 0) {
                scsi_request_sense(ctlr, slave, 0, sp, 8);
 
                if (stat != STS_CHECKCOND) {
-                       printf("st%d: stopen: %s\n", scsi_status(stat));
+                       tprintf(sc->sc_ctty,
+                               "st%d:[stopen]   %s\n", unit, scsi_status(stat));
+                       tprintf_close(sc->sc_ctty);
                        return(EIO);
                }
 
                if (retry-- < 0) {
                        return(EIO);
                }
 
                if (retry-- < 0) {
-                       printf("st%d: stopen: %s\n", sense_key(sp->key));
+                       tprintf(sc->sc_ctty,
+                               "st%d:[stopen]   %s\n", unit, sense_key(sp->key));
+                       tprintf_close(sc->sc_ctty);
                        return(EIO);
                }
 
                DELAY(1000000);
        }
 
                        return(EIO);
                }
 
                DELAY(1000000);
        }
 
-       sc->sc_ctty = tprintf_open(p);
-
        sc->sc_flags |= STF_OPEN;
        if (flag & FWRITE)
                sc->sc_flags |= STF_WMODE;
        sc->sc_flags |= STF_OPEN;
        if (flag & FWRITE)
                sc->sc_flags |= STF_WMODE;
@@ -262,17 +295,11 @@ ststrategy(bp)
        register struct buf *dp = &sttab[unit];
        int s;
 
        register struct buf *dp = &sttab[unit];
        int s;
 
-       bp->av_forw = NULL;
-
+       bp->b_actf = NULL;
        s = splbio();
        s = splbio();
-
-       if (dp->b_actf == NULL)
-               dp->b_actf = bp;
-       else
-               dp->b_actl->av_forw = bp;
-
-       dp->b_actl = bp;
-
+       bp->b_actb = dp->b_actb;
+       *dp->b_actb = bp;
+       dp->b_actb = &bp->b_actf;
        if (dp->b_active == 0) {
                dp->b_active = 1;
                stustart(unit);
        if (dp->b_active == 0) {
                dp->b_active = 1;
                stustart(unit);
@@ -288,7 +315,7 @@ stustart(unit)
        register struct st_softc *sc = &st_softc[unit];
        register struct hp_device *hp = sc->sc_hd;
        register struct scsi_queue *dq = &sc->sc_dq;
        register struct st_softc *sc = &st_softc[unit];
        register struct hp_device *hp = sc->sc_hd;
        register struct scsi_queue *dq = &sc->sc_dq;
-       register struct buf *bp = sttab[unit].b_actf;
+       register struct buf *dp, *bp = sttab[unit].b_actf;
        register struct scsi_fmt_cdb *cmd;
        long nblks;
 
        register struct scsi_fmt_cdb *cmd;
        long nblks;
 
@@ -304,15 +331,18 @@ stustart(unit)
 
        if (bp->b_bcount % DEV_BSIZE) {
                tprintf(sc->sc_ctty,
 
        if (bp->b_bcount % DEV_BSIZE) {
                tprintf(sc->sc_ctty,
-                       "st%d: I/O not block aligned %d/%ld\n",
+                       "st%d:[stustart] I/O not block aligned %d/%ld\n",
                        unit, DEV_BSIZE, bp->b_bcount);
 
                bp->b_flags |= B_ERROR;
                bp->b_error = EIO;
                
                sttab[unit].b_errcnt = 0;
                        unit, DEV_BSIZE, bp->b_bcount);
 
                bp->b_flags |= B_ERROR;
                bp->b_error = EIO;
                
                sttab[unit].b_errcnt = 0;
-               sttab[unit].b_actf = bp->b_actf;
-               
+               if (dp = bp->b_actf)
+                       dp->b_actb = bp->b_actb;
+               else
+                       sttab[unit].b_actb = bp->b_actb;
+               *bp->b_actb = dp;
                bp->b_resid = 0;
                
                biodone(bp);
                bp->b_resid = 0;
                
                biodone(bp);
@@ -390,7 +420,7 @@ stintr(unit, stat)
        register struct st_softc *sc = &st_softc[unit];
        register struct scsi_xsense *xp = (struct scsi_xsense *) xsense_buff;
        register struct scsi_queue *dq = &sc->sc_dq;
        register struct st_softc *sc = &st_softc[unit];
        register struct scsi_xsense *xp = (struct scsi_xsense *) xsense_buff;
        register struct scsi_queue *dq = &sc->sc_dq;
-       register struct buf *bp = dq->dq_bp;
+       register struct buf *dp, *bp = dq->dq_bp;
        int ctlr  = dq->dq_ctlr;
        int slave = dq->dq_slave;
 
        int ctlr  = dq->dq_ctlr;
        int slave = dq->dq_slave;
 
@@ -442,40 +472,45 @@ stintr(unit, stat)
                }
 
                if (xp->filemark) {             /* End of File */
                }
 
                if (xp->filemark) {             /* End of File */
-                       tprintf(sc->sc_ctty, "st%d: End of File\n", unit);
+/*
+                       tprintf(sc->sc_ctty, "st%d:[stintr]   End of File\n", unit);
                        bp->b_flags |= B_ERROR;
                        bp->b_error = EIO;
                        bp->b_flags |= B_ERROR;
                        bp->b_error = EIO;
+ */
                        break;
                }
 
                if (xp->key) {
                        break;
                }
 
                if (xp->key) {
-                       tprintf(sc->sc_ctty, "st%d: %s\n", unit, sense_key(xp->key));
+                       tprintf(sc->sc_ctty, "st%d:[stintr]   %s\n", unit, sense_key(xp->key));
                        bp->b_flags |= B_ERROR;
                        bp->b_error = EIO;
                        break;
                }
 
                if (xp->eom) {          /* End of TAPE */
                        bp->b_flags |= B_ERROR;
                        bp->b_error = EIO;
                        break;
                }
 
                if (xp->eom) {          /* End of TAPE */
-                       tprintf(sc->sc_ctty, "st%d: End of Tape\n", unit);
+                       tprintf(sc->sc_ctty, "st%d:[stintr]   End of Tape\n", unit);
                        bp->b_flags |= B_ERROR;
                        bp->b_error = ENOSPC;
                        break;
                }
 
                        bp->b_flags |= B_ERROR;
                        bp->b_error = ENOSPC;
                        break;
                }
 
-               tprintf(sc->sc_ctty, "st%d: unknown scsi error\n", unit);
+               tprintf(sc->sc_ctty, "st%d:[stintr]   unknown scsi error\n", unit);
                bp->b_flags |= B_ERROR;
                bp->b_error = EIO;
                break;
 
        default:
                bp->b_flags |= B_ERROR;
                bp->b_error = EIO;
                break;
 
        default:
-               printf("st%d: stintr unknown stat 0x%x\n", unit, stat);
+               tprintf(sc->sc_ctty, "st%d:[stintr]   stintr unknown stat 0x%x\n", unit, stat);
                break;
        }
 
 done:
        sttab[unit].b_errcnt = 0;
                break;
        }
 
 done:
        sttab[unit].b_errcnt = 0;
-       sttab[unit].b_actf = bp->b_actf;
-       
+       if (dp = bp->b_actf)
+               dp->b_actb = bp->b_actb;
+       else
+               sttab[unit].b_actb = bp->b_actb;
+       *bp->b_actb = dp;
        bp->b_resid = 0;
 
        biodone(bp);
        bp->b_resid = 0;
 
        biodone(bp);
@@ -557,9 +592,11 @@ st_rewind(dev)
        if (stat == 0) {
                return(1);
        } else {
        if (stat == 0) {
                return(1);
        } else {
-               printf("st: rewind error\n");
+               tprintf(sc->sc_ctty, "st%d:[st_rewind]   rewind error\n", unit);
                scsi_request_sense(ctlr, slave, 0, sp, 8);
                scsi_request_sense(ctlr, slave, 0, sp, 8);
-               printf("st: status = 0x%x, sens key = 0x%x\n", stat, sp->key);
+               tprintf(sc->sc_ctty,
+                       "st%d:[st_rewind]   status = 0x%x, sens key = 0x%x\n",
+                       unit, stat, sp->key);
 
                if (retry > 0) {
                        DELAY(1000000);
 
                if (retry > 0) {
                        DELAY(1000000);
@@ -600,7 +637,7 @@ st_write_EOF(dev)
        if (stat == 0)
                return(1);
 
        if (stat == 0)
                return(1);
 
-       printf("st: write EOF error\n");
+       tprintf(sc->sc_ctty, "st%d:[st_write_EOF]   write EOF error\n", unit);
 
        return(0);
 }
 
        return(0);
 }