first working vorsion
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 9 Feb 1981 10:32:31 +0000 (02:32 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Mon, 9 Feb 1981 10:32:31 +0000 (02:32 -0800)
SCCS-vsn: sys/vax/mba/mba.c 4.4
SCCS-vsn: sys/vax/mba/hp.c 4.7

usr/src/sys/vax/mba/hp.c
usr/src/sys/vax/mba/mba.c

index 6f6dcbd..bde97e3 100644 (file)
@@ -1,9 +1,9 @@
-/*     hp.c    4.6     %G%     */
+/*     hp.c    4.7     81/02/08        */
 
 #include "hp.h"
 #if NHP > 0
 /*
 
 #include "hp.h"
 #if NHP > 0
 /*
- * RP06/RM03/RM05 disk driver
+ * RP/RM disk driver
  */
 
 #include "../h/param.h"
  */
 
 #include "../h/param.h"
 #include "../h/vm.h"
 #include "../h/cmap.h"
 
 #include "../h/vm.h"
 #include "../h/cmap.h"
 
-struct device
-{
-       int     hpcs1;          /* control and Status register 1 */
-       int     hpds;           /* Drive Status */
-       int     hper1;          /* Error register 1 */
-       int     hpmr;           /* Maintenance */ 
-       int     hpas;           /* Attention Summary */
-       int     hpda;           /* Desired address register */
-       int     hpdt;           /* Drive type */
-       int     hpla;           /* Look ahead */
-       int     hpsn;           /* serial number */
-       int     hpof;           /* Offset register */
-       int     hpdc;           /* Desired Cylinder address register */
-       int     hpcc;           /* Current Cylinder */
-       int     hper2;          /* Error register 2 */
-       int     hper3;          /* Error register 3 */
-       int     hpec1;          /* Burst error bit position */
-       int     hpec2;          /* Burst error bit pattern */
-};
-
-#define        RP      022
-#define        RM      024
-#define        RM5     027
-#define        NSECT   22
-#define        NTRAC   19
-#define        NRMSECT 32
-#define        NRMTRAC 5
-
-#define        _hpSDIST        2
-#define        _hpRDIST        3
-
-int    hpSDIST = _hpSDIST;
-int    hpRDIST = _hpRDIST;
-int    hpseek;
+#include "../h/hpreg.h"
 
 
-struct size
-{
+/* THIS SHOULD BE READ OFF THE PACK, PER DRIVE */
+struct size {
        daddr_t nblocks;
        int     cyloff;
        daddr_t nblocks;
        int     cyloff;
-} hp_sizes[8] =
-{
+} hp_sizes[8] = {
        15884,  0,              /* A=cyl 0 thru 37 */
        33440,  38,             /* B=cyl 38 thru 117 */
        340670, 0,              /* C=cyl 0 thru 814 */
        15884,  0,              /* A=cyl 0 thru 37 */
        33440,  38,             /* B=cyl 38 thru 117 */
        340670, 0,              /* C=cyl 0 thru 814 */
@@ -87,50 +53,52 @@ struct      size
        86944,  681,            /* F=cyl 681 thru 823 */
        159296, 562,            /* G=cyl 562 thru 823 */
        291346, 82,             /* H=cyl 82 thru 561 */
        86944,  681,            /* F=cyl 681 thru 823 */
        159296, 562,            /* G=cyl 562 thru 823 */
        291346, 82,             /* H=cyl 82 thru 561 */
+}, rm80_sizes[8] = {
+       15884,  0,              /* A=cyl 0 thru 36 */
+       33440,  37,             /* B=cyl 37 thru 114 */
+       242606, 0,              /* C=cyl 0 thru 558 */
+       0,      0,
+       0,      0,
+       0,      0,
+       82080,  115,            /* G=cyl 115 thru 304 */
+       110236, 305,            /* H=cyl 305 thru 558 */
 };
 };
+/* END OF STUFF WHICH SHOULD BE READ IN PER DISK */
 
 
-#define        P400    020
-#define        M400    0220
-#define        P800    040
-#define        M800    0240
-#define        P1200   060
-#define        M1200   0260
-int    hp_offset[16] =
-{
+#define        _hpSDIST        2
+#define        _hpRDIST        3
+
+int    hpSDIST = _hpSDIST;
+int    hpRDIST = _hpRDIST;
+
+short  hptypes[] =
+       { MBDT_RM03, MBDT_RM05, MBDT_RP06, MBDT_RM80, 0 };
+struct mba_info *hpinfo[NHP];
+int    hpdkinit(),hpustart(),hpstart(),hpdtint();
+struct mba_driver hpdriver =
+       { hpdkinit, hpustart, hpstart, hpdtint, 0, hptypes, hpinfo };
+
+struct hpst {
+       short   nsect;
+       short   ntrak;
+       short   nspc;
+       short   ncyl;
+       struct  size *sizes;
+} hpst[] = {
+       32,     5,      32*5,   823,    rm_sizes,       /* RM03 */
+       32,     19,     32*19,  823,    rm5_sizes,      /* RM05 */
+       22,     19,     22*19,  815,    hp_sizes,       /* RP06 */
+       31,     14,     31*14,  559,    rm80_sizes      /* RM80 */
+};
+
+int    hp_offset[16] = {
        P400, M400, P400, M400,
        P800, M800, P800, M800,
        P1200, M1200, P1200, M1200,
        0, 0, 0, 0,
 };
 
        P400, M400, P400, M400,
        P800, M800, P800, M800,
        P1200, M1200, P1200, M1200,
        0, 0, 0, 0,
 };
 
-struct buf     hptab;
 struct buf     rhpbuf;
 struct buf     rhpbuf;
-struct buf     hputab[NHP];
-char   hp_type[NHP];   /* drive type */
-
-#define        GO      01
-#define        PRESET  020
-#define        RTC     016
-#define        OFFSET  014
-#define        SEEK    04
-#define        SEARCH  030
-#define        RECAL   06
-#define        DCLR    010
-#define        WCOM    060
-#define        RCOM    070
-
-#define        IE      0100
-#define        PIP     020000
-#define        DRY     0200
-#define        ERR     040000
-#define        TRE     040000
-#define        DCK     0100000
-#define        WLE     04000
-#define        ECH     0100
-#define        VV      0100
-#define        DPR     0400
-#define        MOL     010000
-#define        FMT22   010000
 
 #define        b_cylin b_resid
  
 
 #define        b_cylin b_resid
  
@@ -139,298 +107,145 @@ daddr_t dkblock();
 #endif
  
 hpstrategy(bp)
 #endif
  
 hpstrategy(bp)
-register struct buf *bp;
+       register struct buf *bp;
 {
 {
-       register struct buf *dp;
-       register unit, xunit, nspc;
+       register struct mba_info *mi;
+       register struct hpst *st;
+       register int unit;
        long sz, bn;
        long sz, bn;
-       struct size *sizes;
+       int xunit = minor(bp->b_dev) & 07;
 
 
-       if ((mbaact&(1<<HPMBANUM)) == 0)
-               mbainit(HPMBANUM);
-       xunit = minor(bp->b_dev) & 077;
        sz = bp->b_bcount;
        sz = (sz+511) >> 9;
        unit = dkunit(bp);
        sz = bp->b_bcount;
        sz = (sz+511) >> 9;
        unit = dkunit(bp);
-       if (hp_type[unit] == 0) {
-               struct device *hpaddr;
-               double mspw;
-
-               /* determine device type */
-               hpaddr = mbadev(HPMBA, unit);
-
-               /* 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 (HPDK_N + unit <= HPDK_NMAX)
-                       dk_mspw[HPDK_N+unit] = mspw;
-       }
-       switch (hp_type[unit]) {
-
-       case RM:
-               sizes = rm_sizes;
-               nspc = NRMSECT*NRMTRAC;
-               break;
-       case RM5:
-               sizes = rm5_sizes;
-               nspc = NRMSECT*NTRAC;
-               break;
-       case RP:
-               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 ||
-           (bn = dkblock(bp))+sz > sizes[xunit&07].nblocks) {
-               bp->b_flags |= B_ERROR;
-               iodone(bp);
-               return;
-       }
-       bp->b_cylin = bn/nspc + sizes[xunit&07].cyloff;
-       dp = &hputab[unit];
+       if (unit >= NHP)
+               goto bad;
+       mi = hpinfo[unit];
+       if (mi->mi_alive == 0)
+               goto bad;
+       st = &hpst[mi->mi_type];
+       if (bp->b_blkno < 0 ||
+           (bn = dkblock(bp))+sz > st->sizes[xunit].nblocks)
+               goto bad;
+       bp->b_cylin = bn/st->nspc + st->sizes[xunit].cyloff;
        (void) spl5();
        (void) spl5();
-       disksort(dp, bp);
-       if (dp->b_active == 0) {
-               hpustart(unit);
-               if(hptab.b_active == 0)
-                       hpstart();
-       }
+       disksort(&mi->mi_tab, bp);
+       if (mi->mi_tab.b_active == 0)
+               mbustart(mi);
        (void) spl0();
        (void) spl0();
+       return;
+
+bad:
+       bp->b_flags |= B_ERROR;
+       iodone(bp);
+       return;
 }
 
 }
 
-hpustart(unit)
-register unit;
+hpustart(mi)
+       register struct mba_info *mi;
 {
 {
-       register struct buf *bp, *dp;
-       register struct device *hpaddr;
+       register struct device *hpaddr = (struct device *)mi->mi_drv;
+       register struct buf *bp = mi->mi_tab.b_actf;
+       register struct hpst *st;
        daddr_t bn;
        daddr_t bn;
-       int sn, cn, csn, ns;
+       int sn, dist, flags;
 
 
-       ((struct mba_regs *)HPMBA)->mba_cr |= MBAIE;
-       hpaddr = mbadev(HPMBA, 0);
-       hpaddr->hpas = 1<<unit;
-
-       if(unit >= NHP)
-               return;
-       if (unit+HPDK_N <= HPDK_NMAX)
-               dk_busy &= ~(1<<(unit+HPDK_N));
-       dp = &hputab[unit];
-       if((bp=dp->b_actf) == NULL)
-               return;
-       hpaddr = mbadev(HPMBA, unit);
-       if((hpaddr->hpds & VV) == 0) {
+       if ((hpaddr->hpcs1&DVA) == 0)
+               return (MBU_BUSY);
+       if ((hpaddr->hpds & VV) == 0) {
                hpaddr->hpcs1 = DCLR|GO;
                hpaddr->hpcs1 = PRESET|GO;
                hpaddr->hpof = FMT22;
        }
                hpaddr->hpcs1 = DCLR|GO;
                hpaddr->hpcs1 = PRESET|GO;
                hpaddr->hpof = FMT22;
        }
-       if(dp->b_active)
-               goto done;
-       dp->b_active++;
+       if (mi->mi_tab.b_active)
+               return (MBU_DODATA);
        if ((hpaddr->hpds & (DPR|MOL)) != (DPR|MOL))
        if ((hpaddr->hpds & (DPR|MOL)) != (DPR|MOL))
-               goto done;
-
-#if NHP > 1
-       bn = dkblock(bp);
-       cn = bp->b_cylin;
-       switch (hp_type[unit]) {
-
-       case RM:
-               sn = bn%(NRMSECT*NRMTRAC);
-               sn = (sn+NRMSECT-hpSDIST)%NRMSECT;
-               ns = NRMSECT;
-               break;
-       case RM5:
-               sn = bn%(NRMSECT*NTRAC);
-               sn = (sn+NRMSECT-hpSDIST)%NRMSECT;
-               ns = NRMSECT;
-               break;
-       case RP:
-               sn = bn%(NSECT*NTRAC);
-               sn = (sn+NSECT-hpSDIST)%NSECT;
-               ns = NSECT;
-               break;
-       default:
-               panic("hpustart");
+               return (MBU_DODATA);
+       hpaddr->hpdc = bp->b_cylin;
+       flags = mi->mi_hd->mh_flags;
+       if (flags&MH_NOSEEK)
+               return (MBU_DODATA);
+       if (bp->b_cylin == (hpaddr->hpdc & 0xffff)) {
+               if (flags&MH_NOSEARCH)
+                       return (MBU_DODATA);
+               bn = dkblock(bp);
+               st = &hpst[mi->mi_type];
+               sn = bn%st->nspc;
+               sn = (sn+st->nsect-hpSDIST)%st->nsect;
+               dist = ((hpaddr->hpla & 0xffff)>>6) - st->nsect + 1;
+               if (dist < 0)
+                       dist += st->nsect;
+               if (dist > st->nsect - hpRDIST)
+                       return (MBU_DODATA);
        }
        }
-
-       if(cn - (hpaddr->hpdc & 0xffff))
-               goto search;
-       else if (hpseek)
-               goto done;
-       csn = ((hpaddr->hpla & 0xffff)>>6) - sn + 1;
-       if(csn < 0)
-               csn += ns;
-       if(csn > ns-hpRDIST)
-               goto done;
-
-search:
-       hpaddr->hpdc = cn;
-       if (hpseek)
+       if (flags&MH_NOSEARCH)
                hpaddr->hpcs1 = SEEK|GO;
        else {
                hpaddr->hpda = sn;
                hpaddr->hpcs1 = SEARCH|GO;
        }
                hpaddr->hpcs1 = SEEK|GO;
        else {
                hpaddr->hpda = sn;
                hpaddr->hpcs1 = SEARCH|GO;
        }
-       unit += HPDK_N;
-       if (unit <= HPDK_NMAX) {
-               dk_busy |= 1<<unit;
-               dk_seek[unit]++;
-       }
-       return;
-#endif
-
-done:
-       dp->b_forw = NULL;
-       if(hptab.b_actf == NULL)
-               hptab.b_actf = dp;
-       else
-               hptab.b_actl->b_forw = dp;
-       hptab.b_actl = dp;
+       return (MBU_STARTED);
 }
 
 }
 
-hpstart()
+hpstart(mi)
+       register struct mba_info *mi;
 {
 {
-       register struct buf *bp, *dp;
-       register unit;
-       register struct device *hpaddr;
+       register struct device *hpaddr = (struct device *)mi->mi_drv;
+       register struct buf *bp = mi->mi_tab.b_actf;
+       register struct hpst *st = &hpst[mi->mi_type];
        daddr_t bn;
        daddr_t bn;
-       int dn, sn, tn, cn, nspc, ns;
+       int sn, tn;
 
 
-loop:
-       if ((dp = hptab.b_actf) == NULL)
-               return;
-       if ((bp = dp->b_actf) == NULL) {
-               hptab.b_actf = dp->b_forw;
-               goto loop;
-       }
-       hptab.b_active++;
-       unit = minor(bp->b_dev) & 077;
-       dn = dkunit(bp);
        bn = dkblock(bp);
        bn = dkblock(bp);
-       switch (hp_type[dn]) {
-       case RM:
-               nspc = NRMSECT*NRMTRAC;
-               ns = NRMSECT;
-               cn = rm_sizes[unit&07].cyloff;
-               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;
-               break;
-       default:
-               panic("hpstart");
-       }
-       cn += bn/nspc;
-       sn = bn%nspc;
-       tn = sn/ns;
-       sn = sn%ns;
-
-       hpaddr = mbadev(HPMBA, dn);
-       if ((hpaddr->hpds & (DPR|MOL)) != (DPR|MOL)) {
-               hptab.b_active = 0;
-               hptab.b_errcnt = 0;
-               dp->b_actf = bp->av_forw;
-               bp->b_flags |= B_ERROR;
-               iodone(bp);
-               goto loop;
-       }
-       if(hptab.b_errcnt >= 16 && (bp->b_flags&B_READ) != 0) {
-               hpaddr->hpof = hp_offset[hptab.b_errcnt & 017] | FMT22;
-               HPMBA->mba_cr &= ~MBAIE;
+       sn = bn%st->nspc;
+       tn = sn/st->nsect;
+       sn = sn%st->nsect;
+       if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags&B_READ) != 0) {
+               hpaddr->hpof = hp_offset[mi->mi_tab.b_errcnt & 017] | FMT22;
                hpaddr->hpcs1 = OFFSET|GO;
                hpaddr->hpcs1 = OFFSET|GO;
-               while(hpaddr->hpds & PIP)
+               while (hpaddr->hpds & PIP)
                        ;
                        ;
-               HPMBA->mba_cr |= MBAIE;
+               mbclrattn(mi);
        }
        }
-       hpaddr->hpdc = cn;
+       hpaddr->hpdc = bp->b_cylin;
        hpaddr->hpda = (tn << 8) + sn;
        hpaddr->hpda = (tn << 8) + sn;
-       mbastart(bp, (int *)hpaddr);
-
-       unit = dn+HPDK_N;
-       if (unit <= HPDK_NMAX) {
-               dk_busy |= 1<<unit;
-               dk_xfer[unit]++;
-               dk_wds[unit] += bp->b_bcount>>6;
-       }
 }
 
 }
 
-hpintr(mbastat, as)
+hpdtint(mi, mbastat)
+       register struct mba_info *mi;
+       int mbastat;
 {
 {
-       register struct buf *bp, *dp;
-       register unit;
-       register struct device *hpaddr;
-
-       if(hptab.b_active) {
-               dp = hptab.b_actf;
-               bp = dp->b_actf;
-               unit = dkunit(bp);
-               if (HPDK_N+unit <= HPDK_NMAX)
-                       dk_busy &= ~(1<<(HPDK_N+unit));
-               hpaddr = mbadev(HPMBA, unit);
-               if (hpaddr->hpds & ERR || mbastat & MBAEBITS) {
-                       while((hpaddr->hpds & DRY) == 0)
-                               ;
-                       if(++hptab.b_errcnt > 28 || hpaddr->hper1&WLE)
-                               bp->b_flags |= B_ERROR;
-                       else
-                               hptab.b_active = 0;
-                       if(hptab.b_errcnt > 27)
-                               deverror(bp, mbastat, hpaddr->hper1);
-                       if ((hpaddr->hper1&0xffff) == DCK) {
-                               if (hpecc(hpaddr, bp))
-                                       return;
-                       }
-                       hpaddr->hpcs1 = DCLR|GO;
-                       if((hptab.b_errcnt&07) == 4) {
-                               HPMBA->mba_cr &= ~MBAIE;
-                               hpaddr->hpcs1 = RECAL|GO;
-                               while(hpaddr->hpds & PIP)
-                                       ;
-                               HPMBA->mba_cr |= MBAIE;
-                       }
+       register struct device *hpaddr = (struct device *)mi->mi_drv;
+       register struct buf *bp = mi->mi_tab.b_actf;
+
+       while ((hpaddr->hpds & DRY) == 0)       /* shouldn't happen */
+               printf("hp dry not set\n");
+       if (hpaddr->hpds & ERR || mbastat & MBAEBITS)
+               if (++mi->mi_tab.b_errcnt < 28 && (hpaddr->hper1&WLE) == 0) {
+                       if ((hpaddr->hper1&0xffff) != DCK) {
+                               hpaddr->hpcs1 = DCLR|GO;
+                               if ((mi->mi_tab.b_errcnt&07) == 4) {
+                                       hpaddr->hpcs1 = RECAL|GO;
+                                       while (hpaddr->hpds & PIP)
+                                               ;
+                                       mbclrattn(mi);
+                               }
+                               return (MBD_RETRY);
+                       } else if (hpecc(mi))
+                               return (MBD_RESTARTED);
+               } else {
+                       deverror(bp, mbastat, hpaddr->hper1);
+                       bp->b_flags |= B_ERROR;
                }
                }
-               if(hptab.b_active) {
-                       if(hptab.b_errcnt) {
-                               HPMBA->mba_cr &= ~MBAIE;
-                               hpaddr->hpcs1 = RTC|GO;
-                               while(hpaddr->hpds & PIP)
-                                       ;
-                               HPMBA->mba_cr |= MBAIE;
-                       }
-                       hptab.b_active = 0;
-                       hptab.b_errcnt = 0;
-                       hptab.b_actf = dp->b_forw;
-                       dp->b_active = 0;
-                       dp->b_errcnt = 0;
-                       dp->b_actf = bp->av_forw;
-                       bp->b_resid = -HPMBA->mba_bcr & 0xffff;
-                       iodone(bp);
-                       if(dp->b_actf)
-                               hpustart(unit);
-               }
-               as &= ~(1<<unit);
-       } else {
-               if(as == 0)
-                       HPMBA->mba_cr |= MBAIE;
+       bp->b_resid = -(mi->mi_mba->mba_bcr) & 0xffff;
+       if (mi->mi_tab.b_errcnt) {
+               hpaddr->hpcs1 = RTC|GO;
+               while (hpaddr->hpds & PIP)
+                       ;
+               mbclrattn(mi);
        }
        }
-       for(unit=0; unit<NHP; unit++)
-               if(as & (1<<unit))
-                       hpustart(unit);
-       hpstart();
+       hpaddr->hpcs1 = RELEASE|GO;
+       return (MBD_DONE);
 }
 
 hpread(dev)
 }
 
 hpread(dev)
