BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / vax / uba / tmscp.c
index ab4244f..93a67cd 100644 (file)
@@ -1,9 +1,41 @@
-/*     @(#)tmscp.c     7.2 (Berkeley) %G% */
-
-#ifndef lint
-static char    *sccsid = "@(#)tmscp.c  1.24    (ULTRIX)        1/21/86";
-#endif lint
+/*-
+ * Copyright (c) 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)tmscp.c     7.16 (Berkeley) 5/9/91
+ */
 
 
+/*
+ * sccsid = "@(#)tmscp.c       1.24    (ULTRIX)        1/21/86";
+ */
 
 /************************************************************************
  *                                                                     *
 
 /************************************************************************
  *                                                                     *
@@ -122,25 +154,24 @@ static    char    *sccsid = "@(#)tmscp.c  1.24    (ULTRIX)        1/21/86";
 #include "tms.h"
 #if NTMSCP > 0
 
 #include "tms.h"
 #if NTMSCP > 0
 
-#include "param.h"
-#include "systm.h"
-#include "buf.h"
-#include "conf.h"
-#include "dir.h"
-#include "user.h"
-#include "file.h"
-#include "map.h"
-#include "vm.h"
-#include "ioctl.h"
-#include "syslog.h"
-#include "mtio.h"
-#include "cmap.h"
-#include "uio.h"
-#include "tty.h"
-
-#include "../vax/pte.h"
-#include "../vax/cpu.h"
-#include "../vax/mtpr.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/syslog.h"
+#include "sys/mtio.h"
+#include "sys/cmap.h"
+#include "sys/uio.h"
+#include "sys/tprintf.h"
+
+#include "../include/pte.h"
+#include "../include/cpu.h"
+#include "../include/mtpr.h"
 #include "ubareg.h"
 #include "ubavar.h"
 
 #include "ubareg.h"
 #include "ubavar.h"
 
@@ -166,6 +197,7 @@ struct tmscp_softc {
        short   sc_credits;     /* transfer credits */
        short   sc_lastcmd;     /* pointer into command ring */
        short   sc_lastrsp;     /* pointer into response ring */
        short   sc_credits;     /* transfer credits */
        short   sc_lastcmd;     /* pointer into command ring */
        short   sc_lastrsp;     /* pointer into response ring */
+       short   sc_ipl;         /* interrupt priority (Q-bus) */
 } tmscp_softc[NTMSCP];
 
 struct tmscp {
 } tmscp_softc[NTMSCP];
 
 struct tmscp {
@@ -191,7 +223,7 @@ struct tms_info {
        short           tms_fmtmenu;    /* the unit's format (density) menu */
        short           tms_unitflgs;   /* unit flag parameters */
        short           tms_format;     /* the unit's current format (density) */
        short           tms_fmtmenu;    /* the unit's format (density) menu */
        short           tms_unitflgs;   /* unit flag parameters */
        short           tms_format;     /* the unit's current format (density) */
-       struct tty      *tms_ttyp;      /* record user's tty for errors */
+       tpr_t           tms_tpr;        /* tprintf handle */
 } tms_info[NTMS];
 struct uba_ctlr *tmscpminfo[NTMSCP];
 struct uba_device *tmsdinfo[NTMS];
 } tms_info[NTMS];
 struct uba_ctlr *tmscpminfo[NTMSCP];
 struct uba_device *tmsdinfo[NTMS];
@@ -199,7 +231,6 @@ struct uba_device *tmsdinfo[NTMS];
  * ifdef other tmscp devices here if they allow more than 1 unit/controller
  */
 struct uba_device *tmscpip[NTMSCP][1];
  * ifdef other tmscp devices here if they allow more than 1 unit/controller
  */
 struct uba_device *tmscpip[NTMSCP][1];
-struct buf rtmsbuf[NTMS];              /* raw i/o buffer */
 struct buf ctmscpbuf[NTMSCP];          /* internal cmd buffer (for ioctls) */
 struct buf tmsutab[NTMS];              /* Drive queue */
 struct buf tmscpwtab[NTMSCP];          /* I/O wait queue, per controller */
 struct buf ctmscpbuf[NTMSCP];          /* internal cmd buffer (for ioctls) */
 struct buf tmsutab[NTMS];              /* Drive queue */
 struct buf tmscpwtab[NTMSCP];          /* I/O wait queue, per controller */
@@ -275,6 +306,12 @@ struct  uba_driver tmscpdriver =
 
 #define DELAYTEN 1000
 
 
 #define DELAYTEN 1000
 
