Add support for microvax 3000.
[unix-history] / usr / src / sys / vax / uba / dh.c
index c927e5a..05c1900 100644 (file)
@@ -1,4 +1,10 @@
-/*     dh.c    4.57    82/12/30        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)dh.c        7.5 (Berkeley) %G%
+ */
 
 #include "dh.h"
 #if NDH > 0
 
 #include "dh.h"
 #if NDH > 0
 #include "../machine/pte.h"
 
 #include "bk.h"
 #include "../machine/pte.h"
 
 #include "bk.h"
-#include "../h/param.h"
-#include "../h/conf.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
-#include "../h/ioctl.h"
-#include "../h/tty.h"
-#include "../h/map.h"
-#include "../h/buf.h"
-#include "../h/vm.h"
-
-#include "../vaxuba/ubareg.h"
-#include "../vaxuba/ubavar.h"
-#include "../vaxuba/dhreg.h"
-#include "../vaxuba/dmreg.h"
-
-#include "../h/bk.h"
-#include "../h/clist.h"
-#include "../h/file.h"
-#include "../h/uio.h"
+#include "uba.h"
+#include "param.h"
+#include "conf.h"
+#include "dir.h"
+#include "user.h"
+#include "proc.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "map.h"
+#include "buf.h"
+#include "vm.h"
+#include "kernel.h"
+#include "syslog.h"
+
+#include "ubareg.h"
+#include "ubavar.h"
+#include "dhreg.h"
+#include "dmreg.h"
+
+#include "bkmac.h"
+#include "clist.h"
+#include "file.h"
+#include "uio.h"
 
 /*
  * Definition of the driver for the auto-configuration program.
  * There is one definition for the dh and one for the dm.
  */
 
 /*
  * Definition of the driver for the auto-configuration program.
  * There is one definition for the dh and one for the dm.
  */
-int    dhprobe(), dhattach(), dhrint(), dhxint();
+int    dhprobe(), dhattach(), dhrint(), dhxint(), dhtimer();
 struct uba_device *dhinfo[NDH];
 u_short        dhstd[] = { 0 };
 struct uba_driver dhdriver =
 struct uba_device *dhinfo[NDH];
 u_short        dhstd[] = { 0 };
 struct uba_driver dhdriver =
@@ -46,13 +55,15 @@ struct      uba_driver dmdriver =
        { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo };
 
 #ifndef        PORTSELECTOR
        { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo };
 
 #ifndef        PORTSELECTOR
-#define        ISPEED  B300
+#define        ISPEED  B9600
 #define        IFLAGS  (EVENP|ODDP|ECHO)
 #else
 #define        ISPEED  B4800
 #define        IFLAGS  (EVENP|ODDP)
 #endif
 
 #define        IFLAGS  (EVENP|ODDP|ECHO)
 #else
 #define        ISPEED  B4800
 #define        IFLAGS  (EVENP|ODDP)
 #endif
 
+#define        FASTTIMER       (hz/30)         /* scan rate with silos on */
+
 /*
  * Local variables for the driver
  */
 /*
  * Local variables for the driver
  */
@@ -62,15 +73,23 @@ short       dhsoftCAR[NDH];
 struct tty dh11[NDH*16];
 int    ndh11   = NDH*16;
 int    dhact;                          /* mask of active dh's */
 struct tty dh11[NDH*16];
 int    ndh11   = NDH*16;
 int    dhact;                          /* mask of active dh's */
+int    dhsilos;                        /* mask of dh's with silo in use */
+int    dhchars[NDH];                   /* recent input count */
+int    dhrate[NDH];                    /* smoothed input count */
+int    dhhighrate = 100;               /* silo on if dhchars > dhhighrate */
+int    dhlowrate = 75;                 /* silo off if dhrate < dhlowrate */
+static short timerstarted;
 int    dhstart(), ttrstrt();
 
 /*
 int    dhstart(), ttrstrt();
 
 /*
- * The clist space is mapped by the driver onto each UNIBUS.
+ * The clist space is mapped by one terminal driver onto each UNIBUS.
+ * The identity of the board which allocated resources is recorded,
+ * so the process may be repeated after UNIBUS resets.
  * The UBACVT macro converts a clist space address for unibus uban
  * into an i/o space address for the DMA routine.
  */
  * The UBACVT macro converts a clist space address for unibus uban
  * into an i/o space address for the DMA routine.
  */
