Commit 17f947b8 authored by Sergey Samoylenko's avatar Sergey Samoylenko Committed by Martin K. Petersen

scsi: target: core: Unify NAA identifier generation

Both the INQUIRY handling and the XCOPY implementation provide functions to
generate an NAA designator. In addition, these functions are poorly named:

 - spc_parse_naa_6h_vendor_specific()
 - target_xcopy_gen_naa_ieee()

Introduce a common NAA 6 designator generation function,
spc_gen_naa_6h_vendor_specific().

Link: https://lore.kernel.org/r/20210420185920.42431-2-s.samoylenko@yadro.comSigned-off-by: default avatarSergey Samoylenko <s.samoylenko@yadro.com>
Signed-off-by: default avatarRoman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent f8a78e91
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
/* /*
* Function defined in target_core_spc.c * Function defined in target_core_spc.c
*/ */
void spc_parse_naa_6h_vendor_specific(struct se_device *, unsigned char *); void spc_gen_naa_6h_vendor_specific(struct se_device *, unsigned char *);
extern struct kmem_cache *t10_pr_reg_cache; extern struct kmem_cache *t10_pr_reg_cache;
......
...@@ -129,13 +129,28 @@ spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf) ...@@ -129,13 +129,28 @@ spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf)
return 0; return 0;
} }
void spc_parse_naa_6h_vendor_specific(struct se_device *dev, /*
* Generate NAA IEEE Registered Extended designator
*/
void spc_gen_naa_6h_vendor_specific(struct se_device *dev,
unsigned char *buf) unsigned char *buf)
{ {
unsigned char *p = &dev->t10_wwn.unit_serial[0]; unsigned char *p = &dev->t10_wwn.unit_serial[0];
int cnt; int cnt, off = 0;
bool next = true; bool next = true;
/*
* Start NAA IEEE Registered Extended Identifier/Designator
*/
buf[off++] = 0x6 << 4;
/*
* Use OpenFabrics IEEE Company ID: 00 14 05
*/
buf[off++] = 0x01;
buf[off++] = 0x40;
buf[off] = (0x5 << 4);
/* /*
* Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on * Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on
* byte 3 bit 3-0 for NAA IEEE Registered Extended DESIGNATOR field * byte 3 bit 3-0 for NAA IEEE Registered Extended DESIGNATOR field
...@@ -144,7 +159,7 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev, ...@@ -144,7 +159,7 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev,
* NUMBER set via vpd_unit_serial in target_core_configfs.c to ensure * NUMBER set via vpd_unit_serial in target_core_configfs.c to ensure
* per device uniqeness. * per device uniqeness.
*/ */
for (cnt = 0; *p && cnt < 13; p++) { for (cnt = off + 13; *p && off < cnt; p++) {
int val = hex_to_bin(*p); int val = hex_to_bin(*p);
if (val < 0) if (val < 0)
...@@ -152,10 +167,10 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev, ...@@ -152,10 +167,10 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev,
if (next) { if (next) {
next = false; next = false;
buf[cnt++] |= val; buf[off++] |= val;
} else { } else {
next = true; next = true;
buf[cnt] = val << 4; buf[off] = val << 4;
} }
} }
} }
...@@ -203,24 +218,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) ...@@ -203,24 +218,8 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf)
/* Identifier/Designator length */ /* Identifier/Designator length */
buf[off++] = 0x10; buf[off++] = 0x10;
/* /* NAA IEEE Registered Extended designator */
* Start NAA IEEE Registered Extended Identifier/Designator spc_gen_naa_6h_vendor_specific(dev, &buf[off]);
*/
buf[off++] = (0x6 << 4);
/*
* Use OpenFabrics IEEE Company ID: 00 14 05
*/
buf[off++] = 0x01;
buf[off++] = 0x40;
buf[off] = (0x5 << 4);
/*
* Return ConfigFS Unit Serial Number information for
* VENDOR_SPECIFIC_IDENTIFIER and
* VENDOR_SPECIFIC_IDENTIFIER_EXTENTION
*/
spc_parse_naa_6h_vendor_specific(dev, &buf[off]);
len = 20; len = 20;
off = (len + 4); off = (len + 4);
......
...@@ -33,19 +33,6 @@ static struct workqueue_struct *xcopy_wq = NULL; ...@@ -33,19 +33,6 @@ static struct workqueue_struct *xcopy_wq = NULL;
static sense_reason_t target_parse_xcopy_cmd(struct xcopy_op *xop); static sense_reason_t target_parse_xcopy_cmd(struct xcopy_op *xop);
static int target_xcopy_gen_naa_ieee(struct se_device *dev, unsigned char *buf)
{
int off = 0;
buf[off++] = (0x6 << 4);
buf[off++] = 0x01;
buf[off++] = 0x40;
buf[off] = (0x5 << 4);
spc_parse_naa_6h_vendor_specific(dev, &buf[off]);
return 0;
}
/** /**
* target_xcopy_locate_se_dev_e4_iter - compare XCOPY NAA device identifiers * target_xcopy_locate_se_dev_e4_iter - compare XCOPY NAA device identifiers
* *
...@@ -65,7 +52,7 @@ static int target_xcopy_locate_se_dev_e4_iter(struct se_device *se_dev, ...@@ -65,7 +52,7 @@ static int target_xcopy_locate_se_dev_e4_iter(struct se_device *se_dev,
} }
memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN);
target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]); spc_gen_naa_6h_vendor_specific(se_dev, &tmp_dev_wwn[0]);
rc = memcmp(&tmp_dev_wwn[0], dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN); rc = memcmp(&tmp_dev_wwn[0], dev_wwn, XCOPY_NAA_IEEE_REGEX_LEN);
if (rc != 0) { if (rc != 0) {
...@@ -241,7 +228,7 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd, ...@@ -241,7 +228,7 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
* se_device the XCOPY was received upon.. * se_device the XCOPY was received upon..
*/ */
memset(&xop->local_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); memset(&xop->local_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN);
target_xcopy_gen_naa_ieee(local_dev, &xop->local_dev_wwn[0]); spc_gen_naa_6h_vendor_specific(local_dev, &xop->local_dev_wwn[0]);
while (start < tdll) { while (start < tdll) {
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment