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