fhpib.c revision 1.6 1 1.6 mycroft /* $NetBSD: fhpib.c,v 1.6 1995/01/07 10:30:10 mycroft Exp $ */
2 1.5 cgd
3 1.1 cgd /*
4 1.4 mycroft * Copyright (c) 1982, 1990, 1993
5 1.4 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd *
35 1.5 cgd * @(#)fhpib.c 8.2 (Berkeley) 1/12/94
36 1.1 cgd */
37 1.1 cgd
38 1.1 cgd /*
39 1.1 cgd * 98625A/B HPIB driver
40 1.1 cgd */
41 1.1 cgd #include "hpib.h"
42 1.1 cgd #if NHPIB > 0
43 1.1 cgd
44 1.4 mycroft #include <sys/param.h>
45 1.4 mycroft #include <sys/systm.h>
46 1.6 mycroft #include <sys/kernel.h>
47 1.4 mycroft #include <sys/buf.h>
48 1.4 mycroft
49 1.4 mycroft #include <hp300/dev/device.h>
50 1.4 mycroft #include <hp300/dev/fhpibreg.h>
51 1.4 mycroft #include <hp300/dev/hpibvar.h>
52 1.4 mycroft #include <hp300/dev/dmavar.h>
53 1.1 cgd
54 1.1 cgd /*
55 1.1 cgd * Inline version of fhpibwait to be used in places where
56 1.1 cgd * we don't worry about getting hung.
57 1.1 cgd */
58 1.1 cgd #define FHPIBWAIT(hd, m) while (((hd)->hpib_intr & (m)) == 0) DELAY(1)
59 1.1 cgd
60 1.1 cgd #ifdef DEBUG
61 1.1 cgd int fhpibdebugunit = -1;
62 1.1 cgd int fhpibdebug = 0;
63 1.1 cgd #define FDB_FAIL 0x01
64 1.1 cgd #define FDB_DMA 0x02
65 1.1 cgd #define FDB_WAIT 0x04
66 1.1 cgd #define FDB_PPOLL 0x08
67 1.1 cgd
68 1.1 cgd int dopriodma = 0; /* use high priority DMA */
69 1.1 cgd int doworddma = 1; /* non-zero if we should attempt word dma */
70 1.1 cgd int doppollint = 1; /* use ppoll interrupts instead of watchdog */
71 1.4 mycroft int fhpibppolldelay = 50;
72 1.1 cgd
73 1.1 cgd long fhpibbadint[2] = { 0 };
74 1.1 cgd long fhpibtransfer[NHPIB] = { 0 };
75 1.1 cgd long fhpibnondma[NHPIB] = { 0 };
76 1.1 cgd long fhpibworddma[NHPIB] = { 0 };
77 1.4 mycroft long fhpibppollfail[NHPIB] = { 0 };
78 1.1 cgd #endif
79 1.1 cgd
80 1.1 cgd int fhpibcmd[NHPIB];
81 1.1 cgd
82 1.1 cgd fhpibtype(hc)
83 1.1 cgd register struct hp_ctlr *hc;
84 1.1 cgd {
85 1.1 cgd register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
86 1.1 cgd register struct fhpibdevice *hd = (struct fhpibdevice *)hc->hp_addr;
87 1.1 cgd
88 1.1 cgd if (hd->hpib_cid != HPIBC)
89 1.1 cgd return(0);
90 1.1 cgd hs->sc_type = HPIBC;
91 1.1 cgd hs->sc_ba = HPIBC_BA;
92 1.1 cgd hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
93 1.1 cgd return(1);
94 1.1 cgd }
95 1.1 cgd
96 1.1 cgd fhpibreset(unit)
97 1.4 mycroft int unit;
98 1.1 cgd {
99 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
100 1.1 cgd register struct fhpibdevice *hd;
101 1.1 cgd
102 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
103 1.1 cgd hd->hpib_cid = 0xFF;
104 1.1 cgd DELAY(100);
105 1.1 cgd hd->hpib_cmd = CT_8BIT;
106 1.1 cgd hd->hpib_ar = AR_ARONC;
107 1.1 cgd fhpibifc(hd);
108 1.1 cgd hd->hpib_ie = IDS_IE;
109 1.1 cgd hd->hpib_data = C_DCL;
110 1.1 cgd DELAY(100000);
111 1.1 cgd /*
112 1.1 cgd * See if we can do word dma.
113 1.1 cgd * If so, we should be able to write and read back the appropos bit.
114 1.1 cgd */
115 1.1 cgd hd->hpib_ie |= IDS_WDMA;
116 1.1 cgd if (hd->hpib_ie & IDS_WDMA) {
117 1.1 cgd hd->hpib_ie &= ~IDS_WDMA;
118 1.1 cgd hs->sc_flags |= HPIBF_DMA16;
119 1.1 cgd #ifdef DEBUG
120 1.1 cgd if (fhpibdebug & FDB_DMA)
121 1.1 cgd printf("fhpibtype: unit %d has word dma\n", unit);
122 1.1 cgd
123 1.1 cgd #endif
124 1.1 cgd }
125 1.1 cgd }
126 1.1 cgd
127 1.1 cgd fhpibifc(hd)
128 1.1 cgd register struct fhpibdevice *hd;
129 1.1 cgd {
130 1.1 cgd hd->hpib_cmd |= CT_IFC;
131 1.1 cgd hd->hpib_cmd |= CT_INITFIFO;
132 1.1 cgd DELAY(100);
133 1.1 cgd hd->hpib_cmd &= ~CT_IFC;
134 1.1 cgd hd->hpib_cmd |= CT_REN;
135 1.1 cgd hd->hpib_stat = ST_ATN;
136 1.1 cgd }
137 1.1 cgd
138 1.1 cgd fhpibsend(unit, slave, sec, addr, origcnt)
139 1.4 mycroft int unit, slave, sec, origcnt;
140 1.1 cgd register char *addr;
141 1.1 cgd {
142 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
143 1.1 cgd register struct fhpibdevice *hd;
144 1.1 cgd register int cnt = origcnt;
145 1.1 cgd register int timo;
146 1.1 cgd
147 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
148 1.1 cgd hd->hpib_stat = 0;
149 1.1 cgd hd->hpib_imask = IM_IDLE | IM_ROOM;
150 1.1 cgd if (fhpibwait(hd, IM_IDLE) < 0)
151 1.1 cgd goto senderr;
152 1.1 cgd hd->hpib_stat = ST_ATN;
153 1.1 cgd hd->hpib_data = C_UNL;
154 1.1 cgd hd->hpib_data = C_TAG + hs->sc_ba;
155 1.1 cgd hd->hpib_data = C_LAG + slave;
156 1.6 mycroft if (sec < 0) {
157 1.6 mycroft if (sec == -2) /* selected device clear KLUDGE */
158 1.6 mycroft hd->hpib_data = C_SDC;
159 1.6 mycroft } else
160 1.1 cgd hd->hpib_data = C_SCG + sec;
161 1.1 cgd if (fhpibwait(hd, IM_IDLE) < 0)
162 1.1 cgd goto senderr;
163 1.1 cgd if (cnt) {
164 1.1 cgd hd->hpib_stat = ST_WRITE;
165 1.1 cgd while (--cnt) {
166 1.1 cgd hd->hpib_data = *addr++;
167 1.1 cgd timo = hpibtimeout;
168 1.1 cgd while ((hd->hpib_intr & IM_ROOM) == 0) {
169 1.1 cgd if (--timo <= 0)
170 1.1 cgd goto senderr;
171 1.1 cgd DELAY(1);
172 1.1 cgd }
173 1.1 cgd }
174 1.1 cgd hd->hpib_stat = ST_EOI;
175 1.1 cgd hd->hpib_data = *addr;
176 1.1 cgd FHPIBWAIT(hd, IM_ROOM);
177 1.1 cgd hd->hpib_stat = ST_ATN;
178 1.1 cgd /* XXX: HP-UX claims bug with CS80 transparent messages */
179 1.1 cgd if (sec == 0x12)
180 1.1 cgd DELAY(150);
181 1.1 cgd hd->hpib_data = C_UNL;
182 1.1 cgd (void) fhpibwait(hd, IM_IDLE);
183 1.1 cgd }
184 1.1 cgd hd->hpib_imask = 0;
185 1.1 cgd return (origcnt);
186 1.6 mycroft
187 1.1 cgd senderr:
188 1.1 cgd hd->hpib_imask = 0;
189 1.1 cgd fhpibifc(hd);
190 1.1 cgd #ifdef DEBUG
191 1.1 cgd if (fhpibdebug & FDB_FAIL) {
192 1.1 cgd printf("hpib%d: fhpibsend failed: slave %d, sec %x, ",
193 1.1 cgd unit, slave, sec);
194 1.1 cgd printf("sent %d of %d bytes\n", origcnt-cnt-1, origcnt);
195 1.1 cgd }
196 1.1 cgd #endif
197 1.6 mycroft return (origcnt - cnt - 1);
198 1.1 cgd }
199 1.1 cgd
200 1.1 cgd fhpibrecv(unit, slave, sec, addr, origcnt)
201 1.4 mycroft int unit, slave, sec, origcnt;
202 1.1 cgd register char *addr;
203 1.1 cgd {
204 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
205 1.1 cgd register struct fhpibdevice *hd;
206 1.1 cgd register int cnt = origcnt;
207 1.1 cgd register int timo;
208 1.1 cgd
209 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
210 1.6 mycroft /*
211 1.6 mycroft * Slave < 0 implies continuation of a previous receive
212 1.6 mycroft * that probably timed out.
213 1.6 mycroft */
214 1.6 mycroft if (slave >= 0) {
215 1.6 mycroft hd->hpib_stat = 0;
216 1.6 mycroft hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
217 1.6 mycroft if (fhpibwait(hd, IM_IDLE) < 0)
218 1.6 mycroft goto recverror;
219 1.6 mycroft hd->hpib_stat = ST_ATN;
220 1.6 mycroft hd->hpib_data = C_UNL;
221 1.6 mycroft hd->hpib_data = C_LAG + hs->sc_ba;
222 1.6 mycroft hd->hpib_data = C_TAG + slave;
223 1.6 mycroft if (sec != -1)
224 1.6 mycroft hd->hpib_data = C_SCG + sec;
225 1.6 mycroft if (fhpibwait(hd, IM_IDLE) < 0)
226 1.6 mycroft goto recverror;
227 1.6 mycroft hd->hpib_stat = ST_READ0;
228 1.6 mycroft hd->hpib_data = 0;
229 1.6 mycroft }
230 1.1 cgd if (cnt) {
231 1.1 cgd while (--cnt >= 0) {
232 1.1 cgd timo = hpibtimeout;
233 1.1 cgd while ((hd->hpib_intr & IM_BYTE) == 0) {
234 1.1 cgd if (--timo == 0)
235 1.1 cgd goto recvbyteserror;
236 1.1 cgd DELAY(1);
237 1.1 cgd }
238 1.1 cgd *addr++ = hd->hpib_data;
239 1.1 cgd }
240 1.1 cgd FHPIBWAIT(hd, IM_ROOM);
241 1.1 cgd hd->hpib_stat = ST_ATN;
242 1.1 cgd hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
243 1.1 cgd (void) fhpibwait(hd, IM_IDLE);
244 1.1 cgd }
245 1.1 cgd hd->hpib_imask = 0;
246 1.1 cgd return (origcnt);
247 1.1 cgd
248 1.1 cgd recverror:
249 1.1 cgd fhpibifc(hd);
250 1.1 cgd recvbyteserror:
251 1.1 cgd hd->hpib_imask = 0;
252 1.1 cgd #ifdef DEBUG
253 1.1 cgd if (fhpibdebug & FDB_FAIL) {
254 1.1 cgd printf("hpib%d: fhpibrecv failed: slave %d, sec %x, ",
255 1.1 cgd unit, slave, sec);
256 1.1 cgd printf("got %d of %d bytes\n", origcnt-cnt-1, origcnt);
257 1.1 cgd }
258 1.1 cgd #endif
259 1.6 mycroft return (origcnt - cnt - 1);
260 1.1 cgd }
261 1.1 cgd
262 1.6 mycroft fhpibgo(unit, slave, sec, addr, count, rw, timo)
263 1.1 cgd register int unit;
264 1.4 mycroft int slave, sec, count, rw;
265 1.1 cgd char *addr;
266 1.1 cgd {
267 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
268 1.1 cgd register struct fhpibdevice *hd;
269 1.1 cgd register int i;
270 1.1 cgd int flags = 0;
271 1.1 cgd
272 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
273 1.1 cgd hs->sc_flags |= HPIBF_IO;
274 1.6 mycroft if (timo)
275 1.6 mycroft hs->sc_flags |= HPIBF_TIMO;
276 1.1 cgd if (rw == B_READ)
277 1.1 cgd hs->sc_flags |= HPIBF_READ;
278 1.1 cgd #ifdef DEBUG
279 1.1 cgd else if (hs->sc_flags & HPIBF_READ) {
280 1.1 cgd printf("fhpibgo: HPIBF_READ still set\n");
281 1.1 cgd hs->sc_flags &= ~HPIBF_READ;
282 1.1 cgd }
283 1.1 cgd #endif
284 1.1 cgd hs->sc_count = count;
285 1.1 cgd hs->sc_addr = addr;
286 1.1 cgd #ifdef DEBUG
287 1.1 cgd fhpibtransfer[unit]++;
288 1.1 cgd #endif
289 1.1 cgd if ((hs->sc_flags & HPIBF_DMA16) &&
290 1.1 cgd ((int)addr & 1) == 0 && count && (count & 1) == 0
291 1.1 cgd #ifdef DEBUG
292 1.1 cgd && doworddma
293 1.1 cgd #endif
294 1.1 cgd ) {
295 1.1 cgd #ifdef DEBUG
296 1.1 cgd fhpibworddma[unit]++;
297 1.1 cgd #endif
298 1.1 cgd flags |= DMAGO_WORD;
299 1.1 cgd hd->hpib_latch = 0;
300 1.1 cgd }
301 1.1 cgd #ifdef DEBUG
302 1.1 cgd if (dopriodma)
303 1.1 cgd flags |= DMAGO_PRI;
304 1.1 cgd #endif
305 1.1 cgd if (hs->sc_flags & HPIBF_READ) {
306 1.1 cgd fhpibcmd[unit] = CT_REN | CT_8BIT;
307 1.1 cgd hs->sc_curcnt = count;
308 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, flags|DMAGO_READ);
309 1.1 cgd if (fhpibrecv(unit, slave, sec, 0, 0) < 0) {
310 1.1 cgd #ifdef DEBUG
311 1.1 cgd printf("fhpibgo: recv failed, retrying...\n");
312 1.1 cgd #endif
313 1.1 cgd (void) fhpibrecv(unit, slave, sec, 0, 0);
314 1.1 cgd }
315 1.1 cgd i = hd->hpib_cmd;
316 1.1 cgd hd->hpib_cmd = fhpibcmd[unit];
317 1.1 cgd hd->hpib_ie = IDS_DMA(hs->sc_dq.dq_ctlr) |
318 1.1 cgd ((flags & DMAGO_WORD) ? IDS_WDMA : 0);
319 1.1 cgd return;
320 1.1 cgd }
321 1.1 cgd fhpibcmd[unit] = CT_REN | CT_8BIT | CT_FIFOSEL;
322 1.1 cgd if (count < hpibdmathresh) {
323 1.1 cgd #ifdef DEBUG
324 1.1 cgd fhpibnondma[unit]++;
325 1.1 cgd if (flags & DMAGO_WORD)
326 1.1 cgd fhpibworddma[unit]--;
327 1.1 cgd #endif
328 1.1 cgd hs->sc_curcnt = count;
329 1.1 cgd (void) fhpibsend(unit, slave, sec, addr, count);
330 1.1 cgd fhpibdone(unit);
331 1.1 cgd return;
332 1.1 cgd }
333 1.1 cgd count -= (flags & DMAGO_WORD) ? 2 : 1;
334 1.1 cgd hs->sc_curcnt = count;
335 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, flags);
336 1.1 cgd if (fhpibsend(unit, slave, sec, 0, 0) < 0) {
337 1.1 cgd #ifdef DEBUG
338 1.1 cgd printf("fhpibgo: send failed, retrying...\n");
339 1.1 cgd #endif
340 1.1 cgd (void) fhpibsend(unit, slave, sec, 0, 0);
341 1.1 cgd }
342 1.1 cgd i = hd->hpib_cmd;
343 1.1 cgd hd->hpib_cmd = fhpibcmd[unit];
344 1.1 cgd hd->hpib_ie = IDS_DMA(hs->sc_dq.dq_ctlr) | IDS_WRITE |
345 1.1 cgd ((flags & DMAGO_WORD) ? IDS_WDMA : 0);
346 1.1 cgd }
347 1.1 cgd
348 1.6 mycroft /*
349 1.6 mycroft * A DMA read can finish but the device can still be waiting (MAG-tape
350 1.6 mycroft * with more data than we're waiting for). This timeout routine
351 1.6 mycroft * takes care of that. Somehow, the thing gets hosed. For now, since
352 1.6 mycroft * this should be a very rare occurence, we RESET it.
353 1.6 mycroft */
354 1.6 mycroft void
355 1.6 mycroft fhpibdmadone(arg)
356 1.6 mycroft void *arg;
357 1.6 mycroft {
358 1.6 mycroft register int unit;
359 1.6 mycroft register struct hpib_softc *hs;
360 1.6 mycroft int s = splbio();
361 1.6 mycroft
362 1.6 mycroft unit = (int)arg;
363 1.6 mycroft hs = &hpib_softc[unit];
364 1.6 mycroft if (hs->sc_flags & HPIBF_IO) {
365 1.6 mycroft register struct fhpibdevice *hd;
366 1.6 mycroft register struct devqueue *dq;
367 1.6 mycroft
368 1.6 mycroft hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
369 1.6 mycroft hd->hpib_imask = 0;
370 1.6 mycroft hd->hpib_cid = 0xFF;
371 1.6 mycroft DELAY(100);
372 1.6 mycroft hd->hpib_cmd = CT_8BIT;
373 1.6 mycroft hd->hpib_ar = AR_ARONC;
374 1.6 mycroft fhpibifc(hd);
375 1.6 mycroft hd->hpib_ie = IDS_IE;
376 1.6 mycroft hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
377 1.6 mycroft dmafree(&hs->sc_dq);
378 1.6 mycroft dq = hs->sc_sq.dq_forw;
379 1.6 mycroft (dq->dq_driver->d_intr)(dq->dq_unit);
380 1.6 mycroft }
381 1.6 mycroft (void) splx(s);
382 1.6 mycroft }
383 1.6 mycroft
384 1.1 cgd fhpibdone(unit)
385 1.4 mycroft int unit;
386 1.1 cgd {
387 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
388 1.1 cgd register struct fhpibdevice *hd;
389 1.1 cgd register char *addr;
390 1.1 cgd register int cnt;
391 1.1 cgd
392 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
393 1.1 cgd cnt = hs->sc_curcnt;
394 1.1 cgd hs->sc_addr += cnt;
395 1.1 cgd hs->sc_count -= cnt;
396 1.1 cgd #ifdef DEBUG
397 1.1 cgd if ((fhpibdebug & FDB_DMA) && fhpibdebugunit == unit)
398 1.1 cgd printf("fhpibdone: addr %x cnt %d\n",
399 1.1 cgd hs->sc_addr, hs->sc_count);
400 1.1 cgd #endif
401 1.6 mycroft if (hs->sc_flags & HPIBF_READ) {
402 1.1 cgd hd->hpib_imask = IM_IDLE | IM_BYTE;
403 1.6 mycroft if (hs->sc_flags & HPIBF_TIMO)
404 1.6 mycroft timeout(fhpibdmadone, (void *)unit, hz >> 2);
405 1.6 mycroft } else {
406 1.1 cgd cnt = hs->sc_count;
407 1.1 cgd if (cnt) {
408 1.1 cgd addr = hs->sc_addr;
409 1.1 cgd hd->hpib_imask = IM_IDLE | IM_ROOM;
410 1.1 cgd FHPIBWAIT(hd, IM_IDLE);
411 1.1 cgd hd->hpib_stat = ST_WRITE;
412 1.1 cgd while (--cnt) {
413 1.1 cgd hd->hpib_data = *addr++;
414 1.1 cgd FHPIBWAIT(hd, IM_ROOM);
415 1.1 cgd }
416 1.1 cgd hd->hpib_stat = ST_EOI;
417 1.1 cgd hd->hpib_data = *addr;
418 1.1 cgd }
419 1.1 cgd hd->hpib_imask = IM_IDLE;
420 1.1 cgd }
421 1.1 cgd hs->sc_flags |= HPIBF_DONE;
422 1.1 cgd hd->hpib_stat = ST_IENAB;
423 1.1 cgd hd->hpib_ie = IDS_IE;
424 1.1 cgd }
425 1.1 cgd
426 1.1 cgd fhpibintr(unit)
427 1.1 cgd register int unit;
428 1.1 cgd {
429 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
430 1.1 cgd register struct fhpibdevice *hd;
431 1.1 cgd register struct devqueue *dq;
432 1.1 cgd register int stat0;
433 1.1 cgd
434 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
435 1.1 cgd stat0 = hd->hpib_ids;
436 1.1 cgd if ((stat0 & (IDS_IE|IDS_IR)) != (IDS_IE|IDS_IR)) {
437 1.1 cgd #ifdef DEBUG
438 1.1 cgd if ((fhpibdebug & FDB_FAIL) && (stat0 & IDS_IR) &&
439 1.1 cgd (hs->sc_flags & (HPIBF_IO|HPIBF_DONE)) != HPIBF_IO)
440 1.1 cgd printf("hpib%d: fhpibintr: bad status %x\n",
441 1.1 cgd unit, stat0);
442 1.1 cgd fhpibbadint[0]++;
443 1.1 cgd #endif
444 1.1 cgd return(0);
445 1.1 cgd }
446 1.1 cgd if ((hs->sc_flags & (HPIBF_IO|HPIBF_DONE)) == HPIBF_IO) {
447 1.1 cgd #ifdef DEBUG
448 1.1 cgd fhpibbadint[1]++;
449 1.1 cgd #endif
450 1.1 cgd return(0);
451 1.1 cgd }
452 1.1 cgd #ifdef DEBUG
453 1.1 cgd if ((fhpibdebug & FDB_DMA) && fhpibdebugunit == unit)
454 1.1 cgd printf("fhpibintr: flags %x\n", hs->sc_flags);
455 1.1 cgd #endif
456 1.1 cgd dq = hs->sc_sq.dq_forw;
457 1.1 cgd if (hs->sc_flags & HPIBF_IO) {
458 1.6 mycroft if (hs->sc_flags & HPIBF_TIMO)
459 1.6 mycroft untimeout(fhpibdmadone, (void *)unit);
460 1.1 cgd stat0 = hd->hpib_cmd;
461 1.1 cgd hd->hpib_cmd = fhpibcmd[unit] & ~CT_8BIT;
462 1.1 cgd hd->hpib_stat = 0;
463 1.1 cgd hd->hpib_cmd = CT_REN | CT_8BIT;
464 1.1 cgd stat0 = hd->hpib_intr;
465 1.1 cgd hd->hpib_imask = 0;
466 1.6 mycroft hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
467 1.1 cgd dmafree(&hs->sc_dq);
468 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
469 1.1 cgd } else if (hs->sc_flags & HPIBF_PPOLL) {
470 1.1 cgd stat0 = hd->hpib_intr;
471 1.1 cgd #ifdef DEBUG
472 1.1 cgd if ((fhpibdebug & FDB_FAIL) &&
473 1.1 cgd doppollint && (stat0 & IM_PPRESP) == 0)
474 1.1 cgd printf("hpib%d: fhpibintr: bad intr reg %x\n",
475 1.1 cgd unit, stat0);
476 1.1 cgd #endif
477 1.1 cgd hd->hpib_stat = 0;
478 1.1 cgd hd->hpib_imask = 0;
479 1.1 cgd #ifdef DEBUG
480 1.1 cgd stat0 = fhpibppoll(unit);
481 1.1 cgd if ((fhpibdebug & FDB_PPOLL) && unit == fhpibdebugunit)
482 1.1 cgd printf("fhpibintr: got PPOLL status %x\n", stat0);
483 1.1 cgd if ((stat0 & (0x80 >> dq->dq_slave)) == 0) {
484 1.4 mycroft /*
485 1.4 mycroft * XXX give it another shot (68040)
486 1.4 mycroft */
487 1.4 mycroft fhpibppollfail[unit]++;
488 1.4 mycroft DELAY(fhpibppolldelay);
489 1.4 mycroft stat0 = fhpibppoll(unit);
490 1.4 mycroft if ((stat0 & (0x80 >> dq->dq_slave)) == 0 &&
491 1.4 mycroft (fhpibdebug & FDB_PPOLL) && unit == fhpibdebugunit)
492 1.4 mycroft printf("fhpibintr: PPOLL: unit %d slave %d stat %x\n",
493 1.4 mycroft unit, dq->dq_slave, stat0);
494 1.1 cgd }
495 1.1 cgd #endif
496 1.1 cgd hs->sc_flags &= ~HPIBF_PPOLL;
497 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
498 1.1 cgd }
499 1.1 cgd return(1);
500 1.1 cgd }
501 1.1 cgd
502 1.1 cgd fhpibppoll(unit)
503 1.4 mycroft int unit;
504 1.1 cgd {
505 1.1 cgd register struct fhpibdevice *hd;
506 1.1 cgd register int ppoll;
507 1.1 cgd
508 1.1 cgd hd = (struct fhpibdevice *)hpib_softc[unit].sc_hc->hp_addr;
509 1.1 cgd hd->hpib_stat = 0;
510 1.1 cgd hd->hpib_psense = 0;
511 1.1 cgd hd->hpib_pmask = 0xFF;
512 1.1 cgd hd->hpib_imask = IM_PPRESP | IM_PABORT;
513 1.1 cgd DELAY(25);
514 1.1 cgd hd->hpib_intr = IM_PABORT;
515 1.1 cgd ppoll = hd->hpib_data;
516 1.1 cgd if (hd->hpib_intr & IM_PABORT)
517 1.1 cgd ppoll = 0;
518 1.1 cgd hd->hpib_imask = 0;
519 1.1 cgd hd->hpib_pmask = 0;
520 1.1 cgd hd->hpib_stat = ST_IENAB;
521 1.1 cgd return(ppoll);
522 1.1 cgd }
523 1.1 cgd
524 1.1 cgd fhpibwait(hd, x)
525 1.1 cgd register struct fhpibdevice *hd;
526 1.4 mycroft int x;
527 1.1 cgd {
528 1.1 cgd register int timo = hpibtimeout;
529 1.1 cgd
530 1.1 cgd while ((hd->hpib_intr & x) == 0 && --timo)
531 1.1 cgd DELAY(1);
532 1.1 cgd if (timo == 0) {
533 1.1 cgd #ifdef DEBUG
534 1.1 cgd if (fhpibdebug & FDB_FAIL)
535 1.1 cgd printf("fhpibwait(%x, %x) timeout\n", hd, x);
536 1.1 cgd #endif
537 1.1 cgd return(-1);
538 1.1 cgd }
539 1.1 cgd return(0);
540 1.1 cgd }
541 1.1 cgd
542 1.1 cgd /*
543 1.4 mycroft * XXX: this will have to change if we ever allow more than one
544 1.1 cgd * pending operation per HP-IB.
545 1.1 cgd */
546 1.4 mycroft void
547 1.3 mycroft fhpibppwatch(arg)
548 1.3 mycroft void *arg;
549 1.1 cgd {
550 1.4 mycroft register int unit;
551 1.4 mycroft register struct hpib_softc *hs;
552 1.1 cgd register struct fhpibdevice *hd;
553 1.1 cgd register int slave;
554 1.1 cgd
555 1.4 mycroft unit = (int)arg;
556 1.4 mycroft hs = &hpib_softc[unit];
557 1.1 cgd if ((hs->sc_flags & HPIBF_PPOLL) == 0)
558 1.1 cgd return;
559 1.1 cgd hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
560 1.1 cgd slave = (0x80 >> hs->sc_sq.dq_forw->dq_slave);
561 1.1 cgd #ifdef DEBUG
562 1.1 cgd if (!doppollint) {
563 1.1 cgd if (fhpibppoll(unit) & slave) {
564 1.1 cgd hd->hpib_stat = ST_IENAB;
565 1.1 cgd hd->hpib_imask = IM_IDLE | IM_ROOM;
566 1.1 cgd } else
567 1.3 mycroft timeout(fhpibppwatch, (void *)unit, 1);
568 1.1 cgd return;
569 1.1 cgd }
570 1.1 cgd if ((fhpibdebug & FDB_PPOLL) && unit == fhpibdebugunit)
571 1.1 cgd printf("fhpibppwatch: sense request on %d\n", unit);
572 1.1 cgd #endif
573 1.1 cgd hd->hpib_psense = ~slave;
574 1.1 cgd hd->hpib_pmask = slave;
575 1.1 cgd hd->hpib_stat = ST_IENAB;
576 1.1 cgd hd->hpib_imask = IM_PPRESP | IM_PABORT;
577 1.1 cgd hd->hpib_ie = IDS_IE;
578 1.1 cgd }
579 1.1 cgd #endif
580