fixed bug making 2dd screw up on vt100's with "set number".
[unix-history] / usr / src / sys / vax / if / if_en.c
index 7998a01..61ff2aa 100644 (file)
@@ -1,4 +1,4 @@
-/* if_en.c 4.4 81/11/04 */
+/* if_en.c 4.9 81/11/16 */
 
 #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(), enxint(), encollide();
 #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 *)
@@ -148,9 +154,9 @@ 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);
        }
@@ -166,7 +172,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);
@@ -197,12 +202,13 @@ 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);
                        cp += m->m_len;
                        /* too soon! */
                        MFREE(m, mp);
@@ -217,7 +223,8 @@ COUNT(ENSTART);
                else
                        enlastx = xpkt->Header.en_dhost;
        }
                else
                        enlastx = xpkt->Header.en_dhost;
        }
-       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;
@@ -243,30 +250,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;
 }
 
 /*
 }
 
 /*
@@ -292,7 +276,7 @@ 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;
                printf("en%d: output error ostat=%b\n", unit,
                        addr->en_ostat, EN_BITS);
        imp_stat.outactive = 0;
@@ -343,7 +327,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];
@@ -353,7 +337,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);
@@ -384,7 +368,7 @@ COUNT(ENRINT);
        switch (ip->ip_p) {
 
        case IPPROTO_TCP:
        switch (ip->ip_p) {
 
        case IPPROTO_TCP:
-               hlen += ((struct th *)ip)->t_off * 4;
+               hlen += ((struct tcpiphdr *)ip)->ti_off << 2;
                break;
        }
        MGET(m, 0);
                break;
        }
        MGET(m, 0);
@@ -393,7 +377,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;
@@ -408,8 +392,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;
@@ -429,7 +413,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;
@@ -456,7 +440,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