more lint
[unix-history] / usr / src / sys / vax / if / if_en.c
index 492fb3a..af91867 100644 (file)
@@ -1,4 +1,4 @@
-/* if_en.c 4.2 81/10/31 */
+/* if_en.c 4.11 81/11/20 */
 
 #include "en.h"
 /*
 
 #include "en.h"
 /*
@@ -8,11 +8,14 @@
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
-#include "../inet/inet.h"
-#include "../inet/inet_systm.h"
-#include "../inet/imp.h"
-#include "../inet/ip.h"
-#include "../inet/tcp.h"                       /* ### */
+#include "../net/inet.h"
+#include "../net/inet_pcb.h"
+#include "../net/inet_systm.h"
+#include "../net/imp.h"
+#include "../net/ip.h"
+#include "../net/ip_var.h"
+#include "../net/tcp.h"                        /* XXX */
+#include "../net/tcp_var.h"
 #include "../h/map.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/map.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
@@ -27,7 +30,8 @@
 #include "../h/cpu.h"
 #include "../h/cmap.h"
 
 #include "../h/cpu.h"
 #include "../h/cmap.h"
 
-int    enrswaps, enwswaps;
+int    enrswaps;
+/* int enwswaps; */
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 u_short enstd[] = { 0 };
@@ -39,7 +43,7 @@ struct        uba_driver endriver =
 struct en_packet *xpkt, *rpkt;
 struct en_prefix {
        struct en_header enp_h;
 struct en_packet *xpkt, *rpkt;
 struct en_prefix {
        struct en_header enp_h;
-       struct th enp_th;
+       struct tcpiphdr enp_th;
 };
 struct uba_regs *enuba;
 struct pte *enrmr, *enxmr;
 };
 struct uba_regs *enuba;
 struct pte *enrmr, *enxmr;
@@ -56,19 +60,21 @@ enprobe(reg)
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
+       enrint(0); enxint(0); encollide(0);
 #endif
 
        addr->en_istat = 0;
        addr->en_ostat = 0;
        addr->en_owc = -1;
        addr->en_oba = 0;
 #endif
 
        addr->en_istat = 0;
        addr->en_ostat = 0;
        addr->en_owc = -1;
        addr->en_oba = 0;
-       addr->en_ostat = IEN|GO;
+       addr->en_ostat = EN_IEN|EN_GO;
        DELAY(100000);
        addr->en_ostat = 0;
        printf("ethernet address %d\n", ~addr->en_addr&0xff);
        return (1);
 }
 
        DELAY(100000);
        addr->en_ostat = 0;
        printf("ethernet address %d\n", ~addr->en_addr&0xff);
        return (1);
 }
 
+/*ARGSUSED*/
 enattach(ui)
        struct uba_device *ui;
 {
 enattach(ui)
        struct uba_device *ui;
 {
@@ -93,14 +99,14 @@ eninit(unit)
                reenter = 1;
                n = 10;
                k = n<<1;
                reenter = 1;
                n = 10;
                k = n<<1;
-               i = rmalloc(netmap, n*2);
+               i = rmalloc(mbmap, n*2);
                if (i == 0)
                        panic("eninit");
                j = i << 1;
                cp = (char *)pftom(i);
                if (i == 0)
                        panic("eninit");
                j = i << 1;
                cp = (char *)pftom(i);
-               if (memall(&Netmap[j], k, proc, CSYS) == 0)
-                       return (0);
-               vmaccess(&Netmap[j], (caddr_t)cp, k);
+               if (memall(&Mbmap[j], k, proc, CSYS) == 0)
+                       panic("eninit");
+               vmaccess(&Mbmap[j], (caddr_t)cp, k);
                rpkt = (struct en_packet *)
                    (cp + 1024 - sizeof (struct en_prefix));
                xpkt = (struct en_packet *)
                rpkt = (struct en_packet *)
                    (cp + 1024 - sizeof (struct en_prefix));
                xpkt = (struct en_packet *)
@@ -137,6 +143,7 @@ eninit(unit)
 #endif
 }
 
 #endif
 }
 
