xref: /csrg-svn/sys/vax/stand/ht.c (revision 422)
1*422Sbill /*	ht.c	1.3	07/29/80	*/
2319Sbill 
3319Sbill /*
4319Sbill  * TJU16 tape driver
5319Sbill  */
6319Sbill 
7319Sbill #include "../h/param.h"
8319Sbill #include "../h/inode.h"
9*422Sbill #include "../h/pte.h"
10319Sbill #include "../h/mba.h"
11319Sbill #include "saio.h"
12319Sbill 
13319Sbill struct	device
14319Sbill {
15319Sbill 	int	htcs1;
16319Sbill 	int	htds;
17319Sbill 	int	hter;
18319Sbill 	int	htmr;
19319Sbill 	int	htas;
20319Sbill 	int	htfc;
21319Sbill 	int	htdt;
22319Sbill 	int	htck;
23319Sbill 	int	htsn;
24319Sbill 	int	httc;
25319Sbill };
26319Sbill 
27*422Sbill #define	HTMBA		PHYSMBA1
28*422Sbill #define	HTMBANUM	1
29319Sbill 
30319Sbill #define	GO	01
31319Sbill #define	WCOM	060
32319Sbill #define	RCOM	070
33319Sbill #define	NOP	0
34319Sbill #define	WEOF	026
35319Sbill #define	SFORW	030
36319Sbill #define	SREV	032
37319Sbill #define	ERASE	024
38319Sbill #define	REW	06
39319Sbill #define	DCLR	010
40319Sbill #define P800	01700		/* 800 + pdp11 mode */
41319Sbill #define	P1600	02300		/* 1600 + pdp11 mode */
42319Sbill #define	IENABLE	0100
43319Sbill #define	RDY	0200
44319Sbill #define	TM	04
45319Sbill #define	DRY	0200
46319Sbill #define EOT	02000
47319Sbill #define CS	02000
48319Sbill #define COR	0100000
49319Sbill #define PES	040
50319Sbill #define WRL	04000
51319Sbill #define MOL	010000
52319Sbill #define ERR	040000
53319Sbill #define FCE	01000
54319Sbill #define	TRE	040000
55319Sbill #define HARD	064023	/* UNS|OPI|NEF|FMT|RMR|ILR|ILF */
56319Sbill 
57319Sbill #define	SIO	1
58319Sbill #define	SSFOR	2
59319Sbill #define	SSREV	3
60319Sbill #define SRETRY	4
61319Sbill #define SCOM	5
62319Sbill #define SOK	6
63319Sbill 
64319Sbill htopen(io)
65319Sbill register struct iob *io;
66319Sbill {
67319Sbill 	register skip;
68319Sbill 	int i;
69319Sbill 
70*422Sbill 	if ((mbaact&(1<<HTMBANUM)) == 0)
71*422Sbill 		mbainit(HTMBANUM);
72319Sbill 	htinit();
73319Sbill 	htstrategy(io, REW);
74319Sbill 	skip = io->i_boff;
75319Sbill 	while (skip--) {
76319Sbill 		io->i_cc = -1;
77319Sbill 		while (htstrategy(io, SFORW))
78319Sbill 			;
79319Sbill 		i = 65536;
80319Sbill 		while (--i)
81319Sbill 			;
82319Sbill 		htstrategy(io, NOP);
83319Sbill 	}
84319Sbill }
85319Sbill 
86319Sbill htclose(io)
87319Sbill register struct iob *io;
88319Sbill {
89319Sbill 	htstrategy(io, REW);
90319Sbill }
91319Sbill 
92319Sbill htstrategy(io, func)
93319Sbill register struct iob *io;
94319Sbill {
95319Sbill 	register int unit, den, errcnt, ds;
96319Sbill 	short fc;
97*422Sbill 	register struct device *htp = mbadev(HTMBA,0);
98319Sbill 
99319Sbill 	unit = io->i_unit;
100319Sbill 	errcnt = 0;
101319Sbill retry:
102319Sbill 	if(unit & 1)
103319Sbill 		den = P1600;
104319Sbill 	else
105319Sbill 		den = P800;
106319Sbill 	htquiet();
107*422Sbill 	if((htp->httc&03777) != den)
108*422Sbill 		htp->httc = den;
109*422Sbill 	htp->htfc = -io->i_cc;
110319Sbill 	if (func == SREV) {
111*422Sbill 		htp->htfc = -1;
112*422Sbill 		htp->htcs1 = SREV | GO;
113319Sbill 		return(0);
114319Sbill 	}
115319Sbill 	if (func == READ || func == WRITE)
116*422Sbill 		mbastart(io, htp, func);
117319Sbill 	else
118*422Sbill 		htp->htcs1 = func | GO;
119319Sbill 	htquiet();
120*422Sbill 	ds = htp->htds & TM;
121319Sbill 	if (ds&TM) {
122319Sbill 		htinit();
123319Sbill 		return(0);
124319Sbill 	}
125319Sbill 	if (ds&ERR) {
126319Sbill 		if (errcnt == 0)
127319Sbill 			printf("tape error: ds=%x, er=%x, mbasr=%x",
128*422Sbill 			    htp->htds, htp->hter,
129*422Sbill 			    HTMBA->mba_sr);
130319Sbill 		htinit();
131319Sbill 		if (errcnt == 10) {
132319Sbill 			printf("\n");
133319Sbill 			return(-1);
134319Sbill 		}
135319Sbill 		errcnt++;
136319Sbill 		htstrategy(io, SREV);
137319Sbill 		goto retry;
138319Sbill 	}
139319Sbill 	if (errcnt)
140319Sbill 		printf(" recovered by retry\n");
141*422Sbill 	fc = htp->htfc;
142319Sbill 	return(io->i_cc+fc);
143319Sbill }
144319Sbill 
145319Sbill htinit()
146319Sbill {
147319Sbill 
148*422Sbill 	mbadev(HTMBA,0)->htcs1 = DCLR|GO;
149319Sbill }
150319Sbill 
151319Sbill htquiet()
152319Sbill {
153319Sbill 	register int s;
154*422Sbill 	register struct device *htp = mbadev(HTMBA,0);
155319Sbill 
156319Sbill 	do
157*422Sbill 		s = htp->htds;
158319Sbill 	while ((s & RDY) == 0);
159319Sbill }
160