From 5fc12ae9e284bcf521fa2bc204d5096ddfa2058e Mon Sep 17 00:00:00 2001 From: Xiaodong Liu Date: Tue, 15 May 2018 18:36:00 +0800 Subject: [PATCH] ocssd: check whether ctrlr support ocssd There isn't a standardized way to identify Open-Channel SSD, different verdors may have different conditions. Here just take the Qemu simulated OCSSD device as a start. Change-Id: I1aceaac09db438c203875bcf37badd542618bdd7 Signed-off-by: Xiaodong Liu Reviewed-on: https://review.gerrithub.io/411590 Tested-by: SPDK Automated Test System Reviewed-by: Ziye Yang Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker Reviewed-by: Jakub Radtke --- include/spdk/nvme_ocssd.h | 8 ++++++++ lib/nvme/nvme_ctrlr_ocssd_cmd.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/spdk/nvme_ocssd.h b/include/spdk/nvme_ocssd.h index 98a54066e..00cc6d70d 100644 --- a/include/spdk/nvme_ocssd.h +++ b/include/spdk/nvme_ocssd.h @@ -48,6 +48,14 @@ extern "C" { #include "spdk/nvme.h" #include "spdk/nvme_ocssd_spec.h" +/** + * \brief Determine if OpenChannel is supported by the given NVMe controller. + * \param ctrlr NVMe controller to check. + * + * \return true if support OpenChannel + */ +bool spdk_nvme_ctrlr_is_ocssd_supported(struct spdk_nvme_ctrlr *ctrlr); + /** * \brief Identify geometry of the given namespace. * \param ctrlr NVMe controller to query. diff --git a/lib/nvme/nvme_ctrlr_ocssd_cmd.c b/lib/nvme/nvme_ctrlr_ocssd_cmd.c index 6f3742a3c..80de53281 100644 --- a/lib/nvme/nvme_ctrlr_ocssd_cmd.c +++ b/lib/nvme/nvme_ctrlr_ocssd_cmd.c @@ -34,6 +34,27 @@ #include "spdk/nvme_ocssd.h" #include "nvme_internal.h" +bool +spdk_nvme_ctrlr_is_ocssd_supported(struct spdk_nvme_ctrlr *ctrlr) +{ + if (ctrlr->quirks & NVME_QUIRK_OCSSD) { + // TODO: There isn't a standardized way to identify Open-Channel SSD + // different verdors may have different conditions. + + /* + * Current QEMU OpenChannel Device needs to check nsdata->vs[0]. + * Here check nsdata->vs[0] of the first namespace. + */ + if (ctrlr->cdata.vid == SPDK_PCI_VID_CNEXLABS) { + if (ctrlr->num_ns && ctrlr->nsdata[0].vendor_specific[0] == 0x1) { + return true; + } + } + } + return false; +} + + int spdk_nvme_ocssd_ctrlr_cmd_geometry(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, void *payload, uint32_t payload_size,