1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/kernel.h>
29#include <linux/string.h>
30#include <linux/ctype.h>
31#include <linux/spinlock.h>
32#include <linux/export.h>
33#include <scsi/scsi.h>
34#include <scsi/scsi_cmnd.h>
35
36#include <target/target_core_base.h>
37#include <target/target_core_device.h>
38#include <target/target_core_transport.h>
39#include <target/target_core_fabric_lib.h>
40#include <target/target_core_fabric_ops.h>
41#include <target/target_core_configfs.h>
42
43#include "target_core_hba.h"
44#include "target_core_pr.h"
45
46
47
48
49u8 sas_get_fabric_proto_ident(struct se_portal_group *se_tpg)
50{
51
52
53
54
55 return 0x6;
56}
57EXPORT_SYMBOL(sas_get_fabric_proto_ident);
58
59u32 sas_get_pr_transport_id(
60 struct se_portal_group *se_tpg,
61 struct se_node_acl *se_nacl,
62 struct t10_pr_registration *pr_reg,
63 int *format_code,
64 unsigned char *buf)
65{
66 unsigned char *ptr;
67 int ret;
68
69
70
71
72 buf[0] = 0x06;
73
74
75
76
77 ptr = &se_nacl->initiatorname[4];
78
79 ret = hex2bin(&buf[4], ptr, 8);
80 if (ret < 0)
81 pr_debug("sas transport_id: invalid hex string\n");
82
83
84
85
86 return 24;
87}
88EXPORT_SYMBOL(sas_get_pr_transport_id);
89
90u32 sas_get_pr_transport_id_len(
91 struct se_portal_group *se_tpg,
92 struct se_node_acl *se_nacl,
93 struct t10_pr_registration *pr_reg,
94 int *format_code)
95{
96 *format_code = 0;
97
98
99
100
101
102
103 return 24;
104}
105EXPORT_SYMBOL(sas_get_pr_transport_id_len);
106
107
108
109
110
111char *sas_parse_pr_out_transport_id(
112 struct se_portal_group *se_tpg,
113 const char *buf,
114 u32 *out_tid_len,
115 char **port_nexus_ptr)
116{
117
118
119
120
121
122
123
124
125 *port_nexus_ptr = NULL;
126 *out_tid_len = 24;
127
128 return (char *)&buf[4];
129}
130EXPORT_SYMBOL(sas_parse_pr_out_transport_id);
131
132
133
134
135u8 fc_get_fabric_proto_ident(struct se_portal_group *se_tpg)
136{
137 return 0x0;
138}
139EXPORT_SYMBOL(fc_get_fabric_proto_ident);
140
141u32 fc_get_pr_transport_id_len(
142 struct se_portal_group *se_tpg,
143 struct se_node_acl *se_nacl,
144 struct t10_pr_registration *pr_reg,
145 int *format_code)
146{
147 *format_code = 0;
148
149
150
151 return 24;
152}
153EXPORT_SYMBOL(fc_get_pr_transport_id_len);
154
155u32 fc_get_pr_transport_id(
156 struct se_portal_group *se_tpg,
157 struct se_node_acl *se_nacl,
158 struct t10_pr_registration *pr_reg,
159 int *format_code,
160 unsigned char *buf)
161{
162 unsigned char *ptr;
163 int i, ret;
164 u32 off = 8;
165
166
167
168
169
170
171
172
173
174
175 ptr = &se_nacl->initiatorname[0];
176
177 for (i = 0; i < 24; ) {
178 if (!strncmp(&ptr[i], ":", 1)) {
179 i++;
180 continue;
181 }
182 ret = hex2bin(&buf[off++], &ptr[i], 1);
183 if (ret < 0)
184 pr_debug("fc transport_id: invalid hex string\n");
185 i += 2;
186 }
187
188
189
190 return 24;
191}
192EXPORT_SYMBOL(fc_get_pr_transport_id);
193
194char *fc_parse_pr_out_transport_id(
195 struct se_portal_group *se_tpg,
196 const char *buf,
197 u32 *out_tid_len,
198 char **port_nexus_ptr)
199{
200
201
202
203
204
205 *port_nexus_ptr = NULL;
206 *out_tid_len = 24;
207
208 return (char *)&buf[8];
209}
210EXPORT_SYMBOL(fc_parse_pr_out_transport_id);
211
212
213
214
215
216u8 iscsi_get_fabric_proto_ident(struct se_portal_group *se_tpg)
217{
218
219
220
221
222 return 0x5;
223}
224EXPORT_SYMBOL(iscsi_get_fabric_proto_ident);
225
226u32 iscsi_get_pr_transport_id(
227 struct se_portal_group *se_tpg,
228 struct se_node_acl *se_nacl,
229 struct t10_pr_registration *pr_reg,
230 int *format_code,
231 unsigned char *buf)
232{
233 u32 off = 4, padding = 0;
234 u16 len = 0;
235
236 spin_lock_irq(&se_nacl->nacl_sess_lock);
237
238
239
240 buf[0] = 0x05;
241
242
243
244
245
246
247
248
249
250
251
252 len = sprintf(&buf[off], "%s", se_nacl->initiatorname);
253
254
255
256 len++;
257
258
259
260
261
262
263
264
265 if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) {
266
267
268
269
270 buf[0] |= 0x40;
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 buf[off+len] = 0x2c; off++;
286 buf[off+len] = 0x69; off++;
287 buf[off+len] = 0x2c; off++;
288 buf[off+len] = 0x30; off++;
289 buf[off+len] = 0x78; off++;
290 len += 5;
291 buf[off+len] = pr_reg->pr_reg_isid[0]; off++;
292 buf[off+len] = pr_reg->pr_reg_isid[1]; off++;
293 buf[off+len] = pr_reg->pr_reg_isid[2]; off++;
294 buf[off+len] = pr_reg->pr_reg_isid[3]; off++;
295 buf[off+len] = pr_reg->pr_reg_isid[4]; off++;
296 buf[off+len] = pr_reg->pr_reg_isid[5]; off++;
297 buf[off+len] = '\0'; off++;
298 len += 7;
299 }
300 spin_unlock_irq(&se_nacl->nacl_sess_lock);
301
302
303
304
305
306 padding = ((-len) & 3);
307 if (padding != 0)
308 len += padding;
309
310 buf[2] = ((len >> 8) & 0xff);
311 buf[3] = (len & 0xff);
312
313
314
315
316 len += 4;
317
318 return len;
319}
320EXPORT_SYMBOL(iscsi_get_pr_transport_id);
321
322u32 iscsi_get_pr_transport_id_len(
323 struct se_portal_group *se_tpg,
324 struct se_node_acl *se_nacl,
325 struct t10_pr_registration *pr_reg,
326 int *format_code)
327{
328 u32 len = 0, padding = 0;
329
330 spin_lock_irq(&se_nacl->nacl_sess_lock);
331 len = strlen(se_nacl->initiatorname);
332
333
334
335 len++;
336
337
338
339
340
341
342
343 if (pr_reg->isid_present_at_reg) {
344 len += 5;
345 len += 7;
346 *format_code = 1;
347 } else
348 *format_code = 0;
349 spin_unlock_irq(&se_nacl->nacl_sess_lock);
350
351
352
353
354
355 padding = ((-len) & 3);
356 if (padding != 0)
357 len += padding;
358
359
360
361
362 len += 4;
363
364 return len;
365}
366EXPORT_SYMBOL(iscsi_get_pr_transport_id_len);
367
368char *iscsi_parse_pr_out_transport_id(
369 struct se_portal_group *se_tpg,
370 const char *buf,
371 u32 *out_tid_len,
372 char **port_nexus_ptr)
373{
374 char *p;
375 u32 tid_len, padding;
376 int i;
377 u16 add_len;
378 u8 format_code = (buf[0] & 0xc0);
379
380
381
382
383
384
385
386
387
388
389
390
391
392 if ((format_code != 0x00) && (format_code != 0x40)) {
393 pr_err("Illegal format code: 0x%02x for iSCSI"
394 " Initiator Transport ID\n", format_code);
395 return NULL;
396 }
397
398
399
400
401 if (out_tid_len != NULL) {
402 add_len = ((buf[2] >> 8) & 0xff);
403 add_len |= (buf[3] & 0xff);
404
405 tid_len = strlen((char *)&buf[4]);
406 tid_len += 4;
407 tid_len += 1;
408 padding = ((-tid_len) & 3);
409 if (padding != 0)
410 tid_len += padding;
411
412 if ((add_len + 4) != tid_len) {
413 pr_debug("LIO-Target Extracted add_len: %hu "
414 "does not match calculated tid_len: %u,"
415 " using tid_len instead\n", add_len+4, tid_len);
416 *out_tid_len = tid_len;
417 } else
418 *out_tid_len = (add_len + 4);
419 }
420
421
422
423
424
425 if (format_code == 0x40) {
426 p = strstr((char *)&buf[4], ",i,0x");
427 if (!p) {
428 pr_err("Unable to locate \",i,0x\" seperator"
429 " for Initiator port identifier: %s\n",
430 (char *)&buf[4]);
431 return NULL;
432 }
433 *p = '\0';
434 p += 5;
435
436 *port_nexus_ptr = p;
437
438
439
440
441
442
443 for (i = 0; i < 12; i++) {
444 if (isdigit(*p)) {
445 p++;
446 continue;
447 }
448 *p = tolower(*p);
449 p++;
450 }
451 }
452
453 return (char *)&buf[4];
454}
455EXPORT_SYMBOL(iscsi_parse_pr_out_transport_id);
456