minor fixes relating to u.u_error handling
[unix-history] / usr / src / sys / vax / uba / dh.c
index 3ba0b49..f4ae51a 100644 (file)
@@ -1,41 +1,45 @@
-/*     dh.c    4.19    81/02/19        */
+/*     dh.c    4.52    82/10/10        */
 
 #include "dh.h"
 
 #include "dh.h"
-#if NDH11 > 0
-#define        DELAY(i)        { register int j = i; while (--j > 0); }
+#if NDH > 0
 /*
  * DH-11/DM-11 driver
  */
 /*
  * DH-11/DM-11 driver
  */
+#include "bk.h"
 #include "../h/param.h"
 #include "../h/conf.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/param.h"
 #include "../h/conf.h"
 #include "../h/dir.h"
 #include "../h/user.h"
+#include "../h/proc.h"
 #include "../h/tty.h"
 #include "../h/map.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
 #include "../h/tty.h"
 #include "../h/map.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
-#include "../h/uba.h"
+
+#include "../vaxuba/ubareg.h"
+#include "../vaxuba/ubavar.h"
+
 #include "../h/bk.h"
 #include "../h/clist.h"
 #include "../h/bk.h"
 #include "../h/clist.h"
-#include "../h/mx.h"
 #include "../h/file.h"
 #include "../h/file.h"
+#include "../h/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    dhcntrlr(), dhslave(), dhrint(), dhxint();
-struct uba_dinfo *dhinfo[NDH11];
+int    dhprobe(), dhattach(), dhrint(), dhxint();
+struct uba_device *dhinfo[NDH];
 u_short        dhstd[] = { 0 };
 struct uba_driver dhdriver =
 u_short        dhstd[] = { 0 };
 struct uba_driver dhdriver =
-       { dhcntrlr, dhslave, 0, 0, dhstd, "dh", dhinfo };
+       { dhprobe, 0, dhattach, 0, dhstd, "dh", dhinfo };
 
 
-int    dmcntrlr(), dmslave(), dmintr();
-struct uba_dinfo *dminfo[NDH11];
+int    dmprobe(), dmattach(), dmintr();
+struct uba_device *dminfo[NDH];
 u_short        dmstd[] = { 0 };
 struct uba_driver dmdriver =
 u_short        dmstd[] = { 0 };
 struct uba_driver dmdriver =
-       { dmcntrlr, dmslave, 0, 0, dmstd, "dm", dminfo };
+       { dmprobe, 0, dmattach, 0, dmstd, "dm", dminfo };
 
 struct dhdevice
 {
 
 struct dhdevice
 {
@@ -52,6 +56,14 @@ struct dhdevice
        short   dhsilo;                 /* silo status register */
 };
 
        short   dhsilo;                 /* silo status register */
 };
 
+#ifndef        PORTSELECTOR
+#define        ISPEED  B300
+#define        IFLAGS  (EVENP|ODDP|ECHO)
+#else
+#define        ISPEED  B4800
+#define        IFLAGS  (EVENP|ODDP)
+#endif
+
 /* Bits in dhcsr */
 #define        DH_TI   0100000         /* transmit interrupt */
 #define        DH_SI   0040000         /* storage interrupt */
 /* Bits in dhcsr */
 #define        DH_TI   0100000         /* transmit interrupt */
 #define        DH_SI   0040000         /* storage interrupt */
@@ -112,17 +124,17 @@ struct dmdevice
 #define        DML_DTR         0000002         /* data terminal ready */
 #define        DML_LE          0000001         /* line enable */
 
 #define        DML_DTR         0000002         /* data terminal ready */
 #define        DML_LE          0000001         /* line enable */
 
-#define        DML_ON          (DML_DTR|DML_LE)
+#define        DML_ON          (DML_DTR|DML_RTS|DML_LE)
 #define        DML_OFF         (DML_LE)
 
 /*
  * Local variables for the driver
  */
 #define        DML_OFF         (DML_LE)
 
 /*
  * Local variables for the driver
  */
