1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation.
5 #ifndef _RTE_EVENT_ETH_TX_ADAPTER_
6 #define _RTE_EVENT_ETH_TX_ADAPTER_
11 * RTE Event Ethernet Tx Adapter
13 * The event ethernet Tx adapter provides configuration and data path APIs
14 * for the ethernet transmit stage of an event driven packet processing
15 * application. These APIs abstract the implementation of the transmit stage
16 * and allow the application to use eventdev PMD support or a common
19 * In the common implementation, the application enqueues mbufs to the adapter
20 * which runs as a rte_service function. The service function dequeues events
21 * from its event port and transmits the mbufs referenced by these events.
23 * The ethernet Tx event adapter APIs are:
25 * - rte_event_eth_tx_adapter_create()
26 * - rte_event_eth_tx_adapter_create_ext()
27 * - rte_event_eth_tx_adapter_free()
28 * - rte_event_eth_tx_adapter_start()
29 * - rte_event_eth_tx_adapter_stop()
30 * - rte_event_eth_tx_adapter_queue_add()
31 * - rte_event_eth_tx_adapter_queue_del()
32 * - rte_event_eth_tx_adapter_stats_get()
33 * - rte_event_eth_tx_adapter_stats_reset()
34 * - rte_event_eth_tx_adapter_enqueue()
35 * - rte_event_eth_tx_adapter_event_port_get()
36 * - rte_event_eth_tx_adapter_service_id_get()
38 * The application creates the adapter using
39 * rte_event_eth_tx_adapter_create() or rte_event_eth_tx_adapter_create_ext().
41 * The adapter will use the common implementation when the eventdev PMD
42 * does not have the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability.
43 * The common implementation uses an event port that is created using the port
44 * configuration parameter passed to rte_event_eth_tx_adapter_create(). The
45 * application can get the port identifier using
46 * rte_event_eth_tx_adapter_event_port_get() and must link an event queue to
49 * If the eventdev PMD has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT
50 * flags set, Tx adapter events should be enqueued using the
51 * rte_event_eth_tx_adapter_enqueue() function, else the application should
52 * use rte_event_enqueue_burst().
54 * Transmit queues can be added and deleted from the adapter using
55 * rte_event_eth_tx_adapter_queue_add()/del() APIs respectively.
57 * The application can start and stop the adapter using the
58 * rte_event_eth_tx_adapter_start/stop() calls.
60 * The common adapter implementation uses an EAL service function as described
61 * before and its execution is controlled using the rte_service APIs. The
62 * rte_event_eth_tx_adapter_service_id_get()
63 * function can be used to retrieve the adapter's service function ID.
65 * The ethernet port and transmit queue index to transmit the mbuf on are
66 * specified using the mbuf port struct rte_mbuf::hash::txadapter:txq.
67 * The application should use the rte_event_eth_tx_adapter_txq_set()
68 * and rte_event_eth_tx_adapter_txq_get() functions to access the transmit
69 * queue index, using these macros will help with minimizing application
70 * impact due to a change in how the transmit queue index is specified.
81 #include "rte_eventdev.h"
85 * @b EXPERIMENTAL: this API may change without prior notice
87 * Adapter configuration structure
89 * @see rte_event_eth_tx_adapter_create_ext
90 * @see rte_event_eth_tx_adapter_conf_cb
92 struct rte_event_eth_tx_adapter_conf {
93 uint8_t event_port_id;
94 /**< Event port identifier, the adapter service function dequeues mbuf
95 * events from this port.
96 * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT
99 /**< The adapter can return early if it has processed at least
100 * max_nb_tx mbufs. This isn't treated as a requirement; batching may
101 * cause the adapter to process more than max_nb_tx mbufs.
107 * @b EXPERIMENTAL: this API may change without prior notice
109 * Function type used for adapter configuration callback. The callback is
110 * used to fill in members of the struct rte_event_eth_tx_adapter_conf, this
111 * callback is invoked when creating a RTE service function based
112 * adapter implementation.
115 * Adapter identifier.
117 * Event device identifier.
119 * Structure that needs to be populated by this callback.
121 * Argument to the callback. This is the same as the conf_arg passed to the
122 * rte_event_eth_tx_adapter_create_ext().
126 * - <0: Error code on failure
128 typedef int (*rte_event_eth_tx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
129 struct rte_event_eth_tx_adapter_conf *conf,
134 * @b EXPERIMENTAL: this API may change without prior notice
136 * A structure used to retrieve statistics for an ethernet Tx adapter instance.
138 struct rte_event_eth_tx_adapter_stats {
140 /**< Number of transmit retries */
142 /**< Number of packets transmitted */
144 /**< Number of packets dropped */
149 * @b EXPERIMENTAL: this API may change without prior notice
151 * Create a new ethernet Tx adapter with the specified identifier.
154 * The identifier of the ethernet Tx adapter.
156 * The event device identifier.
158 * Event port configuration, the adapter uses this configuration to
159 * create an event port if needed.
162 * - <0: Error code on failure
164 int __rte_experimental
165 rte_event_eth_tx_adapter_create(uint8_t id, uint8_t dev_id,
166 struct rte_event_port_conf *port_config);
170 * @b EXPERIMENTAL: this API may change without prior notice
172 * Create a new ethernet Tx adapter with the specified identifier.
175 * The identifier of the ethernet Tx adapter.
177 * The event device identifier.
179 * Callback function that initializes members of the
180 * struct rte_event_eth_tx_adapter_conf struct passed into
183 * Argument that is passed to the conf_cb function.
186 * - <0: Error code on failure
188 int __rte_experimental
189 rte_event_eth_tx_adapter_create_ext(uint8_t id, uint8_t dev_id,
190 rte_event_eth_tx_adapter_conf_cb conf_cb,
195 * @b EXPERIMENTAL: this API may change without prior notice
197 * Free an ethernet Tx adapter
200 * Adapter identifier.
203 * - <0: Error code on failure, If the adapter still has Tx queues
204 * added to it, the function returns -EBUSY.
206 int __rte_experimental
207 rte_event_eth_tx_adapter_free(uint8_t id);
211 * @b EXPERIMENTAL: this API may change without prior notice
213 * Start ethernet Tx adapter
216 * Adapter identifier.
218 * - 0: Success, Adapter started correctly.
219 * - <0: Error code on failure.
221 int __rte_experimental
222 rte_event_eth_tx_adapter_start(uint8_t id);
226 * @b EXPERIMENTAL: this API may change without prior notice
228 * Stop ethernet Tx adapter
231 * Adapter identifier.
234 * - <0: Error code on failure.
236 int __rte_experimental
237 rte_event_eth_tx_adapter_stop(uint8_t id);
241 * @b EXPERIMENTAL: this API may change without prior notice
243 * Add a Tx queue to the adapter.
244 * A queue value of -1 is used to indicate all
245 * queues within the device.
248 * Adapter identifier.
250 * Ethernet Port Identifier.
254 * - 0: Success, Queues added successfully.
255 * - <0: Error code on failure.
257 int __rte_experimental
258 rte_event_eth_tx_adapter_queue_add(uint8_t id,
264 * @b EXPERIMENTAL: this API may change without prior notice
266 * Delete a Tx queue from the adapter.
267 * A queue value of -1 is used to indicate all
268 * queues within the device, that have been added to this
272 * Adapter identifier.
274 * Ethernet Port Identifier.
278 * - 0: Success, Queues deleted successfully.
279 * - <0: Error code on failure.
281 int __rte_experimental
282 rte_event_eth_tx_adapter_queue_del(uint8_t id,
288 * @b EXPERIMENTAL: this API may change without prior notice
290 * Set Tx queue in the mbuf. This queue is used by the adapter
291 * to transmit the mbuf.
294 * Pointer to the mbuf.
298 static __rte_always_inline void __rte_experimental
299 rte_event_eth_tx_adapter_txq_set(struct rte_mbuf *pkt, uint16_t queue)
301 pkt->hash.txadapter.txq = queue;
306 * @b EXPERIMENTAL: this API may change without prior notice
308 * Retrieve Tx queue from the mbuf.
311 * Pointer to the mbuf.
313 * Tx queue identifier.
315 * @see rte_event_eth_tx_adapter_txq_set()
317 static __rte_always_inline uint16_t __rte_experimental
318 rte_event_eth_tx_adapter_txq_get(struct rte_mbuf *pkt)
320 return pkt->hash.txadapter.txq;
325 * @b EXPERIMENTAL: this API may change without prior notice
327 * Retrieve the adapter event port. The adapter creates an event port if
328 * the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT is not set in the
329 * ethernet Tx capabilities of the event device.
332 * Adapter Identifier.
333 * @param[out] event_port_id
334 * Event port pointer.
337 * - <0: Error code on failure.
339 int __rte_experimental
340 rte_event_eth_tx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id);
343 * Enqueue a burst of events objects or an event object supplied in *rte_event*
344 * structure on an event device designated by its *dev_id* through the event
345 * port specified by *port_id*. This function is supported if the eventdev PMD
346 * has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability flag set.
348 * The *nb_events* parameter is the number of event objects to enqueue which are
349 * supplied in the *ev* array of *rte_event* structure.
351 * The rte_event_eth_tx_adapter_enqueue() function returns the number of
352 * events objects it actually enqueued. A return value equal to *nb_events*
353 * means that all event objects have been enqueued.
356 * The identifier of the device.
358 * The identifier of the event port.
360 * Points to an array of *nb_events* objects of type *rte_event* structure
361 * which contain the event object enqueue operations to be processed.
363 * The number of event objects to enqueue, typically number of
364 * rte_event_port_enqueue_depth() available for this port.
367 * The number of event objects actually enqueued on the event device. The
368 * return value can be less than the value of the *nb_events* parameter when
369 * the event devices queue is full or if invalid parameters are specified in a
370 * *rte_event*. If the return value is less than *nb_events*, the remaining
371 * events at the end of ev[] are not consumed and the caller has to take care
372 * of them, and rte_errno is set accordingly. Possible errno values include:
373 * - -EINVAL The port ID is invalid, device ID is invalid, an event's queue
374 * ID is invalid, or an event's sched type doesn't match the
375 * capabilities of the destination queue.
376 * - -ENOSPC The event port was backpressured and unable to enqueue
377 * one or more events. This error code is only applicable to
380 static inline uint16_t __rte_experimental
381 rte_event_eth_tx_adapter_enqueue(uint8_t dev_id,
383 struct rte_event ev[],
386 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
388 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
389 if (dev_id >= RTE_EVENT_MAX_DEVS ||
390 !rte_eventdevs[dev_id].attached) {
395 if (port_id >= dev->data->nb_ports) {
400 return dev->txa_enqueue(dev->data->ports[port_id], ev, nb_events);
405 * @b EXPERIMENTAL: this API may change without prior notice
407 * Retrieve statistics for an adapter
410 * Adapter identifier.
412 * A pointer to structure used to retrieve statistics for an adapter.
414 * - 0: Success, statistics retrieved successfully.
415 * - <0: Error code on failure.
417 int __rte_experimental
418 rte_event_eth_tx_adapter_stats_get(uint8_t id,
419 struct rte_event_eth_tx_adapter_stats *stats);
423 * @b EXPERIMENTAL: this API may change without prior notice
425 * Reset statistics for an adapter.
428 * Adapter identifier.
430 * - 0: Success, statistics reset successfully.
431 * - <0: Error code on failure.
433 int __rte_experimental
434 rte_event_eth_tx_adapter_stats_reset(uint8_t id);
438 * @b EXPERIMENTAL: this API may change without prior notice
440 * Retrieve the service ID of an adapter. If the adapter doesn't use
441 * a rte_service function, this function returns -ESRCH.
444 * Adapter identifier.
445 * @param [out] service_id
446 * A pointer to a uint32_t, to be filled in with the service id.
449 * - <0: Error code on failure, if the adapter doesn't use a rte_service
450 * function, this function returns -ESRCH.
452 int __rte_experimental
453 rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
458 #endif /* _RTE_EVENT_ETH_TX_ADAPTER_ */