4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
39 #include <rte_ether.h>
41 #include "virtio-net.h"
43 #define RTE_LOGTYPE_XENHOST RTE_LOGTYPE_USER1
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_"
55 #define XEN_GREF_SPLITTOKEN ','
57 #define MAX_XENVIRT_MEMPOOL 16
59 #define MAX_GREF_PER_NODE 64 /* 128 MB memory */
61 #define PAGE_SIZE 4096
62 #define PAGE_PFNNUM (PAGE_SIZE / sizeof(uint32_t))
64 #define XEN_GNTDEV_FNAME "/dev/xen/gntdev"
66 /* xen grant reference info in one grant node */
68 uint32_t gref; /* grant reference for this node */
70 int gref; /* grant reference */
71 uint32_t pfn_num; /* guest pfn number of grant reference */
72 } gref_pfn[PAGE_PFNNUM];
73 }__attribute__((__packed__));
76 /* structure for mempool or vring node list */
78 uint32_t gnt_num; /* grant reference number */
79 struct xen_gnt *gnt_info; /* grant reference info */
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 */
95 uint8_t *flag; /* cleared to zero on guest unmap */
96 struct ether_addr addr; /* ethernet address of virtio device */
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 */
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];
122 TAILQ_HEAD(xen_guestlist, xen_guest);
125 parse_mempoolnode(struct xen_guest *guest);
131 parse_vringnode(struct xen_guest *guest, uint32_t virtio_idx);
134 parse_mempoolnode(struct xen_guest *guest);
137 cleanup_mempool(struct xen_mempool *mempool);
140 cleanup_vring(struct xen_vring *vring);
143 virtio_monitor_loop(void);
146 init_virtio_xen(struct virtio_net_device_ops const * const);