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,