aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/qla2xxx/tcm_qla2xxx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/qla2xxx/tcm_qla2xxx.c')
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c158
1 files changed, 115 insertions, 43 deletions
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 75a141bbe74d..788c4fe2b0c9 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -182,20 +182,6 @@ static int tcm_qla2xxx_npiv_parse_wwn(
182 return 0; 182 return 0;
183} 183}
184 184
185static ssize_t tcm_qla2xxx_npiv_format_wwn(char *buf, size_t len,
186 u64 wwpn, u64 wwnn)
187{
188 u8 b[8], b2[8];
189
190 put_unaligned_be64(wwpn, b);
191 put_unaligned_be64(wwnn, b2);
192 return snprintf(buf, len,
193 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x,"
194 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
195 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
196 b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], b2[6], b2[7]);
197}
198
199static char *tcm_qla2xxx_npiv_get_fabric_name(void) 185static char *tcm_qla2xxx_npiv_get_fabric_name(void)
200{ 186{
201 return "qla2xxx_npiv"; 187 return "qla2xxx_npiv";
@@ -227,15 +213,6 @@ static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg)
227 return lport->lport_naa_name; 213 return lport->lport_naa_name;
228} 214}
229 215
230static char *tcm_qla2xxx_npiv_get_fabric_wwn(struct se_portal_group *se_tpg)
231{
232 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
233 struct tcm_qla2xxx_tpg, se_tpg);
234 struct tcm_qla2xxx_lport *lport = tpg->lport;
235
236 return &lport->lport_npiv_name[0];
237}
238
239static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg) 216static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
240{ 217{
241 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 218 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
@@ -941,15 +918,41 @@ static ssize_t tcm_qla2xxx_tpg_show_enable(
941 atomic_read(&tpg->lport_tpg_enabled)); 918 atomic_read(&tpg->lport_tpg_enabled));
942} 919}
943 920
921static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
922{
923 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
924 struct tcm_qla2xxx_tpg, tpg_base_work);
925 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
926 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
927
928 if (!configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
929 &se_tpg->tpg_group.cg_item)) {
930 atomic_set(&base_tpg->lport_tpg_enabled, 1);
931 qlt_enable_vha(base_vha);
932 }
933 complete(&base_tpg->tpg_base_comp);
934}
935
936static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
937{
938 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
939 struct tcm_qla2xxx_tpg, tpg_base_work);
940 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
941 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
942
943 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
944 atomic_set(&base_tpg->lport_tpg_enabled, 0);
945 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
946 &se_tpg->tpg_group.cg_item);
947 }
948 complete(&base_tpg->tpg_base_comp);
949}
950
944static ssize_t tcm_qla2xxx_tpg_store_enable( 951static ssize_t tcm_qla2xxx_tpg_store_enable(
945 struct se_portal_group *se_tpg, 952 struct se_portal_group *se_tpg,
946 const char *page, 953 const char *page,
947 size_t count) 954 size_t count)
948{ 955{
949 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
950 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
951 struct tcm_qla2xxx_lport, lport_wwn);
952 struct scsi_qla_host *vha = lport->qla_vha;
953 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 956 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
954 struct tcm_qla2xxx_tpg, se_tpg); 957 struct tcm_qla2xxx_tpg, se_tpg);
955 unsigned long op; 958 unsigned long op;
@@ -964,19 +967,28 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
964 pr_err("Illegal value for tpg_enable: %lu\n", op); 967 pr_err("Illegal value for tpg_enable: %lu\n", op);
965 return -EINVAL; 968 return -EINVAL;
966 } 969 }
967
968 if (op) { 970 if (op) {
969 atomic_set(&tpg->lport_tpg_enabled, 1); 971 if (atomic_read(&tpg->lport_tpg_enabled))
970 qlt_enable_vha(vha); 972 return -EEXIST;
973
974 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_depend_tpg);
971 } else { 975 } else {
972 if (!vha->vha_tgt.qla_tgt) { 976 if (!atomic_read(&tpg->lport_tpg_enabled))
973 pr_err("struct qla_hw_data *vha->vha_tgt.qla_tgt is NULL\n"); 977 return count;
974 return -ENODEV; 978
975 } 979 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_undepend_tpg);
976 atomic_set(&tpg->lport_tpg_enabled, 0);
977 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
978 } 980 }
981 init_completion(&tpg->tpg_base_comp);
982 schedule_work(&tpg->tpg_base_work);
983 wait_for_completion(&tpg->tpg_base_comp);
979 984
985 if (op) {
986 if (!atomic_read(&tpg->lport_tpg_enabled))
987 return -ENODEV;
988 } else {
989 if (atomic_read(&tpg->lport_tpg_enabled))
990 return -EPERM;
991 }
980 return count; 992 return count;
981} 993}
982 994
@@ -1053,11 +1065,64 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1053 /* 1065 /*
1054 * Clear local TPG=1 pointer for non NPIV mode. 1066 * Clear local TPG=1 pointer for non NPIV mode.
1055 */ 1067 */
1056 lport->tpg_1 = NULL; 1068 lport->tpg_1 = NULL;
1057
1058 kfree(tpg); 1069 kfree(tpg);
1059} 1070}
1060 1071
1072static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
1073 struct se_portal_group *se_tpg,
1074 char *page)
1075{
1076 return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
1077}
1078
1079static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1080 struct se_portal_group *se_tpg,
1081 const char *page,
1082 size_t count)
1083{
1084 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1085 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1086 struct tcm_qla2xxx_lport, lport_wwn);
1087 struct scsi_qla_host *vha = lport->qla_vha;
1088 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1089 struct tcm_qla2xxx_tpg, se_tpg);
1090 unsigned long op;
1091 int rc;
1092
1093 rc = kstrtoul(page, 0, &op);
1094 if (rc < 0) {
1095 pr_err("kstrtoul() returned %d\n", rc);
1096 return -EINVAL;
1097 }
1098 if ((op != 1) && (op != 0)) {
1099 pr_err("Illegal value for tpg_enable: %lu\n", op);
1100 return -EINVAL;
1101 }
1102 if (op) {
1103 if (atomic_read(&tpg->lport_tpg_enabled))
1104 return -EEXIST;
1105
1106 atomic_set(&tpg->lport_tpg_enabled, 1);
1107 qlt_enable_vha(vha);
1108 } else {
1109 if (!atomic_read(&tpg->lport_tpg_enabled))
1110 return count;
1111
1112 atomic_set(&tpg->lport_tpg_enabled, 0);
1113 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1114 }
1115
1116 return count;
1117}
1118
1119TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
1120
1121static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1122 &tcm_qla2xxx_npiv_tpg_enable.attr,
1123 NULL,
1124};
1125
1061static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg( 1126static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1062 struct se_wwn *wwn, 1127 struct se_wwn *wwn,
1063 struct config_group *group, 1128 struct config_group *group,
@@ -1650,6 +1715,9 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1650 struct scsi_qla_host *npiv_vha; 1715 struct scsi_qla_host *npiv_vha;
1651 struct tcm_qla2xxx_lport *lport = 1716 struct tcm_qla2xxx_lport *lport =
1652 (struct tcm_qla2xxx_lport *)target_lport_ptr; 1717 (struct tcm_qla2xxx_lport *)target_lport_ptr;
1718 struct tcm_qla2xxx_lport *base_lport =
1719 (struct tcm_qla2xxx_lport *)base_vha->vha_tgt.target_lport_ptr;
1720 struct tcm_qla2xxx_tpg *base_tpg;
1653 struct fc_vport_identifiers vport_id; 1721 struct fc_vport_identifiers vport_id;
1654 1722
1655 if (!qla_tgt_mode_enabled(base_vha)) { 1723 if (!qla_tgt_mode_enabled(base_vha)) {
@@ -1657,6 +1725,13 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1657 return -EPERM; 1725 return -EPERM;
1658 } 1726 }
1659 1727
1728 if (!base_lport || !base_lport->tpg_1 ||
1729 !atomic_read(&base_lport->tpg_1->lport_tpg_enabled)) {
1730 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1731 return -EPERM;
1732 }
1733 base_tpg = base_lport->tpg_1;
1734
1660 memset(&vport_id, 0, sizeof(vport_id)); 1735 memset(&vport_id, 0, sizeof(vport_id));
1661 vport_id.port_name = npiv_wwpn; 1736 vport_id.port_name = npiv_wwpn;
1662 vport_id.node_name = npiv_wwnn; 1737 vport_id.node_name = npiv_wwnn;
@@ -1675,7 +1750,6 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1675 npiv_vha = (struct scsi_qla_host *)vport->dd_data; 1750 npiv_vha = (struct scsi_qla_host *)vport->dd_data;
1676 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr; 1751 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1677 lport->qla_vha = npiv_vha; 1752 lport->qla_vha = npiv_vha;
1678
1679 scsi_host_get(npiv_vha->host); 1753 scsi_host_get(npiv_vha->host);
1680 return 0; 1754 return 0;
1681} 1755}
@@ -1714,8 +1788,6 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1714 } 1788 }
1715 lport->lport_npiv_wwpn = npiv_wwpn; 1789 lport->lport_npiv_wwpn = npiv_wwpn;
1716 lport->lport_npiv_wwnn = npiv_wwnn; 1790 lport->lport_npiv_wwnn = npiv_wwnn;
1717 tcm_qla2xxx_npiv_format_wwn(&lport->lport_npiv_name[0],
1718 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn);
1719 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn); 1791 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
1720 1792
1721 ret = tcm_qla2xxx_init_lport(lport); 1793 ret = tcm_qla2xxx_init_lport(lport);
@@ -1824,7 +1896,7 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
1824static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { 1896static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1825 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 1897 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
1826 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1898 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1827 .tpg_get_wwn = tcm_qla2xxx_npiv_get_fabric_wwn, 1899 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1828 .tpg_get_tag = tcm_qla2xxx_get_tag, 1900 .tpg_get_tag = tcm_qla2xxx_get_tag,
1829 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth, 1901 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth,
1830 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1902 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
@@ -1935,7 +2007,7 @@ static int tcm_qla2xxx_register_configfs(void)
1935 */ 2007 */
1936 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs; 2008 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
1937 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = 2009 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
1938 tcm_qla2xxx_tpg_attrs; 2010 tcm_qla2xxx_npiv_tpg_attrs;
1939 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; 2011 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
1940 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; 2012 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1941 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; 2013 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;