70ca427d6601a27ec66be4a8cf45946307812bda
[dpdk.git] / lib / 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.
25  *
26  * The ethernet Rx event adapter's functions are:
27  *  - rte_event_eth_rx_adapter_create_ext()
28  *  - rte_event_eth_rx_adapter_create()
29  *  - rte_event_eth_rx_adapter_create_with_params()
30  *  - rte_event_eth_rx_adapter_free()
31  *  - rte_event_eth_rx_adapter_queue_add()
32  *  - rte_event_eth_rx_adapter_queue_del()
33  *  - rte_event_eth_rx_adapter_start()
34  *  - rte_event_eth_rx_adapter_stop()
35  *  - rte_event_eth_rx_adapter_stats_get()
36  *  - rte_event_eth_rx_adapter_stats_reset()
37  *  - rte_event_eth_rx_adapter_queue_conf_get()
38  *
39  * The application creates an ethernet to event adapter using
40  * rte_event_eth_rx_adapter_create_ext() or rte_event_eth_rx_adapter_create()
41  * or rte_event_eth_rx_adapter_create_with_params() functions.
42  * The adapter needs to know which ethernet rx queues to poll for mbufs as well
43  * as event device parameters such as the event queue identifier, event
44  * priority and scheduling type that the adapter should use when constructing
45  * events. The rte_event_eth_rx_adapter_queue_add() function is provided for
46  * this purpose.
47  * The servicing weight parameter in the rte_event_eth_rx_adapter_queue_conf
48  * is applicable when the Rx adapter uses a service core function and is
49  * intended to provide application control of the frequency of polling ethernet
50  * device receive queues, for example, the application may want to poll higher
51  * priority queues with a higher frequency but at the same time not starve
52  * lower priority queues completely. If this parameter is zero and the receive
53  * interrupt is enabled when configuring the device, the receive queue is
54  * interrupt driven; else, the queue is assigned a servicing weight of one.
55  *
56  * The application can start/stop the adapter using the
57  * rte_event_eth_rx_adapter_start() and the rte_event_eth_rx_adapter_stop()
58  * functions. If the adapter uses a rte_service function, then the application
59  * is also required to assign a core to the service function and control the
60  * service core using the rte_service APIs. The
61  * rte_event_eth_rx_adapter_service_id_get() function can be used to retrieve
62  * the service function ID of the adapter in this case.
63  *
64  * For SW based packet transfers, i.e., when the
65  * RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT is not set in the adapter's
66  * capabilities flags for a particular ethernet device, the service function
67  * temporarily enqueues events to an event buffer before batch enqueuing these
68  * to the event device. If the buffer fills up, the service function stops
69  * dequeuing packets from the ethernet device. The application may want to
70  * monitor the buffer fill level and instruct the service function to
71  * selectively buffer events. The application may also use some other
72  * criteria to decide which packets should enter the event device even when
73  * the event buffer fill level is low or may want to enqueue packets to an
74  * internal event port. The rte_event_eth_rx_adapter_cb_register() function
75  * allows the application to register a callback that selects which packets are
76  * enqueued to the event device by the SW adapter. The callback interface is
77  * event based so the callback can also modify the event data if it needs to.
78  */
79
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83
84 #include <stdint.h>
85
86 #include <rte_service.h>
87
88 #include "rte_eventdev.h"
89
90 #define RTE_EVENT_ETH_RX_ADAPTER_MAX_INSTANCE 32
91
92 /* struct rte_event_eth_rx_adapter_queue_conf flags definitions */
93 #define RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID    0x1
94 /**< This flag indicates the flow identifier is valid
95  * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
96  */
97 #define RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR     0x2
98 /**< This flag indicates that mbufs arriving on the queue need to be vectorized
99  * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
100  */
101
102 /**
103  * Adapter configuration structure that the adapter configuration callback
104  * function is expected to fill out
105  * @see rte_event_eth_rx_adapter_conf_cb
106  */
107 struct rte_event_eth_rx_adapter_conf {
108         uint8_t event_port_id;
109         /**< Event port identifier, the adapter enqueues mbuf events to this
110          * port.
111          */
112         uint32_t max_nb_rx;
113         /**< The adapter can return early if it has processed at least
114          * max_nb_rx mbufs. This isn't treated as a requirement; batching may
115          * cause the adapter to process more than max_nb_rx mbufs.
116          */
117 };
118
119 /**
120  * Function type used for adapter configuration callback. The callback is
121  * used to fill in members of the struct rte_event_eth_rx_adapter_conf, this
122  * callback is invoked when creating a SW service for packet transfer from
123  * ethdev queues to the event device. The SW service is created within the
124  * rte_event_eth_rx_adapter_queue_add() function if SW based packet transfers
125  * from ethdev queues to the event device are required.
126  *
127  * @param id
128  *  Adapter identifier.
129  *
130  * @param dev_id
131  *  Event device identifier.
132  *
133  * @param [out] conf
134  *  Structure that needs to be populated by this callback.
135  *
136  * @param arg
137  *  Argument to the callback. This is the same as the conf_arg passed to the
138  *  rte_event_eth_rx_adapter_create_ext().
139  */
140 typedef int (*rte_event_eth_rx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
141                         struct rte_event_eth_rx_adapter_conf *conf,
142                         void *arg);
143
144 /**
145  * Rx queue configuration structure
146  */
147 struct rte_event_eth_rx_adapter_queue_conf {
148         uint32_t rx_queue_flags;
149          /**< Flags for handling received packets
150           * @see RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID
151           */
152         uint16_t servicing_weight;
153         /**< Relative polling frequency of ethernet receive queue when the
154          * adapter uses a service core function for ethernet to event device
155          * transfers. If it is set to zero, the Rx queue is interrupt driven
156          * (unless rx queue interrupts are not enabled for the ethernet
157          * device).
158          */
159         struct rte_event ev;
160         /**<
161          *  The values from the following event fields will be used when
162          *  queuing mbuf events:
163          *   - event_queue_id: Targeted event queue ID for received packets.
164          *   - event_priority: Event priority of packets from this Rx queue in
165          *                     the event queue relative to other events.
166          *   - sched_type: Scheduling type for packets from this Rx queue.
167          *   - flow_id: If the RTE_ETH_RX_EVENT_ADAPTER_QUEUE_FLOW_ID_VALID bit
168          *              is set in rx_queue_flags, this flow_id is used for all
169          *              packets received from this queue. Otherwise the flow ID
170          *              is set to the RSS hash of the src and dst IPv4/6
171          *              addresses.
172          *
173          * The event adapter sets ev.event_type to RTE_EVENT_TYPE_ETHDEV in the
174          * enqueued event.
175          */
176         uint16_t vector_sz;
177         /**<
178          * Indicates the maximum number for mbufs to combine and form a vector.
179          * Should be within
180          * @see rte_event_eth_rx_adapter_vector_limits::min_vector_sz
181          * @see rte_event_eth_rx_adapter_vector_limits::max_vector_sz
182          * Valid when RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR flag is set in
183          * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
184          */
185         uint64_t vector_timeout_ns;
186         /**<
187          * Indicates the maximum number of nanoseconds to wait for receiving
188          * mbufs. Should be within vectorization limits of the
189          * adapter
190          * @see rte_event_eth_rx_adapter_vector_limits::min_vector_ns
191          * @see rte_event_eth_rx_adapter_vector_limits::max_vector_ns
192          * Valid when RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR flag is set in
193          * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags
194          */
195         struct rte_mempool *vector_mp;
196         /**<
197          * Indicates the mempool that should be used for allocating
198          * rte_event_vector container.
199          * Should be created by using `rte_event_vector_pool_create`.
200          * Valid when RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR flag is set in
201          * @see rte_event_eth_rx_adapter_queue_conf::rx_queue_flags.
202          */
203         uint16_t event_buf_size;
204         /**< event buffer size for this queue */
205 };
206
207 /**
208  * A structure used to retrieve statistics for an eth rx adapter instance.
209  */
210 struct rte_event_eth_rx_adapter_stats {
211         uint64_t rx_poll_count;
212         /**< Receive queue poll count */
213         uint64_t rx_packets;
214         /**< Received packet count */
215         uint64_t rx_enq_count;
216         /**< Eventdev enqueue count */
217         uint64_t rx_enq_retry;
218         /**< Eventdev enqueue retry count */
219         uint64_t rx_dropped;
220         /**< Received packet dropped count */
221         uint64_t rx_enq_start_ts;
222         /**< Rx enqueue start timestamp */
223         uint64_t rx_enq_block_cycles;
224         /**< Cycles for which the service is blocked by the event device,
225          * i.e, the service fails to enqueue to the event device.
226          */
227         uint64_t rx_enq_end_ts;
228         /**< Latest timestamp at which the service is unblocked
229          * by the event device. The start, end timestamps and
230          * block cycles can be used to compute the percentage of
231          * cycles the service is blocked by the event device.
232          */
233         uint64_t rx_intr_packets;
234         /**< Received packet count for interrupt mode Rx queues */
235 };
236
237 /**
238  * A structure used to retrieve eth rx adapter vector limits.
239  */
240 struct rte_event_eth_rx_adapter_vector_limits {
241         uint16_t min_sz;
242         /**< Minimum vector limit configurable.
243          * @see rte_event_eth_rx_adapter_event_vector_config::vector_sz
244          */
245         uint16_t max_sz;
246         /**< Maximum vector limit configurable.
247          * @see rte_event_eth_rx_adapter_event_vector_config::vector_sz
248          */
249         uint8_t log2_sz;
250         /**< True if the size configured should be in log2.
251          * @see rte_event_eth_rx_adapter_event_vector_config::vector_sz
252          */
253         uint64_t min_timeout_ns;
254         /**< Minimum vector timeout configurable.
255          * @see rte_event_eth_rx_adapter_event_vector_config::vector_timeout_ns
256          */
257         uint64_t max_timeout_ns;
258         /**< Maximum vector timeout configurable.
259          * @see rte_event_eth_rx_adapter_event_vector_config::vector_timeout_ns
260          */
261 };
262
263 /**
264  * A structure to hold adapter config params
265  */
266 struct rte_event_eth_rx_adapter_params {
267         uint16_t event_buf_size;
268         /**< size of event buffer for the adapter.
269          * This value is rounded up for better buffer utilization
270          * and performance.
271          */
272         bool use_queue_event_buf;
273         /**< flag to indicate that event buffer is separate for each queue */
274 };
275
276 /**
277  *
278  * Callback function invoked by the SW adapter before it continues
279  * to process events. The callback is passed the size of the enqueue
280  * buffer in the SW adapter and the occupancy of the buffer. The
281  * callback can use these values to decide which events are
282  * enqueued to the event device by the SW adapter. The callback may
283  * also enqueue events internally using its own event port. The SW
284  * adapter populates the event information based on the Rx queue
285  * configuration in the adapter. The callback can modify the this event
286  * information for the events to be enqueued by the SW adapter.
287  *
288  * The callback return value is the number of events from the
289  * beginning of the event array that are to be enqueued by
290  * the SW adapter. It is the callback's responsibility to arrange
291  * these events at the beginning of the array, if these events are
292  * not contiguous in the original array. The *nb_dropped* parameter is
293  * a pointer to the number of events dropped by the callback, this
294  * number is used by the adapter to indicate the number of dropped packets
295  * as part of its statistics.
296  *
297  * @param eth_dev_id
298  *  Port identifier of the Ethernet device.
299  * @param queue_id
300  *  Receive queue index.
301  * @param enqueue_buf_size
302  *  Total enqueue buffer size.
303  * @param enqueue_buf_count
304  *  Event count in enqueue buffer.
305  * @param[in, out] ev
306  *  Event array.
307  * @param nb_event
308  *  Event array length.
309  * @param cb_arg
310  *  Callback argument.
311  * @param[out] nb_dropped
312  *  Packets dropped by callback.
313  * @return
314  *  - The number of events to be enqueued by the SW adapter.
315  */
316 typedef uint16_t (*rte_event_eth_rx_adapter_cb_fn)(uint16_t eth_dev_id,
317                                                 uint16_t queue_id,
318                                                 uint32_t enqueue_buf_size,
319                                                 uint32_t enqueue_buf_count,
320                                                 struct rte_event *ev,
321                                                 uint16_t nb_event,
322                                                 void *cb_arg,
323                                                 uint16_t *nb_dropped);
324
325 /**
326  * Create a new ethernet Rx event adapter with the specified identifier.
327  *
328  * @param id
329  *  The identifier of the ethernet Rx event adapter.
330  *
331  * @param dev_id
332  *  The identifier of the device to configure.
333  *
334  * @param conf_cb
335  *  Callback function that fills in members of a
336  *  struct rte_event_eth_rx_adapter_conf struct passed into
337  *  it.
338  *
339  * @param conf_arg
340  *  Argument that is passed to the conf_cb function.
341  *
342  * @return
343  *   - 0: Success
344  *   - <0: Error code on failure
345  */
346 int rte_event_eth_rx_adapter_create_ext(uint8_t id, uint8_t dev_id,
347                                 rte_event_eth_rx_adapter_conf_cb conf_cb,
348                                 void *conf_arg);
349
350 /**
351  * Create a new ethernet Rx event adapter with the specified identifier.
352  * This function uses an internal configuration function that creates an event
353  * port. This default function reconfigures the event device with an
354  * additional event port and setups up the event port using the port_config
355  * parameter passed into this function. In case the application needs more
356  * control in configuration of the service, it should use the
357  * rte_event_eth_rx_adapter_create_ext() version.
358  *
359  * @param id
360  *  The identifier of the ethernet Rx event adapter.
361  *
362  * @param dev_id
363  *  The identifier of the device to configure.
364  *
365  * @param port_config
366  *  Argument of type *rte_event_port_conf* that is passed to the conf_cb
367  *  function.
368  *
369  * @return
370  *   - 0: Success
371  *   - <0: Error code on failure
372  */
373 int rte_event_eth_rx_adapter_create(uint8_t id, uint8_t dev_id,
374                                 struct rte_event_port_conf *port_config);
375
376 /**
377  * This is a variant of rte_event_eth_rx_adapter_create() with additional
378  * adapter params specified in ``struct rte_event_eth_rx_adapter_params``.
379  *
380  * @param id
381  *  The identifier of the ethernet Rx event adapter.
382  *
383  * @param dev_id
384  *  The identifier of the event device to configure.
385  *
386  * @param port_config
387  *  Argument of type *rte_event_port_conf* that is passed to the conf_cb
388  *  function.
389  *
390  * @param rxa_params
391  *  Pointer to struct rte_event_eth_rx_adapter_params.
392  *  In case of NULL, default values are used.
393  *
394  * @return
395  *   - 0: Success
396  *   - <0: Error code on failure
397  */
398 __rte_experimental
399 int rte_event_eth_rx_adapter_create_with_params(uint8_t id, uint8_t dev_id,
400                         struct rte_event_port_conf *port_config,
401                         struct rte_event_eth_rx_adapter_params *rxa_params);
402
403 /**
404  * Free an event adapter
405  *
406  * @param id
407  *  Adapter identifier.
408  *
409  * @return
410  *   - 0: Success
411  *   - <0: Error code on failure, If the adapter still has Rx queues
412  *      added to it, the function returns -EBUSY.
413  */
414 int rte_event_eth_rx_adapter_free(uint8_t id);
415
416 /**
417  * Add receive queue to an event adapter. After a queue has been
418  * added to the event adapter, the result of the application calling
419  * rte_eth_rx_burst(eth_dev_id, rx_queue_id, ..) is undefined.
420  *
421  * @param id
422  *  Adapter identifier.
423  *
424  * @param eth_dev_id
425  *  Port identifier of Ethernet device.
426  *
427  * @param rx_queue_id
428  *  Ethernet device receive queue index.
429  *  If rx_queue_id is -1, then all Rx queues configured for
430  *  the device are added. If the ethdev Rx queues can only be
431  *  connected to a single event queue then rx_queue_id is
432  *  required to be -1.
433  * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
434  *
435  * @param conf
436  *  Additional configuration structure of type *rte_event_eth_rx_adapter_conf*
437  *
438  * @return
439  *  - 0: Success, Receive queue added correctly.
440  *  - <0: Error code on failure.
441  *  - (-EIO) device reconfiguration and restart error. The adapter reconfigures
442  *  the event device with an additional port if it is required to use a service
443  *  function for packet transfer from the ethernet device to the event device.
444  *  If the device had been started before this call, this error code indicates
445  *  an error in restart following an error in reconfiguration, i.e., a
446  *  combination of the two error codes.
447  */
448 int rte_event_eth_rx_adapter_queue_add(uint8_t id,
449                         uint16_t eth_dev_id,
450                         int32_t rx_queue_id,
451                         const struct rte_event_eth_rx_adapter_queue_conf *conf);
452
453 /**
454  * Delete receive queue from an event adapter.
455  *
456  * @param id
457  *  Adapter identifier.
458  *
459  * @param eth_dev_id
460  *  Port identifier of Ethernet device.
461  *
462  * @param rx_queue_id
463  *  Ethernet device receive queue index.
464  *  If rx_queue_id is -1, then all Rx queues configured for
465  *  the device are deleted. If the ethdev Rx queues can only be
466  *  connected to a single event queue then rx_queue_id is
467  *  required to be -1.
468  * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ
469  *
470  * @return
471  *  - 0: Success, Receive queue deleted correctly.
472  *  - <0: Error code on failure.
473  */
474 int rte_event_eth_rx_adapter_queue_del(uint8_t id, uint16_t eth_dev_id,
475                                        int32_t rx_queue_id);
476
477 /**
478  * Start ethernet Rx event adapter
479  *
480  * @param id
481  *  Adapter identifier.
482  *
483  * @return
484  *  - 0: Success, Adapter started correctly.
485  *  - <0: Error code on failure.
486  *
487  * @note
488  *  The eventdev to which the event_eth_rx_adapter is connected needs to
489  *  be started before calling rte_event_eth_rx_adapter_start().
490  */
491 int rte_event_eth_rx_adapter_start(uint8_t id);
492
493 /**
494  * Stop  ethernet Rx event adapter
495  *
496  * @param id
497  *  Adapter identifier.
498  *
499  * @return
500  *  - 0: Success, Adapter started correctly.
501  *  - <0: Error code on failure.
502  */
503 int rte_event_eth_rx_adapter_stop(uint8_t id);
504
505 /**
506  * Retrieve statistics for an adapter
507  *
508  * @param id
509  *  Adapter identifier.
510  *
511  * @param [out] stats
512  *  A pointer to structure used to retrieve statistics for an adapter.
513  *
514  * @return
515  *  - 0: Success, retrieved successfully.
516  *  - <0: Error code on failure.
517  */
518 int rte_event_eth_rx_adapter_stats_get(uint8_t id,
519                                   struct rte_event_eth_rx_adapter_stats *stats);
520
521 /**
522  * Reset statistics for an adapter.
523  *
524  * @param id
525  *  Adapter identifier.
526  *
527  * @return
528  *  - 0: Success, statistics reset successfully.
529  *  - <0: Error code on failure.
530  */
531 int rte_event_eth_rx_adapter_stats_reset(uint8_t id);
532
533 /**
534  * Retrieve the service ID of an adapter. If the adapter doesn't use
535  * a rte_service function, this function returns -ESRCH.
536  *
537  * @param id
538  *  Adapter identifier.
539  *
540  * @param [out] service_id
541  *  A pointer to a uint32_t, to be filled in with the service id.
542  *
543  * @return
544  *  - 0: Success
545  *  - <0: Error code on failure, if the adapter doesn't use a rte_service
546  * function, this function returns -ESRCH.
547  */
548 int rte_event_eth_rx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
549
550 /**
551  * Register callback to process Rx packets, this is supported for
552  * SW based packet transfers.
553  * @see rte_event_eth_rx_cb_fn
554  *
555  * @param id
556  *  Adapter identifier.
557  * @param eth_dev_id
558  *  Port identifier of Ethernet device.
559  * @param cb_fn
560  *  Callback function.
561  * @param cb_arg
562  *  Callback arg.
563  * @return
564  *  - 0: Success
565  *  - <0: Error code on failure.
566  */
567 int rte_event_eth_rx_adapter_cb_register(uint8_t id, uint16_t eth_dev_id,
568                                          rte_event_eth_rx_adapter_cb_fn cb_fn,
569                                          void *cb_arg);
570
571 /**
572  * Retrieve vector limits for a given event dev and eth dev pair.
573  * @see rte_event_eth_rx_adapter_vector_limits
574  *
575  * @param dev_id
576  *  Event device identifier.
577  * @param eth_port_id
578  *  Port identifier of the ethernet device.
579  * @param [out] limits
580  *  A pointer to rte_event_eth_rx_adapter_vector_limits structure that has to
581  * be filled.
582  *
583  * @return
584  *  - 0: Success.
585  *  - <0: Error code on failure.
586  */
587 __rte_experimental
588 int rte_event_eth_rx_adapter_vector_limits_get(
589         uint8_t dev_id, uint16_t eth_port_id,
590         struct rte_event_eth_rx_adapter_vector_limits *limits);
591
592 /**
593  * Retrieve Rx queue config information.
594  *
595  * @param id
596  *  Adapter identifier.
597
598  * @param eth_dev_id
599  *  Port identifier of Ethernet device.
600
601  * @param rx_queue_id
602  *  Ethernet device receive queue index.
603
604  * @param[out] queue_conf
605  *  Pointer to struct rte_event_eth_rx_adapter_queue_conf
606
607  * @return
608  *  - 0: Success, Receive queue added correctly.
609  *  - <0: Error code on failure.
610  */
611 __rte_experimental
612 int rte_event_eth_rx_adapter_queue_conf_get(uint8_t id,
613                         uint16_t eth_dev_id,
614                         uint16_t rx_queue_id,
615                         struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
616
617
618 #ifdef __cplusplus
619 }
620 #endif
621 #endif  /* _RTE_EVENT_ETH_RX_ADAPTER_ */