xref: /dpdk/lib/vhost/rte_vhost_async.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2020 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_VHOST_ASYNC_H_
699a2dd95SBruce Richardson #define _RTE_VHOST_ASYNC_H_
799a2dd95SBruce Richardson 
853d3f477SJiayu Hu #include <stdint.h>
999a2dd95SBruce Richardson 
1053d3f477SJiayu Hu #include <rte_compat.h>
1153d3f477SJiayu Hu #include <rte_mbuf.h>
12acbc3888SJiayu Hu 
13*719834a6SMattias Rönnblom #ifdef __cplusplus
14*719834a6SMattias Rönnblom extern "C" {
15*719834a6SMattias Rönnblom #endif
16*719834a6SMattias Rönnblom 
17acbc3888SJiayu Hu /**
18acbc3888SJiayu Hu  * Register an async channel for a vhost queue
1999a2dd95SBruce Richardson  *
2099a2dd95SBruce Richardson  * @param vid
2199a2dd95SBruce Richardson  *  vhost device id async channel to be attached to
2299a2dd95SBruce Richardson  * @param queue_id
2399a2dd95SBruce Richardson  *  vhost queue id async channel to be attached to
2499a2dd95SBruce Richardson  * @return
2599a2dd95SBruce Richardson  *  0 on success, -1 on failures
2699a2dd95SBruce Richardson  */
2799a2dd95SBruce Richardson __rte_experimental
2853d3f477SJiayu Hu int rte_vhost_async_channel_register(int vid, uint16_t queue_id);
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson /**
31acbc3888SJiayu Hu  * Unregister an async channel for a vhost queue
3299a2dd95SBruce Richardson  *
3399a2dd95SBruce Richardson  * @param vid
34acbc3888SJiayu Hu  *  vhost device id async channel to be detached from
3599a2dd95SBruce Richardson  * @param queue_id
36acbc3888SJiayu Hu  *  vhost queue id async channel to be detached from
3799a2dd95SBruce Richardson  * @return
3899a2dd95SBruce Richardson  *  0 on success, -1 on failures
3999a2dd95SBruce Richardson  */
4099a2dd95SBruce Richardson __rte_experimental
4199a2dd95SBruce Richardson int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id);
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson /**
44fa51f1aaSJiayu Hu  * Register an async channel for a vhost queue without performing any
45fa51f1aaSJiayu Hu  * locking
46fa51f1aaSJiayu Hu  *
47fa51f1aaSJiayu Hu  * @note This function does not perform any locking, and is only safe to
48fa51f1aaSJiayu Hu  *       call in vhost callback functions.
49fa51f1aaSJiayu Hu  *
50fa51f1aaSJiayu Hu  * @param vid
51fa51f1aaSJiayu Hu  *  vhost device id async channel to be attached to
52fa51f1aaSJiayu Hu  * @param queue_id
53fa51f1aaSJiayu Hu  *  vhost queue id async channel to be attached to
54fa51f1aaSJiayu Hu  * @return
55fa51f1aaSJiayu Hu  *  0 on success, -1 on failures
56fa51f1aaSJiayu Hu  */
57fa51f1aaSJiayu Hu __rte_experimental
5853d3f477SJiayu Hu int rte_vhost_async_channel_register_thread_unsafe(int vid, uint16_t queue_id);
59fa51f1aaSJiayu Hu 
60fa51f1aaSJiayu Hu /**
61fa51f1aaSJiayu Hu  * Unregister an async channel for a vhost queue without performing any
62fa51f1aaSJiayu Hu  * locking
63fa51f1aaSJiayu Hu  *
64fa51f1aaSJiayu Hu  * @note This function does not perform any locking, and is only safe to
65fa51f1aaSJiayu Hu  *       call in vhost callback functions.
66fa51f1aaSJiayu Hu  *
67fa51f1aaSJiayu Hu  * @param vid
68fa51f1aaSJiayu Hu  *  vhost device id async channel to be detached from
69fa51f1aaSJiayu Hu  * @param queue_id
70fa51f1aaSJiayu Hu  *  vhost queue id async channel to be detached from
71fa51f1aaSJiayu Hu  * @return
72fa51f1aaSJiayu Hu  *  0 on success, -1 on failures
73fa51f1aaSJiayu Hu  */
74fa51f1aaSJiayu Hu __rte_experimental
75fa51f1aaSJiayu Hu int rte_vhost_async_channel_unregister_thread_unsafe(int vid,
76fa51f1aaSJiayu Hu 		uint16_t queue_id);
77fa51f1aaSJiayu Hu 
78fa51f1aaSJiayu Hu /**
79abeb8652SJiayu Hu  * This function submits enqueue packets to async copy engine. Users
80abeb8652SJiayu Hu  * need to poll transfer status by rte_vhost_poll_enqueue_completed()
81abeb8652SJiayu Hu  * for successfully enqueued packets.
8299a2dd95SBruce Richardson  *
8399a2dd95SBruce Richardson  * @param vid
8499a2dd95SBruce Richardson  *  id of vhost device to enqueue data
8599a2dd95SBruce Richardson  * @param queue_id
8699a2dd95SBruce Richardson  *  queue id to enqueue data
8799a2dd95SBruce Richardson  * @param pkts
8899a2dd95SBruce Richardson  *  array of packets to be enqueued
8999a2dd95SBruce Richardson  * @param count
9099a2dd95SBruce Richardson  *  packets num to be enqueued
9153d3f477SJiayu Hu  * @param dma_id
9253d3f477SJiayu Hu  *  the identifier of DMA device
9353d3f477SJiayu Hu  * @param vchan_id
9453d3f477SJiayu Hu  *  the identifier of virtual DMA channel
9599a2dd95SBruce Richardson  * @return
96abeb8652SJiayu Hu  *  num of packets enqueued
9799a2dd95SBruce Richardson  */
9899a2dd95SBruce Richardson __rte_experimental
9999a2dd95SBruce Richardson uint16_t rte_vhost_submit_enqueue_burst(int vid, uint16_t queue_id,
10053d3f477SJiayu Hu 		struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
10153d3f477SJiayu Hu 		uint16_t vchan_id);
10299a2dd95SBruce Richardson 
10399a2dd95SBruce Richardson /**
10499a2dd95SBruce Richardson  * This function checks async completion status for a specific vhost
10599a2dd95SBruce Richardson  * device queue. Packets which finish copying (enqueue) operation
10699a2dd95SBruce Richardson  * will be returned in an array.
10799a2dd95SBruce Richardson  *
10899a2dd95SBruce Richardson  * @param vid
10999a2dd95SBruce Richardson  *  id of vhost device to enqueue data
11099a2dd95SBruce Richardson  * @param queue_id
11199a2dd95SBruce Richardson  *  queue id to enqueue data
11299a2dd95SBruce Richardson  * @param pkts
11399a2dd95SBruce Richardson  *  blank array to get return packet pointer
11499a2dd95SBruce Richardson  * @param count
11599a2dd95SBruce Richardson  *  size of the packet array
11653d3f477SJiayu Hu  * @param dma_id
11753d3f477SJiayu Hu  *  the identifier of DMA device
11853d3f477SJiayu Hu  * @param vchan_id
11953d3f477SJiayu Hu  *  the identifier of virtual DMA channel
12099a2dd95SBruce Richardson  * @return
12199a2dd95SBruce Richardson  *  num of packets returned
12299a2dd95SBruce Richardson  */
12399a2dd95SBruce Richardson __rte_experimental
12499a2dd95SBruce Richardson uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
12553d3f477SJiayu Hu 		struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
12653d3f477SJiayu Hu 		uint16_t vchan_id);
12799a2dd95SBruce Richardson 
1280c0935c5SJiayu Hu /**
1290c0935c5SJiayu Hu  * This function returns the amount of in-flight packets for the vhost
1300c0935c5SJiayu Hu  * queue which uses async channel acceleration.
1310c0935c5SJiayu Hu  *
1320c0935c5SJiayu Hu  * @param vid
1330c0935c5SJiayu Hu  *  id of vhost device to enqueue data
1340c0935c5SJiayu Hu  * @param queue_id
1350c0935c5SJiayu Hu  *  queue id to enqueue data
1360c0935c5SJiayu Hu  * @return
1370c0935c5SJiayu Hu  *  the amount of in-flight packets on success; -1 on failure
1380c0935c5SJiayu Hu  */
1390c0935c5SJiayu Hu __rte_experimental
1400c0935c5SJiayu Hu int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
1410c0935c5SJiayu Hu 
142b737fd61SCheng Jiang /**
1431419e8d9SXuan Ding  * This function is lock-free version to return the amount of in-flight
1441419e8d9SXuan Ding  * packets for the vhost queue which uses async channel acceleration.
1451419e8d9SXuan Ding  *
1461419e8d9SXuan Ding  * @note This function does not perform any locking, it should only be
1471419e8d9SXuan Ding  * used within the vhost ops, which already holds the lock.
1481419e8d9SXuan Ding  *
1491419e8d9SXuan Ding  * @param vid
1501419e8d9SXuan Ding  * id of vhost device to enqueue data
1511419e8d9SXuan Ding  * @param queue_id
1521419e8d9SXuan Ding  * queue id to enqueue data
1531419e8d9SXuan Ding  * @return
1541419e8d9SXuan Ding  * the amount of in-flight packets on success; -1 on failure
1551419e8d9SXuan Ding  */
1561419e8d9SXuan Ding __rte_experimental
1571419e8d9SXuan Ding int rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id);
1581419e8d9SXuan Ding 
1591419e8d9SXuan Ding /**
160b737fd61SCheng Jiang  * This function checks async completion status and clear packets for
161b737fd61SCheng Jiang  * a specific vhost device queue. Packets which are inflight will be
162b737fd61SCheng Jiang  * returned in an array.
163b737fd61SCheng Jiang  *
164b737fd61SCheng Jiang  * @note This function does not perform any locking
165b737fd61SCheng Jiang  *
166b737fd61SCheng Jiang  * @param vid
167b737fd61SCheng Jiang  *  ID of vhost device to clear data
168b737fd61SCheng Jiang  * @param queue_id
169b737fd61SCheng Jiang  *  Queue id to clear data
170b737fd61SCheng Jiang  * @param pkts
171b737fd61SCheng Jiang  *  Blank array to get return packet pointer
172b737fd61SCheng Jiang  * @param count
173b737fd61SCheng Jiang  *  Size of the packet array
17453d3f477SJiayu Hu  * @param dma_id
17553d3f477SJiayu Hu  *  the identifier of DMA device
17653d3f477SJiayu Hu  * @param vchan_id
17753d3f477SJiayu Hu  *  the identifier of virtual DMA channel
178b737fd61SCheng Jiang  * @return
179b737fd61SCheng Jiang  *  Number of packets returned
180b737fd61SCheng Jiang  */
181b737fd61SCheng Jiang __rte_experimental
182b737fd61SCheng Jiang uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
18353d3f477SJiayu Hu 		struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
18453d3f477SJiayu Hu 		uint16_t vchan_id);
18553d3f477SJiayu Hu 
18653d3f477SJiayu Hu /**
1873753ebf0SYuan Wang  * This function checks async completion status and clear packets for
1883753ebf0SYuan Wang  * a specific vhost device queue. Packets which are inflight will be
1893753ebf0SYuan Wang  * returned in an array.
1903753ebf0SYuan Wang  *
1913753ebf0SYuan Wang  * @param vid
1923753ebf0SYuan Wang  *  ID of vhost device to clear data
1933753ebf0SYuan Wang  * @param queue_id
1943753ebf0SYuan Wang  *  Queue id to clear data
1953753ebf0SYuan Wang  * @param pkts
1963753ebf0SYuan Wang  *  Blank array to get return packet pointer
1973753ebf0SYuan Wang  * @param count
1983753ebf0SYuan Wang  *  Size of the packet array
1993753ebf0SYuan Wang  * @param dma_id
2003753ebf0SYuan Wang  *  The identifier of the DMA device
2013753ebf0SYuan Wang  * @param vchan_id
2023753ebf0SYuan Wang  *  The identifier of virtual DMA channel
2033753ebf0SYuan Wang  * @return
2043753ebf0SYuan Wang  *  Number of packets returned
2053753ebf0SYuan Wang  */
2063753ebf0SYuan Wang __rte_experimental
2073753ebf0SYuan Wang uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
2083753ebf0SYuan Wang 		struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
2093753ebf0SYuan Wang 		uint16_t vchan_id);
2103753ebf0SYuan Wang 
2113753ebf0SYuan Wang /**
21253d3f477SJiayu Hu  * The DMA vChannels used in asynchronous data path must be configured
21353d3f477SJiayu Hu  * first. So this function needs to be called before enabling DMA
21453d3f477SJiayu Hu  * acceleration for vring. If this function fails, the given DMA vChannel
21553d3f477SJiayu Hu  * cannot be used in asynchronous data path.
21653d3f477SJiayu Hu  *
21753d3f477SJiayu Hu  * DMA devices used in data-path must belong to DMA devices given in this
21853d3f477SJiayu Hu  * function. Application is free to use DMA devices passed to this function
21953d3f477SJiayu Hu  * for non-vhost scenarios, but will have to ensure the Vhost library is not
22053d3f477SJiayu Hu  * using the channel at the same time.
22153d3f477SJiayu Hu  *
22253d3f477SJiayu Hu  * @param dma_id
22353d3f477SJiayu Hu  *  the identifier of DMA device
22453d3f477SJiayu Hu  * @param vchan_id
22553d3f477SJiayu Hu  *  the identifier of virtual DMA channel
22653d3f477SJiayu Hu  * @return
22753d3f477SJiayu Hu  *  0 on success, and -1 on failure
22853d3f477SJiayu Hu  */
22953d3f477SJiayu Hu __rte_experimental
23053d3f477SJiayu Hu int rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id);
231b737fd61SCheng Jiang 
23284d52043SXuan Ding /**
23384d52043SXuan Ding  * @warning
23484d52043SXuan Ding  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
23584d52043SXuan Ding  *
23684d52043SXuan Ding  * This function tries to receive packets from the guest with offloading
23784d52043SXuan Ding  * copies to the DMA vChannels. Successfully dequeued packets are returned
23884d52043SXuan Ding  * in "pkts". The other packets that their copies are submitted to
23984d52043SXuan Ding  * the DMA vChannels but not completed are called "in-flight packets".
24084d52043SXuan Ding  * This function will not return in-flight packets until their copies are
24184d52043SXuan Ding  * completed by the DMA vChannels.
24284d52043SXuan Ding  *
24384d52043SXuan Ding  * @param vid
24484d52043SXuan Ding  *  ID of vhost device to dequeue data
24584d52043SXuan Ding  * @param queue_id
24684d52043SXuan Ding  *  ID of virtqueue to dequeue data
24784d52043SXuan Ding  * @param mbuf_pool
24884d52043SXuan Ding  *  Mbuf_pool where host mbuf is allocated
24984d52043SXuan Ding  * @param pkts
25084d52043SXuan Ding  *  Blank array to keep successfully dequeued packets
25184d52043SXuan Ding  * @param count
25284d52043SXuan Ding  *  Size of the packet array
25384d52043SXuan Ding  * @param nr_inflight
25484d52043SXuan Ding  *  >= 0: The amount of in-flight packets
25584d52043SXuan Ding  *  -1: Meaningless, indicates failed lock acquisition or invalid queue_id/dma_id
25684d52043SXuan Ding  * @param dma_id
25784d52043SXuan Ding  *  The identifier of DMA device
25884d52043SXuan Ding  * @param vchan_id
25984d52043SXuan Ding  *  The identifier of virtual DMA channel
26084d52043SXuan Ding  * @return
26184d52043SXuan Ding  *  Number of successfully dequeued packets
26284d52043SXuan Ding  */
26384d52043SXuan Ding __rte_experimental
26484d52043SXuan Ding uint16_t
26584d52043SXuan Ding rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id,
26684d52043SXuan Ding 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count,
26784d52043SXuan Ding 	int *nr_inflight, int16_t dma_id, uint16_t vchan_id);
26884d52043SXuan Ding 
269e8c3d496SXuan Ding /**
270e8c3d496SXuan Ding  * @warning
271e8c3d496SXuan Ding  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice.
272e8c3d496SXuan Ding  *
273e8c3d496SXuan Ding  * Unconfigure DMA vChannel in Vhost asynchronous data path.
274e8c3d496SXuan Ding  * This function should be called when the specified DMA vChannel is no longer
275e8c3d496SXuan Ding  * used by the Vhost library. Before this function is called, make sure there
276e8c3d496SXuan Ding  * does not exist in-flight packets in DMA vChannel.
277e8c3d496SXuan Ding  *
278e8c3d496SXuan Ding  * @param dma_id
279e8c3d496SXuan Ding  *  the identifier of DMA device
280e8c3d496SXuan Ding  * @param vchan_id
281e8c3d496SXuan Ding  *  the identifier of virtual DMA channel
282e8c3d496SXuan Ding  * @return
283e8c3d496SXuan Ding  *  0 on success, and -1 on failure
284e8c3d496SXuan Ding  */
285e8c3d496SXuan Ding __rte_experimental
286e8c3d496SXuan Ding int
287e8c3d496SXuan Ding rte_vhost_async_dma_unconfigure(int16_t dma_id, uint16_t vchan_id);
288e8c3d496SXuan Ding 
289cedca408SBrian Dooley #ifdef __cplusplus
290cedca408SBrian Dooley }
291cedca408SBrian Dooley #endif
292cedca408SBrian Dooley 
29399a2dd95SBruce Richardson #endif /* _RTE_VHOST_ASYNC_H_ */
294