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 <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/379487
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-09-21 18:59:10 +02:00 committed by Jim Harris
parent 305976168d
commit 671da58caf
2 changed files with 36 additions and 30 deletions

View File

@ -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);

View File

@ -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