xref: /csrg-svn/sys/vax/mba/hp.c (revision 5893)
1*5893Swnj /*	hp.c	4.47	82/02/18	*/
23706Sroot 
33706Sroot #ifdef HPDEBUG
43289Swnj int	hpdebug;
53706Sroot #endif
63706Sroot #ifdef HPBDEBUG
73706Sroot int	hpbdebug;
83706Sroot #endif
921Sbill 
101939Swnj #include "hp.h"
111565Sbill #if NHP > 0
1221Sbill /*
135726Sroot  * HP disk driver for RP0x+RMxx+ML11
142827Swnj  *
152827Swnj  * TODO:
163706Sroot  *	check RM80 skip sector handling when ECC's occur later
173093Swnj  *	check offset recovery handling
183706Sroot  *	see if DCLR and/or RELEASE set attention status
193706Sroot  *	print bits of mr && mr2 symbolically
2021Sbill  */
2121Sbill 
2221Sbill #include "../h/param.h"
2321Sbill #include "../h/systm.h"
24305Sbill #include "../h/dk.h"
2521Sbill #include "../h/buf.h"
2621Sbill #include "../h/conf.h"
2721Sbill #include "../h/dir.h"
2821Sbill #include "../h/user.h"
2921Sbill #include "../h/map.h"
30420Sbill #include "../h/pte.h"
312978Swnj #include "../h/mbareg.h"
322978Swnj #include "../h/mbavar.h"
3321Sbill #include "../h/mtpr.h"
34420Sbill #include "../h/vm.h"
352362Swnj #include "../h/cmap.h"
363706Sroot #include "../h/dkbad.h"
375726Sroot #include "../h/dkio.h"
3821Sbill 
392383Swnj #include "../h/hpreg.h"
4021Sbill 
412383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
422383Swnj struct	size {
4321Sbill 	daddr_t	nblocks;
4421Sbill 	int	cyloff;
453706Sroot } hp6_sizes[8] = {
46886Sbill 	15884,	0,		/* A=cyl 0 thru 37 */
47886Sbill 	33440,	38,		/* B=cyl 38 thru 117 */
48886Sbill 	340670,	0,		/* C=cyl 0 thru 814 */
4921Sbill 	0,	0,
5021Sbill 	0,	0,
5121Sbill 	0,	0,
523726Sroot #ifndef NOBADSECT
533729Sroot 	291280,	118,		/* G=cyl 118 thru 814 */
543706Sroot #else
553706Sroot 	291346,	118,
563706Sroot #endif
5721Sbill 	0,	0,
583706Sroot }, rm3_sizes[8] = {
59886Sbill 	15884,	0,		/* A=cyl 0 thru 99 */
60886Sbill 	33440,	100,		/* B=cyl 100 thru 309 */
61886Sbill 	131680,	0,		/* C=cyl 0 thru 822 */
6221Sbill 	0,	0,
6321Sbill 	0,	0,
643442Sroot 	0,	0,
653726Sroot #ifndef NOBADSECT
663729Sroot 	81984,	310,		/* G=cyl 310 thru 822 */
673706Sroot #else
683706Sroot 	82080,	310,
693706Sroot #endif
7021Sbill 	0,	0,
71886Sbill }, rm5_sizes[8] = {
72886Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
73886Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
743271Swnj 	500384,	0,		/* C=cyl 0 thru 822 */
75886Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
76886Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
773726Sroot #ifndef NOBADSECT
783729Sroot 	86240,	681,		/* F=cyl 681 thru 822 */
793729Sroot 	158592,	562,		/* G=cyl 562 thru 822 */
803706Sroot #else
815695Sroot 	86336,	681,
823706Sroot 	158688,	562,
833706Sroot #endif
84886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
852383Swnj }, rm80_sizes[8] = {
862383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
872383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
882383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
892383Swnj 	0,	0,
902383Swnj 	0,	0,
912383Swnj 	0,	0,
922383Swnj 	82080,	115,		/* G=cyl 115 thru 304 */
933729Sroot 	110143,	305,		/* H=cyl 305 thru 558 */
943706Sroot }, hp7_sizes[8] = {
953706Sroot 	15844,	0,		/* A=cyl 0 thru 9 */
963706Sroot 	64000,	10,		/* B=cyl 10 thru 49 */
973706Sroot 	1008000,0,		/* C=cyl 0 thru 629 */
983706Sroot 	15884,	330,		/* D=cyl 330 thru 339 */
993706Sroot 	256000,	340,		/* E=cyl 340 thru 499 */
1003729Sroot 	207850,	500,		/* F=cyl 500 thru 629 */
1013729Sroot 	479850,	330,		/* G=cyl 330 thru 629 */
1023706Sroot 	448000,	50,		/* H=cyl 50 thru 329 */
10321Sbill };
1042383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
10521Sbill 
1062383Swnj #define	_hpSDIST	2
1072383Swnj #define	_hpRDIST	3
1082383Swnj 
1092383Swnj int	hpSDIST = _hpSDIST;
1102383Swnj int	hpRDIST = _hpRDIST;
1112383Swnj 
1122383Swnj short	hptypes[] =
1135726Sroot 	{ MBDT_RM03, MBDT_RM05, MBDT_RP06, MBDT_RM80, MBDT_RP05, MBDT_RP07,
1145726Sroot 	  MBDT_ML11A, MBDT_ML11B, 0 };
1152978Swnj struct	mba_device *hpinfo[NHP];
1162978Swnj int	hpattach(),hpustart(),hpstart(),hpdtint();
1172383Swnj struct	mba_driver hpdriver =
1182978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
1192978Swnj 	  hptypes, "hp", 0, hpinfo };
1202383Swnj 
1212383Swnj struct hpst {
1222383Swnj 	short	nsect;
1232383Swnj 	short	ntrak;
1242383Swnj 	short	nspc;
1252383Swnj 	short	ncyl;
1262383Swnj 	struct	size *sizes;
1272383Swnj } hpst[] = {
1283706Sroot 	32,	5,	32*5,	823,	rm3_sizes,	/* RM03 */
1292383Swnj 	32,	19,	32*19,	823,	rm5_sizes,	/* RM05 */
1303706Sroot 	22,	19,	22*19,	815,	hp6_sizes,	/* RP06 */
1313706Sroot 	31,	14, 	31*14,	559,	rm80_sizes,	/* RM80 */
1323706Sroot 	22,	19,	22*19,	411,	hp6_sizes,	/* RP05 */
1333706Sroot 	50,	32,	50*32,	630,	hp7_sizes,	/* RP07 */
1345726Sroot 	1,	1,	1,	1,	0,		/* ML11A */
1355726Sroot 	1,	1,	1,	1,	0,		/* ML11B */
1362383Swnj };
1372383Swnj 
1382624Swnj u_char	hp_offset[16] = {
1393093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
1403093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
1413093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
1423093Swnj     0, 0, 0, 0,
14321Sbill };
14421Sbill 
1452624Swnj struct	buf	rhpbuf[NHP];
1463726Sroot #ifndef NOBADSECT
1473706Sroot struct	buf	bhpbuf[NHP];
1483706Sroot struct	dkbad	hpbad[NHP];
1493706Sroot #endif
1505726Sroot /* SHOULD CONSOLIDATE ALL THIS STUFF INTO A STRUCTURE */
1513706Sroot char	hpinit[NHP];
1522892Swnj char	hprecal[NHP];
1535726Sroot char	hphdr[NHP];
1545726Sroot daddr_t	mlsize[NHP];
15521Sbill 
15621Sbill #define	b_cylin b_resid
15721Sbill 
1585726Sroot /* #define ML11 0  to remove ML11 support */
1595726Sroot #define	ML11	(hptypes[mi->mi_type] == MBDT_ML11A)
1605726Sroot #define	RP06	(hptypes[mi->mi_type] <= MBDT_RP06)
1615726Sroot #define	RM80	(hptypes[mi->mi_type] == MBDT_RM80)
1625726Sroot 
16321Sbill #ifdef INTRLVE
16421Sbill daddr_t dkblock();
16521Sbill #endif
16621Sbill 
1672604Swnj int	hpseek;
1682604Swnj 
1692978Swnj /*ARGSUSED*/
1702978Swnj hpattach(mi, slave)
1712978Swnj 	struct mba_device *mi;
1722604Swnj {
1735726Sroot 	if (hptypes[mi->mi_type] == MBDT_ML11B)
1745726Sroot 		mi->mi_type--;	/* A CHEAT - ML11B D.T. SHOULD == ML11A */
1755726Sroot 	if (ML11) {
1765726Sroot 		register struct hpdevice *hpaddr =
1775726Sroot 			(struct hpdevice *)mi->mi_drv;
1785726Sroot 		register int trt, sz;
1792604Swnj 
1805726Sroot 		sz = hpaddr->hpmr & HPMR_SZ;
1815726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
1825726Sroot 			sz >>= 2;
1835726Sroot 		mlsize[mi->mi_unit] = sz;
1845726Sroot 		if (mi->mi_dk >= 0) {
1855726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
1865726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
1875726Sroot 		}
1885726Sroot 	} else if (mi->mi_dk >= 0) {
1895726Sroot 		register struct hpst *st = &hpst[mi->mi_type];
1905726Sroot 
1912757Swnj 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
1925726Sroot 	}
1932604Swnj }
1942604Swnj 
19521Sbill hpstrategy(bp)
1962383Swnj 	register struct buf *bp;
19721Sbill {
1982978Swnj 	register struct mba_device *mi;
1992383Swnj 	register struct hpst *st;
2002383Swnj 	register int unit;
20121Sbill 	long sz, bn;
2022383Swnj 	int xunit = minor(bp->b_dev) & 07;
2035432Sroot 	int s;
20421Sbill 
20521Sbill 	sz = bp->b_bcount;
20621Sbill 	sz = (sz+511) >> 9;
20721Sbill 	unit = dkunit(bp);
2082383Swnj 	if (unit >= NHP)
2092383Swnj 		goto bad;
2102383Swnj 	mi = hpinfo[unit];
2112395Swnj 	if (mi == 0 || mi->mi_alive == 0)
2122383Swnj 		goto bad;
2132383Swnj 	st = &hpst[mi->mi_type];
2145726Sroot 	if (ML11) {
2155726Sroot 		if (bp->b_blkno < 0 ||
2165726Sroot 		    dkblock(bp)+sz > mlsize[mi->mi_unit])
2175726Sroot 			goto bad;
2185726Sroot 		bp->b_cylin = 0;
2195726Sroot 	} else {
2205726Sroot 		if (bp->b_blkno < 0 ||
2215726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
2225726Sroot 			goto bad;
2235726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
2245726Sroot 	}
2255432Sroot 	s = spl5();
2262383Swnj 	disksort(&mi->mi_tab, bp);
2272383Swnj 	if (mi->mi_tab.b_active == 0)
2282383Swnj 		mbustart(mi);
2295432Sroot 	splx(s);
2302383Swnj 	return;
2312383Swnj 
2322383Swnj bad:
2332383Swnj 	bp->b_flags |= B_ERROR;
2342383Swnj 	iodone(bp);
2352383Swnj 	return;
23621Sbill }
23721Sbill 
2382383Swnj hpustart(mi)
2392978Swnj 	register struct mba_device *mi;
24021Sbill {
2412624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
2422383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
2433706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
24421Sbill 	daddr_t bn;
2453102Swnj 	int sn, dist;
24621Sbill 
2473706Sroot 	hpaddr->hpcs1 = 0;
2482624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
2492383Swnj 		return (MBU_BUSY);
2503706Sroot 	if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) {
2513726Sroot #ifndef NOBADSECT
2523706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
2533706Sroot #endif
2543706Sroot 
2553706Sroot 		hpinit[mi->mi_unit] = 1;
2562624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
2573140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
2583140Swnj 			printf("DCLR attn\n");
2592624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
2605726Sroot 		if (!ML11)
2615726Sroot 			hpaddr->hpof = HPOF_FMT22;
2623140Swnj 		mbclrattn(mi);
2633726Sroot #ifndef NOBADSECT
2645726Sroot 		if (!ML11) {
2655726Sroot 			bbp->b_flags = B_READ|B_BUSY;
2665726Sroot 			bbp->b_dev = bp->b_dev;
2675726Sroot 			bbp->b_bcount = 512;
2685726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
2695726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
2705726Sroot 			bbp->b_cylin = st->ncyl - 1;
2715726Sroot 			mi->mi_tab.b_actf = bbp;
2725726Sroot 			bbp->av_forw = bp;
2735726Sroot 			bp = bbp;
2745726Sroot 		}
2753706Sroot #endif
27621Sbill 	}
2772604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
2782383Swnj 		return (MBU_DODATA);
2795726Sroot 	if (ML11)
2805726Sroot 		return (MBU_DODATA);
2813093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
2822383Swnj 		return (MBU_DODATA);
2832395Swnj 	bn = dkblock(bp);
2842395Swnj 	sn = bn%st->nspc;
2852395Swnj 	sn = (sn+st->nsect-hpSDIST)%st->nsect;
2862383Swnj 	if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) {
2872604Swnj 		if (hpseek)
2882383Swnj 			return (MBU_DODATA);
2892383Swnj 		dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1;
2902383Swnj 		if (dist < 0)
2912383Swnj 			dist += st->nsect;
2922383Swnj 		if (dist > st->nsect - hpRDIST)
2932383Swnj 			return (MBU_DODATA);
2942614Swnj 	} else
2952614Swnj 		hpaddr->hpdc = bp->b_cylin;
2962604Swnj 	if (hpseek)
2972624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
298305Sbill 	else {
299305Sbill 		hpaddr->hpda = sn;
3002624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
301305Sbill 	}
3022383Swnj 	return (MBU_STARTED);
30321Sbill }
30421Sbill 
3052383Swnj hpstart(mi)
3062978Swnj 	register struct mba_device *mi;
30721Sbill {
3082624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
3092383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
3102383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
31121Sbill 	daddr_t bn;
3122383Swnj 	int sn, tn;
31321Sbill 
31421Sbill 	bn = dkblock(bp);
3155726Sroot 	if (ML11)
3165726Sroot 		hpaddr->hpda = bn;
3175726Sroot 	else {
3185726Sroot 		sn = bn%st->nspc;
3195726Sroot 		tn = sn/st->nsect;
3205726Sroot 		sn %= st->nsect;
3215726Sroot 		hpaddr->hpdc = bp->b_cylin;
3225726Sroot 		hpaddr->hpda = (tn << 8) + sn;
3235726Sroot 	}
3245726Sroot 	if (hphdr[mi->mi_unit]) {
3255726Sroot 		if (bp->b_flags & B_READ)
3265726Sroot 			return (HP_RHDR|HP_GO);
3275726Sroot 		else
3285726Sroot 			return (HP_WHDR|HP_GO);
3295726Sroot 	}
3305726Sroot 	return (0);
33121Sbill }
33221Sbill 
3333102Swnj hpdtint(mi, mbsr)
3342978Swnj 	register struct mba_device *mi;
3353102Swnj 	int mbsr;
33621Sbill {
3372624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
3382383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
339*5893Swnj 	register int er1, er2;
3402826Swnj 	int retry = 0;
34121Sbill 
3423726Sroot #ifndef NOBADSECT
3433706Sroot 	if (bp->b_flags&B_BAD) {
3443706Sroot 		if (hpecc(mi, CONT))
3453706Sroot 			return(MBD_RESTARTED);
3463706Sroot 	}
3473706Sroot #endif
3483102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
3493706Sroot #ifdef HPDEBUG
3503289Swnj 		if (hpdebug) {
3513706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
3523706Sroot 
3533706Sroot 			printf("hperr: bp %x cyl %d blk %d as %o ",
3543706Sroot 				bp, bp->b_cylin, bp->b_blkno,
3553706Sroot 				hpaddr->hpas&0xff);
3563706Sroot 			printf("dc %x da %x\n",dc&0xffff, da&0xffff);
3573289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
3583289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
3593289Swnj 			printf("er1=%b er2=%b\n",
3603289Swnj 			    hpaddr->hper1, HPER1_BITS,
3613289Swnj 			    hpaddr->hper2, HPER2_BITS);
3623289Swnj 			DELAY(1000000);
3633289Swnj 		}
3643706Sroot #endif
3655858Swnj 		er1 = hpaddr->hper1;
366*5893Swnj 		er2 = hpaddr->hper2;
367*5893Swnj 		if (er1 & HPER1_HCRC) {
3685858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
369*5893Swnj 			er2 &= ~HPER2_BSE;
370*5893Swnj 		}
3715858Swnj 		if (er1&HPER1_WLE) {
3722925Swnj 			printf("hp%d: write locked\n", dkunit(bp));
3732826Swnj 			bp->b_flags |= B_ERROR;
3745858Swnj 		} else if ((er1&0xffff) == HPER1_FER && RP06 &&
3755726Sroot 		    hphdr[mi->mi_unit] == 0) {
3765726Sroot #ifndef NOBADSECT
3775726Sroot 			if (hpecc(mi, BSE))
3785726Sroot 				return(MBD_RESTARTED);
3795726Sroot 			else
3805726Sroot #endif
3815726Sroot 				goto hard;
3822826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
3833102Swnj 		    mbsr & MBSR_HARD ||
3845858Swnj 		    er1 & HPER1_HARD ||
3855726Sroot 		    hphdr[mi->mi_unit] ||
386*5893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
3873706Sroot hard:
3882925Swnj 			harderr(bp, "hp");
3893271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
3903271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
3913706Sroot 			printf("er1=%b er2=%b",
3922826Swnj 			    hpaddr->hper1, HPER1_BITS,
3932826Swnj 			    hpaddr->hper2, HPER2_BITS);
3943706Sroot 			if (hpaddr->hpmr)
3953706Sroot 				printf(" mr=%o", hpaddr->hpmr&0xffff);
3963706Sroot 			if (hpaddr->hpmr2)
3973706Sroot 				printf(" mr2=%o", hpaddr->hpmr2&0xffff);
3983706Sroot 			printf("\n");
3992826Swnj 			bp->b_flags |= B_ERROR;
4003143Swnj 			hprecal[mi->mi_unit] = 0;
401*5893Swnj 		} else if ((er2 & HPER2_BSE) && !ML11) {
4023726Sroot #ifndef NOBADSECT
4033706Sroot 			if (hpecc(mi, BSE))
4043706Sroot 				return(MBD_RESTARTED);
4053706Sroot 			else
4063706Sroot #endif
4073706Sroot 				goto hard;
408*5893Swnj 		} else if (RM80 && er2&HPER2_SSE) {
4093988Sroot 			(void) hpecc(mi, SSE);
4102883Swnj 			return (MBD_RESTARTED);
4115858Swnj 		} else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) {
4123706Sroot 			if (hpecc(mi, ECC))
4132383Swnj 				return (MBD_RESTARTED);
4142826Swnj 			/* else done */
4152826Swnj 		} else
4162826Swnj 			retry = 1;
4172826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4185726Sroot 		if (ML11) {
4195726Sroot 			if (mi->mi_tab.b_errcnt >= 16)
4205726Sroot 				goto hard;
4215726Sroot 		} else if ((mi->mi_tab.b_errcnt&07) == 4) {
4222826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
4233706Sroot 			hprecal[mi->mi_unit] = 1;
4243706Sroot 			return(MBD_RESTARTED);
42521Sbill 		}
4262826Swnj 		if (retry)
4272826Swnj 			return (MBD_RETRY);
4282826Swnj 	}
4293706Sroot #ifdef HPDEBUG
4303289Swnj 	else
4313289Swnj 		if (hpdebug && hprecal[mi->mi_unit]) {
4323289Swnj 			printf("recal %d ", hprecal[mi->mi_unit]);
4333289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
4343289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
4353289Swnj 			printf("er1=%b er2=%b\n",
4363289Swnj 			    hpaddr->hper1, HPER1_BITS,
4373289Swnj 			    hpaddr->hper2, HPER2_BITS);
4383289Swnj 		}
4393706Sroot #endif
4403093Swnj 	switch (hprecal[mi->mi_unit]) {
4413093Swnj 
4423093Swnj 	case 1:
4433093Swnj 		hpaddr->hpdc = bp->b_cylin;
4443093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
4453706Sroot 		hprecal[mi->mi_unit]++;
4463706Sroot 		return (MBD_RESTARTED);
4473093Swnj 	case 2:
4483093Swnj 		if (mi->mi_tab.b_errcnt < 16 ||
4493289Swnj 		    (bp->b_flags & B_READ) == 0)
4503093Swnj 			goto donerecal;
4513093Swnj 		hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
4523093Swnj 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
4533093Swnj 		hprecal[mi->mi_unit]++;
4543093Swnj 		return (MBD_RESTARTED);
4553093Swnj 	donerecal:
4563158Swnj 	case 3:
4572892Swnj 		hprecal[mi->mi_unit] = 0;
4582892Swnj 		return (MBD_RETRY);
4592892Swnj 	}
4605726Sroot 	hphdr[mi->mi_unit] = 0;
4612383Swnj 	bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
4623640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
4633093Swnj 		/*
4643093Swnj 		 * This is fast and occurs rarely; we don't
4653093Swnj 		 * bother with interrupts.
4663093Swnj 		 */
4672624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
4683093Swnj 		while (hpaddr->hpds & HPDS_PIP)
4692383Swnj 			;
4702383Swnj 		mbclrattn(mi);
47121Sbill 	}
4725726Sroot 	if (!ML11) {
4735726Sroot 		hpaddr->hpof = HPOF_FMT22;
4745726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
4755726Sroot 	}
4762383Swnj 	return (MBD_DONE);
47721Sbill }
47821Sbill 
47921Sbill hpread(dev)
4802624Swnj 	dev_t dev;
48121Sbill {
4822624Swnj 	register int unit = minor(dev) >> 3;
48321Sbill 
4842624Swnj 	if (unit >= NHP)
4852624Swnj 		u.u_error = ENXIO;
4862624Swnj 	else
4872624Swnj 		physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys);
48821Sbill }
48921Sbill 
49021Sbill hpwrite(dev)
4912624Swnj 	dev_t dev;
49221Sbill {
4932624Swnj 	register int unit = minor(dev) >> 3;
49421Sbill 
4952624Swnj 	if (unit >= NHP)
4962624Swnj 		u.u_error = ENXIO;
4972624Swnj 	else
4982624Swnj 		physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys);
49921Sbill }
50021Sbill 
5015726Sroot /*ARGSUSED*/
5025726Sroot hpioctl(dev, cmd, addr, flag)
5035726Sroot 	dev_t dev;
5045726Sroot 	int cmd;
5055726Sroot 	caddr_t addr;
5065726Sroot 	int flag;
5075726Sroot {
5085726Sroot 
5095726Sroot 	switch (cmd) {
5105726Sroot 	case DKIOCHDR:	/* do header read/write */
5115726Sroot 		hphdr[minor(dev)>>3] = 1;
5125726Sroot 		return;
5135726Sroot 
5145726Sroot 	default:
5155726Sroot 		u.u_error = ENXIO;
5165726Sroot 	}
5175726Sroot }
5185726Sroot 
5193706Sroot hpecc(mi, flag)
5202978Swnj 	register struct mba_device *mi;
5213706Sroot 	int flag;
52221Sbill {
5232383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
5242624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
5252383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5263706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
5273706Sroot 	int npf, o;
5282383Swnj 	int bn, cn, tn, sn;
529914Sbill 	int bcr;
53021Sbill 
531914Sbill 	bcr = mbp->mba_bcr & 0xffff;
532914Sbill 	if (bcr)
533914Sbill 		bcr |= 0xffff0000;		/* sxt */
5343726Sroot #ifndef NOBADSECT
5353706Sroot 	if (flag == CONT)
5363706Sroot 		npf = bp->b_error;
5373706Sroot 	else
5383706Sroot #endif
5393706Sroot 		npf = btop(bcr + bp->b_bcount);
540420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
541420Sbill 	bn = dkblock(bp);
542420Sbill 	cn = bp->b_cylin;
5433706Sroot 	sn = bn%(st->nspc) + npf;
5442383Swnj 	tn = sn/st->nsect;
5452383Swnj 	sn %= st->nsect;
5462383Swnj 	cn += tn/st->ntrak;
5472383Swnj 	tn %= st->ntrak;
5483706Sroot 	switch (flag) {
5493706Sroot 	case ECC:
5503706Sroot 		{
5513706Sroot 		register int i;
5523706Sroot 		caddr_t addr;
5533706Sroot 		struct pte mpte;
5543706Sroot 		int bit, byte, mask;
5553706Sroot 
5563706Sroot 		npf--;		/* because block in error is previous block */
5573706Sroot 		printf("hp%d%c: soft ecc sn%d\n", dkunit(bp),
5583706Sroot 		    'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
5593706Sroot 		mask = rp->hpec2&0xffff;
5603706Sroot 		i = (rp->hpec1&0xffff) - 1;		/* -1 makes 0 origin */
5613706Sroot 		bit = i&07;
5623706Sroot 		i = (i&~07)>>3;
5633706Sroot 		byte = i + o;
5643706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
5653706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
5663706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
5673706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
5683706Sroot 			byte++;
5693706Sroot 			i++;
5703706Sroot 			bit -= 8;
5713706Sroot 		}
5723706Sroot 		if (bcr == 0)
5733706Sroot 			return (0);
5743847Sroot 		npf++;
5753706Sroot 		break;
5763706Sroot 		}
5773706Sroot 
5783706Sroot 	case SSE:
5793706Sroot 		rp->hpof |= HPOF_SSEI;
5803706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
5813706Sroot 		break;
5823706Sroot 
5833726Sroot #ifndef NOBADSECT
5843706Sroot 	case BSE:
5853706Sroot #ifdef HPBDEBUG
5863706Sroot 		if (hpbdebug)
5873706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
5883706Sroot #endif
5893706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
5903706Sroot 			return(0);
5913706Sroot 		bp->b_flags |= B_BAD;
5923706Sroot 		bp->b_error = npf + 1;
5933706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
5943706Sroot 		cn = bn/st->nspc;
5953706Sroot 		sn = bn%st->nspc;
5963706Sroot 		tn = sn/st->nsect;
5973706Sroot 		sn %= st->nsect;
5983706Sroot 		mbp->mba_bcr = -512;
5993706Sroot #ifdef HPBDEBUG
6003706Sroot 		if (hpbdebug)
6013706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
6023706Sroot #endif
6033706Sroot 		break;
6043706Sroot 
6053706Sroot 	case CONT:
6063706Sroot #ifdef HPBDEBUG
6073706Sroot 		if (hpbdebug)
6083706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
6093706Sroot #endif
6103706Sroot 		npf = bp->b_error;
6113706Sroot 		bp->b_flags &= ~B_BAD;
6123706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
6133706Sroot 		if ((mbp->mba_bcr & 0xffff) == 0)
6143706Sroot 			return(0);
6153706Sroot 		break;
6163706Sroot #endif
6173706Sroot 	}
6183706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
6193350Swnj 	if (rp->hpof&HPOF_SSEI)
6202883Swnj 		sn++;
621420Sbill 	rp->hpdc = cn;
622420Sbill 	rp->hpda = (tn<<8) + sn;
623420Sbill 	mbp->mba_sr = -1;
6243706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
6253706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
6263706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
627420Sbill 	return (1);
62821Sbill }
6292362Swnj 
6302362Swnj #define	DBSIZE	20
6312362Swnj 
6322362Swnj hpdump(dev)
6332362Swnj 	dev_t dev;
6342362Swnj {
6352978Swnj 	register struct mba_device *mi;
6362383Swnj 	register struct mba_regs *mba;
6372624Swnj 	struct hpdevice *hpaddr;
6382362Swnj 	char *start;
6392383Swnj 	int num, unit;
6402383Swnj 	register struct hpst *st;
6412362Swnj 
6422362Swnj 	num = maxfree;
6432362Swnj 	start = 0;
6442362Swnj 	unit = minor(dev) >> 3;
6452827Swnj 	if (unit >= NHP)
6462827Swnj 		return (ENXIO);
6472383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
6482978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
6492827Swnj 	if (mi == 0 || mi->mi_alive == 0)
6502827Swnj 		return (ENXIO);
6512383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
6523102Swnj 	mba->mba_cr = MBCR_INIT;
6532624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
6543093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
6552624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
6562624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
6573093Swnj 		hpaddr->hpof = HPOF_FMT22;
6582362Swnj 	}
6592383Swnj 	st = &hpst[mi->mi_type];
6602827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
6612827Swnj 		return (EINVAL);
6622362Swnj 	while (num > 0) {
6632383Swnj 		register struct pte *hpte = mba->mba_map;
6642362Swnj 		register int i;
6652383Swnj 		int blk, cn, sn, tn;
6662362Swnj 		daddr_t bn;
6672362Swnj 
6682362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
6692362Swnj 		bn = dumplo + btop(start);
6702383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
6712383Swnj 		sn = bn%st->nspc;
6722383Swnj 		tn = sn/st->nsect;
6732383Swnj 		sn = sn%st->nsect;
6742362Swnj 		hpaddr->hpdc = cn;
6752362Swnj 		hpaddr->hpda = (tn << 8) + sn;
6762362Swnj 		for (i = 0; i < blk; i++)
6772362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
6782383Swnj 		mba->mba_sr = -1;
6792383Swnj 		mba->mba_bcr = -(blk*NBPG);
6802383Swnj 		mba->mba_var = 0;
6812624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
6823093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
6832362Swnj 			;
6843093Swnj 		if (hpaddr->hpds&HPDS_ERR)
6852827Swnj 			return (EIO);
6862362Swnj 		start += blk*NBPG;
6872362Swnj 		num -= blk;
6882362Swnj 	}
6892362Swnj 	return (0);
6902362Swnj }
6911565Sbill #endif
692