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