minor fixes relating to u.u_error handling
[unix-history] / usr / src / sys / vax / uba / dh.c
index 40bd460..f4ae51a 100644 (file)
@@ -1,4 +1,4 @@
-/*     dh.c    4.39    81/10/11        */
+/*     dh.c    4.52    82/10/10        */
 
 #include "dh.h"
 #if NDH > 0
 
 #include "dh.h"
 #if NDH > 0
 #include "../h/conf.h"
 #include "../h/dir.h"
 #include "../h/user.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/ubareg.h"
-#include "../h/ubavar.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.
 
 /*
  * Definition of the driver for the auto-configuration program.
@@ -53,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 */
@@ -149,10 +160,13 @@ dhprobe(reg)
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
 
 #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;
 #endif
 #ifndef notdef
        dhaddr->un.dhcsr = DH_RIE|DH_MM|DH_RI;
-       DELAY(25);
+       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;
@@ -166,7 +180,7 @@ dhprobe(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));
 }
 
 /*
 }
 
 /*
@@ -190,6 +204,7 @@ dmprobe(reg)
 
 #ifdef lint
        br = 0; vec = br; br = vec;
 
 #ifdef lint
        br = 0; vec = br; br = vec;
+       dmintr(0);
 #endif
        dmaddr->dmcsr = DM_DONE|DM_IE;
        DELAY(20);
 #endif
        dmaddr->dmcsr = DM_DONE|DM_IE;
        DELAY(20);
@@ -227,15 +242,14 @@ dhopen(dev, flag)
                return;
        }
        tp = &dh11[unit];
                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.
@@ -257,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);
        }
        /*
@@ -288,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));
 }
 
 /*
 }
 
 /*
@@ -335,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;
                }
@@ -371,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;
        }
@@ -423,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;
        }
@@ -472,9 +499,9 @@ 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;
                                /*
@@ -516,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
@@ -545,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;
                }
        }
@@ -566,7 +597,7 @@ dhstart(tp)
                addr->dhbcr = -nch;
                addr->dhbar |= word;
                }
                addr->dhbcr = -nch;
                addr->dhbar |= word;
                }
-               tp->t_state |= BUSY;
+               tp->t_state |= TS_BUSY;
        }
 out:
        splx(s);
        }
 out:
        splx(s);
@@ -587,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
@@ -596,8 +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;
-               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);
@@ -633,10 +664,10 @@ dhreset(uban)
                unit = dh * 16;
                for (i = 0; i < 16; i++) {
                        tp = &dh11[unit];
                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++;
@@ -652,9 +683,11 @@ dhreset(uban)
 dhtimer()
 {
        register int dh;
 dhtimer()
 {
        register int dh;
+       register int s = spl5();
 
        for (dh = 0; dh < NDH; dh++)
                dhrint(dh);
 
        for (dh = 0; dh < NDH; dh++)
                dhrint(dh);
+       splx(s);
 }
 
 /*
 }
 
 /*
@@ -676,7 +709,7 @@ dmopen(dev)
        unit &= 0xf;
        if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 ||
            (dhsoftCAR[dm]&(1<<unit))) {
        unit &= 0xf;
        if (dm >= NDH || (ui = dminfo[dm]) == 0 || ui->ui_alive == 0 ||
            (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;
@@ -687,9 +720,9 @@ dmopen(dev)
        addr->dmcsr = unit;
        addr->dmlstat = DML_ON;
        if (addr->dmlstat&DML_CAR)
        addr->dmcsr = unit;
        addr->dmlstat = DML_ON;
        if (addr->dmlstat&DML_CAR)
-               tp->t_state |= CARR_ON;
+               tp->t_state |= TS_CARR_ON;
        addr->dmcsr = DM_IE|DM_SE;
        addr->dmcsr = DM_IE|DM_SE;
-       while ((tp->t_state&CARR_ON)==0)
+       while ((tp->t_state&TS_CARR_ON)==0)
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
        splx(s);
 }
                sleep((caddr_t)&tp->t_rawq, TTIPRI);
        splx(s);
 }
@@ -749,26 +782,26 @@ dmintr(dm)
                if (addr->dmcsr&DM_CF) {
                        tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)];
                        wakeup((caddr_t)&tp->t_rawq);
                if (addr->dmcsr&DM_CF) {
                        tp = &dh11[(dm<<4)+(addr->dmcsr&0xf)];
                        wakeup((caddr_t)&tp->t_rawq);
-                       if ((tp->t_state&WOPEN)==0 &&
+                       if ((tp->t_state&TS_WOPEN)==0 &&
                            (tp->t_local&LMDMBUF)) {
                                if (addr->dmlstat & DML_CAR) {
                            (tp->t_local&LMDMBUF)) {
                                if (addr->dmlstat & DML_CAR) {
-                                       tp->t_state &= ~TTSTOP;
+                                       tp->t_state &= ~TS_TTSTOP;
                                        ttstart(tp);
                                        ttstart(tp);
-                               } else if ((tp->t_state&TTSTOP) == 0) {
-                                       tp->t_state |= TTSTOP;
+                               } else if ((tp->t_state&TS_TTSTOP) == 0) {
+                                       tp->t_state |= TS_TTSTOP;
                                        dhstop(tp, 0);
                                }
                        } else if ((addr->dmlstat&DML_CAR)==0) {
                                        dhstop(tp, 0);
                                }
                        } else if ((addr->dmlstat&DML_CAR)==0) {
-                               if ((tp->t_state&WOPEN)==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_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;
+                               tp->t_state &= ~TS_CARR_ON;
                        } else
                        } else
-                               tp->t_state |= CARR_ON;
+                               tp->t_state |= TS_CARR_ON;
                }
                addr->dmcsr = DM_IE|DM_SE;
        }
                }
                addr->dmcsr = DM_IE|DM_SE;
        }