From 41e530c7d69947b646c185b37dc39cdac4d834ea Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Tue, 16 Feb 1982 23:11:57 -0800 Subject: [PATCH] first "working" imp driver SCCS-vsn: sys/vax/if/if_acc.c 4.4 SCCS-vsn: sys/deprecated/netimp/if_imp.c 4.5 SCCS-vsn: sys/deprecated/netimp/if_imphost.c 4.3 SCCS-vsn: sys/deprecated/netimp/if_imphost.h 4.3 --- usr/src/sys/deprecated/netimp/if_imp.c | 37 +++++---- usr/src/sys/deprecated/netimp/if_imphost.c | 96 ++++++++++------------ usr/src/sys/deprecated/netimp/if_imphost.h | 4 +- usr/src/sys/vax/if/if_acc.c | 14 +--- 4 files changed, 69 insertions(+), 82 deletions(-) diff --git a/usr/src/sys/deprecated/netimp/if_imp.c b/usr/src/sys/deprecated/netimp/if_imp.c index 1fafca9d83..af09392017 100644 --- a/usr/src/sys/deprecated/netimp/if_imp.c +++ b/usr/src/sys/deprecated/netimp/if_imp.c @@ -1,4 +1,4 @@ -/* if_imp.c 4.4 82/02/12 */ +/* if_imp.c 4.5 82/02/16 */ #include "imp.h" #if NIMP > 0 @@ -11,7 +11,6 @@ * TODO: * rethink coupling between this module and device driver * pass more error indications up to protocol modules - * test raw imp interface */ #include "../h/param.h" #include "../h/systm.h" @@ -28,9 +27,8 @@ #include "../net/in.h" #include "../net/in_systm.h" #include "../net/if.h" -#define IMPLEADERS #include "../net/if_imp.h" -#include "../net/host.h" +#include "../net/if_imphost.h" #include "../net/ip.h" #include "../net/ip_var.h" @@ -143,8 +141,6 @@ impinput(unit, m) struct in_addr addr; COUNT(IMP_INPUT); -printf("impinput(%d, %x), len=%d\n", unit, m, m->m_len); -printleader("impinput", mtod(m, struct imp_leader *)); /* * Verify leader length. Be careful with control * message which don't get a length included. @@ -181,7 +177,11 @@ printleader("impinput", mtod(m, struct imp_leader *)); case IMPTYPE_HOSTDEAD: case IMPTYPE_HOSTUNREACH: case IMPTYPE_BADDATA: +#ifdef notdef addr.s_net = ip->il_network; +#else + addr.s_net = 0; +#endif addr.s_imp = ip->il_imp; addr.s_host = ip->il_host; hp = hostlookup(addr); @@ -284,7 +284,7 @@ printleader("impinput", mtod(m, struct imp_leader *)); if (hp->h_rfnm == 0) hostfree(hp); } - break; + goto rawlinkin; /* * Host or IMP can't be reached. Flush any packets @@ -302,7 +302,7 @@ printleader("impinput", mtod(m, struct imp_leader *)); common: if (hp) hostfree(hp); /* won't work right */ - break; + goto rawlinkin; /* * Error in data. Clear RFNM status for this host and send @@ -313,7 +313,7 @@ printleader("impinput", mtod(m, struct imp_leader *)); if (hp) hp->h_rfnm = 0; impnoops(sc); - break; + goto rawlinkin; /* * Interface reset. @@ -343,6 +343,7 @@ printleader("impinput", mtod(m, struct imp_leader *)); #endif default: +rawlinkin: impproto.sp_protocol = ip->il_link; impdst.sin_addr = sc->imp_if.if_addr; impsrc.sin_addr.s_net = ip->il_network; @@ -394,8 +395,6 @@ impoutput(ifp, m0, pf) int x, dhost, dimp, dlink, len, dnet; COUNT(IMPOUTPUT); -printf("impoutput(%x, %x, %x)\n", ifp, m0, pf); - #ifdef notdef /* * Don't even try if the IMP is unavailable. @@ -416,7 +415,6 @@ printf("impoutput(%x, %x, %x)\n", ifp, m0, pf); dimp = ip->ip_dst.s_imp; dlink = IMPLINK_IP; len = ntohs(ip->ip_len); -printf("impoutput: net=%d,host=%d,imp=%d,len=%d\n",dnet,dhost,dimp,len); break; } #endif @@ -447,11 +445,13 @@ printf("impoutput: net=%d,host=%d,imp=%d,len=%d\n",dnet,dhost,dimp,len); } imp = mtod(m, struct imp_leader *); imp->il_format = IMP_NFF; + imp->il_mtype = IMPTYPE_DATA; imp->il_network = dnet; imp->il_host = dhost; imp->il_imp = dimp; imp->il_length = htons((len + sizeof(struct imp_leader)) << 3); imp->il_link = dlink; + imp->il_flags = imp->il_htype = imp->il_subtype = 0; leaderexists: /* @@ -479,7 +479,6 @@ impsnd(ifp, m) int x; COUNT(IMPSND); -printf("impsnd(%x, %x)\n", ifp, m); ip = mtod(m, struct imp_leader *); /* @@ -489,9 +488,14 @@ printf("impsnd(%x, %x)\n", ifp, m); if (ip->il_mtype == IMPTYPE_DATA) { struct in_addr addr; +#ifdef notdef addr.s_net = ip->il_network; +#else + addr.s_net = 0; +#endif addr.s_host = ip->il_host; addr.s_imp = ip->il_imp; + x = splimp(); if ((hp = hostlookup(addr)) == 0) hp = hostenter(addr); @@ -504,6 +508,7 @@ printf("impsnd(%x, %x)\n", ifp, m); if (hp->h_rfnm < 8) { hp->h_rfnm++; + splx(x); goto enque; } /* @@ -527,14 +532,15 @@ printf("impsnd(%x, %x)\n", ifp, m); m->m_next = n->m_next; hp->h_q = n->m_next = m; } + splx(x); goto start; } drop: m_freem(m); + splx(x); return (0); } enque: -printleader("impsnd", mtod(m, struct imp_leader *)); x = splimp(); IF_ENQUEUE(&ifp->if_snd, m); splx(x); @@ -577,7 +583,6 @@ COUNT(IMPNOOPS); cp->dl_host = sc->imp_if.if_addr.s_host;/* XXX */ cp->dl_imp = sc->imp_if.if_addr.s_imp; /* XXX */ #endif -printleader("impnoops", cp); x = splimp(); IF_PREPEND(&sc->imp_if.if_snd, m); splx(x); @@ -586,6 +591,7 @@ printleader("impnoops", cp); (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); } +#ifdef IMPLEADERS printleader(routine, ip) char *routine; register struct imp_leader *ip; @@ -622,3 +628,4 @@ printbyte(cp, n) putchar('\n'); } #endif +#endif diff --git a/usr/src/sys/deprecated/netimp/if_imphost.c b/usr/src/sys/deprecated/netimp/if_imphost.c index 6231182ab7..374aecafaa 100644 --- a/usr/src/sys/deprecated/netimp/if_imphost.c +++ b/usr/src/sys/deprecated/netimp/if_imphost.c @@ -1,4 +1,4 @@ -/* if_imphost.c 4.2 82/02/12 */ +/* if_imphost.c 4.3 82/02/16 */ #include "imp.h" #if NIMP > 0 @@ -11,13 +11,13 @@ #include "../h/mbuf.h" #include "../net/in.h" #include "../net/in_systm.h" -#include "../net/host.h" #include "../net/if_imp.h" +#include "../net/if_imphost.h" /* * Head of host table hash chains. */ -struct mbuf hosttable = { 0, MMINOFF }; +struct mbuf *hosts; /* * Given an internet address @@ -32,12 +32,10 @@ hostlookup(addr) register int hash = HOSTHASH(addr); COUNT(HOSTLOOKUP); -printf("hostlookup(%x)\n", addr); - for (m = &hosttable; m; m = m->m_next) { + for (m = hosts; m; m = m->m_next) { hp = &mtod(m, struct hmbuf *)->hm_hosts[hash]; if (hp->h_refcnt == 0) - break; -printf("hostlookup: addr=%x\n", hp->h_addr.s_addr); + continue; if (hp->h_addr.s_addr == addr.s_addr) return (hp); } @@ -53,19 +51,22 @@ struct host * hostenter(addr) struct in_addr addr; { - register struct mbuf *m, *mprev; - register struct host *hp; + register struct mbuf *m, **mprev; + register struct host *hp, *hp0 = 0; register int hash = HOSTHASH(addr); COUNT(HOSTENTER); -printf("hostenter(%x)\n", addr); - for (m = &hosttable; m; mprev = m, m = m->m_next) { + mprev = &hosts; + while (m = *mprev) { hp = &mtod(m, struct hmbuf *)->hm_hosts[hash]; - if (hp->h_refcnt == 0) - break; -printf("hostenter: addr=%x\n", addr); + if (hp->h_refcnt == 0) { + if (hp0 == 0) + hp0 = hp; + continue; + } if (hp->h_addr.s_addr == addr.s_addr) goto foundhost; + mprev = &m->m_next; } /* @@ -73,16 +74,16 @@ printf("hostenter: addr=%x\n", addr); * If our search ran off the end of the * chain of mbuf's, allocate another. */ -printf("hostenter: new host\n"); - if (m == 0) { + if (hp0 == 0) { m = m_getclr(M_DONTWAIT); if (m == 0) return (0); - mprev->m_next = m; - m->m_act = mprev; - hp = &mtod(m, struct hmbuf *)->hm_hosts[hash]; + *mprev = m; + m->m_off = MMINOFF; + hp0 = &mtod(m, struct hmbuf *)->hm_hosts[hash]; } - mtod(m, struct hmbuf *)->hm_count++; + mtod(dtom(hp0), struct hmbuf *)->hm_count++; + hp = hp0; hp->h_addr = addr; hp->h_status = HOSTS_UP; @@ -95,26 +96,15 @@ foundhost: * Free a reference to a host. If this causes the * host structure to be released do so. */ -hostfree(addr) - struct in_addr addr; +hostfree(hp) + register struct host *hp; { register struct mbuf *m; - register struct host *hp; - register int hash = HOSTHASH(addr); COUNT(HOSTFREE); -printf("hostfree(%x)\n", addr); - for (m = &hosttable; m; m = m->m_next) { - hp = &mtod(m, struct hmbuf *)->hm_hosts[hash]; - if (hp->h_refcnt == 0) - return; - if (hp->h_addr.s_addr == addr.s_addr) { - if (--hp->h_refcnt == 0) - hostrelease(mtod(m, struct hmbuf *), hp); - return; - } - } - panic("hostfree"); + if (--hp->h_refcnt) + return; + hostrelease(hp); } /* @@ -127,32 +117,34 @@ hostreset(net) { register struct mbuf *m; register struct host *hp, *lp; + struct hmbuf *hm; + int x; COUNT(HOSTRESET); -printf("hostreset(%x)\n", net); - for (m = &hosttable; m; m = m->m_next) { - hp = mtod(m, struct hmbuf *)->hm_hosts; + x = splimp(); + for (m = hosts; m; m = m->m_next) { + hm = mtod(m, struct hmbuf *); + hp = hm->hm_hosts; lp = hp + HPMBUF; - while (hp < lp) { + while (hm->hm_count != 0 && hp < lp) { if (hp->h_addr.s_net == net) hostrelease(mtod(m, struct hmbuf *), hp); hp++; } } + splx(x); } /* * Remove a host structure and release * any resources it's accumulated. */ -hostrelease(hm, hp) - struct hmbuf *hm; +hostrelease(hp) register struct host *hp; { - register struct mbuf *m; + register struct mbuf *m, **mprev, *mh = dtom(hp); COUNT(HOSTRELEASE); -printf("hostrelease(%x,%x)\n", hm, hp); /* * Discard any packets left on the waiting q */ @@ -162,15 +154,11 @@ printf("hostrelease(%x,%x)\n", hm, hp); hp->h_q = 0; m_freem(m); } - /* - * We could compact the database here, but is - * it worth it? For now we assume not and just - * handle the simple case. - */ -printf("hostrelease: count=%d\n", hm->hm_count); - if (--hm->hm_count || (m = dtom(hm)) == &hosttable) + if (--mtod(mh, struct hmbuf *)->hm_count) return; - m->m_act->m_next = m->m_next; - m->m_next->m_act = m->m_act; - (void) m_free(m); + mprev = &hosts; + while ((m = *mprev) != mh) + mprev = &m->m_next; + *mprev = mh->m_next; + (void) m_free(mh); } diff --git a/usr/src/sys/deprecated/netimp/if_imphost.h b/usr/src/sys/deprecated/netimp/if_imphost.h index b97d1f6cd3..b8ca39eb2f 100644 --- a/usr/src/sys/deprecated/netimp/if_imphost.h +++ b/usr/src/sys/deprecated/netimp/if_imphost.h @@ -1,4 +1,4 @@ -/* if_imphost.h 4.2 82/02/12 */ +/* if_imphost.h 4.3 82/02/16 */ /* * Host structure used with IMP's. @@ -28,7 +28,7 @@ struct host { * automatically at the time a structure is free'd. */ #define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host)) -#define HOSTHASH(a) ((a.s_addr) % HPMBUF) +#define HOSTHASH(a) (((a).s_addr&~0x80000000) % HPMBUF) struct hmbuf { int hm_count; /* # of struct's in use */ diff --git a/usr/src/sys/vax/if/if_acc.c b/usr/src/sys/vax/if/if_acc.c index ab84f9fa1b..760242b05d 100644 --- a/usr/src/sys/vax/if/if_acc.c +++ b/usr/src/sys/vax/if/if_acc.c @@ -1,4 +1,4 @@ -/* if_acc.c 4.3 82/02/12 */ +/* if_acc.c 4.4 82/02/16 */ #include "acc.h" #ifdef NACC > 0 @@ -231,7 +231,6 @@ accstart(dev) u_short cmd; COUNT(ACCSTART); -printf("accstart: active=%d\n", sc->acc_ic->ic_oactive); if (sc->acc_ic->ic_oactive) goto restart; @@ -241,13 +240,11 @@ printf("accstart: active=%d\n", sc->acc_ic->ic_oactive); * requeusts, just return. */ IF_DEQUEUE(&sc->acc_if->if_snd, m); -printf("accstart: dequeue m=%x\n", m); if (m == 0) { sc->acc_ic->ic_oactive = 0; return; } sc->acc_olen = if_wubaput(&sc->acc_ifuba, m); -printf("accstart: olen=%d\n", sc->acc_olen); restart: /* @@ -283,7 +280,6 @@ COUNT(ACCXINT); return; } addr = (struct accdevice *)ui->ui_addr; -printf("accxint: ocsr=%b\n", addr->ocsr, ACC_OUTBITS); sc->acc_if->if_opackets++; sc->acc_ic->ic_oactive = 0; if (addr->ocsr & ACC_ERR) { @@ -295,9 +291,8 @@ printf("accxint: ocsr=%b\n", addr->ocsr, ACC_OUTBITS); m_freem(sc->acc_ifuba.ifu_xtofree); sc->acc_ifuba.ifu_xtofree = 0; } - if (sc->acc_if->if_snd.ifq_head == 0) - return; - accstart(unit); + if (sc->acc_if->if_snd.ifq_head) + accstart(unit); } /* @@ -320,7 +315,6 @@ COUNT(ACCRINT); if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP) UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp); addr = (struct accdevice *)accinfo[unit]->ui_addr; -printf("accrint: icsr=%b, flush=%d\n", addr->icsr, ACC_INBITS, sc->acc_flush); if (addr->icsr & ACC_ERR) { printf("acc%d: input error, csr=%b\n", unit, addr->icsr, ACC_INBITS); @@ -334,7 +328,6 @@ printf("accrint: icsr=%b, flush=%d\n", addr->icsr, ACC_INBITS, sc->acc_flush); goto setup; } len = IMP_MTU + (addr->iwc << 1); -printf("accrint: len=%d\n", len); if (len < 0 || len > IMP_MTU) { printf("acc%d: bad length=%d\n", len); sc->acc_if->if_ierrors++; @@ -346,7 +339,6 @@ printf("accrint: len=%d\n", len); * trailers on the ARPAnet is insane. */ m = if_rubaget(&sc->acc_ifuba, len, 0); -printf("accrint: m=%x\n", m); if (m == 0) goto setup; if ((addr->icsr & IN_EOM) == 0) { -- 2.20.1