Don't include linux/config.h from anywhere else in include/
[safe/jmp/linux-2.6] / drivers / scsi / ch.c
index 13ecd0c..d9abd16 100644 (file)
@@ -20,9 +20,9 @@
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/completion.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/chio.h>                        /* here are all the ioctls */
+#include <linux/mutex.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -39,6 +39,7 @@
 MODULE_DESCRIPTION("device driver for scsi media changer devices");
 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org>");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR);
 
 static int init = 1;
 module_param(init, int, 0444);
@@ -75,7 +76,7 @@ static int vendor_counts[CH_TYPES-4];
 module_param_array(vendor_firsts, int, NULL, 0444);
 module_param_array(vendor_counts, int, NULL, 0444);
 
-static char *vendor_labels[CH_TYPES-4] = {
+static const char * vendor_labels[CH_TYPES-4] = {
        "v0", "v1", "v2", "v3"
 };
 // module_param_string_array(vendor_labels, NULL, 0444);
@@ -112,7 +113,7 @@ typedef struct {
        u_int               counts[CH_TYPES];
        u_int               unit_attention;
        u_int               voltags;
-       struct semaphore    lock;
+       struct mutex        lock;
 } scsi_changer;
 
 static LIST_HEAD(ch_devlist);
@@ -140,7 +141,7 @@ static struct file_operations changer_fops =
 #endif
 };
 
-static struct {
+static const struct {
        unsigned char  sense;
        unsigned char  asc;
        unsigned char  ascq;
@@ -560,13 +561,13 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
        return result;
 }
 
-static int ch_gstatus(scsi_changer *ch, int type, unsigned char *dest)
+static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
 {
        int retval = 0;
        u_char data[16];
        unsigned int i;
        
-       down(&ch->lock);
+       mutex_lock(&ch->lock);
        for (i = 0; i < ch->counts[type]; i++) {
                if (0 != ch_read_element_status
                    (ch, ch->firsts[type]+i,data)) {
@@ -583,7 +584,7 @@ static int ch_gstatus(scsi_changer *ch, int type, unsigned char *dest)
                if (0 != retval)
                        break;
        }
-       up(&ch->lock);
+       mutex_unlock(&ch->lock);
        return retval;
 }
 
@@ -634,6 +635,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
 {
        scsi_changer *ch = file->private_data;
        int retval;
+       void __user *argp = (void __user *)arg;
        
        switch (cmd) {
        case CHIOGPARAMS:
@@ -646,7 +648,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                params.cp_nportals  = ch->counts[CHET_IE];
                params.cp_ndrives   = ch->counts[CHET_DT];
                
-               if (copy_to_user((void *) arg, &params, sizeof(params)))
+               if (copy_to_user(argp, &params, sizeof(params)))
                        return -EFAULT;
                return 0;
        }
@@ -671,7 +673,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                        vparams.cvp_n4  = ch->counts[CHET_V4];
                        strncpy(vparams.cvp_label4,vendor_labels[3],16);
                }
-               if (copy_to_user((void *) arg, &vparams, sizeof(vparams)))
+               if (copy_to_user(argp, &vparams, sizeof(vparams)))
                        return -EFAULT;
                return 0;
        }
@@ -680,18 +682,18 @@ static int ch_ioctl(struct inode * inode, struct file * file,
        {
                struct changer_position pos;
                
-               if (copy_from_user(&pos, (void*)arg, sizeof (pos)))
+               if (copy_from_user(&pos, argp, sizeof (pos)))
                        return -EFAULT;
 
                if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
                        dprintk("CHIOPOSITION: invalid parameter\n");
                        return -EBADSLT;
                }
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                retval = ch_position(ch,0,
                                     ch->firsts[pos.cp_type] + pos.cp_unit,
                                     pos.cp_flags & CP_INVERT);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                return retval;
        }
        
@@ -699,7 +701,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
        {
                struct changer_move mv;
 
-               if (copy_from_user(&mv, (void*)arg, sizeof (mv)))
+               if (copy_from_user(&mv, argp, sizeof (mv)))
                        return -EFAULT;
 
                if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
@@ -708,12 +710,12 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                        return -EBADSLT;
                }
                
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                retval = ch_move(ch,0,
                                 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit,
                                 ch->firsts[mv.cm_totype]   + mv.cm_tounit,
                                 mv.cm_flags & CM_INVERT);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                return retval;
        }
 
