xref: /csrg-svn/sys/vax/if/if_il.c (revision 19865)
1*19865Skarels /*	if_il.c	6.6	85/05/01	*/
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"
25*19865Skarels #include "../netinet/in_var.h"
268419Swnj #include "../netinet/ip.h"
278419Swnj #include "../netinet/ip_var.h"
2811575Ssam #include "../netinet/if_ether.h"
298419Swnj #include "../netpup/pup.h"
306893Sfeldman 
318463Sroot #include "../vax/cpu.h"
328463Sroot #include "../vax/mtpr.h"
3317115Sbloom #include "if_il.h"
3417115Sbloom #include "if_ilreg.h"
3517115Sbloom #include "if_uba.h"
368463Sroot #include "../vaxuba/ubareg.h"
378463Sroot #include "../vaxuba/ubavar.h"
388463Sroot 
396893Sfeldman int	ilprobe(), ilattach(), ilrint(), ilcint();
406893Sfeldman struct	uba_device *ilinfo[NIL];
416893Sfeldman u_short ilstd[] = { 0 };
426893Sfeldman struct	uba_driver ildriver =
436893Sfeldman 	{ ilprobe, 0, ilattach, 0, ilstd, "il", ilinfo };
446893Sfeldman #define	ILUNIT(x)	minor(x)
4513056Ssam int	ilinit(),iloutput(),ilioctl(),ilreset(),ilwatch();
466893Sfeldman 
476893Sfeldman /*
486893Sfeldman  * Ethernet software status per interface.
496893Sfeldman  *
506893Sfeldman  * Each interface is referenced by a network interface structure,
516893Sfeldman  * is_if, which the routing code uses to locate the interface.
526893Sfeldman  * This structure contains the output queue for the interface, its address, ...
536893Sfeldman  * We also have, for each interface, a UBA interface structure, which
546893Sfeldman  * contains information about the UNIBUS resources held by the interface:
556893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
566893Sfeldman  * structure for use by the if_uba.c routines in running the interface
576893Sfeldman  * efficiently.
586893Sfeldman  */
596893Sfeldman struct	il_softc {
6011575Ssam 	struct	arpcom is_ac;		/* Ethernet common part */
6111575Ssam #define	is_if	is_ac.ac_if		/* network-visible interface */
6211575Ssam #define	is_addr	is_ac.ac_enaddr		/* hardware Ethernet address */
636893Sfeldman 	struct	ifuba is_ifuba;		/* UNIBUS resources */
647261Ssam 	int	is_flags;
657261Ssam #define	ILF_OACTIVE	0x1		/* output is active */
667261Ssam #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
677261Ssam #define	ILF_STATPENDING	0x4		/* stat cmd pending */
687261Ssam 	short	is_lastcmd;		/* can't read csr, so must save it */
697261Ssam 	short	is_scaninterval;	/* interval of stat collection */
707261Ssam #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
717261Ssam 	struct	il_stats is_stats;	/* holds on-board statistics */
727261Ssam 	struct	il_stats is_sum;	/* summation over time */
737261Ssam 	int	is_ubaddr;		/* mapping registers of is_stats */
746893Sfeldman } il_softc[NIL];
756893Sfeldman 
766893Sfeldman ilprobe(reg)
776893Sfeldman 	caddr_t reg;
786893Sfeldman {
796893Sfeldman 	register int br, cvec;		/* r11, r10 value-result */
806893Sfeldman 	register struct ildevice *addr = (struct ildevice *)reg;
816893Sfeldman 	register i;
826893Sfeldman 
836893Sfeldman #ifdef lint
846893Sfeldman 	br = 0; cvec = br; br = cvec;
859179Ssam 	i = 0; ilrint(i); ilcint(i); ilwatch(i);
866893Sfeldman #endif
876893Sfeldman 
886893Sfeldman 	addr->il_csr = ILC_OFFLINE|IL_CIE;
896893Sfeldman 	DELAY(100000);
907261Ssam 	i = addr->il_csr;		/* clear CDONE */
916893Sfeldman 	if (cvec > 0 && cvec != 0x200)
926893Sfeldman 		cvec -= 4;
936893Sfeldman 	return (1);
946893Sfeldman }
956893Sfeldman 
966893Sfeldman /*
976893Sfeldman  * Interface exists: make available by filling in network interface
986893Sfeldman  * record.  System will initialize the interface when it is ready
996893Sfeldman  * to accept packets.  A STATUS command is done to get the ethernet
1006893Sfeldman  * address and other interesting data.
1016893Sfeldman  */
1026893Sfeldman ilattach(ui)
1036893Sfeldman 	struct uba_device *ui;
1046893Sfeldman {
1056893Sfeldman 	register struct il_softc *is = &il_softc[ui->ui_unit];
1067220Ssam 	register struct ifnet *ifp = &is->is_if;
1076893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
1086893Sfeldman 
1097220Ssam 	ifp->if_unit = ui->ui_unit;
1107220Ssam 	ifp->if_name = "il";
1119746Ssam 	ifp->if_mtu = ETHERMTU;
112*19865Skarels 	ifp->if_flags = IFF_BROADCAST;
1136893Sfeldman 
1146893Sfeldman 	/*
1157261Ssam 	 * Reset the board and map the statistics
1167261Ssam 	 * buffer onto the Unibus.
1176893Sfeldman 	 */
1187261Ssam 	addr->il_csr = ILC_RESET;
1197261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1207261Ssam 		;
1217261Ssam 	if (addr->il_csr&IL_STATUS)
1227261Ssam 		printf("il%d: reset failed, csr=%b\n", ui->ui_unit,
1237261Ssam 			addr->il_csr, IL_BITS);
1246893Sfeldman 
1259179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
12613056Ssam 	    sizeof (struct il_stats), 0);
1277261Ssam 	addr->il_bar = is->is_ubaddr & 0xffff;
1287261Ssam 	addr->il_bcr = sizeof (struct il_stats);
1297261Ssam 	addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT;
1307261Ssam 	while ((addr->il_csr&IL_CDONE) == 0)
1317261Ssam 		;
1327261Ssam 	if (addr->il_csr&IL_STATUS)
1337261Ssam 		printf("il%d: status failed, csr=%b\n", ui->ui_unit,
1347261Ssam 			addr->il_csr, IL_BITS);
1357261Ssam 	ubarelse(ui->ui_ubanum, &is->is_ubaddr);
13611575Ssam #ifdef notdef
1376893Sfeldman 	printf("il%d: addr=%x:%x:%x:%x:%x:%x module=%s firmware=%s\n",
1386893Sfeldman 		ui->ui_unit,
1397261Ssam 		is->is_stats.ils_addr[0]&0xff, is->is_stats.ils_addr[1]&0xff,
1407261Ssam 		is->is_stats.ils_addr[2]&0xff, is->is_stats.ils_addr[3]&0xff,
1417261Ssam 		is->is_stats.ils_addr[4]&0xff, is->is_stats.ils_addr[5]&0xff,
1427261Ssam 		is->is_stats.ils_module, is->is_stats.ils_firmware);
14311575Ssam #endif
144*19865Skarels  	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)is->is_addr,
145*19865Skarels  	    sizeof (is->is_addr));
1467220Ssam 	ifp->if_init = ilinit;
1477220Ssam 	ifp->if_output = iloutput;
14813056Ssam 	ifp->if_ioctl = ilioctl;
1498979Sroot 	ifp->if_reset = ilreset;
1506893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1517220Ssam #ifdef notdef
1527220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1537220Ssam #endif
1547220Ssam 	if_attach(ifp);
1556893Sfeldman }
1566893Sfeldman 
1576893Sfeldman /*
1586893Sfeldman  * Reset of interface after UNIBUS reset.
1596893Sfeldman  * If interface is on specified uba, reset its state.
1606893Sfeldman  */
1616893Sfeldman ilreset(unit, uban)
1626893Sfeldman 	int unit, uban;
1636893Sfeldman {
1646893Sfeldman 	register struct uba_device *ui;
1656893Sfeldman 
1666893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1676893Sfeldman 	    ui->ui_ubanum != uban)
1686893Sfeldman 		return;
1696893Sfeldman 	printf(" il%d", unit);
1706893Sfeldman 	ilinit(unit);
1716893Sfeldman }
1726893Sfeldman 
1736893Sfeldman /*
1746893Sfeldman  * Initialization of interface; clear recorded pending
1756893Sfeldman  * operations, and reinitialize UNIBUS usage.
1766893Sfeldman  */
1776893Sfeldman ilinit(unit)
1786893Sfeldman 	int unit;
1796893Sfeldman {
1806893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1816893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1826893Sfeldman 	register struct ildevice *addr;
18313056Ssam 	register struct ifnet *ifp = &is->is_if;
1847261Ssam 	int s;
1856893Sfeldman 
186*19865Skarels 	/* not yet, if address still unknown */
187*19865Skarels 	if (ifp->if_addrlist == (struct ifaddr *)0)
18811575Ssam 		return;
18911575Ssam 
19013056Ssam 	if (ifp->if_flags & IFF_RUNNING)
191*19865Skarels 		return;
1926893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1939746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
1946893Sfeldman 		printf("il%d: can't initialize\n", unit);
1956893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
1966893Sfeldman 		return;
1976893Sfeldman 	}
1989179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
19913056Ssam 	    sizeof (struct il_stats), 0);
20015071Skarels 	ifp->if_watchdog = ilwatch;
20115071Skarels 	is->is_scaninterval = ILWATCHINTERVAL;
20215071Skarels 	ifp->if_timer = is->is_scaninterval;
2036893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2046893Sfeldman 
2056893Sfeldman 	/*
2069179Ssam 	 * Turn off source address insertion (it's faster this way),
20712488Ssam 	 * and set board online.  Former doesn't work if board is
20812488Ssam 	 * already online (happens on ubareset), so we put it offline
20912488Ssam 	 * first.
2109179Ssam 	 */
2119179Ssam 	s = splimp();
21212488Ssam 	addr->il_csr = ILC_OFFLINE;
2139179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2149179Ssam 		;
21512488Ssam 	addr->il_csr = ILC_CISA;
2169179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2179179Ssam 		;
2189179Ssam 	/*
2196893Sfeldman 	 * Set board online.
2206893Sfeldman 	 * Hang receive buffer and start any pending
2216893Sfeldman 	 * writes by faking a transmit complete.
2226893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2236893Sfeldman 	 * chaining can't happen.
2246893Sfeldman 	 */
2256893Sfeldman 	addr->il_csr = ILC_ONLINE;
2267220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2277220Ssam 		;
2286893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
2299746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
2307261Ssam 	addr->il_csr =
23113056Ssam 	    ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
2327220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2337220Ssam 		;
2347261Ssam 	is->is_flags = ILF_OACTIVE;
235*19865Skarels 	is->is_if.if_flags |= IFF_RUNNING;
2367261Ssam 	is->is_lastcmd = 0;
2376893Sfeldman 	ilcint(unit);
2386893Sfeldman 	splx(s);
2396893Sfeldman }
2406893Sfeldman 
2416893Sfeldman /*
2426893Sfeldman  * Start output on interface.
2436893Sfeldman  * Get another datagram to send off of the interface queue,
2446893Sfeldman  * and map it to the interface before starting the output.
2456893Sfeldman  */
2466893Sfeldman ilstart(dev)
2476893Sfeldman 	dev_t dev;
2486893Sfeldman {
2499179Ssam         int unit = ILUNIT(dev), len;
2506893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2516893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2526893Sfeldman 	register struct ildevice *addr;
2536893Sfeldman 	struct mbuf *m;
2547220Ssam 	short csr;
2556893Sfeldman 
2566893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2577261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2587261Ssam 	if (m == 0) {
2597261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2607261Ssam 			return;
2619179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2627261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2637261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2647261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2657261Ssam 		goto startcmd;
2667261Ssam 	}
2676893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2689179Ssam 	/*
2699179Ssam 	 * Ensure minimum packet length.
2709179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2719179Ssam 	 * after the data.
2729179Ssam 	 * For security, it might be wise to zero out the added bytes,
2739179Ssam 	 * but we're mainly interested in speed at the moment.
2749179Ssam 	 */
2759746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2769746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
2776893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2786893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2796893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2806893Sfeldman 	addr->il_bcr = len;
2817261Ssam 	csr =
2827261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2837261Ssam 
2847261Ssam startcmd:
2857261Ssam 	is->is_lastcmd = csr & IL_CMD;
2867220Ssam 	addr->il_csr = csr;
2877261Ssam 	is->is_flags |= ILF_OACTIVE;
2886893Sfeldman }
2896893Sfeldman 
2906893Sfeldman /*
2916893Sfeldman  * Command done interrupt.
2926893Sfeldman  */
2936893Sfeldman ilcint(unit)
2946893Sfeldman 	int unit;
2956893Sfeldman {
2966893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2977220Ssam 	struct uba_device *ui = ilinfo[unit];
2986893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
2997266Ssam 	short csr;
3006893Sfeldman 
3017261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3027220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3037261Ssam 			addr->il_csr, IL_BITS);
3046893Sfeldman 		return;
3056893Sfeldman 	}
3067220Ssam 
3077266Ssam 	csr = addr->il_csr;
3086893Sfeldman 	/*
3097261Ssam 	 * Hang receive buffer if it couldn't
3107261Ssam 	 * be done earlier (in ilrint).
3116893Sfeldman 	 */
3127261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3136893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3149746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
3157261Ssam 		addr->il_csr =
3167261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3177220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3187220Ssam 			;
3197261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3206893Sfeldman 	}
3217261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3227266Ssam 	csr &= IL_STATUS;
3237261Ssam 	switch (is->is_lastcmd) {
3247261Ssam 
3257261Ssam 	case ILC_XMIT:
3267261Ssam 		is->is_if.if_opackets++;
3277266Ssam 		if (csr > ILERR_RETRIES)
3287261Ssam 			is->is_if.if_oerrors++;
3297261Ssam 		break;
3307261Ssam 
3317261Ssam 	case ILC_STAT:
3327266Ssam 		if (csr == ILERR_SUCCESS)
3337261Ssam 			iltotal(is);
3347261Ssam 		break;
3357261Ssam 	}
3366893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3376893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3386893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3396893Sfeldman 	}
3407261Ssam 	ilstart(unit);
3416893Sfeldman }
3426893Sfeldman 
3436893Sfeldman /*
3446893Sfeldman  * Ethernet interface receiver interrupt.
3456893Sfeldman  * If input error just drop packet.
3466893Sfeldman  * Otherwise purge input buffered data path and examine
3476893Sfeldman  * packet to determine type.  If can't determine length
3486893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3496893Sfeldman  * packet based on type and pass to type specific higher-level
3506893Sfeldman  * input routine.
3516893Sfeldman  */
3526893Sfeldman ilrint(unit)
3536893Sfeldman 	int unit;
3546893Sfeldman {
3556893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3566893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3576893Sfeldman 	register struct il_rheader *il;
3586893Sfeldman     	struct mbuf *m;
35915787Sleres 	int len, off, resid, s;
3606893Sfeldman 	register struct ifqueue *inq;
3616893Sfeldman 
3626893Sfeldman 	is->is_if.if_ipackets++;
3636893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3646893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3656893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3666893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3679746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3689746Ssam 	    len > ETHERMTU) {
3696893Sfeldman 		is->is_if.if_ierrors++;
3706893Sfeldman #ifdef notdef
3716893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3726893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3736893Sfeldman #endif
3746893Sfeldman 		goto setup;
3756893Sfeldman 	}
3766893Sfeldman 
3776893Sfeldman 	/*
378*19865Skarels 	 * Deal with trailer protocol: if type is trailer type
3796893Sfeldman 	 * get true type from first 16-bit word past data.
3806893Sfeldman 	 * Remember that type was trailer by setting off.
3816893Sfeldman 	 */
3829746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3836893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
384*19865Skarels 	if (il->ilr_type >= ETHERTYPE_TRAIL &&
385*19865Skarels 	    il->ilr_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
386*19865Skarels 		off = (il->ilr_type - ETHERTYPE_TRAIL) * 512;
3879746Ssam 		if (off >= ETHERMTU)
3886893Sfeldman 			goto setup;		/* sanity */
3899746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
3909746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
3916893Sfeldman 		if (off + resid > len)
3926893Sfeldman 			goto setup;		/* sanity */
3936893Sfeldman 		len = off + resid;
3946893Sfeldman 	} else
3956893Sfeldman 		off = 0;
3966893Sfeldman 	if (len == 0)
3976893Sfeldman 		goto setup;
3986893Sfeldman 
3996893Sfeldman 	/*
4006893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4016893Sfeldman 	 * has trailing header; ilget will then force this header
4026893Sfeldman 	 * information to be at the front, but we still have to drop
4036893Sfeldman 	 * the type and length which are at the front of any trailer data.
4046893Sfeldman 	 */
4056893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4066893Sfeldman 	if (m == 0)
4076893Sfeldman 		goto setup;
4086893Sfeldman 	if (off) {
4096893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4106893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4116893Sfeldman 	}
4126893Sfeldman 	switch (il->ilr_type) {
4136893Sfeldman 
4146893Sfeldman #ifdef INET
415*19865Skarels 	case ETHERTYPE_IP:
4166893Sfeldman 		schednetisr(NETISR_IP);
4176893Sfeldman 		inq = &ipintrq;
4186893Sfeldman 		break;
41911575Ssam 
420*19865Skarels 	case ETHERTYPE_ARP:
42111575Ssam 		arpinput(&is->is_ac, m);
42213988Ssam 		goto setup;
4236893Sfeldman #endif
4246893Sfeldman 	default:
4256893Sfeldman 		m_freem(m);
4266893Sfeldman 		goto setup;
4276893Sfeldman 	}
4286893Sfeldman 
42915787Sleres 	s = splimp();
4306893Sfeldman 	if (IF_QFULL(inq)) {
4316893Sfeldman 		IF_DROP(inq);
4326893Sfeldman 		m_freem(m);
43315787Sleres 	} else
43415787Sleres 		IF_ENQUEUE(inq, m);
43515787Sleres 	splx(s);
4366893Sfeldman 
4376893Sfeldman setup:
4386893Sfeldman 	/*
4396893Sfeldman 	 * Reset for next packet if possible.
4406893Sfeldman 	 * If waiting for transmit command completion, set flag
4416893Sfeldman 	 * and wait until command completes.
4426893Sfeldman 	 */
4437261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4447261Ssam 		is->is_flags |= ILF_RCVPENDING;
4457220Ssam 		return;
4467220Ssam 	}
4477220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4489746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4497261Ssam 	addr->il_csr =
4507261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4517220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4527220Ssam 		;
4536893Sfeldman }
4546893Sfeldman 
4556893Sfeldman /*
4566893Sfeldman  * Ethernet output routine.
4576893Sfeldman  * Encapsulate a packet of type family for the local net.
4586893Sfeldman  * Use trailer local net encapsulation if enough data in first
4596893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4606893Sfeldman  */
4616893Sfeldman iloutput(ifp, m0, dst)
4626893Sfeldman 	struct ifnet *ifp;
4636893Sfeldman 	struct mbuf *m0;
4646893Sfeldman 	struct sockaddr *dst;
4656893Sfeldman {
46611575Ssam 	int type, s, error;
467*19865Skarels  	u_char edst[6];
46811575Ssam 	struct in_addr idst;
4696893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4706893Sfeldman 	register struct mbuf *m = m0;
4719746Ssam 	register struct ether_header *il;
4729179Ssam 	register int off;
4736893Sfeldman 
4746893Sfeldman 	switch (dst->sa_family) {
4756893Sfeldman 
4766893Sfeldman #ifdef INET
4776893Sfeldman 	case AF_INET:
47811575Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
479*19865Skarels  		if (!arpresolve(&is->is_ac, m, &idst, edst))
48011575Ssam 			return (0);	/* if not yet resolved */
4816893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
48213056Ssam 		/* need per host negotiation */
48313056Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
4846893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4856893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
486*19865Skarels 			type = ETHERTYPE_TRAIL + (off>>9);
4876893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4886893Sfeldman 			m->m_len += 2 * sizeof (u_short);
489*19865Skarels 			*mtod(m, u_short *) = htons((u_short)ETHERTYPE_IP);
4909746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4916893Sfeldman 			goto gottrailertype;
4926893Sfeldman 		}
493*19865Skarels 		type = ETHERTYPE_IP;
4946893Sfeldman 		off = 0;
4956893Sfeldman 		goto gottype;
4966893Sfeldman #endif
4976893Sfeldman 
49811575Ssam 	case AF_UNSPEC:
49911575Ssam 		il = (struct ether_header *)dst->sa_data;
500*19865Skarels  		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
50111575Ssam 		type = il->ether_type;
50211575Ssam 		goto gottype;
50311575Ssam 
5046893Sfeldman 	default:
5056893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5066893Sfeldman 			dst->sa_family);
5076893Sfeldman 		error = EAFNOSUPPORT;
5086893Sfeldman 		goto bad;
5096893Sfeldman 	}
5106893Sfeldman 
5116893Sfeldman gottrailertype:
5126893Sfeldman 	/*
5136893Sfeldman 	 * Packet to be sent as trailer: move first packet
5146893Sfeldman 	 * (control information) to end of chain.
5156893Sfeldman 	 */
5166893Sfeldman 	while (m->m_next)
5176893Sfeldman 		m = m->m_next;
5186893Sfeldman 	m->m_next = m0;
5196893Sfeldman 	m = m0->m_next;
5206893Sfeldman 	m0->m_next = 0;
5216893Sfeldman 	m0 = m;
5226893Sfeldman 
5236893Sfeldman gottype:
5246893Sfeldman 	/*
5256893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5266893Sfeldman 	 * allocate another.
5276893Sfeldman 	 */
5286893Sfeldman 	if (m->m_off > MMAXOFF ||
5299746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5309650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5316893Sfeldman 		if (m == 0) {
5326893Sfeldman 			error = ENOBUFS;
5336893Sfeldman 			goto bad;
5346893Sfeldman 		}
5356893Sfeldman 		m->m_next = m0;
5366893Sfeldman 		m->m_off = MMINOFF;
5379746Ssam 		m->m_len = sizeof (struct ether_header);
5386893Sfeldman 	} else {
5399746Ssam 		m->m_off -= sizeof (struct ether_header);
5409746Ssam 		m->m_len += sizeof (struct ether_header);
5416893Sfeldman 	}
5429746Ssam 	il = mtod(m, struct ether_header *);
5439746Ssam 	il->ether_type = htons((u_short)type);
544*19865Skarels  	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
545*19865Skarels  	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost,
546*19865Skarels 	    sizeof(il->ether_shost));
5476893Sfeldman 
5486893Sfeldman 	/*
5496893Sfeldman 	 * Queue message on interface, and start output if interface
5506893Sfeldman 	 * not yet active.
5516893Sfeldman 	 */
5526893Sfeldman 	s = splimp();
5536893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5546893Sfeldman 		IF_DROP(&ifp->if_snd);
5557220Ssam 		splx(s);
5567220Ssam 		m_freem(m);
5577220Ssam 		return (ENOBUFS);
5586893Sfeldman 	}
5596893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5607261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5616893Sfeldman 		ilstart(ifp->if_unit);
5626893Sfeldman 	splx(s);
5636893Sfeldman 	return (0);
5647220Ssam 
5656893Sfeldman bad:
5666893Sfeldman 	m_freem(m0);
5677220Ssam 	return (error);
5686893Sfeldman }
5697261Ssam 
5707261Ssam /*
5717261Ssam  * Watchdog routine, request statistics from board.
5727261Ssam  */
5737261Ssam ilwatch(unit)
5747261Ssam 	int unit;
5757261Ssam {
5767261Ssam 	register struct il_softc *is = &il_softc[unit];
5777261Ssam 	register struct ifnet *ifp = &is->is_if;
5787261Ssam 	int s;
5797261Ssam 
5807261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5817261Ssam 		ifp->if_timer = is->is_scaninterval;
5827261Ssam 		return;
5837261Ssam 	}
5847261Ssam 	s = splimp();
5857261Ssam 	is->is_flags |= ILF_STATPENDING;
5867261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5877261Ssam 		ilstart(ifp->if_unit);
5887261Ssam 	splx(s);
5897261Ssam 	ifp->if_timer = is->is_scaninterval;
5907261Ssam }
5917261Ssam 
5927261Ssam /*
5937261Ssam  * Total up the on-board statistics.
5947261Ssam  */
5957261Ssam iltotal(is)
5967261Ssam 	register struct il_softc *is;
5977261Ssam {
5987261Ssam 	register u_short *interval, *sum, *end;
5997261Ssam 
6007261Ssam 	interval = &is->is_stats.ils_frames;
6017261Ssam 	sum = &is->is_sum.ils_frames;
6027261Ssam 	end = is->is_sum.ils_fill2;
6037261Ssam 	while (sum < end)
6047261Ssam 		*sum++ += *interval++;
6057261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6067261Ssam }
60713056Ssam 
60813056Ssam /*
60913056Ssam  * Process an ioctl request.
61013056Ssam  */
61113056Ssam ilioctl(ifp, cmd, data)
61213056Ssam 	register struct ifnet *ifp;
61313056Ssam 	int cmd;
61413056Ssam 	caddr_t data;
61513056Ssam {
616*19865Skarels 	register struct ifaddr *ifa = (struct ifaddr *)data;
61713056Ssam 	int s = splimp(), error = 0;
61813056Ssam 
61913056Ssam 	switch (cmd) {
62013056Ssam 
62113056Ssam 	case SIOCSIFADDR:
622*19865Skarels 		ifp->if_flags |= IFF_UP;
62313056Ssam 		ilinit(ifp->if_unit);
624*19865Skarels 
625*19865Skarels 		switch (ifa->ifa_addr.sa_family) {
626*19865Skarels 		case AF_INET:
627*19865Skarels 			((struct arpcom *)ifp)->ac_ipaddr =
628*19865Skarels 				IA_SIN(ifa)->sin_addr;
629*19865Skarels 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
630*19865Skarels 			break;
631*19865Skarels 		}
63213056Ssam 		break;
63313056Ssam 
63413056Ssam 	default:
63513056Ssam 		error = EINVAL;
63613056Ssam 	}
63713056Ssam 	splx(s);
63813056Ssam 	return (error);
63913056Ssam }
640