+/*
+ * Unfortunately qbgetpri can't be used because the TK50 doesn't flip the
+ * TMSCP_STEP2 flag in the tmscpsa register until after the pending interrupt
+ * has been acknowledged by the cpu. If you are at spl6(), the TMSCP_STEP2
+ * flag never gets set and you return (0).
+ */
 tmscpprobe(reg, ctlr)
        caddr_t reg;            /* address of the IP register */
        int ctlr;               /* index of controller in the tmscp_softc array */
 tmscpprobe(reg, ctlr)
        caddr_t reg;            /* address of the IP register */
        int ctlr;               /* index of controller in the tmscp_softc array */
@@ -324,6 +361,9 @@ tmscpprobe(reg, ctlr)
        if (count == DELAYTEN)
                return(0);
 
        if (count == DELAYTEN)
                return(0);
 
+#ifdef QBA
+       sc->sc_ipl = br = 0x15;
+#endif
        return(sizeof (struct tmscpdevice));
 }
 
        return(sizeof (struct tmscpdevice));
 }
 
@@ -453,6 +493,9 @@ tmscpintr (d)
        printd10("tmscpintr: state %d, tmscpsa %o\n", sc->sc_state, tmscpaddr->tmscpsa);
 #      endif   
 
        printd10("tmscpintr: state %d, tmscpsa %o\n", sc->sc_state, tmscpaddr->tmscpsa);
 #      endif   
 
+#ifdef QBA
+       splx(sc->sc_ipl);
+#endif
        /*
         * How the interrupt is handled depends on the state of the controller.
         */
        /*
         * How the interrupt is handled depends on the state of the controller.
         */
@@ -693,7 +736,7 @@ tmscpopen(dev, flag)
                return (EBUSY);
        sc = &tmscp_softc[ui->ui_ctlr];
        tms->tms_openf = 1;
                return (EBUSY);
        sc = &tmscp_softc[ui->ui_ctlr];
        tms->tms_openf = 1;
-       tms->tms_ttyp = u.u_ttyp;
+       tms->tms_tpr = tprintf_open();
        s = spl5();
        if (sc->sc_state != S_RUN)
                {
        s = spl5();
        if (sc->sc_state != S_RUN)
                {
@@ -824,7 +867,9 @@ tmscpclose(dev, flag)
 #                      endif
                        tmscpcommand(dev, TMS_CSE, 1);
                        }
 #                      endif
                        tmscpcommand(dev, TMS_CSE, 1);
                        }
+       tprintf_close(tms->tms_tpr);
        tms->tms_openf = 0;
        tms->tms_openf = 0;
+       return (0);
 }
 
 
 }
 
 
@@ -954,12 +999,7 @@ tmscpinit (d)
                 * space.
                 */
                sc->sc_ubainfo = uballoc(um->um_ubanum, (caddr_t)t, sizeof (struct tmscp), 0);
                 * space.
                 */
                sc->sc_ubainfo = uballoc(um->um_ubanum, (caddr_t)t, sizeof (struct tmscp), 0);
-#              ifdef MVAX
-               if (cpu == MVAX_I)
-                       sc->sc_tmscp = (struct tmscp *)(sc->sc_ubainfo & 0x3fffff);
-               else
-#              endif MVAX
-                       sc->sc_tmscp = (struct tmscp *)(sc->sc_ubainfo & 0x3ffff);
+               sc->sc_tmscp = (struct tmscp *)(UBAI_ADDR(sc->sc_ubainfo));
                sc->sc_mapped = 1;
                }
 
                sc->sc_mapped = 1;
                }
 
