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 1062751c988SGreg Kurz /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN 1072751c988SGreg Kurz * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL). 1082751c988SGreg Kurz * The byte order cannot be changed while the device is active: trying to do so 1092751c988SGreg Kurz * returns -EBUSY. 1102751c988SGreg Kurz * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is 1112751c988SGreg Kurz * set. 1122751c988SGreg Kurz * Not all kernel configurations support this ioctl, but all configurations that 1132751c988SGreg Kurz * support SET also support GET. 1142751c988SGreg Kurz */ 1152751c988SGreg Kurz #define VHOST_VRING_LITTLE_ENDIAN 0 1162751c988SGreg Kurz #define VHOST_VRING_BIG_ENDIAN 1 1172751c988SGreg Kurz #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state) 1182751c988SGreg Kurz #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) 1192751c988SGreg Kurz 120607ca46eSDavid Howells /* The following ioctls use eventfd file descriptors to signal and poll 121607ca46eSDavid Howells * for events. */ 122607ca46eSDavid Howells 123607ca46eSDavid Howells /* Set eventfd to poll for added buffers */ 124607ca46eSDavid Howells #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) 125607ca46eSDavid Howells /* Set eventfd to signal when buffers have beed used */ 126607ca46eSDavid Howells #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) 127607ca46eSDavid Howells /* Set eventfd to signal an error */ 128607ca46eSDavid Howells #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) 12903088137SJason Wang /* Set busy loop timeout (in us) */ 13003088137SJason Wang #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \ 13103088137SJason Wang struct vhost_vring_state) 13203088137SJason Wang /* Get busy loop timeout (in us) */ 13303088137SJason Wang #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ 13403088137SJason Wang struct vhost_vring_state) 135607ca46eSDavid Howells 136607ca46eSDavid Howells /* VHOST_NET specific defines */ 137607ca46eSDavid Howells 138607ca46eSDavid Howells /* Attach virtio net ring to a raw socket, or tap device. 139607ca46eSDavid Howells * The socket must be already bound to an ethernet device, this device will be 140607ca46eSDavid Howells * used for transmit. Pass fd -1 to unbind from the socket and the transmit 141607ca46eSDavid Howells * device. This can be used to stop the ring (e.g. for migration). */ 142607ca46eSDavid Howells #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) 143607ca46eSDavid Howells 144607ca46eSDavid Howells /* Feature bits */ 145607ca46eSDavid Howells /* Log all write descriptors. Can be changed while device is active. */ 146607ca46eSDavid Howells #define VHOST_F_LOG_ALL 26 147607ca46eSDavid Howells /* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ 148607ca46eSDavid Howells #define VHOST_NET_F_VIRTIO_NET_HDR 27 149607ca46eSDavid Howells 1505012a3a3SMichael S. Tsirkin /* VHOST_SCSI specific definitions */ 1515012a3a3SMichael S. Tsirkin 1525012a3a3SMichael S. Tsirkin /* 1535012a3a3SMichael S. Tsirkin * Used by QEMU userspace to ensure a consistent vhost-scsi ABI. 1545012a3a3SMichael S. Tsirkin * 1555012a3a3SMichael S. Tsirkin * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate + 1565012a3a3SMichael S. Tsirkin * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage 1575012a3a3SMichael S. Tsirkin * ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target. 1585012a3a3SMichael S. Tsirkin * All the targets under vhost_wwpn can be seen and used by guset. 1595012a3a3SMichael S. Tsirkin */ 1605012a3a3SMichael S. Tsirkin 1615012a3a3SMichael S. Tsirkin #define VHOST_SCSI_ABI_VERSION 1 1625012a3a3SMichael S. Tsirkin 1635012a3a3SMichael S. Tsirkin struct vhost_scsi_target { 1645012a3a3SMichael S. Tsirkin int abi_version; 1655012a3a3SMichael S. Tsirkin char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */ 1665012a3a3SMichael S. Tsirkin unsigned short vhost_tpgt; 1675012a3a3SMichael S. Tsirkin unsigned short reserved; 1685012a3a3SMichael S. Tsirkin }; 1695012a3a3SMichael S. Tsirkin 1705012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target) 1715012a3a3SMichael S. Tsirkin #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target) 1725012a3a3SMichael S. Tsirkin /* Changing this breaks userspace. */ 1735012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int) 1745012a3a3SMichael S. Tsirkin /* Set and get the events missed flag */ 1755012a3a3SMichael S. Tsirkin #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32) 1765012a3a3SMichael S. Tsirkin #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32) 1775012a3a3SMichael S. Tsirkin 178433fc58eSAsias He /* VHOST_VSOCK specific defines */ 179433fc58eSAsias He 180433fc58eSAsias He #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64) 181433fc58eSAsias He #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int) 182433fc58eSAsias He 183607ca46eSDavid Howells #endif 184