xref: /csrg-svn/sys/vax/if/if_css.c (revision 34501)
123283Smckusick /*
233452Skarels  * Copyright (c) 1982,1986,1988 Regents of the University of California.
333452Skarels  * All rights reserved.
423283Smckusick  *
533452Skarels  * Redistribution and use in source and binary forms are permitted
633452Skarels  * provided that this notice is preserved and that due credit is given
733452Skarels  * to the University of California at Berkeley. The name of the University
833452Skarels  * may not be used to endorse or promote products derived from this
933452Skarels  * software without specific prior written permission. This software
1033452Skarels  * is provided ``as is'' without express or implied warranty.
1133452Skarels  *
12*34501Skarels  *	@(#)if_css.c	7.5 (Berkeley) 05/26/88
1323283Smckusick  */
147468Ssam 
157468Ssam #include "css.h"
1625270Sbloom #if NCSS > 0
177468Ssam 
187468Ssam /*
197468Ssam  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
207468Ssam  * Since "imp11a" is such a mouthful, it is called
217468Ssam  * "css" after the LH/DH being called "acc".
227468Ssam  *
237468Ssam  * Configuration notes:
247468Ssam  *
257468Ssam  * As delivered from DEC/CSS, it
267468Ssam  * is addressed and vectored as two DR11-B's.  This makes
277468Ssam  * Autoconfig almost IMPOSSIBLE.  To make it work, the
287468Ssam  * interrupt vectors must be restrapped to make the vectors
297468Ssam  * consecutive.  The 020 hole between the CSR addresses is
307468Ssam  * tolerated, althought that could be cleaned-up also.
317468Ssam  *
327468Ssam  * Additionally, the TRANSMIT side of the IMP11-A has the
337468Ssam  * lower address of the two subunits, so the vector ordering
347468Ssam  * in the CONFIG file is reversed from most other devices.
357468Ssam  * It should be:
367468Ssam  *
377468Ssam  * device css0 ....  cssxint cssrint
387468Ssam  *
397468Ssam  * If you get it wrong, it will still autoconfig, but will just
4024800Skarels  * sit there with RECEIVE IDLE indicated on the front panel.
417468Ssam  */
4217110Sbloom #include "param.h"
4317110Sbloom #include "systm.h"
4417110Sbloom #include "mbuf.h"
4517110Sbloom #include "buf.h"
4617110Sbloom #include "protosw.h"
4717110Sbloom #include "socket.h"
4817110Sbloom #include "vmmac.h"
498459Sroot 
5033452Skarels #include "../machine/pte.h"
5133452Skarels 
527468Ssam #include "../net/if.h"
538415Swnj #include "../netimp/if_imp.h"
548459Sroot 
558459Sroot #include "../vax/cpu.h"
568459Sroot #include "../vax/mtpr.h"
5717110Sbloom #include "if_cssreg.h"
5817110Sbloom #include "if_uba.h"
598459Sroot #include "../vaxuba/ubareg.h"
608459Sroot #include "../vaxuba/ubavar.h"
617468Ssam 
627468Ssam int     cssprobe(), cssattach(), cssrint(), cssxint();
637468Ssam struct  uba_device *cssinfo[NCSS];
647468Ssam u_short cssstd[] = { 0 };
657468Ssam struct  uba_driver cssdriver =
667468Ssam         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
677468Ssam 
6833452Skarels int     cssinit(), cssoutput(), cssdown(), cssreset();
697468Ssam 
707468Ssam /*
717468Ssam  * "Lower half" of IMP interface driver.
727468Ssam  *
737468Ssam  * Each IMP interface is handled by a common module which handles
747468Ssam  * the IMP-host protocol and a hardware driver which manages the
757468Ssam  * hardware specific details of talking with the IMP.
767468Ssam  *
777468Ssam  * The hardware portion of the IMP driver handles DMA and related
787468Ssam  * management of UNIBUS resources.  The IMP protocol module interprets
797468Ssam  * contents of these messages and "controls" the actions of the
807468Ssam  * hardware module during IMP resets, but not, for instance, during
817468Ssam  * UNIBUS resets.
827468Ssam  *
837468Ssam  * The two modules are coupled at "attach time", and ever after,
847468Ssam  * through the imp interface structure.  Higher level protocols,
857468Ssam  * e.g. IP, interact with the IMP driver, rather than the CSS.
867468Ssam  */
877468Ssam struct  css_softc {
8833452Skarels 	struct	imp_softc *css_imp;	/* pointer to IMP's imp_softc struct */
8933452Skarels 	struct	ifuba css_ifuba;	/* UNIBUS resources */
9033452Skarels 	struct	mbuf *css_iq;		/* input reassembly queue */
9133452Skarels 	short	css_olen;		/* size of last message sent */
9233452Skarels 	char	css_flush;		/* flush remainder of message */
937468Ssam } css_softc[NCSS];
947468Ssam 
957468Ssam /*
967468Ssam  * Reset the IMP and cause a transmitter interrupt by
977468Ssam  * performing a null DMA.
987468Ssam  */
997468Ssam cssprobe(reg)
1007468Ssam         caddr_t reg;
1017468Ssam {
1027468Ssam         register int br, cvec;          /* r11, r10 value-result */
1037468Ssam         register struct cssdevice *addr = (struct cssdevice *)reg;
1047468Ssam 
1057468Ssam #ifdef lint
1067468Ssam         br = 0; cvec = br; br = cvec;
1077468Ssam         cssrint(0); cssxint(0);
1087468Ssam #endif
1097468Ssam 
1107468Ssam         addr->css_icsr = CSS_CLR;
1117468Ssam         addr->css_ocsr = CSS_CLR;
1127468Ssam         DELAY(50000);
1137468Ssam 	addr->css_icsr = 0;
1147468Ssam 	addr->css_ocsr = 0;
1157468Ssam         DELAY(50000);
1167468Ssam 
1177468Ssam 	addr->css_oba = 0;
1187468Ssam 	addr->css_owc = -1;
1197468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1207468Ssam         DELAY(50000);
1217468Ssam         addr->css_ocsr = 0;
1227468Ssam 
1237468Ssam         return (1);
1247468Ssam }
1257468Ssam 
1267468Ssam /*
1277468Ssam  * Call the IMP module to allow it to set up its internal
1287468Ssam  * state, then tie the two modules together by setting up
1297468Ssam  * the back pointers to common data structures.
1307468Ssam  */
1317468Ssam cssattach(ui)
13234273Skarels         register struct uba_device *ui;
1337468Ssam {
1347468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1357468Ssam         register struct impcb *ip;
1367468Ssam 
13734273Skarels         if ((sc->css_imp = impattach(ui->ui_driver->ud_dname, ui->ui_unit,
13834273Skarels 	    cssreset)) == 0)
13924800Skarels                 return;
14033452Skarels 	ip = &sc->css_imp->imp_cb;
1417468Ssam         ip->ic_init = cssinit;
14233452Skarels         ip->ic_output = cssoutput;
14333452Skarels         ip->ic_down = cssdown;
1447468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1457468Ssam #ifdef notdef
14632775Sbostic 	sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
1477468Ssam #endif
1487468Ssam }
1497468Ssam 
1507468Ssam /*
1517468Ssam  * Reset interface after UNIBUS reset.
1527468Ssam  * If interface is on specified uba, reset its state.
1537468Ssam  */
1547468Ssam cssreset(unit, uban)
1557468Ssam         int unit, uban;
1567468Ssam {
1577468Ssam         register struct uba_device *ui;
15833452Skarels         register struct css_softc *sc;
1597468Ssam 
1607468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1617468Ssam             ui->ui_ubanum != uban)
1627468Ssam                 return;
1637468Ssam         printf(" css%d", unit);
1647468Ssam         sc = &css_softc[unit];
16533452Skarels 	sc->css_imp->imp_if.if_flags &= ~IFF_RUNNING;
16634273Skarels 	cssoflush(unit);
1677468Ssam         /* must go through IMP to allow it to set state */
16833452Skarels         (*sc->css_imp->imp_if.if_init)(sc->css_imp->imp_if.if_unit);
1697468Ssam }
1707468Ssam 
1717468Ssam /*
1727468Ssam  * Initialize interface: clear recorded pending operations,
1737468Ssam  * and retrieve, and reinitialize UNIBUS resources.
1747468Ssam  */
1757468Ssam cssinit(unit)
1767468Ssam         int unit;
1777468Ssam {
1787468Ssam         register struct css_softc *sc;
1797468Ssam         register struct uba_device *ui;
1807468Ssam         register struct cssdevice *addr;
1817468Ssam         int x, info;
1827468Ssam 
1837468Ssam 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
1847468Ssam 		printf("css%d: not alive\n", unit);
1857468Ssam 		return(0);
1867468Ssam 	}
1877468Ssam 	sc = &css_softc[unit];
1887468Ssam 
1897468Ssam 	/*
1907468Ssam 	 * Header length is 0 to if_ubainit since we have to pass
1917468Ssam 	 * the IMP leader up to the protocol interpretaion
1927468Ssam 	 * routines.  If we had the deader length as
1937468Ssam 	 * sizeof(struct imp_leader), then the if_ routines
1947468Ssam 	 * would assume we handle it on input and output.
1957468Ssam 	 */
1967468Ssam 
19733452Skarels         if ((sc->css_imp->imp_if.if_flags & IFF_RUNNING) == 0 &&
19833452Skarels 	    if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,
19933452Skarels 	    (int)btoc(IMP_RCVBUF)) == 0) {
2007468Ssam                 printf("css%d: can't initialize\n", unit);
2017468Ssam 		ui->ui_alive = 0;
20233452Skarels 		sc->css_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING);
2037468Ssam 		return(0);
2047468Ssam         }
20533452Skarels 	sc->css_imp->imp_if.if_flags |= IFF_RUNNING;
2067468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2077468Ssam 
2087468Ssam         /* reset the imp interface. */
2097468Ssam         x = spl5();
2107468Ssam         addr->css_icsr = CSS_CLR;
2117468Ssam         addr->css_ocsr = CSS_CLR;
2127468Ssam 	DELAY(100);
2137468Ssam 	addr->css_icsr = 0;
2147468Ssam 	addr->css_ocsr = 0;
2157468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2167468Ssam 	DELAY(5000);
2177468Ssam         splx(x);
2187468Ssam 
2197468Ssam         /*
2207468Ssam 	 * This may hang if the imp isn't really there.
2217468Ssam 	 * Will test and verify safe operation.
2227468Ssam 	 */
2237468Ssam 
2247468Ssam 	x = 500;
2257468Ssam 	while (x-- > 0) {
2267468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2277468Ssam 			break;
2287468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2297468Ssam                 DELAY(5000);
2307468Ssam         }
2317468Ssam 
2327468Ssam 	if (x <= 0) {
2337468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2347468Ssam 			CSS_INBITS, addr->css_icsr);
2357468Ssam 		goto down;
2367468Ssam 	}
2377468Ssam 
2387468Ssam         /*
2397468Ssam          * Put up a read.  We can't restart any outstanding writes
2407468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2417468Ssam          * the NOOPs it throws at us).
24233452Skarels 	 * Note: IMP_RCVBUF includes the leader.
2437468Ssam          */
2447468Ssam 
2457468Ssam         x = spl5();
2467468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2477468Ssam         addr->css_iba = (u_short)info;
24833452Skarels         addr->css_iwc = -(IMP_RCVBUF >> 1);
2497468Ssam         addr->css_icsr =
2507468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2517468Ssam         splx(x);
2527468Ssam 	return(1);
2537468Ssam 
2547468Ssam down:
2557468Ssam 	ui->ui_alive = 0;
2567468Ssam 	return(0);
2577468Ssam }
2587468Ssam 
2597468Ssam /*
26033452Skarels  * Drop the host ready line to mark host down.
26133452Skarels  * UNTESTED.
26233452Skarels  */
26333452Skarels cssdown(unit)
26433452Skarels 	int unit;
26533452Skarels {
26633452Skarels         register struct cssdevice *addr;
26733452Skarels 
26833452Skarels 	addr = (struct cssdevice *)(cssinfo[unit]->ui_addr);
26933452Skarels         /* reset the imp interface. */
27033452Skarels         addr->css_icsr = CSS_CLR;
27133452Skarels         addr->css_ocsr = CSS_CLR;
27233452Skarels 	DELAY(100);
27333452Skarels 	addr->css_icsr = 0;
27433452Skarels 	addr->css_ocsr = 0;
27534273Skarels 	cssoflush(unit);
27633452Skarels 	return (1);
27733452Skarels }
27833452Skarels 
27934273Skarels cssoflush(unit)
28034273Skarels 	int unit;
28134273Skarels {
282*34501Skarels 	register struct css_softc *sc = &css_softc[unit];
28334273Skarels 
284*34501Skarels 	sc->css_imp->imp_cb.ic_oactive = 0;
285*34501Skarels 	if (sc->css_ifuba.ifu_xtofree) {
286*34501Skarels 		m_freem(sc->css_ifuba.ifu_xtofree);
287*34501Skarels 		sc->css_ifuba.ifu_xtofree = 0;
28834273Skarels 	}
28934273Skarels }
29034273Skarels 
29133452Skarels /*
2927468Ssam  * Start output on an interface.
2937468Ssam  */
29433452Skarels cssoutput(unit, m)
29533452Skarels         int unit;
29633452Skarels         struct mbuf *m;
2977468Ssam {
29833452Skarels         int info;
2997468Ssam         struct uba_device *ui = cssinfo[unit];
3007468Ssam         register struct css_softc *sc = &css_softc[unit];
3017468Ssam         register struct cssdevice *addr;
3027468Ssam 
3037468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
3047468Ssam         /*
3057468Ssam          * Have request mapped to UNIBUS for transmission.
3067468Ssam          * Purge any stale data from the BDP, and start the output.
3077468Ssam          */
3087468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3097468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
3107468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3117468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
3127468Ssam         addr->css_oba = (u_short)info;
3137468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
31433452Skarels         addr->css_ocsr =
31533452Skarels 	    (u_short)(CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO);
31633452Skarels         sc->css_imp->imp_cb.ic_oactive = 1;
3177468Ssam }
3187468Ssam 
3197468Ssam /*
3207468Ssam  * Output interrupt handler.
3217468Ssam  */
3227468Ssam cssxint(unit)
3237468Ssam {
3247468Ssam         register struct uba_device *ui = cssinfo[unit];
3257468Ssam         register struct css_softc *sc = &css_softc[unit];
3267468Ssam         register struct cssdevice *addr;
3277468Ssam 
3287468Ssam         addr = (struct cssdevice *)ui->ui_addr;
32933452Skarels         if (sc->css_imp->imp_cb.ic_oactive == 0) {
3307468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3317468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3327468Ssam                 return;
3337468Ssam         }
33433452Skarels         sc->css_imp->imp_if.if_opackets++;
33533452Skarels         sc->css_imp->imp_cb.ic_oactive = 0;
3367468Ssam         if (addr->css_ocsr & CSS_ERR){
33733452Skarels                 sc->css_imp->imp_if.if_oerrors++;
3387468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3397468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3407468Ssam 			addr->css_icsr, CSS_INBITS);
3417468Ssam 	}
3427468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3437468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3447468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3457468Ssam 	}
34633452Skarels 	impstart(sc->css_imp);
3477468Ssam }
3487468Ssam 
3497468Ssam /*
3507468Ssam  * Input interrupt handler
3517468Ssam  */
3527468Ssam cssrint(unit)
3537468Ssam {
3547468Ssam         register struct css_softc *sc = &css_softc[unit];
3557468Ssam         register struct cssdevice *addr;
3567468Ssam         struct mbuf *m;
3577468Ssam         int len, info;
3587468Ssam 
35933452Skarels         sc->css_imp->imp_if.if_ipackets++;
3607468Ssam 
3617468Ssam         /*
3627468Ssam          * Purge BDP; flush message if error indicated.
3637468Ssam          */
3647468Ssam 
3657468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3667468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3677468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3687468Ssam         if (addr->css_icsr & CSS_ERR) {
3697468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3707468Ssam                     addr->css_icsr, CSS_INBITS);
37133452Skarels                 sc->css_imp->imp_if.if_ierrors++;
3727468Ssam                 sc->css_flush = 1;
3737468Ssam         }
3747468Ssam 
3757468Ssam         if (sc->css_flush) {
3767468Ssam                 if (addr->css_icsr & IN_EOM)
3777468Ssam                         sc->css_flush = 0;
3787468Ssam                 goto setup;
3797468Ssam         }
3807468Ssam 
38133452Skarels         len = IMP_RCVBUF + (addr->css_iwc << 1);
38233452Skarels 	if (len < 0 || len > IMP_RCVBUF) {
3837468Ssam 		printf("css%d: bad length=%d\n", len);
38433452Skarels 		sc->css_imp->imp_if.if_ierrors++;
3857468Ssam 		goto setup;
3867468Ssam 	}
3877468Ssam 
3887468Ssam         /*
38924800Skarels          * The offset parameter is always 0 since using
3907468Ssam          * trailers on the ARPAnet is insane.
3917468Ssam          */
39233452Skarels         m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_imp->imp_if);
3937468Ssam         if (m == 0)
3947468Ssam                 goto setup;
3957468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
3967468Ssam 		if (sc->css_iq)
3977468Ssam 			m_cat(sc->css_iq, m);
3987468Ssam 		else
3997468Ssam 			sc->css_iq = m;
4007468Ssam 		goto setup;
4017468Ssam 	}
4027468Ssam 	if (sc->css_iq) {
4037468Ssam 		m_cat(sc->css_iq, m);
4047468Ssam 		m = sc->css_iq;
4057468Ssam 		sc->css_iq = 0;
4067468Ssam         }
4077468Ssam         impinput(unit, m);
4087468Ssam 
4097468Ssam setup:
4107468Ssam         /*
4117468Ssam          * Setup for next message.
4127468Ssam          */
4137468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
4147468Ssam         addr->css_iba = (u_short)info;
41533452Skarels         addr->css_iwc = - (IMP_RCVBUF >> 1);
4167468Ssam         addr->css_icsr =
4177468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
4187468Ssam }
41925270Sbloom #endif
420