nhpib.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1982, 1990 The Regents of the University of California.
3 1.1 cgd * 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.1 cgd * @(#)nhpib.c 7.4 (Berkeley) 5/7/91
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd /*
37 1.1 cgd * Internal/98624 HPIB driver
38 1.1 cgd */
39 1.1 cgd #include "hpib.h"
40 1.1 cgd #if NHPIB > 0
41 1.1 cgd
42 1.1 cgd #include "sys/param.h"
43 1.1 cgd #include "sys/systm.h"
44 1.1 cgd #include "sys/buf.h"
45 1.1 cgd
46 1.1 cgd #include "device.h"
47 1.1 cgd #include "nhpibreg.h"
48 1.1 cgd #include "hpibvar.h"
49 1.1 cgd #include "dmavar.h"
50 1.1 cgd
51 1.1 cgd nhpibtype(hc)
52 1.1 cgd register struct hp_ctlr *hc;
53 1.1 cgd {
54 1.1 cgd register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
55 1.1 cgd register struct nhpibdevice *hd = (struct nhpibdevice *)hc->hp_addr;
56 1.1 cgd
57 1.1 cgd if (hc->hp_addr == internalhpib) {
58 1.1 cgd hs->sc_type = HPIBA;
59 1.1 cgd hs->sc_ba = HPIBA_BA;
60 1.1 cgd hc->hp_ipl = HPIBA_IPL;
61 1.1 cgd }
62 1.1 cgd else if (hd->hpib_cid == HPIBB) {
63 1.1 cgd hs->sc_type = HPIBB;
64 1.1 cgd hs->sc_ba = hd->hpib_csa & CSA_BA;
65 1.1 cgd hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
66 1.1 cgd }
67 1.1 cgd else
68 1.1 cgd return(0);
69 1.1 cgd return(1);
70 1.1 cgd }
71 1.1 cgd
72 1.1 cgd nhpibreset(unit)
73 1.1 cgd {
74 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
75 1.1 cgd register struct nhpibdevice *hd;
76 1.1 cgd
77 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
78 1.1 cgd hd->hpib_acr = AUX_SSWRST;
79 1.1 cgd hd->hpib_ar = hs->sc_ba;
80 1.1 cgd hd->hpib_lim = LIS_ERR;
81 1.1 cgd hd->hpib_mim = 0;
82 1.1 cgd hd->hpib_acr = AUX_CDAI;
83 1.1 cgd hd->hpib_acr = AUX_CSHDW;
84 1.1 cgd hd->hpib_acr = AUX_SSTD1;
85 1.1 cgd hd->hpib_acr = AUX_SVSTD1;
86 1.1 cgd hd->hpib_acr = AUX_CPP;
87 1.1 cgd hd->hpib_acr = AUX_CHDFA;
88 1.1 cgd hd->hpib_acr = AUX_CHDFE;
89 1.1 cgd hd->hpib_acr = AUX_RHDF;
90 1.1 cgd hd->hpib_acr = AUX_CSWRST;
91 1.1 cgd nhpibifc(hd);
92 1.1 cgd hd->hpib_ie = IDS_IE;
93 1.1 cgd hd->hpib_data = C_DCL;
94 1.1 cgd DELAY(100000);
95 1.1 cgd }
96 1.1 cgd
97 1.1 cgd nhpibifc(hd)
98 1.1 cgd register struct nhpibdevice *hd;
99 1.1 cgd {
100 1.1 cgd hd->hpib_acr = AUX_TCA;
101 1.1 cgd hd->hpib_acr = AUX_CSRE;
102 1.1 cgd hd->hpib_acr = AUX_SSIC;
103 1.1 cgd DELAY(100);
104 1.1 cgd hd->hpib_acr = AUX_CSIC;
105 1.1 cgd hd->hpib_acr = AUX_SSRE;
106 1.1 cgd }
107 1.1 cgd
108 1.1 cgd nhpibsend(unit, slave, sec, addr, origcnt)
109 1.1 cgd register char *addr;
110 1.1 cgd {
111 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
112 1.1 cgd register struct nhpibdevice *hd;
113 1.1 cgd register int cnt = origcnt;
114 1.1 cgd
115 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
116 1.1 cgd hd->hpib_acr = AUX_TCA;
117 1.1 cgd hd->hpib_data = C_UNL;
118 1.1 cgd if (nhpibwait(hd, MIS_BO))
119 1.1 cgd goto senderror;
120 1.1 cgd hd->hpib_data = C_TAG + hs->sc_ba;
121 1.1 cgd hd->hpib_acr = AUX_STON;
122 1.1 cgd if (nhpibwait(hd, MIS_BO))
123 1.1 cgd goto senderror;
124 1.1 cgd hd->hpib_data = C_LAG + slave;
125 1.1 cgd if (nhpibwait(hd, MIS_BO))
126 1.1 cgd goto senderror;
127 1.1 cgd if (sec != -1) {
128 1.1 cgd hd->hpib_data = C_SCG + sec;
129 1.1 cgd if (nhpibwait(hd, MIS_BO))
130 1.1 cgd goto senderror;
131 1.1 cgd }
132 1.1 cgd hd->hpib_acr = AUX_GTS;
133 1.1 cgd if (cnt) {
134 1.1 cgd while (--cnt > 0) {
135 1.1 cgd hd->hpib_data = *addr++;
136 1.1 cgd if (nhpibwait(hd, MIS_BO))
137 1.1 cgd goto senderror;
138 1.1 cgd }
139 1.1 cgd hd->hpib_acr = AUX_EOI;
140 1.1 cgd hd->hpib_data = *addr;
141 1.1 cgd if (nhpibwait(hd, MIS_BO))
142 1.1 cgd goto senderror;
143 1.1 cgd hd->hpib_acr = AUX_TCA;
144 1.1 cgd #if 0
145 1.1 cgd /*
146 1.1 cgd * May be causing 345 disks to hang due to interference
147 1.1 cgd * with PPOLL mechanism.
148 1.1 cgd */
149 1.1 cgd hd->hpib_data = C_UNL;
150 1.1 cgd (void) nhpibwait(hd, MIS_BO);
151 1.1 cgd #endif
152 1.1 cgd }
153 1.1 cgd return(origcnt);
154 1.1 cgd senderror:
155 1.1 cgd nhpibifc(hd);
156 1.1 cgd return(origcnt - cnt - 1);
157 1.1 cgd }
158 1.1 cgd
159 1.1 cgd nhpibrecv(unit, slave, sec, addr, origcnt)
160 1.1 cgd register char *addr;
161 1.1 cgd {
162 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
163 1.1 cgd register struct nhpibdevice *hd;
164 1.1 cgd register int cnt = origcnt;
165 1.1 cgd
166 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
167 1.1 cgd hd->hpib_acr = AUX_TCA;
168 1.1 cgd hd->hpib_data = C_UNL;
169 1.1 cgd if (nhpibwait(hd, MIS_BO))
170 1.1 cgd goto recverror;
171 1.1 cgd hd->hpib_data = C_LAG + hs->sc_ba;
172 1.1 cgd hd->hpib_acr = AUX_SLON;
173 1.1 cgd if (nhpibwait(hd, MIS_BO))
174 1.1 cgd goto recverror;
175 1.1 cgd hd->hpib_data = C_TAG + slave;
176 1.1 cgd if (nhpibwait(hd, MIS_BO))
177 1.1 cgd goto recverror;
178 1.1 cgd if (sec != -1) {
179 1.1 cgd hd->hpib_data = C_SCG + sec;
180 1.1 cgd if (nhpibwait(hd, MIS_BO))
181 1.1 cgd goto recverror;
182 1.1 cgd }
183 1.1 cgd hd->hpib_acr = AUX_RHDF;
184 1.1 cgd hd->hpib_acr = AUX_GTS;
185 1.1 cgd if (cnt) {
186 1.1 cgd while (--cnt >= 0) {
187 1.1 cgd if (nhpibwait(hd, MIS_BI))
188 1.1 cgd goto recvbyteserror;
189 1.1 cgd *addr++ = hd->hpib_data;
190 1.1 cgd }
191 1.1 cgd hd->hpib_acr = AUX_TCA;
192 1.1 cgd hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
193 1.1 cgd (void) nhpibwait(hd, MIS_BO);
194 1.1 cgd }
195 1.1 cgd return(origcnt);
196 1.1 cgd recverror:
197 1.1 cgd nhpibifc(hd);
198 1.1 cgd recvbyteserror:
199 1.1 cgd return(origcnt - cnt - 1);
200 1.1 cgd }
201 1.1 cgd
202 1.1 cgd nhpibgo(unit, slave, sec, addr, count, rw)
203 1.1 cgd register int unit, slave;
204 1.1 cgd char *addr;
205 1.1 cgd {
206 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
207 1.1 cgd register struct nhpibdevice *hd;
208 1.1 cgd
209 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
210 1.1 cgd hs->sc_flags |= HPIBF_IO;
211 1.1 cgd if (rw == B_READ)
212 1.1 cgd hs->sc_flags |= HPIBF_READ;
213 1.1 cgd #ifdef DEBUG
214 1.1 cgd else if (hs->sc_flags & HPIBF_READ) {
215 1.1 cgd printf("nhpibgo: HPIBF_READ still set\n");
216 1.1 cgd hs->sc_flags &= ~HPIBF_READ;
217 1.1 cgd }
218 1.1 cgd #endif
219 1.1 cgd hs->sc_count = count;
220 1.1 cgd hs->sc_addr = addr;
221 1.1 cgd if (hs->sc_flags & HPIBF_READ) {
222 1.1 cgd hs->sc_curcnt = count;
223 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE|DMAGO_READ);
224 1.1 cgd nhpibrecv(unit, slave, sec, 0, 0);
225 1.1 cgd hd->hpib_mim = MIS_END;
226 1.1 cgd } else {
227 1.1 cgd hd->hpib_mim = 0;
228 1.1 cgd if (count < hpibdmathresh) {
229 1.1 cgd hs->sc_curcnt = count;
230 1.1 cgd nhpibsend(unit, slave, sec, addr, count);
231 1.1 cgd nhpibdone(unit);
232 1.1 cgd return;
233 1.1 cgd }
234 1.1 cgd hs->sc_curcnt = --count;
235 1.1 cgd dmago(hs->sc_dq.dq_ctlr, addr, count, DMAGO_BYTE);
236 1.1 cgd nhpibsend(unit, slave, sec, 0, 0);
237 1.1 cgd }
238 1.1 cgd hd->hpib_ie = IDS_IE | IDS_DMA(hs->sc_dq.dq_ctlr);
239 1.1 cgd }
240 1.1 cgd
241 1.1 cgd nhpibdone(unit)
242 1.1 cgd register int unit;
243 1.1 cgd {
244 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
245 1.1 cgd register struct nhpibdevice *hd;
246 1.1 cgd register int cnt;
247 1.1 cgd
248 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
249 1.1 cgd cnt = hs->sc_curcnt;
250 1.1 cgd hs->sc_addr += cnt;
251 1.1 cgd hs->sc_count -= cnt;
252 1.1 cgd hs->sc_flags |= HPIBF_DONE;
253 1.1 cgd hd->hpib_ie = IDS_IE;
254 1.1 cgd if ((hs->sc_flags & HPIBF_READ) == 0) {
255 1.1 cgd if (hs->sc_count == 1) {
256 1.1 cgd (void) nhpibwait(hd, MIS_BO);
257 1.1 cgd hd->hpib_acr = AUX_EOI;
258 1.1 cgd hd->hpib_data = *hs->sc_addr;
259 1.1 cgd hd->hpib_mim = MIS_BO;
260 1.1 cgd }
261 1.1 cgd #ifdef DEBUG
262 1.1 cgd else if (hs->sc_count)
263 1.1 cgd panic("nhpibdone");
264 1.1 cgd #endif
265 1.1 cgd }
266 1.1 cgd }
267 1.1 cgd
268 1.1 cgd nhpibintr(unit)
269 1.1 cgd register int unit;
270 1.1 cgd {
271 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
272 1.1 cgd register struct nhpibdevice *hd;
273 1.1 cgd register struct devqueue *dq;
274 1.1 cgd register int stat0;
275 1.1 cgd int stat1;
276 1.1 cgd
277 1.1 cgd #ifdef lint
278 1.1 cgd if (stat1 = unit) return(1);
279 1.1 cgd #endif
280 1.1 cgd hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
281 1.1 cgd if ((hd->hpib_ids & IDS_IR) == 0)
282 1.1 cgd return(0);
283 1.1 cgd stat0 = hd->hpib_mis;
284 1.1 cgd stat1 = hd->hpib_lis;
285 1.1 cgd dq = hs->sc_sq.dq_forw;
286 1.1 cgd if (hs->sc_flags & HPIBF_IO) {
287 1.1 cgd hd->hpib_mim = 0;
288 1.1 cgd if ((hs->sc_flags & HPIBF_DONE) == 0)
289 1.1 cgd dmastop(hs->sc_dq.dq_ctlr);
290 1.1 cgd hd->hpib_acr = AUX_TCA;
291 1.1 cgd hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ);
292 1.1 cgd dmafree(&hs->sc_dq);
293 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
294 1.1 cgd } else if (hs->sc_flags & HPIBF_PPOLL) {
295 1.1 cgd hd->hpib_mim = 0;
296 1.1 cgd stat0 = nhpibppoll(unit);
297 1.1 cgd if (stat0 & (0x80 >> dq->dq_slave)) {
298 1.1 cgd hs->sc_flags &= ~HPIBF_PPOLL;
299 1.1 cgd (dq->dq_driver->d_intr)(dq->dq_unit);
300 1.1 cgd }
301 1.1 cgd #ifdef DEBUG
302 1.1 cgd else
303 1.1 cgd printf("hpib%d: PPOLL intr bad status %x\n",
304 1.1 cgd unit, stat0);
305 1.1 cgd #endif
306 1.1 cgd }
307 1.1 cgd return(1);
308 1.1 cgd }
309 1.1 cgd
310 1.1 cgd nhpibppoll(unit)
311 1.1 cgd int unit;
312 1.1 cgd {
313 1.1 cgd register struct nhpibdevice *hd;
314 1.1 cgd register int ppoll;
315 1.1 cgd
316 1.1 cgd hd = (struct nhpibdevice *)hpib_softc[unit].sc_hc->hp_addr;
317 1.1 cgd hd->hpib_acr = AUX_SPP;
318 1.1 cgd DELAY(25);
319 1.1 cgd ppoll = hd->hpib_cpt;
320 1.1 cgd hd->hpib_acr = AUX_CPP;
321 1.1 cgd return(ppoll);
322 1.1 cgd }
323 1.1 cgd
324 1.1 cgd nhpibwait(hd, x)
325 1.1 cgd register struct nhpibdevice *hd;
326 1.1 cgd {
327 1.1 cgd register int timo = hpibtimeout;
328 1.1 cgd
329 1.1 cgd while ((hd->hpib_mis & x) == 0 && --timo)
330 1.1 cgd DELAY(1);
331 1.1 cgd if (timo == 0)
332 1.1 cgd return(-1);
333 1.1 cgd return(0);
334 1.1 cgd }
335 1.1 cgd
336 1.1 cgd nhpibppwatch(unit)
337 1.1 cgd register int unit;
338 1.1 cgd {
339 1.1 cgd register struct hpib_softc *hs = &hpib_softc[unit];
340 1.1 cgd
341 1.1 cgd if ((hs->sc_flags & HPIBF_PPOLL) == 0)
342 1.1 cgd return;
343 1.1 cgd if (nhpibppoll(unit) & (0x80 >> hs->sc_sq.dq_forw->dq_slave))
344 1.1 cgd ((struct nhpibdevice *)hs->sc_hc->hp_addr)->hpib_mim = MIS_BO;
345 1.1 cgd else
346 1.1 cgd timeout(nhpibppwatch, unit, 1);
347 1.1 cgd }
348 1.1 cgd #endif
349