generalized if_uba support for multiple rcv/xmt buffers per device
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 17 Sep 1985 13:25:03 +0000 (05:25 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Tue, 17 Sep 1985 13:25:03 +0000 (05:25 -0800)
SCCS-vsn: sys/vax/if/if_uba.c 6.6
SCCS-vsn: sys/vax/if/if_uba.h 6.3
SCCS-vsn: sys/vax/if/if_de.c 6.13
SCCS-vsn: sys/vax/if/if_dmc.c 6.7

usr/src/sys/vax/if/if_de.c
usr/src/sys/vax/if/if_dmc.c
usr/src/sys/vax/if/if_uba.c
usr/src/sys/vax/if/if_uba.h

index 28e6ced..1e54450 100644 (file)
@@ -3,7 +3,7 @@
  * 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_de.c     6.12 (Berkeley) %G%
+ *     @(#)if_de.c     6.13 (Berkeley) %G%
  */
 #include "de.h"
 #if NDE > 0
  */
 #include "de.h"
 #if NDE > 0
 #include "../net/netisr.h"
 #include "../net/route.h"
 
 #include "../net/netisr.h"
 #include "../net/route.h"
 
+#ifdef BBNNET
+#define        INET
+#endif
 #ifdef INET
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/in_var.h"
 #include "../netinet/ip.h"
 #ifdef INET
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/in_var.h"
 #include "../netinet/ip.h"
-#include "../netinet/ip_var.h"
 #include "../netinet/if_ether.h"
 #endif
 
 #include "../netinet/if_ether.h"
 #endif
 
@@ -60,7 +62,6 @@
 
 #define        NXMT    3       /* number of transmit buffers */
 #define        NRCV    7       /* number of receive buffers (must be > 1) */
 
 #define        NXMT    3       /* number of transmit buffers */
 #define        NRCV    7       /* number of receive buffers (must be > 1) */
-#define        NTOT    (NXMT + NRCV)
 
 int    dedebug = 0;
 
 
 int    dedebug = 0;
 
@@ -70,29 +71,8 @@ u_short destd[] = { 0 };
 struct uba_driver dedriver =
        { deprobe, 0, deattach, 0, destd, "de", deinfo };
 int    deinit(),deoutput(),deioctl(),dereset();
 struct uba_driver dedriver =
        { deprobe, 0, deattach, 0, destd, "de", deinfo };
 int    deinit(),deoutput(),deioctl(),dereset();
-struct mbuf *deget();
 
 
 
 
-/*
- * The deuba structures generalizes the ifuba structure
- * to an arbitrary number of receive and transmit buffers.
- */
-struct ifxmt {
-       struct  ifrw x_ifrw;                    /* mapping information */
-       struct  pte x_map[IF_MAXNUBAMR];        /* output base pages */
-       short   x_xswapd;                       /* mask of clusters swapped */
-       struct  mbuf *x_xtofree;                /* pages being dma'ed out */
-};
-
-struct deuba {
-       short   ifu_uban;               /* uba number */
-       short   ifu_hlen;               /* local net header length */
-       struct  uba_regs *ifu_uba;      /* uba regs, in vm */
-       struct  ifrw ifu_r[NRCV];       /* receive information */
-       struct  ifxmt ifu_w[NXMT];      /* transmit information */
-       short   ifu_flags;              /* used during uballoc's */
-};
-
 /*
  * Ethernet software status per interface.
  *
 /*
  * Ethernet software status per interface.
  *
@@ -113,7 +93,9 @@ struct       de_softc {
 #define        DSF_LOCK        1               /* lock out destart */
 #define        DSF_RUNNING     2
        int     ds_ubaddr;              /* map info for incore structs */
 #define        DSF_LOCK        1               /* lock out destart */
 #define        DSF_RUNNING     2
        int     ds_ubaddr;              /* map info for incore structs */
-       struct  deuba ds_deuba;         /* unibus resource structure */
+       struct  ifubinfo ds_deuba;      /* unibus resource structure */
+       struct  ifrw ds_ifr[NRCV];      /* unibus receive maps */
+       struct  ifxmt ds_ifw[NXMT];     /* unibus xmt maps */
        /* the following structures are always mapped in */
        struct  de_pcbb ds_pcbb;        /* port control block */
        struct  de_ring ds_xrent[NXMT]; /* transmit ring entrys */
        /* the following structures are always mapped in */
        struct  de_pcbb ds_pcbb;        /* port control block */
        struct  de_ring ds_xrent[NXMT]; /* transmit ring entrys */
@@ -221,10 +203,10 @@ deattach(ui)
        ifp->if_output = deoutput;
        ifp->if_ioctl = deioctl;
        ifp->if_reset = dereset;
        ifp->if_output = deoutput;
        ifp->if_ioctl = deioctl;
        ifp->if_reset = dereset;
-       ds->ds_deuba.ifu_flags = UBA_CANTWAIT;
+       ds->ds_deuba.iff_flags = UBA_CANTWAIT;
 #ifdef notdef
        /* CAN WE USE BDP's ??? */
 #ifdef notdef
        /* CAN WE USE BDP's ??? */
-       ds->ds_deuba.ifu_flags |= UBA_NEEDBDP;
+       ds->ds_deuba.iff_flags |= UBA_NEEDBDP;
 #endif
        if_attach(ifp);
 }
 #endif
        if_attach(ifp);
 }
@@ -270,8 +252,9 @@ deinit(unit)
 
        if (ifp->if_flags & IFF_RUNNING)
                return;
 
        if (ifp->if_flags & IFF_RUNNING)
                return;
-       if (de_ubainit(&ds->ds_deuba, ui->ui_ubanum,
-           sizeof (struct ether_header), (int)btoc(ETHERMTU)) == 0) { 
+       if (if_ubaminit(&ds->ds_deuba, ui->ui_ubanum,
+           sizeof (struct ether_header), (int)btoc(ETHERMTU),
+           ds->ds_ifr, NRCV, ds->ds_ifw, NXMT) == 0) { 
                printf("de%d: can't initialize\n", unit);
                ds->ds_if.if_flags &= ~IFF_UP;
                return;
                printf("de%d: can't initialize\n", unit);
                ds->ds_if.if_flags &= ~IFF_UP;
                return;
@@ -332,14 +315,14 @@ deinit(unit)
                    csr0, PCSR0_BITS, addr->pcsr1, PCSR1_BITS);
 
        /* set up the receive and transmit ring entries */
                    csr0, PCSR0_BITS, addr->pcsr1, PCSR1_BITS);
 
        /* set up the receive and transmit ring entries */
-       ifxp = &ds->ds_deuba.ifu_w[0];
+       ifxp = &ds->ds_ifw[0];
        for (rp = &ds->ds_xrent[0]; rp < &ds->ds_xrent[NXMT]; rp++) {
        for (rp = &ds->ds_xrent[0]; rp < &ds->ds_xrent[NXMT]; rp++) {
-               rp->r_segbl = ifxp->x_ifrw.ifrw_info & 0xffff;
-               rp->r_segbh = (ifxp->x_ifrw.ifrw_info >> 16) & 0x3;
+               rp->r_segbl = ifxp->ifw_info & 0xffff;
+               rp->r_segbh = (ifxp->ifw_info >> 16) & 0x3;
                rp->r_flags = 0;
                ifxp++;
        }
                rp->r_flags = 0;
                ifxp++;
        }
