raw interfaces brought up to date
[unix-history] / usr / src / sys / vax / if / if_acc.c
CommitLineData
28081cf8
SL
1/* if_acc.c 4.1 82/02/01 */
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"
19#include "../h/accreg.h"
20#include "../h/cpu.h"
21#include "../h/mtpr.h"
22#include "../h/vmmac.h"
23#include "../net/in.h"
24#include "../net/in_systm.h"
25#include "../net/if.h"
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 */
62 char acc_previous; /* something on input queue */
63} acc_softc[NACC];
64
65/*
66 * Reset the IMP and cause a transmitter interrupt by
67 * performing a null DMA.
68 */
69accprobe(reg)
70 caddr_t reg;
71{
72 register int br, cvec; /* r11, r10 value-result */
73 register struct accdevice *addr = (struct accdevice *)reg;
74
75COUNT(ACCPROBE);
76#ifdef lint
77 br = 0; cvec = br; br = cvec;
78 accrint(0); accxint(0);
79#endif
80 addr->acc_icsr = ACC_RESET;
81 DELAY(500000);
82 addr->acc_ocsr = ACC_RESET;
83 DELAY(500000);
84
85 addr->acc_ocsr = OUT_BBACK;
86 DELAY(500000);
87 addr->acc_owc = 0;
88 addr->acc_ocsr = ACC_IE | ACC_GO;
89 DELAY(500000);
90 addr->acc_ocsr = 0;
91 /* interrupt was for transmit, push back to receive vector */
92 if (cvec && cvec != 0x200)
93 cvec -= 4;
94 return (1);
95}
96
97/*
98 * Call the IMP module to allow it to set up its internal
99 * state, then tie the two modules together by setting up
100 * the back pointers to common data structures.
101 */
102accattach(ui)
103 struct uba_device *ui;
104{
105 register struct acc_softc *sc = &acc_softc[ui->ui_unit];
106 register struct impcb *ip;
107 struct ifimpcb {
108 struct ifnet ifimp_if;
109 struct impcb ifimp_impcb;
110 } *ifimp;
111
112COUNT(ACCATTACH);
113 if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
114 panic("accattach"); /* XXX */
115 sc->acc_if = &ifimp->ifimp_if;
116 ip = &ifimp->ifimp_impcb;
117 sc->acc_ic = ip;
118 ip->ic_init = accinit;
119 ip->ic_start = accstart;
120}
121
122/*
123 * Reset interface after UNIBUS reset.
124 * If interface is on specified uba, reset its state.
125 */
126accreset(unit, uban)
127 int unit, uban;
128{
129 register struct uba_device *ui;
130 struct acc_softc *sc;
131
132COUNT(ACCRESET);
133 if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 ||
134 ui->ui_ubanum != uban)
135 return;
136 printf(" acc%d", unit);
137 sc = &acc_softc[unit];
138 /* must go through IMP to allow it to set state */
139 (*sc->acc_if->if_init)(unit);
140}
141
142/*
143 * Initialize interface: clear recorded pending operations,
144 * and retrieve, and reinitialize UNIBUS resources.
145 */
146accinit(unit)
147 int unit;
148{
149 register struct acc_softc *sc = &acc_softc[unit];
150 register struct uba_device *ui = accinfo[unit];
151 register struct accdevice *addr;
152 int x, info;
153
154COUNT(ACCINIT);
155 if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum,
156 sizeof(struct imp_leader), (int)btop(IMP_MTU)) == 0) {
157 printf("acc%d: can't initialize\n", unit);
158 return;
159 }
160 addr = (struct accdevice *)ui->ui_addr;
161
162 /* reset the imp interface. */
163 x = spl5();
164 addr->acc_icsr = ACC_RESET;
165 addr->acc_ocsr = ACC_RESET;
166 addr->acc_ocsr = OUT_BBACK; /* reset host master ready */
167 addr->acc_ocsr = 0;
168 addr->acc_icsr = IN_MRDY; /* close the relay */
169 splx(x);
170
171 /* YECH!!! */
172 while ((addr->acc_icsr & IN_HRDY) == 0 ||
173 (addr->acc_icsr & (IN_RMR | IN_IMPBSY))) {
174 /* keep turning IN_RMR off */
175 addr->acc_icsr = IN_MRDY;
176 sleep((caddr_t)&lbolt, PZERO);
177 }
178
179 /*
180 * Put up a read. We can't restart any outstanding writes
181 * until we're back in synch with the IMP (i.e. we've flushed
182 * the NOOPs it throws at us).
183 */
184 x = spl5();
185 info = sc->acc_ifuba.ifu_r.ifrw_info;
186 addr->acc_iba = (u_short)info;
187 addr->acc_iwc = -(sizeof(struct imp_leader) + IMP_MTU) >> 1;
188 addr->acc_icsr =
189 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
190 splx(x);
191}
192
193/*
194 * Start output on an interface.
195 */
196accstart(dev)
197 dev_t dev;
198{
199 int unit = ACCUNIT(dev), info;
200 struct uba_device *ui = accinfo[unit];
201 register struct acc_softc *sc = &acc_softc[unit];
202 register struct accdevice *addr;
203 struct mbuf *m;
204 u_short cmd;
205
206COUNT(ACCSTART);
207 if (sc->acc_ic->ic_oactive)
208 goto restart;
209
210 /*
211 * Not already active, deqeue a request and
212 * map it onto the UNIBUS. If no more
213 * requeusts, just return.
214 */
215 IF_DEQUEUE(&sc->acc_if->if_snd, m);
216 if (m == 0) {
217 sc->acc_ic->ic_oactive = 0;
218 return;
219 }
220 sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
221
222restart:
223 /*
224 * Have request mapped to UNIBUS for transmission.
225 * Purge any stale data from the BDP, and start the output.
226 */
227 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
228 addr = (struct accdevice *)ui->ui_addr;
229 info = sc->acc_ifuba.ifu_w.ifrw_info;
230 addr->acc_oba = (u_short)info;
231 addr->acc_owc = -((sc->acc_olen + 1) >> 1);
232 cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO;
233 addr->acc_ocsr = cmd;
234 sc->acc_ic->ic_oactive = 1;
235}
236
237/*
238 * Output interrupt handler.
239 */
240accxint(unit)
241{
242 register struct uba_device *ui = accinfo[unit];
243 register struct acc_softc *sc = &acc_softc[unit];
244 register struct accdevice *addr;
245
246COUNT(ACCXINT);
247 if (sc->acc_ic->ic_oactive == 0) {
248 printf("acc%d: stray output interrupt\n", unit);
249 return;
250 }
251 addr = (struct accdevice *)ui->ui_addr;
252 sc->acc_if->if_opackets++;
253 sc->acc_ic->ic_oactive = 0;
254 if (addr->acc_ocsr & ACC_ERR)
255 printf("acc%d: output error, csr=%b\n", unit,
256 addr->acc_ocsr, ACC_OUTBITS);
257 if (sc->acc_if->if_snd.ifq_head == 0) {
258 sc->acc_if->if_oerrors++;
259 if (sc->acc_ifuba.ifu_xtofree) {
260 m_freem(sc->acc_ifuba.ifu_xtofree);
261 sc->acc_ifuba.ifu_xtofree = 0;
262 }
263 return;
264 }
265 accstart(unit);
266}
267
268/*
269 * Input interrupt handler
270 */
271accrint(unit)
272{
273 register struct acc_softc *sc = &acc_softc[unit];
274 register struct accdevice *addr;
275 register struct ifqueue *inq;
276 struct mbuf *m;
277 int len, info;
278
279COUNT(ACCRINT);
280 sc->acc_if->if_ipackets++;
281
282 /*
283 * Purge BDP; flush message if error indicated.
284 */
285 UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
286 addr = (struct accdevice *)accinfo[unit]->ui_addr;
287 if (addr->acc_icsr & ACC_ERR) {
288 printf("acc%d: recv error, csr=%b\n", unit,
289 addr->acc_icsr, ACC_INBITS);
290 sc->acc_if->if_ierrors++;
291 sc->acc_flush = 1;
292 }
293
294 if (sc->acc_flush) {
295 if (addr->acc_icsr & IN_EOM)
296 sc->acc_flush = 0;
297 goto setup;
298 }
299 len = sizeof(struct imp_leader) + (addr->acc_iwc << 1);
300
301 /*
302 * The last parameter is always 0 since using
303 * trailers on the ARPAnet is insane.
304 */
305 m = if_rubaget(&sc->acc_ifuba, len, 0);
306 if (m == 0)
307 goto setup;
308 if ((addr->acc_icsr & IN_EOM) == 0) {
309 if (sc->acc_previous)
310 m_cat(sc->acc_iq, m);
311 else {
312 sc->acc_iq = m;
313 sc->acc_previous = 1;
314 }
315 goto setup;
316 }
317 /* adjust message length for padding. */
318 m->m_len -= 2;
319 if (sc->acc_previous) {
320 m_cat(sc->acc_iq, m);
321 m = sc->acc_iq;
322 sc->acc_iq = 0;
323 sc->acc_previous = 0;
324 }
325 impinput(unit, m);
326
327setup:
328 /*
329 * Setup for next message.
330 */
331 info = sc->acc_ifuba.ifu_r.ifrw_info;
332 addr->acc_iba = (u_short)info;
333 addr->acc_iwc = - (sizeof(struct imp_leader) + IMP_MTU) >> 1;
334 addr->acc_icsr =
335 IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
336}
337#endif