cleanup for reasonable controllers
[unix-history] / usr / src / sys / vax / mba / hp.c
index bcbd5c4..516f5c9 100644 (file)
@@ -1,7 +1,9 @@
-/*     hp.c    3.    %G%     */
+/*     hp.c    3.19    %G%     */
 
 
+#include "../conf/hp.h"
+#if NHP > 0
 /*
 /*
- * RP06/RM03 disk driver
+ * RP06/RM03/RM05 disk driver
  */
 
 #include "../h/param.h"
  */
 
 #include "../h/param.h"
@@ -17,9 +19,6 @@
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
-#define        DK_N    0
-#define        DK_NMAX 1
-
 struct device
 {
        int     hpcs1;          /* control and Status register 1 */
 struct device
 {
        int     hpcs1;          /* control and Status register 1 */
@@ -40,19 +39,16 @@ struct      device
        int     hpec2;          /* Burst error bit pattern */
 };
 
        int     hpec2;          /* Burst error bit pattern */
 };
 
-#define        HPMBA           MBA0
-#define        HPMBANUM        0
-
-#define        NHP     2
 #define        RP      022
 #define        RM      024
 #define        RP      022
 #define        RM      024
+#define        RM5     027
 #define        NSECT   22
 #define        NTRAC   19
 #define        NRMSECT 32
 #define        NRMTRAC 5
 
 #define        NSECT   22
 #define        NTRAC   19
 #define        NRMSECT 32
 #define        NRMTRAC 5
 
-#define        _hpSDIST        3
-#define        _hpRDIST        6
+#define        _hpSDIST        2
+#define        _hpRDIST        3
 
 int    hpSDIST = _hpSDIST;
 int    hpRDIST = _hpRDIST;
 
 int    hpSDIST = _hpSDIST;
 int    hpRDIST = _hpRDIST;
@@ -64,31 +60,32 @@ struct      size
        int     cyloff;
 } hp_sizes[8] =
 {
        int     cyloff;
 } hp_sizes[8] =
 {
-       15884,  0,              /* cyl 0 thru 37 */
-       33440,  38,             /* cyl 38 thru 117 */
-       8360,   98,             /* cyl 98 thru 117 */
-#ifdef ERNIE
-       15884,  118,            /* cyl 118 thru 155 */
-       66880,  156,            /* cyl 156 thru 315 */
-       0,      0,
-       291346, 118,            /* cyl 118 thru 814, (like distrib) */
-       208582, 316,            /* cyl 316 thru 814 */
-#else
+       15884,  0,              /* A=cyl 0 thru 37 */
+       33440,  38,             /* B=cyl 38 thru 117 */
+       340670, 0,              /* C=cyl 0 thru 814 */
        0,      0,
        0,      0,
        0,      0,
        0,      0,
        0,      0,
        0,      0,
-       291346, 118,            /* cyl 118 thru 814 */
+       291346, 118,            /* G=cyl 118 thru 814 */
        0,      0,
        0,      0,
-#endif
 }, rm_sizes[8] = {
 }, rm_sizes[8] = {
-       15884,  0,              /* cyl 0 thru 99 */
-       33440,  100,            /* cyl 100 thru 309 */
-       0,      0,
+       15884,  0,              /* A=cyl 0 thru 99 */
+       33440,  100,            /* B=cyl 100 thru 309 */
+       131680, 0,              /* C=cyl 0 thru 822 */
        0,      0,
        0,      0,
        0,      0,
        0,      0,
        0,      0,
        0,      0,
-       82080,  310,            /* cyl 310 thru 822 */
+       82080,  310,            /* G=cyl 310 thru 822 */
        0,      0,
        0,      0,
+}, rm5_sizes[8] = {
+       15884,  0,              /* A=cyl 0 thru 26 */
+       33440,  27,             /* B=cyl 27 thru 81 */
+       500992, 0,              /* C=cyl 0 thru 823 */
+       15884,  562,            /* D=cyl 562 thru 588 */
+       55936,  589,            /* E=cyl 589 thru 680 */
+       86944,  681,            /* F=cyl 681 thru 823 */
+       159296, 562,            /* G=cyl 562 thru 823 */
+       291346, 82,             /* H=cyl 82 thru 561 */
 };
 
 #define        P400    020
 };
 
 #define        P400    020
