version with printing crud
[unix-history] / usr / src / sys / vax / if / if_en.c
index 9048145..dd48f0a 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_en.c 4.15    81/11/29        */
+/*     if_en.c 4.18    81/12/09        */
 
 #include "en.h"
 
 
 #include "en.h"
 
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 
-#define        ENMTU   1024
+#define        ENMTU   (1024+512)
 
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
 struct uba_driver endriver =
 
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
 struct uba_driver endriver =
-       { enprobe, 0, enattach, 0, enstd, "es", eninfo };
+       { enprobe, 0, enattach, 0, enstd, "en", eninfo };
 #define        ENUNIT(x)       minor(x)
 
 int    eninit(),enoutput(),enreset();
 #define        ENUNIT(x)       minor(x)
 
 int    eninit(),enoutput(),enreset();
@@ -67,7 +67,7 @@ struct        en_softc {
 enprobe(reg)
        caddr_t reg;
 {
 enprobe(reg)
        caddr_t reg;
 {
-       register int br, cvec;
+       register int br, cvec;          /* r11, r10 value-result */
        register struct endevice *addr = (struct endevice *)reg;
 
 COUNT(ENPROBE);
        register struct endevice *addr = (struct endevice *)reg;
 
 COUNT(ENPROBE);
@@ -96,15 +96,17 @@ enattach(ui)
 COUNT(ENATTACH);
 
        es->es_if.if_unit = ui->ui_unit;
 COUNT(ENATTACH);
 
        es->es_if.if_unit = ui->ui_unit;
+       es->es_if.if_name = "en";
        es->es_if.if_mtu = ENMTU;
        es->es_if.if_net = ui->ui_flags;
        es->es_if.if_host[0] =
        es->es_if.if_mtu = ENMTU;
        es->es_if.if_net = ui->ui_flags;
        es->es_if.if_host[0] =
-           ~(((struct endevice *)eninfo[ui->ui_unit])->en_addr) & 0xff;
+           (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
        es->es_if.if_addr =
            if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
        es->es_if.if_addr =
            if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
-       es->es_if.if_output = enoutput;
        es->es_if.if_init = eninit;
        es->es_if.if_init = eninit;
+       es->es_if.if_output = enoutput;
        es->es_if.if_ubareset = enreset;
        es->es_if.if_ubareset = enreset;
+       if_attach(&es->es_if);
 }
 
 /*
 }
 
 /*
@@ -117,12 +119,10 @@ enreset(unit, uban)
        register struct uba_device *ui;
 COUNT(ENRESET);
 
        register struct uba_device *ui;
 COUNT(ENRESET);
 
-       if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0) {
-               printf("es%d: not alive\n", unit);
-               return;
-       }
-       if (ui->ui_ubanum != uban)
+       if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
+           ui->ui_ubanum != uban)
                return;
                return;
+       printf(" en%d", unit);
        eninit(unit);
 }
 
        eninit(unit);
 }
 
@@ -133,26 +133,28 @@ COUNT(ENRESET);
 eninit(unit)
        int unit;
 {
 eninit(unit)
        int unit;
 {
-       register struct uba_device *ui;
+       register struct en_softc *es = &en_softc[unit];
+       register struct uba_device *ui = eninfo[unit];
        register struct endevice *addr;
        register struct endevice *addr;
-       register struct en_softc *es;
        int s;
 
        int s;
 
-       es = &en_softc[unit];
-       ui = eninfo[unit];
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
            sizeof (struct en_header), (int)btop(ENMTU)) == 0) { 
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
            sizeof (struct en_header), (int)btop(ENMTU)) == 0) { 
-               printf("es%d: can't initialize\n", unit);
+               printf("en%d: can't initialize\n", unit);
                return;
        }
        addr = (struct endevice *)ui->ui_addr;
        addr->en_istat = addr->en_ostat = 0;
 
        /*
                return;
        }
        addr = (struct endevice *)ui->ui_addr;
        addr->en_istat = addr->en_ostat = 0;
 
        /*
-        * Hang pending read, start any writes.
+        * Hang a receive and start any
+        * pending writes by faking a transmit complete.
         */
        s = splimp();
         */
        s = splimp();
-       enstart(unit);
+       addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
+       addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
+       addr->en_istat = EN_IEN|EN_GO;
+       es->es_oactive = 1;
        enxint(unit);
        splx(s);
 }
        enxint(unit);
        splx(s);
 }
@@ -170,17 +172,14 @@ int       enlastdel = 25;
 enstart(dev)
        dev_t dev;
 {
 enstart(dev)
        dev_t dev;
 {
-        int unit;
-       struct uba_device *ui;
+        int unit = ENUNIT(dev);
+       struct uba_device *ui = eninfo[unit];
+       register struct en_softc *es = &en_softc[unit];
        register struct endevice *addr;
        register struct endevice *addr;
-       register struct en_softc *es;
        struct mbuf *m;
        int dest;
 COUNT(ENSTART);
 
        struct mbuf *m;
        int dest;
 COUNT(ENSTART);
 
-       unit = ENUNIT(dev);
-       ui = eninfo[unit];
-       es = &en_softc[unit];
        if (es->es_oactive)
                goto restart;
 
        if (es->es_oactive)
                goto restart;
 
@@ -194,7 +193,11 @@ COUNT(ENSTART);
                es->es_oactive = 0;
                return;
        }
                es->es_oactive = 0;
                return;
        }
+       dest = mtod(m, struct en_header *)->en_dhost;
+printf("if_wubaput m=%x\n", m);
        es->es_olen = if_wubaput(&es->es_ifuba, m);
        es->es_olen = if_wubaput(&es->es_ifuba, m);
+printf("wubaput to %x len %d\n", es->es_ifuba.ifu_w.ifrw_addr, es->es_olen);
+asm("halt");
 
        /*
         * Ethernet cannot take back-to-back packets (no
 
        /*
         * Ethernet cannot take back-to-back packets (no
@@ -202,7 +205,6 @@ COUNT(ENSTART);
         * receiver, enforce a small delay (about 1ms) in interface
         * on successive packets sent to same host.
         */
         * receiver, enforce a small delay (about 1ms) in interface
         * on successive packets sent to same host.
         */
-       dest = mtod(m, struct en_header *)->en_dhost;
        if (es->es_lastx && es->es_lastx == dest)
                es->es_delay = enlastdel;
        else
        if (es->es_lastx && es->es_lastx == dest)
                es->es_delay = enlastdel;
        else
@@ -215,7 +217,7 @@ restart:
         */
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
        addr = (struct endevice *)ui->ui_addr;
         */
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_w.ifrw_bdp);
        addr = (struct endevice *)ui->ui_addr;
