app/testpmd: check statistics query before printing
[dpdk.git] / examples / vhost / main.h
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         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 struct dma_info {
83         struct rte_pci_addr addr;
84         int16_t dev_id;
85         bool async_enabled;
86 };
87
88 struct dma_for_vhost {
89         struct dma_info dmas[RTE_MAX_QUEUES_PER_PORT * 2];
90 };
91
92 /* we implement non-extra virtio net features */
93 #define VIRTIO_NET_FEATURES     0
94
95 void vs_vhost_net_setup(struct vhost_dev *dev);
96 void vs_vhost_net_remove(struct vhost_dev *dev);
97 uint16_t vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
98                          struct rte_mbuf **pkts, uint32_t count);
99
100 uint16_t vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
101                          struct rte_mempool *mbuf_pool,
102                          struct rte_mbuf **pkts, uint16_t count);
103 #endif /* _MAIN_H_ */