]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/target/target_core_pscsi.c
target: consolidate version defines
[mirror_ubuntu-artful-kernel.git] / drivers / target / target_core_pscsi.c
index f6c954c4635f5dab27ac24ea117dd284561c836a..f757178ed41471847d8fa89b0061713f4c70752f 100644 (file)
@@ -44,9 +44,9 @@
 
 #include <target/target_core_base.h>
 #include <target/target_core_backend.h>
-#include <target/target_core_backend_configfs.h>
 
 #include "target_core_alua.h"
+#include "target_core_internal.h"
 #include "target_core_pscsi.h"
 
 #define ISPRINT(a)  ((a >= ' ') && (a <= '~'))
@@ -56,8 +56,6 @@ static inline struct pscsi_dev_virt *PSCSI_DEV(struct se_device *dev)
        return container_of(dev, struct pscsi_dev_virt, dev);
 }
 
-static struct se_subsystem_api pscsi_template;
-
 static sense_reason_t pscsi_execute_cmd(struct se_cmd *cmd);
 static void pscsi_req_done(struct request *, int);
 
@@ -82,7 +80,7 @@ static int pscsi_attach_hba(struct se_hba *hba, u32 host_id)
 
        pr_debug("CORE_HBA[%d] - TCM SCSI HBA Driver %s on"
                " Generic Target Core Stack %s\n", hba->hba_id,
-               PSCSI_VERSION, TARGET_CORE_MOD_VERSION);
+               PSCSI_VERSION, TARGET_CORE_VERSION);
        pr_debug("CORE_HBA[%d] - Attached SCSI HBA to Generic\n",
               hba->hba_id);
 
@@ -521,6 +519,7 @@ static int pscsi_configure_device(struct se_device *dev)
                                        " pdv_host_id: %d\n", pdv->pdv_host_id);
                                return -EINVAL;
                        }
+                       pdv->pdv_lld_host = sh;
                }
        } else {
                if (phv->phv_mode == PHV_VIRTUAL_HOST_ID) {
@@ -580,6 +579,14 @@ static int pscsi_configure_device(struct se_device *dev)
        return -ENODEV;
 }
 
+static void pscsi_dev_call_rcu(struct rcu_head *p)
+{
+       struct se_device *dev = container_of(p, struct se_device, rcu_head);
+       struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
+
+       kfree(pdv);
+}
+
 static void pscsi_free_device(struct se_device *dev)
 {
        struct pscsi_dev_virt *pdv = PSCSI_DEV(dev);
@@ -603,14 +610,15 @@ static void pscsi_free_device(struct se_device *dev)
                if ((phv->phv_mode == PHV_LLD_SCSI_HOST_NO) &&
                    (phv->phv_lld_host != NULL))
                        scsi_host_put(phv->phv_lld_host);
+               else if (pdv->pdv_lld_host)
+                       scsi_host_put(pdv->pdv_lld_host);
 
                if ((sd->type == TYPE_DISK) || (sd->type == TYPE_ROM))
                        scsi_device_put(sd);
 
                pdv->pdv_sd = NULL;
        }
-
-       kfree(pdv);
+       call_rcu(&dev->rcu_head, pscsi_dev_call_rcu);
 }
 
 static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
@@ -634,12 +642,14 @@ static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg,
         * Hack to make sure that Write-Protect modepage is set if R/O mode is
         * forced.
         */
