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.
34 #ifndef _VIRTIO_NET_H_
35 #define _VIRTIO_NET_H_
39 * Interface to vhost net
43 #include <linux/vhost.h>
44 #include <linux/virtio_ring.h>
45 #include <linux/virtio_net.h>
46 #include <sys/eventfd.h>
47 #include <sys/socket.h>
50 #include <rte_memory.h>
51 #include <rte_mempool.h>
52 #include <rte_ether.h>
54 #define RTE_VHOST_USER_CLIENT (1ULL << 0)
55 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
57 /* Enum for virtqueue management. */
58 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
61 * Device and vring operations.
63 * Make sure to set VIRTIO_DEV_RUNNING to the device flags in new_device and
64 * remove it in destroy_device.
67 struct virtio_net_device_ops {
68 int (*new_device)(int vid); /**< Add device. */
69 void (*destroy_device)(int vid); /**< Remove device. */
71 int (*vring_state_changed)(int vid, uint16_t queue_id, int enable); /**< triggered when a vring is enabled or disabled */
73 void *reserved[5]; /**< Reserved for future extension */
77 * Disable features in feature_mask. Returns 0 on success.
79 int rte_vhost_feature_disable(uint64_t feature_mask);
82 * Enable features in feature_mask. Returns 0 on success.
84 int rte_vhost_feature_enable(uint64_t feature_mask);
86 /* Returns currently supported vhost features */
87 uint64_t rte_vhost_feature_get(void);
89 int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
92 * Register vhost driver. path could be different for multiple
95 int rte_vhost_driver_register(const char *path, uint64_t flags);
97 /* Unregister vhost driver. This is only meaningful to vhost user. */
98 int rte_vhost_driver_unregister(const char *path);
100 /* Register callbacks. */
101 int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const);
102 /* Start vhost driver session blocking loop. */
103 int rte_vhost_driver_session_start(void);
106 * Get the numa node from which the virtio net device's memory
110 * virtio-net device ID
113 * The numa node, -1 on failure
115 int rte_vhost_get_numa_node(int vid);
118 * Get the number of queues the device supports.
121 * virtio-net device ID
124 * The number of queues, 0 on failure
126 uint32_t rte_vhost_get_queue_num(int vid);
129 * Get the virtio net device's ifname. For vhost-cuse, ifname is the
130 * path of the char device. For vhost-user, ifname is the vhost-user
134 * virtio-net device ID
136 * The buffer to stored the queried ifname
141 * 0 on success, -1 on failure
143 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
146 * Get how many avail entries are left in the queue
149 * virtio-net device ID
154 * num of avail entires left
156 uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
159 * This function adds buffers to the virtio devices RX virtqueue. Buffers can
160 * be received from the physical port or from another virtual device. A packet
161 * count is returned to indicate the number of packets that were succesfully
162 * added to the RX queue.
164 * virtio-net device ID
166 * virtio queue index in mq case
168 * array to contain packets to be enqueued
170 * packets num to be enqueued
172 * num of packets enqueued
174 uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
175 struct rte_mbuf **pkts, uint16_t count);
178 * This function gets guest buffers from the virtio device TX virtqueue,
179 * construct host mbufs, copies guest buffer content to host mbufs and
180 * store them in pkts to be processed.
184 * virtio queue index in mq case
186 * mbuf_pool where host mbuf is allocated.
188 * array to contain packets to be dequeued
190 * packets num to be dequeued
192 * num of packets dequeued
194 uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
195 struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
197 #endif /* _VIRTIO_NET_H_ */