merge into new file system
[unix-history] / usr / src / sys / vax / if / if_acc.c
CommitLineData
d9c0644f 1/* if_acc.c 4.14 82/04/16 */
28081cf8
SL
2
3#include "acc.h"
4#ifdef NACC > 0
5
6/*
7 * ACC LH/DH ARPAnet IMP interface driver.
8 */
9
10#include "../h/param.h"
11#include "../h/systm.h"
12#include "../h/mbuf.h"
13#include "../h/pte.h"
14#include "../h/buf.h"
15#include "../h/protosw.h"
16#include "../h/socket.h"
17#include "../h/ubareg.h"
18#include "../h/ubavar.h"
28081cf8
SL
19#include "../h/cpu.h"
20#include "../h/mtpr.h"
21#include "../h/vmmac.h"
22#include "../net/in.h"
23#include "../net/in_systm.h"
24#include "../net/if.h"
a2cd4df7 25#include "../net/if_acc.h"
28081cf8
SL
26#include "../net/if_imp.h"
27#include "../net/if_uba.h"
28
29int accprobe(), accattach(), accrint(), accxint();
30struct uba_device *accinfo[NACC];
31u_short accstd[] = { 0 };
32struct uba_driver accdriver =
33 { accprobe, 0, accattach, 0, accstd, "acc", accinfo };
34#define ACCUNIT(x) minor(x)
35
36int accinit(), accstart(), accreset();
37
38/*
39 * "Lower half" of IMP interface driver.
40 *
41 * Each IMP interface is handled by a common module which handles
42 * the IMP-host protocol and a hardware driver which manages the
43 * hardware specific details of talking with the IMP.
44 *
45 * The hardware portion of the IMP driver handles DMA and related
46 * management of UNIBUS resources. The IMP protocol module interprets
47 * contents of these messages and "controls" the actions of the
48 * hardware module during IMP resets, but not, for instance, during
49 * UNIBUS resets.
50 *
51 * The two modules are coupled at "attach time", and ever after,
52 * through the imp interface structure. Higher level protocols,
53 * e.g. IP, interact with the IMP driver, rather than the ACC.
54 */
55struct acc_softc {
56 struct ifnet *acc_if; /* pointer to IMP's ifnet struct */
57 struct impcb *acc_ic; /* data structure shared with IMP */
58 struct ifuba acc_ifuba; /* UNIBUS resources */
59 struct mbuf *acc_iq; /* input reassembly queue */
60 short acc_olen; /* size of last message sent */
61 char acc_flush; /* flush remainder of message */
28081cf8
SL
62} acc_softc[NACC];
63
64/*
65 * Reset the IMP and cause a transmitter interrupt by
66 * performing a null DMA.
67 */
68accprobe(reg)
69 caddr_t reg;
70{
71 register int br, cvec; /* r11, r10 value-result */
72 register struct accdevice *addr = (struct accdevice *)reg;
73
74COUNT(ACCPROBE);
75#ifdef lint
76 br = 0; cvec = br; br = cvec;
77 accrint(0); accxint(0);
78#endif
a2cd4df7
BJ
79 addr->icsr = ACC_RESET; DELAY(5000);
80 addr->ocsr = ACC_RESET; DELAY(5000);
81 addr->ocsr = OUT_BBACK; DELAY(5000);
82 addr->owc = 0;
83 addr->ocsr = ACC_IE | ACC_GO; DELAY(5000);
84 addr->ocsr = 0;
85 if (cvec && cvec != 0x200) /* transmit -> receive */
28081cf8 86 cvec -= 4;
7d9db2f2 87 br = 0x16; /* temporary ec hack */
28081cf8
SL
88 return (1);
89}
90
91/*
92 * Call the IMP module to allow it to set up its internal
93 * state, then tie the two modules together by setting up
94 * the back pointers to common data structures.
95 */
96accattach(ui)
97 struct uba_device *ui;
98{
99 register struct acc_softc *sc = &acc_softc[ui->ui_unit];
100 register struct impcb *ip;
101 struct ifimpcb {
102 struct ifnet ifimp_if;
103 struct impcb ifimp_impcb;
104 } *ifimp;
105
106COUNT(ACCATTACH);
107 if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
a2cd4df7 108 panic("accattach");
28081cf8
SL
109 sc->acc_if = &ifimp->ifimp_if;
110 ip = &ifimp->ifimp_impcb;
111 sc->acc_ic = ip;
112 ip->ic_init = accinit;
113 ip->ic_start = accstart;
a2cd4df7 114#ifdef notdef
d9c0644f 115 sc->acc_ifuba.ifu_flags = UBA_NEEDBDP | UBA_CANTWAIT;
a2cd4df7 116#endif
28081cf8
SL
117}
118
119/*
120 * Reset interface after UNIBUS reset.
121 * If interface is on specified uba, reset its state.
122 */
123accreset(unit, uban)
124 int unit, uban;
125{
126 register struct uba_device *ui;
127 struct acc_softc *sc;
128
129COUNT(ACCRESET);
130 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 ||
131 ui->ui_ubanum != uban)
132 return;
133 printf(" acc%d", unit);
134 sc = &acc_softc[unit];
135 /* must go through IMP to allow it to set state */
136 (*sc->acc_if->if_init)(unit);
137}
138
139/*
140 * Initialize interface: clear recorded pending operations,
a2cd4df7
BJ
141 * and retrieve, and initialize UNIBUS resources. Note
142 * return value is used by IMP init routine to mark IMP
143 * unavailable for outgoing traffic.
28081cf8
SL
144 */
145accinit(unit)
146 int unit;
147{
a2cd4df7
BJ
148 register struct acc_softc *sc;
149 register struct uba_device *ui;
28081cf8 150 register struct accdevice *addr;
521c9128 151 int info, i;
28081cf8
SL
152
153COUNT(ACCINIT);
a2cd4df7
BJ
154 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
155 printf("acc%d: not alive\n", unit);
156 return (0);
157 }
158 sc = &acc_softc[unit];
159 /*
160 * Header length is 0 since we have to passs
161 * the IMP leader up to the protocol interpretation
162 * routines. If we had the header length as
163 * sizeof(struct imp_leader), then the if_ routines
164 * would asssume we handle it on input and output.
165 */
668cc26d 166 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0,
e431883e 167 (int)btoc(IMPMTU)) == 0) {
28081cf8 168 printf("acc%d: can't initialize\n", unit);
a2cd4df7 169 goto down;
28081cf8
SL
170 }
171 addr = (struct accdevice *)ui->ui_addr;
172
a0b7c7fb 173 /*
a2cd4df7
BJ
174 * Reset the imp interface;
175 * the delays are pure guesswork.
a0b7c7fb 176 */
a2cd4df7
BJ
177 addr->icsr = ACC_RESET; DELAY(5000);
178 addr->ocsr = ACC_RESET; DELAY(5000);
8129679e 179 addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */
a2cd4df7 180 addr->ocsr = 0;
3fb22247 181 addr->icsr = IN_MRDY | IN_WEN; /* close the relay */
8129679e 182 DELAY(10000);
28081cf8 183 /* YECH!!! */
521c9128 184 for (i = 0; i < 500; i++) {
a2cd4df7 185 if ((addr->icsr & IN_HRDY) ||
d49cf621 186 (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0)
521c9128 187 goto ok;
8129679e
BJ
188 addr->icsr = IN_MRDY | IN_WEN; DELAY(10000);
189 /* keep turning IN_RMR off */
a2cd4df7 190 }
521c9128
BJ
191 printf("acc%d: imp doesn't respond, icsr=%b\n", unit,
192 addr->icsr, ACC_INBITS);
193down:
194 ui->ui_alive = 0;
195 return (0);
28081cf8 196
521c9128 197ok:
28081cf8
SL
198 /*
199 * Put up a read. We can't restart any outstanding writes
200 * until we're back in synch with the IMP (i.e. we've flushed
201 * the NOOPs it throws at us).
e431883e 202 * Note: IMPMTU includes the leader.
28081cf8 203 */
28081cf8 204 info = sc->acc_ifuba.ifu_r.ifrw_info;
a2cd4df7 205 addr->iba = (u_short)info;
e431883e 206 addr->iwc = -(IMPMTU >> 1);
a2cd4df7
BJ
207#ifdef LOOPBACK
208 addr->ocsr |= OUT_BBACK;
209#endif
210 addr->icsr =
28081cf8 211 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
a2cd4df7 212 return (1);
28081cf8
SL
213}
214
215/*
216 * Start output on an interface.
217 */
218accstart(dev)
219 dev_t dev;
220{
221 int unit = ACCUNIT(dev), info;
28081cf8
SL
222 register struct acc_softc *sc = &acc_softc[unit];
223 register struct accdevice *addr;
224 struct mbuf *m;
225 u_short cmd;
226
227COUNT(ACCSTART);
228 if (sc->acc_ic->ic_oactive)
229 goto restart;
230
231 /*
232 * Not already active, deqeue a request and
233 * map it onto the UNIBUS. If no more
234 * requeusts, just return.
235 */
236 IF_DEQUEUE(&sc->acc_if->if_snd, m);
237 if (m == 0) {
238 sc->acc_ic->ic_oactive = 0;
239 return;
240 }
241 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
242
243restart:
244 /*
a2cd4df7
BJ
245 * Have request mapped to UNIBUS for
246 * transmission; start the output.
28081cf8 247 */
a2cd4df7
BJ
248 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
249 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
bcb5db7d 250 addr = (struct accdevice *)accinfo[unit]->ui_addr;
28081cf8 251 info = sc->acc_ifuba.ifu_w.ifrw_info;
a2cd4df7
BJ
252 addr->oba = (u_short)info;
253 addr->owc = -((sc->acc_olen + 1) >> 1);
28081cf8 254 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO;
a2cd4df7
BJ
255#ifdef LOOPBACK
256 cmd |= OUT_BBACK;
257#endif
258 addr->ocsr = cmd;
28081cf8
SL
259 sc->acc_ic->ic_oactive = 1;
260}
261
262/*
263 * Output interrupt handler.
264 */
265accxint(unit)
266{
28081cf8
SL
267 register struct acc_softc *sc = &acc_softc[unit];
268 register struct accdevice *addr;
269
270COUNT(ACCXINT);
271 if (sc->acc_ic->ic_oactive == 0) {
a2cd4df7 272 printf("acc%d: stray xmit interrupt\n", unit);
28081cf8
SL
273 return;
274 }
bcb5db7d 275 addr = (struct accdevice *)accinfo[unit]->ui_addr;
28081cf8
SL
276 sc->acc_if->if_opackets++;
277 sc->acc_ic->ic_oactive = 0;
a2cd4df7
BJ
278 if (addr->ocsr & ACC_ERR) {
279 printf("acc%d: output error, csr=%b\n", unit,
280 addr->ocsr, ACC_OUTBITS);
28081cf8 281 sc->acc_if->if_oerrors++;
a0b7c7fb 282 }
a2cd4df7
BJ
283 if (sc->acc_ifuba.ifu_xtofree) {
284 m_freem(sc->acc_ifuba.ifu_xtofree);
285 sc->acc_ifuba.ifu_xtofree = 0;
28081cf8 286 }
41e530c7
BJ
287 if (sc->acc_if->if_snd.ifq_head)
288 accstart(unit);
28081cf8
SL
289}
290
291/*
292 * Input interrupt handler
293 */
294accrint(unit)
295{
296 register struct acc_softc *sc = &acc_softc[unit];
297 register struct accdevice *addr;
28081cf8
SL
298 struct mbuf *m;
299 int len, info;
300
301COUNT(ACCRINT);
302 sc->acc_if->if_ipackets++;
303
304 /*
305 * Purge BDP; flush message if error indicated.
306 */
a2cd4df7
BJ
307 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
308 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
28081cf8 309 addr = (struct accdevice *)accinfo[unit]->ui_addr;
a2cd4df7
BJ
310 if (addr->icsr & ACC_ERR) {
311 printf("acc%d: input error, csr=%b\n", unit,
312 addr->icsr, ACC_INBITS);
28081cf8
SL
313 sc->acc_if->if_ierrors++;
314 sc->acc_flush = 1;
315 }
316
317 if (sc->acc_flush) {
a2cd4df7 318 if (addr->icsr & IN_EOM)
28081cf8
SL
319 sc->acc_flush = 0;
320 goto setup;
321 }
e431883e
BJ
322 len = IMPMTU + (addr->iwc << 1);
323 if (len < 0 || len > IMPMTU) {
a2cd4df7
BJ
324 printf("acc%d: bad length=%d\n", len);
325 sc->acc_if->if_ierrors++;
326 goto setup;
327 }
28081cf8
SL
328
329 /*
330 * The last parameter is always 0 since using
331 * trailers on the ARPAnet is insane.
332 */
333 m = if_rubaget(&sc->acc_ifuba, len, 0);
334 if (m == 0)
335 goto setup;
a2cd4df7 336 if ((addr->icsr & IN_EOM) == 0) {
a0b7c7fb 337 if (sc->acc_iq)
28081cf8 338 m_cat(sc->acc_iq, m);
a0b7c7fb 339 else
28081cf8 340 sc->acc_iq = m;
28081cf8
SL
341 goto setup;
342 }
a0b7c7fb 343 if (sc->acc_iq) {
28081cf8
SL
344 m_cat(sc->acc_iq, m);
345 m = sc->acc_iq;
346 sc->acc_iq = 0;
28081cf8
SL
347 }
348 impinput(unit, m);
349
350setup:
351 /*
352 * Setup for next message.
353 */
354 info = sc->acc_ifuba.ifu_r.ifrw_info;
a2cd4df7 355 addr->iba = (u_short)info;
e431883e 356 addr->iwc = -(IMPMTU >> 1);
a2cd4df7 357 addr->icsr =
28081cf8
SL
358 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
359}
360#endif