xref: /csrg-svn/sys/vax/if/if_en.c (revision 9271)
1*9271Ssam /*	if_en.c	4.73	82/11/17	*/
24686Swnj 
34686Swnj #include "en.h"
45105Swnj 
54686Swnj /*
65105Swnj  * Xerox prototype (3 Mb) Ethernet interface driver.
74686Swnj  */
84686Swnj 
94686Swnj #include "../h/param.h"
104686Swnj #include "../h/systm.h"
114686Swnj #include "../h/mbuf.h"
124686Swnj #include "../h/pte.h"
134686Swnj #include "../h/buf.h"
145083Swnj #include "../h/protosw.h"
155083Swnj #include "../h/socket.h"
165083Swnj #include "../h/vmmac.h"
178462Sroot #include <errno.h>
188462Sroot 
198462Sroot #include "../net/if.h"
208462Sroot #include "../net/netisr.h"
218462Sroot #include "../net/route.h"
228418Swnj #include "../netinet/in.h"
238418Swnj #include "../netinet/in_systm.h"
248418Swnj #include "../netinet/ip.h"
258418Swnj #include "../netinet/ip_var.h"
268418Swnj #include "../netpup/pup.h"
274686Swnj 
288462Sroot #include "../vax/cpu.h"
298462Sroot #include "../vax/mtpr.h"
308462Sroot #include "../vaxif/if_en.h"
318462Sroot #include "../vaxif/if_enreg.h"
328462Sroot #include "../vaxif/if_uba.h"
338462Sroot #include "../vaxuba/ubareg.h"
348462Sroot #include "../vaxuba/ubavar.h"
358462Sroot 
365213Swnj #define	ENMTU	(1024+512)
376925Swnj #define	ENMRU	(1024+512+16)		/* 16 is enough to receive trailer */
385083Swnj 
394686Swnj int	enprobe(), enattach(), enrint(), enxint(), encollide();
404686Swnj struct	uba_device *eninfo[NEN];
414686Swnj u_short enstd[] = { 0 };
424686Swnj struct	uba_driver endriver =
435171Swnj 	{ enprobe, 0, enattach, 0, enstd, "en", eninfo };
444686Swnj #define	ENUNIT(x)	minor(x)
454686Swnj 
465105Swnj int	eninit(),enoutput(),enreset();
475105Swnj 
485105Swnj /*
495105Swnj  * Ethernet software status per interface.
505105Swnj  *
515105Swnj  * Each interface is referenced by a network interface structure,
525105Swnj  * es_if, which the routing code uses to locate the interface.
535105Swnj  * This structure contains the output queue for the interface, its address, ...
545105Swnj  * We also have, for each interface, a UBA interface structure, which
555105Swnj  * contains information about the UNIBUS resources held by the interface:
565105Swnj  * map registers, buffered data paths, etc.  Information is cached in this
575105Swnj  * structure for use by the if_uba.c routines in running the interface
585105Swnj  * efficiently.
595105Swnj  */
605083Swnj struct	en_softc {
615105Swnj 	struct	ifnet es_if;		/* network-visible interface */
625105Swnj 	struct	ifuba es_ifuba;		/* UNIBUS resources */
635105Swnj 	short	es_delay;		/* current output delay */
645105Swnj 	short	es_mask;		/* mask for current output delay */
656471Sroot 	short	es_lastx;		/* host last transmitted to */
665105Swnj 	short	es_oactive;		/* is output active? */
675105Swnj 	short	es_olen;		/* length of last output */
685083Swnj } en_softc[NEN];
694686Swnj 
705105Swnj /*
715105Swnj  * Do output DMA to determine interface presence and
725105Swnj  * interrupt vector.  DMA is too short to disturb other hosts.
735105Swnj  */
744686Swnj enprobe(reg)
754686Swnj 	caddr_t reg;
764686Swnj {
775171Swnj 	register int br, cvec;		/* r11, r10 value-result */
784686Swnj 	register struct endevice *addr = (struct endevice *)reg;
794686Swnj 
804686Swnj #ifdef lint
814686Swnj 	br = 0; cvec = br; br = cvec;
824922Swnj 	enrint(0); enxint(0); encollide(0);
834686Swnj #endif
844686Swnj 	addr->en_istat = 0;
854686Swnj 	addr->en_owc = -1;
864686Swnj 	addr->en_oba = 0;
874771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
884686Swnj 	DELAY(100000);
894686Swnj 	addr->en_ostat = 0;
906575Ssam #ifdef ECHACK
916575Ssam 	br = 0x16;
926575Ssam #endif
934686Swnj 	return (1);
944686Swnj }
954686Swnj 
965105Swnj /*
975105Swnj  * Interface exists: make available by filling in network interface
985105Swnj  * record.  System will initialize the interface when it is ready
995105Swnj  * to accept packets.
1005105Swnj  */
1014686Swnj enattach(ui)
1024686Swnj 	struct uba_device *ui;
1034686Swnj {
1045105Swnj 	register struct en_softc *es = &en_softc[ui->ui_unit];
1056335Ssam 	register struct sockaddr_in *sin;
1064688Swnj 
1075105Swnj 	es->es_if.if_unit = ui->ui_unit;
1085171Swnj 	es->es_if.if_name = "en";
1095105Swnj 	es->es_if.if_mtu = ENMTU;
1107163Ssam 	es->es_if.if_net = ui->ui_flags;
1115105Swnj 	es->es_if.if_host[0] =
1126335Ssam 	 (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
1136335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_addr;
1146335Ssam 	sin->sin_family = AF_INET;
1156335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
1166335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
1176335Ssam 	sin->sin_family = AF_INET;
1186335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
1196335Ssam 	es->es_if.if_flags = IFF_BROADCAST;
1205171Swnj 	es->es_if.if_init = eninit;
1215105Swnj 	es->es_if.if_output = enoutput;
1228978Sroot 	es->es_if.if_reset = enreset;
1236554Ssam 	es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT;
124*9271Ssam #if defined(VAX750)
125*9271Ssam 	/* don't chew up 750 bdp's */
126*9271Ssam 	if (cpu == VAX_750 && ui->ui_unit > 0)
127*9271Ssam 		es->es_ifuba.ifu_flags &= ~UBA_NEEDBDP;
128*9271Ssam #endif
1295160Swnj 	if_attach(&es->es_if);
1304686Swnj }
1314686Swnj 
1325105Swnj /*
1335105Swnj  * Reset of interface after UNIBUS reset.
1345105Swnj  * If interface is on specified uba, reset its state.
1355105Swnj  */
1365105Swnj enreset(unit, uban)
1375105Swnj 	int unit, uban;
1385105Swnj {
1395105Swnj 	register struct uba_device *ui;
1405105Swnj 
1415171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1425171Swnj 	    ui->ui_ubanum != uban)
1435105Swnj 		return;
1445171Swnj 	printf(" en%d", unit);
1455105Swnj 	eninit(unit);
1465105Swnj }
1475105Swnj 
1485105Swnj /*
1495105Swnj  * Initialization of interface; clear recorded pending
1505105Swnj  * operations, and reinitialize UNIBUS usage.
1515105Swnj  */
1524688Swnj eninit(unit)
1534686Swnj 	int unit;
1545083Swnj {
1555171Swnj 	register struct en_softc *es = &en_softc[unit];
1565171Swnj 	register struct uba_device *ui = eninfo[unit];
1574686Swnj 	register struct endevice *addr;
1585105Swnj 	int s;
1594686Swnj 
1605105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1616925Swnj 	    sizeof (struct en_header), (int)btoc(ENMRU)) == 0) {
1625171Swnj 		printf("en%d: can't initialize\n", unit);
1636335Ssam 		es->es_if.if_flags &= ~IFF_UP;
1645083Swnj 		return;
1654686Swnj 	}
1664686Swnj 	addr = (struct endevice *)ui->ui_addr;
1675083Swnj 	addr->en_istat = addr->en_ostat = 0;
1684686Swnj 
1695105Swnj 	/*
1705171Swnj 	 * Hang a receive and start any
1715171Swnj 	 * pending writes by faking a transmit complete.
1725105Swnj 	 */
1735105Swnj 	s = splimp();
1745171Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
1756925Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1;
1765171Swnj 	addr->en_istat = EN_IEN|EN_GO;
1775171Swnj 	es->es_oactive = 1;
1786335Ssam 	es->es_if.if_flags |= IFF_UP;
1795105Swnj 	enxint(unit);
1805105Swnj 	splx(s);
1817151Swnj 	if_rtinit(&es->es_if, RTF_UP);
1824686Swnj }
1834686Swnj 
1846471Sroot int	enalldelay = 0;
1856951Swnj int	enlastdel = 50;
1866471Sroot int	enlastmask = (~0) << 5;
1875083Swnj 
1885105Swnj /*
1895105Swnj  * Start or restart output on interface.
1905105Swnj  * If interface is already active, then this is a retransmit
1915105Swnj  * after a collision, and just restuff registers and delay.
1925105Swnj  * If interface is not already active, get another datagram
1935105Swnj  * to send off of the interface queue, and map it to the interface
1945105Swnj  * before starting the output.
1955105Swnj  */
1964688Swnj enstart(dev)
1974686Swnj 	dev_t dev;
1984686Swnj {
1995171Swnj         int unit = ENUNIT(dev);
2005171Swnj 	struct uba_device *ui = eninfo[unit];
2015171Swnj 	register struct en_softc *es = &en_softc[unit];
2025083Swnj 	register struct endevice *addr;
2035083Swnj 	struct mbuf *m;
2045083Swnj 	int dest;
2054686Swnj 
2065083Swnj 	if (es->es_oactive)
2075083Swnj 		goto restart;
2085105Swnj 
2095105Swnj 	/*
2105105Swnj 	 * Not already active: dequeue another request
2115105Swnj 	 * and map it to the UNIBUS.  If no more requests,
2125105Swnj 	 * just return.
2135105Swnj 	 */
2145105Swnj 	IF_DEQUEUE(&es->es_if.if_snd, m);
2155083Swnj 	if (m == 0) {
2165083Swnj 		es->es_oactive = 0;
2174686Swnj 		return;
2184686Swnj 	}
2195213Swnj 	dest = mtod(m, struct en_header *)->en_dhost;
2205105Swnj 	es->es_olen = if_wubaput(&es->es_ifuba, m);
2215105Swnj 
2225105Swnj 	/*
2235105Swnj 	 * Ethernet cannot take back-to-back packets (no
2246471Sroot 	 * buffering in interface.  To help avoid overrunning
2256471Sroot 	 * receivers, enforce a small delay (about 1ms) in interface:
2266471Sroot 	 *	* between all packets when enalldelay
2276471Sroot 	 *	* whenever last packet was broadcast
2286471Sroot 	 *	* whenever this packet is to same host as last packet
2295105Swnj 	 */
2306471Sroot 	if (enalldelay || es->es_lastx == 0 || es->es_lastx == dest) {
2315083Swnj 		es->es_delay = enlastdel;
2326471Sroot 		es->es_mask = enlastmask;
2336471Sroot 	}
2346471Sroot 	es->es_lastx = dest;
2355105Swnj 
2365083Swnj restart:
2375105Swnj 	/*
2385105Swnj 	 * Have request mapped to UNIBUS for transmission.
2395105Swnj 	 * Purge any stale data from this BDP, and start the otput.
2405105Swnj 	 */
2416335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
2426335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2434686Swnj 	addr = (struct endevice *)ui->ui_addr;
2445160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2455083Swnj 	addr->en_odelay = es->es_delay;
2465083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2474771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2485083Swnj 	es->es_oactive = 1;
2494686Swnj }
2504686Swnj 
2515105Swnj /*
2525105Swnj  * Ethernet interface transmitter interrupt.
2535105Swnj  * Start another output if more data to send.
2545105Swnj  */
2554686Swnj enxint(unit)
2564686Swnj 	int unit;
2574686Swnj {
2585171Swnj 	register struct uba_device *ui = eninfo[unit];
2595171Swnj 	register struct en_softc *es = &en_softc[unit];
2606242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2614686Swnj 
2625083Swnj 	if (es->es_oactive == 0)
2635083Swnj 		return;
2646242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
2656242Sroot 		es->es_if.if_oerrors++;
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 
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;
3438603Sroot 	int len; short resid;
3445171Swnj 	register struct ifqueue *inq;
3455083Swnj 	int off;
3464686Swnj 
3475171Swnj 	es->es_if.if_ipackets++;
3485105Swnj 
3495105Swnj 	/*
3505171Swnj 	 * Purge BDP; drop if input error indicated.
3515105Swnj 	 */
3526335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
3536335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3544771Swnj 	if (addr->en_istat&EN_IERROR) {
3555105Swnj 		es->es_if.if_ierrors++;
3565083Swnj 		goto setup;
3574686Swnj 	}
3585105Swnj 
3595105Swnj 	/*
3606471Sroot 	 * Calculate input data length.
3615105Swnj 	 * Get pointer to ethernet header (in input buffer).
3625105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3635105Swnj 	 * get true type from first 16-bit word past data.
3645105Swnj 	 * Remember that type was trailer by setting off.
3655105Swnj 	 */
3666471Sroot 	resid = addr->en_iwc;
3676471Sroot 	if (resid)
3686471Sroot 		resid |= 0176000;
3696925Swnj 	len = (((sizeof (struct en_header) + ENMRU) >> 1) + resid) << 1;
3706471Sroot 	len -= sizeof (struct en_header);
3716925Swnj 	if (len > ENMRU)
3726471Sroot 		goto setup;			/* sanity */
3735105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3745083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3755083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3765083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3775083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3786925Swnj 		if (off > ENMTU)
3795171Swnj 			goto setup;		/* sanity */
3805083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3816471Sroot 		resid = *(endataaddr(en, off+2, u_short *));
3826471Sroot 		if (off + resid > len)
3836471Sroot 			goto setup;		/* sanity */
3846471Sroot 		len = off + resid;
3855083Swnj 	} else
3865083Swnj 		off = 0;
3875083Swnj 	if (len == 0)
3885083Swnj 		goto setup;
3895105Swnj 	/*
3905105Swnj 	 * Pull packet off interface.  Off is nonzero if packet
3915105Swnj 	 * has trailing header; if_rubaget will then force this header
3925105Swnj 	 * information to be at the front, but we still have to drop
3936471Sroot 	 * the type and length which are at the front of any trailer data.
3945105Swnj 	 */
3955105Swnj 	m = if_rubaget(&es->es_ifuba, len, off);
3965213Swnj 	if (m == 0)
3975213Swnj 		goto setup;
3985105Swnj 	if (off) {
3996471Sroot 		m->m_off += 2 * sizeof (u_short);
4006471Sroot 		m->m_len -= 2 * sizeof (u_short);
4015105Swnj 	}
4026027Ssam 	switch (en->en_type) {
4036027Ssam 
4046027Ssam #ifdef INET
4056027Ssam 	case ENPUP_IPTYPE:
4066260Swnj 		schednetisr(NETISR_IP);
4076027Ssam 		inq = &ipintrq;
4086027Ssam 		break;
4096027Ssam #endif
4106335Ssam #ifdef PUP
4116027Ssam 	case ENPUP_PUPTYPE: {
4126027Ssam 		struct pup_header *pup = mtod(m, struct pup_header *);
4136027Ssam 
4146027Ssam 		pupproto.sp_protocol = pup->pup_type;
4156027Ssam 		pupdst.spup_addr = pup->pup_dport;
4166027Ssam 		pupsrc.spup_addr = pup->pup_sport;
4176526Ssam 		raw_input(m, &pupproto, (struct sockaddr *)&pupsrc,
4186526Ssam 		  (struct sockaddr *)&pupdst);
4196027Ssam 		goto setup;
4206027Ssam 	}
4216335Ssam #endif
4226476Swnj 	default:
4236476Swnj 		m_freem(m);
4246476Swnj 		goto setup;
4256335Ssam 	}
4266335Ssam 
4276207Swnj 	if (IF_QFULL(inq)) {
4286207Swnj 		IF_DROP(inq);
4296335Ssam 		m_freem(m);
4306207Swnj 	} else
4316207Swnj 		IF_ENQUEUE(inq, m);
4325105Swnj 
4334688Swnj setup:
4345105Swnj 	/*
4355105Swnj 	 * Reset for next packet.
4365105Swnj 	 */
4375105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4386925Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1;
4394771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4404688Swnj }
4414686Swnj 
4425083Swnj /*
4435083Swnj  * Ethernet output routine.
4445083Swnj  * Encapsulate a packet of type family for the local net.
4455105Swnj  * Use trailer local net encapsulation if enough data in first
4465105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4475083Swnj  */
4486335Ssam enoutput(ifp, m0, dst)
4495083Swnj 	struct ifnet *ifp;
4505083Swnj 	struct mbuf *m0;
4516335Ssam 	struct sockaddr *dst;
4524686Swnj {
4536503Ssam 	int type, dest, s, error;
4545105Swnj 	register struct mbuf *m = m0;
4555083Swnj 	register struct en_header *en;
4566335Ssam 	register int off;
4574686Swnj 
4586335Ssam 	switch (dst->sa_family) {
4595083Swnj 
4605083Swnj #ifdef INET
4616335Ssam 	case AF_INET:
4626484Swnj 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
4639178Ssam 		if (in_lnaof(*((struct in_addr *)&dest)) >= 0x100) {
4646503Ssam 			error = EPERM;		/* ??? */
4656486Swnj 			goto bad;
4666503Ssam 		}
4676484Swnj 		dest = (dest >> 24) & 0xff;
4686335Ssam 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4696335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
4706471Sroot 		    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
4715083Swnj 			type = ENPUP_TRAIL + (off>>9);
4726471Sroot 			m->m_off -= 2 * sizeof (u_short);
4736471Sroot 			m->m_len += 2 * sizeof (u_short);
4745105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
4756471Sroot 			*(mtod(m, u_short *) + 1) = m->m_len;
4765105Swnj 			goto gottrailertype;
4775083Swnj 		}
4785105Swnj 		type = ENPUP_IPTYPE;
4795105Swnj 		off = 0;
4805105Swnj 		goto gottype;
4815083Swnj #endif
4826027Ssam #ifdef PUP
4836335Ssam 	case AF_PUP:
4846335Ssam 		dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host;
4856027Ssam 		type = ENPUP_PUPTYPE;
4866027Ssam 		off = 0;
4876027Ssam 		goto gottype;
4886027Ssam #endif
4896027Ssam 
4905083Swnj 	default:
4916335Ssam 		printf("en%d: can't handle af%d\n", ifp->if_unit,
4926335Ssam 			dst->sa_family);
4936503Ssam 		error = EAFNOSUPPORT;
4946503Ssam 		goto bad;
4954686Swnj 	}
4965105Swnj 
4975171Swnj gottrailertype:
4985105Swnj 	/*
4995105Swnj 	 * Packet to be sent as trailer: move first packet
5005105Swnj 	 * (control information) to end of chain.
5015105Swnj 	 */
5025105Swnj 	while (m->m_next)
5035105Swnj 		m = m->m_next;
5045105Swnj 	m->m_next = m0;
5055105Swnj 	m = m0->m_next;
5065105Swnj 	m0->m_next = 0;
5075171Swnj 	m0 = m;
5085105Swnj 
5095171Swnj gottype:
5105105Swnj 	/*
5115105Swnj 	 * Add local net header.  If no space in first mbuf,
5125105Swnj 	 * allocate another.
5135105Swnj 	 */
5145213Swnj 	if (m->m_off > MMAXOFF ||
5155213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5165584Sroot 		m = m_get(M_DONTWAIT);
5175083Swnj 		if (m == 0) {
5186503Ssam 			error = ENOBUFS;
5196503Ssam 			goto bad;
5205083Swnj 		}
5215083Swnj 		m->m_next = m0;
5225083Swnj 		m->m_off = MMINOFF;
5235083Swnj 		m->m_len = sizeof (struct en_header);
5245083Swnj 	} else {
5255083Swnj 		m->m_off -= sizeof (struct en_header);
5265083Swnj 		m->m_len += sizeof (struct en_header);
5275083Swnj 	}
5285083Swnj 	en = mtod(m, struct en_header *);
5295083Swnj 	en->en_shost = ifp->if_host[0];
5305083Swnj 	en->en_dhost = dest;
5315083Swnj 	en->en_type = type;
5325105Swnj 
5335105Swnj 	/*
5345105Swnj 	 * Queue message on interface, and start output if interface
5355105Swnj 	 * not yet active.
5365105Swnj 	 */
5375083Swnj 	s = splimp();
5386207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5396207Swnj 		IF_DROP(&ifp->if_snd);
5406503Ssam 		error = ENOBUFS;
5416503Ssam 		goto qfull;
5426207Swnj 	}
5435083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5445083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5455083Swnj 		enstart(ifp->if_unit);
5465275Swnj 	splx(s);
5476503Ssam 	return (0);
5486503Ssam qfull:
5496503Ssam 	m0 = m;
5506503Ssam 	splx(s);
5516484Swnj bad:
5526503Ssam 	m_freem(m0);
5536503Ssam 	return (error);
5544686Swnj }
555