]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/scsi_lib.c
[SCSI] qla2xxx: Correct issue where the rport's upcall was not being made after relogin.
[linux-2.6-omap-h63xx.git] / drivers / scsi / scsi_lib.c
index eb0cfbfbcf8f30daa252181de9eb6e88eeca4e67..3574ba935af8ea451741de17ae26b4e77087fe68 100644 (file)
@@ -259,6 +259,7 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
        memcpy(req->cmd, cmd, req->cmd_len);
        req->sense = sense;
        req->sense_len = 0;
+       req->retries = retries;
        req->timeout = timeout;
        req->flags |= flags | REQ_BLOCK_PC | REQ_SPECIAL | REQ_QUIET;
 
@@ -305,14 +306,16 @@ struct scsi_io_context {
        char sense[SCSI_SENSE_BUFFERSIZE];
 };
 
-static void scsi_end_async(struct request *req)
+static kmem_cache_t *scsi_io_context_cache;
+
+static void scsi_end_async(struct request *req, int uptodate)
 {
        struct scsi_io_context *sioc = req->end_io_data;
 
        if (sioc->done)
                sioc->done(sioc->data, sioc->sense, req->errors, req->data_len);
 
-       kfree(sioc);
+       kmem_cache_free(scsi_io_context_cache, sioc);
        __blk_put_request(req->q, req);
 }
 
@@ -451,13 +454,15 @@ int scsi_execute_async(struct scsi_device *sdev, const unsigned char *cmd,
        int err = 0;
        int write = (data_direction == DMA_TO_DEVICE);
 
-       sioc = kzalloc(sizeof(*sioc), gfp);
+       sioc = kmem_cache_alloc(scsi_io_context_cache, gfp);
        if (!sioc)
                return DRIVER_ERROR << 24;
+       memset(sioc, 0, sizeof(*sioc));
 
        req = blk_get_request(sdev->request_queue, write, gfp);
        if (!req)
                goto free_sense;
+       req->flags |= REQ_BLOCK_PC | REQ_QUIET;
 
        if (use_sg)
                err = scsi_req_map_sg(req, buffer, use_sg, bufflen, gfp);
@@ -472,7 +477,7 @@ int scsi_execute_async(struct scsi_device *sdev, const unsigned char *cmd,
        req->sense = sioc->sense;
        req->sense_len = 0;
        req->timeout = timeout;
-       req->flags |= REQ_BLOCK_PC | REQ_QUIET;
+       req->retries = retries;
        req->end_io_data = sioc;
 
        sioc->data = privdata;
@@ -786,7 +791,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate,
        spin_lock_irqsave(q->queue_lock, flags);
        if (blk_rq_tagged(req))
                blk_queue_end_tag(q, req);
-       end_that_request_last(req);
+       end_that_request_last(req, uptodate);
        spin_unlock_irqrestore(q->queue_lock, flags);
 
        /*
@@ -927,9 +932,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
        int sense_valid = 0;
        int sense_deferred = 0;
 
-       if (blk_complete_barrier_rq(q, req, good_bytes >> 9))
-               return;
-
        /*
         * Free up any indirection buffers we allocated for DMA purposes. 
         * For the case of a READ, we need to copy the data out of the
@@ -1194,38 +1196,6 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
        return BLKPREP_KILL;
 }
 
-static int scsi_prepare_flush_fn(request_queue_t *q, struct request *rq)
-{
-       struct scsi_device *sdev = q->queuedata;
-       struct scsi_driver *drv;
-
-       if (sdev->sdev_state == SDEV_RUNNING) {
-               drv = *(struct scsi_driver **) rq->rq_disk->private_data;
-
-               if (drv->prepare_flush)
-                       return drv->prepare_flush(q, rq);
-       }
-
-       return 0;
-}
-
-static void scsi_end_flush_fn(request_queue_t *q, struct request *rq)
-{
-       struct scsi_device *sdev = q->queuedata;
-       struct request *flush_rq = rq->end_io_data;
-       struct scsi_driver *drv;
-
-       if (flush_rq->errors) {
-               printk("scsi: barrier error, disabling flush support\n");
-               blk_queue_ordered(q, QUEUE_ORDERED_NONE);
-       }
-
-       if (sdev->sdev_state == SDEV_RUNNING) {
-               drv = *(struct scsi_driver **) rq->rq_disk->private_data;
-               drv->end_flush(q, rq);
-       }
-}
-
 static int scsi_issue_flush_fn(request_queue_t *q, struct gendisk *disk,
                               sector_t *error_sector)
 {
@@ -1242,10 +1212,36 @@ static int scsi_issue_flush_fn(request_queue_t *q, struct gendisk *disk,
        return -EOPNOTSUPP;
 }
 
-static void scsi_generic_done(struct scsi_cmnd *cmd)
+static void scsi_blk_pc_done(struct scsi_cmnd *cmd)
 {
        BUG_ON(!blk_pc_request(cmd->request));
-       scsi_io_completion(cmd, cmd->result == 0 ? cmd->bufflen : 0, 0);
+       /*
+        * This will complete the whole command with uptodate=1 so
+        * as far as the block layer is concerned the command completed
+        * successfully. Since this is a REQ_BLOCK_PC command the
+        * caller should check the request's errors value
+        */
+       scsi_io_completion(cmd, cmd->bufflen, 0);
+}
+
+static void scsi_setup_blk_pc_cmnd(struct scsi_cmnd *cmd)
+{
+       struct request *req = cmd->request;
+
+       BUG_ON(sizeof(req->cmd) > sizeof(cmd->cmnd));
+       memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
+       cmd->cmd_len = req->cmd_len;
+       if (!req->data_len)
+               cmd->sc_data_direction = DMA_NONE;
+       else if (rq_data_dir(req) == WRITE)
+               cmd->sc_data_direction = DMA_TO_DEVICE;
+       else
+               cmd->sc_data_direction = DMA_FROM_DEVICE;
+       
+       cmd->transfersize = req->data_len;
+       cmd->allowed = req->retries;
+       cmd->timeout_per_command = req->timeout;
+       cmd->done = scsi_blk_pc_done;
 }
 
 static int scsi_prep_fn(struct request_queue *q, struct request *req)
@@ -1343,7 +1339,6 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
         * happening now.
         */
        if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) {
-               struct scsi_driver *drv;
                int ret;
 
                /*
@@ -1375,27 +1370,17 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
                /*
                 * Initialize the actual SCSI command for this request.
                 */
-               if (req->rq_disk) {
+               if (req->flags & REQ_BLOCK_PC) {
+                       scsi_setup_blk_pc_cmnd(cmd);
+               } else if (req->rq_disk) {
+                       struct scsi_driver *drv;
+
                        drv = *(struct scsi_driver **)req->rq_disk->private_data;
                        if (unlikely(!drv->init_command(cmd))) {
                                scsi_release_buffers(cmd);
                                scsi_put_command(cmd);
                                goto kill;
                        }
-               } else {
-                       memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
-                       cmd->cmd_len = req->cmd_len;
-                       if (rq_data_dir(req) == WRITE)
-                               cmd->sc_data_direction = DMA_TO_DEVICE;
-                       else if (req->data_len)
-                               cmd->sc_data_direction = DMA_FROM_DEVICE;
-                       else
-                               cmd->sc_data_direction = DMA_NONE;
-                       
-                       cmd->transfersize = req->data_len;
-                       cmd->allowed = 3;
-                       cmd->timeout_per_command = req->timeout;
-                       cmd->done = scsi_generic_done;
                }
        }
 
@@ -1508,6 +1493,41 @@ static void scsi_kill_request(struct request *req, request_queue_t *q)
        __scsi_done(cmd);
 }
 
