xref: /csrg-svn/sys/vax/stand/tm.c (revision 3263)
1 /*	tm.c	4.3	81/03/15	*/
2 
3 /*
4  * TM11/TE??
5  */
6 
7 #include "../h/param.h"
8 #include "../h/inode.h"
9 #include "../h/pte.h"
10 #include "../h/ubareg.h"
11 #include "saio.h"
12 #include "savax.h"
13 
14 #include "../h/tmreg.h"
15 
16 u_short	tmstd[] = { 0172520 };
17 
18 tmopen(io)
19 	register struct iob *io;
20 {
21 	register skip;
22 
23 	tmstrategy(io, TM_REW);
24 	skip = io->i_boff;
25 	while (skip--) {
26 		io->i_cc = 0;
27 		while (tmstrategy(io, TM_SFORW))
28 			;
29 	}
30 }
31 
32 tmclose(io)
33 	register struct iob *io;
34 {
35 
36 	tmstrategy(io, TM_REW);
37 }
38 
39 tmstrategy(io, func)
40 	register struct iob *io;
41 {
42 	register int com, unit, errcnt;
43 	register struct device *tmaddr =
44 	    (struct device *)ubamem(io->i_unit, tmstd[0]);
45 	int word, info;
46 
47 	unit = io->i_unit;
48 	errcnt = 0;
49 retry:
50 	tmquiet(tmaddr);
51 	com = (unit<<8);
52 	info = ubasetup(io, 1);
53 	tmaddr->tmbc = -io->i_cc;
54 	tmaddr->tmba = info;
55 	if (func == READ)
56 		tmaddr->tmcs = com | TM_RCOM | TM_GO;
57 	else if (func == WRITE)
58 		tmaddr->tmcs = com | TM_WCOM | TM_GO;
59 	else if (func == TM_SREV) {
60 		tmaddr->tmbc = -1;
61 		tmaddr->tmcs = com | TM_SREV | TM_GO;
62 		return (0);
63 	} else
64 		tmaddr->tmcs = com | func | TM_GO;
65 	for (;;) {
66 		word = tmaddr->tmcs;
67 		if (word&TM_CUR)
68 			break;
69 	}
70 		;
71 	ubafree(io, info);
72 	word = tmaddr->tmer;
73 	if (word&TMER_EOT)
74 		return(0);
75 	if (word < 0) {
76 		if (errcnt == 0)
77 			printf("te error: er=%o", tmaddr->tmer);
78 		if (errcnt==10) {
79 			printf("\n");
80 			return(-1);
81 		}
82 		errcnt++;
83 		tmstrategy(io, TM_SREV);
84 		goto retry;
85 	}
86 	if (errcnt)
87 		printf(" recovered by retry\n");
88 	return (io->i_cc+tmaddr->tmbc);
89 }
90 
91 tmquiet(tmaddr)
92 	register struct device *tmaddr;
93 {
94 	register word;
95 	for (;;) {
96 		word = tmaddr->tmcs;
97 		if (word&TM_CUR)
98 			break;
99 	}
100 	for (;;) {
101 		word = tmaddr->tmer;
102 		if ((word&TMER_TUR) && (word&TMER_SDWN)==0)
103 			break;
104 	}
105 }
106