xref: /csrg-svn/sys/vax/uba/up.c (revision 11112)
1*11112Shelge /*	up.c	4.69	83/02/17	*/
2264Sbill 
31937Swnj #include "up.h"
42646Swnj #if NSC > 0
5264Sbill /*
69548Ssam  * UNIBUS disk driver with:
79548Ssam  *	overlapped seeks,
89548Ssam  *	ECC recovery, and
99548Ssam  *	bad sector forwarding.
102889Swnj  *
112889Swnj  * TODO:
123445Sroot  *	Check that offset recovery code works
13264Sbill  */
149782Ssam #include "../machine/pte.h"
15264Sbill 
16264Sbill #include "../h/param.h"
17264Sbill #include "../h/systm.h"
18308Sbill #include "../h/dk.h"
199548Ssam #include "../h/dkbad.h"
20264Sbill #include "../h/buf.h"
21264Sbill #include "../h/conf.h"
22264Sbill #include "../h/dir.h"
23264Sbill #include "../h/user.h"
24264Sbill #include "../h/map.h"
252571Swnj #include "../h/vm.h"
262379Swnj #include "../h/cmap.h"
279357Ssam #include "../h/uio.h"
2810871Ssam #include "../h/kernel.h"
29264Sbill 
309357Ssam #include "../vax/cpu.h"
319357Ssam #include "../vax/nexus.h"
329357Ssam #include "../vaxuba/ubavar.h"
339357Ssam #include "../vaxuba/ubareg.h"
349357Ssam #include "../vaxuba/upreg.h"
359357Ssam 
362395Swnj struct	up_softc {
372395Swnj 	int	sc_softas;
382607Swnj 	int	sc_ndrive;
392395Swnj 	int	sc_wticks;
402674Swnj 	int	sc_recal;
412646Swnj } up_softc[NSC];
42275Sbill 
432395Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
4410858Ssam struct	size {
45264Sbill 	daddr_t	nblocks;
46264Sbill 	int	cyloff;
47264Sbill } up_sizes[8] = {
48264Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
49264Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
50341Sbill 	495520,	0,		/* C=cyl 0 thru 814 */
51264Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
52264Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
533730Sroot 	81376,	681,		/* F=cyl 681 thru 814 */
543730Sroot 	153728,	562,		/* G=cyl 562 thru 814 */
55264Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
562395Swnj }, fj_sizes[8] = {
572395Swnj 	15884,	0,		/* A=cyl 0 thru 49 */
582395Swnj 	33440,	50,		/* B=cyl 50 thru 154 */
592395Swnj 	263360,	0,		/* C=cyl 0 thru 822 */
602395Swnj 	0,	0,
612395Swnj 	0,	0,
622395Swnj 	0,	0,
632395Swnj 	0,	0,
643730Sroot 	213664,	155,		/* H=cyl 155 thru 822 */
656851Ssam }, upam_sizes[8] = {
666305Sroot 	15884,	0,		/* A=cyl 0 thru 31 */
676305Sroot 	33440,	32,		/* B=cyl 32 thru 97 */
686305Sroot 	524288,	0,		/* C=cyl 0 thru 1023 */
696602Ssam 	27786,	668,
706602Ssam 	27786,	723,
716602Ssam 	125440,	778,
726305Sroot 	181760,	668,		/* G=cyl 668 thru 1022 */
736305Sroot 	291346,	98,		/* H=cyl 98 thru 667 */
74264Sbill };
752395Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
76264Sbill 
776346Swnj /*
786346Swnj  * On a 780 upSDIST could be 2, but
796346Swnj  * in the interest of 750's...
806346Swnj  */
816346Swnj #define	_upSDIST	3		/* 1.5 msec */
822395Swnj #define	_upRDIST	4		/* 2.0 msec */
83264Sbill 
842395Swnj int	upSDIST = _upSDIST;
852395Swnj int	upRDIST = _upRDIST;
862395Swnj 
872607Swnj int	upprobe(), upslave(), upattach(), updgo(), upintr();
882983Swnj struct	uba_ctlr *upminfo[NSC];
892983Swnj struct	uba_device *updinfo[NUP];
906383Swnj #define	UPIPUNITS	8
916383Swnj struct	uba_device *upip[NSC][UPIPUNITS]; /* fuji w/fixed head gives n,n+4 */
922395Swnj 
932607Swnj u_short	upstd[] = { 0776700, 0774400, 0776300, 0 };
942616Swnj struct	uba_driver scdriver =
952607Swnj     { upprobe, upslave, upattach, updgo, upstd, "up", updinfo, "sc", upminfo };
962395Swnj struct	buf	uputab[NUP];
979548Ssam char upinit[NUP];
982395Swnj 
992395Swnj struct	upst {
1002395Swnj 	short	nsect;
1012395Swnj 	short	ntrak;
1022395Swnj 	short	nspc;
1032395Swnj 	short	ncyl;
1042395Swnj 	struct	size *sizes;
1052395Swnj } upst[] = {
106*11112Shelge 	32,	19,	32*19,	815,	up_sizes,	/* 9300 */
1072395Swnj 	32,	10,	32*10,	823,	fj_sizes,	/* fujitsu 160m */
1086851Ssam 	32,	16,	32*16,	1024,	upam_sizes,	/* ampex capricorn */
109*11112Shelge /* should make a new partition table for cdc drives */
110*11112Shelge 	32,	19,	32*19,	823,	up_sizes,	/* cdc */
1112395Swnj };
1122395Swnj 
1132629Swnj u_char	up_offset[16] = {
1149548Ssam 	UPOF_P400, UPOF_M400, UPOF_P400, UPOF_M400,
1159548Ssam 	UPOF_P800, UPOF_M800, UPOF_P800, UPOF_M800,
1169548Ssam 	UPOF_P1200, UPOF_M1200, UPOF_P1200, UPOF_M1200,
1179548Ssam 	0, 0, 0, 0
1182629Swnj };
119264Sbill 
1202616Swnj struct	buf	rupbuf[NUP];
1219548Ssam struct 	buf	bupbuf[NUP];
1229548Ssam struct	dkbad	upbad[NUP];
123264Sbill 
124264Sbill #define	b_cylin b_resid
125264Sbill 
126264Sbill #ifdef INTRLVE
127264Sbill daddr_t dkblock();
128264Sbill #endif
1292395Swnj 
1302395Swnj int	upwstart, upwatch();		/* Have started guardian */
1312470Swnj int	upseek;
1322681Swnj int	upwaitdry;
1332395Swnj 
1342395Swnj /*ARGSUSED*/
1352607Swnj upprobe(reg)
1362395Swnj 	caddr_t reg;
1372395Swnj {
1382459Swnj 	register int br, cvec;
1392459Swnj 
1402607Swnj #ifdef lint
1412607Swnj 	br = 0; cvec = br; br = cvec;
1422607Swnj #endif
1432629Swnj 	((struct updevice *)reg)->upcs1 = UP_IE|UP_RDY;
1442607Swnj 	DELAY(10);
1452629Swnj 	((struct updevice *)reg)->upcs1 = 0;
1469357Ssam 	return (sizeof (struct updevice));
1472395Swnj }
1482395Swnj 
1492607Swnj upslave(ui, reg)
1502983Swnj 	struct uba_device *ui;
1512395Swnj 	caddr_t reg;
1522395Swnj {
1532629Swnj 	register struct updevice *upaddr = (struct updevice *)reg;
1542395Swnj 
1552395Swnj 	upaddr->upcs1 = 0;		/* conservative */
1562607Swnj 	upaddr->upcs2 = ui->ui_slave;
1576843Swnj 	upaddr->upcs1 = UP_NOP|UP_GO;
1583445Sroot 	if (upaddr->upcs2&UPCS2_NED) {
1592629Swnj 		upaddr->upcs1 = UP_DCLR|UP_GO;
1602395Swnj 		return (0);
1612395Swnj 	}
1622607Swnj 	return (1);
1632607Swnj }
1642607Swnj 
1652607Swnj upattach(ui)
1662983Swnj 	register struct uba_device *ui;
1672607Swnj {
1682629Swnj 	register struct updevice *upaddr;
1692607Swnj 
1702395Swnj 	if (upwstart == 0) {
1712759Swnj 		timeout(upwatch, (caddr_t)0, hz);
1722395Swnj 		upwstart++;
1732395Swnj 	}
1742571Swnj 	if (ui->ui_dk >= 0)
1752571Swnj 		dk_mspw[ui->ui_dk] = .0000020345;
1762607Swnj 	upip[ui->ui_ctlr][ui->ui_slave] = ui;
1772607Swnj 	up_softc[ui->ui_ctlr].sc_ndrive++;
1782629Swnj 	upaddr = (struct updevice *)ui->ui_addr;
1792629Swnj 	upaddr->upcs1 = 0;
1802629Swnj 	upaddr->upcs2 = ui->ui_slave;
1813496Sroot 	upaddr->uphr = UPHR_MAXTRAK;
1823553Swnj 	if (upaddr->uphr == 9)
1833496Sroot 		ui->ui_type = 1;		/* fujitsu hack */
1846305Sroot 	else if (upaddr->uphr == 15)
1856305Sroot 		ui->ui_type = 2;		/* ampex hack */
186*11112Shelge 	else {
187*11112Shelge 		upaddr->uphr = UPHR_MAXCYL;
188*11112Shelge 		if (upaddr->uphr == 822)
189*11112Shelge 			ui->ui_type = 3;	/* cdc hack */
190*11112Shelge 	}
1913496Sroot 	upaddr->upcs2 = UPCS2_CLR;
1922395Swnj }
193264Sbill 
1949548Ssam upopen(dev)
1959548Ssam 	dev_t dev;
1969548Ssam {
1979548Ssam 	register int unit = minor(dev) >> 3;
1989548Ssam 	register struct uba_device *ui;
1999548Ssam 
2009548Ssam 	if (unit >= NUP || (ui = updinfo[unit]) == 0 || ui->ui_alive == 0)
2019548Ssam 		return (ENXIO);
2029548Ssam 	return (0);
2039548Ssam }
2049548Ssam 
205264Sbill upstrategy(bp)
2062395Swnj 	register struct buf *bp;
207264Sbill {
2082983Swnj 	register struct uba_device *ui;
2092395Swnj 	register struct upst *st;
2102395Swnj 	register int unit;
2112470Swnj 	register struct buf *dp;
2122395Swnj 	int xunit = minor(bp->b_dev) & 07;
2132470Swnj 	long bn, sz;
214264Sbill 
2152470Swnj 	sz = (bp->b_bcount+511) >> 9;
216264Sbill 	unit = dkunit(bp);
2172395Swnj 	if (unit >= NUP)
2182395Swnj 		goto bad;
2192395Swnj 	ui = updinfo[unit];
2202395Swnj 	if (ui == 0 || ui->ui_alive == 0)
2212395Swnj 		goto bad;
2222395Swnj 	st = &upst[ui->ui_type];
2232395Swnj 	if (bp->b_blkno < 0 ||
2242395Swnj 	    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
2252395Swnj 		goto bad;
2262395Swnj 	bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
2276305Sroot 	(void) spl5();
2282470Swnj 	dp = &uputab[ui->ui_unit];
2292470Swnj 	disksort(dp, bp);
2302470Swnj 	if (dp->b_active == 0) {
2312395Swnj 		(void) upustart(ui);
2322395Swnj 		bp = &ui->ui_mi->um_tab;
2332395Swnj 		if (bp->b_actf && bp->b_active == 0)
2342395Swnj 			(void) upstart(ui->ui_mi);
235264Sbill 	}
2366305Sroot 	(void) spl0();
2372395Swnj 	return;
2382395Swnj 
2392395Swnj bad:
2402395Swnj 	bp->b_flags |= B_ERROR;
2412395Swnj 	iodone(bp);
2422395Swnj 	return;
243264Sbill }
244264Sbill 
2452674Swnj /*
2462674Swnj  * Unit start routine.
2472674Swnj  * Seek the drive to be where the data is
2482674Swnj  * and then generate another interrupt
2492674Swnj  * to actually start the transfer.
2502674Swnj  * If there is only one drive on the controller,
2512674Swnj  * or we are very close to the data, don't
2522674Swnj  * bother with the search.  If called after
2532674Swnj  * searching once, don't bother to look where
2542674Swnj  * we are, just queue for transfer (to avoid
2552674Swnj  * positioning forever without transferrring.)
2562674Swnj  */
2572395Swnj upustart(ui)
2582983Swnj 	register struct uba_device *ui;
259264Sbill {
260264Sbill 	register struct buf *bp, *dp;
2612983Swnj 	register struct uba_ctlr *um;
2622629Swnj 	register struct updevice *upaddr;
2632395Swnj 	register struct upst *st;
264264Sbill 	daddr_t bn;
2652674Swnj 	int sn, csn;
2662607Swnj 	/*
2672607Swnj 	 * The SC21 cancels commands if you just say
2682629Swnj 	 *	cs1 = UP_IE
2692607Swnj 	 * so we are cautious about handling of cs1.
2702607Swnj 	 * Also don't bother to clear as bits other than in upintr().
2712607Swnj 	 */
2722674Swnj 	int didie = 0;
2732674Swnj 
2742674Swnj 	if (ui == 0)
2752674Swnj 		return (0);
2762983Swnj 	um = ui->ui_mi;
2772395Swnj 	dk_busy &= ~(1<<ui->ui_dk);
2782395Swnj 	dp = &uputab[ui->ui_unit];
279266Sbill 	if ((bp = dp->b_actf) == NULL)
280268Sbill 		goto out;
2812674Swnj 	/*
2822674Swnj 	 * If the controller is active, just remember
2832674Swnj 	 * that this device would like to be positioned...
2842674Swnj 	 * if we tried to position now we would confuse the SC21.
2852674Swnj 	 */
2862395Swnj 	if (um->um_tab.b_active) {
2872459Swnj 		up_softc[um->um_ctlr].sc_softas |= 1<<ui->ui_slave;
288275Sbill 		return (0);
289275Sbill 	}
2902674Swnj 	/*
2912674Swnj 	 * If we have already positioned this drive,
2922674Swnj 	 * then just put it on the ready queue.
2932674Swnj 	 */
294276Sbill 	if (dp->b_active)
295276Sbill 		goto done;
296276Sbill 	dp->b_active = 1;
2972629Swnj 	upaddr = (struct updevice *)um->um_addr;
2982395Swnj 	upaddr->upcs2 = ui->ui_slave;
2992674Swnj 	/*
3002674Swnj 	 * If drive has just come up,
3012674Swnj 	 * setup the pack.
3022674Swnj 	 */
3039548Ssam 	if ((upaddr->upds & UPDS_VV) == 0 || upinit[ui->ui_unit] == 0) {
3049548Ssam 		struct buf *bbp = &bupbuf[ui->ui_unit];
30510858Ssam 
3062607Swnj 		/* SHOULD WARN SYSTEM THAT THIS HAPPENED */
3079548Ssam 		upinit[ui->ui_unit] = 1;
3082629Swnj 		upaddr->upcs1 = UP_IE|UP_DCLR|UP_GO;
3092629Swnj 		upaddr->upcs1 = UP_IE|UP_PRESET|UP_GO;
3103445Sroot 		upaddr->upof = UPOF_FMT22;
311268Sbill 		didie = 1;
3129548Ssam 		st = &upst[ui->ui_type];
3139548Ssam 		bbp->b_flags = B_READ|B_BUSY;
3149548Ssam 		bbp->b_dev = bp->b_dev;
3159548Ssam 		bbp->b_bcount = 512;
3169548Ssam 		bbp->b_un.b_addr = (caddr_t)&upbad[ui->ui_unit];
3179548Ssam 		bbp->b_blkno = st->ncyl * st->nspc - st->nsect;
3189548Ssam 		bbp->b_cylin = st->ncyl - 1;
3199548Ssam 		dp->b_actf = bbp;
3209548Ssam 		bbp->av_forw = bp;
3219548Ssam 		bp = bbp;
322264Sbill 	}
3232674Swnj 	/*
3242674Swnj 	 * If drive is offline, forget about positioning.
3252674Swnj 	 */
3263445Sroot 	if ((upaddr->upds & (UPDS_DPR|UPDS_MOL)) != (UPDS_DPR|UPDS_MOL))
327275Sbill 		goto done;
3282674Swnj 	/*
3292674Swnj 	 * If there is only one drive,
3302674Swnj 	 * dont bother searching.
3312674Swnj 	 */
3322607Swnj 	if (up_softc[um->um_ctlr].sc_ndrive == 1)
3332607Swnj 		goto done;
3342674Swnj 	/*
3352674Swnj 	 * Figure out where this transfer is going to
3362674Swnj 	 * and see if we are close enough to justify not searching.
3372674Swnj 	 */
3382395Swnj 	st = &upst[ui->ui_type];
339264Sbill 	bn = dkblock(bp);
3402395Swnj 	sn = bn%st->nspc;
3412395Swnj 	sn = (sn + st->nsect - upSDIST) % st->nsect;
3422674Swnj 	if (bp->b_cylin - upaddr->updc)
343266Sbill 		goto search;		/* Not on-cylinder */
344275Sbill 	else if (upseek)
345275Sbill 		goto done;		/* Ok just to be on-cylinder */
346264Sbill 	csn = (upaddr->upla>>6) - sn - 1;
347266Sbill 	if (csn < 0)
3482395Swnj 		csn += st->nsect;
3492395Swnj 	if (csn > st->nsect - upRDIST)
350264Sbill 		goto done;
351264Sbill search:
3522674Swnj 	upaddr->updc = bp->b_cylin;
3532674Swnj 	/*
3542674Swnj 	 * Not on cylinder at correct position,
3552674Swnj 	 * seek/search.
3562674Swnj 	 */
357275Sbill 	if (upseek)
3582629Swnj 		upaddr->upcs1 = UP_IE|UP_SEEK|UP_GO;
3592470Swnj 	else {
360275Sbill 		upaddr->upda = sn;
3612629Swnj 		upaddr->upcs1 = UP_IE|UP_SEARCH|UP_GO;
362275Sbill 	}
363268Sbill 	didie = 1;
3642674Swnj 	/*
3652674Swnj 	 * Mark unit busy for iostat.
3662674Swnj 	 */
3672395Swnj 	if (ui->ui_dk >= 0) {
3682395Swnj 		dk_busy |= 1<<ui->ui_dk;
3692395Swnj 		dk_seek[ui->ui_dk]++;
370264Sbill 	}
371268Sbill 	goto out;
372264Sbill done:
3732674Swnj 	/*
3742674Swnj 	 * Device is ready to go.
3752674Swnj 	 * Put it on the ready queue for the controller
3762674Swnj 	 * (unless its already there.)
3772674Swnj 	 */
3782629Swnj 	if (dp->b_active != 2) {
3792629Swnj 		dp->b_forw = NULL;
3802629Swnj 		if (um->um_tab.b_actf == NULL)
3812629Swnj 			um->um_tab.b_actf = dp;
3822629Swnj 		else
3832629Swnj 			um->um_tab.b_actl->b_forw = dp;
3842629Swnj 		um->um_tab.b_actl = dp;
3852629Swnj 		dp->b_active = 2;
3862629Swnj 	}
387268Sbill out:
388268Sbill 	return (didie);
389264Sbill }
390264Sbill 
3912674Swnj /*
3922674Swnj  * Start up a transfer on a drive.
3932674Swnj  */
3942395Swnj upstart(um)
3952983Swnj 	register struct uba_ctlr *um;
396264Sbill {
397264Sbill 	register struct buf *bp, *dp;
3982983Swnj 	register struct uba_device *ui;
3992629Swnj 	register struct updevice *upaddr;
4002470Swnj 	struct upst *st;
401264Sbill 	daddr_t bn;
4022681Swnj 	int dn, sn, tn, cmd, waitdry;
403264Sbill 
404264Sbill loop:
4052674Swnj 	/*
4062674Swnj 	 * Pull a request off the controller queue
4072674Swnj 	 */
4082395Swnj 	if ((dp = um->um_tab.b_actf) == NULL)
409268Sbill 		return (0);
410264Sbill 	if ((bp = dp->b_actf) == NULL) {
4112395Swnj 		um->um_tab.b_actf = dp->b_forw;
412264Sbill 		goto loop;
413264Sbill 	}
4142674Swnj 	/*
4152674Swnj 	 * Mark controller busy, and
4162674Swnj 	 * determine destination of this request.
4172674Swnj 	 */
4182395Swnj 	um->um_tab.b_active++;
4192395Swnj 	ui = updinfo[dkunit(bp)];
420264Sbill 	bn = dkblock(bp);
4212395Swnj 	dn = ui->ui_slave;
4222395Swnj 	st = &upst[ui->ui_type];
4232395Swnj 	sn = bn%st->nspc;
4242395Swnj 	tn = sn/st->nsect;
4252395Swnj 	sn %= st->nsect;
4262629Swnj 	upaddr = (struct updevice *)ui->ui_addr;
4272674Swnj 	/*
4282674Swnj 	 * Select drive if not selected already.
4292674Swnj 	 */
4302674Swnj 	if ((upaddr->upcs2&07) != dn)
4312674Swnj 		upaddr->upcs2 = dn;
4322674Swnj 	/*
4332674Swnj 	 * Check that it is ready and online
4342674Swnj 	 */
4352681Swnj 	waitdry = 0;
4363445Sroot 	while ((upaddr->upds&UPDS_DRY) == 0) {
4377036Swnj 		printf("up%d: ds wait ds=%o\n",dkunit(bp),upaddr->upds);
4382681Swnj 		if (++waitdry > 512)
4392681Swnj 			break;
4402681Swnj 		upwaitdry++;
4412681Swnj 	}
4423445Sroot 	if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
4432931Swnj 		printf("up%d: not ready", dkunit(bp));
4443445Sroot 		if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
4452607Swnj 			printf("\n");
4462395Swnj 			um->um_tab.b_active = 0;
4472395Swnj 			um->um_tab.b_errcnt = 0;
448893Sbill 			dp->b_actf = bp->av_forw;
449893Sbill 			dp->b_active = 0;
450893Sbill 			bp->b_flags |= B_ERROR;
451893Sbill 			iodone(bp);
452893Sbill 			goto loop;
453893Sbill 		}
4542674Swnj 		/*
4552674Swnj 		 * Oh, well, sometimes this
4562674Swnj 		 * happens, for reasons unknown.
4572674Swnj 		 */
4582629Swnj 		printf(" (flakey)\n");
459264Sbill 	}
4602674Swnj 	/*
4612674Swnj 	 * Setup for the transfer, and get in the
4622674Swnj 	 * UNIBUS adaptor queue.
4632674Swnj 	 */
4642424Skre 	upaddr->updc = bp->b_cylin;
465264Sbill 	upaddr->upda = (tn << 8) + sn;
466264Sbill 	upaddr->upwc = -bp->b_bcount / sizeof (short);
467264Sbill 	if (bp->b_flags & B_READ)
4682629Swnj 		cmd = UP_IE|UP_RCOM|UP_GO;
469264Sbill 	else
4702629Swnj 		cmd = UP_IE|UP_WCOM|UP_GO;
4712571Swnj 	um->um_cmd = cmd;
4723107Swnj 	(void) ubago(ui);
473268Sbill 	return (1);
474264Sbill }
475264Sbill 
4762674Swnj /*
4772674Swnj  * Now all ready to go, stuff the registers.
4782674Swnj  */
4792571Swnj updgo(um)
4802983Swnj 	struct uba_ctlr *um;
4812395Swnj {
4822629Swnj 	register struct updevice *upaddr = (struct updevice *)um->um_addr;
4832470Swnj 
4846953Swnj 	um->um_tab.b_active = 2;	/* should now be 2 */
4852571Swnj 	upaddr->upba = um->um_ubinfo;
4862571Swnj 	upaddr->upcs1 = um->um_cmd|((um->um_ubinfo>>8)&0x300);
4872395Swnj }
4882395Swnj 
4892674Swnj /*
4902674Swnj  * Handle a disk interrupt.
4912674Swnj  */
4922707Swnj upintr(sc21)
4932395Swnj 	register sc21;
494264Sbill {
495264Sbill 	register struct buf *bp, *dp;
4962983Swnj 	register struct uba_ctlr *um = upminfo[sc21];
4972983Swnj 	register struct uba_device *ui;
4982629Swnj 	register struct updevice *upaddr = (struct updevice *)um->um_addr;
499264Sbill 	register unit;
5002470Swnj 	struct up_softc *sc = &up_softc[um->um_ctlr];
5012607Swnj 	int as = (upaddr->upas & 0377) | sc->sc_softas;
5022681Swnj 	int needie = 1, waitdry;
503264Sbill 
5042470Swnj 	sc->sc_wticks = 0;
5052607Swnj 	sc->sc_softas = 0;
5062674Swnj 	/*
5072674Swnj 	 * If controller wasn't transferring, then this is an
5082674Swnj 	 * interrupt for attention status on seeking drives.
5092674Swnj 	 * Just service them.
5102674Swnj 	 */
5116346Swnj 	if (um->um_tab.b_active != 2 && !sc->sc_recal) {
5122674Swnj 		if (upaddr->upcs1 & UP_TRE)
5132674Swnj 			upaddr->upcs1 = UP_TRE;
5142674Swnj 		goto doattn;
5152674Swnj 	}
5166953Swnj 	um->um_tab.b_active = 1;
5172674Swnj 	/*
5182674Swnj 	 * Get device and block structures, and a pointer
5192983Swnj 	 * to the uba_device for the drive.  Select the drive.
5202674Swnj 	 */
5212674Swnj 	dp = um->um_tab.b_actf;
5222674Swnj 	bp = dp->b_actf;
5232674Swnj 	ui = updinfo[dkunit(bp)];
5242674Swnj 	dk_busy &= ~(1 << ui->ui_dk);
5252674Swnj 	if ((upaddr->upcs2&07) != ui->ui_slave)
5262395Swnj 		upaddr->upcs2 = ui->ui_slave;
5279548Ssam 	if (bp->b_flags&B_BAD) {
5289548Ssam 		if (upecc(ui, CONT))
5299548Ssam 			return;
5309548Ssam 	}
5312674Swnj 	/*
5322674Swnj 	 * Check for and process errors on
5332674Swnj 	 * either the drive or the controller.
5342674Swnj 	 */
5353445Sroot 	if ((upaddr->upds&UPDS_ERR) || (upaddr->upcs1&UP_TRE)) {
5362681Swnj 		waitdry = 0;
5373445Sroot 		while ((upaddr->upds & UPDS_DRY) == 0) {
5382681Swnj 			if (++waitdry > 512)
5392681Swnj 				break;
5402681Swnj 			upwaitdry++;
5412681Swnj 		}
5423445Sroot 		if (upaddr->uper1&UPER1_WLE) {
5432674Swnj 			/*
5442674Swnj 			 * Give up on write locked devices
5452674Swnj 			 * immediately.
5462674Swnj 			 */
5472931Swnj 			printf("up%d: write locked\n", dkunit(bp));
5482674Swnj 			bp->b_flags |= B_ERROR;
5492674Swnj 		} else if (++um->um_tab.b_errcnt > 27) {
5502674Swnj 			/*
5512674Swnj 			 * After 28 retries (16 without offset, and
5522674Swnj 			 * 12 with offset positioning) give up.
55310904Shelge 			 * If the error was header CRC, the header is
55410904Shelge 			 * screwed up, and the sector may in fact exist
55510904Shelge 			 * in the bad sector table, better check...
5562674Swnj 			 */
55710904Shelge 			if (upaddr->uper1&UPER1_HCRC) {
55810904Shelge 				if (upecc(ui, BSE))
55910904Shelge 					return;
56010904Shelge 			}
5619548Ssam 	hard:
5622931Swnj 			harderr(bp, "up");
5639548Ssam 			printf("cn=%d tn=%d sn=%d cs2=%b er1=%b er2=%b\n",
5649548Ssam 			        upaddr->updc, ((upaddr->upda)>>8)&077,
5659548Ssam 			        (upaddr->upda)&037,
5669548Ssam 				upaddr->upcs2, UPCS2_BITS,
5679548Ssam 				upaddr->uper1, UPER1_BITS,
5689548Ssam 				upaddr->uper2, UPER2_BITS);
5692674Swnj 			bp->b_flags |= B_ERROR;
5709548Ssam 		} else if (upaddr->uper2 & UPER2_BSE) {
5719548Ssam 			if (upecc(ui, BSE))
5729548Ssam 				return;
5739548Ssam 			else
5749548Ssam 				goto hard;
5752674Swnj 		} else {
5762674Swnj 			/*
5772674Swnj 			 * Retriable error.
5782674Swnj 			 * If a soft ecc, correct it (continuing
5792674Swnj 			 * by returning if necessary.
5802674Swnj 			 * Otherwise fall through and retry the transfer
5812674Swnj 			 */
5827183Sroot 			if ((upaddr->uper1&(UPER1_DCK|UPER1_ECH))==UPER1_DCK) {
5839548Ssam 				if (upecc(ui, ECC))
5842629Swnj 					return;
5857183Sroot 			} else
5867183Sroot 				um->um_tab.b_active = 0; /* force retry */
5872674Swnj 		}
5882674Swnj 		/*
5892674Swnj 		 * Clear drive error and, every eight attempts,
5902674Swnj 		 * (starting with the fourth)
5912674Swnj 		 * recalibrate to clear the slate.
5922674Swnj 		 */
5932674Swnj 		upaddr->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO;
5942674Swnj 		needie = 0;
5953182Swnj 		if ((um->um_tab.b_errcnt&07) == 4 && um->um_tab.b_active == 0) {
5962674Swnj 			upaddr->upcs1 = UP_RECAL|UP_IE|UP_GO;
5973160Swnj 			sc->sc_recal = 0;
5983160Swnj 			goto nextrecal;
5992674Swnj 		}
6002674Swnj 	}
6012674Swnj 	/*
6023160Swnj 	 * Advance recalibration finite state machine
6033160Swnj 	 * if recalibrate in progress, through
6043160Swnj 	 *	RECAL
6053160Swnj 	 *	SEEK
6063160Swnj 	 *	OFFSET (optional)
6073160Swnj 	 *	RETRY
6082674Swnj 	 */
6093160Swnj 	switch (sc->sc_recal) {
6103160Swnj 
6113160Swnj 	case 1:
6123160Swnj 		upaddr->updc = bp->b_cylin;
6133160Swnj 		upaddr->upcs1 = UP_SEEK|UP_IE|UP_GO;
6143160Swnj 		goto nextrecal;
6153160Swnj 	case 2:
6163160Swnj 		if (um->um_tab.b_errcnt < 16 || (bp->b_flags&B_READ) == 0)
6173160Swnj 			goto donerecal;
6183445Sroot 		upaddr->upof = up_offset[um->um_tab.b_errcnt & 017] | UPOF_FMT22;
6193160Swnj 		upaddr->upcs1 = UP_IE|UP_OFFSET|UP_GO;
6203160Swnj 		goto nextrecal;
6213160Swnj 	nextrecal:
6223160Swnj 		sc->sc_recal++;
6233160Swnj 		um->um_tab.b_active = 1;
6243160Swnj 		return;
6253160Swnj 	donerecal:
6263160Swnj 	case 3:
6272674Swnj 		sc->sc_recal = 0;
6283160Swnj 		um->um_tab.b_active = 0;
6293160Swnj 		break;
6302674Swnj 	}
6312674Swnj 	/*
6322674Swnj 	 * If still ``active'', then don't need any more retries.
6332674Swnj 	 */
6342674Swnj 	if (um->um_tab.b_active) {
6352674Swnj 		/*
6362674Swnj 		 * If we were offset positioning,
6372674Swnj 		 * return to centerline.
6382674Swnj 		 */
6392674Swnj 		if (um->um_tab.b_errcnt >= 16) {
6403445Sroot 			upaddr->upof = UPOF_FMT22;
6412674Swnj 			upaddr->upcs1 = UP_RTC|UP_GO|UP_IE;
6423445Sroot 			while (upaddr->upds & UPDS_PIP)
6432674Swnj 				DELAY(25);
644268Sbill 			needie = 0;
645264Sbill 		}
6462674Swnj 		um->um_tab.b_active = 0;
6472674Swnj 		um->um_tab.b_errcnt = 0;
6482674Swnj 		um->um_tab.b_actf = dp->b_forw;
6492674Swnj 		dp->b_active = 0;
6502674Swnj 		dp->b_errcnt = 0;
6512674Swnj 		dp->b_actf = bp->av_forw;
6522674Swnj 		bp->b_resid = (-upaddr->upwc * sizeof(short));
6532674Swnj 		iodone(bp);
6542674Swnj 		/*
6552674Swnj 		 * If this unit has more work to do,
6562674Swnj 		 * then start it up right away.
6572674Swnj 		 */
6582674Swnj 		if (dp->b_actf)
6592674Swnj 			if (upustart(ui))
660268Sbill 				needie = 0;
661264Sbill 	}
6622674Swnj 	as &= ~(1<<ui->ui_slave);
6633403Swnj 	/*
6643403Swnj 	 * Release unibus resources and flush data paths.
6653403Swnj 	 */
6663403Swnj 	ubadone(um);
6672674Swnj doattn:
6682674Swnj 	/*
6692674Swnj 	 * Process other units which need attention.
6702674Swnj 	 * For each unit which needs attention, call
6712674Swnj 	 * the unit start routine to place the slave
6722674Swnj 	 * on the controller device queue.
6732674Swnj 	 */
6743160Swnj 	while (unit = ffs(as)) {
6753160Swnj 		unit--;		/* was 1 origin */
6763160Swnj 		as &= ~(1<<unit);
6773160Swnj 		upaddr->upas = 1<<unit;
6786383Swnj 		if (unit < UPIPUNITS && upustart(upip[sc21][unit]))
6793160Swnj 			needie = 0;
6803160Swnj 	}
6812674Swnj 	/*
6822674Swnj 	 * If the controller is not transferring, but
6832674Swnj 	 * there are devices ready to transfer, start
6842674Swnj 	 * the controller.
6852674Swnj 	 */
6862395Swnj 	if (um->um_tab.b_actf && um->um_tab.b_active == 0)
6872395Swnj 		if (upstart(um))
688268Sbill 			needie = 0;
689275Sbill 	if (needie)
6902629Swnj 		upaddr->upcs1 = UP_IE;
691264Sbill }
692264Sbill 
6939357Ssam upread(dev, uio)
6942616Swnj 	dev_t dev;
6959357Ssam 	struct uio *uio;
696264Sbill {
6972616Swnj 	register int unit = minor(dev) >> 3;
6982470Swnj 
6992616Swnj 	if (unit >= NUP)
7009357Ssam 		return (ENXIO);
7019357Ssam 	return (physio(upstrategy, &rupbuf[unit], dev, B_READ, minphys, uio));
702264Sbill }
703264Sbill 
7049357Ssam upwrite(dev, uio)
7052616Swnj 	dev_t dev;
7069357Ssam 	struct uio *uio;
707264Sbill {
7082616Swnj 	register int unit = minor(dev) >> 3;
7092470Swnj 
7102616Swnj 	if (unit >= NUP)
7119357Ssam 		return (ENXIO);
7129357Ssam 	return (physio(upstrategy, &rupbuf[unit], dev, B_WRITE, minphys, uio));
713264Sbill }
714264Sbill 
715266Sbill /*
716266Sbill  * Correct an ECC error, and restart the i/o to complete
717266Sbill  * the transfer if necessary.  This is quite complicated because
718266Sbill  * the transfer may be going to an odd memory address base and/or
719266Sbill  * across a page boundary.
720266Sbill  */
7219548Ssam upecc(ui, flag)
7222983Swnj 	register struct uba_device *ui;
7239548Ssam 	int flag;
724264Sbill {
7252629Swnj 	register struct updevice *up = (struct updevice *)ui->ui_addr;
7262395Swnj 	register struct buf *bp = uputab[ui->ui_unit].b_actf;
7272983Swnj 	register struct uba_ctlr *um = ui->ui_mi;
7282395Swnj 	register struct upst *st;
7292395Swnj 	struct uba_regs *ubp = ui->ui_hd->uh_uba;
730266Sbill 	register int i;
731264Sbill 	caddr_t addr;
732266Sbill 	int reg, bit, byte, npf, mask, o, cmd, ubaddr;
733264Sbill 	int bn, cn, tn, sn;
734264Sbill 
735264Sbill 	/*
736266Sbill 	 * Npf is the number of sectors transferred before the sector
737266Sbill 	 * containing the ECC error, and reg is the UBA register
738266Sbill 	 * mapping (the first part of) the transfer.
739266Sbill 	 * O is offset within a memory page of the first byte transferred.
740264Sbill 	 */
7419548Ssam 	if (flag == CONT)
7429548Ssam 		npf = bp->b_error;
7439548Ssam 	else
74410858Ssam 		npf = btop((up->upwc * sizeof(short)) + bp->b_bcount);
7452571Swnj 	reg = btop(um->um_ubinfo&0x3ffff) + npf;
746264Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
747264Sbill 	mask = up->upec2;
7483445Sroot #ifdef UPECCDEBUG
7493403Swnj 	printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask,
7503403Swnj 	    up->upec1);
7513445Sroot #endif
7529548Ssam 	bn = dkblock(bp);
7539548Ssam 	st = &upst[ui->ui_type];
7549548Ssam 	cn = bp->b_cylin;
7559548Ssam 	sn = bn%st->nspc + npf;
7569548Ssam 	tn = sn/st->nsect;
7579548Ssam 	sn %= st->nsect;
7589548Ssam 	cn += tn/st->ntrak;
7599548Ssam 	tn %= st->ntrak;
7602725Swnj 	ubapurge(um);
7619548Ssam 	um->um_tab.b_active=2;
762266Sbill 	/*
7639548Ssam 	 * action taken depends on the flag
764266Sbill 	 */
7659548Ssam 	switch(flag){
7669548Ssam 	case ECC:
7679548Ssam 		npf--;
7689548Ssam 		reg--;
7699548Ssam 		mask = up->upec2;
7709548Ssam 		printf("up%d%c: soft ecc sn%d\n", dkunit(bp),
7719548Ssam 			'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
7729548Ssam 		/*
7739548Ssam 		 * Flush the buffered data path, and compute the
7749548Ssam 		 * byte and bit position of the error.  The variable i
7759548Ssam 		 * is the byte offset in the transfer, the variable byte
7769548Ssam 		 * is the offset from a page boundary in main memory.
7779548Ssam 		 */
7789548Ssam 		i = up->upec1 - 1;		/* -1 makes 0 origin */
7799548Ssam 		bit = i&07;
7809548Ssam 		i = (i&~07)>>3;
7819548Ssam 		byte = i + o;
7829548Ssam 		/*
7839548Ssam 		 * Correct while possible bits remain of mask.  Since mask
7849548Ssam 		 * contains 11 bits, we continue while the bit offset is > -11.
7859548Ssam 		 * Also watch out for end of this block and the end of the whole
7869548Ssam 		 * transfer.
7879548Ssam 		 */
7889548Ssam 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
7899548Ssam 			addr = ptob(ubp->uba_map[reg+btop(byte)].pg_pfnum)+
7909548Ssam 				(byte & PGOFSET);
7913445Sroot #ifdef UPECCDEBUG
7929548Ssam 			printf("addr %x map reg %x\n",
7939548Ssam 				addr, *(int *)(&ubp->uba_map[reg+btop(byte)]));
7949548Ssam 			printf("old: %x, ", getmemc(addr));
7953445Sroot #endif
7969548Ssam 			putmemc(addr, getmemc(addr)^(mask<<bit));
7973445Sroot #ifdef UPECCDEBUG
7989548Ssam 			printf("new: %x\n", getmemc(addr));
7993445Sroot #endif
8009548Ssam 			byte++;
8019548Ssam 			i++;
8029580Shelge 			bit -= 8;
8039548Ssam 		}
8049548Ssam 		if (up->upwc == 0)
8059548Ssam 			return (0);
8069548Ssam 		npf++;
8079548Ssam 		reg++;
8089548Ssam 		break;
8099548Ssam 	case BSE:
8109548Ssam 		/*
8119548Ssam 		 * if not in bad sector table, return 0
8129548Ssam 		 */
8139548Ssam 		if ((bn = isbad(&upbad[ui->ui_unit], cn, tn, sn)) < 0)
8149548Ssam 			return(0);
8159548Ssam 		/*
8169548Ssam 		 * flag this one as bad
8179548Ssam 		 */
8189548Ssam 		bp->b_flags |= B_BAD;
8199548Ssam 		bp->b_error = npf + 1;
8209548Ssam #ifdef UPECCDEBUG
8219548Ssam 		printf("BSE: restart at %d\n",npf+1);
8229548Ssam #endif
8239548Ssam 		bn = st->ncyl * st->nspc -st->nsect - 1 - bn;
8249548Ssam 		cn = bn / st->nspc;
8259548Ssam 		sn = bn % st->nspc;
8269548Ssam 		tn = sn / st->nsect;
8279548Ssam 		sn %= st->nsect;
8289548Ssam 		up->upwc = -(512 / sizeof (short));
8299548Ssam #ifdef UPECCDEBUG
8309548Ssam 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
8319548Ssam #endif
8329548Ssam 		break;
8339548Ssam 	case CONT:
8349548Ssam #ifdef UPECCDEBUG
8359548Ssam 		printf("upecc, CONT: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
8369548Ssam #endif
8379548Ssam 		bp->b_flags &= ~B_BAD;
8389548Ssam 		up->upwc = -((bp->b_bcount - (int)ptob(npf)) / sizeof(short));
8399548Ssam 		if (up->upwc == 0)
8409548Ssam 			return(0);
8419548Ssam 		break;
842264Sbill 	}
8437183Sroot 	if (up->upwc == 0) {
8447183Sroot 		um->um_tab.b_active = 0;
845264Sbill 		return (0);
8467183Sroot 	}
847266Sbill 	/*
848266Sbill 	 * Have to continue the transfer... clear the drive,
849266Sbill 	 * and compute the position where the transfer is to continue.
850266Sbill 	 * We have completed npf+1 sectors of the transfer already;
851266Sbill 	 * restart at offset o of next sector (i.e. in UBA register reg+1).
852266Sbill 	 */
8532629Swnj #ifdef notdef
8542629Swnj 	up->uper1 = 0;
8552629Swnj 	up->upcs1 |= UP_GO;
8562629Swnj #else
8572629Swnj 	up->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO;
858264Sbill 	up->updc = cn;
859266Sbill 	up->upda = (tn << 8) | sn;
8609548Ssam 	ubaddr = (int)ptob(reg) + o;
861266Sbill 	up->upba = ubaddr;
862266Sbill 	cmd = (ubaddr >> 8) & 0x300;
8639548Ssam 	cmd |= ((bp->b_flags&B_READ)?UP_RCOM:UP_WCOM)|UP_IE|UP_GO;
8649548Ssam 	um->um_tab.b_errcnt = 0;
865266Sbill 	up->upcs1 = cmd;
8662629Swnj #endif
867264Sbill 	return (1);
868264Sbill }
869286Sbill 
870286Sbill /*
871286Sbill  * Reset driver after UBA init.
872286Sbill  * Cancel software state of all pending transfers
873286Sbill  * and restart all units and the controller.
874286Sbill  */
8752395Swnj upreset(uban)
8762931Swnj 	int uban;
877286Sbill {
8782983Swnj 	register struct uba_ctlr *um;
8792983Swnj 	register struct uba_device *ui;
8802395Swnj 	register sc21, unit;
881286Sbill 
8822646Swnj 	for (sc21 = 0; sc21 < NSC; sc21++) {
8832470Swnj 		if ((um = upminfo[sc21]) == 0 || um->um_ubanum != uban ||
8842470Swnj 		    um->um_alive == 0)
8852395Swnj 			continue;
8862931Swnj 		printf(" sc%d", sc21);
8872395Swnj 		um->um_tab.b_active = 0;
8882395Swnj 		um->um_tab.b_actf = um->um_tab.b_actl = 0;
8892931Swnj 		up_softc[sc21].sc_recal = 0;
8906346Swnj 		up_softc[sc21].sc_wticks = 0;
8912571Swnj 		if (um->um_ubinfo) {
8922571Swnj 			printf("<%d>", (um->um_ubinfo>>28)&0xf);
8939357Ssam 			um->um_ubinfo = 0;
8942395Swnj 		}
8953445Sroot 		((struct updevice *)(um->um_addr))->upcs2 = UPCS2_CLR;
8962395Swnj 		for (unit = 0; unit < NUP; unit++) {
8972395Swnj 			if ((ui = updinfo[unit]) == 0)
8982395Swnj 				continue;
8992931Swnj 			if (ui->ui_alive == 0 || ui->ui_mi != um)
9002395Swnj 				continue;
9012395Swnj 			uputab[unit].b_active = 0;
9022395Swnj 			(void) upustart(ui);
9032395Swnj 		}
9042395Swnj 		(void) upstart(um);
905286Sbill 	}
906286Sbill }
907313Sbill 
908313Sbill /*
909313Sbill  * Wake up every second and if an interrupt is pending
910313Sbill  * but nothing has happened increment a counter.
9112931Swnj  * If nothing happens for 20 seconds, reset the UNIBUS
912313Sbill  * and begin anew.
913313Sbill  */
914313Sbill upwatch()
915313Sbill {
9162983Swnj 	register struct uba_ctlr *um;
9172395Swnj 	register sc21, unit;
9182470Swnj 	register struct up_softc *sc;
919313Sbill 
9202759Swnj 	timeout(upwatch, (caddr_t)0, hz);
9212646Swnj 	for (sc21 = 0; sc21 < NSC; sc21++) {
9222395Swnj 		um = upminfo[sc21];
9232470Swnj 		if (um == 0 || um->um_alive == 0)
9242470Swnj 			continue;
9252470Swnj 		sc = &up_softc[sc21];
9262395Swnj 		if (um->um_tab.b_active == 0) {
9272395Swnj 			for (unit = 0; unit < NUP; unit++)
9282629Swnj 				if (uputab[unit].b_active &&
9292629Swnj 				    updinfo[unit]->ui_mi == um)
9302395Swnj 					goto active;
9312470Swnj 			sc->sc_wticks = 0;
9322395Swnj 			continue;
9332395Swnj 		}
9342931Swnj active:
9352470Swnj 		sc->sc_wticks++;
9362470Swnj 		if (sc->sc_wticks >= 20) {
9372470Swnj 			sc->sc_wticks = 0;
9382931Swnj 			printf("sc%d: lost interrupt\n", sc21);
9392646Swnj 			ubareset(um->um_ubanum);
9402395Swnj 		}
941313Sbill 	}
942313Sbill }
9432379Swnj 
9442379Swnj #define	DBSIZE	20
9452379Swnj 
9462379Swnj updump(dev)
9472379Swnj 	dev_t dev;
9482379Swnj {
9492629Swnj 	struct updevice *upaddr;
9502379Swnj 	char *start;
9513107Swnj 	int num, blk, unit;
9522379Swnj 	struct size *sizes;
9532395Swnj 	register struct uba_regs *uba;
9542983Swnj 	register struct uba_device *ui;
9552379Swnj 	register short *rp;
9562395Swnj 	struct upst *st;
9576848Ssam 	register int retry;
9582379Swnj 
9592395Swnj 	unit = minor(dev) >> 3;
9602889Swnj 	if (unit >= NUP)
9612889Swnj 		return (ENXIO);
9622470Swnj #define	phys(cast, addr) ((cast)((int)addr & 0x7fffffff))
9632983Swnj 	ui = phys(struct uba_device *, updinfo[unit]);
9642889Swnj 	if (ui->ui_alive == 0)
9652889Swnj 		return (ENXIO);
9662395Swnj 	uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba;
9672983Swnj 	ubainit(uba);
9682629Swnj 	upaddr = (struct updevice *)ui->ui_physaddr;
9696848Ssam 	DELAY(5000000);
9702379Swnj 	num = maxfree;
9712379Swnj 	upaddr->upcs2 = unit;
9722983Swnj 	DELAY(100);
9736848Ssam 	upaddr->upcs1 = UP_DCLR|UP_GO;
9746848Ssam 	upaddr->upcs1 = UP_PRESET|UP_GO;
9756848Ssam 	upaddr->upof = UPOF_FMT22;
9766848Ssam 	retry = 0;
9776848Ssam 	do {
9786848Ssam 		DELAY(25);
9796848Ssam 		if (++retry > 527)
9806848Ssam 			break;
9816861Ssam 	} while ((upaddr->upds & UP_RDY) == 0);
9823445Sroot 	if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY)
9832889Swnj 		return (EFAULT);
9849357Ssam 	start = 0;
9858489Sroot 	st = &upst[ui->ui_type];
9862395Swnj 	sizes = phys(struct size *, st->sizes);
9872889Swnj 	if (dumplo < 0 || dumplo + num >= sizes[minor(dev)&07].nblocks)
9882889Swnj 		return (EINVAL);
9892379Swnj 	while (num > 0) {
9902379Swnj 		register struct pte *io;
9912379Swnj 		register int i;
9922379Swnj 		int cn, sn, tn;
9932379Swnj 		daddr_t bn;
9942379Swnj 
9952379Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9962395Swnj 		io = uba->uba_map;
9972379Swnj 		for (i = 0; i < blk; i++)
9982983Swnj 			*(int *)io++ = (btop(start)+i) | (1<<21) | UBAMR_MRV;
9992379Swnj 		*(int *)io = 0;
10002379Swnj 		bn = dumplo + btop(start);
10012607Swnj 		cn = bn/st->nspc + sizes[minor(dev)&07].cyloff;
10022607Swnj 		sn = bn%st->nspc;
10032607Swnj 		tn = sn/st->nsect;
10042607Swnj 		sn = sn%st->nsect;
10052379Swnj 		upaddr->updc = cn;
10062379Swnj 		rp = (short *) &upaddr->upda;
10072379Swnj 		*rp = (tn << 8) + sn;
10082379Swnj 		*--rp = 0;
10092379Swnj 		*--rp = -blk*NBPG / sizeof (short);
10102629Swnj 		*--rp = UP_GO|UP_WCOM;
10116848Ssam 		retry = 0;
10122379Swnj 		do {
10132379Swnj 			DELAY(25);
10146848Ssam 			if (++retry > 527)
10156848Ssam 				break;
10162629Swnj 		} while ((upaddr->upcs1 & UP_RDY) == 0);
10176848Ssam 		if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
10186861Ssam 			printf("up%d: not ready", unit);
10196848Ssam 			if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
10206848Ssam 				printf("\n");
10216848Ssam 				return (EIO);
10226848Ssam 			}
10236848Ssam 			printf(" (flakey)\n");
10246848Ssam 		}
10253445Sroot 		if (upaddr->upds&UPDS_ERR)
10262889Swnj 			return (EIO);
10272379Swnj 		start += blk*NBPG;
10282379Swnj 		num -= blk;
10292379Swnj 	}
10302379Swnj 	return (0);
10312379Swnj }
10321902Swnj #endif
1033