diff --git a/CONFIG b/CONFIG index ddce2cf3bd..7a1c320434 100644 --- a/CONFIG +++ b/CONFIG @@ -49,3 +49,8 @@ CONFIG_NVME_IMPL?=nvme_impl.h # Header file to use for IOAT implementation specific functions. # 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 diff --git a/examples/ioat/perf/Makefile b/examples/ioat/perf/Makefile index 6baf3023fa..b21d1c1056 100644 --- a/examples/ioat/perf/Makefile +++ b/examples/ioat/perf/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/ioat/libspdk_ioat.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all: $(APP) diff --git a/examples/ioat/verify/Makefile b/examples/ioat/verify/Makefile index 9d7a72d65c..c0502be906 100644 --- a/examples/ioat/verify/Makefile +++ b/examples/ioat/verify/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/ioat/libspdk_ioat.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all: $(APP) diff --git a/examples/nvme/identify/Makefile b/examples/nvme/identify/Makefile index 0091d6ebf2..4a40d8f47b 100644 --- a/examples/nvme/identify/Makefile +++ b/examples/nvme/identify/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all : $(APP) diff --git a/examples/nvme/perf/Makefile b/examples/nvme/perf/Makefile index b7c7601705..4a9dd7a808 100644 --- a/examples/nvme/perf/Makefile +++ b/examples/nvme/perf/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt ifeq ($(OS),Linux) LIBS += -laio diff --git a/examples/nvme/reserve/Makefile b/examples/nvme/reserve/Makefile index 7583f43e61..eba3e22887 100644 --- a/examples/nvme/reserve/Makefile +++ b/examples/nvme/reserve/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all : $(APP) diff --git a/include/spdk/pci.h b/include/spdk/pci.h index 59867f00cf..402986a405 100644 --- a/include/spdk/pci.h +++ b/include/spdk/pci.h @@ -34,6 +34,7 @@ #ifndef SPDK_PCI_H #define SPDK_PCI_H +#ifdef USE_PCIACCESS #define spdk_pci_device_get_domain(dev) (dev->domain) #define spdk_pci_device_get_bus(dev) (dev->bus) #define spdk_pci_device_get_dev(pdev) (pdev->dev) @@ -42,6 +43,7 @@ #define spdk_pci_device_get_device_id(dev) (dev->device_id) #define spdk_pci_device_get_subvendor_id(dev) (dev->subvendor_id) #define spdk_pci_device_get_subdevice_id(dev) (dev->subdevice_id) +#endif #define PCI_CFG_SIZE 256 #define PCI_EXT_CAP_ID_SN 0x03 diff --git a/lib/ioat/ioat_impl.h b/lib/ioat/ioat_impl.h index 1224a2741d..891436790c 100644 --- a/lib/ioat/ioat_impl.h +++ b/lib/ioat/ioat_impl.h @@ -60,6 +60,7 @@ ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr) */ #define ioat_printf(chan, fmt, args...) printf(fmt, ##args) +#ifdef USE_PCIACCESS /** * */ @@ -83,6 +84,7 @@ ioat_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) return pci_device_unmap_range(dev, addr, dev->regions[bar].size); } +#endif typedef pthread_mutex_t ioat_mutex_t; diff --git a/lib/nvme/nvme_impl.h b/lib/nvme/nvme_impl.h index 89310d0193..c176c6d93a 100644 --- a/lib/nvme/nvme_impl.h +++ b/lib/nvme/nvme_impl.h @@ -117,6 +117,7 @@ extern struct rte_mempool *request_mempool; */ #define nvme_dealloc_request(buf) rte_mempool_put(request_mempool, buf) +#ifdef USE_PCIACCESS static inline int nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, void *pci_dev), void *enum_ctx) { @@ -171,6 +172,7 @@ nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr) return pci_device_unmap_range(dev, addr, dev->regions[bar].size); } +#endif typedef pthread_mutex_t nvme_mutex_t; diff --git a/lib/util/pci.c b/lib/util/pci.c index 6651ece07b..7360366c95 100644 --- a/lib/util/pci.c +++ b/lib/util/pci.c @@ -54,10 +54,11 @@ #define PCI_PRI_FMT "%04x:%02x:%02x.%1u" #define SPDK_PCI_PATH_MAX 256 - +#ifdef USE_PCIACCESS /* var should be the pointer */ #define spdk_pcicfg_read32(handle, var, offset) pci_device_cfg_read_u32(handle, var, offset) #define spdk_pcicfg_write32(handle, var, offset) pci_device_cfg_write_u32(handle, *var, offset) +#endif int pci_device_get_serial_number(struct pci_device *dev, char *sn, int len) diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index 16ab059847..cb5dc43079 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -84,6 +84,12 @@ LDFLAGS += --coverage endif endif +ifeq ($(CONFIG_PCIACCESS), y) +PCIACCESS_LIB=-lpciaccess +SPDK_PCIACCESS_CFLAGS=-DUSE_PCIACCESS +COMMON_CFLAGS += $(SPDK_PCIACCESS_CFLAGS) +endif + CFLAGS += $(COMMON_CFLAGS) -Wno-pointer-sign -std=gnu99 MAKEFLAGS += --no-print-directory diff --git a/test/lib/nvme/aer/Makefile b/test/lib/nvme/aer/Makefile index 09e5f5d2b8..dc789c24cf 100644 --- a/test/lib/nvme/aer/Makefile +++ b/test/lib/nvme/aer/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all : $(APP) diff --git a/test/lib/nvme/reset/Makefile b/test/lib/nvme/reset/Makefile index 60134410cf..5b952ce53c 100644 --- a/test/lib/nvme/reset/Makefile +++ b/test/lib/nvme/reset/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt OBJS = $(C_SRCS:.c=.o) diff --git a/test/lib/nvme/sgl/Makefile b/test/lib/nvme/sgl/Makefile index 7e8e291313..618f395f47 100644 --- a/test/lib/nvme/sgl/Makefile +++ b/test/lib/nvme/sgl/Makefile @@ -44,7 +44,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/nvme/libspdk_nvme.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a \ $(SPDK_ROOT_DIR)/lib/memory/libspdk_memory.a -LIBS += $(SPDK_LIBS) -lpciaccess -lpthread $(DPDK_LIB) -lrt +LIBS += $(SPDK_LIBS) $(PCIACCESS_LIB) -lpthread $(DPDK_LIB) -lrt all : $(APP)