All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand
@ 2017-06-23  7:36 Johannes Thumshirn
  2017-06-23 16:37 ` Keith Busch
  2017-06-24  7:12 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2017-06-23  7:36 UTC (permalink / raw)


NVMe 1.3 defines the "Namespace Identification Descriptor" command in
NVMe Identify NS. This command returns a list of so called Namespace
Identificastion Descriptors which currently can either be a EUI-64,
a NGUID or a UUID.

Signed-off-by: Johannes Thumshirn <jthumshirn at suse.de>
---
 linux/nvme.h   |  14 +++++++
 nvme-builtin.h |   1 +
 nvme-ioctl.c   |   6 +++
 nvme-ioctl.h   |   1 +
 nvme-print.c   | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 nvme-print.h   |   2 +
 nvme.c         |  63 +++++++++++++++++++++++++++++
 7 files changed, 209 insertions(+)

diff --git a/linux/nvme.h b/linux/nvme.h
index b2c8dbb2244b..883b5eb8b710 100644
--- a/linux/nvme.h
+++ b/linux/nvme.h
@@ -862,6 +862,20 @@ struct nvme_command {
 	};
 };
 
+#define NVME_IDENTIFY_CMD_LEN 4096
+#define NVME_ID_CNS_NS_DESC_LIST 0x3
+enum {
+	NVME_NIDT_EUI64		= 0x1,
+	NVME_NIDT_NGUID		= 0x2,
+	NVME_NIDT_UUID		= 0x3,
+};
+
+struct nvme_ns_id_desc {
+	__u8 nidt;
+	__u8 nidl;
+	__u16 reserved;
+};
+
 static inline bool nvme_is_write(struct nvme_command *cmd)
 {
 	/*
diff --git a/nvme-builtin.h b/nvme-builtin.h
index 087fc1986b2f..91f361df54a3 100644
--- a/nvme-builtin.h
+++ b/nvme-builtin.h
@@ -11,6 +11,7 @@ COMMAND_LIST(
 	ENTRY("id-ctrl", "Send NVMe Identify Controller", id_ctrl)
 	ENTRY("id-ns", "Send NVMe Identify Namespace, display structure", id_ns)
 	ENTRY("list-ns", "Send NVMe Identify List, display structure", list_ns)
+	ENTRY("ns-descs", "Send NVMe Namespace Descriptor List, display structure", ns_descs)
 	ENTRY("create-ns", "Creates a namespace with the provided parameters", create_ns)
 	ENTRY("delete-ns", "Deletes a namespace from the controller", delete_ns)
 	ENTRY("attach-ns", "Attaches a namespace to requested controller(s)", attach_ns)
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index a22399ab6169..e3e9af412168 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -364,6 +364,12 @@ int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data)
 	return nvme_identify(fd, nsid, (cntid << 16) | cns, data);
 }
 
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
+{
+
+	return nvme_identify(fd, nsid, NVME_ID_CNS_CTRL_LIST, data);
+}
+
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data)
 {
 	struct nvme_admin_cmd cmd = {
diff --git a/nvme-ioctl.h b/nvme-ioctl.h
index 3beddf8e2db2..8faf345dcf37 100644
--- a/nvme-ioctl.h
+++ b/nvme-ioctl.h
@@ -77,6 +77,7 @@ int nvme_identify_ctrl(int fd, void *data);
 int nvme_identify_ns(int fd, __u32 nsid, bool present, void *data);
 int nvme_identify_ns_list(int fd, __u32 nsid, bool all, void *data);
 int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data);
+int nvme_identify_ns_descs(int fd, __u32 nsid, void *data);
 
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data);
 int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log);
diff --git a/nvme-print.c b/nvme-print.c
index 2da5acd5c9b8..f0f7121cb070 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -3,6 +3,10 @@
 #include <string.h>
 #include <stdlib.h>
 
+#ifdef LIBUUID
+#include <uuid/uuid.h>
+#endif
+
 #include "nvme-print.h"
 #include "json.h"
 #include "nvme-models.h"
@@ -599,6 +603,124 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
 	}
 }
 
+void json_nvme_id_ns_descs(void *data)
+{
+#ifdef LIBUUID
+	uuid_t uuid;
+	char uuid_str[37];
+#endif
+	__u8 eui64_desc[8];
+	__u8 nguid_desc[16];
+	char nguid_str[2 * sizeof(nguid_desc) + 1];
+	char eui64_str[2 * sizeof(eui64_desc) + 1];
+	char *eui64 = eui64_str;
+	char *nguid = nguid_str;
+	struct json_object *root;
+	off_t off;
+	int pos, len = 0;
+	int i;
+
+	root = json_create_object();
+
+	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+		struct nvme_ns_id_desc *cur = data + pos;
+
+		off = pos + sizeof(*cur);
+
+		if (cur->nidl == 0)
+			break;
+
+		switch (cur->nidt) {
+		case NVME_NIDT_EUI64:
+			memset(eui64, 0, sizeof(eui64_str));
+			memcpy(eui64_desc, data + off, sizeof(eui64_desc));
+			for (i = 0; i < sizeof(eui64); i++)
+				eui64 += sprintf(eui64, "%02x", eui64_desc[i]);
+			len += sizeof(eui64);
+			json_object_add_value_string(root, "eui64", eui64_str);
+			break;
+		case NVME_NIDT_NGUID:
+			memset(nguid, 0, sizeof(nguid_str));
+			memcpy(nguid_desc, data + off, sizeof(nguid_desc));
+			for (i = 0; i < sizeof(nguid); i++)
+				nguid += sprintf(nguid, "%02x", nguid_desc[i]);
+			len += sizeof(nguid);
+			json_object_add_value_string(root, "nguid", nguid_str);
+			break;
+#ifdef LIBUUID
+		case NVME_NIDT_UUID:
+			memcpy(uuid, data + off, 16);
+			uuid_unparse_lower(uuid, uuid_str);
+			len += sizeof(uuid);
+			json_object_add_value_string(root, "uuid", uuid_str);
+			break;
+#endif
+		default:
+			/* Skip unnkown types */
+			len = cur->nidl;
+			break;
+		}
+
+		len += sizeof(*cur);
+	}
+
+	json_print_object(root, NULL);
+	printf("\n");
+	json_free_object(root);
+}
+
+void show_nvme_id_ns_descs(void *data)
+{
+	int pos, len = 0;
+	int i;
+#ifdef LIBUUID
+	uuid_t uuid;
+	char uuid_str[37];
+#endif
+	__u8 eui64[8];
+	__u8 nguid[16];
+
+	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+		struct nvme_ns_id_desc *cur = data + pos;
+
+		if (cur->nidl == 0)
+			break;
+
+		switch (cur->nidt) {
+		case NVME_NIDT_EUI64:
+			memcpy(eui64, data + pos + sizeof(*cur), sizeof(eui64));
+			printf("eui64   : ");
+			for (i = 0; i < 8; i++)
+				printf("%02x", eui64[i]);
+			printf("\n");
+			len += sizeof(eui64);
+			break;
+		case NVME_NIDT_NGUID:
+			memcpy(nguid, data + pos + sizeof(*cur), sizeof(nguid));
+			printf("nguid   : ");
+			for (i = 0; i < 16; i++)
+				printf("%02x", nguid[i]);
+			printf("\n");
+			len += sizeof(nguid);
+			break;
+#ifdef LIBUUID
+		case NVME_NIDT_UUID:
+			memcpy(uuid, data + pos + sizeof(*cur), 16);
+			uuid_unparse_lower(uuid, uuid_str);
+			printf("uuid    : %s\n", uuid_str);
+			len += sizeof(uuid);
+			break;
+#endif
+		default:
+			/* Skip unnkown types */
+			len = cur->nidl;
+			break;
+		}
+
+		len += sizeof(*cur);
+	}
+}
+
 static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
 {
 	__u16 power = le16_to_cpu(ctr_power);
diff --git a/nvme-print.h b/nvme-print.h
index 0502d0d48ee4..d39bc63dc665 100644
--- a/nvme-print.h
+++ b/nvme-print.h
@@ -26,6 +26,7 @@ void show_error_log(struct nvme_error_log_page *err_log, int entries, const char
 void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
 void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
 void show_ctrl_registers(void *bar, unsigned int mode);
+void show_nvme_id_ns_descs(void *data);
 
 void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf);
 char *nvme_status_to_string(__u32 status);
@@ -39,6 +40,7 @@ void json_error_log(struct nvme_error_log_page *err_log, int entries, const char
 void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
 void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
 void json_print_list_items(struct list_item *items, unsigned amnt);
+void json_nvme_id_ns_descs(void *data);
 
 
 #endif
diff --git a/nvme.c b/nvme.c
index a4e1b719718d..a2d6e7d19551 100644
--- a/nvme.c
+++ b/nvme.c
@@ -952,6 +952,69 @@ static int id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *pl
 	return __id_ctrl(argc, argv, cmd, plugin, NULL);
 }
 
+static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+	const char *desc = "Send Namespace Identification Descriptoprs commadn to the "\
+			    "given device, returns the namespace identifcation descriptors "\
+			    "of the specific namespace in either human-readable or binary format.";
+	const char *raw_binary = "show infos in binary format";
+	const char *namespace_id = "identifier of desired namespace";
+	int err, fmt, fd;
+	char *nsdescs[0x1000] = { };
+	struct config {
+		__u32 namespace_id;
+		int raw_binary;
+		char *output_format;
+	};
+
+	struct config cfg = {
+		.namespace_id = 0,
+		.output_format = "normal",
+	};
+
+	const struct argconfig_commandline_options command_line_options[] = {
+		{"namespace-id",    'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id},
+		{"raw-binary",      'b', "",    CFG_NONE,     &cfg.raw_binary,      no_argument,       raw_binary},
+		{"output-format",   'o', "FMT", CFG_STRING,   &cfg.output_format,   required_argument, output_format },
+		{NULL}
+	};
+
+	if (posix_memalign((void *)&nsdescs, getpagesize(), 0x1000)) {
+		fprintf(stderr, "can not allocate controller list payload\n");
+		return ENOMEM;
+	}
+
+	fd = parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg));
+	if (fd < 0)
+		return fd;
+
+	fmt = validate_output_format(cfg.output_format);
+	if (fmt < 0)
+		return fmt;
+	if (cfg.raw_binary)
+		fmt = BINARY;
+	if (!cfg.namespace_id)
+		cfg.namespace_id = get_nsid(fd);
+
+	err = nvme_identify_ns_descs(fd, cfg.namespace_id, &nsdescs);
+	if (!err) {
+		if (fmt == BINARY)
+			d_raw((unsigned char *)&nsdescs, 0x1000);
+		else if (fmt == JSON)
+			json_nvme_id_ns_descs(&nsdescs);
+		else {
+			printf("NVME Namespace Identification Descriptors NS %d:\n", cfg.namespace_id);
+			show_nvme_id_ns_descs(&nsdescs);
+		}
+	}
+	else if (err > 0)
+		fprintf(stderr, "NVMe Status:%s(%x) NSID:%d\n",
+			nvme_status_to_string(err), err, cfg.namespace_id);
+	else
+		perror("identify namespace");
+	return err;
+}
+
 static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
 	const char *desc = "Send an Identify Namespace command to the "\
-- 
2.12.3

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

* [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand
  2017-06-23  7:36 [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand Johannes Thumshirn
@ 2017-06-23 16:37 ` Keith Busch
  2017-06-24  7:12 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Keith Busch @ 2017-06-23 16:37 UTC (permalink / raw)


