]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/scsi/scsi_lib.c
scsi: add support for multiple hardware queues
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / scsi_lib.c
index db8c449282f9888340b99e25942b1f65d8fd4e9c..38f8c85957b6a7e3278fef7f6d51f0813f3be1c7 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/hardirq.h>
 #include <linux/scatterlist.h>
 #include <linux/blk-mq.h>
+#include <linux/ratelimit.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
@@ -47,7 +48,7 @@ struct scsi_host_sg_pool {
        mempool_t       *pool;
 };
 
-#define SP(x) { x, "sgpool-" __stringify(x) }
+#define SP(x) { .size = x, "sgpool-" __stringify(x) }
 #if (SCSI_MAX_SG_SEGMENTS < 32)
 #error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater)
 #endif
@@ -221,7 +222,7 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
        int ret = DRIVER_ERROR << 24;
 
        req = blk_get_request(sdev->request_queue, write, __GFP_WAIT);
-       if (!req)
+       if (IS_ERR(req))
                return ret;
        blk_rq_set_block_pc(req);
 
@@ -715,7 +716,7 @@ static bool scsi_end_request(struct request *req, int error,
 
        if (req->mq_ctx) {
                /*
-                * In the MQ case the command gets freed by __blk_mq_end_io,
+                * In the MQ case the command gets freed by __blk_mq_end_request,
                 * so we have to do all cleanup that depends on it earlier.
                 *
                 * We also can't kick the queues from irq context, so we
@@ -723,7 +724,7 @@ static bool scsi_end_request(struct request *req, int error,
                 */
                scsi_mq_uninit_cmd(cmd);
 
-               __blk_mq_end_io(req, error);
+               __blk_mq_end_request(req, error);
 
                if (scsi_target(sdev)->single_lun ||
                    !list_empty(&sdev->host->starved_list))
@@ -831,8 +832,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
        struct request *req = cmd->request;
        int error = 0;
        struct scsi_sense_hdr sshdr;
-       int sense_valid = 0;
-       int sense_deferred = 0;
+       bool sense_valid = false;
+       int sense_deferred = 0, level = 0;
        enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY,
              ACTION_DELAYED_RETRY} action;
        unsigned long wait_for = (cmd->allowed + 1) * req->timeout;
@@ -912,7 +913,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
                if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d))
                        ;
                else if (!(req->cmd_flags & REQ_QUIET))
-                       scsi_print_sense("", cmd);
+                       scsi_print_sense(cmd);
                result = 0;
                /* BLOCK_PC may have set error */
                error = 0;
@@ -1039,10 +1040,24 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
        case ACTION_FAIL:
                /* Give up and fail the remainder of the request */
                if (!(req->cmd_flags & REQ_QUIET)) {
-                       scsi_print_result(cmd);
-                       if (driver_byte(result) & DRIVER_SENSE)
-                               scsi_print_sense("", cmd);
-                       scsi_print_command(cmd);
+                       static DEFINE_RATELIMIT_STATE(_rs,
+                                       DEFAULT_RATELIMIT_INTERVAL,
+                                       DEFAULT_RATELIMIT_BURST);
+
+                       if (unlikely(scsi_logging_level))
+                               level = SCSI_LOG_LEVEL(SCSI_LOG_MLCOMPLETE_SHIFT,
+                                                      SCSI_LOG_MLCOMPLETE_BITS);
+
+                       /*
+                        * if logging is enabled the failure will be printed
+                        * in scsi_log_completion(), so avoid duplicate messages
+                        */
+                       if (!level && __ratelimit(&_rs)) {
+                               scsi_print_result(cmd, NULL, FAILED);
+                               if (driver_byte(result) & DRIVER_SENSE)
+                                       scsi_print_sense(cmd);
+                               scsi_print_command(cmd);
+                       }
                }
                if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0))
                        return;
@@ -1847,6 +1862,8 @@ static int scsi_mq_prep_fn(struct request *req)
                next_rq->special = bidi_sdb;
        }
 
+       blk_mq_start_request(req);
+
        return scsi_setup_cmnd(sdev, req);
 }
 
@@ -1856,7 +1873,8 @@ static void scsi_mq_done(struct scsi_cmnd *cmd)
        blk_mq_complete_request(cmd->request);
 }
 
-static int scsi_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
+static int scsi_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req,
+               bool last)
 {
        struct request_queue *q = req->q;
        struct scsi_device *sdev = q->queuedata;
@@ -1880,13 +1898,21 @@ static int scsi_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
        if (!scsi_host_queue_ready(q, shost, sdev))
                goto out_dec_target_busy;
 
+
        if (!(req->cmd_flags & REQ_DONTPREP)) {
                ret = prep_to_mq(scsi_mq_prep_fn(req));
                if (ret)
                        goto out_dec_host_busy;
                req->cmd_flags |= REQ_DONTPREP;
+       } else {
+               blk_mq_start_request(req);
        }
 
+       if (blk_queue_tagged(q))
+               req->cmd_flags |= REQ_QUEUED;
+       else
+               req->cmd_flags &= ~REQ_QUEUED;
+
        scsi_init_cmd_errh(cmd);
        cmd->scsi_done = scsi_mq_done;
 
@@ -1931,6 +1957,14 @@ out:
        return ret;
 }
 
+static enum blk_eh_timer_return scsi_timeout(struct request *req,
+               bool reserved)
+{
+       if (reserved)
+               return BLK_EH_RESET_TIMER;
+       return scsi_times_out(req);
+}
+
 static int scsi_init_request(void *data, struct request *rq,
                unsigned int hctx_idx, unsigned int request_idx,
                unsigned int numa_node)
@@ -2042,7 +2076,7 @@ static struct blk_mq_ops scsi_mq_ops = {
        .map_queue      = blk_mq_map_queue,
        .queue_rq       = scsi_queue_rq,
        .complete       = scsi_softirq_done,
-       .timeout        = scsi_times_out,
+       .timeout        = scsi_timeout,
        .init_request   = scsi_init_request,
        .exit_request   = scsi_exit_request,
 };
@@ -2072,7 +2106,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
 
        memset(&shost->tag_set, 0, sizeof(shost->tag_set));
        shost->tag_set.ops = &scsi_mq_ops;
-       shost->tag_set.nr_hw_queues = 1;
+       shost->tag_set.nr_hw_queues = shost->nr_hw_queues ? : 1;
        shost->tag_set.queue_depth = shost->can_queue;
        shost->tag_set.cmd_size = cmd_size;
        shost->tag_set.numa_node = NUMA_NO_NODE;