]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/scsi/st.c
Merge branch 'master'
[karo-tx-linux.git] / drivers / scsi / st.c
index 26e13dc7bcdb14090a7b3a4370609a002d353dae..7f96f33c1bb1c815b09f88c5458b556ce6c2fc81 100644 (file)
@@ -38,6 +38,7 @@ static const char *verstr = "20050830";
 #include <linux/devfs_fs_kernel.h>
 #include <linux/cdev.h>
 #include <linux/delay.h>
+#include <linux/mutex.h>
 
 #include <asm/uaccess.h>
 #include <asm/dma.h>
@@ -193,7 +194,6 @@ static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
 
 static int st_probe(struct device *);
 static int st_remove(struct device *);
-static int st_init_command(struct scsi_cmnd *);
 
 static void do_create_driverfs_files(void);
 static void do_remove_driverfs_files(void);
@@ -206,7 +206,6 @@ static struct scsi_driver st_template = {
                .probe          = st_probe,
                .remove         = st_remove,
        },
-       .init_command           = st_init_command,
 };
 
 static int st_compression(struct scsi_tape *, int);
@@ -220,7 +219,7 @@ static void scsi_tape_release(struct kref *);
 
 #define to_scsi_tape(obj) container_of(obj, struct scsi_tape, kref)
 
-static DECLARE_MUTEX(st_ref_sem);
+static DEFINE_MUTEX(st_ref_mutex);
 
 \f
 #include "osst_detect.h"
@@ -237,7 +236,7 @@ static struct scsi_tape *scsi_tape_get(int dev)
 {
        struct scsi_tape *STp = NULL;
 
-       down(&st_ref_sem);
+       mutex_lock(&st_ref_mutex);
        write_lock(&st_dev_arr_lock);
 
        if (dev < st_dev_max && scsi_tapes != NULL)
@@ -259,7 +258,7 @@ out_put:
        STp = NULL;
 out:
        write_unlock(&st_dev_arr_lock);
-       up(&st_ref_sem);
+       mutex_unlock(&st_ref_mutex);
        return STp;
 }
 
@@ -267,10 +266,10 @@ static void scsi_tape_put(struct scsi_tape *STp)
 {
        struct scsi_device *sdev = STp->device;
 
-       down(&st_ref_sem);
+       mutex_lock(&st_ref_mutex);
        kref_put(&STp->kref, scsi_tape_release);
        scsi_device_put(sdev);
-       up(&st_ref_sem);
+       mutex_unlock(&st_ref_mutex);
 }
 
 struct st_reject_data {
@@ -509,11 +508,13 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd
        STp->buffer->cmdstat.have_sense = 0;
        STp->buffer->syscall_result = 0;
 
-       if (scsi_execute_async(STp->device, cmd, direction,
+       if (scsi_execute_async(STp->device, cmd, COMMAND_SIZE(cmd[0]), direction,
                        &((STp->buffer)->sg[0]), bytes, (STp->buffer)->sg_segs,
-                       timeout, retries, SRpnt, st_sleep_done, GFP_KERNEL))
+                              timeout, retries, SRpnt, st_sleep_done, GFP_KERNEL)) {
                /* could not allocate the buffer or request was too large */
                (STp->buffer)->syscall_result = (-EBUSY);
+               (STp->buffer)->last_SRpnt = NULL;
+       }
        else if (do_wait) {
                wait_for_completion(waiting);
                SRpnt->waiting = NULL;
@@ -1449,14 +1450,15 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
 
 
 /* Can be called more than once after each setup_buffer() */
-static void release_buffering(struct scsi_tape *STp)
+static void release_buffering(struct scsi_tape *STp, int is_read)
 {
        struct st_buffer *STbp;
 
        STbp = STp->buffer;
        if (STbp->do_dio) {
-               sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, 0);
+               sgl_unmap_user_pages(&(STbp->sg[0]), STbp->do_dio, is_read);
                STbp->do_dio = 0;
+               STbp->sg_segs = 0;
        }
 }
 
@@ -1729,7 +1731,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
  out:
        if (SRpnt != NULL)
                st_release_request(SRpnt);
-       release_buffering(STp);
+       release_buffering(STp, 0);
        up(&STp->lock);
 
        return retval;
@@ -1787,7 +1789,7 @@ static long read_tape(struct scsi_tape *STp, long count,
        SRpnt = *aSRpnt;
        SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
                           STp->device->timeout, MAX_RETRIES, 1);
-       release_buffering(STp);
+       release_buffering(STp, 1);
        *aSRpnt = SRpnt;
        if (!SRpnt)
                return STbp->syscall_result;
@@ -2058,7 +2060,7 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
                SRpnt = NULL;
        }
        if (do_dio) {
-               release_buffering(STp);
+               release_buffering(STp, 1);
                STbp->buffer_bytes = 0;
        }
        up(&STp->lock);
@@ -4138,9 +4140,9 @@ static int st_remove(struct device *dev)
                                }
                        }
 
-                       down(&st_ref_sem);
+                       mutex_lock(&st_ref_mutex);
                        kref_put(&tpnt->kref, scsi_tape_release);
-                       up(&st_ref_sem);
+                       mutex_unlock(&st_ref_mutex);
                        return 0;
                }
        }
@@ -4153,7 +4155,7 @@ static int st_remove(struct device *dev)
  *      scsi_tape_release - Called to free the Scsi_Tape structure
  *      @kref: pointer to embedded kref
  *
- *      st_ref_sem must be held entering this routine.  Because it is
+ *      st_ref_mutex must be held entering this routine.  Because it is
  *      called on last put, you should always use the scsi_tape_get()
  *      scsi_tape_put() helpers which manipulate the semaphore directly
  *      and never do a direct kref_put().
@@ -4177,46 +4179,6 @@ static void scsi_tape_release(struct kref *kref)
        return;
 }
 
-static void st_intr(struct scsi_cmnd *SCpnt)
-{
-       /*
-        * The caller should be checking the request's errors
-        * value.
-        */
-       scsi_io_completion(SCpnt, SCpnt->bufflen, 0);
-}
-
-/*
- * st_init_command: only called via the scsi_cmd_ioctl (block SG_IO)
- * interface for REQ_BLOCK_PC commands.
- */
-static int st_init_command(struct scsi_cmnd *SCpnt)
-{
-       struct request *rq;
-
-       if (!(SCpnt->request->flags & REQ_BLOCK_PC))
-               return 0;
-
-       rq = SCpnt->request;
-       if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-               return 0;
-
-       memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-       SCpnt->cmd_len = rq->cmd_len;
-
-       if (rq_data_dir(rq) == WRITE)
-               SCpnt->sc_data_direction = DMA_TO_DEVICE;
-       else if (rq->data_len)
-               SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-       else
-               SCpnt->sc_data_direction = DMA_NONE;
-
-       SCpnt->timeout_per_command = rq->timeout;
-       SCpnt->transfersize = rq->data_len;
-       SCpnt->done = st_intr;
-       return 1;
-}
-
 static int __init init_st(void)
 {
        validate_options();