aboutgitcodebugslistschat
path: root/vhost_user.h
diff options
context:
space:
mode:
Diffstat (limited to 'vhost_user.h')
-rw-r--r--vhost_user.h115
1 files changed, 91 insertions, 24 deletions
diff --git a/vhost_user.h b/vhost_user.h
index 25f0b61..464ba21 100644
--- a/vhost_user.h
+++ b/vhost_user.h
@@ -1,4 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * vhost-user API, command management and virtio interface
+ *
+ * Copyright Red Hat
+ * Author: Laurent Vivier <lvivier@redhat.com>
+ */
/* some parts from subprojects/libvhost-user/libvhost-user.h */
@@ -12,6 +18,9 @@
#define VHOST_MEMORY_BASELINE_NREGIONS 8
+/**
+ * enum vhost_user_protocol_feature - List of available vhost-user features
+ */
enum vhost_user_protocol_feature {
VHOST_USER_PROTOCOL_F_MQ = 0,
VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
@@ -32,6 +41,9 @@ enum vhost_user_protocol_feature {
VHOST_USER_PROTOCOL_F_MAX
};
+/**
+ * enum vhost_user_request - List of available vhost-user requests
+ */
enum vhost_user_request {
VHOST_USER_NONE = 0,
VHOST_USER_GET_FEATURES = 1,
@@ -74,66 +86,121 @@ enum vhost_user_request {
VHOST_USER_MAX
};
-typedef struct {
+/**
+ * struct vhost_user_header - vhost-user message header
+ * @request: Request type of the message
+ * @flags: Request flags
+ * @size: The following payload size
+ */
+struct vhost_user_header {
enum vhost_user_request request;
#define VHOST_USER_VERSION_MASK 0x3
#define VHOST_USER_REPLY_MASK (0x1 << 2)
#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3)
uint32_t flags;
- uint32_t size; /* the following payload size */
-} __attribute__ ((__packed__)) vhost_user_header;
-
-typedef struct VhostUserMemory_region {
+ uint32_t size;
+} __attribute__ ((__packed__));
+
+/**
+ * struct vhost_user_memory_region - Front-end shared memory region information
+ * @guest_phys_addr: Guest physical address of the region
+ * @memory_size: Memory size
+ * @userspace_addr: front-end (QEMU) userspace address
+ * @mmap_offset: region offset in the shared memory area
+ */
+struct vhost_user_memory_region {
uint64_t guest_phys_addr;
uint64_t memory_size;
uint64_t userspace_addr;
uint64_t mmap_offset;
-} VhostUserMemory_region;
+};
-struct VhostUserMemory {
+/**
+ * struct vhost_user_memory - List of all the shared memory regions
+ * @nregions: Number of memory regions
+ * @padding: Padding
+ * @regions: Memory regions list
+ */
+struct vhost_user_memory {
uint32_t nregions;
uint32_t padding;
- struct VhostUserMemory_region regions[VHOST_MEMORY_BASELINE_NREGIONS];
+ struct vhost_user_memory_region regions[VHOST_MEMORY_BASELINE_NREGIONS];
};
-typedef union {
+/**
+ * union vhost_user_payload - vhost-user message payload
+ * @u64: 64-bit payload
+ * @state: vring state payload
+ * @addr: vring addresses payload
+ * vhost_user_memory: Memory regions information payload
+ */
+union vhost_user_payload {
#define VHOST_USER_VRING_IDX_MASK 0xff
#define VHOST_USER_VRING_NOFD_MASK (0x1 << 8)
uint64_t u64;
struct vhost_vring_state state;
struct vhost_vring_addr addr;
- struct VhostUserMemory memory;
-} vhost_user_payload;
+ struct vhost_user_memory memory;
+};
-typedef struct VhostUserMsg {
- vhost_user_header hdr;
- vhost_user_payload payload;
+/**
+ * struct vhost_user_msg - vhost-use message
+ * @hdr: Message header
+ * @payload: Message payload
+ * @fds: File descriptors associated with the message
+ * in the ancillary data.
+ * (shared memory or event file descriptors)
+ * @fd_num: Number of file descriptors
+ */
+struct vhost_user_msg {
+ struct vhost_user_header hdr;
+ union vhost_user_payload payload;
int fds[VHOST_MEMORY_BASELINE_NREGIONS];
int fd_num;
- uint8_t *data;
-} __attribute__ ((__packed__)) VhostUserMsg;
-#define VHOST_USER_HDR_SIZE sizeof(vhost_user_header)
+} __attribute__ ((__packed__));
+#define VHOST_USER_HDR_SIZE sizeof(struct vhost_user_header)
+/* index of the RX virtqueue */
#define VHOST_USER_RX_QUEUE 0
+/* index of the TX virtqueue */
#define VHOST_USER_TX_QUEUE 1
-static inline bool vu_queue_enabled(VuVirtq *vq)
+/* in case of multiqueue, the RX and TX queues are interleaved */
+#define VHOST_USER_IS_QUEUE_TX(n) (n % 2)
+#define VHOST_USER_IS_QUEUE_RX(n) (!(n % 2))
+
+/* Default virtio-net header for passt */
+#define VU_HEADER ((struct virtio_net_hdr){ \
+ .flags = VIRTIO_NET_HDR_F_DATA_VALID, \
+ .gso_type = VIRTIO_NET_HDR_GSO_NONE, \
+})
+
+/**
+ * vu_queue_enabled - Return state of a virtqueue
+ * @vq: virtqueue to check
+ *
+ * Return: true if the virqueue is enabled, false otherwise
+ */
+static inline bool vu_queue_enabled(const struct vu_virtq *vq)
{
return vq->enable;
}
-static inline bool vu_queue_started(const VuVirtq *vq)
+/**
+ * vu_queue_started - Return state of a virtqueue
+ * @vq: virtqueue to check
+ *
+ * Return: true if the virqueue is started, false otherwise
+ */
+static inline bool vu_queue_started(const struct vu_virtq *vq)
{
return vq->started;
}
-size_t tap_send_frames_vu(const struct ctx *c, const struct iovec *iov,
- size_t n);
-int vu_send(const struct ctx *c, const void *data, size_t len);
void vu_print_capabilities(void);
void vu_init(struct ctx *c);
-void vu_kick_cb(struct ctx *c, union epoll_ref ref);
-void tap_handler_vu(struct ctx *c, uint32_t events);
+void vu_cleanup(struct vu_dev *vdev);
+void vu_control_handler(struct vu_dev *vdev, int fd, uint32_t events);
#endif /* VHOST_USER_H */