Commit 671da58c authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/379487


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 30597616
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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);
+28 −26
Original line number Diff line number Diff line
@@ -307,63 +307,65 @@ spdk_pci_device_get_socket_id(struct spdk_pci_device *pci_dev)
}

int
spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset)
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)
	return rte_pci_read_config(dev, value, 1, offset) == 1 ? 0 : -1;
	rc = rte_pci_read_config(dev, value, len, offset);
#else
	return rte_eal_pci_read_config(dev, value, 1, offset) == 1 ? 0 : -1;
	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_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset)
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)
	return rte_pci_write_config(dev, &value, 1, offset) == 1 ? 0 : -1;
	rc = rte_pci_write_config(dev, value, len, offset);
#else
	return rte_eal_pci_write_config(dev, &value, 1, offset) == 1 ? 0 : -1;
	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)
{
	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)
{
	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