xref: /csrg-svn/sys/vax/stand/hp.c (revision 15068)
1*15068Skarels /*	hp.c	6.3	83/09/23	*/
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;
9811113Shelge 		hp_type[unit] = hpmaptype(hpaddr, i, 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 	}
12110334Shelge 	if (io->i_boff < 0 || io->i_boff > 7 ||
12210334Shelge 	    st->off[io->i_boff]== -1)
12310334Shelge 		_stop("hp bad minor");
12410334Shelge 	io->i_boff = st->off[io->i_boff] * st->nspc;
12510334Shelge }
12610334Shelge 
12710334Shelge hpstrategy(io, func)
12810334Shelge 	register struct iob *io;
12910334Shelge {
13010334Shelge 	register unit = io->i_unit;
13110334Shelge 	struct mba_regs *mba = mbamba(unit);
13211366Ssam 	daddr_t bn, startblock;
13310334Shelge 	struct hpdevice *hpaddr = (struct hpdevice *)mbadrv(unit);
13410353Shelge 	struct st *st = &hpst[hp_type[unit]];
13510334Shelge 	int cn, tn, sn, bytecnt, bytesleft;
13610334Shelge 	char *membase;
13710334Shelge 	int er1, er2, hprecal;
13810334Shelge 
13910334Shelge 	sectsiz = SECTSIZ;
14010334Shelge 	if ((io->i_flgs & (F_HDR|F_HCHECK)) != 0)
14110334Shelge 		sectsiz += HDRSIZ;
14210334Shelge 	if ((hpaddr->hpds & HPDS_VV) == 0) {
14310334Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
14410334Shelge 		hpaddr->hpcs1 = HP_PRESET|HP_GO;
14511084Ssam 		if (!ML11)
14610334Shelge 			hpaddr->hpof = HPOF_FMT22;
14710334Shelge 	}
14810334Shelge 	io->i_errcnt = 0;
14911366Ssam 	ssect[unit] = 0;
15010334Shelge 	bytecnt = io->i_cc;
15110334Shelge 	membase = io->i_ma;
15210334Shelge 	startblock = io->i_bn;
15310608Ssam 	hprecal = 0;
15411140Ssam 
15510626Shelge restart:
15610334Shelge 	bn = io->i_bn;
15710334Shelge 	cn = bn/st->nspc;
15810334Shelge 	sn = bn%st->nspc;
15910334Shelge 	tn = sn/st->nsect;
16011366Ssam 	sn = sn%st->nsect + ssect[unit];
16110334Shelge 
16210864Ssam 	HPWAIT(hpaddr);
16310626Shelge 	mba->mba_sr = -1;
16410647Shelge 	if (ML11)
16510334Shelge 		hpaddr->hpda = bn;
16610334Shelge 	else {
16710334Shelge 		hpaddr->hpdc = cn;
16810334Shelge 		hpaddr->hpda = (tn << 8) + sn;
16910334Shelge 	}
17010334Shelge 	if (mbastart(io, func) != 0)		/* start transfer */
17110334Shelge 		return (-1);
17210864Ssam 	HPWAIT(hpaddr);
17311366Ssam 	/*
17411366Ssam 	 * Successful data transfer, return.
17511366Ssam 	 */
176*15068Skarels 	if ((hpaddr->hpds&HPDS_ERR) == 0 && (mba->mba_sr&MBSR_EBITS) == 0)
177*15068Skarels 		goto done;
17810334Shelge 
17911366Ssam 	/*
18011366Ssam 	 * Error handling.  Calculate location of error.
18111366Ssam 	 */
18211366Ssam 	bytesleft = MASKREG(mba->mba_bcr);
18311366Ssam 	if (bytesleft)
18411366Ssam 		bytesleft |= 0xffff0000;	/* sxt */
18511366Ssam 	bn = io->i_bn + (io->i_cc + bytesleft) / sectsiz;
18615052Skarels 	er1 = MASKREG(hpaddr->hper1);
18715052Skarels 	er2 = MASKREG(hpaddr->hper2);
18815052Skarels 	if (er1 & (HPER1_DCK|HPER1_ECH))
18915052Skarels 		bn--;	/* Error is in Prev block */
19010334Shelge 	cn = bn/st->nspc;
19110334Shelge 	sn = bn%st->nspc;
19210334Shelge 	tn = sn/st->nsect;
19310334Shelge 	sn = sn%st->nsect;
19411366Ssam 	if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG)) {
19511366Ssam 		printf("hp error: (cyl,trk,sec)=(%d,%d,%d) ds=%b\n",
19611366Ssam 			cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
19711366Ssam 		printf("er1=%b er2=%b\n", er1, HPER1_BITS, er2, HPER2_BITS);
19811366Ssam 		printf("bytes left: %d, of 0x%x, da 0x%x\n",-bytesleft,
19911366Ssam 			hpaddr->hpof, hpaddr->hpda);
20011366Ssam 	}
20110334Shelge 	if (er1 & HPER1_HCRC) {
20210334Shelge 		er1 &= ~(HPER1_HCE|HPER1_FER);
20310334Shelge 		er2 &= ~HPER2_BSE;
20410334Shelge 	}
20511140Ssam 	/*
20611140Ssam 	 * Give up early if drive write locked.
20711140Ssam 	 */
20810334Shelge 	if (er1&HPER1_WLE) {
20910334Shelge 		printf("hp%d: write locked\n", unit);
21011084Ssam 		return (-1);
21111084Ssam 	}
21211140Ssam 	/*
21311366Ssam 	 * Interpret format error bit as a bad block on RP06's.
21411140Ssam 	 */
21511084Ssam 	if (MASKREG(er1) == HPER1_FER && RP06)
21610334Shelge 		goto badsect;
21711140Ssam 
21811140Ssam 	/*
21911140Ssam 	 * If a hard error, or maximum retry count
22011140Ssam 	 * exceeded, clear controller state and
22111140Ssam 	 * pass back error to caller.
22211140Ssam 	 */
22311084Ssam 	if (++io->i_errcnt > 27 || (er1 & HPER1_HARD) ||
22411084Ssam 	    (!ML11 && (er2 & HPER2_HARD))) {
22515052Skarels 		/*
22615052Skarels 		 * The last ditch effort to bad sector forward
22715052Skarels 		 * below will probably fail since mba byte ctr
22815052Skarels 		 * (bcr) is different for BSE and ECC errors and
22915052Skarels 		 * the wrong block will be revectored to if one
23015052Skarels 		 * has 2 contiguous bad blocks and reads the second.
23115052Skarels 		 * For now, we can probably just let a header CRC
23215052Skarels 		 * error be handled like a BSE since no data will
23315052Skarels 		 * have been transferred and the bcr should the same
23415052Skarels 		 * as it would with a BSE error.
23515052Skarels 		 * --ghg.
23615052Skarels 		 */
23715052Skarels 		if (er1 & HPER1_HCRC)
23815052Skarels 			if ((io->i_flgs&F_NBSF) == 0 && hpecc(io, BSE) == 0)
23915052Skarels 				goto success;
24010608Ssam hard0:
24110334Shelge 		io->i_error = EHER;
24211084Ssam 		if (mba->mba_sr & (MBSR_WCKUP|MBSR_WCKLWR))
24310334Shelge 			io->i_error = EWCK;
24410334Shelge hard:
24511366Ssam 		io->i_errblk = bn + ssect[unit];
24610334Shelge 		printf("hp error: (cyl,trk,sec)=(%d,%d,%d) ds=%b \n",
24710334Shelge 			   cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS);
24811084Ssam 		printf("er1=%b er2=%b", er1, HPER1_BITS, er2, HPER2_BITS);
24910334Shelge 		if (hpaddr->hpmr)
25010626Shelge 			printf(" mr1=%o", MASKREG(hpaddr->hpmr));
25110334Shelge 		if (hpaddr->hpmr2)
25210626Shelge 			printf(" mr2=%o", MASKREG(hpaddr->hpmr2));
25311366Ssam 		if (hpdebug[unit] & (HPF_BSEDEBUG|HPF_ECCDEBUG))
25411366Ssam 			printf(" dc=%d, da=0x%x",MASKREG(hpaddr->hpdc),
25511366Ssam 			  MASKREG(hpaddr->hpda));
25610626Shelge 		hpaddr->hpcs1 = HP_DCLR|HP_GO;
25710334Shelge 		printf("\n");
258*15068Skarels 		bytecnt = -1;
259*15068Skarels 		goto done;
26010334Shelge 
26111084Ssam 	}
26211140Ssam 	/*
26311140Ssam 	 * Attempt to forward bad sectors on
26411140Ssam 	 * anything but an ML11.  If drive
26511140Ssam 	 * supports skip sector handling, try to
26611140Ssam 	 * use it first; otherwise try the
26711140Ssam 	 * bad sector table.
26811140Ssam 	 */
26911084Ssam 	if ((er2 & HPER2_BSE) && !ML11) {
27010334Shelge badsect:
27111366Ssam 		if (!ssect[unit] && (er2&HPER2_SSE))
27210647Shelge 			goto skipsect;
27311084Ssam 		if (io->i_flgs & F_NBSF) {
27410334Shelge 			io->i_error = EBSE;
27510334Shelge 			goto hard;
27610334Shelge 		}
27710334Shelge 		if (hpecc(io, BSE) == 0)
27810334Shelge 			goto success;
27911084Ssam 		io->i_error = EBSE;
28011084Ssam 		goto hard;
28111084Ssam 	}
28211140Ssam 
28311140Ssam 	/*
28411140Ssam 	 * Skip sector handling.
28511140Ssam 	 */
28611366Ssam 	if (RM80 && (er2 & HPER2_SSE)) {
28710647Shelge skipsect:
28810334Shelge 		(void) hpecc(io, SSE);
28911366Ssam 		ssect[unit] = 1;
29010334Shelge 		goto success;
29111084Ssam 	}
29211140Ssam 	/*
29311366Ssam 	 * ECC correction?
29411140Ssam 	 */
29511084Ssam 	if ((er1 & (HPER1_DCK|HPER1_ECH)) == HPER1_DCK) {
29610864Ssam 		if (hpecc(io, ECC) == 0)
29710334Shelge 			goto success;
29811084Ssam 		io->i_error = EECC;
29915052Skarels 		io->i_errblk = bn + ssect[unit];
30011084Ssam 		return (-1);
30110608Ssam 	}
30215052Skarels #ifdef F_SEVRE
30315052Skarels 	if (io->i_flgs & F_SEVRE)
30415052Skarels 		goto hard;
30515052Skarels #endif
30610608Ssam 	if (ML11 && (io->i_errcnt >= 16))
30711084Ssam 		goto hard0;
30810608Ssam 	/* fall thru to retry */
30910334Shelge 	hpaddr->hpcs1 = HP_DCLR|HP_GO;
31010864Ssam 	HPWAIT(hpaddr);
31111140Ssam 
31211140Ssam 	/*
31311140Ssam 	 * Every fourth retry recalibrate.
31411140Ssam 	 */
31511366Ssam 	if (((io->i_errcnt & 07) == 4) ) {
31610334Shelge 		hpaddr->hpcs1 = HP_RECAL|HP_GO;
31715052Skarels 		HPWAIT(hpaddr);
31810334Shelge 		hpaddr->hpdc = cn;
31910334Shelge 		hpaddr->hpcs1 = HP_SEEK|HP_GO;
32015052Skarels 		HPWAIT(hpaddr);
32115052Skarels 	}
32210864Ssam 
32315052Skarels 	if (io->i_errcnt >= 16 && (io->i_flgs & F_READ)) {
32410334Shelge 		hpaddr->hpof = hp_offset[io->i_errcnt & 017]|HPOF_FMT22;
32510334Shelge 		hpaddr->hpcs1 = HP_OFFSET|HP_GO;
32615052Skarels 		HPWAIT(hpaddr);
32710334Shelge 	}
32815052Skarels 	if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG))
32915052Skarels 		printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
33015052Skarels 		  io->i_bn, io->i_cc, io->i_ma, hprecal);
33115052Skarels 	goto restart;	/* retry whole transfer  --ghg */
33211084Ssam 
33311140Ssam success:
33411140Ssam 	/*
33511140Ssam 	 * On successful error recovery, bump
33611140Ssam 	 * block number to advance to next portion
33711140Ssam 	 * of i/o transfer.
33811140Ssam 	 */
33910334Shelge 	bn++;
34010334Shelge 	if ((bn-startblock) * sectsiz < bytecnt) {
34110334Shelge 		io->i_bn = bn;
34210334Shelge 		io->i_ma = membase + (io->i_bn - startblock)*sectsiz;
34310334Shelge 		io->i_cc = bytecnt - (io->i_bn - startblock)*sectsiz;
34411366Ssam 		if (hpdebug[unit] & (HPF_ECCDEBUG|HPF_BSEDEBUG))
34511366Ssam 			printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n",
34611366Ssam 			  io->i_bn, io->i_cc, io->i_ma, hprecal);
34710626Shelge 		goto restart;
34810334Shelge 	}
349*15068Skarels done:
35015052Skarels 	if (io->i_errcnt >= 16) {
35115052Skarels 		hpaddr->hpcs1 = HP_RTC|HP_GO;
35215052Skarels 		while (hpaddr->hpds & HPDS_PIP)
35315052Skarels 			;
35415052Skarels 	}
35510334Shelge 	return (bytecnt);
35610334Shelge }
35710864Ssam 
35810334Shelge hpecc(io, flag)
35910334Shelge 	register struct iob *io;
36010334Shelge 	int flag;
36110334Shelge {
36210334Shelge 	register unit = io->i_unit;
36310334Shelge 	register struct mba_regs *mbp = mbamba(unit);
36410334Shelge 	register struct hpdevice *rp = (struct hpdevice *)mbadrv(unit);
36510353Shelge 	register struct st *st = &hpst[hp_type[unit]];
36611084Ssam 	int npf, bn, cn, tn, sn, bcr;
36710334Shelge 
36811366Ssam 	bcr = MASKREG(mbp->mba_bcr);
36911366Ssam 	if (bcr)
37011366Ssam 		bcr |= 0xffff0000;		/* sxt */
37111084Ssam 	npf = (bcr + io->i_cc) / sectsiz;	/* # sectors read */
37215052Skarels 	if (flag == ECC)
37315052Skarels 		npf--;		/* Error is in prev block --ghg */
37411366Ssam 	bn = io->i_bn + npf + ssect[unit];	/* physical block #*/
37511366Ssam 	if (hpdebug[unit]&HPF_ECCDEBUG)
37611366Ssam 		printf("bcr=%d npf=%d ssect=%d sectsiz=%d i_cc=%d\n",
37711366Ssam 			bcr, npf, ssect[unit], sectsiz, io->i_cc);
37811140Ssam 	/*
37911140Ssam 	 * ECC correction logic.
38011140Ssam 	 */
38111140Ssam 	if (flag == ECC) {
38210334Shelge 		register int i;
38310334Shelge 		caddr_t addr;
38411179Ssam 		int bit, o, mask, ecccnt = 0;
38510334Shelge 
38610413Shelge 		printf("hp%d: soft ecc sn%d\n", unit, bn);
38710334Shelge 		mask = MASKREG(rp->hpec2);
38811084Ssam 		i = MASKREG(rp->hpec1) - 1;	/* -1 makes 0 origin */
38910334Shelge 		bit = i&07;
39011366Ssam 		o = (i & ~07) >> 3;
39110334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
39211179Ssam 		while (o <sectsiz && npf*sectsiz + o < io->i_cc && bit > -11) {
39311179Ssam 			addr = io->i_ma + (npf*sectsiz) + o;
39411179Ssam 			/*
39511179Ssam 			 * No data transfer occurs with a write check,
39611179Ssam 			 * so don't correct the resident copy of data.
39711179Ssam 			 */
39811366Ssam 			if ((io->i_flgs & (F_CHECK|F_HCHECK)) == 0) {
39911366Ssam 				if (hpdebug[unit] & HPF_ECCDEBUG)
40011366Ssam 					printf("addr=%x old=%x ", addr,
40111366Ssam 						(*addr & 0xff));
40211140Ssam 				*addr ^= (mask << bit);
40311366Ssam 				if (hpdebug[unit] & HPF_ECCDEBUG)
40411366Ssam 					printf("new=%x\n",(*addr & 0xff));
40511366Ssam 			}
40611179Ssam 			o++, bit -= 8;
40711109Ssam 			if ((io->i_flgs & F_ECCLM) && ecccnt++ >= MAXECC)
40811084Ssam 				return (1);
40910334Shelge 		}
41015052Skarels #ifdef F_SEVRE
41115052Skarels 		if (io->i_flgs & F_SEVRE)
41215052Skarels 			return(1);
41315052Skarels #endif
41411179Ssam 		return (0);
41511084Ssam 	}
41610334Shelge 
41711084Ssam 	/*
41811084Ssam 	 * Skip sector error.
41911084Ssam 	 * Set skip-sector-inhibit and
42011084Ssam 	 * read next sector
42111084Ssam 	 */
42211140Ssam 	if (flag == SSE) {
42310334Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
42410864Ssam 		HPWAIT(rp);
42510334Shelge 		rp->hpof |= HPOF_SSEI;
42611084Ssam 		return (0);
42711140Ssam 	}
42810334Shelge 
42911140Ssam 	/*
43011140Ssam 	 * Bad block forwarding.
43111140Ssam 	 */
43211140Ssam 	 if (flag == BSE) {
43310626Shelge 		int bbn;
43411084Ssam 
43510626Shelge 		rp->hpcs1 = HP_DCLR | HP_GO;
43611366Ssam 		if (hpdebug[unit] & HPF_BSEDEBUG)
43711366Ssam 			printf("hpecc: BSE @ bn %d\n", bn);
43810334Shelge 		cn = bn/st->nspc;
43910334Shelge 		sn = bn%st->nspc;
44010334Shelge 		tn = sn/st->nsect;
44110626Shelge 		sn = sn%st->nsect;
44210626Shelge 		bcr += sectsiz;
44310626Shelge 		if ((bbn = isbad(&hpbad[unit], cn, tn, sn)) < 0)
44411084Ssam 			return (1);
44510626Shelge 		bbn = st->ncyl*st->nspc - st->nsect - 1 - bbn;
44610626Shelge 		cn = bbn/st->nspc;
44710626Shelge 		sn = bbn%st->nspc;
44810626Shelge 		tn = sn/st->nsect;
44910626Shelge 		sn = sn%st->nsect;
45010626Shelge 		io->i_cc = sectsiz;
45110626Shelge 		io->i_ma += npf*sectsiz;
45211366Ssam 		if (hpdebug[unit] & HPF_BSEDEBUG)
45311366Ssam 			printf("revector to cn %d tn %d sn %d\n", cn, tn, sn);
45411366Ssam 		rp->hpof &= ~HPOF_SSEI;
45510626Shelge 		mbp->mba_sr = -1;
45610334Shelge 		rp->hpdc = cn;
45710334Shelge 		rp->hpda = (tn<<8) + sn;
45810334Shelge 		mbastart(io,io->i_flgs);
45911366Ssam 		io->i_errcnt = 0;
46010864Ssam 		HPWAIT(rp);
46110864Ssam 		return (rp->hpds&HPDS_ERR);
46210334Shelge 	}
46311084Ssam 	printf("hpecc: flag=%d\n", flag);
46411084Ssam 	return (1);
46510334Shelge }
46611140Ssam 
46710334Shelge /*ARGSUSED*/
46810334Shelge hpioctl(io, cmd, arg)
46910334Shelge 	struct iob *io;
47010334Shelge 	int cmd;
47110334Shelge 	caddr_t arg;
47210334Shelge {
47310647Shelge 	register unit = io->i_unit;
47410647Shelge 	struct st *st = &hpst[hp_type[unit]], *tmp;
47510647Shelge 	struct mba_drv *drv = mbadrv(unit);
47611366Ssam 	int flag;
47710334Shelge 
47810334Shelge 	switch(cmd) {
47910334Shelge 
48011366Ssam 	case SAIODEBUG:
48111366Ssam 		flag = (int)arg;
48211366Ssam 		if (flag > 0)
48311366Ssam 			hpdebug[unit] |= flag;
48411366Ssam 		else
48511366Ssam 			hpdebug[unit] &= ~flag;
48611366Ssam 		return (0);
48711366Ssam 
48810334Shelge 	case SAIODEVDATA:
48910334Shelge 		if ((drv->mbd_dt&MBDT_TAP) == 0) {
49010353Shelge 			tmp = (struct st *)arg;
49110353Shelge 			*tmp = *st;
49211084Ssam 			return (0);
49310334Shelge 		}
49411084Ssam 		return (ECMD);
49510334Shelge 
49611084Ssam 	case SAIOSSI:			/* skip-sector-inhibit */
49711084Ssam 		if (drv->mbd_dt&MBDT_TAP)
49811084Ssam 			return (ECMD);
49911084Ssam 		if ((io->i_flgs&F_SSI) == 0) {
50011084Ssam 			/* make sure this is done once only */
50111084Ssam 			io->i_flgs |= F_SSI;
50211084Ssam 			st->nsect++;
50311084Ssam 			st->nspc += st->ntrak;
50410864Ssam 		}
50511084Ssam 		return (0);
50610626Shelge 
50711084Ssam 	case SAIONOSSI:			/* remove skip-sector-inhibit */
50810626Shelge 		if (io->i_flgs & F_SSI) {
50910626Shelge 			io->i_flgs &= ~F_SSI;
51010626Shelge 			drv->mbd_of &= ~HPOF_SSEI;
51110626Shelge 			st->nsect--;
51210626Shelge 			st->nspc -= st->ntrak;
51310626Shelge 		}
51410626Shelge 		return(0);
51510626Shelge 
51610864Ssam 	case SAIOSSDEV:			/* drive have skip sector? */
51711084Ssam 		return (RM80 ? 0 : ECMD);
51810334Shelge 	}
51911084Ssam 	return (ECMD);
52010334Shelge }
521