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