Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
a4a97100 | 2 | * Copyright (c) 1982 Regents of the University of California. |
da7c5cc6 KM |
3 | * All rights reserved. The Berkeley software License Agreement |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
d8bf99c8 | 6 | * @(#)mba.c 7.4 (Berkeley) %G% |
da7c5cc6 | 7 | */ |
b81fd3e8 | 8 | |
443c8066 BJ |
9 | #include "mba.h" |
10 | #if NMBA > 0 | |
b81fd3e8 | 11 | /* |
d565635a | 12 | * Massbus driver, arbitrates a massbus among attached devices. |
b81fd3e8 | 13 | */ |
c18e27ed | 14 | #include "machine/pte.h" |
961945a8 | 15 | |
969e52ef JB |
16 | #include "param.h" |
17 | #include "systm.h" | |
a4a97100 | 18 | #include "dkstat.h" |
969e52ef JB |
19 | #include "buf.h" |
20 | #include "conf.h" | |
969e52ef JB |
21 | #include "user.h" |
22 | #include "proc.h" | |
23 | #include "map.h" | |
c895c266 | 24 | #include "../vax/mtpr.h" |
969e52ef | 25 | #include "vm.h" |
b5ad10c3 | 26 | |
969e52ef JB |
27 | #include "mbareg.h" |
28 | #include "mbavar.h" | |
c895c266 | 29 | |
a495f8fb MK |
30 | /* mbunit should be the same as hpunit, etc.! */ |
31 | #define mbunit(dev) (minor(dev) >> 3) | |
32 | ||
d565635a | 33 | char mbsr_bits[] = MBSR_BITS; |
b5ad10c3 | 34 | /* |
b81fd3e8 | 35 | * Start activity on a massbus device. |
89bd2f01 | 36 | * We are given the device's mba_device structure and activate |
b81fd3e8 BJ |
37 | * the device via the unit start routine. The unit start |
38 | * routine may indicate that it is finished (e.g. if the operation | |
39 | * was a ``sense'' on a tape drive), that the (multi-ported) unit | |
40 | * is busy (we will get an interrupt later), that it started the | |
41 | * unit (e.g. for a non-data transfer operation), or that it has | |
42 | * set up a data transfer operation and we should start the massbus adaptor. | |
b5ad10c3 | 43 | */ |
b81fd3e8 | 44 | mbustart(mi) |
89bd2f01 | 45 | register struct mba_device *mi; |
b81fd3e8 | 46 | { |
b81fd3e8 BJ |
47 | register struct buf *bp; /* i/o operation at head of queue */ |
48 | register struct mba_hd *mhp; /* header for mba device is on */ | |
49 | ||
b81fd3e8 BJ |
50 | loop: |
51 | /* | |
52 | * Get the first thing to do off device queue. | |
53 | */ | |
54 | bp = mi->mi_tab.b_actf; | |
55 | if (bp == NULL) | |
56 | return; | |
b81fd3e8 BJ |
57 | /* |
58 | * Let the drivers unit start routine have at it | |
59 | * and then process the request further, per its instructions. | |
60 | */ | |
61 | switch ((*mi->mi_driver->md_ustart)(mi)) { | |
62 | ||
63 | case MBU_NEXT: /* request is complete (e.g. ``sense'') */ | |
b81fd3e8 | 64 | mi->mi_tab.b_active = 0; |
cda4cdd4 | 65 | mi->mi_tab.b_errcnt = 0; |
b81fd3e8 | 66 | mi->mi_tab.b_actf = bp->av_forw; |
a4a97100 | 67 | biodone(bp); |
b81fd3e8 BJ |
68 | goto loop; |
69 | ||
70 | case MBU_DODATA: /* all ready to do data transfer */ | |
b81fd3e8 | 71 | /* |
89bd2f01 | 72 | * Queue the device mba_device structure on the massbus |
b81fd3e8 BJ |
73 | * mba_hd structure for processing as soon as the |
74 | * data path is available. | |
75 | */ | |
76 | mhp = mi->mi_hd; | |
77 | mi->mi_forw = NULL; | |
78 | if (mhp->mh_actf == NULL) | |
79 | mhp->mh_actf = mi; | |
80 | else | |
81 | mhp->mh_actl->mi_forw = mi; | |
82 | mhp->mh_actl = mi; | |
83 | /* | |
84 | * If data path is idle, start transfer now. | |
85 | * In any case the device is ``active'' waiting for the | |
86 | * data to transfer. | |
87 | */ | |
3dbaa9da | 88 | mi->mi_tab.b_active = 1; |
b81fd3e8 BJ |
89 | if (mhp->mh_active == 0) |
90 | mbstart(mhp); | |
b81fd3e8 BJ |
91 | return; |
92 | ||
93 | case MBU_STARTED: /* driver started a non-data transfer */ | |
b81fd3e8 BJ |
94 | /* |
95 | * Mark device busy during non-data transfer | |
96 | * and count this as a ``seek'' on the device. | |
97 | */ | |
fc4d0a69 | 98 | if (mi->mi_dk >= 0) { |
b81fd3e8 | 99 | dk_seek[mi->mi_dk]++; |
fc4d0a69 BJ |
100 | dk_busy |= (1 << mi->mi_dk); |
101 | } | |
b81fd3e8 BJ |
102 | mi->mi_tab.b_active = 1; |
103 | return; | |
104 | ||
105 | case MBU_BUSY: /* dual port drive busy */ | |
b81fd3e8 BJ |
106 | /* |
107 | * We mark the device structure so that when an | |
108 | * interrupt occurs we will know to restart the unit. | |
109 | */ | |
110 | mi->mi_tab.b_flags |= B_BUSY; | |
111 | return; | |
112 | ||
113 | default: | |
114 | panic("mbustart"); | |
115 | } | |
e1e57888 | 116 | } |
b81fd3e8 BJ |
117 | |
118 | /* | |
119 | * Start an i/o operation on the massbus specified by the argument. | |
120 | * We peel the first operation off its queue and insure that the drive | |
121 | * is present and on-line. We then use the drivers start routine | |
122 | * (if any) to prepare the drive, setup the massbus map for the transfer | |
123 | * and start the transfer. | |
124 | */ | |
125 | mbstart(mhp) | |
126 | register struct mba_hd *mhp; | |
127 | { | |
89bd2f01 | 128 | register struct mba_device *mi; |
b81fd3e8 | 129 | struct buf *bp; |
b81fd3e8 | 130 | register struct mba_regs *mbp; |
7bd5c7e4 | 131 | register int com; |
a4a97100 | 132 | extern int cold; |
b81fd3e8 | 133 | |
b81fd3e8 BJ |
134 | loop: |
135 | /* | |
136 | * Look for an operation at the front of the queue. | |
137 | */ | |
cda4cdd4 | 138 | if ((mi = mhp->mh_actf) == NULL) { |
b81fd3e8 | 139 | return; |
cda4cdd4 | 140 | } |
b81fd3e8 | 141 | if ((bp = mi->mi_tab.b_actf) == NULL) { |
b81fd3e8 BJ |
142 | mhp->mh_actf = mi->mi_forw; |
143 | goto loop; | |
144 | } | |
145 | /* | |
146 | * If this device isn't present and on-line, then | |
147 | * we screwed up, and can't really do the operation. | |
64614526 BJ |
148 | * Only check for non-tapes because tape drivers check |
149 | * ONLINE themselves and because TU78 registers are | |
150 | * different. | |
a4a97100 MK |
151 | * No complaints during autoconfiguration, |
152 | * when we try to read disk labels from anything on line. | |
b81fd3e8 | 153 | */ |
0d7a9a27 | 154 | if (((com = mi->mi_drv->mbd_dt) & MBDT_TAP) == 0) |
d565635a | 155 | if ((mi->mi_drv->mbd_ds & MBDS_DREADY) != MBDS_DREADY) { |
a4a97100 MK |
156 | if (!cold) { |
157 | if ((com & MBDT_TYPE) == 0) { | |
0d7a9a27 SL |
158 | mi->mi_alive = 0; |
159 | printf("%s%d: nonexistent\n", mi->mi_driver->md_dname, | |
a495f8fb | 160 | mbunit(bp->b_dev)); |
a4a97100 | 161 | } else |
0d7a9a27 | 162 | printf("%s%d: not ready\n", mi->mi_driver->md_dname, |
a495f8fb | 163 | mbunit(bp->b_dev)); |
a4a97100 | 164 | } |
b81fd3e8 | 165 | mi->mi_tab.b_actf = bp->av_forw; |
3dbaa9da BJ |
166 | mi->mi_tab.b_errcnt = 0; |
167 | mi->mi_tab.b_active = 0; | |
b81fd3e8 | 168 | bp->b_flags |= B_ERROR; |
a4a97100 | 169 | biodone(bp); |
b81fd3e8 BJ |
170 | goto loop; |
171 | } | |
172 | /* | |
173 | * We can do the operation; mark the massbus active | |
174 | * and let the device start routine setup any necessary | |
175 | * device state for the transfer (e.g. desired cylinder, etc | |
176 | * on disks). | |
177 | */ | |
178 | mhp->mh_active = 1; | |
3e3f9c04 MK |
179 | if (mi->mi_driver->md_start == (int (*)())0 || |
180 | (com = (*mi->mi_driver->md_start)(mi)) == 0) | |
7bd5c7e4 | 181 | com = (bp->b_flags & B_READ) ? MB_RCOM|MB_GO : MB_WCOM|MB_GO; |
b81fd3e8 BJ |
182 | |
183 | /* | |
184 | * Setup the massbus control and map registers and start | |
185 | * the transfer. | |
186 | */ | |
b81fd3e8 BJ |
187 | mbp = mi->mi_mba; |
188 | mbp->mba_sr = -1; /* conservative */ | |
c0bb0291 | 189 | if (bp->b_bcount >= 0) { |
3e3f9c04 MK |
190 | mbp->mba_var = mbasetup(mi) + mi->mi_tab.b_bdone; |
191 | mbp->mba_bcr = -(bp->b_bcount - mi->mi_tab.b_bdone); | |
c0bb0291 | 192 | } else { |
3e3f9c04 MK |
193 | mbp->mba_var = mbasetup(mi) - bp->b_bcount - mi->mi_tab.b_bdone - 1; |
194 | mbp->mba_bcr = bp->b_bcount + mi->mi_tab.b_bdone; | |
c0bb0291 | 195 | } |
7bd5c7e4 | 196 | mi->mi_drv->mbd_cs1 = com; |
b81fd3e8 BJ |
197 | if (mi->mi_dk >= 0) { |
198 | dk_busy |= 1 << mi->mi_dk; | |
199 | dk_xfer[mi->mi_dk]++; | |
c0bb0291 KM |
200 | if (bp->b_bcount >= 0) |
201 | dk_wds[mi->mi_dk] += bp->b_bcount >> 6; | |
202 | else | |
203 | dk_wds[mi->mi_dk] += -(bp->b_bcount) >> 6; | |
b81fd3e8 BJ |
204 | } |
205 | } | |
b5ad10c3 | 206 | |
b81fd3e8 BJ |
207 | /* |
208 | * Take an interrupt off of massbus mbanum, | |
209 | * and dispatch to drivers as appropriate. | |
210 | */ | |
211 | mbintr(mbanum) | |
212 | int mbanum; | |
213 | { | |
214 | register struct mba_hd *mhp = &mba_hd[mbanum]; | |
215 | register struct mba_regs *mbp = mhp->mh_mba; | |
89bd2f01 | 216 | register struct mba_device *mi; |
80e7c811 | 217 | register struct buf *bp; |
b81fd3e8 | 218 | register int drive; |
cda4cdd4 | 219 | int mbasr, as; |
0d7a9a27 | 220 | extern struct mba_device *mbaconfig(); |
b81fd3e8 BJ |
221 | |
222 | /* | |
223 | * Read out the massbus status register | |
224 | * and attention status register and clear | |
225 | * the bits in same by writing them back. | |
226 | */ | |
cda4cdd4 BJ |
227 | mbasr = mbp->mba_sr; |
228 | mbp->mba_sr = mbasr; | |
c9e9b65b | 229 | #if VAX750 |
d565635a | 230 | if (mbasr&MBSR_CBHUNG) { |
16e4017f BJ |
231 | printf("mba%d: control bus hung\n", mbanum); |
232 | panic("cbhung"); | |
233 | } | |
c9e9b65b | 234 | #endif |
b81fd3e8 | 235 | /* note: the mbd_as register is shared between drives */ |
cda4cdd4 | 236 | as = mbp->mba_drv[0].mbd_as & 0xff; |
b81fd3e8 | 237 | mbp->mba_drv[0].mbd_as = as; |
b81fd3e8 | 238 | |
b81fd3e8 BJ |
239 | /* |
240 | * If the mba was active, process the data transfer | |
241 | * complete interrupt; otherwise just process units which | |
242 | * are now finished. | |
243 | */ | |
244 | if (mhp->mh_active) { | |
b81fd3e8 BJ |
245 | /* |
246 | * Clear attention status for drive whose data | |
d565635a BJ |
247 | * transfer related operation completed, |
248 | * and give the dtint driver | |
b81fd3e8 BJ |
249 | * routine a chance to say what is next. |
250 | */ | |
251 | mi = mhp->mh_actf; | |
252 | as &= ~(1 << mi->mi_drive); | |
253 | dk_busy &= ~(1 << mi->mi_dk); | |
254 | bp = mi->mi_tab.b_actf; | |
d565635a | 255 | switch ((*mi->mi_driver->md_dtint)(mi, mbasr)) { |
b81fd3e8 BJ |
256 | |
257 | case MBD_DONE: /* all done, for better or worse */ | |
b81fd3e8 BJ |
258 | /* |
259 | * Flush request from drive queue. | |
260 | */ | |
261 | mi->mi_tab.b_errcnt = 0; | |
262 | mi->mi_tab.b_actf = bp->av_forw; | |
a4a97100 | 263 | biodone(bp); |
b81fd3e8 BJ |
264 | /* fall into... */ |
265 | case MBD_RETRY: /* attempt the operation again */ | |
b81fd3e8 BJ |
266 | /* |
267 | * Dequeue data transfer from massbus queue; | |
268 | * if there is still a i/o request on the device | |
269 | * queue then start the next operation on the device. | |
270 | * (Common code for DONE and RETRY). | |
271 | */ | |
272 | mhp->mh_active = 0; | |
273 | mi->mi_tab.b_active = 0; | |
274 | mhp->mh_actf = mi->mi_forw; | |
275 | if (mi->mi_tab.b_actf) | |
276 | mbustart(mi); | |
277 | break; | |
278 | ||
5c93d6ba MK |
279 | case MBD_REPOSITION: /* driver started repositioning */ |
280 | /* | |
281 | * Drive is repositioning, not doing data transfer. | |
282 | * Free controller, but don't have to restart drive. | |
283 | */ | |
284 | mhp->mh_active = 0; | |
285 | mhp->mh_actf = mi->mi_forw; | |
286 | break; | |
287 | ||
288 | case MBD_RESTARTED: /* driver restarted op (ecc, e.g.) */ | |
b81fd3e8 | 289 | /* |
3dbaa9da | 290 | * Note that mhp->mh_active is still on. |
b81fd3e8 BJ |
291 | */ |
292 | break; | |
293 | ||
294 | default: | |
c9e9b65b | 295 | panic("mbintr"); |
b81fd3e8 | 296 | } |
b81fd3e8 | 297 | } |
b81fd3e8 BJ |
298 | /* |
299 | * Service drives which require attention | |
300 | * after non-data-transfer operations. | |
301 | */ | |
8011f5df | 302 | while (drive = ffs((long)as)) { |
cda4cdd4 BJ |
303 | drive--; /* was 1 origin */ |
304 | as &= ~(1 << drive); | |
89bd2f01 | 305 | mi = mhp->mh_mbip[drive]; |
0d7a9a27 SL |
306 | if (mi == NULL || mi->mi_alive == 0) { |
307 | struct mba_device fnd; | |
0d7a9a27 SL |
308 | struct mba_drv *mbd = &mhp->mh_mba->mba_drv[drive]; |
309 | int dt = mbd->mbd_dt & 0xffff; | |
310 | ||
311 | if (dt == 0 || dt == MBDT_MOH) | |
312 | continue; | |
313 | fnd.mi_mba = mhp->mh_mba; | |
314 | fnd.mi_mbanum = mbanum; | |
315 | fnd.mi_drive = drive; | |
316 | if ((mi = mbaconfig(&fnd, dt)) == NULL) | |
317 | continue; | |
bc1b7985 SL |
318 | /* |
319 | * If a tape, poke the slave attach routines. | |
320 | * Otherwise, could be a disk which we want | |
321 | * to swap on, so make a pass over the swap | |
322 | * configuration table in case the size of | |
323 | * the swap area must be determined by drive type. | |
324 | */ | |
325 | if (dt & MBDT_TAP) | |
326 | mbaddtape(mi, drive); | |
327 | else | |
328 | swapconf(); | |
0d7a9a27 | 329 | } |
cda4cdd4 | 330 | /* |
89bd2f01 | 331 | * If driver has a handler for non-data transfer |
d565635a | 332 | * interrupts, give it a chance to tell us what to do. |
cda4cdd4 | 333 | */ |
cda4cdd4 | 334 | if (mi->mi_driver->md_ndint) { |
cda4cdd4 | 335 | switch ((*mi->mi_driver->md_ndint)(mi)) { |
b81fd3e8 | 336 | |
d565635a | 337 | case MBN_DONE: /* operation completed */ |
0d7a9a27 | 338 | mi->mi_tab.b_active = 0; |
cda4cdd4 | 339 | mi->mi_tab.b_errcnt = 0; |
89bd2f01 | 340 | bp = mi->mi_tab.b_actf; |
cda4cdd4 | 341 | mi->mi_tab.b_actf = bp->av_forw; |
a4a97100 | 342 | biodone(bp); |
d565635a BJ |
343 | /* fall into common code */ |
344 | case MBN_RETRY: /* operation continues */ | |
cda4cdd4 BJ |
345 | if (mi->mi_tab.b_actf) |
346 | mbustart(mi); | |
347 | break; | |
d565635a | 348 | case MBN_SKIP: /* ignore unsol. interrupt */ |
89bd2f01 | 349 | break; |
cda4cdd4 BJ |
350 | default: |
351 | panic("mbintr"); | |
352 | } | |
353 | } else | |
d565635a BJ |
354 | /* |
355 | * If there is no non-data transfer interrupt | |
356 | * routine, then we should just | |
357 | * restart the unit, leading to a mbstart() soon. | |
358 | */ | |
cda4cdd4 BJ |
359 | mbustart(mi); |
360 | } | |
b81fd3e8 BJ |
361 | /* |
362 | * If there is an operation available and | |
363 | * the massbus isn't active, get it going. | |
364 | */ | |
365 | if (mhp->mh_actf && !mhp->mh_active) | |
366 | mbstart(mhp); | |
d565635a | 367 | /* THHHHATS all folks... */ |
b81fd3e8 BJ |
368 | } |
369 | ||
bc1b7985 SL |
370 | /* |
371 | * For autoconfig'ng tape drives on the fly. | |
372 | */ | |
bc1b7985 SL |
373 | mbaddtape(mi, drive) |
374 | struct mba_device *mi; | |
375 | int drive; | |
376 | { | |
377 | register struct mba_slave *ms; | |
378 | ||
379 | for (ms = mbsinit; ms->ms_driver; ms++) | |
380 | if (ms->ms_driver == mi->mi_driver && ms->ms_alive == 0 && | |
381 | (ms->ms_ctlr == mi->mi_unit || | |
382 | ms->ms_ctlr == '?')) { | |
383 | if ((*ms->ms_driver->md_slave)(mi, ms, drive)) { | |
384 | printf("%s%d at %s%d slave %d\n", | |
385 | ms->ms_driver->md_sname, | |
386 | ms->ms_unit, | |
387 | mi->mi_driver->md_dname, | |
388 | mi->mi_unit, | |
389 | ms->ms_slave); | |
390 | ms->ms_alive = 1; | |
391 | ms->ms_ctlr = mi->mi_unit; | |
392 | } | |
393 | } | |
394 | } | |
395 | ||
b81fd3e8 BJ |
396 | /* |
397 | * Setup the mapping registers for a transfer. | |
398 | */ | |
399 | mbasetup(mi) | |
89bd2f01 | 400 | register struct mba_device *mi; |
b5ad10c3 | 401 | { |
b81fd3e8 BJ |
402 | register struct mba_regs *mbap = mi->mi_mba; |
403 | struct buf *bp = mi->mi_tab.b_actf; | |
309cfbf4 | 404 | register int npf; |
b5ad10c3 BJ |
405 | unsigned v; |
406 | register struct pte *pte, *io; | |
407 | int o; | |
b5ad10c3 | 408 | struct proc *rp; |
b5ad10c3 | 409 | |
f9b6e695 | 410 | v = btop(bp->b_un.b_addr); |
3e3f9c04 | 411 | o = (int)(bp->b_un.b_addr) & PGOFSET; |
c0bb0291 KM |
412 | if (bp->b_bcount >= 0) |
413 | npf = btoc(bp->b_bcount + o); | |
414 | else | |
415 | npf = btoc(-(bp->b_bcount) + o); | |
f9b6e695 | 416 | rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc; |
309cfbf4 | 417 | if ((bp->b_flags & B_PHYS) == 0) |
f9b6e695 | 418 | pte = &Sysmap[btop(((int)bp->b_un.b_addr)&0x7fffffff)]; |
309cfbf4 BJ |
419 | else if (bp->b_flags & B_UAREA) |
420 | pte = &rp->p_addr[v]; | |
421 | else if (bp->b_flags & B_PAGET) | |
422 | pte = &Usrptmap[btokmx((struct pte *)bp->b_un.b_addr)]; | |
423 | else | |
424 | pte = vtopte(rp, v); | |
425 | io = mbap->mba_map; | |
426 | while (--npf >= 0) { | |
427 | if (pte->pg_pfnum == 0) | |
428 | panic("mba, zero entry"); | |
429 | *(int *)io++ = pte++->pg_pfnum | PG_V; | |
b5ad10c3 | 430 | } |
f9b6e695 | 431 | *(int *)io++ = 0; |
309cfbf4 | 432 | return (o); |
b5ad10c3 | 433 | } |
16e4017f | 434 | |
a42d8a6b | 435 | #if notdef |
d565635a BJ |
436 | /* |
437 | * Init and interrupt enable a massbus adapter. | |
438 | */ | |
16e4017f BJ |
439 | mbainit(mp) |
440 | struct mba_regs *mp; | |
441 | { | |
442 | ||
d565635a BJ |
443 | mp->mba_cr = MBCR_INIT; |
444 | mp->mba_cr = MBCR_IE; | |
16e4017f | 445 | } |
443c8066 | 446 | #endif |
2752c877 | 447 | #endif |