BSD 4_4 release
[unix-history] / usr / src / sys / vax / uba / up.c
index bac23e8..a4a5f25 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.
  *
- *     @(#)up.c        7.1 (Berkeley) %G%
+ *     @(#)up.c        7.10 (Berkeley) 12/16/90
  */
 
 #include "up.h"
  */
 
 #include "up.h"
  * TODO:
  *     Check that offset recovery code works
  */
  * TODO:
  *     Check that offset recovery code works
  */
-#include "../machine/pte.h"
+#include "../include/pte.h"
 
 
-#include "param.h"
-#include "systm.h"
-#include "dk.h"
-#include "dkbad.h"
-#include "buf.h"
-#include "conf.h"
-#include "dir.h"
-#include "user.h"
-#include "map.h"
-#include "vm.h"
-#include "cmap.h"
-#include "uio.h"
-#include "kernel.h"
-#include "syslog.h"
-#include "../h/dkbad.h"
-#include "../vax/cpu.h"
+#include "sys/param.h"
+#include "sys/systm.h"
+#include "sys/dkstat.h"
+#include "sys/dkbad.h"
+#include "sys/ioctl.h"
+#include "sys/disklabel.h"
+#include "sys/buf.h"
+#include "sys/conf.h"
+#include "sys/user.h"
+#include "sys/map.h"
+#include "sys/vm.h"
+#include "sys/cmap.h"
+#include "sys/uio.h"
+#include "sys/kernel.h"
+#include "sys/syslog.h"
+
+#include "../include/cpu.h"
 #include "../vax/nexus.h"
 #include "ubavar.h"
 #include "ubareg.h"
 #include "../vax/nexus.h"
 #include "ubavar.h"
 #include "ubareg.h"
@@ -54,11 +55,7 @@ struct       size {
        daddr_t nblocks;
        int     cyloff;
 } up9300_sizes[8] = {
        daddr_t nblocks;
        int     cyloff;
 } up9300_sizes[8] = {
-#ifdef ERNIE
-       49324,  0,              /* A=cyl 0 thru 26 */
-#else
        15884,  0,              /* A=cyl 0 thru 26 */
        15884,  0,              /* A=cyl 0 thru 26 */
-#endif
        33440,  27,             /* B=cyl 27 thru 81 */
        495520, 0,              /* C=cyl 0 thru 814 */
        15884,  562,            /* D=cyl 562 thru 588 */
        33440,  27,             /* B=cyl 27 thru 81 */
        495520, 0,              /* C=cyl 0 thru 814 */
        15884,  562,            /* D=cyl 562 thru 588 */
@@ -125,7 +122,6 @@ struct      uba_driver scdriver =
     { upprobe, upslave, upattach, updgo, upstd, "up", updinfo, "sc", upminfo };
 struct buf     uputab[NUP];
 char upinit[NUP];
     { upprobe, upslave, upattach, updgo, upstd, "up", updinfo, "sc", upminfo };
 struct buf     uputab[NUP];
 char upinit[NUP];
-char upinit[NUP];
 
 struct upst {
        short   nsect;          /* # sectors/track */
 
 struct upst {
        short   nsect;          /* # sectors/track */
@@ -152,13 +148,8 @@ u_char     up_offset[16] = {
        0, 0, 0, 0
 };
 
        0, 0, 0, 0
 };
 
-struct buf     rupbuf[NUP];
-struct         buf     bupbuf[NUP];
-struct dkbad   upbad[NUP];
-#ifndef NOBADSECT
 struct         buf     bupbuf[NUP];
 struct dkbad   upbad[NUP];
 struct         buf     bupbuf[NUP];
 struct dkbad   upbad[NUP];
-#endif
 
 #define        b_cylin b_resid
 
 
 #define        b_cylin b_resid
 
@@ -190,7 +181,6 @@ upslave(ui, reg)
        upaddr->upcs1 = 0;              /* conservative */
        upaddr->upcs2 = ui->ui_slave;
        upaddr->upcs1 = UP_NOP|UP_GO;
        upaddr->upcs1 = 0;              /* conservative */
        upaddr->upcs2 = ui->ui_slave;
        upaddr->upcs1 = UP_NOP|UP_GO;
-       upaddr->upcs1 = UP_NOP|UP_GO;
        if (upaddr->upcs2&UPCS2_NED) {
                upaddr->upcs1 = UP_DCLR|UP_GO;
                return (0);
        if (upaddr->upcs2&UPCS2_NED) {
                upaddr->upcs1 = UP_DCLR|UP_GO;
                return (0);
@@ -207,7 +197,7 @@ upattach(ui)
                upwstart++;
        }
        if (ui->ui_dk >= 0)
                upwstart++;
        }
        if (ui->ui_dk >= 0)
-               dk_mspw[ui->ui_dk] = .0000020345;
+               dk_wpms[ui->ui_dk] = 491521;
        upip[ui->ui_ctlr][ui->ui_slave] = ui;
        up_softc[ui->ui_ctlr].sc_ndrive++;
        ui->ui_type = upmaptype(ui);
        upip[ui->ui_ctlr][ui->ui_slave] = ui;
        up_softc[ui->ui_ctlr].sc_ndrive++;
        ui->ui_type = upmaptype(ui);
@@ -229,7 +219,7 @@ upmaptype(ui)
                        break;
                }
        if (st->nsect == 0)
                        break;
                }
        if (st->nsect == 0)
-               printf("up%d: uphr=%x\n", ui->ui_slave, upaddr->uphr);
+               printf(": uphr=%x", upaddr->uphr);
        if (type == 0) {
                upaddr->uphr = UPHR_MAXCYL;
                if (upaddr->uphr == 822)
        if (type == 0) {
                upaddr->uphr = UPHR_MAXCYL;
                if (upaddr->uphr == 822)
@@ -361,12 +351,10 @@ upustart(ui)
         * setup the pack.
         */
        if ((upaddr->upds & UPDS_VV) == 0 || upinit[ui->ui_unit] == 0) {
         * setup the pack.
         */
        if ((upaddr->upds & UPDS_VV) == 0 || upinit[ui->ui_unit] == 0) {
-#ifndef NOBADSECT
                struct buf *bbp = &bupbuf[ui->ui_unit];
                struct buf *bbp = &bupbuf[ui->ui_unit];
-#endif
+
                /* SHOULD WARN SYSTEM THAT THIS HAPPENED */
                upinit[ui->ui_unit] = 1;
                /* SHOULD WARN SYSTEM THAT THIS HAPPENED */
                upinit[ui->ui_unit] = 1;
-               upinit[ui->ui_unit] = 1;
                upaddr->upcs1 = UP_IE|UP_DCLR|UP_GO;
                upaddr->upcs1 = UP_IE|UP_PRESET|UP_GO;
                upaddr->upof = UPOF_FMT22;
                upaddr->upcs1 = UP_IE|UP_DCLR|UP_GO;
                upaddr->upcs1 = UP_IE|UP_PRESET|UP_GO;
                upaddr->upof = UPOF_FMT22;
@@ -381,18 +369,6 @@ upustart(ui)
                dp->b_actf = bbp;
                bbp->av_forw = bp;
                bp = bbp;
                dp->b_actf = bbp;
                bbp->av_forw = bp;
                bp = bbp;
-#ifndef NOBADSECT
-               st = &upst[ui->ui_type];
-               bbp->b_flags = B_READ|B_BUSY;
-               bbp->b_dev = bp->b_dev;
-               bbp->b_bcount = 512;
-               bbp->b_un.b_addr = (caddr_t)&upbad[ui->ui_unit];
-               bbp->b_blkno = st->ncyl * st->nspc - st->nsect;
-               bbp->b_cylin = st->ncyl - 1;
-               dp->b_actf = bbp;
-               bbp->av_forw = bp;
-               bp = bbp;
-#endif
        }
        /*
         * If drive is offline, forget about positioning.
        }
        /*
         * If drive is offline, forget about positioning.
@@ -508,7 +484,6 @@ loop:
         */
        waitdry = 0;
        while ((upaddr->upds&UPDS_DRY) == 0) {
         */
        waitdry = 0;
        while ((upaddr->upds&UPDS_DRY) == 0) {
-               printf("up%d: ds wait ds=%o\n",dkunit(bp),upaddr->upds);
                printf("up%d: ds wait ds=%o\n",upunit(bp->b_dev),upaddr->upds);
                if (++waitdry > 512)
                        break;
                printf("up%d: ds wait ds=%o\n",upunit(bp->b_dev),upaddr->upds);
                if (++waitdry > 512)
                        break;
@@ -589,7 +564,6 @@ upintr(sc21)
                goto doattn;
        }
        um->um_tab.b_active = 1;
                goto doattn;
        }
        um->um_tab.b_active = 1;
-       um->um_tab.b_active = 1;
        /*
         * Get device and block structures, and a pointer
         * to the uba_device for the drive.  Select the drive.
        /*
         * Get device and block structures, and a pointer
         * to the uba_device for the drive.  Select the drive.
@@ -604,12 +578,6 @@ upintr(sc21)
                if (upecc(ui, CONT))
                        return;
        }
                if (upecc(ui, CONT))
                        return;
        }
-#ifndef NOBADSECT
-       if (bp->b_flags&B_BAD) {
-               if (upecc(ui, CONT))
-                       return;
-       }
-#endif
        /*
         * Check for and process errors on
         * either the drive or the controller.
        /*
         * Check for and process errors on
         * either the drive or the controller.
@@ -641,9 +609,9 @@ upintr(sc21)
                                        return;
                        }
        hard:
                                        return;
                        }
        hard:
-       hard:
-                       harderr(bp, "up");
-                       printf("cn=%d tn=%d sn=%d cs2=%b er1=%b er2=%b\n",
+                       diskerr(bp, "up", "hard error", LOG_PRINTF, -1,
+                           (struct disklabel *)0);
+                       printf(" cn=%d tn=%d sn=%d cs2=%b er1=%b er2=%b\n",
                                upaddr->updc, ((upaddr->upda)>>8)&077,
                                (upaddr->upda)&037,
                                upaddr->upcs2, UPCS2_BITS,
                                upaddr->updc, ((upaddr->upda)>>8)&077,
                                (upaddr->upda)&037,
                                upaddr->upcs2, UPCS2_BITS,
@@ -655,13 +623,6 @@ upintr(sc21)
                                return;
                        else
                                goto hard;
                                return;
                        else
                                goto hard;
-               } else if (upaddr->uper2 & UPER2_BSE) {
-#ifndef NOBADSECT
-                       if (upecc(ui, BSE))
-                               return;
-                       else
-#endif
-                               goto hard;
                } else {
                        /*
                         * Retriable error.
                } else {
                        /*
                         * Retriable error.
@@ -674,8 +635,6 @@ upintr(sc21)
                                        return;
                        } else
                                um->um_tab.b_active = 0; /* force retry */
                                        return;
                        } else
                                um->um_tab.b_active = 0; /* force retry */
-                       } else
-                               um->um_tab.b_active = 0; /* force retry */
                }
                /*
                 * Clear drive error and, every eight attempts,
                }
                /*
                 * Clear drive error and, every eight attempts,
@@ -782,28 +741,6 @@ doattn:
                upaddr->upcs1 = UP_IE;
 }
 
                upaddr->upcs1 = UP_IE;
 }
 
-upread(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-       register int unit = upunit(dev);
-
-       if (unit >= NUP)
-               return (ENXIO);
-       return (physio(upstrategy, &rupbuf[unit], dev, B_READ, minphys, uio));
-}
-
-upwrite(dev, uio)
-       dev_t dev;
-       struct uio *uio;
-{
-       register int unit = upunit(dev);
-
-       if (unit >= NUP)
-               return (ENXIO);
-       return (physio(upstrategy, &rupbuf[unit], dev, B_WRITE, minphys, uio));
-}
-
 /*
  * Correct an ECC error, and restart the i/o to complete
  * the transfer if necessary.  This is quite complicated because
 /*
  * Correct an ECC error, and restart the i/o to complete
  * the transfer if necessary.  This is quite complicated because
@@ -813,7 +750,6 @@ upwrite(dev, uio)
 upecc(ui, flag)
        register struct uba_device *ui;
        int flag;
 upecc(ui, flag)
        register struct uba_device *ui;
        int flag;
-       int flag;
 {
        register struct updevice *up = (struct updevice *)ui->ui_addr;
        register struct buf *bp = uputab[ui->ui_unit].b_actf;
 {
        register struct updevice *up = (struct updevice *)ui->ui_addr;
        register struct buf *bp = uputab[ui->ui_unit].b_actf;
@@ -831,20 +767,18 @@ upecc(ui, flag)
         * mapping (the first part of) the transfer.
         * O is offset within a memory page of the first byte transferred.
         */
         * mapping (the first part of) the transfer.
         * O is offset within a memory page of the first byte transferred.
         */
-#ifndef NOBADSECT
        if (flag == CONT)
                npf = bp->b_error;
        else
        if (flag == CONT)
                npf = bp->b_error;
        else
-#endif
-       npf = btop((up->upwc * sizeof(short)) + bp->b_bcount);
-       reg = btop(um->um_ubinfo&0x3ffff) + npf;
+               npf = btodb(bp->b_bcount + (up->upwc * sizeof(short)) + 511);
+       reg = btop(UBAI_ADDR(um->um_ubinfo)) + npf;
        o = (int)bp->b_un.b_addr & PGOFSET;
        mask = up->upec2;
 #ifdef UPECCDEBUG
        printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask,
            up->upec1);
 #endif
        o = (int)bp->b_un.b_addr & PGOFSET;
        mask = up->upec2;
 #ifdef UPECCDEBUG
        printf("npf %d reg %x o %d mask %o pos %d\n", npf, reg, o, mask,
            up->upec1);
 #endif
-       bn = dkblock(bp);
+       bn = bp->b_blkno;
        st = &upst[ui->ui_type];
        cn = bp->b_cylin;
        sn = bn%st->nspc + npf;
        st = &upst[ui->ui_type];
        cn = bp->b_cylin;
        sn = bn%st->nspc + npf;
@@ -862,8 +796,9 @@ upecc(ui, flag)
                npf--;
                reg--;
                mask = up->upec2;
                npf--;
                reg--;
                mask = up->upec2;
-               printf("up%d%c: soft ecc sn%d\n", dkunit(bp),
-                       'a'+(minor(bp->b_dev)&07), bp->b_blkno + npf);
+               diskerr(bp, "up", "soft ecc", LOG_WARNING, npf,
+                   (struct disklabel *)0);
+               addlog("\n");
                /*
                 * Flush the buffered data path, and compute the
                 * byte and bit position of the error.  The variable i
                /*
                 * Flush the buffered data path, and compute the
                 * byte and bit position of the error.  The variable i
@@ -880,9 +815,11 @@ upecc(ui, flag)
                 * Also watch out for end of this block and the end of the whole
                 * transfer.
                 */
                 * Also watch out for end of this block and the end of the whole
                 * transfer.
                 */
-               while (i < 512 && (int)ptob(npf)+i < bp->b_bcount && bit > -11) {
-                       addr = ptob(ubp->uba_map[reg+btop(byte)].pg_pfnum)+
-                               (byte & PGOFSET);
+               while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) {
+                       struct pte pte;
+
+                       pte = ubp->uba_map[reg + btop(byte)];
+                       addr = ptob(pte.pg_pfnum) + (byte & PGOFSET);
 #ifdef UPECCDEBUG
                        printf("addr %x map reg %x\n",
                                addr, *(int *)(&ubp->uba_map[reg+btop(byte)]));
 #ifdef UPECCDEBUG
                        printf("addr %x map reg %x\n",
                                addr, *(int *)(&ubp->uba_map[reg+btop(byte)]));
@@ -894,13 +831,13 @@ upecc(ui, flag)
 #endif
                        byte++;
                        i++;
 #endif
                        byte++;
                        i++;
+                       bit -= 8;
                }
                if (up->upwc == 0)
                        return (0);
                npf++;
                reg++;
                break;
                }
                if (up->upwc == 0)
                        return (0);
                npf++;
                reg++;
                break;
