1 /* 2 * @(#)uda.c 6.19 (Berkeley) 02/23/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 udamicro[NUDA]; /* to store microcode level */ 167 int udaburst[NUDA] = { 0 }; /* DMA burst size, 0 is default */ 168 169 170 /* 171 * Controller states 172 */ 173 #define S_IDLE 0 /* hasn't been initialized */ 174 #define S_STEP1 1 /* doing step 1 init */ 175 #define S_STEP2 2 /* doing step 2 init */ 176 #define S_STEP3 3 /* doing step 3 init */ 177 #define S_SCHAR 4 /* doing "set controller characteristics" */ 178 #define S_RUN 5 /* running */ 179 180 181 int udaerror = 0; /* causes hex dump of packets */ 182 int udadebug = 0; 183 int uda_cp_wait = 0; /* Something to wait on for command */ 184 /* packets and or credits. */ 185 int wakeup(); 186 extern int hz; /* Should find the right include */ 187 #ifdef DEBUG 188 #define printd if (udadebug) printf 189 #define printd10 if(udadebug >= 10) printf 190 #endif 191 #define mprintf printf /* temporary JG hack until Rich fixes*/ 192 193 int udprobe(), udslave(), udattach(), udintr(); 194 struct mscp *udgetcp(); 195 196 u_short udstd[] = { 0772150, 0772550, 0777550, 0 }; 197 struct uba_driver udadriver = 198 { udprobe, udslave, udattach, 0, udstd, "ra", uddinfo, "uda", udminfo, 0 }; 199 200 #define b_qsize b_resid /* queue size per drive, in udutab */ 201 #define b_ubinfo b_resid /* Unibus mapping info, per buffer */ 202 203 udprobe(reg, ctlr) 204 caddr_t reg; 205 int ctlr; 206 { 207 register int br, cvec; 208 register struct uda_softc *sc = &uda_softc[ctlr]; 209 struct udadevice *udaddr; 210 211 int cur_time; 212 213 #ifdef lint 214 br = 0; cvec = br; br = cvec; 215 udreset(0); udintr(0); 216 #endif 217 udaddr = (struct udadevice *) reg; 218 219 sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 220 udaddr->udaip = 0; /* start initialization */ 221 222 cur_time = mfpr(TODR); /* Time of day */ 223 while(cur_time + TENSEC > mfpr(TODR)){ /* wait for at most 10 secs */ 224 if((udaddr->udasa & UDA_STEP1) != 0) 225 break; 226 } 227 if(cur_time + TENSEC <= mfpr(TODR)) 228 return(0); /* Not a uda or it won't init as it */ 229 /* should within ten seconds. */ 230 udaddr->udasa=UDA_ERR|(NCMDL2<<11)|(NRSPL2<<8)|UDA_IE|(sc->sc_ivec/4); 231 while((udaddr->udasa&UDA_STEP2)==0) 232 DELAY(1000); /* intr should have */ 233 /* have happened by now */ 234 235 return(sizeof (struct udadevice)); 236 } 237 238 /* ARGSUSED */ 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 udaddr = (struct udadevice *)um->um_addr; 252 if(sc->sc_state != S_RUN){ 253 if(!udinit(ui->ui_ctlr)) 254 return(0); 255 } 256 /* Here we will wait for the controller */ 257 /* to come into the run state or go idle. If we go idle we are in */ 258 /* touble and I don't yet know what to do so I will punt */ 259 while(sc->sc_state != S_RUN && sc->sc_state != S_IDLE); /* spin */ 260 if(sc->sc_state == S_IDLE){ /* The Uda failed to initialize */ 261 printf("UDA failed to init\n"); 262 return(0); 263 } 264 /* The controller is up so let see if the drive is there! */ 265 if(0 == (mp = udgetcp(um))){ /* ditto */ 266 printf("UDA can't get command packet\n"); 267 return(0); 268 } 269 mp->mscp_opcode = M_OP_GTUNT; /* This should give us the drive type*/ 270 mp->mscp_unit = ui->ui_slave; 271 mp->mscp_cmdref = (long) ui->ui_slave; 272 #ifdef DEBUG 273 printd("uda%d Get unit status slave %d\n",ui->ui_ctlr,ui->ui_slave); 274 #endif 275 ra_info[ui->ui_unit].rastatus = 0; /* set to zero */ 276 udip[ui->ui_ctlr][ui->ui_slave] = ui; 277 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT;/* maybe we should poll*/ 278 i = udaddr->udaip; 279 #ifdef lint 280 i = i; 281 #endif 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 if (ui->ui_dk >= 0) 299 dk_mspw[ui->ui_dk] = 1.0 / (60 * 31 * 256); /* approx */ 300 ui->ui_flags = 0; 301 udip[ui->ui_ctlr][ui->ui_slave] = ui; 302 /* check to see if the drive is a available if it is bring it online */ 303 /* if not then just return. open will try an online later */ 304 if(ra_info[ui->ui_unit].rastatus != M_ST_AVLBL) 305 return; /* status was set by a GTUNT */ 306 if(0 == (mp = udgetcp(um))){ /* ditto */ 307 printf("UDA can't get command packet\n"); 308 return; 309 } 310 mp->mscp_opcode = M_OP_ONLIN; 311 mp->mscp_unit = ui->ui_slave; 312 mp->mscp_cmdref = (long) ui->ui_slave; 313 #ifdef DEBUG 314 printd("uda%d ONLIN slave %d\n",ui->ui_ctlr,ui->ui_slave); 315 #endif 316 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT; 317 i = udaddr->udaip; 318 #ifdef lint 319 i = i; 320 #endif 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 /* ARGSUSED */ 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 unit = udunit(dev); 343 if (unit >= NRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0) 344 return (ENXIO); 345 sc = &uda_softc[ui->ui_ctlr]; 346 s = spl5(); 347 if (sc->sc_state != S_RUN) { 348 if (sc->sc_state == S_IDLE) 349 if(!udinit(ui->ui_ctlr)){ 350 printf("uda: Controller failed to init\n"); 351 (void) splx(s); 352 return(ENXIO); 353 } 354 /* wait for initialization to complete */ 355 timeout(wakeup,(caddr_t)ui->ui_mi,11*hz); /* to be sure*/ 356 sleep((caddr_t)ui->ui_mi, 0); 357 if (sc->sc_state != S_RUN) 358 { 359 (void) splx(s); /* added by Rich */ 360 return (EIO); 361 } 362 } 363 /* check to see if the device is really there. */ 364 /* this code was taken from Fred Canters 11 driver */ 365 um = ui->ui_mi; 366 udaddr = (struct udadevice *) um->um_addr; 367 (void) splx(s); 368 if(ui->ui_flags == 0){ 369 s = spl5(); 370 while(0 ==(mp = udgetcp(um))){ 371 uda_cp_wait++; 372 sleep((caddr_t)&uda_cp_wait,PSWP+1); 373 uda_cp_wait--; 374 } 375 mp->mscp_opcode = M_OP_ONLIN; 376 mp->mscp_unit = ui->ui_slave; 377 mp->mscp_cmdref = (long) & ra_info[ui->ui_unit].ratype; 378 /* need to sleep on something */ 379 #ifdef DEBUG 380 printd("uda: bring unit %d online\n",ui->ui_unit); 381 #endif 382 *((long *) mp->mscp_dscptr ) |= UDA_OWN | UDA_INT ; 383 i = udaddr->udaip; 384 #ifdef lint 385 i = i; 386 #endif 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 >= NRA) { 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 (void)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 i = UDA_GO | (udaerror? 2 : 0); 734 if (udaburst[d]) 735 i |= (udaburst[d] - 1) << 2; 736 udaddr->udasa = i; 737 udaddr->udasa = UDA_GO; 738 sc->sc_state = S_SCHAR; 739 740 /* 741 * Initialize the data structures. 742 */ 743 uud = sc->sc_uda; 744 for (i = 0; i < NRSP; i++) { 745 ud->uda_ca.ca_rspdsc[i] = UDA_OWN|UDA_INT| 746 (long)&uud->uda_rsp[i].mscp_cmdref; 747 ud->uda_rsp[i].mscp_dscptr = &ud->uda_ca.ca_rspdsc[i]; 748 ud->uda_rsp[i].mscp_header.uda_msglen = mscp_msglen; 749 } 750 for (i = 0; i < NCMD; i++) { 751 ud->uda_ca.ca_cmddsc[i] = UDA_INT| 752 (long)&uud->uda_cmd[i].mscp_cmdref; 753 ud->uda_cmd[i].mscp_dscptr = &ud->uda_ca.ca_cmddsc[i]; 754 ud->uda_cmd[i].mscp_header.uda_msglen = mscp_msglen; 755 } 756 bp = &udwtab[d]; 757 bp->av_forw = bp->av_back = bp; 758 sc->sc_lastcmd = 1; 759 sc->sc_lastrsp = 0; 760 mp = &uda[um->um_ctlr].uda_cmd[0]; 761 mp->mscp_unit = mp->mscp_modifier = 0; 762 mp->mscp_flags = 0; 763 mp->mscp_bytecnt = mp->mscp_buffer = 0; 764 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 765 mp->mscp_opcode = M_OP_STCON; 766 mp->mscp_cntflgs = M_CF_ATTN|M_CF_MISC|M_CF_THIS; 767 *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; 768 i = udaddr->udaip; /* initiate polling */ 769 return; 770 771 case S_SCHAR: 772 case S_RUN: 773 break; 774 775 default: 776 printf("uda%d: interrupt in unknown state %d ignored\n", 777 d, sc->sc_state); 778 return; 779 } 780 781 if (udaddr->udasa&UDA_ERR) { 782 printf("uda(%d): fatal error (%o)\n", d, udaddr->udasa&0xffff); 783 udaddr->udaip = 0; 784 wakeup((caddr_t)um); 785 } 786 787 /* 788 * Check for a buffer purge request. 789 */ 790 if (ud->uda_ca.ca_bdp) { 791 #ifdef DEBUG 792 printd("uda: purge bdp %d\n", ud->uda_ca.ca_bdp); 793 #endif 794 UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 795 ud->uda_ca.ca_bdp = 0; 796 udaddr->udasa = 0; /* signal purge complete */ 797 } 798 799 /* 800 * Check for response ring transition. 801 */ 802 if (ud->uda_ca.ca_rspint) { 803 ud->uda_ca.ca_rspint = 0; 804 for (i = sc->sc_lastrsp;; i++) { 805 i %= NRSP; 806 if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) 807 break; 808 udrsp(um, ud, sc, i); 809 ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; 810 } 811 sc->sc_lastrsp = i; 812 } 813 814 /* 815 * Check for command ring transition. 816 */ 817 if (ud->uda_ca.ca_cmdint) { 818 #ifdef DEBUG 819 printd("uda: command ring transition\n"); 820 #endif 821 ud->uda_ca.ca_cmdint = 0; 822 } 823 if(uda_cp_wait) 824 wakeup((caddr_t)&uda_cp_wait); 825 (void) udstart(um); 826 } 827 828 /* 829 * Process a response packet 830 */ 831 udrsp(um, ud, sc, i) 832 register struct uba_ctlr *um; 833 register struct uda *ud; 834 register struct uda_softc *sc; 835 int i; 836 { 837 register struct mscp *mp; 838 struct uba_device *ui; 839 struct buf *dp, *bp,nullbp; 840 int st; 841 842 mp = &ud->uda_rsp[i]; 843 mp->mscp_header.uda_msglen = mscp_msglen; 844 sc->sc_credits += mp->mscp_header.uda_credits & 0xf; /* just 4 bits?*/ 845 if ((mp->mscp_header.uda_credits & 0xf0) > 0x10) /* Check */ 846 return; 847 #ifdef DEBUG 848 printd10("udarsp, opcode 0x%x status 0x%x\n",mp->mscp_opcode,mp->mscp_status); 849 #endif 850 /* 851 * If it's an error log message (datagram), 852 * pass it on for more extensive processing. 853 */ 854 if ((mp->mscp_header.uda_credits & 0xf0) == 0x10) { /* check */ 855 uderror(um, (struct mslg *)mp); 856 return; 857 } 858 st = mp->mscp_status&M_ST_MASK; 859 /* The controller interrupts as drive 0 */ 860 /* this means that you must check for controller interrupts */ 861 /* before you check to see if there is a drive 0 */ 862 if((M_OP_STCON|M_OP_END) == mp->mscp_opcode){ 863 if (st == M_ST_SUCC) 864 sc->sc_state = S_RUN; 865 else 866 sc->sc_state = S_IDLE; 867 um->um_tab.b_active = 0; 868 wakeup((caddr_t)um); 869 return; 870 } 871 if (mp->mscp_unit >= 8) 872 return; 873 if ((ui = udip[um->um_ctlr][mp->mscp_unit]) == 0) 874 return; 875 switch (mp->mscp_opcode) { 876 877 case M_OP_ONLIN|M_OP_END: 878 ra_info[ui->ui_unit].rastatus = st; 879 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 880 dp = &udutab[ui->ui_unit]; 881 if (st == M_ST_SUCC) { 882 /* 883 * Link the drive onto the controller queue 884 */ 885 dp->b_forw = NULL; 886 if (um->um_tab.b_actf == NULL) 887 um->um_tab.b_actf = dp; 888 else 889 um->um_tab.b_actl->b_forw = dp; 890 um->um_tab.b_actl = dp; 891 ui->ui_flags = 1; /* mark it online */ 892 ra_info[ui->ui_unit].radsize=(daddr_t)mp->mscp_untsize; 893 #ifdef DEBUG 894 printd("uda: unit %d online\n", mp->mscp_unit); 895 #endif 896 #define F_to_C(x,i) ( ((x)->mscp_mediaid) >> (i*5+7) & 0x1f ? ( ( (((x)->mscp_mediaid) >>( i*5 + 7)) & 0x1f) + 'A' - 1): ' ') 897 /* this mess decodes the Media type identifier */ 898 #ifdef DEBUG 899 printd("uda: unit %d online %x %c%c %c%c%c%d\n" 900 ,mp->mscp_unit, mp->mscp_mediaid 901 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 902 ,F_to_C(mp,1),F_to_C(mp,0) 903 ,mp->mscp_mediaid & 0x7f); 904 #endif 905 switch((int)(mp->mscp_mediaid & 0x7f)){ 906 case 25: 907 ra_info[ui->ui_unit].ra_sizes = ra25_sizes; 908 break; 909 case 60: 910 ra_info[ui->ui_unit].ra_sizes = ra60_sizes; 911 break; 912 case 80: 913 ra_info[ui->ui_unit].ra_sizes = ra80_sizes; 914 break; 915 case 81: 916 ra_info[ui->ui_unit].ra_sizes = ra81_sizes; 917 break; 918 default: 919 ui->ui_flags = 0; /* mark it offline */ 920 ra_info[ui->ui_unit].ratype = 0; 921 printf("Don't have a parition table for "); 922 printf("a %c%c %c%c%c%d\n" 923 ,F_to_C(mp,4),F_to_C(mp,3),F_to_C(mp,2) 924 ,F_to_C(mp,1),F_to_C(mp,0) 925 ,mp->mscp_mediaid & 0x7f); 926 while (bp = dp->b_actf) { 927 dp->b_actf = bp->av_forw; 928 bp->b_flags |= B_ERROR; 929 iodone(bp); 930 } 931 } 932 dp->b_active = 1; 933 } else { 934 if(dp->b_actf){ 935 harderr(dp->b_actf,"ra"); 936 } else { 937 nullbp.b_blkno = 0; 938 nullbp.b_dev = makedev(UDADEVNUM,ui->ui_unit); 939 harderr(&nullbp, "ra"); 940 } 941 printf("OFFLINE\n"); 942 while (bp = dp->b_actf) { 943 dp->b_actf = bp->av_forw; 944 bp->b_flags |= B_ERROR; 945 iodone(bp); 946 } 947 } 948 if(mp->mscp_cmdref!=NULL){/* Seems to get lost sometimes */ 949 wakeup((caddr_t)mp->mscp_cmdref); 950 } 951 break; 952 953 /* 954 * The AVAILABLE ATTENTION messages occurs when the 955 * unit becomes available after spinup, 956 * marking the unit offline will force an online command 957 * prior to using the unit. 958 */ 959 case M_OP_AVATN: 960 #ifdef DEBUG 961 printd("uda: unit %d attention\n", mp->mscp_unit); 962 #endif 963 ui->ui_flags = 0; /* it went offline and we didn't notice */ 964 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 965 break; 966 967 case M_OP_END: 968 /* 969 * An endcode without an opcode (0200) is an invalid command. 970 * The mscp specification states that this would be a protocol 971 * type error, such as illegal opcodes. The mscp spec. also 972 * states that parameter error type of invalid commands should 973 * return the normal end message for the command. This does not appear 974 * to be the case. An invalid logical block number returned an endcode 975 * of 0200 instead of the 0241 (read) that was expected. 976 */ 977 978 printf("endcd=%o, stat=%o\n", mp->mscp_opcode, mp->mscp_status); 979 break; 980 case M_OP_READ|M_OP_END: 981 case M_OP_WRITE|M_OP_END: 982 bp = (struct buf *)mp->mscp_cmdref; 983 ubarelse(um->um_ubanum, (int *)&bp->b_ubinfo); 984 /* 985 * Unlink buffer from I/O wait queue. 986 */ 987 bp->av_back->av_forw = bp->av_forw; 988 bp->av_forw->av_back = bp->av_back; 989 #if defined(VAX750) 990 if (cpu == VAX_750 && um->um_tab.b_active == 0 991 && udwtab[um->um_ctlr].av_forw == &udwtab[um->um_ctlr]) { 992 if (um->um_ubinfo == 0) 993 printf("udintr: um_ubinfo == 0\n"); 994 else 995 ubarelse(um->um_ubanum, &um->um_ubinfo); 996 } 997 #endif 998 dp = &udutab[ui->ui_unit]; 999 dp->b_qsize--; 1000 if (ui->ui_dk >= 0) 1001 if (dp->b_qsize == 0) 1002 dk_busy &= ~(1<<ui->ui_dk); 1003 if (st == M_ST_OFFLN || st == M_ST_AVLBL) { 1004 ui->ui_flags = 0; /* mark unit offline */ 1005 /* 1006 * Link the buffer onto the front of the drive queue 1007 */ 1008 if ((bp->av_forw = dp->b_actf) == 0) 1009 dp->b_actl = bp; 1010 dp->b_actf = bp; 1011 /* 1012 * Link the drive onto the controller queue 1013 */ 1014 if (dp->b_active == 0) { 1015 dp->b_forw = NULL; 1016 if (um->um_tab.b_actf == NULL) 1017 um->um_tab.b_actf = dp; 1018 else 1019 um->um_tab.b_actl->b_forw = dp; 1020 um->um_tab.b_actl = dp; 1021 dp->b_active = 1; 1022 } 1023 #if defined(VAX750) 1024 if (cpu == VAX750 && um->um_ubinfo == 0) 1025 um->um_ubinfo = 1026 uballoc(um->um_ubanum, (caddr_t)0, 0, 1027 UBA_NEEDBDP); 1028 #endif 1029 return; 1030 } 1031 if (st != M_ST_SUCC) { 1032 harderr(bp, "ra"); 1033 #ifdef DEBUG 1034 printd("status %o\n", mp->mscp_status); 1035 #endif 1036 bp->b_flags |= B_ERROR; 1037 } 1038 bp->b_resid = bp->b_bcount - mp->mscp_bytecnt; 1039 iodone(bp); 1040 break; 1041 1042 case M_OP_GTUNT|M_OP_END: 1043 #ifdef DEBUG 1044 printd("GTUNT end packet status = 0x%x media id 0x%x\n" 1045 ,st,mp->mscp_mediaid); 1046 #endif 1047 ra_info[ui->ui_unit].rastatus = st; 1048 ra_info[ui->ui_unit].ratype = mp->mscp_mediaid; 1049 break; 1050 1051 default: 1052 printf("uda: unknown packet\n"); 1053 uderror(um, (struct mslg *)mp); 1054 } 1055 } 1056 1057 1058 /* 1059 * Process an error log message 1060 * 1061 * For now, just log the error on the console. 1062 * Only minimal decoding is done, only "useful" 1063 * information is printed. Eventually should 1064 * send message to an error logger. 1065 */ 1066 uderror(um, mp) 1067 register struct uba_ctlr *um; 1068 register struct mslg *mp; 1069 { 1070 register i; 1071 1072 1073 if(!(mp->mslg_flags & (M_LF_SUCC | M_LF_CONT))) 1074 printf("uda%d: hard error\n"); 1075 1076 mprintf("uda%d: %s error, ", um->um_ctlr, 1077 mp->mslg_flags & ( M_LF_SUCC | M_LF_CONT ) ? "soft" : "hard"); 1078 switch (mp->mslg_format) { 1079 case M_FM_CNTERR: 1080 mprintf("controller error, event 0%o\n", mp->mslg_event); 1081 break; 1082 1083 case M_FM_BUSADDR: 1084 mprintf("host memory access error, event 0%o, addr 0%o\n", 1085 mp->mslg_event, mp->mslg_busaddr); 1086 break; 1087 1088 case M_FM_DISKTRN: 1089 mprintf("disk transfer error, unit %d, grp 0x%x, hdr 0x%x, event 0%o\n", 1090 mp->mslg_unit, mp->mslg_group, mp->mslg_hdr, 1091 mp->mslg_event); 1092 break; 1093 1094 case M_FM_SDI: 1095 mprintf("SDI error, unit %d, event 0%o, hdr 0x%x\n", 1096 mp->mslg_unit, mp->mslg_event, mp->mslg_hdr); 1097 for(i = 0; i < 12;i++) 1098 mprintf("\t0x%x",mp->mslg_sdistat[i] & 0xff); 1099 mprintf("\n"); 1100 break; 1101 1102 case M_FM_SMLDSK: 1103 mprintf("small disk error, unit %d, event 0%o, cyl %d\n", 1104 mp->mslg_unit, mp->mslg_event, mp->mslg_sdecyl); 1105 break; 1106 1107 default: 1108 mprintf("unknown error, unit %d, format 0%o, event 0%o\n", 1109 mp->mslg_unit, mp->mslg_format, mp->mslg_event); 1110 } 1111 1112 if (udaerror) { 1113 register long *p = (long *)mp; 1114 1115 for (i = 0; i < mp->mslg_header.uda_msglen; i += sizeof(*p)) 1116 printf("%x ", *p++); 1117 printf("\n"); 1118 } 1119 } 1120 1121 1122 /* 1123 * Find an unused command packet 1124 */ 1125 struct mscp * 1126 udgetcp(um) 1127 struct uba_ctlr *um; 1128 { 1129 register struct mscp *mp; 1130 register struct udaca *cp; 1131 register struct uda_softc *sc; 1132 register int i; 1133 int s; 1134 1135 s = spl5(); 1136 cp = &uda[um->um_ctlr].uda_ca; 1137 sc = &uda_softc[um->um_ctlr]; 1138 /* 1139 * If no credits, can't issue any commands 1140 * until some outstanding commands complete. 1141 */ 1142 i = sc->sc_lastcmd; 1143 if(((cp->ca_cmddsc[i]&(UDA_OWN|UDA_INT))==UDA_INT)&& 1144 (sc->sc_credits >= 2)) { 1145 sc->sc_credits--; /* committed to issuing a command */ 1146 cp->ca_cmddsc[i] &= ~UDA_INT; 1147 mp = &uda[um->um_ctlr].uda_cmd[i]; 1148 mp->mscp_unit = mp->mscp_modifier = 0; 1149 mp->mscp_opcode = mp->mscp_flags = 0; 1150 mp->mscp_bytecnt = mp->mscp_buffer = 0; 1151 mp->mscp_errlgfl = mp->mscp_copyspd = 0; 1152 sc->sc_lastcmd = (i + 1) % NCMD; 1153 (void) splx(s); 1154 return(mp); 1155 } 1156 (void) splx(s); 1157 return(NULL); 1158 } 1159 1160 udread(dev, uio) 1161 dev_t dev; 1162 struct uio *uio; 1163 { 1164 register int unit = udunit(dev); 1165 1166 if (unit >= NRA) 1167 return (ENXIO); 1168 return (physio(udstrategy, &rudbuf[unit], dev, B_READ, minphys, uio)); 1169 } 1170 1171 udwrite(dev, uio) 1172 dev_t dev; 1173 struct uio *uio; 1174 { 1175 register int unit = udunit(dev); 1176 1177 if (unit >= NRA) 1178 return (ENXIO); 1179 return (physio(udstrategy, &rudbuf[unit], dev, B_WRITE, minphys, uio)); 1180 } 1181 1182 udreset(uban) 1183 int uban; 1184 { 1185 register struct uba_ctlr *um; 1186 register struct uba_device *ui; 1187 register struct buf *bp, *dp; 1188 register int unit; 1189 struct buf *nbp; 1190 int d; 1191 1192 for (d = 0; d < NUDA; d++) { 1193 if ((um = udminfo[d]) == 0 || um->um_ubanum != uban || 1194 um->um_alive == 0) 1195 continue; 1196 printf(" uda%d", d); 1197 um->um_tab.b_active = 0; 1198 um->um_tab.b_actf = um->um_tab.b_actl = 0; 1199 uda_softc[d].sc_state = S_IDLE; 1200 uda_softc[d].sc_mapped = 0; /* Rich */ 1201 for (unit = 0; unit < NRA; unit++) { 1202 if ((ui = uddinfo[unit]) == 0) 1203 continue; 1204 if (ui->ui_alive == 0 || ui->ui_mi != um) 1205 continue; 1206 udutab[unit].b_active = 0; 1207 udutab[unit].b_qsize = 0; 1208 } 1209 for (bp = udwtab[d].av_forw; bp != &udwtab[d]; bp = nbp) { 1210 nbp = bp->av_forw; 1211 bp->b_ubinfo = 0; 1212 /* 1213 * Link the buffer onto the drive queue 1214 */ 1215 dp = &udutab[udunit(bp->b_dev)]; 1216 if (dp->b_actf == 0) 1217 dp->b_actf = bp; 1218 else 1219 dp->b_actl->av_forw = bp; 1220 dp->b_actl = bp; 1221 bp->av_forw = 0; 1222 /* 1223 * Link the drive onto the controller queue 1224 */ 1225 if (dp->b_active == 0) { 1226 dp->b_forw = NULL; 1227 if (um->um_tab.b_actf == NULL) 1228 um->um_tab.b_actf = dp; 1229 else 1230 um->um_tab.b_actl->b_forw = dp; 1231 um->um_tab.b_actl = dp; 1232 dp->b_active = 1; 1233 } 1234 } 1235 (void)udinit(d); 1236 } 1237 } 1238 1239 #define DBSIZE 32 1240 1241 #define ca_Rspdsc ca_rspdsc[0] 1242 #define ca_Cmddsc ca_rspdsc[1] 1243 #define uda_Rsp uda_rsp[0] 1244 #define uda_Cmd uda_cmd[0] 1245 1246 struct uda udad[NUDA]; 1247 1248 uddump(dev) 1249 dev_t dev; 1250 { 1251 struct udadevice *udaddr; 1252 struct uda *ud_ubaddr; 1253 char *start; 1254 int num, blk, unit; 1255 int maxsz; 1256 int blkoff; 1257 register struct uba_regs *uba; 1258 register struct uba_device *ui; 1259 register struct uda *udp; 1260 register struct pte *io; 1261 register int i; 1262 struct size *rasizes; 1263 unit = udunit(dev); 1264 if (unit >= NRA) 1265 return (ENXIO); 1266 #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) 1267 ui = phys(struct uba_device *, uddinfo[unit]); 1268 if (ui->ui_alive == 0) 1269 return (ENXIO); 1270 uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 1271 ubainit(uba); 1272 udaddr = (struct udadevice *)ui->ui_physaddr; 1273 DELAY(2000000); 1274 udp = phys(struct uda *, &udad[ui->ui_ctlr]); 1275 1276 num = btoc(sizeof(struct uda)) + 1; 1277 io = &uba->uba_map[NUBMREG-num]; 1278 for(i = 0; i<num; i++) 1279 *(int *)io++ = UBAMR_MRV|(btop(udp)+i); 1280 ud_ubaddr = (struct uda *)(((int)udp & PGOFSET)|((NUBMREG-num)<<9)); 1281 1282 udaddr->udaip = 0; 1283 while ((udaddr->udasa & UDA_STEP1) == 0) 1284 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1285 udaddr->udasa = UDA_ERR; 1286 while ((udaddr->udasa & UDA_STEP2) == 0) 1287 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1288 udaddr->udasa = (short)&ud_ubaddr->uda_ca.ca_ringbase; 1289 while ((udaddr->udasa & UDA_STEP3) == 0) 1290 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1291 udaddr->udasa = (short)(((int)&ud_ubaddr->uda_ca.ca_ringbase) >> 16); 1292 while ((udaddr->udasa & UDA_STEP4) == 0) 1293 if(udaddr->udasa & UDA_ERR) return(EFAULT); 1294 udaddr->udasa = UDA_GO; 1295 udp->uda_ca.ca_Rspdsc = (long)&ud_ubaddr->uda_Rsp.mscp_cmdref; 1296 udp->uda_ca.ca_Cmddsc = (long)&ud_ubaddr->uda_Cmd.mscp_cmdref; 1297 udp->uda_Cmd.mscp_cntflgs = 0; 1298 udp->uda_Cmd.mscp_version = 0; 1299 if (udcmd(M_OP_STCON, udp, udaddr) == 0) { 1300 return(EFAULT); 1301 } 1302 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1303 if (udcmd(M_OP_ONLIN, udp, udaddr) == 0) { 1304 return(EFAULT); 1305 } 1306 1307 num = maxfree; 1308 start = 0; 1309 rasizes = ra_info[ui->ui_unit].ra_sizes; 1310 maxsz = rasizes[minor(dev)&07].nblocks; 1311 blkoff = rasizes[minor(dev)&07].blkoff; 1312 if(maxsz < 0) 1313 maxsz = ra_info[unit].radsize-blkoff; 1314 if (dumplo < 0) 1315 return (EINVAL); 1316 if (dumplo + num >= maxsz) 1317 num = maxsz - dumplo; 1318 blkoff += dumplo; 1319 while (num > 0) { 1320 blk = num > DBSIZE ? DBSIZE : num; 1321 io = uba->uba_map; 1322 for (i = 0; i < blk; i++) 1323 *(int *)io++ = (btop(start)+i) | UBAMR_MRV; 1324 *(int *)io = 0; 1325 udp->uda_Cmd.mscp_lbn = btop(start) + blkoff; 1326 udp->uda_Cmd.mscp_unit = ui->ui_slave; 1327 udp->uda_Cmd.mscp_bytecnt = blk*NBPG; 1328 udp->uda_Cmd.mscp_buffer = 0; 1329 if (udcmd(M_OP_WRITE, udp, udaddr) == 0) { 1330 return(EIO); 1331 } 1332 start += blk*NBPG; 1333 num -= blk; 1334 } 1335 return (0); 1336 } 1337 1338 1339 udcmd(op, udp, udaddr) 1340 int op; 1341 register struct uda *udp; 1342 struct udadevice *udaddr; 1343 { 1344 int i; 1345 1346 udp->uda_Cmd.mscp_opcode = op; 1347 udp->uda_Rsp.mscp_header.uda_msglen = mscp_msglen; 1348 udp->uda_Cmd.mscp_header.uda_msglen = mscp_msglen; 1349 udp->uda_ca.ca_Rspdsc |= UDA_OWN|UDA_INT; 1350 udp->uda_ca.ca_Cmddsc |= UDA_OWN|UDA_INT; 1351 if (udaddr->udasa&UDA_ERR) 1352 printf("Udaerror udasa (%x)\n", udaddr->udasa&0xffff); 1353 i = udaddr->udaip; 1354 #ifdef lint 1355 i = i; 1356 #endif 1357 for (;;) { 1358 if (udp->uda_ca.ca_cmdint) 1359 udp->uda_ca.ca_cmdint = 0; 1360 if (udp->uda_ca.ca_rspint) 1361 break; 1362 } 1363 udp->uda_ca.ca_rspint = 0; 1364 if (udp->uda_Rsp.mscp_opcode != (op|M_OP_END) || 1365 (udp->uda_Rsp.mscp_status&M_ST_MASK) != M_ST_SUCC) { 1366 printf("error: com %d opc 0x%x stat 0x%x\ndump ", 1367 op, 1368 udp->uda_Rsp.mscp_opcode, 1369 udp->uda_Rsp.mscp_status); 1370 return(0); 1371 } 1372 return(1); 1373 } 1374 1375 udsize(dev) 1376 dev_t dev; 1377 { 1378 int unit = udunit(dev); 1379 struct uba_device *ui; 1380 struct size *rasizes; 1381 1382 if (unit >= NRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0 1383 || ui->ui_flags == 0) 1384 return (-1); 1385 rasizes = ra_info[ui->ui_unit].ra_sizes; 1386 return (rasizes[minor(dev) & 07].nblocks); 1387 } 1388 1389 #endif 1390