These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / target / target_core_rd.c
index d16489b..47a833f 100644 (file)
 #include <linux/timer.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <scsi/scsi.h>
-#include <scsi/scsi_host.h>
+#include <scsi/scsi_proto.h>
 
 #include <target/target_core_base.h>
 #include <target/target_core_backend.h>
-#include <target/target_core_backend_configfs.h>
 
 #include "target_core_rd.h"
 
@@ -43,10 +41,6 @@ static inline struct rd_dev *RD_DEV(struct se_device *dev)
        return container_of(dev, struct rd_dev, dev);
 }
 
-/*     rd_attach_hba(): (Part of se_subsystem_api_t template)
- *
- *
- */
 static int rd_attach_hba(struct se_hba *hba, u32 host_id)
 {
        struct rd_host *rd_host;
@@ -63,7 +57,7 @@ static int rd_attach_hba(struct se_hba *hba, u32 host_id)
 
        pr_debug("CORE_HBA[%d] - TCM Ramdisk HBA Driver %s on"
                " Generic Target Core Stack %s\n", hba->hba_id,
-               RD_HBA_VERSION, TARGET_CORE_MOD_VERSION);
+               RD_HBA_VERSION, TARGET_CORE_VERSION);
 
        return 0;
 }
@@ -144,16 +138,12 @@ static int rd_allocate_sgl_table(struct rd_dev *rd_dev, struct rd_dev_sg_table *
                sg_per_table = (total_sg_needed > max_sg_per_table) ?
                        max_sg_per_table : total_sg_needed;
 
-#ifdef CONFIG_ARCH_HAS_SG_CHAIN
-
                /*
                 * Reserve extra element for chain entry
                 */
                if (sg_per_table < total_sg_needed)
                        chain_entry = 1;
 
-#endif /* CONFIG_ARCH_HAS_SG_CHAIN */
-
                sg = kcalloc(sg_per_table + chain_entry, sizeof(*sg),
                                GFP_KERNEL);
                if (!sg) {
@@ -164,15 +154,11 @@ static int rd_allocate_sgl_table(struct rd_dev *rd_dev, struct rd_dev_sg_table *
 
                sg_init_table(sg, sg_per_table + chain_entry);
 
-#ifdef CONFIG_ARCH_HAS_SG_CHAIN
-
                if (i > 0) {
                        sg_chain(sg_table[i - 1].sg_table,
                                 max_sg_per_table + 1, sg);
                }
 
-#endif /* CONFIG_ARCH_HAS_SG_CHAIN */
-
                sg_table[i].sg_table = sg;
                sg_table[i].rd_sg_count = sg_per_table;
                sg_table[i].page_start_offset = page_offset;
@@ -339,6 +325,7 @@ static int rd_configure_device(struct se_device *dev)
        dev->dev_attrib.hw_block_size = RD_BLOCKSIZE;
        dev->dev_attrib.hw_max_sectors = UINT_MAX;
        dev->dev_attrib.hw_queue_depth = RD_MAX_DEVICE_QUEUE_DEPTH;
+       dev->dev_attrib.is_nonrot = 1;
 
        rd_dev->rd_dev_id = rd_host->rd_host_dev_id_count++;
 
@@ -355,12 +342,20 @@ fail:
        return ret;
 }
 
+static void rd_dev_call_rcu(struct rcu_head *p)
+{
+       struct se_device *dev = container_of(p, struct se_device, rcu_head);
+       struct rd_dev *rd_dev = RD_DEV(dev);
+
+       kfree(rd_dev);
+}
+
 static void rd_free_device(struct se_device *dev)
 {
        struct rd_dev *rd_dev = RD_DEV(dev);
 
        rd_release_device_space(rd_dev);
-       kfree(rd_dev);
+       call_rcu(&dev->rcu_head, rd_dev_call_rcu);
 }
 
 static struct rd_dev_sg_table *rd_get_sg_table(struct rd_dev *rd_dev, u32 page)
@@ -403,10 +398,7 @@ static struct rd_dev_sg_table *rd_get_prot_table(struct rd_dev *rd_dev, u32 page
        return NULL;
 }
 
-typedef sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int,
-                                    unsigned int, struct scatterlist *, int);
-
-static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, dif_verify dif_verify)
+static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_read)
 {
        struct se_device *se_dev = cmd->se_dev;
        struct rd_dev *dev = RD_DEV(se_dev);
@@ -430,43 +422,16 @@ static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, dif_verify dif_verify)
        prot_sg = &prot_table->sg_table[prot_page -
                                        prot_table->page_start_offset];
 
-#ifndef CONFIG_ARCH_HAS_SG_CHAIN
+       if (is_read)
+               rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0,
+                                   prot_sg, prot_offset);
+       else
+               rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0,
+                                   cmd->t_prot_sg, 0);
 
-       prot_npages = DIV_ROUND_UP(prot_offset + sectors * se_dev->prot_length,
-                                  PAGE_SIZE);
+       if (!rc)
+               sbc_dif_copy_prot(cmd, sectors, is_read, prot_sg, prot_offset);
 
