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