make bio and disk drivers not do spl0 so can call from panic without trap 2's
[unix-history] / usr / src / sys / vax / uba / tm.c
index 50d9557..0527c53 100644 (file)
@@ -1,4 +1,4 @@
-/*     tm.c    4.35    81/04/14        */
+/*     tm.c    4.44    81/11/18        */
 
 #include "te.h"
 #include "ts.h"
 
 #include "te.h"
 #include "ts.h"
@@ -135,6 +135,7 @@ tmprobe(reg)
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
+       tmintr(0);
 #endif
        ((struct device *)reg)->tmcs = TM_IE;
        /*
 #endif
        ((struct device *)reg)->tmcs = TM_IE;
        /*
@@ -222,13 +223,19 @@ get:
                goto get;
        }
        sc->sc_dens = olddens;
                goto get;
        }
        sc->sc_dens = olddens;
-       if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR) ||
-           (flag&FWRITE) && (sc->sc_erreg&TMER_WRL) ||
-           (sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
-               dens != sc->sc_dens) {
-               /*
-                * Not online or density switch in mid-tape or write locked.
-                */
+       if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR)) {
+               uprintf("te%d: not online\n", teunit);
+               u.u_error = EIO;
+               return;
+       }
+       if ((flag&FWRITE) && (sc->sc_erreg&TMER_WRL)) {
+               uprintf("te%d: no write ring\n", teunit);
+               u.u_error = EIO;
+               return;
+       }
+       if ((sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
+           dens != sc->sc_dens) {
+               uprintf("te%d: can't change density in mid-tape\n", teunit);
                u.u_error = EIO;
                return;
        }
                u.u_error = EIO;
                return;
        }
@@ -241,7 +248,7 @@ get:
        if (sc->sc_tact == 0) {
                sc->sc_timo = INF;
                sc->sc_tact = 1;
        if (sc->sc_tact == 0) {
                sc->sc_timo = INF;
                sc->sc_tact = 1;
-               timeout(tmtimer, dev, 5*hz);
+               timeout(tmtimer, (caddr_t)dev, 5*hz);
        }
        (void) spl0();
 }
        }
        (void) spl0();
 }
@@ -333,6 +340,7 @@ tmstrategy(bp)
        dp = &teutab[teunit];
        bp->av_forw = NULL;
        (void) spl5();
        dp = &teutab[teunit];
        bp->av_forw = NULL;
        (void) spl5();
+       um = tedinfo[teunit]->ui_mi;
        if (dp->b_actf == NULL) {
                dp->b_actf = bp;
                /*
        if (dp->b_actf == NULL) {
                dp->b_actf = bp;
                /*
@@ -340,7 +348,6 @@ tmstrategy(bp)
                 * put at end of controller queue.
                 */
                dp->b_forw = NULL;
                 * put at end of controller queue.
                 */
                dp->b_forw = NULL;
-               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
@@ -415,14 +422,15 @@ loop:
                /*
                 * Set next state; give 5 minutes to complete
                 * rewind, or 10 seconds per iteration (minimum 60
                /*
                 * Set next state; give 5 minutes to complete
                 * rewind, or 10 seconds per iteration (minimum 60
-                * seconds and max 5 minute) to complete other ops.
+                * seconds and max 5 minutes) to complete other ops.
                 */
                if (bp->b_command == TM_REW) {
                        um->um_tab.b_active = SREW;
                        sc->sc_timo = 5 * 60;
                } else {
                        um->um_tab.b_active = SCOM;
                 */
                if (bp->b_command == TM_REW) {
                        um->um_tab.b_active = SREW;
                        sc->sc_timo = 5 * 60;
                } else {
                        um->um_tab.b_active = SCOM;
-                       sc->sc_timo = min(max(10 * bp->b_repcnt, 60), 5 * 60);
+                       sc->sc_timo =
+                           imin(imax(10*(int)-bp->b_repcnt,60),5*60);
                }
                if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV)
                        addr->tmbc = bp->b_repcnt;
                }
                if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV)
                        addr->tmbc = bp->b_repcnt;
@@ -496,7 +504,7 @@ loop:
                bp->b_command = TM_SREV;
                addr->tmbc = dbtofsb(bp->b_blkno) - blkno;
        }
                bp->b_command = TM_SREV;
                addr->tmbc = dbtofsb(bp->b_blkno) - blkno;
        }
-       sc->sc_timo = min(max(10 * -addr->tmbc, 60), 5 * 60);
+       sc->sc_timo = imin(imax(10 * -addr->tmbc, 60), 5 * 60);
 dobpcmd:
 #ifdef notdef
        /*
 dobpcmd:
 #ifdef notdef
        /*
@@ -563,19 +571,21 @@ tmintr(tm11)
        bp = dp->b_actf;
        teunit = TEUNIT(bp->b_dev);
        addr = (struct device *)tedinfo[teunit]->ui_addr;
        bp = dp->b_actf;
        teunit = TEUNIT(bp->b_dev);
        addr = (struct device *)tedinfo[teunit]->ui_addr;
+       sc = &te_softc[teunit];
        /*
         * 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&TMER_RWS)
+               if (addr->tmer&TMER_RWS) {
+                       sc->sc_timo = 5*60;             /* 5 minutes */
                        return;
                        return;
+               }
        }
        /*
         * An operation completed... record status
         */
        }
        /*
         * An operation completed... record status
         */
-       sc = &te_softc[teunit];
        sc->sc_timo = INF;
        sc->sc_dsreg = addr->tmcs;
        sc->sc_erreg = addr->tmer;
        sc->sc_timo = INF;
        sc->sc_dsreg = addr->tmcs;
        sc->sc_erreg = addr->tmer;
@@ -705,15 +715,16 @@ tmtimer(dev)
        int dev;
 {
        register struct te_softc *sc = &te_softc[TEUNIT(dev)];
        int dev;
 {
        register struct te_softc *sc = &te_softc[TEUNIT(dev)];
+       register short x;
 
        if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) {
 
        if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) {
-               printf("te%d: lost interrupt\n");
+               printf("te%d: lost interrupt\n", TEUNIT(dev));
                sc->sc_timo = INF;
                sc->sc_timo = INF;
-               (void) spl5();
+               x = spl5();
                tmintr(TMUNIT(dev));
                tmintr(TMUNIT(dev));
-               (void) spl0();
+               (void) splx(x);
        }
        }
-       timeout(tmtimer, dev, 5*hz);
+       timeout(tmtimer, (caddr_t)dev, 5*hz);
 }
 
 tmseteof(bp)
 }
 
 tmseteof(bp)