@@ -156,17 +153,38 @@ register struct buf *bp;
        unit = dkunit(bp);
        if (hp_type[unit] == 0) {
                struct device *hpaddr;
        unit = dkunit(bp);
        if (hp_type[unit] == 0) {
                struct device *hpaddr;
+               double mspw;
 
                /* determine device type */
                hpaddr = mbadev(HPMBA, unit);
 
                /* determine device type */
                hpaddr = mbadev(HPMBA, unit);
-               hp_type[unit] = hpaddr->hpdt;
+
+               /* record transfer rate (these are guesstimates secs/word) */
+               switch (hp_type[unit] = hpaddr->hpdt) {
+               case RM:        mspw = .0000019728; break;
+               case RM5:       mspw = .0000020345; break;
+               case RP:        mspw = .0000029592; break;
+               }
+               if (DK_N + unit <= DK_NMAX)
+                       dk_mspw[DK_N+unit] = mspw;
        }
        }
-       if (hp_type[unit] == RM) {
+       switch (hp_type[unit]) {
+
+       case RM:
                sizes = rm_sizes;
                nspc = NRMSECT*NRMTRAC;
                sizes = rm_sizes;
                nspc = NRMSECT*NRMTRAC;
-       } else {
+               break;
+       case RM5:
+               sizes = rm5_sizes;
+               nspc = NRMSECT*NTRAC;
+               break;
+       case RP:
                sizes = hp_sizes;
                nspc = NSECT*NTRAC;
                sizes = hp_sizes;
                nspc = NSECT*NTRAC;
+               break;
+       default:
+               printf("hp: unknown device type 0%o\n", hp_type[unit]);
+               u.u_error = ENXIO;
+               unit = NHP+1;   /* force error */
        }
        if (unit >= NHP ||
            bp->b_blkno < 0 ||
        }
        if (unit >= NHP ||
            bp->b_blkno < 0 ||
@@ -195,7 +213,7 @@ register unit;
        daddr_t bn;
        int sn, cn, csn;
 
        daddr_t bn;
        int sn, cn, csn;
 
-       ((struct mba_regs *)MBA0)->mba_cr |= MBAIE;
+       ((struct mba_regs *)HPMBA)->mba_cr |= MBAIE;
        hpaddr = mbadev(HPMBA, 0);
        hpaddr->hpas = 1<<unit;
 
        hpaddr = mbadev(HPMBA, 0);
        hpaddr->hpas = 1<<unit;
 
@@ -219,12 +237,22 @@ register unit;
 
        bn = dkblock(bp);
        cn = bp->b_cylin;
 
        bn = dkblock(bp);
        cn = bp->b_cylin;
-       if(hp_type[unit] == RM) {
+       switch (hp_type[unit]) {
+
+       case RM:
                sn = bn%(NRMSECT*NRMTRAC);
                sn = (sn+NRMSECT-hpSDIST)%NRMSECT;
                sn = bn%(NRMSECT*NRMTRAC);
                sn = (sn+NRMSECT-hpSDIST)%NRMSECT;
-       } else {
+               break;
+       case RM5:
+               sn = bn%(NRMSECT*NTRAC);
+               sn = (sn+NRMSECT-hpSDIST)%NRMSECT;
+               break;
+       case RP:
                sn = bn%(NSECT*NTRAC);
                sn = (sn+NSECT-hpSDIST)%NSECT;
                sn = bn%(NSECT*NTRAC);
                sn = (sn+NSECT-hpSDIST)%NSECT;
+               break;
+       default:
+               panic("hpustart");
        }
 
        if(cn - (hpaddr->hpdc & 0xffff))
        }
 
        if(cn - (hpaddr->hpdc & 0xffff))
@@ -246,9 +274,9 @@ search:
                hpaddr->hpcs1 = SEARCH|GO;
        }
        unit += DK_N;
                hpaddr->hpcs1 = SEARCH|GO;
        }
        unit += DK_N;
