Annotation of 41BSD/4.0.upgrade/sys/dev/ts.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.