1*5858Swnj /* hp.c 4.46 82/02/15 */ 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] = { 72886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 73886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 743271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 75886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 76886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 773726Sroot #ifndef NOBADSECT 783729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 793729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 803706Sroot #else 815695Sroot 86336, 681, 823706Sroot 158688, 562, 833706Sroot #endif 84886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 852383Swnj }, rm80_sizes[8] = { 862383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 872383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 882383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 892383Swnj 0, 0, 902383Swnj 0, 0, 912383Swnj 0, 0, 922383Swnj 82080, 115, /* G=cyl 115 thru 304 */ 933729Sroot 110143, 305, /* H=cyl 305 thru 558 */ 943706Sroot }, hp7_sizes[8] = { 953706Sroot 15844, 0, /* A=cyl 0 thru 9 */ 963706Sroot 64000, 10, /* B=cyl 10 thru 49 */ 973706Sroot 1008000,0, /* C=cyl 0 thru 629 */ 983706Sroot 15884, 330, /* D=cyl 330 thru 339 */ 993706Sroot 256000, 340, /* E=cyl 340 thru 499 */ 1003729Sroot 207850, 500, /* F=cyl 500 thru 629 */ 1013729Sroot 479850, 330, /* G=cyl 330 thru 629 */ 1023706Sroot 448000, 50, /* H=cyl 50 thru 329 */ 10321Sbill }; 1042383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 10521Sbill 1062383Swnj #define _hpSDIST 2 1072383Swnj #define _hpRDIST 3 1082383Swnj 1092383Swnj int hpSDIST = _hpSDIST; 1102383Swnj int hpRDIST = _hpRDIST; 1112383Swnj 1122383Swnj short hptypes[] = 1135726Sroot { MBDT_RM03, MBDT_RM05, MBDT_RP06, MBDT_RM80, MBDT_RP05, MBDT_RP07, 1145726Sroot MBDT_ML11A, MBDT_ML11B, 0 }; 1152978Swnj struct mba_device *hpinfo[NHP]; 1162978Swnj int hpattach(),hpustart(),hpstart(),hpdtint(); 1172383Swnj struct mba_driver hpdriver = 1182978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1192978Swnj hptypes, "hp", 0, hpinfo }; 1202383Swnj 1212383Swnj struct hpst { 1222383Swnj short nsect; 1232383Swnj short ntrak; 1242383Swnj short nspc; 1252383Swnj short ncyl; 1262383Swnj struct size *sizes; 1272383Swnj } hpst[] = { 1283706Sroot 32, 5, 32*5, 823, rm3_sizes, /* RM03 */ 1292383Swnj 32, 19, 32*19, 823, rm5_sizes, /* RM05 */ 1303706Sroot 22, 19, 22*19, 815, hp6_sizes, /* RP06 */ 1313706Sroot 31, 14, 31*14, 559, rm80_sizes, /* RM80 */ 1323706Sroot 22, 19, 22*19, 411, hp6_sizes, /* RP05 */ 1333706Sroot 50, 32, 50*32, 630, hp7_sizes, /* RP07 */ 1345726Sroot 1, 1, 1, 1, 0, /* ML11A */ 1355726Sroot 1, 1, 1, 1, 0, /* ML11B */ 1362383Swnj }; 1372383Swnj 1382624Swnj u_char hp_offset[16] = { 1393093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 1403093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 1413093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 1423093Swnj 0, 0, 0, 0, 14321Sbill }; 14421Sbill 1452624Swnj struct buf rhpbuf[NHP]; 1463726Sroot #ifndef NOBADSECT 1473706Sroot struct buf bhpbuf[NHP]; 1483706Sroot struct dkbad hpbad[NHP]; 1493706Sroot #endif 1505726Sroot /* SHOULD CONSOLIDATE ALL THIS STUFF INTO A STRUCTURE */ 1513706Sroot char hpinit[NHP]; 1522892Swnj char hprecal[NHP]; 1535726Sroot char hphdr[NHP]; 1545726Sroot daddr_t mlsize[NHP]; 15521Sbill 15621Sbill #define b_cylin b_resid 15721Sbill 1585726Sroot /* #define ML11 0 to remove ML11 support */ 1595726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 1605726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 1615726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 1625726Sroot 16321Sbill #ifdef INTRLVE 16421Sbill daddr_t dkblock(); 16521Sbill #endif 16621Sbill 1672604Swnj int hpseek; 1682604Swnj 1692978Swnj /*ARGSUSED*/ 1702978Swnj hpattach(mi, slave) 1712978Swnj struct mba_device *mi; 1722604Swnj { 1735726Sroot if (hptypes[mi->mi_type] == MBDT_ML11B) 1745726Sroot mi->mi_type--; /* A CHEAT - ML11B D.T. SHOULD == ML11A */ 1755726Sroot if (ML11) { 1765726Sroot register struct hpdevice *hpaddr = 1775726Sroot (struct hpdevice *)mi->mi_drv; 1785726Sroot register int trt, sz; 1792604Swnj 1805726Sroot sz = hpaddr->hpmr & HPMR_SZ; 1815726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 1825726Sroot sz >>= 2; 1835726Sroot mlsize[mi->mi_unit] = sz; 1845726Sroot if (mi->mi_dk >= 0) { 1855726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 1865726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 1875726Sroot } 1885726Sroot } else if (mi->mi_dk >= 0) { 1895726Sroot register struct hpst *st = &hpst[mi->mi_type]; 1905726Sroot 1912757Swnj dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 1925726Sroot } 1932604Swnj } 1942604Swnj 19521Sbill hpstrategy(bp) 1962383Swnj register struct buf *bp; 19721Sbill { 1982978Swnj register struct mba_device *mi; 1992383Swnj register struct hpst *st; 2002383Swnj register int unit; 20121Sbill long sz, bn; 2022383Swnj int xunit = minor(bp->b_dev) & 07; 2035432Sroot int s; 20421Sbill 20521Sbill sz = bp->b_bcount; 20621Sbill sz = (sz+511) >> 9; 20721Sbill unit = dkunit(bp); 2082383Swnj if (unit >= NHP) 2092383Swnj goto bad; 2102383Swnj mi = hpinfo[unit]; 2112395Swnj if (mi == 0 || mi->mi_alive == 0) 2122383Swnj goto bad; 2132383Swnj st = &hpst[mi->mi_type]; 2145726Sroot if (ML11) { 2155726Sroot if (bp->b_blkno < 0 || 2165726Sroot dkblock(bp)+sz > mlsize[mi->mi_unit]) 2175726Sroot goto bad; 2185726Sroot bp->b_cylin = 0; 2195726Sroot } else { 2205726Sroot if (bp->b_blkno < 0 || 2215726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 2225726Sroot goto bad; 2235726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 2245726Sroot } 2255432Sroot s = spl5(); 2262383Swnj disksort(&mi->mi_tab, bp); 2272383Swnj if (mi->mi_tab.b_active == 0) 2282383Swnj mbustart(mi); 2295432Sroot splx(s); 2302383Swnj return; 2312383Swnj 2322383Swnj bad: 2332383Swnj bp->b_flags |= B_ERROR; 2342383Swnj iodone(bp); 2352383Swnj return; 23621Sbill } 23721Sbill 2382383Swnj hpustart(mi) 2392978Swnj register struct mba_device *mi; 24021Sbill { 2412624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 2422383Swnj register struct buf *bp = mi->mi_tab.b_actf; 2433706Sroot register struct hpst *st = &hpst[mi->mi_type]; 24421Sbill daddr_t bn; 2453102Swnj int sn, dist; 24621Sbill 2473706Sroot hpaddr->hpcs1 = 0; 2482624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 2492383Swnj return (MBU_BUSY); 2503706Sroot if ((hpaddr->hpds & HPDS_VV) == 0 || hpinit[mi->mi_unit] == 0) { 2513726Sroot #ifndef NOBADSECT 2523706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 2533706Sroot #endif 2543706Sroot 2553706Sroot hpinit[mi->mi_unit] = 1; 2562624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 2573140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 2583140Swnj printf("DCLR attn\n"); 2592624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 2605726Sroot if (!ML11) 2615726Sroot hpaddr->hpof = HPOF_FMT22; 2623140Swnj mbclrattn(mi); 2633726Sroot #ifndef NOBADSECT 2645726Sroot if (!ML11) { 2655726Sroot bbp->b_flags = B_READ|B_BUSY; 2665726Sroot bbp->b_dev = bp->b_dev; 2675726Sroot bbp->b_bcount = 512; 2685726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 2695726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 2705726Sroot bbp->b_cylin = st->ncyl - 1; 2715726Sroot mi->mi_tab.b_actf = bbp; 2725726Sroot bbp->av_forw = bp; 2735726Sroot bp = bbp; 2745726Sroot } 2753706Sroot #endif 27621Sbill } 2772604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 2782383Swnj return (MBU_DODATA); 2795726Sroot if (ML11) 2805726Sroot return (MBU_DODATA); 2813093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 2822383Swnj return (MBU_DODATA); 2832395Swnj bn = dkblock(bp); 2842395Swnj sn = bn%st->nspc; 2852395Swnj sn = (sn+st->nsect-hpSDIST)%st->nsect; 2862383Swnj if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) { 2872604Swnj if (hpseek) 2882383Swnj return (MBU_DODATA); 2892383Swnj dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1; 2902383Swnj if (dist < 0) 2912383Swnj dist += st->nsect; 2922383Swnj if (dist > st->nsect - hpRDIST) 2932383Swnj return (MBU_DODATA); 2942614Swnj } else 2952614Swnj hpaddr->hpdc = bp->b_cylin; 2962604Swnj if (hpseek) 2972624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 298305Sbill else { 299305Sbill hpaddr->hpda = sn; 3002624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 301305Sbill } 3022383Swnj return (MBU_STARTED); 30321Sbill } 30421Sbill 3052383Swnj hpstart(mi) 3062978Swnj register struct mba_device *mi; 30721Sbill { 3082624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 3092383Swnj register struct buf *bp = mi->mi_tab.b_actf; 3102383Swnj register struct hpst *st = &hpst[mi->mi_type]; 31121Sbill daddr_t bn; 3122383Swnj int sn, tn; 31321Sbill 31421Sbill bn = dkblock(bp); 3155726Sroot if (ML11) 3165726Sroot hpaddr->hpda = bn; 3175726Sroot else { 3185726Sroot sn = bn%st->nspc; 3195726Sroot tn = sn/st->nsect; 3205726Sroot sn %= st->nsect; 3215726Sroot hpaddr->hpdc = bp->b_cylin; 3225726Sroot hpaddr->hpda = (tn << 8) + sn; 3235726Sroot } 3245726Sroot if (hphdr[mi->mi_unit]) { 3255726Sroot if (bp->b_flags & B_READ) 3265726Sroot return (HP_RHDR|HP_GO); 3275726Sroot else 3285726Sroot return (HP_WHDR|HP_GO); 3295726Sroot } 3305726Sroot return (0); 33121Sbill } 33221Sbill 3333102Swnj hpdtint(mi, mbsr) 3342978Swnj register struct mba_device *mi; 3353102Swnj int mbsr; 33621Sbill { 3372624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 3382383Swnj register struct buf *bp = mi->mi_tab.b_actf; 339*5858Swnj register int er1; 3402826Swnj int retry = 0; 34121Sbill 3423726Sroot #ifndef NOBADSECT 3433706Sroot if (bp->b_flags&B_BAD) { 3443706Sroot if (hpecc(mi, CONT)) 3453706Sroot return(MBD_RESTARTED); 3463706Sroot } 3473706Sroot #endif 3483102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 3493706Sroot #ifdef HPDEBUG 3503289Swnj if (hpdebug) { 3513706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 3523706Sroot 3533706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 3543706Sroot bp, bp->b_cylin, bp->b_blkno, 3553706Sroot hpaddr->hpas&0xff); 3563706Sroot printf("dc %x da %x\n",dc&0xffff, da&0xffff); 3573289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 3583289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 3593289Swnj printf("er1=%b er2=%b\n", 3603289Swnj hpaddr->hper1, HPER1_BITS, 3613289Swnj hpaddr->hper2, HPER2_BITS); 3623289Swnj DELAY(1000000); 3633289Swnj } 3643706Sroot #endif 365*5858Swnj er1 = hpaddr->hper1; 366*5858Swnj if (er1 & HPER1_HCRC) 367*5858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 368*5858Swnj if (er1&HPER1_WLE) { 3692925Swnj printf("hp%d: write locked\n", dkunit(bp)); 3702826Swnj bp->b_flags |= B_ERROR; 371*5858Swnj } else if ((er1&0xffff) == HPER1_FER && RP06 && 3725726Sroot hphdr[mi->mi_unit] == 0) { 3735726Sroot #ifndef NOBADSECT 3745726Sroot if (hpecc(mi, BSE)) 3755726Sroot return(MBD_RESTARTED); 3765726Sroot else 3775726Sroot #endif 3785726Sroot goto hard; 3792826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 3803102Swnj mbsr & MBSR_HARD || 381*5858Swnj er1 & HPER1_HARD || 3825726Sroot hphdr[mi->mi_unit] || 3835726Sroot (!ML11 && (hpaddr->hper2 & HPER2_HARD))) { 3843706Sroot hard: 3852925Swnj harderr(bp, "hp"); 3863271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 3873271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 3883706Sroot printf("er1=%b er2=%b", 3892826Swnj hpaddr->hper1, HPER1_BITS, 3902826Swnj hpaddr->hper2, HPER2_BITS); 3913706Sroot if (hpaddr->hpmr) 3923706Sroot printf(" mr=%o", hpaddr->hpmr&0xffff); 3933706Sroot if (hpaddr->hpmr2) 3943706Sroot printf(" mr2=%o", hpaddr->hpmr2&0xffff); 3953706Sroot printf("\n"); 3962826Swnj bp->b_flags |= B_ERROR; 3973143Swnj hprecal[mi->mi_unit] = 0; 3985726Sroot } else if ((hpaddr->hper2 & HPER2_BSE) && !ML11) { 3993726Sroot #ifndef NOBADSECT 4003706Sroot if (hpecc(mi, BSE)) 4013706Sroot return(MBD_RESTARTED); 4023706Sroot else 4033706Sroot #endif 4043706Sroot goto hard; 4055726Sroot } else if (RM80 && hpaddr->hper2&HPER2_SSE) { 4063988Sroot (void) hpecc(mi, SSE); 4072883Swnj return (MBD_RESTARTED); 408*5858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 4093706Sroot if (hpecc(mi, ECC)) 4102383Swnj return (MBD_RESTARTED); 4112826Swnj /* else done */ 4122826Swnj } else 4132826Swnj retry = 1; 4142826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4155726Sroot if (ML11) { 4165726Sroot if (mi->mi_tab.b_errcnt >= 16) 4175726Sroot goto hard; 4185726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 4192826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 4203706Sroot hprecal[mi->mi_unit] = 1; 4213706Sroot return(MBD_RESTARTED); 42221Sbill } 4232826Swnj if (retry) 4242826Swnj return (MBD_RETRY); 4252826Swnj } 4263706Sroot #ifdef HPDEBUG 4273289Swnj else 4283289Swnj if (hpdebug && hprecal[mi->mi_unit]) { 4293289Swnj printf("recal %d ", hprecal[mi->mi_unit]); 4303289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 4313289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 4323289Swnj printf("er1=%b er2=%b\n", 4333289Swnj hpaddr->hper1, HPER1_BITS, 4343289Swnj hpaddr->hper2, HPER2_BITS); 4353289Swnj } 4363706Sroot #endif 4373093Swnj switch (hprecal[mi->mi_unit]) { 4383093Swnj 4393093Swnj case 1: 4403093Swnj hpaddr->hpdc = bp->b_cylin; 4413093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 4423706Sroot hprecal[mi->mi_unit]++; 4433706Sroot return (MBD_RESTARTED); 4443093Swnj case 2: 4453093Swnj if (mi->mi_tab.b_errcnt < 16 || 4463289Swnj (bp->b_flags & B_READ) == 0) 4473093Swnj goto donerecal; 4483093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 4493093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 4503093Swnj hprecal[mi->mi_unit]++; 4513093Swnj return (MBD_RESTARTED); 4523093Swnj donerecal: 4533158Swnj case 3: 4542892Swnj hprecal[mi->mi_unit] = 0; 4552892Swnj return (MBD_RETRY); 4562892Swnj } 4575726Sroot hphdr[mi->mi_unit] = 0; 4582383Swnj bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff; 4593640Swnj if (mi->mi_tab.b_errcnt >= 16) { 4603093Swnj /* 4613093Swnj * This is fast and occurs rarely; we don't 4623093Swnj * bother with interrupts. 4633093Swnj */ 4642624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 4653093Swnj while (hpaddr->hpds & HPDS_PIP) 4662383Swnj ; 4672383Swnj mbclrattn(mi); 46821Sbill } 4695726Sroot if (!ML11) { 4705726Sroot hpaddr->hpof = HPOF_FMT22; 4715726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 4725726Sroot } 4732383Swnj return (MBD_DONE); 47421Sbill } 47521Sbill 47621Sbill hpread(dev) 4772624Swnj dev_t dev; 47821Sbill { 4792624Swnj register int unit = minor(dev) >> 3; 48021Sbill 4812624Swnj if (unit >= NHP) 4822624Swnj u.u_error = ENXIO; 4832624Swnj else 4842624Swnj physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys); 48521Sbill } 48621Sbill 48721Sbill hpwrite(dev) 4882624Swnj dev_t dev; 48921Sbill { 4902624Swnj register int unit = minor(dev) >> 3; 49121Sbill 4922624Swnj if (unit >= NHP) 4932624Swnj u.u_error = ENXIO; 4942624Swnj else 4952624Swnj physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys); 49621Sbill } 49721Sbill 4985726Sroot /*ARGSUSED*/ 4995726Sroot hpioctl(dev, cmd, addr, flag) 5005726Sroot dev_t dev; 5015726Sroot int cmd; 5025726Sroot caddr_t addr; 5035726Sroot int flag; 5045726Sroot { 5055726Sroot 5065726Sroot switch (cmd) { 5075726Sroot case DKIOCHDR: /* do header read/write */ 5085726Sroot hphdr[minor(dev)>>3] = 1; 5095726Sroot return; 5105726Sroot 5115726Sroot default: 5125726Sroot u.u_error = ENXIO; 5135726Sroot } 5145726Sroot } 5155726Sroot 5163706Sroot hpecc(mi, flag) 5172978Swnj register struct mba_device *mi; 5183706Sroot int flag; 51921Sbill { 5202383Swnj register struct mba_regs *mbp = mi->mi_mba; 5212624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 5222383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5233706Sroot register struct hpst *st = &hpst[mi->mi_type]; 5243706Sroot int npf, o; 5252383Swnj int bn, cn, tn, sn; 526914Sbill int bcr; 52721Sbill 528914Sbill bcr = mbp->mba_bcr & 0xffff; 529914Sbill if (bcr) 530914Sbill bcr |= 0xffff0000; /* sxt */ 5313726Sroot #ifndef NOBADSECT 5323706Sroot if (flag == CONT) 5333706Sroot npf = bp->b_error; 5343706Sroot else 5353706Sroot #endif 5363706Sroot npf = btop(bcr + bp->b_bcount); 537420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 538420Sbill bn = dkblock(bp); 539420Sbill cn = bp->b_cylin; 5403706Sroot sn = bn%(st->nspc) + npf; 5412383Swnj tn = sn/st->nsect; 5422383Swnj sn %= st->nsect; 5432383Swnj cn += tn/st->ntrak; 5442383Swnj tn %= st->ntrak; 5453706Sroot switch (flag) { 5463706Sroot case ECC: 5473706Sroot { 5483706Sroot register int i; 5493706Sroot caddr_t addr; 5503706Sroot struct pte mpte; 5513706Sroot int bit, byte, mask; 5523706Sroot 5533706Sroot npf--; /* because block in error is previous block */ 5543706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 5553706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 5563706Sroot mask = rp->hpec2&0xffff; 5573706Sroot i = (rp->hpec1&0xffff) - 1; /* -1 makes 0 origin */ 5583706Sroot bit = i&07; 5593706Sroot i = (i&~07)>>3; 5603706Sroot byte = i + o; 5613706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 5623706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 5633706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 5643706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 5653706Sroot byte++; 5663706Sroot i++; 5673706Sroot bit -= 8; 5683706Sroot } 5693706Sroot if (bcr == 0) 5703706Sroot return (0); 5713847Sroot npf++; 5723706Sroot break; 5733706Sroot } 5743706Sroot 5753706Sroot case SSE: 5763706Sroot rp->hpof |= HPOF_SSEI; 5773706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 5783706Sroot break; 5793706Sroot 5803726Sroot #ifndef NOBADSECT 5813706Sroot case BSE: 5823706Sroot #ifdef HPBDEBUG 5833706Sroot if (hpbdebug) 5843706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 5853706Sroot #endif 5863706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 5873706Sroot return(0); 5883706Sroot bp->b_flags |= B_BAD; 5893706Sroot bp->b_error = npf + 1; 5903706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 5913706Sroot cn = bn/st->nspc; 5923706Sroot sn = bn%st->nspc; 5933706Sroot tn = sn/st->nsect; 5943706Sroot sn %= st->nsect; 5953706Sroot mbp->mba_bcr = -512; 5963706Sroot #ifdef HPBDEBUG 5973706Sroot if (hpbdebug) 5983706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 5993706Sroot #endif 6003706Sroot break; 6013706Sroot 6023706Sroot case CONT: 6033706Sroot #ifdef HPBDEBUG 6043706Sroot if (hpbdebug) 6053706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 6063706Sroot #endif 6073706Sroot npf = bp->b_error; 6083706Sroot bp->b_flags &= ~B_BAD; 6093706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 6103706Sroot if ((mbp->mba_bcr & 0xffff) == 0) 6113706Sroot return(0); 6123706Sroot break; 6133706Sroot #endif 6143706Sroot } 6153706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 6163350Swnj if (rp->hpof&HPOF_SSEI) 6172883Swnj sn++; 618420Sbill rp->hpdc = cn; 619420Sbill rp->hpda = (tn<<8) + sn; 620420Sbill mbp->mba_sr = -1; 6213706Sroot mbp->mba_var = (int)ptob(npf) + o; 6223706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 6233706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 624420Sbill return (1); 62521Sbill } 6262362Swnj 6272362Swnj #define DBSIZE 20 6282362Swnj 6292362Swnj hpdump(dev) 6302362Swnj dev_t dev; 6312362Swnj { 6322978Swnj register struct mba_device *mi; 6332383Swnj register struct mba_regs *mba; 6342624Swnj struct hpdevice *hpaddr; 6352362Swnj char *start; 6362383Swnj int num, unit; 6372383Swnj register struct hpst *st; 6382362Swnj 6392362Swnj num = maxfree; 6402362Swnj start = 0; 6412362Swnj unit = minor(dev) >> 3; 6422827Swnj if (unit >= NHP) 6432827Swnj return (ENXIO); 6442383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 6452978Swnj mi = phys(hpinfo[unit],struct mba_device *); 6462827Swnj if (mi == 0 || mi->mi_alive == 0) 6472827Swnj return (ENXIO); 6482383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 6493102Swnj mba->mba_cr = MBCR_INIT; 6502624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 6513093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 6522624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 6532624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 6543093Swnj hpaddr->hpof = HPOF_FMT22; 6552362Swnj } 6562383Swnj st = &hpst[mi->mi_type]; 6572827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 6582827Swnj return (EINVAL); 6592362Swnj while (num > 0) { 6602383Swnj register struct pte *hpte = mba->mba_map; 6612362Swnj register int i; 6622383Swnj int blk, cn, sn, tn; 6632362Swnj daddr_t bn; 6642362Swnj 6652362Swnj blk = num > DBSIZE ? DBSIZE : num; 6662362Swnj bn = dumplo + btop(start); 6672383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 6682383Swnj sn = bn%st->nspc; 6692383Swnj tn = sn/st->nsect; 6702383Swnj sn = sn%st->nsect; 6712362Swnj hpaddr->hpdc = cn; 6722362Swnj hpaddr->hpda = (tn << 8) + sn; 6732362Swnj for (i = 0; i < blk; i++) 6742362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 6752383Swnj mba->mba_sr = -1; 6762383Swnj mba->mba_bcr = -(blk*NBPG); 6772383Swnj mba->mba_var = 0; 6782624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 6793093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 6802362Swnj ; 6813093Swnj if (hpaddr->hpds&HPDS_ERR) 6822827Swnj return (EIO); 6832362Swnj start += blk*NBPG; 6842362Swnj num -= blk; 6852362Swnj } 6862362Swnj return (0); 6872362Swnj } 6881565Sbill #endif 689