Commit | Line | Data |
---|---|---|
155d9ff0 | 1 | /* uda.c 4.3 82/03/14 */ |
db738443 BJ |
2 | |
3 | #include "ra.h" | |
4 | #if NUDA > 0 | |
5 | /* | |
6 | * UDA50/RAxx disk device driver | |
7 | * | |
8 | * Restrictions: | |
9 | * Unit numbers must be less than 8. | |
10 | * | |
11 | * TO DO: | |
12 | * write dump code | |
13 | * test on 750 | |
14 | */ | |
15 | ||
16 | #include "../h/param.h" | |
17 | #include "../h/systm.h" | |
18 | #include "../h/buf.h" | |
19 | #include "../h/conf.h" | |
20 | #include "../h/dir.h" | |
21 | #include "../h/user.h" | |
22 | #include "../h/pte.h" | |
23 | #include "../h/map.h" | |
24 | #include "../h/vm.h" | |
25 | #include "../h/ubareg.h" | |
26 | #include "../h/ubavar.h" | |
27 | #include "../h/dk.h" | |
28 | #include "../h/cpu.h" | |
29 | #include "../h/cmap.h" | |
30 | ||
31 | int udadebug; | |
32 | #define printd if(udadebug&1)printf | |
33 | ||
34 | /* | |
35 | * Parameters for the communications area | |
36 | */ | |
37 | ||
38 | #define NRSPL2 3 | |
39 | #define NCMDL2 3 | |
40 | #define NRSP (1<<NRSPL2) | |
41 | #define NCMD (1<<NCMDL2) | |
42 | ||
43 | #include "../h/udareg.h" | |
44 | #include "../h/mscp.h" | |
45 | ||
46 | struct uda_softc { | |
47 | short sc_state; /* state of controller */ | |
48 | short sc_mapped; /* Unibus map allocated for uda struct? */ | |
49 | int sc_ubainfo; /* Unibus mapping info */ | |
50 | struct uda *sc_uda; /* Unibus address of uda struct */ | |
51 | int sc_ivec; /* interrupt vector address */ | |
52 | short sc_credits; /* transfer credits */ | |
53 | short sc_lastcmd; /* pointer into command ring */ | |
54 | short sc_lastrsp; /* pointer into response ring */ | |
55 | } uda_softc[NUDA]; | |
56 | ||
57 | /* | |
58 | * Controller states | |
59 | */ | |
60 | #define S_IDLE 0 /* hasn't been initialized */ | |
61 | #define S_STEP1 1 /* doing step 1 init */ | |
62 | #define S_STEP2 2 /* doing step 2 init */ | |
63 | #define S_STEP3 3 /* doing step 3 init */ | |
64 | #define S_SCHAR 4 /* doing "set controller characteristics" */ | |
65 | #define S_RUN 5 /* running */ | |
66 | ||
67 | struct uda { | |
68 | struct udaca uda_ca; /* communications area */ | |
69 | struct mscp uda_rsp[NRSP]; /* response packets */ | |
70 | struct mscp uda_cmd[NCMD]; /* command packets */ | |
71 | } uda[NUDA]; | |
72 | ||
73 | /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ | |
74 | struct size { | |
75 | daddr_t nblocks; | |
76 | daddr_t blkoff; | |
77 | } ra_sizes[8] ={ | |
78 | 15884, 0, /* A=blk 0 thru 15883 */ | |
79 | 33440, 15884, /* B=blk 15884 thru 49323 */ | |
80 | -1, 0, /* C=blk 0 thru end */ | |
81 | 0, 0, /* D reserved for RA81 */ | |
82 | 0, 0, /* E reserved for RA81 */ | |
83 | 0, 0, /* F reserved for RA81 */ | |
84 | 82080, 49324, /* G=blk 49324 thru 131403 */ | |
85 | -1, 131404, /* H=blk 131404 thru end */ | |
86 | }; | |
87 | /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ | |
88 | ||
89 | daddr_t radsize[NRA]; /* disk size, from ONLINE end packet */ | |
90 | ||
91 | int udprobe(), udslave(), udattach(), udintr(); | |
92 | struct mscp *udgetcp(); | |
93 | struct uba_ctlr *udminfo[NUDA]; | |
94 | struct uba_device *uddinfo[NRA]; | |
95 | struct uba_device *udip[NUDA][8]; /* 8 == max number of drives */ | |
96 | ||
97 | u_short udstd[] = { 0777550, 0 }; | |
98 | struct uba_driver udadriver = | |
99 | { udprobe, udslave, udattach, 0, udstd, "ra", uddinfo, "uda", udminfo, 0 }; | |
100 | struct buf rudbuf[NRA]; | |
101 | struct buf udutab[NRA]; | |
102 | struct buf udwtab[NUDA]; /* I/O wait queue, per controller */ | |
103 | ||
104 | #define b_qsize b_resid /* queue size per drive, in udutab */ | |
105 | #define b_ubinfo b_resid /* Unibus mapping info, per buffer */ | |
106 | ||
107 | udprobe(reg, ctlr) | |
108 | caddr_t reg; | |
109 | int ctlr; | |
110 | { | |
111 | register int br, cvec; | |
112 | register struct uda_softc *sc = &uda_softc[ctlr]; | |
113 | ||
114 | #ifdef lint | |
155d9ff0 SL |
115 | br = 0; cvec = br; br = cvec; reg = reg; |
116 | udread(0); udwrite(0); udreset(0); udintr(0); | |
db738443 BJ |
117 | #endif |
118 | /* SHOULD CHECK THAT IT REALLY IS A UDA */ | |
119 | br = 0x15; | |
120 | cvec = sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); | |
121 | return(1); | |
122 | } | |
123 | ||
124 | udslave(ui, reg) | |
125 | struct uba_device *ui; | |
126 | caddr_t reg; | |
127 | { | |
128 | /* | |
129 | * TOO HARD TO FIND OUT IF DISK IS THERE UNTIL | |
130 | * INITIALIZED. WE'LL FIND OUT WHEN WE FIRST | |
131 | * TRY TO ACCESS IT. | |
132 | */ | |
155d9ff0 SL |
133 | #ifdef lint |
134 | ui = ui; reg = reg; | |
135 | #endif | |
db738443 BJ |
136 | return(1); |
137 | } | |
138 | ||
139 | udattach(ui) | |
140 | register struct uba_device *ui; | |
141 | { | |
142 | ||
143 | if (ui->ui_dk > 0) | |
144 | dk_mspw[ui->ui_dk] = 1.0 / (60 * 31 * 256); /* approx */ | |
145 | ui->ui_flags = 0; | |
146 | udip[ui->ui_ctlr][ui->ui_slave] = ui; | |
147 | radsize[ui->ui_unit] = (daddr_t)0xffffff; /* max possible size */ | |
148 | } | |
149 | ||
150 | /* | |
151 | * Open a UDA. Initialize the device and | |
152 | * set the unit online. | |
153 | */ | |
154 | udopen(dev, flag) | |
155 | dev_t dev; | |
156 | int flag; | |
157 | { | |
158 | register int unit; | |
159 | register struct uba_device *ui; | |
160 | register struct uda_softc *sc; | |
530d0032 | 161 | int s; |
db738443 | 162 | |
155d9ff0 SL |
163 | #ifdef lint |
164 | flag = flag; | |
165 | #endif | |
db738443 BJ |
166 | unit = minor(dev) >> 3; |
167 | if (unit >= NRA || (ui = uddinfo[unit]) == 0 || ui->ui_alive == 0) { | |
168 | u.u_error = ENXIO; | |
169 | return; | |
170 | } | |
171 | sc = &uda_softc[ui->ui_ctlr]; | |
530d0032 | 172 | s = spl5(); |
db738443 BJ |
173 | if (sc->sc_state != S_RUN) { |
174 | if (sc->sc_state == S_IDLE) | |
175 | udinit(ui->ui_ctlr); | |
155d9ff0 SL |
176 | /* wait for initialization to complete */ |
177 | sleep((caddr_t)ui->ui_mi, 0); | |
db738443 BJ |
178 | if (sc->sc_state != S_RUN) { |
179 | u.u_error = EIO; | |
180 | return; | |
181 | } | |
182 | } | |
530d0032 | 183 | splx(s); |
db738443 BJ |
184 | /* SHOULD PROBABLY FORCE AN ONLINE ATTEMPT |
185 | TO SEE IF DISK IS REALLY THERE */ | |
186 | } | |
187 | ||
188 | /* | |
189 | * Initialize a UDA. Set up UBA mapping registers, | |
190 | * initialize data structures, and start hardware | |
191 | * initialization sequence. | |
192 | */ | |
193 | udinit(d) | |
194 | int d; | |
195 | { | |
196 | register struct uda_softc *sc; | |
197 | register struct uda *ud; | |
198 | struct udadevice *udaddr; | |
199 | struct uba_ctlr *um; | |
200 | ||
201 | sc = &uda_softc[d]; | |
202 | um = udminfo[d]; | |
203 | um->um_tab.b_active++; | |
204 | ud = &uda[d]; | |
205 | udaddr = (struct udadevice *)um->um_addr; | |
206 | if (sc->sc_mapped == 0) { | |
207 | /* | |
208 | * Map the communications area and command | |
209 | * and response packets into Unibus address | |
210 | * space. | |
211 | */ | |
212 | sc->sc_ubainfo = uballoc(um->um_ubanum, (caddr_t)ud, | |
213 | sizeof (struct uda), 0); | |
214 | sc->sc_uda = (struct uda *)(sc->sc_ubainfo & 0x3ffff); | |
215 | sc->sc_mapped = 1; | |
216 | } | |
217 | ||
218 | /* | |
219 | * Start the hardware initialization sequence. | |
220 | */ | |
221 | udaddr->udaip = 0; /* start initialization */ | |
222 | while ((udaddr->udasa & UDA_STEP1) == 0) | |
223 | ; | |
224 | udaddr->udasa = UDA_ERR|(NCMDL2<<11)|(NRSPL2<<8)|UDA_IE|(sc->sc_ivec/4); | |
225 | /* | |
226 | * Initialization continues in interrupt routine. | |
227 | */ | |
228 | sc->sc_state = S_STEP1; | |
229 | sc->sc_credits = 0; | |
230 | } | |
231 | ||
232 | udstrategy(bp) | |
233 | register struct buf *bp; | |
234 | { | |
235 | register struct uba_device *ui; | |
236 | register struct uba_ctlr *um; | |
237 | register struct buf *dp; | |
238 | register int unit; | |
239 | int xunit = minor(bp->b_dev) & 07; | |
240 | daddr_t sz, maxsz; | |
530d0032 | 241 | int s; |
db738443 BJ |
242 | |
243 | sz = (bp->b_bcount+511) >> 9; | |
244 | unit = dkunit(bp); | |
245 | if (unit >= NRA) | |
246 | goto bad; | |
247 | ui = uddinfo[unit]; | |
248 | um = ui->ui_mi; | |
249 | if (ui == 0 || ui->ui_alive == 0) | |
250 | goto bad; | |
251 | if ((maxsz = ra_sizes[xunit].nblocks) < 0) | |
252 | maxsz = radsize[unit] - ra_sizes[xunit].blkoff; | |
253 | if (bp->b_blkno < 0 || bp->b_blkno+sz > maxsz || | |
254 | ra_sizes[xunit].blkoff >= radsize[unit]) | |
255 | goto bad; | |
530d0032 | 256 | s = spl5(); |
db738443 BJ |
257 | /* |
258 | * Link the buffer onto the drive queue | |
259 | */ | |
260 | dp = &udutab[ui->ui_unit]; | |
261 | if (dp->b_actf == 0) | |
262 | dp->b_actf = bp; | |
263 | else | |
264 | dp->b_actl->av_forw = bp; | |
265 | dp->b_actl = bp; | |
266 | bp->av_forw = 0; | |
267 | /* | |
268 | * Link the drive onto the controller queue | |
269 | */ | |
270 | if (dp->b_active == 0) { | |
271 | dp->b_forw = NULL; | |
272 | if (um->um_tab.b_actf == NULL) | |
273 | um->um_tab.b_actf = dp; | |
274 | else | |
275 | um->um_tab.b_actl->b_forw = dp; | |
276 | um->um_tab.b_actl = dp; | |
277 | dp->b_active = 1; | |
278 | } | |
279 | if (um->um_tab.b_active == 0) { | |
280 | #if defined(VAX750) | |
281 | if (cpu == VAX_750) { | |
282 | if (um->um_ubinfo != 0) | |
283 | printf("uda: ubinfo %x\n",um->um_ubinfo); | |
284 | else | |
285 | um->um_ubinfo = | |
155d9ff0 SL |
286 | uballoc(um->um_ubanum, (caddr_t)0, 0, |
287 | UBA_NEEDBDP); | |
db738443 BJ |
288 | } |
289 | #endif | |
290 | (void) udstart(um); | |
291 | } | |
530d0032 | 292 | splx(s); |
db738443 BJ |
293 | return; |
294 | ||
295 | bad: | |
296 | bp->b_flags |= B_ERROR; | |
297 | iodone(bp); | |
298 | return; | |
299 | } | |
300 | ||
301 | udstart(um) | |
302 | register struct uba_ctlr *um; | |
303 | { | |
304 | register struct buf *bp, *dp; | |
305 | register struct mscp *mp; | |
306 | register struct uda_softc *sc; | |
307 | register struct uba_device *ui; | |
308 | struct udadevice *udaddr; | |
309 | int i; | |
310 | ||
311 | sc = &uda_softc[um->um_ctlr]; | |
312 | ||
313 | loop: | |
314 | if ((dp = um->um_tab.b_actf) == NULL) { | |
315 | /* | |
316 | * Release uneeded UBA resources and return | |
317 | */ | |
318 | um->um_tab.b_active = 0; | |
319 | #if defined(VAX750) | |
320 | if (cpu == VAX_750) { | |
321 | if (um->um_ubinfo == 0) | |
322 | printf("uda: um_ubinfo == 0\n"); | |
323 | else | |
324 | ubarelse(um->um_ubanum, &um->um_ubinfo); | |
325 | } | |
326 | #endif | |
155d9ff0 | 327 | return (0); |
db738443 BJ |
328 | } |
329 | if ((bp = dp->b_actf) == NULL) { | |
330 | /* | |
331 | * No more requests for this drive, remove | |
332 | * from controller queue and look at next drive. | |
333 | * We know we're at the head of the controller queue. | |
334 | */ | |
335 | dp->b_active = 0; | |
336 | um->um_tab.b_actf = dp->b_forw; | |
337 | goto loop; | |
338 | } | |
339 | um->um_tab.b_active++; | |
340 | udaddr = (struct udadevice *)um->um_addr; | |
341 | if ((udaddr->udasa&UDA_ERR) || sc->sc_state != S_RUN) { | |
342 | harderr(bp, "ra"); | |
343 | printf("udasa %o, state %d\n", udaddr->udasa&0xffff, sc->sc_state); | |
344 | udinit(um->um_ctlr); | |
345 | /* SHOULD REQUEUE OUTSTANDING REQUESTS, LIKE UDRESET */ | |
155d9ff0 | 346 | return (0); |
db738443 BJ |
347 | } |
348 | ui = uddinfo[dkunit(bp)]; | |
349 | /* | |
350 | * If no credits, can't issue any commands | |
351 | * until some outstanding commands complete. | |
352 | */ | |
353 | if (sc->sc_credits < 2) | |
155d9ff0 | 354 | return (0); |
db738443 | 355 | if ((mp = udgetcp(um)) == NULL) |
155d9ff0 | 356 | return (0); |
db738443 BJ |
357 | sc->sc_credits--; /* committed to issuing a command */ |
358 | if (ui->ui_flags == 0) { /* not online */ | |
359 | mp->mscp_opcode = M_OP_ONLIN; | |
360 | mp->mscp_unit = ui->ui_slave; | |
361 | dp->b_active = 2; | |
362 | um->um_tab.b_actf = dp->b_forw; /* remove from controller q */ | |
363 | printd("uda: bring unit %d online\n", ui->ui_slave); | |
364 | *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; | |
365 | i = udaddr->udaip; | |
366 | goto loop; | |
367 | } | |
368 | switch (cpu) { | |
369 | case VAX_780: | |
370 | i = UBA_NEEDBDP|UBA_CANTWAIT; | |
371 | break; | |
372 | ||
373 | case VAX_750: | |
374 | i = um->um_ubinfo|UBA_HAVEBDP|UBA_CANTWAIT; | |
375 | break; | |
376 | ||
377 | case VAX_7ZZ: | |
378 | i = UBA_CANTWAIT; | |
379 | break; | |
380 | } | |
381 | if ((i = ubasetup(um->um_ubanum, bp, i)) == 0) { | |
382 | mp->mscp_opcode = M_OP_GTUNT; | |
383 | mp->mscp_unit = ui->ui_slave; | |
384 | *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; | |
385 | i = udaddr->udaip; /* initiate polling */ | |
386 | return(1); /* wait for interrupt */ | |
387 | } | |
388 | mp->mscp_cmdref = (long)bp; /* pointer to get back */ | |
389 | mp->mscp_opcode = bp->b_flags&B_READ ? M_OP_READ : M_OP_WRITE; | |
390 | mp->mscp_unit = ui->ui_slave; | |
391 | mp->mscp_lbn = bp->b_blkno + ra_sizes[minor(bp->b_dev)&7].blkoff; | |
392 | mp->mscp_bytecnt = bp->b_bcount; | |
393 | mp->mscp_buffer = (i & 0x3ffff) | (((i>>28)&0xf)<<24); | |
394 | #if defined(VAX750) | |
395 | if (cpu == VAX_750) | |
396 | i &= 0xfffffff; /* mask off bdp */ | |
397 | #endif | |
398 | bp->b_ubinfo = i; /* save mapping info */ | |
399 | *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; | |
400 | i = udaddr->udaip; /* initiate polling */ | |
401 | if (ui->ui_dk >= 0) { | |
402 | dk_busy |= 1<<ui->ui_dk; | |
403 | dp->b_qsize++; | |
404 | dk_xfer[ui->ui_dk]++; | |
405 | dk_wds[ui->ui_dk] += bp->b_bcount>>6; | |
406 | } | |
407 | ||
408 | /* | |
409 | * Move drive to the end of the controller queue | |
410 | */ | |
411 | if (dp->b_forw != NULL) { | |
412 | um->um_tab.b_actf = dp->b_forw; | |
413 | um->um_tab.b_actl->b_forw = dp; | |
414 | um->um_tab.b_actl = dp; | |
415 | dp->b_forw = NULL; | |
416 | } | |
417 | /* | |
418 | * Move buffer to I/O wait queue | |
419 | */ | |
420 | dp->b_actf = bp->av_forw; | |
421 | dp = &udwtab[um->um_ctlr]; | |
422 | bp->av_forw = dp; | |
423 | bp->av_back = dp->av_back; | |
424 | dp->av_back->av_forw = bp; | |
425 | dp->av_back = bp; | |
426 | goto loop; | |
427 | } | |
428 | ||
429 | /* | |
430 | * UDA interrupt routine. | |
431 | */ | |
432 | udintr(d) | |
433 | int d; | |
434 | { | |
435 | register struct uba_ctlr *um = udminfo[d]; | |
436 | register struct udadevice *udaddr = (struct udadevice *)um->um_addr; | |
437 | struct buf *bp; | |
438 | register int i; | |
439 | register struct uda_softc *sc = &uda_softc[d]; | |
440 | register struct uda *ud = &uda[d]; | |
441 | struct uda *uud; | |
442 | struct mscp *mp; | |
443 | ||
444 | printd("udintr: state %d, udasa %o\n", sc->sc_state, udaddr->udasa); | |
445 | switch (sc->sc_state) { | |
446 | case S_IDLE: | |
447 | printf("uda%d: random interrupt ignored\n", d); | |
448 | return; | |
449 | ||
450 | case S_STEP1: | |
451 | #define STEP1GOOD (UDA_STEP2|UDA_IE|(NCMDL2<<3)|NRSPL2) | |
452 | if ((udaddr->udasa&(UDA_ERR|STEP1GOOD)) != STEP1GOOD) { | |
453 | sc->sc_state = S_IDLE; | |
155d9ff0 | 454 | wakeup((caddr_t)um); |
db738443 BJ |
455 | return; |
456 | } | |
457 | udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)| | |
458 | (cpu == VAX_780 ? UDA_PI : 0); | |
459 | sc->sc_state = S_STEP2; | |
460 | return; | |
461 | ||
462 | case S_STEP2: | |
463 | #define STEP2GOOD (UDA_STEP3|UDA_IE|(sc->sc_ivec/4)) | |
464 | if ((udaddr->udasa&(UDA_ERR|STEP2GOOD)) != STEP2GOOD) { | |
465 | sc->sc_state = S_IDLE; | |
155d9ff0 | 466 | wakeup((caddr_t)um); |
db738443 BJ |
467 | return; |
468 | } | |
469 | udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_ringbase)>>16; | |
470 | sc->sc_state = S_STEP3; | |
471 | return; | |
472 | ||
473 | case S_STEP3: | |
474 | #define STEP3GOOD UDA_STEP4 | |
475 | if ((udaddr->udasa&(UDA_ERR|STEP3GOOD)) != STEP3GOOD) { | |
476 | sc->sc_state = S_IDLE; | |
155d9ff0 | 477 | wakeup((caddr_t)um); |
db738443 BJ |
478 | return; |
479 | } | |
480 | udaddr->udasa = UDA_GO; | |
481 | sc->sc_state = S_SCHAR; | |
482 | ||
483 | /* | |
484 | * Initialize the data structures. | |
485 | */ | |
486 | uud = sc->sc_uda; | |
487 | for (i = 0; i < NRSP; i++) { | |
488 | ud->uda_ca.ca_rspdsc[i] = UDA_OWN|UDA_INT| | |
489 | (long)&uud->uda_rsp[i].mscp_cmdref; | |
490 | ud->uda_rsp[i].mscp_dscptr = &ud->uda_ca.ca_rspdsc[i]; | |
491 | ud->uda_rsp[i].mscp_header.uda_msglen = sizeof (struct mscp); | |
492 | } | |
493 | for (i = 0; i < NCMD; i++) { | |
494 | ud->uda_ca.ca_cmddsc[i] = UDA_INT| | |
495 | (long)&uud->uda_cmd[i].mscp_cmdref; | |
496 | ud->uda_cmd[i].mscp_dscptr = &ud->uda_ca.ca_cmddsc[i]; | |
497 | ud->uda_cmd[i].mscp_header.uda_msglen = sizeof (struct mscp); | |
498 | } | |
499 | bp = &udwtab[d]; | |
500 | bp->av_forw = bp->av_back = bp; | |
501 | sc->sc_lastcmd = 0; | |
502 | sc->sc_lastrsp = 0; | |
503 | if ((mp = udgetcp(um)) == NULL) { | |
504 | sc->sc_state = S_IDLE; | |
155d9ff0 | 505 | wakeup((caddr_t)um); |
db738443 BJ |
506 | return; |
507 | } | |
508 | mp->mscp_opcode = M_OP_STCON; | |
509 | mp->mscp_cntflgs = M_CF_ATTN|M_CF_MISC|M_CF_THIS; | |
510 | *((long *)mp->mscp_dscptr) |= UDA_OWN|UDA_INT; | |
511 | i = udaddr->udaip; /* initiate polling */ | |
512 | return; | |
513 | ||
514 | case S_SCHAR: | |
515 | case S_RUN: | |
516 | break; | |
517 | ||
518 | default: | |
519 | printf("uda%d: interrupt in unknown state %d ignored\n", | |
520 | d, sc->sc_state); | |
521 | return; | |
522 | } | |
523 | ||
524 | if (udaddr->udasa&UDA_ERR) { | |
525 | printf("uda%d: fatal error (%o)\n", d, udaddr->udasa&0xffff); | |
526 | udaddr->udaip = 0; | |
155d9ff0 | 527 | wakeup((caddr_t)um); |
db738443 BJ |
528 | } |
529 | ||
530 | /* | |
531 | * Check for a buffer purge request. | |
532 | */ | |
533 | if (ud->uda_ca.ca_bdp) { | |
534 | /* | |
535 | * THIS IS A KLUDGE. | |
536 | * Maybe we should change the entire | |
537 | * UBA interface structure. | |
538 | */ | |
539 | int s = spl7(); | |
540 | ||
541 | i = um->um_ubinfo; | |
542 | printd("uda: purge bdp %d\n", ud->uda_ca.ca_bdp); | |
543 | um->um_ubinfo = ud->uda_ca.ca_bdp<<28; | |
544 | ubapurge(um); | |
545 | um->um_ubinfo = i; | |
546 | (void) splx(s); | |
547 | ud->uda_ca.ca_bdp = 0; | |
548 | udaddr->udasa = 0; /* signal purge complete */ | |
549 | } | |
550 | ||
551 | /* | |
552 | * Check for response ring transition. | |
553 | */ | |
554 | if (ud->uda_ca.ca_rspint) { | |
555 | ud->uda_ca.ca_rspint = 0; | |
556 | for (i = sc->sc_lastrsp;; i++) { | |
557 | i %= NRSP; | |
558 | if (ud->uda_ca.ca_rspdsc[i]&UDA_OWN) | |
559 | break; | |
560 | udrsp(um, ud, sc, i); | |
561 | ud->uda_ca.ca_rspdsc[i] |= UDA_OWN; | |
562 | } | |
563 | sc->sc_lastrsp = i; | |
564 | } | |
565 | ||
566 | /* | |
567 | * Check for command ring transition. | |
568 | */ | |
569 | if (ud->uda_ca.ca_cmdint) { | |
570 | printd("uda: command ring transition\n"); | |
571 | ud->uda_ca.ca_cmdint = 0; | |
572 | } | |
155d9ff0 | 573 | (void) udstart(um); |
db738443 BJ |
574 | } |
575 | ||
576 | /* | |
577 | * Process a response packet | |
578 | */ | |
579 | udrsp(um, ud, sc, i) | |
580 | register struct uba_ctlr *um; | |
581 | register struct uda *ud; | |
582 | register struct uda_softc *sc; | |
583 | int i; | |
584 | { | |
585 | register struct mscp *mp; | |
586 | struct uba_device *ui; | |
587 | struct buf *dp, *bp; | |
588 | int st; | |
589 | ||
590 | mp = &ud->uda_rsp[i]; | |
591 | mp->mscp_header.uda_msglen = sizeof (struct mscp); | |
592 | sc->sc_credits += mp->mscp_header.uda_credits & 0xf; | |
593 | if ((mp->mscp_header.uda_credits & 0xf0) > 0x10) | |
594 | return; | |
595 | /* | |
596 | * If it's an error log message (datagram), | |
597 | * pass it on for more extensive processing. | |
598 | */ | |
599 | if ((mp->mscp_header.uda_credits & 0xf0) == 0x10) { | |
600 | uderror(um, (struct mslg *)mp); | |
601 | return; | |
602 | } | |
603 | if (mp->mscp_unit >= 8) | |
604 | return; | |
605 | if ((ui = udip[um->um_ctlr][mp->mscp_unit]) == 0) | |
606 | return; | |
607 | st = mp->mscp_status&M_ST_MASK; | |
608 | switch (mp->mscp_opcode) { | |
609 | case M_OP_STCON|M_OP_END: | |
610 | if (st == M_ST_SUCC) | |
611 | sc->sc_state = S_RUN; | |
612 | else | |
613 | sc->sc_state = S_IDLE; | |
614 | um->um_tab.b_active = 0; | |
155d9ff0 | 615 | wakeup((caddr_t)um); |
db738443 BJ |
616 | break; |
617 | ||
618 | case M_OP_ONLIN|M_OP_END: | |
619 | /* | |
620 | * Link the drive onto the controller queue | |
621 | */ | |
622 | dp = &udutab[ui->ui_unit]; | |
623 | dp->b_forw = NULL; | |
624 | if (um->um_tab.b_actf == NULL) | |
625 | um->um_tab.b_actf = dp; | |
626 | else | |
627 | um->um_tab.b_actl->b_forw = dp; | |
628 | um->um_tab.b_actl = dp; | |
629 | if (st == M_ST_SUCC) { | |
630 | ui->ui_flags = 1; /* mark it online */ | |
631 | radsize[ui->ui_unit] = (daddr_t)mp->mscp_untsize; | |
632 | printd("uda: unit %d online\n", mp->mscp_unit); | |
633 | } else { | |
634 | harderr(dp->b_actf, "ra"); | |
635 | printf("OFFLINE\n"); | |
636 | while (bp = dp->b_actf) { | |
637 | dp->b_actf = bp->av_forw; | |
638 | bp->b_flags |= B_ERROR; | |
639 | iodone(bp); | |
640 | } | |
641 | } | |
642 | dp->b_active = 1; | |
643 | break; | |
644 | ||
645 | case M_OP_AVATN: | |
646 | printd("uda: unit %d attention\n", mp->mscp_unit); | |
647 | ui->ui_flags = 0; /* it went offline and we didn't notice */ | |
648 | break; | |
649 | ||
650 | case M_OP_READ|M_OP_END: | |
651 | case M_OP_WRITE|M_OP_END: | |
652 | bp = (struct buf *)mp->mscp_cmdref; | |
155d9ff0 | 653 | ubarelse(um->um_ubanum, (int *)&bp->b_resid); |
db738443 BJ |
654 | /* |
655 | * Unlink buffer from I/O wait queue. | |
656 | */ | |
657 | bp->av_back->av_forw = bp->av_forw; | |
658 | bp->av_forw->av_back = bp->av_back; | |
659 | dp = &udutab[ui->ui_unit]; | |
660 | if (ui->ui_dk >= 0) | |
661 | if (--dp->b_qsize == 0) | |
662 | dk_busy &= ~(1<<ui->ui_dk); | |
663 | if (st == M_ST_OFFLN || st == M_ST_AVLBL) { | |
664 | ui->ui_flags = 0; /* mark unit offline */ | |
665 | /* | |
666 | * Link the buffer onto the front of the drive queue | |
667 | */ | |
668 | if ((bp->av_forw = dp->b_actf) == 0) | |
669 | dp->b_actl = bp; | |
670 | dp->b_actf = bp; | |
671 | /* | |
672 | * Link the drive onto the controller queue | |
673 | */ | |
674 | if (dp->b_active == 0) { | |
675 | dp->b_forw = NULL; | |
676 | if (um->um_tab.b_actf == NULL) | |
677 | um->um_tab.b_actf = dp; | |
678 | else | |
679 | um->um_tab.b_actl->b_forw = dp; | |
680 | um->um_tab.b_actl = dp; | |
681 | dp->b_active = 1; | |
682 | } | |
683 | return; | |
684 | } | |
685 | if (st != M_ST_SUCC) { | |
686 | harderr(bp, "ra"); | |
687 | printf("status %o\n", mp->mscp_status); | |
688 | bp->b_flags |= B_ERROR; | |
689 | } | |
690 | bp->b_resid = bp->b_bcount - mp->mscp_bytecnt; | |
691 | iodone(bp); | |
692 | break; | |
693 | ||
694 | case M_OP_GTUNT|M_OP_END: | |
695 | break; | |
696 | ||
697 | default: | |
698 | printf("uda: unknown packet\n"); | |
699 | } | |
700 | } | |
701 | ||
702 | ||
703 | /* | |
704 | * Process an error log message | |
705 | * | |
706 | * For now, just log the error on the console. | |
707 | * Only minimal decoding is done, only "useful" | |
708 | * information is printed. Eventually should | |
709 | * send message to an error logger. | |
710 | */ | |
711 | uderror(um, mp) | |
712 | register struct uba_ctlr *um; | |
713 | register struct mslg *mp; | |
714 | { | |
715 | printf("uda%d:%d: %s error, ", um->um_ctlr, mp->mslg_seqnum, | |
716 | mp->mslg_flags&M_LF_SUCC ? "soft" : "hard"); | |
717 | switch (mp->mslg_format) { | |
718 | case M_FM_CNTERR: | |
719 | printf("controller error, event 0%o\n", mp->mslg_event); | |
720 | break; | |
721 | ||
722 | case M_FM_BUSADDR: | |
723 | printf("host memory access error, event 0%o, addr 0%o\n", | |
724 | mp->mslg_event, *((long *)&mp->mslg_busaddr[0])); | |
725 | break; | |
726 | ||
727 | case M_FM_DISKTRN: | |
728 | printf("disk transfer error, unit %d, grp %d, cyl %d, sec %d, ", | |
729 | mp->mslg_unit, mp->mslg_group, mp->mslg_cylinder, | |
730 | mp->mslg_sector); | |
731 | printf("trk %d, lbn %d, retry %d, level %d\n", mp->mslg_track, | |
732 | mp->mslg_lbn, mp->mslg_retry, mp->mslg_level); | |
733 | break; | |
734 | ||
735 | case M_FM_SDI: | |
736 | printf("SDI error, unit %d, event 0%o, cyl %d\n", mp->mslg_unit, | |
737 | mp->mslg_event, mp->mslg_cylinder); | |
738 | break; | |
739 | ||
740 | case M_FM_SMLDSK: | |
741 | printf("small disk error, unit %d, event 0%o, cyl %d\n", | |
742 | mp->mslg_unit, mp->mslg_event, mp->mslg_sdecyl); | |
743 | break; | |
744 | ||
745 | default: | |
746 | printf("unknown error, unit %d, format 0%o, event 0%o\n", | |
747 | mp->mslg_unit, mp->mslg_format, mp->mslg_event); | |
748 | } | |
749 | } | |
750 | ||
751 | ||
752 | /* | |
753 | * Find an unused command packet | |
754 | */ | |
755 | struct mscp * | |
756 | udgetcp(um) | |
757 | struct uba_ctlr *um; | |
758 | { | |
759 | register struct mscp *mp; | |
760 | register struct udaca *cp; | |
761 | register struct uda_softc *sc; | |
762 | register int i; | |
763 | ||
764 | cp = &uda[um->um_ctlr].uda_ca; | |
765 | sc = &uda_softc[um->um_ctlr]; | |
766 | i = sc->sc_lastcmd; | |
767 | if ((cp->ca_cmddsc[i] & (UDA_OWN|UDA_INT)) == UDA_INT) { | |
768 | cp->ca_cmddsc[i] &= ~UDA_INT; | |
769 | mp = &uda[um->um_ctlr].uda_cmd[i]; | |
770 | mp->mscp_unit = mp->mscp_modifier = 0; | |
771 | mp->mscp_opcode = mp->mscp_flags = 0; | |
772 | mp->mscp_bytecnt = mp->mscp_buffer = 0; | |
773 | mp->mscp_errlgfl = mp->mscp_copyspd = 0; | |
774 | sc->sc_lastcmd = (i + 1) % NCMD; | |
775 | return(mp); | |
776 | } | |
777 | return(NULL); | |
778 | } | |
779 | ||
780 | udread(dev) | |
781 | dev_t dev; | |
782 | { | |
783 | register int unit = minor(dev) >> 3; | |
784 | ||
785 | if (unit >= NRA) | |
786 | u.u_error = ENXIO; | |
787 | else | |
788 | physio(udstrategy, &rudbuf[unit], dev, B_READ, minphys); | |
789 | } | |
790 | ||
791 | udwrite(dev) | |
792 | dev_t dev; | |
793 | { | |
794 | register int unit = minor(dev) >> 3; | |
795 | ||
796 | if (unit >= NRA) | |
797 | u.u_error = ENXIO; | |
798 | else | |
799 | physio(udstrategy, &rudbuf[unit], dev, B_WRITE, minphys); | |
800 | } | |
801 | ||
802 | udreset(uban) | |
803 | int uban; | |
804 | { | |
805 | register struct uba_ctlr *um; | |
806 | register struct uba_device *ui; | |
807 | register struct buf *bp, *dp; | |
808 | register int unit; | |
809 | struct buf *nbp; | |
810 | int d; | |
811 | ||
812 | for (d = 0; d < NUDA; d++) { | |
813 | if ((um = udminfo[d]) == 0 || um->um_ubanum != uban || | |
814 | um->um_alive == 0) | |
815 | continue; | |
816 | printf(" uda%d", d); | |
817 | um->um_tab.b_active = 0; | |
818 | um->um_tab.b_actf = um->um_tab.b_actl = 0; | |
819 | uda_softc[d].sc_state = S_IDLE; | |
820 | for (unit = 0; unit < NRA; unit++) { | |
821 | if ((ui = uddinfo[unit]) == 0) | |
822 | continue; | |
823 | if (ui->ui_alive == 0 || ui->ui_mi != um) | |
824 | continue; | |
825 | udutab[unit].b_active = 0; | |
826 | udutab[unit].b_qsize = 0; | |
827 | } | |
828 | for (bp = udwtab[d].av_forw; bp != &udwtab[d]; bp = nbp) { | |
829 | nbp = bp->av_forw; | |
155d9ff0 | 830 | ubarelse(uban, (int *)&bp->b_ubinfo); |
db738443 BJ |
831 | /* |
832 | * Link the buffer onto the drive queue | |
833 | */ | |
834 | dp = &udutab[dkunit(bp)]; | |
835 | if (dp->b_actf == 0) | |
836 | dp->b_actf = bp; | |
837 | else | |
838 | dp->b_actl->av_forw = bp; | |
839 | dp->b_actl = bp; | |
840 | bp->av_forw = 0; | |
841 | /* | |
842 | * Link the drive onto the controller queue | |
843 | */ | |
844 | if (dp->b_active == 0) { | |
845 | dp->b_forw = NULL; | |
846 | if (um->um_tab.b_actf == NULL) | |
847 | um->um_tab.b_actf = dp; | |
848 | else | |
849 | um->um_tab.b_actl->b_forw = dp; | |
850 | um->um_tab.b_actl = dp; | |
851 | dp->b_active = 1; | |
852 | } | |
853 | } | |
854 | udinit(d); | |
855 | } | |
856 | } | |
857 | ||
858 | uddump() | |
859 | { | |
860 | return(ENXIO); | |
861 | } |