xref: /openbmc/linux/include/uapi/linux/vhost.h (revision 5012a3a3)
1607ca46eSDavid Howells #ifndef _LINUX_VHOST_H
2607ca46eSDavid Howells #define _LINUX_VHOST_H
3607ca46eSDavid Howells /* Userspace interface for in-kernel virtio accelerators. */
4607ca46eSDavid Howells 
5607ca46eSDavid Howells /* vhost is used to reduce the number of system calls involved in virtio.
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  * Existing virtio net code is used in the guest without modification.
8607ca46eSDavid Howells  *
9607ca46eSDavid Howells  * This header includes interface used by userspace hypervisor for
10607ca46eSDavid Howells  * device configuration.
11607ca46eSDavid Howells  */
12607ca46eSDavid Howells 
13607ca46eSDavid Howells #include <linux/types.h>
14607ca46eSDavid Howells #include <linux/compiler.h>
15607ca46eSDavid Howells #include <linux/ioctl.h>
16607ca46eSDavid Howells #include <linux/virtio_config.h>
17607ca46eSDavid Howells #include <linux/virtio_ring.h>
18607ca46eSDavid Howells 
19607ca46eSDavid Howells struct vhost_vring_state {
20607ca46eSDavid Howells 	unsigned int index;
21607ca46eSDavid Howells 	unsigned int num;
22607ca46eSDavid Howells };
23607ca46eSDavid Howells 
24607ca46eSDavid Howells struct vhost_vring_file {
25607ca46eSDavid Howells 	unsigned int index;
26607ca46eSDavid Howells 	int fd; /* Pass -1 to unbind from file. */
27607ca46eSDavid Howells 
28607ca46eSDavid Howells };
29607ca46eSDavid Howells 
30607ca46eSDavid Howells struct vhost_vring_addr {
31607ca46eSDavid Howells 	unsigned int index;
32607ca46eSDavid Howells 	/* Option flags. */
33607ca46eSDavid Howells 	unsigned int flags;
34607ca46eSDavid Howells 	/* Flag values: */
35607ca46eSDavid Howells 	/* Whether log address is valid. If set enables logging. */
36607ca46eSDavid Howells #define VHOST_VRING_F_LOG 0
37607ca46eSDavid Howells 
38607ca46eSDavid Howells 	/* Start of array of descriptors (virtually contiguous) */
39607ca46eSDavid Howells 	__u64 desc_user_addr;
40607ca46eSDavid Howells 	/* Used structure address. Must be 32 bit aligned */
41607ca46eSDavid Howells 	__u64 used_user_addr;
42607ca46eSDavid Howells 	/* Available structure address. Must be 16 bit aligned */
43607ca46eSDavid Howells 	__u64 avail_user_addr;
44607ca46eSDavid Howells 	/* Logging support. */
45607ca46eSDavid Howells 	/* Log writes to used structure, at offset calculated from specified
46607ca46eSDavid Howells 	 * address. Address must be 32 bit aligned. */
47607ca46eSDavid Howells 	__u64 log_guest_addr;
48607ca46eSDavid Howells };
49607ca46eSDavid Howells 
50607ca46eSDavid Howells struct vhost_memory_region {
51607ca46eSDavid Howells 	__u64 guest_phys_addr;
52607ca46eSDavid Howells 	__u64 memory_size; /* bytes */
53607ca46eSDavid Howells 	__u64 userspace_addr;
54607ca46eSDavid Howells 	__u64 flags_padding; /* No flags are currently specified. */
55607ca46eSDavid Howells };
56607ca46eSDavid Howells 
57607ca46eSDavid Howells /* All region addresses and sizes must be 4K aligned. */
58607ca46eSDavid Howells #define VHOST_PAGE_SIZE 0x1000
59607ca46eSDavid Howells 
60607ca46eSDavid Howells struct vhost_memory {
61607ca46eSDavid Howells 	__u32 nregions;
62607ca46eSDavid Howells 	__u32 padding;
63607ca46eSDavid Howells 	struct vhost_memory_region regions[0];
64607ca46eSDavid Howells };
65607ca46eSDavid Howells 
66607ca46eSDavid Howells /* ioctls */
67607ca46eSDavid Howells 
68607ca46eSDavid Howells #define VHOST_VIRTIO 0xAF
69607ca46eSDavid Howells 
70607ca46eSDavid Howells /* Features bitmask for forward compatibility.  Transport bits are used for
71607ca46eSDavid Howells  * vhost specific features. */
72607ca46eSDavid Howells #define VHOST_GET_FEATURES	_IOR(VHOST_VIRTIO, 0x00, __u64)
73607ca46eSDavid Howells #define VHOST_SET_FEATURES	_IOW(VHOST_VIRTIO, 0x00, __u64)
74607ca46eSDavid Howells 
75607ca46eSDavid Howells /* Set current process as the (exclusive) owner of this file descriptor.  This
76607ca46eSDavid Howells  * must be called before any other vhost command.  Further calls to
77607ca46eSDavid Howells  * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
78607ca46eSDavid Howells #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
79607ca46eSDavid Howells /* Give up ownership, and reset the device to default values.
80607ca46eSDavid Howells  * Allows subsequent call to VHOST_OWNER_SET to succeed. */
81607ca46eSDavid Howells #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
82607ca46eSDavid Howells 
83607ca46eSDavid Howells /* Set up/modify memory layout */
84607ca46eSDavid Howells #define VHOST_SET_MEM_TABLE	_IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
85607ca46eSDavid Howells 
86607ca46eSDavid Howells /* Write logging setup. */
87607ca46eSDavid Howells /* Memory writes can optionally be logged by setting bit at an offset
88607ca46eSDavid Howells  * (calculated from the physical address) from specified log base.
89607ca46eSDavid Howells  * The bit is set using an atomic 32 bit operation. */
90607ca46eSDavid Howells /* Set base address for logging. */
91607ca46eSDavid Howells #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
92607ca46eSDavid Howells /* Specify an eventfd file descriptor to signal on log write. */
93607ca46eSDavid Howells #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
94607ca46eSDavid Howells 
95607ca46eSDavid Howells /* Ring setup. */
96607ca46eSDavid Howells /* Set number of descriptors in ring. This parameter can not
97607ca46eSDavid Howells  * be modified while ring is running (bound to a device). */
98607ca46eSDavid Howells #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
99607ca46eSDavid Howells /* Set addresses for the ring. */
100607ca46eSDavid Howells #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
101607ca46eSDavid Howells /* Base value where queue looks for available descriptors */
102607ca46eSDavid Howells #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
103607ca46eSDavid Howells /* Get accessor: reads index, writes value in num */
104607ca46eSDavid Howells #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
105607ca46eSDavid Howells 
106607ca46eSDavid Howells /* The following ioctls use eventfd file descriptors to signal and poll
107607ca46eSDavid Howells  * for events. */
108607ca46eSDavid Howells 
109607ca46eSDavid Howells /* Set eventfd to poll for added buffers */
110607ca46eSDavid Howells #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
111607ca46eSDavid Howells /* Set eventfd to signal when buffers have beed used */
112607ca46eSDavid Howells #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
113607ca46eSDavid Howells /* Set eventfd to signal an error */
114607ca46eSDavid Howells #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
115607ca46eSDavid Howells 
116607ca46eSDavid Howells /* VHOST_NET specific defines */
117607ca46eSDavid Howells 
118607ca46eSDavid Howells /* Attach virtio net ring to a raw socket, or tap device.
119607ca46eSDavid Howells  * The socket must be already bound to an ethernet device, this device will be
120607ca46eSDavid Howells  * used for transmit.  Pass fd -1 to unbind from the socket and the transmit
121607ca46eSDavid Howells  * device.  This can be used to stop the ring (e.g. for migration). */
122607ca46eSDavid Howells #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
123607ca46eSDavid Howells 
124607ca46eSDavid Howells /* Feature bits */
125607ca46eSDavid Howells /* Log all write descriptors. Can be changed while device is active. */
126607ca46eSDavid Howells #define VHOST_F_LOG_ALL 26
127607ca46eSDavid Howells /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
128607ca46eSDavid Howells #define VHOST_NET_F_VIRTIO_NET_HDR 27
129607ca46eSDavid Howells 
1305012a3a3SMichael S. Tsirkin /* VHOST_SCSI specific definitions */
1315012a3a3SMichael S. Tsirkin 
1325012a3a3SMichael S. Tsirkin /*
1335012a3a3SMichael S. Tsirkin  * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
1345012a3a3SMichael S. Tsirkin  *
1355012a3a3SMichael S. Tsirkin  * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
1365012a3a3SMichael S. Tsirkin  *            RFC-v2 vhost-scsi userspace.  Add GET_ABI_VERSION ioctl usage
1375012a3a3SMichael S. Tsirkin  * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
1385012a3a3SMichael S. Tsirkin  *            All the targets under vhost_wwpn can be seen and used by guset.
1395012a3a3SMichael S. Tsirkin  */
1405012a3a3SMichael S. Tsirkin 
1415012a3a3SMichael S. Tsirkin #define VHOST_SCSI_ABI_VERSION	1
1425012a3a3SMichael S. Tsirkin 
1435012a3a3SMichael S. Tsirkin struct vhost_scsi_target {
1445012a3a3SMichael S. Tsirkin 	int abi_version;
1455012a3a3SMichael S. Tsirkin 	char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
1465012a3a3SMichael S. Tsirkin 	unsigned short vhost_tpgt;
1475012a3a3SMichael S. Tsirkin 	unsigned short reserved;
1485012a3a3SMichael S. Tsirkin };
1495012a3a3SMichael S. Tsirkin 
1505012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
1515012a3a3SMichael S. Tsirkin #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
1525012a3a3SMichael S. Tsirkin /* Changing this breaks userspace. */
1535012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
1545012a3a3SMichael S. Tsirkin /* Set and get the events missed flag */
1555012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
1565012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
1575012a3a3SMichael S. Tsirkin 
158607ca46eSDavid Howells #endif
159