-       if (!cmd->se_deve || !cmd->data_length)
+       if (!cmd->data_length)
                goto after_mode_sense;
 
        if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) &&
             (status_byte(result) << 1) == SAM_STAT_GOOD) {
-               if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) {
+               bool read_only = target_lun_is_rdonly(cmd);
+
+               if (read_only) {
                        unsigned char *buf;
 
                        buf = transport_kmap_data_sg(cmd);
@@ -970,64 +980,13 @@ fail:
        return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 }
 
-/*
- * Clear a lun set in the cdb if the initiator talking to use spoke
- * and old standards version, as we can't assume the underlying device
- * won't choke up on it.
- */
-static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
-{
-       switch (cdb[0]) {
-       case READ_10: /* SBC - RDProtect */
-       case READ_12: /* SBC - RDProtect */
-       case READ_16: /* SBC - RDProtect */
-       case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
-       case VERIFY: /* SBC - VRProtect */
-       case VERIFY_16: /* SBC - VRProtect */
-       case WRITE_VERIFY: /* SBC - VRProtect */
-       case WRITE_VERIFY_12: /* SBC - VRProtect */
-       case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
-               break;
-       default:
-               cdb[1] &= 0x1f; /* clear logical unit number */
-               break;
-       }
-}
-
 static sense_reason_t
 pscsi_parse_cdb(struct se_cmd *cmd)
 {
-       unsigned char *cdb = cmd->t_task_cdb;
-
        if (cmd->se_cmd_flags & SCF_BIDI)
                return TCM_UNSUPPORTED_SCSI_OPCODE;
 
-       pscsi_clear_cdb_lun(cdb);
-
-       /*
-        * For REPORT LUNS we always need to emulate the response, for everything
-        * else the default for pSCSI is to pass the command to the underlying
-        * LLD / physical hardware.
-        */
-       switch (cdb[0]) {
-       case REPORT_LUNS:
-               cmd->execute_cmd = spc_emulate_report_luns;
-               return 0;
-       case READ_6:
-       case READ_10:
-       case READ_12:
-       case READ_16:
-       case WRITE_6:
-       case WRITE_10:
-       case WRITE_12:
-       case WRITE_16:
-       case WRITE_VERIFY:
-               cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
-               /* FALLTHROUGH*/
-       default:
-               cmd->execute_cmd = pscsi_execute_cmd;
-               return 0;
-       }
+       return passthrough_parse_cdb(cmd, pscsi_execute_cmd);
 }
 
 static sense_reason_t
@@ -1166,30 +1125,10 @@ static void pscsi_req_done(struct request *req, int uptodate)
        kfree(pt);
 }
 
-DEF_TB_DEV_ATTRIB_RO(pscsi, hw_pi_prot_type);
-TB_DEV_ATTR_RO(pscsi, hw_pi_prot_type);
-
-DEF_TB_DEV_ATTRIB_RO(pscsi, hw_block_size);
-TB_DEV_ATTR_RO(pscsi, hw_block_size);
-
-DEF_TB_DEV_ATTRIB_RO(pscsi, hw_max_sectors);
-TB_DEV_ATTR_RO(pscsi, hw_max_sectors);
-
-DEF_TB_DEV_ATTRIB_RO(pscsi, hw_queue_depth);
-TB_DEV_ATTR_RO(pscsi, hw_queue_depth);
-
-static struct configfs_attribute *pscsi_backend_dev_attrs[] = {
-       &pscsi_dev_attrib_hw_pi_prot_type.attr,
-       &pscsi_dev_attrib_hw_block_size.attr,
-       &pscsi_dev_attrib_hw_max_sectors.attr,
-       &pscsi_dev_attrib_hw_queue_depth.attr,
-       NULL,
-};
-
-static struct se_subsystem_api pscsi_template = {
+static const struct target_backend_ops pscsi_ops = {
        .name                   = "pscsi",
        .owner                  = THIS_MODULE,
-       .transport_type         = TRANSPORT_PLUGIN_PHBA_PDEV,
+       .transport_flags        = TRANSPORT_FLAG_PASSTHROUGH,
        .attach_hba             = pscsi_attach_hba,
        .detach_hba             = pscsi_detach_hba,
        .pmode_enable_hba       = pscsi_pmode_enable_hba,
@@ -1202,21 +1141,17 @@ static struct se_subsystem_api pscsi_template = {
        .show_configfs_dev_params = pscsi_show_configfs_dev_params,
        .get_device_type        = pscsi_get_device_type,
        .get_blocks             = pscsi_get_blocks,
+       .tb_dev_attrib_attrs    = passthrough_attrib_attrs,
 };
 
 static int __init pscsi_module_init(void)
 {
-       struct target_backend_cits *tbc = &pscsi_template.tb_cits;
-
-       target_core_setup_sub_cits(&pscsi_template);
-       tbc->tb_dev_attrib_cit.ct_attrs = pscsi_backend_dev_attrs;
-
-       return transport_subsystem_register(&pscsi_template);
+       return transport_backend_register(&pscsi_ops);
 }
 
 static void __exit pscsi_module_exit(void)
 {
-       transport_subsystem_release(&pscsi_template);
+       target_backend_unregister(&pscsi_ops);
 }
 
 MODULE_DESCRIPTION("TCM PSCSI subsystem plugin");