xref: /csrg-svn/sys/vax/if/if_il.c (revision 13056)
1*13056Ssam /*	if_il.c	4.21	83/06/12	*/
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"
17*13056Ssam #include "../h/ioctl.h"
18*13056Ssam #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)
44*13056Ssam 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,
125*13056Ssam 	    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;
150*13056Ssam 	ifp->if_ioctl = ilioctl;
1518979Sroot 	ifp->if_reset = ilreset;
1527261Ssam 	ifp->if_watchdog = ilwatch;
1537261Ssam 	is->is_scaninterval = ILWATCHINTERVAL;
1547261Ssam 	ifp->if_timer = is->is_scaninterval;
1556893Sfeldman 	is->is_ifuba.ifu_flags = UBA_CANTWAIT;
1567220Ssam #ifdef notdef
1577220Ssam 	is->is_ifuba.ifu_flags |= UBA_NEEDBDP;
1587220Ssam #endif
1597220Ssam 	if_attach(ifp);
1606893Sfeldman }
1616893Sfeldman 
1626893Sfeldman /*
1636893Sfeldman  * Reset of interface after UNIBUS reset.
1646893Sfeldman  * If interface is on specified uba, reset its state.
1656893Sfeldman  */
1666893Sfeldman ilreset(unit, uban)
1676893Sfeldman 	int unit, uban;
1686893Sfeldman {
1696893Sfeldman 	register struct uba_device *ui;
1706893Sfeldman 
1716893Sfeldman 	if (unit >= NIL || (ui = ilinfo[unit]) == 0 || ui->ui_alive == 0 ||
1726893Sfeldman 	    ui->ui_ubanum != uban)
1736893Sfeldman 		return;
1746893Sfeldman 	printf(" il%d", unit);
1756893Sfeldman 	ilinit(unit);
1766893Sfeldman }
1776893Sfeldman 
1786893Sfeldman /*
1796893Sfeldman  * Initialization of interface; clear recorded pending
1806893Sfeldman  * operations, and reinitialize UNIBUS usage.
1816893Sfeldman  */
1826893Sfeldman ilinit(unit)
1836893Sfeldman 	int unit;
1846893Sfeldman {
1856893Sfeldman 	register struct il_softc *is = &il_softc[unit];
1866893Sfeldman 	register struct uba_device *ui = ilinfo[unit];
1876893Sfeldman 	register struct ildevice *addr;
188*13056Ssam 	register struct ifnet *ifp = &is->is_if;
189*13056Ssam 	register struct sockaddr_in *sin;
1907261Ssam 	int s;
1916893Sfeldman 
19211575Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
193*13056Ssam 	if (sin->sin_addr.s_addr == 0)		/* address still unknown */
19411575Ssam 		return;
19511575Ssam 
196*13056Ssam 	if (ifp->if_flags & IFF_RUNNING)
197*13056Ssam 		goto justarp;
1986893Sfeldman 	if (if_ubainit(&is->is_ifuba, ui->ui_ubanum,
1999746Ssam 	    sizeof (struct il_rheader), (int)btoc(ETHERMTU)) == 0) {
2006893Sfeldman 		printf("il%d: can't initialize\n", unit);
2016893Sfeldman 		is->is_if.if_flags &= ~IFF_UP;
2026893Sfeldman 		return;
2036893Sfeldman 	}
2049179Ssam 	is->is_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&is->is_stats,
205*13056Ssam 	    sizeof (struct il_stats), 0);
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 =
234*13056Ssam 	    ((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;
2386893Sfeldman 	is->is_if.if_flags |= IFF_UP;
2397261Ssam 	is->is_lastcmd = 0;
2406893Sfeldman 	ilcint(unit);
2416893Sfeldman 	splx(s);
242*13056Ssam 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;
3666893Sfeldman 	int len, off, resid;
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);
42911575Ssam 		return;
4306893Sfeldman #endif
4316893Sfeldman 	default:
4326893Sfeldman 		m_freem(m);
4336893Sfeldman 		goto setup;
4346893Sfeldman 	}
4356893Sfeldman 
4366893Sfeldman 	if (IF_QFULL(inq)) {
4376893Sfeldman 		IF_DROP(inq);
4386893Sfeldman 		m_freem(m);
4397220Ssam 		goto setup;
4407220Ssam 	}
4417220Ssam 	IF_ENQUEUE(inq, m);
4426893Sfeldman 
4436893Sfeldman setup:
4446893Sfeldman 	/*
4456893Sfeldman 	 * Reset for next packet if possible.
4466893Sfeldman 	 * If waiting for transmit command completion, set flag
4476893Sfeldman 	 * and wait until command completes.
4486893Sfeldman 	 */
4497261Ssam 	if (is->is_flags & ILF_OACTIVE) {
4507261Ssam 		is->is_flags |= ILF_RCVPENDING;
4517220Ssam 		return;
4527220Ssam 	}
4537220Ssam 	addr->il_bar = is->is_ifuba.ifu_r.ifrw_info & 0xffff;
4549746Ssam 	addr->il_bcr = sizeof(struct il_rheader) + ETHERMTU + 6;
4557261Ssam 	addr->il_csr =
4567261Ssam 		((is->is_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE;
4577220Ssam 	while ((addr->il_csr & IL_CDONE) == 0)
4587220Ssam 		;
4596893Sfeldman }
4606893Sfeldman 
4616893Sfeldman /*
4626893Sfeldman  * Ethernet output routine.
4636893Sfeldman  * Encapsulate a packet of type family for the local net.
4646893Sfeldman  * Use trailer local net encapsulation if enough data in first
4656893Sfeldman  * packet leaves a multiple of 512 bytes of data in remainder.
4666893Sfeldman  */
4676893Sfeldman iloutput(ifp, m0, dst)
4686893Sfeldman 	struct ifnet *ifp;
4696893Sfeldman 	struct mbuf *m0;
4706893Sfeldman 	struct sockaddr *dst;
4716893Sfeldman {
47211575Ssam 	int type, s, error;
47311575Ssam 	u_char edst[6];
47411575Ssam 	struct in_addr idst;
4756893Sfeldman 	register struct il_softc *is = &il_softc[ifp->if_unit];
4766893Sfeldman 	register struct mbuf *m = m0;
4779746Ssam 	register struct ether_header *il;
4789179Ssam 	register int off;
4796893Sfeldman 
4806893Sfeldman 	switch (dst->sa_family) {
4816893Sfeldman 
4826893Sfeldman #ifdef INET
4836893Sfeldman 	case AF_INET:
48411575Ssam 		idst = ((struct sockaddr_in *)dst)->sin_addr;
48511575Ssam 		if (!arpresolve(&is->is_ac, m, &idst, edst))
48611575Ssam 			return (0);	/* if not yet resolved */
4876893Sfeldman 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
488*13056Ssam 		/* need per host negotiation */
489*13056Ssam 		if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
4906893Sfeldman 		if (off > 0 && (off & 0x1ff) == 0 &&
4916893Sfeldman 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4929746Ssam 			type = ETHERPUP_TRAIL + (off>>9);
4936893Sfeldman 			m->m_off -= 2 * sizeof (u_short);
4946893Sfeldman 			m->m_len += 2 * sizeof (u_short);
4959746Ssam 			*mtod(m, u_short *) = htons((u_short)ETHERPUP_IPTYPE);
4969746Ssam 			*(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
4976893Sfeldman 			goto gottrailertype;
4986893Sfeldman 		}
4999746Ssam 		type = ETHERPUP_IPTYPE;
5006893Sfeldman 		off = 0;
5016893Sfeldman 		goto gottype;
5026893Sfeldman #endif
5036893Sfeldman 
50411575Ssam 	case AF_UNSPEC:
50511575Ssam 		il = (struct ether_header *)dst->sa_data;
50612773Ssam 		bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst));
50711575Ssam 		type = il->ether_type;
50811575Ssam 		goto gottype;
50911575Ssam 
5106893Sfeldman 	default:
5116893Sfeldman 		printf("il%d: can't handle af%d\n", ifp->if_unit,
5126893Sfeldman 			dst->sa_family);
5136893Sfeldman 		error = EAFNOSUPPORT;
5146893Sfeldman 		goto bad;
5156893Sfeldman 	}
5166893Sfeldman 
5176893Sfeldman gottrailertype:
5186893Sfeldman 	/*
5196893Sfeldman 	 * Packet to be sent as trailer: move first packet
5206893Sfeldman 	 * (control information) to end of chain.
5216893Sfeldman 	 */
5226893Sfeldman 	while (m->m_next)
5236893Sfeldman 		m = m->m_next;
5246893Sfeldman 	m->m_next = m0;
5256893Sfeldman 	m = m0->m_next;
5266893Sfeldman 	m0->m_next = 0;
5276893Sfeldman 	m0 = m;
5286893Sfeldman 
5296893Sfeldman gottype:
5306893Sfeldman 	/*
5316893Sfeldman 	 * Add local net header.  If no space in first mbuf,
5326893Sfeldman 	 * allocate another.
5336893Sfeldman 	 */
5346893Sfeldman 	if (m->m_off > MMAXOFF ||
5359746Ssam 	    MMINOFF + sizeof (struct ether_header) > m->m_off) {
5369650Ssam 		m = m_get(M_DONTWAIT, MT_HEADER);
5376893Sfeldman 		if (m == 0) {
5386893Sfeldman 			error = ENOBUFS;
5396893Sfeldman 			goto bad;
5406893Sfeldman 		}
5416893Sfeldman 		m->m_next = m0;
5426893Sfeldman 		m->m_off = MMINOFF;
5439746Ssam 		m->m_len = sizeof (struct ether_header);
5446893Sfeldman 	} else {
5459746Ssam 		m->m_off -= sizeof (struct ether_header);
5469746Ssam 		m->m_len += sizeof (struct ether_header);
5476893Sfeldman 	}
5489746Ssam 	il = mtod(m, struct ether_header *);
5499746Ssam 	il->ether_type = htons((u_short)type);
55012773Ssam 	bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst));
55111575Ssam 	bcopy((caddr_t)is->is_addr, (caddr_t)il->ether_shost, 6);
5526893Sfeldman 
5536893Sfeldman 	/*
5546893Sfeldman 	 * Queue message on interface, and start output if interface
5556893Sfeldman 	 * not yet active.
5566893Sfeldman 	 */
5576893Sfeldman 	s = splimp();
5586893Sfeldman 	if (IF_QFULL(&ifp->if_snd)) {
5596893Sfeldman 		IF_DROP(&ifp->if_snd);
5607220Ssam 		splx(s);
5617220Ssam 		m_freem(m);
5627220Ssam 		return (ENOBUFS);
5636893Sfeldman 	}
5646893Sfeldman 	IF_ENQUEUE(&ifp->if_snd, m);
5657261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5666893Sfeldman 		ilstart(ifp->if_unit);
5676893Sfeldman 	splx(s);
5686893Sfeldman 	return (0);
5697220Ssam 
5706893Sfeldman bad:
5716893Sfeldman 	m_freem(m0);
5727220Ssam 	return (error);
5736893Sfeldman }
5747261Ssam 
5757261Ssam /*
5767261Ssam  * Watchdog routine, request statistics from board.
5777261Ssam  */
5787261Ssam ilwatch(unit)
5797261Ssam 	int unit;
5807261Ssam {
5817261Ssam 	register struct il_softc *is = &il_softc[unit];
5827261Ssam 	register struct ifnet *ifp = &is->is_if;
5837261Ssam 	int s;
5847261Ssam 
5857261Ssam 	if (is->is_flags & ILF_STATPENDING) {
5867261Ssam 		ifp->if_timer = is->is_scaninterval;
5877261Ssam 		return;
5887261Ssam 	}
5897261Ssam 	s = splimp();
5907261Ssam 	is->is_flags |= ILF_STATPENDING;
5917261Ssam 	if ((is->is_flags & ILF_OACTIVE) == 0)
5927261Ssam 		ilstart(ifp->if_unit);
5937261Ssam 	splx(s);
5947261Ssam 	ifp->if_timer = is->is_scaninterval;
5957261Ssam }
5967261Ssam 
5977261Ssam /*
5987261Ssam  * Total up the on-board statistics.
5997261Ssam  */
6007261Ssam iltotal(is)
6017261Ssam 	register struct il_softc *is;
6027261Ssam {
6037261Ssam 	register u_short *interval, *sum, *end;
6047261Ssam 
6057261Ssam 	interval = &is->is_stats.ils_frames;
6067261Ssam 	sum = &is->is_sum.ils_frames;
6077261Ssam 	end = is->is_sum.ils_fill2;
6087261Ssam 	while (sum < end)
6097261Ssam 		*sum++ += *interval++;
6107261Ssam 	is->is_if.if_collisions = is->is_sum.ils_collis;
6117261Ssam }
612*13056Ssam 
613*13056Ssam /*
614*13056Ssam  * Process an ioctl request.
615*13056Ssam  */
616*13056Ssam ilioctl(ifp, cmd, data)
617*13056Ssam 	register struct ifnet *ifp;
618*13056Ssam 	int cmd;
619*13056Ssam 	caddr_t data;
620*13056Ssam {
621*13056Ssam 	register struct ifreq *ifr = (struct ifreq *)data;
622*13056Ssam 	register struct sockaddr_in *sin;
623*13056Ssam 	int s = splimp(), error = 0;
624*13056Ssam 
625*13056Ssam 	switch (cmd) {
626*13056Ssam 
627*13056Ssam 	case SIOCSIFADDR:
628*13056Ssam 		if (ifp->if_flags & IFF_RUNNING)
629*13056Ssam 			if_rtinit(ifp, -1);	/* delete previous route */
630*13056Ssam 		ifp->if_addr = ifr->ifr_addr;
631*13056Ssam 		ifp->if_net = in_netof(ifr->ifr_addr);
632*13056Ssam 		ifp->if_host[0] = in_lnaof(ifr->ifr_addr);
633*13056Ssam 		sin = (struct sockaddr_in *)&ifp->if_broadaddr;
634*13056Ssam 		sin->sin_family = AF_INET;
635*13056Ssam 		sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
636*13056Ssam 		ifp->if_flags |= IFF_BROADCAST;
637*13056Ssam 		ilinit(ifp->if_unit);
638*13056Ssam 		break;
639*13056Ssam 
640*13056Ssam 	default:
641*13056Ssam 		error = EINVAL;
642*13056Ssam 	}
643*13056Ssam 	splx(s);
644*13056Ssam 	return (error);
645*13056Ssam }
646