xref: /csrg-svn/sys/vax/mba/hp.c (revision 24187)
123308Smckusick /*
223308Smckusick  * Copyright (c) 1982 Regents of the University of California.
323308Smckusick  * All rights reserved.  The Berkeley software License Agreement
423308Smckusick  * specifies the terms and conditions for redistribution.
523308Smckusick  *
6*24187Skarels  *	@(#)hp.c	6.9 (Berkeley) 08/05/85
723308Smckusick  */
83706Sroot 
93706Sroot #ifdef HPDEBUG
103289Swnj int	hpdebug;
113706Sroot #endif
123706Sroot #ifdef HPBDEBUG
133706Sroot int	hpbdebug;
143706Sroot #endif
1521Sbill 
161939Swnj #include "hp.h"
171565Sbill #if NHP > 0
1821Sbill /*
195726Sroot  * HP disk driver for RP0x+RMxx+ML11
202827Swnj  *
212827Swnj  * TODO:
223706Sroot  *	check RM80 skip sector handling when ECC's occur later
233093Swnj  *	check offset recovery handling
243706Sroot  *	see if DCLR and/or RELEASE set attention status
253706Sroot  *	print bits of mr && mr2 symbolically
2621Sbill  */
279786Ssam #include "../machine/pte.h"
2821Sbill 
2917120Sbloom #include "param.h"
3017120Sbloom #include "systm.h"
3117120Sbloom #include "dk.h"
3217120Sbloom #include "buf.h"
3317120Sbloom #include "conf.h"
3417120Sbloom #include "dir.h"
3517120Sbloom #include "user.h"
3617120Sbloom #include "map.h"
378468Sroot #include "../vax/mtpr.h"
3817120Sbloom #include "vm.h"
3917120Sbloom #include "cmap.h"
4017120Sbloom #include "dkbad.h"
4117120Sbloom #include "ioctl.h"
4217120Sbloom #include "uio.h"
4318411Skarels #include "syslog.h"
4421Sbill 
458988Sroot #include "../vax/dkio.h"
4617120Sbloom #include "mbareg.h"
4717120Sbloom #include "mbavar.h"
4817120Sbloom #include "hpreg.h"
4921Sbill 
502383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
512383Swnj struct	size {
5221Sbill 	daddr_t	nblocks;
5321Sbill 	int	cyloff;
5411212Ssam } rp06_sizes[8] = {
55886Sbill 	15884,	0,		/* A=cyl 0 thru 37 */
56886Sbill 	33440,	38,		/* B=cyl 38 thru 117 */
57886Sbill 	340670,	0,		/* C=cyl 0 thru 814 */
5811212Ssam 	15884,	118,		/* D=cyl 118 thru 155 */
5911212Ssam 	55936,	156,		/* E=cyl 156 thru 289 */
6011212Ssam 	219384,	290,		/* F=cyl 290 thru 814 */
6111212Ssam 	291280,	118,		/* G=cyl 118 thru 814 */
6221Sbill 	0,	0,
6311212Ssam }, rp05_sizes[8] = {
6411212Ssam 	15884,	0,		/* A=cyl 0 thru 37 */
6511212Ssam 	33440,	38,		/* B=cyl 38 thru 117 */
6611212Ssam 	171798,	0,		/* C=cyl 0 thru 410 */
6711212Ssam 	15884,	118,		/* D=cyl 118 thru 155 */
6811212Ssam 	55936,	156,		/* E=cyl 156 thru 289 */
6911212Ssam 	50512,	290,		/* F=cyl 290 thru 410 */
7011212Ssam 	122408,	118,		/* G=cyl 118 thru 410 */
7121Sbill 	0,	0,
7211212Ssam }, rm03_sizes[8] = {
73886Sbill 	15884,	0,		/* A=cyl 0 thru 99 */
7411212Ssam 	33440,	100,		/* B=cyl 100 thru 308 */
75886Sbill 	131680,	0,		/* C=cyl 0 thru 822 */
7611212Ssam 	15884,	309,		/* D=cyl 309 thru 408 */
7711212Ssam 	55936,	409,		/* E=cyl 409 thru 758 */
7811212Ssam 	10144,	759,		/* F=cyl 759 thru 822 */
7911212Ssam 	82144,	309,		/* G=cyl 309 thru 822 */
8021Sbill 	0,	0,
8111212Ssam }, rm05_sizes[8] = {
82886Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
83886Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
843271Swnj 	500384,	0,		/* C=cyl 0 thru 822 */
85886Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
86886Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
873729Sroot 	86240,	681,		/* F=cyl 681 thru 822 */
883729Sroot 	158592,	562,		/* G=cyl 562 thru 822 */
89886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
902383Swnj }, rm80_sizes[8] = {
912383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
922383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
932383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
9411212Ssam 	15884,	115,		/* D=cyl 115 thru 151 */
9511212Ssam 	55936,	152,		/* E=cyl 152 thru 280 */
9611212Ssam 	120559,	281,		/* F=cyl 281 thru 558 */
9711212Ssam 	192603,	115,		/* G=cyl 115 thru 558 */
982383Swnj 	0,	0,
9911212Ssam }, rp07_sizes[8] = {
1006927Ssam 	15884,	0,		/* A=cyl 0 thru 9 */
10111212Ssam 	66880,	10,		/* B=cyl 10 thru 51 */
10211212Ssam 	1008000, 0,		/* C=cyl 0 thru 629 */
10311212Ssam 	15884,	235,		/* D=cyl 235 thru 244 */
10411212Ssam 	307200,	245,		/* E=cyl 245 thru 436 */
10511212Ssam 	308650,	437,		/* F=cyl 437 thru 629 */
10611212Ssam 	631850,	235,		/* G=cyl 235 thru 629 */
10711212Ssam 	291346,	52,		/* H=cyl 52 thru 234 */
10811212Ssam }, cdc9775_sizes[8] = {
10911212Ssam 	15884,	0,		/* A=cyl 0 thru 12 */
11011212Ssam 	66880,	13,		/* B=cyl 13 thru 65 */
11115101Skarels 	1077760, 0,		/* C=cyl 0 thru 841 */
11211212Ssam 	15884,	294,		/* D=cyl 294 thru 306 */
11311212Ssam 	307200,	307,		/* E=cyl 307 thru 546 */
11415101Skarels 	377440,	547,		/* F=cyl 547 thru 841 */
11515101Skarels 	701280,	294,		/* G=cyl 294 thru 841 */
11611212Ssam 	291346,	66,		/* H=cyl 66 thru 293 */
11711212Ssam }, cdc9730_sizes[8] = {
1186927Ssam 	15884,	0,		/* A=cyl 0 thru 49 */
1196927Ssam 	33440,	50,		/* B=cyl 50 thru 154 */
1206927Ssam 	263360,	0,		/* C=cyl 0 thru 822 */
12111212Ssam 	15884,	155,		/* D=cyl 155 thru 204 */
12211212Ssam 	55936,	205,		/* E=cyl 205 thru 379 */
12311212Ssam 	141664,	380,		/* F=cyl 380 thru 822 */
12411212Ssam 	213664,	155,		/* G=cyl 155 thru 822 */
1256927Ssam 	0,	0,
12611212Ssam }, capricorn_sizes[8] = {
1276927Ssam 	15884,	0,		/* A=cyl 0 thru 31 */
1286927Ssam 	33440,	32,		/* B=cyl 32 thru 97 */
1296927Ssam 	524288,	0,		/* C=cyl 0 thru 1023 */
13011212Ssam 	15884,	668,		/* D=cyl 668 thru 699 */
13111212Ssam 	55936,	700,		/* E=cyl 700 thru 809 */
13211212Ssam 	109472,	810,		/* F=cyl 810 thru 1023 */
13311212Ssam 	182176,	668,		/* G=cyl 668 thru 1023 */
1346927Ssam 	291346,	98,		/* H=cyl 98 thru 667 */
13511212Ssam }, eagle_sizes[8] = {
13610734Ssam 	15884,	0,		/* A=cyl 0 thru 16 */
13711212Ssam 	66880,	17,		/* B=cyl 17 thru 86 */
13811629Ssam 	808320,	0,		/* C=cyl 0 thru 841 */
13911212Ssam 	15884,	391,		/* D=cyl 391 thru 407 */
14011212Ssam 	307200,	408,		/* E=cyl 408 thru 727 */
14111629Ssam 	109296,	728,		/* F=cyl 728 thru 841 */
14211629Ssam 	432816,	391,		/* G=cyl 391 thru 841 */
14311212Ssam 	291346,	87,		/* H=cyl 87 thru 390 */
14413202Sroot }, ampex_sizes[8] = {
14511281Ssam 	15884,	0,		/* A=cyl 0 thru 26 */
14611281Ssam 	33440,	27,		/* B=cyl 27 thru 81 */
14713184Shelge 	495520,	0,		/* C=cyl 0 thru 814 */
14811281Ssam 	15884,	562,		/* D=cyl 562 thru 588 */
14911281Ssam 	55936,	589,		/* E=cyl 589 thru 680 */
15013184Shelge 	81312,	681,		/* F=cyl 681 thru 814 */
15113184Shelge 	153664,	562,		/* G=cyl 562 thru 814 */
15211281Ssam 	291346,	82,		/* H=cyl 82 thru 561 */
15321Sbill };
1542383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
15521Sbill 
1566927Ssam /*
1576927Ssam  * Table for converting Massbus drive types into
1586927Ssam  * indices into the partition tables.  Slots are
1596927Ssam  * left for those drives devined from other means
1606927Ssam  * (e.g. SI, AMPEX, etc.).
1616927Ssam  */
1626927Ssam short	hptypes[] = {
1636927Ssam #define	HPDT_RM03	0
1646927Ssam 	MBDT_RM03,
1656927Ssam #define	HPDT_RM05	1
1666927Ssam 	MBDT_RM05,
1676927Ssam #define	HPDT_RP06	2
1686927Ssam 	MBDT_RP06,
1696927Ssam #define	HPDT_RM80	3
1706927Ssam 	MBDT_RM80,
17113157Ssam #define	HPDT_RP04	4
17213157Ssam 	MBDT_RP04,
17313157Ssam #define	HPDT_RP05	5
1746927Ssam 	MBDT_RP05,
17513157Ssam #define	HPDT_RP07	6
1766927Ssam 	MBDT_RP07,
17713157Ssam #define	HPDT_ML11A	7
1786927Ssam 	MBDT_ML11A,
17913157Ssam #define	HPDT_ML11B	8
1806927Ssam 	MBDT_ML11B,
18113157Ssam #define	HPDT_9775	9
1826927Ssam 	-1,
18313157Ssam #define	HPDT_9730	10
1846927Ssam 	-1,
18513157Ssam #define	HPDT_CAPRICORN	11
1866927Ssam 	-1,
18713157Ssam #define HPDT_EAGLE	12
1889175Ssam 	-1,
18913157Ssam #define	HPDT_9300	13
19011281Ssam 	-1,
19113157Ssam #define HPDT_RM02	14
1929175Ssam 	MBDT_RM02,		/* beware, actually capricorn or eagle */
1936927Ssam 	0
1946927Ssam };
1952978Swnj struct	mba_device *hpinfo[NHP];
19614145Shelge int	hpattach(),hpustart(),hpstart(),hpdtint();
1972383Swnj struct	mba_driver hpdriver =
1982978Swnj 	{ hpattach, 0, hpustart, hpstart, hpdtint, 0,
1992978Swnj 	  hptypes, "hp", 0, hpinfo };
2002383Swnj 
20112836Ssam /*
20216225Skarels  * These variable are all measured in sectors.
20316225Skarels  * Sdist is how much to "lead" in the search for a desired sector
20416225Skarels  * (i.e. if want N, search for N-sdist.)
20516225Skarels  * Maxdist and mindist define the region right before our desired sector within
20616225Skarels  * which we don't bother searching.  We don't search when we are already less
20716225Skarels  * then maxdist and more than mindist sectors "before" our desired sector.
20816225Skarels  * Maxdist should be >= sdist.
20916225Skarels  *
21016225Skarels  * Beware, sdist, mindist and maxdist are not well tuned
21112836Ssam  * for many of the drives listed in this table.
21212836Ssam  * Try patching things with something i/o intensive
21312836Ssam  * running and watch iostat.
21412836Ssam  */
2152383Swnj struct hpst {
21612836Ssam 	short	nsect;		/* # sectors/track */
21712836Ssam 	short	ntrak;		/* # tracks/cylinder */
21812836Ssam 	short	nspc;		/* # sector/cylinders */
21912836Ssam 	short	ncyl;		/* # cylinders */
22012836Ssam 	struct	size *sizes;	/* partition tables */
22112836Ssam 	short	sdist;		/* seek distance metric */
22216225Skarels 	short	maxdist;	/* boundaries of non-searched area */
22316225Skarels 	short	mindist;	/* preceding the target sector */
2242383Swnj } hpst[] = {
22516225Skarels     { 32, 5,	32*5,	823,	rm03_sizes,	7, 4, 1 },	/* RM03 */
22616225Skarels     { 32, 19,	32*19,	823,	rm05_sizes,	7, 4, 1 },	/* RM05 */
22716225Skarels     { 22,19,	22*19,	815,	rp06_sizes,	7, 4, 1 },	/* RP06 */
22816225Skarels     { 31, 14, 	31*14,	559,	rm80_sizes,	7, 4, 1 },	/* RM80 */
22916225Skarels     { 22, 19,	22*19,	411,	rp05_sizes,	7, 4, 1 },	/* RP04 */
23016225Skarels     { 22, 19,	22*19,	411,	rp05_sizes,	7, 4, 1 },	/* RP05 */
23116225Skarels     { 50, 32,	50*32,	630,	rp07_sizes,    15, 8, 3 },	/* RP07 */
23216225Skarels     { 1, 1,	1,	1,	0,		0, 0, 0 },	/* ML11A */
23316225Skarels     { 1, 1,	1,	1,	0,		0, 0, 0 },	/* ML11B */
23416225Skarels     { 32, 40,	32*40,	843,	cdc9775_sizes,	7, 4, 1 },	/* 9775 */
23516225Skarels     { 32, 10,	32*10,	823,	cdc9730_sizes,	7, 4, 1 },	/* 9730 */
23616225Skarels     { 32, 16,	32*16,	1024,	capricorn_sizes,10,4, 3 },	/* Capricorn */
23716225Skarels     { 48, 20,	48*20,	842,	eagle_sizes,   15, 8, 3 },	/* EAGLE */
23816225Skarels     { 32, 19,	32*19,	815,	ampex_sizes,	7, 4, 1 },	/* 9300 */
2392383Swnj };
2402383Swnj 
2412624Swnj u_char	hp_offset[16] = {
2423093Swnj     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
2433093Swnj     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
2443093Swnj     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
2453093Swnj     0, 0, 0, 0,
24621Sbill };
24721Sbill 
2482624Swnj struct	buf	rhpbuf[NHP];
2493706Sroot struct	buf	bhpbuf[NHP];
2503706Sroot struct	dkbad	hpbad[NHP];
25121Sbill 
25210857Ssam struct	hpsoftc {
25310857Ssam 	u_char	sc_hpinit;	/* drive initialized */
25410857Ssam 	u_char	sc_recal;	/* recalibrate state */
25510857Ssam 	u_char	sc_hdr;		/* next i/o includes header */
25610857Ssam 	u_char	sc_doseeks;	/* perform explicit seeks */
25710857Ssam 	daddr_t	sc_mlsize;	/* ML11 size */
25817071Sralph 	int	sc_pgdone;	/* amount sucessfully transfered */
25917071Sralph 	daddr_t	sc_badbn;	/* replacement block number */
26010857Ssam } hpsoftc[NHP];
26110857Ssam 
26221Sbill #define	b_cylin b_resid
26321Sbill 
2645726Sroot /* #define ML11 0  to remove ML11 support */
2655726Sroot #define	ML11	(hptypes[mi->mi_type] == MBDT_ML11A)
2665726Sroot #define	RP06	(hptypes[mi->mi_type] <= MBDT_RP06)
2675726Sroot #define	RM80	(hptypes[mi->mi_type] == MBDT_RM80)
2685726Sroot 
26911202Ssam #define	MASKREG(reg)	((reg)&0xffff)
27018411Skarels #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi))
27111202Ssam 
27221Sbill #ifdef INTRLVE
27321Sbill daddr_t dkblock();
27421Sbill #endif
2752604Swnj 
2762978Swnj /*ARGSUSED*/
2772978Swnj hpattach(mi, slave)
27810734Ssam 	register struct mba_device *mi;
2792604Swnj {
28010734Ssam 
28110734Ssam 	mi->mi_type = hpmaptype(mi);
28210734Ssam 	if (!ML11 && mi->mi_dk >= 0) {
28310734Ssam 		struct hpst *st = &hpst[mi->mi_type];
28410734Ssam 
28510734Ssam 		dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256);
28610734Ssam 	}
28710734Ssam }
28810734Ssam 
28910734Ssam /*
29010734Ssam  * Map apparent MASSBUS drive type into manufacturer
29110734Ssam  * specific configuration.  For SI controllers this is done
29210734Ssam  * based on codes in the serial number register.  For
29310734Ssam  * EMULEX controllers, the track and sector attributes are
29410734Ssam  * used when the drive type is an RM02 (not supported by DEC).
29510734Ssam  */
29610734Ssam hpmaptype(mi)
29710734Ssam 	register struct mba_device *mi;
29810734Ssam {
2996927Ssam 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
30010734Ssam 	register int type = mi->mi_type;
3016927Ssam 
3026927Ssam 	/*
30311281Ssam 	 * Model-byte processing for SI controllers.
3046927Ssam 	 * NB:  Only deals with RM03 and RM05 emulations.
3056927Ssam 	 */
30610734Ssam 	if (type == HPDT_RM03 || type == HPDT_RM05) {
30710734Ssam 		int hpsn = hpaddr->hpsn;
3086927Ssam 
3096927Ssam 		if ((hpsn & SIMB_LU) != mi->mi_drive)
31010734Ssam 			return (type);
3116927Ssam 		switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
3126927Ssam 
3136927Ssam 		case SI9775D:
31411281Ssam 			printf("hp%d: 9775 (direct)\n", mi->mi_unit);
31510734Ssam 			type = HPDT_9775;
3166927Ssam 			break;
3176927Ssam 
3186927Ssam 		case SI9730D:
31911281Ssam 			printf("hp%d: 9730 (direct)\n", mi->mi_unit);
32010734Ssam 			type = HPDT_9730;
3216927Ssam 			break;
3226927Ssam 
3237035Swnj 		/*
32411281Ssam 		 * Beware, since the only SI controller we
32511281Ssam 		 * have has a 9300 instead of a 9766, we map the
32611281Ssam 		 * drive type into the 9300.  This means that
32711281Ssam 		 * on a 9766 you lose the last 8 cylinders (argh).
3287035Swnj 		 */
3296927Ssam 		case SI9766:
33011281Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
33111281Ssam 			type = HPDT_9300;
3326927Ssam 			break;
3336927Ssam 
3346927Ssam 		case SI9762:
3356927Ssam 			printf("hp%d: 9762\n", mi->mi_unit);
33610734Ssam 			type = HPDT_RM03;
3376927Ssam 			break;
33811281Ssam 
33911281Ssam 		case SICAPD:
34011281Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
34111281Ssam 			type = HPDT_CAPRICORN;
34211281Ssam 			break;
34311281Ssam 
34411281Ssam 		case SI9751D:
34511281Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
34611281Ssam 			type = HPDT_EAGLE;
34711281Ssam 			break;
3486927Ssam 		}
34910734Ssam 		return (type);
35010734Ssam 	}
3516927Ssam 
3526927Ssam 	/*
35310734Ssam 	 * EMULEX SC750 or SC780.  Poke the holding register.
3546927Ssam 	 */
35510734Ssam 	if (type == HPDT_RM02) {
35610734Ssam 		int ntracks, nsectors;
35710734Ssam 
35811315Ssam 		hpaddr->hpof = HPOF_FMT22;
35911315Ssam 		mbclrattn(mi);
3606927Ssam 		hpaddr->hpcs1 = HP_NOP;
3616927Ssam 		hpaddr->hphr = HPHR_MAXTRAK;
36211202Ssam 		ntracks = MASKREG(hpaddr->hphr) + 1;
36310055Ssam 		if (ntracks == 16) {
3646927Ssam 			printf("hp%d: capricorn\n", mi->mi_unit);
36510734Ssam 			type = HPDT_CAPRICORN;
36610734Ssam 			goto done;
36710734Ssam 		}
36813157Ssam 		if (ntracks == 19) {
36913157Ssam 			printf("hp%d: 9300\n", mi->mi_unit);
37013157Ssam 			type = HPDT_9300;
37113157Ssam 			goto done;
37213157Ssam 		}
37310734Ssam 		hpaddr->hpcs1 = HP_NOP;
37410734Ssam 		hpaddr->hphr = HPHR_MAXSECT;
37511202Ssam 		nsectors = MASKREG(hpaddr->hphr) + 1;
37611315Ssam 		if (ntracks == 20 && nsectors == 48) {
37710734Ssam 			type = HPDT_EAGLE;
37811212Ssam 			printf("hp%d: eagle\n", mi->mi_unit);
37911315Ssam 			goto done;
38010734Ssam 		}
38111315Ssam 		printf("hp%d: ntracks %d, nsectors %d: unknown device\n",
38213157Ssam 			mi->mi_unit, ntracks, nsectors);
38310734Ssam done:
3846927Ssam 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
38511315Ssam 		mbclrattn(mi);		/* conservative */
38610734Ssam 		return (type);
38710734Ssam 	}
3886927Ssam 
38910734Ssam 	/*
39010734Ssam 	 * Map all ML11's to the same type.  Also calculate
39110734Ssam 	 * transfer rates based on device characteristics.
39210734Ssam 	 */
39310734Ssam 	if (type == HPDT_ML11A || type == HPDT_ML11B) {
39410857Ssam 		register struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
39510857Ssam 		register int trt;
3962604Swnj 
39710857Ssam 		sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
3985726Sroot 		if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
39910857Ssam 			sc->sc_mlsize >>= 2;
4005726Sroot 		if (mi->mi_dk >= 0) {
4015726Sroot 			trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
4025726Sroot 			dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt));
4035726Sroot 		}
40410734Ssam 		type = HPDT_ML11A;
4056927Ssam 	}
40610734Ssam 	return (type);
4072604Swnj }
4082604Swnj 
4098579Sroot hpopen(dev)
4108579Sroot 	dev_t dev;
4118579Sroot {
4128579Sroot 	register int unit = minor(dev) >> 3;
4138579Sroot 	register struct mba_device *mi;
4148579Sroot 
4158579Sroot 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
4168579Sroot 		return (ENXIO);
4178579Sroot 	return (0);
4188579Sroot }
4198579Sroot 
42021Sbill hpstrategy(bp)
4212383Swnj 	register struct buf *bp;
42221Sbill {
4232978Swnj 	register struct mba_device *mi;
4242383Swnj 	register struct hpst *st;
4252383Swnj 	register int unit;
42621Sbill 	long sz, bn;
4272383Swnj 	int xunit = minor(bp->b_dev) & 07;
4285432Sroot 	int s;
42921Sbill 
43021Sbill 	sz = bp->b_bcount;
43121Sbill 	sz = (sz+511) >> 9;
43221Sbill 	unit = dkunit(bp);
4332383Swnj 	if (unit >= NHP)
4342383Swnj 		goto bad;
4352383Swnj 	mi = hpinfo[unit];
4362395Swnj 	if (mi == 0 || mi->mi_alive == 0)
4372383Swnj 		goto bad;
4382383Swnj 	st = &hpst[mi->mi_type];
4395726Sroot 	if (ML11) {
44010857Ssam 		struct hpsoftc *sc = &hpsoftc[unit];
44110857Ssam 
4425726Sroot 		if (bp->b_blkno < 0 ||
44310857Ssam 		    dkblock(bp)+sz > sc->sc_mlsize)
4445726Sroot 			goto bad;
4455726Sroot 		bp->b_cylin = 0;
4465726Sroot 	} else {
4475726Sroot 		if (bp->b_blkno < 0 ||
4485726Sroot 		    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
4495726Sroot 			goto bad;
4505726Sroot 		bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
4515726Sroot 	}
4525432Sroot 	s = spl5();
4532383Swnj 	disksort(&mi->mi_tab, bp);
4542383Swnj 	if (mi->mi_tab.b_active == 0)
4552383Swnj 		mbustart(mi);
4565432Sroot 	splx(s);
4572383Swnj 	return;
4582383Swnj 
4592383Swnj bad:
4602383Swnj 	bp->b_flags |= B_ERROR;
4612383Swnj 	iodone(bp);
4622383Swnj 	return;
46321Sbill }
46421Sbill 
4652383Swnj hpustart(mi)
4662978Swnj 	register struct mba_device *mi;
46721Sbill {
4682624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4692383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
47011315Ssam 	register struct hpst *st;
47110857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
47221Sbill 	daddr_t bn;
47316791Skarels 	int sn, tn, dist;
47421Sbill 
47511315Ssam 	st = &hpst[mi->mi_type];
4763706Sroot 	hpaddr->hpcs1 = 0;
4772624Swnj 	if ((hpaddr->hpcs1&HP_DVA) == 0)
4782383Swnj 		return (MBU_BUSY);
47910857Ssam 	if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) {
4803706Sroot 		struct buf *bbp = &bhpbuf[mi->mi_unit];
4813706Sroot 
48210857Ssam 		sc->sc_hpinit = 1;
4832624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
4843140Swnj 		if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
4853140Swnj 			printf("DCLR attn\n");
4862624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
4875726Sroot 		if (!ML11)
4885726Sroot 			hpaddr->hpof = HPOF_FMT22;
4893140Swnj 		mbclrattn(mi);
4905726Sroot 		if (!ML11) {
4915726Sroot 			bbp->b_flags = B_READ|B_BUSY;
4925726Sroot 			bbp->b_dev = bp->b_dev;
4935726Sroot 			bbp->b_bcount = 512;
4945726Sroot 			bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit];
4955726Sroot 			bbp->b_blkno = st->ncyl*st->nspc - st->nsect;
4965726Sroot 			bbp->b_cylin = st->ncyl - 1;
4975726Sroot 			mi->mi_tab.b_actf = bbp;
4985726Sroot 			bbp->av_forw = bp;
4995726Sroot 			bp = bbp;
5005726Sroot 		}
50121Sbill 	}
5022604Swnj 	if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1)
5032383Swnj 		return (MBU_DODATA);
5045726Sroot 	if (ML11)
5055726Sroot 		return (MBU_DODATA);
5063093Swnj 	if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
5072383Swnj 		return (MBU_DODATA);
5082395Swnj 	bn = dkblock(bp);
50916791Skarels 	sn = bn % st->nspc;
51016791Skarels 	tn = sn / st->nsect;
51116791Skarels 	sn = sn % st->nsect;
51211202Ssam 	if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
51310908Ssam 		if (sc->sc_doseeks)
5142383Swnj 			return (MBU_DODATA);
51516225Skarels 		dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1;
5162383Swnj 		if (dist < 0)
5172383Swnj 			dist += st->nsect;
51816225Skarels 		if (dist > st->maxdist || dist < st->mindist)
5192383Swnj 			return (MBU_DODATA);
5202614Swnj 	} else
5212614Swnj 		hpaddr->hpdc = bp->b_cylin;
52210908Ssam 	if (sc->sc_doseeks)
5232624Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
524305Sbill 	else {
52516225Skarels 		sn = (sn + st->nsect - st->sdist) % st->nsect;
52616791Skarels 		hpaddr->hpda = (tn << 8) + sn;
5272624Swnj 		hpaddr->hpcs1 = HP_SEARCH|HP_GO;
528305Sbill 	}
5292383Swnj 	return (MBU_STARTED);
53021Sbill }
53121Sbill 
5322383Swnj hpstart(mi)
5332978Swnj 	register struct mba_device *mi;
53421Sbill {
5352624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5362383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
5372383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
53810857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
53921Sbill 	daddr_t bn;
5402383Swnj 	int sn, tn;
54121Sbill 
54217071Sralph 	if (bp->b_flags & B_BAD)
54317071Sralph 		bn = sc->sc_badbn;
54417071Sralph 	else
54517071Sralph 		bn = dkblock(bp) + sc->sc_pgdone;
5465726Sroot 	if (ML11)
5475726Sroot 		hpaddr->hpda = bn;
5485726Sroot 	else {
5495726Sroot 		sn = bn%st->nspc;
5505726Sroot 		tn = sn/st->nsect;
5515726Sroot 		sn %= st->nsect;
5525726Sroot 		hpaddr->hpdc = bp->b_cylin;
5535726Sroot 		hpaddr->hpda = (tn << 8) + sn;
5545726Sroot 	}
55510857Ssam 	if (sc->sc_hdr) {
5565726Sroot 		if (bp->b_flags & B_READ)
5575726Sroot 			return (HP_RHDR|HP_GO);
5585726Sroot 		else
5595726Sroot 			return (HP_WHDR|HP_GO);
5605726Sroot 	}
5615726Sroot 	return (0);
56221Sbill }
56321Sbill 
5643102Swnj hpdtint(mi, mbsr)
5652978Swnj 	register struct mba_device *mi;
5663102Swnj 	int mbsr;
56721Sbill {
5682624Swnj 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5692383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
57011315Ssam 	register struct hpst *st;
5715893Swnj 	register int er1, er2;
57210857Ssam 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
57318411Skarels 	int retry = 0, i;
57421Sbill 
57511315Ssam 	st = &hpst[mi->mi_type];
5763102Swnj 	if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
57714145Shelge 		er1 = hpaddr->hper1;
57814145Shelge 		er2 = hpaddr->hper2;
57918411Skarels 		if (HPWAIT(mi, hpaddr) == 0)
58018411Skarels 			goto hard;
5813706Sroot #ifdef HPDEBUG
5823289Swnj 		if (hpdebug) {
5833706Sroot 			int dc = hpaddr->hpdc, da = hpaddr->hpda;
5843706Sroot 
58518411Skarels 			printf("hperr: bp %x cyl %d blk %d pgdone %d as %o ",
58618411Skarels 				bp, bp->b_cylin, bp->b_blkno, sc->sc_pgdone,
5873706Sroot 				hpaddr->hpas&0xff);
58811202Ssam 			printf("dc %x da %x\n",MASKREG(dc), MASKREG(da));
5893289Swnj 			printf("errcnt %d ", mi->mi_tab.b_errcnt);
5903289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
59114145Shelge 			printf("er1=%b er2=%b\n", MASKREG(er1), HPER1_BITS,
59214145Shelge 			    MASKREG(er2), HPER2_BITS);
5933289Swnj 			DELAY(1000000);
5943289Swnj 		}
5953706Sroot #endif
5965893Swnj 		if (er1 & HPER1_HCRC) {
5975858Swnj 			er1 &= ~(HPER1_HCE|HPER1_FER);
5985893Swnj 			er2 &= ~HPER2_BSE;
5995893Swnj 		}
60016791Skarels 		if (er1 & HPER1_WLE) {
60118411Skarels 			log(KERN_RECOV, "hp%d: write locked\n", dkunit(bp));
6022826Swnj 			bp->b_flags |= B_ERROR;
60316791Skarels 		} else if (sc->sc_hdr) {
60416791Skarels 			goto hard;
60517071Sralph 		} else if (RM80 && er2&HPER2_SSE) {
60617071Sralph 			(void) hpecc(mi, SSE);
60717071Sralph 			return (MBD_RESTARTED);
60816791Skarels 		} else if ((er2 & HPER2_BSE) && !ML11) {
6095726Sroot 			if (hpecc(mi, BSE))
61011202Ssam 				return (MBD_RESTARTED);
61111202Ssam 			goto hard;
61216791Skarels 		} else if (MASKREG(er1) == HPER1_FER && RP06) {
61316791Skarels 			if (hpecc(mi, BSE))
61416791Skarels 				return (MBD_RESTARTED);
61516791Skarels 			goto hard;
61617071Sralph 		} else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK &&
61717071Sralph 		    mi->mi_tab.b_errcnt > 7) {
61816791Skarels 			if (hpecc(mi, ECC))
61916791Skarels 				return (MBD_RESTARTED);
62016791Skarels 			/* else done */
6212826Swnj 		} else if (++mi->mi_tab.b_errcnt > 27 ||
62216791Skarels 		    (ML11 && mi->mi_tab.b_errcnt > 15) ||
6233102Swnj 		    mbsr & MBSR_HARD ||
6245858Swnj 		    er1 & HPER1_HARD ||
6255893Swnj 		    (!ML11 && (er2 & HPER2_HARD))) {
62610886Shelge  			/*
62714134Shelge  			 * HCRC means the header is screwed up and the sector
62814134Shelge  			 * might well exist in the bad sector table,
62914134Shelge 			 * better check....
63010886Shelge  			 */
63116791Skarels  			if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE))
63211202Ssam 				return (MBD_RESTARTED);
6333706Sroot hard:
63417071Sralph 			if (bp->b_flags & B_BAD)
63517071Sralph 				bp->b_blkno = sc->sc_badbn;
63618411Skarels 			else {
63718411Skarels 				bp->b_blkno = dkblock(bp) + btop(bp->b_bcount -
63818411Skarels 				    MASKREG(-mi->mi_mba->mba_bcr));
63918411Skarels 				if (er1 & (HPER1_DCK | HPER1_ECH))
64018411Skarels 					bp->b_blkno--;
64118411Skarels 			}
6422925Swnj 			harderr(bp, "hp");
6433271Swnj 			if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
6443271Swnj 				printf("mbsr=%b ", mbsr, mbsr_bits);
6453706Sroot 			printf("er1=%b er2=%b",
64614145Shelge 			    MASKREG(hpaddr->hper1), HPER1_BITS,
64714145Shelge 			    MASKREG(hpaddr->hper2), HPER2_BITS);
6483706Sroot 			if (hpaddr->hpmr)
64911202Ssam 				printf(" mr=%o", MASKREG(hpaddr->hpmr));
6503706Sroot 			if (hpaddr->hpmr2)
65111202Ssam 				printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
65214134Shelge 			if (sc->sc_hdr)
65314134Shelge 				printf(" (hdr i/o)");
6543706Sroot 			printf("\n");
6552826Swnj 			bp->b_flags |= B_ERROR;
65617071Sralph 			bp->b_flags &= ~B_BAD;
6572826Swnj 		} else
6582826Swnj 			retry = 1;
6592826Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
66016791Skarels 		if ((mi->mi_tab.b_errcnt & 07) == 4) {
6612826Swnj 			hpaddr->hpcs1 = HP_RECAL|HP_GO;
66210857Ssam 			sc->sc_recal = 1;
66311202Ssam 			return (MBD_RESTARTED);
66421Sbill 		}
6652826Swnj 	}
6663706Sroot #ifdef HPDEBUG
6673289Swnj 	else
66810857Ssam 		if (hpdebug && sc->sc_recal) {
66910857Ssam 			printf("recal %d ", sc->sc_recal);
6703289Swnj 			printf("errcnt %d\n", mi->mi_tab.b_errcnt);
6713289Swnj 			printf("mbsr=%b ", mbsr, mbsr_bits);
6723289Swnj 			printf("er1=%b er2=%b\n",
6733289Swnj 			    hpaddr->hper1, HPER1_BITS,
6743289Swnj 			    hpaddr->hper2, HPER2_BITS);
6753289Swnj 		}
6763706Sroot #endif
67718411Skarels 	HPWAIT(mi, hpaddr);
67810857Ssam 	switch (sc->sc_recal) {
6793093Swnj 
6803093Swnj 	case 1:
6813093Swnj 		hpaddr->hpdc = bp->b_cylin;
6823093Swnj 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
68310857Ssam 		sc->sc_recal++;
6843706Sroot 		return (MBD_RESTARTED);
6853093Swnj 	case 2:
68616791Skarels 		retry = 1;
68716791Skarels 		break;
68816791Skarels 	}
68916791Skarels 	sc->sc_recal = 0;
69016791Skarels 	if (retry) {
69116791Skarels 		if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) {
69216791Skarels 			hpaddr->hpof =
69316791Skarels 			    hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
69416791Skarels 			hpaddr->hpcs1 = HP_OFFSET|HP_GO;
69518411Skarels 			HPWAIT(mi, hpaddr);
69616791Skarels 			mbclrattn(mi);
69716791Skarels 		}
6982892Swnj 		return (MBD_RETRY);
6992892Swnj 	}
7003640Swnj 	if (mi->mi_tab.b_errcnt >= 16) {
7013093Swnj 		/*
7023093Swnj 		 * This is fast and occurs rarely; we don't
7033093Swnj 		 * bother with interrupts.
7043093Swnj 		 */
7052624Swnj 		hpaddr->hpcs1 = HP_RTC|HP_GO;
70618411Skarels 		HPWAIT(mi, hpaddr);
7072383Swnj 		mbclrattn(mi);
70821Sbill 	}
70917071Sralph 	if ((bp->b_flags & B_BAD) && hpecc(mi, CONT))
71017071Sralph 		return (MBD_RESTARTED);
71117071Sralph 	sc->sc_hdr = 0;
71217071Sralph 	sc->sc_pgdone = 0;
71317071Sralph 	bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr);
7145726Sroot 	if (!ML11) {
7155726Sroot 		hpaddr->hpof = HPOF_FMT22;
7165726Sroot 		hpaddr->hpcs1 = HP_RELEASE|HP_GO;
7175726Sroot 	}
7182383Swnj 	return (MBD_DONE);
71921Sbill }
72021Sbill 
72118411Skarels /*
72218411Skarels  * Wait (for a bit) for a drive to come ready;
72318411Skarels  * returns nonzero on success.
72418411Skarels  */
72518411Skarels hpwait(mi)
72618411Skarels 	register struct mba_device *mi;
72718411Skarels {
72818411Skarels 	register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
72918411Skarels 	register i = 100000;
73018411Skarels 
73118411Skarels 	while ((hpaddr->hpds & HPDS_DRY) == 0 && --i)
73218411Skarels 		DELAY(10);
73318411Skarels 	if (i == 0)
73418411Skarels 		printf("hp%d: intr, not ready\n", mi->mi_unit);
73518411Skarels 	return (i);
73618411Skarels }
73718411Skarels 
7387738Sroot hpread(dev, uio)
7392624Swnj 	dev_t dev;
7407738Sroot 	struct uio *uio;
74121Sbill {
7422624Swnj 	register int unit = minor(dev) >> 3;
74321Sbill 
7442624Swnj 	if (unit >= NHP)
7458156Sroot 		return (ENXIO);
7468156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio));
74721Sbill }
74821Sbill 
7497831Sroot hpwrite(dev, uio)
7502624Swnj 	dev_t dev;
7517831Sroot 	struct uio *uio;
75221Sbill {
7532624Swnj 	register int unit = minor(dev) >> 3;
75421Sbill 
7552624Swnj 	if (unit >= NHP)
7568156Sroot 		return (ENXIO);
7578156Sroot 	return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio));
75821Sbill }
75921Sbill 
7605726Sroot /*ARGSUSED*/
7617635Ssam hpioctl(dev, cmd, data, flag)
7625726Sroot 	dev_t dev;
7635726Sroot 	int cmd;
7647635Ssam 	caddr_t data;
7655726Sroot 	int flag;
7665726Sroot {
7675726Sroot 
7685726Sroot 	switch (cmd) {
7697635Ssam 
7705726Sroot 	case DKIOCHDR:	/* do header read/write */
77110857Ssam 		hpsoftc[minor(dev) >> 3].sc_hdr = 1;
7728579Sroot 		return (0);
7735726Sroot 
7745726Sroot 	default:
7758579Sroot 		return (ENXIO);
7765726Sroot 	}
7775726Sroot }
7785726Sroot 
7793706Sroot hpecc(mi, flag)
7802978Swnj 	register struct mba_device *mi;
7813706Sroot 	int flag;
78221Sbill {
7832383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
7842624Swnj 	register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
7852383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
7863706Sroot 	register struct hpst *st = &hpst[mi->mi_type];
78717071Sralph 	struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
7883706Sroot 	int npf, o;
7892383Swnj 	int bn, cn, tn, sn;
790914Sbill 	int bcr;
79121Sbill 
79218411Skarels 	bcr = MASKREG(-mbp->mba_bcr);
79317071Sralph 	if (bp->b_flags & B_BAD)
7943706Sroot 		npf = bp->b_error;
7953706Sroot 	else
79618411Skarels 		npf = btop(bp->b_bcount - bcr);
797420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
79818411Skarels 	bn = dkblock(bp);
799420Sbill 	cn = bp->b_cylin;
80018411Skarels 	sn = bn%(st->nspc) + npf;
8012383Swnj 	tn = sn/st->nsect;
8022383Swnj 	sn %= st->nsect;
8032383Swnj 	cn += tn/st->ntrak;
8042383Swnj 	tn %= st->ntrak;
805*24187Skarels 	bn += npf;
8063706Sroot 	switch (flag) {
80710856Ssam 	case ECC: {
8083706Sroot 		register int i;
8093706Sroot 		caddr_t addr;
8103706Sroot 		struct pte mpte;
8113706Sroot 		int bit, byte, mask;
8123706Sroot 
8133706Sroot 		npf--;		/* because block in error is previous block */
81418411Skarels 		bn--;
81517071Sralph 		if (bp->b_flags & B_BAD)
81617071Sralph 			bn = sc->sc_badbn;
81718411Skarels 		log(KERN_RECOV, "hp%d%c: soft ecc sn%d\n", dkunit(bp),
81817071Sralph 		    'a'+(minor(bp->b_dev)&07), bn);
81911202Ssam 		mask = MASKREG(rp->hpec2);
82011202Ssam 		i = MASKREG(rp->hpec1) - 1;		/* -1 makes 0 origin */
8213706Sroot 		bit = i&07;
8223706Sroot 		i = (i&~07)>>3;
8233706Sroot 		byte = i + o;
8243706Sroot 		while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
8253706Sroot 			mpte = mbp->mba_map[npf+btop(byte)];
8263706Sroot 			addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
8273706Sroot 			putmemc(addr, getmemc(addr)^(mask<<bit));
8283706Sroot 			byte++;
8293706Sroot 			i++;
8303706Sroot 			bit -= 8;
8313706Sroot 		}
83218411Skarels 		if (bcr == 0)
8333706Sroot 			return (0);
8343847Sroot 		npf++;
8353706Sroot 		break;
8363706Sroot 		}
8373706Sroot 
8383706Sroot 	case SSE:
8393706Sroot 		rp->hpof |= HPOF_SSEI;
84017071Sralph 		if (bp->b_flags & B_BAD) {
84117071Sralph 			bn = sc->sc_badbn;
84217071Sralph 			goto fixregs;
84317071Sralph 		}
8443706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
8453706Sroot 		break;
8463706Sroot 
8473706Sroot 	case BSE:
84817071Sralph  		if (rp->hpof & HPOF_SSEI)
84917071Sralph  			sn++;
8503706Sroot #ifdef HPBDEBUG
8513706Sroot 		if (hpbdebug)
8523706Sroot 		printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
8533706Sroot #endif
85417071Sralph 		if (bp->b_flags & B_BAD)
85517071Sralph 			return (0);
8563706Sroot 		if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
85711202Ssam 			return (0);
8583706Sroot 		bp->b_flags |= B_BAD;
8593706Sroot 		bp->b_error = npf + 1;
86017071Sralph  		rp->hpof &= ~HPOF_SSEI;
8613706Sroot 		bn = st->ncyl*st->nspc - st->nsect - 1 - bn;
86217071Sralph 		sc->sc_badbn = bn;
86317071Sralph 	fixregs:
8643706Sroot 		cn = bn/st->nspc;
8653706Sroot 		sn = bn%st->nspc;
8663706Sroot 		tn = sn/st->nsect;
8673706Sroot 		sn %= st->nsect;
8683706Sroot 		mbp->mba_bcr = -512;
8693706Sroot #ifdef HPBDEBUG
8703706Sroot 		if (hpbdebug)
8713706Sroot 		printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
8723706Sroot #endif
8733706Sroot 		break;
8743706Sroot 
8753706Sroot 	case CONT:
8763706Sroot #ifdef HPBDEBUG
8773706Sroot 		if (hpbdebug)
8783706Sroot 		printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
8793706Sroot #endif
8803706Sroot 		bp->b_flags &= ~B_BAD;
8813706Sroot 		mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
88211202Ssam 		if (MASKREG(mbp->mba_bcr) == 0)
88311202Ssam 			return (0);
8843706Sroot 		break;
8853706Sroot 	}
8863706Sroot 	rp->hpcs1 = HP_DCLR|HP_GO;
88717071Sralph 	if (rp->hpof & HPOF_SSEI)
8882883Swnj 		sn++;
889420Sbill 	rp->hpdc = cn;
890420Sbill 	rp->hpda = (tn<<8) + sn;
891420Sbill 	mbp->mba_sr = -1;
8923706Sroot 	mbp->mba_var = (int)ptob(npf) + o;
8933706Sroot 	rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
8943706Sroot 	mi->mi_tab.b_errcnt = 0;	/* error has been corrected */
89517071Sralph 	sc->sc_pgdone = npf;
896420Sbill 	return (1);
89721Sbill }
8982362Swnj 
8992362Swnj #define	DBSIZE	20
9002362Swnj 
9012362Swnj hpdump(dev)
9022362Swnj 	dev_t dev;
9032362Swnj {
9042978Swnj 	register struct mba_device *mi;
9052383Swnj 	register struct mba_regs *mba;
9062624Swnj 	struct hpdevice *hpaddr;
9072362Swnj 	char *start;
9082383Swnj 	int num, unit;
9092383Swnj 	register struct hpst *st;
9102362Swnj 
9112362Swnj 	num = maxfree;
9122362Swnj 	start = 0;
9132362Swnj 	unit = minor(dev) >> 3;
9142827Swnj 	if (unit >= NHP)
9152827Swnj 		return (ENXIO);
9162383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
9172978Swnj 	mi = phys(hpinfo[unit],struct mba_device *);
9182827Swnj 	if (mi == 0 || mi->mi_alive == 0)
9192827Swnj 		return (ENXIO);
9202383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
9213102Swnj 	mba->mba_cr = MBCR_INIT;
9222624Swnj 	hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
9233093Swnj 	if ((hpaddr->hpds & HPDS_VV) == 0) {
9242624Swnj 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
9252624Swnj 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
9263093Swnj 		hpaddr->hpof = HPOF_FMT22;
9272362Swnj 	}
9282383Swnj 	st = &hpst[mi->mi_type];
9292827Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks)
9302827Swnj 		return (EINVAL);
9312362Swnj 	while (num > 0) {
9322383Swnj 		register struct pte *hpte = mba->mba_map;
9332362Swnj 		register int i;
9342383Swnj 		int blk, cn, sn, tn;
9352362Swnj 		daddr_t bn;
9362362Swnj 
9372362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
9382362Swnj 		bn = dumplo + btop(start);
9392383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
9402383Swnj 		sn = bn%st->nspc;
9412383Swnj 		tn = sn/st->nsect;
9422383Swnj 		sn = sn%st->nsect;
9432362Swnj 		hpaddr->hpdc = cn;
9442362Swnj 		hpaddr->hpda = (tn << 8) + sn;
9452362Swnj 		for (i = 0; i < blk; i++)
9462362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
9472383Swnj 		mba->mba_sr = -1;
9482383Swnj 		mba->mba_bcr = -(blk*NBPG);
9492383Swnj 		mba->mba_var = 0;
9502624Swnj 		hpaddr->hpcs1 = HP_WCOM | HP_GO;
9513093Swnj 		while ((hpaddr->hpds & HPDS_DRY) == 0)
95216791Skarels 			DELAY(10);
9533093Swnj 		if (hpaddr->hpds&HPDS_ERR)
9542827Swnj 			return (EIO);
9552362Swnj 		start += blk*NBPG;
9562362Swnj 		num -= blk;
9572362Swnj 	}
9582362Swnj 	return (0);
9592362Swnj }
96012506Ssam 
96112506Ssam hpsize(dev)
96212506Ssam 	dev_t dev;
96312506Ssam {
96412506Ssam 	int unit = minor(dev) >> 3;
96512506Ssam 	struct mba_device *mi;
96612506Ssam 	struct hpst *st;
96712506Ssam 
96812506Ssam 	if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
96912506Ssam 		return (-1);
97012506Ssam 	st = &hpst[mi->mi_type];
97112506Ssam 	return ((int)st->sizes[minor(dev) & 07].nblocks);
97212506Ssam }
9731565Sbill #endif
974