xref: /dpdk/examples/vhost/main.h (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4 
5 #ifndef _MAIN_H_
6 #define _MAIN_H_
7 
8 #include <sys/queue.h>
9 
10 #include <rte_ether.h>
11 
12 /* Macros for printing using RTE_LOG */
13 #define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
14 #define RTE_LOGTYPE_VHOST_DATA   RTE_LOGTYPE_USER2
15 #define RTE_LOGTYPE_VHOST_PORT   RTE_LOGTYPE_USER3
16 
17 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
18 
19 #define MAX_PKT_BURST 32		/* Max burst size for RX/TX */
20 
21 struct device_statistics {
22 	uint64_t	tx;
23 	uint64_t	tx_total;
24 	uint64_t	rx_atomic;
25 	uint64_t	rx_total_atomic;
26 };
27 
28 struct vhost_queue {
29 	struct rte_vhost_vring	vr;
30 	uint16_t		last_avail_idx;
31 	uint16_t		last_used_idx;
32 };
33 
34 struct vhost_dev {
35 	/**< Number of memory regions for gpa to hpa translation. */
36 	uint32_t nregions_hpa;
37 	/**< Device MAC address (Obtained on first TX packet). */
38 	struct rte_ether_addr mac_address;
39 	/**< RX VMDQ queue number. */
40 	uint16_t vmdq_rx_q;
41 	/**< Vlan tag assigned to the pool */
42 	uint32_t vlan_tag;
43 	/**< Data core that the device is added to. */
44 	uint16_t coreid;
45 	/**< A device is set as ready if the MAC address has been set. */
46 	volatile uint8_t ready;
47 	/**< Device is marked for removal from the data core. */
48 	volatile uint8_t remove;
49 
50 	int vid;
51 	uint64_t features;
52 	size_t hdr_len;
53 	uint16_t nr_vrings;
54 	uint16_t pkts_inflight;
55 	struct rte_vhost_memory *mem;
56 	struct device_statistics stats;
57 	TAILQ_ENTRY(vhost_dev) global_vdev_entry;
58 	TAILQ_ENTRY(vhost_dev) lcore_vdev_entry;
59 
60 #define MAX_QUEUE_PAIRS	4
61 	struct vhost_queue queues[MAX_QUEUE_PAIRS * 2];
62 } __rte_cache_aligned;
63 
64 TAILQ_HEAD(vhost_dev_tailq_list, vhost_dev);
65 
66 
67 #define REQUEST_DEV_REMOVAL	1
68 #define ACK_DEV_REMOVAL		0
69 
70 /*
71  * Structure containing data core specific information.
72  */
73 struct lcore_info {
74 	uint32_t		device_num;
75 
76 	/* Flag to synchronize device removal. */
77 	volatile uint8_t	dev_removal_flag;
78 
79 	struct vhost_dev_tailq_list vdev_list;
80 };
81 
82 /* we implement non-extra virtio net features */
83 #define VIRTIO_NET_FEATURES	0
84 
85 void vs_vhost_net_setup(struct vhost_dev *dev);
86 void vs_vhost_net_remove(struct vhost_dev *dev);
87 uint16_t vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
88 			 struct rte_mbuf **pkts, uint32_t count);
89 
90 uint16_t vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
91 			 struct rte_mempool *mbuf_pool,
92 			 struct rte_mbuf **pkts, uint16_t count);
93 #endif /* _MAIN_H_ */
94