xref: /csrg-svn/sys/vax/stand/tm.c (revision 11383)
1 /*	tm.c	4.10	83/03/02	*/
2 
3 /*
4  * TM11/TE??
5  */
6 #include "../machine/pte.h"
7 
8 #include "../h/param.h"
9 #include "../h/inode.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 & TM_ERR) {
77 		if (word & TMER_EOF)
78 			return (0);
79 		if (errcnt == 0)
80 			printf("te error: er=%b", word, TMER_BITS);
81 		if (errcnt == 10) {
82 			printf("\n");
83 			return (-1);
84 		}
85 		errcnt++;
86 		tmstrategy(io, TM_SREV);
87 		goto retry;
88 	}
89 	if (errcnt)
90 		printf(" recovered by retry\n");
91 	if (word & TMER_EOF)
92 		return (0);
93 	return (io->i_cc + tmaddr->tmbc);
94 }
95 
96 tmquiet(tmaddr)
97 	register struct tmdevice *tmaddr;
98 {
99 	register word;
100 	for (;;) {
101 		word = tmaddr->tmcs;
102 		if (word&TM_CUR)
103 			break;
104 	}
105 	for (;;) {
106 		word = tmaddr->tmer;
107 		if ((word&TMER_TUR) && (word&TMER_SDWN)==0)
108 			break;
109 	}
110 }
111