xref: /csrg-svn/sys/vax/if/if_css.c (revision 17110)
1*17110Sbloom /*      if_css.c     6.2     84/08/29     */
27468Ssam 
37468Ssam #include "css.h"
47468Ssam 
57468Ssam /*
67468Ssam  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
77468Ssam  * Since "imp11a" is such a mouthful, it is called
87468Ssam  * "css" after the LH/DH being called "acc".
97468Ssam  *
107468Ssam  * Configuration notes:
117468Ssam  *
127468Ssam  * As delivered from DEC/CSS, it
137468Ssam  * is addressed and vectored as two DR11-B's.  This makes
147468Ssam  * Autoconfig almost IMPOSSIBLE.  To make it work, the
157468Ssam  * interrupt vectors must be restrapped to make the vectors
167468Ssam  * consecutive.  The 020 hole between the CSR addresses is
177468Ssam  * tolerated, althought that could be cleaned-up also.
187468Ssam  *
197468Ssam  * Additionally, the TRANSMIT side of the IMP11-A has the
207468Ssam  * lower address of the two subunits, so the vector ordering
217468Ssam  * in the CONFIG file is reversed from most other devices.
227468Ssam  * It should be:
237468Ssam  *
247468Ssam  * device css0 ....  cssxint cssrint
257468Ssam  *
267468Ssam  * If you get it wrong, it will still autoconfig, but will just
277468Ssam  * sit there with RECIEVE IDLE indicated on the front panel.
287468Ssam  */
299794Ssam #include "../machine/pte.h"
307468Ssam 
31*17110Sbloom #include "param.h"
32*17110Sbloom #include "systm.h"
33*17110Sbloom #include "mbuf.h"
34*17110Sbloom #include "buf.h"
35*17110Sbloom #include "protosw.h"
36*17110Sbloom #include "socket.h"
37*17110Sbloom #include "vmmac.h"
388459Sroot 
397468Ssam #include "../net/if.h"
408415Swnj #include "../netimp/if_imp.h"
418459Sroot 
428459Sroot #include "../vax/cpu.h"
438459Sroot #include "../vax/mtpr.h"
44*17110Sbloom #include "if_cssreg.h"
45*17110Sbloom #include "if_uba.h"
468459Sroot #include "../vaxuba/ubareg.h"
478459Sroot #include "../vaxuba/ubavar.h"
487468Ssam 
497468Ssam int     cssprobe(), cssattach(), cssrint(), cssxint();
507468Ssam struct  uba_device *cssinfo[NCSS];
517468Ssam u_short cssstd[] = { 0 };
527468Ssam struct  uba_driver cssdriver =
537468Ssam         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
547468Ssam #define CSSUNIT(x)      minor(x)
557468Ssam 
567468Ssam int     cssinit(), cssstart(), cssreset();
577468Ssam 
587468Ssam /*
597468Ssam  * "Lower half" of IMP interface driver.
607468Ssam  *
617468Ssam  * Each IMP interface is handled by a common module which handles
627468Ssam  * the IMP-host protocol and a hardware driver which manages the
637468Ssam  * hardware specific details of talking with the IMP.
647468Ssam  *
657468Ssam  * The hardware portion of the IMP driver handles DMA and related
667468Ssam  * management of UNIBUS resources.  The IMP protocol module interprets
677468Ssam  * contents of these messages and "controls" the actions of the
687468Ssam  * hardware module during IMP resets, but not, for instance, during
697468Ssam  * UNIBUS resets.
707468Ssam  *
717468Ssam  * The two modules are coupled at "attach time", and ever after,
727468Ssam  * through the imp interface structure.  Higher level protocols,
737468Ssam  * e.g. IP, interact with the IMP driver, rather than the CSS.
747468Ssam  */
757468Ssam struct  css_softc {
767468Ssam         struct  ifnet *css_if;          /* pointer to IMP's ifnet struct */
777468Ssam         struct  impcb *css_ic;          /* data structure shared with IMP */
787468Ssam         struct  ifuba css_ifuba;        /* UNIBUS resources */
797468Ssam         struct  mbuf *css_iq;           /* input reassembly queue */
807468Ssam         short   css_olen;               /* size of last message sent */
817468Ssam         char    css_flush;              /* flush remainder of message */
827468Ssam } css_softc[NCSS];
837468Ssam 
847468Ssam /*
857468Ssam  * Reset the IMP and cause a transmitter interrupt by
867468Ssam  * performing a null DMA.
877468Ssam  */
887468Ssam cssprobe(reg)
897468Ssam         caddr_t reg;
907468Ssam {
917468Ssam         register int br, cvec;          /* r11, r10 value-result */
927468Ssam         register struct cssdevice *addr = (struct cssdevice *)reg;
937468Ssam 
947468Ssam #ifdef lint
957468Ssam         br = 0; cvec = br; br = cvec;
967468Ssam         cssrint(0); cssxint(0);
977468Ssam #endif
987468Ssam 
997468Ssam 
1007468Ssam         addr->css_icsr = CSS_CLR;
1017468Ssam         addr->css_ocsr = CSS_CLR;
1027468Ssam         DELAY(50000);
1037468Ssam 	addr->css_icsr = 0;
1047468Ssam 	addr->css_ocsr = 0;
1057468Ssam         DELAY(50000);
1067468Ssam 
1077468Ssam 	addr->css_oba = 0;
1087468Ssam 	addr->css_owc = -1;
1097468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1107468Ssam         DELAY(50000);
1117468Ssam         addr->css_ocsr = 0;
1127468Ssam 
1137468Ssam         return (1);
1147468Ssam }
1157468Ssam 
1167468Ssam /*
1177468Ssam  * Call the IMP module to allow it to set up its internal
1187468Ssam  * state, then tie the two modules together by setting up
1197468Ssam  * the back pointers to common data structures.
1207468Ssam  */
1217468Ssam cssattach(ui)
1227468Ssam         struct uba_device *ui;
1237468Ssam {
1247468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1257468Ssam         register struct impcb *ip;
1267468Ssam         struct ifimpcb {
1277468Ssam                 struct  ifnet ifimp_if;
1287468Ssam                 struct  impcb ifimp_impcb;
1297468Ssam         } *ifimp;
1307468Ssam 
1318831Sroot         if ((ifimp = (struct ifimpcb *)impattach(ui, cssreset)) == 0)
1327468Ssam                 panic("cssattach");             /* XXX */
1337468Ssam         sc->css_if = &ifimp->ifimp_if;
1347468Ssam         ip = &ifimp->ifimp_impcb;
1357468Ssam         sc->css_ic = ip;
1367468Ssam         ip->ic_init = cssinit;
1377468Ssam         ip->ic_start = cssstart;
1387468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1397468Ssam #ifdef notdef
1407468Ssam 	sc->css_ifuba.ifu_flags =| UBA_NEEDBDP;
1417468Ssam #endif
1427468Ssam }
1437468Ssam 
1447468Ssam /*
1457468Ssam  * Reset interface after UNIBUS reset.
1467468Ssam  * If interface is on specified uba, reset its state.
1477468Ssam  */
1487468Ssam cssreset(unit, uban)
1497468Ssam         int unit, uban;
1507468Ssam {
1517468Ssam         register struct uba_device *ui;
1527468Ssam         struct css_softc *sc;
1537468Ssam 
1547468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1557468Ssam             ui->ui_ubanum != uban)
1567468Ssam                 return;
1577468Ssam         printf(" css%d", unit);
1587468Ssam         sc = &css_softc[unit];
1597468Ssam         /* must go through IMP to allow it to set state */
1607468Ssam         (*sc->css_if->if_init)(unit);
1617468Ssam }
1627468Ssam 
1637468Ssam /*
1647468Ssam  * Initialize interface: clear recorded pending operations,
1657468Ssam  * and retrieve, and reinitialize UNIBUS resources.
1667468Ssam  */
1677468Ssam cssinit(unit)
1687468Ssam         int unit;
1697468Ssam {
1707468Ssam         register struct css_softc *sc;
1717468Ssam         register struct uba_device *ui;
1727468Ssam         register struct cssdevice *addr;
1737468Ssam         int x, info;
1747468Ssam 
1757468Ssam 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
1767468Ssam 		printf("css%d: not alive\n", unit);
1777468Ssam 		return(0);
1787468Ssam 	}
1797468Ssam 	sc = &css_softc[unit];
1807468Ssam 
1817468Ssam 	/*
1827468Ssam 	 * Header length is 0 to if_ubainit since we have to pass
1837468Ssam 	 * the IMP leader up to the protocol interpretaion
1847468Ssam 	 * routines.  If we had the deader length as
1857468Ssam 	 * sizeof(struct imp_leader), then the if_ routines
1867468Ssam 	 * would assume we handle it on input and output.
1877468Ssam 	 */
1887468Ssam 
1897468Ssam         if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) {
1907468Ssam                 printf("css%d: can't initialize\n", unit);
1917468Ssam 		ui->ui_alive = 0;
1927468Ssam 		return(0);
1937468Ssam         }
1947468Ssam         addr = (struct cssdevice *)ui->ui_addr;
1957468Ssam 
1967468Ssam         /* reset the imp interface. */
1977468Ssam         x = spl5();
1987468Ssam         addr->css_icsr = CSS_CLR;
1997468Ssam         addr->css_ocsr = CSS_CLR;
2007468Ssam 	DELAY(100);
2017468Ssam 	addr->css_icsr = 0;
2027468Ssam 	addr->css_ocsr = 0;
2037468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2047468Ssam 	DELAY(5000);
2057468Ssam         splx(x);
2067468Ssam 
2077468Ssam         /*
2087468Ssam 	 * This may hang if the imp isn't really there.
2097468Ssam 	 * Will test and verify safe operation.
2107468Ssam 	 */
2117468Ssam 
2127468Ssam 	x = 500;
2137468Ssam 	while (x-- > 0) {
2147468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2157468Ssam 			break;
2167468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2177468Ssam                 DELAY(5000);
2187468Ssam         }
2197468Ssam 
2207468Ssam 	if (x <= 0) {
2217468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2227468Ssam 			CSS_INBITS, addr->css_icsr);
2237468Ssam 		goto down;
2247468Ssam 	}
2257468Ssam 
2267468Ssam         /*
2277468Ssam          * Put up a read.  We can't restart any outstanding writes
2287468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2297468Ssam          * the NOOPs it throws at us).
2307468Ssam 	 * Note: IMPMTU includes the leader.
2317468Ssam          */
2327468Ssam 
2337468Ssam         x = spl5();
2347468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2357468Ssam         addr->css_iba = (u_short)info;
2367468Ssam         addr->css_iwc = -(IMPMTU >> 1);
2377468Ssam         addr->css_icsr =
2387468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2397468Ssam         splx(x);
2407468Ssam 	return(1);
2417468Ssam 
2427468Ssam down:
2437468Ssam 	ui->ui_alive = 0;
2447468Ssam 	return(0);
2457468Ssam }
2467468Ssam 
2477468Ssam /*
2487468Ssam  * Start output on an interface.
2497468Ssam  */
2507468Ssam cssstart(dev)
2517468Ssam         dev_t dev;
2527468Ssam {
2537468Ssam         int unit = CSSUNIT(dev), info;
2547468Ssam         struct uba_device *ui = cssinfo[unit];
2557468Ssam         register struct css_softc *sc = &css_softc[unit];
2567468Ssam         register struct cssdevice *addr;
2577468Ssam         struct mbuf *m;
2587468Ssam         u_short cmd;
2597468Ssam 
2607468Ssam         if (sc->css_ic->ic_oactive)
2617468Ssam                 goto restart;
2627468Ssam 
2637468Ssam         /*
2647468Ssam          * Not already active, deqeue a request and
2657468Ssam          * map it onto the UNIBUS.  If no more
2667468Ssam          * requeusts, just return.
2677468Ssam          */
2687468Ssam         IF_DEQUEUE(&sc->css_if->if_snd, m);
2697468Ssam         if (m == 0) {
2707468Ssam                 sc->css_ic->ic_oactive = 0;
2717468Ssam                 return;
2727468Ssam         }
2737468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
2747468Ssam 
2757468Ssam restart:
2767468Ssam         /*
2777468Ssam          * Have request mapped to UNIBUS for transmission.
2787468Ssam          * Purge any stale data from the BDP, and start the output.
2797468Ssam          */
2807468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
2817468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
2827468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2837468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
2847468Ssam         addr->css_oba = (u_short)info;
2857468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
2867468Ssam         cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO;
2877468Ssam         addr->css_ocsr = cmd;
2887468Ssam         sc->css_ic->ic_oactive = 1;
2897468Ssam }
2907468Ssam 
2917468Ssam /*
2927468Ssam  * Output interrupt handler.
2937468Ssam  */
2947468Ssam cssxint(unit)
2957468Ssam {
2967468Ssam         register struct uba_device *ui = cssinfo[unit];
2977468Ssam         register struct css_softc *sc = &css_softc[unit];
2987468Ssam         register struct cssdevice *addr;
2997468Ssam 
3007468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3017468Ssam         if (sc->css_ic->ic_oactive == 0) {
3027468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3037468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3047468Ssam                 return;
3057468Ssam         }
3067468Ssam         sc->css_if->if_opackets++;
3077468Ssam         sc->css_ic->ic_oactive = 0;
3087468Ssam         if (addr->css_ocsr & CSS_ERR){
3097468Ssam                 sc->css_if->if_oerrors++;
3107468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3117468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3127468Ssam 			addr->css_icsr, CSS_INBITS);
3137468Ssam 	}
3147468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3157468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3167468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3177468Ssam 	}
3187468Ssam 	if (sc->css_if->if_snd.ifq_head)
3197468Ssam 		cssstart(unit);
3207468Ssam }
3217468Ssam 
3227468Ssam /*
3237468Ssam  * Input interrupt handler
3247468Ssam  */
3257468Ssam cssrint(unit)
3267468Ssam {
3277468Ssam         register struct css_softc *sc = &css_softc[unit];
3287468Ssam         register struct cssdevice *addr;
3297468Ssam         struct mbuf *m;
3307468Ssam         int len, info;
3317468Ssam 
3327468Ssam         sc->css_if->if_ipackets++;
3337468Ssam 
3347468Ssam         /*
3357468Ssam          * Purge BDP; flush message if error indicated.
3367468Ssam          */
3377468Ssam 
3387468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3397468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3407468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3417468Ssam         if (addr->css_icsr & CSS_ERR) {
3427468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3437468Ssam                     addr->css_icsr, CSS_INBITS);
3447468Ssam                 sc->css_if->if_ierrors++;
3457468Ssam                 sc->css_flush = 1;
3467468Ssam         }
3477468Ssam 
3487468Ssam         if (sc->css_flush) {
3497468Ssam                 if (addr->css_icsr & IN_EOM)
3507468Ssam                         sc->css_flush = 0;
3517468Ssam                 goto setup;
3527468Ssam         }
3537468Ssam 
3547468Ssam         len = IMPMTU + (addr->css_iwc << 1);
3557468Ssam 	if (len < 0 || len > IMPMTU) {
3567468Ssam 		printf("css%d: bad length=%d\n", len);
3577468Ssam 		sc->css_if->if_ierrors++;
3587468Ssam 		goto setup;
3597468Ssam 	}
3607468Ssam 
3617468Ssam         /*
3627468Ssam          * The last parameter is always 0 since using
3637468Ssam          * trailers on the ARPAnet is insane.
3647468Ssam          */
3657468Ssam         m = if_rubaget(&sc->css_ifuba, len, 0);
3667468Ssam         if (m == 0)
3677468Ssam                 goto setup;
3687468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
3697468Ssam 		if (sc->css_iq)
3707468Ssam 			m_cat(sc->css_iq, m);
3717468Ssam 		else
3727468Ssam 			sc->css_iq = m;
3737468Ssam 		goto setup;
3747468Ssam 	}
3757468Ssam 	if (sc->css_iq) {
3767468Ssam 		m_cat(sc->css_iq, m);
3777468Ssam 		m = sc->css_iq;
3787468Ssam 		sc->css_iq = 0;
3797468Ssam         }
3807468Ssam         impinput(unit, m);
3817468Ssam 
3827468Ssam setup:
3837468Ssam         /*
3847468Ssam          * Setup for next message.
3857468Ssam          */
3867468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
3877468Ssam         addr->css_iba = (u_short)info;
3887468Ssam         addr->css_iwc = - (IMPMTU >> 1);
3897468Ssam         addr->css_icsr =
3907468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
3917468Ssam }
392