]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/target/tcm_fc/tfc_conf.c
target: Minimize SCSI header #include directives
[karo-tx-linux.git] / drivers / target / tcm_fc / tfc_conf.c
index e879da81ad9303c2ad1d0d4d0487662523bc1b1c..86b699b94c7b615836ac38383554e1c83ff27af2 100644 (file)
 #include <linux/kernel.h>
 #include <linux/ctype.h>
 #include <asm/unaligned.h>
-#include <scsi/scsi.h>
-#include <scsi/scsi_host.h>
-#include <scsi/scsi_device.h>
-#include <scsi/scsi_cmnd.h>
 #include <scsi/libfc.h>
 
 #include <target/target_core_base.h>
@@ -48,9 +44,9 @@
 
 #include "tcm_fc.h"
 
-struct target_fabric_configfs *ft_configfs;
+static const struct target_core_fabric_ops ft_fabric_ops;
 
-LIST_HEAD(ft_lport_list);
+static LIST_HEAD(ft_wwn_list);
 DEFINE_MUTEX(ft_lport_lock);
 
 unsigned int ft_debug_logging;
@@ -298,7 +294,7 @@ static struct se_portal_group *ft_add_tpg(
        struct config_group *group,
        const char *name)
 {
-       struct ft_lport_acl *lacl;
+       struct ft_lport_wwn *ft_wwn;
        struct ft_tpg *tpg;
        struct workqueue_struct *wq;
        unsigned long index;
@@ -318,12 +314,17 @@ static struct se_portal_group *ft_add_tpg(
        if (index > UINT_MAX)
                return NULL;
 
-       lacl = container_of(wwn, struct ft_lport_acl, fc_lport_wwn);
+       if ((index != 1)) {
+               pr_err("Error, a single TPG=1 is used for HW port mappings\n");
+               return ERR_PTR(-ENOSYS);
+       }
+
+       ft_wwn = container_of(wwn, struct ft_lport_wwn, se_wwn);
        tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
        if (!tpg)
                return NULL;
        tpg->index = index;
-       tpg->lport_acl = lacl;
+       tpg->lport_wwn = ft_wwn;
        INIT_LIST_HEAD(&tpg->lun_list);
 
        wq = alloc_workqueue("tcm_fc", 0, 1);
@@ -332,7 +333,7 @@ static struct se_portal_group *ft_add_tpg(
                return NULL;
        }
 
-       ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg,
+       ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg,
                                tpg, TRANSPORT_TPG_TYPE_NORMAL);
        if (ret < 0) {
                destroy_workqueue(wq);
@@ -342,7 +343,7 @@ static struct se_portal_group *ft_add_tpg(
        tpg->workqueue = wq;
 
        mutex_lock(&ft_lport_lock);
-       list_add_tail(&tpg->list, &lacl->tpg_list);
+       ft_wwn->tpg = tpg;
        mutex_unlock(&ft_lport_lock);
 
        return &tpg->se_tpg;
@@ -351,6 +352,7 @@ static struct se_portal_group *ft_add_tpg(
 static void ft_del_tpg(struct se_portal_group *se_tpg)
 {
        struct ft_tpg *tpg = container_of(se_tpg, struct ft_tpg, se_tpg);
+       struct ft_lport_wwn *ft_wwn = tpg->lport_wwn;
 
        pr_debug("del tpg %s\n",
                    config_item_name(&tpg->se_tpg.tpg_group.cg_item));
@@ -361,7 +363,7 @@ static void ft_del_tpg(struct se_portal_group *se_tpg)
        synchronize_rcu();
 
        mutex_lock(&ft_lport_lock);
-       list_del(&tpg->list);
+       ft_wwn->tpg = NULL;
        if (tpg->tport) {
                tpg->tport->tpg = NULL;
                tpg->tport = NULL;
@@ -380,15 +382,11 @@ static void ft_del_tpg(struct se_portal_group *se_tpg)
  */
 struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
 {
-       struct ft_lport_acl *lacl;
-       struct ft_tpg *tpg;
+       struct ft_lport_wwn *ft_wwn;
 
-       list_for_each_entry(lacl, &ft_lport_list, list) {
-               if (lacl->wwpn == lport->wwpn) {
-                       list_for_each_entry(tpg, &lacl->tpg_list, list)
-                               return tpg; /* XXX for now return first entry */
-                       return NULL;
-               }
+       list_for_each_entry(ft_wwn, &ft_wwn_list, ft_wwn_node) {
+               if (ft_wwn->wwpn == lport->wwpn)
+                       return ft_wwn->tpg;
        }
        return NULL;
 }
@@ -401,50 +399,49 @@ struct ft_tpg *ft_lport_find_tpg(struct fc_lport *lport)
  * Add lport to allowed config.
  * The name is the WWPN in lower-case ASCII, colon-separated bytes.
  */
-static struct se_wwn *ft_add_lport(
+static struct se_wwn *ft_add_wwn(
        struct target_fabric_configfs *tf,
        struct config_group *group,
        const char *name)
 {
-       struct ft_lport_acl *lacl;
-       struct ft_lport_acl *old_lacl;
+       struct ft_lport_wwn *ft_wwn;
+       struct ft_lport_wwn *old_ft_wwn;
        u64 wwpn;
 
-       pr_debug("add lport %s\n", name);
+       pr_debug("add wwn %s\n", name);
        if (ft_parse_wwn(name, &wwpn, 1) < 0)
                return NULL;
-       lacl = kzalloc(sizeof(*lacl), GFP_KERNEL);
-       if (!lacl)
+       ft_wwn = kzalloc(sizeof(*ft_wwn), GFP_KERNEL);
+       if (!ft_wwn)
                return NULL;
-       lacl->wwpn = wwpn;
-       INIT_LIST_HEAD(&lacl->tpg_list);
+       ft_wwn->wwpn = wwpn;
 
        mutex_lock(&ft_lport_lock);
-       list_for_each_entry(old_lacl, &ft_lport_list, list) {
-               if (old_lacl->wwpn == wwpn) {
+       list_for_each_entry(old_ft_wwn, &ft_wwn_list, ft_wwn_node) {
+               if (old_ft_wwn->wwpn == wwpn) {
                        mutex_unlock(&ft_lport_lock);
-                       kfree(lacl);
+                       kfree(ft_wwn);
                        return NULL;
                }
        }
-       list_add_tail(&lacl->list, &ft_lport_list);
-       ft_format_wwn(lacl->name, sizeof(lacl->name), wwpn);
+       list_add_tail(&ft_wwn->ft_wwn_node, &ft_wwn_list);
+       ft_format_wwn(ft_wwn->name, sizeof(ft_wwn->name), wwpn);
        mutex_unlock(&ft_lport_lock);
 
-       return &lacl->fc_lport_wwn;
+       return &ft_wwn->se_wwn;
 }
 
-static void ft_del_lport(struct se_wwn *wwn)
+static void ft_del_wwn(struct se_wwn *wwn)
 {
-       struct ft_lport_acl *lacl = container_of(wwn,
-                               struct ft_lport_acl, fc_lport_wwn);
+       struct ft_lport_wwn *ft_wwn = container_of(wwn,
+                               struct ft_lport_wwn, se_wwn);
 
-       pr_debug("del lport %s\n", lacl->name);
+       pr_debug("del wwn %s\n", ft_wwn->name);
        mutex_lock(&ft_lport_lock);
-       list_del(&lacl->list);
+       list_del(&ft_wwn->ft_wwn_node);
        mutex_unlock(&ft_lport_lock);
 
-       kfree(lacl);
+       kfree(ft_wwn);
 }
 
 static ssize_t ft_wwn_show_attr_version(
@@ -471,7 +468,7 @@ static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg)
 {
        struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr;
 
-       return tpg->lport_acl->name;
+       return tpg->lport_wwn->name;
 }
 
 static u16 ft_get_tag(struct se_portal_group *se_tpg)
@@ -506,7 +503,9 @@ static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
        return tpg->index;
 }
 
-static struct target_core_fabric_ops ft_fabric_ops = {
+static const struct target_core_fabric_ops ft_fabric_ops = {
+       .module =                       THIS_MODULE,
+       .name =                         "fc",
        .get_fabric_name =              ft_get_fabric_name,
        .get_fabric_proto_ident =       fc_get_fabric_proto_ident,
        .tpg_get_wwn =                  ft_get_fabric_wwn,
@@ -536,12 +535,13 @@ static struct target_core_fabric_ops ft_fabric_ops = {
        .queue_data_in =                ft_queue_data_in,
        .queue_status =                 ft_queue_status,
        .queue_tm_rsp =                 ft_queue_tm_resp,
+       .aborted_task =                 ft_aborted_task,
        /*
         * Setup function pointers for generic logic in
         * target_core_fabric_configfs.c
         */
-       .fabric_make_wwn =              &ft_add_lport,
-       .fabric_drop_wwn =              &ft_del_lport,
+       .fabric_make_wwn =              &ft_add_wwn,
+       .fabric_drop_wwn =              &ft_del_wwn,
        .fabric_make_tpg =              &ft_add_tpg,
        .fabric_drop_tpg =              &ft_del_tpg,
        .fabric_post_link =             NULL,
@@ -550,62 +550,10 @@ static struct target_core_fabric_ops ft_fabric_ops = {
        .fabric_drop_np =               NULL,
        .fabric_make_nodeacl =          &ft_add_acl,
        .fabric_drop_nodeacl =          &ft_del_acl,
-};
 
-static int ft_register_configfs(void)
-{
-       struct target_fabric_configfs *fabric;
-       int ret;
-
-       /*
-        * Register the top level struct config_item_type with TCM core
-        */
-       fabric = target_fabric_configfs_init(THIS_MODULE, "fc");
-       if (IS_ERR(fabric)) {
-               pr_err("%s: target_fabric_configfs_init() failed!\n",
-                      __func__);
-               return PTR_ERR(fabric);
-       }
-       fabric->tf_ops = ft_fabric_ops;
-
-       /*
-        * Setup default attribute lists for various fabric->tf_cit_tmpl
-        */
-       fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = ft_wwn_attrs;
-       fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs =
-                                                   ft_nacl_base_attrs;
-       fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
-       fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
-       /*
-        * register the fabric for use within TCM
-        */
-       ret = target_fabric_configfs_register(fabric);
-       if (ret < 0) {
-               pr_debug("target_fabric_configfs_register() for"
-                           " FC Target failed!\n");
-               target_fabric_configfs_free(fabric);
-               return -1;
-       }
-
-       /*
-        * Setup our local pointer to *fabric.
-        */
-       ft_configfs = fabric;
-       return 0;
-}
-
-static void ft_deregister_configfs(void)
-{
-       if (!ft_configfs)
-               return;
-       target_fabric_configfs_deregister(ft_configfs);
-       ft_configfs = NULL;
-}
+       .tfc_wwn_attrs                  = ft_wwn_attrs,
+       .tfc_tpg_nacl_base_attrs        = ft_nacl_base_attrs,
+};
 
 static struct notifier_block ft_notifier = {
        .notifier_call = ft_lport_notify
@@ -613,15 +561,24 @@ static struct notifier_block ft_notifier = {
 
 static int __init ft_init(void)
 {
-       if (ft_register_configfs())
-               return -1;
-       if (fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov)) {
-               ft_deregister_configfs();
-               return -1;
-       }
+       int ret;
+
+       ret = target_register_template(&ft_fabric_ops);
+       if (ret)
+               goto out;
+
+       ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov);
+       if (ret)
+               goto out_unregister_template;
+
        blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
        fc_lport_iterate(ft_lport_add, NULL);
        return 0;
+
+out_unregister_template:
+       target_unregister_template(&ft_fabric_ops);
+out:
+       return ret;
 }
 
 static void __exit ft_exit(void)
@@ -630,7 +587,7 @@ static void __exit ft_exit(void)
                                           &ft_notifier);
        fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
        fc_lport_iterate(ft_lport_del, NULL);
-       ft_deregister_configfs();
+       target_unregister_template(&ft_fabric_ops);
        synchronize_rcu();
 }