mv pcs750.bin to /usr/src/etc/vax
[unix-history] / usr / src / sys / vax / stand / rl.c
index 12320fd..3e59f7d 100644 (file)
@@ -1,21 +1,29 @@
-/*     rl.c    6.1     83/07/29        */
+/*
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)rl.c        7.6 (Berkeley) %G%
+ */
 
 /*
  * Standalone RL02 disk driver
  */
 
 /*
  * Standalone RL02 disk driver
  */
-#include "../machine/pte.h"
 
 
-#include "../h/param.h"
-#include "../h/inode.h"
-#include "../h/fs.h"
+#include "param.h"
+#include "inode.h"
+#include "fs.h"
 
 
+#include "../vax/pte.h"
 #include "../vaxuba/rlreg.h"
 #include "../vaxuba/ubareg.h"
 
 #include "saio.h"
 #include "savax.h"
 
 #include "../vaxuba/rlreg.h"
 #include "../vaxuba/ubareg.h"
 
 #include "saio.h"
 #include "savax.h"
 
-u_short        rlstd[] = { 0774400 };
+#define        MAXPART         8
+#define        MAXCTLR         1               /* all addresses must be specified */
+u_short        rlstd[MAXCTLR] = { 0774400 };
 short  rl_off[] = { 0, 361, 0, -1, -1, -1, -1, -1 };
 
 /* struct to keep state info about the controller */
 short  rl_off[] = { 0, 361, 0, -1, -1, -1, -1, -1 };
 
 /* struct to keep state info about the controller */
@@ -24,19 +32,24 @@ struct      rl_stat {
        short   rl_cylnhd;      /* cylinder and head */
        u_short rl_bleft;       /* bytes left to transfer */
        u_short rl_bpart;       /* bytes transferred */
        short   rl_cylnhd;      /* cylinder and head */
        u_short rl_bleft;       /* bytes left to transfer */
        u_short rl_bpart;       /* bytes transferred */
-} rl_stat[] = { -1, 0, 0, 0};
+} rl_stat[MAXCTLR] = { -1, 0, 0, 0 };
 
 rlopen(io)
        register struct iob *io;
 {
 
 rlopen(io)
        register struct iob *io;
 {
-       register struct rldevice *rladdr =
-               (struct rldevice *)ubamem(io->i_unit, rlstd[0]);
-       register struct rl_stat *st = &rl_stat[0];
+       register struct rldevice *rladdr;
+       register struct rl_stat *st;
        register int ctr = 0;
 
        register int ctr = 0;
 
-       if (rl_off[io->i_boff] == -1 ||
-           io->i_boff < 0 || io->i_boff > 7)
-               _stop("rl bad unit");
+       if ((u_int)io->i_adapt >= nuba)
+               return (EADAPT);
+       if ((u_int)io->i_ctlr >= MAXCTLR)
+               return (ECTLR);
+       rladdr = (struct rldevice *)ubamem(io->i_adapt, rlstd[io->i_ctlr]);
+       if (badaddr((char *)rladdr, sizeof(short)))
+               return (ENXIO);
+       if ((u_int)io->i_part >= MAXPART || rl_off[io->i_part] == -1)
+               return (EPART);
 
        /*
         * DEC reports that:
 
        /*
         * DEC reports that:
@@ -54,37 +67,44 @@ rlopen(io)
                rladdr->rlda.getstat = RL_RESET;
                rladdr->rlcs = (io->i_unit <<8) | RL_GETSTAT; /* Get status*/
                rlwait(rladdr);
                rladdr->rlda.getstat = RL_RESET;
                rladdr->rlcs = (io->i_unit <<8) | RL_GETSTAT; /* Get status*/
                rlwait(rladdr);
-       } while( (rladdr->rlmp.getstat&RLMP_STATUS) != RLMP_STATOK && ++ctr<8 );
+       } while ((rladdr->rlmp.getstat&RLMP_STATUS) != RLMP_STATOK && ++ctr<8);
 
 
-       if ((rladdr->rlcs & RL_DE) || (ctr >= 8))
-               _stop("rl unit does not respond");
+       if ((rladdr->rlcs & RL_DE) || (ctr >= 8)) {
+               printf("rl: unit does not respond\n");
+               return (EUNIT);
+       }
 
 
-       if ((rladdr->rlmp.getstat & RLMP_DT) == 0 )     /* NO RL01'S */
-               _stop("rl01 unit not supported");
+       if ((rladdr->rlmp.getstat & RLMP_DT) == 0) {    /* NO RL01'S */
+               printf("rl01 unit not supported\n");
+               return (ENXIO);
+       }
 
        /* Determine disk posistion */
        rladdr->rlcs = (io->i_unit << 8) | RL_RHDR;
        rlwait(rladdr);
 
        /* save disk drive posistion */
 
        /* Determine disk posistion */
        rladdr->rlcs = (io->i_unit << 8) | RL_RHDR;
        rlwait(rladdr);
 
        /* save disk drive posistion */
