xref: /csrg-svn/sys/vax/if/if_css.c (revision 32775)
123283Smckusick /*
229357Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
323283Smckusick  * All rights reserved.  The Berkeley software License Agreement
423283Smckusick  * specifies the terms and conditions for redistribution.
523283Smckusick  *
6*32775Sbostic  *	@(#)if_css.c	7.2 (Berkeley) 12/05/87
723283Smckusick  */
87468Ssam 
97468Ssam #include "css.h"
1025270Sbloom #if NCSS > 0
117468Ssam 
127468Ssam /*
137468Ssam  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
147468Ssam  * Since "imp11a" is such a mouthful, it is called
157468Ssam  * "css" after the LH/DH being called "acc".
167468Ssam  *
177468Ssam  * Configuration notes:
187468Ssam  *
197468Ssam  * As delivered from DEC/CSS, it
207468Ssam  * is addressed and vectored as two DR11-B's.  This makes
217468Ssam  * Autoconfig almost IMPOSSIBLE.  To make it work, the
227468Ssam  * interrupt vectors must be restrapped to make the vectors
237468Ssam  * consecutive.  The 020 hole between the CSR addresses is
247468Ssam  * tolerated, althought that could be cleaned-up also.
257468Ssam  *
267468Ssam  * Additionally, the TRANSMIT side of the IMP11-A has the
277468Ssam  * lower address of the two subunits, so the vector ordering
287468Ssam  * in the CONFIG file is reversed from most other devices.
297468Ssam  * It should be:
307468Ssam  *
317468Ssam  * device css0 ....  cssxint cssrint
327468Ssam  *
337468Ssam  * If you get it wrong, it will still autoconfig, but will just
3424800Skarels  * sit there with RECEIVE IDLE indicated on the front panel.
357468Ssam  */
369794Ssam #include "../machine/pte.h"
377468Ssam 
3817110Sbloom #include "param.h"
3917110Sbloom #include "systm.h"
4017110Sbloom #include "mbuf.h"
4117110Sbloom #include "buf.h"
4217110Sbloom #include "protosw.h"
4317110Sbloom #include "socket.h"
4417110Sbloom #include "vmmac.h"
458459Sroot 
467468Ssam #include "../net/if.h"
478415Swnj #include "../netimp/if_imp.h"
488459Sroot 
498459Sroot #include "../vax/cpu.h"
508459Sroot #include "../vax/mtpr.h"
5117110Sbloom #include "if_cssreg.h"
5217110Sbloom #include "if_uba.h"
538459Sroot #include "../vaxuba/ubareg.h"
548459Sroot #include "../vaxuba/ubavar.h"
557468Ssam 
567468Ssam int     cssprobe(), cssattach(), cssrint(), cssxint();
577468Ssam struct  uba_device *cssinfo[NCSS];
587468Ssam u_short cssstd[] = { 0 };
597468Ssam struct  uba_driver cssdriver =
607468Ssam         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
617468Ssam #define CSSUNIT(x)      minor(x)
627468Ssam 
637468Ssam int     cssinit(), cssstart(), 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 {
837468Ssam         struct  ifnet *css_if;          /* pointer to IMP's ifnet struct */
847468Ssam         struct  impcb *css_ic;          /* data structure shared with IMP */
857468Ssam         struct  ifuba css_ifuba;        /* UNIBUS resources */
867468Ssam         struct  mbuf *css_iq;           /* input reassembly queue */
877468Ssam         short   css_olen;               /* size of last message sent */
887468Ssam         char    css_flush;              /* flush remainder of message */
897468Ssam } css_softc[NCSS];
907468Ssam 
917468Ssam /*
927468Ssam  * Reset the IMP and cause a transmitter interrupt by
937468Ssam  * performing a null DMA.
947468Ssam  */
957468Ssam cssprobe(reg)
967468Ssam         caddr_t reg;
977468Ssam {
987468Ssam         register int br, cvec;          /* r11, r10 value-result */
997468Ssam         register struct cssdevice *addr = (struct cssdevice *)reg;
1007468Ssam 
1017468Ssam #ifdef lint
1027468Ssam         br = 0; cvec = br; br = cvec;
1037468Ssam         cssrint(0); cssxint(0);
1047468Ssam #endif
1057468Ssam 
1067468Ssam 
1077468Ssam         addr->css_icsr = CSS_CLR;
1087468Ssam         addr->css_ocsr = CSS_CLR;
1097468Ssam         DELAY(50000);
1107468Ssam 	addr->css_icsr = 0;
1117468Ssam 	addr->css_ocsr = 0;
1127468Ssam         DELAY(50000);
1137468Ssam 
1147468Ssam 	addr->css_oba = 0;
1157468Ssam 	addr->css_owc = -1;
1167468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1177468Ssam         DELAY(50000);
1187468Ssam         addr->css_ocsr = 0;
1197468Ssam 
1207468Ssam         return (1);
1217468Ssam }
1227468Ssam 
1237468Ssam /*
1247468Ssam  * Call the IMP module to allow it to set up its internal
1257468Ssam  * state, then tie the two modules together by setting up
1267468Ssam  * the back pointers to common data structures.
1277468Ssam  */
1287468Ssam cssattach(ui)
1297468Ssam         struct uba_device *ui;
1307468Ssam {
1317468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1327468Ssam         register struct impcb *ip;
1337468Ssam         struct ifimpcb {
1347468Ssam                 struct  ifnet ifimp_if;
1357468Ssam                 struct  impcb ifimp_impcb;
1367468Ssam         } *ifimp;
1377468Ssam 
1388831Sroot         if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0)
13924800Skarels                 return;
1407468Ssam         sc->css_if = &ifimp->ifimp_if;
1417468Ssam         ip = &ifimp->ifimp_impcb;
1427468Ssam         sc->css_ic = ip;
1437468Ssam         ip->ic_init = cssinit;
1447468Ssam         ip->ic_start = cssstart;
1457468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1467468Ssam #ifdef notdef
147*32775Sbostic 	sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
1487468Ssam #endif
1497468Ssam }
1507468Ssam 
1517468Ssam /*
1527468Ssam  * Reset interface after UNIBUS reset.
1537468Ssam  * If interface is on specified uba, reset its state.
1547468Ssam  */
1557468Ssam cssreset(unit, uban)
1567468Ssam         int unit, uban;
1577468Ssam {
1587468Ssam         register struct uba_device *ui;
1597468Ssam         struct css_softc *sc;
1607468Ssam 
1617468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1627468Ssam             ui->ui_ubanum != uban)
1637468Ssam                 return;
1647468Ssam         printf(" css%d", unit);
1657468Ssam         sc = &css_softc[unit];
16621778Skarels 	sc->css_if->if_flags &= ~IFF_RUNNING;
1677468Ssam         /* must go through IMP to allow it to set state */
1687468Ssam         (*sc->css_if->if_init)(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 
1977468Ssam         if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) {
1987468Ssam                 printf("css%d: can't initialize\n", unit);
1997468Ssam 		ui->ui_alive = 0;
20024800Skarels 		sc->css_if->if_flags &= ~(IFF_UP | IFF_RUNNING);
2017468Ssam 		return(0);
2027468Ssam         }
20321778Skarels 	sc->css_if->if_flags |= IFF_RUNNING;
2047468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2057468Ssam 
2067468Ssam         /* reset the imp interface. */
2077468Ssam         x = spl5();
2087468Ssam         addr->css_icsr = CSS_CLR;
2097468Ssam         addr->css_ocsr = CSS_CLR;
2107468Ssam 	DELAY(100);
2117468Ssam 	addr->css_icsr = 0;
2127468Ssam 	addr->css_ocsr = 0;
2137468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2147468Ssam 	DELAY(5000);
2157468Ssam         splx(x);
2167468Ssam 
2177468Ssam         /*
2187468Ssam 	 * This may hang if the imp isn't really there.
2197468Ssam 	 * Will test and verify safe operation.
2207468Ssam 	 */
2217468Ssam 
2227468Ssam 	x = 500;
2237468Ssam 	while (x-- > 0) {
2247468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2257468Ssam 			break;
2267468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2277468Ssam                 DELAY(5000);
2287468Ssam         }
2297468Ssam 
2307468Ssam 	if (x <= 0) {
2317468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2327468Ssam 			CSS_INBITS, addr->css_icsr);
2337468Ssam 		goto down;
2347468Ssam 	}
2357468Ssam 
2367468Ssam         /*
2377468Ssam          * Put up a read.  We can't restart any outstanding writes
2387468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2397468Ssam          * the NOOPs it throws at us).
2407468Ssam 	 * Note: IMPMTU includes the leader.
2417468Ssam          */
2427468Ssam 
2437468Ssam         x = spl5();
2447468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2457468Ssam         addr->css_iba = (u_short)info;
2467468Ssam         addr->css_iwc = -(IMPMTU >> 1);
2477468Ssam         addr->css_icsr =
2487468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2497468Ssam         splx(x);
2507468Ssam 	return(1);
2517468Ssam 
2527468Ssam down:
2537468Ssam 	ui->ui_alive = 0;
2547468Ssam 	return(0);
2557468Ssam }
2567468Ssam 
2577468Ssam /*
2587468Ssam  * Start output on an interface.
2597468Ssam  */
2607468Ssam cssstart(dev)
2617468Ssam         dev_t dev;
2627468Ssam {
2637468Ssam         int unit = CSSUNIT(dev), info;
2647468Ssam         struct uba_device *ui = cssinfo[unit];
2657468Ssam         register struct css_softc *sc = &css_softc[unit];
2667468Ssam         register struct cssdevice *addr;
2677468Ssam         struct mbuf *m;
2687468Ssam         u_short cmd;
2697468Ssam 
2707468Ssam         if (sc->css_ic->ic_oactive)
2717468Ssam                 goto restart;
2727468Ssam 
2737468Ssam         /*
2747468Ssam          * Not already active, deqeue a request and
2757468Ssam          * map it onto the UNIBUS.  If no more
2767468Ssam          * requeusts, just return.
2777468Ssam          */
2787468Ssam         IF_DEQUEUE(&sc->css_if->if_snd, m);
2797468Ssam         if (m == 0) {
2807468Ssam                 sc->css_ic->ic_oactive = 0;
2817468Ssam                 return;
2827468Ssam         }
2837468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
2847468Ssam 
2857468Ssam restart:
2867468Ssam         /*
2877468Ssam          * Have request mapped to UNIBUS for transmission.
2887468Ssam          * Purge any stale data from the BDP, and start the output.
2897468Ssam          */
2907468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
2917468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
2927468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2937468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
2947468Ssam         addr->css_oba = (u_short)info;
2957468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
2967468Ssam         cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO;
2977468Ssam         addr->css_ocsr = cmd;
2987468Ssam         sc->css_ic->ic_oactive = 1;
2997468Ssam }
3007468Ssam 
3017468Ssam /*
3027468Ssam  * Output interrupt handler.
3037468Ssam  */
3047468Ssam cssxint(unit)
3057468Ssam {
3067468Ssam         register struct uba_device *ui = cssinfo[unit];
3077468Ssam         register struct css_softc *sc = &css_softc[unit];
3087468Ssam         register struct cssdevice *addr;
3097468Ssam 
3107468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3117468Ssam         if (sc->css_ic->ic_oactive == 0) {
3127468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3137468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3147468Ssam                 return;
3157468Ssam         }
3167468Ssam         sc->css_if->if_opackets++;
3177468Ssam         sc->css_ic->ic_oactive = 0;
3187468Ssam         if (addr->css_ocsr & CSS_ERR){
3197468Ssam                 sc->css_if->if_oerrors++;
3207468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3217468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3227468Ssam 			addr->css_icsr, CSS_INBITS);
3237468Ssam 	}
3247468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3257468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3267468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3277468Ssam 	}
3287468Ssam 	if (sc->css_if->if_snd.ifq_head)
3297468Ssam 		cssstart(unit);
3307468Ssam }
3317468Ssam 
3327468Ssam /*
3337468Ssam  * Input interrupt handler
3347468Ssam  */
3357468Ssam cssrint(unit)
3367468Ssam {
3377468Ssam         register struct css_softc *sc = &css_softc[unit];
3387468Ssam         register struct cssdevice *addr;
3397468Ssam         struct mbuf *m;
3407468Ssam         int len, info;
3417468Ssam 
3427468Ssam         sc->css_if->if_ipackets++;
3437468Ssam 
3447468Ssam         /*
3457468Ssam          * Purge BDP; flush message if error indicated.
3467468Ssam          */
3477468Ssam 
3487468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3497468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3507468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3517468Ssam         if (addr->css_icsr & CSS_ERR) {
3527468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3537468Ssam                     addr->css_icsr, CSS_INBITS);
3547468Ssam                 sc->css_if->if_ierrors++;
3557468Ssam                 sc->css_flush = 1;
3567468Ssam         }
3577468Ssam 
3587468Ssam         if (sc->css_flush) {
3597468Ssam                 if (addr->css_icsr & IN_EOM)
3607468Ssam                         sc->css_flush = 0;
3617468Ssam                 goto setup;
3627468Ssam         }
3637468Ssam 
3647468Ssam         len = IMPMTU + (addr->css_iwc << 1);
3657468Ssam 	if (len < 0 || len > IMPMTU) {
3667468Ssam 		printf("css%d: bad length=%d\n", len);
3677468Ssam 		sc->css_if->if_ierrors++;
3687468Ssam 		goto setup;
3697468Ssam 	}
3707468Ssam 
3717468Ssam         /*
37224800Skarels          * The offset parameter is always 0 since using
3737468Ssam          * trailers on the ARPAnet is insane.
3747468Ssam          */
37525457Skarels         m = if_rubaget(&sc->css_ifuba, len, 0, sc->css_if);
3767468Ssam         if (m == 0)
3777468Ssam                 goto setup;
3787468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
3797468Ssam 		if (sc->css_iq)
3807468Ssam 			m_cat(sc->css_iq, m);
3817468Ssam 		else
3827468Ssam 			sc->css_iq = m;
3837468Ssam 		goto setup;
3847468Ssam 	}
3857468Ssam 	if (sc->css_iq) {
3867468Ssam 		m_cat(sc->css_iq, m);
3877468Ssam 		m = sc->css_iq;
3887468Ssam 		sc->css_iq = 0;
3897468Ssam         }
3907468Ssam         impinput(unit, m);
3917468Ssam 
3927468Ssam setup:
3937468Ssam         /*
3947468Ssam          * Setup for next message.
3957468Ssam          */
3967468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
3977468Ssam         addr->css_iba = (u_short)info;
3987468Ssam         addr->css_iwc = - (IMPMTU >> 1);
3997468Ssam         addr->css_icsr =
4007468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
4017468Ssam }
40225270Sbloom #endif
403