+#if 0
 enreset(uban)
        int uban;
 {
 enreset(uban)
        int uban;
 {
@@ -148,14 +155,17 @@ enreset(uban)
                if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
                        continue;
                if (imp_stat.iaddr)
                if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
                        continue;
                if (imp_stat.iaddr)
-                       ubarelse(uban, imp_stat.iaddr);
+                       ubarelse(uban, &imp_stat.iaddr);
                if (imp_stat.oaddr)
                if (imp_stat.oaddr)
-                       ubarelse(uban, imp_stat.oaddr);
+                       ubarelse(uban, &imp_stat.oaddr);
                eninit(unit);
                printf("en%d ", unit);
        }
 }
                eninit(unit);
                printf("en%d ", unit);
        }
 }
+#endif
 
 
+int    enlastdel = 25;
+int    enlastx = 0;
 enstart(dev)
        dev_t dev;
 {
 enstart(dev)
        dev_t dev;
 {
@@ -164,7 +174,6 @@ enstart(dev)
        register caddr_t cp, top;
         int unit;
         register int len;
        register caddr_t cp, top;
         int unit;
         register int len;
-       u_short uaddr;
        struct uba_device *ui;
        int enxswapnow = 0;
 COUNT(ENSTART);
        struct uba_device *ui;
        int enxswapnow = 0;
 COUNT(ENSTART);
@@ -195,23 +204,29 @@ COUNT(ENSTART);
                        }
                        dp = mtod(m, char *);
                        if (((int)cp&0x3ff)==0 && ((int)dp&0x3ff)==0) {
                        }
                        dp = mtod(m, char *);
                        if (((int)cp&0x3ff)==0 && ((int)dp&0x3ff)==0) {
-                               struct pte *pte = &Netmap[mtopf(dp)*2];
+                               struct pte *pte = &Mbmap[mtopf(dp)*2];
                                *(int *)enxmr = enwproto | pte++->pg_pfnum;
                                *(int *)(enxmr+1) = enwproto | pte->pg_pfnum;
                                enxswapd = enxswapnow = 1;
                        } else
                                *(int *)enxmr = enwproto | pte++->pg_pfnum;
                                *(int *)(enxmr+1) = enwproto | pte->pg_pfnum;
                                enxswapd = enxswapnow = 1;
                        } else
-                               bcopy((int)m + m->m_off, cp, m->m_len);
+                               bcopy(mtod(m, caddr_t), cp,
+                                   (unsigned)m->m_len);
                        cp += m->m_len;
                        /* too soon! */
                        MFREE(m, mp);
                        m = mp;
                }
                        cp += m->m_len;
                        /* too soon! */
                        MFREE(m, mp);
                        m = mp;
                }
+               if (enxswapnow == 0 && enxswapd) {
+                       enxmr[0] = enxmap[0];
+                       enxmr[1] = enxmap[1];
+               }
+               if (enlastx && enlastx == xpkt->Header.en_dhost)
+                       imp_stat.endelay = enlastdel;
+               else
+                       enlastx = xpkt->Header.en_dhost;
        }
        }
