xref: /csrg-svn/sys/vax/if/if_en.c (revision 6503)
1*6503Ssam /*	if_en.c	4.54	82/04/10	*/
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"
32*6503Ssam #include <errno.h>
334686Swnj 
345213Swnj #define	ENMTU	(1024+512)
355083Swnj 
364686Swnj int	enprobe(), enattach(), enrint(), enxint(), encollide();
374686Swnj struct	uba_device *eninfo[NEN];
384686Swnj u_short enstd[] = { 0 };
394686Swnj struct	uba_driver endriver =
405171Swnj 	{ enprobe, 0, enattach, 0, enstd, "en", eninfo };
414686Swnj #define	ENUNIT(x)	minor(x)
424686Swnj 
435105Swnj int	eninit(),enoutput(),enreset();
445105Swnj 
455105Swnj /*
465105Swnj  * Ethernet software status per interface.
475105Swnj  *
485105Swnj  * Each interface is referenced by a network interface structure,
495105Swnj  * es_if, which the routing code uses to locate the interface.
505105Swnj  * This structure contains the output queue for the interface, its address, ...
515105Swnj  * We also have, for each interface, a UBA interface structure, which
525105Swnj  * contains information about the UNIBUS resources held by the interface:
535105Swnj  * map registers, buffered data paths, etc.  Information is cached in this
545105Swnj  * structure for use by the if_uba.c routines in running the interface
555105Swnj  * efficiently.
565105Swnj  */
575083Swnj struct	en_softc {
585105Swnj 	struct	ifnet es_if;		/* network-visible interface */
595105Swnj 	struct	ifuba es_ifuba;		/* UNIBUS resources */
605105Swnj 	short	es_delay;		/* current output delay */
615105Swnj 	short	es_mask;		/* mask for current output delay */
626471Sroot 	short	es_lastx;		/* host last transmitted to */
635105Swnj 	short	es_oactive;		/* is output active? */
645105Swnj 	short	es_olen;		/* length of last output */
655083Swnj } en_softc[NEN];
664686Swnj 
675105Swnj /*
685105Swnj  * Do output DMA to determine interface presence and
695105Swnj  * interrupt vector.  DMA is too short to disturb other hosts.
705105Swnj  */
714686Swnj enprobe(reg)
724686Swnj 	caddr_t reg;
734686Swnj {
745171Swnj 	register int br, cvec;		/* r11, r10 value-result */
754686Swnj 	register struct endevice *addr = (struct endevice *)reg;
764686Swnj 
775083Swnj COUNT(ENPROBE);
784686Swnj #ifdef lint
794686Swnj 	br = 0; cvec = br; br = cvec;
804922Swnj 	enrint(0); enxint(0); encollide(0);
814686Swnj #endif
824686Swnj 	addr->en_istat = 0;
834686Swnj 	addr->en_owc = -1;
844686Swnj 	addr->en_oba = 0;
854771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
864686Swnj 	DELAY(100000);
874686Swnj 	addr->en_ostat = 0;
884686Swnj 	return (1);
894686Swnj }
904686Swnj 
915105Swnj /*
925105Swnj  * Interface exists: make available by filling in network interface
935105Swnj  * record.  System will initialize the interface when it is ready
945105Swnj  * to accept packets.
955105Swnj  */
964686Swnj enattach(ui)
974686Swnj 	struct uba_device *ui;
984686Swnj {
995105Swnj 	register struct en_softc *es = &en_softc[ui->ui_unit];
1006335Ssam 	register struct sockaddr_in *sin;
1015105Swnj COUNT(ENATTACH);
1024688Swnj 
1035105Swnj 	es->es_if.if_unit = ui->ui_unit;
1045171Swnj 	es->es_if.if_name = "en";
1055105Swnj 	es->es_if.if_mtu = ENMTU;
1066433Ssam 	es->es_if.if_net = ui->ui_flags & 0xff;
1075105Swnj 	es->es_if.if_host[0] =
1086335Ssam 	 (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
1096335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_addr;
1106335Ssam 	sin->sin_family = AF_INET;
1116335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
1126335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
1136335Ssam 	sin->sin_family = AF_INET;
1146335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
1156335Ssam 	es->es_if.if_flags = IFF_BROADCAST;
1165171Swnj 	es->es_if.if_init = eninit;
1175105Swnj 	es->es_if.if_output = enoutput;
1185105Swnj 	es->es_if.if_ubareset = enreset;
1195696Sroot 	es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16;
1205160Swnj 	if_attach(&es->es_if);
1216410Ssam #if NIMP == 0
1226410Ssam 	/* here's one for you john baby.... */
1236422Sroot 	enlhinit((ui->ui_flags &~ 0xff) | 0x0a);
1246410Ssam #endif
1254686Swnj }
1264686Swnj 
1275105Swnj /*
1285105Swnj  * Reset of interface after UNIBUS reset.
1295105Swnj  * If interface is on specified uba, reset its state.
1305105Swnj  */
1315105Swnj enreset(unit, uban)
1325105Swnj 	int unit, uban;
1335105Swnj {
1345105Swnj 	register struct uba_device *ui;
1355105Swnj COUNT(ENRESET);
1365105Swnj 
1375171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1385171Swnj 	    ui->ui_ubanum != uban)
1395105Swnj 		return;
1405171Swnj 	printf(" en%d", unit);
1415105Swnj 	eninit(unit);
1425105Swnj }
1435105Swnj 
1445105Swnj /*
1455105Swnj  * Initialization of interface; clear recorded pending
1465105Swnj  * operations, and reinitialize UNIBUS usage.
1475105Swnj  */
1484688Swnj eninit(unit)
1494686Swnj 	int unit;
1505083Swnj {
1515171Swnj 	register struct en_softc *es = &en_softc[unit];
1525171Swnj 	register struct uba_device *ui = eninfo[unit];
1534686Swnj 	register struct endevice *addr;
1545105Swnj 	int s;
1554686Swnj 
1565105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1575708Sroot 	    sizeof (struct en_header), (int)btoc(ENMTU)) == 0) {
1585171Swnj 		printf("en%d: can't initialize\n", unit);
1596335Ssam 		es->es_if.if_flags &= ~IFF_UP;
1605083Swnj 		return;
1614686Swnj 	}
1624686Swnj 	addr = (struct endevice *)ui->ui_addr;
1635083Swnj 	addr->en_istat = addr->en_ostat = 0;
1644686Swnj 
1655105Swnj 	/*
1665171Swnj 	 * Hang a receive and start any
1675171Swnj 	 * pending writes by faking a transmit complete.
1685105Swnj 	 */
1695105Swnj 	s = splimp();
1705171Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
1715171Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
1725171Swnj 	addr->en_istat = EN_IEN|EN_GO;
1735171Swnj 	es->es_oactive = 1;
1746335Ssam 	es->es_if.if_flags |= IFF_UP;
1755105Swnj 	enxint(unit);
1765105Swnj 	splx(s);
1776364Ssam 	if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP);
1784686Swnj }
1794686Swnj 
1806471Sroot int	enalldelay = 0;
1814717Swnj int	enlastdel = 25;
1826471Sroot int	enlastmask = (~0) << 5;
1835083Swnj 
1845105Swnj /*
1855105Swnj  * Start or restart output on interface.
1865105Swnj  * If interface is already active, then this is a retransmit
1875105Swnj  * after a collision, and just restuff registers and delay.
1885105Swnj  * If interface is not already active, get another datagram
1895105Swnj  * to send off of the interface queue, and map it to the interface
1905105Swnj  * before starting the output.
1915105Swnj  */
1924688Swnj enstart(dev)
1934686Swnj 	dev_t dev;
1944686Swnj {
1955171Swnj         int unit = ENUNIT(dev);
1965171Swnj 	struct uba_device *ui = eninfo[unit];
1975171Swnj 	register struct en_softc *es = &en_softc[unit];
1985083Swnj 	register struct endevice *addr;
1995083Swnj 	struct mbuf *m;
2005083Swnj 	int dest;
2014688Swnj COUNT(ENSTART);
2024686Swnj 
2035083Swnj 	if (es->es_oactive)
2045083Swnj 		goto restart;
2055105Swnj 
2065105Swnj 	/*
2075105Swnj 	 * Not already active: dequeue another request
2085105Swnj 	 * and map it to the UNIBUS.  If no more requests,
2095105Swnj 	 * just return.
2105105Swnj 	 */
2115105Swnj 	IF_DEQUEUE(&es->es_if.if_snd, m);
2125083Swnj 	if (m == 0) {
2135083Swnj 		es->es_oactive = 0;
2144686Swnj 		return;
2154686Swnj 	}
2165213Swnj 	dest = mtod(m, struct en_header *)->en_dhost;
2175105Swnj 	es->es_olen = if_wubaput(&es->es_ifuba, m);
2185105Swnj 
2195105Swnj 	/*
2205105Swnj 	 * Ethernet cannot take back-to-back packets (no
2216471Sroot 	 * buffering in interface.  To help avoid overrunning
2226471Sroot 	 * receivers, enforce a small delay (about 1ms) in interface:
2236471Sroot 	 *	* between all packets when enalldelay
2246471Sroot 	 *	* whenever last packet was broadcast
2256471Sroot 	 *	* whenever this packet is to same host as last packet
2265105Swnj 	 */
2276471Sroot 	if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) {
2285083Swnj 		es->es_delay = enlastdel;
2296471Sroot 		es->es_mask = enlastmask;
2306471Sroot 	}
2316471Sroot 	es->es_lastx = dest;
2325105Swnj 
2335083Swnj restart:
2345105Swnj 	/*
2355105Swnj 	 * Have request mapped to UNIBUS for transmission.
2365105Swnj 	 * Purge any stale data from this BDP, and start the otput.
2375105Swnj 	 */
2386335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
2396335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2404686Swnj 	addr = (struct endevice *)ui->ui_addr;
2415160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2425083Swnj 	addr->en_odelay = es->es_delay;
2435083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2444771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2455083Swnj 	es->es_oactive = 1;
2464686Swnj }
2474686Swnj 
2485105Swnj /*
2495105Swnj  * Ethernet interface transmitter interrupt.
2505105Swnj  * Start another output if more data to send.
2515105Swnj  */
2524686Swnj enxint(unit)
2534686Swnj 	int unit;
2544686Swnj {
2555171Swnj 	register struct uba_device *ui = eninfo[unit];
2565171Swnj 	register struct en_softc *es = &en_softc[unit];
2576242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2584686Swnj COUNT(ENXINT);
2594686Swnj 
2605083Swnj 	if (es->es_oactive == 0)
2615083Swnj 		return;
2626242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
2636242Sroot 		es->es_if.if_oerrors++;
2646242Sroot 		if (es->es_if.if_oerrors % 100 == 0)
2656242Sroot 			printf("en%d: += 100 output errors\n", unit);
2666242Sroot 		endocoll(unit);
2676242Sroot 		return;
2686242Sroot 	}
2695171Swnj 	es->es_if.if_opackets++;
2705083Swnj 	es->es_oactive = 0;
2715083Swnj 	es->es_delay = 0;
2725083Swnj 	es->es_mask = ~0;
2735696Sroot 	if (es->es_ifuba.ifu_xtofree) {
2745696Sroot 		m_freem(es->es_ifuba.ifu_xtofree);
2755696Sroot 		es->es_ifuba.ifu_xtofree = 0;
2765696Sroot 	}
2775105Swnj 	if (es->es_if.if_snd.ifq_head == 0) {
2786471Sroot 		es->es_lastx = 256;		/* putatively illegal */
2794686Swnj 		return;
2804686Swnj 	}
2815083Swnj 	enstart(unit);
2824686Swnj }
2834686Swnj 
2845105Swnj /*
2855105Swnj  * Collision on ethernet interface.  Do exponential
2865105Swnj  * backoff, and retransmit.  If have backed off all
2876335Ssam  * the way print warning diagnostic, and drop packet.
2885105Swnj  */
2894686Swnj encollide(unit)
2904686Swnj 	int unit;
2914686Swnj {
2926242Sroot 	struct en_softc *es = &en_softc[unit];
2934686Swnj COUNT(ENCOLLIDE);
2944686Swnj 
2955105Swnj 	es->es_if.if_collisions++;
2965083Swnj 	if (es->es_oactive == 0)
2974686Swnj 		return;
2986242Sroot 	endocoll(unit);
2996242Sroot }
3006242Sroot 
3016242Sroot endocoll(unit)
3026242Sroot 	int unit;
3036242Sroot {
3046242Sroot 	register struct en_softc *es = &en_softc[unit];
3056242Sroot 
3065171Swnj 	/*
3075171Swnj 	 * Es_mask is a 16 bit number with n low zero bits, with
3085171Swnj 	 * n the number of backoffs.  When es_mask is 0 we have
3095171Swnj 	 * backed off 16 times, and give up.
3105171Swnj 	 */
3115083Swnj 	if (es->es_mask == 0) {
3125213Swnj 		printf("en%d: send error\n", unit);
3135083Swnj 		enxint(unit);
3145171Swnj 		return;
3154686Swnj 	}
3165171Swnj 	/*
3175171Swnj 	 * Another backoff.  Restart with delay based on n low bits
3185171Swnj 	 * of the interval timer.
3195171Swnj 	 */
3205171Swnj 	es->es_mask <<= 1;
3215171Swnj 	es->es_delay = mfpr(ICR) &~ es->es_mask;
3225171Swnj 	enstart(unit);
3234686Swnj }
3244686Swnj 
3256027Ssam struct	sockaddr_pup pupsrc = { AF_PUP };
3266027Ssam struct	sockaddr_pup pupdst = { AF_PUP };
3276027Ssam struct	sockproto pupproto = { PF_PUP };
3285105Swnj /*
3295105Swnj  * Ethernet interface receiver interrupt.
3305105Swnj  * If input error just drop packet.
3315105Swnj  * Otherwise purge input buffered data path and examine
3325105Swnj  * packet to determine type.  If can't determine length
3335105Swnj  * from type, then have to drop packet.  Othewise decapsulate
3345105Swnj  * packet based on type and pass to type specific higher-level
3355105Swnj  * input routine.
3365105Swnj  */
3374686Swnj enrint(unit)
3384686Swnj 	int unit;
3394686Swnj {
3405171Swnj 	register struct en_softc *es = &en_softc[unit];
3415171Swnj 	struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
3425171Swnj 	register struct en_header *en;
3435083Swnj     	struct mbuf *m;
3446471Sroot 	int len, plen; short resid;
3455171Swnj 	register struct ifqueue *inq;
3465083Swnj 	int off;
3474686Swnj COUNT(ENRINT);
3484686Swnj 
3495171Swnj 	es->es_if.if_ipackets++;
3505105Swnj 
3515105Swnj 	/*
3525171Swnj 	 * Purge BDP; drop if input error indicated.
3535105Swnj 	 */
3546335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
3556335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3564771Swnj 	if (addr->en_istat&EN_IERROR) {
3575105Swnj 		es->es_if.if_ierrors++;
3586238Sroot 		if (es->es_if.if_ierrors % 100 == 0)
3596238Sroot 			printf("en%d: += 100 input errors\n", unit);
3605083Swnj 		goto setup;
3614686Swnj 	}
3625105Swnj 
3635105Swnj 	/*
3646471Sroot 	 * Calculate input data length.
3655105Swnj 	 * Get pointer to ethernet header (in input buffer).
3665105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3675105Swnj 	 * get true type from first 16-bit word past data.
3685105Swnj 	 * Remember that type was trailer by setting off.
3695105Swnj 	 */
3706471Sroot 	resid = addr->en_iwc;
3716471Sroot 	if (resid)
3726471Sroot 		resid |= 0176000;
3736471Sroot 	len = (((sizeof (struct en_header) + ENMTU) >> 1) + resid) << 1;
3746471Sroot 	len -= sizeof (struct en_header);
3756471Sroot 	if (len >= ENMTU)
3766471Sroot 		goto setup;			/* sanity */
3775105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3785083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3795083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3805083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3815083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3825171Swnj 		if (off >= ENMTU)
3835171Swnj 			goto setup;		/* sanity */
3845083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3856471Sroot 		resid = *(endataaddr(en, off+2, u_short *));
3866471Sroot 		if (off + resid > len)
3876471Sroot 			goto setup;		/* sanity */
3886471Sroot 		len = off + resid;
3895083Swnj 	} else
3905083Swnj 		off = 0;
3915083Swnj 	if (len == 0)
3925083Swnj 		goto setup;
3935105Swnj 	/*
3945105Swnj 	 * Pull packet off interface.  Off is nonzero if packet
3955105Swnj 	 * has trailing header; if_rubaget will then force this header
3965105Swnj 	 * information to be at the front, but we still have to drop
3976471Sroot 	 * the type and length which are at the front of any trailer data.
3985105Swnj 	 */
3995105Swnj 	m = if_rubaget(&es->es_ifuba, len, off);
4005213Swnj 	if (m == 0)
4015213Swnj 		goto setup;
4025105Swnj 	if (off) {
4036471Sroot 		m->m_off += 2 * sizeof (u_short);
4046471Sroot 		m->m_len -= 2 * sizeof (u_short);
4055105Swnj 	}
4066027Ssam 	switch (en->en_type) {
4076027Ssam 
4086027Ssam #ifdef INET
4096027Ssam 	case ENPUP_IPTYPE:
4106260Swnj 		schednetisr(NETISR_IP);
4116027Ssam 		inq = &ipintrq;
4126027Ssam 		break;
4136027Ssam #endif
4146335Ssam #ifdef PUP
4156027Ssam 	case ENPUP_PUPTYPE: {
4166027Ssam 		struct pup_header *pup = mtod(m, struct pup_header *);
4176027Ssam 
4186027Ssam 		pupproto.sp_protocol = pup->pup_type;
4196027Ssam 		pupdst.spup_addr = pup->pup_dport;
4206027Ssam 		pupsrc.spup_addr = pup->pup_sport;
4216159Ssam 		raw_input(m, &pupproto, (struct sockaddr *)&pupdst,
4226335Ssam 		  (struct sockaddr *)&pupsrc);
4236027Ssam 		goto setup;
4246027Ssam 	}
4256335Ssam #endif
4266476Swnj 	default:
4276476Swnj 		m_freem(m);
4286476Swnj 		goto setup;
4296335Ssam 	}
4306335Ssam 
4316207Swnj 	if (IF_QFULL(inq)) {
4326207Swnj 		IF_DROP(inq);
4336335Ssam 		m_freem(m);
4346207Swnj 	} else
4356207Swnj 		IF_ENQUEUE(inq, m);
4365105Swnj 
4374688Swnj setup:
4385105Swnj 	/*
4395105Swnj 	 * Reset for next packet.
4405105Swnj 	 */
4415105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4425083Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
4434771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4444688Swnj }
4454686Swnj 
4465083Swnj /*
4475083Swnj  * Ethernet output routine.
4485083Swnj  * Encapsulate a packet of type family for the local net.
4495105Swnj  * Use trailer local net encapsulation if enough data in first
4505105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4515083Swnj  */
4526335Ssam enoutput(ifp, m0, dst)
4535083Swnj 	struct ifnet *ifp;
4545083Swnj 	struct mbuf *m0;
4556335Ssam 	struct sockaddr *dst;
4564686Swnj {
457*6503Ssam 	int type, dest, s, error;
4585105Swnj 	register struct mbuf *m = m0;
4595083Swnj 	register struct en_header *en;
4606335Ssam 	register int off;
4614686Swnj 
4625927Sroot COUNT(ENOUTPUT);
4636335Ssam 	switch (dst->sa_family) {
4645083Swnj 
4655083Swnj #ifdef INET
4666335Ssam 	case AF_INET:
4676484Swnj 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
468*6503Ssam 		if (dest & 0x00ffff00) {
469*6503Ssam 			error = EPERM;		/* ??? */
4706486Swnj 			goto bad;
471*6503Ssam 		}
4726484Swnj 		dest = (dest >> 24) & 0xff;
4736335Ssam 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4746335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
4756471Sroot 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4765083Swnj 			type = ENPUP_TRAIL + (off>>9);
4776471Sroot 			m->m_off -= 2 * sizeof (u_short);
4786471Sroot 			m->m_len += 2 * sizeof (u_short);
4795105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
4806471Sroot 			*(mtod(m, u_short *) + 1) = m->m_len;
4815105Swnj 			goto gottrailertype;
4825083Swnj 		}
4835105Swnj 		type = ENPUP_IPTYPE;
4845105Swnj 		off = 0;
4855105Swnj 		goto gottype;
4865083Swnj #endif
4876027Ssam #ifdef PUP
4886335Ssam 	case AF_PUP:
4896335Ssam 		dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host;
4906027Ssam 		type = ENPUP_PUPTYPE;
4916027Ssam 		off = 0;
4926027Ssam 		goto gottype;
4936027Ssam #endif
4946027Ssam 
4955083Swnj 	default:
4966335Ssam 		printf("en%d: can't handle af%d\n", ifp->if_unit,
4976335Ssam 			dst->sa_family);
498*6503Ssam 		error = EAFNOSUPPORT;
499*6503Ssam 		goto bad;
5004686Swnj 	}
5015105Swnj 
5025171Swnj gottrailertype:
5035105Swnj 	/*
5045105Swnj 	 * Packet to be sent as trailer: move first packet
5055105Swnj 	 * (control information) to end of chain.
5065105Swnj 	 */
5075105Swnj 	while (m->m_next)
5085105Swnj 		m = m->m_next;
5095105Swnj 	m->m_next = m0;
5105105Swnj 	m = m0->m_next;
5115105Swnj 	m0->m_next = 0;
5125171Swnj 	m0 = m;
5135105Swnj 
5145171Swnj gottype:
5155105Swnj 	/*
5165105Swnj 	 * Add local net header.  If no space in first mbuf,
5175105Swnj 	 * allocate another.
5185105Swnj 	 */
5195213Swnj 	if (m->m_off > MMAXOFF ||
5205213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5215584Sroot 		m = m_get(M_DONTWAIT);
5225083Swnj 		if (m == 0) {
523*6503Ssam 			error = ENOBUFS;
524*6503Ssam 			goto bad;
5255083Swnj 		}
5265083Swnj 		m->m_next = m0;
5275083Swnj 		m->m_off = MMINOFF;
5285083Swnj 		m->m_len = sizeof (struct en_header);
5295083Swnj 	} else {
5305083Swnj 		m->m_off -= sizeof (struct en_header);
5315083Swnj 		m->m_len += sizeof (struct en_header);
5325083Swnj 	}
5335083Swnj 	en = mtod(m, struct en_header *);
5345083Swnj 	en->en_shost = ifp->if_host[0];
5355083Swnj 	en->en_dhost = dest;
5365083Swnj 	en->en_type = type;
5375105Swnj 
5385105Swnj 	/*
5395105Swnj 	 * Queue message on interface, and start output if interface
5405105Swnj 	 * not yet active.
5415105Swnj 	 */
5425083Swnj 	s = splimp();
5436207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5446207Swnj 		IF_DROP(&ifp->if_snd);
545*6503Ssam 		error = ENOBUFS;
546*6503Ssam 		goto qfull;
5476207Swnj 	}
5485083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5495083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5505083Swnj 		enstart(ifp->if_unit);
5515275Swnj 	splx(s);
552*6503Ssam 	return (0);
553*6503Ssam qfull:
554*6503Ssam 	m0 = m;
555*6503Ssam 	splx(s);
5566484Swnj bad:
557*6503Ssam 	m_freem(m0);
558*6503Ssam 	return (error);
5594686Swnj }
5606410Ssam 
5616410Ssam #if NIMP == 0 && NEN > 0
5626410Ssam /*
5636410Ssam  * Logical host interface driver.
5646410Ssam  * Allows host to appear as an ARPAnet
5656410Ssam  * logical host.  Must also have routing
5666410Ssam  * table entry set up to forward packets
5676410Ssam  * to appropriate gateway on localnet.
5686410Ssam  */
5696410Ssam 
5706410Ssam struct	ifnet enlhif;
5716410Ssam int	enlhoutput();
5726410Ssam 
5736410Ssam /*
5746410Ssam  * Called by localnet interface to allow logical
5756410Ssam  * host interface to "attach".  Nothing should ever
5766410Ssam  * be sent locally to this interface, it's purpose
5776410Ssam  * is simply to establish the host's arpanet address.
5786410Ssam  */
5796410Ssam enlhinit(addr)
5806410Ssam 	int addr;
5816410Ssam {
5826410Ssam 	register struct ifnet *ifp = &enlhif;
5836410Ssam 	register struct sockaddr_in *sin;
5846410Ssam 
5856410Ssam COUNT(ENLHINIT);
5866410Ssam 	ifp->if_name = "lh";
5876410Ssam 	ifp->if_mtu = ENMTU;
5886410Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
5896410Ssam 	sin->sin_family = AF_INET;
5906410Ssam 	sin->sin_addr.s_addr = addr;
5916410Ssam 	ifp->if_net = sin->sin_addr.s_net;
5926410Ssam 	ifp->if_flags = IFF_UP;
5936410Ssam 	ifp->if_output = enlhoutput;	/* should never be used */
5946410Ssam 	if_attach(ifp);
5956410Ssam }
5966410Ssam 
5976410Ssam enlhoutput(ifp, m0, dst)
5986410Ssam 	struct ifnet *ifp;
5996410Ssam 	struct mbuf *m0;
6006410Ssam 	struct sockaddr *dst;
6016410Ssam {
6026410Ssam COUNT(ENLHOUTPUT);
6036410Ssam 	ifp->if_oerrors++;
6046410Ssam 	m_freem(m0);
6056410Ssam 	return (0);
6066410Ssam }
6076410Ssam #endif
608