Commit | Line | Data |
---|---|---|
de59ccc2 | 1 | /* up.c 4.53 82/05/27 */ |
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 | |
a1ef7a52 | 75 | }, upam_sizes[8] = { |
0cc9b5a9 BJ |
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 */ |
a1ef7a52 | 118 | 32, 16, 32*16, 1024, upam_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 | |
de59ccc2 | 468 | um->um_tab.b_active = 2; /* 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 | } | |
de59ccc2 | 500 | um->um_tab.b_active = 1; |
736772ef BJ |
501 | /* |
502 | * Get device and block structures, and a pointer | |
89bd2f01 | 503 | * to the uba_device for the drive. Select the drive. |
736772ef BJ |
504 | */ |
505 | dp = um->um_tab.b_actf; | |
506 | bp = dp->b_actf; | |
507 | ui = updinfo[dkunit(bp)]; | |
508 | dk_busy &= ~(1 << ui->ui_dk); | |
509 | if ((upaddr->upcs2&07) != ui->ui_slave) | |
3f3a34c3 | 510 | upaddr->upcs2 = ui->ui_slave; |
736772ef BJ |
511 | /* |
512 | * Check for and process errors on | |
513 | * either the drive or the controller. | |
514 | */ | |
299d67ed | 515 | if ((upaddr->upds&UPDS_ERR) || (upaddr->upcs1&UP_TRE)) { |
f88f8fdb | 516 | waitdry = 0; |
299d67ed | 517 | while ((upaddr->upds & UPDS_DRY) == 0) { |
f88f8fdb BJ |
518 | if (++waitdry > 512) |
519 | break; | |
520 | upwaitdry++; | |
521 | } | |
299d67ed | 522 | if (upaddr->uper1&UPER1_WLE) { |
736772ef BJ |
523 | /* |
524 | * Give up on write locked devices | |
525 | * immediately. | |
526 | */ | |
f6d201ff | 527 | printf("up%d: write locked\n", dkunit(bp)); |
736772ef BJ |
528 | bp->b_flags |= B_ERROR; |
529 | } else if (++um->um_tab.b_errcnt > 27) { | |
530 | /* | |
531 | * After 28 retries (16 without offset, and | |
532 | * 12 with offset positioning) give up. | |
533 | */ | |
f6d201ff BJ |
534 | harderr(bp, "up"); |
535 | printf("cs2=%b er1=%b er2=%b\n", | |
c84ff1f9 BJ |
536 | upaddr->upcs2, UPCS2_BITS, |
537 | upaddr->uper1, UPER1_BITS, | |
538 | upaddr->uper2, UPER2_BITS); | |
736772ef BJ |
539 | bp->b_flags |= B_ERROR; |
540 | } else { | |
541 | /* | |
542 | * Retriable error. | |
543 | * If a soft ecc, correct it (continuing | |
544 | * by returning if necessary. | |
545 | * Otherwise fall through and retry the transfer | |
546 | */ | |
547 | um->um_tab.b_active = 0; /* force retry */ | |
299d67ed | 548 | if ((upaddr->uper1&(UPER1_DCK|UPER1_ECH))==UPER1_DCK) |
2601dfbd BJ |
549 | if (upecc(ui)) |
550 | return; | |
736772ef BJ |
551 | } |
552 | /* | |
553 | * Clear drive error and, every eight attempts, | |
554 | * (starting with the fourth) | |
555 | * recalibrate to clear the slate. | |
556 | */ | |
557 | upaddr->upcs1 = UP_TRE|UP_IE|UP_DCLR|UP_GO; | |
558 | needie = 0; | |
fc4d0a69 | 559 | if ((um->um_tab.b_errcnt&07) == 4 && um->um_tab.b_active == 0) { |
736772ef | 560 | upaddr->upcs1 = UP_RECAL|UP_IE|UP_GO; |
a6442a2f BJ |
561 | sc->sc_recal = 0; |
562 | goto nextrecal; | |
736772ef BJ |
563 | } |
564 | } | |
565 | /* | |
a6442a2f BJ |
566 | * Advance recalibration finite state machine |
567 | * if recalibrate in progress, through | |
568 | * RECAL | |
569 | * SEEK | |
570 | * OFFSET (optional) | |
571 | * RETRY | |
736772ef | 572 | */ |
a6442a2f BJ |
573 | switch (sc->sc_recal) { |
574 | ||
575 | case 1: | |
576 | upaddr->updc = bp->b_cylin; | |
577 | upaddr->upcs1 = UP_SEEK|UP_IE|UP_GO; | |
578 | goto nextrecal; | |
579 | case 2: | |
580 | if (um->um_tab.b_errcnt < 16 || (bp->b_flags&B_READ) == 0) | |
581 | goto donerecal; | |
299d67ed | 582 | upaddr->upof = up_offset[um->um_tab.b_errcnt & 017] | UPOF_FMT22; |
a6442a2f BJ |
583 | upaddr->upcs1 = UP_IE|UP_OFFSET|UP_GO; |
584 | goto nextrecal; | |
585 | nextrecal: | |
586 | sc->sc_recal++; | |
587 | um->um_tab.b_active = 1; | |
588 | return; | |
589 | donerecal: | |
590 | case 3: | |
736772ef | 591 | sc->sc_recal = 0; |
a6442a2f BJ |
592 | um->um_tab.b_active = 0; |
593 | break; | |
736772ef BJ |
594 | } |
595 | /* | |
596 | * If still ``active'', then don't need any more retries. | |
597 | */ | |
598 | if (um->um_tab.b_active) { | |
599 | /* | |
600 | * If we were offset positioning, | |
601 | * return to centerline. | |
602 | */ | |
603 | if (um->um_tab.b_errcnt >= 16) { | |
299d67ed | 604 | upaddr->upof = UPOF_FMT22; |
736772ef | 605 | upaddr->upcs1 = UP_RTC|UP_GO|UP_IE; |
299d67ed | 606 | while (upaddr->upds & UPDS_PIP) |
736772ef | 607 | DELAY(25); |
eb891eaa | 608 | needie = 0; |
008c0481 | 609 | } |
736772ef BJ |
610 | um->um_tab.b_active = 0; |
611 | um->um_tab.b_errcnt = 0; | |
612 | um->um_tab.b_actf = dp->b_forw; | |
613 | dp->b_active = 0; | |
614 | dp->b_errcnt = 0; | |
615 | dp->b_actf = bp->av_forw; | |
616 | bp->b_resid = (-upaddr->upwc * sizeof(short)); | |
617 | iodone(bp); | |
618 | /* | |
619 | * If this unit has more work to do, | |
620 | * then start it up right away. | |
621 | */ | |
622 | if (dp->b_actf) | |
623 | if (upustart(ui)) | |
eb891eaa | 624 | needie = 0; |
008c0481 | 625 | } |
736772ef | 626 | as &= ~(1<<ui->ui_slave); |
8c58f40c BJ |
627 | /* |
628 | * Release unibus resources and flush data paths. | |
629 | */ | |
630 | ubadone(um); | |
736772ef BJ |
631 | doattn: |
632 | /* | |
633 | * Process other units which need attention. | |
634 | * For each unit which needs attention, call | |
635 | * the unit start routine to place the slave | |
636 | * on the controller device queue. | |
637 | */ | |
a6442a2f BJ |
638 | while (unit = ffs(as)) { |
639 | unit--; /* was 1 origin */ | |
640 | as &= ~(1<<unit); | |
641 | upaddr->upas = 1<<unit; | |
c10bcf0a | 642 | if (unit < UPIPUNITS && upustart(upip[sc21][unit])) |
a6442a2f BJ |
643 | needie = 0; |
644 | } | |
736772ef BJ |
645 | /* |
646 | * If the controller is not transferring, but | |
647 | * there are devices ready to transfer, start | |
648 | * the controller. | |
649 | */ | |
3f3a34c3 BJ |
650 | if (um->um_tab.b_actf && um->um_tab.b_active == 0) |
651 | if (upstart(um)) | |
eb891eaa | 652 | needie = 0; |
2a3b9a7f | 653 | if (needie) |
2601dfbd | 654 | upaddr->upcs1 = UP_IE; |
008c0481 BJ |
655 | } |
656 | ||
657 | upread(dev) | |
0801d37f | 658 | dev_t dev; |
008c0481 | 659 | { |
0801d37f | 660 | register int unit = minor(dev) >> 3; |
7e00c42b | 661 | |
0801d37f BJ |
662 | if (unit >= NUP) |
663 | u.u_error = ENXIO; | |
664 | else | |
665 | physio(upstrategy, &rupbuf[unit], dev, B_READ, minphys); | |
008c0481 BJ |
666 | } |
667 | ||
668 | upwrite(dev) | |
0801d37f | 669 | dev_t dev; |
008c0481 | 670 | { |
0801d37f | 671 | register int unit = minor(dev) >> 3; |
7e00c42b | 672 | |
0801d37f BJ |
673 | if (unit >= NUP) |
674 | u.u_error = ENXIO; | |
675 | else | |
676 | physio(upstrategy, &rupbuf[unit], dev, B_WRITE, minphys); | |
008c0481 BJ |
677 | } |
678 | ||
7bc8d985 BJ |
679 | /* |
680 | * Correct an ECC error, and restart the i/o to complete | |
681 | * the transfer if necessary. This is quite complicated because | |
682 | * the transfer may be going to an odd memory address base and/or | |
683 | * across a page boundary. | |
684 | */ | |
3f3a34c3 | 685 | upecc(ui) |
89bd2f01 | 686 | register struct uba_device *ui; |
008c0481 | 687 | { |
2601dfbd | 688 | register struct updevice *up = (struct updevice *)ui->ui_addr; |
3f3a34c3 | 689 | register struct buf *bp = uputab[ui->ui_unit].b_actf; |
89bd2f01 | 690 | register struct uba_ctlr *um = ui->ui_mi; |
3f3a34c3 BJ |
691 | register struct upst *st; |
692 | struct uba_regs *ubp = ui->ui_hd->uh_uba; | |
7bc8d985 | 693 | register int i; |
008c0481 | 694 | caddr_t addr; |
7bc8d985 | 695 | int reg, bit, byte, npf, mask, o, cmd, ubaddr; |
008c0481 BJ |
696 | int bn, cn, tn, sn; |
697 | ||
008c0481 | 698 | /* |
7bc8d985 BJ |
699 | * Npf is the number of sectors transferred before the sector |
700 | * containing the ECC error, and reg is the UBA register | |
701 | * mapping (the first part of) the transfer. | |
702 | * O is offset within a memory page of the first byte transferred. | |
008c0481 | 703 | */ |
7bc8d985 | 704 | npf = btop((up->upwc * sizeof(short)) + bp->b_bcount) - 1; |
b7333467 | 705 | reg = btop(um->um_ubinfo&0x3ffff) + npf; |
008c0481 | 706 | o = (int)bp->b_un.b_addr & PGOFSET; |
89bd2f01 | 707 | printf("up%d%c: soft ecc sn%d\n", dkunit(bp), |
0c48c799 | 708 | 'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf); |
008c0481 | 709 | mask = up->upec2; |
299d67ed | 710 | #ifdef UPECCDEBUG |
8c58f40c BJ |
711 | printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask, |
712 | up->upec1); | |
299d67ed | 713 | #endif |
7bc8d985 BJ |
714 | /* |
715 | * Flush the buffered data path, and compute the | |
716 | * byte and bit position of the error. The variable i | |
717 | * is the byte offset in the transfer, the variable byte | |
718 | * is the offset from a page boundary in main memory. | |
719 | */ | |
060afaf6 | 720 | ubapurge(um); |
7bc8d985 BJ |
721 | i = up->upec1 - 1; /* -1 makes 0 origin */ |
722 | bit = i&07; | |
723 | i = (i&~07)>>3; | |
008c0481 | 724 | byte = i + o; |
7bc8d985 BJ |
725 | /* |
726 | * Correct while possible bits remain of mask. Since mask | |
727 | * contains 11 bits, we continue while the bit offset is > -11. | |
728 | * Also watch out for end of this block and the end of the whole | |
729 | * transfer. | |
730 | */ | |
731 | while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) { | |
732 | addr = ptob(ubp->uba_map[reg+btop(byte)].pg_pfnum)+ | |
733 | (byte & PGOFSET); | |
299d67ed | 734 | #ifdef UPECCDEBUG |
8c58f40c BJ |
735 | printf("addr %x map reg %x\n", |
736 | addr, *(int *)(&ubp->uba_map[reg+btop(byte)])); | |
737 | printf("old: %x, ", getmemc(addr)); | |
299d67ed | 738 | #endif |
7bc8d985 | 739 | putmemc(addr, getmemc(addr)^(mask<<bit)); |
299d67ed | 740 | #ifdef UPECCDEBUG |
8c58f40c | 741 | printf("new: %x\n", getmemc(addr)); |
299d67ed | 742 | #endif |
7bc8d985 BJ |
743 | byte++; |
744 | i++; | |
745 | bit -= 8; | |
008c0481 | 746 | } |
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; |
de59ccc2 | 774 | um->um_tab.b_active = 2; /* continuing transfer ... */ |
7bc8d985 | 775 | up->upcs1 = cmd; |
2601dfbd | 776 | #endif |
008c0481 BJ |
777 | return (1); |
778 | } | |
977c2848 BJ |
779 | |
780 | /* | |
781 | * Reset driver after UBA init. | |
782 | * Cancel software state of all pending transfers | |
783 | * and restart all units and the controller. | |
784 | */ | |
3f3a34c3 | 785 | upreset(uban) |
f6d201ff | 786 | int uban; |
977c2848 | 787 | { |
89bd2f01 BJ |
788 | register struct uba_ctlr *um; |
789 | register struct uba_device *ui; | |
3f3a34c3 BJ |
790 | register sc21, unit; |
791 | ||
a3cb8f60 | 792 | for (sc21 = 0; sc21 < NSC; sc21++) { |
7e00c42b BJ |
793 | if ((um = upminfo[sc21]) == 0 || um->um_ubanum != uban || |
794 | um->um_alive == 0) | |
3f3a34c3 | 795 | continue; |
f6d201ff | 796 | printf(" sc%d", sc21); |
3f3a34c3 BJ |
797 | um->um_tab.b_active = 0; |
798 | um->um_tab.b_actf = um->um_tab.b_actl = 0; | |
f6d201ff | 799 | up_softc[sc21].sc_recal = 0; |
cc7ff771 | 800 | up_softc[sc21].sc_wticks = 0; |
b7333467 BJ |
801 | if (um->um_ubinfo) { |
802 | printf("<%d>", (um->um_ubinfo>>28)&0xf); | |
0801d37f | 803 | ubadone(um); |
3f3a34c3 | 804 | } |
299d67ed | 805 | ((struct updevice *)(um->um_addr))->upcs2 = UPCS2_CLR; |
3f3a34c3 BJ |
806 | for (unit = 0; unit < NUP; unit++) { |
807 | if ((ui = updinfo[unit]) == 0) | |
808 | continue; | |
f6d201ff | 809 | if (ui->ui_alive == 0 || ui->ui_mi != um) |
3f3a34c3 BJ |
810 | continue; |
811 | uputab[unit].b_active = 0; | |
812 | (void) upustart(ui); | |
813 | } | |
814 | (void) upstart(um); | |
977c2848 | 815 | } |
977c2848 | 816 | } |
6a81870e BJ |
817 | |
818 | /* | |
819 | * Wake up every second and if an interrupt is pending | |
820 | * but nothing has happened increment a counter. | |
f6d201ff | 821 | * If nothing happens for 20 seconds, reset the UNIBUS |
6a81870e BJ |
822 | * and begin anew. |
823 | */ | |
824 | upwatch() | |
825 | { | |
89bd2f01 | 826 | register struct uba_ctlr *um; |
3f3a34c3 | 827 | register sc21, unit; |
7e00c42b | 828 | register struct up_softc *sc; |
6a81870e | 829 | |
7780575a | 830 | timeout(upwatch, (caddr_t)0, hz); |
a3cb8f60 | 831 | for (sc21 = 0; sc21 < NSC; sc21++) { |
3f3a34c3 | 832 | um = upminfo[sc21]; |
7e00c42b BJ |
833 | if (um == 0 || um->um_alive == 0) |
834 | continue; | |
835 | sc = &up_softc[sc21]; | |
3f3a34c3 BJ |
836 | if (um->um_tab.b_active == 0) { |
837 | for (unit = 0; unit < NUP; unit++) | |
2601dfbd BJ |
838 | if (uputab[unit].b_active && |
839 | updinfo[unit]->ui_mi == um) | |
3f3a34c3 | 840 | goto active; |
7e00c42b | 841 | sc->sc_wticks = 0; |
3f3a34c3 BJ |
842 | continue; |
843 | } | |
f6d201ff | 844 | active: |
7e00c42b BJ |
845 | sc->sc_wticks++; |
846 | if (sc->sc_wticks >= 20) { | |
847 | sc->sc_wticks = 0; | |
f6d201ff | 848 | printf("sc%d: lost interrupt\n", sc21); |
a3cb8f60 | 849 | ubareset(um->um_ubanum); |
3f3a34c3 | 850 | } |
6a81870e BJ |
851 | } |
852 | } | |
0ff318b2 BJ |
853 | |
854 | #define DBSIZE 20 | |
855 | ||
856 | updump(dev) | |
857 | dev_t dev; | |
858 | { | |
2601dfbd | 859 | struct updevice *upaddr; |
0ff318b2 | 860 | char *start; |
a0eab615 | 861 | int num, blk, unit; |
0ff318b2 | 862 | struct size *sizes; |
3f3a34c3 | 863 | register struct uba_regs *uba; |
89bd2f01 | 864 | register struct uba_device *ui; |
0ff318b2 | 865 | register short *rp; |
3f3a34c3 | 866 | struct upst *st; |
cd8ce595 | 867 | register int retry; |
0ff318b2 | 868 | |
0ff318b2 | 869 | unit = minor(dev) >> 3; |
0c48c799 BJ |
870 | if (unit >= NUP) |
871 | return (ENXIO); | |
7e00c42b | 872 | #define phys(cast, addr) ((cast)((int)addr & 0x7fffffff)) |
89bd2f01 | 873 | ui = phys(struct uba_device *, updinfo[unit]); |
0c48c799 BJ |
874 | if (ui->ui_alive == 0) |
875 | return (ENXIO); | |
3f3a34c3 | 876 | uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; |
89bd2f01 | 877 | ubainit(uba); |
2601dfbd | 878 | upaddr = (struct updevice *)ui->ui_physaddr; |
cd8ce595 | 879 | DELAY(5000000); |
3f3a34c3 | 880 | num = maxfree; |
0ff318b2 | 881 | upaddr->upcs2 = unit; |
89bd2f01 | 882 | DELAY(100); |
cd8ce595 SL |
883 | upaddr->upcs1 = UP_DCLR|UP_GO; |
884 | upaddr->upcs1 = UP_PRESET|UP_GO; | |
885 | upaddr->upof = UPOF_FMT22; | |
886 | retry = 0; | |
887 | do { | |
888 | DELAY(25); | |
889 | if (++retry > 527) | |
890 | break; | |
0599cbf1 | 891 | } while ((upaddr->upds & UP_RDY) == 0); |
299d67ed | 892 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) |
0c48c799 | 893 | return (EFAULT); |
cd8ce595 | 894 | start = 0; |
7e00c42b | 895 | st = &upst[ui->ui_type]; |
3f3a34c3 | 896 | sizes = phys(struct size *, st->sizes); |
0c48c799 BJ |
897 | if (dumplo < 0 || dumplo + num >= sizes[minor(dev)&07].nblocks) |
898 | return (EINVAL); | |
0ff318b2 BJ |
899 | while (num > 0) { |
900 | register struct pte *io; | |
901 | register int i; | |
902 | int cn, sn, tn; | |
903 | daddr_t bn; | |
904 | ||
905 | blk = num > DBSIZE ? DBSIZE : num; | |
3f3a34c3 | 906 | io = uba->uba_map; |
0ff318b2 | 907 | for (i = 0; i < blk; i++) |
89bd2f01 | 908 | *(int *)io++ = (btop(start)+i) | (1<<21) | UBAMR_MRV; |
0ff318b2 BJ |
909 | *(int *)io = 0; |
910 | bn = dumplo + btop(start); | |
71236e46 BJ |
911 | cn = bn/st->nspc + sizes[minor(dev)&07].cyloff; |
912 | sn = bn%st->nspc; | |
913 | tn = sn/st->nsect; | |
914 | sn = sn%st->nsect; | |
0ff318b2 BJ |
915 | upaddr->updc = cn; |
916 | rp = (short *) &upaddr->upda; | |
917 | *rp = (tn << 8) + sn; | |
918 | *--rp = 0; | |
919 | *--rp = -blk*NBPG / sizeof (short); | |
2601dfbd | 920 | *--rp = UP_GO|UP_WCOM; |
cd8ce595 | 921 | retry = 0; |
0ff318b2 BJ |
922 | do { |
923 | DELAY(25); | |
cd8ce595 SL |
924 | if (++retry > 527) |
925 | break; | |
2601dfbd | 926 | } while ((upaddr->upcs1 & UP_RDY) == 0); |
cd8ce595 | 927 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { |
0599cbf1 | 928 | printf("up%d: not ready", unit); |
cd8ce595 SL |
929 | if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) { |
930 | printf("\n"); | |
931 | return (EIO); | |
932 | } | |
933 | printf(" (flakey)\n"); | |
934 | } | |
299d67ed | 935 | if (upaddr->upds&UPDS_ERR) |
0c48c799 | 936 | return (EIO); |
0ff318b2 BJ |
937 | start += blk*NBPG; |
938 | num -= blk; | |
939 | } | |
0ff318b2 BJ |
940 | return (0); |
941 | } | |
63c35a63 | 942 | #endif |