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