add uba mem configuration entry, get mem addr from flags
[unix-history] / usr / src / sys / vax / if / if_ec.c
index f2e2b32..3dd2800 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_ec.c 4.36    83/06/13        */
+/*     if_ec.c 6.6     85/02/15        */
 
 #include "ec.h"
 
 
 #include "ec.h"
 
@@ -7,15 +7,15 @@
  */
 #include "../machine/pte.h"
 
  */
 #include "../machine/pte.h"
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/mbuf.h"
-#include "../h/buf.h"
-#include "../h/protosw.h"
-#include "../h/socket.h"
-#include "../h/vmmac.h"
-#include "../h/ioctl.h"
-#include "../h/errno.h"
+#include "param.h"
+#include "systm.h"
+#include "mbuf.h"
+#include "buf.h"
+#include "protosw.h"
+#include "socket.h"
+#include "vmmac.h"
+#include "ioctl.h"
+#include "errno.h"
 
 #include "../net/if.h"
 #include "../net/netisr.h"
 
 #include "../net/if.h"
 #include "../net/netisr.h"
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
-#include "../vaxif/if_ecreg.h"
-#include "../vaxif/if_uba.h"
+#include "if_ecreg.h"
+#include "if_uba.h"
 #include "../vaxuba/ubareg.h"
 #include "../vaxuba/ubavar.h"
 
 #include "../vaxuba/ubareg.h"
 #include "../vaxuba/ubavar.h"
 
-#define        ECMEM   0000000
+#if CLSIZE == 2
+#define ECBUFSIZE      32              /* on-board memory, clusters */
+#endif
 
 
-int    ecprobe(), ecattach(), ecrint(), ecxint(), eccollide();
+int    ecubamem(), ecprobe(), ecattach(), ecrint(), ecxint(), eccollide();
 struct uba_device *ecinfo[NEC];
 u_short ecstd[] = { 0 };
 struct uba_driver ecdriver =
 struct uba_device *ecinfo[NEC];
 u_short ecstd[] = { 0 };
 struct uba_driver ecdriver =
-       { ecprobe, 0, ecattach, 0, ecstd, "ec", ecinfo };
-#define        ECUNIT(x)       minor(x)
+       { ecprobe, 0, ecattach, 0, ecstd, "ec", ecinfo, 0, 0, 0, ecubamem };
 
 int    ecinit(),ecioctl(),ecoutput(),ecreset();
 struct mbuf *ecget();
 
 int    ecinit(),ecioctl(),ecoutput(),ecreset();
 struct mbuf *ecget();
@@ -71,59 +72,88 @@ struct      ec_softc {
 } ec_softc[NEC];
 
 /*
 } ec_softc[NEC];
 
 /*
- * Do output DMA to determine interface presence and
- * interrupt vector.  DMA is too short to disturb other hosts.
+ * Configure on-board memory for an interface.
+ * Called from autoconfig and after a uba reset.
+ * The address of the memory on the uba is supplied in the device flags.
  */
  */
