BSD 4_3_Reno release
[unix-history] / usr / src / sys / vaxif / if_css.c
CommitLineData
da7c5cc6 1/*
616d42db 2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3c238487 3 * All rights reserved.
da7c5cc6 4 *
1c15e888
C
5 * Redistribution is only permitted until one year after the first shipment
6 * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7 * binary forms are permitted provided that: (1) source distributions retain
8 * this entire copyright notice and comment, and (2) distributions including
9 * binaries display the following acknowledgement: This product includes
10 * software developed by the University of California, Berkeley and its
11 * contributors'' in the documentation or other materials provided with the
12 * distribution and in all advertising materials mentioning features or use
13 * of this software. Neither the name of the University nor the names of
14 * its contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
3c238487 19 *
1c15e888 20 * @(#)if_css.c 7.8 (Berkeley) 6/28/90
da7c5cc6 21 */
ee6d9923
SL
22
23#include "css.h"
9a0b0c74 24#if NCSS > 0
ee6d9923
SL
25
26/*
27 * DEC/CSS IMP11-A ARPAnet IMP interface driver.
28 * Since "imp11a" is such a mouthful, it is called
29 * "css" after the LH/DH being called "acc".
30 *
31 * Configuration notes:
32 *
33 * As delivered from DEC/CSS, it
34 * is addressed and vectored as two DR11-B's. This makes
35 * Autoconfig almost IMPOSSIBLE. To make it work, the
36 * interrupt vectors must be restrapped to make the vectors
37 * consecutive. The 020 hole between the CSR addresses is
38 * tolerated, althought that could be cleaned-up also.
39 *
40 * Additionally, the TRANSMIT side of the IMP11-A has the
41 * lower address of the two subunits, so the vector ordering
42 * in the CONFIG file is reversed from most other devices.
43 * It should be:
44 *
45 * device css0 .... cssxint cssrint
46 *
47 * If you get it wrong, it will still autoconfig, but will just
fd4d8418 48 * sit there with RECEIVE IDLE indicated on the front panel.
ee6d9923 49 */
a6e960e7
JB
50#include "param.h"
51#include "systm.h"
52#include "mbuf.h"
53#include "buf.h"
54#include "protosw.h"
55#include "socket.h"
56#include "vmmac.h"
a9687d27 57
1c15e888 58#include "machine/pte.h"
3c238487 59
ee6d9923 60#include "../net/if.h"
d2cc167c 61#include "../netimp/if_imp.h"
a9687d27
BJ
62
63#include "../vax/cpu.h"
64#include "../vax/mtpr.h"
a6e960e7
JB
65#include "if_cssreg.h"
66#include "if_uba.h"
a9687d27
BJ
67#include "../vaxuba/ubareg.h"
68#include "../vaxuba/ubavar.h"
ee6d9923
SL
69
70int cssprobe(), cssattach(), cssrint(), cssxint();
71struct uba_device *cssinfo[NCSS];
72u_short cssstd[] = { 0 };
73struct uba_driver cssdriver =
74 { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
ee6d9923 75
3c238487 76int cssinit(), cssoutput(), cssdown(), cssreset();
ee6d9923
SL
77
78/*
79 * "Lower half" of IMP interface driver.
80 *
81 * Each IMP interface is handled by a common module which handles
82 * the IMP-host protocol and a hardware driver which manages the
83 * hardware specific details of talking with the IMP.
84 *
85 * The hardware portion of the IMP driver handles DMA and related
86 * management of UNIBUS resources. The IMP protocol module interprets
87 * contents of these messages and "controls" the actions of the
88 * hardware module during IMP resets, but not, for instance, during
89 * UNIBUS resets.
90 *
91 * The two modules are coupled at "attach time", and ever after,
92 * through the imp interface structure. Higher level protocols,
93 * e.g. IP, interact with the IMP driver, rather than the CSS.
94 */
95struct css_softc {
3c238487
MK
96 struct imp_softc *css_imp; /* pointer to IMP's imp_softc struct */
97 struct ifuba css_ifuba; /* UNIBUS resources */
98 struct mbuf *css_iq; /* input reassembly queue */
99 short css_olen; /* size of last message sent */
100 char css_flush; /* flush remainder of message */
ee6d9923
SL
101} css_softc[NCSS];
102
103/*
104 * Reset the IMP and cause a transmitter interrupt by
105 * performing a null DMA.
106 */
107cssprobe(reg)
108 caddr_t reg;
109{
110 register int br, cvec; /* r11, r10 value-result */
111 register struct cssdevice *addr = (struct cssdevice *)reg;
112
ee6d9923
SL
113#ifdef lint
114 br = 0; cvec = br; br = cvec;
115 cssrint(0); cssxint(0);
116#endif
117
ee6d9923
SL
118 addr->css_icsr = CSS_CLR;
119 addr->css_ocsr = CSS_CLR;
120 DELAY(50000);
121 addr->css_icsr = 0;
122 addr->css_ocsr = 0;
123 DELAY(50000);
124
125 addr->css_oba = 0;
126 addr->css_owc = -1;
127 addr->css_ocsr = CSS_IE | CSS_GO; /* enable interrupts */
128 DELAY(50000);
129 addr->css_ocsr = 0;
130
131 return (1);
132}
133
134/*
135 * Call the IMP module to allow it to set up its internal
136 * state, then tie the two modules together by setting up
137 * the back pointers to common data structures.
138 */
139cssattach(ui)
35718d8f 140 register struct uba_device *ui;
ee6d9923
SL
141{
142 register struct css_softc *sc = &css_softc[ui->ui_unit];
143 register struct impcb *ip;
ee6d9923 144
35718d8f
MK
145 if ((sc->css_imp = impattach(ui->ui_driver->ud_dname, ui->ui_unit,
146 cssreset)) == 0)
fd4d8418 147 return;
3c238487 148 ip = &sc->css_imp->imp_cb;
ee6d9923 149 ip->ic_init = cssinit;
3c238487
MK
150 ip->ic_output = cssoutput;
151 ip->ic_down = cssdown;
ee6d9923
SL
152 sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
153#ifdef notdef
04ecf99a 154 sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
ee6d9923
SL
155#endif
156}
157
158/*
159 * Reset interface after UNIBUS reset.
160 * If interface is on specified uba, reset its state.
161 */
162cssreset(unit, uban)
163 int unit, uban;
164{
165 register struct uba_device *ui;
3c238487 166 register struct css_softc *sc;
ee6d9923 167
ee6d9923
SL
168 if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
169 ui->ui_ubanum != uban)
170 return;
171 printf(" css%d", unit);
172 sc = &css_softc[unit];
3c238487 173 sc->css_imp->imp_if.if_flags &= ~IFF_RUNNING;
35718d8f 174 cssoflush(unit);
ee6d9923 175 /* must go through IMP to allow it to set state */
3c238487 176 (*sc->css_imp->imp_if.if_init)(sc->css_imp->imp_if.if_unit);
ee6d9923
SL
177}
178
179/*
180 * Initialize interface: clear recorded pending operations,
181 * and retrieve, and reinitialize UNIBUS resources.
182 */
183cssinit(unit)
184 int unit;
185{
186 register struct css_softc *sc;
187 register struct uba_device *ui;
188 register struct cssdevice *addr;
189 int x, info;
190
ee6d9923
SL
191 if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
192 printf("css%d: not alive\n", unit);
193 return(0);
194 }
195 sc = &css_softc[unit];
196
197 /*
198 * Header length is 0 to if_ubainit since we have to pass
199 * the IMP leader up to the protocol interpretaion
200 * routines. If we had the deader length as
201 * sizeof(struct imp_leader), then the if_ routines
202 * would assume we handle it on input and output.
203 */
204
3c238487
MK
205 if ((sc->css_imp->imp_if.if_flags & IFF_RUNNING) == 0 &&
206 if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,
207 (int)btoc(IMP_RCVBUF)) == 0) {
ee6d9923
SL
208 printf("css%d: can't initialize\n", unit);
209 ui->ui_alive = 0;
3c238487 210 sc->css_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING);
ee6d9923
SL
211 return(0);
212 }
3c238487 213 sc->css_imp->imp_if.if_flags |= IFF_RUNNING;
ee6d9923
SL
214 addr = (struct cssdevice *)ui->ui_addr;
215
216 /* reset the imp interface. */
217 x = spl5();
218 addr->css_icsr = CSS_CLR;
219 addr->css_ocsr = CSS_CLR;
220 DELAY(100);
221 addr->css_icsr = 0;
222 addr->css_ocsr = 0;
223 addr->css_icsr = IN_HRDY; /* close the relay */
224 DELAY(5000);
225 splx(x);
226
227 /*
228 * This may hang if the imp isn't really there.
229 * Will test and verify safe operation.
230 */
231
232 x = 500;
233 while (x-- > 0) {
234 if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
235 break;
236 addr->css_icsr = IN_HRDY; /* close the relay */
237 DELAY(5000);
238 }
239
240 if (x <= 0) {
241 printf("css%d: imp doesn't respond, icsr=%b\n", unit,
242 CSS_INBITS, addr->css_icsr);
243 goto down;
244 }
245
246 /*
247 * Put up a read. We can't restart any outstanding writes
248 * until we're back in synch with the IMP (i.e. we've flushed
249 * the NOOPs it throws at us).
3c238487 250 * Note: IMP_RCVBUF includes the leader.
ee6d9923
SL
251 */
252
253 x = spl5();
254 info = sc->css_ifuba.ifu_r.ifrw_info;
255 addr->css_iba = (u_short)info;
3c238487 256 addr->css_iwc = -(IMP_RCVBUF >> 1);
ee6d9923
SL
257 addr->css_icsr =
258 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
259 splx(x);
260 return(1);
261
262down:
263 ui->ui_alive = 0;
264 return(0);
265}
266
3c238487
MK
267/*
268 * Drop the host ready line to mark host down.
269 * UNTESTED.
270 */
271cssdown(unit)
272 int unit;
273{
274 register struct cssdevice *addr;
3c238487
MK
275
276 addr = (struct cssdevice *)(cssinfo[unit]->ui_addr);
277 /* reset the imp interface. */
3c238487
MK
278 addr->css_icsr = CSS_CLR;
279 addr->css_ocsr = CSS_CLR;
280 DELAY(100);
281 addr->css_icsr = 0;
282 addr->css_ocsr = 0;
35718d8f 283 cssoflush(unit);
3c238487
MK
284 return (1);
285}
286
35718d8f
MK
287cssoflush(unit)
288 int unit;
289{
2e5d9362 290 register struct css_softc *sc = &css_softc[unit];
35718d8f 291
2e5d9362
MK
292 sc->css_imp->imp_cb.ic_oactive = 0;
293 if (sc->css_ifuba.ifu_xtofree) {
294 m_freem(sc->css_ifuba.ifu_xtofree);
295 sc->css_ifuba.ifu_xtofree = 0;
35718d8f
MK
296 }
297}
298
ee6d9923
SL
299/*
300 * Start output on an interface.
301 */
3c238487
MK
302cssoutput(unit, m)
303 int unit;
304 struct mbuf *m;
ee6d9923 305{
3c238487 306 int info;
ee6d9923
SL
307 struct uba_device *ui = cssinfo[unit];
308 register struct css_softc *sc = &css_softc[unit];
309 register struct cssdevice *addr;
ee6d9923 310
ee6d9923 311 sc->css_olen = if_wubaput(&sc->css_ifuba, m);
ee6d9923
SL
312 /*
313 * Have request mapped to UNIBUS for transmission.
314 * Purge any stale data from the BDP, and start the output.
315 */
316 if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
317 UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
318 addr = (struct cssdevice *)ui->ui_addr;
319 info = sc->css_ifuba.ifu_w.ifrw_info;
320 addr->css_oba = (u_short)info;
321 addr->css_owc = -((sc->css_olen + 1) >> 1);
3c238487
MK
322 addr->css_ocsr =
323 (u_short)(CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO);
324 sc->css_imp->imp_cb.ic_oactive = 1;
ee6d9923
SL
325}
326
327/*
328 * Output interrupt handler.
329 */
330cssxint(unit)
331{
332 register struct uba_device *ui = cssinfo[unit];
333 register struct css_softc *sc = &css_softc[unit];
334 register struct cssdevice *addr;
335
ee6d9923 336 addr = (struct cssdevice *)ui->ui_addr;
3c238487 337 if (sc->css_imp->imp_cb.ic_oactive == 0) {
ee6d9923
SL
338 printf("css%d: stray output interrupt csr=%b\n",
339 unit, addr->css_ocsr, CSS_OUTBITS);
340 return;
341 }
3c238487
MK
342 sc->css_imp->imp_if.if_opackets++;
343 sc->css_imp->imp_cb.ic_oactive = 0;
ee6d9923 344 if (addr->css_ocsr & CSS_ERR){
3c238487 345 sc->css_imp->imp_if.if_oerrors++;
ee6d9923
SL
346 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
347 addr->css_ocsr, CSS_OUTBITS,
348 addr->css_icsr, CSS_INBITS);
349 }
350 if (sc->css_ifuba.ifu_xtofree) {
351 m_freem(sc->css_ifuba.ifu_xtofree);
352 sc->css_ifuba.ifu_xtofree = 0;
353 }
3c238487 354 impstart(sc->css_imp);
ee6d9923
SL
355}
356
357/*
358 * Input interrupt handler
359 */
360cssrint(unit)
361{
362 register struct css_softc *sc = &css_softc[unit];
363 register struct cssdevice *addr;
ee6d9923
SL
364 struct mbuf *m;
365 int len, info;
366
3c238487 367 sc->css_imp->imp_if.if_ipackets++;
ee6d9923
SL
368
369 /*
370 * Purge BDP; flush message if error indicated.
371 */
372
373 addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
374 if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
375 UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
376 if (addr->css_icsr & CSS_ERR) {
377 printf("css%d: recv error, csr=%b\n", unit,
378 addr->css_icsr, CSS_INBITS);
3c238487 379 sc->css_imp->imp_if.if_ierrors++;
ee6d9923
SL
380 sc->css_flush = 1;
381 }
382
383 if (sc->css_flush) {
384 if (addr->css_icsr & IN_EOM)
385 sc->css_flush = 0;
386 goto setup;
387 }
388
3c238487
MK
389 len = IMP_RCVBUF + (addr->css_iwc << 1);
390 if (len < 0 || len > IMP_RCVBUF) {
ee6d9923 391 printf("css%d: bad length=%d\n", len);
3c238487 392 sc->css_imp->imp_if.if_ierrors++;
ee6d9923
SL
393 goto setup;
394 }
395
396 /*
fd4d8418 397 * The offset parameter is always 0 since using
ee6d9923
SL
398 * trailers on the ARPAnet is insane.
399 */
3c238487 400 m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_imp->imp_if);
ee6d9923
SL
401 if (m == 0)
402 goto setup;
403 if ((addr->css_icsr & IN_EOM) == 0) {
404 if (sc->css_iq)
405 m_cat(sc->css_iq, m);
406 else
407 sc->css_iq = m;
408 goto setup;
409 }
410 if (sc->css_iq) {
411 m_cat(sc->css_iq, m);
412 m = sc->css_iq;
413 sc->css_iq = 0;
414 }
415 impinput(unit, m);
416
417setup:
418 /*
419 * Setup for next message.
420 */
421 info = sc->css_ifuba.ifu_r.ifrw_info;
422 addr->css_iba = (u_short)info;
3c238487 423 addr->css_iwc = - (IMP_RCVBUF >> 1);
ee6d9923
SL
424 addr->css_icsr =
425 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
426}
9a0b0c74 427#endif