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