Commit | Line | Data |
---|---|---|
c224ab94 | 1 | /* up.c 4.49 82/05/19 */ |
008c0481 | 2 | |
66b4fb09 | 3 | #include "up.h" |
a3cb8f60 | 4 | #if NSC > 0 |
008c0481 | 5 | /* |
10fb932f | 6 | * UNIBUS disk driver with overlapped seeks and ECC recovery. |
0c48c799 BJ |
7 | * |
8 | * TODO: | |
0c48c799 | 9 | * Add bad sector forwarding code |
299d67ed | 10 | * Check that offset recovery code works |
008c0481 BJ |
11 | */ |
12 | ||
13 | #include "../h/param.h" | |
14 | #include "../h/systm.h" | |
3f3a34c3 BJ |
15 | #include "../h/cpu.h" |
16 | #include "../h/nexus.h" | |
41888f16 | 17 | #include "../h/dk.h" |
008c0481 BJ |
18 | #include "../h/buf.h" |
19 | #include "../h/conf.h" | |
20 | #include "../h/dir.h" | |
21 | #include "../h/user.h" | |
22 | #include "../h/map.h" | |
80e7c811 | 23 | #include "../h/pte.h" |
008c0481 | 24 | #include "../h/mtpr.h" |
008c0481 | 25 | #include "../h/vm.h" |
89bd2f01 BJ |
26 | #include "../h/ubavar.h" |
27 | #include "../h/ubareg.h" | |
0ff318b2 | 28 | #include "../h/cmap.h" |
008c0481 | 29 | |
0ff318b2 | 30 | #include "../h/upreg.h" |
008c0481 | 31 | |
3f3a34c3 BJ |
32 | struct up_softc { |
33 | int sc_softas; | |
71236e46 | 34 | int sc_ndrive; |
3f3a34c3 | 35 | int sc_wticks; |
736772ef | 36 | int sc_recal; |
a3cb8f60 | 37 | } up_softc[NSC]; |
008c0481 | 38 | |
3f3a34c3 | 39 | /* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */ |
008c0481 BJ |
40 | struct size |
41 | { | |
42 | daddr_t nblocks; | |
43 | int cyloff; | |
44 | } up_sizes[8] = { | |
c94d7fe4 BJ |
45 | #ifdef ERNIE |
46 | 49324, 0, /* A=cyl 0 thru 26 */ | |
47 | #else | |
008c0481 | 48 | 15884, 0, /* A=cyl 0 thru 26 */ |
c94d7fe4 | 49 | #endif |
008c0481 | 50 | 33440, 27, /* B=cyl 27 thru 81 */ |
d1778415 | 51 | 495520, 0, /* C=cyl 0 thru 814 */ |
008c0481 BJ |
52 | 15884, 562, /* D=cyl 562 thru 588 */ |
53 | 55936, 589, /* E=cyl 589 thru 680 */ | |
0d728200 BJ |
54 | #ifndef NOBADSECT |
55 | 81376, 681, /* F=cyl 681 thru 814 */ | |
56 | 153728, 562, /* G=cyl 562 thru 814 */ | |
57 | #else | |
58 | 81472, 681, | |
59 | 153824, 562, | |
60 | #endif | |
008c0481 | 61 | 291346, 82, /* H=cyl 82 thru 561 */ |
3f3a34c3 BJ |
62 | }, fj_sizes[8] = { |
63 | 15884, 0, /* A=cyl 0 thru 49 */ | |
64 | 33440, 50, /* B=cyl 50 thru 154 */ | |
65 | 263360, 0, /* C=cyl 0 thru 822 */ | |
66 | 0, 0, | |
67 | 0, 0, | |
68 | 0, 0, | |
69 | 0, 0, | |
0d728200 BJ |
70 | #ifndef NOBADSECT |
71 | 213664, 155, /* H=cyl 155 thru 822 */ | |
72 | #else | |
73 | 213760, 155, | |
74 | #endif | |
0cc9b5a9 BJ |
75 | }, am_sizes[8] = { |
76 | 15884, 0, /* A=cyl 0 thru 31 */ | |
77 | 33440, 32, /* B=cyl 32 thru 97 */ | |
78 | 524288, 0, /* C=cyl 0 thru 1023 */ | |
eadd189e SL |
79 | 27786, 668, |
80 | 27786, 723, | |
81 | 125440, 778, | |
0cc9b5a9 BJ |
82 | 181760, 668, /* G=cyl 668 thru 1022 */ |
83 | 291346, 98, /* H=cyl 98 thru 667 */ | |
008c0481 | 84 | }; |
3f3a34c3 | 85 | /* END OF STUFF WHICH SHOULD BE READ IN PER DISK */ |
008c0481 | 86 | |
cc7ff771 BJ |
87 | /* |
88 | * On a 780 upSDIST could be 2, but | |
89 | * in the interest of 750's... | |
90 | */ | |
91 | #define _upSDIST 3 /* 1.5 msec */ | |
3f3a34c3 BJ |
92 | #define _upRDIST 4 /* 2.0 msec */ |
93 | ||
94 | int upSDIST = _upSDIST; | |
95 | int upRDIST = _upRDIST; | |
96 | ||
71236e46 | 97 | int upprobe(), upslave(), upattach(), updgo(), upintr(); |
89bd2f01 BJ |
98 | struct uba_ctlr *upminfo[NSC]; |
99 | struct uba_device *updinfo[NUP]; | |
c10bcf0a BJ |
100 | #define UPIPUNITS 8 |
101 | struct uba_device *upip[NSC][UPIPUNITS]; /* fuji w/fixed head gives n,n+4 */ | |
d763a2b7 | 102 | |
71236e46 | 103 | u_short upstd[] = { 0776700, 0774400, 0776300, 0 }; |
0801d37f | 104 | struct uba_driver scdriver = |
71236e46 | 105 | { upprobe, upslave, upattach, updgo, upstd, "up", updinfo, "sc", upminfo }; |
3f3a34c3 BJ |
106 | struct buf uputab[NUP]; |
107 | ||
108 | struct upst { | |
109 | short nsect; | |
110 | short ntrak; | |
111 | short nspc; | |
112 | short ncyl; | |
113 | struct size *sizes; | |
114 | } upst[] = { | |
71236e46 BJ |
115 | 32, 19, 32*19, 823, up_sizes, /* 9300/cdc */ |
116 | /* 9300 actually has 815 cylinders... */ | |
3f3a34c3 | 117 | 32, 10, 32*10, 823, fj_sizes, /* fujitsu 160m */ |
cc7ff771 | 118 | 32, 16, 32*16, 1024, am_sizes, /* ampex capricorn */ |
3f3a34c3 | 119 | }; |
008c0481 | 120 | |
2601dfbd | 121 | u_char up_offset[16] = { |
299d67ed BJ |
122 | UPOF_P400, UPOF_M400, UPOF_P400, UPOF_M400, |
123 | UPOF_P800, UPOF_M800, UPOF_P800, UPOF_M800, | |
124 | UPOF_P1200, UPOF_M1200, UPOF_P1200, UPOF_M1200, | |
125 | 0, 0, 0, 0 | |
2601dfbd | 126 | }; |
008c0481 | 127 | |
0801d37f | 128 | struct buf rupbuf[NUP]; |
008c0481 | 129 | |
008c0481 BJ |
130 | #define b_cylin b_resid |
131 | ||
008c0481 BJ |
132 | #ifdef INTRLVE |
133 | daddr_t dkblock(); | |
134 | #endif | |
3f3a34c3 BJ |
135 | |
136 | int upwstart, upwatch(); /* Have started guardian */ | |
7e00c42b | 137 | int upseek; |
f88f8fdb | 138 | int upwaitdry; |
3f3a34c3 BJ |
139 | |
140 | /*ARGSUSED*/ | |
71236e46 | 141 | upprobe(reg) |
3f3a34c3 | 142 | caddr_t reg; |
008c0481 | 143 | { |
d763a2b7 BJ |
144 | register int br, cvec; |
145 | ||
71236e46 BJ |
146 | #ifdef lint |
147 | br = 0; cvec = br; br = cvec; | |
148 | #endif | |
2601dfbd | 149 | ((struct updevice *)reg)->upcs1 = UP_IE|UP_RDY; |
71236e46 | 150 | DELAY(10); |
2601dfbd | 151 | ((struct updevice *)reg)->upcs1 = 0; |
d763a2b7 | 152 | return (1); |
3f3a34c3 BJ |
153 | } |
154 | ||
71236e46 | 155 | upslave(ui, reg) |
89bd2f01 | 156 | struct uba_device *ui; |
3f3a34c3 BJ |
157 | caddr_t reg; |
158 | { | |
2601dfbd | 159 | register struct updevice *upaddr = (struct updevice *)reg; |
3f3a34c3 BJ |
160 | |
161 | upaddr->upcs1 = 0; /* conservative */ | |
71236e46 | 162 | upaddr->upcs2 = ui->ui_slave; |
c224ab94 | 163 | upaddr->upcs1 = UP_NOP|UP_GO; |
299d67ed | 164 | if (upaddr->upcs2&UPCS2_NED) { |
2601dfbd | 165 | upaddr->upcs1 = UP_DCLR|UP_GO; |
3f3a34c3 BJ |
166 | return (0); |
167 | } | |
71236e46 BJ |
168 | return (1); |
169 | } | |
170 | ||
171 | upattach(ui) | |
89bd2f01 | 172 | register struct uba_device *ui; |
71236e46 | 173 | { |
2601dfbd | 174 | register struct updevice *upaddr; |
71236e46 | 175 | |
6a81870e | 176 | if (upwstart == 0) { |
7780575a | 177 | timeout(upwatch, (caddr_t)0, hz); |
6a81870e BJ |
178 | upwstart++; |
179 | } | |
b7333467 BJ |
180 | if (ui->ui_dk >= 0) |
181 | dk_mspw[ui->ui_dk] = .0000020345; | |
71236e46 BJ |
182 | upip[ui->ui_ctlr][ui->ui_slave] = ui; |
183 | up_softc[ui->ui_ctlr].sc_ndrive++; | |
2601dfbd BJ |
184 | upaddr = (struct updevice *)ui->ui_addr; |
185 | upaddr->upcs1 = 0; | |
186 | upaddr->upcs2 = ui->ui_slave; | |
26e15512 | 187 | upaddr->uphr = UPHR_MAXTRAK; |
c6a51a7b | 188 | if (upaddr->uphr == 9) |
26e15512 | 189 | ui->ui_type = 1; /* fujitsu hack */ |
0cc9b5a9 BJ |
190 | else if (upaddr->uphr == 15) |
191 | ui->ui_type = 2; /* ampex hack */ | |
26e15512 BJ |
192 | upaddr->upcs2 = UPCS2_CLR; |
193 | /* | |
194 | upaddr->uphr = UPHR_MAXCYL; | |
195 | printf("maxcyl %d\n", upaddr->uphr); | |
196 | upaddr->uphr = UPHR_MAXTRAK; | |
197 | printf("maxtrak %d\n", upaddr->uphr); | |
198 | upaddr->uphr = UPHR_MAXSECT; | |
199 | printf("maxsect %d\n", upaddr->uphr); | |
200 | */ | |
3f3a34c3 BJ |
201 | } |
202 | ||
3f3a34c3 BJ |
203 | upstrategy(bp) |
204 | register struct buf *bp; | |
205 | { | |
89bd2f01 | 206 | register struct uba_device *ui; |
3f3a34c3 BJ |
207 | register struct upst *st; |
208 | register int unit; | |
7e00c42b | 209 | register struct buf *dp; |
3f3a34c3 | 210 | int xunit = minor(bp->b_dev) & 07; |
7e00c42b | 211 | long bn, sz; |
3f3a34c3 | 212 | |
7e00c42b | 213 | sz = (bp->b_bcount+511) >> 9; |
008c0481 | 214 | unit = dkunit(bp); |
3f3a34c3 BJ |
215 | if (unit >= NUP) |
216 | goto bad; | |
217 | ui = updinfo[unit]; | |
218 | if (ui == 0 || ui->ui_alive == 0) | |
219 | goto bad; | |
220 | st = &upst[ui->ui_type]; | |
221 | if (bp->b_blkno < 0 || | |
222 | (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks) | |
223 | goto bad; | |
224 | bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff; | |
0cc9b5a9 | 225 | (void) spl5(); |
7e00c42b BJ |
226 | dp = &uputab[ui->ui_unit]; |
227 | disksort(dp, bp); | |
228 | if (dp->b_active == 0) { | |
3f3a34c3 BJ |
229 | (void) upustart(ui); |
230 | bp = &ui->ui_mi->um_tab; | |
231 | if (bp->b_actf && bp->b_active == 0) | |
232 | (void) upstart(ui->ui_mi); | |
008c0481 | 233 | } |
0cc9b5a9 | 234 | (void) spl0(); |
3f3a34c3 BJ |
235 | return; |
236 | ||
237 | bad: | |
238 | bp->b_flags |= B_ERROR; | |
239 | iodone(bp); | |
240 | return; | |
008c0481 BJ |
241 | } |
242 | ||
736772ef BJ |
243 | /* |
244 | * Unit start routine. | |
245 | * Seek the drive to be where the data is | |
246 | * and then generate another interrupt | |
247 | * to actually start the transfer. | |
248 | * If there is only one drive on the controller, | |
249 | * or we are very close to the data, don't | |
250 | * bother with the search. If called after | |
251 | * searching once, don't bother to look where | |
252 | * we are, just queue for transfer (to avoid | |
253 | * positioning forever without transferrring.) | |
254 | */ | |
3f3a34c3 | 255 | upustart(ui) |
89bd2f01 | 256 | register struct uba_device *ui; |
008c0481 BJ |
257 | { |
258 | register struct buf *bp, *dp; | |
89bd2f01 | 259 | register struct uba_ctlr *um; |
2601dfbd | 260 | register struct updevice *upaddr; |
3f3a34c3 | 261 | register struct upst *st; |
008c0481 | 262 | daddr_t bn; |
736772ef | 263 | int sn, csn; |
71236e46 BJ |
264 | /* |
265 | * The SC21 cancels commands if you just say | |
2601dfbd | 266 | * cs1 = UP_IE |
71236e46 BJ |
267 | * so we are cautious about handling of cs1. |
268 | * Also don't bother to clear as bits other than in upintr(). | |
269 | */ | |
736772ef BJ |
270 | int didie = 0; |
271 | ||
272 | if (ui == 0) | |
273 | return (0); | |
89bd2f01 | 274 | um = ui->ui_mi; |
3f3a34c3 BJ |
275 | dk_busy &= ~(1<<ui->ui_dk); |
276 | dp = &uputab[ui->ui_unit]; | |
7bc8d985 | 277 | if ((bp = dp->b_actf) == NULL) |
eb891eaa | 278 | goto out; |
736772ef BJ |
279 | /* |
280 | * If the controller is active, just remember | |
281 | * that this device would like to be positioned... | |
282 | * if we tried to position now we would confuse the SC21. | |
283 | */ | |
3f3a34c3 | 284 | if (um->um_tab.b_active) { |
d763a2b7 | 285 | up_softc[um->um_ctlr].sc_softas |= 1<<ui->ui_slave; |
2a3b9a7f BJ |
286 | return (0); |
287 | } | |
736772ef BJ |
288 | /* |
289 | * If we have already positioned this drive, | |
290 | * then just put it on the ready queue. | |
291 | */ | |
a3f430e0 BJ |
292 | if (dp->b_active) |
293 | goto done; | |
294 | dp->b_active = 1; | |
2601dfbd | 295 | upaddr = (struct updevice *)um->um_addr; |
3f3a34c3 | 296 | upaddr->upcs2 = ui->ui_slave; |
736772ef BJ |
297 | /* |
298 | * If drive has just come up, | |
299 | * setup the pack. | |
300 | */ | |
299d67ed | 301 | if ((upaddr->upds & UPDS_VV) == 0) { |
71236e46 | 302 | /* SHOULD WARN SYSTEM THAT THIS HAPPENED */ |
2601dfbd BJ |
303 | upaddr->upcs1 = UP_IE|UP_DCLR|UP_GO; |
304 | upaddr->upcs1 = UP_IE|UP_PRESET|UP_GO; | |
299d67ed | 305 | upaddr->upof = UPOF_FMT22; |
eb891eaa | 306 | didie = 1; |
008c0481 | 307 | } |
736772ef BJ |
308 | /* |
309 | * If drive is offline, forget about positioning. | |
310 | */ | |
299d67ed | 311 | if ((upaddr->upds & (UPDS_DPR|UPDS_MOL)) != (UPDS_DPR|UPDS_MOL)) |
2a3b9a7f | 312 | goto done; |
736772ef BJ |
313 | /* |
314 | * If there is only one drive, | |
315 | * dont bother searching. | |
316 | */ | |
71236e46 BJ |
317 | if (up_softc[um->um_ctlr].sc_ndrive == 1) |
318 | goto done; | |
736772ef BJ |
319 | /* |
320 | * Figure out where this transfer is going to | |
321 | * and see if we are close enough to justify not searching. | |
322 | */ | |
3f3a34c3 | 323 | st = &upst[ui->ui_type]; |
008c0481 | 324 | bn = dkblock(bp); |
3f3a34c3 BJ |
325 | sn = bn%st->nspc; |
326 | sn = (sn + st->nsect - upSDIST) % st->nsect; | |
736772ef | 327 | if (bp->b_cylin - upaddr->updc) |
7bc8d985 | 328 | goto search; /* Not on-cylinder */ |
2a3b9a7f BJ |
329 | else if (upseek) |
330 | goto done; /* Ok just to be on-cylinder */ | |
008c0481 | 331 | csn = (upaddr->upla>>6) - sn - 1; |
7bc8d985 | 332 | if (csn < 0) |
3f3a34c3 BJ |
333 | csn += st->nsect; |
334 | if (csn > st->nsect - upRDIST) | |
008c0481 | 335 | goto done; |
008c0481 | 336 | search: |
736772ef BJ |
337 | upaddr->updc = bp->b_cylin; |
338 | /* | |
339 | * Not on cylinder at correct position, | |
340 | * seek/search. | |
341 | */ | |
2a3b9a7f | 342 | if (upseek) |
2601dfbd | 343 | upaddr->upcs1 = UP_IE|UP_SEEK|UP_GO; |
7e00c42b | 344 | else { |
2a3b9a7f | 345 | upaddr->upda = sn; |
2601dfbd | 346 | upaddr->upcs1 = UP_IE|UP_SEARCH|UP_GO; |
2a3b9a7f | 347 | } |
eb891eaa | 348 | didie = 1; |
736772ef BJ |
349 | /* |
350 | * Mark unit busy for iostat. | |
351 | */ | |
3f3a34c3 BJ |
352 | if (ui->ui_dk >= 0) { |
353 | dk_busy |= 1<<ui->ui_dk; | |
354 | dk_seek[ui->ui_dk]++; | |
008c0481 | 355 | } |
eb891eaa | 356 | goto out; |
008c0481 | 357 | done: |
736772ef BJ |
358 | /* |
359 | * Device is ready to go. | |
360 | * Put it on the ready queue for the controller | |
361 | * (unless its already there.) | |
362 | */ | |
2601dfbd BJ |
363 | if (dp->b_active != 2) { |
364 | dp->b_forw = NULL; | |
365 | if (um->um_tab.b_actf == NULL) | |
366 | um->um_tab.b_actf = dp; | |
367 | else | |
368 | um->um_tab.b_actl->b_forw = dp; | |
369 | um->um_tab.b_actl = dp; | |
370 | dp->b_active = 2; | |
371 | } | |
eb891eaa BJ |
372 | out: |
373 | return (didie); | |
008c0481 BJ |
374 | } |
375 | ||
736772ef BJ |
376 | /* |
377 | * Start up a transfer on a drive. | |
378 | */ | |
3f3a34c3 | 379 | upstart(um) |
89bd2f01 | 380 | register struct uba_ctlr *um; |
008c0481 BJ |
381 | { |
382 | register struct buf *bp, *dp; | |
89bd2f01 | 383 | register struct uba_device *ui; |
2601dfbd | 384 | register struct updevice *upaddr; |
7e00c42b | 385 | struct upst *st; |
008c0481 | 386 | daddr_t bn; |
f88f8fdb | 387 | int dn, sn, tn, cmd, waitdry; |
008c0481 | 388 | |
008c0481 | 389 | loop: |
736772ef BJ |
390 | /* |
391 | * Pull a request off the controller queue | |
392 | */ | |
3f3a34c3 | 393 | if ((dp = um->um_tab.b_actf) == NULL) |
eb891eaa | 394 | return (0); |
008c0481 | 395 | if ((bp = dp->b_actf) == NULL) { |
3f3a34c3 | 396 | um->um_tab.b_actf = dp->b_forw; |
008c0481 BJ |
397 | goto loop; |
398 | } | |
736772ef BJ |
399 | /* |
400 | * Mark controller busy, and | |
401 | * determine destination of this request. | |
402 | */ | |
3f3a34c3 BJ |
403 | um->um_tab.b_active++; |
404 | ui = updinfo[dkunit(bp)]; | |
008c0481 | 405 | bn = dkblock(bp); |
3f3a34c3 BJ |
406 | dn = ui->ui_slave; |
407 | st = &upst[ui->ui_type]; | |
408 | sn = bn%st->nspc; | |
409 | tn = sn/st->nsect; | |
410 | sn %= st->nsect; | |
2601dfbd | 411 | upaddr = (struct updevice *)ui->ui_addr; |
736772ef BJ |
412 | /* |
413 | * Select drive if not selected already. | |
414 | */ | |
415 | if ((upaddr->upcs2&07) != dn) | |
416 | upaddr->upcs2 = dn; | |
417 | /* | |
418 | * Check that it is ready and online | |
419 | */ | |
f88f8fdb | 420 | waitdry = 0; |
299d67ed | 421 | while ((upaddr->upds&UPDS_DRY) == 0) { |
f88f8fdb BJ |
422 | if (++waitdry > 512) |
423 | break; | |
424 | upwaitdry++; | |
425 | } | |
299d67ed | 426 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { |
f6d201ff | 427 | printf("up%d: not ready", dkunit(bp)); |
299d67ed | 428 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { |
71236e46 | 429 | printf("\n"); |
3f3a34c3 BJ |
430 | um->um_tab.b_active = 0; |
431 | um->um_tab.b_errcnt = 0; | |
88253fd2 BJ |
432 | dp->b_actf = bp->av_forw; |
433 | dp->b_active = 0; | |
434 | bp->b_flags |= B_ERROR; | |
435 | iodone(bp); | |
88253fd2 BJ |
436 | goto loop; |
437 | } | |
736772ef BJ |
438 | /* |
439 | * Oh, well, sometimes this | |
440 | * happens, for reasons unknown. | |
441 | */ | |
2601dfbd | 442 | printf(" (flakey)\n"); |
008c0481 | 443 | } |
736772ef BJ |
444 | /* |
445 | * Setup for the transfer, and get in the | |
446 | * UNIBUS adaptor queue. | |
447 | */ | |
5aa9d5ea | 448 | upaddr->updc = bp->b_cylin; |
008c0481 | 449 | upaddr->upda = (tn << 8) + sn; |
008c0481 BJ |
450 | upaddr->upwc = -bp->b_bcount / sizeof (short); |
451 | if (bp->b_flags & B_READ) | |
2601dfbd | 452 | cmd = UP_IE|UP_RCOM|UP_GO; |
008c0481 | 453 | else |
2601dfbd | 454 | cmd = UP_IE|UP_WCOM|UP_GO; |
b7333467 | 455 | um->um_cmd = cmd; |
a0eab615 | 456 | (void) ubago(ui); |
eb891eaa | 457 | return (1); |
008c0481 BJ |
458 | } |
459 | ||
736772ef BJ |
460 | /* |
461 | * Now all ready to go, stuff the registers. | |
462 | */ | |
b7333467 | 463 | updgo(um) |
89bd2f01 | 464 | struct uba_ctlr *um; |
3f3a34c3 | 465 | { |
2601dfbd | 466 | register struct updevice *upaddr = (struct updevice *)um->um_addr; |
7e00c42b | 467 | |
cc7ff771 | 468 | um->um_tab.b_active++; /* should now be 2 */ |
b7333467 BJ |
469 | upaddr->upba = um->um_ubinfo; |
470 | upaddr->upcs1 = um->um_cmd|((um->um_ubinfo>>8)&0x300); | |
3f3a34c3 BJ |
471 | } |
472 | ||
736772ef BJ |
473 | /* |
474 | * Handle a disk interrupt. | |
475 | */ | |
443c8066 | 476 | upintr(sc21) |
3f3a34c3 | 477 | register sc21; |
008c0481 BJ |
478 | { |
479 | register struct buf *bp, *dp; | |
89bd2f01 BJ |
480 | register struct uba_ctlr *um = upminfo[sc21]; |
481 | register struct uba_device *ui; | |
2601dfbd | 482 | register struct updevice *upaddr = (struct updevice *)um->um_addr; |
008c0481 | 483 | register unit; |
7e00c42b | 484 | struct up_softc *sc = &up_softc[um->um_ctlr]; |
71236e46 | 485 | int as = (upaddr->upas & 0377) | sc->sc_softas; |
f88f8fdb | 486 | int needie = 1, waitdry; |
008c0481 | 487 | |
7e00c42b | 488 | sc->sc_wticks = 0; |
71236e46 | 489 | sc->sc_softas = 0; |
736772ef BJ |
490 | /* |
491 | * If controller wasn't transferring, then this is an | |
492 | * interrupt for attention status on seeking drives. | |
493 | * Just service them. | |
494 | */ | |
cc7ff771 | 495 | if (um->um_tab.b_active != 2 && !sc->sc_recal) { |
736772ef BJ |
496 | if (upaddr->upcs1 & UP_TRE) |
497 | upaddr->upcs1 = UP_TRE; | |
498 | goto doattn; | |
499 | } | |
736772ef BJ |
500 | /* |
501 | * Get device and block structures, and a pointer | |
89bd2f01 | 502 | * to the uba_device for the drive. Select the drive. |
736772ef BJ |
503 | */ |
504 | dp = um->um_tab.b_actf; | |
505 | bp = dp->b_actf; | |
506 | ui = updinfo[dkunit(bp)]; | |
507 | dk_busy &= ~(1 << ui->ui_dk); | |
508 | if ((upaddr->upcs2&07) != ui->ui_slave) | |
3f3a34c3 | 509 | upaddr->upcs2 = ui->ui_slave; |
736772ef BJ |
510 | /* |
511 | * Check for and process errors on | |
512 | * either the drive or the controller. | |
513 | */ | |
299d67ed | 514 | if ((upaddr->upds&UPDS_ERR) || (upaddr->upcs1&UP_TRE)) { |
f88f8fdb | 515 | waitdry = 0; |
299d67ed | 516 | while ((upaddr->upds & UPDS_DRY) == 0) { |
f88f8fdb BJ |
517 | if (++waitdry > 512) |
518 | break; | |
519 | upwaitdry++; | |
520 | } | |
299d67ed | 521 | if (upaddr->uper1&UPER1_WLE) { |
736772ef BJ |
522 | /* |
523 | * Give up on write locked devices | |
524 | * immediately. | |
525 | */ | |
f6d201ff | 526 | printf("up%d: write locked\n", dkunit(bp)); |
736772ef BJ |
527 | bp->b_flags |= B_ERROR; |
528 | } else if (++um->um_tab.b_errcnt > 27) { | |
529 | /* | |
530 | * After 28 retries (16 without offset, and | |
531 | * 12 with offset positioning) give up. | |
532 | */ | |
f6d201ff BJ |
533 | harderr(bp, "up"); |
534 | printf("cs2=%b er1=%b er2=%b\n", | |
c84ff1f9 BJ |
535 | upaddr->upcs2, UPCS2_BITS, |
536 | upaddr->uper1, UPER1_BITS, | |
537 | upaddr->uper2, UPER2_BITS); | |
736772ef BJ |
538 | bp->b_flags |= B_ERROR; |
539 | } else { | |
540 | /* | |
541 | * Retriable error. | |
542 | * If a soft ecc, correct it (continuing | |
543 | * by returning if necessary. | |
544 | * Otherwise fall through and retry the transfer | |
545 | */ | |
546 | um->um_tab.b_active = 0; /* force retry */ | |
299d67ed | 547 | if ((upaddr->uper1&(UPER1_DCK|UPER1_ECH))==UPER1_DCK) |
2601dfbd BJ |
548 | if (upecc(ui)) |
549 | return; | |
736772ef BJ |
550 | } |
551 | /* | |
552 | * Clear drive error and, every eight attempts, | |
553 | * (starting with the fourth) | |
554 | * recalibrate to clear the slate. | |
555 | */ | |
556 | upaddr->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO; | |
557 | needie = 0; | |
fc4d0a69 | 558 | if ((um->um_tab.b_errcnt&07) == 4 && um->um_tab.b_active == 0) { |
736772ef | 559 | upaddr->upcs1 = UP_RECAL|UP_IE|UP_GO; |
a6442a2f BJ |
560 | sc->sc_recal = 0; |
561 | goto nextrecal; | |
736772ef BJ |
562 | } |
563 | } | |
564 | /* | |
a6442a2f BJ |
565 | * Advance recalibration finite state machine |
566 | * if recalibrate in progress, through | |
567 | * RECAL | |
568 | * SEEK | |
569 | * OFFSET (optional) | |
570 | * RETRY | |
736772ef | 571 | */ |
a6442a2f BJ |
572 | switch (sc->sc_recal) { |
573 | ||
574 | case 1: | |
575 | upaddr->updc = bp->b_cylin; | |
576 | upaddr->upcs1 = UP_SEEK|UP_IE|UP_GO; | |
577 | goto nextrecal; | |
578 | case 2: | |
579 | if (um->um_tab.b_errcnt < 16 || (bp->b_flags&B_READ) == 0) | |
580 | goto donerecal; | |
299d67ed | 581 | upaddr->upof = up_offset[um->um_tab.b_errcnt & 017] | UPOF_FMT22; |
a6442a2f BJ |
582 | upaddr->upcs1 = UP_IE|UP_OFFSET|UP_GO; |
583 | goto nextrecal; | |
584 | nextrecal: | |
585 | sc->sc_recal++; | |
586 | um->um_tab.b_active = 1; | |
587 | return; | |
588 | donerecal: | |
589 | case 3: | |
736772ef | 590 | sc->sc_recal = 0; |
a6442a2f BJ |
591 | um->um_tab.b_active = 0; |
592 | break; | |
736772ef BJ |
593 | } |
594 | /* | |
595 | * If still ``active'', then don't need any more retries. | |
596 | */ | |
597 | if (um->um_tab.b_active) { | |
598 | /* | |
599 | * If we were offset positioning, | |
600 | * return to centerline. | |
601 | */ | |
602 | if (um->um_tab.b_errcnt >= 16) { | |
299d67ed | 603 | upaddr->upof = UPOF_FMT22; |
736772ef | 604 | upaddr->upcs1 = UP_RTC|UP_GO|UP_IE; |
299d67ed | 605 | while (upaddr->upds & UPDS_PIP) |
736772ef | 606 | DELAY(25); |
eb891eaa | 607 | needie = 0; |
008c0481 | 608 | } |
736772ef BJ |
609 | um->um_tab.b_active = 0; |
610 | um->um_tab.b_errcnt = 0; | |
611 | um->um_tab.b_actf = dp->b_forw; | |
612 | dp->b_active = 0; | |
613 | dp->b_errcnt = 0; | |
614 | dp->b_actf = bp->av_forw; | |
615 | bp->b_resid = (-upaddr->upwc * sizeof(short)); | |
616 | iodone(bp); | |
617 | /* | |
618 | * If this unit has more work to do, | |
619 | * then start it up right away. | |
620 | */ | |
621 | if (dp->b_actf) | |
622 | if (upustart(ui)) | |
eb891eaa | 623 | needie = 0; |
008c0481 | 624 | } |
736772ef | 625 | as &= ~(1<<ui->ui_slave); |
8c58f40c BJ |
626 | /* |
627 | * Release unibus resources and flush data paths. | |
628 | */ | |
629 | ubadone(um); | |
736772ef BJ |
630 | doattn: |
631 | /* | |
632 | * Process other units which need attention. | |
633 | * For each unit which needs attention, call | |
634 | * the unit start routine to place the slave | |
635 | * on the controller device queue. | |
636 | */ | |
a6442a2f BJ |
637 | while (unit = ffs(as)) { |
638 | unit--; /* was 1 origin */ | |
639 | as &= ~(1<<unit); | |
640 | upaddr->upas = 1<<unit; | |
c10bcf0a | 641 | if (unit < UPIPUNITS && upustart(upip[sc21][unit])) |
a6442a2f BJ |
642 | needie = 0; |
643 | } | |
736772ef BJ |
644 | /* |
645 | * If the controller is not transferring, but | |
646 | * there are devices ready to transfer, start | |
647 | * the controller. | |
648 | */ | |
3f3a34c3 BJ |
649 | if (um->um_tab.b_actf && um->um_tab.b_active == 0) |
650 | if (upstart(um)) | |
eb891eaa | 651 | needie = 0; |
2a3b9a7f | 652 | if (needie) |
2601dfbd | 653 | upaddr->upcs1 = UP_IE; |
008c0481 BJ |
654 | } |
655 | ||
656 | upread(dev) | |
0801d37f | 657 | dev_t dev; |
008c0481 | 658 | { |
0801d37f | 659 | register int unit = minor(dev) >> 3; |
7e00c42b | 660 | |
0801d37f BJ |
661 | if (unit >= NUP) |
662 | u.u_error = ENXIO; | |
663 | else | |
664 | physio(upstrategy, &rupbuf[unit], dev, B_READ, minphys); | |
008c0481 BJ |
665 | } |
666 | ||
667 | upwrite(dev) | |
0801d37f | 668 | dev_t dev; |
008c0481 | 669 | { |
0801d37f | 670 | register int unit = minor(dev) >> 3; |
7e00c42b | 671 | |
0801d37f BJ |
672 | if (unit >= NUP) |
673 | u.u_error = ENXIO; | |
674 | else | |
675 | physio(upstrategy, &rupbuf[unit], dev, B_WRITE, minphys); | |
008c0481 BJ |
676 | } |
677 | ||
7bc8d985 BJ |
678 | /* |
679 | * Correct an ECC error, and restart the i/o to complete | |
680 | * the transfer if necessary. This is quite complicated because | |
681 | * the transfer may be going to an odd memory address base and/or | |
682 | * across a page boundary. | |
683 | */ | |
3f3a34c3 | 684 | upecc(ui) |
89bd2f01 | 685 | register struct uba_device *ui; |
008c0481 | 686 | { |
2601dfbd | 687 | register struct updevice *up = (struct updevice *)ui->ui_addr; |
3f3a34c3 | 688 | register struct buf *bp = uputab[ui->ui_unit].b_actf; |
89bd2f01 | 689 | register struct uba_ctlr *um = ui->ui_mi; |
3f3a34c3 BJ |
690 | register struct upst *st; |
691 | struct uba_regs *ubp = ui->ui_hd->uh_uba; | |
7bc8d985 | 692 | register int i; |
008c0481 | 693 | caddr_t addr; |
7bc8d985 | 694 | int reg, bit, byte, npf, mask, o, cmd, ubaddr; |
008c0481 BJ |
695 | int bn, cn, tn, sn; |
696 | ||
008c0481 | 697 | /* |
7bc8d985 BJ |
698 | * Npf is the number of sectors transferred before the sector |
699 | * containing the ECC error, and reg is the UBA register | |
700 | * mapping (the first part of) the transfer. | |
701 | * O is offset within a memory page of the first byte transferred. | |
008c0481 | 702 | */ |
7bc8d985 | 703 | npf = btop((up->upwc * sizeof(short)) + bp->b_bcount) - 1; |
b7333467 | 704 | reg = btop(um->um_ubinfo&0x3ffff) + npf; |
008c0481 | 705 | o = (int)bp->b_un.b_addr & PGOFSET; |
89bd2f01 | 706 | printf("up%d%c: soft ecc sn%d\n", dkunit(bp), |
0c48c799 | 707 | 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); |
008c0481 | 708 | mask = up->upec2; |
299d67ed | 709 | #ifdef UPECCDEBUG |
8c58f40c BJ |
710 | printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask, |
711 | up->upec1); | |
299d67ed | 712 | #endif |
7bc8d985 BJ |
713 | /* |
714 | * Flush the buffered data path, and compute the | |
715 | * byte and bit position of the error. The variable i | |
716 | * is the byte offset in the transfer, the variable byte | |
717 | * is the offset from a page boundary in main memory. | |
718 | */ | |
060afaf6 | 719 | ubapurge(um); |
7bc8d985 BJ |
720 | i = up->upec1 - 1; /* -1 makes 0 origin */ |
721 | bit = i&07; | |
722 | i = (i&~07)>>3; | |
008c0481 | 723 | byte = i + o; |
7bc8d985 BJ |
724 | /* |
725 | * Correct while possible bits remain of mask. Since mask | |
726 | * contains 11 bits, we continue while the bit offset is > -11. | |
727 | * Also watch out for end of this block and the end of the whole | |
728 | * transfer. | |
729 | */ | |
730 | while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { | |
731 | addr = ptob(ubp->uba_map[reg+btop(byte)].pg_pfnum)+ | |
732 | (byte & PGOFSET); | |
299d67ed | 733 | #ifdef UPECCDEBUG |
8c58f40c BJ |
734 | printf("addr %x map reg %x\n", |
735 | addr, *(int *)(&ubp->uba_map[reg+btop(byte)])); | |
736 | printf("old: %x, ", getmemc(addr)); | |
299d67ed | 737 | #endif |
7bc8d985 | 738 | putmemc(addr, getmemc(addr)^(mask<<bit)); |
299d67ed | 739 | #ifdef UPECCDEBUG |
8c58f40c | 740 | printf("new: %x\n", getmemc(addr)); |
299d67ed | 741 | #endif |
7bc8d985 BJ |
742 | byte++; |
743 | i++; | |
744 | bit -= 8; | |
008c0481 | 745 | } |
cc7ff771 | 746 | um->um_tab.b_active = 2; /* Either complete or continuing... */ |
008c0481 BJ |
747 | if (up->upwc == 0) |
748 | return (0); | |
7bc8d985 BJ |
749 | /* |
750 | * Have to continue the transfer... clear the drive, | |
751 | * and compute the position where the transfer is to continue. | |
752 | * We have completed npf+1 sectors of the transfer already; | |
753 | * restart at offset o of next sector (i.e. in UBA register reg+1). | |
754 | */ | |
2601dfbd BJ |
755 | #ifdef notdef |
756 | up->uper1 = 0; | |
757 | up->upcs1 |= UP_GO; | |
758 | #else | |
759 | up->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO; | |
008c0481 | 760 | bn = dkblock(bp); |
3f3a34c3 | 761 | st = &upst[ui->ui_type]; |
008c0481 | 762 | cn = bp->b_cylin; |
3f3a34c3 BJ |
763 | sn = bn%st->nspc + npf + 1; |
764 | tn = sn/st->nsect; | |
765 | sn %= st->nsect; | |
766 | cn += tn/st->ntrak; | |
767 | tn %= st->ntrak; | |
008c0481 | 768 | up->updc = cn; |
7bc8d985 BJ |
769 | up->upda = (tn << 8) | sn; |
770 | ubaddr = (int)ptob(reg+1) + o; | |
771 | up->upba = ubaddr; | |
772 | cmd = (ubaddr >> 8) & 0x300; | |
2601dfbd | 773 | cmd |= UP_IE|UP_GO|UP_RCOM; |
7bc8d985 | 774 | up->upcs1 = cmd; |
2601dfbd | 775 | #endif |
008c0481 BJ |
776 | return (1); |
777 | } | |
977c2848 BJ |
778 | |
779 | /* | |
780 | * Reset driver after UBA init. | |
781 | * Cancel software state of all pending transfers | |
782 | * and restart all units and the controller. | |
783 | */ | |
3f3a34c3 | 784 | upreset(uban) |
f6d201ff | 785 | int uban; |
977c2848 | 786 | { |
89bd2f01 BJ |
787 | register struct uba_ctlr *um; |
788 | register struct uba_device *ui; | |
3f3a34c3 BJ |
789 | register sc21, unit; |
790 | ||
a3cb8f60 | 791 | for (sc21 = 0; sc21 < NSC; sc21++) { |
7e00c42b BJ |
792 | if ((um = upminfo[sc21]) == 0 || um->um_ubanum != uban || |
793 | um->um_alive == 0) | |
3f3a34c3 | 794 | continue; |
f6d201ff | 795 | printf(" sc%d", sc21); |
3f3a34c3 BJ |
796 | um->um_tab.b_active = 0; |
797 | um->um_tab.b_actf = um->um_tab.b_actl = 0; | |
f6d201ff | 798 | up_softc[sc21].sc_recal = 0; |
cc7ff771 | 799 | up_softc[sc21].sc_wticks = 0; |
b7333467 BJ |
800 | if (um->um_ubinfo) { |
801 | printf("<%d>", (um->um_ubinfo>>28)&0xf); | |
0801d37f | 802 | ubadone(um); |
3f3a34c3 | 803 | } |
299d67ed | 804 | ((struct updevice *)(um->um_addr))->upcs2 = UPCS2_CLR; |
3f3a34c3 BJ |
805 | for (unit = 0; unit < NUP; unit++) { |
806 | if ((ui = updinfo[unit]) == 0) | |
807 | continue; | |
f6d201ff | 808 | if (ui->ui_alive == 0 || ui->ui_mi != um) |
3f3a34c3 BJ |
809 | continue; |
810 | uputab[unit].b_active = 0; | |
811 | (void) upustart(ui); | |
812 | } | |
813 | (void) upstart(um); | |
977c2848 | 814 | } |
977c2848 | 815 | } |
6a81870e BJ |
816 | |
817 | /* | |
818 | * Wake up every second and if an interrupt is pending | |
819 | * but nothing has happened increment a counter. | |
f6d201ff | 820 | * If nothing happens for 20 seconds, reset the UNIBUS |
6a81870e BJ |
821 | * and begin anew. |
822 | */ | |
823 | upwatch() | |
824 | { | |
89bd2f01 | 825 | register struct uba_ctlr *um; |
3f3a34c3 | 826 | register sc21, unit; |
7e00c42b | 827 | register struct up_softc *sc; |
6a81870e | 828 | |
7780575a | 829 | timeout(upwatch, (caddr_t)0, hz); |
a3cb8f60 | 830 | for (sc21 = 0; sc21 < NSC; sc21++) { |
3f3a34c3 | 831 | um = upminfo[sc21]; |
7e00c42b BJ |
832 | if (um == 0 || um->um_alive == 0) |
833 | continue; | |
834 | sc = &up_softc[sc21]; | |
3f3a34c3 BJ |
835 | if (um->um_tab.b_active == 0) { |
836 | for (unit = 0; unit < NUP; unit++) | |
2601dfbd BJ |
837 | if (uputab[unit].b_active && |
838 | updinfo[unit]->ui_mi == um) | |
3f3a34c3 | 839 | goto active; |
7e00c42b | 840 | sc->sc_wticks = 0; |
3f3a34c3 BJ |
841 | continue; |
842 | } | |
f6d201ff | 843 | active: |
7e00c42b BJ |
844 | sc->sc_wticks++; |
845 | if (sc->sc_wticks >= 20) { | |
846 | sc->sc_wticks = 0; | |
f6d201ff | 847 | printf("sc%d: lost interrupt\n", sc21); |
a3cb8f60 | 848 | ubareset(um->um_ubanum); |
3f3a34c3 | 849 | } |
6a81870e BJ |
850 | } |
851 | } | |
0ff318b2 BJ |
852 | |
853 | #define DBSIZE 20 | |
854 | ||
855 | updump(dev) | |
856 | dev_t dev; | |
857 | { | |
2601dfbd | 858 | struct updevice *upaddr; |
0ff318b2 | 859 | char *start; |
a0eab615 | 860 | int num, blk, unit; |
0ff318b2 | 861 | struct size *sizes; |
3f3a34c3 | 862 | register struct uba_regs *uba; |
89bd2f01 | 863 | register struct uba_device *ui; |
0ff318b2 | 864 | register short *rp; |
3f3a34c3 | 865 | struct upst *st; |
0ff318b2 | 866 | |
0ff318b2 | 867 | unit = minor(dev) >> 3; |
0c48c799 BJ |
868 | if (unit >= NUP) |
869 | return (ENXIO); | |
7e00c42b | 870 | #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) |
89bd2f01 | 871 | ui = phys(struct uba_device *, updinfo[unit]); |
0c48c799 BJ |
872 | if (ui->ui_alive == 0) |
873 | return (ENXIO); | |
3f3a34c3 | 874 | uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; |
89bd2f01 | 875 | ubainit(uba); |
2601dfbd | 876 | upaddr = (struct updevice *)ui->ui_physaddr; |
89bd2f01 | 877 | DELAY(2000000); |
3f3a34c3 BJ |
878 | num = maxfree; |
879 | start = 0; | |
0ff318b2 | 880 | upaddr->upcs2 = unit; |
89bd2f01 BJ |
881 | DELAY(100); |
882 | if ((upaddr->upcs1&UP_DVA) == 0) | |
883 | return (EFAULT); | |
299d67ed | 884 | if ((upaddr->upds & UPDS_VV) == 0) { |
2601dfbd BJ |
885 | upaddr->upcs1 = UP_DCLR|UP_GO; |
886 | upaddr->upcs1 = UP_PRESET|UP_GO; | |
299d67ed | 887 | upaddr->upof = UPOF_FMT22; |
0ff318b2 | 888 | } |
299d67ed | 889 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) |
0c48c799 | 890 | return (EFAULT); |
7e00c42b | 891 | st = &upst[ui->ui_type]; |
3f3a34c3 | 892 | sizes = phys(struct size *, st->sizes); |
0c48c799 BJ |
893 | if (dumplo < 0 || dumplo + num >= sizes[minor(dev)&07].nblocks) |
894 | return (EINVAL); | |
0ff318b2 BJ |
895 | while (num > 0) { |
896 | register struct pte *io; | |
897 | register int i; | |
898 | int cn, sn, tn; | |
899 | daddr_t bn; | |
900 | ||
901 | blk = num > DBSIZE ? DBSIZE : num; | |
3f3a34c3 | 902 | io = uba->uba_map; |
0ff318b2 | 903 | for (i = 0; i < blk; i++) |
89bd2f01 | 904 | *(int *)io++ = (btop(start)+i) | (1<<21) | UBAMR_MRV; |
0ff318b2 BJ |
905 | *(int *)io = 0; |
906 | bn = dumplo + btop(start); | |
71236e46 BJ |
907 | cn = bn/st->nspc + sizes[minor(dev)&07].cyloff; |
908 | sn = bn%st->nspc; | |
909 | tn = sn/st->nsect; | |
910 | sn = sn%st->nsect; | |
0ff318b2 BJ |
911 | upaddr->updc = cn; |
912 | rp = (short *) &upaddr->upda; | |
913 | *rp = (tn << 8) + sn; | |
914 | *--rp = 0; | |
915 | *--rp = -blk*NBPG / sizeof (short); | |
2601dfbd | 916 | *--rp = UP_GO|UP_WCOM; |
0ff318b2 BJ |
917 | do { |
918 | DELAY(25); | |
2601dfbd | 919 | } while ((upaddr->upcs1 & UP_RDY) == 0); |
299d67ed | 920 | if (upaddr->upds&UPDS_ERR) |
0c48c799 | 921 | return (EIO); |
0ff318b2 BJ |
922 | start += blk*NBPG; |
923 | num -= blk; | |
924 | } | |
0ff318b2 BJ |
925 | return (0); |
926 | } | |
63c35a63 | 927 | #endif |