+static void scsi_softirq_done(struct request *rq)
+{
+       struct scsi_cmnd *cmd = rq->completion_data;
+       unsigned long wait_for = cmd->allowed * cmd->timeout_per_command;
+       int disposition;
+
+       INIT_LIST_HEAD(&cmd->eh_entry);
+
+       disposition = scsi_decide_disposition(cmd);
+       if (disposition != SUCCESS &&
+           time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) {
+               sdev_printk(KERN_ERR, cmd->device,
+                           "timing out command, waited %lus\n",
+                           wait_for/HZ);
+               disposition = SUCCESS;
+       }
+                       
+       scsi_log_completion(cmd, disposition);
+
+       switch (disposition) {
+               case SUCCESS:
+                       scsi_finish_command(cmd);
+                       break;
+               case NEEDS_RETRY:
+                       scsi_retry_command(cmd);
+                       break;
+               case ADD_TO_MLQUEUE:
+                       scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
+                       break;
+               default:
+                       if (!scsi_eh_scmd_add(cmd, 0))
+                               scsi_finish_command(cmd);
+       }
+}
+
 /*
  * Function:    scsi_request_fn()
  *
@@ -1682,17 +1702,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
        blk_queue_bounce_limit(q, scsi_calculate_bounce_limit(shost));
        blk_queue_segment_boundary(q, shost->dma_boundary);
        blk_queue_issue_flush_fn(q, scsi_issue_flush_fn);
-
-       /*
-        * ordered tags are superior to flush ordering
-        */
-       if (shost->ordered_tag)
-               blk_queue_ordered(q, QUEUE_ORDERED_TAG);
-       else if (shost->ordered_flush) {
-               blk_queue_ordered(q, QUEUE_ORDERED_FLUSH);
-               q->prepare_flush_fn = scsi_prepare_flush_fn;
-               q->end_flush_fn = scsi_end_flush_fn;
-       }
+       blk_queue_softirq_done(q, scsi_softirq_done);
 
        if (!shost->use_clustering)
                clear_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
@@ -1757,6 +1767,14 @@ int __init scsi_init_queue(void)
 {
        int i;
 
+       scsi_io_context_cache = kmem_cache_create("scsi_io_context",
+                                       sizeof(struct scsi_io_context),
+                                       0, 0, NULL, NULL);
+       if (!scsi_io_context_cache) {
+               printk(KERN_ERR "SCSI: can't init scsi io context cache\n");
+               return -ENOMEM;
+       }
+
        for (i = 0; i < SG_MEMPOOL_NR; i++) {
                struct scsi_host_sg_pool *sgp = scsi_sg_pools + i;
                int size = sgp->size * sizeof(struct scatterlist);
@@ -1784,6 +1802,8 @@ void scsi_exit_queue(void)
 {
        int i;
 
+       kmem_cache_destroy(scsi_io_context_cache);
+
        for (i = 0; i < SG_MEMPOOL_NR; i++) {
                struct scsi_host_sg_pool *sgp = scsi_sg_pools + i;
                mempool_destroy(sgp->pool);