1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)hp.c 7.20 (Berkeley) 06/21/90 7 */ 8 9 #ifdef HPDEBUG 10 int hpdebug; 11 #endif 12 #ifdef HPBDEBUG 13 int hpbdebug; 14 #endif 15 16 #include "hp.h" 17 #if NHP > 0 18 /* 19 * HP disk driver for RP0x+RMxx+ML11 20 * 21 * TODO: 22 * see if DCLR and/or RELEASE set attention status 23 */ 24 #include "param.h" 25 #include "systm.h" 26 #include "dkstat.h" 27 #include "buf.h" 28 #include "conf.h" 29 #include "file.h" 30 #include "user.h" 31 #include "map.h" 32 #include "../vax/mtpr.h" 33 #include "vm.h" 34 #include "cmap.h" 35 #include "dkbad.h" 36 #include "disklabel.h" 37 #include "ioctl.h" 38 #include "syslog.h" 39 #include "stat.h" 40 41 #include "machine/pte.h" 42 #include "../vax/dkio.h" 43 #include "mbareg.h" 44 #include "mbavar.h" 45 #include "hpreg.h" 46 47 #define COMPAT_42 48 #define B_FORMAT B_XXX 49 50 /* 51 * Table of supported Massbus drive types. 52 * When using unlabeled packs, slot numbers here 53 * are used as indices into the partition tables. 54 * Slots are left for those drives divined from other means 55 * (e.g. SI, AMPEX, etc.). 56 */ 57 short hptypes[] = { 58 #define HPDT_RM03 0 59 MBDT_RM03, 60 #define HPDT_RM05 1 61 MBDT_RM05, 62 #define HPDT_RP06 2 63 MBDT_RP06, 64 #define HPDT_RM80 3 65 MBDT_RM80, 66 #define HPDT_RP04 4 67 MBDT_RP04, 68 #define HPDT_RP05 5 69 MBDT_RP05, 70 #define HPDT_RP07 6 71 MBDT_RP07, 72 #define HPDT_ML11A 7 73 MBDT_ML11A, 74 #define HPDT_ML11B 8 75 MBDT_ML11B, 76 #define HPDT_9775 9 77 -1, 78 #define HPDT_9730 10 79 -1, 80 #define HPDT_CAPRICORN 11 81 -1, 82 #define HPDT_EAGLE 12 83 -1, 84 #define HPDT_9300 13 85 -1, 86 #define HPDT_RM02 14 87 MBDT_RM02, /* beware, actually mapped */ 88 #define HPDT_2361 15 89 -1, 90 #define HPDT_2361A 16 91 -1, 92 0 93 }; 94 95 struct mba_device *hpinfo[NHP]; 96 int hpattach(),hpustart(),hpstart(),hpdtint(),hpstrategy(); 97 struct mba_driver hpdriver = 98 { hpattach, 0, hpustart, hpstart, hpdtint, 0, 99 hptypes, "hp", 0, hpinfo }; 100 101 u_char hp_offset[16] = { 102 HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 103 HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 104 HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 105 0, 0, 0, 0, 106 }; 107 108 struct disklabel hplabel[NHP]; 109 struct dkbad hpbad[NHP]; 110 111 struct hpsoftc { 112 u_char sc_recal; /* recalibrate state */ 113 u_char sc_doseeks; /* perform explicit seeks */ 114 #ifdef COMPAT_42 115 u_char sc_hdr; /* next i/o includes header */ 116 #endif 117 int sc_state; /* open fsm */ 118 int sc_wlabel; /* label sector is currently writable */ 119 u_long sc_openpart; /* bit mask of open subunits */ 120 u_long sc_copenpart; /* bit mask of open character subunits */ 121 u_long sc_bopenpart; /* bit mask of open block subunits */ 122 daddr_t sc_mlsize; /* ML11 size */ 123 int sc_blkdone; /* amount sucessfully transfered */ 124 daddr_t sc_badbn; /* replacement block number */ 125 int sc_status; /* copy of drive status reg. after format */ 126 int sc_hpds; /* copy of hpds reg. after format */ 127 int sc_er1; /* copy of error reg. 1 after format */ 128 int sc_er2; /* copy of error reg. 2 after format */ 129 } hpsoftc[NHP]; 130 131 /* 132 * Drive states. Used during steps of open/initialization. 133 * States < OPEN (> 0) are transient, during an open operation. 134 * OPENRAW is used for unlabeled disks, 135 * to inhibit bad-sector forwarding or allow format operations. 136 */ 137 #define CLOSED 0 /* disk is closed. */ 138 #define WANTOPEN 1 /* open requested, not started */ 139 #define WANTOPENRAW 2 /* open requested, no label */ 140 #define RDLABEL 3 /* reading pack label */ 141 #define RDBADTBL 4 /* reading bad-sector table */ 142 #define OPEN 5 /* initialized and ready */ 143 #define OPENRAW 6 /* open, no label or badsect */ 144 145 #define b_cylin b_resid 146 147 /* #define ML11 0 to remove ML11 support */ 148 #define ML11(type) ((type) == HPDT_ML11A) 149 #define RP06(type) (hptypes[type] <= MBDT_RP06) 150 #define RM80(type) ((type) == HPDT_RM80) 151 152 #define hpunit(dev) (minor(dev) >> 3) 153 #define hppart(dev) (minor(dev) & 07) 154 #define hpminor(unit, part) (((unit) << 3) | (part)) 155 156 #define MASKREG(reg) ((reg)&0xffff) 157 #ifdef lint 158 #define HPWAIT(mi, addr) (hpwait(mi)) 159 #else 160 #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi)) 161 #endif 162 163 /*ARGSUSED*/ 164 hpattach(mi, slave) 165 struct mba_device *mi; 166 { 167 register int unit = mi->mi_unit; 168 extern int cold; 169 170 if (cold) { 171 /* 172 * Try to initialize device and read pack label. 173 */ 174 if (hpinit(hpminor(unit, 0), 0) == 0) { 175 printf(": %s", hplabel[unit].d_typename); 176 #ifdef notyet 177 addswap(makedev(HPMAJOR, hpminor(unit, 0)), 178 &hplabel[unit]); 179 #endif 180 } else 181 printf(": offline"); 182 } 183 } 184 185 hpopen(dev, flags, fmt) 186 dev_t dev; 187 int flags, fmt; 188 { 189 register int unit = hpunit(dev); 190 register struct hpsoftc *sc; 191 register struct disklabel *lp; 192 register struct partition *pp; 193 struct mba_device *mi; 194 int s, error, part = hppart(dev), mask = 1 << part; 195 daddr_t start, end; 196 197 if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0) 198 return (ENXIO); 199 sc = &hpsoftc[unit]; 200 lp = &hplabel[unit]; 201 202 s = spl5(); 203 while (sc->sc_state != OPEN && sc->sc_state != OPENRAW && 204 sc->sc_state != CLOSED) 205 if (error = tsleep((caddr_t)sc, (PZERO+1) | PCATCH, 206 devopn, 0)) { 207 splx(s); 208 return (error); 209 } 210 splx(s); 211 if (sc->sc_state != OPEN && sc->sc_state != OPENRAW) 212 if (error = hpinit(dev, flags)) 213 return (error); 214 if (part >= lp->d_npartitions) 215 return (ENXIO); 216 /* 217 * Warn if a partion is opened 218 * that overlaps another partition which is open 219 * unless one is the "raw" partition (whole disk). 220 */ 221 #define RAWPART 2 /* 'c' partition */ /* XXX */ 222 if ((sc->sc_openpart & mask) == 0 && part != RAWPART) { 223 pp = &lp->d_partitions[part]; 224 start = pp->p_offset; 225 end = pp->p_offset + pp->p_size; 226 for (pp = lp->d_partitions; 227 pp < &lp->d_partitions[lp->d_npartitions]; pp++) { 228 if (pp->p_offset + pp->p_size <= start || 229 pp->p_offset >= end) 230 continue; 231 if (pp - lp->d_partitions == RAWPART) 232 continue; 233 if (sc->sc_openpart & (1 << (pp - lp->d_partitions))) 234 log(LOG_WARNING, 235 "hp%d%c: overlaps open partition (%c)\n", 236 unit, part + 'a', 237 pp - lp->d_partitions + 'a'); 238 } 239 } 240 switch (fmt) { 241 case S_IFCHR: 242 sc->sc_copenpart |= mask; 243 break; 244 case S_IFBLK: 245 sc->sc_bopenpart |= mask; 246 break; 247 } 248 sc->sc_openpart |= mask; 249 return (0); 250 } 251 252 /* ARGSUSED */ 253 hpclose(dev, flags, fmt) 254 dev_t dev; 255 int flags, fmt; 256 { 257 register int unit = hpunit(dev); 258 register struct hpsoftc *sc; 259 struct mba_device *mi; 260 int s, mask = 1 << hppart(dev); 261 262 sc = &hpsoftc[unit]; 263 mi = hpinfo[unit]; 264 switch (fmt) { 265 case S_IFCHR: 266 sc->sc_copenpart &= ~mask; 267 break; 268 case S_IFBLK: 269 sc->sc_bopenpart &= ~mask; 270 break; 271 } 272 sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart; 273 274 /* 275 * Should wait for I/O to complete on this partition 276 * even if others are open, but wait for work on blkflush(). 277 */ 278 if (sc->sc_openpart == 0) { 279 s = spl5(); 280 while (mi->mi_tab.b_actf) 281 sleep((caddr_t)sc, PZERO - 1); 282 splx(s); 283 sc->sc_state = CLOSED; 284 sc->sc_wlabel = 0; 285 } 286 return (0); 287 } 288 289 hpinit(dev, flags) 290 dev_t dev; 291 int flags; 292 { 293 register struct hpsoftc *sc; 294 register struct buf *bp; 295 register struct disklabel *lp; 296 struct mba_device *mi; 297 struct hpdevice *hpaddr; 298 struct dkbad *db; 299 char *msg, *readdisklabel(); 300 int unit, i, error = 0; 301 302 unit = hpunit(dev); 303 sc = &hpsoftc[unit]; 304 lp = &hplabel[unit]; 305 mi = hpinfo[unit]; 306 hpaddr = (struct hpdevice *)mi->mi_drv; 307 308 sc->sc_state = WANTOPEN; 309 /* 310 * Use the default sizes until we've read the label, 311 * or longer if there isn't one there. 312 */ 313 if (lp->d_secpercyl == 0) { 314 lp->d_secsize = DEV_BSIZE; 315 lp->d_nsectors = 32; 316 lp->d_ntracks = 20; 317 lp->d_secpercyl = 32*20; 318 lp->d_npartitions = 1; 319 lp->d_partitions[0].p_offset = 0; 320 lp->d_partitions[0].p_size = LABELSECTOR + 1; 321 } 322 323 if (flags & O_NDELAY) 324 goto raw; 325 326 /* 327 * Map all ML11's to the same type. Also calculate 328 * transfer rates based on device characteristics. 329 * Set up dummy label with all that's needed. 330 */ 331 if (mi->mi_type == MBDT_ML11A || mi->mi_type == MBDT_ML11B) { 332 register int trt; 333 334 sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ; 335 if ((hpaddr->hpmr & HPMR_ARRTYP) == 0) 336 sc->sc_mlsize >>= 2; 337 if (mi->mi_dk >= 0) { 338 trt = (hpaddr->hpmr & HPMR_TRT) >> 8; 339 dk_wpms[mi->mi_dk] = (1<<(20-trt)); 340 } 341 mi->mi_type = MBDT_ML11A; 342 lp->d_partitions[0].p_size = sc->sc_mlsize; 343 lp->d_secpercyl = sc->sc_mlsize; 344 goto raw; 345 } 346 347 /* 348 * Preset, pack acknowledge will be done in hpstart 349 * during first read operation. 350 */ 351 if (msg = readdisklabel(dev, hpstrategy, lp)) { 352 if (cold) 353 printf(": %s", msg); 354 else 355 log(LOG_ERR, "hp%d: %s\n", unit, msg); 356 #ifdef COMPAT_42 357 if (hpmaptype(mi, lp) == 0) 358 #endif 359 goto raw; 360 } 361 362 /* 363 * Seconds per word = (60 / rpm) / (nsectors * secsize/2) 364 */ 365 if (mi->mi_dk >= 0 && lp->d_rpm) 366 dk_wpms[mi->mi_dk] = 367 (lp->d_rpm * lp->d_nsectors * lp->d_secsize) / 120; 368 /* 369 * Read bad sector table into memory. 370 */ 371 bp = geteblk(DEV_BSIZE); /* max sector size */ 372 bp->b_dev = dev; 373 sc->sc_state = RDBADTBL; 374 i = 0; 375 do { 376 bp->b_flags = B_BUSY | B_READ; 377 bp->b_blkno = lp->d_secperunit - lp->d_nsectors + i; 378 bp->b_bcount = lp->d_secsize; 379 bp->b_cylin = lp->d_ncylinders - 1; 380 hpstrategy(bp); 381 (void) biowait(bp); 382 } while ((bp->b_flags & B_ERROR) && (i += 2) < 10 && 383 i < lp->d_nsectors); 384 db = (struct dkbad *)(bp->b_un.b_addr); 385 if ((bp->b_flags & B_ERROR) == 0 && db->bt_mbz == 0 && 386 db->bt_flag == 0) { 387 hpbad[unit] = *db; 388 } else 389 log(LOG_ERR, "hp%d: %s bad-sector file\n", unit, 390 (bp->b_flags & B_ERROR) ? "can't read" : "format error in"); 391 sc->sc_state = OPEN; 392 bp->b_flags = B_INVAL | B_AGE; 393 brelse(bp); 394 wakeup((caddr_t)sc); 395 return (error); 396 397 raw: 398 if (cold) 399 sc->sc_state = CLOSED; 400 else { 401 sc->sc_state = OPENRAW; 402 wakeup((caddr_t)sc); 403 } 404 return (error); 405 } 406 407 hpstrategy(bp) 408 register struct buf *bp; 409 { 410 register struct mba_device *mi; 411 register struct disklabel *lp; 412 register struct hpsoftc *sc; 413 register int unit; 414 daddr_t sz, maxsz; 415 int xunit = hppart(bp->b_dev); 416 int s; 417 418 sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 419 unit = hpunit(bp->b_dev); 420 if (unit >= NHP) { 421 bp->b_error = ENXIO; 422 goto bad; 423 } 424 mi = hpinfo[unit]; 425 sc = &hpsoftc[unit]; 426 lp = &hplabel[unit]; 427 if (mi == 0 || mi->mi_alive == 0) { 428 bp->b_error = ENXIO; 429 goto bad; 430 } 431 #ifdef COMPAT_42 432 if (sc->sc_hdr) { /* XXX */ 433 if (bp->b_bcount == 516) 434 bp->b_flags |= B_FORMAT; 435 sc->sc_hdr = 0; 436 } 437 #endif 438 if (sc->sc_state < OPEN) 439 goto q; 440 if (sc->sc_state != OPEN && (bp->b_flags & (B_READ|B_FORMAT)) == 0) { 441 bp->b_error = EROFS; 442 goto bad; 443 } 444 if ((sc->sc_openpart & (1 << xunit)) == 0) { 445 bp->b_error = ENODEV; 446 goto bad; 447 } 448 maxsz = lp->d_partitions[xunit].p_size; 449 if (bp->b_blkno + lp->d_partitions[xunit].p_offset <= LABELSECTOR && 450 #if LABELSECTOR != 0 451 bp->b_blkno + lp->d_partitions[xunit].p_offset + sz > LABELSECTOR && 452 #endif 453 (bp->b_flags & B_READ) == 0 && sc->sc_wlabel == 0) { 454 bp->b_error = EROFS; 455 goto bad; 456 } 457 if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { 458 if (bp->b_blkno == maxsz) { 459 bp->b_resid = bp->b_bcount; 460 goto done; 461 } 462 sz = maxsz - bp->b_blkno; 463 if (sz <= 0) { 464 bp->b_error = EINVAL; 465 goto bad; 466 } 467 bp->b_bcount = sz << DEV_BSHIFT; 468 } 469 bp->b_cylin = (bp->b_blkno + lp->d_partitions[xunit].p_offset) / 470 lp->d_secpercyl; 471 q: 472 s = spl5(); 473 disksort(&mi->mi_tab, bp); 474 if (mi->mi_tab.b_active == 0) 475 mbustart(mi); 476 splx(s); 477 return; 478 479 bad: 480 bp->b_flags |= B_ERROR; 481 done: 482 biodone(bp); 483 return; 484 } 485 486 hpustart(mi) 487 register struct mba_device *mi; 488 { 489 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 490 register struct buf *bp = mi->mi_tab.b_actf; 491 register struct disklabel *lp; 492 struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 493 daddr_t bn; 494 int sn, tn, dist; 495 496 lp = &hplabel[mi->mi_unit]; 497 hpaddr->hpcs1 = 0; 498 if ((hpaddr->hpcs1&HP_DVA) == 0) 499 return (MBU_BUSY); 500 501 switch (sc->sc_recal) { 502 503 case 1: 504 (void)HPWAIT(mi, hpaddr); 505 hpaddr->hpdc = bp->b_cylin; 506 hpaddr->hpcs1 = HP_SEEK|HP_GO; 507 sc->sc_recal++; 508 return (MBU_STARTED); 509 case 2: 510 break; 511 } 512 sc->sc_recal = 0; 513 if ((hpaddr->hpds & HPDS_VV) == 0) { 514 if (sc->sc_state == OPEN && lp->d_flags & D_REMOVABLE) { 515 if (sc->sc_openpart) 516 log(LOG_ERR, "hp%d: volume changed\n", 517 mi->mi_unit); 518 sc->sc_openpart = 0; 519 bp->b_flags |= B_ERROR; 520 return (MBU_NEXT); 521 } 522 hpaddr->hpcs1 = HP_DCLR|HP_GO; 523 if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive)) 524 printf("DCLR attn\n"); 525 hpaddr->hpcs1 = HP_PRESET|HP_GO; 526 if (!ML11(mi->mi_type)) 527 hpaddr->hpof = HPOF_FMT22; 528 mbclrattn(mi); 529 if (sc->sc_state == WANTOPENRAW) { 530 sc->sc_state = OPENRAW; 531 return (MBU_NEXT); 532 } 533 if (sc->sc_state == WANTOPEN) 534 sc->sc_state = RDLABEL; 535 } 536 if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) { 537 if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) { 538 hpaddr->hpof = 539 hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22; 540 hpaddr->hpcs1 = HP_OFFSET|HP_GO; 541 (void)HPWAIT(mi, hpaddr); 542 mbclrattn(mi); 543 } 544 return (MBU_DODATA); 545 } 546 if (ML11(mi->mi_type)) 547 return (MBU_DODATA); 548 if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY) 549 return (MBU_DODATA); 550 bn = bp->b_blkno; 551 sn = bn % lp->d_secpercyl; 552 tn = sn / lp->d_nsectors; 553 sn = sn % lp->d_nsectors; 554 if (bp->b_cylin == MASKREG(hpaddr->hpdc)) { 555 if (sc->sc_doseeks) 556 return (MBU_DODATA); 557 dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1; 558 if (dist < 0) 559 dist += lp->d_nsectors; 560 if (dist <= lp->d_maxdist && dist >= lp->d_mindist) 561 return (MBU_DODATA); 562 } else 563 hpaddr->hpdc = bp->b_cylin; 564 if (sc->sc_doseeks) 565 hpaddr->hpcs1 = HP_SEEK|HP_GO; 566 else { 567 sn = (sn + lp->d_nsectors - lp->d_sdist) % lp->d_nsectors; 568 hpaddr->hpda = (tn << 8) + sn; 569 hpaddr->hpcs1 = HP_SEARCH|HP_GO; 570 } 571 return (MBU_STARTED); 572 } 573 574 hpstart(mi) 575 register struct mba_device *mi; 576 { 577 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 578 register struct buf *bp = mi->mi_tab.b_actf; 579 register struct disklabel *lp = &hplabel[mi->mi_unit]; 580 struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 581 daddr_t bn; 582 int sn, tn, cn; 583 584 if (ML11(mi->mi_type)) 585 hpaddr->hpda = bp->b_blkno + sc->sc_blkdone; 586 else { 587 if (bp->b_flags & B_BAD) { 588 bn = sc->sc_badbn; 589 cn = bn / lp->d_secpercyl; 590 } else { 591 bn = bp->b_blkno; 592 cn = bp->b_cylin; 593 } 594 sn = bn % lp->d_secpercyl; 595 if ((bp->b_flags & B_BAD) == 0) 596 sn += sc->sc_blkdone; 597 tn = sn / lp->d_nsectors; 598 sn %= lp->d_nsectors; 599 cn += tn / lp->d_ntracks; 600 tn %= lp->d_ntracks; 601 hpaddr->hpda = (tn << 8) + sn; 602 hpaddr->hpdc = cn; 603 } 604 mi->mi_tab.b_bdone = dbtob(sc->sc_blkdone); 605 if (bp->b_flags & B_FORMAT) { 606 if (bp->b_flags & B_READ) 607 return (HP_RHDR|HP_GO); 608 else 609 return (HP_WHDR|HP_GO); 610 } 611 return (0); 612 } 613 614 hpdtint(mi, mbsr) 615 register struct mba_device *mi; 616 int mbsr; 617 { 618 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 619 register struct buf *bp = mi->mi_tab.b_actf; 620 register int er1, er2; 621 struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 622 int retry = 0; 623 int npf, bcr; 624 625 bcr = MASKREG(-mi->mi_mba->mba_bcr); 626 if (bp->b_flags & B_FORMAT) { 627 sc->sc_status = mbsr; 628 sc->sc_hpds = hpaddr->hpds; 629 sc->sc_er1 = hpaddr->hper1; 630 sc->sc_er2 = hpaddr->hper2; 631 } 632 if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) { 633 er1 = hpaddr->hper1; 634 er2 = hpaddr->hper2; 635 if (bp->b_flags & B_BAD) 636 npf = bp->b_error; 637 else { 638 npf = btodb(bp->b_bcount + (DEV_BSIZE - 1) - bcr); 639 if (er1 & (HPER1_DCK | HPER1_ECH)) 640 npf--; 641 } 642 if (HPWAIT(mi, hpaddr) == 0) 643 goto hard; 644 #ifdef HPDEBUG 645 if (hpdebug) { 646 int dc = hpaddr->hpdc, da = hpaddr->hpda; 647 daddr_t bn; 648 649 if (bp->b_flags & B_BAD) 650 bn = sc->sc_badbn; 651 else 652 bn = bp->b_blkno + npf; 653 log(LOG_DEBUG, 654 "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n", 655 bp, bp->b_cylin, bn, sc->sc_blkdone, 656 hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da)); 657 log(LOG_DEBUG, 658 "errcnt %d mbsr=%b er1=%b er2=%b bcr -%d\n", 659 mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 660 MASKREG(er1), HPER1_BITS, 661 MASKREG(er2), HPER2_BITS, bcr); 662 } 663 #endif 664 if (er1 & HPER1_HCRC) { 665 er1 &= ~(HPER1_HCE|HPER1_FER); 666 er2 &= ~HPER2_BSE; 667 } 668 if (er1 & HPER1_WLE) { 669 log(LOG_WARNING, "hp%d: write locked\n", 670 hpunit(bp->b_dev)); 671 bp->b_flags |= B_ERROR; 672 } else if (bp->b_flags & B_FORMAT) { 673 bp->b_flags |= B_ERROR; 674 } else if (RM80(mi->mi_type) && er2&HPER2_SSE) { 675 (void) hpecc(mi, SSE); 676 return (MBD_RESTARTED); 677 } else if ((er2 & HPER2_BSE) && !ML11(mi->mi_type)) { 678 if (hpecc(mi, BSE)) 679 return (MBD_RESTARTED); 680 goto hard; 681 } else if (MASKREG(er1) == HPER1_FER && RP06(mi->mi_type)) { 682 if (hpecc(mi, BSE)) 683 return (MBD_RESTARTED); 684 goto hard; 685 } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK && 686 mi->mi_tab.b_errcnt >= 3) { 687 if (hpecc(mi, ECC)) 688 return (MBD_RESTARTED); 689 /* 690 * ECC corrected. Only log retries below 691 * if we got errors other than soft ECC 692 * (as indicated by additional retries). 693 */ 694 if (mi->mi_tab.b_errcnt == 3) 695 mi->mi_tab.b_errcnt = 0; 696 } else if ((er1 & HPER1_HCRC) && !ML11(mi->mi_type) && 697 hpecc(mi, BSE)) { 698 /* 699 * HCRC means the header is screwed up and the sector 700 * might well exist in the bad sector table, 701 * better check.... 702 */ 703 return (MBD_RESTARTED); 704 } else if (++mi->mi_tab.b_errcnt > 27 || 705 (ML11(mi->mi_type) && mi->mi_tab.b_errcnt > 15) || 706 mbsr & MBSR_HARD || 707 er1 & HPER1_HARD || 708 (!ML11(mi->mi_type) && (er2 & HPER2_HARD))) { 709 hard: 710 diskerr(bp, "hp", "hard error", LOG_PRINTF, npf, 711 &hplabel[mi->mi_unit]); 712 if (bp->b_flags & B_BAD) 713 printf(" (on replacement sector %d)", 714 sc->sc_badbn); 715 if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC))) 716 printf(" mbsr=%b", mbsr, mbsr_bits); 717 printf(" er1=%b er2=%b ds=%b\n", 718 MASKREG(hpaddr->hper1), HPER1_BITS, 719 MASKREG(hpaddr->hper2), HPER2_BITS, 720 MASKREG(hpaddr->hpds), HPDS_BITS); 721 bp->b_flags |= B_ERROR; 722 bp->b_flags &= ~B_BAD; 723 } else 724 retry = 1; 725 hpaddr->hpcs1 = HP_DCLR|HP_GO; 726 if (retry && (mi->mi_tab.b_errcnt & 07) == 4) { 727 hpaddr->hpcs1 = HP_RECAL|HP_GO; 728 sc->sc_recal = 1; 729 return (MBD_REPOSITION); 730 } 731 } 732 #ifdef HPDEBUG 733 else 734 if (hpdebug && sc->sc_recal) { 735 log(LOG_DEBUG, 736 "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n", 737 sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits, 738 hpaddr->hper1, HPER1_BITS, 739 hpaddr->hper2, HPER2_BITS); 740 } 741 #endif 742 (void)HPWAIT(mi, hpaddr); 743 if (retry) 744 return (MBD_RETRY); 745 if (mi->mi_tab.b_errcnt >= 16) { 746 /* 747 * This is fast and occurs rarely; we don't 748 * bother with interrupts. 749 */ 750 hpaddr->hpcs1 = HP_RTC|HP_GO; 751 (void)HPWAIT(mi, hpaddr); 752 mbclrattn(mi); 753 } 754 if (mi->mi_tab.b_errcnt && (bp->b_flags & B_ERROR) == 0) { 755 diskerr(bp, "hp", "retries", LOG_INFO, sc->sc_blkdone, 756 &hplabel[mi->mi_unit]); 757 addlog(": %d retries\n", mi->mi_tab.b_errcnt); 758 } 759 if ((bp->b_flags & B_BAD) && hpecc(mi, CONT)) 760 return (MBD_RESTARTED); 761 sc->sc_blkdone = 0; 762 bp->b_resid = bcr; 763 if (!ML11(mi->mi_type)) { 764 hpaddr->hpof = HPOF_FMT22; 765 hpaddr->hpcs1 = HP_RELEASE|HP_GO; 766 } 767 if (sc->sc_openpart == 0) 768 wakeup((caddr_t)sc); 769 return (MBD_DONE); 770 } 771 772 /* 773 * Wait (for a bit) for a drive to come ready; 774 * returns nonzero on success. 775 */ 776 hpwait(mi) 777 register struct mba_device *mi; 778 { 779 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 780 register i = 100000; 781 782 while ((hpaddr->hpds & HPDS_DRY) == 0 && --i) 783 DELAY(10); 784 if (i == 0) 785 printf("hp%d: intr, not ready\n", mi->mi_unit); 786 return (i); 787 } 788 789 hpioctl(dev, cmd, data, flag) 790 dev_t dev; 791 int cmd; 792 caddr_t data; 793 int flag; 794 { 795 int unit = hpunit(dev); 796 register struct disklabel *lp; 797 register struct hpsoftc *sc = &hpsoftc[unit]; 798 int error = 0; 799 int hpformat(); 800 801 lp = &hplabel[unit]; 802 803 switch (cmd) { 804 805 case DIOCGDINFO: 806 *(struct disklabel *)data = *lp; 807 break; 808 809 case DIOCGPART: 810 ((struct partinfo *)data)->disklab = lp; 811 ((struct partinfo *)data)->part = 812 &lp->d_partitions[hppart(dev)]; 813 break; 814 815 case DIOCSDINFO: 816 if ((flag & FWRITE) == 0) 817 error = EBADF; 818 else 819 error = setdisklabel(lp, (struct disklabel *)data, 820 (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart); 821 if (error == 0) 822 sc->sc_state = OPEN; 823 break; 824 825 case DIOCWLABEL: 826 if ((flag & FWRITE) == 0) 827 error = EBADF; 828 else 829 sc->sc_wlabel = *(int *)data; 830 break; 831 832 case DIOCWDINFO: 833 if ((flag & FWRITE) == 0) 834 error = EBADF; 835 else if ((error = setdisklabel(lp, (struct disklabel *)data, 836 (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart)) == 0) { 837 int wlab; 838 839 sc->sc_state = OPEN; 840 /* simulate opening partition 0 so write succeeds */ 841 sc->sc_openpart |= (1 << 0); /* XXX */ 842 wlab = sc->sc_wlabel; 843 sc->sc_wlabel = 1; 844 error = writedisklabel(dev, hpstrategy, lp); 845 sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart; 846 sc->sc_wlabel = wlab; 847 } 848 break; 849 850 case DIOCSBAD: 851 { 852 struct dkbad *db = (struct dkbad *)data; 853 854 if ((flag & FWRITE) == 0) 855 error = EBADF; 856 else if (db->bt_mbz != 0 || db->bt_flag != 0) 857 error = EINVAL; 858 else 859 hpbad[unit] = *db; 860 break; 861 } 862 863 case DIOCRFORMAT: 864 case DIOCWFORMAT: 865 { 866 register struct format_op *fop; 867 struct uio auio; 868 struct iovec aiov; 869 870 if (cmd == DIOCWFORMAT && (flag & FWRITE) == 0) { 871 error = EBADF; 872 break; 873 } 874 fop = (struct format_op *)data; 875 aiov.iov_base = fop->df_buf; 876 aiov.iov_len = fop->df_count; 877 auio.uio_iov = &aiov; 878 auio.uio_iovcnt = 1; 879 auio.uio_resid = fop->df_count; 880 auio.uio_segflg = UIO_USERSPACE; 881 auio.uio_offset = fop->df_startblk * lp->d_secsize; 882 /* 883 * Don't return errors, as the format op won't get copied 884 * out if we return nonzero. Callers must check the returned 885 * count. 886 */ 887 (void) physio(hpformat, (struct buf *)NULL, dev, 888 (cmd == DIOCWFORMAT ? B_WRITE : B_READ), minphys, &auio); 889 fop->df_count -= auio.uio_resid; 890 fop->df_reg[0] = sc->sc_status; 891 fop->df_reg[1] = sc->sc_hpds; 892 fop->df_reg[2] = sc->sc_er1; 893 fop->df_reg[3] = sc->sc_er2; 894 break; 895 } 896 897 #ifdef COMPAT_42 898 case DKIOCHDR: /* do header read/write */ /* XXX */ 899 sc->sc_hdr = 1; 900 break; 901 #endif 902 903 default: 904 error = ENOTTY; 905 break; 906 } 907 return (error); 908 } 909 910 hpformat(bp) 911 struct buf *bp; 912 { 913 bp->b_flags |= B_FORMAT; 914 hpstrategy(bp); 915 } 916 917 hpecc(mi, flag) 918 register struct mba_device *mi; 919 int flag; 920 { 921 register struct mba_regs *mbp = mi->mi_mba; 922 register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv; 923 register struct buf *bp = mi->mi_tab.b_actf; 924 register struct disklabel *lp = &hplabel[mi->mi_unit]; 925 struct hpsoftc *sc = &hpsoftc[mi->mi_unit]; 926 int npf, o; 927 int bn, cn, tn, sn; 928 int bcr; 929 930 bcr = MASKREG(-mbp->mba_bcr); 931 if (bp->b_flags & B_BAD) 932 npf = bp->b_error; 933 else { 934 npf = bp->b_bcount - bcr; 935 /* 936 * Watch out for fractional sector at end of transfer; 937 * want to round up if finished, otherwise round down. 938 */ 939 if (bcr == 0) 940 npf += 511; 941 npf = btodb(npf); 942 } 943 o = (int)bp->b_un.b_addr & PGOFSET; 944 bn = bp->b_blkno; 945 cn = bp->b_cylin; 946 sn = bn % lp->d_secpercyl + npf; 947 tn = sn / lp->d_nsectors; 948 sn %= lp->d_nsectors; 949 cn += tn / lp->d_ntracks; 950 tn %= lp->d_ntracks; 951 bn += npf; 952 switch (flag) { 953 case ECC: { 954 register int i; 955 caddr_t addr; 956 struct pte mpte; 957 int bit, byte, mask; 958 959 npf--; /* because block in error is previous block */ 960 diskerr(bp, "hp", "soft ecc", LOG_WARNING, npf, lp); 961 if (bp->b_flags & B_BAD) 962 addlog(" (on replacement sector %d)", sc->sc_badbn); 963 addlog("\n"); 964 mask = MASKREG(rp->hpec2); 965 i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 966 bit = i&07; 967 i = (i&~07)>>3; 968 byte = i + o; 969 while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) { 970 mpte = mbp->mba_map[npf+btop(byte)]; 971 addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET); 972 putmemc(addr, getmemc(addr)^(mask<<bit)); 973 byte++; 974 i++; 975 bit -= 8; 976 } 977 if (bcr == 0) 978 return (0); 979 npf++; 980 break; 981 } 982 983 case SSE: 984 rp->hpof |= HPOF_SSEI; 985 if (bp->b_flags & B_BAD) { 986 bn = sc->sc_badbn; 987 goto fixregs; 988 } 989 mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 990 break; 991 992 case BSE: 993 if (sc->sc_state == OPENRAW) 994 return (0); 995 if (rp->hpof & HPOF_SSEI) 996 sn++; 997 #ifdef HPBDEBUG 998 if (hpbdebug) 999 log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn); 1000 #endif 1001 if (bp->b_flags & B_BAD) 1002 return (0); 1003 if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0) 1004 return (0); 1005 bp->b_flags |= B_BAD; 1006 bp->b_error = npf + 1; 1007 rp->hpof &= ~HPOF_SSEI; 1008 bn = lp->d_ncylinders * lp->d_secpercyl - 1009 lp->d_nsectors - 1 - bn; 1010 sc->sc_badbn = bn; 1011 fixregs: 1012 cn = bn / lp->d_secpercyl; 1013 sn = bn % lp->d_secpercyl; 1014 tn = sn / lp->d_nsectors; 1015 sn %= lp->d_nsectors; 1016 bcr = bp->b_bcount - (int)ptob(npf); 1017 bcr = MIN(bcr, 512); 1018 mbp->mba_bcr = -bcr; 1019 #ifdef HPBDEBUG 1020 if (hpbdebug) 1021 log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn); 1022 #endif 1023 break; 1024 1025 case CONT: 1026 #ifdef HPBDEBUG 1027 if (hpbdebug) 1028 log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn); 1029 #endif 1030 bp->b_flags &= ~B_BAD; 1031 if ((int)ptob(npf) >= bp->b_bcount) 1032 return (0); 1033 mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf)); 1034 break; 1035 } 1036 rp->hpcs1 = HP_DCLR|HP_GO; 1037 if (rp->hpof & HPOF_SSEI) 1038 sn++; 1039 rp->hpdc = cn; 1040 rp->hpda = (tn<<8) + sn; 1041 mbp->mba_sr = -1; 1042 mbp->mba_var = (int)ptob(npf) + o; 1043 rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO; 1044 mi->mi_tab.b_errcnt = 0; /* error has been corrected */ 1045 sc->sc_blkdone = npf; 1046 return (1); 1047 } 1048 1049 #define DBSIZE 20 1050 1051 hpdump(dev) 1052 dev_t dev; 1053 { 1054 register struct mba_device *mi; 1055 register struct mba_regs *mba; 1056 register struct disklabel *lp; 1057 struct hpdevice *hpaddr; 1058 char *start; 1059 int num, unit; 1060 extern int dumpsize; 1061 1062 num = dumpsize; 1063 start = 0; 1064 unit = hpunit(dev); 1065 if (unit >= NHP) 1066 return (ENXIO); 1067 #define phys(a,b) ((b)((int)(a)&0x7fffffff)) 1068 mi = phys(hpinfo[unit],struct mba_device *); 1069 if (mi == 0 || mi->mi_alive == 0) 1070 return (ENXIO); 1071 lp = &hplabel[unit]; 1072 mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba; 1073 mba->mba_cr = MBCR_INIT; 1074 hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive]; 1075 if ((hpaddr->hpds & HPDS_VV) == 0) { 1076 hpaddr->hpcs1 = HP_DCLR|HP_GO; 1077 hpaddr->hpcs1 = HP_PRESET|HP_GO; 1078 hpaddr->hpof = HPOF_FMT22; 1079 } 1080 if (dumplo + num >= lp->d_partitions[hppart(dev)].p_size) 1081 num = lp->d_partitions[hppart(dev)].p_size - dumplo; 1082 while (num > 0) { 1083 register struct pte *hpte = mba->mba_map; 1084 register int i; 1085 int blk, cn, sn, tn; 1086 daddr_t bn; 1087 1088 blk = num > DBSIZE ? DBSIZE : num; 1089 bn = dumplo + btodb(start); 1090 cn = (bn + lp->d_partitions[hppart(dev)].p_offset) / 1091 lp->d_secpercyl; 1092 sn = bn % lp->d_secpercyl; 1093 tn = sn / lp->d_nsectors; 1094 sn = sn % lp->d_nsectors; 1095 hpaddr->hpdc = cn; 1096 hpaddr->hpda = (tn << 8) + sn; 1097 for (i = 0; i < blk; i++) 1098 *(int *)hpte++ = (btop(start)+i) | PG_V; 1099 mba->mba_sr = -1; 1100 mba->mba_bcr = -(blk*NBPG); 1101 mba->mba_var = 0; 1102 hpaddr->hpcs1 = HP_WCOM | HP_GO; 1103 while ((hpaddr->hpds & HPDS_DRY) == 0) 1104 DELAY(10); 1105 if (hpaddr->hpds&HPDS_ERR) 1106 return (EIO); 1107 start += blk*NBPG; 1108 num -= blk; 1109 } 1110 return (0); 1111 } 1112 1113 hpsize(dev) 1114 dev_t dev; 1115 { 1116 register int unit = hpunit(dev); 1117 struct mba_device *mi; 1118 1119 if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0 || 1120 hpsoftc[unit].sc_state != OPEN) 1121 return (-1); 1122 return ((int)hplabel[unit].d_partitions[hppart(dev)].p_size); 1123 } 1124 1125 #ifdef COMPAT_42 1126 /* 1127 * Compatibility code to fake up pack label 1128 * for unlabeled disks. 1129 */ 1130 struct size { 1131 daddr_t nblocks; 1132 int cyloff; 1133 } rp06_sizes[8] = { 1134 15884, 0, /* A=cyl 0 thru 37 */ 1135 33440, 38, /* B=cyl 38 thru 117 */ 1136 340670, 0, /* C=cyl 0 thru 814 */ 1137 15884, 118, /* D=cyl 118 thru 155 */ 1138 55936, 156, /* E=cyl 156 thru 289 */ 1139 219384, 290, /* F=cyl 290 thru 814 */ 1140 291192, 118, /* G=cyl 118 thru 814 */ 1141 0, 0, 1142 }, rp05_sizes[8] = { 1143 15884, 0, /* A=cyl 0 thru 37 */ 1144 33440, 38, /* B=cyl 38 thru 117 */ 1145 171798, 0, /* C=cyl 0 thru 410 */ 1146 15884, 118, /* D=cyl 118 thru 155 */ 1147 55936, 156, /* E=cyl 156 thru 289 */ 1148 50512, 290, /* F=cyl 290 thru 410 */ 1149 122408, 118, /* G=cyl 118 thru 410 */ 1150 0, 0, 1151 }, rm03_sizes[8] = { 1152 15884, 0, /* A=cyl 0 thru 99 */ 1153 33440, 100, /* B=cyl 100 thru 308 */ 1154 131680, 0, /* C=cyl 0 thru 822 */ 1155 15884, 309, /* D=cyl 309 thru 408 */ 1156 55936, 409, /* E=cyl 409 thru 758 */ 1157 10144, 759, /* F=cyl 759 thru 822 */ 1158 82144, 309, /* G=cyl 309 thru 822 */ 1159 0, 0, 1160 }, rm05_sizes[8] = { 1161 15884, 0, /* A=cyl 0 thru 26 */ 1162 33440, 27, /* B=cyl 27 thru 81 */ 1163 500384, 0, /* C=cyl 0 thru 822 */ 1164 15884, 562, /* D=cyl 562 thru 588 */ 1165 55936, 589, /* E=cyl 589 thru 680 */ 1166 86240, 681, /* F=cyl 681 thru 822 */ 1167 158592, 562, /* G=cyl 562 thru 822 */ 1168 291346, 82, /* H=cyl 82 thru 561 */ 1169 }, rm80_sizes[8] = { 1170 15884, 0, /* A=cyl 0 thru 36 */ 1171 33440, 37, /* B=cyl 37 thru 114 */ 1172 242606, 0, /* C=cyl 0 thru 558 */ 1173 15884, 115, /* D=cyl 115 thru 151 */ 1174 55936, 152, /* E=cyl 152 thru 280 */ 1175 120559, 281, /* F=cyl 281 thru 558 */ 1176 192603, 115, /* G=cyl 115 thru 558 */ 1177 0, 0, 1178 }, rp07_sizes[8] = { 1179 15884, 0, /* A=cyl 0 thru 9 */ 1180 66880, 10, /* B=cyl 10 thru 51 */ 1181 1008000, 0, /* C=cyl 0 thru 629 */ 1182 15884, 235, /* D=cyl 235 thru 244 */ 1183 307200, 245, /* E=cyl 245 thru 436 */ 1184 308650, 437, /* F=cyl 437 thru 629 */ 1185 631850, 235, /* G=cyl 235 thru 629 */ 1186 291346, 52, /* H=cyl 52 thru 234 */ 1187 }, cdc9775_sizes[8] = { 1188 15884, 0, /* A=cyl 0 thru 12 */ 1189 66880, 13, /* B=cyl 13 thru 65 */ 1190 1077760, 0, /* C=cyl 0 thru 841 */ 1191 15884, 294, /* D=cyl 294 thru 306 */ 1192 307200, 307, /* E=cyl 307 thru 546 */ 1193 377440, 547, /* F=cyl 547 thru 841 */ 1194 701280, 294, /* G=cyl 294 thru 841 */ 1195 291346, 66, /* H=cyl 66 thru 293 */ 1196 }, cdc9730_sizes[8] = { 1197 15884, 0, /* A=cyl 0 thru 49 */ 1198 33440, 50, /* B=cyl 50 thru 154 */ 1199 263360, 0, /* C=cyl 0 thru 822 */ 1200 15884, 155, /* D=cyl 155 thru 204 */ 1201 55936, 205, /* E=cyl 205 thru 379 */ 1202 141664, 380, /* F=cyl 380 thru 822 */ 1203 213664, 155, /* G=cyl 155 thru 822 */ 1204 0, 0, 1205 }, capricorn_sizes[8] = { 1206 15884, 0, /* A=cyl 0 thru 31 */ 1207 33440, 32, /* B=cyl 32 thru 97 */ 1208 524288, 0, /* C=cyl 0 thru 1023 */ 1209 15884, 668, /* D=cyl 668 thru 699 */ 1210 55936, 700, /* E=cyl 700 thru 809 */ 1211 109472, 810, /* F=cyl 810 thru 1023 */ 1212 182176, 668, /* G=cyl 668 thru 1023 */ 1213 291346, 98, /* H=cyl 98 thru 667 */ 1214 }, eagle_sizes[8] = { 1215 15884, 0, /* A=cyl 0 thru 16 */ 1216 66880, 17, /* B=cyl 17 thru 86 */ 1217 808320, 0, /* C=cyl 0 thru 841 */ 1218 15884, 391, /* D=cyl 391 thru 407 */ 1219 307200, 408, /* E=cyl 408 thru 727 */ 1220 109296, 728, /* F=cyl 728 thru 841 */ 1221 432816, 391, /* G=cyl 391 thru 841 */ 1222 291346, 87, /* H=cyl 87 thru 390 */ 1223 }, ampex_sizes[8] = { 1224 15884, 0, /* A=cyl 0 thru 26 */ 1225 33440, 27, /* B=cyl 27 thru 81 */ 1226 495520, 0, /* C=cyl 0 thru 814 */ 1227 15884, 562, /* D=cyl 562 thru 588 */ 1228 55936, 589, /* E=cyl 589 thru 680 */ 1229 81312, 681, /* F=cyl 681 thru 814 */ 1230 153664, 562, /* G=cyl 562 thru 814 */ 1231 291346, 82, /* H=cyl 82 thru 561 */ 1232 }, fj2361_sizes[8] = { 1233 15884, 0, /* A=cyl 0 thru 12 */ 1234 66880, 13, /* B=cyl 13 thru 65 */ 1235 1077760, 0, /* C=cyl 0 thru 841 */ 1236 15884, 294, /* D=cyl 294 thru 306 */ 1237 307200, 307, /* E=cyl 307 thru 546 */ 1238 377408, 547, /* F=cyl 547 thru 841 */ 1239 701248, 294, /* G=cyl 294 thru 841 */ 1240 291346, 66, /* H=cyl 66 thru 293 */ 1241 }, fj2361a_sizes[8] = { 1242 15884, 0, /* A=cyl 0 thru 11 */ 1243 66880, 12, /* B=cyl 12 thru 61 */ 1244 1145120, 0, /* C=cyl 0 thru 841 */ 1245 15884, 277, /* D=cyl 277 thru 288 */ 1246 307200, 289, /* E=cyl 289 thru 514 */ 1247 444516, 515, /* F=cyl 515 thru 841 */ 1248 768196, 277, /* G=cyl 277 thru 841 */ 1249 291346, 62, /* H=cyl 62 thru 276 */ 1250 }; 1251 1252 /* 1253 * These variable are all measured in sectors. 1254 * Sdist is how much to "lead" in the search for a desired sector 1255 * (i.e. if want N, search for N-sdist.) 1256 * Maxdist and mindist define the region right before our desired sector within 1257 * which we don't bother searching. We don't search when we are already less 1258 * then maxdist and more than mindist sectors "before" our desired sector. 1259 * Maxdist should be >= sdist. 1260 * 1261 * Beware, sdist, mindist and maxdist are not well tuned 1262 * for many of the drives listed in this table. 1263 * Try patching things with something i/o intensive 1264 * running and watch iostat. 1265 * 1266 * The order of these entries must agree with the indices in hptypes[]. 1267 */ 1268 struct hpst { 1269 short nsect; /* # sectors/track */ 1270 short ntrak; /* # tracks/cylinder */ 1271 short nspc; /* # sector/cylinders */ 1272 short ncyl; /* # cylinders */ 1273 struct size *sizes; /* partition tables */ 1274 short sdist; /* seek distance metric */ 1275 short maxdist; /* boundaries of non-searched area */ 1276 short mindist; /* preceding the target sector */ 1277 char *name; /* name of disk type */ 1278 } hpst[] = { 1279 { 32, 5, 32*5, 823, rm03_sizes, 7, 4, 1, "RM03" }, 1280 { 32, 19, 32*19, 823, rm05_sizes, 7, 4, 1, "RM05" }, 1281 { 22,19, 22*19, 815, rp06_sizes, 7, 4, 1, "RP06"}, 1282 { 31, 14, 31*14, 559, rm80_sizes, 7, 4, 1, "RM80"}, 1283 { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP04"}, 1284 { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP05"}, 1285 { 50, 32, 50*32, 630, rp07_sizes, 15, 8, 3, "RP07"}, 1286 { 1, 1, 1, 1, 0, 0, 0, 0, "ML11A"}, 1287 { 1, 1, 1, 1, 0, 0, 0, 0, "ML11B" }, 1288 { 32, 40, 32*40, 843, cdc9775_sizes, 7, 4, 1, "9775" }, 1289 { 32, 10, 32*10, 823, cdc9730_sizes, 7, 4, 1, "9730-160" }, 1290 { 32, 16, 32*16, 1024, capricorn_sizes,10,4, 3, "capricorn" }, 1291 { 48, 20, 48*20, 842, eagle_sizes, 15, 8, 3, "eagle" }, 1292 { 32, 19, 32*19, 815, ampex_sizes, 7, 4, 1, "9300" }, 1293 { 64, 20, 64*20, 842, fj2361_sizes, 15, 8, 3, "2361" }, 1294 { 68, 20, 68*20, 842, fj2361a_sizes, 15, 8, 3, "2361a" }, 1295 }; 1296 1297 /* 1298 * Map apparent MASSBUS drive type into manufacturer 1299 * specific configuration. For SI controllers this is done 1300 * based on codes in the serial number register. For 1301 * EMULEX controllers, the track and sector attributes are 1302 * used when the drive type is an RM02 (not supported by DEC). 1303 */ 1304 hpmaptype(mi, lp) 1305 register struct mba_device *mi; 1306 register struct disklabel *lp; 1307 { 1308 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv; 1309 register int type = mi->mi_type; 1310 register struct hpst *st; 1311 register i; 1312 1313 /* 1314 * Model-byte processing for SI controllers. 1315 * NB: Only deals with RM03 and RM05 emulations. 1316 */ 1317 if (type == HPDT_RM03 || type == HPDT_RM05) { 1318 int hpsn = hpaddr->hpsn; 1319 1320 if ((hpsn & SIMB_LU) == mi->mi_drive) 1321 switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) { 1322 1323 case SI9775D: 1324 type = HPDT_9775; 1325 break; 1326 1327 case SI9730D: 1328 type = HPDT_9730; 1329 break; 1330 1331 case SI9766: 1332 type = HPDT_RM05; 1333 break; 1334 1335 case SI9762: 1336 type = HPDT_RM03; 1337 break; 1338 1339 case SICAPD: 1340 type = HPDT_CAPRICORN; 1341 break; 1342 1343 case SI9751D: 1344 type = HPDT_EAGLE; 1345 break; 1346 } 1347 mi->mi_type = type; 1348 } 1349 1350 /* 1351 * EMULEX SC750 or SC780. Poke the holding register. 1352 */ 1353 if (type == HPDT_RM02) { 1354 int nsectors, ntracks, ncyl; 1355 1356 hpaddr->hpof = HPOF_FMT22; 1357 mbclrattn(mi); 1358 hpaddr->hpcs1 = HP_NOP; 1359 hpaddr->hphr = HPHR_MAXTRAK; 1360 ntracks = MASKREG(hpaddr->hphr) + 1; 1361 DELAY(100); 1362 hpaddr->hpcs1 = HP_NOP; 1363 hpaddr->hphr = HPHR_MAXSECT; 1364 nsectors = MASKREG(hpaddr->hphr) + 1; 1365 DELAY(100); 1366 hpaddr->hpcs1 = HP_NOP; 1367 hpaddr->hphr = HPHR_MAXCYL; 1368 ncyl = MASKREG(hpaddr->hphr) + 1; 1369 for (type = 0; hptypes[type] != 0; type++) 1370 if (hpst[type].nsect == nsectors && 1371 hpst[type].ntrak == ntracks && 1372 hpst[type].ncyl == ncyl) 1373 break; 1374 1375 hpaddr->hpcs1 = HP_DCLR|HP_GO; 1376 mbclrattn(mi); /* conservative */ 1377 if (hptypes[type] == 0) { 1378 printf("hp%d: %d sectors, %d tracks, %d cylinders: unknown device\n", 1379 mi->mi_unit, nsectors, ntracks, ncyl); 1380 lp->d_nsectors = nsectors; 1381 lp->d_ntracks = ntracks; 1382 lp->d_ncylinders = ncyl; 1383 lp->d_secpercyl = nsectors*ntracks; 1384 lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders; 1385 #ifdef notdef /* set elsewhere */ 1386 lp->d_npartitions = 1; 1387 lp->d_partitions[0].p_offset = 0; 1388 #endif 1389 lp->d_partitions[0].p_size = lp->d_secperunit; 1390 return (0); 1391 } 1392 mi->mi_type = type; 1393 } 1394 1395 /* 1396 * set up minimal disk label. 1397 */ 1398 st = &hpst[type]; 1399 lp->d_nsectors = st->nsect; 1400 lp->d_ntracks = st->ntrak; 1401 lp->d_secpercyl = st->nspc; 1402 lp->d_ncylinders = st->ncyl; 1403 lp->d_secperunit = st->nspc * st->ncyl; 1404 lp->d_sdist = st->sdist; 1405 lp->d_mindist = st->mindist; 1406 lp->d_maxdist = st->maxdist; 1407 bcopy(hpst[type].name, lp->d_typename, sizeof(lp->d_typename)); 1408 lp->d_npartitions = 8; 1409 for (i = 0; i < 8; i++) { 1410 lp->d_partitions[i].p_offset = st->sizes[i].cyloff * 1411 lp->d_secpercyl; 1412 lp->d_partitions[i].p_size = st->sizes[i].nblocks; 1413 } 1414 return (1); 1415 } 1416 #endif COMPAT_42 1417 #endif 1418