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