xref: /csrg-svn/sys/vax/if/if_il.c (revision 15787)
1*15787Sleres /*	if_il.c	6.3	84/01/02	*/
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"
1713056Ssam #include "../h/ioctl.h"
1813056Ssam #include "../h/errno.h"
198463Sroot 
208463Sroot #include "../net/if.h"
218463Sroot #include "../net/netisr.h"
228463Sroot #include "../net/route.h"
238419Swnj #include "../netinet/in.h"
248419Swnj #include "../netinet/in_systm.h"
258419Swnj #include "../netinet/ip.h"
268419Swnj #include "../netinet/ip_var.h"
2711575Ssam #include "../netinet/if_ether.h"
288419Swnj #include "../netpup/pup.h"
296893Sfeldman 
308463Sroot #include "../vax/cpu.h"
318463Sroot #include "../vax/mtpr.h"
329746Ssam #include "../vaxif/if_il.h"
338463Sroot #include "../vaxif/if_ilreg.h"
348463Sroot #include "../vaxif/if_uba.h"
358463Sroot #include "../vaxuba/ubareg.h"
368463Sroot #include "../vaxuba/ubavar.h"
378463Sroot 
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)
4413056Ssam int	ilinit(),iloutput(),ilioctl(),ilreset(),ilwatch();
456893Sfeldman 
466893Sfeldman /*
476893Sfeldman  * Ethernet software status per interface.
486893Sfeldman  *
496893Sfeldman  * Each interface is referenced by a network interface structure,
506893Sfeldman  * is_if, which the routing code uses to locate the interface.
516893Sfeldman  * This structure contains the output queue for the interface, its address, ...
526893Sfeldman  * We also have, for each interface, a UBA interface structure, which
536893Sfeldman  * contains information about the UNIBUS resources held by the interface:
546893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
556893Sfeldman  * structure for use by the if_uba.c routines in running the interface
566893Sfeldman  * efficiently.
576893Sfeldman  */
586893Sfeldman struct	il_softc {
5911575Ssam 	struct	arpcom is_ac;		/* Ethernet common part */
6011575Ssam #define	is_if	is_ac.ac_if		/* network-visible interface */
6111575Ssam #define	is_addr	is_ac.ac_enaddr		/* hardware Ethernet address */
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;
849179Ssam 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
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";
1119746Ssam 	ifp->if_mtu = ETHERMTU;
1126893Sfeldman 
1136893Sfeldman 	/*
1147261Ssam 	 * Reset the board and map the statistics
1157261Ssam 	 * buffer onto the Unibus.
1166893Sfeldman 	 */
1177261Ssam 	addr->il_csr = ILC_RESET;
1187261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1197261Ssam 		;
1207261Ssam 	if (addr->il_csr&IL_STATUS)
1217261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1227261Ssam 			addr->il_csr, IL_BITS);
1236893Sfeldman 
1249179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
12513056Ssam 	    sizeof (struct il_stats), 0);
1267261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1277261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1287261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1297261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1307261Ssam 		;
1317261Ssam 	if (addr->il_csr&IL_STATUS)
1327261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1337261Ssam 			addr->il_csr, IL_BITS);
1347261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
13511575Ssam #ifdef notdef
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);
14211575Ssam #endif
14312773Ssam 	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr,
14412773Ssam 	    sizeof (is->is_addr));
1457220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1466893Sfeldman 	sin->sin_family = AF_INET;
14712773Ssam 	sin->sin_addr = arpmyaddr((struct arpcom *)0);
1487220Ssam 	ifp->if_init = ilinit;
1497220Ssam 	ifp->if_output = iloutput;
15013056Ssam 	ifp->if_ioctl = ilioctl;
1518979Sroot 	ifp->if_reset = ilreset;
1526893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1537220Ssam #ifdef notdef
1547220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1557220Ssam #endif
1567220Ssam 	if_attach(ifp);
1576893Sfeldman }
1586893Sfeldman 
1596893Sfeldman /*
1606893Sfeldman  * Reset of interface after UNIBUS reset.
1616893Sfeldman  * If interface is on specified uba, reset its state.
1626893Sfeldman  */
1636893Sfeldman ilreset(unit, uban)
1646893Sfeldman 	int unit, uban;
1656893Sfeldman {
1666893Sfeldman 	register struct uba_device *ui;
1676893Sfeldman 
1686893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1696893Sfeldman 	    ui->ui_ubanum != uban)
1706893Sfeldman 		return;
1716893Sfeldman 	printf(" il%d", unit);
1726893Sfeldman 	ilinit(unit);
1736893Sfeldman }
1746893Sfeldman 
1756893Sfeldman /*
1766893Sfeldman  * Initialization of interface; clear recorded pending
1776893Sfeldman  * operations, and reinitialize UNIBUS usage.
1786893Sfeldman  */
1796893Sfeldman ilinit(unit)
1806893Sfeldman 	int unit;
1816893Sfeldman {
1826893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1836893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1846893Sfeldman 	register struct ildevice *addr;
18513056Ssam 	register struct ifnet *ifp = &is->is_if;
18613056Ssam 	register struct sockaddr_in *sin;
1877261Ssam 	int s;
1886893Sfeldman 
18911575Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
19013056Ssam 	if (sin->sin_addr.s_addr == 0)		/* address still unknown */
19111575Ssam 		return;
19211575Ssam 
19313056Ssam 	if (ifp->if_flags & IFF_RUNNING)
19413056Ssam 		goto justarp;
1956893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1969746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
1976893Sfeldman 		printf("il%d: can't initialize\n", unit);
1986893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
1996893Sfeldman 		return;
2006893Sfeldman 	}
2019179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
20213056Ssam 	    sizeof (struct il_stats), 0);
20315071Skarels 	ifp->if_watchdog = ilwatch;
20415071Skarels 	is->is_scaninterval = ILWATCHINTERVAL;
20515071Skarels 	ifp->if_timer = is->is_scaninterval;
2066893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2076893Sfeldman 
2086893Sfeldman 	/*
2099179Ssam 	 * Turn off source address insertion (it's faster this way),
21012488Ssam 	 * and set board online.  Former doesn't work if board is
21112488Ssam 	 * already online (happens on ubareset), so we put it offline
21212488Ssam 	 * first.
2139179Ssam 	 */
2149179Ssam 	s = splimp();
21512488Ssam 	addr->il_csr = ILC_OFFLINE;
2169179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2179179Ssam 		;
21812488Ssam 	addr->il_csr = ILC_CISA;
2199179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2209179Ssam 		;
2219179Ssam 	/*
2226893Sfeldman 	 * Set board online.
2236893Sfeldman 	 * Hang receive buffer and start any pending
2246893Sfeldman 	 * writes by faking a transmit complete.
2256893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2266893Sfeldman 	 * chaining can't happen.
2276893Sfeldman 	 */
2286893Sfeldman 	addr->il_csr = ILC_ONLINE;
2297220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2307220Ssam 		;
2316893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2329746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
2337261Ssam 	addr->il_csr =
23413056Ssam 	    ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2357220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2367220Ssam 		;
2377261Ssam 	is->is_flags = ILF_OACTIVE;
23813060Ssam 	is->is_if.if_flags |= IFF_UP|IFF_RUNNING;
2397261Ssam 	is->is_lastcmd = 0;
2406893Sfeldman 	ilcint(unit);
2416893Sfeldman 	splx(s);
24213056Ssam justarp:
2437152Swnj 	if_rtinit(&is->is_if, RTF_UP);
24411575Ssam 	arpattach(&is->is_ac);
24511575Ssam 	arpwhohas(&is->is_ac, &sin->sin_addr);
2466893Sfeldman }
2476893Sfeldman 
2486893Sfeldman /*
2496893Sfeldman  * Start output on interface.
2506893Sfeldman  * Get another datagram to send off of the interface queue,
2516893Sfeldman  * and map it to the interface before starting the output.
2526893Sfeldman  */
2536893Sfeldman ilstart(dev)
2546893Sfeldman 	dev_t dev;
2556893Sfeldman {
2569179Ssam         int unit = ILUNIT(dev), len;
2576893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2586893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2596893Sfeldman 	register struct ildevice *addr;
2606893Sfeldman 	struct mbuf *m;
2617220Ssam 	short csr;
2626893Sfeldman 
2636893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2647261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2657261Ssam 	if (m == 0) {
2667261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2677261Ssam 			return;
2689179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2697261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2707261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2717261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2727261Ssam 		goto startcmd;
2737261Ssam 	}
2746893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2759179Ssam 	/*
2769179Ssam 	 * Ensure minimum packet length.
2779179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2789179Ssam 	 * after the data.
2799179Ssam 	 * For security, it might be wise to zero out the added bytes,
2809179Ssam 	 * but we're mainly interested in speed at the moment.
2819179Ssam 	 */
2829746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2839746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
2846893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2856893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2866893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2876893Sfeldman 	addr->il_bcr = len;
2887261Ssam 	csr =
2897261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2907261Ssam 
2917261Ssam startcmd:
2927261Ssam 	is->is_lastcmd = csr & IL_CMD;
2937220Ssam 	addr->il_csr = csr;
2947261Ssam 	is->is_flags |= ILF_OACTIVE;
2956893Sfeldman }
2966893Sfeldman 
2976893Sfeldman /*
2986893Sfeldman  * Command done interrupt.
2996893Sfeldman  */
3006893Sfeldman ilcint(unit)
3016893Sfeldman 	int unit;
3026893Sfeldman {
3036893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3047220Ssam 	struct uba_device *ui = ilinfo[unit];
3056893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
3067266Ssam 	short csr;
3076893Sfeldman 
3087261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3097220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3107261Ssam 			addr->il_csr, IL_BITS);
3116893Sfeldman 		return;
3126893Sfeldman 	}
3137220Ssam 
3147266Ssam 	csr = addr->il_csr;
3156893Sfeldman 	/*
3167261Ssam 	 * Hang receive buffer if it couldn't
3177261Ssam 	 * be done earlier (in ilrint).
3186893Sfeldman 	 */
3197261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3206893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3219746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
3227261Ssam 		addr->il_csr =
3237261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3247220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3257220Ssam 			;
3267261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3276893Sfeldman 	}
3287261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3297266Ssam 	csr &= IL_STATUS;
3307261Ssam 	switch (is->is_lastcmd) {
3317261Ssam 
3327261Ssam 	case ILC_XMIT:
3337261Ssam 		is->is_if.if_opackets++;
3347266Ssam 		if (csr > ILERR_RETRIES)
3357261Ssam 			is->is_if.if_oerrors++;
3367261Ssam 		break;
3377261Ssam 
3387261Ssam 	case ILC_STAT:
3397266Ssam 		if (csr == ILERR_SUCCESS)
3407261Ssam 			iltotal(is);
3417261Ssam 		break;
3427261Ssam 	}
3436893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3446893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3456893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3466893Sfeldman 	}
3477261Ssam 	ilstart(unit);
3486893Sfeldman }
3496893Sfeldman 
3506893Sfeldman /*
3516893Sfeldman  * Ethernet interface receiver interrupt.
3526893Sfeldman  * If input error just drop packet.
3536893Sfeldman  * Otherwise purge input buffered data path and examine
3546893Sfeldman  * packet to determine type.  If can't determine length
3556893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3566893Sfeldman  * packet based on type and pass to type specific higher-level
3576893Sfeldman  * input routine.
3586893Sfeldman  */
3596893Sfeldman ilrint(unit)
3606893Sfeldman 	int unit;
3616893Sfeldman {
3626893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3636893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3646893Sfeldman 	register struct il_rheader *il;
3656893Sfeldman     	struct mbuf *m;
366*15787Sleres 	int len, off, resid, s;
3676893Sfeldman 	register struct ifqueue *inq;
3686893Sfeldman 
3696893Sfeldman 	is->is_if.if_ipackets++;
3706893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3716893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3726893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3736893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3749746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3759746Ssam 	    len > ETHERMTU) {
3766893Sfeldman 		is->is_if.if_ierrors++;
3776893Sfeldman #ifdef notdef
3786893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3796893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3806893Sfeldman #endif
3816893Sfeldman 		goto setup;
3826893Sfeldman 	}
3836893Sfeldman 
3846893Sfeldman 	/*
3856893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3866893Sfeldman 	 * get true type from first 16-bit word past data.
3876893Sfeldman 	 * Remember that type was trailer by setting off.
3886893Sfeldman 	 */
3899746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3906893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3919746Ssam 	if (il->ilr_type >= ETHERPUP_TRAIL &&
3929746Ssam 	    il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) {
3939746Ssam 		off = (il->ilr_type - ETHERPUP_TRAIL) * 512;
3949746Ssam 		if (off >= ETHERMTU)
3956893Sfeldman 			goto setup;		/* sanity */
3969746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
3979746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
3986893Sfeldman 		if (off + resid > len)
3996893Sfeldman 			goto setup;		/* sanity */
4006893Sfeldman 		len = off + resid;
4016893Sfeldman 	} else
4026893Sfeldman 		off = 0;
4036893Sfeldman 	if (len == 0)
4046893Sfeldman 		goto setup;
4056893Sfeldman 
4066893Sfeldman 	/*
4076893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4086893Sfeldman 	 * has trailing header; ilget will then force this header
4096893Sfeldman 	 * information to be at the front, but we still have to drop
4106893Sfeldman 	 * the type and length which are at the front of any trailer data.
4116893Sfeldman 	 */
4126893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4136893Sfeldman 	if (m == 0)
4146893Sfeldman 		goto setup;
4156893Sfeldman 	if (off) {
4166893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4176893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4186893Sfeldman 	}
4196893Sfeldman 	switch (il->ilr_type) {
4206893Sfeldman 
4216893Sfeldman #ifdef INET
4229746Ssam 	case ETHERPUP_IPTYPE:
4236893Sfeldman 		schednetisr(NETISR_IP);
4246893Sfeldman 		inq = &ipintrq;
4256893Sfeldman 		break;
42611575Ssam 
42711575Ssam 	case ETHERPUP_ARPTYPE:
42811575Ssam 		arpinput(&is->is_ac, m);
42913988Ssam 		goto setup;
4306893Sfeldman #endif
4316893Sfeldman 	default:
4326893Sfeldman 		m_freem(m);
4336893Sfeldman 		goto setup;
4346893Sfeldman 	}
4356893Sfeldman 
436*15787Sleres 	s = splimp();
4376893Sfeldman 	if (IF_QFULL(inq)) {
4386893Sfeldman 		IF_DROP(inq);
4396893Sfeldman 		m_freem(m);
440*15787Sleres 	} else
441*15787Sleres 		IF_ENQUEUE(inq, m);
442*15787Sleres 	splx(s);
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;
48913056Ssam 		/* need per host negotiation */
49013056Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
4916893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4926893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4939746Ssam 			type = ETHERPUP_TRAIL + (off>>9);
4946893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4956893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4969746Ssam 			*mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE);
4979746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4986893Sfeldman 			goto gottrailertype;
4996893Sfeldman 		}
5009746Ssam 		type = ETHERPUP_IPTYPE;
5016893Sfeldman 		off = 0;
5026893Sfeldman 		goto gottype;
5036893Sfeldman #endif
5046893Sfeldman 
50511575Ssam 	case AF_UNSPEC:
50611575Ssam 		il = (struct ether_header *)dst->sa_data;
50712773Ssam 		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
50811575Ssam 		type = il->ether_type;
50911575Ssam 		goto gottype;
51011575Ssam 
5116893Sfeldman 	default:
5126893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5136893Sfeldman 			dst->sa_family);
5146893Sfeldman 		error = EAFNOSUPPORT;
5156893Sfeldman 		goto bad;
5166893Sfeldman 	}
5176893Sfeldman 
5186893Sfeldman gottrailertype:
5196893Sfeldman 	/*
5206893Sfeldman 	 * Packet to be sent as trailer: move first packet
5216893Sfeldman 	 * (control information) to end of chain.
5226893Sfeldman 	 */
5236893Sfeldman 	while (m->m_next)
5246893Sfeldman 		m = m->m_next;
5256893Sfeldman 	m->m_next = m0;
5266893Sfeldman 	m = m0->m_next;
5276893Sfeldman 	m0->m_next = 0;
5286893Sfeldman 	m0 = m;
5296893Sfeldman 
5306893Sfeldman gottype:
5316893Sfeldman 	/*
5326893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5336893Sfeldman 	 * allocate another.
5346893Sfeldman 	 */
5356893Sfeldman 	if (m->m_off > MMAXOFF ||
5369746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5379650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5386893Sfeldman 		if (m == 0) {
5396893Sfeldman 			error = ENOBUFS;
5406893Sfeldman 			goto bad;
5416893Sfeldman 		}
5426893Sfeldman 		m->m_next = m0;
5436893Sfeldman 		m->m_off = MMINOFF;
5449746Ssam 		m->m_len = sizeof (struct ether_header);
5456893Sfeldman 	} else {
5469746Ssam 		m->m_off -= sizeof (struct ether_header);
5479746Ssam 		m->m_len += sizeof (struct ether_header);
5486893Sfeldman 	}
5499746Ssam 	il = mtod(m, struct ether_header *);
5509746Ssam 	il->ether_type = htons((u_short)type);
55112773Ssam 	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
55211575Ssam 	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 6);
5536893Sfeldman 
5546893Sfeldman 	/*
5556893Sfeldman 	 * Queue message on interface, and start output if interface
5566893Sfeldman 	 * not yet active.
5576893Sfeldman 	 */
5586893Sfeldman 	s = splimp();
5596893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5606893Sfeldman 		IF_DROP(&ifp->if_snd);
5617220Ssam 		splx(s);
5627220Ssam 		m_freem(m);
5637220Ssam 		return (ENOBUFS);
5646893Sfeldman 	}
5656893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5667261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5676893Sfeldman 		ilstart(ifp->if_unit);
5686893Sfeldman 	splx(s);
5696893Sfeldman 	return (0);
5707220Ssam 
5716893Sfeldman bad:
5726893Sfeldman 	m_freem(m0);
5737220Ssam 	return (error);
5746893Sfeldman }
5757261Ssam 
5767261Ssam /*
5777261Ssam  * Watchdog routine, request statistics from board.
5787261Ssam  */
5797261Ssam ilwatch(unit)
5807261Ssam 	int unit;
5817261Ssam {
5827261Ssam 	register struct il_softc *is = &il_softc[unit];
5837261Ssam 	register struct ifnet *ifp = &is->is_if;
5847261Ssam 	int s;
5857261Ssam 
5867261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5877261Ssam 		ifp->if_timer = is->is_scaninterval;
5887261Ssam 		return;
5897261Ssam 	}
5907261Ssam 	s = splimp();
5917261Ssam 	is->is_flags |= ILF_STATPENDING;
5927261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5937261Ssam 		ilstart(ifp->if_unit);
5947261Ssam 	splx(s);
5957261Ssam 	ifp->if_timer = is->is_scaninterval;
5967261Ssam }
5977261Ssam 
5987261Ssam /*
5997261Ssam  * Total up the on-board statistics.
6007261Ssam  */
6017261Ssam iltotal(is)
6027261Ssam 	register struct il_softc *is;
6037261Ssam {
6047261Ssam 	register u_short *interval, *sum, *end;
6057261Ssam 
6067261Ssam 	interval = &is->is_stats.ils_frames;
6077261Ssam 	sum = &is->is_sum.ils_frames;
6087261Ssam 	end = is->is_sum.ils_fill2;
6097261Ssam 	while (sum < end)
6107261Ssam 		*sum++ += *interval++;
6117261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6127261Ssam }
61313056Ssam 
61413056Ssam /*
61513056Ssam  * Process an ioctl request.
61613056Ssam  */
61713056Ssam ilioctl(ifp, cmd, data)
61813056Ssam 	register struct ifnet *ifp;
61913056Ssam 	int cmd;
62013056Ssam 	caddr_t data;
62113056Ssam {
62213056Ssam 	register struct ifreq *ifr = (struct ifreq *)data;
62313056Ssam 	int s = splimp(), error = 0;
62413056Ssam 
62513056Ssam 	switch (cmd) {
62613056Ssam 
62713056Ssam 	case SIOCSIFADDR:
62813056Ssam 		if (ifp->if_flags & IFF_RUNNING)
62913056Ssam 			if_rtinit(ifp, -1);	/* delete previous route */
63013063Ssam 		ilsetaddr(ifp, (struct sockaddr_in *)&ifr->ifr_addr);
63113056Ssam 		ilinit(ifp->if_unit);
63213056Ssam 		break;
63313056Ssam 
63413056Ssam 	default:
63513056Ssam 		error = EINVAL;
63613056Ssam 	}
63713056Ssam 	splx(s);
63813056Ssam 	return (error);
63913056Ssam }
64013063Ssam 
64113089Ssam ilsetaddr(ifp, sin)
64213063Ssam 	register struct ifnet *ifp;
64313063Ssam 	register struct sockaddr_in *sin;
64413063Ssam {
64513063Ssam 
64613063Ssam 	ifp->if_addr = *(struct sockaddr *)sin;
64713063Ssam 	ifp->if_net = in_netof(sin->sin_addr);
64813063Ssam 	ifp->if_host[0] = in_lnaof(sin->sin_addr);
64913063Ssam 	sin = (struct sockaddr_in *)&ifp->if_broadaddr;
65013063Ssam 	sin->sin_family = AF_INET;
65113063Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
65213063Ssam 	ifp->if_flags |= IFF_BROADCAST;
65313063Ssam }
654