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*26041Skarels * @(#)hp.c 6.18 (Berkeley) 02/02/86 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 */ 25525198Skarels 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); 49025198Skarels 49125198Skarels switch (sc->sc_recal) { 49225198Skarels 49325198Skarels case 1: 49425198Skarels HPWAIT(mi, hpaddr); 49525198Skarels hpaddr->hpdc = bp->b_cylin; 49625198Skarels hpaddr->hpcs1 = HP_SEEK|HP_GO; 49725198Skarels sc->sc_recal++; 49825198Skarels return (MBU_STARTED); 49925198Skarels case 2: 50025198Skarels break; 50125198Skarels } 50225198Skarels 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 } 52625198Skarels if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) { 52725198Skarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 52825198Skarels hpaddr->hpof = 52925198Skarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 53025198Skarels hpaddr->hpcs1 = HP_OFFSET|HP_GO; 53125198Skarels HPWAIT(mi, hpaddr); 53225198Skarels mbclrattn(mi); 53325198Skarels } 5342383Swnj return (MBU_DODATA); 53525198Skarels } 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; 57225198Skarels int sn, tn, cn; 57321Sbill 5745726Sroot if (ML11) 57525198Skarels hpaddr->hpda = bp->b_blkno + sc->sc_blkdone; 5765726Sroot else { 57725198Skarels if (bp->b_flags & B_BAD) { 57825198Skarels bn = sc->sc_badbn; 57925198Skarels cn = bn / st->nspc; 58025198Skarels } else { 58125198Skarels bn = bp->b_blkno; 58225198Skarels cn = bp->b_cylin; 58325198Skarels } 58425198Skarels sn = bn % st->nspc; 58525198Skarels if ((bp->b_flags & B_BAD) == 0) 58625198Skarels sn += sc->sc_blkdone; 58725198Skarels tn = sn / st->nsect; 5885726Sroot sn %= st->nsect; 58925198Skarels cn += tn / st->ntrak; 59025198Skarels tn %= st->ntrak; 5915726Sroot hpaddr->hpda = (tn << 8) + sn; 59225198Skarels hpaddr->hpdc = cn; 5935726Sroot } 594*26041Skarels mi->mi_tab.b_bdone = dbtob(sc->sc_blkdone); 59510857Ssam if (sc->sc_hdr) { 5965726Sroot if (bp->b_flags & B_READ) 5975726Sroot return (HP_RHDR|HP_GO); 5985726Sroot else 5995726Sroot return (HP_WHDR|HP_GO); 6005726Sroot } 6015726Sroot return (0); 60221Sbill } 60321Sbill 6043102Swnj hpdtint(mi, mbsr) 6052978Swnj register struct mba_device *mi; 6063102Swnj int mbsr; 60721Sbill { 6082624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 6092383Swnj register struct buf *bp = mi->mi_tab.b_actf; 61011315Ssam register struct hpst *st; 6115893Swnj register int er1, er2; 61210857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 61318411Skarels int retry = 0, i; 614*26041Skarels int npf; 615*26041Skarels daddr_t bn; 616*26041Skarels int bcr; 61721Sbill 618*26041Skarels bcr = MASKREG(-mi->mi_mba->mba_bcr); 61911315Ssam st = &hpst[mi->mi_type]; 6203102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 62114145Shelge er1 = hpaddr->hper1; 62214145Shelge er2 = hpaddr->hper2; 623*26041Skarels if (bp->b_flags & B_BAD) { 624*26041Skarels npf = bp->b_error; 625*26041Skarels bn = sc->sc_badbn; 626*26041Skarels } else { 627*26041Skarels npf = btop(bp->b_bcount - bcr); 628*26041Skarels if (er1 & (HPER1_DCK | HPER1_ECH)) 629*26041Skarels npf--; 630*26041Skarels bn = bp->b_blkno + npf; 631*26041Skarels } 63218411Skarels if (HPWAIT(mi, hpaddr) == 0) 63318411Skarels goto hard; 6343706Sroot #ifdef HPDEBUG 6353289Swnj if (hpdebug) { 6363706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 6373706Sroot 63825198Skarels log(LOG_DEBUG, 63925198Skarels "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n", 640*26041Skarels bp, bp->b_cylin, bn, sc->sc_blkdone, 64125198Skarels hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da)); 642*26041Skarels log(LOG_DEBUG, 643*26041Skarels "errcnt %d mbsr=%b er1=%b er2=%b bcr -%d\n", 64425198Skarels mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 64525198Skarels MASKREG(er1), HPER1_BITS, 646*26041Skarels MASKREG(er2), HPER2_BITS, bcr); 6473289Swnj } 6483706Sroot #endif 6495893Swnj if (er1 & HPER1_HCRC) { 6505858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 6515893Swnj er2 &= ~HPER2_BSE; 6525893Swnj } 65316791Skarels if (er1 & HPER1_WLE) { 65424844Seric log(LOG_WARNING, "hp%d: write locked\n", 65524738Sbloom hpunit(bp->b_dev)); 6562826Swnj bp->b_flags |= B_ERROR; 65716791Skarels } else if (sc->sc_hdr) { 65816791Skarels goto hard; 65917071Sralph } else if (RM80 && er2&HPER2_SSE) { 66017071Sralph (void) hpecc(mi, SSE); 66117071Sralph return (MBD_RESTARTED); 66216791Skarels } else if ((er2 & HPER2_BSE) && !ML11) { 6635726Sroot if (hpecc(mi, BSE)) 66411202Ssam return (MBD_RESTARTED); 66511202Ssam goto hard; 66616791Skarels } else if (MASKREG(er1) == HPER1_FER && RP06) { 66716791Skarels if (hpecc(mi, BSE)) 66816791Skarels return (MBD_RESTARTED); 66916791Skarels goto hard; 67017071Sralph } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 67125198Skarels mi->mi_tab.b_errcnt >= 3) { 67216791Skarels if (hpecc(mi, ECC)) 67316791Skarels return (MBD_RESTARTED); 67425398Skarels /* 67525398Skarels * ECC corrected. Only log retries below 67625398Skarels * if we got errors other than soft ECC 67725398Skarels * (as indicated by additional retries). 67825398Skarels */ 67925398Skarels if (mi->mi_tab.b_errcnt == 3) 68025398Skarels mi->mi_tab.b_errcnt = 0; 68124780Skarels } else if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE)) { 68224780Skarels /* 68324780Skarels * HCRC means the header is screwed up and the sector 68424780Skarels * might well exist in the bad sector table, 68524780Skarels * better check.... 68624780Skarels */ 68724780Skarels return (MBD_RESTARTED); 6882826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 68916791Skarels (ML11 && mi->mi_tab.b_errcnt > 15) || 6903102Swnj mbsr & MBSR_HARD || 6915858Swnj er1 & HPER1_HARD || 6925893Swnj (!ML11 && (er2 & HPER2_HARD))) { 6933706Sroot hard: 694*26041Skarels bp->b_blkno = bn; /* XXX */ 6952925Swnj harderr(bp, "hp"); 6963271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6973271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 6983706Sroot printf("er1=%b er2=%b", 69914145Shelge MASKREG(hpaddr->hper1), HPER1_BITS, 70014145Shelge MASKREG(hpaddr->hper2), HPER2_BITS); 70114134Shelge if (sc->sc_hdr) 70214134Shelge printf(" (hdr i/o)"); 7033706Sroot printf("\n"); 7042826Swnj bp->b_flags |= B_ERROR; 70517071Sralph bp->b_flags &= ~B_BAD; 7062826Swnj } else 7072826Swnj retry = 1; 7082826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 70925506Skarels if (retry && (mi->mi_tab.b_errcnt & 07) == 4) { 7102826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 71110857Ssam sc->sc_recal = 1; 71225198Skarels return (MBD_REPOSITION); 71321Sbill } 7142826Swnj } 7153706Sroot #ifdef HPDEBUG 7163289Swnj else 71710857Ssam if (hpdebug && sc->sc_recal) { 71825198Skarels log(LOG_DEBUG, 71925198Skarels "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n", 72025198Skarels sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 7213289Swnj hpaddr->hper1, HPER1_BITS, 7223289Swnj hpaddr->hper2, HPER2_BITS); 7233289Swnj } 7243706Sroot #endif 72518411Skarels HPWAIT(mi, hpaddr); 72625198Skarels if (retry) 7272892Swnj return (MBD_RETRY); 7283640Swnj if (mi->mi_tab.b_errcnt >= 16) { 7293093Swnj /* 7303093Swnj * This is fast and occurs rarely; we don't 7313093Swnj * bother with interrupts. 7323093Swnj */ 7332624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 73418411Skarels HPWAIT(mi, hpaddr); 7352383Swnj mbclrattn(mi); 73621Sbill } 73725398Skarels if (mi->mi_tab.b_errcnt && (bp->b_flags & B_ERROR) == 0) 73825198Skarels log(LOG_INFO, "hp%d%c: %d retries %sing sn%d\n", 73925198Skarels hpunit(bp->b_dev), 'a'+(minor(bp->b_dev)&07), 74025198Skarels mi->mi_tab.b_errcnt, 74125198Skarels (bp->b_flags & B_READ) ? "read" : "writ", 74225198Skarels (bp->b_flags & B_BAD) ? 74325198Skarels sc->sc_badbn : bp->b_blkno + sc->sc_blkdone); 74417071Sralph if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 74517071Sralph return (MBD_RESTARTED); 74617071Sralph sc->sc_hdr = 0; 74725198Skarels sc->sc_blkdone = 0; 748*26041Skarels bp->b_resid = bcr; 7495726Sroot if (!ML11) { 7505726Sroot hpaddr->hpof = HPOF_FMT22; 7515726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 7525726Sroot } 7532383Swnj return (MBD_DONE); 75421Sbill } 75521Sbill 75618411Skarels /* 75718411Skarels * Wait (for a bit) for a drive to come ready; 75818411Skarels * returns nonzero on success. 75918411Skarels */ 76018411Skarels hpwait(mi) 76118411Skarels register struct mba_device *mi; 76218411Skarels { 76318411Skarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 76418411Skarels register i = 100000; 76518411Skarels 76618411Skarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 76718411Skarels DELAY(10); 76818411Skarels if (i == 0) 76918411Skarels printf("hp%d: intr, not ready\n", mi->mi_unit); 77018411Skarels return (i); 77118411Skarels } 77218411Skarels 7737738Sroot hpread(dev, uio) 7742624Swnj dev_t dev; 7757738Sroot struct uio *uio; 77621Sbill { 77724738Sbloom register int unit = hpunit(dev); 77821Sbill 7792624Swnj if (unit >= NHP) 7808156Sroot return (ENXIO); 7818156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 78221Sbill } 78321Sbill 7847831Sroot hpwrite(dev, uio) 7852624Swnj dev_t dev; 7867831Sroot struct uio *uio; 78721Sbill { 78824738Sbloom register int unit = hpunit(dev); 78921Sbill 7902624Swnj if (unit >= NHP) 7918156Sroot return (ENXIO); 7928156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 79321Sbill } 79421Sbill 7955726Sroot /*ARGSUSED*/ 7967635Ssam hpioctl(dev, cmd, data, flag) 7975726Sroot dev_t dev; 7985726Sroot int cmd; 7997635Ssam caddr_t data; 8005726Sroot int flag; 8015726Sroot { 8025726Sroot 8035726Sroot switch (cmd) { 8047635Ssam 8055726Sroot case DKIOCHDR: /* do header read/write */ 80624738Sbloom hpsoftc[hpunit(dev)].sc_hdr = 1; 8078579Sroot return (0); 8085726Sroot 8095726Sroot default: 8108579Sroot return (ENXIO); 8115726Sroot } 8125726Sroot } 8135726Sroot 8143706Sroot hpecc(mi, flag) 8152978Swnj register struct mba_device *mi; 8163706Sroot int flag; 81721Sbill { 8182383Swnj register struct mba_regs *mbp = mi->mi_mba; 8192624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 8202383Swnj register struct buf *bp = mi->mi_tab.b_actf; 8213706Sroot register struct hpst *st = &hpst[mi->mi_type]; 82217071Sralph struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 8233706Sroot int npf, o; 8242383Swnj int bn, cn, tn, sn; 825914Sbill int bcr; 82621Sbill 82718411Skarels bcr = MASKREG(-mbp->mba_bcr); 82817071Sralph if (bp->b_flags & B_BAD) 8293706Sroot npf = bp->b_error; 8303706Sroot else 831*26041Skarels npf = btodb(bp->b_bcount - bcr); 832420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 83324738Sbloom bn = bp->b_blkno; 834420Sbill cn = bp->b_cylin; 83518411Skarels sn = bn%(st->nspc) + npf; 8362383Swnj tn = sn/st->nsect; 8372383Swnj sn %= st->nsect; 8382383Swnj cn += tn/st->ntrak; 8392383Swnj tn %= st->ntrak; 84024187Skarels bn += npf; 8413706Sroot switch (flag) { 84210856Ssam case ECC: { 8433706Sroot register int i; 8443706Sroot caddr_t addr; 8453706Sroot struct pte mpte; 8463706Sroot int bit, byte, mask; 8473706Sroot 8483706Sroot npf--; /* because block in error is previous block */ 84918411Skarels bn--; 85017071Sralph if (bp->b_flags & B_BAD) 85117071Sralph bn = sc->sc_badbn; 85224844Seric log(LOG_WARNING, "hp%d%c: soft ecc sn%d\n", hpunit(bp->b_dev), 85317071Sralph 'a'+(minor(bp->b_dev)&07), bn); 85411202Ssam mask = MASKREG(rp->hpec2); 85511202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 8563706Sroot bit = i&07; 8573706Sroot i = (i&~07)>>3; 8583706Sroot byte = i + o; 859*26041Skarels while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) { 8603706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 8613706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 8623706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 8633706Sroot byte++; 8643706Sroot i++; 8653706Sroot bit -= 8; 8663706Sroot } 86718411Skarels if (bcr == 0) 8683706Sroot return (0); 8693847Sroot npf++; 8703706Sroot break; 8713706Sroot } 8723706Sroot 8733706Sroot case SSE: 8743706Sroot rp->hpof |= HPOF_SSEI; 87517071Sralph if (bp->b_flags & B_BAD) { 87617071Sralph bn = sc->sc_badbn; 87717071Sralph goto fixregs; 87817071Sralph } 8793706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8803706Sroot break; 8813706Sroot 8823706Sroot case BSE: 88317071Sralph if (rp->hpof & HPOF_SSEI) 88417071Sralph sn++; 8853706Sroot #ifdef HPBDEBUG 8863706Sroot if (hpbdebug) 88725198Skarels log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8883706Sroot #endif 88917071Sralph if (bp->b_flags & B_BAD) 89017071Sralph return (0); 8913706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 89211202Ssam return (0); 8933706Sroot bp->b_flags |= B_BAD; 8943706Sroot bp->b_error = npf + 1; 89517071Sralph rp->hpof &= ~HPOF_SSEI; 8963706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 89717071Sralph sc->sc_badbn = bn; 89817071Sralph fixregs: 8993706Sroot cn = bn/st->nspc; 9003706Sroot sn = bn%st->nspc; 9013706Sroot tn = sn/st->nsect; 9023706Sroot sn %= st->nsect; 90324780Skarels mbp->mba_bcr = -(min(512, bp->b_bcount - (int)ptob(npf))); 9043706Sroot #ifdef HPBDEBUG 9053706Sroot if (hpbdebug) 90625198Skarels log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn); 9073706Sroot #endif 9083706Sroot break; 9093706Sroot 9103706Sroot case CONT: 9113706Sroot #ifdef HPBDEBUG 9123706Sroot if (hpbdebug) 91325198Skarels log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 9143706Sroot #endif 9153706Sroot bp->b_flags &= ~B_BAD; 91624780Skarels if ((int)ptob(npf) >= bp->b_bcount) 91724780Skarels return (0); 9183706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 9193706Sroot break; 9203706Sroot } 9213706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 92217071Sralph if (rp->hpof & HPOF_SSEI) 9232883Swnj sn++; 924420Sbill rp->hpdc = cn; 925420Sbill rp->hpda = (tn<<8) + sn; 926420Sbill mbp->mba_sr = -1; 9273706Sroot mbp->mba_var = (int)ptob(npf) + o; 9283706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 9293706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 93025198Skarels sc->sc_blkdone = npf; 931420Sbill return (1); 93221Sbill } 9332362Swnj 9342362Swnj #define DBSIZE 20 9352362Swnj 9362362Swnj hpdump(dev) 9372362Swnj dev_t dev; 9382362Swnj { 9392978Swnj register struct mba_device *mi; 9402383Swnj register struct mba_regs *mba; 9412624Swnj struct hpdevice *hpaddr; 9422362Swnj char *start; 9432383Swnj int num, unit; 9442383Swnj register struct hpst *st; 9452362Swnj 9462362Swnj num = maxfree; 9472362Swnj start = 0; 94824738Sbloom unit = hpunit(dev); 9492827Swnj if (unit >= NHP) 9502827Swnj return (ENXIO); 9512383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 9522978Swnj mi = phys(hpinfo[unit],struct mba_device *); 9532827Swnj if (mi == 0 || mi->mi_alive == 0) 9542827Swnj return (ENXIO); 9552383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 9563102Swnj mba->mba_cr = MBCR_INIT; 9572624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 9583093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 9592624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 9602624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 9613093Swnj hpaddr->hpof = HPOF_FMT22; 9622362Swnj } 9632383Swnj st = &hpst[mi->mi_type]; 96424224Sbloom if (dumplo < 0) 9652827Swnj return (EINVAL); 96624224Sbloom if (dumplo + num >= st->sizes[minor(dev)&07].nblocks) 96724224Sbloom num = st->sizes[minor(dev)&07].nblocks - dumplo; 9682362Swnj while (num > 0) { 9692383Swnj register struct pte *hpte = mba->mba_map; 9702362Swnj register int i; 9712383Swnj int blk, cn, sn, tn; 9722362Swnj daddr_t bn; 9732362Swnj 9742362Swnj blk = num > DBSIZE ? DBSIZE : num; 9752362Swnj bn = dumplo + btop(start); 9762383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 9772383Swnj sn = bn%st->nspc; 9782383Swnj tn = sn/st->nsect; 9792383Swnj sn = sn%st->nsect; 9802362Swnj hpaddr->hpdc = cn; 9812362Swnj hpaddr->hpda = (tn << 8) + sn; 9822362Swnj for (i = 0; i < blk; i++) 9832362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 9842383Swnj mba->mba_sr = -1; 9852383Swnj mba->mba_bcr = -(blk*NBPG); 9862383Swnj mba->mba_var = 0; 9872624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 9883093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 98916791Skarels DELAY(10); 9903093Swnj if (hpaddr->hpds&HPDS_ERR) 9912827Swnj return (EIO); 9922362Swnj start += blk*NBPG; 9932362Swnj num -= blk; 9942362Swnj } 9952362Swnj return (0); 9962362Swnj } 99712506Ssam 99812506Ssam hpsize(dev) 99912506Ssam dev_t dev; 100012506Ssam { 100124738Sbloom int unit = hpunit(dev); 100212506Ssam struct mba_device *mi; 100312506Ssam struct hpst *st; 100412506Ssam 100512506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 100612506Ssam return (-1); 100712506Ssam st = &hpst[mi->mi_type]; 100812506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 100912506Ssam } 10101565Sbill #endif 1011