1dd873966SEric Auger /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 251b24e34SJan Kiszka #ifndef _LINUX_VHOST_H 351b24e34SJan Kiszka #define _LINUX_VHOST_H 451b24e34SJan Kiszka /* Userspace interface for in-kernel virtio accelerators. */ 551b24e34SJan Kiszka 651b24e34SJan Kiszka /* vhost is used to reduce the number of system calls involved in virtio. 751b24e34SJan Kiszka * 851b24e34SJan Kiszka * Existing virtio net code is used in the guest without modification. 951b24e34SJan Kiszka * 1051b24e34SJan Kiszka * This header includes interface used by userspace hypervisor for 1151b24e34SJan Kiszka * device configuration. 1251b24e34SJan Kiszka */ 1351b24e34SJan Kiszka 14da054c64SPaolo Bonzini #include <linux/vhost_types.h> 1551b24e34SJan Kiszka #include <linux/types.h> 1651b24e34SJan Kiszka #include <linux/ioctl.h> 1751b24e34SJan Kiszka 1851b24e34SJan Kiszka /* ioctls */ 1951b24e34SJan Kiszka 2051b24e34SJan Kiszka #define VHOST_VIRTIO 0xAF 2151b24e34SJan Kiszka 2251b24e34SJan Kiszka /* Features bitmask for forward compatibility. Transport bits are used for 2351b24e34SJan Kiszka * vhost specific features. */ 2451b24e34SJan Kiszka #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) 2551b24e34SJan Kiszka #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) 2651b24e34SJan Kiszka 2751b24e34SJan Kiszka /* Set current process as the (exclusive) owner of this file descriptor. This 2851b24e34SJan Kiszka * must be called before any other vhost command. Further calls to 2951b24e34SJan Kiszka * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ 3051b24e34SJan Kiszka #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) 3151b24e34SJan Kiszka /* Give up ownership, and reset the device to default values. 3251b24e34SJan Kiszka * Allows subsequent call to VHOST_OWNER_SET to succeed. */ 3360915dc4SYuanhan Liu #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) 3451b24e34SJan Kiszka 3551b24e34SJan Kiszka /* Set up/modify memory layout */ 3651b24e34SJan Kiszka #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) 3751b24e34SJan Kiszka 3851b24e34SJan Kiszka /* Write logging setup. */ 3951b24e34SJan Kiszka /* Memory writes can optionally be logged by setting bit at an offset 4051b24e34SJan Kiszka * (calculated from the physical address) from specified log base. 4151b24e34SJan Kiszka * The bit is set using an atomic 32 bit operation. */ 4251b24e34SJan Kiszka /* Set base address for logging. */ 4351b24e34SJan Kiszka #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) 4451b24e34SJan Kiszka /* Specify an eventfd file descriptor to signal on log write. */ 4551b24e34SJan Kiszka #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) 4651b24e34SJan Kiszka 4751b24e34SJan Kiszka /* Ring setup. */ 4851b24e34SJan Kiszka /* Set number of descriptors in ring. This parameter can not 4951b24e34SJan Kiszka * be modified while ring is running (bound to a device). */ 5051b24e34SJan Kiszka #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) 5151b24e34SJan Kiszka /* Set addresses for the ring. */ 5251b24e34SJan Kiszka #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) 5351b24e34SJan Kiszka /* Base value where queue looks for available descriptors */ 5451b24e34SJan Kiszka #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state) 5551b24e34SJan Kiszka /* Get accessor: reads index, writes value in num */ 5651b24e34SJan Kiszka #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state) 5751b24e34SJan Kiszka 58332f6407SGreg Kurz /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN 59332f6407SGreg Kurz * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL). 60332f6407SGreg Kurz * The byte order cannot be changed while the device is active: trying to do so 61332f6407SGreg Kurz * returns -EBUSY. 62332f6407SGreg Kurz * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is 63332f6407SGreg Kurz * set. 64332f6407SGreg Kurz * Not all kernel configurations support this ioctl, but all configurations that 65332f6407SGreg Kurz * support SET also support GET. 66332f6407SGreg Kurz */ 67332f6407SGreg Kurz #define VHOST_VRING_LITTLE_ENDIAN 0 68332f6407SGreg Kurz #define VHOST_VRING_BIG_ENDIAN 1 69332f6407SGreg Kurz #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state) 70332f6407SGreg Kurz #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state) 71332f6407SGreg Kurz 7251b24e34SJan Kiszka /* The following ioctls use eventfd file descriptors to signal and poll 7351b24e34SJan Kiszka * for events. */ 7451b24e34SJan Kiszka 7551b24e34SJan Kiszka /* Set eventfd to poll for added buffers */ 7651b24e34SJan Kiszka #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) 7751b24e34SJan Kiszka /* Set eventfd to signal when buffers have beed used */ 7851b24e34SJan Kiszka #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) 7951b24e34SJan Kiszka /* Set eventfd to signal an error */ 8051b24e34SJan Kiszka #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) 81b89485a5SPaolo Bonzini /* Set busy loop timeout (in us) */ 82b89485a5SPaolo Bonzini #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \ 83b89485a5SPaolo Bonzini struct vhost_vring_state) 84b89485a5SPaolo Bonzini /* Get busy loop timeout (in us) */ 85b89485a5SPaolo Bonzini #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \ 86b89485a5SPaolo Bonzini struct vhost_vring_state) 8751b24e34SJan Kiszka 88d36f7de8SCornelia Huck /* Set or get vhost backend capability */ 89d36f7de8SCornelia Huck 90d36f7de8SCornelia Huck /* Use message type V2 */ 91d36f7de8SCornelia Huck #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 92d36f7de8SCornelia Huck 93d36f7de8SCornelia Huck #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) 948f3cd250SCornelia Huck #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) 95d36f7de8SCornelia Huck 9651b24e34SJan Kiszka /* VHOST_NET specific defines */ 9751b24e34SJan Kiszka 9851b24e34SJan Kiszka /* Attach virtio net ring to a raw socket, or tap device. 9951b24e34SJan Kiszka * The socket must be already bound to an ethernet device, this device will be 10051b24e34SJan Kiszka * used for transmit. Pass fd -1 to unbind from the socket and the transmit 10151b24e34SJan Kiszka * device. This can be used to stop the ring (e.g. for migration). */ 10251b24e34SJan Kiszka #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) 10351b24e34SJan Kiszka 104da054c64SPaolo Bonzini /* VHOST_SCSI specific defines */ 105e098b453SAlexey Kardashevskiy 106e098b453SAlexey Kardashevskiy #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target) 107e098b453SAlexey Kardashevskiy #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target) 108e098b453SAlexey Kardashevskiy /* Changing this breaks userspace. */ 109e098b453SAlexey Kardashevskiy #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int) 110e098b453SAlexey Kardashevskiy /* Set and get the events missed flag */ 111e098b453SAlexey Kardashevskiy #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32) 112e098b453SAlexey Kardashevskiy #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32) 113e098b453SAlexey Kardashevskiy 114dbdfea92SCornelia Huck /* VHOST_VSOCK specific defines */ 115dbdfea92SCornelia Huck 116dbdfea92SCornelia Huck #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64) 117dbdfea92SCornelia Huck #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int) 118dbdfea92SCornelia Huck 119*dc6f8d45SCornelia Huck /* VHOST_VDPA specific defines */ 120*dc6f8d45SCornelia Huck 121*dc6f8d45SCornelia Huck /* Get the device id. The device ids follow the same definition of 122*dc6f8d45SCornelia Huck * the device id defined in virtio-spec. 123*dc6f8d45SCornelia Huck */ 124*dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_DEVICE_ID _IOR(VHOST_VIRTIO, 0x70, __u32) 125*dc6f8d45SCornelia Huck /* Get and set the status. The status bits follow the same definition 126*dc6f8d45SCornelia Huck * of the device status defined in virtio-spec. 127*dc6f8d45SCornelia Huck */ 128*dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_STATUS _IOR(VHOST_VIRTIO, 0x71, __u8) 129*dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_STATUS _IOW(VHOST_VIRTIO, 0x72, __u8) 130*dc6f8d45SCornelia Huck /* Get and set the device config. The device config follows the same 131*dc6f8d45SCornelia Huck * definition of the device config defined in virtio-spec. 132*dc6f8d45SCornelia Huck */ 133*dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_CONFIG _IOR(VHOST_VIRTIO, 0x73, \ 134*dc6f8d45SCornelia Huck struct vhost_vdpa_config) 135*dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_CONFIG _IOW(VHOST_VIRTIO, 0x74, \ 136*dc6f8d45SCornelia Huck struct vhost_vdpa_config) 137*dc6f8d45SCornelia Huck /* Enable/disable the ring. */ 138*dc6f8d45SCornelia Huck #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, \ 139*dc6f8d45SCornelia Huck struct vhost_vring_state) 140*dc6f8d45SCornelia Huck /* Get the max ring size. */ 141*dc6f8d45SCornelia Huck #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16) 142*dc6f8d45SCornelia Huck 14351b24e34SJan Kiszka #endif 144