On Fri, Jun 23, 2017@09:36:35AM +0200, Johannes Thumshirn wrote:
> NVMe 1.3 defines the "Namespace Identification Descriptor" command in
> NVMe Identify NS. This command returns a list of so called Namespace
> Identificastion Descriptors which currently can either be a EUI-64,
> a NGUID or a UUID.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn at suse.de>

Thanks! Applied.

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

* [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand
  2017-06-23  7:36 [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand Johannes Thumshirn
  2017-06-23 16:37 ` Keith Busch
@ 2017-06-24  7:12 ` Christoph Hellwig
  2018-01-02 22:11   ` Jeffrey Lien
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2017-06-24  7:12 UTC (permalink / raw)


Meh, this still didn't properly resync nvme.h.

Something like this is needed for the current tree:

---
>From 79afec638c7a0eb636065403615a78db64ecaec7 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Sat, 24 Jun 2017 09:04:48 +0200
Subject: resync nvme.h with the kernel

Copy over the current nvme.h from the for-4.13 block tree, and adjust
a few callers.  The biggest tweak is that we can't use the kernel uuid.h
and either need to use libuuid or our own definition.

Signed-off-by: Christoph Hellwig <hch at lst.de>
---
 fabrics.c    |   2 +
 linux/nvme.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 nvme-print.c |   8 +---
 nvme.c       |   4 --
 nvme.h       |  19 ++++----
 5 files changed, 129 insertions(+), 44 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index 87cdba2..da4e04e 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -44,6 +44,8 @@
 
 #include "common.h"
 
+#define NVMF_HOSTID_SIZE	36
+
 static struct config {
 	char *nqn;
 	char *transport;
diff --git a/linux/nvme.h b/linux/nvme.h
index d1a322b..291587a 100644
--- a/linux/nvme.h
+++ b/linux/nvme.h
@@ -16,6 +16,7 @@
 #define _LINUX_NVME_H
 
 #include <linux/types.h>
+#include <linux/uuid.h>
 
 /* NQN names in commands fields specified one size */
 #define NVMF_NQN_FIELD_LEN	256
@@ -23,7 +24,6 @@
 /* However the max length of a qualified name is another size */
 #define NVMF_NQN_SIZE		223
 
-#define NVMF_HOSTID_SIZE        36
 #define NVMF_TRSVCID_SIZE	32
 #define NVMF_TRADDR_SIZE	256
 #define NVMF_TSAS_SIZE		256
@@ -102,6 +102,7 @@ enum {
 	NVME_REG_ACQ	= 0x0030,	/* Admin CQ Base Address */
 	NVME_REG_CMBLOC = 0x0038,	/* Controller Memory Buffer Location */
 	NVME_REG_CMBSZ	= 0x003c,	/* Controller Memory Buffer Size */
+	NVME_REG_DBS	= 0x1000,	/* SQ 0 Tail Doorbell */
 };
 
 #define NVME_CAP_MQES(cap)	((cap) & 0xffff)
@@ -249,7 +250,10 @@ enum {
 	NVME_CTRL_ONCS_COMPARE			= 1 << 0,
 	NVME_CTRL_ONCS_WRITE_UNCORRECTABLE	= 1 << 1,
 	NVME_CTRL_ONCS_DSM			= 1 << 2,
+	NVME_CTRL_ONCS_WRITE_ZEROES		= 1 << 3,
 	NVME_CTRL_VWC_PRESENT			= 1 << 0,
+	NVME_CTRL_OACS_SEC_SUPP                 = 1 << 0,
+	NVME_CTRL_OACS_DBBUF_SUPP		= 1 << 7,
 };
 
 struct nvme_lbaf {
@@ -289,6 +293,17 @@ struct nvme_id_ns {
 };
 
 enum {
+	NVME_ID_CNS_NS			= 0x00,
+	NVME_ID_CNS_CTRL		= 0x01,
+	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
+	NVME_ID_CNS_NS_DESC_LIST	= 0x03,
+	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
+	NVME_ID_CNS_NS_PRESENT		= 0x11,
+	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
+	NVME_ID_CNS_CTRL_LIST		= 0x13,
+};
+
+enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_META_EXT	= 0x10,
@@ -308,6 +323,22 @@ enum {
 	NVME_NS_DPS_PI_TYPE3	= 3,
 };
 
+struct nvme_ns_id_desc {
+	__u8 nidt;
+	__u8 nidl;
+	__le16 reserved;
+};
+
+#define NVME_NIDT_EUI64_LEN	8
+#define NVME_NIDT_NGUID_LEN	16
+#define NVME_NIDT_UUID_LEN	16
+
+enum {
+	NVME_NIDT_EUI64		= 0x01,
+	NVME_NIDT_NGUID		= 0x02,
+	NVME_NIDT_UUID		= 0x03,
+};
+
 struct nvme_smart_log {
 	__u8			critical_warning;
 	__u8			temperature[2];
@@ -549,12 +580,42 @@ enum {
 	NVME_DSMGMT_AD		= 1 << 2,
 };
 
+#define NVME_DSM_MAX_RANGES	256
+
 struct nvme_dsm_range {
 	__le32			cattr;
 	__le32			nlb;
 	__le64			slba;
 };
 
+struct nvme_write_zeroes_cmd {
+	__u8			opcode;
+	__u8			flags;
+	__u16			command_id;
+	__le32			nsid;
+	__u64			rsvd2;
+	__le64			metadata;
+	union nvme_data_ptr	dptr;
+	__le64			slba;
+	__le16			length;
+	__le16			control;
+	__le32			dsmgmt;
+	__le32			reftag;
+	__le16			apptag;
+	__le16			appmask;
+};
+
+/* Features */
+
+struct nvme_feat_auto_pst {
+	__le64 entries[32];
+};
+
+enum {
+	NVME_HOST_MEM_ENABLE	= (1 << 0),
+	NVME_HOST_MEM_RETURN	= (1 << 1),
+};
+
 /* Admin commands */
 
 enum nvme_admin_opcode {
@@ -573,6 +634,7 @@ enum nvme_admin_opcode {
 	nvme_admin_download_fw		= 0x11,
 	nvme_admin_ns_attach		= 0x15,
 	nvme_admin_keep_alive		= 0x18,
+	nvme_admin_dbbuf		= 0x7C,
 	nvme_admin_format_nvm		= 0x80,
 	nvme_admin_security_send	= 0x81,
 	nvme_admin_security_recv	= 0x82,
@@ -620,10 +682,14 @@ struct nvme_identify {
 	__le32			nsid;
 	__u64			rsvd2[2];
 	union nvme_data_ptr	dptr;
-	__le32			cns;
+	__u8			cns;
+	__u8			rsvd3;
+	__le16			ctrlid;
 	__u32			rsvd11[5];
 };
 
+#define NVME_IDENTIFY_DATA_SIZE 4096
+
 struct nvme_features {
 	__u8			opcode;
 	__u8			flags;
@@ -633,7 +699,16 @@ struct nvme_features {
 	union nvme_data_ptr	dptr;
 	__le32			fid;
 	__le32			dword11;
-	__u32			rsvd12[4];
+	__le32                  dword12;
+	__le32                  dword13;
+	__le32                  dword14;
+	__le32                  dword15;
+};
+
+struct nvme_host_mem_buf_desc {
+	__le64			addr;
+	__le32			size;
+	__u32			rsvd;
 };
 
 struct nvme_create_cq {
@@ -809,7 +884,7 @@ struct nvmf_connect_command {
 };
 
 struct nvmf_connect_data {
-	__u8		hostid[16];
+	uuid_t		hostid;
 	__le16		cntlid;
 	char		resv4[238];
 	char		subsysnqn[NVMF_NQN_FIELD_LEN];
@@ -842,6 +917,16 @@ struct nvmf_property_get_command {
 	__u8		resv4[16];
 };
 
+struct nvme_dbbuf {
+	__u8			opcode;
+	__u8			flags;
+	__u16			command_id;
+	__u32			rsvd1[5];
+	__le64			prp1;
+	__le64			prp2;
+	__u32			rsvd12[6];
+};
+
 struct nvme_command {
 	union {
 		struct nvme_common_command common;
@@ -854,29 +939,17 @@ struct nvme_command {
 		struct nvme_download_firmware dlfw;
 		struct nvme_format_cmd format;
 		struct nvme_dsm_cmd dsm;
+		struct nvme_write_zeroes_cmd write_zeroes;
 		struct nvme_abort_cmd abort;
 		struct nvme_get_log_page_command get_log_page;
 		struct nvmf_common_command fabrics;
 		struct nvmf_connect_command connect;
 		struct nvmf_property_set_command prop_set;
 		struct nvmf_property_get_command prop_get;
+		struct nvme_dbbuf dbbuf;
 	};
 };
 
-#define NVME_IDENTIFY_CMD_LEN 4096
-#define NVME_ID_CNS_NS_DESC_LIST 0x3
-enum {
-	NVME_NIDT_EUI64		= 0x1,
-	NVME_NIDT_NGUID		= 0x2,
-	NVME_NIDT_UUID		= 0x3,
-};
-
-struct nvme_ns_id_desc {
-	__u8 nidt;
-	__u8 nidl;
-	__u16 reserved;
-};
-
 static inline bool nvme_is_write(struct nvme_command *cmd)
 {
 	/*
@@ -958,6 +1031,7 @@ enum {
 	NVME_SC_BAD_ATTRIBUTES		= 0x180,
 	NVME_SC_INVALID_PI		= 0x181,
 	NVME_SC_READ_ONLY		= 0x182,
+	NVME_SC_ONCS_NOT_SUPPORTED	= 0x183,
 
 	/*
 	 * I/O Command Set Specific - Fabrics commands:
@@ -984,23 +1058,41 @@ enum {
 	NVME_SC_UNWRITTEN_BLOCK		= 0x287,
 
 	NVME_SC_DNR			= 0x4000,
+
+
+	/*
+	 * FC Transport-specific error status values for NVME commands
+	 *
+	 * Transport-specific status code values must be in the range 0xB0..0xBF
+	 */
+
+	/* Generic FC failure - catchall */
+	NVME_SC_FC_TRANSPORT_ERROR	= 0x00B0,
+
+	/* I/O failure due to FC ABTS'd */
+	NVME_SC_FC_TRANSPORT_ABORTED	= 0x00B1,
 };
 
 struct nvme_completion {
 	/*
 	 * Used by Admin and Fabrics commands to return data:
 	 */
-	union {
-		__le16	result16;
-		__le32	result;
-		__le64	result64;
-	};
+	union nvme_result {
+		__le16	u16;
+		__le32	u32;
+		__le64	u64;
+	} result;
 	__le16	sq_head;	/* how much of this queue may be reclaimed */
 	__le16	sq_id;		/* submission queue that generated this entry */
 	__u16	command_id;	/* of the command which completed */
 	__le16	status;		/* did the command fail, and if so, why? */
 };
 
-#define NVME_VS(major, minor) (((major) << 16) | ((minor) << 8))
+#define NVME_VS(major, minor, tertiary) \
+	(((major) << 16) | ((minor) << 8) | (tertiary))
+
+#define NVME_MAJOR(ver)		((ver) >> 16)
+#define NVME_MINOR(ver)		(((ver) >> 8) & 0xff)
+#define NVME_TERTIARY(ver)	((ver) & 0xff)
 
 #endif /* _LINUX_NVME_H */
diff --git a/nvme-print.c b/nvme-print.c
index dca4a19..637c695 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -3,10 +3,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "json.h"
 #include "nvme-models.h"
@@ -622,7 +618,7 @@ void json_nvme_id_ns_descs(void *data)
 
 	root = json_create_object();
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		off = pos + sizeof(*cur);
@@ -680,7 +676,7 @@ void show_nvme_id_ns_descs(void *data)
 	__u8 eui64[8];
 	__u8 nguid[16];
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		if (cur->nidl == 0)
diff --git a/nvme.c b/nvme.c
index f746b74..4cb7d63 100644
--- a/nvme.c
+++ b/nvme.c
@@ -45,10 +45,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
 #include "nvme-lightnvm.h"
diff --git a/nvme.h b/nvme.h
index 397a1a5..b796961 100644
--- a/nvme.h
+++ b/nvme.h
@@ -21,6 +21,15 @@
 #include "json.h"
 
 #define unlikely(x) x
+
+#ifdef LIBUUID
+#include <uuid/uuid.h>
+#else
+typedef struct {
+	__u8 b[16];
+} uuid_t;
+#endif
+
 #include "linux/nvme.h"
 
 struct nvme_error_log_page {
@@ -45,16 +54,6 @@ struct nvme_firmware_log_page {
 /* idle and active power scales occupy the last 2 bits of the field */
 #define POWER_SCALE(s) ((s) >> 6)
 
-enum {
-	NVME_ID_CNS_NS			= 0x00,
-	NVME_ID_CNS_CTRL		= 0x01,
-	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
-	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
-	NVME_ID_CNS_NS_PRESENT		= 0x11,
-	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
-	NVME_ID_CNS_CTRL_LIST		= 0x13,
-};
-
 struct nvme_host_mem_buffer {
 	__u32			hsize;
 	__u32			hmdlal;
-- 
2.11.0

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

* [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand
  2017-06-24  7:12 ` Christoph Hellwig
@ 2018-01-02 22:11   ` Jeffrey Lien
  0 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Lien @ 2018-01-02 22:11 UTC (permalink / raw)


Is the following line from the patch below really needed?
+#include <linux/uuid.h>

It was causing the following compile error in SLES 11.4
In file included from nvme.h:34,
                 from nvme-print.h:4,
                 from nvme-print.c:6:
linux/nvme.h:19:24: error: linux/uuid.h: No such file or directory
make: *** [nvme-print.o] Error 1

When I comment out the #include <linux/uuid.h>, it compiles just fine.   I also commented it out on SLES 12.2 and Redhat 7.4 and it compiled just fine without it there as well.

Jeff Lien

-----Original Message-----
From: Linux-nvme [mailto:linux-nvme-bounces@lists.infradead.org] On Behalf Of Christoph Hellwig
Sent: Saturday, June 24, 2017 2:13 AM
To: Johannes Thumshirn
Cc: Keith Busch; Sagi Grimberg; Linux NVMe Mailinglist; Christoph Hellwig
Subject: Re: [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand

Meh, this still didn't properly resync nvme.h.

Something like this is needed for the current tree:

---
>From 79afec638c7a0eb636065403615a78db64ecaec7 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Sat, 24 Jun 2017 09:04:48 +0200
Subject: resync nvme.h with the kernel

Copy over the current nvme.h from the for-4.13 block tree, and adjust a few callers.  The biggest tweak is that we can't use the kernel uuid.h and either need to use libuuid or our own definition.

Signed-off-by: Christoph Hellwig <hch at lst.de>
---
 fabrics.c    |   2 +
 linux/nvme.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 nvme-print.c |   8 +---
 nvme.c       |   4 --
 nvme.h       |  19 ++++----
 5 files changed, 129 insertions(+), 44 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index 87cdba2..da4e04e 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -44,6 +44,8 @@
 
 #include "common.h"
 
+#define NVMF_HOSTID_SIZE	36
+
 static struct config {
 	char *nqn;
 	char *transport;
diff --git a/linux/nvme.h b/linux/nvme.h index d1a322b..291587a 100644
--- a/linux/nvme.h
+++ b/linux/nvme.h
@@ -16,6 +16,7 @@
 #define _LINUX_NVME_H
 
 #include <linux/types.h>

 /* NQN names in commands fields specified one size */
 #define NVMF_NQN_FIELD_LEN	256
@@ -23,7 +24,6 @@
 /* However the max length of a qualified name is another size */
 #define NVMF_NQN_SIZE		223
 
-#define NVMF_HOSTID_SIZE        36
 #define NVMF_TRSVCID_SIZE	32
 #define NVMF_TRADDR_SIZE	256
 #define NVMF_TSAS_SIZE		256
@@ -102,6 +102,7 @@ enum {
 	NVME_REG_ACQ	= 0x0030,	/* Admin CQ Base Address */
 	NVME_REG_CMBLOC = 0x0038,	/* Controller Memory Buffer Location */
 	NVME_REG_CMBSZ	= 0x003c,	/* Controller Memory Buffer Size */
+	NVME_REG_DBS	= 0x1000,	/* SQ 0 Tail Doorbell */
 };
 
 #define NVME_CAP_MQES(cap)	((cap) & 0xffff)
@@ -249,7 +250,10 @@ enum {
 	NVME_CTRL_ONCS_COMPARE			= 1 << 0,
 	NVME_CTRL_ONCS_WRITE_UNCORRECTABLE	= 1 << 1,
 	NVME_CTRL_ONCS_DSM			= 1 << 2,
+	NVME_CTRL_ONCS_WRITE_ZEROES		= 1 << 3,
 	NVME_CTRL_VWC_PRESENT			= 1 << 0,
+	NVME_CTRL_OACS_SEC_SUPP                 = 1 << 0,
+	NVME_CTRL_OACS_DBBUF_SUPP		= 1 << 7,
 };
 
 struct nvme_lbaf {
@@ -289,6 +293,17 @@ struct nvme_id_ns {  };
 
 enum {
+	NVME_ID_CNS_NS			= 0x00,
+	NVME_ID_CNS_CTRL		= 0x01,
+	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
+	NVME_ID_CNS_NS_DESC_LIST	= 0x03,
+	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
+	NVME_ID_CNS_NS_PRESENT		= 0x11,
+	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
+	NVME_ID_CNS_CTRL_LIST		= 0x13,
+};
+
+enum {
 	NVME_NS_FEAT_THIN	= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_META_EXT	= 0x10,
@@ -308,6 +323,22 @@ enum {
 	NVME_NS_DPS_PI_TYPE3	= 3,
 };
 
+struct nvme_ns_id_desc {
+	__u8 nidt;
+	__u8 nidl;
+	__le16 reserved;
+};
+
+#define NVME_NIDT_EUI64_LEN	8
+#define NVME_NIDT_NGUID_LEN	16
+#define NVME_NIDT_UUID_LEN	16
+
+enum {
+	NVME_NIDT_EUI64		= 0x01,
+	NVME_NIDT_NGUID		= 0x02,
+	NVME_NIDT_UUID		= 0x03,
+};
+
 struct nvme_smart_log {
 	__u8			critical_warning;
 	__u8			temperature[2];
@@ -549,12 +580,42 @@ enum {
 	NVME_DSMGMT_AD		= 1 << 2,
 };
 
+#define NVME_DSM_MAX_RANGES	256
+
 struct nvme_dsm_range {
 	__le32			cattr;
 	__le32			nlb;
 	__le64			slba;
 };
 
+struct nvme_write_zeroes_cmd {
+	__u8			opcode;
+	__u8			flags;
+	__u16			command_id;
+	__le32			nsid;
+	__u64			rsvd2;
+	__le64			metadata;
+	union nvme_data_ptr	dptr;
+	__le64			slba;
+	__le16			length;
+	__le16			control;
+	__le32			dsmgmt;
+	__le32			reftag;
+	__le16			apptag;
+	__le16			appmask;
+};
+
+/* Features */
+
+struct nvme_feat_auto_pst {
+	__le64 entries[32];
+};
+
+enum {
+	NVME_HOST_MEM_ENABLE	= (1 << 0),
+	NVME_HOST_MEM_RETURN	= (1 << 1),
+};
+
 /* Admin commands */
 
 enum nvme_admin_opcode {
@@ -573,6 +634,7 @@ enum nvme_admin_opcode {
 	nvme_admin_download_fw		= 0x11,
 	nvme_admin_ns_attach		= 0x15,
 	nvme_admin_keep_alive		= 0x18,
+	nvme_admin_dbbuf		= 0x7C,
 	nvme_admin_format_nvm		= 0x80,
 	nvme_admin_security_send	= 0x81,
 	nvme_admin_security_recv	= 0x82,
@@ -620,10 +682,14 @@ struct nvme_identify {
 	__le32			nsid;
 	__u64			rsvd2[2];
 	union nvme_data_ptr	dptr;
-	__le32			cns;
+	__u8			cns;
+	__u8			rsvd3;
+	__le16			ctrlid;
 	__u32			rsvd11[5];
 };
 
+#define NVME_IDENTIFY_DATA_SIZE 4096
+
 struct nvme_features {
 	__u8			opcode;
 	__u8			flags;
@@ -633,7 +699,16 @@ struct nvme_features {
 	union nvme_data_ptr	dptr;
 	__le32			fid;
 	__le32			dword11;
-	__u32			rsvd12[4];
+	__le32                  dword12;
+	__le32                  dword13;
+	__le32                  dword14;
+	__le32                  dword15;
+};
+
+struct nvme_host_mem_buf_desc {
+	__le64			addr;
+	__le32			size;
+	__u32			rsvd;
 };
 
 struct nvme_create_cq {
@@ -809,7 +884,7 @@ struct nvmf_connect_command {  };
 
 struct nvmf_connect_data {
-	__u8		hostid[16];
+	uuid_t		hostid;
 	__le16		cntlid;
 	char		resv4[238];
 	char		subsysnqn[NVMF_NQN_FIELD_LEN];
@@ -842,6 +917,16 @@ struct nvmf_property_get_command {
 	__u8		resv4[16];
 };
 
+struct nvme_dbbuf {
+	__u8			opcode;
+	__u8			flags;
+	__u16			command_id;
+	__u32			rsvd1[5];
+	__le64			prp1;
+	__le64			prp2;
+	__u32			rsvd12[6];
+};
+
 struct nvme_command {
 	union {
 		struct nvme_common_command common;
@@ -854,29 +939,17 @@ struct nvme_command {
 		struct nvme_download_firmware dlfw;
 		struct nvme_format_cmd format;
 		struct nvme_dsm_cmd dsm;
+		struct nvme_write_zeroes_cmd write_zeroes;
 		struct nvme_abort_cmd abort;
 		struct nvme_get_log_page_command get_log_page;
 		struct nvmf_common_command fabrics;
 		struct nvmf_connect_command connect;
 		struct nvmf_property_set_command prop_set;
 		struct nvmf_property_get_command prop_get;
+		struct nvme_dbbuf dbbuf;
 	};
 };
 
-#define NVME_IDENTIFY_CMD_LEN 4096
-#define NVME_ID_CNS_NS_DESC_LIST 0x3
-enum {
-	NVME_NIDT_EUI64		= 0x1,
-	NVME_NIDT_NGUID		= 0x2,
-	NVME_NIDT_UUID		= 0x3,
-};
-
-struct nvme_ns_id_desc {
-	__u8 nidt;
-	__u8 nidl;
-	__u16 reserved;
-};
-
 static inline bool nvme_is_write(struct nvme_command *cmd)  {
 	/*
@@ -958,6 +1031,7 @@ enum {
 	NVME_SC_BAD_ATTRIBUTES		= 0x180,
 	NVME_SC_INVALID_PI		= 0x181,
 	NVME_SC_READ_ONLY		= 0x182,
+	NVME_SC_ONCS_NOT_SUPPORTED	= 0x183,
 
 	/*
 	 * I/O Command Set Specific - Fabrics commands:
@@ -984,23 +1058,41 @@ enum {
 	NVME_SC_UNWRITTEN_BLOCK		= 0x287,
 
 	NVME_SC_DNR			= 0x4000,
+
+
+	/*
+	 * FC Transport-specific error status values for NVME commands
+	 *
+	 * Transport-specific status code values must be in the range 0xB0..0xBF
+	 */
+
+	/* Generic FC failure - catchall */
+	NVME_SC_FC_TRANSPORT_ERROR	= 0x00B0,
+
+	/* I/O failure due to FC ABTS'd */
+	NVME_SC_FC_TRANSPORT_ABORTED	= 0x00B1,
 };
 
 struct nvme_completion {
 	/*
 	 * Used by Admin and Fabrics commands to return data:
 	 */
-	union {
-		__le16	result16;
-		__le32	result;
-		__le64	result64;
-	};
+	union nvme_result {
+		__le16	u16;
+		__le32	u32;
+		__le64	u64;
+	} result;
 	__le16	sq_head;	/* how much of this queue may be reclaimed */
 	__le16	sq_id;		/* submission queue that generated this entry */
 	__u16	command_id;	/* of the command which completed */
 	__le16	status;		/* did the command fail, and if so, why? */
 };
 
-#define NVME_VS(major, minor) (((major) << 16) | ((minor) << 8))
+#define NVME_VS(major, minor, tertiary) \
+	(((major) << 16) | ((minor) << 8) | (tertiary))
+
+#define NVME_MAJOR(ver)		((ver) >> 16)
+#define NVME_MINOR(ver)		(((ver) >> 8) & 0xff)
+#define NVME_TERTIARY(ver)	((ver) & 0xff)
 
 #endif /* _LINUX_NVME_H */
diff --git a/nvme-print.c b/nvme-print.c index dca4a19..637c695 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -3,10 +3,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "json.h"
 #include "nvme-models.h"
@@ -622,7 +618,7 @@ void json_nvme_id_ns_descs(void *data)
 
 	root = json_create_object();
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		off = pos + sizeof(*cur);
@@ -680,7 +676,7 @@ void show_nvme_id_ns_descs(void *data)
 	__u8 eui64[8];
 	__u8 nguid[16];
 
-	for (pos = 0; pos < NVME_IDENTIFY_CMD_LEN; pos += len) {
+	for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
 		struct nvme_ns_id_desc *cur = data + pos;
 
 		if (cur->nidl == 0)
diff --git a/nvme.c b/nvme.c
index f746b74..4cb7d63 100644
--- a/nvme.c
+++ b/nvme.c
@@ -45,10 +45,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
-#ifdef LIBUUID
-#include <uuid/uuid.h>
-#endif
-
 #include "nvme-print.h"
 #include "nvme-ioctl.h"
 #include "nvme-lightnvm.h"
diff --git a/nvme.h b/nvme.h
index 397a1a5..b796961 100644
--- a/nvme.h
+++ b/nvme.h
@@ -21,6 +21,15 @@
 #include "json.h"
 
 #define unlikely(x) x
+
+#ifdef LIBUUID
+#include <uuid/uuid.h>
+#else
+typedef struct {
+	__u8 b[16];
+} uuid_t;
+#endif
+
 #include "linux/nvme.h"
 
 struct nvme_error_log_page {
@@ -45,16 +54,6 @@ struct nvme_firmware_log_page {
 /* idle and active power scales occupy the last 2 bits of the field */  #define POWER_SCALE(s) ((s) >> 6)
 
-enum {
-	NVME_ID_CNS_NS			= 0x00,
-	NVME_ID_CNS_CTRL		= 0x01,
-	NVME_ID_CNS_NS_ACTIVE_LIST	= 0x02,
-	NVME_ID_CNS_NS_PRESENT_LIST	= 0x10,
-	NVME_ID_CNS_NS_PRESENT		= 0x11,
-	NVME_ID_CNS_CTRL_NS_LIST	= 0x12,
-	NVME_ID_CNS_CTRL_LIST		= 0x13,
-};
-
 struct nvme_host_mem_buffer {
 	__u32			hsize;
 	__u32			hmdlal;
--
2.11.0


_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2018-01-02 22:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-23  7:36 [PATCH nvme-cli v2] nvme-cli: add ns-descs subcommand Johannes Thumshirn
2017-06-23 16:37 ` Keith Busch
2017-06-24  7:12 ` Christoph Hellwig
2018-01-02 22:11   ` Jeffrey Lien

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.