2017-05-30 21:13:50 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 17:14:30 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2017-05-30 21:13:50 +00:00
|
|
|
|
|
|
|
#include <linux/virtio_scsi.h>
|
2017-11-02 14:20:25 +00:00
|
|
|
#include <linux/virtio_pci.h>
|
|
|
|
#include <linux/virtio_config.h>
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-11-15 13:52:32 +00:00
|
|
|
#include <rte_config.h>
|
2017-05-30 21:13:50 +00:00
|
|
|
#include <rte_memcpy.h>
|
|
|
|
#include <rte_string_fns.h>
|
|
|
|
#include <rte_memzone.h>
|
|
|
|
#include <rte_malloc.h>
|
|
|
|
#include <rte_atomic.h>
|
|
|
|
#include <rte_branch_prediction.h>
|
|
|
|
#include <rte_pci.h>
|
|
|
|
#include <rte_common.h>
|
|
|
|
#include <rte_errno.h>
|
|
|
|
|
|
|
|
#include <rte_eal.h>
|
|
|
|
#include <rte_dev.h>
|
2017-10-14 09:57:03 +00:00
|
|
|
#include <rte_prefetch.h>
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-11-02 14:20:25 +00:00
|
|
|
#include "spdk/env.h"
|
2017-11-03 15:55:38 +00:00
|
|
|
#include "spdk/barrier.h"
|
|
|
|
|
2017-11-20 12:17:52 +00:00
|
|
|
#include "spdk_internal/virtio.h"
|
|
|
|
|
2017-11-23 13:40:39 +00:00
|
|
|
/* We use SMP memory barrier variants as all virtio_pci devices
|
|
|
|
* are purely virtual. All MMIO is executed on a CPU core, so
|
|
|
|
* there's no need to do full MMIO synchronization.
|
2017-11-03 15:55:38 +00:00
|
|
|
*/
|
2017-11-23 13:40:39 +00:00
|
|
|
#define virtio_mb() spdk_smp_mb()
|
|
|
|
#define virtio_rmb() spdk_smp_rmb()
|
|
|
|
#define virtio_wmb() spdk_smp_wmb()
|
2017-11-02 14:20:25 +00:00
|
|
|
|
2017-11-03 15:55:38 +00:00
|
|
|
/* Chain all the descriptors in the ring with an END */
|
|
|
|
static inline void
|
|
|
|
vring_desc_init(struct vring_desc *dp, uint16_t n)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
for (i = 0; i < n - 1; i++) {
|
2017-11-03 15:55:38 +00:00
|
|
|
dp[i].next = (uint16_t)(i + 1);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-11-03 15:55:38 +00:00
|
|
|
dp[i].next = VQ_RING_DESC_CHAIN_END;
|
|
|
|
}
|
|
|
|
|
2017-05-30 21:13:50 +00:00
|
|
|
static void
|
|
|
|
virtio_init_vring(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
int size = vq->vq_nentries;
|
|
|
|
struct vring *vr = &vq->vq_ring;
|
|
|
|
uint8_t *ring_mem = vq->vq_ring_virt_mem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reinitialise since virtio port might have been stopped and restarted
|
|
|
|
*/
|
|
|
|
memset(ring_mem, 0, vq->vq_ring_size);
|
|
|
|
vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
|
|
|
|
vq->vq_used_cons_idx = 0;
|
|
|
|
vq->vq_desc_head_idx = 0;
|
|
|
|
vq->vq_avail_idx = 0;
|
|
|
|
vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
|
|
|
|
vq->vq_free_cnt = vq->vq_nentries;
|
2017-12-08 19:55:50 +00:00
|
|
|
vq->req_start = VQ_RING_DESC_CHAIN_END;
|
|
|
|
vq->req_end = VQ_RING_DESC_CHAIN_END;
|
2018-06-16 12:51:13 +00:00
|
|
|
vq->reqs_finished = 0;
|
2017-05-30 21:13:50 +00:00
|
|
|
memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
|
|
|
|
|
|
|
|
vring_desc_init(vr->desc, size);
|
|
|
|
|
2018-06-16 12:51:13 +00:00
|
|
|
/* Tell the backend not to interrupt us.
|
|
|
|
* If F_EVENT_IDX is negotiated, we will always set incredibly high
|
|
|
|
* used event idx, so that we will practically never receive an
|
|
|
|
* interrupt. See virtqueue_req_flush()
|
|
|
|
*/
|
|
|
|
if (vq->vdev->negotiated_features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
|
|
|
|
vring_used_event(&vq->vq_ring) = UINT16_MAX;
|
|
|
|
} else {
|
|
|
|
vq->vq_ring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
|
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-09-01 17:33:53 +00:00
|
|
|
virtio_init_queue(struct virtio_dev *dev, uint16_t vtpci_queue_idx)
|
2017-05-30 21:13:50 +00:00
|
|
|
{
|
|
|
|
unsigned int vq_size, size;
|
|
|
|
struct virtqueue *vq;
|
2018-07-11 16:54:35 +00:00
|
|
|
int rc;
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "setting up queue: %"PRIu16"\n", vtpci_queue_idx);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the virtqueue size from the Queue Size field
|
|
|
|
* Always power of 2 and if 0 virtqueue does not exist
|
|
|
|
*/
|
2018-04-18 11:37:48 +00:00
|
|
|
vq_size = virtio_dev_backend_ops(dev)->get_queue_size(dev, vtpci_queue_idx);
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq_size: %u\n", vq_size);
|
2017-05-30 21:13:50 +00:00
|
|
|
if (vq_size == 0) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("virtqueue %"PRIu16" does not exist\n", vtpci_queue_idx);
|
2017-05-30 21:13:50 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rte_is_power_of_2(vq_size)) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("virtqueue %"PRIu16" size (%u) is not powerof 2\n",
|
|
|
|
vtpci_queue_idx, vq_size);
|
2017-05-30 21:13:50 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-04-08 21:14:17 +00:00
|
|
|
size = sizeof(*vq) + vq_size * sizeof(struct vq_desc_extra);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2019-04-08 21:35:25 +00:00
|
|
|
if (posix_memalign((void **)&vq, RTE_CACHE_LINE_SIZE, size)) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("can not allocate vq\n");
|
2017-05-30 21:13:50 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2019-04-19 01:40:39 +00:00
|
|
|
memset(vq, 0, size);
|
2017-09-01 17:33:53 +00:00
|
|
|
dev->vqs[vtpci_queue_idx] = vq;
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-09-01 17:33:53 +00:00
|
|
|
vq->vdev = dev;
|
2017-05-30 21:13:50 +00:00
|
|
|
vq->vq_queue_index = vtpci_queue_idx;
|
|
|
|
vq->vq_nentries = vq_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserve a memzone for vring elements
|
|
|
|
*/
|
|
|
|
size = vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN);
|
|
|
|
vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN);
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vring_size: %u, rounded_vring_size: %u\n",
|
2017-10-18 17:06:51 +00:00
|
|
|
size, vq->vq_ring_size);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2018-06-27 10:33:19 +00:00
|
|
|
vq->owner_thread = NULL;
|
|
|
|
|
2018-07-11 16:54:35 +00:00
|
|
|
rc = virtio_dev_backend_ops(dev)->setup_queue(dev, vq);
|
|
|
|
if (rc < 0) {
|
2018-06-27 10:33:19 +00:00
|
|
|
SPDK_ERRLOG("setup_queue failed\n");
|
2019-04-08 21:35:25 +00:00
|
|
|
free(vq);
|
2018-07-11 15:43:15 +00:00
|
|
|
dev->vqs[vtpci_queue_idx] = NULL;
|
2018-07-11 16:54:35 +00:00
|
|
|
return rc;
|
2017-05-30 21:13:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_mem: 0x%" PRIx64 "\n",
|
2017-11-03 16:37:51 +00:00
|
|
|
vq->vq_ring_mem);
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "vq->vq_ring_virt_mem: 0x%" PRIx64 "\n",
|
2017-11-03 16:37:51 +00:00
|
|
|
(uint64_t)(uintptr_t)vq->vq_ring_virt_mem);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
|
|
|
virtio_init_vring(vq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-09-01 17:33:53 +00:00
|
|
|
virtio_free_queues(struct virtio_dev *dev)
|
2017-05-30 21:13:50 +00:00
|
|
|
{
|
2017-10-10 15:50:20 +00:00
|
|
|
uint16_t nr_vq = dev->max_queues;
|
2017-05-30 21:13:50 +00:00
|
|
|
struct virtqueue *vq;
|
|
|
|
uint16_t i;
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (dev->vqs == NULL) {
|
2017-05-30 21:13:50 +00:00
|
|
|
return;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nr_vq; i++) {
|
2017-09-01 17:33:53 +00:00
|
|
|
vq = dev->vqs[i];
|
2017-12-07 23:23:48 +00:00
|
|
|
if (!vq) {
|
2017-05-30 21:13:50 +00:00
|
|
|
continue;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2018-06-27 11:41:52 +00:00
|
|
|
virtio_dev_backend_ops(dev)->del_queue(dev, vq);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2019-04-08 21:35:25 +00:00
|
|
|
free(vq);
|
2017-09-01 17:33:53 +00:00
|
|
|
dev->vqs[i] = NULL;
|
2017-05-30 21:13:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 21:35:25 +00:00
|
|
|
free(dev->vqs);
|
2017-09-01 17:33:53 +00:00
|
|
|
dev->vqs = NULL;
|
2017-05-30 21:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-12-27 14:51:17 +00:00
|
|
|
virtio_alloc_queues(struct virtio_dev *dev, uint16_t request_vq_num, uint16_t fixed_vq_num)
|
2017-05-30 21:13:50 +00:00
|
|
|
{
|
2017-12-27 14:51:17 +00:00
|
|
|
uint16_t nr_vq;
|
2017-05-30 21:13:50 +00:00
|
|
|
uint16_t i;
|
|
|
|
int ret;
|
|
|
|
|
2017-12-27 14:51:17 +00:00
|
|
|
nr_vq = request_vq_num + fixed_vq_num;
|
|
|
|
if (nr_vq == 0) {
|
|
|
|
/* perfectly fine to have a device with no virtqueues. */
|
2017-11-20 17:22:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-27 14:51:17 +00:00
|
|
|
assert(dev->vqs == NULL);
|
2019-04-08 21:35:25 +00:00
|
|
|
dev->vqs = calloc(1, sizeof(struct virtqueue *) * nr_vq);
|
2017-09-01 17:33:53 +00:00
|
|
|
if (!dev->vqs) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("failed to allocate %"PRIu16" vqs\n", nr_vq);
|
2017-05-30 21:13:50 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nr_vq; i++) {
|
2017-09-01 17:33:53 +00:00
|
|
|
ret = virtio_init_queue(dev, i);
|
2017-05-30 21:13:50 +00:00
|
|
|
if (ret < 0) {
|
2017-09-01 17:33:53 +00:00
|
|
|
virtio_free_queues(dev);
|
2017-05-30 21:13:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-27 14:51:17 +00:00
|
|
|
dev->max_queues = nr_vq;
|
|
|
|
dev->fixed_queues_num = fixed_vq_num;
|
2017-05-30 21:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:50:20 +00:00
|
|
|
/**
|
|
|
|
* Negotiate virtio features. For virtio_user this will also set
|
|
|
|
* dev->modern flag if VIRTIO_F_VERSION_1 flag is negotiated.
|
2017-09-04 13:54:42 +00:00
|
|
|
*/
|
2017-05-30 21:13:50 +00:00
|
|
|
static int
|
2017-09-01 17:33:53 +00:00
|
|
|
virtio_negotiate_features(struct virtio_dev *dev, uint64_t req_features)
|
2017-05-30 21:13:50 +00:00
|
|
|
{
|
2017-11-02 16:10:56 +00:00
|
|
|
uint64_t host_features = virtio_dev_backend_ops(dev)->get_features(dev);
|
2017-10-05 12:46:24 +00:00
|
|
|
int rc;
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "guest features = %" PRIx64 "\n", req_features);
|
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "device features = %" PRIx64 "\n", host_features);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-11-02 16:10:56 +00:00
|
|
|
rc = virtio_dev_backend_ops(dev)->set_features(dev, req_features & host_features);
|
2017-10-05 12:46:24 +00:00
|
|
|
if (rc != 0) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("failed to negotiate device features.\n");
|
2018-07-11 16:54:35 +00:00
|
|
|
return rc;
|
2017-09-04 13:54:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "negotiated features = %" PRIx64 "\n",
|
2017-10-14 10:43:58 +00:00
|
|
|
dev->negotiated_features);
|
2017-10-05 12:46:24 +00:00
|
|
|
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_set_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
|
|
|
|
if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_FEATURES_OK)) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_ERRLOG("failed to set FEATURES_OK status!\n");
|
2018-08-01 09:56:16 +00:00
|
|
|
/* either the device failed, or we offered some features that
|
|
|
|
* depend on other, not offered features.
|
|
|
|
*/
|
2018-07-11 16:54:35 +00:00
|
|
|
return -EINVAL;
|
2017-05-30 21:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:24:24 +00:00
|
|
|
int
|
2018-01-15 12:06:58 +00:00
|
|
|
virtio_dev_construct(struct virtio_dev *vdev, const char *name,
|
|
|
|
const struct virtio_dev_ops *ops, void *ctx)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2018-01-15 12:06:58 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
vdev->name = strdup(name);
|
|
|
|
if (vdev->name == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = pthread_mutex_init(&vdev->mutex, NULL);
|
|
|
|
if (rc != 0) {
|
|
|
|
free(vdev->name);
|
|
|
|
return -rc;
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:20:25 +00:00
|
|
|
vdev->backend_ops = ops;
|
|
|
|
vdev->ctx = ctx;
|
|
|
|
|
2017-11-20 18:24:24 +00:00
|
|
|
return 0;
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 15:04:08 +00:00
|
|
|
int
|
2017-12-27 14:51:17 +00:00
|
|
|
virtio_dev_reset(struct virtio_dev *dev, uint64_t req_features)
|
2017-05-30 21:13:50 +00:00
|
|
|
{
|
2017-12-21 15:01:06 +00:00
|
|
|
req_features |= (1ULL << VIRTIO_F_VERSION_1);
|
|
|
|
|
2017-11-20 18:24:24 +00:00
|
|
|
virtio_dev_stop(dev);
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_set_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
|
2018-03-30 17:10:00 +00:00
|
|
|
if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_ACKNOWLEDGE)) {
|
|
|
|
SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_ACKNOWLEDGE status.\n");
|
2018-07-11 16:54:35 +00:00
|
|
|
return -EIO;
|
2018-03-30 17:10:00 +00:00
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_set_status(dev, VIRTIO_CONFIG_S_DRIVER);
|
2018-03-30 17:10:00 +00:00
|
|
|
if (!(virtio_dev_get_status(dev) & VIRTIO_CONFIG_S_DRIVER)) {
|
|
|
|
SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_DRIVER status.\n");
|
2018-07-11 16:54:35 +00:00
|
|
|
return -EIO;
|
2018-03-30 17:10:00 +00:00
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-12-27 14:51:17 +00:00
|
|
|
return virtio_negotiate_features(dev, req_features);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
virtio_dev_start(struct virtio_dev *vdev, uint16_t max_queues, uint16_t fixed_queue_num)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = virtio_alloc_queues(vdev, max_queues, fixed_queue_num);
|
2017-12-07 23:23:48 +00:00
|
|
|
if (ret < 0) {
|
2017-05-30 21:13:50 +00:00
|
|
|
return ret;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-05-30 21:13:50 +00:00
|
|
|
|
2017-12-27 14:51:17 +00:00
|
|
|
virtio_dev_set_status(vdev, VIRTIO_CONFIG_S_DRIVER_OK);
|
2018-03-30 17:10:00 +00:00
|
|
|
if (!(virtio_dev_get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
|
|
|
SPDK_ERRLOG("Failed to set VIRTIO_CONFIG_S_DRIVER_OK status.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-30 21:13:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-29 11:03:45 +00:00
|
|
|
void
|
2017-11-20 18:24:24 +00:00
|
|
|
virtio_dev_destruct(struct virtio_dev *dev)
|
2017-09-29 11:03:45 +00:00
|
|
|
{
|
2017-11-20 18:24:24 +00:00
|
|
|
virtio_dev_backend_ops(dev)->destruct_dev(dev);
|
2017-11-15 12:25:38 +00:00
|
|
|
pthread_mutex_destroy(&dev->mutex);
|
2018-01-15 12:06:58 +00:00
|
|
|
free(dev->name);
|
2017-09-29 11:03:45 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 09:57:03 +00:00
|
|
|
static void
|
|
|
|
vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx)
|
|
|
|
{
|
|
|
|
struct vring_desc *dp, *dp_tail;
|
|
|
|
struct vq_desc_extra *dxp;
|
|
|
|
uint16_t desc_idx_last = desc_idx;
|
|
|
|
|
|
|
|
dp = &vq->vq_ring.desc[desc_idx];
|
|
|
|
dxp = &vq->vq_descx[desc_idx];
|
|
|
|
vq->vq_free_cnt = (uint16_t)(vq->vq_free_cnt + dxp->ndescs);
|
|
|
|
if ((dp->flags & VRING_DESC_F_INDIRECT) == 0) {
|
|
|
|
while (dp->flags & VRING_DESC_F_NEXT) {
|
|
|
|
desc_idx_last = dp->next;
|
|
|
|
dp = &vq->vq_ring.desc[dp->next];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dxp->ndescs = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must append the existing free chain, if any, to the end of
|
|
|
|
* newly freed chain. If the virtqueue was completely used, then
|
|
|
|
* head would be VQ_RING_DESC_CHAIN_END (ASSERTed above).
|
|
|
|
*/
|
|
|
|
if (vq->vq_desc_tail_idx == VQ_RING_DESC_CHAIN_END) {
|
|
|
|
vq->vq_desc_head_idx = desc_idx;
|
|
|
|
} else {
|
|
|
|
dp_tail = &vq->vq_ring.desc[vq->vq_desc_tail_idx];
|
|
|
|
dp_tail->next = desc_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
vq->vq_desc_tail_idx = desc_idx_last;
|
|
|
|
dp->next = VQ_RING_DESC_CHAIN_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16_t
|
2017-12-01 23:33:42 +00:00
|
|
|
virtqueue_dequeue_burst_rx(struct virtqueue *vq, void **rx_pkts,
|
2017-10-14 09:57:03 +00:00
|
|
|
uint32_t *len, uint16_t num)
|
|
|
|
{
|
|
|
|
struct vring_used_elem *uep;
|
2019-06-26 10:55:19 +00:00
|
|
|
void *cookie;
|
2017-10-14 09:57:03 +00:00
|
|
|
uint16_t used_idx, desc_idx;
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
/* Caller does the check */
|
|
|
|
for (i = 0; i < num ; i++) {
|
|
|
|
used_idx = (uint16_t)(vq->vq_used_cons_idx & (vq->vq_nentries - 1));
|
|
|
|
uep = &vq->vq_ring.used->ring[used_idx];
|
|
|
|
desc_idx = (uint16_t) uep->id;
|
|
|
|
len[i] = uep->len;
|
2019-06-26 10:55:19 +00:00
|
|
|
cookie = vq->vq_descx[desc_idx].cookie;
|
2017-10-14 09:57:03 +00:00
|
|
|
|
|
|
|
if (spdk_unlikely(cookie == NULL)) {
|
2017-10-14 10:43:58 +00:00
|
|
|
SPDK_WARNLOG("vring descriptor with no mbuf cookie at %"PRIu16"\n",
|
|
|
|
vq->vq_used_cons_idx);
|
2017-10-14 09:57:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rte_prefetch0(cookie);
|
|
|
|
rx_pkts[i] = cookie;
|
|
|
|
vq->vq_used_cons_idx++;
|
|
|
|
vq_ring_free_chain(vq, desc_idx);
|
|
|
|
vq->vq_descx[desc_idx].cookie = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-06-16 14:53:24 +00:00
|
|
|
static void
|
|
|
|
finish_req(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
struct vring_desc *desc;
|
|
|
|
uint16_t avail_idx;
|
|
|
|
|
|
|
|
desc = &vq->vq_ring.desc[vq->req_end];
|
|
|
|
desc->flags &= ~VRING_DESC_F_NEXT;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the head of the descriptor chain into the next slot and make
|
|
|
|
* it usable to the host. The chain is made available now rather than
|
|
|
|
* deferring to virtqueue_req_flush() in the hopes that if the host is
|
|
|
|
* currently running on another CPU, we can keep it processing the new
|
|
|
|
* descriptor.
|
|
|
|
*/
|
|
|
|
avail_idx = (uint16_t)(vq->vq_avail_idx & (vq->vq_nentries - 1));
|
|
|
|
vq->vq_ring.avail->ring[avail_idx] = vq->req_start;
|
|
|
|
vq->vq_avail_idx++;
|
|
|
|
vq->req_end = VQ_RING_DESC_CHAIN_END;
|
|
|
|
virtio_wmb();
|
|
|
|
vq->vq_ring.avail->idx = vq->vq_avail_idx;
|
2018-06-16 12:51:13 +00:00
|
|
|
vq->reqs_finished++;
|
2018-06-16 14:53:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
int
|
|
|
|
virtqueue_req_start(struct virtqueue *vq, void *cookie, int iovcnt)
|
2017-10-14 09:57:03 +00:00
|
|
|
{
|
2017-12-08 19:55:50 +00:00
|
|
|
struct vq_desc_extra *dxp;
|
|
|
|
|
|
|
|
if (iovcnt > vq->vq_free_cnt) {
|
2018-01-03 11:16:04 +00:00
|
|
|
return iovcnt > vq->vq_nentries ? -EINVAL : -ENOMEM;
|
2017-12-08 19:55:50 +00:00
|
|
|
}
|
|
|
|
|
2018-06-16 14:53:24 +00:00
|
|
|
if (vq->req_end != VQ_RING_DESC_CHAIN_END) {
|
|
|
|
finish_req(vq);
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
vq->req_start = vq->vq_desc_head_idx;
|
|
|
|
dxp = &vq->vq_descx[vq->req_start];
|
|
|
|
dxp->cookie = cookie;
|
|
|
|
dxp->ndescs = 0;
|
|
|
|
|
|
|
|
return 0;
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
void
|
|
|
|
virtqueue_req_flush(struct virtqueue *vq)
|
2017-10-14 09:57:03 +00:00
|
|
|
{
|
2018-06-16 12:51:13 +00:00
|
|
|
uint16_t reqs_finished;
|
|
|
|
|
2018-06-16 14:53:24 +00:00
|
|
|
if (vq->req_end == VQ_RING_DESC_CHAIN_END) {
|
|
|
|
/* no non-empty requests have been started */
|
2017-12-08 19:55:50 +00:00
|
|
|
return;
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-16 14:53:24 +00:00
|
|
|
finish_req(vq);
|
2018-01-26 00:01:40 +00:00
|
|
|
virtio_mb();
|
2018-06-16 14:53:24 +00:00
|
|
|
|
2018-06-16 12:51:13 +00:00
|
|
|
reqs_finished = vq->reqs_finished;
|
|
|
|
vq->reqs_finished = 0;
|
|
|
|
|
|
|
|
if (vq->vdev->negotiated_features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
|
|
|
|
/* Set used event idx to a value the device will never reach.
|
|
|
|
* This effectively disables interrupts.
|
|
|
|
*/
|
|
|
|
vring_used_event(&vq->vq_ring) = vq->vq_used_cons_idx - vq->vq_nentries - 1;
|
|
|
|
|
|
|
|
if (!vring_need_event(vring_avail_event(&vq->vq_ring),
|
|
|
|
vq->vq_avail_idx,
|
|
|
|
vq->vq_avail_idx - reqs_finished)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY) {
|
|
|
|
return;
|
2017-12-08 19:55:50 +00:00
|
|
|
}
|
2018-06-16 12:51:13 +00:00
|
|
|
|
|
|
|
virtio_dev_backend_ops(vq->vdev)->notify_queue(vq->vdev, vq);
|
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_VIRTIO_DEV, "Notified backend after xmit\n");
|
2017-12-08 19:55:50 +00:00
|
|
|
}
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
void
|
|
|
|
virtqueue_req_abort(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
struct vring_desc *desc;
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
if (vq->req_start == VQ_RING_DESC_CHAIN_END) {
|
|
|
|
/* no requests have been started */
|
|
|
|
return;
|
|
|
|
}
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
desc = &vq->vq_ring.desc[vq->req_end];
|
|
|
|
desc->flags &= ~VRING_DESC_F_NEXT;
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
vq_ring_free_chain(vq, vq->req_start);
|
|
|
|
vq->req_start = VQ_RING_DESC_CHAIN_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
virtqueue_req_add_iovs(struct virtqueue *vq, struct iovec *iovs, uint16_t iovcnt,
|
|
|
|
enum spdk_virtio_desc_type desc_type)
|
|
|
|
{
|
|
|
|
struct vring_desc *desc;
|
|
|
|
struct vq_desc_extra *dxp;
|
|
|
|
uint16_t i, prev_head, new_head;
|
|
|
|
|
|
|
|
assert(vq->req_start != VQ_RING_DESC_CHAIN_END);
|
|
|
|
assert(iovcnt <= vq->vq_free_cnt);
|
|
|
|
|
|
|
|
/* TODO use indirect descriptors if iovcnt is high enough
|
|
|
|
* or the caller specifies SPDK_VIRTIO_DESC_F_INDIRECT
|
|
|
|
*/
|
|
|
|
|
2017-12-22 10:15:53 +00:00
|
|
|
prev_head = vq->req_end;
|
|
|
|
new_head = vq->vq_desc_head_idx;
|
2017-12-08 19:55:50 +00:00
|
|
|
for (i = 0; i < iovcnt; ++i) {
|
|
|
|
desc = &vq->vq_ring.desc[new_head];
|
|
|
|
|
|
|
|
if (!vq->vdev->is_hw) {
|
|
|
|
desc->addr = (uintptr_t)iovs[i].iov_base;
|
|
|
|
} else {
|
2018-12-28 11:59:21 +00:00
|
|
|
desc->addr = spdk_vtophys(iovs[i].iov_base, NULL);
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
2017-12-08 19:55:50 +00:00
|
|
|
|
|
|
|
desc->len = iovs[i].iov_len;
|
|
|
|
/* always set NEXT flag. unset it on the last descriptor
|
|
|
|
* in the request-ending function.
|
|
|
|
*/
|
|
|
|
desc->flags = desc_type | VRING_DESC_F_NEXT;
|
|
|
|
|
|
|
|
prev_head = new_head;
|
|
|
|
new_head = desc->next;
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 19:55:50 +00:00
|
|
|
dxp = &vq->vq_descx[vq->req_start];
|
|
|
|
dxp->ndescs += iovcnt;
|
|
|
|
|
|
|
|
vq->req_end = prev_head;
|
|
|
|
vq->vq_desc_head_idx = new_head;
|
2018-07-26 21:25:45 +00:00
|
|
|
vq->vq_free_cnt = (uint16_t)(vq->vq_free_cnt - iovcnt);
|
2017-10-14 09:57:03 +00:00
|
|
|
if (vq->vq_desc_head_idx == VQ_RING_DESC_CHAIN_END) {
|
|
|
|
assert(vq->vq_free_cnt == 0);
|
|
|
|
vq->vq_desc_tail_idx = VQ_RING_DESC_CHAIN_END;
|
|
|
|
}
|
2017-12-08 19:55:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 09:57:03 +00:00
|
|
|
#define DESC_PER_CACHELINE (RTE_CACHE_LINE_SIZE / sizeof(struct vring_desc))
|
|
|
|
uint16_t
|
2017-12-01 23:33:42 +00:00
|
|
|
virtio_recv_pkts(struct virtqueue *vq, void **io, uint32_t *len, uint16_t nb_pkts)
|
2017-10-14 09:57:03 +00:00
|
|
|
{
|
2017-12-01 23:33:42 +00:00
|
|
|
uint16_t nb_used, num;
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2018-02-05 19:45:09 +00:00
|
|
|
nb_used = vq->vq_ring.used->idx - vq->vq_used_cons_idx;
|
2017-10-14 09:57:03 +00:00
|
|
|
virtio_rmb();
|
|
|
|
|
|
|
|
num = (uint16_t)(spdk_likely(nb_used <= nb_pkts) ? nb_used : nb_pkts);
|
2017-12-07 23:23:48 +00:00
|
|
|
if (spdk_likely(num > DESC_PER_CACHELINE)) {
|
2017-10-14 09:57:03 +00:00
|
|
|
num = num - ((vq->vq_used_cons_idx + num) % DESC_PER_CACHELINE);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-10-14 09:57:03 +00:00
|
|
|
|
2018-06-16 13:00:04 +00:00
|
|
|
return virtqueue_dequeue_burst_rx(vq, io, len, num);
|
2017-10-14 09:57:03 +00:00
|
|
|
}
|
2017-10-14 10:43:58 +00:00
|
|
|
|
2017-10-10 18:44:35 +00:00
|
|
|
int
|
|
|
|
virtio_dev_acquire_queue(struct virtio_dev *vdev, uint16_t index)
|
|
|
|
{
|
|
|
|
struct virtqueue *vq = NULL;
|
|
|
|
|
|
|
|
if (index >= vdev->max_queues) {
|
|
|
|
SPDK_ERRLOG("requested vq index %"PRIu16" exceeds max queue count %"PRIu16".\n",
|
|
|
|
index, vdev->max_queues);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->mutex);
|
|
|
|
vq = vdev->vqs[index];
|
2017-11-23 19:15:23 +00:00
|
|
|
if (vq == NULL || vq->owner_thread != NULL) {
|
2017-10-10 18:44:35 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-23 19:15:23 +00:00
|
|
|
vq->owner_thread = spdk_get_thread();
|
2017-10-10 18:44:35 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
virtio_dev_find_and_acquire_queue(struct virtio_dev *vdev, uint16_t start_index)
|
|
|
|
{
|
|
|
|
struct virtqueue *vq = NULL;
|
|
|
|
uint16_t i;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->mutex);
|
|
|
|
for (i = start_index; i < vdev->max_queues; ++i) {
|
|
|
|
vq = vdev->vqs[i];
|
2017-11-23 19:15:23 +00:00
|
|
|
if (vq != NULL && vq->owner_thread == NULL) {
|
2017-10-10 18:44:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vq == NULL || i == vdev->max_queues) {
|
|
|
|
SPDK_ERRLOG("no more unused virtio queues with idx >= %"PRIu16".\n", start_index);
|
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-23 19:15:23 +00:00
|
|
|
vq->owner_thread = spdk_get_thread();
|
2017-10-10 18:44:35 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-11-23 19:34:44 +00:00
|
|
|
struct spdk_thread *
|
|
|
|
virtio_dev_queue_get_thread(struct virtio_dev *vdev, uint16_t index)
|
2017-10-11 11:45:53 +00:00
|
|
|
{
|
2017-11-23 19:34:44 +00:00
|
|
|
struct spdk_thread *thread = NULL;
|
2017-10-11 11:45:53 +00:00
|
|
|
|
|
|
|
if (index >= vdev->max_queues) {
|
|
|
|
SPDK_ERRLOG("given vq index %"PRIu16" exceeds max queue count %"PRIu16"\n",
|
|
|
|
index, vdev->max_queues);
|
2018-04-18 21:04:11 +00:00
|
|
|
abort(); /* This is not recoverable */
|
2017-10-11 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->mutex);
|
2018-04-18 21:04:11 +00:00
|
|
|
thread = vdev->vqs[index]->owner_thread;
|
2017-10-11 11:45:53 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
|
2017-11-23 19:34:44 +00:00
|
|
|
return thread;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
virtio_dev_queue_is_acquired(struct virtio_dev *vdev, uint16_t index)
|
|
|
|
{
|
|
|
|
return virtio_dev_queue_get_thread(vdev, index) != NULL;
|
2017-10-11 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 18:44:35 +00:00
|
|
|
void
|
|
|
|
virtio_dev_release_queue(struct virtio_dev *vdev, uint16_t index)
|
|
|
|
{
|
|
|
|
struct virtqueue *vq = NULL;
|
|
|
|
|
|
|
|
if (index >= vdev->max_queues) {
|
|
|
|
SPDK_ERRLOG("given vq index %"PRIu16" exceeds max queue count %"PRIu16".\n",
|
|
|
|
index, vdev->max_queues);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&vdev->mutex);
|
|
|
|
vq = vdev->vqs[index];
|
|
|
|
if (vq == NULL) {
|
|
|
|
SPDK_ERRLOG("virtqueue at index %"PRIu16" is not initialized.\n", index);
|
2017-10-16 20:44:51 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
2017-10-10 18:44:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-23 19:15:23 +00:00
|
|
|
assert(vq->owner_thread == spdk_get_thread());
|
|
|
|
vq->owner_thread = NULL;
|
2017-10-10 18:44:35 +00:00
|
|
|
pthread_mutex_unlock(&vdev->mutex);
|
|
|
|
}
|
|
|
|
|
2018-07-02 11:13:52 +00:00
|
|
|
int
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_read_dev_config(struct virtio_dev *dev, size_t offset,
|
|
|
|
void *dst, int length)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2018-07-02 11:13:52 +00:00
|
|
|
return virtio_dev_backend_ops(dev)->read_dev_cfg(dev, offset, dst, length);
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:13:52 +00:00
|
|
|
int
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_write_dev_config(struct virtio_dev *dev, size_t offset,
|
|
|
|
const void *src, int length)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2018-07-02 11:13:52 +00:00
|
|
|
return virtio_dev_backend_ops(dev)->write_dev_cfg(dev, offset, src, length);
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-20 18:24:24 +00:00
|
|
|
virtio_dev_stop(struct virtio_dev *dev)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_backend_ops(dev)->set_status(dev, VIRTIO_CONFIG_S_RESET);
|
2017-11-02 14:20:25 +00:00
|
|
|
/* flush status write */
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_backend_ops(dev)->get_status(dev);
|
2017-12-27 14:51:17 +00:00
|
|
|
virtio_free_queues(dev);
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_set_status(struct virtio_dev *dev, uint8_t status)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2017-12-07 23:23:48 +00:00
|
|
|
if (status != VIRTIO_CONFIG_S_RESET) {
|
2017-11-02 16:10:56 +00:00
|
|
|
status |= virtio_dev_backend_ops(dev)->get_status(dev);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-11-02 14:20:25 +00:00
|
|
|
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_backend_ops(dev)->set_status(dev, status);
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_get_status(struct virtio_dev *dev)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2017-11-02 16:10:56 +00:00
|
|
|
return virtio_dev_backend_ops(dev)->get_status(dev);
|
2017-11-02 14:20:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 14:41:31 +00:00
|
|
|
const struct virtio_dev_ops *
|
2017-11-02 16:10:56 +00:00
|
|
|
virtio_dev_backend_ops(struct virtio_dev *dev)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
|
|
|
return dev->backend_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-03-27 13:45:10 +00:00
|
|
|
virtio_dev_dump_json_info(struct virtio_dev *hw, struct spdk_json_write_ctx *w)
|
2017-11-02 14:20:25 +00:00
|
|
|
{
|
2019-02-01 05:41:15 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "virtio");
|
2017-11-02 14:20:25 +00:00
|
|
|
|
2019-02-01 05:41:15 +00:00
|
|
|
spdk_json_write_named_uint32(w, "vq_count", hw->max_queues);
|
2017-11-02 14:20:25 +00:00
|
|
|
|
2019-02-01 05:41:15 +00:00
|
|
|
spdk_json_write_named_uint32(w, "vq_size",
|
|
|
|
virtio_dev_backend_ops(hw)->get_queue_size(hw, 0));
|
2017-11-02 14:20:25 +00:00
|
|
|
|
2018-03-27 13:45:10 +00:00
|
|
|
virtio_dev_backend_ops(hw)->dump_json_info(hw, w);
|
2017-11-02 14:20:25 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("virtio_dev", SPDK_LOG_VIRTIO_DEV)
|