]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/examples/vhost_xen/xen_vhost.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / examples / vhost_xen / xen_vhost.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 _XEN_VHOST_H_
35 #define _XEN_VHOST_H_
36
37 #include <stdint.h>
38
39 #include <rte_ether.h>
40
41 #include "virtio-net.h"
42
43 #define RTE_LOGTYPE_XENHOST RTE_LOGTYPE_USER1
44
45 #define XEN_VM_ROOTNODE_FMT "/local/domain/%d/control/dpdk"
46 #define XEN_VM_NODE_FMT "/local/domain/%d/control/dpdk/%s"
47 #define XEN_MEMPOOL_SUFFIX "mempool_gref"
48 #define XEN_RXVRING_SUFFIX "rx_vring_gref"
49 #define XEN_TXVRING_SUFFIX "tx_vring_gref"
50 #define XEN_GVA_SUFFIX "mempool_va"
51 #define XEN_VRINGFLAG_SUFFIX "vring_flag"
52 #define XEN_ADDR_SUFFIX "ether_addr"
53 #define VIRTIO_START "event_type_start_"
54
55 #define XEN_GREF_SPLITTOKEN ','
56
57 #define MAX_XENVIRT_MEMPOOL 16
58 #define MAX_VIRTIO 32
59 #define MAX_GREF_PER_NODE 64 /* 128 MB memory */
60
61 #define PAGE_SIZE 4096
62 #define PAGE_PFNNUM (PAGE_SIZE / sizeof(uint32_t))
63
64 #define XEN_GNTDEV_FNAME "/dev/xen/gntdev"
65
66 /* xen grant reference info in one grant node */
67 struct xen_gnt {
68 uint32_t gref; /* grant reference for this node */
69 union {
70 int gref; /* grant reference */
71 uint32_t pfn_num; /* guest pfn number of grant reference */
72 } gref_pfn[PAGE_PFNNUM];
73 }__attribute__((__packed__));
74
75
76 /* structure for mempool or vring node list */
77 struct xen_gntnode {
78 uint32_t gnt_num; /* grant reference number */
79 struct xen_gnt *gnt_info; /* grant reference info */
80 };
81
82
83 struct xen_vring {
84 uint32_t dom_id;
85 uint32_t virtio_idx; /* index of virtio device */
86 void *rxvring_addr; /* mapped virtual address of rxvring */
87 void *txvring_addr; /* mapped virtual address of txvring */
88 uint32_t rxpfn_num; /* number of gpfn for rxvring */
89 uint32_t txpfn_num; /* number of gpfn for txvring */
90 uint32_t *rxpfn_tbl; /* array of rxvring gpfn */
91 uint32_t *txpfn_tbl; /* array of txvring gpfn */
92 uint64_t *rx_pindex; /* index used to release rx grefs */
93 uint64_t *tx_pindex; /* index used to release tx grefs */
94 uint64_t flag_index;
95 uint8_t *flag; /* cleared to zero on guest unmap */
96 struct ether_addr addr; /* ethernet address of virtio device */
97 uint8_t removed;
98
99 };
100
101 struct xen_mempool {
102 uint32_t dom_id; /* guest domain id */
103 uint32_t pool_idx; /* index of memory pool */
104 void *gva; /* guest virtual address of mbuf pool */
105 void *hva; /* host virtual address of mbuf pool */
106 uint32_t mempfn_num; /* number of gpfn for mbuf pool */
107 uint32_t *mempfn_tbl; /* array of mbuf pool gpfn */
108 uint64_t *pindex; /* index used to release grefs */
109 };
110
111 struct xen_guest {
112 TAILQ_ENTRY(xen_guest) next;
113 int32_t dom_id; /* guest domain id */
114 uint32_t pool_num; /* number of mbuf pool of the guest */
115 uint32_t vring_num; /* number of virtio ports of the guest */
116 /* array contain the guest mbuf pool info */
117 struct xen_mempool mempool[MAX_XENVIRT_MEMPOOL];
118 /* array contain the guest rx/tx vring info */
119 struct xen_vring vring[MAX_VIRTIO];
120 };
121
122 TAILQ_HEAD(xen_guestlist, xen_guest);
123
124 int
125 parse_mempoolnode(struct xen_guest *guest);
126
127 int
128 xenhost_init(void);
129
130 int
131 parse_vringnode(struct xen_guest *guest, uint32_t virtio_idx);
132
133 int
134 parse_mempoolnode(struct xen_guest *guest);
135
136 void
137 cleanup_mempool(struct xen_mempool *mempool);
138
139 void
140 cleanup_vring(struct xen_vring *vring);
141
142 void
143 virtio_monitor_loop(void);
144
145 int
146 init_virtio_xen(struct virtio_net_device_ops const * const);
147
148 #endif