before carry to calder
[unix-history] / usr / src / sys / vax / if / if_acc.c
index 836c1d4..08b8fb5 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_acc.c        4.2     82/02/01        */
+/*     if_acc.c        4.16    82/06/14        */
 
 #include "acc.h"
 #ifdef NACC > 0
 
 #include "acc.h"
 #ifdef NACC > 0
 #include "../h/socket.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
 #include "../h/socket.h"
 #include "../h/ubareg.h"
 #include "../h/ubavar.h"
-#include "../h/accreg.h"
 #include "../h/cpu.h"
 #include "../h/mtpr.h"
 #include "../h/vmmac.h"
 #include "../net/in.h"
 #include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../h/cpu.h"
 #include "../h/mtpr.h"
 #include "../h/vmmac.h"
 #include "../net/in.h"
 #include "../net/in_systm.h"
 #include "../net/if.h"
+#include "../net/if_acc.h"
 #include "../net/if_imp.h"
 #include "../net/if_uba.h"
 
 #include "../net/if_imp.h"
 #include "../net/if_uba.h"
 
@@ -61,6 +61,10 @@ struct       acc_softc {
        char    acc_flush;              /* flush remainder of message */
 } acc_softc[NACC];
 
        char    acc_flush;              /* flush remainder of message */
 } acc_softc[NACC];
 
+#define        NACCDEBUG       10000
+char   accdebug[NACCDEBUG];
+int    accdebugx;
+
 /*
  * Reset the IMP and cause a transmitter interrupt by
  * performing a null DMA.
 /*
  * Reset the IMP and cause a transmitter interrupt by
  * performing a null DMA.
@@ -76,20 +80,18 @@ COUNT(ACCPROBE);
        br = 0; cvec = br; br = cvec;
        accrint(0); accxint(0);
 #endif
        br = 0; cvec = br; br = cvec;
        accrint(0); accxint(0);
 #endif
-       addr->acc_icsr = ACC_RESET;
-       DELAY(500000);
-       addr->acc_ocsr = ACC_RESET;
-       DELAY(500000);
-
-       addr->acc_ocsr = OUT_BBACK;
-       DELAY(500000);
-       addr->acc_owc = 0;
-       addr->acc_ocsr = ACC_IE | ACC_GO;
-       DELAY(500000);
-       addr->acc_ocsr = 0;
-       /* interrupt was for transmit, push back to receive vector */
-       if (cvec && cvec != 0x200)
+       addr->icsr = ACC_RESET; DELAY(5000);
+       addr->ocsr = ACC_RESET; DELAY(5000);
+       addr->ocsr = OUT_BBACK; DELAY(5000);
+       addr->owc = 0;
+       addr->ocsr = ACC_IE | ACC_GO; DELAY(5000);
+       addr->icsr = ACC_RESET; DELAY(5000);
+       addr->ocsr = ACC_RESET; DELAY(5000);
+       if (cvec && cvec != 0x200)      /* transmit -> receive */
                cvec -= 4;
                cvec -= 4;
+#ifdef ECHACK
+       br = 0x16;
+#endif
        return (1);
 }
 
        return (1);
 }
 
@@ -110,12 +112,16 @@ accattach(ui)
 
 COUNT(ACCATTACH);
        if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
 
 COUNT(ACCATTACH);
        if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
-               panic("accattach");             /* XXX */
+               panic("accattach");
        sc->acc_if = &ifimp->ifimp_if;
        ip = &ifimp->ifimp_impcb;
        sc->acc_ic = ip;
        ip->ic_init = accinit;
        ip->ic_start = accstart;
        sc->acc_if = &ifimp->ifimp_if;
        ip = &ifimp->ifimp_impcb;
        sc->acc_ic = ip;
        ip->ic_init = accinit;
        ip->ic_start = accstart;
