|
|
b91920 |
From 74bbcd238093edc81b1a1f0b9b6e0d3c3fe32584 Mon Sep 17 00:00:00 2001
|
|
|
b91920 |
From: Jens Freimann <jfreimann@redhat.com>
|
|
|
b91920 |
Date: Fri, 11 Jan 2019 10:39:29 +0100
|
|
|
b91920 |
Subject: [PATCH] net/virtio-user: support control VQ for packed
|
|
|
b91920 |
|
|
|
b91920 |
[ upstream commit 48a4464029a7f76dfb2c1f09146a391917b075e5 ]
|
|
|
b91920 |
|
|
|
b91920 |
Add support to virtio-user for control virtqueues.
|
|
|
b91920 |
|
|
|
b91920 |
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
|
|
|
b91920 |
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
b91920 |
(cherry picked from commit 48a4464029a7f76dfb2c1f09146a391917b075e5)
|
|
|
b91920 |
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
|
|
|
b91920 |
---
|
|
|
b91920 |
.../net/virtio/virtio_user/virtio_user_dev.c | 102 ++++++++++++++++--
|
|
|
b91920 |
.../net/virtio/virtio_user/virtio_user_dev.h | 15 ++-
|
|
|
b91920 |
drivers/net/virtio/virtio_user_ethdev.c | 56 +++++++++-
|
|
|
b91920 |
3 files changed, 157 insertions(+), 16 deletions(-)
|
|
|
b91920 |
|
|
|
b91920 |
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
|
|
|
b91920 |
index 2caaaad5f..83d3fb531 100644
|
|
|
b91920 |
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
|
|
|
b91920 |
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
|
|
|
b91920 |
@@ -43,15 +43,26 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
|
|
|
b91920 |
struct vhost_vring_file file;
|
|
|
b91920 |
struct vhost_vring_state state;
|
|
|
b91920 |
struct vring *vring = &dev->vrings[queue_sel];
|
|
|
b91920 |
+ struct vring_packed *pq_vring = &dev->packed_vrings[queue_sel];
|
|
|
b91920 |
struct vhost_vring_addr addr = {
|
|
|
b91920 |
.index = queue_sel,
|
|
|
b91920 |
- .desc_user_addr = (uint64_t)(uintptr_t)vring->desc,
|
|
|
b91920 |
- .avail_user_addr = (uint64_t)(uintptr_t)vring->avail,
|
|
|
b91920 |
- .used_user_addr = (uint64_t)(uintptr_t)vring->used,
|
|
|
b91920 |
.log_guest_addr = 0,
|
|
|
b91920 |
.flags = 0, /* disable log */
|
|
|
b91920 |
};
|
|
|
b91920 |
|
|
|
b91920 |
+ if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
|
|
|
b91920 |
+ addr.desc_user_addr =
|
|
|
b91920 |
+ (uint64_t)(uintptr_t)pq_vring->desc_packed;
|
|
|
b91920 |
+ addr.avail_user_addr =
|
|
|
b91920 |
+ (uint64_t)(uintptr_t)pq_vring->driver_event;
|
|
|
b91920 |
+ addr.used_user_addr =
|
|
|
b91920 |
+ (uint64_t)(uintptr_t)pq_vring->device_event;
|
|
|
b91920 |
+ } else {
|
|
|
b91920 |
+ addr.desc_user_addr = (uint64_t)(uintptr_t)vring->desc;
|
|
|
b91920 |
+ addr.avail_user_addr = (uint64_t)(uintptr_t)vring->avail;
|
|
|
b91920 |
+ addr.used_user_addr = (uint64_t)(uintptr_t)vring->used;
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+
|
|
|
b91920 |
state.index = queue_sel;
|
|
|
b91920 |
state.num = vring->num;
|
|
|
b91920 |
dev->ops->send_request(dev, VHOST_USER_SET_VRING_NUM, &state);
|
|
|
b91920 |
@@ -468,15 +479,8 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
|
|
|
b91920 |
if (!in_order)
|
|
|
b91920 |
dev->unsupported_features |= (1ull << VIRTIO_F_IN_ORDER);
|
|
|
b91920 |
|
|
|
b91920 |
- if (packed_vq) {
|
|
|
b91920 |
- if (cq) {
|
|
|
b91920 |
- PMD_INIT_LOG(ERR, "control vq not supported yet with "
|
|
|
b91920 |
- "packed virtqueues\n");
|
|
|
b91920 |
- return -1;
|
|
|
b91920 |
- }
|
|
|
b91920 |
- } else {
|
|
|
b91920 |
+ if (!packed_vq)
|
|
|
b91920 |
dev->unsupported_features |= (1ull << VIRTIO_F_RING_PACKED);
|
|
|
b91920 |
- }
|
|
|
b91920 |
|
|
|
b91920 |
if (dev->mac_specified)
|
|
|
b91920 |
dev->frontend_features |= (1ull << VIRTIO_NET_F_MAC);
|
|
|
b91920 |
@@ -621,6 +625,82 @@ virtio_user_handle_ctrl_msg(struct virtio_user_dev *dev, struct vring *vring,
|
|
|
b91920 |
return n_descs;
|
|
|
b91920 |
}
|
|
|
b91920 |
|
|
|
b91920 |
+static inline int
|
|
|
b91920 |
+desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
|
|
|
b91920 |
+{
|
|
|
b91920 |
+ return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL(1)) &&
|
|
|
b91920 |
+ wrap_counter != !!(desc->flags & VRING_DESC_F_USED(1));
|
|
|
b91920 |
+}
|
|
|
b91920 |
+
|
|
|
b91920 |
+static uint32_t
|
|
|
b91920 |
+virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
|
|
|
b91920 |
+ struct vring_packed *vring,
|
|
|
b91920 |
+ uint16_t idx_hdr)
|
|
|
b91920 |
+{
|
|
|
b91920 |
+ struct virtio_net_ctrl_hdr *hdr;
|
|
|
b91920 |
+ virtio_net_ctrl_ack status = ~0;
|
|
|
b91920 |
+ uint16_t idx_data, idx_status;
|
|
|
b91920 |
+ /* initialize to one, header is first */
|
|
|
b91920 |
+ uint32_t n_descs = 1;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ /* locate desc for header, data, and status */
|
|
|
b91920 |
+ idx_data = idx_hdr + 1;
|
|
|
b91920 |
+ if (idx_data >= dev->queue_size)
|
|
|
b91920 |
+ idx_data -= dev->queue_size;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ n_descs++;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ idx_status = idx_data;
|
|
|
b91920 |
+ while (vring->desc_packed[idx_status].flags & VRING_DESC_F_NEXT) {
|
|
|
b91920 |
+ idx_status++;
|
|
|
b91920 |
+ if (idx_status >= dev->queue_size)
|
|
|
b91920 |
+ idx_status -= dev->queue_size;
|
|
|
b91920 |
+ n_descs++;
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+
|
|
|
b91920 |
+ hdr = (void *)(uintptr_t)vring->desc_packed[idx_hdr].addr;
|
|
|
b91920 |
+ if (hdr->class == VIRTIO_NET_CTRL_MQ &&
|
|
|
b91920 |
+ hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
|
|
|
b91920 |
+ uint16_t queues;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ queues = *(uint16_t *)(uintptr_t)
|
|
|
b91920 |
+ vring->desc_packed[idx_data].addr;
|
|
|
b91920 |
+ status = virtio_user_handle_mq(dev, queues);
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+
|
|
|
b91920 |
+ /* Update status */
|
|
|
b91920 |
+ *(virtio_net_ctrl_ack *)(uintptr_t)
|
|
|
b91920 |
+ vring->desc_packed[idx_status].addr = status;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ return n_descs;
|
|
|
b91920 |
+}
|
|
|
b91920 |
+
|
|
|
b91920 |
+void
|
|
|
b91920 |
+virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
|
|
|
b91920 |
+{
|
|
|
b91920 |
+ struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
|
|
|
b91920 |
+ struct vring_packed *vring = &dev->packed_vrings[queue_idx];
|
|
|
b91920 |
+ uint16_t id, n_descs;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ while (desc_is_avail(&vring->desc_packed[vq->used_idx],
|
|
|
b91920 |
+ vq->used_wrap_counter)) {
|
|
|
b91920 |
+ id = vring->desc_packed[vq->used_idx].id;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ n_descs = virtio_user_handle_ctrl_msg_pq(dev, vring, id);
|
|
|
b91920 |
+
|
|
|
b91920 |
+ do {
|
|
|
b91920 |
+ vring->desc_packed[vq->used_idx].flags =
|
|
|
b91920 |
+ VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
|
|
|
b91920 |
+ VRING_DESC_F_USED(vq->used_wrap_counter);
|
|
|
b91920 |
+ if (++vq->used_idx >= dev->queue_size) {
|
|
|
b91920 |
+ vq->used_idx -= dev->queue_size;
|
|
|
b91920 |
+ vq->used_wrap_counter ^= 1;
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+ n_descs--;
|
|
|
b91920 |
+ } while (n_descs);
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+}
|
|
|
b91920 |
+
|
|
|
b91920 |
void
|
|
|
b91920 |
virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx)
|
|
|
b91920 |
{
|
|
|
b91920 |
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
|
|
|
b91920 |
index 67a9c01ac..c6c2f7d6e 100644
|
|
|
b91920 |
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
|
|
|
b91920 |
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
|
|
|
b91920 |
@@ -11,6 +11,12 @@
|
|
|
b91920 |
#include "../virtio_ring.h"
|
|
|
b91920 |
#include "vhost.h"
|
|
|
b91920 |
|
|
|
b91920 |
+struct virtio_user_queue {
|
|
|
b91920 |
+ uint16_t used_idx;
|
|
|
b91920 |
+ bool avail_wrap_counter;
|
|
|
b91920 |
+ bool used_wrap_counter;
|
|
|
b91920 |
+};
|
|
|
b91920 |
+
|
|
|
b91920 |
struct virtio_user_dev {
|
|
|
b91920 |
/* for vhost_user backend */
|
|
|
b91920 |
int vhostfd;
|
|
|
b91920 |
@@ -39,7 +45,12 @@ struct virtio_user_dev {
|
|
|
b91920 |
uint16_t port_id;
|
|
|
b91920 |
uint8_t mac_addr[ETHER_ADDR_LEN];
|
|
|
b91920 |
char path[PATH_MAX];
|
|
|
b91920 |
- struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
|
|
|
b91920 |
+ union {
|
|
|
b91920 |
+ struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
|
|
|
b91920 |
+ struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES];
|
|
|
b91920 |
+ };
|
|
|
b91920 |
+ struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
|
|
|
b91920 |
+
|
|
|
b91920 |
struct virtio_user_backend_ops *ops;
|
|
|
b91920 |
pthread_mutex_t mutex;
|
|
|
b91920 |
bool started;
|
|
|
b91920 |
@@ -53,5 +64,7 @@ int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
|
|
|
b91920 |
int server, int mrg_rxbuf, int in_order, int packed_vq);
|
|
|
b91920 |
void virtio_user_dev_uninit(struct virtio_user_dev *dev);
|
|
|
b91920 |
void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
|
|
|
b91920 |
+void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
|
|
|
b91920 |
+ uint16_t queue_idx);
|
|
|
b91920 |
uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
|
|
|
b91920 |
#endif
|
|
|
b91920 |
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
|
|
|
b91920 |
index a2911febf..dddb7dd23 100644
|
|
|
b91920 |
--- a/drivers/net/virtio/virtio_user_ethdev.c
|
|
|
b91920 |
+++ b/drivers/net/virtio/virtio_user_ethdev.c
|
|
|
b91920 |
@@ -271,10 +271,44 @@ virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
|
|
|
b91920 |
return dev->queue_size;
|
|
|
b91920 |
}
|
|
|
b91920 |
|
|
|
b91920 |
-static int
|
|
|
b91920 |
-virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
|
|
|
b91920 |
+static void
|
|
|
b91920 |
+virtio_user_setup_queue_packed(struct virtqueue *vq,
|
|
|
b91920 |
+ struct virtio_user_dev *dev)
|
|
|
b91920 |
+
|
|
|
b91920 |
+{
|
|
|
b91920 |
+ uint16_t queue_idx = vq->vq_queue_index;
|
|
|
b91920 |
+ struct vring_packed *vring;
|
|
|
b91920 |
+ uint64_t desc_addr;
|
|
|
b91920 |
+ uint64_t avail_addr;
|
|
|
b91920 |
+ uint64_t used_addr;
|
|
|
b91920 |
+ uint16_t i;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ vring = &dev->packed_vrings[queue_idx];
|
|
|
b91920 |
+ desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
|
|
|
b91920 |
+ avail_addr = desc_addr + vq->vq_nentries *
|
|
|
b91920 |
+ sizeof(struct vring_packed_desc);
|
|
|
b91920 |
+ used_addr = RTE_ALIGN_CEIL(avail_addr +
|
|
|
b91920 |
+ sizeof(struct vring_packed_desc_event),
|
|
|
b91920 |
+ VIRTIO_PCI_VRING_ALIGN);
|
|
|
b91920 |
+ vring->num = vq->vq_nentries;
|
|
|
b91920 |
+ vring->desc_packed =
|
|
|
b91920 |
+ (void *)(uintptr_t)desc_addr;
|
|
|
b91920 |
+ vring->driver_event =
|
|
|
b91920 |
+ (void *)(uintptr_t)avail_addr;
|
|
|
b91920 |
+ vring->device_event =
|
|
|
b91920 |
+ (void *)(uintptr_t)used_addr;
|
|
|
b91920 |
+ dev->packed_queues[queue_idx].avail_wrap_counter = true;
|
|
|
b91920 |
+ dev->packed_queues[queue_idx].used_wrap_counter = true;
|
|
|
b91920 |
+
|
|
|
b91920 |
+ for (i = 0; i < vring->num; i++) {
|
|
|
b91920 |
+ vring->desc_packed[i].flags = VRING_DESC_F_USED(1) |
|
|
|
b91920 |
+ VRING_DESC_F_AVAIL(1);
|
|
|
b91920 |
+ }
|
|
|
b91920 |
+}
|
|
|
b91920 |
+
|
|
|
b91920 |
+static void
|
|
|
b91920 |
+virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
|
|
|
b91920 |
{
|
|
|
b91920 |
- struct virtio_user_dev *dev = virtio_user_get_dev(hw);
|
|
|
b91920 |
uint16_t queue_idx = vq->vq_queue_index;
|
|
|
b91920 |
uint64_t desc_addr, avail_addr, used_addr;
|
|
|
b91920 |
|
|
|
b91920 |
@@ -288,6 +322,17 @@ virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
|
|
|
b91920 |
dev->vrings[queue_idx].desc = (void *)(uintptr_t)desc_addr;
|
|
|
b91920 |
dev->vrings[queue_idx].avail = (void *)(uintptr_t)avail_addr;
|
|
|
b91920 |
dev->vrings[queue_idx].used = (void *)(uintptr_t)used_addr;
|
|
|
b91920 |
+}
|
|
|
b91920 |
+
|
|
|
b91920 |
+static int
|
|
|
b91920 |
+virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
|
|
|
b91920 |
+{
|
|
|
b91920 |
+ struct virtio_user_dev *dev = virtio_user_get_dev(hw);
|
|
|
b91920 |
+
|
|
|
b91920 |
+ if (vtpci_packed_queue(hw))
|
|
|
b91920 |
+ virtio_user_setup_queue_packed(vq, dev);
|
|
|
b91920 |
+ else
|
|
|
b91920 |
+ virtio_user_setup_queue_split(vq, dev);
|
|
|
b91920 |
|
|
|
b91920 |
return 0;
|
|
|
b91920 |
}
|
|
|
b91920 |
@@ -317,7 +362,10 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
|
|
|
b91920 |
struct virtio_user_dev *dev = virtio_user_get_dev(hw);
|
|
|
b91920 |
|
|
|
b91920 |
if (hw->cvq && (hw->cvq->vq == vq)) {
|
|
|
b91920 |
- virtio_user_handle_cq(dev, vq->vq_queue_index);
|
|
|
b91920 |
+ if (vtpci_packed_queue(vq->hw))
|
|
|
b91920 |
+ virtio_user_handle_cq_packed(dev, vq->vq_queue_index);
|
|
|
b91920 |
+ else
|
|
|
b91920 |
+ virtio_user_handle_cq(dev, vq->vq_queue_index);
|
|
|
b91920 |
return;
|
|
|
b91920 |
}
|
|
|
b91920 |
|
|
|
b91920 |
--
|
|
|
b91920 |
2.21.0
|
|
|
b91920 |
|