handle var len names, sync with vax
[unix-history] / usr / src / sys / vax / stand / ht.c
index 44cfdc4..ab5e529 100644 (file)
-/*     ht.c    1.3     %G%     */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)ht.c        7.3 (Berkeley) %G%
+ */
 
 /*
 
 /*
- * TJU16 tape driver
+ * TM03/TU?? tape driver
  */
  */
+#include "../machine/pte.h"
 
 
-#include "../h/param.h"
-#include "../h/inode.h"
-#include "../h/pte.h"
-#include "../h/mba.h"
-#include "saio.h"
+#include "param.h"
+#include "inode.h"
+#include "fs.h"
 
 
-struct device
-{
-       int     htcs1;
-       int     htds;
-       int     hter;
-       int     htmr;
-       int     htas;
-       int     htfc;
-       int     htdt;
-       int     htck;
-       int     htsn;
-       int     httc;
-};
+#include "../vaxmba/htreg.h"
+#include "../vaxmba/mbareg.h"
 
 
-#define        HTMBA           PHYSMBA1
-#define        HTMBANUM        1
+#include "saio.h"
+#include "savax.h"
 
 
-#define        GO      01
-#define        WCOM    060
-#define        RCOM    070
-#define        NOP     0
-#define        WEOF    026
-#define        SFORW   030
-#define        SREV    032
-#define        ERASE   024
-#define        REW     06
-#define        DCLR    010
-#define P800   01700           /* 800 + pdp11 mode */
-#define        P1600   02300           /* 1600 + pdp11 mode */
-#define        IENABLE 0100
-#define        RDY     0200
-#define        TM      04
-#define        DRY     0200
-#define EOT    02000
-#define CS     02000
-#define COR    0100000
-#define PES    040
-#define WRL    04000
-#define MOL    010000
-#define ERR    040000
-#define FCE    01000
-#define        TRE     040000
-#define HARD   064023  /* UNS|OPI|NEF|FMT|RMR|ILR|ILF */
+short  httypes[] =
+       { MBDT_TM03, MBDT_TE16, MBDT_TU45, MBDT_TU77, 0 };
 
 
-#define        SIO     1
-#define        SSFOR   2
-#define        SSREV   3
-#define SRETRY 4
-#define SCOM   5
-#define SOK    6
+#define        MASKREG(reg)    ((reg)&0xffff)
 
 htopen(io)
 
 htopen(io)
-register struct iob *io;
+       register struct iob *io;
 {
 {
-       register skip;
-       int i;
+       register struct htdevice *htaddr;
+       register int i, skip;
 
 
-       if ((mbaact&(1<<HTMBANUM)) == 0)
-               mbainit(HTMBANUM);
-       htinit();
-       htstrategy(io, REW);
-       skip = io->i_boff;
-       while (skip--) {
+       htaddr = (struct htdevice *)mbadrv(io->i_adapt, io->i_ctlr);
+       if (mbainit(io->i_adapt) == 0)
+               return (EADAPT);
+       for (i = 0;; i++) {
+               if (!httypes[i]) {
+                       printf("ht: not a tape\n");
+                       return (ENXIO);
+               }
+               if (httypes[i] == (htaddr->htdt&MBDT_TYPE))
+                       break;
+       }
+       htaddr->htcs1 = HT_DCLR|HT_GO;
+       htstrategy(io, HT_REW);
+       for (skip = io->i_part; skip--;) {
                io->i_cc = -1;
                io->i_cc = -1;
-               while (htstrategy(io, SFORW))
-                       ;
-               i = 65536;
-               while (--i)
-                       ;
-               htstrategy(io, NOP);
+               while (htstrategy(io, HT_SFORW));
+               DELAY(65536);
+               htstrategy(io, HT_SENSE);
        }
        }
+       return (0);
 }
 
 htclose(io)
 }
 
 htclose(io)
