BSD 4_4 release
[unix-history] / usr / src / sys / vax / uba / ts.c
index d7956c9..9af0214 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)ts.c        7.9 (Berkeley) %G%
+ *     @(#)ts.c        7.15 (Berkeley) 2/27/92
  */
 
 #include "ts.h"
  */
 
 #include "ts.h"
  * TODO:
  *     test dump code
  */
  * TODO:
  *     test dump code
  */
-#include "param.h"
-#include "systm.h"
-#include "buf.h"
-#include "conf.h"
-#include "user.h"
-#include "file.h"
-#include "map.h"
-#include "vm.h"
-#include "ioctl.h"
-#include "mtio.h"
-#include "cmap.h"
-#include "uio.h"
-#include "tty.h"
-#include "syslog.h"
-
-#include "machine/pte.h"
-#include "../vax/cpu.h"
+#include "sys/param.h"
+#include "sys/systm.h"
+#include "sys/buf.h"
+#include "sys/conf.h"
+#include "sys/errno.h"
+#include "sys/file.h"
+#include "sys/map.h"
+#include "sys/vm.h"
+#include "sys/ioctl.h"
+#include "sys/mtio.h"
+#include "sys/cmap.h"
+#include "sys/uio.h"
+#include "sys/syslog.h"
+#include "sys/tprintf.h"
+
+#include "../include/pte.h"
+#include "../include/cpu.h"
 #include "ubareg.h"
 #include "ubavar.h"
 #include "tsreg.h"
 #include "ubareg.h"
 #include "ubavar.h"
 #include "tsreg.h"
@@ -95,7 +95,7 @@ struct        ts_softc {
        struct  ts_tsdata *sc_ubaddr; /* Unibus address of tsdata structure */
        u_short sc_uba;         /* Unibus addr of cmd pkt for tsdb */
        short   sc_density;     /* value |'ed into char_mode for TC13 density */
        struct  ts_tsdata *sc_ubaddr; /* Unibus address of tsdata structure */
        u_short sc_uba;         /* Unibus addr of cmd pkt for tsdb */
        short   sc_density;     /* value |'ed into char_mode for TC13 density */
-       caddr_t sc_ctty;        /* user's controlling tty (vnode) */
+       tpr_t   sc_tpr;         /* tprintf handle */
        int     sc_blks;        /* number of I/O operations since open */
        int     sc_softerrs;    /* number of soft I/O errors since open */
 } ts_softc[NTS];
        int     sc_blks;        /* number of I/O operations since open */
        int     sc_softerrs;    /* number of soft I/O errors since open */
 } ts_softc[NTS];
@@ -124,7 +124,6 @@ tsprobe(reg, ctlr, um)
        register struct tsdevice *addr = (struct tsdevice *)reg;
        register struct ts_softc *sc;
        register int i;
        register struct tsdevice *addr = (struct tsdevice *)reg;
        register struct ts_softc *sc;
        register int i;
-       int a;
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
 
 #ifdef lint
        br = 0; cvec = br; br = cvec;
@@ -140,7 +139,7 @@ tsprobe(reg, ctlr, um)
         * TS_SETCHR|TS_IE alone refuses to interrupt for me.
         */
        sc = &ts_softc[ctlr];
         * TS_SETCHR|TS_IE alone refuses to interrupt for me.
         */
        sc = &ts_softc[ctlr];
-       tsmap(sc, numuba, &a);
+       tsmap(sc, numuba);
        i = (int)&sc->sc_ubaddr->t_char;
        sc->sc_ts.t_cmd.c_loba = i;
        sc->sc_ts.t_cmd.c_hiba = (i >> 16) & 3;
        i = (int)&sc->sc_ubaddr->t_char;
        sc->sc_ts.t_cmd.c_loba = i;
        sc->sc_ts.t_cmd.c_hiba = (i >> 16) & 3;
@@ -155,12 +154,17 @@ tsprobe(reg, ctlr, um)
        sc->sc_ts.t_cmd.c_repcnt = 1;
        addr->tsdb = sc->sc_uba;
        DELAY(20000);
        sc->sc_ts.t_cmd.c_repcnt = 1;
        addr->tsdb = sc->sc_uba;
        DELAY(20000);
