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