BSD 4_3_Tahoe release
[unix-history] / usr / src / sys / vaxif / if_uba.c
index d5fec32..9ec0890 100644 (file)
@@ -3,11 +3,9 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)if_uba.c    7.1 (Berkeley) 6/5/86
+ *     @(#)if_uba.c    7.9 (Berkeley) 5/24/88
  */
 
  */
 
-#include "../machine/pte.h"
-
 #include "param.h"
 #include "systm.h"
 #include "mbuf.h"
 #include "param.h"
 #include "systm.h"
 #include "mbuf.h"
 #include "vmmac.h"
 #include "socket.h"
 #include "syslog.h"
 #include "vmmac.h"
 #include "socket.h"
 #include "syslog.h"
+#include "malloc.h"
 
 #include "../net/if.h"
 
 
 #include "../net/if.h"
 
+#include "../vax/pte.h"
 #include "../vax/mtpr.h"
 #include "if_uba.h"
 #include "../vaxuba/ubareg.h"
 #include "../vax/mtpr.h"
 #include "if_uba.h"
 #include "../vaxuba/ubareg.h"
@@ -47,34 +47,36 @@ if_ubaminit(ifu, uban, hlen, nmr, ifr, nr, ifw, nw)
 {
        register caddr_t p;
        caddr_t cp;
 {
        register caddr_t p;
        caddr_t cp;
-       int i, ncl, off;
+       int i, nclbytes, off;
 
        if (hlen)
                off = CLBYTES - hlen;
        else
                off = 0;
 
        if (hlen)
                off = CLBYTES - hlen;
        else
                off = 0;
-       ncl = clrnd(nmr) / CLSIZE;
+       nclbytes = CLBYTES * (clrnd(nmr) / CLSIZE);
        if (hlen)
        if (hlen)
-               ncl++;
+               nclbytes += CLBYTES;
        if (ifr[0].ifrw_addr)
                cp = ifr[0].ifrw_addr - off;
        else {
        if (ifr[0].ifrw_addr)
                cp = ifr[0].ifrw_addr - off;
        else {
-               cp = m_clalloc((nr + nw) * ncl, MPG_SPACE, M_DONTWAIT);
+               cp = (caddr_t)malloc((u_long)((nr + nw) * nclbytes), M_DEVBUF,
+                   M_NOWAIT);
                if (cp == 0)
                        return (0);
                p = cp;
                for (i = 0; i < nr; i++) {
                        ifr[i].ifrw_addr = p + off;
                if (cp == 0)
                        return (0);
                p = cp;
                for (i = 0; i < nr; i++) {
                        ifr[i].ifrw_addr = p + off;
-                       p += ncl * CLBYTES;
+                       p += nclbytes;
                }
                for (i = 0; i < nw; i++) {
                        ifw[i].ifw_base = p;
                        ifw[i].ifw_addr = p + off;
                }
                for (i = 0; i < nw; i++) {
                        ifw[i].ifw_base = p;
                        ifw[i].ifw_addr = p + off;
-                       p += ncl * CLBYTES;
+                       p += nclbytes;
                }
                ifu->iff_hlen = hlen;
                ifu->iff_uban = uban;
                ifu->iff_uba = uba_hd[uban].uh_uba;
                }
                ifu->iff_hlen = hlen;
                ifu->iff_uban = uban;
                ifu->iff_uba = uba_hd[uban].uh_uba;
+               ifu->iff_ubamr = uba_hd[uban].uh_mr;
        }
        for (i = 0; i < nr; i++)
                if (if_ubaalloc(ifu, &ifr[i], nmr) == 0) {
        }
        for (i = 0; i < nr; i++)
                if (if_ubaalloc(ifu, &ifr[i], nmr) == 0) {
@@ -97,10 +99,10 @@ if_ubaminit(ifu, uban, hlen, nmr, ifr, nr, ifw, nw)
        return (1);
 bad:
        while (--nw >= 0)
        return (1);
 bad:
        while (--nw >= 0)
-               ubarelse(ifu->iff_uban, &ifr[nw].ifrw_info);
+               ubarelse(ifu->iff_uban, &ifw[nw].ifw_info);
        while (--nr >= 0)
        while (--nr >= 0)
-               ubarelse(ifu->iff_uban, &ifw[nr].ifw_info);
-       m_pgfree(cp, (nr + nw) * ncl);
+               ubarelse(ifu->iff_uban, &ifr[nr].ifrw_info);
+       free(cp, M_DEVBUF);
        ifr[0].ifrw_addr = 0;
        return (0);
 }
        ifr[0].ifrw_addr = 0;
        return (0);
 }
@@ -126,8 +128,7 @@ if_ubaalloc(ifu, ifrw, nmr)
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
        ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
        ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
-       ifrw->ifrw_mr = &ifu->iff_uba->uba_map[UBAI_MR(info) + (ifu->iff_hlen?
-               1 : 0)];
+       ifrw->ifrw_mr = &ifu->iff_ubamr[UBAI_MR(info) + (ifu->iff_hlen? 1 : 0)];
        return (1);
 }
 
        return (1);
 }
 
@@ -200,15 +201,14 @@ if_ubaget(ifu, ifr, totlen, off0, ifp)
                         * as quick form of copy.  Remap UNIBUS and invalidate.
                         */
                        pp = mtod(m, char *);
                         * as quick form of copy.  Remap UNIBUS and invalidate.
                         */
                        pp = mtod(m, char *);
-                       cpte = &Mbmap[mtocl(cp)*CLSIZE];
-                       ppte = &Mbmap[mtocl(pp)*CLSIZE];
+                       cpte = kvtopte(cp);
+                       ppte = kvtopte(pp);
                        x = btop(cp - ifr->ifrw_addr);
                        ip = (int *)&ifr->ifrw_mr[x];
                        for (i = 0; i < CLSIZE; i++) {
                                struct pte t;
                                t = *ppte; *ppte++ = *cpte; *cpte = t;
                        x = btop(cp - ifr->ifrw_addr);
                        ip = (int *)&ifr->ifrw_mr[x];
                        for (i = 0; i < CLSIZE; i++) {
                                struct pte t;
                                t = *ppte; *ppte++ = *cpte; *cpte = t;
-                               *ip++ =
-                                   cpte++->pg_pfnum|ifr->ifrw_proto;
+                               *ip++ = cpte++->pg_pfnum|ifr->ifrw_proto;
                                mtpr(TBIS, cp);
                                cp += NBPG;
                                mtpr(TBIS, (caddr_t)pp);
                                mtpr(TBIS, cp);
                                cp += NBPG;
                                mtpr(TBIS, (caddr_t)pp);
@@ -273,27 +273,24 @@ rcv_xmtbuf(ifw)
        register struct mbuf *m;
        struct mbuf **mprev;
        register i;
        register struct mbuf *m;
        struct mbuf **mprev;
        register i;
-       int t;
        char *cp;
 
        while (i = ffs((long)ifw->ifw_xswapd)) {
                cp = ifw->ifw_base + i * CLBYTES;
                i--;
                ifw->ifw_xswapd &= ~(1<<i);
        char *cp;
 
        while (i = ffs((long)ifw->ifw_xswapd)) {
                cp = ifw->ifw_base + i * CLBYTES;
                i--;
                ifw->ifw_xswapd &= ~(1<<i);
-               i *= CLSIZE;
                mprev = &ifw->ifw_xtofree;
                for (m = ifw->ifw_xtofree; m && m->m_next; m = m->m_next)
                        mprev = &m->m_next;
                if (m == NULL)
                mprev = &ifw->ifw_xtofree;
                for (m = ifw->ifw_xtofree; m && m->m_next; m = m->m_next)
                        mprev = &m->m_next;
                if (m == NULL)
-                       panic("rcv_xmtbuf");
+                       break;
                bcopy(mtod(m, caddr_t), cp, CLBYTES);
                (void) m_free(m);
                *mprev = NULL;
                bcopy(mtod(m, caddr_t), cp, CLBYTES);
                (void) m_free(m);
                *mprev = NULL;
-               for (t = 0; t < CLSIZE; t++) {
-                       ifw->ifw_mr[i] = ifw->ifw_wmap[i];
-                       i++;
-               }
        }
        }
+       ifw->ifw_xswapd = 0;
+       for (i = 0; i < ifw->ifw_nmr; i++)
+               ifw->ifw_mr[i] = ifw->ifw_wmap[i];
 }
 
 /*
 }
 
 /*
@@ -333,13 +330,14 @@ if_ubaput(ifu, ifw, m)
                dp = mtod(m, char *);
                if (claligned(cp) && claligned(dp) &&
                    (m->m_len == CLBYTES || m->m_next == (struct mbuf *)0)) {
                dp = mtod(m, char *);
                if (claligned(cp) && claligned(dp) &&
                    (m->m_len == CLBYTES || m->m_next == (struct mbuf *)0)) {
-                       struct pte *pte; int *ip;
-                       pte = &Mbmap[mtocl(dp)*CLSIZE];
+                       struct pte *pte;
+                       int *ip;
+
+                       pte = kvtopte(dp);
                        x = btop(cp - ifw->ifw_addr);
                        ip = (int *)&ifw->ifw_mr[x];
                        for (i = 0; i < CLSIZE; i++)
                        x = btop(cp - ifw->ifw_addr);
                        ip = (int *)&ifw->ifw_mr[x];
                        for (i = 0; i < CLSIZE; i++)
-                               *ip++ =
-                                   ifw->ifw_proto | pte++->pg_pfnum;
+                               *ip++ = ifw->ifw_proto | pte++->pg_pfnum;
                        xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
                        mp = m->m_next;
                        m->m_next = ifw->ifw_xtofree;
                        xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
                        mp = m->m_next;
                        m->m_next = ifw->ifw_xtofree;