1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
5 #ifndef _RTE_VHOST_ASYNC_H_
6 #define _RTE_VHOST_ASYNC_H_
13 struct rte_vhost_iovec {
22 struct rte_vhost_iov_iter {
23 /** pointer to the iovec array */
24 struct rte_vhost_iovec *iov;
25 /** number of iovec in this iterator */
26 unsigned long nr_segs;
30 * dma transfer descriptor
32 struct rte_vhost_async_desc {
34 struct rte_vhost_iov_iter *iter;
40 struct rte_vhost_async_status {
41 /** An array of application specific data for source memory */
42 uintptr_t *src_opaque_data;
43 /** An array of application specific data for destination memory */
44 uintptr_t *dst_opaque_data;
48 * dma operation callbacks to be implemented by applications
50 struct rte_vhost_async_channel_ops {
52 * instruct async engines to perform copies for a batch of packets
55 * id of vhost device to perform data copies
57 * queue id to perform data copies
59 * an array of DMA transfer memory descriptors
61 * opaque data pair sending to DMA engine
63 * number of elements in the "descs" array
65 * number of descs processed, negative value means error
67 int32_t (*transfer_data)(int vid, uint16_t queue_id,
68 struct rte_vhost_async_desc *descs,
69 struct rte_vhost_async_status *opaque_data,
72 * check copy-completed packets from the async engine
74 * id of vhost device to check copy completion
76 * queue id to check copy completion
78 * buffer to receive the opaque data pair from DMA engine
80 * max number of packets could be completed
82 * number of async descs completed, negative value means error
84 int32_t (*check_completed_copies)(int vid, uint16_t queue_id,
85 struct rte_vhost_async_status *opaque_data,
86 uint16_t max_packets);
90 * async channel features
93 RTE_VHOST_ASYNC_INORDER = 1U << 0,
97 * async channel configuration
99 struct rte_vhost_async_config {
105 * Register an async channel for a vhost queue
108 * vhost device id async channel to be attached to
110 * vhost queue id async channel to be attached to
112 * Async channel configuration structure
114 * Async channel operation callbacks
116 * 0 on success, -1 on failures
119 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
120 struct rte_vhost_async_config config,
121 struct rte_vhost_async_channel_ops *ops);
124 * Unregister an async channel for a vhost queue
127 * vhost device id async channel to be detached from
129 * vhost queue id async channel to be detached from
131 * 0 on success, -1 on failures
134 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
137 * Register an async channel for a vhost queue without performing any
140 * @note This function does not perform any locking, and is only safe to
141 * call in vhost callback functions.
144 * vhost device id async channel to be attached to
146 * vhost queue id async channel to be attached to
148 * Async channel configuration
150 * Async channel operation callbacks
152 * 0 on success, -1 on failures
155 int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
156 struct rte_vhost_async_config config,
157 struct rte_vhost_async_channel_ops *ops);
160 * Unregister an async channel for a vhost queue without performing any
163 * @note This function does not perform any locking, and is only safe to
164 * call in vhost callback functions.
167 * vhost device id async channel to be detached from
169 * vhost queue id async channel to be detached from
171 * 0 on success, -1 on failures
174 int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
178 * This function submits enqueue packets to async copy engine. Users
179 * need to poll transfer status by rte_vhost_poll_enqueue_completed()
180 * for successfully enqueued packets.
183 * id of vhost device to enqueue data
185 * queue id to enqueue data
187 * array of packets to be enqueued
189 * packets num to be enqueued
191 * num of packets enqueued
194 uint16_t rte_vhost_submit_enqueue_burst(int vid, uint16_t queue_id,
195 struct rte_mbuf **pkts, uint16_t count);
198 * This function checks async completion status for a specific vhost
199 * device queue. Packets which finish copying (enqueue) operation
200 * will be returned in an array.
203 * id of vhost device to enqueue data
205 * queue id to enqueue data
207 * blank array to get return packet pointer
209 * size of the packet array
211 * num of packets returned
214 uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
215 struct rte_mbuf **pkts, uint16_t count);
218 * This function returns the amount of in-flight packets for the vhost
219 * queue which uses async channel acceleration.
222 * id of vhost device to enqueue data
224 * queue id to enqueue data
226 * the amount of in-flight packets on success; -1 on failure
229 int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
232 * This function checks async completion status and clear packets for
233 * a specific vhost device queue. Packets which are inflight will be
234 * returned in an array.
236 * @note This function does not perform any locking
239 * ID of vhost device to clear data
241 * Queue id to clear data
243 * Blank array to get return packet pointer
245 * Size of the packet array
247 * Number of packets returned
250 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
251 struct rte_mbuf **pkts, uint16_t count);
253 #endif /* _RTE_VHOST_ASYNC_H_ */