Home | History | Annotate | Line # | Download | only in dev
nhpib.c revision 1.36
      1 /*	$NetBSD: nhpib.c,v 1.36 2007/07/12 20:39:01 he 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.36 2007/07/12 20:39:01 he 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, 0);
    254 	callout_init(&sc->sc_ppwatch_ch, 0);
    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 =
    267 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    268 	struct nhpibdevice *hd = sc->sc_regs;
    269 
    270 	hd->hpib_acr = AUX_SSWRST;
    271 	hd->hpib_ar = hs->sc_ba;
    272 	hd->hpib_lim = LIS_ERR;
    273 	hd->hpib_mim = 0;
    274 	hd->hpib_acr = AUX_CDAI;
    275 	hd->hpib_acr = AUX_CSHDW;
    276 	hd->hpib_acr = AUX_SSTD1;
    277 	hd->hpib_acr = AUX_SVSTD1;
    278 	hd->hpib_acr = AUX_CPP;
    279 	hd->hpib_acr = AUX_CHDFA;
    280 	hd->hpib_acr = AUX_CHDFE;
    281 	hd->hpib_acr = AUX_RHDF;
    282 	hd->hpib_acr = AUX_CSWRST;
    283 	nhpibifc(hd);
    284 	hd->hpib_ie = IDS_IE;
    285 	hd->hpib_data = C_DCL_P;
    286 	DELAY(100000);
    287 }
    288 
    289 static void
    290 nhpibifc(struct nhpibdevice *hd)
    291 {
    292 
    293 	hd->hpib_acr = AUX_TCA;
    294 	hd->hpib_acr = AUX_CSRE;
    295 	hd->hpib_acr = AUX_SSIC;
    296 	DELAY(100);
    297 	hd->hpib_acr = AUX_CSIC;
    298 	hd->hpib_acr = AUX_SSRE;
    299 }
    300 
    301 static int
    302 nhpibsend(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int origcnt)
    303 {
    304 	struct nhpib_softc *sc =
    305 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    306 	struct nhpibdevice *hd = sc->sc_regs;
    307 	int cnt = origcnt;
    308 	char *addr = ptr;
    309 
    310 	hd->hpib_acr = AUX_TCA;
    311 	hd->hpib_data = C_UNL_P;
    312 	if (nhpibwait(hd, MIS_BO))
    313 		goto senderror;
    314 	hd->hpib_data = talker_par[hs->sc_ba];
    315 	hd->hpib_acr = AUX_STON;
    316 	if (nhpibwait(hd, MIS_BO))
    317 		goto senderror;
    318 	hd->hpib_data = listnr_par[slave];
    319 	if (nhpibwait(hd, MIS_BO))
    320 		goto senderror;
    321 	if (sec >= 0 || sec == -2) {
    322 		if (sec == -2)		/* selected device clear KLUDGE */
    323 			hd->hpib_data = C_SDC_P;
    324 		else
    325 			hd->hpib_data = sec_par[sec];
    326 		if (nhpibwait(hd, MIS_BO))
    327 			goto senderror;
    328 	}
    329 	hd->hpib_acr = AUX_GTS;
    330 	if (cnt) {
    331 		while (--cnt > 0) {
    332 			hd->hpib_data = *addr++;
    333 			if (nhpibwait(hd, MIS_BO))
    334 				goto senderror;
    335 		}
    336 		hd->hpib_acr = AUX_EOI;
    337 		hd->hpib_data = *addr;
    338 		if (nhpibwait(hd, MIS_BO))
    339 			goto senderror;
    340 		hd->hpib_acr = AUX_TCA;
    341 #if 0
    342 		/*
    343 		 * May be causing 345 disks to hang due to interference
    344 		 * with PPOLL mechanism.
    345 		 */
    346 		hd->hpib_data = C_UNL_P;
    347 		(void) nhpibwait(hd, MIS_BO);
    348 #endif
    349 	}
    350 	return origcnt;
    351 
    352 senderror:
    353 	nhpibifc(hd);
    354 	return origcnt - cnt - 1;
    355 }
    356 
    357 static int
    358 nhpibrecv(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int origcnt)
    359 {
    360 	struct nhpib_softc *sc =
    361 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    362 	struct nhpibdevice *hd = sc->sc_regs;
    363 	int cnt = origcnt;
    364 	char *addr = ptr;
    365 
    366 	/*
    367 	 * Slave < 0 implies continuation of a previous receive
    368 	 * that probably timed out.
    369 	 */
    370 	if (slave >= 0) {
    371 		hd->hpib_acr = AUX_TCA;
    372 		hd->hpib_data = C_UNL_P;
    373 		if (nhpibwait(hd, MIS_BO))
    374 			goto recverror;
    375 		hd->hpib_data = listnr_par[hs->sc_ba];
    376 		hd->hpib_acr = AUX_SLON;
    377 		if (nhpibwait(hd, MIS_BO))
    378 			goto recverror;
    379 		hd->hpib_data = talker_par[slave];
    380 		if (nhpibwait(hd, MIS_BO))
    381 			goto recverror;
    382 		if (sec >= 0) {
    383 			hd->hpib_data = sec_par[sec];
    384 			if (nhpibwait(hd, MIS_BO))
    385 				goto recverror;
    386 		}
    387 		hd->hpib_acr = AUX_RHDF;
    388 		hd->hpib_acr = AUX_GTS;
    389 	}
    390 	if (cnt) {
    391 		while (--cnt >= 0) {
    392 			if (nhpibwait(hd, MIS_BI))
    393 				goto recvbyteserror;
    394 			*addr++ = hd->hpib_data;
    395 		}
    396 		hd->hpib_acr = AUX_TCA;
    397 		hd->hpib_data = (slave == 31) ? C_UNA_P : C_UNT_P;
    398 		(void) nhpibwait(hd, MIS_BO);
    399 	}
    400 	return origcnt;
    401 
    402 recverror:
    403 	nhpibifc(hd);
    404 recvbyteserror:
    405 	return origcnt - cnt - 1;
    406 }
    407 
    408 static void
    409 nhpibgo(struct hpibbus_softc *hs, int slave, int sec, void *ptr, int count,
    410     int rw, int timo)
    411 {
    412 	struct nhpib_softc *sc =
    413 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    414 	struct nhpibdevice *hd = sc->sc_regs;
    415 	char *addr = ptr;
    416 
    417 	hs->sc_flags |= HPIBF_IO;
    418 	if (timo)
    419 		hs->sc_flags |= HPIBF_TIMO;
    420 	if (rw == B_READ)
    421 		hs->sc_flags |= HPIBF_READ;
    422 #ifdef DEBUG
    423 	else if (hs->sc_flags & HPIBF_READ) {
    424 		printf("nhpibgo: HPIBF_READ still set\n");
    425 		hs->sc_flags &= ~HPIBF_READ;
    426 	}
    427 #endif
    428 	hs->sc_count = count;
    429 	hs->sc_addr = addr;
    430 	if (hs->sc_flags & HPIBF_READ) {
    431 		hs->sc_curcnt = count;
    432 		dmago(hs->sc_dq->dq_chan, addr, count, DMAGO_BYTE|DMAGO_READ);
    433 		nhpibrecv(hs, slave, sec, 0, 0);
    434 		hd->hpib_mim = MIS_END;
    435 	} else {
    436 		hd->hpib_mim = 0;
    437 		if (count < hpibdmathresh) {
    438 			hs->sc_curcnt = count;
    439 			nhpibsend(hs, slave, sec, addr, count);
    440 			nhpibdone(hs);
    441 			return;
    442 		}
    443 		hs->sc_curcnt = --count;
    444 		dmago(hs->sc_dq->dq_chan, addr, count, DMAGO_BYTE);
    445 		nhpibsend(hs, slave, sec, 0, 0);
    446 	}
    447 	hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq->dq_chan);
    448 }
    449 
    450 /*
    451  * This timeout can only happen if a DMA read finishes DMAing with the read
    452  * still pending (more data in read transaction than the driver was prepared
    453  * to accept).  At the moment, variable-record tape drives are the only things
    454  * capabale of doing this.  We repeat the necessary code from nhpibintr() -
    455  * easier and quicker than calling nhpibintr() for this special case.
    456  */
    457 static void
    458 nhpibreadtimo(void *arg)
    459 {
    460 	struct hpibbus_softc *hs = arg;
    461 	struct nhpib_softc *sc =
    462 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    463 	int s = splbio();
    464 
    465 	if (hs->sc_flags & HPIBF_IO) {
    466 		struct nhpibdevice *hd = sc->sc_regs;
    467 		struct hpibqueue *hq;
    468 
    469 		hd->hpib_mim = 0;
    470 		hd->hpib_acr = AUX_TCA;
    471 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    472 		dmafree(hs->sc_dq);
    473 
    474 		hq = hs->sc_queue.tqh_first;
    475 		(hq->hq_intr)(hq->hq_softc);
    476 	}
    477 	splx(s);
    478 }
    479 
    480 static void
    481 nhpibdone(struct hpibbus_softc *hs)
    482 {
    483 	struct nhpib_softc *sc =
    484 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    485 	struct nhpibdevice *hd = sc->sc_regs;
    486 	int cnt;
    487 
    488 	cnt = hs->sc_curcnt;
    489 	hs->sc_addr += cnt;
    490 	hs->sc_count -= cnt;
    491 	hs->sc_flags |= HPIBF_DONE;
    492 	hd->hpib_ie = IDS_IE;
    493 	if (hs->sc_flags & HPIBF_READ) {
    494 		if ((hs->sc_flags & HPIBF_TIMO) &&
    495 		    (hd->hpib_ids & IDS_IR) == 0)
    496 			callout_reset(&sc->sc_read_ch, hz >> 2,
    497 			    nhpibreadtimo, hs);
    498 	} else {
    499 		if (hs->sc_count == 1) {
    500 			(void) nhpibwait(hd, MIS_BO);
    501 			hd->hpib_acr = AUX_EOI;
    502 			hd->hpib_data = *hs->sc_addr;
    503 			hd->hpib_mim = MIS_BO;
    504 		}
    505 #ifdef DEBUG
    506 		else if (hs->sc_count)
    507 			panic("nhpibdone");
    508 #endif
    509 	}
    510 }
    511 
    512 static int
    513 nhpibintr(void *arg)
    514 {
    515 	struct nhpib_softc *sc = arg;
    516 	struct hpibbus_softc *hs = sc->sc_hpibbus;
    517 	struct nhpibdevice *hd = sc->sc_regs;
    518 	struct hpibqueue *hq;
    519 	int stat0;
    520 	int stat1;
    521 
    522 #ifdef lint
    523 	if (stat1 = unit)
    524 		return 1;
    525 #endif
    526 	if ((hd->hpib_ids & IDS_IR) == 0)
    527 		return 0;
    528 	stat0 = hd->hpib_mis;
    529 	stat1 = hd->hpib_lis;
    530 
    531 	hq = hs->sc_queue.tqh_first;
    532 
    533 	if (hs->sc_flags & HPIBF_IO) {
    534 		hd->hpib_mim = 0;
    535 		if ((hs->sc_flags & HPIBF_DONE) == 0) {
    536 			hs->sc_flags &= ~HPIBF_TIMO;
    537 			dmastop(hs->sc_dq->dq_chan);
    538 		} else if (hs->sc_flags & HPIBF_TIMO)
    539 			callout_stop(&sc->sc_read_ch);
    540 		hd->hpib_acr = AUX_TCA;
    541 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    542 
    543 		dmafree(hs->sc_dq);
    544 		(hq->hq_intr)(hq->hq_softc);
    545 	} else if (hs->sc_flags & HPIBF_PPOLL) {
    546 		hd->hpib_mim = 0;
    547 		stat0 = nhpibppoll(hs);
    548 		if (stat0 & (0x80 >> hq->hq_slave)) {
    549 			hs->sc_flags &= ~HPIBF_PPOLL;
    550 			(hq->hq_intr)(hq->hq_softc);
    551 		}
    552 #ifdef DEBUG
    553 		else
    554 			printf("%s: PPOLL intr bad status %x\n",
    555 			       hs->sc_dev.dv_xname, stat0);
    556 #endif
    557 	}
    558 	return 1;
    559 }
    560 
    561 static int
    562 nhpibppoll(struct hpibbus_softc *hs)
    563 {
    564 	struct nhpib_softc *sc =
    565 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    566 	struct nhpibdevice *hd = sc->sc_regs;
    567 	int ppoll;
    568 
    569 	hd->hpib_acr = AUX_SPP;
    570 	DELAY(25);
    571 	ppoll = hd->hpib_cpt;
    572 	hd->hpib_acr = AUX_CPP;
    573 	return ppoll;
    574 }
    575 
    576 #ifdef DEBUG
    577 int nhpibreporttimo = 0;
    578 #endif
    579 
    580 static int
    581 nhpibwait(struct nhpibdevice *hd, int x)
    582 {
    583 	int timo = hpibtimeout;
    584 
    585 	while ((hd->hpib_mis & x) == 0 && --timo)
    586 		DELAY(1);
    587 	if (timo == 0) {
    588 #ifdef DEBUG
    589 		if (nhpibreporttimo)
    590 			printf("hpib0: %s timo\n", x==MIS_BO?"OUT":"IN");
    591 #endif
    592 		return -1;
    593 	}
    594 	return 0;
    595 }
    596 
    597 static void
    598 nhpibppwatch(void *arg)
    599 {
    600 	struct hpibbus_softc *hs = arg;
    601 	struct nhpib_softc *sc =
    602 	    (struct nhpib_softc *)device_parent(&hs->sc_dev);
    603 
    604 	if ((hs->sc_flags & HPIBF_PPOLL) == 0)
    605 		return;
    606 again:
    607 	if (nhpibppoll(hs) & (0x80 >> hs->sc_queue.tqh_first->hq_slave))
    608 		sc->sc_regs->hpib_mim = MIS_BO;
    609 	else if (cold)
    610 		/* timeouts not working yet */
    611 		goto again;
    612 	else
    613 		callout_reset(&sc->sc_ppwatch_ch, 1, nhpibppwatch, hs);
    614 }
    615