123308Smckusick /* 223308Smckusick * Copyright (c) 1982 Regents of the University of California. 323308Smckusick * All rights reserved. The Berkeley software License Agreement 423308Smckusick * specifies the terms and conditions for redistribution. 523308Smckusick * 6*24738Sbloom * @(#)hp.c 6.11 (Berkeley) 09/14/85 723308Smckusick */ 83706Sroot 93706Sroot #ifdef HPDEBUG 103289Swnj int hpdebug; 113706Sroot #endif 123706Sroot #ifdef HPBDEBUG 133706Sroot int hpbdebug; 143706Sroot #endif 1521Sbill 161939Swnj #include "hp.h" 171565Sbill #if NHP > 0 1821Sbill /* 195726Sroot * HP disk driver for RP0x+RMxx+ML11 202827Swnj * 212827Swnj * TODO: 223706Sroot * check RM80 skip sector handling when ECC's occur later 233093Swnj * check offset recovery handling 243706Sroot * see if DCLR and/or RELEASE set attention status 253706Sroot * print bits of mr && mr2 symbolically 2621Sbill */ 279786Ssam #include "../machine/pte.h" 2821Sbill 2917120Sbloom #include "param.h" 3017120Sbloom #include "systm.h" 3117120Sbloom #include "dk.h" 3217120Sbloom #include "buf.h" 3317120Sbloom #include "conf.h" 3417120Sbloom #include "dir.h" 3517120Sbloom #include "user.h" 3617120Sbloom #include "map.h" 378468Sroot #include "../vax/mtpr.h" 3817120Sbloom #include "vm.h" 3917120Sbloom #include "cmap.h" 4017120Sbloom #include "dkbad.h" 4117120Sbloom #include "ioctl.h" 4217120Sbloom #include "uio.h" 4318411Skarels #include "syslog.h" 4421Sbill 458988Sroot #include "../vax/dkio.h" 4617120Sbloom #include "mbareg.h" 4717120Sbloom #include "mbavar.h" 4817120Sbloom #include "hpreg.h" 4921Sbill 502383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 512383Swnj struct size { 5221Sbill daddr_t nblocks; 5321Sbill int cyloff; 5411212Ssam } rp06_sizes[8] = { 55886Sbill 15884, 0, /* A=cyl 0 thru 37 */ 56886Sbill 33440, 38, /* B=cyl 38 thru 117 */ 57886Sbill 340670, 0, /* C=cyl 0 thru 814 */ 5811212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 5911212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 6011212Ssam 219384, 290, /* F=cyl 290 thru 814 */ 6111212Ssam 291280, 118, /* G=cyl 118 thru 814 */ 6221Sbill 0, 0, 6311212Ssam }, rp05_sizes[8] = { 6411212Ssam 15884, 0, /* A=cyl 0 thru 37 */ 6511212Ssam 33440, 38, /* B=cyl 38 thru 117 */ 6611212Ssam 171798, 0, /* C=cyl 0 thru 410 */ 6711212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 6811212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 6911212Ssam 50512, 290, /* F=cyl 290 thru 410 */ 7011212Ssam 122408, 118, /* G=cyl 118 thru 410 */ 7121Sbill 0, 0, 7211212Ssam }, rm03_sizes[8] = { 73886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 7411212Ssam 33440, 100, /* B=cyl 100 thru 308 */ 75886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 7611212Ssam 15884, 309, /* D=cyl 309 thru 408 */ 7711212Ssam 55936, 409, /* E=cyl 409 thru 758 */ 7811212Ssam 10144, 759, /* F=cyl 759 thru 822 */ 7911212Ssam 82144, 309, /* G=cyl 309 thru 822 */ 8021Sbill 0, 0, 8111212Ssam }, rm05_sizes[8] = { 82886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 83886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 843271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 85886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 86886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 873729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 883729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 89886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 902383Swnj }, rm80_sizes[8] = { 912383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 922383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 932383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 9411212Ssam 15884, 115, /* D=cyl 115 thru 151 */ 9511212Ssam 55936, 152, /* E=cyl 152 thru 280 */ 9611212Ssam 120559, 281, /* F=cyl 281 thru 558 */ 9711212Ssam 192603, 115, /* G=cyl 115 thru 558 */ 982383Swnj 0, 0, 9911212Ssam }, rp07_sizes[8] = { 1006927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 10111212Ssam 66880, 10, /* B=cyl 10 thru 51 */ 10211212Ssam 1008000, 0, /* C=cyl 0 thru 629 */ 10311212Ssam 15884, 235, /* D=cyl 235 thru 244 */ 10411212Ssam 307200, 245, /* E=cyl 245 thru 436 */ 10511212Ssam 308650, 437, /* F=cyl 437 thru 629 */ 10611212Ssam 631850, 235, /* G=cyl 235 thru 629 */ 10711212Ssam 291346, 52, /* H=cyl 52 thru 234 */ 10811212Ssam }, cdc9775_sizes[8] = { 10911212Ssam 15884, 0, /* A=cyl 0 thru 12 */ 11011212Ssam 66880, 13, /* B=cyl 13 thru 65 */ 11115101Skarels 1077760, 0, /* C=cyl 0 thru 841 */ 11211212Ssam 15884, 294, /* D=cyl 294 thru 306 */ 11311212Ssam 307200, 307, /* E=cyl 307 thru 546 */ 11415101Skarels 377440, 547, /* F=cyl 547 thru 841 */ 11515101Skarels 701280, 294, /* G=cyl 294 thru 841 */ 11611212Ssam 291346, 66, /* H=cyl 66 thru 293 */ 11711212Ssam }, cdc9730_sizes[8] = { 1186927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1196927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1206927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 12111212Ssam 15884, 155, /* D=cyl 155 thru 204 */ 12211212Ssam 55936, 205, /* E=cyl 205 thru 379 */ 12311212Ssam 141664, 380, /* F=cyl 380 thru 822 */ 12411212Ssam 213664, 155, /* G=cyl 155 thru 822 */ 1256927Ssam 0, 0, 12611212Ssam }, capricorn_sizes[8] = { 1276927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1286927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1296927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 13011212Ssam 15884, 668, /* D=cyl 668 thru 699 */ 13111212Ssam 55936, 700, /* E=cyl 700 thru 809 */ 13211212Ssam 109472, 810, /* F=cyl 810 thru 1023 */ 13311212Ssam 182176, 668, /* G=cyl 668 thru 1023 */ 1346927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 13511212Ssam }, eagle_sizes[8] = { 13610734Ssam 15884, 0, /* A=cyl 0 thru 16 */ 13711212Ssam 66880, 17, /* B=cyl 17 thru 86 */ 13811629Ssam 808320, 0, /* C=cyl 0 thru 841 */ 13911212Ssam 15884, 391, /* D=cyl 391 thru 407 */ 14011212Ssam 307200, 408, /* E=cyl 408 thru 727 */ 14111629Ssam 109296, 728, /* F=cyl 728 thru 841 */ 14211629Ssam 432816, 391, /* G=cyl 391 thru 841 */ 14311212Ssam 291346, 87, /* H=cyl 87 thru 390 */ 14413202Sroot }, ampex_sizes[8] = { 14511281Ssam 15884, 0, /* A=cyl 0 thru 26 */ 14611281Ssam 33440, 27, /* B=cyl 27 thru 81 */ 14713184Shelge 495520, 0, /* C=cyl 0 thru 814 */ 14811281Ssam 15884, 562, /* D=cyl 562 thru 588 */ 14911281Ssam 55936, 589, /* E=cyl 589 thru 680 */ 15013184Shelge 81312, 681, /* F=cyl 681 thru 814 */ 15113184Shelge 153664, 562, /* G=cyl 562 thru 814 */ 15211281Ssam 291346, 82, /* H=cyl 82 thru 561 */ 15321Sbill }; 1542383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 15521Sbill 1566927Ssam /* 1576927Ssam * Table for converting Massbus drive types into 1586927Ssam * indices into the partition tables. Slots are 1596927Ssam * left for those drives devined from other means 1606927Ssam * (e.g. SI, AMPEX, etc.). 1616927Ssam */ 1626927Ssam short hptypes[] = { 1636927Ssam #define HPDT_RM03 0 1646927Ssam MBDT_RM03, 1656927Ssam #define HPDT_RM05 1 1666927Ssam MBDT_RM05, 1676927Ssam #define HPDT_RP06 2 1686927Ssam MBDT_RP06, 1696927Ssam #define HPDT_RM80 3 1706927Ssam MBDT_RM80, 17113157Ssam #define HPDT_RP04 4 17213157Ssam MBDT_RP04, 17313157Ssam #define HPDT_RP05 5 1746927Ssam MBDT_RP05, 17513157Ssam #define HPDT_RP07 6 1766927Ssam MBDT_RP07, 17713157Ssam #define HPDT_ML11A 7 1786927Ssam MBDT_ML11A, 17913157Ssam #define HPDT_ML11B 8 1806927Ssam MBDT_ML11B, 18113157Ssam #define HPDT_9775 9 1826927Ssam -1, 18313157Ssam #define HPDT_9730 10 1846927Ssam -1, 18513157Ssam #define HPDT_CAPRICORN 11 1866927Ssam -1, 18713157Ssam #define HPDT_EAGLE 12 1889175Ssam -1, 18913157Ssam #define HPDT_9300 13 19011281Ssam -1, 19113157Ssam #define HPDT_RM02 14 1929175Ssam MBDT_RM02, /* beware, actually capricorn or eagle */ 1936927Ssam 0 1946927Ssam }; 1952978Swnj struct mba_device *hpinfo[NHP]; 19614145Shelge int hpattach(),hpustart(),hpstart(),hpdtint(); 1972383Swnj struct mba_driver hpdriver = 1982978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1992978Swnj hptypes, "hp", 0, hpinfo }; 2002383Swnj 20112836Ssam /* 20216225Skarels * These variable are all measured in sectors. 20316225Skarels * Sdist is how much to "lead" in the search for a desired sector 20416225Skarels * (i.e. if want N, search for N-sdist.) 20516225Skarels * Maxdist and mindist define the region right before our desired sector within 20616225Skarels * which we don't bother searching. We don't search when we are already less 20716225Skarels * then maxdist and more than mindist sectors "before" our desired sector. 20816225Skarels * Maxdist should be >= sdist. 20916225Skarels * 21016225Skarels * Beware, sdist, mindist and maxdist are not well tuned 21112836Ssam * for many of the drives listed in this table. 21212836Ssam * Try patching things with something i/o intensive 21312836Ssam * running and watch iostat. 21412836Ssam */ 2152383Swnj struct hpst { 21612836Ssam short nsect; /* # sectors/track */ 21712836Ssam short ntrak; /* # tracks/cylinder */ 21812836Ssam short nspc; /* # sector/cylinders */ 21912836Ssam short ncyl; /* # cylinders */ 22012836Ssam struct size *sizes; /* partition tables */ 22112836Ssam short sdist; /* seek distance metric */ 22216225Skarels short maxdist; /* boundaries of non-searched area */ 22316225Skarels short mindist; /* preceding the target sector */ 2242383Swnj } hpst[] = { 22516225Skarels { 32, 5, 32*5, 823, rm03_sizes, 7, 4, 1 }, /* RM03 */ 22616225Skarels { 32, 19, 32*19, 823, rm05_sizes, 7, 4, 1 }, /* RM05 */ 22716225Skarels { 22,19, 22*19, 815, rp06_sizes, 7, 4, 1 }, /* RP06 */ 22816225Skarels { 31, 14, 31*14, 559, rm80_sizes, 7, 4, 1 }, /* RM80 */ 22916225Skarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1 }, /* RP04 */ 23016225Skarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1 }, /* RP05 */ 23116225Skarels { 50, 32, 50*32, 630, rp07_sizes, 15, 8, 3 }, /* RP07 */ 23216225Skarels { 1, 1, 1, 1, 0, 0, 0, 0 }, /* ML11A */ 23316225Skarels { 1, 1, 1, 1, 0, 0, 0, 0 }, /* ML11B */ 23416225Skarels { 32, 40, 32*40, 843, cdc9775_sizes, 7, 4, 1 }, /* 9775 */ 23516225Skarels { 32, 10, 32*10, 823, cdc9730_sizes, 7, 4, 1 }, /* 9730 */ 23616225Skarels { 32, 16, 32*16, 1024, capricorn_sizes,10,4, 3 }, /* Capricorn */ 23716225Skarels { 48, 20, 48*20, 842, eagle_sizes, 15, 8, 3 }, /* EAGLE */ 23816225Skarels { 32, 19, 32*19, 815, ampex_sizes, 7, 4, 1 }, /* 9300 */ 2392383Swnj }; 2402383Swnj 2412624Swnj u_char hp_offset[16] = { 2423093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 2433093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 2443093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 2453093Swnj 0, 0, 0, 0, 24621Sbill }; 24721Sbill 2482624Swnj struct buf rhpbuf[NHP]; 2493706Sroot struct buf bhpbuf[NHP]; 2503706Sroot struct dkbad hpbad[NHP]; 25121Sbill 25210857Ssam struct hpsoftc { 25310857Ssam u_char sc_hpinit; /* drive initialized */ 25410857Ssam u_char sc_recal; /* recalibrate state */ 25510857Ssam u_char sc_hdr; /* next i/o includes header */ 25610857Ssam u_char sc_doseeks; /* perform explicit seeks */ 25710857Ssam daddr_t sc_mlsize; /* ML11 size */ 25817071Sralph int sc_pgdone; /* amount sucessfully transfered */ 25917071Sralph daddr_t sc_badbn; /* replacement block number */ 26010857Ssam } hpsoftc[NHP]; 26110857Ssam 26221Sbill #define b_cylin b_resid 26321Sbill 2645726Sroot /* #define ML11 0 to remove ML11 support */ 2655726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2665726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2675726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2685726Sroot 269*24738Sbloom #define hpunit(dev) (minor(dev) >> 3) 27011202Ssam #define MASKREG(reg) ((reg)&0xffff) 27118411Skarels #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi)) 27211202Ssam 2732978Swnj /*ARGSUSED*/ 2742978Swnj hpattach(mi, slave) 27510734Ssam register struct mba_device *mi; 2762604Swnj { 27710734Ssam 27810734Ssam mi->mi_type = hpmaptype(mi); 27910734Ssam if (!ML11 && mi->mi_dk >= 0) { 28010734Ssam struct hpst *st = &hpst[mi->mi_type]; 28110734Ssam 28210734Ssam dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 28310734Ssam } 28410734Ssam } 28510734Ssam 28610734Ssam /* 28710734Ssam * Map apparent MASSBUS drive type into manufacturer 28810734Ssam * specific configuration. For SI controllers this is done 28910734Ssam * based on codes in the serial number register. For 29010734Ssam * EMULEX controllers, the track and sector attributes are 29110734Ssam * used when the drive type is an RM02 (not supported by DEC). 29210734Ssam */ 29310734Ssam hpmaptype(mi) 29410734Ssam register struct mba_device *mi; 29510734Ssam { 2966927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 29710734Ssam register int type = mi->mi_type; 2986927Ssam 2996927Ssam /* 30011281Ssam * Model-byte processing for SI controllers. 3016927Ssam * NB: Only deals with RM03 and RM05 emulations. 3026927Ssam */ 30310734Ssam if (type == HPDT_RM03 || type == HPDT_RM05) { 30410734Ssam int hpsn = hpaddr->hpsn; 3056927Ssam 3066927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 30710734Ssam return (type); 3086927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 3096927Ssam 3106927Ssam case SI9775D: 31111281Ssam printf("hp%d: 9775 (direct)\n", mi->mi_unit); 31210734Ssam type = HPDT_9775; 3136927Ssam break; 3146927Ssam 3156927Ssam case SI9730D: 31611281Ssam printf("hp%d: 9730 (direct)\n", mi->mi_unit); 31710734Ssam type = HPDT_9730; 3186927Ssam break; 3196927Ssam 3207035Swnj /* 32111281Ssam * Beware, since the only SI controller we 32211281Ssam * have has a 9300 instead of a 9766, we map the 32311281Ssam * drive type into the 9300. This means that 32411281Ssam * on a 9766 you lose the last 8 cylinders (argh). 3257035Swnj */ 3266927Ssam case SI9766: 32711281Ssam printf("hp%d: 9300\n", mi->mi_unit); 32811281Ssam type = HPDT_9300; 3296927Ssam break; 3306927Ssam 3316927Ssam case SI9762: 3326927Ssam printf("hp%d: 9762\n", mi->mi_unit); 33310734Ssam type = HPDT_RM03; 3346927Ssam break; 33511281Ssam 33611281Ssam case SICAPD: 33711281Ssam printf("hp%d: capricorn\n", mi->mi_unit); 33811281Ssam type = HPDT_CAPRICORN; 33911281Ssam break; 34011281Ssam 34111281Ssam case SI9751D: 34211281Ssam printf("hp%d: eagle\n", mi->mi_unit); 34311281Ssam type = HPDT_EAGLE; 34411281Ssam break; 3456927Ssam } 34610734Ssam return (type); 34710734Ssam } 3486927Ssam 3496927Ssam /* 35010734Ssam * EMULEX SC750 or SC780. Poke the holding register. 3516927Ssam */ 35210734Ssam if (type == HPDT_RM02) { 35310734Ssam int ntracks, nsectors; 35410734Ssam 35511315Ssam hpaddr->hpof = HPOF_FMT22; 35611315Ssam mbclrattn(mi); 3576927Ssam hpaddr->hpcs1 = HP_NOP; 3586927Ssam hpaddr->hphr = HPHR_MAXTRAK; 35911202Ssam ntracks = MASKREG(hpaddr->hphr) + 1; 36010055Ssam if (ntracks == 16) { 3616927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 36210734Ssam type = HPDT_CAPRICORN; 36310734Ssam goto done; 36410734Ssam } 36513157Ssam if (ntracks == 19) { 36613157Ssam printf("hp%d: 9300\n", mi->mi_unit); 36713157Ssam type = HPDT_9300; 36813157Ssam goto done; 36913157Ssam } 37010734Ssam hpaddr->hpcs1 = HP_NOP; 37110734Ssam hpaddr->hphr = HPHR_MAXSECT; 37211202Ssam nsectors = MASKREG(hpaddr->hphr) + 1; 37311315Ssam if (ntracks == 20 && nsectors == 48) { 37410734Ssam type = HPDT_EAGLE; 37511212Ssam printf("hp%d: eagle\n", mi->mi_unit); 37611315Ssam goto done; 37710734Ssam } 37811315Ssam printf("hp%d: ntracks %d, nsectors %d: unknown device\n", 37913157Ssam mi->mi_unit, ntracks, nsectors); 38010734Ssam done: 3816927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 38211315Ssam mbclrattn(mi); /* conservative */ 38310734Ssam return (type); 38410734Ssam } 3856927Ssam 38610734Ssam /* 38710734Ssam * Map all ML11's to the same type. Also calculate 38810734Ssam * transfer rates based on device characteristics. 38910734Ssam */ 39010734Ssam if (type == HPDT_ML11A || type == HPDT_ML11B) { 39110857Ssam register struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 39210857Ssam register int trt; 3932604Swnj 39410857Ssam sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 3955726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 39610857Ssam sc->sc_mlsize >>= 2; 3975726Sroot if (mi->mi_dk >= 0) { 3985726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3995726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 4005726Sroot } 40110734Ssam type = HPDT_ML11A; 4026927Ssam } 40310734Ssam return (type); 4042604Swnj } 4052604Swnj 4068579Sroot hpopen(dev) 4078579Sroot dev_t dev; 4088579Sroot { 409*24738Sbloom register int unit = hpunit(dev); 4108579Sroot register struct mba_device *mi; 4118579Sroot 4128579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 4138579Sroot return (ENXIO); 4148579Sroot return (0); 4158579Sroot } 4168579Sroot 41721Sbill hpstrategy(bp) 4182383Swnj register struct buf *bp; 41921Sbill { 4202978Swnj register struct mba_device *mi; 4212383Swnj register struct hpst *st; 4222383Swnj register int unit; 42321Sbill long sz, bn; 4242383Swnj int xunit = minor(bp->b_dev) & 07; 4255432Sroot int s; 42621Sbill 42721Sbill sz = bp->b_bcount; 42821Sbill sz = (sz+511) >> 9; 429*24738Sbloom unit = hpunit(bp->b_dev); 430*24738Sbloom if (unit >= NHP) { 431*24738Sbloom bp->b_error = ENXIO; 4322383Swnj goto bad; 433*24738Sbloom } 4342383Swnj mi = hpinfo[unit]; 435*24738Sbloom if (mi == 0 || mi->mi_alive == 0) { 436*24738Sbloom bp->b_error = ENXIO; 4372383Swnj goto bad; 438*24738Sbloom } 4392383Swnj st = &hpst[mi->mi_type]; 4405726Sroot if (ML11) { 44110857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 44210857Ssam 4435726Sroot if (bp->b_blkno < 0 || 444*24738Sbloom bp->b_blkno+sz > sc->sc_mlsize) { 445*24738Sbloom if (bp->b_blkno == sc->sc_mlsize + 1) 446*24738Sbloom goto done; 447*24738Sbloom bp->b_error = EINVAL; 4485726Sroot goto bad; 449*24738Sbloom } 4505726Sroot bp->b_cylin = 0; 4515726Sroot } else { 4525726Sroot if (bp->b_blkno < 0 || 453*24738Sbloom (bn = bp->b_blkno)+sz > st->sizes[xunit].nblocks) { 454*24738Sbloom if (bp->b_blkno == st->sizes[xunit].nblocks + 1) 455*24738Sbloom goto done; 456*24738Sbloom bp->b_error = EINVAL; 4575726Sroot goto bad; 458*24738Sbloom } 4595726Sroot bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 4605726Sroot } 4615432Sroot s = spl5(); 4622383Swnj disksort(&mi->mi_tab, bp); 4632383Swnj if (mi->mi_tab.b_active == 0) 4642383Swnj mbustart(mi); 4655432Sroot splx(s); 4662383Swnj return; 4672383Swnj 4682383Swnj bad: 4692383Swnj bp->b_flags |= B_ERROR; 470*24738Sbloom done: 4712383Swnj iodone(bp); 4722383Swnj return; 47321Sbill } 47421Sbill 4752383Swnj hpustart(mi) 4762978Swnj register struct mba_device *mi; 47721Sbill { 4782624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4792383Swnj register struct buf *bp = mi->mi_tab.b_actf; 48011315Ssam register struct hpst *st; 48110857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 48221Sbill daddr_t bn; 48316791Skarels int sn, tn, dist; 48421Sbill 48511315Ssam st = &hpst[mi->mi_type]; 4863706Sroot hpaddr->hpcs1 = 0; 4872624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4882383Swnj return (MBU_BUSY); 48910857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 4903706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4913706Sroot 49210857Ssam sc->sc_hpinit = 1; 4932624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4943140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4953140Swnj printf("DCLR attn\n"); 4962624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 4975726Sroot if (!ML11) 4985726Sroot hpaddr->hpof = HPOF_FMT22; 4993140Swnj mbclrattn(mi); 5005726Sroot if (!ML11) { 5015726Sroot bbp->b_flags = B_READ|B_BUSY; 5025726Sroot bbp->b_dev = bp->b_dev; 5035726Sroot bbp->b_bcount = 512; 5045726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 5055726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 5065726Sroot bbp->b_cylin = st->ncyl - 1; 5075726Sroot mi->mi_tab.b_actf = bbp; 5085726Sroot bbp->av_forw = bp; 5095726Sroot bp = bbp; 5105726Sroot } 51121Sbill } 5122604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 5132383Swnj return (MBU_DODATA); 5145726Sroot if (ML11) 5155726Sroot return (MBU_DODATA); 5163093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 5172383Swnj return (MBU_DODATA); 518*24738Sbloom bn = bp->b_blkno; 51916791Skarels sn = bn % st->nspc; 52016791Skarels tn = sn / st->nsect; 52116791Skarels sn = sn % st->nsect; 52211202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 52310908Ssam if (sc->sc_doseeks) 5242383Swnj return (MBU_DODATA); 52516225Skarels dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1; 5262383Swnj if (dist < 0) 5272383Swnj dist += st->nsect; 52816225Skarels if (dist > st->maxdist || dist < st->mindist) 5292383Swnj return (MBU_DODATA); 5302614Swnj } else 5312614Swnj hpaddr->hpdc = bp->b_cylin; 53210908Ssam if (sc->sc_doseeks) 5332624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 534305Sbill else { 53516225Skarels sn = (sn + st->nsect - st->sdist) % st->nsect; 53616791Skarels hpaddr->hpda = (tn << 8) + sn; 5372624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 538305Sbill } 5392383Swnj return (MBU_STARTED); 54021Sbill } 54121Sbill 5422383Swnj hpstart(mi) 5432978Swnj register struct mba_device *mi; 54421Sbill { 5452624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5462383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5472383Swnj register struct hpst *st = &hpst[mi->mi_type]; 54810857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 54921Sbill daddr_t bn; 5502383Swnj int sn, tn; 55121Sbill 55217071Sralph if (bp->b_flags & B_BAD) 55317071Sralph bn = sc->sc_badbn; 55417071Sralph else 555*24738Sbloom bn = bp->b_blkno + sc->sc_pgdone; 5565726Sroot if (ML11) 5575726Sroot hpaddr->hpda = bn; 5585726Sroot else { 5595726Sroot sn = bn%st->nspc; 5605726Sroot tn = sn/st->nsect; 5615726Sroot sn %= st->nsect; 5625726Sroot hpaddr->hpdc = bp->b_cylin; 5635726Sroot hpaddr->hpda = (tn << 8) + sn; 5645726Sroot } 56510857Ssam if (sc->sc_hdr) { 5665726Sroot if (bp->b_flags & B_READ) 5675726Sroot return (HP_RHDR|HP_GO); 5685726Sroot else 5695726Sroot return (HP_WHDR|HP_GO); 5705726Sroot } 5715726Sroot return (0); 57221Sbill } 57321Sbill 5743102Swnj hpdtint(mi, mbsr) 5752978Swnj register struct mba_device *mi; 5763102Swnj int mbsr; 57721Sbill { 5782624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5792383Swnj register struct buf *bp = mi->mi_tab.b_actf; 58011315Ssam register struct hpst *st; 5815893Swnj register int er1, er2; 58210857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 58318411Skarels int retry = 0, i; 58421Sbill 58511315Ssam st = &hpst[mi->mi_type]; 5863102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 58714145Shelge er1 = hpaddr->hper1; 58814145Shelge er2 = hpaddr->hper2; 58918411Skarels if (HPWAIT(mi, hpaddr) == 0) 59018411Skarels goto hard; 5913706Sroot #ifdef HPDEBUG 5923289Swnj if (hpdebug) { 5933706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5943706Sroot 59518411Skarels printf("hperr: bp %x cyl %d blk %d pgdone %d as %o ", 59618411Skarels bp, bp->b_cylin, bp->b_blkno, sc->sc_pgdone, 5973706Sroot hpaddr->hpas&0xff); 59811202Ssam printf("dc %x da %x\n",MASKREG(dc), MASKREG(da)); 5993289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 6003289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 60114145Shelge printf("er1=%b er2=%b\n", MASKREG(er1), HPER1_BITS, 60214145Shelge MASKREG(er2), HPER2_BITS); 6033289Swnj DELAY(1000000); 6043289Swnj } 6053706Sroot #endif 6065893Swnj if (er1 & HPER1_HCRC) { 6075858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 6085893Swnj er2 &= ~HPER2_BSE; 6095893Swnj } 61016791Skarels if (er1 & HPER1_WLE) { 611*24738Sbloom log(KERN_RECOV, "hp%d: write locked\n", 612*24738Sbloom hpunit(bp->b_dev)); 6132826Swnj bp->b_flags |= B_ERROR; 61416791Skarels } else if (sc->sc_hdr) { 61516791Skarels goto hard; 61617071Sralph } else if (RM80 && er2&HPER2_SSE) { 61717071Sralph (void) hpecc(mi, SSE); 61817071Sralph return (MBD_RESTARTED); 61916791Skarels } else if ((er2 & HPER2_BSE) && !ML11) { 6205726Sroot if (hpecc(mi, BSE)) 62111202Ssam return (MBD_RESTARTED); 62211202Ssam goto hard; 62316791Skarels } else if (MASKREG(er1) == HPER1_FER && RP06) { 62416791Skarels if (hpecc(mi, BSE)) 62516791Skarels return (MBD_RESTARTED); 62616791Skarels goto hard; 62717071Sralph } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 62817071Sralph mi->mi_tab.b_errcnt > 7) { 62916791Skarels if (hpecc(mi, ECC)) 63016791Skarels return (MBD_RESTARTED); 63116791Skarels /* else done */ 6322826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 63316791Skarels (ML11 && mi->mi_tab.b_errcnt > 15) || 6343102Swnj mbsr & MBSR_HARD || 6355858Swnj er1 & HPER1_HARD || 6365893Swnj (!ML11 && (er2 & HPER2_HARD))) { 63710886Shelge /* 63814134Shelge * HCRC means the header is screwed up and the sector 63914134Shelge * might well exist in the bad sector table, 64014134Shelge * better check.... 64110886Shelge */ 64216791Skarels if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE)) 64311202Ssam return (MBD_RESTARTED); 6443706Sroot hard: 64517071Sralph if (bp->b_flags & B_BAD) 64617071Sralph bp->b_blkno = sc->sc_badbn; 64718411Skarels else { 648*24738Sbloom bp->b_blkno = bp->b_blkno + btop(bp->b_bcount - 64918411Skarels MASKREG(-mi->mi_mba->mba_bcr)); 65018411Skarels if (er1 & (HPER1_DCK | HPER1_ECH)) 65118411Skarels bp->b_blkno--; 65218411Skarels } 6532925Swnj harderr(bp, "hp"); 6543271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6553271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6563706Sroot printf("er1=%b er2=%b", 65714145Shelge MASKREG(hpaddr->hper1), HPER1_BITS, 65814145Shelge MASKREG(hpaddr->hper2), HPER2_BITS); 6593706Sroot if (hpaddr->hpmr) 66011202Ssam printf(" mr=%o", MASKREG(hpaddr->hpmr)); 6613706Sroot if (hpaddr->hpmr2) 66211202Ssam printf(" mr2=%o", MASKREG(hpaddr->hpmr2)); 66314134Shelge if (sc->sc_hdr) 66414134Shelge printf(" (hdr i/o)"); 6653706Sroot printf("\n"); 6662826Swnj bp->b_flags |= B_ERROR; 66717071Sralph bp->b_flags &= ~B_BAD; 6682826Swnj } else 6692826Swnj retry = 1; 6702826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 67116791Skarels if ((mi->mi_tab.b_errcnt & 07) == 4) { 6722826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 67310857Ssam sc->sc_recal = 1; 67411202Ssam return (MBD_RESTARTED); 67521Sbill } 6762826Swnj } 6773706Sroot #ifdef HPDEBUG 6783289Swnj else 67910857Ssam if (hpdebug && sc->sc_recal) { 68010857Ssam printf("recal %d ", sc->sc_recal); 6813289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 6823289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6833289Swnj printf("er1=%b er2=%b\n", 6843289Swnj hpaddr->hper1, HPER1_BITS, 6853289Swnj hpaddr->hper2, HPER2_BITS); 6863289Swnj } 6873706Sroot #endif 68818411Skarels HPWAIT(mi, hpaddr); 68910857Ssam switch (sc->sc_recal) { 6903093Swnj 6913093Swnj case 1: 6923093Swnj hpaddr->hpdc = bp->b_cylin; 6933093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 69410857Ssam sc->sc_recal++; 6953706Sroot return (MBD_RESTARTED); 6963093Swnj case 2: 69716791Skarels retry = 1; 69816791Skarels break; 69916791Skarels } 70016791Skarels sc->sc_recal = 0; 70116791Skarels if (retry) { 70216791Skarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 70316791Skarels hpaddr->hpof = 70416791Skarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 70516791Skarels hpaddr->hpcs1 = HP_OFFSET|HP_GO; 70618411Skarels HPWAIT(mi, hpaddr); 70716791Skarels mbclrattn(mi); 70816791Skarels } 7092892Swnj return (MBD_RETRY); 7102892Swnj } 7113640Swnj if (mi->mi_tab.b_errcnt >= 16) { 7123093Swnj /* 7133093Swnj * This is fast and occurs rarely; we don't 7143093Swnj * bother with interrupts. 7153093Swnj */ 7162624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 71718411Skarels HPWAIT(mi, hpaddr); 7182383Swnj mbclrattn(mi); 71921Sbill } 72017071Sralph if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 72117071Sralph return (MBD_RESTARTED); 72217071Sralph sc->sc_hdr = 0; 72317071Sralph sc->sc_pgdone = 0; 72417071Sralph bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr); 7255726Sroot if (!ML11) { 7265726Sroot hpaddr->hpof = HPOF_FMT22; 7275726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 7285726Sroot } 7292383Swnj return (MBD_DONE); 73021Sbill } 73121Sbill 73218411Skarels /* 73318411Skarels * Wait (for a bit) for a drive to come ready; 73418411Skarels * returns nonzero on success. 73518411Skarels */ 73618411Skarels hpwait(mi) 73718411Skarels register struct mba_device *mi; 73818411Skarels { 73918411Skarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 74018411Skarels register i = 100000; 74118411Skarels 74218411Skarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 74318411Skarels DELAY(10); 74418411Skarels if (i == 0) 74518411Skarels printf("hp%d: intr, not ready\n", mi->mi_unit); 74618411Skarels return (i); 74718411Skarels } 74818411Skarels 7497738Sroot hpread(dev, uio) 7502624Swnj dev_t dev; 7517738Sroot struct uio *uio; 75221Sbill { 753*24738Sbloom register int unit = hpunit(dev); 75421Sbill 7552624Swnj if (unit >= NHP) 7568156Sroot return (ENXIO); 7578156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 75821Sbill } 75921Sbill 7607831Sroot hpwrite(dev, uio) 7612624Swnj dev_t dev; 7627831Sroot struct uio *uio; 76321Sbill { 764*24738Sbloom register int unit = hpunit(dev); 76521Sbill 7662624Swnj if (unit >= NHP) 7678156Sroot return (ENXIO); 7688156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 76921Sbill } 77021Sbill 7715726Sroot /*ARGSUSED*/ 7727635Ssam hpioctl(dev, cmd, data, flag) 7735726Sroot dev_t dev; 7745726Sroot int cmd; 7757635Ssam caddr_t data; 7765726Sroot int flag; 7775726Sroot { 7785726Sroot 7795726Sroot switch (cmd) { 7807635Ssam 7815726Sroot case DKIOCHDR: /* do header read/write */ 782*24738Sbloom hpsoftc[hpunit(dev)].sc_hdr = 1; 7838579Sroot return (0); 7845726Sroot 7855726Sroot default: 7868579Sroot return (ENXIO); 7875726Sroot } 7885726Sroot } 7895726Sroot 7903706Sroot hpecc(mi, flag) 7912978Swnj register struct mba_device *mi; 7923706Sroot int flag; 79321Sbill { 7942383Swnj register struct mba_regs *mbp = mi->mi_mba; 7952624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 7962383Swnj register struct buf *bp = mi->mi_tab.b_actf; 7973706Sroot register struct hpst *st = &hpst[mi->mi_type]; 79817071Sralph struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 7993706Sroot int npf, o; 8002383Swnj int bn, cn, tn, sn; 801914Sbill int bcr; 80221Sbill 80318411Skarels bcr = MASKREG(-mbp->mba_bcr); 80417071Sralph if (bp->b_flags & B_BAD) 8053706Sroot npf = bp->b_error; 8063706Sroot else 80718411Skarels npf = btop(bp->b_bcount - bcr); 808420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 809*24738Sbloom bn = bp->b_blkno; 810420Sbill cn = bp->b_cylin; 81118411Skarels sn = bn%(st->nspc) + npf; 8122383Swnj tn = sn/st->nsect; 8132383Swnj sn %= st->nsect; 8142383Swnj cn += tn/st->ntrak; 8152383Swnj tn %= st->ntrak; 81624187Skarels bn += npf; 8173706Sroot switch (flag) { 81810856Ssam case ECC: { 8193706Sroot register int i; 8203706Sroot caddr_t addr; 8213706Sroot struct pte mpte; 8223706Sroot int bit, byte, mask; 8233706Sroot 8243706Sroot npf--; /* because block in error is previous block */ 82518411Skarels bn--; 82617071Sralph if (bp->b_flags & B_BAD) 82717071Sralph bn = sc->sc_badbn; 828*24738Sbloom log(KERN_RECOV, "hp%d%c: soft ecc sn%d\n", hpunit(bp->b_dev), 82917071Sralph 'a'+(minor(bp->b_dev)&07), bn); 83011202Ssam mask = MASKREG(rp->hpec2); 83111202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 8323706Sroot bit = i&07; 8333706Sroot i = (i&~07)>>3; 8343706Sroot byte = i + o; 8353706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 8363706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 8373706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 8383706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 8393706Sroot byte++; 8403706Sroot i++; 8413706Sroot bit -= 8; 8423706Sroot } 84318411Skarels if (bcr == 0) 8443706Sroot return (0); 8453847Sroot npf++; 8463706Sroot break; 8473706Sroot } 8483706Sroot 8493706Sroot case SSE: 8503706Sroot rp->hpof |= HPOF_SSEI; 85117071Sralph if (bp->b_flags & B_BAD) { 85217071Sralph bn = sc->sc_badbn; 85317071Sralph goto fixregs; 85417071Sralph } 8553706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8563706Sroot break; 8573706Sroot 8583706Sroot case BSE: 85917071Sralph if (rp->hpof & HPOF_SSEI) 86017071Sralph sn++; 8613706Sroot #ifdef HPBDEBUG 8623706Sroot if (hpbdebug) 8633706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8643706Sroot #endif 86517071Sralph if (bp->b_flags & B_BAD) 86617071Sralph return (0); 8673706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 86811202Ssam return (0); 8693706Sroot bp->b_flags |= B_BAD; 8703706Sroot bp->b_error = npf + 1; 87117071Sralph rp->hpof &= ~HPOF_SSEI; 8723706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 87317071Sralph sc->sc_badbn = bn; 87417071Sralph fixregs: 8753706Sroot cn = bn/st->nspc; 8763706Sroot sn = bn%st->nspc; 8773706Sroot tn = sn/st->nsect; 8783706Sroot sn %= st->nsect; 8793706Sroot mbp->mba_bcr = -512; 8803706Sroot #ifdef HPBDEBUG 8813706Sroot if (hpbdebug) 8823706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 8833706Sroot #endif 8843706Sroot break; 8853706Sroot 8863706Sroot case CONT: 8873706Sroot #ifdef HPBDEBUG 8883706Sroot if (hpbdebug) 8893706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 8903706Sroot #endif 8913706Sroot bp->b_flags &= ~B_BAD; 8923706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 89311202Ssam if (MASKREG(mbp->mba_bcr) == 0) 89411202Ssam return (0); 8953706Sroot break; 8963706Sroot } 8973706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 89817071Sralph if (rp->hpof & HPOF_SSEI) 8992883Swnj sn++; 900420Sbill rp->hpdc = cn; 901420Sbill rp->hpda = (tn<<8) + sn; 902420Sbill mbp->mba_sr = -1; 9033706Sroot mbp->mba_var = (int)ptob(npf) + o; 9043706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 9053706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 90617071Sralph sc->sc_pgdone = npf; 907420Sbill return (1); 90821Sbill } 9092362Swnj 9102362Swnj #define DBSIZE 20 9112362Swnj 9122362Swnj hpdump(dev) 9132362Swnj dev_t dev; 9142362Swnj { 9152978Swnj register struct mba_device *mi; 9162383Swnj register struct mba_regs *mba; 9172624Swnj struct hpdevice *hpaddr; 9182362Swnj char *start; 9192383Swnj int num, unit; 9202383Swnj register struct hpst *st; 9212362Swnj 9222362Swnj num = maxfree; 9232362Swnj start = 0; 924*24738Sbloom unit = hpunit(dev); 9252827Swnj if (unit >= NHP) 9262827Swnj return (ENXIO); 9272383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 9282978Swnj mi = phys(hpinfo[unit],struct mba_device *); 9292827Swnj if (mi == 0 || mi->mi_alive == 0) 9302827Swnj return (ENXIO); 9312383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 9323102Swnj mba->mba_cr = MBCR_INIT; 9332624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 9343093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 9352624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 9362624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 9373093Swnj hpaddr->hpof = HPOF_FMT22; 9382362Swnj } 9392383Swnj st = &hpst[mi->mi_type]; 94024224Sbloom if (dumplo < 0) 9412827Swnj return (EINVAL); 94224224Sbloom if (dumplo + num >= st->sizes[minor(dev)&07].nblocks) 94324224Sbloom num = st->sizes[minor(dev)&07].nblocks - dumplo; 9442362Swnj while (num > 0) { 9452383Swnj register struct pte *hpte = mba->mba_map; 9462362Swnj register int i; 9472383Swnj int blk, cn, sn, tn; 9482362Swnj daddr_t bn; 9492362Swnj 9502362Swnj blk = num > DBSIZE ? DBSIZE : num; 9512362Swnj bn = dumplo + btop(start); 9522383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 9532383Swnj sn = bn%st->nspc; 9542383Swnj tn = sn/st->nsect; 9552383Swnj sn = sn%st->nsect; 9562362Swnj hpaddr->hpdc = cn; 9572362Swnj hpaddr->hpda = (tn << 8) + sn; 9582362Swnj for (i = 0; i < blk; i++) 9592362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 9602383Swnj mba->mba_sr = -1; 9612383Swnj mba->mba_bcr = -(blk*NBPG); 9622383Swnj mba->mba_var = 0; 9632624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 9643093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 96516791Skarels DELAY(10); 9663093Swnj if (hpaddr->hpds&HPDS_ERR) 9672827Swnj return (EIO); 9682362Swnj start += blk*NBPG; 9692362Swnj num -= blk; 9702362Swnj } 9712362Swnj return (0); 9722362Swnj } 97312506Ssam 97412506Ssam hpsize(dev) 97512506Ssam dev_t dev; 97612506Ssam { 977*24738Sbloom int unit = hpunit(dev); 97812506Ssam struct mba_device *mi; 97912506Ssam struct hpst *st; 98012506Ssam 98112506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 98212506Ssam return (-1); 98312506Ssam st = &hpst[mi->mi_type]; 98412506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 98512506Ssam } 9861565Sbill #endif 987