Commit | Line | Data |
---|---|---|
faeec66d | 1 | /* mt.c 4.4 82/12/17 */ |
8d272394 SL |
2 | |
3 | /* | |
4 | * TM78/TU78 tape driver | |
5 | */ | |
faeec66d | 6 | #include "../machine/pte.h" |
8d272394 | 7 | |
8d272394 | 8 | #include "../h/param.h" |
a031a31b | 9 | #include "../h/inode.h" |
b5d17f4d | 10 | #include "../h/fs.h" |
a031a31b SL |
11 | |
12 | #include "../vaxmba/mtreg.h" | |
13 | #include "../vaxmba/mbareg.h" | |
14 | ||
8d272394 SL |
15 | #include "saio.h" |
16 | #include "savax.h" | |
17 | ||
18 | short mttypes[] = | |
19 | { MBDT_TU78, 0 }; | |
20 | ||
21 | #define MASKREG(reg) ((reg)&0xffff) | |
22 | ||
23 | mtopen(io) | |
24 | register struct iob *io; | |
25 | { | |
26 | register int skip; | |
27 | register struct mtdevice *mtaddr = (struct mtdevice *)mbadrv(io->i_unit); | |
28 | int i; | |
29 | ||
30 | for (i = 0; mttypes[i]; i++) | |
31 | if (mttypes[i] == (mtaddr->mtdt&MBDT_TYPE)) | |
32 | goto found; | |
33 | _stop("not a tape\n"); | |
34 | found: | |
35 | mbainit(UNITTOMBA(io->i_unit)); | |
36 | mtaddr->mtid = MTID_CLR; | |
37 | DELAY(250); | |
38 | while ((mtaddr->mtid & MTID_RDY) == 0) | |
39 | ; | |
40 | mtstrategy(io, MT_REW); | |
41 | skip = io->i_boff; | |
42 | while (skip--) { | |
43 | io->i_cc = -1; | |
44 | mtstrategy(io, MT_SFORWF); | |
45 | } | |
46 | } | |
47 | ||
48 | mtclose(io) | |
49 | register struct iob *io; | |
50 | { | |
51 | ||
52 | mtstrategy(io, MT_REW); | |
53 | } | |
54 | ||
55 | mtstrategy(io, func) | |
56 | register struct iob *io; | |
57 | int func; | |
58 | { | |
59 | register int errcnt, s, ic; | |
60 | register struct mtdevice *mtaddr = | |
61 | (struct mtdevice *)mbadrv(io->i_unit); | |
62 | ||
63 | errcnt = 0; | |
64 | retry: | |
65 | if (func == READ || func == WRITE) { | |
66 | mtaddr->mtca = 1<<2; /* 1 record */ | |
67 | mtaddr->mtbc = io->i_cc; | |
68 | mtaddr->mter = 0; | |
69 | mbastart(io, func); | |
70 | do | |
71 | s = mtaddr->mter & MTER_INTCODE; | |
72 | while (s == 0); | |
73 | ic = s; | |
74 | DELAY(2000); | |
75 | } else { | |
76 | mtaddr->mtas = -1; | |
77 | mtaddr->mtncs[0] = (-io->i_cc << 8)|func|MT_GO; | |
78 | rwait: | |
79 | do | |
80 | s = mtaddr->mtas&0xffff; | |
81 | while (s == 0); | |
82 | mtaddr->mtas = mtaddr->mtas; /* clear attention */ | |
83 | ic = mtaddr->mtner & MTER_INTCODE; | |
84 | } | |
85 | switch (ic) { | |
86 | case MTER_TM: | |
87 | case MTER_EOT: | |
88 | case MTER_LEOT: | |
89 | return (0); | |
90 | ||
91 | case MTER_DONE: | |
92 | break; | |
93 | ||
94 | case MTER_RWDING: | |
95 | goto rwait; | |
96 | default: | |
97 | printf("mt hard error: er=%b\n", | |
98 | MASKREG(mtaddr->mter)); | |
99 | mtaddr->mtid = MTID_CLR; | |
100 | DELAY(250); | |
101 | while ((mtaddr->mtid & MTID_RDY) == 0) | |
102 | ; | |
103 | return (-1); | |
104 | ||
105 | case MTER_RETRY: | |
106 | printf("mt error: er=%b\n", | |
107 | MASKREG(mtaddr->mter)); | |
108 | if (errcnt == 10) { | |
109 | printf("mt: unrecovered error\n"); | |
110 | return (-1); | |
111 | } | |
112 | errcnt++; | |
113 | goto retry; | |
114 | } | |
115 | if (errcnt) | |
116 | printf("mt: recovered by retry\n"); | |
117 | return (io->i_cc); /* NO PARTIAL RECORD READS!!! */ | |
118 | } |