-       /* should have interrupted by now */
-
-       if (cvec == 0 || cvec == 0x200) /* no interrupt */
-               ubarelse(numuba, &a);
-
-       return (sizeof (struct tsdevice));
+       /*
+        * The controller should have interrupted by now, but some do not,
+        * even if the delays above are extended to many seconds.  If the
+        * vector is still unknown, we assume the drive is present at
+        * the usual vector.
+        */
+       if (cvec == 0 || cvec == 0x200) {
+               cvec = (int)reg & 7 ? 0260 : 0224;
+               br = 0x15;
+       }
+       return (sizeof(struct tsdevice));
 }
 
 /*
 }
 
 /*
@@ -168,15 +172,13 @@ tsprobe(reg, ctlr, um)
  * make them contiguous to keep overhead down.  This also sets
  * sc_uba (which then never changes).
  */
  * make them contiguous to keep overhead down.  This also sets
  * sc_uba (which then never changes).
  */
-tsmap(sc, uban, a)
+tsmap(sc, uban)
        register struct ts_softc *sc;
        register struct ts_softc *sc;
-       int uban, *a;
+       int uban;
 {
        register int i;
 
        i = uballoc(uban, (caddr_t)&sc->sc_ts, sizeof(sc->sc_ts), 0);
 {
        register int i;
 
        i = uballoc(uban, (caddr_t)&sc->sc_ts, sizeof(sc->sc_ts), 0);
-       if (a != NULL)
-               *a = i;
        i = UBAI_ADDR(i);
        sc->sc_ubaddr = (struct ts_tsdata *)i;
        /*
        i = UBAI_ADDR(i);
        sc->sc_ubaddr = (struct ts_tsdata *)i;
        /*
@@ -253,8 +255,7 @@ tsopen(dev, flag)
        sc->sc_lastiow = 0;
        sc->sc_blks = 0;
        sc->sc_softerrs = 0;
        sc->sc_lastiow = 0;
        sc->sc_blks = 0;
        sc->sc_softerrs = 0;
-       sc->sc_ctty = (caddr_t)(u.u_procp->p_flag&SCTTY ? 
-                       u.u_procp->p_session->s_ttyvp : 0);
+       sc->sc_tpr = tprintf_open();
        return (0);
 }
 
        return (0);
 }
 
@@ -288,6 +289,7 @@ tsclose(dev, flag)
        if (sc->sc_blks > 100 && sc->sc_softerrs > sc->sc_blks / 100)
                log(LOG_INFO, "ts%d: %d soft errors in %d blocks\n",
                    TSUNIT(dev), sc->sc_softerrs, sc->sc_blks);
        if (sc->sc_blks > 100 && sc->sc_softerrs > sc->sc_blks / 100)
                log(LOG_INFO, "ts%d: %d soft errors in %d blocks\n",
                    TSUNIT(dev), sc->sc_softerrs, sc->sc_blks);
+       tprintf_close(sc->sc_tpr);
        sc->sc_openf = 0;
        return (0);
 }
        sc->sc_openf = 0;
        return (0);
 }
@@ -669,29 +671,29 @@ tsintr(tsunit)
 
                case TS_REJECT:         /* function reject */
                        if (state == SIO && sc->sc_ts.t_sts.s_xs0 & TS_WLE)
 
                case TS_REJECT:         /* function reject */
                        if (state == SIO && sc->sc_ts.t_sts.s_xs0 & TS_WLE)
-                               tprintf(sc->sc_ctty, "ts%d: write locked\n",
+                               tprintf(sc->sc_tpr, "ts%d: write locked\n",
                                    tsunit);
                        if ((sc->sc_ts.t_sts.s_xs0 & TS_ONL) == 0)
                                    tsunit);
                        if ((sc->sc_ts.t_sts.s_xs0 & TS_ONL) == 0)
-                               tprintf(sc->sc_ctty, "ts%d: offline\n",
+                               tprintf(sc->sc_tpr, "ts%d: offline\n",
                                    tsunit);
                        break;
                }
                /*
                 * Couldn't recover error
                 */
                                    tsunit);
                        break;
                }
                /*
                 * Couldn't recover error
                 */
