xref: /csrg-svn/sys/vax/if/if_il.c (revision 19949)
1*19949Sbloom /*	if_il.c	6.7	85/05/04	*/
26893Sfeldman 
36893Sfeldman #include "il.h"
46893Sfeldman 
56893Sfeldman /*
66893Sfeldman  * Interlan Ethernet Communications Controller interface
76893Sfeldman  */
89797Ssam #include "../machine/pte.h"
99797Ssam 
1017115Sbloom #include "param.h"
1117115Sbloom #include "systm.h"
1217115Sbloom #include "mbuf.h"
1317115Sbloom #include "buf.h"
1417115Sbloom #include "protosw.h"
1517115Sbloom #include "socket.h"
1617115Sbloom #include "vmmac.h"
1717115Sbloom #include "ioctl.h"
1817115Sbloom #include "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"
2519865Skarels #include "../netinet/in_var.h"
268419Swnj #include "../netinet/ip.h"
278419Swnj #include "../netinet/ip_var.h"
2811575Ssam #include "../netinet/if_ether.h"
29*19949Sbloom #ifdef PUP
308419Swnj #include "../netpup/pup.h"
31*19949Sbloom #endif
326893Sfeldman 
338463Sroot #include "../vax/cpu.h"
348463Sroot #include "../vax/mtpr.h"
3517115Sbloom #include "if_il.h"
3617115Sbloom #include "if_ilreg.h"
3717115Sbloom #include "if_uba.h"
388463Sroot #include "../vaxuba/ubareg.h"
398463Sroot #include "../vaxuba/ubavar.h"
408463Sroot 
416893Sfeldman int	ilprobe(), ilattach(), ilrint(), ilcint();
426893Sfeldman struct	uba_device *ilinfo[NIL];
436893Sfeldman u_short ilstd[] = { 0 };
446893Sfeldman struct	uba_driver ildriver =
456893Sfeldman 	{ ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo };
466893Sfeldman #define	ILUNIT(x)	minor(x)
4713056Ssam int	ilinit(),iloutput(),ilioctl(),ilreset(),ilwatch();
486893Sfeldman 
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 {
6211575Ssam 	struct	arpcom is_ac;		/* Ethernet common part */
6311575Ssam #define	is_if	is_ac.ac_if		/* network-visible interface */
6411575Ssam #define	is_addr	is_ac.ac_enaddr		/* hardware Ethernet address */
656893Sfeldman 	struct	ifuba is_ifuba;		/* UNIBUS resources */
667261Ssam 	int	is_flags;
677261Ssam #define	ILF_OACTIVE	0x1		/* output is active */
687261Ssam #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
697261Ssam #define	ILF_STATPENDING	0x4		/* stat cmd pending */
707261Ssam 	short	is_lastcmd;		/* can't read csr, so must save it */
717261Ssam 	short	is_scaninterval;	/* interval of stat collection */
727261Ssam #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
737261Ssam 	struct	il_stats is_stats;	/* holds on-board statistics */
747261Ssam 	struct	il_stats is_sum;	/* summation over time */
757261Ssam 	int	is_ubaddr;		/* mapping registers of is_stats */
766893Sfeldman } il_softc[NIL];
776893Sfeldman 
786893Sfeldman ilprobe(reg)
796893Sfeldman 	caddr_t reg;
806893Sfeldman {
816893Sfeldman 	register int br, cvec;		/* r11, r10 value-result */
826893Sfeldman 	register struct ildevice *addr = (struct ildevice *)reg;
836893Sfeldman 	register i;
846893Sfeldman 
856893Sfeldman #ifdef lint
866893Sfeldman 	br = 0; cvec = br; br = cvec;
879179Ssam 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
886893Sfeldman #endif
896893Sfeldman 
906893Sfeldman 	addr->il_csr = ILC_OFFLINE|IL_CIE;
916893Sfeldman 	DELAY(100000);
927261Ssam 	i = addr->il_csr;		/* clear CDONE */
936893Sfeldman 	if (cvec > 0 && cvec != 0x200)
946893Sfeldman 		cvec -= 4;
956893Sfeldman 	return (1);
966893Sfeldman }
976893Sfeldman 
986893Sfeldman /*
996893Sfeldman  * Interface exists: make available by filling in network interface
1006893Sfeldman  * record.  System will initialize the interface when it is ready
1016893Sfeldman  * to accept packets.  A STATUS command is done to get the ethernet
1026893Sfeldman  * address and other interesting data.
1036893Sfeldman  */
1046893Sfeldman ilattach(ui)
1056893Sfeldman 	struct uba_device *ui;
1066893Sfeldman {
1076893Sfeldman 	register struct il_softc *is = &il_softc[ui->ui_unit];
1087220Ssam 	register struct ifnet *ifp = &is->is_if;
1096893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
1106893Sfeldman 
1117220Ssam 	ifp->if_unit = ui->ui_unit;
1127220Ssam 	ifp->if_name = "il";
1139746Ssam 	ifp->if_mtu = ETHERMTU;
11419865Skarels 	ifp->if_flags = IFF_BROADCAST;
1156893Sfeldman 
1166893Sfeldman 	/*
1177261Ssam 	 * Reset the board and map the statistics
1187261Ssam 	 * buffer onto the Unibus.
1196893Sfeldman 	 */
1207261Ssam 	addr->il_csr = ILC_RESET;
1217261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1227261Ssam 		;
1237261Ssam 	if (addr->il_csr&IL_STATUS)
1247261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1257261Ssam 			addr->il_csr, IL_BITS);
1266893Sfeldman 
1279179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
12813056Ssam 	    sizeof (struct il_stats), 0);
1297261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1307261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1317261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1327261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1337261Ssam 		;
1347261Ssam 	if (addr->il_csr&IL_STATUS)
1357261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1367261Ssam 			addr->il_csr, IL_BITS);
1377261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
13811575Ssam #ifdef notdef
1396893Sfeldman 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
1406893Sfeldman 		ui->ui_unit,
1417261Ssam 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
1427261Ssam 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
1437261Ssam 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
1447261Ssam 		is->is_stats.ils_module, is->is_stats.ils_firmware);
14511575Ssam #endif
14619865Skarels  	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr,
14719865Skarels  	    sizeof (is->is_addr));
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;
1867261Ssam 	int s;
1876893Sfeldman 
18819865Skarels 	/* not yet, if address still unknown */
18919865Skarels 	if (ifp->if_addrlist == (struct ifaddr *)0)
19011575Ssam 		return;
19111575Ssam 
19213056Ssam 	if (ifp->if_flags & IFF_RUNNING)
19319865Skarels 		return;
1946893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1959746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
1966893Sfeldman 		printf("il%d: can't initialize\n", unit);
1976893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
1986893Sfeldman 		return;
1996893Sfeldman 	}
2009179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
20113056Ssam 	    sizeof (struct il_stats), 0);
20215071Skarels 	ifp->if_watchdog = ilwatch;
20315071Skarels 	is->is_scaninterval = ILWATCHINTERVAL;
20415071Skarels 	ifp->if_timer = is->is_scaninterval;
2056893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2066893Sfeldman 
2076893Sfeldman 	/*
2089179Ssam 	 * Turn off source address insertion (it's faster this way),
20912488Ssam 	 * and set board online.  Former doesn't work if board is
21012488Ssam 	 * already online (happens on ubareset), so we put it offline
21112488Ssam 	 * first.
2129179Ssam 	 */
2139179Ssam 	s = splimp();
21412488Ssam 	addr->il_csr = ILC_OFFLINE;
2159179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2169179Ssam 		;
21712488Ssam 	addr->il_csr = ILC_CISA;
2189179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2199179Ssam 		;
2209179Ssam 	/*
2216893Sfeldman 	 * Set board online.
2226893Sfeldman 	 * Hang receive buffer and start any pending
2236893Sfeldman 	 * writes by faking a transmit complete.
2246893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2256893Sfeldman 	 * chaining can't happen.
2266893Sfeldman 	 */
2276893Sfeldman 	addr->il_csr = ILC_ONLINE;
2287220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2297220Ssam 		;
2306893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2319746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
2327261Ssam 	addr->il_csr =
23313056Ssam 	    ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2347220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2357220Ssam 		;
2367261Ssam 	is->is_flags = ILF_OACTIVE;
23719865Skarels 	is->is_if.if_flags |= IFF_RUNNING;
2387261Ssam 	is->is_lastcmd = 0;
2396893Sfeldman 	ilcint(unit);
2406893Sfeldman 	splx(s);
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 	 */
2779746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2789746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
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;
3169746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 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;
36115787Sleres 	int len, off, resid, s;
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);
3699746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3709746Ssam 	    len > ETHERMTU) {
3716893Sfeldman 		is->is_if.if_ierrors++;
3726893Sfeldman #ifdef notdef
3736893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3746893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3756893Sfeldman #endif
3766893Sfeldman 		goto setup;
3776893Sfeldman 	}
3786893Sfeldman 
3796893Sfeldman 	/*
38019865Skarels 	 * Deal with trailer protocol: if type is trailer type
3816893Sfeldman 	 * get true type from first 16-bit word past data.
3826893Sfeldman 	 * Remember that type was trailer by setting off.
3836893Sfeldman 	 */
3849746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3856893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
38619865Skarels 	if (il->ilr_type >= ETHERTYPE_TRAIL &&
38719865Skarels 	    il->ilr_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
38819865Skarels 		off = (il->ilr_type - ETHERTYPE_TRAIL) * 512;
3899746Ssam 		if (off >= ETHERMTU)
3906893Sfeldman 			goto setup;		/* sanity */
3919746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
3929746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
3936893Sfeldman 		if (off + resid > len)
3946893Sfeldman 			goto setup;		/* sanity */
3956893Sfeldman 		len = off + resid;
3966893Sfeldman 	} else
3976893Sfeldman 		off = 0;
3986893Sfeldman 	if (len == 0)
3996893Sfeldman 		goto setup;
4006893Sfeldman 
4016893Sfeldman 	/*
4026893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4036893Sfeldman 	 * has trailing header; ilget will then force this header
4046893Sfeldman 	 * information to be at the front, but we still have to drop
4056893Sfeldman 	 * the type and length which are at the front of any trailer data.
4066893Sfeldman 	 */
4076893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4086893Sfeldman 	if (m == 0)
4096893Sfeldman 		goto setup;
4106893Sfeldman 	if (off) {
4116893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4126893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4136893Sfeldman 	}
4146893Sfeldman 	switch (il->ilr_type) {
4156893Sfeldman 
4166893Sfeldman #ifdef INET
41719865Skarels 	case ETHERTYPE_IP:
4186893Sfeldman 		schednetisr(NETISR_IP);
4196893Sfeldman 		inq = &ipintrq;
4206893Sfeldman 		break;
42111575Ssam 
42219865Skarels 	case ETHERTYPE_ARP:
42311575Ssam 		arpinput(&is->is_ac, m);
42413988Ssam 		goto setup;
4256893Sfeldman #endif
4266893Sfeldman 	default:
4276893Sfeldman 		m_freem(m);
4286893Sfeldman 		goto setup;
4296893Sfeldman 	}
4306893Sfeldman 
43115787Sleres 	s = splimp();
4326893Sfeldman 	if (IF_QFULL(inq)) {
4336893Sfeldman 		IF_DROP(inq);
4346893Sfeldman 		m_freem(m);
43515787Sleres 	} else
43615787Sleres 		IF_ENQUEUE(inq, m);
43715787Sleres 	splx(s);
4386893Sfeldman 
4396893Sfeldman setup:
4406893Sfeldman 	/*
4416893Sfeldman 	 * Reset for next packet if possible.
4426893Sfeldman 	 * If waiting for transmit command completion, set flag
4436893Sfeldman 	 * and wait until command completes.
4446893Sfeldman 	 */
4457261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4467261Ssam 		is->is_flags |= ILF_RCVPENDING;
4477220Ssam 		return;
4487220Ssam 	}
4497220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4509746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4517261Ssam 	addr->il_csr =
4527261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4537220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4547220Ssam 		;
4556893Sfeldman }
4566893Sfeldman 
4576893Sfeldman /*
4586893Sfeldman  * Ethernet output routine.
4596893Sfeldman  * Encapsulate a packet of type family for the local net.
4606893Sfeldman  * Use trailer local net encapsulation if enough data in first
4616893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4626893Sfeldman  */
4636893Sfeldman iloutput(ifp, m0, dst)
4646893Sfeldman 	struct ifnet *ifp;
4656893Sfeldman 	struct mbuf *m0;
4666893Sfeldman 	struct sockaddr *dst;
4676893Sfeldman {
46811575Ssam 	int type, s, error;
46919865Skarels  	u_char edst[6];
47011575Ssam 	struct in_addr idst;
4716893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4726893Sfeldman 	register struct mbuf *m = m0;
4739746Ssam 	register struct ether_header *il;
4749179Ssam 	register int off;
4756893Sfeldman 
4766893Sfeldman 	switch (dst->sa_family) {
4776893Sfeldman 
4786893Sfeldman #ifdef INET
4796893Sfeldman 	case AF_INET:
48011575Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
48119865Skarels  		if (!arpresolve(&is->is_ac, m, &idst, edst))
48211575Ssam 			return (0);	/* if not yet resolved */
4836893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
48413056Ssam 		/* need per host negotiation */
48513056Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
4866893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4876893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
48819865Skarels 			type = ETHERTYPE_TRAIL + (off>>9);
4896893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4906893Sfeldman 			m->m_len += 2 * sizeof (u_short);
49119865Skarels 			*mtod(m, u_short *) = htons((u_short)ETHERTYPE_IP);
4929746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4936893Sfeldman 			goto gottrailertype;
4946893Sfeldman 		}
49519865Skarels 		type = ETHERTYPE_IP;
4966893Sfeldman 		off = 0;
4976893Sfeldman 		goto gottype;
4986893Sfeldman #endif
4996893Sfeldman 
50011575Ssam 	case AF_UNSPEC:
50111575Ssam 		il = (struct ether_header *)dst->sa_data;
50219865Skarels  		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
50311575Ssam 		type = il->ether_type;
50411575Ssam 		goto gottype;
50511575Ssam 
5066893Sfeldman 	default:
5076893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5086893Sfeldman 			dst->sa_family);
5096893Sfeldman 		error = EAFNOSUPPORT;
5106893Sfeldman 		goto bad;
5116893Sfeldman 	}
5126893Sfeldman 
5136893Sfeldman gottrailertype:
5146893Sfeldman 	/*
5156893Sfeldman 	 * Packet to be sent as trailer: move first packet
5166893Sfeldman 	 * (control information) to end of chain.
5176893Sfeldman 	 */
5186893Sfeldman 	while (m->m_next)
5196893Sfeldman 		m = m->m_next;
5206893Sfeldman 	m->m_next = m0;
5216893Sfeldman 	m = m0->m_next;
5226893Sfeldman 	m0->m_next = 0;
5236893Sfeldman 	m0 = m;
5246893Sfeldman 
5256893Sfeldman gottype:
5266893Sfeldman 	/*
5276893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5286893Sfeldman 	 * allocate another.
5296893Sfeldman 	 */
5306893Sfeldman 	if (m->m_off > MMAXOFF ||
5319746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5329650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5336893Sfeldman 		if (m == 0) {
5346893Sfeldman 			error = ENOBUFS;
5356893Sfeldman 			goto bad;
5366893Sfeldman 		}
5376893Sfeldman 		m->m_next = m0;
5386893Sfeldman 		m->m_off = MMINOFF;
5399746Ssam 		m->m_len = sizeof (struct ether_header);
5406893Sfeldman 	} else {
5419746Ssam 		m->m_off -= sizeof (struct ether_header);
5429746Ssam 		m->m_len += sizeof (struct ether_header);
5436893Sfeldman 	}
5449746Ssam 	il = mtod(m, struct ether_header *);
5459746Ssam 	il->ether_type = htons((u_short)type);
54619865Skarels  	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
54719865Skarels  	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost,
54819865Skarels 	    sizeof(il->ether_shost));
5496893Sfeldman 
5506893Sfeldman 	/*
5516893Sfeldman 	 * Queue message on interface, and start output if interface
5526893Sfeldman 	 * not yet active.
5536893Sfeldman 	 */
5546893Sfeldman 	s = splimp();
5556893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5566893Sfeldman 		IF_DROP(&ifp->if_snd);
5577220Ssam 		splx(s);
5587220Ssam 		m_freem(m);
5597220Ssam 		return (ENOBUFS);
5606893Sfeldman 	}
5616893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5627261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5636893Sfeldman 		ilstart(ifp->if_unit);
5646893Sfeldman 	splx(s);
5656893Sfeldman 	return (0);
5667220Ssam 
5676893Sfeldman bad:
5686893Sfeldman 	m_freem(m0);
5697220Ssam 	return (error);
5706893Sfeldman }
5717261Ssam 
5727261Ssam /*
5737261Ssam  * Watchdog routine, request statistics from board.
5747261Ssam  */
5757261Ssam ilwatch(unit)
5767261Ssam 	int unit;
5777261Ssam {
5787261Ssam 	register struct il_softc *is = &il_softc[unit];
5797261Ssam 	register struct ifnet *ifp = &is->is_if;
5807261Ssam 	int s;
5817261Ssam 
5827261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5837261Ssam 		ifp->if_timer = is->is_scaninterval;
5847261Ssam 		return;
5857261Ssam 	}
5867261Ssam 	s = splimp();
5877261Ssam 	is->is_flags |= ILF_STATPENDING;
5887261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5897261Ssam 		ilstart(ifp->if_unit);
5907261Ssam 	splx(s);
5917261Ssam 	ifp->if_timer = is->is_scaninterval;
5927261Ssam }
5937261Ssam 
5947261Ssam /*
5957261Ssam  * Total up the on-board statistics.
5967261Ssam  */
5977261Ssam iltotal(is)
5987261Ssam 	register struct il_softc *is;
5997261Ssam {
6007261Ssam 	register u_short *interval, *sum, *end;
6017261Ssam 
6027261Ssam 	interval = &is->is_stats.ils_frames;
6037261Ssam 	sum = &is->is_sum.ils_frames;
6047261Ssam 	end = is->is_sum.ils_fill2;
6057261Ssam 	while (sum < end)
6067261Ssam 		*sum++ += *interval++;
6077261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6087261Ssam }
60913056Ssam 
61013056Ssam /*
61113056Ssam  * Process an ioctl request.
61213056Ssam  */
61313056Ssam ilioctl(ifp, cmd, data)
61413056Ssam 	register struct ifnet *ifp;
61513056Ssam 	int cmd;
61613056Ssam 	caddr_t data;
61713056Ssam {
61819865Skarels 	register struct ifaddr *ifa = (struct ifaddr *)data;
61913056Ssam 	int s = splimp(), error = 0;
62013056Ssam 
62113056Ssam 	switch (cmd) {
62213056Ssam 
62313056Ssam 	case SIOCSIFADDR:
62419865Skarels 		ifp->if_flags |= IFF_UP;
62513056Ssam 		ilinit(ifp->if_unit);
62619865Skarels 
62719865Skarels 		switch (ifa->ifa_addr.sa_family) {
62819865Skarels 		case AF_INET:
62919865Skarels 			((struct arpcom *)ifp)->ac_ipaddr =
63019865Skarels 				IA_SIN(ifa)->sin_addr;
63119865Skarels 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
63219865Skarels 			break;
63319865Skarels 		}
63413056Ssam 		break;
63513056Ssam 
63613056Ssam 	default:
63713056Ssam 		error = EINVAL;
63813056Ssam 	}
63913056Ssam 	splx(s);
64013056Ssam 	return (error);
64113056Ssam }
642