Home | History | Annotate | Line # | Download | only in dev
nhpib.c revision 1.27.2.3
      1 /*	$NetBSD: nhpib.c,v 1.27.2.3 2004/09/18 14:34:08 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1982, 1990, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. Neither the name of the University nor the names of its contributors
     52  *    may be used to endorse or promote products derived from this software
     53  *    without specific prior written permission.
     54  *
     55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  * SUCH DAMAGE.
     66  *
     67  *	@(#)nhpib.c	8.2 (Berkeley) 1/12/94
     68  */
     69 
     70 /*
     71  * Internal/98624 HPIB driver
     72  */
     73 
     74 #include <sys/cdefs.h>
     75 __KERNEL_RCSID(0, "$NetBSD: nhpib.c,v 1.27.2.3 2004/09/18 14:34:08 skrll Exp $");
     76 
     77 #include <sys/param.h>
     78 #include <sys/systm.h>
     79 #include <sys/callout.h>
     80 #include <sys/kernel.h>
     81 #include <sys/buf.h>
     82 #include <sys/device.h>
     83 
     84 #include <machine/bus.h>
     85 
     86 #include <hp300/dev/intiovar.h>
     87 #include <hp300/dev/diovar.h>
     88 #include <hp300/dev/diodevs.h>
     89 #include <hp300/dev/dmavar.h>
     90 
     91 #include <hp300/dev/nhpibreg.h>
     92 #include <hp300/dev/hpibvar.h>
     93 
     94 /*
     95  * ODD parity table for listen and talk addresses and secondary commands.
     96  * The TI9914A doesn't produce the parity bit.
     97  */
     98 static const u_char listnr_par[] = {
     99 	0040,0241,0242,0043,0244,0045,0046,0247,
    100 	0250,0051,0052,0253,0054,0255,0256,0057,
    101 	0260,0061,0062,0263,0064,0265,0266,0067,
    102 	0070,0271,0272,0073,0274,0075,0076,0277,
    103 };
    104 static const u_char talker_par[] = {
    105 	0100,0301,0302,0103,0304,0105,0106,0307,
    106 	0310,0111,0112,0313,0114,0315,0316,0117,
    107 	0320,0121,0122,0323,0124,0325,0326,0127,
    108 	0130,0331,0332,0133,0334,0135,0136,0337,
    109 };
    110 static const u_char sec_par[] = {
    111 	0340,0141,0142,0343,0144,0345,0346,0147,
    112 	0150,0351,0352,0153,0354,0155,0156,0357,
    113 	0160,0361,0362,0163,0364,0165,0166,0367,
    114 	0370,0171,0172,0373,0174,0375,0376,0177
    115 };
    116 
    117 static void	nhpibifc(struct nhpibdevice *);
    118 static void	nhpibreadtimo(void *);
    119 static int	nhpibwait(struct nhpibdevice *, int);
    120 
    121 static void	nhpibreset(struct hpibbus_softc *);
    122 static int	nhpibsend(struct hpibbus_softc *, int, int, void *, int);
    123 static int	nhpibrecv(struct hpibbus_softc *, int, int, void *, int);
    124 static int	nhpibppoll(struct hpibbus_softc *);
    125 static void	nhpibppwatch(void *);
    126 static void	nhpibgo(struct hpibbus_softc *, int, int, void *, int, int,
    127 		    int);
    128 static void	nhpibdone(struct hpibbus_softc *);
    129 static int	nhpibintr(void *);
    130 
    131 /*
    132  * Our controller ops structure.
    133  */
    134 static struct hpib_controller nhpib_controller = {
    135 	nhpibreset,
    136 	nhpibsend,
    137 	nhpibrecv,
    138 	nhpibppoll,
    139 	nhpibppwatch,
    140 	nhpibgo,
    141 	nhpibdone,
    142 	nhpibintr
    143 };
    144 
    145 struct nhpib_softc {
    146 	struct device sc_dev;		/* generic device glue */
    147 
    148 	bus_space_tag_t sc_bst;
    149 	bus_space_handle_t sc_bsh;
    150 
    151 	struct nhpibdevice *sc_regs;	/* device registers */
    152 	struct hpibbus_softc *sc_hpibbus; /* XXX */
    153 
    154 	int sc_myaddr;
    155 	int sc_type;
    156 
    157 	struct callout sc_read_ch;
    158 	struct callout sc_ppwatch_ch;
    159 };
    160 
    161 static int	nhpib_dio_match(struct device *, struct cfdata *, void *);
    162 static void	nhpib_dio_attach(struct device *, struct device *, void *);
    163 static int	nhpib_intio_match(struct device *, struct cfdata *, void *);
    164 static void	nhpib_intio_attach(struct device *, struct device *, void *);
    165 
    166 static void	nhpib_common_attach(struct nhpib_softc *, const char *);
    167 
    168 CFATTACH_DECL(nhpib_dio, sizeof(struct nhpib_softc),
    169     nhpib_dio_match, nhpib_dio_attach, NULL, NULL);
    170 
    171 CFATTACH_DECL(nhpib_intio, sizeof(struct nhpib_softc),
    172     nhpib_intio_match, nhpib_intio_attach, NULL, NULL);
    173 
    174 static int
    175 nhpib_intio_match(struct device *parent, struct cfdata *match, void *aux)
    176 {
    177 	struct intio_attach_args *ia = aux;
    178 
    179 	if (strcmp("hpib", ia->ia_modname) == 0)
    180 		return (1);
    181 
    182 	return (0);
    183 }
    184 
    185 static int
    186 nhpib_dio_match(struct device *parent, struct cfdata *match, void *aux)
    187 {
    188 	struct dio_attach_args *da = aux;
    189 
    190 	if (da->da_id == DIO_DEVICE_ID_NHPIB)
    191 		return (1);
    192 
    193 	return (0);
    194 }
    195 
    196 static void
    197 nhpib_intio_attach(struct device *parent, struct device *self, void *aux)
    198 {
    199 	struct nhpib_softc *sc = (struct nhpib_softc *)self;
    200 	struct intio_attach_args *ia = aux;
    201 	bus_space_tag_t bst = ia->ia_bst;
    202 	const char *desc = "internal HP-IB";
    203 
    204 	if (bus_space_map(bst, ia->ia_iobase, INTIO_DEVSIZE, 0, &sc->sc_bsh)) {
    205 		printf(": can't map registers\n");
    206 		return;
    207 	}
    208 
    209 	sc->sc_bst = bst;
    210 	sc->sc_myaddr = HPIBA_BA;
    211 	sc->sc_type = HPIBA;
    212 
    213 	nhpib_common_attach(sc, desc);
    214 
    215 	/* establish the interrupt handler */
    216 	(void) intio_intr_establish(nhpibintr, sc, ia->ia_ipl, IPL_BIO);
    217 }
    218 
    219 static void
    220 nhpib_dio_attach(struct device *parent, struct device *self, void *aux)
    221 {
    222 	struct nhpib_softc *sc = (struct nhpib_softc *)self;
    223 	struct dio_attach_args *da = aux;
    224 	bus_space_tag_t bst = da->da_bst;
    225 	const char *desc = DIO_DEVICE_DESC_NHPIB;
    226 
    227 	if (bus_space_map(bst, da->da_addr, da->da_size, 0, &sc->sc_bsh)) {
    228 		printf(": can't map registers\n");
    229 		return;
    230 	}
    231 
    232 	sc->sc_bst = bst;
    233 	/* read address off switches */
    234 	sc->sc_myaddr = bus_space_read_1(sc->sc_bst, sc->sc_bsh, 5);
    235 	sc->sc_type = HPIBB;
    236 
    237 	nhpib_common_attach(sc, desc);
    238 
    239 	/* establish the interrupt handler */
    240 	(void)dio_intr_establish(nhpibintr, sc, da->da_ipl, IPL_BIO);
    241 }
    242 
    243 static void
    244 nhpib_common_attach(struct nhpib_softc *sc, const char *desc)
    245 {
    246 	struct hpibdev_attach_args ha;
    247 
    248 	printf(": %s\n", desc);
    249 
    250 	sc->sc_regs = (struct nhpibdevice *)bus_space_vaddr(sc->sc_bst,
    251 	    sc->sc_bsh);
    252 
    253 	callout_init(&sc->sc_read_ch);
    254 	callout_init(&sc->sc_ppwatch_ch);
    255 
    256 	ha.ha_ops = &nhpib_controller;
    257 	ha.ha_type = sc->sc_type;			/* XXX */
    258 	ha.ha_ba = sc->sc_myaddr;
    259 	ha.ha_softcpp = &sc->sc_hpibbus;		/* XXX */
    260 	(void)config_found((void *)sc, &ha, hpibdevprint);
    261 }
    262 
    263 static void
    264 nhpibreset(struct hpibbus_softc *hs)
    265 {
    266 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    267 	struct nhpibdevice *hd = sc->sc_regs;
    268 
    269 	hd->hpib_acr = AUX_SSWRST;
    270 	hd->hpib_ar = hs->sc_ba;
    271 	hd->hpib_lim = LIS_ERR;
    272 	hd->hpib_mim = 0;
    273 	hd->hpib_acr = AUX_CDAI;
    274 	hd->hpib_acr = AUX_CSHDW;
    275 	hd->hpib_acr = AUX_SSTD1;
    276 	hd->hpib_acr = AUX_SVSTD1;
    277 	hd->hpib_acr = AUX_CPP;
    278 	hd->hpib_acr = AUX_CHDFA;
    279 	hd->hpib_acr = AUX_CHDFE;
    280 	hd->hpib_acr = AUX_RHDF;
    281 	hd->hpib_acr = AUX_CSWRST;
    282 	nhpibifc(hd);
    283 	hd->hpib_ie = IDS_IE;
    284 	hd->hpib_data = C_DCL_P;
    285 	DELAY(100000);
    286 }
    287 
    288 static void
    289 nhpibifc(struct nhpibdevice *hd)
    290 {
    291 	hd->hpib_acr = AUX_TCA;
    292 	hd->hpib_acr = AUX_CSRE;
    293 	hd->hpib_acr = AUX_SSIC;
    294 	DELAY(100);
    295 	hd->hpib_acr = AUX_CSIC;
    296 	hd->hpib_acr = AUX_SSRE;
    297 }
    298 
    299 static int
    300 nhpibsend(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int origcnt)
    301 {
    302 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    303 	struct nhpibdevice *hd = sc->sc_regs;
    304 	int cnt = origcnt;
    305 	char *addr = ptr;
    306 
    307 	hd->hpib_acr = AUX_TCA;
    308 	hd->hpib_data = C_UNL_P;
    309 	if (nhpibwait(hd, MIS_BO))
    310 		goto senderror;
    311 	hd->hpib_data = talker_par[hs->sc_ba];
    312 	hd->hpib_acr = AUX_STON;
    313 	if (nhpibwait(hd, MIS_BO))
    314 		goto senderror;
    315 	hd->hpib_data = listnr_par[slave];
    316 	if (nhpibwait(hd, MIS_BO))
    317 		goto senderror;
    318 	if (sec >= 0 || sec == -2) {
    319 		if (sec == -2)		/* selected device clear KLUDGE */
    320 			hd->hpib_data = C_SDC_P;
    321 		else
    322 			hd->hpib_data = sec_par[sec];
    323 		if (nhpibwait(hd, MIS_BO))
    324 			goto senderror;
    325 	}
    326 	hd->hpib_acr = AUX_GTS;
    327 	if (cnt) {
    328 		while (--cnt > 0) {
    329 			hd->hpib_data = *addr++;
    330 			if (nhpibwait(hd, MIS_BO))
    331 				goto senderror;
    332 		}
    333 		hd->hpib_acr = AUX_EOI;
    334 		hd->hpib_data = *addr;
    335 		if (nhpibwait(hd, MIS_BO))
    336 			goto senderror;
    337 		hd->hpib_acr = AUX_TCA;
    338 #if 0
    339 		/*
    340 		 * May be causing 345 disks to hang due to interference
    341 		 * with PPOLL mechanism.
    342 		 */
    343 		hd->hpib_data = C_UNL_P;
    344 		(void) nhpibwait(hd, MIS_BO);
    345 #endif
    346 	}
    347 	return(origcnt);
    348 
    349 senderror:
    350 	nhpibifc(hd);
    351 	return(origcnt - cnt - 1);
    352 }
    353 
    354 static int
    355 nhpibrecv(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int origcnt)
    356 {
    357 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    358 	struct nhpibdevice *hd = sc->sc_regs;
    359 	int cnt = origcnt;
    360 	char *addr = ptr;
    361 
    362 	/*
    363 	 * Slave < 0 implies continuation of a previous receive
    364 	 * that probably timed out.
    365 	 */
    366 	if (slave >= 0) {
    367 		hd->hpib_acr = AUX_TCA;
    368 		hd->hpib_data = C_UNL_P;
    369 		if (nhpibwait(hd, MIS_BO))
    370 			goto recverror;
    371 		hd->hpib_data = listnr_par[hs->sc_ba];
    372 		hd->hpib_acr = AUX_SLON;
    373 		if (nhpibwait(hd, MIS_BO))
    374 			goto recverror;
    375 		hd->hpib_data = talker_par[slave];
    376 		if (nhpibwait(hd, MIS_BO))
    377 			goto recverror;
    378 		if (sec >= 0) {
    379 			hd->hpib_data = sec_par[sec];
    380 			if (nhpibwait(hd, MIS_BO))
    381 				goto recverror;
    382 		}
    383 		hd->hpib_acr = AUX_RHDF;
    384 		hd->hpib_acr = AUX_GTS;
    385 	}
    386 	if (cnt) {
    387 		while (--cnt >= 0) {
    388 			if (nhpibwait(hd, MIS_BI))
    389 				goto recvbyteserror;
    390 			*addr++ = hd->hpib_data;
    391 		}
    392 		hd->hpib_acr = AUX_TCA;
    393 		hd->hpib_data = (slave == 31) ? C_UNA_P : C_UNT_P;
    394 		(void) nhpibwait(hd, MIS_BO);
    395 	}
    396 	return(origcnt);
    397 
    398 recverror:
    399 	nhpibifc(hd);
    400 recvbyteserror:
    401 	return(origcnt - cnt - 1);
    402 }
    403 
    404 static void
    405 nhpibgo(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int count,
    406     int rw, int timo)
    407 {
    408 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    409 	struct nhpibdevice *hd = sc->sc_regs;
    410 	char *addr = ptr;
    411 
    412 	hs->sc_flags |= HPIBF_IO;
    413 	if (timo)
    414 		hs->sc_flags |= HPIBF_TIMO;
    415 	if (rw == B_READ)
    416 		hs->sc_flags |= HPIBF_READ;
    417 #ifdef DEBUG
    418 	else if (hs->sc_flags & HPIBF_READ) {
    419 		printf("nhpibgo: HPIBF_READ still set\n");
    420 		hs->sc_flags &= ~HPIBF_READ;
    421 	}
    422 #endif
    423 	hs->sc_count = count;
    424 	hs->sc_addr = addr;
    425 	if (hs->sc_flags & HPIBF_READ) {
    426 		hs->sc_curcnt = count;
    427 		dmago(hs->sc_dq->dq_chan, addr, count, DMAGO_BYTE|DMAGO_READ);
    428 		nhpibrecv(hs, slave, sec, 0, 0);
    429 		hd->hpib_mim = MIS_END;
    430 	} else {
    431 		hd->hpib_mim = 0;
    432 		if (count < hpibdmathresh) {
    433 			hs->sc_curcnt = count;
    434 			nhpibsend(hs, slave, sec, addr, count);
    435 			nhpibdone(hs);
    436 			return;
    437 		}
    438 		hs->sc_curcnt = --count;
    439 		dmago(hs->sc_dq->dq_chan, addr, count, DMAGO_BYTE);
    440 		nhpibsend(hs, slave, sec, 0, 0);
    441 	}
    442 	hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq->dq_chan);
    443 }
    444 
    445 /*
    446  * This timeout can only happen if a DMA read finishes DMAing with the read
    447  * still pending (more data in read transaction than the driver was prepared
    448  * to accept).  At the moment, variable-record tape drives are the only things
    449  * capabale of doing this.  We repeat the necessary code from nhpibintr() -
    450  * easier and quicker than calling nhpibintr() for this special case.
    451  */
    452 static void
    453 nhpibreadtimo(void *arg)
    454 {
    455 	struct hpibbus_softc *hs = arg;
    456 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    457 	int s = splbio();
    458 
    459 	if (hs->sc_flags & HPIBF_IO) {
    460 		struct nhpibdevice *hd = sc->sc_regs;
    461 		struct hpibqueue *hq;
    462 
    463 		hd->hpib_mim = 0;
    464 		hd->hpib_acr = AUX_TCA;
    465 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    466 		dmafree(hs->sc_dq);
    467 
    468 		hq = hs->sc_queue.tqh_first;
    469 		(hq->hq_intr)(hq->hq_softc);
    470 	}
    471 	splx(s);
    472 }
    473 
    474 static void
    475 nhpibdone(struct hpibbus_softc *hs)
    476 {
    477 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    478 	struct nhpibdevice *hd = sc->sc_regs;
    479 	int cnt;
    480 
    481 	cnt = hs->sc_curcnt;
    482 	hs->sc_addr += cnt;
    483 	hs->sc_count -= cnt;
    484 	hs->sc_flags |= HPIBF_DONE;
    485 	hd->hpib_ie = IDS_IE;
    486 	if (hs->sc_flags & HPIBF_READ) {
    487 		if ((hs->sc_flags & HPIBF_TIMO) &&
    488 		    (hd->hpib_ids & IDS_IR) == 0)
    489 			callout_reset(&sc->sc_read_ch, hz >> 2,
    490 			    nhpibreadtimo, hs);
    491 	} else {
    492 		if (hs->sc_count == 1) {
    493 			(void) nhpibwait(hd, MIS_BO);
    494 			hd->hpib_acr = AUX_EOI;
    495 			hd->hpib_data = *hs->sc_addr;
    496 			hd->hpib_mim = MIS_BO;
    497 		}
    498 #ifdef DEBUG
    499 		else if (hs->sc_count)
    500 			panic("nhpibdone");
    501 #endif
    502 	}
    503 }
    504 
    505 static int
    506 nhpibintr(void *arg)
    507 {
    508 	struct nhpib_softc *sc = arg;
    509 	struct hpibbus_softc *hs = sc->sc_hpibbus;
    510 	struct nhpibdevice *hd = sc->sc_regs;
    511 	struct hpibqueue *hq;
    512 	int stat0;
    513 	int stat1;
    514 
    515 #ifdef lint
    516 	if (stat1 = unit) return(1);
    517 #endif
    518 	if ((hd->hpib_ids & IDS_IR) == 0)
    519 		return(0);
    520 	stat0 = hd->hpib_mis;
    521 	stat1 = hd->hpib_lis;
    522 
    523 	hq = hs->sc_queue.tqh_first;
    524 
    525 	if (hs->sc_flags & HPIBF_IO) {
    526 		hd->hpib_mim = 0;
    527 		if ((hs->sc_flags & HPIBF_DONE) == 0) {
    528 			hs->sc_flags &= ~HPIBF_TIMO;
    529 			dmastop(hs->sc_dq->dq_chan);
    530 		} else if (hs->sc_flags & HPIBF_TIMO)
    531 			callout_stop(&sc->sc_read_ch);
    532 		hd->hpib_acr = AUX_TCA;
    533 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    534 
    535 		dmafree(hs->sc_dq);
    536 		(hq->hq_intr)(hq->hq_softc);
    537 	} else if (hs->sc_flags & HPIBF_PPOLL) {
    538 		hd->hpib_mim = 0;
    539 		stat0 = nhpibppoll(hs);
    540 		if (stat0 & (0x80 >> hq->hq_slave)) {
    541 			hs->sc_flags &= ~HPIBF_PPOLL;
    542 			(hq->hq_intr)(hq->hq_softc);
    543 		}
    544 #ifdef DEBUG
    545 		else
    546 			printf("%s: PPOLL intr bad status %x\n",
    547 			       hs->sc_dev.dv_xname, stat0);
    548 #endif
    549 	}
    550 	return(1);
    551 }
    552 
    553 static int
    554 nhpibppoll(struct hpibbus_softc *hs)
    555 {
    556 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    557 	struct nhpibdevice *hd = sc->sc_regs;
    558 	int ppoll;
    559 
    560 	hd->hpib_acr = AUX_SPP;
    561 	DELAY(25);
    562 	ppoll = hd->hpib_cpt;
    563 	hd->hpib_acr = AUX_CPP;
    564 	return(ppoll);
    565 }
    566 
    567 #ifdef DEBUG
    568 int nhpibreporttimo = 0;
    569 #endif
    570 
    571 static int
    572 nhpibwait(struct nhpibdevice *hd, int x)
    573 {
    574 	int timo = hpibtimeout;
    575 
    576 	while ((hd->hpib_mis & x) == 0 && --timo)
    577 		DELAY(1);
    578 	if (timo == 0) {
    579 #ifdef DEBUG
    580 		if (nhpibreporttimo)
    581 			printf("hpib0: %s timo\n", x==MIS_BO?"OUT":"IN");
    582 #endif
    583 		return(-1);
    584 	}
    585 	return(0);
    586 }
    587 
    588 static void
    589 nhpibppwatch(void *arg)
    590 {
    591 	struct hpibbus_softc *hs = arg;
    592 	struct nhpib_softc *sc = (struct nhpib_softc *)hs->sc_dev.dv_parent;
    593 
    594 	if ((hs->sc_flags & HPIBF_PPOLL) == 0)
    595 		return;
    596 again:
    597 	if (nhpibppoll(hs) & (0x80 >> hs->sc_queue.tqh_first->hq_slave))
    598        		sc->sc_regs->hpib_mim = MIS_BO;
    599 	else if (cold)
    600 		/* timeouts not working yet */
    601 		goto again;
    602 	else
    603 		callout_reset(&sc->sc_ppwatch_ch, 1, nhpibppwatch, hs);
    604 }
    605