xref: /csrg-svn/sys/vax/uba/tm.c (revision 40911)
123344Smckusick /*
229242Smckusick  * Copyright (c) 1982, 1986 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*40911Ssklower  *	@(#)tm.c	7.11 (Berkeley) 04/12/90
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 controller
173095Swnj  *	test reset code
183095Swnj  *	what happens if you offline tape during rewind?
193095Swnj  *	test using file system on tape
201919Swnj  */
2117079Sbloom #include "param.h"
2217079Sbloom #include "systm.h"
2317079Sbloom #include "buf.h"
2417079Sbloom #include "conf.h"
2517079Sbloom #include "user.h"
2640903Ssklower #include "proc.h"
2717079Sbloom #include "file.h"
2817079Sbloom #include "map.h"
2917079Sbloom #include "vm.h"
3017079Sbloom #include "ioctl.h"
3117079Sbloom #include "mtio.h"
3217079Sbloom #include "cmap.h"
3317079Sbloom #include "uio.h"
3417079Sbloom #include "kernel.h"
3518321Sralph #include "tty.h"
3630917Skarels #include "syslog.h"
371919Swnj 
3837511Smckusick #include "machine/pte.h"
398479Sroot #include "../vax/cpu.h"
4017079Sbloom #include "ubareg.h"
4117079Sbloom #include "ubavar.h"
4217079Sbloom #include "tmreg.h"
431919Swnj 
443095Swnj /*
453095Swnj  * There is a ctmbuf per tape controller.
463095Swnj  * It is used as the token to pass to the internal routines
473095Swnj  * to execute tape ioctls, and also acts as a lock on the slaves
483095Swnj  * on the controller, since there is only one per controller.
493095Swnj  * In particular, when the tape is rewinding on close we release
503095Swnj  * the user process but any further attempts to use the tape drive
513095Swnj  * before the rewind completes will hang waiting for ctmbuf.
523095Swnj  */
533095Swnj struct	buf	ctmbuf[NTM];
541919Swnj 
553095Swnj /*
563095Swnj  * Driver unibus interface routines and variables.
573095Swnj  */
582608Swnj int	tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr();
592982Swnj struct	uba_ctlr *tmminfo[NTM];
603095Swnj struct	uba_device *tedinfo[NTE];
613095Swnj struct	buf teutab[NTE];
623095Swnj short	tetotm[NTE];
632458Swnj u_short	tmstd[] = { 0772520, 0 };
642396Swnj struct	uba_driver tmdriver =
653095Swnj  { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tedinfo, "tm", tmminfo, 0 };
661919Swnj 
671919Swnj /* bits in minor device */
683095Swnj #define	TEUNIT(dev)	(minor(dev)&03)
693095Swnj #define	TMUNIT(dev)	(tetotm[TEUNIT(dev)])
701919Swnj #define	T_NOREWIND	04
7124974Smckusick #define	T_1600BPI	0x8
721919Swnj 
731919Swnj #define	INF	(daddr_t)1000000L
741919Swnj 
752608Swnj /*
762608Swnj  * Software state per tape transport.
773095Swnj  *
783095Swnj  * 1. A tape drive is a unique-open device; we refuse opens when it is already.
793095Swnj  * 2. We keep track of the current position on a block tape and seek
803095Swnj  *    before operations by forward/back spacing if necessary.
813095Swnj  * 3. We remember if the last operation was a write on a tape, so if a tape
823095Swnj  *    is open read write and the last thing done is a write we can
833095Swnj  *    write a standard end of tape mark (two eofs).
843095Swnj  * 4. We remember the status registers after the last command, using
853095Swnj  *    then internally and returning them to the SENSE ioctl.
863095Swnj  * 5. We remember the last density the tape was used at.  If it is
873095Swnj  *    not a BOT when we start using it and we are writing, we don't
883095Swnj  *    let the density be changed.
892608Swnj  */
903095Swnj struct	te_softc {
912608Swnj 	char	sc_openf;	/* lock against multiple opens */
922608Swnj 	char	sc_lastiow;	/* last op was a write */
932608Swnj 	daddr_t	sc_blkno;	/* block number, for block device tape */
943095Swnj 	daddr_t	sc_nxrec;	/* position of end of tape, if known */
952608Swnj 	u_short	sc_erreg;	/* copy of last erreg */
9633477Skarels 	u_short	sc_ioerreg;	/* copy of last erreg for I/O command */
972608Swnj 	u_short	sc_dsreg;	/* copy of last dsreg */
982608Swnj 	short	sc_resid;	/* copy of last bc */
993105Swnj #ifdef unneeded
1002670Swnj 	short	sc_lastcmd;	/* last command to handle direction changes */
1012928Swnj #endif
1023095Swnj 	u_short	sc_dens;	/* prototype command with density info */
10318321Sralph 	short	sc_tact;	/* timeout is active */
1043495Sroot 	daddr_t	sc_timo;	/* time until timeout expires */
10530917Skarels 	int	sc_blks;	/* number of I/O operations since open */
10630917Skarels 	int	sc_softerrs;	/* number of soft I/O errors since open */
10740045Smarc 	caddr_t	sc_ctty;	/* users controlling terminal (vnode) */
1086952Swnj } te_softc[NTE];
1093105Swnj #ifdef unneeded
1103105Swnj int	tmgapsdcnt;		/* DEBUG */
1113105Swnj #endif
1121919Swnj 
1132608Swnj /*
1143095Swnj  * States for um->um_tab.b_active, the per controller state flag.
1153095Swnj  * This is used to sequence control in the driver.
1162608Swnj  */
1171919Swnj #define	SSEEK	1		/* seeking */
1181919Swnj #define	SIO	2		/* doing seq i/o */
1191919Swnj #define	SCOM	3		/* sending control command */
1202608Swnj #define	SREW	4		/* sending a drive rewind */
1211919Swnj 
1222426Skre /*
1232426Skre  * Determine if there is a controller for
1242426Skre  * a tm at address reg.  Our goal is to make the
1252426Skre  * device interrupt.
1262426Skre  */
1272608Swnj tmprobe(reg)
1282396Swnj 	caddr_t reg;
1292396Swnj {
1303095Swnj 	register int br, cvec;		/* must be r11,r10; value-result */
1312426Skre 
1322608Swnj #ifdef lint
1333105Swnj 	br = 0; cvec = br; br = cvec;
1344936Swnj 	tmintr(0);
1352608Swnj #endif
1365692Sroot 	((struct tmdevice *)reg)->tmcs = TM_IE;
1372396Swnj 	/*
1382630Swnj 	 * If this is a tm11, it ought to have interrupted
1392396Swnj 	 * by now, if it isn't (ie: it is a ts04) then we just
1402458Swnj 	 * hope that it didn't interrupt, so autoconf will ignore it.
1412458Swnj 	 * Just in case, we will reference one
1422396Swnj 	 * of the more distant registers, and hope for a machine
1432458Swnj 	 * check, or similar disaster if this is a ts.
1442471Swnj 	 *
1452471Swnj 	 * Note: on an 11/780, badaddr will just generate
1462471Swnj 	 * a uba error for a ts; but our caller will notice that
1472471Swnj 	 * so we won't check for it.
1482396Swnj 	 */
1495692Sroot 	if (badaddr((caddr_t)&((struct tmdevice *)reg)->tmrd, 2))
1502458Swnj 		return (0);
1517404Skre 	return (sizeof (struct tmdevice));
1522396Swnj }
1532396Swnj 
1542608Swnj /*
1552608Swnj  * Due to a design flaw, we cannot ascertain if the tape
1562608Swnj  * exists or not unless it is on line - ie: unless a tape is
1572608Swnj  * mounted. This is too servere a restriction to bear,
1582608Swnj  * so all units are assumed to exist.
1592608Swnj  */
1602608Swnj /*ARGSUSED*/
1612574Swnj tmslave(ui, reg)
1622982Swnj 	struct uba_device *ui;
1632396Swnj 	caddr_t reg;
1642396Swnj {
1652458Swnj 
1662458Swnj 	return (1);
1672396Swnj }
1682396Swnj 
1692608Swnj /*
1703095Swnj  * Record attachment of the unit to the controller.
1712608Swnj  */
1722608Swnj /*ARGSUSED*/
1732608Swnj tmattach(ui)
1742982Swnj 	struct uba_device *ui;
1752608Swnj {
1763095Swnj 	/*
17734217Sbostic 	 * Tetotm is used in TMUNIT to index the ctmbuf
17834217Sbostic 	 * array given a te unit number.
1793095Swnj 	 */
1803095Swnj 	tetotm[ui->ui_unit] = ui->ui_mi->um_ctlr;
1812608Swnj }
1822608Swnj 
1833495Sroot int	tmtimer();
1842608Swnj /*
1852608Swnj  * Open the device.  Tapes are unique open
1862608Swnj  * devices, so we refuse if it is already open.
1872608Swnj  * We also check that a tape is available, and
1883095Swnj  * don't block waiting here; if you want to wait
1893095Swnj  * for a tape you should timeout in user code.
1902608Swnj  */
19124974Smckusick 
19224974Smckusick #ifdef AVIV
19324974Smckusick int tmdens[4] = { 0x6000, 0x0000, 0x2000, 0 };
19430917Skarels #endif AVIV
19524974Smckusick int tmdiag;
19624974Smckusick 
1971919Swnj tmopen(dev, flag)
1981919Swnj 	dev_t dev;
1991919Swnj 	int flag;
2001919Swnj {
2013095Swnj 	register int teunit;
2022982Swnj 	register struct uba_device *ui;
2033095Swnj 	register struct te_softc *sc;
20440725Skarels 	int olddens, dens, error;
2055437Sroot 	int s;
2061919Swnj 
2073095Swnj 	teunit = TEUNIT(dev);
20825051Skarels 	if (teunit>=NTE || (ui = tedinfo[teunit]) == 0 || ui->ui_alive == 0)
2098574Sroot 		return (ENXIO);
21025051Skarels 	if ((sc = &te_softc[teunit])->sc_openf)
21125051Skarels 		return (EBUSY);
21230917Skarels 	sc->sc_openf = 1;
2133209Swnj 	olddens = sc->sc_dens;
2143209Swnj 	dens = TM_IE | TM_GO | (ui->ui_slave << 8);
21524974Smckusick #ifndef AVIV
2163209Swnj 	if ((minor(dev) & T_1600BPI) == 0)
2173209Swnj 		dens |= TM_D800;
21824974Smckusick #else AVIV
21924974Smckusick 	dens |= tmdens[(minor(dev)>>3)&03];
22024974Smckusick #endif AVIV
2213209Swnj 	sc->sc_dens = dens;
2223141Swnj get:
2232608Swnj 	tmcommand(dev, TM_SENSE, 1);
2243141Swnj 	if (sc->sc_erreg&TMER_SDWN) {
22540725Skarels 		if (error = tsleep((caddr_t)&lbolt, (PZERO+1) | PCATCH,
22640725Skarels 		    devopn, 0))
22740725Skarels 			return (error);
2283141Swnj 		goto get;
2293141Swnj 	}
2303209Swnj 	sc->sc_dens = olddens;
2313710Sroot 	if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR)) {
2323710Sroot 		uprintf("te%d: not online\n", teunit);
23330917Skarels 		sc->sc_openf = 0;
2348574Sroot 		return (EIO);
2351919Swnj 	}
2363710Sroot 	if ((flag&FWRITE) && (sc->sc_erreg&TMER_WRL)) {
2373710Sroot 		uprintf("te%d: no write ring\n", teunit);
23830917Skarels 		sc->sc_openf = 0;
2398574Sroot 		return (EIO);
2403710Sroot 	}
2413710Sroot 	if ((sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
2423710Sroot 	    dens != sc->sc_dens) {
2433710Sroot 		uprintf("te%d: can't change density in mid-tape\n", teunit);
24430917Skarels 		sc->sc_openf = 0;
2458574Sroot 		return (EIO);
2463710Sroot 	}
2472471Swnj 	sc->sc_blkno = (daddr_t)0;
2482471Swnj 	sc->sc_nxrec = INF;
2492608Swnj 	sc->sc_lastiow = 0;
2503095Swnj 	sc->sc_dens = dens;
25130917Skarels 	sc->sc_blks = 0;
25230917Skarels 	sc->sc_softerrs = 0;
25340045Smarc 	sc->sc_ctty = (caddr_t)(u.u_procp->p_flag&SCTTY ?
25440045Smarc 			u.u_procp->p_session->s_ttyvp : 0);
25526369Skarels 	s = splclock();
2563495Sroot 	if (sc->sc_tact == 0) {
2573495Sroot 		sc->sc_timo = INF;
2583495Sroot 		sc->sc_tact = 1;
2593629Sroot 		timeout(tmtimer, (caddr_t)dev, 5*hz);
2603495Sroot 	}
2615437Sroot 	splx(s);
2628574Sroot 	return (0);
2631919Swnj }
2641919Swnj 
2652608Swnj /*
2662608Swnj  * Close tape device.
2672608Swnj  *
2682608Swnj  * If tape was open for writing or last operation was
2692608Swnj  * a write, then write two EOF's and backspace over the last one.
2702608Swnj  * Unless this is a non-rewinding special file, rewind the tape.
2712608Swnj  * Make the tape available to others.
2722608Swnj  */
2731919Swnj tmclose(dev, flag)
2741919Swnj 	register dev_t dev;
2751919Swnj 	register flag;
2761919Swnj {
2773095Swnj 	register struct te_softc *sc = &te_softc[TEUNIT(dev)];
2781919Swnj 
2792608Swnj 	if (flag == FWRITE || (flag&FWRITE) && sc->sc_lastiow) {
2802608Swnj 		tmcommand(dev, TM_WEOF, 1);
2812608Swnj 		tmcommand(dev, TM_WEOF, 1);
2822608Swnj 		tmcommand(dev, TM_SREV, 1);
2831919Swnj 	}
2841919Swnj 	if ((minor(dev)&T_NOREWIND) == 0)
2853095Swnj 		/*
2863095Swnj 		 * 0 count means don't hang waiting for rewind complete
2873095Swnj 		 * rather ctmbuf stays busy until the operation completes
2883095Swnj 		 * preventing further opens from completing by
2893095Swnj 		 * preventing a TM_SENSE from completing.
2903095Swnj 		 */
2913095Swnj 		tmcommand(dev, TM_REW, 0);
29230917Skarels 	if (sc->sc_blks > 100 && sc->sc_softerrs > sc->sc_blks / 100)
29330917Skarels 		log(LOG_INFO, "te%d: %d soft errors in %d blocks\n",
29430917Skarels 		    TEUNIT(dev), sc->sc_softerrs, sc->sc_blks);
2952471Swnj 	sc->sc_openf = 0;
29630917Skarels 	return (0);
2971919Swnj }
2981919Swnj 
2992608Swnj /*
3002608Swnj  * Execute a command on the tape drive
3012608Swnj  * a specified number of times.
3022608Swnj  */
3032574Swnj tmcommand(dev, com, count)
3041919Swnj 	dev_t dev;
3051919Swnj 	int com, count;
3061919Swnj {
3071919Swnj 	register struct buf *bp;
3085437Sroot 	register int s;
3091919Swnj 
3102608Swnj 	bp = &ctmbuf[TMUNIT(dev)];
3115437Sroot 	s = spl5();
3121919Swnj 	while (bp->b_flags&B_BUSY) {
3133095Swnj 		/*
3143095Swnj 		 * This special check is because B_BUSY never
3153095Swnj 		 * gets cleared in the non-waiting rewind case.
3163095Swnj 		 */
3173141Swnj 		if (bp->b_repcnt == 0 && (bp->b_flags&B_DONE))
3183095Swnj 			break;
3191919Swnj 		bp->b_flags |= B_WANTED;
3201919Swnj 		sleep((caddr_t)bp, PRIBIO);
3211919Swnj 	}
3221919Swnj 	bp->b_flags = B_BUSY|B_READ;
3235437Sroot 	splx(s);
3241919Swnj 	bp->b_dev = dev;
3251919Swnj 	bp->b_repcnt = -count;
3261919Swnj 	bp->b_command = com;
3271919Swnj 	bp->b_blkno = 0;
3281919Swnj 	tmstrategy(bp);
3293095Swnj 	/*
3303095Swnj 	 * In case of rewind from close, don't wait.
3313095Swnj 	 * This is the only case where count can be 0.
3323095Swnj 	 */
3333095Swnj 	if (count == 0)
3343095Swnj 		return;
3351919Swnj 	iowait(bp);
3361919Swnj 	if (bp->b_flags&B_WANTED)
3371919Swnj 		wakeup((caddr_t)bp);
3381919Swnj 	bp->b_flags &= B_ERROR;
3391919Swnj }
3401919Swnj 
3412608Swnj /*
3423095Swnj  * Queue a tape operation.
3432608Swnj  */
3441919Swnj tmstrategy(bp)
3451919Swnj 	register struct buf *bp;
3461919Swnj {
3473095Swnj 	int teunit = TEUNIT(bp->b_dev);
3482982Swnj 	register struct uba_ctlr *um;
3492608Swnj 	register struct buf *dp;
3505437Sroot 	int s;
3511919Swnj 
3522608Swnj 	/*
3532608Swnj 	 * Put transfer at end of unit queue
3542608Swnj 	 */
3553095Swnj 	dp = &teutab[teunit];
3561919Swnj 	bp->av_forw = NULL;
3575437Sroot 	s = spl5();
3583939Sbugs 	um = tedinfo[teunit]->ui_mi;
3592608Swnj 	if (dp->b_actf == NULL) {
3602608Swnj 		dp->b_actf = bp;
3612608Swnj 		/*
3622608Swnj 		 * Transport not already active...
3632608Swnj 		 * put at end of controller queue.
3642608Swnj 		 */
3652608Swnj 		dp->b_forw = NULL;
3662608Swnj 		if (um->um_tab.b_actf == NULL)
3672608Swnj 			um->um_tab.b_actf = dp;
3682608Swnj 		else
3692608Swnj 			um->um_tab.b_actl->b_forw = dp;
3702608Swnj 		um->um_tab.b_actl = dp;
3712608Swnj 	} else
3722608Swnj 		dp->b_actl->av_forw = bp;
3732608Swnj 	dp->b_actl = bp;
3742608Swnj 	/*
3752608Swnj 	 * If the controller is not busy, get
3762608Swnj 	 * it going.
3772608Swnj 	 */
3782608Swnj 	if (um->um_tab.b_active == 0)
3792608Swnj 		tmstart(um);
3805437Sroot 	splx(s);
3811919Swnj }
3821919Swnj 
3832608Swnj /*
3842608Swnj  * Start activity on a tm controller.
3852608Swnj  */
3862608Swnj tmstart(um)
3872982Swnj 	register struct uba_ctlr *um;
3881919Swnj {
3892608Swnj 	register struct buf *bp, *dp;
3905692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
3913095Swnj 	register struct te_softc *sc;
3922982Swnj 	register struct uba_device *ui;
3933095Swnj 	int teunit, cmd;
3942471Swnj 	daddr_t blkno;
3951919Swnj 
3962608Swnj 	/*
3972608Swnj 	 * Look for an idle transport on the controller.
3982608Swnj 	 */
3991919Swnj loop:
4002608Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
4011919Swnj 		return;
4022608Swnj 	if ((bp = dp->b_actf) == NULL) {
4032608Swnj 		um->um_tab.b_actf = dp->b_forw;
4042608Swnj 		goto loop;
4052608Swnj 	}
4063095Swnj 	teunit = TEUNIT(bp->b_dev);
4073095Swnj 	ui = tedinfo[teunit];
4082608Swnj 	/*
4092608Swnj 	 * Record pre-transfer status (e.g. for TM_SENSE)
4102608Swnj 	 */
4113095Swnj 	sc = &te_softc[teunit];
4125692Sroot 	addr = (struct tmdevice *)um->um_addr;
4132608Swnj 	addr->tmcs = (ui->ui_slave << 8);
4142471Swnj 	sc->sc_dsreg = addr->tmcs;
4152471Swnj 	sc->sc_erreg = addr->tmer;
4162471Swnj 	sc->sc_resid = addr->tmbc;
4172608Swnj 	/*
4182608Swnj 	 * Default is that last command was NOT a write command;
4192608Swnj 	 * if we do a write command we will notice this in tmintr().
4202608Swnj 	 */
4213493Sroot 	sc->sc_lastiow = 0;
4222608Swnj 	if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) {
4232608Swnj 		/*
4243095Swnj 		 * Have had a hard error on a non-raw tape
4253095Swnj 		 * or the tape unit is now unavailable
4263095Swnj 		 * (e.g. taken off line).
4272608Swnj 		 */
4282608Swnj 		bp->b_flags |= B_ERROR;
4291919Swnj 		goto next;
4301919Swnj 	}
4313095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
4323095Swnj 		/*
4333095Swnj 		 * Execute control operation with the specified count.
4343095Swnj 		 */
4352608Swnj 		if (bp->b_command == TM_SENSE)
4362608Swnj 			goto next;
4373495Sroot 		/*
4383495Sroot 		 * Set next state; give 5 minutes to complete
4393495Sroot 		 * rewind, or 10 seconds per iteration (minimum 60
4403629Sroot 		 * seconds and max 5 minutes) to complete other ops.
4413495Sroot 		 */
4423495Sroot 		if (bp->b_command == TM_REW) {
4433495Sroot 			um->um_tab.b_active = SREW;
4443495Sroot 			sc->sc_timo = 5 * 60;
4453495Sroot 		} else {
4463495Sroot 			um->um_tab.b_active = SCOM;
4474266Swnj 			sc->sc_timo =
4484266Swnj 			    imin(imax(10*(int)-bp->b_repcnt,60),5*60);
4493495Sroot 		}
4502608Swnj 		if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV)
4512608Swnj 			addr->tmbc = bp->b_repcnt;
4522670Swnj 		goto dobpcmd;
4532608Swnj 	}
4542608Swnj 	/*
45539938Skarels 	 * For raw I/O, fudge the current block number
45639938Skarels 	 * so we don't seek except on a retry.
45740045Smarc 	 * For raw I/O, fudge the current block number
45840045Smarc 	 * so we don't seek except on a retry.
4593095Swnj 	 */
46034217Sbostic 	if (bp->b_flags & B_RAW) {
46134217Sbostic 		if (um->um_tab.b_errcnt == 0) {
46234217Sbostic 			sc->sc_blkno = bdbtofsb(bp->b_blkno);
46334217Sbostic 			sc->sc_nxrec = sc->sc_blkno + 1;
46434217Sbostic 		}
46539938Skarels 	} else {
4663095Swnj 		/*
46734217Sbostic 		 * Handle boundary cases for operation
46834217Sbostic 		 * on non-raw tapes.
4693095Swnj 		 */
47034217Sbostic 		if (bdbtofsb(bp->b_blkno) > sc->sc_nxrec) {
47134217Sbostic 			/*
47234217Sbostic 			 * Can't read past known end-of-file.
47334217Sbostic 			 */
47434217Sbostic 			bp->b_flags |= B_ERROR;
47534217Sbostic 			bp->b_error = ENXIO;
47634217Sbostic 			goto next;
47734217Sbostic 		}
47834217Sbostic 		if (bdbtofsb(bp->b_blkno) == sc->sc_nxrec &&
47934217Sbostic 		    bp->b_flags&B_READ) {
48034217Sbostic 			/*
48134217Sbostic 			 * Reading at end of file returns 0 bytes.
48234217Sbostic 			 */
48334217Sbostic 			bp->b_resid = bp->b_bcount;
48434217Sbostic 			clrbuf(bp);
48534217Sbostic 			goto next;
48634217Sbostic 		}
48734217Sbostic 		if ((bp->b_flags&B_READ) == 0)
48834217Sbostic 			/*
48934217Sbostic 			 * Writing sets EOF
49034217Sbostic 			 */
49134217Sbostic 			sc->sc_nxrec = bdbtofsb(bp->b_blkno) + 1;
4923095Swnj 	}
4933095Swnj 	/*
4942608Swnj 	 * If the data transfer command is in the correct place,
4952608Swnj 	 * set up all the registers except the csr, and give
4962608Swnj 	 * control over to the UNIBUS adapter routines, to
4972608Swnj 	 * wait for resources to start the i/o.
4982608Swnj 	 */
4997381Ssam 	if ((blkno = sc->sc_blkno) == bdbtofsb(bp->b_blkno)) {
5002396Swnj 		addr->tmbc = -bp->b_bcount;
5011919Swnj 		if ((bp->b_flags&B_READ) == 0) {
50230917Skarels 			if (um->um_tab.b_errcnt &&
50333477Skarels 			    (sc->sc_ioerreg&(TMER_HARD|TMER_SOFT)) != TMER_BGL)
5043095Swnj 				cmd = TM_WIRG;
5051919Swnj 			else
5063095Swnj 				cmd = TM_WCOM;
5071919Swnj 		} else
5083095Swnj 			cmd = TM_RCOM;
5092471Swnj 		um->um_tab.b_active = SIO;
5103095Swnj 		um->um_cmd = sc->sc_dens|cmd;
5112928Swnj #ifdef notdef
5122670Swnj 		if (tmreverseop(sc->sc_lastcmd))
5133095Swnj 			while (addr->tmer & TMER_SDWN)
51424974Smckusick 				DELAY(10),tmgapsdcnt++;
5152670Swnj 		sc->sc_lastcmd = TM_RCOM;		/* will serve */
5162928Swnj #endif
5173495Sroot 		sc->sc_timo = 60;	/* premature, but should serve */
5183105Swnj 		(void) ubago(ui);
5191919Swnj 		return;
5201919Swnj 	}
5212608Swnj 	/*
5223095Swnj 	 * Tape positioned incorrectly;
5233095Swnj 	 * set to seek forwards or backwards to the correct spot.
5243095Swnj 	 * This happens for raw tapes only on error retries.
5252608Swnj 	 */
5262471Swnj 	um->um_tab.b_active = SSEEK;
5277381Ssam 	if (blkno < bdbtofsb(bp->b_blkno)) {
5282670Swnj 		bp->b_command = TM_SFORW;
5297381Ssam 		addr->tmbc = blkno - bdbtofsb(bp->b_blkno);
5301919Swnj 	} else {
5312670Swnj 		bp->b_command = TM_SREV;
5327381Ssam 		addr->tmbc = bdbtofsb(bp->b_blkno) - blkno;
5331919Swnj 	}
5343629Sroot 	sc->sc_timo = imin(imax(10 * -addr->tmbc, 60), 5 * 60);
5352670Swnj dobpcmd:
5362928Swnj #ifdef notdef
5373095Swnj 	/*
5383095Swnj 	 * It is strictly necessary to wait for the tape
5393095Swnj 	 * to stop before changing directions, but the TC11
5403095Swnj 	 * handles this for us.
5413095Swnj 	 */
5422670Swnj 	if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command))
5432670Swnj 		while (addr->tmer & TM_SDWN)
54424974Smckusick 			DELAY(10),tmgapsdcnt++;
5452670Swnj 	sc->sc_lastcmd = bp->b_command;
5462928Swnj #endif
5473095Swnj 	/*
5483095Swnj 	 * Do the command in bp.
5493095Swnj 	 */
5503095Swnj 	addr->tmcs = (sc->sc_dens | bp->b_command);
5511919Swnj 	return;
5521919Swnj 
5531919Swnj next:
5542608Swnj 	/*
5552608Swnj 	 * Done with this operation due to error or
5562608Swnj 	 * the fact that it doesn't do anything.
5572608Swnj 	 * Release UBA resources (if any), dequeue
5582608Swnj 	 * the transfer and continue processing this slave.
5592608Swnj 	 */
5602608Swnj 	if (um->um_ubinfo)
5612617Swnj 		ubadone(um);
5622608Swnj 	um->um_tab.b_errcnt = 0;
5632608Swnj 	dp->b_actf = bp->av_forw;
5641919Swnj 	iodone(bp);
5651919Swnj 	goto loop;
5661919Swnj }
5671919Swnj 
5682608Swnj /*
5692608Swnj  * The UNIBUS resources we needed have been
5702608Swnj  * allocated to us; start the device.
5712608Swnj  */
5722574Swnj tmdgo(um)
5732982Swnj 	register struct uba_ctlr *um;
5741919Swnj {
5755692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
5762471Swnj 
5772574Swnj 	addr->tmba = um->um_ubinfo;
5782574Swnj 	addr->tmcs = um->um_cmd | ((um->um_ubinfo >> 12) & 0x30);
5792396Swnj }
5802396Swnj 
5812608Swnj /*
5822608Swnj  * Tm interrupt routine.
5832608Swnj  */
5842471Swnj /*ARGSUSED*/
5852630Swnj tmintr(tm11)
5862630Swnj 	int tm11;
5872396Swnj {
5882608Swnj 	struct buf *dp;
5891919Swnj 	register struct buf *bp;
5902982Swnj 	register struct uba_ctlr *um = tmminfo[tm11];
5915692Sroot 	register struct tmdevice *addr;
5923095Swnj 	register struct te_softc *sc;
5933095Swnj 	int teunit;
5941919Swnj 	register state;
5951919Swnj 
5963095Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
5973095Swnj 		return;
5983095Swnj 	bp = dp->b_actf;
5993095Swnj 	teunit = TEUNIT(bp->b_dev);
6005692Sroot 	addr = (struct tmdevice *)tedinfo[teunit]->ui_addr;
6013524Swnj 	sc = &te_softc[teunit];
6022608Swnj 	/*
6032608Swnj 	 * If last command was a rewind, and tape is still
6042608Swnj 	 * rewinding, wait for the rewind complete interrupt.
6052608Swnj 	 */
6062608Swnj 	if (um->um_tab.b_active == SREW) {
6072608Swnj 		um->um_tab.b_active = SCOM;
6083524Swnj 		if (addr->tmer&TMER_RWS) {
6093524Swnj 			sc->sc_timo = 5*60;		/* 5 minutes */
6102608Swnj 			return;
6113524Swnj 		}
6121919Swnj 	}
6132608Swnj 	/*
6142608Swnj 	 * An operation completed... record status
6152608Swnj 	 */
6163495Sroot 	sc->sc_timo = INF;
61739938Skarels 	if (um->um_tab.b_active == SIO)
61840045Smarc 	if (um->um_tab.b_active == SIO)
61933477Skarels 		sc->sc_ioerreg = addr->tmer;
6202471Swnj 	sc->sc_dsreg = addr->tmcs;
6212471Swnj 	sc->sc_erreg = addr->tmer;
6222471Swnj 	sc->sc_resid = addr->tmbc;
6231919Swnj 	if ((bp->b_flags & B_READ) == 0)
6242608Swnj 		sc->sc_lastiow = 1;
6252471Swnj 	state = um->um_tab.b_active;
6262471Swnj 	um->um_tab.b_active = 0;
6272608Swnj 	/*
6282608Swnj 	 * Check for errors.
6292608Swnj 	 */
6302608Swnj 	if (addr->tmcs&TM_ERR) {
6313095Swnj 		while (addr->tmer & TMER_SDWN)
63224974Smckusick 			DELAY(10);			/* await settle down */
6332608Swnj 		/*
6343095Swnj 		 * If we hit the end of the tape file, update our position.
6352608Swnj 		 */
6363095Swnj 		if (addr->tmer&TMER_EOF) {
6372608Swnj 			tmseteof(bp);		/* set blkno and nxrec */
6382608Swnj 			state = SCOM;		/* force completion */
6392608Swnj 			/*
6402608Swnj 			 * Stuff bc so it will be unstuffed correctly
6412608Swnj 			 * later to get resid.
6422608Swnj 			 */
6432396Swnj 			addr->tmbc = -bp->b_bcount;
6442608Swnj 			goto opdone;
6451919Swnj 		}
6462608Swnj 		/*
6473095Swnj 		 * If we were reading raw tape and the only error was that the
6483095Swnj 		 * record was too long, then we don't consider this an error.
6492608Swnj 		 */
65034217Sbostic 		if ((bp->b_flags & (B_READ|B_RAW)) == (B_READ|B_RAW) &&
6513095Swnj 		    (addr->tmer&(TMER_HARD|TMER_SOFT)) == TMER_RLE)
6522608Swnj 			goto ignoreerr;
6532608Swnj 		/*
6542608Swnj 		 * If error is not hard, and this was an i/o operation
6552608Swnj 		 * retry up to 8 times.
6562608Swnj 		 */
6573095Swnj 		if ((addr->tmer&TMER_HARD)==0 && state==SIO) {
65840045Smarc 			if (um->um_tab.b_errcnt++ < 8) {
65930917Skarels 				if (tmdiag)
66030917Skarels 					log(LOG_DEBUG,
66130917Skarels 					    "te%d: soft error bn%d er=%b\n",
66230917Skarels 					    minor(bp->b_dev)&03,
66330917Skarels 					    bp->b_blkno, sc->sc_erreg,
66430917Skarels 					    TMER_BITS);
66540045Smarc 				sc->sc_blkno++;		/* force backspace */
6662617Swnj 				ubadone(um);
6672608Swnj 				goto opcont;
6681919Swnj 			}
6692608Swnj 		} else
6702608Swnj 			/*
6712608Swnj 			 * Hard or non-i/o errors on non-raw tape
6722608Swnj 			 * cause it to close.
6732608Swnj 			 */
67434217Sbostic 			if ((bp->b_flags&B_RAW) == 0 && sc->sc_openf > 0)
6752608Swnj 				sc->sc_openf = -1;
6762608Swnj 		/*
6772608Swnj 		 * Couldn't recover error
6782608Swnj 		 */
67940045Smarc 		tprintf(sc->sc_ctty,
68018321Sralph 		    "te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03,
6813095Swnj 		    bp->b_blkno, sc->sc_erreg, TMER_BITS);
68224974Smckusick #ifdef	AVIV
68324974Smckusick 		if (tmdiag) {
68424974Smckusick 			addr->tmmr = DAB;
68524974Smckusick 			printf("reject code 0%o", addr->tmmr & DAB_MASK);
68624974Smckusick 			addr->tmmr = DTS;
68724974Smckusick 			if (addr->tmmr & DTS_MASK)
68824974Smckusick 			    printf(", dead track 0%o", addr->tmmr & DTS_MASK);
68924974Smckusick 			addr->tmmr = RWERR;
69024974Smckusick 			printf(", read/write errors %b\n",
69124974Smckusick 			    addr->tmmr & RWERR_MASK,
69224974Smckusick 			    RWERR_BITS);
69324974Smckusick 			addr->tmmr = DRSENSE;
69424974Smckusick 			printf("drive sense %b, ", addr->tmmr & DRSENSE_MASK,
69524974Smckusick 			    DRSENSE_BITS);
69624974Smckusick 			printf("fsr %b\n", addr->tmfsr, FSR_BITS);
69724974Smckusick 		}
69824974Smckusick #endif AVIV
6991919Swnj 		bp->b_flags |= B_ERROR;
7002608Swnj 		goto opdone;
7011919Swnj 	}
7022608Swnj 	/*
7032608Swnj 	 * Advance tape control FSM.
7042608Swnj 	 */
7052608Swnj ignoreerr:
7061919Swnj 	switch (state) {
7071919Swnj 
7081919Swnj 	case SIO:
7092608Swnj 		/*
7102608Swnj 		 * Read/write increments tape block number
7112608Swnj 		 */
7122471Swnj 		sc->sc_blkno++;
71330917Skarels 		sc->sc_blks++;
71430917Skarels 		if (um->um_tab.b_errcnt)
71530917Skarels 			sc->sc_softerrs++;
7162608Swnj 		goto opdone;
7171919Swnj 
7181919Swnj 	case SCOM:
7192608Swnj 		/*
7203095Swnj 		 * For forward/backward space record update current position.
7212608Swnj 		 */
7223095Swnj 		if (bp == &ctmbuf[TMUNIT(bp->b_dev)])
72326292Skarels 		switch ((int)bp->b_command) {
7241919Swnj 
7252608Swnj 		case TM_SFORW:
7262608Swnj 			sc->sc_blkno -= bp->b_repcnt;
7273095Swnj 			break;
7281919Swnj 
7292608Swnj 		case TM_SREV:
7302608Swnj 			sc->sc_blkno += bp->b_repcnt;
7313095Swnj 			break;
7321919Swnj 		}
7333095Swnj 		goto opdone;
7341919Swnj 
7351919Swnj 	case SSEEK:
7367381Ssam 		sc->sc_blkno = bdbtofsb(bp->b_blkno);
7372608Swnj 		goto opcont;
7381919Swnj 
7391919Swnj 	default:
7402608Swnj 		panic("tmintr");
7412608Swnj 	}
7422608Swnj opdone:
7432608Swnj 	/*
7442608Swnj 	 * Reset error count and remove
7452608Swnj 	 * from device queue.
7462608Swnj 	 */
7472608Swnj 	um->um_tab.b_errcnt = 0;
7482608Swnj 	dp->b_actf = bp->av_forw;
74914929Skarels 	/*
75014929Skarels 	 * Check resid; watch out for resid >32767 (tmbc not negative).
75114929Skarels 	 */
75215081Skarels 	bp->b_resid = ((int) -addr->tmbc) & 0xffff;
7532617Swnj 	ubadone(um);
7542608Swnj 	iodone(bp);
7552608Swnj 	/*
7562608Swnj 	 * Circulate slave to end of controller
7572608Swnj 	 * queue to give other slaves a chance.
7582608Swnj 	 */
7592608Swnj 	um->um_tab.b_actf = dp->b_forw;
7602608Swnj 	if (dp->b_actf) {
7612608Swnj 		dp->b_forw = NULL;
7622608Swnj 		if (um->um_tab.b_actf == NULL)
7632608Swnj 			um->um_tab.b_actf = dp;
7642608Swnj 		else
7652608Swnj 			um->um_tab.b_actl->b_forw = dp;
7662608Swnj 		um->um_tab.b_actl = dp;
7672608Swnj 	}
7682608Swnj 	if (um->um_tab.b_actf == 0)
7691919Swnj 		return;
7702608Swnj opcont:
7712608Swnj 	tmstart(um);
7721919Swnj }
7731919Swnj 
7743495Sroot tmtimer(dev)
7753495Sroot 	int dev;
7763495Sroot {
7773495Sroot 	register struct te_softc *sc = &te_softc[TEUNIT(dev)];
7784847Sroot 	register short x;
7793495Sroot 
7803495Sroot 	if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) {
7814278Sroot 		printf("te%d: lost interrupt\n", TEUNIT(dev));
7823495Sroot 		sc->sc_timo = INF;
7834847Sroot 		x = spl5();
7843495Sroot 		tmintr(TMUNIT(dev));
7854847Sroot 		(void) splx(x);
7863495Sroot 	}
7873629Sroot 	timeout(tmtimer, (caddr_t)dev, 5*hz);
7883495Sroot }
7893495Sroot 
7901919Swnj tmseteof(bp)
7911919Swnj 	register struct buf *bp;
7921919Swnj {
7933095Swnj 	register int teunit = TEUNIT(bp->b_dev);
7945692Sroot 	register struct tmdevice *addr =
7955692Sroot 	    (struct tmdevice *)tedinfo[teunit]->ui_addr;
7963095Swnj 	register struct te_softc *sc = &te_softc[teunit];
7971919Swnj 
7983095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
7997381Ssam 		if (sc->sc_blkno > bdbtofsb(bp->b_blkno)) {
8001919Swnj 			/* reversing */
8017381Ssam 			sc->sc_nxrec = bdbtofsb(bp->b_blkno) - addr->tmbc;
8022471Swnj 			sc->sc_blkno = sc->sc_nxrec;
8031919Swnj 		} else {
8041919Swnj 			/* spacing forward */
8057381Ssam 			sc->sc_blkno = bdbtofsb(bp->b_blkno) + addr->tmbc;
8062471Swnj 			sc->sc_nxrec = sc->sc_blkno - 1;
8071919Swnj 		}
8081919Swnj 		return;
8091919Swnj 	}
8101919Swnj 	/* eof on read */
8117381Ssam 	sc->sc_nxrec = bdbtofsb(bp->b_blkno);
8121919Swnj }
8131919Swnj 
8142608Swnj tmreset(uban)
8152608Swnj 	int uban;
8162608Swnj {
8172982Swnj 	register struct uba_ctlr *um;
8183095Swnj 	register tm11, teunit;
8192982Swnj 	register struct uba_device *ui;
8202608Swnj 	register struct buf *dp;
8212608Swnj 
8222630Swnj 	for (tm11 = 0; tm11 < NTM; tm11++) {
8232630Swnj 		if ((um = tmminfo[tm11]) == 0 || um->um_alive == 0 ||
8242608Swnj 		   um->um_ubanum != uban)
8252608Swnj 			continue;
8262928Swnj 		printf(" tm%d", tm11);
8272608Swnj 		um->um_tab.b_active = 0;
8282608Swnj 		um->um_tab.b_actf = um->um_tab.b_actl = 0;
8292608Swnj 		if (um->um_ubinfo) {
8302608Swnj 			printf("<%d>", (um->um_ubinfo>>28)&0xf);
8319355Ssam 			um->um_ubinfo = 0;
8322608Swnj 		}
8335692Sroot 		((struct tmdevice *)(um->um_addr))->tmcs = TM_DCLR;
8343095Swnj 		for (teunit = 0; teunit < NTE; teunit++) {
8353095Swnj 			if ((ui = tedinfo[teunit]) == 0 || ui->ui_mi != um ||
8363095Swnj 			    ui->ui_alive == 0)
8372608Swnj 				continue;
8383095Swnj 			dp = &teutab[teunit];
8392608Swnj 			dp->b_active = 0;
8402608Swnj 			dp->b_forw = 0;
8412608Swnj 			if (um->um_tab.b_actf == NULL)
8422608Swnj 				um->um_tab.b_actf = dp;
8432608Swnj 			else
8442608Swnj 				um->um_tab.b_actl->b_forw = dp;
8452608Swnj 			um->um_tab.b_actl = dp;
8463495Sroot 			if (te_softc[teunit].sc_openf > 0)
8473495Sroot 				te_softc[teunit].sc_openf = -1;
8482608Swnj 		}
8492608Swnj 		tmstart(um);
8502608Swnj 	}
8512608Swnj }
8522608Swnj 
8531919Swnj /*ARGSUSED*/
8547632Ssam tmioctl(dev, cmd, data, flag)
8557632Ssam 	caddr_t data;
8561919Swnj 	dev_t dev;
8571919Swnj {
8583095Swnj 	int teunit = TEUNIT(dev);
8593095Swnj 	register struct te_softc *sc = &te_softc[teunit];
8603095Swnj 	register struct buf *bp = &ctmbuf[TMUNIT(dev)];
8611919Swnj 	register callcount;
862*40911Ssklower 	int fcount, error = 0;
8637632Ssam 	struct mtop *mtop;
8647632Ssam 	struct mtget *mtget;
8651919Swnj 	/* we depend of the values and order of the MT codes here */
8662608Swnj 	static tmops[] =
8672608Swnj 	   {TM_WEOF,TM_SFORW,TM_SREV,TM_SFORW,TM_SREV,TM_REW,TM_OFFL,TM_SENSE};
8681919Swnj 
8692608Swnj 	switch (cmd) {
8707632Ssam 
8717632Ssam 	case MTIOCTOP:	/* tape operation */
8727632Ssam 		mtop = (struct mtop *)data;
8738574Sroot 		switch (mtop->mt_op) {
8747632Ssam 
8752608Swnj 		case MTWEOF:
8767632Ssam 			callcount = mtop->mt_count;
8772608Swnj 			fcount = 1;
8782608Swnj 			break;
8797632Ssam 
8802608Swnj 		case MTFSF: case MTBSF:
8817632Ssam 			callcount = mtop->mt_count;
8821919Swnj 			fcount = INF;
8831919Swnj 			break;
8847632Ssam 
8851919Swnj 		case MTFSR: case MTBSR:
8861919Swnj 			callcount = 1;
8877632Ssam 			fcount = mtop->mt_count;
8881919Swnj 			break;
8897632Ssam 
8902324Skre 		case MTREW: case MTOFFL: case MTNOP:
8911919Swnj 			callcount = 1;
8921919Swnj 			fcount = 1;
8931919Swnj 			break;
8947632Ssam 
8951919Swnj 		default:
8968574Sroot 			return (ENXIO);
8971919Swnj 		}
8988574Sroot 		if (callcount <= 0 || fcount <= 0)
8998574Sroot 			return (EINVAL);
9002608Swnj 		while (--callcount >= 0) {
9017632Ssam 			tmcommand(dev, tmops[mtop->mt_op], fcount);
9027632Ssam 			if ((mtop->mt_op == MTFSR || mtop->mt_op == MTBSR) &&
9038574Sroot 			    bp->b_resid)
9048574Sroot 				return (EIO);
9053095Swnj 			if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TMER_BOT)
9061919Swnj 				break;
9071919Swnj 		}
908*40911Ssklower 		if (bp->b_flags&B_ERROR)
909*40911Ssklower 			if ((error = bp->b_error)==0)
910*40911Ssklower 				return (EIO);
911*40911Ssklower 		return (error);
9127632Ssam 
9131919Swnj 	case MTIOCGET:
9147632Ssam 		mtget = (struct mtget *)data;
9157632Ssam 		mtget->mt_dsreg = sc->sc_dsreg;
9167632Ssam 		mtget->mt_erreg = sc->sc_erreg;
9177632Ssam 		mtget->mt_resid = sc->sc_resid;
9187632Ssam 		mtget->mt_type = MT_ISTM;
9198574Sroot 		break;
9207632Ssam 
9211919Swnj 	default:
9228574Sroot 		return (ENXIO);
9231919Swnj 	}
9248574Sroot 	return (0);
9251919Swnj }
9261919Swnj 
9271919Swnj #define	DBSIZE	20
9281919Swnj 
9292363Swnj tmdump()
9302363Swnj {
9312982Swnj 	register struct uba_device *ui;
9322396Swnj 	register struct uba_regs *up;
9335692Sroot 	register struct tmdevice *addr;
9342426Skre 	int blk, num;
9352426Skre 	int start;
9361919Swnj 
9372426Skre 	start = 0;
9382426Skre 	num = maxfree;
9392426Skre #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
9403095Swnj 	if (tedinfo[0] == 0)
9412887Swnj 		return (ENXIO);
9423095Swnj 	ui = phys(tedinfo[0], struct uba_device *);
9432396Swnj 	up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba;
9443331Swnj 	ubainit(up);
9452324Skre 	DELAY(1000000);
9465692Sroot 	addr = (struct tmdevice *)ui->ui_physaddr;
9472396Swnj 	tmwait(addr);
9482608Swnj 	addr->tmcs = TM_DCLR | TM_GO;
9491919Swnj 	while (num > 0) {
9501919Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9512396Swnj 		tmdwrite(start, blk, addr, up);
9521919Swnj 		start += blk;
9531919Swnj 		num -= blk;
9541919Swnj 	}
9552426Skre 	tmeof(addr);
9562426Skre 	tmeof(addr);
9572426Skre 	tmwait(addr);
9582887Swnj 	if (addr->tmcs&TM_ERR)
9592887Swnj 		return (EIO);
9602608Swnj 	addr->tmcs = TM_REW | TM_GO;
9612471Swnj 	tmwait(addr);
9622363Swnj 	return (0);
9631919Swnj }
9641919Swnj 
9652608Swnj tmdwrite(dbuf, num, addr, up)
9662608Swnj 	register dbuf, num;
9675692Sroot 	register struct tmdevice *addr;
9682396Swnj 	struct uba_regs *up;
9691919Swnj {
9702396Swnj 	register struct pte *io;
9712396Swnj 	register int npf;
9721928Swnj 
9732396Swnj 	tmwait(addr);
9742396Swnj 	io = up->uba_map;
9751919Swnj 	npf = num+1;
9761928Swnj 	while (--npf != 0)
9772982Swnj 		 *(int *)io++ = (dbuf++ | (1<<UBAMR_DPSHIFT) | UBAMR_MRV);
9782396Swnj 	*(int *)io = 0;
9792396Swnj 	addr->tmbc = -(num*NBPG);
9802396Swnj 	addr->tmba = 0;
9812608Swnj 	addr->tmcs = TM_WCOM | TM_GO;
9821919Swnj }
9831919Swnj 
9842396Swnj tmwait(addr)
9855692Sroot 	register struct tmdevice *addr;
9861919Swnj {
9871928Swnj 	register s;
9881919Swnj 
9891919Swnj 	do
9902396Swnj 		s = addr->tmcs;
9912608Swnj 	while ((s & TM_CUR) == 0);
9921919Swnj }
9931919Swnj 
9942396Swnj tmeof(addr)
9955692Sroot 	struct tmdevice *addr;
9961919Swnj {
9971919Swnj 
9982396Swnj 	tmwait(addr);
9992608Swnj 	addr->tmcs = TM_WEOF | TM_GO;
10001919Swnj }
10011919Swnj #endif
1002