Increase the timeout from 2000 counts to 6000 counts, reported by someone
[unix-history] / sys / scsi / cd.c
index 628845d..ab39386 100644 (file)
@@ -14,7 +14,7 @@
  *
  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  *
  *
  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  *
- *     $Id: cd.c,v 1.6 93/08/26 21:09:07 julian Exp Locker: julian $
+ *     $Id: cd.c,v 1.8 1993/09/09 07:18:52 rgrimes Exp $
  */
 
 #define SPLCD splbio
  */
 
 #define SPLCD splbio
@@ -68,10 +68,6 @@ int  cd_done();
 int    cdstrategy();
 int    cd_debug = 0;
 
 int    cdstrategy();
 int    cd_debug = 0;
 
-struct buf             cd_buf_queue[NCD];
-struct scsi_xfer       cd_scsi_xfer[NCD][CDOUTSTANDING]; /* XXX */
-struct scsi_xfer       *cd_free_xfer[NCD];
-int                    cd_xfer_block_wait[NCD];
 
 struct cd_data
 {
 
 struct cd_data
 {
@@ -94,12 +90,21 @@ struct      cd_data
        int     partflags[MAXPARTITIONS];       /* per partition flags */
 #define CDOPEN 0x01
        int             openparts;              /* one bit for each open partition */
        int     partflags[MAXPARTITIONS];       /* per partition flags */
 #define CDOPEN 0x01
        int             openparts;              /* one bit for each open partition */
-}cd_data[NCD];
+       int             xfer_block_wait;
+       struct  scsi_xfer       *free_xfer;
+       struct  scsi_xfer       scsi_xfer[CDOUTSTANDING]; /* XXX */
+       struct  buf             buf_queue;
+};
 
 #define CD_STOP                0
 #define CD_START       1
 #define CD_EJECT       -2
 
 
 #define CD_STOP                0
 #define CD_START       1
 #define CD_EJECT       -2
 
+struct cd_driver
+{
+       int     size;
+       struct  cd_data **cd_data;
+}*cd_driver;
 
 static int     next_cd_unit = 0;
 /***********************************************************************\
 
 static int     next_cd_unit = 0;
 /***********************************************************************\
@@ -109,23 +114,81 @@ static    int     next_cd_unit = 0;
 int    cdattach(ctlr,targ,lu,scsi_switch)
 struct scsi_switch *scsi_switch;
 {
 int    cdattach(ctlr,targ,lu,scsi_switch)
 struct scsi_switch *scsi_switch;
 {
-       int     unit,i;
-       unsigned char *tbl;
-       struct cd_data *cd;
-       struct cd_parms *dp;
+       int             unit,i;
+       unsigned char   *tbl;
+       struct cd_data  *cd, **cdrealloc;
+       struct cd_parms *dp;
 
 
-       unit = next_cd_unit++;
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("cdattach: "); 
        if(scsi_debug & PRINTROUTINES) printf("cdattach: "); 
+#endif /*CDDEBUG*/
+       /*******************************************************\
+       * Check if we have resources allocated yet, if not      *
+       * allocate and initialize them                          *
+       \*******************************************************/
+       if (next_cd_unit == 0)
+       {
+               cd_driver =
+                       malloc(sizeof(struct cd_driver),M_DEVBUF,M_NOWAIT);
+               if(!cd_driver)
+               {
+                       printf("cd%d: malloc failed for cd_driver\n",unit);
+                       return(0);
+               }
+               bzero(cd_driver,sizeof(cd_driver));
+               cd_driver->size = 0;
+       }
+       /*******************************************************\
+       * allocate the resources for another drive              *
+       * if we have already allocate a cd_data pointer we must *
+       * copy the old pointers into a new region that is       *
+       * larger and release the old region, aka realloc        *
+       \*******************************************************/
+       unit = next_cd_unit++;
+       /* XXX
+        * This if will always be true for now, but future code may
+        * preallocate more units to reduce overhead.  This would be
+        * done by changing the malloc to be (next_cd_unit * x) and
+        * the cd_driver->size++ to be +x
+        */
+       if(unit >= cd_driver->size)
+       {
+               cdrealloc =
+                       malloc(sizeof(cd_driver->cd_data) * next_cd_unit,
+                               M_DEVBUF,M_NOWAIT);
+               if(!cdrealloc)
+               {
+                       printf("cd%d: malloc failed for cdrealloc\n",unit);
+                       return(0);
+               }
+               /* Make sure we have something to copy before we copy it */
+               bzero(cdrealloc,sizeof(cd_driver->cd_data) * next_cd_unit);
+               if(cd_driver->size)
+               {
+                       bcopy(cd_driver->cd_data,cdrealloc,
+                               sizeof(cd_driver->cd_data) * cd_driver->size);
+                       free(cd_driver->cd_data,M_DEVBUF);
+               }
+               cd_driver->cd_data = cdrealloc;
+               cd_driver->cd_data[unit] = NULL;
+               cd_driver->size++;
+       }
+       if(cd_driver->cd_data[unit])
+       {
+               printf("cd%d: Already has storage!\n",unit);
+               return(0);
+       }
        /*******************************************************\
        /*******************************************************\
-       * Check we have the resources for another drive         *
+       * allocate the per drive data area                      *
        \*******************************************************/
        \*******************************************************/
