1*8579Sroot /* hp.c 4.56 82/10/17 */ 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 */ 2121Sbill 2221Sbill #include "../h/param.h" 2321Sbill #include "../h/systm.h" 24305Sbill #include "../h/dk.h" 2521Sbill #include "../h/buf.h" 2621Sbill #include "../h/conf.h" 2721Sbill #include "../h/dir.h" 2821Sbill #include "../h/user.h" 2921Sbill #include "../h/map.h" 30420Sbill #include "../h/pte.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" 365726Sroot #include "../h/dkio.h" 377738Sroot #include "../h/uio.h" 3821Sbill 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; 473706Sroot } hp6_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 */ 5121Sbill 0, 0, 5221Sbill 0, 0, 5321Sbill 0, 0, 543726Sroot #ifndef NOBADSECT 553729Sroot 291280, 118, /* G=cyl 118 thru 814 */ 563706Sroot #else 573706Sroot 291346, 118, 583706Sroot #endif 5921Sbill 0, 0, 603706Sroot }, rm3_sizes[8] = { 61886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 62886Sbill 33440, 100, /* B=cyl 100 thru 309 */ 63886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 6421Sbill 0, 0, 6521Sbill 0, 0, 663442Sroot 0, 0, 673726Sroot #ifndef NOBADSECT 683729Sroot 81984, 310, /* G=cyl 310 thru 822 */ 693706Sroot #else 703706Sroot 82080, 310, 713706Sroot #endif 7221Sbill 0, 0, 73886Sbill }, rm5_sizes[8] = { 746927Ssam #ifndef CAD 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 */ 803726Sroot #ifndef NOBADSECT 813729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 823729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 833706Sroot #else 845695Sroot 86336, 681, 853706Sroot 158688, 562, 863706Sroot #endif 87886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 886927Ssam #else 896927Ssam 15884, 0, /* A=cyl 0 thru 26 */ 906927Ssam 33440, 27, /* B=cyl 27 thru 81 */ 916927Ssam 495520, 0, /* C=cyl 0 thru 814 */ 926927Ssam 15884, 562, /* D=cyl 562 thru 588 */ 936927Ssam 55936, 589, /* E=cyl 589 thru 680 */ 946927Ssam #ifndef NOBADSECT 956927Ssam 81376, 681, /* F=cyl 681 thru 814 */ 966927Ssam 153728, 562, /* G=cyl 562 thru 814 */ 976927Ssam #else 986927Ssam 81472, 681, 996927Ssam 153824, 562, 1006927Ssam #endif 1016927Ssam 291346, 82, /* H=cyl 82 thru 561 */ 1026927Ssam #endif 1032383Swnj }, rm80_sizes[8] = { 1042383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 1052383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 1062383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 1072383Swnj 0, 0, 1082383Swnj 0, 0, 1092383Swnj 0, 0, 1102383Swnj 82080, 115, /* G=cyl 115 thru 304 */ 1113729Sroot 110143, 305, /* H=cyl 305 thru 558 */ 1123706Sroot }, hp7_sizes[8] = { 1136927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 1143706Sroot 64000, 10, /* B=cyl 10 thru 49 */ 1153706Sroot 1008000,0, /* C=cyl 0 thru 629 */ 1163706Sroot 15884, 330, /* D=cyl 330 thru 339 */ 1173706Sroot 256000, 340, /* E=cyl 340 thru 499 */ 1183729Sroot 207850, 500, /* F=cyl 500 thru 629 */ 1193729Sroot 479850, 330, /* G=cyl 330 thru 629 */ 1203706Sroot 448000, 50, /* H=cyl 50 thru 329 */ 1216927Ssam }, si9775_sizes[8] = { 1226927Ssam 16640, 0, /* A=cyl 0 thru 12 */ 1236927Ssam 34560, 13, /* B=cyl 13 thru 39 */ 1246927Ssam 1079040, 0, /* C=cyl 0 thru 842 - whole disk */ 1256927Ssam 0, 0, /* D unused */ 1266927Ssam 0, 0, /* E unused */ 1276927Ssam 0, 0, /* F unused */ 1286927Ssam 513280, 40, /* G=cyl 40 thru 440 */ 1296927Ssam 513280, 441, /* H=cyl 441 thru 841 */ 1306927Ssam }, si9730_sizes[8] = { 1316927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1326927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1336927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 1346927Ssam 0, 0, 1356927Ssam 0, 0, 1366927Ssam 0, 0, 1376927Ssam 0, 0, 1386927Ssam #ifndef NOBADSECT 1396927Ssam 213664, 155, /* H=cyl 155 thru 822 */ 1406927Ssam #else 1416927Ssam 213760, 155, 1426927Ssam #endif 1436927Ssam }, hpam_sizes[8] = { 1446927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1456927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1466927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 1476927Ssam 27786, 668, 1486927Ssam 27786, 723, 1496927Ssam 125440, 778, 1506927Ssam 181760, 668, /* G=cyl 668 thru 1022 */ 1516927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 15221Sbill }; 1532383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 15421Sbill 1552383Swnj #define _hpSDIST 2 1562383Swnj #define _hpRDIST 3 1572383Swnj 1582383Swnj int hpSDIST = _hpSDIST; 1592383Swnj int hpRDIST = _hpRDIST; 1602383Swnj 1616927Ssam /* 1626927Ssam * Table for converting Massbus drive types into 1636927Ssam * indices into the partition tables. Slots are 1646927Ssam * left for those drives devined from other means 1656927Ssam * (e.g. SI, AMPEX, etc.). 1666927Ssam */ 1676927Ssam short hptypes[] = { 1686927Ssam #define HPDT_RM03 0 1696927Ssam MBDT_RM03, 1706927Ssam #define HPDT_RM05 1 1716927Ssam MBDT_RM05, 1726927Ssam #define HPDT_RP06 2 1736927Ssam MBDT_RP06, 1746927Ssam #define HPDT_RM80 3 1756927Ssam MBDT_RM80, 1766927Ssam #define HPDT_RP05 4 1776927Ssam MBDT_RP05, 1786927Ssam #define HPDT_RP07 5 1796927Ssam MBDT_RP07, 1806927Ssam #define HPDT_ML11A 6 1816927Ssam MBDT_ML11A, 1826927Ssam #define HPDT_ML11B 7 1836927Ssam MBDT_ML11B, 1846927Ssam #define HPDT_9775 8 1856927Ssam -1, 1866927Ssam #define HPDT_9730 9 1876927Ssam -1, 1886927Ssam #define HPDT_CAPRICORN 10 1896927Ssam -1, 1906927Ssam #define HPDT_RM02 11 1916927Ssam MBDT_RM02, /* beware, actually capricorn */ 1926927Ssam 0 1936927Ssam }; 1942978Swnj struct mba_device *hpinfo[NHP]; 1952978Swnj int hpattach(),hpustart(),hpstart(),hpdtint(); 1962383Swnj struct mba_driver hpdriver = 1972978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1982978Swnj hptypes, "hp", 0, hpinfo }; 1992383Swnj 2002383Swnj struct hpst { 2012383Swnj short nsect; 2022383Swnj short ntrak; 2032383Swnj short nspc; 2042383Swnj short ncyl; 2052383Swnj struct size *sizes; 2062383Swnj } hpst[] = { 2073706Sroot 32, 5, 32*5, 823, rm3_sizes, /* RM03 */ 2082383Swnj 32, 19, 32*19, 823, rm5_sizes, /* RM05 */ 2093706Sroot 22, 19, 22*19, 815, hp6_sizes, /* RP06 */ 2103706Sroot 31, 14, 31*14, 559, rm80_sizes, /* RM80 */ 2113706Sroot 22, 19, 22*19, 411, hp6_sizes, /* RP05 */ 2123706Sroot 50, 32, 50*32, 630, hp7_sizes, /* RP07 */ 2135726Sroot 1, 1, 1, 1, 0, /* ML11A */ 2145726Sroot 1, 1, 1, 1, 0, /* ML11B */ 2156927Ssam 32, 40, 32*40, 843, si9775_sizes, /* 9775 */ 2166927Ssam 32, 10, 32*10, 823, si9730_sizes, /* 9730 */ 2176927Ssam 32, 16, 32*16, 1024, hpam_sizes, /* AMPEX capricorn */ 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]; 2283726Sroot #ifndef NOBADSECT 2293706Sroot struct buf bhpbuf[NHP]; 2303706Sroot struct dkbad hpbad[NHP]; 2313706Sroot #endif 2325726Sroot /* SHOULD CONSOLIDATE ALL THIS STUFF INTO A STRUCTURE */ 2333706Sroot char hpinit[NHP]; 2342892Swnj char hprecal[NHP]; 2355726Sroot char hphdr[NHP]; 2365726Sroot daddr_t mlsize[NHP]; 23721Sbill 23821Sbill #define b_cylin b_resid 23921Sbill 2405726Sroot /* #define ML11 0 to remove ML11 support */ 2415726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2425726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2435726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2445726Sroot 24521Sbill #ifdef INTRLVE 24621Sbill daddr_t dkblock(); 24721Sbill #endif 24821Sbill 2492604Swnj int hpseek; 2502604Swnj 2512978Swnj /*ARGSUSED*/ 2522978Swnj hpattach(mi, slave) 2532978Swnj struct mba_device *mi; 2542604Swnj { 2556927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 2566927Ssam 2576927Ssam switch (mi->mi_type) { 2586927Ssam 2596927Ssam /* 2606927Ssam * Model-byte processing for SI 9400 controllers. 2616927Ssam * NB: Only deals with RM03 and RM05 emulations. 2626927Ssam */ 2636927Ssam case HPDT_RM03: 2646927Ssam case HPDT_RM05: { 2656927Ssam register int hpsn; 2666927Ssam 2676927Ssam hpsn = hpaddr->hpsn; 2686927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 2696927Ssam break; 2706927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 2716927Ssam 2726927Ssam case SI9775D: 2736927Ssam printf("hp%d: si 9775 (direct)\n", mi->mi_unit); 2746927Ssam mi->mi_type = HPDT_9775; 2756927Ssam break; 2766927Ssam 2776927Ssam case SI9730D: 2786927Ssam printf("hp%d: si 9730 (direct)\n", mi->mi_unit); 2796927Ssam mi->mi_type = HPDT_9730; 2806927Ssam break; 2816927Ssam 2826927Ssam #ifdef CAD 2837035Swnj /* 2847035Swnj * AMPEX 9300, SI Combination needs a have the drive cleared 2857035Swnj * before we start. We do not know why, but tests show 2867035Swnj * that the recalibrate fixes the problem. 2877035Swnj */ 2886927Ssam case SI9766: 2896927Ssam printf("hp%d: 9776/9300\n", mi->mi_unit); 2906927Ssam mi->mi_type = HPDT_RM05; 2917035Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 2927035Swnj DELAY(100000); 2936927Ssam break; 2946927Ssam 2956927Ssam case SI9762: 2966927Ssam printf("hp%d: 9762\n", mi->mi_unit); 2976927Ssam mi->mi_type = HPDT_RM03; 2986927Ssam break; 2996927Ssam #endif 3006927Ssam } 3016927Ssam break; 3026927Ssam } 3036927Ssam 3046927Ssam /* 3056927Ssam * CAPRICORN KLUDGE...poke the holding register 3066927Ssam * to find out the number of tracks. If it's 15 3076927Ssam * we believe it's a Capricorn. 3086927Ssam */ 3096927Ssam case HPDT_RM02: 3106927Ssam hpaddr->hpcs1 = HP_NOP; 3116927Ssam hpaddr->hphr = HPHR_MAXTRAK; 3127313Ssam if ((hpaddr->hphr&0xffff) == 15) { 3136927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 3146927Ssam mi->mi_type = HPDT_CAPRICORN; 3156927Ssam } 3166927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 3176927Ssam break; 3186927Ssam 3196927Ssam case HPDT_ML11A: 3206927Ssam case HPDT_ML11B: { 3215726Sroot register int trt, sz; 3222604Swnj 3235726Sroot sz = hpaddr->hpmr & HPMR_SZ; 3245726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 3255726Sroot sz >>= 2; 3265726Sroot mlsize[mi->mi_unit] = sz; 3275726Sroot if (mi->mi_dk >= 0) { 3285726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3295726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 3305726Sroot } 3316927Ssam /* A CHEAT - ML11B D.T. SHOULD == ML11A */ 3326927Ssam mi->mi_type = HPDT_ML11A; 3336927Ssam break; 3346927Ssam } 3356927Ssam } 3366927Ssam if (!ML11 && mi->mi_dk >= 0) { 3375726Sroot register struct hpst *st = &hpst[mi->mi_type]; 3385726Sroot 3392757Swnj dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 3405726Sroot } 3412604Swnj } 3422604Swnj 343*8579Sroot hpopen(dev) 344*8579Sroot dev_t dev; 345*8579Sroot { 346*8579Sroot register int unit = minor(dev) >> 3; 347*8579Sroot register struct mba_device *mi; 348*8579Sroot 349*8579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 350*8579Sroot return (ENXIO); 351*8579Sroot return (0); 352*8579Sroot } 353*8579Sroot 35421Sbill hpstrategy(bp) 3552383Swnj register struct buf *bp; 35621Sbill { 3572978Swnj register struct mba_device *mi; 3582383Swnj register struct hpst *st; 3592383Swnj register int unit; 36021Sbill long sz, bn; 3612383Swnj int xunit = minor(bp->b_dev) & 07; 3625432Sroot int s; 36321Sbill 36421Sbill sz = bp->b_bcount; 36521Sbill sz = (sz+511) >> 9; 36621Sbill unit = dkunit(bp); 3672383Swnj if (unit >= NHP) 3682383Swnj goto bad; 3692383Swnj mi = hpinfo[unit]; 3702395Swnj if (mi == 0 || mi->mi_alive == 0) 3712383Swnj goto bad; 3722383Swnj st = &hpst[mi->mi_type]; 3735726Sroot if (ML11) { 3745726Sroot if (bp->b_blkno < 0 || 3755726Sroot dkblock(bp)+sz > mlsize[mi->mi_unit]) 3765726Sroot goto bad; 3775726Sroot bp->b_cylin = 0; 3785726Sroot } else { 3795726Sroot if (bp->b_blkno < 0 || 3805726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 3815726Sroot goto bad; 3825726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 3835726Sroot } 3845432Sroot s = spl5(); 3852383Swnj disksort(&mi->mi_tab, bp); 3862383Swnj if (mi->mi_tab.b_active == 0) 3872383Swnj mbustart(mi); 3885432Sroot splx(s); 3892383Swnj return; 3902383Swnj 3912383Swnj bad: 3922383Swnj bp->b_flags |= B_ERROR; 3932383Swnj iodone(bp); 3942383Swnj return; 39521Sbill } 39621Sbill 3972383Swnj hpustart(mi) 3982978Swnj register struct mba_device *mi; 39921Sbill { 4002624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4012383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4023706Sroot register struct hpst *st = &hpst[mi->mi_type]; 40321Sbill daddr_t bn; 4043102Swnj int sn, dist; 40521Sbill 4063706Sroot hpaddr->hpcs1 = 0; 4072624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4082383Swnj return (MBU_BUSY); 4093706Sroot if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) { 4103726Sroot #ifndef NOBADSECT 4113706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4123706Sroot #endif 4133706Sroot 4143706Sroot hpinit[mi->mi_unit] = 1; 4152624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4163140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4173140Swnj printf("DCLR attn\n"); 4182624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4195726Sroot if (!ML11) 4205726Sroot hpaddr->hpof = HPOF_FMT22; 4213140Swnj mbclrattn(mi); 4223726Sroot #ifndef NOBADSECT 4235726Sroot if (!ML11) { 4245726Sroot bbp->b_flags = B_READ|B_BUSY; 4255726Sroot bbp->b_dev = bp->b_dev; 4265726Sroot bbp->b_bcount = 512; 4275726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 4285726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 4295726Sroot bbp->b_cylin = st->ncyl - 1; 4305726Sroot mi->mi_tab.b_actf = bbp; 4315726Sroot bbp->av_forw = bp; 4325726Sroot bp = bbp; 4335726Sroot } 4343706Sroot #endif 43521Sbill } 4362604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 4372383Swnj return (MBU_DODATA); 4385726Sroot if (ML11) 4395726Sroot return (MBU_DODATA); 4403093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 4412383Swnj return (MBU_DODATA); 4422395Swnj bn = dkblock(bp); 4432395Swnj sn = bn%st->nspc; 4442395Swnj sn = (sn+st->nsect-hpSDIST)%st->nsect; 4452383Swnj if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) { 4462604Swnj if (hpseek) 4472383Swnj return (MBU_DODATA); 4482383Swnj dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1; 4492383Swnj if (dist < 0) 4502383Swnj dist += st->nsect; 4512383Swnj if (dist > st->nsect - hpRDIST) 4522383Swnj return (MBU_DODATA); 4532614Swnj } else 4542614Swnj hpaddr->hpdc = bp->b_cylin; 4552604Swnj if (hpseek) 4562624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 457305Sbill else { 458305Sbill hpaddr->hpda = sn; 4592624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 460305Sbill } 4612383Swnj return (MBU_STARTED); 46221Sbill } 46321Sbill 4642383Swnj hpstart(mi) 4652978Swnj register struct mba_device *mi; 46621Sbill { 4672624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4682383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4692383Swnj register struct hpst *st = &hpst[mi->mi_type]; 47021Sbill daddr_t bn; 4712383Swnj int sn, tn; 47221Sbill 47321Sbill bn = dkblock(bp); 4745726Sroot if (ML11) 4755726Sroot hpaddr->hpda = bn; 4765726Sroot else { 4775726Sroot sn = bn%st->nspc; 4785726Sroot tn = sn/st->nsect; 4795726Sroot sn %= st->nsect; 4805726Sroot hpaddr->hpdc = bp->b_cylin; 4815726Sroot hpaddr->hpda = (tn << 8) + sn; 4825726Sroot } 4835726Sroot if (hphdr[mi->mi_unit]) { 4845726Sroot if (bp->b_flags & B_READ) 4855726Sroot return (HP_RHDR|HP_GO); 4865726Sroot else 4875726Sroot return (HP_WHDR|HP_GO); 4885726Sroot } 4895726Sroot return (0); 49021Sbill } 49121Sbill 4923102Swnj hpdtint(mi, mbsr) 4932978Swnj register struct mba_device *mi; 4943102Swnj int mbsr; 49521Sbill { 4962624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4972383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4985893Swnj register int er1, er2; 4992826Swnj int retry = 0; 50021Sbill 5013726Sroot #ifndef NOBADSECT 5023706Sroot if (bp->b_flags&B_BAD) { 5033706Sroot if (hpecc(mi, CONT)) 5043706Sroot return(MBD_RESTARTED); 5053706Sroot } 5063706Sroot #endif 5073102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 5083706Sroot #ifdef HPDEBUG 5093289Swnj if (hpdebug) { 5103706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5113706Sroot 5123706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 5133706Sroot bp, bp->b_cylin, bp->b_blkno, 5143706Sroot hpaddr->hpas&0xff); 5153706Sroot printf("dc %x da %x\n",dc&0xffff, da&0xffff); 5163289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 5173289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5183289Swnj printf("er1=%b er2=%b\n", 5193289Swnj hpaddr->hper1, HPER1_BITS, 5203289Swnj hpaddr->hper2, HPER2_BITS); 5213289Swnj DELAY(1000000); 5223289Swnj } 5233706Sroot #endif 5245858Swnj er1 = hpaddr->hper1; 5255893Swnj er2 = hpaddr->hper2; 5265893Swnj if (er1 & HPER1_HCRC) { 5275858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 5285893Swnj er2 &= ~HPER2_BSE; 5295893Swnj } 5305858Swnj if (er1&HPER1_WLE) { 5312925Swnj printf("hp%d: write locked\n", dkunit(bp)); 5322826Swnj bp->b_flags |= B_ERROR; 5335858Swnj } else if ((er1&0xffff) == HPER1_FER && RP06 && 5345726Sroot hphdr[mi->mi_unit] == 0) { 5355726Sroot #ifndef NOBADSECT 5365726Sroot if (hpecc(mi, BSE)) 5375726Sroot return(MBD_RESTARTED); 5385726Sroot else 5395726Sroot #endif 5405726Sroot goto hard; 5412826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 5423102Swnj mbsr & MBSR_HARD || 5435858Swnj er1 & HPER1_HARD || 5445726Sroot hphdr[mi->mi_unit] || 5455893Swnj (!ML11 && (er2 & HPER2_HARD))) { 5463706Sroot hard: 5472925Swnj harderr(bp, "hp"); 5483271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 5493271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5503706Sroot printf("er1=%b er2=%b", 5512826Swnj hpaddr->hper1, HPER1_BITS, 5522826Swnj hpaddr->hper2, HPER2_BITS); 5533706Sroot if (hpaddr->hpmr) 5543706Sroot printf(" mr=%o", hpaddr->hpmr&0xffff); 5553706Sroot if (hpaddr->hpmr2) 5563706Sroot printf(" mr2=%o", hpaddr->hpmr2&0xffff); 5573706Sroot printf("\n"); 5582826Swnj bp->b_flags |= B_ERROR; 5593143Swnj hprecal[mi->mi_unit] = 0; 5605893Swnj } else if ((er2 & HPER2_BSE) && !ML11) { 5613726Sroot #ifndef NOBADSECT 5623706Sroot if (hpecc(mi, BSE)) 5633706Sroot return(MBD_RESTARTED); 5643706Sroot else 5653706Sroot #endif 5663706Sroot goto hard; 5675893Swnj } else if (RM80 && er2&HPER2_SSE) { 5683988Sroot (void) hpecc(mi, SSE); 5692883Swnj return (MBD_RESTARTED); 5705858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 5713706Sroot if (hpecc(mi, ECC)) 5722383Swnj return (MBD_RESTARTED); 5732826Swnj /* else done */ 5742826Swnj } else 5752826Swnj retry = 1; 5762826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 5775726Sroot if (ML11) { 5785726Sroot if (mi->mi_tab.b_errcnt >= 16) 5795726Sroot goto hard; 5805726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 5812826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 5823706Sroot hprecal[mi->mi_unit] = 1; 5833706Sroot return(MBD_RESTARTED); 58421Sbill } 5852826Swnj if (retry) 5862826Swnj return (MBD_RETRY); 5872826Swnj } 5883706Sroot #ifdef HPDEBUG 5893289Swnj else 5903289Swnj if (hpdebug && hprecal[mi->mi_unit]) { 5913289Swnj printf("recal %d ", hprecal[mi->mi_unit]); 5923289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 5933289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5943289Swnj printf("er1=%b er2=%b\n", 5953289Swnj hpaddr->hper1, HPER1_BITS, 5963289Swnj hpaddr->hper2, HPER2_BITS); 5973289Swnj } 5983706Sroot #endif 5993093Swnj switch (hprecal[mi->mi_unit]) { 6003093Swnj 6013093Swnj case 1: 6023093Swnj hpaddr->hpdc = bp->b_cylin; 6033093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 6043706Sroot hprecal[mi->mi_unit]++; 6053706Sroot return (MBD_RESTARTED); 6063093Swnj case 2: 6073093Swnj if (mi->mi_tab.b_errcnt < 16 || 6083289Swnj (bp->b_flags & B_READ) == 0) 6093093Swnj goto donerecal; 6103093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 6113093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 6123093Swnj hprecal[mi->mi_unit]++; 6133093Swnj return (MBD_RESTARTED); 6143093Swnj donerecal: 6153158Swnj case 3: 6162892Swnj hprecal[mi->mi_unit] = 0; 6172892Swnj return (MBD_RETRY); 6182892Swnj } 6195726Sroot hphdr[mi->mi_unit] = 0; 6202383Swnj bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff; 6213640Swnj if (mi->mi_tab.b_errcnt >= 16) { 6223093Swnj /* 6233093Swnj * This is fast and occurs rarely; we don't 6243093Swnj * bother with interrupts. 6253093Swnj */ 6262624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 6273093Swnj while (hpaddr->hpds & HPDS_PIP) 6282383Swnj ; 6292383Swnj mbclrattn(mi); 63021Sbill } 6315726Sroot if (!ML11) { 6325726Sroot hpaddr->hpof = HPOF_FMT22; 6335726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 6345726Sroot } 6352383Swnj return (MBD_DONE); 63621Sbill } 63721Sbill 6387738Sroot hpread(dev, uio) 6392624Swnj dev_t dev; 6407738Sroot struct uio *uio; 64121Sbill { 6422624Swnj register int unit = minor(dev) >> 3; 64321Sbill 6442624Swnj if (unit >= NHP) 6458156Sroot return (ENXIO); 6468156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 64721Sbill } 64821Sbill 6497831Sroot hpwrite(dev, uio) 6502624Swnj dev_t dev; 6517831Sroot struct uio *uio; 65221Sbill { 6532624Swnj register int unit = minor(dev) >> 3; 65421Sbill 6552624Swnj if (unit >= NHP) 6568156Sroot return (ENXIO); 6578156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 65821Sbill } 65921Sbill 6605726Sroot /*ARGSUSED*/ 6617635Ssam hpioctl(dev, cmd, data, flag) 6625726Sroot dev_t dev; 6635726Sroot int cmd; 6647635Ssam caddr_t data; 6655726Sroot int flag; 6665726Sroot { 6675726Sroot 6685726Sroot switch (cmd) { 6697635Ssam 6705726Sroot case DKIOCHDR: /* do header read/write */ 6715726Sroot hphdr[minor(dev)>>3] = 1; 672*8579Sroot return (0); 6735726Sroot 6745726Sroot default: 675*8579Sroot return (ENXIO); 6765726Sroot } 6775726Sroot } 6785726Sroot 6793706Sroot hpecc(mi, flag) 6802978Swnj register struct mba_device *mi; 6813706Sroot int flag; 68221Sbill { 6832383Swnj register struct mba_regs *mbp = mi->mi_mba; 6842624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 6852383Swnj register struct buf *bp = mi->mi_tab.b_actf; 6863706Sroot register struct hpst *st = &hpst[mi->mi_type]; 6873706Sroot int npf, o; 6882383Swnj int bn, cn, tn, sn; 689914Sbill int bcr; 69021Sbill 691914Sbill bcr = mbp->mba_bcr & 0xffff; 692914Sbill if (bcr) 693914Sbill bcr |= 0xffff0000; /* sxt */ 6943726Sroot #ifndef NOBADSECT 6953706Sroot if (flag == CONT) 6963706Sroot npf = bp->b_error; 6973706Sroot else 6983706Sroot #endif 6993706Sroot npf = btop(bcr + bp->b_bcount); 700420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 701420Sbill bn = dkblock(bp); 702420Sbill cn = bp->b_cylin; 7033706Sroot sn = bn%(st->nspc) + npf; 7042383Swnj tn = sn/st->nsect; 7052383Swnj sn %= st->nsect; 7062383Swnj cn += tn/st->ntrak; 7072383Swnj tn %= st->ntrak; 7083706Sroot switch (flag) { 7093706Sroot case ECC: 7103706Sroot { 7113706Sroot register int i; 7123706Sroot caddr_t addr; 7133706Sroot struct pte mpte; 7143706Sroot int bit, byte, mask; 7153706Sroot 7163706Sroot npf--; /* because block in error is previous block */ 7173706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 7183706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 7193706Sroot mask = rp->hpec2&0xffff; 7203706Sroot i = (rp->hpec1&0xffff) - 1; /* -1 makes 0 origin */ 7213706Sroot bit = i&07; 7223706Sroot i = (i&~07)>>3; 7233706Sroot byte = i + o; 7243706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 7253706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 7263706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 7273706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 7283706Sroot byte++; 7293706Sroot i++; 7303706Sroot bit -= 8; 7313706Sroot } 7323706Sroot if (bcr == 0) 7333706Sroot return (0); 7343847Sroot npf++; 7353706Sroot break; 7363706Sroot } 7373706Sroot 7383706Sroot case SSE: 7393706Sroot rp->hpof |= HPOF_SSEI; 7403706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7413706Sroot break; 7423706Sroot 7433726Sroot #ifndef NOBADSECT 7443706Sroot case BSE: 7453706Sroot #ifdef HPBDEBUG 7463706Sroot if (hpbdebug) 7473706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 7483706Sroot #endif 7493706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 7503706Sroot return(0); 7513706Sroot bp->b_flags |= B_BAD; 7523706Sroot bp->b_error = npf + 1; 7533706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 7543706Sroot cn = bn/st->nspc; 7553706Sroot sn = bn%st->nspc; 7563706Sroot tn = sn/st->nsect; 7573706Sroot sn %= st->nsect; 7583706Sroot mbp->mba_bcr = -512; 7593706Sroot #ifdef HPBDEBUG 7603706Sroot if (hpbdebug) 7613706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 7623706Sroot #endif 7633706Sroot break; 7643706Sroot 7653706Sroot case CONT: 7663706Sroot #ifdef HPBDEBUG 7673706Sroot if (hpbdebug) 7683706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 7693706Sroot #endif 7703706Sroot npf = bp->b_error; 7713706Sroot bp->b_flags &= ~B_BAD; 7723706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7733706Sroot if ((mbp->mba_bcr & 0xffff) == 0) 7743706Sroot return(0); 7753706Sroot break; 7763706Sroot #endif 7773706Sroot } 7783706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 7793350Swnj if (rp->hpof&HPOF_SSEI) 7802883Swnj sn++; 781420Sbill rp->hpdc = cn; 782420Sbill rp->hpda = (tn<<8) + sn; 783420Sbill mbp->mba_sr = -1; 7843706Sroot mbp->mba_var = (int)ptob(npf) + o; 7853706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 7863706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 787420Sbill return (1); 78821Sbill } 7892362Swnj 7902362Swnj #define DBSIZE 20 7912362Swnj 7922362Swnj hpdump(dev) 7932362Swnj dev_t dev; 7942362Swnj { 7952978Swnj register struct mba_device *mi; 7962383Swnj register struct mba_regs *mba; 7972624Swnj struct hpdevice *hpaddr; 7982362Swnj char *start; 7992383Swnj int num, unit; 8002383Swnj register struct hpst *st; 8012362Swnj 8022362Swnj num = maxfree; 8032362Swnj start = 0; 8042362Swnj unit = minor(dev) >> 3; 8052827Swnj if (unit >= NHP) 8062827Swnj return (ENXIO); 8072383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 8082978Swnj mi = phys(hpinfo[unit],struct mba_device *); 8092827Swnj if (mi == 0 || mi->mi_alive == 0) 8102827Swnj return (ENXIO); 8112383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 8123102Swnj mba->mba_cr = MBCR_INIT; 8132624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 8143093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 8152624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 8162624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 8173093Swnj hpaddr->hpof = HPOF_FMT22; 8182362Swnj } 8192383Swnj st = &hpst[mi->mi_type]; 8202827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 8212827Swnj return (EINVAL); 8222362Swnj while (num > 0) { 8232383Swnj register struct pte *hpte = mba->mba_map; 8242362Swnj register int i; 8252383Swnj int blk, cn, sn, tn; 8262362Swnj daddr_t bn; 8272362Swnj 8282362Swnj blk = num > DBSIZE ? DBSIZE : num; 8292362Swnj bn = dumplo + btop(start); 8302383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 8312383Swnj sn = bn%st->nspc; 8322383Swnj tn = sn/st->nsect; 8332383Swnj sn = sn%st->nsect; 8342362Swnj hpaddr->hpdc = cn; 8352362Swnj hpaddr->hpda = (tn << 8) + sn; 8362362Swnj for (i = 0; i < blk; i++) 8372362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 8382383Swnj mba->mba_sr = -1; 8392383Swnj mba->mba_bcr = -(blk*NBPG); 8402383Swnj mba->mba_var = 0; 8412624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 8423093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 8432362Swnj ; 8443093Swnj if (hpaddr->hpds&HPDS_ERR) 8452827Swnj return (EIO); 8462362Swnj start += blk*NBPG; 8472362Swnj num -= blk; 8482362Swnj } 8492362Swnj return (0); 8502362Swnj } 8511565Sbill #endif 852