4ed5816f0db213e3614efe9a40a0d4496a567b5f
[dpdk.git] / lib / librte_vhost / vhost-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 _VHOST_NET_CDEV_H_
35 #define _VHOST_NET_CDEV_H_
36 #include <stdint.h>
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <linux/vhost.h>
41
42 #include <rte_log.h>
43
44 #include "rte_virtio_net.h"
45
46 /* Macros for printing using RTE_LOG */
47 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
48 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER1
49
50 #ifdef RTE_LIBRTE_VHOST_DEBUG
51 #define VHOST_MAX_PRINT_BUFF 6072
52 #define LOG_LEVEL RTE_LOG_DEBUG
53 #define LOG_DEBUG(log_type, fmt, args...) RTE_LOG(DEBUG, log_type, fmt, ##args)
54 #define PRINT_PACKET(device, addr, size, header) do { \
55         char *pkt_addr = (char *)(addr); \
56         unsigned int index; \
57         char packet[VHOST_MAX_PRINT_BUFF]; \
58         \
59         if ((header)) \
60                 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Header size %d: ", (device->vid), (size)); \
61         else \
62                 snprintf(packet, VHOST_MAX_PRINT_BUFF, "(%d) Packet size %d: ", (device->vid), (size)); \
63         for (index = 0; index < (size); index++) { \
64                 snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), \
65                         "%02hhx ", pkt_addr[index]); \
66         } \
67         snprintf(packet + strnlen(packet, VHOST_MAX_PRINT_BUFF), VHOST_MAX_PRINT_BUFF - strnlen(packet, VHOST_MAX_PRINT_BUFF), "\n"); \
68         \
69         LOG_DEBUG(VHOST_DATA, "%s", packet); \
70 } while (0)
71 #else
72 #define LOG_LEVEL RTE_LOG_INFO
73 #define LOG_DEBUG(log_type, fmt, args...) do {} while (0)
74 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
75 #endif
76
77
78 int vhost_new_device(void);
79 void vhost_destroy_device(int);
80
81 void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
82
83 int vhost_get_features(int, uint64_t *);
84 int vhost_set_features(int, uint64_t *);
85
86 int vhost_set_vring_num(int, struct vhost_vring_state *);
87 int vhost_set_vring_addr(int, struct vhost_vring_addr *);
88 int vhost_set_vring_base(int, struct vhost_vring_state *);
89 int vhost_get_vring_base(int, uint32_t, struct vhost_vring_state *);
90
91 int vhost_set_vring_kick(int, struct vhost_vring_file *);
92 int vhost_set_vring_call(int, struct vhost_vring_file *);
93
94 int vhost_set_backend(int, struct vhost_vring_file *);
95
96 int vhost_set_owner(int);
97 int vhost_reset_owner(int);
98
99 /*
100  * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
101  */
102 void vhost_backend_cleanup(struct virtio_net *dev);
103
104 #endif /* _VHOST_NET_CDEV_H_ */