xref: /csrg-svn/sys/vax/if/if_il.c (revision 11575)
1*11575Ssam /*	if_il.c	4.18	83/03/15	*/
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"
26*11575Ssam #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 {
58*11575Ssam 	struct	arpcom is_ac;		/* Ethernet common part */
59*11575Ssam #define	is_if	is_ac.ac_if		/* network-visible interface */
60*11575Ssam #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);
134*11575Ssam #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);
141*11575Ssam #endif
142*11575Ssam 	bcopy(is->is_stats.ils_addr, is->is_addr, sizeof (is->is_addr));
1437220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1446893Sfeldman 	sin->sin_family = AF_INET;
145*11575Ssam 	if (ui->ui_flags) {
146*11575Ssam 		int i = ((is->is_addr[3]&0xff)<<16) |
147*11575Ssam 		    ((is->is_addr[4]&0xff)<<8) |
148*11575Ssam 		    (is->is_addr[5]&0xff);
149*11575Ssam 		sin->sin_addr = if_makeaddr(ui->ui_flags, i);
150*11575Ssam 	} else
151*11575Ssam 		sin->sin_addr = arpmyaddr();
1526893Sfeldman 
1537220Ssam 	ifp->if_init = ilinit;
1547220Ssam 	ifp->if_output = iloutput;
1558979Sroot 	ifp->if_reset = ilreset;
1567261Ssam 	ifp->if_watchdog = ilwatch;
1577261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1587261Ssam 	ifp->if_timer = is->is_scaninterval;
1596893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1607220Ssam #ifdef notdef
1617220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1627220Ssam #endif
1637220Ssam 	if_attach(ifp);
1646893Sfeldman }
1656893Sfeldman 
1666893Sfeldman /*
1676893Sfeldman  * Reset of interface after UNIBUS reset.
1686893Sfeldman  * If interface is on specified uba, reset its state.
1696893Sfeldman  */
1706893Sfeldman ilreset(unit, uban)
1716893Sfeldman 	int unit, uban;
1726893Sfeldman {
1736893Sfeldman 	register struct uba_device *ui;
1746893Sfeldman 
1756893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1766893Sfeldman 	    ui->ui_ubanum != uban)
1776893Sfeldman 		return;
1786893Sfeldman 	printf(" il%d", unit);
1796893Sfeldman 	ilinit(unit);
1806893Sfeldman }
1816893Sfeldman 
1826893Sfeldman /*
1836893Sfeldman  * Initialization of interface; clear recorded pending
1846893Sfeldman  * operations, and reinitialize UNIBUS usage.
1856893Sfeldman  */
1866893Sfeldman ilinit(unit)
1876893Sfeldman 	int unit;
1886893Sfeldman {
1896893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1906893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1916893Sfeldman 	register struct ildevice *addr;
1927261Ssam 	int s;
193*11575Ssam 	register struct ifnet *ifp = &is->is_if;
194*11575Ssam 	register struct sockaddr_in *sin, *sinb;
1956893Sfeldman 
196*11575Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
197*11575Ssam 	if (sin->sin_addr.s_addr == 0)	/* if address still unknown */
198*11575Ssam 		return;
199*11575Ssam 	ifp->if_net = in_netof(sin->sin_addr);
200*11575Ssam 	ifp->if_host[0] = in_lnaof(sin->sin_addr);
201*11575Ssam 	sinb = (struct sockaddr_in *)&ifp->if_broadaddr;
202*11575Ssam 	sinb->sin_family = AF_INET;
203*11575Ssam 	sinb->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
204*11575Ssam 	ifp->if_flags = IFF_BROADCAST;
205*11575Ssam 
2066893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
2079746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
2086893Sfeldman 		printf("il%d: can't initialize\n", unit);
2096893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2106893Sfeldman 		return;
2116893Sfeldman 	}
2129179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
2137261Ssam 		sizeof (struct il_stats), 0);
2146893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2156893Sfeldman 
2166893Sfeldman 	/*
2179179Ssam 	 * Turn off source address insertion (it's faster this way),
2189179Ssam 	 * and set board online.
2199179Ssam 	 */
2209179Ssam 	s = splimp();
2219179Ssam 	addr->il_csr = ILC_CISA;
2229179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2239179Ssam 		;
2249179Ssam 	addr->il_csr = ILC_ONLINE;
2259179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2269179Ssam 		;
2279179Ssam 	/*
2286893Sfeldman 	 * Set board online.
2296893Sfeldman 	 * Hang receive buffer and start any pending
2306893Sfeldman 	 * writes by faking a transmit complete.
2316893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2326893Sfeldman 	 * chaining can't happen.
2336893Sfeldman 	 */
2346893Sfeldman 	s = splimp();
2356893Sfeldman 	addr->il_csr = ILC_ONLINE;
2367220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2377220Ssam 		;
2386893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2399746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
2407261Ssam 	addr->il_csr =
2417261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2427220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2437220Ssam 		;
2447261Ssam 	is->is_flags = ILF_OACTIVE;
2456893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2467261Ssam 	is->is_lastcmd = 0;
2476893Sfeldman 	ilcint(unit);
2486893Sfeldman 	splx(s);
2497152Swnj 	if_rtinit(&is->is_if, RTF_UP);
250*11575Ssam 	arpattach(&is->is_ac);
251*11575Ssam 	arpwhohas(&is->is_ac, &sin->sin_addr);
2526893Sfeldman }
2536893Sfeldman 
2546893Sfeldman /*
2556893Sfeldman  * Start output on interface.
2566893Sfeldman  * Get another datagram to send off of the interface queue,
2576893Sfeldman  * and map it to the interface before starting the output.
2586893Sfeldman  */
2596893Sfeldman ilstart(dev)
2606893Sfeldman 	dev_t dev;
2616893Sfeldman {
2629179Ssam         int unit = ILUNIT(dev), len;
2636893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2646893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2656893Sfeldman 	register struct ildevice *addr;
2666893Sfeldman 	struct mbuf *m;
2677220Ssam 	short csr;
2686893Sfeldman 
2696893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2707261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2717261Ssam 	if (m == 0) {
2727261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2737261Ssam 			return;
2749179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2757261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2767261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2777261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2787261Ssam 		goto startcmd;
2797261Ssam 	}
2806893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2819179Ssam 	/*
2829179Ssam 	 * Ensure minimum packet length.
2839179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2849179Ssam 	 * after the data.
2859179Ssam 	 * For security, it might be wise to zero out the added bytes,
2869179Ssam 	 * but we're mainly interested in speed at the moment.
2879179Ssam 	 */
2889746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2899746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
2906893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2916893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2926893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2936893Sfeldman 	addr->il_bcr = len;
2947261Ssam 	csr =
2957261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2967261Ssam 
2977261Ssam startcmd:
2987261Ssam 	is->is_lastcmd = csr & IL_CMD;
2997220Ssam 	addr->il_csr = csr;
3007261Ssam 	is->is_flags |= ILF_OACTIVE;
3016893Sfeldman }
3026893Sfeldman 
3036893Sfeldman /*
3046893Sfeldman  * Command done interrupt.
3056893Sfeldman  */
3066893Sfeldman ilcint(unit)
3076893Sfeldman 	int unit;
3086893Sfeldman {
3096893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3107220Ssam 	struct uba_device *ui = ilinfo[unit];
3116893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
3127266Ssam 	short csr;
3136893Sfeldman 
3147261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3157220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3167261Ssam 			addr->il_csr, IL_BITS);
3176893Sfeldman 		return;
3186893Sfeldman 	}
3197220Ssam 
3207266Ssam 	csr = addr->il_csr;
3216893Sfeldman 	/*
3227261Ssam 	 * Hang receive buffer if it couldn't
3237261Ssam 	 * be done earlier (in ilrint).
3246893Sfeldman 	 */
3257261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3266893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3279746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
3287261Ssam 		addr->il_csr =
3297261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3307220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3317220Ssam 			;
3327261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3336893Sfeldman 	}
3347261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3357266Ssam 	csr &= IL_STATUS;
3367261Ssam 	switch (is->is_lastcmd) {
3377261Ssam 
3387261Ssam 	case ILC_XMIT:
3397261Ssam 		is->is_if.if_opackets++;
3407266Ssam 		if (csr > ILERR_RETRIES)
3417261Ssam 			is->is_if.if_oerrors++;
3427261Ssam 		break;
3437261Ssam 
3447261Ssam 	case ILC_STAT:
3457266Ssam 		if (csr == ILERR_SUCCESS)
3467261Ssam 			iltotal(is);
3477261Ssam 		break;
3487261Ssam 	}
3496893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3506893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3516893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3526893Sfeldman 	}
3537261Ssam 	ilstart(unit);
3546893Sfeldman }
3556893Sfeldman 
3566893Sfeldman /*
3576893Sfeldman  * Ethernet interface receiver interrupt.
3586893Sfeldman  * If input error just drop packet.
3596893Sfeldman  * Otherwise purge input buffered data path and examine
3606893Sfeldman  * packet to determine type.  If can't determine length
3616893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3626893Sfeldman  * packet based on type and pass to type specific higher-level
3636893Sfeldman  * input routine.
3646893Sfeldman  */
3656893Sfeldman ilrint(unit)
3666893Sfeldman 	int unit;
3676893Sfeldman {
3686893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3696893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3706893Sfeldman 	register struct il_rheader *il;
3716893Sfeldman     	struct mbuf *m;
3726893Sfeldman 	int len, off, resid;
3736893Sfeldman 	register struct ifqueue *inq;
3746893Sfeldman 
3756893Sfeldman 	is->is_if.if_ipackets++;
3766893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3776893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3786893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3796893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3809746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3819746Ssam 	    len > ETHERMTU) {
3826893Sfeldman 		is->is_if.if_ierrors++;
3836893Sfeldman #ifdef notdef
3846893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3856893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3866893Sfeldman #endif
3876893Sfeldman 		goto setup;
3886893Sfeldman 	}
3896893Sfeldman 
3906893Sfeldman 	/*
3916893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3926893Sfeldman 	 * get true type from first 16-bit word past data.
3936893Sfeldman 	 * Remember that type was trailer by setting off.
3946893Sfeldman 	 */
3959746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3966893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3979746Ssam 	if (il->ilr_type >= ETHERPUP_TRAIL &&
3989746Ssam 	    il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) {
3999746Ssam 		off = (il->ilr_type - ETHERPUP_TRAIL) * 512;
4009746Ssam 		if (off >= ETHERMTU)
4016893Sfeldman 			goto setup;		/* sanity */
4029746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
4039746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
4046893Sfeldman 		if (off + resid > len)
4056893Sfeldman 			goto setup;		/* sanity */
4066893Sfeldman 		len = off + resid;
4076893Sfeldman 	} else
4086893Sfeldman 		off = 0;
4096893Sfeldman 	if (len == 0)
4106893Sfeldman 		goto setup;
4116893Sfeldman 
4126893Sfeldman 	/*
4136893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4146893Sfeldman 	 * has trailing header; ilget will then force this header
4156893Sfeldman 	 * information to be at the front, but we still have to drop
4166893Sfeldman 	 * the type and length which are at the front of any trailer data.
4176893Sfeldman 	 */
4186893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4196893Sfeldman 	if (m == 0)
4206893Sfeldman 		goto setup;
4216893Sfeldman 	if (off) {
4226893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4236893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4246893Sfeldman 	}
4256893Sfeldman 	switch (il->ilr_type) {
4266893Sfeldman 
4276893Sfeldman #ifdef INET
4289746Ssam 	case ETHERPUP_IPTYPE:
4296893Sfeldman 		schednetisr(NETISR_IP);
4306893Sfeldman 		inq = &ipintrq;
4316893Sfeldman 		break;
432*11575Ssam 
433*11575Ssam 	case ETHERPUP_ARPTYPE:
434*11575Ssam 		arpinput(&is->is_ac, m);
435*11575Ssam 		return;
4366893Sfeldman #endif
4376893Sfeldman 	default:
4386893Sfeldman 		m_freem(m);
4396893Sfeldman 		goto setup;
4406893Sfeldman 	}
4416893Sfeldman 
4426893Sfeldman 	if (IF_QFULL(inq)) {
4436893Sfeldman 		IF_DROP(inq);
4446893Sfeldman 		m_freem(m);
4457220Ssam 		goto setup;
4467220Ssam 	}
4477220Ssam 	IF_ENQUEUE(inq, m);
4486893Sfeldman 
4496893Sfeldman setup:
4506893Sfeldman 	/*
4516893Sfeldman 	 * Reset for next packet if possible.
4526893Sfeldman 	 * If waiting for transmit command completion, set flag
4536893Sfeldman 	 * and wait until command completes.
4546893Sfeldman 	 */
4557261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4567261Ssam 		is->is_flags |= ILF_RCVPENDING;
4577220Ssam 		return;
4587220Ssam 	}
4597220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4609746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4617261Ssam 	addr->il_csr =
4627261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4637220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4647220Ssam 		;
4656893Sfeldman }
4666893Sfeldman 
4676893Sfeldman /*
4686893Sfeldman  * Ethernet output routine.
4696893Sfeldman  * Encapsulate a packet of type family for the local net.
4706893Sfeldman  * Use trailer local net encapsulation if enough data in first
4716893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4726893Sfeldman  */
4736893Sfeldman iloutput(ifp, m0, dst)
4746893Sfeldman 	struct ifnet *ifp;
4756893Sfeldman 	struct mbuf *m0;
4766893Sfeldman 	struct sockaddr *dst;
4776893Sfeldman {
478*11575Ssam 	int type, s, error;
479*11575Ssam 	u_char edst[6];
480*11575Ssam 	struct in_addr idst;
4816893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4826893Sfeldman 	register struct mbuf *m = m0;
4839746Ssam 	register struct ether_header *il;
4849179Ssam 	register int off;
4856893Sfeldman 
4866893Sfeldman 	switch (dst->sa_family) {
4876893Sfeldman 
4886893Sfeldman #ifdef INET
4896893Sfeldman 	case AF_INET:
490*11575Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
491*11575Ssam 		if (!arpresolve(&is->is_ac, m, &idst, edst))
492*11575Ssam 			return (0);	/* if not yet resolved */
4936893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4946893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4956893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4969746Ssam 			type = ETHERPUP_TRAIL + (off>>9);
4976893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4986893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4999746Ssam 			*mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE);
5009746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
5016893Sfeldman 			goto gottrailertype;
5026893Sfeldman 		}
5039746Ssam 		type = ETHERPUP_IPTYPE;
5046893Sfeldman 		off = 0;
5056893Sfeldman 		goto gottype;
5066893Sfeldman #endif
5076893Sfeldman 
508*11575Ssam 	case AF_UNSPEC:
509*11575Ssam 		il = (struct ether_header *)dst->sa_data;
510*11575Ssam 		bcopy(il->ether_dhost, edst, sizeof (edst));
511*11575Ssam 		type = il->ether_type;
512*11575Ssam 		goto gottype;
513*11575Ssam 
5146893Sfeldman 	default:
5156893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5166893Sfeldman 			dst->sa_family);
5176893Sfeldman 		error = EAFNOSUPPORT;
5186893Sfeldman 		goto bad;
5196893Sfeldman 	}
5206893Sfeldman 
5216893Sfeldman gottrailertype:
5226893Sfeldman 	/*
5236893Sfeldman 	 * Packet to be sent as trailer: move first packet
5246893Sfeldman 	 * (control information) to end of chain.
5256893Sfeldman 	 */
5266893Sfeldman 	while (m->m_next)
5276893Sfeldman 		m = m->m_next;
5286893Sfeldman 	m->m_next = m0;
5296893Sfeldman 	m = m0->m_next;
5306893Sfeldman 	m0->m_next = 0;
5316893Sfeldman 	m0 = m;
5326893Sfeldman 
5336893Sfeldman gottype:
5346893Sfeldman 	/*
5356893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5366893Sfeldman 	 * allocate another.
5376893Sfeldman 	 */
5386893Sfeldman 	if (m->m_off > MMAXOFF ||
5399746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5409650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5416893Sfeldman 		if (m == 0) {
5426893Sfeldman 			error = ENOBUFS;
5436893Sfeldman 			goto bad;
5446893Sfeldman 		}
5456893Sfeldman 		m->m_next = m0;
5466893Sfeldman 		m->m_off = MMINOFF;
5479746Ssam 		m->m_len = sizeof (struct ether_header);
5486893Sfeldman 	} else {
5499746Ssam 		m->m_off -= sizeof (struct ether_header);
5509746Ssam 		m->m_len += sizeof (struct ether_header);
5516893Sfeldman 	}
5529746Ssam 	il = mtod(m, struct ether_header *);
5539746Ssam 	il->ether_type = htons((u_short)type);
554*11575Ssam 	bcopy(edst, il->ether_dhost, sizeof (edst));
555*11575Ssam 	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 6);
5566893Sfeldman 
5576893Sfeldman 	/*
5586893Sfeldman 	 * Queue message on interface, and start output if interface
5596893Sfeldman 	 * not yet active.
5606893Sfeldman 	 */
5616893Sfeldman 	s = splimp();
5626893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5636893Sfeldman 		IF_DROP(&ifp->if_snd);
5647220Ssam 		splx(s);
5657220Ssam 		m_freem(m);
5667220Ssam 		return (ENOBUFS);
5676893Sfeldman 	}
5686893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5697261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5706893Sfeldman 		ilstart(ifp->if_unit);
5716893Sfeldman 	splx(s);
5726893Sfeldman 	return (0);
5737220Ssam 
5746893Sfeldman bad:
5756893Sfeldman 	m_freem(m0);
5767220Ssam 	return (error);
5776893Sfeldman }
5787261Ssam 
5797261Ssam /*
5807261Ssam  * Watchdog routine, request statistics from board.
5817261Ssam  */
5827261Ssam ilwatch(unit)
5837261Ssam 	int unit;
5847261Ssam {
5857261Ssam 	register struct il_softc *is = &il_softc[unit];
5867261Ssam 	register struct ifnet *ifp = &is->is_if;
5877261Ssam 	int s;
5887261Ssam 
5897261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5907261Ssam 		ifp->if_timer = is->is_scaninterval;
5917261Ssam 		return;
5927261Ssam 	}
5937261Ssam 	s = splimp();
5947261Ssam 	is->is_flags |= ILF_STATPENDING;
5957261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5967261Ssam 		ilstart(ifp->if_unit);
5977261Ssam 	splx(s);
5987261Ssam 	ifp->if_timer = is->is_scaninterval;
5997261Ssam }
6007261Ssam 
6017261Ssam /*
6027261Ssam  * Total up the on-board statistics.
6037261Ssam  */
6047261Ssam iltotal(is)
6057261Ssam 	register struct il_softc *is;
6067261Ssam {
6077261Ssam 	register u_short *interval, *sum, *end;
6087261Ssam 
6097261Ssam 	interval = &is->is_stats.ils_frames;
6107261Ssam 	sum = &is->is_sum.ils_frames;
6117261Ssam 	end = is->is_sum.ils_fill2;
6127261Ssam 	while (sum < end)
6137261Ssam 		*sum++ += *interval++;
6147261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6157261Ssam }
616