target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID
@ 2021-04-20 18:59 Sergey Samoylenko
  2021-04-20 18:59 ` [PATCH RESEND 1/2] scsi: target: core: Unify NAA identifer generation Sergey Samoylenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-04-20 18:59 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: David Disseldorp, linux-scsi, linux, Sergey Samoylenko

The series allows to change IEEE Company ID component
of NAA LUN identifier returned on the SCSI INQUIRY VPD
page (aka WWID). Company ID can be changed via the
target/core/$backstore/$name/wwn/company_id ConfigFS path.

Sergey Samoylenko (2):
  scsi: target: core: Unify NAA identifer generation
  scsi: target: core: Add IEEE Company ID attribute

 drivers/target/target_core_configfs.c | 50 +++++++++++++++++++++++++++
 drivers/target/target_core_device.c   |  5 +++
 drivers/target/target_core_pr.h       |  2 +-
 drivers/target/target_core_spc.c      | 47 ++++++++++++-------------
 drivers/target/target_core_xcopy.c    | 17 ++-------
 include/target/target_core_base.h     |  1 +
 6 files changed, 82 insertions(+), 40 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH RESEND 1/2] scsi: target: core: Unify NAA identifer generation
  2021-04-20 18:59 [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Sergey Samoylenko
@ 2021-04-20 18:59 ` Sergey Samoylenko
  2021-04-20 18:59 ` [PATCH RESEND 2/2] scsi: target: core: Add IEEE Company ID attribute Sergey Samoylenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-04-20 18:59 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: David Disseldorp, linux-scsi, linux, Sergey Samoylenko, Roman Bolshakov

INQUIRY and XCOPY commands contain duplicate code paths with hardcoded
OpenFabrics Company ID for NAA designator.

Also, the two existing functions are somewhat poorly named:

 - spc_parse_naa_6h_vendor_specific()
 - target_xcopy_gen_naa_ieee()

The replacement function combines the names and hopefully better
reflects its meaning of *producing* NAA 6 designator:

 - spc_gen_naa_6h_vendor_specific()

Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/target/target_core_pr.h    |  2 +-
 drivers/target/target_core_spc.c   | 47 +++++++++++++++---------------
 drivers/target/target_core_xcopy.c | 17 ++---------
 3 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/drivers/target/target_core_pr.h b/drivers/target/target_core_pr.h
index a31c93e4e19c..b793c99637ab 100644
--- a/drivers/target/target_core_pr.h
+++ b/drivers/target/target_core_pr.h
@@ -52,7 +52,7 @@
 /*
  *  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;
 
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 70a661801cb9..b2d19493a994 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -129,13 +129,28 @@ spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf)
 	return 0;
 }
 
-void spc_parse_naa_6h_vendor_specific(struct se_device *dev,
-				      unsigned char *buf)
+/*
+ * Generate NAA IEEE Registered Extended designator
+ */
+void spc_gen_naa_6h_vendor_specific(struct se_device *dev,
+				    unsigned char *buf)
 {
 	unsigned char *p = &dev->t10_wwn.unit_serial[0];
-	int cnt;
+	int cnt, off = 0;
 	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
 	 * 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,
 	 * NUMBER set via vpd_unit_serial in target_core_configfs.c to ensure
 	 * per device uniqeness.
 	 */
-	for (cnt = 0; *p && cnt < 13; p++) {
+	for (cnt = off + 13; *p && off < cnt; p++) {
 		int val = hex_to_bin(*p);
 
 		if (val < 0)
@@ -152,10 +167,10 @@ void spc_parse_naa_6h_vendor_specific(struct se_device *dev,
 
 		if (next) {
 			next = false;
-			buf[cnt++] |= val;
+			buf[off++] |= val;
 		} else {
 			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)
 	/* Identifier/Designator length */
 	buf[off++] = 0x10;
 
-	/*
-	 * 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);
-
-	/*
-	 * Return ConfigFS Unit Serial Number information for
-	 * VENDOR_SPECIFIC_IDENTIFIER and
-	 * VENDOR_SPECIFIC_IDENTIFIER_EXTENTION
-	 */
-	spc_parse_naa_6h_vendor_specific(dev, &buf[off]);
+	/* NAA IEEE Registered Extended designator */
+	spc_gen_naa_6h_vendor_specific(dev, &buf[off]);
 
 	len = 20;
 	off = (len + 4);
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index d31ed071cb08..2e7ce661ef32 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -33,19 +33,6 @@ static struct workqueue_struct *xcopy_wq = NULL;
 
 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
  *
@@ -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);
-	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);
 	if (rc != 0) {
@@ -241,7 +228,7 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
 	 * se_device the XCOPY was received upon..
 	 */
 	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) {
 		/*
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH RESEND 2/2] scsi: target: core: Add IEEE Company ID attribute
  2021-04-20 18:59 [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Sergey Samoylenko
  2021-04-20 18:59 ` [PATCH RESEND 1/2] scsi: target: core: Unify NAA identifer generation Sergey Samoylenko
