ioctls
[unix-history] / usr / src / sys / vax / if / if_dmc.c
index 8984dc9..f3705fa 100644 (file)
@@ -1,37 +1,45 @@
-/*     if_dmc.c        4.9     82/03/30        */
+/*     if_dmc.c        4.26    83/05/27        */
 
 #include "dmc.h"
 #if NDMC > 0
 #define printd if(dmcdebug)printf
 
 #include "dmc.h"
 #if NDMC > 0
 #define printd if(dmcdebug)printf
-int dmcdebug = 1;
+int dmcdebug = 0;
 /*
  * DMC11 device driver, internet version
  *
  * TODO
  *     allow more than one outstanding read or write.
 /*
  * DMC11 device driver, internet version
  *
  * TODO
  *     allow more than one outstanding read or write.
+ *
+ * UNTESTED WITH 4.1C
  */
  */
+#include "../machine/pte.h"
 
 #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 "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/tty.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/buf.h"
 #include "../h/tty.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
-#include "../h/ubareg.h"
-#include "../h/ubavar.h"
-#include "../h/cpu.h"
-#include "../h/mtpr.h"
 #include "../h/vmmac.h"
 #include "../h/vmmac.h"
-#include "../net/in.h"
-#include "../net/in_systm.h"
+#include <errno.h>
+
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/if_uba.h"
-#include "../net/if_dmc.h"
-#include "../net/ip.h"
-#include "../net/ip_var.h"
+#include "../net/netisr.h"
 #include "../net/route.h"
 #include "../net/route.h"
+#include "../netinet/in.h"
+#include "../netinet/in_systm.h"
+
+#include "../vax/cpu.h"
+#include "../vax/mtpr.h"
+#include "../vaxif/if_uba.h"
+#include "../vaxif/if_dmc.h"
+#include "../vaxuba/ubareg.h"
+#include "../vaxuba/ubavar.h"
+
+#ifndef DMC_USEMAINT
+#define        DMC_USEMAINT    1       /* use maintenance mode */
+#endif
 
 /*
  * Driver information for auto-configuration stuff.
 
 /*
  * Driver information for auto-configuration stuff.
@@ -43,7 +51,7 @@ struct        uba_driver dmcdriver =
        { dmcprobe, 0, dmcattach, 0, dmcstd, "dmc", dmcinfo };
 
 #define        DMC_AF  0xff            /* 8 bits of address type in ui_flags */
        { dmcprobe, 0, dmcattach, 0, dmcstd, "dmc", dmcinfo };
 
 #define        DMC_AF  0xff            /* 8 bits of address type in ui_flags */
-#define        DMC_NET 0xff00          /* 8 bits of net number in ui_flags */
+#define        DMC_NET 0xffffff00      /* 24 bits of net number in ui_flags */
 
 /*
  * DMC software status per interface.
 
 /*
  * DMC software status per interface.
@@ -84,7 +92,6 @@ dmcprobe(reg)
        register struct dmcdevice *addr = (struct dmcdevice *)reg;
        register int i;
 
        register struct dmcdevice *addr = (struct dmcdevice *)reg;
        register int i;
 
-COUNT(DMCPROBE);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        dmcrint(0); dmcxint(0);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        dmcrint(0); dmcxint(0);
@@ -100,6 +107,9 @@ COUNT(DMCPROBE);
        addr->bsel1 = DMC_MCLR;
        for (i = 100000; i && (addr->bsel1 & DMC_RUN) == 0; i--)
                ;
        addr->bsel1 = DMC_MCLR;
        for (i = 100000; i && (addr->bsel1 & DMC_RUN) == 0; i--)
                ;
+#ifdef ECHACK
+       br = 0x16;
+#endif
        return (1);
 }
 
        return (1);
 }
 
@@ -114,19 +124,19 @@ dmcattach(ui)
        register struct dmc_softc *sc = &dmc_softc[ui->ui_unit];
        register struct sockaddr_in *sin;
 
        register struct dmc_softc *sc = &dmc_softc[ui->ui_unit];
        register struct sockaddr_in *sin;
 
-COUNT(DMCATTACH);
        sc->sc_if.if_unit = ui->ui_unit;
        sc->sc_if.if_name = "dmc";
        sc->sc_if.if_mtu = DMCMTU;
        sc->sc_if.if_net = (ui->ui_flags & DMC_NET) >> 8;
        sc->sc_if.if_host[0] = 17;      /* random number */
        sin = (struct sockaddr_in *)&sc->sc_if.if_addr;
        sc->sc_if.if_unit = ui->ui_unit;
        sc->sc_if.if_name = "dmc";
        sc->sc_if.if_mtu = DMCMTU;
        sc->sc_if.if_net = (ui->ui_flags & DMC_NET) >> 8;
        sc->sc_if.if_host[0] = 17;      /* random number */
        sin = (struct sockaddr_in *)&sc->sc_if.if_addr;
