Note AES PMDs enablement in changelog
[deb_dpdk.git] / lib / librte_eventdev / rte_event_eth_rx_adapter.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation.
3  * All rights reserved.
4  */
5
6 #ifndef _RTE_EVENT_ETH_RX_ADAPTER_
7 #define _RTE_EVENT_ETH_RX_ADAPTER_
8
9 /**
10  * @file
11  *
12  * RTE Event Ethernet Rx Adapter
13  *
14  * An eventdev-based packet processing application enqueues/dequeues mbufs
15  * to/from the event device. Packet flow from the ethernet device to the event
16  * device can be accomplished using either HW or SW mechanisms depending on the
17  * platform and the particular combination of ethernet and event devices. The
18  * event ethernet Rx adapter provides common APIs to configure the packet flow
19  * from the ethernet devices to event devices across both these transfer
20  * mechanisms.
21  *
22  * The adapter uses a EAL service core function for SW based packet transfer
23  * and uses the eventdev PMD functions to configure HW based packet transfer
24  * between the ethernet device and the event device. For SW based packet
25  * transfer, if the mbuf does not have a timestamp set, the adapter adds a
26  * timestamp to the mbuf using rte_get_tsc_cycles(), this provides a more
27  * accurate timestamp as compared to if the application were to set the time
28  * stamp since it avoids event device schedule latency.
29  *
30  * The ethernet Rx event adapter's functions are:
31  *  - rte_event_eth_rx_adapter_create_ext()
32  *  - rte_event_eth_rx_adapter_create()
33  *  - rte_event_eth_rx_adapter_free()
34  *  - rte_event_eth_rx_adapter_queue_add()
35  *  - rte_event_eth_rx_adapter_queue_del()
36  *  - rte_event_eth_rx_adapter_start()
37  *  - rte_event_eth_rx_adapter_stop()
38  *  - rte_event_eth_rx_adapter_stats_get()
39  *  - rte_event_eth_rx_adapter_stats_reset()
40  *
41  * The application creates an ethernet to event adapter using
42  * rte_event_eth_rx_adapter_create_ext() or rte_event_eth_rx_adapter_create()
43  * functions.
44  * The adapter needs to know which ethernet rx queues to poll for mbufs as well
45  * as event device parameters such as the event queue identifier, event
46  * priority and scheduling type that the adapter should use when constructing
47  * events. The rte_event_eth_rx_adapter_queue_add() function is provided for
48  * this purpose.
49  * The servicing weight parameter in the rte_event_eth_rx_adapter_queue_conf
50  * is applicable when the Rx adapter uses a service core function and is
51  * intended to provide application control of the frequency of polling ethernet
52  * device receive queues, for example, the application may want to poll higher
53  * priority queues with a higher frequency but at the same time not starve
54  * lower priority queues completely. If this parameter is zero and the receive
55  * interrupt is enabled when configuring the device, the receive queue is
56  * interrupt driven; else, the queue is assigned a servicing weight of one.
57  *
58  * The application can start/stop the adapter using the
59  * rte_event_eth_rx_adapter_start() and the rte_event_eth_rx_adapter_stop()
60  * functions. If the adapter uses a rte_service function, then the application
61  * is also required to assign a core to the service function and control the
62  * service core using the rte_service APIs. The
63  * rte_event_eth_rx_adapter_service_id_get() function can be used to retrieve
64  * the service function ID of the adapter in this case.
65  *
66  * Note:
67  * 1) Interrupt driven receive queues are currently unimplemented.
68  * 2) Devices created after an instance of rte_event_eth_rx_adapter_create
69  *  should be added to a new instance of the rx adapter.
70  */
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 #include <stdint.h>
77
78 #include <rte_service.h>
79
80 #include "rte_eventdev.h"
81
82 #define RTE_EVENT_ETH_RX_ADAPTER_MAX_INSTANCE 32
83
84 /* struct rte_event_eth_rx_adapter_queue_conf flags definitions */
85 #define RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID    0x1
86 /**< This flag indicates the flow identifier is valid
87  * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
88  */
89
90 /**
91  * @warning
92  * @b EXPERIMENTAL: this API may change without prior notice
93  *
94  * Adapter configuration structure that the adapter configuration callback
95  * function is expected to fill out
96  * @see rte_event_eth_rx_adapter_conf_cb
97  */
98 struct rte_event_eth_rx_adapter_conf {
99         uint8_t event_port_id;
100         /**< Event port identifier, the adapter enqueues mbuf events to this
101          * port.
102          */
103         uint32_t max_nb_rx;
104         /**< The adapter can return early if it has processed at least
105          * max_nb_rx mbufs. This isn't treated as a requirement; batching may
106          * cause the adapter to process more than max_nb_rx mbufs.
107          */
108 };
109
110 /**
111  * @warning
112  * @b EXPERIMENTAL: this API may change without prior notice
113  *
114  * Function type used for adapter configuration callback. The callback is
115  * used to fill in members of the struct rte_event_eth_rx_adapter_conf, this
116  * callback is invoked when creating a SW service for packet transfer from
117  * ethdev queues to the event device. The SW service is created within the
118  * rte_event_eth_rx_adapter_queue_add() function if SW based packet transfers
119  * from ethdev queues to the event device are required.
120  *
121  * @param id
122  *  Adapter identifier.
123  *
124  * @param dev_id
125  *  Event device identifier.
126  *
127  * @param [out] conf
128  *  Structure that needs to be populated by this callback.
129  *
130  * @param arg
131  *  Argument to the callback. This is the same as the conf_arg passed to the
132  *  rte_event_eth_rx_adapter_create_ext().
133  */
134 typedef int (*rte_event_eth_rx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
135                         struct rte_event_eth_rx_adapter_conf *conf,
136                         void *arg);
137
138 /**
139  * @warning
140  * @b EXPERIMENTAL: this API may change without prior notice
141  *
142  * Rx queue configuration structure
143  */
144 struct rte_event_eth_rx_adapter_queue_conf {
145         uint32_t rx_queue_flags;
146          /**< Flags for handling received packets
147           * @see RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID
148           */
149         uint16_t servicing_weight;
150         /**< Relative polling frequency of ethernet receive queue when the
151          * adapter uses a service core function for ethernet to event device
152          * transfers. If it is set to zero, the Rx queue is interrupt driven
153          * (unless rx queue interrupts are not enabled for the ethernet
154          * device).
155          */
156         struct rte_event ev;
157         /**<
158          *  The values from the following event fields will be used when
159          *  queuing mbuf events:
160          *   - event_queue_id: Targeted event queue ID for received packets.
161          *   - event_priority: Event priority of packets from this Rx queue in
162          *                     the event queue relative to other events.
163          *   - sched_type: Scheduling type for packets from this Rx queue.
164          *   - flow_id: If the RTE_ETH_RX_EVENT_ADAPTER_QUEUE_FLOW_ID_VALID bit
165          *              is set in rx_queue_flags, this flow_id is used for all
166          *              packets received from this queue. Otherwise the flow ID
167          *              is set to the RSS hash of the src and dst IPv4/6
168          *              addresses.
169          *
170          * The event adapter sets ev.event_type to RTE_EVENT_TYPE_ETHDEV in the
171          * enqueued event.
172          */
173 };
174
175 /**
176  * @warning
177  * @b EXPERIMENTAL: this API may change without prior notice
178  *
179  * A structure used to retrieve statistics for an eth rx adapter instance.
180  */
181 struct rte_event_eth_rx_adapter_stats {
182         uint64_t rx_poll_count;
183         /**< Receive queue poll count */
184         uint64_t rx_packets;
185         /**< Received packet count */
186         uint64_t rx_enq_count;
187         /**< Eventdev enqueue count */
188         uint64_t rx_enq_retry;
189         /**< Eventdev enqueue retry count */
190         uint64_t rx_enq_start_ts;
191         /**< Rx enqueue start timestamp */
192         uint64_t rx_enq_block_cycles;
193         /**< Cycles for which the service is blocked by the event device,
194          * i.e, the service fails to enqueue to the event device.
195          */
196         uint64_t rx_enq_end_ts;
197         /**< Latest timestamp at which the service is unblocked
198          * by the event device. The start, end timestamps and
199          * block cycles can be used to compute the percentage of
200          * cycles the service is blocked by the event device.
201          */
202 };
203
204 /**
205  * @warning
206  * @b EXPERIMENTAL: this API may change without prior notice
207  *
208  * Create a new ethernet Rx event adapter with the specified identifier.
209  *
210  * @param id
211  *  The identifier of the ethernet Rx event adapter.
212  *
213  * @param dev_id
214  *  The identifier of the device to configure.
215  *
216  * @param conf_cb
217  *  Callback function that fills in members of a
218  *  struct rte_event_eth_rx_adapter_conf struct passed into
219  *  it.
220  *
221  * @param conf_arg
222  *  Argument that is passed to the conf_cb function.
223  *
224  * @return
225  *   - 0: Success
226  *   - <0: Error code on failure
227  */
228 int rte_event_eth_rx_adapter_create_ext(uint8_t id, uint8_t dev_id,
229                                 rte_event_eth_rx_adapter_conf_cb conf_cb,
230                                 void *conf_arg);
231
232 /**
233  * @warning
234  * @b EXPERIMENTAL: this API may change without prior notice
235  *
236  * Create a new ethernet Rx event adapter with the specified identifier.
237  * This function uses an internal configuration function that creates an event
238  * port. This default function reconfigures the event device with an
239  * additional event port and setups up the event port using the port_config
240  * parameter passed into this function. In case the application needs more
241  * control in configuration of the service, it should use the
242  * rte_event_eth_rx_adapter_create_ext() version.
243  *
244  * @param id
245  *  The identifier of the ethernet Rx event adapter.
246  *
247  * @param dev_id
248  *  The identifier of the device to configure.
249  *
250  * @param port_config
251  *  Argument of type *rte_event_port_conf* that is passed to the conf_cb
252  *  function.
253  *
254  * @return
255  *   - 0: Success
256  *   - <0: Error code on failure
257  */
258 int rte_event_eth_rx_adapter_create(uint8_t id, uint8_t dev_id,
259                                 struct rte_event_port_conf *port_config);
260
261 /**
262  * @warning
263  * @b EXPERIMENTAL: this API may change without prior notice
264  *
265  * Free an event adapter
266  *
267  * @param id
268  *  Adapter identifier.
269  *
270  * @return
271  *   - 0: Success
272  *   - <0: Error code on failure, If the adapter still has Rx queues
273  *      added to it, the function returns -EBUSY.
274  */
275 int rte_event_eth_rx_adapter_free(uint8_t id);
276
277 /**
278  * @warning
279  * @b EXPERIMENTAL: this API may change without prior notice
280  *
281  * Add receive queue to an event adapter. After a queue has been
282  * added to the event adapter, the result of the application calling
283  * rte_eth_rx_burst(eth_dev_id, rx_queue_id, ..) is undefined.
284  *
285  * @param id
286  *  Adapter identifier.
287  *
288  * @param eth_dev_id
289  *  Port identifier of Ethernet device.
290  *
291  * @param rx_queue_id
292  *  Ethernet device receive queue index.
293  *  If rx_queue_id is -1, then all Rx queues configured for
294  *  the device are added. If the ethdev Rx queues can only be
295  *  connected to a single event queue then rx_queue_id is
296  *  required to be -1.
297  * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
298  *
299  * @param conf
300  *  Additional configuration structure of type *rte_event_eth_rx_adapter_conf*
301  *
302  * @return
303  *  - 0: Success, Receive queue added correctly.
304  *  - <0: Error code on failure.
305  *  - (-EIO) device reconfiguration and restart error. The adapter reconfigures
306  *  the event device with an additional port if it is required to use a service
307  *  function for packet transfer from the ethernet device to the event device.
308  *  If the device had been started before this call, this error code indicates
309  *  an error in restart following an error in reconfiguration, i.e., a
310  *  combination of the two error codes.
311  */
312 int rte_event_eth_rx_adapter_queue_add(uint8_t id,
313                         uint16_t eth_dev_id,
314                         int32_t rx_queue_id,
315                         const struct rte_event_eth_rx_adapter_queue_conf *conf);
316
317 /**
318  * @warning
319  * @b EXPERIMENTAL: this API may change without prior notice
320  *
321  * Delete receive queue from an event adapter.
322  *
323  * @param id
324  *  Adapter identifier.
325  *
326  * @param eth_dev_id
327  *  Port identifier of Ethernet device.
328  *
329  * @param rx_queue_id
330  *  Ethernet device receive queue index.
331  *  If rx_queue_id is -1, then all Rx queues configured for
332  *  the device are deleted. If the ethdev Rx queues can only be
333  *  connected to a single event queue then rx_queue_id is
334  *  required to be -1.
335  * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
336  *
337  * @return
338  *  - 0: Success, Receive queue deleted correctly.
339  *  - <0: Error code on failure.
340  */
341 int rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id,
342                                        int32_t rx_queue_id);
343
344 /**
345  * @warning
346  * @b EXPERIMENTAL: this API may change without prior notice
347  *
348  * Start ethernet Rx event adapter
349  *
350  * @param id
351  *  Adapter identifier.
352  *
353  * @return
354  *  - 0: Success, Adapter started correctly.
355  *  - <0: Error code on failure.
356  */
357 int rte_event_eth_rx_adapter_start(uint8_t id);
358
359 /**
360  * @warning
361  * @b EXPERIMENTAL: this API may change without prior notice
362  *
363  * Stop  ethernet Rx event adapter
364  *
365  * @param id
366  *  Adapter identifier.
367  *
368  * @return
369  *  - 0: Success, Adapter started correctly.
370  *  - <0: Error code on failure.
371  */
372 int rte_event_eth_rx_adapter_stop(uint8_t id);
373
374 /**
375  * @warning
376  * @b EXPERIMENTAL: this API may change without prior notice
377  *
378  * Retrieve statistics for an adapter
379  *
380  * @param id
381  *  Adapter identifier.
382  *
383  * @param [out] stats
384  *  A pointer to structure used to retrieve statistics for an adapter.
385  *
386  * @return
387  *  - 0: Success, retrieved successfully.
388  *  - <0: Error code on failure.
389  */
390 int rte_event_eth_rx_adapter_stats_get(uint8_t id,
391                                 struct rte_event_eth_rx_adapter_stats *stats);
392
393 /**
394  * @warning
395  * @b EXPERIMENTAL: this API may change without prior notice
396  *
397  * Reset statistics for an adapter.
398  *
399  * @param id
400  *  Adapter identifier.
401  *
402  * @return
403  *  - 0: Success, statistics reset successfully.
404  *  - <0: Error code on failure.
405  */
406 int rte_event_eth_rx_adapter_stats_reset(uint8_t id);
407
408 /**
409  * @warning
410  * @b EXPERIMENTAL: this API may change without prior notice
411  *
412  * Retrieve the service ID of an adapter. If the adapter doesn't use
413  * a rte_service function, this function returns -ESRCH.
414  *
415  * @param id
416  *  Adapter identifier.
417  *
418  * @param [out] service_id
419  *  A pointer to a uint32_t, to be filled in with the service id.
420  *
421  * @return
422  *  - 0: Success
423  *  - <0: Error code on failure, if the adapter doesn't use a rte_service
424  * function, this function returns -ESRCH.
425  */
426 int rte_event_eth_rx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
427
428 #ifdef __cplusplus
429 }
430 #endif
431 #endif  /* _RTE_EVENT_ETH_RX_ADAPTER_ */