rte_virtio: removed virtio_dev conversion macros

The vdev->ctx conversion is now
straighforward and doesn't need
any macro.

Change-Id: I88b0cf3fa5e95b93e5f69a0a3ae9508f9fac3683
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/385625
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-03 15:39:45 +01:00 committed by Jim Harris
parent d42de5c864
commit ec0b92faf2
2 changed files with 26 additions and 32 deletions

View File

@ -69,9 +69,6 @@ struct virtio_hw {
#define PCI_CAP_ID_VNDR 0x09
#define PCI_CAP_ID_MSIX 0x11
#define virtio_dev_get_hw(vdev) \
((struct virtio_hw *)((vdev)->ctx))
static inline int
check_vq_phys_addr_ok(struct virtqueue *vq)
{
@ -107,7 +104,7 @@ free_virtio_hw(struct virtio_hw *hw)
static void
pci_dump_json_config(struct virtio_dev *dev, struct spdk_json_write_ctx *w)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
struct spdk_pci_addr pci_addr = spdk_pci_device_get_addr((struct spdk_pci_device *)hw->pci_dev);
char addr[32];
@ -134,7 +131,7 @@ static void
modern_read_dev_config(struct virtio_dev *dev, size_t offset,
void *dst, int length)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
int i;
uint8_t *p;
uint8_t old_gen, new_gen;
@ -154,7 +151,7 @@ static void
modern_write_dev_config(struct virtio_dev *dev, size_t offset,
const void *src, int length)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
int i;
const uint8_t *p = src;
@ -165,7 +162,7 @@ modern_write_dev_config(struct virtio_dev *dev, size_t offset,
static uint64_t
modern_get_features(struct virtio_dev *dev)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
uint32_t features_lo, features_hi;
spdk_mmio_write_4(&hw->common_cfg->device_feature_select, 0);
@ -180,7 +177,7 @@ modern_get_features(struct virtio_dev *dev)
static int
modern_set_features(struct virtio_dev *dev, uint64_t features)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
if ((features & (1ULL << VIRTIO_F_VERSION_1)) == 0) {
SPDK_ERRLOG("VIRTIO_F_VERSION_1 feature is not enabled.\n");
@ -201,7 +198,7 @@ modern_set_features(struct virtio_dev *dev, uint64_t features)
static void
modern_free_vdev(struct virtio_dev *vdev)
{
struct virtio_hw *hw = virtio_dev_get_hw(vdev);
struct virtio_hw *hw = vdev->ctx;
free_virtio_hw(hw);
free(vdev->name);
@ -210,7 +207,7 @@ modern_free_vdev(struct virtio_dev *vdev)
static uint8_t
modern_get_status(struct virtio_dev *dev)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
return spdk_mmio_read_1(&hw->common_cfg->device_status);
}
@ -218,7 +215,7 @@ modern_get_status(struct virtio_dev *dev)
static void
modern_set_status(struct virtio_dev *dev, uint8_t status)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
spdk_mmio_write_1(&hw->common_cfg->device_status, status);
}
@ -226,7 +223,7 @@ modern_set_status(struct virtio_dev *dev, uint8_t status)
static uint16_t
modern_get_queue_num(struct virtio_dev *dev, uint16_t queue_id)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
spdk_mmio_write_2(&hw->common_cfg->queue_select, queue_id);
return spdk_mmio_read_2(&hw->common_cfg->queue_size);
@ -235,7 +232,7 @@ modern_get_queue_num(struct virtio_dev *dev, uint16_t queue_id)
static int
modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
uint64_t desc_addr, avail_addr, used_addr;
uint16_t notify_off;
@ -276,7 +273,7 @@ modern_setup_queue(struct virtio_dev *dev, struct virtqueue *vq)
static void
modern_del_queue(struct virtio_dev *dev, struct virtqueue *vq)
{
struct virtio_hw *hw = virtio_dev_get_hw(dev);
struct virtio_hw *hw = dev->ctx;
spdk_mmio_write_2(&hw->common_cfg->queue_select, vq->vq_queue_index);

View File

@ -46,13 +46,10 @@
#include "spdk/string.h"
#define virtio_dev_get_user_dev(vdev) \
((struct virtio_user_dev *)((vdev)->ctx))
static int
virtio_user_create_queue(struct virtio_dev *vdev, uint32_t queue_sel)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
/* Of all per virtqueue MSGs, make sure VHOST_SET_VRING_CALL come
* firstly because vhost depends on this msg to allocate virtqueue
@ -70,7 +67,7 @@ virtio_user_create_queue(struct virtio_dev *vdev, uint32_t queue_sel)
static int
virtio_user_kick_queue(struct virtio_dev *vdev, uint32_t queue_sel)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
struct vhost_vring_file file;
struct vhost_vring_state state;
struct vring *vring = &dev->vrings[queue_sel];
@ -107,7 +104,7 @@ virtio_user_kick_queue(struct virtio_dev *vdev, uint32_t queue_sel)
static int
virtio_user_stop_queue(struct virtio_dev *vdev, uint32_t queue_sel)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
struct vhost_vring_state state;
state.index = queue_sel;
@ -136,7 +133,7 @@ virtio_user_queue_setup(struct virtio_dev *vdev,
static int
virtio_user_start_device(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
int ret;
/* tell vhost to create queues */
@ -163,7 +160,7 @@ static int virtio_user_stop_device(struct virtio_dev *vdev)
static int
virtio_user_dev_setup(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
uint16_t i;
dev->vhostfd = -1;
@ -271,7 +268,7 @@ virtio_user_write_dev_config(struct virtio_dev *vdev, size_t offset,
static void
virtio_user_set_status(struct virtio_dev *vdev, uint8_t status)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
virtio_user_start_device(vdev);
@ -285,7 +282,7 @@ virtio_user_set_status(struct virtio_dev *vdev, uint8_t status)
static uint8_t
virtio_user_get_status(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
return dev->status;
}
@ -293,7 +290,7 @@ virtio_user_get_status(struct virtio_dev *vdev)
static uint64_t
virtio_user_get_features(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
char err_str[64];
uint64_t features;
@ -309,7 +306,7 @@ virtio_user_get_features(struct virtio_dev *vdev)
static int
virtio_user_set_features(struct virtio_dev *vdev, uint64_t features)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
int ret;
ret = dev->ops->send_request(dev, VHOST_USER_SET_FEATURES, &features);
@ -330,7 +327,7 @@ virtio_user_set_features(struct virtio_dev *vdev, uint64_t features)
static uint16_t
virtio_user_get_queue_num(struct virtio_dev *vdev, uint16_t queue_id)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
/* Currently, each queue has same queue size */
return dev->queue_size;
@ -339,7 +336,7 @@ virtio_user_get_queue_num(struct virtio_dev *vdev, uint16_t queue_id)
static int
virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
uint16_t queue_idx = vq->vq_queue_index;
uint64_t desc_addr, avail_addr, used_addr;
char err_str[64];
@ -399,7 +396,7 @@ virtio_user_del_queue(struct virtio_dev *vdev, struct virtqueue *vq)
* Here we just care about what information to deliver to vhost-user
* or vhost-kernel. So we just close ioeventfd for now.
*/
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
close(dev->callfds[vq->vq_queue_index]);
close(dev->kickfds[vq->vq_queue_index]);
@ -411,7 +408,7 @@ static void
virtio_user_notify_queue(struct virtio_dev *vdev, struct virtqueue *vq)
{
uint64_t buf = 1;
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
char err_str[64];
if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) {
@ -423,7 +420,7 @@ virtio_user_notify_queue(struct virtio_dev *vdev, struct virtqueue *vq)
static void
virtio_user_free(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
close(dev->vhostfd);
free(vdev->name);
@ -433,7 +430,7 @@ virtio_user_free(struct virtio_dev *vdev)
static void
virtio_user_dump_json_config(struct virtio_dev *vdev, struct spdk_json_write_ctx *w)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
struct virtio_user_dev *dev = vdev->ctx;
spdk_json_write_name(w, "type");
spdk_json_write_string(w, "user");