virtio: generalize PCI enumerate functions
Make them usable for other Virtio drivers (not just SCSI). Change-Id: I7ae2c43f311fefd40e447c8b5accaf824d0e23de Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/393121 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
3dc37c4316
commit
724c9aa7d6
@ -45,6 +45,7 @@
|
|||||||
#include "spdk/queue.h"
|
#include "spdk/queue.h"
|
||||||
#include "spdk/json.h"
|
#include "spdk/json.h"
|
||||||
#include "spdk/io_channel.h"
|
#include "spdk/io_channel.h"
|
||||||
|
#include "spdk/pci_ids.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum virtqueue size is 2^15. Use that value as the end of
|
* The maximum virtqueue size is 2^15. Use that value as the end of
|
||||||
@ -429,14 +430,15 @@ virtio_dev_has_feature(struct virtio_dev *vdev, uint64_t bit)
|
|||||||
void virtio_dev_dump_json_config(struct virtio_dev *vdev, struct spdk_json_write_ctx *w);
|
void virtio_dev_dump_json_config(struct virtio_dev *vdev, struct spdk_json_write_ctx *w);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumerate all PCI Virtio devices on the system.
|
* Enumerate all PCI Virtio devices of given type on the system.
|
||||||
*
|
*
|
||||||
* \param enum_cb a function to be called for each valid PCI device.
|
* \param enum_cb a function to be called for each valid PCI device.
|
||||||
* \return if a virtio_dev is has been created, the callback should return 0.
|
* \return if a virtio_dev is has been created, the callback should return 0.
|
||||||
* Returning any other value will cause the PCI context to be freed,
|
* Returning any other value will cause the PCI context to be freed,
|
||||||
* making it unusable.
|
* making it unusable.
|
||||||
|
* \param pci_device_id PCI Device ID of devices to iterate through
|
||||||
*/
|
*/
|
||||||
int virtio_pci_scsi_dev_enumerate(virtio_pci_create_cb enum_cb);
|
int virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, uint16_t pci_device_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a vhost-user device and init corresponding virtio_dev struct.
|
* Connect to a vhost-user device and init corresponding virtio_dev struct.
|
||||||
|
@ -1473,7 +1473,8 @@ bdev_virtio_process_config(void)
|
|||||||
|
|
||||||
enable_pci = spdk_conf_section_get_boolval(sp, "Enable", false);
|
enable_pci = spdk_conf_section_get_boolval(sp, "Enable", false);
|
||||||
if (enable_pci) {
|
if (enable_pci) {
|
||||||
rc = virtio_pci_scsi_dev_enumerate(virtio_pci_scsi_dev_create_cb);
|
rc = virtio_pci_dev_enumerate(virtio_pci_scsi_dev_create_cb,
|
||||||
|
PCI_DEVICE_ID_VIRTIO_SCSI_MODERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "spdk/mmio.h"
|
#include "spdk/mmio.h"
|
||||||
#include "spdk/string.h"
|
#include "spdk/string.h"
|
||||||
#include "spdk/env.h"
|
#include "spdk/env.h"
|
||||||
#include "spdk/pci_ids.h"
|
|
||||||
|
|
||||||
#include "spdk_internal/virtio.h"
|
#include "spdk_internal/virtio.h"
|
||||||
|
|
||||||
@ -61,6 +60,11 @@ struct virtio_hw {
|
|||||||
void *dev_cfg;
|
void *dev_cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct virtio_pci_probe_ctx {
|
||||||
|
virtio_pci_create_cb enum_cb;
|
||||||
|
uint16_t device_id;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Following macros are derived from linux/pci_regs.h, however,
|
* Following macros are derived from linux/pci_regs.h, however,
|
||||||
* we can't simply include that header here, as there is no such
|
* we can't simply include that header here, as there is no such
|
||||||
@ -464,27 +468,32 @@ virtio_pci_dev_probe(struct spdk_pci_device *pci_dev, virtio_pci_create_cb enum_
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virtio_pci_scsi_dev_probe_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
virtio_pci_dev_probe_cb(void *probe_ctx, struct spdk_pci_device *pci_dev)
|
||||||
{
|
{
|
||||||
virtio_pci_create_cb enum_cb = ctx;
|
struct virtio_pci_probe_ctx *ctx = probe_ctx;
|
||||||
uint16_t pci_device_id = spdk_pci_device_get_device_id(pci_dev);
|
uint16_t pci_device_id = spdk_pci_device_get_device_id(pci_dev);
|
||||||
|
|
||||||
if (pci_device_id != PCI_DEVICE_ID_VIRTIO_SCSI_MODERN) {
|
if (pci_device_id != ctx->device_id) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virtio_pci_dev_probe(pci_dev, enum_cb);
|
return virtio_pci_dev_probe(pci_dev, ctx->enum_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virtio_pci_scsi_dev_enumerate(virtio_pci_create_cb enum_cb)
|
virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, uint16_t pci_device_id)
|
||||||
{
|
{
|
||||||
|
struct virtio_pci_probe_ctx ctx;
|
||||||
|
|
||||||
if (!spdk_process_is_primary()) {
|
if (!spdk_process_is_primary()) {
|
||||||
SPDK_WARNLOG("virtio_pci secondary process support is not implemented yet.\n");
|
SPDK_WARNLOG("virtio_pci secondary process support is not implemented yet.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return spdk_pci_virtio_enumerate(virtio_pci_scsi_dev_probe_cb, enum_cb);
|
ctx.enum_cb = enum_cb;
|
||||||
|
ctx.device_id = pci_device_id;
|
||||||
|
|
||||||
|
return spdk_pci_virtio_enumerate(virtio_pci_dev_probe_cb, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user