more attempts by david
[unix-history] / usr / src / sys / vax / if / if_acc.c
index ab84f9f..a04d61e 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_acc.c        4.3     82/02/12        */
+/*     if_acc.c        4.17    82/06/14        */
 
 #include "acc.h"
 #ifdef NACC > 0
 
 #include "acc.h"
 #ifdef NACC > 0
@@ -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.
@@ -84,6 +88,9 @@ COUNT(ACCPROBE);
        addr->ocsr = 0;
        if (cvec && cvec != 0x200)      /* transmit -> receive */
                cvec -= 4;
        addr->ocsr = 0;
        if (cvec && cvec != 0x200)      /* transmit -> receive */
                cvec -= 4;
+#ifdef ECHACK
+       br = 0x16;
+#endif
        return (1);
 }
 
        return (1);
 }
 
@@ -110,8 +117,9 @@ COUNT(ACCATTACH);
        sc->acc_ic = ip;
        ip->ic_init = accinit;
        ip->ic_start = accstart;
        sc->acc_ic = ip;
        ip->ic_init = accinit;
        ip->ic_start = accstart;
+       sc->acc_ifuba.ifu_flags = UBA_CANTWAIT;
 #ifdef notdef
 #ifdef notdef
-       sc->acc_ifuba.ifu_flags = UBA_NEEDBDP;
+       sc->acc_ifuba.ifu_flags |= UBA_NEEDBDP;
 #endif
 }
 
 #endif
 }
 
@@ -147,7 +155,7 @@ accinit(unit)
        register struct acc_softc *sc;
        register struct uba_device *ui;
        register struct accdevice *addr;
        register struct acc_softc *sc;
        register struct uba_device *ui;
        register struct accdevice *addr;
-       int x, info;
+       int info, i;
 
 COUNT(ACCINIT);
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
 
 COUNT(ACCINIT);
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
@@ -162,9 +170,11 @@ COUNT(ACCINIT);
         * sizeof(struct imp_leader), then the if_ routines
         * would asssume we handle it on input and output.
         */
         * 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, btoc(IMP_MTU)) == 0) {
+       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);
-               goto down;
+               ui->ui_alive = 0;
+               return (0);
        }
        addr = (struct accdevice *)ui->ui_addr;
 
        }
        addr = (struct accdevice *)ui->ui_addr;
 
@@ -172,47 +182,51 @@ COUNT(ACCINIT);
         * Reset the imp interface;
         * the delays are pure guesswork.
         */
         * Reset the imp interface;
         * the delays are pure guesswork.
         */
-       x = spl5();
-       addr->icsr = ACC_RESET; DELAY(5000);
         addr->ocsr = ACC_RESET; DELAY(5000);
         addr->ocsr = ACC_RESET; DELAY(5000);
-       addr->ocsr = OUT_BBACK; DELAY(1000);    /* reset host master ready */
+       addr->ocsr = OUT_BBACK; DELAY(5000);    /* reset host master ready */
        addr->ocsr = 0;
        addr->ocsr = 0;
-       splx(x);
-       addr->icsr = IN_MRDY;                   /* close the relay */
-
-       /* YECH!!! */
-       x = 500;
-       while (x-- > 0) {
-               if ((addr->icsr & IN_HRDY) ||
-                   (addr->icsr & (IN_RMR | IN_IMPBSY) == 0))
-                       break;
-               addr->icsr = IN_MRDY; DELAY(5000); /* keep turning IN_RMR off */
-       }
-       if (x <= 0) {
-               printf("acc%d: imp doesn't respond, icsr=%b\n", unit,
-                       addr->icsr, ACC_INBITS);
-               goto down;
+       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: IMP_MTU includes the leader.
+        * Note: IMPMTU includes the leader.
         */
         */
-       x = spl5();
+       acctrace("init", addr->icsr);
        info = sc->acc_ifuba.ifu_r.ifrw_info;
        addr->iba = (u_short)info;
        info = sc->acc_ifuba.ifu_r.ifrw_info;
        addr->iba = (u_short)info;
-       addr->iwc = -(IMP_MTU >> 1);
+       addr->iwc = -(IMPMTU >> 1);
 #ifdef LOOPBACK
        addr->ocsr |= OUT_BBACK;
 #endif
        addr->icsr = 
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
 #ifdef LOOPBACK
        addr->ocsr |= OUT_BBACK;
 #endif
        addr->icsr = 
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
-       splx(x);
        return (1);
        return (1);
-down:
-       ui->ui_alive = 0;
+}
+
+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);
 }
 
        return (0);
 }
 
@@ -223,15 +237,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;
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
        struct mbuf *m;
-       struct imp_leader *ip;
        u_short cmd;
 
 COUNT(ACCSTART);
        u_short cmd;
 
 COUNT(ACCSTART);
-printf("accstart: active=%d\n", sc->acc_ic->ic_oactive);
+       acctrace("start", sc->acc_ic->ic_oactive);
        if (sc->acc_ic->ic_oactive)
                goto restart;
        
        if (sc->acc_ic->ic_oactive)
                goto restart;
        
@@ -241,13 +253,12 @@ printf("accstart: active=%d\n", sc->acc_ic->ic_oactive);
         * requeusts, just return.
         */
        IF_DEQUEUE(&sc->acc_if->if_snd, m);
         * requeusts, just return.
         */
        IF_DEQUEUE(&sc->acc_if->if_snd, m);
