1*2617Swnj /* tm.c 4.15 02/22/81 */ 21919Swnj 31940Swnj #include "tm.h" 42471Swnj #if NTM03 > 0 51919Swnj /* 61919Swnj * TM tape driver 72471Swnj * 82608Swnj * THIS DRIVER HAS NOT BEEN TESTED WITH MORE THAN ONE TRANSPORT. 91919Swnj */ 102471Swnj #define DELAY(N) { register int d = N; while (--d > 0); } 111919Swnj #include "../h/param.h" 121919Swnj #include "../h/buf.h" 131919Swnj #include "../h/dir.h" 141919Swnj #include "../h/conf.h" 151919Swnj #include "../h/user.h" 161919Swnj #include "../h/file.h" 171919Swnj #include "../h/map.h" 181919Swnj #include "../h/pte.h" 192574Swnj #include "../h/vm.h" 201919Swnj #include "../h/uba.h" 211919Swnj #include "../h/mtio.h" 221919Swnj #include "../h/ioctl.h" 232363Swnj #include "../h/cmap.h" 242396Swnj #include "../h/cpu.h" 251919Swnj 262396Swnj #include "../h/tmreg.h" 271919Swnj 282608Swnj struct buf ctmbuf[NTM11]; 292608Swnj struct buf rtmbuf[NTM11]; 301919Swnj 312608Swnj int tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr(); 322471Swnj struct uba_minfo *tmminfo[NTM03]; 332471Swnj struct uba_dinfo *tmdinfo[NTM11]; 342608Swnj struct buf tmutab[NTM11]; 352608Swnj #ifdef notyet 362608Swnj struct uba_dinfo *tmip[NTM03][4]; 372608Swnj #endif 382458Swnj u_short tmstd[] = { 0772520, 0 }; 392396Swnj struct uba_driver tmdriver = 402608Swnj { tmprobe, tmslave, tmattach, tmdgo, tmstd, "mtm", tmdinfo, "tm", tmminfo }; 411919Swnj 421919Swnj /* bits in minor device */ 432608Swnj #define TMUNIT(dev) (minor(dev)&03) 441919Swnj #define T_NOREWIND 04 451919Swnj #define T_1600BPI 08 461919Swnj 471919Swnj #define INF (daddr_t)1000000L 481919Swnj 492608Swnj /* 502608Swnj * Software state per tape transport. 512608Swnj */ 522471Swnj struct tm_softc { 532608Swnj char sc_openf; /* lock against multiple opens */ 542608Swnj char sc_lastiow; /* last op was a write */ 552608Swnj daddr_t sc_blkno; /* block number, for block device tape */ 562608Swnj daddr_t sc_nxrec; /* desired block position */ 572608Swnj u_short sc_erreg; /* copy of last erreg */ 582608Swnj u_short sc_dsreg; /* copy of last dsreg */ 592608Swnj short sc_resid; /* copy of last bc */ 602471Swnj } tm_softc[NTM03]; 611919Swnj 622608Swnj /* 632608Swnj * States for um->um_tab.b_active, the 642608Swnj * per controller state flag. 652608Swnj */ 661919Swnj #define SSEEK 1 /* seeking */ 671919Swnj #define SIO 2 /* doing seq i/o */ 681919Swnj #define SCOM 3 /* sending control command */ 692608Swnj #define SREW 4 /* sending a drive rewind */ 701919Swnj 712608Swnj /* WE CURRENTLY HANDLE REWINDS PRIMITIVELY, BUSYING OUT THE CONTROLLER */ 722608Swnj /* DURING THE REWIND... IF WE EVER GET TWO TRANSPORTS, WE CAN DEBUG MORE */ 732608Swnj /* SOPHISTICATED LOGIC... THIS SIMPLE CODE AT LEAST MAY WORK. */ 741919Swnj 752426Skre /* 762426Skre * Determine if there is a controller for 772426Skre * a tm at address reg. Our goal is to make the 782426Skre * device interrupt. 792426Skre */ 802608Swnj tmprobe(reg) 812396Swnj caddr_t reg; 822396Swnj { 832458Swnj register int br, cvec; 842426Skre 852608Swnj #ifdef lint 862608Swnj br = 0; br = cvec; cvec = br; 872608Swnj #endif 882608Swnj ((struct device *)reg)->tmcs = TM_IE; 892396Swnj /* 902608Swnj * If this is a tm03, it ought to have interrupted 912396Swnj * by now, if it isn't (ie: it is a ts04) then we just 922458Swnj * hope that it didn't interrupt, so autoconf will ignore it. 932458Swnj * Just in case, we will reference one 942396Swnj * of the more distant registers, and hope for a machine 952458Swnj * check, or similar disaster if this is a ts. 962471Swnj * 972471Swnj * Note: on an 11/780, badaddr will just generate 982471Swnj * a uba error for a ts; but our caller will notice that 992471Swnj * so we won't check for it. 1002396Swnj */ 1012396Swnj if (badaddr(&((struct device *)reg)->tmrd, 2)) 1022458Swnj return (0); 1032458Swnj return (1); 1042396Swnj } 1052396Swnj 1062608Swnj /* 1072608Swnj * Due to a design flaw, we cannot ascertain if the tape 1082608Swnj * exists or not unless it is on line - ie: unless a tape is 1092608Swnj * mounted. This is too servere a restriction to bear, 1102608Swnj * so all units are assumed to exist. 1112608Swnj */ 1122608Swnj /*ARGSUSED*/ 1132574Swnj tmslave(ui, reg) 1142396Swnj struct uba_dinfo *ui; 1152396Swnj caddr_t reg; 1162396Swnj { 1172458Swnj 1182458Swnj return (1); 1192396Swnj } 1202396Swnj 1212608Swnj /* 1222608Swnj * Record attachment of the unit to the controller port. 1232608Swnj */ 1242608Swnj /*ARGSUSED*/ 1252608Swnj tmattach(ui) 1262608Swnj struct uba_dinfo *ui; 1272608Swnj { 1282608Swnj 1292608Swnj #ifdef notyet 1302608Swnj tmip[ui->ui_ctlr][ui->ui_slave] = ui; 1312608Swnj #endif 1322608Swnj } 1332608Swnj 1342608Swnj /* 1352608Swnj * Open the device. Tapes are unique open 1362608Swnj * devices, so we refuse if it is already open. 1372608Swnj * We also check that a tape is available, and 1382608Swnj * don't block waiting here. 1392608Swnj */ 1401919Swnj tmopen(dev, flag) 1411919Swnj dev_t dev; 1421919Swnj int flag; 1431919Swnj { 1442608Swnj register int unit; 1452396Swnj register struct uba_dinfo *ui; 1462608Swnj register struct tm_softc *sc; 1471919Swnj 1482608Swnj unit = TMUNIT(dev); 1492608Swnj if (unit>=NTM11 || (sc = &tm_softc[unit])->sc_openf || 1502608Swnj (ui = tmdinfo[unit]) == 0 || ui->ui_alive == 0) { 1512608Swnj u.u_error = ENXIO; 1521919Swnj return; 1531919Swnj } 1542608Swnj tmcommand(dev, TM_SENSE, 1); 1552608Swnj if ((sc->sc_erreg&(TM_SELR|TM_TUR)) != (TM_SELR|TM_TUR)) { 1562608Swnj uprintf("tape not online\n"); 1572471Swnj u.u_error = EIO; 1582608Swnj return; 1591919Swnj } 1602608Swnj if ((flag&(FREAD|FWRITE)) == FWRITE && sc->sc_erreg&TM_WRL) { 1612608Swnj uprintf("tape write protected\n"); 1622608Swnj u.u_error = EIO; 1631919Swnj return; 1641919Swnj } 1652608Swnj sc->sc_openf = 1; 1662471Swnj sc->sc_blkno = (daddr_t)0; 1672471Swnj sc->sc_nxrec = INF; 1682608Swnj sc->sc_lastiow = 0; 1692471Swnj sc->sc_openf = 1; 1702608Swnj return; 1711919Swnj } 1721919Swnj 1732608Swnj /* 1742608Swnj * Close tape device. 1752608Swnj * 1762608Swnj * If tape was open for writing or last operation was 1772608Swnj * a write, then write two EOF's and backspace over the last one. 1782608Swnj * Unless this is a non-rewinding special file, rewind the tape. 1792608Swnj * Make the tape available to others. 1802608Swnj */ 1811919Swnj tmclose(dev, flag) 1821919Swnj register dev_t dev; 1831919Swnj register flag; 1841919Swnj { 1852608Swnj register struct tm_softc *sc = &tm_softc[TMUNIT(dev)]; 1861919Swnj 1872608Swnj if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) { 1882608Swnj tmcommand(dev, TM_WEOF, 1); 1892608Swnj tmcommand(dev, TM_WEOF, 1); 1902608Swnj tmcommand(dev, TM_SREV, 1); 1911919Swnj } 1921919Swnj if ((minor(dev)&T_NOREWIND) == 0) 1932608Swnj tmcommand(dev, TM_REW, 1); 1942471Swnj sc->sc_openf = 0; 1951919Swnj } 1961919Swnj 1972608Swnj /* 1982608Swnj * Execute a command on the tape drive 1992608Swnj * a specified number of times. 2002608Swnj */ 2012574Swnj tmcommand(dev, com, count) 2021919Swnj dev_t dev; 2031919Swnj int com, count; 2041919Swnj { 2051919Swnj register struct buf *bp; 2061919Swnj 2072608Swnj bp = &ctmbuf[TMUNIT(dev)]; 2081919Swnj (void) spl5(); 2091919Swnj while (bp->b_flags&B_BUSY) { 2101919Swnj bp->b_flags |= B_WANTED; 2111919Swnj sleep((caddr_t)bp, PRIBIO); 2121919Swnj } 2131919Swnj bp->b_flags = B_BUSY|B_READ; 2141919Swnj (void) spl0(); 2151919Swnj bp->b_dev = dev; 2161919Swnj bp->b_repcnt = -count; 2171919Swnj bp->b_command = com; 2181919Swnj bp->b_blkno = 0; 2191919Swnj tmstrategy(bp); 2201919Swnj iowait(bp); 2211919Swnj if (bp->b_flags&B_WANTED) 2221919Swnj wakeup((caddr_t)bp); 2231919Swnj bp->b_flags &= B_ERROR; 2241919Swnj } 2251919Swnj 2262608Swnj /* 2272608Swnj * Decipher a tape operation and do what is needed 2282608Swnj * to see that it happens. 2292608Swnj */ 2301919Swnj tmstrategy(bp) 2311919Swnj register struct buf *bp; 2321919Swnj { 2332608Swnj int unit = TMUNIT(bp->b_dev); 2342608Swnj register struct uba_minfo *um; 2352608Swnj register struct buf *dp; 2362608Swnj register struct tm_softc *sc = &tm_softc[unit]; 2371919Swnj 2382608Swnj /* 2392608Swnj * Put transfer at end of unit queue 2402608Swnj */ 2412608Swnj dp = &tmutab[unit]; 2421919Swnj bp->av_forw = NULL; 2431919Swnj (void) spl5(); 2442608Swnj if (dp->b_actf == NULL) { 2452608Swnj dp->b_actf = bp; 2462608Swnj /* 2472608Swnj * Transport not already active... 2482608Swnj * put at end of controller queue. 2492608Swnj */ 2502608Swnj dp->b_forw = NULL; 2512608Swnj um = tmdinfo[unit]->ui_mi; 2522608Swnj if (um->um_tab.b_actf == NULL) 2532608Swnj um->um_tab.b_actf = dp; 2542608Swnj else 2552608Swnj um->um_tab.b_actl->b_forw = dp; 2562608Swnj um->um_tab.b_actl = dp; 2572608Swnj } else 2582608Swnj dp->b_actl->av_forw = bp; 2592608Swnj dp->b_actl = bp; 2602608Swnj /* 2612608Swnj * If the controller is not busy, get 2622608Swnj * it going. 2632608Swnj */ 2642608Swnj if (um->um_tab.b_active == 0) 2652608Swnj tmstart(um); 2661919Swnj (void) spl0(); 2671919Swnj } 2681919Swnj 2692608Swnj /* 2702608Swnj * Start activity on a tm controller. 2712608Swnj */ 2722608Swnj tmstart(um) 2732608Swnj register struct uba_minfo *um; 2741919Swnj { 2752608Swnj register struct buf *bp, *dp; 2762608Swnj register struct device *addr = (struct device *)um->um_addr; 2772608Swnj register struct tm_softc *sc; 2782396Swnj register struct uba_dinfo *ui; 2792608Swnj int unit, cmd; 2802471Swnj daddr_t blkno; 2811919Swnj 2822608Swnj /* 2832608Swnj * Look for an idle transport on the controller. 2842608Swnj */ 2851919Swnj loop: 2862608Swnj if ((dp = um->um_tab.b_actf) == NULL) 2871919Swnj return; 2882608Swnj if ((bp = dp->b_actf) == NULL) { 2892608Swnj um->um_tab.b_actf = dp->b_forw; 2902608Swnj goto loop; 2912608Swnj } 2922608Swnj unit = TMUNIT(bp->b_dev); 2932608Swnj ui = tmdinfo[unit]; 2942608Swnj /* 2952608Swnj * Record pre-transfer status (e.g. for TM_SENSE) 2962608Swnj */ 2972608Swnj sc = &tm_softc[unit]; 2982608Swnj addr = (struct device *)um->um_addr; 2992608Swnj addr->tmcs = (ui->ui_slave << 8); 3002471Swnj sc->sc_dsreg = addr->tmcs; 3012471Swnj sc->sc_erreg = addr->tmer; 3022471Swnj sc->sc_resid = addr->tmbc; 3032608Swnj /* 3042608Swnj * Default is that last command was NOT a write command; 3052608Swnj * if we do a write command we will notice this in tmintr(). 3062608Swnj */ 3072608Swnj sc->sc_lastiow = 1; 3082608Swnj if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) { 3092608Swnj /* 3102608Swnj * Have had a hard error on this (non-raw) tape, 3112608Swnj * or the tape unit is now unavailable (e.g. taken off 3122608Swnj * line). 3132608Swnj */ 3142608Swnj bp->b_flags |= B_ERROR; 3151919Swnj goto next; 3161919Swnj } 3172608Swnj /* 3182608Swnj * If operation is not a control operation, 3192608Swnj * check for boundary conditions. 3202608Swnj */ 3212608Swnj if (bp != &ctmbuf[unit]) { 3222608Swnj if (dbtofsb(bp->b_blkno) > sc->sc_nxrec) { 3232608Swnj bp->b_flags |= B_ERROR; 3242608Swnj bp->b_error = ENXIO; /* past EOF */ 3252608Swnj goto next; 3261919Swnj } 3272608Swnj if (dbtofsb(bp->b_blkno) == sc->sc_nxrec && 3282608Swnj bp->b_flags&B_READ) { 3292608Swnj bp->b_resid = bp->b_bcount; 3302608Swnj clrbuf(bp); /* at EOF */ 3312608Swnj goto next; 3322608Swnj } 3332608Swnj if ((bp->b_flags&B_READ) == 0) 3342608Swnj /* write sets EOF */ 3352608Swnj sc->sc_nxrec = dbtofsb(bp->b_blkno) + 1; 3361919Swnj } 3372608Swnj /* 3382608Swnj * Set up the command, and then if this is a mt ioctl, 3392608Swnj * do the operation using, for TM_SFORW and TM_SREV, the specified 3402608Swnj * operation count. 3412608Swnj */ 3422608Swnj cmd = TM_IE | TM_GO | (ui->ui_slave << 8); 3432608Swnj if ((minor(bp->b_dev) & T_1600BPI) == 0) 3442608Swnj cmd |= TM_D800; 3452608Swnj if (bp == &ctmbuf[unit]) { 3462608Swnj if (bp->b_command == TM_SENSE) 3472608Swnj goto next; 3482608Swnj cmd |= bp->b_command; 3492608Swnj um->um_tab.b_active = 3502608Swnj bp->b_command == TM_REW ? SREW : SCOM; 3512608Swnj if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV) 3522608Swnj addr->tmbc = bp->b_repcnt; 3532608Swnj addr->tmcs = cmd; 3542608Swnj return; 3552608Swnj } 3562608Swnj /* 3572608Swnj * If the data transfer command is in the correct place, 3582608Swnj * set up all the registers except the csr, and give 3592608Swnj * control over to the UNIBUS adapter routines, to 3602608Swnj * wait for resources to start the i/o. 3612608Swnj */ 3622471Swnj if ((blkno = sc->sc_blkno) == dbtofsb(bp->b_blkno)) { 3632396Swnj addr->tmbc = -bp->b_bcount; 3641919Swnj if ((bp->b_flags&B_READ) == 0) { 3652471Swnj if (um->um_tab.b_errcnt) 3662608Swnj cmd |= TM_WIRG; 3671919Swnj else 3682608Swnj cmd |= TM_WCOM; 3691919Swnj } else 3702608Swnj cmd |= TM_RCOM; 3712471Swnj um->um_tab.b_active = SIO; 3722574Swnj um->um_cmd = cmd; 3732574Swnj ubago(ui); 3741919Swnj return; 3751919Swnj } 3762608Swnj /* 3772608Swnj * Block tape positioned incorrectly; 3782608Swnj * seek forwards or backwards to the correct spot. 3792608Swnj */ 3802471Swnj um->um_tab.b_active = SSEEK; 3811919Swnj if (blkno < dbtofsb(bp->b_blkno)) { 3822608Swnj cmd |= TM_SFORW; 3832396Swnj addr->tmbc = blkno - dbtofsb(bp->b_blkno); 3841919Swnj } else { 3852608Swnj cmd |= TM_SREV; 3862396Swnj addr->tmbc = dbtofsb(bp->b_blkno) - blkno; 3871919Swnj } 3882396Swnj addr->tmcs = cmd; 3891919Swnj return; 3901919Swnj 3911919Swnj next: 3922608Swnj /* 3932608Swnj * Done with this operation due to error or 3942608Swnj * the fact that it doesn't do anything. 3952608Swnj * Release UBA resources (if any), dequeue 3962608Swnj * the transfer and continue processing this slave. 3972608Swnj */ 3982608Swnj if (um->um_ubinfo) 399*2617Swnj ubadone(um); 4002608Swnj um->um_tab.b_errcnt = 0; 4012608Swnj dp->b_actf = bp->av_forw; 4021919Swnj iodone(bp); 4031919Swnj goto loop; 4041919Swnj } 4051919Swnj 4062608Swnj /* 4072608Swnj * The UNIBUS resources we needed have been 4082608Swnj * allocated to us; start the device. 4092608Swnj */ 4102574Swnj tmdgo(um) 4112574Swnj register struct uba_minfo *um; 4121919Swnj { 4132574Swnj register struct device *addr = (struct device *)um->um_addr; 4142471Swnj 4152574Swnj addr->tmba = um->um_ubinfo; 4162574Swnj addr->tmcs = um->um_cmd | ((um->um_ubinfo >> 12) & 0x30); 4172396Swnj } 4182396Swnj 4192608Swnj /* 4202608Swnj * Tm interrupt routine. 4212608Swnj */ 4222471Swnj /*ARGSUSED*/ 4232608Swnj tmintr(tm03) 4242608Swnj int tm03; 4252396Swnj { 4262608Swnj struct buf *dp; 4271919Swnj register struct buf *bp; 4282608Swnj register struct uba_minfo *um = tmminfo[tm03]; 4292608Swnj register struct device *addr = (struct device *)tmdinfo[tm03]->ui_addr; 4302608Swnj register struct tm_softc *sc; 4312608Swnj int unit; 4321919Swnj register state; 4331919Swnj 4342608Swnj /* 4352608Swnj * If last command was a rewind, and tape is still 4362608Swnj * rewinding, wait for the rewind complete interrupt. 4372608Swnj */ 4382608Swnj if (um->um_tab.b_active == SREW) { 4392608Swnj um->um_tab.b_active = SCOM; 4402608Swnj if (addr->tmer&TM_RWS) 4412608Swnj return; 4421919Swnj } 4432608Swnj /* 4442608Swnj * An operation completed... record status 4452608Swnj */ 4462608Swnj if ((dp = um->um_tab.b_actf) == NULL) 4471919Swnj return; 4482608Swnj bp = dp->b_actf; 4492608Swnj unit = TMUNIT(bp->b_dev); 4502608Swnj sc = &tm_softc[unit]; 4512471Swnj sc->sc_dsreg = addr->tmcs; 4522471Swnj sc->sc_erreg = addr->tmer; 4532471Swnj sc->sc_resid = addr->tmbc; 4541919Swnj if ((bp->b_flags & B_READ) == 0) 4552608Swnj sc->sc_lastiow = 1; 4562471Swnj state = um->um_tab.b_active; 4572471Swnj um->um_tab.b_active = 0; 4582608Swnj /* 4592608Swnj * Check for errors. 4602608Swnj */ 4612608Swnj if (addr->tmcs&TM_ERR) { 4622608Swnj while (addr->tmer & TM_SDWN) 4631919Swnj ; /* await settle down */ 4642608Swnj /* 4652608Swnj * If we hit the end of the tape update our position. 4662608Swnj */ 4672608Swnj if (addr->tmer&TM_EOF) { 4682608Swnj tmseteof(bp); /* set blkno and nxrec */ 4692608Swnj state = SCOM; /* force completion */ 4702608Swnj /* 4712608Swnj * Stuff bc so it will be unstuffed correctly 4722608Swnj * later to get resid. 4732608Swnj */ 4742396Swnj addr->tmbc = -bp->b_bcount; 4752608Swnj goto opdone; 4761919Swnj } 4772608Swnj /* 4782608Swnj * If we were reading and the only error was that the 4792608Swnj * record was to long, then we don't consider this an error. 4802608Swnj */ 4812608Swnj if ((bp->b_flags&B_READ) && 4822608Swnj (addr->tmer&(TM_HARD|TM_SOFT)) == TM_RLE) 4832608Swnj goto ignoreerr; 4842608Swnj /* 4852608Swnj * If error is not hard, and this was an i/o operation 4862608Swnj * retry up to 8 times. 4872608Swnj */ 4882608Swnj if ((addr->tmer&TM_HARD)==0 && state==SIO) { 4892471Swnj if (++um->um_tab.b_errcnt < 7) { 4902608Swnj /* SHOULD CHECK THAT RECOVERY WORKS IN THIS CASE */ 4912608Swnj /* AND THEN ONLY PRINT IF errcnt==7 */ 4922608Swnj if((addr->tmer&TM_SOFT) == TM_NXM) 4931919Swnj printf("TM UBA late error\n"); 4942471Swnj sc->sc_blkno++; 495*2617Swnj ubadone(um); 4962608Swnj goto opcont; 4971919Swnj } 4982608Swnj } else 4992608Swnj /* 5002608Swnj * Hard or non-i/o errors on non-raw tape 5012608Swnj * cause it to close. 5022608Swnj */ 5032608Swnj if (sc->sc_openf>0 && bp != &rtmbuf[unit]) 5042608Swnj sc->sc_openf = -1; 5052608Swnj /* 5062608Swnj * Couldn't recover error 5072608Swnj */ 5082471Swnj deverror(bp, sc->sc_erreg, sc->sc_dsreg); 5091919Swnj bp->b_flags |= B_ERROR; 5102608Swnj goto opdone; 5111919Swnj } 5122608Swnj /* 5132608Swnj * Advance tape control FSM. 5142608Swnj */ 5152608Swnj ignoreerr: 5161919Swnj switch (state) { 5171919Swnj 5181919Swnj case SIO: 5192608Swnj /* 5202608Swnj * Read/write increments tape block number 5212608Swnj */ 5222471Swnj sc->sc_blkno++; 5232608Swnj goto opdone; 5241919Swnj 5251919Swnj case SCOM: 5262608Swnj /* 5272608Swnj * Unless special operation, op completed. 5282608Swnj */ 5292608Swnj if (bp != &ctmbuf[unit]) 5302608Swnj goto opdone; 5312608Swnj /* 5322608Swnj * Operation on block device... 5332608Swnj * iterate operations which don't repeat 5342608Swnj * for themselves in the hardware; for forward/ 5352608Swnj * backward space record update the current position. 5362608Swnj */ 5372608Swnj switch (bp->b_command) { 5381919Swnj 5392608Swnj case TM_SFORW: 5402608Swnj sc->sc_blkno -= bp->b_repcnt; 5412608Swnj goto opdone; 5421919Swnj 5432608Swnj case TM_SREV: 5442608Swnj sc->sc_blkno += bp->b_repcnt; 5452608Swnj goto opdone; 5462608Swnj 5472608Swnj default: 5482608Swnj if (++bp->b_repcnt < 0) 5492608Swnj goto opcont; 5502608Swnj goto opdone; 5511919Swnj } 5521919Swnj 5531919Swnj case SSEEK: 5542471Swnj sc->sc_blkno = dbtofsb(bp->b_blkno); 5552608Swnj goto opcont; 5561919Swnj 5571919Swnj default: 5582608Swnj panic("tmintr"); 5592608Swnj } 5602608Swnj opdone: 5612608Swnj /* 5622608Swnj * Reset error count and remove 5632608Swnj * from device queue. 5642608Swnj */ 5652608Swnj um->um_tab.b_errcnt = 0; 5662608Swnj dp->b_actf = bp->av_forw; 5672608Swnj bp->b_resid = -addr->tmbc; 568*2617Swnj ubadone(um); 5692608Swnj iodone(bp); 5702608Swnj /* 5712608Swnj * Circulate slave to end of controller 5722608Swnj * queue to give other slaves a chance. 5732608Swnj */ 5742608Swnj um->um_tab.b_actf = dp->b_forw; 5752608Swnj if (dp->b_actf) { 5762608Swnj dp->b_forw = NULL; 5772608Swnj if (um->um_tab.b_actf == NULL) 5782608Swnj um->um_tab.b_actf = dp; 5792608Swnj else 5802608Swnj um->um_tab.b_actl->b_forw = dp; 5812608Swnj um->um_tab.b_actl = dp; 5822608Swnj } 5832608Swnj if (um->um_tab.b_actf == 0) 5841919Swnj return; 5852608Swnj opcont: 5862608Swnj tmstart(um); 5871919Swnj } 5881919Swnj 5891919Swnj tmseteof(bp) 5901919Swnj register struct buf *bp; 5911919Swnj { 5922608Swnj register int unit = TMUNIT(bp->b_dev); 5932396Swnj register struct device *addr = 5942608Swnj (struct device *)tmdinfo[unit]->ui_addr; 5952608Swnj register struct tm_softc *sc = &tm_softc[unit]; 5961919Swnj 5972608Swnj if (bp == &ctmbuf[unit]) { 5982471Swnj if (sc->sc_blkno > dbtofsb(bp->b_blkno)) { 5991919Swnj /* reversing */ 6002471Swnj sc->sc_nxrec = dbtofsb(bp->b_blkno) - addr->tmbc; 6012471Swnj sc->sc_blkno = sc->sc_nxrec; 6021919Swnj } else { 6031919Swnj /* spacing forward */ 6042471Swnj sc->sc_blkno = dbtofsb(bp->b_blkno) + addr->tmbc; 6052471Swnj sc->sc_nxrec = sc->sc_blkno - 1; 6061919Swnj } 6071919Swnj return; 6081919Swnj } 6091919Swnj /* eof on read */ 6102471Swnj sc->sc_nxrec = dbtofsb(bp->b_blkno); 6111919Swnj } 6121919Swnj 6131919Swnj tmread(dev) 6142608Swnj dev_t dev; 6151919Swnj { 6161919Swnj 6171919Swnj tmphys(dev); 6182608Swnj physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_READ, minphys); 6191919Swnj } 6201919Swnj 6211919Swnj tmwrite(dev) 6222608Swnj dev_t dev; 6231919Swnj { 6241919Swnj 6251919Swnj tmphys(dev); 6262608Swnj physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_WRITE, minphys); 6271919Swnj } 6281919Swnj 6291919Swnj tmphys(dev) 6302608Swnj dev_t dev; 6311919Swnj { 6321919Swnj register daddr_t a; 6332608Swnj register struct tm_softc *sc = &tm_softc[TMUNIT(dev)]; 6341919Swnj 6351919Swnj a = dbtofsb(u.u_offset >> 9); 6362471Swnj sc->sc_blkno = a; 6372471Swnj sc->sc_nxrec = a + 1; 6381919Swnj } 6391919Swnj 6402608Swnj tmreset(uban) 6412608Swnj int uban; 6422608Swnj { 6432608Swnj int printed = 0; 6442608Swnj register struct uba_minfo *um; 6452608Swnj register tm03, unit; 6462608Swnj register struct uba_dinfo *ui; 6472608Swnj register struct buf *dp; 6482608Swnj 6492608Swnj for (tm03 = 0; tm03 < NTM03; tm03++) { 6502608Swnj if ((um = tmminfo[tm03]) == 0 || um->um_alive == 0 || 6512608Swnj um->um_ubanum != uban) 6522608Swnj continue; 6532608Swnj if (printed == 0) { 6542608Swnj printf(" tm"); 6552608Swnj DELAY(2000000); /* time to self test */ 6562608Swnj printed = 1; 6572608Swnj } 6582608Swnj um->um_tab.b_active = 0; 6592608Swnj um->um_tab.b_actf = um->um_tab.b_actl = 0; 6602608Swnj if (um->um_ubinfo) { 6612608Swnj printf("<%d>", (um->um_ubinfo>>28)&0xf); 662*2617Swnj ubadone(um); 6632608Swnj } 6642608Swnj ((struct device *)(um->um_addr))->tmcs = TM_DCLR; 6652608Swnj for (unit = 0; unit < NTM11; unit++) { 6662608Swnj if ((ui = tmdinfo[unit]) == 0) 6672608Swnj continue; 6682608Swnj if (ui->ui_alive == 0) 6692608Swnj continue; 6702608Swnj dp = &tmutab[unit]; 6712608Swnj dp->b_active = 0; 6722608Swnj dp->b_forw = 0; 6732608Swnj if (um->um_tab.b_actf == NULL) 6742608Swnj um->um_tab.b_actf = dp; 6752608Swnj else 6762608Swnj um->um_tab.b_actl->b_forw = dp; 6772608Swnj um->um_tab.b_actl = dp; 6782608Swnj tm_softc[unit].sc_openf = -1; 6792608Swnj } 6802608Swnj tmstart(um); 6812608Swnj } 6822608Swnj } 6832608Swnj 6841919Swnj /*ARGSUSED*/ 6851919Swnj tmioctl(dev, cmd, addr, flag) 6861919Swnj caddr_t addr; 6871919Swnj dev_t dev; 6881919Swnj { 6892608Swnj int unit = TMUNIT(dev); 6902608Swnj register struct tm_softc *sc = &tm_softc[unit]; 6912608Swnj register struct buf *bp = &ctmbuf[unit]; 6921919Swnj register callcount; 6931919Swnj int fcount; 6941919Swnj struct mtop mtop; 6951919Swnj struct mtget mtget; 6961919Swnj /* we depend of the values and order of the MT codes here */ 6972608Swnj static tmops[] = 6982608Swnj {TM_WEOF,TM_SFORW,TM_SREV,TM_SFORW,TM_SREV,TM_REW,TM_OFFL,TM_SENSE}; 6991919Swnj 7002608Swnj switch (cmd) { 7011919Swnj case MTIOCTOP: /* tape operation */ 7021919Swnj if (copyin((caddr_t)addr, (caddr_t)&mtop, sizeof(mtop))) { 7031919Swnj u.u_error = EFAULT; 7041919Swnj return; 7051919Swnj } 7061919Swnj switch(mtop.mt_op) { 7072608Swnj case MTWEOF: 7081919Swnj callcount = mtop.mt_count; 7092608Swnj fcount = 1; 7102608Swnj break; 7112608Swnj case MTFSF: case MTBSF: 7122608Swnj callcount = mtop.mt_count; 7131919Swnj fcount = INF; 7141919Swnj break; 7151919Swnj case MTFSR: case MTBSR: 7161919Swnj callcount = 1; 7171919Swnj fcount = mtop.mt_count; 7181919Swnj break; 7192324Skre case MTREW: case MTOFFL: case MTNOP: 7201919Swnj callcount = 1; 7211919Swnj fcount = 1; 7221919Swnj break; 7231919Swnj default: 7241919Swnj u.u_error = ENXIO; 7251919Swnj return; 7261919Swnj } 7272608Swnj if (callcount <= 0 || fcount <= 0) { 7281919Swnj u.u_error = ENXIO; 7292608Swnj return; 7302608Swnj } 7312608Swnj while (--callcount >= 0) { 7322574Swnj tmcommand(dev, tmops[mtop.mt_op], fcount); 7331919Swnj if ((mtop.mt_op == MTFSR || mtop.mt_op == MTBSR) && 7342608Swnj bp->b_resid) { 7351919Swnj u.u_error = EIO; 7361919Swnj break; 7371919Swnj } 7382608Swnj if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TM_BOT) 7391919Swnj break; 7401919Swnj } 7412608Swnj geterror(bp); 7421919Swnj return; 7431919Swnj case MTIOCGET: 7442471Swnj mtget.mt_dsreg = sc->sc_dsreg; 7452471Swnj mtget.mt_erreg = sc->sc_erreg; 7462471Swnj mtget.mt_resid = sc->sc_resid; 7471919Swnj if (copyout((caddr_t)&mtget, addr, sizeof(mtget))) 7481919Swnj u.u_error = EFAULT; 7491919Swnj return; 7501919Swnj default: 7511919Swnj u.u_error = ENXIO; 7521919Swnj } 7531919Swnj } 7541919Swnj 7551919Swnj #define DBSIZE 20 7561919Swnj 7572363Swnj tmdump() 7582363Swnj { 7592396Swnj register struct uba_dinfo *ui; 7602396Swnj register struct uba_regs *up; 7612396Swnj register struct device *addr; 7622426Skre int blk, num; 7632426Skre int start; 7641919Swnj 7652426Skre start = 0; 7662426Skre num = maxfree; 7672426Skre #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 7682458Swnj if (tmdinfo[0] == 0) { 7692396Swnj printf("dna\n"); 7702396Swnj return (-1); 7712396Swnj } 7722458Swnj ui = phys(tmdinfo[0], struct uba_dinfo *); 7732396Swnj up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba; 7742396Swnj #if VAX780 7752396Swnj if (cpu == VAX_780) 7762396Swnj ubainit(up); 7771919Swnj #endif 7782324Skre DELAY(1000000); 7792396Swnj addr = (struct device *)ui->ui_physaddr; 7802396Swnj tmwait(addr); 7812608Swnj addr->tmcs = TM_DCLR | TM_GO; 7821919Swnj while (num > 0) { 7831919Swnj blk = num > DBSIZE ? DBSIZE : num; 7842396Swnj tmdwrite(start, blk, addr, up); 7851919Swnj start += blk; 7861919Swnj num -= blk; 7871919Swnj } 7882426Skre tmeof(addr); 7892426Skre tmeof(addr); 7902426Skre tmwait(addr); 7912608Swnj addr->tmcs = TM_REW | TM_GO; 7922471Swnj tmwait(addr); 7932363Swnj return (0); 7941919Swnj } 7951919Swnj 7962608Swnj tmdwrite(dbuf, num, addr, up) 7972608Swnj register dbuf, num; 7982396Swnj register struct device *addr; 7992396Swnj struct uba_regs *up; 8001919Swnj { 8012396Swnj register struct pte *io; 8022396Swnj register int npf; 8031928Swnj 8042396Swnj tmwait(addr); 8052396Swnj io = up->uba_map; 8061919Swnj npf = num+1; 8071928Swnj while (--npf != 0) 8082608Swnj *(int *)io++ = (dbuf++ | (1<<UBA_DPSHIFT) | UBA_MRV); 8092396Swnj *(int *)io = 0; 8102396Swnj addr->tmbc = -(num*NBPG); 8112396Swnj addr->tmba = 0; 8122608Swnj addr->tmcs = TM_WCOM | TM_GO; 8131919Swnj } 8141919Swnj 8152396Swnj tmwait(addr) 8162396Swnj register struct device *addr; 8171919Swnj { 8181928Swnj register s; 8191919Swnj 8201919Swnj do 8212396Swnj s = addr->tmcs; 8222608Swnj while ((s & TM_CUR) == 0); 8231919Swnj } 8241919Swnj 8252396Swnj tmeof(addr) 8262396Swnj struct device *addr; 8271919Swnj { 8281919Swnj 8292396Swnj tmwait(addr); 8302608Swnj addr->tmcs = TM_WEOF | TM_GO; 8311919Swnj } 8321919Swnj #endif 833