-short  dhsar[NDH11];                   /* software copy of last bar */
-short  dhsoftCAR[NDH11];
+short  dhsar[NDH];                     /* software copy of last bar */
+short  dhsoftCAR[NDH];
 
 
-struct tty dh11[NDH11*16];
-int    ndh11   = NDH11*16;
+struct tty dh11[NDH*16];
+int    ndh11   = NDH*16;
 int    dhact;                          /* mask of active dh's */
 int    dhstart(), ttrstrt();
 
 int    dhact;                          /* mask of active dh's */
 int    dhstart(), ttrstrt();
 
@@ -140,17 +152,21 @@ int       cbase[MAXNUBA];                 /* base address in unibus map */
  * Set to transmit at 9600 baud, and cause a transmitter interrupt.
  */
 /*ARGSUSED*/
  * Set to transmit at 9600 baud, and cause a transmitter interrupt.
  */
 /*ARGSUSED*/
-dhcntrlr(ui, reg)
-       struct uba_dinfo *ui;
+dhprobe(reg)
        caddr_t reg;
 {
        register int br, cvec;          /* these are ``value-result'' */
        register struct dhdevice *dhaddr = (struct dhdevice *)reg;
        caddr_t reg;
 {
        register int br, cvec;          /* these are ``value-result'' */
        register struct dhdevice *dhaddr = (struct dhdevice *)reg;
-       int i;
 
 
-#ifdef notdef
+#ifdef lint
+       br = 0; cvec = br; br = cvec;
+       if (ndh11 == 0) ndh11 = 1;
+       dhrint(0); dhxint(0);
+#endif
+#ifndef notdef
        dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI;
        dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI;
-       DELAY(5);
+       DELAY(1000);
+       dhaddr->un.dhcsr &= ~DH_RI;
        dhaddr->un.dhcsr = 0;
 #else
        dhaddr->un.dhcsr = DH_TIE;
        dhaddr->un.dhcsr = 0;
 #else
        dhaddr->un.dhcsr = DH_TIE;
@@ -164,15 +180,14 @@ dhcntrlr(ui, reg)
        if (cvec && cvec != 0x200)
                cvec -= 4;              /* transmit -> receive */
 #endif
        if (cvec && cvec != 0x200)
                cvec -= 4;              /* transmit -> receive */
 #endif
-       return (1);
+       return (sizeof (struct dhdevice));
 }
 
 /*
 }
 
 /*
- * Routine called to init slave tables.
+ * Routine called to attach a dh.
  */
  */
-dhslave(ui, reg)
-       struct uba_dinfo *ui;
-       caddr_t reg;
+dhattach(ui)
+       struct uba_device *ui;
 {
 
        dhsoftCAR[ui->ui_unit] = ui->ui_flags;
 {
 
        dhsoftCAR[ui->ui_unit] = ui->ui_flags;
@@ -181,22 +196,25 @@ dhslave(ui, reg)
 /*
  * Configuration routine to cause a dm to interrupt.
  */
 /*
  * Configuration routine to cause a dm to interrupt.
  */
-dmcntrlr(um, addr)
-       struct uba_minfo *um;
-       caddr_t addr;
+dmprobe(reg)
+       caddr_t reg;
 {
        register int br, vec;                   /* value-result */
 {
        register int br, vec;                   /* value-result */
-       register struct dmdevice *dmaddr = (struct dmdevice *)addr;
+       register struct dmdevice *dmaddr = (struct dmdevice *)reg;
 
 
+#ifdef lint
+       br = 0; vec = br; br = vec;
+       dmintr(0);
+#endif
        dmaddr->dmcsr = DM_DONE|DM_IE;
        DELAY(20);
        dmaddr->dmcsr = 0;
        dmaddr->dmcsr = DM_DONE|DM_IE;
        DELAY(20);
        dmaddr->dmcsr = 0;
+       return (1);
 }
 
 }
 
-dmslave(ui, addr, slave)
-       struct uba_dinfo *ui;
-       caddr_t addr;
-       int slave;
+/*ARGSUSED*/
+dmattach(ui)
+       struct uba_device *ui;
 {
 
        /* no local state to set up */
 {
 
        /* no local state to set up */
@@ -214,25 +232,24 @@ dhopen(dev, flag)
        register struct tty *tp;
        register int unit, dh;
        register struct dhdevice *addr;
        register struct tty *tp;
        register int unit, dh;
        register struct dhdevice *addr;
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        int s;
 
        unit = minor(dev);
        dh = unit >> 4;
        int s;
 
        unit = minor(dev);
        dh = unit >> 4;
-       if (unit >= NDH11*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) {
+       if (unit >= NDH*16 || (ui = dhinfo[dh])== 0 || ui->ui_alive == 0) {
                u.u_error = ENXIO;
                return;
        }
        tp = &dh11[unit];
                u.u_error = ENXIO;
                return;
        }
        tp = &dh11[unit];
-       if (tp->t_state&XCLUDE && u.u_uid!=0) {
+       if (tp->t_state&TS_XCLUDE && u.u_uid!=0) {
                u.u_error = EBUSY;
                return;
        }
        addr = (struct dhdevice *)ui->ui_addr;
        tp->t_addr = (caddr_t)addr;
        tp->t_oproc = dhstart;
                u.u_error = EBUSY;
                return;
        }
        addr = (struct dhdevice *)ui->ui_addr;
        tp->t_addr = (caddr_t)addr;
        tp->t_oproc = dhstart;
-       tp->t_iproc = NULL;
-       tp->t_state |= WOPEN;
+       tp->t_state |= TS_WOPEN;
        /*
         * While setting up state for this uba and this dh,
         * block uba resets which can clear the state.
        /*
         * While setting up state for this uba and this dh,
         * block uba resets which can clear the state.
@@ -242,12 +259,11 @@ dhopen(dev, flag)
                /* 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+ 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);
+                       512+nclist*sizeof(struct cblock), 0);
                cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff;
        }
        if ((dhact&(1<<dh)) == 0) {
                addr->un.dhcsr |= DH_IE;
                cbase[ui->ui_ubanum] = dh_ubinfo[ui->ui_ubanum]&0x3ffff;
        }
        if ((dhact&(1<<dh)) == 0) {
                addr->un.dhcsr |= DH_IE;
-               DELAY(5);
                dhact |= (1<<dh);
                addr->dhsilo = 16;
        }
                dhact |= (1<<dh);
                addr->dhsilo = 16;
        }
@@ -255,13 +271,17 @@ dhopen(dev, flag)
        /*
         * If this is first open, initialze tty state to default.
         */
        /*
         * If this is first open, initialze tty state to default.
         */
-       if ((tp->t_state&ISOPEN) == 0) {
+       if ((tp->t_state&TS_ISOPEN) == 0) {
                ttychars(tp);
                ttychars(tp);
+#ifndef PORTSELECTOR
                if (tp->t_ispeed == 0) {
                if (tp->t_ispeed == 0) {
-                       tp->t_ispeed = B300;
-                       tp->t_ospeed = B300;
-                       tp->t_flags = ODDP|EVENP|ECHO;
+#endif
+                       tp->t_ispeed = ISPEED;
+                       tp->t_ospeed = ISPEED;
+                       tp->t_flags = IFLAGS;
+#ifndef PORTSELECTOR
                }
                }
+#endif
                dhparam(unit);
        }
        /*
                dhparam(unit);
        }
        /*
@@ -286,27 +306,27 @@ dhclose(dev, flag)
        tp = &dh11[unit];
        (*linesw[tp->t_line].l_close)(tp);
        ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017));
        tp = &dh11[unit];
        (*linesw[tp->t_line].l_close)(tp);
        ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017));
-       if (tp->t_state&HUPCLS || (tp->t_state&ISOPEN)==0)
+       if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0)
                dmctl(unit, DML_OFF, DMSET);
        ttyclose(tp);
 }
 
                dmctl(unit, DML_OFF, DMSET);
        ttyclose(tp);
 }
 
-dhread(dev)
+dhread(dev, uio)
        dev_t dev;
        dev_t dev;
+       struct uio *uio;
 {
 {
-       register struct tty *tp;
+       register struct tty *tp = &dh11[minor(dev)];
 
 
-       tp = &dh11[minor(dev)];
-       (*linesw[tp->t_line].l_read)(tp);
+       return ((*linesw[tp->t_line].l_read)(tp, uio));
 }
 
 }
 
-dhwrite(dev)
+dhwrite(dev, uio)
        dev_t dev;
        dev_t dev;
+       struct uio *uio;
 {
 {
-       register struct tty *tp;
+       register struct tty *tp = &dh11[minor(dev)];
 
 
-       tp = &dh11[minor(dev)];
-       (*linesw[tp->t_line].l_write)(tp);
+       return ((*linesw[tp->t_line].l_write)(tp, uio));
 }
 
 /*
 }
 
 /*
@@ -319,8 +339,8 @@ dhrint(dh)
        register c;
        register struct dhdevice *addr;
        register struct tty *tp0;
        register c;
        register struct dhdevice *addr;
        register struct tty *tp0;
-       register struct uba_dinfo *ui;
-       int s;
+       register struct uba_device *ui;
+       int overrun = 0;
 
        ui = dhinfo[dh];
        if (ui == 0 || ui->ui_alive == 0)
 
        ui = dhinfo[dh];
        if (ui == 0 || ui->ui_alive == 0)
@@ -333,7 +353,11 @@ dhrint(dh)
         */
        while ((c = addr->dhrcr) < 0) {
                tp = tp0 + ((c>>8)&0xf);
         */
        while ((c = addr->dhrcr) < 0) {
                tp = tp0 + ((c>>8)&0xf);
-               if ((tp->t_state&ISOPEN)==0) {
+#ifndef PORTSELECTOR
+               if ((tp->t_state&TS_ISOPEN)==0) {
+#else
+               if ((tp->t_state&(TS_ISOPEN|TS_WOPEN))==0) {
+#endif
                        wakeup((caddr_t)tp);
                        continue;
                }
                        wakeup((caddr_t)tp);
                        continue;
                }
@@ -341,8 +365,10 @@ dhrint(dh)
                        if ((tp->t_flags&(EVENP|ODDP))==EVENP
                         || (tp->t_flags&(EVENP|ODDP))==ODDP )
                                continue;
                        if ((tp->t_flags&(EVENP|ODDP))==EVENP
                         || (tp->t_flags&(EVENP|ODDP))==ODDP )
                                continue;
-               if (c & DH_DO)
-                       printf("O");
+               if ((c & DH_DO) && overrun == 0) {
+                       printf("dh%d: silo overflow\n", dh);
+                       overrun = 1;
+               }
                if (c & DH_FE)
                        /*
                         * At framing error (break) generate
                if (c & DH_FE)
                        /*
                         * At framing error (break) generate
@@ -353,10 +379,12 @@ dhrint(dh)
                                c = 0;
                        else
                                c = tun.t_intrc;
                                c = 0;
                        else
                                c = tun.t_intrc;
+#if NBK > 0
                if (tp->t_line == NETLDISC) {
                        c &= 0177;
                        BKINPUT(c, tp);
                } else
                if (tp->t_line == NETLDISC) {
                        c &= 0177;
                        BKINPUT(c, tp);
                } else
+#endif
                        (*linesw[tp->t_line].l_rint)(c, tp);
        }
 }
                        (*linesw[tp->t_line].l_rint)(c, tp);
        }
 }
@@ -365,32 +393,37 @@ dhrint(dh)
  * Ioctl for DH11.
  */
 /*ARGSUSED*/
  * Ioctl for DH11.
  */
 /*ARGSUSED*/
-dhioctl(dev, cmd, addr, flag)
-       caddr_t addr;
+dhioctl(dev, cmd, data, flag)
+       caddr_t data;
 {
        register struct tty *tp;
        register unit = minor(dev);
 
        tp = &dh11[unit];
 {
        register struct tty *tp;
        register unit = minor(dev);
 
        tp = &dh11[unit];
-       cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr);
+       cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag);
        if (cmd == 0)
                return;
        if (cmd == 0)
                return;
-       if (ttioctl(tp, cmd, addr, flag)) {
-               if (cmd==TIOCSETP || cmd==TIOCSETN)
+       if (ttioctl(tp, cmd, data, flag)) {
+               if (cmd == TIOCSETP || cmd == TIOCSETN)
                        dhparam(unit);
        } else switch(cmd) {
                        dhparam(unit);
        } else switch(cmd) {
+
        case TIOCSBRK:
                ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017);
                break;
        case TIOCSBRK:
                ((struct dhdevice *)(tp->t_addr))->dhbreak |= 1<<(unit&017);
                break;
+
        case TIOCCBRK:
                ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017));
                break;
        case TIOCCBRK:
                ((struct dhdevice *)(tp->t_addr))->dhbreak &= ~(1<<(unit&017));
                break;
+
        case TIOCSDTR:
                dmctl(unit, DML_DTR|DML_RTS, DMBIS);
                break;
        case TIOCSDTR:
                dmctl(unit, DML_DTR|DML_RTS, DMBIS);
                break;
+
        case TIOCCDTR:
                dmctl(unit, DML_DTR|DML_RTS, DMBIC);
                break;
        case TIOCCDTR:
                dmctl(unit, DML_DTR|DML_RTS, DMBIC);
                break;
+
        default:
                u.u_error = ENOTTY;
        }
        default:
                u.u_error = ENOTTY;
        }
@@ -417,7 +450,7 @@ dhparam(unit)
        s = spl5();
        addr->un.dhcsrl = (unit&0xf) | DH_IE;
        if ((tp->t_ispeed)==0) {
        s = spl5();
        addr->un.dhcsrl = (unit&0xf) | DH_IE;
        if ((tp->t_ispeed)==0) {
-               tp->t_state |= HUPCLS;
+               tp->t_state |= TS_HUPCLS;
                dmctl(unit, DML_OFF, DMSET);
                return;
        }
                dmctl(unit, DML_OFF, DMSET);
                return;
        }
@@ -447,17 +480,15 @@ dhxint(dh)
        register struct tty *tp;
        register struct dhdevice *addr;
        short ttybit, bar, *sbar;
        register struct tty *tp;
        register struct dhdevice *addr;
        short ttybit, bar, *sbar;
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        register int unit;
        register int unit;
-       int s;
-       u_short cnt;
+       u_short cntr;
 
        ui = dhinfo[dh];
        addr = (struct dhdevice *)ui->ui_addr;
        if (addr->un.dhcsr & DH_NXM) {
 
        ui = dhinfo[dh];
        addr = (struct dhdevice *)ui->ui_addr;
        if (addr->un.dhcsr & DH_NXM) {
-               DELAY(5);
                addr->un.dhcsr |= DH_CNI;
                addr->un.dhcsr |= DH_CNI;
-               printf("dh%d NXM\n", dh);
+               printf("dh%d: NXM\n", dh);
        }
        sbar = &dhsar[dh];
        bar = *sbar & ~addr->dhbar;
        }
        sbar = &dhsar[dh];
        bar = *sbar & ~addr->dhbar;
@@ -468,19 +499,18 @@ dhxint(dh)
                        *sbar &= ~ttybit;
                        bar &= ~ttybit;
                        tp = &dh11[unit];
                        *sbar &= ~ttybit;
                        bar &= ~ttybit;
                        tp = &dh11[unit];
-                       tp->t_state &= ~BUSY;
-                       if (tp->t_state&FLUSH)
-                               tp->t_state &= ~FLUSH;
+                       tp->t_state &= ~TS_BUSY;
+                       if (tp->t_state&TS_FLUSH)
+                               tp->t_state &= ~TS_FLUSH;
                        else {
                                addr->un.dhcsrl = (unit&017)|DH_IE;
                        else {
                                addr->un.dhcsrl = (unit&017)|DH_IE;
-                               DELAY(5);
                                /*
                                 * Do arithmetic in a short to make up
                                 * for lost 16&17 bits.
                                 */
                                /*
                                 * Do arithmetic in a short to make up
                                 * for lost 16&17 bits.
                                 */
-                               cnt = addr->dhcar -
+                               cntr = addr->dhcar -
                                    UBACVT(tp->t_outq.c_cf, ui->ui_ubanum);
                                    UBACVT(tp->t_outq.c_cf, ui->ui_ubanum);
-                               ndflush(&tp->t_outq, cnt);
+                               ndflush(&tp->t_outq, (int)cntr);
                        }
                        if (tp->t_line)
                                (*linesw[tp->t_line].l_start)(tp);
                        }
                        if (tp->t_line)
                                (*linesw[tp->t_line].l_start)(tp);
@@ -513,18 +543,22 @@ dhstart(tp)
        /*
         * If it's currently active, or delaying, no need to do anything.
         */
        /*
         * If it's currently active, or delaying, no need to do anything.
         */
-       if (tp->t_state&(TIMEOUT|BUSY|TTSTOP))
+       if (tp->t_state&(TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
                goto out;
        /*
         * If there are sleepers, and output has drained below low
         * water mark, wake up the sleepers.
         */
                goto out;
        /*
         * If there are sleepers, and output has drained below low
         * water mark, wake up the sleepers.
         */
-       if ((tp->t_state&ASLEEP) && tp->t_outq.c_cc<=TTLOWAT(tp)) {
-               tp->t_state &= ~ASLEEP;
-               if (tp->t_chan)
-                       mcstart(tp->t_chan, (caddr_t)&tp->t_outq);
-               else
+       if (tp->t_outq.c_cc<=TTLOWAT(tp)) {
+               if (tp->t_state&TS_ASLEEP) {
+                       tp->t_state &= ~TS_ASLEEP;
                        wakeup((caddr_t)&tp->t_outq);
                        wakeup((caddr_t)&tp->t_outq);
+               }
+               if (tp->t_wsel) {
+                       selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
+                       tp->t_wsel = 0;
+                       tp->t_state &= ~TS_WCOLL;
+               }
        }
        /*
         * Now restart transmission unless the output queue is
        }
        /*
         * Now restart transmission unless the output queue is
@@ -532,7 +566,7 @@ dhstart(tp)
         */
        if (tp->t_outq.c_cc == 0)
                goto out;
         */
        if (tp->t_outq.c_cc == 0)
                goto out;
-       if (tp->t_flags & RAW)
+       if (tp->t_flags&RAW || tp->t_local&LLITOUT)
                nch = ndqb(&tp->t_outq, 0);
        else {
                nch = ndqb(&tp->t_outq, 0200);
                nch = ndqb(&tp->t_outq, 0);
        else {
                nch = ndqb(&tp->t_outq, 0200);
@@ -542,7 +576,7 @@ dhstart(tp)
                if (nch == 0) {
                        nch = getc(&tp->t_outq);
                        timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6);
                if (nch == 0) {
                        nch = getc(&tp->t_outq);
                        timeout(ttrstrt, (caddr_t)tp, (nch&0x7f)+6);
-                       tp->t_state |= TIMEOUT;
+                       tp->t_state |= TS_TIMEOUT;
                        goto out;
                }
        }
                        goto out;
                }
        }
@@ -552,13 +586,18 @@ dhstart(tp)
        if (nch) {
                car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum);
                addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE;
        if (nch) {
                car = UBACVT(tp->t_outq.c_cf, dhinfo[dh]->ui_ubanum);
                addr->un.dhcsrl = unit|((car>>12)&0x30)|DH_IE;
-               DELAY(5);
-               unit = 1 << unit;
-               dhsar[dh] |= unit;
+               /*
+                * The following nonsense with short word
+                * is to make sure the dhbar |= word below
+                * is done with an interlocking bisw2 instruction.
+                */
+               { short word = 1 << unit;
+               dhsar[dh] |= word;
                addr->dhcar = car;
                addr->dhbcr = -nch;
                addr->dhcar = car;
                addr->dhbcr = -nch;
-               addr->dhbar |= unit;
-               tp->t_state |= BUSY;
+               addr->dhbar |= word;
+               }
+               tp->t_state |= TS_BUSY;
        }
 out:
        splx(s);
        }
 out:
        splx(s);
@@ -579,7 +618,7 @@ dhstop(tp, flag)
         * Block input/output interrupts while messing with state.
         */
        s = spl5();
         * Block input/output interrupts while messing with state.
         */
        s = spl5();
-       if (tp->t_state & BUSY) {
+       if (tp->t_state & TS_BUSY) {
                /*
                 * Device is transmitting; stop output
                 * by selecting the line and setting the byte
                /*
                 * Device is transmitting; stop output
                 * by selecting the line and setting the byte
@@ -588,9 +627,8 @@ dhstop(tp, flag)
                 */
                unit = minor(tp->t_dev);
                addr->un.dhcsrl = (unit&017) | DH_IE;
                 */
                unit = minor(tp->t_dev);
                addr->un.dhcsrl = (unit&017) | DH_IE;
-               DELAY(5);
-               if ((tp->t_state&TTSTOP)==0)
-                       tp->t_state |= FLUSH;
+               if ((tp->t_state&TS_TTSTOP)==0)
+                       tp->t_state |= TS_FLUSH;
                addr->dhbcr = -1;
        }
        splx(s);
                addr->dhbcr = -1;
        }
        splx(s);
@@ -606,31 +644,30 @@ dhreset(uban)
 {
        register int dh, unit;
        register struct tty *tp;
 {
        register int dh, unit;
        register struct tty *tp;
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        int i;
 
        if (dh_ubinfo[uban] == 0)
                return;
        int i;
 
        if (dh_ubinfo[uban] == 0)
                return;
-       printf(" dh");
        ubarelse(uban, &dh_ubinfo[uban]);
        dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree,
        ubarelse(uban, &dh_ubinfo[uban]);
        dh_ubinfo[uban] = uballoc(uban, (caddr_t)cfree,
-           512+NCLIST*sizeof (struct cblock), 0);
+           512+nclist*sizeof (struct cblock), 0);
        cbase[uban] = dh_ubinfo[uban]&0x3ffff;
        dh = 0;
        cbase[uban] = dh_ubinfo[uban]&0x3ffff;
        dh = 0;
-       for (dh = 0; dh < NDH11; dh++) {
+       for (dh = 0; dh < NDH; dh++) {
                ui = dhinfo[dh];
                if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban)
                        continue;
                ui = dhinfo[dh];
                if (ui == 0 || ui->ui_alive == 0 || ui->ui_ubanum != uban)
                        continue;
+               printf(" dh%d", dh);
                ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE;
                ((struct dhdevice *)ui->ui_addr)->un.dhcsr |= DH_IE;
-               DELAY(5);
                ((struct dhdevice *)ui->ui_addr)->dhsilo = 16;
                unit = dh * 16;
                for (i = 0; i < 16; i++) {
                        tp = &dh11[unit];
                ((struct dhdevice *)ui->ui_addr)->dhsilo = 16;
                unit = dh * 16;
                for (i = 0; i < 16; i++) {
                        tp = &dh11[unit];
-                       if (tp->t_state & (ISOPEN|WOPEN)) {
+                       if (tp->t_state & (TS_ISOPEN|TS_WOPEN)) {
                                dhparam(unit);
                                dmctl(unit, DML_ON, DMSET);
                                dhparam(unit);
                                dmctl(unit, DML_ON, DMSET);
-                               tp->t_state &= ~BUSY;
+                               tp->t_state &= ~TS_BUSY;
                                dhstart(tp);
                        }
                        unit++;
                                dhstart(tp);
                        }
                        unit++;
@@ -646,9 +683,11 @@ dhreset(uban)
 dhtimer()
 {
        register int dh;
 dhtimer()
 {
        register int dh;
+       register int s = spl5();
 
 
-       for (dh = 0; dh < NDH11; dh++)
+       for (dh = 0; dh < NDH; dh++)
                dhrint(dh);
                dhrint(dh);
+       splx(s);
 }
 
 /*
 }
 
 /*
@@ -659,32 +698,33 @@ dmopen(dev)
 {
        register struct tty *tp;
        register struct dmdevice *addr;
 {
        register struct tty *tp;
        register struct dmdevice *addr;
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        register int unit;
        register int dm;
        register int unit;
        register int dm;
+       int s;
 
        unit = minor(dev);
        dm = unit >> 4;
        tp = &dh11[unit];
        unit &= 0xf;
 
        unit = minor(dev);
        dm = unit >> 4;
        tp = &dh11[unit];
        unit &= 0xf;
-       if (dm >= NDH11 || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 ||
+       if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 ||
            (dhsoftCAR[dm]&(1<<unit))) {
            (dhsoftCAR[dm]&(1<<unit))) {
-               tp->t_state |= CARR_ON;
+               tp->t_state |= TS_CARR_ON;
                return;
        }
        addr = (struct dmdevice *)ui->ui_addr;
                return;
        }
        addr = (struct dmdevice *)ui->ui_addr;
-       spl5();
+       s = spl5();
        addr->dmcsr &= ~DM_SE;
        while (addr->dmcsr & DM_BUSY)
                ;
        addr->dmcsr = unit;
        addr->dmlstat = DML_ON;
        if (addr->dmlstat&DML_CAR)
        addr->dmcsr &= ~DM_SE;
        while (addr->dmcsr & DM_BUSY)
                ;
        addr->dmcsr = unit;
        addr->dmlstat = DML_ON;
        if (addr->dmlstat&DML_CAR)
-               tp->t_state |= CARR_ON;
-       addr->dmcsr = DH_IE|DM_SE;
-       while ((tp->t_state&CARR_ON)==0)
+               tp->t_state |= TS_CARR_ON;
+       addr->dmcsr = DM_IE|DM_SE;
+       while ((tp->t_state&TS_CARR_ON)==0)
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
-       spl0();
+       splx(s);
 }
 
 /*
 }
 
 /*
@@ -694,7 +734,7 @@ dmctl(dev, bits, how)
        dev_t dev;
        int bits, how;
 {
        dev_t dev;
        int bits, how;
 {
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        register struct dmdevice *addr;
        register int unit, s;
        int dm;
        register struct dmdevice *addr;
        register int unit, s;
        int dm;
@@ -720,7 +760,7 @@ dmctl(dev, bits, how)
                addr->dmlstat &= ~bits;
                break;
        }
                addr->dmlstat &= ~bits;
                break;
        }
-       addr->dmcsr = DH_IE|DM_SE;
+       addr->dmcsr = DM_IE|DM_SE;
        splx(s);
 }
 
        splx(s);
 }
 
@@ -730,7 +770,7 @@ dmctl(dev, bits, how)
 dmintr(dm)
        register int dm;
 {
 dmintr(dm)
        register int dm;
 {
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
        register struct tty *tp;
        register struct dmdevice *addr;
 
        register struct tty *tp;
        register struct dmdevice *addr;
 
@@ -738,29 +778,32 @@ dmintr(dm)
        if (ui == 0)
                return;
        addr = (struct dmdevice *)ui->ui_addr;
        if (ui == 0)
                return;
        addr = (struct dmdevice *)ui->ui_addr;
-       if (addr->dmcsr&DM_DONE && addr->dmcsr&DM_CF) {
-               tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)];
-               wakeup((caddr_t)&tp->t_rawq);
-               if ((tp->t_state&WOPEN)==0 &&
-                   (tp->t_local&LMDMBUF)) {
-                       if (addr->dmlstat & DML_CAR) {
-                               tp->t_state &= ~TTSTOP;
-                               ttstart(tp);
-                       } else if ((tp->t_state&TTSTOP) == 0) {
-                               tp->t_state |= TTSTOP;
-                               dhstop(tp, 0);
-                       }
-               } else if ((addr->dmlstat&DML_CAR)==0) {
-                       if ((tp->t_state&WOPEN)==0 &&
-                           (tp->t_local&LNOHANG)==0) {
-                               gsignal(tp->t_pgrp, SIGHUP);
-                               gsignal(tp->t_pgrp, SIGCONT);
-                               addr->dmlstat = 0;
-                               flushtty(tp, FREAD|FWRITE);
-                       }
-                       tp->t_state &= ~CARR_ON;
-               } else
-                       tp->t_state |= CARR_ON;
-               addr->dmcsr = DH_IE|DM_SE;
+       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_local&LMDMBUF)) {
+                               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_local&LNOHANG)==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;
+               }
+               addr->dmcsr = DM_IE|DM_SE;
        }
 }
        }
 }
+#endif