changes for var. length sockaddrs; new routing; mv common ether input
[unix-history] / usr / src / sys / vax / if / if_acc.c
index ca3d556..420df5c 100644 (file)
@@ -1,39 +1,55 @@
-/*     if_acc.c        4.6     82/02/25        */
+/*
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)if_acc.c    7.5 (Berkeley) %G%
+ */
 
 #include "acc.h"
 
 #include "acc.h"
-#ifdef NACC > 0
+#if NACC > 0
 
 /*
  * ACC LH/DH ARPAnet IMP interface driver.
  */
 
 /*
  * ACC LH/DH ARPAnet IMP interface driver.
  */
+#include "../machine/pte.h"
+
+#include "param.h"
+#include "systm.h"
+#include "mbuf.h"
+#include "buf.h"
+#include "protosw.h"
+#include "socket.h"
+#include "vmmac.h"
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/mbuf.h"
-#include "../h/pte.h"
-#include "../h/buf.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 "../net/in.h"
-#include "../net/in_systm.h"
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/if_acc.h"
-#include "../net/if_imp.h"
-#include "../net/if_uba.h"
+#include "../netimp/if_imp.h"
+
+#include "../vax/cpu.h"
+#include "../vax/mtpr.h"
+#include "if_accreg.h"
+#include "if_uba.h"
+#include "../vaxuba/ubareg.h"
+#include "../vaxuba/ubavar.h"
 
 int     accprobe(), accattach(), accrint(), accxint();
 struct  uba_device *accinfo[NACC];
 u_short accstd[] = { 0 };
 struct  uba_driver accdriver =
        { accprobe, 0, accattach, 0, accstd, "acc", accinfo };
 
 int     accprobe(), accattach(), accrint(), accxint();
 struct  uba_device *accinfo[NACC];
 u_short accstd[] = { 0 };
 struct  uba_driver accdriver =
        { accprobe, 0, accattach, 0, accstd, "acc", accinfo };