-       if( unit >= NCD)
+       cd = cd_driver->cd_data[unit] =
+               malloc(sizeof(struct cd_data),M_DEVBUF,M_NOWAIT);
+       if(!cd)
        {
        {
-               printf("Too many scsi CDs..(%d > %d) reconfigure kernel\n",
-                       (unit + 1),NCD);
+               printf("cd%d: malloc failed for cd_data\n",unit);
                return(0);
        }
                return(0);
        }
-       cd = cd_data + unit;
+       bzero(cd,sizeof(struct cd_data));
        dp  = &(cd->params);
        /*******************************************************\
        * Store information needed to contact our base driver   *
        dp  = &(cd->params);
        /*******************************************************\
        * Store information needed to contact our base driver   *
@@ -136,12 +199,11 @@ struct    scsi_switch *scsi_switch;
        cd->lu          =       lu;
        cd->cmdscount = CDOUTSTANDING; /* XXX (ask the board) */
 
        cd->lu          =       lu;
        cd->cmdscount = CDOUTSTANDING; /* XXX (ask the board) */
 
-
        i = cd->cmdscount;
        while(i-- )
        {
        i = cd->cmdscount;
        while(i-- )
        {
-               cd_scsi_xfer[unit][i].next = cd_free_xfer[unit];
-               cd_free_xfer[unit] = &cd_scsi_xfer[unit][i];
+               cd->scsi_xfer[i].next = cd->free_xfer;
+               cd->free_xfer = &cd->scsi_xfer[i];
        }
        /*******************************************************\
        * Use the subdriver to request information regarding    *
        }
        /*******************************************************\
        * Use the subdriver to request information regarding    *
@@ -159,11 +221,8 @@ struct     scsi_switch *scsi_switch;
        }
        cd->flags |= CDINIT;
        return;
        }
        cd->flags |= CDINIT;
        return;
-
 }
 
 }
 
-
-
 /*******************************************************\
 *      open the device. Make sure the partition info   *
 * is a up-to-date as can be.                           *
 /*******************************************************\
 *      open the device. Make sure the partition info   *
 * is a up-to-date as can be.                           *
@@ -173,27 +232,28 @@ cdopen(dev)
        int errcode = 0;
        int unit, part;
        struct cd_parms cd_parms;
        int errcode = 0;
        int unit, part;
        struct cd_parms cd_parms;
-       struct cd_data *cd ;
+       struct cd_data *cd;
 
        unit = UNIT(dev);
        part = PARTITION(dev);
 
        unit = UNIT(dev);
        part = PARTITION(dev);
-       cd = cd_data + unit;
+
+#ifdef CDDEBUG
        if(scsi_debug & (PRINTROUTINES | TRACEOPENS))
                printf("cdopen: dev=0x%x (unit %d (of %d),partition %d)\n"
        if(scsi_debug & (PRINTROUTINES | TRACEOPENS))
                printf("cdopen: dev=0x%x (unit %d (of %d),partition %d)\n"
-                               ,   dev,      unit,   NCD,         part);
+                       ,dev,unit,cd_driver->size,part);
+#endif /*CDDEBUG*/
        /*******************************************************\
        * Check the unit is legal                               *
        \*******************************************************/
        /*******************************************************\
        * Check the unit is legal                               *
        \*******************************************************/
-       if ( unit >= NCD )
+       if ( unit >= cd_driver->size )
        {
                return(ENXIO);
        }
        {
                return(ENXIO);
        }
+       cd = cd_driver->cd_data[unit];
        /*******************************************************\
        /*******************************************************\
-       * Make sure the disk has been initialised               *
-       * At some point in the future, get the scsi driver      *
-       * to look for a new device if we are not initted        *
+       * Make sure the device has been initialised             *
        \*******************************************************/
        \*******************************************************/
-       if (! (cd->flags & CDINIT))
+       if ((cd == NULL) || (!(cd->flags & CDINIT)))
                return(ENXIO);
 
        /*******************************************************\
                return(ENXIO);
 
        /*******************************************************\
@@ -211,41 +271,53 @@ cdopen(dev)
        * disregard because the CDVALID flag is not yet set     *
        \*******************************************************/
        if (cd_req_sense(unit, SCSI_SILENT) != 0) {
        * disregard because the CDVALID flag is not yet set     *
        \*******************************************************/
        if (cd_req_sense(unit, SCSI_SILENT) != 0) {
+#ifdef CDDEBUG
                if(scsi_debug & TRACEOPENS)
                        printf("not reponding\n");
                if(scsi_debug & TRACEOPENS)
                        printf("not reponding\n");
+#endif /*CDDEBUG*/
                return(ENXIO);
        }
                return(ENXIO);
        }
+#ifdef CDDEBUG
        if(scsi_debug & TRACEOPENS)
                printf("Device present\n");
        if(scsi_debug & TRACEOPENS)
                printf("Device present\n");
+#endif /*CDDEBUG*/
        /*******************************************************\
        * In case it is a funny one, tell it to start           *
        * not needed for hard drives                            *
        \*******************************************************/
        cd_start_unit(unit,part,CD_START);
         cd_prevent_unit(unit,PR_PREVENT,SCSI_SILENT);
        /*******************************************************\
        * In case it is a funny one, tell it to start           *
        * not needed for hard drives                            *
        \*******************************************************/
        cd_start_unit(unit,part,CD_START);
         cd_prevent_unit(unit,PR_PREVENT,SCSI_SILENT);
+#ifdef CDDEBUG
        if(scsi_debug & TRACEOPENS)
                printf("started ");
        if(scsi_debug & TRACEOPENS)
                printf("started ");
+#endif /*CDDEBUG*/
        /*******************************************************\
        * Load the physical device parameters                   *
        \*******************************************************/
        cd_get_parms(unit, 0);
        /*******************************************************\
        * Load the physical device parameters                   *
        \*******************************************************/
        cd_get_parms(unit, 0);
+#ifdef CDDEBUG
        if(scsi_debug & TRACEOPENS)
                printf("Params loaded ");
        if(scsi_debug & TRACEOPENS)
                printf("Params loaded ");
+#endif /*CDDEBUG*/
        /*******************************************************\
        * Load the partition info if not already loaded         *
        \*******************************************************/
        cdgetdisklabel(unit);
        /*******************************************************\
        * Load the partition info if not already loaded         *
        \*******************************************************/
        cdgetdisklabel(unit);
+#ifdef CDDEBUG
        if(scsi_debug & TRACEOPENS)
                printf("Disklabel fabricated ");
        if(scsi_debug & TRACEOPENS)
                printf("Disklabel fabricated ");
+#endif /*CDDEBUG*/
        /*******************************************************\
        * Check the partition is legal                          *
        \*******************************************************/
        if (( part >= cd->disklabel.d_npartitions ) 
                && (part != RAW_PART))
        {
        /*******************************************************\
        * Check the partition is legal                          *
        \*******************************************************/
        if (( part >= cd->disklabel.d_npartitions ) 
                && (part != RAW_PART))
        {
+#ifdef CDDEBUG
                if(scsi_debug & TRACEOPENS)
                        printf("partition %d > %d\n",part
                                ,cd->disklabel.d_npartitions);
                if(scsi_debug & TRACEOPENS)
                        printf("partition %d > %d\n",part
                                ,cd->disklabel.d_npartitions);
+#endif /*CDDEBUG*/
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
                return(ENXIO);
        }
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
                return(ENXIO);
        }
@@ -257,14 +329,18 @@ cdopen(dev)
        {
                cd->partflags[part] |= CDOPEN;
                cd->openparts |= (1 << part);
        {
                cd->partflags[part] |= CDOPEN;
                cd->openparts |= (1 << part);
+#ifdef CDDEBUG
                if(scsi_debug & TRACEOPENS)
                        printf("open complete\n");
                if(scsi_debug & TRACEOPENS)
                        printf("open complete\n");
+#endif /*CDDEBUG*/
                cd->flags |= CDVALID;
        }
        else
        {
                cd->flags |= CDVALID;
        }
        else
        {
+#ifdef CDDEBUG
                if(scsi_debug & TRACEOPENS)
                        printf("part %d type UNUSED\n",part);
                if(scsi_debug & TRACEOPENS)
                        printf("part %d type UNUSED\n",part);
+#endif /*CDDEBUG*/
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
                return(ENXIO);
        }
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
                return(ENXIO);
        }
@@ -280,26 +356,28 @@ int       flags;
 int    unit;
 {
        struct scsi_xfer *xs;
 int    unit;
 {
        struct scsi_xfer *xs;
+       struct cd_data *cd;
        int     s;
 
        int     s;
 
+       cd = cd_driver->cd_data[unit];
        if(flags & (SCSI_NOSLEEP |  SCSI_NOMASK))
        {
        if(flags & (SCSI_NOSLEEP |  SCSI_NOMASK))
        {
-               if (xs = cd_free_xfer[unit])
+               if (xs = cd->free_xfer)
                {
                {
-                       cd_free_xfer[unit] = xs->next;
+                       cd->free_xfer = xs->next;
                        xs->flags = 0;
                }
        }
        else
        {
                s = SPLCD();
                        xs->flags = 0;
                }
        }
        else
        {
                s = SPLCD();
-               while (!(xs = cd_free_xfer[unit]))
+               while (!(xs = cd->free_xfer))
                {
                {
-                       cd_xfer_block_wait[unit]++;  /* someone waiting! */
-                       sleep((caddr_t)&cd_free_xfer[unit], PRIBIO+1);
-                       cd_xfer_block_wait[unit]--;
+                       cd->xfer_block_wait++;  /* someone waiting! */
+                       sleep((caddr_t)&cd->free_xfer, PRIBIO+1);
+                       cd->xfer_block_wait--;
                }
                }
-               cd_free_xfer[unit] = xs->next;
+               cd->free_xfer = xs->next;
                splx(s);
                xs->flags = 0;
        }
                splx(s);
                xs->flags = 0;
        }
@@ -314,25 +392,27 @@ struct scsi_xfer *xs;
 int    unit;
 int    flags;
 {
 int    unit;
 int    flags;
 {
+       struct cd_data *cd;
        int     s;
        
        int     s;
        
+       cd = cd_driver->cd_data[unit];
        if(flags & SCSI_NOMASK)
        {
        if(flags & SCSI_NOMASK)
        {
-               if (cd_xfer_block_wait[unit])
+               if (cd->xfer_block_wait)
                {
                        printf("cd%d: doing a wakeup from NOMASK mode\n", unit);
                {
                        printf("cd%d: doing a wakeup from NOMASK mode\n", unit);
-                       wakeup((caddr_t)&cd_free_xfer[unit]);
+                       wakeup((caddr_t)&cd->free_xfer);
                }
                }
-               xs->next = cd_free_xfer[unit];
-               cd_free_xfer[unit] = xs;
+               xs->next = cd->free_xfer;
+               cd->free_xfer = xs;
        }
        else
        {
                s = SPLCD();
        }
        else
        {
                s = SPLCD();
-               if (cd_xfer_block_wait[unit])
-                       wakeup((caddr_t)&cd_free_xfer[unit]);
-               xs->next = cd_free_xfer[unit];
-               cd_free_xfer[unit] = xs;
+               if (cd->xfer_block_wait)
+                       wakeup((caddr_t)&cd->free_xfer);
+               xs->next = cd->free_xfer;
+               cd->free_xfer = xs;
                splx(s);
        }
 }
                splx(s);
        }
 }
@@ -347,7 +427,7 @@ int flags;
 void   cdminphys(bp)
 struct buf     *bp;
 {
 void   cdminphys(bp)
 struct buf     *bp;
 {
-       (*(cd_data[UNIT(bp->b_dev)].sc_sw->scsi_minphys))(bp);
+       (*(cd_driver->cd_data[UNIT(bp->b_dev)]->sc_sw->scsi_minphys))(bp);
 }
 
 /*******************************************************\
 }
 
 /*******************************************************\
@@ -362,15 +442,17 @@ struct    buf     *bp;
 {
        struct  buf     *dp;
        unsigned int opri;
 {
        struct  buf     *dp;
        unsigned int opri;
-       struct cd_data *cd ;
+       struct cd_data *cd;
        int     unit;
 
        cdstrats++;
        unit = UNIT((bp->b_dev));
        int     unit;
 
        cdstrats++;
        unit = UNIT((bp->b_dev));
-       cd = cd_data + unit;
+       cd = cd_driver->cd_data[unit];
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("\ncdstrategy ");
        if(scsi_debug & SHOWREQUESTS) printf("cd%d: %d bytes @ blk%d\n",
                                        unit,bp->b_bcount,bp->b_blkno);
        if(scsi_debug & PRINTROUTINES) printf("\ncdstrategy ");
        if(scsi_debug & SHOWREQUESTS) printf("cd%d: %d bytes @ blk%d\n",
                                        unit,bp->b_bcount,bp->b_blkno);
+#endif /*CDDEBUG*/
        cdminphys(bp);
        /*******************************************************\
        * If the device has been made invalid, error out        *
        cdminphys(bp);
        /*******************************************************\
        * If the device has been made invalid, error out        *
@@ -415,7 +497,7 @@ struct      buf     *bp;
        }
 
        opri = SPLCD();
        }
 
        opri = SPLCD();
-       dp = &cd_buf_queue[unit];
+       dp = &cd->buf_queue;
 
        /*******************************************************\
        * Place it in the queue of disk activities for this disk*
 
        /*******************************************************\
        * Place it in the queue of disk activities for this disk*
@@ -466,26 +548,29 @@ int       unit;
        struct  scsi_xfer       *xs;
        struct  scsi_rw_big     cmd;
        int                     blkno, nblk;
        struct  scsi_xfer       *xs;
        struct  scsi_rw_big     cmd;
        int                     blkno, nblk;
-       struct cd_data *cd = cd_data + unit;
+       struct cd_data *cd;
        struct partition *p ;
 
        struct partition *p ;
 
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("cdstart%d ",unit);
        if(scsi_debug & PRINTROUTINES) printf("cdstart%d ",unit);
+#endif /*CDDEBUG*/
+       cd = cd_driver->cd_data[unit];
        /*******************************************************\
        * See if there is a buf to do and we are not already    *
        * doing one                                             *
        \*******************************************************/
        /*******************************************************\
        * See if there is a buf to do and we are not already    *
        * doing one                                             *
        \*******************************************************/
-       if(!cd_free_xfer[unit])
+       if(!cd->free_xfer)
        {
                return;    /* none for us, unit already underway */
        }
 
        {
                return;    /* none for us, unit already underway */
        }
 
-       if(cd_xfer_block_wait[unit])    /* there is one, but a special waits */
+       if(cd->xfer_block_wait)    /* there is one, but a special waits */
        {
                return; /* give the special that's waiting a chance to run */
        }
 
 
        {
                return; /* give the special that's waiting a chance to run */
        }
 
 
-       dp = &cd_buf_queue[unit];
+       dp = &cd->buf_queue;
        if ((bp = dp->b_actf) != NULL)  /* yes, an assign */
        {
                dp->b_actf = bp->av_forw;
        if ((bp = dp->b_actf) != NULL)  /* yes, an assign */
        {
                dp->b_actf = bp->av_forw;
@@ -574,8 +659,12 @@ struct     scsi_xfer       *xs;
 {
        struct  buf             *bp;
        int     retval;
 {
        struct  buf             *bp;
        int     retval;
+       struct cd_data *cd;
 
 
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("cd_done%d ",unit);
        if(scsi_debug & PRINTROUTINES) printf("cd_done%d ",unit);
+#endif /*CDDEBUG*/
+       cd = cd_driver->cd_data[unit];
        if (! (xs->flags & INUSE))      /* paranoia always pays off */
                panic("scsi_xfer not in use!");
        if(bp = xs->bp)
        if (! (xs->flags & INUSE))      /* paranoia always pays off */
                panic("scsi_xfer not in use!");
        if(bp = xs->bp)
@@ -608,7 +697,7 @@ struct      scsi_xfer       *xs;
                        {
                                xs->error = XS_NOERROR;
                                xs->flags &= ~ITSDONE;
                        {
                                xs->error = XS_NOERROR;
                                xs->flags &= ~ITSDONE;
-                               if ( (*(cd_data[unit].sc_sw->scsi_cmd))(xs)
+                               if ((*(cd->sc_sw->scsi_cmd))(xs)
                                        == SUCCESSFULLY_QUEUED)
                                {       /* shhh! don't wake the job, ok? */
                                        /* don't tell cdstart either, */
                                        == SUCCESSFULLY_QUEUED)
                                {       /* shhh! don't wake the job, ok? */
                                        /* don't tell cdstart either, */
@@ -651,13 +740,15 @@ cdioctl(dev_t dev, int cmd, caddr_t addr, int flag)
        \*******************************************************/
        unit = UNIT(dev);
        part = PARTITION(dev);
        \*******************************************************/
        unit = UNIT(dev);
        part = PARTITION(dev);
-       cd = &cd_data[unit];
+       cd = cd_driver->cd_data[unit];
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("cdioctl%d ",unit);
        if(scsi_debug & PRINTROUTINES) printf("cdioctl%d ",unit);
+#endif /*CDDEBUG*/
 
        /*******************************************************\
        * If the device is not valid.. abandon ship             *
        \*******************************************************/
 
        /*******************************************************\
        * If the device is not valid.. abandon ship             *
        \*******************************************************/
-       if (!(cd_data[unit].flags & CDVALID))
+       if (!(cd_driver->cd_data[unit]->flags & CDVALID))
                return(EIO);
        switch(cmd)
        {
                return(EIO);
        switch(cmd)
        {
@@ -961,10 +1052,11 @@ unsigned char    unit;
        /*unsigned int n, m;*/
        char *errstring;
        struct dos_partition *dos_partition_p;
        /*unsigned int n, m;*/
        char *errstring;
        struct dos_partition *dos_partition_p;
-       struct cd_data *cd = cd_data + unit;
+       struct cd_data *cd;
 
 
+       cd = cd_driver->cd_data[unit];
        /*******************************************************\
        /*******************************************************\
-       * If the inflo is already loaded, use it                *
+       * If the info is already loaded, use it                 *
        \*******************************************************/
        if(cd->flags & CDHAVELABEL) return;
 
        \*******************************************************/
        if(cd->flags & CDHAVELABEL) return;
 
@@ -1043,9 +1135,11 @@ cd_size(unit, flags)
                blksize += rdcap.length_2 << 16;
                blksize += rdcap.length_3 << 24;
        }
                blksize += rdcap.length_2 << 16;
                blksize += rdcap.length_3 << 24;
        }
+#ifdef CDDEBUG
        if(cd_debug)printf("cd%d: %d %d byte blocks\n",unit,size,blksize);
        if(cd_debug)printf("cd%d: %d %d byte blocks\n",unit,size,blksize);
-       cd_data[unit].params.disksize = size;
-       cd_data[unit].params.blksize = blksize;
+#endif /*CDDEBUG*/
+       cd_driver->cd_data[unit]->params.disksize = size;
+       cd_driver->cd_data[unit]->params.blksize = blksize;
        return(size);
 }
        
        return(size);
 }
        
@@ -1262,7 +1356,7 @@ cd_start_unit(unit,part,type)
 {
        struct scsi_start_stop scsi_cmd;
 
 {
        struct scsi_start_stop scsi_cmd;
 
-        if(type==CD_EJECT && (cd_data[unit].openparts&~(1<<part)) == 0 ) {
+        if(type==CD_EJECT && (cd_driver->cd_data[unit]->openparts&~(1<<part)) == 0 ) {
                cd_prevent_unit(unit,CD_EJECT,0);
        }
 
                cd_prevent_unit(unit,CD_EJECT,0);
        }
 
@@ -1290,7 +1384,7 @@ int     unit,type,flags;
 {
         struct  scsi_prevent    scsi_cmd;
 
 {
         struct  scsi_prevent    scsi_cmd;
 
-        if(type==CD_EJECT || type==PR_PREVENT || cd_data[unit].openparts == 0 ) {
+        if(type==CD_EJECT || type==PR_PREVENT || cd_driver->cd_data[unit]->openparts == 0 ) {
                 bzero(&scsi_cmd, sizeof(scsi_cmd));
                 scsi_cmd.op_code = PREVENT_ALLOW;
                 scsi_cmd.how = (type==CD_EJECT)?PR_ALLOW:type;
                 bzero(&scsi_cmd, sizeof(scsi_cmd));
                 scsi_cmd.op_code = PREVENT_ALLOW;
                 scsi_cmd.how = (type==CD_EJECT)?PR_ALLOW:type;
@@ -1383,7 +1477,7 @@ struct cd_toc_entry *data;
 
 int    cd_get_parms(unit, flags)
 {
 
 int    cd_get_parms(unit, flags)
 {
-       struct cd_data *cd = cd_data + unit;
+       struct cd_data *cd = cd_driver->cd_data[unit];
 
        /*******************************************************\
        * First check if we have it all loaded                  *
 
        /*******************************************************\
        * First check if we have it all loaded                  *
@@ -1416,10 +1510,12 @@ dev_t dev;
 
        unit = UNIT(dev);
        part = PARTITION(dev);
 
        unit = UNIT(dev);
        part = PARTITION(dev);
+#ifdef CDDEBUG
        if(scsi_debug & TRACEOPENS)
        if(scsi_debug & TRACEOPENS)
-               printf("closing cd%d part %d\n",unit,part);
-       cd_data[unit].partflags[part] &= ~CDOPEN;
-       cd_data[unit].openparts &= ~(1 << part);
+               printf("cd%d: closing part %d\n",unit,part);
+#endif
+       cd_driver->cd_data[unit]->partflags[part] &= ~CDOPEN;
+       cd_driver->cd_data[unit]->openparts &= ~(1 << part);
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
        return(0);
 }
                cd_prevent_unit(unit,PR_ALLOW,SCSI_SILENT);
        return(0);
 }
@@ -1445,9 +1541,11 @@ int      datalen;
        struct  scsi_xfer *xs;
        int     retval;
        int     s;
        struct  scsi_xfer *xs;
        int     retval;
        int     s;
-       struct cd_data *cd = cd_data + unit;
+       struct cd_data *cd = cd_driver->cd_data[unit];
 
 
+#ifdef CDDEBUG
        if(scsi_debug & PRINTROUTINES) printf("\ncd_scsi_cmd%d ",unit);
        if(scsi_debug & PRINTROUTINES) printf("\ncd_scsi_cmd%d ",unit);
+#endif /*CDDEBUG*/
        if(cd->sc_sw)   /* If we have a scsi driver */
        {
                xs = cd_get_xs(unit,flags); /* should wait unless booting */
        if(cd->sc_sw)   /* If we have a scsi driver */
        {
                xs = cd_get_xs(unit,flags); /* should wait unless booting */
@@ -1617,8 +1715,8 @@ struct    scsi_xfer *xs;
                        return(EINVAL);
                case    0x6:
                        if(!silent)printf("cd%d: Unit attention\n", unit); 
                        return(EINVAL);
                case    0x6:
                        if(!silent)printf("cd%d: Unit attention\n", unit); 
-                       if (cd_data[unit].openparts)
-                       cd_data[unit].flags &= ~(CDVALID | CDHAVELABEL);
+                       if (cd_driver->cd_data[unit]->openparts)
+                       cd_driver->cd_data[unit]->flags &= ~(CDVALID | CDHAVELABEL);
                        {
                                return(EIO);
                        }
                        {
                                return(EIO);
                        }