-       ifrw = &ds->ds_deuba.ifu_r[0];
+       ifrw = &ds->ds_ifr[0];
        for (rp = &ds->ds_rrent[0]; rp < &ds->ds_rrent[NRCV]; rp++) {
                rp->r_slen = sizeof (struct de_buf);
                rp->r_segbl = ifrw->ifrw_info & 0xffff;
        for (rp = &ds->ds_rrent[0]; rp < &ds->ds_rrent[NRCV]; rp++) {
                rp->r_slen = sizeof (struct de_buf);
                rp->r_segbl = ifrw->ifrw_info & 0xffff;
@@ -389,10 +372,10 @@ destart(unit)
                rp = &ds->ds_xrent[ds->ds_xfree];
                if (rp->r_flags & XFLG_OWN)
                        panic("deuna xmit in progress");
                rp = &ds->ds_xrent[ds->ds_xfree];
                if (rp->r_flags & XFLG_OWN)
                        panic("deuna xmit in progress");
-               len = deput(&ds->ds_deuba, ds->ds_xfree, m);
-               if (ds->ds_deuba.ifu_flags & UBA_NEEDBDP)
-                       UBAPURGE(ds->ds_deuba.ifu_uba,
-                       ds->ds_deuba.ifu_w[ds->ds_xfree].x_ifrw.ifrw_bdp);
+               len = if_ubaput(&ds->ds_deuba, &ds->ds_ifw[ds->ds_xfree], m);
+               if (ds->ds_deuba.iff_flags & UBA_NEEDBDP)
+                       UBAPURGE(ds->ds_deuba.iff_uba,
+                       ds->ds_ifw[ds->ds_xfree].ifw_bdp);
                rp->r_slen = len;
                rp->r_tdrerr = 0;
                rp->r_flags = XFLG_STP|XFLG_ENP|XFLG_OWN;
                rp->r_slen = len;
                rp->r_tdrerr = 0;
                rp->r_flags = XFLG_STP|XFLG_ENP|XFLG_OWN;
@@ -444,7 +427,7 @@ deintr(unit)
                if (rp->r_flags & XFLG_OWN)
                        break;
                ds->ds_if.if_opackets++;
                if (rp->r_flags & XFLG_OWN)
                        break;
                ds->ds_if.if_opackets++;
-               ifxp = &ds->ds_deuba.ifu_w[ds->ds_xindex];
+               ifxp = &ds->ds_ifw[ds->ds_xindex];
                /* check for unusual conditions */
                if (rp->r_flags & (XFLG_ERRS|XFLG_MTCH|XFLG_ONE|XFLG_MORE)) {
                        if (rp->r_flags & XFLG_ERRS) {
                /* check for unusual conditions */
                if (rp->r_flags & (XFLG_ERRS|XFLG_MTCH|XFLG_ONE|XFLG_MORE)) {
                        if (rp->r_flags & XFLG_ERRS) {
@@ -463,13 +446,13 @@ deintr(unit)
                        } else if (rp->r_flags & XFLG_MTCH) {
                                /* received our own packet */
                                ds->ds_if.if_ipackets++;
                        } else if (rp->r_flags & XFLG_MTCH) {
                                /* received our own packet */
                                ds->ds_if.if_ipackets++;
-                               deread(ds, &ifxp->x_ifrw,
+                               deread(ds, &ifxp->ifrw,
                                    rp->r_slen - sizeof (struct ether_header));
                        }
                }
                                    rp->r_slen - sizeof (struct ether_header));
                        }
                }
-               if (ifxp->x_xtofree) {
-                       m_freem(ifxp->x_xtofree);
-                       ifxp->x_xtofree = 0;
+               if (ifxp->ifw_xtofree) {
+                       m_freem(ifxp->ifw_xtofree);
+                       ifxp->ifw_xtofree = 0;
                }
                /* check if next transmit buffer also finished */
                ds->ds_xindex++;
                }
                /* check if next transmit buffer also finished */
                ds->ds_xindex++;
@@ -504,9 +487,9 @@ derecv(unit)
        rp = &ds->ds_rrent[ds->ds_rindex];
        while ((rp->r_flags & RFLG_OWN) == 0) {
                ds->ds_if.if_ipackets++;
        rp = &ds->ds_rrent[ds->ds_rindex];
        while ((rp->r_flags & RFLG_OWN) == 0) {
                ds->ds_if.if_ipackets++;
-               if (ds->ds_deuba.ifu_flags & UBA_NEEDBDP)
-                       UBAPURGE(ds->ds_deuba.ifu_uba,
-                       ds->ds_deuba.ifu_r[ds->ds_rindex].ifrw_bdp);
+               if (ds->ds_deuba.iff_flags & UBA_NEEDBDP)
+                       UBAPURGE(ds->ds_deuba.iff_uba,
+                       ds->ds_ifr[ds->ds_rindex].ifrw_bdp);
                len = (rp->r_lenerr&RERR_MLEN) - sizeof (struct ether_header)
                        - 4;    /* don't forget checksum! */
                /* check for errors */
                len = (rp->r_lenerr&RERR_MLEN) - sizeof (struct ether_header)
                        - 4;    /* don't forget checksum! */
                /* check for errors */
@@ -520,7 +503,7 @@ derecv(unit)
                                unit, rp->r_flags, RFLG_BITS, rp->r_lenerr,
                                RERR_BITS, len);
                } else
                                unit, rp->r_flags, RFLG_BITS, rp->r_lenerr,
                                RERR_BITS, len);
                } else
-                       deread(ds, &ds->ds_deuba.ifu_r[ds->ds_rindex], len);
+                       deread(ds, &ds->ds_ifr[ds->ds_rindex], len);
 
                /* hang the receive buffer again */
                rp->r_lenerr = 0;
 
                /* hang the receive buffer again */
                rp->r_lenerr = 0;
@@ -574,16 +557,20 @@ deread(ds, ifrw, len)
 
        /*
         * Pull packet off interface.  Off is nonzero if packet
 
        /*
         * Pull packet off interface.  Off is nonzero if packet
-        * has trailing header; deget will then force this header
+        * has trailing header; if_ubaget will then force this header
         * information to be at the front, but we still have to drop
         * the type and length which are at the front of any trailer data.
         */
         * information to be at the front, but we still have to drop
         * the type and length which are at the front of any trailer data.
         */
-       m = deget(&ds->ds_deuba, ifrw, len, off);
+       m = if_ubaget(&ds->ds_deuba, ifrw, len, off, &ds->ds_if);
        if (m == 0)
                return;
        if (off) {
        if (m == 0)
                return;
        if (off) {
+               struct ifnet *ifp;
+
+               ifp = *(mtod(m, struct ifnet **));
                m->m_off += 2 * sizeof (u_short);
                m->m_len -= 2 * sizeof (u_short);
                m->m_off += 2 * sizeof (u_short);
                m->m_len -= 2 * sizeof (u_short);
+               *(mtod(m, struct ifnet **)) = ifp;
        }
        switch (eh->ether_type) {
 
        }
        switch (eh->ether_type) {
 
@@ -741,270 +728,6 @@ bad:
        return (error);
 }
 
        return (error);
 }
 
