Seastar
High performance C++ framework for concurrent servers
virtio-interface.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 *
21 */
22
23#pragma once
24
25#ifndef _LINUX_VIRTIO_RING_H
26#define _LINUX_VIRTIO_RING_H
27
28/* An interface for efficient virtio implementation, currently for use by KVM
29 * and lguest, but hopefully others soon. Do NOT change this since it will
30 * break existing servers and clients.
31 *
32 * This header is BSD licensed so anyone can use the definitions to implement
33 * compatible drivers/servers.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of IBM nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * Copyright Rusty Russell IBM Corporation 2007. */
59
60/* This marks a buffer as continuing via the next field. */
61#define VRING_DESC_F_NEXT 1
62/* This marks a buffer as write-only (otherwise read-only). */
63#define VRING_DESC_F_WRITE 2
64/* This means the buffer contains a list of buffer descriptors. */
65#define VRING_DESC_F_INDIRECT 4
66
67/* The Host uses this in used->flags to advise the Guest: don't kick me when
68 * you add a buffer. It's unreliable, so it's simply an optimization. Guest
69 * will still kick if it's out of buffers. */
70#define VRING_USED_F_NO_NOTIFY 1
71/* The Guest uses this in avail->flags to advise the Host: don't interrupt me
72 * when you consume a buffer. It's unreliable, so it's simply an
73 * optimization. */
74#define VRING_AVAIL_F_NO_INTERRUPT 1
75
76/* We support indirect buffer descriptors */
77#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28)
78
79/* The Guest publishes the used index for which it expects an interrupt
80 * at the end of the avail ring. Host should ignore the avail->flags field. */
81/* The Host publishes the avail index for which it expects a kick
82 * at the end of the used ring. Guest should ignore the used->flags field. */
83#define VIRTIO_RING_F_EVENT_IDX (1 << 29)
84
85/* The standard layout for the ring is a continuous chunk of memory which looks
86 * like this. We assume num is a power of 2.
87 *
88 * struct vring
89 * {
90 * // The actual descriptors (16 bytes each)
91 * struct vring_desc desc[num];
92 *
93 * // A ring of available descriptor heads with free-running index.
94 * uint16_t avail_flags;
95 * uint16_t avail_idx;
96 * uint16_t available[num];
97 * uint16_t used_event_idx;
98 *
99 * // Padding to the next align boundary.
100 * char pad[];
101 *
102 * // A ring of used descriptor heads with free-running index.
103 * uint16_t used_flags;
104 * uint16_t used_idx;
105 * struct vring_used_elem used[num];
106 * uint16_t avail_event_idx;
107 * };
108 */
109
110#endif
111
112#define VIRTIO_NET_F_CSUM (1 << 0)
113#define VIRTIO_NET_F_GUEST_CSUM (1 << 1)
114#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS (1 << 2)
115#define VIRTIO_NET_F_MAC (1 << 5)
116#define VIRTIO_NET_F_GUEST_TSO4 (1 << 7)
117#define VIRTIO_NET_F_GUEST_TSO6 (1 << 8)
118#define VIRTIO_NET_F_GUEST_ECN (1 << 9)
119#define VIRTIO_NET_F_GUEST_UFO (1 << 10)
120#define VIRTIO_NET_F_HOST_TSO4 (1 << 11)
121#define VIRTIO_NET_F_HOST_TSO6 (1 << 12)
122#define VIRTIO_NET_F_HOST_ECN (1 << 13)
123#define VIRTIO_NET_F_HOST_UFO (1 << 14)
124#define VIRTIO_NET_F_MRG_RXBUF (1 << 15)
125#define VIRTIO_NET_F_STATUS (1 << 16)
126#define VIRTIO_NET_F_CTRL_VQ (1 << 17)
127#define VIRTIO_NET_F_CTRL_RX (1 << 18)
128#define VIRTIO_NET_F_CTRL_VLAN (1 << 19)
129#define VIRTIO_NET_F_GUEST_ANNOUNCE (1 << 21)
130#define VIRTIO_NET_F_MQ (1 << 22)
131#define VIRTIO_NET_F_CTRL_MAC_ADDR (1 << 23)