1*7313Ssam /* hp.c 4.50 82/06/27 */ 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" 312978Swnj #include "../h/mbareg.h" 322978Swnj #include "../h/mbavar.h" 3321Sbill #include "../h/mtpr.h" 34420Sbill #include "../h/vm.h" 352362Swnj #include "../h/cmap.h" 363706Sroot #include "../h/dkbad.h" 375726Sroot #include "../h/dkio.h" 3821Sbill 392383Swnj #include "../h/hpreg.h" 4021Sbill 412383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 422383Swnj struct size { 4321Sbill daddr_t nblocks; 4421Sbill int cyloff; 453706Sroot } hp6_sizes[8] = { 46886Sbill 15884, 0, /* A=cyl 0 thru 37 */ 47886Sbill 33440, 38, /* B=cyl 38 thru 117 */ 48886Sbill 340670, 0, /* C=cyl 0 thru 814 */ 4921Sbill 0, 0, 5021Sbill 0, 0, 5121Sbill 0, 0, 523726Sroot #ifndef NOBADSECT 533729Sroot 291280, 118, /* G=cyl 118 thru 814 */ 543706Sroot #else 553706Sroot 291346, 118, 563706Sroot #endif 5721Sbill 0, 0, 583706Sroot }, rm3_sizes[8] = { 59886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 60886Sbill 33440, 100, /* B=cyl 100 thru 309 */ 61886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 6221Sbill 0, 0, 6321Sbill 0, 0, 643442Sroot 0, 0, 653726Sroot #ifndef NOBADSECT 663729Sroot 81984, 310, /* G=cyl 310 thru 822 */ 673706Sroot #else 683706Sroot 82080, 310, 693706Sroot #endif 7021Sbill 0, 0, 71886Sbill }, rm5_sizes[8] = { 726927Ssam #ifndef CAD 73886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 74886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 753271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 76886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 77886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 783726Sroot #ifndef NOBADSECT 793729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 803729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 813706Sroot #else 825695Sroot 86336, 681, 833706Sroot 158688, 562, 843706Sroot #endif 85886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 866927Ssam #else 876927Ssam 15884, 0, /* A=cyl 0 thru 26 */ 886927Ssam 33440, 27, /* B=cyl 27 thru 81 */ 896927Ssam 495520, 0, /* C=cyl 0 thru 814 */ 906927Ssam 15884, 562, /* D=cyl 562 thru 588 */ 916927Ssam 55936, 589, /* E=cyl 589 thru 680 */ 926927Ssam #ifndef NOBADSECT 936927Ssam 81376, 681, /* F=cyl 681 thru 814 */ 946927Ssam 153728, 562, /* G=cyl 562 thru 814 */ 956927Ssam #else 966927Ssam 81472, 681, 976927Ssam 153824, 562, 986927Ssam #endif 996927Ssam 291346, 82, /* H=cyl 82 thru 561 */ 1006927Ssam #endif 1012383Swnj }, rm80_sizes[8] = { 1022383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 1032383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 1042383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 1052383Swnj 0, 0, 1062383Swnj 0, 0, 1072383Swnj 0, 0, 1082383Swnj 82080, 115, /* G=cyl 115 thru 304 */ 1093729Sroot 110143, 305, /* H=cyl 305 thru 558 */ 1103706Sroot }, hp7_sizes[8] = { 1116927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 1123706Sroot 64000, 10, /* B=cyl 10 thru 49 */ 1133706Sroot 1008000,0, /* C=cyl 0 thru 629 */ 1143706Sroot 15884, 330, /* D=cyl 330 thru 339 */ 1153706Sroot 256000, 340, /* E=cyl 340 thru 499 */ 1163729Sroot 207850, 500, /* F=cyl 500 thru 629 */ 1173729Sroot 479850, 330, /* G=cyl 330 thru 629 */ 1183706Sroot 448000, 50, /* H=cyl 50 thru 329 */ 1196927Ssam }, si9775_sizes[8] = { 1206927Ssam 16640, 0, /* A=cyl 0 thru 12 */ 1216927Ssam 34560, 13, /* B=cyl 13 thru 39 */ 1226927Ssam 1079040, 0, /* C=cyl 0 thru 842 - whole disk */ 1236927Ssam 0, 0, /* D unused */ 1246927Ssam 0, 0, /* E unused */ 1256927Ssam 0, 0, /* F unused */ 1266927Ssam 513280, 40, /* G=cyl 40 thru 440 */ 1276927Ssam 513280, 441, /* H=cyl 441 thru 841 */ 1286927Ssam }, si9730_sizes[8] = { 1296927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1306927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1316927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 1326927Ssam 0, 0, 1336927Ssam 0, 0, 1346927Ssam 0, 0, 1356927Ssam 0, 0, 1366927Ssam #ifndef NOBADSECT 1376927Ssam 213664, 155, /* H=cyl 155 thru 822 */ 1386927Ssam #else 1396927Ssam 213760, 155, 1406927Ssam #endif 1416927Ssam }, hpam_sizes[8] = { 1426927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1436927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1446927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 1456927Ssam 27786, 668, 1466927Ssam 27786, 723, 1476927Ssam 125440, 778, 1486927Ssam 181760, 668, /* G=cyl 668 thru 1022 */ 1496927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 15021Sbill }; 1512383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 15221Sbill 1532383Swnj #define _hpSDIST 2 1542383Swnj #define _hpRDIST 3 1552383Swnj 1562383Swnj int hpSDIST = _hpSDIST; 1572383Swnj int hpRDIST = _hpRDIST; 1582383Swnj 1596927Ssam /* 1606927Ssam * Table for converting Massbus drive types into 1616927Ssam * indices into the partition tables. Slots are 1626927Ssam * left for those drives devined from other means 1636927Ssam * (e.g. SI, AMPEX, etc.). 1646927Ssam */ 1656927Ssam short hptypes[] = { 1666927Ssam #define HPDT_RM03 0 1676927Ssam MBDT_RM03, 1686927Ssam #define HPDT_RM05 1 1696927Ssam MBDT_RM05, 1706927Ssam #define HPDT_RP06 2 1716927Ssam MBDT_RP06, 1726927Ssam #define HPDT_RM80 3 1736927Ssam MBDT_RM80, 1746927Ssam #define HPDT_RP05 4 1756927Ssam MBDT_RP05, 1766927Ssam #define HPDT_RP07 5 1776927Ssam MBDT_RP07, 1786927Ssam #define HPDT_ML11A 6 1796927Ssam MBDT_ML11A, 1806927Ssam #define HPDT_ML11B 7 1816927Ssam MBDT_ML11B, 1826927Ssam #define HPDT_9775 8 1836927Ssam -1, 1846927Ssam #define HPDT_9730 9 1856927Ssam -1, 1866927Ssam #define HPDT_CAPRICORN 10 1876927Ssam -1, 1886927Ssam #define HPDT_RM02 11 1896927Ssam MBDT_RM02, /* beware, actually capricorn */ 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[] = { 2053706Sroot 32, 5, 32*5, 823, rm3_sizes, /* RM03 */ 2062383Swnj 32, 19, 32*19, 823, rm5_sizes, /* RM05 */ 2073706Sroot 22, 19, 22*19, 815, hp6_sizes, /* RP06 */ 2083706Sroot 31, 14, 31*14, 559, rm80_sizes, /* RM80 */ 2093706Sroot 22, 19, 22*19, 411, hp6_sizes, /* RP05 */ 2103706Sroot 50, 32, 50*32, 630, hp7_sizes, /* RP07 */ 2115726Sroot 1, 1, 1, 1, 0, /* ML11A */ 2125726Sroot 1, 1, 1, 1, 0, /* ML11B */ 2136927Ssam 32, 40, 32*40, 843, si9775_sizes, /* 9775 */ 2146927Ssam 32, 10, 32*10, 823, si9730_sizes, /* 9730 */ 2156927Ssam 32, 16, 32*16, 1024, hpam_sizes, /* AMPEX capricorn */ 2162383Swnj }; 2172383Swnj 2182624Swnj u_char hp_offset[16] = { 2193093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 2203093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 2213093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 2223093Swnj 0, 0, 0, 0, 22321Sbill }; 22421Sbill 2252624Swnj struct buf rhpbuf[NHP]; 2263726Sroot #ifndef NOBADSECT 2273706Sroot struct buf bhpbuf[NHP]; 2283706Sroot struct dkbad hpbad[NHP]; 2293706Sroot #endif 2305726Sroot /* SHOULD CONSOLIDATE ALL THIS STUFF INTO A STRUCTURE */ 2313706Sroot char hpinit[NHP]; 2322892Swnj char hprecal[NHP]; 2335726Sroot char hphdr[NHP]; 2345726Sroot daddr_t mlsize[NHP]; 23521Sbill 23621Sbill #define b_cylin b_resid 23721Sbill 2385726Sroot /* #define ML11 0 to remove ML11 support */ 2395726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2405726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2415726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2425726Sroot 24321Sbill #ifdef INTRLVE 24421Sbill daddr_t dkblock(); 24521Sbill #endif 24621Sbill 2472604Swnj int hpseek; 2482604Swnj 2492978Swnj /*ARGSUSED*/ 2502978Swnj hpattach(mi, slave) 2512978Swnj struct mba_device *mi; 2522604Swnj { 2536927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 2546927Ssam 2556927Ssam switch (mi->mi_type) { 2566927Ssam 2576927Ssam /* 2586927Ssam * Model-byte processing for SI 9400 controllers. 2596927Ssam * NB: Only deals with RM03 and RM05 emulations. 2606927Ssam */ 2616927Ssam case HPDT_RM03: 2626927Ssam case HPDT_RM05: { 2636927Ssam register int hpsn; 2646927Ssam 2656927Ssam hpsn = hpaddr->hpsn; 2666927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 2676927Ssam break; 2686927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 2696927Ssam 2706927Ssam case SI9775D: 2716927Ssam printf("hp%d: si 9775 (direct)\n", mi->mi_unit); 2726927Ssam mi->mi_type = HPDT_9775; 2736927Ssam break; 2746927Ssam 2756927Ssam case SI9730D: 2766927Ssam printf("hp%d: si 9730 (direct)\n", mi->mi_unit); 2776927Ssam mi->mi_type = HPDT_9730; 2786927Ssam break; 2796927Ssam 2806927Ssam #ifdef CAD 2817035Swnj /* 2827035Swnj * AMPEX 9300, SI Combination needs a have the drive cleared 2837035Swnj * before we start. We do not know why, but tests show 2847035Swnj * that the recalibrate fixes the problem. 2857035Swnj */ 2866927Ssam case SI9766: 2876927Ssam printf("hp%d: 9776/9300\n", mi->mi_unit); 2886927Ssam mi->mi_type = HPDT_RM05; 2897035Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 2907035Swnj DELAY(100000); 2916927Ssam break; 2926927Ssam 2936927Ssam case SI9762: 2946927Ssam printf("hp%d: 9762\n", mi->mi_unit); 2956927Ssam mi->mi_type = HPDT_RM03; 2966927Ssam break; 2976927Ssam #endif 2986927Ssam } 2996927Ssam break; 3006927Ssam } 3016927Ssam 3026927Ssam /* 3036927Ssam * CAPRICORN KLUDGE...poke the holding register 3046927Ssam * to find out the number of tracks. If it's 15 3056927Ssam * we believe it's a Capricorn. 3066927Ssam */ 3076927Ssam case HPDT_RM02: 3086927Ssam hpaddr->hpcs1 = HP_NOP; 3096927Ssam hpaddr->hphr = HPHR_MAXTRAK; 310*7313Ssam if ((hpaddr->hphr&0xffff) == 15) { 3116927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 3126927Ssam mi->mi_type = HPDT_CAPRICORN; 3136927Ssam } 3146927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 3156927Ssam break; 3166927Ssam 3176927Ssam case HPDT_ML11A: 3186927Ssam case HPDT_ML11B: { 3195726Sroot register int trt, sz; 3202604Swnj 3215726Sroot sz = hpaddr->hpmr & HPMR_SZ; 3225726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 3235726Sroot sz >>= 2; 3245726Sroot mlsize[mi->mi_unit] = sz; 3255726Sroot if (mi->mi_dk >= 0) { 3265726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3275726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 3285726Sroot } 3296927Ssam /* A CHEAT - ML11B D.T. SHOULD == ML11A */ 3306927Ssam mi->mi_type = HPDT_ML11A; 3316927Ssam break; 3326927Ssam } 3336927Ssam } 3346927Ssam if (!ML11 && mi->mi_dk >= 0) { 3355726Sroot register struct hpst *st = &hpst[mi->mi_type]; 3365726Sroot 3372757Swnj dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 3385726Sroot } 3392604Swnj } 3402604Swnj 34121Sbill hpstrategy(bp) 3422383Swnj register struct buf *bp; 34321Sbill { 3442978Swnj register struct mba_device *mi; 3452383Swnj register struct hpst *st; 3462383Swnj register int unit; 34721Sbill long sz, bn; 3482383Swnj int xunit = minor(bp->b_dev) & 07; 3495432Sroot int s; 35021Sbill 35121Sbill sz = bp->b_bcount; 35221Sbill sz = (sz+511) >> 9; 35321Sbill unit = dkunit(bp); 3542383Swnj if (unit >= NHP) 3552383Swnj goto bad; 3562383Swnj mi = hpinfo[unit]; 3572395Swnj if (mi == 0 || mi->mi_alive == 0) 3582383Swnj goto bad; 3592383Swnj st = &hpst[mi->mi_type]; 3605726Sroot if (ML11) { 3615726Sroot if (bp->b_blkno < 0 || 3625726Sroot dkblock(bp)+sz > mlsize[mi->mi_unit]) 3635726Sroot goto bad; 3645726Sroot bp->b_cylin = 0; 3655726Sroot } else { 3665726Sroot if (bp->b_blkno < 0 || 3675726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 3685726Sroot goto bad; 3695726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 3705726Sroot } 3715432Sroot s = spl5(); 3722383Swnj disksort(&mi->mi_tab, bp); 3732383Swnj if (mi->mi_tab.b_active == 0) 3742383Swnj mbustart(mi); 3755432Sroot splx(s); 3762383Swnj return; 3772383Swnj 3782383Swnj bad: 3792383Swnj bp->b_flags |= B_ERROR; 3802383Swnj iodone(bp); 3812383Swnj return; 38221Sbill } 38321Sbill 3842383Swnj hpustart(mi) 3852978Swnj register struct mba_device *mi; 38621Sbill { 3872624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 3882383Swnj register struct buf *bp = mi->mi_tab.b_actf; 3893706Sroot register struct hpst *st = &hpst[mi->mi_type]; 39021Sbill daddr_t bn; 3913102Swnj int sn, dist; 39221Sbill 3933706Sroot hpaddr->hpcs1 = 0; 3942624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 3952383Swnj return (MBU_BUSY); 3963706Sroot if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) { 3973726Sroot #ifndef NOBADSECT 3983706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 3993706Sroot #endif 4003706Sroot 4013706Sroot hpinit[mi->mi_unit] = 1; 4022624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4033140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4043140Swnj printf("DCLR attn\n"); 4052624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4065726Sroot if (!ML11) 4075726Sroot hpaddr->hpof = HPOF_FMT22; 4083140Swnj mbclrattn(mi); 4093726Sroot #ifndef NOBADSECT 4105726Sroot if (!ML11) { 4115726Sroot bbp->b_flags = B_READ|B_BUSY; 4125726Sroot bbp->b_dev = bp->b_dev; 4135726Sroot bbp->b_bcount = 512; 4145726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 4155726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 4165726Sroot bbp->b_cylin = st->ncyl - 1; 4175726Sroot mi->mi_tab.b_actf = bbp; 4185726Sroot bbp->av_forw = bp; 4195726Sroot bp = bbp; 4205726Sroot } 4213706Sroot #endif 42221Sbill } 4232604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 4242383Swnj return (MBU_DODATA); 4255726Sroot if (ML11) 4265726Sroot return (MBU_DODATA); 4273093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 4282383Swnj return (MBU_DODATA); 4292395Swnj bn = dkblock(bp); 4302395Swnj sn = bn%st->nspc; 4312395Swnj sn = (sn+st->nsect-hpSDIST)%st->nsect; 4322383Swnj if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) { 4332604Swnj if (hpseek) 4342383Swnj return (MBU_DODATA); 4352383Swnj dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1; 4362383Swnj if (dist < 0) 4372383Swnj dist += st->nsect; 4382383Swnj if (dist > st->nsect - hpRDIST) 4392383Swnj return (MBU_DODATA); 4402614Swnj } else 4412614Swnj hpaddr->hpdc = bp->b_cylin; 4422604Swnj if (hpseek) 4432624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 444305Sbill else { 445305Sbill hpaddr->hpda = sn; 4462624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 447305Sbill } 4482383Swnj return (MBU_STARTED); 44921Sbill } 45021Sbill 4512383Swnj hpstart(mi) 4522978Swnj register struct mba_device *mi; 45321Sbill { 4542624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4552383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4562383Swnj register struct hpst *st = &hpst[mi->mi_type]; 45721Sbill daddr_t bn; 4582383Swnj int sn, tn; 45921Sbill 46021Sbill bn = dkblock(bp); 4615726Sroot if (ML11) 4625726Sroot hpaddr->hpda = bn; 4635726Sroot else { 4645726Sroot sn = bn%st->nspc; 4655726Sroot tn = sn/st->nsect; 4665726Sroot sn %= st->nsect; 4675726Sroot hpaddr->hpdc = bp->b_cylin; 4685726Sroot hpaddr->hpda = (tn << 8) + sn; 4695726Sroot } 4705726Sroot if (hphdr[mi->mi_unit]) { 4715726Sroot if (bp->b_flags & B_READ) 4725726Sroot return (HP_RHDR|HP_GO); 4735726Sroot else 4745726Sroot return (HP_WHDR|HP_GO); 4755726Sroot } 4765726Sroot return (0); 47721Sbill } 47821Sbill 4793102Swnj hpdtint(mi, mbsr) 4802978Swnj register struct mba_device *mi; 4813102Swnj int mbsr; 48221Sbill { 4832624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4842383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4855893Swnj register int er1, er2; 4862826Swnj int retry = 0; 48721Sbill 4883726Sroot #ifndef NOBADSECT 4893706Sroot if (bp->b_flags&B_BAD) { 4903706Sroot if (hpecc(mi, CONT)) 4913706Sroot return(MBD_RESTARTED); 4923706Sroot } 4933706Sroot #endif 4943102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 4953706Sroot #ifdef HPDEBUG 4963289Swnj if (hpdebug) { 4973706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 4983706Sroot 4993706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 5003706Sroot bp, bp->b_cylin, bp->b_blkno, 5013706Sroot hpaddr->hpas&0xff); 5023706Sroot printf("dc %x da %x\n",dc&0xffff, da&0xffff); 5033289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 5043289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5053289Swnj printf("er1=%b er2=%b\n", 5063289Swnj hpaddr->hper1, HPER1_BITS, 5073289Swnj hpaddr->hper2, HPER2_BITS); 5083289Swnj DELAY(1000000); 5093289Swnj } 5103706Sroot #endif 5115858Swnj er1 = hpaddr->hper1; 5125893Swnj er2 = hpaddr->hper2; 5135893Swnj if (er1 & HPER1_HCRC) { 5145858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 5155893Swnj er2 &= ~HPER2_BSE; 5165893Swnj } 5175858Swnj if (er1&HPER1_WLE) { 5182925Swnj printf("hp%d: write locked\n", dkunit(bp)); 5192826Swnj bp->b_flags |= B_ERROR; 5205858Swnj } else if ((er1&0xffff) == HPER1_FER && RP06 && 5215726Sroot hphdr[mi->mi_unit] == 0) { 5225726Sroot #ifndef NOBADSECT 5235726Sroot if (hpecc(mi, BSE)) 5245726Sroot return(MBD_RESTARTED); 5255726Sroot else 5265726Sroot #endif 5275726Sroot goto hard; 5282826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 5293102Swnj mbsr & MBSR_HARD || 5305858Swnj er1 & HPER1_HARD || 5315726Sroot hphdr[mi->mi_unit] || 5325893Swnj (!ML11 && (er2 & HPER2_HARD))) { 5333706Sroot hard: 5342925Swnj harderr(bp, "hp"); 5353271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 5363271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5373706Sroot printf("er1=%b er2=%b", 5382826Swnj hpaddr->hper1, HPER1_BITS, 5392826Swnj hpaddr->hper2, HPER2_BITS); 5403706Sroot if (hpaddr->hpmr) 5413706Sroot printf(" mr=%o", hpaddr->hpmr&0xffff); 5423706Sroot if (hpaddr->hpmr2) 5433706Sroot printf(" mr2=%o", hpaddr->hpmr2&0xffff); 5443706Sroot printf("\n"); 5452826Swnj bp->b_flags |= B_ERROR; 5463143Swnj hprecal[mi->mi_unit] = 0; 5475893Swnj } else if ((er2 & HPER2_BSE) && !ML11) { 5483726Sroot #ifndef NOBADSECT 5493706Sroot if (hpecc(mi, BSE)) 5503706Sroot return(MBD_RESTARTED); 5513706Sroot else 5523706Sroot #endif 5533706Sroot goto hard; 5545893Swnj } else if (RM80 && er2&HPER2_SSE) { 5553988Sroot (void) hpecc(mi, SSE); 5562883Swnj return (MBD_RESTARTED); 5575858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 5583706Sroot if (hpecc(mi, ECC)) 5592383Swnj return (MBD_RESTARTED); 5602826Swnj /* else done */ 5612826Swnj } else 5622826Swnj retry = 1; 5632826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 5645726Sroot if (ML11) { 5655726Sroot if (mi->mi_tab.b_errcnt >= 16) 5665726Sroot goto hard; 5675726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 5682826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 5693706Sroot hprecal[mi->mi_unit] = 1; 5703706Sroot return(MBD_RESTARTED); 57121Sbill } 5722826Swnj if (retry) 5732826Swnj return (MBD_RETRY); 5742826Swnj } 5753706Sroot #ifdef HPDEBUG 5763289Swnj else 5773289Swnj if (hpdebug && hprecal[mi->mi_unit]) { 5783289Swnj printf("recal %d ", hprecal[mi->mi_unit]); 5793289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 5803289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5813289Swnj printf("er1=%b er2=%b\n", 5823289Swnj hpaddr->hper1, HPER1_BITS, 5833289Swnj hpaddr->hper2, HPER2_BITS); 5843289Swnj } 5853706Sroot #endif 5863093Swnj switch (hprecal[mi->mi_unit]) { 5873093Swnj 5883093Swnj case 1: 5893093Swnj hpaddr->hpdc = bp->b_cylin; 5903093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 5913706Sroot hprecal[mi->mi_unit]++; 5923706Sroot return (MBD_RESTARTED); 5933093Swnj case 2: 5943093Swnj if (mi->mi_tab.b_errcnt < 16 || 5953289Swnj (bp->b_flags & B_READ) == 0) 5963093Swnj goto donerecal; 5973093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 5983093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 5993093Swnj hprecal[mi->mi_unit]++; 6003093Swnj return (MBD_RESTARTED); 6013093Swnj donerecal: 6023158Swnj case 3: 6032892Swnj hprecal[mi->mi_unit] = 0; 6042892Swnj return (MBD_RETRY); 6052892Swnj } 6065726Sroot hphdr[mi->mi_unit] = 0; 6072383Swnj bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff; 6083640Swnj if (mi->mi_tab.b_errcnt >= 16) { 6093093Swnj /* 6103093Swnj * This is fast and occurs rarely; we don't 6113093Swnj * bother with interrupts. 6123093Swnj */ 6132624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 6143093Swnj while (hpaddr->hpds & HPDS_PIP) 6152383Swnj ; 6162383Swnj mbclrattn(mi); 61721Sbill } 6185726Sroot if (!ML11) { 6195726Sroot hpaddr->hpof = HPOF_FMT22; 6205726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 6215726Sroot } 6222383Swnj return (MBD_DONE); 62321Sbill } 62421Sbill 62521Sbill hpread(dev) 6262624Swnj dev_t dev; 62721Sbill { 6282624Swnj register int unit = minor(dev) >> 3; 62921Sbill 6302624Swnj if (unit >= NHP) 6312624Swnj u.u_error = ENXIO; 6322624Swnj else 6332624Swnj physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys); 63421Sbill } 63521Sbill 63621Sbill hpwrite(dev) 6372624Swnj dev_t dev; 63821Sbill { 6392624Swnj register int unit = minor(dev) >> 3; 64021Sbill 6412624Swnj if (unit >= NHP) 6422624Swnj u.u_error = ENXIO; 6432624Swnj else 6442624Swnj physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys); 64521Sbill } 64621Sbill 6475726Sroot /*ARGSUSED*/ 6485726Sroot hpioctl(dev, cmd, addr, flag) 6495726Sroot dev_t dev; 6505726Sroot int cmd; 6515726Sroot caddr_t addr; 6525726Sroot int flag; 6535726Sroot { 6545726Sroot 6555726Sroot switch (cmd) { 6565726Sroot case DKIOCHDR: /* do header read/write */ 6575726Sroot hphdr[minor(dev)>>3] = 1; 6585726Sroot return; 6595726Sroot 6605726Sroot default: 6615726Sroot u.u_error = ENXIO; 6625726Sroot } 6635726Sroot } 6645726Sroot 6653706Sroot hpecc(mi, flag) 6662978Swnj register struct mba_device *mi; 6673706Sroot int flag; 66821Sbill { 6692383Swnj register struct mba_regs *mbp = mi->mi_mba; 6702624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 6712383Swnj register struct buf *bp = mi->mi_tab.b_actf; 6723706Sroot register struct hpst *st = &hpst[mi->mi_type]; 6733706Sroot int npf, o; 6742383Swnj int bn, cn, tn, sn; 675914Sbill int bcr; 67621Sbill 677914Sbill bcr = mbp->mba_bcr & 0xffff; 678914Sbill if (bcr) 679914Sbill bcr |= 0xffff0000; /* sxt */ 6803726Sroot #ifndef NOBADSECT 6813706Sroot if (flag == CONT) 6823706Sroot npf = bp->b_error; 6833706Sroot else 6843706Sroot #endif 6853706Sroot npf = btop(bcr + bp->b_bcount); 686420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 687420Sbill bn = dkblock(bp); 688420Sbill cn = bp->b_cylin; 6893706Sroot sn = bn%(st->nspc) + npf; 6902383Swnj tn = sn/st->nsect; 6912383Swnj sn %= st->nsect; 6922383Swnj cn += tn/st->ntrak; 6932383Swnj tn %= st->ntrak; 6943706Sroot switch (flag) { 6953706Sroot case ECC: 6963706Sroot { 6973706Sroot register int i; 6983706Sroot caddr_t addr; 6993706Sroot struct pte mpte; 7003706Sroot int bit, byte, mask; 7013706Sroot 7023706Sroot npf--; /* because block in error is previous block */ 7033706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 7043706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 7053706Sroot mask = rp->hpec2&0xffff; 7063706Sroot i = (rp->hpec1&0xffff) - 1; /* -1 makes 0 origin */ 7073706Sroot bit = i&07; 7083706Sroot i = (i&~07)>>3; 7093706Sroot byte = i + o; 7103706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 7113706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 7123706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 7133706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 7143706Sroot byte++; 7153706Sroot i++; 7163706Sroot bit -= 8; 7173706Sroot } 7183706Sroot if (bcr == 0) 7193706Sroot return (0); 7203847Sroot npf++; 7213706Sroot break; 7223706Sroot } 7233706Sroot 7243706Sroot case SSE: 7253706Sroot rp->hpof |= HPOF_SSEI; 7263706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7273706Sroot break; 7283706Sroot 7293726Sroot #ifndef NOBADSECT 7303706Sroot case BSE: 7313706Sroot #ifdef HPBDEBUG 7323706Sroot if (hpbdebug) 7333706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 7343706Sroot #endif 7353706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 7363706Sroot return(0); 7373706Sroot bp->b_flags |= B_BAD; 7383706Sroot bp->b_error = npf + 1; 7393706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 7403706Sroot cn = bn/st->nspc; 7413706Sroot sn = bn%st->nspc; 7423706Sroot tn = sn/st->nsect; 7433706Sroot sn %= st->nsect; 7443706Sroot mbp->mba_bcr = -512; 7453706Sroot #ifdef HPBDEBUG 7463706Sroot if (hpbdebug) 7473706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 7483706Sroot #endif 7493706Sroot break; 7503706Sroot 7513706Sroot case CONT: 7523706Sroot #ifdef HPBDEBUG 7533706Sroot if (hpbdebug) 7543706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 7553706Sroot #endif 7563706Sroot npf = bp->b_error; 7573706Sroot bp->b_flags &= ~B_BAD; 7583706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7593706Sroot if ((mbp->mba_bcr & 0xffff) == 0) 7603706Sroot return(0); 7613706Sroot break; 7623706Sroot #endif 7633706Sroot } 7643706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 7653350Swnj if (rp->hpof&HPOF_SSEI) 7662883Swnj sn++; 767420Sbill rp->hpdc = cn; 768420Sbill rp->hpda = (tn<<8) + sn; 769420Sbill mbp->mba_sr = -1; 7703706Sroot mbp->mba_var = (int)ptob(npf) + o; 7713706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 7723706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 773420Sbill return (1); 77421Sbill } 7752362Swnj 7762362Swnj #define DBSIZE 20 7772362Swnj 7782362Swnj hpdump(dev) 7792362Swnj dev_t dev; 7802362Swnj { 7812978Swnj register struct mba_device *mi; 7822383Swnj register struct mba_regs *mba; 7832624Swnj struct hpdevice *hpaddr; 7842362Swnj char *start; 7852383Swnj int num, unit; 7862383Swnj register struct hpst *st; 7872362Swnj 7882362Swnj num = maxfree; 7892362Swnj start = 0; 7902362Swnj unit = minor(dev) >> 3; 7912827Swnj if (unit >= NHP) 7922827Swnj return (ENXIO); 7932383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 7942978Swnj mi = phys(hpinfo[unit],struct mba_device *); 7952827Swnj if (mi == 0 || mi->mi_alive == 0) 7962827Swnj return (ENXIO); 7972383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 7983102Swnj mba->mba_cr = MBCR_INIT; 7992624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 8003093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 8012624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 8022624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 8033093Swnj hpaddr->hpof = HPOF_FMT22; 8042362Swnj } 8052383Swnj st = &hpst[mi->mi_type]; 8062827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 8072827Swnj return (EINVAL); 8082362Swnj while (num > 0) { 8092383Swnj register struct pte *hpte = mba->mba_map; 8102362Swnj register int i; 8112383Swnj int blk, cn, sn, tn; 8122362Swnj daddr_t bn; 8132362Swnj 8142362Swnj blk = num > DBSIZE ? DBSIZE : num; 8152362Swnj bn = dumplo + btop(start); 8162383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 8172383Swnj sn = bn%st->nspc; 8182383Swnj tn = sn/st->nsect; 8192383Swnj sn = sn%st->nsect; 8202362Swnj hpaddr->hpdc = cn; 8212362Swnj hpaddr->hpda = (tn << 8) + sn; 8222362Swnj for (i = 0; i < blk; i++) 8232362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 8242383Swnj mba->mba_sr = -1; 8252383Swnj mba->mba_bcr = -(blk*NBPG); 8262383Swnj mba->mba_var = 0; 8272624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 8283093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 8292362Swnj ; 8303093Swnj if (hpaddr->hpds&HPDS_ERR) 8312827Swnj return (EIO); 8322362Swnj start += blk*NBPG; 8332362Swnj num -= blk; 8342362Swnj } 8352362Swnj return (0); 8362362Swnj } 8371565Sbill #endif 838