xref: /csrg-svn/sys/vax/mba/hp.c (revision 17071)
1*17071Sralph /*	hp.c	6.5	84/08/29	*/
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 */
10415101Skarels 	1077760, 0,		/* C=cyl 0 thru 841 */
10511212Ssam 	15884,	294,		/* D=cyl 294 thru 306 */
10611212Ssam 	307200,	307,		/* E=cyl 307 thru 546 */
10715101Skarels 	377440,	547,		/* F=cyl 547 thru 841 */
10815101Skarels 	701280,	294,		/* G=cyl 294 thru 841 */
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] = {
12910734Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
13011212Ssam 	66880,	17,		/* B=cyl 17 thru 86 */
13111629Ssam 	808320,	0,		/* C=cyl 0 thru 841 */
13211212Ssam 	15884,	391,		/* D=cyl 391 thru 407 */
13311212Ssam 	307200,	408,		/* E=cyl 408 thru 727 */
13411629Ssam 	109296,	728,		/* F=cyl 728 thru 841 */
13511629Ssam 	432816,	391,		/* G=cyl 391 thru 841 */
13611212Ssam 	291346,	87,		/* H=cyl 87 thru 390 */
13713202Sroot }, ampex_sizes[8] = {
13811281Ssam 	15884,	0,		/* A=cyl 0 thru 26 */
13911281Ssam 	33440,	27,		/* B=cyl 27 thru 81 */
14013184Shelge 	495520,	0,		/* C=cyl 0 thru 814 */
14111281Ssam 	15884,	562,		/* D=cyl 562 thru 588 */
14211281Ssam 	55936,	589,		/* E=cyl 589 thru 680 */
14313184Shelge 	81312,	681,		/* F=cyl 681 thru 814 */
14413184Shelge 	153664,	562,		/* G=cyl 562 thru 814 */
14511281Ssam 	291346,	82,		/* H=cyl 82 thru 561 */
14621Sbill };
1472383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
14821Sbill 
1496927Ssam /*
1506927Ssam  * Table for converting Massbus drive types into
1516927Ssam  * indices into the partition tables.  Slots are
1526927Ssam  * left for those drives devined from other means
1536927Ssam  * (e.g. SI, AMPEX, etc.).
1546927Ssam  */
1556927Ssam short	hptypes[] = {
1566927Ssam #define	HPDT_RM03	0
1576927Ssam 	MBDT_RM03,
1586927Ssam #define	HPDT_RM05	1
1596927Ssam 	MBDT_RM05,
1606927Ssam #define	HPDT_RP06	2
1616927Ssam 	MBDT_RP06,
1626927Ssam #define	HPDT_RM80	3
1636927Ssam 	MBDT_RM80,
16413157Ssam #define	HPDT_RP04	4
16513157Ssam 	MBDT_RP04,
16613157Ssam #define	HPDT_RP05	5
1676927Ssam 	MBDT_RP05,
16813157Ssam #define	HPDT_RP07	6
1696927Ssam 	MBDT_RP07,
17013157Ssam #define	HPDT_ML11A	7
1716927Ssam 	MBDT_ML11A,
17213157Ssam #define	HPDT_ML11B	8
1736927Ssam 	MBDT_ML11B,
17413157Ssam #define	HPDT_9775	9
1756927Ssam 	-1,
17613157Ssam #define	HPDT_9730	10
1776927Ssam 	-1,
17813157Ssam #define	HPDT_CAPRICORN	11
1796927Ssam 	-1,
18013157Ssam #define HPDT_EAGLE	12
1819175Ssam 	-1,
18213157Ssam #define	HPDT_9300	13
18311281Ssam 	-1,
18413157Ssam #define HPDT_RM02	14
1859175Ssam 	MBDT_RM02,		/* beware, actually capricorn or eagle */
1866927Ssam 	0
1876927Ssam };
1882978Swnj struct	mba_device *hpinfo[NHP];
18914145Shelge int	hpattach(),hpustart(),hpstart(),hpdtint();
1902383Swnj struct	mba_driver hpdriver =
1912978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
1922978Swnj 	  hptypes, "hp", 0, hpinfo };
1932383Swnj 
19412836Ssam /*
19516225Skarels  * These variable are all measured in sectors.
19616225Skarels  * Sdist is how much to "lead" in the search for a desired sector
19716225Skarels  * (i.e. if want N, search for N-sdist.)
19816225Skarels  * Maxdist and mindist define the region right before our desired sector within
19916225Skarels  * which we don't bother searching.  We don't search when we are already less
20016225Skarels  * then maxdist and more than mindist sectors "before" our desired sector.
20116225Skarels  * Maxdist should be >= sdist.
20216225Skarels  *
20316225Skarels  * Beware, sdist, mindist and maxdist are not well tuned
20412836Ssam  * for many of the drives listed in this table.
20512836Ssam  * Try patching things with something i/o intensive
20612836Ssam  * running and watch iostat.
20712836Ssam  */
2082383Swnj struct hpst {
20912836Ssam 	short	nsect;		/* # sectors/track */
21012836Ssam 	short	ntrak;		/* # tracks/cylinder */
21112836Ssam 	short	nspc;		/* # sector/cylinders */
21212836Ssam 	short	ncyl;		/* # cylinders */
21312836Ssam 	struct	size *sizes;	/* partition tables */
21412836Ssam 	short	sdist;		/* seek distance metric */
21516225Skarels 	short	maxdist;	/* boundaries of non-searched area */
21616225Skarels 	short	mindist;	/* preceding the target sector */
2172383Swnj } hpst[] = {
21816225Skarels     { 32, 5,	32*5,	823,	rm03_sizes,	7, 4, 1 },	/* RM03 */
21916225Skarels     { 32, 19,	32*19,	823,	rm05_sizes,	7, 4, 1 },	/* RM05 */
22016225Skarels     { 22,19,	22*19,	815,	rp06_sizes,	7, 4, 1 },	/* RP06 */
22116225Skarels     { 31, 14, 	31*14,	559,	rm80_sizes,	7, 4, 1 },	/* RM80 */
22216225Skarels     { 22, 19,	22*19,	411,	rp05_sizes,	7, 4, 1 },	/* RP04 */
22316225Skarels     { 22, 19,	22*19,	411,	rp05_sizes,	7, 4, 1 },	/* RP05 */
22416225Skarels     { 50, 32,	50*32,	630,	rp07_sizes,    15, 8, 3 },	/* RP07 */
22516225Skarels     { 1, 1,	1,	1,	0,		0, 0, 0 },	/* ML11A */
22616225Skarels     { 1, 1,	1,	1,	0,		0, 0, 0 },	/* ML11B */
22716225Skarels     { 32, 40,	32*40,	843,	cdc9775_sizes,	7, 4, 1 },	/* 9775 */
22816225Skarels     { 32, 10,	32*10,	823,	cdc9730_sizes,	7, 4, 1 },	/* 9730 */
22916225Skarels     { 32, 16,	32*16,	1024,	capricorn_sizes,10,4, 3 },	/* Capricorn */
23016225Skarels     { 48, 20,	48*20,	842,	eagle_sizes,   15, 8, 3 },	/* EAGLE */
23116225Skarels     { 32, 19,	32*19,	815,	ampex_sizes,	7, 4, 1 },	/* 9300 */
2322383Swnj };
2332383Swnj 
2342624Swnj u_char	hp_offset[16] = {
2353093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
2363093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
2373093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
2383093Swnj     0, 0, 0, 0,
23921Sbill };
24021Sbill 
2412624Swnj struct	buf	rhpbuf[NHP];
2423706Sroot struct	buf	bhpbuf[NHP];
2433706Sroot struct	dkbad	hpbad[NHP];
24421Sbill 
24510857Ssam struct	hpsoftc {
24610857Ssam 	u_char	sc_hpinit;	/* drive initialized */
24710857Ssam 	u_char	sc_recal;	/* recalibrate state */
24810857Ssam 	u_char	sc_hdr;		/* next i/o includes header */
24910857Ssam 	u_char	sc_doseeks;	/* perform explicit seeks */
25010857Ssam 	daddr_t	sc_mlsize;	/* ML11 size */
251*17071Sralph 	int	sc_pgdone;	/* amount sucessfully transfered */
252*17071Sralph 	daddr_t	sc_badbn;	/* replacement block number */
25310857Ssam } hpsoftc[NHP];
25410857Ssam 
25521Sbill #define	b_cylin b_resid
25621Sbill 
2575726Sroot /* #define ML11 0  to remove ML11 support */
2585726Sroot #define	ML11	(hptypes[mi->mi_type] == MBDT_ML11A)
2595726Sroot #define	RP06	(hptypes[mi->mi_type] <= MBDT_RP06)
2605726Sroot #define	RM80	(hptypes[mi->mi_type] == MBDT_RM80)
2615726Sroot 
26211202Ssam #define	MASKREG(reg)	((reg)&0xffff)
26311202Ssam 
26421Sbill #ifdef INTRLVE
26521Sbill daddr_t dkblock();
26621Sbill #endif
2672604Swnj 
2682978Swnj /*ARGSUSED*/
2692978Swnj hpattach(mi, slave)
27010734Ssam 	register struct mba_device *mi;
2712604Swnj {
27210734Ssam 
27310734Ssam 	mi->mi_type = hpmaptype(mi);
27410734Ssam 	if (!ML11 && mi->mi_dk >= 0) {
27510734Ssam 		struct hpst *st = &hpst[mi->mi_type];
27610734Ssam 
27710734Ssam 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
27810734Ssam 	}
27910734Ssam }
28010734Ssam 
28110734Ssam /*
28210734Ssam  * Map apparent MASSBUS drive type into manufacturer
28310734Ssam  * specific configuration.  For SI controllers this is done
28410734Ssam  * based on codes in the serial number register.  For
28510734Ssam  * EMULEX controllers, the track and sector attributes are
28610734Ssam  * used when the drive type is an RM02 (not supported by DEC).
28710734Ssam  */
28810734Ssam hpmaptype(mi)
28910734Ssam 	register struct mba_device *mi;
29010734Ssam {
2916927Ssam 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
29210734Ssam 	register int type = mi->mi_type;
2936927Ssam 
2946927Ssam 	/*
29511281Ssam 	 * Model-byte processing for SI controllers.
2966927Ssam 	 * NB:  Only deals with RM03 and RM05 emulations.
2976927Ssam 	 */
29810734Ssam 	if (type == HPDT_RM03 || type == HPDT_RM05) {
29910734Ssam 		int hpsn = hpaddr->hpsn;
3006927Ssam 
3016927Ssam 		if ((hpsn & SIMB_LU) != mi->mi_drive)
30210734Ssam 			return (type);
3036927Ssam 		switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
3046927Ssam 
3056927Ssam 		case SI9775D:
30611281Ssam 			printf("hp%d: 9775 (direct)\n", mi->mi_unit);
30710734Ssam 			type = HPDT_9775;
3086927Ssam 			break;
3096927Ssam 
3106927Ssam 		case SI9730D:
31111281Ssam 			printf("hp%d: 9730 (direct)\n", mi->mi_unit);
31210734Ssam 			type = HPDT_9730;
3136927Ssam 			break;
3146927Ssam 
3157035Swnj 		/*
31611281Ssam 		 * Beware, since the only SI controller we
31711281Ssam 		 * have has a 9300 instead of a 9766, we map the
31811281Ssam 		 * drive type into the 9300.  This means that
31911281Ssam 		 * on a 9766 you lose the last 8 cylinders (argh).
3207035Swnj 		 */
3216927Ssam 		case SI9766:
32211281Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
32311281Ssam 			type = HPDT_9300;
3246927Ssam 			break;
3256927Ssam 
3266927Ssam 		case SI9762:
3276927Ssam 			printf("hp%d: 9762\n", mi->mi_unit);
32810734Ssam 			type = HPDT_RM03;
3296927Ssam 			break;
33011281Ssam 
33111281Ssam 		case SICAPD:
33211281Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
33311281Ssam 			type = HPDT_CAPRICORN;
33411281Ssam 			break;
33511281Ssam 
33611281Ssam 		case SI9751D:
33711281Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
33811281Ssam 			type = HPDT_EAGLE;
33911281Ssam 			break;
3406927Ssam 		}
34110734Ssam 		return (type);
34210734Ssam 	}
3436927Ssam 
3446927Ssam 	/*
34510734Ssam 	 * EMULEX SC750 or SC780.  Poke the holding register.
3466927Ssam 	 */
34710734Ssam 	if (type == HPDT_RM02) {
34810734Ssam 		int ntracks, nsectors;
34910734Ssam 
35011315Ssam 		hpaddr->hpof = HPOF_FMT22;
35111315Ssam 		mbclrattn(mi);
3526927Ssam 		hpaddr->hpcs1 = HP_NOP;
3536927Ssam 		hpaddr->hphr = HPHR_MAXTRAK;
35411202Ssam 		ntracks = MASKREG(hpaddr->hphr) + 1;
35510055Ssam 		if (ntracks == 16) {
3566927Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
35710734Ssam 			type = HPDT_CAPRICORN;
35810734Ssam 			goto done;
35910734Ssam 		}
36013157Ssam 		if (ntracks == 19) {
36113157Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
36213157Ssam 			type = HPDT_9300;
36313157Ssam 			goto done;
36413157Ssam 		}
36510734Ssam 		hpaddr->hpcs1 = HP_NOP;
36610734Ssam 		hpaddr->hphr = HPHR_MAXSECT;
36711202Ssam 		nsectors = MASKREG(hpaddr->hphr) + 1;
36811315Ssam 		if (ntracks == 20 && nsectors == 48) {
36910734Ssam 			type = HPDT_EAGLE;
37011212Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
37111315Ssam 			goto done;
37210734Ssam 		}
37311315Ssam 		printf("hp%d: ntracks %d, nsectors %d: unknown device\n",
37413157Ssam 			mi->mi_unit, ntracks, nsectors);
37510734Ssam done:
3766927Ssam 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
37711315Ssam 		mbclrattn(mi);		/* conservative */
37810734Ssam 		return (type);
37910734Ssam 	}
3806927Ssam 
38110734Ssam 	/*
38210734Ssam 	 * Map all ML11's to the same type.  Also calculate
38310734Ssam 	 * transfer rates based on device characteristics.
38410734Ssam 	 */
38510734Ssam 	if (type == HPDT_ML11A || type == HPDT_ML11B) {
38610857Ssam 		register struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
38710857Ssam 		register int trt;
3882604Swnj 
38910857Ssam 		sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
3905726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
39110857Ssam 			sc->sc_mlsize >>= 2;
3925726Sroot 		if (mi->mi_dk >= 0) {
3935726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
3945726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
3955726Sroot 		}
39610734Ssam 		type = HPDT_ML11A;
3976927Ssam 	}
39810734Ssam 	return (type);
3992604Swnj }
4002604Swnj 
4018579Sroot hpopen(dev)
4028579Sroot 	dev_t dev;
4038579Sroot {
4048579Sroot 	register int unit = minor(dev) >> 3;
4058579Sroot 	register struct mba_device *mi;
4068579Sroot 
4078579Sroot 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
4088579Sroot 		return (ENXIO);
4098579Sroot 	return (0);
4108579Sroot }
4118579Sroot 
41221Sbill hpstrategy(bp)
4132383Swnj 	register struct buf *bp;
41421Sbill {
4152978Swnj 	register struct mba_device *mi;
4162383Swnj 	register struct hpst *st;
4172383Swnj 	register int unit;
41821Sbill 	long sz, bn;
4192383Swnj 	int xunit = minor(bp->b_dev) & 07;
4205432Sroot 	int s;
42121Sbill 
42221Sbill 	sz = bp->b_bcount;
42321Sbill 	sz = (sz+511) >> 9;
42421Sbill 	unit = dkunit(bp);
4252383Swnj 	if (unit >= NHP)
4262383Swnj 		goto bad;
4272383Swnj 	mi = hpinfo[unit];
4282395Swnj 	if (mi == 0 || mi->mi_alive == 0)
4292383Swnj 		goto bad;
4302383Swnj 	st = &hpst[mi->mi_type];
4315726Sroot 	if (ML11) {
43210857Ssam 		struct hpsoftc *sc = &hpsoftc[unit];
43310857Ssam 
4345726Sroot 		if (bp->b_blkno < 0 ||
43510857Ssam 		    dkblock(bp)+sz > sc->sc_mlsize)
4365726Sroot 			goto bad;
4375726Sroot 		bp->b_cylin = 0;
4385726Sroot 	} else {
4395726Sroot 		if (bp->b_blkno < 0 ||
4405726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
4415726Sroot 			goto bad;
4425726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
4435726Sroot 	}
4445432Sroot 	s = spl5();
4452383Swnj 	disksort(&mi->mi_tab, bp);
4462383Swnj 	if (mi->mi_tab.b_active == 0)
4472383Swnj 		mbustart(mi);
4485432Sroot 	splx(s);
4492383Swnj 	return;
4502383Swnj 
4512383Swnj bad:
4522383Swnj 	bp->b_flags |= B_ERROR;
4532383Swnj 	iodone(bp);
4542383Swnj 	return;
45521Sbill }
45621Sbill 
4572383Swnj hpustart(mi)
4582978Swnj 	register struct mba_device *mi;
45921Sbill {
4602624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4612383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
46211315Ssam 	register struct hpst *st;
46310857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
46421Sbill 	daddr_t bn;
46516791Skarels 	int sn, tn, dist;
46621Sbill 
46711315Ssam 	st = &hpst[mi->mi_type];
4683706Sroot 	hpaddr->hpcs1 = 0;
4692624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
4702383Swnj 		return (MBU_BUSY);
47110857Ssam 	if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) {
4723706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
4733706Sroot 
47410857Ssam 		sc->sc_hpinit = 1;
4752624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4763140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
4773140Swnj 			printf("DCLR attn\n");
4782624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
4795726Sroot 		if (!ML11)
4805726Sroot 			hpaddr->hpof = HPOF_FMT22;
4813140Swnj 		mbclrattn(mi);
4825726Sroot 		if (!ML11) {
4835726Sroot 			bbp->b_flags = B_READ|B_BUSY;
4845726Sroot 			bbp->b_dev = bp->b_dev;
4855726Sroot 			bbp->b_bcount = 512;
4865726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
4875726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
4885726Sroot 			bbp->b_cylin = st->ncyl - 1;
4895726Sroot 			mi->mi_tab.b_actf = bbp;
4905726Sroot 			bbp->av_forw = bp;
4915726Sroot 			bp = bbp;
4925726Sroot 		}
49321Sbill 	}
4942604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
4952383Swnj 		return (MBU_DODATA);
4965726Sroot 	if (ML11)
4975726Sroot 		return (MBU_DODATA);
4983093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
4992383Swnj 		return (MBU_DODATA);
5002395Swnj 	bn = dkblock(bp);
50116791Skarels 	sn = bn % st->nspc;
50216791Skarels 	tn = sn / st->nsect;
50316791Skarels 	sn = sn % st->nsect;
50411202Ssam 	if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
50510908Ssam 		if (sc->sc_doseeks)
5062383Swnj 			return (MBU_DODATA);
50716225Skarels 		dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1;
5082383Swnj 		if (dist < 0)
5092383Swnj 			dist += st->nsect;
51016225Skarels 		if (dist > st->maxdist || dist < st->mindist)
5112383Swnj 			return (MBU_DODATA);
5122614Swnj 	} else
5132614Swnj 		hpaddr->hpdc = bp->b_cylin;
51410908Ssam 	if (sc->sc_doseeks)
5152624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
516305Sbill 	else {
51716225Skarels 		sn = (sn + st->nsect - st->sdist) % st->nsect;
51816791Skarels 		hpaddr->hpda = (tn << 8) + sn;
5192624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
520305Sbill 	}
5212383Swnj 	return (MBU_STARTED);
52221Sbill }
52321Sbill 
5242383Swnj hpstart(mi)
5252978Swnj 	register struct mba_device *mi;
52621Sbill {
5272624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5282383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5292383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
53010857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
53121Sbill 	daddr_t bn;
5322383Swnj 	int sn, tn;
53321Sbill 
534*17071Sralph 	if (bp->b_flags & B_BAD)
535*17071Sralph 		bn = sc->sc_badbn;
536*17071Sralph 	else
537*17071Sralph 		bn = dkblock(bp) + sc->sc_pgdone;
5385726Sroot 	if (ML11)
5395726Sroot 		hpaddr->hpda = bn;
5405726Sroot 	else {
5415726Sroot 		sn = bn%st->nspc;
5425726Sroot 		tn = sn/st->nsect;
5435726Sroot 		sn %= st->nsect;
5445726Sroot 		hpaddr->hpdc = bp->b_cylin;
5455726Sroot 		hpaddr->hpda = (tn << 8) + sn;
5465726Sroot 	}
54710857Ssam 	if (sc->sc_hdr) {
5485726Sroot 		if (bp->b_flags & B_READ)
5495726Sroot 			return (HP_RHDR|HP_GO);
5505726Sroot 		else
5515726Sroot 			return (HP_WHDR|HP_GO);
5525726Sroot 	}
5535726Sroot 	return (0);
55421Sbill }
55521Sbill 
5563102Swnj hpdtint(mi, mbsr)
5572978Swnj 	register struct mba_device *mi;
5583102Swnj 	int mbsr;
55921Sbill {
5602624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5612383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
56211315Ssam 	register struct hpst *st;
5635893Swnj 	register int er1, er2;
56410857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
5652826Swnj 	int retry = 0;
56621Sbill 
56711315Ssam 	st = &hpst[mi->mi_type];
5683102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
56914145Shelge 		er1 = hpaddr->hper1;
57014145Shelge 		er2 = hpaddr->hper2;
5713706Sroot #ifdef HPDEBUG
5723289Swnj 		if (hpdebug) {
5733706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
5743706Sroot 
5753706Sroot 			printf("hperr: bp %x cyl %d blk %d as %o ",
5763706Sroot 				bp, bp->b_cylin, bp->b_blkno,
5773706Sroot 				hpaddr->hpas&0xff);
57811202Ssam 			printf("dc %x da %x\n",MASKREG(dc), MASKREG(da));
5793289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
5803289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
58114145Shelge 			printf("er1=%b er2=%b\n", MASKREG(er1), HPER1_BITS,
58214145Shelge 			    MASKREG(er2), HPER2_BITS);
5833289Swnj 			DELAY(1000000);
5843289Swnj 		}
5853706Sroot #endif
5865893Swnj 		if (er1 & HPER1_HCRC) {
5875858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
5885893Swnj 			er2 &= ~HPER2_BSE;
5895893Swnj 		}
59016791Skarels 		if (er1 & HPER1_WLE) {
5912925Swnj 			printf("hp%d: write locked\n", dkunit(bp));
5922826Swnj 			bp->b_flags |= B_ERROR;
59316791Skarels 		} else if (sc->sc_hdr) {
59416791Skarels 			goto hard;
595*17071Sralph 		} else if (RM80 && er2&HPER2_SSE) {
596*17071Sralph 			(void) hpecc(mi, SSE);
597*17071Sralph 			return (MBD_RESTARTED);
59816791Skarels 		} else if ((er2 & HPER2_BSE) && !ML11) {
5995726Sroot 			if (hpecc(mi, BSE))
60011202Ssam 				return (MBD_RESTARTED);
60111202Ssam 			goto hard;
60216791Skarels 		} else if (MASKREG(er1) == HPER1_FER && RP06) {
60316791Skarels 			if (hpecc(mi, BSE))
60416791Skarels 				return (MBD_RESTARTED);
60516791Skarels 			goto hard;
606*17071Sralph 		} else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK &&
607*17071Sralph 		    mi->mi_tab.b_errcnt > 7) {
60816791Skarels 			if (hpecc(mi, ECC))
60916791Skarels 				return (MBD_RESTARTED);
61016791Skarels 			/* else done */
6112826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
61216791Skarels 		    (ML11 && mi->mi_tab.b_errcnt > 15) ||
6133102Swnj 		    mbsr & MBSR_HARD ||
6145858Swnj 		    er1 & HPER1_HARD ||
6155893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
61610886Shelge  			/*
61714134Shelge  			 * HCRC means the header is screwed up and the sector
61814134Shelge  			 * might well exist in the bad sector table,
61914134Shelge 			 * better check....
62010886Shelge  			 */
62116791Skarels  			if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE))
62211202Ssam 				return (MBD_RESTARTED);
6233706Sroot hard:
624*17071Sralph 			if (bp->b_flags & B_BAD)
625*17071Sralph 				bp->b_blkno = sc->sc_badbn;
62610622Shelge 			else
627*17071Sralph 				bp->b_blkno = dkblock(bp) + sc->sc_pgdone;
628*17071Sralph  			if (hpaddr->hpof & HPOF_SSEI)
629*17071Sralph  				bp->b_blkno++;
6302925Swnj 			harderr(bp, "hp");
6313271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
6323271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
6333706Sroot 			printf("er1=%b er2=%b",
63414145Shelge 			    MASKREG(hpaddr->hper1), HPER1_BITS,
63514145Shelge 			    MASKREG(hpaddr->hper2), HPER2_BITS);
6363706Sroot 			if (hpaddr->hpmr)
63711202Ssam 				printf(" mr=%o", MASKREG(hpaddr->hpmr));
6383706Sroot 			if (hpaddr->hpmr2)
63911202Ssam 				printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
64014134Shelge 			if (sc->sc_hdr)
64114134Shelge 				printf(" (hdr i/o)");
6423706Sroot 			printf("\n");
6432826Swnj 			bp->b_flags |= B_ERROR;
644*17071Sralph 			bp->b_flags &= ~B_BAD;
6452826Swnj 		} else
6462826Swnj 			retry = 1;
6472826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
64816791Skarels 		if ((mi->mi_tab.b_errcnt & 07) == 4) {
6492826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
65010857Ssam 			sc->sc_recal = 1;
65111202Ssam 			return (MBD_RESTARTED);
65221Sbill 		}
6532826Swnj 	}
6543706Sroot #ifdef HPDEBUG
6553289Swnj 	else
65610857Ssam 		if (hpdebug && sc->sc_recal) {
65710857Ssam 			printf("recal %d ", sc->sc_recal);
6583289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
6593289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
6603289Swnj 			printf("er1=%b er2=%b\n",
6613289Swnj 			    hpaddr->hper1, HPER1_BITS,
6623289Swnj 			    hpaddr->hper2, HPER2_BITS);
6633289Swnj 		}
6643706Sroot #endif
66510857Ssam 	switch (sc->sc_recal) {
6663093Swnj 
6673093Swnj 	case 1:
6683093Swnj 		hpaddr->hpdc = bp->b_cylin;
6693093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
67010857Ssam 		sc->sc_recal++;
6713706Sroot 		return (MBD_RESTARTED);
6723093Swnj 	case 2:
67316791Skarels 		retry = 1;
67416791Skarels 		break;
67516791Skarels 	}
67616791Skarels 	sc->sc_recal = 0;
67716791Skarels 	if (retry) {
67816791Skarels 		if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) {
67916791Skarels 			hpaddr->hpof =
68016791Skarels 			    hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
68116791Skarels 			hpaddr->hpcs1 = HP_OFFSET|HP_GO;
68216791Skarels 			while ((hpaddr->hpds & (HPDS_DRY | HPDS_PIP)) !=
68316791Skarels 			    HPDS_DRY)
68416791Skarels 				DELAY(10);
68516791Skarels 			mbclrattn(mi);
68616791Skarels 		}
6872892Swnj 		return (MBD_RETRY);
6882892Swnj 	}
6893640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
6903093Swnj 		/*
6913093Swnj 		 * This is fast and occurs rarely; we don't
6923093Swnj 		 * bother with interrupts.
6933093Swnj 		 */
6942624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
69516225Skarels 		while ((hpaddr->hpds & (HPDS_DRY | HPDS_PIP)) != HPDS_DRY)
69616791Skarels 			DELAY(10);
6972383Swnj 		mbclrattn(mi);
69821Sbill 	}
699*17071Sralph 	if ((bp->b_flags & B_BAD) && hpecc(mi, CONT))
700*17071Sralph 		return (MBD_RESTARTED);
701*17071Sralph 	sc->sc_hdr = 0;
702*17071Sralph 	sc->sc_pgdone = 0;
703*17071Sralph 	bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr);
7045726Sroot 	if (!ML11) {
7055726Sroot 		hpaddr->hpof = HPOF_FMT22;
7065726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
7075726Sroot 	}
7082383Swnj 	return (MBD_DONE);
70921Sbill }
71021Sbill 
7117738Sroot hpread(dev, uio)
7122624Swnj 	dev_t dev;
7137738Sroot 	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_READ, minphys, uio));
72021Sbill }
72121Sbill 
7227831Sroot hpwrite(dev, uio)
7232624Swnj 	dev_t dev;
7247831Sroot 	struct uio *uio;
72521Sbill {
7262624Swnj 	register int unit = minor(dev) >> 3;
72721Sbill 
7282624Swnj 	if (unit >= NHP)
7298156Sroot 		return (ENXIO);
7308156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio));
73121Sbill }
73221Sbill 
7335726Sroot /*ARGSUSED*/
7347635Ssam hpioctl(dev, cmd, data, flag)
7355726Sroot 	dev_t dev;
7365726Sroot 	int cmd;
7377635Ssam 	caddr_t data;
7385726Sroot 	int flag;
7395726Sroot {
7405726Sroot 
7415726Sroot 	switch (cmd) {
7427635Ssam 
7435726Sroot 	case DKIOCHDR:	/* do header read/write */
74410857Ssam 		hpsoftc[minor(dev) >> 3].sc_hdr = 1;
7458579Sroot 		return (0);
7465726Sroot 
7475726Sroot 	default:
7488579Sroot 		return (ENXIO);
7495726Sroot 	}
7505726Sroot }
7515726Sroot 
7523706Sroot hpecc(mi, flag)
7532978Swnj 	register struct mba_device *mi;
7543706Sroot 	int flag;
75521Sbill {
7562383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
7572624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
7582383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
7593706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
760*17071Sralph 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
7613706Sroot 	int npf, o;
7622383Swnj 	int bn, cn, tn, sn;
763914Sbill 	int bcr;
76421Sbill 
76511202Ssam 	bcr = MASKREG(mbp->mba_bcr);
766914Sbill 	if (bcr)
767914Sbill 		bcr |= 0xffff0000;		/* sxt */
768*17071Sralph 	if (bp->b_flags & B_BAD)
7693706Sroot 		npf = bp->b_error;
7703706Sroot 	else
7713706Sroot 		npf = btop(bcr + bp->b_bcount);
772420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
773*17071Sralph 	bn = dkblock(bp) + npf;
774420Sbill 	cn = bp->b_cylin;
775*17071Sralph 	sn = bn%(st->nspc);
7762383Swnj 	tn = sn/st->nsect;
7772383Swnj 	sn %= st->nsect;
7782383Swnj 	cn += tn/st->ntrak;
7792383Swnj 	tn %= st->ntrak;
7803706Sroot 	switch (flag) {
78110856Ssam 	case ECC: {
7823706Sroot 		register int i;
7833706Sroot 		caddr_t addr;
7843706Sroot 		struct pte mpte;
7853706Sroot 		int bit, byte, mask;
7863706Sroot 
7873706Sroot 		npf--;		/* because block in error is previous block */
788*17071Sralph 		if (bp->b_flags & B_BAD)
789*17071Sralph 			bn = sc->sc_badbn;
7903706Sroot 		printf("hp%d%c: soft ecc sn%d\n", dkunit(bp),
791*17071Sralph 		    'a'+(minor(bp->b_dev)&07), bn);
79211202Ssam 		mask = MASKREG(rp->hpec2);
79311202Ssam 		i = MASKREG(rp->hpec1) - 1;		/* -1 makes 0 origin */
7943706Sroot 		bit = i&07;
7953706Sroot 		i = (i&~07)>>3;
7963706Sroot 		byte = i + o;
7973706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
7983706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
7993706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
8003706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
8013706Sroot 			byte++;
8023706Sroot 			i++;
8033706Sroot 			bit -= 8;
8043706Sroot 		}
805*17071Sralph 		if ((bp->b_flags & B_BAD) || bcr == 0)
8063706Sroot 			return (0);
8073847Sroot 		npf++;
8083706Sroot 		break;
8093706Sroot 		}
8103706Sroot 
8113706Sroot 	case SSE:
8123706Sroot 		rp->hpof |= HPOF_SSEI;
813*17071Sralph 		if (bp->b_flags & B_BAD) {
814*17071Sralph 			bn = sc->sc_badbn;
815*17071Sralph 			goto fixregs;
816*17071Sralph 		}
8173706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
8183706Sroot 		break;
8193706Sroot 
8203706Sroot 	case BSE:
821*17071Sralph  		if (rp->hpof & HPOF_SSEI)
822*17071Sralph  			sn++;
8233706Sroot #ifdef HPBDEBUG
8243706Sroot 		if (hpbdebug)
8253706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
8263706Sroot #endif
827*17071Sralph 		if (bp->b_flags & B_BAD)
828*17071Sralph 			return (0);
8293706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
83011202Ssam 			return (0);
8313706Sroot 		bp->b_flags |= B_BAD;
8323706Sroot 		bp->b_error = npf + 1;
833*17071Sralph  		rp->hpof &= ~HPOF_SSEI;
8343706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
835*17071Sralph 		sc->sc_badbn = bn;
836*17071Sralph 	fixregs:
8373706Sroot 		cn = bn/st->nspc;
8383706Sroot 		sn = bn%st->nspc;
8393706Sroot 		tn = sn/st->nsect;
8403706Sroot 		sn %= st->nsect;
8413706Sroot 		mbp->mba_bcr = -512;
8423706Sroot #ifdef HPBDEBUG
8433706Sroot 		if (hpbdebug)
8443706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
8453706Sroot #endif
8463706Sroot 		break;
8473706Sroot 
8483706Sroot 	case CONT:
8493706Sroot #ifdef HPBDEBUG
8503706Sroot 		if (hpbdebug)
8513706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
8523706Sroot #endif
8533706Sroot 		bp->b_flags &= ~B_BAD;
8543706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
85511202Ssam 		if (MASKREG(mbp->mba_bcr) == 0)
85611202Ssam 			return (0);
8573706Sroot 		break;
8583706Sroot 	}
8593706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
860*17071Sralph 	if (rp->hpof & HPOF_SSEI)
8612883Swnj 		sn++;
862420Sbill 	rp->hpdc = cn;
863420Sbill 	rp->hpda = (tn<<8) + sn;
864420Sbill 	mbp->mba_sr = -1;
8653706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
8663706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
8673706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
868*17071Sralph 	sc->sc_pgdone = npf;
869420Sbill 	return (1);
87021Sbill }
8712362Swnj 
8722362Swnj #define	DBSIZE	20
8732362Swnj 
8742362Swnj hpdump(dev)
8752362Swnj 	dev_t dev;
8762362Swnj {
8772978Swnj 	register struct mba_device *mi;
8782383Swnj 	register struct mba_regs *mba;
8792624Swnj 	struct hpdevice *hpaddr;
8802362Swnj 	char *start;
8812383Swnj 	int num, unit;
8822383Swnj 	register struct hpst *st;
8832362Swnj 
8842362Swnj 	num = maxfree;
8852362Swnj 	start = 0;
8862362Swnj 	unit = minor(dev) >> 3;
8872827Swnj 	if (unit >= NHP)
8882827Swnj 		return (ENXIO);
8892383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
8902978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
8912827Swnj 	if (mi == 0 || mi->mi_alive == 0)
8922827Swnj 		return (ENXIO);
8932383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
8943102Swnj 	mba->mba_cr = MBCR_INIT;
8952624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
8963093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
8972624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
8982624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
8993093Swnj 		hpaddr->hpof = HPOF_FMT22;
9002362Swnj 	}
9012383Swnj 	st = &hpst[mi->mi_type];
9022827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
9032827Swnj 		return (EINVAL);
9042362Swnj 	while (num > 0) {
9052383Swnj 		register struct pte *hpte = mba->mba_map;
9062362Swnj 		register int i;
9072383Swnj 		int blk, cn, sn, tn;
9082362Swnj 		daddr_t bn;
9092362Swnj 
9102362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9112362Swnj 		bn = dumplo + btop(start);
9122383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
9132383Swnj 		sn = bn%st->nspc;
9142383Swnj 		tn = sn/st->nsect;
9152383Swnj 		sn = sn%st->nsect;
9162362Swnj 		hpaddr->hpdc = cn;
9172362Swnj 		hpaddr->hpda = (tn << 8) + sn;
9182362Swnj 		for (i = 0; i < blk; i++)
9192362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
9202383Swnj 		mba->mba_sr = -1;
9212383Swnj 		mba->mba_bcr = -(blk*NBPG);
9222383Swnj 		mba->mba_var = 0;
9232624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
9243093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
92516791Skarels 			DELAY(10);
9263093Swnj 		if (hpaddr->hpds&HPDS_ERR)
9272827Swnj 			return (EIO);
9282362Swnj 		start += blk*NBPG;
9292362Swnj 		num -= blk;
9302362Swnj 	}
9312362Swnj 	return (0);
9322362Swnj }
93312506Ssam 
93412506Ssam hpsize(dev)
93512506Ssam 	dev_t dev;
93612506Ssam {
93712506Ssam 	int unit = minor(dev) >> 3;
93812506Ssam 	struct mba_device *mi;
93912506Ssam 	struct hpst *st;
94012506Ssam 
94112506Ssam 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
94212506Ssam 		return (-1);
94312506Ssam 	st = &hpst[mi->mi_type];
94412506Ssam 	return ((int)st->sizes[minor(dev) & 07].nblocks);
94512506Ssam }
9461565Sbill #endif
947