[PATCH] mark struct file_operations const 6
[safe/jmp/linux-2.6] / drivers / scsi / ch.c
index 3900e28..d02759f 100644 (file)
@@ -7,7 +7,6 @@
 
 #define VERSION "0.25"
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
 #include <linux/blkdev.h>
 #include <linux/completion.h>
-#include <linux/devfs_fs_kernel.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>
@@ -31,7 +29,7 @@
 #include <scsi/scsi_ioctl.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_device.h>
-#include <scsi/scsi_request.h>
+#include <scsi/scsi_eh.h>
 #include <scsi/scsi_dbg.h>
 
 #define CH_DT_MAX       16
@@ -40,6 +38,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);
@@ -76,7 +75,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);
@@ -113,11 +112,11 @@ 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);
-static spinlock_t ch_devlist_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(ch_devlist_lock);
 static int ch_devcount;
 
 static struct scsi_driver ch_template =
@@ -130,7 +129,7 @@ static struct scsi_driver ch_template =
        },
 };
 
-static struct file_operations changer_fops =
+static const struct file_operations changer_fops =
 {
        .owner        = THIS_MODULE,
        .open         = ch_open,
@@ -141,7 +140,7 @@ static struct file_operations changer_fops =
 #endif
 };
 
-static struct {
+static const struct {
        unsigned char  sense;
        unsigned char  asc;
        unsigned char  ascq;
@@ -181,17 +180,17 @@ static struct {
 
 /* ------------------------------------------------------------------- */
 
-static int ch_find_errno(unsigned char *sense_buffer)
+static int ch_find_errno(struct scsi_sense_hdr *sshdr)
 {
        int i,errno = 0;
 
        /* Check to see if additional sense information is available */
-       if (sense_buffer[7]  > 5 &&
-           sense_buffer[12] != 0) {
+       if (scsi_sense_valid(sshdr) &&
+           sshdr->asc != 0) {
                for (i = 0; err[i].errno != 0; i++) {
-                       if (err[i].sense == sense_buffer[ 2] &&
-                           err[i].asc   == sense_buffer[12] &&
-                           err[i].ascq  == sense_buffer[13]) {
+                       if (err[i].sense == sshdr->sense_key &&
+                           err[i].asc   == sshdr->asc &&
+                           err[i].ascq  == sshdr->ascq) {
                                errno = -err[i].errno;
                                break;
                        }
@@ -207,13 +206,9 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
           void *buffer, unsigned buflength,
           enum dma_data_direction direction)
 {
-       int errno, retries = 0, timeout;
-       struct scsi_request *sr;
+       int errno, retries = 0, timeout, result;
+       struct scsi_sense_hdr sshdr;
        
-       sr = scsi_allocate_request(ch->device, GFP_KERNEL);
-       if (NULL == sr)
-               return -ENOMEM;
-
        timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
                ? timeout_init : timeout_move;
 
@@ -224,16 +219,17 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
                __scsi_print_command(cmd);
        }
 
-        scsi_wait_req(sr, cmd, buffer, buflength,
-                     timeout * HZ, MAX_RETRIES);
+        result = scsi_execute_req(ch->device, cmd, direction, buffer,
+                                 buflength, &sshdr, timeout * HZ,
+                                 MAX_RETRIES);
 
-       dprintk("result: 0x%x\n",sr->sr_result);
-       if (driver_byte(sr->sr_result) & DRIVER_SENSE) {
+       dprintk("result: 0x%x\n",result);
+       if (driver_byte(result) & DRIVER_SENSE) {
                if (debug)
-                       scsi_print_req_sense(ch->name, sr);
-               errno = ch_find_errno(sr->sr_sense_buffer);
+                       scsi_print_sense_hdr(ch->name, &sshdr);
+               errno = ch_find_errno(&sshdr);
 
-               switch(sr->sr_sense_buffer[2] & 0xf) {
+               switch(sshdr.sense_key) {
                case UNIT_ATTENTION:
                        ch->unit_attention = 1;
                        if (retries++ < 3)
@@ -241,7 +237,6 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
                        break;
                }
        }
-       scsi_release_request(sr);
        return errno;
 }
 
@@ -565,13 +560,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)) {
@@ -588,7 +583,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;
 }
 
@@ -639,6 +634,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:
@@ -651,7 +647,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;
        }
@@ -676,7 +672,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;
        }
@@ -685,18 +681,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;
        }
        
@@ -704,7 +700,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) ||
@@ -713,12 +709,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;
        }
 
@@ -726,7 +722,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 ) ||
@@ -736,14 +732,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;
        }
 
@@ -751,7 +747,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;
@@ -767,7 +763,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))
@@ -777,7 +773,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));
@@ -828,18 +824,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;
        }
                
@@ -848,7 +844,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)) {
@@ -856,17 +852,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);
 
        }
 }
@@ -899,9 +895,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;
@@ -934,21 +930,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);
 
-       devfs_mk_cdev(MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
-                     S_IFCHR | S_IRUGO | S_IWUGO, ch->name);
-       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);
@@ -974,7 +966,6 @@ static int ch_remove(struct device *dev)
 
        class_device_destroy(ch_sysfs_class,
                             MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
-       devfs_remove(ch->name);
        kfree(ch->dt);
        kfree(ch);
        ch_devcount--;