Merge branch 'master' into for_paulus
[linux-drm-fsl-dcu.git] / drivers / scsi / scsi_lib.c
index 2f12f9f12fcb269f5d55a11d9048b6d808bf5f12..9f7482d0b59489e7efccc347a8b7ce33208b4cdb 100644 (file)
@@ -36,7 +36,7 @@
 struct scsi_host_sg_pool {
        size_t          size;
        char            *name; 
-       kmem_cache_t    *slab;
+       struct kmem_cache       *slab;
        mempool_t       *pool;
 };
 
@@ -241,7 +241,7 @@ struct scsi_io_context {
        char sense[SCSI_SENSE_BUFFERSIZE];
 };
 
-static kmem_cache_t *scsi_io_context_cache;
+static struct kmem_cache *scsi_io_context_cache;
 
 static void scsi_end_async(struct request *req, int uptodate)
 {
@@ -265,13 +265,11 @@ static int scsi_merge_bio(struct request *rq, struct bio *bio)
 
        if (!rq->bio)
                blk_rq_bio_prep(q, rq, bio);
-       else if (!q->back_merge_fn(q, rq, bio))
+       else if (!ll_back_merge_fn(q, rq, bio))
                return -EINVAL;
        else {
                rq->biotail->bi_next = bio;
                rq->biotail = bio;
-               rq->hard_nr_sectors += bio_sectors(bio);
-               rq->nr_sectors = rq->hard_nr_sectors;
        }
 
        return 0;
@@ -390,10 +388,9 @@ int scsi_execute_async(struct scsi_device *sdev, const unsigned char *cmd,
        int err = 0;
        int write = (data_direction == DMA_TO_DEVICE);
 
-       sioc = kmem_cache_alloc(scsi_io_context_cache, gfp);
+       sioc = kmem_cache_zalloc(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)
@@ -704,7 +701,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate,
        return NULL;
 }
 
-static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
+struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
 {
        struct scsi_host_sg_pool *sgp;
        struct scatterlist *sgl;
@@ -745,7 +742,9 @@ static struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_m
        return sgl;
 }
 
-static void scsi_free_sgtable(struct scatterlist *sgl, int index)
+EXPORT_SYMBOL(scsi_alloc_sgtable);
+
+void scsi_free_sgtable(struct scatterlist *sgl, int index)
 {
        struct scsi_host_sg_pool *sgp;
 
@@ -755,6 +754,8 @@ static void scsi_free_sgtable(struct scatterlist *sgl, int index)
        mempool_free(sgl, sgp->pool);
 }
 
+EXPORT_SYMBOL(scsi_free_sgtable);
+
 /*
  * Function:    scsi_release_buffers()
  *
@@ -1398,7 +1399,7 @@ static void scsi_softirq_done(struct request *rq)
                        scsi_finish_command(cmd);
                        break;
                case NEEDS_RETRY:
-                       scsi_retry_command(cmd);
+                       scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY);
                        break;
                case ADD_TO_MLQUEUE:
                        scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
@@ -1567,29 +1568,40 @@ u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
 }
 EXPORT_SYMBOL(scsi_calculate_bounce_limit);
 
-struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
+struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
+                                        request_fn_proc *request_fn)
 {
-       struct Scsi_Host *shost = sdev->host;
        struct request_queue *q;
 
-       q = blk_init_queue(scsi_request_fn, NULL);
+       q = blk_init_queue(request_fn, NULL);
        if (!q)
                return NULL;
 
-       blk_queue_prep_rq(q, scsi_prep_fn);
-
        blk_queue_max_hw_segments(q, shost->sg_tablesize);
        blk_queue_max_phys_segments(q, SCSI_MAX_PHYS_SEGMENTS);
        blk_queue_max_sectors(q, shost->max_sectors);
        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);
-       blk_queue_softirq_done(q, scsi_softirq_done);
 
        if (!shost->use_clustering)
                clear_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
        return q;
 }
+EXPORT_SYMBOL(__scsi_alloc_queue);
+
+struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
+{
+       struct request_queue *q;
+
+       q = __scsi_alloc_queue(sdev->host, scsi_request_fn);
+       if (!q)
+               return NULL;
+
+       blk_queue_prep_rq(q, scsi_prep_fn);
+       blk_queue_issue_flush_fn(q, scsi_issue_flush_fn);
+       blk_queue_softirq_done(q, scsi_softirq_done);
+       return q;
+}
 
 void scsi_free_queue(struct request_queue *q)
 {
@@ -2237,6 +2249,8 @@ void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
        size_t sg_len = 0, len_complete = 0;
        struct page *page;
 
+       WARN_ON(!irqs_disabled());
+
        for (i = 0; i < sg_count; i++) {
                len_complete = sg_len; /* Complete sg-entries */
                sg_len += sg[i].length;