rte_virtio: remove vtpci references

Renamed all vtpci functions.
While here, also added some documentation.

Change-Id: Id24aaab8c5b556b969c60ee1c95b9d46936ea13d
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/385426
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2017-11-02 17:10:56 +01:00 committed by Jim Harris
parent 38a22db999
commit 21f46353a5
5 changed files with 102 additions and 48 deletions

View File

@ -387,7 +387,7 @@ bdev_virtio_dump_json_config(void *ctx, struct spdk_json_write_ctx *w)
{ {
struct virtio_scsi_disk *disk = ctx; struct virtio_scsi_disk *disk = ctx;
vtpci_dump_json_config(disk->vdev, w); virtio_dev_dump_json_config(disk->vdev, w);
return 0; return 0;
} }
@ -576,7 +576,7 @@ scan_target_abort(struct virtio_scsi_scan_base *base, int error)
} }
TAILQ_REMOVE(&g_virtio_driver.init_ctrlrs, base->vdev, tailq); TAILQ_REMOVE(&g_virtio_driver.init_ctrlrs, base->vdev, tailq);
vtpci_reset(base->vdev); virtio_dev_reset(base->vdev);
virtio_dev_free(base->vdev); virtio_dev_free(base->vdev);
@ -1101,7 +1101,7 @@ bdev_virtio_scsi_free(struct virtio_dev *vdev)
virtio_dev_release_queue(vdev, VIRTIO_SCSI_REQUESTQ); virtio_dev_release_queue(vdev, VIRTIO_SCSI_REQUESTQ);
} }
vtpci_reset(vdev); virtio_dev_reset(vdev);
virtio_dev_free(vdev); virtio_dev_free(vdev);
} }
@ -1221,7 +1221,7 @@ bdev_virtio_finish(void)
vq->poller_ctx = NULL; vq->poller_ctx = NULL;
virtio_dev_release_queue(vdev, VIRTIO_SCSI_CONTROLQ); virtio_dev_release_queue(vdev, VIRTIO_SCSI_CONTROLQ);
} }
vtpci_reset(vdev); virtio_dev_reset(vdev);
virtio_dev_free(vdev); virtio_dev_free(vdev);
} }
} }

View File

