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