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