@ -105,7 +105,7 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
* Read the virtqueue size from the Queue Size field * Read the virtqueue size from the Queue Size field
* Always power of 2 and if 0 virtqueue does not exist * Always power of 2 and if 0 virtqueue does not exist
*/ */
vq_size = vtpci_ops(dev)->get_queue_num(dev, vtpci_queue_idx); vq_size = virtio_dev_backend_ops(dev)->get_queue_num(dev, vtpci_queue_idx);
SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "vq_size: %u\n", vq_size); SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "vq_size: %u\n", vq_size);
if (vq_size == 0) { if (vq_size == 0) {
SPDK_ERRLOG("virtqueue %"PRIu16" does not exist\n", vtpci_queue_idx); SPDK_ERRLOG("virtqueue %"PRIu16" does not exist\n", vtpci_queue_idx);
@ -173,7 +173,7 @@ virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
vq->owner_lcore = SPDK_VIRTIO_QUEUE_LCORE_ID_UNUSED; vq->owner_lcore = SPDK_VIRTIO_QUEUE_LCORE_ID_UNUSED;
vq->poller = NULL; vq->poller = NULL;
if (vtpci_ops(dev)->setup_queue(dev, vq) < 0) { if (virtio_dev_backend_ops(dev)->setup_queue(dev, vq) < 0) {
SPDK_ERRLOG("setup_queue failed\n"); SPDK_ERRLOG("setup_queue failed\n");
return -EINVAL; return -EINVAL;
} }
@ -243,13 +243,13 @@ virtio_alloc_queues(struct virtio_dev *dev)
static int static int
virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features) virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features)
{ {
uint64_t host_features = vtpci_ops(dev)->get_features(dev); uint64_t host_features = virtio_dev_backend_ops(dev)->get_features(dev);
int rc; int rc;
SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "guest features = %" PRIx64 "\n", req_features); SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "guest features = %" PRIx64 "\n", req_features);
SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "device features = %" PRIx64 "\n", host_features); SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "device features = %" PRIx64 "\n", host_features);
rc = vtpci_ops(dev)->set_features(dev, req_features & host_features); rc = virtio_dev_backend_ops(dev)->set_features(dev, req_features & host_features);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("failed to negotiate device features.\n"); SPDK_ERRLOG("failed to negotiate device features.\n");
return -1; return -1;
@ -258,8 +258,8 @@ virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features)
SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "negotiated features = %" PRIx64 "\n", SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "negotiated features = %" PRIx64 "\n",
dev->negotiated_features); dev->negotiated_features);
vtpci_set_status(dev, VIRTIO_CONFIG_S_FEATURES_OK); virtio_dev_set_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
if (!(vtpci_get_status(dev) & VIRTIO_CONFIG_S_FEATURES_OK)) { if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_FEATURES_OK)) {
SPDK_ERRLOG("failed to set FEATURES_OK status!\n"); SPDK_ERRLOG("failed to set FEATURES_OK status!\n");
return -1; return -1;
} }
@ -295,13 +295,13 @@ virtio_dev_init(struct virtio_dev *dev, uint64_t req_features)
int ret; int ret;
/* Reset the device although not necessary at startup */ /* Reset the device although not necessary at startup */
vtpci_reset(dev); virtio_dev_reset(dev);
/* Tell the host we've noticed this device. */ /* Tell the host we've noticed this device. */
vtpci_set_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); virtio_dev_set_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
/* Tell the host we've known how to drive the device. */ /* Tell the host we've known how to drive the device. */
vtpci_set_status(dev, VIRTIO_CONFIG_S_DRIVER); virtio_dev_set_status(dev, VIRTIO_CONFIG_S_DRIVER);
if (virtio_negotiate_features(dev, req_features) < 0) if (virtio_negotiate_features(dev, req_features) < 0)
return -1; return -1;
@ -309,7 +309,7 @@ virtio_dev_init(struct virtio_dev *dev, uint64_t req_features)
if (ret < 0) if (ret < 0)
return ret; return ret;
vtpci_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); virtio_dev_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
return 0; return 0;
} }
@ -317,7 +317,7 @@ void
virtio_dev_free(struct virtio_dev *dev) virtio_dev_free(struct virtio_dev *dev)
{ {
virtio_free_queues(dev); virtio_free_queues(dev);
vtpci_ops(dev)->free_vdev(dev); virtio_dev_backend_ops(dev)->free_vdev(dev);
pthread_mutex_destroy(&dev->mutex); pthread_mutex_destroy(&dev->mutex);
free(dev); free(dev);
} }
@ -550,7 +550,7 @@ virtio_xmit_pkt(struct virtqueue *vq, struct virtio_req *req)
vq_update_avail_idx(vq); vq_update_avail_idx(vq);
if (spdk_unlikely(virtqueue_kick_prepare(vq))) { if (spdk_unlikely(virtqueue_kick_prepare(vq))) {
vtpci_ops(vdev)->notify_queue(vdev, vq); virtio_dev_backend_ops(vdev)->notify_queue(vdev, vq);
SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "Notified backend after xmit\n"); SPDK_DEBUGLOG(SPDK_TRACE_VIRTIO_DEV, "Notified backend after xmit\n");
} }
@ -659,50 +659,50 @@ virtio_dev_release_queue(struct virtio_dev *vdev, uint16_t index)
} }
void void
vtpci_read_dev_config(struct virtio_dev *dev, size_t offset, virtio_dev_read_dev_config(struct virtio_dev *dev, size_t offset,
void *dst, int length) void *dst, int length)
{ {
vtpci_ops(dev)->read_dev_cfg(dev, offset, dst, length); virtio_dev_backend_ops(dev)->read_dev_cfg(dev, offset, dst, length);
} }
void void
vtpci_write_dev_config(struct virtio_dev *dev, size_t offset, virtio_dev_write_dev_config(struct virtio_dev *dev, size_t offset,
const void *src, int length) const void *src, int length)
{ {
vtpci_ops(dev)->write_dev_cfg(dev, offset, src, length); virtio_dev_backend_ops(dev)->write_dev_cfg(dev, offset, src, length);
} }
void void
vtpci_reset(struct virtio_dev *dev) virtio_dev_reset(struct virtio_dev *dev)
{ {
vtpci_ops(dev)->set_status(dev, VIRTIO_CONFIG_S_RESET); virtio_dev_backend_ops(dev)->set_status(dev, VIRTIO_CONFIG_S_RESET);
/* flush status write */ /* flush status write */
vtpci_ops(dev)->get_status(dev); virtio_dev_backend_ops(dev)->get_status(dev);
} }
void void
vtpci_set_status(struct virtio_dev *dev, uint8_t status) virtio_dev_set_status(struct virtio_dev *dev, uint8_t status)
{ {
if (status != VIRTIO_CONFIG_S_RESET) if (status != VIRTIO_CONFIG_S_RESET)
status |= vtpci_ops(dev)->get_status(dev); status |= virtio_dev_backend_ops(dev)->get_status(dev);
vtpci_ops(dev)->set_status(dev, status); virtio_dev_backend_ops(dev)->set_status(dev, status);
} }
uint8_t uint8_t
vtpci_get_status(struct virtio_dev *dev) virtio_dev_get_status(struct virtio_dev *dev)
{ {
return vtpci_ops(dev)->get_status(dev); return virtio_dev_backend_ops(dev)->get_status(dev);
} }
const struct virtio_pci_ops * const struct virtio_pci_ops *
vtpci_ops(struct virtio_dev *dev) virtio_dev_backend_ops(struct virtio_dev *dev)
{ {
return dev->backend_ops; return dev->backend_ops;
} }
void void
vtpci_dump_json_config(struct virtio_dev *hw, struct spdk_json_write_ctx *w) virtio_dev_dump_json_config(struct virtio_dev *hw, struct spdk_json_write_ctx *w)
{ {
spdk_json_write_name(w, "virtio"); spdk_json_write_name(w, "virtio");
spdk_json_write_object_begin(w); spdk_json_write_object_begin(w);
@ -711,9 +711,9 @@ vtpci_dump_json_config(struct virtio_dev *hw, struct spdk_json_write_ctx *w)
spdk_json_write_uint32(w, hw->max_queues); spdk_json_write_uint32(w, hw->max_queues);
spdk_json_write_name(w, "vq_size"); spdk_json_write_name(w, "vq_size");
spdk_json_write_uint32(w, vtpci_ops(hw)->get_queue_num(hw, 0)); spdk_json_write_uint32(w, virtio_dev_backend_ops(hw)->get_queue_num(hw, 0));
vtpci_ops(hw)->dump_json_config(hw, w); virtio_dev_backend_ops(hw)->dump_json_config(hw, w);
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
} }

