xref: /csrg-svn/sys/vax/if/if_il.c (revision 8979)
1*8979Sroot /*	if_il.c	4.13	82/10/31	*/
26893Sfeldman 
36893Sfeldman #include "il.h"
46893Sfeldman 
56893Sfeldman /*
66893Sfeldman  * Interlan Ethernet Communications Controller interface
76893Sfeldman  */
86893Sfeldman #include "../h/param.h"
96893Sfeldman #include "../h/systm.h"
106893Sfeldman #include "../h/mbuf.h"
116893Sfeldman #include "../h/pte.h"
126893Sfeldman #include "../h/buf.h"
136893Sfeldman #include "../h/protosw.h"
146893Sfeldman #include "../h/socket.h"
156893Sfeldman #include "../h/vmmac.h"
168463Sroot #include <errno.h>
178463Sroot 
188463Sroot #include "../net/if.h"
198463Sroot #include "../net/netisr.h"
208463Sroot #include "../net/route.h"
218419Swnj #include "../netinet/in.h"
228419Swnj #include "../netinet/in_systm.h"
238419Swnj #include "../netinet/ip.h"
248419Swnj #include "../netinet/ip_var.h"
258419Swnj #include "../netpup/pup.h"
266893Sfeldman 
278463Sroot #include "../vax/cpu.h"
288463Sroot #include "../vax/mtpr.h"
298463Sroot #include "../vaxif/if_ilreg.h"
308463Sroot #include "../vaxif/if_il.h"
318463Sroot #include "../vaxif/if_uba.h"
328463Sroot #include "../vaxuba/ubareg.h"
338463Sroot #include "../vaxuba/ubavar.h"
348463Sroot 
356893Sfeldman #define	ILMTU	1500
366893Sfeldman 
376893Sfeldman int	ilprobe(), ilattach(), ilrint(), ilcint();
386893Sfeldman struct	uba_device *ilinfo[NIL];
396893Sfeldman u_short ilstd[] = { 0 };
406893Sfeldman struct	uba_driver ildriver =
416893Sfeldman 	{ ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo };
426893Sfeldman #define	ILUNIT(x)	minor(x)
437261Ssam int	ilinit(),iloutput(),ilreset(),ilwatch();
446893Sfeldman 
457220Ssam u_char	il_ectop[3] = { 0x02, 0x60, 0x8c };
467220Ssam u_char	ilbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
477220Ssam 
486893Sfeldman /*
496893Sfeldman  * Ethernet software status per interface.
506893Sfeldman  *
516893Sfeldman  * Each interface is referenced by a network interface structure,
526893Sfeldman  * is_if, which the routing code uses to locate the interface.
536893Sfeldman  * This structure contains the output queue for the interface, its address, ...
546893Sfeldman  * We also have, for each interface, a UBA interface structure, which
556893Sfeldman  * contains information about the UNIBUS resources held by the interface:
566893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
576893Sfeldman  * structure for use by the if_uba.c routines in running the interface
586893Sfeldman  * efficiently.
596893Sfeldman  */
606893Sfeldman struct	il_softc {
616893Sfeldman 	struct	ifnet is_if;		/* network-visible interface */
626893Sfeldman 	struct	ifuba is_ifuba;		/* UNIBUS resources */
637261Ssam 	int	is_flags;
647261Ssam #define	ILF_OACTIVE	0x1		/* output is active */
657261Ssam #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
667261Ssam #define	ILF_STATPENDING	0x4		/* stat cmd pending */
677261Ssam 	short	is_lastcmd;		/* can't read csr, so must save it */
687261Ssam 	short	is_scaninterval;	/* interval of stat collection */
697261Ssam #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
707261Ssam 	struct	il_stats is_stats;	/* holds on-board statistics */
717261Ssam 	struct	il_stats is_sum;	/* summation over time */
727261Ssam 	int	is_ubaddr;		/* mapping registers of is_stats */
736893Sfeldman } il_softc[NIL];
746893Sfeldman 
756893Sfeldman ilprobe(reg)
766893Sfeldman 	caddr_t reg;
776893Sfeldman {
786893Sfeldman 	register int br, cvec;		/* r11, r10 value-result */
796893Sfeldman 	register struct ildevice *addr = (struct ildevice *)reg;
806893Sfeldman 	register i;
816893Sfeldman 
826893Sfeldman #ifdef lint
836893Sfeldman 	br = 0; cvec = br; br = cvec;
847261Ssam 	ilrint(0); ilcint(0); ilwatch(0);
856893Sfeldman #endif
866893Sfeldman 
876893Sfeldman 	addr->il_csr = ILC_OFFLINE|IL_CIE;
886893Sfeldman 	DELAY(100000);
897261Ssam 	i = addr->il_csr;		/* clear CDONE */
906893Sfeldman 	if (cvec > 0 && cvec != 0x200)
916893Sfeldman 		cvec -= 4;
926893Sfeldman 	return (1);
936893Sfeldman }
946893Sfeldman 
956893Sfeldman /*
966893Sfeldman  * Interface exists: make available by filling in network interface
976893Sfeldman  * record.  System will initialize the interface when it is ready
986893Sfeldman  * to accept packets.  A STATUS command is done to get the ethernet
996893Sfeldman  * address and other interesting data.
1006893Sfeldman  */
1016893Sfeldman ilattach(ui)
1026893Sfeldman 	struct uba_device *ui;
1036893Sfeldman {
1046893Sfeldman 	register struct il_softc *is = &il_softc[ui->ui_unit];
1057220Ssam 	register struct ifnet *ifp = &is->is_if;
1066893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
1077220Ssam 	struct sockaddr_in *sin;
1086893Sfeldman 
1097220Ssam 	ifp->if_unit = ui->ui_unit;
1107220Ssam 	ifp->if_name = "il";
1117220Ssam 	ifp->if_mtu = ILMTU;
1127220Ssam 	ifp->if_net = ui->ui_flags;
1136893Sfeldman 
1146893Sfeldman 	/*
1157261Ssam 	 * Reset the board and map the statistics
1167261Ssam 	 * buffer onto the Unibus.
1176893Sfeldman 	 */
1187261Ssam 	addr->il_csr = ILC_RESET;
1197261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1207261Ssam 		;
1217261Ssam 	if (addr->il_csr&IL_STATUS)
1227261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1237261Ssam 			addr->il_csr, IL_BITS);
1246893Sfeldman 
1257261Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats,
1267261Ssam 		sizeof (struct il_stats), 0);
1277261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1287261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1297261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1307261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1317261Ssam 		;
1327261Ssam 	if (addr->il_csr&IL_STATUS)
1337261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1347261Ssam 			addr->il_csr, IL_BITS);
1357261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
1366893Sfeldman 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
1376893Sfeldman 		ui->ui_unit,
1387261Ssam 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
1397261Ssam 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
1407261Ssam 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
1417261Ssam 		is->is_stats.ils_module, is->is_stats.ils_firmware);
1427261Ssam 	ifp->if_host[0] =
1437261Ssam 	    ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 |
1447261Ssam 	    ((is->is_stats.ils_addr[4]&0xff)<<8) |
1457261Ssam 	    (is->is_stats.ils_addr[5]&0xff);
1467220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1476893Sfeldman 	sin->sin_family = AF_INET;
1487220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]);
1496893Sfeldman 
1507220Ssam 	sin = (struct sockaddr_in *)&ifp->if_broadaddr;
1516893Sfeldman 	sin->sin_family = AF_INET;
1527220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
1537220Ssam 	ifp->if_flags = IFF_BROADCAST;
1546893Sfeldman 
1557220Ssam 	ifp->if_init = ilinit;
1567220Ssam 	ifp->if_output = iloutput;
157*8979Sroot 	ifp->if_reset = ilreset;
1587261Ssam 	ifp->if_watchdog = ilwatch;
1597261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1607261Ssam 	ifp->if_timer = is->is_scaninterval;
1616893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1627220Ssam #ifdef notdef
1637220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1647220Ssam #endif
1657220Ssam 	if_attach(ifp);
1666893Sfeldman }
1676893Sfeldman 
1686893Sfeldman /*
1696893Sfeldman  * Reset of interface after UNIBUS reset.
1706893Sfeldman  * If interface is on specified uba, reset its state.
1716893Sfeldman  */
1726893Sfeldman ilreset(unit, uban)
1736893Sfeldman 	int unit, uban;
1746893Sfeldman {
1756893Sfeldman 	register struct uba_device *ui;
1766893Sfeldman 
1776893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1786893Sfeldman 	    ui->ui_ubanum != uban)
1796893Sfeldman 		return;
1806893Sfeldman 	printf(" il%d", unit);
1816893Sfeldman 	ilinit(unit);
1826893Sfeldman }
1836893Sfeldman 
1846893Sfeldman /*
1856893Sfeldman  * Initialization of interface; clear recorded pending
1866893Sfeldman  * operations, and reinitialize UNIBUS usage.
1876893Sfeldman  */
1886893Sfeldman ilinit(unit)
1896893Sfeldman 	int unit;
1906893Sfeldman {
1916893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1926893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1936893Sfeldman 	register struct ildevice *addr;
1947261Ssam 	int s;
1956893Sfeldman 
1966893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1976893Sfeldman 	    sizeof (struct il_rheader), (int)btoc(ILMTU)) == 0) {
1986893Sfeldman 		printf("il%d: can't initialize\n", unit);
1996893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2006893Sfeldman 		return;
2016893Sfeldman 	}
2027261Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, &is->is_stats,
2037261Ssam 		sizeof (struct il_stats), 0);
2046893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2056893Sfeldman 
2066893Sfeldman 	/*
2076893Sfeldman 	 * Set board online.
2086893Sfeldman 	 * Hang receive buffer and start any pending
2096893Sfeldman 	 * writes by faking a transmit complete.
2106893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2116893Sfeldman 	 * chaining can't happen.
2126893Sfeldman 	 */
2136893Sfeldman 	s = splimp();
2146893Sfeldman 	addr->il_csr = ILC_ONLINE;
2157220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2167220Ssam 		;
2176893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2186893Sfeldman 	addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
2197261Ssam 	addr->il_csr =
2207261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2217220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2227220Ssam 		;
2237261Ssam 	is->is_flags = ILF_OACTIVE;
2246893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2257261Ssam 	is->is_lastcmd = 0;
2266893Sfeldman 	ilcint(unit);
2276893Sfeldman 	splx(s);
2287152Swnj 	if_rtinit(&is->is_if, RTF_UP);
2296893Sfeldman }
2306893Sfeldman 
2316893Sfeldman /*
2326893Sfeldman  * Start output on interface.
2336893Sfeldman  * Get another datagram to send off of the interface queue,
2346893Sfeldman  * and map it to the interface before starting the output.
2356893Sfeldman  */
2366893Sfeldman ilstart(dev)
2376893Sfeldman 	dev_t dev;
2386893Sfeldman {
2397220Ssam         int unit = ILUNIT(dev), dest, len;
2406893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2416893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2426893Sfeldman 	register struct ildevice *addr;
2436893Sfeldman 	struct mbuf *m;
2447220Ssam 	short csr;
2456893Sfeldman 
2466893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2477261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2487261Ssam 	if (m == 0) {
2497261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2507261Ssam 			return;
2517261Ssam 		addr->il_bar = is->is_ubaddr & 0xfff;
2527261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2537261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2547261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2557261Ssam 		goto startcmd;
2567261Ssam 	}
2576893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2586893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2596893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2606893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2616893Sfeldman 	addr->il_bcr = len;
2627261Ssam 	csr =
2637261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2647261Ssam 
2657261Ssam startcmd:
2667261Ssam 	is->is_lastcmd = csr & IL_CMD;
2677220Ssam 	addr->il_csr = csr;
2687261Ssam 	is->is_flags |= ILF_OACTIVE;
2696893Sfeldman }
2706893Sfeldman 
2716893Sfeldman /*
2726893Sfeldman  * Command done interrupt.
2736893Sfeldman  */
2746893Sfeldman ilcint(unit)
2756893Sfeldman 	int unit;
2766893Sfeldman {
2776893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2787220Ssam 	struct uba_device *ui = ilinfo[unit];
2796893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
2807266Ssam 	short csr;
2816893Sfeldman 
2827261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
2837220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
2847261Ssam 			addr->il_csr, IL_BITS);
2856893Sfeldman 		return;
2866893Sfeldman 	}
2877220Ssam 
2887266Ssam 	csr = addr->il_csr;
2896893Sfeldman 	/*
2907261Ssam 	 * Hang receive buffer if it couldn't
2917261Ssam 	 * be done earlier (in ilrint).
2926893Sfeldman 	 */
2937261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
2946893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2956893Sfeldman 		addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
2967261Ssam 		addr->il_csr =
2977261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2987220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
2997220Ssam 			;
3007261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3016893Sfeldman 	}
3027261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3037266Ssam 	csr &= IL_STATUS;
3047261Ssam 	switch (is->is_lastcmd) {
3057261Ssam 
3067261Ssam 	case ILC_XMIT:
3077261Ssam 		is->is_if.if_opackets++;
3087266Ssam 		if (csr > ILERR_RETRIES)
3097261Ssam 			is->is_if.if_oerrors++;
3107261Ssam 		break;
3117261Ssam 
3127261Ssam 	case ILC_STAT:
3137266Ssam 		if (csr == ILERR_SUCCESS)
3147261Ssam 			iltotal(is);
3157261Ssam 		break;
3167261Ssam 	}
3176893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3186893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3196893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3206893Sfeldman 	}
3217261Ssam 	ilstart(unit);
3226893Sfeldman }
3236893Sfeldman 
3246893Sfeldman /*
3256893Sfeldman  * Ethernet interface receiver interrupt.
3266893Sfeldman  * If input error just drop packet.
3276893Sfeldman  * Otherwise purge input buffered data path and examine
3286893Sfeldman  * packet to determine type.  If can't determine length
3296893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3306893Sfeldman  * packet based on type and pass to type specific higher-level
3316893Sfeldman  * input routine.
3326893Sfeldman  */
3336893Sfeldman ilrint(unit)
3346893Sfeldman 	int unit;
3356893Sfeldman {
3366893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3376893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3386893Sfeldman 	register struct il_rheader *il;
3396893Sfeldman     	struct mbuf *m;
3406893Sfeldman 	int len, off, resid;
3416893Sfeldman 	register struct ifqueue *inq;
3426893Sfeldman 
3436893Sfeldman 	is->is_if.if_ipackets++;
3446893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3456893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3466893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3476893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3487261Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || len > ILMTU) {
3496893Sfeldman 		is->is_if.if_ierrors++;
3506893Sfeldman #ifdef notdef
3516893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3526893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3536893Sfeldman #endif
3546893Sfeldman 		goto setup;
3556893Sfeldman 	}
3566893Sfeldman 
3576893Sfeldman 	/*
3586893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3596893Sfeldman 	 * get true type from first 16-bit word past data.
3606893Sfeldman 	 * Remember that type was trailer by setting off.
3616893Sfeldman 	 */
3626893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3636893Sfeldman 	if (il->ilr_type >= ILPUP_TRAIL &&
3646893Sfeldman 	    il->ilr_type < ILPUP_TRAIL+ILPUP_NTRAILER) {
3656893Sfeldman 		off = (il->ilr_type - ILPUP_TRAIL) * 512;
3666893Sfeldman 		if (off >= ILMTU)
3676893Sfeldman 			goto setup;		/* sanity */
3686893Sfeldman 		il->ilr_type = *ildataaddr(il, off, u_short *);
3696893Sfeldman 		resid = *(ildataaddr(il, off+2, u_short *));
3706893Sfeldman 		if (off + resid > len)
3716893Sfeldman 			goto setup;		/* sanity */
3726893Sfeldman 		len = off + resid;
3736893Sfeldman 	} else
3746893Sfeldman 		off = 0;
3756893Sfeldman 	if (len == 0)
3766893Sfeldman 		goto setup;
3776893Sfeldman 
3786893Sfeldman 	/*
3796893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
3806893Sfeldman 	 * has trailing header; ilget will then force this header
3816893Sfeldman 	 * information to be at the front, but we still have to drop
3826893Sfeldman 	 * the type and length which are at the front of any trailer data.
3836893Sfeldman 	 */
3846893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
3856893Sfeldman 	if (m == 0)
3866893Sfeldman 		goto setup;
3876893Sfeldman 	if (off) {
3886893Sfeldman 		m->m_off += 2 * sizeof (u_short);
3896893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
3906893Sfeldman 	}
3916893Sfeldman 	switch (il->ilr_type) {
3926893Sfeldman 
3936893Sfeldman #ifdef INET
3946893Sfeldman 	case ILPUP_IPTYPE:
3956893Sfeldman 		schednetisr(NETISR_IP);
3966893Sfeldman 		inq = &ipintrq;
3976893Sfeldman 		break;
3986893Sfeldman #endif
3996893Sfeldman 	default:
4006893Sfeldman 		m_freem(m);
4016893Sfeldman 		goto setup;
4026893Sfeldman 	}
4036893Sfeldman 
4046893Sfeldman 	if (IF_QFULL(inq)) {
4056893Sfeldman 		IF_DROP(inq);
4066893Sfeldman 		m_freem(m);
4077220Ssam 		goto setup;
4087220Ssam 	}
4097220Ssam 	IF_ENQUEUE(inq, m);
4106893Sfeldman 
4116893Sfeldman setup:
4126893Sfeldman 	/*
4136893Sfeldman 	 * Reset for next packet if possible.
4146893Sfeldman 	 * If waiting for transmit command completion, set flag
4156893Sfeldman 	 * and wait until command completes.
4166893Sfeldman 	 */
4177261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4187261Ssam 		is->is_flags |= ILF_RCVPENDING;
4197220Ssam 		return;
4207220Ssam 	}
4217220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4227220Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
4237261Ssam 	addr->il_csr =
4247261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4257220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4267220Ssam 		;
4276893Sfeldman }
4286893Sfeldman 
4296893Sfeldman /*
4306893Sfeldman  * Ethernet output routine.
4316893Sfeldman  * Encapsulate a packet of type family for the local net.
4326893Sfeldman  * Use trailer local net encapsulation if enough data in first
4336893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4346893Sfeldman  */
4356893Sfeldman iloutput(ifp, m0, dst)
4366893Sfeldman 	struct ifnet *ifp;
4376893Sfeldman 	struct mbuf *m0;
4386893Sfeldman 	struct sockaddr *dst;
4396893Sfeldman {
4406893Sfeldman 	int type, dest, s, error;
4416893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4426893Sfeldman 	register struct mbuf *m = m0;
4436893Sfeldman 	register struct il_xheader *il;
4447220Ssam 	register int off, i;
4456893Sfeldman 
4466893Sfeldman 	switch (dst->sa_family) {
4476893Sfeldman 
4486893Sfeldman #ifdef INET
4496893Sfeldman 	case AF_INET:
4506893Sfeldman 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
4516893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4526893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4536893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4546893Sfeldman 			type = ILPUP_TRAIL + (off>>9);
4556893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4566893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4576893Sfeldman 			*mtod(m, u_short *) = ILPUP_IPTYPE;
4586893Sfeldman 			*(mtod(m, u_short *) + 1) = m->m_len;
4596893Sfeldman 			goto gottrailertype;
4606893Sfeldman 		}
4616893Sfeldman 		type = ILPUP_IPTYPE;
4626893Sfeldman 		off = 0;
4636893Sfeldman 		goto gottype;
4646893Sfeldman #endif
4656893Sfeldman 
4666893Sfeldman 	default:
4676893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
4686893Sfeldman 			dst->sa_family);
4696893Sfeldman 		error = EAFNOSUPPORT;
4706893Sfeldman 		goto bad;
4716893Sfeldman 	}
4726893Sfeldman 
4736893Sfeldman gottrailertype:
4746893Sfeldman 	/*
4756893Sfeldman 	 * Packet to be sent as trailer: move first packet
4766893Sfeldman 	 * (control information) to end of chain.
4776893Sfeldman 	 */
4786893Sfeldman 	while (m->m_next)
4796893Sfeldman 		m = m->m_next;
4806893Sfeldman 	m->m_next = m0;
4816893Sfeldman 	m = m0->m_next;
4826893Sfeldman 	m0->m_next = 0;
4836893Sfeldman 	m0 = m;
4846893Sfeldman 
4856893Sfeldman gottype:
4866893Sfeldman 	/*
4876893Sfeldman 	 * Add local net header.  If no space in first mbuf,
4886893Sfeldman 	 * allocate another.
4896893Sfeldman 	 */
4906893Sfeldman 	if (m->m_off > MMAXOFF ||
4916893Sfeldman 	    MMINOFF + sizeof (struct il_xheader) > m->m_off) {
4926893Sfeldman 		m = m_get(M_DONTWAIT);
4936893Sfeldman 		if (m == 0) {
4946893Sfeldman 			error = ENOBUFS;
4956893Sfeldman 			goto bad;
4966893Sfeldman 		}
4976893Sfeldman 		m->m_next = m0;
4986893Sfeldman 		m->m_off = MMINOFF;
4996893Sfeldman 		m->m_len = sizeof (struct il_xheader);
5006893Sfeldman 	} else {
5016893Sfeldman 		m->m_off -= sizeof (struct il_xheader);
5026893Sfeldman 		m->m_len += sizeof (struct il_xheader);
5036893Sfeldman 	}
5046893Sfeldman 	il = mtod(m, struct il_xheader *);
5056893Sfeldman 	if ((dest &~ 0xff) == 0)
5067220Ssam 		bcopy(ilbroadcastaddr, il->ilx_dhost, 6);
5076893Sfeldman 	else {
5087261Ssam 		u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop;
5097220Ssam 
5107220Ssam 		bcopy(to, il->ilx_dhost, 3);
5116893Sfeldman 		il->ilx_dhost[3] = (dest>>8) & 0x7f;
5126893Sfeldman 		il->ilx_dhost[4] = (dest>>16) & 0xff;
5136893Sfeldman 		il->ilx_dhost[5] = (dest>>24) & 0xff;
5146893Sfeldman 	}
5156893Sfeldman 	il->ilx_type = type;
5166893Sfeldman 
5176893Sfeldman 	/*
5186893Sfeldman 	 * Queue message on interface, and start output if interface
5196893Sfeldman 	 * not yet active.
5206893Sfeldman 	 */
5216893Sfeldman 	s = splimp();
5226893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5236893Sfeldman 		IF_DROP(&ifp->if_snd);
5247220Ssam 		splx(s);
5257220Ssam 		m_freem(m);
5267220Ssam 		return (ENOBUFS);
5276893Sfeldman 	}
5286893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5297261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5306893Sfeldman 		ilstart(ifp->if_unit);
5316893Sfeldman 	splx(s);
5326893Sfeldman 	return (0);
5337220Ssam 
5346893Sfeldman bad:
5356893Sfeldman 	m_freem(m0);
5367220Ssam 	return (error);
5376893Sfeldman }
5387261Ssam 
5397261Ssam /*
5407261Ssam  * Watchdog routine, request statistics from board.
5417261Ssam  */
5427261Ssam ilwatch(unit)
5437261Ssam 	int unit;
5447261Ssam {
5457261Ssam 	register struct il_softc *is = &il_softc[unit];
5467261Ssam 	register struct ifnet *ifp = &is->is_if;
5477261Ssam 	int s;
5487261Ssam 
5497261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5507261Ssam 		ifp->if_timer = is->is_scaninterval;
5517261Ssam 		return;
5527261Ssam 	}
5537261Ssam 	s = splimp();
5547261Ssam 	is->is_flags |= ILF_STATPENDING;
5557261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5567261Ssam 		ilstart(ifp->if_unit);
5577261Ssam 	splx(s);
5587261Ssam 	ifp->if_timer = is->is_scaninterval;
5597261Ssam }
5607261Ssam 
5617261Ssam /*
5627261Ssam  * Total up the on-board statistics.
5637261Ssam  */
5647261Ssam iltotal(is)
5657261Ssam 	register struct il_softc *is;
5667261Ssam {
5677261Ssam 	register u_short *interval, *sum, *end;
5687261Ssam 
5697261Ssam 	interval = &is->is_stats.ils_frames;
5707261Ssam 	sum = &is->is_sum.ils_frames;
5717261Ssam 	end = is->is_sum.ils_fill2;
5727261Ssam 	while (sum < end)
5737261Ssam 		*sum++ += *interval++;
5747261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
5757261Ssam }
576