@ 2021-04-20 18:59 ` Sergey Samoylenko
  2021-05-15 18:14 ` [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Martin K. Petersen
  2021-05-22  4:41 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-04-20 18:59 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: David Disseldorp, linux-scsi, linux, Sergey Samoylenko, Roman Bolshakov

The attribute provides a way to set a company specific WWN
in configfs via:

  target/core/$backstore/$name/wwn/company_id

001405h remains default value for company id.

Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/target/target_core_configfs.c | 50 +++++++++++++++++++++++++++
 drivers/target/target_core_device.c   |  5 +++
 drivers/target/target_core_spc.c      | 14 ++++----
 include/target/target_core_base.h     |  1 +
 4 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 4b2e49341ad6..d6fd2779355a 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -1479,6 +1479,54 @@ static ssize_t target_wwn_revision_store(struct config_item *item,
 	return count;
 }
 
+static ssize_t
+target_wwn_company_id_show(struct config_item *item,
+				char *page)
+{
+	return snprintf(page, PAGE_SIZE, "%#08x\n",
+			to_t10_wwn(item)->company_id);
+}
+
+static ssize_t
+target_wwn_company_id_store(struct config_item *item,
+				 const char *page, size_t count)
+{
+	struct t10_wwn *t10_wwn = to_t10_wwn(item);
+	struct se_device *dev = t10_wwn->t10_dev;
+	u32 val;
+	int ret;
+
+	/*
+	 * The IEEE COMPANY_ID field should contain a 24-bit canonical
+	 * form OUI assigned by the IEEE.
+	 */
+	ret = kstrtou32(page, 0, &val);
+	if (ret < 0)
+		return ret;
+
+	if (val >= 0x1000000)
+		return -EOVERFLOW;
+
+	/*
+	 * Check to see if any active exports exist. If they do exist, fail
+	 * here as changing this information on the fly (underneath the
+	 * initiator side OS dependent multipath code) could cause negative
+	 * effects.
+	 */
+	if (dev->export_count) {
+		pr_err("Unable to set Company ID while %d exports exist\n",
+		       dev->export_count);
+		return -EINVAL;
+	}
+
+	t10_wwn->company_id = val;
+
+	pr_debug("Target_Core_ConfigFS: Set IEEE Company ID: %#08x\n",
+		 t10_wwn->company_id);
+
+	return count;
+}
+
 /*
  * VPD page 0x80 Unit serial
  */
@@ -1625,6 +1673,7 @@ DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20);
 CONFIGFS_ATTR(target_wwn_, vendor_id);
 CONFIGFS_ATTR(target_wwn_, product_id);
 CONFIGFS_ATTR(target_wwn_, revision);
+CONFIGFS_ATTR(target_wwn_, company_id);
 CONFIGFS_ATTR(target_wwn_, vpd_unit_serial);
 CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier);
 CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit);
