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