1*10874Ssam /* if_imp.c 4.47 83/02/10 */ 25640Sroot 35640Sroot #include "imp.h" 45640Sroot #if NIMP > 0 55640Sroot /* 66582Ssam * ARPANET IMP interface driver. 75640Sroot * 85640Sroot * The IMP-host protocol is handled here, leaving 95640Sroot * hardware specifics to the lower level interface driver. 105640Sroot */ 119800Ssam #include "../machine/pte.h" 129800Ssam 135640Sroot #include "../h/param.h" 145640Sroot #include "../h/systm.h" 155640Sroot #include "../h/mbuf.h" 165640Sroot #include "../h/buf.h" 175640Sroot #include "../h/protosw.h" 185640Sroot #include "../h/socket.h" 198705Sroot #include "../h/vmmac.h" 20*10874Ssam #include "../h/time.h" 21*10874Ssam #include "../h/kernel.h" 228705Sroot 238705Sroot #include "../vax/cpu.h" 248533Sroot #include "../vax/mtpr.h" 258782Sroot #include "../vaxuba/ubareg.h" 268782Sroot #include "../vaxuba/ubavar.h" 278705Sroot 288705Sroot #include "../net/if.h" 298705Sroot #include "../net/route.h" 308705Sroot #include "../net/netisr.h" 318408Swnj #include "../netinet/in.h" 328408Swnj #include "../netinet/in_systm.h" 338705Sroot #include "../netinet/ip.h" 348705Sroot #include "../netinet/ip_var.h" 357199Ssam /* define IMPLEADERS here to get leader printing code */ 368408Swnj #include "../netimp/if_imp.h" 378408Swnj #include "../netimp/if_imphost.h" 386504Ssam #include <errno.h> 395640Sroot 405640Sroot /* 415640Sroot * IMP software status per interface. 425640Sroot * (partially shared with the hardware specific module) 435640Sroot * 445640Sroot * Each interface is referenced by a network interface structure, 455640Sroot * imp_if, which the routing code uses to locate the interface. 465640Sroot * This structure contains the output queue for the interface, its 475640Sroot * address, ... IMP specific structures used in connecting the 485640Sroot * IMP software modules to the hardware specific interface routines 495771Swnj * are stored here. The common structures are made visible to the 505771Swnj * interface driver by passing a pointer to the hardware routine 515771Swnj * at "attach" time. 525640Sroot * 535640Sroot * NOTE: imp_if and imp_cb are assumed adjacent in hardware code. 545640Sroot */ 555640Sroot struct imp_softc { 565640Sroot struct ifnet imp_if; /* network visible interface */ 575640Sroot struct impcb imp_cb; /* hooks to hardware module */ 585640Sroot u_char imp_state; /* current state of IMP */ 595640Sroot char imp_dropcnt; /* used during initialization */ 605640Sroot } imp_softc[NIMP]; 615640Sroot 625640Sroot /* 635640Sroot * Messages from IMP regarding why 645640Sroot * it's going down. 655640Sroot */ 665924Sroot static char *impmessage[] = { 675640Sroot "in 30 seconds", 685640Sroot "for hardware PM", 695640Sroot "to reload software", 705640Sroot "for emergency reset" 715640Sroot }; 725640Sroot 735771Swnj int impdown(), impinit(), impoutput(); 745771Swnj 755640Sroot /* 765640Sroot * IMP attach routine. Called from hardware device attach routine 775640Sroot * at configuration time with a pointer to the UNIBUS device structure. 785640Sroot * Sets up local state and returns pointer to base of ifnet+impcb 795640Sroot * structures. This is then used by the device's attach routine 805640Sroot * set up its back pointers. 815640Sroot */ 828815Sroot impattach(ui, reset) 835640Sroot struct uba_device *ui; 848815Sroot int (*reset)(); 855640Sroot { 865640Sroot struct imp_softc *sc = &imp_softc[ui->ui_unit]; 875640Sroot register struct ifnet *ifp = &sc->imp_if; 886336Ssam struct sockaddr_in *sin; 895640Sroot 905640Sroot /* UNIT COULD BE AMBIGUOUS */ 915640Sroot ifp->if_unit = ui->ui_unit; 925640Sroot ifp->if_name = "imp"; 936271Sroot ifp->if_mtu = IMPMTU - sizeof(struct imp_leader); 945640Sroot ifp->if_net = ui->ui_flags; 959001Sroot ifp->if_reset = reset; 965989Sroot /* the host and imp fields will be filled in by the imp */ 976336Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 986336Ssam sin->sin_family = AF_INET; 996336Ssam sin->sin_addr = if_makeaddr(ifp->if_net, 0); 1005771Swnj ifp->if_init = impinit; 1015771Swnj ifp->if_output = impoutput; 1025771Swnj /* reset is handled at the hardware level */ 1035640Sroot if_attach(ifp); 1045640Sroot return ((int)&sc->imp_if); 1055640Sroot } 1065640Sroot 1075640Sroot /* 1085640Sroot * IMP initialization routine: call hardware module to 1095640Sroot * setup UNIBUS resources, init state and get ready for 1105640Sroot * NOOPs the IMP should send us, and that we want to drop. 1115640Sroot */ 1125640Sroot impinit(unit) 1135640Sroot int unit; 1145640Sroot { 1156500Ssam int s = splimp(); 1165640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1175640Sroot 1185771Swnj if ((*sc->imp_cb.ic_init)(unit) == 0) { 1195771Swnj sc->imp_state = IMPS_DOWN; 1206336Ssam sc->imp_if.if_flags &= ~IFF_UP; 1216500Ssam splx(s); 1225771Swnj return; 1235771Swnj } 1245640Sroot sc->imp_state = IMPS_INIT; 1255771Swnj impnoops(sc); 1266500Ssam splx(s); 1275640Sroot } 1285640Sroot 1295640Sroot struct sockproto impproto = { PF_IMPLINK }; 1305645Ssam struct sockaddr_in impdst = { AF_IMPLINK }; 1315645Ssam struct sockaddr_in impsrc = { AF_IMPLINK }; 1327199Ssam #ifdef IMPLEADERS 1337170Ssam int impprintfs = 0; 1347199Ssam #endif 1355640Sroot 1365640Sroot /* 1375640Sroot * ARPAnet 1822 input routine. 1385640Sroot * Called from hardware input interrupt routine to handle 1822 1395640Sroot * IMP-host messages. Type 0 messages (non-control) are 1405640Sroot * passed to higher level protocol processors on the basis 1415640Sroot * of link number. Other type messages (control) are handled here. 1425640Sroot */ 1435771Swnj impinput(unit, m) 1445640Sroot int unit; 1455771Swnj register struct mbuf *m; 1465640Sroot { 1475640Sroot register struct imp_leader *ip; 1485640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1495640Sroot register struct host *hp; 1505640Sroot register struct ifqueue *inq; 1515771Swnj struct control_leader *cp; 1525640Sroot struct in_addr addr; 1535924Sroot struct mbuf *next; 1546336Ssam struct sockaddr_in *sin; 1555640Sroot 1566257Sroot /* verify leader length. */ 1575771Swnj if (m->m_len < sizeof(struct control_leader) && 1585771Swnj (m = m_pullup(m, sizeof(struct control_leader))) == 0) 1595771Swnj return; 1605771Swnj cp = mtod(m, struct control_leader *); 1615771Swnj if (cp->dl_mtype == IMPTYPE_DATA) 1625771Swnj if (m->m_len < sizeof(struct imp_leader) && 1635771Swnj (m = m_pullup(m, sizeof(struct imp_leader))) == 0) 1645771Swnj return; 1655640Sroot ip = mtod(m, struct imp_leader *); 1667199Ssam #ifdef IMPLEADERS 1677170Ssam if (impprintfs) 1687170Ssam printleader("impinput", ip); 1697199Ssam #endif 1705640Sroot 1716257Sroot /* check leader type */ 1725771Swnj if (ip->il_format != IMP_NFF) { 1735771Swnj sc->imp_if.if_collisions++; /* XXX */ 1745640Sroot goto drop; 1755771Swnj } 1765640Sroot 1776588Ssam if (ip->il_mtype != IMPTYPE_DATA) { 1785859Sroot #ifdef notdef 1795771Swnj addr.s_net = ip->il_network; 1805859Sroot #else 1816588Ssam addr.s_net = sc->imp_if.if_net; 1825859Sroot #endif 1835771Swnj addr.s_imp = ip->il_imp; 1845771Swnj addr.s_host = ip->il_host; 1855640Sroot } 1865640Sroot switch (ip->il_mtype) { 1875640Sroot 1885640Sroot case IMPTYPE_DATA: 1895640Sroot break; 1905640Sroot 1915640Sroot /* 1925640Sroot * IMP leader error. Reset the IMP and discard the packet. 1935640Sroot */ 1945640Sroot case IMPTYPE_BADLEADER: 1955647Ssam /* 1965647Ssam * According to 1822 document, this message 1975647Ssam * will be generated in response to the 1985647Ssam * first noop sent to the IMP after 1995647Ssam * the host resets the IMP interface. 2005647Ssam */ 2015771Swnj if (sc->imp_state != IMPS_INIT) { 2025924Sroot impmsg(sc, "leader error"); 2036582Ssam hostreset(sc->imp_if.if_net); 2045647Ssam impnoops(sc); 2055647Ssam } 2066582Ssam goto drop; 2075640Sroot 2085640Sroot /* 2095640Sroot * IMP going down. Print message, and if not immediate, 2105640Sroot * set off a timer to insure things will be reset at the 2115640Sroot * appropriate time. 2125640Sroot */ 2135640Sroot case IMPTYPE_DOWN: 2146599Ssam if (sc->imp_state < IMPS_INIT) 2156598Ssam goto drop; 2165640Sroot if ((ip->il_link & IMP_DMASK) == 0) { 2175640Sroot sc->imp_state = IMPS_GOINGDOWN; 2186160Ssam timeout(impdown, (caddr_t)sc, 30 * hz); 2195640Sroot } 2206160Ssam impmsg(sc, "going down %s", 2216160Ssam (u_int)impmessage[ip->il_link&IMP_DMASK]); 2226582Ssam goto drop; 2235640Sroot 2245640Sroot /* 2255640Sroot * A NOP usually seen during the initialization sequence. 2265640Sroot * Compare the local address with that in the message. 2275640Sroot * Reset the local address notion if it doesn't match. 2285640Sroot */ 2296336Ssam case IMPTYPE_NOOP: 2305647Ssam if (sc->imp_state == IMPS_DOWN) { 2315647Ssam sc->imp_state = IMPS_INIT; 2325647Ssam sc->imp_dropcnt = IMP_DROPCNT; 2335647Ssam } 2346500Ssam if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0) 2356271Sroot goto drop; 2366500Ssam sin = (struct sockaddr_in *)&sc->imp_if.if_addr; 2376500Ssam if (sin->sin_addr.s_host != ip->il_host || 2386500Ssam sin->sin_addr.s_imp != ip->il_imp) { 2396500Ssam sc->imp_if.if_host[0] = 2406500Ssam sin->sin_addr.s_host = ip->il_host; 2416500Ssam sin->sin_addr.s_imp = ip->il_imp; 2426500Ssam impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host, 2436500Ssam ntohs(ip->il_imp)); 2446500Ssam } 2455771Swnj sc->imp_state = IMPS_UP; 2466336Ssam sc->imp_if.if_flags |= IFF_UP; 2477201Ssam if_rtinit(&sc->imp_if, RTF_UP); 2486271Sroot goto drop; 2495640Sroot 2505640Sroot /* 2516582Ssam * RFNM or INCOMPLETE message, send next 2526582Ssam * message on the q. We could pass incomplete's 2536582Ssam * up to the next level, but this currently isn't 2546582Ssam * needed. 2555640Sroot */ 2565640Sroot case IMPTYPE_RFNM: 2575640Sroot case IMPTYPE_INCOMPLETE: 2586588Ssam if (hp = hostlookup(addr)) { 2596588Ssam if (hp->h_rfnm == 0) 2606588Ssam hp->h_flags &= ~HF_INUSE; 2616588Ssam else if (next = hostdeque(hp)) 2626588Ssam (void) impsnd(&sc->imp_if, next); 2636588Ssam } 2646271Sroot goto drop; 2655640Sroot 2665640Sroot /* 2675640Sroot * Host or IMP can't be reached. Flush any packets 2685640Sroot * awaiting transmission and release the host structure. 2695640Sroot */ 2705640Sroot case IMPTYPE_HOSTDEAD: 2716588Ssam case IMPTYPE_HOSTUNREACH: { 2726588Ssam int s = splnet(); 2738705Sroot impnotify((int)ip->il_mtype, (struct control_leader *)ip, 2748705Sroot hostlookup(addr)); 2756588Ssam splx(s); 2765859Sroot goto rawlinkin; 2776588Ssam } 2785640Sroot 2795640Sroot /* 2805640Sroot * Error in data. Clear RFNM status for this host and send 2815640Sroot * noops to the IMP to clear the interface. 2825640Sroot */ 2836588Ssam case IMPTYPE_BADDATA: { 2846588Ssam int s; 2856588Ssam 2865924Sroot impmsg(sc, "data error"); 2876588Ssam s = splnet(); 2886588Ssam if (hp = hostlookup(addr)) 2895640Sroot hp->h_rfnm = 0; 2906588Ssam splx(s); 2915640Sroot impnoops(sc); 2926582Ssam goto drop; 2936588Ssam } 2945640Sroot 2955640Sroot /* 2965647Ssam * Interface reset. 2975640Sroot */ 2985640Sroot case IMPTYPE_RESET: 2995924Sroot impmsg(sc, "interface reset"); 3005647Ssam impnoops(sc); 3016582Ssam goto drop; 3025640Sroot 3035640Sroot default: 3045640Sroot sc->imp_if.if_collisions++; /* XXX */ 3056582Ssam goto drop; 3065640Sroot } 3075640Sroot 3085640Sroot /* 3096257Sroot * Data for a protocol. Dispatch to the appropriate 3106257Sroot * protocol routine (running at software interrupt). 3116257Sroot * If this isn't a raw interface, advance pointer 3126257Sroot * into mbuf past leader. 3135640Sroot */ 3145640Sroot switch (ip->il_link) { 3155640Sroot 3165640Sroot #ifdef INET 3175640Sroot case IMPLINK_IP: 3185640Sroot m->m_len -= sizeof(struct imp_leader); 3195640Sroot m->m_off += sizeof(struct imp_leader); 3206261Swnj schednetisr(NETISR_IP); 3215640Sroot inq = &ipintrq; 3225640Sroot break; 3235640Sroot #endif 3245640Sroot 3255640Sroot default: 3265868Sroot rawlinkin: 3275640Sroot impproto.sp_protocol = ip->il_link; 3286336Ssam sin = (struct sockaddr_in *)&sc->imp_if.if_addr; 3296336Ssam impdst.sin_addr = sin->sin_addr;; 3305645Ssam impsrc.sin_addr.s_net = ip->il_network; 3315645Ssam impsrc.sin_addr.s_host = ip->il_host; 3325645Ssam impsrc.sin_addr.s_imp = ip->il_imp; 3336527Ssam raw_input(m, &impproto, (struct sockaddr *)&impsrc, 3346527Ssam (struct sockaddr *)&impdst); 3355640Sroot return; 3365640Sroot } 3376208Swnj if (IF_QFULL(inq)) { 3386208Swnj IF_DROP(inq); 3396208Swnj goto drop; 3406208Swnj } 3415640Sroot IF_ENQUEUE(inq, m); 3425640Sroot return; 3435640Sroot 3445640Sroot drop: 3455640Sroot m_freem(m); 3465640Sroot } 3475640Sroot 3485647Ssam /* 3495647Ssam * Bring the IMP down after notification. 3505647Ssam */ 3515647Ssam impdown(sc) 3525647Ssam struct imp_softc *sc; 3535647Ssam { 3546208Swnj 3555647Ssam sc->imp_state = IMPS_DOWN; 3565924Sroot impmsg(sc, "marked down"); 3576588Ssam hostreset(sc->imp_if.if_net); 3586582Ssam if_down(&sc->imp_if); 3595647Ssam } 3605647Ssam 3615640Sroot /*VARARGS*/ 3625924Sroot impmsg(sc, fmt, a1, a2) 3635640Sroot struct imp_softc *sc; 3645640Sroot char *fmt; 3656160Ssam u_int a1; 3665640Sroot { 3676208Swnj 3685640Sroot printf("imp%d: ", sc->imp_if.if_unit); 3695640Sroot printf(fmt, a1, a2); 3705640Sroot printf("\n"); 3715640Sroot } 3725640Sroot 3735640Sroot /* 3746582Ssam * Process an IMP "error" message, passing this 3756582Ssam * up to the higher level protocol. 3766582Ssam */ 3776582Ssam impnotify(what, cp, hp) 3786582Ssam int what; 3796582Ssam struct control_leader *cp; 3806582Ssam struct host *hp; 3816582Ssam { 3826582Ssam struct in_addr in; 3836582Ssam 3846582Ssam #ifdef notdef 3856582Ssam in.s_net = cp->dl_network; 3866582Ssam #else 3876588Ssam in.s_net = 10; /* XXX */ 3886582Ssam #endif 3896582Ssam in.s_host = cp->dl_host; 3906582Ssam in.s_imp = cp->dl_imp; 3916582Ssam if (cp->dl_link != IMPLINK_IP) 3926582Ssam raw_ctlinput(what, (caddr_t)&in); 3936582Ssam else 3946582Ssam ip_ctlinput(what, (caddr_t)&in); 3956588Ssam if (hp) { 3966588Ssam hp->h_flags |= (1 << what); 3976582Ssam hostfree(hp); 3986588Ssam } 3996582Ssam } 4006582Ssam 4016582Ssam /* 4025640Sroot * ARPAnet 1822 output routine. 4035640Sroot * Called from higher level protocol routines to set up messages for 4045640Sroot * transmission to the imp. Sets up the header and calls impsnd to 4055640Sroot * enqueue the message for this IMP's hardware driver. 4065640Sroot */ 4076336Ssam impoutput(ifp, m0, dst) 4085640Sroot register struct ifnet *ifp; 4095640Sroot struct mbuf *m0; 4106336Ssam struct sockaddr *dst; 4115640Sroot { 4125640Sroot register struct imp_leader *imp; 4135640Sroot register struct mbuf *m = m0; 4148782Sroot int dhost, dimp, dlink, len, dnet; 4156504Ssam int error = 0; 4165640Sroot 4175640Sroot /* 4185640Sroot * Don't even try if the IMP is unavailable. 4195640Sroot */ 4206504Ssam if (imp_softc[ifp->if_unit].imp_state != IMPS_UP) { 4216504Ssam error = ENETDOWN; 4225647Ssam goto drop; 4236504Ssam } 4245640Sroot 4256336Ssam switch (dst->sa_family) { 4265640Sroot 4275640Sroot #ifdef INET 4286336Ssam case AF_INET: { 4296336Ssam struct ip *ip = mtod(m0, struct ip *); 4306336Ssam struct sockaddr_in *sin = (struct sockaddr_in *)dst; 4315640Sroot 4326336Ssam dhost = sin->sin_addr.s_host; 4336336Ssam dimp = sin->sin_addr.s_impno; 4345640Sroot dlink = IMPLINK_IP; 4356244Sroot dnet = 0; 4366160Ssam len = ntohs((u_short)ip->ip_len); 4375640Sroot break; 4385640Sroot } 4395640Sroot #endif 4406336Ssam case AF_IMPLINK: 4415640Sroot goto leaderexists; 4425640Sroot 4435640Sroot default: 4446336Ssam printf("imp%d: can't handle af%d\n", ifp->if_unit, 4456336Ssam dst->sa_family); 4466504Ssam error = EAFNOSUPPORT; 4475647Ssam goto drop; 4485640Sroot } 4495640Sroot 4505640Sroot /* 4515640Sroot * Add IMP leader. If there's not enough space in the 4525640Sroot * first mbuf, allocate another. If that should fail, we 4535640Sroot * drop this sucker. 4545640Sroot */ 4555640Sroot if (m->m_off > MMAXOFF || 4565640Sroot MMINOFF + sizeof(struct imp_leader) > m->m_off) { 4579645Ssam m = m_get(M_DONTWAIT, MT_HEADER); 4586504Ssam if (m == 0) { 4596504Ssam error = ENOBUFS; 4605647Ssam goto drop; 4616504Ssam } 4625640Sroot m->m_next = m0; 4635640Sroot m->m_len = sizeof(struct imp_leader); 4645640Sroot } else { 4655640Sroot m->m_off -= sizeof(struct imp_leader); 4665640Sroot m->m_len += sizeof(struct imp_leader); 4675640Sroot } 4685640Sroot imp = mtod(m, struct imp_leader *); 4695640Sroot imp->il_format = IMP_NFF; 4705859Sroot imp->il_mtype = IMPTYPE_DATA; 4716244Sroot imp->il_network = dnet; 4725640Sroot imp->il_host = dhost; 4736244Sroot imp->il_imp = htons((u_short)dimp); 4746160Ssam imp->il_length = 4756160Ssam htons((u_short)(len + sizeof(struct imp_leader)) << 3); 4765640Sroot imp->il_link = dlink; 4775859Sroot imp->il_flags = imp->il_htype = imp->il_subtype = 0; 4785640Sroot 4795640Sroot leaderexists: 4805640Sroot return (impsnd(ifp, m)); 4815647Ssam drop: 4825647Ssam m_freem(m0); 4836504Ssam return (error); 4845640Sroot } 4855640Sroot 4865640Sroot /* 4875640Sroot * Put a message on an interface's output queue. 4885640Sroot * Perform RFNM counting: no more than 8 message may be 4895640Sroot * in flight to any one host. 4905640Sroot */ 4915640Sroot impsnd(ifp, m) 4925640Sroot struct ifnet *ifp; 4935640Sroot struct mbuf *m; 4945640Sroot { 4955640Sroot register struct imp_leader *ip; 4965640Sroot register struct host *hp; 4975640Sroot struct impcb *icp; 4986588Ssam int s, error; 4995640Sroot 5005640Sroot ip = mtod(m, struct imp_leader *); 5015640Sroot 5025640Sroot /* 5035640Sroot * Do RFNM counting for data messages 5045640Sroot * (no more than 8 outstanding to any host) 5055640Sroot */ 5066588Ssam s = splimp(); 5075640Sroot if (ip->il_mtype == IMPTYPE_DATA) { 5085640Sroot struct in_addr addr; 5095640Sroot 5105859Sroot #ifdef notdef 5115771Swnj addr.s_net = ip->il_network; 5125859Sroot #else 5136588Ssam addr.s_net = ifp->if_net; /* XXX */ 5145859Sroot #endif 5155640Sroot addr.s_host = ip->il_host; 5165640Sroot addr.s_imp = ip->il_imp; 5175771Swnj if ((hp = hostlookup(addr)) == 0) 5185771Swnj hp = hostenter(addr); 5196588Ssam if (hp && (hp->h_flags & (HF_DEAD|HF_UNREACH))) { 5206607Ssam error = hp->h_flags&HF_DEAD ? EHOSTDOWN : EHOSTUNREACH; 5216588Ssam hp->h_timer = HOSTTIMER; 5226588Ssam hp->h_flags &= ~HF_INUSE; 5236588Ssam goto bad; 5246588Ssam } 5255640Sroot 5265640Sroot /* 5275647Ssam * If IMP would block, queue until RFNM 5285640Sroot */ 5295640Sroot if (hp) { 5305640Sroot if (hp->h_rfnm < 8) { 5315640Sroot hp->h_rfnm++; 5325640Sroot goto enque; 5335640Sroot } 5346095Swnj if (hp->h_qcnt < 8) { /* high water mark */ 5356095Swnj HOST_ENQUE(hp, m); 5366095Swnj goto start; 5376095Swnj } 5385640Sroot } 5396588Ssam error = ENOBUFS; 5406588Ssam goto bad; 5415640Sroot } 5425640Sroot enque: 5436208Swnj if (IF_QFULL(&ifp->if_snd)) { 5446208Swnj IF_DROP(&ifp->if_snd); 5456588Ssam error = ENOBUFS; 5466588Ssam bad: 5476208Swnj m_freem(m); 5486588Ssam splx(s); 5496588Ssam return (error); 5506208Swnj } 5515640Sroot IF_ENQUEUE(&ifp->if_snd, m); 5526095Swnj start: 5535640Sroot icp = &imp_softc[ifp->if_unit].imp_cb; 5545640Sroot if (icp->ic_oactive == 0) 5555640Sroot (*icp->ic_start)(ifp->if_unit); 5566630Ssam splx(s); 5576504Ssam return (0); 5585640Sroot } 5595640Sroot 5605640Sroot /* 5615640Sroot * Put three 1822 NOOPs at the head of the output queue. 5625640Sroot * Part of host-IMP initialization procedure. 5635640Sroot * (Should return success/failure, but noone knows 5645640Sroot * what to do with this, so why bother?) 5656818Ssam * This routine is always called at splimp, so we don't 5666818Ssam * protect the call to IF_PREPEND. 5675640Sroot */ 5685640Sroot impnoops(sc) 5695640Sroot register struct imp_softc *sc; 5705640Sroot { 5715640Sroot register i; 5725640Sroot register struct mbuf *m; 5735771Swnj register struct control_leader *cp; 5745640Sroot 5755640Sroot sc->imp_dropcnt = IMP_DROPCNT; 5765771Swnj for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 5779645Ssam if ((m = m_getclr(M_DONTWAIT, MT_HEADER)) == 0) 5785640Sroot return; 5795771Swnj m->m_len = sizeof(struct control_leader); 5805771Swnj cp = mtod(m, struct control_leader *); 5815771Swnj cp->dl_format = IMP_NFF; 5825771Swnj cp->dl_link = i; 5835771Swnj cp->dl_mtype = IMPTYPE_NOOP; 5845640Sroot IF_PREPEND(&sc->imp_if.if_snd, m); 5855640Sroot } 5865640Sroot if (sc->imp_cb.ic_oactive == 0) 5875640Sroot (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 5885640Sroot } 5897170Ssam 5907170Ssam #ifdef IMPLEADERS 5917170Ssam printleader(routine, ip) 5927170Ssam char *routine; 5937170Ssam register struct imp_leader *ip; 5947170Ssam { 5957170Ssam printf("%s: ", routine); 5967170Ssam printbyte((char *)ip, 12); 5977170Ssam printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, 5987170Ssam ip->il_flags); 5997170Ssam if (ip->il_mtype <= IMPTYPE_READY) 6007170Ssam printf("%s,", impleaders[ip->il_mtype]); 6017170Ssam else 6027170Ssam printf("%x,", ip->il_mtype); 6037170Ssam printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, 6047170Ssam ntohs(ip->il_imp)); 6057170Ssam if (ip->il_link == IMPLINK_IP) 6067170Ssam printf("ip,"); 6077170Ssam else 6087170Ssam printf("%x,", ip->il_link); 6097170Ssam printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); 6107170Ssam } 6117170Ssam 6127170Ssam printbyte(cp, n) 6137170Ssam register char *cp; 6147170Ssam int n; 6157170Ssam { 6167170Ssam register i, j, c; 6177170Ssam 6187170Ssam for (i=0; i<n; i++) { 6197170Ssam c = *cp++; 6207170Ssam for (j=0; j<2; j++) 6217170Ssam putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); 6227170Ssam putchar(' '); 6237170Ssam } 6247170Ssam putchar('\n'); 6257170Ssam } 6265640Sroot #endif 6277170Ssam #endif 628