From d7b7dbfb78223bcaa6416389984d972dc2eac075 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 12 Oct 2016 16:11:55 -0700 Subject: [PATCH] nvme: introduce transport abstraction This will allow factoring out PCIe-specific code into a swappable transport so that NVMe over Fabrics host support can be added. Change-Id: I4df74dd268d655e3b36e8d6114ebe7d79a24844d Signed-off-by: Daniel Verkamp --- lib/nvme/Makefile | 2 +- lib/nvme/nvme.c | 2 + lib/nvme/nvme_internal.h | 10 +++++ lib/nvme/nvme_pcie.c | 41 +++++++++++++++++++ lib/nvme/nvme_qpair.c | 1 + test/lib/nvme/unit/nvme_c/nvme_ut.c | 3 ++ .../nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c | 3 ++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 lib/nvme/nvme_pcie.c diff --git a/lib/nvme/Makefile b/lib/nvme/Makefile index 6def9d2bf..d030f5db1 100644 --- a/lib/nvme/Makefile +++ b/lib/nvme/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk CFLAGS += $(ENV_CFLAGS) -C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_ns_cmd.c nvme_ns.c nvme_qpair.c nvme.c nvme_intel.c +C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_ns_cmd.c nvme_ns.c nvme_pcie.c nvme_qpair.c nvme.c nvme_intel.c LIBNAME = nvme include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 0807c947c..a4669b528 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -58,6 +58,8 @@ nvme_attach(void *devhandle) return NULL; } + ctrlr->transport = &spdk_nvme_transport_pcie; + status = nvme_ctrlr_construct(ctrlr, devhandle); if (status != 0) { spdk_free(ctrlr); diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index bc6cc90cb..3bbf13c5d 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -241,6 +241,10 @@ struct nvme_request { void *user_buffer; }; +struct spdk_nvme_transport { + int reserved; +}; + struct nvme_completion_poll_status { struct spdk_nvme_cpl cpl; bool done; @@ -284,6 +288,8 @@ struct spdk_nvme_qpair { volatile uint32_t *sq_tdbl; volatile uint32_t *cq_hdbl; + const struct spdk_nvme_transport *transport; + /** * Submission queue */ @@ -383,6 +389,8 @@ struct spdk_nvme_ctrlr { /** NVMe MMIO register space */ volatile struct spdk_nvme_registers *regs; + const struct spdk_nvme_transport *transport; + /** I/O queue pairs */ struct spdk_nvme_qpair *ioq; @@ -480,6 +488,8 @@ struct pci_id { extern struct nvme_driver *g_spdk_nvme_driver; +extern const struct spdk_nvme_transport spdk_nvme_transport_pcie; + #define nvme_min(a,b) (((a)<(b))?(a):(b)) #define INTEL_DC_P3X00_DEVID 0x09538086 diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c new file mode 100644 index 000000000..15cb7467b --- /dev/null +++ b/lib/nvme/nvme_pcie.c @@ -0,0 +1,41 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * NVMe over PCIe transport + */ + +#include "nvme_internal.h" + +const struct spdk_nvme_transport spdk_nvme_transport_pcie = { +}; diff --git a/lib/nvme/nvme_qpair.c b/lib/nvme/nvme_qpair.c index 43fb3a06a..b94d34311 100644 --- a/lib/nvme/nvme_qpair.c +++ b/lib/nvme/nvme_qpair.c @@ -546,6 +546,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id, qpair->sq_in_cmb = false; qpair->ctrlr = ctrlr; + qpair->transport = ctrlr->transport; /* cmd and cpl rings must be aligned on 4KB boundaries. */ if (ctrlr->opts.use_cmb_sqs) { diff --git a/test/lib/nvme/unit/nvme_c/nvme_ut.c b/test/lib/nvme/unit/nvme_c/nvme_ut.c index bcd45bf4c..1058f2331 100644 --- a/test/lib/nvme/unit/nvme_c/nvme_ut.c +++ b/test/lib/nvme/unit/nvme_c/nvme_ut.c @@ -39,6 +39,9 @@ #include "lib/nvme/unit/test_env.c" +const struct spdk_nvme_transport spdk_nvme_transport_pcie = { +}; + int spdk_pci_enumerate(enum spdk_pci_device_type type, spdk_pci_enum_cb enum_cb, diff --git a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c index d70cc41e3..b14689e69 100644 --- a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c +++ b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c @@ -39,6 +39,9 @@ struct nvme_request *g_request = NULL; +const struct spdk_nvme_transport spdk_nvme_transport_pcie = { +}; + int spdk_pci_enumerate(enum spdk_pci_device_type type,