fixups just pre lint
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 9 Mar 1981 12:12:54 +0000 (04:12 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 9 Mar 1981 12:12:54 +0000 (04:12 -0800)
SCCS-vsn: sys/vax/vax/autoconf.c 4.24
SCCS-vsn: sys/vax/mba/hp.c 4.25
SCCS-vsn: sys/vax/mba/ht.c 4.9
SCCS-vsn: sys/vax/mba/mba.c 4.17
SCCS-vsn: sys/vax/uba/tm.c 4.24

usr/src/sys/vax/mba/hp.c
usr/src/sys/vax/mba/ht.c
usr/src/sys/vax/mba/mba.c
usr/src/sys/vax/uba/tm.c
usr/src/sys/vax/vax/autoconf.c

index 5b24918..722ab09 100644 (file)
@@ -1,4 +1,4 @@
-/*     hp.c    4.24    81/03/07        */
+/*     hp.c    4.25    81/03/08        */
 
 #include "hp.h"
 #if NHP > 0
 
 #include "hp.h"
 #if NHP > 0
@@ -6,11 +6,13 @@
  * HP disk driver for RP0x+RM0x
  *
  * TODO:
  * HP disk driver for RP0x+RM0x
  *
  * TODO:
- *     Check RM80 skip sector handling, esp when ECC's occur later
- *     Add reading of bad sector information and disk layout from sector 1
- *     Add bad sector forwarding code
- *     Check interaction with tape driver on same mba
- *     Check multiple drive handling
+ *     check RM80 skip sector handling, esp when ECC's occur later
+ *     add reading of bad sector information and disk layout from sector 1
+ *     add bad sector forwarding code
+ *     check interaction with tape driver on same mba
+ *     check multiple drive handling
+ *     check offset recovery handling
+ *     see if DCLR and/or RELEASE set attention status
  */
 
 #include "../h/param.h"
  */
 
 #include "../h/param.h"
@@ -101,8 +103,10 @@ struct hpst {
 };
 
 u_char hp_offset[16] = {
 };
 
 u_char hp_offset[16] = {
-    HP_P400, HP_M400, HP_P400, HP_M400, HP_P800, HP_M800, HP_P800, HP_M800,
-    HP_P1200, HP_M1200, HP_P1200, HP_M1200, 0, 0, 0, 0,
+    HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
+    HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
+    HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
+    0, 0, 0, 0,
 };
 
 struct buf     rhpbuf[NHP];
 };
 
 struct buf     rhpbuf[NHP];
@@ -172,14 +176,14 @@ hpustart(mi)
 
        if ((hpaddr->hpcs1&HP_DVA) == 0)
                return (MBU_BUSY);
 
        if ((hpaddr->hpcs1&HP_DVA) == 0)
                return (MBU_BUSY);
-       if ((hpaddr->hpds & HP_VV) == 0) {
+       if ((hpaddr->hpds & HPDS_VV) == 0) {
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                hpaddr->hpcs1 = HP_PRESET|HP_GO;
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                hpaddr->hpcs1 = HP_PRESET|HP_GO;
-               hpaddr->hpof = HP_FMT22;
+               hpaddr->hpof = HPOF_FMT22;
        }
        if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
                return (MBU_DODATA);
        }
        if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
                return (MBU_DODATA);
-       if ((hpaddr->hpds & (HP_DPR|HP_MOL)) != (HP_DPR|HP_MOL))
+       if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
                return (MBU_DODATA);
        st = &hpst[mi->mi_type];
        bn = dkblock(bp);
                return (MBU_DODATA);
        st = &hpst[mi->mi_type];
        bn = dkblock(bp);
@@ -217,13 +221,6 @@ hpstart(mi)
        sn = bn%st->nspc;
        tn = sn/st->nsect;
        sn %= st->nsect;
        sn = bn%st->nspc;
        tn = sn/st->nsect;
        sn %= st->nsect;
-       if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags&B_READ) != 0) {
-               hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017] | HP_FMT22;
-               hpaddr->hpcs1 = HP_OFFSET|HP_GO;
-               while (hpaddr->hpds & HP_PIP)
-                       ;
-               mbclrattn(mi);
-       }
        hpaddr->hpdc = bp->b_cylin;
        hpaddr->hpda = (tn << 8) + sn;
 }
        hpaddr->hpdc = bp->b_cylin;
        hpaddr->hpda = (tn << 8) + sn;
 }
@@ -236,8 +233,8 @@ hpdtint(mi, mbasr)
        register struct buf *bp = mi->mi_tab.b_actf;
        int retry = 0;
 
        register struct buf *bp = mi->mi_tab.b_actf;
        int retry = 0;
 
-       if (hpaddr->hpds&HP_ERR || mbasr&MBAEBITS) {
-               if (hpaddr->hper1&HP_WLE) {
+       if (hpaddr->hpds&HPDS_ERR || mbasr&MBAEBITS) {
+               if (hpaddr->hper1&HPER1_WLE) {
                        printf("hp%d: write locked\n", dkunit(bp));
                        bp->b_flags |= B_ERROR;
                } else if (++mi->mi_tab.b_errcnt > 27 ||
                        printf("hp%d: write locked\n", dkunit(bp));
                        bp->b_flags |= B_ERROR;
                } else if (++mi->mi_tab.b_errcnt > 27 ||
@@ -251,11 +248,11 @@ hpdtint(mi, mbasr)
                            hpaddr->hper2, HPER2_BITS);
                        bp->b_flags |= B_ERROR;
 #ifdef notdef
                            hpaddr->hper2, HPER2_BITS);
                        bp->b_flags |= B_ERROR;
 #ifdef notdef
-               } else if (hpaddr->hper2&HP_SSE) {
+               } else if (hpaddr->hper2&HPER2_SSE) {
                        hpecc(mi, 1);
                        return (MBD_RESTARTED);
 #endif
                        hpecc(mi, 1);
                        return (MBD_RESTARTED);
 #endif
-               } else if ((hpaddr->hper1&(HP_DCK|HP_ECH)) == HP_DCK) {
+               } else if ((hpaddr->hper1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) {
                        if (hpecc(mi, 0))
                                return (MBD_RESTARTED);
                        /* else done */
                        if (hpecc(mi, 0))
                                return (MBD_RESTARTED);
                        /* else done */
@@ -264,20 +261,40 @@ hpdtint(mi, mbasr)
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                if ((mi->mi_tab.b_errcnt&07) == 4) {
                        hpaddr->hpcs1 = HP_RECAL|HP_GO;
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                if ((mi->mi_tab.b_errcnt&07) == 4) {
                        hpaddr->hpcs1 = HP_RECAL|HP_GO;
-                       hprecal[mi->mi_unit] = 1;
-                       return (MBD_RESTARTED);
+                       hprecal[mi->mi_unit] = 0;
+                       goto nextrecal;
                }
                if (retry)
                        return (MBD_RETRY);
        }
                }
                if (retry)
                        return (MBD_RETRY);
        }
-       if (hprecal[mi->mi_unit]) {
+       switch (hprecal[mi->mi_unit]) {
+
+       case 1:
+               hpaddr->hpdc = bp->b_cylin;
+               hpaddr->hpcs1 = HP_SEEK|HP_GO;
+               goto nextrecal;
+       case 2:
+               if (mi->mi_tab.b_errcnt < 16 ||
+                   (bp->b_flags & B_READ) != 0)
+                       goto donerecal;
+               hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
+               hpaddr->hpcs1 = HP_OFFSET|HP_GO;
+               goto nextrecal;
+       nextrecal:
+               hprecal[mi->mi_unit]++;
+               return (MBD_RESTARTED);
+       donerecal:
                hprecal[mi->mi_unit] = 0;
                return (MBD_RETRY);
        }
        bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
        if (mi->mi_tab.b_errcnt > 16) {
                hprecal[mi->mi_unit] = 0;
                return (MBD_RETRY);
        }
        bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
        if (mi->mi_tab.b_errcnt > 16) {
+               /*
+                * This is fast and occurs rarely; we don't
+                * bother with interrupts.
+                */
                hpaddr->hpcs1 = HP_RTC|HP_GO;
                hpaddr->hpcs1 = HP_RTC|HP_GO;
-               while (hpaddr->hpds & HP_PIP)
+               while (hpaddr->hpds & HPDS_PIP)
                        ;
                mbclrattn(mi);
        }
                        ;
                mbclrattn(mi);
        }
@@ -329,7 +346,7 @@ hpecc(mi, rm80sse)
        reg = npf;
 #ifdef notdef
        if (rm80sse) {
        reg = npf;
 #ifdef notdef
        if (rm80sse) {
-               rp->hpof |= HP_SSEI;
+               rp->hpof |= HPOF_SSEI;
                reg--;          /* compensate in advance for reg-- below */
                goto sse;
        }
                reg--;          /* compensate in advance for reg-- below */
                goto sse;
        }
@@ -354,7 +371,7 @@ hpecc(mi, rm80sse)
                return (0);
 #ifdef notdef
 sse:
                return (0);
 #ifdef notdef
 sse:
-       if (rpof&HP_SSEI)
+       if (rpof&HPOF_SSEI)
                rp->hpda = rp->hpda + 1;
        rp->hper1 = 0;
        rp->hpcs1 = HP_RCOM|HP_GO;
                rp->hpda = rp->hpda + 1;
        rp->hper1 = 0;
        rp->hpcs1 = HP_RCOM|HP_GO;
@@ -406,10 +423,10 @@ hpdump(dev)
        mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
        mba->mba_cr = MBAINIT;
        hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
        mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
        mba->mba_cr = MBAINIT;
        hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
-       if ((hpaddr->hpds & HP_VV) == 0) {
+       if ((hpaddr->hpds & HPDS_VV) == 0) {
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                hpaddr->hpcs1 = HP_PRESET|HP_GO;
                hpaddr->hpcs1 = HP_DCLR|HP_GO;
                hpaddr->hpcs1 = HP_PRESET|HP_GO;
-               hpaddr->hpof = HP_FMT22;
+               hpaddr->hpof = HPOF_FMT22;
        }
        st = &hpst[mi->mi_type];
        if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
        }
        st = &hpst[mi->mi_type];
        if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
@@ -434,9 +451,9 @@ hpdump(dev)
                mba->mba_bcr = -(blk*NBPG);
                mba->mba_var = 0;
                hpaddr->hpcs1 = HP_WCOM | HP_GO;
                mba->mba_bcr = -(blk*NBPG);
                mba->mba_var = 0;
                hpaddr->hpcs1 = HP_WCOM | HP_GO;
-               while ((hpaddr->hpds & HP_DRY) == 0)
+               while ((hpaddr->hpds & HPDS_DRY) == 0)
                        ;
                        ;
-               if (hpaddr->hpds&HP_ERR)
+               if (hpaddr->hpds&HPDS_ERR)
                        return (EIO);
                start += blk*NBPG;
                num -= blk;
                        return (EIO);
                start += blk*NBPG;
                num -= blk;
index 9dddd97..bb34f84 100644 (file)
@@ -1,9 +1,19 @@
-/*     ht.c    4.8     81/03/07        */
+/*     ht.c    4.9     81/03/08        */
 
 #include "tu.h"
 #if NHT > 0
 /*
  * TM03/TU?? tape driver
 
 #include "tu.h"
 #if NHT > 0
 /*
  * TM03/TU?? tape driver
+ *
+ * TODO:
+ *     test tape writing
+ *     test error handling
+ *     test 2 tapes
+ *     test tape with disk on same mba
+ *     test dump code
+ *     try a mounted filesys on tape to check positioning code
+ *     test ioctl's
+ *     see how many rewind interrups we get if we kick when not at BOT
  */
 #include "../h/param.h"
 #include "../h/systm.h"
  */
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -41,11 +51,11 @@ struct      mba_driver htdriver =
 #define        H_NOREWIND      04
 #define        H_1600BPI       08
 
 #define        H_NOREWIND      04
 #define        H_1600BPI       08
 
-#define HTUNIT(dev)    (htunit[TUUNIT(dev)])
+#define HTUNIT(dev)    (tutoht[TUUNIT(dev)])
 
 #define        INF     (daddr_t)1000000L       /* a block number that wont exist */
 
 
 #define        INF     (daddr_t)1000000L       /* a block number that wont exist */
 
-struct ht_softc {
+struct tu_softc {
        char    sc_openf;
        char    sc_flags;
        daddr_t sc_blkno;
        char    sc_openf;
        char    sc_flags;
        daddr_t sc_blkno;
@@ -56,8 +66,8 @@ struct        ht_softc {
        short   sc_dens;
        struct  mba_device *sc_mi;
        int     sc_slave;
        short   sc_dens;
        struct  mba_device *sc_mi;
        int     sc_slave;
-} ht_softc[NTU];
-short  htunit[NTU];
+} tu_softc[NTU];
+short  tutoht[NTU];
 
 /*
  * Bits for sc_flags.
 
 /*
  * Bits for sc_flags.
@@ -77,52 +87,51 @@ htslave(mi, ms)
        struct mba_device *mi;
        struct mba_slave *ms;
 {
        struct mba_device *mi;
        struct mba_slave *ms;
 {
-       register struct ht_softc *sc = &ht_softc[ms->ms_unit];
+       register struct tu_softc *sc = &tu_softc[ms->ms_unit];
 
        sc->sc_mi = mi;
        sc->sc_slave = ms->ms_slave;
 
        sc->sc_mi = mi;
        sc->sc_slave = ms->ms_slave;
-       htunit[ms->ms_unit] = mi->mi_unit;
+       tutoht[ms->ms_unit] = mi->mi_unit;
 }
 
 htopen(dev, flag)
        dev_t dev;
        int flag;
 {
 }
 
 htopen(dev, flag)
        dev_t dev;
        int flag;
 {
-       register int unit;
+       register int tuunit;
        register struct mba_device *mi;
        register struct mba_device *mi;
-       register struct ht_softc *sc;
+       register struct tu_softc *sc;
+       int dens;
 
 
-       unit = TUUNIT(dev);
-       if (unit >= NTU || (sc = &ht_softc[unit])->sc_openf ||
+       tuunit = TUUNIT(dev);
+       if (tuunit >= NTU || (sc = &tu_softc[tuunit])->sc_openf ||
            (mi = htinfo[HTUNIT(dev)]) == 0 || mi->mi_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
            (mi = htinfo[HTUNIT(dev)]) == 0 || mi->mi_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
-       /*
-        * The NOP below serves two purposes:
-        * 1. To get a recent copy of the status registers.
-        * 2. To ensure that any outstanding rewinds are truly finished
-        */
        htcommand(dev, HT_SENSE, 1);
        htcommand(dev, HT_SENSE, 1);
+       dens =
+           ((minor(dev)&H_1600BPI)?HTTC_1600BPI:HTTC_800BPI)|
+               HTTC_PDP11|sc->sc_slave;
        if ((sc->sc_dsreg & HTDS_MOL) == 0 || 
        if ((sc->sc_dsreg & HTDS_MOL) == 0 || 
+          (sc->sc_dsreg & HTDS_BOT) == 0 && (flag&FWRITE) &&
+               dens != sc->sc_dens ||
           (flag & (FREAD|FWRITE)) == FWRITE && sc->sc_dsreg&HTDS_WRL) {
                u.u_error = EIO;
                return;
        }
           (flag & (FREAD|FWRITE)) == FWRITE && sc->sc_dsreg&HTDS_WRL) {
                u.u_error = EIO;
                return;
        }
-       sc->sc_dens =
-           ((minor(dev)&H_1600BPI)?HTTC_1600BPI:HTTC_800BPI)|
-               HTTC_PDP11|sc->sc_slave;
        sc->sc_openf = 1;
        sc->sc_blkno = (daddr_t)0;
        sc->sc_nxrec = INF;
        sc->sc_flags = 0;
        sc->sc_openf = 1;
        sc->sc_blkno = (daddr_t)0;
        sc->sc_nxrec = INF;
        sc->sc_flags = 0;
+       sc->sc_dens = dens;
 }
 
 htclose(dev, flag)
        register dev_t dev;
        register flag;
 {
 }
 
 htclose(dev, flag)
        register dev_t dev;
        register flag;
 {
-       register struct ht_softc *sc = &ht_softc[TUUNIT(dev)];
+       register struct tu_softc *sc = &tu_softc[TUUNIT(dev)];
 
        if (flag == FWRITE || ((flag&FWRITE) && (sc->sc_flags&H_WRITTEN))) {
                htcommand(dev, HT_WEOF, 1);
 
        if (flag == FWRITE || ((flag&FWRITE) && (sc->sc_flags&H_WRITTEN))) {
                htcommand(dev, HT_WEOF, 1);
@@ -130,16 +139,10 @@ htclose(dev, flag)
                htcommand(dev, HT_SREV, 1);
        }
        if ((minor(dev)&H_NOREWIND) == 0)
                htcommand(dev, HT_SREV, 1);
        }
        if ((minor(dev)&H_NOREWIND) == 0)
-               /* 0 as third arg means don't wait */
                htcommand(dev, HT_REW, 0);
        sc->sc_openf = 0;
 }
 
                htcommand(dev, HT_REW, 0);
        sc->sc_openf = 0;
 }
 
