xref: /csrg-svn/sys/vax/stand/hp.c (revision 34982)
123225Smckusick /*
233409Skarels  * Copyright (c) 1982, 1986 Regents of the University of California.
323225Smckusick  * All rights reserved.  The Berkeley software License Agreement
423225Smckusick  * specifies the terms and conditions for redistribution.
523225Smckusick  *
6*34982Skarels  *	@(#)hp.c	7.10 (Berkeley) 07/08/88
723225Smckusick  */
810334Shelge 
910334Shelge /*
1033545Sbostic  * RP??/RM?? disk driver with ECC handling and bad block forwarding.
1133545Sbostic  * Also supports header io operations and commands to write check
1233545Sbostic  * header and data.
1310334Shelge  */
1433409Skarels #include "param.h"
1533409Skarels #include "inode.h"
1633409Skarels #include "fs.h"
1733409Skarels #include "dkbad.h"
1833409Skarels #include "disklabel.h"
1910334Shelge 
2010334Shelge #include "../vax/pte.h"
2133409Skarels 
2210334Shelge #include "../vaxmba/hpreg.h"
2310334Shelge #include "../vaxmba/mbareg.h"
2410334Shelge 
2510334Shelge #include "saio.h"
2610334Shelge #include "savax.h"
2710334Shelge 
2825439Skarels #define	RETRIES		27
2925439Skarels 
3010334Shelge #define	MASKREG(reg)	((reg)&0xffff)
3110334Shelge 
3211366Ssam #define	MAXBADDESC	126
3311366Ssam #define	SECTSIZ 	512	/* sector size in bytes */
3411366Ssam #define	HDRSIZ		4	/* number of bytes in sector header */
3510334Shelge 
3630547Skarels char	lbuf[SECTSIZ];
3710334Shelge 
3830547Skarels #define	RP06(type) ((type) == MBDT_RP06 || (type) == MBDT_RP05 \
3930547Skarels 	|| (type) == MBDT_RP04)
4030547Skarels #define	ML11(type) ((type) == MBDT_ML11A)
4130547Skarels #define	RM80(type) ((type) == MBDT_RM80)
4210334Shelge 
4310334Shelge u_char	hp_offset[16] = {
4433545Sbostic 	HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
4533545Sbostic 	HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
4633545Sbostic 	HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
4733545Sbostic 	0, 0, 0, 0,
4810334Shelge };
4910334Shelge 
5033545Sbostic #define	MAXUNIT		8
5133545Sbostic struct	disklabel hplabel[MAXNMBA][MAXUNIT];
5230547Skarels #ifndef SMALL
5333545Sbostic struct	dkbad hpbad[MAXNMBA][MAXUNIT];
5430547Skarels int	sectsiz;
5530547Skarels #endif
5610334Shelge 
5725439Skarels struct	hp_softc {
5825439Skarels 	char	type;
5925439Skarels 	char	gottype;
6033545Sbostic 	char	ssect;			/* 1 when on track w/skip sector */
6125439Skarels 	char	debug;
6225439Skarels #	define	HPF_BSEDEBUG	01	/* debugging bad sector forwarding */
6325439Skarels #	define	HPF_ECCDEBUG	02	/* debugging ecc correction */
6425439Skarels 	int	ecclim;
6525439Skarels 	int	retries;
6633545Sbostic } hp_softc[MAXNMBA][MAXUNIT];
6711366Ssam 
6810864Ssam /*
6933545Sbostic  * When awaiting command completion, don't hang on to the status register
7033545Sbostic  * since this ties up some controllers.
7110864Ssam  */
7211366Ssam #define	HPWAIT(addr) \
7333545Sbostic 	while ((((addr)->hpds)&HPDS_DRY) == 0) \
7433545Sbostic 		DELAY(500);
7510864Ssam 
7610334Shelge hpopen(io)
7710334Shelge 	register struct iob *io;
7810334Shelge {
7910334Shelge 	register unit = io->i_unit;
8033545Sbostic 	register struct hp_softc *sc;
8133545Sbostic 	register struct disklabel *lp;
8233545Sbostic 	struct hpdevice *hpaddr;
8333041Skarels 	struct disklabel *dlp;
8434519Skarels 	int error = 0;
8510334Shelge 
86*34982Skarels 	/*
87*34982Skarels 	 * Accept adaptor number as either controller or adaptor,
88*34982Skarels 	 * but not both.
89*34982Skarels 	 */
90*34982Skarels 	if (io->i_ctlr) {
91*34982Skarels 		if (io->i_adapt == 0)
92*34982Skarels 			io->i_adapt = io->i_ctlr;
93*34982Skarels 		else
94*34982Skarels 			return (ECTLR);
95*34982Skarels 	}
9633545Sbostic 	if ((u_int)io->i_adapt >= MAXNMBA || !mbainit(io->i_adapt))
9733545Sbostic 		return (EADAPT);
9833545Sbostic 	if ((u_int)unit >= MAXUNIT)
9933545Sbostic 		return (EUNIT);
10033545Sbostic 	hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit);
10133545Sbostic 	sc = &hp_softc[io->i_adapt][unit];
10233545Sbostic 	lp = &hplabel[io->i_adapt][unit];
10325439Skarels 	if (sc->gottype == 0) {
10433545Sbostic 		register int i;
10510334Shelge 		struct iob tio;
10610334Shelge 
10730547Skarels #ifndef SMALL
10825439Skarels 		sc->retries = RETRIES;
10925439Skarels 		sc->ecclim = 11;
11025439Skarels 		sc->debug = 0;
11130547Skarels #endif
11210647Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;		/* init drive */
11310647Shelge 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
11430547Skarels #ifndef SMALL
11533547Sbostic 		if ((hpaddr->hpds & HPDS_DPR) == 0)
11633409Skarels 			return (ENXIO);
11730547Skarels 		sc->type = hpaddr->hpdt & MBDT_TYPE;
11830547Skarels 		if (sc->type == MBDT_ML11B)
11933409Skarels 			sc->type = MBDT_ML11A;
12030547Skarels 		if (!ML11(sc->type))
12130547Skarels #endif
12210647Shelge 			hpaddr->hpof = HPOF_FMT22;
12310334Shelge 		/*
12430547Skarels 		 * Read in the pack label.
12530547Skarels 		 */
12630547Skarels 		lp->d_nsectors = 32;
12730547Skarels 		lp->d_secpercyl = 20*32;
12830547Skarels 		tio = *io;
12930547Skarels 		tio.i_bn = LABELSECTOR;
13030547Skarels 		tio.i_ma = lbuf;
13130547Skarels 		tio.i_cc = SECTSIZ;
13230547Skarels 		tio.i_flgs |= F_RDDATA;
13333635Sbostic 		if (hpstrategy(&tio, READ) != SECTSIZ)
13434519Skarels 			error = ERDLAB;
13533041Skarels 		dlp = (struct disklabel *)(lbuf + LABELOFFSET);
13634519Skarels 		if (error == 0 && (dlp->d_magic != DISKMAGIC ||
13734519Skarels 		    dlp->d_magic2 != DISKMAGIC))
13834519Skarels 			error = EUNLAB;
13934519Skarels 		if (error == 0)
14034519Skarels 			*lp = *dlp;
14134519Skarels 		else
14233635Sbostic #ifdef COMPAT_42
14334519Skarels 		    if (hpmaptype(hpaddr, hpaddr->hpdt & MBDT_TYPE, unit, lp) == 0)
14430547Skarels #endif
14534519Skarels 			return (error);
14634519Skarels 
14733041Skarels #ifndef SMALL
14830547Skarels 		/*
14911366Ssam 		 * Read in the bad sector table.
15010334Shelge 		 */
15130547Skarels 		tio.i_bn = lp->d_secpercyl * lp->d_ncylinders - lp->d_nsectors;
15233545Sbostic 		tio.i_ma = (char *)&hpbad[io->i_adapt][unit];
15333545Sbostic 		tio.i_cc = sizeof(struct dkbad);
15410334Shelge 		for (i = 0; i < 5; i++) {
15533545Sbostic 			if (hpstrategy(&tio, READ) == sizeof(struct dkbad))
15610334Shelge 				break;
15710334Shelge 			tio.i_bn += 2;
15810334Shelge 		}
15910334Shelge 		if (i == 5) {
16033545Sbostic 			printf("hp: can't read bad sector table\n");
16110334Shelge 			for (i = 0; i < MAXBADDESC; i++) {
16233545Sbostic 				hpbad[io->i_adapt][unit].bt_bad[i].bt_cyl = -1;
16333545Sbostic 				hpbad[io->i_adapt][unit].bt_bad[i].bt_trksec = -1;
16410334Shelge 			}
16525439Skarels 		}
16633041Skarels #endif
16725439Skarels 		sc->gottype = 1;
16810334Shelge 	}
16933545Sbostic 	if (io->i_part >= lp->d_npartitions ||
17033545Sbostic 	    lp->d_partitions[io->i_part].p_size == 0)
17133545Sbostic 		return (EPART);
17233545Sbostic 	io->i_boff = lp->d_partitions[io->i_part].p_offset;
17330547Skarels 	return (0);
17410334Shelge }
17510334Shelge 
17610334Shelge hpstrategy(io, func)
17710334Shelge 	register struct iob *io;
17810334Shelge {
17933545Sbostic 	register int unit = io->i_unit;
18033545Sbostic 	register struct hp_softc *sc;
18133545Sbostic 	register struct disklabel *lp;
18233545Sbostic 	struct mba_regs *mba;
18333545Sbostic 	struct hpdevice *hpaddr;
18411366Ssam 	daddr_t bn, startblock;
18533409Skarels 	int cn, tn, sn, bytecnt, bytesleft, rv;
18633545Sbostic 	int er1, er2, hprecal;
18710334Shelge 	char *membase;
18810334Shelge 
18933545Sbostic 	mba = mbamba(io->i_adapt);
19033545Sbostic 	hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit);
19133545Sbostic 	sc = &hp_softc[io->i_adapt][unit];
19233545Sbostic 	lp = &hplabel[io->i_adapt][unit];
19330547Skarels #ifndef SMALL
19410334Shelge 	sectsiz = SECTSIZ;
19510334Shelge 	if ((io->i_flgs & (F_HDR|F_HCHECK)) != 0)
19610334Shelge 		sectsiz += HDRSIZ;
19710334Shelge 	if ((hpaddr->hpds & HPDS_VV) == 0) {
19810334Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
19910334Shelge 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
20030547Skarels 		if (!ML11(sc->type))
20110334Shelge 			hpaddr->hpof = HPOF_FMT22;
20210334Shelge 	}
20310334Shelge 	io->i_errcnt = 0;
20425439Skarels 	sc->ssect = 0;
20525439Skarels 	rv = bytecnt = io->i_cc;
20610334Shelge 	membase = io->i_ma;
20710334Shelge 	startblock = io->i_bn;
20810608Ssam 	hprecal = 0;
20930547Skarels #endif
21011140Ssam 
21110626Shelge restart:
21210334Shelge 	bn = io->i_bn;
21330547Skarels 	cn = bn / lp->d_secpercyl;
21430547Skarels 	sn = bn % lp->d_secpercyl;
21530547Skarels 	tn = sn / lp->d_nsectors;
21630547Skarels 	sn = sn % lp->d_nsectors + sc->ssect;
21710334Shelge 
21810864Ssam 	HPWAIT(hpaddr);
21910626Shelge 	mba->mba_sr = -1;
22030547Skarels 	if (ML11(sc->type))
22110334Shelge 		hpaddr->hpda = bn;
22210334Shelge 	else {
22310334Shelge 		hpaddr->hpdc = cn;
22410334Shelge 		hpaddr->hpda = (tn << 8) + sn;
22510334Shelge 	}
22630547Skarels #ifdef SMALL
22733545Sbostic 	mbastart(io, io->i_unit, func);		/* start transfer */
22830547Skarels 	HPWAIT(hpaddr);
22930547Skarels 	if (hpaddr->hpds & HPDS_ERR) {
23030547Skarels 		printf("hp error: sn [%d-%d) ds=%b er1=%b\n",
23130547Skarels 		    bn, bn + io->i_cc/SECTSIZ, MASKREG(hpaddr->hpds), HPDS_BITS,
23230547Skarels 		    MASKREG(hpaddr->hper1), HPER1_BITS);
23330547Skarels 		return (-1);
23430547Skarels 	}
23530547Skarels 	return (io->i_cc);
23630547Skarels #else
23733545Sbostic 	if (mbastart(io, io->i_unit, func) != 0) {	/* start transfer */
23825439Skarels 		rv = -1;
23925439Skarels 		goto done;
24025439Skarels 	}
24110864Ssam 	HPWAIT(hpaddr);
24211366Ssam 	/*
24311366Ssam 	 * Successful data transfer, return.
24411366Ssam 	 */
24515068Skarels 	if ((hpaddr->hpds&HPDS_ERR) == 0 && (mba->mba_sr&MBSR_EBITS) == 0)
24615068Skarels 		goto done;
24710334Shelge 
24811366Ssam 	/*
24911366Ssam 	 * Error handling.  Calculate location of error.
25011366Ssam 	 */
25111366Ssam 	bytesleft = MASKREG(mba->mba_bcr);
25211366Ssam 	if (bytesleft)
25311366Ssam 		bytesleft |= 0xffff0000;	/* sxt */
25411366Ssam 	bn = io->i_bn + (io->i_cc + bytesleft) / sectsiz;
25515052Skarels 	er1 = MASKREG(hpaddr->hper1);
25615052Skarels 	er2 = MASKREG(hpaddr->hper2);
25715052Skarels 	if (er1 & (HPER1_DCK|HPER1_ECH))
25815052Skarels 		bn--;	/* Error is in Prev block */
25930547Skarels 	cn = bn/lp->d_secpercyl;
26030547Skarels 	sn = bn%lp->d_secpercyl;
26130547Skarels 	tn = sn/lp->d_nsectors;
26230547Skarels 	sn = sn%lp->d_nsectors;
26325439Skarels 	if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) {
26425439Skarels 		printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b\n",
26525439Skarels 			bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
26611366Ssam 		printf("er1=%b er2=%b\n", er1, HPER1_BITS, er2, HPER2_BITS);
26711366Ssam 		printf("bytes left: %d, of 0x%x, da 0x%x\n",-bytesleft,
26811366Ssam 			hpaddr->hpof, hpaddr->hpda);
26911366Ssam 	}
27010334Shelge 	if (er1 & HPER1_HCRC) {
27110334Shelge 		er1 &= ~(HPER1_HCE|HPER1_FER);
27210334Shelge 		er2 &= ~HPER2_BSE;
27325439Skarels 		if ((io->i_flgs&F_NBSF) == 0 && hpecc(io, BSE) == 0)
27425439Skarels 			goto success;
27510334Shelge 	}
27611140Ssam 	/*
27711140Ssam 	 * Give up early if drive write locked.
27811140Ssam 	 */
27910334Shelge 	if (er1&HPER1_WLE) {
28010334Shelge 		printf("hp%d: write locked\n", unit);
28125439Skarels 		rv = -1;
28225439Skarels 		goto done;
28311084Ssam 	}
28411140Ssam 	/*
28525439Skarels 	 * Skip sector handling.
28611140Ssam 	 */
28730547Skarels 	if (RM80(sc->type) && (er2 & HPER2_SSE)) {
28825439Skarels 		(void) hpecc(io, SSE);
28925439Skarels 		sc->ssect = 1;
29025439Skarels 		goto restart;
29111084Ssam 	}
29211140Ssam 	/*
29325439Skarels 	 * Attempt to forward bad sectors on anything but an ML11.
29425439Skarels 	 * Interpret format error bit as a bad block on RP06's.
29511140Ssam 	 */
29630547Skarels 	if (((er2 & HPER2_BSE) && !ML11(sc->type)) ||
29730547Skarels 	    (MASKREG(er1) == HPER1_FER && RP06(sc->type))) {
29811084Ssam 		if (io->i_flgs & F_NBSF) {
29933545Sbostic 			io->i_error = EBSE;
30010334Shelge 			goto hard;
30110334Shelge 		}
30210334Shelge 		if (hpecc(io, BSE) == 0)
30310334Shelge 			goto success;
30411084Ssam 		io->i_error = EBSE;
30511084Ssam 		goto hard;
30611084Ssam 	}
30711140Ssam 	/*
30811366Ssam 	 * ECC correction?
30911140Ssam 	 */
31011084Ssam 	if ((er1 & (HPER1_DCK|HPER1_ECH)) == HPER1_DCK) {
31110864Ssam 		if (hpecc(io, ECC) == 0)
31210334Shelge 			goto success;
31311084Ssam 		io->i_error = EECC;
31425439Skarels 		goto hard;
31510608Ssam 	}
31625439Skarels 
31725439Skarels 	/*
31825439Skarels 	 * If a hard error, or maximum retry count
31925439Skarels 	 * exceeded, clear controller state and
32025439Skarels 	 * pass back error to caller.
32125439Skarels 	 */
32225439Skarels 	if (++io->i_errcnt > sc->retries || (er1 & HPER1_HARD) ||
32330547Skarels 	    (!ML11(sc->type) && (er2 & HPER2_HARD)) ||
32430547Skarels 	    (ML11(sc->type) && (io->i_errcnt >= 16))) {
32525439Skarels 		io->i_error = EHER;
32625439Skarels 		if (mba->mba_sr & (MBSR_WCKUP|MBSR_WCKLWR))
32725439Skarels 			io->i_error = EWCK;
32825439Skarels hard:
32925439Skarels 		io->i_errblk = bn + sc->ssect;
33025439Skarels 		if (sc->debug & (HPF_BSEDEBUG|HPF_ECCDEBUG))
33125439Skarels 		    printf(" dc=%d, da=0x%x",MASKREG(hpaddr->hpdc),
33225439Skarels 			  MASKREG(hpaddr->hpda));
33325439Skarels 		else {
33425439Skarels 		    printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b \n",
33525439Skarels 			   bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
33625439Skarels 		    printf("er1=%b er2=%b", er1, HPER1_BITS, er2, HPER2_BITS);
33725439Skarels 		}
33825439Skarels 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
33925439Skarels 		printf("\n");
34025439Skarels 		rv = -1;
34125439Skarels 		goto done;
34225439Skarels 
34325439Skarels 	}
34410608Ssam 	/* fall thru to retry */
34510334Shelge 	hpaddr->hpcs1 = HP_DCLR|HP_GO;
34610864Ssam 	HPWAIT(hpaddr);
34711140Ssam 
34811140Ssam 	/*
34911140Ssam 	 * Every fourth retry recalibrate.
35011140Ssam 	 */
35111366Ssam 	if (((io->i_errcnt & 07) == 4) ) {
35210334Shelge 		hpaddr->hpcs1 = HP_RECAL|HP_GO;
35315052Skarels 		HPWAIT(hpaddr);
35410334Shelge 		hpaddr->hpdc = cn;
35510334Shelge 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
35615052Skarels 		HPWAIT(hpaddr);
35715052Skarels 	}
35810864Ssam 
35915052Skarels 	if (io->i_errcnt >= 16 && (io->i_flgs & F_READ)) {
36010334Shelge 		hpaddr->hpof = hp_offset[io->i_errcnt & 017]|HPOF_FMT22;
36110334Shelge 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
36215052Skarels 		HPWAIT(hpaddr);
36310334Shelge 	}
36425439Skarels 	if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG))
36515052Skarels 		printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
36615052Skarels 		  io->i_bn, io->i_cc, io->i_ma, hprecal);
36725439Skarels 	goto restart;
36811084Ssam 
36911140Ssam success:
37011140Ssam 	/*
37111140Ssam 	 * On successful error recovery, bump
37211140Ssam 	 * block number to advance to next portion
37311140Ssam 	 * of i/o transfer.
37411140Ssam 	 */
37510334Shelge 	bn++;
37610334Shelge 	if ((bn-startblock) * sectsiz < bytecnt) {
37710334Shelge 		io->i_bn = bn;
37810334Shelge 		io->i_ma = membase + (io->i_bn - startblock)*sectsiz;
37910334Shelge 		io->i_cc = bytecnt - (io->i_bn - startblock)*sectsiz;
38025439Skarels 		if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG))
38111366Ssam 			printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
38211366Ssam 			  io->i_bn, io->i_cc, io->i_ma, hprecal);
38310626Shelge 		goto restart;
38410334Shelge 	}
38515068Skarels done:
38615052Skarels 	if (io->i_errcnt >= 16) {
38715052Skarels 		hpaddr->hpcs1 = HP_RTC|HP_GO;
38815052Skarels 		while (hpaddr->hpds & HPDS_PIP)
38915052Skarels 			;
39015052Skarels 	}
39125439Skarels 	io->i_bn = startblock;		/*reset i_bn to original */
39218515Smiriam 	io->i_cc = bytecnt;		/*reset i_cc to total count xfered*/
39325439Skarels 	io->i_ma = membase;		/*reset i_ma to original */
39425439Skarels 	return (rv);
39530547Skarels #endif
39610334Shelge }
39710864Ssam 
39830547Skarels #ifndef SMALL
39910334Shelge hpecc(io, flag)
40010334Shelge 	register struct iob *io;
40110334Shelge 	int flag;
40210334Shelge {
40333545Sbostic 	register int unit = io->i_unit;
40433545Sbostic 	register struct mba_regs *mbp;
40533545Sbostic 	register struct hpdevice *rp;
40633545Sbostic 	register struct hp_softc *sc;
40733545Sbostic 	register struct disklabel *lp;
40811084Ssam 	int npf, bn, cn, tn, sn, bcr;
40910334Shelge 
41033545Sbostic 	mbp = mbamba(io->i_adapt);
41133545Sbostic 	rp = (struct hpdevice *)mbadrv(io->i_adapt, unit);
41233545Sbostic 	sc = &hp_softc[io->i_adapt][unit];
41333545Sbostic 	lp = &hplabel[io->i_adapt][unit];
41411366Ssam 	bcr = MASKREG(mbp->mba_bcr);
41511366Ssam 	if (bcr)
41611366Ssam 		bcr |= 0xffff0000;		/* sxt */
41711084Ssam 	npf = (bcr + io->i_cc) / sectsiz;	/* # sectors read */
41815052Skarels 	if (flag == ECC)
41915052Skarels 		npf--;		/* Error is in prev block --ghg */
42025439Skarels 	bn = io->i_bn + npf + sc->ssect;	/* physical block #*/
42125439Skarels 	if (sc->debug & HPF_ECCDEBUG)
42211366Ssam 		printf("bcr=%d npf=%d ssect=%d sectsiz=%d i_cc=%d\n",
42325439Skarels 			bcr, npf, sc->ssect, sectsiz, io->i_cc);
42411140Ssam 	/*
42511140Ssam 	 * ECC correction logic.
42611140Ssam 	 */
42711140Ssam 	if (flag == ECC) {
42810334Shelge 		register int i;
42910334Shelge 		caddr_t addr;
43025439Skarels 		int bit, o, mask;
43110334Shelge 
43210413Shelge 		printf("hp%d: soft ecc sn%d\n", unit, bn);
43310334Shelge 		mask = MASKREG(rp->hpec2);
43425439Skarels 		for (i = mask, bit = 0; i; i >>= 1)
43525439Skarels 			if (i & 1)
43625439Skarels 				bit++;
43725439Skarels 		if (bit > sc->ecclim) {
43825439Skarels 			printf("%d-bit error\n", bit);
43925439Skarels 			return (1);
44025439Skarels 		}
44111084Ssam 		i = MASKREG(rp->hpec1) - 1;	/* -1 makes 0 origin */
44210334Shelge 		bit = i&07;
44311366Ssam 		o = (i & ~07) >> 3;
44410334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
44511179Ssam 		while (o <sectsiz && npf*sectsiz + o < io->i_cc && bit > -11) {
44611179Ssam 			addr = io->i_ma + (npf*sectsiz) + o;
44711179Ssam 			/*
44811179Ssam 			 * No data transfer occurs with a write check,
44911179Ssam 			 * so don't correct the resident copy of data.
45011179Ssam 			 */
45111366Ssam 			if ((io->i_flgs & (F_CHECK|F_HCHECK)) == 0) {
45225439Skarels 				if (sc->debug & HPF_ECCDEBUG)
45311366Ssam 					printf("addr=%x old=%x ", addr,
45411366Ssam 						(*addr & 0xff));
45511140Ssam 				*addr ^= (mask << bit);
45625439Skarels 				if (sc->debug & HPF_ECCDEBUG)
45711366Ssam 					printf("new=%x\n",(*addr & 0xff));
45811366Ssam 			}
45911179Ssam 			o++, bit -= 8;
46010334Shelge 		}
46111179Ssam 		return (0);
46211084Ssam 	}
46310334Shelge 
46411084Ssam 	/*
46511084Ssam 	 * Skip sector error.
46611084Ssam 	 * Set skip-sector-inhibit and
46711084Ssam 	 * read next sector
46811084Ssam 	 */
46911140Ssam 	if (flag == SSE) {
47010334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
47110864Ssam 		HPWAIT(rp);
47210334Shelge 		rp->hpof |= HPOF_SSEI;
47333545Sbostic 		return (0);
47411140Ssam 	}
47510334Shelge 
47611140Ssam 	/*
47711140Ssam 	 * Bad block forwarding.
47811140Ssam 	 */
47911140Ssam 	 if (flag == BSE) {
48010626Shelge 		int bbn;
48111084Ssam 
48210626Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
48325439Skarels 		if (sc->debug & HPF_BSEDEBUG)
48411366Ssam 			printf("hpecc: BSE @ bn %d\n", bn);
48530547Skarels 		cn = bn / lp->d_secpercyl;
48630547Skarels 		sn = bn % lp->d_secpercyl;
48730547Skarels 		tn = sn / lp->d_nsectors;
48830547Skarels 		sn = sn % lp->d_nsectors;
48910626Shelge 		bcr += sectsiz;
49033545Sbostic 		if ((bbn = isbad(&hpbad[io->i_adapt][unit], cn, tn, sn)) < 0)
49111084Ssam 			return (1);
49230547Skarels 		bbn = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors - 1
49330547Skarels 		    - bbn;
49430547Skarels 		cn = bbn / lp->d_secpercyl;
49530547Skarels 		sn = bbn % lp->d_secpercyl;
49630547Skarels 		tn = sn / lp->d_nsectors;
49733409Skarels 		sn = sn % lp->d_nsectors;
49810626Shelge 		io->i_cc = sectsiz;
49930547Skarels 		io->i_ma += npf * sectsiz;
50025439Skarels 		if (sc->debug & HPF_BSEDEBUG)
50111366Ssam 			printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
50211366Ssam 		rp->hpof &= ~HPOF_SSEI;
50310626Shelge 		mbp->mba_sr = -1;
50410334Shelge 		rp->hpdc = cn;
50510334Shelge 		rp->hpda = (tn<<8) + sn;
50633545Sbostic 		mbastart(io, io->i_unit, io->i_flgs);
50711366Ssam 		io->i_errcnt = 0;
50810864Ssam 		HPWAIT(rp);
50910864Ssam 		return (rp->hpds&HPDS_ERR);
51010334Shelge 	}
51111084Ssam 	printf("hpecc: flag=%d\n", flag);
51211084Ssam 	return (1);
51310334Shelge }
51411140Ssam 
51510334Shelge /*ARGSUSED*/
51610334Shelge hpioctl(io, cmd, arg)
51710334Shelge 	struct iob *io;
51810334Shelge 	int cmd;
51910334Shelge 	caddr_t arg;
52010334Shelge {
52110647Shelge 	register unit = io->i_unit;
52233545Sbostic 	register struct hp_softc *sc = &hp_softc[io->i_adapt][unit];
52333545Sbostic 	register struct disklabel *lp = &hplabel[io->i_adapt][unit];
52433545Sbostic 	struct mba_drv *drv = mbadrv(io->i_adapt, unit);
52510334Shelge 
52610334Shelge 	switch(cmd) {
52710334Shelge 
52811366Ssam 	case SAIODEBUG:
52925439Skarels 		sc->debug = (int)arg;
53025439Skarels 		break;
53111366Ssam 
53210334Shelge 	case SAIODEVDATA:
53325439Skarels 		if (drv->mbd_dt&MBDT_TAP)
53425439Skarels 			return (ECMD);
53530547Skarels 		*(struct disklabel *)arg = *lp;
53625439Skarels 		break;
53710334Shelge 
53825439Skarels 	case SAIOGBADINFO:
53925439Skarels 		if (drv->mbd_dt&MBDT_TAP)
54025439Skarels 			return (ECMD);
54133545Sbostic 		*(struct dkbad *)arg = hpbad[io->i_adapt][unit];
54225439Skarels 		break;
54325439Skarels 
54425439Skarels 	case SAIOECCLIM:
54525439Skarels 		sc->ecclim = (int)arg;
54625439Skarels 		break;
54725439Skarels 
54825439Skarels 	case SAIORETRIES:
54925439Skarels 		sc->retries = (int)arg;
55025439Skarels 		break;
55125439Skarels 
55211084Ssam 	case SAIOSSI:			/* skip-sector-inhibit */
55311084Ssam 		if (drv->mbd_dt&MBDT_TAP)
55411084Ssam 			return (ECMD);
55511084Ssam 		if ((io->i_flgs&F_SSI) == 0) {
55611084Ssam 			/* make sure this is done once only */
55711084Ssam 			io->i_flgs |= F_SSI;
55830547Skarels 			lp->d_nsectors++;
55930547Skarels 			lp->d_secpercyl += lp->d_ntracks;
56010864Ssam 		}
56125439Skarels 		break;
56210626Shelge 
56311084Ssam 	case SAIONOSSI:			/* remove skip-sector-inhibit */
56410626Shelge 		if (io->i_flgs & F_SSI) {
56510626Shelge 			io->i_flgs &= ~F_SSI;
56610626Shelge 			drv->mbd_of &= ~HPOF_SSEI;
56730547Skarels 			lp->d_nsectors--;
56830547Skarels 			lp->d_secpercyl -= lp->d_ntracks;
56910626Shelge 		}
57025439Skarels 		break;
57110626Shelge 
57210864Ssam 	case SAIOSSDEV:			/* drive have skip sector? */
57330547Skarels 		return (RM80(sc->type) ? 0 : ECMD);
57425439Skarels 
57525439Skarels 	default:
57625439Skarels 		return (ECMD);
57710334Shelge 	}
57825439Skarels 	return (0);
57910334Shelge }
58033545Sbostic #endif /* !SMALL */
581