@@ -445,16 +260,17 @@ hpwrite(dev)
        physio(hpstrategy, &rhpbuf, dev, B_WRITE, minphys);
 }
 
        physio(hpstrategy, &rhpbuf, dev, B_WRITE, minphys);
 }
 
-hpecc(rp, bp)
-register struct device *rp;
-register struct buf *bp;
+hpecc(mi)
+       register struct mba_info *mi;
 {
 {
-       struct mba_regs *mbp = HPMBA;
+       register struct mba_regs *mbp = mi->mi_mba;
+       register struct device *rp = (struct device *)mi->mi_drv;
+       register struct buf *bp = mi->mi_tab.b_actf;
+       register struct hpst *st;
        register int i;
        caddr_t addr;
        int reg, bit, byte, npf, mask, o;
        register int i;
        caddr_t addr;
        int reg, bit, byte, npf, mask, o;
-       int dn, bn, cn, tn, sn, ns, nt;
-       extern char buffers[NBUF][BSIZE];
+       int bn, cn, tn, sn;
        struct pte mpte;
        int bcr;
 
        struct pte mpte;
        int bcr;
 
@@ -502,7 +318,7 @@ register struct buf *bp;
                i++;
                bit -= 8;
        }
                i++;
                bit -= 8;
        }
-       hptab.b_active++;               /* Either complete or continuing */
+       mi->mi_hd->mh_active++;         /* Either complete or continuing */
        if (bcr == 0)
                return (0);
        /*
        if (bcr == 0)
                return (0);
        /*
@@ -512,25 +328,14 @@ register struct buf *bp;
         * restart at offset o of next sector (i.e. in MBA register reg+1).
         */
        rp->hpcs1 = DCLR|GO;
         * restart at offset o of next sector (i.e. in MBA register reg+1).
         */
        rp->hpcs1 = DCLR|GO;
