xref: /csrg-svn/sys/vax/if/if_css.c (revision 45801)
123283Smckusick /*
234868Sbostic  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
333452Skarels  * All rights reserved.
423283Smckusick  *
544556Sbostic  * %sccs.include.redist.c%
633452Skarels  *
7*45801Sbostic  *	@(#)if_css.c	7.9 (Berkeley) 12/16/90
823283Smckusick  */
97468Ssam 
107468Ssam #include "css.h"
1125270Sbloom #if NCSS > 0
127468Ssam 
137468Ssam /*
147468Ssam  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
157468Ssam  * Since "imp11a" is such a mouthful, it is called
167468Ssam  * "css" after the LH/DH being called "acc".
177468Ssam  *
187468Ssam  * Configuration notes:
197468Ssam  *
207468Ssam  * As delivered from DEC/CSS, it
217468Ssam  * is addressed and vectored as two DR11-B's.  This makes
227468Ssam  * Autoconfig almost IMPOSSIBLE.  To make it work, the
237468Ssam  * interrupt vectors must be restrapped to make the vectors
247468Ssam  * consecutive.  The 020 hole between the CSR addresses is
257468Ssam  * tolerated, althought that could be cleaned-up also.
267468Ssam  *
277468Ssam  * Additionally, the TRANSMIT side of the IMP11-A has the
287468Ssam  * lower address of the two subunits, so the vector ordering
297468Ssam  * in the CONFIG file is reversed from most other devices.
307468Ssam  * It should be:
317468Ssam  *
327468Ssam  * device css0 ....  cssxint cssrint
337468Ssam  *
347468Ssam  * If you get it wrong, it will still autoconfig, but will just
3524800Skarels  * sit there with RECEIVE IDLE indicated on the front panel.
367468Ssam  */
37*45801Sbostic #include "sys/param.h"
38*45801Sbostic #include "sys/systm.h"
39*45801Sbostic #include "sys/mbuf.h"
40*45801Sbostic #include "sys/buf.h"
41*45801Sbostic #include "sys/protosw.h"
42*45801Sbostic #include "sys/socket.h"
43*45801Sbostic #include "sys/vmmac.h"
448459Sroot 
45*45801Sbostic #include "../include/pte.h"
4633452Skarels 
47*45801Sbostic #include "net/if.h"
48*45801Sbostic #include "netimp/if_imp.h"
498459Sroot 
50*45801Sbostic #include "../include/cpu.h"
51*45801Sbostic #include "../include/mtpr.h"
5217110Sbloom #include "if_cssreg.h"
5317110Sbloom #include "if_uba.h"
54*45801Sbostic #include "../uba/ubareg.h"
55*45801Sbostic #include "../uba/ubavar.h"
567468Ssam 
577468Ssam int     cssprobe(), cssattach(), cssrint(), cssxint();
587468Ssam struct  uba_device *cssinfo[NCSS];
597468Ssam u_short cssstd[] = { 0 };
607468Ssam struct  uba_driver cssdriver =
617468Ssam         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
627468Ssam 
6333452Skarels int     cssinit(), cssoutput(), cssdown(), cssreset();
647468Ssam 
657468Ssam /*
667468Ssam  * "Lower half" of IMP interface driver.
677468Ssam  *
687468Ssam  * Each IMP interface is handled by a common module which handles
697468Ssam  * the IMP-host protocol and a hardware driver which manages the
707468Ssam  * hardware specific details of talking with the IMP.
717468Ssam  *
727468Ssam  * The hardware portion of the IMP driver handles DMA and related
737468Ssam  * management of UNIBUS resources.  The IMP protocol module interprets
747468Ssam  * contents of these messages and "controls" the actions of the
757468Ssam  * hardware module during IMP resets, but not, for instance, during
767468Ssam  * UNIBUS resets.
777468Ssam  *
787468Ssam  * The two modules are coupled at "attach time", and ever after,
797468Ssam  * through the imp interface structure.  Higher level protocols,
807468Ssam  * e.g. IP, interact with the IMP driver, rather than the CSS.
817468Ssam  */
827468Ssam struct  css_softc {
8333452Skarels 	struct	imp_softc *css_imp;	/* pointer to IMP's imp_softc struct */
8433452Skarels 	struct	ifuba css_ifuba;	/* UNIBUS resources */
8533452Skarels 	struct	mbuf *css_iq;		/* input reassembly queue */
8633452Skarels 	short	css_olen;		/* size of last message sent */
8733452Skarels 	char	css_flush;		/* flush remainder of message */
887468Ssam } css_softc[NCSS];
897468Ssam 
907468Ssam /*
917468Ssam  * Reset the IMP and cause a transmitter interrupt by
927468Ssam  * performing a null DMA.
937468Ssam  */
cssprobe(reg)947468Ssam cssprobe(reg)
957468Ssam         caddr_t reg;
967468Ssam {
977468Ssam         register int br, cvec;          /* r11, r10 value-result */
987468Ssam         register struct cssdevice *addr = (struct cssdevice *)reg;
997468Ssam 
1007468Ssam #ifdef lint
1017468Ssam         br = 0; cvec = br; br = cvec;
1027468Ssam         cssrint(0); cssxint(0);
1037468Ssam #endif
1047468Ssam 
1057468Ssam         addr->css_icsr = CSS_CLR;
1067468Ssam         addr->css_ocsr = CSS_CLR;
1077468Ssam         DELAY(50000);
1087468Ssam 	addr->css_icsr = 0;
1097468Ssam 	addr->css_ocsr = 0;
1107468Ssam         DELAY(50000);
1117468Ssam 
1127468Ssam 	addr->css_oba = 0;
1137468Ssam 	addr->css_owc = -1;
1147468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1157468Ssam         DELAY(50000);
1167468Ssam         addr->css_ocsr = 0;
1177468Ssam 
1187468Ssam         return (1);
1197468Ssam }
1207468Ssam 
1217468Ssam /*
1227468Ssam  * Call the IMP module to allow it to set up its internal
1237468Ssam  * state, then tie the two modules together by setting up
1247468Ssam  * the back pointers to common data structures.
1257468Ssam  */
cssattach(ui)1267468Ssam cssattach(ui)
12734273Skarels         register struct uba_device *ui;
1287468Ssam {
1297468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1307468Ssam         register struct impcb *ip;
1317468Ssam 
13234273Skarels         if ((sc->css_imp = impattach(ui->ui_driver->ud_dname, ui->ui_unit,
13334273Skarels 	    cssreset)) == 0)
13424800Skarels                 return;
13533452Skarels 	ip = &sc->css_imp->imp_cb;
1367468Ssam         ip->ic_init = cssinit;
13733452Skarels         ip->ic_output = cssoutput;
13833452Skarels         ip->ic_down = cssdown;
1397468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1407468Ssam #ifdef notdef
14132775Sbostic 	sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
1427468Ssam #endif
1437468Ssam }
1447468Ssam 
1457468Ssam /*
1467468Ssam  * Reset interface after UNIBUS reset.
1477468Ssam  * If interface is on specified uba, reset its state.
1487468Ssam  */
cssreset(unit,uban)1497468Ssam cssreset(unit, uban)
1507468Ssam         int unit, uban;
1517468Ssam {
1527468Ssam         register struct uba_device *ui;
15333452Skarels         register struct css_softc *sc;
1547468Ssam 
1557468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1567468Ssam             ui->ui_ubanum != uban)
1577468Ssam                 return;
1587468Ssam         printf(" css%d", unit);
1597468Ssam         sc = &css_softc[unit];
16033452Skarels 	sc->css_imp->imp_if.if_flags &= ~IFF_RUNNING;
16134273Skarels 	cssoflush(unit);
1627468Ssam         /* must go through IMP to allow it to set state */
16333452Skarels         (*sc->css_imp->imp_if.if_init)(sc->css_imp->imp_if.if_unit);
1647468Ssam }
1657468Ssam 
1667468Ssam /*
1677468Ssam  * Initialize interface: clear recorded pending operations,
1687468Ssam  * and retrieve, and reinitialize UNIBUS resources.
1697468Ssam  */
cssinit(unit)1707468Ssam cssinit(unit)
1717468Ssam         int unit;
1727468Ssam {
1737468Ssam         register struct css_softc *sc;
1747468Ssam         register struct uba_device *ui;
1757468Ssam         register struct cssdevice *addr;
1767468Ssam         int x, info;
1777468Ssam 
1787468Ssam 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
1797468Ssam 		printf("css%d: not alive\n", unit);
1807468Ssam 		return(0);
1817468Ssam 	}
1827468Ssam 	sc = &css_softc[unit];
1837468Ssam 
1847468Ssam 	/*
1857468Ssam 	 * Header length is 0 to if_ubainit since we have to pass
1867468Ssam 	 * the IMP leader up to the protocol interpretaion
1877468Ssam 	 * routines.  If we had the deader length as
1887468Ssam 	 * sizeof(struct imp_leader), then the if_ routines
1897468Ssam 	 * would assume we handle it on input and output.
1907468Ssam 	 */
1917468Ssam 
19233452Skarels         if ((sc->css_imp->imp_if.if_flags & IFF_RUNNING) == 0 &&
19333452Skarels 	    if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,
19433452Skarels 	    (int)btoc(IMP_RCVBUF)) == 0) {
1957468Ssam                 printf("css%d: can't initialize\n", unit);
1967468Ssam 		ui->ui_alive = 0;
19733452Skarels 		sc->css_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING);
1987468Ssam 		return(0);
1997468Ssam         }
20033452Skarels 	sc->css_imp->imp_if.if_flags |= IFF_RUNNING;
2017468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2027468Ssam 
2037468Ssam         /* reset the imp interface. */
2047468Ssam         x = spl5();
2057468Ssam         addr->css_icsr = CSS_CLR;
2067468Ssam         addr->css_ocsr = CSS_CLR;
2077468Ssam 	DELAY(100);
2087468Ssam 	addr->css_icsr = 0;
2097468Ssam 	addr->css_ocsr = 0;
2107468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2117468Ssam 	DELAY(5000);
2127468Ssam         splx(x);
2137468Ssam 
2147468Ssam         /*
2157468Ssam 	 * This may hang if the imp isn't really there.
2167468Ssam 	 * Will test and verify safe operation.
2177468Ssam 	 */
2187468Ssam 
2197468Ssam 	x = 500;
2207468Ssam 	while (x-- > 0) {
2217468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2227468Ssam 			break;
2237468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2247468Ssam                 DELAY(5000);
2257468Ssam         }
2267468Ssam 
2277468Ssam 	if (x <= 0) {
2287468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2297468Ssam 			CSS_INBITS, addr->css_icsr);
2307468Ssam 		goto down;
2317468Ssam 	}
2327468Ssam 
2337468Ssam         /*
2347468Ssam          * Put up a read.  We can't restart any outstanding writes
2357468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2367468Ssam          * the NOOPs it throws at us).
23733452Skarels 	 * Note: IMP_RCVBUF includes the leader.
2387468Ssam          */
2397468Ssam 
2407468Ssam         x = spl5();
2417468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2427468Ssam         addr->css_iba = (u_short)info;
24333452Skarels         addr->css_iwc = -(IMP_RCVBUF >> 1);
2447468Ssam         addr->css_icsr =
2457468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2467468Ssam         splx(x);
2477468Ssam 	return(1);
2487468Ssam 
2497468Ssam down:
2507468Ssam 	ui->ui_alive = 0;
2517468Ssam 	return(0);
2527468Ssam }
2537468Ssam 
2547468Ssam /*
25533452Skarels  * Drop the host ready line to mark host down.
25633452Skarels  * UNTESTED.
25733452Skarels  */
cssdown(unit)25833452Skarels cssdown(unit)
25933452Skarels 	int unit;
26033452Skarels {
26133452Skarels         register struct cssdevice *addr;
26233452Skarels 
26333452Skarels 	addr = (struct cssdevice *)(cssinfo[unit]->ui_addr);
26433452Skarels         /* reset the imp interface. */
26533452Skarels         addr->css_icsr = CSS_CLR;
26633452Skarels         addr->css_ocsr = CSS_CLR;
26733452Skarels 	DELAY(100);
26833452Skarels 	addr->css_icsr = 0;
26933452Skarels 	addr->css_ocsr = 0;
27034273Skarels 	cssoflush(unit);
27133452Skarels 	return (1);
27233452Skarels }
27333452Skarels 
cssoflush(unit)27434273Skarels cssoflush(unit)
27534273Skarels 	int unit;
27634273Skarels {
27734501Skarels 	register struct css_softc *sc = &css_softc[unit];
27834273Skarels 
27934501Skarels 	sc->css_imp->imp_cb.ic_oactive = 0;
28034501Skarels 	if (sc->css_ifuba.ifu_xtofree) {
28134501Skarels 		m_freem(sc->css_ifuba.ifu_xtofree);
28234501Skarels 		sc->css_ifuba.ifu_xtofree = 0;
28334273Skarels 	}
28434273Skarels }
28534273Skarels 
28633452Skarels /*
2877468Ssam  * Start output on an interface.
2887468Ssam  */
cssoutput(unit,m)28933452Skarels cssoutput(unit, m)
29033452Skarels         int unit;
29133452Skarels         struct mbuf *m;
2927468Ssam {
29333452Skarels         int info;
2947468Ssam         struct uba_device *ui = cssinfo[unit];
2957468Ssam         register struct css_softc *sc = &css_softc[unit];
2967468Ssam         register struct cssdevice *addr;
2977468Ssam 
2987468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
2997468Ssam         /*
3007468Ssam          * Have request mapped to UNIBUS for transmission.
3017468Ssam          * Purge any stale data from the BDP, and start the output.
3027468Ssam          */
3037468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3047468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
3057468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3067468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
3077468Ssam         addr->css_oba = (u_short)info;
3087468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
30933452Skarels         addr->css_ocsr =
31033452Skarels 	    (u_short)(CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO);
31133452Skarels         sc->css_imp->imp_cb.ic_oactive = 1;
3127468Ssam }
3137468Ssam 
3147468Ssam /*
3157468Ssam  * Output interrupt handler.
3167468Ssam  */
cssxint(unit)3177468Ssam cssxint(unit)
3187468Ssam {
3197468Ssam         register struct uba_device *ui = cssinfo[unit];
3207468Ssam         register struct css_softc *sc = &css_softc[unit];
3217468Ssam         register struct cssdevice *addr;
3227468Ssam 
3237468Ssam         addr = (struct cssdevice *)ui->ui_addr;
32433452Skarels         if (sc->css_imp->imp_cb.ic_oactive == 0) {
3257468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3267468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3277468Ssam                 return;
3287468Ssam         }
32933452Skarels         sc->css_imp->imp_if.if_opackets++;
33033452Skarels         sc->css_imp->imp_cb.ic_oactive = 0;
3317468Ssam         if (addr->css_ocsr & CSS_ERR){
33233452Skarels                 sc->css_imp->imp_if.if_oerrors++;
3337468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3347468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3357468Ssam 			addr->css_icsr, CSS_INBITS);
3367468Ssam 	}
3377468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3387468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3397468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3407468Ssam 	}
34133452Skarels 	impstart(sc->css_imp);
3427468Ssam }
3437468Ssam 
3447468Ssam /*
3457468Ssam  * Input interrupt handler
3467468Ssam  */
cssrint(unit)3477468Ssam cssrint(unit)
3487468Ssam {
3497468Ssam         register struct css_softc *sc = &css_softc[unit];
3507468Ssam         register struct cssdevice *addr;
3517468Ssam         struct mbuf *m;
3527468Ssam         int len, info;
3537468Ssam 
35433452Skarels         sc->css_imp->imp_if.if_ipackets++;
3557468Ssam 
3567468Ssam         /*
3577468Ssam          * Purge BDP; flush message if error indicated.
3587468Ssam          */
3597468Ssam 
3607468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3617468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3627468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3637468Ssam         if (addr->css_icsr & CSS_ERR) {
3647468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3657468Ssam                     addr->css_icsr, CSS_INBITS);
36633452Skarels                 sc->css_imp->imp_if.if_ierrors++;
3677468Ssam                 sc->css_flush = 1;
3687468Ssam         }
3697468Ssam 
3707468Ssam         if (sc->css_flush) {
3717468Ssam                 if (addr->css_icsr & IN_EOM)
3727468Ssam                         sc->css_flush = 0;
3737468Ssam                 goto setup;
3747468Ssam         }
3757468Ssam 
37633452Skarels         len = IMP_RCVBUF + (addr->css_iwc << 1);
37733452Skarels 	if (len < 0 || len > IMP_RCVBUF) {
3787468Ssam 		printf("css%d: bad length=%d\n", len);
37933452Skarels 		sc->css_imp->imp_if.if_ierrors++;
3807468Ssam 		goto setup;
3817468Ssam 	}
3827468Ssam 
3837468Ssam         /*
38424800Skarels          * The offset parameter is always 0 since using
3857468Ssam          * trailers on the ARPAnet is insane.
3867468Ssam          */
38733452Skarels         m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_imp->imp_if);
3887468Ssam         if (m == 0)
3897468Ssam                 goto setup;
3907468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
3917468Ssam 		if (sc->css_iq)
3927468Ssam 			m_cat(sc->css_iq, m);
3937468Ssam 		else
3947468Ssam 			sc->css_iq = m;
3957468Ssam 		goto setup;
3967468Ssam 	}
3977468Ssam 	if (sc->css_iq) {
3987468Ssam 		m_cat(sc->css_iq, m);
3997468Ssam 		m = sc->css_iq;
4007468Ssam 		sc->css_iq = 0;
4017468Ssam         }
4027468Ssam         impinput(unit, m);
4037468Ssam 
4047468Ssam setup:
4057468Ssam         /*
4067468Ssam          * Setup for next message.
4077468Ssam          */
4087468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
4097468Ssam         addr->css_iba = (u_short)info;
41033452Skarels         addr->css_iwc = - (IMP_RCVBUF >> 1);
4117468Ssam         addr->css_icsr =
4127468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
4137468Ssam }
41425270Sbloom #endif
415