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*24783Skarels * @(#)hp.c 6.13 (Berkeley) 09/16/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 26924738Sbloom #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 { 40924738Sbloom 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; 423*24783Skarels long sz; 4242383Swnj int xunit = minor(bp->b_dev) & 07; 4255432Sroot int s; 42621Sbill 42721Sbill sz = bp->b_bcount; 42821Sbill sz = (sz+511) >> 9; 42924738Sbloom unit = hpunit(bp->b_dev); 43024738Sbloom if (unit >= NHP) { 43124738Sbloom bp->b_error = ENXIO; 4322383Swnj goto bad; 43324738Sbloom } 4342383Swnj mi = hpinfo[unit]; 43524738Sbloom if (mi == 0 || mi->mi_alive == 0) { 43624738Sbloom bp->b_error = ENXIO; 4372383Swnj goto bad; 43824738Sbloom } 4392383Swnj st = &hpst[mi->mi_type]; 4405726Sroot if (ML11) { 44110857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 44210857Ssam 4435726Sroot if (bp->b_blkno < 0 || 44424738Sbloom bp->b_blkno+sz > sc->sc_mlsize) { 445*24783Skarels if (bp->b_blkno == sc->sc_mlsize) { 446*24783Skarels bp->b_resid = bp->b_bcount; 44724738Sbloom goto done; 448*24783Skarels } 44924738Sbloom bp->b_error = EINVAL; 4505726Sroot goto bad; 45124738Sbloom } 4525726Sroot bp->b_cylin = 0; 4535726Sroot } else { 4545726Sroot if (bp->b_blkno < 0 || 455*24783Skarels bp->b_blkno+sz > st->sizes[xunit].nblocks) { 456*24783Skarels if (bp->b_blkno == st->sizes[xunit].nblocks) { 457*24783Skarels bp->b_resid = bp->b_bcount; 45824738Sbloom goto done; 459*24783Skarels } 46024738Sbloom bp->b_error = EINVAL; 4615726Sroot goto bad; 46224738Sbloom } 463*24783Skarels bp->b_cylin = bp->b_blkno/st->nspc + st->sizes[xunit].cyloff; 4645726Sroot } 4655432Sroot s = spl5(); 4662383Swnj disksort(&mi->mi_tab, bp); 4672383Swnj if (mi->mi_tab.b_active == 0) 4682383Swnj mbustart(mi); 4695432Sroot splx(s); 4702383Swnj return; 4712383Swnj 4722383Swnj bad: 4732383Swnj bp->b_flags |= B_ERROR; 47424738Sbloom done: 4752383Swnj iodone(bp); 4762383Swnj return; 47721Sbill } 47821Sbill 4792383Swnj hpustart(mi) 4802978Swnj register struct mba_device *mi; 48121Sbill { 4822624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4832383Swnj register struct buf *bp = mi->mi_tab.b_actf; 48411315Ssam register struct hpst *st; 48510857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 48621Sbill daddr_t bn; 48716791Skarels int sn, tn, dist; 48821Sbill 48911315Ssam st = &hpst[mi->mi_type]; 4903706Sroot hpaddr->hpcs1 = 0; 4912624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4922383Swnj return (MBU_BUSY); 49310857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 4943706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 4953706Sroot 49610857Ssam sc->sc_hpinit = 1; 4972624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 4983140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 4993140Swnj printf("DCLR attn\n"); 5002624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 5015726Sroot if (!ML11) 5025726Sroot hpaddr->hpof = HPOF_FMT22; 5033140Swnj mbclrattn(mi); 5045726Sroot if (!ML11) { 5055726Sroot bbp->b_flags = B_READ|B_BUSY; 5065726Sroot bbp->b_dev = bp->b_dev; 5075726Sroot bbp->b_bcount = 512; 5085726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 5095726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 5105726Sroot bbp->b_cylin = st->ncyl - 1; 5115726Sroot mi->mi_tab.b_actf = bbp; 5125726Sroot bbp->av_forw = bp; 5135726Sroot bp = bbp; 5145726Sroot } 51521Sbill } 5162604Swnj if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) 5172383Swnj return (MBU_DODATA); 5185726Sroot if (ML11) 5195726Sroot return (MBU_DODATA); 5203093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 5212383Swnj return (MBU_DODATA); 52224738Sbloom bn = bp->b_blkno; 52316791Skarels sn = bn % st->nspc; 52416791Skarels tn = sn / st->nsect; 52516791Skarels sn = sn % st->nsect; 52611202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 52710908Ssam if (sc->sc_doseeks) 5282383Swnj return (MBU_DODATA); 52916225Skarels dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1; 5302383Swnj if (dist < 0) 5312383Swnj dist += st->nsect; 53216225Skarels if (dist > st->maxdist || dist < st->mindist) 5332383Swnj return (MBU_DODATA); 5342614Swnj } else 5352614Swnj hpaddr->hpdc = bp->b_cylin; 53610908Ssam if (sc->sc_doseeks) 5372624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 538305Sbill else { 53916225Skarels sn = (sn + st->nsect - st->sdist) % st->nsect; 54016791Skarels hpaddr->hpda = (tn << 8) + sn; 5412624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 542305Sbill } 5432383Swnj return (MBU_STARTED); 54421Sbill } 54521Sbill 5462383Swnj hpstart(mi) 5472978Swnj register struct mba_device *mi; 54821Sbill { 5492624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5502383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5512383Swnj register struct hpst *st = &hpst[mi->mi_type]; 55210857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 55321Sbill daddr_t bn; 5542383Swnj int sn, tn; 55521Sbill 55617071Sralph if (bp->b_flags & B_BAD) 55717071Sralph bn = sc->sc_badbn; 55817071Sralph else 55924738Sbloom bn = bp->b_blkno + sc->sc_pgdone; 5605726Sroot if (ML11) 5615726Sroot hpaddr->hpda = bn; 5625726Sroot else { 5635726Sroot sn = bn%st->nspc; 5645726Sroot tn = sn/st->nsect; 5655726Sroot sn %= st->nsect; 5665726Sroot hpaddr->hpdc = bp->b_cylin; 5675726Sroot hpaddr->hpda = (tn << 8) + sn; 5685726Sroot } 56910857Ssam if (sc->sc_hdr) { 5705726Sroot if (bp->b_flags & B_READ) 5715726Sroot return (HP_RHDR|HP_GO); 5725726Sroot else 5735726Sroot return (HP_WHDR|HP_GO); 5745726Sroot } 5755726Sroot return (0); 57621Sbill } 57721Sbill 5783102Swnj hpdtint(mi, mbsr) 5792978Swnj register struct mba_device *mi; 5803102Swnj int mbsr; 58121Sbill { 5822624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5832383Swnj register struct buf *bp = mi->mi_tab.b_actf; 58411315Ssam register struct hpst *st; 5855893Swnj register int er1, er2; 58610857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 58718411Skarels int retry = 0, i; 58821Sbill 58911315Ssam st = &hpst[mi->mi_type]; 5903102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 59114145Shelge er1 = hpaddr->hper1; 59214145Shelge er2 = hpaddr->hper2; 59318411Skarels if (HPWAIT(mi, hpaddr) == 0) 59418411Skarels goto hard; 5953706Sroot #ifdef HPDEBUG 5963289Swnj if (hpdebug) { 5973706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 5983706Sroot 59918411Skarels printf("hperr: bp %x cyl %d blk %d pgdone %d as %o ", 60018411Skarels bp, bp->b_cylin, bp->b_blkno, sc->sc_pgdone, 6013706Sroot hpaddr->hpas&0xff); 60211202Ssam printf("dc %x da %x\n",MASKREG(dc), MASKREG(da)); 6033289Swnj printf("errcnt %d ", mi->mi_tab.b_errcnt); 6043289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 60514145Shelge printf("er1=%b er2=%b\n", MASKREG(er1), HPER1_BITS, 60614145Shelge MASKREG(er2), HPER2_BITS); 6073289Swnj DELAY(1000000); 6083289Swnj } 6093706Sroot #endif 6105893Swnj if (er1 & HPER1_HCRC) { 6115858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 6125893Swnj er2 &= ~HPER2_BSE; 6135893Swnj } 61416791Skarels if (er1 & HPER1_WLE) { 61524738Sbloom log(KERN_RECOV, "hp%d: write locked\n", 61624738Sbloom hpunit(bp->b_dev)); 6172826Swnj bp->b_flags |= B_ERROR; 61816791Skarels } else if (sc->sc_hdr) { 61916791Skarels goto hard; 62017071Sralph } else if (RM80 && er2&HPER2_SSE) { 62117071Sralph (void) hpecc(mi, SSE); 62217071Sralph return (MBD_RESTARTED); 62316791Skarels } else if ((er2 & HPER2_BSE) && !ML11) { 6245726Sroot if (hpecc(mi, BSE)) 62511202Ssam return (MBD_RESTARTED); 62611202Ssam goto hard; 62716791Skarels } else if (MASKREG(er1) == HPER1_FER && RP06) { 62816791Skarels if (hpecc(mi, BSE)) 62916791Skarels return (MBD_RESTARTED); 63016791Skarels goto hard; 63117071Sralph } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 63217071Sralph mi->mi_tab.b_errcnt > 7) { 63316791Skarels if (hpecc(mi, ECC)) 63416791Skarels return (MBD_RESTARTED); 63516791Skarels /* else done */ 63624780Skarels } else if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE)) { 63724780Skarels /* 63824780Skarels * HCRC means the header is screwed up and the sector 63924780Skarels * might well exist in the bad sector table, 64024780Skarels * better check.... 64124780Skarels */ 64224780Skarels return (MBD_RESTARTED); 6432826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 64416791Skarels (ML11 && mi->mi_tab.b_errcnt > 15) || 6453102Swnj mbsr & MBSR_HARD || 6465858Swnj er1 & HPER1_HARD || 6475893Swnj (!ML11 && (er2 & HPER2_HARD))) { 6483706Sroot hard: 64917071Sralph if (bp->b_flags & B_BAD) 65017071Sralph bp->b_blkno = sc->sc_badbn; 65118411Skarels else { 65224738Sbloom bp->b_blkno = bp->b_blkno + btop(bp->b_bcount - 65318411Skarels MASKREG(-mi->mi_mba->mba_bcr)); 65418411Skarels if (er1 & (HPER1_DCK | HPER1_ECH)) 65518411Skarels bp->b_blkno--; 65618411Skarels } 6572925Swnj harderr(bp, "hp"); 6583271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6593271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6603706Sroot printf("er1=%b er2=%b", 66114145Shelge MASKREG(hpaddr->hper1), HPER1_BITS, 66214145Shelge MASKREG(hpaddr->hper2), HPER2_BITS); 6633706Sroot if (hpaddr->hpmr) 66411202Ssam printf(" mr=%o", MASKREG(hpaddr->hpmr)); 6653706Sroot if (hpaddr->hpmr2) 66611202Ssam printf(" mr2=%o", MASKREG(hpaddr->hpmr2)); 66714134Shelge if (sc->sc_hdr) 66814134Shelge printf(" (hdr i/o)"); 6693706Sroot printf("\n"); 6702826Swnj bp->b_flags |= B_ERROR; 67117071Sralph bp->b_flags &= ~B_BAD; 6722826Swnj } else 6732826Swnj retry = 1; 6742826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 67516791Skarels if ((mi->mi_tab.b_errcnt & 07) == 4) { 6762826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 67710857Ssam sc->sc_recal = 1; 67811202Ssam return (MBD_RESTARTED); 67921Sbill } 6802826Swnj } 6813706Sroot #ifdef HPDEBUG 6823289Swnj else 68310857Ssam if (hpdebug && sc->sc_recal) { 68410857Ssam printf("recal %d ", sc->sc_recal); 6853289Swnj printf("errcnt %d\n", mi->mi_tab.b_errcnt); 6863289Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6873289Swnj printf("er1=%b er2=%b\n", 6883289Swnj hpaddr->hper1, HPER1_BITS, 6893289Swnj hpaddr->hper2, HPER2_BITS); 6903289Swnj } 6913706Sroot #endif 69218411Skarels HPWAIT(mi, hpaddr); 69310857Ssam switch (sc->sc_recal) { 6943093Swnj 6953093Swnj case 1: 6963093Swnj hpaddr->hpdc = bp->b_cylin; 6973093Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 69810857Ssam sc->sc_recal++; 6993706Sroot return (MBD_RESTARTED); 7003093Swnj case 2: 70116791Skarels retry = 1; 70216791Skarels break; 70316791Skarels } 70416791Skarels sc->sc_recal = 0; 70516791Skarels if (retry) { 70616791Skarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 70716791Skarels hpaddr->hpof = 70816791Skarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 70916791Skarels hpaddr->hpcs1 = HP_OFFSET|HP_GO; 71018411Skarels HPWAIT(mi, hpaddr); 71116791Skarels mbclrattn(mi); 71216791Skarels } 7132892Swnj return (MBD_RETRY); 7142892Swnj } 7153640Swnj if (mi->mi_tab.b_errcnt >= 16) { 7163093Swnj /* 7173093Swnj * This is fast and occurs rarely; we don't 7183093Swnj * bother with interrupts. 7193093Swnj */ 7202624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 72118411Skarels HPWAIT(mi, hpaddr); 7222383Swnj mbclrattn(mi); 72321Sbill } 72417071Sralph if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 72517071Sralph return (MBD_RESTARTED); 72617071Sralph sc->sc_hdr = 0; 72717071Sralph sc->sc_pgdone = 0; 72817071Sralph bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr); 7295726Sroot if (!ML11) { 7305726Sroot hpaddr->hpof = HPOF_FMT22; 7315726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 7325726Sroot } 7332383Swnj return (MBD_DONE); 73421Sbill } 73521Sbill 73618411Skarels /* 73718411Skarels * Wait (for a bit) for a drive to come ready; 73818411Skarels * returns nonzero on success. 73918411Skarels */ 74018411Skarels hpwait(mi) 74118411Skarels register struct mba_device *mi; 74218411Skarels { 74318411Skarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 74418411Skarels register i = 100000; 74518411Skarels 74618411Skarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 74718411Skarels DELAY(10); 74818411Skarels if (i == 0) 74918411Skarels printf("hp%d: intr, not ready\n", mi->mi_unit); 75018411Skarels return (i); 75118411Skarels } 75218411Skarels 7537738Sroot hpread(dev, uio) 7542624Swnj dev_t dev; 7557738Sroot struct uio *uio; 75621Sbill { 75724738Sbloom register int unit = hpunit(dev); 75821Sbill 7592624Swnj if (unit >= NHP) 7608156Sroot return (ENXIO); 7618156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 76221Sbill } 76321Sbill 7647831Sroot hpwrite(dev, uio) 7652624Swnj dev_t dev; 7667831Sroot struct uio *uio; 76721Sbill { 76824738Sbloom register int unit = hpunit(dev); 76921Sbill 7702624Swnj if (unit >= NHP) 7718156Sroot return (ENXIO); 7728156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 77321Sbill } 77421Sbill 7755726Sroot /*ARGSUSED*/ 7767635Ssam hpioctl(dev, cmd, data, flag) 7775726Sroot dev_t dev; 7785726Sroot int cmd; 7797635Ssam caddr_t data; 7805726Sroot int flag; 7815726Sroot { 7825726Sroot 7835726Sroot switch (cmd) { 7847635Ssam 7855726Sroot case DKIOCHDR: /* do header read/write */ 78624738Sbloom hpsoftc[hpunit(dev)].sc_hdr = 1; 7878579Sroot return (0); 7885726Sroot 7895726Sroot default: 7908579Sroot return (ENXIO); 7915726Sroot } 7925726Sroot } 7935726Sroot 7943706Sroot hpecc(mi, flag) 7952978Swnj register struct mba_device *mi; 7963706Sroot int flag; 79721Sbill { 7982383Swnj register struct mba_regs *mbp = mi->mi_mba; 7992624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 8002383Swnj register struct buf *bp = mi->mi_tab.b_actf; 8013706Sroot register struct hpst *st = &hpst[mi->mi_type]; 80217071Sralph struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 8033706Sroot int npf, o; 8042383Swnj int bn, cn, tn, sn; 805914Sbill int bcr; 80621Sbill 80718411Skarels bcr = MASKREG(-mbp->mba_bcr); 80817071Sralph if (bp->b_flags & B_BAD) 8093706Sroot npf = bp->b_error; 8103706Sroot else 81118411Skarels npf = btop(bp->b_bcount - bcr); 812420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 81324738Sbloom bn = bp->b_blkno; 814420Sbill cn = bp->b_cylin; 81518411Skarels sn = bn%(st->nspc) + npf; 8162383Swnj tn = sn/st->nsect; 8172383Swnj sn %= st->nsect; 8182383Swnj cn += tn/st->ntrak; 8192383Swnj tn %= st->ntrak; 82024187Skarels bn += npf; 8213706Sroot switch (flag) { 82210856Ssam case ECC: { 8233706Sroot register int i; 8243706Sroot caddr_t addr; 8253706Sroot struct pte mpte; 8263706Sroot int bit, byte, mask; 8273706Sroot 8283706Sroot npf--; /* because block in error is previous block */ 82918411Skarels bn--; 83017071Sralph if (bp->b_flags & B_BAD) 83117071Sralph bn = sc->sc_badbn; 83224738Sbloom log(KERN_RECOV, "hp%d%c: soft ecc sn%d\n", hpunit(bp->b_dev), 83317071Sralph 'a'+(minor(bp->b_dev)&07), bn); 83411202Ssam mask = MASKREG(rp->hpec2); 83511202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 8363706Sroot bit = i&07; 8373706Sroot i = (i&~07)>>3; 8383706Sroot byte = i + o; 8393706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 8403706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 8413706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 8423706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 8433706Sroot byte++; 8443706Sroot i++; 8453706Sroot bit -= 8; 8463706Sroot } 84718411Skarels if (bcr == 0) 8483706Sroot return (0); 8493847Sroot npf++; 8503706Sroot break; 8513706Sroot } 8523706Sroot 8533706Sroot case SSE: 8543706Sroot rp->hpof |= HPOF_SSEI; 85517071Sralph if (bp->b_flags & B_BAD) { 85617071Sralph bn = sc->sc_badbn; 85717071Sralph goto fixregs; 85817071Sralph } 8593706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8603706Sroot break; 8613706Sroot 8623706Sroot case BSE: 86317071Sralph if (rp->hpof & HPOF_SSEI) 86417071Sralph sn++; 8653706Sroot #ifdef HPBDEBUG 8663706Sroot if (hpbdebug) 8673706Sroot printf("hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8683706Sroot #endif 86917071Sralph if (bp->b_flags & B_BAD) 87017071Sralph return (0); 8713706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 87211202Ssam return (0); 8733706Sroot bp->b_flags |= B_BAD; 8743706Sroot bp->b_error = npf + 1; 87517071Sralph rp->hpof &= ~HPOF_SSEI; 8763706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 87717071Sralph sc->sc_badbn = bn; 87817071Sralph fixregs: 8793706Sroot cn = bn/st->nspc; 8803706Sroot sn = bn%st->nspc; 8813706Sroot tn = sn/st->nsect; 8823706Sroot sn %= st->nsect; 88324780Skarels mbp->mba_bcr = -(min(512, bp->b_bcount - (int)ptob(npf))); 8843706Sroot #ifdef HPBDEBUG 8853706Sroot if (hpbdebug) 8863706Sroot printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 8873706Sroot #endif 8883706Sroot break; 8893706Sroot 8903706Sroot case CONT: 8913706Sroot #ifdef HPBDEBUG 8923706Sroot if (hpbdebug) 8933706Sroot printf("hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 8943706Sroot #endif 8953706Sroot bp->b_flags &= ~B_BAD; 89624780Skarels if ((int)ptob(npf) >= bp->b_bcount) 89724780Skarels return (0); 8983706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8993706Sroot break; 9003706Sroot } 9013706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 90217071Sralph if (rp->hpof & HPOF_SSEI) 9032883Swnj sn++; 904420Sbill rp->hpdc = cn; 905420Sbill rp->hpda = (tn<<8) + sn; 906420Sbill mbp->mba_sr = -1; 9073706Sroot mbp->mba_var = (int)ptob(npf) + o; 9083706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 9093706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 91017071Sralph sc->sc_pgdone = npf; 911420Sbill return (1); 91221Sbill } 9132362Swnj 9142362Swnj #define DBSIZE 20 9152362Swnj 9162362Swnj hpdump(dev) 9172362Swnj dev_t dev; 9182362Swnj { 9192978Swnj register struct mba_device *mi; 9202383Swnj register struct mba_regs *mba; 9212624Swnj struct hpdevice *hpaddr; 9222362Swnj char *start; 9232383Swnj int num, unit; 9242383Swnj register struct hpst *st; 9252362Swnj 9262362Swnj num = maxfree; 9272362Swnj start = 0; 92824738Sbloom unit = hpunit(dev); 9292827Swnj if (unit >= NHP) 9302827Swnj return (ENXIO); 9312383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 9322978Swnj mi = phys(hpinfo[unit],struct mba_device *); 9332827Swnj if (mi == 0 || mi->mi_alive == 0) 9342827Swnj return (ENXIO); 9352383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 9363102Swnj mba->mba_cr = MBCR_INIT; 9372624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 9383093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 9392624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 9402624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 9413093Swnj hpaddr->hpof = HPOF_FMT22; 9422362Swnj } 9432383Swnj st = &hpst[mi->mi_type]; 94424224Sbloom if (dumplo < 0) 9452827Swnj return (EINVAL); 94624224Sbloom if (dumplo + num >= st->sizes[minor(dev)&07].nblocks) 94724224Sbloom num = st->sizes[minor(dev)&07].nblocks - dumplo; 9482362Swnj while (num > 0) { 9492383Swnj register struct pte *hpte = mba->mba_map; 9502362Swnj register int i; 9512383Swnj int blk, cn, sn, tn; 9522362Swnj daddr_t bn; 9532362Swnj 9542362Swnj blk = num > DBSIZE ? DBSIZE : num; 9552362Swnj bn = dumplo + btop(start); 9562383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 9572383Swnj sn = bn%st->nspc; 9582383Swnj tn = sn/st->nsect; 9592383Swnj sn = sn%st->nsect; 9602362Swnj hpaddr->hpdc = cn; 9612362Swnj hpaddr->hpda = (tn << 8) + sn; 9622362Swnj for (i = 0; i < blk; i++) 9632362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 9642383Swnj mba->mba_sr = -1; 9652383Swnj mba->mba_bcr = -(blk*NBPG); 9662383Swnj mba->mba_var = 0; 9672624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 9683093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 96916791Skarels DELAY(10); 9703093Swnj if (hpaddr->hpds&HPDS_ERR) 9712827Swnj return (EIO); 9722362Swnj start += blk*NBPG; 9732362Swnj num -= blk; 9742362Swnj } 9752362Swnj return (0); 9762362Swnj } 97712506Ssam 97812506Ssam hpsize(dev) 97912506Ssam dev_t dev; 98012506Ssam { 98124738Sbloom int unit = hpunit(dev); 98212506Ssam struct mba_device *mi; 98312506Ssam struct hpst *st; 98412506Ssam 98512506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 98612506Ssam return (-1); 98712506Ssam st = &hpst[mi->mi_type]; 98812506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 98912506Ssam } 9901565Sbill #endif 991