xref: /csrg-svn/sys/vax/if/if_il.c (revision 9797)
1*9797Ssam /*	if_il.c	4.17	82/12/17	*/
26893Sfeldman 
36893Sfeldman #include "il.h"
46893Sfeldman 
56893Sfeldman /*
66893Sfeldman  * Interlan Ethernet Communications Controller interface
76893Sfeldman  */
8*9797Ssam #include "../machine/pte.h"
9*9797Ssam 
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"
268419Swnj #include "../netpup/pup.h"
276893Sfeldman 
288463Sroot #include "../vax/cpu.h"
298463Sroot #include "../vax/mtpr.h"
309746Ssam #include "../vaxif/if_ether.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 
457220Ssam u_char	il_ectop[3] = { 0x02, 0x60, 0x8c };
467220Ssam u_char	ilbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
477220Ssam 
486893Sfeldman /*
496893Sfeldman  * Ethernet software status per interface.
506893Sfeldman  *
516893Sfeldman  * Each interface is referenced by a network interface structure,
526893Sfeldman  * is_if, which the routing code uses to locate the interface.
536893Sfeldman  * This structure contains the output queue for the interface, its address, ...
546893Sfeldman  * We also have, for each interface, a UBA interface structure, which
556893Sfeldman  * contains information about the UNIBUS resources held by the interface:
566893Sfeldman  * map registers, buffered data paths, etc.  Information is cached in this
576893Sfeldman  * structure for use by the if_uba.c routines in running the interface
586893Sfeldman  * efficiently.
596893Sfeldman  */
606893Sfeldman struct	il_softc {
616893Sfeldman 	struct	ifnet is_if;		/* network-visible interface */
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;
1127220Ssam 	ifp->if_net = ui->ui_flags;
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,
1267261Ssam 		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);
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);
1427261Ssam 	ifp->if_host[0] =
1437261Ssam 	    ((is->is_stats.ils_addr[3]&0xff)<<16) | 0x800000 |
1447261Ssam 	    ((is->is_stats.ils_addr[4]&0xff)<<8) |
1457261Ssam 	    (is->is_stats.ils_addr[5]&0xff);
1467220Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
1476893Sfeldman 	sin->sin_family = AF_INET;
1487220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]);
1496893Sfeldman 
1507220Ssam 	sin = (struct sockaddr_in *)&ifp->if_broadaddr;
1516893Sfeldman 	sin->sin_family = AF_INET;
1527220Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
1537220Ssam 	ifp->if_flags = IFF_BROADCAST;
1546893Sfeldman 
1557220Ssam 	ifp->if_init = ilinit;
1567220Ssam 	ifp->if_output = iloutput;
1578979Sroot 	ifp->if_reset = ilreset;
1587261Ssam 	ifp->if_watchdog = ilwatch;
1597261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1607261Ssam 	ifp->if_timer = is->is_scaninterval;
1616893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1627220Ssam #ifdef notdef
1637220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1647220Ssam #endif
1657220Ssam 	if_attach(ifp);
1666893Sfeldman }
1676893Sfeldman 
1686893Sfeldman /*
1696893Sfeldman  * Reset of interface after UNIBUS reset.
1706893Sfeldman  * If interface is on specified uba, reset its state.
1716893Sfeldman  */
1726893Sfeldman ilreset(unit, uban)
1736893Sfeldman 	int unit, uban;
1746893Sfeldman {
1756893Sfeldman 	register struct uba_device *ui;
1766893Sfeldman 
1776893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1786893Sfeldman 	    ui->ui_ubanum != uban)
1796893Sfeldman 		return;
1806893Sfeldman 	printf(" il%d", unit);
1816893Sfeldman 	ilinit(unit);
1826893Sfeldman }
1836893Sfeldman 
1846893Sfeldman /*
1856893Sfeldman  * Initialization of interface; clear recorded pending
1866893Sfeldman  * operations, and reinitialize UNIBUS usage.
1876893Sfeldman  */
1886893Sfeldman ilinit(unit)
1896893Sfeldman 	int unit;
1906893Sfeldman {
1916893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1926893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1936893Sfeldman 	register struct ildevice *addr;
1947261Ssam 	int s;
1956893Sfeldman 
1966893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1979746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
1986893Sfeldman 		printf("il%d: can't initialize\n", unit);
1996893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2006893Sfeldman 		return;
2016893Sfeldman 	}
2029179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
2037261Ssam 		sizeof (struct il_stats), 0);
2046893Sfeldman 	addr = (struct ildevice *)ui->ui_addr;
2056893Sfeldman 
2066893Sfeldman 	/*
2079179Ssam 	 * Turn off source address insertion (it's faster this way),
2089179Ssam 	 * and set board online.
2099179Ssam 	 */
2109179Ssam 	s = splimp();
2119179Ssam 	addr->il_csr = ILC_CISA;
2129179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2139179Ssam 		;
2149179Ssam 	addr->il_csr = ILC_ONLINE;
2159179Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
2169179Ssam 		;
2179179Ssam 	/*
2186893Sfeldman 	 * Set board online.
2196893Sfeldman 	 * Hang receive buffer and start any pending
2206893Sfeldman 	 * writes by faking a transmit complete.
2216893Sfeldman 	 * Receive bcr is not a muliple of 4 so buffer
2226893Sfeldman 	 * chaining can't happen.
2236893Sfeldman 	 */
2246893Sfeldman 	s = splimp();
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 =
2317261Ssam 		((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;
2356893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2367261Ssam 	is->is_lastcmd = 0;
2376893Sfeldman 	ilcint(unit);
2386893Sfeldman 	splx(s);
2397152Swnj 	if_rtinit(&is->is_if, RTF_UP);
2406893Sfeldman }
2416893Sfeldman 
2426893Sfeldman /*
2436893Sfeldman  * Start output on interface.
2446893Sfeldman  * Get another datagram to send off of the interface queue,
2456893Sfeldman  * and map it to the interface before starting the output.
2466893Sfeldman  */
2476893Sfeldman ilstart(dev)
2486893Sfeldman 	dev_t dev;
2496893Sfeldman {
2509179Ssam         int unit = ILUNIT(dev), len;
2516893Sfeldman 	struct uba_device *ui = ilinfo[unit];
2526893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2536893Sfeldman 	register struct ildevice *addr;
2546893Sfeldman 	struct mbuf *m;
2557220Ssam 	short csr;
2566893Sfeldman 
2576893Sfeldman 	IF_DEQUEUE(&is->is_if.if_snd, m);
2587261Ssam 	addr = (struct ildevice *)ui->ui_addr;
2597261Ssam 	if (m == 0) {
2607261Ssam 		if ((is->is_flags & ILF_STATPENDING) == 0)
2617261Ssam 			return;
2629179Ssam 		addr->il_bar = is->is_ubaddr & 0xffff;
2637261Ssam 		addr->il_bcr = sizeof (struct il_stats);
2647261Ssam 		csr = ((is->is_ubaddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
2657261Ssam 		is->is_flags &= ~ILF_STATPENDING;
2667261Ssam 		goto startcmd;
2677261Ssam 	}
2686893Sfeldman 	len = if_wubaput(&is->is_ifuba, m);
2699179Ssam 	/*
2709179Ssam 	 * Ensure minimum packet length.
2719179Ssam 	 * This makes the safe assumtion that there are no virtual holes
2729179Ssam 	 * after the data.
2739179Ssam 	 * For security, it might be wise to zero out the added bytes,
2749179Ssam 	 * but we're mainly interested in speed at the moment.
2759179Ssam 	 */
2769746Ssam 	if (len - sizeof(struct ether_header) < ETHERMIN)
2779746Ssam 		len = ETHERMIN + sizeof(struct ether_header);
2786893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
2796893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
2806893Sfeldman 	addr->il_bar = is->is_ifuba.ifu_w.ifrw_info & 0xffff;
2816893Sfeldman 	addr->il_bcr = len;
2827261Ssam 	csr =
2837261Ssam 	  ((is->is_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
2847261Ssam 
2857261Ssam startcmd:
2867261Ssam 	is->is_lastcmd = csr & IL_CMD;
2877220Ssam 	addr->il_csr = csr;
2887261Ssam 	is->is_flags |= ILF_OACTIVE;
2896893Sfeldman }
2906893Sfeldman 
2916893Sfeldman /*
2926893Sfeldman  * Command done interrupt.
2936893Sfeldman  */
2946893Sfeldman ilcint(unit)
2956893Sfeldman 	int unit;
2966893Sfeldman {
2976893Sfeldman 	register struct il_softc *is = &il_softc[unit];
2987220Ssam 	struct uba_device *ui = ilinfo[unit];
2996893Sfeldman 	register struct ildevice *addr = (struct ildevice *)ui->ui_addr;
3007266Ssam 	short csr;
3016893Sfeldman 
3027261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0) {
3037220Ssam 		printf("il%d: stray xmit interrupt, csr=%b\n", unit,
3047261Ssam 			addr->il_csr, IL_BITS);
3056893Sfeldman 		return;
3066893Sfeldman 	}
3077220Ssam 
3087266Ssam 	csr = addr->il_csr;
3096893Sfeldman 	/*
3107261Ssam 	 * Hang receive buffer if it couldn't
3117261Ssam 	 * be done earlier (in ilrint).
3126893Sfeldman 	 */
3137261Ssam 	if (is->is_flags & ILF_RCVPENDING) {
3146893Sfeldman 		addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
3159746Ssam 		addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
3167261Ssam 		addr->il_csr =
3177261Ssam 		  ((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
3187220Ssam 		while ((addr->il_csr & IL_CDONE) == 0)
3197220Ssam 			;
3207261Ssam 		is->is_flags &= ~ILF_RCVPENDING;
3216893Sfeldman 	}
3227261Ssam 	is->is_flags &= ~ILF_OACTIVE;
3237266Ssam 	csr &= IL_STATUS;
3247261Ssam 	switch (is->is_lastcmd) {
3257261Ssam 
3267261Ssam 	case ILC_XMIT:
3277261Ssam 		is->is_if.if_opackets++;
3287266Ssam 		if (csr > ILERR_RETRIES)
3297261Ssam 			is->is_if.if_oerrors++;
3307261Ssam 		break;
3317261Ssam 
3327261Ssam 	case ILC_STAT:
3337266Ssam 		if (csr == ILERR_SUCCESS)
3347261Ssam 			iltotal(is);
3357261Ssam 		break;
3367261Ssam 	}
3376893Sfeldman 	if (is->is_ifuba.ifu_xtofree) {
3386893Sfeldman 		m_freem(is->is_ifuba.ifu_xtofree);
3396893Sfeldman 		is->is_ifuba.ifu_xtofree = 0;
3406893Sfeldman 	}
3417261Ssam 	ilstart(unit);
3426893Sfeldman }
3436893Sfeldman 
3446893Sfeldman /*
3456893Sfeldman  * Ethernet interface receiver interrupt.
3466893Sfeldman  * If input error just drop packet.
3476893Sfeldman  * Otherwise purge input buffered data path and examine
3486893Sfeldman  * packet to determine type.  If can't determine length
3496893Sfeldman  * from type, then have to drop packet.  Othewise decapsulate
3506893Sfeldman  * packet based on type and pass to type specific higher-level
3516893Sfeldman  * input routine.
3526893Sfeldman  */
3536893Sfeldman ilrint(unit)
3546893Sfeldman 	int unit;
3556893Sfeldman {
3566893Sfeldman 	register struct il_softc *is = &il_softc[unit];
3576893Sfeldman 	struct ildevice *addr = (struct ildevice *)ilinfo[unit]->ui_addr;
3586893Sfeldman 	register struct il_rheader *il;
3596893Sfeldman     	struct mbuf *m;
3606893Sfeldman 	int len, off, resid;
3616893Sfeldman 	register struct ifqueue *inq;
3626893Sfeldman 
3636893Sfeldman 	is->is_if.if_ipackets++;
3646893Sfeldman 	if (is->is_ifuba.ifu_flags & UBA_NEEDBDP)
3656893Sfeldman 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
3666893Sfeldman 	il = (struct il_rheader *)(is->is_ifuba.ifu_r.ifrw_addr);
3676893Sfeldman 	len = il->ilr_length - sizeof(struct il_rheader);
3689746Ssam 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
3699746Ssam 	    len > ETHERMTU) {
3706893Sfeldman 		is->is_if.if_ierrors++;
3716893Sfeldman #ifdef notdef
3726893Sfeldman 		if (is->is_if.if_ierrors % 100 == 0)
3736893Sfeldman 			printf("il%d: += 100 input errors\n", unit);
3746893Sfeldman #endif
3756893Sfeldman 		goto setup;
3766893Sfeldman 	}
3776893Sfeldman 
3786893Sfeldman 	/*
3796893Sfeldman 	 * Deal with trailer protocol: if type is PUP trailer
3806893Sfeldman 	 * get true type from first 16-bit word past data.
3816893Sfeldman 	 * Remember that type was trailer by setting off.
3826893Sfeldman 	 */
3839746Ssam 	il->ilr_type = ntohs((u_short)il->ilr_type);
3846893Sfeldman #define	ildataaddr(il, off, type)	((type)(((caddr_t)((il)+1)+(off))))
3859746Ssam 	if (il->ilr_type >= ETHERPUP_TRAIL &&
3869746Ssam 	    il->ilr_type < ETHERPUP_TRAIL+ETHERPUP_NTRAILER) {
3879746Ssam 		off = (il->ilr_type - ETHERPUP_TRAIL) * 512;
3889746Ssam 		if (off >= ETHERMTU)
3896893Sfeldman 			goto setup;		/* sanity */
3909746Ssam 		il->ilr_type = ntohs(*ildataaddr(il, off, u_short *));
3919746Ssam 		resid = ntohs(*(ildataaddr(il, off+2, u_short *)));
3926893Sfeldman 		if (off + resid > len)
3936893Sfeldman 			goto setup;		/* sanity */
3946893Sfeldman 		len = off + resid;
3956893Sfeldman 	} else
3966893Sfeldman 		off = 0;
3976893Sfeldman 	if (len == 0)
3986893Sfeldman 		goto setup;
3996893Sfeldman 
4006893Sfeldman 	/*
4016893Sfeldman 	 * Pull packet off interface.  Off is nonzero if packet
4026893Sfeldman 	 * has trailing header; ilget will then force this header
4036893Sfeldman 	 * information to be at the front, but we still have to drop
4046893Sfeldman 	 * the type and length which are at the front of any trailer data.
4056893Sfeldman 	 */
4066893Sfeldman 	m = if_rubaget(&is->is_ifuba, len, off);
4076893Sfeldman 	if (m == 0)
4086893Sfeldman 		goto setup;
4096893Sfeldman 	if (off) {
4106893Sfeldman 		m->m_off += 2 * sizeof (u_short);
4116893Sfeldman 		m->m_len -= 2 * sizeof (u_short);
4126893Sfeldman 	}
4136893Sfeldman 	switch (il->ilr_type) {
4146893Sfeldman 
4156893Sfeldman #ifdef INET
4169746Ssam 	case ETHERPUP_IPTYPE:
4176893Sfeldman 		schednetisr(NETISR_IP);
4186893Sfeldman 		inq = &ipintrq;
4196893Sfeldman 		break;
4206893Sfeldman #endif
4216893Sfeldman 	default:
4226893Sfeldman 		m_freem(m);
4236893Sfeldman 		goto setup;
4246893Sfeldman 	}
4256893Sfeldman 
4266893Sfeldman 	if (IF_QFULL(inq)) {
4276893Sfeldman 		IF_DROP(inq);
4286893Sfeldman 		m_freem(m);
4297220Ssam 		goto setup;
4307220Ssam 	}
4317220Ssam 	IF_ENQUEUE(inq, m);
4326893Sfeldman 
4336893Sfeldman setup:
4346893Sfeldman 	/*
4356893Sfeldman 	 * Reset for next packet if possible.
4366893Sfeldman 	 * If waiting for transmit command completion, set flag
4376893Sfeldman 	 * and wait until command completes.
4386893Sfeldman 	 */
4397261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4407261Ssam 		is->is_flags |= ILF_RCVPENDING;
4417220Ssam 		return;
4427220Ssam 	}
4437220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4449746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4457261Ssam 	addr->il_csr =
4467261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4477220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4487220Ssam 		;
4496893Sfeldman }
4506893Sfeldman 
4516893Sfeldman /*
4526893Sfeldman  * Ethernet output routine.
4536893Sfeldman  * Encapsulate a packet of type family for the local net.
4546893Sfeldman  * Use trailer local net encapsulation if enough data in first
4556893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4566893Sfeldman  */
4576893Sfeldman iloutput(ifp, m0, dst)
4586893Sfeldman 	struct ifnet *ifp;
4596893Sfeldman 	struct mbuf *m0;
4606893Sfeldman 	struct sockaddr *dst;
4616893Sfeldman {
4626893Sfeldman 	int type, dest, s, error;
4636893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4646893Sfeldman 	register struct mbuf *m = m0;
4659746Ssam 	register struct ether_header *il;
4669179Ssam 	register int off;
4676893Sfeldman 
4686893Sfeldman 	switch (dst->sa_family) {
4696893Sfeldman 
4706893Sfeldman #ifdef INET
4716893Sfeldman 	case AF_INET:
4726893Sfeldman 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
4736893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4746893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4756893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4769746Ssam 			type = ETHERPUP_TRAIL + (off>>9);
4776893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4786893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4799746Ssam 			*mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE);
4809746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4816893Sfeldman 			goto gottrailertype;
4826893Sfeldman 		}
4839746Ssam 		type = ETHERPUP_IPTYPE;
4846893Sfeldman 		off = 0;
4856893Sfeldman 		goto gottype;
4866893Sfeldman #endif
4876893Sfeldman 
4886893Sfeldman 	default:
4896893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
4906893Sfeldman 			dst->sa_family);
4916893Sfeldman 		error = EAFNOSUPPORT;
4926893Sfeldman 		goto bad;
4936893Sfeldman 	}
4946893Sfeldman 
4956893Sfeldman gottrailertype:
4966893Sfeldman 	/*
4976893Sfeldman 	 * Packet to be sent as trailer: move first packet
4986893Sfeldman 	 * (control information) to end of chain.
4996893Sfeldman 	 */
5006893Sfeldman 	while (m->m_next)
5016893Sfeldman 		m = m->m_next;
5026893Sfeldman 	m->m_next = m0;
5036893Sfeldman 	m = m0->m_next;
5046893Sfeldman 	m0->m_next = 0;
5056893Sfeldman 	m0 = m;
5066893Sfeldman 
5076893Sfeldman gottype:
5086893Sfeldman 	/*
5096893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5106893Sfeldman 	 * allocate another.
5116893Sfeldman 	 */
5126893Sfeldman 	if (m->m_off > MMAXOFF ||
5139746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5149650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5156893Sfeldman 		if (m == 0) {
5166893Sfeldman 			error = ENOBUFS;
5176893Sfeldman 			goto bad;
5186893Sfeldman 		}
5196893Sfeldman 		m->m_next = m0;
5206893Sfeldman 		m->m_off = MMINOFF;
5219746Ssam 		m->m_len = sizeof (struct ether_header);
5226893Sfeldman 	} else {
5239746Ssam 		m->m_off -= sizeof (struct ether_header);
5249746Ssam 		m->m_len += sizeof (struct ether_header);
5256893Sfeldman 	}
5269746Ssam 	il = mtod(m, struct ether_header *);
5276893Sfeldman 	if ((dest &~ 0xff) == 0)
5289746Ssam 		bcopy((caddr_t)ilbroadcastaddr, (caddr_t)il->ether_dhost, 6);
5296893Sfeldman 	else {
5307261Ssam 		u_char *to = dest & 0x8000 ? is->is_stats.ils_addr : il_ectop;
5317220Ssam 
5329746Ssam 		bcopy((caddr_t)to, (caddr_t)il->ether_dhost, 3);
5339746Ssam 		il->ether_dhost[3] = (dest>>8) & 0x7f;
5349746Ssam 		il->ether_dhost[4] = (dest>>16) & 0xff;
5359746Ssam 		il->ether_dhost[5] = (dest>>24) & 0xff;
5366893Sfeldman 	}
5379746Ssam 	bcopy((caddr_t)is->is_stats.ils_addr, (caddr_t)il->ether_shost, 6);
5389746Ssam 	il->ether_type = htons((u_short)type);
5396893Sfeldman 
5406893Sfeldman 	/*
5416893Sfeldman 	 * Queue message on interface, and start output if interface
5426893Sfeldman 	 * not yet active.
5436893Sfeldman 	 */
5446893Sfeldman 	s = splimp();
5456893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5466893Sfeldman 		IF_DROP(&ifp->if_snd);
5477220Ssam 		splx(s);
5487220Ssam 		m_freem(m);
5497220Ssam 		return (ENOBUFS);
5506893Sfeldman 	}
5516893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5527261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5536893Sfeldman 		ilstart(ifp->if_unit);
5546893Sfeldman 	splx(s);
5556893Sfeldman 	return (0);
5567220Ssam 
5576893Sfeldman bad:
5586893Sfeldman 	m_freem(m0);
5597220Ssam 	return (error);
5606893Sfeldman }
5617261Ssam 
5627261Ssam /*
5637261Ssam  * Watchdog routine, request statistics from board.
5647261Ssam  */
5657261Ssam ilwatch(unit)
5667261Ssam 	int unit;
5677261Ssam {
5687261Ssam 	register struct il_softc *is = &il_softc[unit];
5697261Ssam 	register struct ifnet *ifp = &is->is_if;
5707261Ssam 	int s;
5717261Ssam 
5727261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5737261Ssam 		ifp->if_timer = is->is_scaninterval;
5747261Ssam 		return;
5757261Ssam 	}
5767261Ssam 	s = splimp();
5777261Ssam 	is->is_flags |= ILF_STATPENDING;
5787261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5797261Ssam 		ilstart(ifp->if_unit);
5807261Ssam 	splx(s);
5817261Ssam 	ifp->if_timer = is->is_scaninterval;
5827261Ssam }
5837261Ssam 
5847261Ssam /*
5857261Ssam  * Total up the on-board statistics.
5867261Ssam  */
5877261Ssam iltotal(is)
5887261Ssam 	register struct il_softc *is;
5897261Ssam {
5907261Ssam 	register u_short *interval, *sum, *end;
5917261Ssam 
5927261Ssam 	interval = &is->is_stats.ils_frames;
5937261Ssam 	sum = &is->is_sum.ils_frames;
5947261Ssam 	end = is->is_sum.ils_fill2;
5957261Ssam 	while (sum < end)
5967261Ssam 		*sum++ += *interval++;
5977261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
5987261Ssam }
599