Home | History | Annotate | Line # | Download | only in dev
nhpib.c revision 1.6
      1  1.6  mycroft /*	$NetBSD: nhpib.c,v 1.6 1995/01/07 10:30:14 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  *	@(#)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.1      cgd nhpibtype(hc)
     78  1.1      cgd 	register struct hp_ctlr *hc;
     79  1.1      cgd {
     80  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
     81  1.1      cgd 	register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
     82  1.1      cgd 
     83  1.1      cgd 	if (hc->hp_addr == internalhpib) {
     84  1.1      cgd 		hs->sc_type = HPIBA;
     85  1.1      cgd 		hs->sc_ba = HPIBA_BA;
     86  1.1      cgd 		hc->hp_ipl = HPIBA_IPL;
     87  1.1      cgd 	}
     88  1.1      cgd 	else if (hd->hpib_cid == HPIBB) {
     89  1.1      cgd 		hs->sc_type = HPIBB;
     90  1.1      cgd 		hs->sc_ba = hd->hpib_csa & CSA_BA;
     91  1.1      cgd 		hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
     92  1.1      cgd 	}
     93  1.1      cgd 	else
     94  1.1      cgd 		return(0);
     95  1.1      cgd 	return(1);
     96  1.1      cgd }
     97  1.1      cgd 
     98  1.1      cgd nhpibreset(unit)
     99  1.4  mycroft 	int unit;
    100  1.1      cgd {
    101  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    102  1.1      cgd 	register struct nhpibdevice *hd;
    103  1.1      cgd 
    104  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    105  1.1      cgd 	hd->hpib_acr = AUX_SSWRST;
    106  1.1      cgd 	hd->hpib_ar = hs->sc_ba;
    107  1.1      cgd 	hd->hpib_lim = LIS_ERR;
    108  1.1      cgd 	hd->hpib_mim = 0;
    109  1.1      cgd 	hd->hpib_acr = AUX_CDAI;
    110  1.1      cgd 	hd->hpib_acr = AUX_CSHDW;
    111  1.1      cgd 	hd->hpib_acr = AUX_SSTD1;
    112  1.1      cgd 	hd->hpib_acr = AUX_SVSTD1;
    113  1.1      cgd 	hd->hpib_acr = AUX_CPP;
    114  1.1      cgd 	hd->hpib_acr = AUX_CHDFA;
    115  1.1      cgd 	hd->hpib_acr = AUX_CHDFE;
    116  1.1      cgd 	hd->hpib_acr = AUX_RHDF;
    117  1.1      cgd 	hd->hpib_acr = AUX_CSWRST;
    118  1.1      cgd 	nhpibifc(hd);
    119  1.1      cgd 	hd->hpib_ie = IDS_IE;
    120  1.6  mycroft 	hd->hpib_data = C_DCL_P;
    121  1.1      cgd 	DELAY(100000);
    122  1.1      cgd }
    123  1.1      cgd 
    124  1.1      cgd nhpibifc(hd)
    125  1.1      cgd 	register struct nhpibdevice *hd;
    126  1.1      cgd {
    127  1.1      cgd 	hd->hpib_acr = AUX_TCA;
    128  1.1      cgd 	hd->hpib_acr = AUX_CSRE;
    129  1.1      cgd 	hd->hpib_acr = AUX_SSIC;
    130  1.1      cgd 	DELAY(100);
    131  1.1      cgd 	hd->hpib_acr = AUX_CSIC;
    132  1.1      cgd 	hd->hpib_acr = AUX_SSRE;
    133  1.1      cgd }
    134  1.1      cgd 
    135  1.1      cgd nhpibsend(unit, slave, sec, addr, origcnt)
    136  1.4  mycroft 	int unit, slave, sec, origcnt;
    137  1.1      cgd 	register char *addr;
    138  1.1      cgd {
    139  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    140  1.1      cgd 	register struct nhpibdevice *hd;
    141  1.1      cgd 	register int cnt = origcnt;
    142  1.1      cgd 
    143  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    144  1.1      cgd 	hd->hpib_acr = AUX_TCA;
    145  1.6  mycroft 	hd->hpib_data = C_UNL_P;
    146  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    147  1.1      cgd 		goto senderror;
    148  1.6  mycroft 	hd->hpib_data = talker_par[hs->sc_ba];
    149  1.1      cgd 	hd->hpib_acr = AUX_STON;
    150  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    151  1.1      cgd 		goto senderror;
    152  1.6  mycroft 	hd->hpib_data = listnr_par[slave];
    153  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    154  1.1      cgd 		goto senderror;
    155  1.6  mycroft 	if (sec >= 0 || sec == -2) {
    156  1.6  mycroft 		if (sec == -2)		/* selected device clear KLUDGE */
    157  1.6  mycroft 			hd->hpib_data = C_SDC_P;
    158  1.6  mycroft 		else
    159  1.6  mycroft 			hd->hpib_data = sec_par[sec];
    160  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    161  1.1      cgd 			goto senderror;
    162  1.1      cgd 	}
    163  1.1      cgd 	hd->hpib_acr = AUX_GTS;
    164  1.1      cgd 	if (cnt) {
    165  1.1      cgd 		while (--cnt > 0) {
    166  1.1      cgd 			hd->hpib_data = *addr++;
    167  1.1      cgd 			if (nhpibwait(hd, MIS_BO))
    168  1.1      cgd 				goto senderror;
    169  1.1      cgd 		}
    170  1.1      cgd 		hd->hpib_acr = AUX_EOI;
    171  1.1      cgd 		hd->hpib_data = *addr;
    172  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    173  1.1      cgd 			goto senderror;
    174  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    175  1.1      cgd #if 0
    176  1.1      cgd 		/*
    177  1.1      cgd 		 * May be causing 345 disks to hang due to interference
    178  1.1      cgd 		 * with PPOLL mechanism.
    179  1.1      cgd 		 */
    180  1.6  mycroft 		hd->hpib_data = C_UNL_P;
    181  1.1      cgd 		(void) nhpibwait(hd, MIS_BO);
    182  1.1      cgd #endif
    183  1.1      cgd 	}
    184  1.1      cgd 	return(origcnt);
    185  1.6  mycroft 
    186  1.1      cgd senderror:
    187  1.1      cgd 	nhpibifc(hd);
    188  1.1      cgd 	return(origcnt - cnt - 1);
    189  1.1      cgd }
    190  1.1      cgd 
    191  1.1      cgd nhpibrecv(unit, slave, sec, addr, origcnt)
    192  1.4  mycroft 	int unit, slave, sec, origcnt;
    193  1.1      cgd 	register char *addr;
    194  1.1      cgd {
    195  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    196  1.1      cgd 	register struct nhpibdevice *hd;
    197  1.1      cgd 	register int cnt = origcnt;
    198  1.1      cgd 
    199  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    200  1.6  mycroft 	/*
    201  1.6  mycroft 	 * Slave < 0 implies continuation of a previous receive
    202  1.6  mycroft 	 * that probably timed out.
    203  1.6  mycroft 	 */
    204  1.6  mycroft 	if (slave >= 0) {
    205  1.6  mycroft 		hd->hpib_acr = AUX_TCA;
    206  1.6  mycroft 		hd->hpib_data = C_UNL_P;
    207  1.6  mycroft 		if (nhpibwait(hd, MIS_BO))
    208  1.6  mycroft 			goto recverror;
    209  1.6  mycroft 		hd->hpib_data = listnr_par[hs->sc_ba];
    210  1.6  mycroft 		hd->hpib_acr = AUX_SLON;
    211  1.6  mycroft 		if (nhpibwait(hd, MIS_BO))
    212  1.6  mycroft 			goto recverror;
    213  1.6  mycroft 		hd->hpib_data = talker_par[slave];
    214  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    215  1.1      cgd 			goto recverror;
    216  1.6  mycroft 		if (sec >= 0) {
    217  1.6  mycroft 			hd->hpib_data = sec_par[sec];
    218  1.6  mycroft 			if (nhpibwait(hd, MIS_BO))
    219  1.6  mycroft 				goto recverror;
    220  1.6  mycroft 		}
    221  1.6  mycroft 		hd->hpib_acr = AUX_RHDF;
    222  1.6  mycroft 		hd->hpib_acr = AUX_GTS;
    223  1.1      cgd 	}
    224  1.1      cgd 	if (cnt) {
    225  1.1      cgd 		while (--cnt >= 0) {
    226  1.1      cgd 			if (nhpibwait(hd, MIS_BI))
    227  1.1      cgd 				goto recvbyteserror;
    228  1.1      cgd 			*addr++ = hd->hpib_data;
    229  1.1      cgd 		}
    230  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    231  1.6  mycroft 		hd->hpib_data = (slave == 31) ? C_UNA_P : C_UNT_P;
    232  1.1      cgd 		(void) nhpibwait(hd, MIS_BO);
    233  1.1      cgd 	}
    234  1.1      cgd 	return(origcnt);
    235  1.6  mycroft 
    236  1.1      cgd recverror:
    237  1.1      cgd 	nhpibifc(hd);
    238  1.1      cgd recvbyteserror:
    239  1.1      cgd 	return(origcnt - cnt - 1);
    240  1.1      cgd }
    241  1.1      cgd 
    242  1.6  mycroft nhpibgo(unit, slave, sec, addr, count, rw, timo)
    243  1.1      cgd 	register int unit, slave;
    244  1.4  mycroft 	int sec, count, rw;
    245  1.1      cgd 	char *addr;
    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 
    250  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    251  1.1      cgd 	hs->sc_flags |= HPIBF_IO;
    252  1.6  mycroft 	if (timo)
    253  1.6  mycroft 		hs->sc_flags |= HPIBF_TIMO;
    254  1.1      cgd 	if (rw == B_READ)
    255  1.1      cgd 		hs->sc_flags |= HPIBF_READ;
    256  1.1      cgd #ifdef DEBUG
    257  1.1      cgd 	else if (hs->sc_flags & HPIBF_READ) {
    258  1.1      cgd 		printf("nhpibgo: HPIBF_READ still set\n");
    259  1.1      cgd 		hs->sc_flags &= ~HPIBF_READ;
    260  1.1      cgd 	}
    261  1.1      cgd #endif
    262  1.1      cgd 	hs->sc_count = count;
    263  1.1      cgd 	hs->sc_addr = addr;
    264  1.1      cgd 	if (hs->sc_flags & HPIBF_READ) {
    265  1.1      cgd 		hs->sc_curcnt = count;
    266  1.1      cgd 		dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE|DMAGO_READ);
    267  1.1      cgd 		nhpibrecv(unit, slave, sec, 0, 0);
    268  1.1      cgd 		hd->hpib_mim = MIS_END;
    269  1.1      cgd 	} else {
    270  1.1      cgd 		hd->hpib_mim = 0;
    271  1.1      cgd 		if (count < hpibdmathresh) {
    272  1.1      cgd 			hs->sc_curcnt = count;
    273  1.1      cgd 			nhpibsend(unit, slave, sec, addr, count);
    274  1.1      cgd 			nhpibdone(unit);
    275  1.1      cgd 			return;
    276  1.1      cgd 		}
    277  1.1      cgd 		hs->sc_curcnt = --count;
    278  1.1      cgd 		dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE);
    279  1.1      cgd 		nhpibsend(unit, slave, sec, 0, 0);
    280  1.1      cgd 	}
    281  1.1      cgd 	hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq.dq_ctlr);
    282  1.1      cgd }
    283  1.1      cgd 
    284  1.6  mycroft /*
    285  1.6  mycroft  * This timeout can only happen if a DMA read finishes DMAing with the read
    286  1.6  mycroft  * still pending (more data in read transaction than the driver was prepared
    287  1.6  mycroft  * to accept).  At the moment, variable-record tape drives are the only things
    288  1.6  mycroft  * capabale of doing this.  We repeat the necessary code from nhpibintr() -
    289  1.6  mycroft  * easier and quicker than calling nhpibintr() for this special case.
    290  1.6  mycroft  */
    291  1.6  mycroft void
    292  1.6  mycroft nhpibreadtimo(arg)
    293  1.6  mycroft 	void *arg;
    294  1.6  mycroft {
    295  1.6  mycroft 	int unit;
    296  1.6  mycroft 	register struct hpib_softc *hs;
    297  1.6  mycroft 	int s = splbio();
    298  1.6  mycroft 
    299  1.6  mycroft 	unit = (int)arg;
    300  1.6  mycroft 	hs = &hpib_softc[unit];
    301  1.6  mycroft 	if (hs->sc_flags & HPIBF_IO) {
    302  1.6  mycroft 		register struct nhpibdevice *hd;
    303  1.6  mycroft 		register struct devqueue *dq;
    304  1.6  mycroft 
    305  1.6  mycroft 		hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    306  1.6  mycroft 		hd->hpib_mim = 0;
    307  1.6  mycroft 		hd->hpib_acr = AUX_TCA;
    308  1.6  mycroft 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    309  1.6  mycroft 		dmafree(&hs->sc_dq);
    310  1.6  mycroft 		dq = hs->sc_sq.dq_forw;
    311  1.6  mycroft 		(dq->dq_driver->d_intr)(dq->dq_unit);
    312  1.6  mycroft 	}
    313  1.6  mycroft 	(void) splx(s);
    314  1.6  mycroft }
    315  1.6  mycroft 
    316  1.1      cgd nhpibdone(unit)
    317  1.1      cgd 	register int unit;
    318  1.1      cgd {
    319  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    320  1.1      cgd 	register struct nhpibdevice *hd;
    321  1.1      cgd 	register int cnt;
    322  1.1      cgd 
    323  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    324  1.1      cgd 	cnt = hs->sc_curcnt;
    325  1.1      cgd 	hs->sc_addr += cnt;
    326  1.1      cgd 	hs->sc_count -= cnt;
    327  1.1      cgd 	hs->sc_flags |= HPIBF_DONE;
    328  1.1      cgd 	hd->hpib_ie = IDS_IE;
    329  1.6  mycroft 	if (hs->sc_flags & HPIBF_READ) {
    330  1.6  mycroft 		if ((hs->sc_flags & HPIBF_TIMO) &&
    331  1.6  mycroft 		    (hd->hpib_ids & IDS_IR) == 0)
    332  1.6  mycroft 			timeout(nhpibreadtimo, (void *)unit, hz >> 2);
    333  1.6  mycroft 	} else {
    334  1.1      cgd 		if (hs->sc_count == 1) {
    335  1.1      cgd 			(void) nhpibwait(hd, MIS_BO);
    336  1.1      cgd 			hd->hpib_acr = AUX_EOI;
    337  1.1      cgd 			hd->hpib_data = *hs->sc_addr;
    338  1.1      cgd 			hd->hpib_mim = MIS_BO;
    339  1.1      cgd 		}
    340  1.1      cgd #ifdef DEBUG
    341  1.1      cgd 		else if (hs->sc_count)
    342  1.1      cgd 			panic("nhpibdone");
    343  1.1      cgd #endif
    344  1.1      cgd 	}
    345  1.1      cgd }
    346  1.1      cgd 
    347  1.1      cgd nhpibintr(unit)
    348  1.1      cgd 	register int unit;
    349  1.1      cgd {
    350  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    351  1.1      cgd 	register struct nhpibdevice *hd;
    352  1.1      cgd 	register struct devqueue *dq;
    353  1.1      cgd 	register int stat0;
    354  1.1      cgd 	int stat1;
    355  1.1      cgd 
    356  1.1      cgd #ifdef lint
    357  1.1      cgd 	if (stat1 = unit) return(1);
    358  1.1      cgd #endif
    359  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    360  1.1      cgd 	if ((hd->hpib_ids & IDS_IR) == 0)
    361  1.1      cgd 		return(0);
    362  1.1      cgd 	stat0 = hd->hpib_mis;
    363  1.1      cgd 	stat1 = hd->hpib_lis;
    364  1.1      cgd 	dq = hs->sc_sq.dq_forw;
    365  1.1      cgd 	if (hs->sc_flags & HPIBF_IO) {
    366  1.1      cgd 		hd->hpib_mim = 0;
    367  1.6  mycroft 		if ((hs->sc_flags & HPIBF_DONE) == 0) {
    368  1.6  mycroft 			hs->sc_flags &= ~HPIBF_TIMO;
    369  1.1      cgd 			dmastop(hs->sc_dq.dq_ctlr);
    370  1.6  mycroft 		} else if (hs->sc_flags & HPIBF_TIMO)
    371  1.6  mycroft 			untimeout(nhpibreadtimo, (void *)unit);
    372  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    373  1.6  mycroft 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
    374  1.1      cgd 		dmafree(&hs->sc_dq);
    375  1.1      cgd 		(dq->dq_driver->d_intr)(dq->dq_unit);
    376  1.1      cgd 	} else if (hs->sc_flags & HPIBF_PPOLL) {
    377  1.1      cgd 		hd->hpib_mim = 0;
    378  1.1      cgd 		stat0 = nhpibppoll(unit);
    379  1.1      cgd 		if (stat0 & (0x80 >> dq->dq_slave)) {
    380  1.1      cgd 			hs->sc_flags &= ~HPIBF_PPOLL;
    381  1.1      cgd 			(dq->dq_driver->d_intr)(dq->dq_unit);
    382  1.1      cgd 		}
    383  1.1      cgd #ifdef DEBUG
    384  1.1      cgd 		else
    385  1.1      cgd 			printf("hpib%d: PPOLL intr bad status %x\n",
    386  1.1      cgd 			       unit, stat0);
    387  1.1      cgd #endif
    388  1.1      cgd 	}
    389  1.1      cgd 	return(1);
    390  1.1      cgd }
    391  1.1      cgd 
    392  1.1      cgd nhpibppoll(unit)
    393  1.1      cgd 	int unit;
    394  1.1      cgd {
    395  1.1      cgd 	register struct nhpibdevice *hd;
    396  1.1      cgd 	register int ppoll;
    397  1.1      cgd 
    398  1.1      cgd 	hd = (struct nhpibdevice *)hpib_softc[unit].sc_hc->hp_addr;
    399  1.1      cgd 	hd->hpib_acr = AUX_SPP;
    400  1.1      cgd 	DELAY(25);
    401  1.1      cgd 	ppoll = hd->hpib_cpt;
    402  1.1      cgd 	hd->hpib_acr = AUX_CPP;
    403  1.1      cgd 	return(ppoll);
    404  1.1      cgd }
    405  1.1      cgd 
    406  1.6  mycroft #ifdef DEBUG
    407  1.6  mycroft int nhpibreporttimo = 0;
    408  1.6  mycroft #endif
    409  1.6  mycroft 
    410  1.1      cgd nhpibwait(hd, x)
    411  1.1      cgd 	register struct nhpibdevice *hd;
    412  1.4  mycroft 	int x;
    413  1.1      cgd {
    414  1.1      cgd 	register int timo = hpibtimeout;
    415  1.1      cgd 
    416  1.1      cgd 	while ((hd->hpib_mis & x) == 0 && --timo)
    417  1.1      cgd 		DELAY(1);
    418  1.6  mycroft 	if (timo == 0) {
    419  1.6  mycroft #ifdef DEBUG
    420  1.6  mycroft 		if (nhpibreporttimo)
    421  1.6  mycroft 			printf("hpib0: %s timo\n", x==MIS_BO?"OUT":"IN");
    422  1.6  mycroft #endif
    423  1.1      cgd 		return(-1);
    424  1.6  mycroft 	}
    425  1.1      cgd 	return(0);
    426  1.1      cgd }
    427  1.1      cgd 
    428  1.4  mycroft void
    429  1.3  mycroft nhpibppwatch(arg)
    430  1.3  mycroft 	void *arg;
    431  1.1      cgd {
    432  1.4  mycroft 	register struct hpib_softc *hs;
    433  1.4  mycroft 	register int unit;
    434  1.4  mycroft 	extern int cold;
    435  1.1      cgd 
    436  1.4  mycroft 	unit = (int)arg;
    437  1.4  mycroft 	hs = &hpib_softc[unit];
    438  1.1      cgd 	if ((hs->sc_flags & HPIBF_PPOLL) == 0)
    439  1.1      cgd 		return;
    440  1.4  mycroft again:
    441  1.1      cgd 	if (nhpibppoll(unit) & (0x80 >> hs->sc_sq.dq_forw->dq_slave))
    442  1.1      cgd        		((struct nhpibdevice *)hs->sc_hc->hp_addr)->hpib_mim = MIS_BO;
    443  1.4  mycroft 	else if (cold)
    444  1.4  mycroft 		/* timeouts not working yet */
    445  1.4  mycroft 		goto again;
    446  1.1      cgd 	else
    447  1.3  mycroft 		timeout(nhpibppwatch, (void *)unit, 1);
    448  1.1      cgd }
    449  1.1      cgd #endif
    450