-       if (unit <= DK_NMAX && DK_N+NHP <= DK_NMAX) {
+       if (unit <= DK_NMAX) {
                dk_busy |= 1<<unit;
                dk_busy |= 1<<unit;
-               dk_numb[unit]++;
+               dk_seek[unit]++;
        }
        return;
 
        }
        return;
 
@@ -280,14 +308,24 @@ loop:
        unit = minor(bp->b_dev) & 077;
        dn = dkunit(bp);
        bn = dkblock(bp);
        unit = minor(bp->b_dev) & 077;
        dn = dkunit(bp);
        bn = dkblock(bp);
-       if (hp_type[dn] == RM) {
+       switch (hp_type[dn]) {
+       case RM:
                nspc = NRMSECT*NRMTRAC;
                ns = NRMSECT;
                cn = rm_sizes[unit&07].cyloff;
                nspc = NRMSECT*NRMTRAC;
                ns = NRMSECT;
                cn = rm_sizes[unit&07].cyloff;
-       } else {
+               break;
+       case RM5:
+               nspc = NRMSECT*NTRAC;
+               ns = NRMSECT;
+               cn = rm5_sizes[unit&07].cyloff;
+               break;
+       case RP:
                nspc = NSECT*NTRAC;
                ns = NSECT;
                cn = hp_sizes[unit&07].cyloff;
                nspc = NSECT*NTRAC;
                ns = NSECT;
                cn = hp_sizes[unit&07].cyloff;
+               break;
+       default:
+               panic("hpstart");
        }
        cn += bn/nspc;
        sn = bn%nspc;
        }
        cn += bn/nspc;
        sn = bn%nspc;
@@ -303,7 +341,7 @@ loop:
                iodone(bp);
                goto loop;
        }
                iodone(bp);
                goto loop;
        }
-       if(hptab.b_errcnt >= 16) {
+       if(hptab.b_errcnt >= 16 && (bp->b_flags&B_WRITE) == 0) {
                hpaddr->hpof = hp_offset[hptab.b_errcnt & 017] | FMT22;
                HPMBA->mba_cr &= ~MBAIE;
                hpaddr->hpcs1 = OFFSET|GO;
                hpaddr->hpof = hp_offset[hptab.b_errcnt & 017] | FMT22;
                HPMBA->mba_cr &= ~MBAIE;
                hpaddr->hpcs1 = OFFSET|GO;
@@ -316,11 +354,9 @@ loop:
        mbastart(bp, (int *)hpaddr);
 
        unit = dn+DK_N;
        mbastart(bp, (int *)hpaddr);
 
        unit = dn+DK_N;
-       if (NHP+DK_N == DK_NMAX)
-               unit = NHP+DK_N;
        if (unit <= DK_NMAX) {
                dk_busy |= 1<<unit;
        if (unit <= DK_NMAX) {
                dk_busy |= 1<<unit;
-               dk_numb[unit]++;
+               dk_xfer[unit]++;
                dk_wds[unit] += bp->b_bcount>>6;
        }
 }
                dk_wds[unit] += bp->b_bcount>>6;
        }
 }
@@ -335,9 +371,7 @@ hpintr(mbastat, as)
                dp = hptab.b_actf;
                bp = dp->b_actf;
                unit = dkunit(bp);
                dp = hptab.b_actf;
                bp = dp->b_actf;
                unit = dkunit(bp);
