xref: /dpdk/lib/eventdev/rte_eventdev.c (revision e74abd48433dc05e3d40cc922577d6c55b5b844c)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2016 Cavium, Inc
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #include <ctype.h>
699a2dd95SBruce Richardson #include <stdio.h>
799a2dd95SBruce Richardson #include <stdlib.h>
899a2dd95SBruce Richardson #include <string.h>
999a2dd95SBruce Richardson #include <stdarg.h>
1099a2dd95SBruce Richardson #include <errno.h>
1199a2dd95SBruce Richardson #include <stdint.h>
1299a2dd95SBruce Richardson #include <inttypes.h>
1399a2dd95SBruce Richardson #include <sys/types.h>
1499a2dd95SBruce Richardson #include <sys/queue.h>
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <rte_string_fns.h>
1799a2dd95SBruce Richardson #include <rte_byteorder.h>
1899a2dd95SBruce Richardson #include <rte_log.h>
1999a2dd95SBruce Richardson #include <rte_debug.h>
2099a2dd95SBruce Richardson #include <rte_dev.h>
2199a2dd95SBruce Richardson #include <rte_memory.h>
2299a2dd95SBruce Richardson #include <rte_memcpy.h>
2399a2dd95SBruce Richardson #include <rte_memzone.h>
2499a2dd95SBruce Richardson #include <rte_eal.h>
2599a2dd95SBruce Richardson #include <rte_per_lcore.h>
2699a2dd95SBruce Richardson #include <rte_lcore.h>
2799a2dd95SBruce Richardson #include <rte_atomic.h>
2899a2dd95SBruce Richardson #include <rte_branch_prediction.h>
2999a2dd95SBruce Richardson #include <rte_common.h>
3099a2dd95SBruce Richardson #include <rte_malloc.h>
3199a2dd95SBruce Richardson #include <rte_errno.h>
3299a2dd95SBruce Richardson #include <rte_ethdev.h>
3399a2dd95SBruce Richardson #include <rte_cryptodev.h>
3499a2dd95SBruce Richardson #include <rte_cryptodev_pmd.h>
3599a2dd95SBruce Richardson #include <rte_telemetry.h>
3699a2dd95SBruce Richardson 
3799a2dd95SBruce Richardson #include "rte_eventdev.h"
3899a2dd95SBruce Richardson #include "eventdev_pmd.h"
3999a2dd95SBruce Richardson #include "rte_eventdev_trace.h"
4099a2dd95SBruce Richardson 
4199a2dd95SBruce Richardson static struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson struct rte_eventdev *rte_eventdevs = rte_event_devices;
4499a2dd95SBruce Richardson 
4599a2dd95SBruce Richardson static struct rte_eventdev_global eventdev_globals = {
4699a2dd95SBruce Richardson 	.nb_devs		= 0
4799a2dd95SBruce Richardson };
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson /* Event dev north bound API implementation */
5099a2dd95SBruce Richardson 
5199a2dd95SBruce Richardson uint8_t
5299a2dd95SBruce Richardson rte_event_dev_count(void)
5399a2dd95SBruce Richardson {
5499a2dd95SBruce Richardson 	return eventdev_globals.nb_devs;
5599a2dd95SBruce Richardson }
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson int
5899a2dd95SBruce Richardson rte_event_dev_get_dev_id(const char *name)
5999a2dd95SBruce Richardson {
6099a2dd95SBruce Richardson 	int i;
6199a2dd95SBruce Richardson 	uint8_t cmp;
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson 	if (!name)
6499a2dd95SBruce Richardson 		return -EINVAL;
6599a2dd95SBruce Richardson 
6699a2dd95SBruce Richardson 	for (i = 0; i < eventdev_globals.nb_devs; i++) {
6799a2dd95SBruce Richardson 		cmp = (strncmp(rte_event_devices[i].data->name, name,
6899a2dd95SBruce Richardson 				RTE_EVENTDEV_NAME_MAX_LEN) == 0) ||
6999a2dd95SBruce Richardson 			(rte_event_devices[i].dev ? (strncmp(
7099a2dd95SBruce Richardson 				rte_event_devices[i].dev->driver->name, name,
7199a2dd95SBruce Richardson 					 RTE_EVENTDEV_NAME_MAX_LEN) == 0) : 0);
7299a2dd95SBruce Richardson 		if (cmp && (rte_event_devices[i].attached ==
7399a2dd95SBruce Richardson 					RTE_EVENTDEV_ATTACHED))
7499a2dd95SBruce Richardson 			return i;
7599a2dd95SBruce Richardson 	}
7699a2dd95SBruce Richardson 	return -ENODEV;
7799a2dd95SBruce Richardson }
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson int
8099a2dd95SBruce Richardson rte_event_dev_socket_id(uint8_t dev_id)
8199a2dd95SBruce Richardson {
8299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
8399a2dd95SBruce Richardson 
8499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
8599a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson 	return dev->data->socket_id;
8899a2dd95SBruce Richardson }
8999a2dd95SBruce Richardson 
9099a2dd95SBruce Richardson int
9199a2dd95SBruce Richardson rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
9299a2dd95SBruce Richardson {
9399a2dd95SBruce Richardson 	struct rte_eventdev *dev;
9499a2dd95SBruce Richardson 
9599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
9699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
9799a2dd95SBruce Richardson 
9899a2dd95SBruce Richardson 	if (dev_info == NULL)
9999a2dd95SBruce Richardson 		return -EINVAL;
10099a2dd95SBruce Richardson 
10199a2dd95SBruce Richardson 	memset(dev_info, 0, sizeof(struct rte_event_dev_info));
10299a2dd95SBruce Richardson 
10399a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
10499a2dd95SBruce Richardson 	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
10599a2dd95SBruce Richardson 
10699a2dd95SBruce Richardson 	dev_info->dequeue_timeout_ns = dev->data->dev_conf.dequeue_timeout_ns;
10799a2dd95SBruce Richardson 
10899a2dd95SBruce Richardson 	dev_info->dev = dev->dev;
10999a2dd95SBruce Richardson 	return 0;
11099a2dd95SBruce Richardson }
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson int
11399a2dd95SBruce Richardson rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
11499a2dd95SBruce Richardson 				uint32_t *caps)
11599a2dd95SBruce Richardson {
11699a2dd95SBruce Richardson 	struct rte_eventdev *dev;
11799a2dd95SBruce Richardson 
11899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
11999a2dd95SBruce Richardson 	RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
12099a2dd95SBruce Richardson 
12199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
12299a2dd95SBruce Richardson 
12399a2dd95SBruce Richardson 	if (caps == NULL)
12499a2dd95SBruce Richardson 		return -EINVAL;
12599a2dd95SBruce Richardson 
12699a2dd95SBruce Richardson 	if (dev->dev_ops->eth_rx_adapter_caps_get == NULL)
12799a2dd95SBruce Richardson 		*caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
12899a2dd95SBruce Richardson 	else
12999a2dd95SBruce Richardson 		*caps = 0;
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson 	return dev->dev_ops->eth_rx_adapter_caps_get ?
13299a2dd95SBruce Richardson 				(*dev->dev_ops->eth_rx_adapter_caps_get)(dev,
13399a2dd95SBruce Richardson 						&rte_eth_devices[eth_port_id],
13499a2dd95SBruce Richardson 						caps)
13599a2dd95SBruce Richardson 				: 0;
13699a2dd95SBruce Richardson }
13799a2dd95SBruce Richardson 
13899a2dd95SBruce Richardson int
13999a2dd95SBruce Richardson rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps)
14099a2dd95SBruce Richardson {
14199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
14299a2dd95SBruce Richardson 	const struct rte_event_timer_adapter_ops *ops;
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
14599a2dd95SBruce Richardson 
14699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
14799a2dd95SBruce Richardson 
14899a2dd95SBruce Richardson 	if (caps == NULL)
14999a2dd95SBruce Richardson 		return -EINVAL;
15099a2dd95SBruce Richardson 	*caps = 0;
15199a2dd95SBruce Richardson 
15299a2dd95SBruce Richardson 	return dev->dev_ops->timer_adapter_caps_get ?
15399a2dd95SBruce Richardson 				(*dev->dev_ops->timer_adapter_caps_get)(dev,
15499a2dd95SBruce Richardson 									0,
15599a2dd95SBruce Richardson 									caps,
15699a2dd95SBruce Richardson 									&ops)
15799a2dd95SBruce Richardson 				: 0;
15899a2dd95SBruce Richardson }
15999a2dd95SBruce Richardson 
16099a2dd95SBruce Richardson int
16199a2dd95SBruce Richardson rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
16299a2dd95SBruce Richardson 				  uint32_t *caps)
16399a2dd95SBruce Richardson {
16499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
16599a2dd95SBruce Richardson 	struct rte_cryptodev *cdev;
16699a2dd95SBruce Richardson 
16799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
168*e74abd48SAkhil Goyal 	if (!rte_cryptodev_is_valid_dev(cdev_id))
16999a2dd95SBruce Richardson 		return -EINVAL;
17099a2dd95SBruce Richardson 
17199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
17299a2dd95SBruce Richardson 	cdev = rte_cryptodev_pmd_get_dev(cdev_id);
17399a2dd95SBruce Richardson 
17499a2dd95SBruce Richardson 	if (caps == NULL)
17599a2dd95SBruce Richardson 		return -EINVAL;
17699a2dd95SBruce Richardson 	*caps = 0;
17799a2dd95SBruce Richardson 
17899a2dd95SBruce Richardson 	return dev->dev_ops->crypto_adapter_caps_get ?
17999a2dd95SBruce Richardson 		(*dev->dev_ops->crypto_adapter_caps_get)
18099a2dd95SBruce Richardson 		(dev, cdev, caps) : -ENOTSUP;
18199a2dd95SBruce Richardson }
18299a2dd95SBruce Richardson 
18399a2dd95SBruce Richardson int
18499a2dd95SBruce Richardson rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
18599a2dd95SBruce Richardson 				uint32_t *caps)
18699a2dd95SBruce Richardson {
18799a2dd95SBruce Richardson 	struct rte_eventdev *dev;
18899a2dd95SBruce Richardson 	struct rte_eth_dev *eth_dev;
18999a2dd95SBruce Richardson 
19099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
19199a2dd95SBruce Richardson 	RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
19299a2dd95SBruce Richardson 
19399a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
19499a2dd95SBruce Richardson 	eth_dev = &rte_eth_devices[eth_port_id];
19599a2dd95SBruce Richardson 
19699a2dd95SBruce Richardson 	if (caps == NULL)
19799a2dd95SBruce Richardson 		return -EINVAL;
19899a2dd95SBruce Richardson 
19999a2dd95SBruce Richardson 	if (dev->dev_ops->eth_tx_adapter_caps_get == NULL)
20099a2dd95SBruce Richardson 		*caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR;
20199a2dd95SBruce Richardson 	else
20299a2dd95SBruce Richardson 		*caps = 0;
20399a2dd95SBruce Richardson 
20499a2dd95SBruce Richardson 	return dev->dev_ops->eth_tx_adapter_caps_get ?
20599a2dd95SBruce Richardson 			(*dev->dev_ops->eth_tx_adapter_caps_get)(dev,
20699a2dd95SBruce Richardson 								eth_dev,
20799a2dd95SBruce Richardson 								caps)
20899a2dd95SBruce Richardson 			: 0;
20999a2dd95SBruce Richardson }
21099a2dd95SBruce Richardson 
21199a2dd95SBruce Richardson static inline int
21299a2dd95SBruce Richardson rte_event_dev_queue_config(struct rte_eventdev *dev, uint8_t nb_queues)
21399a2dd95SBruce Richardson {
21499a2dd95SBruce Richardson 	uint8_t old_nb_queues = dev->data->nb_queues;
21599a2dd95SBruce Richardson 	struct rte_event_queue_conf *queues_cfg;
21699a2dd95SBruce Richardson 	unsigned int i;
21799a2dd95SBruce Richardson 
21899a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Setup %d queues on device %u", nb_queues,
21999a2dd95SBruce Richardson 			 dev->data->dev_id);
22099a2dd95SBruce Richardson 
22199a2dd95SBruce Richardson 	/* First time configuration */
22299a2dd95SBruce Richardson 	if (dev->data->queues_cfg == NULL && nb_queues != 0) {
22399a2dd95SBruce Richardson 		/* Allocate memory to store queue configuration */
22499a2dd95SBruce Richardson 		dev->data->queues_cfg = rte_zmalloc_socket(
22599a2dd95SBruce Richardson 				"eventdev->data->queues_cfg",
22699a2dd95SBruce Richardson 				sizeof(dev->data->queues_cfg[0]) * nb_queues,
22799a2dd95SBruce Richardson 				RTE_CACHE_LINE_SIZE, dev->data->socket_id);
22899a2dd95SBruce Richardson 		if (dev->data->queues_cfg == NULL) {
22999a2dd95SBruce Richardson 			dev->data->nb_queues = 0;
23099a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to get mem for queue cfg,"
23199a2dd95SBruce Richardson 					"nb_queues %u", nb_queues);
23299a2dd95SBruce Richardson 			return -(ENOMEM);
23399a2dd95SBruce Richardson 		}
23499a2dd95SBruce Richardson 	/* Re-configure */
23599a2dd95SBruce Richardson 	} else if (dev->data->queues_cfg != NULL && nb_queues != 0) {
23699a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
23799a2dd95SBruce Richardson 
23899a2dd95SBruce Richardson 		for (i = nb_queues; i < old_nb_queues; i++)
23999a2dd95SBruce Richardson 			(*dev->dev_ops->queue_release)(dev, i);
24099a2dd95SBruce Richardson 
24199a2dd95SBruce Richardson 		/* Re allocate memory to store queue configuration */
24299a2dd95SBruce Richardson 		queues_cfg = dev->data->queues_cfg;
24399a2dd95SBruce Richardson 		queues_cfg = rte_realloc(queues_cfg,
24499a2dd95SBruce Richardson 				sizeof(queues_cfg[0]) * nb_queues,
24599a2dd95SBruce Richardson 				RTE_CACHE_LINE_SIZE);
24699a2dd95SBruce Richardson 		if (queues_cfg == NULL) {
24799a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to realloc queue cfg memory,"
24899a2dd95SBruce Richardson 						" nb_queues %u", nb_queues);
24999a2dd95SBruce Richardson 			return -(ENOMEM);
25099a2dd95SBruce Richardson 		}
25199a2dd95SBruce Richardson 		dev->data->queues_cfg = queues_cfg;
25299a2dd95SBruce Richardson 
25399a2dd95SBruce Richardson 		if (nb_queues > old_nb_queues) {
25499a2dd95SBruce Richardson 			uint8_t new_qs = nb_queues - old_nb_queues;
25599a2dd95SBruce Richardson 
25699a2dd95SBruce Richardson 			memset(queues_cfg + old_nb_queues, 0,
25799a2dd95SBruce Richardson 				sizeof(queues_cfg[0]) * new_qs);
25899a2dd95SBruce Richardson 		}
25999a2dd95SBruce Richardson 	} else if (dev->data->queues_cfg != NULL && nb_queues == 0) {
26099a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
26199a2dd95SBruce Richardson 
26299a2dd95SBruce Richardson 		for (i = nb_queues; i < old_nb_queues; i++)
26399a2dd95SBruce Richardson 			(*dev->dev_ops->queue_release)(dev, i);
26499a2dd95SBruce Richardson 	}
26599a2dd95SBruce Richardson 
26699a2dd95SBruce Richardson 	dev->data->nb_queues = nb_queues;
26799a2dd95SBruce Richardson 	return 0;
26899a2dd95SBruce Richardson }
26999a2dd95SBruce Richardson 
27099a2dd95SBruce Richardson #define EVENT_QUEUE_SERVICE_PRIORITY_INVALID (0xdead)
27199a2dd95SBruce Richardson 
27299a2dd95SBruce Richardson static inline int
27399a2dd95SBruce Richardson rte_event_dev_port_config(struct rte_eventdev *dev, uint8_t nb_ports)
27499a2dd95SBruce Richardson {
27599a2dd95SBruce Richardson 	uint8_t old_nb_ports = dev->data->nb_ports;
27699a2dd95SBruce Richardson 	void **ports;
27799a2dd95SBruce Richardson 	uint16_t *links_map;
27899a2dd95SBruce Richardson 	struct rte_event_port_conf *ports_cfg;
27999a2dd95SBruce Richardson 	unsigned int i;
28099a2dd95SBruce Richardson 
28199a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Setup %d ports on device %u", nb_ports,
28299a2dd95SBruce Richardson 			 dev->data->dev_id);
28399a2dd95SBruce Richardson 
28499a2dd95SBruce Richardson 	/* First time configuration */
28599a2dd95SBruce Richardson 	if (dev->data->ports == NULL && nb_ports != 0) {
28699a2dd95SBruce Richardson 		dev->data->ports = rte_zmalloc_socket("eventdev->data->ports",
28799a2dd95SBruce Richardson 				sizeof(dev->data->ports[0]) * nb_ports,
28899a2dd95SBruce Richardson 				RTE_CACHE_LINE_SIZE, dev->data->socket_id);
28999a2dd95SBruce Richardson 		if (dev->data->ports == NULL) {
29099a2dd95SBruce Richardson 			dev->data->nb_ports = 0;
29199a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to get mem for port meta data,"
29299a2dd95SBruce Richardson 					"nb_ports %u", nb_ports);
29399a2dd95SBruce Richardson 			return -(ENOMEM);
29499a2dd95SBruce Richardson 		}
29599a2dd95SBruce Richardson 
29699a2dd95SBruce Richardson 		/* Allocate memory to store port configurations */
29799a2dd95SBruce Richardson 		dev->data->ports_cfg =
29899a2dd95SBruce Richardson 			rte_zmalloc_socket("eventdev->ports_cfg",
29999a2dd95SBruce Richardson 			sizeof(dev->data->ports_cfg[0]) * nb_ports,
30099a2dd95SBruce Richardson 			RTE_CACHE_LINE_SIZE, dev->data->socket_id);
30199a2dd95SBruce Richardson 		if (dev->data->ports_cfg == NULL) {
30299a2dd95SBruce Richardson 			dev->data->nb_ports = 0;
30399a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to get mem for port cfg,"
30499a2dd95SBruce Richardson 					"nb_ports %u", nb_ports);
30599a2dd95SBruce Richardson 			return -(ENOMEM);
30699a2dd95SBruce Richardson 		}
30799a2dd95SBruce Richardson 
30899a2dd95SBruce Richardson 		/* Allocate memory to store queue to port link connection */
30999a2dd95SBruce Richardson 		dev->data->links_map =
31099a2dd95SBruce Richardson 			rte_zmalloc_socket("eventdev->links_map",
31199a2dd95SBruce Richardson 			sizeof(dev->data->links_map[0]) * nb_ports *
31299a2dd95SBruce Richardson 			RTE_EVENT_MAX_QUEUES_PER_DEV,
31399a2dd95SBruce Richardson 			RTE_CACHE_LINE_SIZE, dev->data->socket_id);
31499a2dd95SBruce Richardson 		if (dev->data->links_map == NULL) {
31599a2dd95SBruce Richardson 			dev->data->nb_ports = 0;
31699a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to get mem for port_map area,"
31799a2dd95SBruce Richardson 					"nb_ports %u", nb_ports);
31899a2dd95SBruce Richardson 			return -(ENOMEM);
31999a2dd95SBruce Richardson 		}
32099a2dd95SBruce Richardson 		for (i = 0; i < nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV; i++)
32199a2dd95SBruce Richardson 			dev->data->links_map[i] =
32299a2dd95SBruce Richardson 				EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
32399a2dd95SBruce Richardson 	} else if (dev->data->ports != NULL && nb_ports != 0) {/* re-config */
32499a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
32599a2dd95SBruce Richardson 
32699a2dd95SBruce Richardson 		ports = dev->data->ports;
32799a2dd95SBruce Richardson 		ports_cfg = dev->data->ports_cfg;
32899a2dd95SBruce Richardson 		links_map = dev->data->links_map;
32999a2dd95SBruce Richardson 
33099a2dd95SBruce Richardson 		for (i = nb_ports; i < old_nb_ports; i++)
33199a2dd95SBruce Richardson 			(*dev->dev_ops->port_release)(ports[i]);
33299a2dd95SBruce Richardson 
33399a2dd95SBruce Richardson 		/* Realloc memory for ports */
33499a2dd95SBruce Richardson 		ports = rte_realloc(ports, sizeof(ports[0]) * nb_ports,
33599a2dd95SBruce Richardson 				RTE_CACHE_LINE_SIZE);
33699a2dd95SBruce Richardson 		if (ports == NULL) {
33799a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to realloc port meta data,"
33899a2dd95SBruce Richardson 						" nb_ports %u", nb_ports);
33999a2dd95SBruce Richardson 			return -(ENOMEM);
34099a2dd95SBruce Richardson 		}
34199a2dd95SBruce Richardson 
34299a2dd95SBruce Richardson 		/* Realloc memory for ports_cfg */
34399a2dd95SBruce Richardson 		ports_cfg = rte_realloc(ports_cfg,
34499a2dd95SBruce Richardson 			sizeof(ports_cfg[0]) * nb_ports,
34599a2dd95SBruce Richardson 			RTE_CACHE_LINE_SIZE);
34699a2dd95SBruce Richardson 		if (ports_cfg == NULL) {
34799a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to realloc port cfg mem,"
34899a2dd95SBruce Richardson 						" nb_ports %u", nb_ports);
34999a2dd95SBruce Richardson 			return -(ENOMEM);
35099a2dd95SBruce Richardson 		}
35199a2dd95SBruce Richardson 
35299a2dd95SBruce Richardson 		/* Realloc memory to store queue to port link connection */
35399a2dd95SBruce Richardson 		links_map = rte_realloc(links_map,
35499a2dd95SBruce Richardson 			sizeof(dev->data->links_map[0]) * nb_ports *
35599a2dd95SBruce Richardson 			RTE_EVENT_MAX_QUEUES_PER_DEV,
35699a2dd95SBruce Richardson 			RTE_CACHE_LINE_SIZE);
35799a2dd95SBruce Richardson 		if (links_map == NULL) {
35899a2dd95SBruce Richardson 			dev->data->nb_ports = 0;
35999a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("failed to realloc mem for port_map,"
36099a2dd95SBruce Richardson 					"nb_ports %u", nb_ports);
36199a2dd95SBruce Richardson 			return -(ENOMEM);
36299a2dd95SBruce Richardson 		}
36399a2dd95SBruce Richardson 
36499a2dd95SBruce Richardson 		if (nb_ports > old_nb_ports) {
36599a2dd95SBruce Richardson 			uint8_t new_ps = nb_ports - old_nb_ports;
36699a2dd95SBruce Richardson 			unsigned int old_links_map_end =
36799a2dd95SBruce Richardson 				old_nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
36899a2dd95SBruce Richardson 			unsigned int links_map_end =
36999a2dd95SBruce Richardson 				nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
37099a2dd95SBruce Richardson 
37199a2dd95SBruce Richardson 			memset(ports + old_nb_ports, 0,
37299a2dd95SBruce Richardson 				sizeof(ports[0]) * new_ps);
37399a2dd95SBruce Richardson 			memset(ports_cfg + old_nb_ports, 0,
37499a2dd95SBruce Richardson 				sizeof(ports_cfg[0]) * new_ps);
37599a2dd95SBruce Richardson 			for (i = old_links_map_end; i < links_map_end; i++)
37699a2dd95SBruce Richardson 				links_map[i] =
37799a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
37899a2dd95SBruce Richardson 		}
37999a2dd95SBruce Richardson 
38099a2dd95SBruce Richardson 		dev->data->ports = ports;
38199a2dd95SBruce Richardson 		dev->data->ports_cfg = ports_cfg;
38299a2dd95SBruce Richardson 		dev->data->links_map = links_map;
38399a2dd95SBruce Richardson 	} else if (dev->data->ports != NULL && nb_ports == 0) {
38499a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
38599a2dd95SBruce Richardson 
38699a2dd95SBruce Richardson 		ports = dev->data->ports;
38799a2dd95SBruce Richardson 		for (i = nb_ports; i < old_nb_ports; i++)
38899a2dd95SBruce Richardson 			(*dev->dev_ops->port_release)(ports[i]);
38999a2dd95SBruce Richardson 	}
39099a2dd95SBruce Richardson 
39199a2dd95SBruce Richardson 	dev->data->nb_ports = nb_ports;
39299a2dd95SBruce Richardson 	return 0;
39399a2dd95SBruce Richardson }
39499a2dd95SBruce Richardson 
39599a2dd95SBruce Richardson int
39699a2dd95SBruce Richardson rte_event_dev_configure(uint8_t dev_id,
39799a2dd95SBruce Richardson 			const struct rte_event_dev_config *dev_conf)
39899a2dd95SBruce Richardson {
39999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
40099a2dd95SBruce Richardson 	struct rte_event_dev_info info;
40199a2dd95SBruce Richardson 	int diag;
40299a2dd95SBruce Richardson 
40399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
40499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
40599a2dd95SBruce Richardson 
40699a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
40799a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
40899a2dd95SBruce Richardson 
40999a2dd95SBruce Richardson 	if (dev->data->dev_started) {
41099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
41199a2dd95SBruce Richardson 		    "device %d must be stopped to allow configuration", dev_id);
41299a2dd95SBruce Richardson 		return -EBUSY;
41399a2dd95SBruce Richardson 	}
41499a2dd95SBruce Richardson 
41599a2dd95SBruce Richardson 	if (dev_conf == NULL)
41699a2dd95SBruce Richardson 		return -EINVAL;
41799a2dd95SBruce Richardson 
41899a2dd95SBruce Richardson 	(*dev->dev_ops->dev_infos_get)(dev, &info);
41999a2dd95SBruce Richardson 
42099a2dd95SBruce Richardson 	/* Check dequeue_timeout_ns value is in limit */
42199a2dd95SBruce Richardson 	if (!(dev_conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)) {
42299a2dd95SBruce Richardson 		if (dev_conf->dequeue_timeout_ns &&
42399a2dd95SBruce Richardson 		    (dev_conf->dequeue_timeout_ns < info.min_dequeue_timeout_ns
42499a2dd95SBruce Richardson 			|| dev_conf->dequeue_timeout_ns >
42599a2dd95SBruce Richardson 				 info.max_dequeue_timeout_ns)) {
42699a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("dev%d invalid dequeue_timeout_ns=%d"
42799a2dd95SBruce Richardson 			" min_dequeue_timeout_ns=%d max_dequeue_timeout_ns=%d",
42899a2dd95SBruce Richardson 			dev_id, dev_conf->dequeue_timeout_ns,
42999a2dd95SBruce Richardson 			info.min_dequeue_timeout_ns,
43099a2dd95SBruce Richardson 			info.max_dequeue_timeout_ns);
43199a2dd95SBruce Richardson 			return -EINVAL;
43299a2dd95SBruce Richardson 		}
43399a2dd95SBruce Richardson 	}
43499a2dd95SBruce Richardson 
43599a2dd95SBruce Richardson 	/* Check nb_events_limit is in limit */
43699a2dd95SBruce Richardson 	if (dev_conf->nb_events_limit > info.max_num_events) {
43799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_events_limit=%d > max_num_events=%d",
43899a2dd95SBruce Richardson 		dev_id, dev_conf->nb_events_limit, info.max_num_events);
43999a2dd95SBruce Richardson 		return -EINVAL;
44099a2dd95SBruce Richardson 	}
44199a2dd95SBruce Richardson 
44299a2dd95SBruce Richardson 	/* Check nb_event_queues is in limit */
44399a2dd95SBruce Richardson 	if (!dev_conf->nb_event_queues) {
44499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_event_queues cannot be zero",
44599a2dd95SBruce Richardson 					dev_id);
44699a2dd95SBruce Richardson 		return -EINVAL;
44799a2dd95SBruce Richardson 	}
44899a2dd95SBruce Richardson 	if (dev_conf->nb_event_queues > info.max_event_queues +
44999a2dd95SBruce Richardson 			info.max_single_link_event_port_queue_pairs) {
45099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("%d nb_event_queues=%d > max_event_queues=%d + max_single_link_event_port_queue_pairs=%d",
45199a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_queues,
45299a2dd95SBruce Richardson 				 info.max_event_queues,
45399a2dd95SBruce Richardson 				 info.max_single_link_event_port_queue_pairs);
45499a2dd95SBruce Richardson 		return -EINVAL;
45599a2dd95SBruce Richardson 	}
45699a2dd95SBruce Richardson 	if (dev_conf->nb_event_queues -
45799a2dd95SBruce Richardson 			dev_conf->nb_single_link_event_port_queues >
45899a2dd95SBruce Richardson 			info.max_event_queues) {
45999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_queues=%d - nb_single_link_event_port_queues=%d > max_event_queues=%d",
46099a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_queues,
46199a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
46299a2dd95SBruce Richardson 				 info.max_event_queues);
46399a2dd95SBruce Richardson 		return -EINVAL;
46499a2dd95SBruce Richardson 	}
46599a2dd95SBruce Richardson 	if (dev_conf->nb_single_link_event_port_queues >
46699a2dd95SBruce Richardson 			dev_conf->nb_event_queues) {
46799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_single_link_event_port_queues=%d > nb_event_queues=%d",
46899a2dd95SBruce Richardson 				 dev_id,
46999a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
47099a2dd95SBruce Richardson 				 dev_conf->nb_event_queues);
47199a2dd95SBruce Richardson 		return -EINVAL;
47299a2dd95SBruce Richardson 	}
47399a2dd95SBruce Richardson 
47499a2dd95SBruce Richardson 	/* Check nb_event_ports is in limit */
47599a2dd95SBruce Richardson 	if (!dev_conf->nb_event_ports) {
47699a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_event_ports cannot be zero", dev_id);
47799a2dd95SBruce Richardson 		return -EINVAL;
47899a2dd95SBruce Richardson 	}
47999a2dd95SBruce Richardson 	if (dev_conf->nb_event_ports > info.max_event_ports +
48099a2dd95SBruce Richardson 			info.max_single_link_event_port_queue_pairs) {
48199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d > max_event_ports=%d + max_single_link_event_port_queue_pairs=%d",
48299a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_ports,
48399a2dd95SBruce Richardson 				 info.max_event_ports,
48499a2dd95SBruce Richardson 				 info.max_single_link_event_port_queue_pairs);
48599a2dd95SBruce Richardson 		return -EINVAL;
48699a2dd95SBruce Richardson 	}
48799a2dd95SBruce Richardson 	if (dev_conf->nb_event_ports -
48899a2dd95SBruce Richardson 			dev_conf->nb_single_link_event_port_queues
48999a2dd95SBruce Richardson 			> info.max_event_ports) {
49099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d - nb_single_link_event_port_queues=%d > max_event_ports=%d",
49199a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_ports,
49299a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
49399a2dd95SBruce Richardson 				 info.max_event_ports);
49499a2dd95SBruce Richardson 		return -EINVAL;
49599a2dd95SBruce Richardson 	}
49699a2dd95SBruce Richardson 
49799a2dd95SBruce Richardson 	if (dev_conf->nb_single_link_event_port_queues >
49899a2dd95SBruce Richardson 	    dev_conf->nb_event_ports) {
49999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
50099a2dd95SBruce Richardson 				 "dev%d nb_single_link_event_port_queues=%d > nb_event_ports=%d",
50199a2dd95SBruce Richardson 				 dev_id,
50299a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
50399a2dd95SBruce Richardson 				 dev_conf->nb_event_ports);
50499a2dd95SBruce Richardson 		return -EINVAL;
50599a2dd95SBruce Richardson 	}
50699a2dd95SBruce Richardson 
50799a2dd95SBruce Richardson 	/* Check nb_event_queue_flows is in limit */
50899a2dd95SBruce Richardson 	if (!dev_conf->nb_event_queue_flows) {
50999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_flows cannot be zero", dev_id);
51099a2dd95SBruce Richardson 		return -EINVAL;
51199a2dd95SBruce Richardson 	}
51299a2dd95SBruce Richardson 	if (dev_conf->nb_event_queue_flows > info.max_event_queue_flows) {
51399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_flows=%x > max_flows=%x",
51499a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_queue_flows,
51599a2dd95SBruce Richardson 		info.max_event_queue_flows);
51699a2dd95SBruce Richardson 		return -EINVAL;
51799a2dd95SBruce Richardson 	}
51899a2dd95SBruce Richardson 
51999a2dd95SBruce Richardson 	/* Check nb_event_port_dequeue_depth is in limit */
52099a2dd95SBruce Richardson 	if (!dev_conf->nb_event_port_dequeue_depth) {
52199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_dequeue_depth cannot be zero",
52299a2dd95SBruce Richardson 					dev_id);
52399a2dd95SBruce Richardson 		return -EINVAL;
52499a2dd95SBruce Richardson 	}
52599a2dd95SBruce Richardson 	if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
52699a2dd95SBruce Richardson 		 (dev_conf->nb_event_port_dequeue_depth >
52799a2dd95SBruce Richardson 			 info.max_event_port_dequeue_depth)) {
52899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_dq_depth=%d > max_dq_depth=%d",
52999a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_port_dequeue_depth,
53099a2dd95SBruce Richardson 		info.max_event_port_dequeue_depth);
53199a2dd95SBruce Richardson 		return -EINVAL;
53299a2dd95SBruce Richardson 	}
53399a2dd95SBruce Richardson 
53499a2dd95SBruce Richardson 	/* Check nb_event_port_enqueue_depth is in limit */
53599a2dd95SBruce Richardson 	if (!dev_conf->nb_event_port_enqueue_depth) {
53699a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_enqueue_depth cannot be zero",
53799a2dd95SBruce Richardson 					dev_id);
53899a2dd95SBruce Richardson 		return -EINVAL;
53999a2dd95SBruce Richardson 	}
54099a2dd95SBruce Richardson 	if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
54199a2dd95SBruce Richardson 		(dev_conf->nb_event_port_enqueue_depth >
54299a2dd95SBruce Richardson 			 info.max_event_port_enqueue_depth)) {
54399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_enq_depth=%d > max_enq_depth=%d",
54499a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_port_enqueue_depth,
54599a2dd95SBruce Richardson 		info.max_event_port_enqueue_depth);
54699a2dd95SBruce Richardson 		return -EINVAL;
54799a2dd95SBruce Richardson 	}
54899a2dd95SBruce Richardson 
54999a2dd95SBruce Richardson 	/* Copy the dev_conf parameter into the dev structure */
55099a2dd95SBruce Richardson 	memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
55199a2dd95SBruce Richardson 
55299a2dd95SBruce Richardson 	/* Setup new number of queues and reconfigure device. */
55399a2dd95SBruce Richardson 	diag = rte_event_dev_queue_config(dev, dev_conf->nb_event_queues);
55499a2dd95SBruce Richardson 	if (diag != 0) {
55599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d rte_event_dev_queue_config = %d",
55699a2dd95SBruce Richardson 				dev_id, diag);
55799a2dd95SBruce Richardson 		return diag;
55899a2dd95SBruce Richardson 	}
55999a2dd95SBruce Richardson 
56099a2dd95SBruce Richardson 	/* Setup new number of ports and reconfigure device. */
56199a2dd95SBruce Richardson 	diag = rte_event_dev_port_config(dev, dev_conf->nb_event_ports);
56299a2dd95SBruce Richardson 	if (diag != 0) {
56399a2dd95SBruce Richardson 		rte_event_dev_queue_config(dev, 0);
56499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d rte_event_dev_port_config = %d",
56599a2dd95SBruce Richardson 				dev_id, diag);
56699a2dd95SBruce Richardson 		return diag;
56799a2dd95SBruce Richardson 	}
56899a2dd95SBruce Richardson 
56999a2dd95SBruce Richardson 	/* Configure the device */
57099a2dd95SBruce Richardson 	diag = (*dev->dev_ops->dev_configure)(dev);
57199a2dd95SBruce Richardson 	if (diag != 0) {
57299a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d dev_configure = %d", dev_id, diag);
57399a2dd95SBruce Richardson 		rte_event_dev_queue_config(dev, 0);
57499a2dd95SBruce Richardson 		rte_event_dev_port_config(dev, 0);
57599a2dd95SBruce Richardson 	}
57699a2dd95SBruce Richardson 
57799a2dd95SBruce Richardson 	dev->data->event_dev_cap = info.event_dev_cap;
57899a2dd95SBruce Richardson 	rte_eventdev_trace_configure(dev_id, dev_conf, diag);
57999a2dd95SBruce Richardson 	return diag;
58099a2dd95SBruce Richardson }
58199a2dd95SBruce Richardson 
58299a2dd95SBruce Richardson static inline int
58399a2dd95SBruce Richardson is_valid_queue(struct rte_eventdev *dev, uint8_t queue_id)
58499a2dd95SBruce Richardson {
58599a2dd95SBruce Richardson 	if (queue_id < dev->data->nb_queues && queue_id <
58699a2dd95SBruce Richardson 				RTE_EVENT_MAX_QUEUES_PER_DEV)
58799a2dd95SBruce Richardson 		return 1;
58899a2dd95SBruce Richardson 	else
58999a2dd95SBruce Richardson 		return 0;
59099a2dd95SBruce Richardson }
59199a2dd95SBruce Richardson 
59299a2dd95SBruce Richardson int
59399a2dd95SBruce Richardson rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
59499a2dd95SBruce Richardson 				 struct rte_event_queue_conf *queue_conf)
59599a2dd95SBruce Richardson {
59699a2dd95SBruce Richardson 	struct rte_eventdev *dev;
59799a2dd95SBruce Richardson 
59899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
59999a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
60099a2dd95SBruce Richardson 
60199a2dd95SBruce Richardson 	if (queue_conf == NULL)
60299a2dd95SBruce Richardson 		return -EINVAL;
60399a2dd95SBruce Richardson 
60499a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
60599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
60699a2dd95SBruce Richardson 		return -EINVAL;
60799a2dd95SBruce Richardson 	}
60899a2dd95SBruce Richardson 
60999a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP);
61099a2dd95SBruce Richardson 	memset(queue_conf, 0, sizeof(struct rte_event_queue_conf));
61199a2dd95SBruce Richardson 	(*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
61299a2dd95SBruce Richardson 	return 0;
61399a2dd95SBruce Richardson }
61499a2dd95SBruce Richardson 
61599a2dd95SBruce Richardson static inline int
61699a2dd95SBruce Richardson is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
61799a2dd95SBruce Richardson {
61899a2dd95SBruce Richardson 	if (queue_conf &&
61999a2dd95SBruce Richardson 		!(queue_conf->event_queue_cfg &
62099a2dd95SBruce Richardson 		  RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
62199a2dd95SBruce Richardson 		((queue_conf->event_queue_cfg &
62299a2dd95SBruce Richardson 			 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
62399a2dd95SBruce Richardson 		(queue_conf->schedule_type
62499a2dd95SBruce Richardson 			== RTE_SCHED_TYPE_ATOMIC)
62599a2dd95SBruce Richardson 		))
62699a2dd95SBruce Richardson 		return 1;
62799a2dd95SBruce Richardson 	else
62899a2dd95SBruce Richardson 		return 0;
62999a2dd95SBruce Richardson }
63099a2dd95SBruce Richardson 
63199a2dd95SBruce Richardson static inline int
63299a2dd95SBruce Richardson is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
63399a2dd95SBruce Richardson {
63499a2dd95SBruce Richardson 	if (queue_conf &&
63599a2dd95SBruce Richardson 		!(queue_conf->event_queue_cfg &
63699a2dd95SBruce Richardson 		  RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
63799a2dd95SBruce Richardson 		((queue_conf->event_queue_cfg &
63899a2dd95SBruce Richardson 			 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
63999a2dd95SBruce Richardson 		(queue_conf->schedule_type
64099a2dd95SBruce Richardson 			== RTE_SCHED_TYPE_ORDERED)
64199a2dd95SBruce Richardson 		))
64299a2dd95SBruce Richardson 		return 1;
64399a2dd95SBruce Richardson 	else
64499a2dd95SBruce Richardson 		return 0;
64599a2dd95SBruce Richardson }
64699a2dd95SBruce Richardson 
64799a2dd95SBruce Richardson 
64899a2dd95SBruce Richardson int
64999a2dd95SBruce Richardson rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
65099a2dd95SBruce Richardson 		      const struct rte_event_queue_conf *queue_conf)
65199a2dd95SBruce Richardson {
65299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
65399a2dd95SBruce Richardson 	struct rte_event_queue_conf def_conf;
65499a2dd95SBruce Richardson 
65599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
65699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
65799a2dd95SBruce Richardson 
65899a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
65999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
66099a2dd95SBruce Richardson 		return -EINVAL;
66199a2dd95SBruce Richardson 	}
66299a2dd95SBruce Richardson 
66399a2dd95SBruce Richardson 	/* Check nb_atomic_flows limit */
66499a2dd95SBruce Richardson 	if (is_valid_atomic_queue_conf(queue_conf)) {
66599a2dd95SBruce Richardson 		if (queue_conf->nb_atomic_flows == 0 ||
66699a2dd95SBruce Richardson 		    queue_conf->nb_atomic_flows >
66799a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows) {
66899a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR(
66999a2dd95SBruce Richardson 		"dev%d queue%d Invalid nb_atomic_flows=%d max_flows=%d",
67099a2dd95SBruce Richardson 			dev_id, queue_id, queue_conf->nb_atomic_flows,
67199a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows);
67299a2dd95SBruce Richardson 			return -EINVAL;
67399a2dd95SBruce Richardson 		}
67499a2dd95SBruce Richardson 	}
67599a2dd95SBruce Richardson 
67699a2dd95SBruce Richardson 	/* Check nb_atomic_order_sequences limit */
67799a2dd95SBruce Richardson 	if (is_valid_ordered_queue_conf(queue_conf)) {
67899a2dd95SBruce Richardson 		if (queue_conf->nb_atomic_order_sequences == 0 ||
67999a2dd95SBruce Richardson 		    queue_conf->nb_atomic_order_sequences >
68099a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows) {
68199a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR(
68299a2dd95SBruce Richardson 		"dev%d queue%d Invalid nb_atomic_order_seq=%d max_flows=%d",
68399a2dd95SBruce Richardson 			dev_id, queue_id, queue_conf->nb_atomic_order_sequences,
68499a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows);
68599a2dd95SBruce Richardson 			return -EINVAL;
68699a2dd95SBruce Richardson 		}
68799a2dd95SBruce Richardson 	}
68899a2dd95SBruce Richardson 
68999a2dd95SBruce Richardson 	if (dev->data->dev_started) {
69099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
69199a2dd95SBruce Richardson 		    "device %d must be stopped to allow queue setup", dev_id);
69299a2dd95SBruce Richardson 		return -EBUSY;
69399a2dd95SBruce Richardson 	}
69499a2dd95SBruce Richardson 
69599a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
69699a2dd95SBruce Richardson 
69799a2dd95SBruce Richardson 	if (queue_conf == NULL) {
69899a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf,
69999a2dd95SBruce Richardson 					-ENOTSUP);
70099a2dd95SBruce Richardson 		(*dev->dev_ops->queue_def_conf)(dev, queue_id, &def_conf);
70199a2dd95SBruce Richardson 		queue_conf = &def_conf;
70299a2dd95SBruce Richardson 	}
70399a2dd95SBruce Richardson 
70499a2dd95SBruce Richardson 	dev->data->queues_cfg[queue_id] = *queue_conf;
70599a2dd95SBruce Richardson 	rte_eventdev_trace_queue_setup(dev_id, queue_id, queue_conf);
70699a2dd95SBruce Richardson 	return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
70799a2dd95SBruce Richardson }
70899a2dd95SBruce Richardson 
70999a2dd95SBruce Richardson static inline int
71099a2dd95SBruce Richardson is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
71199a2dd95SBruce Richardson {
71299a2dd95SBruce Richardson 	if (port_id < dev->data->nb_ports)
71399a2dd95SBruce Richardson 		return 1;
71499a2dd95SBruce Richardson 	else
71599a2dd95SBruce Richardson 		return 0;
71699a2dd95SBruce Richardson }
71799a2dd95SBruce Richardson 
71899a2dd95SBruce Richardson int
71999a2dd95SBruce Richardson rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
72099a2dd95SBruce Richardson 				 struct rte_event_port_conf *port_conf)
72199a2dd95SBruce Richardson {
72299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
72399a2dd95SBruce Richardson 
72499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
72599a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
72699a2dd95SBruce Richardson 
72799a2dd95SBruce Richardson 	if (port_conf == NULL)
72899a2dd95SBruce Richardson 		return -EINVAL;
72999a2dd95SBruce Richardson 
73099a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
73199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
73299a2dd95SBruce Richardson 		return -EINVAL;
73399a2dd95SBruce Richardson 	}
73499a2dd95SBruce Richardson 
73599a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf, -ENOTSUP);
73699a2dd95SBruce Richardson 	memset(port_conf, 0, sizeof(struct rte_event_port_conf));
73799a2dd95SBruce Richardson 	(*dev->dev_ops->port_def_conf)(dev, port_id, port_conf);
73899a2dd95SBruce Richardson 	return 0;
73999a2dd95SBruce Richardson }
74099a2dd95SBruce Richardson 
74199a2dd95SBruce Richardson int
74299a2dd95SBruce Richardson rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
74399a2dd95SBruce Richardson 		     const struct rte_event_port_conf *port_conf)
74499a2dd95SBruce Richardson {
74599a2dd95SBruce Richardson 	struct rte_eventdev *dev;
74699a2dd95SBruce Richardson 	struct rte_event_port_conf def_conf;
74799a2dd95SBruce Richardson 	int diag;
74899a2dd95SBruce Richardson 
74999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
75099a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
75199a2dd95SBruce Richardson 
75299a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
75399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
75499a2dd95SBruce Richardson 		return -EINVAL;
75599a2dd95SBruce Richardson 	}
75699a2dd95SBruce Richardson 
75799a2dd95SBruce Richardson 	/* Check new_event_threshold limit */
75899a2dd95SBruce Richardson 	if ((port_conf && !port_conf->new_event_threshold) ||
75999a2dd95SBruce Richardson 			(port_conf && port_conf->new_event_threshold >
76099a2dd95SBruce Richardson 				 dev->data->dev_conf.nb_events_limit)) {
76199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
76299a2dd95SBruce Richardson 		   "dev%d port%d Invalid event_threshold=%d nb_events_limit=%d",
76399a2dd95SBruce Richardson 			dev_id, port_id, port_conf->new_event_threshold,
76499a2dd95SBruce Richardson 			dev->data->dev_conf.nb_events_limit);
76599a2dd95SBruce Richardson 		return -EINVAL;
76699a2dd95SBruce Richardson 	}
76799a2dd95SBruce Richardson 
76899a2dd95SBruce Richardson 	/* Check dequeue_depth limit */
76999a2dd95SBruce Richardson 	if ((port_conf && !port_conf->dequeue_depth) ||
77099a2dd95SBruce Richardson 			(port_conf && port_conf->dequeue_depth >
77199a2dd95SBruce Richardson 		dev->data->dev_conf.nb_event_port_dequeue_depth)) {
77299a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
77399a2dd95SBruce Richardson 		   "dev%d port%d Invalid dequeue depth=%d max_dequeue_depth=%d",
77499a2dd95SBruce Richardson 			dev_id, port_id, port_conf->dequeue_depth,
77599a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_port_dequeue_depth);
77699a2dd95SBruce Richardson 		return -EINVAL;
77799a2dd95SBruce Richardson 	}
77899a2dd95SBruce Richardson 
77999a2dd95SBruce Richardson 	/* Check enqueue_depth limit */
78099a2dd95SBruce Richardson 	if ((port_conf && !port_conf->enqueue_depth) ||
78199a2dd95SBruce Richardson 			(port_conf && port_conf->enqueue_depth >
78299a2dd95SBruce Richardson 		dev->data->dev_conf.nb_event_port_enqueue_depth)) {
78399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
78499a2dd95SBruce Richardson 		   "dev%d port%d Invalid enqueue depth=%d max_enqueue_depth=%d",
78599a2dd95SBruce Richardson 			dev_id, port_id, port_conf->enqueue_depth,
78699a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_port_enqueue_depth);
78799a2dd95SBruce Richardson 		return -EINVAL;
78899a2dd95SBruce Richardson 	}
78999a2dd95SBruce Richardson 
79099a2dd95SBruce Richardson 	if (port_conf &&
79199a2dd95SBruce Richardson 	    (port_conf->event_port_cfg & RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL) &&
79299a2dd95SBruce Richardson 	    !(dev->data->event_dev_cap &
79399a2dd95SBruce Richardson 	      RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)) {
79499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
79599a2dd95SBruce Richardson 		   "dev%d port%d Implicit release disable not supported",
79699a2dd95SBruce Richardson 			dev_id, port_id);
79799a2dd95SBruce Richardson 		return -EINVAL;
79899a2dd95SBruce Richardson 	}
79999a2dd95SBruce Richardson 
80099a2dd95SBruce Richardson 	if (dev->data->dev_started) {
80199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
80299a2dd95SBruce Richardson 		    "device %d must be stopped to allow port setup", dev_id);
80399a2dd95SBruce Richardson 		return -EBUSY;
80499a2dd95SBruce Richardson 	}
80599a2dd95SBruce Richardson 
80699a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_setup, -ENOTSUP);
80799a2dd95SBruce Richardson 
80899a2dd95SBruce Richardson 	if (port_conf == NULL) {
80999a2dd95SBruce Richardson 		RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf,
81099a2dd95SBruce Richardson 					-ENOTSUP);
81199a2dd95SBruce Richardson 		(*dev->dev_ops->port_def_conf)(dev, port_id, &def_conf);
81299a2dd95SBruce Richardson 		port_conf = &def_conf;
81399a2dd95SBruce Richardson 	}
81499a2dd95SBruce Richardson 
81599a2dd95SBruce Richardson 	dev->data->ports_cfg[port_id] = *port_conf;
81699a2dd95SBruce Richardson 
81799a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_setup)(dev, port_id, port_conf);
81899a2dd95SBruce Richardson 
81999a2dd95SBruce Richardson 	/* Unlink all the queues from this port(default state after setup) */
82099a2dd95SBruce Richardson 	if (!diag)
82199a2dd95SBruce Richardson 		diag = rte_event_port_unlink(dev_id, port_id, NULL, 0);
82299a2dd95SBruce Richardson 
82399a2dd95SBruce Richardson 	rte_eventdev_trace_port_setup(dev_id, port_id, port_conf, diag);
82499a2dd95SBruce Richardson 	if (diag < 0)
82599a2dd95SBruce Richardson 		return diag;
82699a2dd95SBruce Richardson 
82799a2dd95SBruce Richardson 	return 0;
82899a2dd95SBruce Richardson }
82999a2dd95SBruce Richardson 
83099a2dd95SBruce Richardson int
83199a2dd95SBruce Richardson rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
83299a2dd95SBruce Richardson 		       uint32_t *attr_value)
83399a2dd95SBruce Richardson {
83499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
83599a2dd95SBruce Richardson 
83699a2dd95SBruce Richardson 	if (!attr_value)
83799a2dd95SBruce Richardson 		return -EINVAL;
83899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
83999a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
84099a2dd95SBruce Richardson 
84199a2dd95SBruce Richardson 	switch (attr_id) {
84299a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_PORT_COUNT:
84399a2dd95SBruce Richardson 		*attr_value = dev->data->nb_ports;
84499a2dd95SBruce Richardson 		break;
84599a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
84699a2dd95SBruce Richardson 		*attr_value = dev->data->nb_queues;
84799a2dd95SBruce Richardson 		break;
84899a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_STARTED:
84999a2dd95SBruce Richardson 		*attr_value = dev->data->dev_started;
85099a2dd95SBruce Richardson 		break;
85199a2dd95SBruce Richardson 	default:
85299a2dd95SBruce Richardson 		return -EINVAL;
85399a2dd95SBruce Richardson 	}
85499a2dd95SBruce Richardson 
85599a2dd95SBruce Richardson 	return 0;
85699a2dd95SBruce Richardson }
85799a2dd95SBruce Richardson 
85899a2dd95SBruce Richardson int
85999a2dd95SBruce Richardson rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
86099a2dd95SBruce Richardson 			uint32_t *attr_value)
86199a2dd95SBruce Richardson {
86299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
86399a2dd95SBruce Richardson 
86499a2dd95SBruce Richardson 	if (!attr_value)
86599a2dd95SBruce Richardson 		return -EINVAL;
86699a2dd95SBruce Richardson 
86799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
86899a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
86999a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
87099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
87199a2dd95SBruce Richardson 		return -EINVAL;
87299a2dd95SBruce Richardson 	}
87399a2dd95SBruce Richardson 
87499a2dd95SBruce Richardson 	switch (attr_id) {
87599a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
87699a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].enqueue_depth;
87799a2dd95SBruce Richardson 		break;
87899a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
87999a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].dequeue_depth;
88099a2dd95SBruce Richardson 		break;
88199a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD:
88299a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].new_event_threshold;
88399a2dd95SBruce Richardson 		break;
88499a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE:
88599a2dd95SBruce Richardson 	{
88699a2dd95SBruce Richardson 		uint32_t config;
88799a2dd95SBruce Richardson 
88899a2dd95SBruce Richardson 		config = dev->data->ports_cfg[port_id].event_port_cfg;
88999a2dd95SBruce Richardson 		*attr_value = !!(config & RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL);
89099a2dd95SBruce Richardson 		break;
89199a2dd95SBruce Richardson 	}
89299a2dd95SBruce Richardson 	default:
89399a2dd95SBruce Richardson 		return -EINVAL;
89499a2dd95SBruce Richardson 	};
89599a2dd95SBruce Richardson 	return 0;
89699a2dd95SBruce Richardson }
89799a2dd95SBruce Richardson 
89899a2dd95SBruce Richardson int
89999a2dd95SBruce Richardson rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
90099a2dd95SBruce Richardson 			uint32_t *attr_value)
90199a2dd95SBruce Richardson {
90299a2dd95SBruce Richardson 	struct rte_event_queue_conf *conf;
90399a2dd95SBruce Richardson 	struct rte_eventdev *dev;
90499a2dd95SBruce Richardson 
90599a2dd95SBruce Richardson 	if (!attr_value)
90699a2dd95SBruce Richardson 		return -EINVAL;
90799a2dd95SBruce Richardson 
90899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
90999a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
91099a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
91199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
91299a2dd95SBruce Richardson 		return -EINVAL;
91399a2dd95SBruce Richardson 	}
91499a2dd95SBruce Richardson 
91599a2dd95SBruce Richardson 	conf = &dev->data->queues_cfg[queue_id];
91699a2dd95SBruce Richardson 
91799a2dd95SBruce Richardson 	switch (attr_id) {
91899a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_PRIORITY:
91999a2dd95SBruce Richardson 		*attr_value = RTE_EVENT_DEV_PRIORITY_NORMAL;
92099a2dd95SBruce Richardson 		if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
92199a2dd95SBruce Richardson 			*attr_value = conf->priority;
92299a2dd95SBruce Richardson 		break;
92399a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS:
92499a2dd95SBruce Richardson 		*attr_value = conf->nb_atomic_flows;
92599a2dd95SBruce Richardson 		break;
92699a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES:
92799a2dd95SBruce Richardson 		*attr_value = conf->nb_atomic_order_sequences;
92899a2dd95SBruce Richardson 		break;
92999a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG:
93099a2dd95SBruce Richardson 		*attr_value = conf->event_queue_cfg;
93199a2dd95SBruce Richardson 		break;
93299a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE:
93399a2dd95SBruce Richardson 		if (conf->event_queue_cfg & RTE_EVENT_QUEUE_CFG_ALL_TYPES)
93499a2dd95SBruce Richardson 			return -EOVERFLOW;
93599a2dd95SBruce Richardson 
93699a2dd95SBruce Richardson 		*attr_value = conf->schedule_type;
93799a2dd95SBruce Richardson 		break;
93899a2dd95SBruce Richardson 	default:
93999a2dd95SBruce Richardson 		return -EINVAL;
94099a2dd95SBruce Richardson 	};
94199a2dd95SBruce Richardson 	return 0;
94299a2dd95SBruce Richardson }
94399a2dd95SBruce Richardson 
94499a2dd95SBruce Richardson int
94599a2dd95SBruce Richardson rte_event_port_link(uint8_t dev_id, uint8_t port_id,
94699a2dd95SBruce Richardson 		    const uint8_t queues[], const uint8_t priorities[],
94799a2dd95SBruce Richardson 		    uint16_t nb_links)
94899a2dd95SBruce Richardson {
94999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
95099a2dd95SBruce Richardson 	uint8_t queues_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
95199a2dd95SBruce Richardson 	uint8_t priorities_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
95299a2dd95SBruce Richardson 	uint16_t *links_map;
95399a2dd95SBruce Richardson 	int i, diag;
95499a2dd95SBruce Richardson 
95599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
95699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
95799a2dd95SBruce Richardson 
95899a2dd95SBruce Richardson 	if (*dev->dev_ops->port_link == NULL) {
95999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Function not supported\n");
96099a2dd95SBruce Richardson 		rte_errno = ENOTSUP;
96199a2dd95SBruce Richardson 		return 0;
96299a2dd95SBruce Richardson 	}
96399a2dd95SBruce Richardson 
96499a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
96599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
96699a2dd95SBruce Richardson 		rte_errno = EINVAL;
96799a2dd95SBruce Richardson 		return 0;
96899a2dd95SBruce Richardson 	}
96999a2dd95SBruce Richardson 
97099a2dd95SBruce Richardson 	if (queues == NULL) {
97199a2dd95SBruce Richardson 		for (i = 0; i < dev->data->nb_queues; i++)
97299a2dd95SBruce Richardson 			queues_list[i] = i;
97399a2dd95SBruce Richardson 
97499a2dd95SBruce Richardson 		queues = queues_list;
97599a2dd95SBruce Richardson 		nb_links = dev->data->nb_queues;
97699a2dd95SBruce Richardson 	}
97799a2dd95SBruce Richardson 
97899a2dd95SBruce Richardson 	if (priorities == NULL) {
97999a2dd95SBruce Richardson 		for (i = 0; i < nb_links; i++)
98099a2dd95SBruce Richardson 			priorities_list[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
98199a2dd95SBruce Richardson 
98299a2dd95SBruce Richardson 		priorities = priorities_list;
98399a2dd95SBruce Richardson 	}
98499a2dd95SBruce Richardson 
98599a2dd95SBruce Richardson 	for (i = 0; i < nb_links; i++)
98699a2dd95SBruce Richardson 		if (queues[i] >= dev->data->nb_queues) {
98799a2dd95SBruce Richardson 			rte_errno = EINVAL;
98899a2dd95SBruce Richardson 			return 0;
98999a2dd95SBruce Richardson 		}
99099a2dd95SBruce Richardson 
99199a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
99299a2dd95SBruce Richardson 						queues, priorities, nb_links);
99399a2dd95SBruce Richardson 	if (diag < 0)
99499a2dd95SBruce Richardson 		return diag;
99599a2dd95SBruce Richardson 
99699a2dd95SBruce Richardson 	links_map = dev->data->links_map;
99799a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
99899a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
99999a2dd95SBruce Richardson 	for (i = 0; i < diag; i++)
100099a2dd95SBruce Richardson 		links_map[queues[i]] = (uint8_t)priorities[i];
100199a2dd95SBruce Richardson 
100299a2dd95SBruce Richardson 	rte_eventdev_trace_port_link(dev_id, port_id, nb_links, diag);
100399a2dd95SBruce Richardson 	return diag;
100499a2dd95SBruce Richardson }
100599a2dd95SBruce Richardson 
100699a2dd95SBruce Richardson int
100799a2dd95SBruce Richardson rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
100899a2dd95SBruce Richardson 		      uint8_t queues[], uint16_t nb_unlinks)
100999a2dd95SBruce Richardson {
101099a2dd95SBruce Richardson 	struct rte_eventdev *dev;
101199a2dd95SBruce Richardson 	uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
101299a2dd95SBruce Richardson 	int i, diag, j;
101399a2dd95SBruce Richardson 	uint16_t *links_map;
101499a2dd95SBruce Richardson 
101599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
101699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
101799a2dd95SBruce Richardson 
101899a2dd95SBruce Richardson 	if (*dev->dev_ops->port_unlink == NULL) {
101999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Function not supported");
102099a2dd95SBruce Richardson 		rte_errno = ENOTSUP;
102199a2dd95SBruce Richardson 		return 0;
102299a2dd95SBruce Richardson 	}
102399a2dd95SBruce Richardson 
102499a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
102599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
102699a2dd95SBruce Richardson 		rte_errno = EINVAL;
102799a2dd95SBruce Richardson 		return 0;
102899a2dd95SBruce Richardson 	}
102999a2dd95SBruce Richardson 
103099a2dd95SBruce Richardson 	links_map = dev->data->links_map;
103199a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
103299a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
103399a2dd95SBruce Richardson 
103499a2dd95SBruce Richardson 	if (queues == NULL) {
103599a2dd95SBruce Richardson 		j = 0;
103699a2dd95SBruce Richardson 		for (i = 0; i < dev->data->nb_queues; i++) {
103799a2dd95SBruce Richardson 			if (links_map[i] !=
103899a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
103999a2dd95SBruce Richardson 				all_queues[j] = i;
104099a2dd95SBruce Richardson 				j++;
104199a2dd95SBruce Richardson 			}
104299a2dd95SBruce Richardson 		}
104399a2dd95SBruce Richardson 		queues = all_queues;
104499a2dd95SBruce Richardson 	} else {
104599a2dd95SBruce Richardson 		for (j = 0; j < nb_unlinks; j++) {
104699a2dd95SBruce Richardson 			if (links_map[queues[j]] ==
104799a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID)
104899a2dd95SBruce Richardson 				break;
104999a2dd95SBruce Richardson 		}
105099a2dd95SBruce Richardson 	}
105199a2dd95SBruce Richardson 
105299a2dd95SBruce Richardson 	nb_unlinks = j;
105399a2dd95SBruce Richardson 	for (i = 0; i < nb_unlinks; i++)
105499a2dd95SBruce Richardson 		if (queues[i] >= dev->data->nb_queues) {
105599a2dd95SBruce Richardson 			rte_errno = EINVAL;
105699a2dd95SBruce Richardson 			return 0;
105799a2dd95SBruce Richardson 		}
105899a2dd95SBruce Richardson 
105999a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
106099a2dd95SBruce Richardson 					queues, nb_unlinks);
106199a2dd95SBruce Richardson 
106299a2dd95SBruce Richardson 	if (diag < 0)
106399a2dd95SBruce Richardson 		return diag;
106499a2dd95SBruce Richardson 
106599a2dd95SBruce Richardson 	for (i = 0; i < diag; i++)
106699a2dd95SBruce Richardson 		links_map[queues[i]] = EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
106799a2dd95SBruce Richardson 
106899a2dd95SBruce Richardson 	rte_eventdev_trace_port_unlink(dev_id, port_id, nb_unlinks, diag);
106999a2dd95SBruce Richardson 	return diag;
107099a2dd95SBruce Richardson }
107199a2dd95SBruce Richardson 
107299a2dd95SBruce Richardson int
107399a2dd95SBruce Richardson rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id)
107499a2dd95SBruce Richardson {
107599a2dd95SBruce Richardson 	struct rte_eventdev *dev;
107699a2dd95SBruce Richardson 
107799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
107899a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
107999a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
108099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
108199a2dd95SBruce Richardson 		return -EINVAL;
108299a2dd95SBruce Richardson 	}
108399a2dd95SBruce Richardson 
108499a2dd95SBruce Richardson 	/* Return 0 if the PMD does not implement unlinks in progress.
108599a2dd95SBruce Richardson 	 * This allows PMDs which handle unlink synchronously to not implement
108699a2dd95SBruce Richardson 	 * this function at all.
108799a2dd95SBruce Richardson 	 */
108899a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlinks_in_progress, 0);
108999a2dd95SBruce Richardson 
109099a2dd95SBruce Richardson 	return (*dev->dev_ops->port_unlinks_in_progress)(dev,
109199a2dd95SBruce Richardson 			dev->data->ports[port_id]);
109299a2dd95SBruce Richardson }
109399a2dd95SBruce Richardson 
109499a2dd95SBruce Richardson int
109599a2dd95SBruce Richardson rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
109699a2dd95SBruce Richardson 			 uint8_t queues[], uint8_t priorities[])
109799a2dd95SBruce Richardson {
109899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
109999a2dd95SBruce Richardson 	uint16_t *links_map;
110099a2dd95SBruce Richardson 	int i, count = 0;
110199a2dd95SBruce Richardson 
110299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
110399a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
110499a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
110599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
110699a2dd95SBruce Richardson 		return -EINVAL;
110799a2dd95SBruce Richardson 	}
110899a2dd95SBruce Richardson 
110999a2dd95SBruce Richardson 	links_map = dev->data->links_map;
111099a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
111199a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
111299a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_queues; i++) {
111399a2dd95SBruce Richardson 		if (links_map[i] != EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
111499a2dd95SBruce Richardson 			queues[count] = i;
111599a2dd95SBruce Richardson 			priorities[count] = (uint8_t)links_map[i];
111699a2dd95SBruce Richardson 			++count;
111799a2dd95SBruce Richardson 		}
111899a2dd95SBruce Richardson 	}
111999a2dd95SBruce Richardson 	return count;
112099a2dd95SBruce Richardson }
112199a2dd95SBruce Richardson 
112299a2dd95SBruce Richardson int
112399a2dd95SBruce Richardson rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
112499a2dd95SBruce Richardson 				 uint64_t *timeout_ticks)
112599a2dd95SBruce Richardson {
112699a2dd95SBruce Richardson 	struct rte_eventdev *dev;
112799a2dd95SBruce Richardson 
112899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
112999a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
113099a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timeout_ticks, -ENOTSUP);
113199a2dd95SBruce Richardson 
113299a2dd95SBruce Richardson 	if (timeout_ticks == NULL)
113399a2dd95SBruce Richardson 		return -EINVAL;
113499a2dd95SBruce Richardson 
113599a2dd95SBruce Richardson 	return (*dev->dev_ops->timeout_ticks)(dev, ns, timeout_ticks);
113699a2dd95SBruce Richardson }
113799a2dd95SBruce Richardson 
113899a2dd95SBruce Richardson int
113999a2dd95SBruce Richardson rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id)
114099a2dd95SBruce Richardson {
114199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
114299a2dd95SBruce Richardson 
114399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
114499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
114599a2dd95SBruce Richardson 
114699a2dd95SBruce Richardson 	if (service_id == NULL)
114799a2dd95SBruce Richardson 		return -EINVAL;
114899a2dd95SBruce Richardson 
114999a2dd95SBruce Richardson 	if (dev->data->service_inited)
115099a2dd95SBruce Richardson 		*service_id = dev->data->service_id;
115199a2dd95SBruce Richardson 
115299a2dd95SBruce Richardson 	return dev->data->service_inited ? 0 : -ESRCH;
115399a2dd95SBruce Richardson }
115499a2dd95SBruce Richardson 
115599a2dd95SBruce Richardson int
115699a2dd95SBruce Richardson rte_event_dev_dump(uint8_t dev_id, FILE *f)
115799a2dd95SBruce Richardson {
115899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
115999a2dd95SBruce Richardson 
116099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
116199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
116299a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dump, -ENOTSUP);
116399a2dd95SBruce Richardson 	if (f == NULL)
116499a2dd95SBruce Richardson 		return -EINVAL;
116599a2dd95SBruce Richardson 
116699a2dd95SBruce Richardson 	(*dev->dev_ops->dump)(dev, f);
116799a2dd95SBruce Richardson 	return 0;
116899a2dd95SBruce Richardson 
116999a2dd95SBruce Richardson }
117099a2dd95SBruce Richardson 
117199a2dd95SBruce Richardson static int
117299a2dd95SBruce Richardson xstats_get_count(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
117399a2dd95SBruce Richardson 		uint8_t queue_port_id)
117499a2dd95SBruce Richardson {
117599a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
117699a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get_names != NULL)
117799a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get_names)(dev, mode,
117899a2dd95SBruce Richardson 							queue_port_id,
117999a2dd95SBruce Richardson 							NULL, NULL, 0);
118099a2dd95SBruce Richardson 	return 0;
118199a2dd95SBruce Richardson }
118299a2dd95SBruce Richardson 
118399a2dd95SBruce Richardson int
118499a2dd95SBruce Richardson rte_event_dev_xstats_names_get(uint8_t dev_id,
118599a2dd95SBruce Richardson 		enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
118699a2dd95SBruce Richardson 		struct rte_event_dev_xstats_name *xstats_names,
118799a2dd95SBruce Richardson 		unsigned int *ids, unsigned int size)
118899a2dd95SBruce Richardson {
118999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
119099a2dd95SBruce Richardson 	const int cnt_expected_entries = xstats_get_count(dev_id, mode,
119199a2dd95SBruce Richardson 							  queue_port_id);
119299a2dd95SBruce Richardson 	if (xstats_names == NULL || cnt_expected_entries < 0 ||
119399a2dd95SBruce Richardson 			(int)size < cnt_expected_entries)
119499a2dd95SBruce Richardson 		return cnt_expected_entries;
119599a2dd95SBruce Richardson 
119699a2dd95SBruce Richardson 	/* dev_id checked above */
119799a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
119899a2dd95SBruce Richardson 
119999a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get_names != NULL)
120099a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get_names)(dev, mode,
120199a2dd95SBruce Richardson 				queue_port_id, xstats_names, ids, size);
120299a2dd95SBruce Richardson 
120399a2dd95SBruce Richardson 	return -ENOTSUP;
120499a2dd95SBruce Richardson }
120599a2dd95SBruce Richardson 
120699a2dd95SBruce Richardson /* retrieve eventdev extended statistics */
120799a2dd95SBruce Richardson int
120899a2dd95SBruce Richardson rte_event_dev_xstats_get(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
120999a2dd95SBruce Richardson 		uint8_t queue_port_id, const unsigned int ids[],
121099a2dd95SBruce Richardson 		uint64_t values[], unsigned int n)
121199a2dd95SBruce Richardson {
121299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
121399a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
121499a2dd95SBruce Richardson 
121599a2dd95SBruce Richardson 	/* implemented by the driver */
121699a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get != NULL)
121799a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get)(dev, mode, queue_port_id,
121899a2dd95SBruce Richardson 				ids, values, n);
121999a2dd95SBruce Richardson 	return -ENOTSUP;
122099a2dd95SBruce Richardson }
122199a2dd95SBruce Richardson 
122299a2dd95SBruce Richardson uint64_t
122399a2dd95SBruce Richardson rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
122499a2dd95SBruce Richardson 		unsigned int *id)
122599a2dd95SBruce Richardson {
122699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, 0);
122799a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
122899a2dd95SBruce Richardson 	unsigned int temp = -1;
122999a2dd95SBruce Richardson 
123099a2dd95SBruce Richardson 	if (id != NULL)
123199a2dd95SBruce Richardson 		*id = (unsigned int)-1;
123299a2dd95SBruce Richardson 	else
123399a2dd95SBruce Richardson 		id = &temp; /* ensure driver never gets a NULL value */
123499a2dd95SBruce Richardson 
123599a2dd95SBruce Richardson 	/* implemented by driver */
123699a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get_by_name != NULL)
123799a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get_by_name)(dev, name, id);
123899a2dd95SBruce Richardson 	return -ENOTSUP;
123999a2dd95SBruce Richardson }
124099a2dd95SBruce Richardson 
124199a2dd95SBruce Richardson int rte_event_dev_xstats_reset(uint8_t dev_id,
124299a2dd95SBruce Richardson 		enum rte_event_dev_xstats_mode mode, int16_t queue_port_id,
124399a2dd95SBruce Richardson 		const uint32_t ids[], uint32_t nb_ids)
124499a2dd95SBruce Richardson {
124599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
124699a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
124799a2dd95SBruce Richardson 
124899a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_reset != NULL)
124999a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_reset)(dev, mode, queue_port_id,
125099a2dd95SBruce Richardson 							ids, nb_ids);
125199a2dd95SBruce Richardson 	return -ENOTSUP;
125299a2dd95SBruce Richardson }
125399a2dd95SBruce Richardson 
125499a2dd95SBruce Richardson int rte_event_pmd_selftest_seqn_dynfield_offset = -1;
125599a2dd95SBruce Richardson 
125699a2dd95SBruce Richardson int rte_event_dev_selftest(uint8_t dev_id)
125799a2dd95SBruce Richardson {
125899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
125999a2dd95SBruce Richardson 	static const struct rte_mbuf_dynfield test_seqn_dynfield_desc = {
126099a2dd95SBruce Richardson 		.name = "rte_event_pmd_selftest_seqn_dynfield",
126199a2dd95SBruce Richardson 		.size = sizeof(rte_event_pmd_selftest_seqn_t),
126299a2dd95SBruce Richardson 		.align = __alignof__(rte_event_pmd_selftest_seqn_t),
126399a2dd95SBruce Richardson 	};
126499a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
126599a2dd95SBruce Richardson 
126699a2dd95SBruce Richardson 	if (dev->dev_ops->dev_selftest != NULL) {
126799a2dd95SBruce Richardson 		rte_event_pmd_selftest_seqn_dynfield_offset =
126899a2dd95SBruce Richardson 			rte_mbuf_dynfield_register(&test_seqn_dynfield_desc);
126999a2dd95SBruce Richardson 		if (rte_event_pmd_selftest_seqn_dynfield_offset < 0)
127099a2dd95SBruce Richardson 			return -ENOMEM;
127199a2dd95SBruce Richardson 		return (*dev->dev_ops->dev_selftest)();
127299a2dd95SBruce Richardson 	}
127399a2dd95SBruce Richardson 	return -ENOTSUP;
127499a2dd95SBruce Richardson }
127599a2dd95SBruce Richardson 
127699a2dd95SBruce Richardson struct rte_mempool *
127799a2dd95SBruce Richardson rte_event_vector_pool_create(const char *name, unsigned int n,
127899a2dd95SBruce Richardson 			     unsigned int cache_size, uint16_t nb_elem,
127999a2dd95SBruce Richardson 			     int socket_id)
128099a2dd95SBruce Richardson {
128199a2dd95SBruce Richardson 	const char *mp_ops_name;
128299a2dd95SBruce Richardson 	struct rte_mempool *mp;
128399a2dd95SBruce Richardson 	unsigned int elt_sz;
128499a2dd95SBruce Richardson 	int ret;
128599a2dd95SBruce Richardson 
128699a2dd95SBruce Richardson 	if (!nb_elem) {
128799a2dd95SBruce Richardson 		RTE_LOG(ERR, EVENTDEV,
128899a2dd95SBruce Richardson 			"Invalid number of elements=%d requested\n", nb_elem);
128999a2dd95SBruce Richardson 		rte_errno = EINVAL;
129099a2dd95SBruce Richardson 		return NULL;
129199a2dd95SBruce Richardson 	}
129299a2dd95SBruce Richardson 
129399a2dd95SBruce Richardson 	elt_sz =
129499a2dd95SBruce Richardson 		sizeof(struct rte_event_vector) + (nb_elem * sizeof(uintptr_t));
129599a2dd95SBruce Richardson 	mp = rte_mempool_create_empty(name, n, elt_sz, cache_size, 0, socket_id,
129699a2dd95SBruce Richardson 				      0);
129799a2dd95SBruce Richardson 	if (mp == NULL)
129899a2dd95SBruce Richardson 		return NULL;
129999a2dd95SBruce Richardson 
130099a2dd95SBruce Richardson 	mp_ops_name = rte_mbuf_best_mempool_ops();
130199a2dd95SBruce Richardson 	ret = rte_mempool_set_ops_byname(mp, mp_ops_name, NULL);
130299a2dd95SBruce Richardson 	if (ret != 0) {
130399a2dd95SBruce Richardson 		RTE_LOG(ERR, EVENTDEV, "error setting mempool handler\n");
130499a2dd95SBruce Richardson 		goto err;
130599a2dd95SBruce Richardson 	}
130699a2dd95SBruce Richardson 
130799a2dd95SBruce Richardson 	ret = rte_mempool_populate_default(mp);
130899a2dd95SBruce Richardson 	if (ret < 0)
130999a2dd95SBruce Richardson 		goto err;
131099a2dd95SBruce Richardson 
131199a2dd95SBruce Richardson 	return mp;
131299a2dd95SBruce Richardson err:
131399a2dd95SBruce Richardson 	rte_mempool_free(mp);
131499a2dd95SBruce Richardson 	rte_errno = -ret;
131599a2dd95SBruce Richardson 	return NULL;
131699a2dd95SBruce Richardson }
131799a2dd95SBruce Richardson 
131899a2dd95SBruce Richardson int
131999a2dd95SBruce Richardson rte_event_dev_start(uint8_t dev_id)
132099a2dd95SBruce Richardson {
132199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
132299a2dd95SBruce Richardson 	int diag;
132399a2dd95SBruce Richardson 
132499a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
132599a2dd95SBruce Richardson 
132699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
132799a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
132899a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
132999a2dd95SBruce Richardson 
133099a2dd95SBruce Richardson 	if (dev->data->dev_started != 0) {
133199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already started",
133299a2dd95SBruce Richardson 			dev_id);
133399a2dd95SBruce Richardson 		return 0;
133499a2dd95SBruce Richardson 	}
133599a2dd95SBruce Richardson 
133699a2dd95SBruce Richardson 	diag = (*dev->dev_ops->dev_start)(dev);
133799a2dd95SBruce Richardson 	rte_eventdev_trace_start(dev_id, diag);
133899a2dd95SBruce Richardson 	if (diag == 0)
133999a2dd95SBruce Richardson 		dev->data->dev_started = 1;
134099a2dd95SBruce Richardson 	else
134199a2dd95SBruce Richardson 		return diag;
134299a2dd95SBruce Richardson 
134399a2dd95SBruce Richardson 	return 0;
134499a2dd95SBruce Richardson }
134599a2dd95SBruce Richardson 
134699a2dd95SBruce Richardson int
134799a2dd95SBruce Richardson rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
134899a2dd95SBruce Richardson 		eventdev_stop_flush_t callback, void *userdata)
134999a2dd95SBruce Richardson {
135099a2dd95SBruce Richardson 	struct rte_eventdev *dev;
135199a2dd95SBruce Richardson 
135299a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Stop flush register dev_id=%" PRIu8, dev_id);
135399a2dd95SBruce Richardson 
135499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
135599a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
135699a2dd95SBruce Richardson 
135799a2dd95SBruce Richardson 	dev->dev_ops->dev_stop_flush = callback;
135899a2dd95SBruce Richardson 	dev->data->dev_stop_flush_arg = userdata;
135999a2dd95SBruce Richardson 
136099a2dd95SBruce Richardson 	return 0;
136199a2dd95SBruce Richardson }
136299a2dd95SBruce Richardson 
136399a2dd95SBruce Richardson void
136499a2dd95SBruce Richardson rte_event_dev_stop(uint8_t dev_id)
136599a2dd95SBruce Richardson {
136699a2dd95SBruce Richardson 	struct rte_eventdev *dev;
136799a2dd95SBruce Richardson 
136899a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Stop dev_id=%" PRIu8, dev_id);
136999a2dd95SBruce Richardson 
137099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
137199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
137299a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
137399a2dd95SBruce Richardson 
137499a2dd95SBruce Richardson 	if (dev->data->dev_started == 0) {
137599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already stopped",
137699a2dd95SBruce Richardson 			dev_id);
137799a2dd95SBruce Richardson 		return;
137899a2dd95SBruce Richardson 	}
137999a2dd95SBruce Richardson 
138099a2dd95SBruce Richardson 	dev->data->dev_started = 0;
138199a2dd95SBruce Richardson 	(*dev->dev_ops->dev_stop)(dev);
138299a2dd95SBruce Richardson 	rte_eventdev_trace_stop(dev_id);
138399a2dd95SBruce Richardson }
138499a2dd95SBruce Richardson 
138599a2dd95SBruce Richardson int
138699a2dd95SBruce Richardson rte_event_dev_close(uint8_t dev_id)
138799a2dd95SBruce Richardson {
138899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
138999a2dd95SBruce Richardson 
139099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
139199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
139299a2dd95SBruce Richardson 	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
139399a2dd95SBruce Richardson 
139499a2dd95SBruce Richardson 	/* Device must be stopped before it can be closed */
139599a2dd95SBruce Richardson 	if (dev->data->dev_started == 1) {
139699a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device %u must be stopped before closing",
139799a2dd95SBruce Richardson 				dev_id);
139899a2dd95SBruce Richardson 		return -EBUSY;
139999a2dd95SBruce Richardson 	}
140099a2dd95SBruce Richardson 
140199a2dd95SBruce Richardson 	rte_eventdev_trace_close(dev_id);
140299a2dd95SBruce Richardson 	return (*dev->dev_ops->dev_close)(dev);
140399a2dd95SBruce Richardson }
140499a2dd95SBruce Richardson 
140599a2dd95SBruce Richardson static inline int
140699a2dd95SBruce Richardson rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
140799a2dd95SBruce Richardson 		int socket_id)
140899a2dd95SBruce Richardson {
140999a2dd95SBruce Richardson 	char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
141099a2dd95SBruce Richardson 	const struct rte_memzone *mz;
141199a2dd95SBruce Richardson 	int n;
141299a2dd95SBruce Richardson 
141399a2dd95SBruce Richardson 	/* Generate memzone name */
141499a2dd95SBruce Richardson 	n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
141599a2dd95SBruce Richardson 	if (n >= (int)sizeof(mz_name))
141699a2dd95SBruce Richardson 		return -EINVAL;
141799a2dd95SBruce Richardson 
141899a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
141999a2dd95SBruce Richardson 		mz = rte_memzone_reserve(mz_name,
142099a2dd95SBruce Richardson 				sizeof(struct rte_eventdev_data),
142199a2dd95SBruce Richardson 				socket_id, 0);
142299a2dd95SBruce Richardson 	} else
142399a2dd95SBruce Richardson 		mz = rte_memzone_lookup(mz_name);
142499a2dd95SBruce Richardson 
142599a2dd95SBruce Richardson 	if (mz == NULL)
142699a2dd95SBruce Richardson 		return -ENOMEM;
142799a2dd95SBruce Richardson 
142899a2dd95SBruce Richardson 	*data = mz->addr;
142999a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
143099a2dd95SBruce Richardson 		memset(*data, 0, sizeof(struct rte_eventdev_data));
143199a2dd95SBruce Richardson 
143299a2dd95SBruce Richardson 	return 0;
143399a2dd95SBruce Richardson }
143499a2dd95SBruce Richardson 
143599a2dd95SBruce Richardson static inline uint8_t
143699a2dd95SBruce Richardson rte_eventdev_find_free_device_index(void)
143799a2dd95SBruce Richardson {
143899a2dd95SBruce Richardson 	uint8_t dev_id;
143999a2dd95SBruce Richardson 
144099a2dd95SBruce Richardson 	for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
144199a2dd95SBruce Richardson 		if (rte_eventdevs[dev_id].attached ==
144299a2dd95SBruce Richardson 				RTE_EVENTDEV_DETACHED)
144399a2dd95SBruce Richardson 			return dev_id;
144499a2dd95SBruce Richardson 	}
144599a2dd95SBruce Richardson 	return RTE_EVENT_MAX_DEVS;
144699a2dd95SBruce Richardson }
144799a2dd95SBruce Richardson 
144899a2dd95SBruce Richardson static uint16_t
144999a2dd95SBruce Richardson rte_event_tx_adapter_enqueue(__rte_unused void *port,
145099a2dd95SBruce Richardson 			__rte_unused struct rte_event ev[],
145199a2dd95SBruce Richardson 			__rte_unused uint16_t nb_events)
145299a2dd95SBruce Richardson {
145399a2dd95SBruce Richardson 	rte_errno = ENOTSUP;
145499a2dd95SBruce Richardson 	return 0;
145599a2dd95SBruce Richardson }
145699a2dd95SBruce Richardson 
145799a2dd95SBruce Richardson static uint16_t
145899a2dd95SBruce Richardson rte_event_crypto_adapter_enqueue(__rte_unused void *port,
145999a2dd95SBruce Richardson 			__rte_unused struct rte_event ev[],
146099a2dd95SBruce Richardson 			__rte_unused uint16_t nb_events)
146199a2dd95SBruce Richardson {
146299a2dd95SBruce Richardson 	rte_errno = ENOTSUP;
146399a2dd95SBruce Richardson 	return 0;
146499a2dd95SBruce Richardson }
146599a2dd95SBruce Richardson 
146699a2dd95SBruce Richardson struct rte_eventdev *
146799a2dd95SBruce Richardson rte_event_pmd_allocate(const char *name, int socket_id)
146899a2dd95SBruce Richardson {
146999a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
147099a2dd95SBruce Richardson 	uint8_t dev_id;
147199a2dd95SBruce Richardson 
147299a2dd95SBruce Richardson 	if (rte_event_pmd_get_named_dev(name) != NULL) {
147399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Event device with name %s already "
147499a2dd95SBruce Richardson 				"allocated!", name);
147599a2dd95SBruce Richardson 		return NULL;
147699a2dd95SBruce Richardson 	}
147799a2dd95SBruce Richardson 
147899a2dd95SBruce Richardson 	dev_id = rte_eventdev_find_free_device_index();
147999a2dd95SBruce Richardson 	if (dev_id == RTE_EVENT_MAX_DEVS) {
148099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
148199a2dd95SBruce Richardson 		return NULL;
148299a2dd95SBruce Richardson 	}
148399a2dd95SBruce Richardson 
148499a2dd95SBruce Richardson 	eventdev = &rte_eventdevs[dev_id];
148599a2dd95SBruce Richardson 
148699a2dd95SBruce Richardson 	eventdev->txa_enqueue = rte_event_tx_adapter_enqueue;
148799a2dd95SBruce Richardson 	eventdev->txa_enqueue_same_dest = rte_event_tx_adapter_enqueue;
148899a2dd95SBruce Richardson 	eventdev->ca_enqueue = rte_event_crypto_adapter_enqueue;
148999a2dd95SBruce Richardson 
149099a2dd95SBruce Richardson 	if (eventdev->data == NULL) {
149199a2dd95SBruce Richardson 		struct rte_eventdev_data *eventdev_data = NULL;
149299a2dd95SBruce Richardson 
149399a2dd95SBruce Richardson 		int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data,
149499a2dd95SBruce Richardson 				socket_id);
149599a2dd95SBruce Richardson 
149699a2dd95SBruce Richardson 		if (retval < 0 || eventdev_data == NULL)
149799a2dd95SBruce Richardson 			return NULL;
149899a2dd95SBruce Richardson 
149999a2dd95SBruce Richardson 		eventdev->data = eventdev_data;
150099a2dd95SBruce Richardson 
150199a2dd95SBruce Richardson 		if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
150299a2dd95SBruce Richardson 
150399a2dd95SBruce Richardson 			strlcpy(eventdev->data->name, name,
150499a2dd95SBruce Richardson 				RTE_EVENTDEV_NAME_MAX_LEN);
150599a2dd95SBruce Richardson 
150699a2dd95SBruce Richardson 			eventdev->data->dev_id = dev_id;
150799a2dd95SBruce Richardson 			eventdev->data->socket_id = socket_id;
150899a2dd95SBruce Richardson 			eventdev->data->dev_started = 0;
150999a2dd95SBruce Richardson 		}
151099a2dd95SBruce Richardson 
151199a2dd95SBruce Richardson 		eventdev->attached = RTE_EVENTDEV_ATTACHED;
151299a2dd95SBruce Richardson 		eventdev_globals.nb_devs++;
151399a2dd95SBruce Richardson 	}
151499a2dd95SBruce Richardson 
151599a2dd95SBruce Richardson 	return eventdev;
151699a2dd95SBruce Richardson }
151799a2dd95SBruce Richardson 
151899a2dd95SBruce Richardson int
151999a2dd95SBruce Richardson rte_event_pmd_release(struct rte_eventdev *eventdev)
152099a2dd95SBruce Richardson {
152199a2dd95SBruce Richardson 	int ret;
152299a2dd95SBruce Richardson 	char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
152399a2dd95SBruce Richardson 	const struct rte_memzone *mz;
152499a2dd95SBruce Richardson 
152599a2dd95SBruce Richardson 	if (eventdev == NULL)
152699a2dd95SBruce Richardson 		return -EINVAL;
152799a2dd95SBruce Richardson 
152899a2dd95SBruce Richardson 	eventdev->attached = RTE_EVENTDEV_DETACHED;
152999a2dd95SBruce Richardson 	eventdev_globals.nb_devs--;
153099a2dd95SBruce Richardson 
153199a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
153299a2dd95SBruce Richardson 		rte_free(eventdev->data->dev_private);
153399a2dd95SBruce Richardson 
153499a2dd95SBruce Richardson 		/* Generate memzone name */
153599a2dd95SBruce Richardson 		ret = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u",
153699a2dd95SBruce Richardson 				eventdev->data->dev_id);
153799a2dd95SBruce Richardson 		if (ret >= (int)sizeof(mz_name))
153899a2dd95SBruce Richardson 			return -EINVAL;
153999a2dd95SBruce Richardson 
154099a2dd95SBruce Richardson 		mz = rte_memzone_lookup(mz_name);
154199a2dd95SBruce Richardson 		if (mz == NULL)
154299a2dd95SBruce Richardson 			return -ENOMEM;
154399a2dd95SBruce Richardson 
154499a2dd95SBruce Richardson 		ret = rte_memzone_free(mz);
154599a2dd95SBruce Richardson 		if (ret)
154699a2dd95SBruce Richardson 			return ret;
154799a2dd95SBruce Richardson 	}
154899a2dd95SBruce Richardson 
154999a2dd95SBruce Richardson 	eventdev->data = NULL;
155099a2dd95SBruce Richardson 	return 0;
155199a2dd95SBruce Richardson }
155299a2dd95SBruce Richardson 
155399a2dd95SBruce Richardson 
155499a2dd95SBruce Richardson static int
155599a2dd95SBruce Richardson handle_dev_list(const char *cmd __rte_unused,
155699a2dd95SBruce Richardson 		const char *params __rte_unused,
155799a2dd95SBruce Richardson 		struct rte_tel_data *d)
155899a2dd95SBruce Richardson {
155999a2dd95SBruce Richardson 	uint8_t dev_id;
156099a2dd95SBruce Richardson 	int ndev = rte_event_dev_count();
156199a2dd95SBruce Richardson 
156299a2dd95SBruce Richardson 	if (ndev < 1)
156399a2dd95SBruce Richardson 		return -1;
156499a2dd95SBruce Richardson 
156599a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
156699a2dd95SBruce Richardson 	for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
156799a2dd95SBruce Richardson 		if (rte_eventdevs[dev_id].attached ==
156899a2dd95SBruce Richardson 				RTE_EVENTDEV_ATTACHED)
156999a2dd95SBruce Richardson 			rte_tel_data_add_array_int(d, dev_id);
157099a2dd95SBruce Richardson 	}
157199a2dd95SBruce Richardson 
157299a2dd95SBruce Richardson 	return 0;
157399a2dd95SBruce Richardson }
157499a2dd95SBruce Richardson 
157599a2dd95SBruce Richardson static int
157699a2dd95SBruce Richardson handle_port_list(const char *cmd __rte_unused,
157799a2dd95SBruce Richardson 		 const char *params,
157899a2dd95SBruce Richardson 		 struct rte_tel_data *d)
157999a2dd95SBruce Richardson {
158099a2dd95SBruce Richardson 	int i;
158199a2dd95SBruce Richardson 	uint8_t dev_id;
158299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
158399a2dd95SBruce Richardson 	char *end_param;
158499a2dd95SBruce Richardson 
158599a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
158699a2dd95SBruce Richardson 		return -1;
158799a2dd95SBruce Richardson 
158899a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
158999a2dd95SBruce Richardson 	if (*end_param != '\0')
159099a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
159199a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
159299a2dd95SBruce Richardson 
159399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
159499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
159599a2dd95SBruce Richardson 
159699a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
159799a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_ports; i++)
159899a2dd95SBruce Richardson 		rte_tel_data_add_array_int(d, i);
159999a2dd95SBruce Richardson 
160099a2dd95SBruce Richardson 	return 0;
160199a2dd95SBruce Richardson }
160299a2dd95SBruce Richardson 
160399a2dd95SBruce Richardson static int
160499a2dd95SBruce Richardson handle_queue_list(const char *cmd __rte_unused,
160599a2dd95SBruce Richardson 		  const char *params,
160699a2dd95SBruce Richardson 		  struct rte_tel_data *d)
160799a2dd95SBruce Richardson {
160899a2dd95SBruce Richardson 	int i;
160999a2dd95SBruce Richardson 	uint8_t dev_id;
161099a2dd95SBruce Richardson 	struct rte_eventdev *dev;
161199a2dd95SBruce Richardson 	char *end_param;
161299a2dd95SBruce Richardson 
161399a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
161499a2dd95SBruce Richardson 		return -1;
161599a2dd95SBruce Richardson 
161699a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
161799a2dd95SBruce Richardson 	if (*end_param != '\0')
161899a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
161999a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
162099a2dd95SBruce Richardson 
162199a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
162299a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
162399a2dd95SBruce Richardson 
162499a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
162599a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_queues; i++)
162699a2dd95SBruce Richardson 		rte_tel_data_add_array_int(d, i);
162799a2dd95SBruce Richardson 
162899a2dd95SBruce Richardson 	return 0;
162999a2dd95SBruce Richardson }
163099a2dd95SBruce Richardson 
163199a2dd95SBruce Richardson static int
163299a2dd95SBruce Richardson handle_queue_links(const char *cmd __rte_unused,
163399a2dd95SBruce Richardson 		   const char *params,
163499a2dd95SBruce Richardson 		   struct rte_tel_data *d)
163599a2dd95SBruce Richardson {
163699a2dd95SBruce Richardson 	int i, ret, port_id = 0;
163799a2dd95SBruce Richardson 	char *end_param;
163899a2dd95SBruce Richardson 	uint8_t dev_id;
163999a2dd95SBruce Richardson 	uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
164099a2dd95SBruce Richardson 	uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
164199a2dd95SBruce Richardson 	const char *p_param;
164299a2dd95SBruce Richardson 
164399a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
164499a2dd95SBruce Richardson 		return -1;
164599a2dd95SBruce Richardson 
164699a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
164799a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
164899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
164999a2dd95SBruce Richardson 
165099a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
165199a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
165299a2dd95SBruce Richardson 		return -1;
165399a2dd95SBruce Richardson 
165499a2dd95SBruce Richardson 	port_id = strtoul(p_param, &end_param, 10);
165599a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
165699a2dd95SBruce Richardson 	if (p_param != NULL)
165799a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
165899a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
165999a2dd95SBruce Richardson 
166099a2dd95SBruce Richardson 	ret = rte_event_port_links_get(dev_id, port_id, queues, priorities);
166199a2dd95SBruce Richardson 	if (ret < 0)
166299a2dd95SBruce Richardson 		return -1;
166399a2dd95SBruce Richardson 
166499a2dd95SBruce Richardson 	rte_tel_data_start_dict(d);
166599a2dd95SBruce Richardson 	for (i = 0; i < ret; i++) {
166699a2dd95SBruce Richardson 		char qid_name[32];
166799a2dd95SBruce Richardson 
166899a2dd95SBruce Richardson 		snprintf(qid_name, 31, "qid_%u", queues[i]);
166999a2dd95SBruce Richardson 		rte_tel_data_add_dict_u64(d, qid_name, priorities[i]);
167099a2dd95SBruce Richardson 	}
167199a2dd95SBruce Richardson 
167299a2dd95SBruce Richardson 	return 0;
167399a2dd95SBruce Richardson }
167499a2dd95SBruce Richardson 
167599a2dd95SBruce Richardson static int
167699a2dd95SBruce Richardson eventdev_build_telemetry_data(int dev_id,
167799a2dd95SBruce Richardson 			      enum rte_event_dev_xstats_mode mode,
167899a2dd95SBruce Richardson 			      int port_queue_id,
167999a2dd95SBruce Richardson 			      struct rte_tel_data *d)
168099a2dd95SBruce Richardson {
168199a2dd95SBruce Richardson 	struct rte_event_dev_xstats_name *xstat_names;
168299a2dd95SBruce Richardson 	unsigned int *ids;
168399a2dd95SBruce Richardson 	uint64_t *values;
168499a2dd95SBruce Richardson 	int i, ret, num_xstats;
168599a2dd95SBruce Richardson 
168699a2dd95SBruce Richardson 	num_xstats = rte_event_dev_xstats_names_get(dev_id,
168799a2dd95SBruce Richardson 						    mode,
168899a2dd95SBruce Richardson 						    port_queue_id,
168999a2dd95SBruce Richardson 						    NULL,
169099a2dd95SBruce Richardson 						    NULL,
169199a2dd95SBruce Richardson 						    0);
169299a2dd95SBruce Richardson 
169399a2dd95SBruce Richardson 	if (num_xstats < 0)
169499a2dd95SBruce Richardson 		return -1;
169599a2dd95SBruce Richardson 
169699a2dd95SBruce Richardson 	/* use one malloc for names */
169799a2dd95SBruce Richardson 	xstat_names = malloc((sizeof(struct rte_event_dev_xstats_name))
169899a2dd95SBruce Richardson 			     * num_xstats);
169999a2dd95SBruce Richardson 	if (xstat_names == NULL)
170099a2dd95SBruce Richardson 		return -1;
170199a2dd95SBruce Richardson 
170299a2dd95SBruce Richardson 	ids = malloc((sizeof(unsigned int)) * num_xstats);
170399a2dd95SBruce Richardson 	if (ids == NULL) {
170499a2dd95SBruce Richardson 		free(xstat_names);
170599a2dd95SBruce Richardson 		return -1;
170699a2dd95SBruce Richardson 	}
170799a2dd95SBruce Richardson 
170899a2dd95SBruce Richardson 	values = malloc((sizeof(uint64_t)) * num_xstats);
170999a2dd95SBruce Richardson 	if (values == NULL) {
171099a2dd95SBruce Richardson 		free(xstat_names);
171199a2dd95SBruce Richardson 		free(ids);
171299a2dd95SBruce Richardson 		return -1;
171399a2dd95SBruce Richardson 	}
171499a2dd95SBruce Richardson 
171599a2dd95SBruce Richardson 	ret = rte_event_dev_xstats_names_get(dev_id, mode, port_queue_id,
171699a2dd95SBruce Richardson 					     xstat_names, ids, num_xstats);
171799a2dd95SBruce Richardson 	if (ret < 0 || ret > num_xstats) {
171899a2dd95SBruce Richardson 		free(xstat_names);
171999a2dd95SBruce Richardson 		free(ids);
172099a2dd95SBruce Richardson 		free(values);
172199a2dd95SBruce Richardson 		return -1;
172299a2dd95SBruce Richardson 	}
172399a2dd95SBruce Richardson 
172499a2dd95SBruce Richardson 	ret = rte_event_dev_xstats_get(dev_id, mode, port_queue_id,
172599a2dd95SBruce Richardson 				       ids, values, num_xstats);
172699a2dd95SBruce Richardson 	if (ret < 0 || ret > num_xstats) {
172799a2dd95SBruce Richardson 		free(xstat_names);
172899a2dd95SBruce Richardson 		free(ids);
172999a2dd95SBruce Richardson 		free(values);
173099a2dd95SBruce Richardson 		return -1;
173199a2dd95SBruce Richardson 	}
173299a2dd95SBruce Richardson 
173399a2dd95SBruce Richardson 	rte_tel_data_start_dict(d);
173499a2dd95SBruce Richardson 	for (i = 0; i < num_xstats; i++)
173599a2dd95SBruce Richardson 		rte_tel_data_add_dict_u64(d, xstat_names[i].name,
173699a2dd95SBruce Richardson 					  values[i]);
173799a2dd95SBruce Richardson 
173899a2dd95SBruce Richardson 	free(xstat_names);
173999a2dd95SBruce Richardson 	free(ids);
174099a2dd95SBruce Richardson 	free(values);
174199a2dd95SBruce Richardson 	return 0;
174299a2dd95SBruce Richardson }
174399a2dd95SBruce Richardson 
174499a2dd95SBruce Richardson static int
174599a2dd95SBruce Richardson handle_dev_xstats(const char *cmd __rte_unused,
174699a2dd95SBruce Richardson 		  const char *params,
174799a2dd95SBruce Richardson 		  struct rte_tel_data *d)
174899a2dd95SBruce Richardson {
174999a2dd95SBruce Richardson 	int dev_id;
175099a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
175199a2dd95SBruce Richardson 	char *end_param;
175299a2dd95SBruce Richardson 
175399a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
175499a2dd95SBruce Richardson 		return -1;
175599a2dd95SBruce Richardson 
175699a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
175799a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
175899a2dd95SBruce Richardson 	if (*end_param != '\0')
175999a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
176099a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
176199a2dd95SBruce Richardson 
176299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
176399a2dd95SBruce Richardson 
176499a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_DEVICE;
176599a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, 0, d);
176699a2dd95SBruce Richardson }
176799a2dd95SBruce Richardson 
176899a2dd95SBruce Richardson static int
176999a2dd95SBruce Richardson handle_port_xstats(const char *cmd __rte_unused,
177099a2dd95SBruce Richardson 		   const char *params,
177199a2dd95SBruce Richardson 		   struct rte_tel_data *d)
177299a2dd95SBruce Richardson {
177399a2dd95SBruce Richardson 	int dev_id;
177499a2dd95SBruce Richardson 	int port_queue_id = 0;
177599a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
177699a2dd95SBruce Richardson 	char *end_param;
177799a2dd95SBruce Richardson 	const char *p_param;
177899a2dd95SBruce Richardson 
177999a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
178099a2dd95SBruce Richardson 		return -1;
178199a2dd95SBruce Richardson 
178299a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
178399a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
178499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
178599a2dd95SBruce Richardson 
178699a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
178799a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_PORT;
178899a2dd95SBruce Richardson 
178999a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
179099a2dd95SBruce Richardson 		return -1;
179199a2dd95SBruce Richardson 
179299a2dd95SBruce Richardson 	port_queue_id = strtoul(p_param, &end_param, 10);
179399a2dd95SBruce Richardson 
179499a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
179599a2dd95SBruce Richardson 	if (p_param != NULL)
179699a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
179799a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
179899a2dd95SBruce Richardson 
179999a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, port_queue_id, d);
180099a2dd95SBruce Richardson }
180199a2dd95SBruce Richardson 
180299a2dd95SBruce Richardson static int
180399a2dd95SBruce Richardson handle_queue_xstats(const char *cmd __rte_unused,
180499a2dd95SBruce Richardson 		    const char *params,
180599a2dd95SBruce Richardson 		    struct rte_tel_data *d)
180699a2dd95SBruce Richardson {
180799a2dd95SBruce Richardson 	int dev_id;
180899a2dd95SBruce Richardson 	int port_queue_id = 0;
180999a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
181099a2dd95SBruce Richardson 	char *end_param;
181199a2dd95SBruce Richardson 	const char *p_param;
181299a2dd95SBruce Richardson 
181399a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
181499a2dd95SBruce Richardson 		return -1;
181599a2dd95SBruce Richardson 
181699a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
181799a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
181899a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
181999a2dd95SBruce Richardson 
182099a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
182199a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_QUEUE;
182299a2dd95SBruce Richardson 
182399a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
182499a2dd95SBruce Richardson 		return -1;
182599a2dd95SBruce Richardson 
182699a2dd95SBruce Richardson 	port_queue_id = strtoul(p_param, &end_param, 10);
182799a2dd95SBruce Richardson 
182899a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
182999a2dd95SBruce Richardson 	if (p_param != NULL)
183099a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
183199a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
183299a2dd95SBruce Richardson 
183399a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, port_queue_id, d);
183499a2dd95SBruce Richardson }
183599a2dd95SBruce Richardson 
183699a2dd95SBruce Richardson RTE_INIT(eventdev_init_telemetry)
183799a2dd95SBruce Richardson {
183899a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/dev_list", handle_dev_list,
183999a2dd95SBruce Richardson 			"Returns list of available eventdevs. Takes no parameters");
184099a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/port_list", handle_port_list,
184199a2dd95SBruce Richardson 			"Returns list of available ports. Parameter: DevID");
184299a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_list", handle_queue_list,
184399a2dd95SBruce Richardson 			"Returns list of available queues. Parameter: DevID");
184499a2dd95SBruce Richardson 
184599a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/dev_xstats", handle_dev_xstats,
184699a2dd95SBruce Richardson 			"Returns stats for an eventdev. Parameter: DevID");
184799a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/port_xstats", handle_port_xstats,
184899a2dd95SBruce Richardson 			"Returns stats for an eventdev port. Params: DevID,PortID");
184999a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_xstats",
185099a2dd95SBruce Richardson 			handle_queue_xstats,
185199a2dd95SBruce Richardson 			"Returns stats for an eventdev queue. Params: DevID,QueueID");
185299a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_links", handle_queue_links,
185399a2dd95SBruce Richardson 			"Returns links for an eventdev port. Params: DevID,QueueID");
185499a2dd95SBruce Richardson }
1855