xref: /csrg-svn/sys/vax/mba/hp.c (revision 11629)
1*11629Ssam /*	hp.c	4.73	83/03/19	*/
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  */
219786Ssam #include "../machine/pte.h"
2221Sbill 
2321Sbill #include "../h/param.h"
2421Sbill #include "../h/systm.h"
25305Sbill #include "../h/dk.h"
2621Sbill #include "../h/buf.h"
2721Sbill #include "../h/conf.h"
2821Sbill #include "../h/dir.h"
2921Sbill #include "../h/user.h"
3021Sbill #include "../h/map.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;
4711212Ssam } rp06_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 */
5111212Ssam 	15884,	118,		/* D=cyl 118 thru 155 */
5211212Ssam 	55936,	156,		/* E=cyl 156 thru 289 */
5311212Ssam 	219384,	290,		/* F=cyl 290 thru 814 */
5411212Ssam 	291280,	118,		/* G=cyl 118 thru 814 */
5521Sbill 	0,	0,
5611212Ssam }, rp05_sizes[8] = {
5711212Ssam 	15884,	0,		/* A=cyl 0 thru 37 */
5811212Ssam 	33440,	38,		/* B=cyl 38 thru 117 */
5911212Ssam 	171798,	0,		/* C=cyl 0 thru 410 */
6011212Ssam 	15884,	118,		/* D=cyl 118 thru 155 */
6111212Ssam 	55936,	156,		/* E=cyl 156 thru 289 */
6211212Ssam 	50512,	290,		/* F=cyl 290 thru 410 */
6311212Ssam 	122408,	118,		/* G=cyl 118 thru 410 */
6421Sbill 	0,	0,
6511212Ssam }, rm03_sizes[8] = {
66886Sbill 	15884,	0,		/* A=cyl 0 thru 99 */
6711212Ssam 	33440,	100,		/* B=cyl 100 thru 308 */
68886Sbill 	131680,	0,		/* C=cyl 0 thru 822 */
6911212Ssam 	15884,	309,		/* D=cyl 309 thru 408 */
7011212Ssam 	55936,	409,		/* E=cyl 409 thru 758 */
7111212Ssam 	10144,	759,		/* F=cyl 759 thru 822 */
7211212Ssam 	82144,	309,		/* G=cyl 309 thru 822 */
7321Sbill 	0,	0,
7411212Ssam }, rm05_sizes[8] = {
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 */
803729Sroot 	86240,	681,		/* F=cyl 681 thru 822 */
813729Sroot 	158592,	562,		/* G=cyl 562 thru 822 */
82886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
832383Swnj }, rm80_sizes[8] = {
842383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
852383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
862383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
8711212Ssam 	15884,	115,		/* D=cyl 115 thru 151 */
8811212Ssam 	55936,	152,		/* E=cyl 152 thru 280 */
8911212Ssam 	120559,	281,		/* F=cyl 281 thru 558 */
9011212Ssam 	192603,	115,		/* G=cyl 115 thru 558 */
912383Swnj 	0,	0,
9211212Ssam }, rp07_sizes[8] = {
936927Ssam 	15884,	0,		/* A=cyl 0 thru 9 */
9411212Ssam 	66880,	10,		/* B=cyl 10 thru 51 */
9511212Ssam 	1008000, 0,		/* C=cyl 0 thru 629 */
9611212Ssam 	15884,	235,		/* D=cyl 235 thru 244 */
9711212Ssam 	307200,	245,		/* E=cyl 245 thru 436 */
9811212Ssam 	308650,	437,		/* F=cyl 437 thru 629 */
9911212Ssam 	631850,	235,		/* G=cyl 235 thru 629 */
10011212Ssam 	291346,	52,		/* H=cyl 52 thru 234 */
10111212Ssam }, cdc9775_sizes[8] = {
10211212Ssam 	15884,	0,		/* A=cyl 0 thru 12 */
10311212Ssam 	66880,	13,		/* B=cyl 13 thru 65 */
10411212Ssam 	1079040, 0,		/* C=cyl 0 thru 842 */
10511212Ssam 	15884,	294,		/* D=cyl 294 thru 306 */
10611212Ssam 	307200,	307,		/* E=cyl 307 thru 546 */
10711212Ssam 	378784,	547,		/* F=cyl 547 thru 842 */
10811212Ssam 	702624,	294,		/* G=cyl 294 thru 842 */
10911212Ssam 	291346,	66,		/* H=cyl 66 thru 293 */
11011212Ssam }, cdc9730_sizes[8] = {
1116927Ssam 	15884,	0,		/* A=cyl 0 thru 49 */
1126927Ssam 	33440,	50,		/* B=cyl 50 thru 154 */
1136927Ssam 	263360,	0,		/* C=cyl 0 thru 822 */
11411212Ssam 	15884,	155,		/* D=cyl 155 thru 204 */
11511212Ssam 	55936,	205,		/* E=cyl 205 thru 379 */
11611212Ssam 	141664,	380,		/* F=cyl 380 thru 822 */
11711212Ssam 	213664,	155,		/* G=cyl 155 thru 822 */
1186927Ssam 	0,	0,
11911212Ssam }, capricorn_sizes[8] = {
1206927Ssam 	15884,	0,		/* A=cyl 0 thru 31 */
1216927Ssam 	33440,	32,		/* B=cyl 32 thru 97 */
1226927Ssam 	524288,	0,		/* C=cyl 0 thru 1023 */
12311212Ssam 	15884,	668,		/* D=cyl 668 thru 699 */
12411212Ssam 	55936,	700,		/* E=cyl 700 thru 809 */
12511212Ssam 	109472,	810,		/* F=cyl 810 thru 1023 */
12611212Ssam 	182176,	668,		/* G=cyl 668 thru 1023 */
1276927Ssam 	291346,	98,		/* H=cyl 98 thru 667 */
12811212Ssam }, eagle_sizes[8] = {
12911212Ssam #ifdef MONET
13010734Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
13110734Ssam 	33440,	17,		/* B=cyl 17 thru 52 */
13210734Ssam 	808176,	0,		/* C=cyl 0 thru 841 */
13310734Ssam 	0, 0,
13410734Ssam 	0, 0,
13510734Ssam 	0, 0,
13610734Ssam 	465456, 357,		/* G=cyl 357 thru 841 */
13710734Ssam 	291346, 53,		/* H=cyl 52 thru 356 */
13811212Ssam #else
13911212Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
14011212Ssam 	66880,	17,		/* B=cyl 17 thru 86 */
141*11629Ssam 	808320,	0,		/* C=cyl 0 thru 841 */
14211212Ssam 	15884,	391,		/* D=cyl 391 thru 407 */
14311212Ssam 	307200,	408,		/* E=cyl 408 thru 727 */
144*11629Ssam 	109296,	728,		/* F=cyl 728 thru 841 */
145*11629Ssam 	432816,	391,		/* G=cyl 391 thru 841 */
14611212Ssam 	291346,	87,		/* H=cyl 87 thru 390 */
14711212Ssam #endif
14811281Ssam }, cdc9300_sizes[8] = {
14911281Ssam 	15884,	0,		/* A=cyl 0 thru 26 */
15011281Ssam 	33440,	27,		/* B=cyl 27 thru 81 */
15111281Ssam 	500384,	0,		/* C=cyl 0 thru 822 */
15211281Ssam 	15884,	562,		/* D=cyl 562 thru 588 */
15311281Ssam 	55936,	589,		/* E=cyl 589 thru 680 */
15411281Ssam 	86240,	681,		/* F=cyl 681 thru 822 */
15511281Ssam 	158592,	562,		/* G=cyl 562 thru 822 */
15611281Ssam 	291346,	82,		/* H=cyl 82 thru 561 */
15721Sbill };
1582383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
15921Sbill 
1602383Swnj #define	_hpSDIST	2
1612383Swnj #define	_hpRDIST	3
1622383Swnj 
1632383Swnj int	hpSDIST = _hpSDIST;
1642383Swnj int	hpRDIST = _hpRDIST;
1652383Swnj 
1666927Ssam /*
1676927Ssam  * Table for converting Massbus drive types into
1686927Ssam  * indices into the partition tables.  Slots are
1696927Ssam  * left for those drives devined from other means
1706927Ssam  * (e.g. SI, AMPEX, etc.).
1716927Ssam  */
1726927Ssam short	hptypes[] = {
1736927Ssam #define	HPDT_RM03	0
1746927Ssam 	MBDT_RM03,
1756927Ssam #define	HPDT_RM05	1
1766927Ssam 	MBDT_RM05,
1776927Ssam #define	HPDT_RP06	2
1786927Ssam 	MBDT_RP06,
1796927Ssam #define	HPDT_RM80	3
1806927Ssam 	MBDT_RM80,
1816927Ssam #define	HPDT_RP05	4
1826927Ssam 	MBDT_RP05,
1836927Ssam #define	HPDT_RP07	5
1846927Ssam 	MBDT_RP07,
1856927Ssam #define	HPDT_ML11A	6
1866927Ssam 	MBDT_ML11A,
1876927Ssam #define	HPDT_ML11B	7
1886927Ssam 	MBDT_ML11B,
1896927Ssam #define	HPDT_9775	8
1906927Ssam 	-1,
1916927Ssam #define	HPDT_9730	9
1926927Ssam 	-1,
1936927Ssam #define	HPDT_CAPRICORN	10
1946927Ssam 	-1,
1959175Ssam #define HPDT_EAGLE	11
1969175Ssam 	-1,
19711281Ssam #define	HPDT_9300	12
19811281Ssam 	-1,
19911281Ssam #define HPDT_RM02	13
2009175Ssam 	MBDT_RM02,		/* beware, actually capricorn or eagle */
2016927Ssam 	0
2026927Ssam };
2032978Swnj struct	mba_device *hpinfo[NHP];
2042978Swnj int	hpattach(),hpustart(),hpstart(),hpdtint();
2052383Swnj struct	mba_driver hpdriver =
2062978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
2072978Swnj 	  hptypes, "hp", 0, hpinfo };
2082383Swnj 
2092383Swnj struct hpst {
2102383Swnj 	short	nsect;
2112383Swnj 	short	ntrak;
2122383Swnj 	short	nspc;
2132383Swnj 	short	ncyl;
2142383Swnj 	struct	size *sizes;
2152383Swnj } hpst[] = {
21611212Ssam 	32,	5,	32*5,	823,	rm03_sizes,	/* RM03 */
21711212Ssam 	32,	19,	32*19,	823,	rm05_sizes,	/* RM05 */
21811212Ssam 	22,	19,	22*19,	815,	rp06_sizes,	/* RP06 */
2193706Sroot 	31,	14, 	31*14,	559,	rm80_sizes,	/* RM80 */
22011212Ssam 	22,	19,	22*19,	411,	rp05_sizes,	/* RP05 */
22111212Ssam 	50,	32,	50*32,	630,	rp07_sizes,	/* RP07 */
2225726Sroot 	1,	1,	1,	1,	0,		/* ML11A */
2235726Sroot 	1,	1,	1,	1,	0,		/* ML11B */
22411212Ssam 	32,	40,	32*40,	843,	cdc9775_sizes,	/* 9775 */
22511212Ssam 	32,	10,	32*10,	823,	cdc9730_sizes,	/* 9730 */
22611281Ssam 	32,	16,	32*16,	1024,	capricorn_sizes,/* Capricorn */
22711281Ssam 	48,	20,	48*20,	842,	eagle_sizes,	/* EAGLE */
22811281Ssam 	32,	19,	32*19,	815,	cdc9300_sizes,	/* 9300 */
2292383Swnj };
2302383Swnj 
2312624Swnj u_char	hp_offset[16] = {
2323093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
2333093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
2343093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
2353093Swnj     0, 0, 0, 0,
23621Sbill };
23721Sbill 
2382624Swnj struct	buf	rhpbuf[NHP];
2393706Sroot struct	buf	bhpbuf[NHP];
2403706Sroot struct	dkbad	hpbad[NHP];
24121Sbill 
24210857Ssam struct	hpsoftc {
24310857Ssam 	u_char	sc_hpinit;	/* drive initialized */
24410857Ssam 	u_char	sc_recal;	/* recalibrate state */
24510857Ssam 	u_char	sc_hdr;		/* next i/o includes header */
24610857Ssam 	u_char	sc_doseeks;	/* perform explicit seeks */
24710857Ssam 	daddr_t	sc_mlsize;	/* ML11 size */
24810857Ssam } hpsoftc[NHP];
24910857Ssam 
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 
25711202Ssam #define	MASKREG(reg)	((reg)&0xffff)
25811202Ssam 
25921Sbill #ifdef INTRLVE
26021Sbill daddr_t dkblock();
26121Sbill #endif
2622604Swnj 
2632978Swnj /*ARGSUSED*/
2642978Swnj hpattach(mi, slave)
26510734Ssam 	register struct mba_device *mi;
2662604Swnj {
26710734Ssam 
26810734Ssam 	mi->mi_type = hpmaptype(mi);
26910734Ssam 	if (!ML11 && mi->mi_dk >= 0) {
27010734Ssam 		struct hpst *st = &hpst[mi->mi_type];
27110734Ssam 
27210734Ssam 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
27310734Ssam 	}
27410734Ssam }
27510734Ssam 
27610734Ssam /*
27710734Ssam  * Map apparent MASSBUS drive type into manufacturer
27810734Ssam  * specific configuration.  For SI controllers this is done
27910734Ssam  * based on codes in the serial number register.  For
28010734Ssam  * EMULEX controllers, the track and sector attributes are
28110734Ssam  * used when the drive type is an RM02 (not supported by DEC).
28210734Ssam  */
28310734Ssam hpmaptype(mi)
28410734Ssam 	register struct mba_device *mi;
28510734Ssam {
2866927Ssam 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
28710734Ssam 	register int type = mi->mi_type;
2886927Ssam 
2896927Ssam 	/*
29011281Ssam 	 * Model-byte processing for SI controllers.
2916927Ssam 	 * NB:  Only deals with RM03 and RM05 emulations.
2926927Ssam 	 */
29310734Ssam 	if (type == HPDT_RM03 || type == HPDT_RM05) {
29410734Ssam 		int hpsn = hpaddr->hpsn;
2956927Ssam 
2966927Ssam 		if ((hpsn & SIMB_LU) != mi->mi_drive)
29710734Ssam 			return (type);
2986927Ssam 		switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
2996927Ssam 
3006927Ssam 		case SI9775D:
30111281Ssam 			printf("hp%d: 9775 (direct)\n", mi->mi_unit);
30210734Ssam 			type = HPDT_9775;
3036927Ssam 			break;
3046927Ssam 
3056927Ssam 		case SI9730D:
30611281Ssam 			printf("hp%d: 9730 (direct)\n", mi->mi_unit);
30710734Ssam 			type = HPDT_9730;
3086927Ssam 			break;
3096927Ssam 
3107035Swnj 		/*
31111281Ssam 		 * Beware, since the only SI controller we
31211281Ssam 		 * have has a 9300 instead of a 9766, we map the
31311281Ssam 		 * drive type into the 9300.  This means that
31411281Ssam 		 * on a 9766 you lose the last 8 cylinders (argh).
3157035Swnj 		 */
3166927Ssam 		case SI9766:
31711281Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
31811281Ssam 			type = HPDT_9300;
3196927Ssam 			break;
3206927Ssam 
3216927Ssam 		case SI9762:
3226927Ssam 			printf("hp%d: 9762\n", mi->mi_unit);
32310734Ssam 			type = HPDT_RM03;
3246927Ssam 			break;
32511281Ssam 
32611281Ssam 		case SICAPD:
32711281Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
32811281Ssam 			type = HPDT_CAPRICORN;
32911281Ssam 			break;
33011281Ssam 
33111281Ssam 		case SI9751D:
33211281Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
33311281Ssam 			type = HPDT_EAGLE;
33411281Ssam 			break;
3356927Ssam 		}
33610734Ssam 		return (type);
33710734Ssam 	}
3386927Ssam 
3396927Ssam 	/*
34010734Ssam 	 * EMULEX SC750 or SC780.  Poke the holding register.
3416927Ssam 	 */
34210734Ssam 	if (type == HPDT_RM02) {
34310734Ssam 		int ntracks, nsectors;
34410734Ssam 
34511315Ssam 		hpaddr->hpof = HPOF_FMT22;
34611315Ssam 		mbclrattn(mi);
3476927Ssam 		hpaddr->hpcs1 = HP_NOP;
3486927Ssam 		hpaddr->hphr = HPHR_MAXTRAK;
34911202Ssam 		ntracks = MASKREG(hpaddr->hphr) + 1;
35010055Ssam 		if (ntracks == 16) {
3516927Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
35210734Ssam 			type = HPDT_CAPRICORN;
35310734Ssam 			goto done;
35410734Ssam 		}
35510734Ssam 		hpaddr->hpcs1 = HP_NOP;
35610734Ssam 		hpaddr->hphr = HPHR_MAXSECT;
35711202Ssam 		nsectors = MASKREG(hpaddr->hphr) + 1;
35811315Ssam 		if (ntracks == 20 && nsectors == 48) {
35910734Ssam 			type = HPDT_EAGLE;
36011212Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
36111315Ssam 			goto done;
36210734Ssam 		}
36311315Ssam 		printf("hp%d: ntracks %d, nsectors %d: unknown device\n",
36411315Ssam 			ntracks, nsectors);
36510734Ssam done:
3666927Ssam 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
36711315Ssam 		mbclrattn(mi);		/* conservative */
36810734Ssam 		return (type);
36910734Ssam 	}
3706927Ssam 
37110734Ssam 	/*
37210734Ssam 	 * Map all ML11's to the same type.  Also calculate
37310734Ssam 	 * transfer rates based on device characteristics.
37410734Ssam 	 */
37510734Ssam 	if (type == HPDT_ML11A || type == HPDT_ML11B) {
37610857Ssam 		register struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
37710857Ssam 		register int trt;
3782604Swnj 
37910857Ssam 		sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
3805726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
38110857Ssam 			sc->sc_mlsize >>= 2;
3825726Sroot 		if (mi->mi_dk >= 0) {
3835726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
3845726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
3855726Sroot 		}
38610734Ssam 		type = HPDT_ML11A;
3876927Ssam 	}
38810734Ssam 	return (type);
3892604Swnj }
3902604Swnj 
3918579Sroot hpopen(dev)
3928579Sroot 	dev_t dev;
3938579Sroot {
3948579Sroot 	register int unit = minor(dev) >> 3;
3958579Sroot 	register struct mba_device *mi;
3968579Sroot 
3978579Sroot 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
3988579Sroot 		return (ENXIO);
3998579Sroot 	return (0);
4008579Sroot }
4018579Sroot 
40221Sbill hpstrategy(bp)
4032383Swnj 	register struct buf *bp;
40421Sbill {
4052978Swnj 	register struct mba_device *mi;
4062383Swnj 	register struct hpst *st;
4072383Swnj 	register int unit;
40821Sbill 	long sz, bn;
4092383Swnj 	int xunit = minor(bp->b_dev) & 07;
4105432Sroot 	int s;
41121Sbill 
41221Sbill 	sz = bp->b_bcount;
41321Sbill 	sz = (sz+511) >> 9;
41421Sbill 	unit = dkunit(bp);
4152383Swnj 	if (unit >= NHP)
4162383Swnj 		goto bad;
4172383Swnj 	mi = hpinfo[unit];
4182395Swnj 	if (mi == 0 || mi->mi_alive == 0)
4192383Swnj 		goto bad;
4202383Swnj 	st = &hpst[mi->mi_type];
4215726Sroot 	if (ML11) {
42210857Ssam 		struct hpsoftc *sc = &hpsoftc[unit];
42310857Ssam 
4245726Sroot 		if (bp->b_blkno < 0 ||
42510857Ssam 		    dkblock(bp)+sz > sc->sc_mlsize)
4265726Sroot 			goto bad;
4275726Sroot 		bp->b_cylin = 0;
4285726Sroot 	} else {
4295726Sroot 		if (bp->b_blkno < 0 ||
4305726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
4315726Sroot 			goto bad;
4325726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
4335726Sroot 	}
4345432Sroot 	s = spl5();
4352383Swnj 	disksort(&mi->mi_tab, bp);
4362383Swnj 	if (mi->mi_tab.b_active == 0)
4372383Swnj 		mbustart(mi);
4385432Sroot 	splx(s);
4392383Swnj 	return;
4402383Swnj 
4412383Swnj bad:
4422383Swnj 	bp->b_flags |= B_ERROR;
4432383Swnj 	iodone(bp);
4442383Swnj 	return;
44521Sbill }
44621Sbill 
4472383Swnj hpustart(mi)
4482978Swnj 	register struct mba_device *mi;
44921Sbill {
4502624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4512383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
45211315Ssam 	register struct hpst *st;
45310857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
45421Sbill 	daddr_t bn;
4553102Swnj 	int sn, dist;
45621Sbill 
45711315Ssam 	st = &hpst[mi->mi_type];
4583706Sroot 	hpaddr->hpcs1 = 0;
4592624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
4602383Swnj 		return (MBU_BUSY);
46110857Ssam 	if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) {
4623706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
4633706Sroot 
46410857Ssam 		sc->sc_hpinit = 1;
4652624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4663140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
4673140Swnj 			printf("DCLR attn\n");
4682624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
4695726Sroot 		if (!ML11)
4705726Sroot 			hpaddr->hpof = HPOF_FMT22;
4713140Swnj 		mbclrattn(mi);
4725726Sroot 		if (!ML11) {
4735726Sroot 			bbp->b_flags = B_READ|B_BUSY;
4745726Sroot 			bbp->b_dev = bp->b_dev;
4755726Sroot 			bbp->b_bcount = 512;
4765726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
4775726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
4785726Sroot 			bbp->b_cylin = st->ncyl - 1;
4795726Sroot 			mi->mi_tab.b_actf = bbp;
4805726Sroot 			bbp->av_forw = bp;
4815726Sroot 			bp = bbp;
4825726Sroot 		}
48321Sbill 	}
4842604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
4852383Swnj 		return (MBU_DODATA);
4865726Sroot 	if (ML11)
4875726Sroot 		return (MBU_DODATA);
4883093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
4892383Swnj 		return (MBU_DODATA);
4902395Swnj 	bn = dkblock(bp);
4912395Swnj 	sn = bn%st->nspc;
4922395Swnj 	sn = (sn+st->nsect-hpSDIST)%st->nsect;
49311202Ssam 	if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
49410908Ssam 		if (sc->sc_doseeks)
4952383Swnj 			return (MBU_DODATA);
49611202Ssam 		dist = (MASKREG(hpaddr->hpla) >> 6) - st->nsect + 1;
4972383Swnj 		if (dist < 0)
4982383Swnj 			dist += st->nsect;
4992383Swnj 		if (dist > st->nsect - hpRDIST)
5002383Swnj 			return (MBU_DODATA);
5012614Swnj 	} else
5022614Swnj 		hpaddr->hpdc = bp->b_cylin;
50310908Ssam 	if (sc->sc_doseeks)
5042624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
505305Sbill 	else {
506305Sbill 		hpaddr->hpda = sn;
5072624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
508305Sbill 	}
5092383Swnj 	return (MBU_STARTED);
51021Sbill }
51121Sbill 
5122383Swnj hpstart(mi)
5132978Swnj 	register struct mba_device *mi;
51421Sbill {
5152624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5162383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5172383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
51810857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
51921Sbill 	daddr_t bn;
5202383Swnj 	int sn, tn;
52121Sbill 
52221Sbill 	bn = dkblock(bp);
5235726Sroot 	if (ML11)
5245726Sroot 		hpaddr->hpda = bn;
5255726Sroot 	else {
5265726Sroot 		sn = bn%st->nspc;
5275726Sroot 		tn = sn/st->nsect;
5285726Sroot 		sn %= st->nsect;
5295726Sroot 		hpaddr->hpdc = bp->b_cylin;
5305726Sroot 		hpaddr->hpda = (tn << 8) + sn;
5315726Sroot 	}
53210857Ssam 	if (sc->sc_hdr) {
5335726Sroot 		if (bp->b_flags & B_READ)
5345726Sroot 			return (HP_RHDR|HP_GO);
5355726Sroot 		else
5365726Sroot 			return (HP_WHDR|HP_GO);
5375726Sroot 	}
5385726Sroot 	return (0);
53921Sbill }
54021Sbill 
5413102Swnj hpdtint(mi, mbsr)
5422978Swnj 	register struct mba_device *mi;
5433102Swnj 	int mbsr;
54421Sbill {
5452624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5462383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
54711315Ssam 	register struct hpst *st;
5485893Swnj 	register int er1, er2;
54910857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
5502826Swnj 	int retry = 0;
55121Sbill 
55211315Ssam 	st = &hpst[mi->mi_type];
55311315Ssam 	if (bp->b_flags&B_BAD && hpecc(mi, CONT))
55411315Ssam 		return (MBD_RESTARTED);
5553102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
5563706Sroot #ifdef HPDEBUG
5573289Swnj 		if (hpdebug) {
5583706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
5593706Sroot 
5603706Sroot 			printf("hperr: bp %x cyl %d blk %d as %o ",
5613706Sroot 				bp, bp->b_cylin, bp->b_blkno,
5623706Sroot 				hpaddr->hpas&0xff);
56311202Ssam 			printf("dc %x da %x\n",MASKREG(dc), MASKREG(da));
5643289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
5653289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
5663289Swnj 			printf("er1=%b er2=%b\n",
5673289Swnj 			    hpaddr->hper1, HPER1_BITS,
5683289Swnj 			    hpaddr->hper2, HPER2_BITS);
5693289Swnj 			DELAY(1000000);
5703289Swnj 		}
5713706Sroot #endif
5725858Swnj 		er1 = hpaddr->hper1;
5735893Swnj 		er2 = hpaddr->hper2;
5745893Swnj 		if (er1 & HPER1_HCRC) {
5755858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
5765893Swnj 			er2 &= ~HPER2_BSE;
5775893Swnj 		}
5785858Swnj 		if (er1&HPER1_WLE) {
5792925Swnj 			printf("hp%d: write locked\n", dkunit(bp));
5802826Swnj 			bp->b_flags |= B_ERROR;
58111202Ssam 		} else if (MASKREG(er1) == HPER1_FER && RP06 && !sc->sc_hdr) {
5825726Sroot 			if (hpecc(mi, BSE))
58311202Ssam 				return (MBD_RESTARTED);
58411202Ssam 			goto hard;
5852826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
5863102Swnj 		    mbsr & MBSR_HARD ||
5875858Swnj 		    er1 & HPER1_HARD ||
58810857Ssam 		    sc->sc_hdr ||
5895893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
59010886Shelge  			/*
59110886Shelge  			 * If HCRC the header is screwed up and the sector
59211202Ssam  			 * might be in the bad sector table, better check..
59311202Ssam 			 *
59410886Shelge 			 * Note: If the header is screwed up on a skip sector
59510886Shelge 			 * track, then the appropriate replacement sector
59611202Ssam 			 * cannot be found.
59710886Shelge  			 */
59811202Ssam  			if (er1&HPER1_HCRC && !ML11 && hpecc(mi, BSE))
59911202Ssam 				return (MBD_RESTARTED);
6003706Sroot hard:
60110622Shelge 			if (ML11)
60211202Ssam 				bp->b_blkno = MASKREG(hpaddr->hpda);
60310622Shelge 			else
60411202Ssam 				bp->b_blkno = MASKREG(hpaddr->hpdc) * st->nspc +
60511202Ssam 				   (MASKREG(hpaddr->hpda) >> 8) * st->nsect +
60611202Ssam 				   (hpaddr->hpda&0x1f);
6072925Swnj 			harderr(bp, "hp");
6083271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
6093271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
6103706Sroot 			printf("er1=%b er2=%b",
6112826Swnj 			    hpaddr->hper1, HPER1_BITS,
6122826Swnj 			    hpaddr->hper2, HPER2_BITS);
6133706Sroot 			if (hpaddr->hpmr)
61411202Ssam 				printf(" mr=%o", MASKREG(hpaddr->hpmr));
6153706Sroot 			if (hpaddr->hpmr2)
61611202Ssam 				printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
6173706Sroot 			printf("\n");
6182826Swnj 			bp->b_flags |= B_ERROR;
61910622Shelge 			retry = 0;
62010857Ssam 			sc->sc_recal = 0;
6215893Swnj 		} else if ((er2 & HPER2_BSE) && !ML11) {
6223706Sroot 			if (hpecc(mi, BSE))
62311202Ssam 				return (MBD_RESTARTED);
62411315Ssam 			goto hard;
6255893Swnj 		} else if (RM80 && er2&HPER2_SSE) {
6263988Sroot 			(void) hpecc(mi, SSE);
6272883Swnj 			return (MBD_RESTARTED);
6285858Swnj 		} else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) {
6293706Sroot 			if (hpecc(mi, ECC))
6302383Swnj 				return (MBD_RESTARTED);
6312826Swnj 			/* else done */
6322826Swnj 		} else
6332826Swnj 			retry = 1;
6342826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
6355726Sroot 		if (ML11) {
6365726Sroot 			if (mi->mi_tab.b_errcnt >= 16)
6375726Sroot 				goto hard;
6385726Sroot 		} else if ((mi->mi_tab.b_errcnt&07) == 4) {
6392826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
64010857Ssam 			sc->sc_recal = 1;
64111202Ssam 			return (MBD_RESTARTED);
64221Sbill 		}
6432826Swnj 		if (retry)
6442826Swnj 			return (MBD_RETRY);
6452826Swnj 	}
6463706Sroot #ifdef HPDEBUG
6473289Swnj 	else
64810857Ssam 		if (hpdebug && sc->sc_recal) {
64910857Ssam 			printf("recal %d ", sc->sc_recal);
6503289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
6513289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
6523289Swnj 			printf("er1=%b er2=%b\n",
6533289Swnj 			    hpaddr->hper1, HPER1_BITS,
6543289Swnj 			    hpaddr->hper2, HPER2_BITS);
6553289Swnj 		}
6563706Sroot #endif
65710857Ssam 	switch (sc->sc_recal) {
6583093Swnj 
6593093Swnj 	case 1:
6603093Swnj 		hpaddr->hpdc = bp->b_cylin;
6613093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
66210857Ssam 		sc->sc_recal++;
6633706Sroot 		return (MBD_RESTARTED);
6643093Swnj 	case 2:
6653093Swnj 		if (mi->mi_tab.b_errcnt < 16 ||
6663289Swnj 		    (bp->b_flags & B_READ) == 0)
6673093Swnj 			goto donerecal;
6683093Swnj 		hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
6693093Swnj 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
67010857Ssam 		sc->sc_recal++;
6713093Swnj 		return (MBD_RESTARTED);
6723093Swnj 	donerecal:
6733158Swnj 	case 3:
67410857Ssam 		sc->sc_recal = 0;
6752892Swnj 		return (MBD_RETRY);
6762892Swnj 	}
67710857Ssam 	sc->sc_hdr = 0;
67811202Ssam 	bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr);
6793640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
6803093Swnj 		/*
6813093Swnj 		 * This is fast and occurs rarely; we don't
6823093Swnj 		 * bother with interrupts.
6833093Swnj 		 */
6842624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
6853093Swnj 		while (hpaddr->hpds & HPDS_PIP)
6862383Swnj 			;
6872383Swnj 		mbclrattn(mi);
68821Sbill 	}
6895726Sroot 	if (!ML11) {
6905726Sroot 		hpaddr->hpof = HPOF_FMT22;
6915726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
6925726Sroot 	}
6932383Swnj 	return (MBD_DONE);
69421Sbill }
69521Sbill 
6967738Sroot hpread(dev, uio)
6972624Swnj 	dev_t dev;
6987738Sroot 	struct uio *uio;
69921Sbill {
7002624Swnj 	register int unit = minor(dev) >> 3;
70121Sbill 
7022624Swnj 	if (unit >= NHP)
7038156Sroot 		return (ENXIO);
7048156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio));
70521Sbill }
70621Sbill 
7077831Sroot hpwrite(dev, uio)
7082624Swnj 	dev_t dev;
7097831Sroot 	struct uio *uio;
71021Sbill {
7112624Swnj 	register int unit = minor(dev) >> 3;
71221Sbill 
7132624Swnj 	if (unit >= NHP)
7148156Sroot 		return (ENXIO);
7158156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio));
71621Sbill }
71721Sbill 
7185726Sroot /*ARGSUSED*/
7197635Ssam hpioctl(dev, cmd, data, flag)
7205726Sroot 	dev_t dev;
7215726Sroot 	int cmd;
7227635Ssam 	caddr_t data;
7235726Sroot 	int flag;
7245726Sroot {
7255726Sroot 
7265726Sroot 	switch (cmd) {
7277635Ssam 
7285726Sroot 	case DKIOCHDR:	/* do header read/write */
72910857Ssam 		hpsoftc[minor(dev) >> 3].sc_hdr = 1;
7308579Sroot 		return (0);
7315726Sroot 
7325726Sroot 	default:
7338579Sroot 		return (ENXIO);
7345726Sroot 	}
7355726Sroot }
7365726Sroot 
7373706Sroot hpecc(mi, flag)
7382978Swnj 	register struct mba_device *mi;
7393706Sroot 	int flag;
74021Sbill {
7412383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
7422624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
7432383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
7443706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
7453706Sroot 	int npf, o;
7462383Swnj 	int bn, cn, tn, sn;
747914Sbill 	int bcr;
74821Sbill 
74911202Ssam 	bcr = MASKREG(mbp->mba_bcr);
750914Sbill 	if (bcr)
751914Sbill 		bcr |= 0xffff0000;		/* sxt */
7523706Sroot 	if (flag == CONT)
7533706Sroot 		npf = bp->b_error;
7543706Sroot 	else
7553706Sroot 		npf = btop(bcr + bp->b_bcount);
756420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
757420Sbill 	bn = dkblock(bp);
758420Sbill 	cn = bp->b_cylin;
7593706Sroot 	sn = bn%(st->nspc) + npf;
7602383Swnj 	tn = sn/st->nsect;
7612383Swnj 	sn %= st->nsect;
7622383Swnj 	cn += tn/st->ntrak;
7632383Swnj 	tn %= st->ntrak;
7643706Sroot 	switch (flag) {
76510856Ssam 	case ECC: {
7663706Sroot 		register int i;
7673706Sroot 		caddr_t addr;
7683706Sroot 		struct pte mpte;
7693706Sroot 		int bit, byte, mask;
7703706Sroot 
7713706Sroot 		npf--;		/* because block in error is previous block */
7723706Sroot 		printf("hp%d%c: soft ecc sn%d\n", dkunit(bp),
7733706Sroot 		    'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
77411202Ssam 		mask = MASKREG(rp->hpec2);
77511202Ssam 		i = MASKREG(rp->hpec1) - 1;		/* -1 makes 0 origin */
7763706Sroot 		bit = i&07;
7773706Sroot 		i = (i&~07)>>3;
7783706Sroot 		byte = i + o;
7793706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
7803706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
7813706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
7823706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
7833706Sroot 			byte++;
7843706Sroot 			i++;
7853706Sroot 			bit -= 8;
7863706Sroot 		}
7873706Sroot 		if (bcr == 0)
7883706Sroot 			return (0);
7893847Sroot 		npf++;
7903706Sroot 		break;
7913706Sroot 		}
7923706Sroot 
7933706Sroot 	case SSE:
7943706Sroot 		rp->hpof |= HPOF_SSEI;
7953706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
7963706Sroot 		break;
7973706Sroot 
7983706Sroot 	case BSE:
7993706Sroot #ifdef HPBDEBUG
8003706Sroot 		if (hpbdebug)
8013706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
8023706Sroot #endif
80311202Ssam  		if (rp->hpof&HPOF_SSEI)
80411202Ssam  			sn++;
8053706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
80611202Ssam 			return (0);
8073706Sroot 		bp->b_flags |= B_BAD;
8083706Sroot 		bp->b_error = npf + 1;
8093706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
8103706Sroot 		cn = bn/st->nspc;
8113706Sroot 		sn = bn%st->nspc;
8123706Sroot 		tn = sn/st->nsect;
8133706Sroot 		sn %= st->nsect;
8143706Sroot 		mbp->mba_bcr = -512;
81510886Shelge  		rp->hpof &= ~HPOF_SSEI;
8163706Sroot #ifdef HPBDEBUG
8173706Sroot 		if (hpbdebug)
8183706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
8193706Sroot #endif
8203706Sroot 		break;
8213706Sroot 
8223706Sroot 	case CONT:
8233706Sroot #ifdef HPBDEBUG
8243706Sroot 		if (hpbdebug)
8253706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
8263706Sroot #endif
8273706Sroot 		npf = bp->b_error;
8283706Sroot 		bp->b_flags &= ~B_BAD;
8293706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
83011202Ssam 		if (MASKREG(mbp->mba_bcr) == 0)
83111202Ssam 			return (0);
8323706Sroot 		break;
8333706Sroot 	}
8343706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
8353350Swnj 	if (rp->hpof&HPOF_SSEI)
8362883Swnj 		sn++;
837420Sbill 	rp->hpdc = cn;
838420Sbill 	rp->hpda = (tn<<8) + sn;
839420Sbill 	mbp->mba_sr = -1;
8403706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
8413706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
8423706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
843420Sbill 	return (1);
84421Sbill }
8452362Swnj 
8462362Swnj #define	DBSIZE	20
8472362Swnj 
8482362Swnj hpdump(dev)
8492362Swnj 	dev_t dev;
8502362Swnj {
8512978Swnj 	register struct mba_device *mi;
8522383Swnj 	register struct mba_regs *mba;
8532624Swnj 	struct hpdevice *hpaddr;
8542362Swnj 	char *start;
8552383Swnj 	int num, unit;
8562383Swnj 	register struct hpst *st;
8572362Swnj 
8582362Swnj 	num = maxfree;
8592362Swnj 	start = 0;
8602362Swnj 	unit = minor(dev) >> 3;
8612827Swnj 	if (unit >= NHP)
8622827Swnj 		return (ENXIO);
8632383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
8642978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
8652827Swnj 	if (mi == 0 || mi->mi_alive == 0)
8662827Swnj 		return (ENXIO);
8672383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
8683102Swnj 	mba->mba_cr = MBCR_INIT;
8692624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
8703093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
8712624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
8722624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
8733093Swnj 		hpaddr->hpof = HPOF_FMT22;
8742362Swnj 	}
8752383Swnj 	st = &hpst[mi->mi_type];
8762827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
8772827Swnj 		return (EINVAL);
8782362Swnj 	while (num > 0) {
8792383Swnj 		register struct pte *hpte = mba->mba_map;
8802362Swnj 		register int i;
8812383Swnj 		int blk, cn, sn, tn;
8822362Swnj 		daddr_t bn;
8832362Swnj 
8842362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
8852362Swnj 		bn = dumplo + btop(start);
8862383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
8872383Swnj 		sn = bn%st->nspc;
8882383Swnj 		tn = sn/st->nsect;
8892383Swnj 		sn = sn%st->nsect;
8902362Swnj 		hpaddr->hpdc = cn;
8912362Swnj 		hpaddr->hpda = (tn << 8) + sn;
8922362Swnj 		for (i = 0; i < blk; i++)
8932362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
8942383Swnj 		mba->mba_sr = -1;
8952383Swnj 		mba->mba_bcr = -(blk*NBPG);
8962383Swnj 		mba->mba_var = 0;
8972624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
8983093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
8992362Swnj 			;
9003093Swnj 		if (hpaddr->hpds&HPDS_ERR)
9012827Swnj 			return (EIO);
9022362Swnj 		start += blk*NBPG;
9032362Swnj 		num -= blk;
9042362Swnj 	}
9052362Swnj 	return (0);
9062362Swnj }
9071565Sbill #endif
908