-ecprobe(reg)
-       caddr_t reg;
+ecubamem(ui, uban)
+       register struct uba_device *ui;
 {
 {
-       register int br, cvec;          /* r11, r10 value-result */
-       register struct ecdevice *addr = (struct ecdevice *)reg;
-       register caddr_t ecbuf = (caddr_t) &umem[numuba][ECMEM];
+       register caddr_t ecbuf = (caddr_t) &umem[uban][ui->ui_flags];
+       register struct ecdevice *addr = (struct ecdevice *)ui->ui_addr;
 
 
-#ifdef lint
-       br = 0; cvec = br; br = cvec;
-       ecrint(0); ecxint(0); eccollide(0);
+       /*
+        * Make sure csr is there (we run before ecprobe).
+        */
+       if (badaddr((caddr_t)addr, 2))
+               return (-1);
+#if VAX780
+       if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
+               uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
+               return (-1);
+       }
 #endif
        /*
         * Make sure memory is turned on
         */
        addr->ec_rcr = EC_AROM;
        /*
 #endif
        /*
         * Make sure memory is turned on
         */
        addr->ec_rcr = EC_AROM;
        /*
-        * Disable map registers for ec unibus space,
-        * but don't allocate yet.
+        * Tell the system that the board has memory here, so it won't
+        * attempt to allocate the addresses later.
         */
         */
-       (void) ubamem(numuba, ECMEM, 32*2, 0);
+       if (ubamem(uban, ui->ui_flags, ECBUFSIZE*CLSIZE, 1) == 0) {
+               printf("ec%d: cannot reserve uba addresses\n", ui->ui_unit);
+               addr->ec_rcr = EC_MDISAB;       /* disable memory */
+               return (-1);
+       }
        /*
         * Check for existence of buffers on Unibus.
         */
        if (badaddr((caddr_t)ecbuf, 2)) {
        /*
         * Check for existence of buffers on Unibus.
         */
        if (badaddr((caddr_t)ecbuf, 2)) {
-       bad1:
-               printf("ec: buffer mem not found\n");
-       bad2:
-               (void) ubamem(numuba, 0, 0, 0); /* reenable map (780 only) */
+bad:
+               printf("ec%d: buffer mem not found\n", ui->ui_unit);
+               (void) ubamem(uban, ui->ui_flags, ECBUFSIZE*2, 0);
                addr->ec_rcr = EC_MDISAB;       /* disable memory */
                addr->ec_rcr = EC_MDISAB;       /* disable memory */
-               return (0);
+               return (-1);
        }
 #if VAX780
        }
 #if VAX780
-       if (cpu == VAX_780 && uba_hd[numuba].uh_uba->uba_sr) {
-               uba_hd[numuba].uh_uba->uba_sr = uba_hd[numuba].uh_uba->uba_sr;
-               goto bad1;
+       if (cpu == VAX_780 && uba_hd[uban].uh_uba->uba_sr) {
+               uba_hd[uban].uh_uba->uba_sr = uba_hd[uban].uh_uba->uba_sr;
+               goto bad;
        }
 #endif
        }
 #endif
+       if (ui->ui_alive == 0)          /* Only printf from autoconfig */
+               printf("ec%d: mem %x-%x\n", ui->ui_unit,
+                       ui->ui_flags, ui->ui_flags + ECBUFSIZE*CLBYTES - 1);
+       ui->ui_type = 1;                /* Memory on, allocated */
+       return (0);
+}
+
+/*
+ * Do output DMA to determine interface presence and
+ * interrupt vector.  DMA is too short to disturb other hosts.
+ */
+ecprobe(reg, ui)
+       caddr_t reg;
+       struct uba_device *ui;
+{
+       register int br, cvec;          /* r11, r10 value-result */
+       register struct ecdevice *addr = (struct ecdevice *)reg;
+       register caddr_t ecbuf = (caddr_t) &umem[ui->ui_ubanum][ui->ui_flags];
+
+#ifdef lint
+       br = 0; cvec = br; br = cvec;
+       ecrint(0); ecxint(0); eccollide(0);
+#endif
 
        /*
 
        /*
-        * Tell the system that the board has memory here, so it won't
-        * attempt to allocate the addresses later.
+        * Check that buffer memory was found and enabled.
         */
         */
-       if (ubamem(numuba, ECMEM, 32*2, 1) == 0) {
-               printf("ecprobe: cannot reserve uba addresses\n");
-               goto bad2;
-       }
-
+       if (ui->ui_type == 0)
+               return(0);
        /*
         * Make a one byte packet in what should be buffer #0.
        /*
         * Make a one byte packet in what should be buffer #0.
-        * Submit it for sending.  This whould cause an xmit interrupt.
+        * Submit it for sending.  This should cause an xmit interrupt.
         * The xmit interrupt vector is 8 bytes after the receive vector,
         * so adjust for this before returning.
         */
         * The xmit interrupt vector is 8 bytes after the receive vector,
         * so adjust for this before returning.
         */
@@ -168,9 +198,9 @@ ecattach(ui)
         */
        addr->ec_xcr = EC_UECLR;
        addr->ec_rcr = EC_AROM;
         */
        addr->ec_xcr = EC_UECLR;
        addr->ec_rcr = EC_AROM;
-       cp = es->es_addr;
+       cp = (u_char *) &es->es_addr;
 #define        NEXTBIT addr->ec_rcr = EC_AROM|EC_ASTEP; addr->ec_rcr = EC_AROM
 #define        NEXTBIT addr->ec_rcr = EC_AROM|EC_ASTEP; addr->ec_rcr = EC_AROM
-       for (i=0; i<6; i++) {
+       for (i=0; i < sizeof (es->es_addr); i++) {
                *cp = 0;
                for (j=0; j<=4; j+=4) {
                        *cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
                *cp = 0;
                for (j=0; j<=4; j+=4) {
                        *cp |= ((addr->ec_rcr >> 8) & 0xf) << j;
@@ -180,13 +210,13 @@ ecattach(ui)
        }
        sin = (struct sockaddr_in *)&es->es_if.if_addr;
        sin->sin_family = AF_INET;
        }
        sin = (struct sockaddr_in *)&es->es_if.if_addr;
        sin->sin_family = AF_INET;
-       sin->sin_addr = arpmyaddr((struct arpcom *)0);
        ifp->if_init = ecinit;
        ifp->if_ioctl = ecioctl;
        ifp->if_output = ecoutput;
        ifp->if_reset = ecreset;
        for (i=0; i<16; i++)
        ifp->if_init = ecinit;
        ifp->if_ioctl = ecioctl;
        ifp->if_output = ecoutput;
        ifp->if_reset = ecreset;
        for (i=0; i<16; i++)
-               es->es_buf[i] = (u_char *)&umem[ui->ui_ubanum][ECMEM+2048*i];
+               es->es_buf[i] 
+                   = (u_char *)&umem[ui->ui_ubanum][ui->ui_flags + 2048*i];
        if_attach(ifp);
 }
 
        if_attach(ifp);
 }
 
@@ -203,7 +233,7 @@ ecreset(unit, uban)
            ui->ui_ubanum != uban)
                return;
        printf(" ec%d", unit);
            ui->ui_ubanum != uban)
                return;
        printf(" ec%d", unit);
