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