-register struct iob *io;
+       register struct iob *io;
 {
 {
-       htstrategy(io, REW);
+       htstrategy(io, HT_REW);
 }
 
 htstrategy(io, func)
 }
 
 htstrategy(io, func)
-register struct iob *io;
+       register struct iob *io;
+       int func;
 {
 {
-       register int unit, den, errcnt, ds;
+       register struct htdevice *htaddr;
+       register int den, errcnt, ds;
+       int er;
        short fc;
        short fc;
-       register struct device *htp = mbadev(HTMBA,0);
 
 
-       unit = io->i_unit;
        errcnt = 0;
        errcnt = 0;
+       htaddr = (struct htdevice *)mbadrv(io->i_adapt, io->i_ctlr);
 retry:
 retry:
-       if(unit & 1)
-               den = P1600;
-       else
-               den = P800;
-       htquiet();
-       if((htp->httc&03777) != den)
-               htp->httc = den;
-       htp->htfc = -io->i_cc;
-       if (func == SREV) {
-               htp->htfc = -1;
-               htp->htcs1 = SREV | GO;
-               return(0);
+       den = HTTC_1600BPI | HTTC_PDP11 | io->i_unit;
+       htquiet(htaddr);
+       htaddr->htcs1 = HT_DCLR|HT_GO;
+       htaddr->httc = den;
+       htaddr->htfc = -io->i_cc;
+       if (func == HT_SREV) {
+               htaddr->htfc = -1;
+               htaddr->htcs1 = HT_SREV|HT_GO;
+               return (0);
        }
        if (func == READ || func == WRITE)
        }
        if (func == READ || func == WRITE)
-               mbastart(io, htp, func);
+               mbastart(io, io->i_ctlr, func);
        else
        else
-               htp->htcs1 = func | GO;
-       htquiet();
-       ds = htp->htds & TM;
-       if (ds&TM) {
-               htinit();
-               return(0);
+               htaddr->htcs1 = func|HT_GO;
+       htquiet(htaddr);
+       ds = htaddr->htds;
+       er = htaddr->hter;
+       if (ds & HTDS_TM) {
+               htaddr->htcs1 = HT_DCLR|HT_GO;
+               return (0);
        }
        }
-       if (ds&ERR) {
-               if (errcnt == 0)
-                       printf("tape error: ds=%x, er=%x, mbasr=%x",
-                           htp->htds, htp->hter,
-                           HTMBA->mba_sr);
-               htinit();
-               if (errcnt == 10) {
-                       printf("\n");
-                       return(-1);
+       if (ds & HTDS_ERR) {
+               htaddr->htcs1 = HT_DCLR|HT_GO;
+               if ((er & HTER_CORCRC) == 0) {
+                       printf("ht error: ds=%b, er=%b\n",
+                           MASKREG(ds), HTDS_BITS,
+                           MASKREG(er), HTER_BITS);
+                       if (errcnt++ == 10) {
+                               printf("ht: unrecovered error\n");
+                               return (-1);
+                       }
+                       htstrategy(io, HT_SREV);
+                       goto retry;
                }
                }
-               errcnt++;
-               htstrategy(io, SREV);
-               goto retry;
        }
        if (errcnt)
        }
        if (errcnt)
-               printf(" recovered by retry\n");
-       fc = htp->htfc;
-       return(io->i_cc+fc);
-}
-
-htinit()
-{
-
-       mbadev(HTMBA,0)->htcs1 = DCLR|GO;
+               printf("ht: recovered by retry\n");
+       fc = htaddr->htfc;
+       return (io->i_cc+fc);
 }
 
 }
 
-htquiet()
+static
+htquiet(htaddr)
+       register struct htdevice *htaddr;
 {
        register int s;
 {
        register int s;
-       register struct device *htp = mbadev(HTMBA,0);
 
        do
 
        do
-               s = htp->htds;
-       while ((s & RDY) == 0);
+               s = htaddr->htds;
+       while ((s & HTDS_DRY) == 0);
 }
 }