1 /* 2 * Copyright (c) 1987 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 * @(#)uda.c 7.10 (Berkeley) 11/12/87 7 * 8 */ 9 10 /* 11 * UDA50/MSCP device driver 12 */ 13 14 #define POLLSTATS 15 16 /* 17 * TODO 18 * write bad block forwarding code 19 */ 20 21 #include "ra.h" 22 23 #if NUDA > 0 24 25 /* 26 * CONFIGURATION OPTIONS. The next three defines are tunable -- tune away! 27 * 28 * COMPAT_42 enables 4.2/4.3 compatibility (label mapping) 29 * 30 * NRSPL2 and NCMDL2 control the number of response and command 31 * packets respectively. They may be any value from 0 to 7, though 32 * setting them higher than 5 is unlikely to be of any value. 33 * If you get warnings about your command ring being too small, 34 * try increasing the values by one. 35 * 36 * MAXUNIT controls the maximum unit number (number of drives per 37 * controller) we are prepared to handle. 38 * 39 * DEFAULT_BURST must be at least 1. 40 */ 41 #define COMPAT_42 42 43 #define NRSPL2 5 /* log2 number of response packets */ 44 #define NCMDL2 5 /* log2 number of command packets */ 45 #define MAXUNIT 8 /* maximum allowed unit number */ 46 #define DEFAULT_BURST 4 /* default DMA burst size */ 47 48 #include "../machine/pte.h" 49 50 #include "param.h" 51 #include "systm.h" 52 #include "buf.h" 53 #include "conf.h" 54 #include "dir.h" 55 #include "file.h" 56 #include "ioctl.h" 57 #include "user.h" 58 #include "map.h" 59 #include "vm.h" 60 #include "dkstat.h" 61 #include "cmap.h" 62 #include "disklabel.h" 63 #include "syslog.h" 64 #include "stat.h" 65 66 #include "../vax/cpu.h" 67 #include "ubareg.h" 68 #include "ubavar.h" 69 70 #define NRSP (1 << NRSPL2) 71 #define NCMD (1 << NCMDL2) 72 73 #include "udareg.h" 74 #include "../vax/mscp.h" 75 #include "../vax/mscpvar.h" 76 #include "../vax/mtpr.h" 77 78 /* 79 * Backwards compatibility: Reuse the old names. Should fix someday. 80 */ 81 #define udaprobe udprobe 82 #define udaslave udslave 83 #define udaattach udattach 84 #define udaopen udopen 85 #define udaclose udclose 86 #define udastrategy udstrategy 87 #define udaread udread 88 #define udawrite udwrite 89 #define udaioctl udioctl 90 #define udareset udreset 91 #define udaintr udintr 92 #define udadump uddump 93 #define udasize udsize 94 95 /* 96 * UDA communications area and MSCP packet pools, per controller. 97 */ 98 struct uda { 99 struct udaca uda_ca; /* communications area */ 100 struct mscp uda_rsp[NRSP]; /* response packets */ 101 struct mscp uda_cmd[NCMD]; /* command packets */ 102 } uda[NUDA]; 103 104 /* 105 * Software status, per controller. 106 */ 107 struct uda_softc { 108 struct uda *sc_uda; /* Unibus address of uda struct */ 109 short sc_state; /* UDA50 state; see below */ 110 short sc_flags; /* flags; see below */ 111 int sc_micro; /* microcode revision */ 112 int sc_ivec; /* interrupt vector address */ 113 struct mscp_info sc_mi;/* MSCP info (per mscpvar.h) */ 114 #ifndef POLLSTATS 115 int sc_wticks; /* watchdog timer ticks */ 116 #else 117 short sc_wticks; 118 short sc_ncmd; 119 #endif 120 } uda_softc[NUDA]; 121 122 #ifdef POLLSTATS 123 struct udastats { 124 int ncmd; 125 int cmd[NCMD + 1]; 126 } udastats = { NCMD + 1 }; 127 #endif 128 129 /* 130 * Controller states 131 */ 132 #define ST_IDLE 0 /* uninitialised */ 133 #define ST_STEP1 1 /* in `STEP 1' */ 134 #define ST_STEP2 2 /* in `STEP 2' */ 135 #define ST_STEP3 3 /* in `STEP 3' */ 136 #define ST_SETCHAR 4 /* in `Set Controller Characteristics' */ 137 #define ST_RUN 5 /* up and running */ 138 139 /* 140 * Flags 141 */ 142 #define SC_MAPPED 0x01 /* mapped in Unibus I/O space */ 143 #define SC_INSTART 0x02 /* inside udastart() */ 144 #define SC_GRIPED 0x04 /* griped about cmd ring too small */ 145 #define SC_INSLAVE 0x08 /* inside udaslave() */ 146 #define SC_DOWAKE 0x10 /* wakeup when ctlr init done */ 147 #define SC_STARTPOLL 0x20 /* need to initiate polling */ 148 149 /* 150 * Device to unit number and partition and back 151 */ 152 #define UNITSHIFT 3 153 #define UNITMASK 7 154 #define udaunit(dev) (minor(dev) >> UNITSHIFT) 155 #define udapart(dev) (minor(dev) & UNITMASK) 156 #define udaminor(u, p) (((u) << UNITSHIFT) | (p)) 157 158 /* 159 * Drive status, per drive 160 */ 161 struct ra_info { 162 daddr_t ra_dsize; /* size in sectors */ 163 u_long ra_type; /* drive type */ 164 u_long ra_mediaid; /* media id */ 165 int ra_state; /* open/closed state */ 166 struct ra_geom { /* geometry information */ 167 u_short rg_nsectors; /* sectors/track */ 168 u_short rg_ngroups; /* track groups */ 169 u_short rg_ngpc; /* groups/cylinder */ 170 u_short rg_ntracks; /* ngroups*ngpc */ 171 u_short rg_ncyl; /* ra_dsize/ntracks/nsectors */ 172 #ifdef notyet 173 u_short rg_rctsize; /* size of rct */ 174 u_short rg_rbns; /* replacement blocks per track */ 175 u_short rg_nrct; /* number of rct copies */ 176 #endif 177 } ra_geom; 178 u_long ra_openpart; /* partitions open */ 179 u_long ra_bopenpart; /* block partitions open */ 180 u_long ra_copenpart; /* character partitions open */ 181 } ra_info[NRA]; 182 183 /* 184 * Software state, per drive 185 */ 186 #define CLOSED 0 187 #define WANTOPEN 1 188 #define RDLABEL 2 189 #define OPEN 3 190 #define OPENRAW 4 191 192 /* 193 * Definition of the driver for autoconf. 194 */ 195 int udaprobe(), udaslave(), udaattach(), udadgo(), udaintr(); 196 struct uba_ctlr *udaminfo[NUDA]; 197 struct uba_device *udadinfo[NRA]; 198 struct disklabel udalabel[NRA]; 199 200 u_short udastd[] = { 0772150, 0772550, 0777550, 0 }; 201 struct uba_driver udadriver = 202 { udaprobe, udaslave, udaattach, udadgo, udastd, "ra", udadinfo, "uda", 203 udaminfo }; 204 205 /* 206 * More driver definitions, for generic MSCP code. 207 */ 208 int udadgram(), udactlrdone(), udaunconf(), udaiodone(); 209 int udaonline(), udagotstatus(), udaioerror(), udareplace(), udabb(); 210 211 struct buf udautab[NRA]; /* per drive transfer queue */ 212 213 struct mscp_driver udamscpdriver = 214 { MAXUNIT, NRA, UNITSHIFT, udautab, udadinfo, 215 udadgram, udactlrdone, udaunconf, udaiodone, 216 udaonline, udagotstatus, udareplace, udaioerror, udabb, 217 "uda", "ra" }; 218 219 /* 220 * Miscellaneous private variables. 221 */ 222 char udasr_bits[] = UDASR_BITS; 223 224 struct uba_device *udaip[NUDA][MAXUNIT]; 225 /* inverting pointers: ctlr & unit => Unibus 226 device pointer */ 227 228 int udaburst[NUDA] = { 0 }; /* burst size, per UDA50, zero => default; 229 in data space so patchable via adb */ 230 231 struct mscp udaslavereply; /* get unit status response packet, set 232 for udaslave by udaunconf, via udaintr */ 233 234 static struct uba_ctlr *probeum;/* this is a hack---autoconf should pass ctlr 235 info to slave routine; instead, we remember 236 the last ctlr argument to probe */ 237 238 int udawstart, udawatch(); /* watchdog timer */ 239 240 /* 241 * Externals 242 */ 243 int wakeup(); 244 int hz; 245 246 /* 247 * Poke at a supposed UDA50 to see if it is there. 248 * This routine duplicates some of the code in udainit() only 249 * because autoconf has not set up the right information yet. 250 * We have to do everything `by hand'. 251 */ 252 udaprobe(reg, ctlr, um) 253 caddr_t reg; 254 int ctlr; 255 struct uba_ctlr *um; 256 { 257 register int br, cvec; 258 register struct uda_softc *sc; 259 register struct udadevice *udaddr; 260 register struct mscp_info *mi; 261 int timeout, tries; 262 263 #ifdef VAX750 264 /* 265 * The UDA50 wants to share BDPs on 750s, but not on 780s or 266 * 8600s. (730s have no BDPs anyway.) Toward this end, we 267 * here set the `keep bdp' flag in the per-driver information 268 * if this is a 750. (We just need to do it once, but it is 269 * easiest to do it now, for each UDA50.) 270 */ 271 if (cpu == VAX_750) 272 udadriver.ud_keepbdp = 1; 273 #endif 274 275 probeum = um; /* remember for udaslave() */ 276 #ifdef lint 277 br = 0; cvec = br; br = cvec; udaintr(0); 278 #endif 279 /* 280 * Set up the controller-specific generic MSCP driver info. 281 * Note that this should really be done in the (nonexistent) 282 * controller attach routine. 283 */ 284 sc = &uda_softc[ctlr]; 285 mi = &sc->sc_mi; 286 mi->mi_md = &udamscpdriver; 287 mi->mi_ctlr = um->um_ctlr; 288 mi->mi_tab = &um->um_tab; 289 mi->mi_ip = udaip[ctlr]; 290 mi->mi_cmd.mri_size = NCMD; 291 mi->mi_cmd.mri_desc = uda[ctlr].uda_ca.ca_cmddsc; 292 mi->mi_cmd.mri_ring = uda[ctlr].uda_cmd; 293 mi->mi_rsp.mri_size = NRSP; 294 mi->mi_rsp.mri_desc = uda[ctlr].uda_ca.ca_rspdsc; 295 mi->mi_rsp.mri_ring = uda[ctlr].uda_rsp; 296 mi->mi_wtab.av_forw = mi->mi_wtab.av_back = &mi->mi_wtab; 297 298 /* 299 * More controller specific variables. Again, this should 300 * be in the controller attach routine. 301 */ 302 if (udaburst[ctlr] == 0) 303 udaburst[ctlr] = DEFAULT_BURST; 304 305 /* 306 * Get an interrupt vector. Note that even if the controller 307 * does not respond, we keep the vector. This is not a serious 308 * problem; but it would be easily fixed if we had a controller 309 * attach routine. Sigh. 310 */ 311 sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 312 udaddr = (struct udadevice *) reg; 313 314 /* 315 * Initialise the controller (partially). The UDA50 programmer's 316 * manual states that if initialisation fails, it should be retried 317 * at least once, but after a second failure the port should be 318 * considered `down'; it also mentions that the controller should 319 * initialise within ten seconds. Or so I hear; I have not seen 320 * this manual myself. 321 */ 322 tries = 0; 323 again: 324 udaddr->udaip = 0; /* start initialisation */ 325 timeout = todr() + 1000; /* timeout in 10 seconds */ 326 while ((udaddr->udasa & UDA_STEP1) == 0) 327 if (todr() > timeout) 328 goto bad; 329 udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 330 (sc->sc_ivec >> 2); 331 while ((udaddr->udasa & UDA_STEP2) == 0) 332 if (todr() > timeout) 333 goto bad; 334 335 /* should have interrupted by now */ 336 #ifdef VAX630 337 if (cpu == VAX_630) 338 br = 0x15; /* screwy interrupt structure */ 339 #endif 340 return (sizeof (struct udadevice)); 341 bad: 342 if (++tries < 2) 343 goto again; 344 return (0); 345 } 346 347 /* 348 * Find a slave. We allow wildcard slave numbers (something autoconf 349 * is not really prepared to deal with); and we need to know the 350 * controller number to talk to the UDA. For the latter, we keep 351 * track of the last controller probed, since a controller probe 352 * immediately precedes all slave probes for that controller. For the 353 * former, we simply put the unit number into ui->ui_slave after we 354 * have found one. 355 * 356 * Note that by the time udaslave is called, the interrupt vector 357 * for the UDA50 has been set up (so that udaunconf() will be called). 358 */ 359 udaslave(ui, reg) 360 register struct uba_device *ui; 361 caddr_t reg; 362 { 363 register struct uba_ctlr *um = probeum; 364 register struct mscp *mp; 365 register struct uda_softc *sc; 366 register struct ra_info *ra; 367 int next = 0, type, timeout, tries, i; 368 369 #ifdef lint 370 i = 0; i = i; 371 #endif 372 /* 373 * Make sure the controller is fully initialised, by waiting 374 * for it if necessary. 375 */ 376 sc = &uda_softc[um->um_ctlr]; 377 if (sc->sc_state == ST_RUN) 378 goto findunit; 379 tries = 0; 380 again: 381 if (udainit(ui->ui_ctlr)) 382 return (0); 383 timeout = todr() + 1000; /* 10 seconds */ 384 while (todr() < timeout) 385 if (sc->sc_state == ST_RUN) /* made it */ 386 goto findunit; 387 if (++tries < 2) 388 goto again; 389 printf("uda%d: controller hung\n", um->um_ctlr); 390 return (0); 391 392 /* 393 * The controller is all set; go find the unit. Grab an 394 * MSCP packet and send out a Get Unit Status command, with 395 * the `next unit' modifier if we are looking for a generic 396 * unit. We set the `in slave' flag so that udaunconf() 397 * knows to copy the response to `udaslavereply'. 398 */ 399 findunit: 400 udaslavereply.mscp_opcode = 0; 401 sc->sc_flags |= SC_INSLAVE; 402 if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) 403 panic("udaslave"); /* `cannot happen' */ 404 mp->mscp_opcode = M_OP_GETUNITST; 405 if (ui->ui_slave == '?') { 406 mp->mscp_unit = next; 407 mp->mscp_modifier = M_GUM_NEXTUNIT; 408 } else { 409 mp->mscp_unit = ui->ui_slave; 410 mp->mscp_modifier = 0; 411 } 412 *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 413 i = ((struct udadevice *) reg)->udaip; /* initiate polling */ 414 mp = &udaslavereply; 415 timeout = todr() + 1000; 416 while (todr() < timeout) 417 if (mp->mscp_opcode) 418 goto gotit; 419 printf("uda%d: no response to Get Unit Status request\n", 420 um->um_ctlr); 421 sc->sc_flags &= ~SC_INSLAVE; 422 return (0); 423 424 gotit: 425 sc->sc_flags &= ~SC_INSLAVE; 426 427 /* 428 * Got a slave response. If the unit is there, use it. 429 */ 430 switch (mp->mscp_status & M_ST_MASK) { 431 432 case M_ST_SUCCESS: /* worked */ 433 case M_ST_AVAILABLE: /* found another drive */ 434 break; /* use it */ 435 436 case M_ST_OFFLINE: 437 /* 438 * Figure out why it is off line. It may be because 439 * it is nonexistent, or because it is spun down, or 440 * for some other reason. 441 */ 442 switch (mp->mscp_status & ~M_ST_MASK) { 443 444 case M_OFFLINE_UNKNOWN: 445 /* 446 * No such drive, and there are none with 447 * higher unit numbers either, if we are 448 * using M_GUM_NEXTUNIT. 449 */ 450 return (0); 451 452 case M_OFFLINE_UNMOUNTED: 453 /* 454 * The drive is not spun up. Use it anyway. 455 * 456 * N.B.: this seems to be a common occurrance 457 * after a power failure. The first attempt 458 * to bring it on line seems to spin it up 459 * (and thus takes several minutes). Perhaps 460 * we should note here that the on-line may 461 * take longer than usual. 462 */ 463 break; 464 465 default: 466 /* 467 * In service, or something else equally unusable. 468 */ 469 printf("uda%d: unit %d off line: ", um->um_ctlr, 470 mp->mscp_unit); 471 mscp_printevent(mp); 472 goto try_another; 473 } 474 break; 475 476 default: 477 printf("uda%d: unable to get unit status: ", um->um_ctlr); 478 mscp_printevent(mp); 479 return (0); 480 } 481 482 /* 483 * Does this ever happen? What (if anything) does it mean? 484 */ 485 if (mp->mscp_unit < next) { 486 printf("uda%d: unit %d, next %d\n", 487 um->um_ctlr, mp->mscp_unit, next); 488 return (0); 489 } 490 491 if (mp->mscp_unit >= MAXUNIT) { 492 printf("uda%d: cannot handle unit number %d (max is %d)\n", 493 um->um_ctlr, mp->mscp_unit, MAXUNIT - 1); 494 return (0); 495 } 496 497 /* 498 * See if we already handle this drive. 499 * (Only likely if ui->ui_slave=='?'.) 500 */ 501 if (udaip[um->um_ctlr][mp->mscp_unit] != NULL) { 502 try_another: 503 if (ui->ui_slave != '?') 504 return (0); 505 next = mp->mscp_unit + 1; 506 goto findunit; 507 } 508 509 /* 510 * Voila! 511 */ 512 uda_rasave(ui->ui_unit, mp, 0); 513 ui->ui_flags = 0; /* not on line, nor anything else */ 514 ui->ui_slave = mp->mscp_unit; 515 return (1); 516 } 517 518 /* 519 * Attach a found slave. Make sure the watchdog timer is running. 520 * If this disk is being profiled, fill in the `mspw' value (used by 521 * what?). Set up the inverting pointer, and attempt to bring the 522 * drive on line and read its label. 523 */ 524 udaattach(ui) 525 register struct uba_device *ui; 526 { 527 register int unit = ui->ui_unit; 528 529 if (udawstart == 0) { 530 timeout(udawatch, (caddr_t) 0, hz); 531 udawstart++; 532 } 533 if (ui->ui_dk >= 0) 534 dk_mspw[ui->ui_dk] = 1.0 / (60 * 31 * 256); /* approx */ 535 udaip[ui->ui_ctlr][ui->ui_slave] = ui; 536 if (uda_rainit(ui, 0)) 537 printf("ra%d: offline\n", unit); 538 else { 539 printf("ra%d: %s\n", unit, udalabel[unit].d_typename); 540 #ifdef notyet 541 addswap(makedev(UDADEVNUM, udaminor(unit, 0)), &udalabel[unit]); 542 #endif 543 } 544 } 545 546 /* 547 * Initialise a UDA50. Return true iff something goes wrong. 548 */ 549 udainit(ctlr) 550 int ctlr; 551 { 552 register struct uda_softc *sc; 553 register struct udadevice *udaddr; 554 struct uba_ctlr *um; 555 int timo, ubinfo; 556 557 sc = &uda_softc[ctlr]; 558 um = udaminfo[ctlr]; 559 if ((sc->sc_flags & SC_MAPPED) == 0) { 560 /* 561 * Map the communication area and command and 562 * response packets into Unibus space. 563 */ 564 ubinfo = uballoc(um->um_ubanum, (caddr_t) &uda[ctlr], 565 sizeof (struct uda), UBA_CANTWAIT); 566 if (ubinfo == 0) { 567 printf("uda%d: uballoc map failed\n", ctlr); 568 return (-1); 569 } 570 sc->sc_uda = (struct uda *) (ubinfo & 0x3ffff); 571 sc->sc_flags |= SC_MAPPED; 572 } 573 574 /* 575 * While we are thinking about it, reset the next command 576 * and response indicies. 577 */ 578 sc->sc_mi.mi_cmd.mri_next = 0; 579 sc->sc_mi.mi_rsp.mri_next = 0; 580 581 /* 582 * Start up the hardware initialisation sequence. 583 */ 584 #define STEP0MASK (UDA_ERR | UDA_STEP4 | UDA_STEP3 | UDA_STEP2 | \ 585 UDA_STEP1 | UDA_NV) 586 587 sc->sc_state = ST_IDLE; /* in case init fails */ 588 udaddr = (struct udadevice *) um->um_addr; 589 udaddr->udaip = 0; 590 timo = todr() + 1000; 591 while ((udaddr->udasa & STEP0MASK) == 0) { 592 if (todr() > timo) { 593 printf("uda%d: timeout during init\n", ctlr); 594 return (-1); 595 } 596 } 597 if ((udaddr->udasa & STEP0MASK) != UDA_STEP1) { 598 printf("uda%d: init failed, sa=%b\n", ctlr, 599 udaddr->udasa, udasr_bits); 600 return (-1); 601 } 602 603 /* 604 * Success! Record new state, and start step 1 initialisation. 605 * The rest is done in the interrupt handler. 606 */ 607 sc->sc_state = ST_STEP1; 608 udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 609 (sc->sc_ivec >> 2); 610 return (0); 611 } 612 613 /* 614 * Open a drive. 615 */ 616 /*ARGSUSED*/ 617 udaopen(dev, flag, fmt) 618 dev_t dev; 619 int flag, fmt; 620 { 621 register int unit; 622 register struct uba_device *ui; 623 register struct uda_softc *sc; 624 register struct disklabel *lp; 625 register struct partition *pp; 626 register struct ra_info *ra; 627 int s, i, part, mask, error = 0; 628 daddr_t start, end; 629 630 /* 631 * Make sure this is a reasonable open request. 632 */ 633 unit = udaunit(dev); 634 if (unit >= NRA || (ui = udadinfo[unit]) == 0 || ui->ui_alive == 0) 635 return (ENXIO); 636 637 /* 638 * Make sure the controller is running, by (re)initialising it if 639 * necessary. 640 */ 641 sc = &uda_softc[ui->ui_ctlr]; 642 s = spl5(); 643 if (sc->sc_state != ST_RUN) { 644 if (sc->sc_state == ST_IDLE && udainit(ui->ui_ctlr)) { 645 splx(s); 646 return (EIO); 647 } 648 /* 649 * In case it does not come up, make sure we will be 650 * restarted in 10 seconds. This corresponds to the 651 * 10 second timeouts in udaprobe() and udaslave(). 652 */ 653 sc->sc_flags |= SC_DOWAKE; 654 timeout(wakeup, (caddr_t) sc, 10 * hz); 655 sleep((caddr_t) sc, PRIBIO); 656 if (sc->sc_state != ST_RUN) { 657 splx(s); 658 printf("uda%d: controller hung\n", ui->ui_ctlr); 659 return (EIO); 660 } 661 untimeout(wakeup, (caddr_t) sc); 662 } 663 664 /* 665 * Wait for the state to settle 666 */ 667 ra = &ra_info[unit]; 668 while (ra->ra_state != OPEN && ra->ra_state != OPENRAW && 669 ra->ra_state != CLOSED) 670 sleep((caddr_t)ra, PZERO + 1); 671 672 /* 673 * If not on line, or we are not sure of the label, reinitialise 674 * the drive. 675 */ 676 if ((ui->ui_flags & UNIT_ONLINE) == 0 || 677 (ra->ra_state != OPEN && ra->ra_state != OPENRAW)) 678 error = uda_rainit(ui, flag); 679 splx(s); 680 if (error) 681 return (error); 682 683 part = udapart(dev); 684 lp = &udalabel[unit]; 685 if (part >= lp->d_npartitions) 686 return (ENXIO); 687 /* 688 * Warn if a partition is opened that overlaps another 689 * already open, unless either is the `raw' partition 690 * (whole disk). 691 */ 692 #define RAWPART 2 /* 'c' partition */ /* XXX */ 693 mask = 1 << part; 694 if ((ra->ra_openpart & mask) == 0 && part != RAWPART) { 695 pp = &lp->d_partitions[part]; 696 start = pp->p_offset; 697 end = pp->p_offset + pp->p_size; 698 for (pp = lp->d_partitions, i = 0; 699 i < lp->d_npartitions; pp++, i++) { 700 if (pp->p_offset + pp->p_size <= start || 701 pp->p_offset >= end || i == RAWPART) 702 continue; 703 if (ra->ra_openpart & (1 << i)) 704 log(LOG_WARNING, 705 "ra%d%c: overlaps open partition (%c)\n", 706 unit, part + 'a', i + 'a'); 707 } 708 } 709 switch (fmt) { 710 case S_IFCHR: 711 ra->ra_copenpart |= mask; 712 break; 713 case S_IFBLK: 714 ra->ra_bopenpart |= mask; 715 break; 716 } 717 ra->ra_openpart |= mask; 718 return (0); 719 } 720 721 udaclose(dev, flags, fmt) 722 dev_t dev; 723 int flags, fmt; 724 { 725 register int unit = udaunit(dev); 726 register struct ra_info *ra = &ra_info[unit]; 727 int s, mask = (1 << udapart(dev)); 728 729 switch (fmt) { 730 case S_IFCHR: 731 ra->ra_copenpart &= ~mask; 732 break; 733 case S_IFBLK: 734 ra->ra_bopenpart &= ~mask; 735 break; 736 } 737 ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 738 739 /* 740 * Should wait for I/O to complete on this partition even if 741 * others are open, but wait for work on blkflush(). 742 */ 743 if (ra->ra_openpart == 0) { 744 s = spl5(); 745 while (udautab[unit].b_actf) 746 sleep((caddr_t)&udautab[unit], PZERO - 1); 747 splx(s); 748 ra->ra_state = CLOSED; 749 } 750 return (0); 751 } 752 753 /* 754 * Initialise a drive. If it is not already, bring it on line, 755 * and set a timeout on it in case it fails to respond. 756 * When on line, read in the pack label. 757 */ 758 uda_rainit(ui, flags) 759 register struct uba_device *ui; 760 int flags; 761 { 762 register struct uda_softc *sc = &uda_softc[ui->ui_ctlr]; 763 register struct disklabel *lp; 764 register struct mscp *mp; 765 register int unit = ui->ui_unit; 766 register struct ra_info *ra; 767 char *msg, *readdisklabel(); 768 int s, i, udastrategy(); 769 extern int cold; 770 771 ra = &ra_info[unit]; 772 if ((ui->ui_flags & UNIT_ONLINE) == 0) { 773 mp = mscp_getcp(&sc->sc_mi, MSCP_WAIT); 774 mp->mscp_opcode = M_OP_ONLINE; 775 mp->mscp_unit = ui->ui_slave; 776 mp->mscp_cmdref = (long)&ui->ui_flags; 777 *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 778 ra->ra_state = WANTOPEN; 779 if (!cold) 780 s = spl5(); 781 i = ((struct udadevice *)ui->ui_addr)->udaip; 782 783 if (cold) { 784 i = todr() + 1000; 785 while ((ui->ui_flags & UNIT_ONLINE) == 0) 786 if (todr() > i) 787 break; 788 } else { 789 timeout(wakeup, (caddr_t)&ui->ui_flags, 10 * hz); 790 sleep((caddr_t)&ui->ui_flags, PSWP + 1); 791 splx(s); 792 untimeout(wakeup, (caddr_t)&ui->ui_flags); 793 } 794 if (ra->ra_state != OPENRAW) { 795 ra->ra_state = CLOSED; 796 wakeup((caddr_t)ra); 797 return (EIO); 798 } 799 } 800 801 lp = &udalabel[unit]; 802 lp->d_secsize = DEV_BSIZE; 803 lp->d_secperunit = ra->ra_dsize; 804 805 if (flags & O_NDELAY) 806 return (0); 807 ra->ra_state = RDLABEL; 808 /* 809 * Set up default sizes until we have the label, or longer 810 * if there is none. Set secpercyl, as readdisklabel wants 811 * to compute b_cylin (although we do not need it). 812 */ 813 lp->d_secpercyl = 1; 814 lp->d_npartitions = 1; 815 lp->d_partitions[0].p_size = lp->d_secperunit; 816 lp->d_partitions[0].p_offset = 0; 817 818 /* 819 * Read pack label. 820 */ 821 if ((msg = readdisklabel(udaminor(unit, 0), udastrategy, lp)) != NULL) { 822 log(LOG_ERR, "ra%d: %s\n", unit, msg); 823 #ifdef COMPAT_42 824 if (udamaptype(unit, lp)) 825 ra->ra_state = OPEN; 826 else 827 ra->ra_state = OPENRAW; 828 #else 829 ra->ra_state = OPENRAW; 830 /* uda_makefakelabel(ra, lp); */ 831 #endif 832 } else 833 ra->ra_state = OPEN; 834 wakeup((caddr_t)ra); 835 return (0); 836 } 837 838 /* 839 * Copy the geometry information for the given ra from a 840 * GET UNIT STATUS response. If check, see if it changed. 841 */ 842 uda_rasave(unit, mp, check) 843 int unit; 844 register struct mscp *mp; 845 int check; 846 { 847 register struct ra_info *ra = &ra_info[unit]; 848 849 if (check && ra->ra_type != mp->mscp_guse.guse_drivetype) { 850 printf("ra%d: changed types! was %d now %d\n", 851 ra->ra_type, mp->mscp_guse.guse_drivetype); 852 ra->ra_state = CLOSED; /* ??? */ 853 } 854 ra->ra_type = mp->mscp_guse.guse_drivetype; 855 ra->ra_mediaid = mp->mscp_guse.guse_mediaid; 856 ra->ra_geom.rg_nsectors = mp->mscp_guse.guse_nspt; 857 ra->ra_geom.rg_ngroups = mp->mscp_guse.guse_group; 858 ra->ra_geom.rg_ngpc = mp->mscp_guse.guse_ngpc; 859 ra->ra_geom.rg_ntracks = ra->ra_geom.rg_ngroups * ra->ra_geom.rg_ngpc; 860 /* ra_geom.rg_ncyl cannot be computed until we have ra_dsize */ 861 #ifdef notyet 862 ra->ra_geom.rg_rctsize = mp->mscp_guse.guse_rctsize; 863 ra->ra_geom.rg_rbns = mp->mscp_guse.guse_nrpt; 864 ra->ra_geom.rg_nrct = mp->mscp_guse.guse_nrct; 865 #endif 866 } 867 868 /* 869 * Queue a transfer request, and if possible, hand it to the controller. 870 * 871 * This routine is broken into two so that the internal version 872 * udastrat1() can be called by the (nonexistent, as yet) bad block 873 * revectoring routine. 874 */ 875 udastrategy(bp) 876 register struct buf *bp; 877 { 878 register int unit; 879 register struct uba_device *ui; 880 register struct disklabel *lp; 881 register struct ra_info *ra; 882 struct partition *pp; 883 int p; 884 daddr_t sz, maxsz; 885 886 /* 887 * Make sure this is a reasonable drive to use. 888 */ 889 if ((unit = udaunit(bp->b_dev)) >= NRA || 890 (ui = udadinfo[unit]) == NULL || ui->ui_alive == 0 || 891 (ra = &ra_info[unit])->ra_state == CLOSED) { 892 bp->b_error = ENXIO; 893 goto bad; 894 } 895 896 /* 897 * If drive is open `raw' or reading label, let it at it. 898 */ 899 if (ra->ra_state < OPEN) { 900 udastrat1(bp); 901 return; 902 } 903 p = udapart(bp->b_dev); 904 if ((ra->ra_openpart & (1 << p)) == 0) /* can't happen? */ 905 panic("udastrategy"); 906 /* alternatively, ENODEV */ 907 908 /* 909 * Determine the size of the transfer, and make sure it is 910 * within the boundaries of the partition. 911 */ 912 pp = &udalabel[unit].d_partitions[p]; 913 maxsz = pp->p_size; 914 if (pp->p_offset + pp->p_size > ra->ra_dsize) 915 maxsz = ra->ra_dsize - pp->p_offset; 916 sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 917 if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { 918 /* if exactly at end of disk, return an EOF */ 919 if (bp->b_blkno == maxsz) { 920 bp->b_resid = bp->b_bcount; 921 biodone(bp); 922 return; 923 } 924 /* or truncate if part of it fits */ 925 sz = maxsz - bp->b_blkno; 926 if (sz <= 0) { 927 bp->b_error = EINVAL; /* or hang it up */ 928 goto bad; 929 } 930 bp->b_bcount = sz << DEV_BSHIFT; 931 } 932 udastrat1(bp); 933 return; 934 bad: 935 bp->b_flags |= B_ERROR; 936 biodone(bp); 937 } 938 939 /* 940 * Work routine for udastrategy. 941 */ 942 udastrat1(bp) 943 register struct buf *bp; 944 { 945 register int unit = udaunit(bp->b_dev); 946 register struct uba_ctlr *um; 947 register struct buf *dp; 948 struct uba_device *ui; 949 int s = spl5(); 950 951 /* 952 * Append the buffer to the drive queue, and if it is not 953 * already there, the drive to the controller queue. (However, 954 * if the drive queue is marked to be requeued, we must be 955 * awaiting an on line or get unit status command; in this 956 * case, leave it off the controller queue.) 957 */ 958 um = (ui = udadinfo[unit])->ui_mi; 959 dp = &udautab[unit]; 960 APPEND(bp, dp, av_forw); 961 if (dp->b_active == 0 && (ui->ui_flags & UNIT_REQUEUE) == 0) { 962 APPEND(dp, &um->um_tab, b_forw); 963 dp->b_active++; 964 } 965 966 /* 967 * Start activity on the controller. Note that unlike other 968 * Unibus drivers, we must always do this, not just when the 969 * controller is not active. 970 */ 971 udastart(um); 972 splx(s); 973 } 974 975 /* 976 * Start up whatever transfers we can find. 977 * Note that udastart() must be called at spl5(). 978 */ 979 udastart(um) 980 register struct uba_ctlr *um; 981 { 982 register struct uda_softc *sc = &uda_softc[um->um_ctlr]; 983 register struct buf *bp, *dp; 984 register struct mscp *mp; 985 struct uba_device *ui; 986 struct udadevice *udaddr; 987 struct partition *pp; 988 int i, sz; 989 990 #ifdef lint 991 i = 0; i = i; 992 #endif 993 /* 994 * If it is not running, try (again and again...) to initialise 995 * it. If it is currently initialising just ignore it for now. 996 */ 997 if (sc->sc_state != ST_RUN) { 998 if (sc->sc_state == ST_IDLE && udainit(um->um_ctlr)) 999 printf("uda%d: still hung\n", um->um_ctlr); 1000 return; 1001 } 1002 1003 /* 1004 * If um_cmd is nonzero, this controller is on the Unibus 1005 * resource wait queue. It will not help to try more requests; 1006 * instead, when the Unibus unblocks and calls udadgo(), we 1007 * will call udastart() again. 1008 */ 1009 if (um->um_cmd) 1010 return; 1011 1012 sc->sc_flags |= SC_INSTART; 1013 udaddr = (struct udadevice *) um->um_addr; 1014 1015 loop: 1016 /* 1017 * Service the drive at the head of the queue. It may not 1018 * need anything, in which case it might be shutting down 1019 * in udaclose(). 1020 */ 1021 if ((dp = um->um_tab.b_actf) == NULL) 1022 goto out; 1023 if ((bp = dp->b_actf) == NULL) { 1024 dp->b_active = 0; 1025 um->um_tab.b_actf = dp->b_forw; 1026 if (ra_info[dp - udautab].ra_openpart == 0) 1027 wakeup((caddr_t)dp); /* finish close protocol */ 1028 goto loop; 1029 } 1030 1031 if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 1032 udasaerror(um); 1033 goto out; 1034 } 1035 1036 /* 1037 * Get an MSCP packet, then figure out what to do. If 1038 * we cannot get a command packet, the command ring may 1039 * be too small: We should have at least as many command 1040 * packets as credits, for best performance. 1041 */ 1042 if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) { 1043 if (sc->sc_mi.mi_credits > MSCP_MINCREDITS && 1044 (sc->sc_flags & SC_GRIPED) == 0) { 1045 log(LOG_NOTICE, "uda%d: command ring too small\n", 1046 um->um_ctlr); 1047 sc->sc_flags |= SC_GRIPED;/* complain only once */ 1048 } 1049 goto out; 1050 } 1051 1052 /* 1053 * Bring the drive on line if it is not already. Get its status 1054 * if we do not already have it. Otherwise just start the transfer. 1055 */ 1056 ui = udadinfo[udaunit(bp->b_dev)]; 1057 if ((ui->ui_flags & UNIT_ONLINE) == 0) { 1058 mp->mscp_opcode = M_OP_ONLINE; 1059 goto common; 1060 } 1061 if ((ui->ui_flags & UNIT_HAVESTATUS) == 0) { 1062 mp->mscp_opcode = M_OP_GETUNITST; 1063 common: 1064 if (ui->ui_flags & UNIT_REQUEUE) panic("udastart"); 1065 /* 1066 * Take the drive off the controller queue. When the 1067 * command finishes, make sure the drive is requeued. 1068 */ 1069 um->um_tab.b_actf = dp->b_forw; 1070 dp->b_active = 0; 1071 ui->ui_flags |= UNIT_REQUEUE; 1072 mp->mscp_unit = ui->ui_slave; 1073 *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 1074 sc->sc_flags |= SC_STARTPOLL; 1075 #ifdef POLLSTATS 1076 sc->sc_ncmd++; 1077 #endif 1078 goto loop; 1079 } 1080 1081 pp = &udalabel[ui->ui_unit].d_partitions[udapart(bp->b_dev)]; 1082 mp->mscp_opcode = (bp->b_flags & B_READ) ? M_OP_READ : M_OP_WRITE; 1083 mp->mscp_unit = ui->ui_slave; 1084 mp->mscp_seq.seq_lbn = bp->b_blkno + pp->p_offset; 1085 sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 1086 mp->mscp_seq.seq_bytecount = bp->b_blkno + sz > pp->p_size ? 1087 (pp->p_size - bp->b_blkno) >> DEV_BSHIFT : bp->b_bcount; 1088 /* mscp_cmdref is filled in by mscp_go() */ 1089 1090 /* 1091 * Drop the packet pointer into the `command' field so udadgo() 1092 * can tell what to start. If ubago returns 1, we can do another 1093 * transfer. If not, um_cmd will still point at mp, so we will 1094 * know that we are waiting for resources. 1095 */ 1096 um->um_cmd = (int)mp; 1097 if (ubago(ui)) 1098 goto loop; 1099 1100 /* 1101 * All done, or blocked in ubago(). If we managed to 1102 * issue some commands, start up the beast. 1103 */ 1104 out: 1105 if (sc->sc_flags & SC_STARTPOLL) { 1106 #ifdef POLLSTATS 1107 udastats.cmd[sc->sc_ncmd]++; 1108 sc->sc_ncmd = 0; 1109 #endif 1110 i = ((struct udadevice *) um->um_addr)->udaip; 1111 } 1112 sc->sc_flags &= ~(SC_INSTART | SC_STARTPOLL); 1113 } 1114 1115 /* 1116 * Start a transfer. 1117 * 1118 * If we are not called from within udastart(), we must have been 1119 * blocked, so call udastart to do more requests (if any). If 1120 * this calls us again immediately we will not recurse, because 1121 * that time we will be in udastart(). Clever.... 1122 */ 1123 udadgo(um) 1124 register struct uba_ctlr *um; 1125 { 1126 struct uda_softc *sc = &uda_softc[um->um_ctlr]; 1127 struct mscp *mp = (struct mscp *)um->um_cmd; 1128 1129 um->um_tab.b_active++; /* another transfer going */ 1130 1131 /* 1132 * Fill in the MSCP packet and move the buffer to the 1133 * I/O wait queue. Mark the controller as no longer on 1134 * the resource queue, and remember to initiate polling. 1135 */ 1136 mp->mscp_seq.seq_buffer = (um->um_ubinfo & 0x3ffff) | 1137 (UBAI_BDP(um->um_ubinfo) << 24); 1138 mscp_go(&sc->sc_mi, mp, um->um_ubinfo); 1139 um->um_cmd = 0; 1140 um->um_ubinfo = 0; /* tyke it awye */ 1141 sc->sc_flags |= SC_STARTPOLL; 1142 #ifdef POLLSTATS 1143 sc->sc_ncmd++; 1144 #endif 1145 if ((sc->sc_flags & SC_INSTART) == 0) 1146 udastart(um); 1147 } 1148 1149 udaiodone(mi, bp, info) 1150 register struct mscp_info *mi; 1151 struct buf *bp; 1152 int info; 1153 { 1154 register struct uba_ctlr *um = udaminfo[mi->mi_ctlr]; 1155 1156 um->um_ubinfo = info; 1157 ubadone(um); 1158 biodone(bp); 1159 if (um->um_bdp && mi->mi_wtab.av_forw == &mi->mi_wtab) 1160 ubarelse(um->um_ubanum, &um->um_bdp); 1161 um->um_tab.b_active--; /* another transfer done */ 1162 } 1163 1164 /* 1165 * The error bit was set in the controller status register. Gripe, 1166 * reset the controller, requeue pending transfers. 1167 */ 1168 udasaerror(um) 1169 register struct uba_ctlr *um; 1170 { 1171 1172 printf("uda%d: controller error, sa=%b\n", um->um_ctlr, 1173 ((struct udadevice *) um->um_addr)->udasa, udasr_bits); 1174 mscp_requeue(&uda_softc[um->um_ctlr].sc_mi); 1175 (void) udainit(um->um_ctlr); 1176 } 1177 1178 /* 1179 * Interrupt routine. Depending on the state of the controller, 1180 * continue initialisation, or acknowledge command and response 1181 * interrupts, and process responses. 1182 */ 1183 udaintr(ctlr) 1184 int ctlr; 1185 { 1186 register struct uba_ctlr *um = udaminfo[ctlr]; 1187 register struct uda_softc *sc = &uda_softc[ctlr]; 1188 register struct udadevice *udaddr = (struct udadevice *) um->um_addr; 1189 register struct uda *ud; 1190 register struct mscp *mp; 1191 register int i; 1192 1193 #ifdef VAX630 1194 (void) spl5(); /* Qbus interrupt protocol is odd */ 1195 #endif 1196 sc->sc_wticks = 0; /* reset interrupt watchdog */ 1197 1198 /* 1199 * Combinations during steps 1, 2, and 3: STEPnMASK 1200 * corresponds to which bits should be tested; 1201 * STEPnGOOD corresponds to the pattern that should 1202 * appear after the interrupt from STEPn initialisation. 1203 * All steps test the bits in ALLSTEPS. 1204 */ 1205 #define ALLSTEPS (UDA_ERR|UDA_STEP4|UDA_STEP3|UDA_STEP2|UDA_STEP1) 1206 1207 #define STEP1MASK (ALLSTEPS | UDA_IE | UDA_NCNRMASK) 1208 #define STEP1GOOD (UDA_STEP2 | UDA_IE | (NCMDL2 << 3) | NRSPL2) 1209 1210 #define STEP2MASK (ALLSTEPS | UDA_IE | UDA_IVECMASK) 1211 #define STEP2GOOD (UDA_STEP3 | UDA_IE | (sc->sc_ivec >> 2)) 1212 1213 #define STEP3MASK ALLSTEPS 1214 #define STEP3GOOD UDA_STEP4 1215 1216 switch (sc->sc_state) { 1217 1218 case ST_IDLE: 1219 /* 1220 * Ignore unsolicited interrupts. 1221 */ 1222 log(LOG_WARNING, "uda%d: stray intr\n", ctlr); 1223 return; 1224 1225 case ST_STEP1: 1226 /* 1227 * Begin step two initialisation. 1228 */ 1229 if ((udaddr->udasa & STEP1MASK) != STEP1GOOD) { 1230 i = 1; 1231 initfailed: 1232 printf("uda%d: init step %d failed, sa=%b\n", 1233 ctlr, i, udaddr->udasa, udasr_bits); 1234 sc->sc_state = ST_IDLE; 1235 if (sc->sc_flags & SC_DOWAKE) { 1236 sc->sc_flags &= ~SC_DOWAKE; 1237 wakeup((caddr_t) sc); 1238 } 1239 return; 1240 } 1241 udaddr->udasa = (int) &sc->sc_uda->uda_ca.ca_rspdsc[0] | 1242 (cpu == VAX_780 || cpu == VAX_8600 ? UDA_PI : 0); 1243 sc->sc_state = ST_STEP2; 1244 return; 1245 1246 case ST_STEP2: 1247 /* 1248 * Begin step 3 initialisation. 1249 */ 1250 if ((udaddr->udasa & STEP2MASK) != STEP2GOOD) { 1251 i = 2; 1252 goto initfailed; 1253 } 1254 udaddr->udasa = ((int) &sc->sc_uda->uda_ca.ca_rspdsc[0]) >> 16; 1255 sc->sc_state = ST_STEP3; 1256 return; 1257 1258 case ST_STEP3: 1259 /* 1260 * Set controller characteristics (finish initialisation). 1261 */ 1262 if ((udaddr->udasa & STEP3MASK) != STEP3GOOD) { 1263 i = 3; 1264 goto initfailed; 1265 } 1266 i = udaddr->udasa & 0xff; 1267 if (i != sc->sc_micro) { 1268 sc->sc_micro = i; 1269 printf("uda%d: version %d model %d\n", 1270 ctlr, i & 0xf, i >> 4); 1271 } 1272 1273 /* 1274 * Present the burst size, then remove it. Why this 1275 * should be done this way, I have no idea. 1276 * 1277 * Note that this assumes udaburst[ctlr] > 0. 1278 */ 1279 udaddr->udasa = UDA_GO | (udaburst[ctlr] - 1) << 2; 1280 udaddr->udasa = UDA_GO; 1281 printf("uda%d: DMA burst size set to %d\n", 1282 ctlr, udaburst[ctlr]); 1283 1284 udainitds(ctlr); /* initialise data structures */ 1285 1286 /* 1287 * Before we can get a command packet, we need some 1288 * credits. Fake some up to keep mscp_getcp() happy, 1289 * get a packet, and cancel all credits (the right 1290 * number should come back in the response to the 1291 * SCC packet). 1292 */ 1293 sc->sc_mi.mi_credits = MSCP_MINCREDITS + 1; 1294 mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT); 1295 if (mp == NULL) /* `cannot happen' */ 1296 panic("udaintr"); 1297 sc->sc_mi.mi_credits = 0; 1298 mp->mscp_opcode = M_OP_SETCTLRC; 1299 mp->mscp_unit = 0; 1300 mp->mscp_sccc.sccc_ctlrflags = M_CF_ATTN | M_CF_MISC | 1301 M_CF_THIS; 1302 *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 1303 i = udaddr->udaip; 1304 sc->sc_state = ST_SETCHAR; 1305 return; 1306 1307 case ST_SETCHAR: 1308 case ST_RUN: 1309 /* 1310 * Handle Set Ctlr Characteristics responses and operational 1311 * responses (via mscp_dorsp). 1312 */ 1313 break; 1314 1315 default: 1316 printf("uda%d: driver bug, state %d\n", ctlr, sc->sc_state); 1317 panic("udastate"); 1318 } 1319 1320 if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 1321 udasaerror(um); 1322 return; 1323 } 1324 1325 ud = &uda[ctlr]; 1326 1327 /* 1328 * Handle buffer purge requests. 1329 * I have never seen these to work usefully, thus the log(). 1330 */ 1331 if (ud->uda_ca.ca_bdp) { 1332 log(LOG_DEBUG, "uda%d: purge bdp %d\n", 1333 ctlr, ud->uda_ca.ca_bdp); 1334 UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 1335 ud->uda_ca.ca_bdp = 0; 1336 udaddr->udasa = 0; /* signal purge complete */ 1337 } 1338 1339 /* 1340 * Check for response and command ring transitions. 1341 */ 1342 if (ud->uda_ca.ca_rspint) { 1343 ud->uda_ca.ca_rspint = 0; 1344 mscp_dorsp(&sc->sc_mi); 1345 } 1346 if (ud->uda_ca.ca_cmdint) { 1347 ud->uda_ca.ca_cmdint = 0; 1348 MSCP_DOCMD(&sc->sc_mi); 1349 } 1350 udastart(um); 1351 } 1352 1353 #ifndef GENERIC_RAW 1354 struct buf rudabuf[NRA]; 1355 1356 /* 1357 * Read and write. 1358 */ 1359 udaread(dev, uio) 1360 dev_t dev; 1361 struct uio *uio; 1362 { 1363 1364 return (physio(udastrategy, &rudabuf[udaunit(dev)], dev, B_READ, 1365 minphys, uio)); 1366 } 1367 1368 udawrite(dev, uio) 1369 dev_t dev; 1370 struct uio *uio; 1371 { 1372 1373 return (physio(udastrategy, &rudabuf[udaunit(dev)], dev, B_WRITE, 1374 minphys, uio)); 1375 } 1376 #endif /* GENERIC_RAW */ 1377 1378 /* 1379 * Initialise the various data structures that control the UDA50. 1380 */ 1381 udainitds(ctlr) 1382 int ctlr; 1383 { 1384 register struct uda *ud = &uda[ctlr]; 1385 register struct uda *uud = uda_softc[ctlr].sc_uda; 1386 register struct mscp *mp; 1387 register int i; 1388 1389 for (i = 0, mp = ud->uda_rsp; i < NRSP; i++, mp++) { 1390 ud->uda_ca.ca_rspdsc[i] = MSCP_OWN | MSCP_INT | 1391 (long)&uud->uda_rsp[i].mscp_cmdref; 1392 mp->mscp_addr = &ud->uda_ca.ca_rspdsc[i]; 1393 mp->mscp_msglen = MSCP_MSGLEN; 1394 } 1395 for (i = 0, mp = ud->uda_cmd; i < NCMD; i++, mp++) { 1396 ud->uda_ca.ca_cmddsc[i] = MSCP_INT | 1397 (long)&uud->uda_cmd[i].mscp_cmdref; 1398 mp->mscp_addr = &ud->uda_ca.ca_cmddsc[i]; 1399 mp->mscp_msglen = MSCP_MSGLEN; 1400 } 1401 } 1402 1403 /* 1404 * Handle an error datagram. All we do now is decode it. 1405 */ 1406 udadgram(mi, mp) 1407 struct mscp_info *mi; 1408 struct mscp *mp; 1409 { 1410 1411 mscp_decodeerror(mi->mi_md->md_mname, mi->mi_ctlr, mp); 1412 } 1413 1414 /* 1415 * The Set Controller Characteristics command finished. 1416 * Record the new state of the controller. 1417 */ 1418 udactlrdone(mi, mp) 1419 register struct mscp_info *mi; 1420 struct mscp *mp; 1421 { 1422 register struct uda_softc *sc = &uda_softc[mi->mi_ctlr]; 1423 1424 if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS) 1425 sc->sc_state = ST_RUN; 1426 else { 1427 printf("uda%d: SETCTLRC failed: ", 1428 mi->mi_ctlr, mp->mscp_status); 1429 mscp_printevent(mp); 1430 sc->sc_state = ST_IDLE; 1431 } 1432 if (sc->sc_flags & SC_DOWAKE) { 1433 sc->sc_flags &= ~SC_DOWAKE; 1434 wakeup((caddr_t)sc); 1435 } 1436 } 1437 1438 /* 1439 * Received a response from an as-yet unconfigured drive. Configure it 1440 * in, if possible. 1441 */ 1442 udaunconf(mi, mp) 1443 struct mscp_info *mi; 1444 register struct mscp *mp; 1445 { 1446 1447 /* 1448 * If it is a slave response, copy it to udaslavereply for 1449 * udaslave() to look at. 1450 */ 1451 if (mp->mscp_opcode == (M_OP_GETUNITST | M_OP_END) && 1452 (uda_softc[mi->mi_ctlr].sc_flags & SC_INSLAVE) != 0) { 1453 udaslavereply = *mp; 1454 return (MSCP_DONE); 1455 } 1456 1457 /* 1458 * Otherwise, it had better be an available attention response. 1459 */ 1460 if (mp->mscp_opcode != M_OP_AVAILATTN) 1461 return (MSCP_FAILED); 1462 1463 /* do what autoconf does */ 1464 return (MSCP_FAILED); /* not yet, arwhite, not yet */ 1465 } 1466 1467 /* 1468 * A drive came on line. Check its type and size. Return DONE if 1469 * we think the drive is truly on line. In any case, awaken anyone 1470 * sleeping on the drive on-line-ness. 1471 */ 1472 udaonline(ui, mp) 1473 register struct uba_device *ui; 1474 struct mscp *mp; 1475 { 1476 register struct ra_info *ra = &ra_info[ui->ui_unit]; 1477 1478 wakeup((caddr_t)&ui->ui_flags); 1479 if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 1480 printf("uda%d: attempt to bring ra%d on line failed: ", 1481 ui->ui_ctlr, ui->ui_unit); 1482 mscp_printevent(mp); 1483 ra->ra_state = CLOSED; 1484 return (MSCP_FAILED); 1485 } 1486 1487 ra->ra_state = OPENRAW; 1488 ra->ra_dsize = (daddr_t)mp->mscp_onle.onle_unitsize; 1489 printf("ra%d: uda%d, unit %d, size = %d sectors\n", ui->ui_unit, 1490 ui->ui_ctlr, mp->mscp_unit, ra->ra_dsize); 1491 /* can now compute ncyl */ 1492 ra->ra_geom.rg_ncyl = ra->ra_dsize / ra->ra_geom.rg_ntracks / 1493 ra->ra_geom.rg_nsectors; 1494 return (MSCP_DONE); 1495 } 1496 1497 /* 1498 * We got some (configured) unit's status. Return DONE if it succeeded. 1499 */ 1500 udagotstatus(ui, mp) 1501 register struct uba_device *ui; 1502 register struct mscp *mp; 1503 { 1504 1505 if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 1506 printf("uda%d: attempt to get status for ra%d failed: ", 1507 ui->ui_ctlr, ui->ui_unit); 1508 mscp_printevent(mp); 1509 return (MSCP_FAILED); 1510 } 1511 /* record for (future) bad block forwarding and whatever else */ 1512 uda_rasave(ui->ui_unit, mp, 1); 1513 return (MSCP_DONE); 1514 } 1515 1516 /* 1517 * A transfer failed. We get a chance to fix or restart it. 1518 * Need to write the bad block forwaring code first.... 1519 */ 1520 /*ARGSUSED*/ 1521 udaioerror(ui, mp, bp) 1522 register struct uba_device *ui; 1523 register struct mscp *mp; 1524 struct buf *bp; 1525 { 1526 1527 if (mp->mscp_flags & M_EF_BBLKR) { 1528 /* 1529 * A bad block report. Eventually we will 1530 * restart this transfer, but for now, just 1531 * log it and give up. 1532 */ 1533 log(LOG_ERR, "ra%d: bad block report: %d%s\n", 1534 ui->ui_unit, mp->mscp_seq.seq_lbn, 1535 mp->mscp_flags & M_EF_BBLKU ? " + others" : ""); 1536 } else { 1537 /* 1538 * What the heck IS a `serious exception' anyway? 1539 * IT SURE WOULD BE NICE IF DEC SOLD DOCUMENTATION 1540 * FOR THEIR OWN CONTROLLERS. 1541 */ 1542 if (mp->mscp_flags & M_EF_SEREX) 1543 log(LOG_ERR, "ra%d: serious exception reported\n", 1544 ui->ui_unit); 1545 } 1546 return (MSCP_FAILED); 1547 } 1548 1549 /* 1550 * A replace operation finished. 1551 */ 1552 /*ARGSUSED*/ 1553 udareplace(ui, mp) 1554 struct uba_device *ui; 1555 struct mscp *mp; 1556 { 1557 1558 panic("udareplace"); 1559 } 1560 1561 /* 1562 * A bad block related operation finished. 1563 */ 1564 /*ARGSUSED*/ 1565 udabb(ui, mp, bp) 1566 struct uba_device *ui; 1567 struct mscp *mp; 1568 struct buf *bp; 1569 { 1570 1571 panic("udabb"); 1572 } 1573 1574 1575 /* 1576 * I/O controls. 1577 */ 1578 udaioctl(dev, cmd, data, flag) 1579 dev_t dev; 1580 int cmd; 1581 caddr_t data; 1582 int flag; 1583 { 1584 register int unit = udaunit(dev); 1585 register struct disklabel *lp; 1586 int error = 0; 1587 1588 lp = &udalabel[unit]; 1589 1590 switch (cmd) { 1591 1592 case DIOCGDINFO: 1593 *(struct disklabel *)data = *lp; 1594 break; 1595 1596 case DIOCGPART: 1597 ((struct partinfo *)data)->disklab = lp; 1598 ((struct partinfo *)data)->part = 1599 &lp->d_partitions[udapart(dev)]; 1600 break; 1601 1602 case DIOCSDINFO: 1603 if ((flag & FWRITE) == 0) 1604 error = EBADF; 1605 else 1606 error = setdisklabel(lp, (struct disklabel *)data, 1607 ra_info[unit].ra_openpart); 1608 break; 1609 1610 case DIOCWDINFO: 1611 if ((flag & FWRITE) == 0) 1612 error = EBADF; 1613 else if ((error = setdisklabel(lp, (struct disklabel *)data, 1614 ra_info[unit].ra_openpart)) == 0) 1615 error = writedisklabel(dev, udastrategy, lp); 1616 break; 1617 1618 #ifdef notyet 1619 case UDAIOCREPLACE: 1620 /* 1621 * Initiate bad block replacement for the given LBN. 1622 * (Should we allow modifiers?) 1623 */ 1624 error = EOPNOTSUPP; 1625 break; 1626 1627 case UDAIOCGMICRO: 1628 /* 1629 * Return the microcode revision for the UDA50 running 1630 * this drive. 1631 */ 1632 *(int *) data = uda_softc[uddinfo[unit]->ui_ctlr].sc_micro; 1633 break; 1634 #endif 1635 1636 default: 1637 error = ENOTTY; 1638 break; 1639 } 1640 return (error); 1641 } 1642 1643 /* 1644 * A Unibus reset has occurred on UBA uban. Reinitialise the controller(s) 1645 * on that Unibus, and requeue outstanding I/O. 1646 */ 1647 udareset(uban) 1648 int uban; 1649 { 1650 register struct uba_ctlr *um; 1651 register struct uda_softc *sc; 1652 register int ctlr; 1653 1654 for (ctlr = 0, sc = uda_softc; ctlr < NUDA; ctlr++, sc++) { 1655 if ((um = udaminfo[ctlr]) == NULL || um->um_ubanum != uban || 1656 um->um_alive == 0) 1657 continue; 1658 printf(" uda%d", ctlr); 1659 1660 /* 1661 * Our BDP (if any) is gone; our command (if any) is 1662 * flushed; the device is no longer mapped; and the 1663 * UDA50 is not yet initialised. 1664 */ 1665 if (um->um_bdp) { 1666 printf("<%d>", UBAI_BDP(um->um_bdp)); 1667 um->um_bdp = 0; 1668 } 1669 um->um_ubinfo = 0; 1670 um->um_cmd = 0; 1671 sc->sc_flags &= ~SC_MAPPED; 1672 sc->sc_state = ST_IDLE; 1673 1674 /* reset queues and requeue pending transfers */ 1675 mscp_requeue(&sc->sc_mi); 1676 1677 /* 1678 * If it fails to initialise we will notice later and 1679 * try again (and again...). Do not call udastart() 1680 * here; it will be done after the controller finishes 1681 * initialisation. 1682 */ 1683 if (udainit(ctlr)) 1684 printf(" (hung)"); 1685 } 1686 } 1687 1688 /* 1689 * Watchdog timer: If the controller is active, and no interrupts 1690 * have occurred for 30 seconds, assume it has gone away. 1691 */ 1692 udawatch() 1693 { 1694 register int i; 1695 register struct uba_ctlr *um; 1696 register struct uda_softc *sc; 1697 1698 timeout(udawatch, (caddr_t) 0, hz); /* every second */ 1699 for (i = 0, sc = uda_softc; i < NUDA; i++, sc++) { 1700 if ((um = udaminfo[i]) == 0 || !um->um_alive) 1701 continue; 1702 if (sc->sc_state == ST_IDLE) 1703 continue; 1704 if (sc->sc_state == ST_RUN && !um->um_tab.b_active) 1705 sc->sc_wticks = 0; 1706 else if (++sc->sc_wticks >= 30) { 1707 sc->sc_wticks = 0; 1708 printf("uda%d: lost interrupt\n", i); 1709 ubareset(um->um_ubanum); 1710 } 1711 } 1712 } 1713 1714 /* 1715 * Do a panic dump. We set up the controller for one command packet 1716 * and one response packet, for which we use `struct uda1'. 1717 */ 1718 struct uda1 { 1719 struct uda1ca uda1_ca; /* communications area */ 1720 struct mscp uda1_rsp; /* response packet */ 1721 struct mscp uda1_cmd; /* command packet */ 1722 } uda1; 1723 1724 #define DBSIZE 32 /* dump 16K at a time */ 1725 1726 udadump(dev) 1727 dev_t dev; 1728 { 1729 struct udadevice *udaddr; 1730 struct uda1 *ud_ubaddr; 1731 char *start; 1732 int num, blk, unit, maxsz, blkoff, reg; 1733 struct partition *pp; 1734 register struct uba_regs *uba; 1735 register struct uba_device *ui; 1736 register struct uda1 *ud; 1737 register struct pte *io; 1738 register int i; 1739 1740 /* 1741 * Make sure the device is a reasonable place on which to dump. 1742 */ 1743 unit = udaunit(dev); 1744 if (unit >= NRA) 1745 return (ENXIO); 1746 #define phys(cast, addr) ((cast) ((int) addr & 0x7fffffff)) 1747 ui = phys(struct uba_device *, udadinfo[unit]); 1748 if (ui == NULL || ui->ui_alive == 0) 1749 return (ENXIO); 1750 1751 /* 1752 * Find and initialise the UBA; get the physical address of the 1753 * device registers, and of communications area and command and 1754 * response packet. 1755 */ 1756 uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 1757 ubainit(uba); 1758 udaddr = (struct udadevice *)ui->ui_physaddr; 1759 ud = phys(struct uda1 *, &uda1); 1760 1761 /* 1762 * Map the ca+packets into Unibus I/O space so the UDA50 can get 1763 * at them. Use the registers at the end of the Unibus map (since 1764 * we will use the registers at the beginning to map the memory 1765 * we are dumping). 1766 */ 1767 num = btoc(sizeof(struct uda1)) + 1; 1768 reg = NUBMREG - num; 1769 io = &uba->uba_map[reg]; 1770 for (i = 0; i < num; i++) 1771 *(int *)io++ = UBAMR_MRV | (btop(ud) + i); 1772 ud_ubaddr = (struct uda1 *)(((int)ud & PGOFSET) | (reg << 9)); 1773 1774 /* 1775 * Initialise the controller, with one command and one response 1776 * packet. 1777 */ 1778 udaddr->udaip = 0; 1779 if (udadumpwait(udaddr, UDA_STEP1)) 1780 return (EFAULT); 1781 udaddr->udasa = UDA_ERR; 1782 if (udadumpwait(udaddr, UDA_STEP2)) 1783 return (EFAULT); 1784 udaddr->udasa = (int)&ud_ubaddr->uda1_ca.ca_rspdsc; 1785 if (udadumpwait(udaddr, UDA_STEP3)) 1786 return (EFAULT); 1787 udaddr->udasa = ((int)&ud_ubaddr->uda1_ca.ca_rspdsc) >> 16; 1788 if (udadumpwait(udaddr, UDA_STEP4)) 1789 return (EFAULT); 1790 uda_softc[ui->ui_ctlr].sc_micro = udaddr->udasa & 0xff; 1791 udaddr->udasa = UDA_GO; 1792 1793 /* 1794 * Set up the command and response descriptor, then set the 1795 * controller characteristics and bring the drive on line. 1796 * Note that all uninitialised locations in uda1_cmd are zero. 1797 */ 1798 ud->uda1_ca.ca_rspdsc = (long)&ud_ubaddr->uda1_rsp.mscp_cmdref; 1799 ud->uda1_ca.ca_cmddsc = (long)&ud_ubaddr->uda1_cmd.mscp_cmdref; 1800 /* ud->uda1_cmd.mscp_sccc.sccc_ctlrflags = 0; */ 1801 /* ud->uda1_cmd.mscp_sccc.sccc_version = 0; */ 1802 if (udadumpcmd(M_OP_SETCTLRC, ud, ui)) 1803 return (EFAULT); 1804 ud->uda1_cmd.mscp_unit = ui->ui_slave; 1805 if (udadumpcmd(M_OP_ONLINE, ud, ui)) 1806 return (EFAULT); 1807 1808 pp = phys(struct partition *, 1809 &udalabel[unit].d_partitions[udapart(dev)]); 1810 maxsz = pp->p_size; 1811 blkoff = pp->p_offset; 1812 1813 /* 1814 * Dump all of physical memory, or as much as will fit in the 1815 * space provided. 1816 */ 1817 start = 0; 1818 num = maxfree; 1819 if (dumplo < 0) 1820 return (EINVAL); 1821 if (dumplo + num >= maxsz) 1822 num = maxsz - dumplo; 1823 blkoff += dumplo; 1824 1825 /* 1826 * Write out memory, DBSIZE pages at a time. 1827 * N.B.: this code depends on the fact that the sector 1828 * size == the page size. 1829 */ 1830 while (num > 0) { 1831 blk = num > DBSIZE ? DBSIZE : num; 1832 io = uba->uba_map; 1833 /* 1834 * Map in the pages to write, leaving an invalid entry 1835 * at the end to guard against wild Unibus transfers. 1836 * Then do the write. 1837 */ 1838 for (i = 0; i < blk; i++) 1839 *(int *) io++ = UBAMR_MRV | (btop(start) + i); 1840 *(int *) io = 0; 1841 ud->uda1_cmd.mscp_unit = ui->ui_slave; 1842 ud->uda1_cmd.mscp_seq.seq_lbn = btop(start) + blkoff; 1843 ud->uda1_cmd.mscp_seq.seq_bytecount = blk << PGSHIFT; 1844 if (udadumpcmd(M_OP_WRITE, ud, ui)) 1845 return (EIO); 1846 start += blk << PGSHIFT; 1847 num -= blk; 1848 } 1849 return (0); /* made it! */ 1850 } 1851 1852 /* 1853 * Wait for some of the bits in `bits' to come on. If the error bit 1854 * comes on, or ten seconds pass without response, return true (error). 1855 */ 1856 udadumpwait(udaddr, bits) 1857 register struct udadevice *udaddr; 1858 register int bits; 1859 { 1860 register int timo = todr() + 1000; 1861 1862 while ((udaddr->udasa & bits) == 0) { 1863 if (udaddr->udasa & UDA_ERR) { 1864 printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 1865 return (1); 1866 } 1867 if (todr() >= timo) { 1868 printf("timeout\ndump "); 1869 return (1); 1870 } 1871 } 1872 return (0); 1873 } 1874 1875 /* 1876 * Feed a command to the UDA50, wait for its response, and return 1877 * true iff something went wrong. 1878 */ 1879 udadumpcmd(op, ud, ui) 1880 int op; 1881 register struct uda1 *ud; 1882 struct uba_device *ui; 1883 { 1884 register struct udadevice *udaddr; 1885 register int n; 1886 #define mp (&ud->uda1_rsp) 1887 1888 udaddr = (struct udadevice *) ui->ui_physaddr; 1889 ud->uda1_cmd.mscp_opcode = op; 1890 ud->uda1_cmd.mscp_msglen = MSCP_MSGLEN; 1891 ud->uda1_rsp.mscp_msglen = MSCP_MSGLEN; 1892 ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 1893 ud->uda1_ca.ca_cmddsc |= MSCP_OWN | MSCP_INT; 1894 if (udaddr->udasa & UDA_ERR) { 1895 printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 1896 return (1); 1897 } 1898 n = udaddr->udaip; 1899 n = todr() + 1000; 1900 for (;;) { 1901 if (todr() > n) { 1902 printf("timeout\ndump "); 1903 return (1); 1904 } 1905 if (ud->uda1_ca.ca_cmdint) 1906 ud->uda1_ca.ca_cmdint = 0; 1907 if (ud->uda1_ca.ca_rspint == 0) 1908 continue; 1909 ud->uda1_ca.ca_rspint = 0; 1910 if (mp->mscp_opcode == (op | M_OP_END)) 1911 break; 1912 printf("\n"); 1913 switch (MSCP_MSGTYPE(mp->mscp_msgtc)) { 1914 1915 case MSCPT_SEQ: 1916 printf("sequential"); 1917 break; 1918 1919 case MSCPT_DATAGRAM: 1920 mscp_decodeerror("uda", ui->ui_ctlr, mp); 1921 printf("datagram"); 1922 break; 1923 1924 case MSCPT_CREDITS: 1925 printf("credits"); 1926 break; 1927 1928 case MSCPT_MAINTENANCE: 1929 printf("maintenance"); 1930 break; 1931 1932 default: 1933 printf("unknown (type 0x%x)", 1934 MSCP_MSGTYPE(mp->mscp_msgtc)); 1935 break; 1936 } 1937 printf(" ignored\ndump "); 1938 ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 1939 } 1940 if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 1941 printf("error: op 0x%x => 0x%x status 0x%x\ndump ", op, 1942 mp->mscp_opcode, mp->mscp_status); 1943 return (1); 1944 } 1945 return (0); 1946 #undef mp 1947 } 1948 1949 /* 1950 * Return the size of a partition, if known, or -1 if not. 1951 */ 1952 udasize(dev) 1953 dev_t dev; 1954 { 1955 register int unit = udaunit(dev); 1956 register struct uba_device *ui; 1957 register struct size *st; 1958 1959 if (unit >= NRA || (ui = udadinfo[unit]) == NULL || 1960 ui->ui_alive == 0 || (ui->ui_flags & UNIT_ONLINE) == 0 || 1961 ra_info[unit].ra_state != OPEN) 1962 return (-1); 1963 return ((int)udalabel[unit].d_partitions[udapart(dev)].p_size); 1964 } 1965 1966 #ifdef COMPAT_42 1967 /* 1968 * Tables mapping unlabelled drives. 1969 */ 1970 struct size { 1971 daddr_t nblocks; 1972 daddr_t blkoff; 1973 } ra25_sizes[8] = { 1974 15884, 0, /* A=blk 0 thru 15883 */ 1975 10032, 15884, /* B=blk 15884 thru 49323 */ 1976 -1, 0, /* C=blk 0 thru end */ 1977 0, 0, /* D=blk 340670 thru 356553 */ 1978 0, 0, /* E=blk 356554 thru 412489 */ 1979 0, 0, /* F=blk 412490 thru end */ 1980 -1, 25916, /* G=blk 49324 thru 131403 */ 1981 0, 0, /* H=blk 131404 thru end */ 1982 }, rx50_sizes[8] = { 1983 800, 0, /* A=blk 0 thru 799 */ 1984 0, 0, 1985 -1, 0, /* C=blk 0 thru end */ 1986 0, 0, 1987 0, 0, 1988 0, 0, 1989 0, 0, 1990 0, 0, 1991 }, rd52_sizes[8] = { 1992 15884, 0, /* A=blk 0 thru 15883 */ 1993 9766, 15884, /* B=blk 15884 thru 25649 */ 1994 -1, 0, /* C=blk 0 thru end */ 1995 0, 0, /* D=unused */ 1996 0, 0, /* E=unused */ 1997 0, 0, /* F=unused */ 1998 -1, 25650, /* G=blk 25650 thru end */ 1999 0, 0, /* H=unused */ 2000 }, rd53_sizes[8] = { 2001 15884, 0, /* A=blk 0 thru 15883 */ 2002 33440, 15884, /* B=blk 15884 thru 49323 */ 2003 -1, 0, /* C=blk 0 thru end */ 2004 0, 0, /* D=unused */ 2005 33440, 0, /* E=blk 0 thru 33439 */ 2006 -1, 33440, /* F=blk 33440 thru end */ 2007 -1, 49324, /* G=blk 49324 thru end */ 2008 -1, 15884, /* H=blk 15884 thru end */ 2009 }, ra60_sizes[8] = { 2010 15884, 0, /* A=sectors 0 thru 15883 */ 2011 33440, 15884, /* B=sectors 15884 thru 49323 */ 2012 400176, 0, /* C=sectors 0 thru 400175 */ 2013 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 2014 268772, 131404, /* 4.2 H => E=sectors 131404 thru 400175 */ 2015 350852, 49324, /* F=sectors 49324 thru 400175 */ 2016 157570, 242606, /* UCB G => G=sectors 242606 thru 400175 */ 2017 193282, 49324, /* UCB H => H=sectors 49324 thru 242605 */ 2018 }, ra80_sizes[8] = { 2019 15884, 0, /* A=sectors 0 thru 15883 */ 2020 33440, 15884, /* B=sectors 15884 thru 49323 */ 2021 242606, 0, /* C=sectors 0 thru 242605 */ 2022 0, 0, /* D=unused */ 2023 193282, 49324, /* UCB H => E=sectors 49324 thru 242605 */ 2024 82080, 49324, /* 4.2 G => F=sectors 49324 thru 131403 */ 2025 192696, 49910, /* G=sectors 49910 thru 242605 */ 2026 111202, 131404, /* 4.2 H => H=sectors 131404 thru 242605 */ 2027 }, ra81_sizes[8] ={ 2028 /* 2029 * These are the new standard partition sizes for ra81's. 2030 * An RA_COMPAT system is compiled with D, E, and F corresponding 2031 * to the 4.2 partitions for G, H, and F respectively. 2032 */ 2033 #ifndef UCBRA 2034 15884, 0, /* A=sectors 0 thru 15883 */ 2035 66880, 16422, /* B=sectors 16422 thru 83301 */ 2036 891072, 0, /* C=sectors 0 thru 891071 */ 2037 #ifdef RA_COMPAT 2038 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 2039 759668, 131404, /* 4.2 H => E=sectors 131404 thru 891071 */ 2040 478582, 412490, /* 4.2 F => F=sectors 412490 thru 891071 */ 2041 #else 2042 15884, 375564, /* D=sectors 375564 thru 391447 */ 2043 307200, 391986, /* E=sectors 391986 thru 699185 */ 2044 191352, 699720, /* F=sectors 699720 thru 891071 */ 2045 #endif RA_COMPAT 2046 515508, 375564, /* G=sectors 375564 thru 891071 */ 2047 291346, 83538, /* H=sectors 83538 thru 374883 */ 2048 2049 /* 2050 * These partitions correspond to the sizes used by sites at Berkeley, 2051 * and by those sites that have received copies of the Berkeley driver 2052 * with deltas 6.2 or greater (11/15/83). 2053 */ 2054 #else UCBRA 2055 2056 15884, 0, /* A=sectors 0 thru 15883 */ 2057 33440, 15884, /* B=sectors 15884 thru 49323 */ 2058 891072, 0, /* C=sectors 0 thru 891071 */ 2059 15884, 242606, /* D=sectors 242606 thru 258489 */ 2060 307200, 258490, /* E=sectors 258490 thru 565689 */ 2061 325382, 565690, /* F=sectors 565690 thru 891071 */ 2062 648466, 242606, /* G=sectors 242606 thru 891071 */ 2063 193282, 49324, /* H=sectors 49324 thru 242605 */ 2064 2065 #endif UCBRA 2066 }; 2067 2068 /* 2069 * Drive type index decoding table. `ut_name' is null iff the 2070 * type is not known. 2071 */ 2072 struct udatypes { 2073 char *ut_name; /* drive type name */ 2074 struct size *ut_sizes; /* partition tables */ 2075 int ut_nsectors, ut_ntracks, ut_ncylinders; 2076 } udatypes[] = { 2077 NULL, NULL, 2078 0, 0, 0, 2079 "ra80", ra80_sizes, /* 1 = ra80 */ 2080 31, 14, 559, 2081 "rc25-removable", ra25_sizes, /* 2 = rc25-r */ 2082 42, 4, 302, 2083 "rc25-fixed", ra25_sizes, /* 3 = rc25-f */ 2084 42, 4, 302, 2085 "ra60", ra60_sizes, /* 4 = ra60 */ 2086 42, 4, 2382, 2087 "ra81", ra81_sizes, /* 5 = ra81 */ 2088 51, 14, 1248, 2089 NULL, NULL, /* 6 = ? */ 2090 0, 0, 0, 2091 "rx50", rx50_sizes, /* 7 = rx50 */ 2092 10, 1, 80, 2093 "rd52", rd52_sizes, /* 8 = rd52 */ 2094 18, 7, 480, 2095 "rd53", rd53_sizes, /* 9 = rd53 */ 2096 18, 8, 963, 2097 }; 2098 2099 #define NTYPES (sizeof(udatypes) / sizeof(*udatypes)) 2100 2101 udamaptype(unit, lp) 2102 int unit; 2103 register struct disklabel *lp; 2104 { 2105 register struct udatypes *ut; 2106 register struct size *sz; 2107 register struct partition *pp; 2108 register char *p; 2109 register int i; 2110 register struct ra_info *ra = &ra_info[unit]; 2111 2112 lp->d_secsize = 512; 2113 lp->d_secperunit = ra->ra_dsize; 2114 if ((u_long)ra->ra_type >= NTYPES) { 2115 printf("ra%d: don't have a partition table for", unit); 2116 mscp_printmedia(ra->ra_mediaid); 2117 lp->d_nsectors = ra->ra_geom.rg_nsectors; 2118 lp->d_ntracks = ra->ra_geom.rg_ntracks; 2119 lp->d_ncylinders = ra->ra_geom.rg_ncyl; 2120 printf(";\nusing (t,s,c)=(%d,%d,%d)\n", lp->d_nsectors, 2121 lp->d_ntracks, lp->d_ncylinders); 2122 lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 2123 lp->d_typename[0] = 'r'; 2124 lp->d_typename[1] = 'a'; 2125 lp->d_typename[2] = '?'; 2126 lp->d_typename[3] = '?'; 2127 lp->d_typename[4] = 0; 2128 lp->d_npartitions = 1; 2129 lp->d_partitions[0].p_offset = 0; 2130 lp->d_partitions[0].p_size = lp->d_secperunit; 2131 return (0); 2132 } 2133 ut = &udatypes[ra->ra_type]; 2134 p = ut->ut_name; 2135 for (i = 0; i < sizeof(lp->d_typename) - 1 && *p; i++) 2136 lp->d_typename[i] = *p++; 2137 lp->d_typename[i] = 0; 2138 sz = ut->ut_sizes; 2139 /* GET nsectors, ntracks, ncylinders FROM SAVED GEOMETRY? */ 2140 lp->d_nsectors = ut->ut_nsectors; 2141 lp->d_ntracks = ut->ut_ntracks; 2142 lp->d_ncylinders = ut->ut_ncylinders; 2143 lp->d_npartitions = 8; 2144 lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 2145 for (pp = lp->d_partitions; pp < &lp->d_partitions[8]; pp++, sz++) { 2146 pp->p_offset = sz->blkoff; 2147 if ((pp->p_size = sz->nblocks) == (u_long)-1) 2148 pp->p_size = ra->ra_dsize - sz->blkoff; 2149 } 2150 return (1); 2151 } 2152 #endif /* COMPAT_42 */ 2153 #endif /* NUDA > 0 */ 2154