xref: /csrg-svn/sys/vax/if/if_en.c (revision 6486)
1*6486Swnj /*	if_en.c	4.53	82/04/07	*/
24686Swnj 
34686Swnj #include "en.h"
46410Ssam #include "imp.h"
55105Swnj 
64686Swnj /*
75105Swnj  * Xerox prototype (3 Mb) Ethernet interface driver.
84686Swnj  */
94686Swnj 
104686Swnj #include "../h/param.h"
114686Swnj #include "../h/systm.h"
124686Swnj #include "../h/mbuf.h"
134686Swnj #include "../h/pte.h"
144686Swnj #include "../h/buf.h"
155083Swnj #include "../h/protosw.h"
165083Swnj #include "../h/socket.h"
174686Swnj #include "../h/ubareg.h"
184686Swnj #include "../h/ubavar.h"
194686Swnj #include "../h/enreg.h"
205083Swnj #include "../h/cpu.h"
214686Swnj #include "../h/mtpr.h"
225083Swnj #include "../h/vmmac.h"
235083Swnj #include "../net/in.h"
245083Swnj #include "../net/in_systm.h"
255083Swnj #include "../net/if.h"
265083Swnj #include "../net/if_en.h"
275083Swnj #include "../net/if_uba.h"
285083Swnj #include "../net/ip.h"
295083Swnj #include "../net/ip_var.h"
306027Ssam #include "../net/pup.h"
316364Ssam #include "../net/route.h"
324686Swnj 
335213Swnj #define	ENMTU	(1024+512)
345083Swnj 
354686Swnj int	enprobe(), enattach(), enrint(), enxint(), encollide();
364686Swnj struct	uba_device *eninfo[NEN];
374686Swnj u_short enstd[] = { 0 };
384686Swnj struct	uba_driver endriver =
395171Swnj 	{ enprobe, 0, enattach, 0, enstd, "en", eninfo };
404686Swnj #define	ENUNIT(x)	minor(x)
414686Swnj 
425105Swnj int	eninit(),enoutput(),enreset();
435105Swnj 
445105Swnj /*
455105Swnj  * Ethernet software status per interface.
465105Swnj  *
475105Swnj  * Each interface is referenced by a network interface structure,
485105Swnj  * es_if, which the routing code uses to locate the interface.
495105Swnj  * This structure contains the output queue for the interface, its address, ...
505105Swnj  * We also have, for each interface, a UBA interface structure, which
515105Swnj  * contains information about the UNIBUS resources held by the interface:
525105Swnj  * map registers, buffered data paths, etc.  Information is cached in this
535105Swnj  * structure for use by the if_uba.c routines in running the interface
545105Swnj  * efficiently.
555105Swnj  */
565083Swnj struct	en_softc {
575105Swnj 	struct	ifnet es_if;		/* network-visible interface */
585105Swnj 	struct	ifuba es_ifuba;		/* UNIBUS resources */
595105Swnj 	short	es_delay;		/* current output delay */
605105Swnj 	short	es_mask;		/* mask for current output delay */
616471Sroot 	short	es_lastx;		/* host last transmitted to */
625105Swnj 	short	es_oactive;		/* is output active? */
635105Swnj 	short	es_olen;		/* length of last output */
645083Swnj } en_softc[NEN];
654686Swnj 
665105Swnj /*
675105Swnj  * Do output DMA to determine interface presence and
685105Swnj  * interrupt vector.  DMA is too short to disturb other hosts.
695105Swnj  */
704686Swnj enprobe(reg)
714686Swnj 	caddr_t reg;
724686Swnj {
735171Swnj 	register int br, cvec;		/* r11, r10 value-result */
744686Swnj 	register struct endevice *addr = (struct endevice *)reg;
754686Swnj 
765083Swnj COUNT(ENPROBE);
774686Swnj #ifdef lint
784686Swnj 	br = 0; cvec = br; br = cvec;
794922Swnj 	enrint(0); enxint(0); encollide(0);
804686Swnj #endif
814686Swnj 	addr->en_istat = 0;
824686Swnj 	addr->en_owc = -1;
834686Swnj 	addr->en_oba = 0;
844771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
854686Swnj 	DELAY(100000);
864686Swnj 	addr->en_ostat = 0;
874686Swnj 	return (1);
884686Swnj }
894686Swnj 
905105Swnj /*
915105Swnj  * Interface exists: make available by filling in network interface
925105Swnj  * record.  System will initialize the interface when it is ready
935105Swnj  * to accept packets.
945105Swnj  */
954686Swnj enattach(ui)
964686Swnj 	struct uba_device *ui;
974686Swnj {
985105Swnj 	register struct en_softc *es = &en_softc[ui->ui_unit];
996335Ssam 	register struct sockaddr_in *sin;
1005105Swnj COUNT(ENATTACH);
1014688Swnj 
1025105Swnj 	es->es_if.if_unit = ui->ui_unit;
1035171Swnj 	es->es_if.if_name = "en";
1045105Swnj 	es->es_if.if_mtu = ENMTU;
1056433Ssam 	es->es_if.if_net = ui->ui_flags & 0xff;
1065105Swnj 	es->es_if.if_host[0] =
1076335Ssam 	 (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
1086335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_addr;
1096335Ssam 	sin->sin_family = AF_INET;
1106335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
1116335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
1126335Ssam 	sin->sin_family = AF_INET;
1136335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
1146335Ssam 	es->es_if.if_flags = IFF_BROADCAST;
1155171Swnj 	es->es_if.if_init = eninit;
1165105Swnj 	es->es_if.if_output = enoutput;
1175105Swnj 	es->es_if.if_ubareset = enreset;
1185696Sroot 	es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16;
1195160Swnj 	if_attach(&es->es_if);
1206410Ssam #if NIMP == 0
1216410Ssam 	/* here's one for you john baby.... */
1226422Sroot 	enlhinit((ui->ui_flags &~ 0xff) | 0x0a);
1236410Ssam #endif
1244686Swnj }
1254686Swnj 
1265105Swnj /*
1275105Swnj  * Reset of interface after UNIBUS reset.
1285105Swnj  * If interface is on specified uba, reset its state.
1295105Swnj  */
1305105Swnj enreset(unit, uban)
1315105Swnj 	int unit, uban;
1325105Swnj {
1335105Swnj 	register struct uba_device *ui;
1345105Swnj COUNT(ENRESET);
1355105Swnj 
1365171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1375171Swnj 	    ui->ui_ubanum != uban)
1385105Swnj 		return;
1395171Swnj 	printf(" en%d", unit);
1405105Swnj 	eninit(unit);
1415105Swnj }
1425105Swnj 
1435105Swnj /*
1445105Swnj  * Initialization of interface; clear recorded pending
1455105Swnj  * operations, and reinitialize UNIBUS usage.
1465105Swnj  */
1474688Swnj eninit(unit)
1484686Swnj 	int unit;
1495083Swnj {
1505171Swnj 	register struct en_softc *es = &en_softc[unit];
1515171Swnj 	register struct uba_device *ui = eninfo[unit];
1524686Swnj 	register struct endevice *addr;
1535105Swnj 	int s;
1544686Swnj 
1555105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1565708Sroot 	    sizeof (struct en_header), (int)btoc(ENMTU)) == 0) {
1575171Swnj 		printf("en%d: can't initialize\n", unit);
1586335Ssam 		es->es_if.if_flags &= ~IFF_UP;
1595083Swnj 		return;
1604686Swnj 	}
1614686Swnj 	addr = (struct endevice *)ui->ui_addr;
1625083Swnj 	addr->en_istat = addr->en_ostat = 0;
1634686Swnj 
1645105Swnj 	/*
1655171Swnj 	 * Hang a receive and start any
1665171Swnj 	 * pending writes by faking a transmit complete.
1675105Swnj 	 */
1685105Swnj 	s = splimp();
1695171Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
1705171Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
1715171Swnj 	addr->en_istat = EN_IEN|EN_GO;
1725171Swnj 	es->es_oactive = 1;
1736335Ssam 	es->es_if.if_flags |= IFF_UP;
1745105Swnj 	enxint(unit);
1755105Swnj 	splx(s);
1766364Ssam 	if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP);
1774686Swnj }
1784686Swnj 
1796471Sroot int	enalldelay = 0;
1804717Swnj int	enlastdel = 25;
1816471Sroot int	enlastmask = (~0) << 5;
1825083Swnj 
1835105Swnj /*
1845105Swnj  * Start or restart output on interface.
1855105Swnj  * If interface is already active, then this is a retransmit
1865105Swnj  * after a collision, and just restuff registers and delay.
1875105Swnj  * If interface is not already active, get another datagram
1885105Swnj  * to send off of the interface queue, and map it to the interface
1895105Swnj  * before starting the output.
1905105Swnj  */
1914688Swnj enstart(dev)
1924686Swnj 	dev_t dev;
1934686Swnj {
1945171Swnj         int unit = ENUNIT(dev);
1955171Swnj 	struct uba_device *ui = eninfo[unit];
1965171Swnj 	register struct en_softc *es = &en_softc[unit];
1975083Swnj 	register struct endevice *addr;
1985083Swnj 	struct mbuf *m;
1995083Swnj 	int dest;
2004688Swnj COUNT(ENSTART);
2014686Swnj 
2025083Swnj 	if (es->es_oactive)
2035083Swnj 		goto restart;
2045105Swnj 
2055105Swnj 	/*
2065105Swnj 	 * Not already active: dequeue another request
2075105Swnj 	 * and map it to the UNIBUS.  If no more requests,
2085105Swnj 	 * just return.
2095105Swnj 	 */
2105105Swnj 	IF_DEQUEUE(&es->es_if.if_snd, m);
2115083Swnj 	if (m == 0) {
2125083Swnj 		es->es_oactive = 0;
2134686Swnj 		return;
2144686Swnj 	}
2155213Swnj 	dest = mtod(m, struct en_header *)->en_dhost;
2165105Swnj 	es->es_olen = if_wubaput(&es->es_ifuba, m);
2175105Swnj 
2185105Swnj 	/*
2195105Swnj 	 * Ethernet cannot take back-to-back packets (no
2206471Sroot 	 * buffering in interface.  To help avoid overrunning
2216471Sroot 	 * receivers, enforce a small delay (about 1ms) in interface:
2226471Sroot 	 *	* between all packets when enalldelay
2236471Sroot 	 *	* whenever last packet was broadcast
2246471Sroot 	 *	* whenever this packet is to same host as last packet
2255105Swnj 	 */
2266471Sroot 	if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) {
2275083Swnj 		es->es_delay = enlastdel;
2286471Sroot 		es->es_mask = enlastmask;
2296471Sroot 	}
2306471Sroot 	es->es_lastx = dest;
2315105Swnj 
2325083Swnj restart:
2335105Swnj 	/*
2345105Swnj 	 * Have request mapped to UNIBUS for transmission.
2355105Swnj 	 * Purge any stale data from this BDP, and start the otput.
2365105Swnj 	 */
2376335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
2386335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2394686Swnj 	addr = (struct endevice *)ui->ui_addr;
2405160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2415083Swnj 	addr->en_odelay = es->es_delay;
2425083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2434771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2445083Swnj 	es->es_oactive = 1;
2454686Swnj }
2464686Swnj 
2475105Swnj /*
2485105Swnj  * Ethernet interface transmitter interrupt.
2495105Swnj  * Start another output if more data to send.
2505105Swnj  */
2514686Swnj enxint(unit)
2524686Swnj 	int unit;
2534686Swnj {
2545171Swnj 	register struct uba_device *ui = eninfo[unit];
2555171Swnj 	register struct en_softc *es = &en_softc[unit];
2566242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2574686Swnj COUNT(ENXINT);
2584686Swnj 
2595083Swnj 	if (es->es_oactive == 0)
2605083Swnj 		return;
2616242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
2626242Sroot 		es->es_if.if_oerrors++;
2636242Sroot 		if (es->es_if.if_oerrors % 100 == 0)
2646242Sroot 			printf("en%d: += 100 output errors\n", unit);
2656242Sroot 		endocoll(unit);
2666242Sroot 		return;
2676242Sroot 	}
2685171Swnj 	es->es_if.if_opackets++;
2695083Swnj 	es->es_oactive = 0;
2705083Swnj 	es->es_delay = 0;
2715083Swnj 	es->es_mask = ~0;
2725696Sroot 	if (es->es_ifuba.ifu_xtofree) {
2735696Sroot 		m_freem(es->es_ifuba.ifu_xtofree);
2745696Sroot 		es->es_ifuba.ifu_xtofree = 0;
2755696Sroot 	}
2765105Swnj 	if (es->es_if.if_snd.ifq_head == 0) {
2776471Sroot 		es->es_lastx = 256;		/* putatively illegal */
2784686Swnj 		return;
2794686Swnj 	}
2805083Swnj 	enstart(unit);
2814686Swnj }
2824686Swnj 
2835105Swnj /*
2845105Swnj  * Collision on ethernet interface.  Do exponential
2855105Swnj  * backoff, and retransmit.  If have backed off all
2866335Ssam  * the way print warning diagnostic, and drop packet.
2875105Swnj  */
2884686Swnj encollide(unit)
2894686Swnj 	int unit;
2904686Swnj {
2916242Sroot 	struct en_softc *es = &en_softc[unit];
2924686Swnj COUNT(ENCOLLIDE);
2934686Swnj 
2945105Swnj 	es->es_if.if_collisions++;
2955083Swnj 	if (es->es_oactive == 0)
2964686Swnj 		return;
2976242Sroot 	endocoll(unit);
2986242Sroot }
2996242Sroot 
3006242Sroot endocoll(unit)
3016242Sroot 	int unit;
3026242Sroot {
3036242Sroot 	register struct en_softc *es = &en_softc[unit];
3046242Sroot 
3055171Swnj 	/*
3065171Swnj 	 * Es_mask is a 16 bit number with n low zero bits, with
3075171Swnj 	 * n the number of backoffs.  When es_mask is 0 we have
3085171Swnj 	 * backed off 16 times, and give up.
3095171Swnj 	 */
3105083Swnj 	if (es->es_mask == 0) {
3115213Swnj 		printf("en%d: send error\n", unit);
3125083Swnj 		enxint(unit);
3135171Swnj 		return;
3144686Swnj 	}
3155171Swnj 	/*
3165171Swnj 	 * Another backoff.  Restart with delay based on n low bits
3175171Swnj 	 * of the interval timer.
3185171Swnj 	 */
3195171Swnj 	es->es_mask <<= 1;
3205171Swnj 	es->es_delay = mfpr(ICR) &~ es->es_mask;
3215171Swnj 	enstart(unit);
3224686Swnj }
3234686Swnj 
3246027Ssam struct	sockaddr_pup pupsrc = { AF_PUP };
3256027Ssam struct	sockaddr_pup pupdst = { AF_PUP };
3266027Ssam struct	sockproto pupproto = { PF_PUP };
3275105Swnj /*
3285105Swnj  * Ethernet interface receiver interrupt.
3295105Swnj  * If input error just drop packet.
3305105Swnj  * Otherwise purge input buffered data path and examine
3315105Swnj  * packet to determine type.  If can't determine length
3325105Swnj  * from type, then have to drop packet.  Othewise decapsulate
3335105Swnj  * packet based on type and pass to type specific higher-level
3345105Swnj  * input routine.
3355105Swnj  */
3364686Swnj enrint(unit)
3374686Swnj 	int unit;
3384686Swnj {
3395171Swnj 	register struct en_softc *es = &en_softc[unit];
3405171Swnj 	struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
3415171Swnj 	register struct en_header *en;
3425083Swnj     	struct mbuf *m;
3436471Sroot 	int len, plen; short resid;
3445171Swnj 	register struct ifqueue *inq;
3455083Swnj 	int off;
3464686Swnj COUNT(ENRINT);
3474686Swnj 
3485171Swnj 	es->es_if.if_ipackets++;
3495105Swnj 
3505105Swnj 	/*
3515171Swnj 	 * Purge BDP; drop if input error indicated.
3525105Swnj 	 */
3536335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
3546335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3554771Swnj 	if (addr->en_istat&EN_IERROR) {
3565105Swnj 		es->es_if.if_ierrors++;
3576238Sroot 		if (es->es_if.if_ierrors % 100 == 0)
3586238Sroot 			printf("en%d: += 100 input errors\n", unit);
3595083Swnj 		goto setup;
3604686Swnj 	}
3615105Swnj 
3625105Swnj 	/*
3636471Sroot 	 * Calculate input data length.
3645105Swnj 	 * Get pointer to ethernet header (in input buffer).
3655105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3665105Swnj 	 * get true type from first 16-bit word past data.
3675105Swnj 	 * Remember that type was trailer by setting off.
3685105Swnj 	 */
3696471Sroot 	resid = addr->en_iwc;
3706471Sroot 	if (resid)
3716471Sroot 		resid |= 0176000;
3726471Sroot 	len = (((sizeof (struct en_header) + ENMTU) >> 1) + resid) << 1;
3736471Sroot 	len -= sizeof (struct en_header);
3746471Sroot 	if (len >= ENMTU)
3756471Sroot 		goto setup;			/* sanity */
3765105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3775083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3785083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3795083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3805083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3815171Swnj 		if (off >= ENMTU)
3825171Swnj 			goto setup;		/* sanity */
3835083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3846471Sroot 		resid = *(endataaddr(en, off+2, u_short *));
3856471Sroot 		if (off + resid > len)
3866471Sroot 			goto setup;		/* sanity */
3876471Sroot 		len = off + resid;
3885083Swnj 	} else
3895083Swnj 		off = 0;
3905083Swnj 	if (len == 0)
3915083Swnj 		goto setup;
3925105Swnj 	/*
3935105Swnj 	 * Pull packet off interface.  Off is nonzero if packet
3945105Swnj 	 * has trailing header; if_rubaget will then force this header
3955105Swnj 	 * information to be at the front, but we still have to drop
3966471Sroot 	 * the type and length which are at the front of any trailer data.
3975105Swnj 	 */
3985105Swnj 	m = if_rubaget(&es->es_ifuba, len, off);
3995213Swnj 	if (m == 0)
4005213Swnj 		goto setup;
4015105Swnj 	if (off) {
4026471Sroot 		m->m_off += 2 * sizeof (u_short);
4036471Sroot 		m->m_len -= 2 * sizeof (u_short);
4045105Swnj 	}
4056027Ssam 	switch (en->en_type) {
4066027Ssam 
4076027Ssam #ifdef INET
4086027Ssam 	case ENPUP_IPTYPE:
4096260Swnj 		schednetisr(NETISR_IP);
4106027Ssam 		inq = &ipintrq;
4116027Ssam 		break;
4126027Ssam #endif
4136335Ssam #ifdef PUP
4146027Ssam 	case ENPUP_PUPTYPE: {
4156027Ssam 		struct pup_header *pup = mtod(m, struct pup_header *);
4166027Ssam 
4176027Ssam 		pupproto.sp_protocol = pup->pup_type;
4186027Ssam 		pupdst.spup_addr = pup->pup_dport;
4196027Ssam 		pupsrc.spup_addr = pup->pup_sport;
4206159Ssam 		raw_input(m, &pupproto, (struct sockaddr *)&pupdst,
4216335Ssam 		  (struct sockaddr *)&pupsrc);
4226027Ssam 		goto setup;
4236027Ssam 	}
4246335Ssam #endif
4256476Swnj 	default:
4266476Swnj 		m_freem(m);
4276476Swnj 		goto setup;
4286335Ssam 	}
4296335Ssam 
4306207Swnj 	if (IF_QFULL(inq)) {
4316207Swnj 		IF_DROP(inq);
4326335Ssam 		m_freem(m);
4336207Swnj 	} else
4346207Swnj 		IF_ENQUEUE(inq, m);
4355105Swnj 
4364688Swnj setup:
4375105Swnj 	/*
4385105Swnj 	 * Reset for next packet.
4395105Swnj 	 */
4405105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4415083Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
4424771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4434688Swnj }
4444686Swnj 
4455083Swnj /*
4465083Swnj  * Ethernet output routine.
4475083Swnj  * Encapsulate a packet of type family for the local net.
4485105Swnj  * Use trailer local net encapsulation if enough data in first
4495105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4505083Swnj  */
4516335Ssam enoutput(ifp, m0, dst)
4525083Swnj 	struct ifnet *ifp;
4535083Swnj 	struct mbuf *m0;
4546335Ssam 	struct sockaddr *dst;
4554686Swnj {
4566335Ssam 	int type, dest, s;
4575105Swnj 	register struct mbuf *m = m0;
4585083Swnj 	register struct en_header *en;
4596335Ssam 	register int off;
4604686Swnj 
4615927Sroot COUNT(ENOUTPUT);
4626335Ssam 	switch (dst->sa_family) {
4635083Swnj 
4645083Swnj #ifdef INET
4656335Ssam 	case AF_INET:
4666484Swnj 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
4676484Swnj 		if (dest & 0x00ffff00)
468*6486Swnj 			goto bad;
4696484Swnj 		dest = (dest >> 24) & 0xff;
4706335Ssam 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4716335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
4726471Sroot 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4735083Swnj 			type = ENPUP_TRAIL + (off>>9);
4746471Sroot 			m->m_off -= 2 * sizeof (u_short);
4756471Sroot 			m->m_len += 2 * sizeof (u_short);
4765105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
4776471Sroot 			*(mtod(m, u_short *) + 1) = m->m_len;
4785105Swnj 			goto gottrailertype;
4795083Swnj 		}
4805105Swnj 		type = ENPUP_IPTYPE;
4815105Swnj 		off = 0;
4825105Swnj 		goto gottype;
4835083Swnj #endif
4846027Ssam #ifdef PUP
4856335Ssam 	case AF_PUP:
4866335Ssam 		dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host;
4876027Ssam 		type = ENPUP_PUPTYPE;
4886027Ssam 		off = 0;
4896027Ssam 		goto gottype;
4906027Ssam #endif
4916027Ssam 
4925083Swnj 	default:
4936335Ssam 		printf("en%d: can't handle af%d\n", ifp->if_unit,
4946335Ssam 			dst->sa_family);
4955083Swnj 		m_freem(m0);
4965083Swnj 		return (0);
4974686Swnj 	}
4985105Swnj 
4995171Swnj gottrailertype:
5005105Swnj 	/*
5015105Swnj 	 * Packet to be sent as trailer: move first packet
5025105Swnj 	 * (control information) to end of chain.
5035105Swnj 	 */
5045105Swnj 	while (m->m_next)
5055105Swnj 		m = m->m_next;
5065105Swnj 	m->m_next = m0;
5075105Swnj 	m = m0->m_next;
5085105Swnj 	m0->m_next = 0;
5095171Swnj 	m0 = m;
5105105Swnj 
5115171Swnj gottype:
5125105Swnj 	/*
5135105Swnj 	 * Add local net header.  If no space in first mbuf,
5145105Swnj 	 * allocate another.
5155105Swnj 	 */
5165213Swnj 	if (m->m_off > MMAXOFF ||
5175213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5185584Sroot 		m = m_get(M_DONTWAIT);
5195083Swnj 		if (m == 0) {
5205083Swnj 			m_freem(m0);
5215083Swnj 			return (0);
5225083Swnj 		}
5235083Swnj 		m->m_next = m0;
5245083Swnj 		m->m_off = MMINOFF;
5255083Swnj 		m->m_len = sizeof (struct en_header);
5265083Swnj 	} else {
5275083Swnj 		m->m_off -= sizeof (struct en_header);
5285083Swnj 		m->m_len += sizeof (struct en_header);
5295083Swnj 	}
5305083Swnj 	en = mtod(m, struct en_header *);
5315083Swnj 	en->en_shost = ifp->if_host[0];
5325083Swnj 	en->en_dhost = dest;
5335083Swnj 	en->en_type = type;
5345105Swnj 
5355105Swnj 	/*
5365105Swnj 	 * Queue message on interface, and start output if interface
5375105Swnj 	 * not yet active.
5385105Swnj 	 */
5395083Swnj 	s = splimp();
5406207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5416207Swnj 		IF_DROP(&ifp->if_snd);
5426484Swnj 		goto bad;
5436207Swnj 	}
5445083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5455083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5465083Swnj 		enstart(ifp->if_unit);
5475275Swnj 	splx(s);
5485105Swnj 	return (1);
5496484Swnj bad:
5506484Swnj 	m_freem(m);
5516484Swnj 	splx(s);
5526484Swnj 	return (0);
5534686Swnj }
5546410Ssam 
5556410Ssam #if NIMP == 0 && NEN > 0
5566410Ssam /*
5576410Ssam  * Logical host interface driver.
5586410Ssam  * Allows host to appear as an ARPAnet
5596410Ssam  * logical host.  Must also have routing
5606410Ssam  * table entry set up to forward packets
5616410Ssam  * to appropriate gateway on localnet.
5626410Ssam  */
5636410Ssam 
5646410Ssam struct	ifnet enlhif;
5656410Ssam int	enlhoutput();
5666410Ssam 
5676410Ssam /*
5686410Ssam  * Called by localnet interface to allow logical
5696410Ssam  * host interface to "attach".  Nothing should ever
5706410Ssam  * be sent locally to this interface, it's purpose
5716410Ssam  * is simply to establish the host's arpanet address.
5726410Ssam  */
5736410Ssam enlhinit(addr)
5746410Ssam 	int addr;
5756410Ssam {
5766410Ssam 	register struct ifnet *ifp = &enlhif;
5776410Ssam 	register struct sockaddr_in *sin;
5786410Ssam 
5796410Ssam COUNT(ENLHINIT);
5806410Ssam 	ifp->if_name = "lh";
5816410Ssam 	ifp->if_mtu = ENMTU;
5826410Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
5836410Ssam 	sin->sin_family = AF_INET;
5846410Ssam 	sin->sin_addr.s_addr = addr;
5856410Ssam 	ifp->if_net = sin->sin_addr.s_net;
5866410Ssam 	ifp->if_flags = IFF_UP;
5876410Ssam 	ifp->if_output = enlhoutput;	/* should never be used */
5886410Ssam 	if_attach(ifp);
5896410Ssam }
5906410Ssam 
5916410Ssam enlhoutput(ifp, m0, dst)
5926410Ssam 	struct ifnet *ifp;
5936410Ssam 	struct mbuf *m0;
5946410Ssam 	struct sockaddr *dst;
5956410Ssam {
5966410Ssam COUNT(ENLHOUTPUT);
5976410Ssam 	ifp->if_oerrors++;
5986410Ssam 	m_freem(m0);
5996410Ssam 	return (0);
6006410Ssam }
6016410Ssam #endif
602