env: encapsulate spdk_pci_device fields
In order to populate our PCI device list with devices located behind the VMD, we'll need to fill out those device structures from within a special VMD driver. That driver will base on PCI configuration and BAR accesses, but definitely not on DPDK. We want to put the VMD driver outside of the env lib, so we're about to provide it with a direct access to the device struct. Before we do that, let's group all the env-internal fields into an extra struct "internal". The spdk_pci_device struct does actually depend on DPDK now as it contains an `rte_pci_device *dev_handle` field, but we can easily break that dependency. The field is only used as an arguement to DPDK functions, so we can change its type to void* and let the implicit type conversion do the magic. After all, the VMD driver will potentially use it to store its (non-DPDK) data as well. Change-Id: I425d6dfa7af13e022f5377ceaff39efbd4a01b3d Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/435799 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
1cbd14ca1b
commit
df4d03f107
@ -79,13 +79,16 @@ __attribute__((constructor)) static void pci_drv ## _register(void) \
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct spdk_pci_device {
|
struct spdk_pci_device {
|
||||||
struct rte_pci_device *dev_handle;
|
void *dev_handle;
|
||||||
struct spdk_pci_driver *driver;
|
|
||||||
struct spdk_pci_addr addr;
|
struct spdk_pci_addr addr;
|
||||||
struct spdk_pci_id id;
|
struct spdk_pci_id id;
|
||||||
int socket_id;
|
int socket_id;
|
||||||
|
|
||||||
|
struct _spdk_pci_device_internal {
|
||||||
|
struct spdk_pci_driver *driver;
|
||||||
bool attached;
|
bool attached;
|
||||||
TAILQ_ENTRY(spdk_pci_device) tailq;
|
TAILQ_ENTRY(spdk_pci_device) tailq;
|
||||||
|
} internal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spdk_pci_driver {
|
struct spdk_pci_driver {
|
||||||
|
@ -108,7 +108,6 @@ spdk_pci_device_init(struct rte_pci_driver *_drv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dev->dev_handle = _dev;
|
dev->dev_handle = _dev;
|
||||||
dev->driver = driver;
|
|
||||||
|
|
||||||
dev->addr.domain = _dev->addr.domain;
|
dev->addr.domain = _dev->addr.domain;
|
||||||
dev->addr.bus = _dev->addr.bus;
|
dev->addr.bus = _dev->addr.bus;
|
||||||
@ -120,16 +119,18 @@ spdk_pci_device_init(struct rte_pci_driver *_drv,
|
|||||||
dev->id.subdevice_id = _dev->id.subsystem_device_id;
|
dev->id.subdevice_id = _dev->id.subsystem_device_id;
|
||||||
dev->socket_id = _dev->device.numa_node;
|
dev->socket_id = _dev->device.numa_node;
|
||||||
|
|
||||||
|
dev->internal.driver = driver;
|
||||||
|
|
||||||
if (driver->cb_fn != NULL) {
|
if (driver->cb_fn != NULL) {
|
||||||
rc = driver->cb_fn(driver->cb_arg, dev);
|
rc = driver->cb_fn(driver->cb_arg, dev);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
free(dev);
|
free(dev);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
dev->attached = true;
|
dev->internal.attached = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&g_pci_devices, dev, tailq);
|
TAILQ_INSERT_TAIL(&g_pci_devices, dev, internal.tailq);
|
||||||
spdk_vtophys_pci_device_added(dev->dev_handle);
|
spdk_vtophys_pci_device_added(dev->dev_handle);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -139,19 +140,19 @@ spdk_pci_device_fini(struct rte_pci_device *_dev)
|
|||||||
{
|
{
|
||||||
struct spdk_pci_device *dev;
|
struct spdk_pci_device *dev;
|
||||||
|
|
||||||
TAILQ_FOREACH(dev, &g_pci_devices, tailq) {
|
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
|
||||||
if (dev->dev_handle == _dev) {
|
if (dev->dev_handle == _dev) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev == NULL || dev->attached) {
|
if (dev == NULL || dev->internal.attached) {
|
||||||
/* The device might be still referenced somewhere in SPDK. */
|
/* The device might be still referenced somewhere in SPDK. */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_vtophys_pci_device_removed(dev->dev_handle);
|
spdk_vtophys_pci_device_removed(dev->dev_handle);
|
||||||
TAILQ_REMOVE(&g_pci_devices, dev, tailq);
|
TAILQ_REMOVE(&g_pci_devices, dev, internal.tailq);
|
||||||
free(dev);
|
free(dev);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -162,8 +163,8 @@ spdk_pci_device_detach(struct spdk_pci_device *dev)
|
|||||||
{
|
{
|
||||||
struct rte_pci_device *device = dev->dev_handle;
|
struct rte_pci_device *device = dev->dev_handle;
|
||||||
|
|
||||||
assert(dev->attached);
|
assert(dev->internal.attached);
|
||||||
dev->attached = false;
|
dev->internal.attached = false;
|
||||||
#if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0)
|
#if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0)
|
||||||
char bdf[32];
|
char bdf[32];
|
||||||
int i = 0, rc;
|
int i = 0, rc;
|
||||||
@ -204,21 +205,21 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver,
|
|||||||
|
|
||||||
pthread_mutex_lock(&g_pci_mutex);
|
pthread_mutex_lock(&g_pci_mutex);
|
||||||
|
|
||||||
TAILQ_FOREACH(dev, &g_pci_devices, tailq) {
|
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
|
||||||
if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) {
|
if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev != NULL && dev->driver == driver) {
|
if (dev != NULL && dev->internal.driver == driver) {
|
||||||
if (dev->attached) {
|
if (dev->internal.attached) {
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
pthread_mutex_unlock(&g_pci_mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = enum_cb(enum_ctx, dev);
|
rc = enum_cb(enum_ctx, dev);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
dev->attached = true;
|
dev->internal.attached = true;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
pthread_mutex_unlock(&g_pci_mutex);
|
||||||
return rc;
|
return rc;
|
||||||
@ -278,14 +279,14 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver,
|
|||||||
|
|
||||||
pthread_mutex_lock(&g_pci_mutex);
|
pthread_mutex_lock(&g_pci_mutex);
|
||||||
|
|
||||||
TAILQ_FOREACH(dev, &g_pci_devices, tailq) {
|
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
|
||||||
if (dev->attached || dev->driver != driver) {
|
if (dev->internal.attached || dev->internal.driver != driver) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = enum_cb(enum_ctx, dev);
|
rc = enum_cb(enum_ctx, dev);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
dev->attached = true;
|
dev->internal.attached = true;
|
||||||
} else if (rc < 0) {
|
} else if (rc < 0) {
|
||||||
pthread_mutex_unlock(&g_pci_mutex);
|
pthread_mutex_unlock(&g_pci_mutex);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user