-/*
- * Routines supporting UNIBUS network interfaces.
- */
-
-/*
- * Init UNIBUS for interface on uban whose headers of size hlen are to
- * end on a page boundary.  We allocate a UNIBUS map register for the page
- * with the header, and nmr more UNIBUS map registers for i/o on the adapter,
- * doing this for each receive and transmit buffer.  We also
- * allocate page frames in the mbuffer pool for these pages.
- */
-de_ubainit(ifu, uban, hlen, nmr)
-       register struct deuba *ifu;
-       int uban, hlen, nmr;
-{
-       register caddr_t cp, dp;
-       register struct ifrw *ifrw;
-       register struct ifxmt *ifxp;
-       int i, ncl;
-
-       ncl = clrnd(nmr + CLSIZE) / CLSIZE;
-       if (ifu->ifu_r[0].ifrw_addr)
-               /*
-                * If the first read buffer has a non-zero
-                * address, it means we have already allocated core
-                */
-               cp = ifu->ifu_r[0].ifrw_addr - (CLBYTES - hlen);
-       else {
-               cp = m_clalloc(NTOT * ncl, MPG_SPACE);
-               if (cp == 0)
-                       return (0);
-               ifu->ifu_hlen = hlen;
-               ifu->ifu_uban = uban;
-               ifu->ifu_uba = uba_hd[uban].uh_uba;
-               dp = cp + CLBYTES - hlen;
-               for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++) {
-                       ifrw->ifrw_addr = dp;
-                       dp += ncl * CLBYTES;
-               }
-               for (ifxp = ifu->ifu_w; ifxp < &ifu->ifu_w[NXMT]; ifxp++) {
-                       ifxp->x_ifrw.ifrw_addr = dp;
-                       dp += ncl * CLBYTES;
-               }
-       }
-       /* allocate for receive ring */
-       for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++) {
-               if (de_ubaalloc(ifu, ifrw, nmr) == 0) {
-                       struct ifrw *rw;
-
-                       for (rw = ifu->ifu_r; rw < ifrw; rw++)
-                               ubarelse(ifu->ifu_uban, &rw->ifrw_info);
-                       goto bad;
-               }
-       }
-       /* and now transmit ring */
-       for (ifxp = ifu->ifu_w; ifxp < &ifu->ifu_w[NXMT]; ifxp++) {
-               ifrw = &ifxp->x_ifrw;
-               if (de_ubaalloc(ifu, ifrw, nmr) == 0) {
-                       struct ifxmt *xp;
-
-                       for (xp = ifu->ifu_w; xp < ifxp; xp++)
-                               ubarelse(ifu->ifu_uban, &xp->x_ifrw.ifrw_info);
-                       for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++)
-                               ubarelse(ifu->ifu_uban, &ifrw->ifrw_info);
-                       goto bad;
-               }
-               for (i = 0; i < nmr; i++)
-                       ifxp->x_map[i] = ifrw->ifrw_mr[i];
-               ifxp->x_xswapd = 0;
-       }
-       return (1);
-bad:
-       m_pgfree(cp, NTOT * ncl);
-       ifu->ifu_r[0].ifrw_addr = 0;
-       return(0);
-}
-
-/*
- * Setup either a ifrw structure by allocating UNIBUS map registers,
- * possibly a buffered data path, and initializing the fields of
- * the ifrw structure to minimize run-time overhead.
- */
-static
-de_ubaalloc(ifu, ifrw, nmr)
-       struct deuba *ifu;
-       register struct ifrw *ifrw;
-       int nmr;
-{
-       register int info;
-
-       info =
-           uballoc(ifu->ifu_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->ifu_hlen,
-               ifu->ifu_flags);
-       if (info == 0)
-               return (0);
-       ifrw->ifrw_info = info;
-       ifrw->ifrw_bdp = UBAI_BDP(info);
-       ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
-       ifrw->ifrw_mr = &ifu->ifu_uba->uba_map[UBAI_MR(info) + 1];
-       return (1);
-}
-
-/*
- * Pull read data off a interface.
- * Len is length of data, with local net header stripped.
- * Off is non-zero if a trailer protocol was used, and
- * gives the offset of the trailer information.
- * We copy the trailer information and then all the normal
- * data into mbufs.  When full cluster sized units are present
- * on the interface on cluster boundaries we can get them more
- * easily by remapping, and take advantage of this here.
- */
-struct mbuf *
-deget(ifu, ifrw, totlen, off0)
-       register struct deuba *ifu;
-       register struct ifrw *ifrw;
-       int totlen, off0;
-{
-       struct mbuf *top, **mp, *m;
-       int off = off0, len;
-       register caddr_t cp = ifrw->ifrw_addr + ifu->ifu_hlen;
-
-       top = 0;
-       mp = &top;
-       while (totlen > 0) {
-               MGET(m, M_DONTWAIT, MT_DATA);
-               if (m == 0)
-                       goto bad;
-               if (off) {
-                       len = totlen - off;
-                       cp = ifrw->ifrw_addr + ifu->ifu_hlen + off;
-               } else
-                       len = totlen;
-               if (len >= CLBYTES) {
-                       struct mbuf *p;
-                       struct pte *cpte, *ppte;
-                       int x, *ip, i;
-
-                       MCLGET(p, 1);
-                       if (p == 0)
-                               goto nopage;
-                       len = m->m_len = CLBYTES;
-                       m->m_off = (int)p - (int)m;
-                       if (!claligned(cp))
-                               goto copy;
-
-                       /*
-                        * Switch pages mapped to UNIBUS with new page p,
-                        * as quick form of copy.  Remap UNIBUS and invalidate.
-                        */
-                       cpte = &Mbmap[mtocl(cp)*CLSIZE];
-                       ppte = &Mbmap[mtocl(p)*CLSIZE];
-                       x = btop(cp - ifrw->ifrw_addr);
-                       ip = (int *)&ifrw->ifrw_mr[x];
-                       for (i = 0; i < CLSIZE; i++) {
-                               struct pte t;
-                               t = *ppte; *ppte++ = *cpte; *cpte = t;
-                               *ip++ =
-                                   cpte++->pg_pfnum|ifrw->ifrw_proto;
-                               mtpr(TBIS, cp);
-                               cp += NBPG;
-                               mtpr(TBIS, (caddr_t)p);
-                               p += NBPG / sizeof (*p);
-                       }
-                       goto nocopy;
-               }
-nopage:
-               m->m_len = MIN(MLEN, len);
-               m->m_off = MMINOFF;
-copy:
-               bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len);
-               cp += m->m_len;
-nocopy:
-               *mp = m;
-               mp = &m->m_next;
-               if (off) {
-                       /* sort of an ALGOL-W style for statement... */
-                       off += m->m_len;
-                       if (off == totlen) {
-                               cp = ifrw->ifrw_addr + ifu->ifu_hlen;
-                               off = 0;
-                               totlen = off0;
-                       }
-               } else
-                       totlen -= m->m_len;
-       }
-       return (top);
-bad:
-       m_freem(top);
-       return (0);
-}
-
-/*
- * Map a chain of mbufs onto a network interface
- * in preparation for an i/o operation.
- * The argument chain of mbufs includes the local network
- * header which is copied to be in the mapped, aligned
- * i/o space.
- */
-deput(ifu, n, m)
-       struct deuba *ifu;
-       int n;
-       register struct mbuf *m;
-{
-       register struct mbuf *mp;
-       register caddr_t cp;
-       register struct ifxmt *ifxp;
-       register struct ifrw *ifrw;
-       register int i;
-       int xswapd = 0;
-       int x, cc, t;
-       caddr_t dp;
-
-       ifxp = &ifu->ifu_w[n];
-       ifrw = &ifxp->x_ifrw;
-       cp = ifrw->ifrw_addr;
-       while (m) {
-               dp = mtod(m, char *);
-               if (claligned(cp) && claligned(dp) && m->m_len == CLBYTES) {
-                       struct pte *pte; int *ip;
-                       pte = &Mbmap[mtocl(dp)*CLSIZE];
-                       x = btop(cp - ifrw->ifrw_addr);
-                       ip = (int *)&ifrw->ifrw_mr[x];
-                       for (i = 0; i < CLSIZE; i++)
-                               *ip++ =
-                                   ifrw->ifrw_proto | pte++->pg_pfnum;
-                       xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
-                       mp = m->m_next;
-                       m->m_next = ifxp->x_xtofree;
-                       ifxp->x_xtofree = m;
-                       cp += m->m_len;
-               } else {
-                       bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len);
-                       cp += m->m_len;
-                       MFREE(m, mp);
-               }
-               m = mp;
-       }
-
-       /*
-        * Xswapd is the set of clusters we just mapped out.  Ifxp->x_xswapd
-        * is the set of clusters mapped out from before.  We compute
-        * the number of clusters involved in this operation in x.
-        * Clusters mapped out before and involved in this operation
-        * should be unmapped so original pages will be accessed by the device.
-        */
-       cc = cp - ifrw->ifrw_addr;
-       x = ((cc - ifu->ifu_hlen) + CLBYTES - 1) >> CLSHIFT;
-       ifxp->x_xswapd &= ~xswapd;
-       while (i = ffs(ifxp->x_xswapd)) {
-               i--;
-               if (i >= x)
-                       break;
-               ifxp->x_xswapd &= ~(1<<i);
-               i *= CLSIZE;
-               for (t = 0; t < CLSIZE; t++) {
-                       ifrw->ifrw_mr[i] = ifxp->x_map[i];
-                       i++;
-               }
-       }
-       ifxp->x_xswapd |= xswapd;
-       return (cc);
-}
-
 /*
  * Process an ioctl request.
  */
 /*
  * Process an ioctl request.
  */
@@ -1079,6 +802,4 @@ int unit;
                    ui->ui_unit, csr0, PCSR0_BITS, 
                    addr->pcsr1, PCSR1_BITS);
 }
                    ui->ui_unit, csr0, PCSR0_BITS, 
                    addr->pcsr1, PCSR1_BITS);
 }
-
 #endif
 #endif
-
index 76a7328..36b0880 100644 (file)
@@ -3,7 +3,7 @@
  * 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_dmc.c    6.6 (Berkeley) %G%
