xref: /csrg-svn/sys/vax/if/if_il.c (revision 12773)
1*12773Ssam /*	if_il.c	4.20	83/05/27	*/
26893Sfeldman 
36893Sfeldman #include "il.h"
46893Sfeldman 
56893Sfeldman /*
66893Sfeldman  * Interlan Ethernet Communications Controller interface
76893Sfeldman  */
89797Ssam #include "../machine/pte.h"
99797Ssam 
106893Sfeldman #include "../h/param.h"
116893Sfeldman #include "../h/systm.h"
126893Sfeldman #include "../h/mbuf.h"
136893Sfeldman #include "../h/buf.h"
146893Sfeldman #include "../h/protosw.h"
156893Sfeldman #include "../h/socket.h"
166893Sfeldman #include "../h/vmmac.h"
178463Sroot #include <errno.h>
188463Sroot 
198463Sroot #include "../net/if.h"
208463Sroot #include "../net/netisr.h"
218463Sroot #include "../net/route.h"
228419Swnj #include "../netinet/in.h"
238419Swnj #include "../netinet/in_systm.h"
248419Swnj #include "../netinet/ip.h"
258419Swnj #include "../netinet/ip_var.h"
2611575Ssam #include "../netinet/if_ether.h"
278419Swnj #include "../netpup/pup.h"
286893Sfeldman 
298463Sroot #include "../vax/cpu.h"
308463Sroot #include "../vax/mtpr.h"
319746Ssam #include "../vaxif/if_il.h"
328463Sroot #include "../vaxif/if_ilreg.h"
338463Sroot #include "../vaxif/if_uba.h"
348463Sroot #include "../vaxuba/ubareg.h"
358463Sroot #include "../vaxuba/ubavar.h"
368463Sroot 
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 
456893Sfeldman /*
466893Sfeldman  * Ethernet software status per interface.
476893Sfeldman  *
486893Sfeldman  * Each interface is referenced by a network interface structure,
496893Sfeldman  * is_if, which the routing code uses to locate the interface.
506893Sfeldman  * This structure contains the output queue for the interface, its address, ...
516893Sfeldman  * We also have, for each interface, a UBA interface structure, which
526893Sfeldman  * contains information about the UNIBUS resources held by the interface:
536893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
546893Sfeldman  * structure for use by the if_uba.c routines in running the interface
556893Sfeldman  * efficiently.
566893Sfeldman  */
576893Sfeldman struct	il_softc {
5811575Ssam 	struct	arpcom is_ac;		/* Ethernet common part */
5911575Ssam #define	is_if	is_ac.ac_if		/* network-visible interface */
6011575Ssam #define	is_addr	is_ac.ac_enaddr		/* hardware Ethernet address */
616893Sfeldman 	struct	ifuba is_ifuba;		/* UNIBUS resources */
627261Ssam 	int	is_flags;
637261Ssam #define	ILF_OACTIVE	0x1		/* output is active */
647261Ssam #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
657261Ssam #define	ILF_STATPENDING	0x4		/* stat cmd pending */
667261Ssam 	short	is_lastcmd;		/* can't read csr, so must save it */
677261Ssam 	short	is_scaninterval;	/* interval of stat collection */
687261Ssam #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
697261Ssam 	struct	il_stats is_stats;	/* holds on-board statistics */
707261Ssam 	struct	il_stats is_sum;	/* summation over time */
717261Ssam 	int	is_ubaddr;		/* mapping registers of is_stats */
726893Sfeldman } il_softc[NIL];
736893Sfeldman 
746893Sfeldman ilprobe(reg)
756893Sfeldman 	caddr_t reg;
766893Sfeldman {
776893Sfeldman 	register int br, cvec;		/* r11, r10 value-result */
786893Sfeldman 	register struct ildevice *addr = (struct ildevice *)reg;
796893Sfeldman 	register i;
806893Sfeldman 
816893Sfeldman #ifdef lint
826893Sfeldman 	br = 0; cvec = br; br = cvec;
839179Ssam 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
846893Sfeldman #endif
856893Sfeldman 
866893Sfeldman 	addr->il_csr = ILC_OFFLINE|IL_CIE;
876893Sfeldman 	DELAY(100000);
887261Ssam 	i = addr->il_csr;		/* clear CDONE */
896893Sfeldman 	if (cvec > 0 && cvec != 0x200)
906893Sfeldman 		cvec -= 4;
916893Sfeldman 	return (1);
926893Sfeldman }
936893Sfeldman 
946893Sfeldman /*
956893Sfeldman  * Interface exists: make available by filling in network interface
966893Sfeldman  * record.  System will initialize the interface when it is ready
976893Sfeldman  * to accept packets.  A STATUS command is done to get the ethernet
986893Sfeldman  * address and other interesting data.
996893Sfeldman  */
1006893Sfeldman ilattach(ui)
1016893Sfeldman 	struct uba_device *ui;
1026893Sfeldman {
1036893Sfeldman 	register struct il_softc *is = &il_softc[ui->ui_unit];
1047220Ssam 	register struct ifnet *ifp = &is->is_if;
1056893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
1067220Ssam 	struct sockaddr_in *sin;
1076893Sfeldman 
1087220Ssam 	ifp->if_unit = ui->ui_unit;
1097220Ssam 	ifp->if_name = "il";
1109746Ssam 	ifp->if_mtu = ETHERMTU;
1116893Sfeldman 
1126893Sfeldman 	/*
1137261Ssam 	 * Reset the board and map the statistics
1147261Ssam 	 * buffer onto the Unibus.
1156893Sfeldman 	 */
1167261Ssam 	addr->il_csr = ILC_RESET;
1177261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1187261Ssam 		;
1197261Ssam 	if (addr->il_csr&IL_STATUS)
1207261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1217261Ssam 			addr->il_csr, IL_BITS);
1226893Sfeldman 
1239179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
1247261Ssam 		sizeof (struct il_stats), 0);
1257261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1267261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1277261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1287261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1297261Ssam 		;
1307261Ssam 	if (addr->il_csr&IL_STATUS)
1317261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1327261Ssam 			addr->il_csr, IL_BITS);
1337261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
13411575Ssam #ifdef notdef
1356893Sfeldman 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
1366893Sfeldman 		ui->ui_unit,
1377261Ssam 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
1387261Ssam 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
1397261Ssam 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
1407261Ssam 		is->is_stats.ils_module, is->is_stats.ils_firmware);
14111575Ssam #endif
142*12773Ssam 	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr,
143*12773Ssam 	    sizeof (is->is_addr));
1447220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1456893Sfeldman 	sin->sin_family = AF_INET;
146*12773Ssam 	sin->sin_addr = arpmyaddr((struct arpcom *)0);
1477220Ssam 	ifp->if_init = ilinit;
1487220Ssam 	ifp->if_output = iloutput;
1498979Sroot 	ifp->if_reset = ilreset;
1507261Ssam 	ifp->if_watchdog = ilwatch;
1517261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1527261Ssam 	ifp->if_timer = is->is_scaninterval;
1536893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1547220Ssam #ifdef notdef
1557220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1567220Ssam #endif
1577220Ssam 	if_attach(ifp);
1586893Sfeldman }
1596893Sfeldman 
1606893Sfeldman /*
1616893Sfeldman  * Reset of interface after UNIBUS reset.
1626893Sfeldman  * If interface is on specified uba, reset its state.
1636893Sfeldman  */
1646893Sfeldman ilreset(unit, uban)
1656893Sfeldman 	int unit, uban;
1666893Sfeldman {
1676893Sfeldman 	register struct uba_device *ui;
1686893Sfeldman 
1696893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1706893Sfeldman 	    ui->ui_ubanum != uban)
1716893Sfeldman 		return;
1726893Sfeldman 	printf(" il%d", unit);
1736893Sfeldman 	ilinit(unit);
1746893Sfeldman }
1756893Sfeldman 
1766893Sfeldman /*
1776893Sfeldman  * Initialization of interface; clear recorded pending
1786893Sfeldman  * operations, and reinitialize UNIBUS usage.
1796893Sfeldman  */
1806893Sfeldman ilinit(unit)
1816893Sfeldman 	int unit;
1826893Sfeldman {
1836893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1846893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1856893Sfeldman 	register struct ildevice *addr;
1867261Ssam 	int s;
18711575Ssam 	register struct ifnet *ifp = &is->is_if;
18811575Ssam 	register struct sockaddr_in *sin, *sinb;
1896893Sfeldman 
19011575Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
19111575Ssam 	if (sin->sin_addr.s_addr == 0)	/* if address still unknown */
19211575Ssam 		return;
19311575Ssam 	ifp->if_net = in_netof(sin->sin_addr);
19411575Ssam 	ifp->if_host[0] = in_lnaof(sin->sin_addr);
19511575Ssam 	sinb = (struct sockaddr_in *)&ifp->if_broadaddr;
19611575Ssam 	sinb->sin_family = AF_INET;
19711575Ssam 	sinb->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
19811575Ssam 	ifp->if_flags = IFF_BROADCAST;
19911575Ssam 
2006893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
2019746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
2026893Sfeldman 		printf("il%d: can't initialize\n", unit);
2036893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2046893Sfeldman 		return;
2056893Sfeldman 	}
2069179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
2077261Ssam 		sizeof (struct il_stats), 0);
2086893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2096893Sfeldman 
2106893Sfeldman 	/*
2119179Ssam 	 * Turn off source address insertion (it's faster this way),
21212488Ssam 	 * and set board online.  Former doesn't work if board is
21312488Ssam 	 * already online (happens on ubareset), so we put it offline
21412488Ssam 	 * first.
2159179Ssam 	 */
2169179Ssam 	s = splimp();
21712488Ssam 	addr->il_csr = ILC_OFFLINE;
2189179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2199179Ssam 		;
22012488Ssam 	addr->il_csr = ILC_CISA;
2219179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2229179Ssam 		;
2239179Ssam 	/*
2246893Sfeldman 	 * Set board online.
2256893Sfeldman 	 * Hang receive buffer and start any pending
2266893Sfeldman 	 * writes by faking a transmit complete.
2276893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2286893Sfeldman 	 * chaining can't happen.
2296893Sfeldman 	 */
2306893Sfeldman 	addr->il_csr = ILC_ONLINE;
2317220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2327220Ssam 		;
2336893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2349746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
2357261Ssam 	addr->il_csr =
2367261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2377220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2387220Ssam 		;
2397261Ssam 	is->is_flags = ILF_OACTIVE;
2406893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2417261Ssam 	is->is_lastcmd = 0;
2426893Sfeldman 	ilcint(unit);
2436893Sfeldman 	splx(s);
2447152Swnj 	if_rtinit(&is->is_if, RTF_UP);
24511575Ssam 	arpattach(&is->is_ac);
24611575Ssam 	arpwhohas(&is->is_ac, &sin->sin_addr);
2476893Sfeldman }
2486893Sfeldman 
2496893Sfeldman /*
2506893Sfeldman  * Start output on interface.
2516893Sfeldman  * Get another datagram to send off of the interface queue,
2526893Sfeldman  * and map it to the interface before starting the output.
2536893Sfeldman  */
2546893Sfeldman ilstart(dev)
2556893Sfeldman 	dev_t dev;
2566893Sfeldman {
2579179Ssam         int unit = ILUNIT(dev), len;
2586893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2596893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2606893Sfeldman 	register struct ildevice *addr;
2616893Sfeldman 	struct mbuf *m;
2627220Ssam 	short csr;
2636893Sfeldman 
2646893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2657261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2667261Ssam 	if (m == 0) {
2677261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2687261Ssam 			return;
2699179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2707261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2717261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2727261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2737261Ssam 		goto startcmd;
2747261Ssam 	}
2756893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2769179Ssam 	/*
2779179Ssam 	 * Ensure minimum packet length.
2789179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2799179Ssam 	 * after the data.
2809179Ssam 	 * For security, it might be wise to zero out the added bytes,
2819179Ssam 	 * but we're mainly interested in speed at the moment.
2829179Ssam 	 */
2839746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2849746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
2856893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2866893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2876893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2886893Sfeldman 	addr->il_bcr = len;
2897261Ssam 	csr =
2907261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2917261Ssam 
2927261Ssam startcmd:
2937261Ssam 	is->is_lastcmd = csr & IL_CMD;
2947220Ssam 	addr->il_csr = csr;
2957261Ssam 	is->is_flags |= ILF_OACTIVE;
2966893Sfeldman }
2976893Sfeldman 
2986893Sfeldman /*
2996893Sfeldman  * Command done interrupt.
3006893Sfeldman  */
3016893Sfeldman ilcint(unit)
3026893Sfeldman 	int unit;
3036893Sfeldman {
3046893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3057220Ssam 	struct uba_device *ui = ilinfo[unit];
3066893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
3077266Ssam 	short csr;
3086893Sfeldman 
3097261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3107220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3117261Ssam 			addr->il_csr, IL_BITS);
3126893Sfeldman 		return;
3136893Sfeldman 	}
3147220Ssam 
3157266Ssam 	csr = addr->il_csr;
3166893Sfeldman 	/*
3177261Ssam 	 * Hang receive buffer if it couldn't
3187261Ssam 	 * be done earlier (in ilrint).
3196893Sfeldman 	 */
3207261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3216893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3229746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
3237261Ssam 		addr->il_csr =
3247261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3257220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3267220Ssam 			;
3277261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3286893Sfeldman 	}
3297261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3307266Ssam 	csr &= IL_STATUS;
3317261Ssam 	switch (is->is_lastcmd) {
3327261Ssam 
3337261Ssam 	case ILC_XMIT:
3347261Ssam 		is->is_if.if_opackets++;
3357266Ssam 		if (csr > ILERR_RETRIES)
3367261Ssam 			is->is_if.if_oerrors++;
3377261Ssam 		break;
3387261Ssam 
3397261Ssam 	case ILC_STAT:
3407266Ssam 		if (csr == ILERR_SUCCESS)
3417261Ssam 			iltotal(is);
3427261Ssam 		break;
3437261Ssam 	}
3446893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3456893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3466893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3476893Sfeldman 	}
3487261Ssam 	ilstart(unit);
3496893Sfeldman }
3506893Sfeldman 
3516893Sfeldman /*
3526893Sfeldman  * Ethernet interface receiver interrupt.
3536893Sfeldman  * If input error just drop packet.
3546893Sfeldman  * Otherwise purge input buffered data path and examine
3556893Sfeldman  * packet to determine type.  If can't determine length
3566893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3576893Sfeldman  * packet based on type and pass to type specific higher-level
3586893Sfeldman  * input routine.
3596893Sfeldman  */
3606893Sfeldman ilrint(unit)
3616893Sfeldman 	int unit;
3626893Sfeldman {
3636893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3646893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3656893Sfeldman 	register struct il_rheader *il;
3666893Sfeldman     	struct mbuf *m;
3676893Sfeldman 	int len, off, resid;
3686893Sfeldman 	register struct ifqueue *inq;
3696893Sfeldman 
3706893Sfeldman 	is->is_if.if_ipackets++;
3716893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3726893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3736893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3746893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3759746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3769746Ssam 	    len > ETHERMTU) {
3776893Sfeldman 		is->is_if.if_ierrors++;
3786893Sfeldman #ifdef notdef
3796893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3806893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3816893Sfeldman #endif
3826893Sfeldman 		goto setup;
3836893Sfeldman 	}
3846893Sfeldman 
3856893Sfeldman 	/*
3866893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3876893Sfeldman 	 * get true type from first 16-bit word past data.
3886893Sfeldman 	 * Remember that type was trailer by setting off.
3896893Sfeldman 	 */
3909746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3916893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3929746Ssam 	if (il->ilr_type >= ETHERPUP_TRAIL &&
3939746Ssam 	    il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) {
3949746Ssam 		off = (il->ilr_type - ETHERPUP_TRAIL) * 512;
3959746Ssam 		if (off >= ETHERMTU)
3966893Sfeldman 			goto setup;		/* sanity */
3979746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
3989746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
3996893Sfeldman 		if (off + resid > len)
4006893Sfeldman 			goto setup;		/* sanity */
4016893Sfeldman 		len = off + resid;
4026893Sfeldman 	} else
4036893Sfeldman 		off = 0;
4046893Sfeldman 	if (len == 0)
4056893Sfeldman 		goto setup;
4066893Sfeldman 
4076893Sfeldman 	/*
4086893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4096893Sfeldman 	 * has trailing header; ilget will then force this header
4106893Sfeldman 	 * information to be at the front, but we still have to drop
4116893Sfeldman 	 * the type and length which are at the front of any trailer data.
4126893Sfeldman 	 */
4136893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4146893Sfeldman 	if (m == 0)
4156893Sfeldman 		goto setup;
4166893Sfeldman 	if (off) {
4176893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4186893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4196893Sfeldman 	}
4206893Sfeldman 	switch (il->ilr_type) {
4216893Sfeldman 
4226893Sfeldman #ifdef INET
4239746Ssam 	case ETHERPUP_IPTYPE:
4246893Sfeldman 		schednetisr(NETISR_IP);
4256893Sfeldman 		inq = &ipintrq;
4266893Sfeldman 		break;
42711575Ssam 
42811575Ssam 	case ETHERPUP_ARPTYPE:
42911575Ssam 		arpinput(&is->is_ac, m);
43011575Ssam 		return;
4316893Sfeldman #endif
4326893Sfeldman 	default:
4336893Sfeldman 		m_freem(m);
4346893Sfeldman 		goto setup;
4356893Sfeldman 	}
4366893Sfeldman 
4376893Sfeldman 	if (IF_QFULL(inq)) {
4386893Sfeldman 		IF_DROP(inq);
4396893Sfeldman 		m_freem(m);
4407220Ssam 		goto setup;
4417220Ssam 	}
4427220Ssam 	IF_ENQUEUE(inq, m);
4436893Sfeldman 
4446893Sfeldman setup:
4456893Sfeldman 	/*
4466893Sfeldman 	 * Reset for next packet if possible.
4476893Sfeldman 	 * If waiting for transmit command completion, set flag
4486893Sfeldman 	 * and wait until command completes.
4496893Sfeldman 	 */
4507261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4517261Ssam 		is->is_flags |= ILF_RCVPENDING;
4527220Ssam 		return;
4537220Ssam 	}
4547220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4559746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4567261Ssam 	addr->il_csr =
4577261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4587220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4597220Ssam 		;
4606893Sfeldman }
4616893Sfeldman 
4626893Sfeldman /*
4636893Sfeldman  * Ethernet output routine.
4646893Sfeldman  * Encapsulate a packet of type family for the local net.
4656893Sfeldman  * Use trailer local net encapsulation if enough data in first
4666893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4676893Sfeldman  */
4686893Sfeldman iloutput(ifp, m0, dst)
4696893Sfeldman 	struct ifnet *ifp;
4706893Sfeldman 	struct mbuf *m0;
4716893Sfeldman 	struct sockaddr *dst;
4726893Sfeldman {
47311575Ssam 	int type, s, error;
47411575Ssam 	u_char edst[6];
47511575Ssam 	struct in_addr idst;
4766893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4776893Sfeldman 	register struct mbuf *m = m0;
4789746Ssam 	register struct ether_header *il;
4799179Ssam 	register int off;
4806893Sfeldman 
4816893Sfeldman 	switch (dst->sa_family) {
4826893Sfeldman 
4836893Sfeldman #ifdef INET
4846893Sfeldman 	case AF_INET:
48511575Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
48611575Ssam 		if (!arpresolve(&is->is_ac, m, &idst, edst))
48711575Ssam 			return (0);	/* if not yet resolved */
4886893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4896893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4906893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4919746Ssam 			type = ETHERPUP_TRAIL + (off>>9);
4926893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4936893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4949746Ssam 			*mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE);
4959746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4966893Sfeldman 			goto gottrailertype;
4976893Sfeldman 		}
4989746Ssam 		type = ETHERPUP_IPTYPE;
4996893Sfeldman 		off = 0;
5006893Sfeldman 		goto gottype;
5016893Sfeldman #endif
5026893Sfeldman 
50311575Ssam 	case AF_UNSPEC:
50411575Ssam 		il = (struct ether_header *)dst->sa_data;
505*12773Ssam 		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
50611575Ssam 		type = il->ether_type;
50711575Ssam 		goto gottype;
50811575Ssam 
5096893Sfeldman 	default:
5106893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5116893Sfeldman 			dst->sa_family);
5126893Sfeldman 		error = EAFNOSUPPORT;
5136893Sfeldman 		goto bad;
5146893Sfeldman 	}
5156893Sfeldman 
5166893Sfeldman gottrailertype:
5176893Sfeldman 	/*
5186893Sfeldman 	 * Packet to be sent as trailer: move first packet
5196893Sfeldman 	 * (control information) to end of chain.
5206893Sfeldman 	 */
5216893Sfeldman 	while (m->m_next)
5226893Sfeldman 		m = m->m_next;
5236893Sfeldman 	m->m_next = m0;
5246893Sfeldman 	m = m0->m_next;
5256893Sfeldman 	m0->m_next = 0;
5266893Sfeldman 	m0 = m;
5276893Sfeldman 
5286893Sfeldman gottype:
5296893Sfeldman 	/*
5306893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5316893Sfeldman 	 * allocate another.
5326893Sfeldman 	 */
5336893Sfeldman 	if (m->m_off > MMAXOFF ||
5349746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5359650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5366893Sfeldman 		if (m == 0) {
5376893Sfeldman 			error = ENOBUFS;
5386893Sfeldman 			goto bad;
5396893Sfeldman 		}
5406893Sfeldman 		m->m_next = m0;
5416893Sfeldman 		m->m_off = MMINOFF;
5429746Ssam 		m->m_len = sizeof (struct ether_header);
5436893Sfeldman 	} else {
5449746Ssam 		m->m_off -= sizeof (struct ether_header);
5459746Ssam 		m->m_len += sizeof (struct ether_header);
5466893Sfeldman 	}
5479746Ssam 	il = mtod(m, struct ether_header *);
5489746Ssam 	il->ether_type = htons((u_short)type);
549*12773Ssam 	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
55011575Ssam 	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 6);
5516893Sfeldman 
5526893Sfeldman 	/*
5536893Sfeldman 	 * Queue message on interface, and start output if interface
5546893Sfeldman 	 * not yet active.
5556893Sfeldman 	 */
5566893Sfeldman 	s = splimp();
5576893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5586893Sfeldman 		IF_DROP(&ifp->if_snd);
5597220Ssam 		splx(s);
5607220Ssam 		m_freem(m);
5617220Ssam 		return (ENOBUFS);
5626893Sfeldman 	}
5636893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5647261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5656893Sfeldman 		ilstart(ifp->if_unit);
5666893Sfeldman 	splx(s);
5676893Sfeldman 	return (0);
5687220Ssam 
5696893Sfeldman bad:
5706893Sfeldman 	m_freem(m0);
5717220Ssam 	return (error);
5726893Sfeldman }
5737261Ssam 
5747261Ssam /*
5757261Ssam  * Watchdog routine, request statistics from board.
5767261Ssam  */
5777261Ssam ilwatch(unit)
5787261Ssam 	int unit;
5797261Ssam {
5807261Ssam 	register struct il_softc *is = &il_softc[unit];
5817261Ssam 	register struct ifnet *ifp = &is->is_if;
5827261Ssam 	int s;
5837261Ssam 
5847261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5857261Ssam 		ifp->if_timer = is->is_scaninterval;
5867261Ssam 		return;
5877261Ssam 	}
5887261Ssam 	s = splimp();
5897261Ssam 	is->is_flags |= ILF_STATPENDING;
5907261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5917261Ssam 		ilstart(ifp->if_unit);
5927261Ssam 	splx(s);
5937261Ssam 	ifp->if_timer = is->is_scaninterval;
5947261Ssam }
5957261Ssam 
5967261Ssam /*
5977261Ssam  * Total up the on-board statistics.
5987261Ssam  */
5997261Ssam iltotal(is)
6007261Ssam 	register struct il_softc *is;
6017261Ssam {
6027261Ssam 	register u_short *interval, *sum, *end;
6037261Ssam 
6047261Ssam 	interval = &is->is_stats.ils_frames;
6057261Ssam 	sum = &is->is_sum.ils_frames;
6067261Ssam 	end = is->is_sum.ils_fill2;
6077261Ssam 	while (sum < end)
6087261Ssam 		*sum++ += *interval++;
6097261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6107261Ssam }
611