create netif directory
[unix-history] / usr / src / sys / vax / if / if_acc.c
CommitLineData
5e35ed24 1/* if_acc.c 4.29 82/10/24 */
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"
28081cf8 17#include "../h/vmmac.h"
a9687d27 18
28081cf8 19#include "../net/if.h"
d2cc167c 20#include "../netimp/if_imp.h"
a9687d27
BJ
21
22#include "../vax/cpu.h"
23#include "../vax/mtpr.h"
5e35ed24 24#include "../vaxif/if_accreg.h"
d2cc167c 25#include "../vaxif/if_uba.h"
a9687d27
BJ
26#include "../vaxuba/ubareg.h"
27#include "../vaxuba/ubavar.h"
28081cf8
SL
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
28081cf8
SL
74#ifdef lint
75 br = 0; cvec = br; br = cvec;
76 accrint(0); accxint(0);
77#endif
a2cd4df7
BJ
78 addr->icsr = ACC_RESET; DELAY(5000);
79 addr->ocsr = ACC_RESET; DELAY(5000);
80 addr->ocsr = OUT_BBACK; DELAY(5000);
81 addr->owc = 0;
82 addr->ocsr = ACC_IE | ACC_GO; DELAY(5000);
7dd4b7cb 83 addr->ocsr = 0;
a2cd4df7 84 if (cvec && cvec != 0x200) /* transmit -> receive */
28081cf8 85 cvec -= 4;
7d6f1cd5
SL
86#ifdef ECHACK
87 br = 0x16;
88#endif
28081cf8
SL
89 return (1);
90}
91
92/*
93 * Call the IMP module to allow it to set up its internal
94 * state, then tie the two modules together by setting up
95 * the back pointers to common data structures.
96 */
97accattach(ui)
98 struct uba_device *ui;
99{
100 register struct acc_softc *sc = &acc_softc[ui->ui_unit];
101 register struct impcb *ip;
102 struct ifimpcb {
103 struct ifnet ifimp_if;
104 struct impcb ifimp_impcb;
105 } *ifimp;
106
92aca3da 107 if ((ifimp = (struct ifimpcb *)impattacch(ui, acreset)) == 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;
92aca3da 114 sc->acc_ifuba.ifu_flags = UBA_CANTWAIT;
a2cd4df7 115#ifdef notdef
7dfb87a5 116 sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP;
a2cd4df7 117#endif
28081cf8
SL
118}
119
120/*
121 * Reset interface after UNIBUS reset.
122 * If interface is on specified uba, reset its state.
123 */
124accreset(unit, uban)
125 int unit, uban;
126{
127 register struct uba_device *ui;
128 struct acc_softc *sc;
129
28081cf8
SL
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;
7d47e8bb 151 int info;
28081cf8 152
a2cd4df7
BJ
153 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
154 printf("acc%d: not alive\n", unit);
155 return (0);
156 }
157 sc = &acc_softc[unit];
158 /*
159 * Header length is 0 since we have to passs
160 * the IMP leader up to the protocol interpretation
161 * routines. If we had the header length as
162 * sizeof(struct imp_leader), then the if_ routines
163 * would asssume we handle it on input and output.
164 */
668cc26d 165 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0,
e431883e 166 (int)btoc(IMPMTU)) == 0) {
28081cf8 167 printf("acc%d: can't initialize\n", unit);
7dfb87a5
SL
168 ui->ui_alive = 0;
169 return (0);
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 177 addr->ocsr = ACC_RESET; DELAY(5000);
8129679e 178 addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */
a2cd4df7 179 addr->ocsr = 0;
7dfb87a5
SL
180 if (accinputreset(addr, unit) == 0) {
181 ui->ui_alive = 0;
182 return (0);
a2cd4df7 183 }
28081cf8
SL
184
185 /*
186 * Put up a read. We can't restart any outstanding writes
187 * until we're back in synch with the IMP (i.e. we've flushed
188 * the NOOPs it throws at us).
e431883e 189 * Note: IMPMTU includes the leader.
28081cf8 190 */
28081cf8 191 info = sc->acc_ifuba.ifu_r.ifrw_info;
a2cd4df7 192 addr->iba = (u_short)info;
e431883e 193 addr->iwc = -(IMPMTU >> 1);
a2cd4df7
BJ
194#ifdef LOOPBACK
195 addr->ocsr |= OUT_BBACK;
196#endif
197 addr->icsr =
28081cf8 198 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
a2cd4df7 199 return (1);
28081cf8
SL
200}
201
7dfb87a5
SL
202accinputreset(addr, unit)
203 register struct accdevice *addr;
204 register int unit;
205{
206 register int i;
207
208 addr->icsr = ACC_RESET; DELAY(5000);
209 addr->icsr = IN_MRDY | IN_WEN; /* close the relay */
210 DELAY(10000);
211 /* YECH!!! */
212 for (i = 0; i < 500; i++) {
213 if ((addr->icsr & IN_HRDY) ||
214 (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0)
215 return (1);
216 addr->icsr = IN_MRDY | IN_WEN; DELAY(10000);
217 /* keep turning IN_RMR off */
218 }
219 printf("acc%d: imp doesn't respond, icsr=%b\n", unit,
220 addr->icsr, ACC_INBITS);
221 return (0);
222}
223
28081cf8
SL
224/*
225 * Start output on an interface.
226 */
227accstart(dev)
228 dev_t dev;
229{
230 int unit = ACCUNIT(dev), info;
28081cf8
SL
231 register struct acc_softc *sc = &acc_softc[unit];
232 register struct accdevice *addr;
233 struct mbuf *m;
234 u_short cmd;
235
28081cf8
SL
236 if (sc->acc_ic->ic_oactive)
237 goto restart;
238
239 /*
240 * Not already active, deqeue a request and
241 * map it onto the UNIBUS. If no more
242 * requeusts, just return.
243 */
244 IF_DEQUEUE(&sc->acc_if->if_snd, m);
245 if (m == 0) {
246 sc->acc_ic->ic_oactive = 0;
247 return;
248 }
249 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
250
251restart:
252 /*
a2cd4df7
BJ
253 * Have request mapped to UNIBUS for
254 * transmission; start the output.
28081cf8 255 */
a2cd4df7
BJ
256 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
257 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
bcb5db7d 258 addr = (struct accdevice *)accinfo[unit]->ui_addr;
28081cf8 259 info = sc->acc_ifuba.ifu_w.ifrw_info;
a2cd4df7
BJ
260 addr->oba = (u_short)info;
261 addr->owc = -((sc->acc_olen + 1) >> 1);
28081cf8 262 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO;
a2cd4df7
BJ
263#ifdef LOOPBACK
264 cmd |= OUT_BBACK;
265#endif
266 addr->ocsr = cmd;
28081cf8
SL
267 sc->acc_ic->ic_oactive = 1;
268}
269
270/*
271 * Output interrupt handler.
272 */
273accxint(unit)
d2cc167c 274 int unit;
28081cf8 275{
28081cf8
SL
276 register struct acc_softc *sc = &acc_softc[unit];
277 register struct accdevice *addr;
278
7dfb87a5 279 addr = (struct accdevice *)accinfo[unit]->ui_addr;
28081cf8 280 if (sc->acc_ic->ic_oactive == 0) {
7dfb87a5
SL
281 printf("acc%d: stray xmit interrupt, csr=%b\n", unit,
282 addr->ocsr, ACC_OUTBITS);
28081cf8
SL
283 return;
284 }
28081cf8
SL
285 sc->acc_if->if_opackets++;
286 sc->acc_ic->ic_oactive = 0;
7dd4b7cb 287 if (addr->ocsr & ACC_ERR) {
7dfb87a5
SL
288 printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit,
289 addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS);
28081cf8 290 sc->acc_if->if_oerrors++;
a0b7c7fb 291 }
a2cd4df7
BJ
292 if (sc->acc_ifuba.ifu_xtofree) {
293 m_freem(sc->acc_ifuba.ifu_xtofree);
294 sc->acc_ifuba.ifu_xtofree = 0;
28081cf8 295 }
b690198c
SL
296 if (sc->acc_if->if_snd.ifq_head)
297 accstart(unit);
28081cf8
SL
298}
299
300/*
301 * Input interrupt handler
302 */
303accrint(unit)
d2cc167c 304 int unit;
28081cf8
SL
305{
306 register struct acc_softc *sc = &acc_softc[unit];
307 register struct accdevice *addr;
28081cf8
SL
308 struct mbuf *m;
309 int len, info;
310
7dfb87a5 311 addr = (struct accdevice *)accinfo[unit]->ui_addr;
28081cf8
SL
312 sc->acc_if->if_ipackets++;
313
314 /*
315 * Purge BDP; flush message if error indicated.
316 */
a2cd4df7
BJ
317 if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
318 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
7dd4b7cb 319 if (addr->icsr & ACC_ERR) {
b690198c
SL
320 printf("acc%d: input error, csr=%b\n", unit,
321 addr->icsr, ACC_INBITS);
28081cf8
SL
322 sc->acc_if->if_ierrors++;
323 sc->acc_flush = 1;
324 }
325
326 if (sc->acc_flush) {
a2cd4df7 327 if (addr->icsr & IN_EOM)
28081cf8
SL
328 sc->acc_flush = 0;
329 goto setup;
330 }
e431883e
BJ
331 len = IMPMTU + (addr->iwc << 1);
332 if (len < 0 || len > IMPMTU) {
a2cd4df7
BJ
333 printf("acc%d: bad length=%d\n", len);
334 sc->acc_if->if_ierrors++;
335 goto setup;
336 }
28081cf8
SL
337
338 /*
339 * The last parameter is always 0 since using
340 * trailers on the ARPAnet is insane.
341 */
342 m = if_rubaget(&sc->acc_ifuba, len, 0);
343 if (m == 0)
344 goto setup;
a2cd4df7 345 if ((addr->icsr & IN_EOM) == 0) {
a0b7c7fb 346 if (sc->acc_iq)
28081cf8 347 m_cat(sc->acc_iq, m);
a0b7c7fb 348 else
28081cf8 349 sc->acc_iq = m;
28081cf8
SL
350 goto setup;
351 }
a0b7c7fb 352 if (sc->acc_iq) {
28081cf8
SL
353 m_cat(sc->acc_iq, m);
354 m = sc->acc_iq;
355 sc->acc_iq = 0;
28081cf8
SL
356 }
357 impinput(unit, m);
358
359setup:
360 /*
361 * Setup for next message.
362 */
363 info = sc->acc_ifuba.ifu_r.ifrw_info;
a2cd4df7 364 addr->iba = (u_short)info;
e431883e 365 addr->iwc = -(IMPMTU >> 1);
a2cd4df7 366 addr->icsr =
28081cf8
SL
367 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
368}
369#endif