-#define        ACCUNIT(x)      minor(x)
 
 
-int    accinit(), accstart(), accreset();
+int    accinit(), accoutput(), accdown(), accreset();
 
 /*
  * "Lower half" of IMP interface driver.
 
 /*
  * "Lower half" of IMP interface driver.
@@ -53,8 +69,7 @@ int   accinit(), accstart(), accreset();
  * e.g. IP, interact with the IMP driver, rather than the ACC.
  */
 struct acc_softc {
  * e.g. IP, interact with the IMP driver, rather than the ACC.
  */
 struct acc_softc {
-       struct  ifnet *acc_if;          /* pointer to IMP's ifnet struct */
-       struct  impcb *acc_ic;          /* data structure shared with IMP */
+       struct  imp_softc *acc_imp;     /* data structure shared with IMP */
        struct  ifuba acc_ifuba;        /* UNIBUS resources */
        struct  mbuf *acc_iq;           /* input reassembly queue */
        short   acc_olen;               /* size of last message sent */
        struct  ifuba acc_ifuba;        /* UNIBUS resources */
        struct  mbuf *acc_iq;           /* input reassembly queue */
        short   acc_olen;               /* size of last message sent */
@@ -71,7 +86,6 @@ accprobe(reg)
        register int br, cvec;          /* r11, r10 value-result */
        register struct accdevice *addr = (struct accdevice *)reg;
 
        register int br, cvec;          /* r11, r10 value-result */
        register struct accdevice *addr = (struct accdevice *)reg;
 
-COUNT(ACCPROBE);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        accrint(0); accxint(0);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        accrint(0); accxint(0);
@@ -93,25 +107,21 @@ COUNT(ACCPROBE);
  * the back pointers to common data structures.
  */
 accattach(ui)
  * the back pointers to common data structures.
  */
 accattach(ui)
-       struct uba_device *ui;
+       register struct uba_device *ui;
 {
        register struct acc_softc *sc = &acc_softc[ui->ui_unit];
        register struct impcb *ip;
 {
        register struct acc_softc *sc = &acc_softc[ui->ui_unit];
        register struct impcb *ip;
-       struct ifimpcb {
-               struct  ifnet ifimp_if;
-               struct  impcb ifimp_impcb;
-       } *ifimp;
-
-COUNT(ACCATTACH);
-       if ((ifimp = (struct ifimpcb *)impattach(ui)) == 0)
-               panic("accattach");
-       sc->acc_if = &ifimp->ifimp_if;
-       ip = &ifimp->ifimp_impcb;
-       sc->acc_ic = ip;
+
+       if ((sc->acc_imp = impattach(ui->ui_driver->ud_dname, ui->ui_unit,
+           accreset)) == 0)
+               return;
+       ip = &sc->acc_imp->imp_cb;
        ip->ic_init = accinit;
        ip->ic_init = accinit;
-       ip->ic_start = accstart;
+       ip->ic_output = accoutput;
+       ip->ic_down = accdown;
+       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
 }
 
@@ -125,14 +135,15 @@ accreset(unit, uban)
        register struct uba_device *ui;
        struct acc_softc *sc;
 
        register struct uba_device *ui;
        struct acc_softc *sc;
 
-COUNT(ACCRESET);
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
                return;
        printf(" acc%d", unit);
        sc = &acc_softc[unit];
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
                return;
        printf(" acc%d", unit);
        sc = &acc_softc[unit];
+       sc->acc_imp->imp_if.if_flags &= ~IFF_RUNNING;
+       accoflush(unit);
        /* must go through IMP to allow it to set state */
        /* must go through IMP to allow it to set state */
-       (*sc->acc_if->if_init)(unit);
+       (*sc->acc_imp->imp_if.if_init)(sc->acc_imp->imp_if.if_unit);
 }
 
 /*
 }
 
 /*
@@ -147,9 +158,8 @@ 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;
 
 
-COUNT(ACCINIT);
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
                printf("acc%d: not alive\n", unit);
                return (0);
        if (unit >= NACC || (ui = accinfo[unit]) == 0 || ui->ui_alive == 0) {
                printf("acc%d: not alive\n", unit);
                return (0);
@@ -162,90 +172,108 @@ 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 ((sc->acc_imp->imp_if.if_flags & IFF_RUNNING) == 0 &&
+           if_ubainit(&sc->acc_ifuba, ui->ui_ubanum, 0,
+            (int)btoc(IMP_RCVBUF)) == 0) {
                printf("acc%d: can't initialize\n", unit);
                printf("acc%d: can't initialize\n", unit);
-               goto down;
+               sc->acc_imp->imp_if.if_flags &= ~(IFF_UP | IFF_RUNNING);
+               return (0);
        }
        }
+       sc->acc_imp->imp_if.if_flags |= IFF_RUNNING;
        addr = (struct accdevice *)ui->ui_addr;
 
        /*
         * Reset the imp interface;
         * the delays are pure guesswork.
         */
        addr = (struct accdevice *)ui->ui_addr;
 
        /*
         * 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 | IN_WEN;          /* close the relay */
-       DELAY(5000);
-       /* YECH!!! */
-       x = 500;
-       while (x-- > 0) {
-               if ((addr->icsr & IN_HRDY) ||
-                   (addr->icsr & (IN_RMR | IN_IMPBSY) == 0))
-                       break;
-               addr->icsr = IN_MRDY | IN_WEN;
-               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: IMP_RCVBUF includes the leader.
         */
         */
-       x = spl5();
        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 = -((IMP_RCVBUF) >> 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);
 }
 
+/*
+ * Drop the host ready line to mark host down.
+ */
+accdown(unit)
+       int unit;
+{
+       register struct accdevice *addr;
+
+       addr = (struct accdevice *)(accinfo[unit]->ui_addr);
+        addr->ocsr = ACC_RESET;
+       DELAY(5000);
+       addr->ocsr = OUT_BBACK;         /* reset host master ready */
+       accoflush(unit);
+       return (1);
+}
+
+accoflush(unit)
+       int unit;
+{
+       register struct acc_softc *sc = &acc_softc[unit];
+
+       sc->acc_imp->imp_cb.ic_oactive = 0;
+       if (sc->acc_ifuba.ifu_xtofree) {
+               m_freem(sc->acc_ifuba.ifu_xtofree);
+               sc->acc_ifuba.ifu_xtofree = 0;
+       }
+}
+
 /*
  * Start output on an interface.
  */
 /*
  * Start output on an interface.
  */
-accstart(dev)
-       dev_t dev;
+accoutput(unit, m)
+       int unit;
+       struct mbuf *m;
 {
 {
-       int unit = ACCUNIT(dev), info;
+       int info;
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
        register struct acc_softc *sc = &acc_softc[unit];
        register struct accdevice *addr;
-       struct mbuf *m;
        u_short cmd;
 
        u_short cmd;
 
-COUNT(ACCSTART);
-       if (sc->acc_ic->ic_oactive)
-               goto restart;
-       
-       /*
-        * Not already active, deqeue a request and
-        * map it onto the UNIBUS.  If no more
-        * requeusts, just return.
-        */
-       IF_DEQUEUE(&sc->acc_if->if_snd, m);
-       if (m == 0) {
-               sc->acc_ic->ic_oactive = 0;
-               return;
-       }
        sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
        sc->acc_olen = if_wubaput(&sc->acc_ifuba, m);
-
-restart:
        /*
         * Have request mapped to UNIBUS for
         * transmission; start the output.
        /*
         * Have request mapped to UNIBUS for
         * transmission; start the output.
@@ -261,62 +289,61 @@ restart:
        cmd |= OUT_BBACK;
 #endif
        addr->ocsr = cmd;
        cmd |= OUT_BBACK;
 #endif
        addr->ocsr = cmd;
-       sc->acc_ic->ic_oactive = 1;
+       sc->acc_imp->imp_cb.ic_oactive = 1;
 }
 
 /*
  * Output interrupt handler.
  */
 accxint(unit)
 }
 
 /*
  * Output interrupt handler.
  */
 accxint(unit)
+       int 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;
 
-COUNT(ACCXINT);
-       if (sc->acc_ic->ic_oactive == 0) {
-               printf("acc%d: stray xmit interrupt\n", unit);
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
+       if (sc->acc_imp->imp_cb.ic_oactive == 0) {
+               printf("acc%d: stray xmit interrupt, csr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS);
                return;
        }
                return;
        }
-       addr = (struct accdevice *)accinfo[unit]->ui_addr;
-       sc->acc_if->if_opackets++;
-       sc->acc_ic->ic_oactive = 0;
+       sc->acc_imp->imp_if.if_opackets++;
+       sc->acc_imp->imp_cb.ic_oactive = 0;
        if (addr->ocsr & ACC_ERR) {
        if (addr->ocsr & ACC_ERR) {
-               printf("acc%d: output error, csr=%b\n", unit,
-                       addr->ocsr, ACC_OUTBITS);
-               sc->acc_if->if_oerrors++;
+               printf("acc%d: output error, ocsr=%b, icsr=%b\n", unit,
+                       addr->ocsr, ACC_OUTBITS, addr->icsr, ACC_INBITS);
+               sc->acc_imp->imp_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_ifuba.ifu_xtofree) {
                m_freem(sc->acc_ifuba.ifu_xtofree);
                sc->acc_ifuba.ifu_xtofree = 0;
        }
-       if (sc->acc_if->if_snd.ifq_head)
-               accstart(unit);
+       impstart(sc->acc_imp);
 }
 
 /*
  * Input interrupt handler
  */
 accrint(unit)
 }
 
 /*
  * Input interrupt handler
  */
 accrint(unit)
+       int 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;
 
        struct mbuf *m;
        int len, info;
 
-COUNT(ACCRINT);
-       sc->acc_if->if_ipackets++;
+       addr = (struct accdevice *)accinfo[unit]->ui_addr;
+       sc->acc_imp->imp_if.if_ipackets++;
 
        /*
         * Purge BDP; flush message if error indicated.
         */
        if (sc->acc_ifuba.ifu_flags & UBA_NEEDBDP)
                UBAPURGE(sc->acc_ifuba.ifu_uba, sc->acc_ifuba.ifu_r.ifrw_bdp);
 
        /*
         * Purge BDP; flush message if error indicated.
         */
        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;
        if (addr->icsr & ACC_ERR) {
                printf("acc%d: input error, csr=%b\n", unit,
                    addr->icsr, ACC_INBITS);
        if (addr->icsr & ACC_ERR) {
                printf("acc%d: input error, csr=%b\n", unit,
                    addr->icsr, ACC_INBITS);
-               sc->acc_if->if_ierrors++;
+               sc->acc_imp->imp_if.if_ierrors++;
                sc->acc_flush = 1;
        }
 
                sc->acc_flush = 1;
        }
 
@@ -325,18 +352,18 @@ COUNT(ACCRINT);
                        sc->acc_flush = 0;
                goto setup;
        }
                        sc->acc_flush = 0;
                goto setup;
        }
-       len = IMP_MTU + (addr->iwc << 1);
-       if (len < 0 || len > IMP_MTU) {
-               printf("acc%d: bad length=%d\n", len);
-               sc->acc_if->if_ierrors++;
+       len = IMP_RCVBUF + (addr->iwc << 1);
+       if (len < 0 || len > IMP_RCVBUF) {
+               printf("acc%d: bad length=%d\n", unit, len);
+               sc->acc_imp->imp_if.if_ierrors++;
                goto setup;
        }
 
        /*
                goto setup;
        }
 
        /*
-        * The last parameter is always 0 since using
+        * The offset parameter is always 0 since using
         * trailers on the ARPAnet is insane.
         */
         * trailers on the ARPAnet is insane.
         */
-       m = if_rubaget(&sc->acc_ifuba, len, 0);
+       m = if_rubaget(&sc->acc_ifuba, len, 0, &sc->acc_imp->imp_if);
        if (m == 0)
                goto setup;
        if ((addr->icsr & IN_EOM) == 0) {
        if (m == 0)
                goto setup;
        if ((addr->icsr & IN_EOM) == 0) {
@@ -346,10 +373,6 @@ COUNT(ACCRINT);
                        sc->acc_iq = m;
                goto setup;
        }
                        sc->acc_iq = m;
                goto setup;
        }
-#ifdef notdef
-       /* adjust message length for padding. */
-       m->m_len -= 2;
-#endif
        if (sc->acc_iq) {
                m_cat(sc->acc_iq, m);
                m = sc->acc_iq;
        if (sc->acc_iq) {
                m_cat(sc->acc_iq, m);
                m = sc->acc_iq;
@@ -363,7 +386,7 @@ 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 = -((IMP_RCVBUF)>> 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;
 }