-int    dh_ubinfo[MAXNUBA];             /* info about allocated unibus map */
-int    cbase[MAXNUBA];                 /* base address in unibus map */
+int    dh_uballoc[NUBA];       /* which dh (if any) allocated unibus map */
+int    cbase[NUBA];            /* base address of clists in unibus map */
 #define        UBACVT(x, uban)         (cbase[uban] + ((x)-(char *)cfree))
 
 /*
 #define        UBACVT(x, uban)         (cbase[uban] + ((x)-(char *)cfree))
 
 /*
@@ -117,6 +136,8 @@ dhattach(ui)
 {
 
        dhsoftCAR[ui->ui_unit] = ui->ui_flags;
 {
 
        dhsoftCAR[ui->ui_unit] = ui->ui_flags;
+       cbase[ui->ui_ubanum] = -1;
+       dh_uballoc[ui->ui_unit] = -1;
 }
 
 /*
 }
 
 /*
@@ -177,33 +198,37 @@ dhopen(dev, flag)
         * block uba resets which can clear the state.
         */
        s = spl5();
         * block uba resets which can clear the state.
         */
        s = spl5();
-       if (dh_ubinfo[ui->ui_ubanum] == 0) {
-               /* 512+ is a kludge to try to get around a hardware problem */
-               dh_ubinfo[ui->ui_ubanum] =
-                   uballoc(ui->ui_ubanum, (caddr_t)cfree,
-                       512+nclist*sizeof(struct cblock), 0);
-               cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff;
+       if (cbase[ui->ui_ubanum] == -1) {
+               dh_uballoc[ui->ui_ubanum] = dh;
+               cbase[ui->ui_ubanum] = UBAI_ADDR(uballoc(ui->ui_ubanum,
+                   (caddr_t)cfree, nclist*sizeof(struct cblock), 0));
+       }
+       if (timerstarted == 0) {
+               timerstarted++;
+               timeout(dhtimer, (caddr_t) 0, hz);
        }
        if ((dhact&(1<<dh)) == 0) {
                addr->un.dhcsr |= DH_IE;
                dhact |= (1<<dh);
        }
        if ((dhact&(1<<dh)) == 0) {
                addr->un.dhcsr |= DH_IE;
                dhact |= (1<<dh);
-               addr->dhsilo = 16;
+               addr->dhsilo = 0;
        }
        splx(s);
        /*
        }
        splx(s);
        /*
-        * If this is first open, initialze tty state to default.
+        * If this is first open, initialize tty state to default.
         */
        if ((tp->t_state&TS_ISOPEN) == 0) {
                ttychars(tp);
 #ifndef PORTSELECTOR
                if (tp->t_ispeed == 0) {
         */
        if ((tp->t_state&TS_ISOPEN) == 0) {
                ttychars(tp);
 #ifndef PORTSELECTOR
                if (tp->t_ispeed == 0) {
-#endif
+#else
+                       tp->t_state |= TS_HUPCLS;
+#endif PORTSELECTOR
                        tp->t_ispeed = ISPEED;
                        tp->t_ospeed = ISPEED;
                        tp->t_flags = IFLAGS;
 #ifndef PORTSELECTOR
                }
                        tp->t_ispeed = ISPEED;
                        tp->t_ospeed = ISPEED;
                        tp->t_flags = IFLAGS;
 #ifndef PORTSELECTOR
                }
-#endif
+#endif PORTSELECTOR
                dhparam(unit);
        }
        /*
                dhparam(unit);
        }
        /*
@@ -275,20 +300,20 @@ dhrint(dh)
         */
        while ((c = addr->dhrcr) < 0) {
                tp = tp0 + ((c>>8)&0xf);
         */
        while ((c = addr->dhrcr) < 0) {
                tp = tp0 + ((c>>8)&0xf);
-#ifndef PORTSELECTOR
+               dhchars[dh]++;
                if ((tp->t_state&TS_ISOPEN)==0) {
                if ((tp->t_state&TS_ISOPEN)==0) {
-#else
-               if ((tp->t_state&(TS_ISOPEN|TS_WOPEN))==0) {
+                       wakeup((caddr_t)&tp->t_rawq);
+#ifdef PORTSELECTOR
+                       if ((tp->t_state&TS_WOPEN) == 0)
 #endif
 #endif
-                       wakeup((caddr_t)tp);
-                       continue;
+                               continue;
                }
                if (c & DH_PE)
                        if ((tp->t_flags&(EVENP|ODDP))==EVENP
                         || (tp->t_flags&(EVENP|ODDP))==ODDP )
                                continue;
                if ((c & DH_DO) && overrun == 0) {
                }
                if (c & DH_PE)
                        if ((tp->t_flags&(EVENP|ODDP))==EVENP
                         || (tp->t_flags&(EVENP|ODDP))==ODDP )
                                continue;
                if ((c & DH_DO) && overrun == 0) {
-                       printf("dh%d: silo overflow\n", dh);
+                       log(LOG_WARNING, "dh%d: silo overflow\n", dh);
                        overrun = 1;
                }
                if (c & DH_FE)
                        overrun = 1;
                }
                if (c & DH_FE)
@@ -328,7 +353,8 @@ dhioctl(dev, cmd, data, flag)
                return (error);
        error = ttioctl(tp, cmd, data, flag);
        if (error >= 0) {
                return (error);
        error = ttioctl(tp, cmd, data, flag);
        if (error >= 0) {
-               if (cmd == TIOCSETP || cmd == TIOCSETN)
+               if (cmd == TIOCSETP || cmd == TIOCSETN || cmd == TIOCLBIS ||
+                   cmd == TIOCLBIC || cmd == TIOCLSET)
                        dhparam(unit);
                return (error);
        }
                        dhparam(unit);
                return (error);
        }
@@ -379,12 +405,13 @@ dhparam(unit)
        if ((tp->t_ispeed)==0) {
                tp->t_state |= TS_HUPCLS;
                dmctl(unit, DML_OFF, DMSET);
        if ((tp->t_ispeed)==0) {
                tp->t_state |= TS_HUPCLS;
                dmctl(unit, DML_OFF, DMSET);
+               splx(s);
                return;
        }
        lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6);
        if ((tp->t_ispeed) == B134)
                lpar |= BITS6|PENABLE|HDUPLX;
                return;
        }
        lpar = ((tp->t_ospeed)<<10) | ((tp->t_ispeed)<<6);
        if ((tp->t_ispeed) == B134)
                lpar |= BITS6|PENABLE|HDUPLX;
-       else if (tp->t_flags & (RAW|LITOUT))
+       else if (tp->t_flags & (RAW|LITOUT|PASS8))
                lpar |= BITS8;
        else
                lpar |= BITS7|PENABLE;
                lpar |= BITS8;
        else
                lpar |= BITS7|PENABLE;
@@ -574,19 +601,26 @@ dhreset(uban)
        register struct uba_device *ui;
        int i;
 
        register struct uba_device *ui;
        int i;
 
-       if (dh_ubinfo[uban] == 0)
-               return;
-       dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree,
-           512+nclist*sizeof (struct cblock), 0);
-       cbase[uban] = dh_ubinfo[uban]&0x3ffff;
        dh = 0;
        for (dh = 0; dh < NDH; dh++) {
                ui = dhinfo[dh];
                if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban)
                        continue;
                printf(" dh%d", dh);
        dh = 0;
        for (dh = 0; dh < NDH; dh++) {
                ui = dhinfo[dh];
                if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban)
                        continue;
                printf(" dh%d", dh);
+               if (dh_uballoc[uban] == dh) {
+                       int info;
+
+                       info = uballoc(uban, (caddr_t)cfree,
+                           nclist * sizeof(struct cblock), UBA_CANTWAIT);
+                       if (info)
+                               cbase[uban] = UBAI_ADDR(info);
+                       else {
+                               printf(" [can't get uba map]");
+                               cbase[uban] = -1;
+                       }
+               }
                ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE;
                ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE;
-               ((struct dhdevice *)ui->ui_addr)->dhsilo = 16;
+               ((struct dhdevice *)ui->ui_addr)->dhsilo = 0;
                unit = dh * 16;
                for (i = 0; i < 16; i++) {
                        tp = &dh11[unit];
                unit = dh * 16;
                for (i = 0; i < 16; i++) {
                        tp = &dh11[unit];
@@ -599,21 +633,49 @@ dhreset(uban)
                        unit++;
                }
        }
                        unit++;
                }
        }
-       dhtimer();
+       dhsilos = 0;
 }
 
 }
 
