xref: /csrg-svn/sys/vax/mba/hp.c (revision 9175)
1*9175Ssam /*	hp.c	4.58	82/11/13	*/
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"
318468Sroot #include "../vax/mtpr.h"
32420Sbill #include "../h/vm.h"
332362Swnj #include "../h/cmap.h"
343706Sroot #include "../h/dkbad.h"
357635Ssam #include "../h/ioctl.h"
367738Sroot #include "../h/uio.h"
3721Sbill 
388988Sroot #include "../vax/dkio.h"
398468Sroot #include "../vaxmba/mbareg.h"
408468Sroot #include "../vaxmba/mbavar.h"
418468Sroot #include "../vaxmba/hpreg.h"
4221Sbill 
432383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
442383Swnj struct	size {
4521Sbill 	daddr_t	nblocks;
4621Sbill 	int	cyloff;
473706Sroot } hp6_sizes[8] = {
48886Sbill 	15884,	0,		/* A=cyl 0 thru 37 */
49886Sbill 	33440,	38,		/* B=cyl 38 thru 117 */
50886Sbill 	340670,	0,		/* C=cyl 0 thru 814 */
5121Sbill 	0,	0,
5221Sbill 	0,	0,
5321Sbill 	0,	0,
543726Sroot #ifndef NOBADSECT
553729Sroot 	291280,	118,		/* G=cyl 118 thru 814 */
563706Sroot #else
573706Sroot 	291346,	118,
583706Sroot #endif
5921Sbill 	0,	0,
603706Sroot }, rm3_sizes[8] = {
61886Sbill 	15884,	0,		/* A=cyl 0 thru 99 */
62886Sbill 	33440,	100,		/* B=cyl 100 thru 309 */
63886Sbill 	131680,	0,		/* C=cyl 0 thru 822 */
6421Sbill 	0,	0,
6521Sbill 	0,	0,
663442Sroot 	0,	0,
673726Sroot #ifndef NOBADSECT
683729Sroot 	81984,	310,		/* G=cyl 310 thru 822 */
693706Sroot #else
703706Sroot 	82080,	310,
713706Sroot #endif
7221Sbill 	0,	0,
73886Sbill }, rm5_sizes[8] = {
746927Ssam #ifndef CAD
75886Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
76886Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
773271Swnj 	500384,	0,		/* C=cyl 0 thru 822 */
78886Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
79886Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
803726Sroot #ifndef NOBADSECT
813729Sroot 	86240,	681,		/* F=cyl 681 thru 822 */
823729Sroot 	158592,	562,		/* G=cyl 562 thru 822 */
833706Sroot #else
845695Sroot 	86336,	681,
853706Sroot 	158688,	562,
863706Sroot #endif
87886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
886927Ssam #else
896927Ssam 	15884,	0,		/* A=cyl 0 thru 26 */
906927Ssam 	33440,	27,		/* B=cyl 27 thru 81 */
916927Ssam 	495520,	0,		/* C=cyl 0 thru 814 */
926927Ssam 	15884,	562,		/* D=cyl 562 thru 588 */
936927Ssam 	55936,	589,		/* E=cyl 589 thru 680 */
946927Ssam #ifndef NOBADSECT
956927Ssam 	81376,	681,		/* F=cyl 681 thru 814 */
966927Ssam 	153728,	562,		/* G=cyl 562 thru 814 */
976927Ssam #else
986927Ssam 	81472,	681,
996927Ssam 	153824,	562,
1006927Ssam #endif
1016927Ssam 	291346,	82,		/* H=cyl 82 thru 561 */
1026927Ssam #endif
1032383Swnj }, rm80_sizes[8] = {
1042383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
1052383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
1062383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
1072383Swnj 	0,	0,
1082383Swnj 	0,	0,
1092383Swnj 	0,	0,
1102383Swnj 	82080,	115,		/* G=cyl 115 thru 304 */
1113729Sroot 	110143,	305,		/* H=cyl 305 thru 558 */
1123706Sroot }, hp7_sizes[8] = {
1136927Ssam 	15884,	0,		/* A=cyl 0 thru 9 */
1143706Sroot 	64000,	10,		/* B=cyl 10 thru 49 */
1153706Sroot 	1008000,0,		/* C=cyl 0 thru 629 */
1163706Sroot 	15884,	330,		/* D=cyl 330 thru 339 */
1173706Sroot 	256000,	340,		/* E=cyl 340 thru 499 */
1183729Sroot 	207850,	500,		/* F=cyl 500 thru 629 */
1193729Sroot 	479850,	330,		/* G=cyl 330 thru 629 */
1203706Sroot 	448000,	50,		/* H=cyl 50 thru 329 */
1216927Ssam }, si9775_sizes[8] = {
1226927Ssam 	16640,	  0,		/* A=cyl   0 thru  12 */
1236927Ssam 	34560,	 13,		/* B=cyl  13 thru  39 */
1246927Ssam 	1079040,  0,		/* C=cyl   0 thru 842 - whole disk */
1256927Ssam 	0,	  0,		/* D unused */
1266927Ssam 	0,	  0,		/* E unused */
1276927Ssam 	0,	  0,		/* F unused */
1286927Ssam 	513280,	 40,		/* G=cyl  40 thru 440 */
1296927Ssam 	513280,	441,		/* H=cyl 441 thru 841 */
1306927Ssam }, si9730_sizes[8] = {
1316927Ssam 	15884,	0,		/* A=cyl 0 thru 49 */
1326927Ssam 	33440,	50,		/* B=cyl 50 thru 154 */
1336927Ssam 	263360,	0,		/* C=cyl 0 thru 822 */
1346927Ssam 	0,	0,
1356927Ssam 	0,	0,
1366927Ssam 	0,	0,
1376927Ssam 	0,	0,
1386927Ssam #ifndef NOBADSECT
1396927Ssam 	213664,	155,		/* H=cyl 155 thru 822 */
1406927Ssam #else
1416927Ssam 	213760,	155,
1426927Ssam #endif
1436927Ssam }, hpam_sizes[8] = {
1446927Ssam 	15884,	0,		/* A=cyl 0 thru 31 */
1456927Ssam 	33440,	32,		/* B=cyl 32 thru 97 */
1466927Ssam 	524288,	0,		/* C=cyl 0 thru 1023 */
1476927Ssam 	27786,	668,
1486927Ssam 	27786,	723,
1496927Ssam 	125440,	778,
1506927Ssam 	181760,	668,		/* G=cyl 668 thru 1022 */
1516927Ssam 	291346,	98,		/* H=cyl 98 thru 667 */
152*9175Ssam }, hpfj_sizes[8] = {
153*9175Ssam 	15884,	0,		/* A=cyl 0 thru 18 */
154*9175Ssam 	33440,	19,		/* B=cyl 19 thru 58 */
155*9175Ssam 	723991,	0,		/* C=cyl 0 thru 841 */
156*9175Ssam 	0, 0,
157*9175Ssam 	0, 0,
158*9175Ssam 	0, 0,
159*9175Ssam 	381711, 398,		/* G=cyl 398 thru 841 */
160*9175Ssam 	291346, 59,		/* H=cyl 59 thru 397 */
16121Sbill };
1622383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
16321Sbill 
1642383Swnj #define	_hpSDIST	2
1652383Swnj #define	_hpRDIST	3
1662383Swnj 
1672383Swnj int	hpSDIST = _hpSDIST;
1682383Swnj int	hpRDIST = _hpRDIST;
1692383Swnj 
1706927Ssam /*
1716927Ssam  * Table for converting Massbus drive types into
1726927Ssam  * indices into the partition tables.  Slots are
1736927Ssam  * left for those drives devined from other means
1746927Ssam  * (e.g. SI, AMPEX, etc.).
1756927Ssam  */
1766927Ssam short	hptypes[] = {
1776927Ssam #define	HPDT_RM03	0
1786927Ssam 	MBDT_RM03,
1796927Ssam #define	HPDT_RM05	1
1806927Ssam 	MBDT_RM05,
1816927Ssam #define	HPDT_RP06	2
1826927Ssam 	MBDT_RP06,
1836927Ssam #define	HPDT_RM80	3
1846927Ssam 	MBDT_RM80,
1856927Ssam #define	HPDT_RP05	4
1866927Ssam 	MBDT_RP05,
1876927Ssam #define	HPDT_RP07	5
1886927Ssam 	MBDT_RP07,
1896927Ssam #define	HPDT_ML11A	6
1906927Ssam 	MBDT_ML11A,
1916927Ssam #define	HPDT_ML11B	7
1926927Ssam 	MBDT_ML11B,
1936927Ssam #define	HPDT_9775	8
1946927Ssam 	-1,
1956927Ssam #define	HPDT_9730	9
1966927Ssam 	-1,
1976927Ssam #define	HPDT_CAPRICORN	10
1986927Ssam 	-1,
199*9175Ssam #define HPDT_EAGLE	11
200*9175Ssam 	-1,
201*9175Ssam #define HPDT_RM02	12
202*9175Ssam 	MBDT_RM02,		/* beware, actually capricorn or eagle */
2036927Ssam 	0
2046927Ssam };
2052978Swnj struct	mba_device *hpinfo[NHP];
2062978Swnj int	hpattach(),hpustart(),hpstart(),hpdtint();
2072383Swnj struct	mba_driver hpdriver =
2082978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
2092978Swnj 	  hptypes, "hp", 0, hpinfo };
2102383Swnj 
2112383Swnj struct hpst {
2122383Swnj 	short	nsect;
2132383Swnj 	short	ntrak;
2142383Swnj 	short	nspc;
2152383Swnj 	short	ncyl;
2162383Swnj 	struct	size *sizes;
2172383Swnj } hpst[] = {
2183706Sroot 	32,	5,	32*5,	823,	rm3_sizes,	/* RM03 */
2192383Swnj 	32,	19,	32*19,	823,	rm5_sizes,	/* RM05 */
2203706Sroot 	22,	19,	22*19,	815,	hp6_sizes,	/* RP06 */
2213706Sroot 	31,	14, 	31*14,	559,	rm80_sizes,	/* RM80 */
2223706Sroot 	22,	19,	22*19,	411,	hp6_sizes,	/* RP05 */
2233706Sroot 	50,	32,	50*32,	630,	hp7_sizes,	/* RP07 */
2245726Sroot 	1,	1,	1,	1,	0,		/* ML11A */
2255726Sroot 	1,	1,	1,	1,	0,		/* ML11B */
2266927Ssam 	32,	40,	32*40,	843,	si9775_sizes,	/* 9775 */
2276927Ssam 	32,	10,	32*10,	823,	si9730_sizes,	/* 9730 */
2286927Ssam 	32,	16,	32*16,	1024,	hpam_sizes,	/* AMPEX capricorn */
229*9175Ssam 	43,	20,	43*20,	843,	hpfj_sizes,	/* Fujitsu EAGLE */
2302383Swnj };
2312383Swnj 
2322624Swnj u_char	hp_offset[16] = {
2333093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
2343093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
2353093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
2363093Swnj     0, 0, 0, 0,
23721Sbill };
23821Sbill 
2392624Swnj struct	buf	rhpbuf[NHP];
2403726Sroot #ifndef NOBADSECT
2413706Sroot struct	buf	bhpbuf[NHP];
2423706Sroot struct	dkbad	hpbad[NHP];
2433706Sroot #endif
2445726Sroot /* SHOULD CONSOLIDATE ALL THIS STUFF INTO A STRUCTURE */
2453706Sroot char	hpinit[NHP];
2462892Swnj char	hprecal[NHP];
2475726Sroot char	hphdr[NHP];
2485726Sroot daddr_t	mlsize[NHP];
24921Sbill 
25021Sbill #define	b_cylin b_resid
25121Sbill 
2525726Sroot /* #define ML11 0  to remove ML11 support */
2535726Sroot #define	ML11	(hptypes[mi->mi_type] == MBDT_ML11A)
2545726Sroot #define	RP06	(hptypes[mi->mi_type] <= MBDT_RP06)
2555726Sroot #define	RM80	(hptypes[mi->mi_type] == MBDT_RM80)
2565726Sroot 
25721Sbill #ifdef INTRLVE
25821Sbill daddr_t dkblock();
25921Sbill #endif
26021Sbill 
2612604Swnj int	hpseek;
2622604Swnj 
2632978Swnj /*ARGSUSED*/
2642978Swnj hpattach(mi, slave)
2652978Swnj 	struct mba_device *mi;
2662604Swnj {
2676927Ssam 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
2686927Ssam 
2696927Ssam 	switch (mi->mi_type) {
2706927Ssam 
2716927Ssam 	/*
2726927Ssam 	 * Model-byte processing for SI 9400 controllers.
2736927Ssam 	 * NB:  Only deals with RM03 and RM05 emulations.
2746927Ssam 	 */
2756927Ssam 	case HPDT_RM03:
2766927Ssam 	case HPDT_RM05: {
2776927Ssam 		register int hpsn;
2786927Ssam 
2796927Ssam 		hpsn = hpaddr->hpsn;
2806927Ssam 		if ((hpsn & SIMB_LU) != mi->mi_drive)
2816927Ssam 			break;
2826927Ssam 		switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
2836927Ssam 
2846927Ssam 		case SI9775D:
2856927Ssam 			printf("hp%d: si 9775 (direct)\n", mi->mi_unit);
2866927Ssam 			mi->mi_type = HPDT_9775;
2876927Ssam 			break;
2886927Ssam 
2896927Ssam 		case SI9730D:
2906927Ssam 			printf("hp%d: si 9730 (direct)\n", mi->mi_unit);
2916927Ssam 			mi->mi_type = HPDT_9730;
2926927Ssam 			break;
2936927Ssam 
2946927Ssam #ifdef CAD
2957035Swnj 		/*
2967035Swnj 		 * AMPEX 9300, SI Combination needs a have the drive cleared
2977035Swnj 		 * before we start.  We do not know why, but tests show
2987035Swnj 		 * that the recalibrate fixes the problem.
2997035Swnj 		 */
3006927Ssam 		case SI9766:
3016927Ssam 			printf("hp%d: 9776/9300\n", mi->mi_unit);
3026927Ssam 			mi->mi_type = HPDT_RM05;
3037035Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
3047035Swnj 			DELAY(100000);
3056927Ssam 			break;
3066927Ssam 
3076927Ssam 		case SI9762:
3086927Ssam 			printf("hp%d: 9762\n", mi->mi_unit);
3096927Ssam 			mi->mi_type = HPDT_RM03;
3106927Ssam 			break;
3116927Ssam #endif
3126927Ssam 		}
3136927Ssam 		break;
3146927Ssam 		}
3156927Ssam 
3166927Ssam 	/*
3176927Ssam 	 * CAPRICORN KLUDGE...poke the holding register
318*9175Ssam 	 * we believe it's a Capricorn.  Otherwise assume
319*9175Ssam 	 * its an Eagle.
3206927Ssam 	 */
3216927Ssam 	case HPDT_RM02:
3226927Ssam 		hpaddr->hpcs1 = HP_NOP;
3236927Ssam 		hpaddr->hphr = HPHR_MAXTRAK;
3247313Ssam 		if ((hpaddr->hphr&0xffff) == 15) {
3256927Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
3266927Ssam 			mi->mi_type = HPDT_CAPRICORN;
327*9175Ssam 		} else {
328*9175Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
329*9175Ssam 			mi->mi_type = HPDT_EAGLE;
3306927Ssam 		}
3316927Ssam 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
3326927Ssam 		break;
3336927Ssam 
3346927Ssam 	case HPDT_ML11A:
3356927Ssam 	case HPDT_ML11B: {
3365726Sroot 		register int trt, sz;
3372604Swnj 
3385726Sroot 		sz = hpaddr->hpmr & HPMR_SZ;
3395726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
3405726Sroot 			sz >>= 2;
3415726Sroot 		mlsize[mi->mi_unit] = sz;
3425726Sroot 		if (mi->mi_dk >= 0) {
3435726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
3445726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
3455726Sroot 		}
3466927Ssam 		/* A CHEAT - ML11B D.T. SHOULD == ML11A */
3476927Ssam 		mi->mi_type = HPDT_ML11A;
3486927Ssam 		break;
3496927Ssam 		}
3506927Ssam 	}
3516927Ssam 	if (!ML11 && mi->mi_dk >= 0) {
3525726Sroot 		register struct hpst *st = &hpst[mi->mi_type];
3535726Sroot 
3542757Swnj 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
3555726Sroot 	}
3562604Swnj }
3572604Swnj 
3588579Sroot hpopen(dev)
3598579Sroot 	dev_t dev;
3608579Sroot {
3618579Sroot 	register int unit = minor(dev) >> 3;
3628579Sroot 	register struct mba_device *mi;
3638579Sroot 
3648579Sroot 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
3658579Sroot 		return (ENXIO);
3668579Sroot 	return (0);
3678579Sroot }
3688579Sroot 
36921Sbill hpstrategy(bp)
3702383Swnj 	register struct buf *bp;
37121Sbill {
3722978Swnj 	register struct mba_device *mi;
3732383Swnj 	register struct hpst *st;
3742383Swnj 	register int unit;
37521Sbill 	long sz, bn;
3762383Swnj 	int xunit = minor(bp->b_dev) & 07;
3775432Sroot 	int s;
37821Sbill 
37921Sbill 	sz = bp->b_bcount;
38021Sbill 	sz = (sz+511) >> 9;
38121Sbill 	unit = dkunit(bp);
3822383Swnj 	if (unit >= NHP)
3832383Swnj 		goto bad;
3842383Swnj 	mi = hpinfo[unit];
3852395Swnj 	if (mi == 0 || mi->mi_alive == 0)
3862383Swnj 		goto bad;
3872383Swnj 	st = &hpst[mi->mi_type];
3885726Sroot 	if (ML11) {
3895726Sroot 		if (bp->b_blkno < 0 ||
3905726Sroot 		    dkblock(bp)+sz > mlsize[mi->mi_unit])
3915726Sroot 			goto bad;
3925726Sroot 		bp->b_cylin = 0;
3935726Sroot 	} else {
3945726Sroot 		if (bp->b_blkno < 0 ||
3955726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
3965726Sroot 			goto bad;
3975726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
3985726Sroot 	}
3995432Sroot 	s = spl5();
4002383Swnj 	disksort(&mi->mi_tab, bp);
4012383Swnj 	if (mi->mi_tab.b_active == 0)
4022383Swnj 		mbustart(mi);
4035432Sroot 	splx(s);
4042383Swnj 	return;
4052383Swnj 
4062383Swnj bad:
4072383Swnj 	bp->b_flags |= B_ERROR;
4082383Swnj 	iodone(bp);
4092383Swnj 	return;
41021Sbill }
41121Sbill 
4122383Swnj hpustart(mi)
4132978Swnj 	register struct mba_device *mi;
41421Sbill {
4152624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4162383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
4173706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
41821Sbill 	daddr_t bn;
4193102Swnj 	int sn, dist;
42021Sbill 
4213706Sroot 	hpaddr->hpcs1 = 0;
4222624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
4232383Swnj 		return (MBU_BUSY);
4243706Sroot 	if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) {
4253726Sroot #ifndef NOBADSECT
4263706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
4273706Sroot #endif
4283706Sroot 
4293706Sroot 		hpinit[mi->mi_unit] = 1;
4302624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4313140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
4323140Swnj 			printf("DCLR attn\n");
4332624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
4345726Sroot 		if (!ML11)
4355726Sroot 			hpaddr->hpof = HPOF_FMT22;
4363140Swnj 		mbclrattn(mi);
4373726Sroot #ifndef NOBADSECT
4385726Sroot 		if (!ML11) {
4395726Sroot 			bbp->b_flags = B_READ|B_BUSY;
4405726Sroot 			bbp->b_dev = bp->b_dev;
4415726Sroot 			bbp->b_bcount = 512;
4425726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
4435726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
4445726Sroot 			bbp->b_cylin = st->ncyl - 1;
4455726Sroot 			mi->mi_tab.b_actf = bbp;
4465726Sroot 			bbp->av_forw = bp;
4475726Sroot 			bp = bbp;
4485726Sroot 		}
4493706Sroot #endif
45021Sbill 	}
4512604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
4522383Swnj 		return (MBU_DODATA);
4535726Sroot 	if (ML11)
4545726Sroot 		return (MBU_DODATA);
4553093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
4562383Swnj 		return (MBU_DODATA);
4572395Swnj 	bn = dkblock(bp);
4582395Swnj 	sn = bn%st->nspc;
4592395Swnj 	sn = (sn+st->nsect-hpSDIST)%st->nsect;
4602383Swnj 	if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) {
4612604Swnj 		if (hpseek)
4622383Swnj 			return (MBU_DODATA);
4632383Swnj 		dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1;
4642383Swnj 		if (dist < 0)
4652383Swnj 			dist += st->nsect;
4662383Swnj 		if (dist > st->nsect - hpRDIST)
4672383Swnj 			return (MBU_DODATA);
4682614Swnj 	} else
4692614Swnj 		hpaddr->hpdc = bp->b_cylin;
4702604Swnj 	if (hpseek)
4712624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
472305Sbill 	else {
473305Sbill 		hpaddr->hpda = sn;
4742624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
475305Sbill 	}
4762383Swnj 	return (MBU_STARTED);
47721Sbill }
47821Sbill 
4792383Swnj hpstart(mi)
4802978Swnj 	register struct mba_device *mi;
48121Sbill {
4822624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4832383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
4842383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
48521Sbill 	daddr_t bn;
4862383Swnj 	int sn, tn;
48721Sbill 
48821Sbill 	bn = dkblock(bp);
4895726Sroot 	if (ML11)
4905726Sroot 		hpaddr->hpda = bn;
4915726Sroot 	else {
4925726Sroot 		sn = bn%st->nspc;
4935726Sroot 		tn = sn/st->nsect;
4945726Sroot 		sn %= st->nsect;
4955726Sroot 		hpaddr->hpdc = bp->b_cylin;
4965726Sroot 		hpaddr->hpda = (tn << 8) + sn;
4975726Sroot 	}
4985726Sroot 	if (hphdr[mi->mi_unit]) {
4995726Sroot 		if (bp->b_flags & B_READ)
5005726Sroot 			return (HP_RHDR|HP_GO);
5015726Sroot 		else
5025726Sroot 			return (HP_WHDR|HP_GO);
5035726Sroot 	}
5045726Sroot 	return (0);
50521Sbill }
50621Sbill 
5073102Swnj hpdtint(mi, mbsr)
5082978Swnj 	register struct mba_device *mi;
5093102Swnj 	int mbsr;
51021Sbill {
5112624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5122383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5135893Swnj 	register int er1, er2;
5142826Swnj 	int retry = 0;
51521Sbill 
5163726Sroot #ifndef NOBADSECT
5173706Sroot 	if (bp->b_flags&B_BAD) {
5183706Sroot 		if (hpecc(mi, CONT))
5193706Sroot 			return(MBD_RESTARTED);
5203706Sroot 	}
5213706Sroot #endif
5223102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
5233706Sroot #ifdef HPDEBUG
5243289Swnj 		if (hpdebug) {
5253706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
5263706Sroot 
5273706Sroot 			printf("hperr: bp %x cyl %d blk %d as %o ",
5283706Sroot 				bp, bp->b_cylin, bp->b_blkno,
5293706Sroot 				hpaddr->hpas&0xff);
5303706Sroot 			printf("dc %x da %x\n",dc&0xffff, da&0xffff);
5313289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
5323289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
5333289Swnj 			printf("er1=%b er2=%b\n",
5343289Swnj 			    hpaddr->hper1, HPER1_BITS,
5353289Swnj 			    hpaddr->hper2, HPER2_BITS);
5363289Swnj 			DELAY(1000000);
5373289Swnj 		}
5383706Sroot #endif
5395858Swnj 		er1 = hpaddr->hper1;
5405893Swnj 		er2 = hpaddr->hper2;
5415893Swnj 		if (er1 & HPER1_HCRC) {
5425858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
5435893Swnj 			er2 &= ~HPER2_BSE;
5445893Swnj 		}
5455858Swnj 		if (er1&HPER1_WLE) {
5462925Swnj 			printf("hp%d: write locked\n", dkunit(bp));
5472826Swnj 			bp->b_flags |= B_ERROR;
5485858Swnj 		} else if ((er1&0xffff) == HPER1_FER && RP06 &&
5495726Sroot 		    hphdr[mi->mi_unit] == 0) {
5505726Sroot #ifndef NOBADSECT
5515726Sroot 			if (hpecc(mi, BSE))
5525726Sroot 				return(MBD_RESTARTED);
5535726Sroot 			else
5545726Sroot #endif
5555726Sroot 				goto hard;
5562826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
5573102Swnj 		    mbsr & MBSR_HARD ||
5585858Swnj 		    er1 & HPER1_HARD ||
5595726Sroot 		    hphdr[mi->mi_unit] ||
5605893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
5613706Sroot hard:
5622925Swnj 			harderr(bp, "hp");
5633271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
5643271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
5653706Sroot 			printf("er1=%b er2=%b",
5662826Swnj 			    hpaddr->hper1, HPER1_BITS,
5672826Swnj 			    hpaddr->hper2, HPER2_BITS);
5683706Sroot 			if (hpaddr->hpmr)
5693706Sroot 				printf(" mr=%o", hpaddr->hpmr&0xffff);
5703706Sroot 			if (hpaddr->hpmr2)
5713706Sroot 				printf(" mr2=%o", hpaddr->hpmr2&0xffff);
5723706Sroot 			printf("\n");
5732826Swnj 			bp->b_flags |= B_ERROR;
5743143Swnj 			hprecal[mi->mi_unit] = 0;
5755893Swnj 		} else if ((er2 & HPER2_BSE) && !ML11) {
5763726Sroot #ifndef NOBADSECT
5773706Sroot 			if (hpecc(mi, BSE))
5783706Sroot 				return(MBD_RESTARTED);
5793706Sroot 			else
5803706Sroot #endif
5813706Sroot 				goto hard;
5825893Swnj 		} else if (RM80 && er2&HPER2_SSE) {
5833988Sroot 			(void) hpecc(mi, SSE);
5842883Swnj 			return (MBD_RESTARTED);
5855858Swnj 		} else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) {
5863706Sroot 			if (hpecc(mi, ECC))
5872383Swnj 				return (MBD_RESTARTED);
5882826Swnj 			/* else done */
5892826Swnj 		} else
5902826Swnj 			retry = 1;
5912826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
5925726Sroot 		if (ML11) {
5935726Sroot 			if (mi->mi_tab.b_errcnt >= 16)
5945726Sroot 				goto hard;
5955726Sroot 		} else if ((mi->mi_tab.b_errcnt&07) == 4) {
5962826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
5973706Sroot 			hprecal[mi->mi_unit] = 1;
5983706Sroot 			return(MBD_RESTARTED);
59921Sbill 		}
6002826Swnj 		if (retry)
6012826Swnj 			return (MBD_RETRY);
6022826Swnj 	}
6033706Sroot #ifdef HPDEBUG
6043289Swnj 	else
6053289Swnj 		if (hpdebug && hprecal[mi->mi_unit]) {
6063289Swnj 			printf("recal %d ", hprecal[mi->mi_unit]);
6073289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
6083289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
6093289Swnj 			printf("er1=%b er2=%b\n",
6103289Swnj 			    hpaddr->hper1, HPER1_BITS,
6113289Swnj 			    hpaddr->hper2, HPER2_BITS);
6123289Swnj 		}
6133706Sroot #endif
6143093Swnj 	switch (hprecal[mi->mi_unit]) {
6153093Swnj 
6163093Swnj 	case 1:
6173093Swnj 		hpaddr->hpdc = bp->b_cylin;
6183093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
6193706Sroot 		hprecal[mi->mi_unit]++;
6203706Sroot 		return (MBD_RESTARTED);
6213093Swnj 	case 2:
6223093Swnj 		if (mi->mi_tab.b_errcnt < 16 ||
6233289Swnj 		    (bp->b_flags & B_READ) == 0)
6243093Swnj 			goto donerecal;
6253093Swnj 		hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
6263093Swnj 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
6273093Swnj 		hprecal[mi->mi_unit]++;
6283093Swnj 		return (MBD_RESTARTED);
6293093Swnj 	donerecal:
6303158Swnj 	case 3:
6312892Swnj 		hprecal[mi->mi_unit] = 0;
6322892Swnj 		return (MBD_RETRY);
6332892Swnj 	}
6345726Sroot 	hphdr[mi->mi_unit] = 0;
6352383Swnj 	bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
6363640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
6373093Swnj 		/*
6383093Swnj 		 * This is fast and occurs rarely; we don't
6393093Swnj 		 * bother with interrupts.
6403093Swnj 		 */
6412624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
6423093Swnj 		while (hpaddr->hpds & HPDS_PIP)
6432383Swnj 			;
6442383Swnj 		mbclrattn(mi);
64521Sbill 	}
6465726Sroot 	if (!ML11) {
6475726Sroot 		hpaddr->hpof = HPOF_FMT22;
6485726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
6495726Sroot 	}
6502383Swnj 	return (MBD_DONE);
65121Sbill }
65221Sbill 
6537738Sroot hpread(dev, uio)
6542624Swnj 	dev_t dev;
6557738Sroot 	struct uio *uio;
65621Sbill {
6572624Swnj 	register int unit = minor(dev) >> 3;
65821Sbill 
6592624Swnj 	if (unit >= NHP)
6608156Sroot 		return (ENXIO);
6618156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio));
66221Sbill }
66321Sbill 
6647831Sroot hpwrite(dev, uio)
6652624Swnj 	dev_t dev;
6667831Sroot 	struct uio *uio;
66721Sbill {
6682624Swnj 	register int unit = minor(dev) >> 3;
66921Sbill 
6702624Swnj 	if (unit >= NHP)
6718156Sroot 		return (ENXIO);
6728156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio));
67321Sbill }
67421Sbill 
6755726Sroot /*ARGSUSED*/
6767635Ssam hpioctl(dev, cmd, data, flag)
6775726Sroot 	dev_t dev;
6785726Sroot 	int cmd;
6797635Ssam 	caddr_t data;
6805726Sroot 	int flag;
6815726Sroot {
6825726Sroot 
6835726Sroot 	switch (cmd) {
6847635Ssam 
6855726Sroot 	case DKIOCHDR:	/* do header read/write */
6865726Sroot 		hphdr[minor(dev)>>3] = 1;
6878579Sroot 		return (0);
6885726Sroot 
6895726Sroot 	default:
6908579Sroot 		return (ENXIO);
6915726Sroot 	}
6925726Sroot }
6935726Sroot 
6943706Sroot hpecc(mi, flag)
6952978Swnj 	register struct mba_device *mi;
6963706Sroot 	int flag;
69721Sbill {
6982383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
6992624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
7002383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
7013706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
7023706Sroot 	int npf, o;
7032383Swnj 	int bn, cn, tn, sn;
704914Sbill 	int bcr;
70521Sbill 
706914Sbill 	bcr = mbp->mba_bcr & 0xffff;
707914Sbill 	if (bcr)
708914Sbill 		bcr |= 0xffff0000;		/* sxt */
7093726Sroot #ifndef NOBADSECT
7103706Sroot 	if (flag == CONT)
7113706Sroot 		npf = bp->b_error;
7123706Sroot 	else
7133706Sroot #endif
7143706Sroot 		npf = btop(bcr + bp->b_bcount);
715420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
716420Sbill 	bn = dkblock(bp);
717420Sbill 	cn = bp->b_cylin;
7183706Sroot 	sn = bn%(st->nspc) + npf;
7192383Swnj 	tn = sn/st->nsect;
7202383Swnj 	sn %= st->nsect;
7212383Swnj 	cn += tn/st->ntrak;
7222383Swnj 	tn %= st->ntrak;
7233706Sroot 	switch (flag) {
7243706Sroot 	case ECC:
7253706Sroot 		{
7263706Sroot 		register int i;
7273706Sroot 		caddr_t addr;
7283706Sroot 		struct pte mpte;
7293706Sroot 		int bit, byte, mask;
7303706Sroot 
7313706Sroot 		npf--;		/* because block in error is previous block */
7323706Sroot 		printf("hp%d%c: soft ecc sn%d\n", dkunit(bp),
7333706Sroot 		    'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
7343706Sroot 		mask = rp->hpec2&0xffff;
7353706Sroot 		i = (rp->hpec1&0xffff) - 1;		/* -1 makes 0 origin */
7363706Sroot 		bit = i&07;
7373706Sroot 		i = (i&~07)>>3;
7383706Sroot 		byte = i + o;
7393706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
7403706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
7413706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
7423706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
7433706Sroot 			byte++;
7443706Sroot 			i++;
7453706Sroot 			bit -= 8;
7463706Sroot 		}
7473706Sroot 		if (bcr == 0)
7483706Sroot 			return (0);
7493847Sroot 		npf++;
7503706Sroot 		break;
7513706Sroot 		}
7523706Sroot 
7533706Sroot 	case SSE:
7543706Sroot 		rp->hpof |= HPOF_SSEI;
7553706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
7563706Sroot 		break;
7573706Sroot 
7583726Sroot #ifndef NOBADSECT
7593706Sroot 	case BSE:
7603706Sroot #ifdef HPBDEBUG
7613706Sroot 		if (hpbdebug)
7623706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
7633706Sroot #endif
7643706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
7653706Sroot 			return(0);
7663706Sroot 		bp->b_flags |= B_BAD;
7673706Sroot 		bp->b_error = npf + 1;
7683706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
7693706Sroot 		cn = bn/st->nspc;
7703706Sroot 		sn = bn%st->nspc;
7713706Sroot 		tn = sn/st->nsect;
7723706Sroot 		sn %= st->nsect;
7733706Sroot 		mbp->mba_bcr = -512;
7743706Sroot #ifdef HPBDEBUG
7753706Sroot 		if (hpbdebug)
7763706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
7773706Sroot #endif
7783706Sroot 		break;
7793706Sroot 
7803706Sroot 	case CONT:
7813706Sroot #ifdef HPBDEBUG
7823706Sroot 		if (hpbdebug)
7833706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
7843706Sroot #endif
7853706Sroot 		npf = bp->b_error;
7863706Sroot 		bp->b_flags &= ~B_BAD;
7873706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
7883706Sroot 		if ((mbp->mba_bcr & 0xffff) == 0)
7893706Sroot 			return(0);
7903706Sroot 		break;
7913706Sroot #endif
7923706Sroot 	}
7933706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
7943350Swnj 	if (rp->hpof&HPOF_SSEI)
7952883Swnj 		sn++;
796420Sbill 	rp->hpdc = cn;
797420Sbill 	rp->hpda = (tn<<8) + sn;
798420Sbill 	mbp->mba_sr = -1;
7993706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
8003706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
8013706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
802420Sbill 	return (1);
80321Sbill }
8042362Swnj 
8052362Swnj #define	DBSIZE	20
8062362Swnj 
8072362Swnj hpdump(dev)
8082362Swnj 	dev_t dev;
8092362Swnj {
8102978Swnj 	register struct mba_device *mi;
8112383Swnj 	register struct mba_regs *mba;
8122624Swnj 	struct hpdevice *hpaddr;
8132362Swnj 	char *start;
8142383Swnj 	int num, unit;
8152383Swnj 	register struct hpst *st;
8162362Swnj 
8172362Swnj 	num = maxfree;
8182362Swnj 	start = 0;
8192362Swnj 	unit = minor(dev) >> 3;
8202827Swnj 	if (unit >= NHP)
8212827Swnj 		return (ENXIO);
8222383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
8232978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
8242827Swnj 	if (mi == 0 || mi->mi_alive == 0)
8252827Swnj 		return (ENXIO);
8262383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
8273102Swnj 	mba->mba_cr = MBCR_INIT;
8282624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
8293093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
8302624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
8312624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
8323093Swnj 		hpaddr->hpof = HPOF_FMT22;
8332362Swnj 	}
8342383Swnj 	st = &hpst[mi->mi_type];
8352827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
8362827Swnj 		return (EINVAL);
8372362Swnj 	while (num > 0) {
8382383Swnj 		register struct pte *hpte = mba->mba_map;
8392362Swnj 		register int i;
8402383Swnj 		int blk, cn, sn, tn;
8412362Swnj 		daddr_t bn;
8422362Swnj 
8432362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
8442362Swnj 		bn = dumplo + btop(start);
8452383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
8462383Swnj 		sn = bn%st->nspc;
8472383Swnj 		tn = sn/st->nsect;
8482383Swnj 		sn = sn%st->nsect;
8492362Swnj 		hpaddr->hpdc = cn;
8502362Swnj 		hpaddr->hpda = (tn << 8) + sn;
8512362Swnj 		for (i = 0; i < blk; i++)
8522362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
8532383Swnj 		mba->mba_sr = -1;
8542383Swnj 		mba->mba_bcr = -(blk*NBPG);
8552383Swnj 		mba->mba_var = 0;
8562624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
8573093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
8582362Swnj 			;
8593093Swnj 		if (hpaddr->hpds&HPDS_ERR)
8602827Swnj 			return (EIO);
8612362Swnj 		start += blk*NBPG;
8622362Swnj 		num -= blk;
8632362Swnj 	}
8642362Swnj 	return (0);
8652362Swnj }
8661565Sbill #endif
867