+       sc->acc_ifuba.ifu_flags = UBA_CANTWAIT;
+#ifdef notdef
+       sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP;
+#endif
 }
 
 /*
 }
 
 /*
@@ -140,59 +146,89 @@ COUNT(ACCRESET);
 
 /*
  * Initialize interface: clear recorded pending operations,
 
 /*
  * Initialize interface: clear recorded pending operations,
- * and retrieve, and reinitialize UNIBUS resources.
+ * and retrieve, and initialize UNIBUS resources.  Note
+ * return value is used by IMP init routine to mark IMP
+ * unavailable for outgoing traffic.
  */
 accinit(unit)
        int unit;
 {      
  */
 accinit(unit)
        int unit;
 {      
-       register struct acc_softc *sc = &acc_softc[unit];
-       register struct uba_device *ui = accinfo[unit];
+       register struct acc_softc *sc;
+       register struct uba_device *ui;
        register struct accdevice *addr;
        register struct accdevice *addr;
-       int x, info;
+       int info, i;
 
 COUNT(ACCINIT);
 
 COUNT(ACCINIT);
-       if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum,
-             sizeof(struct imp_leader), (int)btop(IMP_MTU)) == 0) {
+       if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
+               printf("acc%d: not alive\n", unit);
+               return (0);
+       }
+       sc = &acc_softc[unit];
+       /*
+        * Header length is 0 since we have to passs
+        * the IMP leader up to the protocol interpretation
+        * routines.  If we had the header length as
+        * sizeof(struct imp_leader), then the if_ routines
+        * would asssume we handle it on input and output.
+        */
+       if (if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0,
+            (int)btoc(IMPMTU)) == 0) {
                printf("acc%d: can't initialize\n", unit);
                printf("acc%d: can't initialize\n", unit);
-               return;
+               ui->ui_alive = 0;
+               return (0);
        }
        addr = (struct accdevice *)ui->ui_addr;
 
        /*
        }
        addr = (struct accdevice *)ui->ui_addr;
 
        /*
-        * Reset the imp interface.
-        * the delays are totally guesses
+        * Reset the imp interface;
+        * the delays are pure guesswork.
         */
         */
-       x = spl5();
-       addr->acc_icsr = ACC_RESET;
-       DELAY(100);
-        addr->acc_ocsr = ACC_RESET;
-       DELAY(1000);
-       addr->acc_ocsr = OUT_BBACK;     /* reset host master ready */
-       DELAY(1000);
-       addr->acc_ocsr = 0;
-       addr->acc_icsr = IN_MRDY;       /* close the relay */
-       splx(x);
-
-       /* YECH!!! */
-       while ((addr->acc_icsr & IN_HRDY) == 0 ||
-              (addr->acc_icsr & (IN_RMR | IN_IMPBSY))) {
-               /* keep turning IN_RMR off */
-               addr->acc_icsr = IN_MRDY;
-               sleep((caddr_t)&lbolt, PZERO);  /* ??? */
+        addr->ocsr = ACC_RESET; DELAY(5000);
+       addr->ocsr = OUT_BBACK; DELAY(5000);    /* reset host master ready */
+       addr->ocsr = 0;
+       if (accinputreset(addr, unit) == 0) {
+               ui->ui_alive = 0;
+               return (0);
        }
 
        /*
         * Put up a read.  We can't restart any outstanding writes
         * until we're back in synch with the IMP (i.e. we've flushed
         * the NOOPs it throws at us).
        }
 
        /*
         * Put up a read.  We can't restart any outstanding writes
         * until we're back in synch with the IMP (i.e. we've flushed
         * the NOOPs it throws at us).
+        * Note: IMPMTU includes the leader.
         */
         */
-       x = spl5();
+       acctrace("init", addr->icsr);
        info = sc->acc_ifuba.ifu_r.ifrw_info;
        info = sc->acc_ifuba.ifu_r.ifrw_info;
-       addr->acc_iba = (u_short)info;
-       addr->acc_iwc = -(sizeof(struct imp_leader) + IMP_MTU) >> 1;
-       addr->acc_icsr = 
+       addr->iba = (u_short)info;
+       addr->iwc = -(IMPMTU >> 1);
+#ifdef LOOPBACK
+       addr->ocsr |= OUT_BBACK;
+#endif
+       addr->icsr = 
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
-       splx(x);
+       return (1);
+}
+
+accinputreset(addr, unit)
+       register struct accdevice *addr;
+       register int unit;
+{
+       register int i;
+
+       addr->icsr = ACC_RESET; DELAY(5000);
+       addr->icsr = IN_MRDY | IN_WEN;          /* close the relay */
+       DELAY(10000);
+       /* YECH!!! */
+       for (i = 0; i < 500; i++) {
+               if ((addr->icsr & IN_HRDY) ||
+                   (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0)
+                       return (1);
+               addr->icsr = IN_MRDY | IN_WEN; DELAY(10000);
+               /* keep turning IN_RMR off */
+       }
+       printf("acc%d: imp doesn't respond, icsr=%b\n", unit,
+               addr->icsr, ACC_INBITS);
+       return (0);
 }
 
 /*
 }
 
 /*
@@ -202,13 +238,13 @@ accstart(dev)
        dev_t dev;
 {
        int unit = ACCUNIT(dev), info;
        dev_t dev;
 {
        int unit = ACCUNIT(dev), info;
-       struct uba_device *ui = accinfo[unit];
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
        struct mbuf *m;
        u_short cmd;
 
 COUNT(ACCSTART);
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
        struct mbuf *m;
        u_short cmd;
 
 COUNT(ACCSTART);
+       acctrace("start", sc->acc_ic->ic_oactive);
        if (sc->acc_ic->ic_oactive)
                goto restart;
        
        if (sc->acc_ic->ic_oactive)
                goto restart;
        
@@ -219,6 +255,7 @@ COUNT(ACCSTART);
         */
        IF_DEQUEUE(&sc->acc_if->if_snd, m);
        if (m == 0) {
         */
        IF_DEQUEUE(&sc->acc_if->if_snd, m);
        if (m == 0) {
+               acctrace("q empty", 0);
                sc->acc_ic->ic_oactive = 0;
                return;
        }
                sc->acc_ic->ic_oactive = 0;
                return;
        }
@@ -226,16 +263,20 @@ COUNT(ACCSTART);
 
 restart:
        /*
 
 restart:
        /*
-        * Have request mapped to UNIBUS for transmission.
-        * Purge any stale data from the BDP, and start the output.
+        * Have request mapped to UNIBUS for
+        * transmission; start the output.
         */
         */
-       UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
-       addr = (struct accdevice *)ui->ui_addr;
+       if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
+               UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
        info = sc->acc_ifuba.ifu_w.ifrw_info;
        info = sc->acc_ifuba.ifu_w.ifrw_info;
-       addr->acc_oba = (u_short)info;
-       addr->acc_owc = -((sc->acc_olen + 1) >> 1);
+       addr->oba = (u_short)info;
+       addr->owc = -((sc->acc_olen + 1) >> 1);
        cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO;
        cmd = ACC_IE | OUT_ENLB | ((info & 0x30000) >> 12) | ACC_GO;
-       addr->acc_ocsr = cmd;
+#ifdef LOOPBACK
+       cmd |= OUT_BBACK;
+#endif
+       addr->ocsr = cmd;
        sc->acc_ic->ic_oactive = 1;
 }
 
        sc->acc_ic->ic_oactive = 1;
 }
 
