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 /** offset to the first byte of interesting data */
25 /** total bytes of data in this iterator */
27 /** pointer to the iovec array */
28 struct rte_vhost_iovec *iov;
29 /** number of iovec in this iterator */
30 unsigned long nr_segs;
34 * dma transfer descriptor
36 struct rte_vhost_async_desc {
38 struct rte_vhost_iov_iter *iter;
44 struct rte_vhost_async_status {
45 /** An array of application specific data for source memory */
46 uintptr_t *src_opaque_data;
47 /** An array of application specific data for destination memory */
48 uintptr_t *dst_opaque_data;
52 * dma operation callbacks to be implemented by applications
54 struct rte_vhost_async_channel_ops {
56 * instruct async engines to perform copies for a batch of packets
59 * id of vhost device to perform data copies
61 * queue id to perform data copies
63 * an array of DMA transfer memory descriptors
65 * opaque data pair sending to DMA engine
67 * number of elements in the "descs" array
69 * number of descs processed, negative value means error
71 int32_t (*transfer_data)(int vid, uint16_t queue_id,
72 struct rte_vhost_async_desc *descs,
73 struct rte_vhost_async_status *opaque_data,
76 * check copy-completed packets from the async engine
78 * id of vhost device to check copy completion
80 * queue id to check copy completion
82 * buffer to receive the opaque data pair from DMA engine
84 * max number of packets could be completed
86 * number of async descs completed, negative value means error
88 int32_t (*check_completed_copies)(int vid, uint16_t queue_id,
89 struct rte_vhost_async_status *opaque_data,
90 uint16_t max_packets);
94 * async channel features
97 RTE_VHOST_ASYNC_INORDER = 1U << 0,
101 * async channel configuration
103 struct rte_vhost_async_config {
109 * Register an async channel for a vhost queue
112 * vhost device id async channel to be attached to
114 * vhost queue id async channel to be attached to
116 * Async channel configuration structure
118 * Async channel operation callbacks
120 * 0 on success, -1 on failures
123 int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
124 struct rte_vhost_async_config config,
125 struct rte_vhost_async_channel_ops *ops);
128 * Unregister an async channel for a vhost queue
131 * vhost device id async channel to be detached from
133 * vhost queue id async channel to be detached from
135 * 0 on success, -1 on failures
138 int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
141 * Register an async channel for a vhost queue without performing any
144 * @note This function does not perform any locking, and is only safe to
145 * call in vhost callback functions.
148 * vhost device id async channel to be attached to
150 * vhost queue id async channel to be attached to
152 * Async channel configuration
154 * Async channel operation callbacks
156 * 0 on success, -1 on failures
159 int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id,
160 struct rte_vhost_async_config config,
161 struct rte_vhost_async_channel_ops *ops);
164 * Unregister an async channel for a vhost queue without performing any
167 * @note This function does not perform any locking, and is only safe to
168 * call in vhost callback functions.
171 * vhost device id async channel to be detached from
173 * vhost queue id async channel to be detached from
175 * 0 on success, -1 on failures
178 int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
182 * This function submits enqueue packets to async copy engine. Users
183 * need to poll transfer status by rte_vhost_poll_enqueue_completed()
184 * for successfully enqueued packets.
187 * id of vhost device to enqueue data
189 * queue id to enqueue data
191 * array of packets to be enqueued
193 * packets num to be enqueued
195 * num of packets enqueued
198 uint16_t rte_vhost_submit_enqueue_burst(int vid, uint16_t queue_id,
199 struct rte_mbuf **pkts, uint16_t count);
202 * This function checks async completion status for a specific vhost
203 * device queue. Packets which finish copying (enqueue) operation
204 * will be returned in an array.
207 * id of vhost device to enqueue data
209 * queue id to enqueue data
211 * blank array to get return packet pointer
213 * size of the packet array
215 * num of packets returned
218 uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
219 struct rte_mbuf **pkts, uint16_t count);
222 * This function returns the amount of in-flight packets for the vhost
223 * queue which uses async channel acceleration.
226 * id of vhost device to enqueue data
228 * queue id to enqueue data
230 * the amount of in-flight packets on success; -1 on failure
233 int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
236 * This function checks async completion status and clear packets for
237 * a specific vhost device queue. Packets which are inflight will be
238 * returned in an array.
240 * @note This function does not perform any locking
243 * ID of vhost device to clear data
245 * Queue id to clear data
247 * Blank array to get return packet pointer
249 * Size of the packet array
251 * Number of packets returned
254 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
255 struct rte_mbuf **pkts, uint16_t count);
257 #endif /* _RTE_VHOST_ASYNC_H_ */