xref: /csrg-svn/sys/vax/if/if_il.c (revision 9650)
1*9650Ssam /*	if_il.c	4.15	82/12/14	*/
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
369179Ssam #define	ILMIN	(60-14)
376893Sfeldman 
386893Sfeldman int	ilprobe(), ilattach(), ilrint(), ilcint();
396893Sfeldman struct	uba_device *ilinfo[NIL];
406893Sfeldman u_short ilstd[] = { 0 };
416893Sfeldman struct	uba_driver ildriver =
426893Sfeldman 	{ ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo };
436893Sfeldman #define	ILUNIT(x)	minor(x)
447261Ssam int	ilinit(),iloutput(),ilreset(),ilwatch();
456893Sfeldman 
467220Ssam u_char	il_ectop[3] = { 0x02, 0x60, 0x8c };
477220Ssam u_char	ilbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
487220Ssam 
496893Sfeldman /*
506893Sfeldman  * Ethernet software status per interface.
516893Sfeldman  *
526893Sfeldman  * Each interface is referenced by a network interface structure,
536893Sfeldman  * is_if, which the routing code uses to locate the interface.
546893Sfeldman  * This structure contains the output queue for the interface, its address, ...
556893Sfeldman  * We also have, for each interface, a UBA interface structure, which
566893Sfeldman  * contains information about the UNIBUS resources held by the interface:
576893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
586893Sfeldman  * structure for use by the if_uba.c routines in running the interface
596893Sfeldman  * efficiently.
606893Sfeldman  */
616893Sfeldman struct	il_softc {
626893Sfeldman 	struct	ifnet is_if;		/* network-visible interface */
636893Sfeldman 	struct	ifuba is_ifuba;		/* UNIBUS resources */
647261Ssam 	int	is_flags;
657261Ssam #define	ILF_OACTIVE	0x1		/* output is active */
667261Ssam #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
677261Ssam #define	ILF_STATPENDING	0x4		/* stat cmd pending */
687261Ssam 	short	is_lastcmd;		/* can't read csr, so must save it */
697261Ssam 	short	is_scaninterval;	/* interval of stat collection */
707261Ssam #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
717261Ssam 	struct	il_stats is_stats;	/* holds on-board statistics */
727261Ssam 	struct	il_stats is_sum;	/* summation over time */
737261Ssam 	int	is_ubaddr;		/* mapping registers of is_stats */
746893Sfeldman } il_softc[NIL];
756893Sfeldman 
766893Sfeldman ilprobe(reg)
776893Sfeldman 	caddr_t reg;
786893Sfeldman {
796893Sfeldman 	register int br, cvec;		/* r11, r10 value-result */
806893Sfeldman 	register struct ildevice *addr = (struct ildevice *)reg;
816893Sfeldman 	register i;
826893Sfeldman 
836893Sfeldman #ifdef lint
846893Sfeldman 	br = 0; cvec = br; br = cvec;
859179Ssam 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
866893Sfeldman #endif
876893Sfeldman 
886893Sfeldman 	addr->il_csr = ILC_OFFLINE|IL_CIE;
896893Sfeldman 	DELAY(100000);
907261Ssam 	i = addr->il_csr;		/* clear CDONE */
916893Sfeldman 	if (cvec > 0 && cvec != 0x200)
926893Sfeldman 		cvec -= 4;
936893Sfeldman 	return (1);
946893Sfeldman }
956893Sfeldman 
966893Sfeldman /*
976893Sfeldman  * Interface exists: make available by filling in network interface
986893Sfeldman  * record.  System will initialize the interface when it is ready
996893Sfeldman  * to accept packets.  A STATUS command is done to get the ethernet
1006893Sfeldman  * address and other interesting data.
1016893Sfeldman  */
1026893Sfeldman ilattach(ui)
1036893Sfeldman 	struct uba_device *ui;
1046893Sfeldman {
1056893Sfeldman 	register struct il_softc *is = &il_softc[ui->ui_unit];
1067220Ssam 	register struct ifnet *ifp = &is->is_if;
1076893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
1087220Ssam 	struct sockaddr_in *sin;
1096893Sfeldman 
1107220Ssam 	ifp->if_unit = ui->ui_unit;
1117220Ssam 	ifp->if_name = "il";
1127220Ssam 	ifp->if_mtu = ILMTU;
1137220Ssam 	ifp->if_net = ui->ui_flags;
1146893Sfeldman 
1156893Sfeldman 	/*
1167261Ssam 	 * Reset the board and map the statistics
1177261Ssam 	 * buffer onto the Unibus.
1186893Sfeldman 	 */
1197261Ssam 	addr->il_csr = ILC_RESET;
1207261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1217261Ssam 		;
1227261Ssam 	if (addr->il_csr&IL_STATUS)
1237261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1247261Ssam 			addr->il_csr, IL_BITS);
1256893Sfeldman 
1269179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
1277261Ssam 		sizeof (struct il_stats), 0);
1287261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1297261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1307261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1317261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1327261Ssam 		;
1337261Ssam 	if (addr->il_csr&IL_STATUS)
1347261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1357261Ssam 			addr->il_csr, IL_BITS);
1367261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
1376893Sfeldman 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
1386893Sfeldman 		ui->ui_unit,
1397261Ssam 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
1407261Ssam 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
1417261Ssam 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
1427261Ssam 		is->is_stats.ils_module, is->is_stats.ils_firmware);
1437261Ssam 	ifp->if_host[0] =
1447261Ssam 	    ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 |
1457261Ssam 	    ((is->is_stats.ils_addr[4]&0xff)<<8) |
1467261Ssam 	    (is->is_stats.ils_addr[5]&0xff);
1477220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1486893Sfeldman 	sin->sin_family = AF_INET;
1497220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]);
1506893Sfeldman 
1517220Ssam 	sin = (struct sockaddr_in *)&ifp->if_broadaddr;
1526893Sfeldman 	sin->sin_family = AF_INET;
1537220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
1547220Ssam 	ifp->if_flags = IFF_BROADCAST;
1556893Sfeldman 
1567220Ssam 	ifp->if_init = ilinit;
1577220Ssam 	ifp->if_output = iloutput;
1588979Sroot 	ifp->if_reset = ilreset;
1597261Ssam 	ifp->if_watchdog = ilwatch;
1607261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1617261Ssam 	ifp->if_timer = is->is_scaninterval;
1626893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1637220Ssam #ifdef notdef
1647220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1657220Ssam #endif
1667220Ssam 	if_attach(ifp);
1676893Sfeldman }
1686893Sfeldman 
1696893Sfeldman /*
1706893Sfeldman  * Reset of interface after UNIBUS reset.
1716893Sfeldman  * If interface is on specified uba, reset its state.
1726893Sfeldman  */
1736893Sfeldman ilreset(unit, uban)
1746893Sfeldman 	int unit, uban;
1756893Sfeldman {
1766893Sfeldman 	register struct uba_device *ui;
1776893Sfeldman 
1786893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1796893Sfeldman 	    ui->ui_ubanum != uban)
1806893Sfeldman 		return;
1816893Sfeldman 	printf(" il%d", unit);
1826893Sfeldman 	ilinit(unit);
1836893Sfeldman }
1846893Sfeldman 
1856893Sfeldman /*
1866893Sfeldman  * Initialization of interface; clear recorded pending
1876893Sfeldman  * operations, and reinitialize UNIBUS usage.
1886893Sfeldman  */
1896893Sfeldman ilinit(unit)
1906893Sfeldman 	int unit;
1916893Sfeldman {
1926893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1936893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1946893Sfeldman 	register struct ildevice *addr;
1957261Ssam 	int s;
1966893Sfeldman 
1976893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1986893Sfeldman 	    sizeof (struct il_rheader), (int)btoc(ILMTU)) == 0) {
1996893Sfeldman 		printf("il%d: can't initialize\n", unit);
2006893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2016893Sfeldman 		return;
2026893Sfeldman 	}
2039179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
2047261Ssam 		sizeof (struct il_stats), 0);
2056893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2066893Sfeldman 
2076893Sfeldman 	/*
2089179Ssam 	 * Turn off source address insertion (it's faster this way),
2099179Ssam 	 * and set board online.
2109179Ssam 	 */
2119179Ssam 	s = splimp();
2129179Ssam 	addr->il_csr = ILC_CISA;
2139179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2149179Ssam 		;
2159179Ssam 	addr->il_csr = ILC_ONLINE;
2169179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2179179Ssam 		;
2189179Ssam 	/*
2196893Sfeldman 	 * Set board online.
2206893Sfeldman 	 * Hang receive buffer and start any pending
2216893Sfeldman 	 * writes by faking a transmit complete.
2226893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2236893Sfeldman 	 * chaining can't happen.
2246893Sfeldman 	 */
2256893Sfeldman 	s = splimp();
2266893Sfeldman 	addr->il_csr = ILC_ONLINE;
2277220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2287220Ssam 		;
2296893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2306893Sfeldman 	addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
2317261Ssam 	addr->il_csr =
2327261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2337220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2347220Ssam 		;
2357261Ssam 	is->is_flags = ILF_OACTIVE;
2366893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2377261Ssam 	is->is_lastcmd = 0;
2386893Sfeldman 	ilcint(unit);
2396893Sfeldman 	splx(s);
2407152Swnj 	if_rtinit(&is->is_if, RTF_UP);
2416893Sfeldman }
2426893Sfeldman 
2436893Sfeldman /*
2446893Sfeldman  * Start output on interface.
2456893Sfeldman  * Get another datagram to send off of the interface queue,
2466893Sfeldman  * and map it to the interface before starting the output.
2476893Sfeldman  */
2486893Sfeldman ilstart(dev)
2496893Sfeldman 	dev_t dev;
2506893Sfeldman {
2519179Ssam         int unit = ILUNIT(dev), len;
2526893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2536893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2546893Sfeldman 	register struct ildevice *addr;
2556893Sfeldman 	struct mbuf *m;
2567220Ssam 	short csr;
2576893Sfeldman 
2586893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2597261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2607261Ssam 	if (m == 0) {
2617261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2627261Ssam 			return;
2639179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2647261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2657261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2667261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2677261Ssam 		goto startcmd;
2687261Ssam 	}
2696893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2709179Ssam 	/*
2719179Ssam 	 * Ensure minimum packet length.
2729179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2739179Ssam 	 * after the data.
2749179Ssam 	 * For security, it might be wise to zero out the added bytes,
2759179Ssam 	 * but we're mainly interested in speed at the moment.
2769179Ssam 	 */
2779179Ssam 	if (len - sizeof(struct il_xheader) < ILMIN)
2789179Ssam 		len = ILMIN + sizeof(struct il_xheader);
2796893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2806893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2816893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2826893Sfeldman 	addr->il_bcr = len;
2837261Ssam 	csr =
2847261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2857261Ssam 
2867261Ssam startcmd:
2877261Ssam 	is->is_lastcmd = csr & IL_CMD;
2887220Ssam 	addr->il_csr = csr;
2897261Ssam 	is->is_flags |= ILF_OACTIVE;
2906893Sfeldman }
2916893Sfeldman 
2926893Sfeldman /*
2936893Sfeldman  * Command done interrupt.
2946893Sfeldman  */
2956893Sfeldman ilcint(unit)
2966893Sfeldman 	int unit;
2976893Sfeldman {
2986893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2997220Ssam 	struct uba_device *ui = ilinfo[unit];
3006893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
3017266Ssam 	short csr;
3026893Sfeldman 
3037261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3047220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3057261Ssam 			addr->il_csr, IL_BITS);
3066893Sfeldman 		return;
3076893Sfeldman 	}
3087220Ssam 
3097266Ssam 	csr = addr->il_csr;
3106893Sfeldman 	/*
3117261Ssam 	 * Hang receive buffer if it couldn't
3127261Ssam 	 * be done earlier (in ilrint).
3136893Sfeldman 	 */
3147261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3156893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3166893Sfeldman 		addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
3177261Ssam 		addr->il_csr =
3187261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3197220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3207220Ssam 			;
3217261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3226893Sfeldman 	}
3237261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3247266Ssam 	csr &= IL_STATUS;
3257261Ssam 	switch (is->is_lastcmd) {
3267261Ssam 
3277261Ssam 	case ILC_XMIT:
3287261Ssam 		is->is_if.if_opackets++;
3297266Ssam 		if (csr > ILERR_RETRIES)
3307261Ssam 			is->is_if.if_oerrors++;
3317261Ssam 		break;
3327261Ssam 
3337261Ssam 	case ILC_STAT:
3347266Ssam 		if (csr == ILERR_SUCCESS)
3357261Ssam 			iltotal(is);
3367261Ssam 		break;
3377261Ssam 	}
3386893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3396893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3406893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3416893Sfeldman 	}
3427261Ssam 	ilstart(unit);
3436893Sfeldman }
3446893Sfeldman 
3456893Sfeldman /*
3466893Sfeldman  * Ethernet interface receiver interrupt.
3476893Sfeldman  * If input error just drop packet.
3486893Sfeldman  * Otherwise purge input buffered data path and examine
3496893Sfeldman  * packet to determine type.  If can't determine length
3506893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3516893Sfeldman  * packet based on type and pass to type specific higher-level
3526893Sfeldman  * input routine.
3536893Sfeldman  */
3546893Sfeldman ilrint(unit)
3556893Sfeldman 	int unit;
3566893Sfeldman {
3576893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3586893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3596893Sfeldman 	register struct il_rheader *il;
3606893Sfeldman     	struct mbuf *m;
3616893Sfeldman 	int len, off, resid;
3626893Sfeldman 	register struct ifqueue *inq;
3636893Sfeldman 
3646893Sfeldman 	is->is_if.if_ipackets++;
3656893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3666893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3676893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3686893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3697261Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 || len > ILMTU) {
3706893Sfeldman 		is->is_if.if_ierrors++;
3716893Sfeldman #ifdef notdef
3726893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3736893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3746893Sfeldman #endif
3756893Sfeldman 		goto setup;
3766893Sfeldman 	}
3776893Sfeldman 
3786893Sfeldman 	/*
3796893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3806893Sfeldman 	 * get true type from first 16-bit word past data.
3816893Sfeldman 	 * Remember that type was trailer by setting off.
3826893Sfeldman 	 */
3836893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3846893Sfeldman 	if (il->ilr_type >= ILPUP_TRAIL &&
3856893Sfeldman 	    il->ilr_type < ILPUP_TRAIL+ILPUP_NTRAILER) {
3866893Sfeldman 		off = (il->ilr_type - ILPUP_TRAIL) * 512;
3876893Sfeldman 		if (off >= ILMTU)
3886893Sfeldman 			goto setup;		/* sanity */
3896893Sfeldman 		il->ilr_type = *ildataaddr(il, off, u_short *);
3906893Sfeldman 		resid = *(ildataaddr(il, off+2, u_short *));
3916893Sfeldman 		if (off + resid > len)
3926893Sfeldman 			goto setup;		/* sanity */
3936893Sfeldman 		len = off + resid;
3946893Sfeldman 	} else
3956893Sfeldman 		off = 0;
3966893Sfeldman 	if (len == 0)
3976893Sfeldman 		goto setup;
3986893Sfeldman 
3996893Sfeldman 	/*
4006893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4016893Sfeldman 	 * has trailing header; ilget will then force this header
4026893Sfeldman 	 * information to be at the front, but we still have to drop
4036893Sfeldman 	 * the type and length which are at the front of any trailer data.
4046893Sfeldman 	 */
4056893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4066893Sfeldman 	if (m == 0)
4076893Sfeldman 		goto setup;
4086893Sfeldman 	if (off) {
4096893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4106893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4116893Sfeldman 	}
4126893Sfeldman 	switch (il->ilr_type) {
4136893Sfeldman 
4146893Sfeldman #ifdef INET
4156893Sfeldman 	case ILPUP_IPTYPE:
4166893Sfeldman 		schednetisr(NETISR_IP);
4176893Sfeldman 		inq = &ipintrq;
4186893Sfeldman 		break;
4196893Sfeldman #endif
4206893Sfeldman 	default:
4216893Sfeldman 		m_freem(m);
4226893Sfeldman 		goto setup;
4236893Sfeldman 	}
4246893Sfeldman 
4256893Sfeldman 	if (IF_QFULL(inq)) {
4266893Sfeldman 		IF_DROP(inq);
4276893Sfeldman 		m_freem(m);
4287220Ssam 		goto setup;
4297220Ssam 	}
4307220Ssam 	IF_ENQUEUE(inq, m);
4316893Sfeldman 
4326893Sfeldman setup:
4336893Sfeldman 	/*
4346893Sfeldman 	 * Reset for next packet if possible.
4356893Sfeldman 	 * If waiting for transmit command completion, set flag
4366893Sfeldman 	 * and wait until command completes.
4376893Sfeldman 	 */
4387261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4397261Ssam 		is->is_flags |= ILF_RCVPENDING;
4407220Ssam 		return;
4417220Ssam 	}
4427220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4437220Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ILMTU + 6;
4447261Ssam 	addr->il_csr =
4457261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4467220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4477220Ssam 		;
4486893Sfeldman }
4496893Sfeldman 
4506893Sfeldman /*
4516893Sfeldman  * Ethernet output routine.
4526893Sfeldman  * Encapsulate a packet of type family for the local net.
4536893Sfeldman  * Use trailer local net encapsulation if enough data in first
4546893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4556893Sfeldman  */
4566893Sfeldman iloutput(ifp, m0, dst)
4576893Sfeldman 	struct ifnet *ifp;
4586893Sfeldman 	struct mbuf *m0;
4596893Sfeldman 	struct sockaddr *dst;
4606893Sfeldman {
4616893Sfeldman 	int type, dest, s, error;
4626893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4636893Sfeldman 	register struct mbuf *m = m0;
4646893Sfeldman 	register struct il_xheader *il;
4659179Ssam 	register int off;
4666893Sfeldman 
4676893Sfeldman 	switch (dst->sa_family) {
4686893Sfeldman 
4696893Sfeldman #ifdef INET
4706893Sfeldman 	case AF_INET:
4716893Sfeldman 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
4726893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4736893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4746893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4756893Sfeldman 			type = ILPUP_TRAIL + (off>>9);
4766893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4776893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4786893Sfeldman 			*mtod(m, u_short *) = ILPUP_IPTYPE;
4796893Sfeldman 			*(mtod(m, u_short *) + 1) = m->m_len;
4806893Sfeldman 			goto gottrailertype;
4816893Sfeldman 		}
4826893Sfeldman 		type = ILPUP_IPTYPE;
4836893Sfeldman 		off = 0;
4846893Sfeldman 		goto gottype;
4856893Sfeldman #endif
4866893Sfeldman 
4876893Sfeldman 	default:
4886893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
4896893Sfeldman 			dst->sa_family);
4906893Sfeldman 		error = EAFNOSUPPORT;
4916893Sfeldman 		goto bad;
4926893Sfeldman 	}
4936893Sfeldman 
4946893Sfeldman gottrailertype:
4956893Sfeldman 	/*
4966893Sfeldman 	 * Packet to be sent as trailer: move first packet
4976893Sfeldman 	 * (control information) to end of chain.
4986893Sfeldman 	 */
4996893Sfeldman 	while (m->m_next)
5006893Sfeldman 		m = m->m_next;
5016893Sfeldman 	m->m_next = m0;
5026893Sfeldman 	m = m0->m_next;
5036893Sfeldman 	m0->m_next = 0;
5046893Sfeldman 	m0 = m;
5056893Sfeldman 
5066893Sfeldman gottype:
5076893Sfeldman 	/*
5086893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5096893Sfeldman 	 * allocate another.
5106893Sfeldman 	 */
5116893Sfeldman 	if (m->m_off > MMAXOFF ||
5126893Sfeldman 	    MMINOFF + sizeof (struct il_xheader) > m->m_off) {
513*9650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5146893Sfeldman 		if (m == 0) {
5156893Sfeldman 			error = ENOBUFS;
5166893Sfeldman 			goto bad;
5176893Sfeldman 		}
5186893Sfeldman 		m->m_next = m0;
5196893Sfeldman 		m->m_off = MMINOFF;
5206893Sfeldman 		m->m_len = sizeof (struct il_xheader);
5216893Sfeldman 	} else {
5226893Sfeldman 		m->m_off -= sizeof (struct il_xheader);
5236893Sfeldman 		m->m_len += sizeof (struct il_xheader);
5246893Sfeldman 	}
5256893Sfeldman 	il = mtod(m, struct il_xheader *);
5266893Sfeldman 	if ((dest &~ 0xff) == 0)
5279179Ssam 		bcopy((caddr_t)ilbroadcastaddr, (caddr_t)il->ilx_dhost, 6);
5286893Sfeldman 	else {
5297261Ssam 		u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop;
5307220Ssam 
5319179Ssam 		bcopy((caddr_t)to, (caddr_t)il->ilx_dhost, 3);
5326893Sfeldman 		il->ilx_dhost[3] = (dest>>8) & 0x7f;
5336893Sfeldman 		il->ilx_dhost[4] = (dest>>16) & 0xff;
5346893Sfeldman 		il->ilx_dhost[5] = (dest>>24) & 0xff;
5356893Sfeldman 	}
5369179Ssam 	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)il->ilx_shost, 6);
5376893Sfeldman 	il->ilx_type = type;
5386893Sfeldman 
5396893Sfeldman 	/*
5406893Sfeldman 	 * Queue message on interface, and start output if interface
5416893Sfeldman 	 * not yet active.
5426893Sfeldman 	 */
5436893Sfeldman 	s = splimp();
5446893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5456893Sfeldman 		IF_DROP(&ifp->if_snd);
5467220Ssam 		splx(s);
5477220Ssam 		m_freem(m);
5487220Ssam 		return (ENOBUFS);
5496893Sfeldman 	}
5506893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5517261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5526893Sfeldman 		ilstart(ifp->if_unit);
5536893Sfeldman 	splx(s);
5546893Sfeldman 	return (0);
5557220Ssam 
5566893Sfeldman bad:
5576893Sfeldman 	m_freem(m0);
5587220Ssam 	return (error);
5596893Sfeldman }
5607261Ssam 
5617261Ssam /*
5627261Ssam  * Watchdog routine, request statistics from board.
5637261Ssam  */
5647261Ssam ilwatch(unit)
5657261Ssam 	int unit;
5667261Ssam {
5677261Ssam 	register struct il_softc *is = &il_softc[unit];
5687261Ssam 	register struct ifnet *ifp = &is->is_if;
5697261Ssam 	int s;
5707261Ssam 
5717261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5727261Ssam 		ifp->if_timer = is->is_scaninterval;
5737261Ssam 		return;
5747261Ssam 	}
5757261Ssam 	s = splimp();
5767261Ssam 	is->is_flags |= ILF_STATPENDING;
5777261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5787261Ssam 		ilstart(ifp->if_unit);
5797261Ssam 	splx(s);
5807261Ssam 	ifp->if_timer = is->is_scaninterval;
5817261Ssam }
5827261Ssam 
5837261Ssam /*
5847261Ssam  * Total up the on-board statistics.
5857261Ssam  */
5867261Ssam iltotal(is)
5877261Ssam 	register struct il_softc *is;
5887261Ssam {
5897261Ssam 	register u_short *interval, *sum, *end;
5907261Ssam 
5917261Ssam 	interval = &is->is_stats.ils_frames;
5927261Ssam 	sum = &is->is_sum.ils_frames;
5937261Ssam 	end = is->is_sum.ils_fill2;
5947261Ssam 	while (sum < end)
5957261Ssam 		*sum++ += *interval++;
5967261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
5977261Ssam }
598