xref: /openbmc/linux/include/uapi/linux/vhost.h (revision 4c8cf318)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2607ca46eSDavid Howells #ifndef _LINUX_VHOST_H
3607ca46eSDavid Howells #define _LINUX_VHOST_H
4607ca46eSDavid Howells /* Userspace interface for in-kernel virtio accelerators. */
5607ca46eSDavid Howells 
6607ca46eSDavid Howells /* vhost is used to reduce the number of system calls involved in virtio.
7607ca46eSDavid Howells  *
8607ca46eSDavid Howells  * Existing virtio net code is used in the guest without modification.
9607ca46eSDavid Howells  *
10607ca46eSDavid Howells  * This header includes interface used by userspace hypervisor for
11607ca46eSDavid Howells  * device configuration.
12607ca46eSDavid Howells  */
13607ca46eSDavid Howells 
144b867132SPaolo Bonzini #include <linux/vhost_types.h>
15607ca46eSDavid Howells #include <linux/types.h>
16607ca46eSDavid Howells #include <linux/ioctl.h>
17607ca46eSDavid Howells 
18607ca46eSDavid Howells /* ioctls */
19607ca46eSDavid Howells 
20607ca46eSDavid Howells #define VHOST_VIRTIO 0xAF
21607ca46eSDavid Howells 
22607ca46eSDavid Howells /* Features bitmask for forward compatibility.  Transport bits are used for
23607ca46eSDavid Howells  * vhost specific features. */
24607ca46eSDavid Howells #define VHOST_GET_FEATURES	_IOR(VHOST_VIRTIO, 0x00, __u64)
25607ca46eSDavid Howells #define VHOST_SET_FEATURES	_IOW(VHOST_VIRTIO, 0x00, __u64)
26607ca46eSDavid Howells 
27607ca46eSDavid Howells /* Set current process as the (exclusive) owner of this file descriptor.  This
28607ca46eSDavid Howells  * must be called before any other vhost command.  Further calls to
29607ca46eSDavid Howells  * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
30607ca46eSDavid Howells #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
31607ca46eSDavid Howells /* Give up ownership, and reset the device to default values.
32607ca46eSDavid Howells  * Allows subsequent call to VHOST_OWNER_SET to succeed. */
33607ca46eSDavid Howells #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
34607ca46eSDavid Howells 
35607ca46eSDavid Howells /* Set up/modify memory layout */
36607ca46eSDavid Howells #define VHOST_SET_MEM_TABLE	_IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
37607ca46eSDavid Howells 
38607ca46eSDavid Howells /* Write logging setup. */
39607ca46eSDavid Howells /* Memory writes can optionally be logged by setting bit at an offset
40607ca46eSDavid Howells  * (calculated from the physical address) from specified log base.
41607ca46eSDavid Howells  * The bit is set using an atomic 32 bit operation. */
42607ca46eSDavid Howells /* Set base address for logging. */
43607ca46eSDavid Howells #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
44607ca46eSDavid Howells /* Specify an eventfd file descriptor to signal on log write. */
45607ca46eSDavid Howells #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
46607ca46eSDavid Howells 
47607ca46eSDavid Howells /* Ring setup. */
48607ca46eSDavid Howells /* Set number of descriptors in ring. This parameter can not
49607ca46eSDavid Howells  * be modified while ring is running (bound to a device). */
50607ca46eSDavid Howells #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
51607ca46eSDavid Howells /* Set addresses for the ring. */
52607ca46eSDavid Howells #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
53607ca46eSDavid Howells /* Base value where queue looks for available descriptors */
54607ca46eSDavid Howells #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
55607ca46eSDavid Howells /* Get accessor: reads index, writes value in num */
56607ca46eSDavid Howells #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
57607ca46eSDavid Howells 
582751c988SGreg Kurz /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
592751c988SGreg Kurz  * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
602751c988SGreg Kurz  * The byte order cannot be changed while the device is active: trying to do so
612751c988SGreg Kurz  * returns -EBUSY.
622751c988SGreg Kurz  * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
632751c988SGreg Kurz  * set.
642751c988SGreg Kurz  * Not all kernel configurations support this ioctl, but all configurations that
652751c988SGreg Kurz  * support SET also support GET.
662751c988SGreg Kurz  */
672751c988SGreg Kurz #define VHOST_VRING_LITTLE_ENDIAN 0
682751c988SGreg Kurz #define VHOST_VRING_BIG_ENDIAN 1
692751c988SGreg Kurz #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
702751c988SGreg Kurz #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
712751c988SGreg Kurz 
72607ca46eSDavid Howells /* The following ioctls use eventfd file descriptors to signal and poll
73607ca46eSDavid Howells  * for events. */
74607ca46eSDavid Howells 
75607ca46eSDavid Howells /* Set eventfd to poll for added buffers */
76607ca46eSDavid Howells #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
77607ca46eSDavid Howells /* Set eventfd to signal when buffers have beed used */
78607ca46eSDavid Howells #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
79607ca46eSDavid Howells /* Set eventfd to signal an error */
80607ca46eSDavid Howells #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
8103088137SJason Wang /* Set busy loop timeout (in us) */
8203088137SJason Wang #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23,	\
8303088137SJason Wang 					 struct vhost_vring_state)
8403088137SJason Wang /* Get busy loop timeout (in us) */
8503088137SJason Wang #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24,	\
8603088137SJason Wang 					 struct vhost_vring_state)
87607ca46eSDavid Howells 
88429711aeSJason Wang /* Set or get vhost backend capability */
89429711aeSJason Wang 
90429711aeSJason Wang /* Use message type V2 */
91429711aeSJason Wang #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
92429711aeSJason Wang 
93429711aeSJason Wang #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
94c48300c9SGleb Fotengauer-Malinovskiy #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
95429711aeSJason Wang 
96607ca46eSDavid Howells /* VHOST_NET specific defines */
97607ca46eSDavid Howells 
98607ca46eSDavid Howells /* Attach virtio net ring to a raw socket, or tap device.
99607ca46eSDavid Howells  * The socket must be already bound to an ethernet device, this device will be
100607ca46eSDavid Howells  * used for transmit.  Pass fd -1 to unbind from the socket and the transmit
101607ca46eSDavid Howells  * device.  This can be used to stop the ring (e.g. for migration). */
102607ca46eSDavid Howells #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
103607ca46eSDavid Howells 
1044b867132SPaolo Bonzini /* VHOST_SCSI specific defines */
1055012a3a3SMichael S. Tsirkin 
1065012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
1075012a3a3SMichael S. Tsirkin #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
1085012a3a3SMichael S. Tsirkin /* Changing this breaks userspace. */
1095012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
1105012a3a3SMichael S. Tsirkin /* Set and get the events missed flag */
1115012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
1125012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
1135012a3a3SMichael S. Tsirkin 
114433fc58eSAsias He /* VHOST_VSOCK specific defines */
115433fc58eSAsias He 
116433fc58eSAsias He #define VHOST_VSOCK_SET_GUEST_CID	_IOW(VHOST_VIRTIO, 0x60, __u64)
117433fc58eSAsias He #define VHOST_VSOCK_SET_RUNNING		_IOW(VHOST_VIRTIO, 0x61, int)
118433fc58eSAsias He 
1194c8cf318STiwei Bie /* VHOST_VDPA specific defines */
1204c8cf318STiwei Bie 
1214c8cf318STiwei Bie /* Get the device id. The device ids follow the same definition of
1224c8cf318STiwei Bie  * the device id defined in virtio-spec.
1234c8cf318STiwei Bie  */
1244c8cf318STiwei Bie #define VHOST_VDPA_GET_DEVICE_ID	_IOR(VHOST_VIRTIO, 0x70, __u32)
1254c8cf318STiwei Bie /* Get and set the status. The status bits follow the same definition
1264c8cf318STiwei Bie  * of the device status defined in virtio-spec.
1274c8cf318STiwei Bie  */
1284c8cf318STiwei Bie #define VHOST_VDPA_GET_STATUS		_IOR(VHOST_VIRTIO, 0x71, __u8)
1294c8cf318STiwei Bie #define VHOST_VDPA_SET_STATUS		_IOW(VHOST_VIRTIO, 0x72, __u8)
1304c8cf318STiwei Bie /* Get and set the device config. The device config follows the same
1314c8cf318STiwei Bie  * definition of the device config defined in virtio-spec.
1324c8cf318STiwei Bie  */
1334c8cf318STiwei Bie #define VHOST_VDPA_GET_CONFIG		_IOR(VHOST_VIRTIO, 0x73, \
1344c8cf318STiwei Bie 					     struct vhost_vdpa_config)
1354c8cf318STiwei Bie #define VHOST_VDPA_SET_CONFIG		_IOW(VHOST_VIRTIO, 0x74, \
1364c8cf318STiwei Bie 					     struct vhost_vdpa_config)
1374c8cf318STiwei Bie /* Enable/disable the ring. */
1384c8cf318STiwei Bie #define VHOST_VDPA_SET_VRING_ENABLE	_IOW(VHOST_VIRTIO, 0x75, \
1394c8cf318STiwei Bie 					     struct vhost_vring_state)
1404c8cf318STiwei Bie /* Get the max ring size. */
1414c8cf318STiwei Bie #define VHOST_VDPA_GET_VRING_NUM	_IOR(VHOST_VIRTIO, 0x76, __u16)
1424c8cf318STiwei Bie 
143607ca46eSDavid Howells #endif
144