dpdk/examples/vhost/main.h
<<
>>
Prefs
   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
  17enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
  18
  19#define MAX_PKT_BURST 32                /* Max burst size for RX/TX */
  20
  21struct device_statistics {
  22        uint64_t        tx;
  23        uint64_t        tx_total;
  24        uint64_t        rx_atomic;
  25        uint64_t        rx_total_atomic;
  26};
  27
  28struct vhost_queue {
  29        struct rte_vhost_vring  vr;
  30        uint16_t                last_avail_idx;
  31        uint16_t                last_used_idx;
  32};
  33
  34struct 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        struct rte_vhost_memory *mem;
  55        struct device_statistics stats;
  56        TAILQ_ENTRY(vhost_dev) global_vdev_entry;
  57        TAILQ_ENTRY(vhost_dev) lcore_vdev_entry;
  58
  59#define MAX_QUEUE_PAIRS 4
  60        struct vhost_queue queues[MAX_QUEUE_PAIRS * 2];
  61} __rte_cache_aligned;
  62
  63TAILQ_HEAD(vhost_dev_tailq_list, vhost_dev);
  64
  65
  66#define REQUEST_DEV_REMOVAL     1
  67#define ACK_DEV_REMOVAL         0
  68
  69/*
  70 * Structure containing data core specific information.
  71 */
  72struct lcore_info {
  73        uint32_t                device_num;
  74
  75        /* Flag to synchronize device removal. */
  76        volatile uint8_t        dev_removal_flag;
  77
  78        struct vhost_dev_tailq_list vdev_list;
  79};
  80
  81/* we implement non-extra virtio net features */
  82#define VIRTIO_NET_FEATURES     0
  83
  84void vs_vhost_net_setup(struct vhost_dev *dev);
  85void vs_vhost_net_remove(struct vhost_dev *dev);
  86uint16_t vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
  87                         struct rte_mbuf **pkts, uint32_t count);
  88
  89uint16_t vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
  90                         struct rte_mempool *mbuf_pool,
  91                         struct rte_mbuf **pkts, uint16_t count);
  92#endif /* _MAIN_H_ */
  93