-#ifndef NOBADSECT
        case BSE:
                /*
                 * if not in bad sector table, return 0
        case BSE:
                /*
                 * if not in bad sector table, return 0
@@ -930,17 +867,15 @@ upecc(ui, flag)
                printf("upecc, CONT: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
 #endif
                bp->b_flags &= ~B_BAD;
                printf("upecc, CONT: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
 #endif
                bp->b_flags &= ~B_BAD;
-               up->upwc = -((bp->b_bcount - (int)ptob(npf)) / sizeof(short));
-               if (up->upwc == 0)
-                       return(0);
+               if ((int)dbtob(npf) >= bp->b_bcount)
+                       return (0);
+               up->upwc = -((bp->b_bcount - (int)dbtob(npf)) / sizeof(short));
                break;
                break;
-#endif
        }
        if (up->upwc == 0) {
                um->um_tab.b_active = 0;
                return (0);
        }
        }
        if (up->upwc == 0) {
                um->um_tab.b_active = 0;
                return (0);
        }
-       }
        /*
         * Have to continue the transfer... clear the drive,
         * and compute the position where the transfer is to continue.
        /*
         * Have to continue the transfer... clear the drive,
         * and compute the position where the transfer is to continue.
@@ -1052,7 +987,6 @@ updump(dev)
        register short *rp;
        struct upst *st;
        register int retry;
        register short *rp;
        struct upst *st;
        register int retry;
-       register int retry;
 
        unit = upunit(dev);
        if (unit >= NUP)
 
        unit = upunit(dev);
        if (unit >= NUP)
@@ -1081,7 +1015,6 @@ updump(dev)
                return (EFAULT);
        start = 0;
        st = &upst[ui->ui_type];
                return (EFAULT);
        start = 0;
        st = &upst[ui->ui_type];
-       start = 0;
        sizes = phys(struct size *, st->sizes);
        if (dumplo < 0)
                return (EINVAL);
        sizes = phys(struct size *, st->sizes);
        if (dumplo < 0)
                return (EINVAL);
@@ -1110,13 +1043,10 @@ updump(dev)
                *--rp = -blk*NBPG / sizeof (short);
                *--rp = UP_GO|UP_WCOM;
                retry = 0;
                *--rp = -blk*NBPG / sizeof (short);
                *--rp = UP_GO|UP_WCOM;
                retry = 0;
-               retry = 0;
                do {
                        DELAY(25);
                        if (++retry > 527)
                                break;
                do {
                        DELAY(25);
                        if (++retry > 527)
                                break;
-                       if (++retry > 527)
-                               break;
                } while ((upaddr->upcs1 & UP_RDY) == 0);
                if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
                        printf("up%d: not ready", unit);
                } while ((upaddr->upcs1 & UP_RDY) == 0);
                if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
                        printf("up%d: not ready", unit);
@@ -1126,14 +1056,6 @@ updump(dev)
                        }
                        printf(" (flakey)\n");
                }
                        }
                        printf(" (flakey)\n");
                }
-               if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
-                       printf("up%d: not ready", unit);
-                       if ((upaddr->upds & UPDS_DREADY) != UPDS_DREADY) {
-                               printf("\n");
-                               return (EIO);
-                       }
-                       printf(" (flakey)\n");
-               }
                if (upaddr->upds&UPDS_ERR)
                        return (EIO);
                start += blk*NBPG;
                if (upaddr->upds&UPDS_ERR)
                        return (EIO);
                start += blk*NBPG;