18c2ecf20Sopenharmony_ci#!/usr/bin/env python 28c2ecf20Sopenharmony_ci# The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# Copyright (c) 2010 Rising Tide Systems 58c2ecf20Sopenharmony_ci# Copyright (c) 2010 Linux-iSCSI.org 68c2ecf20Sopenharmony_ci# 78c2ecf20Sopenharmony_ci# Author: nab@kernel.org 88c2ecf20Sopenharmony_ci# 98c2ecf20Sopenharmony_ciimport os, sys 108c2ecf20Sopenharmony_ciimport subprocess as sub 118c2ecf20Sopenharmony_ciimport string 128c2ecf20Sopenharmony_ciimport re 138c2ecf20Sopenharmony_ciimport optparse 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_citcm_dir = "" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cifabric_ops = [] 188c2ecf20Sopenharmony_cifabric_mod_dir = "" 198c2ecf20Sopenharmony_cifabric_mod_port = "" 208c2ecf20Sopenharmony_cifabric_mod_init_port = "" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cidef tcm_mod_err(msg): 238c2ecf20Sopenharmony_ci print msg 248c2ecf20Sopenharmony_ci sys.exit(1) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cidef tcm_mod_create_module_subdir(fabric_mod_dir_var): 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci if os.path.isdir(fabric_mod_dir_var) == True: 298c2ecf20Sopenharmony_ci return 1 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci print "Creating fabric_mod_dir: " + fabric_mod_dir_var 328c2ecf20Sopenharmony_ci ret = os.mkdir(fabric_mod_dir_var) 338c2ecf20Sopenharmony_ci if ret: 348c2ecf20Sopenharmony_ci tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci return 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cidef tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name): 398c2ecf20Sopenharmony_ci global fabric_mod_port 408c2ecf20Sopenharmony_ci global fabric_mod_init_port 418c2ecf20Sopenharmony_ci buf = "" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" 448c2ecf20Sopenharmony_ci print "Writing file: " + f 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci p = open(f, 'w'); 478c2ecf20Sopenharmony_ci if not p: 488c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 518c2ecf20Sopenharmony_ci buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 528c2ecf20Sopenharmony_ci buf += "\n" 538c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_tpg {\n" 548c2ecf20Sopenharmony_ci buf += " /* FC lport target portal group tag for TCM */\n" 558c2ecf20Sopenharmony_ci buf += " u16 lport_tpgt;\n" 568c2ecf20Sopenharmony_ci buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" 578c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_lport *lport;\n" 588c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" 598c2ecf20Sopenharmony_ci buf += " struct se_portal_group se_tpg;\n" 608c2ecf20Sopenharmony_ci buf += "};\n" 618c2ecf20Sopenharmony_ci buf += "\n" 628c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_lport {\n" 638c2ecf20Sopenharmony_ci buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" 648c2ecf20Sopenharmony_ci buf += " u64 lport_wwpn;\n" 658c2ecf20Sopenharmony_ci buf += " /* ASCII formatted WWPN for FC Target Lport */\n" 668c2ecf20Sopenharmony_ci buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 678c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" 688c2ecf20Sopenharmony_ci buf += " struct se_wwn lport_wwn;\n" 698c2ecf20Sopenharmony_ci buf += "};\n" 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci ret = p.write(buf) 728c2ecf20Sopenharmony_ci if ret: 738c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci p.close() 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci fabric_mod_port = "lport" 788c2ecf20Sopenharmony_ci fabric_mod_init_port = "nport" 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci return 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cidef tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name): 838c2ecf20Sopenharmony_ci global fabric_mod_port 848c2ecf20Sopenharmony_ci global fabric_mod_init_port 858c2ecf20Sopenharmony_ci buf = "" 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" 888c2ecf20Sopenharmony_ci print "Writing file: " + f 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci p = open(f, 'w'); 918c2ecf20Sopenharmony_ci if not p: 928c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 958c2ecf20Sopenharmony_ci buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 968c2ecf20Sopenharmony_ci buf += "\n" 978c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_tpg {\n" 988c2ecf20Sopenharmony_ci buf += " /* SAS port target portal group tag for TCM */\n" 998c2ecf20Sopenharmony_ci buf += " u16 tport_tpgt;\n" 1008c2ecf20Sopenharmony_ci buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" 1018c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tport *tport;\n" 1028c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" 1038c2ecf20Sopenharmony_ci buf += " struct se_portal_group se_tpg;\n" 1048c2ecf20Sopenharmony_ci buf += "};\n\n" 1058c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_tport {\n" 1068c2ecf20Sopenharmony_ci buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" 1078c2ecf20Sopenharmony_ci buf += " u64 tport_wwpn;\n" 1088c2ecf20Sopenharmony_ci buf += " /* ASCII formatted WWPN for SAS Target port */\n" 1098c2ecf20Sopenharmony_ci buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 1108c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" 1118c2ecf20Sopenharmony_ci buf += " struct se_wwn tport_wwn;\n" 1128c2ecf20Sopenharmony_ci buf += "};\n" 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci ret = p.write(buf) 1158c2ecf20Sopenharmony_ci if ret: 1168c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci p.close() 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci fabric_mod_port = "tport" 1218c2ecf20Sopenharmony_ci fabric_mod_init_port = "iport" 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci return 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cidef tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name): 1268c2ecf20Sopenharmony_ci global fabric_mod_port 1278c2ecf20Sopenharmony_ci global fabric_mod_init_port 1288c2ecf20Sopenharmony_ci buf = "" 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" 1318c2ecf20Sopenharmony_ci print "Writing file: " + f 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci p = open(f, 'w'); 1348c2ecf20Sopenharmony_ci if not p: 1358c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 1388c2ecf20Sopenharmony_ci buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 1398c2ecf20Sopenharmony_ci buf += "\n" 1408c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_tpg {\n" 1418c2ecf20Sopenharmony_ci buf += " /* iSCSI target portal group tag for TCM */\n" 1428c2ecf20Sopenharmony_ci buf += " u16 tport_tpgt;\n" 1438c2ecf20Sopenharmony_ci buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" 1448c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tport *tport;\n" 1458c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" 1468c2ecf20Sopenharmony_ci buf += " struct se_portal_group se_tpg;\n" 1478c2ecf20Sopenharmony_ci buf += "};\n\n" 1488c2ecf20Sopenharmony_ci buf += "struct " + fabric_mod_name + "_tport {\n" 1498c2ecf20Sopenharmony_ci buf += " /* ASCII formatted TargetName for IQN */\n" 1508c2ecf20Sopenharmony_ci buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 1518c2ecf20Sopenharmony_ci buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" 1528c2ecf20Sopenharmony_ci buf += " struct se_wwn tport_wwn;\n" 1538c2ecf20Sopenharmony_ci buf += "};\n" 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci ret = p.write(buf) 1568c2ecf20Sopenharmony_ci if ret: 1578c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci p.close() 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci fabric_mod_port = "tport" 1628c2ecf20Sopenharmony_ci fabric_mod_init_port = "iport" 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci return 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cidef tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name): 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci if proto_ident == "FC": 1698c2ecf20Sopenharmony_ci tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name) 1708c2ecf20Sopenharmony_ci elif proto_ident == "SAS": 1718c2ecf20Sopenharmony_ci tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name) 1728c2ecf20Sopenharmony_ci elif proto_ident == "iSCSI": 1738c2ecf20Sopenharmony_ci tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name) 1748c2ecf20Sopenharmony_ci else: 1758c2ecf20Sopenharmony_ci print "Unsupported proto_ident: " + proto_ident 1768c2ecf20Sopenharmony_ci sys.exit(1) 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci return 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cidef tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name): 1818c2ecf20Sopenharmony_ci buf = "" 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c" 1848c2ecf20Sopenharmony_ci print "Writing file: " + f 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci p = open(f, 'w'); 1878c2ecf20Sopenharmony_ci if not p: 1888c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci buf = "#include <linux/module.h>\n" 1918c2ecf20Sopenharmony_ci buf += "#include <linux/moduleparam.h>\n" 1928c2ecf20Sopenharmony_ci buf += "#include <linux/version.h>\n" 1938c2ecf20Sopenharmony_ci buf += "#include <generated/utsrelease.h>\n" 1948c2ecf20Sopenharmony_ci buf += "#include <linux/utsname.h>\n" 1958c2ecf20Sopenharmony_ci buf += "#include <linux/init.h>\n" 1968c2ecf20Sopenharmony_ci buf += "#include <linux/slab.h>\n" 1978c2ecf20Sopenharmony_ci buf += "#include <linux/kthread.h>\n" 1988c2ecf20Sopenharmony_ci buf += "#include <linux/types.h>\n" 1998c2ecf20Sopenharmony_ci buf += "#include <linux/string.h>\n" 2008c2ecf20Sopenharmony_ci buf += "#include <linux/configfs.h>\n" 2018c2ecf20Sopenharmony_ci buf += "#include <linux/ctype.h>\n" 2028c2ecf20Sopenharmony_ci buf += "#include <asm/unaligned.h>\n" 2038c2ecf20Sopenharmony_ci buf += "#include <scsi/scsi_proto.h>\n\n" 2048c2ecf20Sopenharmony_ci buf += "#include <target/target_core_base.h>\n" 2058c2ecf20Sopenharmony_ci buf += "#include <target/target_core_fabric.h>\n" 2068c2ecf20Sopenharmony_ci buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 2078c2ecf20Sopenharmony_ci buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n" 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n" 2128c2ecf20Sopenharmony_ci buf += " struct se_wwn *wwn,\n" 2138c2ecf20Sopenharmony_ci buf += " struct config_group *group,\n" 2148c2ecf20Sopenharmony_ci buf += " const char *name)\n" 2158c2ecf20Sopenharmony_ci buf += "{\n" 2168c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n" 2178c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n" 2188c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg *tpg;\n" 2198c2ecf20Sopenharmony_ci buf += " unsigned long tpgt;\n" 2208c2ecf20Sopenharmony_ci buf += " int ret;\n\n" 2218c2ecf20Sopenharmony_ci buf += " if (strstr(name, \"tpgt_\") != name)\n" 2228c2ecf20Sopenharmony_ci buf += " return ERR_PTR(-EINVAL);\n" 2238c2ecf20Sopenharmony_ci buf += " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n" 2248c2ecf20Sopenharmony_ci buf += " return ERR_PTR(-EINVAL);\n\n" 2258c2ecf20Sopenharmony_ci buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n" 2268c2ecf20Sopenharmony_ci buf += " if (!tpg) {\n" 2278c2ecf20Sopenharmony_ci buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n" 2288c2ecf20Sopenharmony_ci buf += " return ERR_PTR(-ENOMEM);\n" 2298c2ecf20Sopenharmony_ci buf += " }\n" 2308c2ecf20Sopenharmony_ci buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n" 2318c2ecf20Sopenharmony_ci buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n" 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci if proto_ident == "FC": 2348c2ecf20Sopenharmony_ci buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);\n" 2358c2ecf20Sopenharmony_ci elif proto_ident == "SAS": 2368c2ecf20Sopenharmony_ci buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS);\n" 2378c2ecf20Sopenharmony_ci elif proto_ident == "iSCSI": 2388c2ecf20Sopenharmony_ci buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_ISCSI);\n" 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci buf += " if (ret < 0) {\n" 2418c2ecf20Sopenharmony_ci buf += " kfree(tpg);\n" 2428c2ecf20Sopenharmony_ci buf += " return NULL;\n" 2438c2ecf20Sopenharmony_ci buf += " }\n" 2448c2ecf20Sopenharmony_ci buf += " return &tpg->se_tpg;\n" 2458c2ecf20Sopenharmony_ci buf += "}\n\n" 2468c2ecf20Sopenharmony_ci buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n" 2478c2ecf20Sopenharmony_ci buf += "{\n" 2488c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 2498c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n" 2508c2ecf20Sopenharmony_ci buf += " core_tpg_deregister(se_tpg);\n" 2518c2ecf20Sopenharmony_ci buf += " kfree(tpg);\n" 2528c2ecf20Sopenharmony_ci buf += "}\n\n" 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n" 2558c2ecf20Sopenharmony_ci buf += " struct target_fabric_configfs *tf,\n" 2568c2ecf20Sopenharmony_ci buf += " struct config_group *group,\n" 2578c2ecf20Sopenharmony_ci buf += " const char *name)\n" 2588c2ecf20Sopenharmony_ci buf += "{\n" 2598c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n" 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci if proto_ident == "FC" or proto_ident == "SAS": 2628c2ecf20Sopenharmony_ci buf += " u64 wwpn = 0;\n\n" 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n" 2658c2ecf20Sopenharmony_ci buf += " return ERR_PTR(-EINVAL); */\n\n" 2668c2ecf20Sopenharmony_ci buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n" 2678c2ecf20Sopenharmony_ci buf += " if (!" + fabric_mod_port + ") {\n" 2688c2ecf20Sopenharmony_ci buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n" 2698c2ecf20Sopenharmony_ci buf += " return ERR_PTR(-ENOMEM);\n" 2708c2ecf20Sopenharmony_ci buf += " }\n" 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci if proto_ident == "FC" or proto_ident == "SAS": 2738c2ecf20Sopenharmony_ci buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n" 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n" 2768c2ecf20Sopenharmony_ci buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n" 2778c2ecf20Sopenharmony_ci buf += "}\n\n" 2788c2ecf20Sopenharmony_ci buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n" 2798c2ecf20Sopenharmony_ci buf += "{\n" 2808c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n" 2818c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" 2828c2ecf20Sopenharmony_ci buf += " kfree(" + fabric_mod_port + ");\n" 2838c2ecf20Sopenharmony_ci buf += "}\n\n" 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" 2868c2ecf20Sopenharmony_ci buf += " .module = THIS_MODULE,\n" 2878c2ecf20Sopenharmony_ci buf += " .name = \"" + fabric_mod_name + "\",\n" 2888c2ecf20Sopenharmony_ci buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" 2898c2ecf20Sopenharmony_ci buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" 2908c2ecf20Sopenharmony_ci buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" 2918c2ecf20Sopenharmony_ci buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" 2928c2ecf20Sopenharmony_ci buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" 2938c2ecf20Sopenharmony_ci buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" 2948c2ecf20Sopenharmony_ci buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n" 2958c2ecf20Sopenharmony_ci buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n" 2968c2ecf20Sopenharmony_ci buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" 2978c2ecf20Sopenharmony_ci buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n" 2988c2ecf20Sopenharmony_ci buf += " .sess_get_initiator_sid = NULL,\n" 2998c2ecf20Sopenharmony_ci buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" 3008c2ecf20Sopenharmony_ci buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n" 3018c2ecf20Sopenharmony_ci buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n" 3028c2ecf20Sopenharmony_ci buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" 3038c2ecf20Sopenharmony_ci buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" 3048c2ecf20Sopenharmony_ci buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n" 3058c2ecf20Sopenharmony_ci buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n" 3068c2ecf20Sopenharmony_ci buf += " /*\n" 3078c2ecf20Sopenharmony_ci buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n" 3088c2ecf20Sopenharmony_ci buf += " */\n" 3098c2ecf20Sopenharmony_ci buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n" 3108c2ecf20Sopenharmony_ci buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" 3118c2ecf20Sopenharmony_ci buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" 3128c2ecf20Sopenharmony_ci buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" 3138c2ecf20Sopenharmony_ci buf += "};\n\n" 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci buf += "static int __init " + fabric_mod_name + "_init(void)\n" 3168c2ecf20Sopenharmony_ci buf += "{\n" 3178c2ecf20Sopenharmony_ci buf += " return target_register_template(&" + fabric_mod_name + "_ops);\n" 3188c2ecf20Sopenharmony_ci buf += "};\n\n" 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci buf += "static void __exit " + fabric_mod_name + "_exit(void)\n" 3218c2ecf20Sopenharmony_ci buf += "{\n" 3228c2ecf20Sopenharmony_ci buf += " target_unregister_template(&" + fabric_mod_name + "_ops);\n" 3238c2ecf20Sopenharmony_ci buf += "};\n\n" 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n" 3268c2ecf20Sopenharmony_ci buf += "MODULE_LICENSE(\"GPL\");\n" 3278c2ecf20Sopenharmony_ci buf += "module_init(" + fabric_mod_name + "_init);\n" 3288c2ecf20Sopenharmony_ci buf += "module_exit(" + fabric_mod_name + "_exit);\n" 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci ret = p.write(buf) 3318c2ecf20Sopenharmony_ci if ret: 3328c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci p.close() 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci return 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_cidef tcm_mod_scan_fabric_ops(tcm_dir): 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h" 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api 3438c2ecf20Sopenharmony_ci process_fo = 0; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci p = open(fabric_ops_api, 'r') 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci line = p.readline() 3488c2ecf20Sopenharmony_ci while line: 3498c2ecf20Sopenharmony_ci if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): 3508c2ecf20Sopenharmony_ci line = p.readline() 3518c2ecf20Sopenharmony_ci continue 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci if process_fo == 0: 3548c2ecf20Sopenharmony_ci process_fo = 1; 3558c2ecf20Sopenharmony_ci line = p.readline() 3568c2ecf20Sopenharmony_ci # Search for function pointer 3578c2ecf20Sopenharmony_ci if not re.search('\(\*', line): 3588c2ecf20Sopenharmony_ci continue 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci fabric_ops.append(line.rstrip()) 3618c2ecf20Sopenharmony_ci continue 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci line = p.readline() 3648c2ecf20Sopenharmony_ci # Search for function pointer 3658c2ecf20Sopenharmony_ci if not re.search('\(\*', line): 3668c2ecf20Sopenharmony_ci continue 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci fabric_ops.append(line.rstrip()) 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci p.close() 3718c2ecf20Sopenharmony_ci return 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_cidef tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name): 3748c2ecf20Sopenharmony_ci buf = "" 3758c2ecf20Sopenharmony_ci bufi = "" 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c" 3788c2ecf20Sopenharmony_ci print "Writing file: " + f 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci p = open(f, 'w') 3818c2ecf20Sopenharmony_ci if not p: 3828c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h" 3858c2ecf20Sopenharmony_ci print "Writing file: " + fi 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci pi = open(fi, 'w') 3888c2ecf20Sopenharmony_ci if not pi: 3898c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + fi) 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci buf = "#include <linux/slab.h>\n" 3928c2ecf20Sopenharmony_ci buf += "#include <linux/kthread.h>\n" 3938c2ecf20Sopenharmony_ci buf += "#include <linux/types.h>\n" 3948c2ecf20Sopenharmony_ci buf += "#include <linux/list.h>\n" 3958c2ecf20Sopenharmony_ci buf += "#include <linux/types.h>\n" 3968c2ecf20Sopenharmony_ci buf += "#include <linux/string.h>\n" 3978c2ecf20Sopenharmony_ci buf += "#include <linux/ctype.h>\n" 3988c2ecf20Sopenharmony_ci buf += "#include <asm/unaligned.h>\n" 3998c2ecf20Sopenharmony_ci buf += "#include <scsi/scsi_common.h>\n" 4008c2ecf20Sopenharmony_ci buf += "#include <scsi/scsi_proto.h>\n" 4018c2ecf20Sopenharmony_ci buf += "#include <target/target_core_base.h>\n" 4028c2ecf20Sopenharmony_ci buf += "#include <target/target_core_fabric.h>\n" 4038c2ecf20Sopenharmony_ci buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 4048c2ecf20Sopenharmony_ci buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n" 4078c2ecf20Sopenharmony_ci buf += "{\n" 4088c2ecf20Sopenharmony_ci buf += " return 1;\n" 4098c2ecf20Sopenharmony_ci buf += "}\n\n" 4108c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n" 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n" 4138c2ecf20Sopenharmony_ci buf += "{\n" 4148c2ecf20Sopenharmony_ci buf += " return 0;\n" 4158c2ecf20Sopenharmony_ci buf += "}\n\n" 4168c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n" 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci total_fabric_ops = len(fabric_ops) 4198c2ecf20Sopenharmony_ci i = 0 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci while i < total_fabric_ops: 4228c2ecf20Sopenharmony_ci fo = fabric_ops[i] 4238c2ecf20Sopenharmony_ci i += 1 4248c2ecf20Sopenharmony_ci# print "fabric_ops: " + fo 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci if re.search('get_fabric_name', fo): 4278c2ecf20Sopenharmony_ci buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n" 4288c2ecf20Sopenharmony_ci buf += "{\n" 4298c2ecf20Sopenharmony_ci buf += " return \"" + fabric_mod_name + "\";\n" 4308c2ecf20Sopenharmony_ci buf += "}\n\n" 4318c2ecf20Sopenharmony_ci bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n" 4328c2ecf20Sopenharmony_ci continue 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci if re.search('get_wwn', fo): 4358c2ecf20Sopenharmony_ci buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n" 4368c2ecf20Sopenharmony_ci buf += "{\n" 4378c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 4388c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 4398c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n" 4408c2ecf20Sopenharmony_ci buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n" 4418c2ecf20Sopenharmony_ci buf += "}\n\n" 4428c2ecf20Sopenharmony_ci bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n" 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci if re.search('get_tag', fo): 4458c2ecf20Sopenharmony_ci buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n" 4468c2ecf20Sopenharmony_ci buf += "{\n" 4478c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 4488c2ecf20Sopenharmony_ci buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 4498c2ecf20Sopenharmony_ci buf += " return tpg->" + fabric_mod_port + "_tpgt;\n" 4508c2ecf20Sopenharmony_ci buf += "}\n\n" 4518c2ecf20Sopenharmony_ci bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n" 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci if re.search('tpg_get_inst_index\)\(', fo): 4548c2ecf20Sopenharmony_ci buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n" 4558c2ecf20Sopenharmony_ci buf += "{\n" 4568c2ecf20Sopenharmony_ci buf += " return 1;\n" 4578c2ecf20Sopenharmony_ci buf += "}\n\n" 4588c2ecf20Sopenharmony_ci bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n" 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci if re.search('\*release_cmd\)\(', fo): 4618c2ecf20Sopenharmony_ci buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n" 4628c2ecf20Sopenharmony_ci buf += "{\n" 4638c2ecf20Sopenharmony_ci buf += " return;\n" 4648c2ecf20Sopenharmony_ci buf += "}\n\n" 4658c2ecf20Sopenharmony_ci bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n" 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci if re.search('sess_get_index\)\(', fo): 4688c2ecf20Sopenharmony_ci buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n" 4698c2ecf20Sopenharmony_ci buf += "{\n" 4708c2ecf20Sopenharmony_ci buf += " return 0;\n" 4718c2ecf20Sopenharmony_ci buf += "}\n\n" 4728c2ecf20Sopenharmony_ci bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n" 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci if re.search('write_pending\)\(', fo): 4758c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n" 4768c2ecf20Sopenharmony_ci buf += "{\n" 4778c2ecf20Sopenharmony_ci buf += " return 0;\n" 4788c2ecf20Sopenharmony_ci buf += "}\n\n" 4798c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n" 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci if re.search('set_default_node_attributes\)\(', fo): 4828c2ecf20Sopenharmony_ci buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n" 4838c2ecf20Sopenharmony_ci buf += "{\n" 4848c2ecf20Sopenharmony_ci buf += " return;\n" 4858c2ecf20Sopenharmony_ci buf += "}\n\n" 4868c2ecf20Sopenharmony_ci bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n" 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci if re.search('get_cmd_state\)\(', fo): 4898c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n" 4908c2ecf20Sopenharmony_ci buf += "{\n" 4918c2ecf20Sopenharmony_ci buf += " return 0;\n" 4928c2ecf20Sopenharmony_ci buf += "}\n\n" 4938c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n" 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci if re.search('queue_data_in\)\(', fo): 4968c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n" 4978c2ecf20Sopenharmony_ci buf += "{\n" 4988c2ecf20Sopenharmony_ci buf += " return 0;\n" 4998c2ecf20Sopenharmony_ci buf += "}\n\n" 5008c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n" 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci if re.search('queue_status\)\(', fo): 5038c2ecf20Sopenharmony_ci buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n" 5048c2ecf20Sopenharmony_ci buf += "{\n" 5058c2ecf20Sopenharmony_ci buf += " return 0;\n" 5068c2ecf20Sopenharmony_ci buf += "}\n\n" 5078c2ecf20Sopenharmony_ci bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n" 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci if re.search('queue_tm_rsp\)\(', fo): 5108c2ecf20Sopenharmony_ci buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n" 5118c2ecf20Sopenharmony_ci buf += "{\n" 5128c2ecf20Sopenharmony_ci buf += " return;\n" 5138c2ecf20Sopenharmony_ci buf += "}\n\n" 5148c2ecf20Sopenharmony_ci bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n" 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci if re.search('aborted_task\)\(', fo): 5178c2ecf20Sopenharmony_ci buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n" 5188c2ecf20Sopenharmony_ci buf += "{\n" 5198c2ecf20Sopenharmony_ci buf += " return;\n" 5208c2ecf20Sopenharmony_ci buf += "}\n\n" 5218c2ecf20Sopenharmony_ci bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n" 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci ret = p.write(buf) 5248c2ecf20Sopenharmony_ci if ret: 5258c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci p.close() 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci ret = pi.write(bufi) 5308c2ecf20Sopenharmony_ci if ret: 5318c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write fi: " + fi) 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci pi.close() 5348c2ecf20Sopenharmony_ci return 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_cidef tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name): 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci buf = "" 5398c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/Makefile" 5408c2ecf20Sopenharmony_ci print "Writing file: " + f 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci p = open(f, 'w') 5438c2ecf20Sopenharmony_ci if not p: 5448c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n" 5478c2ecf20Sopenharmony_ci buf += " " + fabric_mod_name + "_configfs.o\n" 5488c2ecf20Sopenharmony_ci buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n" 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci ret = p.write(buf) 5518c2ecf20Sopenharmony_ci if ret: 5528c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci p.close() 5558c2ecf20Sopenharmony_ci return 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_cidef tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name): 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci buf = "" 5608c2ecf20Sopenharmony_ci f = fabric_mod_dir_var + "/Kconfig" 5618c2ecf20Sopenharmony_ci print "Writing file: " + f 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci p = open(f, 'w') 5648c2ecf20Sopenharmony_ci if not p: 5658c2ecf20Sopenharmony_ci tcm_mod_err("Unable to open file: " + f) 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci buf = "config " + fabric_mod_name.upper() + "\n" 5688c2ecf20Sopenharmony_ci buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n" 5698c2ecf20Sopenharmony_ci buf += " depends on TARGET_CORE && CONFIGFS_FS\n" 5708c2ecf20Sopenharmony_ci buf += " default n\n" 5718c2ecf20Sopenharmony_ci buf += " help\n" 5728c2ecf20Sopenharmony_ci buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n" 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci ret = p.write(buf) 5758c2ecf20Sopenharmony_ci if ret: 5768c2ecf20Sopenharmony_ci tcm_mod_err("Unable to write f: " + f) 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci p.close() 5798c2ecf20Sopenharmony_ci return 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_cidef tcm_mod_add_kbuild(tcm_dir, fabric_mod_name): 5828c2ecf20Sopenharmony_ci buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n" 5838c2ecf20Sopenharmony_ci kbuild = tcm_dir + "/drivers/target/Makefile" 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci f = open(kbuild, 'a') 5868c2ecf20Sopenharmony_ci f.write(buf) 5878c2ecf20Sopenharmony_ci f.close() 5888c2ecf20Sopenharmony_ci return 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_cidef tcm_mod_add_kconfig(tcm_dir, fabric_mod_name): 5918c2ecf20Sopenharmony_ci buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n" 5928c2ecf20Sopenharmony_ci kconfig = tcm_dir + "/drivers/target/Kconfig" 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci f = open(kconfig, 'a') 5958c2ecf20Sopenharmony_ci f.write(buf) 5968c2ecf20Sopenharmony_ci f.close() 5978c2ecf20Sopenharmony_ci return 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_cidef main(modname, proto_ident): 6008c2ecf20Sopenharmony_ci# proto_ident = "FC" 6018c2ecf20Sopenharmony_ci# proto_ident = "SAS" 6028c2ecf20Sopenharmony_ci# proto_ident = "iSCSI" 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci tcm_dir = os.getcwd(); 6058c2ecf20Sopenharmony_ci tcm_dir += "/../../" 6068c2ecf20Sopenharmony_ci print "tcm_dir: " + tcm_dir 6078c2ecf20Sopenharmony_ci fabric_mod_name = modname 6088c2ecf20Sopenharmony_ci fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name 6098c2ecf20Sopenharmony_ci print "Set fabric_mod_name: " + fabric_mod_name 6108c2ecf20Sopenharmony_ci print "Set fabric_mod_dir: " + fabric_mod_dir 6118c2ecf20Sopenharmony_ci print "Using proto_ident: " + proto_ident 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI": 6148c2ecf20Sopenharmony_ci print "Unsupported proto_ident: " + proto_ident 6158c2ecf20Sopenharmony_ci sys.exit(1) 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci ret = tcm_mod_create_module_subdir(fabric_mod_dir) 6188c2ecf20Sopenharmony_ci if ret: 6198c2ecf20Sopenharmony_ci print "tcm_mod_create_module_subdir() failed because module already exists!" 6208c2ecf20Sopenharmony_ci sys.exit(1) 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name) 6238c2ecf20Sopenharmony_ci tcm_mod_scan_fabric_ops(tcm_dir) 6248c2ecf20Sopenharmony_ci tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name) 6258c2ecf20Sopenharmony_ci tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name) 6268c2ecf20Sopenharmony_ci tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name) 6278c2ecf20Sopenharmony_ci tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name) 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ") 6308c2ecf20Sopenharmony_ci if input == "yes" or input == "y": 6318c2ecf20Sopenharmony_ci tcm_mod_add_kbuild(tcm_dir, fabric_mod_name) 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ") 6348c2ecf20Sopenharmony_ci if input == "yes" or input == "y": 6358c2ecf20Sopenharmony_ci tcm_mod_add_kconfig(tcm_dir, fabric_mod_name) 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci return 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ciparser = optparse.OptionParser() 6408c2ecf20Sopenharmony_ciparser.add_option('-m', '--modulename', help='Module name', dest='modname', 6418c2ecf20Sopenharmony_ci action='store', nargs=1, type='string') 6428c2ecf20Sopenharmony_ciparser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident', 6438c2ecf20Sopenharmony_ci action='store', nargs=1, type='string') 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci(opts, args) = parser.parse_args() 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_cimandatories = ['modname', 'protoident'] 6488c2ecf20Sopenharmony_cifor m in mandatories: 6498c2ecf20Sopenharmony_ci if not opts.__dict__[m]: 6508c2ecf20Sopenharmony_ci print "mandatory option is missing\n" 6518c2ecf20Sopenharmony_ci parser.print_help() 6528c2ecf20Sopenharmony_ci exit(-1) 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ciif __name__ == "__main__": 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci main(str(opts.modname), opts.protoident) 657