xref: /titanic_51/usr/src/uts/common/io/virtio/virtioreg.h (revision 17ad7f9fd28ceea21aea94421cb8ada963285765)
1e0724c53SAlexey Zaytsev /*
2e0724c53SAlexey Zaytsev  * Copyright (c) 2010 Minoura Makoto.
3e0724c53SAlexey Zaytsev  * Copyright (c) 2012 Nexenta Systems, Inc.
4e0724c53SAlexey Zaytsev  * All rights reserved.
5e0724c53SAlexey Zaytsev  *
6e0724c53SAlexey Zaytsev  * Redistribution and use in source and binary forms, with or without
7e0724c53SAlexey Zaytsev  * modification, are permitted provided that the following conditions
8e0724c53SAlexey Zaytsev  * are met:
9e0724c53SAlexey Zaytsev  * 1. Redistributions of source code must retain the above copyright
10e0724c53SAlexey Zaytsev  *    notice, this list of conditions and the following disclaimer.
11e0724c53SAlexey Zaytsev  * 2. Redistributions in binary form must reproduce the above copyright
12e0724c53SAlexey Zaytsev  *    notice, this list of conditions and the following disclaimer in the
13e0724c53SAlexey Zaytsev  *    documentation and/or other materials provided with the distribution.
14e0724c53SAlexey Zaytsev  *
15e0724c53SAlexey Zaytsev  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16e0724c53SAlexey Zaytsev  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17e0724c53SAlexey Zaytsev  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18e0724c53SAlexey Zaytsev  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19e0724c53SAlexey Zaytsev  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20e0724c53SAlexey Zaytsev  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21e0724c53SAlexey Zaytsev  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22e0724c53SAlexey Zaytsev  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23e0724c53SAlexey Zaytsev  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24e0724c53SAlexey Zaytsev  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25e0724c53SAlexey Zaytsev  */
26e0724c53SAlexey Zaytsev 
27e0724c53SAlexey Zaytsev /*
28e0724c53SAlexey Zaytsev  * Part of the file derived from `Virtio PCI Card Specification v0.8.6 DRAFT'
29e0724c53SAlexey Zaytsev  * Appendix A.
30e0724c53SAlexey Zaytsev  */
31e0724c53SAlexey Zaytsev 
32e0724c53SAlexey Zaytsev /*
33e0724c53SAlexey Zaytsev  * An interface for efficient virtio implementation.
34e0724c53SAlexey Zaytsev  *
35e0724c53SAlexey Zaytsev  * This header is BSD licensed so anyone can use the definitions
36e0724c53SAlexey Zaytsev  * to implement compatible drivers/servers.
37e0724c53SAlexey Zaytsev  *
38e0724c53SAlexey Zaytsev  * Copyright 2007, 2009, IBM Corporation
39e0724c53SAlexey Zaytsev  * All rights reserved.
40e0724c53SAlexey Zaytsev  *
41e0724c53SAlexey Zaytsev  * Redistribution and use in source and binary forms, with or without
42e0724c53SAlexey Zaytsev  * modification, are permitted provided that the following conditions
43e0724c53SAlexey Zaytsev  * are met:
44e0724c53SAlexey Zaytsev  * 1. Redistributions of source code must retain the above copyright
45e0724c53SAlexey Zaytsev  *    notice, this list of conditions and the following disclaimer.
46e0724c53SAlexey Zaytsev  * 2. Redistributions in binary form must reproduce the above copyright
47e0724c53SAlexey Zaytsev  *    notice, this list of conditions and the following disclaimer in the
48e0724c53SAlexey Zaytsev  *    documentation and/or other materials provided with the distribution.
49e0724c53SAlexey Zaytsev  * 3. Neither the name of IBM nor the names of its contributors
50e0724c53SAlexey Zaytsev  *    may be used to endorse or promote products derived from this software
51e0724c53SAlexey Zaytsev  *    without specific prior written permission.
52e0724c53SAlexey Zaytsev  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53e0724c53SAlexey Zaytsev  * ``AS IS'' ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
54e0724c53SAlexey Zaytsev  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55e0724c53SAlexey Zaytsev  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
56e0724c53SAlexey Zaytsev  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57e0724c53SAlexey Zaytsev  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58e0724c53SAlexey Zaytsev  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59e0724c53SAlexey Zaytsev  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60e0724c53SAlexey Zaytsev  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61e0724c53SAlexey Zaytsev  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62e0724c53SAlexey Zaytsev  * SUCH DAMAGE.
63e0724c53SAlexey Zaytsev  */
64e0724c53SAlexey Zaytsev 
65e0724c53SAlexey Zaytsev 
66e0724c53SAlexey Zaytsev #ifndef __VIRTIOREG_H__
67e0724c53SAlexey Zaytsev #define	__VIRTIOREG_H__
68e0724c53SAlexey Zaytsev 
69e0724c53SAlexey Zaytsev #include <sys/types.h>
70e0724c53SAlexey Zaytsev 
71e0724c53SAlexey Zaytsev #define	PCI_VENDOR_QUMRANET 0x1af4
72e0724c53SAlexey Zaytsev #define	PCI_DEV_VIRTIO_MIN 0x1000
73e0724c53SAlexey Zaytsev #define	PCI_DEV_VIRTIO_MAX 0x103f
74e0724c53SAlexey Zaytsev #define	VIRTIO_PCI_ABI_VERSION 0
75e0724c53SAlexey Zaytsev 
76e0724c53SAlexey Zaytsev /* Virtio product id (subsystem) */
77e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_NETWORK	1
78e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_BLOCK	2
79e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_CONSOLE	3
80e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_ENTROPY	4
81e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_BALLOON	5
82e0724c53SAlexey Zaytsev #define	PCI_PRODUCT_VIRTIO_9P		9
83e0724c53SAlexey Zaytsev 
84e0724c53SAlexey Zaytsev /* Virtio header */
85e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_FEATURES		0 /* 32bit */
86e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_GUEST_FEATURES		4 /* 32bit */
87e0724c53SAlexey Zaytsev 
88e0724c53SAlexey Zaytsev #define	VIRTIO_F_NOTIFY_ON_EMPTY		(1<<24)
89e0724c53SAlexey Zaytsev #define	VIRTIO_F_RING_INDIRECT_DESC		(1<<28)
90e0724c53SAlexey Zaytsev #define	VIRTIO_F_BAD_FEATURE			(1<<30)
91e0724c53SAlexey Zaytsev 
92e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_QUEUE_ADDRESS		8 /* 32bit */
93e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_QUEUE_SIZE		12 /* 16bit */
94e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_QUEUE_SELECT		14 /* 16bit */
95e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_QUEUE_NOTIFY		16 /* 16bit */
96e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS		18 /* 8bit */
97e0724c53SAlexey Zaytsev 
98e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS_RESET	0
99e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS_ACK		1
100e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS_DRIVER	2
101e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK	4
102e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_DEVICE_STATUS_FAILED	128
103e0724c53SAlexey Zaytsev 
104e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_ISR_STATUS		19 /* 8bit */
105e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_ISR_CONFIG_CHANGE		2
106e0724c53SAlexey Zaytsev 
107e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_CONFIG_VECTOR		20 /* 16bit, optional */
108e0724c53SAlexey Zaytsev #define	VIRTIO_CONFIG_QUEUE_VECTOR		22
109e0724c53SAlexey Zaytsev 
110*17ad7f9fSAndriy Gapon #define	VIRTIO_CONFIG_DEVICE_CONFIG_NOMSIX	20
111*17ad7f9fSAndriy Gapon #define	VIRTIO_CONFIG_DEVICE_CONFIG_MSIX	24
112e0724c53SAlexey Zaytsev 
113e0724c53SAlexey Zaytsev #define	VIRTIO_MSI_NO_VECTOR 0xffff
114e0724c53SAlexey Zaytsev 
115e0724c53SAlexey Zaytsev /* Virtqueue */
116e0724c53SAlexey Zaytsev /* This marks a buffer as continuing via the next field. */
117e0724c53SAlexey Zaytsev #define	VRING_DESC_F_NEXT	1
118e0724c53SAlexey Zaytsev /*
119e0724c53SAlexey Zaytsev  * This marks a buffer as write-only, from the devices's perspective.
120e0724c53SAlexey Zaytsev  * (otherwise read-only).
121e0724c53SAlexey Zaytsev  */
122e0724c53SAlexey Zaytsev #define	VRING_DESC_F_WRITE	2
123e0724c53SAlexey Zaytsev /* This means the buffer contains a list of buffer descriptors. */
124e0724c53SAlexey Zaytsev #define	VRING_DESC_F_INDIRECT	4
125e0724c53SAlexey Zaytsev 
126e0724c53SAlexey Zaytsev /*
127e0724c53SAlexey Zaytsev  * The Host uses this in used->flags to advise the Guest: don't kick me
128e0724c53SAlexey Zaytsev  * when you add a buffer.  It's unreliable, so it's simply an
129e0724c53SAlexey Zaytsev  * optimization.  Guest will still kick if it's out of buffers.
130e0724c53SAlexey Zaytsev  */
131e0724c53SAlexey Zaytsev #define	VRING_USED_F_NO_NOTIFY	1
132e0724c53SAlexey Zaytsev /*
133e0724c53SAlexey Zaytsev  *  The Guest uses this in avail->flags to advise the Host: don't
134e0724c53SAlexey Zaytsev  * interrupt me when you consume a buffer.  It's unreliable, so it's
135e0724c53SAlexey Zaytsev  * simply an optimization.
136e0724c53SAlexey Zaytsev  */
137e0724c53SAlexey Zaytsev #define	VRING_AVAIL_F_NO_INTERRUPT	1
138e0724c53SAlexey Zaytsev 
139e0724c53SAlexey Zaytsev /*
140e0724c53SAlexey Zaytsev  * Virtio ring descriptors: 16 bytes.
141e0724c53SAlexey Zaytsev  * These can chain together via "next".
142e0724c53SAlexey Zaytsev  */
143e0724c53SAlexey Zaytsev struct vring_desc {
144e0724c53SAlexey Zaytsev 	/* Address (guest-physical). */
145e0724c53SAlexey Zaytsev 	uint64_t addr;
146e0724c53SAlexey Zaytsev 	/* Length. */
147e0724c53SAlexey Zaytsev 	uint32_t len;
148e0724c53SAlexey Zaytsev 	/* The flags as indicated above. */
149e0724c53SAlexey Zaytsev 	uint16_t flags;
150e0724c53SAlexey Zaytsev 	/* We chain unused descriptors via this, too */
151e0724c53SAlexey Zaytsev 	uint16_t next;
152e0724c53SAlexey Zaytsev } __attribute__((packed));
153e0724c53SAlexey Zaytsev 
154e0724c53SAlexey Zaytsev struct vring_avail {
155e0724c53SAlexey Zaytsev 	uint16_t flags;
156e0724c53SAlexey Zaytsev 	uint16_t idx;
157e0724c53SAlexey Zaytsev 	uint16_t ring[];
158e0724c53SAlexey Zaytsev } __attribute__((packed));
159e0724c53SAlexey Zaytsev 
160e0724c53SAlexey Zaytsev /* u32 is used here for ids for padding reasons. */
161e0724c53SAlexey Zaytsev struct vring_used_elem {
162e0724c53SAlexey Zaytsev 	/* Index of start of used descriptor chain. */
163e0724c53SAlexey Zaytsev 	uint32_t id;
164e0724c53SAlexey Zaytsev 	/* Total length of the descriptor chain which was written to. */
165e0724c53SAlexey Zaytsev 	uint32_t len;
166e0724c53SAlexey Zaytsev } __attribute__((packed));
167e0724c53SAlexey Zaytsev 
168e0724c53SAlexey Zaytsev struct vring_used {
169e0724c53SAlexey Zaytsev 	uint16_t flags;
170e0724c53SAlexey Zaytsev 	uint16_t idx;
171e0724c53SAlexey Zaytsev 	struct vring_used_elem ring[];
172e0724c53SAlexey Zaytsev } __attribute__((packed));
173e0724c53SAlexey Zaytsev 
174e0724c53SAlexey Zaytsev 
175e0724c53SAlexey Zaytsev /* Got nothing to do with the system page size, just a confusing name. */
176e0724c53SAlexey Zaytsev #define	VIRTIO_PAGE_SIZE	(4096)
177e0724c53SAlexey Zaytsev 
178e0724c53SAlexey Zaytsev #endif /* __VIRTIOREG_H__ */
179