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