xref: /csrg-svn/sys/vax/mba/hp.c (revision 2395)
1*2395Swnj /*	hp.c	4.8	81/02/10	*/
221Sbill 
31939Swnj #include "hp.h"
41565Sbill #if NHP > 0
521Sbill /*
62383Swnj  * RP/RM disk driver
721Sbill  */
821Sbill 
921Sbill #include "../h/param.h"
1021Sbill #include "../h/systm.h"
11305Sbill #include "../h/dk.h"
1221Sbill #include "../h/buf.h"
1321Sbill #include "../h/conf.h"
1421Sbill #include "../h/dir.h"
1521Sbill #include "../h/user.h"
1621Sbill #include "../h/map.h"
17420Sbill #include "../h/pte.h"
1821Sbill #include "../h/mba.h"
1921Sbill #include "../h/mtpr.h"
20420Sbill #include "../h/vm.h"
212362Swnj #include "../h/cmap.h"
2221Sbill 
232383Swnj #include "../h/hpreg.h"
2421Sbill 
252383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
262383Swnj struct	size {
2721Sbill 	daddr_t	nblocks;
2821Sbill 	int	cyloff;
292383Swnj } hp_sizes[8] = {
30886Sbill 	15884,	0,		/* A=cyl 0 thru 37 */
31886Sbill 	33440,	38,		/* B=cyl 38 thru 117 */
32886Sbill 	340670,	0,		/* C=cyl 0 thru 814 */
3321Sbill 	0,	0,
3421Sbill 	0,	0,
3521Sbill 	0,	0,
36886Sbill 	291346,	118,		/* G=cyl 118 thru 814 */
3721Sbill 	0,	0,
3821Sbill }, rm_sizes[8] = {
39886Sbill 	15884,	0,		/* A=cyl 0 thru 99 */
40886Sbill 	33440,	100,		/* B=cyl 100 thru 309 */
41886Sbill 	131680,	0,		/* C=cyl 0 thru 822 */
422362Swnj 	2720,	291,
4321Sbill 	0,	0,
4421Sbill 	0,	0,
45886Sbill 	82080,	310,		/* G=cyl 310 thru 822 */
4621Sbill 	0,	0,
47886Sbill }, rm5_sizes[8] = {
48886Sbill 	15884,	0,		/* A=cyl 0 thru 26 */
49886Sbill 	33440,	27,		/* B=cyl 27 thru 81 */
50886Sbill 	500992,	0,		/* C=cyl 0 thru 823 */
51886Sbill 	15884,	562,		/* D=cyl 562 thru 588 */
52886Sbill 	55936,	589,		/* E=cyl 589 thru 680 */
53886Sbill 	86944,	681,		/* F=cyl 681 thru 823 */
54886Sbill 	159296,	562,		/* G=cyl 562 thru 823 */
55886Sbill 	291346,	82,		/* H=cyl 82 thru 561 */
562383Swnj }, rm80_sizes[8] = {
572383Swnj 	15884,	0,		/* A=cyl 0 thru 36 */
582383Swnj 	33440,	37,		/* B=cyl 37 thru 114 */
592383Swnj 	242606,	0,		/* C=cyl 0 thru 558 */
602383Swnj 	0,	0,
612383Swnj 	0,	0,
622383Swnj 	0,	0,
632383Swnj 	82080,	115,		/* G=cyl 115 thru 304 */
642383Swnj 	110236,	305,		/* H=cyl 305 thru 558 */
6521Sbill };
662383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
6721Sbill 
682383Swnj #define	_hpSDIST	2
692383Swnj #define	_hpRDIST	3
702383Swnj 
712383Swnj int	hpSDIST = _hpSDIST;
722383Swnj int	hpRDIST = _hpRDIST;
732383Swnj 
742383Swnj short	hptypes[] =
752383Swnj 	{ MBDT_RM03, MBDT_RM05, MBDT_RP06, MBDT_RM80, 0 };
762383Swnj struct	mba_info *hpinfo[NHP];
772383Swnj int	hpdkinit(),hpustart(),hpstart(),hpdtint();
782383Swnj struct	mba_driver hpdriver =
792383Swnj 	{ hpdkinit, hpustart, hpstart, hpdtint, 0, hptypes, hpinfo };
802383Swnj 
812383Swnj struct hpst {
822383Swnj 	short	nsect;
832383Swnj 	short	ntrak;
842383Swnj 	short	nspc;
852383Swnj 	short	ncyl;
862383Swnj 	struct	size *sizes;
872383Swnj } hpst[] = {
882383Swnj 	32,	5,	32*5,	823,	rm_sizes,	/* RM03 */
892383Swnj 	32,	19,	32*19,	823,	rm5_sizes,	/* RM05 */
902383Swnj 	22,	19,	22*19,	815,	hp_sizes,	/* RP06 */
912383Swnj 	31,	14, 	31*14,	559,	rm80_sizes	/* RM80 */
922383Swnj };
932383Swnj 
942383Swnj int	hp_offset[16] = {
9521Sbill 	P400, M400, P400, M400,
9621Sbill 	P800, M800, P800, M800,
9721Sbill 	P1200, M1200, P1200, M1200,
9821Sbill 	0, 0, 0, 0,
9921Sbill };
10021Sbill 
10121Sbill struct	buf	rhpbuf;
10221Sbill 
10321Sbill #define	b_cylin b_resid
10421Sbill 
10521Sbill #ifdef INTRLVE
10621Sbill daddr_t dkblock();
10721Sbill #endif
10821Sbill 
10921Sbill hpstrategy(bp)
1102383Swnj 	register struct buf *bp;
11121Sbill {
1122383Swnj 	register struct mba_info *mi;
1132383Swnj 	register struct hpst *st;
1142383Swnj 	register int unit;
11521Sbill 	long sz, bn;
1162383Swnj 	int xunit = minor(bp->b_dev) & 07;
11721Sbill 
11821Sbill 	sz = bp->b_bcount;
11921Sbill 	sz = (sz+511) >> 9;
12021Sbill 	unit = dkunit(bp);
1212383Swnj 	if (unit >= NHP)
1222383Swnj 		goto bad;
1232383Swnj 	mi = hpinfo[unit];
124*2395Swnj 	if (mi == 0 || mi->mi_alive == 0)
1252383Swnj 		goto bad;
1262383Swnj 	st = &hpst[mi->mi_type];
1272383Swnj 	if (bp->b_blkno < 0 ||
1282383Swnj 	    (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
1292383Swnj 		goto bad;
1302383Swnj 	bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
131127Sbill 	(void) spl5();
1322383Swnj 	disksort(&mi->mi_tab, bp);
1332383Swnj 	if (mi->mi_tab.b_active == 0)
1342383Swnj 		mbustart(mi);
135127Sbill 	(void) spl0();
1362383Swnj 	return;
1372383Swnj 
1382383Swnj bad:
1392383Swnj 	bp->b_flags |= B_ERROR;
1402383Swnj 	iodone(bp);
1412383Swnj 	return;
14221Sbill }
14321Sbill 
1442383Swnj hpustart(mi)
1452383Swnj 	register struct mba_info *mi;
14621Sbill {
1472383Swnj 	register struct device *hpaddr = (struct device *)mi->mi_drv;
1482383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
1492383Swnj 	register struct hpst *st;
15021Sbill 	daddr_t bn;
1512383Swnj 	int sn, dist, flags;
15221Sbill 
1532383Swnj 	if ((hpaddr->hpcs1&DVA) == 0)
1542383Swnj 		return (MBU_BUSY);
1552383Swnj 	if ((hpaddr->hpds & VV) == 0) {
1562298Skre 		hpaddr->hpcs1 = DCLR|GO;
15721Sbill 		hpaddr->hpcs1 = PRESET|GO;
15821Sbill 		hpaddr->hpof = FMT22;
15921Sbill 	}
1602383Swnj 	if (mi->mi_tab.b_active)
1612383Swnj 		return (MBU_DODATA);
16221Sbill 	if ((hpaddr->hpds & (DPR|MOL)) != (DPR|MOL))
1632383Swnj 		return (MBU_DODATA);
164*2395Swnj 	if (flags&MH_NOSEEK)
165*2395Swnj 		return (MBU_DODATA);
1662383Swnj 	hpaddr->hpdc = bp->b_cylin;
167*2395Swnj 	st = &hpst[mi->mi_type];
168*2395Swnj 	bn = dkblock(bp);
169*2395Swnj 	sn = bn%st->nspc;
170*2395Swnj 	sn = (sn+st->nsect-hpSDIST)%st->nsect;
1712383Swnj 	flags = mi->mi_hd->mh_flags;
1722383Swnj 	if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) {
1732383Swnj 		if (flags&MH_NOSEARCH)
1742383Swnj 			return (MBU_DODATA);
1752383Swnj 		dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1;
1762383Swnj 		if (dist < 0)
1772383Swnj 			dist += st->nsect;
1782383Swnj 		if (dist > st->nsect - hpRDIST)
1792383Swnj 			return (MBU_DODATA);
18021Sbill 	}
1812383Swnj 	if (flags&MH_NOSEARCH)
182305Sbill 		hpaddr->hpcs1 = SEEK|GO;
183305Sbill 	else {
184305Sbill 		hpaddr->hpda = sn;
185305Sbill 		hpaddr->hpcs1 = SEARCH|GO;
186305Sbill 	}
1872383Swnj 	return (MBU_STARTED);
18821Sbill }
18921Sbill 
1902383Swnj hpstart(mi)
1912383Swnj 	register struct mba_info *mi;
19221Sbill {
1932383Swnj 	register struct device *hpaddr = (struct device *)mi->mi_drv;
1942383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
1952383Swnj 	register struct hpst *st = &hpst[mi->mi_type];
19621Sbill 	daddr_t bn;
1972383Swnj 	int sn, tn;
19821Sbill 
19921Sbill 	bn = dkblock(bp);
2002383Swnj 	sn = bn%st->nspc;
2012383Swnj 	tn = sn/st->nsect;
202*2395Swnj 	sn %= st->nsect;
2032383Swnj 	if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags&B_READ) != 0) {
2042383Swnj 		hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017] | FMT22;
20521Sbill 		hpaddr->hpcs1 = OFFSET|GO;
2062383Swnj 		while (hpaddr->hpds & PIP)
20721Sbill 			;
2082383Swnj 		mbclrattn(mi);
20921Sbill 	}
2102383Swnj 	hpaddr->hpdc = bp->b_cylin;
21121Sbill 	hpaddr->hpda = (tn << 8) + sn;
21221Sbill }
21321Sbill 
2142383Swnj hpdtint(mi, mbastat)
2152383Swnj 	register struct mba_info *mi;
2162383Swnj 	int mbastat;
21721Sbill {
2182383Swnj 	register struct device *hpaddr = (struct device *)mi->mi_drv;
2192383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
22021Sbill 
2212383Swnj 	while ((hpaddr->hpds & DRY) == 0)	/* shouldn't happen */
2222383Swnj 		printf("hp dry not set\n");
2232383Swnj 	if (hpaddr->hpds & ERR || mbastat & MBAEBITS)
2242383Swnj 		if (++mi->mi_tab.b_errcnt < 28 && (hpaddr->hper1&WLE) == 0) {
2252383Swnj 			if ((hpaddr->hper1&0xffff) != DCK) {
2262383Swnj 				hpaddr->hpcs1 = DCLR|GO;
2272383Swnj 				if ((mi->mi_tab.b_errcnt&07) == 4) {
2282383Swnj 					hpaddr->hpcs1 = RECAL|GO;
2292383Swnj 					while (hpaddr->hpds & PIP)
2302383Swnj 						;
2312383Swnj 					mbclrattn(mi);
2322383Swnj 				}
2332383Swnj 				return (MBD_RETRY);
2342383Swnj 			} else if (hpecc(mi))
2352383Swnj 				return (MBD_RESTARTED);
2362383Swnj 		} else {
2372383Swnj 			deverror(bp, mbastat, hpaddr->hper1);
2382383Swnj 			bp->b_flags |= B_ERROR;
23921Sbill 		}
2402383Swnj 	bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
2412383Swnj 	if (mi->mi_tab.b_errcnt) {
2422383Swnj 		hpaddr->hpcs1 = RTC|GO;
2432383Swnj 		while (hpaddr->hpds & PIP)
2442383Swnj 			;
2452383Swnj 		mbclrattn(mi);
24621Sbill 	}
2472383Swnj 	hpaddr->hpcs1 = RELEASE|GO;
2482383Swnj 	return (MBD_DONE);
24921Sbill }
25021Sbill 
25121Sbill hpread(dev)
25221Sbill {
25321Sbill 
25421Sbill 	physio(hpstrategy, &rhpbuf, dev, B_READ, minphys);
25521Sbill }
25621Sbill 
25721Sbill hpwrite(dev)
25821Sbill {
25921Sbill 
26021Sbill 	physio(hpstrategy, &rhpbuf, dev, B_WRITE, minphys);
26121Sbill }
26221Sbill 
2632383Swnj hpecc(mi)
2642383Swnj 	register struct mba_info *mi;
26521Sbill {
2662383Swnj 	register struct mba_regs *mbp = mi->mi_mba;
2672383Swnj 	register struct device *rp = (struct device *)mi->mi_drv;
2682383Swnj 	register struct buf *bp = mi->mi_tab.b_actf;
2692383Swnj 	register struct hpst *st;
270420Sbill 	register int i;
271420Sbill 	caddr_t addr;
272420Sbill 	int reg, bit, byte, npf, mask, o;
2732383Swnj 	int bn, cn, tn, sn;
274420Sbill 	struct pte mpte;
275914Sbill 	int bcr;
27621Sbill 
277420Sbill 	/*
278420Sbill 	 * Npf is the number of sectors transferred before the sector
279420Sbill 	 * containing the ECC error, and reg is the MBA register
280420Sbill 	 * mapping (the first part of)the transfer.
281420Sbill 	 * O is offset within a memory page of the first byte transferred.
282420Sbill 	 */
283914Sbill 	bcr = mbp->mba_bcr & 0xffff;
284914Sbill 	if (bcr)
285914Sbill 		bcr |= 0xffff0000;		/* sxt */
286719Sbill 	npf = btop(bcr + bp->b_bcount) - 1;
2871413Sbill 	reg = npf;
288420Sbill 	o = (int)bp->b_un.b_addr & PGOFSET;
289420Sbill 	printf("%D ", bp->b_blkno + npf);
29021Sbill 	prdev("ECC", bp->b_dev);
29121Sbill 	mask = rp->hpec2&0xffff;
29221Sbill 	if (mask == 0) {
29321Sbill 		rp->hpof = FMT22;
294420Sbill 		return (0);
29521Sbill 	}
296420Sbill 
297420Sbill 	/*
298420Sbill 	 * Compute the byte and bit position of the error.
299420Sbill 	 * The variable i is the byte offset in the transfer,
300420Sbill 	 * the variable byte is the offset from a page boundary
301420Sbill 	 * in main memory.
302420Sbill 	 */
303420Sbill 	i = (rp->hpec1&0xffff) - 1;		/* -1 makes 0 origin */
304719Sbill 	bit = i&07;
305420Sbill 	i = (i&~07)>>3;
306420Sbill 	byte = i + o;
307420Sbill 	/*
308420Sbill 	 * Correct while possible bits remain of mask.  Since mask
309420Sbill 	 * contains 11 bits, we continue while the bit offset is > -11.
310420Sbill 	 * Also watch out for end of this block and the end of the whole
311420Sbill 	 * transfer.
312420Sbill 	 */
313420Sbill 	while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
314420Sbill 		mpte = mbp->mba_map[reg+btop(byte)];
315420Sbill 		addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
316420Sbill 		putmemc(addr, getmemc(addr)^(mask<<bit));
317420Sbill 		byte++;
318420Sbill 		i++;
319420Sbill 		bit -= 8;
32021Sbill 	}
3212383Swnj 	mi->mi_hd->mh_active++;		/* Either complete or continuing */
322719Sbill 	if (bcr == 0)
323420Sbill 		return (0);
324420Sbill 	/*
325420Sbill 	 * Have to continue the transfer... clear the drive,
326420Sbill 	 * and compute the position where the transfer is to continue.
327420Sbill 	 * We have completed npf+1 sectores of the transfer already;
328420Sbill 	 * restart at offset o of next sector (i.e. in MBA register reg+1).
329420Sbill 	 */
330420Sbill 	rp->hpcs1 = DCLR|GO;
331420Sbill 	bn = dkblock(bp);
3322383Swnj 	st = &hpst[mi->mi_type];
333420Sbill 	cn = bp->b_cylin;
3342383Swnj 	sn = bn%(st->nspc) + npf + 1;
3352383Swnj 	tn = sn/st->nsect;
3362383Swnj 	sn %= st->nsect;
3372383Swnj 	cn += tn/st->ntrak;
3382383Swnj 	tn %= st->ntrak;
339420Sbill 	rp->hpdc = cn;
340420Sbill 	rp->hpda = (tn<<8) + sn;
341420Sbill 	mbp->mba_sr = -1;
342420Sbill 	mbp->mba_var = (int)ptob(reg+1) + o;
343420Sbill 	rp->hpcs1 = RCOM|GO;
344420Sbill 	return (1);
34521Sbill }
3462362Swnj 
3472362Swnj #define	DBSIZE	20
3482362Swnj 
3492362Swnj hpdump(dev)
3502362Swnj 	dev_t dev;
3512362Swnj {
3522383Swnj 	register struct mba_info *mi;
3532383Swnj 	register struct mba_regs *mba;
3542362Swnj 	struct device *hpaddr;
3552362Swnj 	char *start;
3562383Swnj 	int num, unit;
3572383Swnj 	register struct hpst *st;
3582362Swnj 
3592362Swnj 	num = maxfree;
3602362Swnj 	start = 0;
3612362Swnj 	unit = minor(dev) >> 3;
3622362Swnj 	if (unit >= NHP) {
3632362Swnj 		printf("bad unit\n");
3642362Swnj 		return (-1);
3652362Swnj 	}
3662383Swnj #define	phys(a,b)	((b)((int)(a)&0x7fffffff))
3672383Swnj 	mi = phys(hpinfo[unit],struct mba_info *);
3682383Swnj 	if (mi->mi_alive == 0) {
3692383Swnj 		printf("dna\n");
3702383Swnj 		return (-1);
3712383Swnj 	}
3722383Swnj 	mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
3732383Swnj 	mba->mba_cr = MBAINIT;
3742383Swnj 	hpaddr = (struct device *)&mba->mba_drv[mi->mi_drive];
3752383Swnj 	if ((hpaddr->hpds & VV) == 0) {
3762383Swnj 		hpaddr->hpcs1 = DCLR|GO;
3772362Swnj 		hpaddr->hpcs1 = PRESET|GO;
3782362Swnj 		hpaddr->hpof = FMT22;
3792362Swnj 	}
3802383Swnj 	st = &hpst[mi->mi_type];
3812383Swnj 	if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) {
3822383Swnj 		printf("oor\n");
3832362Swnj 		return (-1);
3842362Swnj 	}
3852362Swnj 	while (num > 0) {
3862383Swnj 		register struct pte *hpte = mba->mba_map;
3872362Swnj 		register int i;
3882383Swnj 		int blk, cn, sn, tn;
3892362Swnj 		daddr_t bn;
3902362Swnj 
3912362Swnj 		blk = num > DBSIZE ? DBSIZE : num;
3922362Swnj 		bn = dumplo + btop(start);
3932383Swnj 		cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
3942383Swnj 		sn = bn%st->nspc;
3952383Swnj 		tn = sn/st->nsect;
3962383Swnj 		sn = sn%st->nsect;
3972362Swnj 		hpaddr->hpdc = cn;
3982362Swnj 		hpaddr->hpda = (tn << 8) + sn;
3992362Swnj 		for (i = 0; i < blk; i++)
4002362Swnj 			*(int *)hpte++ = (btop(start)+i) | PG_V;
4012383Swnj 		mba->mba_sr = -1;
4022383Swnj 		mba->mba_bcr = -(blk*NBPG);
4032383Swnj 		mba->mba_var = 0;
4042362Swnj 		hpaddr->hpcs1 = WCOM | GO;
4052362Swnj 		while ((hpaddr->hpds & DRY) == 0)
4062362Swnj 			;
4072362Swnj 		if (hpaddr->hpds&ERR) {
4082383Swnj 			printf("dskerr: (%d,%d,%d) ds=%x er=%x\n",
4092362Swnj 			    cn, tn, sn, hpaddr->hpds, hpaddr->hper1);
4102362Swnj 			return (-1);
4112362Swnj 		}
4122362Swnj 		start += blk*NBPG;
4132362Swnj 		num -= blk;
4142362Swnj 	}
4152362Swnj 	return (0);
4162362Swnj }
4172383Swnj 
4182383Swnj hpdkinit()
4192383Swnj {
4202383Swnj 	/* I don't really care what this does .. kre */
4212383Swnj }
4221565Sbill #endif
423