From 671da58caff38584a644b77e15608ccac2589eb0 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Thu, 21 Sep 2017 18:59:10 +0200 Subject: [PATCH] env/pci: added pci_device_cfg read/write New functions for reading/writing any length of data. Also simplified specific 8/16/32-bit reads/writes. Change-Id: I518cdb3ce8d27a25353e80f2e7ca21162b0bd12b Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/379487 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- include/spdk/env.h | 4 +++ lib/env_dpdk/pci.c | 62 ++++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index 4a7c8da63..1acaae88f 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -341,6 +341,10 @@ int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx, struct spdk_pci_addr *pci_address); +int spdk_pci_device_cfg_read(struct spdk_pci_device *dev, void *value, uint32_t len, + uint32_t offset); +int spdk_pci_device_cfg_write(struct spdk_pci_device *dev, void *value, uint32_t len, + uint32_t offset); 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); int spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset); diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 7f1691427..df2f289f8 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -306,64 +306,66 @@ spdk_pci_device_get_socket_id(struct spdk_pci_device *pci_dev) #endif } +int +spdk_pci_device_cfg_read(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t offset) +{ + int rc; + +#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) + rc = rte_pci_read_config(dev, value, len, offset); +#else + rc = rte_eal_pci_read_config(dev, value, len, offset); +#endif + return (rc > 0 && (uint32_t) rc == len) ? 0 : -1; +} + +int +spdk_pci_device_cfg_write(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t offset) +{ + int rc; + +#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) + rc = rte_pci_write_config(dev, value, len, offset); +#else + rc = rte_eal_pci_write_config(dev, value, len, offset); +#endif + return (rc > 0 && (uint32_t) rc == len) ? 0 : -1; +} + int spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_read_config(dev, value, 1, offset) == 1 ? 0 : -1; -#else - return rte_eal_pci_read_config(dev, value, 1, offset) == 1 ? 0 : -1; -#endif + return spdk_pci_device_cfg_read(dev, value, 1, offset); } int spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_write_config(dev, &value, 1, offset) == 1 ? 0 : -1; -#else - return rte_eal_pci_write_config(dev, &value, 1, offset) == 1 ? 0 : -1; -#endif + return spdk_pci_device_cfg_write(dev, &value, 1, offset); } int spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_read_config(dev, value, 2, offset) == 2 ? 0 : -1; -#else - return rte_eal_pci_read_config(dev, value, 2, offset) == 2 ? 0 : -1; -#endif + return spdk_pci_device_cfg_read(dev, value, 2, offset); } int spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_write_config(dev, &value, 2, offset) == 2 ? 0 : -1; -#else - return rte_eal_pci_write_config(dev, &value, 2, offset) == 2 ? 0 : -1; -#endif + return spdk_pci_device_cfg_write(dev, &value, 2, offset); } int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_read_config(dev, value, 4, offset) == 4 ? 0 : -1; -#else - return rte_eal_pci_read_config(dev, value, 4, offset) == 4 ? 0 : -1; -#endif + return spdk_pci_device_cfg_read(dev, value, 4, offset); } int spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset) { -#if RTE_VERSION >= RTE_VERSION_NUM(17, 05, 0, 4) - return rte_pci_write_config(dev, &value, 4, offset) == 4 ? 0 : -1; -#else - return rte_eal_pci_write_config(dev, &value, 4, offset) == 4 ? 0 : -1; -#endif + return spdk_pci_device_cfg_write(dev, &value, 4, offset); } int