-               if (DK_N+NHP == DK_NMAX)
-                       dk_busy &= ~(1<<(DK_N+NHP));
-               else if (DK_N+unit <= DK_NMAX)
+               if (DK_N+unit <= DK_NMAX)
                        dk_busy &= ~(1<<(DK_N+unit));
                hpaddr = mbadev(HPMBA, unit);
                if (hpaddr->hpds & ERR || mbastat & MBAEBITS) {
                        dk_busy &= ~(1<<(DK_N+unit));
                hpaddr = mbadev(HPMBA, unit);
                if (hpaddr->hpds & ERR || mbastat & MBAEBITS) {
@@ -415,6 +449,7 @@ register struct buf *bp;
        int dn, bn, cn, tn, sn, ns, nt;
        extern char buffers[NBUF][BSIZE];
        struct pte mpte;
        int dn, bn, cn, tn, sn, ns, nt;
        extern char buffers[NBUF][BSIZE];
        struct pte mpte;
+       int bcr;
 
        /*
         * Npf is the number of sectors transferred before the sector
 
        /*
         * Npf is the number of sectors transferred before the sector
@@ -422,11 +457,11 @@ register struct buf *bp;
         * 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.
         */
-       npf = btop((mbp->mba_bcr&0xffff) + bp->b_bcount) - 1;
-       if (bp->b_flags&B_PHYS)
-               reg = 128 + npf;
-       else
-               reg = btop(bp->b_un.b_addr - buffers[0]) + npf;
+       bcr = mbp->mba_bcr & 0xffff;
+       if (bcr)
+               bcr |= 0xffff0000;              /* sxt */
+       npf = btop(bcr + bp->b_bcount) - 1;
+       reg = npf;
        o = (int)bp->b_un.b_addr & PGOFSET;
        printf("%D ", bp->b_blkno + npf);
        prdev("ECC", bp->b_dev);
        o = (int)bp->b_un.b_addr & PGOFSET;
        printf("%D ", bp->b_blkno + npf);
        prdev("ECC", bp->b_dev);
@@ -443,7 +478,7 @@ register struct buf *bp;
         * in main memory.
         */
        i = (rp->hpec1&0xffff) - 1;             /* -1 makes 0 origin */
         * in main memory.
         */
        i = (rp->hpec1&0xffff) - 1;             /* -1 makes 0 origin */
-       bit = i&017;
+       bit = i&07;
        i = (i&~07)>>3;
        byte = i + o;
        /*
        i = (i&~07)>>3;
        byte = i + o;
        /*
@@ -461,7 +496,7 @@ register struct buf *bp;
                bit -= 8;
        }
        hptab.b_active++;               /* Either complete or continuing */
                bit -= 8;
        }
        hptab.b_active++;               /* Either complete or continuing */
-       if (mbp->mba_bcr == 0)
+       if (bcr == 0)
                return (0);
        /*
         * Have to continue the transfer... clear the drive,
                return (0);
        /*
         * Have to continue the transfer... clear the drive,
@@ -472,12 +507,16 @@ register struct buf *bp;
        rp->hpcs1 = DCLR|GO;
        dn = dkunit(bp);
        bn = dkblock(bp);
        rp->hpcs1 = DCLR|GO;
        dn = dkunit(bp);
        bn = dkblock(bp);
-       if (hp_type[dn] == RM) {
-               ns = NRMSECT;
-               nt = NRMTRAC;
-       } else {
-               ns = NSECT;
-               nt = NTRAC;
+       switch (hp_type[dn]) {
+
+       case RM:
+               ns = NRMSECT; nt = NRMTRAC; break;
+       case RM5:
+               ns = NRMSECT; nt = NTRAC; break;
+       case RP:
+               ns = NSECT; nt = NTRAC; break;
+       default:
+               panic("hpecc");
        }
        cn = bp->b_cylin;
        sn = bn%(ns*nt) + npf + 1;
        }
        cn = bp->b_cylin;
        sn = bn%(ns*nt) + npf + 1;
@@ -492,3 +531,4 @@ register struct buf *bp;
        rp->hpcs1 = RCOM|GO;
        return (1);
 }
        rp->hpcs1 = RCOM|GO;
        return (1);
 }
+#endif