From: Yuanhan Liu Date: Sat, 1 Apr 2017 07:22:45 +0000 (+0800) Subject: vhost: export vhost vring info X-Git-Tag: spdx-start~3893 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=40ef286f236a;p=dpdk.git vhost: export vhost vring info Signed-off-by: Yuanhan Liu Reviewed-by: Maxime Coquelin --- diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map index cec1e9eec5..93b67339fb 100644 --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -38,5 +38,6 @@ DPDK_17.05 { rte_vhost_get_mem_table; rte_vhost_get_mtu; rte_vhost_get_negotiated_features; + rte_vhost_get_vhost_vring; } DPDK_16.07; diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index e3655974f5..31e175b16c 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -80,6 +80,17 @@ struct rte_vhost_memory { struct rte_vhost_mem_region regions[0]; }; +struct rte_vhost_vring { + struct vring_desc *desc; + struct vring_avail *avail; + struct vring_used *used; + uint64_t log_guest_addr; + + int callfd; + int kickfd; + uint16_t size; +}; + /** * Device and vring operations. */ @@ -298,4 +309,19 @@ uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, */ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem); +/** + * Get guest vring info, including the vring address, vring size, etc. + * + * @param vid + * vhost device ID + * @param vring_idx + * vring index + * @param vring + * the structure to hold the requested vring info + * @return + * 0 on success, -1 on failure + */ +int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, + struct rte_vhost_vring *vring); + #endif /* _VIRTIO_NET_H_ */ diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 90b0f67492..4b9d7815e6 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -395,6 +395,36 @@ rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem) return 0; } +int +rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, + struct rte_vhost_vring *vring) +{ + struct virtio_net *dev; + struct vhost_virtqueue *vq; + + dev = get_device(vid); + if (!dev) + return -1; + + if (vring_idx >= VHOST_MAX_VRING) + return -1; + + vq = dev->virtqueue[vring_idx]; + if (!vq) + return -1; + + vring->desc = vq->desc; + vring->avail = vq->avail; + vring->used = vq->used; + vring->log_guest_addr = vq->log_guest_addr; + + vring->callfd = vq->callfd; + vring->kickfd = vq->kickfd; + vring->size = vq->size; + + return 0; +} + uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id) { diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 6d1986a655..68ca19769b 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -120,6 +120,8 @@ struct vhost_virtqueue { #ifndef VIRTIO_NET_F_MQ #define VIRTIO_NET_F_MQ 22 #endif + +#define VHOST_MAX_VRING 0x100 #define VHOST_MAX_QUEUE_PAIRS 0x80 #ifndef VIRTIO_NET_F_MTU