pci: keep device information in the spdk_pci_device struct

It's handy to store the SPDK structs within the device
structure. The subsequent patch will make us use
spdk_pci_addr much more frequently, so it makes sense
to keep it around rather than build it up from rte_pci_addr
everytime.

The upcoming VMD driver will also benefit from this patch
by being able to fill the spdk_pci_device struct with any
custom PCI details.

Change-Id: I236a19e28beba9a593b29f23b79b1b0b92ef1fa7
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/434418 (master)
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448374
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Darek Stojaczyk 2018-11-20 15:05:13 +01:00
parent 5980c657bd
commit 0a0739c67a
2 changed files with 28 additions and 27 deletions

View File

@ -74,6 +74,10 @@ extern struct rte_pci_bus rte_pci_bus;
struct spdk_pci_device {
struct rte_pci_device *dev_handle;
struct spdk_pci_enum_ctx *enum_ctx;
struct spdk_pci_addr addr;
struct spdk_pci_id id;
int socket_id;
bool attached;
TAILQ_ENTRY(spdk_pci_device) tailq;
};

View File

@ -66,6 +66,17 @@ spdk_pci_device_init(struct rte_pci_driver *driver,
}
dev->dev_handle = _dev;
dev->enum_ctx = ctx;
dev->addr.domain = _dev->addr.domain;
dev->addr.bus = _dev->addr.bus;
dev->addr.dev = _dev->addr.devid;
dev->addr.func = _dev->addr.function;
dev->id.vendor_id = _dev->id.vendor_id;
dev->id.device_id = _dev->id.device_id;
dev->id.subvendor_id = _dev->id.subsystem_vendor_id;
dev->id.subdevice_id = _dev->id.subsystem_device_id;
dev->socket_id = _dev->device.numa_node;
rc = ctx->cb_fn(ctx->cb_arg, dev);
if (rc != 0) {
@ -236,68 +247,61 @@ spdk_pci_device_unmap_bar(struct spdk_pci_device *device, uint32_t bar, void *ad
uint32_t
spdk_pci_device_get_domain(struct spdk_pci_device *dev)
{
return dev->dev_handle->addr.domain;
return dev->addr.domain;
}
uint8_t
spdk_pci_device_get_bus(struct spdk_pci_device *dev)
{
return dev->dev_handle->addr.bus;
return dev->addr.bus;
}
uint8_t
spdk_pci_device_get_dev(struct spdk_pci_device *dev)
{
return dev->dev_handle->addr.devid;
return dev->addr.dev;
}
uint8_t
spdk_pci_device_get_func(struct spdk_pci_device *dev)
{
return dev->dev_handle->addr.function;
return dev->addr.func;
}
uint16_t
spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev)
{
return dev->dev_handle->id.vendor_id;
return dev->id.vendor_id;
}
uint16_t
spdk_pci_device_get_device_id(struct spdk_pci_device *dev)
{
return dev->dev_handle->id.device_id;
return dev->id.device_id;
}
uint16_t
spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev)
{
return dev->dev_handle->id.subsystem_vendor_id;
return dev->id.subvendor_id;
}
uint16_t
spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev)
{
return dev->dev_handle->id.subsystem_device_id;
return dev->id.subdevice_id;
}
struct spdk_pci_id
spdk_pci_device_get_id(struct spdk_pci_device *pci_dev)
spdk_pci_device_get_id(struct spdk_pci_device *dev)
{
struct spdk_pci_id pci_id;
pci_id.vendor_id = spdk_pci_device_get_vendor_id(pci_dev);
pci_id.device_id = spdk_pci_device_get_device_id(pci_dev);
pci_id.subvendor_id = spdk_pci_device_get_subvendor_id(pci_dev);
pci_id.subdevice_id = spdk_pci_device_get_subdevice_id(pci_dev);
return pci_id;
return dev->id;
}
int
spdk_pci_device_get_socket_id(struct spdk_pci_device *dev)
{
return dev->dev_handle->device.numa_node;
return dev->socket_id;
}
int
@ -418,16 +422,9 @@ spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t
}
struct spdk_pci_addr
spdk_pci_device_get_addr(struct spdk_pci_device *pci_dev)
spdk_pci_device_get_addr(struct spdk_pci_device *dev)
{
struct spdk_pci_addr pci_addr;
pci_addr.domain = spdk_pci_device_get_domain(pci_dev);
pci_addr.bus = spdk_pci_device_get_bus(pci_dev);
pci_addr.dev = spdk_pci_device_get_dev(pci_dev);
pci_addr.func = spdk_pci_device_get_func(pci_dev);
return pci_addr;
return dev->addr;
}
int