+ *     @(#)if_dmc.c    6.7 (Berkeley) %G%
  */
 
 #include "dmc.h"
  */
 
 #include "dmc.h"
 #include "../net/if.h"
 #include "../net/netisr.h"
 #include "../net/route.h"
 #include "../net/if.h"
 #include "../net/netisr.h"
 #include "../net/route.h"
+
+#ifdef BBNNET
+#define        INET
+#endif
+#ifdef INET
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/ip.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../netinet/ip.h"
-#include "../netinet/ip_var.h"
+#endif
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
@@ -68,8 +73,7 @@ struct        uba_driver dmcdriver =
 
 #define NRCV 7
 #define NXMT 3 
 
 #define NRCV 7
 #define NXMT 3 
-#define NTOT (NRCV + NXMT)
-#define NCMDS  (NTOT+4)        /* size of command queue */
+#define NCMDS  (NRCV+NXMT+4)   /* size of command queue */
 
 #define printd if(dmcdebug)printf
 int dmcdebug = 0;
 
 #define printd if(dmcdebug)printf
 int dmcdebug = 0;
@@ -87,27 +91,6 @@ struct  dmc_command {
        struct  dmc_command *qp_next;   /* next command on queue */
 };
 
        struct  dmc_command *qp_next;   /* next command on queue */
 };
 
