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;
32 struct rte_vhost_async_status {
33 /** An array of application specific data for source memory */
34 uintptr_t *src_opaque_data;
35 /** An array of application specific data for destination memory */
36 uintptr_t *dst_opaque_data;
40 * dma operation callbacks to be implemented by applications
42 struct rte_vhost_async_channel_ops {
44 * instruct async engines to perform copies for a batch of packets
47 * id of vhost device to perform data copies
49 * queue id to perform data copies
51 * an array of IOV iterators
53 * opaque data pair sending to DMA engine
55 * number of elements in the "descs" array
57 * number of IOV iterators processed, negative value means error
59 int32_t (*transfer_data)(int vid, uint16_t queue_id,
60 struct rte_vhost_iov_iter *iov_iter,
61 struct rte_vhost_async_status *opaque_data,
64 * check copy-completed packets from the async engine
66 * id of vhost device to check copy completion
68 * queue id to check copy completion
70 * buffer to receive the opaque data pair from DMA engine
72 * max number of packets could be completed
74 * number of async descs completed, negative value means error
76 int32_t (*check_completed_copies)(int vid, uint16_t queue_id,
77 struct rte_vhost_async_status *opaque_data,
78 uint16_t max_packets);
82 * async channel features
85 RTE_VHOST_ASYNC_INORDER = 1U << 0,
89 * async channel configuration
91 struct rte_vhost_async_config {
97 * Register an async channel for a vhost queue
100 * vhost device id async channel to be attached to
102 * vhost queue id async channel to be attached to
104 * Async channel configuration structure
106 * Async channel operation callbacks
108 * 0 on success, -1 on failures
111 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
112 struct rte_vhost_async_config config,
113 struct rte_vhost_async_channel_ops *ops);
116 * Unregister an async channel for a vhost queue
119 * vhost device id async channel to be detached from
121 * vhost queue id async channel to be detached from
123 * 0 on success, -1 on failures
126 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
129 * Register an async channel for a vhost queue without performing any
132 * @note This function does not perform any locking, and is only safe to
133 * call in vhost callback functions.
136 * vhost device id async channel to be attached to
138 * vhost queue id async channel to be attached to
140 * Async channel configuration
142 * Async channel operation callbacks
144 * 0 on success, -1 on failures
147 int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
148 struct rte_vhost_async_config config,
149 struct rte_vhost_async_channel_ops *ops);
152 * Unregister an async channel for a vhost queue without performing any
155 * @note This function does not perform any locking, and is only safe to
156 * call in vhost callback functions.
159 * vhost device id async channel to be detached from
161 * vhost queue id async channel to be detached from
163 * 0 on success, -1 on failures
166 int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
170 * This function submits enqueue packets to async copy engine. Users
171 * need to poll transfer status by rte_vhost_poll_enqueue_completed()
172 * for successfully enqueued packets.
175 * id of vhost device to enqueue data
177 * queue id to enqueue data
179 * array of packets to be enqueued
181 * packets num to be enqueued
183 * num of packets enqueued
186 uint16_t rte_vhost_submit_enqueue_burst(int vid, uint16_t queue_id,
187 struct rte_mbuf **pkts, uint16_t count);
190 * This function checks async completion status for a specific vhost
191 * device queue. Packets which finish copying (enqueue) operation
192 * will be returned in an array.
195 * id of vhost device to enqueue data
197 * queue id to enqueue data
199 * blank array to get return packet pointer
201 * size of the packet array
203 * num of packets returned
206 uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
207 struct rte_mbuf **pkts, uint16_t count);
210 * This function returns the amount of in-flight packets for the vhost
211 * queue which uses async channel acceleration.
214 * id of vhost device to enqueue data
216 * queue id to enqueue data
218 * the amount of in-flight packets on success; -1 on failure
221 int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
224 * This function checks async completion status and clear packets for
225 * a specific vhost device queue. Packets which are inflight will be
226 * returned in an array.
228 * @note This function does not perform any locking
231 * ID of vhost device to clear data
233 * Queue id to clear data
235 * Blank array to get return packet pointer
237 * Size of the packet array
239 * Number of packets returned
242 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
243 struct rte_mbuf **pkts, uint16_t count);
245 #endif /* _RTE_VHOST_ASYNC_H_ */