All of lore.kernel.org
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH 1/5] nvmet: EUI64 support
Date: Fri,  4 May 2018 13:28:41 +0200	[thread overview]
Message-ID: <20180504112845.38820-2-hare@suse.de> (raw)
In-Reply-To: <20180504112845.38820-1-hare@suse.de>

Allow the setting of an IEEE Extended Unique Identifier (EUI64) for
each namespace. As the OUI is per subsystem ensure that the OUI
part of the EUI64 value (ie the top 3 bytes) are matching for each
namespace.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/target/admin-cmd.c |  6 ++---
 drivers/nvme/target/configfs.c  | 58 +++++++++++++++++++++++++++++++++++++++++
 drivers/nvme/target/nvmet.h     |  2 ++
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 5e0e9fcc0d4d..a53259e1082e 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -187,10 +187,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
 
 	id->rab = 6;
 
-	/*
-	 * XXX: figure out how we can assign a IEEE OUI, but until then
-	 * the safest is to leave it as zeroes.
-	 */
+	memcpy(id->ieee, &ctrl->subsys->oui, 3);
 
 	/* we support multiple ports and multiples hosts: */
 	id->cmic = (1 << 0) | (1 << 1);
@@ -314,6 +311,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
 	id->nmic = (1 << 0);
 
 	memcpy(&id->nguid, &ns->nguid, sizeof(uuid_le));
+	memcpy(&id->eui64, &ns->eui64, sizeof(id->eui64));
 
 	id->lbaf[0].ds = ns->blksize_shift;
 
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index ad9ff27234b5..3dc2b2ae56e5 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -378,6 +378,49 @@ static ssize_t nvmet_ns_device_nguid_store(struct config_item *item,
 
 CONFIGFS_ATTR(nvmet_ns_, device_nguid);
 
+static ssize_t nvmet_ns_device_eui64_show(struct config_item *item, char *page)
+{
+	return sprintf(page, "%llx\n",
+		       (unsigned long long)&to_nvmet_ns(item)->eui64);
+}
+
+static ssize_t nvmet_ns_device_eui64_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct nvmet_ns *ns = to_nvmet_ns(item), *n;
+	struct nvmet_subsys *subsys = ns->subsys;
+	u64 eui64;
+	int ret = 0;
+
+	mutex_lock(&subsys->lock);
+	if (ns->enabled) {
+		ret = -EBUSY;
+		goto out_unlock;
+	}
+
+	if (sscanf(page, "%llx\n", &eui64) != 1) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	list_for_each_entry_rcu(n, &subsys->namespaces, dev_link) {
+		if ((n->eui64 >> 40) != (eui64 >> 40)) {
+			pr_warn("non-matching EUI64 company id %06x\n",
+				(unsigned int)(eui64 >> 40));
+			ret = -EINVAL;
+			goto out_unlock;
+		}
+	}
+	ns->eui64 = eui64;
+	if (!subsys->oui)
+		subsys->oui = (eui64 >> 40);
+out_unlock:
+	mutex_unlock(&subsys->lock);
+	return ret ? ret : count;
+}
+
+CONFIGFS_ATTR(nvmet_ns_, device_eui64);
+
 static ssize_t nvmet_ns_enable_show(struct config_item *item, char *page)
 {
 	return sprintf(page, "%d\n", to_nvmet_ns(item)->enabled);
@@ -407,6 +450,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_device_path,
 	&nvmet_ns_attr_device_nguid,
 	&nvmet_ns_attr_device_uuid,
+	&nvmet_ns_attr_device_eui64,
 	&nvmet_ns_attr_enable,
 	NULL,
 };
@@ -704,10 +748,24 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
 }
 CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
 
+/*
+ * OUI is set from the namespace EUI64, so we cannot set it here.
+ */
+static ssize_t nvmet_subsys_attr_oui_show(struct config_item *item,
+					     char *page)
+{
+	struct nvmet_subsys *subsys = to_subsys(item);
+
+	return snprintf(page, PAGE_SIZE, "%06x\n", subsys->oui);
+}
+
+CONFIGFS_ATTR_RO(nvmet_subsys_, attr_oui);
+
 static struct configfs_attribute *nvmet_subsys_attrs[] = {
 	&nvmet_subsys_attr_attr_allow_any_host,
 	&nvmet_subsys_attr_attr_version,
 	&nvmet_subsys_attr_attr_serial,
+	&nvmet_subsys_attr_attr_oui,
 	NULL,
 };
 
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 15fd84ab21f8..8cd42ed37314 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -47,6 +47,7 @@ struct nvmet_ns {
 	u32			blksize_shift;
 	loff_t			size;
 	u8			nguid[16];
+	u64			eui64;
 	uuid_t			uuid;
 
 	bool			enabled;
@@ -154,6 +155,7 @@ struct nvmet_subsys {
 
 	u64			ver;
 	u64			serial;
+	u32			oui;
 	char			*subsysnqn;
 
 	struct config_group	group;
-- 
2.12.3

  reply	other threads:[~2018-05-04 11:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-04 11:28 [RFC PATCH 0/5] nvme: ANA support Hannes Reinecke
2018-05-04 11:28 ` Hannes Reinecke [this message]
2018-05-07  7:17   ` [PATCH 1/5] nvmet: EUI64 support Johannes Thumshirn
2018-05-09  7:08   ` Christoph Hellwig
2018-05-09  7:45     ` Hannes Reinecke
2018-05-09  7:52       ` Christoph Hellwig
2018-05-09 15:43   ` Ewan D. Milne
2018-05-04 11:28 ` [PATCH 2/5] nvme: Add ANA base definitions Hannes Reinecke
2018-05-04 16:17   ` Keith Busch
2018-05-04 17:03     ` Meneghini, John
2018-05-04 17:21       ` Knight, Frederick
2018-05-05 13:17       ` Hannes Reinecke
2018-05-04 21:12   ` Schremmer, Steven
2018-05-09  7:27   ` Christoph Hellwig
2018-05-04 11:28 ` [PATCH 3/5] nvmet: Add ANA base support Hannes Reinecke
2018-05-06  2:42   ` Guan Junxiong
2018-05-04 11:28 ` [PATCH 4/5] block: BLK_STS_NEXUS is a path failure Hannes Reinecke
2018-05-09  7:31   ` Christoph Hellwig
2018-05-04 11:28 ` [PATCH 5/5] nvme: ANA base support Hannes Reinecke
2018-05-04 22:11   ` Schremmer, Steven
2018-05-05 13:23     ` Hannes Reinecke
2018-05-06  3:23   ` Guan Junxiong
2018-05-07  7:21   ` Johannes Thumshirn
2018-05-09 18:49   ` Ewan D. Milne
2018-05-09 19:03   ` Ewan D. Milne
2018-05-10  9:16     ` Sriram Popuri
     [not found]     ` <CAGYjvj0Mk0MFAfUEApOOyQ9Prm3CvGcZH14PJzDQT2+Qc+w81w@mail.gmail.com>
2018-05-10 13:40       ` Hannes Reinecke
2018-05-11  7:50       ` Hannes Reinecke
2018-05-11  8:22         ` Popuri, Sriram
2018-05-11  8:36           ` Popuri, Sriram
2018-05-11 16:24             ` Knight, Frederick
2018-05-12 13:31   ` Christoph Hellwig
2018-05-13 10:33     ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180504112845.38820-2-hare@suse.de \
    --to=hare@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.