xref: /csrg-svn/sys/vax/if/if_css.c (revision 8831)
1 /*      if_css.c     4.4     82/10/23     */
2 
3 #include "css.h"
4 
5 /*
6  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
7  * Since "imp11a" is such a mouthful, it is called
8  * "css" after the LH/DH being called "acc".
9  *
10  * Configuration notes:
11  *
12  * As delivered from DEC/CSS, it
13  * is addressed and vectored as two DR11-B's.  This makes
14  * Autoconfig almost IMPOSSIBLE.  To make it work, the
15  * interrupt vectors must be restrapped to make the vectors
16  * consecutive.  The 020 hole between the CSR addresses is
17  * tolerated, althought that could be cleaned-up also.
18  *
19  * Additionally, the TRANSMIT side of the IMP11-A has the
20  * lower address of the two subunits, so the vector ordering
21  * in the CONFIG file is reversed from most other devices.
22  * It should be:
23  *
24  * device css0 ....  cssxint cssrint
25  *
26  * If you get it wrong, it will still autoconfig, but will just
27  * sit there with RECIEVE IDLE indicated on the front panel.
28  */
29 
30 #include "../h/param.h"
31 #include "../h/systm.h"
32 #include "../h/mbuf.h"
33 #include "../h/pte.h"
34 #include "../h/buf.h"
35 #include "../h/protosw.h"
36 #include "../h/socket.h"
37 #include "../h/vmmac.h"
38 
39 #include "../net/if.h"
40 #include "../netimp/if_imp.h"
41 
42 #include "../vax/cpu.h"
43 #include "../vax/mtpr.h"
44 #include "../vaxif/if_css.h"
45 #include "../vaxif/if_uba.h"
46 #include "../vaxuba/ubareg.h"
47 #include "../vaxuba/ubavar.h"
48 
49 int     cssprobe(), cssattach(), cssrint(), cssxint();
50 struct  uba_device *cssinfo[NCSS];
51 u_short cssstd[] = { 0 };
52 struct  uba_driver cssdriver =
53         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
54 #define CSSUNIT(x)      minor(x)
55 
56 int     cssinit(), cssstart(), cssreset();
57 
58 /*
59  * "Lower half" of IMP interface driver.
60  *
61  * Each IMP interface is handled by a common module which handles
62  * the IMP-host protocol and a hardware driver which manages the
63  * hardware specific details of talking with the IMP.
64  *
65  * The hardware portion of the IMP driver handles DMA and related
66  * management of UNIBUS resources.  The IMP protocol module interprets
67  * contents of these messages and "controls" the actions of the
68  * hardware module during IMP resets, but not, for instance, during
69  * UNIBUS resets.
70  *
71  * The two modules are coupled at "attach time", and ever after,
72  * through the imp interface structure.  Higher level protocols,
73  * e.g. IP, interact with the IMP driver, rather than the CSS.
74  */
75 struct  css_softc {
76         struct  ifnet *css_if;          /* pointer to IMP's ifnet struct */
77         struct  impcb *css_ic;          /* data structure shared with IMP */
78         struct  ifuba css_ifuba;        /* UNIBUS resources */
79         struct  mbuf *css_iq;           /* input reassembly queue */
80         short   css_olen;               /* size of last message sent */
81         char    css_flush;              /* flush remainder of message */
82 } css_softc[NCSS];
83 
84 /*
85  * Reset the IMP and cause a transmitter interrupt by
86  * performing a null DMA.
87  */
88 cssprobe(reg)
89         caddr_t reg;
90 {
91         register int br, cvec;          /* r11, r10 value-result */
92         register struct cssdevice *addr = (struct cssdevice *)reg;
93 
94 COUNT(CSSPROBE);
95 #ifdef lint
96         br = 0; cvec = br; br = cvec;
97         cssrint(0); cssxint(0);
98 #endif
99 
100 
101         addr->css_icsr = CSS_CLR;
102         addr->css_ocsr = CSS_CLR;
103         DELAY(50000);
104 	addr->css_icsr = 0;
105 	addr->css_ocsr = 0;
106         DELAY(50000);
107 
108 	addr->css_oba = 0;
109 	addr->css_owc = -1;
110         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
111         DELAY(50000);
112         addr->css_ocsr = 0;
113 
114         return (1);
115 }
116 
117 /*
118  * Call the IMP module to allow it to set up its internal
119  * state, then tie the two modules together by setting up
120  * the back pointers to common data structures.
121  */
122 cssattach(ui)
123         struct uba_device *ui;
124 {
125         register struct css_softc *sc = &css_softc[ui->ui_unit];
126         register struct impcb *ip;
127         struct ifimpcb {
128                 struct  ifnet ifimp_if;
129                 struct  impcb ifimp_impcb;
130         } *ifimp;
131 
132 COUNT(CSSATTACH);
133         if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0)
134                 panic("cssattach");             /* XXX */
135         sc->css_if = &ifimp->ifimp_if;
136         ip = &ifimp->ifimp_impcb;
137         sc->css_ic = ip;
138         ip->ic_init = cssinit;
139         ip->ic_start = cssstart;
140 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
141 #ifdef notdef
142 	sc->css_ifuba.ifu_flags =| UBA_NEEDBDP;
143 #endif
144 }
145 
146 /*
147  * Reset interface after UNIBUS reset.
148  * If interface is on specified uba, reset its state.
149  */
150 cssreset(unit, uban)
151         int unit, uban;
152 {
153         register struct uba_device *ui;
154         struct css_softc *sc;
155 
156 COUNT(CSSCLR);
157         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
158             ui->ui_ubanum != uban)
159                 return;
160         printf(" css%d", unit);
161         sc = &css_softc[unit];
162         /* must go through IMP to allow it to set state */
163         (*sc->css_if->if_init)(unit);
164 }
165 
166 /*
167  * Initialize interface: clear recorded pending operations,
168  * and retrieve, and reinitialize UNIBUS resources.
169  */
170 cssinit(unit)
171         int unit;
172 {
173         register struct css_softc *sc;
174         register struct uba_device *ui;
175         register struct cssdevice *addr;
176         int x, info;
177 
178 COUNT(CSSINIT);
179 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
180 		printf("css%d: not alive\n", unit);
181 		return(0);
182 	}
183 	sc = &css_softc[unit];
184 
185 	/*
186 	 * Header length is 0 to if_ubainit since we have to pass
187 	 * the IMP leader up to the protocol interpretaion
188 	 * routines.  If we had the deader length as
189 	 * sizeof(struct imp_leader), then the if_ routines
190 	 * would assume we handle it on input and output.
191 	 */
192 
193         if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) {
194                 printf("css%d: can't initialize\n", unit);
195 		ui->ui_alive = 0;
196 		return(0);
197         }
198         addr = (struct cssdevice *)ui->ui_addr;
199 
200         /* reset the imp interface. */
201         x = spl5();
202         addr->css_icsr = CSS_CLR;
203         addr->css_ocsr = CSS_CLR;
204 	DELAY(100);
205 	addr->css_icsr = 0;
206 	addr->css_ocsr = 0;
207         addr->css_icsr = IN_HRDY;       /* close the relay */
208 	DELAY(5000);
209         splx(x);
210 
211         /*
212 	 * This may hang if the imp isn't really there.
213 	 * Will test and verify safe operation.
214 	 */
215 
216 	x = 500;
217 	while (x-- > 0) {
218 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
219 			break;
220                 addr->css_icsr = IN_HRDY;	/* close the relay */
221                 DELAY(5000);
222         }
223 
224 	if (x <= 0) {
225 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
226 			CSS_INBITS, addr->css_icsr);
227 		goto down;
228 	}
229 
230         /*
231          * Put up a read.  We can't restart any outstanding writes
232          * until we're back in synch with the IMP (i.e. we've flushed
233          * the NOOPs it throws at us).
234 	 * Note: IMPMTU includes the leader.
235          */
236 
237         x = spl5();
238         info = sc->css_ifuba.ifu_r.ifrw_info;
239         addr->css_iba = (u_short)info;
240         addr->css_iwc = -(IMPMTU >> 1);
241         addr->css_icsr =
242                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
243         splx(x);
244 	return(1);
245 
246 down:
247 	ui->ui_alive = 0;
248 	return(0);
249 }
250 
251 /*
252  * Start output on an interface.
253  */
254 cssstart(dev)
255         dev_t dev;
256 {
257         int unit = CSSUNIT(dev), info;
258         struct uba_device *ui = cssinfo[unit];
259         register struct css_softc *sc = &css_softc[unit];
260         register struct cssdevice *addr;
261         struct mbuf *m;
262         u_short cmd;
263 
264 COUNT(CSSSTART);
265         if (sc->css_ic->ic_oactive)
266                 goto restart;
267 
268         /*
269          * Not already active, deqeue a request and
270          * map it onto the UNIBUS.  If no more
271          * requeusts, just return.
272          */
273         IF_DEQUEUE(&sc->css_if->if_snd, m);
274         if (m == 0) {
275                 sc->css_ic->ic_oactive = 0;
276                 return;
277         }
278         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
279 
280 restart:
281         /*
282          * Have request mapped to UNIBUS for transmission.
283          * Purge any stale data from the BDP, and start the output.
284          */
285 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
286 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
287         addr = (struct cssdevice *)ui->ui_addr;
288         info = sc->css_ifuba.ifu_w.ifrw_info;
289         addr->css_oba = (u_short)info;
290         addr->css_owc = -((sc->css_olen + 1) >> 1);
291         cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO;
292         addr->css_ocsr = cmd;
293         sc->css_ic->ic_oactive = 1;
294 }
295 
296 /*
297  * Output interrupt handler.
298  */
299 cssxint(unit)
300 {
301         register struct uba_device *ui = cssinfo[unit];
302         register struct css_softc *sc = &css_softc[unit];
303         register struct cssdevice *addr;
304 
305 COUNT(CSSXINT);
306         addr = (struct cssdevice *)ui->ui_addr;
307         if (sc->css_ic->ic_oactive == 0) {
308                 printf("css%d: stray output interrupt csr=%b\n",
309 			unit, addr->css_ocsr, CSS_OUTBITS);
310                 return;
311         }
312         sc->css_if->if_opackets++;
313         sc->css_ic->ic_oactive = 0;
314         if (addr->css_ocsr & CSS_ERR){
315                 sc->css_if->if_oerrors++;
316                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
317                         addr->css_ocsr, CSS_OUTBITS,
318 			addr->css_icsr, CSS_INBITS);
319 	}
320 	if (sc->css_ifuba.ifu_xtofree) {
321 		m_freem(sc->css_ifuba.ifu_xtofree);
322 		sc->css_ifuba.ifu_xtofree = 0;
323 	}
324 	if (sc->css_if->if_snd.ifq_head)
325 		cssstart(unit);
326 }
327 
328 /*
329  * Input interrupt handler
330  */
331 cssrint(unit)
332 {
333         register struct css_softc *sc = &css_softc[unit];
334         register struct cssdevice *addr;
335         register struct ifqueue *inq;
336         struct mbuf *m;
337         int len, info;
338 
339 COUNT(CSSRINT);
340         sc->css_if->if_ipackets++;
341 
342         /*
343          * Purge BDP; flush message if error indicated.
344          */
345 
346         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
347 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
348 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
349         if (addr->css_icsr & CSS_ERR) {
350                 printf("css%d: recv error, csr=%b\n", unit,
351                     addr->css_icsr, CSS_INBITS);
352                 sc->css_if->if_ierrors++;
353                 sc->css_flush = 1;
354         }
355 
356         if (sc->css_flush) {
357                 if (addr->css_icsr & IN_EOM)
358                         sc->css_flush = 0;
359                 goto setup;
360         }
361 
362         len = IMPMTU + (addr->css_iwc << 1);
363 	if (len < 0 || len > IMPMTU) {
364 		printf("css%d: bad length=%d\n", len);
365 		sc->css_if->if_ierrors++;
366 		goto setup;
367 	}
368 
369         /*
370          * The last parameter is always 0 since using
371          * trailers on the ARPAnet is insane.
372          */
373         m = if_rubaget(&sc->css_ifuba, len, 0);
374         if (m == 0)
375                 goto setup;
376         if ((addr->css_icsr & IN_EOM) == 0) {
377 		if (sc->css_iq)
378 			m_cat(sc->css_iq, m);
379 		else
380 			sc->css_iq = m;
381 		goto setup;
382 	}
383 	if (sc->css_iq) {
384 		m_cat(sc->css_iq, m);
385 		m = sc->css_iq;
386 		sc->css_iq = 0;
387         }
388         impinput(unit, m);
389 
390 setup:
391         /*
392          * Setup for next message.
393          */
394         info = sc->css_ifuba.ifu_r.ifrw_info;
395         addr->css_iba = (u_short)info;
396         addr->css_iwc = - (IMPMTU >> 1);
397         addr->css_icsr =
398                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
399 }
400