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