3 /* Userspace interface for in-kernel virtio accelerators. */
5 /* vhost is used to reduce the number of system calls involved in virtio.
7 * Existing virtio net code is used in the guest without modification.
9 * This header includes interface used by userspace hypervisor for
10 * device configuration.
13 #include <linux/types.h>
15 #include <linux/ioctl.h>
16 #include <linux/virtio_config.h>
17 #include <linux/virtio_ring.h>
19 struct vhost_vring_state
{
24 struct vhost_vring_file
{
26 int fd
; /* Pass -1 to unbind from file. */
30 struct vhost_vring_addr
{
35 /* Whether log address is valid. If set enables logging. */
36 #define VHOST_VRING_F_LOG 0
38 /* Start of array of descriptors (virtually contiguous) */
40 /* Used structure address. Must be 32 bit aligned */
42 /* Available structure address. Must be 16 bit aligned */
43 __u64 avail_user_addr
;
44 /* Logging support. */
45 /* Log writes to used structure, at offset calculated from specified
46 * address. Address must be 32 bit aligned. */
50 struct vhost_memory_region
{
51 __u64 guest_phys_addr
;
52 __u64 memory_size
; /* bytes */
54 __u64 flags_padding
; /* No flags are currently specified. */
57 /* All region addresses and sizes must be 4K aligned. */
58 #define VHOST_PAGE_SIZE 0x1000
63 struct vhost_memory_region regions
[0];
68 #define VHOST_VIRTIO 0xAF
70 /* Features bitmask for forward compatibility. Transport bits are used for
71 * vhost specific features. */
72 #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
73 #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
75 /* Set current process as the (exclusive) owner of this file descriptor. This
76 * must be called before any other vhost command. Further calls to
77 * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
78 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
79 /* Give up ownership, and reset the device to default values.
80 * Allows subsequent call to VHOST_OWNER_SET to succeed. */
81 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
83 /* Set up/modify memory layout */
84 #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
86 /* Write logging setup. */
87 /* Memory writes can optionally be logged by setting bit at an offset
88 * (calculated from the physical address) from specified log base.
89 * The bit is set using an atomic 32 bit operation. */
90 /* Set base address for logging. */
91 #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
92 /* Specify an eventfd file descriptor to signal on log write. */
93 #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
96 /* Set number of descriptors in ring. This parameter can not
97 * be modified while ring is running (bound to a device). */
98 #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
99 /* Set addresses for the ring. */
100 #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
101 /* Base value where queue looks for available descriptors */
102 #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
103 /* Get accessor: reads index, writes value in num */
104 #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
106 /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
107 * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
108 * The byte order cannot be changed while the device is active: trying to do so
110 * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
112 * Not all kernel configurations support this ioctl, but all configurations that
113 * support SET also support GET.
115 #define VHOST_VRING_LITTLE_ENDIAN 0
116 #define VHOST_VRING_BIG_ENDIAN 1
117 #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
118 #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
120 /* The following ioctls use eventfd file descriptors to signal and poll
123 /* Set eventfd to poll for added buffers */
124 #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
125 /* Set eventfd to signal when buffers have beed used */
126 #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
127 /* Set eventfd to signal an error */
128 #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
130 /* VHOST_NET specific defines */
132 /* Attach virtio net ring to a raw socket, or tap device.
133 * The socket must be already bound to an ethernet device, this device will be
134 * used for transmit. Pass fd -1 to unbind from the socket and the transmit
135 * device. This can be used to stop the ring (e.g. for migration). */
136 #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
139 /* Log all write descriptors. Can be changed while device is active. */
140 #define VHOST_F_LOG_ALL 26
141 /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
142 #define VHOST_NET_F_VIRTIO_NET_HDR 27
144 /* VHOST_SCSI specific definitions */
147 * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
149 * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
150 * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
151 * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
152 * All the targets under vhost_wwpn can be seen and used by guset.
155 #define VHOST_SCSI_ABI_VERSION 1
157 struct vhost_scsi_target
{
159 char vhost_wwpn
[224]; /* TRANSPORT_IQN_LEN */
160 unsigned short vhost_tpgt
;
161 unsigned short reserved
;
164 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
165 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
166 /* Changing this breaks userspace. */
167 #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
168 /* Set and get the events missed flag */
169 #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
170 #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)