xref: /csrg-svn/sys/vax/if/if_css.c (revision 8459)
1*8459Sroot /*      if_css.c     4.3     82/10/10     */
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  */
297468Ssam 
307468Ssam #include "../h/param.h"
317468Ssam #include "../h/systm.h"
327468Ssam #include "../h/mbuf.h"
337468Ssam #include "../h/pte.h"
347468Ssam #include "../h/buf.h"
357468Ssam #include "../h/protosw.h"
367468Ssam #include "../h/socket.h"
377468Ssam #include "../h/vmmac.h"
38*8459Sroot 
397468Ssam #include "../net/if.h"
408415Swnj #include "../netimp/if_imp.h"
41*8459Sroot 
42*8459Sroot #include "../vax/cpu.h"
43*8459Sroot #include "../vax/mtpr.h"
44*8459Sroot #include "../vaxif/if_css.h"
458415Swnj #include "../vaxif/if_uba.h"
46*8459Sroot #include "../vaxuba/ubareg.h"
47*8459Sroot #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 COUNT(CSSPROBE);
957468Ssam #ifdef lint
967468Ssam         br = 0; cvec = br; br = cvec;
977468Ssam         cssrint(0); cssxint(0);
987468Ssam #endif
997468Ssam 
1007468Ssam 
1017468Ssam         addr->css_icsr = CSS_CLR;
1027468Ssam         addr->css_ocsr = CSS_CLR;
1037468Ssam         DELAY(50000);
1047468Ssam 	addr->css_icsr = 0;
1057468Ssam 	addr->css_ocsr = 0;
1067468Ssam         DELAY(50000);
1077468Ssam 
1087468Ssam 	addr->css_oba = 0;
1097468Ssam 	addr->css_owc = -1;
1107468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1117468Ssam         DELAY(50000);
1127468Ssam         addr->css_ocsr = 0;
1137468Ssam 
1147468Ssam         return (1);
1157468Ssam }
1167468Ssam 
1177468Ssam /*
1187468Ssam  * Call the IMP module to allow it to set up its internal
1197468Ssam  * state, then tie the two modules together by setting up
1207468Ssam  * the back pointers to common data structures.
1217468Ssam  */
1227468Ssam cssattach(ui)
1237468Ssam         struct uba_device *ui;
1247468Ssam {
1257468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1267468Ssam         register struct impcb *ip;
1277468Ssam         struct ifimpcb {
1287468Ssam                 struct  ifnet ifimp_if;
1297468Ssam                 struct  impcb ifimp_impcb;
1307468Ssam         } *ifimp;
1317468Ssam 
1327468Ssam COUNT(CSSATTACH);
1337468Ssam         if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
1347468Ssam                 panic("cssattach");             /* XXX */
1357468Ssam         sc->css_if = &ifimp->ifimp_if;
1367468Ssam         ip = &ifimp->ifimp_impcb;
1377468Ssam         sc->css_ic = ip;
1387468Ssam         ip->ic_init = cssinit;
1397468Ssam         ip->ic_start = cssstart;
1407468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1417468Ssam #ifdef notdef
1427468Ssam 	sc->css_ifuba.ifu_flags =| UBA_NEEDBDP;
1437468Ssam #endif
1447468Ssam }
1457468Ssam 
1467468Ssam /*
1477468Ssam  * Reset interface after UNIBUS reset.
1487468Ssam  * If interface is on specified uba, reset its state.
1497468Ssam  */
1507468Ssam cssreset(unit, uban)
1517468Ssam         int unit, uban;
1527468Ssam {
1537468Ssam         register struct uba_device *ui;
1547468Ssam         struct css_softc *sc;
1557468Ssam 
1567468Ssam COUNT(CSSCLR);
1577468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1587468Ssam             ui->ui_ubanum != uban)
1597468Ssam                 return;
1607468Ssam         printf(" css%d", unit);
1617468Ssam         sc = &css_softc[unit];
1627468Ssam         /* must go through IMP to allow it to set state */
1637468Ssam         (*sc->css_if->if_init)(unit);
1647468Ssam }
1657468Ssam 
1667468Ssam /*
1677468Ssam  * Initialize interface: clear recorded pending operations,
1687468Ssam  * and retrieve, and reinitialize UNIBUS resources.
1697468Ssam  */
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 COUNT(CSSINIT);
1797468Ssam 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
1807468Ssam 		printf("css%d: not alive\n", unit);
1817468Ssam 		return(0);
1827468Ssam 	}
1837468Ssam 	sc = &css_softc[unit];
1847468Ssam 
1857468Ssam 	/*
1867468Ssam 	 * Header length is 0 to if_ubainit since we have to pass
1877468Ssam 	 * the IMP leader up to the protocol interpretaion
1887468Ssam 	 * routines.  If we had the deader length as
1897468Ssam 	 * sizeof(struct imp_leader), then the if_ routines
1907468Ssam 	 * would assume we handle it on input and output.
1917468Ssam 	 */
1927468Ssam 
1937468Ssam         if (if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,(int)btoc(IMPMTU)) == 0) {
1947468Ssam                 printf("css%d: can't initialize\n", unit);
1957468Ssam 		ui->ui_alive = 0;
1967468Ssam 		return(0);
1977468Ssam         }
1987468Ssam         addr = (struct cssdevice *)ui->ui_addr;
1997468Ssam 
2007468Ssam         /* reset the imp interface. */
2017468Ssam         x = spl5();
2027468Ssam         addr->css_icsr = CSS_CLR;
2037468Ssam         addr->css_ocsr = CSS_CLR;
2047468Ssam 	DELAY(100);
2057468Ssam 	addr->css_icsr = 0;
2067468Ssam 	addr->css_ocsr = 0;
2077468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2087468Ssam 	DELAY(5000);
2097468Ssam         splx(x);
2107468Ssam 
2117468Ssam         /*
2127468Ssam 	 * This may hang if the imp isn't really there.
2137468Ssam 	 * Will test and verify safe operation.
2147468Ssam 	 */
2157468Ssam 
2167468Ssam 	x = 500;
2177468Ssam 	while (x-- > 0) {
2187468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2197468Ssam 			break;
2207468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2217468Ssam                 DELAY(5000);
2227468Ssam         }
2237468Ssam 
2247468Ssam 	if (x <= 0) {
2257468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2267468Ssam 			CSS_INBITS, addr->css_icsr);
2277468Ssam 		goto down;
2287468Ssam 	}
2297468Ssam 
2307468Ssam         /*
2317468Ssam          * Put up a read.  We can't restart any outstanding writes
2327468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2337468Ssam          * the NOOPs it throws at us).
2347468Ssam 	 * Note: IMPMTU includes the leader.
2357468Ssam          */
2367468Ssam 
2377468Ssam         x = spl5();
2387468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2397468Ssam         addr->css_iba = (u_short)info;
2407468Ssam         addr->css_iwc = -(IMPMTU >> 1);
2417468Ssam         addr->css_icsr =
2427468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2437468Ssam         splx(x);
2447468Ssam 	return(1);
2457468Ssam 
2467468Ssam down:
2477468Ssam 	ui->ui_alive = 0;
2487468Ssam 	return(0);
2497468Ssam }
2507468Ssam 
2517468Ssam /*
2527468Ssam  * Start output on an interface.
2537468Ssam  */
2547468Ssam cssstart(dev)
2557468Ssam         dev_t dev;
2567468Ssam {
2577468Ssam         int unit = CSSUNIT(dev), info;
2587468Ssam         struct uba_device *ui = cssinfo[unit];
2597468Ssam         register struct css_softc *sc = &css_softc[unit];
2607468Ssam         register struct cssdevice *addr;
2617468Ssam         struct mbuf *m;
2627468Ssam         u_short cmd;
2637468Ssam 
2647468Ssam COUNT(CSSSTART);
2657468Ssam         if (sc->css_ic->ic_oactive)
2667468Ssam                 goto restart;
2677468Ssam 
2687468Ssam         /*
2697468Ssam          * Not already active, deqeue a request and
2707468Ssam          * map it onto the UNIBUS.  If no more
2717468Ssam          * requeusts, just return.
2727468Ssam          */
2737468Ssam         IF_DEQUEUE(&sc->css_if->if_snd, m);
2747468Ssam         if (m == 0) {
2757468Ssam                 sc->css_ic->ic_oactive = 0;
2767468Ssam                 return;
2777468Ssam         }
2787468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
2797468Ssam 
2807468Ssam restart:
2817468Ssam         /*
2827468Ssam          * Have request mapped to UNIBUS for transmission.
2837468Ssam          * Purge any stale data from the BDP, and start the output.
2847468Ssam          */
2857468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
2867468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
2877468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2887468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
2897468Ssam         addr->css_oba = (u_short)info;
2907468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
2917468Ssam         cmd = CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO;
2927468Ssam         addr->css_ocsr = cmd;
2937468Ssam         sc->css_ic->ic_oactive = 1;
2947468Ssam }
2957468Ssam 
2967468Ssam /*
2977468Ssam  * Output interrupt handler.
2987468Ssam  */
2997468Ssam cssxint(unit)
3007468Ssam {
3017468Ssam         register struct uba_device *ui = cssinfo[unit];
3027468Ssam         register struct css_softc *sc = &css_softc[unit];
3037468Ssam         register struct cssdevice *addr;
3047468Ssam 
3057468Ssam COUNT(CSSXINT);
3067468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3077468Ssam         if (sc->css_ic->ic_oactive == 0) {
3087468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3097468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3107468Ssam                 return;
3117468Ssam         }
3127468Ssam         sc->css_if->if_opackets++;
3137468Ssam         sc->css_ic->ic_oactive = 0;
3147468Ssam         if (addr->css_ocsr & CSS_ERR){
3157468Ssam                 sc->css_if->if_oerrors++;
3167468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3177468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3187468Ssam 			addr->css_icsr, CSS_INBITS);
3197468Ssam 	}
3207468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3217468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3227468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3237468Ssam 	}
3247468Ssam 	if (sc->css_if->if_snd.ifq_head)
3257468Ssam 		cssstart(unit);
3267468Ssam }
3277468Ssam 
3287468Ssam /*
3297468Ssam  * Input interrupt handler
3307468Ssam  */
3317468Ssam cssrint(unit)
3327468Ssam {
3337468Ssam         register struct css_softc *sc = &css_softc[unit];
3347468Ssam         register struct cssdevice *addr;
3357468Ssam         register struct ifqueue *inq;
3367468Ssam         struct mbuf *m;
3377468Ssam         int len, info;
3387468Ssam 
3397468Ssam COUNT(CSSRINT);
3407468Ssam         sc->css_if->if_ipackets++;
3417468Ssam 
3427468Ssam         /*
3437468Ssam          * Purge BDP; flush message if error indicated.
3447468Ssam          */
3457468Ssam 
3467468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3477468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3487468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3497468Ssam         if (addr->css_icsr & CSS_ERR) {
3507468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3517468Ssam                     addr->css_icsr, CSS_INBITS);
3527468Ssam                 sc->css_if->if_ierrors++;
3537468Ssam                 sc->css_flush = 1;
3547468Ssam         }
3557468Ssam 
3567468Ssam         if (sc->css_flush) {
3577468Ssam                 if (addr->css_icsr & IN_EOM)
3587468Ssam                         sc->css_flush = 0;
3597468Ssam                 goto setup;
3607468Ssam         }
3617468Ssam 
3627468Ssam         len = IMPMTU + (addr->css_iwc << 1);
3637468Ssam 	if (len < 0 || len > IMPMTU) {
3647468Ssam 		printf("css%d: bad length=%d\n", len);
3657468Ssam 		sc->css_if->if_ierrors++;
3667468Ssam 		goto setup;
3677468Ssam 	}
3687468Ssam 
3697468Ssam         /*
3707468Ssam          * The last parameter is always 0 since using
3717468Ssam          * trailers on the ARPAnet is insane.
3727468Ssam          */
3737468Ssam         m = if_rubaget(&sc->css_ifuba, len, 0);
3747468Ssam         if (m == 0)
3757468Ssam                 goto setup;
3767468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
3777468Ssam 		if (sc->css_iq)
3787468Ssam 			m_cat(sc->css_iq, m);
3797468Ssam 		else
3807468Ssam 			sc->css_iq = m;
3817468Ssam 		goto setup;
3827468Ssam 	}
3837468Ssam 	if (sc->css_iq) {
3847468Ssam 		m_cat(sc->css_iq, m);
3857468Ssam 		m = sc->css_iq;
3867468Ssam 		sc->css_iq = 0;
3877468Ssam         }
3887468Ssam         impinput(unit, m);
3897468Ssam 
3907468Ssam setup:
3917468Ssam         /*
3927468Ssam          * Setup for next message.
3937468Ssam          */
3947468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
3957468Ssam         addr->css_iba = (u_short)info;
3967468Ssam         addr->css_iwc = - (IMPMTU >> 1);
3977468Ssam         addr->css_icsr =
3987468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
3997468Ssam }
400