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