remove trailing whitespaces
[dpdk.git] / examples / vhost_xen / virtio-net.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _VIRTIO_NET_H_
35 #define _VIRTIO_NET_H_
36
37 #include <stdint.h>
38
39 #define VQ_DESC_NUM 256
40 /* Used to indicate that the device is running on a data core */
41 #define VIRTIO_DEV_RUNNING 1
42
43 /*
44  * Structure contains variables relevant to TX/RX virtqueues.
45  */
46 struct vhost_virtqueue
47 {
48         struct vring_desc  *desc;             /* Virtqueue descriptor ring. */
49         struct vring_avail *avail;            /* Virtqueue available ring. */
50         struct vring_used  *used;             /* Virtqueue used ring. */
51         uint32_t           size;              /* Size of descriptor ring. */
52         uint32_t           vhost_hlen;        /* Vhost header length (varies depending on RX merge buffers. */
53         volatile uint16_t  last_used_idx;     /* Last index used on the available ring */
54         volatile uint16_t  last_used_idx_res; /* Used for multiple devices reserving buffers. */
55 } __rte_cache_aligned;
56
57 /*
58  * Device structure contains all configuration information relating to the device.
59  */
60 struct virtio_net
61 {
62         struct vhost_virtqueue  *virtqueue_tx;  /* Contains all TX virtqueue information. */
63         struct vhost_virtqueue  *virtqueue_rx;  /* Contains all RX virtqueue information. */
64         struct virtio_memory    *mem;           /* QEMU memory and memory region information. */
65         struct ether_addr       mac_address;    /* Device MAC address (Obtained on first TX packet). */
66         uint32_t                flags;          /* Device flags. Only used to check if device is running on data core. */
67         uint32_t                vlan_tag;       /* Vlan tag for device. Currently set to device_id (0-63). */
68         uint32_t                vmdq_rx_q;
69         uint64_t                device_fh;      /* device identifier. */
70         uint16_t                coreid;
71         volatile uint8_t        ready;          /* A device is set as ready if the MAC address has been set. */
72         volatile uint8_t        remove;         /* Device is marked for removal from the data core. */
73         uint32_t                virtio_idx;     /* Index of virtio device */
74         uint32_t                dom_id;         /* Domain id of xen guest */
75 } ___rte_cache_aligned;
76
77 /*
78  * Device linked list structure for configuration.
79  */
80 struct virtio_net_config_ll
81 {
82         struct virtio_net               dev;    /* Virtio device. */
83         struct virtio_net_config_ll     *next; /* Next entry on linked list. */
84 };
85
86 /*
87  * Information relating to memory regions including offsets to addresses in QEMUs memory file.
88  */
89 struct virtio_memory_regions {
90         uint64_t        guest_phys_address;     /* Base guest physical address of region. */
91         uint64_t        guest_phys_address_end; /* End guest physical address of region. */
92         uint64_t        memory_size;            /* Size of region. */
93         uint64_t        userspace_address;      /* Base userspace address of region. */
94         uint64_t        address_offset;         /* Offset of region for address translation. */
95 };
96
97 /*
98  * Memory structure includes region and mapping information.
99  */
100 struct virtio_memory {
101         uint32_t                        nregions;       /* Number of memory regions. */
102         struct virtio_memory_regions    regions[0];     /* Memory region information. */
103 };
104
105 /*
106  * Device operations to add/remove device.
107  */
108 struct virtio_net_device_ops {
109         int (* new_device)(struct virtio_net *);        /* Add device. */
110         void (* destroy_device) (volatile struct virtio_net *); /* Remove device. */
111 };
112
113 struct vhost_net_device_ops const * get_virtio_net_callbacks(void);
114
115 #endif