Commit | Line | Data |
---|---|---|
afa0df56 | 1 | /* tm.c 4.43 81/11/10 */ |
d75e5c3e | 2 | |
443c8066 | 3 | #include "te.h" |
23e0e9b8 | 4 | #include "ts.h" |
afb907f2 | 5 | #if NTM > 0 |
d75e5c3e | 6 | /* |
afb907f2 | 7 | * TM11/TE10 tape driver |
7e00c42b | 8 | * |
d565635a BJ |
9 | * TODO: |
10 | * test driver with more than one slave | |
11 | * test driver with more than one controller | |
12 | * test reset code | |
d565635a BJ |
13 | * what happens if you offline tape during rewind? |
14 | * test using file system on tape | |
d75e5c3e | 15 | */ |
d75e5c3e | 16 | #include "../h/param.h" |
27a897a2 | 17 | #include "../h/systm.h" |
d75e5c3e BJ |
18 | #include "../h/buf.h" |
19 | #include "../h/dir.h" | |
20 | #include "../h/conf.h" | |
21 | #include "../h/user.h" | |
22 | #include "../h/file.h" | |
23 | #include "../h/map.h" | |
24 | #include "../h/pte.h" | |
e4271c68 | 25 | #include "../h/vm.h" |
89bd2f01 BJ |
26 | #include "../h/ubareg.h" |
27 | #include "../h/ubavar.h" | |
d75e5c3e BJ |
28 | #include "../h/mtio.h" |
29 | #include "../h/ioctl.h" | |
7455bf3e | 30 | #include "../h/cmap.h" |
3f3a34c3 | 31 | #include "../h/cpu.h" |
d75e5c3e | 32 | |
3f3a34c3 | 33 | #include "../h/tmreg.h" |
d75e5c3e | 34 | |
d565635a BJ |
35 | /* |
36 | * There is a ctmbuf per tape controller. | |
37 | * It is used as the token to pass to the internal routines | |
38 | * to execute tape ioctls, and also acts as a lock on the slaves | |
39 | * on the controller, since there is only one per controller. | |
40 | * In particular, when the tape is rewinding on close we release | |
41 | * the user process but any further attempts to use the tape drive | |
42 | * before the rewind completes will hang waiting for ctmbuf. | |
43 | */ | |
44 | struct buf ctmbuf[NTM]; | |
45 | ||
46 | /* | |
47 | * Raw tape operations use rtmbuf. The driver | |
48 | * notices when rtmbuf is being used and allows the user | |
49 | * program to continue after errors and read records | |
50 | * not of the standard length (BSIZE). | |
51 | */ | |
52 | struct buf rtmbuf[NTM]; | |
d75e5c3e | 53 | |
d565635a BJ |
54 | /* |
55 | * Driver unibus interface routines and variables. | |
56 | */ | |
71236e46 | 57 | int tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr(); |
89bd2f01 | 58 | struct uba_ctlr *tmminfo[NTM]; |
d565635a BJ |
59 | struct uba_device *tedinfo[NTE]; |
60 | struct buf teutab[NTE]; | |
61 | short tetotm[NTE]; | |
d763a2b7 | 62 | u_short tmstd[] = { 0772520, 0 }; |
3f3a34c3 | 63 | struct uba_driver tmdriver = |
d565635a | 64 | { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tedinfo, "tm", tmminfo, 0 }; |
d75e5c3e BJ |
65 | |
66 | /* bits in minor device */ | |
d565635a BJ |
67 | #define TEUNIT(dev) (minor(dev)&03) |
68 | #define TMUNIT(dev) (tetotm[TEUNIT(dev)]) | |
d75e5c3e BJ |
69 | #define T_NOREWIND 04 |
70 | #define T_1600BPI 08 | |
71 | ||
72 | #define INF (daddr_t)1000000L | |
73 | ||
71236e46 BJ |
74 | /* |
75 | * Software state per tape transport. | |
d565635a BJ |
76 | * |
77 | * 1. A tape drive is a unique-open device; we refuse opens when it is already. | |
78 | * 2. We keep track of the current position on a block tape and seek | |
79 | * before operations by forward/back spacing if necessary. | |
80 | * 3. We remember if the last operation was a write on a tape, so if a tape | |
81 | * is open read write and the last thing done is a write we can | |
82 | * write a standard end of tape mark (two eofs). | |
83 | * 4. We remember the status registers after the last command, using | |
84 | * then internally and returning them to the SENSE ioctl. | |
85 | * 5. We remember the last density the tape was used at. If it is | |
86 | * not a BOT when we start using it and we are writing, we don't | |
87 | * let the density be changed. | |
71236e46 | 88 | */ |
d565635a | 89 | struct te_softc { |
71236e46 BJ |
90 | char sc_openf; /* lock against multiple opens */ |
91 | char sc_lastiow; /* last op was a write */ | |
92 | daddr_t sc_blkno; /* block number, for block device tape */ | |
d565635a | 93 | daddr_t sc_nxrec; /* position of end of tape, if known */ |
71236e46 BJ |
94 | u_short sc_erreg; /* copy of last erreg */ |
95 | u_short sc_dsreg; /* copy of last dsreg */ | |
96 | short sc_resid; /* copy of last bc */ | |
a0eab615 | 97 | #ifdef unneeded |
d1330646 | 98 | short sc_lastcmd; /* last command to handle direction changes */ |
80905075 | 99 | #endif |
d565635a | 100 | u_short sc_dens; /* prototype command with density info */ |
a752fee0 BJ |
101 | daddr_t sc_timo; /* time until timeout expires */ |
102 | short sc_tact; /* timeout is active */ | |
d565635a | 103 | } te_softc[NTM]; |
a0eab615 BJ |
104 | #ifdef unneeded |
105 | int tmgapsdcnt; /* DEBUG */ | |
106 | #endif | |
d75e5c3e | 107 | |
71236e46 | 108 | /* |
d565635a BJ |
109 | * States for um->um_tab.b_active, the per controller state flag. |
110 | * This is used to sequence control in the driver. | |
71236e46 | 111 | */ |
d75e5c3e BJ |
112 | #define SSEEK 1 /* seeking */ |
113 | #define SIO 2 /* doing seq i/o */ | |
114 | #define SCOM 3 /* sending control command */ | |
71236e46 | 115 | #define SREW 4 /* sending a drive rewind */ |
d75e5c3e | 116 | |
23e0e9b8 BJ |
117 | #if NTS > 0 |
118 | /* | |
119 | * Kludge to get around fact that we don't really | |
120 | * check if a ts is there... if there are both tm's and ts's | |
121 | * declared in the system, then this driver sets havetm to 1 | |
122 | * if it finds a tm, and ts just pretends there isn't a ts. | |
123 | */ | |
124 | int havetm = 0; | |
125 | #endif | |
5aa9d5ea RE |
126 | /* |
127 | * Determine if there is a controller for | |
128 | * a tm at address reg. Our goal is to make the | |
129 | * device interrupt. | |
5aa9d5ea | 130 | */ |
71236e46 | 131 | tmprobe(reg) |
3f3a34c3 BJ |
132 | caddr_t reg; |
133 | { | |
d565635a | 134 | register int br, cvec; /* must be r11,r10; value-result */ |
5aa9d5ea | 135 | |
71236e46 | 136 | #ifdef lint |
a0eab615 | 137 | br = 0; cvec = br; br = cvec; |
71236e46 BJ |
138 | #endif |
139 | ((struct device *)reg)->tmcs = TM_IE; | |
3f3a34c3 | 140 | /* |
afb907f2 | 141 | * If this is a tm11, it ought to have interrupted |
3f3a34c3 | 142 | * by now, if it isn't (ie: it is a ts04) then we just |
d763a2b7 BJ |
143 | * hope that it didn't interrupt, so autoconf will ignore it. |
144 | * Just in case, we will reference one | |
3f3a34c3 | 145 | * of the more distant registers, and hope for a machine |
d763a2b7 | 146 | * check, or similar disaster if this is a ts. |
7e00c42b BJ |
147 | * |
148 | * Note: on an 11/780, badaddr will just generate | |
149 | * a uba error for a ts; but our caller will notice that | |
150 | * so we won't check for it. | |
3f3a34c3 | 151 | */ |
a0eab615 | 152 | if (badaddr((caddr_t)&((struct device *)reg)->tmrd, 2)) |
d763a2b7 BJ |
153 | return (0); |
154 | return (1); | |
3f3a34c3 BJ |
155 | } |
156 | ||
71236e46 BJ |
157 | /* |
158 | * Due to a design flaw, we cannot ascertain if the tape | |
159 | * exists or not unless it is on line - ie: unless a tape is | |
160 | * mounted. This is too servere a restriction to bear, | |
161 | * so all units are assumed to exist. | |
162 | */ | |
163 | /*ARGSUSED*/ | |
e4271c68 | 164 | tmslave(ui, reg) |
89bd2f01 | 165 | struct uba_device *ui; |
3f3a34c3 BJ |
166 | caddr_t reg; |
167 | { | |
d763a2b7 | 168 | |
d763a2b7 | 169 | return (1); |
3f3a34c3 BJ |
170 | } |
171 | ||
71236e46 | 172 | /* |
d565635a | 173 | * Record attachment of the unit to the controller. |
71236e46 BJ |
174 | */ |
175 | /*ARGSUSED*/ | |
176 | tmattach(ui) | |
89bd2f01 | 177 | struct uba_device *ui; |
71236e46 BJ |
178 | { |
179 | ||
23e0e9b8 BJ |
180 | #if NTS > 0 |
181 | havetm = 1; | |
182 | #endif | |
d565635a BJ |
183 | /* |
184 | * Tetotm is used in TMUNIT to index the ctmbuf and rtmbuf | |
185 | * arrays given a te unit number. | |
186 | */ | |
187 | tetotm[ui->ui_unit] = ui->ui_mi->um_ctlr; | |
71236e46 BJ |
188 | } |
189 | ||
a752fee0 | 190 | int tmtimer(); |
71236e46 BJ |
191 | /* |
192 | * Open the device. Tapes are unique open | |
193 | * devices, so we refuse if it is already open. | |
194 | * We also check that a tape is available, and | |
d565635a BJ |
195 | * don't block waiting here; if you want to wait |
196 | * for a tape you should timeout in user code. | |
71236e46 | 197 | */ |
d75e5c3e BJ |
198 | tmopen(dev, flag) |
199 | dev_t dev; | |
200 | int flag; | |
201 | { | |
d565635a | 202 | register int teunit; |
89bd2f01 | 203 | register struct uba_device *ui; |
d565635a | 204 | register struct te_softc *sc; |
971424d9 | 205 | int olddens, dens; |
d75e5c3e | 206 | |
d565635a BJ |
207 | teunit = TEUNIT(dev); |
208 | if (teunit>=NTE || (sc = &te_softc[teunit])->sc_openf || | |
209 | (ui = tedinfo[teunit]) == 0 || ui->ui_alive == 0) { | |
71236e46 | 210 | u.u_error = ENXIO; |
d75e5c3e BJ |
211 | return; |
212 | } | |
971424d9 BJ |
213 | olddens = sc->sc_dens; |
214 | dens = TM_IE | TM_GO | (ui->ui_slave << 8); | |
215 | if ((minor(dev) & T_1600BPI) == 0) | |
216 | dens |= TM_D800; | |
217 | sc->sc_dens = dens; | |
27a897a2 | 218 | get: |
71236e46 | 219 | tmcommand(dev, TM_SENSE, 1); |
27a897a2 BJ |
220 | if (sc->sc_erreg&TMER_SDWN) { |
221 | sleep((caddr_t)&lbolt, PZERO+1); | |
222 | goto get; | |
223 | } | |
971424d9 | 224 | sc->sc_dens = olddens; |
a1706887 BJ |
225 | if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR)) { |
226 | uprintf("te%d: not online\n", teunit); | |
227 | u.u_error = EIO; | |
228 | return; | |
229 | } | |
230 | if ((flag&FWRITE) && (sc->sc_erreg&TMER_WRL)) { | |
231 | uprintf("te%d: no write ring\n", teunit); | |
232 | u.u_error = EIO; | |
233 | return; | |
234 | } | |
235 | if ((sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) && | |
236 | dens != sc->sc_dens) { | |
237 | uprintf("te%d: can't change density in mid-tape\n", teunit); | |
71236e46 | 238 | u.u_error = EIO; |
d75e5c3e BJ |
239 | return; |
240 | } | |
71236e46 | 241 | sc->sc_openf = 1; |
7e00c42b BJ |
242 | sc->sc_blkno = (daddr_t)0; |
243 | sc->sc_nxrec = INF; | |
71236e46 | 244 | sc->sc_lastiow = 0; |
d565635a | 245 | sc->sc_dens = dens; |
a752fee0 BJ |
246 | (void) spl6(); |
247 | if (sc->sc_tact == 0) { | |
248 | sc->sc_timo = INF; | |
249 | sc->sc_tact = 1; | |
c27ba986 | 250 | timeout(tmtimer, (caddr_t)dev, 5*hz); |
a752fee0 BJ |
251 | } |
252 | (void) spl0(); | |
d75e5c3e BJ |
253 | } |
254 | ||
71236e46 BJ |
255 | /* |
256 | * Close tape device. | |
257 | * | |
258 | * If tape was open for writing or last operation was | |
259 | * a write, then write two EOF's and backspace over the last one. | |
260 | * Unless this is a non-rewinding special file, rewind the tape. | |
261 | * Make the tape available to others. | |
262 | */ | |
d75e5c3e BJ |
263 | tmclose(dev, flag) |
264 | register dev_t dev; | |
265 | register flag; | |
266 | { | |
d565635a | 267 | register struct te_softc *sc = &te_softc[TEUNIT(dev)]; |
d75e5c3e | 268 | |
71236e46 BJ |
269 | if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) { |
270 | tmcommand(dev, TM_WEOF, 1); | |
271 | tmcommand(dev, TM_WEOF, 1); | |
272 | tmcommand(dev, TM_SREV, 1); | |
d75e5c3e BJ |
273 | } |
274 | if ((minor(dev)&T_NOREWIND) == 0) | |
d565635a BJ |
275 | /* |
276 | * 0 count means don't hang waiting for rewind complete | |
277 | * rather ctmbuf stays busy until the operation completes | |
278 | * preventing further opens from completing by | |
279 | * preventing a TM_SENSE from completing. | |
280 | */ | |
281 | tmcommand(dev, TM_REW, 0); | |
7e00c42b | 282 | sc->sc_openf = 0; |
d75e5c3e BJ |
283 | } |
284 | ||
71236e46 BJ |
285 | /* |
286 | * Execute a command on the tape drive | |
287 | * a specified number of times. | |
288 | */ | |
e4271c68 | 289 | tmcommand(dev, com, count) |
d75e5c3e BJ |
290 | dev_t dev; |
291 | int com, count; | |
292 | { | |
293 | register struct buf *bp; | |
294 | ||
71236e46 | 295 | bp = &ctmbuf[TMUNIT(dev)]; |
d75e5c3e BJ |
296 | (void) spl5(); |
297 | while (bp->b_flags&B_BUSY) { | |
d565635a BJ |
298 | /* |
299 | * This special check is because B_BUSY never | |
300 | * gets cleared in the non-waiting rewind case. | |
301 | */ | |
27a897a2 | 302 | if (bp->b_repcnt == 0 && (bp->b_flags&B_DONE)) |
d565635a | 303 | break; |
d75e5c3e BJ |
304 | bp->b_flags |= B_WANTED; |
305 | sleep((caddr_t)bp, PRIBIO); | |
306 | } | |
307 | bp->b_flags = B_BUSY|B_READ; | |
308 | (void) spl0(); | |
309 | bp->b_dev = dev; | |
310 | bp->b_repcnt = -count; | |
311 | bp->b_command = com; | |
312 | bp->b_blkno = 0; | |
313 | tmstrategy(bp); | |
d565635a BJ |
314 | /* |
315 | * In case of rewind from close, don't wait. | |
316 | * This is the only case where count can be 0. | |
317 | */ | |
318 | if (count == 0) | |
319 | return; | |
d75e5c3e BJ |
320 | iowait(bp); |
321 | if (bp->b_flags&B_WANTED) | |
322 | wakeup((caddr_t)bp); | |
323 | bp->b_flags &= B_ERROR; | |
324 | } | |
325 | ||
71236e46 | 326 | /* |
d565635a | 327 | * Queue a tape operation. |
71236e46 | 328 | */ |
d75e5c3e BJ |
329 | tmstrategy(bp) |
330 | register struct buf *bp; | |
331 | { | |
d565635a | 332 | int teunit = TEUNIT(bp->b_dev); |
89bd2f01 | 333 | register struct uba_ctlr *um; |
71236e46 | 334 | register struct buf *dp; |
d75e5c3e | 335 | |
71236e46 BJ |
336 | /* |
337 | * Put transfer at end of unit queue | |
338 | */ | |
d565635a | 339 | dp = &teutab[teunit]; |
d75e5c3e BJ |
340 | bp->av_forw = NULL; |
341 | (void) spl5(); | |
06e2c4fb | 342 | um = tedinfo[teunit]->ui_mi; |
71236e46 BJ |
343 | if (dp->b_actf == NULL) { |
344 | dp->b_actf = bp; | |
345 | /* | |
346 | * Transport not already active... | |
347 | * put at end of controller queue. | |
348 | */ | |
349 | dp->b_forw = NULL; | |
71236e46 BJ |
350 | if (um->um_tab.b_actf == NULL) |
351 | um->um_tab.b_actf = dp; | |
352 | else | |
353 | um->um_tab.b_actl->b_forw = dp; | |
354 | um->um_tab.b_actl = dp; | |
355 | } else | |
356 | dp->b_actl->av_forw = bp; | |
357 | dp->b_actl = bp; | |
358 | /* | |
359 | * If the controller is not busy, get | |
360 | * it going. | |
361 | */ | |
362 | if (um->um_tab.b_active == 0) | |
363 | tmstart(um); | |
d75e5c3e BJ |
364 | (void) spl0(); |
365 | } | |
366 | ||
71236e46 BJ |
367 | /* |
368 | * Start activity on a tm controller. | |
369 | */ | |
370 | tmstart(um) | |
89bd2f01 | 371 | register struct uba_ctlr *um; |
d75e5c3e | 372 | { |
71236e46 BJ |
373 | register struct buf *bp, *dp; |
374 | register struct device *addr = (struct device *)um->um_addr; | |
d565635a | 375 | register struct te_softc *sc; |
89bd2f01 | 376 | register struct uba_device *ui; |
d565635a | 377 | int teunit, cmd; |
7e00c42b | 378 | daddr_t blkno; |
d75e5c3e | 379 | |
71236e46 BJ |
380 | /* |
381 | * Look for an idle transport on the controller. | |
382 | */ | |
d75e5c3e | 383 | loop: |
71236e46 | 384 | if ((dp = um->um_tab.b_actf) == NULL) |
d75e5c3e | 385 | return; |
71236e46 BJ |
386 | if ((bp = dp->b_actf) == NULL) { |
387 | um->um_tab.b_actf = dp->b_forw; | |
388 | goto loop; | |
389 | } | |
d565635a BJ |
390 | teunit = TEUNIT(bp->b_dev); |
391 | ui = tedinfo[teunit]; | |
71236e46 BJ |
392 | /* |
393 | * Record pre-transfer status (e.g. for TM_SENSE) | |
394 | */ | |
d565635a | 395 | sc = &te_softc[teunit]; |
71236e46 BJ |
396 | addr = (struct device *)um->um_addr; |
397 | addr->tmcs = (ui->ui_slave << 8); | |
7e00c42b BJ |
398 | sc->sc_dsreg = addr->tmcs; |
399 | sc->sc_erreg = addr->tmer; | |
400 | sc->sc_resid = addr->tmbc; | |
71236e46 BJ |
401 | /* |
402 | * Default is that last command was NOT a write command; | |
403 | * if we do a write command we will notice this in tmintr(). | |
404 | */ | |
bc9da2ca | 405 | sc->sc_lastiow = 0; |
71236e46 BJ |
406 | if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) { |
407 | /* | |
d565635a BJ |
408 | * Have had a hard error on a non-raw tape |
409 | * or the tape unit is now unavailable | |
410 | * (e.g. taken off line). | |
71236e46 BJ |
411 | */ |
412 | bp->b_flags |= B_ERROR; | |
d75e5c3e BJ |
413 | goto next; |
414 | } | |
d565635a BJ |
415 | if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) { |
416 | /* | |
417 | * Execute control operation with the specified count. | |
418 | */ | |
71236e46 BJ |
419 | if (bp->b_command == TM_SENSE) |
420 | goto next; | |
a752fee0 BJ |
421 | /* |
422 | * Set next state; give 5 minutes to complete | |
423 | * rewind, or 10 seconds per iteration (minimum 60 | |
c27ba986 | 424 | * seconds and max 5 minutes) to complete other ops. |
a752fee0 BJ |
425 | */ |
426 | if (bp->b_command == TM_REW) { | |
427 | um->um_tab.b_active = SREW; | |
428 | sc->sc_timo = 5 * 60; | |
429 | } else { | |
430 | um->um_tab.b_active = SCOM; | |
0218811c BJ |
431 | sc->sc_timo = |
432 | imin(imax(10*(int)-bp->b_repcnt,60),5*60); | |
a752fee0 | 433 | } |
71236e46 BJ |
434 | if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV) |
435 | addr->tmbc = bp->b_repcnt; | |
d1330646 | 436 | goto dobpcmd; |
71236e46 | 437 | } |
d565635a BJ |
438 | /* |
439 | * The following checks handle boundary cases for operation | |
440 | * on non-raw tapes. On raw tapes the initialization of | |
441 | * sc->sc_nxrec by tmphys causes them to be skipped normally | |
442 | * (except in the case of retries). | |
443 | */ | |
444 | if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) { | |
445 | /* | |
446 | * Can't read past known end-of-file. | |
447 | */ | |
448 | bp->b_flags |= B_ERROR; | |
449 | bp->b_error = ENXIO; | |
450 | goto next; | |
451 | } | |
452 | if (dbtofsb(bp->b_blkno) == sc->sc_nxrec && | |
453 | bp->b_flags&B_READ) { | |
454 | /* | |
455 | * Reading at end of file returns 0 bytes. | |
456 | */ | |
457 | bp->b_resid = bp->b_bcount; | |
458 | clrbuf(bp); | |
459 | goto next; | |
460 | } | |
461 | if ((bp->b_flags&B_READ) == 0) | |
462 | /* | |
463 | * Writing sets EOF | |
464 | */ | |
465 | sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1; | |
71236e46 BJ |
466 | /* |
467 | * If the data transfer command is in the correct place, | |
468 | * set up all the registers except the csr, and give | |
469 | * control over to the UNIBUS adapter routines, to | |
470 | * wait for resources to start the i/o. | |
471 | */ | |
7e00c42b | 472 | if ((blkno = sc->sc_blkno) == dbtofsb(bp->b_blkno)) { |
3f3a34c3 | 473 | addr->tmbc = -bp->b_bcount; |
d75e5c3e | 474 | if ((bp->b_flags&B_READ) == 0) { |
7e00c42b | 475 | if (um->um_tab.b_errcnt) |
d565635a | 476 | cmd = TM_WIRG; |
d75e5c3e | 477 | else |
d565635a | 478 | cmd = TM_WCOM; |
d75e5c3e | 479 | } else |
d565635a | 480 | cmd = TM_RCOM; |
7e00c42b | 481 | um->um_tab.b_active = SIO; |
d565635a | 482 | um->um_cmd = sc->sc_dens|cmd; |
80905075 | 483 | #ifdef notdef |
d1330646 | 484 | if (tmreverseop(sc->sc_lastcmd)) |
d565635a | 485 | while (addr->tmer & TMER_SDWN) |
d1330646 | 486 | tmgapsdcnt++; |
d1330646 | 487 | sc->sc_lastcmd = TM_RCOM; /* will serve */ |
80905075 | 488 | #endif |
a752fee0 | 489 | sc->sc_timo = 60; /* premature, but should serve */ |
a0eab615 | 490 | (void) ubago(ui); |
d75e5c3e BJ |
491 | return; |
492 | } | |
71236e46 | 493 | /* |
d565635a BJ |
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. | |
71236e46 | 497 | */ |
7e00c42b | 498 | um->um_tab.b_active = SSEEK; |
d75e5c3e | 499 | if (blkno < dbtofsb(bp->b_blkno)) { |
d1330646 | 500 | bp->b_command = TM_SFORW; |
3f3a34c3 | 501 | addr->tmbc = blkno - dbtofsb(bp->b_blkno); |
d75e5c3e | 502 | } else { |
d1330646 | 503 | bp->b_command = TM_SREV; |
3f3a34c3 | 504 | addr->tmbc = dbtofsb(bp->b_blkno) - blkno; |
d75e5c3e | 505 | } |
c27ba986 | 506 | sc->sc_timo = imin(imax(10 * -addr->tmbc, 60), 5 * 60); |
d1330646 | 507 | dobpcmd: |
80905075 | 508 | #ifdef notdef |
d565635a BJ |
509 | /* |
510 | * It is strictly necessary to wait for the tape | |
511 | * to stop before changing directions, but the TC11 | |
512 | * handles this for us. | |
513 | */ | |
d1330646 BJ |
514 | if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command)) |
515 | while (addr->tmer & TM_SDWN) | |
516 | tmgapsdcnt++; | |
d1330646 | 517 | sc->sc_lastcmd = bp->b_command; |
80905075 | 518 | #endif |
d565635a BJ |
519 | /* |
520 | * Do the command in bp. | |
521 | */ | |
522 | addr->tmcs = (sc->sc_dens | bp->b_command); | |
d75e5c3e BJ |
523 | return; |
524 | ||
525 | next: | |
71236e46 BJ |
526 | /* |
527 | * Done with this operation due to error or | |
528 | * the fact that it doesn't do anything. | |
529 | * Release UBA resources (if any), dequeue | |
530 | * the transfer and continue processing this slave. | |
531 | */ | |
532 | if (um->um_ubinfo) | |
0801d37f | 533 | ubadone(um); |
71236e46 BJ |
534 | um->um_tab.b_errcnt = 0; |
535 | dp->b_actf = bp->av_forw; | |
d75e5c3e BJ |
536 | iodone(bp); |
537 | goto loop; | |
538 | } | |
539 | ||
71236e46 BJ |
540 | /* |
541 | * The UNIBUS resources we needed have been | |
542 | * allocated to us; start the device. | |
543 | */ | |
e4271c68 | 544 | tmdgo(um) |
89bd2f01 | 545 | register struct uba_ctlr *um; |
3f3a34c3 | 546 | { |
e4271c68 | 547 | register struct device *addr = (struct device *)um->um_addr; |
7e00c42b | 548 | |
e4271c68 BJ |
549 | addr->tmba = um->um_ubinfo; |
550 | addr->tmcs = um->um_cmd | ((um->um_ubinfo >> 12) & 0x30); | |
3f3a34c3 BJ |
551 | } |
552 | ||
71236e46 BJ |
553 | /* |
554 | * Tm interrupt routine. | |
555 | */ | |
7e00c42b | 556 | /*ARGSUSED*/ |
afb907f2 BJ |
557 | tmintr(tm11) |
558 | int tm11; | |
d75e5c3e | 559 | { |
71236e46 | 560 | struct buf *dp; |
d75e5c3e | 561 | register struct buf *bp; |
89bd2f01 | 562 | register struct uba_ctlr *um = tmminfo[tm11]; |
d565635a BJ |
563 | register struct device *addr; |
564 | register struct te_softc *sc; | |
565 | int teunit; | |
d75e5c3e BJ |
566 | register state; |
567 | ||
d565635a BJ |
568 | if ((dp = um->um_tab.b_actf) == NULL) |
569 | return; | |
570 | bp = dp->b_actf; | |
571 | teunit = TEUNIT(bp->b_dev); | |
572 | addr = (struct device *)tedinfo[teunit]->ui_addr; | |
6a476a42 | 573 | sc = &te_softc[teunit]; |
71236e46 BJ |
574 | /* |
575 | * If last command was a rewind, and tape is still | |
576 | * rewinding, wait for the rewind complete interrupt. | |
577 | */ | |
578 | if (um->um_tab.b_active == SREW) { | |
579 | um->um_tab.b_active = SCOM; | |
6a476a42 BJ |
580 | if (addr->tmer&TMER_RWS) { |
581 | sc->sc_timo = 5*60; /* 5 minutes */ | |
71236e46 | 582 | return; |
6a476a42 | 583 | } |
d75e5c3e | 584 | } |
71236e46 BJ |
585 | /* |
586 | * An operation completed... record status | |
587 | */ | |
a752fee0 | 588 | sc->sc_timo = INF; |
7e00c42b BJ |
589 | sc->sc_dsreg = addr->tmcs; |
590 | sc->sc_erreg = addr->tmer; | |
591 | sc->sc_resid = addr->tmbc; | |
d75e5c3e | 592 | if ((bp->b_flags & B_READ) == 0) |
71236e46 | 593 | sc->sc_lastiow = 1; |
7e00c42b BJ |
594 | state = um->um_tab.b_active; |
595 | um->um_tab.b_active = 0; | |
71236e46 BJ |
596 | /* |
597 | * Check for errors. | |
598 | */ | |
599 | if (addr->tmcs&TM_ERR) { | |
d565635a | 600 | while (addr->tmer & TMER_SDWN) |
d75e5c3e | 601 | ; /* await settle down */ |
71236e46 | 602 | /* |
d565635a | 603 | * If we hit the end of the tape file, update our position. |
71236e46 | 604 | */ |
d565635a | 605 | if (addr->tmer&TMER_EOF) { |
71236e46 BJ |
606 | tmseteof(bp); /* set blkno and nxrec */ |
607 | state = SCOM; /* force completion */ | |
608 | /* | |
609 | * Stuff bc so it will be unstuffed correctly | |
610 | * later to get resid. | |
611 | */ | |
3f3a34c3 | 612 | addr->tmbc = -bp->b_bcount; |
71236e46 | 613 | goto opdone; |
d75e5c3e | 614 | } |
71236e46 | 615 | /* |
d565635a BJ |
616 | * If we were reading raw tape and the only error was that the |
617 | * record was too long, then we don't consider this an error. | |
71236e46 | 618 | */ |
d565635a BJ |
619 | if (bp == &rtmbuf[TMUNIT(bp->b_dev)] && (bp->b_flags&B_READ) && |
620 | (addr->tmer&(TMER_HARD|TMER_SOFT)) == TMER_RLE) | |
71236e46 BJ |
621 | goto ignoreerr; |
622 | /* | |
623 | * If error is not hard, and this was an i/o operation | |
624 | * retry up to 8 times. | |
625 | */ | |
d565635a | 626 | if ((addr->tmer&TMER_HARD)==0 && state==SIO) { |
7e00c42b | 627 | if (++um->um_tab.b_errcnt < 7) { |
7e00c42b | 628 | sc->sc_blkno++; |
0801d37f | 629 | ubadone(um); |
71236e46 | 630 | goto opcont; |
d75e5c3e | 631 | } |
71236e46 BJ |
632 | } else |
633 | /* | |
634 | * Hard or non-i/o errors on non-raw tape | |
635 | * cause it to close. | |
636 | */ | |
d565635a | 637 | if (sc->sc_openf>0 && bp != &rtmbuf[TMUNIT(bp->b_dev)]) |
71236e46 BJ |
638 | sc->sc_openf = -1; |
639 | /* | |
640 | * Couldn't recover error | |
641 | */ | |
80905075 | 642 | printf("te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03, |
d565635a | 643 | bp->b_blkno, sc->sc_erreg, TMER_BITS); |
d75e5c3e | 644 | bp->b_flags |= B_ERROR; |
71236e46 | 645 | goto opdone; |
d75e5c3e | 646 | } |
71236e46 BJ |
647 | /* |
648 | * Advance tape control FSM. | |
649 | */ | |
650 | ignoreerr: | |
d75e5c3e BJ |
651 | switch (state) { |
652 | ||
653 | case SIO: | |
71236e46 BJ |
654 | /* |
655 | * Read/write increments tape block number | |
656 | */ | |
7e00c42b | 657 | sc->sc_blkno++; |
71236e46 | 658 | goto opdone; |
d75e5c3e BJ |
659 | |
660 | case SCOM: | |
71236e46 | 661 | /* |
d565635a | 662 | * For forward/backward space record update current position. |
71236e46 | 663 | */ |
d565635a | 664 | if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) |
71236e46 BJ |
665 | switch (bp->b_command) { |
666 | ||
667 | case TM_SFORW: | |
668 | sc->sc_blkno -= bp->b_repcnt; | |
d565635a | 669 | break; |
71236e46 BJ |
670 | |
671 | case TM_SREV: | |
672 | sc->sc_blkno += bp->b_repcnt; | |
d565635a | 673 | break; |
d75e5c3e | 674 | } |
d565635a | 675 | goto opdone; |
d75e5c3e BJ |
676 | |
677 | case SSEEK: | |
7e00c42b | 678 | sc->sc_blkno = dbtofsb(bp->b_blkno); |
71236e46 | 679 | goto opcont; |
d75e5c3e BJ |
680 | |
681 | default: | |
71236e46 | 682 | panic("tmintr"); |
d75e5c3e | 683 | } |
71236e46 BJ |
684 | opdone: |
685 | /* | |
686 | * Reset error count and remove | |
687 | * from device queue. | |
688 | */ | |
689 | um->um_tab.b_errcnt = 0; | |
690 | dp->b_actf = bp->av_forw; | |
691 | bp->b_resid = -addr->tmbc; | |
0801d37f | 692 | ubadone(um); |
71236e46 BJ |
693 | iodone(bp); |
694 | /* | |
695 | * Circulate slave to end of controller | |
696 | * queue to give other slaves a chance. | |
697 | */ | |
698 | um->um_tab.b_actf = dp->b_forw; | |
699 | if (dp->b_actf) { | |
700 | dp->b_forw = NULL; | |
701 | if (um->um_tab.b_actf == NULL) | |
702 | um->um_tab.b_actf = dp; | |
703 | else | |
704 | um->um_tab.b_actl->b_forw = dp; | |
705 | um->um_tab.b_actl = dp; | |
706 | } | |
707 | if (um->um_tab.b_actf == 0) | |
708 | return; | |
709 | opcont: | |
710 | tmstart(um); | |
d75e5c3e BJ |
711 | } |
712 | ||
a752fee0 BJ |
713 | tmtimer(dev) |
714 | int dev; | |
715 | { | |
716 | register struct te_softc *sc = &te_softc[TEUNIT(dev)]; | |
afa0df56 | 717 | register short x; |
a752fee0 BJ |
718 | |
719 | if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) { | |
aa4e15a3 | 720 | printf("te%d: lost interrupt\n", TEUNIT(dev)); |
a752fee0 | 721 | sc->sc_timo = INF; |
afa0df56 | 722 | x = spl5(); |
a752fee0 | 723 | tmintr(TMUNIT(dev)); |
afa0df56 | 724 | (void) splx(x); |
a752fee0 | 725 | } |
c27ba986 | 726 | timeout(tmtimer, (caddr_t)dev, 5*hz); |
a752fee0 BJ |
727 | } |
728 | ||
d75e5c3e BJ |
729 | tmseteof(bp) |
730 | register struct buf *bp; | |
731 | { | |
d565635a | 732 | register int teunit = TEUNIT(bp->b_dev); |
3f3a34c3 | 733 | register struct device *addr = |
d565635a BJ |
734 | (struct device *)tedinfo[teunit]->ui_addr; |
735 | register struct te_softc *sc = &te_softc[teunit]; | |
d75e5c3e | 736 | |
d565635a | 737 | if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) { |
7e00c42b | 738 | if (sc->sc_blkno > dbtofsb(bp->b_blkno)) { |
d75e5c3e | 739 | /* reversing */ |
7e00c42b BJ |
740 | sc->sc_nxrec = dbtofsb(bp->b_blkno) - addr->tmbc; |
741 | sc->sc_blkno = sc->sc_nxrec; | |
d75e5c3e BJ |
742 | } else { |
743 | /* spacing forward */ | |
7e00c42b BJ |
744 | sc->sc_blkno = dbtofsb(bp->b_blkno) + addr->tmbc; |
745 | sc->sc_nxrec = sc->sc_blkno - 1; | |
d75e5c3e BJ |
746 | } |
747 | return; | |
748 | } | |
749 | /* eof on read */ | |
7e00c42b | 750 | sc->sc_nxrec = dbtofsb(bp->b_blkno); |
d75e5c3e BJ |
751 | } |
752 | ||
753 | tmread(dev) | |
71236e46 | 754 | dev_t dev; |
d75e5c3e BJ |
755 | { |
756 | ||
757 | tmphys(dev); | |
89bd2f01 BJ |
758 | if (u.u_error) |
759 | return; | |
71236e46 | 760 | physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_READ, minphys); |
d75e5c3e BJ |
761 | } |
762 | ||
763 | tmwrite(dev) | |
71236e46 | 764 | dev_t dev; |
d75e5c3e BJ |
765 | { |
766 | ||
767 | tmphys(dev); | |
89bd2f01 BJ |
768 | if (u.u_error) |
769 | return; | |
71236e46 | 770 | physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_WRITE, minphys); |
d75e5c3e BJ |
771 | } |
772 | ||
d565635a BJ |
773 | /* |
774 | * Check that a raw device exists. | |
775 | * If it does, set up sc_blkno and sc_nxrec | |
776 | * so that the tape will appear positioned correctly. | |
777 | */ | |
d75e5c3e | 778 | tmphys(dev) |
71236e46 | 779 | dev_t dev; |
d75e5c3e | 780 | { |
d565635a | 781 | register int teunit = TEUNIT(dev); |
d75e5c3e | 782 | register daddr_t a; |
d565635a BJ |
783 | register struct te_softc *sc; |
784 | register struct uba_device *ui; | |
d75e5c3e | 785 | |
d565635a | 786 | if (teunit >= NTE || (ui=tedinfo[teunit]) == 0 || ui->ui_alive == 0) { |
89bd2f01 BJ |
787 | u.u_error = ENXIO; |
788 | return; | |
789 | } | |
d565635a | 790 | sc = &te_softc[teunit]; |
d75e5c3e | 791 | a = dbtofsb(u.u_offset >> 9); |
7e00c42b BJ |
792 | sc->sc_blkno = a; |
793 | sc->sc_nxrec = a + 1; | |
d75e5c3e BJ |
794 | } |
795 | ||
71236e46 BJ |
796 | tmreset(uban) |
797 | int uban; | |
798 | { | |
89bd2f01 | 799 | register struct uba_ctlr *um; |
d565635a | 800 | register tm11, teunit; |
89bd2f01 | 801 | register struct uba_device *ui; |
71236e46 BJ |
802 | register struct buf *dp; |
803 | ||
afb907f2 BJ |
804 | for (tm11 = 0; tm11 < NTM; tm11++) { |
805 | if ((um = tmminfo[tm11]) == 0 || um->um_alive == 0 || | |
71236e46 BJ |
806 | um->um_ubanum != uban) |
807 | continue; | |
80905075 | 808 | printf(" tm%d", tm11); |
71236e46 BJ |
809 | um->um_tab.b_active = 0; |
810 | um->um_tab.b_actf = um->um_tab.b_actl = 0; | |
811 | if (um->um_ubinfo) { | |
812 | printf("<%d>", (um->um_ubinfo>>28)&0xf); | |
0801d37f | 813 | ubadone(um); |
71236e46 BJ |
814 | } |
815 | ((struct device *)(um->um_addr))->tmcs = TM_DCLR; | |
d565635a BJ |
816 | for (teunit = 0; teunit < NTE; teunit++) { |
817 | if ((ui = tedinfo[teunit]) == 0 || ui->ui_mi != um || | |
818 | ui->ui_alive == 0) | |
71236e46 | 819 | continue; |
d565635a | 820 | dp = &teutab[teunit]; |
71236e46 BJ |
821 | dp->b_active = 0; |
822 | dp->b_forw = 0; | |
823 | if (um->um_tab.b_actf == NULL) | |
824 | um->um_tab.b_actf = dp; | |
825 | else | |
826 | um->um_tab.b_actl->b_forw = dp; | |
827 | um->um_tab.b_actl = dp; | |
a752fee0 BJ |
828 | if (te_softc[teunit].sc_openf > 0) |
829 | te_softc[teunit].sc_openf = -1; | |
71236e46 BJ |
830 | } |
831 | tmstart(um); | |
832 | } | |
833 | } | |
834 | ||
d75e5c3e BJ |
835 | /*ARGSUSED*/ |
836 | tmioctl(dev, cmd, addr, flag) | |
837 | caddr_t addr; | |
838 | dev_t dev; | |
839 | { | |
d565635a BJ |
840 | int teunit = TEUNIT(dev); |
841 | register struct te_softc *sc = &te_softc[teunit]; | |
842 | register struct buf *bp = &ctmbuf[TMUNIT(dev)]; | |
d75e5c3e BJ |
843 | register callcount; |
844 | int fcount; | |
845 | struct mtop mtop; | |
846 | struct mtget mtget; | |
847 | /* we depend of the values and order of the MT codes here */ | |
71236e46 BJ |
848 | static tmops[] = |
849 | {TM_WEOF,TM_SFORW,TM_SREV,TM_SFORW,TM_SREV,TM_REW,TM_OFFL,TM_SENSE}; | |
d75e5c3e | 850 | |
71236e46 | 851 | switch (cmd) { |
d75e5c3e BJ |
852 | case MTIOCTOP: /* tape operation */ |
853 | if (copyin((caddr_t)addr, (caddr_t)&mtop, sizeof(mtop))) { | |
854 | u.u_error = EFAULT; | |
855 | return; | |
856 | } | |
857 | switch(mtop.mt_op) { | |
71236e46 BJ |
858 | case MTWEOF: |
859 | callcount = mtop.mt_count; | |
860 | fcount = 1; | |
861 | break; | |
862 | case MTFSF: case MTBSF: | |
d75e5c3e BJ |
863 | callcount = mtop.mt_count; |
864 | fcount = INF; | |
865 | break; | |
866 | case MTFSR: case MTBSR: | |
867 | callcount = 1; | |
868 | fcount = mtop.mt_count; | |
869 | break; | |
77115c00 | 870 | case MTREW: case MTOFFL: case MTNOP: |
d75e5c3e BJ |
871 | callcount = 1; |
872 | fcount = 1; | |
873 | break; | |
874 | default: | |
875 | u.u_error = ENXIO; | |
876 | return; | |
877 | } | |
71236e46 | 878 | if (callcount <= 0 || fcount <= 0) { |
d75e5c3e | 879 | u.u_error = ENXIO; |
71236e46 BJ |
880 | return; |
881 | } | |
882 | while (--callcount >= 0) { | |
e4271c68 | 883 | tmcommand(dev, tmops[mtop.mt_op], fcount); |
d75e5c3e | 884 | if ((mtop.mt_op == MTFSR || mtop.mt_op == MTBSR) && |
71236e46 | 885 | bp->b_resid) { |
d75e5c3e BJ |
886 | u.u_error = EIO; |
887 | break; | |
888 | } | |
d565635a | 889 | if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TMER_BOT) |
d75e5c3e BJ |
890 | break; |
891 | } | |
71236e46 | 892 | geterror(bp); |
d75e5c3e BJ |
893 | return; |
894 | case MTIOCGET: | |
7e00c42b BJ |
895 | mtget.mt_dsreg = sc->sc_dsreg; |
896 | mtget.mt_erreg = sc->sc_erreg; | |
897 | mtget.mt_resid = sc->sc_resid; | |
65e74b33 | 898 | mtget.mt_type = MT_ISTM; |
d75e5c3e BJ |
899 | if (copyout((caddr_t)&mtget, addr, sizeof(mtget))) |
900 | u.u_error = EFAULT; | |
901 | return; | |
902 | default: | |
903 | u.u_error = ENXIO; | |
904 | } | |
905 | } | |
906 | ||
907 | #define DBSIZE 20 | |
908 | ||
7455bf3e | 909 | tmdump() |
d75e5c3e | 910 | { |
89bd2f01 | 911 | register struct uba_device *ui; |
3f3a34c3 BJ |
912 | register struct uba_regs *up; |
913 | register struct device *addr; | |
5aa9d5ea RE |
914 | int blk, num; |
915 | int start; | |
d75e5c3e | 916 | |
5aa9d5ea RE |
917 | start = 0; |
918 | num = maxfree; | |
919 | #define phys(a,b) ((b)((int)(a)&0x7fffffff)) | |
d565635a | 920 | if (tedinfo[0] == 0) |
2536c16c | 921 | return (ENXIO); |
d565635a | 922 | ui = phys(tedinfo[0], struct uba_device *); |
3f3a34c3 | 923 | up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba; |
57229699 | 924 | ubainit(up); |
77115c00 | 925 | DELAY(1000000); |
3f3a34c3 BJ |
926 | addr = (struct device *)ui->ui_physaddr; |
927 | tmwait(addr); | |
71236e46 | 928 | addr->tmcs = TM_DCLR | TM_GO; |
d75e5c3e BJ |
929 | while (num > 0) { |
930 | blk = num > DBSIZE ? DBSIZE : num; | |
3f3a34c3 | 931 | tmdwrite(start, blk, addr, up); |
d75e5c3e BJ |
932 | start += blk; |
933 | num -= blk; | |
934 | } | |
5aa9d5ea RE |
935 | tmeof(addr); |
936 | tmeof(addr); | |
7e00c42b | 937 | tmwait(addr); |
2536c16c BJ |
938 | if (addr->tmcs&TM_ERR) |
939 | return (EIO); | |
71236e46 | 940 | addr->tmcs = TM_REW | TM_GO; |
5aa9d5ea | 941 | tmwait(addr); |
7455bf3e | 942 | return (0); |
d75e5c3e BJ |
943 | } |
944 | ||
71236e46 BJ |
945 | tmdwrite(dbuf, num, addr, up) |
946 | register dbuf, num; | |
3f3a34c3 BJ |
947 | register struct device *addr; |
948 | struct uba_regs *up; | |
d75e5c3e | 949 | { |
3f3a34c3 BJ |
950 | register struct pte *io; |
951 | register int npf; | |
0a51498e | 952 | |
3f3a34c3 | 953 | tmwait(addr); |
3f3a34c3 | 954 | io = up->uba_map; |
d75e5c3e | 955 | npf = num+1; |
0a51498e | 956 | while (--npf != 0) |
89bd2f01 | 957 | *(int *)io++ = (dbuf++ | (1<<UBAMR_DPSHIFT) | UBAMR_MRV); |
3f3a34c3 BJ |
958 | *(int *)io = 0; |
959 | addr->tmbc = -(num*NBPG); | |
960 | addr->tmba = 0; | |
71236e46 | 961 | addr->tmcs = TM_WCOM | TM_GO; |
d75e5c3e BJ |
962 | } |
963 | ||
3f3a34c3 BJ |
964 | tmwait(addr) |
965 | register struct device *addr; | |
d75e5c3e | 966 | { |
0a51498e | 967 | register s; |
d75e5c3e BJ |
968 | |
969 | do | |
3f3a34c3 | 970 | s = addr->tmcs; |
71236e46 | 971 | while ((s & TM_CUR) == 0); |
d75e5c3e BJ |
972 | } |
973 | ||
3f3a34c3 BJ |
974 | tmeof(addr) |
975 | struct device *addr; | |
d75e5c3e BJ |
976 | { |
977 | ||
3f3a34c3 | 978 | tmwait(addr); |
71236e46 | 979 | addr->tmcs = TM_WEOF | TM_GO; |
d75e5c3e BJ |
980 | } |
981 | #endif |