Commit 84c34e64 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

env_dpdk: add dpdk_pci_device functions for bars and cfg



Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I2f65adaead06d2443f634d8d905c780ad38ec454
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14545


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 0c6a7b91
Loading
Loading
Loading
Loading
+44 −21
Original line number Diff line number Diff line
@@ -59,6 +59,12 @@ SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver) >= sizeof(struct rte
const char *dpdk_pci_device_get_name(struct rte_pci_device *);
struct rte_devargs *dpdk_pci_device_get_devargs(struct rte_pci_device *);
void dpdk_pci_device_copy_identifiers(struct rte_pci_device *_dev, struct spdk_pci_device *dev);
int dpdk_pci_device_map_bar(struct rte_pci_device *dev, uint32_t bar,
			    void **mapped_addr, uint64_t *phys_addr, uint64_t *size);
int dpdk_pci_device_read_config(struct rte_pci_device *dev, void *value, uint32_t len,
				uint32_t offset);
int dpdk_pci_device_write_config(struct rte_pci_device *dev, void *value, uint32_t len,
				 uint32_t offset);

int pci_device_init(struct rte_pci_driver *driver, struct rte_pci_device *device);
int pci_device_fini(struct rte_pci_device *device);
@@ -89,13 +95,7 @@ static int
map_bar_rte(struct spdk_pci_device *device, uint32_t bar,
	    void **mapped_addr, uint64_t *phys_addr, uint64_t *size)
{
	struct rte_pci_device *dev = device->dev_handle;

	*mapped_addr = dev->mem_resource[bar].addr;
	*phys_addr = (uint64_t)dev->mem_resource[bar].phys_addr;
	*size = (uint64_t)dev->mem_resource[bar].len;

	return 0;
	return dpdk_pci_device_map_bar(device->dev_handle, bar, mapped_addr, phys_addr, size);
}

static int
@@ -107,25 +107,13 @@ unmap_bar_rte(struct spdk_pci_device *device, uint32_t bar, void *addr)
static int
cfg_read_rte(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t offset)
{
	int rc;

	rc = rte_pci_read_config(dev->dev_handle, value, len, offset);

	return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
	return dpdk_pci_device_read_config(dev->dev_handle, value, len, offset);
}

static int
cfg_write_rte(struct spdk_pci_device *dev, void *value, uint32_t len, uint32_t offset)
{
	int rc;

	rc = rte_pci_write_config(dev->dev_handle, value, len, offset);

#ifdef __FreeBSD__
	/* DPDK returns 0 on success and -1 on failure */
	return rc;
#endif
	return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
	return dpdk_pci_device_write_config(dev->dev_handle, value, len, offset);
}

static void
@@ -1294,3 +1282,38 @@ dpdk_pci_device_copy_identifiers(struct rte_pci_device *_dev, struct spdk_pci_de
	dev->id.subdevice_id = _dev->id.subsystem_device_id;
	dev->socket_id = _dev->device.numa_node;
}

int
dpdk_pci_device_map_bar(struct rte_pci_device *dev, uint32_t bar,
			void **mapped_addr, uint64_t *phys_addr, uint64_t *size)
{
	*mapped_addr = dev->mem_resource[bar].addr;
	*phys_addr = (uint64_t)dev->mem_resource[bar].phys_addr;
	*size = (uint64_t)dev->mem_resource[bar].len;

	return 0;
}

int
dpdk_pci_device_read_config(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
{
	int rc;

	rc = rte_pci_read_config(dev, value, len, offset);

	return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
}

int
dpdk_pci_device_write_config(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
{
	int rc;

	rc = rte_pci_write_config(dev, value, len, offset);

#ifdef __FreeBSD__
	/* DPDK returns 0 on success and -1 on failure */
	return rc;
#endif
	return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
}