xref: /csrg-svn/sys/vax/mba/hp.c (revision 11315)
1*11315Ssam /*	hp.c	4.71	83/02/27	*/
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 #ifdef ARPA
733729Sroot 	81984,	310,		/* G=cyl 310 thru 822 */
7411212Ssam #else
7511212Ssam 	82144,	309,		/* G=cyl 309 thru 822 */
7611212Ssam #endif
7721Sbill 	0,	0,
7811212Ssam }, rm05_sizes[8] = {
79886Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
80886Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
813271Swnj 	500384,	0,		/* C=cyl 0 thru 822 */
82886Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
83886Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
843729Sroot 	86240,	681,		/* F=cyl 681 thru 822 */
853729Sroot 	158592,	562,		/* G=cyl 562 thru 822 */
86886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
872383Swnj }, rm80_sizes[8] = {
882383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
892383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
902383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
9111212Ssam 	15884,	115,		/* D=cyl 115 thru 151 */
9211212Ssam 	55936,	152,		/* E=cyl 152 thru 280 */
9311212Ssam 	120559,	281,		/* F=cyl 281 thru 558 */
9411212Ssam 	192603,	115,		/* G=cyl 115 thru 558 */
952383Swnj 	0,	0,
9611212Ssam }, rp07_sizes[8] = {
976927Ssam 	15884,	0,		/* A=cyl 0 thru 9 */
9811212Ssam 	66880,	10,		/* B=cyl 10 thru 51 */
9911212Ssam 	1008000, 0,		/* C=cyl 0 thru 629 */
10011212Ssam 	15884,	235,		/* D=cyl 235 thru 244 */
10111212Ssam 	307200,	245,		/* E=cyl 245 thru 436 */
10211212Ssam 	308650,	437,		/* F=cyl 437 thru 629 */
10311212Ssam 	631850,	235,		/* G=cyl 235 thru 629 */
10411212Ssam 	291346,	52,		/* H=cyl 52 thru 234 */
10511212Ssam }, cdc9775_sizes[8] = {
10611212Ssam 	15884,	0,		/* A=cyl 0 thru 12 */
10711212Ssam 	66880,	13,		/* B=cyl 13 thru 65 */
10811212Ssam 	1079040, 0,		/* C=cyl 0 thru 842 */
10911212Ssam 	15884,	294,		/* D=cyl 294 thru 306 */
11011212Ssam 	307200,	307,		/* E=cyl 307 thru 546 */
11111212Ssam 	378784,	547,		/* F=cyl 547 thru 842 */
11211212Ssam 	702624,	294,		/* G=cyl 294 thru 842 */
11311212Ssam 	291346,	66,		/* H=cyl 66 thru 293 */
11411212Ssam }, cdc9730_sizes[8] = {
1156927Ssam 	15884,	0,		/* A=cyl 0 thru 49 */
1166927Ssam 	33440,	50,		/* B=cyl 50 thru 154 */
1176927Ssam 	263360,	0,		/* C=cyl 0 thru 822 */
11811212Ssam 	15884,	155,		/* D=cyl 155 thru 204 */
11911212Ssam 	55936,	205,		/* E=cyl 205 thru 379 */
12011212Ssam 	141664,	380,		/* F=cyl 380 thru 822 */
12111212Ssam 	213664,	155,		/* G=cyl 155 thru 822 */
1226927Ssam 	0,	0,
12311212Ssam }, capricorn_sizes[8] = {
1246927Ssam 	15884,	0,		/* A=cyl 0 thru 31 */
1256927Ssam 	33440,	32,		/* B=cyl 32 thru 97 */
1266927Ssam 	524288,	0,		/* C=cyl 0 thru 1023 */
12711212Ssam 	15884,	668,		/* D=cyl 668 thru 699 */
12811212Ssam 	55936,	700,		/* E=cyl 700 thru 809 */
12911212Ssam 	109472,	810,		/* F=cyl 810 thru 1023 */
13011212Ssam 	182176,	668,		/* G=cyl 668 thru 1023 */
1316927Ssam 	291346,	98,		/* H=cyl 98 thru 667 */
13211212Ssam }, eagle_sizes[8] = {
13311212Ssam #ifdef MONET
13410734Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
13510734Ssam 	33440,	17,		/* B=cyl 17 thru 52 */
13610734Ssam 	808176,	0,		/* C=cyl 0 thru 841 */
13710734Ssam 	0, 0,
13810734Ssam 	0, 0,
13910734Ssam 	0, 0,
14010734Ssam 	465456, 357,		/* G=cyl 357 thru 841 */
14110734Ssam 	291346, 53,		/* H=cyl 52 thru 356 */
14211212Ssam #else
14311212Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
14411212Ssam 	66880,	17,		/* B=cyl 17 thru 86 */
14511212Ssam 	809280,	0,		/* C=cyl 0 thru 842 */
14611212Ssam 	15884,	391,		/* D=cyl 391 thru 407 */
14711212Ssam 	307200,	408,		/* E=cyl 408 thru 727 */
14811212Ssam 	110256,	728,		/* F=cyl 728 thru 842 */
14911212Ssam 	433776,	391,		/* G=cyl 391 thru 842 */
15011212Ssam 	291346,	87,		/* H=cyl 87 thru 390 */
15111212Ssam #endif
15211281Ssam }, cdc9300_sizes[8] = {
15311281Ssam 	15884,	0,		/* A=cyl 0 thru 26 */
15411281Ssam 	33440,	27,		/* B=cyl 27 thru 81 */
15511281Ssam 	500384,	0,		/* C=cyl 0 thru 822 */
15611281Ssam 	15884,	562,		/* D=cyl 562 thru 588 */
15711281Ssam 	55936,	589,		/* E=cyl 589 thru 680 */
15811281Ssam 	86240,	681,		/* F=cyl 681 thru 822 */
15911281Ssam 	158592,	562,		/* G=cyl 562 thru 822 */
16011281Ssam 	291346,	82,		/* H=cyl 82 thru 561 */
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,
1999175Ssam #define HPDT_EAGLE	11
2009175Ssam 	-1,
20111281Ssam #define	HPDT_9300	12
20211281Ssam 	-1,
20311281Ssam #define HPDT_RM02	13
2049175Ssam 	MBDT_RM02,		/* beware, actually capricorn or eagle */
2056927Ssam 	0
2066927Ssam };
2072978Swnj struct	mba_device *hpinfo[NHP];
2082978Swnj int	hpattach(),hpustart(),hpstart(),hpdtint();
2092383Swnj struct	mba_driver hpdriver =
2102978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
2112978Swnj 	  hptypes, "hp", 0, hpinfo };
2122383Swnj 
2132383Swnj struct hpst {
2142383Swnj 	short	nsect;
2152383Swnj 	short	ntrak;
2162383Swnj 	short	nspc;
2172383Swnj 	short	ncyl;
2182383Swnj 	struct	size *sizes;
2192383Swnj } hpst[] = {
22011212Ssam 	32,	5,	32*5,	823,	rm03_sizes,	/* RM03 */
22111212Ssam 	32,	19,	32*19,	823,	rm05_sizes,	/* RM05 */
22211212Ssam 	22,	19,	22*19,	815,	rp06_sizes,	/* RP06 */
2233706Sroot 	31,	14, 	31*14,	559,	rm80_sizes,	/* RM80 */
22411212Ssam 	22,	19,	22*19,	411,	rp05_sizes,	/* RP05 */
22511212Ssam 	50,	32,	50*32,	630,	rp07_sizes,	/* RP07 */
2265726Sroot 	1,	1,	1,	1,	0,		/* ML11A */
2275726Sroot 	1,	1,	1,	1,	0,		/* ML11B */
22811212Ssam 	32,	40,	32*40,	843,	cdc9775_sizes,	/* 9775 */
22911212Ssam 	32,	10,	32*10,	823,	cdc9730_sizes,	/* 9730 */
23011281Ssam 	32,	16,	32*16,	1024,	capricorn_sizes,/* Capricorn */
23111281Ssam 	48,	20,	48*20,	842,	eagle_sizes,	/* EAGLE */
23211281Ssam 	32,	19,	32*19,	815,	cdc9300_sizes,	/* 9300 */
2332383Swnj };
2342383Swnj 
2352624Swnj u_char	hp_offset[16] = {
2363093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
2373093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
2383093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
2393093Swnj     0, 0, 0, 0,
24021Sbill };
24121Sbill 
2422624Swnj struct	buf	rhpbuf[NHP];
2433706Sroot struct	buf	bhpbuf[NHP];
2443706Sroot struct	dkbad	hpbad[NHP];
24521Sbill 
24610857Ssam struct	hpsoftc {
24710857Ssam 	u_char	sc_hpinit;	/* drive initialized */
24810857Ssam 	u_char	sc_recal;	/* recalibrate state */
24910857Ssam 	u_char	sc_hdr;		/* next i/o includes header */
25010857Ssam 	u_char	sc_doseeks;	/* perform explicit seeks */
25110857Ssam 	daddr_t	sc_mlsize;	/* ML11 size */
25210857Ssam } hpsoftc[NHP];
25310857Ssam 
25421Sbill #define	b_cylin b_resid
25521Sbill 
2565726Sroot /* #define ML11 0  to remove ML11 support */
2575726Sroot #define	ML11	(hptypes[mi->mi_type] == MBDT_ML11A)
2585726Sroot #define	RP06	(hptypes[mi->mi_type] <= MBDT_RP06)
2595726Sroot #define	RM80	(hptypes[mi->mi_type] == MBDT_RM80)
2605726Sroot 
26111202Ssam #define	MASKREG(reg)	((reg)&0xffff)
26211202Ssam 
26321Sbill #ifdef INTRLVE
26421Sbill daddr_t dkblock();
26521Sbill #endif
2662604Swnj 
2672978Swnj /*ARGSUSED*/
2682978Swnj hpattach(mi, slave)
26910734Ssam 	register struct mba_device *mi;
2702604Swnj {
27110734Ssam 
27210734Ssam 	mi->mi_type = hpmaptype(mi);
27310734Ssam 	if (!ML11 && mi->mi_dk >= 0) {
27410734Ssam 		struct hpst *st = &hpst[mi->mi_type];
27510734Ssam 
27610734Ssam 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
27710734Ssam 	}
27810734Ssam }
27910734Ssam 
28010734Ssam /*
28110734Ssam  * Map apparent MASSBUS drive type into manufacturer
28210734Ssam  * specific configuration.  For SI controllers this is done
28310734Ssam  * based on codes in the serial number register.  For
28410734Ssam  * EMULEX controllers, the track and sector attributes are
28510734Ssam  * used when the drive type is an RM02 (not supported by DEC).
28610734Ssam  */
28710734Ssam hpmaptype(mi)
28810734Ssam 	register struct mba_device *mi;
28910734Ssam {
2906927Ssam 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
29110734Ssam 	register int type = mi->mi_type;
2926927Ssam 
2936927Ssam 	/*
29411281Ssam 	 * Model-byte processing for SI controllers.
2956927Ssam 	 * NB:  Only deals with RM03 and RM05 emulations.
2966927Ssam 	 */
29710734Ssam 	if (type == HPDT_RM03 || type == HPDT_RM05) {
29810734Ssam 		int hpsn = hpaddr->hpsn;
2996927Ssam 
3006927Ssam 		if ((hpsn & SIMB_LU) != mi->mi_drive)
30110734Ssam 			return (type);
3026927Ssam 		switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
3036927Ssam 
3046927Ssam 		case SI9775D:
30511281Ssam 			printf("hp%d: 9775 (direct)\n", mi->mi_unit);
30610734Ssam 			type = HPDT_9775;
3076927Ssam 			break;
3086927Ssam 
3096927Ssam 		case SI9730D:
31011281Ssam 			printf("hp%d: 9730 (direct)\n", mi->mi_unit);
31110734Ssam 			type = HPDT_9730;
3126927Ssam 			break;
3136927Ssam 
3147035Swnj 		/*
31511281Ssam 		 * Beware, since the only SI controller we
31611281Ssam 		 * have has a 9300 instead of a 9766, we map the
31711281Ssam 		 * drive type into the 9300.  This means that
31811281Ssam 		 * on a 9766 you lose the last 8 cylinders (argh).
3197035Swnj 		 */
3206927Ssam 		case SI9766:
32111281Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
32211281Ssam 			type = HPDT_9300;
3236927Ssam 			break;
3246927Ssam 
3256927Ssam 		case SI9762:
3266927Ssam 			printf("hp%d: 9762\n", mi->mi_unit);
32710734Ssam 			type = HPDT_RM03;
3286927Ssam 			break;
32911281Ssam 
33011281Ssam 		case SICAPD:
33111281Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
33211281Ssam 			type = HPDT_CAPRICORN;
33311281Ssam 			break;
33411281Ssam 
33511281Ssam 		case SI9751D:
33611281Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
33711281Ssam 			type = HPDT_EAGLE;
33811281Ssam 			break;
3396927Ssam 		}
34010734Ssam 		return (type);
34110734Ssam 	}
3426927Ssam 
3436927Ssam 	/*
34410734Ssam 	 * EMULEX SC750 or SC780.  Poke the holding register.
3456927Ssam 	 */
34610734Ssam 	if (type == HPDT_RM02) {
34710734Ssam 		int ntracks, nsectors;
34810734Ssam 
349*11315Ssam 		hpaddr->hpof = HPOF_FMT22;
350*11315Ssam 		mbclrattn(mi);
3516927Ssam 		hpaddr->hpcs1 = HP_NOP;
3526927Ssam 		hpaddr->hphr = HPHR_MAXTRAK;
35311202Ssam 		ntracks = MASKREG(hpaddr->hphr) + 1;
35410055Ssam 		if (ntracks == 16) {
3556927Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
35610734Ssam 			type = HPDT_CAPRICORN;
35710734Ssam 			goto done;
35810734Ssam 		}
35910734Ssam 		hpaddr->hpcs1 = HP_NOP;
36010734Ssam 		hpaddr->hphr = HPHR_MAXSECT;
36111202Ssam 		nsectors = MASKREG(hpaddr->hphr) + 1;
362*11315Ssam 		if (ntracks == 20 && nsectors == 48) {
36310734Ssam 			type = HPDT_EAGLE;
36411212Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
365*11315Ssam 			goto done;
36610734Ssam 		}
367*11315Ssam 		printf("hp%d: ntracks %d, nsectors %d: unknown device\n",
368*11315Ssam 			ntracks, nsectors);
36910734Ssam done:
3706927Ssam 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
371*11315Ssam 		mbclrattn(mi);		/* conservative */
37210734Ssam 		return (type);
37310734Ssam 	}
3746927Ssam 
37510734Ssam 	/*
37610734Ssam 	 * Map all ML11's to the same type.  Also calculate
37710734Ssam 	 * transfer rates based on device characteristics.
37810734Ssam 	 */
37910734Ssam 	if (type == HPDT_ML11A || type == HPDT_ML11B) {
38010857Ssam 		register struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
38110857Ssam 		register int trt;
3822604Swnj 
38310857Ssam 		sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
3845726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
38510857Ssam 			sc->sc_mlsize >>= 2;
3865726Sroot 		if (mi->mi_dk >= 0) {
3875726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
3885726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
3895726Sroot 		}
39010734Ssam 		type = HPDT_ML11A;
3916927Ssam 	}
39210734Ssam 	return (type);
3932604Swnj }
3942604Swnj 
3958579Sroot hpopen(dev)
3968579Sroot 	dev_t dev;
3978579Sroot {
3988579Sroot 	register int unit = minor(dev) >> 3;
3998579Sroot 	register struct mba_device *mi;
4008579Sroot 
4018579Sroot 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
4028579Sroot 		return (ENXIO);
4038579Sroot 	return (0);
4048579Sroot }
4058579Sroot 
40621Sbill hpstrategy(bp)
4072383Swnj 	register struct buf *bp;
40821Sbill {
4092978Swnj 	register struct mba_device *mi;
4102383Swnj 	register struct hpst *st;
4112383Swnj 	register int unit;
41221Sbill 	long sz, bn;
4132383Swnj 	int xunit = minor(bp->b_dev) & 07;
4145432Sroot 	int s;
41521Sbill 
41621Sbill 	sz = bp->b_bcount;
41721Sbill 	sz = (sz+511) >> 9;
41821Sbill 	unit = dkunit(bp);
4192383Swnj 	if (unit >= NHP)
4202383Swnj 		goto bad;
4212383Swnj 	mi = hpinfo[unit];
4222395Swnj 	if (mi == 0 || mi->mi_alive == 0)
4232383Swnj 		goto bad;
4242383Swnj 	st = &hpst[mi->mi_type];
4255726Sroot 	if (ML11) {
42610857Ssam 		struct hpsoftc *sc = &hpsoftc[unit];
42710857Ssam 
4285726Sroot 		if (bp->b_blkno < 0 ||
42910857Ssam 		    dkblock(bp)+sz > sc->sc_mlsize)
4305726Sroot 			goto bad;
4315726Sroot 		bp->b_cylin = 0;
4325726Sroot 	} else {
4335726Sroot 		if (bp->b_blkno < 0 ||
4345726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
4355726Sroot 			goto bad;
4365726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
4375726Sroot 	}
4385432Sroot 	s = spl5();
4392383Swnj 	disksort(&mi->mi_tab, bp);
4402383Swnj 	if (mi->mi_tab.b_active == 0)
4412383Swnj 		mbustart(mi);
4425432Sroot 	splx(s);
4432383Swnj 	return;
4442383Swnj 
4452383Swnj bad:
4462383Swnj 	bp->b_flags |= B_ERROR;
4472383Swnj 	iodone(bp);
4482383Swnj 	return;
44921Sbill }
45021Sbill 
4512383Swnj hpustart(mi)
4522978Swnj 	register struct mba_device *mi;
45321Sbill {
4542624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4552383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
456*11315Ssam 	register struct hpst *st;
45710857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
45821Sbill 	daddr_t bn;
4593102Swnj 	int sn, dist;
46021Sbill 
461*11315Ssam 	st = &hpst[mi->mi_type];
4623706Sroot 	hpaddr->hpcs1 = 0;
4632624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
4642383Swnj 		return (MBU_BUSY);
46510857Ssam 	if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) {
4663706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
4673706Sroot 
46810857Ssam 		sc->sc_hpinit = 1;
4692624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4703140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
4713140Swnj 			printf("DCLR attn\n");
4722624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
4735726Sroot 		if (!ML11)
4745726Sroot 			hpaddr->hpof = HPOF_FMT22;
4753140Swnj 		mbclrattn(mi);
4765726Sroot 		if (!ML11) {
4775726Sroot 			bbp->b_flags = B_READ|B_BUSY;
4785726Sroot 			bbp->b_dev = bp->b_dev;
4795726Sroot 			bbp->b_bcount = 512;
4805726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
4815726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
4825726Sroot 			bbp->b_cylin = st->ncyl - 1;
4835726Sroot 			mi->mi_tab.b_actf = bbp;
4845726Sroot 			bbp->av_forw = bp;
4855726Sroot 			bp = bbp;
4865726Sroot 		}
48721Sbill 	}
4882604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
4892383Swnj 		return (MBU_DODATA);
4905726Sroot 	if (ML11)
4915726Sroot 		return (MBU_DODATA);
4923093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
4932383Swnj 		return (MBU_DODATA);
4942395Swnj 	bn = dkblock(bp);
4952395Swnj 	sn = bn%st->nspc;
4962395Swnj 	sn = (sn+st->nsect-hpSDIST)%st->nsect;
49711202Ssam 	if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
49810908Ssam 		if (sc->sc_doseeks)
4992383Swnj 			return (MBU_DODATA);
50011202Ssam 		dist = (MASKREG(hpaddr->hpla) >> 6) - st->nsect + 1;
5012383Swnj 		if (dist < 0)
5022383Swnj 			dist += st->nsect;
5032383Swnj 		if (dist > st->nsect - hpRDIST)
5042383Swnj 			return (MBU_DODATA);
5052614Swnj 	} else
5062614Swnj 		hpaddr->hpdc = bp->b_cylin;
50710908Ssam 	if (sc->sc_doseeks)
5082624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
509305Sbill 	else {
510305Sbill 		hpaddr->hpda = sn;
5112624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
512305Sbill 	}
5132383Swnj 	return (MBU_STARTED);
51421Sbill }
51521Sbill 
5162383Swnj hpstart(mi)
5172978Swnj 	register struct mba_device *mi;
51821Sbill {
5192624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5202383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5212383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
52210857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
52321Sbill 	daddr_t bn;
5242383Swnj 	int sn, tn;
52521Sbill 
52621Sbill 	bn = dkblock(bp);
5275726Sroot 	if (ML11)
5285726Sroot 		hpaddr->hpda = bn;
5295726Sroot 	else {
5305726Sroot 		sn = bn%st->nspc;
5315726Sroot 		tn = sn/st->nsect;
5325726Sroot 		sn %= st->nsect;
5335726Sroot 		hpaddr->hpdc = bp->b_cylin;
5345726Sroot 		hpaddr->hpda = (tn << 8) + sn;
5355726Sroot 	}
53610857Ssam 	if (sc->sc_hdr) {
5375726Sroot 		if (bp->b_flags & B_READ)
5385726Sroot 			return (HP_RHDR|HP_GO);
5395726Sroot 		else
5405726Sroot 			return (HP_WHDR|HP_GO);
5415726Sroot 	}
5425726Sroot 	return (0);
54321Sbill }
54421Sbill 
5453102Swnj hpdtint(mi, mbsr)
5462978Swnj 	register struct mba_device *mi;
5473102Swnj 	int mbsr;
54821Sbill {
5492624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5502383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
551*11315Ssam 	register struct hpst *st;
5525893Swnj 	register int er1, er2;
55310857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
5542826Swnj 	int retry = 0;
55521Sbill 
556*11315Ssam 	st = &hpst[mi->mi_type];
557*11315Ssam 	if (bp->b_flags&B_BAD && hpecc(mi, CONT))
558*11315Ssam 		return (MBD_RESTARTED);
5593102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
5603706Sroot #ifdef HPDEBUG
5613289Swnj 		if (hpdebug) {
5623706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
5633706Sroot 
5643706Sroot 			printf("hperr: bp %x cyl %d blk %d as %o ",
5653706Sroot 				bp, bp->b_cylin, bp->b_blkno,
5663706Sroot 				hpaddr->hpas&0xff);
56711202Ssam 			printf("dc %x da %x\n",MASKREG(dc), MASKREG(da));
5683289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
5693289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
5703289Swnj 			printf("er1=%b er2=%b\n",
5713289Swnj 			    hpaddr->hper1, HPER1_BITS,
5723289Swnj 			    hpaddr->hper2, HPER2_BITS);
5733289Swnj 			DELAY(1000000);
5743289Swnj 		}
5753706Sroot #endif
5765858Swnj 		er1 = hpaddr->hper1;
5775893Swnj 		er2 = hpaddr->hper2;
5785893Swnj 		if (er1 & HPER1_HCRC) {
5795858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
5805893Swnj 			er2 &= ~HPER2_BSE;
5815893Swnj 		}
5825858Swnj 		if (er1&HPER1_WLE) {
5832925Swnj 			printf("hp%d: write locked\n", dkunit(bp));
5842826Swnj 			bp->b_flags |= B_ERROR;
58511202Ssam 		} else if (MASKREG(er1) == HPER1_FER && RP06 && !sc->sc_hdr) {
5865726Sroot 			if (hpecc(mi, BSE))
58711202Ssam 				return (MBD_RESTARTED);
58811202Ssam 			goto hard;
5892826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
5903102Swnj 		    mbsr & MBSR_HARD ||
5915858Swnj 		    er1 & HPER1_HARD ||
59210857Ssam 		    sc->sc_hdr ||
5935893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
59410886Shelge  			/*
59510886Shelge  			 * If HCRC the header is screwed up and the sector
59611202Ssam  			 * might be in the bad sector table, better check..
59711202Ssam 			 *
59810886Shelge 			 * Note: If the header is screwed up on a skip sector
59910886Shelge 			 * track, then the appropriate replacement sector
60011202Ssam 			 * cannot be found.
60110886Shelge  			 */
60211202Ssam  			if (er1&HPER1_HCRC && !ML11 && hpecc(mi, BSE))
60311202Ssam 				return (MBD_RESTARTED);
6043706Sroot hard:
60510622Shelge 			if (ML11)
60611202Ssam 				bp->b_blkno = MASKREG(hpaddr->hpda);
60710622Shelge 			else
60811202Ssam 				bp->b_blkno = MASKREG(hpaddr->hpdc) * st->nspc +
60911202Ssam 				   (MASKREG(hpaddr->hpda) >> 8) * st->nsect +
61011202Ssam 				   (hpaddr->hpda&0x1f);
6112925Swnj 			harderr(bp, "hp");
6123271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
6133271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
6143706Sroot 			printf("er1=%b er2=%b",
6152826Swnj 			    hpaddr->hper1, HPER1_BITS,
6162826Swnj 			    hpaddr->hper2, HPER2_BITS);
6173706Sroot 			if (hpaddr->hpmr)
61811202Ssam 				printf(" mr=%o", MASKREG(hpaddr->hpmr));
6193706Sroot 			if (hpaddr->hpmr2)
62011202Ssam 				printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
6213706Sroot 			printf("\n");
6222826Swnj 			bp->b_flags |= B_ERROR;
62310622Shelge 			retry = 0;
62410857Ssam 			sc->sc_recal = 0;
6255893Swnj 		} else if ((er2 & HPER2_BSE) && !ML11) {
6263706Sroot 			if (hpecc(mi, BSE))
62711202Ssam 				return (MBD_RESTARTED);
628*11315Ssam 			goto hard;
6295893Swnj 		} else if (RM80 && er2&HPER2_SSE) {
6303988Sroot 			(void) hpecc(mi, SSE);
6312883Swnj 			return (MBD_RESTARTED);
6325858Swnj 		} else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) {
6333706Sroot 			if (hpecc(mi, ECC))
6342383Swnj 				return (MBD_RESTARTED);
6352826Swnj 			/* else done */
6362826Swnj 		} else
6372826Swnj 			retry = 1;
6382826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
6395726Sroot 		if (ML11) {
6405726Sroot 			if (mi->mi_tab.b_errcnt >= 16)
6415726Sroot 				goto hard;
6425726Sroot 		} else if ((mi->mi_tab.b_errcnt&07) == 4) {
6432826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
64410857Ssam 			sc->sc_recal = 1;
64511202Ssam 			return (MBD_RESTARTED);
64621Sbill 		}
6472826Swnj 		if (retry)
6482826Swnj 			return (MBD_RETRY);
6492826Swnj 	}
6503706Sroot #ifdef HPDEBUG
6513289Swnj 	else
65210857Ssam 		if (hpdebug && sc->sc_recal) {
65310857Ssam 			printf("recal %d ", sc->sc_recal);
6543289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
6553289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
6563289Swnj 			printf("er1=%b er2=%b\n",
6573289Swnj 			    hpaddr->hper1, HPER1_BITS,
6583289Swnj 			    hpaddr->hper2, HPER2_BITS);
6593289Swnj 		}
6603706Sroot #endif
66110857Ssam 	switch (sc->sc_recal) {
6623093Swnj 
6633093Swnj 	case 1:
6643093Swnj 		hpaddr->hpdc = bp->b_cylin;
6653093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
66610857Ssam 		sc->sc_recal++;
6673706Sroot 		return (MBD_RESTARTED);
6683093Swnj 	case 2:
6693093Swnj 		if (mi->mi_tab.b_errcnt < 16 ||
6703289Swnj 		    (bp->b_flags & B_READ) == 0)
6713093Swnj 			goto donerecal;
6723093Swnj 		hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
6733093Swnj 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
67410857Ssam 		sc->sc_recal++;
6753093Swnj 		return (MBD_RESTARTED);
6763093Swnj 	donerecal:
6773158Swnj 	case 3:
67810857Ssam 		sc->sc_recal = 0;
6792892Swnj 		return (MBD_RETRY);
6802892Swnj 	}
68110857Ssam 	sc->sc_hdr = 0;
68211202Ssam 	bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr);
6833640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
6843093Swnj 		/*
6853093Swnj 		 * This is fast and occurs rarely; we don't
6863093Swnj 		 * bother with interrupts.
6873093Swnj 		 */
6882624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
6893093Swnj 		while (hpaddr->hpds & HPDS_PIP)
6902383Swnj 			;
6912383Swnj 		mbclrattn(mi);
69221Sbill 	}
6935726Sroot 	if (!ML11) {
6945726Sroot 		hpaddr->hpof = HPOF_FMT22;
6955726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
6965726Sroot 	}
6972383Swnj 	return (MBD_DONE);
69821Sbill }
69921Sbill 
7007738Sroot hpread(dev, uio)
7012624Swnj 	dev_t dev;
7027738Sroot 	struct uio *uio;
70321Sbill {
7042624Swnj 	register int unit = minor(dev) >> 3;
70521Sbill 
7062624Swnj 	if (unit >= NHP)
7078156Sroot 		return (ENXIO);
7088156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio));
70921Sbill }
71021Sbill 
7117831Sroot hpwrite(dev, uio)
7122624Swnj 	dev_t dev;
7137831Sroot 	struct uio *uio;
71421Sbill {
7152624Swnj 	register int unit = minor(dev) >> 3;
71621Sbill 
7172624Swnj 	if (unit >= NHP)
7188156Sroot 		return (ENXIO);
7198156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio));
72021Sbill }
72121Sbill 
7225726Sroot /*ARGSUSED*/
7237635Ssam hpioctl(dev, cmd, data, flag)
7245726Sroot 	dev_t dev;
7255726Sroot 	int cmd;
7267635Ssam 	caddr_t data;
7275726Sroot 	int flag;
7285726Sroot {
7295726Sroot 
7305726Sroot 	switch (cmd) {
7317635Ssam 
7325726Sroot 	case DKIOCHDR:	/* do header read/write */
73310857Ssam 		hpsoftc[minor(dev) >> 3].sc_hdr = 1;
7348579Sroot 		return (0);
7355726Sroot 
7365726Sroot 	default:
7378579Sroot 		return (ENXIO);
7385726Sroot 	}
7395726Sroot }
7405726Sroot 
7413706Sroot hpecc(mi, flag)
7422978Swnj 	register struct mba_device *mi;
7433706Sroot 	int flag;
74421Sbill {
7452383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
7462624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
7472383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
7483706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
7493706Sroot 	int npf, o;
7502383Swnj 	int bn, cn, tn, sn;
751914Sbill 	int bcr;
75221Sbill 
75311202Ssam 	bcr = MASKREG(mbp->mba_bcr);
754914Sbill 	if (bcr)
755914Sbill 		bcr |= 0xffff0000;		/* sxt */
7563706Sroot 	if (flag == CONT)
7573706Sroot 		npf = bp->b_error;
7583706Sroot 	else
7593706Sroot 		npf = btop(bcr + bp->b_bcount);
760420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
761420Sbill 	bn = dkblock(bp);
762420Sbill 	cn = bp->b_cylin;
7633706Sroot 	sn = bn%(st->nspc) + npf;
7642383Swnj 	tn = sn/st->nsect;
7652383Swnj 	sn %= st->nsect;
7662383Swnj 	cn += tn/st->ntrak;
7672383Swnj 	tn %= st->ntrak;
7683706Sroot 	switch (flag) {
76910856Ssam 	case ECC: {
7703706Sroot 		register int i;
7713706Sroot 		caddr_t addr;
7723706Sroot 		struct pte mpte;
7733706Sroot 		int bit, byte, mask;
7743706Sroot 
7753706Sroot 		npf--;		/* because block in error is previous block */
7763706Sroot 		printf("hp%d%c: soft ecc sn%d\n", dkunit(bp),
7773706Sroot 		    'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
77811202Ssam 		mask = MASKREG(rp->hpec2);
77911202Ssam 		i = MASKREG(rp->hpec1) - 1;		/* -1 makes 0 origin */
7803706Sroot 		bit = i&07;
7813706Sroot 		i = (i&~07)>>3;
7823706Sroot 		byte = i + o;
7833706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
7843706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
7853706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
7863706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
7873706Sroot 			byte++;
7883706Sroot 			i++;
7893706Sroot 			bit -= 8;
7903706Sroot 		}
7913706Sroot 		if (bcr == 0)
7923706Sroot 			return (0);
7933847Sroot 		npf++;
7943706Sroot 		break;
7953706Sroot 		}
7963706Sroot 
7973706Sroot 	case SSE:
7983706Sroot 		rp->hpof |= HPOF_SSEI;
7993706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
8003706Sroot 		break;
8013706Sroot 
8023706Sroot 	case BSE:
8033706Sroot #ifdef HPBDEBUG
8043706Sroot 		if (hpbdebug)
8053706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
8063706Sroot #endif
80711202Ssam  		if (rp->hpof&HPOF_SSEI)
80811202Ssam  			sn++;
8093706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
81011202Ssam 			return (0);
8113706Sroot 		bp->b_flags |= B_BAD;
8123706Sroot 		bp->b_error = npf + 1;
8133706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
8143706Sroot 		cn = bn/st->nspc;
8153706Sroot 		sn = bn%st->nspc;
8163706Sroot 		tn = sn/st->nsect;
8173706Sroot 		sn %= st->nsect;
8183706Sroot 		mbp->mba_bcr = -512;
81910886Shelge  		rp->hpof &= ~HPOF_SSEI;
8203706Sroot #ifdef HPBDEBUG
8213706Sroot 		if (hpbdebug)
8223706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
8233706Sroot #endif
8243706Sroot 		break;
8253706Sroot 
8263706Sroot 	case CONT:
8273706Sroot #ifdef HPBDEBUG
8283706Sroot 		if (hpbdebug)
8293706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
8303706Sroot #endif
8313706Sroot 		npf = bp->b_error;
8323706Sroot 		bp->b_flags &= ~B_BAD;
8333706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
83411202Ssam 		if (MASKREG(mbp->mba_bcr) == 0)
83511202Ssam 			return (0);
8363706Sroot 		break;
8373706Sroot 	}
8383706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
8393350Swnj 	if (rp->hpof&HPOF_SSEI)
8402883Swnj 		sn++;
841420Sbill 	rp->hpdc = cn;
842420Sbill 	rp->hpda = (tn<<8) + sn;
843420Sbill 	mbp->mba_sr = -1;
8443706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
8453706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
8463706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
847420Sbill 	return (1);
84821Sbill }
8492362Swnj 
8502362Swnj #define	DBSIZE	20
8512362Swnj 
8522362Swnj hpdump(dev)
8532362Swnj 	dev_t dev;
8542362Swnj {
8552978Swnj 	register struct mba_device *mi;
8562383Swnj 	register struct mba_regs *mba;
8572624Swnj 	struct hpdevice *hpaddr;
8582362Swnj 	char *start;
8592383Swnj 	int num, unit;
8602383Swnj 	register struct hpst *st;
8612362Swnj 
8622362Swnj 	num = maxfree;
8632362Swnj 	start = 0;
8642362Swnj 	unit = minor(dev) >> 3;
8652827Swnj 	if (unit >= NHP)
8662827Swnj 		return (ENXIO);
8672383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
8682978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
8692827Swnj 	if (mi == 0 || mi->mi_alive == 0)
8702827Swnj 		return (ENXIO);
8712383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
8723102Swnj 	mba->mba_cr = MBCR_INIT;
8732624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
8743093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
8752624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
8762624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
8773093Swnj 		hpaddr->hpof = HPOF_FMT22;
8782362Swnj 	}
8792383Swnj 	st = &hpst[mi->mi_type];
8802827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
8812827Swnj 		return (EINVAL);
8822362Swnj 	while (num > 0) {
8832383Swnj 		register struct pte *hpte = mba->mba_map;
8842362Swnj 		register int i;
8852383Swnj 		int blk, cn, sn, tn;
8862362Swnj 		daddr_t bn;
8872362Swnj 
8882362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
8892362Swnj 		bn = dumplo + btop(start);
8902383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
8912383Swnj 		sn = bn%st->nspc;
8922383Swnj 		tn = sn/st->nsect;
8932383Swnj 		sn = sn%st->nsect;
8942362Swnj 		hpaddr->hpdc = cn;
8952362Swnj 		hpaddr->hpda = (tn << 8) + sn;
8962362Swnj 		for (i = 0; i < blk; i++)
8972362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
8982383Swnj 		mba->mba_sr = -1;
8992383Swnj 		mba->mba_bcr = -(blk*NBPG);
9002383Swnj 		mba->mba_var = 0;
9012624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
9023093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
9032362Swnj 			;
9043093Swnj 		if (hpaddr->hpds&HPDS_ERR)
9052827Swnj 			return (EIO);
9062362Swnj 		start += blk*NBPG;
9072362Swnj 		num -= blk;
9082362Swnj 	}
9092362Swnj 	return (0);
9102362Swnj }
9111565Sbill #endif
912