Home | History | Annotate | Line # | Download | only in dev
nhpib.c revision 1.4
      1  1.1      cgd /*
      2  1.4  mycroft  * Copyright (c) 1982, 1990, 1993
      3  1.4  mycroft  *	The Regents of the University of California.  All rights reserved.
      4  1.1      cgd  *
      5  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1      cgd  * modification, are permitted provided that the following conditions
      7  1.1      cgd  * are met:
      8  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1      cgd  *    must display the following acknowledgement:
     15  1.1      cgd  *	This product includes software developed by the University of
     16  1.1      cgd  *	California, Berkeley and its contributors.
     17  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1      cgd  *    may be used to endorse or promote products derived from this software
     19  1.1      cgd  *    without specific prior written permission.
     20  1.1      cgd  *
     21  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1      cgd  * SUCH DAMAGE.
     32  1.1      cgd  *
     33  1.4  mycroft  *	from: @(#)nhpib.c	8.2 (Berkeley) 1/12/94
     34  1.4  mycroft  *	$Id: nhpib.c,v 1.4 1994/05/23 05:59:10 mycroft Exp $
     35  1.1      cgd  */
     36  1.1      cgd 
     37  1.1      cgd /*
     38  1.1      cgd  * Internal/98624 HPIB driver
     39  1.1      cgd  */
     40  1.1      cgd #include "hpib.h"
     41  1.1      cgd #if NHPIB > 0
     42  1.1      cgd 
     43  1.4  mycroft #include <sys/param.h>
     44  1.4  mycroft #include <sys/systm.h>
     45  1.4  mycroft #include <sys/buf.h>
     46  1.4  mycroft 
     47  1.4  mycroft #include <hp300/dev/device.h>
     48  1.4  mycroft #include <hp300/dev/nhpibreg.h>
     49  1.4  mycroft #include <hp300/dev/hpibvar.h>
     50  1.4  mycroft #include <hp300/dev/dmavar.h>
     51  1.1      cgd 
     52  1.1      cgd nhpibtype(hc)
     53  1.1      cgd 	register struct hp_ctlr *hc;
     54  1.1      cgd {
     55  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
     56  1.1      cgd 	register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
     57  1.1      cgd 
     58  1.1      cgd 	if (hc->hp_addr == internalhpib) {
     59  1.1      cgd 		hs->sc_type = HPIBA;
     60  1.1      cgd 		hs->sc_ba = HPIBA_BA;
     61  1.1      cgd 		hc->hp_ipl = HPIBA_IPL;
     62  1.1      cgd 	}
     63  1.1      cgd 	else if (hd->hpib_cid == HPIBB) {
     64  1.1      cgd 		hs->sc_type = HPIBB;
     65  1.1      cgd 		hs->sc_ba = hd->hpib_csa & CSA_BA;
     66  1.1      cgd 		hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
     67  1.1      cgd 	}
     68  1.1      cgd 	else
     69  1.1      cgd 		return(0);
     70  1.1      cgd 	return(1);
     71  1.1      cgd }
     72  1.1      cgd 
     73  1.1      cgd nhpibreset(unit)
     74  1.4  mycroft 	int unit;
     75  1.1      cgd {
     76  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
     77  1.1      cgd 	register struct nhpibdevice *hd;
     78  1.1      cgd 
     79  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
     80  1.1      cgd 	hd->hpib_acr = AUX_SSWRST;
     81  1.1      cgd 	hd->hpib_ar = hs->sc_ba;
     82  1.1      cgd 	hd->hpib_lim = LIS_ERR;
     83  1.1      cgd 	hd->hpib_mim = 0;
     84  1.1      cgd 	hd->hpib_acr = AUX_CDAI;
     85  1.1      cgd 	hd->hpib_acr = AUX_CSHDW;
     86  1.1      cgd 	hd->hpib_acr = AUX_SSTD1;
     87  1.1      cgd 	hd->hpib_acr = AUX_SVSTD1;
     88  1.1      cgd 	hd->hpib_acr = AUX_CPP;
     89  1.1      cgd 	hd->hpib_acr = AUX_CHDFA;
     90  1.1      cgd 	hd->hpib_acr = AUX_CHDFE;
     91  1.1      cgd 	hd->hpib_acr = AUX_RHDF;
     92  1.1      cgd 	hd->hpib_acr = AUX_CSWRST;
     93  1.1      cgd 	nhpibifc(hd);
     94  1.1      cgd 	hd->hpib_ie = IDS_IE;
     95  1.1      cgd 	hd->hpib_data = C_DCL;
     96  1.1      cgd 	DELAY(100000);
     97  1.1      cgd }
     98  1.1      cgd 
     99  1.1      cgd nhpibifc(hd)
    100  1.1      cgd 	register struct nhpibdevice *hd;
    101  1.1      cgd {
    102  1.1      cgd 	hd->hpib_acr = AUX_TCA;
    103  1.1      cgd 	hd->hpib_acr = AUX_CSRE;
    104  1.1      cgd 	hd->hpib_acr = AUX_SSIC;
    105  1.1      cgd 	DELAY(100);
    106  1.1      cgd 	hd->hpib_acr = AUX_CSIC;
    107  1.1      cgd 	hd->hpib_acr = AUX_SSRE;
    108  1.1      cgd }
    109  1.1      cgd 
    110  1.1      cgd nhpibsend(unit, slave, sec, addr, origcnt)
    111  1.4  mycroft 	int unit, slave, sec, origcnt;
    112  1.1      cgd 	register char *addr;
    113  1.1      cgd {
    114  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    115  1.1      cgd 	register struct nhpibdevice *hd;
    116  1.1      cgd 	register int cnt = origcnt;
    117  1.1      cgd 
    118  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    119  1.1      cgd 	hd->hpib_acr = AUX_TCA;
    120  1.1      cgd 	hd->hpib_data = C_UNL;
    121  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    122  1.1      cgd 		goto senderror;
    123  1.1      cgd 	hd->hpib_data = C_TAG + hs->sc_ba;
    124  1.1      cgd 	hd->hpib_acr = AUX_STON;
    125  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    126  1.1      cgd 		goto senderror;
    127  1.1      cgd 	hd->hpib_data = C_LAG + slave;
    128  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    129  1.1      cgd 		goto senderror;
    130  1.1      cgd 	if (sec != -1) {
    131  1.1      cgd 		hd->hpib_data = C_SCG + sec;
    132  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    133  1.1      cgd 			goto senderror;
    134  1.1      cgd 	}
    135  1.1      cgd 	hd->hpib_acr = AUX_GTS;
    136  1.1      cgd 	if (cnt) {
    137  1.1      cgd 		while (--cnt > 0) {
    138  1.1      cgd 			hd->hpib_data = *addr++;
    139  1.1      cgd 			if (nhpibwait(hd, MIS_BO))
    140  1.1      cgd 				goto senderror;
    141  1.1      cgd 		}
    142  1.1      cgd 		hd->hpib_acr = AUX_EOI;
    143  1.1      cgd 		hd->hpib_data = *addr;
    144  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    145  1.1      cgd 			goto senderror;
    146  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    147  1.1      cgd #if 0
    148  1.1      cgd 		/*
    149  1.1      cgd 		 * May be causing 345 disks to hang due to interference
    150  1.1      cgd 		 * with PPOLL mechanism.
    151  1.1      cgd 		 */
    152  1.1      cgd 		hd->hpib_data = C_UNL;
    153  1.1      cgd 		(void) nhpibwait(hd, MIS_BO);
    154  1.1      cgd #endif
    155  1.1      cgd 	}
    156  1.1      cgd 	return(origcnt);
    157  1.1      cgd senderror:
    158  1.1      cgd 	nhpibifc(hd);
    159  1.1      cgd 	return(origcnt - cnt - 1);
    160  1.1      cgd }
    161  1.1      cgd 
    162  1.1      cgd nhpibrecv(unit, slave, sec, addr, origcnt)
    163  1.4  mycroft 	int unit, slave, sec, origcnt;
    164  1.1      cgd 	register char *addr;
    165  1.1      cgd {
    166  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    167  1.1      cgd 	register struct nhpibdevice *hd;
    168  1.1      cgd 	register int cnt = origcnt;
    169  1.1      cgd 
    170  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    171  1.1      cgd 	hd->hpib_acr = AUX_TCA;
    172  1.1      cgd 	hd->hpib_data = C_UNL;
    173  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    174  1.1      cgd 		goto recverror;
    175  1.1      cgd 	hd->hpib_data = C_LAG + hs->sc_ba;
    176  1.1      cgd 	hd->hpib_acr = AUX_SLON;
    177  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    178  1.1      cgd 		goto recverror;
    179  1.1      cgd 	hd->hpib_data = C_TAG + slave;
    180  1.1      cgd 	if (nhpibwait(hd, MIS_BO))
    181  1.1      cgd 		goto recverror;
    182  1.1      cgd 	if (sec != -1) {
    183  1.1      cgd 		hd->hpib_data = C_SCG + sec;
    184  1.1      cgd 		if (nhpibwait(hd, MIS_BO))
    185  1.1      cgd 			goto recverror;
    186  1.1      cgd 	}
    187  1.1      cgd 	hd->hpib_acr = AUX_RHDF;
    188  1.1      cgd 	hd->hpib_acr = AUX_GTS;
    189  1.1      cgd 	if (cnt) {
    190  1.1      cgd 		while (--cnt >= 0) {
    191  1.1      cgd 			if (nhpibwait(hd, MIS_BI))
    192  1.1      cgd 				goto recvbyteserror;
    193  1.1      cgd 			*addr++ = hd->hpib_data;
    194  1.1      cgd 		}
    195  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    196  1.1      cgd 		hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
    197  1.1      cgd 		(void) nhpibwait(hd, MIS_BO);
    198  1.1      cgd 	}
    199  1.1      cgd 	return(origcnt);
    200  1.1      cgd recverror:
    201  1.1      cgd 	nhpibifc(hd);
    202  1.1      cgd recvbyteserror:
    203  1.1      cgd 	return(origcnt - cnt - 1);
    204  1.1      cgd }
    205  1.1      cgd 
    206  1.1      cgd nhpibgo(unit, slave, sec, addr, count, rw)
    207  1.1      cgd 	register int unit, slave;
    208  1.4  mycroft 	int sec, count, rw;
    209  1.1      cgd 	char *addr;
    210  1.1      cgd {
    211  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    212  1.1      cgd 	register struct nhpibdevice *hd;
    213  1.1      cgd 
    214  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    215  1.1      cgd 	hs->sc_flags |= HPIBF_IO;
    216  1.1      cgd 	if (rw == B_READ)
    217  1.1      cgd 		hs->sc_flags |= HPIBF_READ;
    218  1.1      cgd #ifdef DEBUG
    219  1.1      cgd 	else if (hs->sc_flags & HPIBF_READ) {
    220  1.1      cgd 		printf("nhpibgo: HPIBF_READ still set\n");
    221  1.1      cgd 		hs->sc_flags &= ~HPIBF_READ;
    222  1.1      cgd 	}
    223  1.1      cgd #endif
    224  1.1      cgd 	hs->sc_count = count;
    225  1.1      cgd 	hs->sc_addr = addr;
    226  1.1      cgd 	if (hs->sc_flags & HPIBF_READ) {
    227  1.1      cgd 		hs->sc_curcnt = count;
    228  1.1      cgd 		dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE|DMAGO_READ);
    229  1.1      cgd 		nhpibrecv(unit, slave, sec, 0, 0);
    230  1.1      cgd 		hd->hpib_mim = MIS_END;
    231  1.1      cgd 	} else {
    232  1.1      cgd 		hd->hpib_mim = 0;
    233  1.1      cgd 		if (count < hpibdmathresh) {
    234  1.1      cgd 			hs->sc_curcnt = count;
    235  1.1      cgd 			nhpibsend(unit, slave, sec, addr, count);
    236  1.1      cgd 			nhpibdone(unit);
    237  1.1      cgd 			return;
    238  1.1      cgd 		}
    239  1.1      cgd 		hs->sc_curcnt = --count;
    240  1.1      cgd 		dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE);
    241  1.1      cgd 		nhpibsend(unit, slave, sec, 0, 0);
    242  1.1      cgd 	}
    243  1.1      cgd 	hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq.dq_ctlr);
    244  1.1      cgd }
    245  1.1      cgd 
    246  1.1      cgd nhpibdone(unit)
    247  1.1      cgd 	register int unit;
    248  1.1      cgd {
    249  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    250  1.1      cgd 	register struct nhpibdevice *hd;
    251  1.1      cgd 	register int cnt;
    252  1.1      cgd 
    253  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    254  1.1      cgd 	cnt = hs->sc_curcnt;
    255  1.1      cgd 	hs->sc_addr += cnt;
    256  1.1      cgd 	hs->sc_count -= cnt;
    257  1.1      cgd 	hs->sc_flags |= HPIBF_DONE;
    258  1.1      cgd 	hd->hpib_ie = IDS_IE;
    259  1.1      cgd 	if ((hs->sc_flags & HPIBF_READ) == 0) {
    260  1.1      cgd 		if (hs->sc_count == 1) {
    261  1.1      cgd 			(void) nhpibwait(hd, MIS_BO);
    262  1.1      cgd 			hd->hpib_acr = AUX_EOI;
    263  1.1      cgd 			hd->hpib_data = *hs->sc_addr;
    264  1.1      cgd 			hd->hpib_mim = MIS_BO;
    265  1.1      cgd 		}
    266  1.1      cgd #ifdef DEBUG
    267  1.1      cgd 		else if (hs->sc_count)
    268  1.1      cgd 			panic("nhpibdone");
    269  1.1      cgd #endif
    270  1.1      cgd 	}
    271  1.1      cgd }
    272  1.1      cgd 
    273  1.1      cgd nhpibintr(unit)
    274  1.1      cgd 	register int unit;
    275  1.1      cgd {
    276  1.1      cgd 	register struct hpib_softc *hs = &hpib_softc[unit];
    277  1.1      cgd 	register struct nhpibdevice *hd;
    278  1.1      cgd 	register struct devqueue *dq;
    279  1.1      cgd 	register int stat0;
    280  1.1      cgd 	int stat1;
    281  1.1      cgd 
    282  1.1      cgd #ifdef lint
    283  1.1      cgd 	if (stat1 = unit) return(1);
    284  1.1      cgd #endif
    285  1.1      cgd 	hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
    286  1.1      cgd 	if ((hd->hpib_ids & IDS_IR) == 0)
    287  1.1      cgd 		return(0);
    288  1.1      cgd 	stat0 = hd->hpib_mis;
    289  1.1      cgd 	stat1 = hd->hpib_lis;
    290  1.1      cgd 	dq = hs->sc_sq.dq_forw;
    291  1.1      cgd 	if (hs->sc_flags & HPIBF_IO) {
    292  1.1      cgd 		hd->hpib_mim = 0;
    293  1.1      cgd 		if ((hs->sc_flags & HPIBF_DONE) == 0)
    294  1.1      cgd 			dmastop(hs->sc_dq.dq_ctlr);
    295  1.1      cgd 		hd->hpib_acr = AUX_TCA;
    296  1.1      cgd 		hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ);
    297  1.1      cgd 		dmafree(&hs->sc_dq);
    298  1.1      cgd 		(dq->dq_driver->d_intr)(dq->dq_unit);
    299  1.1      cgd 	} else if (hs->sc_flags & HPIBF_PPOLL) {
    300  1.1      cgd 		hd->hpib_mim = 0;
    301  1.1      cgd 		stat0 = nhpibppoll(unit);
    302  1.1      cgd 		if (stat0 & (0x80 >> dq->dq_slave)) {
    303  1.1      cgd 			hs->sc_flags &= ~HPIBF_PPOLL;
    304  1.1      cgd 			(dq->dq_driver->d_intr)(dq->dq_unit);
    305  1.1      cgd 		}
    306  1.1      cgd #ifdef DEBUG
    307  1.1      cgd 		else
    308  1.1      cgd 			printf("hpib%d: PPOLL intr bad status %x\n",
    309  1.1      cgd 			       unit, stat0);
    310  1.1      cgd #endif
    311  1.1      cgd 	}
    312  1.1      cgd 	return(1);
    313  1.1      cgd }
    314  1.1      cgd 
    315  1.1      cgd nhpibppoll(unit)
    316  1.1      cgd 	int unit;
    317  1.1      cgd {
    318  1.1      cgd 	register struct nhpibdevice *hd;
    319  1.1      cgd 	register int ppoll;
    320  1.1      cgd 
    321  1.1      cgd 	hd = (struct nhpibdevice *)hpib_softc[unit].sc_hc->hp_addr;
    322  1.1      cgd 	hd->hpib_acr = AUX_SPP;
    323  1.1      cgd 	DELAY(25);
    324  1.1      cgd 	ppoll = hd->hpib_cpt;
    325  1.1      cgd 	hd->hpib_acr = AUX_CPP;
    326  1.1      cgd 	return(ppoll);
    327  1.1      cgd }
    328  1.1      cgd 
    329  1.1      cgd nhpibwait(hd, x)
    330  1.1      cgd 	register struct nhpibdevice *hd;
    331  1.4  mycroft 	int x;
    332  1.1      cgd {
    333  1.1      cgd 	register int timo = hpibtimeout;
    334  1.1      cgd 
    335  1.1      cgd 	while ((hd->hpib_mis & x) == 0 && --timo)
    336  1.1      cgd 		DELAY(1);
    337  1.1      cgd 	if (timo == 0)
    338  1.1      cgd 		return(-1);
    339  1.1      cgd 	return(0);
    340  1.1      cgd }
    341  1.1      cgd 
    342  1.4  mycroft void
    343  1.3  mycroft nhpibppwatch(arg)
    344  1.3  mycroft 	void *arg;
    345  1.1      cgd {
    346  1.4  mycroft 	register struct hpib_softc *hs;
    347  1.4  mycroft 	register int unit;
    348  1.4  mycroft 	extern int cold;
    349  1.1      cgd 
    350  1.4  mycroft 	unit = (int)arg;
    351  1.4  mycroft 	hs = &hpib_softc[unit];
    352  1.1      cgd 	if ((hs->sc_flags & HPIBF_PPOLL) == 0)
    353  1.1      cgd 		return;
    354  1.4  mycroft again:
    355  1.1      cgd 	if (nhpibppoll(unit) & (0x80 >> hs->sc_sq.dq_forw->dq_slave))
    356  1.1      cgd        		((struct nhpibdevice *)hs->sc_hc->hp_addr)->hpib_mim = MIS_BO;
    357  1.4  mycroft 	else if (cold)
    358  1.4  mycroft 		/* timeouts not working yet */
    359  1.4  mycroft 		goto again;
    360  1.1      cgd 	else
    361  1.3  mycroft 		timeout(nhpibppwatch, (void *)unit, 1);
    362  1.1      cgd }
    363  1.1      cgd #endif
    364