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