-       dn = dkunit(bp);
        bn = dkblock(bp);
        bn = dkblock(bp);
-       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");
-       }
+       st = &hpst[mi->mi_type];
        cn = bp->b_cylin;
        cn = bp->b_cylin;
-       sn = bn%(ns*nt) + npf + 1;
-       tn = sn/ns;
-       sn %= ns;
-       cn += tn/nt;
-       tn %= nt;
+       sn = bn%(st->nspc) + npf + 1;
+       tn = sn/st->nsect;
+       sn %= st->nsect;
+       cn += tn/st->ntrak;
+       tn %= st->ntrak;
        rp->hpdc = cn;
        rp->hpda = (tn<<8) + sn;
        mbp->mba_sr = -1;
        rp->hpdc = cn;
        rp->hpda = (tn<<8) + sn;
        mbp->mba_sr = -1;
@@ -544,10 +349,12 @@ register struct buf *bp;
 hpdump(dev)
        dev_t dev;
 {
 hpdump(dev)
        dev_t dev;
 {
+       register struct mba_info *mi;
+       register struct mba_regs *mba;
        struct device *hpaddr;
        char *start;
        struct device *hpaddr;
        char *start;
-       int num, blk, unit, nsect, ntrak, nspc;
-       struct size *sizes;
+       int num, unit;
+       register struct hpst *st;
 
        num = maxfree;
        start = 0;
 
        num = maxfree;
        start = 0;
@@ -556,54 +363,49 @@ hpdump(dev)
                printf("bad unit\n");
                return (-1);
        }
                printf("bad unit\n");
                return (-1);
        }