-printf("accstart: dequeue m=%x\n", m);
        if (m == 0) {
        if (m == 0) {
+               acctrace("q empty", 0);
                sc->acc_ic->ic_oactive = 0;
                return;
        }
        sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
                sc->acc_ic->ic_oactive = 0;
                return;
        }
        sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
-printf("accstart: olen=%d\n", sc->acc_olen);
 
 restart:
        /*
 
 restart:
        /*
@@ -256,7 +267,7 @@ restart:
         */
        if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
         */
        if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_w.ifrw_bdp);
-       addr = (struct accdevice *)ui->ui_addr;
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
        info = sc->acc_ifuba.ifu_w.ifrw_info;
        addr->oba = (u_short)info;
        addr->owc = -((sc->acc_olen + 1) >> 1);
        info = sc->acc_ifuba.ifu_w.ifrw_info;
        addr->oba = (u_short)info;
        addr->owc = -((sc->acc_olen + 1) >> 1);
@@ -273,30 +284,33 @@ 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 xmit interrupt\n", unit);
+               printf("acc%d: stray xmit interrupt, csr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS);
                return;
        }
                return;
        }
-       addr = (struct accdevice *)ui->ui_addr;
-printf("accxint: ocsr=%b\n", addr->ocsr, ACC_OUTBITS);
+       acctrace("ocsr", addr->ocsr);
        sc->acc_if->if_opackets++;
        sc->acc_ic->ic_oactive = 0;
        if (addr->ocsr & ACC_ERR) {
        sc->acc_if->if_opackets++;
        sc->acc_ic->ic_oactive = 0;
        if (addr->ocsr & ACC_ERR) {
-               printf("acc%d: output error, csr=%b\n", unit,
-                       addr->ocsr, ACC_OUTBITS);
+               printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS);
                sc->acc_if->if_oerrors++;
        }
        if (sc->acc_ifuba.ifu_xtofree) {
                m_freem(sc->acc_ifuba.ifu_xtofree);
                sc->acc_ifuba.ifu_xtofree = 0;
        }
                sc->acc_if->if_oerrors++;
        }
        if (sc->acc_ifuba.ifu_xtofree) {
                m_freem(sc->acc_ifuba.ifu_xtofree);
                sc->acc_ifuba.ifu_xtofree = 0;
        }
-       if (sc->acc_if->if_snd.ifq_head == 0)
+       if (sc->acc_if->if_snd.ifq_head == 0) {
+               addr->ocsr &= ~ACC_IE;          /* hardware funky? */
                return;
                return;
+       }
        accstart(unit);
 }
 
        accstart(unit);
 }
 
@@ -307,11 +321,11 @@ 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;
        sc->acc_if->if_ipackets++;
 
        /*
        sc->acc_if->if_ipackets++;
 
        /*
@@ -319,23 +333,23 @@ COUNT(ACCRINT);
         */
        if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
         */
        if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
-       addr = (struct accdevice *)accinfo[unit]->ui_addr;
-printf("accrint: icsr=%b, flush=%d\n", addr->icsr, ACC_INBITS, sc->acc_flush);
+       acctrace("rint", addr->icsr);
        if (addr->icsr & ACC_ERR) {
        if (addr->icsr & ACC_ERR) {
-               printf("acc%d: input error, csr=%b\n", unit,
-                   addr->icsr, ACC_INBITS);
+               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_flush = 1;
        }
 
                sc->acc_if->if_ierrors++;
                sc->acc_flush = 1;
        }
 
+       acctrace("flush", sc->acc_flush);
        if (sc->acc_flush) {
                if (addr->icsr & IN_EOM)
                        sc->acc_flush = 0;
                goto setup;
        }
        if (sc->acc_flush) {
                if (addr->icsr & IN_EOM)
                        sc->acc_flush = 0;
                goto setup;
        }
-       len = IMP_MTU + (addr->iwc << 1);
-printf("accrint: len=%d\n", len);
-       if (len < 0 || len > IMP_MTU) {
+       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;
                printf("acc%d: bad length=%d\n", len);
                sc->acc_if->if_ierrors++;
                goto setup;
@@ -346,7 +360,6 @@ printf("accrint: len=%d\n", len);
         * trailers on the ARPAnet is insane.
         */
        m = if_rubaget(&sc->acc_ifuba, len, 0);
         * trailers on the ARPAnet is insane.
         */
        m = if_rubaget(&sc->acc_ifuba, len, 0);
-printf("accrint: m=%x\n", m);
        if (m == 0)
                goto setup;
        if ((addr->icsr & IN_EOM) == 0) {
        if (m == 0)
                goto setup;
        if ((addr->icsr & IN_EOM) == 0) {
@@ -356,15 +369,12 @@ printf("accrint: m=%x\n", m);
                        sc->acc_iq = m;
                goto setup;
        }
                        sc->acc_iq = m;
                goto setup;
        }
-       /* adjust message length for padding. */
-#ifdef notdef
-       m->m_len -= 2;
-#endif
        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:
@@ -373,8 +383,31 @@ setup:
         */
        info = sc->acc_ifuba.ifu_r.ifrw_info;
        addr->iba = (u_short)info;
         */
        info = sc->acc_ifuba.ifu_r.ifrw_info;
        addr->iba = (u_short)info;
-       addr->iwc = -(IMP_MTU >> 1);
+       addr->iwc = -(IMPMTU >> 1);
        addr->icsr =
                IN_MRDY | ACC_IE | IN_WEN | ((info & 0x30000) >> 12) | ACC_GO;
 }
        addr->icsr =
                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