xref: /csrg-svn/sys/vax/if/if_en.c (revision 6242)
1*6242Sroot /*	if_en.c	4.42	82/03/15	*/
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"
164686Swnj #include "../h/ubareg.h"
174686Swnj #include "../h/ubavar.h"
184686Swnj #include "../h/enreg.h"
195083Swnj #include "../h/cpu.h"
204686Swnj #include "../h/mtpr.h"
215083Swnj #include "../h/vmmac.h"
225083Swnj #include "../net/in.h"
235083Swnj #include "../net/in_systm.h"
245083Swnj #include "../net/if.h"
255083Swnj #include "../net/if_en.h"
265083Swnj #include "../net/if_uba.h"
275083Swnj #include "../net/ip.h"
285083Swnj #include "../net/ip_var.h"
296027Ssam #include "../net/pup.h"
304686Swnj 
315213Swnj #define	ENMTU	(1024+512)
325083Swnj 
334686Swnj int	enprobe(), enattach(), enrint(), enxint(), encollide();
344686Swnj struct	uba_device *eninfo[NEN];
354686Swnj u_short enstd[] = { 0 };
364686Swnj struct	uba_driver endriver =
375171Swnj 	{ enprobe, 0, enattach, 0, enstd, "en", eninfo };
384686Swnj #define	ENUNIT(x)	minor(x)
394686Swnj 
405105Swnj int	eninit(),enoutput(),enreset();
415105Swnj 
425105Swnj /*
435105Swnj  * Ethernet software status per interface.
445105Swnj  *
455105Swnj  * Each interface is referenced by a network interface structure,
465105Swnj  * es_if, which the routing code uses to locate the interface.
475105Swnj  * This structure contains the output queue for the interface, its address, ...
485105Swnj  * We also have, for each interface, a UBA interface structure, which
495105Swnj  * contains information about the UNIBUS resources held by the interface:
505105Swnj  * map registers, buffered data paths, etc.  Information is cached in this
515105Swnj  * structure for use by the if_uba.c routines in running the interface
525105Swnj  * efficiently.
535105Swnj  */
545083Swnj struct	en_softc {
555105Swnj 	struct	ifnet es_if;		/* network-visible interface */
565105Swnj 	struct	ifuba es_ifuba;		/* UNIBUS resources */
575105Swnj 	short	es_delay;		/* current output delay */
585105Swnj 	short	es_mask;		/* mask for current output delay */
595105Swnj 	u_char	es_lastx;		/* host last transmitted to */
605105Swnj 	short	es_oactive;		/* is output active? */
615105Swnj 	short	es_olen;		/* length of last output */
625083Swnj } en_softc[NEN];
634686Swnj 
645105Swnj /*
655105Swnj  * Do output DMA to determine interface presence and
665105Swnj  * interrupt vector.  DMA is too short to disturb other hosts.
675105Swnj  */
684686Swnj enprobe(reg)
694686Swnj 	caddr_t reg;
704686Swnj {
715171Swnj 	register int br, cvec;		/* r11, r10 value-result */
724686Swnj 	register struct endevice *addr = (struct endevice *)reg;
734686Swnj 
745083Swnj COUNT(ENPROBE);
754686Swnj #ifdef lint
764686Swnj 	br = 0; cvec = br; br = cvec;
774922Swnj 	enrint(0); enxint(0); encollide(0);
784686Swnj #endif
794686Swnj 	addr->en_istat = 0;
804686Swnj 	addr->en_owc = -1;
814686Swnj 	addr->en_oba = 0;
824771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
834686Swnj 	DELAY(100000);
844686Swnj 	addr->en_ostat = 0;
854686Swnj 	return (1);
864686Swnj }
874686Swnj 
885105Swnj /*
895105Swnj  * Interface exists: make available by filling in network interface
905105Swnj  * record.  System will initialize the interface when it is ready
915105Swnj  * to accept packets.
925105Swnj  */
934686Swnj enattach(ui)
944686Swnj 	struct uba_device *ui;
954686Swnj {
965105Swnj 	register struct en_softc *es = &en_softc[ui->ui_unit];
975105Swnj COUNT(ENATTACH);
984688Swnj 
995105Swnj 	es->es_if.if_unit = ui->ui_unit;
1005171Swnj 	es->es_if.if_name = "en";
1015105Swnj 	es->es_if.if_mtu = ENMTU;
1025105Swnj 	es->es_if.if_net = ui->ui_flags;
1035105Swnj 	es->es_if.if_host[0] =
1045213Swnj 	    (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
1055294Sroot #ifdef ENKLUDGE
1065294Sroot 	if (es->es_if.if_net == 10) {
1075294Sroot 		es->es_if.if_host[0] <<= 16;
1085294Sroot 		es->es_if.if_host[0] |= 0x4e;
1095294Sroot 	}
1105294Sroot #endif
1115105Swnj 	es->es_if.if_addr =
1125105Swnj 	    if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
1136087Sroot 	es->es_if.if_broadaddr =
1146087Sroot 	    if_makeaddr(es->es_if.if_net, 0);
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);
1204686Swnj }
1214686Swnj 
1225105Swnj /*
1235105Swnj  * Reset of interface after UNIBUS reset.
1245105Swnj  * If interface is on specified uba, reset its state.
1255105Swnj  */
1265105Swnj enreset(unit, uban)
1275105Swnj 	int unit, uban;
1285105Swnj {
1295105Swnj 	register struct uba_device *ui;
1305105Swnj COUNT(ENRESET);
1315105Swnj 
1325171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1335171Swnj 	    ui->ui_ubanum != uban)
1345105Swnj 		return;
1355171Swnj 	printf(" en%d", unit);
1365105Swnj 	eninit(unit);
1375105Swnj }
1385105Swnj 
1395105Swnj /*
1405105Swnj  * Initialization of interface; clear recorded pending
1415105Swnj  * operations, and reinitialize UNIBUS usage.
1425105Swnj  */
1434688Swnj eninit(unit)
1444686Swnj 	int unit;
1455083Swnj {
1465171Swnj 	register struct en_softc *es = &en_softc[unit];
1475171Swnj 	register struct uba_device *ui = eninfo[unit];
1484686Swnj 	register struct endevice *addr;
1495105Swnj 	int s;
1504686Swnj 
1515105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1525708Sroot 	    sizeof (struct en_header), (int)btoc(ENMTU)) == 0) {
1535171Swnj 		printf("en%d: can't initialize\n", unit);
1545083Swnj 		return;
1554686Swnj 	}
1564686Swnj 	addr = (struct endevice *)ui->ui_addr;
1575083Swnj 	addr->en_istat = addr->en_ostat = 0;
1584686Swnj 
1595105Swnj 	/*
1605171Swnj 	 * Hang a receive and start any
1615171Swnj 	 * pending writes by faking a transmit complete.
1625105Swnj 	 */
1635105Swnj 	s = splimp();
1645171Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
1655171Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
1665171Swnj 	addr->en_istat = EN_IEN|EN_GO;
1675171Swnj 	es->es_oactive = 1;
1685105Swnj 	enxint(unit);
1695105Swnj 	splx(s);
1704686Swnj }
1714686Swnj 
1724717Swnj int	enlastdel = 25;
1735083Swnj 
1745105Swnj /*
1755105Swnj  * Start or restart output on interface.
1765105Swnj  * If interface is already active, then this is a retransmit
1775105Swnj  * after a collision, and just restuff registers and delay.
1785105Swnj  * If interface is not already active, get another datagram
1795105Swnj  * to send off of the interface queue, and map it to the interface
1805105Swnj  * before starting the output.
1815105Swnj  */
1824688Swnj enstart(dev)
1834686Swnj 	dev_t dev;
1844686Swnj {
1855171Swnj         int unit = ENUNIT(dev);
1865171Swnj 	struct uba_device *ui = eninfo[unit];
1875171Swnj 	register struct en_softc *es = &en_softc[unit];
1885083Swnj 	register struct endevice *addr;
1895083Swnj 	struct mbuf *m;
1905083Swnj 	int dest;
1914688Swnj COUNT(ENSTART);
1924686Swnj 
1935083Swnj 	if (es->es_oactive)
1945083Swnj 		goto restart;
1955105Swnj 
1965105Swnj 	/*
1975105Swnj 	 * Not already active: dequeue another request
1985105Swnj 	 * and map it to the UNIBUS.  If no more requests,
1995105Swnj 	 * just return.
2005105Swnj 	 */
2015105Swnj 	IF_DEQUEUE(&es->es_if.if_snd, m);
2025083Swnj 	if (m == 0) {
2035083Swnj 		es->es_oactive = 0;
2044686Swnj 		return;
2054686Swnj 	}
2065213Swnj 	dest = mtod(m, struct en_header *)->en_dhost;
2075105Swnj 	es->es_olen = if_wubaput(&es->es_ifuba, m);
2085105Swnj 
2095105Swnj 	/*
2105105Swnj 	 * Ethernet cannot take back-to-back packets (no
2115105Swnj 	 * buffering in interface.  To avoid overrunning
2125105Swnj 	 * receiver, enforce a small delay (about 1ms) in interface
2135105Swnj 	 * on successive packets sent to same host.
2145105Swnj 	 */
2155083Swnj 	if (es->es_lastx && es->es_lastx == dest)
2165083Swnj 		es->es_delay = enlastdel;
2175083Swnj 	else
2185083Swnj 		es->es_lastx = dest;
2195105Swnj 
2205083Swnj restart:
2215105Swnj 	/*
2225105Swnj 	 * Have request mapped to UNIBUS for transmission.
2235105Swnj 	 * Purge any stale data from this BDP, and start the otput.
2245105Swnj 	 */
2255105Swnj 	UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2264686Swnj 	addr = (struct endevice *)ui->ui_addr;
2275160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2285083Swnj 	addr->en_odelay = es->es_delay;
2295083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2304771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2315083Swnj 	es->es_oactive = 1;
2324686Swnj }
2334686Swnj 
2345105Swnj /*
2355105Swnj  * Ethernet interface transmitter interrupt.
2365105Swnj  * Start another output if more data to send.
2375105Swnj  */
2384686Swnj enxint(unit)
2394686Swnj 	int unit;
2404686Swnj {
2415171Swnj 	register struct uba_device *ui = eninfo[unit];
2425171Swnj 	register struct en_softc *es = &en_softc[unit];
243*6242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2444686Swnj COUNT(ENXINT);
2454686Swnj 
2465083Swnj 	if (es->es_oactive == 0)
2475083Swnj 		return;
248*6242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
249*6242Sroot 		es->es_if.if_oerrors++;
250*6242Sroot 		if (es->es_if.if_oerrors % 100 == 0)
251*6242Sroot 			printf("en%d: += 100 output errors\n", unit);
252*6242Sroot 		endocoll(unit);
253*6242Sroot 		return;
254*6242Sroot 	}
2555171Swnj 	es->es_if.if_opackets++;
2565083Swnj 	es->es_oactive = 0;
2575083Swnj 	es->es_delay = 0;
2585083Swnj 	es->es_mask = ~0;
2595696Sroot 	if (es->es_ifuba.ifu_xtofree) {
2605696Sroot 		m_freem(es->es_ifuba.ifu_xtofree);
2615696Sroot 		es->es_ifuba.ifu_xtofree = 0;
2625696Sroot 	}
2635105Swnj 	if (es->es_if.if_snd.ifq_head == 0) {
2645083Swnj 		es->es_lastx = 0;
2654686Swnj 		return;
2664686Swnj 	}
2675083Swnj 	enstart(unit);
2684686Swnj }
2694686Swnj 
2705105Swnj /*
2715105Swnj  * Collision on ethernet interface.  Do exponential
2725105Swnj  * backoff, and retransmit.  If have backed off all
2735105Swnj  * the way printing warning diagnostic, and drop packet.
2745105Swnj  */
2754686Swnj encollide(unit)
2764686Swnj 	int unit;
2774686Swnj {
278*6242Sroot 	struct en_softc *es = &en_softc[unit];
2794686Swnj COUNT(ENCOLLIDE);
2804686Swnj 
2815105Swnj 	es->es_if.if_collisions++;
2825083Swnj 	if (es->es_oactive == 0)
2834686Swnj 		return;
284*6242Sroot 	endocoll(unit);
285*6242Sroot }
286*6242Sroot 
287*6242Sroot endocoll(unit)
288*6242Sroot 	int unit;
289*6242Sroot {
290*6242Sroot 	register struct en_softc *es = &en_softc[unit];
291*6242Sroot 
2925171Swnj 	/*
2935171Swnj 	 * Es_mask is a 16 bit number with n low zero bits, with
2945171Swnj 	 * n the number of backoffs.  When es_mask is 0 we have
2955171Swnj 	 * backed off 16 times, and give up.
2965171Swnj 	 */
2975083Swnj 	if (es->es_mask == 0) {
2985213Swnj 		printf("en%d: send error\n", unit);
2995083Swnj 		enxint(unit);
3005171Swnj 		return;
3014686Swnj 	}
3025171Swnj 	/*
3035171Swnj 	 * Another backoff.  Restart with delay based on n low bits
3045171Swnj 	 * of the interval timer.
3055171Swnj 	 */
3065171Swnj 	es->es_mask <<= 1;
3075171Swnj 	es->es_delay = mfpr(ICR) &~ es->es_mask;
3085171Swnj 	enstart(unit);
3094686Swnj }
3104686Swnj 
3116027Ssam struct	sockaddr_pup pupsrc = { AF_PUP };
3126027Ssam struct	sockaddr_pup pupdst = { AF_PUP };
3136027Ssam struct	sockproto pupproto = { PF_PUP };
3145105Swnj /*
3155105Swnj  * Ethernet interface receiver interrupt.
3165105Swnj  * If input error just drop packet.
3175105Swnj  * Otherwise purge input buffered data path and examine
3185105Swnj  * packet to determine type.  If can't determine length
3195105Swnj  * from type, then have to drop packet.  Othewise decapsulate
3205105Swnj  * packet based on type and pass to type specific higher-level
3215105Swnj  * input routine.
3225105Swnj  */
3234686Swnj enrint(unit)
3244686Swnj 	int unit;
3254686Swnj {
3265171Swnj 	register struct en_softc *es = &en_softc[unit];
3275171Swnj 	struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
3285171Swnj 	register struct en_header *en;
3295083Swnj     	struct mbuf *m;
3305171Swnj 	int len;
3315171Swnj 	register struct ifqueue *inq;
3325083Swnj 	int off;
3334686Swnj COUNT(ENRINT);
3344686Swnj 
3355171Swnj 	es->es_if.if_ipackets++;
3365105Swnj 
3375105Swnj 	/*
3385171Swnj 	 * Purge BDP; drop if input error indicated.
3395105Swnj 	 */
3405105Swnj 	UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3414771Swnj 	if (addr->en_istat&EN_IERROR) {
3425105Swnj 		es->es_if.if_ierrors++;
3436238Sroot 		if (es->es_if.if_ierrors % 100 == 0)
3446238Sroot 			printf("en%d: += 100 input errors\n", unit);
3455083Swnj 		goto setup;
3464686Swnj 	}
3475105Swnj 
3485105Swnj 	/*
3495105Swnj 	 * Get pointer to ethernet header (in input buffer).
3505105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3515105Swnj 	 * get true type from first 16-bit word past data.
3525105Swnj 	 * Remember that type was trailer by setting off.
3535105Swnj 	 */
3545105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3555083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3565083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3575083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3585083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3595171Swnj 		if (off >= ENMTU)
3605171Swnj 			goto setup;		/* sanity */
3615083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3625083Swnj 	} else
3635083Swnj 		off = 0;
3645105Swnj 
3655105Swnj 	/*
3665105Swnj 	 * Attempt to infer packet length from type;
3675105Swnj 	 * can't deal with packet if can't infer length.
3685105Swnj 	 */
3695083Swnj 	switch (en->en_type) {
3705083Swnj 
3715083Swnj #ifdef INET
3725083Swnj 	case ENPUP_IPTYPE:
3735239Sroot 		len = htons((u_short)endataaddr(en, off ? off+2 : 0, struct ip *)->ip_len);
3745239Sroot 		if (off)
3755239Sroot 			len += 2;
3764686Swnj 		break;
3774686Swnj #endif
3786027Ssam #ifdef PUP
3796027Ssam 	case ENPUP_PUPTYPE:
3806027Ssam 		len = endataaddr(en, off, struct pup_header *)->pup_length;
3816027Ssam 		if (off)
3826027Ssam 			len -= 2;
3836027Ssam 		break;
3846027Ssam #endif
3856027Ssam 
3865083Swnj 	default:
3876026Sroot 		printf("en%d: unknown pkt type 0x%x\n", unit, en->en_type);
3885083Swnj 		goto setup;
3894686Swnj 	}
3905083Swnj 	if (len == 0)
3915083Swnj 		goto setup;
3925105Swnj 
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
3975171Swnj 	 * the two-byte type which is 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) {
4035105Swnj 		m->m_off += 2;
4045105Swnj 		m->m_len -= 2;
4055105Swnj 	}
4066027Ssam 	switch (en->en_type) {
4076027Ssam 
4086027Ssam #ifdef INET
4096027Ssam 	case ENPUP_IPTYPE:
4106027Ssam 		setipintr();
4116027Ssam 		inq = &ipintrq;
4126027Ssam 		break;
4136027Ssam #endif
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,
4216159Ssam 		 (struct sockaddr *)&pupsrc);
4226027Ssam 		goto setup;
4236027Ssam 		}
4246027Ssam 	}
4256207Swnj 	if (IF_QFULL(inq)) {
4266207Swnj 		IF_DROP(inq);
4276207Swnj 		(void) m_freem(m);
4286207Swnj 	} else
4296207Swnj 		IF_ENQUEUE(inq, m);
4305105Swnj 
4314688Swnj setup:
4325105Swnj 	/*
4335105Swnj 	 * Reset for next packet.
4345105Swnj 	 */
4355105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4365083Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
4374771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4384688Swnj }
4394686Swnj 
4405083Swnj /*
4415083Swnj  * Ethernet output routine.
4425083Swnj  * Encapsulate a packet of type family for the local net.
4435105Swnj  * Use trailer local net encapsulation if enough data in first
4445105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4455083Swnj  */
4465083Swnj enoutput(ifp, m0, pf)
4475083Swnj 	struct ifnet *ifp;
4485083Swnj 	struct mbuf *m0;
4495083Swnj 	int pf;
4504686Swnj {
4516175Ssam 	int type, dest, s, off;
4525105Swnj 	register struct mbuf *m = m0;
4535083Swnj 	register struct en_header *en;
4544686Swnj 
4555927Sroot COUNT(ENOUTPUT);
4565083Swnj 	switch (pf) {
4575083Swnj 
4585083Swnj #ifdef INET
4595083Swnj 	case PF_INET: {
4605083Swnj 		register struct ip *ip = mtod(m0, struct ip *);
4615083Swnj 
4625294Sroot #ifndef ENKLUDGE
4635105Swnj 		dest = ip->ip_dst.s_addr >> 24;
4645294Sroot #else
4655294Sroot 		dest = (ip->ip_dst.s_addr >> 8) & 0xff;
4665294Sroot #endif
4675239Sroot 		off = ntohs((u_short)ip->ip_len) - m->m_len;
4685356Sroot #ifndef ENKLUDGE
4695171Swnj 		if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
4705083Swnj 			type = ENPUP_TRAIL + (off>>9);
4715105Swnj 			m->m_off -= 2;
4725105Swnj 			m->m_len += 2;
4735105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
4745105Swnj 			goto gottrailertype;
4755083Swnj 		}
4765356Sroot #endif
4775105Swnj 		type = ENPUP_IPTYPE;
4785105Swnj 		off = 0;
4795105Swnj 		goto gottype;
4805083Swnj 		}
4815083Swnj #endif
4826027Ssam #ifdef PUP
4836027Ssam 	case PF_PUP: {
4846027Ssam 		register struct pup_header *pup = mtod(m, struct pup_header *);
4855083Swnj 
4866027Ssam 		dest = pup->pup_dhost;
4876027Ssam 		off = pup->pup_length - m->m_len;
4886027Ssam 		if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
4896027Ssam 			type = ENPUP_TRAIL + (off>>9);
4906027Ssam 			m->m_off -= 2;
4916027Ssam 			m->m_len += 2;
4926027Ssam 			*mtod(m, u_short *) = ENPUP_PUPTYPE;
4936027Ssam 			goto gottrailertype;
4946027Ssam 		}
4956027Ssam 		type = ENPUP_PUPTYPE;
4966027Ssam 		off = 0;
4976027Ssam 		goto gottype;
4986027Ssam 		}
4996027Ssam #endif
5006027Ssam 
5015083Swnj 	default:
5025083Swnj 		printf("en%d: can't encapsulate pf%d\n", ifp->if_unit, pf);
5035083Swnj 		m_freem(m0);
5045083Swnj 		return (0);
5054686Swnj 	}
5065105Swnj 
5075171Swnj gottrailertype:
5085105Swnj 	/*
5095105Swnj 	 * Packet to be sent as trailer: move first packet
5105105Swnj 	 * (control information) to end of chain.
5115105Swnj 	 */
5125105Swnj 	while (m->m_next)
5135105Swnj 		m = m->m_next;
5145105Swnj 	m->m_next = m0;
5155105Swnj 	m = m0->m_next;
5165105Swnj 	m0->m_next = 0;
5175171Swnj 	m0 = m;
5185105Swnj 
5195171Swnj gottype:
5205105Swnj 	/*
5215105Swnj 	 * Add local net header.  If no space in first mbuf,
5225105Swnj 	 * allocate another.
5235105Swnj 	 */
5245213Swnj 	if (m->m_off > MMAXOFF ||
5255213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5265584Sroot 		m = m_get(M_DONTWAIT);
5275083Swnj 		if (m == 0) {
5285083Swnj 			m_freem(m0);
5295083Swnj 			return (0);
5305083Swnj 		}
5315083Swnj 		m->m_next = m0;
5325083Swnj 		m->m_off = MMINOFF;
5335083Swnj 		m->m_len = sizeof (struct en_header);
5345083Swnj 	} else {
5355083Swnj 		m->m_off -= sizeof (struct en_header);
5365083Swnj 		m->m_len += sizeof (struct en_header);
5375083Swnj 	}
5385083Swnj 	en = mtod(m, struct en_header *);
5395083Swnj 	en->en_shost = ifp->if_host[0];
5405083Swnj 	en->en_dhost = dest;
5415083Swnj 	en->en_type = type;
5425105Swnj 
5435105Swnj 	/*
5445105Swnj 	 * Queue message on interface, and start output if interface
5455105Swnj 	 * not yet active.
5465105Swnj 	 */
5475083Swnj 	s = splimp();
5486207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5496207Swnj 		IF_DROP(&ifp->if_snd);
5506207Swnj 		m_freem(m);
5516207Swnj 		splx(s);
5526207Swnj 		return (0);
5536207Swnj 	}
5545083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5555083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5565083Swnj 		enstart(ifp->if_unit);
5575275Swnj 	splx(s);
5585105Swnj 	return (1);
5594686Swnj }
560