1*12836Ssam /* hp.c 4.76 83/05/30 */ 23706Sroot 33706Sroot #ifdef HPDEBUG 43289Swnj int hpdebug; 53706Sroot #endif 63706Sroot #ifdef HPBDEBUG 73706Sroot int hpbdebug; 83706Sroot #endif 921Sbill 101939Swnj #include "hp.h" 111565Sbill #if NHP > 0 1221Sbill /* 135726Sroot * HP disk driver for RP0x+RMxx+ML11 142827Swnj * 152827Swnj * TODO: 163706Sroot * check RM80 skip sector handling when ECC's occur later 173093Swnj * check offset recovery handling 183706Sroot * see if DCLR and/or RELEASE set attention status 193706Sroot * print bits of mr && mr2 symbolically 2021Sbill */ 219786Ssam #include "../machine/pte.h" 2221Sbill 2321Sbill #include "../h/param.h" 2421Sbill #include "../h/systm.h" 25305Sbill #include "../h/dk.h" 2621Sbill #include "../h/buf.h" 2721Sbill #include "../h/conf.h" 2821Sbill #include "../h/dir.h" 2921Sbill #include "../h/user.h" 3021Sbill #include "../h/map.h" 318468Sroot #include "../vax/mtpr.h" 32420Sbill #include "../h/vm.h" 332362Swnj #include "../h/cmap.h" 343706Sroot #include "../h/dkbad.h" 357635Ssam #include "../h/ioctl.h" 367738Sroot #include "../h/uio.h" 3721Sbill 388988Sroot #include "../vax/dkio.h" 398468Sroot #include "../vaxmba/mbareg.h" 408468Sroot #include "../vaxmba/mbavar.h" 418468Sroot #include "../vaxmba/hpreg.h" 4221Sbill 432383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 442383Swnj struct size { 4521Sbill daddr_t nblocks; 4621Sbill int cyloff; 4711212Ssam } rp06_sizes[8] = { 48886Sbill 15884, 0, /* A=cyl 0 thru 37 */ 49886Sbill 33440, 38, /* B=cyl 38 thru 117 */ 50886Sbill 340670, 0, /* C=cyl 0 thru 814 */ 5111212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 5211212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 5311212Ssam 219384, 290, /* F=cyl 290 thru 814 */ 5411212Ssam 291280, 118, /* G=cyl 118 thru 814 */ 5521Sbill 0, 0, 5611212Ssam }, rp05_sizes[8] = { 5711212Ssam 15884, 0, /* A=cyl 0 thru 37 */ 5811212Ssam 33440, 38, /* B=cyl 38 thru 117 */ 5911212Ssam 171798, 0, /* C=cyl 0 thru 410 */ 6011212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 6111212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 6211212Ssam 50512, 290, /* F=cyl 290 thru 410 */ 6311212Ssam 122408, 118, /* G=cyl 118 thru 410 */ 6421Sbill 0, 0, 6511212Ssam }, rm03_sizes[8] = { 66886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 6711212Ssam 33440, 100, /* B=cyl 100 thru 308 */ 68886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 6911212Ssam 15884, 309, /* D=cyl 309 thru 408 */ 7011212Ssam 55936, 409, /* E=cyl 409 thru 758 */ 7111212Ssam 10144, 759, /* F=cyl 759 thru 822 */ 7211212Ssam 82144, 309, /* G=cyl 309 thru 822 */ 7321Sbill 0, 0, 7411212Ssam }, rm05_sizes[8] = { 75886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 76886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 773271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 78886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 79886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 803729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 813729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 82886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 832383Swnj }, rm80_sizes[8] = { 842383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 852383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 862383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 8711212Ssam 15884, 115, /* D=cyl 115 thru 151 */ 8811212Ssam 55936, 152, /* E=cyl 152 thru 280 */ 8911212Ssam 120559, 281, /* F=cyl 281 thru 558 */ 9011212Ssam 192603, 115, /* G=cyl 115 thru 558 */ 912383Swnj 0, 0, 9211212Ssam }, rp07_sizes[8] = { 936927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 9411212Ssam 66880, 10, /* B=cyl 10 thru 51 */ 9511212Ssam 1008000, 0, /* C=cyl 0 thru 629 */ 9611212Ssam 15884, 235, /* D=cyl 235 thru 244 */ 9711212Ssam 307200, 245, /* E=cyl 245 thru 436 */ 9811212Ssam 308650, 437, /* F=cyl 437 thru 629 */ 9911212Ssam 631850, 235, /* G=cyl 235 thru 629 */ 10011212Ssam 291346, 52, /* H=cyl 52 thru 234 */ 10111212Ssam }, cdc9775_sizes[8] = { 10211212Ssam 15884, 0, /* A=cyl 0 thru 12 */ 10311212Ssam 66880, 13, /* B=cyl 13 thru 65 */ 10411212Ssam 1079040, 0, /* C=cyl 0 thru 842 */ 10511212Ssam 15884, 294, /* D=cyl 294 thru 306 */ 10611212Ssam 307200, 307, /* E=cyl 307 thru 546 */ 10711212Ssam 378784, 547, /* F=cyl 547 thru 842 */ 10811212Ssam 702624, 294, /* G=cyl 294 thru 842 */ 10911212Ssam 291346, 66, /* H=cyl 66 thru 293 */ 11011212Ssam }, cdc9730_sizes[8] = { 1116927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1126927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1136927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 11411212Ssam 15884, 155, /* D=cyl 155 thru 204 */ 11511212Ssam 55936, 205, /* E=cyl 205 thru 379 */ 11611212Ssam 141664, 380, /* F=cyl 380 thru 822 */ 11711212Ssam 213664, 155, /* G=cyl 155 thru 822 */ 1186927Ssam 0, 0, 11911212Ssam }, capricorn_sizes[8] = { 1206927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1216927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1226927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 12311212Ssam 15884, 668, /* D=cyl 668 thru 699 */ 12411212Ssam 55936, 700, /* E=cyl 700 thru 809 */ 12511212Ssam 109472, 810, /* F=cyl 810 thru 1023 */ 12611212Ssam 182176, 668, /* G=cyl 668 thru 1023 */ 1276927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 12811212Ssam }, eagle_sizes[8] = { 12910734Ssam 15884, 0, /* A=cyl 0 thru 16 */ 13011212Ssam 66880, 17, /* B=cyl 17 thru 86 */ 13111629Ssam 808320, 0, /* C=cyl 0 thru 841 */ 13211212Ssam 15884, 391, /* D=cyl 391 thru 407 */ 13311212Ssam 307200, 408, /* E=cyl 408 thru 727 */ 13411629Ssam 109296, 728, /* F=cyl 728 thru 841 */ 13511629Ssam 432816, 391, /* G=cyl 391 thru 841 */ 13611212Ssam 291346, 87, /* H=cyl 87 thru 390 */ 13711281Ssam }, cdc9300_sizes[8] = { 13811281Ssam 15884, 0, /* A=cyl 0 thru 26 */ 13911281Ssam 33440, 27, /* B=cyl 27 thru 81 */ 14011281Ssam 500384, 0, /* C=cyl 0 thru 822 */ 14111281Ssam 15884, 562, /* D=cyl 562 thru 588 */ 14211281Ssam 55936, 589, /* E=cyl 589 thru 680 */ 14311281Ssam 86240, 681, /* F=cyl 681 thru 822 */ 14411281Ssam 158592, 562, /* G=cyl 562 thru 822 */ 14511281Ssam 291346, 82, /* H=cyl 82 thru 561 */ 14621Sbill }; 1472383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 14821Sbill 1496927Ssam /* 1506927Ssam * Table for converting Massbus drive types into 1516927Ssam * indices into the partition tables. Slots are 1526927Ssam * left for those drives devined from other means 1536927Ssam * (e.g. SI, AMPEX, etc.). 1546927Ssam */ 1556927Ssam short hptypes[] = { 1566927Ssam #define HPDT_RM03 0 1576927Ssam MBDT_RM03, 1586927Ssam #define HPDT_RM05 1 1596927Ssam MBDT_RM05, 1606927Ssam #define HPDT_RP06 2 1616927Ssam MBDT_RP06, 1626927Ssam #define HPDT_RM80 3 1636927Ssam MBDT_RM80, 1646927Ssam #define HPDT_RP05 4 1656927Ssam MBDT_RP05, 1666927Ssam #define HPDT_RP07 5 1676927Ssam MBDT_RP07, 1686927Ssam #define HPDT_ML11A 6 1696927Ssam MBDT_ML11A, 1706927Ssam #define HPDT_ML11B 7 1716927Ssam MBDT_ML11B, 1726927Ssam #define HPDT_9775 8 1736927Ssam -1, 1746927Ssam #define HPDT_9730 9 1756927Ssam -1, 1766927Ssam #define HPDT_CAPRICORN 10 1776927Ssam -1, 1789175Ssam #define HPDT_EAGLE 11 1799175Ssam -1, 18011281Ssam #define HPDT_9300 12 18111281Ssam -1, 18211281Ssam #define HPDT_RM02 13 1839175Ssam MBDT_RM02, /* beware, actually capricorn or eagle */ 1846927Ssam 0 1856927Ssam }; 1862978Swnj struct mba_device *hpinfo[NHP]; 1872978Swnj int hpattach(),hpustart(),hpstart(),hpdtint(); 1882383Swnj struct mba_driver hpdriver = 1892978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1902978Swnj hptypes, "hp", 0, hpinfo }; 1912383Swnj 192*12836Ssam /* 193*12836Ssam * Beware, sdist and rdist are not well tuned 194*12836Ssam * for many of the drives listed in this table. 195*12836Ssam * Try patching things with something i/o intensive 196*12836Ssam * running and watch iostat. 197*12836Ssam */ 1982383Swnj struct hpst { 199*12836Ssam short nsect; /* # sectors/track */ 200*12836Ssam short ntrak; /* # tracks/cylinder */ 201*12836Ssam short nspc; /* # sector/cylinders */ 202*12836Ssam short ncyl; /* # cylinders */ 203*12836Ssam struct size *sizes; /* partition tables */ 204*12836Ssam short sdist; /* seek distance metric */ 205*12836Ssam short rdist; /* rotational distance metric */ 2062383Swnj } hpst[] = { 207*12836Ssam { 32, 5, 32*5, 823, rm03_sizes, 3, 4 }, /* RM03 */ 208*12836Ssam { 32, 19, 32*19, 823, rm05_sizes, 3, 4 }, /* RM05 */ 209*12836Ssam { 22, 19, 22*19, 815, rp06_sizes, 3, 4 }, /* RP06 */ 210*12836Ssam { 31, 14, 31*14, 559, rm80_sizes, 3, 4 }, /* RM80 */ 211*12836Ssam { 22, 19, 22*19, 411, rp05_sizes, 3, 4 }, /* RP05 */ 212*12836Ssam { 50, 32, 50*32, 630, rp07_sizes, 7, 8 }, /* RP07 */ 213*12836Ssam { 1, 1, 1, 1, 0, 0, 0 }, /* ML11A */ 214*12836Ssam { 1, 1, 1, 1, 0, 0, 0 }, /* ML11B */ 215*12836Ssam { 32, 40, 32*40, 843, cdc9775_sizes, 3, 4 }, /* 9775 */ 216*12836Ssam { 32, 10, 32*10, 823, cdc9730_sizes, 3, 4 }, /* 9730 */ 217*12836Ssam { 32, 16, 32*16, 1024, capricorn_sizes,7, 8 }, /* Capricorn */ 218*12836Ssam { 48, 20, 48*20, 842, eagle_sizes, 7, 8 }, /* EAGLE */ 219*12836Ssam { 32, 19, 32*19, 815, cdc9300_sizes, 3, 4 }, /* 9300 */ 2202383Swnj }; 2212383Swnj 2222624Swnj u_char hp_offset[16] = { 2233093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 2243093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 2253093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 2263093Swnj 0, 0, 0, 0, 22721Sbill }; 22821Sbill 2292624Swnj struct buf rhpbuf[NHP]; 2303706Sroot struct buf bhpbuf[NHP]; 2313706Sroot struct dkbad hpbad[NHP]; 23221Sbill 23310857Ssam struct hpsoftc { 23410857Ssam u_char sc_hpinit; /* drive initialized */ 23510857Ssam u_char sc_recal; /* recalibrate state */ 23610857Ssam u_char sc_hdr; /* next i/o includes header */ 23710857Ssam u_char sc_doseeks; /* perform explicit seeks */ 23810857Ssam daddr_t sc_mlsize; /* ML11 size */ 23910857Ssam } hpsoftc[NHP]; 24010857Ssam 24121Sbill #define b_cylin b_resid 24221Sbill 2435726Sroot /* #define ML11 0 to remove ML11 support */ 2445726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2455726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2465726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2475726Sroot 24811202Ssam #define MASKREG(reg) ((reg)&0xffff) 24911202Ssam 25021Sbill #ifdef INTRLVE 25121Sbill daddr_t dkblock(); 25221Sbill #endif 2532604Swnj 2542978Swnj /*ARGSUSED*/ 2552978Swnj hpattach(mi, slave) 25610734Ssam register struct mba_device *mi; 2572604Swnj { 25810734Ssam 25910734Ssam mi->mi_type = hpmaptype(mi); 26010734Ssam if (!ML11 && mi->mi_dk >= 0) { 26110734Ssam struct hpst *st = &hpst[mi->mi_type]; 26210734Ssam 26310734Ssam dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 26410734Ssam } 26510734Ssam } 26610734Ssam 26710734Ssam /* 26810734Ssam * Map apparent MASSBUS drive type into manufacturer 26910734Ssam * specific configuration. For SI controllers this is done 27010734Ssam * based on codes in the serial number register. For 27110734Ssam * EMULEX controllers, the track and sector attributes are 27210734Ssam * used when the drive type is an RM02 (not supported by DEC). 27310734Ssam */ 27410734Ssam hpmaptype(mi) 27510734Ssam register struct mba_device *mi; 27610734Ssam { 2776927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 27810734Ssam register int type = mi->mi_type; 2796927Ssam 2806927Ssam /* 28111281Ssam * Model-byte processing for SI controllers. 2826927Ssam * NB: Only deals with RM03 and RM05 emulations. 2836927Ssam */ 28410734Ssam if (type == HPDT_RM03 || type == HPDT_RM05) { 28510734Ssam int hpsn = hpaddr->hpsn; 2866927Ssam 2876927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 28810734Ssam return (type); 2896927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 2906927Ssam 2916927Ssam case SI9775D: 29211281Ssam printf("hp%d: 9775 (direct)\n", mi->mi_unit); 29310734Ssam type = HPDT_9775; 2946927Ssam break; 2956927Ssam 2966927Ssam case SI9730D: 29711281Ssam printf("hp%d: 9730 (direct)\n", mi->mi_unit); 29810734Ssam type = HPDT_9730; 2996927Ssam break; 3006927Ssam 3017035Swnj /* 30211281Ssam * Beware, since the only SI controller we 30311281Ssam * have has a 9300 instead of a 9766, we map the 30411281Ssam * drive type into the 9300. This means that 30511281Ssam * on a 9766 you lose the last 8 cylinders (argh). 3067035Swnj */ 3076927Ssam case SI9766: 30811281Ssam printf("hp%d: 9300\n", mi->mi_unit); 30911281Ssam type = HPDT_9300; 3106927Ssam break; 3116927Ssam 3126927Ssam case SI9762: 3136927Ssam printf("hp%d: 9762\n", mi->mi_unit); 31410734Ssam type = HPDT_RM03; 3156927Ssam break; 31611281Ssam 31711281Ssam case SICAPD: 31811281Ssam printf("hp%d: capricorn\n", mi->mi_unit); 31911281Ssam type = HPDT_CAPRICORN; 32011281Ssam break; 32111281Ssam 32211281Ssam case SI9751D: 32311281Ssam printf("hp%d: eagle\n", mi->mi_unit); 32411281Ssam type = HPDT_EAGLE; 32511281Ssam break; 3266927Ssam } 32710734Ssam return (type); 32810734Ssam } 3296927Ssam 3306927Ssam /* 33110734Ssam * EMULEX SC750 or SC780. Poke the holding register. 3326927Ssam */ 33310734Ssam if (type == HPDT_RM02) { 33410734Ssam int ntracks, nsectors; 33510734Ssam 33611315Ssam hpaddr->hpof = HPOF_FMT22; 33711315Ssam mbclrattn(mi); 3386927Ssam hpaddr->hpcs1 = HP_NOP; 3396927Ssam hpaddr->hphr = HPHR_MAXTRAK; 34011202Ssam ntracks = MASKREG(hpaddr->hphr) + 1; 34110055Ssam if (ntracks == 16) { 3426927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 34310734Ssam type = HPDT_CAPRICORN; 34410734Ssam goto done; 34510734Ssam } 34610734Ssam hpaddr->hpcs1 = HP_NOP; 34710734Ssam hpaddr->hphr = HPHR_MAXSECT; 34811202Ssam nsectors = MASKREG(hpaddr->hphr) + 1; 34911315Ssam if (ntracks == 20 && nsectors == 48) { 35010734Ssam type = HPDT_EAGLE; 35111212Ssam printf("hp%d: eagle\n", mi->mi_unit); 35211315Ssam goto done; 35310734Ssam } 35411315Ssam printf("hp%d: ntracks %d, nsectors %d: unknown device\n", 35511315Ssam ntracks, nsectors); 35610734Ssam done: 3576927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 35811315Ssam mbclrattn(mi); /* conservative */ 35910734Ssam return (type); 36010734Ssam } 3616927Ssam 36210734Ssam /* 36310734Ssam * Map all ML11's to the same type. Also calculate 36410734Ssam * transfer rates based on device characteristics. 36510734Ssam */ 36610734Ssam if (type == HPDT_ML11A || type == HPDT_ML11B) { 36710857Ssam register struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 36810857Ssam register int trt; 3692604Swnj 37010857Ssam sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 3715726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 37210857Ssam sc->sc_mlsize >>= 2; 3735726Sroot if (mi->mi_dk >= 0) { 3745726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3755726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 3765726Sroot } 37710734Ssam type = HPDT_ML11A; 3786927Ssam } 37910734Ssam return (type); 3802604Swnj } 3812604Swnj 3828579Sroot hpopen(dev) 3838579Sroot dev_t dev; 3848579Sroot { 3858579Sroot register int unit = minor(dev) >> 3; 3868579Sroot register struct mba_device *mi; 3878579Sroot 3888579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 3898579Sroot return (ENXIO); 3908579Sroot return (0); 3918579Sroot } 3928579Sroot 39321Sbill hpstrategy(bp) 3942383Swnj register struct buf *bp; 39521Sbill { 3962978Swnj register struct mba_device *mi; 3972383Swnj register struct hpst *st; 3982383Swnj register int unit; 39921Sbill long sz, bn; 4002383Swnj int xunit = minor(bp->b_dev) & 07; 4015432Sroot int s; 40221Sbill 40321Sbill sz = bp->b_bcount; 40421Sbill sz = (sz+511) >> 9; 40521Sbill unit = dkunit(bp); 4062383Swnj if (unit >= NHP) 4072383Swnj goto bad; 4082383Swnj mi = hpinfo[unit]; 4092395Swnj if (mi == 0 || mi->mi_alive == 0) 4102383Swnj goto bad; 4112383Swnj st = &hpst[mi->mi_type]; 4125726Sroot if (ML11) { 41310857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 41410857Ssam 4155726Sroot if (bp->b_blkno < 0 || 41610857Ssam dkblock(bp)+sz > sc->sc_mlsize) 4175726Sroot goto bad; 4185726Sroot bp->b_cylin = 0; 4195726Sroot } else { 4205726Sroot if (bp->b_blkno < 0 || 4215726Sroot (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 4225726Sroot goto bad; 4235726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 4245726Sroot } 4255432Sroot s = spl5(); 4262383Swnj disksort(&mi->mi_tab, bp); 4272383Swnj if (mi->mi_tab.b_active == 0) 4282383Swnj mbustart(mi); 4295432Sroot splx(s); 4302383Swnj return; 4312383Swnj 4322383Swnj bad: 4332383Swnj bp->b_flags |= B_ERROR; 4342383Swnj iodone(bp); 4352383Swnj return; 43621Sbill } 43721Sbill 4382383Swnj hpustart(mi) 4392978Swnj register struct mba_device *mi; 44021Sbill { 4412624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4422383Swnj register struct buf *bp = mi->mi_tab.b_actf; 44311315Ssam register struct hpst *st; 44410857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 44521Sbill daddr_t bn; 4463102Swnj int sn, dist; 44721Sbill 44811315Ssam st = &hpst[mi->mi_type]; 4493706Sroot hpaddr->hpcs1 = 0; 4502624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4512383Swnj return (MBU_BUSY); 45210857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 4533706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4543706Sroot 45510857Ssam sc->sc_hpinit = 1; 4562624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4573140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4583140Swnj printf("DCLR attn\n"); 4592624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4605726Sroot if (!ML11) 4615726Sroot hpaddr->hpof = HPOF_FMT22; 4623140Swnj mbclrattn(mi); 4635726Sroot if (!ML11) { 4645726Sroot bbp->b_flags = B_READ|B_BUSY; 4655726Sroot bbp->b_dev = bp->b_dev; 4665726Sroot bbp->b_bcount = 512; 4675726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 4685726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 4695726Sroot bbp->b_cylin = st->ncyl - 1; 4705726Sroot mi->mi_tab.b_actf = bbp; 4715726Sroot bbp->av_forw = bp; 4725726Sroot bp = bbp; 4735726Sroot } 47421Sbill } 4752604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 4762383Swnj return (MBU_DODATA); 4775726Sroot if (ML11) 4785726Sroot return (MBU_DODATA); 4793093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 4802383Swnj return (MBU_DODATA); 4812395Swnj bn = dkblock(bp); 4822395Swnj sn = bn%st->nspc; 483*12836Ssam sn = (sn + st->nsect - st->sdist) % st->nsect; 48411202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 48510908Ssam if (sc->sc_doseeks) 4862383Swnj return (MBU_DODATA); 48711202Ssam dist = (MASKREG(hpaddr->hpla) >> 6) - st->nsect + 1; 4882383Swnj if (dist < 0) 4892383Swnj dist += st->nsect; 490*12836Ssam if (dist > st->nsect - st->rdist) 4912383Swnj return (MBU_DODATA); 4922614Swnj } else 4932614Swnj hpaddr->hpdc = bp->b_cylin; 49410908Ssam if (sc->sc_doseeks) 4952624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 496305Sbill else { 497305Sbill hpaddr->hpda = sn; 4982624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 499305Sbill } 5002383Swnj return (MBU_STARTED); 50121Sbill } 50221Sbill 5032383Swnj hpstart(mi) 5042978Swnj register struct mba_device *mi; 50521Sbill { 5062624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5072383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5082383Swnj register struct hpst *st = &hpst[mi->mi_type]; 50910857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 51021Sbill daddr_t bn; 5112383Swnj int sn, tn; 51221Sbill 51321Sbill bn = dkblock(bp); 5145726Sroot if (ML11) 5155726Sroot hpaddr->hpda = bn; 5165726Sroot else { 5175726Sroot sn = bn%st->nspc; 5185726Sroot tn = sn/st->nsect; 5195726Sroot sn %= st->nsect; 5205726Sroot hpaddr->hpdc = bp->b_cylin; 5215726Sroot hpaddr->hpda = (tn << 8) + sn; 5225726Sroot } 52310857Ssam if (sc->sc_hdr) { 5245726Sroot if (bp->b_flags & B_READ) 5255726Sroot return (HP_RHDR|HP_GO); 5265726Sroot else 5275726Sroot return (HP_WHDR|HP_GO); 5285726Sroot } 5295726Sroot return (0); 53021Sbill } 53121Sbill 5323102Swnj hpdtint(mi, mbsr) 5332978Swnj register struct mba_device *mi; 5343102Swnj int mbsr; 53521Sbill { 5362624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5372383Swnj register struct buf *bp = mi->mi_tab.b_actf; 53811315Ssam register struct hpst *st; 5395893Swnj register int er1, er2; 54010857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 5412826Swnj int retry = 0; 54221Sbill 54311315Ssam st = &hpst[mi->mi_type]; 54411315Ssam if (bp->b_flags&B_BAD && hpecc(mi, CONT)) 54511315Ssam return (MBD_RESTARTED); 5463102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 5473706Sroot #ifdef HPDEBUG 5483289Swnj if (hpdebug) { 5493706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5503706Sroot 5513706Sroot printf("hperr: bp %x cyl %d blk %d as %o ", 5523706Sroot bp, bp->b_cylin, bp->b_blkno, 5533706Sroot hpaddr->hpas&0xff); 55411202Ssam printf("dc %x da %x\n",MASKREG(dc), MASKREG(da)); 5553289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 5563289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 5573289Swnj printf("er1=%b er2=%b\n", 5583289Swnj hpaddr->hper1, HPER1_BITS, 5593289Swnj hpaddr->hper2, HPER2_BITS); 5603289Swnj DELAY(1000000); 5613289Swnj } 5623706Sroot #endif 5635858Swnj er1 = hpaddr->hper1; 5645893Swnj er2 = hpaddr->hper2; 5655893Swnj if (er1 & HPER1_HCRC) { 5665858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 5675893Swnj er2 &= ~HPER2_BSE; 5685893Swnj } 5695858Swnj if (er1&HPER1_WLE) { 5702925Swnj printf("hp%d: write locked\n", dkunit(bp)); 5712826Swnj bp->b_flags |= B_ERROR; 57211202Ssam } else if (MASKREG(er1) == HPER1_FER && RP06 && !sc->sc_hdr) { 5735726Sroot if (hpecc(mi, BSE)) 57411202Ssam return (MBD_RESTARTED); 57511202Ssam goto hard; 5762826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 5773102Swnj mbsr & MBSR_HARD || 5785858Swnj er1 & HPER1_HARD || 57910857Ssam sc->sc_hdr || 5805893Swnj (!ML11 && (er2 & HPER2_HARD))) { 58110886Shelge /* 58210886Shelge * If HCRC the header is screwed up and the sector 58311202Ssam * might be in the bad sector table, better check.. 58411202Ssam * 58510886Shelge * Note: If the header is screwed up on a skip sector 58610886Shelge * track, then the appropriate replacement sector 58711202Ssam * cannot be found. 58810886Shelge */ 58911202Ssam if (er1&HPER1_HCRC && !ML11 && hpecc(mi, BSE)) 59011202Ssam return (MBD_RESTARTED); 5913706Sroot hard: 59210622Shelge if (ML11) 59311202Ssam bp->b_blkno = MASKREG(hpaddr->hpda); 59410622Shelge else 59511202Ssam bp->b_blkno = MASKREG(hpaddr->hpdc) * st->nspc + 59611202Ssam (MASKREG(hpaddr->hpda) >> 8) * st->nsect + 59711202Ssam (hpaddr->hpda&0x1f); 5982925Swnj harderr(bp, "hp"); 5993271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6003271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6013706Sroot printf("er1=%b er2=%b", 6022826Swnj hpaddr->hper1, HPER1_BITS, 6032826Swnj hpaddr->hper2, HPER2_BITS); 6043706Sroot if (hpaddr->hpmr) 60511202Ssam printf(" mr=%o", MASKREG(hpaddr->hpmr)); 6063706Sroot if (hpaddr->hpmr2) 60711202Ssam printf(" mr2=%o", MASKREG(hpaddr->hpmr2)); 6083706Sroot printf("\n"); 6092826Swnj bp->b_flags |= B_ERROR; 61010622Shelge retry = 0; 61110857Ssam sc->sc_recal = 0; 6125893Swnj } else if ((er2 & HPER2_BSE) && !ML11) { 6133706Sroot if (hpecc(mi, BSE)) 61411202Ssam return (MBD_RESTARTED); 61511315Ssam goto hard; 6165893Swnj } else if (RM80 && er2&HPER2_SSE) { 6173988Sroot (void) hpecc(mi, SSE); 6182883Swnj return (MBD_RESTARTED); 6195858Swnj } else if ((er1&(HPER1_DCK|HPER1_ECH))==HPER1_DCK) { 6203706Sroot if (hpecc(mi, ECC)) 6212383Swnj return (MBD_RESTARTED); 6222826Swnj /* else done */ 6232826Swnj } else 6242826Swnj retry = 1; 6252826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 6265726Sroot if (ML11) { 6275726Sroot if (mi->mi_tab.b_errcnt >= 16) 6285726Sroot goto hard; 6295726Sroot } else if ((mi->mi_tab.b_errcnt&07) == 4) { 6302826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 63110857Ssam sc->sc_recal = 1; 63211202Ssam return (MBD_RESTARTED); 63321Sbill } 6342826Swnj if (retry) 6352826Swnj return (MBD_RETRY); 6362826Swnj } 6373706Sroot #ifdef HPDEBUG 6383289Swnj else 63910857Ssam if (hpdebug && sc->sc_recal) { 64010857Ssam printf("recal %d ", sc->sc_recal); 6413289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 6423289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6433289Swnj printf("er1=%b er2=%b\n", 6443289Swnj hpaddr->hper1, HPER1_BITS, 6453289Swnj hpaddr->hper2, HPER2_BITS); 6463289Swnj } 6473706Sroot #endif 64810857Ssam switch (sc->sc_recal) { 6493093Swnj 6503093Swnj case 1: 6513093Swnj hpaddr->hpdc = bp->b_cylin; 6523093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 65310857Ssam sc->sc_recal++; 6543706Sroot return (MBD_RESTARTED); 6553093Swnj case 2: 6563093Swnj if (mi->mi_tab.b_errcnt < 16 || 6573289Swnj (bp->b_flags & B_READ) == 0) 6583093Swnj goto donerecal; 6593093Swnj hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 6603093Swnj hpaddr->hpcs1 = HP_OFFSET|HP_GO; 66110857Ssam sc->sc_recal++; 6623093Swnj return (MBD_RESTARTED); 6633093Swnj donerecal: 6643158Swnj case 3: 66510857Ssam sc->sc_recal = 0; 6662892Swnj return (MBD_RETRY); 6672892Swnj } 66810857Ssam sc->sc_hdr = 0; 66911202Ssam bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr); 6703640Swnj if (mi->mi_tab.b_errcnt >= 16) { 6713093Swnj /* 6723093Swnj * This is fast and occurs rarely; we don't 6733093Swnj * bother with interrupts. 6743093Swnj */ 6752624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 6763093Swnj while (hpaddr->hpds & HPDS_PIP) 6772383Swnj ; 6782383Swnj mbclrattn(mi); 67921Sbill } 6805726Sroot if (!ML11) { 6815726Sroot hpaddr->hpof = HPOF_FMT22; 6825726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 6835726Sroot } 6842383Swnj return (MBD_DONE); 68521Sbill } 68621Sbill 6877738Sroot hpread(dev, uio) 6882624Swnj dev_t dev; 6897738Sroot struct uio *uio; 69021Sbill { 6912624Swnj register int unit = minor(dev) >> 3; 69221Sbill 6932624Swnj if (unit >= NHP) 6948156Sroot return (ENXIO); 6958156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 69621Sbill } 69721Sbill 6987831Sroot hpwrite(dev, uio) 6992624Swnj dev_t dev; 7007831Sroot struct uio *uio; 70121Sbill { 7022624Swnj register int unit = minor(dev) >> 3; 70321Sbill 7042624Swnj if (unit >= NHP) 7058156Sroot return (ENXIO); 7068156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 70721Sbill } 70821Sbill 7095726Sroot /*ARGSUSED*/ 7107635Ssam hpioctl(dev, cmd, data, flag) 7115726Sroot dev_t dev; 7125726Sroot int cmd; 7137635Ssam caddr_t data; 7145726Sroot int flag; 7155726Sroot { 7165726Sroot 7175726Sroot switch (cmd) { 7187635Ssam 7195726Sroot case DKIOCHDR: /* do header read/write */ 72010857Ssam hpsoftc[minor(dev) >> 3].sc_hdr = 1; 7218579Sroot return (0); 7225726Sroot 7235726Sroot default: 7248579Sroot return (ENXIO); 7255726Sroot } 7265726Sroot } 7275726Sroot 7283706Sroot hpecc(mi, flag) 7292978Swnj register struct mba_device *mi; 7303706Sroot int flag; 73121Sbill { 7322383Swnj register struct mba_regs *mbp = mi->mi_mba; 7332624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 7342383Swnj register struct buf *bp = mi->mi_tab.b_actf; 7353706Sroot register struct hpst *st = &hpst[mi->mi_type]; 7363706Sroot int npf, o; 7372383Swnj int bn, cn, tn, sn; 738914Sbill int bcr; 73921Sbill 74011202Ssam bcr = MASKREG(mbp->mba_bcr); 741914Sbill if (bcr) 742914Sbill bcr |= 0xffff0000; /* sxt */ 7433706Sroot if (flag == CONT) 7443706Sroot npf = bp->b_error; 7453706Sroot else 7463706Sroot npf = btop(bcr + bp->b_bcount); 747420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 748420Sbill bn = dkblock(bp); 749420Sbill cn = bp->b_cylin; 7503706Sroot sn = bn%(st->nspc) + npf; 7512383Swnj tn = sn/st->nsect; 7522383Swnj sn %= st->nsect; 7532383Swnj cn += tn/st->ntrak; 7542383Swnj tn %= st->ntrak; 7553706Sroot switch (flag) { 75610856Ssam case ECC: { 7573706Sroot register int i; 7583706Sroot caddr_t addr; 7593706Sroot struct pte mpte; 7603706Sroot int bit, byte, mask; 7613706Sroot 7623706Sroot npf--; /* because block in error is previous block */ 7633706Sroot printf("hp%d%c: soft ecc sn%d\n", dkunit(bp), 7643706Sroot 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 76511202Ssam mask = MASKREG(rp->hpec2); 76611202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 7673706Sroot bit = i&07; 7683706Sroot i = (i&~07)>>3; 7693706Sroot byte = i + o; 7703706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 7713706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 7723706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 7733706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 7743706Sroot byte++; 7753706Sroot i++; 7763706Sroot bit -= 8; 7773706Sroot } 7783706Sroot if (bcr == 0) 7793706Sroot return (0); 7803847Sroot npf++; 7813706Sroot break; 7823706Sroot } 7833706Sroot 7843706Sroot case SSE: 7853706Sroot rp->hpof |= HPOF_SSEI; 7863706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 7873706Sroot break; 7883706Sroot 7893706Sroot case BSE: 7903706Sroot #ifdef HPBDEBUG 7913706Sroot if (hpbdebug) 7923706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 7933706Sroot #endif 79411202Ssam if (rp->hpof&HPOF_SSEI) 79511202Ssam sn++; 7963706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 79711202Ssam return (0); 7983706Sroot bp->b_flags |= B_BAD; 7993706Sroot bp->b_error = npf + 1; 8003706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 8013706Sroot cn = bn/st->nspc; 8023706Sroot sn = bn%st->nspc; 8033706Sroot tn = sn/st->nsect; 8043706Sroot sn %= st->nsect; 8053706Sroot mbp->mba_bcr = -512; 80610886Shelge rp->hpof &= ~HPOF_SSEI; 8073706Sroot #ifdef HPBDEBUG 8083706Sroot if (hpbdebug) 8093706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 8103706Sroot #endif 8113706Sroot break; 8123706Sroot 8133706Sroot case CONT: 8143706Sroot #ifdef HPBDEBUG 8153706Sroot if (hpbdebug) 8163706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 8173706Sroot #endif 8183706Sroot npf = bp->b_error; 8193706Sroot bp->b_flags &= ~B_BAD; 8203706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 82111202Ssam if (MASKREG(mbp->mba_bcr) == 0) 82211202Ssam return (0); 8233706Sroot break; 8243706Sroot } 8253706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 8263350Swnj if (rp->hpof&HPOF_SSEI) 8272883Swnj sn++; 828420Sbill rp->hpdc = cn; 829420Sbill rp->hpda = (tn<<8) + sn; 830420Sbill mbp->mba_sr = -1; 8313706Sroot mbp->mba_var = (int)ptob(npf) + o; 8323706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 8333706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 834420Sbill return (1); 83521Sbill } 8362362Swnj 8372362Swnj #define DBSIZE 20 8382362Swnj 8392362Swnj hpdump(dev) 8402362Swnj dev_t dev; 8412362Swnj { 8422978Swnj register struct mba_device *mi; 8432383Swnj register struct mba_regs *mba; 8442624Swnj struct hpdevice *hpaddr; 8452362Swnj char *start; 8462383Swnj int num, unit; 8472383Swnj register struct hpst *st; 8482362Swnj 8492362Swnj num = maxfree; 8502362Swnj start = 0; 8512362Swnj unit = minor(dev) >> 3; 8522827Swnj if (unit >= NHP) 8532827Swnj return (ENXIO); 8542383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 8552978Swnj mi = phys(hpinfo[unit],struct mba_device *); 8562827Swnj if (mi == 0 || mi->mi_alive == 0) 8572827Swnj return (ENXIO); 8582383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 8593102Swnj mba->mba_cr = MBCR_INIT; 8602624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 8613093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 8622624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 8632624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 8643093Swnj hpaddr->hpof = HPOF_FMT22; 8652362Swnj } 8662383Swnj st = &hpst[mi->mi_type]; 8672827Swnj if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) 8682827Swnj return (EINVAL); 8692362Swnj while (num > 0) { 8702383Swnj register struct pte *hpte = mba->mba_map; 8712362Swnj register int i; 8722383Swnj int blk, cn, sn, tn; 8732362Swnj daddr_t bn; 8742362Swnj 8752362Swnj blk = num > DBSIZE ? DBSIZE : num; 8762362Swnj bn = dumplo + btop(start); 8772383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 8782383Swnj sn = bn%st->nspc; 8792383Swnj tn = sn/st->nsect; 8802383Swnj sn = sn%st->nsect; 8812362Swnj hpaddr->hpdc = cn; 8822362Swnj hpaddr->hpda = (tn << 8) + sn; 8832362Swnj for (i = 0; i < blk; i++) 8842362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 8852383Swnj mba->mba_sr = -1; 8862383Swnj mba->mba_bcr = -(blk*NBPG); 8872383Swnj mba->mba_var = 0; 8882624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 8893093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 8902362Swnj ; 8913093Swnj if (hpaddr->hpds&HPDS_ERR) 8922827Swnj return (EIO); 8932362Swnj start += blk*NBPG; 8942362Swnj num -= blk; 8952362Swnj } 8962362Swnj return (0); 8972362Swnj } 89812506Ssam 89912506Ssam hpsize(dev) 90012506Ssam dev_t dev; 90112506Ssam { 90212506Ssam int unit = minor(dev) >> 3; 90312506Ssam struct mba_device *mi; 90412506Ssam struct hpst *st; 90512506Ssam 90612506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 90712506Ssam return (-1); 90812506Ssam st = &hpst[mi->mi_type]; 90912506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 91012506Ssam } 9111565Sbill #endif 912