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