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