1 /* 2 * @(#)uda.c 6.13 (Berkeley) 10/11/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 return(ENXIO); 362 } 363 /* wait for initialization to complete */ 364 timeout(wakeup,(caddr_t)ui->ui_mi,11*hz); /* to be sure*/ 365 sleep((caddr_t)ui->ui_mi, 0); 366 if (sc->sc_state != S_RUN) 367 { 368 (void) splx(s); /* added by Rich */ 369 return (EIO); 370 } 371 } 372 /* check to see if the device is really there. */ 373 /* this code was taken from Fred Canters 11 driver */ 374 um = ui->ui_mi; 375 udaddr = (struct udadevice *) um->um_addr; 376 (void) splx(s); 377 if(ui->ui_flags == 0){ 378 s = spl5(); 379 while(0 ==(mp = udgetcp(um))){ 380 uda_cp_wait++; 381 sleep(&uda_cp_wait,PSWP+1); 382 uda_cp_wait--; 383 } 384 mp->mscp_opcode = M_OP_ONLIN; 385 mp->mscp_unit = ui->ui_slave; 386 mp->mscp_cmdref = (long) & ra_info[ui->ui_unit].ratype; 387 /* need to sleep on something */ 388 #ifdef DEBUG 389 printd("uda: bring unit %d online\n",ui->ui_unit); 390 #endif 391 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT ; 392 i = udaddr->udaip; 393 timeout(wakeup,(caddr_t) mp->mscp_cmdref,10 * hz); 394 /* make sure we wake up */ 395 sleep((caddr_t) mp->mscp_cmdref,PSWP+1); /*wakeup in udrsp() */ 396 (void) splx(s); 397 } 398 if(ui->ui_flags == 0){ 399 return(ENXIO); /* Didn't go online */ 400 } 401 return (0); 402 } 403 404 /* 405 * Initialize a UDA. Set up UBA mapping registers, 406 * initialize data structures, and start hardware 407 * initialization sequence. 408 */ 409 udinit(d) 410 int d; 411 { 412 register struct uda_softc *sc; 413 register struct uda *ud; 414 struct udadevice *udaddr; 415 struct uba_ctlr *um; 416 417 sc = &uda_softc[d]; 418 um = udminfo[d]; 419 um->um_tab.b_active++; 420 ud = &uda[d]; 421 udaddr = (struct udadevice *)um->um_addr; 422 if (sc->sc_mapped == 0) { 423 /* 424 * Map the communications area and command 425 * and response packets into Unibus address 426 * space. 427 */ 428 sc->sc_ubainfo = uballoc(um->um_ubanum, (caddr_t)ud, 429 sizeof (struct uda), 0); 430 sc->sc_uda = (struct uda *)(sc->sc_ubainfo & 0x3ffff); 431 sc->sc_mapped = 1; 432 } 433 434 /* 435 * Start the hardware initialization sequence. 436 */ 437 438 udaddr->udaip = 0; /* start initialization */ 439 440 while((udaddr->udasa & UDA_STEP1) == 0){ 441 if(udaddr->udasa & UDA_ERR) 442 return(0); /* CHECK */ 443 } 444 udaddr->udasa=UDA_ERR|(NCMDL2<<11)|(NRSPL2<<8)|UDA_IE|(sc->sc_ivec/4); 445 /* 446 * Initialization continues in interrupt routine. 447 */ 448 sc->sc_state = S_STEP1; 449 sc->sc_credits = 0; 450 return(1); 451 } 452 453 udstrategy(bp) 454 register struct buf *bp; 455 { 456 register struct uba_device *ui; 457 register struct uba_ctlr *um; 458 register struct buf *dp; 459 register int unit; 460 register struct size *rasizes; 461 int xunit = minor(bp->b_dev) & 07; 462 daddr_t sz, maxsz; 463 int s; 464 465 sz = (bp->b_bcount+511) >> 9; 466 unit = udunit(bp->b_dev); 467 if (unit >= nNRA) { 468 bp->b_error = ENXIO; 469 goto bad; 470 } 471 rasizes = ra_info[unit].ra_sizes; 472 ui = uddinfo[unit]; 473 um = ui->ui_mi; 474 if (ui == 0 || ui->ui_alive == 0) { 475 bp->b_error = ENXIO; 476 goto bad; 477 } 478 if ((maxsz = rasizes[xunit].nblocks) < 0) 479 maxsz = ra_info[unit].radsize - rasizes[xunit].blkoff; 480 if (bp->b_blkno < 0 || bp->b_blkno+sz > maxsz || 481 rasizes[xunit].blkoff >= ra_info[unit].radsize) { 482 if (bp->b_blkno == maxsz) { 483 bp->b_resid = bp->b_bcount; 484 goto done; 485 } 486 bp->b_error = EINVAL; 487 goto bad; 488 } 489 s = spl5(); 490 /* 491 * Link the buffer onto the drive queue 492 */ 493 dp = &udutab[ui->ui_unit]; 494 if (dp->b_actf == 0) 495 dp->b_actf = bp; 496 else 497 dp->b_actl->av_forw = bp; 498 dp->b_actl = bp; 499 bp->av_forw = 0; 500 /* 501 * Link the drive onto the controller queue 502 */ 503 if (dp->b_active == 0) { 504 dp->b_forw = NULL; 505 if (um->um_tab.b_actf == NULL) 506 um->um_tab.b_actf = dp; 507 else 508 um->um_tab.b_actl->b_forw = dp; 509 um->um_tab.b_actl = dp; 510 dp->b_active = 1; 511 } 512 if (um->um_tab.b_active == 0) { 513 #if defined(VAX750) 514 if (cpu == VAX_750 515 && udwtab[um->um_ctlr].av_forw == &udwtab[um->um_ctlr]) { 516 if (um->um_ubinfo != 0) { 517 printd("udastrat: ubinfo 0x%x\n",um->um_ubinfo); 518 } else 519 um->um_ubinfo = 520 uballoc(um->um_ubanum, (caddr_t)0, 0, 521 UBA_NEEDBDP); 522 } 523 #endif 524 (void) udstart(um); 525 } 526 splx(s); 527 return; 528 529 bad: 530 bp->b_flags |= B_ERROR; 531 done: 532 iodone(bp); 533 return; 534 } 535 536 udstart(um) 537 register struct uba_ctlr *um; 538 { 539 register struct buf *bp, *dp; 540 register struct mscp *mp; 541 register struct uda_softc *sc; 542 register struct uba_device *ui; 543 struct size *rasizes; 544 struct udadevice *udaddr; 545 struct uda *ud = &uda[um->um_ctlr]; 546 int i; 547 548 sc = &uda_softc[um->um_ctlr]; 549 550 loop: 551 if ((dp = um->um_tab.b_actf) == NULL) { 552 /* 553 * Release uneeded UBA resources and return 554 */ 555 um->um_tab.b_active = 0; 556 /* Check for response ring transitions lost in the 557 * Race condition 558 */ 559 for (i = sc->sc_lastrsp;; i++) { 560 i %= NRSP; 561 if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) 562 break; 563 udrsp(um, ud, sc, i); 564 ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; 565 } 566 sc->sc_lastrsp = i; 567 return (0); 568 } 569 if ((bp = dp->b_actf) == NULL) { 570 /* 571 * No more requests for this drive, remove 572 * from controller queue and look at next drive. 573 * We know we're at the head of the controller queue. 574 */ 575 dp->b_active = 0; 576 um->um_tab.b_actf = dp->b_forw; 577 goto loop; /* Need to check for loop */ 578 } 579 um->um_tab.b_active++; 580 udaddr = (struct udadevice *)um->um_addr; 581 if ((udaddr->udasa&UDA_ERR) || sc->sc_state != S_RUN) { 582 harderr(bp, "ra"); 583 mprintf("Uda%d udasa %o, state %d\n",um->um_ctlr , udaddr->udasa&0xffff, sc->sc_state); 584 udinit(um->um_ctlr); 585 /* SHOULD REQUEUE OUTSTANDING REQUESTS, LIKE UDRESET */ 586 return (0); 587 } 588 ui = uddinfo[udunit(bp->b_dev)]; 589 rasizes = ra_info[ui->ui_unit].ra_sizes; 590 if (ui->ui_flags == 0) { /* not online */ 591 if ((mp = udgetcp(um)) == NULL){ 592 return (0); 593 } 594 mp->mscp_opcode = M_OP_ONLIN; 595 mp->mscp_unit = ui->ui_slave; 596 dp->b_active = 2; 597 um->um_tab.b_actf = dp->b_forw; /* remove from controller q */ 598 #ifdef DEBUG 599 printd("uda: bring unit %d online\n", ui->ui_slave); 600 #endif 601 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 602 if (udaddr->udasa&UDA_ERR) 603 printf("Uda (%d) Error (%x)\n",um->um_ctlr , udaddr->udasa&0xffff); 604 i = udaddr->udaip; 605 goto loop; 606 } 607 switch (cpu) { 608 case VAX_8600: 609 case VAX_780: 610 i = UBA_NEEDBDP|UBA_CANTWAIT; 611 break; 612 613 case VAX_750: 614 i = um->um_ubinfo|UBA_HAVEBDP|UBA_CANTWAIT; 615 break; 616 617 case VAX_730: 618 i = UBA_CANTWAIT; 619 break; 620 } 621 if ((i = ubasetup(um->um_ubanum, bp, i)) == 0) 622 return(1); 623 if ((mp = udgetcp(um)) == NULL) { 624 ubarelse(um->um_ubanum,&i); 625 return(0); 626 } 627 mp->mscp_cmdref = (long)bp; /* pointer to get back */ 628 mp->mscp_opcode = bp->b_flags&B_READ ? M_OP_READ : M_OP_WRITE; 629 mp->mscp_unit = ui->ui_slave; 630 mp->mscp_lbn = bp->b_blkno + rasizes[minor(bp->b_dev)&7].blkoff; 631 mp->mscp_bytecnt = bp->b_bcount; 632 mp->mscp_buffer = (i & 0x3ffff) | (((i>>28)&0xf)<<24); 633 #if defined(VAX750) 634 if (cpu == VAX_750) 635 i &= 0xfffffff; /* mask off bdp */ 636 #endif 637 bp->b_ubinfo = i; /* save mapping info */ 638 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 639 if (udaddr->udasa&UDA_ERR) 640 printf("Uda(%d) udasa (%x)\n",um->um_ctlr , udaddr->udasa&0xffff); 641 i = udaddr->udaip; /* initiate polling */ 642 dp->b_qsize++; 643 if (ui->ui_dk >= 0) { 644 dk_busy |= 1<<ui->ui_dk; 645 dk_xfer[ui->ui_dk]++; 646 dk_wds[ui->ui_dk] += bp->b_bcount>>6; 647 } 648 649 /* 650 * Move drive to the end of the controller queue 651 */ 652 if (dp->b_forw != NULL) { 653 um->um_tab.b_actf = dp->b_forw; 654 um->um_tab.b_actl->b_forw = dp; 655 um->um_tab.b_actl = dp; 656 dp->b_forw = NULL; 657 } 658 /* 659 * Move buffer to I/O wait queue 660 */ 661 dp->b_actf = bp->av_forw; 662 dp = &udwtab[um->um_ctlr]; 663 bp->av_forw = dp; 664 bp->av_back = dp->av_back; 665 dp->av_back->av_forw = bp; 666 dp->av_back = bp; 667 goto loop; 668 } 669 670 /* 671 * UDA interrupt routine. 672 */ 673 udintr(d) 674 int d; 675 { 676 register struct uba_ctlr *um = udminfo[d]; 677 register struct udadevice *udaddr = (struct udadevice *)um->um_addr; 678 struct buf *bp; 679 register int i; 680 register struct uda_softc *sc = &uda_softc[d]; 681 register struct uda *ud = &uda[d]; 682 struct uda *uud; 683 struct mscp *mp; 684 685 #ifdef DEBUG 686 printd10("udintr: state %d, udasa %o\n", sc->sc_state, udaddr->udasa); 687 #endif 688 switch (sc->sc_state) { 689 case S_IDLE: 690 printf("uda%d: random interrupt ignored\n", d); 691 return; 692 693 case S_STEP1: 694 #define STEP1MASK 0174377 695 #define STEP1GOOD (UDA_STEP2|UDA_IE|(NCMDL2<<3)|NRSPL2) 696 if ((udaddr->udasa&STEP1MASK) != STEP1GOOD) { 697 sc->sc_state = S_IDLE; 698 wakeup((caddr_t)um); 699 return; 700 } 701 udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)| 702 ((cpu == VAX_780) || (cpu == VAX_8600) ? UDA_PI : 0); 703 sc->sc_state = S_STEP2; 704 return; 705 706 case S_STEP2: 707 #define STEP2MASK 0174377 708 #define STEP2GOOD (UDA_STEP3|UDA_IE|(sc->sc_ivec/4)) 709 if ((udaddr->udasa&STEP2MASK) != STEP2GOOD) { 710 sc->sc_state = S_IDLE; 711 wakeup((caddr_t)um); 712 return; 713 } 714 udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)>>16; 715 sc->sc_state = S_STEP3; 716 return; 717 718 case S_STEP3: 719 #define STEP3MASK 0174000 720 #define STEP3GOOD UDA_STEP4 721 if ((udaddr->udasa&STEP3MASK) != STEP3GOOD) { 722 sc->sc_state = S_IDLE; 723 wakeup((caddr_t)um); 724 return; 725 } 726 udamicro[d] = udaddr->udasa; 727 #ifdef DEBUG 728 printd("Uda%d Version %d model %d\n",d,udamicro[d]&0xF, 729 (udamicro[d]>>4) & 0xF); 730 /* 731 * Requesting the error status (|= 2) 732 * may hang older controllers. 733 */ 734 udaddr->udasa = UDA_GO | (udaerror? 2 : 0); 735 #endif 736 udaddr->udasa = UDA_GO; 737 sc->sc_state = S_SCHAR; 738 739 /* 740 * Initialize the data structures. 741 */ 742 uud = sc->sc_uda; 743 for (i = 0; i < NRSP; i++) { 744 ud->uda_ca.ca_rspdsc[i] = UDA_OWN|UDA_INT| 745 (long)&uud->uda_rsp[i].mscp_cmdref; 746 ud->uda_rsp[i].mscp_dscptr = &ud->uda_ca.ca_rspdsc[i]; 747 ud->uda_rsp[i].mscp_header.uda_msglen = mscp_msglen; 748 } 749 for (i = 0; i < NCMD; i++) { 750 ud->uda_ca.ca_cmddsc[i] = UDA_INT| 751 (long)&uud->uda_cmd[i].mscp_cmdref; 752 ud->uda_cmd[i].mscp_dscptr = &ud->uda_ca.ca_cmddsc[i]; 753 ud->uda_cmd[i].mscp_header.uda_msglen = mscp_msglen; 754 } 755 bp = &udwtab[d]; 756 bp->av_forw = bp->av_back = bp; 757 sc->sc_lastcmd = 1; 758 sc->sc_lastrsp = 0; 759 mp = &uda[um->um_ctlr].uda_cmd[0]; 760 mp->mscp_unit = mp->mscp_modifier = 0; 761 mp->mscp_flags = 0; 762 mp->mscp_bytecnt = mp->mscp_buffer = 0; 763 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 764 mp->mscp_opcode = M_OP_STCON; 765 mp->mscp_cntflgs = M_CF_ATTN|M_CF_MISC|M_CF_THIS; 766 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 767 i = udaddr->udaip; /* initiate polling */ 768 return; 769 770 case S_SCHAR: 771 case S_RUN: 772 break; 773 774 default: 775 printf("uda%d: interrupt in unknown state %d ignored\n", 776 d, sc->sc_state); 777 return; 778 } 779 780 if (udaddr->udasa&UDA_ERR) { 781 printf("uda(%d): fatal error (%o)\n", d, udaddr->udasa&0xffff); 782 udaddr->udaip = 0; 783 wakeup((caddr_t)um); 784 } 785 786 /* 787 * Check for a buffer purge request. 788 */ 789 if (ud->uda_ca.ca_bdp) { 790 /* 791 * THIS IS A KLUDGE. 792 * Maybe we should change the entire 793 * UBA interface structure. 794 */ 795 int s = spl6(); /* was spl7 but I don't like turning */ 796 /* off machine checks */ 797 i = um->um_ubinfo; 798 #ifdef DEBUG 799 printd("uda: purge bdp %d\n", ud->uda_ca.ca_bdp); 800 #endif 801 um->um_ubinfo = ud->uda_ca.ca_bdp<<28; 802 ubapurge(um); 803 um->um_ubinfo = i; 804 (void) splx(s); 805 ud->uda_ca.ca_bdp = 0; 806 udaddr->udasa = 0; /* signal purge complete */ 807 } 808 809 /* 810 * Check for response ring transition. 811 */ 812 if (ud->uda_ca.ca_rspint) { 813 ud->uda_ca.ca_rspint = 0; 814 for (i = sc->sc_lastrsp;; i++) { 815 i %= NRSP; 816 if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) 817 break; 818 udrsp(um, ud, sc, i); 819 ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; 820 } 821 sc->sc_lastrsp = i; 822 } 823 824 /* 825 * Check for command ring transition. 826 */ 827 if (ud->uda_ca.ca_cmdint) { 828 #ifdef DEBUG 829 printd("uda: command ring transition\n"); 830 #endif 831 ud->uda_ca.ca_cmdint = 0; 832 } 833 if(uda_cp_wait) 834 wakeup(&uda_cp_wait); 835 (void) udstart(um); 836 } 837 838 /* 839 * Process a response packet 840 */ 841 udrsp(um, ud, sc, i) 842 register struct uba_ctlr *um; 843 register struct uda *ud; 844 register struct uda_softc *sc; 845 int i; 846 { 847 register struct mscp *mp; 848 struct uba_device *ui; 849 struct buf *dp, *bp,nullbp; 850 int st; 851 852 mp = &ud->uda_rsp[i]; 853 mp->mscp_header.uda_msglen = mscp_msglen; 854 sc->sc_credits += mp->mscp_header.uda_credits & 0xf; /* just 4 bits?*/ 855 if ((mp->mscp_header.uda_credits & 0xf0) > 0x10) /* Check */ 856 return; 857 #ifdef DEBUG 858 printd10("udarsp, opcode 0x%x status 0x%x\n",mp->mscp_opcode,mp->mscp_status); 859 #endif 860 /* 861 * If it's an error log message (datagram), 862 * pass it on for more extensive processing. 863 */ 864 if ((mp->mscp_header.uda_credits & 0xf0) == 0x10) { /* check */ 865 uderror(um, (struct mslg *)mp); 866 return; 867 } 868 st = mp->mscp_status&M_ST_MASK; 869 /* The controller interrupts as drive 0 */ 870 /* this means that you must check for controller interrupts */ 871 /* before you check to see if there is a drive 0 */ 872 if((M_OP_STCON|M_OP_END) == mp->mscp_opcode){ 873 if (st == M_ST_SUCC) 874 sc->sc_state = S_RUN; 875 else 876 sc->sc_state = S_IDLE; 877 um->um_tab.b_active = 0; 878 wakeup((caddr_t)um); 879 return; 880 } 881 if (mp->mscp_unit >= 8) 882 return; 883 if ((ui = udip[um->um_ctlr][mp->mscp_unit]) == 0) 884 return; 885 switch (mp->mscp_opcode) { 886 887 case M_OP_ONLIN|M_OP_END: 888 ra_info[ui->ui_unit].rastatus = st; 889 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 890 dp = &udutab[ui->ui_unit]; 891 if (st == M_ST_SUCC) { 892 /* 893 * Link the drive onto the controller queue 894 */ 895 dp->b_forw = NULL; 896 if (um->um_tab.b_actf == NULL) 897 um->um_tab.b_actf = dp; 898 else 899 um->um_tab.b_actl->b_forw = dp; 900 um->um_tab.b_actl = dp; 901 ui->ui_flags = 1; /* mark it online */ 902 ra_info[ui->ui_unit].radsize=(daddr_t)mp->mscp_untsize; 903 #ifdef DEBUG 904 printd("uda: unit %d online\n", mp->mscp_unit); 905 #endif 906 #define F_to_C(x,i) ( ((x)->mscp_mediaid) >> (i*5+7) & 0x1f ? ( ( (((x)->mscp_mediaid) >>( i*5 + 7)) & 0x1f) + 'A' - 1): ' ') 907 /* this mess decodes the Media type identifier */ 908 #ifdef DEBUG 909 printd("uda: unit %d online %x %c%c %c%c%c%d\n" 910 ,mp->mscp_unit, mp->mscp_mediaid 911 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 912 ,F_to_C(mp,1),F_to_C(mp,0) 913 ,mp->mscp_mediaid & 0x7f); 914 #endif 915 switch(mp->mscp_mediaid & 0x7f){ 916 case 25: 917 ra_info[ui->ui_unit].ra_sizes = ra25_sizes; 918 break; 919 case 60: 920 ra_info[ui->ui_unit].ra_sizes = ra60_sizes; 921 break; 922 case 80: 923 ra_info[ui->ui_unit].ra_sizes = ra80_sizes; 924 break; 925 case 81: 926 ra_info[ui->ui_unit].ra_sizes = ra81_sizes; 927 break; 928 default: 929 ui->ui_flags = 0; /* mark it offline */ 930 ra_info[ui->ui_unit].ratype = 0; 931 printf("Don't have a parition table for "); 932 printf("a %c%c %c%c%c%d\n" 933 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 934 ,F_to_C(mp,1),F_to_C(mp,0) 935 ,mp->mscp_mediaid & 0x7f); 936 while (bp = dp->b_actf) { 937 dp->b_actf = bp->av_forw; 938 bp->b_flags |= B_ERROR; 939 iodone(bp); 940 } 941 } 942 dp->b_active = 1; 943 } else { 944 if(dp->b_actf){ 945 harderr(dp->b_actf,"ra"); 946 } else { 947 nullbp.b_blkno = 0; 948 nullbp.b_dev = makedev(UDADEVNUM,ui->ui_unit); 949 harderr(&nullbp, "ra"); 950 } 951 printf("OFFLINE\n"); 952 while (bp = dp->b_actf) { 953 dp->b_actf = bp->av_forw; 954 bp->b_flags |= B_ERROR; 955 iodone(bp); 956 } 957 } 958 if(mp->mscp_cmdref!=NULL){/* Seems to get lost sometimes */ 959 wakeup((caddr_t *) mp->mscp_cmdref); 960 } 961 break; 962 963 /* 964 * The AVAILABLE ATTENTION messages occurs when the 965 * unit becomes available after spinup, 966 * marking the unit offline will force an online command 967 * prior to using the unit. 968 */ 969 case M_OP_AVATN: 970 #ifdef DEBUG 971 printd("uda: unit %d attention\n", mp->mscp_unit); 972 #endif 973 ui->ui_flags = 0; /* it went offline and we didn't notice */ 974 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 975 break; 976 977 case M_OP_END: 978 /* 979 * An endcode without an opcode (0200) is an invalid command. 980 * The mscp specification states that this would be a protocol 981 * type error, such as illegal opcodes. The mscp spec. also 982 * states that parameter error type of invalid commands should 983 * return the normal end message for the command. This does not appear 984 * to be the case. An invalid logical block number returned an endcode 985 * of 0200 instead of the 0241 (read) that was expected. 986 */ 987 988 printf("endcd=%o, stat=%o\n", mp->mscp_opcode, mp->mscp_status); 989 break; 990 case M_OP_READ|M_OP_END: 991 case M_OP_WRITE|M_OP_END: 992 bp = (struct buf *)mp->mscp_cmdref; 993 ubarelse(um->um_ubanum, (int *)&bp->b_ubinfo); 994 /* 995 * Unlink buffer from I/O wait queue. 996 */ 997 bp->av_back->av_forw = bp->av_forw; 998 bp->av_forw->av_back = bp->av_back; 999 #if defined(VAX750) 1000 if (cpu == VAX_750 1001 && udwtab[um->um_ctlr].av_forw == &udwtab[um->um_ctlr]) { 1002 if (um->um_ubinfo == 0) 1003 printf("udintr: um_ubinfo == 0\n"); 1004 else 1005 ubarelse(um->um_ubanum, &um->um_ubinfo); 1006 } 1007 #endif 1008 dp = &udutab[ui->ui_unit]; 1009 dp->b_qsize--; 1010 if (ui->ui_dk >= 0) 1011 if (dp->b_qsize == 0) 1012 dk_busy &= ~(1<<ui->ui_dk); 1013 if (st == M_ST_OFFLN || st == M_ST_AVLBL) { 1014 ui->ui_flags = 0; /* mark unit offline */ 1015 /* 1016 * Link the buffer onto the front of the drive queue 1017 */ 1018 if ((bp->av_forw = dp->b_actf) == 0) 1019 dp->b_actl = bp; 1020 dp->b_actf = bp; 1021 /* 1022 * Link the drive onto the controller queue 1023 */ 1024 if (dp->b_active == 0) { 1025 dp->b_forw = NULL; 1026 if (um->um_tab.b_actf == NULL) 1027 um->um_tab.b_actf = dp; 1028 else 1029 um->um_tab.b_actl->b_forw = dp; 1030 um->um_tab.b_actl = dp; 1031 dp->b_active = 1; 1032 } 1033 #if defined(VAX750) 1034 if (cpu == VAX750 && um->um_ubinfo == 0) 1035 um->um_ubinfo = 1036 uballoc(um->um_ubanum, (caddr_t)0, 0, 1037 UBA_NEEDBDP); 1038 #endif 1039 return; 1040 } 1041 if (st != M_ST_SUCC) { 1042 harderr(bp, "ra"); 1043 #ifdef DEBUG 1044 printd("status %o\n", mp->mscp_status); 1045 #endif 1046 bp->b_flags |= B_ERROR; 1047 } 1048 bp->b_resid = bp->b_bcount - mp->mscp_bytecnt; 1049 iodone(bp); 1050 break; 1051 1052 case M_OP_GTUNT|M_OP_END: 1053 #ifdef DEBUG 1054 printd("GTUNT end packet status = 0x%x media id 0x%x\n" 1055 ,st,mp->mscp_mediaid); 1056 #endif 1057 ra_info[ui->ui_unit].rastatus = st; 1058 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 1059 break; 1060 1061 default: 1062 printf("uda: unknown packet\n"); 1063 uderror(um, (struct mslg *)mp); 1064 } 1065 } 1066 1067 1068 /* 1069 * Process an error log message 1070 * 1071 * For now, just log the error on the console. 1072 * Only minimal decoding is done, only "useful" 1073 * information is printed. Eventually should 1074 * send message to an error logger. 1075 */ 1076 uderror(um, mp) 1077 register struct uba_ctlr *um; 1078 register struct mslg *mp; 1079 { 1080 register i; 1081 1082 1083 if(!(mp->mslg_flags & (M_LF_SUCC | M_LF_CONT))) 1084 printf("uda%d: hard error\n"); 1085 1086 mprintf("uda%d: %s error, ", um->um_ctlr, 1087 mp->mslg_flags & ( M_LF_SUCC | M_LF_CONT ) ? "soft" : "hard"); 1088 switch (mp->mslg_format) { 1089 case M_FM_CNTERR: 1090 mprintf("controller error, event 0%o\n", mp->mslg_event); 1091 break; 1092 1093 case M_FM_BUSADDR: 1094 mprintf("host memory access error, event 0%o, addr 0%o\n", 1095 mp->mslg_event, mp->mslg_busaddr); 1096 break; 1097 1098 case M_FM_DISKTRN: 1099 mprintf("disk transfer error, unit %d, grp 0x%x, hdr 0x%x, event 0%o\n", 1100 mp->mslg_unit, mp->mslg_group, mp->mslg_hdr, 1101 mp->mslg_event); 1102 break; 1103 1104 case M_FM_SDI: 1105 mprintf("SDI error, unit %d, event 0%o, hdr 0x%x\n", 1106 mp->mslg_unit, mp->mslg_event, mp->mslg_hdr); 1107 for(i = 0; i < 12;i++) 1108 mprintf("\t0x%x",mp->mslg_sdistat[i] & 0xff); 1109 mprintf("\n"); 1110 break; 1111 1112 case M_FM_SMLDSK: 1113 mprintf("small disk error, unit %d, event 0%o, cyl %d\n", 1114 mp->mslg_unit, mp->mslg_event, mp->mslg_sdecyl); 1115 break; 1116 1117 default: 1118 mprintf("unknown error, unit %d, format 0%o, event 0%o\n", 1119 mp->mslg_unit, mp->mslg_format, mp->mslg_event); 1120 } 1121 1122 if (udaerror) { 1123 register long *p = (long *)mp; 1124 1125 for (i = 0; i < mp->mslg_header.uda_msglen; i += sizeof(*p)) 1126 printf("%x ", *p++); 1127 printf("\n"); 1128 } 1129 } 1130 1131 1132 /* 1133 * Find an unused command packet 1134 */ 1135 struct mscp * 1136 udgetcp(um) 1137 struct uba_ctlr *um; 1138 { 1139 register struct mscp *mp; 1140 register struct udaca *cp; 1141 register struct uda_softc *sc; 1142 register int i; 1143 int s; 1144 1145 s = spl5(); 1146 cp = &uda[um->um_ctlr].uda_ca; 1147 sc = &uda_softc[um->um_ctlr]; 1148 /* 1149 * If no credits, can't issue any commands 1150 * until some outstanding commands complete. 1151 */ 1152 i = sc->sc_lastcmd; 1153 if(((cp->ca_cmddsc[i]&(UDA_OWN|UDA_INT))==UDA_INT)&& 1154 (sc->sc_credits >= 2)) { 1155 sc->sc_credits--; /* committed to issuing a command */ 1156 cp->ca_cmddsc[i] &= ~UDA_INT; 1157 mp = &uda[um->um_ctlr].uda_cmd[i]; 1158 mp->mscp_unit = mp->mscp_modifier = 0; 1159 mp->mscp_opcode = mp->mscp_flags = 0; 1160 mp->mscp_bytecnt = mp->mscp_buffer = 0; 1161 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 1162 sc->sc_lastcmd = (i + 1) % NCMD; 1163 (void) splx(s); 1164 return(mp); 1165 } 1166 (void) splx(s); 1167 return(NULL); 1168 } 1169 1170 udread(dev, uio) 1171 dev_t dev; 1172 struct uio *uio; 1173 { 1174 register int unit = udunit(dev); 1175 1176 if (unit >= nNRA) 1177 return (ENXIO); 1178 return (physio(udstrategy, &rudbuf[unit], dev, B_READ, minphys, uio)); 1179 } 1180 1181 udwrite(dev, uio) 1182 dev_t dev; 1183 struct uio *uio; 1184 { 1185 register int unit = udunit(dev); 1186 1187 if (unit >= nNRA) 1188 return (ENXIO); 1189 return (physio(udstrategy, &rudbuf[unit], dev, B_WRITE, minphys, uio)); 1190 } 1191 1192 udreset(uban) 1193 int uban; 1194 { 1195 register struct uba_ctlr *um; 1196 register struct uba_device *ui; 1197 register struct buf *bp, *dp; 1198 register int unit; 1199 struct buf *nbp; 1200 int d; 1201 1202 for (d = 0; d < NUDA; d++) { 1203 if ((um = udminfo[d]) == 0 || um->um_ubanum != uban || 1204 um->um_alive == 0) 1205 continue; 1206 printf(" uda%d", d); 1207 um->um_tab.b_active = 0; 1208 um->um_tab.b_actf = um->um_tab.b_actl = 0; 1209 uda_softc[d].sc_state = S_IDLE; 1210 uda_softc[d].sc_mapped = 0; /* Rich */ 1211 for (unit = 0; unit < nNRA; unit++) { 1212 if ((ui = uddinfo[unit]) == 0) 1213 continue; 1214 if (ui->ui_alive == 0 || ui->ui_mi != um) 1215 continue; 1216 udutab[unit].b_active = 0; 1217 udutab[unit].b_qsize = 0; 1218 } 1219 for (bp = udwtab[d].av_forw; bp != &udwtab[d]; bp = nbp) { 1220 nbp = bp->av_forw; 1221 bp->b_ubinfo = 0; 1222 /* 1223 * Link the buffer onto the drive queue 1224 */ 1225 dp = &udutab[udunit(bp->b_dev)]; 1226 if (dp->b_actf == 0) 1227 dp->b_actf = bp; 1228 else 1229 dp->b_actl->av_forw = bp; 1230 dp->b_actl = bp; 1231 bp->av_forw = 0; 1232 /* 1233 * Link the drive onto the controller queue 1234 */ 1235 if (dp->b_active == 0) { 1236 dp->b_forw = NULL; 1237 if (um->um_tab.b_actf == NULL) 1238 um->um_tab.b_actf = dp; 1239 else 1240 um->um_tab.b_actl->b_forw = dp; 1241 um->um_tab.b_actl = dp; 1242 dp->b_active = 1; 1243 } 1244 } 1245 udinit(d); 1246 } 1247 } 1248 1249 #define DBSIZE 32 1250 1251 #define ca_Rspdsc ca_rspdsc[0] 1252 #define ca_Cmddsc ca_rspdsc[1] 1253 #define uda_Rsp uda_rsp[0] 1254 #define uda_Cmd uda_cmd[0] 1255 1256 struct uda udad[NUDA]; 1257 1258 uddump(dev) 1259 dev_t dev; 1260 { 1261 struct udadevice *udaddr; 1262 struct uda *ud_ubaddr; 1263 char *start; 1264 int num, blk, unit; 1265 int maxsz; 1266 int blkoff; 1267 register struct uba_regs *uba; 1268 register struct uba_device *ui; 1269 register struct uda *udp; 1270 register struct pte *io; 1271 register int i; 1272 struct size *rasizes; 1273 unit = udunit(dev); 1274 if (unit >= nNRA) 1275 return (ENXIO); 1276 #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) 1277 ui = phys(struct uba_device *, uddinfo[unit]); 1278 if (ui->ui_alive == 0) 1279 return (ENXIO); 1280 uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 1281 ubainit(uba); 1282 udaddr = (struct udadevice *)ui->ui_physaddr; 1283 DELAY(2000000); 1284 udp = phys(struct uda *, &udad[ui->ui_ctlr]); 1285 1286 num = btoc(sizeof(struct uda)) + 1; 1287 io = &uba->uba_map[NUBMREG-num]; 1288 for(i = 0; i<num; i++) 1289 *(int *)io++ = UBAMR_MRV|(btop(udp)+i); 1290 ud_ubaddr = (struct uda *)(((int)udp & PGOFSET)|((NUBMREG-num)<<9)); 1291 1292 udaddr->udaip = 0; 1293 while ((udaddr->udasa & UDA_STEP1) == 0) 1294 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1295 udaddr->udasa = UDA_ERR; 1296 while ((udaddr->udasa & UDA_STEP2) == 0) 1297 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1298 udaddr->udasa = (short)&ud_ubaddr->uda_ca.ca_ringbase; 1299 while ((udaddr->udasa & UDA_STEP3) == 0) 1300 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1301 udaddr->udasa = (short)(((int)&ud_ubaddr->uda_ca.ca_ringbase) >> 16); 1302 while ((udaddr->udasa & UDA_STEP4) == 0) 1303 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1304 udaddr->udasa = UDA_GO; 1305 udp->uda_ca.ca_Rspdsc = (long)&ud_ubaddr->uda_Rsp.mscp_cmdref; 1306 udp->uda_ca.ca_Cmddsc = (long)&ud_ubaddr->uda_Cmd.mscp_cmdref; 1307 udp->uda_Cmd.mscp_cntflgs = 0; 1308 udp->uda_Cmd.mscp_version = 0; 1309 if (udcmd(M_OP_STCON, udp, udaddr) == 0) { 1310 return(EFAULT); 1311 } 1312 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1313 if (udcmd(M_OP_ONLIN, udp, udaddr) == 0) { 1314 return(EFAULT); 1315 } 1316 1317 num = maxfree; 1318 start = 0; 1319 rasizes = ra_info[ui->ui_unit].ra_sizes; 1320 maxsz = rasizes[minor(dev)&07].nblocks; 1321 blkoff = rasizes[minor(dev)&07].blkoff; 1322 if(maxsz < 0) 1323 maxsz = ra_info[unit].radsize-blkoff; 1324 if (dumplo < 0) 1325 return (EINVAL); 1326 if (dumplo + num >= maxsz) 1327 num = maxsz - dumplo; 1328 blkoff += dumplo; 1329 while (num > 0) { 1330 blk = num > DBSIZE ? DBSIZE : num; 1331 io = uba->uba_map; 1332 for (i = 0; i < blk; i++) 1333 *(int *)io++ = (btop(start)+i) | UBAMR_MRV; 1334 *(int *)io = 0; 1335 udp->uda_Cmd.mscp_lbn = btop(start) + blkoff; 1336 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1337 udp->uda_Cmd.mscp_bytecnt = blk*NBPG; 1338 udp->uda_Cmd.mscp_buffer = 0; 1339 if (udcmd(M_OP_WRITE, udp, udaddr) == 0) { 1340 return(EIO); 1341 } 1342 start += blk*NBPG; 1343 num -= blk; 1344 } 1345 return (0); 1346 } 1347 1348 1349 udcmd(op, udp, udaddr) 1350 int op; 1351 register struct uda *udp; 1352 struct udadevice *udaddr; 1353 { 1354 int i; 1355 1356 #ifdef lint 1357 i = i; 1358 #endif 1359 1360 udp->uda_Cmd.mscp_opcode = op; 1361 udp->uda_Rsp.mscp_header.uda_msglen = mscp_msglen; 1362 udp->uda_Cmd.mscp_header.uda_msglen = mscp_msglen; 1363 udp->uda_ca.ca_Rspdsc |= UDA_OWN|UDA_INT; 1364 udp->uda_ca.ca_Cmddsc |= UDA_OWN|UDA_INT; 1365 if (udaddr->udasa&UDA_ERR) 1366 printf("Udaerror udasa (%x)\n", udaddr->udasa&0xffff); 1367 i = udaddr->udaip; 1368 for (;;) { 1369 if (udp->uda_ca.ca_cmdint) 1370 udp->uda_ca.ca_cmdint = 0; 1371 if (udp->uda_ca.ca_rspint) 1372 break; 1373 } 1374 udp->uda_ca.ca_rspint = 0; 1375 if (udp->uda_Rsp.mscp_opcode != (op|M_OP_END) || 1376 (udp->uda_Rsp.mscp_status&M_ST_MASK) != M_ST_SUCC) { 1377 printf("error: com %d opc 0x%x stat 0x%x\ndump ", 1378 op, 1379 udp->uda_Rsp.mscp_opcode, 1380 udp->uda_Rsp.mscp_status); 1381 return(0); 1382 } 1383 return(1); 1384 } 1385 1386 udsize(dev) 1387 dev_t dev; 1388 { 1389 int unit = udunit(dev); 1390 struct uba_device *ui; 1391 struct size *rasizes; 1392 1393 if (unit >= nNRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0 1394 || ui->ui_flags == 0) 1395 return (-1); 1396 rasizes = ra_info[ui->ui_unit].ra_sizes; 1397 return (rasizes[minor(dev) & 07].nblocks); 1398 } 1399 1400 #endif 1401