-       sin->sa_family = AF_INET;
+       sin->sin_family = AF_INET;
        sin->sin_addr = if_makeaddr(sc->sc_if.if_net, sc->sc_if.if_host[0]);
        sc->sc_if.if_init = dmcinit;
        sc->sc_if.if_output = dmcoutput;
        sin->sin_addr = if_makeaddr(sc->sc_if.if_net, sc->sc_if.if_host[0]);
        sc->sc_if.if_init = dmcinit;
        sc->sc_if.if_output = dmcoutput;
-       sc->sc_if.if_ubareset = dmcreset;
-       sc->sc_ifuba.ifuba_flags = UBA_NEEDBDP;
+       sc->sc_if.if_reset = dmcreset;
+       /* DON'T KNOW IF THIS WILL WORK WITH A BDP AT HIGH SPEEDS */
+       sc->sc_ifuba.ifu_flags = UBA_NEEDBDP | UBA_CANTWAIT;
        if_attach(&sc->sc_if);
 }
 
        if_attach(&sc->sc_if);
 }
 
@@ -139,7 +149,6 @@ dmcreset(unit, uban)
 {
        register struct uba_device *ui;
 
 {
        register struct uba_device *ui;
 
-COUNT(DMCRESET);
        if (unit >= NDMC || (ui = dmcinfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
                return;
        if (unit >= NDMC || (ui = dmcinfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
                return;
@@ -158,7 +167,6 @@ dmcinit(unit)
        register struct dmcdevice *addr;
        int base;
 
        register struct dmcdevice *addr;
        int base;
 
-COUNT(DMCINIT);
        printd("dmcinit\n");
        if ((sc->sc_flag&DMCBMAPPED) == 0) {
                sc->sc_ubinfo = uballoc(ui->ui_ubanum,
        printd("dmcinit\n");
        if ((sc->sc_flag&DMCBMAPPED) == 0) {
                sc->sc_ubinfo = uballoc(ui->ui_ubanum,
@@ -176,15 +184,14 @@ COUNT(DMCINIT);
        base = sc->sc_ubinfo & 0x3ffff;
        printd("  base 0x%x\n", base);
        dmcload(sc, DMC_BASEI, base, (base>>2)&DMC_XMEM);
        base = sc->sc_ubinfo & 0x3ffff;
        printd("  base 0x%x\n", base);
        dmcload(sc, DMC_BASEI, base, (base>>2)&DMC_XMEM);
-       dmcload(sc, DMC_CNTLI, 0, 0);
+       dmcload(sc, DMC_CNTLI, 0, DMC_USEMAINT ? DMC_MAINT : 0);
        base = sc->sc_ifuba.ifu_r.ifrw_info & 0x3ffff;
        dmcload(sc, DMC_READ, base, ((base>>2)&DMC_XMEM)|DMCMTU);
        printd("  first read queued, addr 0x%x\n", base);
        sc->sc_if.if_flags |= IFF_UP;
        /* set up routing table entry */
        if ((sc->sc_if.if_flags & IFF_ROUTE) == 0) {
        base = sc->sc_ifuba.ifu_r.ifrw_info & 0x3ffff;
        dmcload(sc, DMC_READ, base, ((base>>2)&DMC_XMEM)|DMCMTU);
        printd("  first read queued, addr 0x%x\n", base);
        sc->sc_if.if_flags |= IFF_UP;
        /* set up routing table entry */
        if ((sc->sc_if.if_flags & IFF_ROUTE) == 0) {
-               rtinit(&sc->sc_if.if_addr, &sc->sc_if.if_addr,
-                       RTF_DIRECT|RTF_HOST|RTF_UP);
+               rtinit(&sc->sc_if.if_addr, &sc->sc_if.if_addr, RTF_HOST|RTF_UP);
                sc->sc_if.if_flags |= IFF_ROUTE;
        }
 }
                sc->sc_if.if_flags |= IFF_ROUTE;
        }
 }
@@ -198,12 +205,10 @@ dmcstart(dev)
        dev_t dev;
 {
        int unit = minor(dev);
        dev_t dev;
 {
        int unit = minor(dev);
-       struct uba_device *ui = dmcinfo[unit];
        register struct dmc_softc *sc = &dmc_softc[unit];
        int addr, len;
        struct mbuf *m;
 
        register struct dmc_softc *sc = &dmc_softc[unit];
        int addr, len;
        struct mbuf *m;
 
-COUNT(DMCSTART);
        printd("dmcstart\n");
        /*
         * Dequeue a request and map it to the UNIBUS.
        printd("dmcstart\n");
        /*
         * Dequeue a request and map it to the UNIBUS.
@@ -218,7 +223,7 @@ COUNT(DMCSTART);
         * Have request mapped to UNIBUS for transmission.
         * Purge any stale data from this BDP and start the output.
         */
         * Have request mapped to UNIBUS for transmission.
         * Purge any stale data from this BDP and start the output.
         */
-       if (sc->sc_ifuba.ifuba_flags & UBA_NEEDBDP)
+       if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->sc_ifuba.ifu_uba, sc->sc_ifuba.ifu_w.ifrw_bdp);
        addr = sc->sc_ifuba.ifu_w.ifrw_info & 0x3ffff;
        printd("  len %d, addr 0x%x, ", len, addr);
                UBAPURGE(sc->sc_ifuba.ifu_uba, sc->sc_ifuba.ifu_w.ifrw_bdp);
        addr = sc->sc_ifuba.ifu_w.ifrw_info & 0x3ffff;
        printd("  len %d, addr 0x%x, ", len, addr);
@@ -237,7 +242,6 @@ dmcload(sc, type, w0, w1)
        register struct dmcdevice *addr;
        register int unit, sps, n;
 
        register struct dmcdevice *addr;
        register int unit, sps, n;
 
-COUNT(DMCLOAD);
        printd("dmcload: 0x%x 0x%x 0x%x\n", type, w0, w1);
        unit = sc - dmc_softc;
        addr = (struct dmcdevice *)dmcinfo[unit]->ui_addr;
        printd("dmcload: 0x%x 0x%x 0x%x\n", type, w0, w1);
        unit = sc - dmc_softc;
        addr = (struct dmcdevice *)dmcinfo[unit]->ui_addr;
@@ -264,26 +268,17 @@ dmcrint(unit)
        register struct dmc_softc *sc;
        register struct dmcdevice *addr;
        register int n;
        register struct dmc_softc *sc;
        register struct dmcdevice *addr;
        register int n;
-       int w0, w1; /* DEBUG */
 
 
-COUNT(DMCRINT);
        addr = (struct dmcdevice *)dmcinfo[unit]->ui_addr;
        sc = &dmc_softc[unit];
        while (addr->bsel0&DMC_RDYI) {
        addr = (struct dmcdevice *)dmcinfo[unit]->ui_addr;
        sc = &dmc_softc[unit];
        while (addr->bsel0&DMC_RDYI) {
-               w0 = getw(&sc->sc_que); /* DEBUG */
-               addr->sel4 = w0; /* DEBUG */
-               w1 = getw(&sc->sc_que); /* DEBUG */
-               addr->sel6 = w1; /* DEBUG */
-               /* DEBUG
                addr->sel4 = getw(&sc->sc_que);
                addr->sel6 = getw(&sc->sc_que);
                addr->sel4 = getw(&sc->sc_que);
                addr->sel6 = getw(&sc->sc_que);
-               DEBUG */
                addr->bsel0 &= ~(DMC_IEI|DMC_RQI);
                addr->bsel0 &= ~(DMC_IEI|DMC_RQI);
-               printd("  w0 0x%x, w1 0x%x\n", w0, w1);
                while (addr->bsel0&DMC_RDYI)
                        ;
                if (sc->sc_que.c_cc == 0)
                while (addr->bsel0&DMC_RDYI)
                        ;
                if (sc->sc_que.c_cc == 0)
-                       return;
+                       goto out;
                addr->bsel0 = getc(&sc->sc_que);
                n = RDYSCAN;
                while (n-- && (addr->bsel0&DMC_RDYI) == 0)
                addr->bsel0 = getc(&sc->sc_que);
                n = RDYSCAN;
                while (n-- && (addr->bsel0&DMC_RDYI) == 0)
@@ -291,6 +286,8 @@ COUNT(DMCRINT);
        }
        if (sc->sc_que.c_cc)
                addr->bsel0 |= DMC_IEI;
        }
        if (sc->sc_que.c_cc)
                addr->bsel0 |= DMC_IEI;
+out:
+       dmcxint(unit);
 }
 
 /*
 }
 
 /*
@@ -307,16 +304,18 @@ dmcxint(unit)
        struct dmcdevice *addr;
        struct mbuf *m;
        register struct ifqueue *inq;
        struct dmcdevice *addr;
        struct mbuf *m;
        register struct ifqueue *inq;
-       int arg, cmd, len;
+       int arg, arg2, cmd, len;
 
 
-COUNT(DMCXINT);
        addr = (struct dmcdevice *)ui->ui_addr;
        addr = (struct dmcdevice *)ui->ui_addr;
+       cmd = addr->bsel2 & 0xff;
+       if ((cmd & DMC_RDYO) == 0)
+               return;
+       arg2 = addr->sel4;
        arg = addr->sel6;
        arg = addr->sel6;
-       cmd = addr->bsel2&7;
        addr->bsel2 &= ~DMC_RDYO;
        sc = &dmc_softc[unit];
        printd("dmcxint\n");
        addr->bsel2 &= ~DMC_RDYO;
        sc = &dmc_softc[unit];
        printd("dmcxint\n");
-       switch (cmd) {
+       switch (cmd & 07) {
 
        case DMC_OUR:
                /*
 
        case DMC_OUR:
                /*
@@ -325,7 +324,7 @@ COUNT(DMCXINT);
                 * higher-level input routine.
                 */
                sc->sc_if.if_ipackets++;
                 * higher-level input routine.
                 */
                sc->sc_if.if_ipackets++;
-               if (sc->sc_ifuba.ifuba_flags & UBA_NEEDBDP)
+               if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
                        UBAPURGE(sc->sc_ifuba.ifu_uba,
                                sc->sc_ifuba.ifu_r.ifrw_bdp);
                len = arg & DMC_CCOUNT;
                        UBAPURGE(sc->sc_ifuba.ifu_uba,
                                sc->sc_ifuba.ifu_r.ifrw_bdp);
                len = arg & DMC_CCOUNT;
@@ -348,7 +347,7 @@ COUNT(DMCXINT);
                        goto setup;
                if (IF_QFULL(inq)) {
                        IF_DROP(inq);
                        goto setup;
                if (IF_QFULL(inq)) {
                        IF_DROP(inq);
-                       (void) m_freem(m);
+                       m_freem(m);
                } else
                        IF_ENQUEUE(inq, m);
 
                } else
                        IF_ENQUEUE(inq, m);
 
@@ -368,7 +367,7 @@ setup:
                sc->sc_if.if_opackets++;
                sc->sc_oactive = 0;
                if (sc->sc_ifuba.ifu_xtofree) {
                sc->sc_if.if_opackets++;
                sc->sc_oactive = 0;
                if (sc->sc_ifuba.ifu_xtofree) {
-                       (void) m_freem(sc->sc_ifuba.ifu_xtofree);
+                       m_freem(sc->sc_ifuba.ifu_xtofree);
                        sc->sc_ifuba.ifu_xtofree = 0;
                }
                if (sc->sc_if.if_snd.ifq_head == 0)
                        sc->sc_ifuba.ifu_xtofree = 0;
                }
                if (sc->sc_if.if_snd.ifq_head == 0)
@@ -407,23 +406,23 @@ dmcoutput(ifp, m, dst)
        struct uba_device *ui = dmcinfo[ifp->if_unit];
        int s;
 
        struct uba_device *ui = dmcinfo[ifp->if_unit];
        int s;
 
-COUNT(DMCOUTPUT);
        printd("dmcoutput\n");
        if (dst->sa_family != (ui->ui_flags & DMC_AF)) {
        printd("dmcoutput\n");
        if (dst->sa_family != (ui->ui_flags & DMC_AF)) {
-               printf("dmc%d: af%d not supported\n", ifp->if_unit, pf);
+               printf("dmc%d: af%d not supported\n", ifp->if_unit,
+                       dst->sa_family);
                m_freem(m);
                m_freem(m);
-               return (0);
+               return (EAFNOSUPPORT);
        }
        s = splimp();
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
                m_freem(m);
                splx(s);
        }
        s = splimp();
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
                m_freem(m);
                splx(s);
-               return (0);
+               return (ENOBUFS);
        }
        IF_ENQUEUE(&ifp->if_snd, m);
        if (dmc_softc[ifp->if_unit].sc_oactive == 0)
                dmcstart(ifp->if_unit);
        splx(s);
        }
        IF_ENQUEUE(&ifp->if_snd, m);
        if (dmc_softc[ifp->if_unit].sc_oactive == 0)
                dmcstart(ifp->if_unit);
        splx(s);
-       return (1);
+       return (0);
 }
 }