+       st = &rl_stat[io->i_ctlr];
        st->rl_cylnhd = (rladdr->rlmp.readhdr & 0177700) >> 6;
        st->rl_dn = io->i_unit;
 
        /* byte offset for cylinder desired */
        st->rl_cylnhd = (rladdr->rlmp.readhdr & 0177700) >> 6;
        st->rl_dn = io->i_unit;
 
        /* byte offset for cylinder desired */
-       io->i_boff = rl_off[io->i_boff] * NRLBPSC * NRLTRKS * NRLSECT;
+       io->i_boff = rl_off[io->i_part] * NRLBPSC * NRLTRKS * NRLSECT;
+       return (0);
 }
 
 rlstrategy(io, func)
        register struct iob *io;
 {
 }
 
 rlstrategy(io, func)
        register struct iob *io;
 {
-       register struct rldevice *rladdr =
-               (struct rldevice *)ubamem(io->i_unit, rlstd[0]);
-       register struct rl_stat *st = &rl_stat[0];
+       register struct rldevice *rladdr;
+       register struct rl_stat *st;
        int com;
        daddr_t bn;
        short cn, sn, head;
        int com;
        daddr_t bn;
        short cn, sn, head;
-       int diff, ubinfo, ubaddr, errcnt = 0;
+       int diff, ubinfo, ubaaddr, errcnt = 0;
 
 
+       rladdr = (struct rldevice *)ubamem(io->i_adapt, rlstd[io->i_ctlr]);
+       st = &rl_stat[io->i_ctlr];
 retry:
        ubinfo = ubasetup(io, 1);
        bn = io->i_bn;          /* block number */
 retry:
        ubinfo = ubasetup(io, 1);
        bn = io->i_bn;          /* block number */
@@ -92,18 +112,18 @@ retry:
        sn = (bn % 20) << 1;
        head = (bn / 20) & 1;
        st->rl_bleft = io->i_cc;        /* total number of bytes to trans */
        sn = (bn % 20) << 1;
        head = (bn / 20) & 1;
        st->rl_bleft = io->i_cc;        /* total number of bytes to trans */
-       ubaddr = ubinfo;
+       ubaaddr = ubinfo;
 
 stupid_rl:
        /* find out how many cylinders to seek */
        diff = (st->rl_cylnhd >> 1) - cn;
 
 stupid_rl:
        /* find out how many cylinders to seek */
        diff = (st->rl_cylnhd >> 1) - cn;
-       if ( diff == 0 && (st->rl_cylnhd & 1) == head )
+       if (diff == 0 && (st->rl_cylnhd & 1) == head)
                goto noseek;
 
        /* first time or we switched drives */
        st->rl_dn = io->i_unit; /* drive number */
 
                goto noseek;
 
        /* first time or we switched drives */
        st->rl_dn = io->i_unit; /* drive number */
 
-       if ( diff < 0 )
+       if (diff < 0)
                rladdr->rlda.seek = -diff<<7 | RLDA_HGH | head << 4;
        else
                rladdr->rlda.seek = diff<<7 | RLDA_LOW | head << 4;
                rladdr->rlda.seek = -diff<<7 | RLDA_HGH | head << 4;
        else
                rladdr->rlda.seek = diff<<7 | RLDA_LOW | head << 4;
@@ -119,14 +139,14 @@ noseek:
 
        /* calculate the max number of bytes we can trans */
        st->rl_bpart = NRLSECT * NRLBPSC - (sn * NRLBPSC);
 
        /* calculate the max number of bytes we can trans */
        st->rl_bpart = NRLSECT * NRLBPSC - (sn * NRLBPSC);
-       if ( st->rl_bleft < st->rl_bpart )
+       if (st->rl_bleft < st->rl_bpart)
                st->rl_bpart = st->rl_bleft;
 
        rladdr->rlda.rw = (st->rl_cylnhd << 6) | sn;
        rladdr->rlmp.rw = -(st->rl_bpart >> 1);
                st->rl_bpart = st->rl_bleft;
 
        rladdr->rlda.rw = (st->rl_cylnhd << 6) | sn;
        rladdr->rlmp.rw = -(st->rl_bpart >> 1);
-       rladdr->rlba = ubaddr;
+       rladdr->rlba = ubaaddr;
 
 
-       com = (st->rl_dn << 8) | ((ubaddr>>12)&RL_BAE);
+       com = (st->rl_dn << 8) | ((ubaaddr>>12)&RL_BAE);
 
        if (func == READ)
                com |= RL_READ;
 
        if (func == READ)
                com |= RL_READ;
@@ -141,7 +161,7 @@ noseek:
        if (rladdr->rlcs & RL_ERR) {
                int status;
 
        if (rladdr->rlcs & RL_ERR) {
                int status;
 
-               if ( rladdr->rlcs & RL_DE ) {
+               if (rladdr->rlcs & RL_DE) {
                        rladdr->rlda.getstat = RL_GSTAT;
                        rladdr->rlcs = (st->rl_dn << 8) | RL_GETSTAT;
                        rlwait(rladdr);
                        rladdr->rlda.getstat = RL_GSTAT;
                        rladdr->rlcs = (st->rl_dn << 8) | RL_GETSTAT;
                        rlwait(rladdr);
@@ -161,18 +181,17 @@ noseek:
                /* save disk drive posistion */
                st->rl_cylnhd = (rladdr->rlmp.readhdr & 0177700) >> 6;
 
                /* save disk drive posistion */
                st->rl_cylnhd = (rladdr->rlmp.readhdr & 0177700) >> 6;
 
-               if (errcnt == 10) {
+               if (errcnt++ == 10) {
                        printf("rl: unrecovered error\n");
                        return (-1);
                }
                        printf("rl: unrecovered error\n");
                        return (-1);
                }
-               errcnt++;
                goto retry;
        }
 
        /* do we have to finish off the rest of the transfer? */
                goto retry;
        }
 
        /* do we have to finish off the rest of the transfer? */
-       if ( (st->rl_bleft -= st->rl_bpart) > 0 ) {
+       if ((st->rl_bleft -= st->rl_bpart) > 0) {
                /* increment head and/or cylinder */
                /* increment head and/or cylinder */
-               if ( ++head > 1 ) {
+               if (++head > 1) {
                        cn++;           /* want next cyl, head 0 sector 0 */
                        head = 0;
                }
                        cn++;           /* want next cyl, head 0 sector 0 */
                        head = 0;
                }
@@ -186,7 +205,7 @@ noseek:
                 */
                ubafree(io, ubinfo);
 
                 */
                ubafree(io, ubinfo);
 
-               ubaddr = ubinfo + io->i_cc - st->rl_bleft;
+               ubaaddr = ubinfo + io->i_cc - st->rl_bleft;
 
                goto stupid_rl;
        }
 
                goto stupid_rl;
        }
@@ -198,19 +217,9 @@ noseek:
        return (io->i_cc);
 }
 
        return (io->i_cc);
 }
 
+static
 rlwait(rladdr)
        register struct rldevice *rladdr;
 {
 rlwait(rladdr)
        register struct rldevice *rladdr;
 {
-
-       while ((rladdr->rlcs & RL_CRDY) == 0)
-               continue;
-}
-
-rlioctl(io, cmd, arg)
-       struct iob *io;
-       int cmd;
-       caddr_t arg;
-{
-
-       return (ECMD);
+       while ((rladdr->rlcs & RL_CRDY) == 0);
 }
 }