-       (void) ubamem(uban, ECMEM, 32*2, 0);    /* mr disable (no alloc) */
+       ec_softc[unit].es_if.if_flags &= ~IFF_RUNNING;
        ecinit(unit);
 }
 
        ecinit(unit);
 }
 
@@ -217,7 +247,7 @@ ecinit(unit)
        struct ec_softc *es = &ec_softc[unit];
        struct ecdevice *addr;
        register struct ifnet *ifp = &es->es_if;
        struct ec_softc *es = &ec_softc[unit];
        struct ecdevice *addr;
        register struct ifnet *ifp = &es->es_if;
-       register struct sockaddr_in *sin, *sinb;
+       register struct sockaddr_in *sin;
        int i, s;
 
        sin = (struct sockaddr_in *)&ifp->if_addr;
        int i, s;
 
        sin = (struct sockaddr_in *)&ifp->if_addr;
@@ -242,7 +272,6 @@ ecinit(unit)
                splx(s);
        }
        if_rtinit(&es->es_if, RTF_UP);
                splx(s);
        }
        if_rtinit(&es->es_if, RTF_UP);
-       arpattach(&es->es_ac);
        arpwhohas(&es->es_ac, &sin->sin_addr);
 }
 
        arpwhohas(&es->es_ac, &sin->sin_addr);
 }
 
