1*12506Ssam /* hp.c 4.75 83/05/18 */ 23706Sroot 33706Sroot #ifdef HPDEBUG 43289Swnj int hpdebug; 53706Sroot #endif 63706Sroot #ifdef HPBDEBUG 73706Sroot int hpbdebug; 83706Sroot #endif 921Sbill 101939Swnj #include "hp.h" 111565Sbill #if NHP > 0 1221Sbill /* 135726Sroot * HP disk driver for RP0x+RMxx+ML11 142827Swnj * 152827Swnj * TODO: 163706Sroot * check RM80 skip sector handling when ECC's occur later 173093Swnj * check offset recovery handling 183706Sroot * see if DCLR and/or RELEASE set attention status 193706Sroot * print bits of mr && mr2 symbolically 2021Sbill */ 219786Ssam #include "../machine/pte.h" 2221Sbill 2321Sbill #include "../h/param.h" 2421Sbill #include "../h/systm.h" 25305Sbill #include "../h/dk.h" 2621Sbill #include "../h/buf.h" 2721Sbill #include "../h/conf.h" 2821Sbill #include "../h/dir.h" 2921Sbill #include "../h/user.h" 3021Sbill #include "../h/map.h" 318468Sroot #include "../vax/mtpr.h" 32420Sbill #include "../h/vm.h" 332362Swnj #include "../h/cmap.h" 343706Sroot #include "../h/dkbad.h" 357635Ssam #include "../h/ioctl.h" 367738Sroot #include "../h/uio.h" 3721Sbill 388988Sroot #include "../vax/dkio.h" 398468Sroot #include "../vaxmba/mbareg.h" 408468Sroot #include "../vaxmba/mbavar.h" 418468Sroot #include "../vaxmba/hpreg.h" 4221Sbill 432383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 442383Swnj struct size { 4521Sbill daddr_t nblocks; 4621Sbill int cyloff; 4711212Ssam } rp06_sizes[8] = { 48886Sbill 15884, 0, /* A=cyl 0 thru 37 */ 49886Sbill 33440, 38, /* B=cyl 38 thru 117 */ 50886Sbill 340670, 0, /* C=cyl 0 thru 814 */ 5111212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 5211212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 5311212Ssam 219384, 290, /* F=cyl 290 thru 814 */ 5411212Ssam 291280, 118, /* G=cyl 118 thru 814 */ 5521Sbill 0, 0, 5611212Ssam }, rp05_sizes[8] = { 5711212Ssam 15884, 0, /* A=cyl 0 thru 37 */ 5811212Ssam 33440, 38, /* B=cyl 38 thru 117 */ 5911212Ssam 171798, 0, /* C=cyl 0 thru 410 */ 6011212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 6111212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 6211212Ssam 50512, 290, /* F=cyl 290 thru 410 */ 6311212Ssam 122408, 118, /* G=cyl 118 thru 410 */ 6421Sbill 0, 0, 6511212Ssam }, rm03_sizes[8] = { 66886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 6711212Ssam 33440, 100, /* B=cyl 100 thru 308 */ 68886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 6911212Ssam 15884, 309, /* D=cyl 309 thru 408 */ 7011212Ssam 55936, 409, /* E=cyl 409 thru 758 */ 7111212Ssam 10144, 759, /* F=cyl 759 thru 822 */ 7211212Ssam 82144, 309, /* G=cyl 309 thru 822 */ 7321Sbill 0, 0, 7411212Ssam }, rm05_sizes[8] = { 75886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 76886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 773271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 78886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 79886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 803729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 813729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 82886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 832383Swnj }, rm80_sizes[8] = { 842383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 852383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 862383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 8711212Ssam 15884, 115, /* D=cyl 115 thru 151 */ 8811212Ssam 55936, 152, /* E=cyl 152 thru 280 */ 8911212Ssam 120559, 281, /* F=cyl 281 thru 558 */ 9011212Ssam 192603, 115, /* G=cyl 115 thru 558 */ 912383Swnj 0, 0, 9211212Ssam }, rp07_sizes[8] = { 936927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 9411212Ssam 66880, 10, /* B=cyl 10 thru 51 */ 9511212Ssam 1008000, 0, /* C=cyl 0 thru 629 */ 9611212Ssam 15884, 235, /* D=cyl 235 thru 244 */ 9711212Ssam 307200, 245, /* E=cyl 245 thru 436 */ 9811212Ssam 308650, 437, /* F=cyl 437 thru 629 */ 9911212Ssam 631850, 235, /* G=cyl 235 thru 629 */ 10011212Ssam 291346, 52, /* H=cyl 52 thru 234 */ 10111212Ssam }, cdc9775_sizes[8] = { 10211212Ssam 15884, 0, /* A=cyl 0 thru 12 */ 10311212Ssam 66880, 13, /* B=cyl 13 thru 65 */ 10411212Ssam 1079040, 0, /* C=cyl 0 thru 842 */ 10511212Ssam 15884, 294, /* D=cyl 294 thru 306 */ 10611212Ssam 307200, 307, /* E=cyl 307 thru 546 */ 10711212Ssam 378784, 547, /* F=cyl 547 thru 842 */ 10811212Ssam 702624, 294, /* G=cyl 294 thru 842 */ 10911212Ssam 291346, 66, /* H=cyl 66 thru 293 */ 11011212Ssam }, cdc9730_sizes[8] = { 1116927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1126927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1136927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 11411212Ssam 15884, 155, /* D=cyl 155 thru 204 */ 11511212Ssam 55936, 205, /* E=cyl 205 thru 379 */ 11611212Ssam 141664, 380, /* F=cyl 380 thru 822 */ 11711212Ssam 213664, 155, /* G=cyl 155 thru 822 */ 1186927Ssam 0, 0, 11911212Ssam }, capricorn_sizes[8] = { 1206927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1216927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1226927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 12311212Ssam 15884, 668, /* D=cyl 668 thru 699 */ 12411212Ssam 55936, 700, /* E=cyl 700 thru 809 */ 12511212Ssam 109472, 810, /* F=cyl 810 thru 1023 */ 12611212Ssam 182176, 668, /* G=cyl 668 thru 1023 */ 1276927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 12811212Ssam }, eagle_sizes[8] = { 12910734Ssam 15884, 0, /* A=cyl 0 thru 16 */ 13011212Ssam 66880, 17, /* B=cyl 17 thru 86 */ 13111629Ssam 808320, 0, /* C=cyl 0 thru 841 */ 13211212Ssam 15884, 391, /* D=cyl 391 thru 407 */ 13311212Ssam 307200, 408, /* E=cyl 408 thru 727 */ 13411629Ssam 109296, 728, /* F=cyl 728 thru 841 */ 13511629Ssam 432816, 391, /* G=cyl 391 thru 841 */ 13611212Ssam 291346, 87, /* H=cyl 87 thru 390 */ 13711281Ssam }, cdc9300_sizes[8] = { 13811281Ssam 15884, 0, /* A=cyl 0 thru 26 */ 13911281Ssam 33440, 27, /* B=cyl 27 thru 81 */ 14011281Ssam 500384, 0, /* C=cyl 0 thru 822 */ 14111281Ssam 15884, 562, /* D=cyl 562 thru 588 */ 14211281Ssam 55936, 589, /* E=cyl 589 thru 680 */ 14311281Ssam 86240, 681, /* F=cyl 681 thru 822 */ 14411281Ssam 158592, 562, /* G=cyl 562 thru 822 */ 14511281Ssam 291346, 82, /* H=cyl 82 thru 561 */ 14621Sbill }; 1472383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 14821Sbill 1492383Swnj #define _hpSDIST 2 1502383Swnj #define _hpRDIST 3 1512383Swnj 1522383Swnj int hpSDIST = _hpSDIST; 1532383Swnj int hpRDIST = _hpRDIST; 1542383Swnj 1556927Ssam /* 1566927Ssam * Table for converting Massbus drive types into 1576927Ssam * indices into the partition tables. Slots are 1586927Ssam * left for those drives devined from other means 1596927Ssam * (e.g. SI, AMPEX, etc.). 1606927Ssam */ 1616927Ssam short hptypes[] = { 1626927Ssam #define HPDT_RM03 0 1636927Ssam MBDT_RM03, 1646927Ssam #define HPDT_RM05 1 1656927Ssam MBDT_RM05, 1666927Ssam #define HPDT_RP06 2 1676927Ssam MBDT_RP06, 1686927Ssam #define HPDT_RM80 3 1696927Ssam MBDT_RM80, 1706927Ssam #define HPDT_RP05 4 1716927Ssam MBDT_RP05, 1726927Ssam #define HPDT_RP07 5 1736927Ssam MBDT_RP07, 1746927Ssam #define HPDT_ML11A 6 1756927Ssam MBDT_ML11A, 1766927Ssam #define HPDT_ML11B 7 1776927Ssam MBDT_ML11B, 1786927Ssam #define HPDT_9775 8 1796927Ssam -1, 1806927Ssam #define HPDT_9730 9 1816927Ssam -1, 1826927Ssam #define HPDT_CAPRICORN 10 1836927Ssam -1, 1849175Ssam #define HPDT_EAGLE 11 1859175Ssam -1, 18611281Ssam #define HPDT_9300 12 18711281Ssam -1, 18811281Ssam #define HPDT_RM02 13 1899175Ssam MBDT_RM02, /* beware, actually capricorn or eagle */ 1906927Ssam 0 1916927Ssam }; 1922978Swnj struct mba_device *hpinfo[NHP]; 1932978Swnj int hpattach(),hpustart(),hpstart(),hpdtint(); 1942383Swnj struct mba_driver hpdriver = 1952978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1962978Swnj hptypes, "hp", 0, hpinfo }; 1972383Swnj 1982383Swnj struct hpst { 1992383Swnj short nsect; 2002383Swnj short ntrak; 2012383Swnj short nspc; 2022383Swnj short ncyl; 2032383Swnj struct size *sizes; 2042383Swnj } hpst[] = { 20511212Ssam 32, 5, 32*5, 823, rm03_sizes, /* RM03 */ 20611212Ssam 32, 19, 32*19, 823, rm05_sizes, /* RM05 */ 20711212Ssam 22, 19, 22*19, 815, rp06_sizes, /* RP06 */ 2083706Sroot 31, 14, 31*14, 559, rm80_sizes, /* RM80 */ 20911212Ssam 22, 19, 22*19, 411, rp05_sizes, /* RP05 */ 21011212Ssam 50, 32, 50*32, 630, rp07_sizes, /* RP07 */ 2115726Sroot 1, 1, 1, 1, 0, /* ML11A */ 2125726Sroot 1, 1, 1, 1, 0, /* ML11B */ 21311212Ssam 32, 40, 32*40, 843, cdc9775_sizes, /* 9775 */ 21411212Ssam 32, 10, 32*10, 823, cdc9730_sizes, /* 9730 */ 21511281Ssam 32, 16, 32*16, 1024, capricorn_sizes,/* Capricorn */ 21611281Ssam 48, 20, 48*20, 842, eagle_sizes, /* EAGLE */ 21711281Ssam 32, 19, 32*19, 815, cdc9300_sizes, /* 9300 */ 2182383Swnj }; 2192383Swnj 2202624Swnj u_char hp_offset[16] = { 2213093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 2223093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 2233093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 2243093Swnj 0, 0, 0, 0, 22521Sbill }; 22621Sbill 2272624Swnj struct buf rhpbuf[NHP]; 2283706Sroot struct buf bhpbuf[NHP]; 2293706Sroot struct dkbad hpbad[NHP]; 23021Sbill 23110857Ssam struct hpsoftc { 23210857Ssam u_char sc_hpinit; /* drive initialized */ 23310857Ssam u_char sc_recal; /* recalibrate state */ 23410857Ssam u_char sc_hdr; /* next i/o includes header */ 23510857Ssam u_char sc_doseeks; /* perform explicit seeks */ 23610857Ssam daddr_t sc_mlsize; /* ML11 size */ 23710857Ssam } hpsoftc[NHP]; 23810857Ssam 23921Sbill #define b_cylin b_resid 24021Sbill 2415726Sroot /* #define ML11 0 to remove ML11 support */ 2425726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2435726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2445726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2455726Sroot 24611202Ssam #define MASKREG(reg) ((reg)&0xffff) 24711202Ssam 24821Sbill #ifdef INTRLVE 24921Sbill daddr_t dkblock(); 25021Sbill #endif 2512604Swnj 2522978Swnj /*ARGSUSED*/ 2532978Swnj hpattach(mi, slave) 25410734Ssam register struct mba_device *mi; 2552604Swnj { 25610734Ssam 25710734Ssam mi->mi_type = hpmaptype(mi); 25810734Ssam if (!ML11 && mi->mi_dk >= 0) { 25910734Ssam struct hpst *st = &hpst[mi->mi_type]; 26010734Ssam 26110734Ssam dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 26210734Ssam } 26310734Ssam } 26410734Ssam 26510734Ssam /* 26610734Ssam * Map apparent MASSBUS drive type into manufacturer 26710734Ssam * specific configuration. For SI controllers this is done 26810734Ssam * based on codes in the serial number register. For 26910734Ssam * EMULEX controllers, the track and sector attributes are 27010734Ssam * used when the drive type is an RM02 (not supported by DEC). 27110734Ssam */ 27210734Ssam hpmaptype(mi) 27310734Ssam register struct mba_device *mi; 27410734Ssam { 2756927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 27610734Ssam register int type = mi->mi_type; 2776927Ssam 2786927Ssam /* 27911281Ssam * Model-byte processing for SI controllers. 2806927Ssam * NB: Only deals with RM03 and RM05 emulations. 2816927Ssam */ 28210734Ssam if (type == HPDT_RM03 || type == HPDT_RM05) { 28310734Ssam int hpsn = hpaddr->hpsn; 2846927Ssam 2856927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 28610734Ssam return (type); 2876927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 2886927Ssam 2896927Ssam case SI9775D: 29011281Ssam printf("hp%d: 9775 (direct)\n", mi->mi_unit); 29110734Ssam type = HPDT_9775; 2926927Ssam break; 2936927Ssam 2946927Ssam case SI9730D: 29511281Ssam printf("hp%d: 9730 (direct)\n", mi->mi_unit); 29610734Ssam type = HPDT_9730; 2976927Ssam break; 2986927Ssam 2997035Swnj /* 30011281Ssam * Beware, since the only SI controller we 30111281Ssam * have has a 9300 instead of a 9766, we map the 30211281Ssam * drive type into the 9300. This means that 30311281Ssam * on a 9766 you lose the last 8 cylinders (argh). 3047035Swnj */ 3056927Ssam case SI9766: 30611281Ssam printf("hp%d: 9300\n", mi->mi_unit); 30711281Ssam type = HPDT_9300; 3086927Ssam break; 3096927Ssam 3106927Ssam case SI9762: 3116927Ssam printf("hp%d: 9762\n", mi->mi_unit); 31210734Ssam type = HPDT_RM03; 3136927Ssam break; 31411281Ssam 31511281Ssam case SICAPD: 31611281Ssam printf("hp%d: capricorn\n", mi->mi_unit); 31711281Ssam type = HPDT_CAPRICORN; 31811281Ssam break; 31911281Ssam 32011281Ssam case SI9751D: 32111281Ssam printf("hp%d: eagle\n", mi->mi_unit); 32211281Ssam type = HPDT_EAGLE; 32311281Ssam break; 3246927Ssam } 32510734Ssam return (type); 32610734Ssam } 3276927Ssam 3286927Ssam /* 32910734Ssam * EMULEX SC750 or SC780. Poke the holding register. 3306927Ssam */ 33110734Ssam if (type == HPDT_RM02) { 33210734Ssam int ntracks, nsectors; 33310734Ssam 33411315Ssam hpaddr->hpof = HPOF_FMT22; 33511315Ssam mbclrattn(mi); 3366927Ssam hpaddr->hpcs1 = HP_NOP; 3376927Ssam hpaddr->hphr = HPHR_MAXTRAK; 33811202Ssam ntracks = MASKREG(hpaddr->hphr) + 1; 33910055Ssam if (ntracks == 16) { 3406927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 34110734Ssam type = HPDT_CAPRICORN; 34210734Ssam goto done; 34310734Ssam } 34410734Ssam hpaddr->hpcs1 = HP_NOP; 34510734Ssam hpaddr->hphr = HPHR_MAXSECT; 34611202Ssam nsectors = MASKREG(hpaddr->hphr) + 1; 34711315Ssam if (ntracks == 20 && nsectors == 48) { 34810734Ssam type = HPDT_EAGLE; 34911212Ssam printf("hp%d: eagle\n", mi->mi_unit); 35011315Ssam goto done; 35110734Ssam } 35211315Ssam printf("hp%d: ntracks %d, nsectors %d: unknown device\n", 35311315Ssam ntracks, nsectors); 35410734Ssam done: 3556927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 35611315Ssam mbclrattn(mi); /* conservative */ 35710734Ssam return (type); 35810734Ssam } 3596927Ssam 36010734Ssam /* 36110734Ssam * Map all ML11's to the same type. Also calculate 36210734Ssam * transfer rates based on device characteristics. 36310734Ssam */ 36410734Ssam if (type == HPDT_ML11A || type == HPDT_ML11B) { 36510857Ssam register struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 36610857Ssam register int trt; 3672604Swnj 36810857Ssam sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 3695726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 37010857Ssam sc->sc_mlsize >>= 2; 3715726Sroot if (mi->mi_dk >= 0) { 3725726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3735726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 3745726Sroot } 37510734Ssam type = HPDT_ML11A; 3766927Ssam } 37710734Ssam return (type); 3782604Swnj } 3792604Swnj 3808579Sroot hpopen(dev) 3818579Sroot dev_t dev; 3828579Sroot { 3838579Sroot register int unit = minor(dev) >> 3; 3848579Sroot register struct mba_device *mi; 3858579Sroot 3868579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 3878579Sroot return (ENXIO); 3888579Sroot return (0); 3898579Sroot } 3908579Sroot 39121Sbill hpstrategy(bp) 3922383Swnj register struct buf *bp; 39321Sbill { 3942978Swnj register struct mba_device *mi; 3952383Swnj register struct hpst *st; 3962383Swnj register int unit; 39721Sbill long sz, bn; 3982383Swnj int xunit = minor(bp->b_dev) & 07; 3995432Sroot int s; 40021Sbill 40121Sbill sz = bp->b_bcount; 40221Sbill sz = (sz+511) >> 9; 40321Sbill unit = dkunit(bp); 4042383Swnj if (unit >= NHP) 4052383Swnj goto bad; 4062383Swnj mi = hpinfo[unit]; 4072395Swnj if (mi == 0 || mi->mi_alive == 0) 4082383Swnj goto bad; 4092383Swnj st = &hpst[mi->mi_type]; 4105726Sroot if (ML11) { 41110857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 41210857Ssam 4135726Sroot if (bp->b_blkno < 0 || 41410857Ssam dkblock(bp)+sz > sc->sc_mlsize) 4155726Sroot goto bad; 4165726Sroot bp->b_cylin = 0; 4175726Sroot } else { 4185726Sroot if (bp->b_blkno < 0 || 4195726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 4205726Sroot goto bad; 4215726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 4225726Sroot } 4235432Sroot s = spl5(); 4242383Swnj disksort(&mi->mi_tab, bp); 4252383Swnj if (mi->mi_tab.b_active == 0) 4262383Swnj mbustart(mi); 4275432Sroot splx(s); 4282383Swnj return; 4292383Swnj 4302383Swnj bad: 4312383Swnj bp->b_flags |= B_ERROR; 4322383Swnj iodone(bp); 4332383Swnj return; 43421Sbill } 43521Sbill 4362383Swnj hpustart(mi) 4372978Swnj register struct mba_device *mi; 43821Sbill { 4392624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4402383Swnj register struct buf *bp = mi->mi_tab.b_actf; 44111315Ssam register struct hpst *st; 44210857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 44321Sbill daddr_t bn; 4443102Swnj int sn, dist; 44521Sbill 44611315Ssam st = &hpst[mi->mi_type]; 4473706Sroot hpaddr->hpcs1 = 0; 4482624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4492383Swnj return (MBU_BUSY); 45010857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 4513706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4523706Sroot 45310857Ssam sc->sc_hpinit = 1; 4542624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4553140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4563140Swnj printf("DCLR attn\n"); 4572624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4585726Sroot if (!ML11) 4595726Sroot hpaddr->hpof = HPOF_FMT22; 4603140Swnj mbclrattn(mi); 4615726Sroot if (!ML11) { 4625726Sroot bbp->b_flags = B_READ|B_BUSY; 4635726Sroot bbp->b_dev = bp->b_dev; 4645726Sroot bbp->b_bcount = 512; 4655726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 4665726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 4675726Sroot bbp->b_cylin = st->ncyl - 1; 4685726Sroot mi->mi_tab.b_actf = bbp; 4695726Sroot bbp->av_forw = bp; 4705726Sroot bp = bbp; 4715726Sroot } 47221Sbill } 4732604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 4742383Swnj return (MBU_DODATA); 4755726Sroot if (ML11) 4765726Sroot return (MBU_DODATA); 4773093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 4782383Swnj return (MBU_DODATA); 4792395Swnj bn = dkblock(bp); 4802395Swnj sn = bn%st->nspc; 4812395Swnj sn = (sn+st->nsect-hpSDIST)%st->nsect; 48211202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 48310908Ssam if (sc->sc_doseeks) 4842383Swnj return (MBU_DODATA); 48511202Ssam dist = (MASKREG(hpaddr->hpla) >> 6) - st->nsect + 1; 4862383Swnj if (dist < 0) 4872383Swnj dist += st->nsect; 4882383Swnj if (dist > st->nsect - hpRDIST) 4892383Swnj return (MBU_DODATA); 4902614Swnj } else 4912614Swnj hpaddr->hpdc = bp->b_cylin; 49210908Ssam if (sc->sc_doseeks) 4932624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 494305Sbill else { 495305Sbill hpaddr->hpda = sn; 4962624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 497305Sbill } 4982383Swnj return (MBU_STARTED); 49921Sbill } 50021Sbill 5012383Swnj hpstart(mi) 5022978Swnj register struct mba_device *mi; 50321Sbill { 5042624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5052383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5062383Swnj register struct hpst *st = &hpst[mi->mi_type]; 50710857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 50821Sbill daddr_t bn; 5092383Swnj int sn, tn; 51021Sbill 51121Sbill bn = dkblock(bp); 5125726Sroot if (ML11) 5135726Sroot hpaddr->hpda = bn; 5145726Sroot else { 5155726Sroot sn = bn%st->nspc; 5165726Sroot tn = sn/st->nsect; 5175726Sroot sn %= st->nsect; 5185726Sroot hpaddr->hpdc = bp->b_cylin; 5195726Sroot hpaddr->hpda = (tn << 8) + sn; 5205726Sroot } 52110857Ssam if (sc->sc_hdr) { 5225726Sroot if (bp->b_flags & B_READ) 5235726Sroot return (HP_RHDR|HP_GO); 5245726Sroot else 5255726Sroot return (HP_WHDR|HP_GO); 5265726Sroot } 5275726Sroot return (0); 52821Sbill } 52921Sbill 5303102Swnj hpdtint(mi, mbsr) 5312978Swnj register struct mba_device *mi; 5323102Swnj int mbsr; 53321Sbill { 5342624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5352383Swnj register struct buf *bp = mi->mi_tab.b_actf; 53611315Ssam register struct hpst *st; 5375893Swnj register int er1, er2; 53810857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 5392826Swnj int retry = 0; 54021Sbill 54111315Ssam st = &hpst[mi->mi_type]; 54211315Ssam if (bp->b_flags&B_BAD && hpecc(mi, CONT)) 54311315Ssam return (MBD_RESTARTED); 5443102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 5453706Sroot #ifdef HPDEBUG 5463289Swnj if (hpdebug) { 5473706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5483706Sroot 5493706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 5503706Sroot bp, bp->b_cylin, bp->b_blkno, 5513706Sroot hpaddr->hpas&0xff); 55211202Ssam printf("dc %x da %x\n",MASKREG(dc), MASKREG(da)); 5533289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 5543289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5553289Swnj printf("er1=%b er2=%b\n", 5563289Swnj hpaddr->hper1, HPER1_BITS, 5573289Swnj hpaddr->hper2, HPER2_BITS); 5583289Swnj DELAY(1000000); 5593289Swnj } 5603706Sroot #endif 5615858Swnj er1 = hpaddr->hper1; 5625893Swnj er2 = hpaddr->hper2; 5635893Swnj if (er1 & HPER1_HCRC) { 5645858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 5655893Swnj er2 &= ~HPER2_BSE; 5665893Swnj } 5675858Swnj if (er1&HPER1_WLE) { 5682925Swnj printf("hp%d: write locked\n", dkunit(bp)); 5692826Swnj bp->b_flags |= B_ERROR; 57011202Ssam } else if (MASKREG(er1) == HPER1_FER && RP06 && !sc->sc_hdr) { 5715726Sroot if (hpecc(mi, BSE)) 57211202Ssam return (MBD_RESTARTED); 57311202Ssam goto hard; 5742826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 5753102Swnj mbsr & MBSR_HARD || 5765858Swnj er1 & HPER1_HARD || 57710857Ssam sc->sc_hdr || 5785893Swnj (!ML11 && (er2 & HPER2_HARD))) { 57910886Shelge /* 58010886Shelge * If HCRC the header is screwed up and the sector 58111202Ssam * might be in the bad sector table, better check.. 58211202Ssam * 58310886Shelge * Note: If the header is screwed up on a skip sector 58410886Shelge * track, then the appropriate replacement sector 58511202Ssam * cannot be found. 58610886Shelge */ 58711202Ssam if (er1&HPER1_HCRC && !ML11 && hpecc(mi, BSE)) 58811202Ssam return (MBD_RESTARTED); 5893706Sroot hard: 59010622Shelge if (ML11) 59111202Ssam bp->b_blkno = MASKREG(hpaddr->hpda); 59210622Shelge else 59311202Ssam bp->b_blkno = MASKREG(hpaddr->hpdc) * st->nspc + 59411202Ssam (MASKREG(hpaddr->hpda) >> 8) * st->nsect + 59511202Ssam (hpaddr->hpda&0x1f); 5962925Swnj harderr(bp, "hp"); 5973271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 5983271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5993706Sroot printf("er1=%b er2=%b", 6002826Swnj hpaddr->hper1, HPER1_BITS, 6012826Swnj hpaddr->hper2, HPER2_BITS); 6023706Sroot if (hpaddr->hpmr) 60311202Ssam printf(" mr=%o", MASKREG(hpaddr->hpmr)); 6043706Sroot if (hpaddr->hpmr2) 60511202Ssam printf(" mr2=%o", MASKREG(hpaddr->hpmr2)); 6063706Sroot printf("\n"); 6072826Swnj bp->b_flags |= B_ERROR; 60810622Shelge retry = 0; 60910857Ssam sc->sc_recal = 0; 6105893Swnj } else if ((er2 & HPER2_BSE) && !ML11) { 6113706Sroot if (hpecc(mi, BSE)) 61211202Ssam return (MBD_RESTARTED); 61311315Ssam goto hard; 6145893Swnj } else if (RM80 && er2&HPER2_SSE) { 6153988Sroot (void) hpecc(mi, SSE); 6162883Swnj return (MBD_RESTARTED); 6175858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 6183706Sroot if (hpecc(mi, ECC)) 6192383Swnj return (MBD_RESTARTED); 6202826Swnj /* else done */ 6212826Swnj } else 6222826Swnj retry = 1; 6232826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 6245726Sroot if (ML11) { 6255726Sroot if (mi->mi_tab.b_errcnt >= 16) 6265726Sroot goto hard; 6275726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 6282826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 62910857Ssam sc->sc_recal = 1; 63011202Ssam return (MBD_RESTARTED); 63121Sbill } 6322826Swnj if (retry) 6332826Swnj return (MBD_RETRY); 6342826Swnj } 6353706Sroot #ifdef HPDEBUG 6363289Swnj else 63710857Ssam if (hpdebug && sc->sc_recal) { 63810857Ssam printf("recal %d ", sc->sc_recal); 6393289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 6403289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6413289Swnj printf("er1=%b er2=%b\n", 6423289Swnj hpaddr->hper1, HPER1_BITS, 6433289Swnj hpaddr->hper2, HPER2_BITS); 6443289Swnj } 6453706Sroot #endif 64610857Ssam switch (sc->sc_recal) { 6473093Swnj 6483093Swnj case 1: 6493093Swnj hpaddr->hpdc = bp->b_cylin; 6503093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 65110857Ssam sc->sc_recal++; 6523706Sroot return (MBD_RESTARTED); 6533093Swnj case 2: 6543093Swnj if (mi->mi_tab.b_errcnt < 16 || 6553289Swnj (bp->b_flags & B_READ) == 0) 6563093Swnj goto donerecal; 6573093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 6583093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 65910857Ssam sc->sc_recal++; 6603093Swnj return (MBD_RESTARTED); 6613093Swnj donerecal: 6623158Swnj case 3: 66310857Ssam sc->sc_recal = 0; 6642892Swnj return (MBD_RETRY); 6652892Swnj } 66610857Ssam sc->sc_hdr = 0; 66711202Ssam bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr); 6683640Swnj if (mi->mi_tab.b_errcnt >= 16) { 6693093Swnj /* 6703093Swnj * This is fast and occurs rarely; we don't 6713093Swnj * bother with interrupts. 6723093Swnj */ 6732624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 6743093Swnj while (hpaddr->hpds & HPDS_PIP) 6752383Swnj ; 6762383Swnj mbclrattn(mi); 67721Sbill } 6785726Sroot if (!ML11) { 6795726Sroot hpaddr->hpof = HPOF_FMT22; 6805726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 6815726Sroot } 6822383Swnj return (MBD_DONE); 68321Sbill } 68421Sbill 6857738Sroot hpread(dev, uio) 6862624Swnj dev_t dev; 6877738Sroot struct uio *uio; 68821Sbill { 6892624Swnj register int unit = minor(dev) >> 3; 69021Sbill 6912624Swnj if (unit >= NHP) 6928156Sroot return (ENXIO); 6938156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 69421Sbill } 69521Sbill 6967831Sroot hpwrite(dev, uio) 6972624Swnj dev_t dev; 6987831Sroot struct uio *uio; 69921Sbill { 7002624Swnj register int unit = minor(dev) >> 3; 70121Sbill 7022624Swnj if (unit >= NHP) 7038156Sroot return (ENXIO); 7048156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 70521Sbill } 70621Sbill 7075726Sroot /*ARGSUSED*/ 7087635Ssam hpioctl(dev, cmd, data, flag) 7095726Sroot dev_t dev; 7105726Sroot int cmd; 7117635Ssam caddr_t data; 7125726Sroot int flag; 7135726Sroot { 7145726Sroot 7155726Sroot switch (cmd) { 7167635Ssam 7175726Sroot case DKIOCHDR: /* do header read/write */ 71810857Ssam hpsoftc[minor(dev) >> 3].sc_hdr = 1; 7198579Sroot return (0); 7205726Sroot 7215726Sroot default: 7228579Sroot return (ENXIO); 7235726Sroot } 7245726Sroot } 7255726Sroot 7263706Sroot hpecc(mi, flag) 7272978Swnj register struct mba_device *mi; 7283706Sroot int flag; 72921Sbill { 7302383Swnj register struct mba_regs *mbp = mi->mi_mba; 7312624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 7322383Swnj register struct buf *bp = mi->mi_tab.b_actf; 7333706Sroot register struct hpst *st = &hpst[mi->mi_type]; 7343706Sroot int npf, o; 7352383Swnj int bn, cn, tn, sn; 736914Sbill int bcr; 73721Sbill 73811202Ssam bcr = MASKREG(mbp->mba_bcr); 739914Sbill if (bcr) 740914Sbill bcr |= 0xffff0000; /* sxt */ 7413706Sroot if (flag == CONT) 7423706Sroot npf = bp->b_error; 7433706Sroot else 7443706Sroot npf = btop(bcr + bp->b_bcount); 745420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 746420Sbill bn = dkblock(bp); 747420Sbill cn = bp->b_cylin; 7483706Sroot sn = bn%(st->nspc) + npf; 7492383Swnj tn = sn/st->nsect; 7502383Swnj sn %= st->nsect; 7512383Swnj cn += tn/st->ntrak; 7522383Swnj tn %= st->ntrak; 7533706Sroot switch (flag) { 75410856Ssam case ECC: { 7553706Sroot register int i; 7563706Sroot caddr_t addr; 7573706Sroot struct pte mpte; 7583706Sroot int bit, byte, mask; 7593706Sroot 7603706Sroot npf--; /* because block in error is previous block */ 7613706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 7623706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 76311202Ssam mask = MASKREG(rp->hpec2); 76411202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 7653706Sroot bit = i&07; 7663706Sroot i = (i&~07)>>3; 7673706Sroot byte = i + o; 7683706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 7693706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 7703706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 7713706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 7723706Sroot byte++; 7733706Sroot i++; 7743706Sroot bit -= 8; 7753706Sroot } 7763706Sroot if (bcr == 0) 7773706Sroot return (0); 7783847Sroot npf++; 7793706Sroot break; 7803706Sroot } 7813706Sroot 7823706Sroot case SSE: 7833706Sroot rp->hpof |= HPOF_SSEI; 7843706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7853706Sroot break; 7863706Sroot 7873706Sroot case BSE: 7883706Sroot #ifdef HPBDEBUG 7893706Sroot if (hpbdebug) 7903706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 7913706Sroot #endif 79211202Ssam if (rp->hpof&HPOF_SSEI) 79311202Ssam sn++; 7943706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 79511202Ssam return (0); 7963706Sroot bp->b_flags |= B_BAD; 7973706Sroot bp->b_error = npf + 1; 7983706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 7993706Sroot cn = bn/st->nspc; 8003706Sroot sn = bn%st->nspc; 8013706Sroot tn = sn/st->nsect; 8023706Sroot sn %= st->nsect; 8033706Sroot mbp->mba_bcr = -512; 80410886Shelge rp->hpof &= ~HPOF_SSEI; 8053706Sroot #ifdef HPBDEBUG 8063706Sroot if (hpbdebug) 8073706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 8083706Sroot #endif 8093706Sroot break; 8103706Sroot 8113706Sroot case CONT: 8123706Sroot #ifdef HPBDEBUG 8133706Sroot if (hpbdebug) 8143706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 8153706Sroot #endif 8163706Sroot npf = bp->b_error; 8173706Sroot bp->b_flags &= ~B_BAD; 8183706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 81911202Ssam if (MASKREG(mbp->mba_bcr) == 0) 82011202Ssam return (0); 8213706Sroot break; 8223706Sroot } 8233706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 8243350Swnj if (rp->hpof&HPOF_SSEI) 8252883Swnj sn++; 826420Sbill rp->hpdc = cn; 827420Sbill rp->hpda = (tn<<8) + sn; 828420Sbill mbp->mba_sr = -1; 8293706Sroot mbp->mba_var = (int)ptob(npf) + o; 8303706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 8313706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 832420Sbill return (1); 83321Sbill } 8342362Swnj 8352362Swnj #define DBSIZE 20 8362362Swnj 8372362Swnj hpdump(dev) 8382362Swnj dev_t dev; 8392362Swnj { 8402978Swnj register struct mba_device *mi; 8412383Swnj register struct mba_regs *mba; 8422624Swnj struct hpdevice *hpaddr; 8432362Swnj char *start; 8442383Swnj int num, unit; 8452383Swnj register struct hpst *st; 8462362Swnj 8472362Swnj num = maxfree; 8482362Swnj start = 0; 8492362Swnj unit = minor(dev) >> 3; 8502827Swnj if (unit >= NHP) 8512827Swnj return (ENXIO); 8522383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 8532978Swnj mi = phys(hpinfo[unit],struct mba_device *); 8542827Swnj if (mi == 0 || mi->mi_alive == 0) 8552827Swnj return (ENXIO); 8562383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 8573102Swnj mba->mba_cr = MBCR_INIT; 8582624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 8593093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 8602624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 8612624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 8623093Swnj hpaddr->hpof = HPOF_FMT22; 8632362Swnj } 8642383Swnj st = &hpst[mi->mi_type]; 8652827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 8662827Swnj return (EINVAL); 8672362Swnj while (num > 0) { 8682383Swnj register struct pte *hpte = mba->mba_map; 8692362Swnj register int i; 8702383Swnj int blk, cn, sn, tn; 8712362Swnj daddr_t bn; 8722362Swnj 8732362Swnj blk = num > DBSIZE ? DBSIZE : num; 8742362Swnj bn = dumplo + btop(start); 8752383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 8762383Swnj sn = bn%st->nspc; 8772383Swnj tn = sn/st->nsect; 8782383Swnj sn = sn%st->nsect; 8792362Swnj hpaddr->hpdc = cn; 8802362Swnj hpaddr->hpda = (tn << 8) + sn; 8812362Swnj for (i = 0; i < blk; i++) 8822362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 8832383Swnj mba->mba_sr = -1; 8842383Swnj mba->mba_bcr = -(blk*NBPG); 8852383Swnj mba->mba_var = 0; 8862624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 8873093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 8882362Swnj ; 8893093Swnj if (hpaddr->hpds&HPDS_ERR) 8902827Swnj return (EIO); 8912362Swnj start += blk*NBPG; 8922362Swnj num -= blk; 8932362Swnj } 8942362Swnj return (0); 8952362Swnj } 896*12506Ssam 897*12506Ssam hpsize(dev) 898*12506Ssam dev_t dev; 899*12506Ssam { 900*12506Ssam int unit = minor(dev) >> 3; 901*12506Ssam struct mba_device *mi; 902*12506Ssam struct hpst *st; 903*12506Ssam 904*12506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 905*12506Ssam return (-1); 906*12506Ssam st = &hpst[mi->mi_type]; 907*12506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 908*12506Ssam } 9091565Sbill #endif 910