11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2c66ac9dbSNicholas Bellinger /*******************************************************************************
3c66ac9dbSNicholas Bellinger * Filename: target_core_fabric_lib.c
4c66ac9dbSNicholas Bellinger *
5c66ac9dbSNicholas Bellinger * This file contains generic high level protocol identifier and PR
6c66ac9dbSNicholas Bellinger * handlers for TCM fabric modules
7c66ac9dbSNicholas Bellinger *
84c76251eSNicholas Bellinger * (c) Copyright 2010-2013 Datera, Inc.
9c66ac9dbSNicholas Bellinger *
10c66ac9dbSNicholas Bellinger * Nicholas A. Bellinger <nab@linux-iscsi.org>
11c66ac9dbSNicholas Bellinger *
12c66ac9dbSNicholas Bellinger ******************************************************************************/
13c66ac9dbSNicholas Bellinger
142650d71eSChristoph Hellwig /*
152650d71eSChristoph Hellwig * See SPC4, section 7.5 "Protocol specific parameters" for details
162650d71eSChristoph Hellwig * on the formats implemented in this file.
172650d71eSChristoph Hellwig */
182650d71eSChristoph Hellwig
1911650b85SAndy Shevchenko #include <linux/kernel.h>
20c66ac9dbSNicholas Bellinger #include <linux/string.h>
21c66ac9dbSNicholas Bellinger #include <linux/ctype.h>
22c66ac9dbSNicholas Bellinger #include <linux/spinlock.h>
23c53181afSPaul Gortmaker #include <linux/export.h>
24a85d667eSBart Van Assche #include <asm/unaligned.h>
25c66ac9dbSNicholas Bellinger
266546a02aSStephen Rothwell #include <scsi/scsi_proto.h>
276546a02aSStephen Rothwell
28c66ac9dbSNicholas Bellinger #include <target/target_core_base.h>
29c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h>
30c66ac9dbSNicholas Bellinger
31e26d99aeSChristoph Hellwig #include "target_core_internal.h"
32c66ac9dbSNicholas Bellinger #include "target_core_pr.h"
33c66ac9dbSNicholas Bellinger
34c66ac9dbSNicholas Bellinger
sas_get_pr_transport_id(struct se_node_acl * nacl,int * format_code,unsigned char * buf)352650d71eSChristoph Hellwig static int sas_get_pr_transport_id(
362650d71eSChristoph Hellwig struct se_node_acl *nacl,
37c66ac9dbSNicholas Bellinger int *format_code,
38c66ac9dbSNicholas Bellinger unsigned char *buf)
39c66ac9dbSNicholas Bellinger {
408c35ad20SMimi Zohar int ret;
4111650b85SAndy Shevchenko
422650d71eSChristoph Hellwig /* Skip over 'naa. prefix */
432650d71eSChristoph Hellwig ret = hex2bin(&buf[4], &nacl->initiatorname[4], 8);
442650d71eSChristoph Hellwig if (ret) {
452650d71eSChristoph Hellwig pr_debug("%s: invalid hex string\n", __func__);
462650d71eSChristoph Hellwig return ret;
472650d71eSChristoph Hellwig }
48c66ac9dbSNicholas Bellinger
49c66ac9dbSNicholas Bellinger return 24;
50c66ac9dbSNicholas Bellinger }
51c66ac9dbSNicholas Bellinger
fc_get_pr_transport_id(struct se_node_acl * se_nacl,int * format_code,unsigned char * buf)522650d71eSChristoph Hellwig static int fc_get_pr_transport_id(
53c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl,
54c66ac9dbSNicholas Bellinger int *format_code,
55c66ac9dbSNicholas Bellinger unsigned char *buf)
56c66ac9dbSNicholas Bellinger {
5711650b85SAndy Shevchenko unsigned char *ptr;
588c35ad20SMimi Zohar int i, ret;
59c66ac9dbSNicholas Bellinger u32 off = 8;
608c35ad20SMimi Zohar
61c66ac9dbSNicholas Bellinger /*
62c66ac9dbSNicholas Bellinger * We convert the ASCII formatted N Port name into a binary
63c66ac9dbSNicholas Bellinger * encoded TransportID.
64c66ac9dbSNicholas Bellinger */
65c66ac9dbSNicholas Bellinger ptr = &se_nacl->initiatorname[0];
668fed04ebSBodo Stroesser for (i = 0; i < 23; ) {
676708bb27SAndy Grover if (!strncmp(&ptr[i], ":", 1)) {
68c66ac9dbSNicholas Bellinger i++;
69c66ac9dbSNicholas Bellinger continue;
70c66ac9dbSNicholas Bellinger }
718c35ad20SMimi Zohar ret = hex2bin(&buf[off++], &ptr[i], 1);
722650d71eSChristoph Hellwig if (ret < 0) {
732650d71eSChristoph Hellwig pr_debug("%s: invalid hex string\n", __func__);
742650d71eSChristoph Hellwig return ret;
752650d71eSChristoph Hellwig }
76c66ac9dbSNicholas Bellinger i += 2;
77c66ac9dbSNicholas Bellinger }
78c66ac9dbSNicholas Bellinger /*
79c66ac9dbSNicholas Bellinger * The FC Transport ID is a hardcoded 24-byte length
80c66ac9dbSNicholas Bellinger */
81c66ac9dbSNicholas Bellinger return 24;
82c66ac9dbSNicholas Bellinger }
83c66ac9dbSNicholas Bellinger
sbp_get_pr_transport_id(struct se_node_acl * nacl,int * format_code,unsigned char * buf)842650d71eSChristoph Hellwig static int sbp_get_pr_transport_id(
852650d71eSChristoph Hellwig struct se_node_acl *nacl,
862650d71eSChristoph Hellwig int *format_code,
872650d71eSChristoph Hellwig unsigned char *buf)
88c66ac9dbSNicholas Bellinger {
892650d71eSChristoph Hellwig int ret;
90c66ac9dbSNicholas Bellinger
912650d71eSChristoph Hellwig ret = hex2bin(&buf[8], nacl->initiatorname, 8);
922650d71eSChristoph Hellwig if (ret) {
932650d71eSChristoph Hellwig pr_debug("%s: invalid hex string\n", __func__);
942650d71eSChristoph Hellwig return ret;
95c66ac9dbSNicholas Bellinger }
96c66ac9dbSNicholas Bellinger
972650d71eSChristoph Hellwig return 24;
982650d71eSChristoph Hellwig }
99c66ac9dbSNicholas Bellinger
srp_get_pr_transport_id(struct se_node_acl * nacl,int * format_code,unsigned char * buf)1002650d71eSChristoph Hellwig static int srp_get_pr_transport_id(
1012650d71eSChristoph Hellwig struct se_node_acl *nacl,
1022650d71eSChristoph Hellwig int *format_code,
1032650d71eSChristoph Hellwig unsigned char *buf)
104c66ac9dbSNicholas Bellinger {
1052650d71eSChristoph Hellwig const char *p;
1062650d71eSChristoph Hellwig unsigned len, count, leading_zero_bytes;
1072650d71eSChristoph Hellwig int rc;
108c66ac9dbSNicholas Bellinger
1092650d71eSChristoph Hellwig p = nacl->initiatorname;
1102650d71eSChristoph Hellwig if (strncasecmp(p, "0x", 2) == 0)
1112650d71eSChristoph Hellwig p += 2;
1122650d71eSChristoph Hellwig len = strlen(p);
1132650d71eSChristoph Hellwig if (len % 2)
1142650d71eSChristoph Hellwig return -EINVAL;
1152650d71eSChristoph Hellwig
1162650d71eSChristoph Hellwig count = min(len / 2, 16U);
1172650d71eSChristoph Hellwig leading_zero_bytes = 16 - count;
1182650d71eSChristoph Hellwig memset(buf + 8, 0, leading_zero_bytes);
1192650d71eSChristoph Hellwig rc = hex2bin(buf + 8 + leading_zero_bytes, p, count);
1202650d71eSChristoph Hellwig if (rc < 0) {
121c941e0d1SBart Van Assche pr_debug("hex2bin failed for %s: %d\n", p, rc);
1222650d71eSChristoph Hellwig return rc;
1232650d71eSChristoph Hellwig }
1242650d71eSChristoph Hellwig
1252650d71eSChristoph Hellwig return 24;
1262650d71eSChristoph Hellwig }
1272650d71eSChristoph Hellwig
iscsi_get_pr_transport_id(struct se_node_acl * se_nacl,struct t10_pr_registration * pr_reg,int * format_code,unsigned char * buf)1282650d71eSChristoph Hellwig static int iscsi_get_pr_transport_id(
129c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl,
130c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg,
131c66ac9dbSNicholas Bellinger int *format_code,
132c66ac9dbSNicholas Bellinger unsigned char *buf)
133c66ac9dbSNicholas Bellinger {
134c66ac9dbSNicholas Bellinger u32 off = 4, padding = 0;
135639341bfSMike Christie int isid_len;
136c66ac9dbSNicholas Bellinger u16 len = 0;
137c66ac9dbSNicholas Bellinger
138c66ac9dbSNicholas Bellinger spin_lock_irq(&se_nacl->nacl_sess_lock);
139c66ac9dbSNicholas Bellinger /*
140a6f9b6ceSMike Christie * Only null terminate the last field.
141c66ac9dbSNicholas Bellinger *
142a6f9b6ceSMike Christie * From spc4r37 section 7.6.4.6: TransportID for initiator ports using
143a6f9b6ceSMike Christie * SCSI over iSCSI.
144a6f9b6ceSMike Christie *
145a6f9b6ceSMike Christie * Table 507 TPID=0 Initiator device TransportID
146a6f9b6ceSMike Christie *
147a6f9b6ceSMike Christie * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall
148a6f9b6ceSMike Christie * contain the iSCSI name of an iSCSI initiator node (see RFC 7143).
149a6f9b6ceSMike Christie * The first ISCSI NAME field byte containing an ASCII null character
150a6f9b6ceSMike Christie * terminates the ISCSI NAME field without regard for the specified
151a6f9b6ceSMike Christie * length of the iSCSI TransportID or the contents of the ADDITIONAL
152a6f9b6ceSMike Christie * LENGTH field.
153c66ac9dbSNicholas Bellinger */
154c66ac9dbSNicholas Bellinger len = sprintf(&buf[off], "%s", se_nacl->initiatorname);
155a6f9b6ceSMike Christie off += len;
156c66ac9dbSNicholas Bellinger if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) {
157c66ac9dbSNicholas Bellinger /*
158c66ac9dbSNicholas Bellinger * Set FORMAT CODE 01b for iSCSI Initiator port TransportID
159c66ac9dbSNicholas Bellinger * format.
160c66ac9dbSNicholas Bellinger */
161c66ac9dbSNicholas Bellinger buf[0] |= 0x40;
162c66ac9dbSNicholas Bellinger /*
163a6f9b6ceSMike Christie * From spc4r37 Section 7.6.4.6
164a6f9b6ceSMike Christie *
165a6f9b6ceSMike Christie * Table 508 TPID=1 Initiator port TransportID.
166a6f9b6ceSMike Christie *
167a6f9b6ceSMike Christie * The ISCSI NAME field shall not be null-terminated
168a6f9b6ceSMike Christie * (see 4.3.2) and shall not be padded.
169c66ac9dbSNicholas Bellinger *
170c66ac9dbSNicholas Bellinger * The SEPARATOR field shall contain the five ASCII
171c66ac9dbSNicholas Bellinger * characters ",i,0x".
172c66ac9dbSNicholas Bellinger *
173c66ac9dbSNicholas Bellinger * The null-terminated, null-padded ISCSI INITIATOR SESSION ID
174c66ac9dbSNicholas Bellinger * field shall contain the iSCSI initiator session identifier
175c66ac9dbSNicholas Bellinger * (see RFC 3720) in the form of ASCII characters that are the
176c66ac9dbSNicholas Bellinger * hexadecimal digits converted from the binary iSCSI initiator
177c66ac9dbSNicholas Bellinger * session identifier value. The first ISCSI INITIATOR SESSION
178a6f9b6ceSMike Christie * ID field byte containing an ASCII null character terminates
179a6f9b6ceSMike Christie * the ISCSI INITIATOR SESSION ID field without regard for the
180a6f9b6ceSMike Christie * specified length of the iSCSI TransportID or the contents
181a6f9b6ceSMike Christie * of the ADDITIONAL LENGTH field.
182c66ac9dbSNicholas Bellinger */
183a6f9b6ceSMike Christie buf[off++] = 0x2c; /* ASCII Character: "," */
184a6f9b6ceSMike Christie buf[off++] = 0x69; /* ASCII Character: "i" */
185a6f9b6ceSMike Christie buf[off++] = 0x2c; /* ASCII Character: "," */
186a6f9b6ceSMike Christie buf[off++] = 0x30; /* ASCII Character: "0" */
187a6f9b6ceSMike Christie buf[off++] = 0x78; /* ASCII Character: "x" */
188639341bfSMike Christie len += 5;
189a6f9b6ceSMike Christie
190639341bfSMike Christie isid_len = sprintf(buf + off, "%s", pr_reg->pr_reg_isid);
191639341bfSMike Christie off += isid_len;
192639341bfSMike Christie len += isid_len;
193c66ac9dbSNicholas Bellinger }
194a6f9b6ceSMike Christie buf[off] = '\0';
195a6f9b6ceSMike Christie len += 1;
196c66ac9dbSNicholas Bellinger spin_unlock_irq(&se_nacl->nacl_sess_lock);
197c66ac9dbSNicholas Bellinger /*
198c66ac9dbSNicholas Bellinger * The ADDITIONAL LENGTH field specifies the number of bytes that follow
199c66ac9dbSNicholas Bellinger * in the TransportID. The additional length shall be at least 20 and
200c66ac9dbSNicholas Bellinger * shall be a multiple of four.
201c66ac9dbSNicholas Bellinger */
202c66ac9dbSNicholas Bellinger padding = ((-len) & 3);
203c66ac9dbSNicholas Bellinger if (padding != 0)
204c66ac9dbSNicholas Bellinger len += padding;
205c66ac9dbSNicholas Bellinger
206a85d667eSBart Van Assche put_unaligned_be16(len, &buf[2]);
207c66ac9dbSNicholas Bellinger /*
208c66ac9dbSNicholas Bellinger * Increment value for total payload + header length for
209c66ac9dbSNicholas Bellinger * full status descriptor
210c66ac9dbSNicholas Bellinger */
211c66ac9dbSNicholas Bellinger len += 4;
212c66ac9dbSNicholas Bellinger
213c66ac9dbSNicholas Bellinger return len;
214c66ac9dbSNicholas Bellinger }
215c66ac9dbSNicholas Bellinger
iscsi_get_pr_transport_id_len(struct se_node_acl * se_nacl,struct t10_pr_registration * pr_reg,int * format_code)2162650d71eSChristoph Hellwig static int iscsi_get_pr_transport_id_len(
217c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl,
218c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg,
219c66ac9dbSNicholas Bellinger int *format_code)
220c66ac9dbSNicholas Bellinger {
221c66ac9dbSNicholas Bellinger u32 len = 0, padding = 0;
222c66ac9dbSNicholas Bellinger
223c66ac9dbSNicholas Bellinger spin_lock_irq(&se_nacl->nacl_sess_lock);
224c66ac9dbSNicholas Bellinger len = strlen(se_nacl->initiatorname);
225c66ac9dbSNicholas Bellinger /*
226c66ac9dbSNicholas Bellinger * Add extra byte for NULL terminator
227c66ac9dbSNicholas Bellinger */
228c66ac9dbSNicholas Bellinger len++;
229c66ac9dbSNicholas Bellinger /*
230c66ac9dbSNicholas Bellinger * If there is ISID present with the registration, use format code:
231c66ac9dbSNicholas Bellinger * 01b: iSCSI Initiator port TransportID format
232c66ac9dbSNicholas Bellinger *
233c66ac9dbSNicholas Bellinger * If there is not an active iSCSI session, use format code:
234c66ac9dbSNicholas Bellinger * 00b: iSCSI Initiator device TransportID format
235c66ac9dbSNicholas Bellinger */
236c66ac9dbSNicholas Bellinger if (pr_reg->isid_present_at_reg) {
23735d1efe8SMasanari Iida len += 5; /* For ",i,0x" ASCII separator */
238639341bfSMike Christie len += strlen(pr_reg->pr_reg_isid);
239c66ac9dbSNicholas Bellinger *format_code = 1;
240c66ac9dbSNicholas Bellinger } else
241c66ac9dbSNicholas Bellinger *format_code = 0;
242c66ac9dbSNicholas Bellinger spin_unlock_irq(&se_nacl->nacl_sess_lock);
243c66ac9dbSNicholas Bellinger /*
244c66ac9dbSNicholas Bellinger * The ADDITIONAL LENGTH field specifies the number of bytes that follow
245c66ac9dbSNicholas Bellinger * in the TransportID. The additional length shall be at least 20 and
246c66ac9dbSNicholas Bellinger * shall be a multiple of four.
247c66ac9dbSNicholas Bellinger */
248c66ac9dbSNicholas Bellinger padding = ((-len) & 3);
249c66ac9dbSNicholas Bellinger if (padding != 0)
250c66ac9dbSNicholas Bellinger len += padding;
251c66ac9dbSNicholas Bellinger /*
252c66ac9dbSNicholas Bellinger * Increment value for total payload + header length for
253c66ac9dbSNicholas Bellinger * full status descriptor
254c66ac9dbSNicholas Bellinger */
255c66ac9dbSNicholas Bellinger len += 4;
256c66ac9dbSNicholas Bellinger
257c66ac9dbSNicholas Bellinger return len;
258c66ac9dbSNicholas Bellinger }
259c66ac9dbSNicholas Bellinger
iscsi_parse_pr_out_transport_id(struct se_portal_group * se_tpg,char * buf,u32 * out_tid_len,char ** port_nexus_ptr)2602650d71eSChristoph Hellwig static char *iscsi_parse_pr_out_transport_id(
261c66ac9dbSNicholas Bellinger struct se_portal_group *se_tpg,
262094bb5d7SRasmus Villemoes char *buf,
263c66ac9dbSNicholas Bellinger u32 *out_tid_len,
264c66ac9dbSNicholas Bellinger char **port_nexus_ptr)
265c66ac9dbSNicholas Bellinger {
266c66ac9dbSNicholas Bellinger char *p;
267c66ac9dbSNicholas Bellinger int i;
268c66ac9dbSNicholas Bellinger u8 format_code = (buf[0] & 0xc0);
269c66ac9dbSNicholas Bellinger /*
270c66ac9dbSNicholas Bellinger * Check for FORMAT CODE 00b or 01b from spc4r17, section 7.5.4.6:
271c66ac9dbSNicholas Bellinger *
272c66ac9dbSNicholas Bellinger * TransportID for initiator ports using SCSI over iSCSI,
273c66ac9dbSNicholas Bellinger * from Table 388 -- iSCSI TransportID formats.
274c66ac9dbSNicholas Bellinger *
275c66ac9dbSNicholas Bellinger * 00b Initiator port is identified using the world wide unique
276c66ac9dbSNicholas Bellinger * SCSI device name of the iSCSI initiator
277c66ac9dbSNicholas Bellinger * device containing the initiator port (see table 389).
278c66ac9dbSNicholas Bellinger * 01b Initiator port is identified using the world wide unique
279c66ac9dbSNicholas Bellinger * initiator port identifier (see table 390).10b to 11b
280c66ac9dbSNicholas Bellinger * Reserved
281c66ac9dbSNicholas Bellinger */
282c66ac9dbSNicholas Bellinger if ((format_code != 0x00) && (format_code != 0x40)) {
2836708bb27SAndy Grover pr_err("Illegal format code: 0x%02x for iSCSI"
284c66ac9dbSNicholas Bellinger " Initiator Transport ID\n", format_code);
285c66ac9dbSNicholas Bellinger return NULL;
286c66ac9dbSNicholas Bellinger }
287c66ac9dbSNicholas Bellinger /*
288c66ac9dbSNicholas Bellinger * If the caller wants the TransportID Length, we set that value for the
289c66ac9dbSNicholas Bellinger * entire iSCSI Tarnsport ID now.
290c66ac9dbSNicholas Bellinger */
29168edbce4SJoern Engel if (out_tid_len) {
29268edbce4SJoern Engel /* The shift works thanks to integer promotion rules */
293169622eeSMike Christie *out_tid_len = get_unaligned_be16(&buf[2]);
294169622eeSMike Christie /* Add four bytes for iSCSI Transport ID header */
295169622eeSMike Christie *out_tid_len += 4;
296c66ac9dbSNicholas Bellinger }
297169622eeSMike Christie
298c66ac9dbSNicholas Bellinger /*
29935d1efe8SMasanari Iida * Check for ',i,0x' separator between iSCSI Name and iSCSI Initiator
300c66ac9dbSNicholas Bellinger * Session ID as defined in Table 390 - iSCSI initiator port TransportID
301c66ac9dbSNicholas Bellinger * format.
302c66ac9dbSNicholas Bellinger */
303c66ac9dbSNicholas Bellinger if (format_code == 0x40) {
3048359cf43SJörn Engel p = strstr(&buf[4], ",i,0x");
3056708bb27SAndy Grover if (!p) {
30635d1efe8SMasanari Iida pr_err("Unable to locate \",i,0x\" separator"
307c66ac9dbSNicholas Bellinger " for Initiator port identifier: %s\n",
3088359cf43SJörn Engel &buf[4]);
309c66ac9dbSNicholas Bellinger return NULL;
310c66ac9dbSNicholas Bellinger }
311c66ac9dbSNicholas Bellinger *p = '\0'; /* Terminate iSCSI Name */
31235d1efe8SMasanari Iida p += 5; /* Skip over ",i,0x" separator */
313c66ac9dbSNicholas Bellinger
314c66ac9dbSNicholas Bellinger *port_nexus_ptr = p;
315c66ac9dbSNicholas Bellinger /*
316c66ac9dbSNicholas Bellinger * Go ahead and do the lower case conversion of the received
317c66ac9dbSNicholas Bellinger * 12 ASCII characters representing the ISID in the TransportID
31825985edcSLucas De Marchi * for comparison against the running iSCSI session's ISID from
319c66ac9dbSNicholas Bellinger * iscsi_target.c:lio_sess_get_initiator_sid()
320c66ac9dbSNicholas Bellinger */
321c66ac9dbSNicholas Bellinger for (i = 0; i < 12; i++) {
322639341bfSMike Christie /*
323639341bfSMike Christie * The first ISCSI INITIATOR SESSION ID field byte
324639341bfSMike Christie * containing an ASCII null character terminates the
325639341bfSMike Christie * ISCSI INITIATOR SESSION ID field without regard for
326639341bfSMike Christie * the specified length of the iSCSI TransportID or the
327639341bfSMike Christie * contents of the ADDITIONAL LENGTH field.
328639341bfSMike Christie */
329639341bfSMike Christie if (*p == '\0')
330639341bfSMike Christie break;
331639341bfSMike Christie
332c66ac9dbSNicholas Bellinger if (isdigit(*p)) {
333c66ac9dbSNicholas Bellinger p++;
334c66ac9dbSNicholas Bellinger continue;
335c66ac9dbSNicholas Bellinger }
336c66ac9dbSNicholas Bellinger *p = tolower(*p);
337c66ac9dbSNicholas Bellinger p++;
338c66ac9dbSNicholas Bellinger }
33913ef143dSBodo Stroesser } else
34013ef143dSBodo Stroesser *port_nexus_ptr = NULL;
341c66ac9dbSNicholas Bellinger
342094bb5d7SRasmus Villemoes return &buf[4];
343c66ac9dbSNicholas Bellinger }
3442650d71eSChristoph Hellwig
target_get_pr_transport_id_len(struct se_node_acl * nacl,struct t10_pr_registration * pr_reg,int * format_code)3452650d71eSChristoph Hellwig int target_get_pr_transport_id_len(struct se_node_acl *nacl,
3462650d71eSChristoph Hellwig struct t10_pr_registration *pr_reg, int *format_code)
3472650d71eSChristoph Hellwig {
3482650d71eSChristoph Hellwig switch (nacl->se_tpg->proto_id) {
3492650d71eSChristoph Hellwig case SCSI_PROTOCOL_FCP:
3502650d71eSChristoph Hellwig case SCSI_PROTOCOL_SBP:
3512650d71eSChristoph Hellwig case SCSI_PROTOCOL_SRP:
3522650d71eSChristoph Hellwig case SCSI_PROTOCOL_SAS:
3532650d71eSChristoph Hellwig break;
3542650d71eSChristoph Hellwig case SCSI_PROTOCOL_ISCSI:
3552650d71eSChristoph Hellwig return iscsi_get_pr_transport_id_len(nacl, pr_reg, format_code);
3562650d71eSChristoph Hellwig default:
3572650d71eSChristoph Hellwig pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id);
3582650d71eSChristoph Hellwig return -EINVAL;
3592650d71eSChristoph Hellwig }
3602650d71eSChristoph Hellwig
3612650d71eSChristoph Hellwig /*
3622650d71eSChristoph Hellwig * Most transports use a fixed length 24 byte identifier.
3632650d71eSChristoph Hellwig */
3642650d71eSChristoph Hellwig *format_code = 0;
3652650d71eSChristoph Hellwig return 24;
3662650d71eSChristoph Hellwig }
3672650d71eSChristoph Hellwig
target_get_pr_transport_id(struct se_node_acl * nacl,struct t10_pr_registration * pr_reg,int * format_code,unsigned char * buf)3682650d71eSChristoph Hellwig int target_get_pr_transport_id(struct se_node_acl *nacl,
3692650d71eSChristoph Hellwig struct t10_pr_registration *pr_reg, int *format_code,
3702650d71eSChristoph Hellwig unsigned char *buf)
3712650d71eSChristoph Hellwig {
3722650d71eSChristoph Hellwig switch (nacl->se_tpg->proto_id) {
3732650d71eSChristoph Hellwig case SCSI_PROTOCOL_SAS:
3742650d71eSChristoph Hellwig return sas_get_pr_transport_id(nacl, format_code, buf);
3752650d71eSChristoph Hellwig case SCSI_PROTOCOL_SBP:
3762650d71eSChristoph Hellwig return sbp_get_pr_transport_id(nacl, format_code, buf);
3772650d71eSChristoph Hellwig case SCSI_PROTOCOL_SRP:
3782650d71eSChristoph Hellwig return srp_get_pr_transport_id(nacl, format_code, buf);
3792650d71eSChristoph Hellwig case SCSI_PROTOCOL_FCP:
3802650d71eSChristoph Hellwig return fc_get_pr_transport_id(nacl, format_code, buf);
3812650d71eSChristoph Hellwig case SCSI_PROTOCOL_ISCSI:
3822650d71eSChristoph Hellwig return iscsi_get_pr_transport_id(nacl, pr_reg, format_code,
3832650d71eSChristoph Hellwig buf);
3842650d71eSChristoph Hellwig default:
3852650d71eSChristoph Hellwig pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id);
3862650d71eSChristoph Hellwig return -EINVAL;
3872650d71eSChristoph Hellwig }
3882650d71eSChristoph Hellwig }
3892650d71eSChristoph Hellwig
target_parse_pr_out_transport_id(struct se_portal_group * tpg,char * buf,u32 * out_tid_len,char ** port_nexus_ptr)3902650d71eSChristoph Hellwig const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
391094bb5d7SRasmus Villemoes char *buf, u32 *out_tid_len, char **port_nexus_ptr)
3922650d71eSChristoph Hellwig {
3932650d71eSChristoph Hellwig u32 offset;
3942650d71eSChristoph Hellwig
3952650d71eSChristoph Hellwig switch (tpg->proto_id) {
3962650d71eSChristoph Hellwig case SCSI_PROTOCOL_SAS:
3972650d71eSChristoph Hellwig /*
3982650d71eSChristoph Hellwig * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID
3992650d71eSChristoph Hellwig * for initiator ports using SCSI over SAS Serial SCSI Protocol.
4002650d71eSChristoph Hellwig */
4012650d71eSChristoph Hellwig offset = 4;
4022650d71eSChristoph Hellwig break;
4032650d71eSChristoph Hellwig case SCSI_PROTOCOL_SBP:
4042650d71eSChristoph Hellwig case SCSI_PROTOCOL_SRP:
4052650d71eSChristoph Hellwig case SCSI_PROTOCOL_FCP:
4062650d71eSChristoph Hellwig offset = 8;
4072650d71eSChristoph Hellwig break;
4082650d71eSChristoph Hellwig case SCSI_PROTOCOL_ISCSI:
4092650d71eSChristoph Hellwig return iscsi_parse_pr_out_transport_id(tpg, buf, out_tid_len,
4102650d71eSChristoph Hellwig port_nexus_ptr);
4112650d71eSChristoph Hellwig default:
4122650d71eSChristoph Hellwig pr_err("Unknown proto_id: 0x%02x\n", tpg->proto_id);
4132650d71eSChristoph Hellwig return NULL;
4142650d71eSChristoph Hellwig }
4152650d71eSChristoph Hellwig
4162650d71eSChristoph Hellwig *port_nexus_ptr = NULL;
4172650d71eSChristoph Hellwig *out_tid_len = 24;
4182650d71eSChristoph Hellwig return buf + offset;
4192650d71eSChristoph Hellwig }
420