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