xref: /dpdk/lib/eventdev/rte_event_eth_tx_adapter.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2018 Intel Corporation.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_EVENT_ETH_TX_ADAPTER_
699a2dd95SBruce Richardson #define _RTE_EVENT_ETH_TX_ADAPTER_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * RTE Event Ethernet Tx Adapter
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * The event ethernet Tx adapter provides configuration and data path APIs
1499a2dd95SBruce Richardson  * for the ethernet transmit stage of an event driven packet processing
1599a2dd95SBruce Richardson  * application. These APIs abstract the implementation of the transmit stage
1699a2dd95SBruce Richardson  * and allow the application to use eventdev PMD support or a common
1799a2dd95SBruce Richardson  * implementation.
1899a2dd95SBruce Richardson  *
1999a2dd95SBruce Richardson  * In the common implementation, the application enqueues mbufs to the adapter
2099a2dd95SBruce Richardson  * which runs as a rte_service function. The service function dequeues events
2199a2dd95SBruce Richardson  * from its event port and transmits the mbufs referenced by these events.
2299a2dd95SBruce Richardson  *
2399a2dd95SBruce Richardson  * The ethernet Tx event adapter APIs are:
2499a2dd95SBruce Richardson  *
2599a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_create()
2699a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_create_ext()
2799a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_free()
2899a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_start()
2999a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_stop()
3099a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_queue_add()
3199a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_queue_del()
3299a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_stats_get()
3399a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_stats_reset()
3499a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_enqueue()
3599a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_event_port_get()
3699a2dd95SBruce Richardson  *  - rte_event_eth_tx_adapter_service_id_get()
37b2963cbdSGanapati Kundapura  *  - rte_event_eth_tx_adapter_instance_get()
383c3328aeSNaga Harish K S V  *  - rte_event_eth_tx_adapter_queue_start()
393c3328aeSNaga Harish K S V  *  - rte_event_eth_tx_adapter_queue_stop()
401d176c7aSNaga Harish K S V  *  - rte_event_eth_tx_adapter_runtime_params_get()
411d176c7aSNaga Harish K S V  *  - rte_event_eth_tx_adapter_runtime_params_init()
421d176c7aSNaga Harish K S V  *  - rte_event_eth_tx_adapter_runtime_params_set()
4399a2dd95SBruce Richardson  *
4499a2dd95SBruce Richardson  * The application creates the adapter using
4599a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_create() or rte_event_eth_tx_adapter_create_ext().
4699a2dd95SBruce Richardson  *
4799a2dd95SBruce Richardson  * The adapter will use the common implementation when the eventdev PMD
4899a2dd95SBruce Richardson  * does not have the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability.
4999a2dd95SBruce Richardson  * The common implementation uses an event port that is created using the port
5099a2dd95SBruce Richardson  * configuration parameter passed to rte_event_eth_tx_adapter_create(). The
5199a2dd95SBruce Richardson  * application can get the port identifier using
5299a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_event_port_get() and must link an event queue to
5399a2dd95SBruce Richardson  * this port.
5499a2dd95SBruce Richardson  *
5599a2dd95SBruce Richardson  * If the eventdev PMD has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT
5699a2dd95SBruce Richardson  * flags set, Tx adapter events should be enqueued using the
5799a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_enqueue() function, else the application should
5899a2dd95SBruce Richardson  * use rte_event_enqueue_burst().
5999a2dd95SBruce Richardson  *
6099a2dd95SBruce Richardson  * Transmit queues can be added and deleted from the adapter using
6199a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_queue_add()/del() APIs respectively.
6299a2dd95SBruce Richardson  *
6399a2dd95SBruce Richardson  * The application can start and stop the adapter using the
6499a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_start/stop() calls.
6599a2dd95SBruce Richardson  *
6699a2dd95SBruce Richardson  * The common adapter implementation uses an EAL service function as described
6799a2dd95SBruce Richardson  * before and its execution is controlled using the rte_service APIs. The
6899a2dd95SBruce Richardson  * rte_event_eth_tx_adapter_service_id_get()
6999a2dd95SBruce Richardson  * function can be used to retrieve the adapter's service function ID.
7099a2dd95SBruce Richardson  *
7199a2dd95SBruce Richardson  * The ethernet port and transmit queue index to transmit the mbuf on are
7299a2dd95SBruce Richardson  * specified using the mbuf port struct rte_mbuf::hash::txadapter:txq.
7399a2dd95SBruce Richardson  * The application should use the rte_event_eth_tx_adapter_txq_set()
7499a2dd95SBruce Richardson  * and rte_event_eth_tx_adapter_txq_get() functions to access the transmit
7599a2dd95SBruce Richardson  * queue index, using these macros will help with minimizing application
7699a2dd95SBruce Richardson  * impact due to a change in how the transmit queue index is specified.
7799a2dd95SBruce Richardson  */
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson #include <stdint.h>
8099a2dd95SBruce Richardson 
811094dd94SDavid Marchand #include <rte_compat.h>
8299a2dd95SBruce Richardson #include <rte_mbuf.h>
8399a2dd95SBruce Richardson 
8499a2dd95SBruce Richardson #include "rte_eventdev.h"
8599a2dd95SBruce Richardson 
86*719834a6SMattias Rönnblom #ifdef __cplusplus
87*719834a6SMattias Rönnblom extern "C" {
88*719834a6SMattias Rönnblom #endif
89*719834a6SMattias Rönnblom 
9099a2dd95SBruce Richardson /**
9199a2dd95SBruce Richardson  * Adapter configuration structure
9299a2dd95SBruce Richardson  *
9399a2dd95SBruce Richardson  * @see rte_event_eth_tx_adapter_create_ext
9499a2dd95SBruce Richardson  * @see rte_event_eth_tx_adapter_conf_cb
9599a2dd95SBruce Richardson  */
9699a2dd95SBruce Richardson struct rte_event_eth_tx_adapter_conf {
9799a2dd95SBruce Richardson 	uint8_t event_port_id;
9899a2dd95SBruce Richardson 	/**< Event port identifier, the adapter service function dequeues mbuf
9999a2dd95SBruce Richardson 	 * events from this port.
10099a2dd95SBruce Richardson 	 * @see RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT
10199a2dd95SBruce Richardson 	 */
10299a2dd95SBruce Richardson 	uint32_t max_nb_tx;
10399a2dd95SBruce Richardson 	/**< The adapter can return early if it has processed at least
10499a2dd95SBruce Richardson 	 * max_nb_tx mbufs. This isn't treated as a requirement; batching may
10599a2dd95SBruce Richardson 	 * cause the adapter to process more than max_nb_tx mbufs.
10699a2dd95SBruce Richardson 	 */
10799a2dd95SBruce Richardson };
10899a2dd95SBruce Richardson 
10999a2dd95SBruce Richardson /**
1101d176c7aSNaga Harish K S V  * Adapter runtime configuration parameters
1111d176c7aSNaga Harish K S V  */
1121d176c7aSNaga Harish K S V struct rte_event_eth_tx_adapter_runtime_params {
1131d176c7aSNaga Harish K S V 	uint32_t max_nb_tx;
1141d176c7aSNaga Harish K S V 	/**< The adapter can return early if it has processed at least
1151d176c7aSNaga Harish K S V 	 * max_nb_tx mbufs. This isn't treated as a requirement; batching may
1161d176c7aSNaga Harish K S V 	 * cause the adapter to process more than max_nb_tx mbufs.
1171d176c7aSNaga Harish K S V 	 *
1181d176c7aSNaga Harish K S V 	 * rte_event_eth_tx_adapter_create() configures the
1191d176c7aSNaga Harish K S V 	 * adapter with default value of max_nb_tx.
1201d176c7aSNaga Harish K S V 	 * rte_event_eth_tx_adapter_create_ext() configures the adapter with
1211d176c7aSNaga Harish K S V 	 * user provided value of max_nb_tx through
1221d176c7aSNaga Harish K S V 	 * rte_event_eth_tx_adapter_conf::max_nb_tx parameter.
1231d176c7aSNaga Harish K S V 	 * rte_event_eth_tx_adapter_runtime_params_set() allows to re-configure
1241d176c7aSNaga Harish K S V 	 * max_nb_tx during runtime (after adding at least one queue)
1251d176c7aSNaga Harish K S V 	 *
1261d176c7aSNaga Harish K S V 	 * This is valid for the devices without
1271d176c7aSNaga Harish K S V 	 * RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability.
1281d176c7aSNaga Harish K S V 	 */
1291d176c7aSNaga Harish K S V 	uint16_t flush_threshold;
1301d176c7aSNaga Harish K S V 	/**< the number of service function iteration count to
1311d176c7aSNaga Harish K S V 	 * flush buffered packets.
1321d176c7aSNaga Harish K S V 	 *
1331d176c7aSNaga Harish K S V 	 * This is valid for the devices without
1341d176c7aSNaga Harish K S V 	 * RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability.
1351d176c7aSNaga Harish K S V 	 */
1361d176c7aSNaga Harish K S V 	uint16_t rsvd[29];
1371d176c7aSNaga Harish K S V 	/**< Reserved fields for future expansion */
1381d176c7aSNaga Harish K S V };
1391d176c7aSNaga Harish K S V 
1401d176c7aSNaga Harish K S V /**
14199a2dd95SBruce Richardson  * Function type used for adapter configuration callback. The callback is
14299a2dd95SBruce Richardson  * used to fill in members of the struct rte_event_eth_tx_adapter_conf, this
14399a2dd95SBruce Richardson  * callback is invoked when creating a RTE service function based
14499a2dd95SBruce Richardson  * adapter implementation.
14599a2dd95SBruce Richardson  *
14699a2dd95SBruce Richardson  * @param id
14799a2dd95SBruce Richardson  *  Adapter identifier.
14899a2dd95SBruce Richardson  * @param dev_id
14999a2dd95SBruce Richardson  *  Event device identifier.
15099a2dd95SBruce Richardson  * @param [out] conf
15199a2dd95SBruce Richardson  *  Structure that needs to be populated by this callback.
15299a2dd95SBruce Richardson  * @param arg
15399a2dd95SBruce Richardson  *  Argument to the callback. This is the same as the conf_arg passed to the
15499a2dd95SBruce Richardson  *  rte_event_eth_tx_adapter_create_ext().
15599a2dd95SBruce Richardson  *
15699a2dd95SBruce Richardson  * @return
15799a2dd95SBruce Richardson  *   - 0: Success
15899a2dd95SBruce Richardson  *   - <0: Error code on failure
15999a2dd95SBruce Richardson  */
16099a2dd95SBruce Richardson typedef int (*rte_event_eth_tx_adapter_conf_cb) (uint8_t id, uint8_t dev_id,
16199a2dd95SBruce Richardson 				struct rte_event_eth_tx_adapter_conf *conf,
16299a2dd95SBruce Richardson 				void *arg);
16399a2dd95SBruce Richardson 
16499a2dd95SBruce Richardson /**
16599a2dd95SBruce Richardson  * A structure used to retrieve statistics for an ethernet Tx adapter instance.
16699a2dd95SBruce Richardson  */
16799a2dd95SBruce Richardson struct rte_event_eth_tx_adapter_stats {
16899a2dd95SBruce Richardson 	uint64_t tx_retry;
16999a2dd95SBruce Richardson 	/**< Number of transmit retries */
17099a2dd95SBruce Richardson 	uint64_t tx_packets;
17199a2dd95SBruce Richardson 	/**< Number of packets transmitted */
17299a2dd95SBruce Richardson 	uint64_t tx_dropped;
17399a2dd95SBruce Richardson 	/**< Number of packets dropped */
17499a2dd95SBruce Richardson };
17599a2dd95SBruce Richardson 
17699a2dd95SBruce Richardson /**
17799a2dd95SBruce Richardson  * Create a new ethernet Tx adapter with the specified identifier.
17899a2dd95SBruce Richardson  *
17972fc5337SNaga Harish K S V  * When this API is used for creating adapter instance,
18072fc5337SNaga Harish K S V  * ``rte_event_dev_config::nb_event_ports`` is automatically incremented,
18172fc5337SNaga Harish K S V  * and event device is reconfigured with additional event port during service
18272fc5337SNaga Harish K S V  * initialization. This event device reconfigure logic also increments the
18372fc5337SNaga Harish K S V  * ``rte_event_dev_config::nb_single_link_event_port_queues``
18472fc5337SNaga Harish K S V  * parameter if the adapter event port config is of type
18572fc5337SNaga Harish K S V  * ``RTE_EVENT_PORT_CFG_SINGLE_LINK``.
18672fc5337SNaga Harish K S V  *
18772fc5337SNaga Harish K S V  * Application no longer needs to account for the
18872fc5337SNaga Harish K S V  * ``rte_event_dev_config::nb_event_ports`` and
18972fc5337SNaga Harish K S V  * ``rte_event_dev_config::nb_single_link_event_port_queues``
19072fc5337SNaga Harish K S V  * parameters required for eth Tx adapter in event device configure when
19172fc5337SNaga Harish K S V  * the adapter is created with this API.
19272fc5337SNaga Harish K S V  *
19399a2dd95SBruce Richardson  * @param id
19499a2dd95SBruce Richardson  *  The identifier of the ethernet Tx adapter.
19599a2dd95SBruce Richardson  * @param dev_id
19699a2dd95SBruce Richardson  *  The event device identifier.
19799a2dd95SBruce Richardson  * @param port_config
19899a2dd95SBruce Richardson  *  Event port configuration, the adapter uses this configuration to
19999a2dd95SBruce Richardson  *  create an event port if needed.
20099a2dd95SBruce Richardson  * @return
20199a2dd95SBruce Richardson  *   - 0: Success
20299a2dd95SBruce Richardson  *   - <0: Error code on failure
20399a2dd95SBruce Richardson  */
20499a2dd95SBruce Richardson int
20599a2dd95SBruce Richardson rte_event_eth_tx_adapter_create(uint8_t id, uint8_t dev_id,
20699a2dd95SBruce Richardson 				struct rte_event_port_conf *port_config);
20799a2dd95SBruce Richardson 
20899a2dd95SBruce Richardson /**
20999a2dd95SBruce Richardson  * Create a new ethernet Tx adapter with the specified identifier.
21099a2dd95SBruce Richardson  *
21199a2dd95SBruce Richardson  * @param id
21299a2dd95SBruce Richardson  *  The identifier of the ethernet Tx adapter.
21399a2dd95SBruce Richardson  * @param dev_id
21499a2dd95SBruce Richardson  *  The event device identifier.
21599a2dd95SBruce Richardson  * @param conf_cb
21699a2dd95SBruce Richardson  *  Callback function that initializes members of the
21799a2dd95SBruce Richardson  *  struct rte_event_eth_tx_adapter_conf struct passed into
21899a2dd95SBruce Richardson  *  it.
21999a2dd95SBruce Richardson  * @param conf_arg
22099a2dd95SBruce Richardson  *  Argument that is passed to the conf_cb function.
22199a2dd95SBruce Richardson  * @return
22299a2dd95SBruce Richardson  *   - 0: Success
22399a2dd95SBruce Richardson  *   - <0: Error code on failure
22499a2dd95SBruce Richardson  */
22599a2dd95SBruce Richardson int
22699a2dd95SBruce Richardson rte_event_eth_tx_adapter_create_ext(uint8_t id, uint8_t dev_id,
22799a2dd95SBruce Richardson 				rte_event_eth_tx_adapter_conf_cb conf_cb,
22899a2dd95SBruce Richardson 				void *conf_arg);
22999a2dd95SBruce Richardson 
23099a2dd95SBruce Richardson /**
23199a2dd95SBruce Richardson  * Free an ethernet Tx adapter
23299a2dd95SBruce Richardson  *
23399a2dd95SBruce Richardson  * @param id
23499a2dd95SBruce Richardson  *  Adapter identifier.
23599a2dd95SBruce Richardson  * @return
23699a2dd95SBruce Richardson  *   - 0: Success
23799a2dd95SBruce Richardson  *   - <0: Error code on failure, If the adapter still has Tx queues
23899a2dd95SBruce Richardson  *      added to it, the function returns -EBUSY.
23999a2dd95SBruce Richardson  */
24099a2dd95SBruce Richardson int
24199a2dd95SBruce Richardson rte_event_eth_tx_adapter_free(uint8_t id);
24299a2dd95SBruce Richardson 
24399a2dd95SBruce Richardson /**
24499a2dd95SBruce Richardson  * Start ethernet Tx adapter
24599a2dd95SBruce Richardson  *
24699a2dd95SBruce Richardson  * @param id
24799a2dd95SBruce Richardson  *  Adapter identifier.
24899a2dd95SBruce Richardson  * @return
24999a2dd95SBruce Richardson  *  - 0: Success, Adapter started correctly.
25099a2dd95SBruce Richardson  *  - <0: Error code on failure.
25199a2dd95SBruce Richardson  */
25299a2dd95SBruce Richardson int
25399a2dd95SBruce Richardson rte_event_eth_tx_adapter_start(uint8_t id);
25499a2dd95SBruce Richardson 
25599a2dd95SBruce Richardson /**
25699a2dd95SBruce Richardson  * Stop ethernet Tx adapter
25799a2dd95SBruce Richardson  *
25899a2dd95SBruce Richardson  * @param id
25999a2dd95SBruce Richardson  *  Adapter identifier.
26099a2dd95SBruce Richardson  * @return
26199a2dd95SBruce Richardson  *  - 0: Success.
26299a2dd95SBruce Richardson  *  - <0: Error code on failure.
26399a2dd95SBruce Richardson  */
26499a2dd95SBruce Richardson int
26599a2dd95SBruce Richardson rte_event_eth_tx_adapter_stop(uint8_t id);
26699a2dd95SBruce Richardson 
26799a2dd95SBruce Richardson /**
26899a2dd95SBruce Richardson  * Add a Tx queue to the adapter.
26999a2dd95SBruce Richardson  * A queue value of -1 is used to indicate all
27099a2dd95SBruce Richardson  * queues within the device.
27199a2dd95SBruce Richardson  *
27299a2dd95SBruce Richardson  * @param id
27399a2dd95SBruce Richardson  *  Adapter identifier.
27499a2dd95SBruce Richardson  * @param eth_dev_id
27599a2dd95SBruce Richardson  *  Ethernet Port Identifier.
27699a2dd95SBruce Richardson  * @param queue
27799a2dd95SBruce Richardson  *  Tx queue index.
27899a2dd95SBruce Richardson  * @return
27999a2dd95SBruce Richardson  *  - 0: Success, Queues added successfully.
28099a2dd95SBruce Richardson  *  - <0: Error code on failure.
28199a2dd95SBruce Richardson  */
28299a2dd95SBruce Richardson int
28399a2dd95SBruce Richardson rte_event_eth_tx_adapter_queue_add(uint8_t id,
28499a2dd95SBruce Richardson 				uint16_t eth_dev_id,
28599a2dd95SBruce Richardson 				int32_t queue);
28699a2dd95SBruce Richardson 
28799a2dd95SBruce Richardson /**
28899a2dd95SBruce Richardson  * Delete a Tx queue from the adapter.
28999a2dd95SBruce Richardson  * A queue value of -1 is used to indicate all
29099a2dd95SBruce Richardson  * queues within the device, that have been added to this
29199a2dd95SBruce Richardson  * adapter.
29299a2dd95SBruce Richardson  *
29399a2dd95SBruce Richardson  * @param id
29499a2dd95SBruce Richardson  *  Adapter identifier.
29599a2dd95SBruce Richardson  * @param eth_dev_id
29699a2dd95SBruce Richardson  *  Ethernet Port Identifier.
29799a2dd95SBruce Richardson  * @param queue
29899a2dd95SBruce Richardson  *  Tx queue index.
29999a2dd95SBruce Richardson  * @return
30099a2dd95SBruce Richardson  *  - 0: Success, Queues deleted successfully.
30199a2dd95SBruce Richardson  *  - <0: Error code on failure.
30299a2dd95SBruce Richardson  */
30399a2dd95SBruce Richardson int
30499a2dd95SBruce Richardson rte_event_eth_tx_adapter_queue_del(uint8_t id,
30599a2dd95SBruce Richardson 				uint16_t eth_dev_id,
30699a2dd95SBruce Richardson 				int32_t queue);
30799a2dd95SBruce Richardson 
30899a2dd95SBruce Richardson /**
30999a2dd95SBruce Richardson  * Set Tx queue in the mbuf. This queue is used by the adapter
31099a2dd95SBruce Richardson  * to transmit the mbuf.
31199a2dd95SBruce Richardson  *
31299a2dd95SBruce Richardson  * @param pkt
31399a2dd95SBruce Richardson  *  Pointer to the mbuf.
31499a2dd95SBruce Richardson  * @param queue
31599a2dd95SBruce Richardson  *  Tx queue index.
31699a2dd95SBruce Richardson  */
31799a2dd95SBruce Richardson static __rte_always_inline void
31899a2dd95SBruce Richardson rte_event_eth_tx_adapter_txq_set(struct rte_mbuf *pkt, uint16_t queue)
31999a2dd95SBruce Richardson {
32099a2dd95SBruce Richardson 	pkt->hash.txadapter.txq = queue;
32199a2dd95SBruce Richardson }
32299a2dd95SBruce Richardson 
32399a2dd95SBruce Richardson /**
32499a2dd95SBruce Richardson  * Retrieve Tx queue from the mbuf.
32599a2dd95SBruce Richardson  *
32699a2dd95SBruce Richardson  * @param pkt
32799a2dd95SBruce Richardson  *  Pointer to the mbuf.
32899a2dd95SBruce Richardson  * @return
32999a2dd95SBruce Richardson  *  Tx queue identifier.
33099a2dd95SBruce Richardson  *
33199a2dd95SBruce Richardson  * @see rte_event_eth_tx_adapter_txq_set()
33299a2dd95SBruce Richardson  */
33399a2dd95SBruce Richardson static __rte_always_inline uint16_t
33499a2dd95SBruce Richardson rte_event_eth_tx_adapter_txq_get(struct rte_mbuf *pkt)
33599a2dd95SBruce Richardson {
33699a2dd95SBruce Richardson 	return pkt->hash.txadapter.txq;
33799a2dd95SBruce Richardson }
33899a2dd95SBruce Richardson 
33999a2dd95SBruce Richardson /**
34099a2dd95SBruce Richardson  * Retrieve the adapter event port. The adapter creates an event port if
34199a2dd95SBruce Richardson  * the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT is not set in the
34299a2dd95SBruce Richardson  * ethernet Tx capabilities of the event device.
34399a2dd95SBruce Richardson  *
34499a2dd95SBruce Richardson  * @param id
34599a2dd95SBruce Richardson  *  Adapter Identifier.
34699a2dd95SBruce Richardson  * @param[out] event_port_id
34799a2dd95SBruce Richardson  *  Event port pointer.
34899a2dd95SBruce Richardson  * @return
34999a2dd95SBruce Richardson  *   - 0: Success.
35099a2dd95SBruce Richardson  *   - <0: Error code on failure.
35199a2dd95SBruce Richardson  */
35299a2dd95SBruce Richardson int
35399a2dd95SBruce Richardson rte_event_eth_tx_adapter_event_port_get(uint8_t id, uint8_t *event_port_id);
35499a2dd95SBruce Richardson 
35599a2dd95SBruce Richardson #define RTE_EVENT_ETH_TX_ADAPTER_ENQUEUE_SAME_DEST	0x1
35699a2dd95SBruce Richardson /**< This flag is used when all the packets enqueued in the tx adapter are
35799a2dd95SBruce Richardson  * destined for the same Ethernet port & Tx queue.
35899a2dd95SBruce Richardson  */
35999a2dd95SBruce Richardson 
36099a2dd95SBruce Richardson /**
36199a2dd95SBruce Richardson  * Enqueue a burst of events objects or an event object supplied in *rte_event*
36299a2dd95SBruce Richardson  * structure on an  event device designated by its *dev_id* through the event
36399a2dd95SBruce Richardson  * port specified by *port_id*. This function is supported if the eventdev PMD
36499a2dd95SBruce Richardson  * has the #RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT capability flag set.
36599a2dd95SBruce Richardson  *
36699a2dd95SBruce Richardson  * The *nb_events* parameter is the number of event objects to enqueue which are
36799a2dd95SBruce Richardson  * supplied in the *ev* array of *rte_event* structure.
36899a2dd95SBruce Richardson  *
36999a2dd95SBruce Richardson  * The rte_event_eth_tx_adapter_enqueue() function returns the number of
37099a2dd95SBruce Richardson  * events objects it actually enqueued. A return value equal to *nb_events*
37199a2dd95SBruce Richardson  * means that all event objects have been enqueued.
37299a2dd95SBruce Richardson  *
37399a2dd95SBruce Richardson  * @param dev_id
37499a2dd95SBruce Richardson  *  The identifier of the device.
37599a2dd95SBruce Richardson  * @param port_id
37699a2dd95SBruce Richardson  *  The identifier of the event port.
37799a2dd95SBruce Richardson  * @param ev
37899a2dd95SBruce Richardson  *  Points to an array of *nb_events* objects of type *rte_event* structure
37999a2dd95SBruce Richardson  *  which contain the event object enqueue operations to be processed.
38099a2dd95SBruce Richardson  * @param nb_events
38199a2dd95SBruce Richardson  *  The number of event objects to enqueue, typically number of
38299a2dd95SBruce Richardson  *  rte_event_port_attr_get(...RTE_EVENT_PORT_ATTR_ENQ_DEPTH...)
38399a2dd95SBruce Richardson  *  available for this port.
38499a2dd95SBruce Richardson  * @param flags
38599a2dd95SBruce Richardson  *  RTE_EVENT_ETH_TX_ADAPTER_ENQUEUE_ flags.
38699a2dd95SBruce Richardson  *  #RTE_EVENT_ETH_TX_ADAPTER_ENQUEUE_SAME_DEST signifies that all the packets
38799a2dd95SBruce Richardson  *  which are enqueued are destined for the same Ethernet port & Tx queue.
38899a2dd95SBruce Richardson  *
38999a2dd95SBruce Richardson  * @return
39099a2dd95SBruce Richardson  *   The number of event objects actually enqueued on the event device. The
39199a2dd95SBruce Richardson  *   return value can be less than the value of the *nb_events* parameter when
39299a2dd95SBruce Richardson  *   the event devices queue is full or if invalid parameters are specified in a
39399a2dd95SBruce Richardson  *   *rte_event*. If the return value is less than *nb_events*, the remaining
39499a2dd95SBruce Richardson  *   events at the end of ev[] are not consumed and the caller has to take care
39599a2dd95SBruce Richardson  *   of them, and rte_errno is set accordingly. Possible errno values include:
39699a2dd95SBruce Richardson  *   - EINVAL   The port ID is invalid, device ID is invalid, an event's queue
39799a2dd95SBruce Richardson  *              ID is invalid, or an event's sched type doesn't match the
39899a2dd95SBruce Richardson  *              capabilities of the destination queue.
39999a2dd95SBruce Richardson  *   - ENOSPC   The event port was backpressured and unable to enqueue
40099a2dd95SBruce Richardson  *              one or more events. This error code is only applicable to
40199a2dd95SBruce Richardson  *              closed systems.
40299a2dd95SBruce Richardson  */
40399a2dd95SBruce Richardson static inline uint16_t
40499a2dd95SBruce Richardson rte_event_eth_tx_adapter_enqueue(uint8_t dev_id,
40599a2dd95SBruce Richardson 				uint8_t port_id,
40699a2dd95SBruce Richardson 				struct rte_event ev[],
40799a2dd95SBruce Richardson 				uint16_t nb_events,
40899a2dd95SBruce Richardson 				const uint8_t flags)
40999a2dd95SBruce Richardson {
410052e25d9SPavan Nikhilesh 	const struct rte_event_fp_ops *fp_ops;
411052e25d9SPavan Nikhilesh 	void *port;
41299a2dd95SBruce Richardson 
413052e25d9SPavan Nikhilesh 	fp_ops = &rte_event_fp_ops[dev_id];
414052e25d9SPavan Nikhilesh 	port = fp_ops->data[port_id];
41599a2dd95SBruce Richardson #ifdef RTE_LIBRTE_EVENTDEV_DEBUG
41699a2dd95SBruce Richardson 	if (dev_id >= RTE_EVENT_MAX_DEVS ||
417052e25d9SPavan Nikhilesh 	    port_id >= RTE_EVENT_MAX_PORTS_PER_DEV) {
41899a2dd95SBruce Richardson 		rte_errno = EINVAL;
41999a2dd95SBruce Richardson 		return 0;
42099a2dd95SBruce Richardson 	}
42199a2dd95SBruce Richardson 
422052e25d9SPavan Nikhilesh 	if (port == NULL) {
42399a2dd95SBruce Richardson 		rte_errno = EINVAL;
42499a2dd95SBruce Richardson 		return 0;
42599a2dd95SBruce Richardson 	}
42699a2dd95SBruce Richardson #endif
42799a2dd95SBruce Richardson 	rte_eventdev_trace_eth_tx_adapter_enqueue(dev_id, port_id, ev,
42899a2dd95SBruce Richardson 		nb_events, flags);
42999a2dd95SBruce Richardson 	if (flags)
430052e25d9SPavan Nikhilesh 		return fp_ops->txa_enqueue_same_dest(port, ev, nb_events);
43199a2dd95SBruce Richardson 	else
432052e25d9SPavan Nikhilesh 		return fp_ops->txa_enqueue(port, ev, nb_events);
43399a2dd95SBruce Richardson }
43499a2dd95SBruce Richardson 
43599a2dd95SBruce Richardson /**
43699a2dd95SBruce Richardson  * Retrieve statistics for an adapter
43799a2dd95SBruce Richardson  *
43899a2dd95SBruce Richardson  * @param id
43999a2dd95SBruce Richardson  *  Adapter identifier.
44099a2dd95SBruce Richardson  * @param [out] stats
44199a2dd95SBruce Richardson  *  A pointer to structure used to retrieve statistics for an adapter.
44299a2dd95SBruce Richardson  * @return
44399a2dd95SBruce Richardson  *  - 0: Success, statistics retrieved successfully.
44499a2dd95SBruce Richardson  *  - <0: Error code on failure.
44599a2dd95SBruce Richardson  */
44699a2dd95SBruce Richardson int
44799a2dd95SBruce Richardson rte_event_eth_tx_adapter_stats_get(uint8_t id,
44899a2dd95SBruce Richardson 				struct rte_event_eth_tx_adapter_stats *stats);
44999a2dd95SBruce Richardson 
45099a2dd95SBruce Richardson /**
45199a2dd95SBruce Richardson  * Reset statistics for an adapter.
45299a2dd95SBruce Richardson  *
45399a2dd95SBruce Richardson  * @param id
45499a2dd95SBruce Richardson  *  Adapter identifier.
45599a2dd95SBruce Richardson  * @return
45699a2dd95SBruce Richardson  *  - 0: Success, statistics reset successfully.
45799a2dd95SBruce Richardson  *  - <0: Error code on failure.
45899a2dd95SBruce Richardson  */
45999a2dd95SBruce Richardson int
46099a2dd95SBruce Richardson rte_event_eth_tx_adapter_stats_reset(uint8_t id);
46199a2dd95SBruce Richardson 
46299a2dd95SBruce Richardson /**
46399a2dd95SBruce Richardson  * Retrieve the service ID of an adapter. If the adapter doesn't use
46499a2dd95SBruce Richardson  * a rte_service function, this function returns -ESRCH.
46599a2dd95SBruce Richardson  *
46699a2dd95SBruce Richardson  * @param id
46799a2dd95SBruce Richardson  *  Adapter identifier.
46899a2dd95SBruce Richardson  * @param [out] service_id
46999a2dd95SBruce Richardson  *  A pointer to a uint32_t, to be filled in with the service id.
47099a2dd95SBruce Richardson  * @return
47199a2dd95SBruce Richardson  *  - 0: Success
47299a2dd95SBruce Richardson  *  - <0: Error code on failure, if the adapter doesn't use a rte_service
47399a2dd95SBruce Richardson  * function, this function returns -ESRCH.
47499a2dd95SBruce Richardson  */
47599a2dd95SBruce Richardson int
47699a2dd95SBruce Richardson rte_event_eth_tx_adapter_service_id_get(uint8_t id, uint32_t *service_id);
47799a2dd95SBruce Richardson 
478b2963cbdSGanapati Kundapura /**
479b2963cbdSGanapati Kundapura  * Get TX adapter instance id for TX queue
480b2963cbdSGanapati Kundapura  *
481b2963cbdSGanapati Kundapura  * @param eth_dev_id
482b2963cbdSGanapati Kundapura  *  Port identifier of Ethernet device
483b2963cbdSGanapati Kundapura  *
484b2963cbdSGanapati Kundapura  * @param tx_queue_id
485b2963cbdSGanapati Kundapura  *  Etherdev device TX queue index
486b2963cbdSGanapati Kundapura  *
487b2963cbdSGanapati Kundapura  * @param[out] txa_inst_id
488b2963cbdSGanapati Kundapura  *  Pointer to TX adapter instance identifier
489b2963cbdSGanapati Kundapura  *  Contains valid Tx adapter instance id when return value is 0
490b2963cbdSGanapati Kundapura  *
491b2963cbdSGanapati Kundapura  * @return
492b2963cbdSGanapati Kundapura  *  -  0: Success
493b2963cbdSGanapati Kundapura  *  - <0: Error code on failure
494b2963cbdSGanapati Kundapura  */
495b2963cbdSGanapati Kundapura int
496b2963cbdSGanapati Kundapura rte_event_eth_tx_adapter_instance_get(uint16_t eth_dev_id,
497b2963cbdSGanapati Kundapura 				      uint16_t tx_queue_id,
498b2963cbdSGanapati Kundapura 				      uint8_t *txa_inst_id);
4993c3328aeSNaga Harish K S V /**
5003c3328aeSNaga Harish K S V  * Enables the adapter to start enqueueing of packets to the
5013c3328aeSNaga Harish K S V  * Tx queue.
5023c3328aeSNaga Harish K S V  *
5033c3328aeSNaga Harish K S V  * This function is provided so that the application can
5043c3328aeSNaga Harish K S V  * resume enqueueing packets that reference packets for
5053c3328aeSNaga Harish K S V  * <eth_dev_id, tx_queue_id> after calling
5063c3328aeSNaga Harish K S V  * rte_event_eth_tx_adapter_queue_stop().
5073c3328aeSNaga Harish K S V  * @see rte_event_eth_tx_adapter_queue_stop
5083c3328aeSNaga Harish K S V  *
5093c3328aeSNaga Harish K S V  * Use case:
5103c3328aeSNaga Harish K S V  * --------
5113c3328aeSNaga Harish K S V  * The queue start/stop APIs help avoid some unexpected behavior with
5123c3328aeSNaga Harish K S V  * application stopping ethdev Tx queues and adapter being unaware of it.
5133c3328aeSNaga Harish K S V  * With these APIs, the application can call stop API to notify adapter
5143c3328aeSNaga Harish K S V  * that corresponding ethdev Tx queue is stopped and any in-flight
5153c3328aeSNaga Harish K S V  * packets are freed by adapter dataplane code. Adapter queue stop API
5163c3328aeSNaga Harish K S V  * is called before stopping the ethdev Tx queue. When ethdev Tx queue
5173c3328aeSNaga Harish K S V  * is enabled, application can notify adapter to resume processing of
5183c3328aeSNaga Harish K S V  * the packets for that queue by calling the start API. The ethdev Tx
5193c3328aeSNaga Harish K S V  * queue is started before calling adapter start API.
5203c3328aeSNaga Harish K S V  *
5213c3328aeSNaga Harish K S V  * @param eth_dev_id
5223c3328aeSNaga Harish K S V  *  Port identifier of Ethernet device.
5233c3328aeSNaga Harish K S V  * @param tx_queue_id
5243c3328aeSNaga Harish K S V  *  Ethernet device transmit queue index.
5253c3328aeSNaga Harish K S V  * @return
5263c3328aeSNaga Harish K S V  *   - 0: Success
5273c3328aeSNaga Harish K S V  *   - <0: Error code on failure
5283c3328aeSNaga Harish K S V  */
5293c3328aeSNaga Harish K S V int
5303c3328aeSNaga Harish K S V rte_event_eth_tx_adapter_queue_start(uint16_t eth_dev_id, uint16_t tx_queue_id);
5313c3328aeSNaga Harish K S V 
5323c3328aeSNaga Harish K S V /**
5333c3328aeSNaga Harish K S V  * Stops the adapter runtime function from enqueueing any packets
5343c3328aeSNaga Harish K S V  * to the associated Tx queue. This API also frees any packets that may
5353c3328aeSNaga Harish K S V  * have been buffered for this queue. All inflight packets destined to the
5363c3328aeSNaga Harish K S V  * queue are freed by the adapter runtime until the queue is started again.
5373c3328aeSNaga Harish K S V  * @see rte_event_eth_tx_adapter_queue_start
5383c3328aeSNaga Harish K S V  *
5393c3328aeSNaga Harish K S V  * @param eth_dev_id
5403c3328aeSNaga Harish K S V  *  Port identifier of Ethernet device.
5413c3328aeSNaga Harish K S V  * @param tx_queue_id
5423c3328aeSNaga Harish K S V  *  Ethernet device transmit queue index.
5433c3328aeSNaga Harish K S V  * @return
5443c3328aeSNaga Harish K S V  *   - 0: Success
5453c3328aeSNaga Harish K S V  *   - <0: Error code on failure
5463c3328aeSNaga Harish K S V  */
5473c3328aeSNaga Harish K S V int
5483c3328aeSNaga Harish K S V rte_event_eth_tx_adapter_queue_stop(uint16_t eth_dev_id, uint16_t tx_queue_id);
549b2963cbdSGanapati Kundapura 
5501d176c7aSNaga Harish K S V /**
5511d176c7aSNaga Harish K S V  * Initialize the adapter runtime configuration parameters with default values
5521d176c7aSNaga Harish K S V  *
5531d176c7aSNaga Harish K S V  * @param txa_params
5541d176c7aSNaga Harish K S V  *  A pointer to structure of type struct rte_event_eth_tx_adapter_runtime_params
5551d176c7aSNaga Harish K S V  *
5561d176c7aSNaga Harish K S V  * @return
5571d176c7aSNaga Harish K S V  *  -  0: Success
5581d176c7aSNaga Harish K S V  *  - <0: Error code on failure
5591d176c7aSNaga Harish K S V  */
5601d176c7aSNaga Harish K S V __rte_experimental
5611d176c7aSNaga Harish K S V int
5621d176c7aSNaga Harish K S V rte_event_eth_tx_adapter_runtime_params_init(
5631d176c7aSNaga Harish K S V 		struct rte_event_eth_tx_adapter_runtime_params *txa_params);
5641d176c7aSNaga Harish K S V 
5651d176c7aSNaga Harish K S V /**
5661d176c7aSNaga Harish K S V  * Set the runtime configuration parameters for adapter.
5671d176c7aSNaga Harish K S V  *
5681d176c7aSNaga Harish K S V  * @param id
5691d176c7aSNaga Harish K S V  *  Adapter identifier
5701d176c7aSNaga Harish K S V  * @param params
5711d176c7aSNaga Harish K S V  *  A pointer to structure of type struct rte_event_eth_tx_adapter_runtime_params
5721d176c7aSNaga Harish K S V  *  with configuration parameter values. The reserved fields of this structure
5731d176c7aSNaga Harish K S V  *  must be initialized to zero and the valid fields need to be set appropriately.
5741d176c7aSNaga Harish K S V  *  This structure can be initialized using
5751d176c7aSNaga Harish K S V  *  rte_event_eth_tx_adapter_runtime_params_init() API to default values or
5761d176c7aSNaga Harish K S V  *  application may reset this structure and update required fields.
5771d176c7aSNaga Harish K S V  *
5781d176c7aSNaga Harish K S V  * @return
5791d176c7aSNaga Harish K S V  * -  0: Success
5801d176c7aSNaga Harish K S V  * - <0: Error code on failure
5811d176c7aSNaga Harish K S V  */
5821d176c7aSNaga Harish K S V __rte_experimental
5831d176c7aSNaga Harish K S V int
5841d176c7aSNaga Harish K S V rte_event_eth_tx_adapter_runtime_params_set(uint8_t id,
5851d176c7aSNaga Harish K S V 		struct rte_event_eth_tx_adapter_runtime_params *params);
5861d176c7aSNaga Harish K S V 
5871d176c7aSNaga Harish K S V /**
5881d176c7aSNaga Harish K S V  * Get the runtime configuration parameters of adapter.
5891d176c7aSNaga Harish K S V  *
5901d176c7aSNaga Harish K S V  * @param id
5911d176c7aSNaga Harish K S V  *  Adapter identifier
5921d176c7aSNaga Harish K S V  * @param[out] params
5931d176c7aSNaga Harish K S V  *  A pointer to structure of type struct rte_event_eth_tx_adapter_runtime_params
5941d176c7aSNaga Harish K S V  *  containing valid Tx adapter parameters when return value is 0.
5951d176c7aSNaga Harish K S V  *
5961d176c7aSNaga Harish K S V  * @return
5971d176c7aSNaga Harish K S V  * -  0: Success
5981d176c7aSNaga Harish K S V  * - <0: Error code on failure
5991d176c7aSNaga Harish K S V  */
6001d176c7aSNaga Harish K S V __rte_experimental
6011d176c7aSNaga Harish K S V int
6021d176c7aSNaga Harish K S V rte_event_eth_tx_adapter_runtime_params_get(uint8_t id,
6031d176c7aSNaga Harish K S V 		struct rte_event_eth_tx_adapter_runtime_params *params);
6041d176c7aSNaga Harish K S V 
60599a2dd95SBruce Richardson #ifdef __cplusplus
60699a2dd95SBruce Richardson }
60799a2dd95SBruce Richardson #endif
60899a2dd95SBruce Richardson #endif	/* _RTE_EVENT_ETH_TX_ADAPTER_ */
609