nhpib.c revision 1.8 1 1.8 thorpej /* $NetBSD: nhpib.c,v 1.8 1995/12/02 18:22:06 thorpej 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 * @(#)nhpib.c 8.2 (Berkeley) 1/12/94
36 1.1 cgd */
37 1.1 cgd
38 1.1 cgd /*
39 1.1 cgd * Internal/98624 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/nhpibreg.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.6 mycroft /*
55 1.6 mycroft * ODD parity table for listen and talk addresses and secondary commands.
56 1.6 mycroft * The TI9914A doesn't produce the parity bit.
57 1.6 mycroft */
58 1.6 mycroft static u_char listnr_par[] = {
59 1.6 mycroft 0040,0241,0242,0043,0244,0045,0046,0247,
60 1.6 mycroft 0250,0051,0052,0253,0054,0255,0256,0057,
61 1.6 mycroft 0260,0061,0062,0263,0064,0265,0266,0067,
62 1.6 mycroft 0070,0271,0272,0073,0274,0075,0076,0277,
63 1.6 mycroft };
64 1.6 mycroft static u_char talker_par[] = {
65 1.6 mycroft 0100,0301,0302,0103,0304,0105,0106,0307,
66 1.6 mycroft 0310,0111,0112,0313,0114,0315,0316,0117,
67 1.6 mycroft 0320,0121,0122,0323,0124,0325,0326,0127,
68 1.6 mycroft 0130,0331,0332,0133,0334,0135,0136,0337,
69 1.6 mycroft };
70 1.6 mycroft static u_char sec_par[] = {
71 1.6 mycroft 0340,0141,0142,0343,0144,0345,0346,0147,
72 1.6 mycroft 0150,0351,0352,0153,0354,0155,0156,0357,
73 1.6 mycroft 0160,0361,0362,0163,0364,0165,0166,0367,
74 1.6 mycroft 0370,0171,0172,0373,0174,0375,0376,0177
75 1.6 mycroft };
76 1.6 mycroft
77 1.7 thorpej void nhpibreset __P((int));
78 1.7 thorpej int nhpibsend __P((int, int, int, void *, int));
79 1.7 thorpej int nhpibrecv __P((int, int, int, void *, int));
80 1.7 thorpej int nhpibppoll __P((int));
81 1.7 thorpej void nhpibppwatch __P((void *));
82 1.7 thorpej void nhpibgo __P((int, int, int, void *, int, int, int));
83 1.7 thorpej void nhpibdone __P((int));
84 1.7 thorpej int nhpibintr __P((int));
85 1.7 thorpej
86 1.7 thorpej /*
87 1.7 thorpej * Our controller ops structure.
88 1.7 thorpej */
89 1.7 thorpej struct hpib_controller nhpib_controller = {
90 1.7 thorpej nhpibreset,
91 1.7 thorpej nhpibsend,
92 1.7 thorpej nhpibrecv,
93 1.7 thorpej nhpibppoll,
94 1.7 thorpej nhpibppwatch,
95 1.7 thorpej nhpibgo,
96 1.7 thorpej nhpibdone,
97 1.7 thorpej nhpibintr
98 1.7 thorpej };
99 1.7 thorpej
100 1.7 thorpej int
101 1.1 cgd nhpibtype(hc)
102 1.1 cgd register struct hp_ctlr *hc;
103 1.1 cgd {
104 1.1 cgd register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
105 1.1 cgd register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
106 1.1 cgd
107 1.1 cgd if (hc->hp_addr == internalhpib) {
108 1.1 cgd hs->sc_type = HPIBA;
109 1.8 thorpej hc->hp_ipl = HPIBA_IPL;
110 1.8 thorpej return (1);
111 1.8 thorpej } else if (hd->hpib_cid == HPIBB) {
112 1.8 thorpej hs->sc_type = HPIBB;
113 1.8 thorpej hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
114 1.8 thorpej return (1);
115 1.8 thorpej }
116 1.8 thorpej
117 1.8 thorpej return(0);
118 1.8 thorpej }
119 1.8 thorpej
120 1.8 thorpej void
121 1.8 thorpej nhpibattach(hc)
122 1.8 thorpej register struct hp_ctlr *hc;
123 1.8 thorpej {
124 1.8 thorpej struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
125 1.8 thorpej register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
126 1.8 thorpej
127 1.8 thorpej switch (hs->sc_type) {
128 1.8 thorpej case HPIBA:
129 1.1 cgd hs->sc_ba = HPIBA_BA;
130 1.7 thorpej hs->sc_descrip = "Internal HP-IB";
131 1.8 thorpej break;
132 1.8 thorpej
133 1.8 thorpej case HPIBB:
134 1.1 cgd hs->sc_ba = hd->hpib_csa & CSA_BA;
135 1.7 thorpej hs->sc_descrip = "98624 HP-IB";
136 1.8 thorpej break;
137 1.8 thorpej
138 1.8 thorpej default:
139 1.8 thorpej panic("nhpibattach: unknown type 0x%x", hs->sc_type);
140 1.8 thorpej /* NOTREACHED */
141 1.1 cgd }
142 1.7 thorpej
143 1.7 thorpej hs->sc_controller = &nhpib_controller;
144 1.1 cgd }
145 1.1 cgd
146 1.7 thorpej void
147 1.1 cgd nhpibreset(unit)
148 1.4 mycroft int unit;
149 1.1 cgd {
150 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
151 1.1 cgd register struct nhpibdevice *hd;
152 1.1 cgd
153 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
154 1.1 cgd hd->hpib_acr = AUX_SSWRST;
155 1.1 cgd hd->hpib_ar = hs->sc_ba;
156 1.1 cgd hd->hpib_lim = LIS_ERR;
157 1.1 cgd hd->hpib_mim = 0;
158 1.1 cgd hd->hpib_acr = AUX_CDAI;
159 1.1 cgd hd->hpib_acr = AUX_CSHDW;
160 1.1 cgd hd->hpib_acr = AUX_SSTD1;
161 1.1 cgd hd->hpib_acr = AUX_SVSTD1;
162 1.1 cgd hd->hpib_acr = AUX_CPP;
163 1.1 cgd hd->hpib_acr = AUX_CHDFA;
164 1.1 cgd hd->hpib_acr = AUX_CHDFE;
165 1.1 cgd hd->hpib_acr = AUX_RHDF;
166 1.1 cgd hd->hpib_acr = AUX_CSWRST;
167 1.1 cgd nhpibifc(hd);
168 1.1 cgd hd->hpib_ie = IDS_IE;
169 1.6 mycroft hd->hpib_data = C_DCL_P;
170 1.1 cgd DELAY(100000);
171 1.1 cgd }
172 1.1 cgd
173 1.1 cgd nhpibifc(hd)
174 1.1 cgd register struct nhpibdevice *hd;
175 1.1 cgd {
176 1.1 cgd hd->hpib_acr = AUX_TCA;
177 1.1 cgd hd->hpib_acr = AUX_CSRE;
178 1.1 cgd hd->hpib_acr = AUX_SSIC;
179 1.1 cgd DELAY(100);
180 1.1 cgd hd->hpib_acr = AUX_CSIC;
181 1.1 cgd hd->hpib_acr = AUX_SSRE;
182 1.1 cgd }
183 1.1 cgd
184 1.7 thorpej int
185 1.7 thorpej nhpibsend(unit, slave, sec, ptr, origcnt)
186 1.4 mycroft int unit, slave, sec, origcnt;
187 1.7 thorpej void *ptr;
188 1.1 cgd {
189 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
190 1.1 cgd register struct nhpibdevice *hd;
191 1.1 cgd register int cnt = origcnt;
192 1.7 thorpej char *addr = ptr;
193 1.1 cgd
194 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
195 1.1 cgd hd->hpib_acr = AUX_TCA;
196 1.6 mycroft hd->hpib_data = C_UNL_P;
197 1.1 cgd if (nhpibwait(hd, MIS_BO))
198 1.1 cgd goto senderror;
199 1.6 mycroft hd->hpib_data = talker_par[hs->sc_ba];
200 1.1 cgd hd->hpib_acr = AUX_STON;
201 1.1 cgd if (nhpibwait(hd, MIS_BO))
202 1.1 cgd goto senderror;
203 1.6 mycroft hd->hpib_data = listnr_par[slave];
204 1.1 cgd if (nhpibwait(hd, MIS_BO))
205 1.1 cgd goto senderror;
206 1.6 mycroft if (sec >= 0 || sec == -2) {
207 1.6 mycroft if (sec == -2) /* selected device clear KLUDGE */
208 1.6 mycroft hd->hpib_data = C_SDC_P;
209 1.6 mycroft else
210 1.6 mycroft hd->hpib_data = sec_par[sec];
211 1.1 cgd if (nhpibwait(hd, MIS_BO))
212 1.1 cgd goto senderror;
213 1.1 cgd }
214 1.1 cgd hd->hpib_acr = AUX_GTS;
215 1.1 cgd if (cnt) {
216 1.1 cgd while (--cnt > 0) {
217 1.1 cgd hd->hpib_data = *addr++;
218 1.1 cgd if (nhpibwait(hd, MIS_BO))
219 1.1 cgd goto senderror;
220 1.1 cgd }
221 1.1 cgd hd->hpib_acr = AUX_EOI;
222 1.1 cgd hd->hpib_data = *addr;
223 1.1 cgd if (nhpibwait(hd, MIS_BO))
224 1.1 cgd goto senderror;
225 1.1 cgd hd->hpib_acr = AUX_TCA;
226 1.1 cgd #if 0
227 1.1 cgd /*
228 1.1 cgd * May be causing 345 disks to hang due to interference
229 1.1 cgd * with PPOLL mechanism.
230 1.1 cgd */
231 1.6 mycroft hd->hpib_data = C_UNL_P;
232 1.1 cgd (void) nhpibwait(hd, MIS_BO);
233 1.1 cgd #endif
234 1.1 cgd }
235 1.1 cgd return(origcnt);
236 1.6 mycroft
237 1.1 cgd senderror:
238 1.1 cgd nhpibifc(hd);
239 1.1 cgd return(origcnt - cnt - 1);
240 1.1 cgd }
241 1.1 cgd
242 1.7 thorpej int
243 1.7 thorpej nhpibrecv(unit, slave, sec, ptr, origcnt)
244 1.4 mycroft int unit, slave, sec, origcnt;
245 1.7 thorpej void *ptr;
246 1.1 cgd {
247 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
248 1.1 cgd register struct nhpibdevice *hd;
249 1.1 cgd register int cnt = origcnt;
250 1.7 thorpej char *addr = ptr;
251 1.1 cgd
252 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
253 1.6 mycroft /*
254 1.6 mycroft * Slave < 0 implies continuation of a previous receive
255 1.6 mycroft * that probably timed out.
256 1.6 mycroft */
257 1.6 mycroft if (slave >= 0) {
258 1.6 mycroft hd->hpib_acr = AUX_TCA;
259 1.6 mycroft hd->hpib_data = C_UNL_P;
260 1.6 mycroft if (nhpibwait(hd, MIS_BO))
261 1.6 mycroft goto recverror;
262 1.6 mycroft hd->hpib_data = listnr_par[hs->sc_ba];
263 1.6 mycroft hd->hpib_acr = AUX_SLON;
264 1.6 mycroft if (nhpibwait(hd, MIS_BO))
265 1.6 mycroft goto recverror;
266 1.6 mycroft hd->hpib_data = talker_par[slave];
267 1.1 cgd if (nhpibwait(hd, MIS_BO))
268 1.1 cgd goto recverror;
269 1.6 mycroft if (sec >= 0) {
270 1.6 mycroft hd->hpib_data = sec_par[sec];
271 1.6 mycroft if (nhpibwait(hd, MIS_BO))
272 1.6 mycroft goto recverror;
273 1.6 mycroft }
274 1.6 mycroft hd->hpib_acr = AUX_RHDF;
275 1.6 mycroft hd->hpib_acr = AUX_GTS;
276 1.1 cgd }
277 1.1 cgd if (cnt) {
278 1.1 cgd while (--cnt >= 0) {
279 1.1 cgd if (nhpibwait(hd, MIS_BI))
280 1.1 cgd goto recvbyteserror;
281 1.1 cgd *addr++ = hd->hpib_data;
282 1.1 cgd }
283 1.1 cgd hd->hpib_acr = AUX_TCA;
284 1.6 mycroft hd->hpib_data = (slave == 31) ? C_UNA_P : C_UNT_P;
285 1.1 cgd (void) nhpibwait(hd, MIS_BO);
286 1.1 cgd }
287 1.1 cgd return(origcnt);
288 1.6 mycroft
289 1.1 cgd recverror:
290 1.1 cgd nhpibifc(hd);
291 1.1 cgd recvbyteserror:
292 1.1 cgd return(origcnt - cnt - 1);
293 1.1 cgd }
294 1.1 cgd
295 1.7 thorpej void
296 1.7 thorpej nhpibgo(unit, slave, sec, ptr, count, rw, timo)
297 1.7 thorpej int unit, slave, sec, count, rw, timo;
298 1.7 thorpej void *ptr;
299 1.1 cgd {
300 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
301 1.1 cgd register struct nhpibdevice *hd;
302 1.7 thorpej char *addr = ptr;
303 1.1 cgd
304 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
305 1.1 cgd hs->sc_flags |= HPIBF_IO;
306 1.6 mycroft if (timo)
307 1.6 mycroft hs->sc_flags |= HPIBF_TIMO;
308 1.1 cgd if (rw == B_READ)
309 1.1 cgd hs->sc_flags |= HPIBF_READ;
310 1.1 cgd #ifdef DEBUG
311 1.1 cgd else if (hs->sc_flags & HPIBF_READ) {
312 1.1 cgd printf("nhpibgo: HPIBF_READ still set\n");
313 1.1 cgd hs->sc_flags &= ~HPIBF_READ;
314 1.1 cgd }
315 1.1 cgd #endif
316 1.1 cgd hs->sc_count = count;
317 1.1 cgd hs->sc_addr = addr;
318 1.1 cgd if (hs->sc_flags & HPIBF_READ) {
319 1.1 cgd hs->sc_curcnt = count;
320 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE|DMAGO_READ);
321 1.1 cgd nhpibrecv(unit, slave, sec, 0, 0);
322 1.1 cgd hd->hpib_mim = MIS_END;
323 1.1 cgd } else {
324 1.1 cgd hd->hpib_mim = 0;
325 1.1 cgd if (count < hpibdmathresh) {
326 1.1 cgd hs->sc_curcnt = count;
327 1.1 cgd nhpibsend(unit, slave, sec, addr, count);
328 1.1 cgd nhpibdone(unit);
329 1.1 cgd return;
330 1.1 cgd }
331 1.1 cgd hs->sc_curcnt = --count;
332 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE);
333 1.1 cgd nhpibsend(unit, slave, sec, 0, 0);
334 1.1 cgd }
335 1.1 cgd hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq.dq_ctlr);
336 1.1 cgd }
337 1.1 cgd
338 1.6 mycroft /*
339 1.6 mycroft * This timeout can only happen if a DMA read finishes DMAing with the read
340 1.6 mycroft * still pending (more data in read transaction than the driver was prepared
341 1.6 mycroft * to accept). At the moment, variable-record tape drives are the only things
342 1.6 mycroft * capabale of doing this. We repeat the necessary code from nhpibintr() -
343 1.6 mycroft * easier and quicker than calling nhpibintr() for this special case.
344 1.6 mycroft */
345 1.6 mycroft void
346 1.6 mycroft nhpibreadtimo(arg)
347 1.6 mycroft void *arg;
348 1.6 mycroft {
349 1.6 mycroft int unit;
350 1.6 mycroft register struct hpib_softc *hs;
351 1.6 mycroft int s = splbio();
352 1.6 mycroft
353 1.6 mycroft unit = (int)arg;
354 1.6 mycroft hs = &hpib_softc[unit];
355 1.6 mycroft if (hs->sc_flags & HPIBF_IO) {
356 1.6 mycroft register struct nhpibdevice *hd;
357 1.6 mycroft register struct devqueue *dq;
358 1.6 mycroft
359 1.6 mycroft hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
360 1.6 mycroft hd->hpib_mim = 0;
361 1.6 mycroft hd->hpib_acr = AUX_TCA;
362 1.6 mycroft hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
363 1.6 mycroft dmafree(&hs->sc_dq);
364 1.6 mycroft dq = hs->sc_sq.dq_forw;
365 1.6 mycroft (dq->dq_driver->d_intr)(dq->dq_unit);
366 1.6 mycroft }
367 1.6 mycroft (void) splx(s);
368 1.6 mycroft }
369 1.6 mycroft
370 1.7 thorpej void
371 1.1 cgd nhpibdone(unit)
372 1.1 cgd register int unit;
373 1.1 cgd {
374 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
375 1.1 cgd register struct nhpibdevice *hd;
376 1.1 cgd register int cnt;
377 1.1 cgd
378 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
379 1.1 cgd cnt = hs->sc_curcnt;
380 1.1 cgd hs->sc_addr += cnt;
381 1.1 cgd hs->sc_count -= cnt;
382 1.1 cgd hs->sc_flags |= HPIBF_DONE;
383 1.1 cgd hd->hpib_ie = IDS_IE;
384 1.6 mycroft if (hs->sc_flags & HPIBF_READ) {
385 1.6 mycroft if ((hs->sc_flags & HPIBF_TIMO) &&
386 1.6 mycroft (hd->hpib_ids & IDS_IR) == 0)
387 1.6 mycroft timeout(nhpibreadtimo, (void *)unit, hz >> 2);
388 1.6 mycroft } else {
389 1.1 cgd if (hs->sc_count == 1) {
390 1.1 cgd (void) nhpibwait(hd, MIS_BO);
391 1.1 cgd hd->hpib_acr = AUX_EOI;
392 1.1 cgd hd->hpib_data = *hs->sc_addr;
393 1.1 cgd hd->hpib_mim = MIS_BO;
394 1.1 cgd }
395 1.1 cgd #ifdef DEBUG
396 1.1 cgd else if (hs->sc_count)
397 1.1 cgd panic("nhpibdone");
398 1.1 cgd #endif
399 1.1 cgd }
400 1.1 cgd }
401 1.1 cgd
402 1.7 thorpej int
403 1.1 cgd nhpibintr(unit)
404 1.1 cgd register int unit;
405 1.1 cgd {
406 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
407 1.1 cgd register struct nhpibdevice *hd;
408 1.1 cgd register struct devqueue *dq;
409 1.1 cgd register int stat0;
410 1.1 cgd int stat1;
411 1.1 cgd
412 1.1 cgd #ifdef lint
413 1.1 cgd if (stat1 = unit) return(1);
414 1.1 cgd #endif
415 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
416 1.1 cgd if ((hd->hpib_ids & IDS_IR) == 0)
417 1.1 cgd return(0);
418 1.1 cgd stat0 = hd->hpib_mis;
419 1.1 cgd stat1 = hd->hpib_lis;
420 1.1 cgd dq = hs->sc_sq.dq_forw;
421 1.1 cgd if (hs->sc_flags & HPIBF_IO) {
422 1.1 cgd hd->hpib_mim = 0;
423 1.6 mycroft if ((hs->sc_flags & HPIBF_DONE) == 0) {
424 1.6 mycroft hs->sc_flags &= ~HPIBF_TIMO;
425 1.1 cgd dmastop(hs->sc_dq.dq_ctlr);
426 1.6 mycroft } else if (hs->sc_flags & HPIBF_TIMO)
427 1.6 mycroft untimeout(nhpibreadtimo, (void *)unit);
428 1.1 cgd hd->hpib_acr = AUX_TCA;
429 1.6 mycroft hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
430 1.1 cgd dmafree(&hs->sc_dq);
431 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
432 1.1 cgd } else if (hs->sc_flags & HPIBF_PPOLL) {
433 1.1 cgd hd->hpib_mim = 0;
434 1.1 cgd stat0 = nhpibppoll(unit);
435 1.1 cgd if (stat0 & (0x80 >> dq->dq_slave)) {
436 1.1 cgd hs->sc_flags &= ~HPIBF_PPOLL;
437 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
438 1.1 cgd }
439 1.1 cgd #ifdef DEBUG
440 1.1 cgd else
441 1.8 thorpej printf("%s: PPOLL intr bad status %x\n",
442 1.8 thorpej hs->sc_hc->hp_xname, stat0);
443 1.1 cgd #endif
444 1.1 cgd }
445 1.1 cgd return(1);
446 1.1 cgd }
447 1.1 cgd
448 1.7 thorpej int
449 1.1 cgd nhpibppoll(unit)
450 1.1 cgd int unit;
451 1.1 cgd {
452 1.1 cgd register struct nhpibdevice *hd;
453 1.1 cgd register int ppoll;
454 1.1 cgd
455 1.1 cgd hd = (struct nhpibdevice *)hpib_softc[unit].sc_hc->hp_addr;
456 1.1 cgd hd->hpib_acr = AUX_SPP;
457 1.1 cgd DELAY(25);
458 1.1 cgd ppoll = hd->hpib_cpt;
459 1.1 cgd hd->hpib_acr = AUX_CPP;
460 1.1 cgd return(ppoll);
461 1.1 cgd }
462 1.1 cgd
463 1.6 mycroft #ifdef DEBUG
464 1.6 mycroft int nhpibreporttimo = 0;
465 1.6 mycroft #endif
466 1.6 mycroft
467 1.7 thorpej int
468 1.1 cgd nhpibwait(hd, x)
469 1.1 cgd register struct nhpibdevice *hd;
470 1.4 mycroft int x;
471 1.1 cgd {
472 1.1 cgd register int timo = hpibtimeout;
473 1.1 cgd
474 1.1 cgd while ((hd->hpib_mis & x) == 0 && --timo)
475 1.1 cgd DELAY(1);
476 1.6 mycroft if (timo == 0) {
477 1.6 mycroft #ifdef DEBUG
478 1.6 mycroft if (nhpibreporttimo)
479 1.6 mycroft printf("hpib0: %s timo\n", x==MIS_BO?"OUT":"IN");
480 1.6 mycroft #endif
481 1.1 cgd return(-1);
482 1.6 mycroft }
483 1.1 cgd return(0);
484 1.1 cgd }
485 1.1 cgd
486 1.4 mycroft void
487 1.3 mycroft nhpibppwatch(arg)
488 1.3 mycroft void *arg;
489 1.1 cgd {
490 1.4 mycroft register struct hpib_softc *hs;
491 1.4 mycroft register int unit;
492 1.4 mycroft extern int cold;
493 1.1 cgd
494 1.4 mycroft unit = (int)arg;
495 1.4 mycroft hs = &hpib_softc[unit];
496 1.1 cgd if ((hs->sc_flags & HPIBF_PPOLL) == 0)
497 1.1 cgd return;
498 1.4 mycroft again:
499 1.1 cgd if (nhpibppoll(unit) & (0x80 >> hs->sc_sq.dq_forw->dq_slave))
500 1.1 cgd ((struct nhpibdevice *)hs->sc_hc->hp_addr)->hpib_mim = MIS_BO;
501 1.4 mycroft else if (cold)
502 1.4 mycroft /* timeouts not working yet */
503 1.4 mycroft goto again;
504 1.1 cgd else
505 1.3 mycroft timeout(nhpibppwatch, (void *)unit, 1);
506 1.1 cgd }
507 1.7 thorpej #endif /* NHPIB > 0 */
508