1*7831Sroot /* hp.c 4.53 82/08/22 */ 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" 377635Ssam #include "../h/ioctl.h" 385726Sroot #include "../h/dkio.h" 397738Sroot #include "../h/uio.h" 4021Sbill 412383Swnj #include "../h/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 34321Sbill hpstrategy(bp) 3442383Swnj register struct buf *bp; 34521Sbill { 3462978Swnj register struct mba_device *mi; 3472383Swnj register struct hpst *st; 3482383Swnj register int unit; 34921Sbill long sz, bn; 3502383Swnj int xunit = minor(bp->b_dev) & 07; 3515432Sroot int s; 35221Sbill 35321Sbill sz = bp->b_bcount; 35421Sbill sz = (sz+511) >> 9; 35521Sbill unit = dkunit(bp); 3562383Swnj if (unit >= NHP) 3572383Swnj goto bad; 3582383Swnj mi = hpinfo[unit]; 3592395Swnj if (mi == 0 || mi->mi_alive == 0) 3602383Swnj goto bad; 3612383Swnj st = &hpst[mi->mi_type]; 3625726Sroot if (ML11) { 3635726Sroot if (bp->b_blkno < 0 || 3645726Sroot dkblock(bp)+sz > mlsize[mi->mi_unit]) 3655726Sroot goto bad; 3665726Sroot bp->b_cylin = 0; 3675726Sroot } else { 3685726Sroot if (bp->b_blkno < 0 || 3695726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 3705726Sroot goto bad; 3715726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 3725726Sroot } 3735432Sroot s = spl5(); 3742383Swnj disksort(&mi->mi_tab, bp); 3752383Swnj if (mi->mi_tab.b_active == 0) 3762383Swnj mbustart(mi); 3775432Sroot splx(s); 3782383Swnj return; 3792383Swnj 3802383Swnj bad: 3812383Swnj bp->b_flags |= B_ERROR; 3822383Swnj iodone(bp); 3832383Swnj return; 38421Sbill } 38521Sbill 3862383Swnj hpustart(mi) 3872978Swnj register struct mba_device *mi; 38821Sbill { 3892624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 3902383Swnj register struct buf *bp = mi->mi_tab.b_actf; 3913706Sroot register struct hpst *st = &hpst[mi->mi_type]; 39221Sbill daddr_t bn; 3933102Swnj int sn, dist; 39421Sbill 3953706Sroot hpaddr->hpcs1 = 0; 3962624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 3972383Swnj return (MBU_BUSY); 3983706Sroot if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) { 3993726Sroot #ifndef NOBADSECT 4003706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4013706Sroot #endif 4023706Sroot 4033706Sroot hpinit[mi->mi_unit] = 1; 4042624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4053140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4063140Swnj printf("DCLR attn\n"); 4072624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4085726Sroot if (!ML11) 4095726Sroot hpaddr->hpof = HPOF_FMT22; 4103140Swnj mbclrattn(mi); 4113726Sroot #ifndef NOBADSECT 4125726Sroot if (!ML11) { 4135726Sroot bbp->b_flags = B_READ|B_BUSY; 4145726Sroot bbp->b_dev = bp->b_dev; 4155726Sroot bbp->b_bcount = 512; 4165726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 4175726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 4185726Sroot bbp->b_cylin = st->ncyl - 1; 4195726Sroot mi->mi_tab.b_actf = bbp; 4205726Sroot bbp->av_forw = bp; 4215726Sroot bp = bbp; 4225726Sroot } 4233706Sroot #endif 42421Sbill } 4252604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 4262383Swnj return (MBU_DODATA); 4275726Sroot if (ML11) 4285726Sroot return (MBU_DODATA); 4293093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 4302383Swnj return (MBU_DODATA); 4312395Swnj bn = dkblock(bp); 4322395Swnj sn = bn%st->nspc; 4332395Swnj sn = (sn+st->nsect-hpSDIST)%st->nsect; 4342383Swnj if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) { 4352604Swnj if (hpseek) 4362383Swnj return (MBU_DODATA); 4372383Swnj dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1; 4382383Swnj if (dist < 0) 4392383Swnj dist += st->nsect; 4402383Swnj if (dist > st->nsect - hpRDIST) 4412383Swnj return (MBU_DODATA); 4422614Swnj } else 4432614Swnj hpaddr->hpdc = bp->b_cylin; 4442604Swnj if (hpseek) 4452624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 446305Sbill else { 447305Sbill hpaddr->hpda = sn; 4482624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 449305Sbill } 4502383Swnj return (MBU_STARTED); 45121Sbill } 45221Sbill 4532383Swnj hpstart(mi) 4542978Swnj register struct mba_device *mi; 45521Sbill { 4562624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4572383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4582383Swnj register struct hpst *st = &hpst[mi->mi_type]; 45921Sbill daddr_t bn; 4602383Swnj int sn, tn; 46121Sbill 46221Sbill bn = dkblock(bp); 4635726Sroot if (ML11) 4645726Sroot hpaddr->hpda = bn; 4655726Sroot else { 4665726Sroot sn = bn%st->nspc; 4675726Sroot tn = sn/st->nsect; 4685726Sroot sn %= st->nsect; 4695726Sroot hpaddr->hpdc = bp->b_cylin; 4705726Sroot hpaddr->hpda = (tn << 8) + sn; 4715726Sroot } 4725726Sroot if (hphdr[mi->mi_unit]) { 4735726Sroot if (bp->b_flags & B_READ) 4745726Sroot return (HP_RHDR|HP_GO); 4755726Sroot else 4765726Sroot return (HP_WHDR|HP_GO); 4775726Sroot } 4785726Sroot return (0); 47921Sbill } 48021Sbill 4813102Swnj hpdtint(mi, mbsr) 4822978Swnj register struct mba_device *mi; 4833102Swnj int mbsr; 48421Sbill { 4852624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4862383Swnj register struct buf *bp = mi->mi_tab.b_actf; 4875893Swnj register int er1, er2; 4882826Swnj int retry = 0; 48921Sbill 4903726Sroot #ifndef NOBADSECT 4913706Sroot if (bp->b_flags&B_BAD) { 4923706Sroot if (hpecc(mi, CONT)) 4933706Sroot return(MBD_RESTARTED); 4943706Sroot } 4953706Sroot #endif 4963102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 4973706Sroot #ifdef HPDEBUG 4983289Swnj if (hpdebug) { 4993706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5003706Sroot 5013706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 5023706Sroot bp, bp->b_cylin, bp->b_blkno, 5033706Sroot hpaddr->hpas&0xff); 5043706Sroot printf("dc %x da %x\n",dc&0xffff, da&0xffff); 5053289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 5063289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5073289Swnj printf("er1=%b er2=%b\n", 5083289Swnj hpaddr->hper1, HPER1_BITS, 5093289Swnj hpaddr->hper2, HPER2_BITS); 5103289Swnj DELAY(1000000); 5113289Swnj } 5123706Sroot #endif 5135858Swnj er1 = hpaddr->hper1; 5145893Swnj er2 = hpaddr->hper2; 5155893Swnj if (er1 & HPER1_HCRC) { 5165858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 5175893Swnj er2 &= ~HPER2_BSE; 5185893Swnj } 5195858Swnj if (er1&HPER1_WLE) { 5202925Swnj printf("hp%d: write locked\n", dkunit(bp)); 5212826Swnj bp->b_flags |= B_ERROR; 5225858Swnj } else if ((er1&0xffff) == HPER1_FER && RP06 && 5235726Sroot hphdr[mi->mi_unit] == 0) { 5245726Sroot #ifndef NOBADSECT 5255726Sroot if (hpecc(mi, BSE)) 5265726Sroot return(MBD_RESTARTED); 5275726Sroot else 5285726Sroot #endif 5295726Sroot goto hard; 5302826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 5313102Swnj mbsr & MBSR_HARD || 5325858Swnj er1 & HPER1_HARD || 5335726Sroot hphdr[mi->mi_unit] || 5345893Swnj (!ML11 && (er2 & HPER2_HARD))) { 5353706Sroot hard: 5362925Swnj harderr(bp, "hp"); 5373271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 5383271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5393706Sroot printf("er1=%b er2=%b", 5402826Swnj hpaddr->hper1, HPER1_BITS, 5412826Swnj hpaddr->hper2, HPER2_BITS); 5423706Sroot if (hpaddr->hpmr) 5433706Sroot printf(" mr=%o", hpaddr->hpmr&0xffff); 5443706Sroot if (hpaddr->hpmr2) 5453706Sroot printf(" mr2=%o", hpaddr->hpmr2&0xffff); 5463706Sroot printf("\n"); 5472826Swnj bp->b_flags |= B_ERROR; 5483143Swnj hprecal[mi->mi_unit] = 0; 5495893Swnj } else if ((er2 & HPER2_BSE) && !ML11) { 5503726Sroot #ifndef NOBADSECT 5513706Sroot if (hpecc(mi, BSE)) 5523706Sroot return(MBD_RESTARTED); 5533706Sroot else 5543706Sroot #endif 5553706Sroot goto hard; 5565893Swnj } else if (RM80 && er2&HPER2_SSE) { 5573988Sroot (void) hpecc(mi, SSE); 5582883Swnj return (MBD_RESTARTED); 5595858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 5603706Sroot if (hpecc(mi, ECC)) 5612383Swnj return (MBD_RESTARTED); 5622826Swnj /* else done */ 5632826Swnj } else 5642826Swnj retry = 1; 5652826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 5665726Sroot if (ML11) { 5675726Sroot if (mi->mi_tab.b_errcnt >= 16) 5685726Sroot goto hard; 5695726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 5702826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 5713706Sroot hprecal[mi->mi_unit] = 1; 5723706Sroot return(MBD_RESTARTED); 57321Sbill } 5742826Swnj if (retry) 5752826Swnj return (MBD_RETRY); 5762826Swnj } 5773706Sroot #ifdef HPDEBUG 5783289Swnj else 5793289Swnj if (hpdebug && hprecal[mi->mi_unit]) { 5803289Swnj printf("recal %d ", hprecal[mi->mi_unit]); 5813289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 5823289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5833289Swnj printf("er1=%b er2=%b\n", 5843289Swnj hpaddr->hper1, HPER1_BITS, 5853289Swnj hpaddr->hper2, HPER2_BITS); 5863289Swnj } 5873706Sroot #endif 5883093Swnj switch (hprecal[mi->mi_unit]) { 5893093Swnj 5903093Swnj case 1: 5913093Swnj hpaddr->hpdc = bp->b_cylin; 5923093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 5933706Sroot hprecal[mi->mi_unit]++; 5943706Sroot return (MBD_RESTARTED); 5953093Swnj case 2: 5963093Swnj if (mi->mi_tab.b_errcnt < 16 || 5973289Swnj (bp->b_flags & B_READ) == 0) 5983093Swnj goto donerecal; 5993093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 6003093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 6013093Swnj hprecal[mi->mi_unit]++; 6023093Swnj return (MBD_RESTARTED); 6033093Swnj donerecal: 6043158Swnj case 3: 6052892Swnj hprecal[mi->mi_unit] = 0; 6062892Swnj return (MBD_RETRY); 6072892Swnj } 6085726Sroot hphdr[mi->mi_unit] = 0; 6092383Swnj bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff; 6103640Swnj if (mi->mi_tab.b_errcnt >= 16) { 6113093Swnj /* 6123093Swnj * This is fast and occurs rarely; we don't 6133093Swnj * bother with interrupts. 6143093Swnj */ 6152624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 6163093Swnj while (hpaddr->hpds & HPDS_PIP) 6172383Swnj ; 6182383Swnj mbclrattn(mi); 61921Sbill } 6205726Sroot if (!ML11) { 6215726Sroot hpaddr->hpof = HPOF_FMT22; 6225726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 6235726Sroot } 6242383Swnj return (MBD_DONE); 62521Sbill } 62621Sbill 6277738Sroot hpread(dev, uio) 6282624Swnj dev_t dev; 6297738Sroot struct uio *uio; 63021Sbill { 6312624Swnj register int unit = minor(dev) >> 3; 63221Sbill 6332624Swnj if (unit >= NHP) 6342624Swnj u.u_error = ENXIO; 6352624Swnj else 6367738Sroot physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio); 63721Sbill } 63821Sbill 639*7831Sroot hpwrite(dev, uio) 6402624Swnj dev_t dev; 641*7831Sroot struct uio *uio; 64221Sbill { 6432624Swnj register int unit = minor(dev) >> 3; 64421Sbill 6452624Swnj if (unit >= NHP) 6462624Swnj u.u_error = ENXIO; 6472624Swnj else 648*7831Sroot physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio); 64921Sbill } 65021Sbill 6515726Sroot /*ARGSUSED*/ 6527635Ssam hpioctl(dev, cmd, data, flag) 6535726Sroot dev_t dev; 6545726Sroot int cmd; 6557635Ssam caddr_t data; 6565726Sroot int flag; 6575726Sroot { 6585726Sroot 6595726Sroot switch (cmd) { 6607635Ssam 6615726Sroot case DKIOCHDR: /* do header read/write */ 6625726Sroot hphdr[minor(dev)>>3] = 1; 6635726Sroot return; 6645726Sroot 6655726Sroot default: 6665726Sroot u.u_error = ENXIO; 6675726Sroot } 6685726Sroot } 6695726Sroot 6703706Sroot hpecc(mi, flag) 6712978Swnj register struct mba_device *mi; 6723706Sroot int flag; 67321Sbill { 6742383Swnj register struct mba_regs *mbp = mi->mi_mba; 6752624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 6762383Swnj register struct buf *bp = mi->mi_tab.b_actf; 6773706Sroot register struct hpst *st = &hpst[mi->mi_type]; 6783706Sroot int npf, o; 6792383Swnj int bn, cn, tn, sn; 680914Sbill int bcr; 68121Sbill 682914Sbill bcr = mbp->mba_bcr & 0xffff; 683914Sbill if (bcr) 684914Sbill bcr |= 0xffff0000; /* sxt */ 6853726Sroot #ifndef NOBADSECT 6863706Sroot if (flag == CONT) 6873706Sroot npf = bp->b_error; 6883706Sroot else 6893706Sroot #endif 6903706Sroot npf = btop(bcr + bp->b_bcount); 691420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 692420Sbill bn = dkblock(bp); 693420Sbill cn = bp->b_cylin; 6943706Sroot sn = bn%(st->nspc) + npf; 6952383Swnj tn = sn/st->nsect; 6962383Swnj sn %= st->nsect; 6972383Swnj cn += tn/st->ntrak; 6982383Swnj tn %= st->ntrak; 6993706Sroot switch (flag) { 7003706Sroot case ECC: 7013706Sroot { 7023706Sroot register int i; 7033706Sroot caddr_t addr; 7043706Sroot struct pte mpte; 7053706Sroot int bit, byte, mask; 7063706Sroot 7073706Sroot npf--; /* because block in error is previous block */ 7083706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 7093706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 7103706Sroot mask = rp->hpec2&0xffff; 7113706Sroot i = (rp->hpec1&0xffff) - 1; /* -1 makes 0 origin */ 7123706Sroot bit = i&07; 7133706Sroot i = (i&~07)>>3; 7143706Sroot byte = i + o; 7153706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 7163706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 7173706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 7183706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 7193706Sroot byte++; 7203706Sroot i++; 7213706Sroot bit -= 8; 7223706Sroot } 7233706Sroot if (bcr == 0) 7243706Sroot return (0); 7253847Sroot npf++; 7263706Sroot break; 7273706Sroot } 7283706Sroot 7293706Sroot case SSE: 7303706Sroot rp->hpof |= HPOF_SSEI; 7313706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7323706Sroot break; 7333706Sroot 7343726Sroot #ifndef NOBADSECT 7353706Sroot case BSE: 7363706Sroot #ifdef HPBDEBUG 7373706Sroot if (hpbdebug) 7383706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 7393706Sroot #endif 7403706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 7413706Sroot return(0); 7423706Sroot bp->b_flags |= B_BAD; 7433706Sroot bp->b_error = npf + 1; 7443706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 7453706Sroot cn = bn/st->nspc; 7463706Sroot sn = bn%st->nspc; 7473706Sroot tn = sn/st->nsect; 7483706Sroot sn %= st->nsect; 7493706Sroot mbp->mba_bcr = -512; 7503706Sroot #ifdef HPBDEBUG 7513706Sroot if (hpbdebug) 7523706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 7533706Sroot #endif 7543706Sroot break; 7553706Sroot 7563706Sroot case CONT: 7573706Sroot #ifdef HPBDEBUG 7583706Sroot if (hpbdebug) 7593706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 7603706Sroot #endif 7613706Sroot npf = bp->b_error; 7623706Sroot bp->b_flags &= ~B_BAD; 7633706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7643706Sroot if ((mbp->mba_bcr & 0xffff) == 0) 7653706Sroot return(0); 7663706Sroot break; 7673706Sroot #endif 7683706Sroot } 7693706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 7703350Swnj if (rp->hpof&HPOF_SSEI) 7712883Swnj sn++; 772420Sbill rp->hpdc = cn; 773420Sbill rp->hpda = (tn<<8) + sn; 774420Sbill mbp->mba_sr = -1; 7753706Sroot mbp->mba_var = (int)ptob(npf) + o; 7763706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 7773706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 778420Sbill return (1); 77921Sbill } 7802362Swnj 7812362Swnj #define DBSIZE 20 7822362Swnj 7832362Swnj hpdump(dev) 7842362Swnj dev_t dev; 7852362Swnj { 7862978Swnj register struct mba_device *mi; 7872383Swnj register struct mba_regs *mba; 7882624Swnj struct hpdevice *hpaddr; 7892362Swnj char *start; 7902383Swnj int num, unit; 7912383Swnj register struct hpst *st; 7922362Swnj 7932362Swnj num = maxfree; 7942362Swnj start = 0; 7952362Swnj unit = minor(dev) >> 3; 7962827Swnj if (unit >= NHP) 7972827Swnj return (ENXIO); 7982383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 7992978Swnj mi = phys(hpinfo[unit],struct mba_device *); 8002827Swnj if (mi == 0 || mi->mi_alive == 0) 8012827Swnj return (ENXIO); 8022383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 8033102Swnj mba->mba_cr = MBCR_INIT; 8042624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 8053093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 8062624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 8072624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 8083093Swnj hpaddr->hpof = HPOF_FMT22; 8092362Swnj } 8102383Swnj st = &hpst[mi->mi_type]; 8112827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 8122827Swnj return (EINVAL); 8132362Swnj while (num > 0) { 8142383Swnj register struct pte *hpte = mba->mba_map; 8152362Swnj register int i; 8162383Swnj int blk, cn, sn, tn; 8172362Swnj daddr_t bn; 8182362Swnj 8192362Swnj blk = num > DBSIZE ? DBSIZE : num; 8202362Swnj bn = dumplo + btop(start); 8212383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 8222383Swnj sn = bn%st->nspc; 8232383Swnj tn = sn/st->nsect; 8242383Swnj sn = sn%st->nsect; 8252362Swnj hpaddr->hpdc = cn; 8262362Swnj hpaddr->hpda = (tn << 8) + sn; 8272362Swnj for (i = 0; i < blk; i++) 8282362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 8292383Swnj mba->mba_sr = -1; 8302383Swnj mba->mba_bcr = -(blk*NBPG); 8312383Swnj mba->mba_var = 0; 8322624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 8333093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 8342362Swnj ; 8353093Swnj if (hpaddr->hpds&HPDS_ERR) 8362827Swnj return (EIO); 8372362Swnj start += blk*NBPG; 8382362Swnj num -= blk; 8392362Swnj } 8402362Swnj return (0); 8412362Swnj } 8421565Sbill #endif 843