1*6500Ssam /*	if_imp.c	4.23	82/04/10	*/
25640Sroot 
35640Sroot #include "imp.h"
45640Sroot #if NIMP > 0
55640Sroot /*
65640Sroot  * ARPAnet IMP interface driver.
75640Sroot  *
85640Sroot  * The IMP-host protocol is handled here, leaving
95640Sroot  * hardware specifics to the lower level interface driver.
105771Swnj  *
115771Swnj  * TODO:
125771Swnj  *	pass more error indications up to protocol modules
135640Sroot  */
145640Sroot #include "../h/param.h"
155640Sroot #include "../h/systm.h"
165640Sroot #include "../h/mbuf.h"
175640Sroot #include "../h/pte.h"
185640Sroot #include "../h/buf.h"
195640Sroot #include "../h/protosw.h"
205640Sroot #include "../h/socket.h"
215640Sroot #include "../h/ubareg.h"
225640Sroot #include "../h/ubavar.h"
235640Sroot #include "../h/cpu.h"
245640Sroot #include "../h/mtpr.h"
255640Sroot #include "../h/vmmac.h"
265640Sroot #include "../net/in.h"
275640Sroot #include "../net/in_systm.h"
285640Sroot #include "../net/if.h"
295640Sroot #include "../net/if_imp.h"
305859Sroot #include "../net/if_imphost.h"
315640Sroot #include "../net/ip.h"
325640Sroot #include "../net/ip_var.h"
336365Ssam #include "../net/route.h"
345640Sroot 
355640Sroot /*
365640Sroot  * IMP software status per interface.
375640Sroot  * (partially shared with the hardware specific module)
385640Sroot  *
395640Sroot  * Each interface is referenced by a network interface structure,
405640Sroot  * imp_if, which the routing code uses to locate the interface.
415640Sroot  * This structure contains the output queue for the interface, its
425640Sroot  * address, ...  IMP specific structures used in connecting the
435640Sroot  * IMP software modules to the hardware specific interface routines
445771Swnj  * are stored here.  The common structures are made visible to the
455771Swnj  * interface driver by passing a pointer to the hardware routine
465771Swnj  * at "attach" time.
475640Sroot  *
485640Sroot  * NOTE: imp_if and imp_cb are assumed adjacent in hardware code.
495640Sroot  */
505640Sroot struct imp_softc {
515640Sroot 	struct	ifnet imp_if;		/* network visible interface */
525640Sroot 	struct	impcb imp_cb;		/* hooks to hardware module */
535640Sroot 	u_char	imp_state;		/* current state of IMP */
545640Sroot 	char	imp_dropcnt;		/* used during initialization */
555640Sroot } imp_softc[NIMP];
565640Sroot 
575640Sroot /*
585640Sroot  * Messages from IMP regarding why
595640Sroot  * it's going down.
605640Sroot  */
615924Sroot static char *impmessage[] = {
625640Sroot 	"in 30 seconds",
635640Sroot 	"for hardware PM",
645640Sroot 	"to reload software",
655640Sroot 	"for emergency reset"
665640Sroot };
675640Sroot 
685771Swnj int	impdown(), impinit(), impoutput();
695771Swnj 
705640Sroot /*
715640Sroot  * IMP attach routine.  Called from hardware device attach routine
725640Sroot  * at configuration time with a pointer to the UNIBUS device structure.
735640Sroot  * Sets up local state and returns pointer to base of ifnet+impcb
745640Sroot  * structures.  This is then used by the device's attach routine
755640Sroot  * set up its back pointers.
765640Sroot  */
775640Sroot impattach(ui)
785640Sroot 	struct uba_device *ui;
795640Sroot {
805640Sroot 	struct imp_softc *sc = &imp_softc[ui->ui_unit];
815640Sroot 	register struct ifnet *ifp = &sc->imp_if;
826336Ssam 	struct sockaddr_in *sin;
835640Sroot 
845640Sroot COUNT(IMPATTACH);
855640Sroot 	/* UNIT COULD BE AMBIGUOUS */
865640Sroot 	ifp->if_unit = ui->ui_unit;
875640Sroot 	ifp->if_name = "imp";
886271Sroot 	ifp->if_mtu = IMPMTU - sizeof(struct imp_leader);
895640Sroot 	ifp->if_net = ui->ui_flags;
905989Sroot 	/* the host and imp fields will be filled in by the imp */
916336Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
926336Ssam 	sin->sin_family = AF_INET;
936336Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, 0);
945771Swnj 	ifp->if_init = impinit;
955771Swnj 	ifp->if_output = impoutput;
965771Swnj 	/* reset is handled at the hardware level */
975640Sroot 	if_attach(ifp);
985640Sroot 	return ((int)&sc->imp_if);
995640Sroot }
1005640Sroot 
1015640Sroot /*
1025640Sroot  * IMP initialization routine: call hardware module to
1035640Sroot  * setup UNIBUS resources, init state and get ready for
1045640Sroot  * NOOPs the IMP should send us, and that we want to drop.
1055640Sroot  */
1065640Sroot impinit(unit)
1075640Sroot 	int unit;
1085640Sroot {
109*6500Ssam 	int s = splimp();
1105640Sroot 	register struct imp_softc *sc = &imp_softc[unit];
1115640Sroot 
112*6500Ssam COUNT(IMPINIT);
1135771Swnj 	if ((*sc->imp_cb.ic_init)(unit) == 0) {
1145771Swnj 		sc->imp_state = IMPS_DOWN;
1156336Ssam 		sc->imp_if.if_flags &= ~IFF_UP;
116*6500Ssam 		splx(s);
1175771Swnj 		return;
1185771Swnj 	}
1195640Sroot 	sc->imp_state = IMPS_INIT;
1205771Swnj 	impnoops(sc);
1216365Ssam 	if_rtinit(&sc->imp_if, RTF_DIRECT|RTF_UP);
122*6500Ssam 	splx(s);
1235640Sroot }
1245640Sroot 
1255640Sroot struct sockproto impproto = { PF_IMPLINK };
1265645Ssam struct sockaddr_in impdst = { AF_IMPLINK };
1275645Ssam struct sockaddr_in impsrc = { AF_IMPLINK };
1285640Sroot 
1295640Sroot /*
1305640Sroot  * ARPAnet 1822 input routine.
1315640Sroot  * Called from hardware input interrupt routine to handle 1822
1325640Sroot  * IMP-host messages.  Type 0 messages (non-control) are
1335640Sroot  * passed to higher level protocol processors on the basis
1345640Sroot  * of link number.  Other type messages (control) are handled here.
1355640Sroot  */
1365771Swnj impinput(unit, m)
1375640Sroot 	int unit;
1385771Swnj 	register struct mbuf *m;
1395640Sroot {
1405640Sroot 	register struct imp_leader *ip;
1415640Sroot 	register struct imp_softc *sc = &imp_softc[unit];
1425640Sroot 	register struct host *hp;
1435640Sroot 	register struct ifqueue *inq;
1445771Swnj 	struct control_leader *cp;
1455640Sroot 	struct in_addr addr;
1465924Sroot 	struct mbuf *next;
1476336Ssam 	struct sockaddr_in *sin;
1485640Sroot 
1495932Sroot COUNT(IMPINPUT);
1506257Sroot 	/* verify leader length. */
1515771Swnj 	if (m->m_len < sizeof(struct control_leader) &&
1525771Swnj 	    (m = m_pullup(m, sizeof(struct control_leader))) == 0)
1535771Swnj 		return;
1545771Swnj 	cp = mtod(m, struct control_leader *);
1555771Swnj 	if (cp->dl_mtype == IMPTYPE_DATA)
1565771Swnj 		if (m->m_len < sizeof(struct imp_leader) &&
1575771Swnj 		    (m = m_pullup(m, sizeof(struct imp_leader))) == 0)
1585771Swnj 			return;
1595640Sroot 	ip = mtod(m, struct imp_leader *);
1605640Sroot 
1616257Sroot 	/* check leader type */
1625771Swnj 	if (ip->il_format != IMP_NFF) {
1635771Swnj 		sc->imp_if.if_collisions++;	/* XXX */
1645640Sroot 		goto drop;
1655771Swnj 	}
1665640Sroot 
1675640Sroot 	/*
1685640Sroot 	 * Certain messages require a host structure.
1695640Sroot 	 * Do this in one shot here.
1705640Sroot 	 */
1715640Sroot 	switch (ip->il_mtype) {
1725640Sroot 
1735640Sroot 	case IMPTYPE_RFNM:
1745640Sroot 	case IMPTYPE_INCOMPLETE:
1755640Sroot 	case IMPTYPE_HOSTDEAD:
1765640Sroot 	case IMPTYPE_HOSTUNREACH:
1775640Sroot 	case IMPTYPE_BADDATA:
1785859Sroot #ifdef notdef
1795771Swnj 		addr.s_net = ip->il_network;
1805859Sroot #else
1815859Sroot 		addr.s_net = 0;
1825859Sroot #endif
1835771Swnj 		addr.s_imp = ip->il_imp;
1845771Swnj 		addr.s_host = ip->il_host;
1855771Swnj 		hp = hostlookup(addr);
1865640Sroot 		break;
1875640Sroot 	}
1885640Sroot 
1895640Sroot 	switch (ip->il_mtype) {
1905640Sroot 
1915640Sroot 	case IMPTYPE_DATA:
1925640Sroot 		break;
1935640Sroot 
1945640Sroot 	/*
1955640Sroot 	 * IMP leader error.  Reset the IMP and discard the packet.
1965640Sroot 	 */
1975640Sroot 	case IMPTYPE_BADLEADER:
1985647Ssam 		/*
1995647Ssam 		 * According to 1822 document, this message
2005647Ssam 		 * will be generated in response to the
2015647Ssam 		 * first noop sent to the IMP after
2025647Ssam 		 * the host resets the IMP interface.
2035647Ssam 		 */
2045771Swnj 		if (sc->imp_state != IMPS_INIT) {
2055924Sroot 			impmsg(sc, "leader error");
2065771Swnj 			hostreset(sc->imp_if.if_net);	/* XXX */
2075647Ssam 			impnoops(sc);
2085647Ssam 		}
2096044Swnj 		goto rawlinkin;
2105640Sroot 
2115640Sroot 	/*
2125640Sroot 	 * IMP going down.  Print message, and if not immediate,
2135640Sroot 	 * set off a timer to insure things will be reset at the
2145640Sroot 	 * appropriate time.
2155640Sroot 	 */
2165640Sroot 	case IMPTYPE_DOWN:
2175640Sroot 		if ((ip->il_link & IMP_DMASK) == 0) {
2185640Sroot 			sc->imp_state = IMPS_GOINGDOWN;
2196160Ssam 			timeout(impdown, (caddr_t)sc, 30 * hz);
2205640Sroot 		}
2216160Ssam 		impmsg(sc, "going down %s",
2226160Ssam 			(u_int)impmessage[ip->il_link&IMP_DMASK]);
2236044Swnj 		goto rawlinkin;
2245640Sroot 
2255640Sroot 	/*
2265640Sroot 	 * A NOP usually seen during the initialization sequence.
2275640Sroot 	 * Compare the local address with that in the message.
2285640Sroot 	 * Reset the local address notion if it doesn't match.
2295640Sroot 	 */
2306336Ssam 	case IMPTYPE_NOOP:
2315647Ssam 		if (sc->imp_state == IMPS_DOWN) {
2325647Ssam 			sc->imp_state = IMPS_INIT;
2335647Ssam 			sc->imp_dropcnt = IMP_DROPCNT;
2345647Ssam 		}
235*6500Ssam 		if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0)
2366271Sroot 			goto drop;
237*6500Ssam 		sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
238*6500Ssam 		if (sin->sin_addr.s_host != ip->il_host ||
239*6500Ssam 		    sin->sin_addr.s_imp != ip->il_imp) {
240*6500Ssam 			sc->imp_if.if_host[0] =
241*6500Ssam 				sin->sin_addr.s_host = ip->il_host;
242*6500Ssam 			sin->sin_addr.s_imp = ip->il_imp;
243*6500Ssam 			impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host,
244*6500Ssam 				ntohs(ip->il_imp));
245*6500Ssam 		}
2465771Swnj 		sc->imp_state = IMPS_UP;
2476336Ssam 		sc->imp_if.if_flags |= IFF_UP;
2485771Swnj 		/* restart output in case something was q'd */
2495771Swnj 		(*sc->imp_cb.ic_start)(sc->imp_if.if_unit);
2506271Sroot 		goto drop;
2515640Sroot 
2525640Sroot 	/*
2535640Sroot 	 * RFNM or INCOMPLETE message, record in
2545640Sroot 	 * host table and prime output routine.
2555640Sroot 	 *
2565647Ssam 	 * SHOULD NOTIFY PROTOCOL ABOUT INCOMPLETES.
2575640Sroot 	 */
2585640Sroot 	case IMPTYPE_RFNM:
2595640Sroot 	case IMPTYPE_INCOMPLETE:
2605924Sroot 		if (hp && hp->h_rfnm)
2615924Sroot 			if (next = hostdeque(hp))
2626160Ssam 				(void) impsnd(&sc->imp_if, next);
2636271Sroot 		goto drop;
2645640Sroot 
2655640Sroot 	/*
2665640Sroot 	 * Host or IMP can't be reached.  Flush any packets
2675640Sroot 	 * awaiting transmission and release the host structure.
2685640Sroot 	 *
2695771Swnj 	 * TODO: NOTIFY THE PROTOCOL
2705640Sroot 	 */
2715640Sroot 	case IMPTYPE_HOSTDEAD:
2725924Sroot 		impmsg(sc, "host dead");	/* XXX */
2735771Swnj 		goto common;			/* XXX */
2745771Swnj 
2755771Swnj 	/* SHOULD SIGNAL ROUTING DAEMON */
2765640Sroot 	case IMPTYPE_HOSTUNREACH:
2775924Sroot 		impmsg(sc, "host unreachable");	/* XXX */
2785771Swnj 	common:
2795640Sroot 		if (hp)
2805771Swnj 			hostfree(hp);		/* won't work right */
2815859Sroot 		goto rawlinkin;
2825640Sroot 
2835640Sroot 	/*
2845640Sroot 	 * Error in data.  Clear RFNM status for this host and send
2855640Sroot 	 * noops to the IMP to clear the interface.
2865640Sroot 	 */
2875640Sroot 	case IMPTYPE_BADDATA:
2885924Sroot 		impmsg(sc, "data error");
2895640Sroot 		if (hp)
2905640Sroot 			hp->h_rfnm = 0;
2915640Sroot 		impnoops(sc);
2925859Sroot 		goto rawlinkin;
2935640Sroot 
2945640Sroot 	/*
2955647Ssam 	 * Interface reset.
2965640Sroot 	 */
2975640Sroot 	case IMPTYPE_RESET:
2985924Sroot 		impmsg(sc, "interface reset");
2995647Ssam 		impnoops(sc);
3006044Swnj 		goto rawlinkin;
3015640Sroot 
3025640Sroot 	default:
3035640Sroot 		sc->imp_if.if_collisions++;		/* XXX */
3046044Swnj 		goto rawlinkin;
3055640Sroot 	}
3065640Sroot 
3075640Sroot 	/*
3086257Sroot 	 * Data for a protocol.  Dispatch to the appropriate
3096257Sroot 	 * protocol routine (running at software interrupt).
3106257Sroot 	 * If this isn't a raw interface, advance pointer
3116257Sroot 	 * into mbuf past leader.
3125640Sroot 	 */
3135640Sroot 	switch (ip->il_link) {
3145640Sroot 
3155640Sroot #ifdef INET
3165640Sroot 	case IMPLINK_IP:
3175640Sroot 		m->m_len -= sizeof(struct imp_leader);
3185640Sroot 		m->m_off += sizeof(struct imp_leader);
3196261Swnj 		schednetisr(NETISR_IP);
3205640Sroot 		inq = &ipintrq;
3215640Sroot 		break;
3225640Sroot #endif
3235640Sroot 
3245640Sroot 	default:
3255868Sroot 	rawlinkin:
3265640Sroot 		impproto.sp_protocol = ip->il_link;
3276336Ssam 		sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
3286336Ssam 		impdst.sin_addr = sin->sin_addr;;
3295645Ssam 		impsrc.sin_addr.s_net = ip->il_network;
3305645Ssam 		impsrc.sin_addr.s_host = ip->il_host;
3315645Ssam 		impsrc.sin_addr.s_imp = ip->il_imp;
3326160Ssam 		raw_input(m, &impproto, (struct sockaddr *)&impdst,
3336160Ssam 		  (struct sockaddr *)&impsrc);
3345640Sroot 		return;
3355640Sroot 	}
3366208Swnj 	if (IF_QFULL(inq)) {
3376208Swnj 		IF_DROP(inq);
3386208Swnj 		goto drop;
3396208Swnj 	}
3405640Sroot 	IF_ENQUEUE(inq, m);
3415640Sroot 	return;
3425640Sroot 
3435640Sroot drop:
3445640Sroot 	m_freem(m);
3455640Sroot }
3465640Sroot 
3475647Ssam /*
3485647Ssam  * Bring the IMP down after notification.
3495647Ssam  */
3505647Ssam impdown(sc)
3515647Ssam 	struct imp_softc *sc;
3525647Ssam {
3536208Swnj 
3545647Ssam 	sc->imp_state = IMPS_DOWN;
3556336Ssam 	sc->imp_if.if_flags &= ~IFF_UP;
3565924Sroot 	impmsg(sc, "marked down");
3575647Ssam 	/* notify protocols with messages waiting? */
3585647Ssam }
3595647Ssam 
3605640Sroot /*VARARGS*/
3615924Sroot impmsg(sc, fmt, a1, a2)
3625640Sroot 	struct imp_softc *sc;
3635640Sroot 	char *fmt;
3646160Ssam 	u_int a1;
3655640Sroot {
3666208Swnj 
3675640Sroot 	printf("imp%d: ", sc->imp_if.if_unit);
3685640Sroot 	printf(fmt, a1, a2);
3695640Sroot 	printf("\n");
3705640Sroot }
3715640Sroot 
3725640Sroot /*
3735640Sroot  * ARPAnet 1822 output routine.
3745640Sroot  * Called from higher level protocol routines to set up messages for
3755640Sroot  * transmission to the imp.  Sets up the header and calls impsnd to
3765640Sroot  * enqueue the message for this IMP's hardware driver.
3775640Sroot  */
3786336Ssam impoutput(ifp, m0, dst)
3795640Sroot 	register struct ifnet *ifp;
3805640Sroot 	struct mbuf *m0;
3816336Ssam 	struct sockaddr *dst;
3825640Sroot {
3835640Sroot 	register struct imp_leader *imp;
3845640Sroot 	register struct mbuf *m = m0;
3856244Sroot 	int x, dhost, dimp, dlink, len, dnet;
3865640Sroot 
3875771Swnj COUNT(IMPOUTPUT);
3885640Sroot 	/*
3895640Sroot 	 * Don't even try if the IMP is unavailable.
3905640Sroot 	 */
3916482Ssam 	if (imp_softc[ifp->if_unit].imp_state != IMPS_UP)
3925647Ssam 		goto drop;
3935640Sroot 
3946336Ssam 	switch (dst->sa_family) {
3955640Sroot 
3965640Sroot #ifdef INET
3976336Ssam 	case AF_INET: {
3986336Ssam 		struct ip *ip = mtod(m0, struct ip *);
3996336Ssam 		struct sockaddr_in *sin = (struct sockaddr_in *)dst;
4005640Sroot 
4016336Ssam 		dhost = sin->sin_addr.s_host;
4026336Ssam 		dimp = sin->sin_addr.s_impno;
4035640Sroot 		dlink = IMPLINK_IP;
4046244Sroot 		dnet = 0;
4056160Ssam 		len = ntohs((u_short)ip->ip_len);
4065640Sroot 		break;
4075640Sroot 	}
4085640Sroot #endif
4096336Ssam 	case AF_IMPLINK:
4105640Sroot 		goto leaderexists;
4115640Sroot 
4125640Sroot 	default:
4136336Ssam 		printf("imp%d: can't handle af%d\n", ifp->if_unit,
4146336Ssam 			dst->sa_family);
4155647Ssam 		goto drop;
4165640Sroot 	}
4175640Sroot 
4185640Sroot 	/*
4195640Sroot 	 * Add IMP leader.  If there's not enough space in the
4205640Sroot 	 * first mbuf, allocate another.  If that should fail, we
4215640Sroot 	 * drop this sucker.
4225640Sroot 	 */
4235640Sroot 	if (m->m_off > MMAXOFF ||
4245640Sroot 	    MMINOFF + sizeof(struct imp_leader) > m->m_off) {
4255640Sroot 		m = m_get(M_DONTWAIT);
4265647Ssam 		if (m == 0)
4275647Ssam 			goto drop;
4285640Sroot 		m->m_next = m0;
4295640Sroot 		m->m_off = MMINOFF;
4305640Sroot 		m->m_len = sizeof(struct imp_leader);
4315640Sroot 	} else {
4325640Sroot 		m->m_off -= sizeof(struct imp_leader);
4335640Sroot 		m->m_len += sizeof(struct imp_leader);
4345640Sroot 	}
4355640Sroot 	imp = mtod(m, struct imp_leader *);
4365640Sroot 	imp->il_format = IMP_NFF;
4375859Sroot 	imp->il_mtype = IMPTYPE_DATA;
4386244Sroot 	imp->il_network = dnet;
4395640Sroot 	imp->il_host = dhost;
4406244Sroot 	imp->il_imp = htons((u_short)dimp);
4416160Ssam 	imp->il_length =
4426160Ssam 		htons((u_short)(len + sizeof(struct imp_leader)) << 3);
4435640Sroot 	imp->il_link = dlink;
4445859Sroot 	imp->il_flags = imp->il_htype = imp->il_subtype = 0;
4455640Sroot 
4465640Sroot leaderexists:
4475640Sroot 	/*
4485640Sroot 	 * Hand message to impsnd to perform RFNM counting
4495640Sroot 	 * and eventual transmission.
4505640Sroot 	 */
4515640Sroot 	return (impsnd(ifp, m));
4525647Ssam drop:
4535647Ssam 	m_freem(m0);
4545647Ssam 	return (0);
4555640Sroot }
4565640Sroot 
4575640Sroot /*
4585640Sroot  * Put a message on an interface's output queue.
4595640Sroot  * Perform RFNM counting: no more than 8 message may be
4605640Sroot  * in flight to any one host.
4615640Sroot  */
4625640Sroot impsnd(ifp, m)
4635640Sroot 	struct ifnet *ifp;
4645640Sroot 	struct mbuf *m;
4655640Sroot {
4665640Sroot 	register struct imp_leader *ip;
4675640Sroot 	register struct host *hp;
4685640Sroot 	struct impcb *icp;
4695640Sroot 	int x;
4705640Sroot 
4715771Swnj COUNT(IMPSND);
4725640Sroot 	ip = mtod(m, struct imp_leader *);
4735640Sroot 
4745640Sroot 	/*
4755640Sroot 	 * Do RFNM counting for data messages
4765640Sroot 	 * (no more than 8 outstanding to any host)
4775640Sroot 	 */
4786095Swnj 	x = splimp();
4795640Sroot 	if (ip->il_mtype == IMPTYPE_DATA) {
4805640Sroot 		struct in_addr addr;
4815640Sroot 
4825859Sroot #ifdef notdef
4835771Swnj                 addr.s_net = ip->il_network;
4845859Sroot #else
4855859Sroot 		addr.s_net = 0;
4865859Sroot #endif
4875640Sroot                 addr.s_host = ip->il_host;
4885640Sroot                 addr.s_imp = ip->il_imp;
4895771Swnj 		if ((hp = hostlookup(addr)) == 0)
4905771Swnj 			hp = hostenter(addr);
4915640Sroot 
4925640Sroot 		/*
4935647Ssam 		 * If IMP would block, queue until RFNM
4945640Sroot 		 */
4955640Sroot 		if (hp) {
4965640Sroot 			if (hp->h_rfnm < 8) {
4975640Sroot 				hp->h_rfnm++;
4985640Sroot 				goto enque;
4995640Sroot 			}
5006095Swnj 			if (hp->h_qcnt < 8) {	/* high water mark */
5016095Swnj 				HOST_ENQUE(hp, m);
5026095Swnj 				goto start;
5036095Swnj 			}
5045640Sroot 		}
5055640Sroot 		m_freem(m);
5065859Sroot 		splx(x);
5075640Sroot 		return (0);
5085640Sroot 	}
5095640Sroot enque:
5106208Swnj 	if (IF_QFULL(&ifp->if_snd)) {
5116208Swnj 		IF_DROP(&ifp->if_snd);
5126208Swnj 		m_freem(m);
5136208Swnj 		splx(x);
5146208Swnj 		return (0);
5156208Swnj 	}
5165640Sroot 	IF_ENQUEUE(&ifp->if_snd, m);
5176095Swnj start:
5185640Sroot 	splx(x);
5195640Sroot 	icp = &imp_softc[ifp->if_unit].imp_cb;
5205640Sroot 	if (icp->ic_oactive == 0)
5215640Sroot 		(*icp->ic_start)(ifp->if_unit);
5225640Sroot 	return (1);
5235640Sroot }
5245640Sroot 
5255640Sroot /*
5265640Sroot  * Put three 1822 NOOPs at the head of the output queue.
5275640Sroot  * Part of host-IMP initialization procedure.
5285640Sroot  * (Should return success/failure, but noone knows
5295640Sroot  * what to do with this, so why bother?)
5305640Sroot  */
5315640Sroot impnoops(sc)
5325640Sroot 	register struct imp_softc *sc;
5335640Sroot {
5345640Sroot 	register i;
5355640Sroot 	register struct mbuf *m;
5365771Swnj 	register struct control_leader *cp;
5375640Sroot 	int x;
5385640Sroot 
5395771Swnj COUNT(IMPNOOPS);
5405640Sroot 	sc->imp_dropcnt = IMP_DROPCNT;
5415771Swnj 	for (i = 0; i < IMP_DROPCNT + 1; i++ ) {
5425640Sroot 		if ((m = m_getclr(M_DONTWAIT)) == 0)
5435640Sroot 			return;
5445640Sroot 		m->m_off = MMINOFF;
5455771Swnj 		m->m_len = sizeof(struct control_leader);
5465771Swnj 		cp = mtod(m, struct control_leader *);
5475771Swnj 		cp->dl_format = IMP_NFF;
5485771Swnj                 cp->dl_link = i;
5495771Swnj                 cp->dl_mtype = IMPTYPE_NOOP;
5505640Sroot 		x = splimp();
5515640Sroot 		IF_PREPEND(&sc->imp_if.if_snd, m);
5525640Sroot 		splx(x);
5535640Sroot 	}
5545640Sroot 	if (sc->imp_cb.ic_oactive == 0)
5555640Sroot 		(*sc->imp_cb.ic_start)(sc->imp_if.if_unit);
5565640Sroot }
5575771Swnj 
5585859Sroot #ifdef IMPLEADERS
5595771Swnj printleader(routine, ip)
5605771Swnj 	char *routine;
5615771Swnj 	register struct imp_leader *ip;
5625771Swnj {
5635771Swnj 	printf("%s: ", routine);
5645771Swnj 	printbyte((char *)ip, 12);
5655771Swnj 	printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network,
5665771Swnj 		ip->il_flags);
5675771Swnj 	if (ip->il_mtype <= IMPTYPE_READY)
5685771Swnj 		printf("%s,", impleaders[ip->il_mtype]);
5695771Swnj 	else
5705771Swnj 		printf("%x,", ip->il_mtype);
5715771Swnj 	printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host,
5726244Sroot 		ntohs(ip->il_imp));
5735771Swnj 	if (ip->il_link == IMPLINK_IP)
5745771Swnj 		printf("ip,");
5755771Swnj 	else
5765771Swnj 		printf("%x,", ip->il_link);
5775771Swnj 	printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3);
5785771Swnj }
5795771Swnj 
5805771Swnj printbyte(cp, n)
5815771Swnj 	register char *cp;
5825771Swnj 	int n;
5835771Swnj {
5845771Swnj 	register i, j, c;
5855771Swnj 
5865771Swnj 	for (i=0; i<n; i++) {
5875771Swnj 		c = *cp++;
5885771Swnj 		for (j=0; j<2; j++)
5895771Swnj 			putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]);
5905771Swnj 		putchar(' ');
5915771Swnj 	}
5925771Swnj 	putchar('\n');
5935771Swnj }
5945640Sroot #endif
5955859Sroot #endif
596