-       if (enxswapnow == 0 && enxswapd) {
-               enxmr[0] = enxmap[0];
-               enxmr[1] = enxmap[1];
-       }
-       len = ntohs(((struct ip *)((int)xpkt + L1822))->ip_len) + L1822;
+       len = ntohs((u_short)(((struct ip *)((int)xpkt + L1822))->ip_len)) +
+           L1822;
        if (len > sizeof(struct en_packet)) {
                printf("imp_output: ridiculous IP length %d\n", len);
                return;
        if (len > sizeof(struct en_packet)) {
                printf("imp_output: ridiculous IP length %d\n", len);
                return;
@@ -237,30 +252,7 @@ COUNT(ENSTART);
        printf("en%d: sending packet (%d bytes)\n", unit, len);
        prt_byte(xpkt, len);
 #endif
        printf("en%d: sending packet (%d bytes)\n", unit, len);
        prt_byte(xpkt, len);
 #endif
-       addr->en_ostat = IEN|GO;
-}
-
-/*
- * Setup for a read
- */
-ensetup(dev)
-       dev_t dev;
-{
-       register struct endevice *addr;
-       register struct uba_device *ui;
-        register unsigned ubaddr;
-       register int sps;
-COUNT(ENSETUP);
-
-       ui = eninfo[ENUNIT(dev)];
-       if (ui == 0 || ui->ui_alive == 0) {
-               printf("en%d (imp_read): not alive\n", ENUNIT(dev));
-               return;
-       }
-       addr = (struct endevice *)ui->ui_addr;
-       addr->en_iba = imp_stat.iaddr;
-       addr->en_iwc = -600;    /* a little extra to avoid hardware bugs */
-       addr->en_istat = IEN|GO;
+       addr->en_ostat = EN_IEN|EN_GO;
 }
 
 /*
 }
 
 /*
@@ -286,14 +278,17 @@ COUNT(ENXINT);
        }
        imp_stat.endelay = 0;
        imp_stat.enmask = ~0;
        }
        imp_stat.endelay = 0;
        imp_stat.enmask = ~0;
-       if (addr->en_ostat&ERROR)
+       if (addr->en_ostat&EN_OERROR)
                printf("en%d: output error ostat=%b\n", unit,
                        addr->en_ostat, EN_BITS);
        imp_stat.outactive = 0;
        if (imp_stat.outq_head)
                enstart(unit);
                printf("en%d: output error ostat=%b\n", unit,
                        addr->en_ostat, EN_BITS);
        imp_stat.outactive = 0;
        if (imp_stat.outq_head)
                enstart(unit);
+       else
+               enlastx = 0;
 }
 
 }
 
+int collisions;
 encollide(unit)
        int unit;
 {
 encollide(unit)
        int unit;
 {
@@ -301,6 +296,7 @@ encollide(unit)
        register struct uba_device *ui;
 COUNT(ENCOLLIDE);
 
        register struct uba_device *ui;
 COUNT(ENCOLLIDE);
 
+       collisions++;
        ui = eninfo[unit];
        addr = (struct endevice *)ui->ui_addr;
 
        ui = eninfo[unit];
        addr = (struct endevice *)ui->ui_addr;
 
@@ -317,7 +313,7 @@ COUNT(ENCOLLIDE);
                        addr->en_ostat, EN_BITS);
        } else {
                imp_stat.enmask <<= 1;
                        addr->en_ostat, EN_BITS);
        } else {
                imp_stat.enmask <<= 1;
-               imp_stat.endelay = time & ~imp_stat.enmask;
+               imp_stat.endelay = mfpr(ICR) & ~imp_stat.enmask;
        }
        enstart(unit);
 }
        }
        enstart(unit);
 }
@@ -333,7 +329,7 @@ enrint(unit)
        register caddr_t cp;
        struct mbuf *p, *top = 0;
        struct ip *ip;
        register caddr_t cp;
        struct mbuf *p, *top = 0;
        struct ip *ip;
-       int j, hlen;
+       u_int hlen;
 COUNT(ENRINT);
 
        ui = eninfo[unit];
 COUNT(ENRINT);
 
        ui = eninfo[unit];
@@ -343,7 +339,7 @@ COUNT(ENRINT);
 #endif
        if (imp_stat.flush)
                goto flush;
 #endif
        if (imp_stat.flush)
                goto flush;
-       if (addr->en_istat&ERROR) {
+       if (addr->en_istat&EN_IERROR) {
 #ifdef notdef
                printf("en%d: input error istat=%b\n", unit,
                        addr->en_istat, EN_BITS);
 #ifdef notdef
                printf("en%d: input error istat=%b\n", unit,
                        addr->en_istat, EN_BITS);
@@ -365,7 +361,7 @@ COUNT(ENRINT);
        }
 #endif
        ip = (struct ip *)((int)rpkt + L1822);
        }
 #endif
        ip = (struct ip *)((int)rpkt + L1822);
-       len = ntohs(ip->ip_len) + L1822;
+       len = ntohs((u_short *)ip->ip_len) + L1822;
        if (len > sizeof(struct en_packet) || len < sizeof (struct ip)) {
                printf("enrint: bad ip length %d\n", len);
                goto flush;
        if (len > sizeof(struct en_packet) || len < sizeof (struct ip)) {
                printf("enrint: bad ip length %d\n", len);
                goto flush;
@@ -373,8 +369,8 @@ COUNT(ENRINT);
        hlen = L1822 + sizeof (struct ip);
        switch (ip->ip_p) {
 
        hlen = L1822 + sizeof (struct ip);
        switch (ip->ip_p) {
 
-       case TCPROTO:
-               hlen += ((struct th *)ip)->t_off * 4;
+       case IPPROTO_TCP:
+               hlen += ((struct tcpiphdr *)ip)->ti_off << 2;
                break;
        }
        MGET(m, 0);
                break;
        }
        MGET(m, 0);
@@ -383,7 +379,7 @@ COUNT(ENRINT);
        top = m;
        m->m_off = MMINOFF;
        m->m_len = hlen;
        top = m;
        m->m_off = MMINOFF;
        m->m_len = hlen;
-       bcopy(rpkt, mtod(m, caddr_t), hlen);
+       bcopy((caddr_t)rpkt, mtod(m, caddr_t), hlen);
        len -= hlen;
        cp = (caddr_t)rpkt + hlen;
        mp = m;
        len -= hlen;
        cp = (caddr_t)rpkt + hlen;
        mp = m;
@@ -398,8 +394,8 @@ COUNT(ENRINT);
                        m->m_len = PGSIZE;
                        m->m_off = (int)p - (int)m;
                        if (((int)cp & 0x3ff) == 0) {
                        m->m_len = PGSIZE;
                        m->m_off = (int)p - (int)m;
                        if (((int)cp & 0x3ff) == 0) {
-                               struct pte *cpte = &Netmap[mtopf(cp)*2];
-                               struct pte *ppte = &Netmap[mtopf(p)*2];
+                               struct pte *cpte = &Mbmap[mtopf(cp)*2];
+                               struct pte *ppte = &Mbmap[mtopf(p)*2];
                                struct pte t;
                                enrswaps++;
                                t = *ppte; *ppte++ = *cpte; *cpte++ = t;
                                struct pte t;
                                enrswaps++;
                                t = *ppte; *ppte++ = *cpte; *cpte++ = t;
@@ -419,7 +415,7 @@ nopage:
                        m->m_len = MIN(MLEN, len);
                        m->m_off = MMINOFF;
                }
                        m->m_len = MIN(MLEN, len);
                        m->m_off = MMINOFF;
                }
-               bcopy(cp, (int)m + m->m_off, m->m_len);
+               bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len);
 nocopy:
                cp += m->m_len;
                len -= m->m_len;
 nocopy:
                cp += m->m_len;
                len -= m->m_len;
@@ -446,7 +442,7 @@ flush:
 setup:
        addr->en_iba = imp_stat.iaddr;
        addr->en_iwc = -600;
 setup:
        addr->en_iba = imp_stat.iaddr;
        addr->en_iwc = -600;
-       addr->en_istat = IEN|GO;
+       addr->en_istat = EN_IEN|EN_GO;
 }
 
 #ifdef IMPDEBUG
 }
 
 #ifdef IMPDEBUG