@@ -1635,6 +1684,7 @@ static struct configfs_attribute *target_core_dev_wwn_attrs[] = {
 	&target_wwn_attr_vendor_id,
 	&target_wwn_attr_product_id,
 	&target_wwn_attr_revision,
+	&target_wwn_attr_company_id,
 	&target_wwn_attr_vpd_unit_serial,
 	&target_wwn_attr_vpd_protocol_identifier,
 	&target_wwn_attr_vpd_assoc_logical_unit,
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index a8df9f0a82fa..8cb1fa0c0585 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -773,6 +773,11 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
 	spin_lock_init(&dev->t10_alua.lba_map_lock);
 
 	dev->t10_wwn.t10_dev = dev;
+	/*
+	 * Use OpenFabrics IEEE Company ID: 00 14 05
+	 */
+	dev->t10_wwn.company_id = 0x001405;
+
 	dev->t10_alua.t10_dev = dev;
 
 	dev->dev_attrib.da_dev = dev;
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index b2d19493a994..fe5d5ce4099c 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -136,20 +136,20 @@ void spc_gen_naa_6h_vendor_specific(struct se_device *dev,
 				    unsigned char *buf)
 {
 	unsigned char *p = &dev->t10_wwn.unit_serial[0];
+	u32 company_id = dev->t10_wwn.company_id;
 	int cnt, off = 0;
 	bool next = true;
 
 	/*
 	 * Start NAA IEEE Registered Extended Identifier/Designator
 	 */
-	buf[off++] = 0x6 << 4;
+	buf[off] = 0x6 << 4;
 
-	/*
-	 * Use OpenFabrics IEEE Company ID: 00 14 05
-	 */
-	buf[off++] = 0x01;
-	buf[off++] = 0x40;
-	buf[off] = (0x5 << 4);
+	/* IEEE COMPANY_ID */
+	buf[off++] |= (company_id >> 20) & 0xf;
+	buf[off++] = (company_id >> 12) & 0xff;
+	buf[off++] = (company_id >> 4) & 0xff;
+	buf[off] = (company_id & 0xf) << 4;
 
 	/*
 	 * Generate up to 36 bits of VENDOR SPECIFIC IDENTIFIER starting on
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index d1f7d2a45354..85c16c266eac 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -326,6 +326,7 @@ struct t10_wwn {
 	char model[INQUIRY_MODEL_LEN + 1];
 	char revision[INQUIRY_REVISION_LEN + 1];
 	char unit_serial[INQUIRY_VPD_SERIAL_LEN];
+	u32 company_id;
 	spinlock_t t10_vpd_lock;
 	struct se_device *t10_dev;
 	struct config_group t10_wwn_group;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID
  2021-04-20 18:59 [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Sergey Samoylenko
  2021-04-20 18:59 ` [PATCH RESEND 1/2] scsi: target: core: Unify NAA identifer generation Sergey Samoylenko
  2021-04-20 18:59 ` [PATCH RESEND 2/2] scsi: target: core: Add IEEE Company ID attribute Sergey Samoylenko
@ 2021-05-15 18:14 ` Martin K. Petersen
  2021-05-22  4:41 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-05-15 18:14 UTC (permalink / raw)
  To: Sergey Samoylenko
  Cc: Martin Petersen, Mike Christie, target-devel, David Disseldorp,
	linux-scsi, linux


Sergey,

> The series allows to change IEEE Company ID component of NAA LUN
> identifier returned on the SCSI INQUIRY VPD page (aka WWID). Company
> ID can be changed via the target/core/$backstore/$name/wwn/company_id
> ConfigFS path.

Applied to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID
  2021-04-20 18:59 [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Sergey Samoylenko
                   ` (2 preceding siblings ...)
  2021-05-15 18:14 ` [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Martin K. Petersen
@ 2021-05-22  4:41 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-05-22  4:41 UTC (permalink / raw)
  To: Mike Christie, Sergey Samoylenko, target-devel
  Cc: Martin K . Petersen, David Disseldorp, linux-scsi, linux

On Tue, 20 Apr 2021 21:59:18 +0300, Sergey Samoylenko wrote:

> The series allows to change IEEE Company ID component
> of NAA LUN identifier returned on the SCSI INQUIRY VPD
> page (aka WWID). Company ID can be changed via the
> target/core/$backstore/$name/wwn/company_id ConfigFS path.
> 
> Sergey Samoylenko (2):
>   scsi: target: core: Unify NAA identifer generation
>   scsi: target: core: Add IEEE Company ID attribute
> 
> [...]

Applied to 5.14/scsi-queue, thanks!

[1/2] scsi: target: core: Unify NAA identifer generation
      https://git.kernel.org/mkp/scsi/c/17f947b8b06f
[2/2] scsi: target: core: Add IEEE Company ID attribute
      https://git.kernel.org/mkp/scsi/c/2469f1e0412c

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-22  4:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 18:59 [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Sergey Samoylenko
2021-04-20 18:59 ` [PATCH RESEND 1/2] scsi: target: core: Unify NAA identifer generation Sergey Samoylenko
2021-04-20 18:59 ` [PATCH RESEND 2/2] scsi: target: core: Add IEEE Company ID attribute Sergey Samoylenko
2021-05-15 18:14 ` [PATCH RESEND 0/2] scsi: target: user configurable IEEE Company ID Martin K. Petersen
2021-05-22  4:41 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).