Commit | Line | Data |
---|---|---|
b5d17f4d | 1 | /* ts.c 4.5 82/07/15 */ |
12785974 BJ |
2 | |
3 | /* | |
4 | * TS11 tape driver | |
5 | */ | |
6 | ||
7 | #include "../h/param.h" | |
8 | #include "../h/tsreg.h" | |
9 | #include "../h/inode.h" | |
10 | #include "../h/pte.h" | |
11 | #include "../h/ubareg.h" | |
b5d17f4d | 12 | #include "../h/fs.h" |
12785974 BJ |
13 | #include "saio.h" |
14 | #include "savax.h" | |
15 | ||
16 | ||
17 | u_short tsstd[] = { 0772520 }; | |
18 | ||
19 | struct iob ctsbuf; | |
20 | ||
21 | u_short ts_uba; /* Unibus address of ts structure */ | |
22 | ||
2e0ec09b | 23 | struct tsdevice *tsaddr = 0; |
12785974 BJ |
24 | |
25 | struct ts { | |
26 | struct ts_cmd ts_cmd; | |
27 | struct ts_char ts_char; | |
28 | struct ts_sts ts_sts; | |
29 | } ts; | |
30 | ||
31 | tsopen(io) | |
32 | register struct iob *io; | |
33 | { | |
34 | static struct ts *ts_ubaddr; | |
67092c84 | 35 | long i = 0; |
12785974 BJ |
36 | |
37 | if (tsaddr == 0) | |
b5d17f4d | 38 | tsaddr = (struct tsdevice *)ubamem(io->i_unit, tsstd[0]); |
67092c84 BJ |
39 | tsaddr->tssr = 0; |
40 | while ((tsaddr->tssr & TS_SSR)==0) { | |
b5d17f4d | 41 | DELAY(10); |
67092c84 BJ |
42 | if (++i > 1000000) { |
43 | printf("ts: not ready\n"); | |
44 | return; | |
12785974 BJ |
45 | } |
46 | } | |
47 | if (tsaddr->tssr&TS_OFL) { | |
48 | printf("ts: offline\n"); | |
49 | return; | |
50 | } | |
51 | if (tsaddr->tssr&TS_NBA) { | |
67092c84 BJ |
52 | int i; |
53 | ||
12785974 BJ |
54 | ctsbuf.i_ma = (caddr_t) &ts; |
55 | ctsbuf.i_cc = sizeof(ts); | |
56 | if (ts_ubaddr == 0) | |
67092c84 BJ |
57 | ts_ubaddr = (struct ts *)ubasetup(&ctsbuf, 2); |
58 | ts_uba = (u_short)((long)ts_ubaddr + (((long)ts_ubaddr>>16)&03)); | |
12785974 BJ |
59 | ts.ts_char.char_addr = (int)&ts_ubaddr->ts_sts; |
60 | ts.ts_char.char_size = sizeof(ts.ts_sts); | |
67092c84 BJ |
61 | ts.ts_char.char_mode = TS_ESS; |
62 | ts.ts_cmd.c_cmd = TS_ACK|TS_SETCHR; | |
63 | i = (int)&ts_ubaddr->ts_char; | |
64 | ts.ts_cmd.c_loba = i; | |
65 | ts.ts_cmd.c_hiba = (i>>16)&3; | |
12785974 BJ |
66 | ts.ts_cmd.c_size = sizeof(ts.ts_char); |
67 | tsaddr->tsdb = ts_uba; | |
68 | } | |
69 | tsstrategy(io, TS_REW); | |
70 | if (io->i_cc = io->i_boff) | |
71 | tsstrategy(io, TS_SFORWF); | |
72 | } | |
73 | ||
74 | tsclose(io) | |
75 | register struct iob *io; | |
76 | { | |
67092c84 | 77 | |
12785974 BJ |
78 | tsstrategy(io, TS_REW); |
79 | } | |
80 | ||
81 | tsstrategy(io, func) | |
82 | register struct iob *io; | |
83 | { | |
67092c84 | 84 | register int errcnt, info = 0; |
12785974 BJ |
85 | |
86 | errcnt = 0; | |
87 | retry: | |
88 | while ((tsaddr->tssr & TS_SSR) == 0) | |
67092c84 BJ |
89 | DELAY(100); |
90 | if (func == TS_REW || func == TS_SFORWF) | |
91 | ts.ts_cmd.c_repcnt = io->i_cc; | |
92 | else { | |
93 | info = ubasetup(io, 1); | |
94 | ts.ts_cmd.c_size = io->i_cc; | |
95 | ts.ts_cmd.c_loba = info; | |
96 | ts.ts_cmd.c_hiba = (info>>16)&3; | |
97 | } | |
12785974 BJ |
98 | if (func == READ) |
99 | func = TS_RCOM; | |
100 | else if (func == WRITE) | |
101 | func = TS_WCOM; | |
102 | ts.ts_cmd.c_cmd = TS_ACK|TS_CVC|func; | |
103 | tsaddr->tsdb = ts_uba; | |
67092c84 BJ |
104 | do |
105 | DELAY(100) | |
106 | while ((tsaddr->tssr & TS_SSR) == 0); | |
107 | if (info) | |
108 | ubafree(io, info); | |
109 | if (ts.ts_sts.s_xs0 & TS_TMK) | |
12785974 BJ |
110 | return (0); |
111 | if (tsaddr->tssr & TS_SC) { | |
b5d17f4d | 112 | printf("ts tape error: er=%b, xs0=%b\n", |
10899d3a BJ |
113 | tsaddr->tssr, TSSR_BITS, |
114 | ts.ts_sts.s_xs0, TSXS0_BITS); | |
12785974 | 115 | if (errcnt==10) { |
10899d3a | 116 | printf("ts: unrecovered error\n"); |
12785974 BJ |
117 | return (-1); |
118 | } | |
119 | errcnt++; | |
120 | if (func == TS_RCOM || func == TS_WCOM) | |
121 | func |= TS_RETRY; | |
122 | goto retry; | |
123 | } | |
124 | if (errcnt) | |
10899d3a | 125 | printf("ts: recovered by retry\n"); |
12785974 BJ |
126 | return (io->i_cc - ts.ts_sts.s_rbpcr); |
127 | } |