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