-       HPPHYSMBA->mba_cr = MBAINIT;
-       hpaddr = mbadev(HPPHYSMBA, unit);
-       if (hp_type[unit] == 0)
-               hp_type[unit] = hpaddr->hpdt;
-       if((hpaddr->hpds & VV) == 0) {
+#define        phys(a,b)       ((b)((int)(a)&0x7fffffff))
+       mi = phys(hpinfo[unit],struct mba_info *);
+       if (mi->mi_alive == 0) {
+               printf("dna\n");
+               return (-1);
+       }
+       mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
+       mba->mba_cr = MBAINIT;
+       hpaddr = (struct device *)&mba->mba_drv[mi->mi_drive];
+       if ((hpaddr->hpds & VV) == 0) {
+               hpaddr->hpcs1 = DCLR|GO;
                hpaddr->hpcs1 = PRESET|GO;
                hpaddr->hpof = FMT22;
        }
                hpaddr->hpcs1 = PRESET|GO;
                hpaddr->hpof = FMT22;
        }
-       switch (hp_type[unit]) {
-       case RM5:
-               nsect = NRMSECT; ntrak = NTRAC; sizes = rm5_sizes; break;
-       case RM:
-               nsect = NRMSECT; ntrak = NRMTRAC; sizes = rm_sizes; break;
-       case RP:
-               nsect = NSECT; ntrak = NTRAC; sizes = hp_sizes; break;
-       default:
-               printf("hp unknown type %x\n", hp_type[unit]);
-               return (-1);
-       }
-       if (dumplo < 0 || dumplo + num >= sizes[minor(dev)&07].nblocks) {
-               printf("dumplo+num, sizes %d %d\n", dumplo+num, sizes[minor(dev)&07].nblocks);
+       st = &hpst[mi->mi_type];
+       if (dumplo < 0 || dumplo + num >= st->sizes[minor(dev)&07].nblocks) {
+               printf("oor\n");
                return (-1);
        }
                return (-1);
        }