@@ -1035,7 +1075,7 @@ tmscpstart(um)
        tms = &tms_info[ui->ui_unit];
        if ((tmscpaddr->tmscpsa&TMSCP_ERR) || sc->sc_state != S_RUN)
                {
        tms = &tms_info[ui->ui_unit];
        if ((tmscpaddr->tmscpsa&TMSCP_ERR) || sc->sc_state != S_RUN)
                {
-               tprintf(tms->tms_ttyp,
+               tprintf(tms->tms_tpr,
                    "tms%d: hard error bn%d\n",
                    minor(bp->b_dev)&03, bp->b_blkno);
                log(TMS_PRI, "tmscp%d: sa 0%o, state %d\n",um->um_ctlr,
                    "tms%d: hard error bn%d\n",
                    minor(bp->b_dev)&03, bp->b_blkno);
                log(TMS_PRI, "tmscp%d: sa 0%o, state %d\n",um->um_ctlr,
@@ -1074,6 +1114,7 @@ tmscpstart(um)
                i = um->um_ubinfo|UBA_HAVEBDP|UBA_CANTWAIT;
                break;
        case VAX_730:
                i = um->um_ubinfo|UBA_HAVEBDP|UBA_CANTWAIT;
                break;
        case VAX_730:
+       case VAX_630:
                i = UBA_CANTWAIT;
                break;
        }   /* end switch (cpu) */
                i = UBA_CANTWAIT;
                break;
        }   /* end switch (cpu) */
@@ -1239,15 +1280,7 @@ tmscpstart(um)
                {
                mp->mscp_opcode = bp->b_flags&B_READ ? M_OP_READ : M_OP_WRITE;
                mp->mscp_bytecnt = bp->b_bcount;
                {
                mp->mscp_opcode = bp->b_flags&B_READ ? M_OP_READ : M_OP_WRITE;
                mp->mscp_bytecnt = bp->b_bcount;
-#              if MVAX
-               if (cpu == MVAX_I)
-                       {
-                       mp->mscp_buffer = (i & 0x3ffff) | TMSCP_MAP;
-                       mp->mscp_mapbase = (long)&(uba_hd[um->um_ubanum].uh_physuba->uba_map[0]);
-                       }
-               else
-#              endif MVAX
-                       mp->mscp_buffer = (i & 0x3ffff) | (((i>>28)&0xf)<<24);
+               mp->mscp_buffer = UBAI_ADDR(i) | (UBAI_BDP(i) << 24);
 
                bp->b_ubinfo = tempi;                   /* save mapping info */
                }
 
                bp->b_ubinfo = tempi;                   /* save mapping info */
                }
@@ -1413,11 +1446,11 @@ tmscprsp(um, tm, sc, i)
                else 
                        {
                        if (bp = dp->b_actf)
                else 
                        {
                        if (bp = dp->b_actf)
-                               tprintf(tms->tms_ttyp,
+                               tprintf(tms->tms_tpr,
                                    "tms%d: hard error bn%d: OFFLINE\n",
                                    minor(bp->b_dev)&03, bp->b_blkno);
                        else
                                    "tms%d: hard error bn%d: OFFLINE\n",
                                    minor(bp->b_dev)&03, bp->b_blkno);
                        else
-                               tprintf(tms->tms_ttyp,
+                               tprintf(tms->tms_tpr,
                                    "tms%d: hard error: OFFLINE\n",
                                    ui->ui_unit);
                        while (bp = dp->b_actf)
                                    "tms%d: hard error: OFFLINE\n",
                                    ui->ui_unit);
                        while (bp = dp->b_actf)
@@ -1549,7 +1582,7 @@ tmscprsp(um, tm, sc, i)
                                tms->tms_serex = 1;
                        if (st != M_ST_TAPEM)
                                {
                                tms->tms_serex = 1;
                        if (st != M_ST_TAPEM)
                                {
-                               tprintf(tms->tms_ttyp,
+                               tprintf(tms->tms_tpr,
                                    "tms%d: hard error bn%d\n",
                                    minor(bp->b_dev)&03, bp->b_blkno);
                                errinfo(st);            /* produces more info */
                                    "tms%d: hard error bn%d\n",
                                    minor(bp->b_dev)&03, bp->b_blkno);
                                errinfo(st);            /* produces more info */
@@ -1877,39 +1910,6 @@ tmscpcmd(op, tmscpp, tmscpaddr)
        return(1);
 }
 
        return(1);
 }
 
-
-/*
- * Perform raw read
- */
-
-tmscpread(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-       register int unit = TMSUNIT(dev);
-
-       if (unit >= NTMS)
-               return (ENXIO);
-       return (physio(tmscpstrategy, &rtmsbuf[unit], dev, B_READ, minphys, uio));
-}
-
-
-/*
- * Perform raw write
- */
-
-tmscpwrite(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-       register int unit = TMSUNIT(dev);
-
-       if (unit >= NTMS)
-               return (ENXIO);
-       return (physio(tmscpstrategy, &rtmsbuf[unit], dev, B_WRITE, minphys, uio));
-}
-
-
 /*
  * Catch ioctl commands, and call the "command" routine to do them.
  */
 /*
  * Catch ioctl commands, and call the "command" routine to do them.
  */
@@ -1926,6 +1926,7 @@ tmscpioctl(dev, cmd, data, flag)
        register struct uba_device *ui;
        register struct tms_info *tms;
        int fcount;             /* number of files (or records) to space */
        register struct uba_device *ui;
        register struct tms_info *tms;
        int fcount;             /* number of files (or records) to space */
+       int error = 0;
        register struct mtop *mtop;     /* mag tape cmd op to perform */
        register struct mtget *mtget;   /* mag tape struct to get info in */
 
        register struct mtop *mtop;     /* mag tape cmd op to perform */
        register struct mtget *mtget;   /* mag tape struct to get info in */
 
@@ -1968,7 +1969,10 @@ tmscpioctl(dev, cmd, data, flag)
                        if (bp->b_flags & B_ERROR)      /* like hitting BOT */
                                break;
                        }
                        if (bp->b_flags & B_ERROR)      /* like hitting BOT */
                                break;
                        }
-               return (geterror(bp));
+               if (bp->b_flags&B_ERROR)
+                       if ((error = bp->b_error)==0)
+                               return (EIO);
+               return (error);
 
        case MTIOCGET:
                /*
 
        case MTIOCGET:
                /*