diff --git a/include/spdk/pci.h b/include/spdk/pci.h index a2f8e5884..7d71e79f3 100644 --- a/include/spdk/pci.h +++ b/include/spdk/pci.h @@ -57,6 +57,10 @@ 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_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); +int spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset); 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); diff --git a/lib/util/pci.c b/lib/util/pci.c index a0751e49f..1a70d2103 100644 --- a/lib/util/pci.c +++ b/lib/util/pci.c @@ -162,6 +162,30 @@ spdk_pci_device_get_device_name(struct spdk_pci_device *dev) return pci_device_get_device_name(dev); } +int +spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset) +{ + return pci_device_cfg_read_u8(dev, value, offset); +} + +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) { @@ -314,6 +338,30 @@ spdk_pci_device_get_device_name(struct spdk_pci_device *dev) return NULL; } +int +spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset) +{ + return rte_eal_pci_read_config(dev, value, 1, offset) == 1 ? 0 : -1; +} + +int +spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset) +{ + return rte_eal_pci_write_config(dev, &value, 1, offset) == 1 ? 0 : -1; +} + +int +spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset) +{ + return rte_eal_pci_read_config(dev, value, 2, offset) == 2 ? 0 : -1; +} + +int +spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset) +{ + return rte_eal_pci_write_config(dev, &value, 2, offset) == 2 ? 0 : -1; +} + int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset) {