1 /* 2 * @(#)uda.c 6.21 (Berkeley) 04/22/86 3 */ 4 5 /************************************************************************ 6 * * 7 * Copyright (c) 1983 by * 8 * Digital Equipment Corporation, Maynard, MA * 9 * All rights reserved. * 10 * * 11 ************************************************************************/ 12 /* 13 * uda.c - UDA50A Driver 14 * 15 * decvax!rich 16 */ 17 18 #define DEBUG 19 #define UDADEVNUM (9) /* entry in bdevsw */ 20 #include "ra.h" 21 #if NUDA > 0 22 /* 23 * UDA50/RAxx disk device driver 24 * 25 * Restrictions: 26 * Unit numbers must be less than 8. 27 */ 28 #include "../machine/pte.h" 29 30 #include "param.h" 31 #include "systm.h" 32 #include "buf.h" 33 #include "conf.h" 34 #include "dir.h" 35 #include "user.h" 36 #include "map.h" 37 #include "vm.h" 38 #include "dk.h" 39 #include "cmap.h" 40 #include "uio.h" 41 42 #include "../vax/cpu.h" 43 #include "ubareg.h" 44 #include "ubavar.h" 45 #include "../vax/mtpr.h" 46 47 #define TENSEC (1000) 48 49 #define NRSPL2 3 /* log2 number of response packets */ 50 #define NCMDL2 3 /* log2 number of command packets */ 51 #define NRSP (1<<NRSPL2) 52 #define NCMD (1<<NCMDL2) 53 54 #include "../vaxuba/udareg.h" 55 #include "../vax/mscp.h" 56 57 58 struct uda_softc { 59 short sc_state; /* state of controller */ 60 short sc_mapped; /* Unibus map allocated for uda struct? */ 61 int sc_ubainfo; /* Unibus mapping info */ 62 struct uda *sc_uda; /* Unibus address of uda struct */ 63 int sc_ivec; /* interrupt vector address */ 64 short sc_credits; /* transfer credits */ 65 short sc_lastcmd; /* pointer into command ring */ 66 short sc_lastrsp; /* pointer into response ring */ 67 } uda_softc[NUDA]; 68 struct uda { 69 struct udaca uda_ca; /* communications area */ 70 struct mscp uda_rsp[NRSP]; /* response packets */ 71 struct mscp uda_cmd[NCMD]; /* command packets */ 72 } uda[NUDA]; 73 74 #define udunit(dev) (minor(dev) >> 3) 75 76 /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ 77 struct size { 78 daddr_t nblocks; 79 daddr_t blkoff; 80 } ra25_sizes[8] = { 81 15884, 0, /* A=blk 0 thru 15883 */ 82 10032, 15884, /* B=blk 15884 thru 49323 */ 83 -1, 0, /* C=blk 0 thru end */ 84 0, 0, /* D=blk 340670 thru 356553 */ 85 0, 0, /* E=blk 356554 thru 412489 */ 86 0, 0, /* F=blk 412490 thru end */ 87 -1, 25916, /* G=blk 49324 thru 131403 */ 88 0, 0, /* H=blk 131404 thru end */ 89 }, ra53_sizes[8] = { 90 15884, 0, 91 33440, 15884, 92 -1, 0, 93 0, 0, 94 33440, 0, 95 -1, 33440, 96 -1, 15884, 97 -1, 49324, 98 }, ra60_sizes[8] = { 99 15884, 0, /* A=sectors 0 thru 15883 */ 100 33440, 15884, /* B=sectors 15884 thru 49323 */ 101 400176, 0, /* C=sectors 0 thru 400175 */ 102 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 103 268772, 131404, /* 4.2 H => E=sectors 131404 thru 400175 */ 104 350852, 49324, /* F=sectors 49324 thru 400175 */ 105 157570, 242606, /* UCB G => G=sectors 242606 thru 400175 */ 106 193282, 49324, /* UCB H => H=sectors 49324 thru 242605 */ 107 }, ra80_sizes[8] = { 108 15884, 0, /* A=sectors 0 thru 15883 */ 109 33440, 15884, /* B=sectors 15884 thru 49323 */ 110 242606, 0, /* C=sectors 0 thru 242605 */ 111 0, 0, /* D=unused */ 112 193282, 49324, /* UCB H => E=sectors 49324 thru 242605 */ 113 82080, 49324, /* 4.2 G => F=sectors 49324 thru 131403 */ 114 192696, 49910, /* G=sectors 49910 thru 242605 */ 115 111202, 131404, /* 4.2 H => H=sectors 131404 thru 242605 */ 116 }, ra81_sizes[8] ={ 117 /* 118 * These are the new standard partition sizes for ra81's. 119 * An RA_COMPAT system is compiled with D, E, and F corresponding 120 * to the 4.2 partitions for G, H, and F respectively. 121 */ 122 #ifndef UCBRA 123 15884, 0, /* A=sectors 0 thru 15883 */ 124 66880, 16422, /* B=sectors 16422 thru 83301 */ 125 891072, 0, /* C=sectors 0 thru 891071 */ 126 #ifdef RA_COMPAT 127 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 128 759668, 131404, /* 4.2 H => E=sectors 131404 thru 891071 */ 129 478582, 412490, /* 4.2 F => F=sectors 412490 thru 891071 */ 130 #else 131 15884, 375564, /* D=sectors 375564 thru 391447 */ 132 307200, 391986, /* E=sectors 391986 thru 699185 */ 133 191352, 699720, /* F=sectors 699720 thru 891071 */ 134 #endif RA_COMPAT 135 515508, 375564, /* G=sectors 375564 thru 891071 */ 136 291346, 83538, /* H=sectors 83538 thru 374883 */ 137 138 /* 139 * These partitions correspond to the sizes used by sites at Berkeley, 140 * and by those sites that have received copies of the Berkeley driver 141 * with deltas 6.2 or greater (11/15/83). 142 */ 143 #else UCBRA 144 145 15884, 0, /* A=sectors 0 thru 15883 */ 146 33440, 15884, /* B=sectors 15884 thru 49323 */ 147 891072, 0, /* C=sectors 0 thru 891071 */ 148 15884, 242606, /* D=sectors 242606 thru 258489 */ 149 307200, 258490, /* E=sectors 258490 thru 565689 */ 150 325382, 565690, /* F=sectors 565690 thru 891071 */ 151 648466, 242606, /* G=sectors 242606 thru 891071 */ 152 193282, 49324, /* H=sectors 49324 thru 242605 */ 153 154 #endif UCBRA 155 }; 156 157 struct ra_info { 158 struct size *ra_sizes; /* Partion tables for drive */ 159 daddr_t radsize; /* Max user size form online pkt */ 160 unsigned ratype; /* Drive type int field */ 161 unsigned rastatus; /* Command status from */ 162 /* last onlin or GTUNT */ 163 } ra_info[NRA]; 164 165 166 /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ 167 struct uba_ctlr *udminfo[NUDA]; 168 struct uba_device *uddinfo[NRA]; 169 struct uba_device *udip[NUDA][8]; /* 8 == max number of drives */ 170 struct buf rudbuf[NRA]; 171 struct buf udutab[NRA]; 172 struct buf udwtab[NUDA]; /* I/O wait queue, per controller */ 173 174 175 int udamicro[NUDA]; /* to store microcode level */ 176 int udaburst[NUDA] = { 0 }; /* DMA burst size, 0 is default */ 177 178 179 /* 180 * Controller states 181 */ 182 #define S_IDLE 0 /* hasn't been initialized */ 183 #define S_STEP1 1 /* doing step 1 init */ 184 #define S_STEP2 2 /* doing step 2 init */ 185 #define S_STEP3 3 /* doing step 3 init */ 186 #define S_SCHAR 4 /* doing "set controller characteristics" */ 187 #define S_RUN 5 /* running */ 188 189 190 int udaerror = 0; /* causes hex dump of packets */ 191 int udadebug = 0; 192 int uda_cp_wait = 0; /* Something to wait on for command */ 193 /* packets and or credits. */ 194 int wakeup(); 195 extern int hz; /* Should find the right include */ 196 #ifdef DEBUG 197 #define printd if (udadebug) printf 198 #define printd10 if(udadebug >= 10) printf 199 #endif 200 #define mprintf printf /* temporary JG hack until Rich fixes*/ 201 202 int udprobe(), udslave(), udattach(), udintr(); 203 struct mscp *udgetcp(); 204 205 u_short udstd[] = { 0772150, 0772550, 0777550, 0 }; 206 struct uba_driver udadriver = 207 { udprobe, udslave, udattach, 0, udstd, "ra", uddinfo, "uda", udminfo, 0 }; 208 209 #define b_qsize b_resid /* queue size per drive, in udutab */ 210 #define b_ubinfo b_resid /* Unibus mapping info, per buffer */ 211 212 udprobe(reg, ctlr) 213 caddr_t reg; 214 int ctlr; 215 { 216 register int br, cvec; 217 register struct uda_softc *sc = &uda_softc[ctlr]; 218 struct udadevice *udaddr; 219 220 int cur_time; 221 222 #ifdef lint 223 br = 0; cvec = br; br = cvec; 224 udreset(0); udintr(0); 225 #endif 226 udaddr = (struct udadevice *) reg; 227 228 sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 229 #if VAX630 230 if (cpu == VAX_630) { 231 br = 0x15; 232 cvec = sc->sc_ivec; 233 return(sizeof (struct udadevice)); 234 } 235 #endif 236 udaddr->udaip = 0; /* start initialization */ 237 238 cur_time = mfpr(TODR); /* Time of day */ 239 while(cur_time + TENSEC > mfpr(TODR)){ /* wait for at most 10 secs */ 240 if((udaddr->udasa & UDA_STEP1) != 0) 241 break; 242 } 243 if(cur_time + TENSEC <= mfpr(TODR)) 244 return(0); /* Not a uda or it won't init as it */ 245 /* should within ten seconds. */ 246 udaddr->udasa=UDA_ERR|(NCMDL2<<11)|(NRSPL2<<8)|UDA_IE|(sc->sc_ivec/4); 247 while((udaddr->udasa&UDA_STEP2)==0) 248 DELAY(1000); /* intr should have */ 249 /* have happened by now */ 250 251 return(sizeof (struct udadevice)); 252 } 253 254 /* ARGSUSED */ 255 udslave(ui, reg) 256 struct uba_device *ui; 257 caddr_t reg; 258 { 259 register struct uba_ctlr *um = udminfo[ui->ui_ctlr]; 260 register struct uda_softc *sc = &uda_softc[ui->ui_ctlr]; 261 struct udadevice *udaddr; 262 struct mscp *mp; 263 int i; /* Something to write into to start */ 264 /* the uda polling */ 265 266 267 udaddr = (struct udadevice *)um->um_addr; 268 if(sc->sc_state != S_RUN){ 269 if(!udinit(ui->ui_ctlr)) 270 return(0); 271 } 272 /* Here we will wait for the controller */ 273 /* to come into the run state or go idle. If we go idle we are in */ 274 /* touble and I don't yet know what to do so I will punt */ 275 while(sc->sc_state != S_RUN && sc->sc_state != S_IDLE); /* spin */ 276 if(sc->sc_state == S_IDLE){ /* The Uda failed to initialize */ 277 printf("UDA failed to init\n"); 278 return(0); 279 } 280 /* The controller is up so let see if the drive is there! */ 281 if(0 == (mp = udgetcp(um))){ /* ditto */ 282 printf("UDA can't get command packet\n"); 283 return(0); 284 } 285 mp->mscp_opcode = M_OP_GTUNT; /* This should give us the drive type*/ 286 mp->mscp_unit = ui->ui_slave; 287 mp->mscp_cmdref = (long) ui->ui_slave; 288 #ifdef DEBUG 289 printd("uda%d Get unit status slave %d\n",ui->ui_ctlr,ui->ui_slave); 290 #endif 291 ra_info[ui->ui_unit].rastatus = 0; /* set to zero */ 292 udip[ui->ui_ctlr][ui->ui_slave] = ui; 293 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT;/* maybe we should poll*/ 294 i = udaddr->udaip; 295 #ifdef lint 296 i = i; 297 #endif 298 while(!ra_info[ui->ui_unit].rastatus); /* Wait for some status */ 299 udip[ui->ui_ctlr][ui->ui_slave] = 0; 300 if(!ra_info[ui->ui_unit].ratype) /* packet from a GTUNT */ 301 return(0); /* Failed No such drive */ 302 else 303 return(1); /* Got it and it is there */ 304 } 305 306 udattach(ui) 307 register struct uba_device *ui; 308 { 309 register struct uba_ctlr *um = ui->ui_mi ; 310 struct udadevice *udaddr = (struct udadevice *) um->um_addr; 311 struct mscp *mp; 312 int i; /* Something to write into to start */ 313 /* the uda polling */ 314 if (ui->ui_dk >= 0) 315 dk_mspw[ui->ui_dk] = 1.0 / (60 * 31 * 256); /* approx */ 316 ui->ui_flags = 0; 317 udip[ui->ui_ctlr][ui->ui_slave] = ui; 318 /* check to see if the drive is a available if it is bring it online */ 319 /* if not then just return. open will try an online later */ 320 if(ra_info[ui->ui_unit].rastatus != M_ST_AVLBL) 321 return; /* status was set by a GTUNT */ 322 if(0 == (mp = udgetcp(um))){ /* ditto */ 323 printf("UDA can't get command packet\n"); 324 return; 325 } 326 mp->mscp_opcode = M_OP_ONLIN; 327 mp->mscp_unit = ui->ui_slave; 328 mp->mscp_cmdref = (long) ui->ui_slave; 329 #ifdef DEBUG 330 printd("uda%d ONLIN slave %d\n",ui->ui_ctlr,ui->ui_slave); 331 #endif 332 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT; 333 i = udaddr->udaip; 334 #ifdef lint 335 i = i; 336 #endif 337 while(ui->ui_flags == 0 && ra_info[ui->ui_unit].ratype != 0); 338 } 339 340 /* 341 * Open a UDA. Initialize the device and 342 * set the unit online. 343 */ 344 /* ARGSUSED */ 345 udopen(dev, flag) 346 dev_t dev; 347 int flag; 348 { 349 register int unit; 350 register struct uba_device *ui; 351 register struct uda_softc *sc; 352 register struct mscp *mp; 353 register struct uba_ctlr *um; 354 struct udadevice *udaddr; 355 int s,i; 356 357 unit = udunit(dev); 358 if (unit >= NRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0) 359 return (ENXIO); 360 sc = &uda_softc[ui->ui_ctlr]; 361 s = spl5(); 362 if (sc->sc_state != S_RUN) { 363 if (sc->sc_state == S_IDLE) 364 if(!udinit(ui->ui_ctlr)){ 365 printf("uda: Controller failed to init\n"); 366 (void) splx(s); 367 return(ENXIO); 368 } 369 /* wait for initialization to complete */ 370 timeout(wakeup,(caddr_t)ui->ui_mi,11*hz); /* to be sure*/ 371 sleep((caddr_t)ui->ui_mi, 0); 372 if (sc->sc_state != S_RUN) 373 { 374 (void) splx(s); /* added by Rich */ 375 return (EIO); 376 } 377 } 378 /* check to see if the device is really there. */ 379 /* this code was taken from Fred Canters 11 driver */ 380 um = ui->ui_mi; 381 udaddr = (struct udadevice *) um->um_addr; 382 (void) splx(s); 383 if(ui->ui_flags == 0){ 384 s = spl5(); 385 while(0 ==(mp = udgetcp(um))){ 386 uda_cp_wait++; 387 sleep((caddr_t)&uda_cp_wait,PSWP+1); 388 uda_cp_wait--; 389 } 390 mp->mscp_opcode = M_OP_ONLIN; 391 mp->mscp_unit = ui->ui_slave; 392 mp->mscp_cmdref = (long) & ra_info[ui->ui_unit].ratype; 393 /* need to sleep on something */ 394 #ifdef DEBUG 395 printd("uda: bring unit %d online\n",ui->ui_unit); 396 #endif 397 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT ; 398 i = udaddr->udaip; 399 #ifdef lint 400 i = i; 401 #endif 402 timeout(wakeup,(caddr_t) mp->mscp_cmdref,10 * hz); 403 /* make sure we wake up */ 404 sleep((caddr_t) mp->mscp_cmdref,PSWP+1); /*wakeup in udrsp() */ 405 (void) splx(s); 406 } 407 if(ui->ui_flags == 0){ 408 return(ENXIO); /* Didn't go online */ 409 } 410 return (0); 411 } 412 413 /* 414 * Initialize a UDA. Set up UBA mapping registers, 415 * initialize data structures, and start hardware 416 * initialization sequence. 417 */ 418 udinit(d) 419 int d; 420 { 421 register struct uda_softc *sc; 422 register struct uda *ud; 423 struct udadevice *udaddr; 424 struct uba_ctlr *um; 425 426 sc = &uda_softc[d]; 427 um = udminfo[d]; 428 um->um_tab.b_active++; 429 ud = &uda[d]; 430 udaddr = (struct udadevice *)um->um_addr; 431 if (sc->sc_mapped == 0) { 432 /* 433 * Map the communications area and command 434 * and response packets into Unibus address 435 * space. 436 */ 437 sc->sc_ubainfo = uballoc(um->um_ubanum, (caddr_t)ud, 438 sizeof (struct uda), 0); 439 sc->sc_uda = (struct uda *)(sc->sc_ubainfo & 0x3ffff); 440 sc->sc_mapped = 1; 441 } 442 443 /* 444 * Start the hardware initialization sequence. 445 */ 446 447 udaddr->udaip = 0; /* start initialization */ 448 449 while((udaddr->udasa & UDA_STEP1) == 0){ 450 if(udaddr->udasa & UDA_ERR) 451 return(0); /* CHECK */ 452 } 453 udaddr->udasa=UDA_ERR|(NCMDL2<<11)|(NRSPL2<<8)|UDA_IE|(sc->sc_ivec/4); 454 /* 455 * Initialization continues in interrupt routine. 456 */ 457 sc->sc_state = S_STEP1; 458 sc->sc_credits = 0; 459 return(1); 460 } 461 462 udstrategy(bp) 463 register struct buf *bp; 464 { 465 register struct uba_device *ui; 466 register struct uba_ctlr *um; 467 register struct buf *dp; 468 register int unit; 469 register struct size *rasizes; 470 int xunit = minor(bp->b_dev) & 07; 471 daddr_t sz, maxsz; 472 int s; 473 474 sz = (bp->b_bcount+511) >> 9; 475 unit = udunit(bp->b_dev); 476 if (unit >= NRA) { 477 bp->b_error = ENXIO; 478 goto bad; 479 } 480 rasizes = ra_info[unit].ra_sizes; 481 ui = uddinfo[unit]; 482 um = ui->ui_mi; 483 if (ui == 0 || ui->ui_alive == 0) { 484 bp->b_error = ENXIO; 485 goto bad; 486 } 487 if ((maxsz = rasizes[xunit].nblocks) < 0) 488 maxsz = ra_info[unit].radsize - rasizes[xunit].blkoff; 489 if (bp->b_blkno < 0 || bp->b_blkno+sz > maxsz || 490 rasizes[xunit].blkoff >= ra_info[unit].radsize) { 491 if (bp->b_blkno == maxsz) { 492 bp->b_resid = bp->b_bcount; 493 goto done; 494 } 495 bp->b_error = EINVAL; 496 goto bad; 497 } 498 s = spl5(); 499 /* 500 * Link the buffer onto the drive queue 501 */ 502 dp = &udutab[ui->ui_unit]; 503 if (dp->b_actf == 0) 504 dp->b_actf = bp; 505 else 506 dp->b_actl->av_forw = bp; 507 dp->b_actl = bp; 508 bp->av_forw = 0; 509 /* 510 * Link the drive onto the controller queue 511 */ 512 if (dp->b_active == 0) { 513 dp->b_forw = NULL; 514 if (um->um_tab.b_actf == NULL) 515 um->um_tab.b_actf = dp; 516 else 517 um->um_tab.b_actl->b_forw = dp; 518 um->um_tab.b_actl = dp; 519 dp->b_active = 1; 520 } 521 if (um->um_tab.b_active == 0) { 522 #if defined(VAX750) 523 if (cpu == VAX_750 524 && udwtab[um->um_ctlr].av_forw == &udwtab[um->um_ctlr]) { 525 if (um->um_ubinfo != 0) { 526 printd("udastrat: ubinfo 0x%x\n",um->um_ubinfo); 527 } else 528 um->um_ubinfo = 529 uballoc(um->um_ubanum, (caddr_t)0, 0, 530 UBA_NEEDBDP); 531 } 532 #endif 533 (void) udstart(um); 534 } 535 splx(s); 536 return; 537 538 bad: 539 bp->b_flags |= B_ERROR; 540 done: 541 iodone(bp); 542 return; 543 } 544 545 udstart(um) 546 register struct uba_ctlr *um; 547 { 548 register struct buf *bp, *dp; 549 register struct mscp *mp; 550 register struct uda_softc *sc; 551 register struct uba_device *ui; 552 struct size *rasizes; 553 struct udadevice *udaddr; 554 struct uda *ud = &uda[um->um_ctlr]; 555 int i; 556 557 sc = &uda_softc[um->um_ctlr]; 558 559 loop: 560 if ((dp = um->um_tab.b_actf) == NULL) { 561 /* 562 * Release uneeded UBA resources and return 563 */ 564 um->um_tab.b_active = 0; 565 /* Check for response ring transitions lost in the 566 * Race condition 567 */ 568 for (i = sc->sc_lastrsp;; i++) { 569 i %= NRSP; 570 if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) 571 break; 572 udrsp(um, ud, sc, i); 573 ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; 574 } 575 sc->sc_lastrsp = i; 576 return (0); 577 } 578 if ((bp = dp->b_actf) == NULL) { 579 /* 580 * No more requests for this drive, remove 581 * from controller queue and look at next drive. 582 * We know we're at the head of the controller queue. 583 */ 584 dp->b_active = 0; 585 um->um_tab.b_actf = dp->b_forw; 586 goto loop; /* Need to check for loop */ 587 } 588 um->um_tab.b_active++; 589 udaddr = (struct udadevice *)um->um_addr; 590 if ((udaddr->udasa&UDA_ERR) || sc->sc_state != S_RUN) { 591 harderr(bp, "ra"); 592 mprintf("Uda%d udasa %o, state %d\n",um->um_ctlr , udaddr->udasa&0xffff, sc->sc_state); 593 (void)udinit(um->um_ctlr); 594 /* SHOULD REQUEUE OUTSTANDING REQUESTS, LIKE UDRESET */ 595 return (0); 596 } 597 ui = uddinfo[udunit(bp->b_dev)]; 598 rasizes = ra_info[ui->ui_unit].ra_sizes; 599 if (ui->ui_flags == 0) { /* not online */ 600 if ((mp = udgetcp(um)) == NULL){ 601 return (0); 602 } 603 mp->mscp_opcode = M_OP_ONLIN; 604 mp->mscp_unit = ui->ui_slave; 605 dp->b_active = 2; 606 um->um_tab.b_actf = dp->b_forw; /* remove from controller q */ 607 #ifdef DEBUG 608 printd("uda: bring unit %d online\n", ui->ui_slave); 609 #endif 610 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 611 if (udaddr->udasa&UDA_ERR) 612 printf("Uda (%d) Error (%x)\n",um->um_ctlr , udaddr->udasa&0xffff); 613 i = udaddr->udaip; 614 goto loop; 615 } 616 switch (cpu) { 617 case VAX_8600: 618 case VAX_780: 619 i = UBA_NEEDBDP|UBA_CANTWAIT; 620 break; 621 622 case VAX_750: 623 i = um->um_ubinfo|UBA_HAVEBDP|UBA_CANTWAIT; 624 break; 625 626 case VAX_730: 627 case VAX_630: 628 i = UBA_CANTWAIT; 629 break; 630 } 631 if ((i = ubasetup(um->um_ubanum, bp, i)) == 0) 632 return(1); 633 if ((mp = udgetcp(um)) == NULL) { 634 #if defined(VAX750) 635 if (cpu == VAX_750) 636 i &= 0xfffffff; /* mask off bdp */ 637 #endif 638 ubarelse(um->um_ubanum,&i); 639 return(0); 640 } 641 mp->mscp_cmdref = (long)bp; /* pointer to get back */ 642 mp->mscp_opcode = bp->b_flags&B_READ ? M_OP_READ : M_OP_WRITE; 643 mp->mscp_unit = ui->ui_slave; 644 mp->mscp_lbn = bp->b_blkno + rasizes[minor(bp->b_dev)&7].blkoff; 645 mp->mscp_bytecnt = bp->b_bcount; 646 mp->mscp_buffer = (i & 0x3ffff) | (((i>>28)&0xf)<<24); 647 #if defined(VAX750) 648 if (cpu == VAX_750) 649 i &= 0xfffffff; /* mask off bdp */ 650 #endif 651 bp->b_ubinfo = i; /* save mapping info */ 652 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 653 if (udaddr->udasa&UDA_ERR) 654 printf("Uda(%d) udasa (%x)\n",um->um_ctlr , udaddr->udasa&0xffff); 655 i = udaddr->udaip; /* initiate polling */ 656 dp->b_qsize++; 657 if (ui->ui_dk >= 0) { 658 dk_busy |= 1<<ui->ui_dk; 659 dk_xfer[ui->ui_dk]++; 660 dk_wds[ui->ui_dk] += bp->b_bcount>>6; 661 } 662 663 /* 664 * Move drive to the end of the controller queue 665 */ 666 if (dp->b_forw != NULL) { 667 um->um_tab.b_actf = dp->b_forw; 668 um->um_tab.b_actl->b_forw = dp; 669 um->um_tab.b_actl = dp; 670 dp->b_forw = NULL; 671 } 672 /* 673 * Move buffer to I/O wait queue 674 */ 675 dp->b_actf = bp->av_forw; 676 dp = &udwtab[um->um_ctlr]; 677 bp->av_forw = dp; 678 bp->av_back = dp->av_back; 679 dp->av_back->av_forw = bp; 680 dp->av_back = bp; 681 goto loop; 682 } 683 684 /* 685 * UDA interrupt routine. 686 */ 687 udintr(d) 688 int d; 689 { 690 register struct uba_ctlr *um = udminfo[d]; 691 register struct udadevice *udaddr = (struct udadevice *)um->um_addr; 692 struct buf *bp; 693 register int i; 694 register struct uda_softc *sc = &uda_softc[d]; 695 register struct uda *ud = &uda[d]; 696 struct uda *uud; 697 struct mscp *mp; 698 699 #ifdef DEBUG 700 printd10("udintr: state %d, udasa %o\n", sc->sc_state, udaddr->udasa); 701 #endif 702 #ifdef VAX630 703 (void) spl5(); 704 #endif 705 switch (sc->sc_state) { 706 case S_IDLE: 707 printf("uda%d: random interrupt ignored\n", d); 708 return; 709 710 case S_STEP1: 711 #define STEP1MASK 0174377 712 #define STEP1GOOD (UDA_STEP2|UDA_IE|(NCMDL2<<3)|NRSPL2) 713 if ((udaddr->udasa&STEP1MASK) != STEP1GOOD) { 714 sc->sc_state = S_IDLE; 715 wakeup((caddr_t)um); 716 return; 717 } 718 udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)| 719 ((cpu == VAX_780) || (cpu == VAX_8600) ? UDA_PI : 0); 720 sc->sc_state = S_STEP2; 721 return; 722 723 case S_STEP2: 724 #define STEP2MASK 0174377 725 #define STEP2GOOD (UDA_STEP3|UDA_IE|(sc->sc_ivec/4)) 726 if ((udaddr->udasa&STEP2MASK) != STEP2GOOD) { 727 sc->sc_state = S_IDLE; 728 wakeup((caddr_t)um); 729 return; 730 } 731 udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)>>16; 732 sc->sc_state = S_STEP3; 733 return; 734 735 case S_STEP3: 736 #define STEP3MASK 0174000 737 #define STEP3GOOD UDA_STEP4 738 if ((udaddr->udasa&STEP3MASK) != STEP3GOOD) { 739 sc->sc_state = S_IDLE; 740 wakeup((caddr_t)um); 741 return; 742 } 743 udamicro[d] = udaddr->udasa; 744 #ifdef DEBUG 745 printd("Uda%d Version %d model %d\n",d,udamicro[d]&0xF, 746 (udamicro[d]>>4) & 0xF); 747 #endif 748 /* 749 * Requesting the error status (|= 2) 750 * may hang older controllers. 751 */ 752 i = UDA_GO | (udaerror? 2 : 0); 753 if (udaburst[d]) 754 i |= (udaburst[d] - 1) << 2; 755 udaddr->udasa = i; 756 udaddr->udasa = UDA_GO; 757 sc->sc_state = S_SCHAR; 758 759 /* 760 * Initialize the data structures. 761 */ 762 uud = sc->sc_uda; 763 for (i = 0; i < NRSP; i++) { 764 ud->uda_ca.ca_rspdsc[i] = UDA_OWN|UDA_INT| 765 (long)&uud->uda_rsp[i].mscp_cmdref; 766 ud->uda_rsp[i].mscp_dscptr = &ud->uda_ca.ca_rspdsc[i]; 767 ud->uda_rsp[i].mscp_header.uda_msglen = mscp_msglen; 768 } 769 for (i = 0; i < NCMD; i++) { 770 ud->uda_ca.ca_cmddsc[i] = UDA_INT| 771 (long)&uud->uda_cmd[i].mscp_cmdref; 772 ud->uda_cmd[i].mscp_dscptr = &ud->uda_ca.ca_cmddsc[i]; 773 ud->uda_cmd[i].mscp_header.uda_msglen = mscp_msglen; 774 } 775 bp = &udwtab[d]; 776 bp->av_forw = bp->av_back = bp; 777 sc->sc_lastcmd = 1; 778 sc->sc_lastrsp = 0; 779 mp = &uda[um->um_ctlr].uda_cmd[0]; 780 mp->mscp_unit = mp->mscp_modifier = 0; 781 mp->mscp_flags = 0; 782 mp->mscp_bytecnt = mp->mscp_buffer = 0; 783 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 784 mp->mscp_opcode = M_OP_STCON; 785 mp->mscp_cntflgs = M_CF_ATTN|M_CF_MISC|M_CF_THIS; 786 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 787 i = udaddr->udaip; /* initiate polling */ 788 return; 789 790 case S_SCHAR: 791 case S_RUN: 792 break; 793 794 default: 795 printf("uda%d: interrupt in unknown state %d ignored\n", 796 d, sc->sc_state); 797 return; 798 } 799 800 if (udaddr->udasa&UDA_ERR) { 801 printf("uda(%d): fatal error (%o)\n", d, udaddr->udasa&0xffff); 802 udaddr->udaip = 0; 803 wakeup((caddr_t)um); 804 } 805 806 /* 807 * Check for a buffer purge request. 808 */ 809 if (ud->uda_ca.ca_bdp) { 810 #ifdef DEBUG 811 printd("uda: purge bdp %d\n", ud->uda_ca.ca_bdp); 812 #endif 813 UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 814 ud->uda_ca.ca_bdp = 0; 815 udaddr->udasa = 0; /* signal purge complete */ 816 } 817 818 /* 819 * Check for response ring transition. 820 */ 821 if (ud->uda_ca.ca_rspint) { 822 ud->uda_ca.ca_rspint = 0; 823 for (i = sc->sc_lastrsp;; i++) { 824 i %= NRSP; 825 if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) 826 break; 827 udrsp(um, ud, sc, i); 828 ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; 829 } 830 sc->sc_lastrsp = i; 831 } 832 833 /* 834 * Check for command ring transition. 835 */ 836 if (ud->uda_ca.ca_cmdint) { 837 #ifdef DEBUG 838 printd("uda: command ring transition\n"); 839 #endif 840 ud->uda_ca.ca_cmdint = 0; 841 } 842 if(uda_cp_wait) 843 wakeup((caddr_t)&uda_cp_wait); 844 (void) udstart(um); 845 } 846 847 /* 848 * Process a response packet 849 */ 850 udrsp(um, ud, sc, i) 851 register struct uba_ctlr *um; 852 register struct uda *ud; 853 register struct uda_softc *sc; 854 int i; 855 { 856 register struct mscp *mp; 857 struct uba_device *ui; 858 struct buf *dp, *bp,nullbp; 859 int st; 860 861 mp = &ud->uda_rsp[i]; 862 mp->mscp_header.uda_msglen = mscp_msglen; 863 sc->sc_credits += mp->mscp_header.uda_credits & 0xf; /* just 4 bits?*/ 864 if ((mp->mscp_header.uda_credits & 0xf0) > 0x10) /* Check */ 865 return; 866 #ifdef DEBUG 867 printd10("udarsp, opcode 0x%x status 0x%x\n",mp->mscp_opcode,mp->mscp_status); 868 #endif 869 /* 870 * If it's an error log message (datagram), 871 * pass it on for more extensive processing. 872 */ 873 if ((mp->mscp_header.uda_credits & 0xf0) == 0x10) { /* check */ 874 uderror(um, (struct mslg *)mp); 875 return; 876 } 877 st = mp->mscp_status&M_ST_MASK; 878 /* The controller interrupts as drive 0 */ 879 /* this means that you must check for controller interrupts */ 880 /* before you check to see if there is a drive 0 */ 881 if((M_OP_STCON|M_OP_END) == mp->mscp_opcode){ 882 if (st == M_ST_SUCC) 883 sc->sc_state = S_RUN; 884 else 885 sc->sc_state = S_IDLE; 886 um->um_tab.b_active = 0; 887 wakeup((caddr_t)um); 888 return; 889 } 890 if (mp->mscp_unit >= 8) 891 return; 892 if ((ui = udip[um->um_ctlr][mp->mscp_unit]) == 0) 893 return; 894 switch (mp->mscp_opcode) { 895 896 case M_OP_ONLIN|M_OP_END: 897 ra_info[ui->ui_unit].rastatus = st; 898 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 899 dp = &udutab[ui->ui_unit]; 900 if (st == M_ST_SUCC) { 901 /* 902 * Link the drive onto the controller queue 903 */ 904 dp->b_forw = NULL; 905 if (um->um_tab.b_actf == NULL) 906 um->um_tab.b_actf = dp; 907 else 908 um->um_tab.b_actl->b_forw = dp; 909 um->um_tab.b_actl = dp; 910 ui->ui_flags = 1; /* mark it online */ 911 ra_info[ui->ui_unit].radsize=(daddr_t)mp->mscp_untsize; 912 #ifdef DEBUG 913 printd("uda: unit %d online\n", mp->mscp_unit); 914 #endif 915 #define F_to_C(x,i) ( ((x)->mscp_mediaid) >> (i*5+7) & 0x1f ? ( ( (((x)->mscp_mediaid) >>( i*5 + 7)) & 0x1f) + 'A' - 1): ' ') 916 /* this mess decodes the Media type identifier */ 917 #ifdef DEBUG 918 printd("uda: unit %d online %x %c%c %c%c%c%d\n" 919 ,mp->mscp_unit, mp->mscp_mediaid 920 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 921 ,F_to_C(mp,1),F_to_C(mp,0) 922 ,mp->mscp_mediaid & 0x7f); 923 #endif 924 switch((int)(mp->mscp_mediaid & 0x7f)){ 925 case 25: 926 ra_info[ui->ui_unit].ra_sizes = ra25_sizes; 927 break; 928 case 53: 929 ra_info[ui->ui_unit].ra_sizes = ra53_sizes; 930 break; 931 case 60: 932 ra_info[ui->ui_unit].ra_sizes = ra60_sizes; 933 break; 934 case 80: 935 ra_info[ui->ui_unit].ra_sizes = ra80_sizes; 936 break; 937 case 81: 938 ra_info[ui->ui_unit].ra_sizes = ra81_sizes; 939 break; 940 default: 941 ui->ui_flags = 0; /* mark it offline */ 942 ra_info[ui->ui_unit].ratype = 0; 943 printf("Don't have a parition table for "); 944 printf("a %c%c %c%c%c%d\n" 945 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 946 ,F_to_C(mp,1),F_to_C(mp,0) 947 ,mp->mscp_mediaid & 0x7f); 948 while (bp = dp->b_actf) { 949 dp->b_actf = bp->av_forw; 950 bp->b_flags |= B_ERROR; 951 iodone(bp); 952 } 953 } 954 dp->b_active = 1; 955 } else { 956 if(dp->b_actf){ 957 harderr(dp->b_actf,"ra"); 958 } else { 959 nullbp.b_blkno = 0; 960 nullbp.b_dev = makedev(UDADEVNUM,ui->ui_unit); 961 harderr(&nullbp, "ra"); 962 } 963 printf("OFFLINE\n"); 964 while (bp = dp->b_actf) { 965 dp->b_actf = bp->av_forw; 966 bp->b_flags |= B_ERROR; 967 iodone(bp); 968 } 969 } 970 if(mp->mscp_cmdref!=NULL){/* Seems to get lost sometimes */ 971 wakeup((caddr_t)mp->mscp_cmdref); 972 } 973 break; 974 975 /* 976 * The AVAILABLE ATTENTION messages occurs when the 977 * unit becomes available after spinup, 978 * marking the unit offline will force an online command 979 * prior to using the unit. 980 */ 981 case M_OP_AVATN: 982 #ifdef DEBUG 983 printd("uda: unit %d attention\n", mp->mscp_unit); 984 #endif 985 ui->ui_flags = 0; /* it went offline and we didn't notice */ 986 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 987 break; 988 989 case M_OP_END: 990 /* 991 * An endcode without an opcode (0200) is an invalid command. 992 * The mscp specification states that this would be a protocol 993 * type error, such as illegal opcodes. The mscp spec. also 994 * states that parameter error type of invalid commands should 995 * return the normal end message for the command. This does not appear 996 * to be the case. An invalid logical block number returned an endcode 997 * of 0200 instead of the 0241 (read) that was expected. 998 */ 999 1000 printf("endcd=%o, stat=%o\n", mp->mscp_opcode, mp->mscp_status); 1001 break; 1002 case M_OP_READ|M_OP_END: 1003 case M_OP_WRITE|M_OP_END: 1004 bp = (struct buf *)mp->mscp_cmdref; 1005 ubarelse(um->um_ubanum, (int *)&bp->b_ubinfo); 1006 /* 1007 * Unlink buffer from I/O wait queue. 1008 */ 1009 bp->av_back->av_forw = bp->av_forw; 1010 bp->av_forw->av_back = bp->av_back; 1011 #if defined(VAX750) 1012 if (cpu == VAX_750 && um->um_tab.b_active == 0 1013 && udwtab[um->um_ctlr].av_forw == &udwtab[um->um_ctlr]) { 1014 if (um->um_ubinfo == 0) 1015 printf("udintr: um_ubinfo == 0\n"); 1016 else 1017 ubarelse(um->um_ubanum, &um->um_ubinfo); 1018 } 1019 #endif 1020 dp = &udutab[ui->ui_unit]; 1021 dp->b_qsize--; 1022 if (ui->ui_dk >= 0) 1023 if (dp->b_qsize == 0) 1024 dk_busy &= ~(1<<ui->ui_dk); 1025 if (st == M_ST_OFFLN || st == M_ST_AVLBL) { 1026 ui->ui_flags = 0; /* mark unit offline */ 1027 /* 1028 * Link the buffer onto the front of the drive queue 1029 */ 1030 if ((bp->av_forw = dp->b_actf) == 0) 1031 dp->b_actl = bp; 1032 dp->b_actf = bp; 1033 /* 1034 * Link the drive onto the controller queue 1035 */ 1036 if (dp->b_active == 0) { 1037 dp->b_forw = NULL; 1038 if (um->um_tab.b_actf == NULL) 1039 um->um_tab.b_actf = dp; 1040 else 1041 um->um_tab.b_actl->b_forw = dp; 1042 um->um_tab.b_actl = dp; 1043 dp->b_active = 1; 1044 } 1045 #if defined(VAX750) 1046 if (cpu == VAX750 && um->um_ubinfo == 0) 1047 um->um_ubinfo = 1048 uballoc(um->um_ubanum, (caddr_t)0, 0, 1049 UBA_NEEDBDP); 1050 #endif 1051 return; 1052 } 1053 if (st != M_ST_SUCC) { 1054 harderr(bp, "ra"); 1055 #ifdef DEBUG 1056 printd("status %o\n", mp->mscp_status); 1057 #endif 1058 bp->b_flags |= B_ERROR; 1059 } 1060 bp->b_resid = bp->b_bcount - mp->mscp_bytecnt; 1061 iodone(bp); 1062 break; 1063 1064 case M_OP_GTUNT|M_OP_END: 1065 #ifdef DEBUG 1066 printd("GTUNT end packet status = 0x%x media id 0x%x\n" 1067 ,st,mp->mscp_mediaid); 1068 #endif 1069 ra_info[ui->ui_unit].rastatus = st; 1070 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 1071 break; 1072 1073 default: 1074 printf("uda: unknown packet\n"); 1075 uderror(um, (struct mslg *)mp); 1076 } 1077 } 1078 1079 1080 /* 1081 * Process an error log message 1082 * 1083 * For now, just log the error on the console. 1084 * Only minimal decoding is done, only "useful" 1085 * information is printed. Eventually should 1086 * send message to an error logger. 1087 */ 1088 uderror(um, mp) 1089 register struct uba_ctlr *um; 1090 register struct mslg *mp; 1091 { 1092 register i; 1093 1094 1095 if(!(mp->mslg_flags & (M_LF_SUCC | M_LF_CONT))) 1096 printf("uda%d: hard error\n"); 1097 1098 mprintf("uda%d: %s error, ", um->um_ctlr, 1099 mp->mslg_flags & ( M_LF_SUCC | M_LF_CONT ) ? "soft" : "hard"); 1100 switch (mp->mslg_format) { 1101 case M_FM_CNTERR: 1102 mprintf("controller error, event 0%o\n", mp->mslg_event); 1103 break; 1104 1105 case M_FM_BUSADDR: 1106 mprintf("host memory access error, event 0%o, addr 0%o\n", 1107 mp->mslg_event, mp->mslg_busaddr); 1108 break; 1109 1110 case M_FM_DISKTRN: 1111 mprintf("disk transfer error, unit %d, grp 0x%x, hdr 0x%x, event 0%o\n", 1112 mp->mslg_unit, mp->mslg_group, mp->mslg_hdr, 1113 mp->mslg_event); 1114 break; 1115 1116 case M_FM_SDI: 1117 mprintf("SDI error, unit %d, event 0%o, hdr 0x%x\n", 1118 mp->mslg_unit, mp->mslg_event, mp->mslg_hdr); 1119 for(i = 0; i < 12;i++) 1120 mprintf("\t0x%x",mp->mslg_sdistat[i] & 0xff); 1121 mprintf("\n"); 1122 break; 1123 1124 case M_FM_SMLDSK: 1125 mprintf("small disk error, unit %d, event 0%o, cyl %d\n", 1126 mp->mslg_unit, mp->mslg_event, mp->mslg_sdecyl); 1127 break; 1128 1129 default: 1130 mprintf("unknown error, unit %d, format 0%o, event 0%o\n", 1131 mp->mslg_unit, mp->mslg_format, mp->mslg_event); 1132 } 1133 1134 if (udaerror) { 1135 register long *p = (long *)mp; 1136 1137 for (i = 0; i < mp->mslg_header.uda_msglen; i += sizeof(*p)) 1138 printf("%x ", *p++); 1139 printf("\n"); 1140 } 1141 } 1142 1143 1144 /* 1145 * Find an unused command packet 1146 */ 1147 struct mscp * 1148 udgetcp(um) 1149 struct uba_ctlr *um; 1150 { 1151 register struct mscp *mp; 1152 register struct udaca *cp; 1153 register struct uda_softc *sc; 1154 register int i; 1155 int s; 1156 1157 s = spl5(); 1158 cp = &uda[um->um_ctlr].uda_ca; 1159 sc = &uda_softc[um->um_ctlr]; 1160 /* 1161 * If no credits, can't issue any commands 1162 * until some outstanding commands complete. 1163 */ 1164 i = sc->sc_lastcmd; 1165 if(((cp->ca_cmddsc[i]&(UDA_OWN|UDA_INT))==UDA_INT)&& 1166 (sc->sc_credits >= 2)) { 1167 sc->sc_credits--; /* committed to issuing a command */ 1168 cp->ca_cmddsc[i] &= ~UDA_INT; 1169 mp = &uda[um->um_ctlr].uda_cmd[i]; 1170 mp->mscp_unit = mp->mscp_modifier = 0; 1171 mp->mscp_opcode = mp->mscp_flags = 0; 1172 mp->mscp_bytecnt = mp->mscp_buffer = 0; 1173 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 1174 sc->sc_lastcmd = (i + 1) % NCMD; 1175 (void) splx(s); 1176 return(mp); 1177 } 1178 (void) splx(s); 1179 return(NULL); 1180 } 1181 1182 udread(dev, uio) 1183 dev_t dev; 1184 struct uio *uio; 1185 { 1186 register int unit = udunit(dev); 1187 1188 if (unit >= NRA) 1189 return (ENXIO); 1190 return (physio(udstrategy, &rudbuf[unit], dev, B_READ, minphys, uio)); 1191 } 1192 1193 udwrite(dev, uio) 1194 dev_t dev; 1195 struct uio *uio; 1196 { 1197 register int unit = udunit(dev); 1198 1199 if (unit >= NRA) 1200 return (ENXIO); 1201 return (physio(udstrategy, &rudbuf[unit], dev, B_WRITE, minphys, uio)); 1202 } 1203 1204 udreset(uban) 1205 int uban; 1206 { 1207 register struct uba_ctlr *um; 1208 register struct uba_device *ui; 1209 register struct buf *bp, *dp; 1210 register int unit; 1211 struct buf *nbp; 1212 int d; 1213 1214 for (d = 0; d < NUDA; d++) { 1215 if ((um = udminfo[d]) == 0 || um->um_ubanum != uban || 1216 um->um_alive == 0) 1217 continue; 1218 printf(" uda%d", d); 1219 um->um_tab.b_active = 0; 1220 um->um_tab.b_actf = um->um_tab.b_actl = 0; 1221 uda_softc[d].sc_state = S_IDLE; 1222 uda_softc[d].sc_mapped = 0; /* Rich */ 1223 for (unit = 0; unit < NRA; unit++) { 1224 if ((ui = uddinfo[unit]) == 0) 1225 continue; 1226 if (ui->ui_alive == 0 || ui->ui_mi != um) 1227 continue; 1228 udutab[unit].b_active = 0; 1229 udutab[unit].b_qsize = 0; 1230 } 1231 for (bp = udwtab[d].av_forw; bp != &udwtab[d]; bp = nbp) { 1232 nbp = bp->av_forw; 1233 bp->b_ubinfo = 0; 1234 /* 1235 * Link the buffer onto the drive queue 1236 */ 1237 dp = &udutab[udunit(bp->b_dev)]; 1238 if (dp->b_actf == 0) 1239 dp->b_actf = bp; 1240 else 1241 dp->b_actl->av_forw = bp; 1242 dp->b_actl = bp; 1243 bp->av_forw = 0; 1244 /* 1245 * Link the drive onto the controller queue 1246 */ 1247 if (dp->b_active == 0) { 1248 dp->b_forw = NULL; 1249 if (um->um_tab.b_actf == NULL) 1250 um->um_tab.b_actf = dp; 1251 else 1252 um->um_tab.b_actl->b_forw = dp; 1253 um->um_tab.b_actl = dp; 1254 dp->b_active = 1; 1255 } 1256 } 1257 (void)udinit(d); 1258 } 1259 } 1260 1261 #define DBSIZE 32 1262 1263 #define ca_Rspdsc ca_rspdsc[0] 1264 #define ca_Cmddsc ca_rspdsc[1] 1265 #define uda_Rsp uda_rsp[0] 1266 #define uda_Cmd uda_cmd[0] 1267 1268 struct uda udad[NUDA]; 1269 1270 uddump(dev) 1271 dev_t dev; 1272 { 1273 struct udadevice *udaddr; 1274 struct uda *ud_ubaddr; 1275 char *start; 1276 int num, blk, unit; 1277 int maxsz; 1278 int blkoff; 1279 register struct uba_regs *uba; 1280 register struct uba_device *ui; 1281 register struct uda *udp; 1282 register struct pte *io; 1283 register int i; 1284 struct size *rasizes; 1285 unit = udunit(dev); 1286 if (unit >= NRA) 1287 return (ENXIO); 1288 #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) 1289 ui = phys(struct uba_device *, uddinfo[unit]); 1290 if (ui->ui_alive == 0) 1291 return (ENXIO); 1292 uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 1293 ubainit(uba); 1294 udaddr = (struct udadevice *)ui->ui_physaddr; 1295 DELAY(2000000); 1296 udp = phys(struct uda *, &udad[ui->ui_ctlr]); 1297 1298 num = btoc(sizeof(struct uda)) + 1; 1299 io = &uba->uba_map[NUBMREG-num]; 1300 for(i = 0; i<num; i++) 1301 *(int *)io++ = UBAMR_MRV|(btop(udp)+i); 1302 ud_ubaddr = (struct uda *)(((int)udp & PGOFSET)|((NUBMREG-num)<<9)); 1303 1304 udaddr->udaip = 0; 1305 while ((udaddr->udasa & UDA_STEP1) == 0) 1306 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1307 udaddr->udasa = UDA_ERR; 1308 while ((udaddr->udasa & UDA_STEP2) == 0) 1309 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1310 udaddr->udasa = (short)&ud_ubaddr->uda_ca.ca_ringbase; 1311 while ((udaddr->udasa & UDA_STEP3) == 0) 1312 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1313 udaddr->udasa = (short)(((int)&ud_ubaddr->uda_ca.ca_ringbase) >> 16); 1314 while ((udaddr->udasa & UDA_STEP4) == 0) 1315 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1316 udaddr->udasa = UDA_GO; 1317 udp->uda_ca.ca_Rspdsc = (long)&ud_ubaddr->uda_Rsp.mscp_cmdref; 1318 udp->uda_ca.ca_Cmddsc = (long)&ud_ubaddr->uda_Cmd.mscp_cmdref; 1319 udp->uda_Cmd.mscp_cntflgs = 0; 1320 udp->uda_Cmd.mscp_version = 0; 1321 if (udcmd(M_OP_STCON, udp, udaddr) == 0) { 1322 return(EFAULT); 1323 } 1324 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1325 if (udcmd(M_OP_ONLIN, udp, udaddr) == 0) { 1326 return(EFAULT); 1327 } 1328 1329 num = maxfree; 1330 start = 0; 1331 rasizes = ra_info[ui->ui_unit].ra_sizes; 1332 maxsz = rasizes[minor(dev)&07].nblocks; 1333 blkoff = rasizes[minor(dev)&07].blkoff; 1334 if(maxsz < 0) 1335 maxsz = ra_info[unit].radsize-blkoff; 1336 if (dumplo < 0) 1337 return (EINVAL); 1338 if (dumplo + num >= maxsz) 1339 num = maxsz - dumplo; 1340 blkoff += dumplo; 1341 while (num > 0) { 1342 blk = num > DBSIZE ? DBSIZE : num; 1343 io = uba->uba_map; 1344 for (i = 0; i < blk; i++) 1345 *(int *)io++ = (btop(start)+i) | UBAMR_MRV; 1346 *(int *)io = 0; 1347 udp->uda_Cmd.mscp_lbn = btop(start) + blkoff; 1348 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1349 udp->uda_Cmd.mscp_bytecnt = blk*NBPG; 1350 udp->uda_Cmd.mscp_buffer = 0; 1351 if (udcmd(M_OP_WRITE, udp, udaddr) == 0) { 1352 return(EIO); 1353 } 1354 start += blk*NBPG; 1355 num -= blk; 1356 } 1357 return (0); 1358 } 1359 1360 1361 udcmd(op, udp, udaddr) 1362 int op; 1363 register struct uda *udp; 1364 struct udadevice *udaddr; 1365 { 1366 int i; 1367 1368 udp->uda_Cmd.mscp_opcode = op; 1369 udp->uda_Rsp.mscp_header.uda_msglen = mscp_msglen; 1370 udp->uda_Cmd.mscp_header.uda_msglen = mscp_msglen; 1371 udp->uda_ca.ca_Rspdsc |= UDA_OWN|UDA_INT; 1372 udp->uda_ca.ca_Cmddsc |= UDA_OWN|UDA_INT; 1373 if (udaddr->udasa&UDA_ERR) 1374 printf("Udaerror udasa (%x)\n", udaddr->udasa&0xffff); 1375 i = udaddr->udaip; 1376 #ifdef lint 1377 i = i; 1378 #endif 1379 for (;;) { 1380 if (udp->uda_ca.ca_cmdint) 1381 udp->uda_ca.ca_cmdint = 0; 1382 if (udp->uda_ca.ca_rspint) 1383 break; 1384 } 1385 udp->uda_ca.ca_rspint = 0; 1386 if (udp->uda_Rsp.mscp_opcode != (op|M_OP_END) || 1387 (udp->uda_Rsp.mscp_status&M_ST_MASK) != M_ST_SUCC) { 1388 printf("error: com %d opc 0x%x stat 0x%x\ndump ", 1389 op, 1390 udp->uda_Rsp.mscp_opcode, 1391 udp->uda_Rsp.mscp_status); 1392 return(0); 1393 } 1394 return(1); 1395 } 1396 1397 udsize(dev) 1398 dev_t dev; 1399 { 1400 int unit = udunit(dev); 1401 struct uba_device *ui; 1402 struct size *rasizes; 1403 1404 if (unit >= NRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0 1405 || ui->ui_flags == 0) 1406 return (-1); 1407 rasizes = ra_info[ui->ui_unit].ra_sizes; 1408 return (rasizes[minor(dev) & 07].nblocks); 1409 } 1410 1411 #endif 1412