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