-               tprintf(sc->sc_ctty, "ts%d: hard error bn%d tssr=%b xs0=%b",
+               tprintf(sc->sc_tpr, "ts%d: hard error bn%d tssr=%b xs0=%b",
                    tsunit, bp->b_blkno, addr->tssr, TSSR_BITS,
                    sc->sc_ts.t_sts.s_xs0, TSXS0_BITS);
                if (sc->sc_ts.t_sts.s_xs1)
                    tsunit, bp->b_blkno, addr->tssr, TSSR_BITS,
                    sc->sc_ts.t_sts.s_xs0, TSXS0_BITS);
                if (sc->sc_ts.t_sts.s_xs1)
-                       tprintf(sc->sc_ctty, " xs1=%b", sc->sc_ts.t_sts.s_xs1,
+                       tprintf(sc->sc_tpr, " xs1=%b", sc->sc_ts.t_sts.s_xs1,
                            TSXS1_BITS);
                if (sc->sc_ts.t_sts.s_xs2)
                            TSXS1_BITS);
                if (sc->sc_ts.t_sts.s_xs2)
-                       tprintf(sc->sc_ctty, " xs2=%b", sc->sc_ts.t_sts.s_xs2,
+                       tprintf(sc->sc_tpr, " xs2=%b", sc->sc_ts.t_sts.s_xs2,
                            TSXS2_BITS);
                if (sc->sc_ts.t_sts.s_xs3)
                            TSXS2_BITS);
                if (sc->sc_ts.t_sts.s_xs3)
-                       tprintf(sc->sc_ctty, " xs3=%b", sc->sc_ts.t_sts.s_xs3,
+                       tprintf(sc->sc_tpr, " xs3=%b", sc->sc_ts.t_sts.s_xs3,
                            TSXS3_BITS);
                            TSXS3_BITS);
-               tprintf(sc->sc_ctty, "\n");
+               tprintf(sc->sc_tpr, "\n");
                bp->b_flags |= B_ERROR;
                goto opdone;
        }
                bp->b_flags |= B_ERROR;
                goto opdone;
        }
@@ -809,7 +811,7 @@ tsreset(uban)
                                break;
                        }
                }
                                break;
                        }
                }
-               tsmap(&ts_softc[ts11], uban, (int *)NULL);
+               tsmap(&ts_softc[ts11], uban);
                (void) tsinit(ts11);
                tsstart(um);
        }
                (void) tsinit(ts11);
                tsstart(um);
        }
@@ -824,7 +826,7 @@ tsioctl(dev, cmd, data, flag)
        register struct ts_softc *sc = &ts_softc[tsdinfo[tsunit]->ui_ctlr];
        register struct buf *bp = &ctsbuf[TSUNIT(dev)];
        register int callcount;
        register struct ts_softc *sc = &ts_softc[tsdinfo[tsunit]->ui_ctlr];
        register struct buf *bp = &ctsbuf[TSUNIT(dev)];
        register int callcount;
-       int fcount;
+       int fcount, error = 0;
        struct mtop *mtop;
        struct mtget *mtget;
        /* we depend of the values and order of the MT codes here */
        struct mtop *mtop;
        struct mtget *mtget;
        /* we depend of the values and order of the MT codes here */
@@ -867,7 +869,10 @@ tsioctl(dev, cmd, data, flag)
                            sc->sc_ts.t_sts.s_xs0&TS_BOT)
                                break;
                }
                            sc->sc_ts.t_sts.s_xs0&TS_BOT)
                                break;
                }
-               return (geterror(bp));
+               if (bp->b_flags&B_ERROR)
+                       if ((error = bp->b_error)==0)
+                               return (EIO);
+               return (error);
 
        case MTIOCGET:
                mtget = (struct mtget *)data;
 
        case MTIOCGET:
                mtget = (struct mtget *)data;