-/*
- * The dmcuba structures generalize the ifuba structure
- * to an arbitrary number of receive and transmit buffers.
- */
-struct ifxmt {
-       struct  ifrw x_ifrw;            /* mapping info */
-       struct  pte x_map[IF_MAXNUBAMR];        /* output base pages */
-       short   x_xswapd;               /* mask of clusters swapped */
-       struct  mbuf *x_xtofree;        /* pages being dma'd out */
-};
-
-struct dmcuba {
-       short   ifu_uban;               /* uba number */
-       short   ifu_hlen;               /* local net header length */
-       struct  uba_regs *ifu_uba;      /* uba regs, in vm */
-       struct  ifrw ifu_r[NRCV];       /* receive information */
-       struct  ifxmt ifu_w[NXMT];      /* transmit information */
-                               /* these should only be pointers */
-       short   ifu_flags;              /* used during uballoc's */
-};
-
 struct dmcbufs {
        int     ubinfo;         /* from uballoc */
        short   cc;             /* buffer size */
 struct dmcbufs {
        int     ubinfo;         /* from uballoc */
        short   cc;             /* buffer size */
@@ -118,7 +101,6 @@ struct dmcbufs {
 #define        DBUF_XMIT       4       /* transmit buffer */
 #define        DBUF_RCV        8       /* receive buffer */
 
 #define        DBUF_XMIT       4       /* transmit buffer */
 #define        DBUF_RCV        8       /* receive buffer */
 
-struct mbuf *dmc_get();
 
 /*
  * DMC software status per interface.
 
 /*
  * DMC software status per interface.
@@ -141,7 +123,9 @@ struct dmc_softc {
        struct  ifnet sc_if;            /* network-visible interface */
        struct  dmcbufs sc_rbufs[NRCV]; /* receive buffer info */
        struct  dmcbufs sc_xbufs[NXMT]; /* transmit buffer info */
        struct  ifnet sc_if;            /* network-visible interface */
        struct  dmcbufs sc_rbufs[NRCV]; /* receive buffer info */
        struct  dmcbufs sc_xbufs[NXMT]; /* transmit buffer info */
-       struct  dmcuba sc_ifuba;        /* UNIBUS resources */
+       struct  ifubinfo sc_ifuba;      /* UNIBUS resources */
+       struct  ifrw sc_ifr[NRCV];      /* UNIBUS receive buffer maps */
+       struct  ifxmt sc_ifw[NXMT];     /* UNIBUS receive buffer maps */
        int     sc_ubinfo;              /* UBA mapping info for base table */
        int     sc_errors[4];           /* non-fatal error counters */
 #define sc_datck sc_errors[0]
        int     sc_ubinfo;              /* UBA mapping info for base table */
        int     sc_errors[4];           /* non-fatal error counters */
 #define sc_datck sc_errors[0]
@@ -234,13 +218,13 @@ dmcattach(ui)
        sc->sc_if.if_ioctl = dmcioctl;
        sc->sc_if.if_reset = dmcreset;
        sc->sc_if.if_flags = IFF_POINTOPOINT;
        sc->sc_if.if_ioctl = dmcioctl;
        sc->sc_if.if_reset = dmcreset;
        sc->sc_if.if_flags = IFF_POINTOPOINT;
-       sc->sc_ifuba.ifu_flags = UBA_CANTWAIT;
+       sc->sc_ifuba.iff_flags = UBA_CANTWAIT;
 
 
-       if_attach(&sc->sc_if);
        if (dmctimer == 0) {
                dmctimer = 1;
                timeout(dmcwatch, (caddr_t) 0, hz);
        }
        if (dmctimer == 0) {
                dmctimer = 1;
                timeout(dmcwatch, (caddr_t) 0, hz);
        }
+       if_attach(&sc->sc_if);
 }
 
 /*
 }
 
 /*
@@ -306,8 +290,9 @@ dmcinit(unit)
        /* initialize UNIBUS resources */
        sc->sc_iused = sc->sc_oused = 0;
        if ((ifp->if_flags & IFF_RUNNING) == 0) {
        /* initialize UNIBUS resources */
        sc->sc_iused = sc->sc_oused = 0;
        if ((ifp->if_flags & IFF_RUNNING) == 0) {
-               if (dmc_ubainit(&sc->sc_ifuba, ui->ui_ubanum,
-                   sizeof(struct dmc_header), (int)btoc(DMCMTU)) == 0) {
+               if (if_ubaminit(&sc->sc_ifuba, ui->ui_ubanum,
+                   sizeof(struct dmc_header), (int)btoc(DMCMTU),
+                   sc->sc_ifr, NRCV, sc->sc_ifw, NXMT) == 0) {
                        printf("dmc%d: can't allocate uba resources\n", unit);
                        ifp->if_flags &= ~IFF_UP;
                        return;
                        printf("dmc%d: can't allocate uba resources\n", unit);
                        ifp->if_flags &= ~IFF_UP;
                        return;
@@ -317,7 +302,7 @@ dmcinit(unit)
 
        /* initialize buffer pool */
        /* receives */
 
        /* initialize buffer pool */
        /* receives */
-       ifrw = &sc->sc_ifuba.ifu_r[0];
+       ifrw = &sc->sc_ifr[0];
        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
                rp->ubinfo = ifrw->ifrw_info & 0x3ffff;
                rp->cc = DMCMTU + sizeof (struct dmc_header);
        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
                rp->ubinfo = ifrw->ifrw_info & 0x3ffff;
                rp->cc = DMCMTU + sizeof (struct dmc_header);
@@ -325,9 +310,9 @@ dmcinit(unit)
                ifrw++; 
        }
        /* transmits */
                ifrw++; 
        }
        /* transmits */
-       ifxp = &sc->sc_ifuba.ifu_w[0];
+       ifxp = &sc->sc_ifw[0];
        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
-               rp->ubinfo = ifxp->x_ifrw.ifrw_info & 0x3ffff;
+               rp->ubinfo = ifxp->ifw_info & 0x3ffff;
                rp->cc = 0;
                rp->flags = DBUF_OURS|DBUF_XMIT;
                ifxp++; 
                rp->cc = 0;
                rp->flags = DBUF_OURS|DBUF_XMIT;
                ifxp++; 
@@ -408,7 +393,7 @@ dmcstart(dev)
                         * Have request mapped to UNIBUS for transmission
                         * and start the output.
                         */
                         * Have request mapped to UNIBUS for transmission
                         * and start the output.
                         */
-                       rp->cc = dmcput(&sc->sc_ifuba, n, m);
+                       rp->cc = if_ubaput(&sc->sc_ifuba, &sc->sc_ifw[n], m);
                        rp->cc &= DMC_CCOUNT;
                        sc->sc_oused++;
                        dmcload(sc, DMC_WRITE, rp->ubinfo, 
                        rp->cc &= DMC_CCOUNT;
                        sc->sc_oused++;
                        dmcload(sc, DMC_WRITE, rp->ubinfo, 
@@ -553,7 +538,7 @@ dmcxint(unit)
                         */
                        ifp->if_ipackets++;
                        /* find location in dmcuba struct */
                         */
                        ifp->if_ipackets++;
                        /* find location in dmcuba struct */
-                       ifrw= &sc->sc_ifuba.ifu_r[0];
+                       ifrw= &sc->sc_ifr[0];
                        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
                                if(rp->ubinfo == pkaddr)
                                        break;
                        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
                                if(rp->ubinfo == pkaddr)
                                        break;
@@ -601,12 +586,16 @@ dmcxint(unit)
                         * but we still have to drop the type and length
                         * which are at the front of any trailer data.
                         */
                         * but we still have to drop the type and length
                         * which are at the front of any trailer data.
                         */
-                       m = dmc_get(&sc->sc_ifuba, ifrw, len, off);
+                       m = if_ubaget(&sc->sc_ifuba, ifrw, len, off, ifp);
                        if (m == 0)
                                goto setup;
                        if (off) {
                        if (m == 0)
                                goto setup;
                        if (off) {
+                               struct ifnet *ifp;
+
+                               ifp = *(mtod(m, struct ifnet **));
                                m->m_off += 2 * sizeof (u_short);
                                m->m_len -= 2 * sizeof (u_short);
                                m->m_off += 2 * sizeof (u_short);
                                m->m_len -= 2 * sizeof (u_short);
+                               *(mtod(m, struct ifnet **)) = ifp;
                        }
                        switch (dh->dmc_type) {
 
                        }
                        switch (dh->dmc_type) {
 
@@ -642,7 +631,7 @@ dmcxint(unit)
                         */
                        ifp->if_opackets++;
                        /* find associated dmcbuf structure */
                         */
                        ifp->if_opackets++;
                        /* find associated dmcbuf structure */
-                       ifxp = &sc->sc_ifuba.ifu_w[0];
+                       ifxp = &sc->sc_ifw[0];
                        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
                                if(rp->ubinfo == pkaddr)
                                        break;
                        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
                                if(rp->ubinfo == pkaddr)
                                        break;
@@ -657,9 +646,9 @@ dmcxint(unit)
                                printf("dmc%d: unallocated packet 0x%x\n",
                                    unit, pkaddr);
                        /* mark buffer free */
                                printf("dmc%d: unallocated packet 0x%x\n",
                                    unit, pkaddr);
                        /* mark buffer free */
-                       if (ifxp->x_xtofree) {
-                               (void)m_freem(ifxp->x_xtofree);
-                               ifxp->x_xtofree = 0;
+                       if (ifxp->ifw_xtofree) {
+                               (void)m_freem(ifxp->ifw_xtofree);
+                               ifxp->ifw_xtofree = 0;
                        }
                        rp->flags &= ~DBUF_DMCS;
                        sc->sc_oused--;
                        }
                        rp->flags &= ~DBUF_DMCS;
                        sc->sc_oused--;
@@ -829,6 +818,7 @@ bad:
 /*
  * Process an ioctl request.
  */
 /*
  * Process an ioctl request.
  */
+/* ARGSUSED */
 dmcioctl(ifp, cmd, data)
        register struct ifnet *ifp;
        int cmd;
 dmcioctl(ifp, cmd, data)
        register struct ifnet *ifp;
        int cmd;
@@ -856,270 +846,6 @@ dmcioctl(ifp, cmd, data)
        return (error);
 }
 
        return (error);
 }
 
-
-/*
- * Routines supporting UNIBUS network interfaces.
- */
-
-/*
- * Init UNIBUS for interface on uban whose headers of size hlen are to
- * end on a page boundary.  We allocate a UNIBUS map register for the page
- * with the header, and nmr more UNIBUS map registers for i/o on the adapter,
- * doing this for each receive and transmit buffer.  We also
- * allocate page frames in the mbuffer pool for these pages.
- */
-dmc_ubainit(ifu, uban, hlen, nmr)
-       register struct dmcuba *ifu;
-       int uban, hlen, nmr;
-{
-       register caddr_t cp, dp;
-       register struct ifrw *ifrw;
-       register struct ifxmt *ifxp;
-       int i, ncl;
-
-       ncl = clrnd(nmr + CLSIZE) / CLSIZE;
-       if (ifu->ifu_r[0].ifrw_addr)
-               /*
-                * If the first read buffer has a non-zero
-                * address, it means we have already allocated core
-                */
-               cp = ifu->ifu_r[0].ifrw_addr - (CLBYTES - hlen);
-       else {
-               cp = m_clalloc(NTOT * ncl, MPG_SPACE);
-               if (cp == 0)
-                       return (0);
-               ifu->ifu_hlen = hlen;
-               ifu->ifu_uban = uban;
-               ifu->ifu_uba = uba_hd[uban].uh_uba;
-               dp = cp + CLBYTES - hlen;
-               for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++) {
-                       ifrw->ifrw_addr = dp;
-                       dp += ncl * CLBYTES;
-               }
-               for (ifxp = ifu->ifu_w; ifxp < &ifu->ifu_w[NXMT]; ifxp++) {
-                       ifxp->x_ifrw.ifrw_addr = dp;
-                       dp += ncl * CLBYTES;
-               }
-       }
-       /* allocate for receive ring */
-       for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++) {
-               if (dmc_ubaalloc(ifu, ifrw, nmr) == 0) {
-                       struct ifrw *rw;
-
-                       for (rw = ifu->ifu_r; rw < ifrw; rw++)
-                               ubarelse(ifu->ifu_uban, &rw->ifrw_info);
-                       goto bad;
-               }
-       }
-       /* and now transmit ring */
-       for (ifxp = ifu->ifu_w; ifxp < &ifu->ifu_w[NXMT]; ifxp++) {
-               ifrw = &ifxp->x_ifrw;
-               if (dmc_ubaalloc(ifu, ifrw, nmr) == 0) {
-                       struct ifxmt *xp;
-
-                       for (xp = ifu->ifu_w; xp < ifxp; xp++)
-                               ubarelse(ifu->ifu_uban, &xp->x_ifrw.ifrw_info);
-                       for (ifrw = ifu->ifu_r; ifrw < &ifu->ifu_r[NRCV]; ifrw++)
-                               ubarelse(ifu->ifu_uban, &ifrw->ifrw_info);
-                       goto bad;
-               }
-               for (i = 0; i < nmr; i++)
-                       ifxp->x_map[i] = ifrw->ifrw_mr[i];
-               ifxp->x_xswapd = 0;
-       }
-       return (1);
-bad:
-       m_pgfree(cp, NTOT * ncl);
-       ifu->ifu_r[0].ifrw_addr = 0;
-       return (0);
-}
-
-/*
- * Setup either a ifrw structure by allocating UNIBUS map registers,
- * possibly a buffered data path, and initializing the fields of
- * the ifrw structure to minimize run-time overhead.
- */
-static
-dmc_ubaalloc(ifu, ifrw, nmr)
-       struct dmcuba *ifu;
-       register struct ifrw *ifrw;
-       int nmr;
-{
-       register int info;
-
-       info =
-           uballoc(ifu->ifu_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->ifu_hlen,
-               ifu->ifu_flags);
-       if (info == 0)
-               return (0);
-       ifrw->ifrw_info = info;
-       ifrw->ifrw_bdp = UBAI_BDP(info);
-       ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
-       ifrw->ifrw_mr = &ifu->ifu_uba->uba_map[UBAI_MR(info) + 1];
-       return (1);
-}
-
-/*
- * Pull read data off a interface.
- * Len is length of data, with local net header stripped.
- * Off is non-zero if a trailer protocol was used, and
- * gives the offset of the trailer information.
- * We copy the trailer information and then all the normal
- * data into mbufs.  When full cluster sized units are present
- * on the interface on cluster boundaries we can get them more
- * easily by remapping, and take advantage of this here.
- */
-struct mbuf *
-dmc_get(ifu, ifrw, totlen, off0)
-       register struct dmcuba *ifu;
-       register struct ifrw *ifrw;
-       int totlen, off0;
-{
-       struct mbuf *top, **mp, *m;
-       int off = off0, len;
-       register caddr_t cp = ifrw->ifrw_addr + ifu->ifu_hlen;
-
-       top = 0;
-       mp = &top;
-       while (totlen > 0) {
-               MGET(m, M_DONTWAIT, MT_DATA);
-               if (m == 0)
-                       goto bad;
-               if (off) {
-                       len = totlen - off;
-                       cp = ifrw->ifrw_addr + ifu->ifu_hlen + off;
-               } else
-                       len = totlen;
-               if (len >= CLBYTES) {
-                       struct mbuf *p;
-                       struct pte *cpte, *ppte;
-                       int x, *ip, i;
-
-                       MCLGET(p, 1);
-                       if (p == 0)
-                               goto nopage;
-                       len = m->m_len = CLBYTES;
-                       m->m_off = (int)p - (int)m;
-                       if (!claligned(cp))
-                               goto copy;
-
-                       /*
-                        * Switch pages mapped to UNIBUS with new page p,
-                        * as quick form of copy.  Remap UNIBUS and invalidate.
-                        */
-                       cpte = &Mbmap[mtocl(cp)*CLSIZE];
-                       ppte = &Mbmap[mtocl(p)*CLSIZE];
-                       x = btop(cp - ifrw->ifrw_addr);
-                       ip = (int *)&ifrw->ifrw_mr[x];
-                       for (i = 0; i < CLSIZE; i++) {
-                               struct pte t;
-                               t = *ppte; *ppte++ = *cpte; *cpte = t;
-                               *ip++ =
-                                   cpte++->pg_pfnum|ifrw->ifrw_proto;
-                               mtpr(TBIS, cp);
-                               cp += NBPG;
-                               mtpr(TBIS, (caddr_t)p);
-                               p += NBPG / sizeof (*p);
-                       }
-                       goto nocopy;
-               }
-nopage:
-               m->m_len = MIN(MLEN, len);
-               m->m_off = MMINOFF;
-copy:
-               bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len);
-               cp += m->m_len;
-nocopy:
-               *mp = m;
-               mp = &m->m_next;
-               if (off) {
-                       /* sort of an ALGOL-W style for statement... */
-                       off += m->m_len;
-                       if (off == totlen) {
-                               cp = ifrw->ifrw_addr + ifu->ifu_hlen;
-                               off = 0;
-                               totlen = off0;
-                       }
-               } else
-                       totlen -= m->m_len;
-       }
-       return (top);
-bad:
-       m_freem(top);
-       return (0);
-}
-
-/*
- * Map a chain of mbufs onto a network interface
- * in preparation for an i/o operation.
- * The argument chain of mbufs includes the local network
- * header which is copied to be in the mapped, aligned
- * i/o space.
- */
-dmcput(ifu, n, m)
-       struct dmcuba *ifu;
-       int n;
-       register struct mbuf *m;
-{
-       register struct mbuf *mp;
-       register caddr_t cp;
-       register struct ifxmt *ifxp;
-       register struct ifrw *ifrw;
-       register int i;
-       int xswapd = 0;
-       int x, cc, t;
-       caddr_t dp;
-
-       ifxp = &ifu->ifu_w[n];
-       ifrw = &ifxp->x_ifrw;
-       cp = ifrw->ifrw_addr;
-       while (m) {
-               dp = mtod(m, char *);
-               if (claligned(cp) && claligned(dp) && m->m_len == CLBYTES) {
-                       struct pte *pte; int *ip;
-                       pte = &Mbmap[mtocl(dp)*CLSIZE];
-                       x = btop(cp - ifrw->ifrw_addr);
-                       ip = (int *)&ifrw->ifrw_mr[x];
-                       for (i = 0; i < CLSIZE; i++)
-                               *ip++ = ifrw->ifrw_proto | pte++->pg_pfnum;
-                       xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
-                       mp = m->m_next;
-                       m->m_next = ifxp->x_xtofree;
-                       ifxp->x_xtofree = m;
-                       cp += m->m_len;
-               } else {
-                       bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len);
-                       cp += m->m_len;
-                       MFREE(m, mp);
-               }
-               m = mp;
-       }
-
-       /*
-        * Xswapd is the set of clusters we just mapped out.  Ifxp->x_xswapd
-        * is the set of clusters mapped out from before.  We compute
-        * the number of clusters involved in this operation in x.
-        * Clusters mapped out before and involved in this operation
-        * should be unmapped so original pages will be accessed by the device.
-        */
-       cc = cp - ifrw->ifrw_addr;
-       x = ((cc - ifu->ifu_hlen) + CLBYTES - 1) >> CLSHIFT;
-       ifxp->x_xswapd &= ~xswapd;
-       while (i = ffs(ifxp->x_xswapd)) {
-               i--;
-               if (i >= x)
-                       break;
-               ifxp->x_xswapd &= ~(1<<i);
-               i *= CLSIZE;
-               for (t = 0; t < CLSIZE; t++) {
-                       ifrw->ifrw_mr[i] = ifxp->x_map[i];
-                       i++;
-               }
-       }
-       ifxp->x_xswapd |= xswapd;
-       return (cc);
-}
-
 /*
  * Restart after a fatal error.
  * Clear device and reinitialize.
 /*
  * Restart after a fatal error.
  * Clear device and reinitialize.
@@ -1132,8 +858,7 @@ dmcrestart(unit)
        register struct dmcdevice *addr;
        register struct ifxmt *ifxp;
        register int i;
        register struct dmcdevice *addr;
        register struct ifxmt *ifxp;
        register int i;
-       register struct mbuf *m;
-       struct dmcuba *ifu;
+       struct ifubinfo *ifu;
        
        addr = (struct dmcdevice *)ui->ui_addr;
        ifu = &sc->sc_ifuba;
        
        addr = (struct dmcdevice *)ui->ui_addr;
        ifu = &sc->sc_ifuba;
@@ -1156,18 +881,10 @@ dmcrestart(unit)
                return;
        }
 
                return;
        }
 
-#ifdef notdef  /* tef sez why throw these packets away??? */
-       /* purge send queue */
-       IF_DEQUEUE(&sc->sc_if.if_snd, m);
-       while (m) {
-               m_freem(m);
-               IF_DEQUEUE(&sc->sc_if.if_snd, m);
-       }
-#endif
-       for (ifxp = ifu->ifu_w; ifxp < &ifu->ifu_w[NXMT]; ifxp++) {
-               if (ifxp->x_xtofree) {
-                       (void) m_freem(ifxp->x_xtofree);
-                       ifxp->x_xtofree = 0;
+       for (ifxp = sc->sc_ifw; ifxp < &sc->sc_ifw[NXMT]; ifxp++) {
+               if (ifxp->ifw_xtofree) {
+                       (void) m_freem(ifxp->ifw_xtofree);
+                       ifxp->ifw_xtofree = 0;
                }
        }
 
                }
        }
 
index 4d7ce0a..4ee8cc2 100644 (file)
@@ -3,7 +3,7 @@
  * 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    6.5 (Berkeley) %G%
+ *     @(#)if_uba.c    6.6 (Berkeley) %G%
  */
 
 #include "../machine/pte.h"
  */
 
 #include "../machine/pte.h"
  * Init UNIBUS for interface on uban whose headers of size hlen are to
  * end on a page boundary.  We allocate a UNIBUS map register for the page
  * with the header, and nmr more UNIBUS map registers for i/o on the adapter,
  * Init UNIBUS for interface on uban whose headers of size hlen are to
  * end on a page boundary.  We allocate a UNIBUS map register for the page
  * with the header, and nmr more UNIBUS map registers for i/o on the adapter,
- * doing this twice: once for reading and once for writing.  We also
+ * doing this once for each read and once for each write buffer.  We also
  * allocate page frames in the mbuffer pool for these pages.
  */
  * allocate page frames in the mbuffer pool for these pages.
  */
-if_ubainit(ifu, uban, hlen, nmr)
-       register struct ifuba *ifu;
-       int uban, hlen, nmr;
+if_ubaminit(ifu, uban, hlen, nmr, ifr, nr, ifw, nw)
+       register struct ifubinfo *ifu;
+       int uban, hlen, nmr, nr, nw;
+       register struct ifrw *ifr;
+       register struct ifxmt *ifw;
 {
 {
-       register caddr_t cp;
+       register caddr_t p;
+       caddr_t cp;
        int i, ncl, off;
 
        if (hlen)
        int i, ncl, off;
 
        if (hlen)
@@ -52,56 +55,75 @@ if_ubainit(ifu, uban, hlen, nmr)
        ncl = clrnd(nmr) / CLSIZE;
        if (hlen)
                ncl++;
        ncl = clrnd(nmr) / CLSIZE;
        if (hlen)
                ncl++;
-       if (ifu->ifu_r.ifrw_addr)
-               cp = ifu->ifu_r.ifrw_addr - off;
+       if (ifr[0].ifrw_addr)
+               cp = ifr[0].ifrw_addr - off;
        else {
        else {
-               cp = m_clalloc(2 * ncl, MPG_SPACE);
+               cp = m_clalloc((nr + nw) * ncl, MPG_SPACE);
                if (cp == 0)
                        return (0);
                if (cp == 0)
                        return (0);
-               ifu->ifu_r.ifrw_addr = cp + off;
-               ifu->ifu_w.ifrw_addr = ifu->ifu_r.ifrw_addr + ncl * CLBYTES;
-               ifu->ifu_hlen = hlen;
-               ifu->ifu_uban = uban;
-               ifu->ifu_uba = uba_hd[uban].uh_uba;
+               p = cp;
+               for (i = 0; i < nr; i++) {
+                       ifr[i].ifrw_addr = p + off;
+                       p += ncl * CLBYTES;
+               }
+               for (i = 0; i < nw; i++) {
+                       ifw[i].ifw_base = p;
+                       ifw[i].ifw_addr = p + off;
+                       p += ncl * CLBYTES;
+               }
+               ifu->iff_hlen = hlen;
+               ifu->iff_uban = uban;
+               ifu->iff_uba = uba_hd[uban].uh_uba;
+       }
+       for (i = 0; i < nr; i++)
+               if (if_ubaalloc(ifu, &ifr[i], nmr) == 0) {
+                       nr = i;
+                       nw = 0;
+                       goto bad;
+               }
+       for (i = 0; i < nw; i++)
+               if (if_ubaalloc(ifu, &ifw[i].ifrw, nmr) == 0) {
+                       nw = i;
+                       goto bad;
+               }
+       while (--nw >= 0) {
+               for (i = 0; i < nmr; i++)
+                       ifw[nw].ifw_wmap[i] = ifw[nw].ifw_mr[i];
+               ifw[nw].ifw_xswapd = 0;
        }
        }
-       if (if_ubaalloc(ifu, &ifu->ifu_r, nmr) == 0)
-               goto bad;
-       if (if_ubaalloc(ifu, &ifu->ifu_w, nmr) == 0)
-               goto bad2;
-       for (i = 0; i < nmr; i++)
-               ifu->ifu_wmap[i] = ifu->ifu_w.ifrw_mr[i];
-       ifu->ifu_xswapd = 0;
        return (1);
        return (1);
-bad2:
-       ubarelse(ifu->ifu_uban, &ifu->ifu_r.ifrw_info);
 bad:
 bad:
-       m_pgfree(cp, 2 * ncl);
-       ifu->ifu_r.ifrw_addr = 0;
+       while (--nw >= 0)
+               ubarelse(ifu->iff_uban, &ifr[nw].ifrw_info);
+       while (--nr >= 0)
+               ubarelse(ifu->iff_uban, &ifw[nr].ifw_info);
+       m_pgfree(cp, (nr + nw) * ncl);
+       ifr[0].ifrw_addr = 0;
        return (0);
 }
 
 /*
        return (0);
 }
 
 /*
- * Setup either a ifrw structure by allocating UNIBUS map registers,
+ * Setup an ifrw structure by allocating UNIBUS map registers,
  * possibly a buffered data path, and initializing the fields of
  * the ifrw structure to minimize run-time overhead.
  */
 static
 if_ubaalloc(ifu, ifrw, nmr)
  * possibly a buffered data path, and initializing the fields of
  * the ifrw structure to minimize run-time overhead.
  */
 static
 if_ubaalloc(ifu, ifrw, nmr)
-       struct ifuba *ifu;
+       struct ifubinfo *ifu;
        register struct ifrw *ifrw;
        int nmr;
 {
        register int info;
 
        info =
        register struct ifrw *ifrw;
        int nmr;
 {
        register int info;
 
        info =
-           uballoc(ifu->ifu_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->ifu_hlen,
-               ifu->ifu_flags);
+           uballoc(ifu->iff_uban, ifrw->ifrw_addr, nmr*NBPG + ifu->iff_hlen,
+               ifu->iff_flags);
        if (info == 0)
                return (0);
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
        ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
        if (info == 0)
                return (0);
        ifrw->ifrw_info = info;
        ifrw->ifrw_bdp = UBAI_BDP(info);
        ifrw->ifrw_proto = UBAMR_MRV | (UBAI_BDP(info) << UBAMR_DPSHIFT);
-       ifrw->ifrw_mr = &ifu->ifu_uba->uba_map[UBAI_MR(info) + (ifu->ifu_hlen?
+       ifrw->ifrw_mr = &ifu->iff_uba->uba_map[UBAI_MR(info) + (ifu->iff_hlen?
                1 : 0)];
        return (1);
 }
                1 : 0)];
        return (1);
 }
@@ -119,15 +141,16 @@ if_ubaalloc(ifu, ifrw, nmr)
  * so that protocols can determine where incoming packets arrived.
  */
 struct mbuf *
  * so that protocols can determine where incoming packets arrived.
  */
 struct mbuf *
-if_rubaget(ifu, totlen, off0, ifp)
-       register struct ifuba *ifu;
+if_ubaget(ifu, ifr, totlen, off0, ifp)
+       struct ifubinfo *ifu;
+       register struct ifrw *ifr;
        int totlen, off0;
        struct ifnet *ifp;
 {
        int totlen, off0;
        struct ifnet *ifp;
 {
-       struct mbuf *top, **mp, *m;
+       struct mbuf *top, **mp;
+       register struct mbuf *m;
        int off = off0, len;
        int off = off0, len;
-       register caddr_t cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen;
-
+       register caddr_t cp = ifr->ifrw_addr + ifu->iff_hlen;
 
        top = 0;
        mp = &top;
 
        top = 0;
        mp = &top;
@@ -137,7 +160,7 @@ if_rubaget(ifu, totlen, off0, ifp)
                        goto bad;
                if (off) {
                        len = totlen - off;
                        goto bad;
                if (off) {
                        len = totlen - off;
-                       cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen + off;
+                       cp = ifr->ifrw_addr + ifu->iff_hlen + off;
                } else
                        len = totlen;
                if (len >= NBPG) {
                } else
                        len = totlen;
                if (len >= NBPG) {
@@ -157,7 +180,7 @@ if_rubaget(ifu, totlen, off0, ifp)
                        MCLGET(p, 1);
                        if (p == 0)
                                goto nopage;
                        MCLGET(p, 1);
                        if (p == 0)
                                goto nopage;
-                       len = m->m_len = min(len, CLBYTES);
+                       m->m_len = MIN(len, CLBYTES);
                        m->m_off = (int)p - (int)m;
                        if (!claligned(cp))
                                goto copy;
                        m->m_off = (int)p - (int)m;
                        if (!claligned(cp))
                                goto copy;
@@ -168,13 +191,13 @@ if_rubaget(ifu, totlen, off0, ifp)
                         */
                        cpte = &Mbmap[mtocl(cp)*CLSIZE];
                        ppte = &Mbmap[mtocl(p)*CLSIZE];
                         */
                        cpte = &Mbmap[mtocl(cp)*CLSIZE];
                        ppte = &Mbmap[mtocl(p)*CLSIZE];
-                       x = btop(cp - ifu->ifu_r.ifrw_addr);
-                       ip = (int *)&ifu->ifu_r.ifrw_mr[x];
+                       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++ =
                        for (i = 0; i < CLSIZE; i++) {
                                struct pte t;
                                t = *ppte; *ppte++ = *cpte; *cpte = t;
                                *ip++ =
-                                   cpte++->pg_pfnum|ifu->ifu_r.ifrw_proto;
+                                   cpte++->pg_pfnum|ifr->ifrw_proto;
                                mtpr(TBIS, cp);
                                cp += NBPG;
                                mtpr(TBIS, (caddr_t)p);
                                mtpr(TBIS, cp);
                                cp += NBPG;
                                mtpr(TBIS, (caddr_t)p);
@@ -202,7 +225,7 @@ nocopy:
                        /* sort of an ALGOL-W style for statement... */
                        off += m->m_len;
                        if (off == totlen) {
                        /* sort of an ALGOL-W style for statement... */
                        off += m->m_len;
                        if (off == totlen) {
-                               cp = ifu->ifu_r.ifrw_addr + ifu->ifu_hlen;
+                               cp = ifr->ifrw_addr + ifu->iff_hlen;
                                off = 0;
                                totlen = off0;
                        }
                                off = 0;
                                totlen = off0;
                        }
@@ -231,8 +254,9 @@ bad:
  * header which is copied to be in the mapped, aligned
  * i/o space.
  */
  * header which is copied to be in the mapped, aligned
  * i/o space.
  */
-if_wubaput(ifu, m)
-       register struct ifuba *ifu;
+if_ubaput(ifu, ifw, m)
+       struct ifubinfo *ifu;
+       register struct ifxmt *ifw;
        register struct mbuf *m;
 {
        register struct mbuf *mp;
        register struct mbuf *m;
 {
        register struct mbuf *mp;
@@ -241,22 +265,22 @@ if_wubaput(ifu, m)
        int xswapd = 0;
        int x, cc, t;
 
        int xswapd = 0;
        int x, cc, t;
 
-       cp = ifu->ifu_w.ifrw_addr;
+       cp = ifw->ifw_addr;
        while (m) {
                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];
        while (m) {
                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];
-                       x = btop(cp - ifu->ifu_w.ifrw_addr);
-                       ip = (int *)&ifu->ifu_w.ifrw_mr[x];
+                       x = btop(cp - ifw->ifw_addr);
+                       ip = (int *)&ifw->ifw_mr[x];
                        for (i = 0; i < CLSIZE; i++)
                                *ip++ =
                        for (i = 0; i < CLSIZE; i++)
                                *ip++ =
-                                   ifu->ifu_w.ifrw_proto | pte++->pg_pfnum;
+                                   ifw->ifw_proto | pte++->pg_pfnum;
                        xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
                        mp = m->m_next;
                        xswapd |= 1 << (x>>(CLSHIFT-PGSHIFT));
                        mp = m->m_next;
-                       m->m_next = ifu->ifu_xtofree;
-                       ifu->ifu_xtofree = m;
+                       m->m_next = ifw->ifw_xtofree;
+                       ifw->ifw_xtofree = m;
                        cp += m->m_len;
                } else {
                        bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len);
                        cp += m->m_len;
                } else {
                        bcopy(mtod(m, caddr_t), cp, (unsigned)m->m_len);
@@ -267,27 +291,26 @@ if_wubaput(ifu, m)
        }
 
        /*
        }
 
        /*
-        * Xswapd is the set of clusters we just mapped out.  Ifu->ifu_xswapd
+        * Xswapd is the set of clusters we just mapped out.  Ifu->iff_xswapd
         * is the set of clusters mapped out from before.  We compute
         * the number of clusters involved in this operation in x.
         * Clusters mapped out before and involved in this operation
         * should be unmapped so original pages will be accessed by the device.
         */
         * is the set of clusters mapped out from before.  We compute
         * the number of clusters involved in this operation in x.
         * Clusters mapped out before and involved in this operation
         * should be unmapped so original pages will be accessed by the device.
         */
-       cc = cp - ifu->ifu_w.ifrw_addr;
-       x = ((cc - ifu->ifu_hlen) + CLBYTES - 1) >> CLSHIFT;
-       ifu->ifu_xswapd &= ~xswapd;
-       xswapd &= ~ifu->ifu_xswapd;
-       while (i = ffs(ifu->ifu_xswapd)) {
+       cc = cp - ifw->ifw_addr;
+       x = ((cc - ifu->iff_hlen) + CLBYTES - 1) >> CLSHIFT;
+       ifw->ifw_xswapd &= ~xswapd;
+       while (i = ffs(ifw->ifw_xswapd)) {
                i--;
                if (i >= x)
                        break;
                i--;
                if (i >= x)
                        break;
-               ifu->ifu_xswapd &= ~(1<<i);
+               ifw->ifw_xswapd &= ~(1<<i);
                i *= CLSIZE;
                for (t = 0; t < CLSIZE; t++) {
                i *= CLSIZE;
                for (t = 0; t < CLSIZE; t++) {
-                       ifu->ifu_w.ifrw_mr[i] = ifu->ifu_wmap[i];
+                       ifw->ifw_mr[i] = ifw->ifw_wmap[i];
                        i++;
                }
        }
                        i++;
                }
        }
-       ifu->ifu_xswapd |= xswapd;
+       ifw->ifw_xswapd |= xswapd;
        return (cc);
 }
        return (cc);
 }
index 840c95f..17e6a0f 100644 (file)
@@ -3,7 +3,7 @@
  * 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.h    6.2 (Berkeley) %G%
+ *     @(#)if_uba.h    6.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -13,8 +13,9 @@
 
 #define        IF_MAXNUBAMR    10
 /*
 
 #define        IF_MAXNUBAMR    10
 /*
- * Each interface has one of these structures giving information
- * about UNIBUS resources held by the interface.
+ * Each interface has structures giving information
+ * about UNIBUS resources held by the interface
+ * for each send and receive buffer.
  *
  * We hold IF_NUBAMR map registers for datagram data, starting
  * at ifr_mr.  Map register ifr_mr[-1] maps the local network header
  *
  * We hold IF_NUBAMR map registers for datagram data, starting
  * at ifr_mr.  Map register ifr_mr[-1] maps the local network header
  * with the pages already containing the data, mapping the allocated
  * pages to replace the input pages for the next UNIBUS data input.
  */
  * with the pages already containing the data, mapping the allocated
  * pages to replace the input pages for the next UNIBUS data input.
  */
-struct ifuba {
-       short   ifu_uban;                       /* uba number */
-       short   ifu_hlen;                       /* local net header length */
-       struct  uba_regs *ifu_uba;              /* uba regs, in vm */
-       struct ifrw {
-               caddr_t ifrw_addr;              /* virt addr of header */
-               int     ifrw_bdp;               /* unibus bdp */
-               int     ifrw_info;              /* value from ubaalloc */
-               int     ifrw_proto;             /* map register prototype */
-               struct  pte *ifrw_mr;           /* base of map registers */
-       } ifu_r, ifu_w;
-       struct  pte ifu_wmap[IF_MAXNUBAMR];     /* base pages for output */
-       short   ifu_xswapd;                     /* mask of clusters swapped */
-       short   ifu_flags;                      /* used during uballoc's */
-       struct  mbuf *ifu_xtofree;              /* pages being dma'd out */
+
+/*
+ * Information per interface.
+ */
+struct ifubinfo {
+       short   iff_uban;                       /* uba number */
+       short   iff_hlen;                       /* local net header length */
+       struct  uba_regs *iff_uba;              /* uba regs, in vm */
+       short   iff_flags;                      /* used during uballoc's */
+};
+
+/*
+ * Information per buffer.
+ */
+struct ifrw {
+       caddr_t ifrw_addr;                      /* virt addr of header */
+       int     ifrw_bdp;                       /* unibus bdp */
+       int     ifrw_info;                      /* value from ubaalloc */
+       int     ifrw_proto;                     /* map register prototype */
+       struct  pte *ifrw_mr;                   /* base of map registers */
+};
+
+/*
+ * Information per transmit buffer, including the above.
+ */
+struct ifxmt {
+       struct  ifrw ifrw;
+       caddr_t ifw_base;                       /* virt addr of buffer */
+       struct  pte ifw_wmap[IF_MAXNUBAMR];     /* base pages for output */
+       struct  mbuf *ifw_xtofree;              /* pages being dma'd out */
+       short   ifw_xswapd;                     /* mask of clusters swapped */
+};
+#define        ifw_addr        ifrw.ifrw_addr
+#define        ifw_bdp         ifrw.ifrw_bdp
+#define        ifw_info        ifrw.ifrw_info
+#define        ifw_proto       ifrw.ifrw_proto
+#define        ifw_mr          ifrw.ifrw_mr
+
+/*
+ * Most interfaces have a single receive and a single transmit buffer,
+ * and use struct ifuba to store all of the unibus information.
+ */
+struct ifuba {
+       struct  ifubinfo ifu_info;
+       struct  ifrw ifu_r;
+       struct  ifxmt ifu_xmt;
 };
 
 };
 
+#define        ifu_uban        ifu_info.iff_uban
+#define        ifu_hlen        ifu_info.iff_hlen
+#define        ifu_uba         ifu_info.iff_uba
+#define        ifu_flags       ifu_info.iff_flags
+#define        ifu_w           ifu_xmt.ifrw
+#define        ifu_xtofree     ifu_xmt.ifw_xtofree
+
 #ifdef         KERNEL
 #ifdef         KERNEL
-struct mbuf *if_rubaget();
+#define        if_ubainit(ifuba, uban, hlen, nmr) \
+               if_ubaminit(&(ifuba)->ifu_info, uban, hlen, nmr, \
+                       &(ifuba)->ifu_r, 1, &(ifuba)->ifu_w, 1)
+#define        if_rubaget(ifu, totlen, off0, ifp) \
+               if_ubaget(&(ifu)->ifu_info, &(ifu)->ifu_r, totlen, off0, ifp)
+#define        if_wubaput(ifu, m) \
+               if_ubaput(&(ifu)->ifu_info, &(ifu)->ifu_w, m)
+struct mbuf *if_ubaget();
 #endif
 #endif