Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD |
| 3 | # |
| 4 | # Copyright (c) 2010 Rising Tide Systems |
| 5 | # Copyright (c) 2010 Linux-iSCSI.org |
| 6 | # |
| 7 | # Author: nab@kernel.org |
| 8 | # |
| 9 | import os, sys |
| 10 | import subprocess as sub |
| 11 | import string |
| 12 | import re |
| 13 | import optparse |
| 14 | |
| 15 | tcm_dir = "" |
| 16 | |
| 17 | fabric_ops = [] |
| 18 | fabric_mod_dir = "" |
| 19 | fabric_mod_port = "" |
| 20 | fabric_mod_init_port = "" |
| 21 | |
| 22 | def tcm_mod_err(msg): |
| 23 | print msg |
| 24 | sys.exit(1) |
| 25 | |
| 26 | def tcm_mod_create_module_subdir(fabric_mod_dir_var): |
| 27 | |
| 28 | if os.path.isdir(fabric_mod_dir_var) == True: |
| 29 | return 1 |
| 30 | |
| 31 | print "Creating fabric_mod_dir: " + fabric_mod_dir_var |
| 32 | ret = os.mkdir(fabric_mod_dir_var) |
| 33 | if ret: |
| 34 | tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var) |
| 35 | |
| 36 | return |
| 37 | |
| 38 | def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name): |
| 39 | global fabric_mod_port |
| 40 | global fabric_mod_init_port |
| 41 | buf = "" |
| 42 | |
| 43 | f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" |
| 44 | print "Writing file: " + f |
| 45 | |
| 46 | p = open(f, 'w'); |
| 47 | if not p: |
| 48 | tcm_mod_err("Unable to open file: " + f) |
| 49 | |
| 50 | buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" |
| 51 | buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" |
| 52 | buf += "\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 53 | buf += "struct " + fabric_mod_name + "_tpg {\n" |
| 54 | buf += " /* FC lport target portal group tag for TCM */\n" |
| 55 | buf += " u16 lport_tpgt;\n" |
| 56 | buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" |
| 57 | buf += " struct " + fabric_mod_name + "_lport *lport;\n" |
| 58 | buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" |
| 59 | buf += " struct se_portal_group se_tpg;\n" |
| 60 | buf += "};\n" |
| 61 | buf += "\n" |
| 62 | buf += "struct " + fabric_mod_name + "_lport {\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 63 | buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" |
| 64 | buf += " u64 lport_wwpn;\n" |
| 65 | buf += " /* ASCII formatted WWPN for FC Target Lport */\n" |
| 66 | buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" |
| 67 | buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" |
| 68 | buf += " struct se_wwn lport_wwn;\n" |
| 69 | buf += "};\n" |
| 70 | |
| 71 | ret = p.write(buf) |
| 72 | if ret: |
| 73 | tcm_mod_err("Unable to write f: " + f) |
| 74 | |
| 75 | p.close() |
| 76 | |
| 77 | fabric_mod_port = "lport" |
| 78 | fabric_mod_init_port = "nport" |
| 79 | |
| 80 | return |
| 81 | |
| 82 | def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name): |
| 83 | global fabric_mod_port |
| 84 | global fabric_mod_init_port |
| 85 | buf = "" |
| 86 | |
| 87 | f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" |
| 88 | print "Writing file: " + f |
| 89 | |
| 90 | p = open(f, 'w'); |
| 91 | if not p: |
| 92 | tcm_mod_err("Unable to open file: " + f) |
| 93 | |
| 94 | buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" |
| 95 | buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" |
| 96 | buf += "\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 97 | buf += "struct " + fabric_mod_name + "_tpg {\n" |
| 98 | buf += " /* SAS port target portal group tag for TCM */\n" |
| 99 | buf += " u16 tport_tpgt;\n" |
| 100 | buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" |
| 101 | buf += " struct " + fabric_mod_name + "_tport *tport;\n" |
| 102 | buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" |
| 103 | buf += " struct se_portal_group se_tpg;\n" |
| 104 | buf += "};\n\n" |
| 105 | buf += "struct " + fabric_mod_name + "_tport {\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 106 | buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" |
| 107 | buf += " u64 tport_wwpn;\n" |
| 108 | buf += " /* ASCII formatted WWPN for SAS Target port */\n" |
| 109 | buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" |
| 110 | buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" |
| 111 | buf += " struct se_wwn tport_wwn;\n" |
| 112 | buf += "};\n" |
| 113 | |
| 114 | ret = p.write(buf) |
| 115 | if ret: |
| 116 | tcm_mod_err("Unable to write f: " + f) |
| 117 | |
| 118 | p.close() |
| 119 | |
| 120 | fabric_mod_port = "tport" |
| 121 | fabric_mod_init_port = "iport" |
| 122 | |
| 123 | return |
| 124 | |
| 125 | def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name): |
| 126 | global fabric_mod_port |
| 127 | global fabric_mod_init_port |
| 128 | buf = "" |
| 129 | |
| 130 | f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" |
| 131 | print "Writing file: " + f |
| 132 | |
| 133 | p = open(f, 'w'); |
| 134 | if not p: |
| 135 | tcm_mod_err("Unable to open file: " + f) |
| 136 | |
| 137 | buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" |
| 138 | buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" |
| 139 | buf += "\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 140 | buf += "struct " + fabric_mod_name + "_tpg {\n" |
| 141 | buf += " /* iSCSI target portal group tag for TCM */\n" |
| 142 | buf += " u16 tport_tpgt;\n" |
| 143 | buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" |
| 144 | buf += " struct " + fabric_mod_name + "_tport *tport;\n" |
| 145 | buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" |
| 146 | buf += " struct se_portal_group se_tpg;\n" |
| 147 | buf += "};\n\n" |
| 148 | buf += "struct " + fabric_mod_name + "_tport {\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 149 | buf += " /* ASCII formatted TargetName for IQN */\n" |
| 150 | buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" |
| 151 | buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" |
| 152 | buf += " struct se_wwn tport_wwn;\n" |
| 153 | buf += "};\n" |
| 154 | |
| 155 | ret = p.write(buf) |
| 156 | if ret: |
| 157 | tcm_mod_err("Unable to write f: " + f) |
| 158 | |
| 159 | p.close() |
| 160 | |
| 161 | fabric_mod_port = "tport" |
| 162 | fabric_mod_init_port = "iport" |
| 163 | |
| 164 | return |
| 165 | |
| 166 | def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name): |
| 167 | |
| 168 | if proto_ident == "FC": |
| 169 | tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name) |
| 170 | elif proto_ident == "SAS": |
| 171 | tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name) |
| 172 | elif proto_ident == "iSCSI": |
| 173 | tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name) |
| 174 | else: |
| 175 | print "Unsupported proto_ident: " + proto_ident |
| 176 | sys.exit(1) |
| 177 | |
| 178 | return |
| 179 | |
| 180 | def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name): |
| 181 | buf = "" |
| 182 | |
| 183 | f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c" |
| 184 | print "Writing file: " + f |
| 185 | |
| 186 | p = open(f, 'w'); |
| 187 | if not p: |
| 188 | tcm_mod_err("Unable to open file: " + f) |
| 189 | |
| 190 | buf = "#include <linux/module.h>\n" |
| 191 | buf += "#include <linux/moduleparam.h>\n" |
| 192 | buf += "#include <linux/version.h>\n" |
| 193 | buf += "#include <generated/utsrelease.h>\n" |
| 194 | buf += "#include <linux/utsname.h>\n" |
| 195 | buf += "#include <linux/init.h>\n" |
| 196 | buf += "#include <linux/slab.h>\n" |
| 197 | buf += "#include <linux/kthread.h>\n" |
| 198 | buf += "#include <linux/types.h>\n" |
| 199 | buf += "#include <linux/string.h>\n" |
| 200 | buf += "#include <linux/configfs.h>\n" |
| 201 | buf += "#include <linux/ctype.h>\n" |
| 202 | buf += "#include <asm/unaligned.h>\n\n" |
| 203 | buf += "#include <target/target_core_base.h>\n" |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 204 | buf += "#include <target/target_core_fabric.h>\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 205 | buf += "#include <target/target_core_fabric_configfs.h>\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 206 | buf += "#include <target/target_core_configfs.h>\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 207 | buf += "#include <target/configfs_macros.h>\n\n" |
Nicholas Bellinger | 10635c8 | 2011-03-14 04:05:57 -0700 | [diff] [blame] | 208 | buf += "#include \"" + fabric_mod_name + "_base.h\"\n" |
| 209 | buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 210 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 211 | buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 212 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 213 | buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n" |
| 214 | buf += " struct se_wwn *wwn,\n" |
| 215 | buf += " struct config_group *group,\n" |
| 216 | buf += " const char *name)\n" |
| 217 | buf += "{\n" |
| 218 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n" |
| 219 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n" |
| 220 | buf += " struct " + fabric_mod_name + "_tpg *tpg;\n" |
| 221 | buf += " unsigned long tpgt;\n" |
| 222 | buf += " int ret;\n\n" |
| 223 | buf += " if (strstr(name, \"tpgt_\") != name)\n" |
| 224 | buf += " return ERR_PTR(-EINVAL);\n" |
Jingoo Han | 0ab943b | 2013-07-31 14:59:16 -0700 | [diff] [blame] | 225 | buf += " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 226 | buf += " return ERR_PTR(-EINVAL);\n\n" |
| 227 | buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n" |
Sebastian Andrzej Siewior | ced38c8 | 2011-12-06 11:20:31 +0100 | [diff] [blame] | 228 | buf += " if (!tpg) {\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 229 | buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n" |
| 230 | buf += " return ERR_PTR(-ENOMEM);\n" |
| 231 | buf += " }\n" |
| 232 | buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n" |
| 233 | buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 234 | buf += " ret = core_tpg_register(&" + fabric_mod_name + "_ops, wwn,\n" |
Christoph Hellwig | e4aae5a | 2015-05-01 17:47:56 +0200 | [diff] [blame] | 235 | buf += " &tpg->se_tpg, SCSI_PROTOCOL_SAS);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 236 | buf += " if (ret < 0) {\n" |
| 237 | buf += " kfree(tpg);\n" |
| 238 | buf += " return NULL;\n" |
| 239 | buf += " }\n" |
| 240 | buf += " return &tpg->se_tpg;\n" |
| 241 | buf += "}\n\n" |
| 242 | buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n" |
| 243 | buf += "{\n" |
| 244 | buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" |
| 245 | buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n" |
| 246 | buf += " core_tpg_deregister(se_tpg);\n" |
| 247 | buf += " kfree(tpg);\n" |
| 248 | buf += "}\n\n" |
| 249 | |
| 250 | buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n" |
| 251 | buf += " struct target_fabric_configfs *tf,\n" |
| 252 | buf += " struct config_group *group,\n" |
| 253 | buf += " const char *name)\n" |
| 254 | buf += "{\n" |
| 255 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n" |
| 256 | |
| 257 | if proto_ident == "FC" or proto_ident == "SAS": |
| 258 | buf += " u64 wwpn = 0;\n\n" |
| 259 | |
| 260 | buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n" |
| 261 | buf += " return ERR_PTR(-EINVAL); */\n\n" |
| 262 | buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n" |
Sebastian Andrzej Siewior | ced38c8 | 2011-12-06 11:20:31 +0100 | [diff] [blame] | 263 | buf += " if (!" + fabric_mod_port + ") {\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 264 | buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n" |
| 265 | buf += " return ERR_PTR(-ENOMEM);\n" |
| 266 | buf += " }\n" |
| 267 | |
| 268 | if proto_ident == "FC" or proto_ident == "SAS": |
| 269 | buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n" |
| 270 | |
Sebastian Andrzej Siewior | ced38c8 | 2011-12-06 11:20:31 +0100 | [diff] [blame] | 271 | buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 272 | buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n" |
| 273 | buf += "}\n\n" |
| 274 | buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n" |
| 275 | buf += "{\n" |
| 276 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n" |
| 277 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" |
| 278 | buf += " kfree(" + fabric_mod_port + ");\n" |
| 279 | buf += "}\n\n" |
| 280 | buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n" |
| 281 | buf += " struct target_fabric_configfs *tf,\n" |
| 282 | buf += " char *page)\n" |
| 283 | buf += "{\n" |
| 284 | buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n" |
| 285 | buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n" |
| 286 | buf += " utsname()->machine);\n" |
| 287 | buf += "}\n\n" |
| 288 | buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n" |
| 289 | buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n" |
| 290 | buf += " &" + fabric_mod_name + "_wwn_version.attr,\n" |
| 291 | buf += " NULL,\n" |
| 292 | buf += "};\n\n" |
| 293 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 294 | buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" |
Christoph Hellwig | 65204c8 | 2015-04-15 09:04:41 +0200 | [diff] [blame] | 295 | buf += " .module = THIS_MODULE,\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 296 | buf += " .name = " + fabric_mod_name + ",\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 297 | buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 298 | buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" |
| 299 | buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 300 | buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" |
| 301 | buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" |
| 302 | buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" |
| 303 | buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 304 | buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n" |
Nicholas Bellinger | 77271de | 2011-11-28 17:54:28 -0800 | [diff] [blame] | 305 | buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 306 | buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n" |
| 307 | buf += " .close_session = " + fabric_mod_name + "_close_session,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 308 | buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n" |
| 309 | buf += " .sess_get_initiator_sid = NULL,\n" |
| 310 | buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" |
| 311 | buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n" |
| 312 | buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n" |
| 313 | buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n" |
| 314 | buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 315 | buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" |
| 316 | buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" |
| 317 | buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 318 | buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 319 | buf += " /*\n" |
| 320 | buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n" |
| 321 | buf += " */\n" |
| 322 | buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n" |
| 323 | buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" |
| 324 | buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" |
| 325 | buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 326 | buf += "\n" |
| 327 | buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs;\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 328 | buf += "};\n\n" |
| 329 | |
| 330 | buf += "static int __init " + fabric_mod_name + "_init(void)\n" |
| 331 | buf += "{\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 332 | buf += " return target_register_template(" + fabric_mod_name + "_ops);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 333 | buf += "};\n\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 334 | |
Sebastian Andrzej Siewior | ced38c8 | 2011-12-06 11:20:31 +0100 | [diff] [blame] | 335 | buf += "static void __exit " + fabric_mod_name + "_exit(void)\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 336 | buf += "{\n" |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 337 | buf += " target_unregister_template(" + fabric_mod_name + "_ops);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 338 | buf += "};\n\n" |
| 339 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 340 | buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n" |
| 341 | buf += "MODULE_LICENSE(\"GPL\");\n" |
| 342 | buf += "module_init(" + fabric_mod_name + "_init);\n" |
| 343 | buf += "module_exit(" + fabric_mod_name + "_exit);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 344 | |
| 345 | ret = p.write(buf) |
| 346 | if ret: |
| 347 | tcm_mod_err("Unable to write f: " + f) |
| 348 | |
| 349 | p.close() |
| 350 | |
| 351 | return |
| 352 | |
| 353 | def tcm_mod_scan_fabric_ops(tcm_dir): |
| 354 | |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 355 | fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 356 | |
| 357 | print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api |
| 358 | process_fo = 0; |
| 359 | |
| 360 | p = open(fabric_ops_api, 'r') |
| 361 | |
| 362 | line = p.readline() |
| 363 | while line: |
| 364 | if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): |
| 365 | line = p.readline() |
| 366 | continue |
| 367 | |
| 368 | if process_fo == 0: |
| 369 | process_fo = 1; |
| 370 | line = p.readline() |
| 371 | # Search for function pointer |
| 372 | if not re.search('\(\*', line): |
| 373 | continue |
| 374 | |
| 375 | fabric_ops.append(line.rstrip()) |
| 376 | continue |
| 377 | |
| 378 | line = p.readline() |
| 379 | # Search for function pointer |
| 380 | if not re.search('\(\*', line): |
| 381 | continue |
| 382 | |
| 383 | fabric_ops.append(line.rstrip()) |
| 384 | |
| 385 | p.close() |
| 386 | return |
| 387 | |
| 388 | def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name): |
| 389 | buf = "" |
| 390 | bufi = "" |
| 391 | |
| 392 | f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c" |
| 393 | print "Writing file: " + f |
| 394 | |
| 395 | p = open(f, 'w') |
| 396 | if not p: |
| 397 | tcm_mod_err("Unable to open file: " + f) |
| 398 | |
| 399 | fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h" |
| 400 | print "Writing file: " + fi |
| 401 | |
| 402 | pi = open(fi, 'w') |
| 403 | if not pi: |
| 404 | tcm_mod_err("Unable to open file: " + fi) |
| 405 | |
| 406 | buf = "#include <linux/slab.h>\n" |
| 407 | buf += "#include <linux/kthread.h>\n" |
| 408 | buf += "#include <linux/types.h>\n" |
| 409 | buf += "#include <linux/list.h>\n" |
| 410 | buf += "#include <linux/types.h>\n" |
| 411 | buf += "#include <linux/string.h>\n" |
| 412 | buf += "#include <linux/ctype.h>\n" |
| 413 | buf += "#include <asm/unaligned.h>\n" |
| 414 | buf += "#include <scsi/scsi.h>\n" |
| 415 | buf += "#include <scsi/scsi_host.h>\n" |
| 416 | buf += "#include <scsi/scsi_device.h>\n" |
| 417 | buf += "#include <scsi/scsi_cmnd.h>\n" |
| 418 | buf += "#include <scsi/libfc.h>\n\n" |
| 419 | buf += "#include <target/target_core_base.h>\n" |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 420 | buf += "#include <target/target_core_fabric.h>\n" |
Nicholas Bellinger | 10635c8 | 2011-03-14 04:05:57 -0700 | [diff] [blame] | 421 | buf += "#include <target/target_core_configfs.h>\n\n" |
| 422 | buf += "#include \"" + fabric_mod_name + "_base.h\"\n" |
| 423 | buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 424 | |
| 425 | buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n" |
| 426 | buf += "{\n" |
| 427 | buf += " return 1;\n" |
| 428 | buf += "}\n\n" |
| 429 | bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n" |
| 430 | |
| 431 | buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n" |
| 432 | buf += "{\n" |
| 433 | buf += " return 0;\n" |
| 434 | buf += "}\n\n" |
| 435 | bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n" |
| 436 | |
| 437 | total_fabric_ops = len(fabric_ops) |
| 438 | i = 0 |
| 439 | |
| 440 | while i < total_fabric_ops: |
| 441 | fo = fabric_ops[i] |
| 442 | i += 1 |
| 443 | # print "fabric_ops: " + fo |
| 444 | |
| 445 | if re.search('get_fabric_name', fo): |
| 446 | buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n" |
| 447 | buf += "{\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 448 | buf += " return \"" + fabric_mod_name + "\";\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 449 | buf += "}\n\n" |
| 450 | bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n" |
| 451 | continue |
| 452 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 453 | if re.search('get_wwn', fo): |
| 454 | buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n" |
| 455 | buf += "{\n" |
| 456 | buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" |
| 457 | buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" |
| 458 | buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n" |
| 459 | buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n" |
| 460 | buf += "}\n\n" |
| 461 | bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n" |
| 462 | |
| 463 | if re.search('get_tag', fo): |
| 464 | buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n" |
| 465 | buf += "{\n" |
| 466 | buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" |
| 467 | buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" |
| 468 | buf += " return tpg->" + fabric_mod_port + "_tpgt;\n" |
| 469 | buf += "}\n\n" |
| 470 | bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n" |
| 471 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 472 | if re.search('tpg_get_inst_index\)\(', fo): |
| 473 | buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n" |
| 474 | buf += "{\n" |
| 475 | buf += " return 1;\n" |
| 476 | buf += "}\n\n" |
| 477 | bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n" |
| 478 | |
Nicholas Bellinger | 77271de | 2011-11-28 17:54:28 -0800 | [diff] [blame] | 479 | if re.search('\*release_cmd\)\(', fo): |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 480 | buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n" |
| 481 | buf += "{\n" |
| 482 | buf += " return;\n" |
| 483 | buf += "}\n\n" |
| 484 | bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n" |
| 485 | |
| 486 | if re.search('shutdown_session\)\(', fo): |
| 487 | buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n" |
| 488 | buf += "{\n" |
| 489 | buf += " return 0;\n" |
| 490 | buf += "}\n\n" |
| 491 | bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n" |
| 492 | |
| 493 | if re.search('close_session\)\(', fo): |
| 494 | buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n" |
| 495 | buf += "{\n" |
| 496 | buf += " return;\n" |
| 497 | buf += "}\n\n" |
| 498 | bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n" |
| 499 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 500 | if re.search('sess_get_index\)\(', fo): |
| 501 | buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n" |
| 502 | buf += "{\n" |
| 503 | buf += " return 0;\n" |
| 504 | buf += "}\n\n" |
| 505 | bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n" |
| 506 | |
| 507 | if re.search('write_pending\)\(', fo): |
| 508 | buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n" |
| 509 | buf += "{\n" |
| 510 | buf += " return 0;\n" |
| 511 | buf += "}\n\n" |
| 512 | bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n" |
| 513 | |
| 514 | if re.search('write_pending_status\)\(', fo): |
| 515 | buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n" |
| 516 | buf += "{\n" |
| 517 | buf += " return 0;\n" |
| 518 | buf += "}\n\n" |
| 519 | bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n" |
| 520 | |
| 521 | if re.search('set_default_node_attributes\)\(', fo): |
| 522 | buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n" |
| 523 | buf += "{\n" |
| 524 | buf += " return;\n" |
| 525 | buf += "}\n\n" |
| 526 | bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n" |
| 527 | |
| 528 | if re.search('get_task_tag\)\(', fo): |
| 529 | buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n" |
| 530 | buf += "{\n" |
| 531 | buf += " return 0;\n" |
| 532 | buf += "}\n\n" |
| 533 | bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n" |
| 534 | |
| 535 | if re.search('get_cmd_state\)\(', fo): |
| 536 | buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n" |
| 537 | buf += "{\n" |
| 538 | buf += " return 0;\n" |
| 539 | buf += "}\n\n" |
| 540 | bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n" |
| 541 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 542 | if re.search('queue_data_in\)\(', fo): |
| 543 | buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n" |
| 544 | buf += "{\n" |
| 545 | buf += " return 0;\n" |
| 546 | buf += "}\n\n" |
| 547 | bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n" |
| 548 | |
| 549 | if re.search('queue_status\)\(', fo): |
| 550 | buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n" |
| 551 | buf += "{\n" |
| 552 | buf += " return 0;\n" |
| 553 | buf += "}\n\n" |
| 554 | bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n" |
| 555 | |
| 556 | if re.search('queue_tm_rsp\)\(', fo): |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 557 | buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 558 | buf += "{\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 559 | buf += " return;\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 560 | buf += "}\n\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 561 | bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 562 | |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 563 | if re.search('aborted_task\)\(', fo): |
| 564 | buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 565 | buf += "{\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 566 | buf += " return;\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 567 | buf += "}\n\n" |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 568 | bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 569 | |
| 570 | ret = p.write(buf) |
| 571 | if ret: |
| 572 | tcm_mod_err("Unable to write f: " + f) |
| 573 | |
| 574 | p.close() |
| 575 | |
| 576 | ret = pi.write(bufi) |
| 577 | if ret: |
| 578 | tcm_mod_err("Unable to write fi: " + fi) |
| 579 | |
| 580 | pi.close() |
| 581 | return |
| 582 | |
| 583 | def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name): |
| 584 | |
| 585 | buf = "" |
Nicholas Bellinger | 10635c8 | 2011-03-14 04:05:57 -0700 | [diff] [blame] | 586 | f = fabric_mod_dir_var + "/Makefile" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 587 | print "Writing file: " + f |
| 588 | |
| 589 | p = open(f, 'w') |
| 590 | if not p: |
| 591 | tcm_mod_err("Unable to open file: " + f) |
| 592 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 593 | buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n" |
| 594 | buf += " " + fabric_mod_name + "_configfs.o\n" |
| 595 | buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n" |
| 596 | |
| 597 | ret = p.write(buf) |
| 598 | if ret: |
| 599 | tcm_mod_err("Unable to write f: " + f) |
| 600 | |
| 601 | p.close() |
| 602 | return |
| 603 | |
| 604 | def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name): |
| 605 | |
| 606 | buf = "" |
| 607 | f = fabric_mod_dir_var + "/Kconfig" |
| 608 | print "Writing file: " + f |
| 609 | |
| 610 | p = open(f, 'w') |
| 611 | if not p: |
| 612 | tcm_mod_err("Unable to open file: " + f) |
| 613 | |
| 614 | buf = "config " + fabric_mod_name.upper() + "\n" |
| 615 | buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n" |
| 616 | buf += " depends on TARGET_CORE && CONFIGFS_FS\n" |
| 617 | buf += " default n\n" |
| 618 | buf += " ---help---\n" |
| 619 | buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n" |
| 620 | |
| 621 | ret = p.write(buf) |
| 622 | if ret: |
| 623 | tcm_mod_err("Unable to write f: " + f) |
| 624 | |
| 625 | p.close() |
| 626 | return |
| 627 | |
| 628 | def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name): |
| 629 | buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n" |
Nicholas Bellinger | 10635c8 | 2011-03-14 04:05:57 -0700 | [diff] [blame] | 630 | kbuild = tcm_dir + "/drivers/target/Makefile" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 631 | |
| 632 | f = open(kbuild, 'a') |
| 633 | f.write(buf) |
| 634 | f.close() |
| 635 | return |
| 636 | |
| 637 | def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name): |
| 638 | buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n" |
| 639 | kconfig = tcm_dir + "/drivers/target/Kconfig" |
| 640 | |
| 641 | f = open(kconfig, 'a') |
| 642 | f.write(buf) |
| 643 | f.close() |
| 644 | return |
| 645 | |
| 646 | def main(modname, proto_ident): |
| 647 | # proto_ident = "FC" |
| 648 | # proto_ident = "SAS" |
| 649 | # proto_ident = "iSCSI" |
| 650 | |
| 651 | tcm_dir = os.getcwd(); |
| 652 | tcm_dir += "/../../" |
| 653 | print "tcm_dir: " + tcm_dir |
| 654 | fabric_mod_name = modname |
| 655 | fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name |
| 656 | print "Set fabric_mod_name: " + fabric_mod_name |
| 657 | print "Set fabric_mod_dir: " + fabric_mod_dir |
| 658 | print "Using proto_ident: " + proto_ident |
| 659 | |
| 660 | if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI": |
| 661 | print "Unsupported proto_ident: " + proto_ident |
| 662 | sys.exit(1) |
| 663 | |
| 664 | ret = tcm_mod_create_module_subdir(fabric_mod_dir) |
| 665 | if ret: |
| 666 | print "tcm_mod_create_module_subdir() failed because module already exists!" |
| 667 | sys.exit(1) |
| 668 | |
| 669 | tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name) |
| 670 | tcm_mod_scan_fabric_ops(tcm_dir) |
| 671 | tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name) |
| 672 | tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name) |
| 673 | tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name) |
| 674 | tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name) |
| 675 | |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 676 | input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ") |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 677 | if input == "yes" or input == "y": |
| 678 | tcm_mod_add_kbuild(tcm_dir, fabric_mod_name) |
| 679 | |
Nicholas Bellinger | 67e51da | 2014-12-23 00:32:21 -0800 | [diff] [blame] | 680 | input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ") |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 681 | if input == "yes" or input == "y": |
| 682 | tcm_mod_add_kconfig(tcm_dir, fabric_mod_name) |
| 683 | |
| 684 | return |
| 685 | |
| 686 | parser = optparse.OptionParser() |
| 687 | parser.add_option('-m', '--modulename', help='Module name', dest='modname', |
| 688 | action='store', nargs=1, type='string') |
| 689 | parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident', |
| 690 | action='store', nargs=1, type='string') |
| 691 | |
| 692 | (opts, args) = parser.parse_args() |
| 693 | |
| 694 | mandatories = ['modname', 'protoident'] |
| 695 | for m in mandatories: |
| 696 | if not opts.__dict__[m]: |
| 697 | print "mandatory option is missing\n" |
| 698 | parser.print_help() |
| 699 | exit(-1) |
| 700 | |
| 701 | if __name__ == "__main__": |
| 702 | |
| 703 | main(str(opts.modname), opts.protoident) |