Commit 174a5fe1 authored by Niklas Cassel's avatar Niklas Cassel Committed by Tomasz Zawadzki
Browse files

nvme: add initial namespace types support



Add support for getting the Command Set Identifier for a given namespace.

The SPDK_NVME_CAP_CSS_IOCS feature can be implemented on top of an old NVMe
specification. If the feature is set, retrieve the NS ID Descriptor List
regardless of the NVMe specification version. The quirk is still respected.

Signed-off-by: default avatarNiklas Cassel <niklas.cassel@wdc.com>
Change-Id: I7b257115ecb0d813ba75201c0f48960c7070dcc9
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4085


Community-CI: Broadcom CI
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 5c861295
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2274,6 +2274,15 @@ uint32_t spdk_nvme_ns_get_optimal_io_boundary(struct spdk_nvme_ns *ns);
 */
const struct spdk_uuid *spdk_nvme_ns_get_uuid(const struct spdk_nvme_ns *ns);

/**
 * Get the Command Set Identifier for the given namespace.
 *
 * \param ns Namespace to query.
 *
 * \return the namespace Command Set Identifier.
 */
enum spdk_nvme_csi spdk_nvme_ns_get_csi(const struct spdk_nvme_ns *ns);

/**
 * \brief Namespace command support flags.
 */
+17 −0
Original line number Diff line number Diff line
@@ -980,6 +980,14 @@ SPDK_STATIC_ASSERT(sizeof(union spdk_nvme_cmd_cdw10) == 4, "Incorrect size");
union spdk_nvme_cmd_cdw11 {
	uint32_t raw;

	struct {
		/* NVM Set Identifier */
		uint32_t nvmsetid  : 16;
		uint32_t reserved  : 8;
		/* Command Set Identifier */
		uint32_t csi       : 8;
	} identify;

	struct {
		/* Physically Contiguous */
		uint32_t pc       : 1;
@@ -2852,6 +2860,9 @@ enum spdk_nvme_nidt {

	/** Namespace UUID */
	SPDK_NVME_NIDT_UUID		= 0x03,

	/** Namespace Command Set Identifier */
	SPDK_NVME_NIDT_CSI		= 0x04,
};

struct spdk_nvme_ns_id_desc {
@@ -2875,6 +2886,12 @@ struct spdk_nvme_ctrlr_list {
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvme_ctrlr_list) == 4096, "Incorrect size");

enum spdk_nvme_csi {
	SPDK_NVME_CSI_NVM	= 0x0,
	SPDK_NVME_CSI_KV	= 0x1,
	SPDK_NVME_CSI_ZNS	= 0x2,
};

enum spdk_nvme_secure_erase_setting {
	SPDK_NVME_FMT_NVM_SES_NO_SECURE_ERASE	= 0x0,
	SPDK_NVME_FMT_NVM_SES_USER_DATA_ERASE	= 0x1,
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 4
SO_MINOR := 0
SO_MINOR := 1

C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_fabric.c nvme_ns_cmd.c nvme_ns.c nvme_pcie.c nvme_qpair.c nvme.c nvme_quirks.c nvme_transport.c nvme_uevent.c nvme_ctrlr_ocssd_cmd.c \
	nvme_ns_ocssd_cmd.c nvme_tcp.c nvme_opal.c nvme_io_msg.c nvme_poll_group.c
+2 −1
Original line number Diff line number Diff line
@@ -1731,7 +1731,8 @@ nvme_ctrlr_identify_id_desc_namespaces(struct spdk_nvme_ctrlr *ctrlr)
	struct spdk_nvme_ns *ns;
	int rc;

	if (ctrlr->vs.raw < SPDK_NVME_VERSION(1, 3, 0) ||
	if ((ctrlr->vs.raw < SPDK_NVME_VERSION(1, 3, 0) &&
	     !(ctrlr->cap.bits.css & SPDK_NVME_CAP_CSS_IOCS)) ||
	    (ctrlr->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
		SPDK_DEBUGLOG(SPDK_LOG_NVME, "Version < 1.3; not attempting to retrieve NS ID Descriptor List\n");
		nvme_ctrlr_set_state(ctrlr, NVME_CTRLR_STATE_CONFIGURE_AER,
+25 −1
Original line number Diff line number Diff line
@@ -157,7 +157,8 @@ nvme_ctrlr_identify_id_desc(struct spdk_nvme_ns *ns)

	memset(ns->id_desc_list, 0, sizeof(ns->id_desc_list));

	if (ns->ctrlr->vs.raw < SPDK_NVME_VERSION(1, 3, 0) ||
	if ((ns->ctrlr->vs.raw < SPDK_NVME_VERSION(1, 3, 0) &&
	     !(ns->ctrlr->cap.bits.css & SPDK_NVME_CAP_CSS_IOCS)) ||
	    (ns->ctrlr->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
		SPDK_DEBUGLOG(SPDK_LOG_NVME, "Version < 1.3; not attempting to retrieve NS ID Descriptor List\n");
		return 0;
@@ -360,6 +361,29 @@ spdk_nvme_ns_get_uuid(const struct spdk_nvme_ns *ns)
	return uuid;
}

enum spdk_nvme_csi
spdk_nvme_ns_get_csi(const struct spdk_nvme_ns *ns) {
	const uint8_t *csi;
	size_t csi_size;

	csi = nvme_ns_find_id_desc(ns, SPDK_NVME_NIDT_CSI, &csi_size);
	if (csi && csi_size != sizeof(*csi))
	{
		SPDK_WARNLOG("Invalid NIDT_CSI descriptor length reported: %zu (expected: %zu)\n",
			     csi_size, sizeof(*csi));
		return SPDK_NVME_CSI_NVM;
	}
	if (!csi)
	{
		if (ns->ctrlr->cap.bits.css & SPDK_NVME_CAP_CSS_IOCS) {
			SPDK_WARNLOG("CSI not reported for NSID: %" PRIu32 "\n", ns->id);
		}
		return SPDK_NVME_CSI_NVM;
	}

	return *csi;
}

int nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id,
		      struct spdk_nvme_ctrlr *ctrlr)
{
Loading