@@ -721,7 +723,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
        {
                struct changer_exchange mv;
                
-               if (copy_from_user(&mv, (void*)arg, sizeof (mv)))
+               if (copy_from_user(&mv, argp, sizeof (mv)))
                        return -EFAULT;
 
                if (0 != ch_checkrange(ch, mv.ce_srctype,  mv.ce_srcunit ) ||
@@ -731,14 +733,14 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                        return -EBADSLT;
                }
                
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                retval = ch_exchange
                        (ch,0,
                         ch->firsts[mv.ce_srctype]  + mv.ce_srcunit,
                         ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit,
                         ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit,
                         mv.ce_flags & CE_INVERT1, mv.ce_flags & CE_INVERT2);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                return retval;
        }
 
@@ -746,7 +748,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
        {
                struct changer_element_status ces;
                
-               if (copy_from_user(&ces, (void*)arg, sizeof (ces)))
+               if (copy_from_user(&ces, argp, sizeof (ces)))
                        return -EFAULT;
                if (ces.ces_type < 0 || ces.ces_type >= CH_TYPES)
                        return -EINVAL;
@@ -762,7 +764,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                unsigned int elem;
                int     result,i;
                
-               if (copy_from_user(&cge, (void*)arg, sizeof (cge)))
+               if (copy_from_user(&cge, argp, sizeof (cge)))
                        return -EFAULT;
 
                if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit))
@@ -772,7 +774,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
                if (!buffer)
                        return -ENOMEM;
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                
        voltag_retry:
                memset(cmd,0,sizeof(cmd));
@@ -823,18 +825,18 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                        goto voltag_retry;
                }
                kfree(buffer);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                
-               if (copy_to_user((void*)arg, &cge, sizeof (cge)))
+               if (copy_to_user(argp, &cge, sizeof (cge)))
                        return -EFAULT;
                return result;
        }
 
        case CHIOINITELEM:
        {
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                retval = ch_init_elem(ch);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                return retval;
        }
                
@@ -843,7 +845,7 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                struct changer_set_voltag csv;
                int elem;
 
-               if (copy_from_user(&csv, (void*)arg, sizeof(csv)))
+               if (copy_from_user(&csv, argp, sizeof(csv)))
                        return -EFAULT;
 
                if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
@@ -851,17 +853,17 @@ static int ch_ioctl(struct inode * inode, struct file * file,
                        return -EBADSLT;
                }
                elem = ch->firsts[csv.csv_type] + csv.csv_unit;
-               down(&ch->lock);
+               mutex_lock(&ch->lock);
                retval = ch_set_voltag(ch, elem,
                                       csv.csv_flags & CSV_AVOLTAG,
                                       csv.csv_flags & CSV_CLEARTAG,
                                       csv.csv_voltag);
-               up(&ch->lock);
+               mutex_unlock(&ch->lock);
                return retval;
        }
 
        default:
-               return scsi_ioctl(ch->device, cmd, (void*)arg);
+               return scsi_ioctl(ch->device, cmd, argp);
 
        }
 }
@@ -894,9 +896,9 @@ static long ch_ioctl_compat(struct file * file,
        case CHIOGSTATUS32:
        {
                struct changer_element_status32 ces32;
-               unsigned char *data;
+               unsigned char __user *data;
                
-               if (copy_from_user(&ces32, (void*)arg, sizeof (ces32)))
+               if (copy_from_user(&ces32, (void __user *)arg, sizeof (ces32)))
                        return -EFAULT;
                if (ces32.ces_type < 0 || ces32.ces_type >= CH_TYPES)
                        return -EINVAL;
@@ -929,19 +931,17 @@ static int ch_probe(struct device *dev)
        memset(ch,0,sizeof(*ch));
        ch->minor = ch_devcount;
        sprintf(ch->name,"ch%d",ch->minor);
-       init_MUTEX(&ch->lock);
+       mutex_init(&ch->lock);
        ch->device = sd;
        ch_readconfig(ch);
        if (init)
                ch_init_elem(ch);
 
-       class_device_create(ch_sysfs_class,
+       class_device_create(ch_sysfs_class, NULL,
                            MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
                            dev, "s%s", ch->name);
 
-       printk(KERN_INFO "Attached scsi changer %s "
-              "at scsi%d, channel %d, id %d, lun %d\n", 
-              ch->name, sd->host->host_no, sd->channel, sd->id, sd->lun);
+       sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name);
        
        spin_lock(&ch_devlist_lock);
        list_add_tail(&ch->list,&ch_devlist);