@@ -244,31 +285,32 @@ restart:
  */
 accxint(unit)
 {
  */
 accxint(unit)
 {
-       register struct uba_device *ui = accinfo[unit];
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
 
 COUNT(ACCXINT);
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
 
 COUNT(ACCXINT);
+       acctrace("xint", sc->acc_ic->ic_oactive);
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
        if (sc->acc_ic->ic_oactive == 0) {
        if (sc->acc_ic->ic_oactive == 0) {
-               printf("acc%d: stray send interrupt\n", unit);
+               printf("acc%d: stray xmit interrupt, csr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS);
+               addr->ocsr  = ACC_RESET; 
                return;
        }
                return;
        }
-       addr = (struct accdevice *)ui->ui_addr;
+       acctrace("ocsr", addr->ocsr);
        sc->acc_if->if_opackets++;
        sc->acc_ic->ic_oactive = 0;
        sc->acc_if->if_opackets++;
        sc->acc_ic->ic_oactive = 0;
-       if (addr->acc_ocsr & ACC_ERR) {
-               printf("acc%d: send error, csr=%b\n", unit,
-                       addr->acc_ocsr, ACC_OUTBITS);
+       if (addr->ocsr & (ACC_ERR|OUT_TMR)) {
+               printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS);
                sc->acc_if->if_oerrors++;
        }
                sc->acc_if->if_oerrors++;
        }
-       if (sc->acc_if->if_snd.ifq_head == 0) {
-               if (sc->acc_ifuba.ifu_xtofree) {
-                       m_freem(sc->acc_ifuba.ifu_xtofree);
-                       sc->acc_ifuba.ifu_xtofree = 0;
-               }
-               return;
+       if (sc->acc_ifuba.ifu_xtofree) {
+               m_freem(sc->acc_ifuba.ifu_xtofree);
+               sc->acc_ifuba.ifu_xtofree = 0;
        }
        }
-       accstart(unit);
+       if (sc->acc_if->if_snd.ifq_head)
+               accstart(unit);
 }
 
 /*
 }
 
 /*
@@ -278,31 +320,46 @@ accrint(unit)
 {
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
 {
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
-       register struct ifqueue *inq;
        struct mbuf *m;
        int len, info;
 
 COUNT(ACCRINT);
        struct mbuf *m;
        int len, info;
 
 COUNT(ACCRINT);
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
+       if ((addr->icsr & ACC_RDY) == 0) {
+               printf("acc%d: stray input interrupt\n", unit);
+               accinputreset(addr, unit);
+               goto setup;
+       }
        sc->acc_if->if_ipackets++;
 
        /*
         * Purge BDP; flush message if error indicated.
         */
        sc->acc_if->if_ipackets++;
 
        /*
         * Purge BDP; flush message if error indicated.
         */
-       UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
-       addr = (struct accdevice *)accinfo[unit]->ui_addr;
-       if (addr->acc_icsr & ACC_ERR) {
-               printf("acc%d: recv error, csr=%b\n", unit,
-                   addr->acc_icsr, ACC_INBITS);
+       if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
+               UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
+       acctrace("rint", addr->icsr);
+       if (addr->icsr & (ACC_ERR|IN_RMR)) {
+               printf("acc%d: input error, icsr=%b, ocsr=%b\n", unit,
+                   addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS);
                sc->acc_if->if_ierrors++;
                sc->acc_if->if_ierrors++;
+               if (addr->icsr & IN_RMR)
+                       accinputreset(addr, unit);
                sc->acc_flush = 1;
        }
 
                sc->acc_flush = 1;
        }
 
+       acctrace("flush", sc->acc_flush);
        if (sc->acc_flush) {
        if (sc->acc_flush) {
-               if (addr->acc_icsr & IN_EOM)
+               if (addr->icsr & IN_EOM)
                        sc->acc_flush = 0;
                goto setup;
        }
                        sc->acc_flush = 0;
                goto setup;
        }
-       len = sizeof(struct imp_leader) + (addr->acc_iwc << 1);
+       len = IMPMTU + (addr->iwc << 1);
+       acctrace("length", len);
+       if (len < 0 || len > IMPMTU) {
+               printf("acc%d: bad length=%d\n", len);
+               sc->acc_if->if_ierrors++;
+               goto setup;
+       }
 
        /*
         * The last parameter is always 0 since using
 
        /*
         * The last parameter is always 0 since using
@@ -311,20 +368,19 @@ COUNT(ACCRINT);
        m = if_rubaget(&sc->acc_ifuba, len, 0);
        if (m == 0)
                goto setup;
        m = if_rubaget(&sc->acc_ifuba, len, 0);
        if (m == 0)
                goto setup;
-       if ((addr->acc_icsr & IN_EOM) == 0) {
+       if ((addr->icsr & IN_EOM) == 0) {
                if (sc->acc_iq)
                        m_cat(sc->acc_iq, m);
                else
                        sc->acc_iq = m;
                goto setup;
        }
                if (sc->acc_iq)
                        m_cat(sc->acc_iq, m);
                else
                        sc->acc_iq = m;
                goto setup;
        }
-       /* adjust message length for padding. */
-       m->m_len -= 2;
        if (sc->acc_iq) {
                m_cat(sc->acc_iq, m);
                m = sc->acc_iq;
                sc->acc_iq = 0;
        }
        if (sc->acc_iq) {
                m_cat(sc->acc_iq, m);
                m = sc->acc_iq;
                sc->acc_iq = 0;
        }
+       acctrace("impinput", 0);
        impinput(unit, m);
 
 setup:
        impinput(unit, m);
 
 setup:
@@ -332,9 +388,32 @@ setup:
         * Setup for next message.
         */
        info = sc->acc_ifuba.ifu_r.ifrw_info;
         * Setup for next message.
         */
        info = sc->acc_ifuba.ifu_r.ifrw_info;
-       addr->acc_iba = (u_short)info;
-       addr->acc_iwc = - (sizeof(struct imp_leader) + IMP_MTU) >> 1;
-       addr->acc_icsr =
+       addr->iba = (u_short)info;
+       addr->iwc = -(IMPMTU >> 1);
+       addr->icsr =
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
 }
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
 }
+
+int    accprintf = 0;
+
+acctrace(cmd, value)
+       char *cmd;
+       int value;
+{
+       register int i;
+       register char *p = (char *)&value;
+
+       if (accprintf)
+               printf("%s: %x", cmd, value);
+       do {
+               if (accdebugx >= NACCDEBUG)
+                       accdebugx = 0;
+               accdebug[accdebugx++] = *cmd;
+       } while (*cmd++);
+       for (i = 0; i < sizeof (int); i++) {
+               if (accdebugx >= NACCDEBUG)
+                       accdebugx = 0;
+               accdebug[accdebugx++] = *p++;
+       }
+}
 #endif
 #endif