examples/pipeline: fix build
[dpdk.git] / lib / vhost / rte_vhost.h
index d0a8ae3..4683a53 100644 (file)
 extern "C" {
 #endif
 
+#ifndef __cplusplus
 /* These are not C++-aware. */
 #include <linux/vhost.h>
 #include <linux/virtio_ring.h>
 #include <linux/virtio_net.h>
+#endif
 
 #define RTE_VHOST_USER_CLIENT          (1ULL << 0)
 #define RTE_VHOST_USER_NO_RECONNECT    (1ULL << 1)
@@ -36,6 +38,8 @@ extern "C" {
 /* support only linear buffers (no chained mbufs) */
 #define RTE_VHOST_USER_LINEARBUF_SUPPORT       (1ULL << 6)
 #define RTE_VHOST_USER_ASYNC_COPY      (1ULL << 7)
+#define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS  (1ULL << 8)
+#define RTE_VHOST_USER_NET_STATS_ENABLE        (1ULL << 9)
 
 /* Features. */
 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
@@ -112,6 +116,11 @@ extern "C" {
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 #endif
 
+#define RTE_MAX_VHOST_DEVICE   1024
+
+#define RTE_VHOST_VDPA_DEVICE_TYPE_NET 0
+#define RTE_VHOST_VDPA_DEVICE_TYPE_BLK 1
+
 struct rte_vdpa_device;
 
 /**
@@ -263,7 +272,7 @@ struct rte_vhost_user_extern_ops {
 /**
  * Device and vring operations.
  */
-struct vhost_device_ops {
+struct rte_vhost_device_ops {
        int (*new_device)(int vid);             /**< Add device. */
        void (*destroy_device)(int vid);        /**< Remove device. */
 
@@ -291,6 +300,57 @@ struct vhost_device_ops {
        void *reserved[1]; /**< Reserved for future extension */
 };
 
+/**
+ * Power monitor condition.
+ */
+struct rte_vhost_power_monitor_cond {
+       /**< Address to monitor for changes */
+       volatile void *addr;
+       /**< If the `mask` is non-zero, location pointed
+        *   to by `addr` will be read and masked, then
+        *   compared with this value.
+        */
+       uint64_t val;
+       /**< 64-bit mask to extract value read from `addr` */
+       uint64_t mask;
+       /**< Data size (in bytes) that will be read from the
+        *   monitored memory location (`addr`).
+        */
+       uint8_t size;
+       /**< If 1, and masked value that read from 'addr' equals
+        *   'val', the driver should skip core sleep. If 0, and
+        *  masked value that read from 'addr' does not equal 'val',
+        *  the driver should skip core sleep.
+        */
+       uint8_t match;
+};
+
+/** Maximum name length for the statistics counters */
+#define RTE_VHOST_STATS_NAME_SIZE 64
+
+/**
+ * Vhost virtqueue statistics structure
+ *
+ * This structure is used by rte_vhost_vring_stats_get() to provide
+ * virtqueue statistics to the calling application.
+ * It maps a name ID, corresponding to an index in the array returned
+ * by rte_vhost_vring_stats_get_names(), to a statistic value.
+ */
+struct rte_vhost_stat {
+       uint64_t id;    /**< The index in xstats name array. */
+       uint64_t value; /**< The statistic counter value. */
+};
+
+/**
+ * Vhost virtqueue statistic name element
+ *
+ * This structure is used by rte_vhost_vring_stats_get_names() to
+ * provide virtqueue statistics names to the calling application.
+ */
+struct rte_vhost_stat_name {
+       char name[RTE_VHOST_STATS_NAME_SIZE]; /**< The statistic name. */
+};
+
 /**
  * Convert guest physical address to host virtual address
  *
@@ -341,7 +401,6 @@ rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa)
  * @return
  *  the host virtual address on success, 0 on failure
  */
-__rte_experimental
 static __rte_always_inline uint64_t
 rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem,
                                                   uint64_t gpa, uint64_t *len)
@@ -456,6 +515,20 @@ rte_vhost_driver_detach_vdpa_device(const char *path);
 struct rte_vdpa_device *
 rte_vhost_driver_get_vdpa_device(const char *path);
 
+/**
+ * Get the device type of the vdpa device.
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @param type
+ *  the device type of the vdpa device
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type);
+
 /**
  * Set the feature bits the vhost-user driver supports.
  *
@@ -521,7 +594,6 @@ int rte_vhost_driver_get_features(const char *path, uint64_t *features);
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_driver_set_protocol_features(const char *path,
                uint64_t protocol_features);
@@ -536,7 +608,6 @@ rte_vhost_driver_set_protocol_features(const char *path,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_driver_get_protocol_features(const char *path,
                uint64_t *protocol_features);
@@ -551,7 +622,6 @@ rte_vhost_driver_get_protocol_features(const char *path,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num);
 
@@ -584,7 +654,7 @@ rte_vhost_get_negotiated_protocol_features(int vid,
 
 /* Register callbacks. */
 int rte_vhost_driver_callback_register(const char *path,
-       struct vhost_device_ops const * const ops);
+       struct rte_vhost_device_ops const * const ops);
 
 /**
  *
@@ -767,7 +837,6 @@ int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx,
        struct rte_vhost_ring_inflight *vring);
@@ -775,7 +844,7 @@ rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx,
 /**
  * Set split inflight descriptor.
  *
- * This function save descriptors that has been comsumed in available
+ * This function save descriptors that has been consumed in available
  * ring
  *
  * @param vid
@@ -787,7 +856,6 @@ rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx,
        uint16_t idx);
@@ -795,7 +863,7 @@ rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx,
 /**
  * Set packed inflight descriptor and get corresponding inflight entry
  *
- * This function save descriptors that has been comsumed
+ * This function save descriptors that has been consumed
  *
  * @param vid
  *  vhost device ID
@@ -810,7 +878,6 @@ rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_set_inflight_desc_packed(int vid, uint16_t vring_idx,
        uint16_t head, uint16_t last, uint16_t *inflight_entry);
@@ -827,7 +894,6 @@ rte_vhost_set_inflight_desc_packed(int vid, uint16_t vring_idx,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_set_last_inflight_io_split(int vid,
        uint16_t vring_idx, uint16_t idx);
@@ -847,7 +913,6 @@ rte_vhost_set_last_inflight_io_split(int vid,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_set_last_inflight_io_packed(int vid,
        uint16_t vring_idx, uint16_t head);
@@ -866,7 +931,6 @@ rte_vhost_set_last_inflight_io_packed(int vid,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx,
        uint16_t last_used_idx, uint16_t idx);
@@ -883,7 +947,6 @@ rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx,
        uint16_t head);
@@ -913,6 +976,23 @@ int rte_vhost_vring_call(int vid, uint16_t vring_idx);
  */
 uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
 
+/**
+ * Get power monitor address of the vhost device
+ *
+ * @param vid
+ *  vhost device ID
+ * @param queue_id
+ *  vhost queue ID
+ * @param pmc
+ *  power monitor condition
+ * @return
+ *  0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
+               struct rte_vhost_power_monitor_cond *pmc);
+
 /**
  * Get log base and log size of the vhost device
  *
@@ -964,7 +1044,6 @@ rte_vhost_get_vring_base(int vid, uint16_t queue_id,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_get_vring_base_from_inflight(int vid,
        uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx);
@@ -999,7 +1078,6 @@ rte_vhost_set_vring_base(int vid, uint16_t queue_id,
  * @return
  *  0 on success, -1 on failure
  */
-__rte_experimental
 int
 rte_vhost_extern_callback_register(int vid,
                struct rte_vhost_user_extern_ops const * const ops, void *ctx);
@@ -1029,6 +1107,78 @@ __rte_experimental
 int
 rte_vhost_slave_config_change(int vid, bool need_reply);
 
+/**
+ * Retrieve names of statistics of a Vhost virtqueue.
+ *
+ * There is an assumption that 'stat_names' and 'stats' arrays are matched
+ * by array index: stats_names[i].name => stats[i].value
+ *
+ * @param vid
+ *   vhost device ID
+ * @param queue_id
+ *   vhost queue index
+ * @param name
+ *   array of at least size elements to be filled.
+ *   If set to NULL, the function returns the required number of elements.
+ * @param size
+ *   The number of elements in stats_names array.
+ * @return
+ *  - Success if greater than 0 and lower or equal to *size*. The return value
+ *    indicates the number of elements filled in the *names* array.
+ *  - Failure if greater than *size*. The return value indicates the number of
+ *    elements the *names* array that should be given to succeed.
+ *  - Failure if lower than 0. The device ID or queue ID is invalid or
+ +    statistics collection is not enabled.
+ */
+__rte_experimental
+int
+rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id,
+               struct rte_vhost_stat_name *name, unsigned int size);
+
+/**
+ * Retrieve statistics of a Vhost virtqueue.
+ *
+ * There is an assumption that 'stat_names' and 'stats' arrays are matched
+ * by array index: stats_names[i].name => stats[i].value
+ *
+ * @param vid
+ *   vhost device ID
+ * @param queue_id
+ *   vhost queue index
+ * @param stats
+ *   A pointer to a table of structure of type rte_vhost_stat to be filled with
+ *   virtqueue statistics ids and values.
+ * @param n
+ *   The number of elements in stats array.
+ * @return
+ *  - Success if greater than 0 and lower or equal to *n*. The return value
+ *    indicates the number of elements filled in the *stats* array.
+ *  - Failure if greater than *n*. The return value indicates the number of
+ *    elements the *stats* array that should be given to succeed.
+ *  - Failure if lower than 0. The device ID or queue ID is invalid, or
+ *    statistics collection is not enabled.
+ */
+__rte_experimental
+int
+rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
+               struct rte_vhost_stat *stats, unsigned int n);
+
+/**
+ * Reset statistics of a Vhost virtqueue.
+ *
+ * @param vid
+ *   vhost device ID
+ * @param queue_id
+ *   vhost queue index
+ * @return
+ *  - Success if 0. Statistics have been reset.
+ *  - Failure if lower than 0. The device ID or queue ID is invalid, or
+ *    statistics collection is not enabled.
+ */
+__rte_experimental
+int
+rte_vhost_vring_stats_reset(int vid, uint16_t queue_id);
+
 #ifdef __cplusplus
 }
 #endif