BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / vax / if / if_dmc.c
index 4149945..0e252ce 100644 (file)
@@ -1,9 +1,36 @@
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
  *
  *
- *     @(#)if_dmc.c    7.2 (Berkeley) %G%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)if_dmc.c    7.10 (Berkeley) 12/16/90
  */
 
 #include "dmc.h"
  */
 
 #include "dmc.h"
 
 /* #define DEBUG       /* for base table dump on fatal error */
 
 
 /* #define DEBUG       /* for base table dump on fatal error */
 
-#include "../machine/pte.h"
-
-#include "param.h"
-#include "systm.h"
-#include "mbuf.h"
-#include "buf.h"
-#include "ioctl.h"             /* must precede tty.h */
-#include "tty.h"
-#include "protosw.h"
-#include "socket.h"
-#include "syslog.h"
-#include "vmmac.h"
-#include "errno.h"
-
-#include "../net/if.h"
-#include "../net/netisr.h"
-#include "../net/route.h"
+#include "../include/pte.h"
+
+#include "sys/param.h"
+#include "sys/systm.h"
+#include "sys/mbuf.h"
+#include "sys/buf.h"
+#include "sys/ioctl.h"         /* must precede tty.h */
+#include "sys/tty.h"
+#include "sys/protosw.h"
+#include "sys/socket.h"
+#include "sys/syslog.h"
+#include "sys/vmmac.h"
+#include "sys/errno.h"
+#include "sys/time.h"
+#include "sys/kernel.h"
+
+#include "net/if.h"
+#include "net/netisr.h"
+#include "net/route.h"
 
 #ifdef INET
 
 #ifdef INET
-#include "../netinet/in.h"
-#include "../netinet/in_systm.h"
-#include "../netinet/in_var.h"
-#include "../netinet/ip.h"
+#include "netinet/in.h"
+#include "netinet/in_systm.h"
+#include "netinet/in_var.h"
+#include "netinet/ip.h"
 #endif
 
 #endif
 
-#include "../vax/cpu.h"
-#include "../vax/mtpr.h"
+#include "../include/cpu.h"
+#include "../include/mtpr.h"
 #include "if_uba.h"
 #include "if_dmc.h"
 #include "if_uba.h"
 #include "if_dmc.h"
-#include "../vaxuba/ubareg.h"
-#include "../vaxuba/ubavar.h"
+#include "../uba/ubareg.h"
+#include "../uba/ubavar.h"
 
 
-#include "../h/time.h"
-#include "../h/kernel.h"
 
 /*
  * output timeout value, sec.; should depend on line speed.
 
 /*
  * output timeout value, sec.; should depend on line speed.
@@ -267,7 +294,7 @@ dmcinit(unit)
         * (both local and destination for an address family).
         */
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
         * (both local and destination for an address family).
         */
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
-               if (ifa->ifa_addr.sa_family && ifa->ifa_dstaddr.sa_family)
+               if (ifa->ifa_addr->sa_family && ifa->ifa_dstaddr->sa_family)
                        break;
        if (ifa == (struct ifaddr *) 0)
                return;
                        break;
        if (ifa == (struct ifaddr *) 0)
                return;
@@ -306,7 +333,7 @@ dmcinit(unit)
        /* receives */
        ifrw = &sc->sc_ifr[0];
        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
        /* receives */
        ifrw = &sc->sc_ifr[0];
        for (rp = &sc->sc_rbufs[0]; rp < &sc->sc_rbufs[NRCV]; rp++) {
-               rp->ubinfo = ifrw->ifrw_info & 0x3ffff;
+               rp->ubinfo = UBAI_ADDR(ifrw->ifrw_info);
                rp->cc = DMCMTU + sizeof (struct dmc_header);
                rp->flags = DBUF_OURS|DBUF_RCV;
                ifrw++; 
                rp->cc = DMCMTU + sizeof (struct dmc_header);
                rp->flags = DBUF_OURS|DBUF_RCV;
                ifrw++; 
@@ -314,7 +341,7 @@ dmcinit(unit)
        /* transmits */
        ifxp = &sc->sc_ifw[0];
        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
        /* transmits */
        ifxp = &sc->sc_ifw[0];
        for (rp = &sc->sc_xbufs[0]; rp < &sc->sc_xbufs[NXMT]; rp++) {
-               rp->ubinfo = ifxp->ifw_info & 0x3ffff;
+               rp->ubinfo = UBAI_ADDR(ifxp->ifw_info);
                rp->cc = 0;
                rp->flags = DBUF_OURS|DBUF_XMIT;
                ifxp++; 
                rp->cc = 0;
                rp->flags = DBUF_OURS|DBUF_XMIT;
                ifxp++; 
@@ -330,8 +357,8 @@ dmcinit(unit)
        }
 
        /* base in */
        }
 
        /* base in */
-       base = sc->sc_ubinfo & 0x3ffff;
-       dmcload(sc, DMC_BASEI, base, (base>>2) & DMC_XMEM);
+       base = UBAI_ADDR(sc->sc_ubinfo);
+       dmcload(sc, DMC_BASEI, (u_short)base, (base>>2) & DMC_XMEM);
        /* specify half duplex operation, flags tell if primary */
        /* or secondary station */
        if (ui->ui_flags == 0)
        /* specify half duplex operation, flags tell if primary */
        /* or secondary station */
        if (ui->ui_flags == 0)
@@ -409,7 +436,8 @@ dmcstart(unit)
  */
 dmcload(sc, type, w0, w1)
        register struct dmc_softc *sc;
  */
 dmcload(sc, type, w0, w1)
        register struct dmc_softc *sc;
-       int type, w0, w1;
+       int type;
+       u_short w0, w1;
 {
        register struct dmcdevice *addr;
        register int unit, sps;
 {
        register struct dmcdevice *addr;
        register int unit, sps;
@@ -590,12 +618,6 @@ dmcxint(unit)
                        m = if_ubaget(&sc->sc_ifuba, ifrw, len, off, ifp);
                        if (m == 0)
                                goto setup;
                        m = if_ubaget(&sc->sc_ifuba, ifrw, len, off, ifp);
                        if (m == 0)
                                goto setup;
-                       if (off) {
-                               ifp = *(mtod(m, struct ifnet **));
-                               m->m_off += 2 * sizeof (u_short);
-                               m->m_len -= 2 * sizeof (u_short);
-                               *(mtod(m, struct ifnet **)) = ifp;
-                       }
                        switch (dh->dmc_type) {
 
 #ifdef INET
                        switch (dh->dmc_type) {
 
 #ifdef INET
@@ -619,7 +641,7 @@ dmcxint(unit)
 
        setup:
                        /* is this needed? */
 
        setup:
                        /* is this needed? */
-                       rp->ubinfo = ifrw->ifrw_info & 0x3ffff;
+                       rp->ubinfo = UBAI_ADDR(ifrw->ifrw_info);
 
                        dmcload(sc, DMC_READ, rp->ubinfo, 
                            ((rp->ubinfo >> 2) & DMC_XMEM) | rp->cc);
 
                        dmcload(sc, DMC_READ, rp->ubinfo, 
                            ((rp->ubinfo >> 2) & DMC_XMEM) | rp->cc);
@@ -712,7 +734,7 @@ dmcxint(unit)
                                 * procedure error
                                 */
                                sc->sc_flag |= DMC_RESTART;
                                 * procedure error
                                 */
                                sc->sc_flag |= DMC_RESTART;
-                               arg = sc->sc_ubinfo & 0x3ffff;
+                               arg = UBAI_ADDR(sc->sc_ubinfo);
                                dmcload(sc, DMC_BASEI, arg, (arg>>2)&DMC_XMEM);
                        }
                        break;
                                dmcload(sc, DMC_BASEI, arg, (arg>>2)&DMC_XMEM);
                        }
                        break;
@@ -750,12 +772,13 @@ dmcoutput(ifp, m0, dst)
        switch (dst->sa_family) {
 #ifdef INET
        case AF_INET:
        switch (dst->sa_family) {
 #ifdef INET
        case AF_INET:
-               off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
+               off = m->m_pkthdr.len - m->m_len;
                if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
                if (off > 0 && (off & 0x1ff) == 0 &&
                if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
                if (off > 0 && (off & 0x1ff) == 0 &&
-                   m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
+                   (m->m_flags & M_EXT) == 0 &&
+                   m->m_data >= m->m_pktdat + 2 * sizeof (u_short)) {
                        type = DMC_TRAILER + (off>>9);
                        type = DMC_TRAILER + (off>>9);
-                       m->m_off -= 2 * sizeof (u_short);
+                       m->m_data -= 2 * sizeof (u_short);
                        m->m_len += 2 * sizeof (u_short);
                        *mtod(m, u_short *) = htons((u_short)DMC_IPTYPE);
                        *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
                        m->m_len += 2 * sizeof (u_short);
                        *mtod(m, u_short *) = htons((u_short)DMC_IPTYPE);
                        *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len);
@@ -795,19 +818,10 @@ gottype:
         * Add local network header
         * (there is space for a uba on a vax to step on)
         */
         * Add local network header
         * (there is space for a uba on a vax to step on)
         */
-       if (m->m_off > MMAXOFF ||
-           MMINOFF + sizeof(struct dmc_header) > m->m_off) {
-               m = m_get(M_DONTWAIT, MT_HEADER);
-               if (m == 0) {
-                       error = ENOBUFS;
-                       goto bad;
-               }
-               m->m_next = m0;
-               m->m_off = MMINOFF;
-               m->m_len = sizeof (struct dmc_header);
-       } else {
-               m->m_off -= sizeof (struct dmc_header);
-               m->m_len += sizeof (struct dmc_header);
+       M_PREPEND(m, sizeof(struct dmc_header), M_DONTWAIT);
+       if (m == 0) {
+               error = ENOBUFS;
+               goto bad;
        }
        dh = mtod(m, struct dmc_header *);
        dh->dmc_type = htons((u_short)type);
        }
        dh = mtod(m, struct dmc_header *);
        dh->dmc_type = htons((u_short)type);