@@ -254,10 +283,8 @@ ecinit(unit)
  * to send off of the interface queue, and map it to the interface
  * before starting the output.
  */
  * to send off of the interface queue, and map it to the interface
  * before starting the output.
  */
-ecstart(dev)
-       dev_t dev;
+ecstart(unit)
 {
 {
-        int unit = ECUNIT(dev);
        struct ec_softc *es = &ec_softc[unit];
        struct ecdevice *addr;
        struct mbuf *m;
        struct ec_softc *es = &ec_softc[unit];
        struct ecdevice *addr;
        struct mbuf *m;
@@ -464,7 +491,7 @@ ecread(unit)
 
        case ETHERPUP_ARPTYPE:
                arpinput(&es->es_ac, m);
 
        case ETHERPUP_ARPTYPE:
                arpinput(&es->es_ac, m);
-               return;
+               goto setup;
 #endif
        default:
                m_freem(m);
 #endif
        default:
                m_freem(m);
@@ -500,7 +527,7 @@ ecoutput(ifp, m0, dst)
        struct sockaddr *dst;
 {
        int type, s, error;
        struct sockaddr *dst;
 {
        int type, s, error;
-       u_char edst[6];
+       struct ether_addr edst;
        struct in_addr idst;
        register struct ec_softc *es = &ec_softc[ifp->if_unit];
        register struct mbuf *m = m0;
        struct in_addr idst;
        register struct ec_softc *es = &ec_softc[ifp->if_unit];
        register struct mbuf *m = m0;
@@ -513,7 +540,7 @@ ecoutput(ifp, m0, dst)
 #ifdef INET
        case AF_INET:
                idst = ((struct sockaddr_in *)dst)->sin_addr;
 #ifdef INET
        case AF_INET:
                idst = ((struct sockaddr_in *)dst)->sin_addr;
-               if (!arpresolve(&es->es_ac, m, &idst, edst))
+               if (!arpresolve(&es->es_ac, m, &idst, &edst))
                        return (0);     /* if not yet resolved */
                if (in_lnaof(idst) == INADDR_ANY)
                        mcopy = m_copy(m, 0, (int)M_COPYALL);
                        return (0);     /* if not yet resolved */
                if (in_lnaof(idst) == INADDR_ANY)
                        mcopy = m_copy(m, 0, (int)M_COPYALL);
@@ -536,7 +563,7 @@ ecoutput(ifp, m0, dst)
 
        case AF_UNSPEC:
                ec = (struct ether_header *)dst->sa_data;
 
        case AF_UNSPEC:
                ec = (struct ether_header *)dst->sa_data;
-               bcopy((caddr_t)ec->ether_dhost, (caddr_t)edst, sizeof (edst));
+               edst = ec->ether_dhost;
                type = ec->ether_type;
                goto gottype;
 
                type = ec->ether_type;
                goto gottype;
 
@@ -579,9 +606,9 @@ gottype:
                m->m_len += sizeof (struct ether_header);
        }
        ec = mtod(m, struct ether_header *);
                m->m_len += sizeof (struct ether_header);
        }
        ec = mtod(m, struct ether_header *);
-       bcopy((caddr_t)edst, (caddr_t)ec->ether_dhost, sizeof (edst));
+       ec->ether_dhost = edst;
+       ec->ether_shost = es->es_addr;
        ec->ether_type = htons((u_short)type);
        ec->ether_type = htons((u_short)type);
-       bcopy((caddr_t)es->es_addr, (caddr_t)ec->ether_shost, 6);
 
        /*
         * Queue message on interface, and start output if interface
 
        /*
         * Queue message on interface, and start output if interface
@@ -604,6 +631,8 @@ qfull:
        splx(s);
 bad:
        m_freem(m0);
        splx(s);
 bad:
        m_freem(m0);
+       if (mcopy)
+               m_freem(mcopy);
        return (error);
 }
 
        return (error);
 }