View File

@ -358,26 +358,80 @@ bool virtio_dev_queue_is_acquired(struct virtio_dev *vdev, uint16_t index);
*/ */
void virtio_dev_release_queue(struct virtio_dev *vdev, uint16_t index); void virtio_dev_release_queue(struct virtio_dev *vdev, uint16_t index);
void vtpci_reset(struct virtio_dev *); /**
* Reset given virtio device. This will leave the device in unusable state.
* To reuse the device, call \c virtio_dev_init.
*
* \param vdev virtio device
*/
void virtio_dev_reset(struct virtio_dev *vdev);
uint8_t vtpci_get_status(struct virtio_dev *); /**
void vtpci_set_status(struct virtio_dev *, uint8_t); * Get Virtio status flags.
*
* \param vdev virtio device
*/
uint8_t virtio_dev_get_status(struct virtio_dev *vdev);
uint64_t vtpci_negotiate_features(struct virtio_dev *, uint64_t); /**
* Set Virtio status flag. The flags have to be set in very specific order
* defined the VirtIO 1.0 spec section 3.1.1. To unset the flags, call
* \c virtio_dev_reset or set \c VIRTIO_CONFIG_S_RESET flag. There is
* no way to unset particular flags.
*
* \param vdev virtio device
* \param flag flag to set
*/
void virtio_dev_set_status(struct virtio_dev *vdev, uint8_t flag);
void vtpci_write_dev_config(struct virtio_dev *, size_t, const void *, int); /**
* Write raw data into the device config at given offset. This call does not
* provide any error checking.
*
* \param vdev virtio device
* \param offset offset in bytes
* \param src pointer to data to copy from
* \param len length of data to copy in bytes
*/
void virtio_dev_write_dev_config(struct virtio_dev *vdev, size_t offset, const void *src, int len);
void vtpci_read_dev_config(struct virtio_dev *, size_t, void *, int); /**
* Read raw data from the device config at given offset. This call does not
* provide any error checking.
*
* \param vdev virtio device
* \param offset offset in bytes
* \param dst pointer to buffer to copy data into
* \param len length of data to copy in bytes
*/
void virtio_dev_read_dev_config(struct virtio_dev *vdev, size_t offset, void *dst, int len);
const struct virtio_pci_ops *vtpci_ops(struct virtio_dev *dev); /**
* Get backend-specific ops for given device.
*
* \param vdev virtio device
*/
const struct virtio_pci_ops *virtio_dev_backend_ops(struct virtio_dev *vdev);
static inline int /**
vtpci_with_feature(struct virtio_dev *dev, uint64_t bit) * Check if the device has negotiated given feature bit.
*
* \param vdev virtio device
* \param bit feature bit
*/
static inline bool
virtio_dev_has_feature(struct virtio_dev *vdev, uint64_t bit)
{ {
return (dev->negotiated_features & (1ULL << bit)) != 0; return !!(vdev->negotiated_features & (1ULL << bit));
} }
void vtpci_dump_json_config(struct virtio_dev *hw, struct spdk_json_write_ctx *w); /**
* Dump all device specific information into given json stream.
*
* \param vdev virtio device
* \param w json stream
*/
void virtio_dev_dump_json_config(struct virtio_dev *vdev, struct spdk_json_write_ctx *w);
/** /**
* Init all compatible Virtio PCI devices. * Init all compatible Virtio PCI devices.

View File

@ -423,7 +423,7 @@ virtio_dev_pci_init(struct virtio_dev *vdev)
return -1; return -1;
} }
vtpci_read_dev_config(vdev, offsetof(struct virtio_scsi_config, num_queues), virtio_dev_read_dev_config(vdev, offsetof(struct virtio_scsi_config, num_queues),
&vdev->max_queues, sizeof(vdev->max_queues)); &vdev->max_queues, sizeof(vdev->max_queues));
vdev->max_queues += SPDK_VIRTIO_SCSI_QUEUE_NUM_FIXED; vdev->max_queues += SPDK_VIRTIO_SCSI_QUEUE_NUM_FIXED;
TAILQ_INSERT_TAIL(&g_virtio_driver.init_ctrlrs, vdev, tailq); TAILQ_INSERT_TAIL(&g_virtio_driver.init_ctrlrs, vdev, tailq);

View File

@ -113,7 +113,7 @@ virtio_user_set_features(struct virtio_dev *vdev, uint64_t features)
} }
vdev->negotiated_features = features; vdev->negotiated_features = features;
vdev->modern = vtpci_with_feature(vdev, VIRTIO_F_VERSION_1); vdev->modern = virtio_dev_has_feature(vdev, VIRTIO_F_VERSION_1);
return 0; return 0;
} }