xref: /csrg-svn/sys/vax/uba/tm.c (revision 45806)
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*45806Sbostic  *	@(#)tm.c	7.14 (Berkeley) 12/16/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  */
21*45806Sbostic #include "sys/param.h"
22*45806Sbostic #include "sys/systm.h"
23*45806Sbostic #include "sys/buf.h"
24*45806Sbostic #include "sys/conf.h"
25*45806Sbostic #include "sys/user.h"
26*45806Sbostic #include "sys/file.h"
27*45806Sbostic #include "sys/map.h"
28*45806Sbostic #include "sys/vm.h"
29*45806Sbostic #include "sys/ioctl.h"
30*45806Sbostic #include "sys/mtio.h"
31*45806Sbostic #include "sys/cmap.h"
32*45806Sbostic #include "sys/uio.h"
33*45806Sbostic #include "sys/kernel.h"
34*45806Sbostic #include "sys/syslog.h"
35*45806Sbostic #include "sys/tprintf.h"
361919Swnj 
37*45806Sbostic #include "../include/pte.h"
38*45806Sbostic #include "../include/cpu.h"
3917079Sbloom #include "ubareg.h"
4017079Sbloom #include "ubavar.h"
4117079Sbloom #include "tmreg.h"
421919Swnj 
433095Swnj /*
443095Swnj  * There is a ctmbuf per tape controller.
453095Swnj  * It is used as the token to pass to the internal routines
463095Swnj  * to execute tape ioctls, and also acts as a lock on the slaves
473095Swnj  * on the controller, since there is only one per controller.
483095Swnj  * In particular, when the tape is rewinding on close we release
493095Swnj  * the user process but any further attempts to use the tape drive
503095Swnj  * before the rewind completes will hang waiting for ctmbuf.
513095Swnj  */
523095Swnj struct	buf	ctmbuf[NTM];
531919Swnj 
543095Swnj /*
553095Swnj  * Driver unibus interface routines and variables.
563095Swnj  */
572608Swnj int	tmprobe(), tmslave(), tmattach(), tmdgo(), tmintr();
582982Swnj struct	uba_ctlr *tmminfo[NTM];
593095Swnj struct	uba_device *tedinfo[NTE];
603095Swnj struct	buf teutab[NTE];
613095Swnj short	tetotm[NTE];
622458Swnj u_short	tmstd[] = { 0772520, 0 };
632396Swnj struct	uba_driver tmdriver =
643095Swnj  { tmprobe, tmslave, tmattach, tmdgo, tmstd, "te", tedinfo, "tm", tmminfo, 0 };
651919Swnj 
661919Swnj /* bits in minor device */
673095Swnj #define	TEUNIT(dev)	(minor(dev)&03)
683095Swnj #define	TMUNIT(dev)	(tetotm[TEUNIT(dev)])
691919Swnj #define	T_NOREWIND	04
7024974Smckusick #define	T_1600BPI	0x8
711919Swnj 
721919Swnj #define	INF	(daddr_t)1000000L
731919Swnj 
742608Swnj /*
752608Swnj  * Software state per tape transport.
763095Swnj  *
773095Swnj  * 1. A tape drive is a unique-open device; we refuse opens when it is already.
783095Swnj  * 2. We keep track of the current position on a block tape and seek
793095Swnj  *    before operations by forward/back spacing if necessary.
803095Swnj  * 3. We remember if the last operation was a write on a tape, so if a tape
813095Swnj  *    is open read write and the last thing done is a write we can
823095Swnj  *    write a standard end of tape mark (two eofs).
833095Swnj  * 4. We remember the status registers after the last command, using
843095Swnj  *    then internally and returning them to the SENSE ioctl.
853095Swnj  * 5. We remember the last density the tape was used at.  If it is
863095Swnj  *    not a BOT when we start using it and we are writing, we don't
873095Swnj  *    let the density be changed.
882608Swnj  */
893095Swnj struct	te_softc {
902608Swnj 	char	sc_openf;	/* lock against multiple opens */
912608Swnj 	char	sc_lastiow;	/* last op was a write */
922608Swnj 	daddr_t	sc_blkno;	/* block number, for block device tape */
933095Swnj 	daddr_t	sc_nxrec;	/* position of end of tape, if known */
942608Swnj 	u_short	sc_erreg;	/* copy of last erreg */
9533477Skarels 	u_short	sc_ioerreg;	/* copy of last erreg for I/O command */
962608Swnj 	u_short	sc_dsreg;	/* copy of last dsreg */
972608Swnj 	short	sc_resid;	/* copy of last bc */
983105Swnj #ifdef unneeded
992670Swnj 	short	sc_lastcmd;	/* last command to handle direction changes */
1002928Swnj #endif
1013095Swnj 	u_short	sc_dens;	/* prototype command with density info */
10218321Sralph 	short	sc_tact;	/* timeout is active */
1033495Sroot 	daddr_t	sc_timo;	/* time until timeout expires */
10430917Skarels 	int	sc_blks;	/* number of I/O operations since open */
10530917Skarels 	int	sc_softerrs;	/* number of soft I/O errors since open */
10644395Smarc 	tpr_t	sc_tpr;		/* tprintf handle */
1076952Swnj } te_softc[NTE];
1083105Swnj #ifdef unneeded
1093105Swnj int	tmgapsdcnt;		/* DEBUG */
1103105Swnj #endif
1111919Swnj 
1122608Swnj /*
1133095Swnj  * States for um->um_tab.b_active, the per controller state flag.
1143095Swnj  * This is used to sequence control in the driver.
1152608Swnj  */
1161919Swnj #define	SSEEK	1		/* seeking */
1171919Swnj #define	SIO	2		/* doing seq i/o */
1181919Swnj #define	SCOM	3		/* sending control command */
1192608Swnj #define	SREW	4		/* sending a drive rewind */
1201919Swnj 
1212426Skre /*
1222426Skre  * Determine if there is a controller for
1232426Skre  * a tm at address reg.  Our goal is to make the
1242426Skre  * device interrupt.
1252426Skre  */
tmprobe(reg)1262608Swnj tmprobe(reg)
1272396Swnj 	caddr_t reg;
1282396Swnj {
1293095Swnj 	register int br, cvec;		/* must be r11,r10; value-result */
1302426Skre 
1312608Swnj #ifdef lint
1323105Swnj 	br = 0; cvec = br; br = cvec;
1334936Swnj 	tmintr(0);
1342608Swnj #endif
1355692Sroot 	((struct tmdevice *)reg)->tmcs = TM_IE;
1362396Swnj 	/*
1372630Swnj 	 * If this is a tm11, it ought to have interrupted
1382396Swnj 	 * by now, if it isn't (ie: it is a ts04) then we just
1392458Swnj 	 * hope that it didn't interrupt, so autoconf will ignore it.
1402458Swnj 	 * Just in case, we will reference one
1412396Swnj 	 * of the more distant registers, and hope for a machine
1422458Swnj 	 * check, or similar disaster if this is a ts.
1432471Swnj 	 *
1442471Swnj 	 * Note: on an 11/780, badaddr will just generate
1452471Swnj 	 * a uba error for a ts; but our caller will notice that
1462471Swnj 	 * so we won't check for it.
1472396Swnj 	 */
1485692Sroot 	if (badaddr((caddr_t)&((struct tmdevice *)reg)->tmrd, 2))
1492458Swnj 		return (0);
1507404Skre 	return (sizeof (struct tmdevice));
1512396Swnj }
1522396Swnj 
1532608Swnj /*
1542608Swnj  * Due to a design flaw, we cannot ascertain if the tape
1552608Swnj  * exists or not unless it is on line - ie: unless a tape is
1562608Swnj  * mounted. This is too servere a restriction to bear,
1572608Swnj  * so all units are assumed to exist.
1582608Swnj  */
1592608Swnj /*ARGSUSED*/
1602574Swnj tmslave(ui, reg)
1612982Swnj 	struct uba_device *ui;
1622396Swnj 	caddr_t reg;
1632396Swnj {
1642458Swnj 
1652458Swnj 	return (1);
1662396Swnj }
1672396Swnj 
1682608Swnj /*
1693095Swnj  * Record attachment of the unit to the controller.
1702608Swnj  */
1712608Swnj /*ARGSUSED*/
1722608Swnj tmattach(ui)
1732982Swnj 	struct uba_device *ui;
1742608Swnj {
1753095Swnj 	/*
17634217Sbostic 	 * Tetotm is used in TMUNIT to index the ctmbuf
17734217Sbostic 	 * array given a te unit number.
1783095Swnj 	 */
1793095Swnj 	tetotm[ui->ui_unit] = ui->ui_mi->um_ctlr;
1802608Swnj }
1812608Swnj 
1823495Sroot int	tmtimer();
1832608Swnj /*
1842608Swnj  * Open the device.  Tapes are unique open
1852608Swnj  * devices, so we refuse if it is already open.
1862608Swnj  * We also check that a tape is available, and
1873095Swnj  * don't block waiting here; if you want to wait
1883095Swnj  * for a tape you should timeout in user code.
1892608Swnj  */
19024974Smckusick 
19124974Smckusick #ifdef AVIV
19224974Smckusick int tmdens[4] = { 0x6000, 0x0000, 0x2000, 0 };
19330917Skarels #endif AVIV
19424974Smckusick int tmdiag;
19524974Smckusick 
tmopen(dev,flag)1961919Swnj tmopen(dev, flag)
1971919Swnj 	dev_t dev;
1981919Swnj 	int flag;
1991919Swnj {
2003095Swnj 	register int teunit;
2012982Swnj 	register struct uba_device *ui;
2023095Swnj 	register struct te_softc *sc;
20340725Skarels 	int olddens, dens, error;
2045437Sroot 	int s;
2051919Swnj 
2063095Swnj 	teunit = TEUNIT(dev);
20725051Skarels 	if (teunit>=NTE || (ui = tedinfo[teunit]) == 0 || ui->ui_alive == 0)
2088574Sroot 		return (ENXIO);
20925051Skarels 	if ((sc = &te_softc[teunit])->sc_openf)
21025051Skarels 		return (EBUSY);
21130917Skarels 	sc->sc_openf = 1;
2123209Swnj 	olddens = sc->sc_dens;
2133209Swnj 	dens = TM_IE | TM_GO | (ui->ui_slave << 8);
21424974Smckusick #ifndef AVIV
2153209Swnj 	if ((minor(dev) & T_1600BPI) == 0)
2163209Swnj 		dens |= TM_D800;
21724974Smckusick #else AVIV
21824974Smckusick 	dens |= tmdens[(minor(dev)>>3)&03];
21924974Smckusick #endif AVIV
2203209Swnj 	sc->sc_dens = dens;
2213141Swnj get:
2222608Swnj 	tmcommand(dev, TM_SENSE, 1);
2233141Swnj 	if (sc->sc_erreg&TMER_SDWN) {
22440725Skarels 		if (error = tsleep((caddr_t)&lbolt, (PZERO+1) | PCATCH,
22540725Skarels 		    devopn, 0))
22640725Skarels 			return (error);
2273141Swnj 		goto get;
2283141Swnj 	}
2293209Swnj 	sc->sc_dens = olddens;
2303710Sroot 	if ((sc->sc_erreg&(TMER_SELR|TMER_TUR)) != (TMER_SELR|TMER_TUR)) {
2313710Sroot 		uprintf("te%d: not online\n", teunit);
23230917Skarels 		sc->sc_openf = 0;
2338574Sroot 		return (EIO);
2341919Swnj 	}
2353710Sroot 	if ((flag&FWRITE) && (sc->sc_erreg&TMER_WRL)) {
2363710Sroot 		uprintf("te%d: no write ring\n", teunit);
23730917Skarels 		sc->sc_openf = 0;
2388574Sroot 		return (EIO);
2393710Sroot 	}
2403710Sroot 	if ((sc->sc_erreg&TMER_BOT) == 0 && (flag&FWRITE) &&
2413710Sroot 	    dens != sc->sc_dens) {
2423710Sroot 		uprintf("te%d: can't change density in mid-tape\n", teunit);
24330917Skarels 		sc->sc_openf = 0;
2448574Sroot 		return (EIO);
2453710Sroot 	}
2462471Swnj 	sc->sc_blkno = (daddr_t)0;
2472471Swnj 	sc->sc_nxrec = INF;
2482608Swnj 	sc->sc_lastiow = 0;
2493095Swnj 	sc->sc_dens = dens;
25030917Skarels 	sc->sc_blks = 0;
25130917Skarels 	sc->sc_softerrs = 0;
25244395Smarc 	sc->sc_tpr = tprintf_open();
25326369Skarels 	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  */
tmclose(dev,flag)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);
29030917Skarels 	if (sc->sc_blks > 100 && sc->sc_softerrs > sc->sc_blks / 100)
29130917Skarels 		log(LOG_INFO, "te%d: %d soft errors in %d blocks\n",
29230917Skarels 		    TEUNIT(dev), sc->sc_softerrs, sc->sc_blks);
29344395Smarc 	tprintf_close(sc->sc_tpr);
2942471Swnj 	sc->sc_openf = 0;
29530917Skarels 	return (0);
2961919Swnj }
2971919Swnj 
2982608Swnj /*
2992608Swnj  * Execute a command on the tape drive
3002608Swnj  * a specified number of times.
3012608Swnj  */
tmcommand(dev,com,count)3022574Swnj tmcommand(dev, com, count)
3031919Swnj 	dev_t dev;
3041919Swnj 	int com, count;
3051919Swnj {
3061919Swnj 	register struct buf *bp;
3075437Sroot 	register int s;
3081919Swnj 
3092608Swnj 	bp = &ctmbuf[TMUNIT(dev)];
3105437Sroot 	s = spl5();
3111919Swnj 	while (bp->b_flags&B_BUSY) {
3123095Swnj 		/*
3133095Swnj 		 * This special check is because B_BUSY never
3143095Swnj 		 * gets cleared in the non-waiting rewind case.
3153095Swnj 		 */
3163141Swnj 		if (bp->b_repcnt == 0 && (bp->b_flags&B_DONE))
3173095Swnj 			break;
3181919Swnj 		bp->b_flags |= B_WANTED;
3191919Swnj 		sleep((caddr_t)bp, PRIBIO);
3201919Swnj 	}
3211919Swnj 	bp->b_flags = B_BUSY|B_READ;
3225437Sroot 	splx(s);
3231919Swnj 	bp->b_dev = dev;
3241919Swnj 	bp->b_repcnt = -count;
3251919Swnj 	bp->b_command = com;
3261919Swnj 	bp->b_blkno = 0;
3271919Swnj 	tmstrategy(bp);
3283095Swnj 	/*
3293095Swnj 	 * In case of rewind from close, don't wait.
3303095Swnj 	 * This is the only case where count can be 0.
3313095Swnj 	 */
3323095Swnj 	if (count == 0)
3333095Swnj 		return;
3341919Swnj 	iowait(bp);
3351919Swnj 	if (bp->b_flags&B_WANTED)
3361919Swnj 		wakeup((caddr_t)bp);
3371919Swnj 	bp->b_flags &= B_ERROR;
3381919Swnj }
3391919Swnj 
3402608Swnj /*
3413095Swnj  * Queue a tape operation.
3422608Swnj  */
tmstrategy(bp)3431919Swnj tmstrategy(bp)
3441919Swnj 	register struct buf *bp;
3451919Swnj {
3463095Swnj 	int teunit = TEUNIT(bp->b_dev);
3472982Swnj 	register struct uba_ctlr *um;
3482608Swnj 	register struct buf *dp;
3495437Sroot 	int s;
3501919Swnj 
3512608Swnj 	/*
3522608Swnj 	 * Put transfer at end of unit queue
3532608Swnj 	 */
3543095Swnj 	dp = &teutab[teunit];
3551919Swnj 	bp->av_forw = NULL;
3565437Sroot 	s = spl5();
3573939Sbugs 	um = tedinfo[teunit]->ui_mi;
3582608Swnj 	if (dp->b_actf == NULL) {
3592608Swnj 		dp->b_actf = bp;
3602608Swnj 		/*
3612608Swnj 		 * Transport not already active...
3622608Swnj 		 * put at end of controller queue.
3632608Swnj 		 */
3642608Swnj 		dp->b_forw = NULL;
3652608Swnj 		if (um->um_tab.b_actf == NULL)
3662608Swnj 			um->um_tab.b_actf = dp;
3672608Swnj 		else
3682608Swnj 			um->um_tab.b_actl->b_forw = dp;
3692608Swnj 		um->um_tab.b_actl = dp;
3702608Swnj 	} else
3712608Swnj 		dp->b_actl->av_forw = bp;
3722608Swnj 	dp->b_actl = bp;
3732608Swnj 	/*
3742608Swnj 	 * If the controller is not busy, get
3752608Swnj 	 * it going.
3762608Swnj 	 */
3772608Swnj 	if (um->um_tab.b_active == 0)
3782608Swnj 		tmstart(um);
3795437Sroot 	splx(s);
3801919Swnj }
3811919Swnj 
3822608Swnj /*
3832608Swnj  * Start activity on a tm controller.
3842608Swnj  */
tmstart(um)3852608Swnj tmstart(um)
3862982Swnj 	register struct uba_ctlr *um;
3871919Swnj {
3882608Swnj 	register struct buf *bp, *dp;
3895692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
3903095Swnj 	register struct te_softc *sc;
3912982Swnj 	register struct uba_device *ui;
3923095Swnj 	int teunit, cmd;
3932471Swnj 	daddr_t blkno;
3941919Swnj 
3952608Swnj 	/*
3962608Swnj 	 * Look for an idle transport on the controller.
3972608Swnj 	 */
3981919Swnj loop:
3992608Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
4001919Swnj 		return;
4012608Swnj 	if ((bp = dp->b_actf) == NULL) {
4022608Swnj 		um->um_tab.b_actf = dp->b_forw;
4032608Swnj 		goto loop;
4042608Swnj 	}
4053095Swnj 	teunit = TEUNIT(bp->b_dev);
4063095Swnj 	ui = tedinfo[teunit];
4072608Swnj 	/*
4082608Swnj 	 * Record pre-transfer status (e.g. for TM_SENSE)
4092608Swnj 	 */
4103095Swnj 	sc = &te_softc[teunit];
4115692Sroot 	addr = (struct tmdevice *)um->um_addr;
4122608Swnj 	addr->tmcs = (ui->ui_slave << 8);
4132471Swnj 	sc->sc_dsreg = addr->tmcs;
4142471Swnj 	sc->sc_erreg = addr->tmer;
4152471Swnj 	sc->sc_resid = addr->tmbc;
4162608Swnj 	/*
4172608Swnj 	 * Default is that last command was NOT a write command;
4182608Swnj 	 * if we do a write command we will notice this in tmintr().
4192608Swnj 	 */
4203493Sroot 	sc->sc_lastiow = 0;
4212608Swnj 	if (sc->sc_openf < 0 || (addr->tmcs&TM_CUR) == 0) {
4222608Swnj 		/*
4233095Swnj 		 * Have had a hard error on a non-raw tape
4243095Swnj 		 * or the tape unit is now unavailable
4253095Swnj 		 * (e.g. taken off line).
4262608Swnj 		 */
4272608Swnj 		bp->b_flags |= B_ERROR;
4281919Swnj 		goto next;
4291919Swnj 	}
4303095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
4313095Swnj 		/*
4323095Swnj 		 * Execute control operation with the specified count.
4333095Swnj 		 */
4342608Swnj 		if (bp->b_command == TM_SENSE)
4352608Swnj 			goto next;
4363495Sroot 		/*
4373495Sroot 		 * Set next state; give 5 minutes to complete
4383495Sroot 		 * rewind, or 10 seconds per iteration (minimum 60
4393629Sroot 		 * seconds and max 5 minutes) to complete other ops.
4403495Sroot 		 */
4413495Sroot 		if (bp->b_command == TM_REW) {
4423495Sroot 			um->um_tab.b_active = SREW;
4433495Sroot 			sc->sc_timo = 5 * 60;
4443495Sroot 		} else {
4453495Sroot 			um->um_tab.b_active = SCOM;
4464266Swnj 			sc->sc_timo =
4474266Swnj 			    imin(imax(10*(int)-bp->b_repcnt,60),5*60);
4483495Sroot 		}
4492608Swnj 		if (bp->b_command == TM_SFORW || bp->b_command == TM_SREV)
4502608Swnj 			addr->tmbc = bp->b_repcnt;
4512670Swnj 		goto dobpcmd;
4522608Swnj 	}
4532608Swnj 	/*
45439938Skarels 	 * For raw I/O, fudge the current block number
45539938Skarels 	 * so we don't seek except on a retry.
45640045Smarc 	 * For raw I/O, fudge the current block number
45740045Smarc 	 * so we don't seek except on a retry.
4583095Swnj 	 */
45934217Sbostic 	if (bp->b_flags & B_RAW) {
46034217Sbostic 		if (um->um_tab.b_errcnt == 0) {
46134217Sbostic 			sc->sc_blkno = bdbtofsb(bp->b_blkno);
46234217Sbostic 			sc->sc_nxrec = sc->sc_blkno + 1;
46334217Sbostic 		}
46439938Skarels 	} else {
4653095Swnj 		/*
46634217Sbostic 		 * Handle boundary cases for operation
46734217Sbostic 		 * on non-raw tapes.
4683095Swnj 		 */
46934217Sbostic 		if (bdbtofsb(bp->b_blkno) > sc->sc_nxrec) {
47034217Sbostic 			/*
47134217Sbostic 			 * Can't read past known end-of-file.
47234217Sbostic 			 */
47334217Sbostic 			bp->b_flags |= B_ERROR;
47434217Sbostic 			bp->b_error = ENXIO;
47534217Sbostic 			goto next;
47634217Sbostic 		}
47734217Sbostic 		if (bdbtofsb(bp->b_blkno) == sc->sc_nxrec &&
47834217Sbostic 		    bp->b_flags&B_READ) {
47934217Sbostic 			/*
48034217Sbostic 			 * Reading at end of file returns 0 bytes.
48134217Sbostic 			 */
48234217Sbostic 			bp->b_resid = bp->b_bcount;
48334217Sbostic 			clrbuf(bp);
48434217Sbostic 			goto next;
48534217Sbostic 		}
48634217Sbostic 		if ((bp->b_flags&B_READ) == 0)
48734217Sbostic 			/*
48834217Sbostic 			 * Writing sets EOF
48934217Sbostic 			 */
49034217Sbostic 			sc->sc_nxrec = bdbtofsb(bp->b_blkno) + 1;
4913095Swnj 	}
4923095Swnj 	/*
4932608Swnj 	 * If the data transfer command is in the correct place,
4942608Swnj 	 * set up all the registers except the csr, and give
4952608Swnj 	 * control over to the UNIBUS adapter routines, to
4962608Swnj 	 * wait for resources to start the i/o.
4972608Swnj 	 */
4987381Ssam 	if ((blkno = sc->sc_blkno) == bdbtofsb(bp->b_blkno)) {
4992396Swnj 		addr->tmbc = -bp->b_bcount;
5001919Swnj 		if ((bp->b_flags&B_READ) == 0) {
50130917Skarels 			if (um->um_tab.b_errcnt &&
50233477Skarels 			    (sc->sc_ioerreg&(TMER_HARD|TMER_SOFT)) != TMER_BGL)
5033095Swnj 				cmd = TM_WIRG;
5041919Swnj 			else
5053095Swnj 				cmd = TM_WCOM;
5061919Swnj 		} else
5073095Swnj 			cmd = TM_RCOM;
5082471Swnj 		um->um_tab.b_active = SIO;
5093095Swnj 		um->um_cmd = sc->sc_dens|cmd;
5102928Swnj #ifdef notdef
5112670Swnj 		if (tmreverseop(sc->sc_lastcmd))
5123095Swnj 			while (addr->tmer & TMER_SDWN)
51324974Smckusick 				DELAY(10),tmgapsdcnt++;
5142670Swnj 		sc->sc_lastcmd = TM_RCOM;		/* will serve */
5152928Swnj #endif
5163495Sroot 		sc->sc_timo = 60;	/* premature, but should serve */
5173105Swnj 		(void) ubago(ui);
5181919Swnj 		return;
5191919Swnj 	}
5202608Swnj 	/*
5213095Swnj 	 * Tape positioned incorrectly;
5223095Swnj 	 * set to seek forwards or backwards to the correct spot.
5233095Swnj 	 * This happens for raw tapes only on error retries.
5242608Swnj 	 */
5252471Swnj 	um->um_tab.b_active = SSEEK;
5267381Ssam 	if (blkno < bdbtofsb(bp->b_blkno)) {
5272670Swnj 		bp->b_command = TM_SFORW;
5287381Ssam 		addr->tmbc = blkno - bdbtofsb(bp->b_blkno);
5291919Swnj 	} else {
5302670Swnj 		bp->b_command = TM_SREV;
5317381Ssam 		addr->tmbc = bdbtofsb(bp->b_blkno) - blkno;
5321919Swnj 	}
5333629Sroot 	sc->sc_timo = imin(imax(10 * -addr->tmbc, 60), 5 * 60);
5342670Swnj dobpcmd:
5352928Swnj #ifdef notdef
5363095Swnj 	/*
5373095Swnj 	 * It is strictly necessary to wait for the tape
5383095Swnj 	 * to stop before changing directions, but the TC11
5393095Swnj 	 * handles this for us.
5403095Swnj 	 */
5412670Swnj 	if (tmreverseop(sc->sc_lastcmd) != tmreverseop(bp->b_command))
5422670Swnj 		while (addr->tmer & TM_SDWN)
54324974Smckusick 			DELAY(10),tmgapsdcnt++;
5442670Swnj 	sc->sc_lastcmd = bp->b_command;
5452928Swnj #endif
5463095Swnj 	/*
5473095Swnj 	 * Do the command in bp.
5483095Swnj 	 */
5493095Swnj 	addr->tmcs = (sc->sc_dens | bp->b_command);
5501919Swnj 	return;
5511919Swnj 
5521919Swnj next:
5532608Swnj 	/*
5542608Swnj 	 * Done with this operation due to error or
5552608Swnj 	 * the fact that it doesn't do anything.
5562608Swnj 	 * Release UBA resources (if any), dequeue
5572608Swnj 	 * the transfer and continue processing this slave.
5582608Swnj 	 */
5592608Swnj 	if (um->um_ubinfo)
5602617Swnj 		ubadone(um);
5612608Swnj 	um->um_tab.b_errcnt = 0;
5622608Swnj 	dp->b_actf = bp->av_forw;
5631919Swnj 	iodone(bp);
5641919Swnj 	goto loop;
5651919Swnj }
5661919Swnj 
5672608Swnj /*
5682608Swnj  * The UNIBUS resources we needed have been
5692608Swnj  * allocated to us; start the device.
5702608Swnj  */
tmdgo(um)5712574Swnj tmdgo(um)
5722982Swnj 	register struct uba_ctlr *um;
5731919Swnj {
5745692Sroot 	register struct tmdevice *addr = (struct tmdevice *)um->um_addr;
5752471Swnj 
5762574Swnj 	addr->tmba = um->um_ubinfo;
5772574Swnj 	addr->tmcs = um->um_cmd | ((um->um_ubinfo >> 12) & 0x30);
5782396Swnj }
5792396Swnj 
5802608Swnj /*
5812608Swnj  * Tm interrupt routine.
5822608Swnj  */
5832471Swnj /*ARGSUSED*/
tmintr(tm11)5842630Swnj tmintr(tm11)
5852630Swnj 	int tm11;
5862396Swnj {
5872608Swnj 	struct buf *dp;
5881919Swnj 	register struct buf *bp;
5892982Swnj 	register struct uba_ctlr *um = tmminfo[tm11];
5905692Sroot 	register struct tmdevice *addr;
5913095Swnj 	register struct te_softc *sc;
5923095Swnj 	int teunit;
5931919Swnj 	register state;
5941919Swnj 
5953095Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
5963095Swnj 		return;
5973095Swnj 	bp = dp->b_actf;
5983095Swnj 	teunit = TEUNIT(bp->b_dev);
5995692Sroot 	addr = (struct tmdevice *)tedinfo[teunit]->ui_addr;
6003524Swnj 	sc = &te_softc[teunit];
6012608Swnj 	/*
6022608Swnj 	 * If last command was a rewind, and tape is still
6032608Swnj 	 * rewinding, wait for the rewind complete interrupt.
6042608Swnj 	 */
6052608Swnj 	if (um->um_tab.b_active == SREW) {
6062608Swnj 		um->um_tab.b_active = SCOM;
6073524Swnj 		if (addr->tmer&TMER_RWS) {
6083524Swnj 			sc->sc_timo = 5*60;		/* 5 minutes */
6092608Swnj 			return;
6103524Swnj 		}
6111919Swnj 	}
6122608Swnj 	/*
6132608Swnj 	 * An operation completed... record status
6142608Swnj 	 */
6153495Sroot 	sc->sc_timo = INF;
61639938Skarels 	if (um->um_tab.b_active == SIO)
61740045Smarc 	if (um->um_tab.b_active == SIO)
61833477Skarels 		sc->sc_ioerreg = addr->tmer;
6192471Swnj 	sc->sc_dsreg = addr->tmcs;
6202471Swnj 	sc->sc_erreg = addr->tmer;
6212471Swnj 	sc->sc_resid = addr->tmbc;
6221919Swnj 	if ((bp->b_flags & B_READ) == 0)
6232608Swnj 		sc->sc_lastiow = 1;
6242471Swnj 	state = um->um_tab.b_active;
6252471Swnj 	um->um_tab.b_active = 0;
6262608Swnj 	/*
6272608Swnj 	 * Check for errors.
6282608Swnj 	 */
6292608Swnj 	if (addr->tmcs&TM_ERR) {
6303095Swnj 		while (addr->tmer & TMER_SDWN)
63124974Smckusick 			DELAY(10);			/* await settle down */
6322608Swnj 		/*
6333095Swnj 		 * If we hit the end of the tape file, update our position.
6342608Swnj 		 */
6353095Swnj 		if (addr->tmer&TMER_EOF) {
6362608Swnj 			tmseteof(bp);		/* set blkno and nxrec */
6372608Swnj 			state = SCOM;		/* force completion */
6382608Swnj 			/*
6392608Swnj 			 * Stuff bc so it will be unstuffed correctly
6402608Swnj 			 * later to get resid.
6412608Swnj 			 */
6422396Swnj 			addr->tmbc = -bp->b_bcount;
6432608Swnj 			goto opdone;
6441919Swnj 		}
6452608Swnj 		/*
6463095Swnj 		 * If we were reading raw tape and the only error was that the
6473095Swnj 		 * record was too long, then we don't consider this an error.
6482608Swnj 		 */
64934217Sbostic 		if ((bp->b_flags & (B_READ|B_RAW)) == (B_READ|B_RAW) &&
6503095Swnj 		    (addr->tmer&(TMER_HARD|TMER_SOFT)) == TMER_RLE)
6512608Swnj 			goto ignoreerr;
6522608Swnj 		/*
6532608Swnj 		 * If error is not hard, and this was an i/o operation
6542608Swnj 		 * retry up to 8 times.
6552608Swnj 		 */
6563095Swnj 		if ((addr->tmer&TMER_HARD)==0 && state==SIO) {
65740045Smarc 			if (um->um_tab.b_errcnt++ < 8) {
65830917Skarels 				if (tmdiag)
65930917Skarels 					log(LOG_DEBUG,
66030917Skarels 					    "te%d: soft error bn%d er=%b\n",
66130917Skarels 					    minor(bp->b_dev)&03,
66230917Skarels 					    bp->b_blkno, sc->sc_erreg,
66330917Skarels 					    TMER_BITS);
66440045Smarc 				sc->sc_blkno++;		/* force backspace */
6652617Swnj 				ubadone(um);
6662608Swnj 				goto opcont;
6671919Swnj 			}
6682608Swnj 		} else
6692608Swnj 			/*
6702608Swnj 			 * Hard or non-i/o errors on non-raw tape
6712608Swnj 			 * cause it to close.
6722608Swnj 			 */
67334217Sbostic 			if ((bp->b_flags&B_RAW) == 0 && sc->sc_openf > 0)
6742608Swnj 				sc->sc_openf = -1;
6752608Swnj 		/*
6762608Swnj 		 * Couldn't recover error
6772608Swnj 		 */
67844395Smarc 		tprintf(sc->sc_tpr,
67918321Sralph 		    "te%d: hard error bn%d er=%b\n", minor(bp->b_dev)&03,
6803095Swnj 		    bp->b_blkno, sc->sc_erreg, TMER_BITS);
68124974Smckusick #ifdef	AVIV
68224974Smckusick 		if (tmdiag) {
68324974Smckusick 			addr->tmmr = DAB;
68424974Smckusick 			printf("reject code 0%o", addr->tmmr & DAB_MASK);
68524974Smckusick 			addr->tmmr = DTS;
68624974Smckusick 			if (addr->tmmr & DTS_MASK)
68724974Smckusick 			    printf(", dead track 0%o", addr->tmmr & DTS_MASK);
68824974Smckusick 			addr->tmmr = RWERR;
68924974Smckusick 			printf(", read/write errors %b\n",
69024974Smckusick 			    addr->tmmr & RWERR_MASK,
69124974Smckusick 			    RWERR_BITS);
69224974Smckusick 			addr->tmmr = DRSENSE;
69324974Smckusick 			printf("drive sense %b, ", addr->tmmr & DRSENSE_MASK,
69424974Smckusick 			    DRSENSE_BITS);
69524974Smckusick 			printf("fsr %b\n", addr->tmfsr, FSR_BITS);
69624974Smckusick 		}
69724974Smckusick #endif AVIV
6981919Swnj 		bp->b_flags |= B_ERROR;
6992608Swnj 		goto opdone;
7001919Swnj 	}
7012608Swnj 	/*
7022608Swnj 	 * Advance tape control FSM.
7032608Swnj 	 */
7042608Swnj ignoreerr:
7051919Swnj 	switch (state) {
7061919Swnj 
7071919Swnj 	case SIO:
7082608Swnj 		/*
7092608Swnj 		 * Read/write increments tape block number
7102608Swnj 		 */
7112471Swnj 		sc->sc_blkno++;
71230917Skarels 		sc->sc_blks++;
71330917Skarels 		if (um->um_tab.b_errcnt)
71430917Skarels 			sc->sc_softerrs++;
7152608Swnj 		goto opdone;
7161919Swnj 
7171919Swnj 	case SCOM:
7182608Swnj 		/*
7193095Swnj 		 * For forward/backward space record update current position.
7202608Swnj 		 */
7213095Swnj 		if (bp == &ctmbuf[TMUNIT(bp->b_dev)])
72226292Skarels 		switch ((int)bp->b_command) {
7231919Swnj 
7242608Swnj 		case TM_SFORW:
7252608Swnj 			sc->sc_blkno -= bp->b_repcnt;
7263095Swnj 			break;
7271919Swnj 
7282608Swnj 		case TM_SREV:
7292608Swnj 			sc->sc_blkno += bp->b_repcnt;
7303095Swnj 			break;
7311919Swnj 		}
7323095Swnj 		goto opdone;
7331919Swnj 
7341919Swnj 	case SSEEK:
7357381Ssam 		sc->sc_blkno = bdbtofsb(bp->b_blkno);
7362608Swnj 		goto opcont;
7371919Swnj 
7381919Swnj 	default:
7392608Swnj 		panic("tmintr");
7402608Swnj 	}
7412608Swnj opdone:
7422608Swnj 	/*
7432608Swnj 	 * Reset error count and remove
7442608Swnj 	 * from device queue.
7452608Swnj 	 */
7462608Swnj 	um->um_tab.b_errcnt = 0;
7472608Swnj 	dp->b_actf = bp->av_forw;
74814929Skarels 	/*
74914929Skarels 	 * Check resid; watch out for resid >32767 (tmbc not negative).
75014929Skarels 	 */
75115081Skarels 	bp->b_resid = ((int) -addr->tmbc) & 0xffff;
7522617Swnj 	ubadone(um);
7532608Swnj 	iodone(bp);
7542608Swnj 	/*
7552608Swnj 	 * Circulate slave to end of controller
7562608Swnj 	 * queue to give other slaves a chance.
7572608Swnj 	 */
7582608Swnj 	um->um_tab.b_actf = dp->b_forw;
7592608Swnj 	if (dp->b_actf) {
7602608Swnj 		dp->b_forw = NULL;
7612608Swnj 		if (um->um_tab.b_actf == NULL)
7622608Swnj 			um->um_tab.b_actf = dp;
7632608Swnj 		else
7642608Swnj 			um->um_tab.b_actl->b_forw = dp;
7652608Swnj 		um->um_tab.b_actl = dp;
7662608Swnj 	}
7672608Swnj 	if (um->um_tab.b_actf == 0)
7681919Swnj 		return;
7692608Swnj opcont:
7702608Swnj 	tmstart(um);
7711919Swnj }
7721919Swnj 
tmtimer(dev)7733495Sroot tmtimer(dev)
7743495Sroot 	int dev;
7753495Sroot {
7763495Sroot 	register struct te_softc *sc = &te_softc[TEUNIT(dev)];
7774847Sroot 	register short x;
7783495Sroot 
7793495Sroot 	if (sc->sc_timo != INF && (sc->sc_timo -= 5) < 0) {
7804278Sroot 		printf("te%d: lost interrupt\n", TEUNIT(dev));
7813495Sroot 		sc->sc_timo = INF;
7824847Sroot 		x = spl5();
7833495Sroot 		tmintr(TMUNIT(dev));
7844847Sroot 		(void) splx(x);
7853495Sroot 	}
7863629Sroot 	timeout(tmtimer, (caddr_t)dev, 5*hz);
7873495Sroot }
7883495Sroot 
tmseteof(bp)7891919Swnj tmseteof(bp)
7901919Swnj 	register struct buf *bp;
7911919Swnj {
7923095Swnj 	register int teunit = TEUNIT(bp->b_dev);
7935692Sroot 	register struct tmdevice *addr =
7945692Sroot 	    (struct tmdevice *)tedinfo[teunit]->ui_addr;
7953095Swnj 	register struct te_softc *sc = &te_softc[teunit];
7961919Swnj 
7973095Swnj 	if (bp == &ctmbuf[TMUNIT(bp->b_dev)]) {
7987381Ssam 		if (sc->sc_blkno > bdbtofsb(bp->b_blkno)) {
7991919Swnj 			/* reversing */
8007381Ssam 			sc->sc_nxrec = bdbtofsb(bp->b_blkno) - addr->tmbc;
8012471Swnj 			sc->sc_blkno = sc->sc_nxrec;
8021919Swnj 		} else {
8031919Swnj 			/* spacing forward */
8047381Ssam 			sc->sc_blkno = bdbtofsb(bp->b_blkno) + addr->tmbc;
8052471Swnj 			sc->sc_nxrec = sc->sc_blkno - 1;
8061919Swnj 		}
8071919Swnj 		return;
8081919Swnj 	}
8091919Swnj 	/* eof on read */
8107381Ssam 	sc->sc_nxrec = bdbtofsb(bp->b_blkno);
8111919Swnj }
8121919Swnj 
tmreset(uban)8132608Swnj tmreset(uban)
8142608Swnj 	int uban;
8152608Swnj {
8162982Swnj 	register struct uba_ctlr *um;
8173095Swnj 	register tm11, teunit;
8182982Swnj 	register struct uba_device *ui;
8192608Swnj 	register struct buf *dp;
8202608Swnj 
8212630Swnj 	for (tm11 = 0; tm11 < NTM; tm11++) {
8222630Swnj 		if ((um = tmminfo[tm11]) == 0 || um->um_alive == 0 ||
8232608Swnj 		   um->um_ubanum != uban)
8242608Swnj 			continue;
8252928Swnj 		printf(" tm%d", tm11);
8262608Swnj 		um->um_tab.b_active = 0;
8272608Swnj 		um->um_tab.b_actf = um->um_tab.b_actl = 0;
8282608Swnj 		if (um->um_ubinfo) {
8292608Swnj 			printf("<%d>", (um->um_ubinfo>>28)&0xf);
8309355Ssam 			um->um_ubinfo = 0;
8312608Swnj 		}
8325692Sroot 		((struct tmdevice *)(um->um_addr))->tmcs = TM_DCLR;
8333095Swnj 		for (teunit = 0; teunit < NTE; teunit++) {
8343095Swnj 			if ((ui = tedinfo[teunit]) == 0 || ui->ui_mi != um ||
8353095Swnj 			    ui->ui_alive == 0)
8362608Swnj 				continue;
8373095Swnj 			dp = &teutab[teunit];
8382608Swnj 			dp->b_active = 0;
8392608Swnj 			dp->b_forw = 0;
8402608Swnj 			if (um->um_tab.b_actf == NULL)
8412608Swnj 				um->um_tab.b_actf = dp;
8422608Swnj 			else
8432608Swnj 				um->um_tab.b_actl->b_forw = dp;
8442608Swnj 			um->um_tab.b_actl = dp;
8453495Sroot 			if (te_softc[teunit].sc_openf > 0)
8463495Sroot 				te_softc[teunit].sc_openf = -1;
8472608Swnj 		}
8482608Swnj 		tmstart(um);
8492608Swnj 	}
8502608Swnj }
8512608Swnj 
8521919Swnj /*ARGSUSED*/
tmioctl(dev,cmd,data,flag)8537632Ssam tmioctl(dev, cmd, data, flag)
8547632Ssam 	caddr_t data;
8551919Swnj 	dev_t dev;
8561919Swnj {
8573095Swnj 	int teunit = TEUNIT(dev);
8583095Swnj 	register struct te_softc *sc = &te_softc[teunit];
8593095Swnj 	register struct buf *bp = &ctmbuf[TMUNIT(dev)];
8601919Swnj 	register callcount;
86140911Ssklower 	int fcount, error = 0;
8627632Ssam 	struct mtop *mtop;
8637632Ssam 	struct mtget *mtget;
8641919Swnj 	/* we depend of the values and order of the MT codes here */
8652608Swnj 	static tmops[] =
8662608Swnj 	   {TM_WEOF,TM_SFORW,TM_SREV,TM_SFORW,TM_SREV,TM_REW,TM_OFFL,TM_SENSE};
8671919Swnj 
8682608Swnj 	switch (cmd) {
8697632Ssam 
8707632Ssam 	case MTIOCTOP:	/* tape operation */
8717632Ssam 		mtop = (struct mtop *)data;
8728574Sroot 		switch (mtop->mt_op) {
8737632Ssam 
8742608Swnj 		case MTWEOF:
8757632Ssam 			callcount = mtop->mt_count;
8762608Swnj 			fcount = 1;
8772608Swnj 			break;
8787632Ssam 
8792608Swnj 		case MTFSF: case MTBSF:
8807632Ssam 			callcount = mtop->mt_count;
8811919Swnj 			fcount = INF;
8821919Swnj 			break;
8837632Ssam 
8841919Swnj 		case MTFSR: case MTBSR:
8851919Swnj 			callcount = 1;
8867632Ssam 			fcount = mtop->mt_count;
8871919Swnj 			break;
8887632Ssam 
8892324Skre 		case MTREW: case MTOFFL: case MTNOP:
8901919Swnj 			callcount = 1;
8911919Swnj 			fcount = 1;
8921919Swnj 			break;
8937632Ssam 
8941919Swnj 		default:
8958574Sroot 			return (ENXIO);
8961919Swnj 		}
8978574Sroot 		if (callcount <= 0 || fcount <= 0)
8988574Sroot 			return (EINVAL);
8992608Swnj 		while (--callcount >= 0) {
9007632Ssam 			tmcommand(dev, tmops[mtop->mt_op], fcount);
9017632Ssam 			if ((mtop->mt_op == MTFSR || mtop->mt_op == MTBSR) &&
9028574Sroot 			    bp->b_resid)
9038574Sroot 				return (EIO);
9043095Swnj 			if ((bp->b_flags&B_ERROR) || sc->sc_erreg&TMER_BOT)
9051919Swnj 				break;
9061919Swnj 		}
90740911Ssklower 		if (bp->b_flags&B_ERROR)
90840911Ssklower 			if ((error = bp->b_error)==0)
90940911Ssklower 				return (EIO);
91040911Ssklower 		return (error);
9117632Ssam 
9121919Swnj 	case MTIOCGET:
9137632Ssam 		mtget = (struct mtget *)data;
9147632Ssam 		mtget->mt_dsreg = sc->sc_dsreg;
9157632Ssam 		mtget->mt_erreg = sc->sc_erreg;
9167632Ssam 		mtget->mt_resid = sc->sc_resid;
9177632Ssam 		mtget->mt_type = MT_ISTM;
9188574Sroot 		break;
9197632Ssam 
9201919Swnj 	default:
9218574Sroot 		return (ENXIO);
9221919Swnj 	}
9238574Sroot 	return (0);
9241919Swnj }
9251919Swnj 
9261919Swnj #define	DBSIZE	20
9271919Swnj 
tmdump()9282363Swnj tmdump()
9292363Swnj {
9302982Swnj 	register struct uba_device *ui;
9312396Swnj 	register struct uba_regs *up;
9325692Sroot 	register struct tmdevice *addr;
9332426Skre 	int blk, num;
9342426Skre 	int start;
9351919Swnj 
9362426Skre 	start = 0;
9372426Skre 	num = maxfree;
9382426Skre #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
9393095Swnj 	if (tedinfo[0] == 0)
9402887Swnj 		return (ENXIO);
9413095Swnj 	ui = phys(tedinfo[0], struct uba_device *);
9422396Swnj 	up = phys(ui->ui_hd, struct uba_hd *)->uh_physuba;
9433331Swnj 	ubainit(up);
9442324Skre 	DELAY(1000000);
9455692Sroot 	addr = (struct tmdevice *)ui->ui_physaddr;
9462396Swnj 	tmwait(addr);
9472608Swnj 	addr->tmcs = TM_DCLR | TM_GO;
9481919Swnj 	while (num > 0) {
9491919Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9502396Swnj 		tmdwrite(start, blk, addr, up);
9511919Swnj 		start += blk;
9521919Swnj 		num -= blk;
9531919Swnj 	}
9542426Skre 	tmeof(addr);
9552426Skre 	tmeof(addr);
9562426Skre 	tmwait(addr);
9572887Swnj 	if (addr->tmcs&TM_ERR)
9582887Swnj 		return (EIO);
9592608Swnj 	addr->tmcs = TM_REW | TM_GO;
9602471Swnj 	tmwait(addr);
9612363Swnj 	return (0);
9621919Swnj }
9631919Swnj 
tmdwrite(dbuf,num,addr,up)9642608Swnj tmdwrite(dbuf, num, addr, up)
9652608Swnj 	register dbuf, num;
9665692Sroot 	register struct tmdevice *addr;
9672396Swnj 	struct uba_regs *up;
9681919Swnj {
9692396Swnj 	register struct pte *io;
9702396Swnj 	register int npf;
9711928Swnj 
9722396Swnj 	tmwait(addr);
9732396Swnj 	io = up->uba_map;
9741919Swnj 	npf = num+1;
9751928Swnj 	while (--npf != 0)
9762982Swnj 		 *(int *)io++ = (dbuf++ | (1<<UBAMR_DPSHIFT) | UBAMR_MRV);
9772396Swnj 	*(int *)io = 0;
9782396Swnj 	addr->tmbc = -(num*NBPG);
9792396Swnj 	addr->tmba = 0;
9802608Swnj 	addr->tmcs = TM_WCOM | TM_GO;
9811919Swnj }
9821919Swnj 
tmwait(addr)9832396Swnj tmwait(addr)
9845692Sroot 	register struct tmdevice *addr;
9851919Swnj {
9861928Swnj 	register s;
9871919Swnj 
9881919Swnj 	do
9892396Swnj 		s = addr->tmcs;
9902608Swnj 	while ((s & TM_CUR) == 0);
9911919Swnj }
9921919Swnj 
9932396Swnj tmeof(addr)
9945692Sroot 	struct tmdevice *addr;
9951919Swnj {
9961919Swnj 
9972396Swnj 	tmwait(addr);
9982608Swnj 	addr->tmcs = TM_WEOF | TM_GO;
9991919Swnj }
10001919Swnj #endif
1001