xref: /csrg-svn/sys/vax/stand/hp.c (revision 18515)
1*18515Smiriam /*	hp.c	6.6	85/03/27	*/
210334Shelge 
310334Shelge /*
410334Shelge  * RP??/RM?? disk driver
510334Shelge  * with ECC handling and bad block forwarding.
610334Shelge  * Also supports header io operations and
710334Shelge  * commands to write check header and data.
810334Shelge  */
910334Shelge #include "../h/param.h"
1010334Shelge #include "../h/inode.h"
1110334Shelge #include "../h/fs.h"
1210334Shelge #include "../h/dkbad.h"
1310334Shelge 
1410334Shelge #include "../vax/pte.h"
1510334Shelge #include "../vaxmba/hpreg.h"
1610334Shelge #include "../vaxmba/mbareg.h"
1710334Shelge 
1810334Shelge #include "saio.h"
1910334Shelge #include "savax.h"
2010334Shelge 
2110334Shelge #define	MASKREG(reg)	((reg)&0xffff)
2210334Shelge 
2311366Ssam #define	MAXBADDESC	126
2411366Ssam #define	SECTSIZ 	512	/* sector size in bytes */
2511366Ssam #define	HDRSIZ		4	/* number of bytes in sector header */
2611366Ssam #define	MAXECC		5	/* max # bits allow in ecc error w/ F_ECCLM */
2710334Shelge 
2810334Shelge char	hp_type[MAXNMBA*8] = { 0 };
2911140Ssam extern	struct st hpst[];
3010334Shelge 
3111115Ssam short	hptypes[] = {
3211366Ssam 	MBDT_RM03,
3311366Ssam 	MBDT_RM05,
3411366Ssam 	MBDT_RP06,
3511366Ssam 	MBDT_RM80,
3611366Ssam 	MBDT_RP05,
3711366Ssam 	MBDT_RP07,
3811366Ssam 	MBDT_ML11A,
3911366Ssam 	MBDT_ML11B,
4011366Ssam 	-1,		/* 9755 */
4111366Ssam 	-1,		/* 9730 */
4211366Ssam 	-1,		/* Capricorn */
4311366Ssam 	-1,		/* Eagle */
4411366Ssam 	MBDT_RM02,	/* actually something else */
4511366Ssam 	-1,		/* 9300 */
4611366Ssam 	0
4711115Ssam };
4810334Shelge 
4911366Ssam #define	RP06 (hptypes[hp_type[unit]] <= MBDT_RP06)
5011366Ssam #define	ML11 (hptypes[hp_type[unit]] == MBDT_ML11A)
5111366Ssam #define	RM80 (hptypes[hp_type[unit]] == MBDT_RM80)
5210334Shelge 
5310334Shelge u_char	hp_offset[16] = {
5410334Shelge     HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
5510334Shelge     HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
5610334Shelge     HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
5710334Shelge     0, 0, 0, 0,
5810334Shelge };
5910334Shelge 
6011366Ssam struct	dkbad hpbad[MAXNMBA*8];
6111366Ssam int	ssect[MAXNMBA*8];		/* 1 when on track w/skip sector */
6210334Shelge 
6311366Ssam int	hpdebug[MAXNMBA*8];
6411366Ssam #define	HPF_BSEDEBUG	01	/* debugging bad sector forwarding */
6511366Ssam #define	HPF_ECCDEBUG	02	/* debugging ecc correction */
6611366Ssam 
6711366Ssam int	sectsiz;
6811366Ssam 
6910864Ssam /*
7010864Ssam  * When awaiting command completion, don't
7110864Ssam  * hang on to the status register since
7211366Ssam  * this ties up some controllers.
7310864Ssam  */
7411366Ssam #define	HPWAIT(addr) \
7511366Ssam 	while ((((addr)->hpds)&HPDS_DRY)==0) DELAY(500);
7610864Ssam 
7710334Shelge hpopen(io)
7810334Shelge 	register struct iob *io;
7910334Shelge {
8010334Shelge 	register unit = io->i_unit;
8110334Shelge 	struct hpdevice *hpaddr = (struct hpdevice *)mbadrv(unit);
8210353Shelge 	register struct st *st;
8310334Shelge 
8410334Shelge 	mbainit(UNITTOMBA(unit));
8510334Shelge 	if (hp_type[unit] == 0) {
8611366Ssam 		register i, type = hpaddr->hpdt & MBDT_TYPE;
8710334Shelge 		struct iob tio;
8810334Shelge 
8910334Shelge 		for (i = 0; hptypes[i]; i++)
9010334Shelge 			if (hptypes[i] == type)
9110334Shelge 				goto found;
9210334Shelge 		_stop("unknown drive type");
9310334Shelge found:
9410647Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;		/* init drive */
9510647Shelge 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
9610647Shelge 		if (!ML11)
9710647Shelge 			hpaddr->hpof = HPOF_FMT22;
9816271Skarels 		hp_type[unit] = hpmaptype(hpaddr, i, UNITTODRIVE(unit));
9910334Shelge 		/*
10011366Ssam 		 * Read in the bad sector table.
10110334Shelge 		 */
10211140Ssam 		st = &hpst[hp_type[unit]];
10310334Shelge 		tio = *io;
10410334Shelge 		tio.i_bn = st->nspc * st->ncyl - st->nsect;
10510626Shelge 		tio.i_ma = (char *)&hpbad[unit];
10610628Shelge 		tio.i_cc = sizeof (struct dkbad);
10710334Shelge 		tio.i_flgs |= F_RDDATA;
10810334Shelge 		for (i = 0; i < 5; i++) {
10910628Shelge 			if (hpstrategy(&tio, READ) == sizeof (struct dkbad))
11010334Shelge 				break;
11110334Shelge 			tio.i_bn += 2;
11210334Shelge 		}
11310334Shelge 		if (i == 5) {
11410334Shelge 			printf("Unable to read bad sector table\n");
11510334Shelge 			for (i = 0; i < MAXBADDESC; i++) {
11610334Shelge 				hpbad[unit].bt_bad[i].bt_cyl = -1;
11710334Shelge 				hpbad[unit].bt_bad[i].bt_trksec = -1;
11810334Shelge 			}
11910334Shelge 		}
12010334Shelge 	}
12115947Skarels 	st = &hpst[hp_type[unit]];
12210334Shelge 	if (io->i_boff < 0 || io->i_boff > 7 ||
12310334Shelge 	    st->off[io->i_boff]== -1)
12410334Shelge 		_stop("hp bad minor");
12510334Shelge 	io->i_boff = st->off[io->i_boff] * st->nspc;
12610334Shelge }
12710334Shelge 
12810334Shelge hpstrategy(io, func)
12910334Shelge 	register struct iob *io;
13010334Shelge {
13110334Shelge 	register unit = io->i_unit;
13210334Shelge 	struct mba_regs *mba = mbamba(unit);
13311366Ssam 	daddr_t bn, startblock;
13410334Shelge 	struct hpdevice *hpaddr = (struct hpdevice *)mbadrv(unit);
13510353Shelge 	struct st *st = &hpst[hp_type[unit]];
13610334Shelge 	int cn, tn, sn, bytecnt, bytesleft;
13710334Shelge 	char *membase;
13810334Shelge 	int er1, er2, hprecal;
13910334Shelge 
14010334Shelge 	sectsiz = SECTSIZ;
14110334Shelge 	if ((io->i_flgs & (F_HDR|F_HCHECK)) != 0)
14210334Shelge 		sectsiz += HDRSIZ;
14310334Shelge 	if ((hpaddr->hpds & HPDS_VV) == 0) {
14410334Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
14510334Shelge 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
14611084Ssam 		if (!ML11)
14710334Shelge 			hpaddr->hpof = HPOF_FMT22;
14810334Shelge 	}
14910334Shelge 	io->i_errcnt = 0;
15011366Ssam 	ssect[unit] = 0;
15110334Shelge 	bytecnt = io->i_cc;
15210334Shelge 	membase = io->i_ma;
15310334Shelge 	startblock = io->i_bn;
15410608Ssam 	hprecal = 0;
15511140Ssam 
15610626Shelge restart:
15710334Shelge 	bn = io->i_bn;
15810334Shelge 	cn = bn/st->nspc;
15910334Shelge 	sn = bn%st->nspc;
16010334Shelge 	tn = sn/st->nsect;
16111366Ssam 	sn = sn%st->nsect + ssect[unit];
16210334Shelge 
16310864Ssam 	HPWAIT(hpaddr);
16410626Shelge 	mba->mba_sr = -1;
16510647Shelge 	if (ML11)
16610334Shelge 		hpaddr->hpda = bn;
16710334Shelge 	else {
16810334Shelge 		hpaddr->hpdc = cn;
16910334Shelge 		hpaddr->hpda = (tn << 8) + sn;
17010334Shelge 	}
17110334Shelge 	if (mbastart(io, func) != 0)		/* start transfer */
17210334Shelge 		return (-1);
17310864Ssam 	HPWAIT(hpaddr);
17411366Ssam 	/*
17511366Ssam 	 * Successful data transfer, return.
17611366Ssam 	 */
17715068Skarels 	if ((hpaddr->hpds&HPDS_ERR) == 0 && (mba->mba_sr&MBSR_EBITS) == 0)
17815068Skarels 		goto done;
17910334Shelge 
18011366Ssam 	/*
18111366Ssam 	 * Error handling.  Calculate location of error.
18211366Ssam 	 */
18311366Ssam 	bytesleft = MASKREG(mba->mba_bcr);
18411366Ssam 	if (bytesleft)
18511366Ssam 		bytesleft |= 0xffff0000;	/* sxt */
18611366Ssam 	bn = io->i_bn + (io->i_cc + bytesleft) / sectsiz;
18715052Skarels 	er1 = MASKREG(hpaddr->hper1);
18815052Skarels 	er2 = MASKREG(hpaddr->hper2);
18915052Skarels 	if (er1 & (HPER1_DCK|HPER1_ECH))
19015052Skarels 		bn--;	/* Error is in Prev block */
19110334Shelge 	cn = bn/st->nspc;
19210334Shelge 	sn = bn%st->nspc;
19310334Shelge 	tn = sn/st->nsect;
19410334Shelge 	sn = sn%st->nsect;
19511366Ssam 	if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG)) {
19611366Ssam 		printf("hp error: (cyl,trk,sec)=(%d,%d,%d) ds=%b\n",
19711366Ssam 			cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
19811366Ssam 		printf("er1=%b er2=%b\n", er1, HPER1_BITS, er2, HPER2_BITS);
19911366Ssam 		printf("bytes left: %d, of 0x%x, da 0x%x\n",-bytesleft,
20011366Ssam 			hpaddr->hpof, hpaddr->hpda);
20111366Ssam 	}
20210334Shelge 	if (er1 & HPER1_HCRC) {
20310334Shelge 		er1 &= ~(HPER1_HCE|HPER1_FER);
20410334Shelge 		er2 &= ~HPER2_BSE;
20510334Shelge 	}
20611140Ssam 	/*
20711140Ssam 	 * Give up early if drive write locked.
20811140Ssam 	 */
20910334Shelge 	if (er1&HPER1_WLE) {
21010334Shelge 		printf("hp%d: write locked\n", unit);
21111084Ssam 		return (-1);
21211084Ssam 	}
21311140Ssam 	/*
21411366Ssam 	 * Interpret format error bit as a bad block on RP06's.
21511140Ssam 	 */
21611084Ssam 	if (MASKREG(er1) == HPER1_FER && RP06)
21710334Shelge 		goto badsect;
21811140Ssam 
21911140Ssam 	/*
22011140Ssam 	 * If a hard error, or maximum retry count
22111140Ssam 	 * exceeded, clear controller state and
22211140Ssam 	 * pass back error to caller.
22311140Ssam 	 */
22411084Ssam 	if (++io->i_errcnt > 27 || (er1 & HPER1_HARD) ||
22511084Ssam 	    (!ML11 && (er2 & HPER2_HARD))) {
22615052Skarels 		/*
22715052Skarels 		 * The last ditch effort to bad sector forward
22815052Skarels 		 * below will probably fail since mba byte ctr
22915052Skarels 		 * (bcr) is different for BSE and ECC errors and
23015052Skarels 		 * the wrong block will be revectored to if one
23115052Skarels 		 * has 2 contiguous bad blocks and reads the second.
23215052Skarels 		 * For now, we can probably just let a header CRC
23315052Skarels 		 * error be handled like a BSE since no data will
23415052Skarels 		 * have been transferred and the bcr should the same
23515052Skarels 		 * as it would with a BSE error.
23615052Skarels 		 * --ghg.
23715052Skarels 		 */
23815052Skarels 		if (er1 & HPER1_HCRC)
23915052Skarels 			if ((io->i_flgs&F_NBSF) == 0 && hpecc(io, BSE) == 0)
24015052Skarels 				goto success;
24110608Ssam hard0:
24210334Shelge 		io->i_error = EHER;
24311084Ssam 		if (mba->mba_sr & (MBSR_WCKUP|MBSR_WCKLWR))
24410334Shelge 			io->i_error = EWCK;
24510334Shelge hard:
24611366Ssam 		io->i_errblk = bn + ssect[unit];
24710334Shelge 		printf("hp error: (cyl,trk,sec)=(%d,%d,%d) ds=%b \n",
24810334Shelge 			   cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
24911084Ssam 		printf("er1=%b er2=%b", er1, HPER1_BITS, er2, HPER2_BITS);
25010334Shelge 		if (hpaddr->hpmr)
25110626Shelge 			printf(" mr1=%o", MASKREG(hpaddr->hpmr));
25210334Shelge 		if (hpaddr->hpmr2)
25310626Shelge 			printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
25411366Ssam 		if (hpdebug[unit] & (HPF_BSEDEBUG|HPF_ECCDEBUG))
25511366Ssam 			printf(" dc=%d, da=0x%x",MASKREG(hpaddr->hpdc),
25611366Ssam 			  MASKREG(hpaddr->hpda));
25710626Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
25810334Shelge 		printf("\n");
25915068Skarels 		bytecnt = -1;
26015068Skarels 		goto done;
26110334Shelge 
26211084Ssam 	}
26311140Ssam 	/*
26411140Ssam 	 * Attempt to forward bad sectors on
265*18515Smiriam 	 * anything but an ML11.
26611140Ssam 	 */
26711084Ssam 	if ((er2 & HPER2_BSE) && !ML11) {
26810334Shelge badsect:
26911366Ssam 		if (!ssect[unit] && (er2&HPER2_SSE))
27010647Shelge 			goto skipsect;
27111084Ssam 		if (io->i_flgs & F_NBSF) {
27210334Shelge 			io->i_error = EBSE;
27310334Shelge 			goto hard;
27410334Shelge 		}
27510334Shelge 		if (hpecc(io, BSE) == 0)
27610334Shelge 			goto success;
27711084Ssam 		io->i_error = EBSE;
27811084Ssam 		goto hard;
27911084Ssam 	}
28011140Ssam 	/*
28111140Ssam 	 * Skip sector handling.
28211140Ssam 	 */
28311366Ssam 	if (RM80 && (er2 & HPER2_SSE)) {
28410647Shelge skipsect:
28510334Shelge 		(void) hpecc(io, SSE);
28611366Ssam 		ssect[unit] = 1;
287*18515Smiriam 		goto restart;
28811084Ssam 	}
28911140Ssam 	/*
29011366Ssam 	 * ECC correction?
29111140Ssam 	 */
29211084Ssam 	if ((er1 & (HPER1_DCK|HPER1_ECH)) == HPER1_DCK) {
29310864Ssam 		if (hpecc(io, ECC) == 0)
29410334Shelge 			goto success;
29511084Ssam 		io->i_error = EECC;
29615052Skarels 		io->i_errblk = bn + ssect[unit];
29711084Ssam 		return (-1);
29810608Ssam 	}
29915052Skarels #ifdef F_SEVRE
30015052Skarels 	if (io->i_flgs & F_SEVRE)
30115052Skarels 		goto hard;
30215052Skarels #endif
30310608Ssam 	if (ML11 && (io->i_errcnt >= 16))
30411084Ssam 		goto hard0;
30510608Ssam 	/* fall thru to retry */
30610334Shelge 	hpaddr->hpcs1 = HP_DCLR|HP_GO;
30710864Ssam 	HPWAIT(hpaddr);
30811140Ssam 
30911140Ssam 	/*
31011140Ssam 	 * Every fourth retry recalibrate.
31111140Ssam 	 */
31211366Ssam 	if (((io->i_errcnt & 07) == 4) ) {
31310334Shelge 		hpaddr->hpcs1 = HP_RECAL|HP_GO;
31415052Skarels 		HPWAIT(hpaddr);
31510334Shelge 		hpaddr->hpdc = cn;
31610334Shelge 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
31715052Skarels 		HPWAIT(hpaddr);
31815052Skarels 	}
31910864Ssam 
32015052Skarels 	if (io->i_errcnt >= 16 && (io->i_flgs & F_READ)) {
32110334Shelge 		hpaddr->hpof = hp_offset[io->i_errcnt & 017]|HPOF_FMT22;
32210334Shelge 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
32315052Skarels 		HPWAIT(hpaddr);
32410334Shelge 	}
32515052Skarels 	if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG))
32615052Skarels 		printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
32715052Skarels 		  io->i_bn, io->i_cc, io->i_ma, hprecal);
32815052Skarels 	goto restart;	/* retry whole transfer  --ghg */
32911084Ssam 
33011140Ssam success:
33111140Ssam 	/*
33211140Ssam 	 * On successful error recovery, bump
33311140Ssam 	 * block number to advance to next portion
33411140Ssam 	 * of i/o transfer.
33511140Ssam 	 */
33610334Shelge 	bn++;
33710334Shelge 	if ((bn-startblock) * sectsiz < bytecnt) {
33810334Shelge 		io->i_bn = bn;
33910334Shelge 		io->i_ma = membase + (io->i_bn - startblock)*sectsiz;
34010334Shelge 		io->i_cc = bytecnt - (io->i_bn - startblock)*sectsiz;
34111366Ssam 		if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG))
34211366Ssam 			printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
34311366Ssam 			  io->i_bn, io->i_cc, io->i_ma, hprecal);
34410626Shelge 		goto restart;
34510334Shelge 	}
34615068Skarels done:
34715052Skarels 	if (io->i_errcnt >= 16) {
34815052Skarels 		hpaddr->hpcs1 = HP_RTC|HP_GO;
34915052Skarels 		while (hpaddr->hpds & HPDS_PIP)
35015052Skarels 			;
35115052Skarels 	}
352*18515Smiriam 	io->i_cc = bytecnt;		/*reset i_cc to total count xfered*/
35310334Shelge 	return (bytecnt);
35410334Shelge }
35510864Ssam 
35610334Shelge hpecc(io, flag)
35710334Shelge 	register struct iob *io;
35810334Shelge 	int flag;
35910334Shelge {
36010334Shelge 	register unit = io->i_unit;
36110334Shelge 	register struct mba_regs *mbp = mbamba(unit);
36210334Shelge 	register struct hpdevice *rp = (struct hpdevice *)mbadrv(unit);
36310353Shelge 	register struct st *st = &hpst[hp_type[unit]];
36411084Ssam 	int npf, bn, cn, tn, sn, bcr;
36510334Shelge 
36611366Ssam 	bcr = MASKREG(mbp->mba_bcr);
36711366Ssam 	if (bcr)
36811366Ssam 		bcr |= 0xffff0000;		/* sxt */
36911084Ssam 	npf = (bcr + io->i_cc) / sectsiz;	/* # sectors read */
37015052Skarels 	if (flag == ECC)
37115052Skarels 		npf--;		/* Error is in prev block --ghg */
37211366Ssam 	bn = io->i_bn + npf + ssect[unit];	/* physical block #*/
37311366Ssam 	if (hpdebug[unit]&HPF_ECCDEBUG)
37411366Ssam 		printf("bcr=%d npf=%d ssect=%d sectsiz=%d i_cc=%d\n",
37511366Ssam 			bcr, npf, ssect[unit], sectsiz, io->i_cc);
37611140Ssam 	/*
37711140Ssam 	 * ECC correction logic.
37811140Ssam 	 */
37911140Ssam 	if (flag == ECC) {
38010334Shelge 		register int i;
38110334Shelge 		caddr_t addr;
38211179Ssam 		int bit, o, mask, ecccnt = 0;
38310334Shelge 
38410413Shelge 		printf("hp%d: soft ecc sn%d\n", unit, bn);
38510334Shelge 		mask = MASKREG(rp->hpec2);
38611084Ssam 		i = MASKREG(rp->hpec1) - 1;	/* -1 makes 0 origin */
38710334Shelge 		bit = i&07;
38811366Ssam 		o = (i & ~07) >> 3;
38910334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
39011179Ssam 		while (o <sectsiz && npf*sectsiz + o < io->i_cc && bit > -11) {
39111179Ssam 			addr = io->i_ma + (npf*sectsiz) + o;
39211179Ssam 			/*
39311179Ssam 			 * No data transfer occurs with a write check,
39411179Ssam 			 * so don't correct the resident copy of data.
39511179Ssam 			 */
39611366Ssam 			if ((io->i_flgs & (F_CHECK|F_HCHECK)) == 0) {
39711366Ssam 				if (hpdebug[unit] & HPF_ECCDEBUG)
39811366Ssam 					printf("addr=%x old=%x ", addr,
39911366Ssam 						(*addr & 0xff));
40011140Ssam 				*addr ^= (mask << bit);
40111366Ssam 				if (hpdebug[unit] & HPF_ECCDEBUG)
40211366Ssam 					printf("new=%x\n",(*addr & 0xff));
40311366Ssam 			}
40411179Ssam 			o++, bit -= 8;
40511109Ssam 			if ((io->i_flgs & F_ECCLM) && ecccnt++ >= MAXECC)
40611084Ssam 				return (1);
40710334Shelge 		}
40815052Skarels #ifdef F_SEVRE
40915052Skarels 		if (io->i_flgs & F_SEVRE)
41015052Skarels 			return(1);
41115052Skarels #endif
41211179Ssam 		return (0);
41311084Ssam 	}
41410334Shelge 
41511084Ssam 	/*
41611084Ssam 	 * Skip sector error.
41711084Ssam 	 * Set skip-sector-inhibit and
41811084Ssam 	 * read next sector
41911084Ssam 	 */
42011140Ssam 	if (flag == SSE) {
42110334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
42210864Ssam 		HPWAIT(rp);
42310334Shelge 		rp->hpof |= HPOF_SSEI;
42411084Ssam 		return (0);
42511140Ssam 	}
42610334Shelge 
42711140Ssam 	/*
42811140Ssam 	 * Bad block forwarding.
42911140Ssam 	 */
43011140Ssam 	 if (flag == BSE) {
43110626Shelge 		int bbn;
43211084Ssam 
43310626Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
43411366Ssam 		if (hpdebug[unit] & HPF_BSEDEBUG)
43511366Ssam 			printf("hpecc: BSE @ bn %d\n", bn);
43610334Shelge 		cn = bn/st->nspc;
43710334Shelge 		sn = bn%st->nspc;
43810334Shelge 		tn = sn/st->nsect;
43910626Shelge 		sn = sn%st->nsect;
44010626Shelge 		bcr += sectsiz;
44110626Shelge 		if ((bbn = isbad(&hpbad[unit], cn, tn, sn)) < 0)
44211084Ssam 			return (1);
44310626Shelge 		bbn = st->ncyl*st->nspc - st->nsect - 1 - bbn;
44410626Shelge 		cn = bbn/st->nspc;
44510626Shelge 		sn = bbn%st->nspc;
44610626Shelge 		tn = sn/st->nsect;
44710626Shelge 		sn = sn%st->nsect;
44810626Shelge 		io->i_cc = sectsiz;
44910626Shelge 		io->i_ma += npf*sectsiz;
45011366Ssam 		if (hpdebug[unit] & HPF_BSEDEBUG)
45111366Ssam 			printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
45211366Ssam 		rp->hpof &= ~HPOF_SSEI;
45310626Shelge 		mbp->mba_sr = -1;
45410334Shelge 		rp->hpdc = cn;
45510334Shelge 		rp->hpda = (tn<<8) + sn;
45610334Shelge 		mbastart(io,io->i_flgs);
45711366Ssam 		io->i_errcnt = 0;
45810864Ssam 		HPWAIT(rp);
45910864Ssam 		return (rp->hpds&HPDS_ERR);
46010334Shelge 	}
46111084Ssam 	printf("hpecc: flag=%d\n", flag);
46211084Ssam 	return (1);
46310334Shelge }
46411140Ssam 
46510334Shelge /*ARGSUSED*/
46610334Shelge hpioctl(io, cmd, arg)
46710334Shelge 	struct iob *io;
46810334Shelge 	int cmd;
46910334Shelge 	caddr_t arg;
47010334Shelge {
47110647Shelge 	register unit = io->i_unit;
47210647Shelge 	struct st *st = &hpst[hp_type[unit]], *tmp;
47310647Shelge 	struct mba_drv *drv = mbadrv(unit);
47411366Ssam 	int flag;
47510334Shelge 
47610334Shelge 	switch(cmd) {
47710334Shelge 
47811366Ssam 	case SAIODEBUG:
47911366Ssam 		flag = (int)arg;
48011366Ssam 		if (flag > 0)
48111366Ssam 			hpdebug[unit] |= flag;
48211366Ssam 		else
48311366Ssam 			hpdebug[unit] &= ~flag;
48411366Ssam 		return (0);
48511366Ssam 
48610334Shelge 	case SAIODEVDATA:
48710334Shelge 		if ((drv->mbd_dt&MBDT_TAP) == 0) {
48810353Shelge 			tmp = (struct st *)arg;
48910353Shelge 			*tmp = *st;
49011084Ssam 			return (0);
49110334Shelge 		}
49211084Ssam 		return (ECMD);
49310334Shelge 
49411084Ssam 	case SAIOSSI:			/* skip-sector-inhibit */
49511084Ssam 		if (drv->mbd_dt&MBDT_TAP)
49611084Ssam 			return (ECMD);
49711084Ssam 		if ((io->i_flgs&F_SSI) == 0) {
49811084Ssam 			/* make sure this is done once only */
49911084Ssam 			io->i_flgs |= F_SSI;
50011084Ssam 			st->nsect++;
50111084Ssam 			st->nspc += st->ntrak;
50210864Ssam 		}
50311084Ssam 		return (0);
50410626Shelge 
50511084Ssam 	case SAIONOSSI:			/* remove skip-sector-inhibit */
50610626Shelge 		if (io->i_flgs & F_SSI) {
50710626Shelge 			io->i_flgs &= ~F_SSI;
50810626Shelge 			drv->mbd_of &= ~HPOF_SSEI;
50910626Shelge 			st->nsect--;
51010626Shelge 			st->nspc -= st->ntrak;
51110626Shelge 		}
51210626Shelge 		return(0);
51310626Shelge 
51410864Ssam 	case SAIOSSDEV:			/* drive have skip sector? */
51511084Ssam 		return (RM80 ? 0 : ECMD);
51610334Shelge 	}
51711084Ssam 	return (ECMD);
51810334Shelge }
519