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