-       addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_addr;
+       addr->en_oba = (int)es->es_ifuba.ifu_w.ifrw_info;
        addr->en_odelay = es->es_delay;
        addr->en_owc = -((es->es_olen + 1) >> 1);
        addr->en_ostat = EN_IEN|EN_GO;
        addr->en_odelay = es->es_delay;
        addr->en_owc = -((es->es_olen + 1) >> 1);
        addr->en_ostat = EN_IEN|EN_GO;
@@ -229,23 +231,27 @@ restart:
 enxint(unit)
        int unit;
 {
 enxint(unit)
        int unit;
 {
+       register struct uba_device *ui = eninfo[unit];
+       register struct en_softc *es = &en_softc[unit];
        register struct endevice *addr;
        register struct endevice *addr;
-       register struct uba_device *ui;
-       register struct en_softc *es;
 COUNT(ENXINT);
 
 COUNT(ENXINT);
 
-       ui = eninfo[unit];
-       es = &en_softc[unit];
+printf("enxint\n");
        if (es->es_oactive == 0)
                return;
        addr = (struct endevice *)ui->ui_addr;
        if (es->es_oactive == 0)
                return;
        addr = (struct endevice *)ui->ui_addr;
-       es = &en_softc[unit];
+       es->es_if.if_opackets++;
        es->es_oactive = 0;
        es->es_delay = 0;
        es->es_mask = ~0;
        if (addr->en_ostat&EN_OERROR)
        es->es_oactive = 0;
        es->es_delay = 0;
        es->es_mask = ~0;
        if (addr->en_ostat&EN_OERROR)
-               printf("es%d: output error\n", unit);
+               printf("en%d: output error\n", unit);
        if (es->es_if.if_snd.ifq_head == 0) {
        if (es->es_if.if_snd.ifq_head == 0) {
+               es->es_if.if_oerrors++;
+               if (es->es_ifuba.ifu_xtofree) {
+                       m_freem(es->es_ifuba.ifu_xtofree);
+                       es->es_ifuba.ifu_xtofree = 0;
+               }
                es->es_lastx = 0;
                return;
        }
                es->es_lastx = 0;
                return;
        }
@@ -260,21 +266,30 @@ COUNT(ENXINT);
 encollide(unit)
        int unit;
 {
 encollide(unit)
        int unit;
 {
-       register struct en_softc *es;
+       register struct en_softc *es = &en_softc[unit];
 COUNT(ENCOLLIDE);
 
 COUNT(ENCOLLIDE);
 
-       es = &en_softc[unit];
+printf("encollide\n");
        es->es_if.if_collisions++;
        if (es->es_oactive == 0)
                return;
        es->es_if.if_collisions++;
        if (es->es_oactive == 0)
                return;
+       /*
+        * Es_mask is a 16 bit number with n low zero bits, with
+        * n the number of backoffs.  When es_mask is 0 we have
+        * backed off 16 times, and give up.
+        */
        if (es->es_mask == 0) {
        if (es->es_mask == 0) {
-               printf("es%d: send error\n", unit);
+               printf("en%d: send error\n", unit);
                enxint(unit);
                enxint(unit);
-       } else {
-               es->es_mask <<= 1;
-               es->es_delay = mfpr(ICR) &~ es->es_mask;
-               enstart(unit);
+               return;
        }
        }
+       /*
+        * Another backoff.  Restart with delay based on n low bits
+        * of the interval timer.
+        */
+       es->es_mask <<= 1;
+       es->es_delay = mfpr(ICR) &~ es->es_mask;
+       enstart(unit);
 }
 
 /*
 }
 
 /*
@@ -289,25 +304,25 @@ COUNT(ENCOLLIDE);
 enrint(unit)
        int unit;
 {
 enrint(unit)
        int unit;
 {
-       struct endevice *addr;
-       register struct en_softc *es;
-       struct en_header *en;
+       register struct en_softc *es = &en_softc[unit];
+       struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
+       register struct en_header *en;
        struct mbuf *m;
        struct mbuf *m;
-       struct ifqueue *inq;
-       register int len;
+       int len;
+       register struct ifqueue *inq;
        int off;
 COUNT(ENRINT);
 
        int off;
 COUNT(ENRINT);
 
-       es = &en_softc[unit];
-       addr = (struct endevice *)eninfo[unit]->ui_addr;
+printf("enrint\n");
+       es->es_if.if_ipackets++;
 
        /*
 
        /*
-        * Purge BDP; drop error packets.
+        * Purge BDP; drop if input error indicated.
         */
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
        if (addr->en_istat&EN_IERROR) {
                es->es_if.if_ierrors++;
         */
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
        if (addr->en_istat&EN_IERROR) {
                es->es_if.if_ierrors++;
-               printf("es%d: input error\n", unit);
+               printf("en%d: input error\n", unit);
                goto setup;
        }
 
                goto setup;
        }
 
@@ -318,15 +333,18 @@ COUNT(ENRINT);
         * Remember that type was trailer by setting off.
         */
        en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
         * Remember that type was trailer by setting off.
         */
        en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
+printf("en %x, en->en_type %d\n", en, en->en_type);
 #define        endataaddr(en, off, type)       ((type)(((caddr_t)((en)+1)+(off))))
        if (en->en_type >= ENPUP_TRAIL &&
            en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
                off = (en->en_type - ENPUP_TRAIL) * 512;
 #define        endataaddr(en, off, type)       ((type)(((caddr_t)((en)+1)+(off))))
        if (en->en_type >= ENPUP_TRAIL &&
            en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
                off = (en->en_type - ENPUP_TRAIL) * 512;
+               if (off >= ENMTU)
+                       goto setup;             /* sanity */
                en->en_type = *endataaddr(en, off, u_short *);
                en->en_type = *endataaddr(en, off, u_short *);
-               off += 2;
        } else
                off = 0;
 
        } else
                off = 0;
 
+printf("off %d\n", off);
        /*
         * Attempt to infer packet length from type;
         * can't deal with packet if can't infer length.
        /*
         * Attempt to infer packet length from type;
         * can't deal with packet if can't infer length.
@@ -335,7 +353,7 @@ COUNT(ENRINT);
 
 #ifdef INET
        case ENPUP_IPTYPE:
 
 #ifdef INET
        case ENPUP_IPTYPE:
-               len = endataaddr(en, off, struct ip *)->ip_len;
+               len = htons(endataaddr(en, off+2, struct ip *)->ip_len)+2;
                setipintr();
                inq = &ipintrq;
                break;
                setipintr();
                inq = &ipintrq;
                break;
@@ -352,10 +370,13 @@ COUNT(ENRINT);
         * Pull packet off interface.  Off is nonzero if packet
         * has trailing header; if_rubaget will then force this header
         * information to be at the front, but we still have to drop
         * Pull packet off interface.  Off is nonzero if packet
         * has trailing header; if_rubaget will then force this header
         * information to be at the front, but we still have to drop
-        * the two-byte type which is at the front of the trailer data
-        * (which we ``consumed'' above).
+        * the two-byte type which is at the front of any trailer data.
         */
        m = if_rubaget(&es->es_ifuba, len, off);
         */
        m = if_rubaget(&es->es_ifuba, len, off);
+       if (m == 0)
+               goto setup;
+       printf("rubaget returns m %x\n", m);
+       asm("halt");
        if (off) {
                m->m_off += 2;
                m->m_len -= 2;
        if (off) {
                m->m_off += 2;
                m->m_len -= 2;
@@ -395,8 +416,9 @@ enoutput(ifp, m0, pf)
                int off;
 
                dest = ip->ip_dst.s_addr >> 24;
                int off;
 
                dest = ip->ip_dst.s_addr >> 24;
-               off = ip->ip_len - m->m_len;
-               if (off && off % 512 == 0 && m->m_off >= MMINOFF + 2) {
+               off = ntohs(ip->ip_len) - m->m_len;
+printf("PF_INET enoutput off %d m->m_off %d m->m_len %d\n", off, m->m_off, m->m_len);
+               if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
                        type = ENPUP_TRAIL + (off>>9);
                        m->m_off -= 2;
                        m->m_len += 2;
                        type = ENPUP_TRAIL + (off>>9);
                        m->m_off -= 2;
                        m->m_len += 2;
@@ -415,24 +437,27 @@ enoutput(ifp, m0, pf)
                return (0);
        }
 
                return (0);
        }
 
+gottrailertype:
        /*
         * Packet to be sent as trailer: move first packet
         * (control information) to end of chain.
         */
        /*
         * Packet to be sent as trailer: move first packet
         * (control information) to end of chain.
         */
-gottrailertype:
        while (m->m_next)
                m = m->m_next;
        m->m_next = m0;
        m = m0->m_next;
        m0->m_next = 0;
        while (m->m_next)
                m = m->m_next;
        m->m_next = m0;
        m = m0->m_next;
        m0->m_next = 0;
+       m0 = m;
 
 
+printf("m %x after trailer futz\n", m);
+asm("halt");
+gottype:
        /*
         * Add local net header.  If no space in first mbuf,
         * allocate another.
         */
        /*
         * Add local net header.  If no space in first mbuf,
         * allocate another.
         */
-gottype:
-       m0 = m;
-       if (MMINOFF + sizeof (struct en_header) > m->m_off) {
+       if (m->m_off > MMAXOFF ||
+           MMINOFF + sizeof (struct en_header) > m->m_off) {
                m = m_get(0);
                if (m == 0) {
                        m_freem(m0);
                m = m_get(0);
                if (m == 0) {
                        m_freem(m0);
@@ -442,7 +467,6 @@ gottype:
                m->m_off = MMINOFF;
                m->m_len = sizeof (struct en_header);
        } else {
                m->m_off = MMINOFF;
                m->m_len = sizeof (struct en_header);
        } else {
-               m = m0;
                m->m_off -= sizeof (struct en_header);
                m->m_len += sizeof (struct en_header);
        }
                m->m_off -= sizeof (struct en_header);
                m->m_len += sizeof (struct en_header);
        }
@@ -456,6 +480,8 @@ gottype:
         * not yet active.
         */
        s = splimp();
         * not yet active.
         */
        s = splimp();
+printf("queueing %x\n", m);
+asm("halt");
        IF_ENQUEUE(&ifp->if_snd, m);
        splx(s);
        if (en_softc[ifp->if_unit].es_oactive == 0)
        IF_ENQUEUE(&ifp->if_snd, m);
        splx(s);
        if (en_softc[ifp->if_unit].es_oactive == 0)