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"
84 * Adapter configuration structure
86 * @see rte_event_eth_tx_adapter_create_ext
87 * @see rte_event_eth_tx_adapter_conf_cb
89 struct rte_event_eth_tx_adapter_conf {
90 uint8_t event_port_id;
91 /**< Event port identifier, the adapter service function dequeues mbuf
92 * events from this port.
93 * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT
96 /**< The adapter can return early if it has processed at least
97 * max_nb_tx mbufs. This isn't treated as a requirement; batching may
98 * cause the adapter to process more than max_nb_tx mbufs.
103 * Function type used for adapter configuration callback. The callback is
104 * used to fill in members of the struct rte_event_eth_tx_adapter_conf, this
105 * callback is invoked when creating a RTE service function based
106 * adapter implementation.
109 * Adapter identifier.
111 * Event device identifier.
113 * Structure that needs to be populated by this callback.
115 * Argument to the callback. This is the same as the conf_arg passed to the
116 * rte_event_eth_tx_adapter_create_ext().
120 * - <0: Error code on failure
122 typedef int (*rte_event_eth_tx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
123 struct rte_event_eth_tx_adapter_conf *conf,
127 * A structure used to retrieve statistics for an ethernet Tx adapter instance.
129 struct rte_event_eth_tx_adapter_stats {
131 /**< Number of transmit retries */
133 /**< Number of packets transmitted */
135 /**< Number of packets dropped */
139 * Create a new ethernet Tx adapter with the specified identifier.
142 * The identifier of the ethernet Tx adapter.
144 * The event device identifier.
146 * Event port configuration, the adapter uses this configuration to
147 * create an event port if needed.
150 * - <0: Error code on failure
153 rte_event_eth_tx_adapter_create(uint8_t id, uint8_t dev_id,
154 struct rte_event_port_conf *port_config);
157 * Create a new ethernet Tx adapter with the specified identifier.
160 * The identifier of the ethernet Tx adapter.
162 * The event device identifier.
164 * Callback function that initializes members of the
165 * struct rte_event_eth_tx_adapter_conf struct passed into
168 * Argument that is passed to the conf_cb function.
171 * - <0: Error code on failure
174 rte_event_eth_tx_adapter_create_ext(uint8_t id, uint8_t dev_id,
175 rte_event_eth_tx_adapter_conf_cb conf_cb,
179 * Free an ethernet Tx adapter
182 * Adapter identifier.
185 * - <0: Error code on failure, If the adapter still has Tx queues
186 * added to it, the function returns -EBUSY.
189 rte_event_eth_tx_adapter_free(uint8_t id);
192 * Start ethernet Tx adapter
195 * Adapter identifier.
197 * - 0: Success, Adapter started correctly.
198 * - <0: Error code on failure.
201 rte_event_eth_tx_adapter_start(uint8_t id);
204 * Stop ethernet Tx adapter
207 * Adapter identifier.
210 * - <0: Error code on failure.
213 rte_event_eth_tx_adapter_stop(uint8_t id);
216 * Add a Tx queue to the adapter.
217 * A queue value of -1 is used to indicate all
218 * queues within the device.
221 * Adapter identifier.
223 * Ethernet Port Identifier.
227 * - 0: Success, Queues added successfully.
228 * - <0: Error code on failure.
231 rte_event_eth_tx_adapter_queue_add(uint8_t id,
236 * Delete a Tx queue from the adapter.
237 * A queue value of -1 is used to indicate all
238 * queues within the device, that have been added to this
242 * Adapter identifier.
244 * Ethernet Port Identifier.
248 * - 0: Success, Queues deleted successfully.
249 * - <0: Error code on failure.
252 rte_event_eth_tx_adapter_queue_del(uint8_t id,
257 * Set Tx queue in the mbuf. This queue is used by the adapter
258 * to transmit the mbuf.
261 * Pointer to the mbuf.
265 static __rte_always_inline void
266 rte_event_eth_tx_adapter_txq_set(struct rte_mbuf *pkt, uint16_t queue)
268 pkt->hash.txadapter.txq = queue;
272 * Retrieve Tx queue from the mbuf.
275 * Pointer to the mbuf.
277 * Tx queue identifier.
279 * @see rte_event_eth_tx_adapter_txq_set()
281 static __rte_always_inline uint16_t
282 rte_event_eth_tx_adapter_txq_get(struct rte_mbuf *pkt)
284 return pkt->hash.txadapter.txq;
288 * Retrieve the adapter event port. The adapter creates an event port if
289 * the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT is not set in the
290 * ethernet Tx capabilities of the event device.
293 * Adapter Identifier.
294 * @param[out] event_port_id
295 * Event port pointer.
298 * - <0: Error code on failure.
301 rte_event_eth_tx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id);
304 * Enqueue a burst of events objects or an event object supplied in *rte_event*
305 * structure on an event device designated by its *dev_id* through the event
306 * port specified by *port_id*. This function is supported if the eventdev PMD
307 * has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability flag set.
309 * The *nb_events* parameter is the number of event objects to enqueue which are
310 * supplied in the *ev* array of *rte_event* structure.
312 * The rte_event_eth_tx_adapter_enqueue() function returns the number of
313 * events objects it actually enqueued. A return value equal to *nb_events*
314 * means that all event objects have been enqueued.
317 * The identifier of the device.
319 * The identifier of the event port.
321 * Points to an array of *nb_events* objects of type *rte_event* structure
322 * which contain the event object enqueue operations to be processed.
324 * The number of event objects to enqueue, typically number of
325 * rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
326 * available for this port.
329 * The number of event objects actually enqueued on the event device. The
330 * return value can be less than the value of the *nb_events* parameter when
331 * the event devices queue is full or if invalid parameters are specified in a
332 * *rte_event*. If the return value is less than *nb_events*, the remaining
333 * events at the end of ev[] are not consumed and the caller has to take care
334 * of them, and rte_errno is set accordingly. Possible errno values include:
335 * - -EINVAL The port ID is invalid, device ID is invalid, an event's queue
336 * ID is invalid, or an event's sched type doesn't match the
337 * capabilities of the destination queue.
338 * - -ENOSPC The event port was backpressured and unable to enqueue
339 * one or more events. This error code is only applicable to
342 static inline uint16_t
343 rte_event_eth_tx_adapter_enqueue(uint8_t dev_id,
345 struct rte_event ev[],
348 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
350 #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
351 if (dev_id >= RTE_EVENT_MAX_DEVS ||
352 !rte_eventdevs[dev_id].attached) {
357 if (port_id >= dev->data->nb_ports) {
362 return dev->txa_enqueue(dev->data->ports[port_id], ev, nb_events);
366 * Retrieve statistics for an adapter
369 * Adapter identifier.
371 * A pointer to structure used to retrieve statistics for an adapter.
373 * - 0: Success, statistics retrieved successfully.
374 * - <0: Error code on failure.
377 rte_event_eth_tx_adapter_stats_get(uint8_t id,
378 struct rte_event_eth_tx_adapter_stats *stats);
381 * Reset statistics for an adapter.
384 * Adapter identifier.
386 * - 0: Success, statistics reset successfully.
387 * - <0: Error code on failure.
390 rte_event_eth_tx_adapter_stats_reset(uint8_t id);
393 * Retrieve the service ID of an adapter. If the adapter doesn't use
394 * a rte_service function, this function returns -ESRCH.
397 * Adapter identifier.
398 * @param [out] service_id
399 * A pointer to a uint32_t, to be filled in with the service id.
402 * - <0: Error code on failure, if the adapter doesn't use a rte_service
403 * function, this function returns -ESRCH.
406 rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
411 #endif /* _RTE_EVENT_ETH_TX_ADAPTER_ */