xref: /csrg-svn/sys/vax/uba/tm.c (revision 26369)
123344Smckusick /*
223344Smckusick  * Copyright (c) 1982 Regents of the University of California.
323344Smckusick  * All rights reserved.  The Berkeley software License Agreement
423344Smckusick  * specifies the terms and conditions for redistribution.
523344Smckusick  *
6*26369Skarels  *	@(#)tm.c	6.10 (Berkeley) 02/23/86
723344Smckusick  */
81919Swnj 
92709Swnj #include "te.h"
103519Sroot #include "ts.h"
116343Swnj #if NTE > 0
121919Swnj /*
132630Swnj  * TM11/TE10 tape driver
142471Swnj  *
153095Swnj  * TODO:
163095Swnj  *	test driver with more than one slave
173095Swnj  *	test driver with more than one controller
183095Swnj  *	test reset code
193095Swnj  *	what happens if you offline tape during rewind?
203095Swnj  *	test using file system on tape
211919Swnj  */
229778Ssam #include "../machine/pte.h"
239778Ssam 
2417079Sbloom #include "param.h"
2517079Sbloom #include "systm.h"
2617079Sbloom #include "buf.h"
2717079Sbloom #include "dir.h"
2817079Sbloom #include "conf.h"
2917079Sbloom #include "user.h"
3017079Sbloom #include "file.h"
3117079Sbloom #include "map.h"
3217079Sbloom #include "vm.h"
3317079Sbloom #include "ioctl.h"
3417079Sbloom #include "mtio.h"
3517079Sbloom #include "cmap.h"
3617079Sbloom #include "uio.h"
3717079Sbloom #include "kernel.h"
3818321Sralph #include "tty.h"
391919Swnj 
408479Sroot #include "../vax/cpu.h"
4117079Sbloom #include "ubareg.h"
4217079Sbloom #include "ubavar.h"
4317079Sbloom #include "tmreg.h"
441919Swnj 
453095Swnj /*
463095Swnj  * There is a ctmbuf per tape controller.
473095Swnj  * It is used as the token to pass to the internal routines
483095Swnj  * to execute tape ioctls, and also acts as a lock on the slaves
493095Swnj  * on the controller, since there is only one per controller.
503095Swnj  * In particular, when the tape is rewinding on close we release
513095Swnj  * the user process but any further attempts to use the tape drive
523095Swnj  * before the rewind completes will hang waiting for ctmbuf.
533095Swnj  */
543095Swnj struct	buf	ctmbuf[NTM];
551919Swnj 
563095Swnj /*
573095Swnj  * Raw tape operations use rtmbuf.  The driver
583095Swnj  * notices when rtmbuf is being used and allows the user
593095Swnj  * program to continue after errors and read records
603095Swnj  * not of the standard length (BSIZE).
613095Swnj  */
623095Swnj struct	buf	rtmbuf[NTM];
633095Swnj 
643095Swnj /*
653095Swnj  * Driver unibus interface routines and variables.
663095Swnj  */
672608Swnj int	tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr();
682982Swnj struct	uba_ctlr *tmminfo[NTM];
693095Swnj struct	uba_device *tedinfo[NTE];
703095Swnj struct	buf teutab[NTE];
713095Swnj short	tetotm[NTE];
722458Swnj u_short	tmstd[] = { 0772520, 0 };
732396Swnj struct	uba_driver tmdriver =
743095Swnj  { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tedinfo, "tm", tmminfo, 0 };
751919Swnj 
761919Swnj /* bits in minor device */
773095Swnj #define	TEUNIT(dev)	(minor(dev)&03)
783095Swnj #define	TMUNIT(dev)	(tetotm[TEUNIT(dev)])
791919Swnj #define	T_NOREWIND	04
8024974Smckusick #define	T_1600BPI	0x8
811919Swnj 
821919Swnj #define	INF	(daddr_t)1000000L
831919Swnj 
842608Swnj /*
852608Swnj  * Software state per tape transport.
863095Swnj  *
873095Swnj  * 1. A tape drive is a unique-open device; we refuse opens when it is already.
883095Swnj  * 2. We keep track of the current position on a block tape and seek
893095Swnj  *    before operations by forward/back spacing if necessary.
903095Swnj  * 3. We remember if the last operation was a write on a tape, so if a tape
913095Swnj  *    is open read write and the last thing done is a write we can
923095Swnj  *    write a standard end of tape mark (two eofs).
933095Swnj  * 4. We remember the status registers after the last command, using
943095Swnj  *    then internally and returning them to the SENSE ioctl.
953095Swnj  * 5. We remember the last density the tape was used at.  If it is
963095Swnj  *    not a BOT when we start using it and we are writing, we don't
973095Swnj  *    let the density be changed.
982608Swnj  */
993095Swnj struct	te_softc {
1002608Swnj 	char	sc_openf;	/* lock against multiple opens */
1012608Swnj 	char	sc_lastiow;	/* last op was a write */
1022608Swnj 	daddr_t	sc_blkno;	/* block number, for block device tape */
1033095Swnj 	daddr_t	sc_nxrec;	/* position of end of tape, if known */
1042608Swnj 	u_short	sc_erreg;	/* copy of last erreg */
1052608Swnj 	u_short	sc_dsreg;	/* copy of last dsreg */
1062608Swnj 	short	sc_resid;	/* copy of last bc */
1073105Swnj #ifdef unneeded
1082670Swnj 	short	sc_lastcmd;	/* last command to handle direction changes */
1092928Swnj #endif
1103095Swnj 	u_short	sc_dens;	/* prototype command with density info */
11118321Sralph 	short	sc_tact;	/* timeout is active */
1123495Sroot 	daddr_t	sc_timo;	/* time until timeout expires */
11318321Sralph 	struct	tty *sc_ttyp;	/* record user's tty for errors */
1146952Swnj } te_softc[NTE];
1153105Swnj #ifdef unneeded
1163105Swnj int	tmgapsdcnt;		/* DEBUG */
1173105Swnj #endif
1181919Swnj 
1192608Swnj /*
1203095Swnj  * States for um->um_tab.b_active, the per controller state flag.
1213095Swnj  * This is used to sequence control in the driver.
1222608Swnj  */
1231919Swnj #define	SSEEK	1		/* seeking */
1241919Swnj #define	SIO	2		/* doing seq i/o */
1251919Swnj #define	SCOM	3		/* sending control command */
1262608Swnj #define	SREW	4		/* sending a drive rewind */
1271919Swnj 
1282426Skre /*
1292426Skre  * Determine if there is a controller for
1302426Skre  * a tm at address reg.  Our goal is to make the
1312426Skre  * device interrupt.
1322426Skre  */
1332608Swnj tmprobe(reg)
1342396Swnj 	caddr_t reg;
1352396Swnj {
1363095Swnj 	register int br, cvec;		/* must be r11,r10; value-result */
1372426Skre 
1382608Swnj #ifdef lint
1393105Swnj 	br = 0; cvec = br; br = cvec;
1404936Swnj 	tmintr(0);
1412608Swnj #endif
1425692Sroot 	((struct tmdevice *)reg)->tmcs = TM_IE;
1432396Swnj 	/*
1442630Swnj 	 * If this is a tm11, it ought to have interrupted
1452396Swnj 	 * by now, if it isn't (ie: it is a ts04) then we just
1462458Swnj 	 * hope that it didn't interrupt, so autoconf will ignore it.
1472458Swnj 	 * Just in case, we will reference one
1482396Swnj 	 * of the more distant registers, and hope for a machine
1492458Swnj 	 * check, or similar disaster if this is a ts.
1502471Swnj 	 *
1512471Swnj 	 * Note: on an 11/780, badaddr will just generate
1522471Swnj 	 * a uba error for a ts; but our caller will notice that
1532471Swnj 	 * so we won't check for it.
1542396Swnj 	 */
1555692Sroot 	if (badaddr((caddr_t)&((struct tmdevice *)reg)->tmrd, 2))
1562458Swnj 		return (0);
1577404Skre 	return (sizeof (struct tmdevice));
1582396Swnj }
1592396Swnj 
1602608Swnj /*
1612608Swnj  * Due to a design flaw, we cannot ascertain if the tape
1622608Swnj  * exists or not unless it is on line - ie: unless a tape is
1632608Swnj  * mounted. This is too servere a restriction to bear,
1642608Swnj  * so all units are assumed to exist.
1652608Swnj  */
1662608Swnj /*ARGSUSED*/
1672574Swnj tmslave(ui, reg)
1682982Swnj 	struct uba_device *ui;
1692396Swnj 	caddr_t reg;
1702396Swnj {
1712458Swnj 
1722458Swnj 	return (1);
1732396Swnj }
1742396Swnj 
1752608Swnj /*
1763095Swnj  * Record attachment of the unit to the controller.
1772608Swnj  */
1782608Swnj /*ARGSUSED*/
1792608Swnj tmattach(ui)
1802982Swnj 	struct uba_device *ui;
1812608Swnj {
1823095Swnj 	/*
1833095Swnj 	 * Tetotm is used in TMUNIT to index the ctmbuf and rtmbuf
1843095Swnj 	 * arrays given a te unit number.
1853095Swnj 	 */
1863095Swnj 	tetotm[ui->ui_unit] = ui->ui_mi->um_ctlr;
1872608Swnj }
1882608Swnj 
1893495Sroot int	tmtimer();
1902608Swnj /*
1912608Swnj  * Open the device.  Tapes are unique open
1922608Swnj  * devices, so we refuse if it is already open.
1932608Swnj  * We also check that a tape is available, and
1943095Swnj  * don't block waiting here; if you want to wait
1953095Swnj  * for a tape you should timeout in user code.
1962608Swnj  */
19724974Smckusick 
19824974Smckusick #ifdef AVIV
19924974Smckusick int tmdens[4] = { 0x6000, 0x0000, 0x2000, 0 };
20024974Smckusick int tmdiag;
20124974Smckusick #endif AVIV
20224974Smckusick 
2031919Swnj tmopen(dev, flag)
2041919Swnj 	dev_t dev;
2051919Swnj 	int flag;
2061919Swnj {
2073095Swnj 	register int teunit;
2082982Swnj 	register struct uba_device *ui;
2093095Swnj 	register struct te_softc *sc;
2103209Swnj 	int olddens, dens;
2115437Sroot 	int s;
2121919Swnj 
2133095Swnj 	teunit = TEUNIT(dev);
21425051Skarels 	if (teunit>=NTE || (ui = tedinfo[teunit]) == 0 || ui->ui_alive == 0)
2158574Sroot 		return (ENXIO);
21625051Skarels 	if ((sc = &te_softc[teunit])->sc_openf)
21725051Skarels 		return (EBUSY);
2183209Swnj 	olddens = sc->sc_dens;
2193209Swnj 	dens = TM_IE | TM_GO | (ui->ui_slave << 8);
22024974Smckusick #ifndef AVIV
2213209Swnj 	if ((minor(dev) & T_1600BPI) == 0)
2223209Swnj 		dens |= TM_D800;
22324974Smckusick #else AVIV
22424974Smckusick 	dens |= tmdens[(minor(dev)>>3)&03];
22524974Smckusick #endif AVIV
2263209Swnj 	sc->sc_dens = dens;
2273141Swnj get:
2282608Swnj 	tmcommand(dev, TM_SENSE, 1);
2293141Swnj 	if (sc->sc_erreg&TMER_SDWN) {
2303141Swnj 		sleep((caddr_t)&lbolt, PZERO+1);
2313141Swnj 		goto get;
2323141Swnj 	}
2333209Swnj 	sc->sc_dens = olddens;
2343710Sroot 	if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR)) {
2353710Sroot 		uprintf("te%d: not online\n", teunit);
2368574Sroot 		return (EIO);
2371919Swnj 	}
2383710Sroot 	if ((flag&FWRITE) && (sc->sc_erreg&TMER_WRL)) {
2393710Sroot 		uprintf("te%d: no write ring\n", teunit);
2408574Sroot 		return (EIO);
2413710Sroot 	}
2423710Sroot 	if ((sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
2433710Sroot 	    dens != sc->sc_dens) {
2443710Sroot 		uprintf("te%d: can't change density in mid-tape\n", teunit);
2458574Sroot 		return (EIO);
2463710Sroot 	}
2472608Swnj 	sc->sc_openf = 1;
2482471Swnj 	sc->sc_blkno = (daddr_t)0;
2492471Swnj 	sc->sc_nxrec = INF;
2502608Swnj 	sc->sc_lastiow = 0;
2513095Swnj 	sc->sc_dens = dens;
25218321Sralph 	sc->sc_ttyp = u.u_ttyp;
253*26369Skarels 	s = splclock();
2543495Sroot 	if (sc->sc_tact == 0) {
2553495Sroot 		sc->sc_timo = INF;
2563495Sroot 		sc->sc_tact = 1;
2573629Sroot 		timeout(tmtimer, (caddr_t)dev, 5*hz);
2583495Sroot 	}
2595437Sroot 	splx(s);
2608574Sroot 	return (0);
2611919Swnj }
2621919Swnj 
2632608Swnj /*
2642608Swnj  * Close tape device.
2652608Swnj  *
2662608Swnj  * If tape was open for writing or last operation was
2672608Swnj  * a write, then write two EOF's and backspace over the last one.
2682608Swnj  * Unless this is a non-rewinding special file, rewind the tape.
2692608Swnj  * Make the tape available to others.
2702608Swnj  */
2711919Swnj tmclose(dev, flag)
2721919Swnj 	register dev_t dev;
2731919Swnj 	register flag;
2741919Swnj {
2753095Swnj 	register struct te_softc *sc = &te_softc[TEUNIT(dev)];
2761919Swnj 
2772608Swnj 	if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) {
2782608Swnj 		tmcommand(dev, TM_WEOF, 1);
2792608Swnj 		tmcommand(dev, TM_WEOF, 1);
2802608Swnj 		tmcommand(dev, TM_SREV, 1);
2811919Swnj 	}
2821919Swnj 	if ((minor(dev)&T_NOREWIND) == 0)
2833095Swnj 		/*
2843095Swnj 		 * 0 count means don't hang waiting for rewind complete
2853095Swnj 		 * rather ctmbuf stays busy until the operation completes
2863095Swnj 		 * preventing further opens from completing by
2873095Swnj 		 * preventing a TM_SENSE from completing.
2883095Swnj 		 */
2893095Swnj 		tmcommand(dev, TM_REW, 0);
2902471Swnj 	sc->sc_openf = 0;
2911919Swnj }
2921919Swnj 
2932608Swnj /*
2942608Swnj  * Execute a command on the tape drive
2952608Swnj  * a specified number of times.
2962608Swnj  */
2972574Swnj tmcommand(dev, com, count)
2981919Swnj 	dev_t dev;
2991919Swnj 	int com, count;
3001919Swnj {
3011919Swnj 	register struct buf *bp;
3025437Sroot 	register int s;
3031919Swnj 
3042608Swnj 	bp = &ctmbuf[TMUNIT(dev)];
3055437Sroot 	s = spl5();
3061919Swnj 	while (bp->b_flags&B_BUSY) {
3073095Swnj 		/*
3083095Swnj 		 * This special check is because B_BUSY never
3093095Swnj 		 * gets cleared in the non-waiting rewind case.
3103095Swnj 		 */
3113141Swnj 		if (bp->b_repcnt == 0 && (bp->b_flags&B_DONE))
3123095Swnj 			break;
3131919Swnj 		bp->b_flags |= B_WANTED;
3141919Swnj 		sleep((caddr_t)bp, PRIBIO);
3151919Swnj 	}
3161919Swnj 	bp->b_flags = B_BUSY|B_READ;
3175437Sroot 	splx(s);
3181919Swnj 	bp->b_dev = dev;
3191919Swnj 	bp->b_repcnt = -count;
3201919Swnj 	bp->b_command = com;
3211919Swnj 	bp->b_blkno = 0;
3221919Swnj 	tmstrategy(bp);
3233095Swnj 	/*
3243095Swnj 	 * In case of rewind from close, don't wait.
3253095Swnj 	 * This is the only case where count can be 0.
3263095Swnj 	 */
3273095Swnj 	if (count == 0)
3283095Swnj 		return;
3291919Swnj 	iowait(bp);
3301919Swnj 	if (bp->b_flags&B_WANTED)
3311919Swnj 		wakeup((caddr_t)bp);
3321919Swnj 	bp->b_flags &= B_ERROR;
3331919Swnj }
3341919Swnj 
3352608Swnj /*
3363095Swnj  * Queue a tape operation.
3372608Swnj  */
3381919Swnj tmstrategy(bp)
3391919Swnj 	register struct buf *bp;
3401919Swnj {
3413095Swnj 	int teunit = TEUNIT(bp->b_dev);
3422982Swnj 	register struct uba_ctlr *um;
3432608Swnj 	register struct buf *dp;
3445437Sroot 	int s;
3451919Swnj 
3462608Swnj 	/*
3472608Swnj 	 * Put transfer at end of unit queue
3482608Swnj 	 */
3493095Swnj 	dp = &teutab[teunit];
3501919Swnj 	bp->av_forw = NULL;
3515437Sroot 	s = spl5();
3523939Sbugs 	um = tedinfo[teunit]->ui_mi;
3532608Swnj 	if (dp->b_actf == NULL) {
3542608Swnj 		dp->b_actf = bp;
3552608Swnj 		/*
3562608Swnj 		 * Transport not already active...
3572608Swnj 		 * put at end of controller queue.
3582608Swnj 		 */
3592608Swnj 		dp->b_forw = NULL;
3602608Swnj 		if (um->um_tab.b_actf == NULL)
3612608Swnj 			um->um_tab.b_actf = dp;
3622608Swnj 		else
3632608Swnj 			um->um_tab.b_actl->b_forw = dp;
3642608Swnj 		um->um_tab.b_actl = dp;
3652608Swnj 	} else
3662608Swnj 		dp->b_actl->av_forw = bp;
3672608Swnj 	dp->b_actl = bp;
3682608Swnj 	/*
3692608Swnj 	 * If the controller is not busy, get
3702608Swnj 	 * it going.
3712608Swnj 	 */
3722608Swnj 	if (um->um_tab.b_active == 0)
3732608Swnj 		tmstart(um);
3745437Sroot 	splx(s);
3751919Swnj }
3761919Swnj 
3772608Swnj /*
3782608Swnj  * Start activity on a tm controller.
3792608Swnj  */
3802608Swnj tmstart(um)
3812982Swnj 	register struct uba_ctlr *um;
3821919Swnj {
3832608Swnj 	register struct buf *bp, *dp;
3845692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
3853095Swnj 	register struct te_softc *sc;
3862982Swnj 	register struct uba_device *ui;
3873095Swnj 	int teunit, cmd;
3882471Swnj 	daddr_t blkno;
3891919Swnj 
3902608Swnj 	/*
3912608Swnj 	 * Look for an idle transport on the controller.
3922608Swnj 	 */
3931919Swnj loop:
3942608Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
3951919Swnj 		return;
3962608Swnj 	if ((bp = dp->b_actf) == NULL) {
3972608Swnj 		um->um_tab.b_actf = dp->b_forw;
3982608Swnj 		goto loop;
3992608Swnj 	}
4003095Swnj 	teunit = TEUNIT(bp->b_dev);
4013095Swnj 	ui = tedinfo[teunit];
4022608Swnj 	/*
4032608Swnj 	 * Record pre-transfer status (e.g. for TM_SENSE)
4042608Swnj 	 */
4053095Swnj 	sc = &te_softc[teunit];
4065692Sroot 	addr = (struct tmdevice *)um->um_addr;
4072608Swnj 	addr->tmcs = (ui->ui_slave << 8);
4082471Swnj 	sc->sc_dsreg = addr->tmcs;
4092471Swnj 	sc->sc_erreg = addr->tmer;
4102471Swnj 	sc->sc_resid = addr->tmbc;
4112608Swnj 	/*
4122608Swnj 	 * Default is that last command was NOT a write command;
4132608Swnj 	 * if we do a write command we will notice this in tmintr().
4142608Swnj 	 */
4153493Sroot 	sc->sc_lastiow = 0;
4162608Swnj 	if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) {
4172608Swnj 		/*
4183095Swnj 		 * Have had a hard error on a non-raw tape
4193095Swnj 		 * or the tape unit is now unavailable
4203095Swnj 		 * (e.g. taken off line).
4212608Swnj 		 */
4222608Swnj 		bp->b_flags |= B_ERROR;
4231919Swnj 		goto next;
4241919Swnj 	}
4253095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
4263095Swnj 		/*
4273095Swnj 		 * Execute control operation with the specified count.
4283095Swnj 		 */
4292608Swnj 		if (bp->b_command == TM_SENSE)
4302608Swnj 			goto next;
4313495Sroot 		/*
4323495Sroot 		 * Set next state; give 5 minutes to complete
4333495Sroot 		 * rewind, or 10 seconds per iteration (minimum 60
4343629Sroot 		 * seconds and max 5 minutes) to complete other ops.
4353495Sroot 		 */
4363495Sroot 		if (bp->b_command == TM_REW) {
4373495Sroot 			um->um_tab.b_active = SREW;
4383495Sroot 			sc->sc_timo = 5 * 60;
4393495Sroot 		} else {
4403495Sroot 			um->um_tab.b_active = SCOM;
4414266Swnj 			sc->sc_timo =
4424266Swnj 			    imin(imax(10*(int)-bp->b_repcnt,60),5*60);
4433495Sroot 		}
4442608Swnj 		if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV)
4452608Swnj 			addr->tmbc = bp->b_repcnt;
4462670Swnj 		goto dobpcmd;
4472608Swnj 	}
4482608Swnj 	/*
4493095Swnj 	 * The following checks handle boundary cases for operation
4503095Swnj 	 * on non-raw tapes.  On raw tapes the initialization of
4513095Swnj 	 * sc->sc_nxrec by tmphys causes them to be skipped normally
4523095Swnj 	 * (except in the case of retries).
4533095Swnj 	 */
4547381Ssam 	if (bdbtofsb(bp->b_blkno) > sc->sc_nxrec) {
4553095Swnj 		/*
4563095Swnj 		 * Can't read past known end-of-file.
4573095Swnj 		 */
4583095Swnj 		bp->b_flags |= B_ERROR;
4593095Swnj 		bp->b_error = ENXIO;
4603095Swnj 		goto next;
4613095Swnj 	}
4627381Ssam 	if (bdbtofsb(bp->b_blkno) == sc->sc_nxrec &&
4633095Swnj 	    bp->b_flags&B_READ) {
4643095Swnj 		/*
4653095Swnj 		 * Reading at end of file returns 0 bytes.
4663095Swnj 		 */
4673095Swnj 		bp->b_resid = bp->b_bcount;
4683095Swnj 		clrbuf(bp);
4693095Swnj 		goto next;
4703095Swnj 	}
4713095Swnj 	if ((bp->b_flags&B_READ) == 0)
4723095Swnj 		/*
4733095Swnj 		 * Writing sets EOF
4743095Swnj 		 */
4757381Ssam 		sc->sc_nxrec = bdbtofsb(bp->b_blkno) + 1;
4763095Swnj 	/*
4772608Swnj 	 * If the data transfer command is in the correct place,
4782608Swnj 	 * set up all the registers except the csr, and give
4792608Swnj 	 * control over to the UNIBUS adapter routines, to
4802608Swnj 	 * wait for resources to start the i/o.
4812608Swnj 	 */
4827381Ssam 	if ((blkno = sc->sc_blkno) == bdbtofsb(bp->b_blkno)) {
4832396Swnj 		addr->tmbc = -bp->b_bcount;
4841919Swnj 		if ((bp->b_flags&B_READ) == 0) {
4852471Swnj 			if (um->um_tab.b_errcnt)
4863095Swnj 				cmd = TM_WIRG;
4871919Swnj 			else
4883095Swnj 				cmd = TM_WCOM;
4891919Swnj 		} else
4903095Swnj 			cmd = TM_RCOM;
4912471Swnj 		um->um_tab.b_active = SIO;
4923095Swnj 		um->um_cmd = sc->sc_dens|cmd;
4932928Swnj #ifdef notdef
4942670Swnj 		if (tmreverseop(sc->sc_lastcmd))
4953095Swnj 			while (addr->tmer & TMER_SDWN)
49624974Smckusick 				DELAY(10),tmgapsdcnt++;
4972670Swnj 		sc->sc_lastcmd = TM_RCOM;		/* will serve */
4982928Swnj #endif
4993495Sroot 		sc->sc_timo = 60;	/* premature, but should serve */
5003105Swnj 		(void) ubago(ui);
5011919Swnj 		return;
5021919Swnj 	}
5032608Swnj 	/*
5043095Swnj 	 * Tape positioned incorrectly;
5053095Swnj 	 * set to seek forwards or backwards to the correct spot.
5063095Swnj 	 * This happens for raw tapes only on error retries.
5072608Swnj 	 */
5082471Swnj 	um->um_tab.b_active = SSEEK;
5097381Ssam 	if (blkno < bdbtofsb(bp->b_blkno)) {
5102670Swnj 		bp->b_command = TM_SFORW;
5117381Ssam 		addr->tmbc = blkno - bdbtofsb(bp->b_blkno);
5121919Swnj 	} else {
5132670Swnj 		bp->b_command = TM_SREV;
5147381Ssam 		addr->tmbc = bdbtofsb(bp->b_blkno) - blkno;
5151919Swnj 	}
5163629Sroot 	sc->sc_timo = imin(imax(10 * -addr->tmbc, 60), 5 * 60);
5172670Swnj dobpcmd:
5182928Swnj #ifdef notdef
5193095Swnj 	/*
5203095Swnj 	 * It is strictly necessary to wait for the tape
5213095Swnj 	 * to stop before changing directions, but the TC11
5223095Swnj 	 * handles this for us.
5233095Swnj 	 */
5242670Swnj 	if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command))
5252670Swnj 		while (addr->tmer & TM_SDWN)
52624974Smckusick 			DELAY(10),tmgapsdcnt++;
5272670Swnj 	sc->sc_lastcmd = bp->b_command;
5282928Swnj #endif
5293095Swnj 	/*
5303095Swnj 	 * Do the command in bp.
5313095Swnj 	 */
5323095Swnj 	addr->tmcs = (sc->sc_dens | bp->b_command);
5331919Swnj 	return;
5341919Swnj 
5351919Swnj next:
5362608Swnj 	/*
5372608Swnj 	 * Done with this operation due to error or
5382608Swnj 	 * the fact that it doesn't do anything.
5392608Swnj 	 * Release UBA resources (if any), dequeue
5402608Swnj 	 * the transfer and continue processing this slave.
5412608Swnj 	 */
5422608Swnj 	if (um->um_ubinfo)
5432617Swnj 		ubadone(um);
5442608Swnj 	um->um_tab.b_errcnt = 0;
5452608Swnj 	dp->b_actf = bp->av_forw;
5461919Swnj 	iodone(bp);
5471919Swnj 	goto loop;
5481919Swnj }
5491919Swnj 
5502608Swnj /*
5512608Swnj  * The UNIBUS resources we needed have been
5522608Swnj  * allocated to us; start the device.
5532608Swnj  */
5542574Swnj tmdgo(um)
5552982Swnj 	register struct uba_ctlr *um;
5561919Swnj {
5575692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
5582471Swnj 
5592574Swnj 	addr->tmba = um->um_ubinfo;
5602574Swnj 	addr->tmcs = um->um_cmd | ((um->um_ubinfo >> 12) & 0x30);
5612396Swnj }
5622396Swnj 
5632608Swnj /*
5642608Swnj  * Tm interrupt routine.
5652608Swnj  */
5662471Swnj /*ARGSUSED*/
5672630Swnj tmintr(tm11)
5682630Swnj 	int tm11;
5692396Swnj {
5702608Swnj 	struct buf *dp;
5711919Swnj 	register struct buf *bp;
5722982Swnj 	register struct uba_ctlr *um = tmminfo[tm11];
5735692Sroot 	register struct tmdevice *addr;
5743095Swnj 	register struct te_softc *sc;
5753095Swnj 	int teunit;
5761919Swnj 	register state;
5771919Swnj 
5783095Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
5793095Swnj 		return;
5803095Swnj 	bp = dp->b_actf;
5813095Swnj 	teunit = TEUNIT(bp->b_dev);
5825692Sroot 	addr = (struct tmdevice *)tedinfo[teunit]->ui_addr;
5833524Swnj 	sc = &te_softc[teunit];
5842608Swnj 	/*
5852608Swnj 	 * If last command was a rewind, and tape is still
5862608Swnj 	 * rewinding, wait for the rewind complete interrupt.
5872608Swnj 	 */
5882608Swnj 	if (um->um_tab.b_active == SREW) {
5892608Swnj 		um->um_tab.b_active = SCOM;
5903524Swnj 		if (addr->tmer&TMER_RWS) {
5913524Swnj 			sc->sc_timo = 5*60;		/* 5 minutes */
5922608Swnj 			return;
5933524Swnj 		}
5941919Swnj 	}
5952608Swnj 	/*
5962608Swnj 	 * An operation completed... record status
5972608Swnj 	 */
5983495Sroot 	sc->sc_timo = INF;
5992471Swnj 	sc->sc_dsreg = addr->tmcs;
6002471Swnj 	sc->sc_erreg = addr->tmer;
6012471Swnj 	sc->sc_resid = addr->tmbc;
6021919Swnj 	if ((bp->b_flags & B_READ) == 0)
6032608Swnj 		sc->sc_lastiow = 1;
6042471Swnj 	state = um->um_tab.b_active;
6052471Swnj 	um->um_tab.b_active = 0;
6062608Swnj 	/*
6072608Swnj 	 * Check for errors.
6082608Swnj 	 */
6092608Swnj 	if (addr->tmcs&TM_ERR) {
6103095Swnj 		while (addr->tmer & TMER_SDWN)
61124974Smckusick 			DELAY(10);			/* await settle down */
6122608Swnj 		/*
6133095Swnj 		 * If we hit the end of the tape file, update our position.
6142608Swnj 		 */
6153095Swnj 		if (addr->tmer&TMER_EOF) {
6162608Swnj 			tmseteof(bp);		/* set blkno and nxrec */
6172608Swnj 			state = SCOM;		/* force completion */
6182608Swnj 			/*
6192608Swnj 			 * Stuff bc so it will be unstuffed correctly
6202608Swnj 			 * later to get resid.
6212608Swnj 			 */
6222396Swnj 			addr->tmbc = -bp->b_bcount;
6232608Swnj 			goto opdone;
6241919Swnj 		}
6252608Swnj 		/*
6263095Swnj 		 * If we were reading raw tape and the only error was that the
6273095Swnj 		 * record was too long, then we don't consider this an error.
6282608Swnj 		 */
6293095Swnj 		if (bp == &rtmbuf[TMUNIT(bp->b_dev)] && (bp->b_flags&B_READ) &&
6303095Swnj 		    (addr->tmer&(TMER_HARD|TMER_SOFT)) == TMER_RLE)
6312608Swnj 			goto ignoreerr;
6322608Swnj 		/*
6332608Swnj 		 * If error is not hard, and this was an i/o operation
6342608Swnj 		 * retry up to 8 times.
6352608Swnj 		 */
6363095Swnj 		if ((addr->tmer&TMER_HARD)==0 && state==SIO) {
6372471Swnj 			if (++um->um_tab.b_errcnt < 7) {
6382471Swnj 				sc->sc_blkno++;
6392617Swnj 				ubadone(um);
6402608Swnj 				goto opcont;
6411919Swnj 			}
6422608Swnj 		} else
6432608Swnj 			/*
6442608Swnj 			 * Hard or non-i/o errors on non-raw tape
6452608Swnj 			 * cause it to close.
6462608Swnj 			 */
6473095Swnj 			if (sc->sc_openf>0 && bp != &rtmbuf[TMUNIT(bp->b_dev)])
6482608Swnj 				sc->sc_openf = -1;
6492608Swnj 		/*
6502608Swnj 		 * Couldn't recover error
6512608Swnj 		 */
65218321Sralph 		tprintf(sc->sc_ttyp,
65318321Sralph 		    "te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03,
6543095Swnj 		    bp->b_blkno, sc->sc_erreg, TMER_BITS);
65524974Smckusick #ifdef	AVIV
65624974Smckusick 		if (tmdiag) {
65724974Smckusick 			addr->tmmr = DAB;
65824974Smckusick 			printf("reject code 0%o", addr->tmmr & DAB_MASK);
65924974Smckusick 			addr->tmmr = DTS;
66024974Smckusick 			if (addr->tmmr & DTS_MASK)
66124974Smckusick 			    printf(", dead track 0%o", addr->tmmr & DTS_MASK);
66224974Smckusick 			addr->tmmr = RWERR;
66324974Smckusick 			printf(", read/write errors %b\n",
66424974Smckusick 			    addr->tmmr & RWERR_MASK,
66524974Smckusick 			    RWERR_BITS);
66624974Smckusick 			addr->tmmr = DRSENSE;
66724974Smckusick 			printf("drive sense %b, ", addr->tmmr & DRSENSE_MASK,
66824974Smckusick 			    DRSENSE_BITS);
66924974Smckusick 			printf("fsr %b\n", addr->tmfsr, FSR_BITS);
67024974Smckusick 		}
67124974Smckusick #endif AVIV
6721919Swnj 		bp->b_flags |= B_ERROR;
6732608Swnj 		goto opdone;
6741919Swnj 	}
6752608Swnj 	/*
6762608Swnj 	 * Advance tape control FSM.
6772608Swnj 	 */
6782608Swnj ignoreerr:
6791919Swnj 	switch (state) {
6801919Swnj 
6811919Swnj 	case SIO:
6822608Swnj 		/*
6832608Swnj 		 * Read/write increments tape block number
6842608Swnj 		 */
6852471Swnj 		sc->sc_blkno++;
6862608Swnj 		goto opdone;
6871919Swnj 
6881919Swnj 	case SCOM:
6892608Swnj 		/*
6903095Swnj 		 * For forward/backward space record update current position.
6912608Swnj 		 */
6923095Swnj 		if (bp == &ctmbuf[TMUNIT(bp->b_dev)])
69326292Skarels 		switch ((int)bp->b_command) {
6941919Swnj 
6952608Swnj 		case TM_SFORW:
6962608Swnj 			sc->sc_blkno -= bp->b_repcnt;
6973095Swnj 			break;
6981919Swnj 
6992608Swnj 		case TM_SREV:
7002608Swnj 			sc->sc_blkno += bp->b_repcnt;
7013095Swnj 			break;
7021919Swnj 		}
7033095Swnj 		goto opdone;
7041919Swnj 
7051919Swnj 	case SSEEK:
7067381Ssam 		sc->sc_blkno = bdbtofsb(bp->b_blkno);
7072608Swnj 		goto opcont;
7081919Swnj 
7091919Swnj 	default:
7102608Swnj 		panic("tmintr");
7112608Swnj 	}
7122608Swnj opdone:
7132608Swnj 	/*
7142608Swnj 	 * Reset error count and remove
7152608Swnj 	 * from device queue.
7162608Swnj 	 */
7172608Swnj 	um->um_tab.b_errcnt = 0;
7182608Swnj 	dp->b_actf = bp->av_forw;
71914929Skarels 	/*
72014929Skarels 	 * Check resid; watch out for resid >32767 (tmbc not negative).
72114929Skarels 	 */
72215081Skarels 	bp->b_resid = ((int) -addr->tmbc) & 0xffff;
7232617Swnj 	ubadone(um);
7242608Swnj 	iodone(bp);
7252608Swnj 	/*
7262608Swnj 	 * Circulate slave to end of controller
7272608Swnj 	 * queue to give other slaves a chance.
7282608Swnj 	 */
7292608Swnj 	um->um_tab.b_actf = dp->b_forw;
7302608Swnj 	if (dp->b_actf) {
7312608Swnj 		dp->b_forw = NULL;
7322608Swnj 		if (um->um_tab.b_actf == NULL)
7332608Swnj 			um->um_tab.b_actf = dp;
7342608Swnj 		else
7352608Swnj 			um->um_tab.b_actl->b_forw = dp;
7362608Swnj 		um->um_tab.b_actl = dp;
7372608Swnj 	}
7382608Swnj 	if (um->um_tab.b_actf == 0)
7391919Swnj 		return;
7402608Swnj opcont:
7412608Swnj 	tmstart(um);
7421919Swnj }
7431919Swnj 
7443495Sroot tmtimer(dev)
7453495Sroot 	int dev;
7463495Sroot {
7473495Sroot 	register struct te_softc *sc = &te_softc[TEUNIT(dev)];
7484847Sroot 	register short x;
7493495Sroot 
7503495Sroot 	if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) {
7514278Sroot 		printf("te%d: lost interrupt\n", TEUNIT(dev));
7523495Sroot 		sc->sc_timo = INF;
7534847Sroot 		x = spl5();
7543495Sroot 		tmintr(TMUNIT(dev));
7554847Sroot 		(void) splx(x);
7563495Sroot 	}
7573629Sroot 	timeout(tmtimer, (caddr_t)dev, 5*hz);
7583495Sroot }
7593495Sroot 
7601919Swnj tmseteof(bp)
7611919Swnj 	register struct buf *bp;
7621919Swnj {
7633095Swnj 	register int teunit = TEUNIT(bp->b_dev);
7645692Sroot 	register struct tmdevice *addr =
7655692Sroot 	    (struct tmdevice *)tedinfo[teunit]->ui_addr;
7663095Swnj 	register struct te_softc *sc = &te_softc[teunit];
7671919Swnj 
7683095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
7697381Ssam 		if (sc->sc_blkno > bdbtofsb(bp->b_blkno)) {
7701919Swnj 			/* reversing */
7717381Ssam 			sc->sc_nxrec = bdbtofsb(bp->b_blkno) - addr->tmbc;
7722471Swnj 			sc->sc_blkno = sc->sc_nxrec;
7731919Swnj 		} else {
7741919Swnj 			/* spacing forward */
7757381Ssam 			sc->sc_blkno = bdbtofsb(bp->b_blkno) + addr->tmbc;
7762471Swnj 			sc->sc_nxrec = sc->sc_blkno - 1;
7771919Swnj 		}
7781919Swnj 		return;
7791919Swnj 	}
7801919Swnj 	/* eof on read */
7817381Ssam 	sc->sc_nxrec = bdbtofsb(bp->b_blkno);
7821919Swnj }
7831919Swnj 
7847732Sroot tmread(dev, uio)
7852608Swnj 	dev_t dev;
7867732Sroot 	struct uio *uio;
7871919Swnj {
7888163Sroot 	int errno;
7891919Swnj 
7908163Sroot 	errno = tmphys(dev, uio);
7918163Sroot 	if (errno)
7928163Sroot 		return (errno);
7938163Sroot 	return (physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_READ, minphys, uio));
7941919Swnj }
7951919Swnj 
7967838Sroot tmwrite(dev, uio)
7972608Swnj 	dev_t dev;
7987838Sroot 	struct uio *uio;
7991919Swnj {
8008163Sroot 	int errno;
8011919Swnj 
8028163Sroot 	errno = tmphys(dev, uio);
8038163Sroot 	if (errno)
8048163Sroot 		return (errno);
8058163Sroot 	return (physio(tmstrategy, &rtmbuf[TMUNIT(dev)], dev, B_WRITE, minphys, uio));
8061919Swnj }
8071919Swnj 
8083095Swnj /*
8093095Swnj  * Check that a raw device exists.
8103095Swnj  * If it does, set up sc_blkno and sc_nxrec
8113095Swnj  * so that the tape will appear positioned correctly.
8123095Swnj  */
8137732Sroot tmphys(dev, uio)
8142608Swnj 	dev_t dev;
8157732Sroot 	struct uio *uio;
8161919Swnj {
8173095Swnj 	register int teunit = TEUNIT(dev);
8181919Swnj 	register daddr_t a;
8193095Swnj 	register struct te_softc *sc;
8203095Swnj 	register struct uba_device *ui;
8211919Swnj 
8227838Sroot 	if (teunit >= NTE || (ui=tedinfo[teunit]) == 0 || ui->ui_alive == 0)
8237732Sroot 		return (ENXIO);
8243095Swnj 	sc = &te_softc[teunit];
8257838Sroot 	a = bdbtofsb(uio->uio_offset >> 9);
8262471Swnj 	sc->sc_blkno = a;
8272471Swnj 	sc->sc_nxrec = a + 1;
8287732Sroot 	return (0);
8291919Swnj }
8301919Swnj 
8312608Swnj tmreset(uban)
8322608Swnj 	int uban;
8332608Swnj {
8342982Swnj 	register struct uba_ctlr *um;
8353095Swnj 	register tm11, teunit;
8362982Swnj 	register struct uba_device *ui;
8372608Swnj 	register struct buf *dp;
8382608Swnj 
8392630Swnj 	for (tm11 = 0; tm11 < NTM; tm11++) {
8402630Swnj 		if ((um = tmminfo[tm11]) == 0 || um->um_alive == 0 ||
8412608Swnj 		   um->um_ubanum != uban)
8422608Swnj 			continue;
8432928Swnj 		printf(" tm%d", tm11);
8442608Swnj 		um->um_tab.b_active = 0;
8452608Swnj 		um->um_tab.b_actf = um->um_tab.b_actl = 0;
8462608Swnj 		if (um->um_ubinfo) {
8472608Swnj 			printf("<%d>", (um->um_ubinfo>>28)&0xf);
8489355Ssam 			um->um_ubinfo = 0;
8492608Swnj 		}
8505692Sroot 		((struct tmdevice *)(um->um_addr))->tmcs = TM_DCLR;
8513095Swnj 		for (teunit = 0; teunit < NTE; teunit++) {
8523095Swnj 			if ((ui = tedinfo[teunit]) == 0 || ui->ui_mi != um ||
8533095Swnj 			    ui->ui_alive == 0)
8542608Swnj 				continue;
8553095Swnj 			dp = &teutab[teunit];
8562608Swnj 			dp->b_active = 0;
8572608Swnj 			dp->b_forw = 0;
8582608Swnj 			if (um->um_tab.b_actf == NULL)
8592608Swnj 				um->um_tab.b_actf = dp;
8602608Swnj 			else
8612608Swnj 				um->um_tab.b_actl->b_forw = dp;
8622608Swnj 			um->um_tab.b_actl = dp;
8633495Sroot 			if (te_softc[teunit].sc_openf > 0)
8643495Sroot 				te_softc[teunit].sc_openf = -1;
8652608Swnj 		}
8662608Swnj 		tmstart(um);
8672608Swnj 	}
8682608Swnj }
8692608Swnj 
8701919Swnj /*ARGSUSED*/
8717632Ssam tmioctl(dev, cmd, data, flag)
8727632Ssam 	caddr_t data;
8731919Swnj 	dev_t dev;
8741919Swnj {
8753095Swnj 	int teunit = TEUNIT(dev);
8763095Swnj 	register struct te_softc *sc = &te_softc[teunit];
8773095Swnj 	register struct buf *bp = &ctmbuf[TMUNIT(dev)];
8781919Swnj 	register callcount;
8791919Swnj 	int fcount;
8807632Ssam 	struct mtop *mtop;
8817632Ssam 	struct mtget *mtget;
8821919Swnj 	/* we depend of the values and order of the MT codes here */
8832608Swnj 	static tmops[] =
8842608Swnj 	   {TM_WEOF,TM_SFORW,TM_SREV,TM_SFORW,TM_SREV,TM_REW,TM_OFFL,TM_SENSE};
8851919Swnj 
8862608Swnj 	switch (cmd) {
8877632Ssam 
8887632Ssam 	case MTIOCTOP:	/* tape operation */
8897632Ssam 		mtop = (struct mtop *)data;
8908574Sroot 		switch (mtop->mt_op) {
8917632Ssam 
8922608Swnj 		case MTWEOF:
8937632Ssam 			callcount = mtop->mt_count;
8942608Swnj 			fcount = 1;
8952608Swnj 			break;
8967632Ssam 
8972608Swnj 		case MTFSF: case MTBSF:
8987632Ssam 			callcount = mtop->mt_count;
8991919Swnj 			fcount = INF;
9001919Swnj 			break;
9017632Ssam 
9021919Swnj 		case MTFSR: case MTBSR:
9031919Swnj 			callcount = 1;
9047632Ssam 			fcount = mtop->mt_count;
9051919Swnj 			break;
9067632Ssam 
9072324Skre 		case MTREW: case MTOFFL: case MTNOP:
9081919Swnj 			callcount = 1;
9091919Swnj 			fcount = 1;
9101919Swnj 			break;
9117632Ssam 
9121919Swnj 		default:
9138574Sroot 			return (ENXIO);
9141919Swnj 		}
9158574Sroot 		if (callcount <= 0 || fcount <= 0)
9168574Sroot 			return (EINVAL);
9172608Swnj 		while (--callcount >= 0) {
9187632Ssam 			tmcommand(dev, tmops[mtop->mt_op], fcount);
9197632Ssam 			if ((mtop->mt_op == MTFSR || mtop->mt_op == MTBSR) &&
9208574Sroot 			    bp->b_resid)
9218574Sroot 				return (EIO);
9223095Swnj 			if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TMER_BOT)
9231919Swnj 				break;
9241919Swnj 		}
9258648Sroot 		return (geterror(bp));
9267632Ssam 
9271919Swnj 	case MTIOCGET:
9287632Ssam 		mtget = (struct mtget *)data;
9297632Ssam 		mtget->mt_dsreg = sc->sc_dsreg;
9307632Ssam 		mtget->mt_erreg = sc->sc_erreg;
9317632Ssam 		mtget->mt_resid = sc->sc_resid;
9327632Ssam 		mtget->mt_type = MT_ISTM;
9338574Sroot 		break;
9347632Ssam 
9351919Swnj 	default:
9368574Sroot 		return (ENXIO);
9371919Swnj 	}
9388574Sroot 	return (0);
9391919Swnj }
9401919Swnj 
9411919Swnj #define	DBSIZE	20
9421919Swnj 
9432363Swnj tmdump()
9442363Swnj {
9452982Swnj 	register struct uba_device *ui;
9462396Swnj 	register struct uba_regs *up;
9475692Sroot 	register struct tmdevice *addr;
9482426Skre 	int blk, num;
9492426Skre 	int start;
9501919Swnj 
9512426Skre 	start = 0;
9522426Skre 	num = maxfree;
9532426Skre #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
9543095Swnj 	if (tedinfo[0] == 0)
9552887Swnj 		return (ENXIO);
9563095Swnj 	ui = phys(tedinfo[0], struct uba_device *);
9572396Swnj 	up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba;
9583331Swnj 	ubainit(up);
9592324Skre 	DELAY(1000000);
9605692Sroot 	addr = (struct tmdevice *)ui->ui_physaddr;
9612396Swnj 	tmwait(addr);
9622608Swnj 	addr->tmcs = TM_DCLR | TM_GO;
9631919Swnj 	while (num > 0) {
9641919Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9652396Swnj 		tmdwrite(start, blk, addr, up);
9661919Swnj 		start += blk;
9671919Swnj 		num -= blk;
9681919Swnj 	}
9692426Skre 	tmeof(addr);
9702426Skre 	tmeof(addr);
9712426Skre 	tmwait(addr);
9722887Swnj 	if (addr->tmcs&TM_ERR)
9732887Swnj 		return (EIO);
9742608Swnj 	addr->tmcs = TM_REW | TM_GO;
9752471Swnj 	tmwait(addr);
9762363Swnj 	return (0);
9771919Swnj }
9781919Swnj 
9792608Swnj tmdwrite(dbuf, num, addr, up)
9802608Swnj 	register dbuf, num;
9815692Sroot 	register struct tmdevice *addr;
9822396Swnj 	struct uba_regs *up;
9831919Swnj {
9842396Swnj 	register struct pte *io;
9852396Swnj 	register int npf;
9861928Swnj 
9872396Swnj 	tmwait(addr);
9882396Swnj 	io = up->uba_map;
9891919Swnj 	npf = num+1;
9901928Swnj 	while (--npf != 0)
9912982Swnj 		 *(int *)io++ = (dbuf++ | (1<<UBAMR_DPSHIFT) | UBAMR_MRV);
9922396Swnj 	*(int *)io = 0;
9932396Swnj 	addr->tmbc = -(num*NBPG);
9942396Swnj 	addr->tmba = 0;
9952608Swnj 	addr->tmcs = TM_WCOM | TM_GO;
9961919Swnj }
9971919Swnj 
9982396Swnj tmwait(addr)
9995692Sroot 	register struct tmdevice *addr;
10001919Swnj {
10011928Swnj 	register s;
10021919Swnj 
10031919Swnj 	do
10042396Swnj 		s = addr->tmcs;
10052608Swnj 	while ((s & TM_CUR) == 0);
10061919Swnj }
10071919Swnj 
10082396Swnj tmeof(addr)
10095692Sroot 	struct tmdevice *addr;
10101919Swnj {
10111919Swnj 
10122396Swnj 	tmwait(addr);
10132608Swnj 	addr->tmcs = TM_WEOF | TM_GO;
10141919Swnj }
10151919Swnj #endif
1016