diff --git a/CHANGELOG.md b/CHANGELOG.md index 885c51ea9..351d7a9a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ updated by simply removing the initialization of `request_mempool`. Since the N library user no longer needs to know the size of the internal NVMe request structure to create the pool, the `spdk_nvme_request_size()` function was also removed. +Libpciaccess has been removed as a dependency and DPDK PCI enumeration is +used instead. Prior to DPDK 16.07 enumeration by class code was not supported, +so for earlier DPDK versions only Intel SSDs will be discovered. Starting with +DPDK 16.07 all devices will be discovered correctly by class code. + v16.08: iSCSI target, NVMe over Fabrics maturity ------------------------------------------------ diff --git a/CONFIG b/CONFIG index 0c84ac4a2..bcc573b95 100644 --- a/CONFIG +++ b/CONFIG @@ -56,11 +56,6 @@ CONFIG_NVME_IMPL?=nvme_impl.h # Defaults to depending on DPDK. CONFIG_IOAT_IMPL?=ioat_impl.h -# This item indicates using libpciaccess library or not. If enabled with y, -# libpciaccess library is used to map pci devices; else DPDK library is used to -# map pci devices. -CONFIG_PCIACCESS?=y - # Build SPDK FIO plugin. Requires FIO_SOURCE_DIR set to a valid # fio source code directory. CONFIG_FIO_PLUGIN?=n diff --git a/PORTING.md b/PORTING.md index 5266a6282..c20923e38 100644 --- a/PORTING.md +++ b/PORTING.md @@ -8,10 +8,9 @@ operations (config cycles and mapping BARs), virtual to physical address translation and allocating per I/O data structures. SPDK includes a default implementation of the nvme_impl API based -on the Data Plane Development Kit ([DPDK](dpdk.org)) and -libpciaccess. This DPDK implementation can be found in -lib/nvme/nvme_impl.h. DPDK is currently supported on Linux and -FreeBSD only. +on the Data Plane Development Kit ([DPDK](dpdk.org)). This DPDK +implementation can be found in lib/nvme/nvme_impl.h. DPDK is +currently supported on Linux and FreeBSD only. Users who want to use SPDK on other operating system, or in userspace driver frameworks other than DPDK, will need to implement diff --git a/README.md b/README.md index c67928fd4..2b664e8c6 100644 --- a/README.md +++ b/README.md @@ -38,20 +38,19 @@ To build SPDK, some dependencies must be installed. Fedora/CentOS: - sudo dnf install -y gcc gcc-c++ libpciaccess-devel CUnit-devel libaio-devel openssl-devel + sudo dnf install -y gcc gcc-c++ CUnit-devel libaio-devel openssl-devel # Additional dependencies for NVMe over Fabrics: sudo dnf install -y libibverbs-devel librdmacm-devel Ubuntu/Debian: - sudo apt-get install -y gcc g++ libpciaccess-dev make libcunit1-dev libaio-dev libssl-dev + sudo apt-get install -y gcc g++ make libcunit1-dev libaio-dev libssl-dev # Additional dependencies for NVMe over Fabrics: sudo apt-get install -y libibverbs-dev librdmacm-dev FreeBSD: - gcc -- libpciaccess - gmake - cunit - openssl diff --git a/app/iscsi_tgt/Makefile b/app/iscsi_tgt/Makefile index 876819265..8d7b41686 100644 --- a/app/iscsi_tgt/Makefile +++ b/app/iscsi_tgt/Makefile @@ -64,7 +64,7 @@ SPDK_LIBS = \ $(SPDK_ROOT_DIR)/lib/event/rpc/libspdk_app_rpc.a \ LIBS += -Wl,--whole-archive $(SPDK_LIBS) -Wl,--no-whole-archive -LIBS += -lcrypto $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += -lcrypto $(DPDK_LIB) LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \ $(COPY_MODULES_LINKER_ARGS) diff --git a/app/nvmf_tgt/Makefile b/app/nvmf_tgt/Makefile index 675e33598..7187129ba 100644 --- a/app/nvmf_tgt/Makefile +++ b/app/nvmf_tgt/Makefile @@ -65,7 +65,7 @@ SPDK_LIBS = \ LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \ $(COPY_MODULES_LINKER_ARGS) -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) +LIBS += $(SPDK_LIBS) ifeq ($(CONFIG_RDMA),y) LIBS += -libverbs -lrdmacm diff --git a/app/nvmf_tgt/conf.c b/app/nvmf_tgt/conf.c index 0521941e7..d8a51f30b 100644 --- a/app/nvmf_tgt/conf.c +++ b/app/nvmf_tgt/conf.c @@ -341,11 +341,8 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts found_bus == ctx->bus && found_dev == ctx->device && found_func == ctx->function) { - if (!spdk_pci_device_has_non_uio_driver(dev)) { - ctx->found = true; - return true; - } - SPDK_ERRLOG("Requested device is still bound to the kernel. Unbind your NVMe devices first.\n"); + ctx->found = true; + return true; } return false; diff --git a/app/nvmf_tgt/nvmf_rpc.c b/app/nvmf_tgt/nvmf_rpc.c index f5ea2931d..0400d6f95 100644 --- a/app/nvmf_tgt/nvmf_rpc.c +++ b/app/nvmf_tgt/nvmf_rpc.c @@ -33,7 +33,7 @@ #include #include -#include + #include "nvmf_tgt.h" #include "nvmf/subsystem.h" #include "nvmf/transport.h" diff --git a/doc/iscsi/getting_started.txt b/doc/iscsi/getting_started.txt index 5d0acfde1..71f7e701b 100644 --- a/doc/iscsi/getting_started.txt +++ b/doc/iscsi/getting_started.txt @@ -149,12 +149,6 @@ the kernel to avoid interrupts and context switching. BDF 0000:00:00.0 Nvme0 BDF 0000:01:00.0 Nvme1 - # Users can set the option "UnbindFromKernel Yes", SPDK will unbind all NVMe - # devices from kernel driver and bind them to the uio_pci_generic driver. - # The purpose is to prevent the case where NVMe driver is loaded while iscsi - # is running. - UnbindFromKernel Yes - # SPDK supports partitioning each nvme card into multiple LUNs # through the NvmeLunsPerNs parameter. If NvmeLunsPerNs is specified, # then the size of the nvme card is split up equally only if LunSizeinMB diff --git a/etc/spdk/iscsi.conf.in b/etc/spdk/iscsi.conf.in index d30077fed..593dc253c 100644 --- a/etc/spdk/iscsi.conf.in +++ b/etc/spdk/iscsi.conf.in @@ -96,9 +96,6 @@ BDF 0000:00:00.0 Nvme0 BDF 0000:01:00.0 Nvme1 - # If 'Yes', iscsi will automatically unbind the kernel NVMe driver from - # discovered devices and rebind it to the uio driver. - UnbindFromKernel Yes # The following two arguments allow the user to partition NVMe namespaces # into multiple LUNs NvmeLunsPerNs 1 @@ -126,13 +123,10 @@ # Users may not want to use offload even it is available. # Users may use the whitelist to initialize specified devices, IDS # uses BUS:DEVICE.FUNCTION to identify each Ioat channel. -# Users can set the option "UnbindFromKernel Yes", iscsi will automatically -# unbind from the Ioat driver and bind the device to uio driver. [Ioat] Disable Yes Whitelist 00:04.0 Whitelist 00:04.1 - UnbindFromKernel Yes # Users must change this section to match the /dev/sdX devices to be # exported as iSCSI LUNs. The devices are accessed using Linux AIO. diff --git a/examples/ioat/perf/Makefile b/examples/ioat/perf/Makefile index 9dd16d9e1..6284d3d0c 100644 --- a/examples/ioat/perf/Makefile +++ b/examples/ioat/perf/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/ioat/libspdk_ioat.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all: $(APP) diff --git a/examples/ioat/perf/perf.c b/examples/ioat/perf/perf.c index fd772bac3..da69d3e85 100644 --- a/examples/ioat/perf/perf.c +++ b/examples/ioat/perf/perf.c @@ -154,11 +154,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev) spdk_pci_device_get_vendor_id(pci_dev), spdk_pci_device_get_device_id(pci_dev), spdk_pci_device_get_device_name(pci_dev)); - if (spdk_pci_device_has_non_uio_driver(pci_dev)) { - printf("Device has non-uio kernel driver, skipping...\n"); - return false; - } - return true; } @@ -329,7 +324,7 @@ init(void) return 1; } - char *ealargs[] = {"perf", core_mask_conf, "-n 4", "--no-pci"}; + char *ealargs[] = {"perf", core_mask_conf, "-n 4"}; if (rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs) < 0) { free(core_mask_conf); diff --git a/examples/ioat/verify/Makefile b/examples/ioat/verify/Makefile index b66a6e151..15511f781 100644 --- a/examples/ioat/verify/Makefile +++ b/examples/ioat/verify/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/ioat/libspdk_ioat.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all: $(APP) diff --git a/examples/ioat/verify/verify.c b/examples/ioat/verify/verify.c index 9645f740e..164197750 100644 --- a/examples/ioat/verify/verify.c +++ b/examples/ioat/verify/verify.c @@ -210,11 +210,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev) spdk_pci_device_get_vendor_id(pci_dev), spdk_pci_device_get_device_id(pci_dev), spdk_pci_device_get_device_name(pci_dev)); - if (spdk_pci_device_has_non_uio_driver(pci_dev)) { - printf("Device has non-uio kernel driver, skipping...\n"); - return false; - } - return true; } @@ -395,7 +390,7 @@ init(void) return 1; } - char *ealargs[] = {"verify", core_mask_conf, "-n 4", "--no-pci"}; + char *ealargs[] = {"verify", core_mask_conf, "-n 4"}; if (rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs) < 0) { free(core_mask_conf); fprintf(stderr, "Could not init eal\n"); diff --git a/examples/nvme/arbitration/Makefile b/examples/nvme/arbitration/Makefile index 4dda543b5..0057530b5 100644 --- a/examples/nvme/arbitration/Makefile +++ b/examples/nvme/arbitration/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index 8db5db48b..10bb89793 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -869,17 +869,6 @@ register_workers(void) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - /* Update with user specified arbitration configuration */ opts->arb_mechanism = g_arbitration.arbitration_mechanism; diff --git a/examples/nvme/fio_plugin/Makefile b/examples/nvme/fio_plugin/Makefile index 6c85c7faf..d127fd696 100644 --- a/examples/nvme/fio_plugin/Makefile +++ b/examples/nvme/fio_plugin/Makefile @@ -49,7 +49,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 1a681e507..5bc307609 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -36,7 +36,6 @@ #include #include #include -#include #include "rte_config.h" #include "rte_mempool.h" @@ -109,13 +108,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts continue; } if (bus == found_bus && slot == found_slot && func == found_func) { - /* We do want to claim this device */ - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, - "Requested to attach to %02x:%02x.%02x but that device is not unbound from the kernel\n", - bus, slot, func); - return false; - } return true; } } diff --git a/examples/nvme/hello_world/Makefile b/examples/nvme/hello_world/Makefile index 4945b11ca..a91aae4c5 100644 --- a/examples/nvme/hello_world/Makefile +++ b/examples/nvme/hello_world/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 9fff5bf85..5e53c110f 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -240,22 +240,6 @@ hello_world(void) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - /* - * If an NVMe controller is found, but it is attached to a non-uio - * driver (i.e. the kernel NVMe driver), we will not try to attach - * to it. - */ - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - printf("Attaching to %04x:%02x:%02x.%02x\n", spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), diff --git a/examples/nvme/identify/Makefile b/examples/nvme/identify/Makefile index 7223d243f..038f8fe31 100644 --- a/examples/nvme/identify/Makefile +++ b/examples/nvme/identify/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 5b730025a..89c136116 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -872,17 +872,6 @@ parse_args(int argc, char **argv) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - return true; } diff --git a/examples/nvme/nvme_manage/Makefile b/examples/nvme/nvme_manage/Makefile index 1ffeea448..333893a62 100644 --- a/examples/nvme/nvme_manage/Makefile +++ b/examples/nvme/nvme_manage/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index 0d8faceef..33682da83 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -101,17 +101,6 @@ cmp_devs(const void *ap, const void *bp) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - return true; } diff --git a/examples/nvme/perf/Makefile b/examples/nvme/perf/Makefile index 72b059398..5d9a62b5a 100644 --- a/examples/nvme/perf/Makefile +++ b/examples/nvme/perf/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) ifeq ($(OS),Linux) LIBS += -laio diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index c9a8cdeba..24c09129f 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -966,17 +966,6 @@ unregister_workers(void) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - printf("Attaching to %04x:%02x:%02x.%02x\n", spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), diff --git a/examples/nvme/reserve/Makefile b/examples/nvme/reserve/Makefile index 5468c98b7..450263cbd 100644 --- a/examples/nvme/reserve/Makefile +++ b/examples/nvme/reserve/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/examples/nvme/reserve/reservation.c b/examples/nvme/reserve/reservation.c index 6a00d69ae..f2f24ce77 100644 --- a/examples/nvme/reserve/reservation.c +++ b/examples/nvme/reserve/reservation.c @@ -364,17 +364,6 @@ reserve_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair, static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - return true; } diff --git a/include/spdk/pci.h b/include/spdk/pci.h index 9f3474552..7f937b779 100644 --- a/include/spdk/pci.h +++ b/include/spdk/pci.h @@ -45,11 +45,23 @@ extern "C" { #include #include +enum spdk_pci_device_type { + SPDK_PCI_DEVICE_NVME, + SPDK_PCI_DEVICE_IOAT, +}; + struct spdk_pci_device; -int spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), +typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev); + +int spdk_pci_enumerate(enum spdk_pci_device_type type, + spdk_pci_enum_cb enum_cb, void *enum_ctx); +int spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, + void **mapped_addr, uint64_t *phys_addr, uint64_t *size); +int spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr); + uint16_t spdk_pci_device_get_domain(struct spdk_pci_device *dev); uint8_t spdk_pci_device_get_bus(struct spdk_pci_device *dev); uint8_t spdk_pci_device_get_dev(struct spdk_pci_device *dev); @@ -60,6 +72,8 @@ uint16_t spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev); uint16_t spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev); uint32_t spdk_pci_device_get_class(struct spdk_pci_device *dev); const char *spdk_pci_device_get_device_name(struct spdk_pci_device *dev); +int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len); +int spdk_pci_device_claim(struct spdk_pci_device *dev); int spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset); int spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset); @@ -68,13 +82,6 @@ int spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uin int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset); int spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset); -int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len); -int spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev); -int spdk_pci_device_unbind_kernel_driver(struct spdk_pci_device *dev); -int spdk_pci_device_bind_uio_driver(struct spdk_pci_device *dev); -int spdk_pci_device_switch_to_uio_driver(struct spdk_pci_device *pci_dev); -int spdk_pci_device_claim(struct spdk_pci_device *dev); - #ifdef __cplusplus } #endif diff --git a/include/spdk/pci_ids.h b/include/spdk/pci_ids.h index 194832562..7af6a9cd7 100644 --- a/include/spdk/pci_ids.h +++ b/include/spdk/pci_ids.h @@ -55,6 +55,60 @@ extern "C" { */ #define SPDK_PCI_CLASS_NVME 0x010802 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB0 0x3c20 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB1 0x3c21 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB2 0x3c22 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB3 0x3c23 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB4 0x3c24 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB5 0x3c25 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB6 0x3c26 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB7 0x3c27 +#define PCI_DEVICE_ID_INTEL_IOAT_SNB8 0x3c2e +#define PCI_DEVICE_ID_INTEL_IOAT_SNB9 0x3c2f + +#define PCI_DEVICE_ID_INTEL_IOAT_IVB0 0x0e20 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB1 0x0e21 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB2 0x0e22 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB3 0x0e23 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB4 0x0e24 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB5 0x0e25 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB6 0x0e26 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB7 0x0e27 +#define PCI_DEVICE_ID_INTEL_IOAT_IVB8 0x0e2e +#define PCI_DEVICE_ID_INTEL_IOAT_IVB9 0x0e2f + +#define PCI_DEVICE_ID_INTEL_IOAT_HSW0 0x2f20 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW1 0x2f21 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW2 0x2f22 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW3 0x2f23 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW4 0x2f24 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW5 0x2f25 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW6 0x2f26 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW7 0x2f27 +#define PCI_DEVICE_ID_INTEL_IOAT_HSW8 0x2f2e +#define PCI_DEVICE_ID_INTEL_IOAT_HSW9 0x2f2f + +#define PCI_DEVICE_ID_INTEL_IOAT_BWD0 0x0C50 +#define PCI_DEVICE_ID_INTEL_IOAT_BWD1 0x0C51 +#define PCI_DEVICE_ID_INTEL_IOAT_BWD2 0x0C52 +#define PCI_DEVICE_ID_INTEL_IOAT_BWD3 0x0C53 + +#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE0 0x6f50 +#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE1 0x6f51 +#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE2 0x6f52 +#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE3 0x6f53 + +#define PCI_DEVICE_ID_INTEL_IOAT_BDX0 0x6f20 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX1 0x6f21 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX2 0x6f22 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX3 0x6f23 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX4 0x6f24 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX5 0x6f25 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX6 0x6f26 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX7 0x6f27 +#define PCI_DEVICE_ID_INTEL_IOAT_BDX8 0x6f2e +#define PCI_DEVICE_ID_INTEL_IOAT_BDX9 0x6f2f + #ifdef __cplusplus } #endif diff --git a/lib/bdev/nvme/blockdev_nvme.c b/lib/bdev/nvme/blockdev_nvme.c index 2bda00470..f3bb46ba0 100644 --- a/lib/bdev/nvme/blockdev_nvme.c +++ b/lib/bdev/nvme/blockdev_nvme.c @@ -115,7 +115,6 @@ static int nvme_luns_per_ns = 1; static int nvme_controller_index = 0; static int LunSizeInMB = 0; static int num_controllers = -1; -static int unbindfromkernel = 0; static TAILQ_HEAD(, nvme_device) g_nvme_devices = TAILQ_HEAD_INITIALIZER(g_nvme_devices);; @@ -388,27 +387,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_o return false; } - if (spdk_pci_device_has_non_uio_driver(pci_dev)) { - /* NVMe kernel driver case */ - if (unbindfromkernel || ctx->num_whitelist_controllers > 0) { - if (spdk_pci_device_switch_to_uio_driver(pci_dev)) { - return false; - } - } else { - SPDK_WARNLOG("Device has kernel nvme driver attached, skipping...\n"); - return false; - } - } else { - if (spdk_pci_device_bind_uio_driver(pci_dev)) { - SPDK_WARNLOG("Device %s %d:%d:%d bind to uio driver failed\n", - spdk_pci_device_get_device_name(pci_dev), - spdk_pci_device_get_bus(pci_dev), - spdk_pci_device_get_dev(pci_dev), - spdk_pci_device_get_func(pci_dev)); - return false; - } - } - /* Claim the device in case conflict with other process */ if (spdk_pci_device_claim(pci_dev) != 0) { return false; @@ -487,13 +465,6 @@ nvme_library_init(void) */ num_controllers = spdk_conf_section_get_intval(sp, "NumControllers"); - val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); - if (val != NULL) { - if (!strcmp(val, "Yes")) { - unbindfromkernel = 1; - } - } - /* Init the whitelist */ probe_ctx.num_whitelist_controllers = 0; @@ -710,9 +681,7 @@ blockdev_nvme_get_spdk_running_config(FILE *fp) "\n" "# Users may change this to partition an NVMe namespace into multiple LUNs.\n" "[Nvme]\n" - " UnbindFromKernel %s\n" " NvmeLunsPerNs %d\n", - unbindfromkernel ? "Yes" : "No", nvme_luns_per_ns); if (num_controllers != -1) { fprintf(fp, " NumControllers %d\n", num_controllers); diff --git a/lib/copy/ioat/copy_engine_ioat.c b/lib/copy/ioat/copy_engine_ioat.c index fa3ba4542..71016b4c4 100644 --- a/lib/copy/ioat/copy_engine_ioat.c +++ b/lib/copy/ioat/copy_engine_ioat.c @@ -60,7 +60,6 @@ struct ioat_device { }; static TAILQ_HEAD(, ioat_device) g_devices = TAILQ_HEAD_INITIALIZER(g_devices); -static int g_unbindfromkernel = 0; static pthread_mutex_t g_ioat_mutex = PTHREAD_MUTEX_INITIALIZER; struct ioat_whitelist { @@ -262,26 +261,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev) return false; } - if (spdk_pci_device_has_non_uio_driver(pci_dev)) { - if (g_unbindfromkernel && ctx->num_whitelist_devices > 0) { - if (spdk_pci_device_switch_to_uio_driver(pci_dev)) { - return false; - } - } else { - SPDK_WARNLOG("Device has kernel ioat driver attached, skipping...\n"); - return false; - } - } else { - if (spdk_pci_device_bind_uio_driver(pci_dev)) { - SPDK_WARNLOG("Device %s %d:%d:%d bind to uio driver failed\n", - spdk_pci_device_get_device_name(pci_dev), - spdk_pci_device_get_bus(pci_dev), - spdk_pci_device_get_dev(pci_dev), - spdk_pci_device_get_func(pci_dev)); - return false; - } - } - /* Claim the device in case conflict with other process */ if (spdk_pci_device_claim(pci_dev) != 0) { return false; @@ -332,13 +311,6 @@ copy_engine_ioat_init(void) &probe_ctx.whitelist[probe_ctx.num_whitelist_devices].func); probe_ctx.num_whitelist_devices++; } - - val = spdk_conf_section_get_val(sp, "UnbindFromKernel"); - if (val != NULL) { - if (!strcmp(val, "Yes")) { - g_unbindfromkernel = 1; - } - } } if (spdk_ioat_probe(&probe_ctx, probe_cb, attach_cb) != 0) { diff --git a/lib/ioat/ioat.c b/lib/ioat/ioat.c index 99fa59dc5..c79eae7eb 100644 --- a/lib/ioat/ioat.c +++ b/lib/ioat/ioat.c @@ -32,7 +32,7 @@ */ #include "ioat_internal.h" -#include "ioat_pci.h" +#include "spdk/pci.h" #include "spdk/log.h" @@ -92,9 +92,10 @@ ioat_map_pci_bar(struct spdk_ioat_chan *ioat) { int regs_bar, rc; void *addr; + uint64_t phys_addr, size; regs_bar = 0; - rc = ioat_pcicfg_map_bar(ioat->device, regs_bar, 0, &addr); + rc = spdk_pci_device_map_bar(ioat->device, regs_bar, &addr, &phys_addr, &size); if (rc != 0 || addr == NULL) { SPDK_ERRLOG("pci_device_map_range failed with error code %d\n", rc); @@ -113,7 +114,7 @@ ioat_unmap_pci_bar(struct spdk_ioat_chan *ioat) void *addr = (void *)ioat->regs; if (addr) { - rc = ioat_pcicfg_unmap_bar(ioat->device, 0, addr); + rc = spdk_pci_device_unmap_bar(ioat->device, 0, addr); } return rc; } @@ -368,7 +369,7 @@ ioat_channel_start(struct spdk_ioat_chan *ioat) uint8_t xfercap, version; uint64_t status; int i, num_descriptors; - uint64_t comp_update_bus_addr; + uint64_t comp_update_bus_addr = 0; if (ioat_map_pci_bar(ioat) != 0) { SPDK_ERRLOG("ioat_map_pci_bar() failed\n"); @@ -471,9 +472,9 @@ ioat_attach(void *device) } /* Enable PCI busmaster. */ - ioat_pcicfg_read32(device, &cmd_reg, 4); + spdk_pci_device_cfg_read32(device, &cmd_reg, 4); cmd_reg |= 0x4; - ioat_pcicfg_write32(device, cmd_reg, 4); + spdk_pci_device_cfg_write32(device, cmd_reg, 4); ioat->device = device; @@ -542,7 +543,7 @@ spdk_ioat_probe(void *cb_ctx, spdk_ioat_probe_cb probe_cb, spdk_ioat_attach_cb a enum_ctx.attach_cb = attach_cb; enum_ctx.cb_ctx = cb_ctx; - rc = ioat_pci_enumerate(ioat_enum_cb, &enum_ctx); + rc = spdk_pci_enumerate(SPDK_PCI_DEVICE_IOAT, ioat_enum_cb, &enum_ctx); pthread_mutex_unlock(&g_ioat_driver.lock); diff --git a/lib/ioat/ioat_impl.h b/lib/ioat/ioat_impl.h index 9c1b5598b..7d0e07ba9 100644 --- a/lib/ioat/ioat_impl.h +++ b/lib/ioat/ioat_impl.h @@ -13,15 +13,8 @@ #include "spdk/assert.h" #include "spdk/pci.h" #include "spdk/vtophys.h" -#include "spdk/pci.h" -#include "ioat_pci.h" - -#ifdef SPDK_CONFIG_PCIACCESS -#include -#else #include -#endif /** * \file @@ -64,230 +57,4 @@ ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr) */ #define ioat_delay_us(us) rte_delay_us(us) -/** - * - */ -#define ioat_pcicfg_read32(handle, var, offset) spdk_pci_device_cfg_read32(handle, var, offset) -#define ioat_pcicfg_write32(handle, var, offset) spdk_pci_device_cfg_write32(handle, var, offset) - -struct ioat_pci_enum_ctx { - int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev); - void *user_enum_ctx; -}; - -#ifdef SPDK_CONFIG_PCIACCESS - -static inline bool -ioat_pci_device_match_id(uint16_t vendor_id, uint16_t device_id) -{ - if (vendor_id != SPDK_PCI_VID_INTEL) { - return false; - } - - switch (device_id) { - case PCI_DEVICE_ID_INTEL_IOAT_SNB0: - case PCI_DEVICE_ID_INTEL_IOAT_SNB1: - case PCI_DEVICE_ID_INTEL_IOAT_SNB2: - case PCI_DEVICE_ID_INTEL_IOAT_SNB3: - case PCI_DEVICE_ID_INTEL_IOAT_SNB4: - case PCI_DEVICE_ID_INTEL_IOAT_SNB5: - case PCI_DEVICE_ID_INTEL_IOAT_SNB6: - case PCI_DEVICE_ID_INTEL_IOAT_SNB7: - case PCI_DEVICE_ID_INTEL_IOAT_IVB0: - case PCI_DEVICE_ID_INTEL_IOAT_IVB1: - case PCI_DEVICE_ID_INTEL_IOAT_IVB2: - case PCI_DEVICE_ID_INTEL_IOAT_IVB3: - case PCI_DEVICE_ID_INTEL_IOAT_IVB4: - case PCI_DEVICE_ID_INTEL_IOAT_IVB5: - case PCI_DEVICE_ID_INTEL_IOAT_IVB6: - case PCI_DEVICE_ID_INTEL_IOAT_IVB7: - case PCI_DEVICE_ID_INTEL_IOAT_HSW0: - case PCI_DEVICE_ID_INTEL_IOAT_HSW1: - case PCI_DEVICE_ID_INTEL_IOAT_HSW2: - case PCI_DEVICE_ID_INTEL_IOAT_HSW3: - case PCI_DEVICE_ID_INTEL_IOAT_HSW4: - case PCI_DEVICE_ID_INTEL_IOAT_HSW5: - case PCI_DEVICE_ID_INTEL_IOAT_HSW6: - case PCI_DEVICE_ID_INTEL_IOAT_HSW7: - case PCI_DEVICE_ID_INTEL_IOAT_BDX0: - case PCI_DEVICE_ID_INTEL_IOAT_BDX1: - case PCI_DEVICE_ID_INTEL_IOAT_BDX2: - case PCI_DEVICE_ID_INTEL_IOAT_BDX3: - case PCI_DEVICE_ID_INTEL_IOAT_BDX4: - case PCI_DEVICE_ID_INTEL_IOAT_BDX5: - case PCI_DEVICE_ID_INTEL_IOAT_BDX6: - case PCI_DEVICE_ID_INTEL_IOAT_BDX7: - case PCI_DEVICE_ID_INTEL_IOAT_BDX8: - case PCI_DEVICE_ID_INTEL_IOAT_BDX9: - case PCI_DEVICE_ID_INTEL_IOAT_BWD0: - case PCI_DEVICE_ID_INTEL_IOAT_BWD1: - case PCI_DEVICE_ID_INTEL_IOAT_BWD2: - case PCI_DEVICE_ID_INTEL_IOAT_BWD3: - case PCI_DEVICE_ID_INTEL_IOAT_BDXDE0: - case PCI_DEVICE_ID_INTEL_IOAT_BDXDE1: - case PCI_DEVICE_ID_INTEL_IOAT_BDXDE2: - case PCI_DEVICE_ID_INTEL_IOAT_BDXDE3: - return true; - } - - return false; -} - -static int -ioat_pci_enum_cb(void *enum_ctx, struct spdk_pci_device *pci_dev) -{ - struct ioat_pci_enum_ctx *ctx = enum_ctx; - uint16_t vendor_id = spdk_pci_device_get_vendor_id(pci_dev); - uint16_t device_id = spdk_pci_device_get_device_id(pci_dev); - - if (!ioat_pci_device_match_id(vendor_id, device_id)) { - return 0; - } - - return ctx->user_enum_cb(ctx->user_enum_ctx, pci_dev); -} - -static inline int -ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - struct ioat_pci_enum_ctx ioat_enum_ctx; - - ioat_enum_ctx.user_enum_cb = enum_cb; - ioat_enum_ctx.user_enum_ctx = enum_ctx; - - return spdk_pci_enumerate(ioat_pci_enum_cb, &ioat_enum_ctx); -} - -static inline int -ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr) -{ - struct pci_device *dev = devhandle; - uint32_t flags = (read_only ? 0 : PCI_DEV_MAP_FLAG_WRITABLE); - - return pci_device_map_range(dev, dev->regions[bar].base_addr, 4096, - flags, mapped_addr); -} - -static inline int -ioat_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - struct pci_device *dev = devhandle; - - return pci_device_unmap_range(dev, addr, dev->regions[bar].size); -} - -#else /* !SPDK_CONFIG_PCIACCESS */ - -static inline int -ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr) -{ - struct rte_pci_device *dev = devhandle; - - *mapped_addr = dev->mem_resource[bar].addr; - return 0; -} - -static inline int -ioat_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - return 0; -} - -#define SPDK_IOAT_PCI_DEVICE(DEVICE_ID) RTE_PCI_DEVICE(SPDK_PCI_VID_INTEL, DEVICE_ID) - -/* TODO: avoid duplicating the device ID list */ -static struct rte_pci_id ioat_driver_id[] = { - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB1)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB4)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB5)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB6)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB7)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB8)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB1)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB4)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB5)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB6)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB7)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB8)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB9)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW4)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW5)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW6)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW7)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW8)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW9)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD1)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE1)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX0)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX1)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX2)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX3)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX4)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX5)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX6)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX7)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX8)}, - {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX9)}, - { .vendor_id = 0, /* sentinel */ }, -}; - -/* - * TODO: eliminate this global if possible (does rte_pci_driver have a context field for this?) - * - * This should be protected by the ioat driver lock, since ioat_probe() holds the lock - * the whole time, but we shouldn't have to depend on that. - */ -static struct ioat_pci_enum_ctx g_ioat_pci_enum_ctx; - -static int -ioat_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *rte_dev) -{ - /* - * These are actually the same type internally. - * TODO: refactor this so it's inside pci.c - */ - struct spdk_pci_device *pci_dev = (struct spdk_pci_device *)rte_dev; - - return g_ioat_pci_enum_ctx.user_enum_cb(g_ioat_pci_enum_ctx.user_enum_ctx, pci_dev); -} - -static struct rte_pci_driver ioat_rte_driver = { - .name = "ioat_driver", - .devinit = ioat_driver_init, - .id_table = ioat_driver_id, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING, -}; - -static inline int -ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - int rc; - - g_ioat_pci_enum_ctx.user_enum_cb = enum_cb; - g_ioat_pci_enum_ctx.user_enum_ctx = enum_ctx; - - rte_eal_pci_register(&ioat_rte_driver); - rc = rte_eal_pci_probe(); - rte_eal_pci_unregister(&ioat_rte_driver); - - return rc; -} - -#endif /* !SPDK_CONFIG_PCIACCESS */ - #endif /* __IOAT_IMPL_H__ */ diff --git a/lib/ioat/ioat_pci.h b/lib/ioat/ioat_pci.h deleted file mode 100644 index 3f6d4ffad..000000000 --- a/lib/ioat/ioat_pci.h +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * 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. - */ - -#ifndef __IOAT_PCI_H__ -#define __IOAT_PCI_H__ - -#include "spdk/pci_ids.h" - -#define PCI_DEVICE_ID_INTEL_IOAT_SNB0 0x3c20 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB1 0x3c21 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB2 0x3c22 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB3 0x3c23 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB4 0x3c24 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB5 0x3c25 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB6 0x3c26 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB7 0x3c27 -#define PCI_DEVICE_ID_INTEL_IOAT_SNB8 0x3c2e -#define PCI_DEVICE_ID_INTEL_IOAT_SNB9 0x3c2f - -#define PCI_DEVICE_ID_INTEL_IOAT_IVB0 0x0e20 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB1 0x0e21 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB2 0x0e22 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB3 0x0e23 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB4 0x0e24 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB5 0x0e25 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB6 0x0e26 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB7 0x0e27 -#define PCI_DEVICE_ID_INTEL_IOAT_IVB8 0x0e2e -#define PCI_DEVICE_ID_INTEL_IOAT_IVB9 0x0e2f - -#define PCI_DEVICE_ID_INTEL_IOAT_HSW0 0x2f20 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW1 0x2f21 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW2 0x2f22 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW3 0x2f23 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW4 0x2f24 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW5 0x2f25 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW6 0x2f26 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW7 0x2f27 -#define PCI_DEVICE_ID_INTEL_IOAT_HSW8 0x2f2e -#define PCI_DEVICE_ID_INTEL_IOAT_HSW9 0x2f2f - -#define PCI_DEVICE_ID_INTEL_IOAT_BWD0 0x0C50 -#define PCI_DEVICE_ID_INTEL_IOAT_BWD1 0x0C51 -#define PCI_DEVICE_ID_INTEL_IOAT_BWD2 0x0C52 -#define PCI_DEVICE_ID_INTEL_IOAT_BWD3 0x0C53 - -#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE0 0x6f50 -#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE1 0x6f51 -#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE2 0x6f52 -#define PCI_DEVICE_ID_INTEL_IOAT_BDXDE3 0x6f53 - -#define PCI_DEVICE_ID_INTEL_IOAT_BDX0 0x6f20 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX1 0x6f21 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX2 0x6f22 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX3 0x6f23 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX4 0x6f24 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX5 0x6f25 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX6 0x6f26 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX7 0x6f27 -#define PCI_DEVICE_ID_INTEL_IOAT_BDX8 0x6f2e -#define PCI_DEVICE_ID_INTEL_IOAT_BDX9 0x6f2f - -#endif /* __IOAT_PCI_H__ */ - diff --git a/lib/net/sock.c b/lib/net/sock.c index 69e25eb19..bd695110d 100644 --- a/lib/net/sock.c +++ b/lib/net/sock.c @@ -196,7 +196,7 @@ retry: case EADDRNOTAVAIL: SPDK_ERRLOG("IP address %s not available. " "Verify IP address in config file " - "and make sure unbind script is " + "and make sure setup script is " "run before starting spdk app.\n", ip); /* fallthrough */ default: diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 145bad8a7..d25ccb46b 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -291,7 +291,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a enum_ctx.probe_cb = probe_cb; enum_ctx.cb_ctx = cb_ctx; - rc = nvme_pci_enumerate(nvme_enum_cb, &enum_ctx); + rc = spdk_pci_enumerate(SPDK_PCI_DEVICE_NVME, nvme_enum_cb, &enum_ctx); /* * Keep going even if one or more nvme_attach() calls failed, * but maintain the value of rc to signal errors when we return. diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index f3d064410..8422ef994 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -982,17 +982,19 @@ nvme_ctrlr_map_cmb(struct spdk_nvme_ctrlr *ctrlr) /* controller memory buffer offset from BAR in Bytes */ offset = unit_size * cmbloc.bits.ofst; - nvme_pcicfg_get_bar_addr_len(ctrlr->devhandle, bir, &bar_phys_addr, &bar_size); - - if (offset > bar_size) + rc = spdk_pci_device_map_bar(ctrlr->devhandle, bir, &addr, + &bar_phys_addr, &bar_size); + if ((rc != 0) || addr == NULL) { goto exit; + } - if (size > bar_size - offset) + if (offset > bar_size) { goto exit; + } - rc = nvme_pcicfg_map_bar_write_combine(ctrlr->devhandle, bir, &addr); - if ((rc != 0) || addr == NULL) + if (size > bar_size - offset) { goto exit; + } ctrlr->cmb_bar_virt_addr = addr; ctrlr->cmb_bar_phys_addr = bar_phys_addr; @@ -1019,7 +1021,7 @@ nvme_ctrlr_unmap_cmb(struct spdk_nvme_ctrlr *ctrlr) if (addr) { cmbloc.raw = nvme_mmio_read_4(ctrlr, cmbloc.raw); - rc = nvme_pcicfg_unmap_bar(ctrlr->devhandle, cmbloc.bits.bir, addr); + rc = spdk_pci_device_unmap_bar(ctrlr->devhandle, cmbloc.bits.bir, addr); } return rc; } @@ -1047,8 +1049,10 @@ nvme_ctrlr_allocate_bars(struct spdk_nvme_ctrlr *ctrlr) { int rc; void *addr; + uint64_t phys_addr, size; - rc = nvme_pcicfg_map_bar(ctrlr->devhandle, 0, 0 /* writable */, &addr); + rc = spdk_pci_device_map_bar(ctrlr->devhandle, 0, &addr, + &phys_addr, &size); ctrlr->regs = (volatile struct spdk_nvme_registers *)addr; if ((ctrlr->regs == NULL) || (rc != 0)) { SPDK_ERRLOG("nvme_pcicfg_map_bar failed with rc %d or bar %p\n", @@ -1074,7 +1078,7 @@ nvme_ctrlr_free_bars(struct spdk_nvme_ctrlr *ctrlr) } if (addr) { - rc = nvme_pcicfg_unmap_bar(ctrlr->devhandle, 0, addr); + rc = spdk_pci_device_unmap_bar(ctrlr->devhandle, 0, addr); } return rc; } @@ -1114,9 +1118,9 @@ nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr, void *devhandle) } /* Enable PCI busmaster and disable INTx */ - nvme_pcicfg_read32(devhandle, &cmd_reg, 4); - cmd_reg |= 0x0404; - nvme_pcicfg_write32(devhandle, cmd_reg, 4); + spdk_pci_device_cfg_read32(devhandle, &cmd_reg, 4); + cmd_reg |= 0x404; + spdk_pci_device_cfg_write32(devhandle, cmd_reg, 4); cap.raw = nvme_mmio_read_8(ctrlr, cap.raw); diff --git a/lib/nvme/nvme_impl.h b/lib/nvme/nvme_impl.h index 537a8c59a..53bef1f7b 100644 --- a/lib/nvme/nvme_impl.h +++ b/lib/nvme/nvme_impl.h @@ -60,11 +60,7 @@ #include #include -#ifdef SPDK_CONFIG_PCIACCESS -#include -#else #include -#endif #include "spdk/pci_ids.h" @@ -212,174 +208,4 @@ nvme_mempool_put(nvme_mempool_t *mp, void *buf) */ #define nvme_get_tsc_hz() rte_get_timer_hz() -/** - * - */ -#define nvme_pcicfg_read32(handle, var, offset) spdk_pci_device_cfg_read32(handle, var, offset) -#define nvme_pcicfg_write32(handle, var, offset) spdk_pci_device_cfg_write32(handle, var, offset) - -struct nvme_pci_enum_ctx { - int (*user_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev); - void *user_enum_ctx; -}; - -#ifdef SPDK_CONFIG_PCIACCESS - -static int -nvme_pci_enum_cb(void *enum_ctx, struct spdk_pci_device *pci_dev) -{ - struct nvme_pci_enum_ctx *ctx = enum_ctx; - - if (spdk_pci_device_get_class(pci_dev) != SPDK_PCI_CLASS_NVME) { - return 0; - } - - return ctx->user_enum_cb(ctx->user_enum_ctx, pci_dev); -} - -static inline int -nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - struct nvme_pci_enum_ctx nvme_enum_ctx; - - nvme_enum_ctx.user_enum_cb = enum_cb; - nvme_enum_ctx.user_enum_ctx = enum_ctx; - - return spdk_pci_enumerate(nvme_pci_enum_cb, &nvme_enum_ctx); -} - -static inline int -nvme_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr) -{ - struct pci_device *dev = devhandle; - uint32_t flags = (read_only ? 0 : PCI_DEV_MAP_FLAG_WRITABLE); - - return pci_device_map_range(dev, dev->regions[bar].base_addr, dev->regions[bar].size, - flags, mapped_addr); -} - -static inline int -nvme_pcicfg_map_bar_write_combine(void *devhandle, uint32_t bar, void **mapped_addr) -{ - struct pci_device *dev = devhandle; - uint32_t flags = PCI_DEV_MAP_FLAG_WRITABLE | PCI_DEV_MAP_FLAG_WRITE_COMBINE; - - return pci_device_map_range(dev, dev->regions[bar].base_addr, dev->regions[bar].size, - flags, mapped_addr); -} - -static inline int -nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - struct pci_device *dev = devhandle; - - return pci_device_unmap_range(dev, addr, dev->regions[bar].size); -} - -static inline void -nvme_pcicfg_get_bar_addr_len(void *devhandle, uint32_t bar, uint64_t *addr, uint64_t *size) -{ - struct pci_device *dev = devhandle; - - *addr = (uint64_t)dev->regions[bar].base_addr; - *size = (uint64_t)dev->regions[bar].size; -} - -#else /* !SPDK_CONFIG_PCIACCESS */ - -static inline int -nvme_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr) -{ - struct rte_pci_device *dev = devhandle; - - *mapped_addr = dev->mem_resource[bar].addr; - return 0; -} - -static inline int -nvme_pcicfg_map_bar_write_combine(void *devhandle, uint32_t bar, void **mapped_addr) -{ - return -1; -} - -static inline int -nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - return 0; -} - -static inline void -nvme_pcicfg_get_bar_addr_len(void *devhandle, uint32_t bar, uint64_t *addr, uint64_t *size) -{ - struct rte_pci_device *dev = devhandle; - - *addr = (uint64_t)dev->mem_resource[bar].phys_addr; - *size = (uint64_t)dev->mem_resource[bar].len; -} - -static struct rte_pci_id nvme_pci_driver_id[] = { -#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 1) - { - .class_id = SPDK_PCI_CLASS_NVME, - .vendor_id = PCI_ANY_ID, - .device_id = PCI_ANY_ID, - .subsystem_vendor_id = PCI_ANY_ID, - .subsystem_device_id = PCI_ANY_ID, - }, -#else - {RTE_PCI_DEVICE(0x8086, 0x0953)}, -#endif - { .vendor_id = 0, /* sentinel */ }, -}; - -/* - * TODO: eliminate this global if possible (does rte_pci_driver have a context field for this?) - * - * This should be protected by the NVMe driver lock, since nvme_probe() holds the lock - * while calling nvme_pci_enumerate(), but we shouldn't have to depend on that. - */ -static struct nvme_pci_enum_ctx g_nvme_pci_enum_ctx; - -static int -nvme_driver_init(struct rte_pci_driver *dr, struct rte_pci_device *rte_dev) -{ - /* - * These are actually the same type internally. - * TODO: refactor this so it's inside pci.c - */ - struct spdk_pci_device *pci_dev = (struct spdk_pci_device *)rte_dev; - - /* - * TODO: This is a workaround for an issue where the device is not ready after VFIO reset. - * Figure out what is actually going wrong and remove this sleep. - */ - usleep(500 * 1000); - - return g_nvme_pci_enum_ctx.user_enum_cb(g_nvme_pci_enum_ctx.user_enum_ctx, pci_dev); -} - -static struct rte_pci_driver nvme_rte_driver = { - .name = "nvme_driver", - .devinit = nvme_driver_init, - .id_table = nvme_pci_driver_id, - .drv_flags = RTE_PCI_DRV_NEED_MAPPING, -}; - -static inline int -nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - int rc; - - g_nvme_pci_enum_ctx.user_enum_cb = enum_cb; - g_nvme_pci_enum_ctx.user_enum_ctx = enum_ctx; - - rte_eal_pci_register(&nvme_rte_driver); - rc = rte_eal_pci_probe(); - rte_eal_pci_unregister(&nvme_rte_driver); - - return rc; -} - -#endif /* !SPDK_CONFIG_PCIACCESS */ - #endif /* __NVME_IMPL_H__ */ diff --git a/lib/nvme/nvme_ns.c b/lib/nvme/nvme_ns.c index 086758f44..597005d39 100644 --- a/lib/nvme/nvme_ns.c +++ b/lib/nvme/nvme_ns.c @@ -191,7 +191,7 @@ int nvme_ns_construct(struct spdk_nvme_ns *ns, uint16_t id, ns->id = id; ns->stripe_size = 0; - nvme_pcicfg_read32(ctrlr->devhandle, &pci_devid, 0); + spdk_pci_device_cfg_read32(ctrlr->devhandle, &pci_devid, 0); if (pci_devid == INTEL_DC_P3X00_DEVID && ctrlr->cdata.vs[3] != 0) { ns->stripe_size = (1 << ctrlr->cdata.vs[3]) * ctrlr->min_page_size; } diff --git a/lib/util/pci.c b/lib/util/pci.c index 8d22a7729..58d9dc002 100644 --- a/lib/util/pci.c +++ b/lib/util/pci.c @@ -43,200 +43,171 @@ #include #include -#ifdef SPDK_CONFIG_PCIACCESS -#include -/* When using libpciaccess, struct spdk_pci_device * is actually struct pci_device * internally. */ -#define spdk_pci_device pci_device -#else +#include #include -/* When using DPDK PCI, struct spdk_pci_device * is actually struct rte_pci_device * internally. */ +#include + #define spdk_pci_device rte_pci_device -#endif #ifdef __FreeBSD__ #include #endif #include "spdk/pci.h" +#include "spdk/pci_ids.h" #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" #define SYSFS_PCI_DRIVERS "/sys/bus/pci/drivers" -#ifndef PCI_PRI_FMT /* This is defined by rte_pci.h when SPDK_CONFIG_PCIACCESS is not set */ -#define PCI_PRI_FMT "%04x:%02x:%02x.%1u" -#endif - #define SPDK_PCI_PATH_MAX 256 #define PCI_CFG_SIZE 256 #define PCI_EXT_CAP_ID_SN 0x03 -#define PCI_UIO_DRIVER "uio_pci_generic" -#ifdef SPDK_CONFIG_PCIACCESS +struct spdk_pci_enum_ctx { + struct rte_pci_driver driver; + spdk_pci_enum_cb enum_cb; + void *enum_ctx; +}; -/* - * libpciaccess wrapper functions - */ +static struct rte_pci_id nvme_pci_driver_id[] = { +#if RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 1) + { + .class_id = SPDK_PCI_CLASS_NVME, + .vendor_id = PCI_ANY_ID, + .device_id = PCI_ANY_ID, + .subsystem_vendor_id = PCI_ANY_ID, + .subsystem_device_id = PCI_ANY_ID, + }, +#else + {RTE_PCI_DEVICE(0x8086, 0x0953)}, +#endif + { .vendor_id = 0, /* sentinel */ }, +}; -static pthread_mutex_t g_pci_init_mutex = PTHREAD_MUTEX_INITIALIZER; -static bool g_pci_initialized = false; +#define SPDK_IOAT_PCI_DEVICE(DEVICE_ID) RTE_PCI_DEVICE(SPDK_PCI_VID_INTEL, DEVICE_ID) +static struct rte_pci_id ioat_driver_id[] = { + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB1)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB4)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB5)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB6)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB7)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_SNB8)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB1)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB4)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB5)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB6)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB7)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB8)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_IVB9)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW4)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW5)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW6)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW7)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW8)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_HSW9)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD1)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BWD3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE1)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDXDE3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX0)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX1)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX2)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX3)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX4)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX5)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX6)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX7)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX8)}, + {SPDK_IOAT_PCI_DEVICE(PCI_DEVICE_ID_INTEL_IOAT_BDX9)}, + { .vendor_id = 0, /* sentinel */ }, +}; static int -spdk_pci_init(void) +spdk_pci_device_init(struct rte_pci_driver *driver, + struct rte_pci_device *device) { + struct spdk_pci_enum_ctx *ctx = (struct spdk_pci_enum_ctx *)driver; + + if (device->kdrv == RTE_KDRV_VFIO) { + /* + * TODO: This is a workaround for an issue where the device is not ready after VFIO reset. + * Figure out what is actually going wrong and remove this sleep. + */ + usleep(500 * 1000); + } + + return ctx->enum_cb(ctx->enum_ctx, (struct spdk_pci_device *)device); +} + +static int +spdk_pci_device_fini(struct rte_pci_device *device) +{ + return 0; +} + +int +spdk_pci_enumerate(enum spdk_pci_device_type type, + spdk_pci_enum_cb enum_cb, + void *enum_ctx) +{ + struct spdk_pci_enum_ctx ctx = {}; int rc; - pthread_mutex_lock(&g_pci_init_mutex); + ctx.enum_cb = enum_cb; + ctx.enum_ctx = enum_ctx; + ctx.driver.devinit = spdk_pci_device_init; + ctx.driver.devuninit = spdk_pci_device_fini; + ctx.driver.drv_flags = RTE_PCI_DRV_NEED_MAPPING; - if (!g_pci_initialized) { - rc = pci_system_init(); - if (rc == 0) { - g_pci_initialized = true; - } + if (type == SPDK_PCI_DEVICE_NVME) { + ctx.driver.name = "SPDK NVMe"; + ctx.driver.id_table = nvme_pci_driver_id; + } else if (type == SPDK_PCI_DEVICE_IOAT) { + ctx.driver.id_table = ioat_driver_id; + ctx.driver.name = "SPDK IOAT"; } else { - rc = 0; + return -1; } - pthread_mutex_unlock(&g_pci_init_mutex); + rte_eal_pci_register(&ctx.driver); + rc = rte_eal_pci_probe(); + rte_eal_pci_unregister(&ctx.driver); return rc; } -uint16_t -spdk_pci_device_get_domain(struct spdk_pci_device *dev) +int +spdk_pci_device_map_bar(struct spdk_pci_device *device, uint32_t bar, + void **mapped_addr, uint64_t *phys_addr, uint64_t *size) { - return dev->domain; -} + struct rte_pci_device *dev = device; -uint8_t -spdk_pci_device_get_bus(struct spdk_pci_device *dev) -{ - return dev->bus; -} + *mapped_addr = dev->mem_resource[bar].addr; + *phys_addr = (uint64_t)dev->mem_resource[bar].phys_addr; + *size = (uint64_t)dev->mem_resource[bar].len; - -uint8_t -spdk_pci_device_get_dev(struct spdk_pci_device *dev) -{ - return dev->dev; -} - -uint8_t -spdk_pci_device_get_func(struct spdk_pci_device *dev) -{ - return dev->func; -} - -uint16_t -spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev) -{ - return dev->vendor_id; -} - -uint16_t -spdk_pci_device_get_device_id(struct spdk_pci_device *dev) -{ - return dev->device_id; -} - -uint16_t -spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev) -{ - return dev->subvendor_id; -} - -uint16_t -spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev) -{ - return dev->subdevice_id; -} - -uint32_t -spdk_pci_device_get_class(struct spdk_pci_device *dev) -{ - return dev->device_class; -} - -const char * -spdk_pci_device_get_device_name(struct spdk_pci_device *dev) -{ - return pci_device_get_device_name(dev); + return 0; } int -spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset) +spdk_pci_device_unmap_bar(struct spdk_pci_device *device, uint32_t bar, void *addr) { - return pci_device_cfg_read_u8(dev, value, offset); + return 0; } -int -spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset) -{ - return pci_device_cfg_write_u8(dev, value, offset); -} - -int -spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset) -{ - return pci_device_cfg_read_u16(dev, value, offset); -} - -int -spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset) -{ - return pci_device_cfg_write_u16(dev, value, offset); -} - -int -spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset) -{ - return pci_device_cfg_read_u32(dev, value, offset); -} - -int -spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset) -{ - return pci_device_cfg_write_u32(dev, value, offset); -} - -int -spdk_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - struct pci_device_iterator *pci_dev_iter; - struct pci_device *pci_dev; - struct pci_slot_match match; - int rc; - - rc = spdk_pci_init(); - if (rc != 0) { - return rc; - } - - match.domain = PCI_MATCH_ANY; - match.bus = PCI_MATCH_ANY; - match.dev = PCI_MATCH_ANY; - match.func = PCI_MATCH_ANY; - - pci_dev_iter = pci_slot_match_iterator_create(&match); - - rc = 0; - while ((pci_dev = pci_device_next(pci_dev_iter))) { - pci_device_probe(pci_dev); - if (enum_cb(enum_ctx, pci_dev)) { - rc = -1; - } - } - - pci_iterator_destroy(pci_dev_iter); - - return rc; -} - -#else /* !SPDK_CONFIG_PCIACCESS */ - -/* - * DPDK PCI wrapper functions - */ - static int pci_device_get_u32(struct spdk_pci_device *dev, const char *file, uint32_t *val) { @@ -374,9 +345,6 @@ spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_ return rte_eal_pci_write_config(dev, &value, 4, offset) == 4 ? 0 : -1; } -#endif /* !SPDK_CONFIG_PCIACCESS */ - - int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len) { @@ -418,160 +386,6 @@ spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t } #ifdef __linux__ -int -spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev) -{ - char linkname[SPDK_PCI_PATH_MAX]; - char driver[SPDK_PCI_PATH_MAX]; - ssize_t driver_len; - char *driver_begin; - - snprintf(linkname, sizeof(linkname), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver", - spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), spdk_pci_device_get_func(dev)); - - driver_len = readlink(linkname, driver, sizeof(driver)); - - if (driver_len < 0 || driver_len >= SPDK_PCI_PATH_MAX) { - return 0; - } - - driver[driver_len] = '\0'; /* readlink() doesn't null terminate, so we have to */ - - driver_begin = strrchr(driver, '/'); - if (driver_begin) { - /* Advance to the character after the slash */ - driver_begin++; - } else { - /* This shouldn't normally happen - driver should be a relative path with slashes */ - driver_begin = driver; - } - - return (strncmp(driver_begin, "uio_", 4) != 0 && - strcmp(driver_begin, "vfio-pci") != 0); -} - - -int -spdk_pci_device_unbind_kernel_driver(struct spdk_pci_device *dev) -{ - int n; - FILE *fd; - char filename[SPDK_PCI_PATH_MAX]; - char buf[256]; - - snprintf(filename, sizeof(filename), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind", - spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), spdk_pci_device_get_func(dev)); - - fd = fopen(filename, "w"); - if (!fd) - return 0; - - n = snprintf(buf, sizeof(buf), PCI_PRI_FMT, - spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), spdk_pci_device_get_dev(dev)); - - if (fwrite(buf, n, 1, fd) == 0) - goto error; - - fclose(fd); - return 0; - -error: - fclose(fd); - return -1; -} - -static int -check_modules(const char *driver_name) -{ - FILE *fd; - const char *proc_modules = "/proc/modules"; - char buffer[256]; - - fd = fopen(proc_modules, "r"); - if (!fd) - return -1; - - while (fgets(buffer, sizeof(buffer), fd)) { - if (strstr(buffer, driver_name) == NULL) - continue; - else { - fclose(fd); - return 0; - } - } - fclose(fd); - - return -1; -} - -int -spdk_pci_device_bind_uio_driver(struct spdk_pci_device *dev) -{ - int err, n; - FILE *fd; - char filename[SPDK_PCI_PATH_MAX]; - char buf[256]; - const char *driver_name = PCI_UIO_DRIVER; - - err = check_modules(driver_name); - if (err < 0) { - fprintf(stderr, "No %s module loaded\n", driver_name); - return err; - } - - snprintf(filename, sizeof(filename), - SYSFS_PCI_DRIVERS "/" "%s" "/new_id", driver_name); - - fd = fopen(filename, "w"); - if (!fd) { - return -1; - } - - n = snprintf(buf, sizeof(buf), "%04x %04x", - spdk_pci_device_get_vendor_id(dev), - spdk_pci_device_get_device_id(dev)); - - if (fwrite(buf, n, 1, fd) == 0) - goto error; - - fclose(fd); - return 0; - -error: - fclose(fd); - return -1; -} - -int -spdk_pci_device_switch_to_uio_driver(struct spdk_pci_device *dev) -{ - if (spdk_pci_device_unbind_kernel_driver(dev)) { - fprintf(stderr, "Device %d:%d:%d unbind from " - "kernel driver failed\n", - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - return -1; - } - if (spdk_pci_device_bind_uio_driver(dev)) { - fprintf(stderr, "Device %d:%d:%d bind to " - "uio driver failed\n", - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - return -1; - } - printf("Device %d:%d:%d bind to uio driver success\n", - spdk_pci_device_get_bus(dev), spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - return 0; -} - int spdk_pci_device_claim(struct spdk_pci_device *dev) { @@ -627,78 +441,6 @@ spdk_pci_device_claim(struct spdk_pci_device *dev) #endif /* __linux__ */ #ifdef __FreeBSD__ -int -spdk_pci_device_has_non_uio_driver(struct spdk_pci_device *dev) -{ - struct pci_conf_io configsel; - struct pci_match_conf pattern; - struct pci_conf conf; - int fd; - - memset(&pattern, 0, sizeof(pattern)); - pattern.pc_sel.pc_domain = spdk_pci_device_get_domain(dev); - pattern.pc_sel.pc_bus = spdk_pci_device_get_bus(dev); - pattern.pc_sel.pc_dev = spdk_pci_device_get_dev(dev); - pattern.pc_sel.pc_func = spdk_pci_device_get_func(dev); - pattern.flags = PCI_GETCONF_MATCH_DOMAIN | - PCI_GETCONF_MATCH_BUS | - PCI_GETCONF_MATCH_DEV | - PCI_GETCONF_MATCH_FUNC; - - memset(&configsel, 0, sizeof(configsel)); - configsel.match_buf_len = sizeof(conf); - configsel.matches = &conf; - configsel.num_patterns = 1; - configsel.pat_buf_len = sizeof(pattern); - configsel.patterns = &pattern; - - fd = open("/dev/pci", O_RDONLY, 0); - if (fd < 0) { - fprintf(stderr, "could not open /dev/pci\n"); - return -1; - } - - if (ioctl(fd, PCIOCGETCONF, &configsel) == -1) { - fprintf(stderr, "ioctl(PCIOCGETCONF) failed\n"); - close(fd); - return -1; - } - - close(fd); - - if (configsel.num_matches != 1) { - fprintf(stderr, "could not find specified device\n"); - return -1; - } - - if (conf.pd_name[0] == '\0' || !strcmp(conf.pd_name, "nic_uio")) { - return 0; - } else { - return 1; - } -} - -int -spdk_pci_device_unbind_kernel_driver(struct spdk_pci_device *dev) -{ - /* TODO */ - return 0; -} - -int -spdk_pci_device_bind_uio_driver(struct spdk_pci_device *dev) -{ - /* TODO */ - return 0; -} - -int -spdk_pci_device_switch_to_uio_driver(struct spdk_pci_device *dev) -{ - /* TODO */ - return 0; -} - int spdk_pci_device_claim(struct spdk_pci_device *dev) { diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index 368e9d5f1..e2ab050be 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -93,10 +93,6 @@ LDFLAGS += --coverage endif endif -ifeq ($(CONFIG_PCIACCESS), y) -PCIACCESS_LIB=-lpciaccess -endif - CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -Wstrict-prototypes -Wold-style-definition -std=gnu99 CXXFLAGS += $(COMMON_CFLAGS) -std=c++0x diff --git a/scripts/setup.sh b/scripts/setup.sh index 64e0c8195..5f2f732f7 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -56,7 +56,7 @@ function configure_linux { # IOAT TMP=`mktemp` #collect all the device_id info of ioat devices. - grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/lib/ioat/ioat_pci.h \ + grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \ | awk -F"x" '{print $2}' > $TMP for dev_id in `cat $TMP`; do @@ -110,7 +110,7 @@ function reset_linux { # IOAT TMP=`mktemp` #collect all the device_id info of ioat devices. - grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/lib/ioat/ioat_pci.h \ + grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \ | awk -F"x" '{print $2}' > $TMP modprobe ioatdma || true @@ -127,10 +127,22 @@ function reset_linux { function configure_freebsd { TMP=`mktemp` + + # NVMe + GREP_STR="class=0x010802" + + # IOAT + grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \ + | awk -F"x" '{print $2}' > $TMP + for dev_id in `cat $TMP`; do + GREP_STR="${GREP_STR}\|chip=0x${dev_id}8086" + done + AWK_PROG="{if (count > 0) printf \",\"; printf \"%s:%s:%s\",\$2,\$3,\$4; count++}" echo $AWK_PROG > $TMP - PCICONF=`pciconf -l | grep 'class=0x010802\|^ioat'` - BDFS=`echo $PCICONF | awk -F: -f $TMP` + + BDFS=`pciconf -l | grep "${GREP_STR}" | awk -F: -f $TMP` + kldunload nic_uio.ko || true kenv hw.nic_uio.bdfs=$BDFS kldload nic_uio.ko diff --git a/test/iscsi_tgt/fio/iscsi.conf b/test/iscsi_tgt/fio/iscsi.conf index 723adf940..fd9430e75 100644 --- a/test/iscsi_tgt/fio/iscsi.conf +++ b/test/iscsi_tgt/fio/iscsi.conf @@ -15,4 +15,3 @@ [Nvme] NvmeLunsPerNs 1 - UnbindFromKernel Yes diff --git a/test/lib/bdev/bdev.conf b/test/lib/bdev/bdev.conf index 43085a292..73cf65436 100644 --- a/test/lib/bdev/bdev.conf +++ b/test/lib/bdev/bdev.conf @@ -1,9 +1,8 @@ [Nvme] NvmeLunsPerNs 1 - UnbindFromKernel Yes # autotest.sh will automatically rmmod ioatdma, so we do -# not need to specify UnbindFromKernel and Whitelist +# not need to specify Whitelist # entries to enable ioat offload for this malloc LUN [Malloc] NumberOfLuns 5 diff --git a/test/lib/bdev/bdevio/Makefile b/test/lib/bdev/bdevio/Makefile index 675218804..11c40e03b 100644 --- a/test/lib/bdev/bdevio/Makefile +++ b/test/lib/bdev/bdevio/Makefile @@ -56,7 +56,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/bdev/libspdk_bdev.a \ LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \ $(COPY_MODULES_LINKER_ARGS) -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) -lcunit +LIBS += $(SPDK_LIBS) $(DPDK_LIB) -lcunit all : $(APP) diff --git a/test/lib/bdev/bdevperf/Makefile b/test/lib/bdev/bdevperf/Makefile index 5a463662f..e182b2462 100644 --- a/test/lib/bdev/bdevperf/Makefile +++ b/test/lib/bdev/bdevperf/Makefile @@ -56,7 +56,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/bdev/libspdk_bdev.a \ LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \ $(COPY_MODULES_LINKER_ARGS) -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/test/lib/ioat/unit/ioat_impl.h b/test/lib/ioat/unit/ioat_impl.h index a8b2ba640..ddfa43c13 100644 --- a/test/lib/ioat/unit/ioat_impl.h +++ b/test/lib/ioat/unit/ioat_impl.h @@ -25,27 +25,4 @@ ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr) #define ioat_vtophys(buf) (uint64_t)(buf) #define ioat_delay_us(us) ioat_noop() -static inline int -ioat_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - return -1; -} - -#define ioat_pcicfg_read32(handle, var, offset) do { *(var) = 0xFFFFFFFFu; } while (0) -#define ioat_pcicfg_write32(handle, var, offset) do { (void)(var); } while (0) - -static inline int -ioat_pcicfg_map_bar(void *devhandle, uint32_t bar, uint32_t read_only, void **mapped_addr) -{ - /* TODO */ - *mapped_addr = NULL; - return -1; -} - -static inline int -ioat_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - return 0; -} - #endif /* __IOAT_IMPL_H__ */ diff --git a/test/lib/ioat/unit/ioat_ut.c b/test/lib/ioat/unit/ioat_ut.c index ff9bb82d2..0425a4cc7 100644 --- a/test/lib/ioat/unit/ioat_ut.c +++ b/test/lib/ioat/unit/ioat_ut.c @@ -35,6 +35,45 @@ #include "ioat/ioat.c" +int +spdk_pci_enumerate(enum spdk_pci_device_type type, + spdk_pci_enum_cb enum_cb, + void *enum_ctx) +{ + return -1; +} + +int +spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, + void **mapped_addr, uint64_t *phys_addr, uint64_t *size) +{ + *mapped_addr = NULL; + *phys_addr = 0; + *size = 0; + return 0; +} + +int +spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr) +{ + return 0; +} + +int +spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, + uint32_t offset) +{ + *value = 0xFFFFFFFFu; + return 0; +} + +int +spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, + uint32_t offset) +{ + return 0; +} + static void ioat_state_check(void) { /* diff --git a/test/lib/nvme/aer/Makefile b/test/lib/nvme/aer/Makefile index 3466d568f..fcae5a2c4 100644 --- a/test/lib/nvme/aer/Makefile +++ b/test/lib/nvme/aer/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/test/lib/nvme/aer/aer.c b/test/lib/nvme/aer/aer.c index d6f696a53..25a523580 100644 --- a/test/lib/nvme/aer/aer.c +++ b/test/lib/nvme/aer/aer.c @@ -188,17 +188,6 @@ static void aer_cb(void *arg, const struct spdk_nvme_cpl *cpl) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - printf("Attaching to %04x:%02x:%02x.%02x\n", spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), diff --git a/test/lib/nvme/e2edp/Makefile b/test/lib/nvme/e2edp/Makefile index fc62f9200..602b489ad 100644 --- a/test/lib/nvme/e2edp/Makefile +++ b/test/lib/nvme/e2edp/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/test/lib/nvme/e2edp/nvme_dp.c b/test/lib/nvme/e2edp/nvme_dp.c index 01f65958d..8b2180a31 100644 --- a/test/lib/nvme/e2edp/nvme_dp.c +++ b/test/lib/nvme/e2edp/nvme_dp.c @@ -520,17 +520,6 @@ write_read_e2e_dp_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, con static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - printf("Attaching to %04x:%02x:%02x.%02x\n", spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), diff --git a/test/lib/nvme/overhead/Makefile b/test/lib/nvme/overhead/Makefile index 099e13963..ed22bae27 100644 --- a/test/lib/nvme/overhead/Makefile +++ b/test/lib/nvme/overhead/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) ifeq ($(OS),Linux) LIBS += -laio diff --git a/test/lib/nvme/overhead/overhead.c b/test/lib/nvme/overhead/overhead.c index 750a86a8f..bb598e646 100644 --- a/test/lib/nvme/overhead/overhead.c +++ b/test/lib/nvme/overhead/overhead.c @@ -533,17 +533,6 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts { static uint32_t ctrlr_found = 0; - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - if (ctrlr_found == 1) { fprintf(stderr, "only attching to one controller, so skipping\n"); fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", diff --git a/test/lib/nvme/reset/Makefile b/test/lib/nvme/reset/Makefile index 147ae7a51..7fd1d1eb9 100644 --- a/test/lib/nvme/reset/Makefile +++ b/test/lib/nvme/reset/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/test/lib/nvme/reset/reset.c b/test/lib/nvme/reset/reset.c index 4210c40ef..2f8e6acde 100644 --- a/test/lib/nvme/reset/reset.c +++ b/test/lib/nvme/reset/reset.c @@ -512,17 +512,6 @@ register_workers(void) static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - return true; } diff --git a/test/lib/nvme/sgl/Makefile b/test/lib/nvme/sgl/Makefile index 928c72857..328e7f0f5 100644 --- a/test/lib/nvme/sgl/Makefile +++ b/test/lib/nvme/sgl/Makefile @@ -45,7 +45,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a \ $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) all : $(APP) diff --git a/test/lib/nvme/sgl/nvme_sgl.c b/test/lib/nvme/sgl/nvme_sgl.c index 3decc5bd5..195320324 100644 --- a/test/lib/nvme/sgl/nvme_sgl.c +++ b/test/lib/nvme/sgl/nvme_sgl.c @@ -367,17 +367,6 @@ writev_readv_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, const ch static bool probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts) { - if (spdk_pci_device_has_non_uio_driver(dev)) { - fprintf(stderr, "non-uio kernel driver attached to NVMe\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - spdk_pci_device_get_domain(dev), - spdk_pci_device_get_bus(dev), - spdk_pci_device_get_dev(dev), - spdk_pci_device_get_func(dev)); - fprintf(stderr, " skipping...\n"); - return false; - } - printf("Attaching to %04x:%02x:%02x.%02x\n", spdk_pci_device_get_domain(dev), spdk_pci_device_get_bus(dev), diff --git a/test/lib/nvme/unit/nvme_c/nvme_ut.c b/test/lib/nvme/unit/nvme_c/nvme_ut.c index 2137b3cd6..39fd49f12 100644 --- a/test/lib/nvme/unit/nvme_c/nvme_ut.c +++ b/test/lib/nvme/unit/nvme_c/nvme_ut.c @@ -33,8 +33,18 @@ #include "spdk_cunit.h" +#include "spdk/pci.h" + #include "nvme/nvme.c" +int +spdk_pci_enumerate(enum spdk_pci_device_type type, + spdk_pci_enum_cb enum_cb, + void *enum_ctx) +{ + return -1; +} + uint64_t nvme_vtophys(void *buf) { return (uintptr_t)buf; diff --git a/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c b/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c index 89b2729a2..c52fc0251 100644 --- a/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c +++ b/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c @@ -55,6 +55,37 @@ struct spdk_nvme_registers g_ut_nvme_regs = {}; __thread int nvme_thread_ioq_index = -1; +int +spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, + void **mapped_addr, uint64_t *phys_addr, uint64_t *size) +{ + *mapped_addr = &g_ut_nvme_regs; + *phys_addr = (uintptr_t)&g_ut_nvme_regs; + *size = sizeof(g_ut_nvme_regs); + return 0; +} + +int +spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr) +{ + return 0; +} + +int +spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, + uint32_t offset) +{ + *value = 0xFFFFFFFFu; + return 0; +} + +int +spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, + uint32_t offset) +{ + return 0; +} + uint16_t spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev) { diff --git a/test/lib/nvme/unit/nvme_impl.h b/test/lib/nvme/unit/nvme_impl.h index 534908029..0bf6e9698 100644 --- a/test/lib/nvme/unit/nvme_impl.h +++ b/test/lib/nvme/unit/nvme_impl.h @@ -67,45 +67,6 @@ extern uint64_t g_ut_tsc; #define nvme_get_tsc() (g_ut_tsc) #define nvme_get_tsc_hz() (1000000) -static inline int -nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx) -{ - /* TODO: enumeration is not needed in any unit tests yet, so it's not implemented */ - return -1; -} - -#define nvme_pcicfg_read32(handle, var, offset) do { *(var) = 0xFFFFFFFFu; } while (0) -#define nvme_pcicfg_write32(handle, var, offset) do { (void)(var); } while (0) - -extern struct spdk_nvme_registers g_ut_nvme_regs; - -static inline -int nvme_pcicfg_map_bar(void *pci_handle, int bar, int read_only, void **addr) -{ - *addr = &g_ut_nvme_regs; - return 0; -} - -static inline int -nvme_pcicfg_map_bar_write_combine(void *devhandle, uint32_t bar, void **addr) -{ - *addr = &g_ut_nvme_regs; - return 0; -} - -static inline int -nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) -{ - return 0; -} - -static inline void -nvme_pcicfg_get_bar_addr_len(void *devhandle, uint32_t bar, uint64_t *addr, uint64_t *size) -{ - *addr = 0; - *size = 0; -} - static inline void * nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) { 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 9d0a91754..a65308128 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 @@ -38,6 +38,14 @@ struct nvme_request *g_request = NULL; +int +spdk_pci_enumerate(enum spdk_pci_device_type type, + spdk_pci_enum_cb enum_cb, + void *enum_ctx) +{ + return -1; +} + static void nvme_request_reset_sgl(void *cb_arg, uint32_t sgl_offset) { } diff --git a/test/lib/nvmf/nvmf/Makefile b/test/lib/nvmf/nvmf/Makefile index 53f70bc52..2582b6332 100644 --- a/test/lib/nvmf/nvmf/Makefile +++ b/test/lib/nvmf/nvmf/Makefile @@ -40,7 +40,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ $(SPDK_ROOT_DIR)/lib/trace/libspdk_trace.a \ $(SPDK_ROOT_DIR)/lib/event/libspdk_event.a \ -LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) $(DPDK_LIB) +LIBS += $(SPDK_LIBS) $(DPDK_LIB) TEST_FILE = nvmf_ut.c diff --git a/unittest.sh b/unittest.sh index f4b837594..f5258bfd3 100755 --- a/unittest.sh +++ b/unittest.sh @@ -39,7 +39,7 @@ test/lib/nvmf/request/request_ut test/lib/nvmf/session/session_ut test/lib/nvmf/subsystem/subsystem_ut -# TODO: allow lib/util to build without DPDK/libpciaccess +# TODO: allow lib/util to build without DPDK #make -C test/lib/scsi CONFIG_WERROR=y make -C test/lib/scsi/dev CONFIG_WERROR=y make -C test/lib/scsi/lun CONFIG_WERROR=y