-/*
- * Do a non-data-transfer command.
- *
- * N.B.: Count should be zero ONLY for rewind during close.
- */
 htcommand(dev, com, count)
        dev_t dev;
        int com, count;
 htcommand(dev, com, count)
        dev_t dev;
        int com, count;
@@ -173,8 +176,7 @@ htcommand(dev, com, count)
 htstrategy(bp)
        register struct buf *bp;
 {
 htstrategy(bp)
        register struct buf *bp;
 {
-       register int unit = HTUNIT(bp->b_dev);
-       register struct mba_device *mi = htinfo[unit];
+       register struct mba_device *mi = htinfo[HTUNIT(bp->b_dev)];
        register struct buf *dp;
 
        bp->av_forw = NULL;
        register struct buf *dp;
 
        bp->av_forw = NULL;
@@ -196,8 +198,7 @@ htustart(mi)
        register struct htdevice *htaddr =
            (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
        register struct htdevice *htaddr =
            (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
-       int unit = TUUNIT(bp->b_dev);
-       register struct ht_softc *sc = &ht_softc[unit];
+       register struct tu_softc *sc = &tu_softc[TUUNIT(bp->b_dev)];
        daddr_t blkno;
 
        htaddr->httc = sc->sc_dens;
        daddr_t blkno;
 
        htaddr->httc = sc->sc_dens;
@@ -212,17 +213,19 @@ htustart(mi)
                bp->b_flags |= B_ERROR;
                return (MBU_NEXT);
        }
                bp->b_flags |= B_ERROR;
                return (MBU_NEXT);
        }
-       if (bp != &chtbuf[unit]) {
+       if (bp != &chtbuf[HTUNIT(bp->b_dev)]) {
                if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) {
                        bp->b_flags |= B_ERROR;
                        bp->b_error = ENXIO;
                        return (MBU_NEXT);
                if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) {
                        bp->b_flags |= B_ERROR;
                        bp->b_error = ENXIO;
                        return (MBU_NEXT);
-               } else if (dbtofsb(bp->b_blkno) == sc->sc_nxrec &&
+               }
+               if (dbtofsb(bp->b_blkno) == sc->sc_nxrec &&
                    bp->b_flags&B_READ) {
                        bp->b_resid = bp->b_bcount;
                        clrbuf(bp);
                        return (MBU_NEXT);
                    bp->b_flags&B_READ) {
                        bp->b_resid = bp->b_bcount;
                        clrbuf(bp);
                        return (MBU_NEXT);
-               } else if ((bp->b_flags&B_READ)==0)
+               }
+               if ((bp->b_flags&B_READ)==0)
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1;
        } else {
                if (bp->b_command == HT_SENSE)
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1;
        } else {
                if (bp->b_command == HT_SENSE)
@@ -237,14 +240,14 @@ htustart(mi)
        if ((blkno = sc->sc_blkno) == dbtofsb(bp->b_blkno)) {
                htaddr->htfc = -bp->b_bcount;
                if ((bp->b_flags&B_READ) == 0) {
        if ((blkno = sc->sc_blkno) == dbtofsb(bp->b_blkno)) {
                htaddr->htfc = -bp->b_bcount;
                if ((bp->b_flags&B_READ) == 0) {
-                       if (mi->mi_tab.b_errcnt)
-                               if (sc->sc_flags & H_ERASED)
-                                       sc->sc_flags &= ~H_ERASED;
-                               else {
+                       if (mi->mi_tab.b_errcnt) {
+                               if ((sc->sc_flags & H_ERASED) == 0) {
                                        sc->sc_flags |= H_ERASED;
                                        htaddr->htcs1 = HT_ERASE | HT_GO;
                                        return (MBU_STARTED);
                                }
                                        sc->sc_flags |= H_ERASED;
                                        htaddr->htcs1 = HT_ERASE | HT_GO;
                                        return (MBU_STARTED);
                                }
+                               sc->sc_flags &= ~H_ERASED;
+                       }
                        if (htaddr->htds & HTDS_EOT) {
                                bp->b_resid = bp->b_bcount;
                                return (MBU_NEXT);
                        if (htaddr->htds & HTDS_EOT) {
                                bp->b_resid = bp->b_bcount;
                                return (MBU_NEXT);
@@ -262,45 +265,39 @@ htustart(mi)
        return (MBU_STARTED);
 }
 
        return (MBU_STARTED);
 }
 
-/*
- * data transfer interrupt - must be read or write
- */
-/*ARGSUSED*/
-htdtint(mi, mbasr)
+htdtint(mi, mbsr)
        register struct mba_device *mi;
        register struct mba_device *mi;
-       int mbasr;
+       int mbsr;
 {
        register struct htdevice *htaddr = (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
 {
        register struct htdevice *htaddr = (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
-       register struct ht_softc *sc;
+       register struct tu_softc *sc;
        int ds, er, mbs;
 
        int ds, er, mbs;
 
-       sc = &ht_softc[TUUNIT(bp->b_dev)];
+       sc = &tu_softc[TUUNIT(bp->b_dev)];
        ds = sc->sc_dsreg = MASKREG(htaddr->htds);
        er = sc->sc_erreg = MASKREG(htaddr->hter);
        sc->sc_resid = MASKREG(htaddr->htfc);
        ds = sc->sc_dsreg = MASKREG(htaddr->htds);
        er = sc->sc_erreg = MASKREG(htaddr->hter);
        sc->sc_resid = MASKREG(htaddr->htfc);
-       mbs = mbasr;
+       mbs = mbsr;
        sc->sc_blkno++;
        if((bp->b_flags & B_READ) == 0)
                sc->sc_flags |= H_WRITTEN;
        sc->sc_blkno++;
        if((bp->b_flags & B_READ) == 0)
                sc->sc_flags |= H_WRITTEN;
-       if ((ds&(HTDS_ERR|HTDS_MOL)) != HTDS_MOL ||
-           mbs & MBAEBITS) {
+       if ((ds&(HTDS_ERR|HTDS_MOL)) != HTDS_MOL || mbs & MBSR_EBITS) {
                htaddr->htcs1 = HT_DCLR|HT_GO;
                mbclrattn(mi);
                if (bp == &rhtbuf[HTUNIT(bp->b_dev)]) {
                        er &= ~HTER_FCE;
                htaddr->htcs1 = HT_DCLR|HT_GO;
                mbclrattn(mi);
                if (bp == &rhtbuf[HTUNIT(bp->b_dev)]) {
                        er &= ~HTER_FCE;
-                       mbs &= ~(MBS_DTABT|MBS_MBEXC);
+                       mbs &= ~(MBSR_DTABT|MBSR_MBEXC);
                }
                if (bp->b_flags & B_READ && ds & HTDS_PES)
                        er &= ~(HTER_CSITM|HTER_CORCRC);
                }
                if (bp->b_flags & B_READ && ds & HTDS_PES)
                        er &= ~(HTER_CSITM|HTER_CORCRC);
-               if (er&HTER_HARD ||
-                   mbs&MBAEBITS || (ds&HTDS_MOL) == 0 ||
+               if (er&HTER_HARD || mbs&MBSR_EBITS || (ds&HTDS_MOL) == 0 ||
                    er && ++mi->mi_tab.b_errcnt >= 7) {
                        if ((ds & HTDS_MOL) == 0 && sc->sc_openf > 0)
                                sc->sc_openf = -1;
                    er && ++mi->mi_tab.b_errcnt >= 7) {
                        if ((ds & HTDS_MOL) == 0 && sc->sc_openf > 0)
                                sc->sc_openf = -1;
-                       printf("tu%d: hard error bn%d mbasr=%b er=%b\n",
+                       printf("tu%d: hard error bn%d mbsr=%b er=%b\n",
                            TUUNIT(bp->b_dev), bp->b_blkno,
                            TUUNIT(bp->b_dev), bp->b_blkno,
-                           mbasr, mbasr_bits,
+                           mbsr, mbsr_bits,
                            MASKREG(htaddr->hter), HTER_BITS);
                        bp->b_flags |= B_ERROR;
                        return (MBD_DONE);
                            MASKREG(htaddr->hter), HTER_BITS);
                        bp->b_flags |= B_ERROR;
                        return (MBD_DONE);
@@ -318,39 +315,40 @@ htdtint(mi, mbasr)
        return (MBD_DONE);
 }
 
        return (MBD_DONE);
 }
 
-/*
- * non-data-transfer interrupt
- */
 htndtint(mi)
        register struct mba_device *mi;
 {
        register struct htdevice *htaddr = (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
 htndtint(mi)
        register struct mba_device *mi;
 {
        register struct htdevice *htaddr = (struct htdevice *)mi->mi_drv;
        register struct buf *bp = mi->mi_tab.b_actf;
-       register struct ht_softc *sc;
+       register struct tu_softc *sc;
        int er, ds, fc;
 
        int er, ds, fc;
 
-       if (bp == 0)
-               return (MBN_SKIP);
-       sc = &ht_softc[TUUNIT(bp->b_dev)];
-       ds = sc->sc_dsreg = MASKREG(htaddr->htds);
-       er = sc->sc_erreg = MASKREG(htaddr->hter);
-       fc = sc->sc_resid = MASKREG(htaddr->htfc);
-       if (sc->sc_erreg) {
+       ds = MASKREG(htaddr->htds);
+       er = MASKREG(htaddr->hter);
+       fc = MASKREG(htaddr->htfc);
+       if (er) {
                htaddr->htcs1 = HT_DCLR|HT_GO;
                mbclrattn(mi);
        }
                htaddr->htcs1 = HT_DCLR|HT_GO;
                mbclrattn(mi);
        }
-       if (sc->sc_flags&H_REWIND) {
-               sc->sc_flags &= ~H_REWIND;
-               return (MBN_CONT);
-       }
-       if (bp == &chtbuf[TUUNIT(bp->b_dev)]) {
-               if (bp->b_command == HT_REWOFFL)
+       if (bp == 0)
+               return (MBN_SKIP);
+       sc = &tu_softc[TUUNIT(bp->b_dev)];
+       sc->sc_dsreg = ds;
+       sc->sc_erreg = er;
+       sc->sc_resid = fc;
+       if (bp == &chtbuf[HTUNIT(bp->b_dev)]) {
+               switch (bp->b_command) {
+               case HT_REWOFFL:
                        /* offline is on purpose; don't do anything special */
                        ds |= HTDS_MOL; 
                        /* offline is on purpose; don't do anything special */
                        ds |= HTDS_MOL; 
-               else if (bp->b_resid == HT_SREV &&
-                   er == (HTER_NEF|HTER_FCE) &&
-                   ds&HTDS_BOT && bp->b_bcount == INF)
-                       er &= ~HTER_NEF;
+                       break;
+               case HT_SREV:
+                       /* if backspace file hit bot, its not an error */
+                       if (er == (HTER_NEF|HTER_FCE) && ds&HTDS_BOT &&
+                           bp->b_repcnt == INF)
+                               er &= ~HTER_NEF;
+                       break;
+               }
                er &= ~HTER_FCE;
                if (er == 0)
                        ds &= ~HTDS_ERR;
                er &= ~HTER_FCE;
                if (er == 0)
                        ds &= ~HTDS_ERR;
@@ -364,17 +362,17 @@ htndtint(mi)
                bp->b_flags |= B_ERROR;
                return (MBN_DONE);
        }
                bp->b_flags |= B_ERROR;
                return (MBN_DONE);
        }
-       if (bp == &chtbuf[TUUNIT(bp->b_dev)]) {
+       if (bp == &chtbuf[HTUNIT(bp->b_dev)]) {
                if (sc->sc_flags & H_REWIND)
                        return (ds & HTDS_BOT ? MBN_DONE : MBN_RETRY);
                bp->b_resid = -sc->sc_resid;
                return (MBN_DONE);
        }
        if (ds & HTDS_TM)
                if (sc->sc_flags & H_REWIND)
                        return (ds & HTDS_BOT ? MBN_DONE : MBN_RETRY);
                bp->b_resid = -sc->sc_resid;
                return (MBN_DONE);
        }
        if (ds & HTDS_TM)
-               if (sc->sc_blkno > dbtofsb(bp->b_blkno)) {/* reversing */
+               if (sc->sc_blkno > dbtofsb(bp->b_blkno)) {
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) - fc;
                        sc->sc_blkno = sc->sc_nxrec;
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) - fc;
                        sc->sc_blkno = sc->sc_nxrec;
-               } else {                        /* spacing forward */
+               } else {
                        sc->sc_blkno = dbtofsb(bp->b_blkno) + fc;
                        sc->sc_nxrec = sc->sc_blkno - 1;
                }
                        sc->sc_blkno = dbtofsb(bp->b_blkno) + fc;
                        sc->sc_nxrec = sc->sc_blkno - 1;
                }
@@ -405,17 +403,18 @@ htwrite(dev)
 htphys(dev)
        dev_t dev;
 {
 htphys(dev)
        dev_t dev;
 {
-       register int unit;
-       register struct ht_softc *sc;
+       register int htunit;
+       register struct tu_softc *sc;
+       register struct mba_device *mi;
        daddr_t a;
 
        daddr_t a;
 
-       unit = HTUNIT(dev);
-       if (unit >= NHT) {
+       htunit = HTUNIT(dev);
+       if (htunit >= NHT || (mi = htinfo[htunit]) == 0 || mi->mi_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
        a = u.u_offset >> 9;
                u.u_error = ENXIO;
                return;
        }
        a = u.u_offset >> 9;
-       sc = &ht_softc[unit];
+       sc = &tu_softc[TUUNIT(dev)];
        sc->sc_blkno = dbtofsb(a);
        sc->sc_nxrec = dbtofsb(a)+1;
 }
        sc->sc_blkno = dbtofsb(a);
        sc->sc_nxrec = dbtofsb(a)+1;
 }
@@ -427,9 +426,8 @@ htioctl(dev, cmd, addr, flag)
        caddr_t addr;
        int flag;
 {
        caddr_t addr;
        int flag;
 {
-       register unit = HTUNIT(dev);
-       register struct ht_softc *sc = &ht_softc[unit];
-       register struct buf *bp = &chtbuf[unit];
+       register struct tu_softc *sc = &tu_softc[TUUNIT(dev)];
+       register struct buf *bp = &chtbuf[HTUNIT(dev)];
        register callcount;
        int fcount;
        struct mtop mtop;
        register callcount;
        int fcount;
        struct mtop mtop;
@@ -476,8 +474,7 @@ htioctl(dev, cmd, addr, flag)
                                u.u_error = EIO;
                                break;
                        }
                                u.u_error = EIO;
                                break;
                        }
-                       if ((chtbuf[HTUNIT(bp->b_dev)].b_flags&B_ERROR) ||
-                           sc->sc_dsreg&HTDS_BOT)
+                       if ((bp->b_flags&B_ERROR) || sc->sc_dsreg&HTDS_BOT)
                                break;
                }
                geterror(bp);
                                break;
                }
                geterror(bp);
@@ -511,10 +508,7 @@ htdump()
                return (ENXIO);
        mi = phys(htinfo[0], struct mba_device *);
        mp = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
                return (ENXIO);
        mi = phys(htinfo[0], struct mba_device *);
        mp = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
-#if VAX780
-       if (cpu == VAX780)
-               mbainit(mp);
-#endif
+       mbainit(mp);
        htaddr = (struct htdevice *)&mp->mba_drv[mi->mi_drive];
        htaddr->httc = HTTC_PDP11|HTTC_1600BPI;
        htaddr->htcs1 = HT_DCLR|HT_GO;
        htaddr = (struct htdevice *)&mp->mba_drv[mi->mi_drive];
        htaddr->httc = HTTC_PDP11|HTTC_1600BPI;
        htaddr->htcs1 = HT_DCLR|HT_GO;
index a43e033..10972bf 100644 (file)
@@ -1,10 +1,9 @@
-/*     mba.c   4.16    81/03/07        */
+/*     mba.c   4.17    81/03/08        */
 
 #include "mba.h"
 #if NMBA > 0
 /*
 
 #include "mba.h"
 #if NMBA > 0
 /*
- * Massbus driver; arbitrates massbus using device
- * driver routines.  This module provides common functions.
+ * Massbus driver, arbitrates a massbus among attached devices.
  */
 #include "../h/param.h"
 #include "../h/systm.h"
  */
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -21,7 +20,7 @@
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
-char   mbasr_bits[] = MBASR_BITS;
+char   mbsr_bits[] = MBSR_BITS;
 /*
  * Start activity on a massbus device.
  * We are given the device's mba_device structure and activate
 /*
  * Start activity on a massbus device.
  * We are given the device's mba_device structure and activate
@@ -133,7 +132,7 @@ loop:
         * If this device isn't present and on-line, then
         * we screwed up, and can't really do the operation.
         */
         * If this device isn't present and on-line, then
         * we screwed up, and can't really do the operation.
         */
-       if ((mi->mi_drv->mbd_ds & (MBD_DPR|MBD_MOL)) != (MBD_DPR|MBD_MOL)) {
+       if ((mi->mi_drv->mbd_ds & MBDS_DREADY) != MBDS_DREADY) {
                printf("%s%d: not ready\n", mi->mi_driver->md_dname,
                    dkunit(bp));
                mi->mi_tab.b_actf = bp->av_forw;
                printf("%s%d: not ready\n", mi->mi_driver->md_dname,
                    dkunit(bp));
                mi->mi_tab.b_actf = bp->av_forw;
@@ -162,7 +161,7 @@ loop:
        mbp->mba_var = mbasetup(mi);
        mbp->mba_bcr = -bp->b_bcount;
        mi->mi_drv->mbd_cs1 =
        mbp->mba_var = mbasetup(mi);
        mbp->mba_bcr = -bp->b_bcount;
        mi->mi_drv->mbd_cs1 =
-           (bp->b_flags & B_READ) ? MBD_RCOM|MBD_GO : MBD_WCOM|MBD_GO;
+           (bp->b_flags & B_READ) ? MB_RCOM|MB_GO : MB_WCOM|MB_GO;
        if (mi->mi_dk >= 0) {
                dk_busy |= 1 << mi->mi_dk;
                dk_xfer[mi->mi_dk]++;
        if (mi->mi_dk >= 0) {
                dk_busy |= 1 << mi->mi_dk;
                dk_xfer[mi->mi_dk]++;
@@ -192,7 +191,7 @@ mbintr(mbanum)
        mbasr = mbp->mba_sr;
        mbp->mba_sr = mbasr;
 #if VAX750
        mbasr = mbp->mba_sr;
        mbp->mba_sr = mbasr;
 #if VAX750
-       if (mbasr&MBS_CBHUNG) {
+       if (mbasr&MBSR_CBHUNG) {
                printf("mba%d: control bus hung\n", mbanum);
                panic("cbhung");
        }
                printf("mba%d: control bus hung\n", mbanum);
                panic("cbhung");
        }
@@ -201,13 +200,6 @@ mbintr(mbanum)
        as = mbp->mba_drv[0].mbd_as & 0xff;
        mbp->mba_drv[0].mbd_as = as;
 
        as = mbp->mba_drv[0].mbd_as & 0xff;
        mbp->mba_drv[0].mbd_as = as;
 
-       /*
-        * Disable interrupts from the massbus adapter
-        * for the duration of the operation of the massbus
-        * driver, so that spurious interrupts won't be generated.
-        */
-       mbp->mba_cr &= ~MBAIE;
-
        /*
         * If the mba was active, process the data transfer
         * complete interrupt; otherwise just process units which
        /*
         * If the mba was active, process the data transfer
         * complete interrupt; otherwise just process units which
@@ -216,14 +208,15 @@ mbintr(mbanum)
        if (mhp->mh_active) {
                /*
                 * Clear attention status for drive whose data
        if (mhp->mh_active) {
                /*
                 * Clear attention status for drive whose data
-                * transfer completed, and give the dtint driver
+                * transfer related operation completed,
+                * and give the dtint driver
                 * routine a chance to say what is next.
                 */
                mi = mhp->mh_actf;
                as &= ~(1 << mi->mi_drive);
                dk_busy &= ~(1 << mi->mi_dk);
                bp = mi->mi_tab.b_actf;
                 * routine a chance to say what is next.
                 */
                mi = mhp->mh_actf;
                as &= ~(1 << mi->mi_drive);
                dk_busy &= ~(1 << mi->mi_dk);
                bp = mi->mi_tab.b_actf;
-               switch((*mi->mi_driver->md_dtint)(mi, mbasr)) {
+               switch ((*mi->mi_driver->md_dtint)(mi, mbasr)) {
 
                case MBD_DONE:          /* all done, for better or worse */
                        /*
 
                case MBD_DONE:          /* all done, for better or worse */
                        /*
@@ -269,47 +262,33 @@ mbintr(mbanum)
                        continue;
                /*
                 * If driver has a handler for non-data transfer
                        continue;
                /*
                 * If driver has a handler for non-data transfer
-                * interrupts, give it a chance to tell us that
-                * the operation needs to be redone
+                * interrupts, give it a chance to tell us what to do.
                 */
                if (mi->mi_driver->md_ndint) {
                        mi->mi_tab.b_active = 0;
                        switch ((*mi->mi_driver->md_ndint)(mi)) {
 
                 */
                if (mi->mi_driver->md_ndint) {
                        mi->mi_tab.b_active = 0;
                        switch ((*mi->mi_driver->md_ndint)(mi)) {
 
-                       case MBN_DONE:
-                               /*
-                                * Non-data transfer interrupt
-                                * completed i/o request's processing.
-                                */
+                       case MBN_DONE:          /* operation completed */
                                mi->mi_tab.b_errcnt = 0;
                                bp = mi->mi_tab.b_actf;
                                mi->mi_tab.b_actf = bp->av_forw;
                                iodone(bp);
                                mi->mi_tab.b_errcnt = 0;
                                bp = mi->mi_tab.b_actf;
                                mi->mi_tab.b_actf = bp->av_forw;
                                iodone(bp);
-                               /* fall into... */
-                       case MBN_RETRY:
+                               /* fall into common code */
+                       case MBN_RETRY:         /* operation continues */
                                if (mi->mi_tab.b_actf)
                                        mbustart(mi);
                                break;
                                if (mi->mi_tab.b_actf)
                                        mbustart(mi);
                                break;
-
-                       case MBN_SKIP:
-                               /*
-                                * Ignore (unsolicited interrupt, e.g.)
-                                */
-                               break;
-
-                       case MBN_CONT:
-                               /*
-                                * Continue with unit active, e.g.
-                                * between first and second rewind
-                                * interrupts.
-                                */
-                               mi->mi_tab.b_active = 1;
+                       case MBN_SKIP:          /* ignore unsol. interrupt */
                                break;
                                break;
-
                        default:
                                panic("mbintr");
                        }
                } else
                        default:
                                panic("mbintr");
                        }
                } else
+                       /*
+                        * If there is no non-data transfer interrupt
+                        * routine, then we should just
+                        * restart the unit, leading to a mbstart() soon.
+                        */
                        mbustart(mi);
        }
        /*
                        mbustart(mi);
        }
        /*
@@ -318,7 +297,7 @@ mbintr(mbanum)
         */
        if (mhp->mh_actf && !mhp->mh_active)
                mbstart(mhp);
         */
        if (mhp->mh_actf && !mhp->mh_active)
                mbstart(mhp);
-       mbp->mba_cr |= MBAIE;
+       /* THHHHATS all folks... */
 }
 
 /*
 }
 
 /*
@@ -368,11 +347,14 @@ mbasetup(mi)
        return (vaddr);
 }
 
        return (vaddr);
 }
 
+/*
+ * Init and interrupt enable a massbus adapter.
+ */
 mbainit(mp)
        struct mba_regs *mp;
 {
 
 mbainit(mp)
        struct mba_regs *mp;
 {
 
-       mp->mba_cr = MBAINIT;
-       mp->mba_cr = MBAIE;
+       mp->mba_cr = MBCR_INIT;
+       mp->mba_cr = MBCR_IE;
 }
 #endif
 }
 #endif
index 9ef5f44..eead0b3 100644 (file)
@@ -1,4 +1,4 @@
-/*     tm.c    4.23    %G%     */
+/*     tm.c    4.24    %G%     */
 
 #include "te.h"
 #if NTM > 0
 
 #include "te.h"
 #if NTM > 0
@@ -6,12 +6,14 @@ int   tmgapsdcnt;             /* DEBUG */
 /*
  * TM11/TE10 tape driver
  *
 /*
  * TM11/TE10 tape driver
  *
- * Todo:
- *     Test driver with more than one slave
- *     Test reset code
- *     Do rewinds without hanging in driver
+ * TODO:
+ *     test driver with more than one slave
+ *     test driver with more than one controller
+ *     test reset code
+ *     test rewinds without hanging in driver
+ *     what happens if you offline tape during rewind?
+ *     test using file system on tape
  */
  */
-#define        DELAY(N)                { register int d = N; while (--d > 0); }
 #include "../h/param.h"
 #include "../h/buf.h"
 #include "../h/dir.h"
 #include "../h/param.h"
 #include "../h/buf.h"
 #include "../h/dir.h"
@@ -30,22 +32,40 @@ int tmgapsdcnt;             /* DEBUG */
 
 #include "../h/tmreg.h"
 
 
 #include "../h/tmreg.h"
 
-struct buf     ctmbuf[NTE];
-struct buf     rtmbuf[NTE];
+/*
+ * There is a ctmbuf per tape controller.
+ * It is used as the token to pass to the internal routines
+ * to execute tape ioctls, and also acts as a lock on the slaves
+ * on the controller, since there is only one per controller.
+ * In particular, when the tape is rewinding on close we release
+ * the user process but any further attempts to use the tape drive
+ * before the rewind completes will hang waiting for ctmbuf.
+ */
+struct buf     ctmbuf[NTM];
+
+/*
+ * Raw tape operations use rtmbuf.  The driver
+ * notices when rtmbuf is being used and allows the user
+ * program to continue after errors and read records
+ * not of the standard length (BSIZE).
+ */
+struct buf     rtmbuf[NTM];
 
 
+/*
+ * Driver unibus interface routines and variables.
+ */
 int    tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr();
 struct uba_ctlr *tmminfo[NTM];
 int    tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr();
 struct uba_ctlr *tmminfo[NTM];
-struct uba_device *tmdinfo[NTE];
-struct buf tmutab[NTE];
-#ifdef notyet
-struct uba_device *tmip[NTM][4];
-#endif
+struct uba_device *tedinfo[NTE];
+struct buf teutab[NTE];
+short  tetotm[NTE];
 u_short        tmstd[] = { 0772520, 0 };
 struct uba_driver tmdriver =
 u_short        tmstd[] = { 0772520, 0 };
 struct uba_driver tmdriver =
- { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tmdinfo, "tm", tmminfo, 0 };
+ { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tedinfo, "tm", tmminfo, 0 };
 
 /* bits in minor device */
 
 /* bits in minor device */
-#define        TMUNIT(dev)     (minor(dev)&03)
+#define        TEUNIT(dev)     (minor(dev)&03)
+#define        TMUNIT(dev)     (tetotm[TEUNIT(dev)])
 #define        T_NOREWIND      04
 #define        T_1600BPI       08
 
 #define        T_NOREWIND      04
 #define        T_1600BPI       08
 
@@ -53,33 +73,42 @@ struct      uba_driver tmdriver =
 
 /*
  * Software state per tape transport.
 
 /*
  * Software state per tape transport.
+ *
+ * 1. A tape drive is a unique-open device; we refuse opens when it is already.
+ * 2. We keep track of the current position on a block tape and seek
+ *    before operations by forward/back spacing if necessary.
+ * 3. We remember if the last operation was a write on a tape, so if a tape
+ *    is open read write and the last thing done is a write we can
+ *    write a standard end of tape mark (two eofs).
+ * 4. We remember the status registers after the last command, using
+ *    then internally and returning them to the SENSE ioctl.
+ * 5. We remember the last density the tape was used at.  If it is
+ *    not a BOT when we start using it and we are writing, we don't
+ *    let the density be changed.
  */
  */
-struct tm_softc {
+struct te_softc {
        char    sc_openf;       /* lock against multiple opens */
        char    sc_lastiow;     /* last op was a write */
        daddr_t sc_blkno;       /* block number, for block device tape */
        char    sc_openf;       /* lock against multiple opens */
        char    sc_lastiow;     /* last op was a write */
        daddr_t sc_blkno;       /* block number, for block device tape */
-       daddr_t sc_nxrec;       /* desired block position */
+       daddr_t sc_nxrec;       /* position of end of tape, if known */
        u_short sc_erreg;       /* copy of last erreg */
        u_short sc_dsreg;       /* copy of last dsreg */
        short   sc_resid;       /* copy of last bc */
 #ifdef notdef
        short   sc_lastcmd;     /* last command to handle direction changes */
 #endif
        u_short sc_erreg;       /* copy of last erreg */
        u_short sc_dsreg;       /* copy of last dsreg */
        short   sc_resid;       /* copy of last bc */
 #ifdef notdef
        short   sc_lastcmd;     /* last command to handle direction changes */
 #endif
-} tm_softc[NTM];
+       u_short sc_dens;        /* prototype command with density info */
+} te_softc[NTM];
 
 /*
 
 /*
- * States for um->um_tab.b_active, the
- * per controller state flag.
+ * States for um->um_tab.b_active, the per controller state flag.
+ * This is used to sequence control in the driver.
  */
 #define        SSEEK   1               /* seeking */
 #define        SIO     2               /* doing seq i/o */
 #define        SCOM    3               /* sending control command */
 #define        SREW    4               /* sending a drive rewind */
 
  */
 #define        SSEEK   1               /* seeking */
 #define        SIO     2               /* doing seq i/o */
 #define        SCOM    3               /* sending control command */
 #define        SREW    4               /* sending a drive rewind */
 
-/* WE CURRENTLY HANDLE REWINDS PRIMITIVELY, BUSYING OUT THE CONTROLLER */
-/* DURING THE REWIND... IF WE EVER GET TWO TRANSPORTS, WE CAN DEBUG MORE */
-/* SOPHISTICATED LOGIC... THIS SIMPLE CODE AT LEAST MAY WORK. */
-
 /*
  * Determine if there is a controller for
  * a tm at address reg.  Our goal is to make the
 /*
  * Determine if there is a controller for
  * a tm at address reg.  Our goal is to make the
@@ -88,7 +117,7 @@ struct       tm_softc {
 tmprobe(reg)
        caddr_t reg;
 {
 tmprobe(reg)
        caddr_t reg;
 {
-       register int br, cvec;
+       register int br, cvec;          /* must be r11,r10; value-result */
 
 #ifdef lint
        br = 0; br = cvec; cvec = br;
 
 #ifdef lint
        br = 0; br = cvec; cvec = br;
@@ -127,41 +156,53 @@ tmslave(ui, reg)
 }
 
 /*
 }
 
 /*
- * Record attachment of the unit to the controller port.
+ * Record attachment of the unit to the controller.
  */
 /*ARGSUSED*/
 tmattach(ui)
        struct uba_device *ui;
 {
 
  */
 /*ARGSUSED*/
 tmattach(ui)
        struct uba_device *ui;
 {
 
-#ifdef notyet
-       tmip[ui->ui_ctlr][ui->ui_slave] = ui;
-#endif
+       /*
+        * Tetotm is used in TMUNIT to index the ctmbuf and rtmbuf
+        * arrays given a te unit number.
+        */
+       tetotm[ui->ui_unit] = ui->ui_mi->um_ctlr;
 }
 
 /*
  * Open the device.  Tapes are unique open
  * devices, so we refuse if it is already open.
  * We also check that a tape is available, and
 }
 
 /*
  * Open the device.  Tapes are unique open
  * devices, so we refuse if it is already open.
  * We also check that a tape is available, and
- * don't block waiting here.
+ * don't block waiting here; if you want to wait
+ * for a tape you should timeout in user code.
  */
 tmopen(dev, flag)
        dev_t dev;
        int flag;
 {
  */
 tmopen(dev, flag)
        dev_t dev;
        int flag;
 {
-       register int unit;
+       register int teunit;
        register struct uba_device *ui;
        register struct uba_device *ui;
-       register struct tm_softc *sc;
+       register struct te_softc *sc;
+       int dens;
 
 
-       unit = TMUNIT(dev);
-       if (unit>=NTE || (sc = &tm_softc[unit])->sc_openf ||
-           (ui = tmdinfo[unit]) == 0 || ui->ui_alive == 0) {
+       teunit = TEUNIT(dev);
+       if (teunit>=NTE || (sc = &te_softc[teunit])->sc_openf ||
+           (ui = tedinfo[teunit]) == 0 || ui->ui_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
        tmcommand(dev, TM_SENSE, 1);
                u.u_error = ENXIO;
                return;
        }
        tmcommand(dev, TM_SENSE, 1);
-       if ((sc->sc_erreg&(TM_SELR|TM_TUR)) != (TM_SELR|TM_TUR) ||
-           (flag&(FREAD|FWRITE)) == FWRITE && sc->sc_erreg&TM_WRL) {
+       dens = TM_IE | TM_GO | (ui->ui_slave << 8);
+       if ((minor(dev) & T_1600BPI) == 0)
+               dens |= TM_D800;
+       if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR) ||
+           (sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
+               dens != sc->sc_dens ||
+           (flag&(FREAD|FWRITE)) == FWRITE && sc->sc_erreg&TMER_WRL) {
+               /*
+                * Not online or density switch in mid-tape or write locked.
+                */
                u.u_error = EIO;
                return;
        }
                u.u_error = EIO;
                return;
        }
@@ -169,6 +210,7 @@ tmopen(dev, flag)
        sc->sc_blkno = (daddr_t)0;
        sc->sc_nxrec = INF;
        sc->sc_lastiow = 0;
        sc->sc_blkno = (daddr_t)0;
        sc->sc_nxrec = INF;
        sc->sc_lastiow = 0;
+       sc->sc_dens = dens;
 }
 
 /*
 }
 
 /*
@@ -183,7 +225,7 @@ tmclose(dev, flag)
        register dev_t dev;
        register flag;
 {
        register dev_t dev;
        register flag;
 {
-       register struct tm_softc *sc = &tm_softc[TMUNIT(dev)];
+       register struct te_softc *sc = &te_softc[TEUNIT(dev)];
 
        if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) {
                tmcommand(dev, TM_WEOF, 1);
 
        if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) {
                tmcommand(dev, TM_WEOF, 1);
@@ -191,7 +233,13 @@ tmclose(dev, flag)
                tmcommand(dev, TM_SREV, 1);
        }
        if ((minor(dev)&T_NOREWIND) == 0)
                tmcommand(dev, TM_SREV, 1);
        }
        if ((minor(dev)&T_NOREWIND) == 0)
-               tmcommand(dev, TM_REW, 1);
+               /*
+                * 0 count means don't hang waiting for rewind complete
+                * rather ctmbuf stays busy until the operation completes
+                * preventing further opens from completing by
+                * preventing a TM_SENSE from completing.
+                */
+               tmcommand(dev, TM_REW, 0);
        sc->sc_openf = 0;
 }
 
        sc->sc_openf = 0;
 }
 
@@ -208,6 +256,13 @@ tmcommand(dev, com, count)
        bp = &ctmbuf[TMUNIT(dev)];
        (void) spl5();
        while (bp->b_flags&B_BUSY) {
        bp = &ctmbuf[TMUNIT(dev)];
        (void) spl5();
        while (bp->b_flags&B_BUSY) {
+               /*
+                * This special check is because B_BUSY never
+                * gets cleared in the non-waiting rewind case.
+                */
+               if (bp->b_command == TM_REW && bp->b_repcnt == 0 &&
+                   (bp->b_flags&B_DONE))
+                       break;
                bp->b_flags |= B_WANTED;
                sleep((caddr_t)bp, PRIBIO);
        }
                bp->b_flags |= B_WANTED;
                sleep((caddr_t)bp, PRIBIO);
        }
@@ -218,6 +273,12 @@ tmcommand(dev, com, count)
        bp->b_command = com;
        bp->b_blkno = 0;
        tmstrategy(bp);
        bp->b_command = com;
        bp->b_blkno = 0;
        tmstrategy(bp);
+       /*
+        * In case of rewind from close, don't wait.
+        * This is the only case where count can be 0.
+        */
+       if (count == 0)
+               return;
        iowait(bp);
        if (bp->b_flags&B_WANTED)
                wakeup((caddr_t)bp);
        iowait(bp);
        if (bp->b_flags&B_WANTED)
                wakeup((caddr_t)bp);
@@ -225,21 +286,20 @@ tmcommand(dev, com, count)
 }
 
 /*
 }
 
 /*
- * Decipher a tape operation and do what is needed
- * to see that it happens.
+ * Queue a tape operation.
  */
 tmstrategy(bp)
        register struct buf *bp;
 {
  */
 tmstrategy(bp)
        register struct buf *bp;
 {
-       int unit = TMUNIT(bp->b_dev);
+       int teunit = TEUNIT(bp->b_dev);
        register struct uba_ctlr *um;
        register struct buf *dp;
        register struct uba_ctlr *um;
        register struct buf *dp;
-       register struct tm_softc *sc = &tm_softc[unit];
+       register struct te_softc *sc = &te_softc[teunit];
 
        /*
         * Put transfer at end of unit queue
         */
 
        /*
         * Put transfer at end of unit queue
         */
-       dp = &tmutab[unit];
+       dp = &teutab[teunit];
        bp->av_forw = NULL;
        (void) spl5();
        if (dp->b_actf == NULL) {
        bp->av_forw = NULL;
        (void) spl5();
        if (dp->b_actf == NULL) {
@@ -249,7 +309,7 @@ tmstrategy(bp)
                 * put at end of controller queue.
                 */
                dp->b_forw = NULL;
                 * put at end of controller queue.
                 */
                dp->b_forw = NULL;
-               um = tmdinfo[unit]->ui_mi;
+               um = tedinfo[teunit]->ui_mi;
                if (um->um_tab.b_actf == NULL)
                        um->um_tab.b_actf = dp;
                else
                if (um->um_tab.b_actf == NULL)
                        um->um_tab.b_actf = dp;
                else
@@ -275,9 +335,9 @@ tmstart(um)
 {
        register struct buf *bp, *dp;
        register struct device *addr = (struct device *)um->um_addr;
 {
        register struct buf *bp, *dp;
        register struct device *addr = (struct device *)um->um_addr;
-       register struct tm_softc *sc;
+       register struct te_softc *sc;
        register struct uba_device *ui;
        register struct uba_device *ui;
-       int unit, cmd;
+       int teunit, cmd;
        daddr_t blkno;
 
        /*
        daddr_t blkno;
 
        /*
@@ -290,12 +350,12 @@ loop:
                um->um_tab.b_actf = dp->b_forw;
                goto loop;
        }
                um->um_tab.b_actf = dp->b_forw;
                goto loop;
        }
-       unit = TMUNIT(bp->b_dev);
-       ui = tmdinfo[unit];
+       teunit = TEUNIT(bp->b_dev);
+       ui = tedinfo[teunit];
        /*
         * Record pre-transfer status (e.g. for TM_SENSE)
         */
        /*
         * Record pre-transfer status (e.g. for TM_SENSE)
         */
-       sc = &tm_softc[unit];
+       sc = &te_softc[teunit];
        addr = (struct device *)um->um_addr;
        addr->tmcs = (ui->ui_slave << 8);
        sc->sc_dsreg = addr->tmcs;
        addr = (struct device *)um->um_addr;
        addr->tmcs = (ui->ui_slave << 8);
        sc->sc_dsreg = addr->tmcs;
@@ -308,42 +368,17 @@ loop:
        sc->sc_lastiow = 1;
        if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) {
                /*
        sc->sc_lastiow = 1;
        if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) {
                /*
-                * Have had a hard error on this (non-raw) tape,
-                * or the tape unit is now unavailable (e.g. taken off
-                * line).
+                * Have had a hard error on a non-raw tape
+                * or the tape unit is now unavailable
+                * (e.g. taken off line).
                 */
                bp->b_flags |= B_ERROR;
                goto next;
        }
                 */
                bp->b_flags |= B_ERROR;
                goto next;
        }
-       /*
-        * If operation is not a control operation,
-        * check for boundary conditions.
-        */
-       if (bp != &ctmbuf[unit]) {
-               if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) {
-                       bp->b_flags |= B_ERROR;
-                       bp->b_error = ENXIO;            /* past EOF */
-                       goto next;
-               }
-               if (dbtofsb(bp->b_blkno) == sc->sc_nxrec &&
-                   bp->b_flags&B_READ) {
-                       bp->b_resid = bp->b_bcount;
-                       clrbuf(bp);                     /* at EOF */
-                       goto next;
-               }
-               if ((bp->b_flags&B_READ) == 0)
-                       /* write sets EOF */
-                       sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1;
-       }
-       /*
-        * Set up the command, and then if this is a mt ioctl,
-        * do the operation using, for TM_SFORW and TM_SREV, the specified
-        * operation count.
-        */
-       cmd = TM_IE | TM_GO | (ui->ui_slave << 8);
-       if ((minor(bp->b_dev) & T_1600BPI) == 0)
-               cmd |= TM_D800;
-       if (bp == &ctmbuf[unit]) {
+       if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
+               /*
+                * Execute control operation with the specified count.
+                */
                if (bp->b_command == TM_SENSE)
                        goto next;
                um->um_tab.b_active =
                if (bp->b_command == TM_SENSE)
                        goto next;
                um->um_tab.b_active =
@@ -352,6 +387,34 @@ loop:
                        addr->tmbc = bp->b_repcnt;
                goto dobpcmd;
        }
                        addr->tmbc = bp->b_repcnt;
                goto dobpcmd;
        }
+       /*
+        * The following checks handle boundary cases for operation
+        * on non-raw tapes.  On raw tapes the initialization of
+        * sc->sc_nxrec by tmphys causes them to be skipped normally
+        * (except in the case of retries).
+        */
+       if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) {
+               /*
+                * Can't read past known end-of-file.
+                */
+               bp->b_flags |= B_ERROR;
+               bp->b_error = ENXIO;
+               goto next;
+       }
+       if (dbtofsb(bp->b_blkno) == sc->sc_nxrec &&
+           bp->b_flags&B_READ) {
+               /*
+                * Reading at end of file returns 0 bytes.
+                */
+               bp->b_resid = bp->b_bcount;
+               clrbuf(bp);
+               goto next;
+       }
+       if ((bp->b_flags&B_READ) == 0)
+               /*
+                * Writing sets EOF
+                */
+               sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1;
        /*
         * If the data transfer command is in the correct place,
         * set up all the registers except the csr, and give
        /*
         * If the data transfer command is in the correct place,
         * set up all the registers except the csr, and give
@@ -362,16 +425,16 @@ loop:
                addr->tmbc = -bp->b_bcount;
                if ((bp->b_flags&B_READ) == 0) {
                        if (um->um_tab.b_errcnt)
                addr->tmbc = -bp->b_bcount;
                if ((bp->b_flags&B_READ) == 0) {
                        if (um->um_tab.b_errcnt)
-                               cmd |= TM_WIRG;
+                               cmd = TM_WIRG;
                        else
                        else
-                               cmd |= TM_WCOM;
+                               cmd = TM_WCOM;
                } else
                } else
-                       cmd |= TM_RCOM;
+                       cmd = TM_RCOM;
                um->um_tab.b_active = SIO;
                um->um_tab.b_active = SIO;
-               um->um_cmd = cmd;
+               um->um_cmd = sc->sc_dens|cmd;
 #ifdef notdef
                if (tmreverseop(sc->sc_lastcmd))
 #ifdef notdef
                if (tmreverseop(sc->sc_lastcmd))
-                       while (addr->tmer & TM_SDWN)
+                       while (addr->tmer & TMER_SDWN)
                                tmgapsdcnt++;
                sc->sc_lastcmd = TM_RCOM;               /* will serve */
 #endif
                                tmgapsdcnt++;
                sc->sc_lastcmd = TM_RCOM;               /* will serve */
 #endif
@@ -379,8 +442,9 @@ loop:
                return;
        }
        /*
                return;
        }
        /*
-        * Block tape positioned incorrectly;
-        * seek forwards or backwards to the correct spot.
+        * Tape positioned incorrectly;
+        * set to seek forwards or backwards to the correct spot.
+        * This happens for raw tapes only on error retries.
         */
        um->um_tab.b_active = SSEEK;
        if (blkno < dbtofsb(bp->b_blkno)) {
         */
        um->um_tab.b_active = SSEEK;
        if (blkno < dbtofsb(bp->b_blkno)) {
@@ -392,12 +456,20 @@ loop:
        }
 dobpcmd:
 #ifdef notdef
        }
 dobpcmd:
 #ifdef notdef
+       /*
+        * It is strictly necessary to wait for the tape
+        * to stop before changing directions, but the TC11
+        * handles this for us.
+        */
        if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command))
                while (addr->tmer & TM_SDWN)
                        tmgapsdcnt++;
        sc->sc_lastcmd = bp->b_command;
 #endif
        if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command))
                while (addr->tmer & TM_SDWN)
                        tmgapsdcnt++;
        sc->sc_lastcmd = bp->b_command;
 #endif
-       addr->tmcs = (cmd | bp->b_command);
+       /*
+        * Do the command in bp.
+        */
+       addr->tmcs = (sc->sc_dens | bp->b_command);
        return;
 
 next:
        return;
 
 next:
@@ -438,28 +510,29 @@ tmintr(tm11)
        struct buf *dp;
        register struct buf *bp;
        register struct uba_ctlr *um = tmminfo[tm11];
        struct buf *dp;
        register struct buf *bp;
        register struct uba_ctlr *um = tmminfo[tm11];
-       register struct device *addr = (struct device *)tmdinfo[tm11]->ui_addr;
-       register struct tm_softc *sc;
-       int unit;
+       register struct device *addr;
+       register struct te_softc *sc;
+       int teunit;
        register state;
 
        register state;
 
+       if ((dp = um->um_tab.b_actf) == NULL)
+               return;
+       bp = dp->b_actf;
+       teunit = TEUNIT(bp->b_dev);
+       addr = (struct device *)tedinfo[teunit]->ui_addr;
        /*
         * If last command was a rewind, and tape is still
         * rewinding, wait for the rewind complete interrupt.
         */
        if (um->um_tab.b_active == SREW) {
                um->um_tab.b_active = SCOM;
        /*
         * If last command was a rewind, and tape is still
         * rewinding, wait for the rewind complete interrupt.
         */
        if (um->um_tab.b_active == SREW) {
                um->um_tab.b_active = SCOM;
-               if (addr->tmer&TM_RWS)
+               if (addr->tmer&TMER_RWS)
                        return;
        }
        /*
         * An operation completed... record status
         */
                        return;
        }
        /*
         * An operation completed... record status
         */
-       if ((dp = um->um_tab.b_actf) == NULL)
-               return;
-       bp = dp->b_actf;
-       unit = TMUNIT(bp->b_dev);
-       sc = &tm_softc[unit];
+       sc = &te_softc[teunit];
        sc->sc_dsreg = addr->tmcs;
        sc->sc_erreg = addr->tmer;
        sc->sc_resid = addr->tmbc;
        sc->sc_dsreg = addr->tmcs;
        sc->sc_erreg = addr->tmer;
        sc->sc_resid = addr->tmbc;
@@ -471,12 +544,12 @@ tmintr(tm11)
         * Check for errors.
         */
        if (addr->tmcs&TM_ERR) {
         * Check for errors.
         */
        if (addr->tmcs&TM_ERR) {
-               while (addr->tmer & TM_SDWN)
+               while (addr->tmer & TMER_SDWN)
                        ;                       /* await settle down */
                /*
                        ;                       /* await settle down */
                /*
-                * If we hit the end of the tape update our position.
+                * If we hit the end of the tape file, update our position.
                 */
                 */
-               if (addr->tmer&TM_EOF) {
+               if (addr->tmer&TMER_EOF) {
                        tmseteof(bp);           /* set blkno and nxrec */
                        state = SCOM;           /* force completion */
                        /*
                        tmseteof(bp);           /* set blkno and nxrec */
                        state = SCOM;           /* force completion */
                        /*
@@ -487,17 +560,17 @@ tmintr(tm11)
                        goto opdone;
                }
                /*
                        goto opdone;
                }
                /*
-                * If we were reading and the only error was that the
-                * record was to long, then we don't consider this an error.
+                * If we were reading raw tape and the only error was that the
+                * record was too long, then we don't consider this an error.
                 */
                 */
-               if ((bp->b_flags&B_READ) &&
-                   (addr->tmer&(TM_HARD|TM_SOFT)) == TM_RLE)
+               if (bp == &rtmbuf[TMUNIT(bp->b_dev)] && (bp->b_flags&B_READ) &&
+                   (addr->tmer&(TMER_HARD|TMER_SOFT)) == TMER_RLE)
                        goto ignoreerr;
                /*
                 * If error is not hard, and this was an i/o operation
                 * retry up to 8 times.
                 */
                        goto ignoreerr;
                /*
                 * If error is not hard, and this was an i/o operation
                 * retry up to 8 times.
                 */
-               if ((addr->tmer&TM_HARD)==0 && state==SIO) {
+               if ((addr->tmer&TMER_HARD)==0 && state==SIO) {
                        if (++um->um_tab.b_errcnt < 7) {
                                sc->sc_blkno++;
                                ubadone(um);
                        if (++um->um_tab.b_errcnt < 7) {
                                sc->sc_blkno++;
                                ubadone(um);
@@ -508,13 +581,13 @@ tmintr(tm11)
                         * Hard or non-i/o errors on non-raw tape
                         * cause it to close.
                         */
                         * Hard or non-i/o errors on non-raw tape
                         * cause it to close.
                         */
-                       if (sc->sc_openf>0 && bp != &rtmbuf[unit])
+                       if (sc->sc_openf>0 && bp != &rtmbuf[TMUNIT(bp->b_dev)])
                                sc->sc_openf = -1;
                /*
                 * Couldn't recover error
                 */
                printf("te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03,
                                sc->sc_openf = -1;
                /*
                 * Couldn't recover error
                 */
                printf("te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03,
-                   bp->b_blkno, sc->sc_erreg, TMEREG_BITS);
+                   bp->b_blkno, sc->sc_erreg, TMER_BITS);
                bp->b_flags |= B_ERROR;
                goto opdone;
        }
                bp->b_flags |= B_ERROR;
                goto opdone;
        }
@@ -533,31 +606,20 @@ ignoreerr:
 
        case SCOM:
                /*
 
        case SCOM:
                /*
-                * Unless special operation, op completed.
-                */
-               if (bp != &ctmbuf[unit])
-                       goto opdone;
-               /*
-                * Operation on block device...
-                * iterate operations which don't repeat
-                * for themselves in the hardware; for forward/
-                * backward space record update the current position.
+                * For forward/backward space record update current position.
                 */
                 */
+               if (bp == &ctmbuf[TMUNIT(bp->b_dev)])
                switch (bp->b_command) {
 
                case TM_SFORW:
                        sc->sc_blkno -= bp->b_repcnt;
                switch (bp->b_command) {
 
                case TM_SFORW:
                        sc->sc_blkno -= bp->b_repcnt;
-                       goto opdone;
+                       break;
 
                case TM_SREV:
                        sc->sc_blkno += bp->b_repcnt;
 
                case TM_SREV:
                        sc->sc_blkno += bp->b_repcnt;
-                       goto opdone;
-
-               default:
-                       if (++bp->b_repcnt < 0)
-                               goto opcont;
-                       goto opdone;
+                       break;
                }
                }
+               goto opdone;
 
        case SSEEK:
                sc->sc_blkno = dbtofsb(bp->b_blkno);
 
        case SSEEK:
                sc->sc_blkno = dbtofsb(bp->b_blkno);
@@ -598,12 +660,12 @@ opcont:
 tmseteof(bp)
        register struct buf *bp;
 {
 tmseteof(bp)
        register struct buf *bp;
 {
-       register int unit = TMUNIT(bp->b_dev);
+       register int teunit = TEUNIT(bp->b_dev);
        register struct device *addr = 
        register struct device *addr = 
-           (struct device *)tmdinfo[unit]->ui_addr;
-       register struct tm_softc *sc = &tm_softc[unit];
+           (struct device *)tedinfo[teunit]->ui_addr;
+       register struct te_softc *sc = &te_softc[teunit];
 
 
-       if (bp == &ctmbuf[unit]) {
+       if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
                if (sc->sc_blkno > dbtofsb(bp->b_blkno)) {
                        /* reversing */
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) - addr->tmbc;
                if (sc->sc_blkno > dbtofsb(bp->b_blkno)) {
                        /* reversing */
                        sc->sc_nxrec = dbtofsb(bp->b_blkno) - addr->tmbc;
@@ -639,18 +701,24 @@ tmwrite(dev)
        physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_WRITE, minphys);
 }
 
        physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_WRITE, minphys);
 }
 
+/*
+ * Check that a raw device exists.
+ * If it does, set up sc_blkno and sc_nxrec
+ * so that the tape will appear positioned correctly.
+ */
 tmphys(dev)
        dev_t dev;
 {
 tmphys(dev)
        dev_t dev;
 {
-       register int unit = TMUNIT(dev);
+       register int teunit = TEUNIT(dev);
        register daddr_t a;
        register daddr_t a;
-       register struct tm_softc *sc;
+       register struct te_softc *sc;
+       register struct uba_device *ui;
 
 
-       if (unit >= NTM) {
+       if (teunit >= NTE || (ui=tedinfo[teunit]) == 0 || ui->ui_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
                u.u_error = ENXIO;
                return;
        }
-       sc = &tm_softc[TMUNIT(dev)];
+       sc = &te_softc[teunit];
        a = dbtofsb(u.u_offset >> 9);
        sc->sc_blkno = a;
        sc->sc_nxrec = a + 1;
        a = dbtofsb(u.u_offset >> 9);
        sc->sc_blkno = a;
        sc->sc_nxrec = a + 1;
@@ -660,7 +728,7 @@ tmreset(uban)
        int uban;
 {
        register struct uba_ctlr *um;
        int uban;
 {
        register struct uba_ctlr *um;
-       register tm11, unit;
+       register tm11, teunit;
        register struct uba_device *ui;
        register struct buf *dp;
 
        register struct uba_device *ui;
        register struct buf *dp;
 
@@ -676,12 +744,11 @@ tmreset(uban)
                        ubadone(um);
                }
                ((struct device *)(um->um_addr))->tmcs = TM_DCLR;
                        ubadone(um);
                }
                ((struct device *)(um->um_addr))->tmcs = TM_DCLR;
-               for (unit = 0; unit < NTE; unit++) {
-                       if ((ui = tmdinfo[unit]) == 0)
-                               continue;
-                       if (ui->ui_alive == 0)
+               for (teunit = 0; teunit < NTE; teunit++) {
+                       if ((ui = tedinfo[teunit]) == 0 || ui->ui_mi != um ||
+                           ui->ui_alive == 0)
                                continue;
                                continue;
-                       dp = &tmutab[unit];
+                       dp = &teutab[teunit];
                        dp->b_active = 0;
                        dp->b_forw = 0;
                        if (um->um_tab.b_actf == NULL)
                        dp->b_active = 0;
                        dp->b_forw = 0;
                        if (um->um_tab.b_actf == NULL)
@@ -689,7 +756,7 @@ tmreset(uban)
                        else
                                um->um_tab.b_actl->b_forw = dp;
                        um->um_tab.b_actl = dp;
                        else
                                um->um_tab.b_actl->b_forw = dp;
                        um->um_tab.b_actl = dp;
-                       tm_softc[unit].sc_openf = -1;
+                       te_softc[teunit].sc_openf = -1;
                }
                tmstart(um);
        }
                }
                tmstart(um);
        }
@@ -700,9 +767,9 @@ tmioctl(dev, cmd, addr, flag)
        caddr_t addr;
        dev_t dev;
 {
        caddr_t addr;
        dev_t dev;
 {
-       int unit = TMUNIT(dev);
-       register struct tm_softc *sc = &tm_softc[unit];
-       register struct buf *bp = &ctmbuf[unit];
+       int teunit = TEUNIT(dev);
+       register struct te_softc *sc = &te_softc[teunit];
+       register struct buf *bp = &ctmbuf[TMUNIT(dev)];
        register callcount;
        int fcount;
        struct mtop mtop;
        register callcount;
        int fcount;
        struct mtop mtop;
@@ -749,7 +816,7 @@ tmioctl(dev, cmd, addr, flag)
                                u.u_error = EIO;
                                break;
                        }
                                u.u_error = EIO;
                                break;
                        }
-                       if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TM_BOT)
+                       if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TMER_BOT)
                                break;
                }
                geterror(bp);
                                break;
                }
                geterror(bp);
@@ -779,9 +846,9 @@ tmdump()
        start = 0;
        num = maxfree;
 #define        phys(a,b)       ((b)((int)(a)&0x7fffffff))
        start = 0;
        num = maxfree;
 #define        phys(a,b)       ((b)((int)(a)&0x7fffffff))
-       if (tmdinfo[0] == 0)
+       if (tedinfo[0] == 0)
                return (ENXIO);
                return (ENXIO);
-       ui = phys(tmdinfo[0], struct uba_device *);
+       ui = phys(tedinfo[0], struct uba_device *);
        up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba;
 #if VAX780
        if (cpu == VAX_780)
        up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba;
 #if VAX780
        if (cpu == VAX_780)
index c6adb1b..f094dc5 100644 (file)
@@ -1,7 +1,22 @@
-/*     autoconf.c      4.23    81/03/07        */
+/*     autoconf.c      4.24    81/03/08        */
 
 /*
 
 /*
- * Initialize the devices for the current machine.
+ * Setup the system to run on the current machine.
+ *
+ * Configure() is called at boot time and initializes the uba and mba
+ * device tables and the memory controller monitoring.  Available
+ * devices are determined (from possibilities mentioned in ioconf.c),
+ * and the drivers are initialized.
+ *
+ * N.B.: A lot of the conditionals based on processor type say
+ *     #if VAX780
+ * and
+ *     #if VAX750
+ * which may be incorrect after more processors are introduced if they
+ * are like either of these machines.  Thus the exact form of these
+ * lines may change.  Will future machines have configuration registers
+ * in the adapters and probable nexus space (like the 780), or wired
+ * addresses (like the 750)?  It remains to be seen.
  */
 
 #include "mba.h"
  */
 
 #include "mba.h"
 #include "../h/scb.h"
 #include "../h/mem.h"
 
 #include "../h/scb.h"
 #include "../h/mem.h"
 
-int    cold;
+/*
+ * The following several variables are related to
+ * the configuration process, and are used in initializing
+ * the machine.
+ */
+int    cold;           /* if 1, still working on cold-start */
 int    nexnum;         /* current nexus number */
 int    nexnum;         /* current nexus number */
-int    dkn;            /* number of dk numbers assigned so far */
+int    dkn;            /* number of iostat dk numbers assigned so far */
 
 
+/*
+ * Addresses of the (locore) routines which bootstrap us from
+ * hardware traps to C code.  Filled into the system control block
+ * as necessary.
+ */
 #if NMBA > 0
 int    (*mbaintv[4])() =       { Xmba0int, Xmba1int, Xmba2int, Xmba3int };
 #endif
 #if VAX780
 int    (*ubaintv[4])() =       { Xua0int, Xua1int, Xua2int, Xua3int };
 #if NMBA > 0
 int    (*mbaintv[4])() =       { Xmba0int, Xmba1int, Xmba2int, Xmba3int };
 #endif
 #if VAX780
 int    (*ubaintv[4])() =       { Xua0int, Xua1int, Xua2int, Xua3int };
+/*
+ * These are the (fixed) addresses of the (last 8k bytes of) unibus memory for
+ * each of the 4 possible unibus adapters.  Note that the unibus memory
+ * addresses are actually indexed by the unibus adapter type code,
+ * and are unrelated to tr (nexus) number.
+ */
 caddr_t        umaddr780[4] = {
        (caddr_t) 0x2013e000, (caddr_t) 0x2017e000,
        (caddr_t) 0x201be000, (caddr_t) 0x201fe000
 };
 #endif
 caddr_t        umaddr780[4] = {
        (caddr_t) 0x2013e000, (caddr_t) 0x2017e000,
        (caddr_t) 0x201be000, (caddr_t) 0x201fe000
 };
 #endif
+
+/*
+ * This allocates the space for the per-uba information,
+ * such as buffered data path usage.
+ */
 struct uba_hd uba_hd[MAXNUBA];
 
 struct uba_hd uba_hd[MAXNUBA];
 
+/*
+ * The bits which decode the fault bits in the configuration register
+ * of nexus's are reusable per nexus-type, so we declare them once here
+ * to avoid replication.
+ */
 #if VAX780
 char   nexflt_bits[] = NEXFLT_BITS;
 #endif
 
 #if VAX780
 char   nexflt_bits[] = NEXFLT_BITS;
 #endif
 
+/*
+ * Per-processor type initialization routines and data.
+ * It would be nice to parameterize initialization more,
+ * but the 780 and 750 are really quite different at this
+ * level.  We await future machines before attempting 
+ * any significant parameterization.
+ */
 #if VAX780
 int    c780();
 #endif
 #if VAX780
 int    c780();
 #endif
@@ -76,16 +124,23 @@ configure()
        for (ocp = percpu; ocp < &percpu[NCPU]; ocp++)
                if (ocp->pc_cputype == cpusid.cpuany.cp_type) {
                        (*ocp->pc_config)(ocp);
        for (ocp = percpu; ocp < &percpu[NCPU]; ocp++)
                if (ocp->pc_cputype == cpusid.cpuany.cp_type) {
                        (*ocp->pc_config)(ocp);
-#if VAXANY
-                       setconf();
-#endif
+                       /*
+                        * Write protect the scb.  It is strange
+                        * that this code is here, but this is as soon
+                        * as we are done mucking with it, and the
+                        * write-enable was done in assembly language
+                        * to which we will never return.
+                        */
                        ip = (int *)Sysmap; *ip &= ~PG_PROT; *ip |= PG_KR;
                        mtpr(TBIS, Sysbase);
                        ip = (int *)Sysmap; *ip &= ~PG_PROT; *ip |= PG_KR;
                        mtpr(TBIS, Sysbase);
+#if GENERIC
+                       setconf();
+#endif
                        cold = 0;
                        memenable();
                        return;
                }
                        cold = 0;
                        memenable();
                        return;
                }
-       printf("cpu type %d unsupported\n", cpusid.cpuany.cp_type);
+       printf("cpu type %d not configured\n", cpusid.cpuany.cp_type);
        asm("halt");
 }
 
        asm("halt");
 }
 
@@ -114,29 +169,26 @@ c780(pcpu)
                switch (nexcsr.nex_type) {
 
                case NEX_MBA:
                switch (nexcsr.nex_type) {
 
                case NEX_MBA:
-#if NMBA > 0
                        printf("mba%d at tr%d\n", nummba, nexnum);
                        if (nummba >= NMBA) {
                        printf("mba%d at tr%d\n", nummba, nexnum);
                        if (nummba >= NMBA) {
-                               printf("%d mba's not configured\n", nummba+1);
-                               continue;
+                               printf("%d mba's", nummba);
+                               goto notconfig;
                        }
                        }
+#if NMBA > 0
                        mbafind(nxv, nxp);
                        nummba++;
                        mbafind(nxv, nxp);
                        nummba++;
-                       break;
-#else
-                       printf("mba's");
-                       goto unsupp;
 #endif
 #endif
+                       break;
 
                case NEX_UBA0:
                case NEX_UBA1:
                case NEX_UBA2:
                case NEX_UBA3:
 
                case NEX_UBA0:
                case NEX_UBA1:
                case NEX_UBA2:
                case NEX_UBA3:
+                       printf("uba%d at tr%d\n", numuba, nexnum);
                        if (numuba >= 4) {
                                printf("5 uba's");
                                goto unsupp;
                        }
                        if (numuba >= 4) {
                                printf("5 uba's");
                                goto unsupp;
                        }
-                       printf("uba%d at tr%d\n", numuba, nexnum);
                        setscbnex(nexnum, ubaintv[numuba]);
                        i = nexcsr.nex_type - NEX_UBA0;
                        unifind((struct uba_regs *)nxv, (struct uba_regs *)nxp,
                        setscbnex(nexnum, ubaintv[numuba]);
                        i = nexcsr.nex_type - NEX_UBA0;
                        unifind((struct uba_regs *)nxv, (struct uba_regs *)nxp,
@@ -155,11 +207,11 @@ c780(pcpu)
                case NEX_MEM4I:
                case NEX_MEM16:
                case NEX_MEM16I:
                case NEX_MEM4I:
                case NEX_MEM16:
                case NEX_MEM16I:
+                       printf("mcr%d at tr%d\n", nmcr, nexnum);
                        if (nmcr >= 4) {
                        if (nmcr >= 4) {
-                               printf("%d mcr's", 4);
+                               printf("5 mcr's");
                                goto unsupp;
                        }
                                goto unsupp;
                        }
-                       printf("mcr%d at tr%d\n", nmcr, nexnum);
                        mcraddr[nmcr++] = (struct mcr *)nxv;
                        break;
 
                        mcraddr[nmcr++] = (struct mcr *)nxv;
                        break;
 
@@ -175,6 +227,9 @@ c780(pcpu)
 unsupp:
                        printf(" unsupported (at tr %d)\n", nexnum);
                        continue;
 unsupp:
                        printf(" unsupported (at tr %d)\n", nexnum);
                        continue;
+unconfig:
+                       printf(" not configured\n");
+                       continue;
                }
        }
        timeout(ubawatch, 0, hz);
                }
        }
        timeout(ubawatch, 0, hz);
@@ -195,23 +250,23 @@ c750(pcpu)
        printf("mcr at %x\n", MCR_750);
        nxaccess((caddr_t)MCR_750, Nexmap[nexnum]);
        mcraddr[nmcr++] = (struct mcr *)nxv;
        printf("mcr at %x\n", MCR_750);
        nxaccess((caddr_t)MCR_750, Nexmap[nexnum]);
        mcraddr[nmcr++] = (struct mcr *)nxv;
-#if NMBA > 0
        for (nexnum = 0; nexnum < NNEX750; nexnum++, nxp++, nxv++) {
                nxaccess((caddr_t)nxp, Nexmap[nexnum]);
                if (badaddr((caddr_t)nxv, 4))
                        continue;
                printf("mba%d at %x\n", nummba, nxp);
        for (nexnum = 0; nexnum < NNEX750; nexnum++, nxp++, nxv++) {
                nxaccess((caddr_t)nxp, Nexmap[nexnum]);
                if (badaddr((caddr_t)nxv, 4))
                        continue;
                printf("mba%d at %x\n", nummba, nxp);
-               if (nummba >= NMBA)
-                       printf("%d mba's not configured\n", nummba+1);
-               else {
-                       mbafind(nxv, nxp);
-                       nummba++;
+               if (nummba >= NMBA) {
+                       printf("%d mba(s) not configured\n", nummba+1);
+                       continue;
                }
                }
-       }
+#if NMBA > 0
+               mbafind(nxv, nxp);
+               nummba++;
 #endif
 #endif
+       }
        printf("uba at %x\n", nxp);
        nxaccess((caddr_t)nxp, Nexmap[nexnum++]);
        printf("uba at %x\n", nxp);
        nxaccess((caddr_t)nxp, Nexmap[nexnum++]);
-       unifind((struct uba_regs *)nxv++, (struct uba_regs *)nxp,
+       unifind((struct uba_regs *)nxv, (struct uba_regs *)nxp,
            umem[0], UMEM750);
        numuba = 1;
 }
            umem[0], UMEM750);
        numuba = 1;
 }
@@ -257,8 +312,6 @@ mbafind(nxv, nxp)
                            (ms->ms_ctlr == mi->mi_unit || ms->ms_ctlr=='?')) {
                                mbd->mbd_tc = ms->ms_slave;
                                dt = mbd->mbd_dt;
                            (ms->ms_ctlr == mi->mi_unit || ms->ms_ctlr=='?')) {
                                mbd->mbd_tc = ms->ms_slave;
                                dt = mbd->mbd_dt;
-                               ms->ms_alive = 1;
-                               ms->ms_ctlr = mi->mi_unit;
                                if (dt & MBDT_SPR) {
                                        printf("%s%d at %s%d slave %d\n",
                                            ms->ms_driver->md_sname,
                                if (dt & MBDT_SPR) {
                                        printf("%s%d at %s%d slave %d\n",
                                            ms->ms_driver->md_sname,
@@ -266,6 +319,8 @@ mbafind(nxv, nxp)
                                            mi->mi_driver->md_dname,
                                            mi->mi_unit,
                                            ms->ms_slave);
                                            mi->mi_driver->md_dname,
                                            mi->mi_unit,
                                            ms->ms_slave);
+                                       ms->ms_alive = 1;
+                                       ms->ms_ctlr = mi->mi_unit;
                                        (*ms->ms_driver->md_slave)
                                            (mi, ms);
                                }
                                        (*ms->ms_driver->md_slave)
                                            (mi, ms);
                                }