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