Commit | Line | Data |
---|---|---|
92e67171 | 1 | /* ts.c 6.1 83/07/29 */ |
9bad5ea5 | 2 | |
66b4fb09 | 3 | #include "ts.h" |
9bad5ea5 BJ |
4 | #if NTS > 0 |
5 | /* | |
6 | * TS11 tape driver | |
30a7bcbf BJ |
7 | * |
8 | * TODO: | |
a870f835 | 9 | * write dump code |
9bad5ea5 | 10 | */ |
961945a8 SL |
11 | #include "../machine/pte.h" |
12 | ||
9bad5ea5 BJ |
13 | #include "../h/param.h" |
14 | #include "../h/systm.h" | |
15 | #include "../h/buf.h" | |
9bad5ea5 | 16 | #include "../h/dir.h" |
30a7bcbf | 17 | #include "../h/conf.h" |
9bad5ea5 | 18 | #include "../h/user.h" |
30a7bcbf | 19 | #include "../h/file.h" |
9bad5ea5 | 20 | #include "../h/map.h" |
e1b765e1 | 21 | #include "../h/vm.h" |
30a7bcbf | 22 | #include "../h/ioctl.h" |
942f05a9 | 23 | #include "../h/mtio.h" |
30a7bcbf | 24 | #include "../h/cmap.h" |
740e4029 | 25 | #include "../h/uio.h" |
30a7bcbf | 26 | |
896962b1 BJ |
27 | #include "../vax/cpu.h" |
28 | #include "../vaxuba/ubareg.h" | |
29 | #include "../vaxuba/ubavar.h" | |
30 | #include "../vaxuba/tsreg.h" | |
30a7bcbf BJ |
31 | |
32 | /* | |
33 | * There is a ctsbuf per tape controller. | |
34 | * It is used as the token to pass to the internal routines | |
35 | * to execute tape ioctls. | |
36 | * In particular, when the tape is rewinding on close we release | |
37 | * the user process but any further attempts to use the tape drive | |
38 | * before the rewind completes will hang waiting for ctsbuf. | |
39 | */ | |
40 | struct buf ctsbuf[NTS]; | |
41 | ||
42 | /* | |
43 | * Raw tape operations use rtsbuf. The driver | |
44 | * notices when rtsbuf is being used and allows the user | |
45 | * program to continue after errors and read records | |
46 | * not of the standard length (BSIZE). | |
47 | */ | |
48 | struct buf rtsbuf[NTS]; | |
49 | ||
50 | /* | |
51 | * Driver unibus interface routines and variables. | |
52 | */ | |
53 | int tsprobe(), tsslave(), tsattach(), tsdgo(), tsintr(); | |
54 | struct uba_ctlr *tsminfo[NTS]; | |
55 | struct uba_device *tsdinfo[NTS]; | |
a870f835 | 56 | struct buf tsutab[NTS]; |
30a7bcbf BJ |
57 | u_short tsstd[] = { 0772520, 0 }; |
58 | /*** PROBABLY DON'T NEED ALL THESE SINCE CONTROLLER == DRIVE ***/ | |
59 | struct uba_driver zsdriver = | |
30e0abb3 | 60 | { tsprobe, tsslave, tsattach, tsdgo, tsstd, "ts", tsdinfo, "zs", tsminfo, 0 }; |
30a7bcbf BJ |
61 | |
62 | /* bits in minor device */ | |
63 | #define TSUNIT(dev) (minor(dev)&03) | |
64 | #define T_NOREWIND 04 | |
9bad5ea5 | 65 | |
30a7bcbf | 66 | #define INF (daddr_t)1000000L |
9bad5ea5 | 67 | |
30a7bcbf BJ |
68 | /* |
69 | * Software state per tape transport. | |
70 | * Also contains hardware state in message packets. | |
71 | * | |
72 | * 1. A tape drive is a unique-open device; we refuse opens when it is already. | |
73 | * 2. We keep track of the current position on a block tape and seek | |
74 | * before operations by forward/back spacing if necessary. | |
75 | * 3. We remember if the last operation was a write on a tape, so if a tape | |
76 | * is open read write and the last thing done is a write we can | |
77 | * write a standard end of tape mark (two eofs). | |
78 | * 4. We remember the status registers after the last command, using | |
79 | * then internally and returning them to the SENSE ioctl. | |
80 | */ | |
81 | struct ts_softc { | |
82 | char sc_openf; /* lock against multiple opens */ | |
83 | char sc_lastiow; /* last op was a write */ | |
30e0abb3 | 84 | short sc_resid; /* copy of last bc */ |
30a7bcbf BJ |
85 | daddr_t sc_blkno; /* block number, for block device tape */ |
86 | daddr_t sc_nxrec; /* position of end of tape, if known */ | |
a870f835 BJ |
87 | struct ts_cmd sc_cmd; /* the command packet */ |
88 | struct ts_sts sc_sts; /* status packet, for returned status */ | |
89 | struct ts_char sc_char; /* characteristics packet */ | |
90 | struct ts_softc *sc_ubaddr; /* Unibus address of ts_softc structure */ | |
198f077a | 91 | u_short sc_uba; /* Unibus addr of cmd pkt for tsdb */ |
a870f835 | 92 | short sc_mapped; /* is ts_sfotc mapped in Unibus space? */ |
30a7bcbf BJ |
93 | } ts_softc[NTS]; |
94 | ||
30a7bcbf BJ |
95 | /* |
96 | * States for um->um_tab.b_active, the per controller state flag. | |
97 | * This is used to sequence control in the driver. | |
98 | */ | |
99 | #define SSEEK 1 /* seeking */ | |
100 | #define SIO 2 /* doing seq i/o */ | |
101 | #define SCOM 3 /* sending control command */ | |
102 | #define SREW 4 /* sending a drive rewind */ | |
103 | ||
104 | /* | |
105 | * Determine if there is a controller for | |
106 | * a ts at address reg. Our goal is to make the | |
107 | * device interrupt. | |
108 | */ | |
b620b354 | 109 | /*ARGSUSED*/ |
30a7bcbf BJ |
110 | tsprobe(reg) |
111 | caddr_t reg; | |
112 | { | |
113 | register int br, cvec; /* must be r11,r10; value-result */ | |
114 | ||
115 | #ifdef lint | |
116 | br = 0; cvec = br; br = cvec; | |
89b8a44c | 117 | tsintr(0); |
30a7bcbf | 118 | #endif |
a870f835 BJ |
119 | ((struct tsdevice *)reg)->tssr = 0; |
120 | DELAY(100); | |
121 | if ((((struct tsdevice *)reg)->tssr & TS_NBA) == 0) | |
122 | return(0); | |
123 | /* IT'S TOO HARD TO MAKE THIS THING INTERRUPT JUST TO FIND ITS VECTOR */ | |
124 | cvec = ((unsigned)reg) & 07 ? 0260 : 0224; | |
30a7bcbf | 125 | br = 0x15; |
9c0adba0 | 126 | return (sizeof (struct tsdevice)); |
30a7bcbf BJ |
127 | } |
128 | ||
129 | /* | |
130 | * TS11 only supports one drive per controller; | |
131 | * check for ui_slave == 0. | |
132 | * | |
133 | * DO WE REALLY NEED THIS ROUTINE??? | |
134 | */ | |
135 | /*ARGSUSED*/ | |
136 | tsslave(ui, reg) | |
137 | struct uba_device *ui; | |
138 | caddr_t reg; | |
139 | { | |
140 | ||
141 | if (ui->ui_slave) /* non-zero slave not allowed */ | |
142 | return(0); | |
143 | return (1); | |
144 | } | |
145 | ||
146 | /* | |
147 | * Record attachment of the unit to the controller. | |
148 | * | |
149 | * SHOULD THIS ROUTINE DO ANYTHING??? | |
150 | */ | |
151 | /*ARGSUSED*/ | |
152 | tsattach(ui) | |
153 | struct uba_device *ui; | |
154 | { | |
155 | ||
156 | } | |
157 | ||
158 | /* | |
159 | * Open the device. Tapes are unique open | |
160 | * devices, so we refuse if it is already open. | |
161 | * We also check that a tape is available, and | |
162 | * don't block waiting here; if you want to wait | |
163 | * for a tape you should timeout in user code. | |
164 | */ | |
9bad5ea5 | 165 | tsopen(dev, flag) |
30a7bcbf BJ |
166 | dev_t dev; |
167 | int flag; | |
9bad5ea5 | 168 | { |
30a7bcbf BJ |
169 | register int tsunit; |
170 | register struct uba_device *ui; | |
171 | register struct ts_softc *sc; | |
9bad5ea5 | 172 | |
30a7bcbf BJ |
173 | tsunit = TSUNIT(dev); |
174 | if (tsunit>=NTS || (sc = &ts_softc[tsunit])->sc_openf || | |
7da157da BJ |
175 | (ui = tsdinfo[tsunit]) == 0 || ui->ui_alive == 0) |
176 | return (ENXIO); | |
177 | if (tsinit(tsunit)) | |
178 | return (ENXIO); | |
30a7bcbf | 179 | tscommand(dev, TS_SENSE, 1); |
9f1f6818 BJ |
180 | if ((sc->sc_sts.s_xs0&TS_ONL) == 0) { |
181 | uprintf("ts%d: not online\n", tsunit); | |
7da157da | 182 | return (EIO); |
9f1f6818 | 183 | } |
4cb88cd4 | 184 | if ((flag&(FREAD|FWRITE)) == FWRITE && (sc->sc_sts.s_xs0&TS_WLK)) { |
9f1f6818 | 185 | uprintf("ts%d: no write ring\n", tsunit); |
7da157da | 186 | return (EIO); |
9bad5ea5 | 187 | } |
30a7bcbf BJ |
188 | sc->sc_openf = 1; |
189 | sc->sc_blkno = (daddr_t)0; | |
190 | sc->sc_nxrec = INF; | |
191 | sc->sc_lastiow = 0; | |
7da157da | 192 | return (0); |
9bad5ea5 BJ |
193 | } |
194 | ||
30a7bcbf BJ |
195 | /* |
196 | * Close tape device. | |
197 | * | |
198 | * If tape was open for writing or last operation was | |
199 | * a write, then write two EOF's and backspace over the last one. | |
200 | * Unless this is a non-rewinding special file, rewind the tape. | |
201 | * Make the tape available to others. | |
202 | */ | |
9bad5ea5 | 203 | tsclose(dev, flag) |
30a7bcbf BJ |
204 | register dev_t dev; |
205 | register flag; | |
9bad5ea5 | 206 | { |
30a7bcbf BJ |
207 | register struct ts_softc *sc = &ts_softc[TSUNIT(dev)]; |
208 | ||
209 | if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) { | |
210 | tscommand(dev, TS_WEOF, 1); | |
211 | tscommand(dev, TS_WEOF, 1); | |
212 | tscommand(dev, TS_SREV, 1); | |
213 | } | |
214 | if ((minor(dev)&T_NOREWIND) == 0) | |
215 | /* | |
216 | * 0 count means don't hang waiting for rewind complete | |
217 | * rather ctsbuf stays busy until the operation completes | |
218 | * preventing further opens from completing by | |
219 | * preventing a TS_SENSE from completing. | |
220 | */ | |
221 | tscommand(dev, TS_REW, 0); | |
222 | sc->sc_openf = 0; | |
223 | } | |
9bad5ea5 | 224 | |
30a7bcbf BJ |
225 | /* |
226 | * Initialize the TS11. Set up Unibus mapping for command | |
227 | * packets and set device characteristics. | |
228 | */ | |
229 | tsinit(unit) | |
230 | register int unit; | |
231 | { | |
232 | register struct ts_softc *sc = &ts_softc[unit]; | |
233 | register struct uba_ctlr *um = tsminfo[unit]; | |
a870f835 | 234 | register struct tsdevice *addr = (struct tsdevice *)um->um_addr; |
30a7bcbf BJ |
235 | register int i; |
236 | ||
237 | /* | |
238 | * Map the command and message packets into Unibus | |
239 | * address space. We do all the command and message | |
240 | * packets at once to minimize the amount of Unibus | |
241 | * mapping necessary. | |
242 | */ | |
a870f835 BJ |
243 | if (sc->sc_mapped == 0) { |
244 | ctsbuf[unit].b_un.b_addr = (caddr_t)sc; | |
245 | ctsbuf[unit].b_bcount = sizeof(*sc); | |
30a7bcbf BJ |
246 | i = ubasetup(um->um_ubanum, &ctsbuf[unit], 0); |
247 | i &= 0777777; | |
a870f835 BJ |
248 | sc->sc_ubaddr = (struct ts_softc *)i; |
249 | sc->sc_mapped++; | |
30a7bcbf BJ |
250 | } |
251 | /* | |
252 | * Now initialize the TS11 controller. | |
253 | * Set the characteristics. | |
254 | */ | |
691a71cc | 255 | if (addr->tssr & (TS_NBA|TS_OFL)) { |
30a7bcbf BJ |
256 | addr->tssr = 0; /* subsystem initialize */ |
257 | tswait(addr); | |
a870f835 | 258 | i = (int)&sc->sc_ubaddr->sc_cmd; /* Unibus addr of cmd */ |
30a7bcbf | 259 | sc->sc_uba = (u_short)(i + ((i>>16)&3)); |
a870f835 | 260 | sc->sc_char.char_addr = (int)&sc->sc_ubaddr->sc_sts; |
30a7bcbf BJ |
261 | sc->sc_char.char_size = sizeof(struct ts_sts); |
262 | sc->sc_char.char_mode = TS_ESS; | |
263 | sc->sc_cmd.c_cmd = TS_ACK | TS_SETCHR; | |
a870f835 | 264 | i = (int)&sc->sc_ubaddr->sc_char; |
30e0abb3 BJ |
265 | sc->sc_cmd.c_loba = i; |
266 | sc->sc_cmd.c_hiba = (i>>16)&3; | |
30a7bcbf BJ |
267 | sc->sc_cmd.c_size = sizeof(struct ts_char); |
268 | addr->tsdb = sc->sc_uba; | |
269 | tswait(addr); | |
30e0abb3 BJ |
270 | if (addr->tssr & TS_NBA) |
271 | return(1); | |
9bad5ea5 | 272 | } |
30a7bcbf | 273 | return(0); |
9bad5ea5 BJ |
274 | } |
275 | ||
30a7bcbf BJ |
276 | /* |
277 | * Execute a command on the tape drive | |
278 | * a specified number of times. | |
279 | */ | |
280 | tscommand(dev, com, count) | |
281 | dev_t dev; | |
282 | int com, count; | |
9bad5ea5 BJ |
283 | { |
284 | register struct buf *bp; | |
2311123d | 285 | register int s; |
9bad5ea5 | 286 | |
30a7bcbf | 287 | bp = &ctsbuf[TSUNIT(dev)]; |
2311123d | 288 | s = spl5(); |
30a7bcbf BJ |
289 | while (bp->b_flags&B_BUSY) { |
290 | /* | |
291 | * This special check is because B_BUSY never | |
292 | * gets cleared in the non-waiting rewind case. | |
293 | */ | |
294 | if (bp->b_repcnt == 0 && (bp->b_flags&B_DONE)) | |
295 | break; | |
9bad5ea5 BJ |
296 | bp->b_flags |= B_WANTED; |
297 | sleep((caddr_t)bp, PRIBIO); | |
298 | } | |
9bad5ea5 | 299 | bp->b_flags = B_BUSY|B_READ; |
2311123d | 300 | splx(s); |
30a7bcbf BJ |
301 | bp->b_dev = dev; |
302 | bp->b_repcnt = count; | |
303 | bp->b_command = com; | |
304 | bp->b_blkno = 0; | |
9bad5ea5 | 305 | tsstrategy(bp); |
30a7bcbf BJ |
306 | /* |
307 | * In case of rewind from close, don't wait. | |
308 | * This is the only case where count can be 0. | |
309 | */ | |
310 | if (count == 0) | |
311 | return; | |
9bad5ea5 | 312 | iowait(bp); |
30a7bcbf | 313 | if (bp->b_flags&B_WANTED) |
9bad5ea5 | 314 | wakeup((caddr_t)bp); |
30a7bcbf | 315 | bp->b_flags &= B_ERROR; |
9bad5ea5 BJ |
316 | } |
317 | ||
30a7bcbf BJ |
318 | /* |
319 | * Queue a tape operation. | |
320 | */ | |
9bad5ea5 | 321 | tsstrategy(bp) |
30a7bcbf | 322 | register struct buf *bp; |
9bad5ea5 | 323 | { |
30a7bcbf BJ |
324 | int tsunit = TSUNIT(bp->b_dev); |
325 | register struct uba_ctlr *um; | |
30e0abb3 | 326 | register struct buf *dp; |
2311123d | 327 | register int s; |
30a7bcbf BJ |
328 | |
329 | /* | |
330 | * Put transfer at end of controller queue | |
331 | */ | |
9bad5ea5 | 332 | bp->av_forw = NULL; |
30a7bcbf | 333 | um = tsdinfo[tsunit]->ui_mi; |
2311123d | 334 | s = spl5(); |
a870f835 | 335 | dp = &tsutab[tsunit]; |
30e0abb3 BJ |
336 | if (dp->b_actf == NULL) |
337 | dp->b_actf = bp; | |
9bad5ea5 | 338 | else |
30e0abb3 BJ |
339 | dp->b_actl->av_forw = bp; |
340 | dp->b_actl = bp; | |
341 | um->um_tab.b_actf = um->um_tab.b_actl = dp; | |
30a7bcbf BJ |
342 | /* |
343 | * If the controller is not busy, get | |
344 | * it going. | |
345 | */ | |
346 | if (um->um_tab.b_active == 0) | |
347 | tsstart(um); | |
2311123d | 348 | splx(s); |
9bad5ea5 BJ |
349 | } |
350 | ||
30a7bcbf BJ |
351 | /* |
352 | * Start activity on a ts controller. | |
353 | */ | |
354 | tsstart(um) | |
355 | register struct uba_ctlr *um; | |
9bad5ea5 BJ |
356 | { |
357 | register struct buf *bp; | |
a870f835 | 358 | register struct tsdevice *addr = (struct tsdevice *)um->um_addr; |
30a7bcbf BJ |
359 | register struct ts_softc *sc; |
360 | register struct ts_cmd *tc; | |
361 | register struct uba_device *ui; | |
362 | int tsunit, cmd; | |
9bad5ea5 BJ |
363 | daddr_t blkno; |
364 | ||
30a7bcbf BJ |
365 | /* |
366 | * Start the controller if there is something for it to do. | |
367 | */ | |
368 | loop: | |
30e0abb3 | 369 | if ((bp = um->um_tab.b_actf->b_actf) == NULL) |
9bad5ea5 | 370 | return; |
30a7bcbf BJ |
371 | tsunit = TSUNIT(bp->b_dev); |
372 | ui = tsdinfo[tsunit]; | |
373 | sc = &ts_softc[tsunit]; | |
374 | tc = &sc->sc_cmd; | |
375 | /* | |
376 | * Default is that last command was NOT a write command; | |
377 | * if we do a write command we will notice this in tsintr(). | |
378 | */ | |
b56f55c7 | 379 | sc->sc_lastiow = 0; |
30a7bcbf BJ |
380 | if (sc->sc_openf < 0 || (addr->tssr&TS_OFL)) { |
381 | /* | |
382 | * Have had a hard error on a non-raw tape | |
383 | * or the tape unit is now unavailable | |
384 | * (e.g. taken off line). | |
385 | */ | |
386 | bp->b_flags |= B_ERROR; | |
387 | goto next; | |
388 | } | |
389 | if (bp == &ctsbuf[TSUNIT(bp->b_dev)]) { | |
390 | /* | |
391 | * Execute control operation with the specified count. | |
392 | */ | |
393 | um->um_tab.b_active = | |
394 | bp->b_command == TS_REW ? SREW : SCOM; | |
395 | tc->c_repcnt = bp->b_repcnt; | |
396 | goto dobpcmd; | |
397 | } | |
398 | /* | |
399 | * The following checks handle boundary cases for operation | |
400 | * on non-raw tapes. On raw tapes the initialization of | |
401 | * sc->sc_nxrec by tsphys causes them to be skipped normally | |
402 | * (except in the case of retries). | |
403 | */ | |
fb739082 | 404 | if (bdbtofsb(bp->b_blkno) > sc->sc_nxrec) { |
30a7bcbf BJ |
405 | /* |
406 | * Can't read past known end-of-file. | |
407 | */ | |
408 | bp->b_flags |= B_ERROR; | |
409 | bp->b_error = ENXIO; | |
410 | goto next; | |
411 | } | |
fb739082 | 412 | if (bdbtofsb(bp->b_blkno) == sc->sc_nxrec && |
30a7bcbf BJ |
413 | bp->b_flags&B_READ) { |
414 | /* | |
415 | * Reading at end of file returns 0 bytes. | |
416 | */ | |
417 | bp->b_resid = bp->b_bcount; | |
418 | clrbuf(bp); | |
419 | goto next; | |
420 | } | |
421 | if ((bp->b_flags&B_READ) == 0) | |
422 | /* | |
423 | * Writing sets EOF | |
424 | */ | |
fb739082 | 425 | sc->sc_nxrec = bdbtofsb(bp->b_blkno) + 1; |
30a7bcbf BJ |
426 | /* |
427 | * If the data transfer command is in the correct place, | |
428 | * set up all the registers except the csr, and give | |
429 | * control over to the UNIBUS adapter routines, to | |
430 | * wait for resources to start the i/o. | |
431 | */ | |
fb739082 | 432 | if ((blkno = sc->sc_blkno) == bdbtofsb(bp->b_blkno)) { |
30a7bcbf BJ |
433 | tc->c_size = bp->b_bcount; |
434 | if ((bp->b_flags&B_READ) == 0) | |
435 | cmd = TS_WCOM; | |
9bad5ea5 | 436 | else |
30a7bcbf BJ |
437 | cmd = TS_RCOM; |
438 | if (um->um_tab.b_errcnt) | |
439 | cmd |= TS_RETRY; | |
440 | um->um_tab.b_active = SIO; | |
30e0abb3 | 441 | tc->c_cmd = TS_ACK | TS_CVC | TS_IE | cmd; |
30a7bcbf BJ |
442 | (void) ubago(ui); |
443 | return; | |
444 | } | |
445 | /* | |
446 | * Tape positioned incorrectly; | |
447 | * set to seek forwards or backwards to the correct spot. | |
448 | * This happens for raw tapes only on error retries. | |
449 | */ | |
450 | um->um_tab.b_active = SSEEK; | |
fb739082 | 451 | if (blkno < bdbtofsb(bp->b_blkno)) { |
30a7bcbf | 452 | bp->b_command = TS_SFORW; |
fb739082 | 453 | tc->c_repcnt = bdbtofsb(bp->b_blkno) - blkno; |
9bad5ea5 | 454 | } else { |
30a7bcbf | 455 | bp->b_command = TS_SREV; |
fb739082 | 456 | tc->c_repcnt = blkno - bdbtofsb(bp->b_blkno); |
9bad5ea5 | 457 | } |
30a7bcbf BJ |
458 | dobpcmd: |
459 | /* | |
460 | * Do the command in bp. | |
461 | */ | |
30e0abb3 | 462 | tc->c_cmd = TS_ACK | TS_CVC | TS_IE | bp->b_command; |
30a7bcbf | 463 | addr->tsdb = sc->sc_uba; |
9bad5ea5 BJ |
464 | return; |
465 | ||
30a7bcbf BJ |
466 | next: |
467 | /* | |
468 | * Done with this operation due to error or | |
469 | * the fact that it doesn't do anything. | |
470 | * Release UBA resources (if any), dequeue | |
471 | * the transfer and continue processing this slave. | |
472 | */ | |
473 | if (um->um_ubinfo) | |
474 | ubadone(um); | |
475 | um->um_tab.b_errcnt = 0; | |
30e0abb3 | 476 | um->um_tab.b_actf->b_actf = bp->av_forw; |
9bad5ea5 BJ |
477 | iodone(bp); |
478 | goto loop; | |
479 | } | |
480 | ||
30a7bcbf BJ |
481 | /* |
482 | * The UNIBUS resources we needed have been | |
483 | * allocated to us; start the device. | |
484 | */ | |
485 | tsdgo(um) | |
486 | register struct uba_ctlr *um; | |
487 | { | |
a870f835 | 488 | register struct tsdevice *addr = (struct tsdevice *)um->um_addr; |
30a7bcbf | 489 | register struct ts_softc *sc = &ts_softc[um->um_ctlr]; |
30e0abb3 | 490 | register int i; |
30a7bcbf | 491 | |
30e0abb3 | 492 | i = um->um_ubinfo & 0777777; |
30e0abb3 BJ |
493 | sc->sc_cmd.c_loba = i; |
494 | sc->sc_cmd.c_hiba = (i>>16)&3; | |
30a7bcbf BJ |
495 | addr->tsdb = sc->sc_uba; |
496 | } | |
497 | ||
498 | /* | |
499 | * Ts interrupt routine. | |
500 | */ | |
501 | /*ARGSUSED*/ | |
502 | tsintr(ts11) | |
503 | int ts11; | |
9bad5ea5 BJ |
504 | { |
505 | register struct buf *bp; | |
30a7bcbf | 506 | register struct uba_ctlr *um = tsminfo[ts11]; |
a870f835 | 507 | register struct tsdevice *addr; |
30a7bcbf BJ |
508 | register struct ts_softc *sc; |
509 | int tsunit; | |
510 | register state; | |
9bad5ea5 | 511 | |
30e0abb3 | 512 | if ((bp = um->um_tab.b_actf->b_actf) == NULL) |
9bad5ea5 | 513 | return; |
30a7bcbf | 514 | tsunit = TSUNIT(bp->b_dev); |
a870f835 | 515 | addr = (struct tsdevice *)tsdinfo[tsunit]->ui_addr; |
30a7bcbf BJ |
516 | /* |
517 | * If last command was a rewind, and tape is still | |
518 | * rewinding, wait for the rewind complete interrupt. | |
519 | * | |
520 | * SHOULD NEVER GET AN INTERRUPT IN THIS STATE. | |
521 | */ | |
522 | if (um->um_tab.b_active == SREW) { | |
523 | um->um_tab.b_active = SCOM; | |
524 | if ((addr->tssr&TS_SSR) == 0) | |
525 | return; | |
526 | } | |
527 | /* | |
528 | * An operation completed... record status | |
529 | */ | |
530 | sc = &ts_softc[tsunit]; | |
531 | if ((bp->b_flags & B_READ) == 0) | |
532 | sc->sc_lastiow = 1; | |
533 | state = um->um_tab.b_active; | |
534 | um->um_tab.b_active = 0; | |
535 | /* | |
536 | * Check for errors. | |
537 | */ | |
538 | if (addr->tssr&TS_SC) { | |
539 | switch (addr->tssr & TS_TC) { | |
540 | case TS_UNREC: /* unrecoverable */ | |
541 | case TS_FATAL: /* fatal error */ | |
542 | case TS_ATTN: /* attention (shouldn't happen) */ | |
543 | case TS_RECNM: /* recoverable, no motion */ | |
544 | break; | |
545 | ||
546 | case TS_SUCC: /* success termination */ | |
547 | printf("ts%d: success\n", TSUNIT(minor(bp->b_dev))); | |
548 | goto ignoreerr; | |
549 | ||
550 | case TS_ALERT: /* tape status alert */ | |
551 | /* | |
552 | * If we hit the end of the tape file, | |
553 | * update our position. | |
554 | */ | |
555 | if (sc->sc_sts.s_xs0 & (TS_TMK|TS_EOT)) { | |
556 | tsseteof(bp); /* set blkno and nxrec */ | |
557 | state = SCOM; /* force completion */ | |
558 | /* | |
559 | * Stuff bc so it will be unstuffed correctly | |
560 | * later to get resid. | |
561 | */ | |
562 | sc->sc_sts.s_rbpcr = bp->b_bcount; | |
563 | goto opdone; | |
564 | } | |
565 | /* | |
566 | * If we were reading raw tape and the record was too long | |
567 | * or too short, then we don't consider this an error. | |
568 | */ | |
569 | if (bp == &rtsbuf[TSUNIT(bp->b_dev)] && (bp->b_flags&B_READ) && | |
570 | sc->sc_sts.s_xs0&(TS_RLS|TS_RLL)) | |
571 | goto ignoreerr; | |
572 | case TS_RECOV: /* recoverable, tape moved */ | |
573 | /* | |
574 | * If this was an i/o operation retry up to 8 times. | |
575 | */ | |
576 | if (state==SIO) { | |
577 | if (++um->um_tab.b_errcnt < 7) { | |
578 | ubadone(um); | |
579 | goto opcont; | |
580 | } else | |
581 | sc->sc_blkno++; | |
582 | } else { | |
583 | /* | |
584 | * Non-i/o errors on non-raw tape | |
585 | * cause it to close. | |
586 | */ | |
587 | if (sc->sc_openf>0 && bp != &rtsbuf[TSUNIT(bp->b_dev)]) | |
588 | sc->sc_openf = -1; | |
589 | } | |
9bad5ea5 | 590 | break; |
30a7bcbf BJ |
591 | |
592 | case TS_REJECT: /* function reject */ | |
593 | if (state == SIO && sc->sc_sts.s_xs0 & TS_WLE) | |
594 | printf("ts%d: write locked\n", TSUNIT(bp->b_dev)); | |
595 | if ((sc->sc_sts.s_xs0 & TS_ONL) == 0) | |
596 | printf("ts%d: offline\n", TSUNIT(bp->b_dev)); | |
9bad5ea5 BJ |
597 | break; |
598 | } | |
30a7bcbf BJ |
599 | /* |
600 | * Couldn't recover error | |
601 | */ | |
ead7d8e1 | 602 | printf("ts%d: hard error bn%d xs0=%b", TSUNIT(bp->b_dev), |
30a7bcbf | 603 | bp->b_blkno, sc->sc_sts.s_xs0, TSXS0_BITS); |
ead7d8e1 BJ |
604 | if (sc->sc_sts.s_xs1) |
605 | printf(" xs1=%b", sc->sc_sts.s_xs1, TSXS1_BITS); | |
606 | if (sc->sc_sts.s_xs2) | |
607 | printf(" xs2=%b", sc->sc_sts.s_xs2, TSXS2_BITS); | |
608 | if (sc->sc_sts.s_xs3) | |
609 | printf(" xs3=%b", sc->sc_sts.s_xs3, TSXS3_BITS); | |
610 | printf("\n"); | |
30a7bcbf BJ |
611 | bp->b_flags |= B_ERROR; |
612 | goto opdone; | |
9bad5ea5 | 613 | } |
30a7bcbf BJ |
614 | /* |
615 | * Advance tape control FSM. | |
616 | */ | |
617 | ignoreerr: | |
618 | switch (state) { | |
619 | ||
9bad5ea5 | 620 | case SIO: |
30a7bcbf BJ |
621 | /* |
622 | * Read/write increments tape block number | |
623 | */ | |
624 | sc->sc_blkno++; | |
625 | goto opdone; | |
626 | ||
9bad5ea5 | 627 | case SCOM: |
30a7bcbf BJ |
628 | /* |
629 | * For forward/backward space record update current position. | |
630 | */ | |
631 | if (bp == &ctsbuf[TSUNIT(bp->b_dev)]) | |
632 | switch (bp->b_command) { | |
633 | ||
634 | case TS_SFORW: | |
635 | sc->sc_blkno += bp->b_repcnt; | |
636 | break; | |
9bad5ea5 | 637 | |
30a7bcbf BJ |
638 | case TS_SREV: |
639 | sc->sc_blkno -= bp->b_repcnt; | |
640 | break; | |
641 | } | |
642 | goto opdone; | |
643 | ||
644 | case SSEEK: | |
fb739082 | 645 | sc->sc_blkno = bdbtofsb(bp->b_blkno); |
30a7bcbf | 646 | goto opcont; |
9bad5ea5 BJ |
647 | |
648 | default: | |
30a7bcbf | 649 | panic("tsintr"); |
9bad5ea5 | 650 | } |
30a7bcbf BJ |
651 | opdone: |
652 | /* | |
653 | * Reset error count and remove | |
654 | * from device queue. | |
655 | */ | |
656 | um->um_tab.b_errcnt = 0; | |
30e0abb3 | 657 | um->um_tab.b_actf->b_actf = bp->av_forw; |
30a7bcbf BJ |
658 | bp->b_resid = sc->sc_sts.s_rbpcr; |
659 | ubadone(um); | |
660 | iodone(bp); | |
30e0abb3 | 661 | if (um->um_tab.b_actf->b_actf == 0) |
30a7bcbf BJ |
662 | return; |
663 | opcont: | |
664 | tsstart(um); | |
665 | } | |
666 | ||
667 | tsseteof(bp) | |
668 | register struct buf *bp; | |
669 | { | |
670 | register int tsunit = TSUNIT(bp->b_dev); | |
671 | register struct ts_softc *sc = &ts_softc[tsunit]; | |
672 | ||
673 | if (bp == &ctsbuf[TSUNIT(bp->b_dev)]) { | |
fb739082 | 674 | if (sc->sc_blkno > bdbtofsb(bp->b_blkno)) { |
30a7bcbf | 675 | /* reversing */ |
fb739082 | 676 | sc->sc_nxrec = bdbtofsb(bp->b_blkno) - sc->sc_sts.s_rbpcr; |
30a7bcbf BJ |
677 | sc->sc_blkno = sc->sc_nxrec; |
678 | } else { | |
679 | /* spacing forward */ | |
fb739082 | 680 | sc->sc_blkno = bdbtofsb(bp->b_blkno) + sc->sc_sts.s_rbpcr; |
30a7bcbf | 681 | sc->sc_nxrec = sc->sc_blkno - 1; |
9bad5ea5 | 682 | } |
30a7bcbf BJ |
683 | return; |
684 | } | |
685 | /* eof on read */ | |
fb739082 | 686 | sc->sc_nxrec = bdbtofsb(bp->b_blkno); |
9bad5ea5 BJ |
687 | } |
688 | ||
740e4029 | 689 | tsread(dev, uio) |
30a7bcbf | 690 | dev_t dev; |
740e4029 | 691 | struct uio *uio; |
9bad5ea5 | 692 | { |
0cd5eac7 | 693 | int errno; |
30a7bcbf | 694 | |
0cd5eac7 BJ |
695 | errno = tsphys(dev, uio); |
696 | if (errno) | |
697 | return (errno); | |
698 | return (physio(tsstrategy, &rtsbuf[TSUNIT(dev)], dev, B_READ, minphys, uio)); | |
9bad5ea5 BJ |
699 | } |
700 | ||
406ddcbe | 701 | tswrite(dev, uio) |
30a7bcbf | 702 | dev_t dev; |
406ddcbe | 703 | struct uio *uio; |
9bad5ea5 | 704 | { |
0cd5eac7 | 705 | int errno; |
30a7bcbf | 706 | |
0cd5eac7 BJ |
707 | errno = tsphys(dev, uio); |
708 | if (errno) | |
709 | return (errno); | |
710 | return (physio(tsstrategy, &rtsbuf[TSUNIT(dev)], dev, B_WRITE, minphys, uio)); | |
9bad5ea5 BJ |
711 | } |
712 | ||
30a7bcbf BJ |
713 | /* |
714 | * Check that a raw device exists. | |
715 | * If it does, set up sc_blkno and sc_nxrec | |
716 | * so that the tape will appear positioned correctly. | |
717 | */ | |
740e4029 | 718 | tsphys(dev, uio) |
30a7bcbf | 719 | dev_t dev; |
740e4029 | 720 | struct uio *uio; |
9bad5ea5 | 721 | { |
30a7bcbf BJ |
722 | register int tsunit = TSUNIT(dev); |
723 | register daddr_t a; | |
724 | register struct ts_softc *sc; | |
725 | register struct uba_device *ui; | |
9bad5ea5 | 726 | |
406ddcbe | 727 | if (tsunit >= NTS || (ui=tsdinfo[tsunit]) == 0 || ui->ui_alive == 0) |
740e4029 | 728 | return (ENXIO); |
30a7bcbf | 729 | sc = &ts_softc[tsunit]; |
406ddcbe | 730 | a = bdbtofsb(uio->uio_offset >> 9); |
30a7bcbf BJ |
731 | sc->sc_blkno = a; |
732 | sc->sc_nxrec = a + 1; | |
740e4029 | 733 | return (0); |
9bad5ea5 | 734 | } |
f0a3ddbd | 735 | |
30a7bcbf BJ |
736 | tsreset(uban) |
737 | int uban; | |
f0a3ddbd | 738 | { |
30a7bcbf | 739 | register struct uba_ctlr *um; |
a870f835 BJ |
740 | register struct uba_device *ui; |
741 | register struct buf *dp; | |
30a7bcbf | 742 | register ts11; |
30a7bcbf BJ |
743 | |
744 | for (ts11 = 0; ts11 < NTS; ts11++) { | |
745 | if ((um = tsminfo[ts11]) == 0 || um->um_alive == 0 || | |
746 | um->um_ubanum != uban) | |
747 | continue; | |
748 | printf(" ts%d", ts11); | |
749 | um->um_tab.b_active = 0; | |
750 | um->um_tab.b_actf = um->um_tab.b_actl = 0; | |
a870f835 BJ |
751 | if (ts_softc[ts11].sc_openf > 0) |
752 | ts_softc[ts11].sc_openf = -1; | |
30a7bcbf BJ |
753 | if (um->um_ubinfo) { |
754 | printf("<%d>", (um->um_ubinfo>>28)&0xf); | |
96b997eb | 755 | um->um_ubinfo = 0; |
30a7bcbf | 756 | } |
a870f835 BJ |
757 | if ((ui = tsdinfo[ts11]) && ui->ui_mi == um && ui->ui_alive) { |
758 | dp = &tsutab[ts11]; | |
759 | dp->b_active = 0; | |
760 | dp->b_forw = 0; | |
761 | if (um->um_tab.b_actf == NULL) | |
762 | um->um_tab.b_actf = dp; | |
763 | else | |
764 | um->um_tab.b_actl->b_forw = dp; | |
765 | um->um_tab.b_actl = dp; | |
766 | } | |
b620b354 | 767 | (void) tsinit(ts11); |
30a7bcbf | 768 | tsstart(um); |
f0a3ddbd | 769 | } |
f0a3ddbd BJ |
770 | } |
771 | ||
30a7bcbf | 772 | /*ARGSUSED*/ |
942f05a9 SL |
773 | tsioctl(dev, cmd, data, flag) |
774 | caddr_t data; | |
30a7bcbf | 775 | dev_t dev; |
f0a3ddbd | 776 | { |
30a7bcbf BJ |
777 | int tsunit = TSUNIT(dev); |
778 | register struct ts_softc *sc = &ts_softc[tsunit]; | |
779 | register struct buf *bp = &ctsbuf[TSUNIT(dev)]; | |
780 | register callcount; | |
781 | int fcount; | |
942f05a9 SL |
782 | struct mtop *mtop; |
783 | struct mtget *mtget; | |
30a7bcbf BJ |
784 | /* we depend of the values and order of the MT codes here */ |
785 | static tsops[] = | |
b56f55c7 | 786 | {TS_WEOF,TS_SFORWF,TS_SREVF,TS_SFORW,TS_SREV,TS_REW,TS_OFFL,TS_SENSE}; |
30a7bcbf BJ |
787 | |
788 | switch (cmd) { | |
942f05a9 | 789 | |
30a7bcbf | 790 | case MTIOCTOP: /* tape operation */ |
942f05a9 | 791 | mtop = (struct mtop *)data; |
7da157da | 792 | switch (mtop->mt_op) { |
942f05a9 | 793 | |
30a7bcbf | 794 | case MTWEOF: |
942f05a9 | 795 | callcount = mtop->mt_count; |
30a7bcbf BJ |
796 | fcount = 1; |
797 | break; | |
942f05a9 | 798 | |
30a7bcbf BJ |
799 | case MTFSF: case MTBSF: |
800 | case MTFSR: case MTBSR: | |
801 | callcount = 1; | |
942f05a9 | 802 | fcount = mtop->mt_count; |
30a7bcbf | 803 | break; |
942f05a9 | 804 | |
30a7bcbf BJ |
805 | case MTREW: case MTOFFL: case MTNOP: |
806 | callcount = 1; | |
807 | fcount = 1; | |
808 | break; | |
942f05a9 | 809 | |
30a7bcbf | 810 | default: |
7da157da | 811 | return (ENXIO); |
30a7bcbf | 812 | } |
7da157da BJ |
813 | if (callcount <= 0 || fcount <= 0) |
814 | return (EINVAL); | |
30a7bcbf | 815 | while (--callcount >= 0) { |
942f05a9 SL |
816 | tscommand(dev, tsops[mtop->mt_op], fcount); |
817 | if ((mtop->mt_op == MTFSR || mtop->mt_op == MTBSR) && | |
bc3a8383 | 818 | bp->b_resid) |
7da157da | 819 | return (EIO); |
30a7bcbf BJ |
820 | if ((bp->b_flags&B_ERROR) || sc->sc_sts.s_xs0&TS_BOT) |
821 | break; | |
822 | } | |
a1edc12b | 823 | return (geterror(bp)); |
942f05a9 | 824 | |
30a7bcbf | 825 | case MTIOCGET: |
942f05a9 SL |
826 | mtget = (struct mtget *)data; |
827 | mtget->mt_dsreg = 0; | |
828 | mtget->mt_erreg = sc->sc_sts.s_xs0; | |
829 | mtget->mt_resid = sc->sc_resid; | |
830 | mtget->mt_type = MT_ISTS; | |
7da157da | 831 | break; |
942f05a9 | 832 | |
30a7bcbf | 833 | default: |
7da157da | 834 | return (ENXIO); |
30a7bcbf | 835 | } |
7da157da | 836 | return (0); |
f0a3ddbd BJ |
837 | } |
838 | ||
30a7bcbf | 839 | #define DBSIZE 20 |
f0a3ddbd | 840 | |
30a7bcbf BJ |
841 | tsdump() |
842 | { | |
843 | register struct uba_device *ui; | |
844 | register struct uba_regs *up; | |
a870f835 | 845 | register struct tsdevice *addr; |
30a7bcbf BJ |
846 | int blk, num; |
847 | int start; | |
848 | ||
849 | start = 0; | |
850 | num = maxfree; | |
851 | #define phys(a,b) ((b)((int)(a)&0x7fffffff)) | |
852 | if (tsdinfo[0] == 0) | |
853 | return (ENXIO); | |
854 | ui = phys(tsdinfo[0], struct uba_device *); | |
855 | up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba; | |
6e7edb25 | 856 | ubainit(up); |
30a7bcbf | 857 | DELAY(1000000); |
a870f835 | 858 | addr = (struct tsdevice *)ui->ui_physaddr; |
30a7bcbf BJ |
859 | addr->tssr = 0; |
860 | tswait(addr); | |
861 | while (num > 0) { | |
862 | blk = num > DBSIZE ? DBSIZE : num; | |
863 | tsdwrite(start, blk, addr, up); | |
864 | start += blk; | |
865 | num -= blk; | |
866 | } | |
867 | tseof(addr); | |
868 | tseof(addr); | |
869 | tswait(addr); | |
870 | if (addr->tssr&TS_SC) | |
871 | return (EIO); | |
872 | addr->tssr = 0; | |
873 | tswait(addr); | |
874 | return (0); | |
f0a3ddbd BJ |
875 | } |
876 | ||
30a7bcbf | 877 | tsdwrite(dbuf, num, addr, up) |
a1edc12b | 878 | register int dbuf, num; |
a870f835 | 879 | register struct tsdevice *addr; |
30a7bcbf | 880 | struct uba_regs *up; |
f0a3ddbd | 881 | { |
30a7bcbf BJ |
882 | register struct pte *io; |
883 | register int npf; | |
884 | ||
885 | tswait(addr); | |
886 | io = up->uba_map; | |
887 | npf = num+1; | |
888 | while (--npf != 0) | |
889 | *(int *)io++ = (dbuf++ | (1<<UBAMR_DPSHIFT) | UBAMR_MRV); | |
890 | *(int *)io = 0; | |
891 | #ifdef notyet | |
892 | addr->tsbc = -(num*NBPG); | |
893 | addr->tsba = 0; | |
894 | addr->tscs = TS_WCOM | TM_GO; | |
895 | #endif | |
f0a3ddbd BJ |
896 | } |
897 | ||
30a7bcbf | 898 | tswait(addr) |
a870f835 | 899 | register struct tsdevice *addr; |
f0a3ddbd | 900 | { |
30a7bcbf | 901 | register s; |
f0a3ddbd | 902 | |
30a7bcbf BJ |
903 | do |
904 | s = addr->tssr; | |
905 | while ((s & TS_SSR) == 0); | |
f0a3ddbd BJ |
906 | } |
907 | ||
30a7bcbf | 908 | tseof(addr) |
a870f835 | 909 | struct tsdevice *addr; |
f0a3ddbd | 910 | { |
30a7bcbf BJ |
911 | |
912 | tswait(addr); | |
913 | #ifdef notyet | |
914 | addr->tscs = TS_WEOF | TM_GO; | |
915 | #endif | |
f0a3ddbd | 916 | } |
9bad5ea5 | 917 | #endif |