1*18317Sralph /* up.c 6.3 85/03/12 */ 2264Sbill 31937Swnj #include "up.h" 42646Swnj #if NSC > 0 5264Sbill /* 69548Ssam * UNIBUS disk driver with: 79548Ssam * overlapped seeks, 89548Ssam * ECC recovery, and 99548Ssam * bad sector forwarding. 102889Swnj * 112889Swnj * TODO: 123445Sroot * Check that offset recovery code works 13264Sbill */ 149782Ssam #include "../machine/pte.h" 15264Sbill 1617082Sbloom #include "param.h" 1717082Sbloom #include "systm.h" 1817082Sbloom #include "dk.h" 1917082Sbloom #include "dkbad.h" 2017082Sbloom #include "buf.h" 2117082Sbloom #include "conf.h" 2217082Sbloom #include "dir.h" 2317082Sbloom #include "user.h" 2417082Sbloom #include "map.h" 2517082Sbloom #include "vm.h" 2617082Sbloom #include "cmap.h" 2717082Sbloom #include "uio.h" 2817082Sbloom #include "kernel.h" 29*18317Sralph #include "syslog.h" 30264Sbill 319357Ssam #include "../vax/cpu.h" 329357Ssam #include "../vax/nexus.h" 3317082Sbloom #include "ubavar.h" 3417082Sbloom #include "ubareg.h" 3517082Sbloom #include "upreg.h" 369357Ssam 372395Swnj struct up_softc { 382395Swnj int sc_softas; 392607Swnj int sc_ndrive; 402395Swnj int sc_wticks; 412674Swnj int sc_recal; 422646Swnj } up_softc[NSC]; 43275Sbill 442395Swnj /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 4510858Ssam struct size { 46264Sbill daddr_t nblocks; 47264Sbill int cyloff; 4811211Ssam } up9300_sizes[8] = { 49264Sbill 15884, 0, /* A=cyl 0 thru 26 */ 50264Sbill 33440, 27, /* B=cyl 27 thru 81 */ 51341Sbill 495520, 0, /* C=cyl 0 thru 814 */ 52264Sbill 15884, 562, /* D=cyl 562 thru 588 */ 53264Sbill 55936, 589, /* E=cyl 589 thru 680 */ 543730Sroot 81376, 681, /* F=cyl 681 thru 814 */ 553730Sroot 153728, 562, /* G=cyl 562 thru 814 */ 56264Sbill 291346, 82, /* H=cyl 82 thru 561 */ 5711211Ssam }, up9766_sizes[8] = { 5811211Ssam 15884, 0, /* A=cyl 0 thru 26 */ 5911211Ssam 33440, 27, /* B=cyl 27 thru 81 */ 6011211Ssam 500384, 0, /* C=cyl 0 thru 822 */ 6111211Ssam 15884, 562, /* D=cyl 562 thru 588 */ 6211211Ssam 55936, 589, /* E=cyl 589 thru 680 */ 6311211Ssam 86240, 681, /* F=cyl 681 thru 822 */ 6411211Ssam 158592, 562, /* G=cyl 562 thru 822 */ 6511211Ssam 291346, 82, /* H=cyl 82 thru 561 */ 6611211Ssam }, up160_sizes[8] = { 672395Swnj 15884, 0, /* A=cyl 0 thru 49 */ 682395Swnj 33440, 50, /* B=cyl 50 thru 154 */ 692395Swnj 263360, 0, /* C=cyl 0 thru 822 */ 7011211Ssam 15884, 155, /* D=cyl 155 thru 204 */ 7111211Ssam 55936, 205, /* E=cyl 205 thru 379 */ 7211211Ssam 141664, 380, /* F=cyl 380 thru 822 */ 7311211Ssam 213664, 155, /* G=cyl 155 thru 822 */ 742395Swnj 0, 0, 756851Ssam }, upam_sizes[8] = { 766305Sroot 15884, 0, /* A=cyl 0 thru 31 */ 776305Sroot 33440, 32, /* B=cyl 32 thru 97 */ 786305Sroot 524288, 0, /* C=cyl 0 thru 1023 */ 7911211Ssam 15884, 668, /* D=cyl 668 thru 699 */ 8011211Ssam 55936, 700, /* E=cyl 700 thru 809 */ 8111211Ssam 109472, 810, /* F=cyl 810 thru 1023 */ 8211211Ssam 182176, 668, /* G=cyl 668 thru 1023 */ 836305Sroot 291346, 98, /* H=cyl 98 thru 667 */ 8414002Ssam }, up980_sizes[8] = { 8514002Ssam 15884, 0, /* A=cyl 0 thru 99 */ 8614002Ssam 33440, 100, /* B=cyl 100 thru 308 */ 8714002Ssam 131680, 0, /* C=cyl 0 thru 822 */ 8814002Ssam 15884, 309, /* D=cyl 309 thru 408 */ 8914002Ssam 55936, 409, /* E=cyl 409 thru 758 */ 9014002Ssam 10080, 759, /* F=cyl 759 thru 822 */ 9114002Ssam 82080, 309, /* G=cyl 309 thru 822 */ 9214002Ssam 0, 0, 93264Sbill }; 942395Swnj /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 95264Sbill 962607Swnj int upprobe(), upslave(), upattach(), updgo(), upintr(); 972983Swnj struct uba_ctlr *upminfo[NSC]; 982983Swnj struct uba_device *updinfo[NUP]; 996383Swnj #define UPIPUNITS 8 1006383Swnj struct uba_device *upip[NSC][UPIPUNITS]; /* fuji w/fixed head gives n,n+4 */ 1012395Swnj 1022607Swnj u_short upstd[] = { 0776700, 0774400, 0776300, 0 }; 1032616Swnj struct uba_driver scdriver = 1042607Swnj { upprobe, upslave, upattach, updgo, upstd, "up", updinfo, "sc", upminfo }; 1052395Swnj struct buf uputab[NUP]; 1069548Ssam char upinit[NUP]; 1072395Swnj 1082395Swnj struct upst { 10912837Ssam short nsect; /* # sectors/track */ 11012837Ssam short ntrak; /* # tracks/cylinder */ 11112837Ssam short nspc; /* # sectors/cylinder */ 11212837Ssam short ncyl; /* # cylinders */ 11312837Ssam struct size *sizes; /* partition tables */ 11412837Ssam short sdist; /* seek distance metric */ 11512837Ssam short rdist; /* rotational distance metric */ 1162395Swnj } upst[] = { 11712837Ssam { 32, 19, 32*19, 815, up9300_sizes, 3, 4 }, /* 9300 */ 11812837Ssam { 32, 19, 32*19, 823, up9766_sizes, 3, 4 }, /* 9766 */ 11912837Ssam { 32, 10, 32*10, 823, up160_sizes, 3, 4 }, /* fuji 160m */ 12012837Ssam { 32, 16, 32*16, 1024, upam_sizes, 7, 8 }, /* Capricorn */ 12114002Ssam { 32, 5, 32*5, 823, up980_sizes, 3, 4 }, /* DM980 */ 12212837Ssam { 0, 0, 0, 0, 0, 0, 0 } 1232395Swnj }; 1242395Swnj 1252629Swnj u_char up_offset[16] = { 1269548Ssam UPOF_P400, UPOF_M400, UPOF_P400, UPOF_M400, 1279548Ssam UPOF_P800, UPOF_M800, UPOF_P800, UPOF_M800, 1289548Ssam UPOF_P1200, UPOF_M1200, UPOF_P1200, UPOF_M1200, 1299548Ssam 0, 0, 0, 0 1302629Swnj }; 131264Sbill 1322616Swnj struct buf rupbuf[NUP]; 1339548Ssam struct buf bupbuf[NUP]; 1349548Ssam struct dkbad upbad[NUP]; 135264Sbill 136264Sbill #define b_cylin b_resid 137264Sbill 138264Sbill #ifdef INTRLVE 139264Sbill daddr_t dkblock(); 140264Sbill #endif 1412395Swnj 1422395Swnj int upwstart, upwatch(); /* Have started guardian */ 1432470Swnj int upseek; 1442681Swnj int upwaitdry; 1452395Swnj 1462395Swnj /*ARGSUSED*/ 1472607Swnj upprobe(reg) 1482395Swnj caddr_t reg; 1492395Swnj { 1502459Swnj register int br, cvec; 1512459Swnj 1522607Swnj #ifdef lint 15312779Ssam br = 0; cvec = br; br = cvec; upintr(0); 1542607Swnj #endif 1552629Swnj ((struct updevice *)reg)->upcs1 = UP_IE|UP_RDY; 1562607Swnj DELAY(10); 1572629Swnj ((struct updevice *)reg)->upcs1 = 0; 1589357Ssam return (sizeof (struct updevice)); 1592395Swnj } 1602395Swnj 1612607Swnj upslave(ui, reg) 1622983Swnj struct uba_device *ui; 1632395Swnj caddr_t reg; 1642395Swnj { 1652629Swnj register struct updevice *upaddr = (struct updevice *)reg; 1662395Swnj 1672395Swnj upaddr->upcs1 = 0; /* conservative */ 1682607Swnj upaddr->upcs2 = ui->ui_slave; 1696843Swnj upaddr->upcs1 = UP_NOP|UP_GO; 1703445Sroot if (upaddr->upcs2&UPCS2_NED) { 1712629Swnj upaddr->upcs1 = UP_DCLR|UP_GO; 1722395Swnj return (0); 1732395Swnj } 1742607Swnj return (1); 1752607Swnj } 1762607Swnj 1772607Swnj upattach(ui) 1782983Swnj register struct uba_device *ui; 1792607Swnj { 1802607Swnj 1812395Swnj if (upwstart == 0) { 1822759Swnj timeout(upwatch, (caddr_t)0, hz); 1832395Swnj upwstart++; 1842395Swnj } 1852571Swnj if (ui->ui_dk >= 0) 1862571Swnj dk_mspw[ui->ui_dk] = .0000020345; 1872607Swnj upip[ui->ui_ctlr][ui->ui_slave] = ui; 1882607Swnj up_softc[ui->ui_ctlr].sc_ndrive++; 18911119Ssam ui->ui_type = upmaptype(ui); 19011119Ssam } 19111119Ssam 19211119Ssam upmaptype(ui) 19311119Ssam register struct uba_device *ui; 19411119Ssam { 19511119Ssam register struct updevice *upaddr = (struct updevice *)ui->ui_addr; 19611119Ssam int type = ui->ui_type; 19711119Ssam register struct upst *st; 19811119Ssam 1992629Swnj upaddr->upcs1 = 0; 2002629Swnj upaddr->upcs2 = ui->ui_slave; 2013496Sroot upaddr->uphr = UPHR_MAXTRAK; 20211119Ssam for (st = upst; st->nsect != 0; st++) 20311119Ssam if (upaddr->uphr == st->ntrak - 1) { 20411119Ssam type = st - upst; 20511119Ssam break; 20611119Ssam } 20711119Ssam if (st->nsect == 0) 20811119Ssam printf("up%d: uphr=%x\n", ui->ui_slave, upaddr->uphr); 20911119Ssam if (type == 0) { 21011112Shelge upaddr->uphr = UPHR_MAXCYL; 21111112Shelge if (upaddr->uphr == 822) 21211119Ssam type++; 21311112Shelge } 2143496Sroot upaddr->upcs2 = UPCS2_CLR; 21511119Ssam return (type); 2162395Swnj } 217264Sbill 2189548Ssam upopen(dev) 2199548Ssam dev_t dev; 2209548Ssam { 2219548Ssam register int unit = minor(dev) >> 3; 2229548Ssam register struct uba_device *ui; 2239548Ssam 2249548Ssam if (unit >= NUP || (ui = updinfo[unit]) == 0 || ui->ui_alive == 0) 2259548Ssam return (ENXIO); 2269548Ssam return (0); 2279548Ssam } 2289548Ssam 229264Sbill upstrategy(bp) 2302395Swnj register struct buf *bp; 231264Sbill { 2322983Swnj register struct uba_device *ui; 2332395Swnj register struct upst *st; 2342395Swnj register int unit; 2352470Swnj register struct buf *dp; 2362395Swnj int xunit = minor(bp->b_dev) & 07; 2372470Swnj long bn, sz; 238264Sbill 2392470Swnj sz = (bp->b_bcount+511) >> 9; 240264Sbill unit = dkunit(bp); 2412395Swnj if (unit >= NUP) 2422395Swnj goto bad; 2432395Swnj ui = updinfo[unit]; 2442395Swnj if (ui == 0 || ui->ui_alive == 0) 2452395Swnj goto bad; 2462395Swnj st = &upst[ui->ui_type]; 2472395Swnj if (bp->b_blkno < 0 || 2482395Swnj (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) 2492395Swnj goto bad; 2502395Swnj bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; 2516305Sroot (void) spl5(); 2522470Swnj dp = &uputab[ui->ui_unit]; 2532470Swnj disksort(dp, bp); 2542470Swnj if (dp->b_active == 0) { 2552395Swnj (void) upustart(ui); 2562395Swnj bp = &ui->ui_mi->um_tab; 2572395Swnj if (bp->b_actf && bp->b_active == 0) 2582395Swnj (void) upstart(ui->ui_mi); 259264Sbill } 2606305Sroot (void) spl0(); 2612395Swnj return; 2622395Swnj 2632395Swnj bad: 2642395Swnj bp->b_flags |= B_ERROR; 2652395Swnj iodone(bp); 2662395Swnj return; 267264Sbill } 268264Sbill 2692674Swnj /* 2702674Swnj * Unit start routine. 2712674Swnj * Seek the drive to be where the data is 2722674Swnj * and then generate another interrupt 2732674Swnj * to actually start the transfer. 2742674Swnj * If there is only one drive on the controller, 2752674Swnj * or we are very close to the data, don't 2762674Swnj * bother with the search. If called after 2772674Swnj * searching once, don't bother to look where 2782674Swnj * we are, just queue for transfer (to avoid 2792674Swnj * positioning forever without transferrring.) 2802674Swnj */ 2812395Swnj upustart(ui) 2822983Swnj register struct uba_device *ui; 283264Sbill { 284264Sbill register struct buf *bp, *dp; 2852983Swnj register struct uba_ctlr *um; 2862629Swnj register struct updevice *upaddr; 2872395Swnj register struct upst *st; 288264Sbill daddr_t bn; 2892674Swnj int sn, csn; 2902607Swnj /* 2912607Swnj * The SC21 cancels commands if you just say 2922629Swnj * cs1 = UP_IE 2932607Swnj * so we are cautious about handling of cs1. 2942607Swnj * Also don't bother to clear as bits other than in upintr(). 2952607Swnj */ 2962674Swnj int didie = 0; 2972674Swnj 2982674Swnj if (ui == 0) 2992674Swnj return (0); 3002983Swnj um = ui->ui_mi; 3012395Swnj dk_busy &= ~(1<<ui->ui_dk); 3022395Swnj dp = &uputab[ui->ui_unit]; 303266Sbill if ((bp = dp->b_actf) == NULL) 304268Sbill goto out; 3052674Swnj /* 3062674Swnj * If the controller is active, just remember 3072674Swnj * that this device would like to be positioned... 3082674Swnj * if we tried to position now we would confuse the SC21. 3092674Swnj */ 3102395Swnj if (um->um_tab.b_active) { 3112459Swnj up_softc[um->um_ctlr].sc_softas |= 1<<ui->ui_slave; 312275Sbill return (0); 313275Sbill } 3142674Swnj /* 3152674Swnj * If we have already positioned this drive, 3162674Swnj * then just put it on the ready queue. 3172674Swnj */ 318276Sbill if (dp->b_active) 319276Sbill goto done; 320276Sbill dp->b_active = 1; 3212629Swnj upaddr = (struct updevice *)um->um_addr; 3222395Swnj upaddr->upcs2 = ui->ui_slave; 3232674Swnj /* 3242674Swnj * If drive has just come up, 3252674Swnj * setup the pack. 3262674Swnj */ 3279548Ssam if ((upaddr->upds & UPDS_VV) == 0 || upinit[ui->ui_unit] == 0) { 3289548Ssam struct buf *bbp = &bupbuf[ui->ui_unit]; 32910858Ssam 3302607Swnj /* SHOULD WARN SYSTEM THAT THIS HAPPENED */ 3319548Ssam upinit[ui->ui_unit] = 1; 3322629Swnj upaddr->upcs1 = UP_IE|UP_DCLR|UP_GO; 3332629Swnj upaddr->upcs1 = UP_IE|UP_PRESET|UP_GO; 3343445Sroot upaddr->upof = UPOF_FMT22; 335268Sbill didie = 1; 3369548Ssam st = &upst[ui->ui_type]; 3379548Ssam bbp->b_flags = B_READ|B_BUSY; 3389548Ssam bbp->b_dev = bp->b_dev; 3399548Ssam bbp->b_bcount = 512; 3409548Ssam bbp->b_un.b_addr = (caddr_t)&upbad[ui->ui_unit]; 3419548Ssam bbp->b_blkno = st->ncyl * st->nspc - st->nsect; 3429548Ssam bbp->b_cylin = st->ncyl - 1; 3439548Ssam dp->b_actf = bbp; 3449548Ssam bbp->av_forw = bp; 3459548Ssam bp = bbp; 346264Sbill } 3472674Swnj /* 3482674Swnj * If drive is offline, forget about positioning. 3492674Swnj */ 3503445Sroot if ((upaddr->upds & (UPDS_DPR|UPDS_MOL)) != (UPDS_DPR|UPDS_MOL)) 351275Sbill goto done; 3522674Swnj /* 3532674Swnj * If there is only one drive, 3542674Swnj * dont bother searching. 3552674Swnj */ 3562607Swnj if (up_softc[um->um_ctlr].sc_ndrive == 1) 3572607Swnj goto done; 3582674Swnj /* 3592674Swnj * Figure out where this transfer is going to 3602674Swnj * and see if we are close enough to justify not searching. 3612674Swnj */ 3622395Swnj st = &upst[ui->ui_type]; 363264Sbill bn = dkblock(bp); 3642395Swnj sn = bn%st->nspc; 36512837Ssam sn = (sn + st->nsect - st->sdist) % st->nsect; 3662674Swnj if (bp->b_cylin - upaddr->updc) 367266Sbill goto search; /* Not on-cylinder */ 368275Sbill else if (upseek) 369275Sbill goto done; /* Ok just to be on-cylinder */ 370264Sbill csn = (upaddr->upla>>6) - sn - 1; 371266Sbill if (csn < 0) 3722395Swnj csn += st->nsect; 37312837Ssam if (csn > st->nsect - st->rdist) 374264Sbill goto done; 375264Sbill search: 3762674Swnj upaddr->updc = bp->b_cylin; 3772674Swnj /* 3782674Swnj * Not on cylinder at correct position, 3792674Swnj * seek/search. 3802674Swnj */ 381275Sbill if (upseek) 3822629Swnj upaddr->upcs1 = UP_IE|UP_SEEK|UP_GO; 3832470Swnj else { 384275Sbill upaddr->upda = sn; 3852629Swnj upaddr->upcs1 = UP_IE|UP_SEARCH|UP_GO; 386275Sbill } 387268Sbill didie = 1; 3882674Swnj /* 3892674Swnj * Mark unit busy for iostat. 3902674Swnj */ 3912395Swnj if (ui->ui_dk >= 0) { 3922395Swnj dk_busy |= 1<<ui->ui_dk; 3932395Swnj dk_seek[ui->ui_dk]++; 394264Sbill } 395268Sbill goto out; 396264Sbill done: 3972674Swnj /* 3982674Swnj * Device is ready to go. 3992674Swnj * Put it on the ready queue for the controller 4002674Swnj * (unless its already there.) 4012674Swnj */ 4022629Swnj if (dp->b_active != 2) { 4032629Swnj dp->b_forw = NULL; 4042629Swnj if (um->um_tab.b_actf == NULL) 4052629Swnj um->um_tab.b_actf = dp; 4062629Swnj else 4072629Swnj um->um_tab.b_actl->b_forw = dp; 4082629Swnj um->um_tab.b_actl = dp; 4092629Swnj dp->b_active = 2; 4102629Swnj } 411268Sbill out: 412268Sbill return (didie); 413264Sbill } 414264Sbill 4152674Swnj /* 4162674Swnj * Start up a transfer on a drive. 4172674Swnj */ 4182395Swnj upstart(um) 4192983Swnj register struct uba_ctlr *um; 420264Sbill { 421264Sbill register struct buf *bp, *dp; 4222983Swnj register struct uba_device *ui; 4232629Swnj register struct updevice *upaddr; 4242470Swnj struct upst *st; 425264Sbill daddr_t bn; 4262681Swnj int dn, sn, tn, cmd, waitdry; 427264Sbill 428264Sbill loop: 4292674Swnj /* 4302674Swnj * Pull a request off the controller queue 4312674Swnj */ 4322395Swnj if ((dp = um->um_tab.b_actf) == NULL) 433268Sbill return (0); 434264Sbill if ((bp = dp->b_actf) == NULL) { 4352395Swnj um->um_tab.b_actf = dp->b_forw; 436264Sbill goto loop; 437264Sbill } 4382674Swnj /* 4392674Swnj * Mark controller busy, and 4402674Swnj * determine destination of this request. 4412674Swnj */ 4422395Swnj um->um_tab.b_active++; 4432395Swnj ui = updinfo[dkunit(bp)]; 444264Sbill bn = dkblock(bp); 4452395Swnj dn = ui->ui_slave; 4462395Swnj st = &upst[ui->ui_type]; 4472395Swnj sn = bn%st->nspc; 4482395Swnj tn = sn/st->nsect; 4492395Swnj sn %= st->nsect; 4502629Swnj upaddr = (struct updevice *)ui->ui_addr; 4512674Swnj /* 4522674Swnj * Select drive if not selected already. 4532674Swnj */ 4542674Swnj if ((upaddr->upcs2&07) != dn) 4552674Swnj upaddr->upcs2 = dn; 4562674Swnj /* 4572674Swnj * Check that it is ready and online 4582674Swnj */ 4592681Swnj waitdry = 0; 4603445Sroot while ((upaddr->upds&UPDS_DRY) == 0) { 4617036Swnj printf("up%d: ds wait ds=%o\n",dkunit(bp),upaddr->upds); 4622681Swnj if (++waitdry > 512) 4632681Swnj break; 4642681Swnj upwaitdry++; 4652681Swnj } 4663445Sroot if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { 4672931Swnj printf("up%d: not ready", dkunit(bp)); 4683445Sroot if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { 4692607Swnj printf("\n"); 4702395Swnj um->um_tab.b_active = 0; 4712395Swnj um->um_tab.b_errcnt = 0; 472893Sbill dp->b_actf = bp->av_forw; 473893Sbill dp->b_active = 0; 474893Sbill bp->b_flags |= B_ERROR; 475893Sbill iodone(bp); 476893Sbill goto loop; 477893Sbill } 4782674Swnj /* 4792674Swnj * Oh, well, sometimes this 4802674Swnj * happens, for reasons unknown. 4812674Swnj */ 4822629Swnj printf(" (flakey)\n"); 483264Sbill } 4842674Swnj /* 4852674Swnj * Setup for the transfer, and get in the 4862674Swnj * UNIBUS adaptor queue. 4872674Swnj */ 4882424Skre upaddr->updc = bp->b_cylin; 489264Sbill upaddr->upda = (tn << 8) + sn; 490264Sbill upaddr->upwc = -bp->b_bcount / sizeof (short); 491264Sbill if (bp->b_flags & B_READ) 4922629Swnj cmd = UP_IE|UP_RCOM|UP_GO; 493264Sbill else 4942629Swnj cmd = UP_IE|UP_WCOM|UP_GO; 4952571Swnj um->um_cmd = cmd; 4963107Swnj (void) ubago(ui); 497268Sbill return (1); 498264Sbill } 499264Sbill 5002674Swnj /* 5012674Swnj * Now all ready to go, stuff the registers. 5022674Swnj */ 5032571Swnj updgo(um) 5042983Swnj struct uba_ctlr *um; 5052395Swnj { 5062629Swnj register struct updevice *upaddr = (struct updevice *)um->um_addr; 5072470Swnj 5086953Swnj um->um_tab.b_active = 2; /* should now be 2 */ 5092571Swnj upaddr->upba = um->um_ubinfo; 5102571Swnj upaddr->upcs1 = um->um_cmd|((um->um_ubinfo>>8)&0x300); 5112395Swnj } 5122395Swnj 5132674Swnj /* 5142674Swnj * Handle a disk interrupt. 5152674Swnj */ 5162707Swnj upintr(sc21) 5172395Swnj register sc21; 518264Sbill { 519264Sbill register struct buf *bp, *dp; 5202983Swnj register struct uba_ctlr *um = upminfo[sc21]; 5212983Swnj register struct uba_device *ui; 5222629Swnj register struct updevice *upaddr = (struct updevice *)um->um_addr; 523264Sbill register unit; 5242470Swnj struct up_softc *sc = &up_softc[um->um_ctlr]; 5252607Swnj int as = (upaddr->upas & 0377) | sc->sc_softas; 5262681Swnj int needie = 1, waitdry; 527264Sbill 5282470Swnj sc->sc_wticks = 0; 5292607Swnj sc->sc_softas = 0; 5302674Swnj /* 5312674Swnj * If controller wasn't transferring, then this is an 5322674Swnj * interrupt for attention status on seeking drives. 5332674Swnj * Just service them. 5342674Swnj */ 5356346Swnj if (um->um_tab.b_active != 2 && !sc->sc_recal) { 5362674Swnj if (upaddr->upcs1 & UP_TRE) 5372674Swnj upaddr->upcs1 = UP_TRE; 5382674Swnj goto doattn; 5392674Swnj } 5406953Swnj um->um_tab.b_active = 1; 5412674Swnj /* 5422674Swnj * Get device and block structures, and a pointer 5432983Swnj * to the uba_device for the drive. Select the drive. 5442674Swnj */ 5452674Swnj dp = um->um_tab.b_actf; 5462674Swnj bp = dp->b_actf; 5472674Swnj ui = updinfo[dkunit(bp)]; 5482674Swnj dk_busy &= ~(1 << ui->ui_dk); 5492674Swnj if ((upaddr->upcs2&07) != ui->ui_slave) 5502395Swnj upaddr->upcs2 = ui->ui_slave; 5519548Ssam if (bp->b_flags&B_BAD) { 5529548Ssam if (upecc(ui, CONT)) 5539548Ssam return; 5549548Ssam } 5552674Swnj /* 5562674Swnj * Check for and process errors on 5572674Swnj * either the drive or the controller. 5582674Swnj */ 5593445Sroot if ((upaddr->upds&UPDS_ERR) || (upaddr->upcs1&UP_TRE)) { 5602681Swnj waitdry = 0; 5613445Sroot while ((upaddr->upds & UPDS_DRY) == 0) { 5622681Swnj if (++waitdry > 512) 5632681Swnj break; 5642681Swnj upwaitdry++; 5652681Swnj } 5663445Sroot if (upaddr->uper1&UPER1_WLE) { 5672674Swnj /* 5682674Swnj * Give up on write locked devices 5692674Swnj * immediately. 5702674Swnj */ 5712931Swnj printf("up%d: write locked\n", dkunit(bp)); 5722674Swnj bp->b_flags |= B_ERROR; 5732674Swnj } else if (++um->um_tab.b_errcnt > 27) { 5742674Swnj /* 5752674Swnj * After 28 retries (16 without offset, and 5762674Swnj * 12 with offset positioning) give up. 57710904Shelge * If the error was header CRC, the header is 57810904Shelge * screwed up, and the sector may in fact exist 57910904Shelge * in the bad sector table, better check... 5802674Swnj */ 58110904Shelge if (upaddr->uper1&UPER1_HCRC) { 58210904Shelge if (upecc(ui, BSE)) 58310904Shelge return; 58410904Shelge } 5859548Ssam hard: 5862931Swnj harderr(bp, "up"); 5879548Ssam printf("cn=%d tn=%d sn=%d cs2=%b er1=%b er2=%b\n", 5889548Ssam upaddr->updc, ((upaddr->upda)>>8)&077, 5899548Ssam (upaddr->upda)&037, 5909548Ssam upaddr->upcs2, UPCS2_BITS, 5919548Ssam upaddr->uper1, UPER1_BITS, 5929548Ssam upaddr->uper2, UPER2_BITS); 5932674Swnj bp->b_flags |= B_ERROR; 5949548Ssam } else if (upaddr->uper2 & UPER2_BSE) { 5959548Ssam if (upecc(ui, BSE)) 5969548Ssam return; 5979548Ssam else 5989548Ssam goto hard; 5992674Swnj } else { 6002674Swnj /* 6012674Swnj * Retriable error. 6022674Swnj * If a soft ecc, correct it (continuing 6032674Swnj * by returning if necessary. 6042674Swnj * Otherwise fall through and retry the transfer 6052674Swnj */ 6067183Sroot if ((upaddr->uper1&(UPER1_DCK|UPER1_ECH))==UPER1_DCK) { 6079548Ssam if (upecc(ui, ECC)) 6082629Swnj return; 6097183Sroot } else 6107183Sroot um->um_tab.b_active = 0; /* force retry */ 6112674Swnj } 6122674Swnj /* 6132674Swnj * Clear drive error and, every eight attempts, 6142674Swnj * (starting with the fourth) 6152674Swnj * recalibrate to clear the slate. 6162674Swnj */ 6172674Swnj upaddr->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO; 6182674Swnj needie = 0; 6193182Swnj if ((um->um_tab.b_errcnt&07) == 4 && um->um_tab.b_active == 0) { 6202674Swnj upaddr->upcs1 = UP_RECAL|UP_IE|UP_GO; 6213160Swnj sc->sc_recal = 0; 6223160Swnj goto nextrecal; 6232674Swnj } 6242674Swnj } 6252674Swnj /* 6263160Swnj * Advance recalibration finite state machine 6273160Swnj * if recalibrate in progress, through 6283160Swnj * RECAL 6293160Swnj * SEEK 6303160Swnj * OFFSET (optional) 6313160Swnj * RETRY 6322674Swnj */ 6333160Swnj switch (sc->sc_recal) { 6343160Swnj 6353160Swnj case 1: 6363160Swnj upaddr->updc = bp->b_cylin; 6373160Swnj upaddr->upcs1 = UP_SEEK|UP_IE|UP_GO; 6383160Swnj goto nextrecal; 6393160Swnj case 2: 6403160Swnj if (um->um_tab.b_errcnt < 16 || (bp->b_flags&B_READ) == 0) 6413160Swnj goto donerecal; 6423445Sroot upaddr->upof = up_offset[um->um_tab.b_errcnt & 017] | UPOF_FMT22; 6433160Swnj upaddr->upcs1 = UP_IE|UP_OFFSET|UP_GO; 6443160Swnj goto nextrecal; 6453160Swnj nextrecal: 6463160Swnj sc->sc_recal++; 6473160Swnj um->um_tab.b_active = 1; 6483160Swnj return; 6493160Swnj donerecal: 6503160Swnj case 3: 6512674Swnj sc->sc_recal = 0; 6523160Swnj um->um_tab.b_active = 0; 6533160Swnj break; 6542674Swnj } 6552674Swnj /* 6562674Swnj * If still ``active'', then don't need any more retries. 6572674Swnj */ 6582674Swnj if (um->um_tab.b_active) { 6592674Swnj /* 6602674Swnj * If we were offset positioning, 6612674Swnj * return to centerline. 6622674Swnj */ 6632674Swnj if (um->um_tab.b_errcnt >= 16) { 6643445Sroot upaddr->upof = UPOF_FMT22; 6652674Swnj upaddr->upcs1 = UP_RTC|UP_GO|UP_IE; 6663445Sroot while (upaddr->upds & UPDS_PIP) 6672674Swnj DELAY(25); 668268Sbill needie = 0; 669264Sbill } 6702674Swnj um->um_tab.b_active = 0; 6712674Swnj um->um_tab.b_errcnt = 0; 6722674Swnj um->um_tab.b_actf = dp->b_forw; 6732674Swnj dp->b_active = 0; 6742674Swnj dp->b_errcnt = 0; 6752674Swnj dp->b_actf = bp->av_forw; 6762674Swnj bp->b_resid = (-upaddr->upwc * sizeof(short)); 6772674Swnj iodone(bp); 6782674Swnj /* 6792674Swnj * If this unit has more work to do, 6802674Swnj * then start it up right away. 6812674Swnj */ 6822674Swnj if (dp->b_actf) 6832674Swnj if (upustart(ui)) 684268Sbill needie = 0; 685264Sbill } 6862674Swnj as &= ~(1<<ui->ui_slave); 6873403Swnj /* 6883403Swnj * Release unibus resources and flush data paths. 6893403Swnj */ 6903403Swnj ubadone(um); 6912674Swnj doattn: 6922674Swnj /* 6932674Swnj * Process other units which need attention. 6942674Swnj * For each unit which needs attention, call 6952674Swnj * the unit start routine to place the slave 6962674Swnj * on the controller device queue. 6972674Swnj */ 6983160Swnj while (unit = ffs(as)) { 6993160Swnj unit--; /* was 1 origin */ 7003160Swnj as &= ~(1<<unit); 7013160Swnj upaddr->upas = 1<<unit; 7026383Swnj if (unit < UPIPUNITS && upustart(upip[sc21][unit])) 7033160Swnj needie = 0; 7043160Swnj } 7052674Swnj /* 7062674Swnj * If the controller is not transferring, but 7072674Swnj * there are devices ready to transfer, start 7082674Swnj * the controller. 7092674Swnj */ 7102395Swnj if (um->um_tab.b_actf && um->um_tab.b_active == 0) 7112395Swnj if (upstart(um)) 712268Sbill needie = 0; 713275Sbill if (needie) 7142629Swnj upaddr->upcs1 = UP_IE; 715264Sbill } 716264Sbill 7179357Ssam upread(dev, uio) 7182616Swnj dev_t dev; 7199357Ssam struct uio *uio; 720264Sbill { 7212616Swnj register int unit = minor(dev) >> 3; 7222470Swnj 7232616Swnj if (unit >= NUP) 7249357Ssam return (ENXIO); 7259357Ssam return (physio(upstrategy, &rupbuf[unit], dev, B_READ, minphys, uio)); 726264Sbill } 727264Sbill 7289357Ssam upwrite(dev, uio) 7292616Swnj dev_t dev; 7309357Ssam struct uio *uio; 731264Sbill { 7322616Swnj register int unit = minor(dev) >> 3; 7332470Swnj 7342616Swnj if (unit >= NUP) 7359357Ssam return (ENXIO); 7369357Ssam return (physio(upstrategy, &rupbuf[unit], dev, B_WRITE, minphys, uio)); 737264Sbill } 738264Sbill 739266Sbill /* 740266Sbill * Correct an ECC error, and restart the i/o to complete 741266Sbill * the transfer if necessary. This is quite complicated because 742266Sbill * the transfer may be going to an odd memory address base and/or 743266Sbill * across a page boundary. 744266Sbill */ 7459548Ssam upecc(ui, flag) 7462983Swnj register struct uba_device *ui; 7479548Ssam int flag; 748264Sbill { 7492629Swnj register struct updevice *up = (struct updevice *)ui->ui_addr; 7502395Swnj register struct buf *bp = uputab[ui->ui_unit].b_actf; 7512983Swnj register struct uba_ctlr *um = ui->ui_mi; 7522395Swnj register struct upst *st; 7532395Swnj struct uba_regs *ubp = ui->ui_hd->uh_uba; 754266Sbill register int i; 755264Sbill caddr_t addr; 756266Sbill int reg, bit, byte, npf, mask, o, cmd, ubaddr; 757264Sbill int bn, cn, tn, sn; 758264Sbill 759264Sbill /* 760266Sbill * Npf is the number of sectors transferred before the sector 761266Sbill * containing the ECC error, and reg is the UBA register 762266Sbill * mapping (the first part of) the transfer. 763266Sbill * O is offset within a memory page of the first byte transferred. 764264Sbill */ 7659548Ssam if (flag == CONT) 7669548Ssam npf = bp->b_error; 7679548Ssam else 76810858Ssam npf = btop((up->upwc * sizeof(short)) + bp->b_bcount); 7692571Swnj reg = btop(um->um_ubinfo&0x3ffff) + npf; 770264Sbill o = (int)bp->b_un.b_addr & PGOFSET; 771264Sbill mask = up->upec2; 7723445Sroot #ifdef UPECCDEBUG 7733403Swnj printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask, 7743403Swnj up->upec1); 7753445Sroot #endif 7769548Ssam bn = dkblock(bp); 7779548Ssam st = &upst[ui->ui_type]; 7789548Ssam cn = bp->b_cylin; 7799548Ssam sn = bn%st->nspc + npf; 7809548Ssam tn = sn/st->nsect; 7819548Ssam sn %= st->nsect; 7829548Ssam cn += tn/st->ntrak; 7839548Ssam tn %= st->ntrak; 7842725Swnj ubapurge(um); 7859548Ssam um->um_tab.b_active=2; 786266Sbill /* 7879548Ssam * action taken depends on the flag 788266Sbill */ 7899548Ssam switch(flag){ 7909548Ssam case ECC: 7919548Ssam npf--; 7929548Ssam reg--; 7939548Ssam mask = up->upec2; 794*18317Sralph log(KERN_RECOV, "up%d%c: soft ecc sn%d\n", dkunit(bp), 7959548Ssam 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); 7969548Ssam /* 7979548Ssam * Flush the buffered data path, and compute the 7989548Ssam * byte and bit position of the error. The variable i 7999548Ssam * is the byte offset in the transfer, the variable byte 8009548Ssam * is the offset from a page boundary in main memory. 8019548Ssam */ 8029548Ssam i = up->upec1 - 1; /* -1 makes 0 origin */ 8039548Ssam bit = i&07; 8049548Ssam i = (i&~07)>>3; 8059548Ssam byte = i + o; 8069548Ssam /* 8079548Ssam * Correct while possible bits remain of mask. Since mask 8089548Ssam * contains 11 bits, we continue while the bit offset is > -11. 8099548Ssam * Also watch out for end of this block and the end of the whole 8109548Ssam * transfer. 8119548Ssam */ 8129548Ssam while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { 81313879Ssam struct pte pte; 81413879Ssam 81513879Ssam pte = ubp->uba_map[reg + btop(byte)]; 81613879Ssam addr = ptob(pte.pg_pfnum) + (byte & PGOFSET); 8173445Sroot #ifdef UPECCDEBUG 8189548Ssam printf("addr %x map reg %x\n", 8199548Ssam addr, *(int *)(&ubp->uba_map[reg+btop(byte)])); 8209548Ssam printf("old: %x, ", getmemc(addr)); 8213445Sroot #endif 8229548Ssam putmemc(addr, getmemc(addr)^(mask<<bit)); 8233445Sroot #ifdef UPECCDEBUG 8249548Ssam printf("new: %x\n", getmemc(addr)); 8253445Sroot #endif 8269548Ssam byte++; 8279548Ssam i++; 8289580Shelge bit -= 8; 8299548Ssam } 8309548Ssam if (up->upwc == 0) 8319548Ssam return (0); 8329548Ssam npf++; 8339548Ssam reg++; 8349548Ssam break; 8359548Ssam case BSE: 8369548Ssam /* 8379548Ssam * if not in bad sector table, return 0 8389548Ssam */ 8399548Ssam if ((bn = isbad(&upbad[ui->ui_unit], cn, tn, sn)) < 0) 8409548Ssam return(0); 8419548Ssam /* 8429548Ssam * flag this one as bad 8439548Ssam */ 8449548Ssam bp->b_flags |= B_BAD; 8459548Ssam bp->b_error = npf + 1; 8469548Ssam #ifdef UPECCDEBUG 8479548Ssam printf("BSE: restart at %d\n",npf+1); 8489548Ssam #endif 8499548Ssam bn = st->ncyl * st->nspc -st->nsect - 1 - bn; 8509548Ssam cn = bn / st->nspc; 8519548Ssam sn = bn % st->nspc; 8529548Ssam tn = sn / st->nsect; 8539548Ssam sn %= st->nsect; 8549548Ssam up->upwc = -(512 / sizeof (short)); 8559548Ssam #ifdef UPECCDEBUG 8569548Ssam printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 8579548Ssam #endif 8589548Ssam break; 8599548Ssam case CONT: 8609548Ssam #ifdef UPECCDEBUG 8619548Ssam printf("upecc, CONT: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 8629548Ssam #endif 8639548Ssam bp->b_flags &= ~B_BAD; 8649548Ssam up->upwc = -((bp->b_bcount - (int)ptob(npf)) / sizeof(short)); 8659548Ssam if (up->upwc == 0) 8669548Ssam return(0); 8679548Ssam break; 868264Sbill } 8697183Sroot if (up->upwc == 0) { 8707183Sroot um->um_tab.b_active = 0; 871264Sbill return (0); 8727183Sroot } 873266Sbill /* 874266Sbill * Have to continue the transfer... clear the drive, 875266Sbill * and compute the position where the transfer is to continue. 876266Sbill * We have completed npf+1 sectors of the transfer already; 877266Sbill * restart at offset o of next sector (i.e. in UBA register reg+1). 878266Sbill */ 8792629Swnj #ifdef notdef 8802629Swnj up->uper1 = 0; 8812629Swnj up->upcs1 |= UP_GO; 8822629Swnj #else 8832629Swnj up->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO; 884264Sbill up->updc = cn; 885266Sbill up->upda = (tn << 8) | sn; 8869548Ssam ubaddr = (int)ptob(reg) + o; 887266Sbill up->upba = ubaddr; 888266Sbill cmd = (ubaddr >> 8) & 0x300; 8899548Ssam cmd |= ((bp->b_flags&B_READ)?UP_RCOM:UP_WCOM)|UP_IE|UP_GO; 8909548Ssam um->um_tab.b_errcnt = 0; 891266Sbill up->upcs1 = cmd; 8922629Swnj #endif 893264Sbill return (1); 894264Sbill } 895286Sbill 896286Sbill /* 897286Sbill * Reset driver after UBA init. 898286Sbill * Cancel software state of all pending transfers 899286Sbill * and restart all units and the controller. 900286Sbill */ 9012395Swnj upreset(uban) 9022931Swnj int uban; 903286Sbill { 9042983Swnj register struct uba_ctlr *um; 9052983Swnj register struct uba_device *ui; 9062395Swnj register sc21, unit; 907286Sbill 9082646Swnj for (sc21 = 0; sc21 < NSC; sc21++) { 9092470Swnj if ((um = upminfo[sc21]) == 0 || um->um_ubanum != uban || 9102470Swnj um->um_alive == 0) 9112395Swnj continue; 9122931Swnj printf(" sc%d", sc21); 9132395Swnj um->um_tab.b_active = 0; 9142395Swnj um->um_tab.b_actf = um->um_tab.b_actl = 0; 9152931Swnj up_softc[sc21].sc_recal = 0; 9166346Swnj up_softc[sc21].sc_wticks = 0; 9172571Swnj if (um->um_ubinfo) { 9182571Swnj printf("<%d>", (um->um_ubinfo>>28)&0xf); 9199357Ssam um->um_ubinfo = 0; 9202395Swnj } 9213445Sroot ((struct updevice *)(um->um_addr))->upcs2 = UPCS2_CLR; 9222395Swnj for (unit = 0; unit < NUP; unit++) { 9232395Swnj if ((ui = updinfo[unit]) == 0) 9242395Swnj continue; 9252931Swnj if (ui->ui_alive == 0 || ui->ui_mi != um) 9262395Swnj continue; 9272395Swnj uputab[unit].b_active = 0; 9282395Swnj (void) upustart(ui); 9292395Swnj } 9302395Swnj (void) upstart(um); 931286Sbill } 932286Sbill } 933313Sbill 934313Sbill /* 935313Sbill * Wake up every second and if an interrupt is pending 936313Sbill * but nothing has happened increment a counter. 9372931Swnj * If nothing happens for 20 seconds, reset the UNIBUS 938313Sbill * and begin anew. 939313Sbill */ 940313Sbill upwatch() 941313Sbill { 9422983Swnj register struct uba_ctlr *um; 9432395Swnj register sc21, unit; 9442470Swnj register struct up_softc *sc; 945313Sbill 9462759Swnj timeout(upwatch, (caddr_t)0, hz); 9472646Swnj for (sc21 = 0; sc21 < NSC; sc21++) { 9482395Swnj um = upminfo[sc21]; 9492470Swnj if (um == 0 || um->um_alive == 0) 9502470Swnj continue; 9512470Swnj sc = &up_softc[sc21]; 9522395Swnj if (um->um_tab.b_active == 0) { 9532395Swnj for (unit = 0; unit < NUP; unit++) 9542629Swnj if (uputab[unit].b_active && 9552629Swnj updinfo[unit]->ui_mi == um) 9562395Swnj goto active; 9572470Swnj sc->sc_wticks = 0; 9582395Swnj continue; 9592395Swnj } 9602931Swnj active: 9612470Swnj sc->sc_wticks++; 9622470Swnj if (sc->sc_wticks >= 20) { 9632470Swnj sc->sc_wticks = 0; 9642931Swnj printf("sc%d: lost interrupt\n", sc21); 9652646Swnj ubareset(um->um_ubanum); 9662395Swnj } 967313Sbill } 968313Sbill } 9692379Swnj 9702379Swnj #define DBSIZE 20 9712379Swnj 9722379Swnj updump(dev) 9732379Swnj dev_t dev; 9742379Swnj { 9752629Swnj struct updevice *upaddr; 9762379Swnj char *start; 9773107Swnj int num, blk, unit; 9782379Swnj struct size *sizes; 9792395Swnj register struct uba_regs *uba; 9802983Swnj register struct uba_device *ui; 9812379Swnj register short *rp; 9822395Swnj struct upst *st; 9836848Ssam register int retry; 9842379Swnj 9852395Swnj unit = minor(dev) >> 3; 9862889Swnj if (unit >= NUP) 9872889Swnj return (ENXIO); 9882470Swnj #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) 9892983Swnj ui = phys(struct uba_device *, updinfo[unit]); 9902889Swnj if (ui->ui_alive == 0) 9912889Swnj return (ENXIO); 9922395Swnj uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 9932983Swnj ubainit(uba); 9942629Swnj upaddr = (struct updevice *)ui->ui_physaddr; 9956848Ssam DELAY(5000000); 9962379Swnj num = maxfree; 9972379Swnj upaddr->upcs2 = unit; 9982983Swnj DELAY(100); 9996848Ssam upaddr->upcs1 = UP_DCLR|UP_GO; 10006848Ssam upaddr->upcs1 = UP_PRESET|UP_GO; 10016848Ssam upaddr->upof = UPOF_FMT22; 10026848Ssam retry = 0; 10036848Ssam do { 10046848Ssam DELAY(25); 10056848Ssam if (++retry > 527) 10066848Ssam break; 10076861Ssam } while ((upaddr->upds & UP_RDY) == 0); 10083445Sroot if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) 10092889Swnj return (EFAULT); 10109357Ssam start = 0; 10118489Sroot st = &upst[ui->ui_type]; 10122395Swnj sizes = phys(struct size *, st->sizes); 10132889Swnj if (dumplo < 0 || dumplo + num >= sizes[minor(dev)&07].nblocks) 10142889Swnj return (EINVAL); 10152379Swnj while (num > 0) { 10162379Swnj register struct pte *io; 10172379Swnj register int i; 10182379Swnj int cn, sn, tn; 10192379Swnj daddr_t bn; 10202379Swnj 10212379Swnj blk = num > DBSIZE ? DBSIZE : num; 10222395Swnj io = uba->uba_map; 10232379Swnj for (i = 0; i < blk; i++) 10242983Swnj *(int *)io++ = (btop(start)+i) | (1<<21) | UBAMR_MRV; 10252379Swnj *(int *)io = 0; 10262379Swnj bn = dumplo + btop(start); 10272607Swnj cn = bn/st->nspc + sizes[minor(dev)&07].cyloff; 10282607Swnj sn = bn%st->nspc; 10292607Swnj tn = sn/st->nsect; 10302607Swnj sn = sn%st->nsect; 10312379Swnj upaddr->updc = cn; 10322379Swnj rp = (short *) &upaddr->upda; 10332379Swnj *rp = (tn << 8) + sn; 10342379Swnj *--rp = 0; 10352379Swnj *--rp = -blk*NBPG / sizeof (short); 10362629Swnj *--rp = UP_GO|UP_WCOM; 10376848Ssam retry = 0; 10382379Swnj do { 10392379Swnj DELAY(25); 10406848Ssam if (++retry > 527) 10416848Ssam break; 10422629Swnj } while ((upaddr->upcs1 & UP_RDY) == 0); 10436848Ssam if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { 10446861Ssam printf("up%d: not ready", unit); 10456848Ssam if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { 10466848Ssam printf("\n"); 10476848Ssam return (EIO); 10486848Ssam } 10496848Ssam printf(" (flakey)\n"); 10506848Ssam } 10513445Sroot if (upaddr->upds&UPDS_ERR) 10522889Swnj return (EIO); 10532379Swnj start += blk*NBPG; 10542379Swnj num -= blk; 10552379Swnj } 10562379Swnj return (0); 10572379Swnj } 105812505Ssam 105912505Ssam upsize(dev) 106012505Ssam dev_t dev; 106112505Ssam { 106212505Ssam int unit = minor(dev) >> 3; 106312505Ssam struct uba_device *ui; 106412505Ssam struct upst *st; 106512505Ssam 106612505Ssam if (unit >= NUP || (ui = updinfo[unit]) == 0 || ui->ui_alive == 0) 106712505Ssam return (-1); 106812505Ssam st = &upst[ui->ui_type]; 106912505Ssam return (st->sizes[minor(dev) & 07].nblocks); 107012505Ssam } 10711902Swnj #endif 1072