-       nspc = nsect * ntrak;
        while (num > 0) {
        while (num > 0) {
-               register struct pte *hpte = HPPHYSMBA->mba_map;
+               register struct pte *hpte = mba->mba_map;
                register int i;
                register int i;
-               int cn, sn, tn;
+               int blk, cn, sn, tn;
                daddr_t bn;
 
                blk = num > DBSIZE ? DBSIZE : num;
                bn = dumplo + btop(start);
                daddr_t bn;
 
                blk = num > DBSIZE ? DBSIZE : num;
                bn = dumplo + btop(start);
-               cn = bn/nspc + sizes[minor(dev)&07].cyloff;
-               sn = bn%nspc;
-               tn = sn/nsect;
-               sn = sn%nsect;
+               cn = bn/st->nspc + st->sizes[minor(dev)&07].cyloff;
+               sn = bn%st->nspc;
+               tn = sn/st->nsect;
+               sn = sn%st->nsect;
                hpaddr->hpdc = cn;
                hpaddr->hpda = (tn << 8) + sn;
                for (i = 0; i < blk; i++)
                        *(int *)hpte++ = (btop(start)+i) | PG_V;
                hpaddr->hpdc = cn;
                hpaddr->hpda = (tn << 8) + sn;
                for (i = 0; i < blk; i++)
                        *(int *)hpte++ = (btop(start)+i) | PG_V;
-               ((struct mba_regs *)HPPHYSMBA)->mba_sr = -1;
-               ((struct mba_regs *)HPPHYSMBA)->mba_bcr = -(blk*NBPG);
-               ((struct mba_regs *)HPPHYSMBA)->mba_var = 0;
+               mba->mba_sr = -1;
+               mba->mba_bcr = -(blk*NBPG);
+               mba->mba_var = 0;
                hpaddr->hpcs1 = WCOM | GO;
                while ((hpaddr->hpds & DRY) == 0)
                        ;
                if (hpaddr->hpds&ERR) {
                hpaddr->hpcs1 = WCOM | GO;
                while ((hpaddr->hpds & DRY) == 0)
                        ;
                if (hpaddr->hpds&ERR) {
-                       printf("hp dump dsk err: (%d,%d,%d) ds=%x er=%x\n",
+                       printf("dskerr: (%d,%d,%d) ds=%x er=%x\n",
                            cn, tn, sn, hpaddr->hpds, hpaddr->hper1);
                        return (-1);
                }
                            cn, tn, sn, hpaddr->hpds, hpaddr->hper1);
                        return (-1);
                }
@@ -612,4 +414,9 @@ hpdump(dev)
        }
        return (0);
 }
        }
        return (0);
 }