-       /*
-        * Allocate temporaly contiguous scatterlist entries if prot pages
-        * straddles multiple scatterlist tables.
-        */
-       if (prot_table->page_end_offset < prot_page + prot_npages - 1) {
-               int i;
-
-               prot_sg = kcalloc(prot_npages, sizeof(*prot_sg), GFP_KERNEL);
-               if (!prot_sg)
-                       return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
-               need_to_release = true;
-               sg_init_table(prot_sg, prot_npages);
-
-               for (i = 0; i < prot_npages; i++) {
-                       if (prot_page + i > prot_table->page_end_offset) {
-                               prot_table = rd_get_prot_table(dev,
-                                                               prot_page + i);
-                               if (!prot_table) {
-                                       kfree(prot_sg);
-                                       return rc;
-                               }
-                               sg_unmark_end(&prot_sg[i - 1]);
-                       }
-                       prot_sg[i] = prot_table->sg_table[prot_page + i -
-                                               prot_table->page_start_offset];
-               }
-       }
-
-#endif /* !CONFIG_ARCH_HAS_SG_CHAIN */
-
-       rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg, prot_offset);
        if (need_to_release)
                kfree(prot_sg);
 
@@ -512,7 +477,7 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 
        if (cmd->prot_type && se_dev->dev_attrib.pi_prot_type &&
            data_direction == DMA_TO_DEVICE) {
-               rc = rd_do_prot_rw(cmd, sbc_dif_verify_write);
+               rc = rd_do_prot_rw(cmd, false);
                if (rc)
                        return rc;
        }
@@ -580,7 +545,7 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 
        if (cmd->prot_type && se_dev->dev_attrib.pi_prot_type &&
            data_direction == DMA_FROM_DEVICE) {
-               rc = rd_do_prot_rw(cmd, sbc_dif_verify_read);
+               rc = rd_do_prot_rw(cmd, true);
                if (rc)
                        return rc;
        }
@@ -694,42 +659,7 @@ rd_parse_cdb(struct se_cmd *cmd)
        return sbc_parse_cdb(cmd, &rd_sbc_ops);
 }
 
-DEF_TB_DEFAULT_ATTRIBS(rd_mcp);
-
-static struct configfs_attribute *rd_mcp_backend_dev_attrs[] = {
-       &rd_mcp_dev_attrib_emulate_model_alias.attr,
-       &rd_mcp_dev_attrib_emulate_dpo.attr,
-       &rd_mcp_dev_attrib_emulate_fua_write.attr,
-       &rd_mcp_dev_attrib_emulate_fua_read.attr,
-       &rd_mcp_dev_attrib_emulate_write_cache.attr,
-       &rd_mcp_dev_attrib_emulate_ua_intlck_ctrl.attr,
-       &rd_mcp_dev_attrib_emulate_tas.attr,
-       &rd_mcp_dev_attrib_emulate_tpu.attr,
-       &rd_mcp_dev_attrib_emulate_tpws.attr,
-       &rd_mcp_dev_attrib_emulate_caw.attr,
-       &rd_mcp_dev_attrib_emulate_3pc.attr,
-       &rd_mcp_dev_attrib_pi_prot_type.attr,
-       &rd_mcp_dev_attrib_hw_pi_prot_type.attr,
-       &rd_mcp_dev_attrib_pi_prot_format.attr,
-       &rd_mcp_dev_attrib_enforce_pr_isids.attr,
-       &rd_mcp_dev_attrib_is_nonrot.attr,
-       &rd_mcp_dev_attrib_emulate_rest_reord.attr,
-       &rd_mcp_dev_attrib_force_pr_aptpl.attr,
-       &rd_mcp_dev_attrib_hw_block_size.attr,
-       &rd_mcp_dev_attrib_block_size.attr,
-       &rd_mcp_dev_attrib_hw_max_sectors.attr,
-       &rd_mcp_dev_attrib_optimal_sectors.attr,
-       &rd_mcp_dev_attrib_hw_queue_depth.attr,
-       &rd_mcp_dev_attrib_queue_depth.attr,
-       &rd_mcp_dev_attrib_max_unmap_lba_count.attr,
-       &rd_mcp_dev_attrib_max_unmap_block_desc_count.attr,
-       &rd_mcp_dev_attrib_unmap_granularity.attr,
-       &rd_mcp_dev_attrib_unmap_granularity_alignment.attr,
-       &rd_mcp_dev_attrib_max_write_same_len.attr,
-       NULL,
-};
-
-static struct se_subsystem_api rd_mcp_template = {
+static const struct target_backend_ops rd_mcp_ops = {
        .name                   = "rd_mcp",
        .inquiry_prod           = "RAMDISK-MCP",
        .inquiry_rev            = RD_MCP_VERSION,
@@ -745,25 +675,15 @@ static struct se_subsystem_api rd_mcp_template = {
        .get_blocks             = rd_get_blocks,
        .init_prot              = rd_init_prot,
        .free_prot              = rd_free_prot,
+       .tb_dev_attrib_attrs    = sbc_attrib_attrs,
 };
 
 int __init rd_module_init(void)
 {
-       struct target_backend_cits *tbc = &rd_mcp_template.tb_cits;
-       int ret;
-
-       target_core_setup_sub_cits(&rd_mcp_template);
-       tbc->tb_dev_attrib_cit.ct_attrs = rd_mcp_backend_dev_attrs;
-
-       ret = transport_subsystem_register(&rd_mcp_template);
-       if (ret < 0) {
-               return ret;
-       }
-
-       return 0;
+       return transport_backend_register(&rd_mcp_ops);
 }
 
 void rd_module_exit(void)
 {
-       transport_subsystem_release(&rd_mcp_template);
+       target_backend_unregister(&rd_mcp_ops);
 }