[SCSI] save command pool address of Scsi_Host
[cascardo/linux.git] / drivers / scsi / scsi.c
index 2396e89..d81f3cc 100644 (file)
@@ -72,8 +72,6 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/scsi.h>
 
-static void scsi_done(struct scsi_cmnd *cmd);
-
 /*
  * Definitions and constants.
  */
@@ -124,6 +122,8 @@ static const char *const scsi_device_types[] = {
        "Bridge controller",
        "Object storage   ",
        "Automation/Drive ",
+       "Security Manager ",
+       "Direct-Access-ZBC",
 };
 
 /**
@@ -365,8 +365,8 @@ scsi_alloc_host_cmd_pool(struct Scsi_Host *shost)
        if (!pool)
                return NULL;
 
-       pool->cmd_name = kasprintf(GFP_KERNEL, "%s_cmd", hostt->name);
-       pool->sense_name = kasprintf(GFP_KERNEL, "%s_sense", hostt->name);
+       pool->cmd_name = kasprintf(GFP_KERNEL, "%s_cmd", hostt->proc_name);
+       pool->sense_name = kasprintf(GFP_KERNEL, "%s_sense", hostt->proc_name);
        if (!pool->cmd_name || !pool->sense_name) {
                scsi_free_host_cmd_pool(pool);
                return NULL;
@@ -377,6 +377,10 @@ scsi_alloc_host_cmd_pool(struct Scsi_Host *shost)
                pool->slab_flags |= SLAB_CACHE_DMA;
                pool->gfp_mask = __GFP_DMA;
        }
+
+       if (hostt->cmd_size)
+               hostt->cmd_pool = pool;
+
        return pool;
 }
 
@@ -421,8 +425,10 @@ out:
 out_free_slab:
        kmem_cache_destroy(pool->cmd_slab);
 out_free_pool:
-       if (hostt->cmd_size)
+       if (hostt->cmd_size) {
                scsi_free_host_cmd_pool(pool);
+               hostt->cmd_pool = NULL;
+       }
        goto out;
 }
 
@@ -444,8 +450,10 @@ static void scsi_put_host_cmd_pool(struct Scsi_Host *shost)
        if (!--pool->users) {
                kmem_cache_destroy(pool->cmd_slab);
                kmem_cache_destroy(pool->sense_slab);
-               if (hostt->cmd_size)
+               if (hostt->cmd_size) {
                        scsi_free_host_cmd_pool(pool);
+                       hostt->cmd_pool = NULL;
+               }
        }
        mutex_unlock(&host_cmd_pool_mutex);
 }
@@ -602,7 +610,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
                        if (level > 3)
                                scmd_printk(KERN_INFO, cmd,
                                            "scsi host busy %d failed %d\n",
-                                           cmd->device->host->host_busy,
+                                           atomic_read(&cmd->device->host->host_busy),
                                            cmd->device->host->host_failed);
                }
        }
@@ -693,8 +701,6 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
        }
 
        trace_scsi_dispatch_cmd_start(cmd);
-
-       cmd->scsi_done = scsi_done;
        rtn = host->hostt->queuecommand(host, cmd);
        if (rtn) {
                trace_scsi_dispatch_cmd_error(cmd, rtn);
@@ -708,27 +714,10 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
 
        return rtn;
  done:
-       scsi_done(cmd);
+       cmd->scsi_done(cmd);
        return 0;
 }
 
-/**
- * scsi_done - Invoke completion on finished SCSI command.
- * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
- * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
- *
- * Description: This function is the mid-level's (SCSI Core) interrupt routine,
- * which regains ownership of the SCSI command (de facto) from a LLDD, and
- * calls blk_complete_request() for further processing.
- *
- * This function is interrupt context safe.
- */
-static void scsi_done(struct scsi_cmnd *cmd)
-{
-       trace_scsi_dispatch_cmd_done(cmd);
-       blk_complete_request(cmd->request);
-}
-
 /**
  * scsi_finish_command - cleanup and pass command back to upper layer
  * @cmd: the command
@@ -747,17 +736,16 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
 
        scsi_device_unbusy(sdev);
 
-        /*
-         * Clear the flags which say that the device/host is no longer
-         * capable of accepting new commands.  These are set in scsi_queue.c
-         * for both the queue full condition on a device, and for a
-         * host full condition on the host.
-        *
-        * XXX(hch): What about locking?
-         */
-        shost->host_blocked = 0;
-       starget->target_blocked = 0;
-        sdev->device_blocked = 0;
+       /*
+        * Clear the flags that say that the device/target/host is no longer
+        * capable of accepting new commands.
+        */
+       if (atomic_read(&shost->host_blocked))
+               atomic_set(&shost->host_blocked, 0);
+       if (atomic_read(&starget->target_blocked))
+               atomic_set(&starget->target_blocked, 0);
+       if (atomic_read(&sdev->device_blocked))
+               atomic_set(&sdev->device_blocked, 0);
 
        /*
         * If we have valid sense information, then some kind of recovery
@@ -827,7 +815,7 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
         * is more IO than the LLD's can_queue (so there are not enuogh
         * tags) request_fn's host queue ready check will handle it.
         */
-       if (!sdev->host->bqt) {
+       if (!shost_use_blk_mq(sdev->host) && !sdev->host->bqt) {
                if (blk_queue_tagged(sdev->request_queue) &&
                    blk_queue_resize_tags(sdev->request_queue, tags) != 0)
                        goto out;
@@ -1383,6 +1371,9 @@ MODULE_LICENSE("GPL");
 module_param(scsi_logging_level, int, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels");
 
+bool scsi_use_blk_mq = false;
+module_param_named(use_blk_mq, scsi_use_blk_mq, bool, S_IWUSR | S_IRUGO);
+
 static int __init init_scsi(void)
 {
        int error;