+
+hpdkinit()
+{
+       /* I don't really care what this does .. kre */
+}
 #endif
 #endif
index 32612e3..0d81c27 100644 (file)
-/*     mba.c   4.3     %G%     */
+/*     mba.c   4.4     81/02/08        */
+
+/*
+ * Massbus driver; arbitrates massbusses through device driver routines
+ * and provides common functions.
+ */
+int    mbadebug = 0;
+#define        dprintf if (mbadebug) printf
 
 
-#if VAX==780
 #include "../h/param.h"
 #include "../h/param.h"
+#include "../h/systm.h"
+#include "../h/dk.h"
 #include "../h/buf.h"
 #include "../h/conf.h"
 #include "../h/buf.h"
 #include "../h/conf.h"
-#include "../h/systm.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
-#include "../h/seg.h"
-#include "../h/pte.h"
 #include "../h/map.h"
 #include "../h/map.h"
+#include "../h/pte.h"
 #include "../h/mba.h"
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
 /*
 #include "../h/mba.h"
 #include "../h/mtpr.h"
 #include "../h/vm.h"
 
 /*
- * startup routine for MBA controllers.
+ * Start activity on a massbus device.
+ * We are given the device's mba_info structure and activate
+ * the device via the unit start routine.  The unit start
+ * routine may indicate that it is finished (e.g. if the operation
+ * was a ``sense'' on a tape drive), that the (multi-ported) unit
+ * is busy (we will get an interrupt later), that it started the
+ * unit (e.g. for a non-data transfer operation), or that it has
+ * set up a data transfer operation and we should start the massbus adaptor.
  */
  */
