summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-05-01 11:47:58 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-05-31 01:42:30 -0400
commit2650d71e244fb3637b5f58a0080682a8bf9c7091 (patch)
tree8fe28878d010df59f9b13b69b1e994270054218f
parent2aeeafae6bb9f04dbe17b521bcd8f0d03516c393 (diff)
target: move transport ID handling to the core
Now that struct se_portal_group contains a protocol identifier field we can take all the code to format an parse protocol identifiers in CDBs into common code instead of leaving this to low-level drivers. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rwxr-xr-xDocumentation/target/tcm_mod_builder.py121
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c39
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.h18
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c73
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.h2
-rw-r--r--drivers/target/iscsi/iscsi_target_configfs.c3
-rw-r--r--drivers/target/loopback/tcm_loop.c92
-rw-r--r--drivers/target/sbp/sbp_target.c70
-rw-r--r--drivers/target/target_core_configfs.c8
-rw-r--r--drivers/target/target_core_fabric_lib.c263
-rw-r--r--drivers/target/target_core_internal.h9
-rw-r--r--drivers/target/target_core_pr.c49
-rw-r--r--drivers/target/tcm_fc/tfc_conf.c3
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c75
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.h2
-rw-r--r--drivers/vhost/scsi.c94
-rw-r--r--drivers/xen/xen-scsiback.c94
-rw-r--r--include/target/target_core_fabric.h33
18 files changed, 173 insertions, 875 deletions
diff --git a/Documentation/target/tcm_mod_builder.py b/Documentation/target/tcm_mod_builder.py
index 29176c29537c..0dbd70cccde1 100755
--- a/Documentation/target/tcm_mod_builder.py
+++ b/Documentation/target/tcm_mod_builder.py
@@ -60,8 +60,6 @@ def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
60 buf += "};\n" 60 buf += "};\n"
61 buf += "\n" 61 buf += "\n"
62 buf += "struct " + fabric_mod_name + "_lport {\n" 62 buf += "struct " + fabric_mod_name + "_lport {\n"
63 buf += " /* SCSI protocol the lport is providing */\n"
64 buf += " u8 lport_proto_id;\n"
65 buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" 63 buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
66 buf += " u64 lport_wwpn;\n" 64 buf += " u64 lport_wwpn;\n"
67 buf += " /* ASCII formatted WWPN for FC Target Lport */\n" 65 buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
@@ -105,8 +103,6 @@ def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
105 buf += " struct se_portal_group se_tpg;\n" 103 buf += " struct se_portal_group se_tpg;\n"
106 buf += "};\n\n" 104 buf += "};\n\n"
107 buf += "struct " + fabric_mod_name + "_tport {\n" 105 buf += "struct " + fabric_mod_name + "_tport {\n"
108 buf += " /* SCSI protocol the tport is providing */\n"
109 buf += " u8 tport_proto_id;\n"
110 buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" 106 buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
111 buf += " u64 tport_wwpn;\n" 107 buf += " u64 tport_wwpn;\n"
112 buf += " /* ASCII formatted WWPN for SAS Target port */\n" 108 buf += " /* ASCII formatted WWPN for SAS Target port */\n"
@@ -150,8 +146,6 @@ def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
150 buf += " struct se_portal_group se_tpg;\n" 146 buf += " struct se_portal_group se_tpg;\n"
151 buf += "};\n\n" 147 buf += "};\n\n"
152 buf += "struct " + fabric_mod_name + "_tport {\n" 148 buf += "struct " + fabric_mod_name + "_tport {\n"
153 buf += " /* SCSI protocol the tport is providing */\n"
154 buf += " u8 tport_proto_id;\n"
155 buf += " /* ASCII formatted TargetName for IQN */\n" 149 buf += " /* ASCII formatted TargetName for IQN */\n"
156 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 150 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
157 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" 151 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
@@ -303,9 +297,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
303 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" 297 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
304 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" 298 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
305 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" 299 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
306 buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
307 buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
308 buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
309 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" 300 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
310 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" 301 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
311 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" 302 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
@@ -478,118 +469,6 @@ def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
478 buf += "}\n\n" 469 buf += "}\n\n"
479 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n" 470 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
480 471
481 if re.search('get_pr_transport_id\)\(', fo):
482 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
483 buf += " struct se_portal_group *se_tpg,\n"
484 buf += " struct se_node_acl *se_nacl,\n"
485 buf += " struct t10_pr_registration *pr_reg,\n"
486 buf += " int *format_code,\n"
487 buf += " unsigned char *buf)\n"
488 buf += "{\n"
489 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
490 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
491 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
492 buf += " int ret = 0;\n\n"
493 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
494 if proto_ident == "FC":
495 buf += " case SCSI_PROTOCOL_FCP:\n"
496 buf += " default:\n"
497 buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
498 buf += " format_code, buf);\n"
499 buf += " break;\n"
500 elif proto_ident == "SAS":
501 buf += " case SCSI_PROTOCOL_SAS:\n"
502 buf += " default:\n"
503 buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
504 buf += " format_code, buf);\n"
505 buf += " break;\n"
506 elif proto_ident == "iSCSI":
507 buf += " case SCSI_PROTOCOL_ISCSI:\n"
508 buf += " default:\n"
509 buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
510 buf += " format_code, buf);\n"
511 buf += " break;\n"
512
513 buf += " }\n\n"
514 buf += " return ret;\n"
515 buf += "}\n\n"
516 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
517 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
518 bufi += " int *, unsigned char *);\n"
519
520 if re.search('get_pr_transport_id_len\)\(', fo):
521 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
522 buf += " struct se_portal_group *se_tpg,\n"
523 buf += " struct se_node_acl *se_nacl,\n"
524 buf += " struct t10_pr_registration *pr_reg,\n"
525 buf += " int *format_code)\n"
526 buf += "{\n"
527 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
528 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
529 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
530 buf += " int ret = 0;\n\n"
531 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
532 if proto_ident == "FC":
533 buf += " case SCSI_PROTOCOL_FCP:\n"
534 buf += " default:\n"
535 buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
536 buf += " format_code);\n"
537 buf += " break;\n"
538 elif proto_ident == "SAS":
539 buf += " case SCSI_PROTOCOL_SAS:\n"
540 buf += " default:\n"
541 buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
542 buf += " format_code);\n"
543 buf += " break;\n"
544 elif proto_ident == "iSCSI":
545 buf += " case SCSI_PROTOCOL_ISCSI:\n"
546 buf += " default:\n"
547 buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
548 buf += " format_code);\n"
549 buf += " break;\n"
550
551
552 buf += " }\n\n"
553 buf += " return ret;\n"
554 buf += "}\n\n"
555 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
556 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
557 bufi += " int *);\n"
558
559 if re.search('parse_pr_out_transport_id\)\(', fo):
560 buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
561 buf += " struct se_portal_group *se_tpg,\n"
562 buf += " const char *buf,\n"
563 buf += " u32 *out_tid_len,\n"
564 buf += " char **port_nexus_ptr)\n"
565 buf += "{\n"
566 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
567 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
568 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
569 buf += " char *tid = NULL;\n\n"
570 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
571 if proto_ident == "FC":
572 buf += " case SCSI_PROTOCOL_FCP:\n"
573 buf += " default:\n"
574 buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
575 buf += " port_nexus_ptr);\n"
576 elif proto_ident == "SAS":
577 buf += " case SCSI_PROTOCOL_SAS:\n"
578 buf += " default:\n"
579 buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
580 buf += " port_nexus_ptr);\n"
581 elif proto_ident == "iSCSI":
582 buf += " case SCSI_PROTOCOL_ISCSI:\n"
583 buf += " default:\n"
584 buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
585 buf += " port_nexus_ptr);\n"
586
587 buf += " }\n\n"
588 buf += " return tid;\n"
589 buf += "}\n\n"
590 bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
591 bufi += " const char *, u32 *, char **);\n"
592
593 if re.search('tpg_get_inst_index\)\(', fo): 472 if re.search('tpg_get_inst_index\)\(', fo):
594 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n" 473 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
595 buf += "{\n" 474 buf += "{\n"
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 9213c2de28fc..98e00360f97e 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -3406,42 +3406,6 @@ static u16 srpt_get_tag(struct se_portal_group *tpg)
3406 return 1; 3406 return 1;
3407} 3407}
3408 3408
3409static u32 srpt_get_pr_transport_id(struct se_portal_group *se_tpg,
3410 struct se_node_acl *se_nacl,
3411 struct t10_pr_registration *pr_reg,
3412 int *format_code, unsigned char *buf)
3413{
3414 struct srpt_node_acl *nacl;
3415 struct spc_rdma_transport_id *tr_id;
3416
3417 nacl = container_of(se_nacl, struct srpt_node_acl, nacl);
3418 tr_id = (void *)buf;
3419 tr_id->protocol_identifier = SCSI_TRANSPORTID_PROTOCOLID_SRP;
3420 memcpy(tr_id->i_port_id, nacl->i_port_id, sizeof(tr_id->i_port_id));
3421 return sizeof(*tr_id);
3422}
3423
3424static u32 srpt_get_pr_transport_id_len(struct se_portal_group *se_tpg,
3425 struct se_node_acl *se_nacl,
3426 struct t10_pr_registration *pr_reg,
3427 int *format_code)
3428{
3429 *format_code = 0;
3430 return sizeof(struct spc_rdma_transport_id);
3431}
3432
3433static char *srpt_parse_pr_out_transport_id(struct se_portal_group *se_tpg,
3434 const char *buf, u32 *out_tid_len,
3435 char **port_nexus_ptr)
3436{
3437 struct spc_rdma_transport_id *tr_id;
3438
3439 *port_nexus_ptr = NULL;
3440 *out_tid_len = sizeof(struct spc_rdma_transport_id);
3441 tr_id = (void *)buf;
3442 return (char *)tr_id->i_port_id;
3443}
3444
3445static u32 srpt_tpg_get_inst_index(struct se_portal_group *se_tpg) 3409static u32 srpt_tpg_get_inst_index(struct se_portal_group *se_tpg)
3446{ 3410{
3447 return 1; 3411 return 1;
@@ -3860,9 +3824,6 @@ static const struct target_core_fabric_ops srpt_template = {
3860 .get_fabric_name = srpt_get_fabric_name, 3824 .get_fabric_name = srpt_get_fabric_name,
3861 .tpg_get_wwn = srpt_get_fabric_wwn, 3825 .tpg_get_wwn = srpt_get_fabric_wwn,
3862 .tpg_get_tag = srpt_get_tag, 3826 .tpg_get_tag = srpt_get_tag,
3863 .tpg_get_pr_transport_id = srpt_get_pr_transport_id,
3864 .tpg_get_pr_transport_id_len = srpt_get_pr_transport_id_len,
3865 .tpg_parse_pr_out_transport_id = srpt_parse_pr_out_transport_id,
3866 .tpg_check_demo_mode = srpt_check_false, 3827 .tpg_check_demo_mode = srpt_check_false,
3867 .tpg_check_demo_mode_cache = srpt_check_true, 3828 .tpg_check_demo_mode_cache = srpt_check_true,
3868 .tpg_check_demo_mode_write_protect = srpt_check_true, 3829 .tpg_check_demo_mode_write_protect = srpt_check_true,
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.h b/drivers/infiniband/ulp/srpt/ib_srpt.h
index 355f6f5ce8b2..33b2c88b73ba 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.h
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.h
@@ -422,22 +422,4 @@ struct srpt_node_acl {
422 struct list_head list; 422 struct list_head list;
423}; 423};
424 424
425/*
426 * SRP-releated SCSI persistent reservation definitions.
427 *
428 * See also SPC4r28, section 7.6.1 (Protocol specific parameters introduction).
429 * See also SPC4r28, section 7.6.4.5 (TransportID for initiator ports using
430 * SCSI over an RDMA interface).
431 */
432
433enum {
434 SCSI_TRANSPORTID_PROTOCOLID_SRP = 4,
435};
436
437struct spc_rdma_transport_id {
438 uint8_t protocol_identifier;
439 uint8_t reserved[7];
440 uint8_t i_port_id[16];
441};
442
443#endif /* IB_SRPT_H */ 425#endif /* IB_SRPT_H */
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 4566c4649751..bd0f9eb67901 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -206,73 +206,6 @@ static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
206 return tpg->lport_tpgt; 206 return tpg->lport_tpgt;
207} 207}
208 208
209static u32 tcm_qla2xxx_get_pr_transport_id(
210 struct se_portal_group *se_tpg,
211 struct se_node_acl *se_nacl,
212 struct t10_pr_registration *pr_reg,
213 int *format_code,
214 unsigned char *buf)
215{
216 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
217 struct tcm_qla2xxx_tpg, se_tpg);
218 struct tcm_qla2xxx_lport *lport = tpg->lport;
219 int ret = 0;
220
221 switch (lport->lport_proto_id) {
222 case SCSI_PROTOCOL_FCP:
223 default:
224 ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
225 format_code, buf);
226 break;
227 }
228
229 return ret;
230}
231
232static u32 tcm_qla2xxx_get_pr_transport_id_len(
233 struct se_portal_group *se_tpg,
234 struct se_node_acl *se_nacl,
235 struct t10_pr_registration *pr_reg,
236 int *format_code)
237{
238 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
239 struct tcm_qla2xxx_tpg, se_tpg);
240 struct tcm_qla2xxx_lport *lport = tpg->lport;
241 int ret = 0;
242
243 switch (lport->lport_proto_id) {
244 case SCSI_PROTOCOL_FCP:
245 default:
246 ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
247 format_code);
248 break;
249 }
250
251 return ret;
252}
253
254static char *tcm_qla2xxx_parse_pr_out_transport_id(
255 struct se_portal_group *se_tpg,
256 const char *buf,
257 u32 *out_tid_len,
258 char **port_nexus_ptr)
259{
260 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
261 struct tcm_qla2xxx_tpg, se_tpg);
262 struct tcm_qla2xxx_lport *lport = tpg->lport;
263 char *tid = NULL;
264
265 switch (lport->lport_proto_id) {
266 case SCSI_PROTOCOL_FCP:
267 default:
268 tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
269 port_nexus_ptr);
270 break;
271 }
272
273 return tid;
274}
275
276static int tcm_qla2xxx_check_demo_mode(struct se_portal_group *se_tpg) 209static int tcm_qla2xxx_check_demo_mode(struct se_portal_group *se_tpg)
277{ 210{
278 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 211 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
@@ -1913,9 +1846,6 @@ static const struct target_core_fabric_ops tcm_qla2xxx_ops = {
1913 .get_fabric_name = tcm_qla2xxx_get_fabric_name, 1846 .get_fabric_name = tcm_qla2xxx_get_fabric_name,
1914 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 1847 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1915 .tpg_get_tag = tcm_qla2xxx_get_tag, 1848 .tpg_get_tag = tcm_qla2xxx_get_tag,
1916 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1917 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1918 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1919 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode, 1849 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1920 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache, 1850 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1921 .tpg_check_demo_mode_write_protect = 1851 .tpg_check_demo_mode_write_protect =
@@ -1963,9 +1893,6 @@ static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1963 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 1893 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
1964 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 1894 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1965 .tpg_get_tag = tcm_qla2xxx_get_tag, 1895 .tpg_get_tag = tcm_qla2xxx_get_tag,
1966 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
1967 .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len,
1968 .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id,
1969 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode, 1896 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode,
1970 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache, 1897 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache,
1971 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode, 1898 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode,
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.h b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
index 3d805a07061c..3bbf4cb6fd97 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.h
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
@@ -57,8 +57,6 @@ struct tcm_qla2xxx_fc_loopid {
57}; 57};
58 58
59struct tcm_qla2xxx_lport { 59struct tcm_qla2xxx_lport {
60 /* SCSI protocol the lport is providing */
61 u8 lport_proto_id;
62 /* Binary World Wide unique Port Name for FC Target Lport */ 60 /* Binary World Wide unique Port Name for FC Target Lport */
63 u64 lport_wwpn; 61 u64 lport_wwpn;
64 /* Binary World Wide unique Port Name for FC NPIV Target Lport */ 62 /* Binary World Wide unique Port Name for FC NPIV Target Lport */
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index 9dec9f39139f..bd8af8764f4b 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -1921,9 +1921,6 @@ const struct target_core_fabric_ops iscsi_ops = {
1921 .tpg_get_wwn = lio_tpg_get_endpoint_wwn, 1921 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1922 .tpg_get_tag = lio_tpg_get_tag, 1922 .tpg_get_tag = lio_tpg_get_tag,
1923 .tpg_get_default_depth = lio_tpg_get_default_depth, 1923 .tpg_get_default_depth = lio_tpg_get_default_depth,
1924 .tpg_get_pr_transport_id = iscsi_get_pr_transport_id,
1925 .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len,
1926 .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id,
1927 .tpg_check_demo_mode = lio_tpg_check_demo_mode, 1924 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1928 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, 1925 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1929 .tpg_check_demo_mode_write_protect = 1926 .tpg_check_demo_mode_write_protect =
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 0eed0209a7f4..b788406977f6 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -542,95 +542,6 @@ static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg)
542 return tl_tpg(se_tpg)->tl_tpgt; 542 return tl_tpg(se_tpg)->tl_tpgt;
543} 543}
544 544
545static u32 tcm_loop_get_pr_transport_id(
546 struct se_portal_group *se_tpg,
547 struct se_node_acl *se_nacl,
548 struct t10_pr_registration *pr_reg,
549 int *format_code,
550 unsigned char *buf)
551{
552 struct tcm_loop_hba *tl_hba = tl_tpg(se_tpg)->tl_hba;
553
554 switch (tl_hba->tl_proto_id) {
555 case SCSI_PROTOCOL_SAS:
556 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
557 format_code, buf);
558 case SCSI_PROTOCOL_FCP:
559 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
560 format_code, buf);
561 case SCSI_PROTOCOL_ISCSI:
562 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
563 format_code, buf);
564 default:
565 pr_err("Unknown tl_proto_id: 0x%02x, using"
566 " SAS emulation\n", tl_hba->tl_proto_id);
567 break;
568 }
569
570 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
571 format_code, buf);
572}
573
574static u32 tcm_loop_get_pr_transport_id_len(
575 struct se_portal_group *se_tpg,
576 struct se_node_acl *se_nacl,
577 struct t10_pr_registration *pr_reg,
578 int *format_code)
579{
580 struct tcm_loop_hba *tl_hba = tl_tpg(se_tpg)->tl_hba;
581
582 switch (tl_hba->tl_proto_id) {
583 case SCSI_PROTOCOL_SAS:
584 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
585 format_code);
586 case SCSI_PROTOCOL_FCP:
587 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
588 format_code);
589 case SCSI_PROTOCOL_ISCSI:
590 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
591 format_code);
592 default:
593 pr_err("Unknown tl_proto_id: 0x%02x, using"
594 " SAS emulation\n", tl_hba->tl_proto_id);
595 break;
596 }
597
598 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
599 format_code);
600}
601
602/*
603 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
604 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
605 */
606static char *tcm_loop_parse_pr_out_transport_id(
607 struct se_portal_group *se_tpg,
608 const char *buf,
609 u32 *out_tid_len,
610 char **port_nexus_ptr)
611{
612 struct tcm_loop_hba *tl_hba = tl_tpg(se_tpg)->tl_hba;
613
614 switch (tl_hba->tl_proto_id) {
615 case SCSI_PROTOCOL_SAS:
616 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
617 port_nexus_ptr);
618 case SCSI_PROTOCOL_FCP:
619 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
620 port_nexus_ptr);
621 case SCSI_PROTOCOL_ISCSI:
622 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
623 port_nexus_ptr);
624 default:
625 pr_err("Unknown tl_proto_id: 0x%02x, using"
626 " SAS emulation\n", tl_hba->tl_proto_id);
627 break;
628 }
629
630 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
631 port_nexus_ptr);
632}
633
634/* 545/*
635 * Returning (1) here allows for target_core_mod struct se_node_acl to be generated 546 * Returning (1) here allows for target_core_mod struct se_node_acl to be generated
636 * based upon the incoming fabric dependent SCSI Initiator Port 547 * based upon the incoming fabric dependent SCSI Initiator Port
@@ -1332,9 +1243,6 @@ static const struct target_core_fabric_ops loop_ops = {
1332 .get_fabric_name = tcm_loop_get_fabric_name, 1243 .get_fabric_name = tcm_loop_get_fabric_name,
1333 .tpg_get_wwn = tcm_loop_get_endpoint_wwn, 1244 .tpg_get_wwn = tcm_loop_get_endpoint_wwn,
1334 .tpg_get_tag = tcm_loop_get_tag, 1245 .tpg_get_tag = tcm_loop_get_tag,
1335 .tpg_get_pr_transport_id = tcm_loop_get_pr_transport_id,
1336 .tpg_get_pr_transport_id_len = tcm_loop_get_pr_transport_id_len,
1337 .tpg_parse_pr_out_transport_id = tcm_loop_parse_pr_out_transport_id,
1338 .tpg_check_demo_mode = tcm_loop_check_demo_mode, 1246 .tpg_check_demo_mode = tcm_loop_check_demo_mode,
1339 .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache, 1247 .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache,
1340 .tpg_check_demo_mode_write_protect = 1248 .tpg_check_demo_mode_write_protect =
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index 8acb37fd9ebc..89f172dc8678 100644
--- a/drivers/target/sbp/sbp_target.c
+++ b/drivers/target/sbp/sbp_target.c
@@ -1832,73 +1832,6 @@ static int sbp_check_stop_free(struct se_cmd *se_cmd)
1832 return 1; 1832 return 1;
1833} 1833}
1834 1834
1835static u32 sbp_get_pr_transport_id(
1836 struct se_portal_group *se_tpg,
1837 struct se_node_acl *se_nacl,
1838 struct t10_pr_registration *pr_reg,
1839 int *format_code,
1840 unsigned char *buf)
1841{
1842 int ret;
1843
1844 /*
1845 * Set PROTOCOL IDENTIFIER to 3h for SBP
1846 */
1847 buf[0] = SCSI_PROTOCOL_SBP;
1848 /*
1849 * From spc4r17, 7.5.4.4 TransportID for initiator ports using SCSI
1850 * over IEEE 1394
1851 */
1852 ret = hex2bin(&buf[8], se_nacl->initiatorname, 8);
1853 if (ret < 0)
1854 pr_debug("sbp transport_id: invalid hex string\n");
1855
1856 /*
1857 * The IEEE 1394 Transport ID is a hardcoded 24-byte length
1858 */
1859 return 24;
1860}
1861
1862static u32 sbp_get_pr_transport_id_len(
1863 struct se_portal_group *se_tpg,
1864 struct se_node_acl *se_nacl,
1865 struct t10_pr_registration *pr_reg,
1866 int *format_code)
1867{
1868 *format_code = 0;
1869 /*
1870 * From spc4r17, 7.5.4.4 TransportID for initiator ports using SCSI
1871 * over IEEE 1394
1872 *
1873 * The SBP Transport ID is a hardcoded 24-byte length
1874 */
1875 return 24;
1876}
1877
1878/*
1879 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
1880 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
1881 */
1882static char *sbp_parse_pr_out_transport_id(
1883 struct se_portal_group *se_tpg,
1884 const char *buf,
1885 u32 *out_tid_len,
1886 char **port_nexus_ptr)
1887{
1888 /*
1889 * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.4 TransportID
1890 * for initiator ports using SCSI over SBP Serial SCSI Protocol
1891 *
1892 * The TransportID for a IEEE 1394 Initiator Port is of fixed size of
1893 * 24 bytes, and IEEE 1394 does not contain a I_T nexus identifier,
1894 * so we return the **port_nexus_ptr set to NULL.
1895 */
1896 *port_nexus_ptr = NULL;
1897 *out_tid_len = 24;
1898
1899 return (char *)&buf[8];
1900}
1901
1902static int sbp_count_se_tpg_luns(struct se_portal_group *tpg) 1835static int sbp_count_se_tpg_luns(struct se_portal_group *tpg)
1903{ 1836{
1904 int i, count = 0; 1837 int i, count = 0;
@@ -2432,9 +2365,6 @@ static const struct target_core_fabric_ops sbp_ops = {
2432 .get_fabric_name = sbp_get_fabric_name, 2365 .get_fabric_name = sbp_get_fabric_name,
2433 .tpg_get_wwn = sbp_get_fabric_wwn, 2366 .tpg_get_wwn = sbp_get_fabric_wwn,
2434 .tpg_get_tag = sbp_get_tag, 2367 .tpg_get_tag = sbp_get_tag,
2435 .tpg_get_pr_transport_id = sbp_get_pr_transport_id,
2436 .tpg_get_pr_transport_id_len = sbp_get_pr_transport_id_len,
2437 .tpg_parse_pr_out_transport_id = sbp_parse_pr_out_transport_id,
2438 .tpg_check_demo_mode = sbp_check_true, 2368 .tpg_check_demo_mode = sbp_check_true,
2439 .tpg_check_demo_mode_cache = sbp_check_true, 2369 .tpg_check_demo_mode_cache = sbp_check_true,
2440 .tpg_check_demo_mode_write_protect = sbp_check_false, 2370 .tpg_check_demo_mode_write_protect = sbp_check_false,
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 21c9f7d79d5e..5e2649fc6919 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -326,14 +326,6 @@ static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
326 pr_err("Missing tfo->tpg_get_tag()\n"); 326 pr_err("Missing tfo->tpg_get_tag()\n");
327 return -EINVAL; 327 return -EINVAL;
328 } 328 }
329 if (!tfo->tpg_get_pr_transport_id) {
330 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
331 return -EINVAL;
332 }
333 if (!tfo->tpg_get_pr_transport_id_len) {
334 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
335 return -EINVAL;
336 }
337 if (!tfo->tpg_check_demo_mode) { 329 if (!tfo->tpg_check_demo_mode) {
338 pr_err("Missing tfo->tpg_check_demo_mode()\n"); 330 pr_err("Missing tfo->tpg_check_demo_mode()\n");
339 return -EINVAL; 331 return -EINVAL;
diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c
index 6fed14adbe61..89720b2f37c2 100644
--- a/drivers/target/target_core_fabric_lib.c
+++ b/drivers/target/target_core_fabric_lib.c
@@ -24,6 +24,11 @@
24 * 24 *
25 ******************************************************************************/ 25 ******************************************************************************/
26 26
27/*
28 * See SPC4, section 7.5 "Protocol specific parameters" for details
29 * on the formats implemented in this file.
30 */
31
27#include <linux/kernel.h> 32#include <linux/kernel.h>
28#include <linux/string.h> 33#include <linux/string.h>
29#include <linux/ctype.h> 34#include <linux/ctype.h>
@@ -39,103 +44,26 @@
39#include "target_core_internal.h" 44#include "target_core_internal.h"
40#include "target_core_pr.h" 45#include "target_core_pr.h"
41 46
42/* 47
43 * Handlers for Serial Attached SCSI (SAS) 48static int sas_get_pr_transport_id(
44 */ 49 struct se_node_acl *nacl,
45u32 sas_get_pr_transport_id(
46 struct se_portal_group *se_tpg,
47 struct se_node_acl *se_nacl,
48 struct t10_pr_registration *pr_reg,
49 int *format_code, 50 int *format_code,
50 unsigned char *buf) 51 unsigned char *buf)
51{ 52{
52 unsigned char *ptr;
53 int ret; 53 int ret;
54 54
55 /* 55 /* Skip over 'naa. prefix */
56 * Set PROTOCOL IDENTIFIER to 6h for SAS 56 ret = hex2bin(&buf[4], &nacl->initiatorname[4], 8);
57 */ 57 if (ret) {
58 buf[0] = 0x06; 58 pr_debug("%s: invalid hex string\n", __func__);
59 /* 59 return ret;
60 * From spc4r17, 7.5.4.7 TransportID for initiator ports using SCSI 60 }
61 * over SAS Serial SCSI Protocol
62 */
63 ptr = &se_nacl->initiatorname[4]; /* Skip over 'naa. prefix */
64
65 ret = hex2bin(&buf[4], ptr, 8);
66 if (ret < 0)
67 pr_debug("sas transport_id: invalid hex string\n");
68
69 /*
70 * The SAS Transport ID is a hardcoded 24-byte length
71 */
72 return 24;
73}
74EXPORT_SYMBOL(sas_get_pr_transport_id);
75
76u32 sas_get_pr_transport_id_len(
77 struct se_portal_group *se_tpg,
78 struct se_node_acl *se_nacl,
79 struct t10_pr_registration *pr_reg,
80 int *format_code)
81{
82 *format_code = 0;
83 /*
84 * From spc4r17, 7.5.4.7 TransportID for initiator ports using SCSI
85 * over SAS Serial SCSI Protocol
86 *
87 * The SAS Transport ID is a hardcoded 24-byte length
88 */
89 return 24;
90}
91EXPORT_SYMBOL(sas_get_pr_transport_id_len);
92
93/*
94 * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above
95 * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations.
96 */
97char *sas_parse_pr_out_transport_id(
98 struct se_portal_group *se_tpg,
99 const char *buf,
100 u32 *out_tid_len,
101 char **port_nexus_ptr)
102{
103 /*
104 * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID
105 * for initiator ports using SCSI over SAS Serial SCSI Protocol
106 *
107 * The TransportID for a SAS Initiator Port is of fixed size of
108 * 24 bytes, and SAS does not contain a I_T nexus identifier,
109 * so we return the **port_nexus_ptr set to NULL.
110 */
111 *port_nexus_ptr = NULL;
112 *out_tid_len = 24;
113
114 return (char *)&buf[4];
115}
116EXPORT_SYMBOL(sas_parse_pr_out_transport_id);
117 61
118/*
119 * Handlers for Fibre Channel Protocol (FCP)
120 */
121u32 fc_get_pr_transport_id_len(
122 struct se_portal_group *se_tpg,
123 struct se_node_acl *se_nacl,
124 struct t10_pr_registration *pr_reg,
125 int *format_code)
126{
127 *format_code = 0;
128 /*
129 * The FC Transport ID is a hardcoded 24-byte length
130 */
131 return 24; 62 return 24;
132} 63}
133EXPORT_SYMBOL(fc_get_pr_transport_id_len);
134 64
135u32 fc_get_pr_transport_id( 65static int fc_get_pr_transport_id(
136 struct se_portal_group *se_tpg,
137 struct se_node_acl *se_nacl, 66 struct se_node_acl *se_nacl,
138 struct t10_pr_registration *pr_reg,
139 int *format_code, 67 int *format_code,
140 unsigned char *buf) 68 unsigned char *buf)
141{ 69{
@@ -144,24 +72,20 @@ u32 fc_get_pr_transport_id(
144 u32 off = 8; 72 u32 off = 8;
145 73
146 /* 74 /*
147 * PROTOCOL IDENTIFIER is 0h for FCP-2
148 *
149 * From spc4r17, 7.5.4.2 TransportID for initiator ports using
150 * SCSI over Fibre Channel
151 *
152 * We convert the ASCII formatted N Port name into a binary 75 * We convert the ASCII formatted N Port name into a binary
153 * encoded TransportID. 76 * encoded TransportID.
154 */ 77 */
155 ptr = &se_nacl->initiatorname[0]; 78 ptr = &se_nacl->initiatorname[0];
156
157 for (i = 0; i < 24; ) { 79 for (i = 0; i < 24; ) {
158 if (!strncmp(&ptr[i], ":", 1)) { 80 if (!strncmp(&ptr[i], ":", 1)) {
159 i++; 81 i++;
160 continue; 82 continue;
161 } 83 }
162 ret = hex2bin(&buf[off++], &ptr[i], 1); 84 ret = hex2bin(&buf[off++], &ptr[i], 1);
163 if (ret < 0) 85 if (ret < 0) {
164 pr_debug("fc transport_id: invalid hex string\n"); 86 pr_debug("%s: invalid hex string\n", __func__);
87 return ret;
88 }
165 i += 2; 89 i += 2;
166 } 90 }
167 /* 91 /*
@@ -169,31 +93,52 @@ u32 fc_get_pr_transport_id(
169 */ 93 */
170 return 24; 94 return 24;
171} 95}
172EXPORT_SYMBOL(fc_get_pr_transport_id);
173 96
174char *fc_parse_pr_out_transport_id( 97static int sbp_get_pr_transport_id(
175 struct se_portal_group *se_tpg, 98 struct se_node_acl *nacl,
176 const char *buf, 99 int *format_code,
177 u32 *out_tid_len, 100 unsigned char *buf)
178 char **port_nexus_ptr)
179{ 101{
180 /* 102 int ret;
181 * The TransportID for a FC N Port is of fixed size of 103
182 * 24 bytes, and FC does not contain a I_T nexus identifier, 104 ret = hex2bin(&buf[8], nacl->initiatorname, 8);
183 * so we return the **port_nexus_ptr set to NULL. 105 if (ret) {
184 */ 106 pr_debug("%s: invalid hex string\n", __func__);
185 *port_nexus_ptr = NULL; 107 return ret;
186 *out_tid_len = 24; 108 }
187 109
188 return (char *)&buf[8]; 110 return 24;
189} 111}
190EXPORT_SYMBOL(fc_parse_pr_out_transport_id);
191 112
192/* 113static int srp_get_pr_transport_id(
193 * Handlers for Internet Small Computer Systems Interface (iSCSI) 114 struct se_node_acl *nacl,
194 */ 115 int *format_code,
195u32 iscsi_get_pr_transport_id( 116 unsigned char *buf)
196 struct se_portal_group *se_tpg, 117{
118 const char *p;
119 unsigned len, count, leading_zero_bytes;
120 int rc;
121
122 p = nacl->initiatorname;
123 if (strncasecmp(p, "0x", 2) == 0)
124 p += 2;
125 len = strlen(p);
126 if (len % 2)
127 return -EINVAL;
128
129 count = min(len / 2, 16U);
130 leading_zero_bytes = 16 - count;
131 memset(buf + 8, 0, leading_zero_bytes);
132 rc = hex2bin(buf + 8 + leading_zero_bytes, p, count);
133 if (rc < 0) {
134 pr_debug("hex2bin failed for %s: %d\n", __func__, rc);
135 return rc;
136 }
137
138 return 24;
139}
140
141static int iscsi_get_pr_transport_id(
197 struct se_node_acl *se_nacl, 142 struct se_node_acl *se_nacl,
198 struct t10_pr_registration *pr_reg, 143 struct t10_pr_registration *pr_reg,
199 int *format_code, 144 int *format_code,
@@ -204,10 +149,6 @@ u32 iscsi_get_pr_transport_id(
204 149
205 spin_lock_irq(&se_nacl->nacl_sess_lock); 150 spin_lock_irq(&se_nacl->nacl_sess_lock);
206 /* 151 /*
207 * Set PROTOCOL IDENTIFIER to 5h for iSCSI
208 */
209 buf[0] = 0x05;
210 /*
211 * From spc4r17 Section 7.5.4.6: TransportID for initiator 152 * From spc4r17 Section 7.5.4.6: TransportID for initiator
212 * ports using SCSI over iSCSI. 153 * ports using SCSI over iSCSI.
213 * 154 *
@@ -286,10 +227,8 @@ u32 iscsi_get_pr_transport_id(
286 227
287 return len; 228 return len;
288} 229}
289EXPORT_SYMBOL(iscsi_get_pr_transport_id);
290 230
291u32 iscsi_get_pr_transport_id_len( 231static int iscsi_get_pr_transport_id_len(
292 struct se_portal_group *se_tpg,
293 struct se_node_acl *se_nacl, 232 struct se_node_acl *se_nacl,
294 struct t10_pr_registration *pr_reg, 233 struct t10_pr_registration *pr_reg,
295 int *format_code) 234 int *format_code)
@@ -332,9 +271,8 @@ u32 iscsi_get_pr_transport_id_len(
332 271
333 return len; 272 return len;
334} 273}
335EXPORT_SYMBOL(iscsi_get_pr_transport_id_len);
336 274
337char *iscsi_parse_pr_out_transport_id( 275static char *iscsi_parse_pr_out_transport_id(
338 struct se_portal_group *se_tpg, 276 struct se_portal_group *se_tpg,
339 const char *buf, 277 const char *buf,
340 u32 *out_tid_len, 278 u32 *out_tid_len,
@@ -421,4 +359,79 @@ char *iscsi_parse_pr_out_transport_id(
421 359
422 return (char *)&buf[4]; 360 return (char *)&buf[4];
423} 361}
424EXPORT_SYMBOL(iscsi_parse_pr_out_transport_id); 362
363int target_get_pr_transport_id_len(struct se_node_acl *nacl,
364 struct t10_pr_registration *pr_reg, int *format_code)
365{
366 switch (nacl->se_tpg->proto_id) {
367 case SCSI_PROTOCOL_FCP:
368 case SCSI_PROTOCOL_SBP:
369 case SCSI_PROTOCOL_SRP:
370 case SCSI_PROTOCOL_SAS:
371 break;
372 case SCSI_PROTOCOL_ISCSI:
373 return iscsi_get_pr_transport_id_len(nacl, pr_reg, format_code);
374 default:
375 pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id);
376 return -EINVAL;
377 }
378
379 /*
380 * Most transports use a fixed length 24 byte identifier.
381 */
382 *format_code = 0;
383 return 24;
384}
385
386int target_get_pr_transport_id(struct se_node_acl *nacl,
387 struct t10_pr_registration *pr_reg, int *format_code,
388 unsigned char *buf)
389{
390 switch (nacl->se_tpg->proto_id) {
391 case SCSI_PROTOCOL_SAS:
392 return sas_get_pr_transport_id(nacl, format_code, buf);
393 case SCSI_PROTOCOL_SBP:
394 return sbp_get_pr_transport_id(nacl, format_code, buf);
395 case SCSI_PROTOCOL_SRP:
396 return srp_get_pr_transport_id(nacl, format_code, buf);
397 case SCSI_PROTOCOL_FCP:
398 return fc_get_pr_transport_id(nacl, format_code, buf);
399 case SCSI_PROTOCOL_ISCSI:
400 return iscsi_get_pr_transport_id(nacl, pr_reg, format_code,
401 buf);
402 default:
403 pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id);
404 return -EINVAL;
405 }
406}
407
408const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
409 const char *buf, u32 *out_tid_len, char **port_nexus_ptr)
410{
411 u32 offset;
412
413 switch (tpg->proto_id) {
414 case SCSI_PROTOCOL_SAS:
415 /*
416 * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID
417 * for initiator ports using SCSI over SAS Serial SCSI Protocol.
418 */
419 offset = 4;
420 break;
421 case SCSI_PROTOCOL_SBP:
422 case SCSI_PROTOCOL_SRP:
423 case SCSI_PROTOCOL_FCP:
424 offset = 8;
425 break;
426 case SCSI_PROTOCOL_ISCSI:
427 return iscsi_parse_pr_out_transport_id(tpg, buf, out_tid_len,
428 port_nexus_ptr);
429 default:
430 pr_err("Unknown proto_id: 0x%02x\n", tpg->proto_id);
431 return NULL;
432 }
433
434 *port_nexus_ptr = NULL;
435 *out_tid_len = 24;
436 return buf + offset;
437}
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 058ca71cda81..d0344ad9b0d8 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -38,6 +38,15 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name);
38int target_configure_device(struct se_device *dev); 38int target_configure_device(struct se_device *dev);
39void target_free_device(struct se_device *); 39void target_free_device(struct se_device *);
40 40
41/* target_core_fabric_lib.c */
42int target_get_pr_transport_id_len(struct se_node_acl *nacl,
43 struct t10_pr_registration *pr_reg, int *format_code);
44int target_get_pr_transport_id(struct se_node_acl *nacl,
45 struct t10_pr_registration *pr_reg, int *format_code,
46 unsigned char *buf);
47const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
48 const char *buf, u32 *out_tid_len, char **port_nexus_ptr);
49
41/* target_core_hba.c */ 50/* target_core_hba.c */
42struct se_hba *core_alloc_hba(const char *, u32, u32); 51struct se_hba *core_alloc_hba(const char *, u32, u32);
43int core_delete_hba(struct se_hba *); 52int core_delete_hba(struct se_hba *);
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 23c065f83a56..d396b3b87025 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1445,9 +1445,8 @@ core_scsi3_decode_spec_i_port(
1445 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1445 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe;
1446 LIST_HEAD(tid_dest_list); 1446 LIST_HEAD(tid_dest_list);
1447 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; 1447 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp;
1448 const struct target_core_fabric_ops *tmp_tf_ops; 1448 unsigned char *buf, *ptr, proto_ident;
1449 unsigned char *buf; 1449 const unsigned char *i_str;
1450 unsigned char *ptr, *i_str = NULL, proto_ident;
1451 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 1450 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN];
1452 sense_reason_t ret; 1451 sense_reason_t ret;
1453 u32 tpdl, tid_len = 0; 1452 u32 tpdl, tid_len = 0;
@@ -1533,11 +1532,7 @@ core_scsi3_decode_spec_i_port(
1533 tmp_tpg = tmp_port->sep_tpg; 1532 tmp_tpg = tmp_port->sep_tpg;
1534 if (!tmp_tpg) 1533 if (!tmp_tpg)
1535 continue; 1534 continue;
1536 tmp_tf_ops = tmp_tpg->se_tpg_tfo; 1535
1537 if (!tmp_tf_ops)
1538 continue;
1539 if (!tmp_tf_ops->tpg_parse_pr_out_transport_id)
1540 continue;
1541 /* 1536 /*
1542 * Look for the matching proto_ident provided by 1537 * Look for the matching proto_ident provided by
1543 * the received TransportID 1538 * the received TransportID
@@ -1546,9 +1541,8 @@ core_scsi3_decode_spec_i_port(
1546 continue; 1541 continue;
1547 dest_rtpi = tmp_port->sep_rtpi; 1542 dest_rtpi = tmp_port->sep_rtpi;
1548 1543
1549 i_str = tmp_tf_ops->tpg_parse_pr_out_transport_id( 1544 i_str = target_parse_pr_out_transport_id(tmp_tpg,
1550 tmp_tpg, (const char *)ptr, &tid_len, 1545 (const char *)ptr, &tid_len, &iport_ptr);
1551 &iport_ptr);
1552 if (!i_str) 1546 if (!i_str)
1553 continue; 1547 continue;
1554 1548
@@ -3105,7 +3099,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
3105 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; 3099 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg;
3106 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3100 struct t10_reservation *pr_tmpl = &dev->t10_pr;
3107 unsigned char *buf; 3101 unsigned char *buf;
3108 unsigned char *initiator_str; 3102 const unsigned char *initiator_str;
3109 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 3103 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN];
3110 u32 tid_len, tmp_tid_len; 3104 u32 tid_len, tmp_tid_len;
3111 int new_reg = 0, type, scope, matching_iname; 3105 int new_reg = 0, type, scope, matching_iname;
@@ -3237,14 +3231,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
3237 ret = TCM_INVALID_PARAMETER_LIST; 3231 ret = TCM_INVALID_PARAMETER_LIST;
3238 goto out; 3232 goto out;
3239 } 3233 }
3240 if (dest_tf_ops->tpg_parse_pr_out_transport_id == NULL) { 3234 initiator_str = target_parse_pr_out_transport_id(dest_se_tpg,
3241 pr_err("SPC-3 PR REGISTER_AND_MOVE: Fabric does not"
3242 " containg a valid tpg_parse_pr_out_transport_id"
3243 " function pointer\n");
3244 ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
3245 goto out;
3246 }
3247 initiator_str = dest_tf_ops->tpg_parse_pr_out_transport_id(dest_se_tpg,
3248 (const char *)&buf[24], &tmp_tid_len, &iport_ptr); 3235 (const char *)&buf[24], &tmp_tid_len, &iport_ptr);
3249 if (!initiator_str) { 3236 if (!initiator_str) {
3250 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" 3237 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate"
@@ -3881,9 +3868,10 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd)
3881 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 3868 struct t10_pr_registration *pr_reg, *pr_reg_tmp;
3882 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3869 struct t10_reservation *pr_tmpl = &dev->t10_pr;
3883 unsigned char *buf; 3870 unsigned char *buf;
3884 u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len; 3871 u32 add_desc_len = 0, add_len = 0;
3885 u32 off = 8; /* off into first Full Status descriptor */ 3872 u32 off = 8; /* off into first Full Status descriptor */
3886 int format_code = 0, pr_res_type = 0, pr_res_scope = 0; 3873 int format_code = 0, pr_res_type = 0, pr_res_scope = 0;
3874 int exp_desc_len, desc_len;
3887 bool all_reg = false; 3875 bool all_reg = false;
3888 3876
3889 if (cmd->data_length < 8) { 3877 if (cmd->data_length < 8) {
@@ -3928,10 +3916,10 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd)
3928 * Determine expected length of $FABRIC_MOD specific 3916 * Determine expected length of $FABRIC_MOD specific
3929 * TransportID full status descriptor.. 3917 * TransportID full status descriptor..
3930 */ 3918 */
3931 exp_desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id_len( 3919 exp_desc_len = target_get_pr_transport_id_len(se_nacl, pr_reg,
3932 se_tpg, se_nacl, pr_reg, &format_code); 3920 &format_code);
3933 3921 if (exp_desc_len < 0 ||
3934 if ((exp_desc_len + add_len) > cmd->data_length) { 3922 exp_desc_len + add_len > cmd->data_length) {
3935 pr_warn("SPC-3 PRIN READ_FULL_STATUS ran" 3923 pr_warn("SPC-3 PRIN READ_FULL_STATUS ran"
3936 " out of buffer: %d\n", cmd->data_length); 3924 " out of buffer: %d\n", cmd->data_length);
3937 spin_lock(&pr_tmpl->registration_lock); 3925 spin_lock(&pr_tmpl->registration_lock);
@@ -3995,14 +3983,19 @@ core_scsi3_pri_read_full_status(struct se_cmd *cmd)
3995 } else 3983 } else
3996 off += 2; /* Skip over RELATIVE TARGET PORT IDENTIFIER */ 3984 off += 2; /* Skip over RELATIVE TARGET PORT IDENTIFIER */
3997 3985
3986 buf[off+4] = se_tpg->proto_id;
3987
3998 /* 3988 /*
3999 * Now, have the $FABRIC_MOD fill in the protocol identifier 3989 * Now, have the $FABRIC_MOD fill in the transport ID.
4000 */ 3990 */
4001 desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id(se_tpg, 3991 desc_len = target_get_pr_transport_id(se_nacl, pr_reg,
4002 se_nacl, pr_reg, &format_code, &buf[off+4]); 3992 &format_code, &buf[off+4]);
4003 3993
4004 spin_lock(&pr_tmpl->registration_lock); 3994 spin_lock(&pr_tmpl->registration_lock);
4005 atomic_dec_mb(&pr_reg->pr_res_holders); 3995 atomic_dec_mb(&pr_reg->pr_res_holders);
3996
3997 if (desc_len < 0)
3998 break;
4006 /* 3999 /*
4007 * Set the ADDITIONAL DESCRIPTOR LENGTH 4000 * Set the ADDITIONAL DESCRIPTOR LENGTH
4008 */ 4001 */
diff --git a/drivers/target/tcm_fc/tfc_conf.c b/drivers/target/tcm_fc/tfc_conf.c
index fabc7bacf693..6ad7404b7dd1 100644
--- a/drivers/target/tcm_fc/tfc_conf.c
+++ b/drivers/target/tcm_fc/tfc_conf.c
@@ -454,9 +454,6 @@ static const struct target_core_fabric_ops ft_fabric_ops = {
454 .get_fabric_name = ft_get_fabric_name, 454 .get_fabric_name = ft_get_fabric_name,
455 .tpg_get_wwn = ft_get_fabric_wwn, 455 .tpg_get_wwn = ft_get_fabric_wwn,
456 .tpg_get_tag = ft_get_tag, 456 .tpg_get_tag = ft_get_tag,
457 .tpg_get_pr_transport_id = fc_get_pr_transport_id,
458 .tpg_get_pr_transport_id_len = fc_get_pr_transport_id_len,
459 .tpg_parse_pr_out_transport_id = fc_parse_pr_out_transport_id,
460 .tpg_check_demo_mode = ft_check_false, 457 .tpg_check_demo_mode = ft_check_false,
461 .tpg_check_demo_mode_cache = ft_check_false, 458 .tpg_check_demo_mode_cache = ft_check_false,
462 .tpg_check_demo_mode_write_protect = ft_check_false, 459 .tpg_check_demo_mode_write_protect = ft_check_false,
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index d6b03178262f..77cdbb56e1d5 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -1290,72 +1290,6 @@ static u16 usbg_get_tag(struct se_portal_group *se_tpg)
1290 return tpg->tport_tpgt; 1290 return tpg->tport_tpgt;
1291} 1291}
1292 1292
1293static u32 usbg_get_pr_transport_id(
1294 struct se_portal_group *se_tpg,
1295 struct se_node_acl *se_nacl,
1296 struct t10_pr_registration *pr_reg,
1297 int *format_code,
1298 unsigned char *buf)
1299{
1300 struct usbg_tpg *tpg = container_of(se_tpg,
1301 struct usbg_tpg, se_tpg);
1302 struct usbg_tport *tport = tpg->tport;
1303 int ret = 0;
1304
1305 switch (tport->tport_proto_id) {
1306 case SCSI_PROTOCOL_SAS:
1307 default:
1308 ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
1309 format_code, buf);
1310 break;
1311 }
1312
1313 return ret;
1314}
1315
1316static u32 usbg_get_pr_transport_id_len(
1317 struct se_portal_group *se_tpg,
1318 struct se_node_acl *se_nacl,
1319 struct t10_pr_registration *pr_reg,
1320 int *format_code)
1321{
1322 struct usbg_tpg *tpg = container_of(se_tpg,
1323 struct usbg_tpg, se_tpg);
1324 struct usbg_tport *tport = tpg->tport;
1325 int ret = 0;
1326
1327 switch (tport->tport_proto_id) {
1328 case SCSI_PROTOCOL_SAS:
1329 default:
1330 ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
1331 format_code);
1332 break;
1333 }
1334
1335 return ret;
1336}
1337
1338static char *usbg_parse_pr_out_transport_id(
1339 struct se_portal_group *se_tpg,
1340 const char *buf,
1341 u32 *out_tid_len,
1342 char **port_nexus_ptr)
1343{
1344 struct usbg_tpg *tpg = container_of(se_tpg,
1345 struct usbg_tpg, se_tpg);
1346 struct usbg_tport *tport = tpg->tport;
1347 char *tid = NULL;
1348
1349 switch (tport->tport_proto_id) {
1350 case SCSI_PROTOCOL_SAS:
1351 default:
1352 tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
1353 port_nexus_ptr);
1354 }
1355
1356 return tid;
1357}
1358
1359static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg) 1293static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg)
1360{ 1294{
1361 return 1; 1295 return 1;
@@ -1491,8 +1425,12 @@ static struct se_portal_group *usbg_make_tpg(
1491 tpg->tport = tport; 1425 tpg->tport = tport;
1492 tpg->tport_tpgt = tpgt; 1426 tpg->tport_tpgt = tpgt;
1493 1427
1428 /*
1429 * SPC doesn't assign a protocol identifier for USB-SCSI, so we
1430 * pretend to be SAS..
1431 */
1494 ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, 1432 ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg,
1495 tport->tport_proto_id); 1433 SCSI_PROTOCOL_SAS);
1496 if (ret < 0) { 1434 if (ret < 0) {
1497 destroy_workqueue(tpg->workqueue); 1435 destroy_workqueue(tpg->workqueue);
1498 kfree(tpg); 1436 kfree(tpg);
@@ -1788,9 +1726,6 @@ static const struct target_core_fabric_ops usbg_ops = {
1788 .get_fabric_name = usbg_get_fabric_name, 1726 .get_fabric_name = usbg_get_fabric_name,
1789 .tpg_get_wwn = usbg_get_fabric_wwn, 1727 .tpg_get_wwn = usbg_get_fabric_wwn,
1790 .tpg_get_tag = usbg_get_tag, 1728 .tpg_get_tag = usbg_get_tag,
1791 .tpg_get_pr_transport_id = usbg_get_pr_transport_id,
1792 .tpg_get_pr_transport_id_len = usbg_get_pr_transport_id_len,
1793 .tpg_parse_pr_out_transport_id = usbg_parse_pr_out_transport_id,
1794 .tpg_check_demo_mode = usbg_check_true, 1729 .tpg_check_demo_mode = usbg_check_true,
1795 .tpg_check_demo_mode_cache = usbg_check_false, 1730 .tpg_check_demo_mode_cache = usbg_check_false,
1796 .tpg_check_demo_mode_write_protect = usbg_check_false, 1731 .tpg_check_demo_mode_write_protect = usbg_check_false,
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.h b/drivers/usb/gadget/legacy/tcm_usb_gadget.h
index b254aec521da..4c1c22a964b4 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.h
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.h
@@ -44,8 +44,6 @@ struct usbg_tpg {
44}; 44};
45 45
46struct usbg_tport { 46struct usbg_tport {
47 /* SCSI protocol the tport is providing */
48 u8 tport_proto_id;
49 /* Binary World Wide unique Port Name for SAS Target port */ 47 /* Binary World Wide unique Port Name for SAS Target port */
50 u64 tport_wwpn; 48 u64 tport_wwpn;
51 /* ASCII formatted WWPN for SAS Target port */ 49 /* ASCII formatted WWPN for SAS Target port */
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 022860ccd008..db9f4b474214 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -304,97 +304,6 @@ static u16 vhost_scsi_get_tpgt(struct se_portal_group *se_tpg)
304 return tpg->tport_tpgt; 304 return tpg->tport_tpgt;
305} 305}
306 306
307static u32
308vhost_scsi_get_pr_transport_id(struct se_portal_group *se_tpg,
309 struct se_node_acl *se_nacl,
310 struct t10_pr_registration *pr_reg,
311 int *format_code,
312 unsigned char *buf)
313{
314 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
315 struct vhost_scsi_tpg, se_tpg);
316 struct vhost_scsi_tport *tport = tpg->tport;
317
318 switch (tport->tport_proto_id) {
319 case SCSI_PROTOCOL_SAS:
320 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
321 format_code, buf);
322 case SCSI_PROTOCOL_FCP:
323 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
324 format_code, buf);
325 case SCSI_PROTOCOL_ISCSI:
326 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
327 format_code, buf);
328 default:
329 pr_err("Unknown tport_proto_id: 0x%02x, using"
330 " SAS emulation\n", tport->tport_proto_id);
331 break;
332 }
333
334 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
335 format_code, buf);
336}
337
338static u32
339vhost_scsi_get_pr_transport_id_len(struct se_portal_group *se_tpg,
340 struct se_node_acl *se_nacl,
341 struct t10_pr_registration *pr_reg,
342 int *format_code)
343{
344 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
345 struct vhost_scsi_tpg, se_tpg);
346 struct vhost_scsi_tport *tport = tpg->tport;
347
348 switch (tport->tport_proto_id) {
349 case SCSI_PROTOCOL_SAS:
350 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
351 format_code);
352 case SCSI_PROTOCOL_FCP:
353 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
354 format_code);
355 case SCSI_PROTOCOL_ISCSI:
356 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
357 format_code);
358 default:
359 pr_err("Unknown tport_proto_id: 0x%02x, using"
360 " SAS emulation\n", tport->tport_proto_id);
361 break;
362 }
363
364 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
365 format_code);
366}
367
368static char *
369vhost_scsi_parse_pr_out_transport_id(struct se_portal_group *se_tpg,
370 const char *buf,
371 u32 *out_tid_len,
372 char **port_nexus_ptr)
373{
374 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
375 struct vhost_scsi_tpg, se_tpg);
376 struct vhost_scsi_tport *tport = tpg->tport;
377
378 switch (tport->tport_proto_id) {
379 case SCSI_PROTOCOL_SAS:
380 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
381 port_nexus_ptr);
382 case SCSI_PROTOCOL_FCP:
383 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
384 port_nexus_ptr);
385 case SCSI_PROTOCOL_ISCSI:
386 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
387 port_nexus_ptr);
388 default:
389 pr_err("Unknown tport_proto_id: 0x%02x, using"
390 " SAS emulation\n", tport->tport_proto_id);
391 break;
392 }
393
394 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
395 port_nexus_ptr);
396}
397
398static int vhost_scsi_check_prot_fabric_only(struct se_portal_group *se_tpg) 307static int vhost_scsi_check_prot_fabric_only(struct se_portal_group *se_tpg)
399{ 308{
400 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 309 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
@@ -2224,9 +2133,6 @@ static struct target_core_fabric_ops vhost_scsi_ops = {
2224 .get_fabric_name = vhost_scsi_get_fabric_name, 2133 .get_fabric_name = vhost_scsi_get_fabric_name,
2225 .tpg_get_wwn = vhost_scsi_get_fabric_wwn, 2134 .tpg_get_wwn = vhost_scsi_get_fabric_wwn,
2226 .tpg_get_tag = vhost_scsi_get_tpgt, 2135 .tpg_get_tag = vhost_scsi_get_tpgt,
2227 .tpg_get_pr_transport_id = vhost_scsi_get_pr_transport_id,
2228 .tpg_get_pr_transport_id_len = vhost_scsi_get_pr_transport_id_len,
2229 .tpg_parse_pr_out_transport_id = vhost_scsi_parse_pr_out_transport_id,
2230 .tpg_check_demo_mode = vhost_scsi_check_true, 2136 .tpg_check_demo_mode = vhost_scsi_check_true,
2231 .tpg_check_demo_mode_cache = vhost_scsi_check_true, 2137 .tpg_check_demo_mode_cache = vhost_scsi_check_true,
2232 .tpg_check_demo_mode_write_protect = vhost_scsi_check_false, 2138 .tpg_check_demo_mode_write_protect = vhost_scsi_check_false,
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 8bf9448bd7fd..10c71a5616fa 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1270,97 +1270,6 @@ static u16 scsiback_get_tag(struct se_portal_group *se_tpg)
1270 return tpg->tport_tpgt; 1270 return tpg->tport_tpgt;
1271} 1271}
1272 1272
1273static u32
1274scsiback_get_pr_transport_id(struct se_portal_group *se_tpg,
1275 struct se_node_acl *se_nacl,
1276 struct t10_pr_registration *pr_reg,
1277 int *format_code,
1278 unsigned char *buf)
1279{
1280 struct scsiback_tpg *tpg = container_of(se_tpg,
1281 struct scsiback_tpg, se_tpg);
1282 struct scsiback_tport *tport = tpg->tport;
1283
1284 switch (tport->tport_proto_id) {
1285 case SCSI_PROTOCOL_SAS:
1286 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
1287 format_code, buf);
1288 case SCSI_PROTOCOL_FCP:
1289 return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
1290 format_code, buf);
1291 case SCSI_PROTOCOL_ISCSI:
1292 return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
1293 format_code, buf);
1294 default:
1295 pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n",
1296 tport->tport_proto_id);
1297 break;
1298 }
1299
1300 return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,
1301 format_code, buf);
1302}
1303
1304static u32
1305scsiback_get_pr_transport_id_len(struct se_portal_group *se_tpg,
1306 struct se_node_acl *se_nacl,
1307 struct t10_pr_registration *pr_reg,
1308 int *format_code)
1309{
1310 struct scsiback_tpg *tpg = container_of(se_tpg,
1311 struct scsiback_tpg, se_tpg);
1312 struct scsiback_tport *tport = tpg->tport;
1313
1314 switch (tport->tport_proto_id) {
1315 case SCSI_PROTOCOL_SAS:
1316 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
1317 format_code);
1318 case SCSI_PROTOCOL_FCP:
1319 return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
1320 format_code);
1321 case SCSI_PROTOCOL_ISCSI:
1322 return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
1323 format_code);
1324 default:
1325 pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n",
1326 tport->tport_proto_id);
1327 break;
1328 }
1329
1330 return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,
1331 format_code);
1332}
1333
1334static char *
1335scsiback_parse_pr_out_transport_id(struct se_portal_group *se_tpg,
1336 const char *buf,
1337 u32 *out_tid_len,
1338 char **port_nexus_ptr)
1339{
1340 struct scsiback_tpg *tpg = container_of(se_tpg,
1341 struct scsiback_tpg, se_tpg);
1342 struct scsiback_tport *tport = tpg->tport;
1343
1344 switch (tport->tport_proto_id) {
1345 case SCSI_PROTOCOL_SAS:
1346 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
1347 port_nexus_ptr);
1348 case SCSI_PROTOCOL_FCP:
1349 return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
1350 port_nexus_ptr);
1351 case SCSI_PROTOCOL_ISCSI:
1352 return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
1353 port_nexus_ptr);
1354 default:
1355 pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n",
1356 tport->tport_proto_id);
1357 break;
1358 }
1359
1360 return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,
1361 port_nexus_ptr);
1362}
1363
1364static struct se_wwn * 1273static struct se_wwn *
1365scsiback_make_tport(struct target_fabric_configfs *tf, 1274scsiback_make_tport(struct target_fabric_configfs *tf,
1366 struct config_group *group, 1275 struct config_group *group,
@@ -1909,9 +1818,6 @@ static const struct target_core_fabric_ops scsiback_ops = {
1909 .get_fabric_name = scsiback_get_fabric_name, 1818 .get_fabric_name = scsiback_get_fabric_name,
1910 .tpg_get_wwn = scsiback_get_fabric_wwn, 1819 .tpg_get_wwn = scsiback_get_fabric_wwn,
1911 .tpg_get_tag = scsiback_get_tag, 1820 .tpg_get_tag = scsiback_get_tag,
1912 .tpg_get_pr_transport_id = scsiback_get_pr_transport_id,
1913 .tpg_get_pr_transport_id_len = scsiback_get_pr_transport_id_len,
1914 .tpg_parse_pr_out_transport_id = scsiback_parse_pr_out_transport_id,
1915 .tpg_check_demo_mode = scsiback_check_true, 1821 .tpg_check_demo_mode = scsiback_check_true,
1916 .tpg_check_demo_mode_cache = scsiback_check_true, 1822 .tpg_check_demo_mode_cache = scsiback_check_true,
1917 .tpg_check_demo_mode_write_protect = scsiback_check_false, 1823 .tpg_check_demo_mode_write_protect = scsiback_check_false,
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h
index 495606382546..a420f434c6c5 100644
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -9,15 +9,6 @@ struct target_core_fabric_ops {
9 char *(*tpg_get_wwn)(struct se_portal_group *); 9 char *(*tpg_get_wwn)(struct se_portal_group *);
10 u16 (*tpg_get_tag)(struct se_portal_group *); 10 u16 (*tpg_get_tag)(struct se_portal_group *);
11 u32 (*tpg_get_default_depth)(struct se_portal_group *); 11 u32 (*tpg_get_default_depth)(struct se_portal_group *);
12 u32 (*tpg_get_pr_transport_id)(struct se_portal_group *,
13 struct se_node_acl *,
14 struct t10_pr_registration *, int *,
15 unsigned char *);
16 u32 (*tpg_get_pr_transport_id_len)(struct se_portal_group *,
17 struct se_node_acl *,
18 struct t10_pr_registration *, int *);
19 char *(*tpg_parse_pr_out_transport_id)(struct se_portal_group *,
20 const char *, u32 *, char **);
21 int (*tpg_check_demo_mode)(struct se_portal_group *); 12 int (*tpg_check_demo_mode)(struct se_portal_group *);
22 int (*tpg_check_demo_mode_cache)(struct se_portal_group *); 13 int (*tpg_check_demo_mode_cache)(struct se_portal_group *);
23 int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *); 14 int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *);
@@ -177,30 +168,6 @@ int core_tpg_register(const struct target_core_fabric_ops *,
177 struct se_wwn *, struct se_portal_group *, int); 168 struct se_wwn *, struct se_portal_group *, int);
178int core_tpg_deregister(struct se_portal_group *); 169int core_tpg_deregister(struct se_portal_group *);
179 170
180/* SAS helpers */
181u32 sas_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
182 struct t10_pr_registration *, int *, unsigned char *);
183u32 sas_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
184 struct t10_pr_registration *, int *);
185char *sas_parse_pr_out_transport_id(struct se_portal_group *, const char *,
186 u32 *, char **);
187
188/* FC helpers */
189u32 fc_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
190 struct t10_pr_registration *, int *, unsigned char *);
191u32 fc_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
192 struct t10_pr_registration *, int *);
193char *fc_parse_pr_out_transport_id(struct se_portal_group *, const char *,
194 u32 *, char **);
195
196/* iSCSI helpers */
197u32 iscsi_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *,
198 struct t10_pr_registration *, int *, unsigned char *);
199u32 iscsi_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *,
200 struct t10_pr_registration *, int *);
201char *iscsi_parse_pr_out_transport_id(struct se_portal_group *, const char *,
202 u32 *, char **);
203
204/* 171/*
205 * The LIO target core uses DMA_TO_DEVICE to mean that data is going 172 * The LIO target core uses DMA_TO_DEVICE to mean that data is going
206 * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean 173 * to the target (eg handling a WRITE) and DMA_FROM_DEVICE to mean