virtio: add opaque ctx param to PCI enumerate callback
In current bdev_virtio_scsi PCI enumerate callback implementation we rely on a global variable - a global list of virtio devices. We do not need any opaque context data inside this callback just yet. It will be required to add virtio devices in runtime. See the next patch for details. Change-Id: I116cbd3bd633f56922eedcc7c07b8c0310e51d49 Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/394444 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
5b057b3a05
commit
5c0c104b81
@ -190,10 +190,11 @@ struct virtio_pci_ctx;
|
||||
|
||||
/**
|
||||
* Callback for creating virtio_dev from a PCI device.
|
||||
* The first param is the PCI context to be associated with virtio_dev.
|
||||
* \param pci_ctx PCI context to be associated with a virtio_dev
|
||||
* \param ctx context provided by the user
|
||||
* \return 0 on success, -1 on error.
|
||||
*/
|
||||
typedef int (*virtio_pci_create_cb)(struct virtio_pci_ctx *pci_ctx);
|
||||
typedef int (*virtio_pci_create_cb)(struct virtio_pci_ctx *pci_ctx, void *ctx);
|
||||
|
||||
uint16_t virtio_recv_pkts(struct virtqueue *vq, void **io, uint32_t *len, uint16_t io_cnt);
|
||||
|
||||
@ -434,12 +435,14 @@ void virtio_dev_dump_json_config(struct virtio_dev *vdev, struct spdk_json_write
|
||||
* Enumerate all PCI Virtio devices of given type on the system.
|
||||
*
|
||||
* \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.
|
||||
* 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,
|
||||
* making it unusable.
|
||||
* \param enum_ctx additional opaque context to be passed into `enum_cb`
|
||||
* \param pci_device_id PCI Device ID of devices to iterate through
|
||||
*/
|
||||
int virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, uint16_t pci_device_id);
|
||||
int virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, void *enum_ctx,
|
||||
uint16_t pci_device_id);
|
||||
|
||||
/**
|
||||
* Connect to a vhost-user device and init corresponding virtio_dev struct.
|
||||
|
@ -293,7 +293,7 @@ virtio_scsi_dev_init(struct virtio_scsi_dev *svdev, uint16_t max_queues)
|
||||
}
|
||||
|
||||
static int
|
||||
virtio_pci_scsi_dev_create_cb(struct virtio_pci_ctx *pci_ctx)
|
||||
virtio_pci_scsi_dev_create_cb(struct virtio_pci_ctx *pci_ctx, void *ctx)
|
||||
{
|
||||
static int pci_dev_counter = 0;
|
||||
struct virtio_scsi_dev *svdev;
|
||||
@ -1502,7 +1502,7 @@ bdev_virtio_process_config(void)
|
||||
|
||||
enable_pci = spdk_conf_section_get_boolval(sp, "Enable", false);
|
||||
if (enable_pci) {
|
||||
rc = virtio_pci_dev_enumerate(virtio_pci_scsi_dev_create_cb,
|
||||
rc = virtio_pci_dev_enumerate(virtio_pci_scsi_dev_create_cb, NULL,
|
||||
PCI_DEVICE_ID_VIRTIO_SCSI_MODERN);
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ struct virtio_hw {
|
||||
|
||||
struct virtio_pci_probe_ctx {
|
||||
virtio_pci_create_cb enum_cb;
|
||||
void *enum_ctx;
|
||||
uint16_t device_id;
|
||||
};
|
||||
|
||||
@ -421,7 +422,7 @@ next:
|
||||
}
|
||||
|
||||
static int
|
||||
virtio_pci_dev_probe(struct spdk_pci_device *pci_dev, virtio_pci_create_cb enum_cb)
|
||||
virtio_pci_dev_probe(struct spdk_pci_device *pci_dev, struct virtio_pci_probe_ctx *ctx)
|
||||
{
|
||||
struct virtio_hw *hw;
|
||||
uint8_t *bar_vaddr;
|
||||
@ -468,7 +469,7 @@ virtio_pci_dev_probe(struct spdk_pci_device *pci_dev, virtio_pci_create_cb enum_
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = enum_cb((struct virtio_pci_ctx *)hw);
|
||||
rc = ctx->enum_cb((struct virtio_pci_ctx *)hw, ctx->enum_ctx);
|
||||
if (rc != 0) {
|
||||
free_virtio_hw(hw);
|
||||
}
|
||||
@ -486,11 +487,12 @@ virtio_pci_dev_probe_cb(void *probe_ctx, struct spdk_pci_device *pci_dev)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return virtio_pci_dev_probe(pci_dev, ctx->enum_cb);
|
||||
return virtio_pci_dev_probe(pci_dev, ctx);
|
||||
}
|
||||
|
||||
int
|
||||
virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, uint16_t pci_device_id)
|
||||
virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, void *enum_ctx,
|
||||
uint16_t pci_device_id)
|
||||
{
|
||||
struct virtio_pci_probe_ctx ctx;
|
||||
|
||||
@ -500,6 +502,7 @@ virtio_pci_dev_enumerate(virtio_pci_create_cb enum_cb, uint16_t pci_device_id)
|
||||
}
|
||||
|
||||
ctx.enum_cb = enum_cb;
|
||||
ctx.enum_ctx = enum_ctx;
|
||||
ctx.device_id = pci_device_id;
|
||||
|
||||
return spdk_pci_virtio_enumerate(virtio_pci_dev_probe_cb, &ctx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user