| @@ -1,1081 +1,1078 @@ | | | @@ -1,1081 +1,1078 @@ |
1 | /* $NetBSD: ts.c,v 1.34 2022/01/01 10:32:29 msaitoh Exp $ */ | | 1 | /* $NetBSD: ts.c,v 1.35 2022/02/12 02:40:20 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1991 The Regents of the University of California. | | 4 | * Copyright (c) 1991 The Regents of the University of California. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * 3. Neither the name of the University nor the names of its contributors | | 15 | * 3. Neither the name of the University nor the names of its contributors |
16 | * may be used to endorse or promote products derived from this software | | 16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. | | 17 | * without specific prior written permission. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | * | | 30 | * |
31 | * @(#)tmscp.c 7.16 (Berkeley) 5/9/91 | | 31 | * @(#)tmscp.c 7.16 (Berkeley) 5/9/91 |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | /* | | 34 | /* |
35 | * sccsid = "@(#)tmscp.c 1.24 (ULTRIX) 1/21/86"; | | 35 | * sccsid = "@(#)tmscp.c 1.24 (ULTRIX) 1/21/86"; |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | /************************************************************************ | | 38 | /************************************************************************ |
39 | * * | | 39 | * * |
40 | * Licensed from Digital Equipment Corporation * | | 40 | * Licensed from Digital Equipment Corporation * |
41 | * Copyright (c) * | | 41 | * Copyright (c) * |
42 | * Digital Equipment Corporation * | | 42 | * Digital Equipment Corporation * |
43 | * Maynard, Massachusetts * | | 43 | * Maynard, Massachusetts * |
44 | * 1985, 1986 * | | 44 | * 1985, 1986 * |
45 | * All rights reserved. * | | 45 | * All rights reserved. * |
46 | * * | | 46 | * * |
47 | * The Information in this software is subject to change * | | 47 | * The Information in this software is subject to change * |
48 | * without notice and should not be construed as a commitment * | | 48 | * without notice and should not be construed as a commitment * |
49 | * by Digital Equipment Corporation. Digital makes no * | | 49 | * by Digital Equipment Corporation. Digital makes no * |
50 | * representations about the suitability of this software for * | | 50 | * representations about the suitability of this software for * |
51 | * any purpose. It is supplied "As Is" without expressed or * | | 51 | * any purpose. It is supplied "As Is" without expressed or * |
52 | * implied warranty. * | | 52 | * implied warranty. * |
53 | * * | | 53 | * * |
54 | * If the Regents of the University of California or its * | | 54 | * If the Regents of the University of California or its * |
55 | * licensees modify the software in a manner creating * | | 55 | * licensees modify the software in a manner creating * |
56 | * derivative copyright rights, appropriate copyright * | | 56 | * derivative copyright rights, appropriate copyright * |
57 | * legends may be placed on the derivative work in addition * | | 57 | * legends may be placed on the derivative work in addition * |
58 | * to that set forth above. * | | 58 | * to that set forth above. * |
59 | * * | | 59 | * * |
60 | ************************************************************************/ | | 60 | ************************************************************************/ |
61 | | | 61 | |
62 | /* | | 62 | /* |
63 | * TSV05/TS05 device driver, written by Bertram Barth. | | 63 | * TSV05/TS05 device driver, written by Bertram Barth. |
64 | * | | 64 | * |
65 | * should be TS11 compatible (untested) | | 65 | * should be TS11 compatible (untested) |
66 | */ | | 66 | */ |
67 | | | 67 | |
68 | #include <sys/cdefs.h> | | 68 | #include <sys/cdefs.h> |
69 | __KERNEL_RCSID(0, "$NetBSD: ts.c,v 1.34 2022/01/01 10:32:29 msaitoh Exp $"); | | 69 | __KERNEL_RCSID(0, "$NetBSD: ts.c,v 1.35 2022/02/12 02:40:20 riastradh Exp $"); |
70 | | | 70 | |
71 | #undef TSDEBUG | | 71 | #undef TSDEBUG |
72 | | | 72 | |
73 | /* | | 73 | /* |
74 | * TODO: | | 74 | * TODO: |
75 | * | | 75 | * |
76 | * Keep track of tape position so that lseek et al works. | | 76 | * Keep track of tape position so that lseek et al works. |
77 | * Use tprintf to inform the user, not the system console. | | 77 | * Use tprintf to inform the user, not the system console. |
78 | */ | | 78 | */ |
79 | | | 79 | |
80 | | | 80 | |
81 | #include <sys/param.h> | | 81 | #include <sys/param.h> |
82 | #include <sys/systm.h> | | 82 | #include <sys/systm.h> |
83 | #include <sys/kernel.h> | | 83 | #include <sys/kernel.h> |
84 | #include <sys/buf.h> | | 84 | #include <sys/buf.h> |
85 | #include <sys/bufq.h> | | 85 | #include <sys/bufq.h> |
86 | #include <sys/conf.h> | | 86 | #include <sys/conf.h> |
87 | #include <sys/device.h> | | 87 | #include <sys/device.h> |
88 | #include <sys/errno.h> | | 88 | #include <sys/errno.h> |
89 | #include <sys/file.h> | | 89 | #include <sys/file.h> |
90 | #include <sys/syslog.h> | | 90 | #include <sys/syslog.h> |
91 | #include <sys/ioctl.h> | | 91 | #include <sys/ioctl.h> |
92 | #include <sys/mtio.h> | | 92 | #include <sys/mtio.h> |
93 | #include <sys/uio.h> | | 93 | #include <sys/uio.h> |
94 | #include <sys/proc.h> | | 94 | #include <sys/proc.h> |
95 | | | 95 | |
96 | #include <sys/bus.h> | | 96 | #include <sys/bus.h> |
97 | | | 97 | |
98 | #include <dev/qbus/ubareg.h> | | 98 | #include <dev/qbus/ubareg.h> |
99 | #include <dev/qbus/ubavar.h> | | 99 | #include <dev/qbus/ubavar.h> |
100 | | | 100 | |
101 | #include <dev/qbus/tsreg.h> | | 101 | #include <dev/qbus/tsreg.h> |
102 | | | 102 | |
103 | #include "ioconf.h" | | 103 | #include "ioconf.h" |
104 | | | 104 | |
105 | struct ts { | | 105 | struct ts { |
106 | struct cmd cmd; /* command packet */ | | 106 | struct cmd cmd; /* command packet */ |
107 | struct chr chr; /* characteristics packet */ | | 107 | struct chr chr; /* characteristics packet */ |
108 | struct status status; /* status packet */ | | 108 | struct status status; /* status packet */ |
109 | }; | | 109 | }; |
110 | | | 110 | |
111 | /* | | 111 | /* |
112 | * Software status, per controller. | | 112 | * Software status, per controller. |
113 | * also status per tape-unit, since only one unit per controller | | 113 | * also status per tape-unit, since only one unit per controller |
114 | * (thus we have no struct ts_info) | | 114 | * (thus we have no struct ts_info) |
115 | */ | | 115 | */ |
116 | struct ts_softc { | | 116 | struct ts_softc { |
117 | device_t sc_dev; /* Autoconf ... */ | | 117 | device_t sc_dev; /* Autoconf ... */ |
118 | struct uba_softc *sc_uh; /* the parent UBA */ | | 118 | struct uba_softc *sc_uh; /* the parent UBA */ |
119 | struct uba_unit sc_unit; /* Struct common for UBA to talk */ | | 119 | struct uba_unit sc_unit; /* Struct common for UBA to talk */ |
120 | struct evcnt sc_intrcnt; /* Interrupt counting */ | | 120 | struct evcnt sc_intrcnt; /* Interrupt counting */ |
121 | struct ubinfo sc_ui; /* mapping info for struct ts */ | | 121 | struct ubinfo sc_ui; /* mapping info for struct ts */ |
122 | struct uba_unit sc_uu; /* Struct for UBA to communicate */ | | 122 | struct uba_unit sc_uu; /* Struct for UBA to communicate */ |
123 | bus_space_tag_t sc_iot; | | 123 | bus_space_tag_t sc_iot; |
124 | bus_addr_t sc_ioh; | | 124 | bus_addr_t sc_ioh; |
125 | bus_dma_tag_t sc_dmat; | | 125 | bus_dma_tag_t sc_dmat; |
126 | bus_dmamap_t sc_dmam; | | 126 | bus_dmamap_t sc_dmam; |
127 | volatile struct ts *sc_vts; /* Memory address of ts struct */ | | 127 | volatile struct ts *sc_vts; /* Memory address of ts struct */ |
128 | struct ts *sc_bts; /* Unibus address of ts struct */ | | 128 | struct ts *sc_bts; /* Unibus address of ts struct */ |
129 | int sc_type; /* TS11 or TS05? */ | | 129 | int sc_type; /* TS11 or TS05? */ |
130 | short sc_waddr; /* Value to write to TSDB */ | | 130 | short sc_waddr; /* Value to write to TSDB */ |
131 | struct bufq_state *sc_bufq; /* pending I/O requests */ | | 131 | struct bufq_state *sc_bufq; /* pending I/O requests */ |
132 | | | 132 | |
133 | short sc_mapped; /* Unibus map allocated ? */ | | 133 | short sc_mapped; /* Unibus map allocated ? */ |
134 | short sc_state; /* see below: ST_xxx */ | | 134 | short sc_state; /* see below: ST_xxx */ |
135 | short sc_rtc; /* retry count for lcmd */ | | 135 | short sc_rtc; /* retry count for lcmd */ |
136 | short sc_openf; /* lock against multiple opens */ | | 136 | short sc_openf; /* lock against multiple opens */ |
137 | short sc_liowf; /* last operation was write */ | | 137 | short sc_liowf; /* last operation was write */ |
138 | struct buf ts_cbuf; /* internal cmd buffer (for ioctls) */ | | 138 | struct buf ts_cbuf; /* internal cmd buffer (for ioctls) */ |
139 | }; | | 139 | }; |
140 | | | 140 | |
141 | #define TS_WCSR(csr, val) \ | | 141 | #define TS_WCSR(csr, val) \ |
142 | bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val) | | 142 | bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val) |
143 | #define TS_RCSR(csr) \ | | 143 | #define TS_RCSR(csr) \ |
144 | bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr) | | 144 | bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr) |
145 | | | 145 | |
146 | #define LOWORD(x) ((int)(x) & 0xffff) | | 146 | #define LOWORD(x) ((int)(x) & 0xffff) |
147 | #define HIWORD(x) (((int)(x) >> 16) & 0x3f) | | 147 | #define HIWORD(x) (((int)(x) >> 16) & 0x3f) |
148 | | | 148 | |
149 | #define TYPE_TS11 0 | | 149 | #define TYPE_TS11 0 |
150 | #define TYPE_TS05 1 | | 150 | #define TYPE_TS05 1 |
151 | #define TYPE_TU80 2 | | 151 | #define TYPE_TU80 2 |
152 | | | 152 | |
153 | #define TS_INVALID 0 | | 153 | #define TS_INVALID 0 |
154 | #define TS_INIT 1 | | 154 | #define TS_INIT 1 |
155 | #define TS_RUNNING 2 | | 155 | #define TS_RUNNING 2 |
156 | #define TS_FASTREPOS 3 | | 156 | #define TS_FASTREPOS 3 |
157 | | | 157 | |
158 | static void tsintr(void *); | | 158 | static void tsintr(void *); |
159 | static void tsinit(struct ts_softc *); | | 159 | static void tsinit(struct ts_softc *); |
160 | static void tscommand(struct ts_softc *, dev_t, int, int); | | 160 | static void tscommand(struct ts_softc *, dev_t, int, int); |
161 | static int tsstart(struct ts_softc *, int); | | 161 | static int tsstart(struct ts_softc *, int); |
162 | static void tswchar(struct ts_softc *); | | 162 | static void tswchar(struct ts_softc *); |
163 | static bool tsreset(struct ts_softc *); | | 163 | static bool tsreset(struct ts_softc *); |
164 | static int tsmatch(device_t, cfdata_t, void *); | | 164 | static int tsmatch(device_t, cfdata_t, void *); |
165 | static void tsattach(device_t, device_t, void *); | | 165 | static void tsattach(device_t, device_t, void *); |
166 | static int tsready(struct uba_unit *); | | 166 | static int tsready(struct uba_unit *); |
167 | | | 167 | |
168 | CFATTACH_DECL_NEW(ts, sizeof(struct ts_softc), | | 168 | CFATTACH_DECL_NEW(ts, sizeof(struct ts_softc), |
169 | tsmatch, tsattach, NULL, NULL); | | 169 | tsmatch, tsattach, NULL, NULL); |
170 | | | 170 | |
171 | dev_type_open(tsopen); | | 171 | dev_type_open(tsopen); |
172 | dev_type_close(tsclose); | | 172 | dev_type_close(tsclose); |
173 | dev_type_read(tsread); | | 173 | dev_type_read(tsread); |
174 | dev_type_write(tswrite); | | 174 | dev_type_write(tswrite); |
175 | dev_type_ioctl(tsioctl); | | 175 | dev_type_ioctl(tsioctl); |
176 | dev_type_strategy(tsstrategy); | | 176 | dev_type_strategy(tsstrategy); |
177 | dev_type_dump(tsdump); | | 177 | dev_type_dump(tsdump); |
178 | | | 178 | |
179 | const struct bdevsw ts_bdevsw = { | | 179 | const struct bdevsw ts_bdevsw = { |
180 | .d_open = tsopen, | | 180 | .d_open = tsopen, |
181 | .d_close = tsclose, | | 181 | .d_close = tsclose, |
182 | .d_strategy = tsstrategy, | | 182 | .d_strategy = tsstrategy, |
183 | .d_ioctl = tsioctl, | | 183 | .d_ioctl = tsioctl, |
184 | .d_dump = tsdump, | | 184 | .d_dump = tsdump, |
185 | .d_psize = nosize, | | 185 | .d_psize = nosize, |
186 | .d_discard = nodiscard, | | 186 | .d_discard = nodiscard, |
187 | .d_flag = D_TAPE | | 187 | .d_flag = D_TAPE |
188 | }; | | 188 | }; |
189 | | | 189 | |
190 | const struct cdevsw ts_cdevsw = { | | 190 | const struct cdevsw ts_cdevsw = { |
191 | .d_open = tsopen, | | 191 | .d_open = tsopen, |
192 | .d_close = tsclose, | | 192 | .d_close = tsclose, |
193 | .d_read = tsread, | | 193 | .d_read = tsread, |
194 | .d_write = tswrite, | | 194 | .d_write = tswrite, |
195 | .d_ioctl = tsioctl, | | 195 | .d_ioctl = tsioctl, |
196 | .d_stop = nostop, | | 196 | .d_stop = nostop, |
197 | .d_tty = notty, | | 197 | .d_tty = notty, |
198 | .d_poll = nopoll, | | 198 | .d_poll = nopoll, |
199 | .d_mmap = nommap, | | 199 | .d_mmap = nommap, |
200 | .d_kqfilter = nokqfilter, | | 200 | .d_kqfilter = nokqfilter, |
201 | .d_discard = nodiscard, | | 201 | .d_discard = nodiscard, |
202 | .d_flag = D_TAPE | | 202 | .d_flag = D_TAPE |
203 | }; | | 203 | }; |
204 | | | 204 | |
205 | /* Bits in minor device */ | | 205 | /* Bits in minor device */ |
206 | #define TS_UNIT(dev) (minor(dev)&03) | | 206 | #define TS_UNIT(dev) (minor(dev)&03) |
207 | #define TS_HIDENSITY 010 | | 207 | #define TS_HIDENSITY 010 |
208 | | | 208 | |
209 | #define TS_PRI LOG_INFO | | 209 | #define TS_PRI LOG_INFO |
210 | | | 210 | |
211 | | | 211 | |
212 | /* | | 212 | /* |
213 | * Probe for device. If found, try to raise an interrupt. | | 213 | * Probe for device. If found, try to raise an interrupt. |
214 | */ | | 214 | */ |
215 | int | | 215 | int |
216 | tsmatch(device_t parent, cfdata_t match, void *aux) | | 216 | tsmatch(device_t parent, cfdata_t match, void *aux) |
217 | { | | 217 | { |
218 | struct device tsdev; | | | |
219 | struct ts_softc ssc; | | 218 | struct ts_softc ssc; |
220 | struct ts_softc *sc = &ssc; | | 219 | struct ts_softc *sc = &ssc; |
221 | struct uba_attach_args *ua = aux; | | 220 | struct uba_attach_args *ua = aux; |
222 | int i; | | 221 | int i; |
223 | | | 222 | |
224 | sc->sc_iot = ua->ua_iot; | | 223 | sc->sc_iot = ua->ua_iot; |
225 | sc->sc_ioh = ua->ua_ioh; | | 224 | sc->sc_ioh = ua->ua_ioh; |
226 | sc->sc_mapped = 0; | | 225 | sc->sc_mapped = 0; |
227 | sc->sc_dev = &tsdev; | | | |
228 | sc->sc_uh = device_private(parent); | | 226 | sc->sc_uh = device_private(parent); |
229 | strcpy(sc->sc_dev->dv_xname, "ts"); | | | |
230 | | | 227 | |
231 | /* Try to reset the device */ | | 228 | /* Try to reset the device */ |
232 | for (i = 0; i < 3; i++) { | | 229 | for (i = 0; i < 3; i++) { |
233 | if (tsreset(sc)) | | 230 | if (tsreset(sc)) |
234 | break; | | 231 | break; |
235 | } | | 232 | } |
236 | | | 233 | |
237 | if (i == 3) | | 234 | if (i == 3) |
238 | return 0; | | 235 | return 0; |
239 | | | 236 | |
240 | tsinit(sc); | | 237 | tsinit(sc); |
241 | tswchar(sc); /* write charact. to enable interrupts */ | | 238 | tswchar(sc); /* write charact. to enable interrupts */ |
242 | /* completion of this will raise the intr. */ | | 239 | /* completion of this will raise the intr. */ |
243 | | | 240 | |
244 | DELAY(1000000); /* Wait for interrupt */ | | 241 | DELAY(1000000); /* Wait for interrupt */ |
245 | ubmemfree(sc->sc_uh, &sc->sc_ui); | | 242 | ubmemfree(sc->sc_uh, &sc->sc_ui); |
246 | return 1; | | 243 | return 1; |
247 | } | | 244 | } |
248 | | | 245 | |
249 | /* | | 246 | /* |
250 | */ | | 247 | */ |
251 | void | | 248 | void |
252 | tsattach(device_t parent, device_t self, void *aux) | | 249 | tsattach(device_t parent, device_t self, void *aux) |
253 | { | | 250 | { |
254 | struct ts_softc *sc = device_private(self); | | 251 | struct ts_softc *sc = device_private(self); |
255 | struct uba_attach_args *ua = aux; | | 252 | struct uba_attach_args *ua = aux; |
256 | int error; | | 253 | int error; |
257 | const char *t; | | 254 | const char *t; |
258 | | | 255 | |
259 | sc->sc_dev = self; | | 256 | sc->sc_dev = self; |
260 | sc->sc_uh = device_private(parent); | | 257 | sc->sc_uh = device_private(parent); |
261 | sc->sc_iot = ua->ua_iot; | | 258 | sc->sc_iot = ua->ua_iot; |
262 | sc->sc_ioh = ua->ua_ioh; | | 259 | sc->sc_ioh = ua->ua_ioh; |
263 | sc->sc_dmat = ua->ua_dmat; | | 260 | sc->sc_dmat = ua->ua_dmat; |
264 | | | 261 | |
265 | sc->sc_uu.uu_dev = self; | | 262 | sc->sc_uu.uu_dev = self; |
266 | sc->sc_uu.uu_ready = tsready; | | 263 | sc->sc_uu.uu_ready = tsready; |
267 | | | 264 | |
268 | tsinit(sc); /* reset and map */ | | 265 | tsinit(sc); /* reset and map */ |
269 | | | 266 | |
270 | error = bus_dmamap_create(sc->sc_dmat, (64*1024), 16, (64*1024), | | 267 | error = bus_dmamap_create(sc->sc_dmat, (64*1024), 16, (64*1024), |
271 | 0, BUS_DMA_NOWAIT, &sc->sc_dmam); | | 268 | 0, BUS_DMA_NOWAIT, &sc->sc_dmam); |
272 | if (error) { | | 269 | if (error) { |
273 | aprint_error(": failed create DMA map %d\n", error); | | 270 | aprint_error(": failed create DMA map %d\n", error); |
274 | return; | | 271 | return; |
275 | } | | 272 | } |
276 | | | 273 | |
277 | bufq_alloc(&sc->sc_bufq, "fcfs", 0); | | 274 | bufq_alloc(&sc->sc_bufq, "fcfs", 0); |
278 | | | 275 | |
279 | /* | | 276 | /* |
280 | * write the characteristics (again) | | 277 | * write the characteristics (again) |
281 | */ | | 278 | */ |
282 | sc->sc_state = TS_INIT; /* tsintr() checks this ... */ | | 279 | sc->sc_state = TS_INIT; /* tsintr() checks this ... */ |
283 | tswchar(sc); | | 280 | tswchar(sc); |
284 | if (tsleep(sc, PRIBIO, "tsattach", 100)) { | | 281 | if (tsleep(sc, PRIBIO, "tsattach", 100)) { |
285 | aprint_error(": failed SET CHARACTERISTICS\n"); | | 282 | aprint_error(": failed SET CHARACTERISTICS\n"); |
286 | return; | | 283 | return; |
287 | } | | 284 | } |
288 | | | 285 | |
289 | sc->sc_state = TS_RUNNING; | | 286 | sc->sc_state = TS_RUNNING; |
290 | if (sc->sc_uh->uh_type == UBA_UBA) { | | 287 | if (sc->sc_uh->uh_type == UBA_UBA) { |
291 | if (sc->sc_vts->status.xst2 & TS_SF_TU80) { | | 288 | if (sc->sc_vts->status.xst2 & TS_SF_TU80) { |
292 | sc->sc_type = TYPE_TU80; | | 289 | sc->sc_type = TYPE_TU80; |
293 | t = "TU80"; | | 290 | t = "TU80"; |
294 | } else { | | 291 | } else { |
295 | sc->sc_type = TYPE_TS11; | | 292 | sc->sc_type = TYPE_TS11; |
296 | t = "TS11"; | | 293 | t = "TS11"; |
297 | } | | 294 | } |
298 | } else { | | 295 | } else { |
299 | sc->sc_type = TYPE_TS05; | | 296 | sc->sc_type = TYPE_TS05; |
300 | t = "TS05"; | | 297 | t = "TS05"; |
301 | } | | 298 | } |
302 | | | 299 | |
303 | aprint_normal(": %s\n", t); | | 300 | aprint_normal(": %s\n", t); |
304 | aprint_normal_dev(sc->sc_dev, | | 301 | aprint_normal_dev(sc->sc_dev, |
305 | "rev %d, extended features %s, transport %s\n", | | 302 | "rev %d, extended features %s, transport %s\n", |
306 | (sc->sc_vts->status.xst2 & TS_SF_MCRL) >> 2, | | 303 | (sc->sc_vts->status.xst2 & TS_SF_MCRL) >> 2, |
307 | (sc->sc_vts->status.xst2 & TS_SF_EFES ? "enabled" : "disabled"), | | 304 | (sc->sc_vts->status.xst2 & TS_SF_EFES ? "enabled" : "disabled"), |
308 | (TS_RCSR(TSSR) & TS_OFL ? "offline" : "online")); | | 305 | (TS_RCSR(TSSR) & TS_OFL ? "offline" : "online")); |
309 | | | 306 | |
310 | uba_intr_establish(ua->ua_icookie, ua->ua_cvec, tsintr, | | 307 | uba_intr_establish(ua->ua_icookie, ua->ua_cvec, tsintr, |
311 | sc, &sc->sc_intrcnt); | | 308 | sc, &sc->sc_intrcnt); |
312 | evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, | | 309 | evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, |
313 | device_xname(sc->sc_dev), "intr"); | | 310 | device_xname(sc->sc_dev), "intr"); |
314 | } | | 311 | } |
315 | | | 312 | |
316 | /* | | 313 | /* |
317 | * Initialize a TS device. Set up UBA mapping registers, | | 314 | * Initialize a TS device. Set up UBA mapping registers, |
318 | * initialize data structures, what else ??? | | 315 | * initialize data structures, what else ??? |
319 | */ | | 316 | */ |
320 | void | | 317 | void |
321 | tsinit(struct ts_softc *sc) | | 318 | tsinit(struct ts_softc *sc) |
322 | { | | 319 | { |
323 | if (sc->sc_mapped == 0) { | | 320 | if (sc->sc_mapped == 0) { |
324 | | | 321 | |
325 | /* | | 322 | /* |
326 | * Map the communications area and command and message | | 323 | * Map the communications area and command and message |
327 | * buffer into Unibus address space. | | 324 | * buffer into Unibus address space. |
328 | */ | | 325 | */ |
329 | sc->sc_ui.ui_size = sizeof(struct ts); | | 326 | sc->sc_ui.ui_size = sizeof(struct ts); |
330 | if (ubmemalloc(sc->sc_uh, &sc->sc_ui, UBA_CANTWAIT)) | | 327 | if (ubmemalloc(sc->sc_uh, &sc->sc_ui, UBA_CANTWAIT)) |
331 | return; | | 328 | return; |
332 | sc->sc_vts = (void *)sc->sc_ui.ui_vaddr; | | 329 | sc->sc_vts = (void *)sc->sc_ui.ui_vaddr; |
333 | sc->sc_bts = (void *)sc->sc_ui.ui_baddr; | | 330 | sc->sc_bts = (void *)sc->sc_ui.ui_baddr; |
334 | sc->sc_waddr = sc->sc_ui.ui_baddr | | | 331 | sc->sc_waddr = sc->sc_ui.ui_baddr | |
335 | ((sc->sc_ui.ui_baddr >> 16) & 3); | | 332 | ((sc->sc_ui.ui_baddr >> 16) & 3); |
336 | sc->sc_mapped = 1; | | 333 | sc->sc_mapped = 1; |
337 | } | | 334 | } |
338 | tsreset(sc); | | 335 | tsreset(sc); |
339 | } | | 336 | } |
340 | | | 337 | |
341 | /* | | 338 | /* |
342 | * Execute a (ioctl) command on the tape drive a specified number of times. | | 339 | * Execute a (ioctl) command on the tape drive a specified number of times. |
343 | * This routine sets up a buffer and calls the strategy routine which | | 340 | * This routine sets up a buffer and calls the strategy routine which |
344 | * issues the command to the controller. | | 341 | * issues the command to the controller. |
345 | */ | | 342 | */ |
346 | void | | 343 | void |
347 | tscommand(struct ts_softc *sc, dev_t dev, int cmd, int count) | | 344 | tscommand(struct ts_softc *sc, dev_t dev, int cmd, int count) |
348 | { | | 345 | { |
349 | struct buf *bp; | | 346 | struct buf *bp; |
350 | | | 347 | |
351 | #ifdef TSDEBUG | | 348 | #ifdef TSDEBUG |
352 | printf("tscommand (%x, %d)\n", cmd, count); | | 349 | printf("tscommand (%x, %d)\n", cmd, count); |
353 | #endif | | 350 | #endif |
354 | | | 351 | |
355 | bp = &sc->ts_cbuf; | | 352 | bp = &sc->ts_cbuf; |
356 | | | 353 | |
357 | mutex_enter(&bufcache_lock); | | 354 | mutex_enter(&bufcache_lock); |
358 | while (bp->b_cflags & BC_BUSY) { | | 355 | while (bp->b_cflags & BC_BUSY) { |
359 | /* | | 356 | /* |
360 | * This special check is because BC_BUSY never | | 357 | * This special check is because BC_BUSY never |
361 | * gets cleared in the non-waiting rewind case. ??? | | 358 | * gets cleared in the non-waiting rewind case. ??? |
362 | */ | | 359 | */ |
363 | if (bp->b_bcount == 0 && (bp->b_oflags & BO_DONE)) | | 360 | if (bp->b_bcount == 0 && (bp->b_oflags & BO_DONE)) |
364 | break; | | 361 | break; |
365 | if (bbusy(bp, false, 0, NULL) == 0) | | 362 | if (bbusy(bp, false, 0, NULL) == 0) |
366 | break; | | 363 | break; |
367 | /* check MOT-flag !!! */ | | 364 | /* check MOT-flag !!! */ |
368 | } | | 365 | } |
369 | bp->b_flags = B_READ; | | 366 | bp->b_flags = B_READ; |
370 | mutex_exit(&bufcache_lock); | | 367 | mutex_exit(&bufcache_lock); |
371 | | | 368 | |
372 | /* | | 369 | /* |
373 | * Load the buffer. The b_count field gets used to hold the command | | 370 | * Load the buffer. The b_count field gets used to hold the command |
374 | * count. the b_resid field gets used to hold the command mneumonic. | | 371 | * count. the b_resid field gets used to hold the command mneumonic. |
375 | * These 2 fields are "known" to be "safe" to use for this purpose. | | 372 | * These 2 fields are "known" to be "safe" to use for this purpose. |
376 | * (Most other drivers also use these fields in this way.) | | 373 | * (Most other drivers also use these fields in this way.) |
377 | */ | | 374 | */ |
378 | bp->b_dev = dev; | | 375 | bp->b_dev = dev; |
379 | bp->b_bcount = count; | | 376 | bp->b_bcount = count; |
380 | bp->b_resid = cmd; | | 377 | bp->b_resid = cmd; |
381 | bp->b_blkno = 0; | | 378 | bp->b_blkno = 0; |
382 | bp->b_oflags = 0; | | 379 | bp->b_oflags = 0; |
383 | bp->b_objlock = &buffer_lock; | | 380 | bp->b_objlock = &buffer_lock; |
384 | tsstrategy(bp); | | 381 | tsstrategy(bp); |
385 | /* | | 382 | /* |
386 | * In case of rewind from close, don't wait. | | 383 | * In case of rewind from close, don't wait. |
387 | * This is the only case where count can be 0. | | 384 | * This is the only case where count can be 0. |
388 | */ | | 385 | */ |
389 | if (count == 0) | | 386 | if (count == 0) |
390 | return; | | 387 | return; |
391 | biowait(bp); | | 388 | biowait(bp); |
392 | mutex_enter(&bufcache_lock); | | 389 | mutex_enter(&bufcache_lock); |
393 | cv_broadcast(&bp->b_busy); | | 390 | cv_broadcast(&bp->b_busy); |
394 | bp->b_cflags = 0; | | 391 | bp->b_cflags = 0; |
395 | mutex_exit(&bufcache_lock); | | 392 | mutex_exit(&bufcache_lock); |
396 | } | | 393 | } |
397 | | | 394 | |
398 | /* | | 395 | /* |
399 | * Start an I/O operation on TS05 controller | | 396 | * Start an I/O operation on TS05 controller |
400 | */ | | 397 | */ |
401 | int | | 398 | int |
402 | tsstart(struct ts_softc *sc, int isloaded) | | 399 | tsstart(struct ts_softc *sc, int isloaded) |
403 | { | | 400 | { |
404 | struct buf *bp; | | 401 | struct buf *bp; |
405 | int cmd; | | 402 | int cmd; |
406 | | | 403 | |
407 | bp = bufq_peek(sc->sc_bufq); | | 404 | bp = bufq_peek(sc->sc_bufq); |
408 | if (bp == NULL) { | | 405 | if (bp == NULL) { |
409 | return 0; | | 406 | return 0; |
410 | } | | 407 | } |
411 | #ifdef TSDEBUG | | 408 | #ifdef TSDEBUG |
412 | printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); | | 409 | printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); |
413 | #endif | | 410 | #endif |
414 | /* | | 411 | /* |
415 | * Check if command is an ioctl or not (ie. read or write). | | 412 | * Check if command is an ioctl or not (ie. read or write). |
416 | * If it's an ioctl then just set the flags for later use; | | 413 | * If it's an ioctl then just set the flags for later use; |
417 | * For other commands attempt to setup a buffer pointer. | | 414 | * For other commands attempt to setup a buffer pointer. |
418 | */ | | 415 | */ |
419 | if (bp == &sc->ts_cbuf) { | | 416 | if (bp == &sc->ts_cbuf) { |
420 | switch ((int)bp->b_resid) { | | 417 | switch ((int)bp->b_resid) { |
421 | case MTWEOF: | | 418 | case MTWEOF: |
422 | cmd = TS_CMD_WTM; | | 419 | cmd = TS_CMD_WTM; |
423 | break; | | 420 | break; |
424 | case MTFSF: | | 421 | case MTFSF: |
425 | cmd = TS_CMD_STMF; | | 422 | cmd = TS_CMD_STMF; |
426 | sc->sc_vts->cmd.cw1 = bp->b_bcount; | | 423 | sc->sc_vts->cmd.cw1 = bp->b_bcount; |
427 | break; | | 424 | break; |
428 | case MTBSF: | | 425 | case MTBSF: |
429 | cmd = TS_CMD_STMR; | | 426 | cmd = TS_CMD_STMR; |
430 | sc->sc_vts->cmd.cw1 = bp->b_bcount; | | 427 | sc->sc_vts->cmd.cw1 = bp->b_bcount; |
431 | break; | | 428 | break; |
432 | case MTFSR: | | 429 | case MTFSR: |
433 | cmd = TS_CMD_SRF; | | 430 | cmd = TS_CMD_SRF; |
434 | sc->sc_vts->cmd.cw1 = bp->b_bcount; | | 431 | sc->sc_vts->cmd.cw1 = bp->b_bcount; |
435 | break; | | 432 | break; |
436 | case MTBSR: | | 433 | case MTBSR: |
437 | cmd = TS_CMD_SRR; | | 434 | cmd = TS_CMD_SRR; |
438 | sc->sc_vts->cmd.cw1 = bp->b_bcount; | | 435 | sc->sc_vts->cmd.cw1 = bp->b_bcount; |
439 | break; | | 436 | break; |
440 | case MTREW: | | 437 | case MTREW: |
441 | cmd = TS_CMD_RWND; | | 438 | cmd = TS_CMD_RWND; |
442 | break; | | 439 | break; |
443 | case MTOFFL: | | 440 | case MTOFFL: |
444 | cmd = TS_CMD_RWUL; | | 441 | cmd = TS_CMD_RWUL; |
445 | break; | | 442 | break; |
446 | case MTNOP: | | 443 | case MTNOP: |
447 | cmd = TS_CMD_STAT; | | 444 | cmd = TS_CMD_STAT; |
448 | break; | | 445 | break; |
449 | default: | | 446 | default: |
450 | aprint_error_dev(sc->sc_dev, "bad ioctl %d\n", | | 447 | aprint_error_dev(sc->sc_dev, "bad ioctl %d\n", |
451 | (int)bp->b_resid); | | 448 | (int)bp->b_resid); |
452 | /* Need a no-op. get status */ | | 449 | /* Need a no-op. get status */ |
453 | cmd = TS_CMD_STAT; | | 450 | cmd = TS_CMD_STAT; |
454 | } /* end switch (bp->b_resid) */ | | 451 | } /* end switch (bp->b_resid) */ |
455 | } else { | | 452 | } else { |
456 | if (isloaded == 0) { | | 453 | if (isloaded == 0) { |
457 | /* | | 454 | /* |
458 | * now we try to map the buffer into uba map space (???) | | 455 | * now we try to map the buffer into uba map space (???) |
459 | */ | | 456 | */ |
460 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, | | 457 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, |
461 | bp->b_data, | | 458 | bp->b_data, |
462 | bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) { | | 459 | bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) { |
463 | uba_enqueue(&sc->sc_uu); | | 460 | uba_enqueue(&sc->sc_uu); |
464 | return 0; | | 461 | return 0; |
465 | } | | 462 | } |
466 | sc->sc_rtc = 0; | | 463 | sc->sc_rtc = 0; |
467 | } | | 464 | } |
468 | sc->sc_vts->cmd.cw1 = LOWORD(sc->sc_dmam->dm_segs[0].ds_addr); | | 465 | sc->sc_vts->cmd.cw1 = LOWORD(sc->sc_dmam->dm_segs[0].ds_addr); |
469 | sc->sc_vts->cmd.cw2 = HIWORD(sc->sc_dmam->dm_segs[0].ds_addr); | | 466 | sc->sc_vts->cmd.cw2 = HIWORD(sc->sc_dmam->dm_segs[0].ds_addr); |
470 | sc->sc_vts->cmd.cw3 = bp->b_bcount; | | 467 | sc->sc_vts->cmd.cw3 = bp->b_bcount; |
471 | bp->b_error = 0; /* Used for error count */ | | 468 | bp->b_error = 0; /* Used for error count */ |
472 | #ifdef TSDEBUG | | 469 | #ifdef TSDEBUG |
473 | printf("tsstart-1: err %d\n", bp->b_error); | | 470 | printf("tsstart-1: err %d\n", bp->b_error); |
474 | #endif | | 471 | #endif |
475 | if (bp->b_flags & B_READ) | | 472 | if (bp->b_flags & B_READ) |
476 | cmd = TS_CMD_RNF; | | 473 | cmd = TS_CMD_RNF; |
477 | else | | 474 | else |
478 | cmd = TS_CMD_WD; | | 475 | cmd = TS_CMD_WD; |
479 | } | | 476 | } |
480 | | | 477 | |
481 | /* | | 478 | /* |
482 | * Now that the command-buffer is setup, give it to the controller | | 479 | * Now that the command-buffer is setup, give it to the controller |
483 | */ | | 480 | */ |
484 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | cmd; | | 481 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | cmd; |
485 | #ifdef TSDEBUG | | 482 | #ifdef TSDEBUG |
486 | printf("tsstart: sending cmdr %x\n", sc->sc_vts->cmd.cmdr); | | 483 | printf("tsstart: sending cmdr %x\n", sc->sc_vts->cmd.cmdr); |
487 | #endif | | 484 | #endif |
488 | TS_WCSR(TSDB, sc->sc_waddr); | | 485 | TS_WCSR(TSDB, sc->sc_waddr); |
489 | return 1; | | 486 | return 1; |
490 | } | | 487 | } |
491 | | | 488 | |
492 | /* | | 489 | /* |
493 | * Called when there are free uba resources. | | 490 | * Called when there are free uba resources. |
494 | */ | | 491 | */ |
495 | int | | 492 | int |
496 | tsready(struct uba_unit *uu) | | 493 | tsready(struct uba_unit *uu) |
497 | { | | 494 | { |
498 | struct ts_softc *sc = device_private(uu->uu_dev); | | 495 | struct ts_softc *sc = device_private(uu->uu_dev); |
499 | struct buf *bp = bufq_peek(sc->sc_bufq); | | 496 | struct buf *bp = bufq_peek(sc->sc_bufq); |
500 | | | 497 | |
501 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, bp->b_data, | | 498 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam, bp->b_data, |
502 | bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) | | 499 | bp->b_bcount, bp->b_proc, BUS_DMA_NOWAIT)) |
503 | return 0; | | 500 | return 0; |
504 | | | 501 | |
505 | tsstart(sc, 1); | | 502 | tsstart(sc, 1); |
506 | return 1; | | 503 | return 1; |
507 | } | | 504 | } |
508 | | | 505 | |
509 | /* | | 506 | /* |
510 | * initialize the controller by sending WRITE CHARACTERISTICS command. | | 507 | * initialize the controller by sending WRITE CHARACTERISTICS command. |
511 | * contents of command- and message-buffer are assembled during this | | 508 | * contents of command- and message-buffer are assembled during this |
512 | * function. | | 509 | * function. |
513 | */ | | 510 | */ |
514 | void | | 511 | void |
515 | tswchar(struct ts_softc *sc) | | 512 | tswchar(struct ts_softc *sc) |
516 | { | | 513 | { |
517 | /* | | 514 | /* |
518 | * assemble and send "WRITE CHARACTERISTICS" command | | 515 | * assemble and send "WRITE CHARACTERISTICS" command |
519 | */ | | 516 | */ |
520 | | | 517 | |
521 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_WCHAR; | | 518 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_WCHAR; |
522 | sc->sc_vts->cmd.cw1 = LOWORD(&sc->sc_bts->chr); | | 519 | sc->sc_vts->cmd.cw1 = LOWORD(&sc->sc_bts->chr); |
523 | sc->sc_vts->cmd.cw2 = HIWORD(&sc->sc_bts->chr); | | 520 | sc->sc_vts->cmd.cw2 = HIWORD(&sc->sc_bts->chr); |
524 | sc->sc_vts->cmd.cw3 = 010; /* size of charact.-data */ | | 521 | sc->sc_vts->cmd.cw3 = 010; /* size of charact.-data */ |
525 | | | 522 | |
526 | sc->sc_vts->chr.sadrl = LOWORD(&sc->sc_bts->status); | | 523 | sc->sc_vts->chr.sadrl = LOWORD(&sc->sc_bts->status); |
527 | sc->sc_vts->chr.sadrh = HIWORD(&sc->sc_bts->status); | | 524 | sc->sc_vts->chr.sadrh = HIWORD(&sc->sc_bts->status); |
528 | sc->sc_vts->chr.onesix = (sc->sc_type == TYPE_TS05 ? 020 : 016); | | 525 | sc->sc_vts->chr.onesix = (sc->sc_type == TYPE_TS05 ? 020 : 016); |
529 | sc->sc_vts->chr.chrw = TS_WC_ESS; | | 526 | sc->sc_vts->chr.chrw = TS_WC_ESS; |
530 | sc->sc_vts->chr.xchrw = TS_WCX_HSP|TS_WCX_RBUF|TS_WCX_WBUF; | | 527 | sc->sc_vts->chr.xchrw = TS_WCX_HSP|TS_WCX_RBUF|TS_WCX_WBUF; |
531 | | | 528 | |
532 | TS_WCSR(TSDB, sc->sc_waddr); | | 529 | TS_WCSR(TSDB, sc->sc_waddr); |
533 | } | | 530 | } |
534 | | | 531 | |
535 | /* | | 532 | /* |
536 | * Reset the TS11. Return 1 if failed, 0 if succeeded. | | 533 | * Reset the TS11. Return 1 if failed, 0 if succeeded. |
537 | */ | | 534 | */ |
538 | bool | | 535 | bool |
539 | tsreset(struct ts_softc *sc) | | 536 | tsreset(struct ts_softc *sc) |
540 | { | | 537 | { |
541 | int timeout; | | 538 | int timeout; |
542 | | | 539 | |
543 | /* | | 540 | /* |
544 | * reset ctlr by writing into TSSR, then write characteristics | | 541 | * reset ctlr by writing into TSSR, then write characteristics |
545 | */ | | 542 | */ |
546 | timeout = 0; /* timeout in 10 seconds */ | | 543 | timeout = 0; /* timeout in 10 seconds */ |
547 | TS_WCSR(TSSR, 0); /* start initialization */ | | 544 | TS_WCSR(TSSR, 0); /* start initialization */ |
548 | while ((TS_RCSR(TSSR) & TS_SSR) == 0) { | | 545 | while ((TS_RCSR(TSSR) & TS_SSR) == 0) { |
549 | DELAY(10000); | | 546 | DELAY(10000); |
550 | if (timeout++ > 1000) | | 547 | if (timeout++ > 1000) |
551 | return false; | | 548 | return false; |
552 | } | | 549 | } |
553 | return true; | | 550 | return true; |
554 | } | | 551 | } |
555 | | | 552 | |
556 | static void | | 553 | static void |
557 | prtstat(struct ts_softc *sc, int sr) | | 554 | prtstat(struct ts_softc *sc, int sr) |
558 | { | | 555 | { |
559 | char buf[100]; | | 556 | char buf[100]; |
560 | | | 557 | |
561 | snprintb(buf, sizeof(buf), TS_TSSR_BITS, sr); | | 558 | snprintb(buf, sizeof(buf), TS_TSSR_BITS, sr); |
562 | aprint_normal_dev(sc->sc_dev, "TSSR=%s\n", buf); | | 559 | aprint_normal_dev(sc->sc_dev, "TSSR=%s\n", buf); |
563 | snprintb(buf, sizeof(buf), TS_XST0_BITS, sc->sc_vts->status.xst0); | | 560 | snprintb(buf, sizeof(buf), TS_XST0_BITS, sc->sc_vts->status.xst0); |
564 | aprint_normal_dev(sc->sc_dev, "XST0=%s\n", buf); | | 561 | aprint_normal_dev(sc->sc_dev, "XST0=%s\n", buf); |
565 | } | | 562 | } |
566 | | | 563 | |
567 | /* | | 564 | /* |
568 | * TSV05/TS05 interrupt routine | | 565 | * TSV05/TS05 interrupt routine |
569 | */ | | 566 | */ |
570 | static void | | 567 | static void |
571 | tsintr(void *arg) | | 568 | tsintr(void *arg) |
572 | { | | 569 | { |
573 | struct ts_softc *sc = arg; | | 570 | struct ts_softc *sc = arg; |
574 | struct buf *bp; | | 571 | struct buf *bp; |
575 | | | 572 | |
576 | unsigned short sr = TS_RCSR(TSSR); /* save TSSR */ | | 573 | unsigned short sr = TS_RCSR(TSSR); /* save TSSR */ |
577 | unsigned short mh = sc->sc_vts->status.hdr; /* and msg-header */ | | 574 | unsigned short mh = sc->sc_vts->status.hdr; /* and msg-header */ |
578 | /* clear the message header ??? */ | | 575 | /* clear the message header ??? */ |
579 | | | 576 | |
580 | short ccode = sc->sc_vts->cmd.cmdr & TS_CF_CCODE; | | 577 | short ccode = sc->sc_vts->cmd.cmdr & TS_CF_CCODE; |
581 | | | 578 | |
582 | bp = bufq_peek(sc->sc_bufq); | | 579 | bp = bufq_peek(sc->sc_bufq); |
583 | #ifdef TSDEBUG | | 580 | #ifdef TSDEBUG |
584 | { | | 581 | { |
585 | char buf[100]; | | 582 | char buf[100]; |
586 | snprintb(buf, sizeof(buf), TS_TSSR_BITS, sr); | | 583 | snprintb(buf, sizeof(buf), TS_TSSR_BITS, sr); |
587 | printf("tsintr: sr %x mh %x\n", sr, mh); | | 584 | printf("tsintr: sr %x mh %x\n", sr, mh); |
588 | printf("srbits: %s\n", buf); | | 585 | printf("srbits: %s\n", buf); |
589 | } | | 586 | } |
590 | #endif | | 587 | #endif |
591 | /* | | 588 | /* |
592 | * There are two different things which can (and should) be checked: | | 589 | * There are two different things which can (and should) be checked: |
593 | * the actual (internal) state and the device's result (tssr/msg.hdr) | | 590 | * the actual (internal) state and the device's result (tssr/msg.hdr) |
594 | * | | 591 | * |
595 | * For each state there's only one "normal" interrupt. Anything else | | 592 | * For each state there's only one "normal" interrupt. Anything else |
596 | * has to be checked more intensively. Thus in a first run according | | 593 | * has to be checked more intensively. Thus in a first run according |
597 | * to the internal state the expected interrupt is checked/handled. | | 594 | * to the internal state the expected interrupt is checked/handled. |
598 | * | | 595 | * |
599 | * In a second run the remaining (not yet handled) interrupts are | | 596 | * In a second run the remaining (not yet handled) interrupts are |
600 | * checked according to the drive's result. | | 597 | * checked according to the drive's result. |
601 | */ | | 598 | */ |
602 | switch (sc->sc_state) { | | 599 | switch (sc->sc_state) { |
603 | | | 600 | |
604 | case TS_INVALID: | | 601 | case TS_INVALID: |
605 | /* | | 602 | /* |
606 | * Ignore unsolicited interrupts. | | 603 | * Ignore unsolicited interrupts. |
607 | */ | | 604 | */ |
608 | log(LOG_WARNING, "%s: stray intr [%x,%x]\n", | | 605 | log(LOG_WARNING, "%s: stray intr [%x,%x]\n", |
609 | device_xname(sc->sc_dev), sr, mh); | | 606 | device_xname(sc->sc_dev), sr, mh); |
610 | return; | | 607 | return; |
611 | | | 608 | |
612 | case TS_INIT: | | 609 | case TS_INIT: |
613 | /* | | 610 | /* |
614 | * Init phase ready. | | 611 | * Init phase ready. |
615 | */ | | 612 | */ |
616 | wakeup(sc); | | 613 | wakeup(sc); |
617 | return; | | 614 | return; |
618 | | | 615 | |
619 | case TS_RUNNING: | | 616 | case TS_RUNNING: |
620 | case TS_FASTREPOS: | | 617 | case TS_FASTREPOS: |
621 | /* | | 618 | /* |
622 | * Here we expect interrupts indicating the end of | | 619 | * Here we expect interrupts indicating the end of |
623 | * commands or indicating problems. | | 620 | * commands or indicating problems. |
624 | */ | | 621 | */ |
625 | /* | | 622 | /* |
626 | * Anything else is handled outside this switch ... | | 623 | * Anything else is handled outside this switch ... |
627 | */ | | 624 | */ |
628 | break; | | 625 | break; |
629 | | | 626 | |
630 | default: | | 627 | default: |
631 | aprint_error_dev(sc->sc_dev, | | 628 | aprint_error_dev(sc->sc_dev, |
632 | "unexpected interrupt during state %d [%x,%x]\n", | | 629 | "unexpected interrupt during state %d [%x,%x]\n", |
633 | sc->sc_state, sr, mh); | | 630 | sc->sc_state, sr, mh); |
634 | return; | | 631 | return; |
635 | } | | 632 | } |
636 | | | 633 | |
637 | /* | | 634 | /* |
638 | * now we check the termination class. | | 635 | * now we check the termination class. |
639 | */ | | 636 | */ |
640 | switch (sr & TS_TC) { | | 637 | switch (sr & TS_TC) { |
641 | | | 638 | |
642 | case TS_TC_NORM: | | 639 | case TS_TC_NORM: |
643 | /* | | 640 | /* |
644 | * Normal termination -- The operation is completed | | 641 | * Normal termination -- The operation is completed |
645 | * witout incident. | | 642 | * witout incident. |
646 | */ | | 643 | */ |
647 | if (sc->sc_state == TS_FASTREPOS) { | | 644 | if (sc->sc_state == TS_FASTREPOS) { |
648 | #ifdef TSDEBUG | | 645 | #ifdef TSDEBUG |
649 | printf("Fast repos interrupt\n"); | | 646 | printf("Fast repos interrupt\n"); |
650 | #endif | | 647 | #endif |
651 | /* Fast repos succeeded, start normal data xfer */ | | 648 | /* Fast repos succeeded, start normal data xfer */ |
652 | sc->sc_state = TS_RUNNING; | | 649 | sc->sc_state = TS_RUNNING; |
653 | tsstart(sc, 1); | | 650 | tsstart(sc, 1); |
654 | return; | | 651 | return; |
655 | } | | 652 | } |
656 | sc->sc_liowf = (ccode == TS_CC_WRITE); | | 653 | sc->sc_liowf = (ccode == TS_CC_WRITE); |
657 | break; | | 654 | break; |
658 | | | 655 | |
659 | case TS_TC_ATTN: | | 656 | case TS_TC_ATTN: |
660 | /* | | 657 | /* |
661 | * Attention condition -- this code indicates that the | | 658 | * Attention condition -- this code indicates that the |
662 | * drive has undergone a status change, such as going | | 659 | * drive has undergone a status change, such as going |
663 | * off-line or coming on-line. | | 660 | * off-line or coming on-line. |
664 | * (Without EAI enabled, no Attention interrupts occur. | | 661 | * (Without EAI enabled, no Attention interrupts occur. |
665 | * drive status changes are signaled by the VCK flag.) | | 662 | * drive status changes are signaled by the VCK flag.) |
666 | */ | | 663 | */ |
667 | return; | | 664 | return; |
668 | | | 665 | |
669 | case TS_TC_TSA: | | 666 | case TS_TC_TSA: |
670 | /* | | 667 | /* |
671 | * Tape Status Alert -- A status condition is encountered | | 668 | * Tape Status Alert -- A status condition is encountered |
672 | * that may have significance to the program. Bits of | | 669 | * that may have significance to the program. Bits of |
673 | * interest in the extended status registers include | | 670 | * interest in the extended status registers include |
674 | * TMK, EOT and RLL. | | 671 | * TMK, EOT and RLL. |
675 | */ | | 672 | */ |
676 | #ifdef TSDEBUG | | 673 | #ifdef TSDEBUG |
677 | { | | 674 | { |
678 | char buf[100]; | | 675 | char buf[100]; |
679 | snprintb(buf, sizeof(buf), | | 676 | snprintb(buf, sizeof(buf), |
680 | TS_XST0_BITS, sc->sc_vts->status.xst0); | | 677 | TS_XST0_BITS, sc->sc_vts->status.xst0); |
681 | printf("TSA: sr %x bits %s\n", | | 678 | printf("TSA: sr %x bits %s\n", |
682 | sc->sc_vts->status.xst0, buf); | | 679 | sc->sc_vts->status.xst0, buf); |
683 | } | | 680 | } |
684 | #endif | | 681 | #endif |
685 | if (sc->sc_vts->status.xst0 & TS_SF_TMK) { | | 682 | if (sc->sc_vts->status.xst0 & TS_SF_TMK) { |
686 | #ifdef TSDEBUG | | 683 | #ifdef TSDEBUG |
687 | printf(("Tape Mark detected")); | | 684 | printf(("Tape Mark detected")); |
688 | #endif | | 685 | #endif |
689 | /* Read to end-of-file. No error. */ | | 686 | /* Read to end-of-file. No error. */ |
690 | break; | | 687 | break; |
691 | } | | 688 | } |
692 | if (sc->sc_vts->status.xst0 & TS_SF_EOT) { | | 689 | if (sc->sc_vts->status.xst0 & TS_SF_EOT) { |
693 | /* End of tape. Bad. */ | | 690 | /* End of tape. Bad. */ |
694 | #ifdef TSDEBUG | | 691 | #ifdef TSDEBUG |
695 | printf("TS_TC_TSA: EOT\n"); | | 692 | printf("TS_TC_TSA: EOT\n"); |
696 | #endif | | 693 | #endif |
697 | if (bp != NULL) | | 694 | if (bp != NULL) |
698 | bp->b_error = EIO; | | 695 | bp->b_error = EIO; |
699 | break; | | 696 | break; |
700 | } | | 697 | } |
701 | if (sc->sc_vts->status.xst0 & TS_SF_RLS) | | 698 | if (sc->sc_vts->status.xst0 & TS_SF_RLS) |
702 | break; | | 699 | break; |
703 | #ifndef TSDEBUG | | 700 | #ifndef TSDEBUG |
704 | { | | 701 | { |
705 | char buf[100]; | | 702 | char buf[100]; |
706 | snprintb(buf, sizeof(buf), | | 703 | snprintb(buf, sizeof(buf), |
707 | TS_XST0_BITS, sc->sc_vts->status.xst0); | | 704 | TS_XST0_BITS, sc->sc_vts->status.xst0); |
708 | printf("TSA: sr %x bits %s\n", | | 705 | printf("TSA: sr %x bits %s\n", |
709 | sc->sc_vts->status.xst0, buf); | | 706 | sc->sc_vts->status.xst0, buf); |
710 | } | | 707 | } |
711 | #endif | | 708 | #endif |
712 | break; | | 709 | break; |
713 | | | 710 | |
714 | case TS_TC_FR: | | 711 | case TS_TC_FR: |
715 | /* | | 712 | /* |
716 | * Function Reject -- The specified function was not | | 713 | * Function Reject -- The specified function was not |
717 | * initiated. Bits of interest include OFL, VCK, BOT, | | 714 | * initiated. Bits of interest include OFL, VCK, BOT, |
718 | * WLE, ILC and ILA. | | 715 | * WLE, ILC and ILA. |
719 | */ | | 716 | */ |
720 | if (sr & TS_OFL) | | 717 | if (sr & TS_OFL) |
721 | printf("tape is off-line.\n"); | | 718 | printf("tape is off-line.\n"); |
722 | #ifdef TSDEBUG | | 719 | #ifdef TSDEBUG |
723 | { | | 720 | { |
724 | char buf[100]; | | 721 | char buf[100]; |
725 | snprintb(buf, sizeof(buf), | | 722 | snprintb(buf, sizeof(buf), |
726 | TS_XST0_BITS, sc->sc_vts->status.xst0); | | 723 | TS_XST0_BITS, sc->sc_vts->status.xst0); |
727 | printf("FR: sr %x bits %s\n", | | 724 | printf("FR: sr %x bits %s\n", |
728 | sc->sc_vts->status.xst0, buf); | | 725 | sc->sc_vts->status.xst0, buf); |
729 | } | | 726 | } |
730 | #endif | | 727 | #endif |
731 | if (sc->sc_vts->status.xst0 & TS_SF_VCK) | | 728 | if (sc->sc_vts->status.xst0 & TS_SF_VCK) |
732 | printf("Volume check\n"); | | 729 | printf("Volume check\n"); |
733 | if (sc->sc_vts->status.xst0 & TS_SF_BOT) | | 730 | if (sc->sc_vts->status.xst0 & TS_SF_BOT) |
734 | printf("Start of tape.\n"); | | 731 | printf("Start of tape.\n"); |
735 | if (sc->sc_vts->status.xst0 & TS_SF_WLE) | | 732 | if (sc->sc_vts->status.xst0 & TS_SF_WLE) |
736 | printf("Write Lock Error\n"); | | 733 | printf("Write Lock Error\n"); |
737 | if (sc->sc_vts->status.xst0 & TS_SF_EOT) | | 734 | if (sc->sc_vts->status.xst0 & TS_SF_EOT) |
738 | printf("End of tape.\n"); | | 735 | printf("End of tape.\n"); |
739 | break; | | 736 | break; |
740 | | | 737 | |
741 | case TS_TC_TPD: | | 738 | case TS_TC_TPD: |
742 | /* | | 739 | /* |
743 | * Recoverable Error -- Tape position is a record beyond | | 740 | * Recoverable Error -- Tape position is a record beyond |
744 | * what its position was when the function was initiated. | | 741 | * what its position was when the function was initiated. |
745 | * Suggested recovery procedure is to log the error and | | 742 | * Suggested recovery procedure is to log the error and |
746 | * issue the appropriate retry command. | | 743 | * issue the appropriate retry command. |
747 | * | | 744 | * |
748 | * Do a fast repositioning one record back. | | 745 | * Do a fast repositioning one record back. |
749 | */ | | 746 | */ |
750 | sc->sc_state = TS_FASTREPOS; | | 747 | sc->sc_state = TS_FASTREPOS; |
751 | #ifdef TSDEBUG | | 748 | #ifdef TSDEBUG |
752 | printf("TS_TC_TPD: errcnt %d\n", sc->sc_rtc); | | 749 | printf("TS_TC_TPD: errcnt %d\n", sc->sc_rtc); |
753 | #endif | | 750 | #endif |
754 | if (sc->sc_rtc++ == 8) { | | 751 | if (sc->sc_rtc++ == 8) { |
755 | aprint_error_dev(sc->sc_dev, "failed 8 retries\n"); | | 752 | aprint_error_dev(sc->sc_dev, "failed 8 retries\n"); |
756 | prtstat(sc, sr); | | 753 | prtstat(sc, sr); |
757 | if (bp != NULL) | | 754 | if (bp != NULL) |
758 | bp->b_error = EIO; | | 755 | bp->b_error = EIO; |
759 | break; | | 756 | break; |
760 | } | | 757 | } |
761 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_SRR; | | 758 | sc->sc_vts->cmd.cmdr = TS_CF_ACK | TS_CF_IE | TS_CMD_SRR; |
762 | sc->sc_vts->cmd.cw1 = 1; | | 759 | sc->sc_vts->cmd.cw1 = 1; |
763 | TS_WCSR(TSDB, sc->sc_waddr); | | 760 | TS_WCSR(TSDB, sc->sc_waddr); |
764 | return; | | 761 | return; |
765 | | | 762 | |
766 | case TS_TC_TNM: | | 763 | case TS_TC_TNM: |
767 | /* | | 764 | /* |
768 | * Recoverable Error -- Tape position has not changed. | | 765 | * Recoverable Error -- Tape position has not changed. |
769 | * Suggested recovery procedure is to log the error and | | 766 | * Suggested recovery procedure is to log the error and |
770 | * reissue the original command. | | 767 | * reissue the original command. |
771 | */ | | 768 | */ |
772 | if (sc->sc_rtc++ == 8) { | | 769 | if (sc->sc_rtc++ == 8) { |
773 | aprint_error_dev(sc->sc_dev, "failed 8 retries\n"); | | 770 | aprint_error_dev(sc->sc_dev, "failed 8 retries\n"); |
774 | prtstat(sc, sr); | | 771 | prtstat(sc, sr); |
775 | if (bp != NULL) | | 772 | if (bp != NULL) |
776 | bp->b_error = EIO; | | 773 | bp->b_error = EIO; |
777 | break; | | 774 | break; |
778 | } | | 775 | } |
779 | tsstart(sc, 1); | | 776 | tsstart(sc, 1); |
780 | return; | | 777 | return; |
781 | | | 778 | |
782 | case TS_TC_TPL: | | 779 | case TS_TC_TPL: |
783 | /* | | 780 | /* |
784 | * Unrecoverable Error -- Tape position has been lost. | | 781 | * Unrecoverable Error -- Tape position has been lost. |
785 | * No valid recovery procedures exist unless the tape | | 782 | * No valid recovery procedures exist unless the tape |
786 | * has labels or sequence numbers. | | 783 | * has labels or sequence numbers. |
787 | */ | | 784 | */ |
788 | aprint_error_dev(sc->sc_dev, "tape position lost\n"); | | 785 | aprint_error_dev(sc->sc_dev, "tape position lost\n"); |
789 | if (bp != NULL) | | 786 | if (bp != NULL) |
790 | bp->b_error = EIO; | | 787 | bp->b_error = EIO; |
791 | break; | | 788 | break; |
792 | | | 789 | |
793 | case TS_TC_FCE: | | 790 | case TS_TC_FCE: |
794 | /* | | 791 | /* |
795 | * Fatal subsystem Error -- The subsystem is incapable | | 792 | * Fatal subsystem Error -- The subsystem is incapable |
796 | * of properly performing commands, or at least its | | 793 | * of properly performing commands, or at least its |
797 | * integrity is seriously questionable. Refer to the | | 794 | * integrity is seriously questionable. Refer to the |
798 | * fatal class code field in the TSSR register for | | 795 | * fatal class code field in the TSSR register for |
799 | * additional information on the type of fatal error. | | 796 | * additional information on the type of fatal error. |
800 | */ | | 797 | */ |
801 | aprint_error_dev(sc->sc_dev, "fatal controller error\n"); | | 798 | aprint_error_dev(sc->sc_dev, "fatal controller error\n"); |
802 | prtstat(sc, sr); | | 799 | prtstat(sc, sr); |
803 | break; | | 800 | break; |
804 | | | 801 | |
805 | default: | | 802 | default: |
806 | aprint_error_dev(sc->sc_dev, | | 803 | aprint_error_dev(sc->sc_dev, |
807 | "error 0x%x, resetting controller\n", sr & TS_TC); | | 804 | "error 0x%x, resetting controller\n", sr & TS_TC); |
808 | tsreset(sc); | | 805 | tsreset(sc); |
809 | } | | 806 | } |
810 | if ((bp = bufq_get(sc->sc_bufq)) != NULL) { | | 807 | if ((bp = bufq_get(sc->sc_bufq)) != NULL) { |
811 | #ifdef TSDEBUG | | 808 | #ifdef TSDEBUG |
812 | printf("tsintr2: que %p\n", bufq_peek(sc->sc_bufq)); | | 809 | printf("tsintr2: que %p\n", bufq_peek(sc->sc_bufq)); |
813 | #endif | | 810 | #endif |
814 | if (bp != &sc->ts_cbuf) { /* no ioctl */ | | 811 | if (bp != &sc->ts_cbuf) { /* no ioctl */ |
815 | bus_dmamap_unload(sc->sc_dmat, sc->sc_dmam); | | 812 | bus_dmamap_unload(sc->sc_dmat, sc->sc_dmam); |
816 | uba_done(sc->sc_uh); | | 813 | uba_done(sc->sc_uh); |
817 | } | | 814 | } |
818 | bp->b_resid = sc->sc_vts->status.rbpcr; | | 815 | bp->b_resid = sc->sc_vts->status.rbpcr; |
819 | biodone (bp); | | 816 | biodone (bp); |
820 | } | | 817 | } |
821 | tsstart(sc, 0); | | 818 | tsstart(sc, 0); |
822 | } | | 819 | } |
823 | | | 820 | |
824 | | | 821 | |
825 | /* | | 822 | /* |
826 | * Open a ts device and set the unit online. If the controller is not | | 823 | * Open a ts device and set the unit online. If the controller is not |
827 | * in the run state, call init to initialize the ts controller first. | | 824 | * in the run state, call init to initialize the ts controller first. |
828 | */ | | 825 | */ |
829 | int | | 826 | int |
830 | tsopen(dev_t dev, int flag, int type, struct lwp *l) | | 827 | tsopen(dev_t dev, int flag, int type, struct lwp *l) |
831 | { | | 828 | { |
832 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); | | 829 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); |
833 | | | 830 | |
834 | if (sc == NULL) | | 831 | if (sc == NULL) |
835 | return ENXIO; | | 832 | return ENXIO; |
836 | | | 833 | |
837 | if (sc->sc_state < TS_RUNNING) | | 834 | if (sc->sc_state < TS_RUNNING) |
838 | return ENXIO; | | 835 | return ENXIO; |
839 | | | 836 | |
840 | if (sc->sc_openf) | | 837 | if (sc->sc_openf) |
841 | return EBUSY; | | 838 | return EBUSY; |
842 | sc->sc_openf = 1; | | 839 | sc->sc_openf = 1; |
843 | | | 840 | |
844 | /* | | 841 | /* |
845 | * check if transport is really online. | | 842 | * check if transport is really online. |
846 | * (without attention-interrupts enabled, we really don't know | | 843 | * (without attention-interrupts enabled, we really don't know |
847 | * the actual state of the transport. Thus we call get-status | | 844 | * the actual state of the transport. Thus we call get-status |
848 | * (ie. MTNOP) once and check the actual status.) | | 845 | * (ie. MTNOP) once and check the actual status.) |
849 | */ | | 846 | */ |
850 | if (TS_RCSR(TSSR) & TS_OFL) { | | 847 | if (TS_RCSR(TSSR) & TS_OFL) { |
851 | uprintf("%s: transport is offline.\n", device_xname(sc->sc_dev)); | | 848 | uprintf("%s: transport is offline.\n", device_xname(sc->sc_dev)); |
852 | sc->sc_openf = 0; | | 849 | sc->sc_openf = 0; |
853 | return EIO; /* transport is offline */ | | 850 | return EIO; /* transport is offline */ |
854 | } | | 851 | } |
855 | tscommand(sc, dev, MTNOP, 1); | | 852 | tscommand(sc, dev, MTNOP, 1); |
856 | if ((flag & FWRITE) && (sc->sc_vts->status.xst0 & TS_SF_WLK)) { | | 853 | if ((flag & FWRITE) && (sc->sc_vts->status.xst0 & TS_SF_WLK)) { |
857 | uprintf("%s: no write ring.\n", device_xname(sc->sc_dev)); | | 854 | uprintf("%s: no write ring.\n", device_xname(sc->sc_dev)); |
858 | sc->sc_openf = 0; | | 855 | sc->sc_openf = 0; |
859 | return EROFS; | | 856 | return EROFS; |
860 | } | | 857 | } |
861 | if (sc->sc_vts->status.xst0 & TS_SF_VCK) { | | 858 | if (sc->sc_vts->status.xst0 & TS_SF_VCK) { |
862 | sc->sc_vts->cmd.cmdr = TS_CF_CVC|TS_CF_ACK; | | 859 | sc->sc_vts->cmd.cmdr = TS_CF_CVC|TS_CF_ACK; |
863 | TS_WCSR(TSDB, sc->sc_waddr); | | 860 | TS_WCSR(TSDB, sc->sc_waddr); |
864 | } | | 861 | } |
865 | tscommand(sc, dev, MTNOP, 1); | | 862 | tscommand(sc, dev, MTNOP, 1); |
866 | #ifdef TSDEBUG | | 863 | #ifdef TSDEBUG |
867 | { | | 864 | { |
868 | char buf[100]; | | 865 | char buf[100]; |
869 | snprintb(buf, sizeof(buf), | | 866 | snprintb(buf, sizeof(buf), |
870 | TS_XST0_BITS, sc->sc_vts->status.xst0); | | 867 | TS_XST0_BITS, sc->sc_vts->status.xst0); |
871 | printf("tsopen: xst0 %s\n", buf); | | 868 | printf("tsopen: xst0 %s\n", buf); |
872 | } | | 869 | } |
873 | #endif | | 870 | #endif |
874 | sc->sc_liowf = 0; | | 871 | sc->sc_liowf = 0; |
875 | return 0; | | 872 | return 0; |
876 | } | | 873 | } |
877 | | | 874 | |
878 | | | 875 | |
879 | /* | | 876 | /* |
880 | * Close tape device. | | 877 | * Close tape device. |
881 | * | | 878 | * |
882 | * If tape was open for writing or last operation was | | 879 | * If tape was open for writing or last operation was |
883 | * a write, then write two EOF's and backspace over the last one. | | 880 | * a write, then write two EOF's and backspace over the last one. |
884 | * Unless this is a non-rewinding special file, rewind the tape. | | 881 | * Unless this is a non-rewinding special file, rewind the tape. |
885 | * | | 882 | * |
886 | * Make the tape available to others, by clearing openf flag. | | 883 | * Make the tape available to others, by clearing openf flag. |
887 | */ | | 884 | */ |
888 | int | | 885 | int |
889 | tsclose(dev_t dev, int flag, int type, struct lwp *l) | | 886 | tsclose(dev_t dev, int flag, int type, struct lwp *l) |
890 | { | | 887 | { |
891 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); | | 888 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); |
892 | | | 889 | |
893 | if (flag == FWRITE || ((flag & FWRITE) && sc->sc_liowf)) { | | 890 | if (flag == FWRITE || ((flag & FWRITE) && sc->sc_liowf)) { |
894 | /* | | 891 | /* |
895 | * We are writing two tape marks (EOT), but place the tape | | 892 | * We are writing two tape marks (EOT), but place the tape |
896 | * before the second one, so that another write operation | | 893 | * before the second one, so that another write operation |
897 | * will overwrite the second one and leave and EOF-mark. | | 894 | * will overwrite the second one and leave and EOF-mark. |
898 | */ | | 895 | */ |
899 | tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ | | 896 | tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ |
900 | tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ | | 897 | tscommand(sc, dev, MTWEOF, 1); /* Write Tape Mark */ |
901 | tscommand(sc, dev, MTBSF, 1); /* Skip Tape Marks Reverse */ | | 898 | tscommand(sc, dev, MTBSF, 1); /* Skip Tape Marks Reverse */ |
902 | } | | 899 | } |
903 | | | 900 | |
904 | if ((dev & T_NOREWIND) == 0) | | 901 | if ((dev & T_NOREWIND) == 0) |
905 | tscommand(sc, dev, MTREW, 0); | | 902 | tscommand(sc, dev, MTREW, 0); |
906 | | | 903 | |
907 | sc->sc_openf = 0; | | 904 | sc->sc_openf = 0; |
908 | sc->sc_liowf = 0; | | 905 | sc->sc_liowf = 0; |
909 | return 0; | | 906 | return 0; |
910 | } | | 907 | } |
911 | | | 908 | |
912 | | | 909 | |
913 | /* | | 910 | /* |
914 | * Manage buffers and perform block mode read and write operations. | | 911 | * Manage buffers and perform block mode read and write operations. |
915 | */ | | 912 | */ |
916 | void | | 913 | void |
917 | tsstrategy(struct buf *bp) | | 914 | tsstrategy(struct buf *bp) |
918 | { | | 915 | { |
919 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(bp->b_dev)); | | 916 | struct ts_softc *sc = device_lookup_private(&ts_cd, TS_UNIT(bp->b_dev)); |
920 | bool empty; | | 917 | bool empty; |
921 | int s; | | 918 | int s; |
922 | | | 919 | |
923 | #ifdef TSDEBUG | | 920 | #ifdef TSDEBUG |
924 | printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); | | 921 | printf("buf: %p bcount %ld blkno %d\n", bp, bp->b_bcount, bp->b_blkno); |
925 | #endif | | 922 | #endif |
926 | s = splbio (); | | 923 | s = splbio (); |
927 | empty = (bufq_peek(sc->sc_bufq) == NULL); | | 924 | empty = (bufq_peek(sc->sc_bufq) == NULL); |
928 | bufq_put(sc->sc_bufq, bp); | | 925 | bufq_put(sc->sc_bufq, bp); |
929 | if (empty) | | 926 | if (empty) |
930 | tsstart(sc, 0); | | 927 | tsstart(sc, 0); |
931 | splx(s); | | 928 | splx(s); |
932 | } | | 929 | } |
933 | | | 930 | |
934 | | | 931 | |
935 | /* | | 932 | /* |
936 | * Catch ioctl commands, and call the "command" routine to do them. | | 933 | * Catch ioctl commands, and call the "command" routine to do them. |
937 | */ | | 934 | */ |
938 | int | | 935 | int |
939 | tsioctl(dev_t dev, | | 936 | tsioctl(dev_t dev, |
940 | u_long cmd, | | 937 | u_long cmd, |
941 | void *data, | | 938 | void *data, |
942 | int flag, | | 939 | int flag, |
943 | struct lwp *l) | | 940 | struct lwp *l) |
944 | { | | 941 | { |
945 | struct buf *bp; | | 942 | struct buf *bp; |
946 | struct ts_softc * const sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); | | 943 | struct ts_softc * const sc = device_lookup_private(&ts_cd, TS_UNIT(dev)); |
947 | struct mtop *mtop; /* mag tape cmd op to perform */ | | 944 | struct mtop *mtop; /* mag tape cmd op to perform */ |
948 | struct mtget *mtget; /* mag tape struct to get info in */ | | 945 | struct mtget *mtget; /* mag tape struct to get info in */ |
949 | int callcount; /* number of times to call routine */ | | 946 | int callcount; /* number of times to call routine */ |
950 | int scount; /* number of files/records to space */ | | 947 | int scount; /* number of files/records to space */ |
951 | int spaceop = 0; /* flag for skip/space operation */ | | 948 | int spaceop = 0; /* flag for skip/space operation */ |
952 | int error = 0; | | 949 | int error = 0; |
953 | | | 950 | |
954 | #ifdef TSDEBUG | | 951 | #ifdef TSDEBUG |
955 | printf("tsioctl (%x, %lx, %p, %d)\n", dev, cmd, data, flag); | | 952 | printf("tsioctl (%x, %lx, %p, %d)\n", dev, cmd, data, flag); |
956 | #endif | | 953 | #endif |
957 | | | 954 | |
958 | bp = &sc->ts_cbuf; | | 955 | bp = &sc->ts_cbuf; |
959 | | | 956 | |
960 | switch (cmd) { | | 957 | switch (cmd) { |
961 | case MTIOCTOP: /* do a mag tape op */ | | 958 | case MTIOCTOP: /* do a mag tape op */ |
962 | mtop = (struct mtop *)data; | | 959 | mtop = (struct mtop *)data; |
963 | switch (mtop->mt_op) { | | 960 | switch (mtop->mt_op) { |
964 | case MTWEOF: /* write an end-of-file record */ | | 961 | case MTWEOF: /* write an end-of-file record */ |
965 | callcount = mtop->mt_count; | | 962 | callcount = mtop->mt_count; |
966 | scount = 1; | | 963 | scount = 1; |
967 | break; | | 964 | break; |
968 | case MTFSR: /* forward space record */ | | 965 | case MTFSR: /* forward space record */ |
969 | case MTBSR: /* backward space record */ | | 966 | case MTBSR: /* backward space record */ |
970 | spaceop = 1; | | 967 | spaceop = 1; |
971 | case MTFSF: /* forward space file */ | | 968 | case MTFSF: /* forward space file */ |
972 | case MTBSF: /* backward space file */ | | 969 | case MTBSF: /* backward space file */ |
973 | callcount = 1; | | 970 | callcount = 1; |
974 | scount = mtop->mt_count; | | 971 | scount = mtop->mt_count; |
975 | break; | | 972 | break; |
976 | case MTREW: /* rewind */ | | 973 | case MTREW: /* rewind */ |
977 | case MTOFFL: /* rewind and put the drive offline */ | | 974 | case MTOFFL: /* rewind and put the drive offline */ |
978 | case MTNOP: /* no operation, sets status only */ | | 975 | case MTNOP: /* no operation, sets status only */ |
979 | callcount = 1; | | 976 | callcount = 1; |
980 | scount = 1; /* wait for this rewind */ | | 977 | scount = 1; /* wait for this rewind */ |
981 | break; | | 978 | break; |
982 | case MTRETEN: /* retension */ | | 979 | case MTRETEN: /* retension */ |
983 | case MTERASE: /* erase entire tape */ | | 980 | case MTERASE: /* erase entire tape */ |
984 | case MTEOM: /* forward to end of media */ | | 981 | case MTEOM: /* forward to end of media */ |
985 | case MTNBSF: /* backward space to begin of file */ | | 982 | case MTNBSF: /* backward space to begin of file */ |
986 | case MTCACHE: /* enable controller cache */ | | 983 | case MTCACHE: /* enable controller cache */ |
987 | case MTNOCACHE: /* disable controller cache */ | | 984 | case MTNOCACHE: /* disable controller cache */ |
988 | case MTSETBSIZ: /* set block size; 0 for variable */ | | 985 | case MTSETBSIZ: /* set block size; 0 for variable */ |
989 | case MTSETDNSTY: /* set density code for current mode */ | | 986 | case MTSETDNSTY: /* set density code for current mode */ |
990 | printf("ioctl %d not implemented.\n", mtop->mt_op); | | 987 | printf("ioctl %d not implemented.\n", mtop->mt_op); |
991 | return (ENXIO); | | 988 | return (ENXIO); |
992 | default: | | 989 | default: |
993 | #ifdef TSDEBUG | | 990 | #ifdef TSDEBUG |
994 | printf("invalid ioctl %d\n", mtop->mt_op); | | 991 | printf("invalid ioctl %d\n", mtop->mt_op); |
995 | #endif | | 992 | #endif |
996 | return (ENXIO); | | 993 | return (ENXIO); |
997 | } /* switch (mtop->mt_op) */ | | 994 | } /* switch (mtop->mt_op) */ |
998 | | | 995 | |
999 | if (callcount <= 0 || scount <= 0) { | | 996 | if (callcount <= 0 || scount <= 0) { |
1000 | #ifdef TSDEBUG | | 997 | #ifdef TSDEBUG |
1001 | printf("invalid values %d/%d\n", callcount, scount); | | 998 | printf("invalid values %d/%d\n", callcount, scount); |
1002 | #endif | | 999 | #endif |
1003 | return (EINVAL); | | 1000 | return (EINVAL); |
1004 | } | | 1001 | } |
1005 | do { | | 1002 | do { |
1006 | tscommand(sc, dev, mtop->mt_op, scount); | | 1003 | tscommand(sc, dev, mtop->mt_op, scount); |
1007 | if (spaceop && bp->b_resid) { | | 1004 | if (spaceop && bp->b_resid) { |
1008 | #ifdef TSDEBUG | | 1005 | #ifdef TSDEBUG |
1009 | printf(("spaceop didn't complete\n")); | | 1006 | printf(("spaceop didn't complete\n")); |
1010 | #endif | | 1007 | #endif |
1011 | return (EIO); | | 1008 | return (EIO); |
1012 | } | | 1009 | } |
1013 | if (bp->b_error != 0) { | | 1010 | if (bp->b_error != 0) { |
1014 | #ifdef TSDEBUG | | 1011 | #ifdef TSDEBUG |
1015 | printf("error in ioctl %d\n", mtop->mt_op); | | 1012 | printf("error in ioctl %d\n", mtop->mt_op); |
1016 | #endif | | 1013 | #endif |
1017 | break; | | 1014 | break; |
1018 | } | | 1015 | } |
1019 | } while (--callcount > 0); | | 1016 | } while (--callcount > 0); |
1020 | if (bp->b_error != 0) | | 1017 | if (bp->b_error != 0) |
1021 | error = bp->b_error; | | 1018 | error = bp->b_error; |
1022 | return (error); | | 1019 | return (error); |
1023 | | | 1020 | |
1024 | case MTIOCGET: /* get tape status */ | | 1021 | case MTIOCGET: /* get tape status */ |
1025 | mtget = (struct mtget *)data; | | 1022 | mtget = (struct mtget *)data; |
1026 | mtget->mt_type = MT_ISTS; | | 1023 | mtget->mt_type = MT_ISTS; |
1027 | mtget->mt_dsreg = TS_RCSR(TSSR); | | 1024 | mtget->mt_dsreg = TS_RCSR(TSSR); |
1028 | mtget->mt_erreg = sc->sc_vts->status.xst0; | | 1025 | mtget->mt_erreg = sc->sc_vts->status.xst0; |
1029 | mtget->mt_resid = 0; /* ??? */ | | 1026 | mtget->mt_resid = 0; /* ??? */ |
1030 | mtget->mt_density = 0; /* ??? */ | | 1027 | mtget->mt_density = 0; /* ??? */ |
1031 | break; | | 1028 | break; |
1032 | | | 1029 | |
1033 | case MTIOCIEOT: /* ignore EOT error */ | | 1030 | case MTIOCIEOT: /* ignore EOT error */ |
1034 | #ifdef TSDEBUG | | 1031 | #ifdef TSDEBUG |
1035 | printf(("MTIOCIEOT not implemented.\n")); | | 1032 | printf(("MTIOCIEOT not implemented.\n")); |
1036 | #endif | | 1033 | #endif |
1037 | return (ENXIO); | | 1034 | return (ENXIO); |
1038 | | | 1035 | |
1039 | case MTIOCEEOT: /* enable EOT error */ | | 1036 | case MTIOCEEOT: /* enable EOT error */ |
1040 | #ifdef TSDEBUG | | 1037 | #ifdef TSDEBUG |
1041 | printf(("MTIOCEEOT not implemented.\n")); | | 1038 | printf(("MTIOCEEOT not implemented.\n")); |
1042 | #endif | | 1039 | #endif |
1043 | return (ENXIO); | | 1040 | return (ENXIO); |
1044 | | | 1041 | |
1045 | default: | | 1042 | default: |
1046 | #ifdef TSDEBUG | | 1043 | #ifdef TSDEBUG |
1047 | printf("invalid ioctl cmd 0x%lx\n", cmd); | | 1044 | printf("invalid ioctl cmd 0x%lx\n", cmd); |
1048 | #endif | | 1045 | #endif |
1049 | return (ENXIO); | | 1046 | return (ENXIO); |
1050 | } | | 1047 | } |
1051 | | | 1048 | |
1052 | return (0); | | 1049 | return (0); |
1053 | } | | 1050 | } |
1054 | | | 1051 | |
1055 | | | 1052 | |
1056 | /* | | 1053 | /* |
1057 | * | | 1054 | * |
1058 | */ | | 1055 | */ |
1059 | int | | 1056 | int |
1060 | tsread(dev_t dev, struct uio *uio, int flag) | | 1057 | tsread(dev_t dev, struct uio *uio, int flag) |
1061 | { | | 1058 | { |
1062 | return (physio (tsstrategy, NULL, dev, B_READ, minphys, uio)); | | 1059 | return (physio (tsstrategy, NULL, dev, B_READ, minphys, uio)); |
1063 | } | | 1060 | } |
1064 | | | 1061 | |
1065 | /* | | 1062 | /* |
1066 | * | | 1063 | * |
1067 | */ | | 1064 | */ |
1068 | int | | 1065 | int |
1069 | tswrite(dev_t dev, struct uio *uio, int flag) | | 1066 | tswrite(dev_t dev, struct uio *uio, int flag) |
1070 | { | | 1067 | { |
1071 | return (physio (tsstrategy, NULL, dev, B_WRITE, minphys, uio)); | | 1068 | return (physio (tsstrategy, NULL, dev, B_WRITE, minphys, uio)); |
1072 | } | | 1069 | } |
1073 | | | 1070 | |
1074 | /* | | 1071 | /* |
1075 | * | | 1072 | * |
1076 | */ | | 1073 | */ |
1077 | int | | 1074 | int |
1078 | tsdump(dev_t dev, daddr_t blkno, void *va, size_t size) | | 1075 | tsdump(dev_t dev, daddr_t blkno, void *va, size_t size) |
1079 | { | | 1076 | { |
1080 | return EIO; | | 1077 | return EIO; |
1081 | } | | 1078 | } |