xref: /csrg-svn/sys/vax/if/if_en.c (revision 6364)
1*6364Ssam /*	if_en.c	4.45	82/03/30	*/
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"
30*6364Ssam #include "../net/route.h"
314686Swnj 
325213Swnj #define	ENMTU	(1024+512)
335083Swnj 
344686Swnj int	enprobe(), enattach(), enrint(), enxint(), encollide();
354686Swnj struct	uba_device *eninfo[NEN];
364686Swnj u_short enstd[] = { 0 };
374686Swnj struct	uba_driver endriver =
385171Swnj 	{ enprobe, 0, enattach, 0, enstd, "en", eninfo };
394686Swnj #define	ENUNIT(x)	minor(x)
404686Swnj 
415105Swnj int	eninit(),enoutput(),enreset();
425105Swnj 
435105Swnj /*
445105Swnj  * Ethernet software status per interface.
455105Swnj  *
465105Swnj  * Each interface is referenced by a network interface structure,
475105Swnj  * es_if, which the routing code uses to locate the interface.
485105Swnj  * This structure contains the output queue for the interface, its address, ...
495105Swnj  * We also have, for each interface, a UBA interface structure, which
505105Swnj  * contains information about the UNIBUS resources held by the interface:
515105Swnj  * map registers, buffered data paths, etc.  Information is cached in this
525105Swnj  * structure for use by the if_uba.c routines in running the interface
535105Swnj  * efficiently.
545105Swnj  */
555083Swnj struct	en_softc {
565105Swnj 	struct	ifnet es_if;		/* network-visible interface */
575105Swnj 	struct	ifuba es_ifuba;		/* UNIBUS resources */
585105Swnj 	short	es_delay;		/* current output delay */
595105Swnj 	short	es_mask;		/* mask for current output delay */
605105Swnj 	u_char	es_lastx;		/* host last transmitted to */
615105Swnj 	short	es_oactive;		/* is output active? */
625105Swnj 	short	es_olen;		/* length of last output */
635083Swnj } en_softc[NEN];
644686Swnj 
655105Swnj /*
665105Swnj  * Do output DMA to determine interface presence and
675105Swnj  * interrupt vector.  DMA is too short to disturb other hosts.
685105Swnj  */
694686Swnj enprobe(reg)
704686Swnj 	caddr_t reg;
714686Swnj {
725171Swnj 	register int br, cvec;		/* r11, r10 value-result */
734686Swnj 	register struct endevice *addr = (struct endevice *)reg;
744686Swnj 
755083Swnj COUNT(ENPROBE);
764686Swnj #ifdef lint
774686Swnj 	br = 0; cvec = br; br = cvec;
784922Swnj 	enrint(0); enxint(0); encollide(0);
794686Swnj #endif
804686Swnj 	addr->en_istat = 0;
814686Swnj 	addr->en_owc = -1;
824686Swnj 	addr->en_oba = 0;
834771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
844686Swnj 	DELAY(100000);
854686Swnj 	addr->en_ostat = 0;
864686Swnj 	return (1);
874686Swnj }
884686Swnj 
895105Swnj /*
905105Swnj  * Interface exists: make available by filling in network interface
915105Swnj  * record.  System will initialize the interface when it is ready
925105Swnj  * to accept packets.
935105Swnj  */
944686Swnj enattach(ui)
954686Swnj 	struct uba_device *ui;
964686Swnj {
975105Swnj 	register struct en_softc *es = &en_softc[ui->ui_unit];
986335Ssam 	register struct sockaddr_in *sin;
995105Swnj COUNT(ENATTACH);
1004688Swnj 
1015105Swnj 	es->es_if.if_unit = ui->ui_unit;
1025171Swnj 	es->es_if.if_name = "en";
1035105Swnj 	es->es_if.if_mtu = ENMTU;
1045105Swnj 	es->es_if.if_net = ui->ui_flags;
1055105Swnj 	es->es_if.if_host[0] =
1066335Ssam 	 (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
1076335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_addr;
1086335Ssam 	sin->sin_family = AF_INET;
1096335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
1106335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
1116335Ssam 	sin->sin_family = AF_INET;
1126335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
1136335Ssam 	es->es_if.if_flags = IFF_BROADCAST;
1145171Swnj 	es->es_if.if_init = eninit;
1155105Swnj 	es->es_if.if_output = enoutput;
1165105Swnj 	es->es_if.if_ubareset = enreset;
1175696Sroot 	es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16;
1185160Swnj 	if_attach(&es->es_if);
1194686Swnj }
1204686Swnj 
1215105Swnj /*
1225105Swnj  * Reset of interface after UNIBUS reset.
1235105Swnj  * If interface is on specified uba, reset its state.
1245105Swnj  */
1255105Swnj enreset(unit, uban)
1265105Swnj 	int unit, uban;
1275105Swnj {
1285105Swnj 	register struct uba_device *ui;
1295105Swnj COUNT(ENRESET);
1305105Swnj 
1315171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1325171Swnj 	    ui->ui_ubanum != uban)
1335105Swnj 		return;
1345171Swnj 	printf(" en%d", unit);
1355105Swnj 	eninit(unit);
1365105Swnj }
1375105Swnj 
1385105Swnj /*
1395105Swnj  * Initialization of interface; clear recorded pending
1405105Swnj  * operations, and reinitialize UNIBUS usage.
1415105Swnj  */
1424688Swnj eninit(unit)
1434686Swnj 	int unit;
1445083Swnj {
1455171Swnj 	register struct en_softc *es = &en_softc[unit];
1465171Swnj 	register struct uba_device *ui = eninfo[unit];
1474686Swnj 	register struct endevice *addr;
1485105Swnj 	int s;
1494686Swnj 
1505105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1515708Sroot 	    sizeof (struct en_header), (int)btoc(ENMTU)) == 0) {
1525171Swnj 		printf("en%d: can't initialize\n", unit);
1536335Ssam 		es->es_if.if_flags &= ~IFF_UP;
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;
1686335Ssam 	es->es_if.if_flags |= IFF_UP;
1695105Swnj 	enxint(unit);
1705105Swnj 	splx(s);
171*6364Ssam 	if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP);
1724686Swnj }
1734686Swnj 
1744717Swnj int	enlastdel = 25;
1755083Swnj 
1765105Swnj /*
1775105Swnj  * Start or restart output on interface.
1785105Swnj  * If interface is already active, then this is a retransmit
1795105Swnj  * after a collision, and just restuff registers and delay.
1805105Swnj  * If interface is not already active, get another datagram
1815105Swnj  * to send off of the interface queue, and map it to the interface
1825105Swnj  * before starting the output.
1835105Swnj  */
1844688Swnj enstart(dev)
1854686Swnj 	dev_t dev;
1864686Swnj {
1875171Swnj         int unit = ENUNIT(dev);
1885171Swnj 	struct uba_device *ui = eninfo[unit];
1895171Swnj 	register struct en_softc *es = &en_softc[unit];
1905083Swnj 	register struct endevice *addr;
1915083Swnj 	struct mbuf *m;
1925083Swnj 	int dest;
1934688Swnj COUNT(ENSTART);
1944686Swnj 
1955083Swnj 	if (es->es_oactive)
1965083Swnj 		goto restart;
1975105Swnj 
1985105Swnj 	/*
1995105Swnj 	 * Not already active: dequeue another request
2005105Swnj 	 * and map it to the UNIBUS.  If no more requests,
2015105Swnj 	 * just return.
2025105Swnj 	 */
2035105Swnj 	IF_DEQUEUE(&es->es_if.if_snd, m);
2045083Swnj 	if (m == 0) {
2055083Swnj 		es->es_oactive = 0;
2064686Swnj 		return;
2074686Swnj 	}
2085213Swnj 	dest = mtod(m, struct en_header *)->en_dhost;
2095105Swnj 	es->es_olen = if_wubaput(&es->es_ifuba, m);
2105105Swnj 
2115105Swnj 	/*
2125105Swnj 	 * Ethernet cannot take back-to-back packets (no
2135105Swnj 	 * buffering in interface.  To avoid overrunning
2145105Swnj 	 * receiver, enforce a small delay (about 1ms) in interface
2155105Swnj 	 * on successive packets sent to same host.
2165105Swnj 	 */
2175083Swnj 	if (es->es_lastx && es->es_lastx == dest)
2185083Swnj 		es->es_delay = enlastdel;
2195083Swnj 	else
2205083Swnj 		es->es_lastx = dest;
2215105Swnj 
2225083Swnj restart:
2235105Swnj 	/*
2245105Swnj 	 * Have request mapped to UNIBUS for transmission.
2255105Swnj 	 * Purge any stale data from this BDP, and start the otput.
2265105Swnj 	 */
2276335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
2286335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2294686Swnj 	addr = (struct endevice *)ui->ui_addr;
2305160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2315083Swnj 	addr->en_odelay = es->es_delay;
2325083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2334771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2345083Swnj 	es->es_oactive = 1;
2354686Swnj }
2364686Swnj 
2375105Swnj /*
2385105Swnj  * Ethernet interface transmitter interrupt.
2395105Swnj  * Start another output if more data to send.
2405105Swnj  */
2414686Swnj enxint(unit)
2424686Swnj 	int unit;
2434686Swnj {
2445171Swnj 	register struct uba_device *ui = eninfo[unit];
2455171Swnj 	register struct en_softc *es = &en_softc[unit];
2466242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2474686Swnj COUNT(ENXINT);
2484686Swnj 
2495083Swnj 	if (es->es_oactive == 0)
2505083Swnj 		return;
2516242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
2526242Sroot 		es->es_if.if_oerrors++;
2536242Sroot 		if (es->es_if.if_oerrors % 100 == 0)
2546242Sroot 			printf("en%d: += 100 output errors\n", unit);
2556242Sroot 		endocoll(unit);
2566242Sroot 		return;
2576242Sroot 	}
2585171Swnj 	es->es_if.if_opackets++;
2595083Swnj 	es->es_oactive = 0;
2605083Swnj 	es->es_delay = 0;
2615083Swnj 	es->es_mask = ~0;
2625696Sroot 	if (es->es_ifuba.ifu_xtofree) {
2635696Sroot 		m_freem(es->es_ifuba.ifu_xtofree);
2645696Sroot 		es->es_ifuba.ifu_xtofree = 0;
2655696Sroot 	}
2665105Swnj 	if (es->es_if.if_snd.ifq_head == 0) {
2675083Swnj 		es->es_lastx = 0;
2684686Swnj 		return;
2694686Swnj 	}
2705083Swnj 	enstart(unit);
2714686Swnj }
2724686Swnj 
2735105Swnj /*
2745105Swnj  * Collision on ethernet interface.  Do exponential
2755105Swnj  * backoff, and retransmit.  If have backed off all
2766335Ssam  * the way print warning diagnostic, and drop packet.
2775105Swnj  */
2784686Swnj encollide(unit)
2794686Swnj 	int unit;
2804686Swnj {
2816242Sroot 	struct en_softc *es = &en_softc[unit];
2824686Swnj COUNT(ENCOLLIDE);
2834686Swnj 
2845105Swnj 	es->es_if.if_collisions++;
2855083Swnj 	if (es->es_oactive == 0)
2864686Swnj 		return;
2876242Sroot 	endocoll(unit);
2886242Sroot }
2896242Sroot 
2906242Sroot endocoll(unit)
2916242Sroot 	int unit;
2926242Sroot {
2936242Sroot 	register struct en_softc *es = &en_softc[unit];
2946242Sroot 
2955171Swnj 	/*
2965171Swnj 	 * Es_mask is a 16 bit number with n low zero bits, with
2975171Swnj 	 * n the number of backoffs.  When es_mask is 0 we have
2985171Swnj 	 * backed off 16 times, and give up.
2995171Swnj 	 */
3005083Swnj 	if (es->es_mask == 0) {
3015213Swnj 		printf("en%d: send error\n", unit);
3025083Swnj 		enxint(unit);
3035171Swnj 		return;
3044686Swnj 	}
3055171Swnj 	/*
3065171Swnj 	 * Another backoff.  Restart with delay based on n low bits
3075171Swnj 	 * of the interval timer.
3085171Swnj 	 */
3095171Swnj 	es->es_mask <<= 1;
3105171Swnj 	es->es_delay = mfpr(ICR) &~ es->es_mask;
3115171Swnj 	enstart(unit);
3124686Swnj }
3134686Swnj 
3146027Ssam struct	sockaddr_pup pupsrc = { AF_PUP };
3156027Ssam struct	sockaddr_pup pupdst = { AF_PUP };
3166027Ssam struct	sockproto pupproto = { PF_PUP };
3175105Swnj /*
3185105Swnj  * Ethernet interface receiver interrupt.
3195105Swnj  * If input error just drop packet.
3205105Swnj  * Otherwise purge input buffered data path and examine
3215105Swnj  * packet to determine type.  If can't determine length
3225105Swnj  * from type, then have to drop packet.  Othewise decapsulate
3235105Swnj  * packet based on type and pass to type specific higher-level
3245105Swnj  * input routine.
3255105Swnj  */
3264686Swnj enrint(unit)
3274686Swnj 	int unit;
3284686Swnj {
3295171Swnj 	register struct en_softc *es = &en_softc[unit];
3305171Swnj 	struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
3315171Swnj 	register struct en_header *en;
3325083Swnj     	struct mbuf *m;
3335171Swnj 	int len;
3345171Swnj 	register struct ifqueue *inq;
3355083Swnj 	int off;
3364686Swnj COUNT(ENRINT);
3374686Swnj 
3385171Swnj 	es->es_if.if_ipackets++;
3395105Swnj 
3405105Swnj 	/*
3415171Swnj 	 * Purge BDP; drop if input error indicated.
3425105Swnj 	 */
3436335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
3446335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3454771Swnj 	if (addr->en_istat&EN_IERROR) {
3465105Swnj 		es->es_if.if_ierrors++;
3476238Sroot 		if (es->es_if.if_ierrors % 100 == 0)
3486238Sroot 			printf("en%d: += 100 input errors\n", unit);
3495083Swnj 		goto setup;
3504686Swnj 	}
3515105Swnj 
3525105Swnj 	/*
3535105Swnj 	 * Get pointer to ethernet header (in input buffer).
3545105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3555105Swnj 	 * get true type from first 16-bit word past data.
3565105Swnj 	 * Remember that type was trailer by setting off.
3575105Swnj 	 */
3585105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3595083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3605083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3615083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3625083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3635171Swnj 		if (off >= ENMTU)
3645171Swnj 			goto setup;		/* sanity */
3655083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3665083Swnj 	} else
3675083Swnj 		off = 0;
3685105Swnj 
3695105Swnj 	/*
3705105Swnj 	 * Attempt to infer packet length from type;
3715105Swnj 	 * can't deal with packet if can't infer length.
3725105Swnj 	 */
3735083Swnj 	switch (en->en_type) {
3745083Swnj 
3755083Swnj #ifdef INET
3765083Swnj 	case ENPUP_IPTYPE:
3776335Ssam 		len = htons((u_short)endataaddr(en,
3786335Ssam 			off ? off + sizeof (u_short) : 0, struct ip *)->ip_len);
3795239Sroot 		if (off)
3806335Ssam 			len += sizeof (u_short);
3814686Swnj 		break;
3824686Swnj #endif
3836027Ssam #ifdef PUP
3846027Ssam 	case ENPUP_PUPTYPE:
3856335Ssam 		len = endataaddr(en, off ? off + sizeof (u_short) : 0,
3866335Ssam 			struct pup_header *)->pup_length;
3876027Ssam 		if (off)
3886335Ssam 			len -= sizeof (u_short);
3896027Ssam 		break;
3906027Ssam #endif
3916027Ssam 
3925083Swnj 	default:
3936026Sroot 		printf("en%d: unknown pkt type 0x%x\n", unit, en->en_type);
3945083Swnj 		goto setup;
3954686Swnj 	}
3965083Swnj 	if (len == 0)
3975083Swnj 		goto setup;
3985105Swnj 
3995105Swnj 	/*
4005105Swnj 	 * Pull packet off interface.  Off is nonzero if packet
4015105Swnj 	 * has trailing header; if_rubaget will then force this header
4025105Swnj 	 * information to be at the front, but we still have to drop
4035171Swnj 	 * the two-byte type which is at the front of any trailer data.
4045105Swnj 	 */
4055105Swnj 	m = if_rubaget(&es->es_ifuba, len, off);
4065213Swnj 	if (m == 0)
4075213Swnj 		goto setup;
4085105Swnj 	if (off) {
4096335Ssam 		m->m_off += sizeof (u_short);
4106335Ssam 		m->m_len -= sizeof (u_short);
4115105Swnj 	}
4126027Ssam 	switch (en->en_type) {
4136027Ssam 
4146027Ssam #ifdef INET
4156027Ssam 	case ENPUP_IPTYPE:
4166260Swnj 		schednetisr(NETISR_IP);
4176027Ssam 		inq = &ipintrq;
4186027Ssam 		break;
4196027Ssam #endif
4206335Ssam #ifdef PUP
4216027Ssam 	case ENPUP_PUPTYPE: {
4226027Ssam 		struct pup_header *pup = mtod(m, struct pup_header *);
4236027Ssam 
4246027Ssam 		pupproto.sp_protocol = pup->pup_type;
4256027Ssam 		pupdst.spup_addr = pup->pup_dport;
4266027Ssam 		pupsrc.spup_addr = pup->pup_sport;
4276159Ssam 		raw_input(m, &pupproto, (struct sockaddr *)&pupdst,
4286335Ssam 		  (struct sockaddr *)&pupsrc);
4296027Ssam 		goto setup;
4306027Ssam 	}
4316335Ssam #endif
4326335Ssam 	}
4336335Ssam 
4346207Swnj 	if (IF_QFULL(inq)) {
4356207Swnj 		IF_DROP(inq);
4366335Ssam 		m_freem(m);
4376207Swnj 	} else
4386207Swnj 		IF_ENQUEUE(inq, m);
4395105Swnj 
4404688Swnj setup:
4415105Swnj 	/*
4425105Swnj 	 * Reset for next packet.
4435105Swnj 	 */
4445105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4455083Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
4464771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4474688Swnj }
4484686Swnj 
4495083Swnj /*
4505083Swnj  * Ethernet output routine.
4515083Swnj  * Encapsulate a packet of type family for the local net.
4525105Swnj  * Use trailer local net encapsulation if enough data in first
4535105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4545083Swnj  */
4556335Ssam enoutput(ifp, m0, dst)
4565083Swnj 	struct ifnet *ifp;
4575083Swnj 	struct mbuf *m0;
4586335Ssam 	struct sockaddr *dst;
4594686Swnj {
4606335Ssam 	int type, dest, s;
4615105Swnj 	register struct mbuf *m = m0;
4625083Swnj 	register struct en_header *en;
4636335Ssam 	register int off;
4644686Swnj 
4655927Sroot COUNT(ENOUTPUT);
4666335Ssam 	switch (dst->sa_family) {
4675083Swnj 
4685083Swnj #ifdef INET
4696335Ssam 	case AF_INET:
4706335Ssam 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr >> 24;
4716335Ssam 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
4726335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
4736335Ssam 		    m->m_off >= MMINOFF + sizeof (u_short)) {
4745083Swnj 			type = ENPUP_TRAIL + (off>>9);
4756335Ssam 			m->m_off -= sizeof (u_short);
4766335Ssam 			m->m_len += sizeof (u_short);
4775105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
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;
4876335Ssam 		off = mtod(m, struct pup_header *)->pup_length - m->m_len;
4886335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
4896335Ssam 		    m->m_off >= MMINOFF + sizeof (u_short)) {
4906027Ssam 			type = ENPUP_TRAIL + (off>>9);
4916335Ssam 			m->m_off -= sizeof (u_short);
4926335Ssam 			m->m_len += sizeof (u_short);
4936027Ssam 			*mtod(m, u_short *) = ENPUP_PUPTYPE;
4946027Ssam 			goto gottrailertype;
4956027Ssam 		}
4966027Ssam 		type = ENPUP_PUPTYPE;
4976027Ssam 		off = 0;
4986027Ssam 		goto gottype;
4996027Ssam #endif
5006027Ssam 
5015083Swnj 	default:
5026335Ssam 		printf("en%d: can't handle af%d\n", ifp->if_unit,
5036335Ssam 			dst->sa_family);
5045083Swnj 		m_freem(m0);
5055083Swnj 		return (0);
5064686Swnj 	}
5075105Swnj 
5085171Swnj gottrailertype:
5095105Swnj 	/*
5105105Swnj 	 * Packet to be sent as trailer: move first packet
5115105Swnj 	 * (control information) to end of chain.
5125105Swnj 	 */
5135105Swnj 	while (m->m_next)
5145105Swnj 		m = m->m_next;
5155105Swnj 	m->m_next = m0;
5165105Swnj 	m = m0->m_next;
5175105Swnj 	m0->m_next = 0;
5185171Swnj 	m0 = m;
5195105Swnj 
5205171Swnj gottype:
5215105Swnj 	/*
5225105Swnj 	 * Add local net header.  If no space in first mbuf,
5235105Swnj 	 * allocate another.
5245105Swnj 	 */
5255213Swnj 	if (m->m_off > MMAXOFF ||
5265213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5275584Sroot 		m = m_get(M_DONTWAIT);
5285083Swnj 		if (m == 0) {
5295083Swnj 			m_freem(m0);
5305083Swnj 			return (0);
5315083Swnj 		}
5325083Swnj 		m->m_next = m0;
5335083Swnj 		m->m_off = MMINOFF;
5345083Swnj 		m->m_len = sizeof (struct en_header);
5355083Swnj 	} else {
5365083Swnj 		m->m_off -= sizeof (struct en_header);
5375083Swnj 		m->m_len += sizeof (struct en_header);
5385083Swnj 	}
5395083Swnj 	en = mtod(m, struct en_header *);
5405083Swnj 	en->en_shost = ifp->if_host[0];
5415083Swnj 	en->en_dhost = dest;
5425083Swnj 	en->en_type = type;
5435105Swnj 
5445105Swnj 	/*
5455105Swnj 	 * Queue message on interface, and start output if interface
5465105Swnj 	 * not yet active.
5475105Swnj 	 */
5485083Swnj 	s = splimp();
5496207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5506207Swnj 		IF_DROP(&ifp->if_snd);
5516207Swnj 		m_freem(m);
5526207Swnj 		splx(s);
5536207Swnj 		return (0);
5546207Swnj 	}
5555083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5565083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5575083Swnj 		enstart(ifp->if_unit);
5585275Swnj 	splx(s);
5595105Swnj 	return (1);
5604686Swnj }
561