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*26375Skarels * @(#)hp.c 6.20 (Berkeley) 02/23/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) 268*26375Skarels #ifdef lint 269*26375Skarels #define HPWAIT(mi, addr) (hpwait(mi)) 270*26375Skarels #else 27118411Skarels #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi)) 272*26375Skarels #endif 27311202Ssam 2742978Swnj /*ARGSUSED*/ 2752978Swnj hpattach(mi, slave) 27610734Ssam register struct mba_device *mi; 2772604Swnj { 27810734Ssam 27910734Ssam mi->mi_type = hpmaptype(mi); 28010734Ssam if (!ML11 && mi->mi_dk >= 0) { 28110734Ssam struct hpst *st = &hpst[mi->mi_type]; 28210734Ssam 28310734Ssam dk_mspw[mi->mi_dk] = 1.0 / 60 / (st->nsect * 256); 28410734Ssam } 28510734Ssam } 28610734Ssam 28710734Ssam /* 28810734Ssam * Map apparent MASSBUS drive type into manufacturer 28910734Ssam * specific configuration. For SI controllers this is done 29010734Ssam * based on codes in the serial number register. For 29110734Ssam * EMULEX controllers, the track and sector attributes are 29210734Ssam * used when the drive type is an RM02 (not supported by DEC). 29310734Ssam */ 29410734Ssam hpmaptype(mi) 29510734Ssam register struct mba_device *mi; 29610734Ssam { 2976927Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 29810734Ssam register int type = mi->mi_type; 2996927Ssam 3006927Ssam /* 30111281Ssam * Model-byte processing for SI controllers. 3026927Ssam * NB: Only deals with RM03 and RM05 emulations. 3036927Ssam */ 30410734Ssam if (type == HPDT_RM03 || type == HPDT_RM05) { 30510734Ssam int hpsn = hpaddr->hpsn; 3066927Ssam 3076927Ssam if ((hpsn & SIMB_LU) != mi->mi_drive) 30810734Ssam return (type); 3096927Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 3106927Ssam 3116927Ssam case SI9775D: 31211281Ssam printf("hp%d: 9775 (direct)\n", mi->mi_unit); 31310734Ssam type = HPDT_9775; 3146927Ssam break; 3156927Ssam 3166927Ssam case SI9730D: 31711281Ssam printf("hp%d: 9730 (direct)\n", mi->mi_unit); 31810734Ssam type = HPDT_9730; 3196927Ssam break; 3206927Ssam 3217035Swnj /* 32211281Ssam * Beware, since the only SI controller we 32311281Ssam * have has a 9300 instead of a 9766, we map the 32411281Ssam * drive type into the 9300. This means that 32511281Ssam * on a 9766 you lose the last 8 cylinders (argh). 3267035Swnj */ 3276927Ssam case SI9766: 32811281Ssam printf("hp%d: 9300\n", mi->mi_unit); 32911281Ssam type = HPDT_9300; 3306927Ssam break; 3316927Ssam 3326927Ssam case SI9762: 3336927Ssam printf("hp%d: 9762\n", mi->mi_unit); 33410734Ssam type = HPDT_RM03; 3356927Ssam break; 33611281Ssam 33711281Ssam case SICAPD: 33811281Ssam printf("hp%d: capricorn\n", mi->mi_unit); 33911281Ssam type = HPDT_CAPRICORN; 34011281Ssam break; 34111281Ssam 34211281Ssam case SI9751D: 34311281Ssam printf("hp%d: eagle\n", mi->mi_unit); 34411281Ssam type = HPDT_EAGLE; 34511281Ssam break; 3466927Ssam } 34710734Ssam return (type); 34810734Ssam } 3496927Ssam 3506927Ssam /* 35110734Ssam * EMULEX SC750 or SC780. Poke the holding register. 3526927Ssam */ 35310734Ssam if (type == HPDT_RM02) { 35410734Ssam int ntracks, nsectors; 35510734Ssam 35611315Ssam hpaddr->hpof = HPOF_FMT22; 35711315Ssam mbclrattn(mi); 3586927Ssam hpaddr->hpcs1 = HP_NOP; 3596927Ssam hpaddr->hphr = HPHR_MAXTRAK; 36011202Ssam ntracks = MASKREG(hpaddr->hphr) + 1; 36110055Ssam if (ntracks == 16) { 3626927Ssam printf("hp%d: capricorn\n", mi->mi_unit); 36310734Ssam type = HPDT_CAPRICORN; 36410734Ssam goto done; 36510734Ssam } 36613157Ssam if (ntracks == 19) { 36713157Ssam printf("hp%d: 9300\n", mi->mi_unit); 36813157Ssam type = HPDT_9300; 36913157Ssam goto done; 37013157Ssam } 37110734Ssam hpaddr->hpcs1 = HP_NOP; 37210734Ssam hpaddr->hphr = HPHR_MAXSECT; 37311202Ssam nsectors = MASKREG(hpaddr->hphr) + 1; 37411315Ssam if (ntracks == 20 && nsectors == 48) { 37510734Ssam type = HPDT_EAGLE; 37611212Ssam printf("hp%d: eagle\n", mi->mi_unit); 37711315Ssam goto done; 37810734Ssam } 37911315Ssam printf("hp%d: ntracks %d, nsectors %d: unknown device\n", 38013157Ssam mi->mi_unit, ntracks, nsectors); 38110734Ssam done: 3826927Ssam hpaddr->hpcs1 = HP_DCLR|HP_GO; 38311315Ssam mbclrattn(mi); /* conservative */ 38410734Ssam return (type); 38510734Ssam } 3866927Ssam 38710734Ssam /* 38810734Ssam * Map all ML11's to the same type. Also calculate 38910734Ssam * transfer rates based on device characteristics. 39010734Ssam */ 39110734Ssam if (type == HPDT_ML11A || type == HPDT_ML11B) { 39210857Ssam register struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 39310857Ssam register int trt; 3942604Swnj 39510857Ssam sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 3965726Sroot if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 39710857Ssam sc->sc_mlsize >>= 2; 3985726Sroot if (mi->mi_dk >= 0) { 3995726Sroot trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 4005726Sroot dk_mspw[mi->mi_dk] = 1.0 / (1<<(20-trt)); 4015726Sroot } 40210734Ssam type = HPDT_ML11A; 4036927Ssam } 40410734Ssam return (type); 4052604Swnj } 4062604Swnj 4078579Sroot hpopen(dev) 4088579Sroot dev_t dev; 4098579Sroot { 41024738Sbloom register int unit = hpunit(dev); 4118579Sroot register struct mba_device *mi; 4128579Sroot 4138579Sroot if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 4148579Sroot return (ENXIO); 4158579Sroot return (0); 4168579Sroot } 4178579Sroot 41821Sbill hpstrategy(bp) 4192383Swnj register struct buf *bp; 42021Sbill { 4212978Swnj register struct mba_device *mi; 4222383Swnj register struct hpst *st; 4232383Swnj register int unit; 42424783Skarels long sz; 4252383Swnj int xunit = minor(bp->b_dev) & 07; 4265432Sroot int s; 42721Sbill 42821Sbill sz = bp->b_bcount; 42921Sbill sz = (sz+511) >> 9; 43024738Sbloom unit = hpunit(bp->b_dev); 43124738Sbloom if (unit >= NHP) { 43224738Sbloom bp->b_error = ENXIO; 4332383Swnj goto bad; 43424738Sbloom } 4352383Swnj mi = hpinfo[unit]; 43624738Sbloom if (mi == 0 || mi->mi_alive == 0) { 43724738Sbloom bp->b_error = ENXIO; 4382383Swnj goto bad; 43924738Sbloom } 4402383Swnj st = &hpst[mi->mi_type]; 4415726Sroot if (ML11) { 44210857Ssam struct hpsoftc *sc = &hpsoftc[unit]; 44310857Ssam 4445726Sroot if (bp->b_blkno < 0 || 44524738Sbloom bp->b_blkno+sz > sc->sc_mlsize) { 44624783Skarels if (bp->b_blkno == sc->sc_mlsize) { 44724783Skarels bp->b_resid = bp->b_bcount; 44824738Sbloom goto done; 44924783Skarels } 45024738Sbloom bp->b_error = EINVAL; 4515726Sroot goto bad; 45224738Sbloom } 4535726Sroot bp->b_cylin = 0; 4545726Sroot } else { 4555726Sroot if (bp->b_blkno < 0 || 45624783Skarels bp->b_blkno+sz > st->sizes[xunit].nblocks) { 45724783Skarels if (bp->b_blkno == st->sizes[xunit].nblocks) { 45824783Skarels bp->b_resid = bp->b_bcount; 45924738Sbloom goto done; 46024783Skarels } 46124738Sbloom bp->b_error = EINVAL; 4625726Sroot goto bad; 46324738Sbloom } 46424783Skarels bp->b_cylin = bp->b_blkno/st->nspc + st->sizes[xunit].cyloff; 4655726Sroot } 4665432Sroot s = spl5(); 4672383Swnj disksort(&mi->mi_tab, bp); 4682383Swnj if (mi->mi_tab.b_active == 0) 4692383Swnj mbustart(mi); 4705432Sroot splx(s); 4712383Swnj return; 4722383Swnj 4732383Swnj bad: 4742383Swnj bp->b_flags |= B_ERROR; 47524738Sbloom done: 4762383Swnj iodone(bp); 4772383Swnj return; 47821Sbill } 47921Sbill 4802383Swnj hpustart(mi) 4812978Swnj register struct mba_device *mi; 48221Sbill { 4832624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 4842383Swnj register struct buf *bp = mi->mi_tab.b_actf; 48511315Ssam register struct hpst *st; 48610857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 48721Sbill daddr_t bn; 48816791Skarels int sn, tn, dist; 48921Sbill 49011315Ssam st = &hpst[mi->mi_type]; 4913706Sroot hpaddr->hpcs1 = 0; 4922624Swnj if ((hpaddr->hpcs1&HP_DVA) == 0) 4932383Swnj return (MBU_BUSY); 49425198Skarels 49525198Skarels switch (sc->sc_recal) { 49625198Skarels 49725198Skarels case 1: 498*26375Skarels (void)HPWAIT(mi, hpaddr); 49925198Skarels hpaddr->hpdc = bp->b_cylin; 50025198Skarels hpaddr->hpcs1 = HP_SEEK|HP_GO; 50125198Skarels sc->sc_recal++; 50225198Skarels return (MBU_STARTED); 50325198Skarels case 2: 50425198Skarels break; 50525198Skarels } 50625198Skarels sc->sc_recal = 0; 50710857Ssam if ((hpaddr->hpds & HPDS_VV) == 0 || !sc->sc_hpinit) { 5083706Sroot struct buf *bbp = &bhpbuf[mi->mi_unit]; 5093706Sroot 51010857Ssam sc->sc_hpinit = 1; 5112624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 5123140Swnj if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 5133140Swnj printf("DCLR attn\n"); 5142624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 5155726Sroot if (!ML11) 5165726Sroot hpaddr->hpof = HPOF_FMT22; 5173140Swnj mbclrattn(mi); 5185726Sroot if (!ML11) { 5195726Sroot bbp->b_flags = B_READ|B_BUSY; 5205726Sroot bbp->b_dev = bp->b_dev; 5215726Sroot bbp->b_bcount = 512; 5225726Sroot bbp->b_un.b_addr = (caddr_t)&hpbad[mi->mi_unit]; 5235726Sroot bbp->b_blkno = st->ncyl*st->nspc - st->nsect; 5245726Sroot bbp->b_cylin = st->ncyl - 1; 5255726Sroot mi->mi_tab.b_actf = bbp; 5265726Sroot bbp->av_forw = bp; 5275726Sroot bp = bbp; 5285726Sroot } 52921Sbill } 53025198Skarels if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) { 53125198Skarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 53225198Skarels hpaddr->hpof = 53325198Skarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 53425198Skarels hpaddr->hpcs1 = HP_OFFSET|HP_GO; 535*26375Skarels (void)HPWAIT(mi, hpaddr); 53625198Skarels mbclrattn(mi); 53725198Skarels } 5382383Swnj return (MBU_DODATA); 53925198Skarels } 5405726Sroot if (ML11) 5415726Sroot return (MBU_DODATA); 5423093Swnj if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 5432383Swnj return (MBU_DODATA); 54424738Sbloom bn = bp->b_blkno; 54516791Skarels sn = bn % st->nspc; 54616791Skarels tn = sn / st->nsect; 54716791Skarels sn = sn % st->nsect; 54811202Ssam if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 54910908Ssam if (sc->sc_doseeks) 5502383Swnj return (MBU_DODATA); 55116225Skarels dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1; 5522383Swnj if (dist < 0) 5532383Swnj dist += st->nsect; 55416225Skarels if (dist > st->maxdist || dist < st->mindist) 5552383Swnj return (MBU_DODATA); 5562614Swnj } else 5572614Swnj hpaddr->hpdc = bp->b_cylin; 55810908Ssam if (sc->sc_doseeks) 5592624Swnj hpaddr->hpcs1 = HP_SEEK|HP_GO; 560305Sbill else { 56116225Skarels sn = (sn + st->nsect - st->sdist) % st->nsect; 56216791Skarels hpaddr->hpda = (tn << 8) + sn; 5632624Swnj hpaddr->hpcs1 = HP_SEARCH|HP_GO; 564305Sbill } 5652383Swnj return (MBU_STARTED); 56621Sbill } 56721Sbill 5682383Swnj hpstart(mi) 5692978Swnj register struct mba_device *mi; 57021Sbill { 5712624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 5722383Swnj register struct buf *bp = mi->mi_tab.b_actf; 5732383Swnj register struct hpst *st = &hpst[mi->mi_type]; 57410857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 57521Sbill daddr_t bn; 57625198Skarels int sn, tn, cn; 57721Sbill 5785726Sroot if (ML11) 57925198Skarels hpaddr->hpda = bp->b_blkno + sc->sc_blkdone; 5805726Sroot else { 58125198Skarels if (bp->b_flags & B_BAD) { 58225198Skarels bn = sc->sc_badbn; 58325198Skarels cn = bn / st->nspc; 58425198Skarels } else { 58525198Skarels bn = bp->b_blkno; 58625198Skarels cn = bp->b_cylin; 58725198Skarels } 58825198Skarels sn = bn % st->nspc; 58925198Skarels if ((bp->b_flags & B_BAD) == 0) 59025198Skarels sn += sc->sc_blkdone; 59125198Skarels tn = sn / st->nsect; 5925726Sroot sn %= st->nsect; 59325198Skarels cn += tn / st->ntrak; 59425198Skarels tn %= st->ntrak; 5955726Sroot hpaddr->hpda = (tn << 8) + sn; 59625198Skarels hpaddr->hpdc = cn; 5975726Sroot } 59826041Skarels mi->mi_tab.b_bdone = dbtob(sc->sc_blkdone); 59910857Ssam if (sc->sc_hdr) { 6005726Sroot if (bp->b_flags & B_READ) 6015726Sroot return (HP_RHDR|HP_GO); 6025726Sroot else 6035726Sroot return (HP_WHDR|HP_GO); 6045726Sroot } 6055726Sroot return (0); 60621Sbill } 60721Sbill 6083102Swnj hpdtint(mi, mbsr) 6092978Swnj register struct mba_device *mi; 6103102Swnj int mbsr; 61121Sbill { 6122624Swnj register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 6132383Swnj register struct buf *bp = mi->mi_tab.b_actf; 6145893Swnj register int er1, er2; 61510857Ssam struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 61626289Skarels int retry = 0; 61726041Skarels int npf; 61826041Skarels daddr_t bn; 61926041Skarels int bcr; 62021Sbill 62126041Skarels bcr = MASKREG(-mi->mi_mba->mba_bcr); 6223102Swnj if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 62314145Shelge er1 = hpaddr->hper1; 62414145Shelge er2 = hpaddr->hper2; 62526041Skarels if (bp->b_flags & B_BAD) { 62626041Skarels npf = bp->b_error; 62726041Skarels bn = sc->sc_badbn; 62826041Skarels } else { 62926041Skarels npf = btop(bp->b_bcount - bcr); 63026041Skarels if (er1 & (HPER1_DCK | HPER1_ECH)) 63126041Skarels npf--; 63226041Skarels bn = bp->b_blkno + npf; 63326041Skarels } 63418411Skarels if (HPWAIT(mi, hpaddr) == 0) 63518411Skarels goto hard; 6363706Sroot #ifdef HPDEBUG 6373289Swnj if (hpdebug) { 6383706Sroot int dc = hpaddr->hpdc, da = hpaddr->hpda; 6393706Sroot 64025198Skarels log(LOG_DEBUG, 64125198Skarels "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n", 64226041Skarels bp, bp->b_cylin, bn, sc->sc_blkdone, 64325198Skarels hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da)); 64426041Skarels log(LOG_DEBUG, 64526041Skarels "errcnt %d mbsr=%b er1=%b er2=%b bcr -%d\n", 64625198Skarels mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 64725198Skarels MASKREG(er1), HPER1_BITS, 64826041Skarels MASKREG(er2), HPER2_BITS, bcr); 6493289Swnj } 6503706Sroot #endif 6515893Swnj if (er1 & HPER1_HCRC) { 6525858Swnj er1 &= ~(HPER1_HCE|HPER1_FER); 6535893Swnj er2 &= ~HPER2_BSE; 6545893Swnj } 65516791Skarels if (er1 & HPER1_WLE) { 65624844Seric log(LOG_WARNING, "hp%d: write locked\n", 65724738Sbloom hpunit(bp->b_dev)); 6582826Swnj bp->b_flags |= B_ERROR; 65916791Skarels } else if (sc->sc_hdr) { 66016791Skarels goto hard; 66117071Sralph } else if (RM80 && er2&HPER2_SSE) { 66217071Sralph (void) hpecc(mi, SSE); 66317071Sralph return (MBD_RESTARTED); 66416791Skarels } else if ((er2 & HPER2_BSE) && !ML11) { 6655726Sroot if (hpecc(mi, BSE)) 66611202Ssam return (MBD_RESTARTED); 66711202Ssam goto hard; 66816791Skarels } else if (MASKREG(er1) == HPER1_FER && RP06) { 66916791Skarels if (hpecc(mi, BSE)) 67016791Skarels return (MBD_RESTARTED); 67116791Skarels goto hard; 67217071Sralph } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 67325198Skarels mi->mi_tab.b_errcnt >= 3) { 67416791Skarels if (hpecc(mi, ECC)) 67516791Skarels return (MBD_RESTARTED); 67625398Skarels /* 67725398Skarels * ECC corrected. Only log retries below 67825398Skarels * if we got errors other than soft ECC 67925398Skarels * (as indicated by additional retries). 68025398Skarels */ 68125398Skarels if (mi->mi_tab.b_errcnt == 3) 68225398Skarels mi->mi_tab.b_errcnt = 0; 68324780Skarels } else if ((er1 & HPER1_HCRC) && !ML11 && hpecc(mi, BSE)) { 68424780Skarels /* 68524780Skarels * HCRC means the header is screwed up and the sector 68624780Skarels * might well exist in the bad sector table, 68724780Skarels * better check.... 68824780Skarels */ 68924780Skarels return (MBD_RESTARTED); 6902826Swnj } else if (++mi->mi_tab.b_errcnt > 27 || 69116791Skarels (ML11 && mi->mi_tab.b_errcnt > 15) || 6923102Swnj mbsr & MBSR_HARD || 6935858Swnj er1 & HPER1_HARD || 6945893Swnj (!ML11 && (er2 & HPER2_HARD))) { 6953706Sroot hard: 69626041Skarels bp->b_blkno = bn; /* XXX */ 6972925Swnj harderr(bp, "hp"); 6983271Swnj if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 6993271Swnj printf("mbsr=%b ", mbsr, mbsr_bits); 7003706Sroot printf("er1=%b er2=%b", 70114145Shelge MASKREG(hpaddr->hper1), HPER1_BITS, 70214145Shelge MASKREG(hpaddr->hper2), HPER2_BITS); 70314134Shelge if (sc->sc_hdr) 70414134Shelge printf(" (hdr i/o)"); 7053706Sroot printf("\n"); 7062826Swnj bp->b_flags |= B_ERROR; 70717071Sralph bp->b_flags &= ~B_BAD; 7082826Swnj } else 7092826Swnj retry = 1; 7102826Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 71125506Skarels if (retry && (mi->mi_tab.b_errcnt & 07) == 4) { 7122826Swnj hpaddr->hpcs1 = HP_RECAL|HP_GO; 71310857Ssam sc->sc_recal = 1; 71425198Skarels return (MBD_REPOSITION); 71521Sbill } 7162826Swnj } 7173706Sroot #ifdef HPDEBUG 7183289Swnj else 71910857Ssam if (hpdebug && sc->sc_recal) { 72025198Skarels log(LOG_DEBUG, 72125198Skarels "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n", 72225198Skarels sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 7233289Swnj hpaddr->hper1, HPER1_BITS, 7243289Swnj hpaddr->hper2, HPER2_BITS); 7253289Swnj } 7263706Sroot #endif 727*26375Skarels (void)HPWAIT(mi, hpaddr); 72825198Skarels if (retry) 7292892Swnj return (MBD_RETRY); 7303640Swnj if (mi->mi_tab.b_errcnt >= 16) { 7313093Swnj /* 7323093Swnj * This is fast and occurs rarely; we don't 7333093Swnj * bother with interrupts. 7343093Swnj */ 7352624Swnj hpaddr->hpcs1 = HP_RTC|HP_GO; 736*26375Skarels (void)HPWAIT(mi, hpaddr); 7372383Swnj mbclrattn(mi); 73821Sbill } 73925398Skarels if (mi->mi_tab.b_errcnt && (bp->b_flags & B_ERROR) == 0) 74025198Skarels log(LOG_INFO, "hp%d%c: %d retries %sing sn%d\n", 74125198Skarels hpunit(bp->b_dev), 'a'+(minor(bp->b_dev)&07), 74225198Skarels mi->mi_tab.b_errcnt, 74325198Skarels (bp->b_flags & B_READ) ? "read" : "writ", 74425198Skarels (bp->b_flags & B_BAD) ? 74525198Skarels sc->sc_badbn : bp->b_blkno + sc->sc_blkdone); 74617071Sralph if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 74717071Sralph return (MBD_RESTARTED); 74817071Sralph sc->sc_hdr = 0; 74925198Skarels sc->sc_blkdone = 0; 75026041Skarels bp->b_resid = bcr; 7515726Sroot if (!ML11) { 7525726Sroot hpaddr->hpof = HPOF_FMT22; 7535726Sroot hpaddr->hpcs1 = HP_RELEASE|HP_GO; 7545726Sroot } 7552383Swnj return (MBD_DONE); 75621Sbill } 75721Sbill 75818411Skarels /* 75918411Skarels * Wait (for a bit) for a drive to come ready; 76018411Skarels * returns nonzero on success. 76118411Skarels */ 76218411Skarels hpwait(mi) 76318411Skarels register struct mba_device *mi; 76418411Skarels { 76518411Skarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 76618411Skarels register i = 100000; 76718411Skarels 76818411Skarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 76918411Skarels DELAY(10); 77018411Skarels if (i == 0) 77118411Skarels printf("hp%d: intr, not ready\n", mi->mi_unit); 77218411Skarels return (i); 77318411Skarels } 77418411Skarels 7757738Sroot hpread(dev, uio) 7762624Swnj dev_t dev; 7777738Sroot struct uio *uio; 77821Sbill { 77924738Sbloom register int unit = hpunit(dev); 78021Sbill 7812624Swnj if (unit >= NHP) 7828156Sroot return (ENXIO); 7838156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_READ, minphys, uio)); 78421Sbill } 78521Sbill 7867831Sroot hpwrite(dev, uio) 7872624Swnj dev_t dev; 7887831Sroot struct uio *uio; 78921Sbill { 79024738Sbloom register int unit = hpunit(dev); 79121Sbill 7922624Swnj if (unit >= NHP) 7938156Sroot return (ENXIO); 7948156Sroot return (physio(hpstrategy, &rhpbuf[unit], dev, B_WRITE, minphys, uio)); 79521Sbill } 79621Sbill 7975726Sroot /*ARGSUSED*/ 7987635Ssam hpioctl(dev, cmd, data, flag) 7995726Sroot dev_t dev; 8005726Sroot int cmd; 8017635Ssam caddr_t data; 8025726Sroot int flag; 8035726Sroot { 8045726Sroot 8055726Sroot switch (cmd) { 8067635Ssam 8075726Sroot case DKIOCHDR: /* do header read/write */ 80824738Sbloom hpsoftc[hpunit(dev)].sc_hdr = 1; 8098579Sroot return (0); 8105726Sroot 8115726Sroot default: 8128579Sroot return (ENXIO); 8135726Sroot } 8145726Sroot } 8155726Sroot 8163706Sroot hpecc(mi, flag) 8172978Swnj register struct mba_device *mi; 8183706Sroot int flag; 81921Sbill { 8202383Swnj register struct mba_regs *mbp = mi->mi_mba; 8212624Swnj register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 8222383Swnj register struct buf *bp = mi->mi_tab.b_actf; 8233706Sroot register struct hpst *st = &hpst[mi->mi_type]; 82417071Sralph struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 8253706Sroot int npf, o; 8262383Swnj int bn, cn, tn, sn; 827914Sbill int bcr; 82821Sbill 82918411Skarels bcr = MASKREG(-mbp->mba_bcr); 83017071Sralph if (bp->b_flags & B_BAD) 8313706Sroot npf = bp->b_error; 8323706Sroot else 83326041Skarels npf = btodb(bp->b_bcount - bcr); 834420Sbill o = (int)bp->b_un.b_addr & PGOFSET; 83524738Sbloom bn = bp->b_blkno; 836420Sbill cn = bp->b_cylin; 83718411Skarels sn = bn%(st->nspc) + npf; 8382383Swnj tn = sn/st->nsect; 8392383Swnj sn %= st->nsect; 8402383Swnj cn += tn/st->ntrak; 8412383Swnj tn %= st->ntrak; 84224187Skarels bn += npf; 8433706Sroot switch (flag) { 84410856Ssam case ECC: { 8453706Sroot register int i; 8463706Sroot caddr_t addr; 8473706Sroot struct pte mpte; 8483706Sroot int bit, byte, mask; 8493706Sroot 8503706Sroot npf--; /* because block in error is previous block */ 85118411Skarels bn--; 85217071Sralph if (bp->b_flags & B_BAD) 85317071Sralph bn = sc->sc_badbn; 85424844Seric log(LOG_WARNING, "hp%d%c: soft ecc sn%d\n", hpunit(bp->b_dev), 85517071Sralph 'a'+(minor(bp->b_dev)&07), bn); 85611202Ssam mask = MASKREG(rp->hpec2); 85711202Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 8583706Sroot bit = i&07; 8593706Sroot i = (i&~07)>>3; 8603706Sroot byte = i + o; 86126041Skarels while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) { 8623706Sroot mpte = mbp->mba_map[npf+btop(byte)]; 8633706Sroot addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 8643706Sroot putmemc(addr, getmemc(addr)^(mask<<bit)); 8653706Sroot byte++; 8663706Sroot i++; 8673706Sroot bit -= 8; 8683706Sroot } 86918411Skarels if (bcr == 0) 8703706Sroot return (0); 8713847Sroot npf++; 8723706Sroot break; 8733706Sroot } 8743706Sroot 8753706Sroot case SSE: 8763706Sroot rp->hpof |= HPOF_SSEI; 87717071Sralph if (bp->b_flags & B_BAD) { 87817071Sralph bn = sc->sc_badbn; 87917071Sralph goto fixregs; 88017071Sralph } 8813706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 8823706Sroot break; 8833706Sroot 8843706Sroot case BSE: 88517071Sralph if (rp->hpof & HPOF_SSEI) 88617071Sralph sn++; 8873706Sroot #ifdef HPBDEBUG 8883706Sroot if (hpbdebug) 88925198Skarels log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8903706Sroot #endif 89117071Sralph if (bp->b_flags & B_BAD) 89217071Sralph return (0); 8933706Sroot if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 89411202Ssam return (0); 8953706Sroot bp->b_flags |= B_BAD; 8963706Sroot bp->b_error = npf + 1; 89717071Sralph rp->hpof &= ~HPOF_SSEI; 8983706Sroot bn = st->ncyl*st->nspc - st->nsect - 1 - bn; 89917071Sralph sc->sc_badbn = bn; 90017071Sralph fixregs: 9013706Sroot cn = bn/st->nspc; 9023706Sroot sn = bn%st->nspc; 9033706Sroot tn = sn/st->nsect; 9043706Sroot sn %= st->nsect; 905*26375Skarels bcr = bp->b_bcount - (int)ptob(npf); 906*26375Skarels bcr = MIN(bcr, 512); 907*26375Skarels mbp->mba_bcr = -bcr; 9083706Sroot #ifdef HPBDEBUG 9093706Sroot if (hpbdebug) 91025198Skarels log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn); 9113706Sroot #endif 9123706Sroot break; 9133706Sroot 9143706Sroot case CONT: 9153706Sroot #ifdef HPBDEBUG 9163706Sroot if (hpbdebug) 91725198Skarels log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 9183706Sroot #endif 9193706Sroot bp->b_flags &= ~B_BAD; 92024780Skarels if ((int)ptob(npf) >= bp->b_bcount) 92124780Skarels return (0); 9223706Sroot mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 9233706Sroot break; 9243706Sroot } 9253706Sroot rp->hpcs1 = HP_DCLR|HP_GO; 92617071Sralph if (rp->hpof & HPOF_SSEI) 9272883Swnj sn++; 928420Sbill rp->hpdc = cn; 929420Sbill rp->hpda = (tn<<8) + sn; 930420Sbill mbp->mba_sr = -1; 9313706Sroot mbp->mba_var = (int)ptob(npf) + o; 9323706Sroot rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 9333706Sroot mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 93425198Skarels sc->sc_blkdone = npf; 935420Sbill return (1); 93621Sbill } 9372362Swnj 9382362Swnj #define DBSIZE 20 9392362Swnj 9402362Swnj hpdump(dev) 9412362Swnj dev_t dev; 9422362Swnj { 9432978Swnj register struct mba_device *mi; 9442383Swnj register struct mba_regs *mba; 9452624Swnj struct hpdevice *hpaddr; 9462362Swnj char *start; 9472383Swnj int num, unit; 9482383Swnj register struct hpst *st; 9492362Swnj 9502362Swnj num = maxfree; 9512362Swnj start = 0; 95224738Sbloom unit = hpunit(dev); 9532827Swnj if (unit >= NHP) 9542827Swnj return (ENXIO); 9552383Swnj #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 9562978Swnj mi = phys(hpinfo[unit],struct mba_device *); 9572827Swnj if (mi == 0 || mi->mi_alive == 0) 9582827Swnj return (ENXIO); 9592383Swnj mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 9603102Swnj mba->mba_cr = MBCR_INIT; 9612624Swnj hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 9623093Swnj if ((hpaddr->hpds & HPDS_VV) == 0) { 9632624Swnj hpaddr->hpcs1 = HP_DCLR|HP_GO; 9642624Swnj hpaddr->hpcs1 = HP_PRESET|HP_GO; 9653093Swnj hpaddr->hpof = HPOF_FMT22; 9662362Swnj } 9672383Swnj st = &hpst[mi->mi_type]; 96824224Sbloom if (dumplo < 0) 9692827Swnj return (EINVAL); 97024224Sbloom if (dumplo + num >= st->sizes[minor(dev)&07].nblocks) 97124224Sbloom num = st->sizes[minor(dev)&07].nblocks - dumplo; 9722362Swnj while (num > 0) { 9732383Swnj register struct pte *hpte = mba->mba_map; 9742362Swnj register int i; 9752383Swnj int blk, cn, sn, tn; 9762362Swnj daddr_t bn; 9772362Swnj 9782362Swnj blk = num > DBSIZE ? DBSIZE : num; 9792362Swnj bn = dumplo + btop(start); 9802383Swnj cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff; 9812383Swnj sn = bn%st->nspc; 9822383Swnj tn = sn/st->nsect; 9832383Swnj sn = sn%st->nsect; 9842362Swnj hpaddr->hpdc = cn; 9852362Swnj hpaddr->hpda = (tn << 8) + sn; 9862362Swnj for (i = 0; i < blk; i++) 9872362Swnj *(int *)hpte++ = (btop(start)+i) | PG_V; 9882383Swnj mba->mba_sr = -1; 9892383Swnj mba->mba_bcr = -(blk*NBPG); 9902383Swnj mba->mba_var = 0; 9912624Swnj hpaddr->hpcs1 = HP_WCOM | HP_GO; 9923093Swnj while ((hpaddr->hpds & HPDS_DRY) == 0) 99316791Skarels DELAY(10); 9943093Swnj if (hpaddr->hpds&HPDS_ERR) 9952827Swnj return (EIO); 9962362Swnj start += blk*NBPG; 9972362Swnj num -= blk; 9982362Swnj } 9992362Swnj return (0); 10002362Swnj } 100112506Ssam 100212506Ssam hpsize(dev) 100312506Ssam dev_t dev; 100412506Ssam { 100524738Sbloom int unit = hpunit(dev); 100612506Ssam struct mba_device *mi; 100712506Ssam struct hpst *st; 100812506Ssam 100912506Ssam if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 101012506Ssam return (-1); 101112506Ssam st = &hpst[mi->mi_type]; 101212506Ssam return ((int)st->sizes[minor(dev) & 07].nblocks); 101312506Ssam } 10141565Sbill #endif 1015