xref: /csrg-svn/sys/vax/if/if_en.c (revision 6335)
1*6335Ssam /*	if_en.c	4.44	82/03/28	*/
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];
97*6335Ssam 	register struct sockaddr_in *sin;
985105Swnj COUNT(ENATTACH);
994688Swnj 
1005105Swnj 	es->es_if.if_unit = ui->ui_unit;
1015171Swnj 	es->es_if.if_name = "en";
1025105Swnj 	es->es_if.if_mtu = ENMTU;
1035105Swnj 	es->es_if.if_net = ui->ui_flags;
1045105Swnj 	es->es_if.if_host[0] =
105*6335Ssam 	 (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
106*6335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_addr;
107*6335Ssam 	sin->sin_family = AF_INET;
108*6335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
109*6335Ssam 	sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
110*6335Ssam 	sin->sin_family = AF_INET;
111*6335Ssam 	sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
112*6335Ssam 	es->es_if.if_flags = IFF_BROADCAST;
1135171Swnj 	es->es_if.if_init = eninit;
1145105Swnj 	es->es_if.if_output = enoutput;
1155105Swnj 	es->es_if.if_ubareset = enreset;
1165696Sroot 	es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16;
1175160Swnj 	if_attach(&es->es_if);
1184686Swnj }
1194686Swnj 
1205105Swnj /*
1215105Swnj  * Reset of interface after UNIBUS reset.
1225105Swnj  * If interface is on specified uba, reset its state.
1235105Swnj  */
1245105Swnj enreset(unit, uban)
1255105Swnj 	int unit, uban;
1265105Swnj {
1275105Swnj 	register struct uba_device *ui;
1285105Swnj COUNT(ENRESET);
1295105Swnj 
1305171Swnj 	if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
1315171Swnj 	    ui->ui_ubanum != uban)
1325105Swnj 		return;
1335171Swnj 	printf(" en%d", unit);
1345105Swnj 	eninit(unit);
1355105Swnj }
1365105Swnj 
1375105Swnj /*
1385105Swnj  * Initialization of interface; clear recorded pending
1395105Swnj  * operations, and reinitialize UNIBUS usage.
1405105Swnj  */
1414688Swnj eninit(unit)
1424686Swnj 	int unit;
1435083Swnj {
1445171Swnj 	register struct en_softc *es = &en_softc[unit];
1455171Swnj 	register struct uba_device *ui = eninfo[unit];
1464686Swnj 	register struct endevice *addr;
1475105Swnj 	int s;
1484686Swnj 
1495105Swnj 	if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
1505708Sroot 	    sizeof (struct en_header), (int)btoc(ENMTU)) == 0) {
1515171Swnj 		printf("en%d: can't initialize\n", unit);
152*6335Ssam 		es->es_if.if_flags &= ~IFF_UP;
1535083Swnj 		return;
1544686Swnj 	}
1554686Swnj 	addr = (struct endevice *)ui->ui_addr;
1565083Swnj 	addr->en_istat = addr->en_ostat = 0;
1574686Swnj 
1585105Swnj 	/*
1595171Swnj 	 * Hang a receive and start any
1605171Swnj 	 * pending writes by faking a transmit complete.
1615105Swnj 	 */
1625105Swnj 	s = splimp();
1635171Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
1645171Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
1655171Swnj 	addr->en_istat = EN_IEN|EN_GO;
1665171Swnj 	es->es_oactive = 1;
167*6335Ssam 	es->es_if.if_flags |= IFF_UP;
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 	 */
225*6335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
226*6335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
2274686Swnj 	addr = (struct endevice *)ui->ui_addr;
2285160Swnj 	addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
2295083Swnj 	addr->en_odelay = es->es_delay;
2305083Swnj 	addr->en_owc = -((es->es_olen + 1) >> 1);
2314771Swnj 	addr->en_ostat = EN_IEN|EN_GO;
2325083Swnj 	es->es_oactive = 1;
2334686Swnj }
2344686Swnj 
2355105Swnj /*
2365105Swnj  * Ethernet interface transmitter interrupt.
2375105Swnj  * Start another output if more data to send.
2385105Swnj  */
2394686Swnj enxint(unit)
2404686Swnj 	int unit;
2414686Swnj {
2425171Swnj 	register struct uba_device *ui = eninfo[unit];
2435171Swnj 	register struct en_softc *es = &en_softc[unit];
2446242Sroot 	register struct endevice *addr = (struct endevice *)ui->ui_addr;
2454686Swnj COUNT(ENXINT);
2464686Swnj 
2475083Swnj 	if (es->es_oactive == 0)
2485083Swnj 		return;
2496242Sroot 	if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
2506242Sroot 		es->es_if.if_oerrors++;
2516242Sroot 		if (es->es_if.if_oerrors % 100 == 0)
2526242Sroot 			printf("en%d: += 100 output errors\n", unit);
2536242Sroot 		endocoll(unit);
2546242Sroot 		return;
2556242Sroot 	}
2565171Swnj 	es->es_if.if_opackets++;
2575083Swnj 	es->es_oactive = 0;
2585083Swnj 	es->es_delay = 0;
2595083Swnj 	es->es_mask = ~0;
2605696Sroot 	if (es->es_ifuba.ifu_xtofree) {
2615696Sroot 		m_freem(es->es_ifuba.ifu_xtofree);
2625696Sroot 		es->es_ifuba.ifu_xtofree = 0;
2635696Sroot 	}
2645105Swnj 	if (es->es_if.if_snd.ifq_head == 0) {
2655083Swnj 		es->es_lastx = 0;
2664686Swnj 		return;
2674686Swnj 	}
2685083Swnj 	enstart(unit);
2694686Swnj }
2704686Swnj 
2715105Swnj /*
2725105Swnj  * Collision on ethernet interface.  Do exponential
2735105Swnj  * backoff, and retransmit.  If have backed off all
274*6335Ssam  * the way print warning diagnostic, and drop packet.
2755105Swnj  */
2764686Swnj encollide(unit)
2774686Swnj 	int unit;
2784686Swnj {
2796242Sroot 	struct en_softc *es = &en_softc[unit];
2804686Swnj COUNT(ENCOLLIDE);
2814686Swnj 
2825105Swnj 	es->es_if.if_collisions++;
2835083Swnj 	if (es->es_oactive == 0)
2844686Swnj 		return;
2856242Sroot 	endocoll(unit);
2866242Sroot }
2876242Sroot 
2886242Sroot endocoll(unit)
2896242Sroot 	int unit;
2906242Sroot {
2916242Sroot 	register struct en_softc *es = &en_softc[unit];
2926242Sroot 
2935171Swnj 	/*
2945171Swnj 	 * Es_mask is a 16 bit number with n low zero bits, with
2955171Swnj 	 * n the number of backoffs.  When es_mask is 0 we have
2965171Swnj 	 * backed off 16 times, and give up.
2975171Swnj 	 */
2985083Swnj 	if (es->es_mask == 0) {
2995213Swnj 		printf("en%d: send error\n", unit);
3005083Swnj 		enxint(unit);
3015171Swnj 		return;
3024686Swnj 	}
3035171Swnj 	/*
3045171Swnj 	 * Another backoff.  Restart with delay based on n low bits
3055171Swnj 	 * of the interval timer.
3065171Swnj 	 */
3075171Swnj 	es->es_mask <<= 1;
3085171Swnj 	es->es_delay = mfpr(ICR) &~ es->es_mask;
3095171Swnj 	enstart(unit);
3104686Swnj }
3114686Swnj 
3126027Ssam struct	sockaddr_pup pupsrc = { AF_PUP };
3136027Ssam struct	sockaddr_pup pupdst = { AF_PUP };
3146027Ssam struct	sockproto pupproto = { PF_PUP };
3155105Swnj /*
3165105Swnj  * Ethernet interface receiver interrupt.
3175105Swnj  * If input error just drop packet.
3185105Swnj  * Otherwise purge input buffered data path and examine
3195105Swnj  * packet to determine type.  If can't determine length
3205105Swnj  * from type, then have to drop packet.  Othewise decapsulate
3215105Swnj  * packet based on type and pass to type specific higher-level
3225105Swnj  * input routine.
3235105Swnj  */
3244686Swnj enrint(unit)
3254686Swnj 	int unit;
3264686Swnj {
3275171Swnj 	register struct en_softc *es = &en_softc[unit];
3285171Swnj 	struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
3295171Swnj 	register struct en_header *en;
3305083Swnj     	struct mbuf *m;
3315171Swnj 	int len;
3325171Swnj 	register struct ifqueue *inq;
3335083Swnj 	int off;
3344686Swnj COUNT(ENRINT);
3354686Swnj 
3365171Swnj 	es->es_if.if_ipackets++;
3375105Swnj 
3385105Swnj 	/*
3395171Swnj 	 * Purge BDP; drop if input error indicated.
3405105Swnj 	 */
341*6335Ssam 	if (es->es_ifuba.ifu_flags & UBA_NEEDBDP)
342*6335Ssam 		UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
3434771Swnj 	if (addr->en_istat&EN_IERROR) {
3445105Swnj 		es->es_if.if_ierrors++;
3456238Sroot 		if (es->es_if.if_ierrors % 100 == 0)
3466238Sroot 			printf("en%d: += 100 input errors\n", unit);
3475083Swnj 		goto setup;
3484686Swnj 	}
3495105Swnj 
3505105Swnj 	/*
3515105Swnj 	 * Get pointer to ethernet header (in input buffer).
3525105Swnj 	 * Deal with trailer protocol: if type is PUP trailer
3535105Swnj 	 * get true type from first 16-bit word past data.
3545105Swnj 	 * Remember that type was trailer by setting off.
3555105Swnj 	 */
3565105Swnj 	en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
3575083Swnj #define	endataaddr(en, off, type)	((type)(((caddr_t)((en)+1)+(off))))
3585083Swnj 	if (en->en_type >= ENPUP_TRAIL &&
3595083Swnj 	    en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
3605083Swnj 		off = (en->en_type - ENPUP_TRAIL) * 512;
3615171Swnj 		if (off >= ENMTU)
3625171Swnj 			goto setup;		/* sanity */
3635083Swnj 		en->en_type = *endataaddr(en, off, u_short *);
3645083Swnj 	} else
3655083Swnj 		off = 0;
3665105Swnj 
3675105Swnj 	/*
3685105Swnj 	 * Attempt to infer packet length from type;
3695105Swnj 	 * can't deal with packet if can't infer length.
3705105Swnj 	 */
3715083Swnj 	switch (en->en_type) {
3725083Swnj 
3735083Swnj #ifdef INET
3745083Swnj 	case ENPUP_IPTYPE:
375*6335Ssam 		len = htons((u_short)endataaddr(en,
376*6335Ssam 			off ? off + sizeof (u_short) : 0, struct ip *)->ip_len);
3775239Sroot 		if (off)
378*6335Ssam 			len += sizeof (u_short);
3794686Swnj 		break;
3804686Swnj #endif
3816027Ssam #ifdef PUP
3826027Ssam 	case ENPUP_PUPTYPE:
383*6335Ssam 		len = endataaddr(en, off ? off + sizeof (u_short) : 0,
384*6335Ssam 			struct pup_header *)->pup_length;
3856027Ssam 		if (off)
386*6335Ssam 			len -= sizeof (u_short);
3876027Ssam 		break;
3886027Ssam #endif
3896027Ssam 
3905083Swnj 	default:
3916026Sroot 		printf("en%d: unknown pkt type 0x%x\n", unit, en->en_type);
3925083Swnj 		goto setup;
3934686Swnj 	}
3945083Swnj 	if (len == 0)
3955083Swnj 		goto setup;
3965105Swnj 
3975105Swnj 	/*
3985105Swnj 	 * Pull packet off interface.  Off is nonzero if packet
3995105Swnj 	 * has trailing header; if_rubaget will then force this header
4005105Swnj 	 * information to be at the front, but we still have to drop
4015171Swnj 	 * the two-byte type which is at the front of any trailer data.
4025105Swnj 	 */
4035105Swnj 	m = if_rubaget(&es->es_ifuba, len, off);
4045213Swnj 	if (m == 0)
4055213Swnj 		goto setup;
4065105Swnj 	if (off) {
407*6335Ssam 		m->m_off += sizeof (u_short);
408*6335Ssam 		m->m_len -= sizeof (u_short);
4095105Swnj 	}
4106027Ssam 	switch (en->en_type) {
4116027Ssam 
4126027Ssam #ifdef INET
4136027Ssam 	case ENPUP_IPTYPE:
4146260Swnj 		schednetisr(NETISR_IP);
4156027Ssam 		inq = &ipintrq;
4166027Ssam 		break;
4176027Ssam #endif
418*6335Ssam #ifdef PUP
4196027Ssam 	case ENPUP_PUPTYPE: {
4206027Ssam 		struct pup_header *pup = mtod(m, struct pup_header *);
4216027Ssam 
4226027Ssam 		pupproto.sp_protocol = pup->pup_type;
4236027Ssam 		pupdst.spup_addr = pup->pup_dport;
4246027Ssam 		pupsrc.spup_addr = pup->pup_sport;
4256159Ssam 		raw_input(m, &pupproto, (struct sockaddr *)&pupdst,
426*6335Ssam 		  (struct sockaddr *)&pupsrc);
4276027Ssam 		goto setup;
4286027Ssam 	}
429*6335Ssam #endif
430*6335Ssam 	}
431*6335Ssam 
4326207Swnj 	if (IF_QFULL(inq)) {
4336207Swnj 		IF_DROP(inq);
434*6335Ssam 		m_freem(m);
4356207Swnj 	} else
4366207Swnj 		IF_ENQUEUE(inq, m);
4375105Swnj 
4384688Swnj setup:
4395105Swnj 	/*
4405105Swnj 	 * Reset for next packet.
4415105Swnj 	 */
4425105Swnj 	addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
4435083Swnj 	addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
4444771Swnj 	addr->en_istat = EN_IEN|EN_GO;
4454688Swnj }
4464686Swnj 
4475083Swnj /*
4485083Swnj  * Ethernet output routine.
4495083Swnj  * Encapsulate a packet of type family for the local net.
4505105Swnj  * Use trailer local net encapsulation if enough data in first
4515105Swnj  * packet leaves a multiple of 512 bytes of data in remainder.
4525083Swnj  */
453*6335Ssam enoutput(ifp, m0, dst)
4545083Swnj 	struct ifnet *ifp;
4555083Swnj 	struct mbuf *m0;
456*6335Ssam 	struct sockaddr *dst;
4574686Swnj {
458*6335Ssam 	int type, dest, s;
4595105Swnj 	register struct mbuf *m = m0;
4605083Swnj 	register struct en_header *en;
461*6335Ssam 	register int off;
4624686Swnj 
4635927Sroot COUNT(ENOUTPUT);
464*6335Ssam 	switch (dst->sa_family) {
4655083Swnj 
4665083Swnj #ifdef INET
467*6335Ssam 	case AF_INET:
468*6335Ssam 		dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr >> 24;
469*6335Ssam 		off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
470*6335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
471*6335Ssam 		    m->m_off >= MMINOFF + sizeof (u_short)) {
4725083Swnj 			type = ENPUP_TRAIL + (off>>9);
473*6335Ssam 			m->m_off -= sizeof (u_short);
474*6335Ssam 			m->m_len += sizeof (u_short);
4755105Swnj 			*mtod(m, u_short *) = ENPUP_IPTYPE;
4765105Swnj 			goto gottrailertype;
4775083Swnj 		}
4785105Swnj 		type = ENPUP_IPTYPE;
4795105Swnj 		off = 0;
4805105Swnj 		goto gottype;
4815083Swnj #endif
4826027Ssam #ifdef PUP
483*6335Ssam 	case AF_PUP:
484*6335Ssam 		dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host;
485*6335Ssam 		off = mtod(m, struct pup_header *)->pup_length - m->m_len;
486*6335Ssam 		if (off > 0 && (off & 0x1ff) == 0 &&
487*6335Ssam 		    m->m_off >= MMINOFF + sizeof (u_short)) {
4886027Ssam 			type = ENPUP_TRAIL + (off>>9);
489*6335Ssam 			m->m_off -= sizeof (u_short);
490*6335Ssam 			m->m_len += sizeof (u_short);
4916027Ssam 			*mtod(m, u_short *) = ENPUP_PUPTYPE;
4926027Ssam 			goto gottrailertype;
4936027Ssam 		}
4946027Ssam 		type = ENPUP_PUPTYPE;
4956027Ssam 		off = 0;
4966027Ssam 		goto gottype;
4976027Ssam #endif
4986027Ssam 
4995083Swnj 	default:
500*6335Ssam 		printf("en%d: can't handle af%d\n", ifp->if_unit,
501*6335Ssam 			dst->sa_family);
5025083Swnj 		m_freem(m0);
5035083Swnj 		return (0);
5044686Swnj 	}
5055105Swnj 
5065171Swnj gottrailertype:
5075105Swnj 	/*
5085105Swnj 	 * Packet to be sent as trailer: move first packet
5095105Swnj 	 * (control information) to end of chain.
5105105Swnj 	 */
5115105Swnj 	while (m->m_next)
5125105Swnj 		m = m->m_next;
5135105Swnj 	m->m_next = m0;
5145105Swnj 	m = m0->m_next;
5155105Swnj 	m0->m_next = 0;
5165171Swnj 	m0 = m;
5175105Swnj 
5185171Swnj gottype:
5195105Swnj 	/*
5205105Swnj 	 * Add local net header.  If no space in first mbuf,
5215105Swnj 	 * allocate another.
5225105Swnj 	 */
5235213Swnj 	if (m->m_off > MMAXOFF ||
5245213Swnj 	    MMINOFF + sizeof (struct en_header) > m->m_off) {
5255584Sroot 		m = m_get(M_DONTWAIT);
5265083Swnj 		if (m == 0) {
5275083Swnj 			m_freem(m0);
5285083Swnj 			return (0);
5295083Swnj 		}
5305083Swnj 		m->m_next = m0;
5315083Swnj 		m->m_off = MMINOFF;
5325083Swnj 		m->m_len = sizeof (struct en_header);
5335083Swnj 	} else {
5345083Swnj 		m->m_off -= sizeof (struct en_header);
5355083Swnj 		m->m_len += sizeof (struct en_header);
5365083Swnj 	}
5375083Swnj 	en = mtod(m, struct en_header *);
5385083Swnj 	en->en_shost = ifp->if_host[0];
5395083Swnj 	en->en_dhost = dest;
5405083Swnj 	en->en_type = type;
5415105Swnj 
5425105Swnj 	/*
5435105Swnj 	 * Queue message on interface, and start output if interface
5445105Swnj 	 * not yet active.
5455105Swnj 	 */
5465083Swnj 	s = splimp();
5476207Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5486207Swnj 		IF_DROP(&ifp->if_snd);
5496207Swnj 		m_freem(m);
5506207Swnj 		splx(s);
5516207Swnj 		return (0);
5526207Swnj 	}
5535083Swnj 	IF_ENQUEUE(&ifp->if_snd, m);
5545083Swnj 	if (en_softc[ifp->if_unit].es_oactive == 0)
5555083Swnj 		enstart(ifp->if_unit);
5565275Swnj 	splx(s);
5575105Swnj 	return (1);
5584686Swnj }
559