+int dhtransitions, dhslowtimers, dhfasttimers;         /*DEBUG*/
 /*
 /*
- * At software clock interrupt time or after a UNIBUS reset
- * empty all the dh silos.
+ * At software clock interrupt time, check status.
+ * Empty all the dh silos that are in use, and decide whether
+ * to turn any silos off or on.
  */
 dhtimer()
 {
  */
 dhtimer()
 {
-       register int dh;
-       register int s = spl5();
-
-       for (dh = 0; dh < NDH; dh++)
-               dhrint(dh);
-       splx(s);
+       register int dh, s;
+       static int timercalls;
+
+       if (dhsilos) {
+               dhfasttimers++;         /*DEBUG*/
+               timercalls++;
+               s = spl5();
+               for (dh = 0; dh < NDH; dh++)
+                       if (dhsilos & (1 << dh))
+                               dhrint(dh);
+               splx(s);
+       }
+       if ((dhsilos == 0) || ((timercalls += FASTTIMER) >= hz)) {
+               dhslowtimers++;         /*DEBUG*/
+               timercalls = 0;
+               for (dh = 0; dh < NDH; dh++) {
+                   ave(dhrate[dh], dhchars[dh], 8);
+                   if ((dhchars[dh] > dhhighrate) &&
+                     ((dhsilos & (1 << dh)) == 0)) {
+                       ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo =
+                           (dhchars[dh] > 500? 32 : 16);
+                       dhsilos |= (1 << dh);
+                       dhtransitions++;                /*DEBUG*/
+                   } else if ((dhsilos & (1 << dh)) &&
+                     (dhrate[dh] < dhlowrate)) {
+                       ((struct dhdevice *)(dhinfo[dh]->ui_addr))->dhsilo = 0;
+                       dhsilos &= ~(1 << dh);
+                   }
+                   dhchars[dh] = 0;
+               }
+       }
+       timeout(dhtimer, (caddr_t) 0, dhsilos? FASTTIMER: hz);
 }
 
 /*
 }
 
 /*
@@ -633,23 +695,25 @@ dmopen(dev)
        dm = unit >> 4;
        tp = &dh11[unit];
        unit &= 0xf;
        dm = unit >> 4;
        tp = &dh11[unit];
        unit &= 0xf;
-       if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 ||
-           (dhsoftCAR[dm]&(1<<unit))) {
+       if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0) {
                tp->t_state |= TS_CARR_ON;
                return;
        }
        addr = (struct dmdevice *)ui->ui_addr;
        s = spl5();
                tp->t_state |= TS_CARR_ON;
                return;
        }
        addr = (struct dmdevice *)ui->ui_addr;
        s = spl5();
-       addr->dmcsr &= ~DM_SE;
-       while (addr->dmcsr & DM_BUSY)
-               ;
-       addr->dmcsr = unit;
-       addr->dmlstat = DML_ON;
-       if (addr->dmlstat&DML_CAR)
-               tp->t_state |= TS_CARR_ON;
-       addr->dmcsr = DM_IE|DM_SE;
-       while ((tp->t_state&TS_CARR_ON)==0)
+       for (;;) {
+               addr->dmcsr &= ~DM_SE;
+               while (addr->dmcsr & DM_BUSY)
+                       ;
+               addr->dmcsr = unit;
+               addr->dmlstat = DML_ON;
+               if ((addr->dmlstat & DML_CAR) || (dhsoftCAR[dm] & (1 << unit)))
+                       tp->t_state |= TS_CARR_ON;
+               addr->dmcsr = DM_IE|DM_SE;
+               if (tp->t_state & TS_CARR_ON)
+                       break;
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
+       }
        splx(s);
 }
 
        splx(s);
 }
 
@@ -699,6 +763,7 @@ dmintr(dm)
        register struct uba_device *ui;
        register struct tty *tp;
        register struct dmdevice *addr;
        register struct uba_device *ui;
        register struct tty *tp;
        register struct dmdevice *addr;
+       int unit;
 
        ui = dminfo[dm];
        if (ui == 0)
 
        ui = dminfo[dm];
        if (ui == 0)
@@ -706,28 +771,13 @@ dmintr(dm)
        addr = (struct dmdevice *)ui->ui_addr;
        if (addr->dmcsr&DM_DONE) {
                if (addr->dmcsr&DM_CF) {
        addr = (struct dmdevice *)ui->ui_addr;
        if (addr->dmcsr&DM_DONE) {
                if (addr->dmcsr&DM_CF) {
-                       tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)];
-                       wakeup((caddr_t)&tp->t_rawq);
-                       if ((tp->t_state&TS_WOPEN) == 0 &&
-                           (tp->t_flags & MDMBUF)) {
-                               if (addr->dmlstat & DML_CAR) {
-                                       tp->t_state &= ~TS_TTSTOP;
-                                       ttstart(tp);
-                               } else if ((tp->t_state&TS_TTSTOP) == 0) {
-                                       tp->t_state |= TS_TTSTOP;
-                                       dhstop(tp, 0);
-                               }
-                       } else if ((addr->dmlstat&DML_CAR)==0) {
-                               if ((tp->t_state&TS_WOPEN)==0 &&
-                                   (tp->t_flags & NOHANG) == 0) {
-                                       gsignal(tp->t_pgrp, SIGHUP);
-                                       gsignal(tp->t_pgrp, SIGCONT);
-                                       addr->dmlstat = 0;
-                                       flushtty(tp, FREAD|FWRITE);
-                               }
-                               tp->t_state &= ~TS_CARR_ON;
-                       } else
-                               tp->t_state |= TS_CARR_ON;
+                       unit = addr->dmcsr & 0xf;
+                       tp = &dh11[(dm << 4) + unit];
+                       if (addr->dmlstat & DML_CAR)
+                               (void)(*linesw[tp->t_line].l_modem)(tp, 1);
+                       else if ((dhsoftCAR[dm] & (1<<unit)) == 0 &&
+                           (*linesw[tp->t_line].l_modem)(tp, 0) == 0)
+                               addr->dmlstat = 0;
                }
                addr->dmcsr = DM_IE|DM_SE;
        }
                }
                addr->dmcsr = DM_IE|DM_SE;
        }