xref: /csrg-svn/sys/vax/if/if_css.c (revision 34868)
123283Smckusick /*
2*34868Sbostic  * 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
6*34868Sbostic  * provided that the above copyright notice and this paragraph are
7*34868Sbostic  * duplicated in all such forms and that any documentation,
8*34868Sbostic  * advertising materials, and other materials related to such
9*34868Sbostic  * distribution and use acknowledge that the software was developed
10*34868Sbostic  * by the University of California, Berkeley.  The name of the
11*34868Sbostic  * University may not be used to endorse or promote products derived
12*34868Sbostic  * from this software without specific prior written permission.
13*34868Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34868Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34868Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633452Skarels  *
17*34868Sbostic  *	@(#)if_css.c	7.6 (Berkeley) 06/29/88
1823283Smckusick  */
197468Ssam 
207468Ssam #include "css.h"
2125270Sbloom #if NCSS > 0
227468Ssam 
237468Ssam /*
247468Ssam  * DEC/CSS IMP11-A ARPAnet IMP interface driver.
257468Ssam  * Since "imp11a" is such a mouthful, it is called
267468Ssam  * "css" after the LH/DH being called "acc".
277468Ssam  *
287468Ssam  * Configuration notes:
297468Ssam  *
307468Ssam  * As delivered from DEC/CSS, it
317468Ssam  * is addressed and vectored as two DR11-B's.  This makes
327468Ssam  * Autoconfig almost IMPOSSIBLE.  To make it work, the
337468Ssam  * interrupt vectors must be restrapped to make the vectors
347468Ssam  * consecutive.  The 020 hole between the CSR addresses is
357468Ssam  * tolerated, althought that could be cleaned-up also.
367468Ssam  *
377468Ssam  * Additionally, the TRANSMIT side of the IMP11-A has the
387468Ssam  * lower address of the two subunits, so the vector ordering
397468Ssam  * in the CONFIG file is reversed from most other devices.
407468Ssam  * It should be:
417468Ssam  *
427468Ssam  * device css0 ....  cssxint cssrint
437468Ssam  *
447468Ssam  * If you get it wrong, it will still autoconfig, but will just
4524800Skarels  * sit there with RECEIVE IDLE indicated on the front panel.
467468Ssam  */
4717110Sbloom #include "param.h"
4817110Sbloom #include "systm.h"
4917110Sbloom #include "mbuf.h"
5017110Sbloom #include "buf.h"
5117110Sbloom #include "protosw.h"
5217110Sbloom #include "socket.h"
5317110Sbloom #include "vmmac.h"
548459Sroot 
5533452Skarels #include "../machine/pte.h"
5633452Skarels 
577468Ssam #include "../net/if.h"
588415Swnj #include "../netimp/if_imp.h"
598459Sroot 
608459Sroot #include "../vax/cpu.h"
618459Sroot #include "../vax/mtpr.h"
6217110Sbloom #include "if_cssreg.h"
6317110Sbloom #include "if_uba.h"
648459Sroot #include "../vaxuba/ubareg.h"
658459Sroot #include "../vaxuba/ubavar.h"
667468Ssam 
677468Ssam int     cssprobe(), cssattach(), cssrint(), cssxint();
687468Ssam struct  uba_device *cssinfo[NCSS];
697468Ssam u_short cssstd[] = { 0 };
707468Ssam struct  uba_driver cssdriver =
717468Ssam         { cssprobe, 0, cssattach, 0, cssstd, "css", cssinfo };
727468Ssam 
7333452Skarels int     cssinit(), cssoutput(), cssdown(), cssreset();
747468Ssam 
757468Ssam /*
767468Ssam  * "Lower half" of IMP interface driver.
777468Ssam  *
787468Ssam  * Each IMP interface is handled by a common module which handles
797468Ssam  * the IMP-host protocol and a hardware driver which manages the
807468Ssam  * hardware specific details of talking with the IMP.
817468Ssam  *
827468Ssam  * The hardware portion of the IMP driver handles DMA and related
837468Ssam  * management of UNIBUS resources.  The IMP protocol module interprets
847468Ssam  * contents of these messages and "controls" the actions of the
857468Ssam  * hardware module during IMP resets, but not, for instance, during
867468Ssam  * UNIBUS resets.
877468Ssam  *
887468Ssam  * The two modules are coupled at "attach time", and ever after,
897468Ssam  * through the imp interface structure.  Higher level protocols,
907468Ssam  * e.g. IP, interact with the IMP driver, rather than the CSS.
917468Ssam  */
927468Ssam struct  css_softc {
9333452Skarels 	struct	imp_softc *css_imp;	/* pointer to IMP's imp_softc struct */
9433452Skarels 	struct	ifuba css_ifuba;	/* UNIBUS resources */
9533452Skarels 	struct	mbuf *css_iq;		/* input reassembly queue */
9633452Skarels 	short	css_olen;		/* size of last message sent */
9733452Skarels 	char	css_flush;		/* flush remainder of message */
987468Ssam } css_softc[NCSS];
997468Ssam 
1007468Ssam /*
1017468Ssam  * Reset the IMP and cause a transmitter interrupt by
1027468Ssam  * performing a null DMA.
1037468Ssam  */
1047468Ssam cssprobe(reg)
1057468Ssam         caddr_t reg;
1067468Ssam {
1077468Ssam         register int br, cvec;          /* r11, r10 value-result */
1087468Ssam         register struct cssdevice *addr = (struct cssdevice *)reg;
1097468Ssam 
1107468Ssam #ifdef lint
1117468Ssam         br = 0; cvec = br; br = cvec;
1127468Ssam         cssrint(0); cssxint(0);
1137468Ssam #endif
1147468Ssam 
1157468Ssam         addr->css_icsr = CSS_CLR;
1167468Ssam         addr->css_ocsr = CSS_CLR;
1177468Ssam         DELAY(50000);
1187468Ssam 	addr->css_icsr = 0;
1197468Ssam 	addr->css_ocsr = 0;
1207468Ssam         DELAY(50000);
1217468Ssam 
1227468Ssam 	addr->css_oba = 0;
1237468Ssam 	addr->css_owc = -1;
1247468Ssam         addr->css_ocsr = CSS_IE | CSS_GO;	/* enable interrupts */
1257468Ssam         DELAY(50000);
1267468Ssam         addr->css_ocsr = 0;
1277468Ssam 
1287468Ssam         return (1);
1297468Ssam }
1307468Ssam 
1317468Ssam /*
1327468Ssam  * Call the IMP module to allow it to set up its internal
1337468Ssam  * state, then tie the two modules together by setting up
1347468Ssam  * the back pointers to common data structures.
1357468Ssam  */
1367468Ssam cssattach(ui)
13734273Skarels         register struct uba_device *ui;
1387468Ssam {
1397468Ssam         register struct css_softc *sc = &css_softc[ui->ui_unit];
1407468Ssam         register struct impcb *ip;
1417468Ssam 
14234273Skarels         if ((sc->css_imp = impattach(ui->ui_driver->ud_dname, ui->ui_unit,
14334273Skarels 	    cssreset)) == 0)
14424800Skarels                 return;
14533452Skarels 	ip = &sc->css_imp->imp_cb;
1467468Ssam         ip->ic_init = cssinit;
14733452Skarels         ip->ic_output = cssoutput;
14833452Skarels         ip->ic_down = cssdown;
1497468Ssam 	sc->css_ifuba.ifu_flags = UBA_CANTWAIT | UBA_NEED16;
1507468Ssam #ifdef notdef
15132775Sbostic 	sc->css_ifuba.ifu_flags |= UBA_NEEDBDP;
1527468Ssam #endif
1537468Ssam }
1547468Ssam 
1557468Ssam /*
1567468Ssam  * Reset interface after UNIBUS reset.
1577468Ssam  * If interface is on specified uba, reset its state.
1587468Ssam  */
1597468Ssam cssreset(unit, uban)
1607468Ssam         int unit, uban;
1617468Ssam {
1627468Ssam         register struct uba_device *ui;
16333452Skarels         register struct css_softc *sc;
1647468Ssam 
1657468Ssam         if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0 ||
1667468Ssam             ui->ui_ubanum != uban)
1677468Ssam                 return;
1687468Ssam         printf(" css%d", unit);
1697468Ssam         sc = &css_softc[unit];
17033452Skarels 	sc->css_imp->imp_if.if_flags &= ~IFF_RUNNING;
17134273Skarels 	cssoflush(unit);
1727468Ssam         /* must go through IMP to allow it to set state */
17333452Skarels         (*sc->css_imp->imp_if.if_init)(sc->css_imp->imp_if.if_unit);
1747468Ssam }
1757468Ssam 
1767468Ssam /*
1777468Ssam  * Initialize interface: clear recorded pending operations,
1787468Ssam  * and retrieve, and reinitialize UNIBUS resources.
1797468Ssam  */
1807468Ssam cssinit(unit)
1817468Ssam         int unit;
1827468Ssam {
1837468Ssam         register struct css_softc *sc;
1847468Ssam         register struct uba_device *ui;
1857468Ssam         register struct cssdevice *addr;
1867468Ssam         int x, info;
1877468Ssam 
1887468Ssam 	if (unit >= NCSS || (ui = cssinfo[unit]) == 0 || ui->ui_alive == 0) {
1897468Ssam 		printf("css%d: not alive\n", unit);
1907468Ssam 		return(0);
1917468Ssam 	}
1927468Ssam 	sc = &css_softc[unit];
1937468Ssam 
1947468Ssam 	/*
1957468Ssam 	 * Header length is 0 to if_ubainit since we have to pass
1967468Ssam 	 * the IMP leader up to the protocol interpretaion
1977468Ssam 	 * routines.  If we had the deader length as
1987468Ssam 	 * sizeof(struct imp_leader), then the if_ routines
1997468Ssam 	 * would assume we handle it on input and output.
2007468Ssam 	 */
2017468Ssam 
20233452Skarels         if ((sc->css_imp->imp_if.if_flags & IFF_RUNNING) == 0 &&
20333452Skarels 	    if_ubainit(&sc->css_ifuba, ui->ui_ubanum, 0,
20433452Skarels 	    (int)btoc(IMP_RCVBUF)) == 0) {
2057468Ssam                 printf("css%d: can't initialize\n", unit);
2067468Ssam 		ui->ui_alive = 0;
20733452Skarels 		sc->css_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING);
2087468Ssam 		return(0);
2097468Ssam         }
21033452Skarels 	sc->css_imp->imp_if.if_flags |= IFF_RUNNING;
2117468Ssam         addr = (struct cssdevice *)ui->ui_addr;
2127468Ssam 
2137468Ssam         /* reset the imp interface. */
2147468Ssam         x = spl5();
2157468Ssam         addr->css_icsr = CSS_CLR;
2167468Ssam         addr->css_ocsr = CSS_CLR;
2177468Ssam 	DELAY(100);
2187468Ssam 	addr->css_icsr = 0;
2197468Ssam 	addr->css_ocsr = 0;
2207468Ssam         addr->css_icsr = IN_HRDY;       /* close the relay */
2217468Ssam 	DELAY(5000);
2227468Ssam         splx(x);
2237468Ssam 
2247468Ssam         /*
2257468Ssam 	 * This may hang if the imp isn't really there.
2267468Ssam 	 * Will test and verify safe operation.
2277468Ssam 	 */
2287468Ssam 
2297468Ssam 	x = 500;
2307468Ssam 	while (x-- > 0) {
2317468Ssam 		if ((addr->css_icsr & (IN_HRDY|IN_IMPNR)) == IN_HRDY)
2327468Ssam 			break;
2337468Ssam                 addr->css_icsr = IN_HRDY;	/* close the relay */
2347468Ssam                 DELAY(5000);
2357468Ssam         }
2367468Ssam 
2377468Ssam 	if (x <= 0) {
2387468Ssam 		printf("css%d: imp doesn't respond, icsr=%b\n", unit,
2397468Ssam 			CSS_INBITS, addr->css_icsr);
2407468Ssam 		goto down;
2417468Ssam 	}
2427468Ssam 
2437468Ssam         /*
2447468Ssam          * Put up a read.  We can't restart any outstanding writes
2457468Ssam          * until we're back in synch with the IMP (i.e. we've flushed
2467468Ssam          * the NOOPs it throws at us).
24733452Skarels 	 * Note: IMP_RCVBUF includes the leader.
2487468Ssam          */
2497468Ssam 
2507468Ssam         x = spl5();
2517468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
2527468Ssam         addr->css_iba = (u_short)info;
25333452Skarels         addr->css_iwc = -(IMP_RCVBUF >> 1);
2547468Ssam         addr->css_icsr =
2557468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
2567468Ssam         splx(x);
2577468Ssam 	return(1);
2587468Ssam 
2597468Ssam down:
2607468Ssam 	ui->ui_alive = 0;
2617468Ssam 	return(0);
2627468Ssam }
2637468Ssam 
2647468Ssam /*
26533452Skarels  * Drop the host ready line to mark host down.
26633452Skarels  * UNTESTED.
26733452Skarels  */
26833452Skarels cssdown(unit)
26933452Skarels 	int unit;
27033452Skarels {
27133452Skarels         register struct cssdevice *addr;
27233452Skarels 
27333452Skarels 	addr = (struct cssdevice *)(cssinfo[unit]->ui_addr);
27433452Skarels         /* reset the imp interface. */
27533452Skarels         addr->css_icsr = CSS_CLR;
27633452Skarels         addr->css_ocsr = CSS_CLR;
27733452Skarels 	DELAY(100);
27833452Skarels 	addr->css_icsr = 0;
27933452Skarels 	addr->css_ocsr = 0;
28034273Skarels 	cssoflush(unit);
28133452Skarels 	return (1);
28233452Skarels }
28333452Skarels 
28434273Skarels cssoflush(unit)
28534273Skarels 	int unit;
28634273Skarels {
28734501Skarels 	register struct css_softc *sc = &css_softc[unit];
28834273Skarels 
28934501Skarels 	sc->css_imp->imp_cb.ic_oactive = 0;
29034501Skarels 	if (sc->css_ifuba.ifu_xtofree) {
29134501Skarels 		m_freem(sc->css_ifuba.ifu_xtofree);
29234501Skarels 		sc->css_ifuba.ifu_xtofree = 0;
29334273Skarels 	}
29434273Skarels }
29534273Skarels 
29633452Skarels /*
2977468Ssam  * Start output on an interface.
2987468Ssam  */
29933452Skarels cssoutput(unit, m)
30033452Skarels         int unit;
30133452Skarels         struct mbuf *m;
3027468Ssam {
30333452Skarels         int info;
3047468Ssam         struct uba_device *ui = cssinfo[unit];
3057468Ssam         register struct css_softc *sc = &css_softc[unit];
3067468Ssam         register struct cssdevice *addr;
3077468Ssam 
3087468Ssam         sc->css_olen = if_wubaput(&sc->css_ifuba, m);
3097468Ssam         /*
3107468Ssam          * Have request mapped to UNIBUS for transmission.
3117468Ssam          * Purge any stale data from the BDP, and start the output.
3127468Ssam          */
3137468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3147468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_w.ifrw_bdp);
3157468Ssam         addr = (struct cssdevice *)ui->ui_addr;
3167468Ssam         info = sc->css_ifuba.ifu_w.ifrw_info;
3177468Ssam         addr->css_oba = (u_short)info;
3187468Ssam         addr->css_owc = -((sc->css_olen + 1) >> 1);
31933452Skarels         addr->css_ocsr =
32033452Skarels 	    (u_short)(CSS_IE | OUT_ENLB | ((info & 0x30000) >> 12) | CSS_GO);
32133452Skarels         sc->css_imp->imp_cb.ic_oactive = 1;
3227468Ssam }
3237468Ssam 
3247468Ssam /*
3257468Ssam  * Output interrupt handler.
3267468Ssam  */
3277468Ssam cssxint(unit)
3287468Ssam {
3297468Ssam         register struct uba_device *ui = cssinfo[unit];
3307468Ssam         register struct css_softc *sc = &css_softc[unit];
3317468Ssam         register struct cssdevice *addr;
3327468Ssam 
3337468Ssam         addr = (struct cssdevice *)ui->ui_addr;
33433452Skarels         if (sc->css_imp->imp_cb.ic_oactive == 0) {
3357468Ssam                 printf("css%d: stray output interrupt csr=%b\n",
3367468Ssam 			unit, addr->css_ocsr, CSS_OUTBITS);
3377468Ssam                 return;
3387468Ssam         }
33933452Skarels         sc->css_imp->imp_if.if_opackets++;
34033452Skarels         sc->css_imp->imp_cb.ic_oactive = 0;
3417468Ssam         if (addr->css_ocsr & CSS_ERR){
34233452Skarels                 sc->css_imp->imp_if.if_oerrors++;
3437468Ssam                 printf("css%d: output error, ocsr=%b icsr=%b\n", unit,
3447468Ssam                         addr->css_ocsr, CSS_OUTBITS,
3457468Ssam 			addr->css_icsr, CSS_INBITS);
3467468Ssam 	}
3477468Ssam 	if (sc->css_ifuba.ifu_xtofree) {
3487468Ssam 		m_freem(sc->css_ifuba.ifu_xtofree);
3497468Ssam 		sc->css_ifuba.ifu_xtofree = 0;
3507468Ssam 	}
35133452Skarels 	impstart(sc->css_imp);
3527468Ssam }
3537468Ssam 
3547468Ssam /*
3557468Ssam  * Input interrupt handler
3567468Ssam  */
3577468Ssam cssrint(unit)
3587468Ssam {
3597468Ssam         register struct css_softc *sc = &css_softc[unit];
3607468Ssam         register struct cssdevice *addr;
3617468Ssam         struct mbuf *m;
3627468Ssam         int len, info;
3637468Ssam 
36433452Skarels         sc->css_imp->imp_if.if_ipackets++;
3657468Ssam 
3667468Ssam         /*
3677468Ssam          * Purge BDP; flush message if error indicated.
3687468Ssam          */
3697468Ssam 
3707468Ssam         addr = (struct cssdevice *)cssinfo[unit]->ui_addr;
3717468Ssam 	if (sc->css_ifuba.ifu_flags & UBA_NEEDBDP)
3727468Ssam 		UBAPURGE(sc->css_ifuba.ifu_uba, sc->css_ifuba.ifu_r.ifrw_bdp);
3737468Ssam         if (addr->css_icsr & CSS_ERR) {
3747468Ssam                 printf("css%d: recv error, csr=%b\n", unit,
3757468Ssam                     addr->css_icsr, CSS_INBITS);
37633452Skarels                 sc->css_imp->imp_if.if_ierrors++;
3777468Ssam                 sc->css_flush = 1;
3787468Ssam         }
3797468Ssam 
3807468Ssam         if (sc->css_flush) {
3817468Ssam                 if (addr->css_icsr & IN_EOM)
3827468Ssam                         sc->css_flush = 0;
3837468Ssam                 goto setup;
3847468Ssam         }
3857468Ssam 
38633452Skarels         len = IMP_RCVBUF + (addr->css_iwc << 1);
38733452Skarels 	if (len < 0 || len > IMP_RCVBUF) {
3887468Ssam 		printf("css%d: bad length=%d\n", len);
38933452Skarels 		sc->css_imp->imp_if.if_ierrors++;
3907468Ssam 		goto setup;
3917468Ssam 	}
3927468Ssam 
3937468Ssam         /*
39424800Skarels          * The offset parameter is always 0 since using
3957468Ssam          * trailers on the ARPAnet is insane.
3967468Ssam          */
39733452Skarels         m = if_rubaget(&sc->css_ifuba, len, 0, &sc->css_imp->imp_if);
3987468Ssam         if (m == 0)
3997468Ssam                 goto setup;
4007468Ssam         if ((addr->css_icsr & IN_EOM) == 0) {
4017468Ssam 		if (sc->css_iq)
4027468Ssam 			m_cat(sc->css_iq, m);
4037468Ssam 		else
4047468Ssam 			sc->css_iq = m;
4057468Ssam 		goto setup;
4067468Ssam 	}
4077468Ssam 	if (sc->css_iq) {
4087468Ssam 		m_cat(sc->css_iq, m);
4097468Ssam 		m = sc->css_iq;
4107468Ssam 		sc->css_iq = 0;
4117468Ssam         }
4127468Ssam         impinput(unit, m);
4137468Ssam 
4147468Ssam setup:
4157468Ssam         /*
4167468Ssam          * Setup for next message.
4177468Ssam          */
4187468Ssam         info = sc->css_ifuba.ifu_r.ifrw_info;
4197468Ssam         addr->css_iba = (u_short)info;
42033452Skarels         addr->css_iwc = - (IMP_RCVBUF >> 1);
4217468Ssam         addr->css_icsr =
4227468Ssam                 IN_HRDY | CSS_IE | IN_WEN | ((info & 0x30000) >> 12) | CSS_GO;
4237468Ssam }
42425270Sbloom #endif
425