-#define        MBAWCOM 0x30
-#define        MBARCOM 0x38
-#define        GO      01
+mbustart(mi)
+       register struct mba_info *mi;
+{
+       register struct mba_drv *mdp;   /* drive registers */
+       register struct buf *bp;        /* i/o operation at head of queue */
+       register struct mba_hd *mhp;    /* header for mba device is on */
+
+       dprintf("enter mbustart\n");
+loop:
+       /*
+        * Get the first thing to do off device queue.
+        */
+       bp = mi->mi_tab.b_actf;
+       if (bp == NULL)
+               return;
+       mdp = mi->mi_drv;
+       /*
+        * Since we clear attentions on the drive when we are
+        * finished processing it, the fact that an attention
+        * status shows indicated confusion in the hardware or our logic.
+        */
+       if (mdp->mbd_as & (1 << mi->mi_drive)) {
+               printf("mbustart: ata on for %d\n", mi->mi_drive);
+               mdp->mbd_as = 1 << mi->mi_drive;
+       }
+       /*
+        * Let the drivers unit start routine have at it
+        * and then process the request further, per its instructions.
+        */
+       switch ((*mi->mi_driver->md_ustart)(mi)) {
+
+       case MBU_NEXT:          /* request is complete (e.g. ``sense'') */
+               dprintf("mbu_next\n");
+               mi->mi_tab.b_active = 0;
+               mi->mi_tab.b_actf = bp->av_forw;
+               iodone(bp);
+               goto loop;
+
+       case MBU_DODATA:        /* all ready to do data transfer */
+               dprintf("mbu_dodata\n");
+               /*
+                * Queue the device mba_info structure on the massbus
+                * mba_hd structure for processing as soon as the
+                * data path is available.
+                */
+               mhp = mi->mi_hd;
+               mi->mi_forw = NULL;
+               if (mhp->mh_actf == NULL)
+                       mhp->mh_actf = mi;
+               else
+                       mhp->mh_actl->mi_forw = mi;
+               mhp->mh_actl = mi;
+               /*
+                * If data path is idle, start transfer now.
+                * In any case the device is ``active'' waiting for the
+                * data to transfer.
+                */
+               if (mhp->mh_active == 0)
+                       mbstart(mhp);
+               mi->mi_tab.b_active = 1;
+               return;
+
+       case MBU_STARTED:       /* driver started a non-data transfer */
+               dprintf("mbu_started\n");
+               /*
+                * Mark device busy during non-data transfer
+                * and count this as a ``seek'' on the device.
+                */
+               if (mi->mi_dk >= 0)
+                       dk_seek[mi->mi_dk]++;
+               mi->mi_tab.b_active = 1;
+               return;
+
+       case MBU_BUSY:          /* dual port drive busy */
+               dprintf("mbu_busy\n");
+               /*
+                * We mark the device structure so that when an
+                * interrupt occurs we will know to restart the unit.
+                */
+               mi->mi_tab.b_flags |= B_BUSY;
+               return;
+
+       default:
+               panic("mbustart");
+       }
+#if VAX==780
+
+/*
+ * Start an i/o operation on the massbus specified by the argument.
+ * We peel the first operation off its queue and insure that the drive
+ * is present and on-line.  We then use the drivers start routine
+ * (if any) to prepare the drive, setup the massbus map for the transfer
+ * and start the transfer.
+ */
+mbstart(mhp)
+       register struct mba_hd *mhp;
+{
+       register struct mba_info *mi;
+       struct buf *bp;
+       register struct mba_drv *daddr;
+       register struct mba_regs *mbp;
+
+       dprintf("mbstart\n");
+loop:
+       /*
+        * Look for an operation at the front of the queue.
+        */
+       if ((mi = mhp->mh_actf) == NULL) {
+               dprintf("nothing to do\n");
+               return;
+       }
+       if ((bp = mi->mi_tab.b_actf) == NULL) {
+               dprintf("nothing on actf\n");
+               mhp->mh_actf = mi->mi_forw;
+               goto loop;
+       }
+       /*
+        * If this device isn't present and on-line, then
+        * we screwed up, and can't really do the operation.
+        */
+       if ((mi->mi_drv->mbd_ds & (MBD_DPR|MBD_MOL)) != (MBD_DPR|MBD_MOL)) {
+               dprintf("not on line ds %x\n", mi->mi_drv->mbd_ds);
+               mi->mi_tab.b_actf = bp->av_forw;
+               bp->b_flags |= B_ERROR;
+               iodone(bp);
+               goto loop;
+       }
+       /*
+        * We can do the operation; mark the massbus active
+        * and let the device start routine setup any necessary
+        * device state for the transfer (e.g. desired cylinder, etc
+        * on disks).
+        */
+       mhp->mh_active = 1;
+       if (mi->mi_driver->md_start) {
+               dprintf("md_start\n");
+               (*mi->mi_driver->md_start)(mi);
+       }
+
+       /*
+        * Setup the massbus control and map registers and start
+        * the transfer.
+        */
+       dprintf("start mba\n");
+       mbp = mi->mi_mba;
+       mbp->mba_sr = -1;       /* conservative */
+       mbp->mba_var = mbasetup(mi);
+       mbp->mba_bcr = -bp->b_bcount;
+       mi->mi_drv->mbd_cs1 =
+           (bp->b_flags & B_READ) ? MBD_RCOM|MBD_GO : MBD_WCOM|MBD_GO;
+       if (mi->mi_dk >= 0) {
+               dk_busy |= 1 << mi->mi_dk;
+               dk_xfer[mi->mi_dk]++;
+               dk_wds[mi->mi_dk] += bp->b_bcount >> 6;
+       }
+}
 
 
-mbastart(bp, adcr)
+/*
+ * Take an interrupt off of massbus mbanum,
+ * and dispatch to drivers as appropriate.
+ */
+mbintr(mbanum)
+       int mbanum;
+{
+       register struct mba_hd *mhp = &mba_hd[mbanum];
+       register struct mba_regs *mbp = mhp->mh_mba;
+       register struct mba_info *mi;
        register struct buf *bp;
        register struct buf *bp;
-       int *adcr;
+       register int drive;
+       int mbastat, as;
+       
+       /*
+        * Read out the massbus status register
+        * and attention status register and clear
+        * the bits in same by writing them back.
+        */
+       mbastat = mbp->mba_sr;
+       mbp->mba_sr = mbastat;
+       /* note: the mbd_as register is shared between drives */
+       as = mbp->mba_drv[0].mbd_as;
+       mbp->mba_drv[0].mbd_as = as;
+       dprintf("mbintr mbastat %x as %x\n", mbastat, as);
+
+       /*
+        * Disable interrupts from the massbus adapter
+        * for the duration of the operation of the massbus
+        * driver, so that spurious interrupts won't be generated.
+        */
+       mbp->mba_cr &= ~MBAIE;
+
+       /*
+        * If the mba was active, process the data transfer
+        * complete interrupt; otherwise just process units which
+        * are now finished.
+        */
+       if (mhp->mh_active) {
+               if ((mbastat & MBS_DTCMP) == 0) {
+                       printf("mbintr(%d),b_active,no DTCMP!\n", mbanum);
+                       goto doattn;
+#include "../h/buf.h"
+               /*
+                * Clear attention status for drive whose data
+                * transfer completed, and give the dtint driver
+                * routine a chance to say what is next.
+                */
+               mi = mhp->mh_actf;
+               as &= ~(1 << mi->mi_drive);
+               dk_busy &= ~(1 << mi->mi_dk);
+               bp = mi->mi_tab.b_actf;
+               switch((*mi->mi_driver->md_dtint)(mi, mbastat)) {
+
+               case MBD_DONE:          /* all done, for better or worse */
+                       dprintf("mbd_done\n");
+                       /*
+                        * Flush request from drive queue.
+                        */
+                       mi->mi_tab.b_errcnt = 0;
+                       mi->mi_tab.b_actf = bp->av_forw;
+                       iodone(bp);
+                       /* fall into... */
+               case MBD_RETRY:         /* attempt the operation again */
+                       dprintf("mbd_retry\n");
+                       /*
+                        * Dequeue data transfer from massbus queue;
+                        * if there is still a i/o request on the device
+                        * queue then start the next operation on the device.
+                        * (Common code for DONE and RETRY).
+                        */
+                       mhp->mh_active = 0;
+                       mi->mi_tab.b_active = 0;
+                       mhp->mh_actf = mi->mi_forw;
+                       if (mi->mi_tab.b_actf)
+                               mbustart(mi);
+                       break;
+
+               case MBD_RESTARTED:     /* driver restarted op (ecc, e.g.)
+                       dprintf("mbd_restarted\n");
+                       /*
+                        * Note that mp->b_active is still on.
+                        */
+                       break;
+
+               default:
+                       panic("mbaintr");
+               }
+       } else {
+               dprintf("!dtcmp\n");
+               if (mbastat & MBS_DTCMP)
+                       printf("mbaintr,DTCMP,!b_active\n");
+       }
+doattn:
+       /*
+        * Service drives which require attention
+        * after non-data-transfer operations.
+        */
+       for (drive = 0; as && drive < 8; drive++)
+               if (as & (1 << drive)) {
+                       dprintf("service as %d\n", drive);
+                       as &= ~(1 << drive);
+                       /*
+                        * Consistency check the implied attention,
+                        * to make sure the drive should have interrupted.
+                        */
+                       mi = mhp->mh_mbip[drive];
+                       if (mi == NULL)
+                               goto random;            /* no such drive */
+                       if (mi->mi_tab.b_active == 0 &&
+                           (mi->mi_tab.b_flags&B_BUSY) == 0)
+                               goto random;            /* not active */
+                       if ((bp = mi->mi_tab.b_actf) == NULL) {
+                                                       /* nothing doing */
+random:
+                               printf("random mbaintr %d %d\n",mbanum,drive);
+                               continue;
+                       }
+                       /*
+                        * If this interrupt wasn't a notification that
+                        * a dual ported drive is available, and if the
+                        * driver has a handler for non-data transfer
+                        * interrupts, give it a chance to tell us that
+                        * the operation needs to be redone
+                        */
+                       if ((mi->mi_tab.b_flags&B_BUSY) == 0 &&
+                           mi->mi_driver->md_ndint) {
+                               mi->mi_tab.b_active = 0;
+                               switch((*mi->mi_driver->md_ndint)(mi)) {
+
+                               case MBN_DONE:
+                                       dprintf("mbn_done\n");
+                                       /*
+                                        * Non-data transfer interrupt
+                                        * completed i/o request's processing.
+                                        */
+                                       mi->mi_tab.b_errcnt = 0;
+                                       mi->mi_tab.b_actf = bp->av_forw;
+                                       iodone(bp);
+                                       /* fall into... */
+                               case MBN_RETRY:
+                                       dprintf("mbn_retry\n");
+                                       if (mi->mi_tab.b_actf)
+                                               mbustart(mi);
+                                       break;
+
+                               default:
+                                       panic("mbintr ndint");
+                               }
+                       } else
+                               mbustart(mi);
+               }
+       /*
+        * If there is an operation available and
+        * the massbus isn't active, get it going.
+        */
+       if (mhp->mh_actf && !mhp->mh_active)
+               mbstart(mhp);
+       mbp->mba_cr |= MBAIE;
+}
+
+/*
+ * Setup the mapping registers for a transfer.
+ */
+mbasetup(mi)
+       register struct mba_info *mi;
 {
 {
+       register struct mba_regs *mbap = mi->mi_mba;
+       struct buf *bp = mi->mi_tab.b_actf;
        register int i;
        int npf;
        unsigned v;
        register struct pte *pte, *io;
        int o;
        int vaddr;
        register int i;
        int npf;
        unsigned v;
        register struct pte *pte, *io;
        int o;
        int vaddr;
-       register struct mba_regs *mbap;
        struct proc *rp;
 
        struct proc *rp;
 
-       mbap = mbainfo[mbanum[major(bp->b_dev)]].mi_loc;
        io = mbap->mba_map;
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
        io = mbap->mba_map;
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
@@ -64,35 +393,5 @@ mbastart(bp, adcr)
                }
        }
        *(int *)io++ = 0;
                }
        }
        *(int *)io++ = 0;
-       mbap->mba_sr = -1;      /* clear status (error) bits */
-       mbap->mba_bcr = -bp->b_bcount;
-       mbap->mba_var = vaddr;
-       if (bp->b_flags & B_READ)
-               *adcr = MBARCOM | GO;
-       else
-               *adcr = MBAWCOM | GO;
-}
-
-mbainit(mbano)
-       int mbano;
-{
-       register struct pte *b;
-       register int i;
-       register struct mba_info *mi;
-       register struct mba_regs *mbap;
-       unsigned v;
-
-       mi = &mbainfo[mbano];
-       v = btop((int)mi->mi_phys);
-       b = mi->mi_map;
-       for (i = 0; i < 8192; i += NBPG) {
-               *(int *)b++ = PG_V | PG_KW | v;
-               mtpr(TBIS, ptob(v));
-               v++;
-       }
-       mbap = mi->mi_loc;
-       mbap->mba_cr = MBAINIT;
-       mbap->mba_cr = MBAIE;
-       mbaact |= (1<<mbano);
+       return (vaddr);
 }
 }
-#endif