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*25198Skarels * @(#)hp.c 6.15 (Berkeley) 10/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 * see if DCLR and/or RELEASE set attention status 2321Sbill */ 249786Ssam #include "../machine/pte.h" 2521Sbill 2617120Sbloom #include "param.h" 2717120Sbloom #include "systm.h" 2817120Sbloom #include "dk.h" 2917120Sbloom #include "buf.h" 3017120Sbloom #include "conf.h" 3117120Sbloom #include "dir.h" 3217120Sbloom #include "user.h" 3317120Sbloom #include "map.h" 348468Sroot #include "../vax/mtpr.h" 3517120Sbloom #include "vm.h" 3617120Sbloom #include "cmap.h" 3717120Sbloom #include "dkbad.h" 3817120Sbloom #include "ioctl.h" 3917120Sbloom #include "uio.h" 4018411Skarels #include "syslog.h" 4121Sbill 428988Sroot #include "../vax/dkio.h" 4317120Sbloom #include "mbareg.h" 4417120Sbloom #include "mbavar.h" 4517120Sbloom #include "hpreg.h" 4621Sbill 472383Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 482383Swnj struct size { 4921Sbill daddr_t nblocks; 5021Sbill int cyloff; 5111212Ssam } rp06_sizes[8] = { 52886Sbill 15884, 0, /* A=cyl 0 thru 37 */ 53886Sbill 33440, 38, /* B=cyl 38 thru 117 */ 54886Sbill 340670, 0, /* C=cyl 0 thru 814 */ 5511212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 5611212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 5711212Ssam 219384, 290, /* F=cyl 290 thru 814 */ 5811212Ssam 291280, 118, /* G=cyl 118 thru 814 */ 5921Sbill 0, 0, 6011212Ssam }, rp05_sizes[8] = { 6111212Ssam 15884, 0, /* A=cyl 0 thru 37 */ 6211212Ssam 33440, 38, /* B=cyl 38 thru 117 */ 6311212Ssam 171798, 0, /* C=cyl 0 thru 410 */ 6411212Ssam 15884, 118, /* D=cyl 118 thru 155 */ 6511212Ssam 55936, 156, /* E=cyl 156 thru 289 */ 6611212Ssam 50512, 290, /* F=cyl 290 thru 410 */ 6711212Ssam 122408, 118, /* G=cyl 118 thru 410 */ 6821Sbill 0, 0, 6911212Ssam }, rm03_sizes[8] = { 70886Sbill 15884, 0, /* A=cyl 0 thru 99 */ 7111212Ssam 33440, 100, /* B=cyl 100 thru 308 */ 72886Sbill 131680, 0, /* C=cyl 0 thru 822 */ 7311212Ssam 15884, 309, /* D=cyl 309 thru 408 */ 7411212Ssam 55936, 409, /* E=cyl 409 thru 758 */ 7511212Ssam 10144, 759, /* F=cyl 759 thru 822 */ 7611212Ssam 82144, 309, /* G=cyl 309 thru 822 */ 7721Sbill 0, 0, 7811212Ssam }, rm05_sizes[8] = { 79886Sbill 15884, 0, /* A=cyl 0 thru 26 */ 80886Sbill 33440, 27, /* B=cyl 27 thru 81 */ 813271Swnj 500384, 0, /* C=cyl 0 thru 822 */ 82886Sbill 15884, 562, /* D=cyl 562 thru 588 */ 83886Sbill 55936, 589, /* E=cyl 589 thru 680 */ 843729Sroot 86240, 681, /* F=cyl 681 thru 822 */ 853729Sroot 158592, 562, /* G=cyl 562 thru 822 */ 86886Sbill 291346, 82, /* H=cyl 82 thru 561 */ 872383Swnj }, rm80_sizes[8] = { 882383Swnj 15884, 0, /* A=cyl 0 thru 36 */ 892383Swnj 33440, 37, /* B=cyl 37 thru 114 */ 902383Swnj 242606, 0, /* C=cyl 0 thru 558 */ 9111212Ssam 15884, 115, /* D=cyl 115 thru 151 */ 9211212Ssam 55936, 152, /* E=cyl 152 thru 280 */ 9311212Ssam 120559, 281, /* F=cyl 281 thru 558 */ 9411212Ssam 192603, 115, /* G=cyl 115 thru 558 */ 952383Swnj 0, 0, 9611212Ssam }, rp07_sizes[8] = { 976927Ssam 15884, 0, /* A=cyl 0 thru 9 */ 9811212Ssam 66880, 10, /* B=cyl 10 thru 51 */ 9911212Ssam 1008000, 0, /* C=cyl 0 thru 629 */ 10011212Ssam 15884, 235, /* D=cyl 235 thru 244 */ 10111212Ssam 307200, 245, /* E=cyl 245 thru 436 */ 10211212Ssam 308650, 437, /* F=cyl 437 thru 629 */ 10311212Ssam 631850, 235, /* G=cyl 235 thru 629 */ 10411212Ssam 291346, 52, /* H=cyl 52 thru 234 */ 10511212Ssam }, cdc9775_sizes[8] = { 10611212Ssam 15884, 0, /* A=cyl 0 thru 12 */ 10711212Ssam 66880, 13, /* B=cyl 13 thru 65 */ 10815101Skarels 1077760, 0, /* C=cyl 0 thru 841 */ 10911212Ssam 15884, 294, /* D=cyl 294 thru 306 */ 11011212Ssam 307200, 307, /* E=cyl 307 thru 546 */ 11115101Skarels 377440, 547, /* F=cyl 547 thru 841 */ 11215101Skarels 701280, 294, /* G=cyl 294 thru 841 */ 11311212Ssam 291346, 66, /* H=cyl 66 thru 293 */ 11411212Ssam }, cdc9730_sizes[8] = { 1156927Ssam 15884, 0, /* A=cyl 0 thru 49 */ 1166927Ssam 33440, 50, /* B=cyl 50 thru 154 */ 1176927Ssam 263360, 0, /* C=cyl 0 thru 822 */ 11811212Ssam 15884, 155, /* D=cyl 155 thru 204 */ 11911212Ssam 55936, 205, /* E=cyl 205 thru 379 */ 12011212Ssam 141664, 380, /* F=cyl 380 thru 822 */ 12111212Ssam 213664, 155, /* G=cyl 155 thru 822 */ 1226927Ssam 0, 0, 12311212Ssam }, capricorn_sizes[8] = { 1246927Ssam 15884, 0, /* A=cyl 0 thru 31 */ 1256927Ssam 33440, 32, /* B=cyl 32 thru 97 */ 1266927Ssam 524288, 0, /* C=cyl 0 thru 1023 */ 12711212Ssam 15884, 668, /* D=cyl 668 thru 699 */ 12811212Ssam 55936, 700, /* E=cyl 700 thru 809 */ 12911212Ssam 109472, 810, /* F=cyl 810 thru 1023 */ 13011212Ssam 182176, 668, /* G=cyl 668 thru 1023 */ 1316927Ssam 291346, 98, /* H=cyl 98 thru 667 */ 13211212Ssam }, eagle_sizes[8] = { 13310734Ssam 15884, 0, /* A=cyl 0 thru 16 */ 13411212Ssam 66880, 17, /* B=cyl 17 thru 86 */ 13511629Ssam 808320, 0, /* C=cyl 0 thru 841 */ 13611212Ssam 15884, 391, /* D=cyl 391 thru 407 */ 13711212Ssam 307200, 408, /* E=cyl 408 thru 727 */ 13811629Ssam 109296, 728, /* F=cyl 728 thru 841 */ 13911629Ssam 432816, 391, /* G=cyl 391 thru 841 */ 14011212Ssam 291346, 87, /* H=cyl 87 thru 390 */ 14113202Sroot }, ampex_sizes[8] = { 14211281Ssam 15884, 0, /* A=cyl 0 thru 26 */ 14311281Ssam 33440, 27, /* B=cyl 27 thru 81 */ 14413184Shelge 495520, 0, /* C=cyl 0 thru 814 */ 14511281Ssam 15884, 562, /* D=cyl 562 thru 588 */ 14611281Ssam 55936, 589, /* E=cyl 589 thru 680 */ 14713184Shelge 81312, 681, /* F=cyl 681 thru 814 */ 14813184Shelge 153664, 562, /* G=cyl 562 thru 814 */ 14911281Ssam 291346, 82, /* H=cyl 82 thru 561 */ 15021Sbill }; 1512383Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 15221Sbill 1536927Ssam /* 1546927Ssam * Table for converting Massbus drive types into 1556927Ssam * indices into the partition tables. Slots are 1566927Ssam * left for those drives devined from other means 1576927Ssam * (e.g. SI, AMPEX, etc.). 1586927Ssam */ 1596927Ssam short hptypes[] = { 1606927Ssam #define HPDT_RM03 0 1616927Ssam MBDT_RM03, 1626927Ssam #define HPDT_RM05 1 1636927Ssam MBDT_RM05, 1646927Ssam #define HPDT_RP06 2 1656927Ssam MBDT_RP06, 1666927Ssam #define HPDT_RM80 3 1676927Ssam MBDT_RM80, 16813157Ssam #define HPDT_RP04 4 16913157Ssam MBDT_RP04, 17013157Ssam #define HPDT_RP05 5 1716927Ssam MBDT_RP05, 17213157Ssam #define HPDT_RP07 6 1736927Ssam MBDT_RP07, 17413157Ssam #define HPDT_ML11A 7 1756927Ssam MBDT_ML11A, 17613157Ssam #define HPDT_ML11B 8 1776927Ssam MBDT_ML11B, 17813157Ssam #define HPDT_9775 9 1796927Ssam -1, 18013157Ssam #define HPDT_9730 10 1816927Ssam -1, 18213157Ssam #define HPDT_CAPRICORN 11 1836927Ssam -1, 18413157Ssam #define HPDT_EAGLE 12 1859175Ssam -1, 18613157Ssam #define HPDT_9300 13 18711281Ssam -1, 18813157Ssam #define HPDT_RM02 14 1899175Ssam MBDT_RM02, /* beware, actually capricorn or eagle */ 1906927Ssam 0 1916927Ssam }; 1922978Swnj struct mba_device *hpinfo[NHP]; 19314145Shelge int hpattach(),hpustart(),hpstart(),hpdtint(); 1942383Swnj struct mba_driver hpdriver = 1952978Swnj { hpattach, 0, hpustart, hpstart, hpdtint, 0, 1962978Swnj hptypes, "hp", 0, hpinfo }; 1972383Swnj 19812836Ssam /* 19916225Skarels * These variable are all measured in sectors. 20016225Skarels * Sdist is how much to "lead" in the search for a desired sector 20116225Skarels * (i.e. if want N, search for N-sdist.) 20216225Skarels * Maxdist and mindist define the region right before our desired sector within 20316225Skarels * which we don't bother searching. We don't search when we are already less 20416225Skarels * then maxdist and more than mindist sectors "before" our desired sector. 20516225Skarels * Maxdist should be >= sdist. 20616225Skarels * 20716225Skarels * Beware, sdist, mindist and maxdist are not well tuned 20812836Ssam * for many of the drives listed in this table. 20912836Ssam * Try patching things with something i/o intensive 21012836Ssam * running and watch iostat. 21112836Ssam */ 2122383Swnj struct hpst { 21312836Ssam short nsect; /* # sectors/track */ 21412836Ssam short ntrak; /* # tracks/cylinder */ 21512836Ssam short nspc; /* # sector/cylinders */ 21612836Ssam short ncyl; /* # cylinders */ 21712836Ssam struct size *sizes; /* partition tables */ 21812836Ssam short sdist; /* seek distance metric */ 21916225Skarels short maxdist; /* boundaries of non-searched area */ 22016225Skarels short mindist; /* preceding the target sector */ 2212383Swnj } hpst[] = { 22216225Skarels { 32, 5, 32*5, 823, rm03_sizes, 7, 4, 1 }, /* RM03 */ 22316225Skarels { 32, 19, 32*19, 823, rm05_sizes, 7, 4, 1 }, /* RM05 */ 22416225Skarels { 22,19, 22*19, 815, rp06_sizes, 7, 4, 1 }, /* RP06 */ 22516225Skarels { 31, 14, 31*14, 559, rm80_sizes, 7, 4, 1 }, /* RM80 */ 22616225Skarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1 }, /* RP04 */ 22716225Skarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1 }, /* RP05 */ 22816225Skarels { 50, 32, 50*32, 630, rp07_sizes, 15, 8, 3 }, /* RP07 */ 22916225Skarels { 1, 1, 1, 1, 0, 0, 0, 0 }, /* ML11A */ 23016225Skarels { 1, 1, 1, 1, 0, 0, 0, 0 }, /* ML11B */ 23116225Skarels { 32, 40, 32*40, 843, cdc9775_sizes, 7, 4, 1 }, /* 9775 */ 23216225Skarels { 32, 10, 32*10, 823, cdc9730_sizes, 7, 4, 1 }, /* 9730 */ 23316225Skarels { 32, 16, 32*16, 1024, capricorn_sizes,10,4, 3 }, /* Capricorn */ 23416225Skarels { 48, 20, 48*20, 842, eagle_sizes, 15, 8, 3 }, /* EAGLE */ 23516225Skarels { 32, 19, 32*19, 815, ampex_sizes, 7, 4, 1 }, /* 9300 */ 2362383Swnj }; 2372383Swnj 2382624Swnj u_char hp_offset[16] = { 2393093Swnj HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 2403093Swnj HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 2413093Swnj HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 2423093Swnj 0, 0, 0, 0, 24321Sbill }; 24421Sbill 2452624Swnj struct buf rhpbuf[NHP]; 2463706Sroot struct buf bhpbuf[NHP]; 2473706Sroot struct dkbad hpbad[NHP]; 24821Sbill 24910857Ssam struct hpsoftc { 25010857Ssam u_char sc_hpinit; /* drive initialized */ 25110857Ssam u_char sc_recal; /* recalibrate state */ 25210857Ssam u_char sc_hdr; /* next i/o includes header */ 25310857Ssam u_char sc_doseeks; /* perform explicit seeks */ 25410857Ssam daddr_t sc_mlsize; /* ML11 size */ 255*25198Skarels int sc_blkdone; /* amount sucessfully transfered */ 25617071Sralph daddr_t sc_badbn; /* replacement block number */ 25710857Ssam } hpsoftc[NHP]; 25810857Ssam 25921Sbill #define b_cylin b_resid 26021Sbill 2615726Sroot /* #define ML11 0 to remove ML11 support */ 2625726Sroot #define ML11 (hptypes[mi->mi_type] == MBDT_ML11A) 2635726Sroot #define RP06 (hptypes[mi->mi_type] <= MBDT_RP06) 2645726Sroot #define RM80 (hptypes[mi->mi_type] == MBDT_RM80) 2655726Sroot 26624738Sbloom #define hpunit(dev) (minor(dev) >> 3) 26711202Ssam #define MASKREG(reg) ((reg)&0xffff) 26818411Skarels #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi)) 26911202Ssam 2702978Swnj /*ARGSUSED*/ 2712978Swnj hpattach(mi, slave) 27210734Ssam register struct mba_device *mi; 2732604Swnj { 27410734Ssam 27510734Ssam mi->mi_type = hpmaptype(mi); 27610734Ssam if (!ML11 && mi->mi_dk >= 0) { 27710734Ssam struct hpst *st = &hpst[mi->mi_type]; 27810734Ssam 27910734Ssam dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 28010734Ssam } 28110734Ssam } 28210734Ssam 28310734Ssam /* 28410734Ssam * Map apparent MASSBUS drive type into manufacturer 28510734Ssam * specific configuration. For SI controllers this is done 28610734Ssam * based on codes in the serial number register. For 28710734Ssam * EMULEX controllers, the track and sector attributes are 28810734Ssam * used when the drive type is an RM02 (not supported by DEC). 28910734Ssam */ 29010734Ssam hpmaptype(mi) 29110734Ssam register struct mba_device *mi; 29210734Ssam { 2936927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 29410734Ssam register int type = mi->mi_type; 2956927Ssam 2966927Ssam /* 29711281Ssam * Model-byte processing for SI controllers. 2986927Ssam * NB: Only deals with RM03 and RM05 emulations. 2996927Ssam */ 30010734Ssam if (type == HPDT_RM03 || type == HPDT_RM05) { 30110734Ssam int hpsn = hpaddr->hpsn; 3026927Ssam 3036927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 30410734Ssam return (type); 3056927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 3066927Ssam 3076927Ssam case SI9775D: 30811281Ssam printf("hp%d: 9775 (direct)\n", mi->mi_unit); 30910734Ssam type = HPDT_9775; 3106927Ssam break; 3116927Ssam 3126927Ssam case SI9730D: 31311281Ssam printf("hp%d: 9730 (direct)\n", mi->mi_unit); 31410734Ssam type = HPDT_9730; 3156927Ssam break; 3166927Ssam 3177035Swnj /* 31811281Ssam * Beware, since the only SI controller we 31911281Ssam * have has a 9300 instead of a 9766, we map the 32011281Ssam * drive type into the 9300. This means that 32111281Ssam * on a 9766 you lose the last 8 cylinders (argh). 3227035Swnj */ 3236927Ssam case SI9766: 32411281Ssam printf("hp%d: 9300\n", mi->mi_unit); 32511281Ssam type = HPDT_9300; 3266927Ssam break; 3276927Ssam 3286927Ssam case SI9762: 3296927Ssam printf("hp%d: 9762\n", mi->mi_unit); 33010734Ssam type = HPDT_RM03; 3316927Ssam break; 33211281Ssam 33311281Ssam case SICAPD: 33411281Ssam printf("hp%d: capricorn\n", mi->mi_unit); 33511281Ssam type = HPDT_CAPRICORN; 33611281Ssam break; 33711281Ssam 33811281Ssam case SI9751D: 33911281Ssam printf("hp%d: eagle\n", mi->mi_unit); 34011281Ssam type = HPDT_EAGLE; 34111281Ssam break; 3426927Ssam } 34310734Ssam return (type); 34410734Ssam } 3456927Ssam 3466927Ssam /* 34710734Ssam * EMULEX SC750 or SC780. Poke the holding register. 3486927Ssam */ 34910734Ssam if (type == HPDT_RM02) { 35010734Ssam int ntracks, nsectors; 35110734Ssam 35211315Ssam hpaddr->hpof = HPOF_FMT22; 35311315Ssam mbclrattn(mi); 3546927Ssam hpaddr->hpcs1 = HP_NOP; 3556927Ssam hpaddr->hphr = HPHR_MAXTRAK; 35611202Ssam ntracks = MASKREG(hpaddr->hphr) + 1; 35710055Ssam if (ntracks == 16) { 3586927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 35910734Ssam type = HPDT_CAPRICORN; 36010734Ssam goto done; 36110734Ssam } 36213157Ssam if (ntracks == 19) { 36313157Ssam printf("hp%d: 9300\n", mi->mi_unit); 36413157Ssam type = HPDT_9300; 36513157Ssam goto done; 36613157Ssam } 36710734Ssam hpaddr->hpcs1 = HP_NOP; 36810734Ssam hpaddr->hphr = HPHR_MAXSECT; 36911202Ssam nsectors = MASKREG(hpaddr->hphr) + 1; 37011315Ssam if (ntracks == 20 && nsectors == 48) { 37110734Ssam type = HPDT_EAGLE; 37211212Ssam printf("hp%d: eagle\n", mi->mi_unit); 37311315Ssam goto done; 37410734Ssam } 37511315Ssam printf("hp%d: ntracks %d, nsectors %d: unknown device\n", 37613157Ssam mi->mi_unit, ntracks, nsectors); 37710734Ssam done: 3786927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 37911315Ssam mbclrattn(mi); /* conservative */ 38010734Ssam return (type); 38110734Ssam } 3826927Ssam 38310734Ssam /* 38410734Ssam * Map all ML11's to the same type. Also calculate 38510734Ssam * transfer rates based on device characteristics. 38610734Ssam */ 38710734Ssam if (type == HPDT_ML11A || type == HPDT_ML11B) { 38810857Ssam register struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 38910857Ssam register int trt; 3902604Swnj 39110857Ssam sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 3925726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 39310857Ssam sc->sc_mlsize >>= 2; 3945726Sroot if (mi->mi_dk >= 0) { 3955726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 3965726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 3975726Sroot } 39810734Ssam type = HPDT_ML11A; 3996927Ssam } 40010734Ssam return (type); 4012604Swnj } 4022604Swnj 4038579Sroot hpopen(dev) 4048579Sroot dev_t dev; 4058579Sroot { 40624738Sbloom register int unit = hpunit(dev); 4078579Sroot register struct mba_device *mi; 4088579Sroot 4098579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 4108579Sroot return (ENXIO); 4118579Sroot return (0); 4128579Sroot } 4138579Sroot 41421Sbill hpstrategy(bp) 4152383Swnj register struct buf *bp; 41621Sbill { 4172978Swnj register struct mba_device *mi; 4182383Swnj register struct hpst *st; 4192383Swnj register int unit; 42024783Skarels long sz; 4212383Swnj int xunit = minor(bp->b_dev) & 07; 4225432Sroot int s; 42321Sbill 42421Sbill sz = bp->b_bcount; 42521Sbill sz = (sz+511) >> 9; 42624738Sbloom unit = hpunit(bp->b_dev); 42724738Sbloom if (unit >= NHP) { 42824738Sbloom bp->b_error = ENXIO; 4292383Swnj goto bad; 43024738Sbloom } 4312383Swnj mi = hpinfo[unit]; 43224738Sbloom if (mi == 0 || mi->mi_alive == 0) { 43324738Sbloom bp->b_error = ENXIO; 4342383Swnj goto bad; 43524738Sbloom } 4362383Swnj st = &hpst[mi->mi_type]; 4375726Sroot if (ML11) { 43810857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 43910857Ssam 4405726Sroot if (bp->b_blkno < 0 || 44124738Sbloom bp->b_blkno+sz > sc->sc_mlsize) { 44224783Skarels if (bp->b_blkno == sc->sc_mlsize) { 44324783Skarels bp->b_resid = bp->b_bcount; 44424738Sbloom goto done; 44524783Skarels } 44624738Sbloom bp->b_error = EINVAL; 4475726Sroot goto bad; 44824738Sbloom } 4495726Sroot bp->b_cylin = 0; 4505726Sroot } else { 4515726Sroot if (bp->b_blkno < 0 || 45224783Skarels bp->b_blkno+sz > st->sizes[xunit].nblocks) { 45324783Skarels if (bp->b_blkno == st->sizes[xunit].nblocks) { 45424783Skarels bp->b_resid = bp->b_bcount; 45524738Sbloom goto done; 45624783Skarels } 45724738Sbloom bp->b_error = EINVAL; 4585726Sroot goto bad; 45924738Sbloom } 46024783Skarels bp->b_cylin = bp->b_blkno/st->nspc + st->sizes[xunit].cyloff; 4615726Sroot } 4625432Sroot s = spl5(); 4632383Swnj disksort(&mi->mi_tab, bp); 4642383Swnj if (mi->mi_tab.b_active == 0) 4652383Swnj mbustart(mi); 4665432Sroot splx(s); 4672383Swnj return; 4682383Swnj 4692383Swnj bad: 4702383Swnj bp->b_flags |= B_ERROR; 47124738Sbloom done: 4722383Swnj iodone(bp); 4732383Swnj return; 47421Sbill } 47521Sbill 4762383Swnj hpustart(mi) 4772978Swnj register struct mba_device *mi; 47821Sbill { 4792624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4802383Swnj register struct buf *bp = mi->mi_tab.b_actf; 48111315Ssam register struct hpst *st; 48210857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 48321Sbill daddr_t bn; 48416791Skarels int sn, tn, dist; 48521Sbill 48611315Ssam st = &hpst[mi->mi_type]; 4873706Sroot hpaddr->hpcs1 = 0; 4882624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4892383Swnj return (MBU_BUSY); 490*25198Skarels 491*25198Skarels switch (sc->sc_recal) { 492*25198Skarels 493*25198Skarels case 1: 494*25198Skarels HPWAIT(mi, hpaddr); 495*25198Skarels hpaddr->hpdc = bp->b_cylin; 496*25198Skarels hpaddr->hpcs1 = HP_SEEK|HP_GO; 497*25198Skarels sc->sc_recal++; 498*25198Skarels return (MBU_STARTED); 499*25198Skarels case 2: 500*25198Skarels break; 501*25198Skarels } 502*25198Skarels sc->sc_recal = 0; 50310857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 5043706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 5053706Sroot 50610857Ssam sc->sc_hpinit = 1; 5072624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 5083140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 5093140Swnj printf("DCLR attn\n"); 5102624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 5115726Sroot if (!ML11) 5125726Sroot hpaddr->hpof = HPOF_FMT22; 5133140Swnj mbclrattn(mi); 5145726Sroot if (!ML11) { 5155726Sroot bbp->b_flags = B_READ|B_BUSY; 5165726Sroot bbp->b_dev = bp->b_dev; 5175726Sroot bbp->b_bcount = 512; 5185726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 5195726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 5205726Sroot bbp->b_cylin = st->ncyl - 1; 5215726Sroot mi->mi_tab.b_actf = bbp; 5225726Sroot bbp->av_forw = bp; 5235726Sroot bp = bbp; 5245726Sroot } 52521Sbill } 526*25198Skarels if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) { 527*25198Skarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 528*25198Skarels hpaddr->hpof = 529*25198Skarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 530*25198Skarels hpaddr->hpcs1 = HP_OFFSET|HP_GO; 531*25198Skarels HPWAIT(mi, hpaddr); 532*25198Skarels mbclrattn(mi); 533*25198Skarels } 5342383Swnj return (MBU_DODATA); 535*25198Skarels } 5365726Sroot if (ML11) 5375726Sroot return (MBU_DODATA); 5383093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 5392383Swnj return (MBU_DODATA); 54024738Sbloom bn = bp->b_blkno; 54116791Skarels sn = bn % st->nspc; 54216791Skarels tn = sn / st->nsect; 54316791Skarels sn = sn % st->nsect; 54411202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 54510908Ssam if (sc->sc_doseeks) 5462383Swnj return (MBU_DODATA); 54716225Skarels dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1; 5482383Swnj if (dist < 0) 5492383Swnj dist += st->nsect; 55016225Skarels if (dist > st->maxdist || dist < st->mindist) 5512383Swnj return (MBU_DODATA); 5522614Swnj } else 5532614Swnj hpaddr->hpdc = bp->b_cylin; 55410908Ssam if (sc->sc_doseeks) 5552624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 556305Sbill else { 55716225Skarels sn = (sn + st->nsect - st->sdist) % st->nsect; 55816791Skarels hpaddr->hpda = (tn << 8) + sn; 5592624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 560305Sbill } 5612383Swnj return (MBU_STARTED); 56221Sbill } 56321Sbill 5642383Swnj hpstart(mi) 5652978Swnj register struct mba_device *mi; 56621Sbill { 5672624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5682383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5692383Swnj register struct hpst *st = &hpst[mi->mi_type]; 57010857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 57121Sbill daddr_t bn; 572*25198Skarels int sn, tn, cn; 57321Sbill 5745726Sroot if (ML11) 575*25198Skarels hpaddr->hpda = bp->b_blkno + sc->sc_blkdone; 5765726Sroot else { 577*25198Skarels if (bp->b_flags & B_BAD) { 578*25198Skarels bn = sc->sc_badbn; 579*25198Skarels cn = bn / st->nspc; 580*25198Skarels } else { 581*25198Skarels bn = bp->b_blkno; 582*25198Skarels cn = bp->b_cylin; 583*25198Skarels } 584*25198Skarels sn = bn % st->nspc; 585*25198Skarels if ((bp->b_flags & B_BAD) == 0) 586*25198Skarels sn += sc->sc_blkdone; 587*25198Skarels tn = sn / st->nsect; 5885726Sroot sn %= st->nsect; 589*25198Skarels cn += tn / st->ntrak; 590*25198Skarels tn %= st->ntrak; 5915726Sroot hpaddr->hpda = (tn << 8) + sn; 592*25198Skarels hpaddr->hpdc = cn; 5935726Sroot } 59410857Ssam if (sc->sc_hdr) { 5955726Sroot if (bp->b_flags & B_READ) 5965726Sroot return (HP_RHDR|HP_GO); 5975726Sroot else 5985726Sroot return (HP_WHDR|HP_GO); 5995726Sroot } 6005726Sroot return (0); 60121Sbill } 60221Sbill 6033102Swnj hpdtint(mi, mbsr) 6042978Swnj register struct mba_device *mi; 6053102Swnj int mbsr; 60621Sbill { 6072624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 6082383Swnj register struct buf *bp = mi->mi_tab.b_actf; 60911315Ssam register struct hpst *st; 6105893Swnj register int er1, er2; 61110857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 61218411Skarels int retry = 0, i; 61321Sbill 61411315Ssam st = &hpst[mi->mi_type]; 6153102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 61614145Shelge er1 = hpaddr->hper1; 61714145Shelge er2 = hpaddr->hper2; 61818411Skarels if (HPWAIT(mi, hpaddr) == 0) 61918411Skarels goto hard; 6203706Sroot #ifdef HPDEBUG 6213289Swnj if (hpdebug) { 6223706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 6233706Sroot 624*25198Skarels log(LOG_DEBUG, 625*25198Skarels "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n", 626*25198Skarels bp, bp->b_cylin, bp->b_blkno, sc->sc_blkdone, 627*25198Skarels hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da)); 628*25198Skarels log(LOG_DEBUG, "errcnt %d mbsr=%b er1=%b er2=%b\n", 629*25198Skarels mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 630*25198Skarels MASKREG(er1), HPER1_BITS, 631*25198Skarels MASKREG(er2), HPER2_BITS); 6323289Swnj } 6333706Sroot #endif 6345893Swnj if (er1 & HPER1_HCRC) { 6355858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 6365893Swnj er2 &= ~HPER2_BSE; 6375893Swnj } 63816791Skarels if (er1 & HPER1_WLE) { 63924844Seric log(LOG_WARNING, "hp%d: write locked\n", 64024738Sbloom hpunit(bp->b_dev)); 6412826Swnj bp->b_flags |= B_ERROR; 64216791Skarels } else if (sc->sc_hdr) { 64316791Skarels goto hard; 64417071Sralph } else if (RM80 && er2&HPER2_SSE) { 64517071Sralph (void) hpecc(mi, SSE); 64617071Sralph return (MBD_RESTARTED); 64716791Skarels } else if ((er2 & HPER2_BSE) && !ML11) { 6485726Sroot if (hpecc(mi, BSE)) 64911202Ssam return (MBD_RESTARTED); 65011202Ssam goto hard; 65116791Skarels } else if (MASKREG(er1) == HPER1_FER && RP06) { 65216791Skarels if (hpecc(mi, BSE)) 65316791Skarels return (MBD_RESTARTED); 65416791Skarels goto hard; 65517071Sralph } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 656*25198Skarels mi->mi_tab.b_errcnt >= 3) { 65716791Skarels if (hpecc(mi, ECC)) 65816791Skarels return (MBD_RESTARTED); 65916791Skarels /* else done */ 66024780Skarels } else if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE)) { 66124780Skarels /* 66224780Skarels * HCRC means the header is screwed up and the sector 66324780Skarels * might well exist in the bad sector table, 66424780Skarels * better check.... 66524780Skarels */ 66624780Skarels return (MBD_RESTARTED); 6672826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 66816791Skarels (ML11 && mi->mi_tab.b_errcnt > 15) || 6693102Swnj mbsr & MBSR_HARD || 6705858Swnj er1 & HPER1_HARD || 6715893Swnj (!ML11 && (er2 & HPER2_HARD))) { 6723706Sroot hard: 67317071Sralph if (bp->b_flags & B_BAD) 67417071Sralph bp->b_blkno = sc->sc_badbn; 67518411Skarels else { 67624738Sbloom bp->b_blkno = bp->b_blkno + btop(bp->b_bcount - 67718411Skarels MASKREG(-mi->mi_mba->mba_bcr)); 67818411Skarels if (er1 & (HPER1_DCK | HPER1_ECH)) 67918411Skarels bp->b_blkno--; 68018411Skarels } 6812925Swnj harderr(bp, "hp"); 6823271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6833271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6843706Sroot printf("er1=%b er2=%b", 68514145Shelge MASKREG(hpaddr->hper1), HPER1_BITS, 68614145Shelge MASKREG(hpaddr->hper2), HPER2_BITS); 68714134Shelge if (sc->sc_hdr) 68814134Shelge printf(" (hdr i/o)"); 6893706Sroot printf("\n"); 6902826Swnj bp->b_flags |= B_ERROR; 69117071Sralph bp->b_flags &= ~B_BAD; 6922826Swnj } else 6932826Swnj retry = 1; 6942826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 69516791Skarels if ((mi->mi_tab.b_errcnt & 07) == 4) { 6962826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 69710857Ssam sc->sc_recal = 1; 698*25198Skarels return (MBD_REPOSITION); 69921Sbill } 7002826Swnj } 7013706Sroot #ifdef HPDEBUG 7023289Swnj else 70310857Ssam if (hpdebug && sc->sc_recal) { 704*25198Skarels log(LOG_DEBUG, 705*25198Skarels "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n", 706*25198Skarels sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 7073289Swnj hpaddr->hper1, HPER1_BITS, 7083289Swnj hpaddr->hper2, HPER2_BITS); 7093289Swnj } 7103706Sroot #endif 71118411Skarels HPWAIT(mi, hpaddr); 712*25198Skarels if (retry) 7132892Swnj return (MBD_RETRY); 7143640Swnj if (mi->mi_tab.b_errcnt >= 16) { 7153093Swnj /* 7163093Swnj * This is fast and occurs rarely; we don't 7173093Swnj * bother with interrupts. 7183093Swnj */ 7192624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 72018411Skarels HPWAIT(mi, hpaddr); 7212383Swnj mbclrattn(mi); 72221Sbill } 723*25198Skarels if (mi->mi_tab.b_errcnt) 724*25198Skarels log(LOG_INFO, "hp%d%c: %d retries %sing sn%d\n", 725*25198Skarels hpunit(bp->b_dev), 'a'+(minor(bp->b_dev)&07), 726*25198Skarels mi->mi_tab.b_errcnt, 727*25198Skarels (bp->b_flags & B_READ) ? "read" : "writ", 728*25198Skarels (bp->b_flags & B_BAD) ? 729*25198Skarels sc->sc_badbn : bp->b_blkno + sc->sc_blkdone); 73017071Sralph if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 73117071Sralph return (MBD_RESTARTED); 73217071Sralph sc->sc_hdr = 0; 733*25198Skarels sc->sc_blkdone = 0; 73417071Sralph bp->b_resid = MASKREG(-mi->mi_mba->mba_bcr); 7355726Sroot if (!ML11) { 7365726Sroot hpaddr->hpof = HPOF_FMT22; 7375726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 7385726Sroot } 7392383Swnj return (MBD_DONE); 74021Sbill } 74121Sbill 74218411Skarels /* 74318411Skarels * Wait (for a bit) for a drive to come ready; 74418411Skarels * returns nonzero on success. 74518411Skarels */ 74618411Skarels hpwait(mi) 74718411Skarels register struct mba_device *mi; 74818411Skarels { 74918411Skarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 75018411Skarels register i = 100000; 75118411Skarels 75218411Skarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 75318411Skarels DELAY(10); 75418411Skarels if (i == 0) 75518411Skarels printf("hp%d: intr, not ready\n", mi->mi_unit); 75618411Skarels return (i); 75718411Skarels } 75818411Skarels 7597738Sroot hpread(dev, uio) 7602624Swnj dev_t dev; 7617738Sroot struct uio *uio; 76221Sbill { 76324738Sbloom register int unit = hpunit(dev); 76421Sbill 7652624Swnj if (unit >= NHP) 7668156Sroot return (ENXIO); 7678156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 76821Sbill } 76921Sbill 7707831Sroot hpwrite(dev, uio) 7712624Swnj dev_t dev; 7727831Sroot struct uio *uio; 77321Sbill { 77424738Sbloom register int unit = hpunit(dev); 77521Sbill 7762624Swnj if (unit >= NHP) 7778156Sroot return (ENXIO); 7788156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 77921Sbill } 78021Sbill 7815726Sroot /*ARGSUSED*/ 7827635Ssam hpioctl(dev, cmd, data, flag) 7835726Sroot dev_t dev; 7845726Sroot int cmd; 7857635Ssam caddr_t data; 7865726Sroot int flag; 7875726Sroot { 7885726Sroot 7895726Sroot switch (cmd) { 7907635Ssam 7915726Sroot case DKIOCHDR: /* do header read/write */ 79224738Sbloom hpsoftc[hpunit(dev)].sc_hdr = 1; 7938579Sroot return (0); 7945726Sroot 7955726Sroot default: 7968579Sroot return (ENXIO); 7975726Sroot } 7985726Sroot } 7995726Sroot 8003706Sroot hpecc(mi, flag) 8012978Swnj register struct mba_device *mi; 8023706Sroot int flag; 80321Sbill { 8042383Swnj register struct mba_regs *mbp = mi->mi_mba; 8052624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 8062383Swnj register struct buf *bp = mi->mi_tab.b_actf; 8073706Sroot register struct hpst *st = &hpst[mi->mi_type]; 80817071Sralph struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 8093706Sroot int npf, o; 8102383Swnj int bn, cn, tn, sn; 811914Sbill int bcr; 81221Sbill 81318411Skarels bcr = MASKREG(-mbp->mba_bcr); 81417071Sralph if (bp->b_flags & B_BAD) 8153706Sroot npf = bp->b_error; 8163706Sroot else 81718411Skarels npf = btop(bp->b_bcount - bcr); 818420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 81924738Sbloom bn = bp->b_blkno; 820420Sbill cn = bp->b_cylin; 82118411Skarels sn = bn%(st->nspc) + npf; 8222383Swnj tn = sn/st->nsect; 8232383Swnj sn %= st->nsect; 8242383Swnj cn += tn/st->ntrak; 8252383Swnj tn %= st->ntrak; 82624187Skarels bn += npf; 8273706Sroot switch (flag) { 82810856Ssam case ECC: { 8293706Sroot register int i; 8303706Sroot caddr_t addr; 8313706Sroot struct pte mpte; 8323706Sroot int bit, byte, mask; 8333706Sroot 8343706Sroot npf--; /* because block in error is previous block */ 83518411Skarels bn--; 83617071Sralph if (bp->b_flags & B_BAD) 83717071Sralph bn = sc->sc_badbn; 83824844Seric log(LOG_WARNING, "hp%d%c: soft ecc sn%d\n", hpunit(bp->b_dev), 83917071Sralph 'a'+(minor(bp->b_dev)&07), bn); 84011202Ssam mask = MASKREG(rp->hpec2); 84111202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 8423706Sroot bit = i&07; 8433706Sroot i = (i&~07)>>3; 8443706Sroot byte = i + o; 8453706Sroot while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 8463706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 8473706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 8483706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 8493706Sroot byte++; 8503706Sroot i++; 8513706Sroot bit -= 8; 8523706Sroot } 85318411Skarels if (bcr == 0) 8543706Sroot return (0); 8553847Sroot npf++; 8563706Sroot break; 8573706Sroot } 8583706Sroot 8593706Sroot case SSE: 8603706Sroot rp->hpof |= HPOF_SSEI; 86117071Sralph if (bp->b_flags & B_BAD) { 86217071Sralph bn = sc->sc_badbn; 86317071Sralph goto fixregs; 86417071Sralph } 8653706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8663706Sroot break; 8673706Sroot 8683706Sroot case BSE: 86917071Sralph if (rp->hpof & HPOF_SSEI) 87017071Sralph sn++; 8713706Sroot #ifdef HPBDEBUG 8723706Sroot if (hpbdebug) 873*25198Skarels log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8743706Sroot #endif 87517071Sralph if (bp->b_flags & B_BAD) 87617071Sralph return (0); 8773706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 87811202Ssam return (0); 8793706Sroot bp->b_flags |= B_BAD; 8803706Sroot bp->b_error = npf + 1; 88117071Sralph rp->hpof &= ~HPOF_SSEI; 8823706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 88317071Sralph sc->sc_badbn = bn; 88417071Sralph fixregs: 8853706Sroot cn = bn/st->nspc; 8863706Sroot sn = bn%st->nspc; 8873706Sroot tn = sn/st->nsect; 8883706Sroot sn %= st->nsect; 88924780Skarels mbp->mba_bcr = -(min(512, bp->b_bcount - (int)ptob(npf))); 8903706Sroot #ifdef HPBDEBUG 8913706Sroot if (hpbdebug) 892*25198Skarels log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn); 8933706Sroot #endif 8943706Sroot break; 8953706Sroot 8963706Sroot case CONT: 8973706Sroot #ifdef HPBDEBUG 8983706Sroot if (hpbdebug) 899*25198Skarels log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 9003706Sroot #endif 9013706Sroot bp->b_flags &= ~B_BAD; 90224780Skarels if ((int)ptob(npf) >= bp->b_bcount) 90324780Skarels return (0); 9043706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 9053706Sroot break; 9063706Sroot } 9073706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 90817071Sralph if (rp->hpof & HPOF_SSEI) 9092883Swnj sn++; 910420Sbill rp->hpdc = cn; 911420Sbill rp->hpda = (tn<<8) + sn; 912420Sbill mbp->mba_sr = -1; 9133706Sroot mbp->mba_var = (int)ptob(npf) + o; 9143706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 9153706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 916*25198Skarels sc->sc_blkdone = npf; 917420Sbill return (1); 91821Sbill } 9192362Swnj 9202362Swnj #define DBSIZE 20 9212362Swnj 9222362Swnj hpdump(dev) 9232362Swnj dev_t dev; 9242362Swnj { 9252978Swnj register struct mba_device *mi; 9262383Swnj register struct mba_regs *mba; 9272624Swnj struct hpdevice *hpaddr; 9282362Swnj char *start; 9292383Swnj int num, unit; 9302383Swnj register struct hpst *st; 9312362Swnj 9322362Swnj num = maxfree; 9332362Swnj start = 0; 93424738Sbloom unit = hpunit(dev); 9352827Swnj if (unit >= NHP) 9362827Swnj return (ENXIO); 9372383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 9382978Swnj mi = phys(hpinfo[unit],struct mba_device *); 9392827Swnj if (mi == 0 || mi->mi_alive == 0) 9402827Swnj return (ENXIO); 9412383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 9423102Swnj mba->mba_cr = MBCR_INIT; 9432624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 9443093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 9452624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 9462624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 9473093Swnj hpaddr->hpof = HPOF_FMT22; 9482362Swnj } 9492383Swnj st = &hpst[mi->mi_type]; 95024224Sbloom if (dumplo < 0) 9512827Swnj return (EINVAL); 95224224Sbloom if (dumplo + num >= st->sizes[minor(dev)&07].nblocks) 95324224Sbloom num = st->sizes[minor(dev)&07].nblocks - dumplo; 9542362Swnj while (num > 0) { 9552383Swnj register struct pte *hpte = mba->mba_map; 9562362Swnj register int i; 9572383Swnj int blk, cn, sn, tn; 9582362Swnj daddr_t bn; 9592362Swnj 9602362Swnj blk = num > DBSIZE ? DBSIZE : num; 9612362Swnj bn = dumplo + btop(start); 9622383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 9632383Swnj sn = bn%st->nspc; 9642383Swnj tn = sn/st->nsect; 9652383Swnj sn = sn%st->nsect; 9662362Swnj hpaddr->hpdc = cn; 9672362Swnj hpaddr->hpda = (tn << 8) + sn; 9682362Swnj for (i = 0; i < blk; i++) 9692362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 9702383Swnj mba->mba_sr = -1; 9712383Swnj mba->mba_bcr = -(blk*NBPG); 9722383Swnj mba->mba_var = 0; 9732624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 9743093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 97516791Skarels DELAY(10); 9763093Swnj if (hpaddr->hpds&HPDS_ERR) 9772827Swnj return (EIO); 9782362Swnj start += blk*NBPG; 9792362Swnj num -= blk; 9802362Swnj } 9812362Swnj return (0); 9822362Swnj } 98312506Ssam 98412506Ssam hpsize(dev) 98512506Ssam dev_t dev; 98612506Ssam { 98724738Sbloom int unit = hpunit(dev); 98812506Ssam struct mba_device *mi; 98912506Ssam struct hpst *st; 99012506Ssam 99112506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 99212506Ssam return (-1); 99312506Ssam st = &hpst[mi->mi_type]; 99412506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 99512506Ssam } 9961565Sbill #endif 997