1*6582Ssam /*	if_imp.c	4.26	82/04/24	*/
25640Sroot 
35640Sroot #include "imp.h"
45640Sroot #if NIMP > 0
55640Sroot /*
6*6582Ssam  * ARPANET IMP interface driver.
75640Sroot  *
85640Sroot  * The IMP-host protocol is handled here, leaving
95640Sroot  * hardware specifics to the lower level interface driver.
105640Sroot  */
115640Sroot #include "../h/param.h"
125640Sroot #include "../h/systm.h"
135640Sroot #include "../h/mbuf.h"
145640Sroot #include "../h/pte.h"
155640Sroot #include "../h/buf.h"
165640Sroot #include "../h/protosw.h"
175640Sroot #include "../h/socket.h"
185640Sroot #include "../h/ubareg.h"
195640Sroot #include "../h/ubavar.h"
205640Sroot #include "../h/cpu.h"
215640Sroot #include "../h/mtpr.h"
225640Sroot #include "../h/vmmac.h"
235640Sroot #include "../net/in.h"
245640Sroot #include "../net/in_systm.h"
255640Sroot #include "../net/if.h"
265640Sroot #include "../net/if_imp.h"
275859Sroot #include "../net/if_imphost.h"
285640Sroot #include "../net/ip.h"
295640Sroot #include "../net/ip_var.h"
306365Ssam #include "../net/route.h"
316504Ssam #include <errno.h>
325640Sroot 
335640Sroot /*
345640Sroot  * IMP software status per interface.
355640Sroot  * (partially shared with the hardware specific module)
365640Sroot  *
375640Sroot  * Each interface is referenced by a network interface structure,
385640Sroot  * imp_if, which the routing code uses to locate the interface.
395640Sroot  * This structure contains the output queue for the interface, its
405640Sroot  * address, ...  IMP specific structures used in connecting the
415640Sroot  * IMP software modules to the hardware specific interface routines
425771Swnj  * are stored here.  The common structures are made visible to the
435771Swnj  * interface driver by passing a pointer to the hardware routine
445771Swnj  * at "attach" time.
455640Sroot  *
465640Sroot  * NOTE: imp_if and imp_cb are assumed adjacent in hardware code.
475640Sroot  */
485640Sroot struct imp_softc {
495640Sroot 	struct	ifnet imp_if;		/* network visible interface */
505640Sroot 	struct	impcb imp_cb;		/* hooks to hardware module */
515640Sroot 	u_char	imp_state;		/* current state of IMP */
525640Sroot 	char	imp_dropcnt;		/* used during initialization */
535640Sroot } imp_softc[NIMP];
545640Sroot 
555640Sroot /*
565640Sroot  * Messages from IMP regarding why
575640Sroot  * it's going down.
585640Sroot  */
595924Sroot static char *impmessage[] = {
605640Sroot 	"in 30 seconds",
615640Sroot 	"for hardware PM",
625640Sroot 	"to reload software",
635640Sroot 	"for emergency reset"
645640Sroot };
655640Sroot 
665771Swnj int	impdown(), impinit(), impoutput();
675771Swnj 
685640Sroot /*
695640Sroot  * IMP attach routine.  Called from hardware device attach routine
705640Sroot  * at configuration time with a pointer to the UNIBUS device structure.
715640Sroot  * Sets up local state and returns pointer to base of ifnet+impcb
725640Sroot  * structures.  This is then used by the device's attach routine
735640Sroot  * set up its back pointers.
745640Sroot  */
755640Sroot impattach(ui)
765640Sroot 	struct uba_device *ui;
775640Sroot {
785640Sroot 	struct imp_softc *sc = &imp_softc[ui->ui_unit];
795640Sroot 	register struct ifnet *ifp = &sc->imp_if;
806336Ssam 	struct sockaddr_in *sin;
815640Sroot 
825640Sroot COUNT(IMPATTACH);
835640Sroot 	/* UNIT COULD BE AMBIGUOUS */
845640Sroot 	ifp->if_unit = ui->ui_unit;
855640Sroot 	ifp->if_name = "imp";
866271Sroot 	ifp->if_mtu = IMPMTU - sizeof(struct imp_leader);
875640Sroot 	ifp->if_net = ui->ui_flags;
885989Sroot 	/* the host and imp fields will be filled in by the imp */
896336Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
906336Ssam 	sin->sin_family = AF_INET;
916336Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, 0);
925771Swnj 	ifp->if_init = impinit;
935771Swnj 	ifp->if_output = impoutput;
945771Swnj 	/* reset is handled at the hardware level */
955640Sroot 	if_attach(ifp);
965640Sroot 	return ((int)&sc->imp_if);
975640Sroot }
985640Sroot 
995640Sroot /*
1005640Sroot  * IMP initialization routine: call hardware module to
1015640Sroot  * setup UNIBUS resources, init state and get ready for
1025640Sroot  * NOOPs the IMP should send us, and that we want to drop.
1035640Sroot  */
1045640Sroot impinit(unit)
1055640Sroot 	int unit;
1065640Sroot {
1076500Ssam 	int s = splimp();
1085640Sroot 	register struct imp_softc *sc = &imp_softc[unit];
1095640Sroot 
1106500Ssam COUNT(IMPINIT);
1115771Swnj 	if ((*sc->imp_cb.ic_init)(unit) == 0) {
1125771Swnj 		sc->imp_state = IMPS_DOWN;
1136336Ssam 		sc->imp_if.if_flags &= ~IFF_UP;
1146500Ssam 		splx(s);
1155771Swnj 		return;
1165771Swnj 	}
1175640Sroot 	sc->imp_state = IMPS_INIT;
1185771Swnj 	impnoops(sc);
1196365Ssam 	if_rtinit(&sc->imp_if, RTF_DIRECT|RTF_UP);
1206500Ssam 	splx(s);
1215640Sroot }
1225640Sroot 
1235640Sroot struct sockproto impproto = { PF_IMPLINK };
1245645Ssam struct sockaddr_in impdst = { AF_IMPLINK };
1255645Ssam struct sockaddr_in impsrc = { AF_IMPLINK };
1265640Sroot 
1275640Sroot /*
1285640Sroot  * ARPAnet 1822 input routine.
1295640Sroot  * Called from hardware input interrupt routine to handle 1822
1305640Sroot  * IMP-host messages.  Type 0 messages (non-control) are
1315640Sroot  * passed to higher level protocol processors on the basis
1325640Sroot  * of link number.  Other type messages (control) are handled here.
1335640Sroot  */
1345771Swnj impinput(unit, m)
1355640Sroot 	int unit;
1365771Swnj 	register struct mbuf *m;
1375640Sroot {
1385640Sroot 	register struct imp_leader *ip;
1395640Sroot 	register struct imp_softc *sc = &imp_softc[unit];
1405640Sroot 	register struct host *hp;
1415640Sroot 	register struct ifqueue *inq;
1425771Swnj 	struct control_leader *cp;
1435640Sroot 	struct in_addr addr;
1445924Sroot 	struct mbuf *next;
1456336Ssam 	struct sockaddr_in *sin;
1465640Sroot 
1475932Sroot COUNT(IMPINPUT);
1486257Sroot 	/* verify leader length. */
1495771Swnj 	if (m->m_len < sizeof(struct control_leader) &&
1505771Swnj 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0)
1515771Swnj 		return;
1525771Swnj 	cp = mtod(m, struct control_leader *);
1535771Swnj 	if (cp->dl_mtype == IMPTYPE_DATA)
1545771Swnj 		if (m->m_len < sizeof(struct imp_leader) &&
1555771Swnj 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0)
1565771Swnj 			return;
1575640Sroot 	ip = mtod(m, struct imp_leader *);
1585640Sroot 
1596257Sroot 	/* check leader type */
1605771Swnj 	if (ip->il_format != IMP_NFF) {
1615771Swnj 		sc->imp_if.if_collisions++;	/* XXX */
1625640Sroot 		goto drop;
1635771Swnj 	}
1645640Sroot 
1655640Sroot 	/*
1665640Sroot 	 * Certain messages require a host structure.
1675640Sroot 	 * Do this in one shot here.
1685640Sroot 	 */
1695640Sroot 	switch (ip->il_mtype) {
1705640Sroot 
1715640Sroot 	case IMPTYPE_RFNM:
1725640Sroot 	case IMPTYPE_INCOMPLETE:
1735640Sroot 	case IMPTYPE_HOSTDEAD:
1745640Sroot 	case IMPTYPE_HOSTUNREACH:
1755640Sroot 	case IMPTYPE_BADDATA:
1765859Sroot #ifdef notdef
1775771Swnj 		addr.s_net = ip->il_network;
1785859Sroot #else
1795859Sroot 		addr.s_net = 0;
1805859Sroot #endif
1815771Swnj 		addr.s_imp = ip->il_imp;
1825771Swnj 		addr.s_host = ip->il_host;
1835771Swnj 		hp = hostlookup(addr);
1845640Sroot 		break;
1855640Sroot 	}
1865640Sroot 
1875640Sroot 	switch (ip->il_mtype) {
1885640Sroot 
1895640Sroot 	case IMPTYPE_DATA:
1905640Sroot 		break;
1915640Sroot 
1925640Sroot 	/*
1935640Sroot 	 * IMP leader error.  Reset the IMP and discard the packet.
1945640Sroot 	 */
1955640Sroot 	case IMPTYPE_BADLEADER:
1965647Ssam 		/*
1975647Ssam 		 * According to 1822 document, this message
1985647Ssam 		 * will be generated in response to the
1995647Ssam 		 * first noop sent to the IMP after
2005647Ssam 		 * the host resets the IMP interface.
2015647Ssam 		 */
2025771Swnj 		if (sc->imp_state != IMPS_INIT) {
2035924Sroot 			impmsg(sc, "leader error");
204*6582Ssam 			hostreset(sc->imp_if.if_net);
2055647Ssam 			impnoops(sc);
2065647Ssam 		}
207*6582Ssam 		goto drop;
2085640Sroot 
2095640Sroot 	/*
2105640Sroot 	 * IMP going down.  Print message, and if not immediate,
2115640Sroot 	 * set off a timer to insure things will be reset at the
2125640Sroot 	 * appropriate time.
2135640Sroot 	 */
2145640Sroot 	case IMPTYPE_DOWN:
2155640Sroot 		if ((ip->il_link & IMP_DMASK) == 0) {
2165640Sroot 			sc->imp_state = IMPS_GOINGDOWN;
2176160Ssam 			timeout(impdown, (caddr_t)sc, 30 * hz);
2185640Sroot 		}
2196160Ssam 		impmsg(sc, "going down %s",
2206160Ssam 			(u_int)impmessage[ip->il_link&IMP_DMASK]);
221*6582Ssam 		goto drop;
2225640Sroot 
2235640Sroot 	/*
2245640Sroot 	 * A NOP usually seen during the initialization sequence.
2255640Sroot 	 * Compare the local address with that in the message.
2265640Sroot 	 * Reset the local address notion if it doesn't match.
2275640Sroot 	 */
2286336Ssam 	case IMPTYPE_NOOP:
2295647Ssam 		if (sc->imp_state == IMPS_DOWN) {
2305647Ssam 			sc->imp_state = IMPS_INIT;
2315647Ssam 			sc->imp_dropcnt = IMP_DROPCNT;
2325647Ssam 		}
2336500Ssam 		if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0)
2346271Sroot 			goto drop;
2356500Ssam 		sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
2366500Ssam 		if (sin->sin_addr.s_host != ip->il_host ||
2376500Ssam 		    sin->sin_addr.s_imp != ip->il_imp) {
2386500Ssam 			sc->imp_if.if_host[0] =
2396500Ssam 				sin->sin_addr.s_host = ip->il_host;
2406500Ssam 			sin->sin_addr.s_imp = ip->il_imp;
2416500Ssam 			impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host,
2426500Ssam 				ntohs(ip->il_imp));
2436500Ssam 		}
2445771Swnj 		sc->imp_state = IMPS_UP;
2456336Ssam 		sc->imp_if.if_flags |= IFF_UP;
2465771Swnj 		/* restart output in case something was q'd */
2475771Swnj 		(*sc->imp_cb.ic_start)(sc->imp_if.if_unit);
2486271Sroot 		goto drop;
2495640Sroot 
2505640Sroot 	/*
251*6582Ssam 	 * RFNM or INCOMPLETE message, send next
252*6582Ssam 	 * message on the q.  We could pass incomplete's
253*6582Ssam 	 * up to the next level, but this currently isn't
254*6582Ssam 	 * needed.
2555640Sroot 	 */
2565640Sroot 	case IMPTYPE_RFNM:
2575640Sroot 	case IMPTYPE_INCOMPLETE:
258*6582Ssam 		if (hp && hp->h_rfnm && (next = hostdeque(hp)))
259*6582Ssam 			(void) impsnd(&sc->imp_if, next);
2606271Sroot 		goto drop;
2615640Sroot 
2625640Sroot 	/*
2635640Sroot 	 * Host or IMP can't be reached.  Flush any packets
2645640Sroot 	 * awaiting transmission and release the host structure.
2655640Sroot 	 */
2665640Sroot 	case IMPTYPE_HOSTDEAD:
2675640Sroot 	case IMPTYPE_HOSTUNREACH:
268*6582Ssam 		impnotify(ip->il_mtype, ip, hp);
2695859Sroot 		goto rawlinkin;
2705640Sroot 
2715640Sroot 	/*
2725640Sroot 	 * Error in data.  Clear RFNM status for this host and send
2735640Sroot 	 * noops to the IMP to clear the interface.
2745640Sroot 	 */
2755640Sroot 	case IMPTYPE_BADDATA:
2765924Sroot 		impmsg(sc, "data error");
2775640Sroot 		if (hp)
2785640Sroot 			hp->h_rfnm = 0;
2795640Sroot 		impnoops(sc);
280*6582Ssam 		goto drop;
2815640Sroot 
2825640Sroot 	/*
2835647Ssam 	 * Interface reset.
2845640Sroot 	 */
2855640Sroot 	case IMPTYPE_RESET:
2865924Sroot 		impmsg(sc, "interface reset");
2875647Ssam 		impnoops(sc);
288*6582Ssam 		goto drop;
2895640Sroot 
2905640Sroot 	default:
2915640Sroot 		sc->imp_if.if_collisions++;		/* XXX */
292*6582Ssam 		goto drop;
2935640Sroot 	}
2945640Sroot 
2955640Sroot 	/*
2966257Sroot 	 * Data for a protocol.  Dispatch to the appropriate
2976257Sroot 	 * protocol routine (running at software interrupt).
2986257Sroot 	 * If this isn't a raw interface, advance pointer
2996257Sroot 	 * into mbuf past leader.
3005640Sroot 	 */
3015640Sroot 	switch (ip->il_link) {
3025640Sroot 
3035640Sroot #ifdef INET
3045640Sroot 	case IMPLINK_IP:
3055640Sroot 		m->m_len -= sizeof(struct imp_leader);
3065640Sroot 		m->m_off += sizeof(struct imp_leader);
3076261Swnj 		schednetisr(NETISR_IP);
3085640Sroot 		inq = &ipintrq;
3095640Sroot 		break;
3105640Sroot #endif
3115640Sroot 
3125640Sroot 	default:
3135868Sroot 	rawlinkin:
3145640Sroot 		impproto.sp_protocol = ip->il_link;
3156336Ssam 		sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
3166336Ssam 		impdst.sin_addr = sin->sin_addr;;
3175645Ssam 		impsrc.sin_addr.s_net = ip->il_network;
3185645Ssam 		impsrc.sin_addr.s_host = ip->il_host;
3195645Ssam 		impsrc.sin_addr.s_imp = ip->il_imp;
3206527Ssam 		raw_input(m, &impproto, (struct sockaddr *)&impsrc,
3216527Ssam 		  (struct sockaddr *)&impdst);
3225640Sroot 		return;
3235640Sroot 	}
3246208Swnj 	if (IF_QFULL(inq)) {
3256208Swnj 		IF_DROP(inq);
3266208Swnj 		goto drop;
3276208Swnj 	}
3285640Sroot 	IF_ENQUEUE(inq, m);
3295640Sroot 	return;
3305640Sroot 
3315640Sroot drop:
3325640Sroot 	m_freem(m);
3335640Sroot }
3345640Sroot 
3355647Ssam /*
3365647Ssam  * Bring the IMP down after notification.
3375647Ssam  */
3385647Ssam impdown(sc)
3395647Ssam 	struct imp_softc *sc;
3405647Ssam {
3416208Swnj 
3425647Ssam 	sc->imp_state = IMPS_DOWN;
3435924Sroot 	impmsg(sc, "marked down");
344*6582Ssam 	if_down(&sc->imp_if);
3455647Ssam }
3465647Ssam 
3475640Sroot /*VARARGS*/
3485924Sroot impmsg(sc, fmt, a1, a2)
3495640Sroot 	struct imp_softc *sc;
3505640Sroot 	char *fmt;
3516160Ssam 	u_int a1;
3525640Sroot {
3536208Swnj 
3545640Sroot 	printf("imp%d: ", sc->imp_if.if_unit);
3555640Sroot 	printf(fmt, a1, a2);
3565640Sroot 	printf("\n");
3575640Sroot }
3585640Sroot 
3595640Sroot /*
360*6582Ssam  * Process an IMP "error" message, passing this
361*6582Ssam  * up to the higher level protocol.
362*6582Ssam  */
363*6582Ssam impnotify(what, cp, hp)
364*6582Ssam 	int what;
365*6582Ssam 	struct control_leader *cp;
366*6582Ssam 	struct host *hp;
367*6582Ssam {
368*6582Ssam 	struct in_addr in;
369*6582Ssam 
370*6582Ssam #ifdef notdef
371*6582Ssam 	in.s_net = cp->dl_network;
372*6582Ssam #else
373*6582Ssam 	in.s_net = 10;
374*6582Ssam #endif
375*6582Ssam 	in.s_host = cp->dl_host;
376*6582Ssam 	in.s_imp = cp->dl_imp;
377*6582Ssam 	if (cp->dl_link != IMPLINK_IP)
378*6582Ssam 		raw_ctlinput(what, (caddr_t)&in);
379*6582Ssam 	else
380*6582Ssam 		ip_ctlinput(what, (caddr_t)&in);
381*6582Ssam 	if (hp)
382*6582Ssam 		hostfree(hp);
383*6582Ssam }
384*6582Ssam 
385*6582Ssam /*
3865640Sroot  * ARPAnet 1822 output routine.
3875640Sroot  * Called from higher level protocol routines to set up messages for
3885640Sroot  * transmission to the imp.  Sets up the header and calls impsnd to
3895640Sroot  * enqueue the message for this IMP's hardware driver.
3905640Sroot  */
3916336Ssam impoutput(ifp, m0, dst)
3925640Sroot 	register struct ifnet *ifp;
3935640Sroot 	struct mbuf *m0;
3946336Ssam 	struct sockaddr *dst;
3955640Sroot {
3965640Sroot 	register struct imp_leader *imp;
3975640Sroot 	register struct mbuf *m = m0;
3986244Sroot 	int x, dhost, dimp, dlink, len, dnet;
3996504Ssam 	int error = 0;
4005640Sroot 
4015771Swnj COUNT(IMPOUTPUT);
4025640Sroot 	/*
4035640Sroot 	 * Don't even try if the IMP is unavailable.
4045640Sroot 	 */
4056504Ssam 	if (imp_softc[ifp->if_unit].imp_state != IMPS_UP) {
4066504Ssam 		error = ENETDOWN;
4075647Ssam 		goto drop;
4086504Ssam 	}
4095640Sroot 
4106336Ssam 	switch (dst->sa_family) {
4115640Sroot 
4125640Sroot #ifdef INET
4136336Ssam 	case AF_INET: {
4146336Ssam 		struct ip *ip = mtod(m0, struct ip *);
4156336Ssam 		struct sockaddr_in *sin = (struct sockaddr_in *)dst;
4165640Sroot 
4176336Ssam 		dhost = sin->sin_addr.s_host;
4186336Ssam 		dimp = sin->sin_addr.s_impno;
4195640Sroot 		dlink = IMPLINK_IP;
4206244Sroot 		dnet = 0;
4216160Ssam 		len = ntohs((u_short)ip->ip_len);
4225640Sroot 		break;
4235640Sroot 	}
4245640Sroot #endif
4256336Ssam 	case AF_IMPLINK:
4265640Sroot 		goto leaderexists;
4275640Sroot 
4285640Sroot 	default:
4296336Ssam 		printf("imp%d: can't handle af%d\n", ifp->if_unit,
4306336Ssam 			dst->sa_family);
4316504Ssam 		error = EAFNOSUPPORT;
4325647Ssam 		goto drop;
4335640Sroot 	}
4345640Sroot 
4355640Sroot 	/*
4365640Sroot 	 * Add IMP leader.  If there's not enough space in the
4375640Sroot 	 * first mbuf, allocate another.  If that should fail, we
4385640Sroot 	 * drop this sucker.
4395640Sroot 	 */
4405640Sroot 	if (m->m_off > MMAXOFF ||
4415640Sroot 	    MMINOFF + sizeof(struct imp_leader) > m->m_off) {
4425640Sroot 		m = m_get(M_DONTWAIT);
4436504Ssam 		if (m == 0) {
4446504Ssam 			error = ENOBUFS;
4455647Ssam 			goto drop;
4466504Ssam 		}
4475640Sroot 		m->m_next = m0;
4485640Sroot 		m->m_off = MMINOFF;
4495640Sroot 		m->m_len = sizeof(struct imp_leader);
4505640Sroot 	} else {
4515640Sroot 		m->m_off -= sizeof(struct imp_leader);
4525640Sroot 		m->m_len += sizeof(struct imp_leader);
4535640Sroot 	}
4545640Sroot 	imp = mtod(m, struct imp_leader *);
4555640Sroot 	imp->il_format = IMP_NFF;
4565859Sroot 	imp->il_mtype = IMPTYPE_DATA;
4576244Sroot 	imp->il_network = dnet;
4585640Sroot 	imp->il_host = dhost;
4596244Sroot 	imp->il_imp = htons((u_short)dimp);
4606160Ssam 	imp->il_length =
4616160Ssam 		htons((u_short)(len + sizeof(struct imp_leader)) << 3);
4625640Sroot 	imp->il_link = dlink;
4635859Sroot 	imp->il_flags = imp->il_htype = imp->il_subtype = 0;
4645640Sroot 
4655640Sroot leaderexists:
4665640Sroot 	return (impsnd(ifp, m));
4675647Ssam drop:
4685647Ssam 	m_freem(m0);
4696504Ssam 	return (error);
4705640Sroot }
4715640Sroot 
4725640Sroot /*
4735640Sroot  * Put a message on an interface's output queue.
4745640Sroot  * Perform RFNM counting: no more than 8 message may be
4755640Sroot  * in flight to any one host.
4765640Sroot  */
4775640Sroot impsnd(ifp, m)
4785640Sroot 	struct ifnet *ifp;
4795640Sroot 	struct mbuf *m;
4805640Sroot {
4815640Sroot 	register struct imp_leader *ip;
4825640Sroot 	register struct host *hp;
4835640Sroot 	struct impcb *icp;
4845640Sroot 	int x;
4855640Sroot 
4865771Swnj COUNT(IMPSND);
4875640Sroot 	ip = mtod(m, struct imp_leader *);
4885640Sroot 
4895640Sroot 	/*
4905640Sroot 	 * Do RFNM counting for data messages
4915640Sroot 	 * (no more than 8 outstanding to any host)
4925640Sroot 	 */
4936095Swnj 	x = splimp();
4945640Sroot 	if (ip->il_mtype == IMPTYPE_DATA) {
4955640Sroot 		struct in_addr addr;
4965640Sroot 
4975859Sroot #ifdef notdef
4985771Swnj                 addr.s_net = ip->il_network;
4995859Sroot #else
5005859Sroot 		addr.s_net = 0;
5015859Sroot #endif
5025640Sroot                 addr.s_host = ip->il_host;
5035640Sroot                 addr.s_imp = ip->il_imp;
5045771Swnj 		if ((hp = hostlookup(addr)) == 0)
5055771Swnj 			hp = hostenter(addr);
5065640Sroot 
5075640Sroot 		/*
5085647Ssam 		 * If IMP would block, queue until RFNM
5095640Sroot 		 */
5105640Sroot 		if (hp) {
5115640Sroot 			if (hp->h_rfnm < 8) {
5125640Sroot 				hp->h_rfnm++;
5135640Sroot 				goto enque;
5145640Sroot 			}
5156095Swnj 			if (hp->h_qcnt < 8) {	/* high water mark */
5166095Swnj 				HOST_ENQUE(hp, m);
5176095Swnj 				goto start;
5186095Swnj 			}
5195640Sroot 		}
5205640Sroot 		m_freem(m);
5215859Sroot 		splx(x);
5226504Ssam 		return (ENOBUFS);	/* XXX */
5235640Sroot 	}
5245640Sroot enque:
5256208Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5266208Swnj 		IF_DROP(&ifp->if_snd);
5276208Swnj 		m_freem(m);
5286208Swnj 		splx(x);
5296504Ssam 		return (ENOBUFS);	/* XXX */
5306208Swnj 	}
5315640Sroot 	IF_ENQUEUE(&ifp->if_snd, m);
5326095Swnj start:
5335640Sroot 	splx(x);
5345640Sroot 	icp = &imp_softc[ifp->if_unit].imp_cb;
5355640Sroot 	if (icp->ic_oactive == 0)
5365640Sroot 		(*icp->ic_start)(ifp->if_unit);
5376504Ssam 	return (0);
5385640Sroot }
5395640Sroot 
5405640Sroot /*
5415640Sroot  * Put three 1822 NOOPs at the head of the output queue.
5425640Sroot  * Part of host-IMP initialization procedure.
5435640Sroot  * (Should return success/failure, but noone knows
5445640Sroot  * what to do with this, so why bother?)
5455640Sroot  */
5465640Sroot impnoops(sc)
5475640Sroot 	register struct imp_softc *sc;
5485640Sroot {
5495640Sroot 	register i;
5505640Sroot 	register struct mbuf *m;
5515771Swnj 	register struct control_leader *cp;
5525640Sroot 	int x;
5535640Sroot 
5545771Swnj COUNT(IMPNOOPS);
5555640Sroot 	sc->imp_dropcnt = IMP_DROPCNT;
5565771Swnj 	for (i = 0; i < IMP_DROPCNT + 1; i++ ) {
5575640Sroot 		if ((m = m_getclr(M_DONTWAIT)) == 0)
5585640Sroot 			return;
5595640Sroot 		m->m_off = MMINOFF;
5605771Swnj 		m->m_len = sizeof(struct control_leader);
5615771Swnj 		cp = mtod(m, struct control_leader *);
5625771Swnj 		cp->dl_format = IMP_NFF;
5635771Swnj                 cp->dl_link = i;
5645771Swnj                 cp->dl_mtype = IMPTYPE_NOOP;
5655640Sroot 		x = splimp();
5665640Sroot 		IF_PREPEND(&sc->imp_if.if_snd, m);
5675640Sroot 		splx(x);
5685640Sroot 	}
5695640Sroot 	if (sc->imp_cb.ic_oactive == 0)
5705640Sroot 		(*sc->imp_cb.ic_start)(sc->imp_if.if_unit);
5715640Sroot }
5725640Sroot #endif
573