xref: /dpdk/lib/eventdev/rte_eventdev.c (revision af0785a2447b307965377b62f46a5f39457a85a3)
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 <errno.h>
1099a2dd95SBruce Richardson #include <stdint.h>
1199a2dd95SBruce Richardson #include <inttypes.h>
1299a2dd95SBruce Richardson 
1399a2dd95SBruce Richardson #include <rte_string_fns.h>
1499a2dd95SBruce Richardson #include <rte_log.h>
151acb7f54SDavid Marchand #include <dev_driver.h>
1699a2dd95SBruce Richardson #include <rte_memzone.h>
1799a2dd95SBruce Richardson #include <rte_eal.h>
1899a2dd95SBruce Richardson #include <rte_common.h>
1999a2dd95SBruce Richardson #include <rte_malloc.h>
2099a2dd95SBruce Richardson #include <rte_errno.h>
21f9bdee26SKonstantin Ananyev #include <ethdev_driver.h>
2299a2dd95SBruce Richardson #include <rte_cryptodev.h>
23af668035SAkhil Goyal #include <cryptodev_pmd.h>
2499a2dd95SBruce Richardson #include <rte_telemetry.h>
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson #include "rte_eventdev.h"
2799a2dd95SBruce Richardson #include "eventdev_pmd.h"
28f26f2ca6SPavan Nikhilesh #include "eventdev_trace.h"
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson static struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
3199a2dd95SBruce Richardson 
3299a2dd95SBruce Richardson struct rte_eventdev *rte_eventdevs = rte_event_devices;
3399a2dd95SBruce Richardson 
3499a2dd95SBruce Richardson static struct rte_eventdev_global eventdev_globals = {
3599a2dd95SBruce Richardson 	.nb_devs		= 0
3699a2dd95SBruce Richardson };
3799a2dd95SBruce Richardson 
38d35e6132SPavan Nikhilesh /* Public fastpath APIs. */
39d35e6132SPavan Nikhilesh struct rte_event_fp_ops rte_event_fp_ops[RTE_EVENT_MAX_DEVS];
40d35e6132SPavan Nikhilesh 
4199a2dd95SBruce Richardson /* Event dev north bound API implementation */
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson uint8_t
4499a2dd95SBruce Richardson rte_event_dev_count(void)
4599a2dd95SBruce Richardson {
4699a2dd95SBruce Richardson 	return eventdev_globals.nb_devs;
4799a2dd95SBruce Richardson }
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson int
5099a2dd95SBruce Richardson rte_event_dev_get_dev_id(const char *name)
5199a2dd95SBruce Richardson {
5299a2dd95SBruce Richardson 	int i;
5399a2dd95SBruce Richardson 	uint8_t cmp;
5499a2dd95SBruce Richardson 
5599a2dd95SBruce Richardson 	if (!name)
5699a2dd95SBruce Richardson 		return -EINVAL;
5799a2dd95SBruce Richardson 
5899a2dd95SBruce Richardson 	for (i = 0; i < eventdev_globals.nb_devs; i++) {
5999a2dd95SBruce Richardson 		cmp = (strncmp(rte_event_devices[i].data->name, name,
6099a2dd95SBruce Richardson 				RTE_EVENTDEV_NAME_MAX_LEN) == 0) ||
6199a2dd95SBruce Richardson 			(rte_event_devices[i].dev ? (strncmp(
6299a2dd95SBruce Richardson 				rte_event_devices[i].dev->driver->name, name,
6399a2dd95SBruce Richardson 					 RTE_EVENTDEV_NAME_MAX_LEN) == 0) : 0);
6499a2dd95SBruce Richardson 		if (cmp && (rte_event_devices[i].attached ==
6599a2dd95SBruce Richardson 					RTE_EVENTDEV_ATTACHED))
6699a2dd95SBruce Richardson 			return i;
6799a2dd95SBruce Richardson 	}
6899a2dd95SBruce Richardson 	return -ENODEV;
6999a2dd95SBruce Richardson }
7099a2dd95SBruce Richardson 
7199a2dd95SBruce Richardson int
7299a2dd95SBruce Richardson rte_event_dev_socket_id(uint8_t dev_id)
7399a2dd95SBruce Richardson {
7499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
7599a2dd95SBruce Richardson 
7699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
7799a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson 	return dev->data->socket_id;
8099a2dd95SBruce Richardson }
8199a2dd95SBruce Richardson 
8299a2dd95SBruce Richardson int
8399a2dd95SBruce Richardson rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
8499a2dd95SBruce Richardson {
8599a2dd95SBruce Richardson 	struct rte_eventdev *dev;
8699a2dd95SBruce Richardson 
8799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
8899a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
8999a2dd95SBruce Richardson 
9099a2dd95SBruce Richardson 	if (dev_info == NULL)
9199a2dd95SBruce Richardson 		return -EINVAL;
9299a2dd95SBruce Richardson 
9399a2dd95SBruce Richardson 	memset(dev_info, 0, sizeof(struct rte_event_dev_info));
9499a2dd95SBruce Richardson 
958f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_infos_get == NULL)
968f1d23ecSDavid Marchand 		return -ENOTSUP;
9799a2dd95SBruce Richardson 	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
9899a2dd95SBruce Richardson 
9999a2dd95SBruce Richardson 	dev_info->dequeue_timeout_ns = dev->data->dev_conf.dequeue_timeout_ns;
10099a2dd95SBruce Richardson 
10199a2dd95SBruce Richardson 	dev_info->dev = dev->dev;
10299a2dd95SBruce Richardson 	return 0;
10399a2dd95SBruce Richardson }
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson int
10699a2dd95SBruce Richardson rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
10799a2dd95SBruce Richardson 				uint32_t *caps)
10899a2dd95SBruce Richardson {
10999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
11099a2dd95SBruce Richardson 
11199a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
11299a2dd95SBruce Richardson 	RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
11599a2dd95SBruce Richardson 
11699a2dd95SBruce Richardson 	if (caps == NULL)
11799a2dd95SBruce Richardson 		return -EINVAL;
11899a2dd95SBruce Richardson 
11999a2dd95SBruce Richardson 	if (dev->dev_ops->eth_rx_adapter_caps_get == NULL)
12099a2dd95SBruce Richardson 		*caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
12199a2dd95SBruce Richardson 	else
12299a2dd95SBruce Richardson 		*caps = 0;
12399a2dd95SBruce Richardson 
12499a2dd95SBruce Richardson 	return dev->dev_ops->eth_rx_adapter_caps_get ?
12599a2dd95SBruce Richardson 				(*dev->dev_ops->eth_rx_adapter_caps_get)(dev,
12699a2dd95SBruce Richardson 						&rte_eth_devices[eth_port_id],
12799a2dd95SBruce Richardson 						caps)
12899a2dd95SBruce Richardson 				: 0;
12999a2dd95SBruce Richardson }
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson int
13299a2dd95SBruce Richardson rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps)
13399a2dd95SBruce Richardson {
13499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
13553548ad3SPavan Nikhilesh 	const struct event_timer_adapter_ops *ops;
13699a2dd95SBruce Richardson 
13799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
13899a2dd95SBruce Richardson 
13999a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson 	if (caps == NULL)
14299a2dd95SBruce Richardson 		return -EINVAL;
1433d9d8adfSNaga Harish K S V 
1443d9d8adfSNaga Harish K S V 	if (dev->dev_ops->timer_adapter_caps_get == NULL)
1453d9d8adfSNaga Harish K S V 		*caps = RTE_EVENT_TIMER_ADAPTER_SW_CAP;
1463d9d8adfSNaga Harish K S V 	else
14799a2dd95SBruce Richardson 		*caps = 0;
14899a2dd95SBruce Richardson 
14999a2dd95SBruce Richardson 	return dev->dev_ops->timer_adapter_caps_get ?
15099a2dd95SBruce Richardson 				(*dev->dev_ops->timer_adapter_caps_get)(dev,
15199a2dd95SBruce Richardson 									0,
15299a2dd95SBruce Richardson 									caps,
15399a2dd95SBruce Richardson 									&ops)
15499a2dd95SBruce Richardson 				: 0;
15599a2dd95SBruce Richardson }
15699a2dd95SBruce Richardson 
15799a2dd95SBruce Richardson int
15899a2dd95SBruce Richardson rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
15999a2dd95SBruce Richardson 				  uint32_t *caps)
16099a2dd95SBruce Richardson {
16199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
16299a2dd95SBruce Richardson 	struct rte_cryptodev *cdev;
16399a2dd95SBruce Richardson 
16499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
165e74abd48SAkhil Goyal 	if (!rte_cryptodev_is_valid_dev(cdev_id))
16699a2dd95SBruce Richardson 		return -EINVAL;
16799a2dd95SBruce Richardson 
16899a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
16999a2dd95SBruce Richardson 	cdev = rte_cryptodev_pmd_get_dev(cdev_id);
17099a2dd95SBruce Richardson 
17199a2dd95SBruce Richardson 	if (caps == NULL)
17299a2dd95SBruce Richardson 		return -EINVAL;
1736b946657SGanapati Kundapura 
1746b946657SGanapati Kundapura 	if (dev->dev_ops->crypto_adapter_caps_get == NULL)
1756b946657SGanapati Kundapura 		*caps = RTE_EVENT_CRYPTO_ADAPTER_SW_CAP;
1766b946657SGanapati Kundapura 	else
17799a2dd95SBruce Richardson 		*caps = 0;
17899a2dd95SBruce Richardson 
17999a2dd95SBruce Richardson 	return dev->dev_ops->crypto_adapter_caps_get ?
18099a2dd95SBruce Richardson 		(*dev->dev_ops->crypto_adapter_caps_get)
1816b946657SGanapati Kundapura 		(dev, cdev, caps) : 0;
18299a2dd95SBruce Richardson }
18399a2dd95SBruce Richardson 
18499a2dd95SBruce Richardson int
18599a2dd95SBruce Richardson rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
18699a2dd95SBruce Richardson 				uint32_t *caps)
18799a2dd95SBruce Richardson {
18899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
18999a2dd95SBruce Richardson 	struct rte_eth_dev *eth_dev;
19099a2dd95SBruce Richardson 
19199a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
19299a2dd95SBruce Richardson 	RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
19399a2dd95SBruce Richardson 
19499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
19599a2dd95SBruce Richardson 	eth_dev = &rte_eth_devices[eth_port_id];
19699a2dd95SBruce Richardson 
19799a2dd95SBruce Richardson 	if (caps == NULL)
19899a2dd95SBruce Richardson 		return -EINVAL;
19999a2dd95SBruce Richardson 
20099a2dd95SBruce Richardson 	if (dev->dev_ops->eth_tx_adapter_caps_get == NULL)
20199a2dd95SBruce Richardson 		*caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_EVENT_VECTOR;
20299a2dd95SBruce Richardson 	else
20399a2dd95SBruce Richardson 		*caps = 0;
20499a2dd95SBruce Richardson 
20599a2dd95SBruce Richardson 	return dev->dev_ops->eth_tx_adapter_caps_get ?
20699a2dd95SBruce Richardson 			(*dev->dev_ops->eth_tx_adapter_caps_get)(dev,
20799a2dd95SBruce Richardson 								eth_dev,
20899a2dd95SBruce Richardson 								caps)
20999a2dd95SBruce Richardson 			: 0;
21099a2dd95SBruce Richardson }
21199a2dd95SBruce Richardson 
21299a2dd95SBruce Richardson static inline int
2139c67fcbfSPavan Nikhilesh event_dev_queue_config(struct rte_eventdev *dev, uint8_t nb_queues)
21499a2dd95SBruce Richardson {
21599a2dd95SBruce Richardson 	uint8_t old_nb_queues = dev->data->nb_queues;
21699a2dd95SBruce Richardson 	struct rte_event_queue_conf *queues_cfg;
21799a2dd95SBruce Richardson 	unsigned int i;
21899a2dd95SBruce Richardson 
21999a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Setup %d queues on device %u", nb_queues,
22099a2dd95SBruce Richardson 			 dev->data->dev_id);
22199a2dd95SBruce Richardson 
2229c67fcbfSPavan Nikhilesh 	if (nb_queues != 0) {
2239c67fcbfSPavan Nikhilesh 		queues_cfg = dev->data->queues_cfg;
2248f1d23ecSDavid Marchand 		if (*dev->dev_ops->queue_release == NULL)
2258f1d23ecSDavid Marchand 			return -ENOTSUP;
22699a2dd95SBruce Richardson 
22799a2dd95SBruce Richardson 		for (i = nb_queues; i < old_nb_queues; i++)
22899a2dd95SBruce Richardson 			(*dev->dev_ops->queue_release)(dev, i);
22999a2dd95SBruce Richardson 
23099a2dd95SBruce Richardson 
23199a2dd95SBruce Richardson 		if (nb_queues > old_nb_queues) {
23299a2dd95SBruce Richardson 			uint8_t new_qs = nb_queues - old_nb_queues;
23399a2dd95SBruce Richardson 
23499a2dd95SBruce Richardson 			memset(queues_cfg + old_nb_queues, 0,
23599a2dd95SBruce Richardson 				sizeof(queues_cfg[0]) * new_qs);
23699a2dd95SBruce Richardson 		}
2379c67fcbfSPavan Nikhilesh 	} else {
2388f1d23ecSDavid Marchand 		if (*dev->dev_ops->queue_release == NULL)
2398f1d23ecSDavid Marchand 			return -ENOTSUP;
24099a2dd95SBruce Richardson 
24199a2dd95SBruce Richardson 		for (i = nb_queues; i < old_nb_queues; i++)
24299a2dd95SBruce Richardson 			(*dev->dev_ops->queue_release)(dev, i);
24399a2dd95SBruce Richardson 	}
24499a2dd95SBruce Richardson 
24599a2dd95SBruce Richardson 	dev->data->nb_queues = nb_queues;
24699a2dd95SBruce Richardson 	return 0;
24799a2dd95SBruce Richardson }
24899a2dd95SBruce Richardson 
24999a2dd95SBruce Richardson #define EVENT_QUEUE_SERVICE_PRIORITY_INVALID (0xdead)
25099a2dd95SBruce Richardson 
25199a2dd95SBruce Richardson static inline int
2529c67fcbfSPavan Nikhilesh event_dev_port_config(struct rte_eventdev *dev, uint8_t nb_ports)
25399a2dd95SBruce Richardson {
25499a2dd95SBruce Richardson 	uint8_t old_nb_ports = dev->data->nb_ports;
25599a2dd95SBruce Richardson 	void **ports;
25699a2dd95SBruce Richardson 	uint16_t *links_map;
25799a2dd95SBruce Richardson 	struct rte_event_port_conf *ports_cfg;
25899a2dd95SBruce Richardson 	unsigned int i;
25999a2dd95SBruce Richardson 
26099a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Setup %d ports on device %u", nb_ports,
26199a2dd95SBruce Richardson 			 dev->data->dev_id);
26299a2dd95SBruce Richardson 
2639c67fcbfSPavan Nikhilesh 	if (nb_ports != 0) { /* re-config */
2648f1d23ecSDavid Marchand 		if (*dev->dev_ops->port_release == NULL)
2658f1d23ecSDavid Marchand 			return -ENOTSUP;
26699a2dd95SBruce Richardson 
26799a2dd95SBruce Richardson 		ports = dev->data->ports;
26899a2dd95SBruce Richardson 		ports_cfg = dev->data->ports_cfg;
26999a2dd95SBruce Richardson 		links_map = dev->data->links_map;
27099a2dd95SBruce Richardson 
27199a2dd95SBruce Richardson 		for (i = nb_ports; i < old_nb_ports; i++)
27299a2dd95SBruce Richardson 			(*dev->dev_ops->port_release)(ports[i]);
27399a2dd95SBruce Richardson 
27499a2dd95SBruce Richardson 		if (nb_ports > old_nb_ports) {
27599a2dd95SBruce Richardson 			uint8_t new_ps = nb_ports - old_nb_ports;
27699a2dd95SBruce Richardson 			unsigned int old_links_map_end =
27799a2dd95SBruce Richardson 				old_nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
27899a2dd95SBruce Richardson 			unsigned int links_map_end =
27999a2dd95SBruce Richardson 				nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
28099a2dd95SBruce Richardson 
28199a2dd95SBruce Richardson 			memset(ports + old_nb_ports, 0,
28299a2dd95SBruce Richardson 				sizeof(ports[0]) * new_ps);
28399a2dd95SBruce Richardson 			memset(ports_cfg + old_nb_ports, 0,
28499a2dd95SBruce Richardson 				sizeof(ports_cfg[0]) * new_ps);
28599a2dd95SBruce Richardson 			for (i = old_links_map_end; i < links_map_end; i++)
28699a2dd95SBruce Richardson 				links_map[i] =
28799a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
28899a2dd95SBruce Richardson 		}
2899c67fcbfSPavan Nikhilesh 	} else {
2908f1d23ecSDavid Marchand 		if (*dev->dev_ops->port_release == NULL)
2918f1d23ecSDavid Marchand 			return -ENOTSUP;
29299a2dd95SBruce Richardson 
29399a2dd95SBruce Richardson 		ports = dev->data->ports;
2949c67fcbfSPavan Nikhilesh 		for (i = nb_ports; i < old_nb_ports; i++) {
29599a2dd95SBruce Richardson 			(*dev->dev_ops->port_release)(ports[i]);
2969c67fcbfSPavan Nikhilesh 			ports[i] = NULL;
2979c67fcbfSPavan Nikhilesh 		}
29899a2dd95SBruce Richardson 	}
29999a2dd95SBruce Richardson 
30099a2dd95SBruce Richardson 	dev->data->nb_ports = nb_ports;
30199a2dd95SBruce Richardson 	return 0;
30299a2dd95SBruce Richardson }
30399a2dd95SBruce Richardson 
30499a2dd95SBruce Richardson int
30599a2dd95SBruce Richardson rte_event_dev_configure(uint8_t dev_id,
30699a2dd95SBruce Richardson 			const struct rte_event_dev_config *dev_conf)
30799a2dd95SBruce Richardson {
30899a2dd95SBruce Richardson 	struct rte_event_dev_info info;
309d35e6132SPavan Nikhilesh 	struct rte_eventdev *dev;
31099a2dd95SBruce Richardson 	int diag;
31199a2dd95SBruce Richardson 
31299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
31399a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
31499a2dd95SBruce Richardson 
3158f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_infos_get == NULL)
3168f1d23ecSDavid Marchand 		return -ENOTSUP;
3178f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_configure == NULL)
3188f1d23ecSDavid Marchand 		return -ENOTSUP;
31999a2dd95SBruce Richardson 
32099a2dd95SBruce Richardson 	if (dev->data->dev_started) {
32199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
32299a2dd95SBruce Richardson 		    "device %d must be stopped to allow configuration", dev_id);
32399a2dd95SBruce Richardson 		return -EBUSY;
32499a2dd95SBruce Richardson 	}
32599a2dd95SBruce Richardson 
32699a2dd95SBruce Richardson 	if (dev_conf == NULL)
32799a2dd95SBruce Richardson 		return -EINVAL;
32899a2dd95SBruce Richardson 
32999a2dd95SBruce Richardson 	(*dev->dev_ops->dev_infos_get)(dev, &info);
33099a2dd95SBruce Richardson 
33199a2dd95SBruce Richardson 	/* Check dequeue_timeout_ns value is in limit */
33299a2dd95SBruce Richardson 	if (!(dev_conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)) {
33399a2dd95SBruce Richardson 		if (dev_conf->dequeue_timeout_ns &&
33499a2dd95SBruce Richardson 		    (dev_conf->dequeue_timeout_ns < info.min_dequeue_timeout_ns
33599a2dd95SBruce Richardson 			|| dev_conf->dequeue_timeout_ns >
33699a2dd95SBruce Richardson 				 info.max_dequeue_timeout_ns)) {
33799a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR("dev%d invalid dequeue_timeout_ns=%d"
33899a2dd95SBruce Richardson 			" min_dequeue_timeout_ns=%d max_dequeue_timeout_ns=%d",
33999a2dd95SBruce Richardson 			dev_id, dev_conf->dequeue_timeout_ns,
34099a2dd95SBruce Richardson 			info.min_dequeue_timeout_ns,
34199a2dd95SBruce Richardson 			info.max_dequeue_timeout_ns);
34299a2dd95SBruce Richardson 			return -EINVAL;
34399a2dd95SBruce Richardson 		}
34499a2dd95SBruce Richardson 	}
34599a2dd95SBruce Richardson 
34699a2dd95SBruce Richardson 	/* Check nb_events_limit is in limit */
34799a2dd95SBruce Richardson 	if (dev_conf->nb_events_limit > info.max_num_events) {
34899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_events_limit=%d > max_num_events=%d",
34999a2dd95SBruce Richardson 		dev_id, dev_conf->nb_events_limit, info.max_num_events);
35099a2dd95SBruce Richardson 		return -EINVAL;
35199a2dd95SBruce Richardson 	}
35299a2dd95SBruce Richardson 
35399a2dd95SBruce Richardson 	/* Check nb_event_queues is in limit */
35499a2dd95SBruce Richardson 	if (!dev_conf->nb_event_queues) {
35599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_event_queues cannot be zero",
35699a2dd95SBruce Richardson 					dev_id);
35799a2dd95SBruce Richardson 		return -EINVAL;
35899a2dd95SBruce Richardson 	}
35999a2dd95SBruce Richardson 	if (dev_conf->nb_event_queues > info.max_event_queues +
36099a2dd95SBruce Richardson 			info.max_single_link_event_port_queue_pairs) {
36199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("%d nb_event_queues=%d > max_event_queues=%d + max_single_link_event_port_queue_pairs=%d",
36299a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_queues,
36399a2dd95SBruce Richardson 				 info.max_event_queues,
36499a2dd95SBruce Richardson 				 info.max_single_link_event_port_queue_pairs);
36599a2dd95SBruce Richardson 		return -EINVAL;
36699a2dd95SBruce Richardson 	}
36799a2dd95SBruce Richardson 	if (dev_conf->nb_event_queues -
36899a2dd95SBruce Richardson 			dev_conf->nb_single_link_event_port_queues >
36999a2dd95SBruce Richardson 			info.max_event_queues) {
37099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_queues=%d - nb_single_link_event_port_queues=%d > max_event_queues=%d",
37199a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_queues,
37299a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
37399a2dd95SBruce Richardson 				 info.max_event_queues);
37499a2dd95SBruce Richardson 		return -EINVAL;
37599a2dd95SBruce Richardson 	}
37699a2dd95SBruce Richardson 	if (dev_conf->nb_single_link_event_port_queues >
37799a2dd95SBruce Richardson 			dev_conf->nb_event_queues) {
37899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_single_link_event_port_queues=%d > nb_event_queues=%d",
37999a2dd95SBruce Richardson 				 dev_id,
38099a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
38199a2dd95SBruce Richardson 				 dev_conf->nb_event_queues);
38299a2dd95SBruce Richardson 		return -EINVAL;
38399a2dd95SBruce Richardson 	}
38499a2dd95SBruce Richardson 
38599a2dd95SBruce Richardson 	/* Check nb_event_ports is in limit */
38699a2dd95SBruce Richardson 	if (!dev_conf->nb_event_ports) {
38799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_event_ports cannot be zero", dev_id);
38899a2dd95SBruce Richardson 		return -EINVAL;
38999a2dd95SBruce Richardson 	}
39099a2dd95SBruce Richardson 	if (dev_conf->nb_event_ports > info.max_event_ports +
39199a2dd95SBruce Richardson 			info.max_single_link_event_port_queue_pairs) {
39299a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d > max_event_ports=%d + max_single_link_event_port_queue_pairs=%d",
39399a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_ports,
39499a2dd95SBruce Richardson 				 info.max_event_ports,
39599a2dd95SBruce Richardson 				 info.max_single_link_event_port_queue_pairs);
39699a2dd95SBruce Richardson 		return -EINVAL;
39799a2dd95SBruce Richardson 	}
39899a2dd95SBruce Richardson 	if (dev_conf->nb_event_ports -
39999a2dd95SBruce Richardson 			dev_conf->nb_single_link_event_port_queues
40099a2dd95SBruce Richardson 			> info.max_event_ports) {
40199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d - nb_single_link_event_port_queues=%d > max_event_ports=%d",
40299a2dd95SBruce Richardson 				 dev_id, dev_conf->nb_event_ports,
40399a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
40499a2dd95SBruce Richardson 				 info.max_event_ports);
40599a2dd95SBruce Richardson 		return -EINVAL;
40699a2dd95SBruce Richardson 	}
40799a2dd95SBruce Richardson 
40899a2dd95SBruce Richardson 	if (dev_conf->nb_single_link_event_port_queues >
40999a2dd95SBruce Richardson 	    dev_conf->nb_event_ports) {
41099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
41199a2dd95SBruce Richardson 				 "dev%d nb_single_link_event_port_queues=%d > nb_event_ports=%d",
41299a2dd95SBruce Richardson 				 dev_id,
41399a2dd95SBruce Richardson 				 dev_conf->nb_single_link_event_port_queues,
41499a2dd95SBruce Richardson 				 dev_conf->nb_event_ports);
41599a2dd95SBruce Richardson 		return -EINVAL;
41699a2dd95SBruce Richardson 	}
41799a2dd95SBruce Richardson 
41899a2dd95SBruce Richardson 	/* Check nb_event_queue_flows is in limit */
41999a2dd95SBruce Richardson 	if (!dev_conf->nb_event_queue_flows) {
42099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_flows cannot be zero", dev_id);
42199a2dd95SBruce Richardson 		return -EINVAL;
42299a2dd95SBruce Richardson 	}
42399a2dd95SBruce Richardson 	if (dev_conf->nb_event_queue_flows > info.max_event_queue_flows) {
42499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_flows=%x > max_flows=%x",
42599a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_queue_flows,
42699a2dd95SBruce Richardson 		info.max_event_queue_flows);
42799a2dd95SBruce Richardson 		return -EINVAL;
42899a2dd95SBruce Richardson 	}
42999a2dd95SBruce Richardson 
43099a2dd95SBruce Richardson 	/* Check nb_event_port_dequeue_depth is in limit */
43199a2dd95SBruce Richardson 	if (!dev_conf->nb_event_port_dequeue_depth) {
43299a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_dequeue_depth cannot be zero",
43399a2dd95SBruce Richardson 					dev_id);
43499a2dd95SBruce Richardson 		return -EINVAL;
43599a2dd95SBruce Richardson 	}
43699a2dd95SBruce Richardson 	if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
43799a2dd95SBruce Richardson 		 (dev_conf->nb_event_port_dequeue_depth >
43899a2dd95SBruce Richardson 			 info.max_event_port_dequeue_depth)) {
43999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_dq_depth=%d > max_dq_depth=%d",
44099a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_port_dequeue_depth,
44199a2dd95SBruce Richardson 		info.max_event_port_dequeue_depth);
44299a2dd95SBruce Richardson 		return -EINVAL;
44399a2dd95SBruce Richardson 	}
44499a2dd95SBruce Richardson 
44599a2dd95SBruce Richardson 	/* Check nb_event_port_enqueue_depth is in limit */
44699a2dd95SBruce Richardson 	if (!dev_conf->nb_event_port_enqueue_depth) {
44799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_enqueue_depth cannot be zero",
44899a2dd95SBruce Richardson 					dev_id);
44999a2dd95SBruce Richardson 		return -EINVAL;
45099a2dd95SBruce Richardson 	}
45199a2dd95SBruce Richardson 	if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
45299a2dd95SBruce Richardson 		(dev_conf->nb_event_port_enqueue_depth >
45399a2dd95SBruce Richardson 			 info.max_event_port_enqueue_depth)) {
45499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d nb_enq_depth=%d > max_enq_depth=%d",
45599a2dd95SBruce Richardson 		dev_id, dev_conf->nb_event_port_enqueue_depth,
45699a2dd95SBruce Richardson 		info.max_event_port_enqueue_depth);
45799a2dd95SBruce Richardson 		return -EINVAL;
45899a2dd95SBruce Richardson 	}
45999a2dd95SBruce Richardson 
46099a2dd95SBruce Richardson 	/* Copy the dev_conf parameter into the dev structure */
46199a2dd95SBruce Richardson 	memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
46299a2dd95SBruce Richardson 
46399a2dd95SBruce Richardson 	/* Setup new number of queues and reconfigure device. */
4649c67fcbfSPavan Nikhilesh 	diag = event_dev_queue_config(dev, dev_conf->nb_event_queues);
46599a2dd95SBruce Richardson 	if (diag != 0) {
4669c67fcbfSPavan Nikhilesh 		RTE_EDEV_LOG_ERR("dev%d event_dev_queue_config = %d", dev_id,
4679c67fcbfSPavan Nikhilesh 				 diag);
46899a2dd95SBruce Richardson 		return diag;
46999a2dd95SBruce Richardson 	}
47099a2dd95SBruce Richardson 
47199a2dd95SBruce Richardson 	/* Setup new number of ports and reconfigure device. */
4729c67fcbfSPavan Nikhilesh 	diag = event_dev_port_config(dev, dev_conf->nb_event_ports);
47399a2dd95SBruce Richardson 	if (diag != 0) {
4749c67fcbfSPavan Nikhilesh 		event_dev_queue_config(dev, 0);
4759c67fcbfSPavan Nikhilesh 		RTE_EDEV_LOG_ERR("dev%d event_dev_port_config = %d", dev_id,
4769c67fcbfSPavan Nikhilesh 				 diag);
47799a2dd95SBruce Richardson 		return diag;
47899a2dd95SBruce Richardson 	}
47999a2dd95SBruce Richardson 
480d35e6132SPavan Nikhilesh 	event_dev_fp_ops_reset(rte_event_fp_ops + dev_id);
481d35e6132SPavan Nikhilesh 
48299a2dd95SBruce Richardson 	/* Configure the device */
48399a2dd95SBruce Richardson 	diag = (*dev->dev_ops->dev_configure)(dev);
48499a2dd95SBruce Richardson 	if (diag != 0) {
48599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("dev%d dev_configure = %d", dev_id, diag);
486d35e6132SPavan Nikhilesh 		event_dev_fp_ops_reset(rte_event_fp_ops + dev_id);
4879c67fcbfSPavan Nikhilesh 		event_dev_queue_config(dev, 0);
4889c67fcbfSPavan Nikhilesh 		event_dev_port_config(dev, 0);
48999a2dd95SBruce Richardson 	}
49099a2dd95SBruce Richardson 
49199a2dd95SBruce Richardson 	dev->data->event_dev_cap = info.event_dev_cap;
49299a2dd95SBruce Richardson 	rte_eventdev_trace_configure(dev_id, dev_conf, diag);
49399a2dd95SBruce Richardson 	return diag;
49499a2dd95SBruce Richardson }
49599a2dd95SBruce Richardson 
49699a2dd95SBruce Richardson static inline int
49799a2dd95SBruce Richardson is_valid_queue(struct rte_eventdev *dev, uint8_t queue_id)
49899a2dd95SBruce Richardson {
49999a2dd95SBruce Richardson 	if (queue_id < dev->data->nb_queues && queue_id <
50099a2dd95SBruce Richardson 				RTE_EVENT_MAX_QUEUES_PER_DEV)
50199a2dd95SBruce Richardson 		return 1;
50299a2dd95SBruce Richardson 	else
50399a2dd95SBruce Richardson 		return 0;
50499a2dd95SBruce Richardson }
50599a2dd95SBruce Richardson 
50699a2dd95SBruce Richardson int
50799a2dd95SBruce Richardson rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
50899a2dd95SBruce Richardson 				 struct rte_event_queue_conf *queue_conf)
50999a2dd95SBruce Richardson {
51099a2dd95SBruce Richardson 	struct rte_eventdev *dev;
51199a2dd95SBruce Richardson 
51299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
51399a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
51499a2dd95SBruce Richardson 
51599a2dd95SBruce Richardson 	if (queue_conf == NULL)
51699a2dd95SBruce Richardson 		return -EINVAL;
51799a2dd95SBruce Richardson 
51899a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
51999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
52099a2dd95SBruce Richardson 		return -EINVAL;
52199a2dd95SBruce Richardson 	}
52299a2dd95SBruce Richardson 
5238f1d23ecSDavid Marchand 	if (*dev->dev_ops->queue_def_conf == NULL)
5248f1d23ecSDavid Marchand 		return -ENOTSUP;
52599a2dd95SBruce Richardson 	memset(queue_conf, 0, sizeof(struct rte_event_queue_conf));
52699a2dd95SBruce Richardson 	(*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
52799a2dd95SBruce Richardson 	return 0;
52899a2dd95SBruce Richardson }
52999a2dd95SBruce Richardson 
53099a2dd95SBruce Richardson static inline int
53199a2dd95SBruce Richardson is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
53299a2dd95SBruce Richardson {
53399a2dd95SBruce Richardson 	if (queue_conf &&
53499a2dd95SBruce Richardson 		!(queue_conf->event_queue_cfg &
53599a2dd95SBruce Richardson 		  RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
53699a2dd95SBruce Richardson 		((queue_conf->event_queue_cfg &
53799a2dd95SBruce Richardson 			 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
53899a2dd95SBruce Richardson 		(queue_conf->schedule_type
53999a2dd95SBruce Richardson 			== RTE_SCHED_TYPE_ATOMIC)
54099a2dd95SBruce Richardson 		))
54199a2dd95SBruce Richardson 		return 1;
54299a2dd95SBruce Richardson 	else
54399a2dd95SBruce Richardson 		return 0;
54499a2dd95SBruce Richardson }
54599a2dd95SBruce Richardson 
54699a2dd95SBruce Richardson static inline int
54799a2dd95SBruce Richardson is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
54899a2dd95SBruce Richardson {
54999a2dd95SBruce Richardson 	if (queue_conf &&
55099a2dd95SBruce Richardson 		!(queue_conf->event_queue_cfg &
55199a2dd95SBruce Richardson 		  RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
55299a2dd95SBruce Richardson 		((queue_conf->event_queue_cfg &
55399a2dd95SBruce Richardson 			 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
55499a2dd95SBruce Richardson 		(queue_conf->schedule_type
55599a2dd95SBruce Richardson 			== RTE_SCHED_TYPE_ORDERED)
55699a2dd95SBruce Richardson 		))
55799a2dd95SBruce Richardson 		return 1;
55899a2dd95SBruce Richardson 	else
55999a2dd95SBruce Richardson 		return 0;
56099a2dd95SBruce Richardson }
56199a2dd95SBruce Richardson 
56299a2dd95SBruce Richardson 
56399a2dd95SBruce Richardson int
56499a2dd95SBruce Richardson rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
56599a2dd95SBruce Richardson 		      const struct rte_event_queue_conf *queue_conf)
56699a2dd95SBruce Richardson {
56799a2dd95SBruce Richardson 	struct rte_eventdev *dev;
56899a2dd95SBruce Richardson 	struct rte_event_queue_conf def_conf;
56999a2dd95SBruce Richardson 
57099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
57199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
57299a2dd95SBruce Richardson 
57399a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
57499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
57599a2dd95SBruce Richardson 		return -EINVAL;
57699a2dd95SBruce Richardson 	}
57799a2dd95SBruce Richardson 
57899a2dd95SBruce Richardson 	/* Check nb_atomic_flows limit */
57999a2dd95SBruce Richardson 	if (is_valid_atomic_queue_conf(queue_conf)) {
58099a2dd95SBruce Richardson 		if (queue_conf->nb_atomic_flows == 0 ||
58199a2dd95SBruce Richardson 		    queue_conf->nb_atomic_flows >
58299a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows) {
58399a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR(
58499a2dd95SBruce Richardson 		"dev%d queue%d Invalid nb_atomic_flows=%d max_flows=%d",
58599a2dd95SBruce Richardson 			dev_id, queue_id, queue_conf->nb_atomic_flows,
58699a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows);
58799a2dd95SBruce Richardson 			return -EINVAL;
58899a2dd95SBruce Richardson 		}
58999a2dd95SBruce Richardson 	}
59099a2dd95SBruce Richardson 
59199a2dd95SBruce Richardson 	/* Check nb_atomic_order_sequences limit */
59299a2dd95SBruce Richardson 	if (is_valid_ordered_queue_conf(queue_conf)) {
59399a2dd95SBruce Richardson 		if (queue_conf->nb_atomic_order_sequences == 0 ||
59499a2dd95SBruce Richardson 		    queue_conf->nb_atomic_order_sequences >
59599a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows) {
59699a2dd95SBruce Richardson 			RTE_EDEV_LOG_ERR(
59799a2dd95SBruce Richardson 		"dev%d queue%d Invalid nb_atomic_order_seq=%d max_flows=%d",
59899a2dd95SBruce Richardson 			dev_id, queue_id, queue_conf->nb_atomic_order_sequences,
59999a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_queue_flows);
60099a2dd95SBruce Richardson 			return -EINVAL;
60199a2dd95SBruce Richardson 		}
60299a2dd95SBruce Richardson 	}
60399a2dd95SBruce Richardson 
60499a2dd95SBruce Richardson 	if (dev->data->dev_started) {
60599a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
60699a2dd95SBruce Richardson 		    "device %d must be stopped to allow queue setup", dev_id);
60799a2dd95SBruce Richardson 		return -EBUSY;
60899a2dd95SBruce Richardson 	}
60999a2dd95SBruce Richardson 
6108f1d23ecSDavid Marchand 	if (*dev->dev_ops->queue_setup == NULL)
6118f1d23ecSDavid Marchand 		return -ENOTSUP;
61299a2dd95SBruce Richardson 
61399a2dd95SBruce Richardson 	if (queue_conf == NULL) {
6148f1d23ecSDavid Marchand 		if (*dev->dev_ops->queue_def_conf == NULL)
6158f1d23ecSDavid Marchand 			return -ENOTSUP;
61699a2dd95SBruce Richardson 		(*dev->dev_ops->queue_def_conf)(dev, queue_id, &def_conf);
61799a2dd95SBruce Richardson 		queue_conf = &def_conf;
61899a2dd95SBruce Richardson 	}
61999a2dd95SBruce Richardson 
62099a2dd95SBruce Richardson 	dev->data->queues_cfg[queue_id] = *queue_conf;
62199a2dd95SBruce Richardson 	rte_eventdev_trace_queue_setup(dev_id, queue_id, queue_conf);
62299a2dd95SBruce Richardson 	return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
62399a2dd95SBruce Richardson }
62499a2dd95SBruce Richardson 
62599a2dd95SBruce Richardson static inline int
62699a2dd95SBruce Richardson is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
62799a2dd95SBruce Richardson {
62899a2dd95SBruce Richardson 	if (port_id < dev->data->nb_ports)
62999a2dd95SBruce Richardson 		return 1;
63099a2dd95SBruce Richardson 	else
63199a2dd95SBruce Richardson 		return 0;
63299a2dd95SBruce Richardson }
63399a2dd95SBruce Richardson 
63499a2dd95SBruce Richardson int
63599a2dd95SBruce Richardson rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
63699a2dd95SBruce Richardson 				 struct rte_event_port_conf *port_conf)
63799a2dd95SBruce Richardson {
63899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
63999a2dd95SBruce Richardson 
64099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
64199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
64299a2dd95SBruce Richardson 
64399a2dd95SBruce Richardson 	if (port_conf == NULL)
64499a2dd95SBruce Richardson 		return -EINVAL;
64599a2dd95SBruce Richardson 
64699a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
64799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
64899a2dd95SBruce Richardson 		return -EINVAL;
64999a2dd95SBruce Richardson 	}
65099a2dd95SBruce Richardson 
6518f1d23ecSDavid Marchand 	if (*dev->dev_ops->port_def_conf == NULL)
6528f1d23ecSDavid Marchand 		return -ENOTSUP;
65399a2dd95SBruce Richardson 	memset(port_conf, 0, sizeof(struct rte_event_port_conf));
65499a2dd95SBruce Richardson 	(*dev->dev_ops->port_def_conf)(dev, port_id, port_conf);
65599a2dd95SBruce Richardson 	return 0;
65699a2dd95SBruce Richardson }
65799a2dd95SBruce Richardson 
65899a2dd95SBruce Richardson int
65999a2dd95SBruce Richardson rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
66099a2dd95SBruce Richardson 		     const struct rte_event_port_conf *port_conf)
66199a2dd95SBruce Richardson {
66299a2dd95SBruce Richardson 	struct rte_eventdev *dev;
66399a2dd95SBruce Richardson 	struct rte_event_port_conf def_conf;
66499a2dd95SBruce Richardson 	int diag;
66599a2dd95SBruce Richardson 
66699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
66799a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
66899a2dd95SBruce Richardson 
66999a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
67099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
67199a2dd95SBruce Richardson 		return -EINVAL;
67299a2dd95SBruce Richardson 	}
67399a2dd95SBruce Richardson 
67499a2dd95SBruce Richardson 	/* Check new_event_threshold limit */
67599a2dd95SBruce Richardson 	if ((port_conf && !port_conf->new_event_threshold) ||
67699a2dd95SBruce Richardson 			(port_conf && port_conf->new_event_threshold >
67799a2dd95SBruce Richardson 				 dev->data->dev_conf.nb_events_limit)) {
67899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
67999a2dd95SBruce Richardson 		   "dev%d port%d Invalid event_threshold=%d nb_events_limit=%d",
68099a2dd95SBruce Richardson 			dev_id, port_id, port_conf->new_event_threshold,
68199a2dd95SBruce Richardson 			dev->data->dev_conf.nb_events_limit);
68299a2dd95SBruce Richardson 		return -EINVAL;
68399a2dd95SBruce Richardson 	}
68499a2dd95SBruce Richardson 
68599a2dd95SBruce Richardson 	/* Check dequeue_depth limit */
68699a2dd95SBruce Richardson 	if ((port_conf && !port_conf->dequeue_depth) ||
68799a2dd95SBruce Richardson 			(port_conf && port_conf->dequeue_depth >
68899a2dd95SBruce Richardson 		dev->data->dev_conf.nb_event_port_dequeue_depth)) {
68999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
69099a2dd95SBruce Richardson 		   "dev%d port%d Invalid dequeue depth=%d max_dequeue_depth=%d",
69199a2dd95SBruce Richardson 			dev_id, port_id, port_conf->dequeue_depth,
69299a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_port_dequeue_depth);
69399a2dd95SBruce Richardson 		return -EINVAL;
69499a2dd95SBruce Richardson 	}
69599a2dd95SBruce Richardson 
69699a2dd95SBruce Richardson 	/* Check enqueue_depth limit */
69799a2dd95SBruce Richardson 	if ((port_conf && !port_conf->enqueue_depth) ||
69899a2dd95SBruce Richardson 			(port_conf && port_conf->enqueue_depth >
69999a2dd95SBruce Richardson 		dev->data->dev_conf.nb_event_port_enqueue_depth)) {
70099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
70199a2dd95SBruce Richardson 		   "dev%d port%d Invalid enqueue depth=%d max_enqueue_depth=%d",
70299a2dd95SBruce Richardson 			dev_id, port_id, port_conf->enqueue_depth,
70399a2dd95SBruce Richardson 			dev->data->dev_conf.nb_event_port_enqueue_depth);
70499a2dd95SBruce Richardson 		return -EINVAL;
70599a2dd95SBruce Richardson 	}
70699a2dd95SBruce Richardson 
70799a2dd95SBruce Richardson 	if (port_conf &&
70899a2dd95SBruce Richardson 	    (port_conf->event_port_cfg & RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL) &&
70999a2dd95SBruce Richardson 	    !(dev->data->event_dev_cap &
71099a2dd95SBruce Richardson 	      RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)) {
71199a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
71299a2dd95SBruce Richardson 		   "dev%d port%d Implicit release disable not supported",
71399a2dd95SBruce Richardson 			dev_id, port_id);
71499a2dd95SBruce Richardson 		return -EINVAL;
71599a2dd95SBruce Richardson 	}
71699a2dd95SBruce Richardson 
71799a2dd95SBruce Richardson 	if (dev->data->dev_started) {
71899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR(
71999a2dd95SBruce Richardson 		    "device %d must be stopped to allow port setup", dev_id);
72099a2dd95SBruce Richardson 		return -EBUSY;
72199a2dd95SBruce Richardson 	}
72299a2dd95SBruce Richardson 
7238f1d23ecSDavid Marchand 	if (*dev->dev_ops->port_setup == NULL)
7248f1d23ecSDavid Marchand 		return -ENOTSUP;
72599a2dd95SBruce Richardson 
72699a2dd95SBruce Richardson 	if (port_conf == NULL) {
7278f1d23ecSDavid Marchand 		if (*dev->dev_ops->port_def_conf == NULL)
7288f1d23ecSDavid Marchand 			return -ENOTSUP;
72999a2dd95SBruce Richardson 		(*dev->dev_ops->port_def_conf)(dev, port_id, &def_conf);
73099a2dd95SBruce Richardson 		port_conf = &def_conf;
73199a2dd95SBruce Richardson 	}
73299a2dd95SBruce Richardson 
73399a2dd95SBruce Richardson 	dev->data->ports_cfg[port_id] = *port_conf;
73499a2dd95SBruce Richardson 
73599a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_setup)(dev, port_id, port_conf);
73699a2dd95SBruce Richardson 
73799a2dd95SBruce Richardson 	/* Unlink all the queues from this port(default state after setup) */
73899a2dd95SBruce Richardson 	if (!diag)
73999a2dd95SBruce Richardson 		diag = rte_event_port_unlink(dev_id, port_id, NULL, 0);
74099a2dd95SBruce Richardson 
74199a2dd95SBruce Richardson 	rte_eventdev_trace_port_setup(dev_id, port_id, port_conf, diag);
74299a2dd95SBruce Richardson 	if (diag < 0)
74399a2dd95SBruce Richardson 		return diag;
74499a2dd95SBruce Richardson 
74599a2dd95SBruce Richardson 	return 0;
74699a2dd95SBruce Richardson }
74799a2dd95SBruce Richardson 
7481ff23ce6SPavan Nikhilesh void
7491ff23ce6SPavan Nikhilesh rte_event_port_quiesce(uint8_t dev_id, uint8_t port_id,
7501ff23ce6SPavan Nikhilesh 		       rte_eventdev_port_flush_t release_cb, void *args)
7511ff23ce6SPavan Nikhilesh {
7521ff23ce6SPavan Nikhilesh 	struct rte_eventdev *dev;
7531ff23ce6SPavan Nikhilesh 
7541ff23ce6SPavan Nikhilesh 	RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
7551ff23ce6SPavan Nikhilesh 	dev = &rte_eventdevs[dev_id];
7561ff23ce6SPavan Nikhilesh 
7571ff23ce6SPavan Nikhilesh 	if (!is_valid_port(dev, port_id)) {
7581ff23ce6SPavan Nikhilesh 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
7591ff23ce6SPavan Nikhilesh 		return;
7601ff23ce6SPavan Nikhilesh 	}
7611ff23ce6SPavan Nikhilesh 
7621ff23ce6SPavan Nikhilesh 	if (dev->dev_ops->port_quiesce)
7631ff23ce6SPavan Nikhilesh 		(*dev->dev_ops->port_quiesce)(dev, dev->data->ports[port_id],
7641ff23ce6SPavan Nikhilesh 					      release_cb, args);
7651ff23ce6SPavan Nikhilesh }
7661ff23ce6SPavan Nikhilesh 
76799a2dd95SBruce Richardson int
76899a2dd95SBruce Richardson rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
76999a2dd95SBruce Richardson 		       uint32_t *attr_value)
77099a2dd95SBruce Richardson {
77199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
77299a2dd95SBruce Richardson 
77399a2dd95SBruce Richardson 	if (!attr_value)
77499a2dd95SBruce Richardson 		return -EINVAL;
77599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
77699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
77799a2dd95SBruce Richardson 
77899a2dd95SBruce Richardson 	switch (attr_id) {
77999a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_PORT_COUNT:
78099a2dd95SBruce Richardson 		*attr_value = dev->data->nb_ports;
78199a2dd95SBruce Richardson 		break;
78299a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
78399a2dd95SBruce Richardson 		*attr_value = dev->data->nb_queues;
78499a2dd95SBruce Richardson 		break;
78599a2dd95SBruce Richardson 	case RTE_EVENT_DEV_ATTR_STARTED:
78699a2dd95SBruce Richardson 		*attr_value = dev->data->dev_started;
78799a2dd95SBruce Richardson 		break;
78899a2dd95SBruce Richardson 	default:
78999a2dd95SBruce Richardson 		return -EINVAL;
79099a2dd95SBruce Richardson 	}
79199a2dd95SBruce Richardson 
79299a2dd95SBruce Richardson 	return 0;
79399a2dd95SBruce Richardson }
79499a2dd95SBruce Richardson 
79599a2dd95SBruce Richardson int
79699a2dd95SBruce Richardson rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
79799a2dd95SBruce Richardson 			uint32_t *attr_value)
79899a2dd95SBruce Richardson {
79999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
80099a2dd95SBruce Richardson 
80199a2dd95SBruce Richardson 	if (!attr_value)
80299a2dd95SBruce Richardson 		return -EINVAL;
80399a2dd95SBruce Richardson 
80499a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
80599a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
80699a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
80799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
80899a2dd95SBruce Richardson 		return -EINVAL;
80999a2dd95SBruce Richardson 	}
81099a2dd95SBruce Richardson 
81199a2dd95SBruce Richardson 	switch (attr_id) {
81299a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
81399a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].enqueue_depth;
81499a2dd95SBruce Richardson 		break;
81599a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
81699a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].dequeue_depth;
81799a2dd95SBruce Richardson 		break;
81899a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD:
81999a2dd95SBruce Richardson 		*attr_value = dev->data->ports_cfg[port_id].new_event_threshold;
82099a2dd95SBruce Richardson 		break;
82199a2dd95SBruce Richardson 	case RTE_EVENT_PORT_ATTR_IMPLICIT_RELEASE_DISABLE:
82299a2dd95SBruce Richardson 	{
82399a2dd95SBruce Richardson 		uint32_t config;
82499a2dd95SBruce Richardson 
82599a2dd95SBruce Richardson 		config = dev->data->ports_cfg[port_id].event_port_cfg;
82699a2dd95SBruce Richardson 		*attr_value = !!(config & RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL);
82799a2dd95SBruce Richardson 		break;
82899a2dd95SBruce Richardson 	}
82999a2dd95SBruce Richardson 	default:
83099a2dd95SBruce Richardson 		return -EINVAL;
83199a2dd95SBruce Richardson 	};
83299a2dd95SBruce Richardson 	return 0;
83399a2dd95SBruce Richardson }
83499a2dd95SBruce Richardson 
83599a2dd95SBruce Richardson int
83699a2dd95SBruce Richardson rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
83799a2dd95SBruce Richardson 			uint32_t *attr_value)
83899a2dd95SBruce Richardson {
83999a2dd95SBruce Richardson 	struct rte_event_queue_conf *conf;
84099a2dd95SBruce Richardson 	struct rte_eventdev *dev;
84199a2dd95SBruce Richardson 
84299a2dd95SBruce Richardson 	if (!attr_value)
84399a2dd95SBruce Richardson 		return -EINVAL;
84499a2dd95SBruce Richardson 
84599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
84699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
84799a2dd95SBruce Richardson 	if (!is_valid_queue(dev, queue_id)) {
84899a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
84999a2dd95SBruce Richardson 		return -EINVAL;
85099a2dd95SBruce Richardson 	}
85199a2dd95SBruce Richardson 
85299a2dd95SBruce Richardson 	conf = &dev->data->queues_cfg[queue_id];
85399a2dd95SBruce Richardson 
85499a2dd95SBruce Richardson 	switch (attr_id) {
85599a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_PRIORITY:
85699a2dd95SBruce Richardson 		*attr_value = RTE_EVENT_DEV_PRIORITY_NORMAL;
85799a2dd95SBruce Richardson 		if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
85899a2dd95SBruce Richardson 			*attr_value = conf->priority;
85999a2dd95SBruce Richardson 		break;
86099a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS:
86199a2dd95SBruce Richardson 		*attr_value = conf->nb_atomic_flows;
86299a2dd95SBruce Richardson 		break;
86399a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES:
86499a2dd95SBruce Richardson 		*attr_value = conf->nb_atomic_order_sequences;
86599a2dd95SBruce Richardson 		break;
86699a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG:
86799a2dd95SBruce Richardson 		*attr_value = conf->event_queue_cfg;
86899a2dd95SBruce Richardson 		break;
86999a2dd95SBruce Richardson 	case RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE:
87099a2dd95SBruce Richardson 		if (conf->event_queue_cfg & RTE_EVENT_QUEUE_CFG_ALL_TYPES)
87199a2dd95SBruce Richardson 			return -EOVERFLOW;
87299a2dd95SBruce Richardson 
87399a2dd95SBruce Richardson 		*attr_value = conf->schedule_type;
87499a2dd95SBruce Richardson 		break;
87544516e6bSShijith Thotton 	case RTE_EVENT_QUEUE_ATTR_WEIGHT:
87644516e6bSShijith Thotton 		*attr_value = RTE_EVENT_QUEUE_WEIGHT_LOWEST;
8772f279a1bSShijith Thotton 		if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
8782f279a1bSShijith Thotton 			*attr_value = conf->weight;
87944516e6bSShijith Thotton 		break;
88044516e6bSShijith Thotton 	case RTE_EVENT_QUEUE_ATTR_AFFINITY:
88144516e6bSShijith Thotton 		*attr_value = RTE_EVENT_QUEUE_AFFINITY_LOWEST;
8822f279a1bSShijith Thotton 		if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
8832f279a1bSShijith Thotton 			*attr_value = conf->affinity;
88444516e6bSShijith Thotton 		break;
88599a2dd95SBruce Richardson 	default:
88699a2dd95SBruce Richardson 		return -EINVAL;
88799a2dd95SBruce Richardson 	};
88899a2dd95SBruce Richardson 	return 0;
88999a2dd95SBruce Richardson }
89099a2dd95SBruce Richardson 
89199a2dd95SBruce Richardson int
89297b914f4SShijith Thotton rte_event_queue_attr_set(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
89397b914f4SShijith Thotton 			 uint64_t attr_value)
89497b914f4SShijith Thotton {
89597b914f4SShijith Thotton 	struct rte_eventdev *dev;
89697b914f4SShijith Thotton 
89797b914f4SShijith Thotton 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
89897b914f4SShijith Thotton 	dev = &rte_eventdevs[dev_id];
89997b914f4SShijith Thotton 	if (!is_valid_queue(dev, queue_id)) {
90097b914f4SShijith Thotton 		RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
90197b914f4SShijith Thotton 		return -EINVAL;
90297b914f4SShijith Thotton 	}
90397b914f4SShijith Thotton 
90497b914f4SShijith Thotton 	if (!(dev->data->event_dev_cap &
90597b914f4SShijith Thotton 	      RTE_EVENT_DEV_CAP_RUNTIME_QUEUE_ATTR)) {
90697b914f4SShijith Thotton 		RTE_EDEV_LOG_ERR(
90797b914f4SShijith Thotton 			"Device %" PRIu8 "does not support changing queue attributes at runtime",
90897b914f4SShijith Thotton 			dev_id);
90997b914f4SShijith Thotton 		return -ENOTSUP;
91097b914f4SShijith Thotton 	}
91197b914f4SShijith Thotton 
9128f1d23ecSDavid Marchand 	if (*dev->dev_ops->queue_attr_set == NULL)
9138f1d23ecSDavid Marchand 		return -ENOTSUP;
91497b914f4SShijith Thotton 	return (*dev->dev_ops->queue_attr_set)(dev, queue_id, attr_id,
91597b914f4SShijith Thotton 					       attr_value);
91697b914f4SShijith Thotton }
91797b914f4SShijith Thotton 
91897b914f4SShijith Thotton int
91999a2dd95SBruce Richardson rte_event_port_link(uint8_t dev_id, uint8_t port_id,
92099a2dd95SBruce Richardson 		    const uint8_t queues[], const uint8_t priorities[],
92199a2dd95SBruce Richardson 		    uint16_t nb_links)
92299a2dd95SBruce Richardson {
92399a2dd95SBruce Richardson 	struct rte_eventdev *dev;
92499a2dd95SBruce Richardson 	uint8_t queues_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
92599a2dd95SBruce Richardson 	uint8_t priorities_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
92699a2dd95SBruce Richardson 	uint16_t *links_map;
92799a2dd95SBruce Richardson 	int i, diag;
92899a2dd95SBruce Richardson 
92999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
93099a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
93199a2dd95SBruce Richardson 
93299a2dd95SBruce Richardson 	if (*dev->dev_ops->port_link == NULL) {
93399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Function not supported\n");
93499a2dd95SBruce Richardson 		rte_errno = ENOTSUP;
93599a2dd95SBruce Richardson 		return 0;
93699a2dd95SBruce Richardson 	}
93799a2dd95SBruce Richardson 
93899a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
93999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
94099a2dd95SBruce Richardson 		rte_errno = EINVAL;
94199a2dd95SBruce Richardson 		return 0;
94299a2dd95SBruce Richardson 	}
94399a2dd95SBruce Richardson 
94499a2dd95SBruce Richardson 	if (queues == NULL) {
94599a2dd95SBruce Richardson 		for (i = 0; i < dev->data->nb_queues; i++)
94699a2dd95SBruce Richardson 			queues_list[i] = i;
94799a2dd95SBruce Richardson 
94899a2dd95SBruce Richardson 		queues = queues_list;
94999a2dd95SBruce Richardson 		nb_links = dev->data->nb_queues;
95099a2dd95SBruce Richardson 	}
95199a2dd95SBruce Richardson 
95299a2dd95SBruce Richardson 	if (priorities == NULL) {
95399a2dd95SBruce Richardson 		for (i = 0; i < nb_links; i++)
95499a2dd95SBruce Richardson 			priorities_list[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
95599a2dd95SBruce Richardson 
95699a2dd95SBruce Richardson 		priorities = priorities_list;
95799a2dd95SBruce Richardson 	}
95899a2dd95SBruce Richardson 
95999a2dd95SBruce Richardson 	for (i = 0; i < nb_links; i++)
96099a2dd95SBruce Richardson 		if (queues[i] >= dev->data->nb_queues) {
96199a2dd95SBruce Richardson 			rte_errno = EINVAL;
96299a2dd95SBruce Richardson 			return 0;
96399a2dd95SBruce Richardson 		}
96499a2dd95SBruce Richardson 
96599a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
96699a2dd95SBruce Richardson 						queues, priorities, nb_links);
96799a2dd95SBruce Richardson 	if (diag < 0)
96899a2dd95SBruce Richardson 		return diag;
96999a2dd95SBruce Richardson 
97099a2dd95SBruce Richardson 	links_map = dev->data->links_map;
97199a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
97299a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
97399a2dd95SBruce Richardson 	for (i = 0; i < diag; i++)
97499a2dd95SBruce Richardson 		links_map[queues[i]] = (uint8_t)priorities[i];
97599a2dd95SBruce Richardson 
97699a2dd95SBruce Richardson 	rte_eventdev_trace_port_link(dev_id, port_id, nb_links, diag);
97799a2dd95SBruce Richardson 	return diag;
97899a2dd95SBruce Richardson }
97999a2dd95SBruce Richardson 
98099a2dd95SBruce Richardson int
98199a2dd95SBruce Richardson rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
98299a2dd95SBruce Richardson 		      uint8_t queues[], uint16_t nb_unlinks)
98399a2dd95SBruce Richardson {
98499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
98599a2dd95SBruce Richardson 	uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
98699a2dd95SBruce Richardson 	int i, diag, j;
98799a2dd95SBruce Richardson 	uint16_t *links_map;
98899a2dd95SBruce Richardson 
98999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
99099a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
99199a2dd95SBruce Richardson 
99299a2dd95SBruce Richardson 	if (*dev->dev_ops->port_unlink == NULL) {
99399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Function not supported");
99499a2dd95SBruce Richardson 		rte_errno = ENOTSUP;
99599a2dd95SBruce Richardson 		return 0;
99699a2dd95SBruce Richardson 	}
99799a2dd95SBruce Richardson 
99899a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
99999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
100099a2dd95SBruce Richardson 		rte_errno = EINVAL;
100199a2dd95SBruce Richardson 		return 0;
100299a2dd95SBruce Richardson 	}
100399a2dd95SBruce Richardson 
100499a2dd95SBruce Richardson 	links_map = dev->data->links_map;
100599a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
100699a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
100799a2dd95SBruce Richardson 
100899a2dd95SBruce Richardson 	if (queues == NULL) {
100999a2dd95SBruce Richardson 		j = 0;
101099a2dd95SBruce Richardson 		for (i = 0; i < dev->data->nb_queues; i++) {
101199a2dd95SBruce Richardson 			if (links_map[i] !=
101299a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
101399a2dd95SBruce Richardson 				all_queues[j] = i;
101499a2dd95SBruce Richardson 				j++;
101599a2dd95SBruce Richardson 			}
101699a2dd95SBruce Richardson 		}
101799a2dd95SBruce Richardson 		queues = all_queues;
101899a2dd95SBruce Richardson 	} else {
101999a2dd95SBruce Richardson 		for (j = 0; j < nb_unlinks; j++) {
102099a2dd95SBruce Richardson 			if (links_map[queues[j]] ==
102199a2dd95SBruce Richardson 					EVENT_QUEUE_SERVICE_PRIORITY_INVALID)
102299a2dd95SBruce Richardson 				break;
102399a2dd95SBruce Richardson 		}
102499a2dd95SBruce Richardson 	}
102599a2dd95SBruce Richardson 
102699a2dd95SBruce Richardson 	nb_unlinks = j;
102799a2dd95SBruce Richardson 	for (i = 0; i < nb_unlinks; i++)
102899a2dd95SBruce Richardson 		if (queues[i] >= dev->data->nb_queues) {
102999a2dd95SBruce Richardson 			rte_errno = EINVAL;
103099a2dd95SBruce Richardson 			return 0;
103199a2dd95SBruce Richardson 		}
103299a2dd95SBruce Richardson 
103399a2dd95SBruce Richardson 	diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
103499a2dd95SBruce Richardson 					queues, nb_unlinks);
103599a2dd95SBruce Richardson 
103699a2dd95SBruce Richardson 	if (diag < 0)
103799a2dd95SBruce Richardson 		return diag;
103899a2dd95SBruce Richardson 
103999a2dd95SBruce Richardson 	for (i = 0; i < diag; i++)
104099a2dd95SBruce Richardson 		links_map[queues[i]] = EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
104199a2dd95SBruce Richardson 
104299a2dd95SBruce Richardson 	rte_eventdev_trace_port_unlink(dev_id, port_id, nb_unlinks, diag);
104399a2dd95SBruce Richardson 	return diag;
104499a2dd95SBruce Richardson }
104599a2dd95SBruce Richardson 
104699a2dd95SBruce Richardson int
104799a2dd95SBruce Richardson rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id)
104899a2dd95SBruce Richardson {
104999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
105099a2dd95SBruce Richardson 
105199a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
105299a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
105399a2dd95SBruce Richardson 	if (!is_valid_port(dev, port_id)) {
105499a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
105599a2dd95SBruce Richardson 		return -EINVAL;
105699a2dd95SBruce Richardson 	}
105799a2dd95SBruce Richardson 
105899a2dd95SBruce Richardson 	/* Return 0 if the PMD does not implement unlinks in progress.
105999a2dd95SBruce Richardson 	 * This allows PMDs which handle unlink synchronously to not implement
106099a2dd95SBruce Richardson 	 * this function at all.
106199a2dd95SBruce Richardson 	 */
10628f1d23ecSDavid Marchand 	if (*dev->dev_ops->port_unlinks_in_progress == NULL)
10638f1d23ecSDavid Marchand 		return 0;
106499a2dd95SBruce Richardson 
106599a2dd95SBruce Richardson 	return (*dev->dev_ops->port_unlinks_in_progress)(dev,
106699a2dd95SBruce Richardson 			dev->data->ports[port_id]);
106799a2dd95SBruce Richardson }
106899a2dd95SBruce Richardson 
106999a2dd95SBruce Richardson int
107099a2dd95SBruce Richardson rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
107199a2dd95SBruce Richardson 			 uint8_t queues[], uint8_t priorities[])
107299a2dd95SBruce Richardson {
107399a2dd95SBruce Richardson 	struct rte_eventdev *dev;
107499a2dd95SBruce Richardson 	uint16_t *links_map;
107599a2dd95SBruce Richardson 	int i, count = 0;
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 	links_map = dev->data->links_map;
108599a2dd95SBruce Richardson 	/* Point links_map to this port specific area */
108699a2dd95SBruce Richardson 	links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
108799a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_queues; i++) {
108899a2dd95SBruce Richardson 		if (links_map[i] != EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
108999a2dd95SBruce Richardson 			queues[count] = i;
109099a2dd95SBruce Richardson 			priorities[count] = (uint8_t)links_map[i];
109199a2dd95SBruce Richardson 			++count;
109299a2dd95SBruce Richardson 		}
109399a2dd95SBruce Richardson 	}
109499a2dd95SBruce Richardson 	return count;
109599a2dd95SBruce Richardson }
109699a2dd95SBruce Richardson 
109799a2dd95SBruce Richardson int
109899a2dd95SBruce Richardson rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
109999a2dd95SBruce Richardson 				 uint64_t *timeout_ticks)
110099a2dd95SBruce Richardson {
110199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
110299a2dd95SBruce Richardson 
110399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
110499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
11058f1d23ecSDavid Marchand 	if (*dev->dev_ops->timeout_ticks == NULL)
11068f1d23ecSDavid Marchand 		return -ENOTSUP;
110799a2dd95SBruce Richardson 
110899a2dd95SBruce Richardson 	if (timeout_ticks == NULL)
110999a2dd95SBruce Richardson 		return -EINVAL;
111099a2dd95SBruce Richardson 
111199a2dd95SBruce Richardson 	return (*dev->dev_ops->timeout_ticks)(dev, ns, timeout_ticks);
111299a2dd95SBruce Richardson }
111399a2dd95SBruce Richardson 
111499a2dd95SBruce Richardson int
111599a2dd95SBruce Richardson rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id)
111699a2dd95SBruce Richardson {
111799a2dd95SBruce Richardson 	struct rte_eventdev *dev;
111899a2dd95SBruce Richardson 
111999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
112099a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
112199a2dd95SBruce Richardson 
112299a2dd95SBruce Richardson 	if (service_id == NULL)
112399a2dd95SBruce Richardson 		return -EINVAL;
112499a2dd95SBruce Richardson 
112599a2dd95SBruce Richardson 	if (dev->data->service_inited)
112699a2dd95SBruce Richardson 		*service_id = dev->data->service_id;
112799a2dd95SBruce Richardson 
112899a2dd95SBruce Richardson 	return dev->data->service_inited ? 0 : -ESRCH;
112999a2dd95SBruce Richardson }
113099a2dd95SBruce Richardson 
113199a2dd95SBruce Richardson int
113299a2dd95SBruce Richardson rte_event_dev_dump(uint8_t dev_id, FILE *f)
113399a2dd95SBruce Richardson {
113499a2dd95SBruce Richardson 	struct rte_eventdev *dev;
113599a2dd95SBruce Richardson 
113699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
113799a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
11388f1d23ecSDavid Marchand 	if (*dev->dev_ops->dump == NULL)
11398f1d23ecSDavid Marchand 		return -ENOTSUP;
114099a2dd95SBruce Richardson 	if (f == NULL)
114199a2dd95SBruce Richardson 		return -EINVAL;
114299a2dd95SBruce Richardson 
114399a2dd95SBruce Richardson 	(*dev->dev_ops->dump)(dev, f);
114499a2dd95SBruce Richardson 	return 0;
114599a2dd95SBruce Richardson 
114699a2dd95SBruce Richardson }
114799a2dd95SBruce Richardson 
114899a2dd95SBruce Richardson static int
114999a2dd95SBruce Richardson xstats_get_count(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
115099a2dd95SBruce Richardson 		uint8_t queue_port_id)
115199a2dd95SBruce Richardson {
115299a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
115399a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get_names != NULL)
115499a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get_names)(dev, mode,
115599a2dd95SBruce Richardson 							queue_port_id,
115699a2dd95SBruce Richardson 							NULL, NULL, 0);
115799a2dd95SBruce Richardson 	return 0;
115899a2dd95SBruce Richardson }
115999a2dd95SBruce Richardson 
116099a2dd95SBruce Richardson int
116199a2dd95SBruce Richardson rte_event_dev_xstats_names_get(uint8_t dev_id,
116299a2dd95SBruce Richardson 		enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
116399a2dd95SBruce Richardson 		struct rte_event_dev_xstats_name *xstats_names,
11641bdfe4d7SPavan Nikhilesh 		uint64_t *ids, unsigned int size)
116599a2dd95SBruce Richardson {
116699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
116799a2dd95SBruce Richardson 	const int cnt_expected_entries = xstats_get_count(dev_id, mode,
116899a2dd95SBruce Richardson 							  queue_port_id);
116999a2dd95SBruce Richardson 	if (xstats_names == NULL || cnt_expected_entries < 0 ||
117099a2dd95SBruce Richardson 			(int)size < cnt_expected_entries)
117199a2dd95SBruce Richardson 		return cnt_expected_entries;
117299a2dd95SBruce Richardson 
117399a2dd95SBruce Richardson 	/* dev_id checked above */
117499a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
117599a2dd95SBruce Richardson 
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, xstats_names, ids, size);
117999a2dd95SBruce Richardson 
118099a2dd95SBruce Richardson 	return -ENOTSUP;
118199a2dd95SBruce Richardson }
118299a2dd95SBruce Richardson 
118399a2dd95SBruce Richardson /* retrieve eventdev extended statistics */
118499a2dd95SBruce Richardson int
118599a2dd95SBruce Richardson rte_event_dev_xstats_get(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
11861bdfe4d7SPavan Nikhilesh 		uint8_t queue_port_id, const uint64_t ids[],
118799a2dd95SBruce Richardson 		uint64_t values[], unsigned int n)
118899a2dd95SBruce Richardson {
118999a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
119099a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
119199a2dd95SBruce Richardson 
119299a2dd95SBruce Richardson 	/* implemented by the driver */
119399a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get != NULL)
119499a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get)(dev, mode, queue_port_id,
119599a2dd95SBruce Richardson 				ids, values, n);
119699a2dd95SBruce Richardson 	return -ENOTSUP;
119799a2dd95SBruce Richardson }
119899a2dd95SBruce Richardson 
119999a2dd95SBruce Richardson uint64_t
120099a2dd95SBruce Richardson rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
12011bdfe4d7SPavan Nikhilesh 		uint64_t *id)
120299a2dd95SBruce Richardson {
120399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, 0);
120499a2dd95SBruce Richardson 	const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
12051bdfe4d7SPavan Nikhilesh 	uint64_t temp = -1;
120699a2dd95SBruce Richardson 
120799a2dd95SBruce Richardson 	if (id != NULL)
120899a2dd95SBruce Richardson 		*id = (unsigned int)-1;
120999a2dd95SBruce Richardson 	else
121099a2dd95SBruce Richardson 		id = &temp; /* ensure driver never gets a NULL value */
121199a2dd95SBruce Richardson 
121299a2dd95SBruce Richardson 	/* implemented by driver */
121399a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_get_by_name != NULL)
121499a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_get_by_name)(dev, name, id);
121599a2dd95SBruce Richardson 	return -ENOTSUP;
121699a2dd95SBruce Richardson }
121799a2dd95SBruce Richardson 
121899a2dd95SBruce Richardson int rte_event_dev_xstats_reset(uint8_t dev_id,
121999a2dd95SBruce Richardson 		enum rte_event_dev_xstats_mode mode, int16_t queue_port_id,
12201bdfe4d7SPavan Nikhilesh 		const uint64_t ids[], uint32_t nb_ids)
122199a2dd95SBruce Richardson {
122299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
122399a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
122499a2dd95SBruce Richardson 
122599a2dd95SBruce Richardson 	if (dev->dev_ops->xstats_reset != NULL)
122699a2dd95SBruce Richardson 		return (*dev->dev_ops->xstats_reset)(dev, mode, queue_port_id,
122799a2dd95SBruce Richardson 							ids, nb_ids);
122899a2dd95SBruce Richardson 	return -ENOTSUP;
122999a2dd95SBruce Richardson }
123099a2dd95SBruce Richardson 
123199a2dd95SBruce Richardson int rte_event_pmd_selftest_seqn_dynfield_offset = -1;
123299a2dd95SBruce Richardson 
123399a2dd95SBruce Richardson int rte_event_dev_selftest(uint8_t dev_id)
123499a2dd95SBruce Richardson {
123599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
123699a2dd95SBruce Richardson 	static const struct rte_mbuf_dynfield test_seqn_dynfield_desc = {
123799a2dd95SBruce Richardson 		.name = "rte_event_pmd_selftest_seqn_dynfield",
123899a2dd95SBruce Richardson 		.size = sizeof(rte_event_pmd_selftest_seqn_t),
123999a2dd95SBruce Richardson 		.align = __alignof__(rte_event_pmd_selftest_seqn_t),
124099a2dd95SBruce Richardson 	};
124199a2dd95SBruce Richardson 	struct rte_eventdev *dev = &rte_eventdevs[dev_id];
124299a2dd95SBruce Richardson 
124399a2dd95SBruce Richardson 	if (dev->dev_ops->dev_selftest != NULL) {
124499a2dd95SBruce Richardson 		rte_event_pmd_selftest_seqn_dynfield_offset =
124599a2dd95SBruce Richardson 			rte_mbuf_dynfield_register(&test_seqn_dynfield_desc);
124699a2dd95SBruce Richardson 		if (rte_event_pmd_selftest_seqn_dynfield_offset < 0)
124799a2dd95SBruce Richardson 			return -ENOMEM;
124899a2dd95SBruce Richardson 		return (*dev->dev_ops->dev_selftest)();
124999a2dd95SBruce Richardson 	}
125099a2dd95SBruce Richardson 	return -ENOTSUP;
125199a2dd95SBruce Richardson }
125299a2dd95SBruce Richardson 
125399a2dd95SBruce Richardson struct rte_mempool *
125499a2dd95SBruce Richardson rte_event_vector_pool_create(const char *name, unsigned int n,
125599a2dd95SBruce Richardson 			     unsigned int cache_size, uint16_t nb_elem,
125699a2dd95SBruce Richardson 			     int socket_id)
125799a2dd95SBruce Richardson {
125899a2dd95SBruce Richardson 	const char *mp_ops_name;
125999a2dd95SBruce Richardson 	struct rte_mempool *mp;
126099a2dd95SBruce Richardson 	unsigned int elt_sz;
126199a2dd95SBruce Richardson 	int ret;
126299a2dd95SBruce Richardson 
126399a2dd95SBruce Richardson 	if (!nb_elem) {
126499a2dd95SBruce Richardson 		RTE_LOG(ERR, EVENTDEV,
126599a2dd95SBruce Richardson 			"Invalid number of elements=%d requested\n", nb_elem);
126699a2dd95SBruce Richardson 		rte_errno = EINVAL;
126799a2dd95SBruce Richardson 		return NULL;
126899a2dd95SBruce Richardson 	}
126999a2dd95SBruce Richardson 
127099a2dd95SBruce Richardson 	elt_sz =
127199a2dd95SBruce Richardson 		sizeof(struct rte_event_vector) + (nb_elem * sizeof(uintptr_t));
127299a2dd95SBruce Richardson 	mp = rte_mempool_create_empty(name, n, elt_sz, cache_size, 0, socket_id,
127399a2dd95SBruce Richardson 				      0);
127499a2dd95SBruce Richardson 	if (mp == NULL)
127599a2dd95SBruce Richardson 		return NULL;
127699a2dd95SBruce Richardson 
127799a2dd95SBruce Richardson 	mp_ops_name = rte_mbuf_best_mempool_ops();
127899a2dd95SBruce Richardson 	ret = rte_mempool_set_ops_byname(mp, mp_ops_name, NULL);
127999a2dd95SBruce Richardson 	if (ret != 0) {
128099a2dd95SBruce Richardson 		RTE_LOG(ERR, EVENTDEV, "error setting mempool handler\n");
128199a2dd95SBruce Richardson 		goto err;
128299a2dd95SBruce Richardson 	}
128399a2dd95SBruce Richardson 
128499a2dd95SBruce Richardson 	ret = rte_mempool_populate_default(mp);
128599a2dd95SBruce Richardson 	if (ret < 0)
128699a2dd95SBruce Richardson 		goto err;
128799a2dd95SBruce Richardson 
128899a2dd95SBruce Richardson 	return mp;
128999a2dd95SBruce Richardson err:
129099a2dd95SBruce Richardson 	rte_mempool_free(mp);
129199a2dd95SBruce Richardson 	rte_errno = -ret;
129299a2dd95SBruce Richardson 	return NULL;
129399a2dd95SBruce Richardson }
129499a2dd95SBruce Richardson 
129599a2dd95SBruce Richardson int
129699a2dd95SBruce Richardson rte_event_dev_start(uint8_t dev_id)
129799a2dd95SBruce Richardson {
129899a2dd95SBruce Richardson 	struct rte_eventdev *dev;
129999a2dd95SBruce Richardson 	int diag;
130099a2dd95SBruce Richardson 
130199a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
130299a2dd95SBruce Richardson 
130399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
130499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
13058f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_start == NULL)
13068f1d23ecSDavid Marchand 		return -ENOTSUP;
130799a2dd95SBruce Richardson 
130899a2dd95SBruce Richardson 	if (dev->data->dev_started != 0) {
130999a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already started",
131099a2dd95SBruce Richardson 			dev_id);
131199a2dd95SBruce Richardson 		return 0;
131299a2dd95SBruce Richardson 	}
131399a2dd95SBruce Richardson 
131499a2dd95SBruce Richardson 	diag = (*dev->dev_ops->dev_start)(dev);
131599a2dd95SBruce Richardson 	rte_eventdev_trace_start(dev_id, diag);
131699a2dd95SBruce Richardson 	if (diag == 0)
131799a2dd95SBruce Richardson 		dev->data->dev_started = 1;
131899a2dd95SBruce Richardson 	else
131999a2dd95SBruce Richardson 		return diag;
132099a2dd95SBruce Richardson 
1321d35e6132SPavan Nikhilesh 	event_dev_fp_ops_set(rte_event_fp_ops + dev_id, dev);
1322d35e6132SPavan Nikhilesh 
132399a2dd95SBruce Richardson 	return 0;
132499a2dd95SBruce Richardson }
132599a2dd95SBruce Richardson 
132699a2dd95SBruce Richardson int
132799a2dd95SBruce Richardson rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
1328d986276fSPavan Nikhilesh 					   rte_eventdev_stop_flush_t callback,
1329d986276fSPavan Nikhilesh 					   void *userdata)
133099a2dd95SBruce Richardson {
133199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
133299a2dd95SBruce Richardson 
133399a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Stop flush register dev_id=%" PRIu8, dev_id);
133499a2dd95SBruce Richardson 
133599a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
133699a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
133799a2dd95SBruce Richardson 
133899a2dd95SBruce Richardson 	dev->dev_ops->dev_stop_flush = callback;
133999a2dd95SBruce Richardson 	dev->data->dev_stop_flush_arg = userdata;
134099a2dd95SBruce Richardson 
134199a2dd95SBruce Richardson 	return 0;
134299a2dd95SBruce Richardson }
134399a2dd95SBruce Richardson 
134499a2dd95SBruce Richardson void
134599a2dd95SBruce Richardson rte_event_dev_stop(uint8_t dev_id)
134699a2dd95SBruce Richardson {
134799a2dd95SBruce Richardson 	struct rte_eventdev *dev;
134899a2dd95SBruce Richardson 
134999a2dd95SBruce Richardson 	RTE_EDEV_LOG_DEBUG("Stop dev_id=%" PRIu8, dev_id);
135099a2dd95SBruce Richardson 
135199a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
135299a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
13538f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_stop == NULL)
13548f1d23ecSDavid Marchand 		return;
135599a2dd95SBruce Richardson 
135699a2dd95SBruce Richardson 	if (dev->data->dev_started == 0) {
135799a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already stopped",
135899a2dd95SBruce Richardson 			dev_id);
135999a2dd95SBruce Richardson 		return;
136099a2dd95SBruce Richardson 	}
136199a2dd95SBruce Richardson 
136299a2dd95SBruce Richardson 	dev->data->dev_started = 0;
136399a2dd95SBruce Richardson 	(*dev->dev_ops->dev_stop)(dev);
136499a2dd95SBruce Richardson 	rte_eventdev_trace_stop(dev_id);
1365d35e6132SPavan Nikhilesh 	event_dev_fp_ops_reset(rte_event_fp_ops + dev_id);
136699a2dd95SBruce Richardson }
136799a2dd95SBruce Richardson 
136899a2dd95SBruce Richardson int
136999a2dd95SBruce Richardson rte_event_dev_close(uint8_t dev_id)
137099a2dd95SBruce Richardson {
137199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
137299a2dd95SBruce Richardson 
137399a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
137499a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
13758f1d23ecSDavid Marchand 	if (*dev->dev_ops->dev_close == NULL)
13768f1d23ecSDavid Marchand 		return -ENOTSUP;
137799a2dd95SBruce Richardson 
137899a2dd95SBruce Richardson 	/* Device must be stopped before it can be closed */
137999a2dd95SBruce Richardson 	if (dev->data->dev_started == 1) {
138099a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Device %u must be stopped before closing",
138199a2dd95SBruce Richardson 				dev_id);
138299a2dd95SBruce Richardson 		return -EBUSY;
138399a2dd95SBruce Richardson 	}
138499a2dd95SBruce Richardson 
1385d35e6132SPavan Nikhilesh 	event_dev_fp_ops_reset(rte_event_fp_ops + dev_id);
138699a2dd95SBruce Richardson 	rte_eventdev_trace_close(dev_id);
138799a2dd95SBruce Richardson 	return (*dev->dev_ops->dev_close)(dev);
138899a2dd95SBruce Richardson }
138999a2dd95SBruce Richardson 
139099a2dd95SBruce Richardson static inline int
13919c67fcbfSPavan Nikhilesh eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
139299a2dd95SBruce Richardson 		    int socket_id)
139399a2dd95SBruce Richardson {
139499a2dd95SBruce Richardson 	char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
139599a2dd95SBruce Richardson 	const struct rte_memzone *mz;
139699a2dd95SBruce Richardson 	int n;
139799a2dd95SBruce Richardson 
139899a2dd95SBruce Richardson 	/* Generate memzone name */
139999a2dd95SBruce Richardson 	n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
140099a2dd95SBruce Richardson 	if (n >= (int)sizeof(mz_name))
140199a2dd95SBruce Richardson 		return -EINVAL;
140299a2dd95SBruce Richardson 
140399a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
140499a2dd95SBruce Richardson 		mz = rte_memzone_reserve(mz_name,
140599a2dd95SBruce Richardson 				sizeof(struct rte_eventdev_data),
140699a2dd95SBruce Richardson 				socket_id, 0);
140799a2dd95SBruce Richardson 	} else
140899a2dd95SBruce Richardson 		mz = rte_memzone_lookup(mz_name);
140999a2dd95SBruce Richardson 
141099a2dd95SBruce Richardson 	if (mz == NULL)
141199a2dd95SBruce Richardson 		return -ENOMEM;
141299a2dd95SBruce Richardson 
141399a2dd95SBruce Richardson 	*data = mz->addr;
14149c67fcbfSPavan Nikhilesh 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
141599a2dd95SBruce Richardson 		memset(*data, 0, sizeof(struct rte_eventdev_data));
14169c67fcbfSPavan Nikhilesh 		for (n = 0; n < RTE_EVENT_MAX_PORTS_PER_DEV *
14179c67fcbfSPavan Nikhilesh 					RTE_EVENT_MAX_QUEUES_PER_DEV;
14189c67fcbfSPavan Nikhilesh 		     n++)
14199c67fcbfSPavan Nikhilesh 			(*data)->links_map[n] =
14209c67fcbfSPavan Nikhilesh 				EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
14219c67fcbfSPavan Nikhilesh 	}
142299a2dd95SBruce Richardson 
142399a2dd95SBruce Richardson 	return 0;
142499a2dd95SBruce Richardson }
142599a2dd95SBruce Richardson 
142699a2dd95SBruce Richardson static inline uint8_t
14279c67fcbfSPavan Nikhilesh eventdev_find_free_device_index(void)
142899a2dd95SBruce Richardson {
142999a2dd95SBruce Richardson 	uint8_t dev_id;
143099a2dd95SBruce Richardson 
143199a2dd95SBruce Richardson 	for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
143299a2dd95SBruce Richardson 		if (rte_eventdevs[dev_id].attached ==
143399a2dd95SBruce Richardson 				RTE_EVENTDEV_DETACHED)
143499a2dd95SBruce Richardson 			return dev_id;
143599a2dd95SBruce Richardson 	}
143699a2dd95SBruce Richardson 	return RTE_EVENT_MAX_DEVS;
143799a2dd95SBruce Richardson }
143899a2dd95SBruce Richardson 
143999a2dd95SBruce Richardson struct rte_eventdev *
144099a2dd95SBruce Richardson rte_event_pmd_allocate(const char *name, int socket_id)
144199a2dd95SBruce Richardson {
144299a2dd95SBruce Richardson 	struct rte_eventdev *eventdev;
144399a2dd95SBruce Richardson 	uint8_t dev_id;
144499a2dd95SBruce Richardson 
144599a2dd95SBruce Richardson 	if (rte_event_pmd_get_named_dev(name) != NULL) {
144699a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Event device with name %s already "
144799a2dd95SBruce Richardson 				"allocated!", name);
144899a2dd95SBruce Richardson 		return NULL;
144999a2dd95SBruce Richardson 	}
145099a2dd95SBruce Richardson 
14519c67fcbfSPavan Nikhilesh 	dev_id = eventdev_find_free_device_index();
145299a2dd95SBruce Richardson 	if (dev_id == RTE_EVENT_MAX_DEVS) {
145399a2dd95SBruce Richardson 		RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
145499a2dd95SBruce Richardson 		return NULL;
145599a2dd95SBruce Richardson 	}
145699a2dd95SBruce Richardson 
145799a2dd95SBruce Richardson 	eventdev = &rte_eventdevs[dev_id];
145899a2dd95SBruce Richardson 
145999a2dd95SBruce Richardson 	if (eventdev->data == NULL) {
146099a2dd95SBruce Richardson 		struct rte_eventdev_data *eventdev_data = NULL;
146199a2dd95SBruce Richardson 
14629c67fcbfSPavan Nikhilesh 		int retval =
14639c67fcbfSPavan Nikhilesh 			eventdev_data_alloc(dev_id, &eventdev_data, socket_id);
146499a2dd95SBruce Richardson 
146599a2dd95SBruce Richardson 		if (retval < 0 || eventdev_data == NULL)
146699a2dd95SBruce Richardson 			return NULL;
146799a2dd95SBruce Richardson 
146899a2dd95SBruce Richardson 		eventdev->data = eventdev_data;
146999a2dd95SBruce Richardson 
147099a2dd95SBruce Richardson 		if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
147199a2dd95SBruce Richardson 
147299a2dd95SBruce Richardson 			strlcpy(eventdev->data->name, name,
147399a2dd95SBruce Richardson 				RTE_EVENTDEV_NAME_MAX_LEN);
147499a2dd95SBruce Richardson 
147599a2dd95SBruce Richardson 			eventdev->data->dev_id = dev_id;
147699a2dd95SBruce Richardson 			eventdev->data->socket_id = socket_id;
147799a2dd95SBruce Richardson 			eventdev->data->dev_started = 0;
147899a2dd95SBruce Richardson 		}
147999a2dd95SBruce Richardson 
148099a2dd95SBruce Richardson 		eventdev->attached = RTE_EVENTDEV_ATTACHED;
148199a2dd95SBruce Richardson 		eventdev_globals.nb_devs++;
148299a2dd95SBruce Richardson 	}
148399a2dd95SBruce Richardson 
148499a2dd95SBruce Richardson 	return eventdev;
148599a2dd95SBruce Richardson }
148699a2dd95SBruce Richardson 
148799a2dd95SBruce Richardson int
148899a2dd95SBruce Richardson rte_event_pmd_release(struct rte_eventdev *eventdev)
148999a2dd95SBruce Richardson {
149099a2dd95SBruce Richardson 	int ret;
149199a2dd95SBruce Richardson 	char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
149299a2dd95SBruce Richardson 	const struct rte_memzone *mz;
149399a2dd95SBruce Richardson 
149499a2dd95SBruce Richardson 	if (eventdev == NULL)
149599a2dd95SBruce Richardson 		return -EINVAL;
149699a2dd95SBruce Richardson 
1497d35e6132SPavan Nikhilesh 	event_dev_fp_ops_reset(rte_event_fp_ops + eventdev->data->dev_id);
149899a2dd95SBruce Richardson 	eventdev->attached = RTE_EVENTDEV_DETACHED;
149999a2dd95SBruce Richardson 	eventdev_globals.nb_devs--;
150099a2dd95SBruce Richardson 
150199a2dd95SBruce Richardson 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
150299a2dd95SBruce Richardson 		rte_free(eventdev->data->dev_private);
150399a2dd95SBruce Richardson 
150499a2dd95SBruce Richardson 		/* Generate memzone name */
150599a2dd95SBruce Richardson 		ret = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u",
150699a2dd95SBruce Richardson 				eventdev->data->dev_id);
150799a2dd95SBruce Richardson 		if (ret >= (int)sizeof(mz_name))
150899a2dd95SBruce Richardson 			return -EINVAL;
150999a2dd95SBruce Richardson 
151099a2dd95SBruce Richardson 		mz = rte_memzone_lookup(mz_name);
151199a2dd95SBruce Richardson 		if (mz == NULL)
151299a2dd95SBruce Richardson 			return -ENOMEM;
151399a2dd95SBruce Richardson 
151499a2dd95SBruce Richardson 		ret = rte_memzone_free(mz);
151599a2dd95SBruce Richardson 		if (ret)
151699a2dd95SBruce Richardson 			return ret;
151799a2dd95SBruce Richardson 	}
151899a2dd95SBruce Richardson 
151999a2dd95SBruce Richardson 	eventdev->data = NULL;
152099a2dd95SBruce Richardson 	return 0;
152199a2dd95SBruce Richardson }
152299a2dd95SBruce Richardson 
1523d35e6132SPavan Nikhilesh void
1524d35e6132SPavan Nikhilesh event_dev_probing_finish(struct rte_eventdev *eventdev)
1525d35e6132SPavan Nikhilesh {
1526d35e6132SPavan Nikhilesh 	if (eventdev == NULL)
1527d35e6132SPavan Nikhilesh 		return;
1528d35e6132SPavan Nikhilesh 
1529d35e6132SPavan Nikhilesh 	event_dev_fp_ops_set(rte_event_fp_ops + eventdev->data->dev_id,
1530d35e6132SPavan Nikhilesh 			     eventdev);
1531d35e6132SPavan Nikhilesh }
153299a2dd95SBruce Richardson 
153399a2dd95SBruce Richardson static int
153499a2dd95SBruce Richardson handle_dev_list(const char *cmd __rte_unused,
153599a2dd95SBruce Richardson 		const char *params __rte_unused,
153699a2dd95SBruce Richardson 		struct rte_tel_data *d)
153799a2dd95SBruce Richardson {
153899a2dd95SBruce Richardson 	uint8_t dev_id;
153999a2dd95SBruce Richardson 	int ndev = rte_event_dev_count();
154099a2dd95SBruce Richardson 
154199a2dd95SBruce Richardson 	if (ndev < 1)
154299a2dd95SBruce Richardson 		return -1;
154399a2dd95SBruce Richardson 
154499a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
154599a2dd95SBruce Richardson 	for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
154699a2dd95SBruce Richardson 		if (rte_eventdevs[dev_id].attached ==
154799a2dd95SBruce Richardson 				RTE_EVENTDEV_ATTACHED)
154899a2dd95SBruce Richardson 			rte_tel_data_add_array_int(d, dev_id);
154999a2dd95SBruce Richardson 	}
155099a2dd95SBruce Richardson 
155199a2dd95SBruce Richardson 	return 0;
155299a2dd95SBruce Richardson }
155399a2dd95SBruce Richardson 
155499a2dd95SBruce Richardson static int
155599a2dd95SBruce Richardson handle_port_list(const char *cmd __rte_unused,
155699a2dd95SBruce Richardson 		 const char *params,
155799a2dd95SBruce Richardson 		 struct rte_tel_data *d)
155899a2dd95SBruce Richardson {
155999a2dd95SBruce Richardson 	int i;
156099a2dd95SBruce Richardson 	uint8_t dev_id;
156199a2dd95SBruce Richardson 	struct rte_eventdev *dev;
156299a2dd95SBruce Richardson 	char *end_param;
156399a2dd95SBruce Richardson 
156499a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
156599a2dd95SBruce Richardson 		return -1;
156699a2dd95SBruce Richardson 
156799a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
156899a2dd95SBruce Richardson 	if (*end_param != '\0')
156999a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
157099a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
157199a2dd95SBruce Richardson 
157299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
157399a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
157499a2dd95SBruce Richardson 
157599a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
157699a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_ports; i++)
157799a2dd95SBruce Richardson 		rte_tel_data_add_array_int(d, i);
157899a2dd95SBruce Richardson 
157999a2dd95SBruce Richardson 	return 0;
158099a2dd95SBruce Richardson }
158199a2dd95SBruce Richardson 
158299a2dd95SBruce Richardson static int
158399a2dd95SBruce Richardson handle_queue_list(const char *cmd __rte_unused,
158499a2dd95SBruce Richardson 		  const char *params,
158599a2dd95SBruce Richardson 		  struct rte_tel_data *d)
158699a2dd95SBruce Richardson {
158799a2dd95SBruce Richardson 	int i;
158899a2dd95SBruce Richardson 	uint8_t dev_id;
158999a2dd95SBruce Richardson 	struct rte_eventdev *dev;
159099a2dd95SBruce Richardson 	char *end_param;
159199a2dd95SBruce Richardson 
159299a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
159399a2dd95SBruce Richardson 		return -1;
159499a2dd95SBruce Richardson 
159599a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
159699a2dd95SBruce Richardson 	if (*end_param != '\0')
159799a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
159899a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
159999a2dd95SBruce Richardson 
160099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
160199a2dd95SBruce Richardson 	dev = &rte_eventdevs[dev_id];
160299a2dd95SBruce Richardson 
160399a2dd95SBruce Richardson 	rte_tel_data_start_array(d, RTE_TEL_INT_VAL);
160499a2dd95SBruce Richardson 	for (i = 0; i < dev->data->nb_queues; i++)
160599a2dd95SBruce Richardson 		rte_tel_data_add_array_int(d, i);
160699a2dd95SBruce Richardson 
160799a2dd95SBruce Richardson 	return 0;
160899a2dd95SBruce Richardson }
160999a2dd95SBruce Richardson 
161099a2dd95SBruce Richardson static int
161199a2dd95SBruce Richardson handle_queue_links(const char *cmd __rte_unused,
161299a2dd95SBruce Richardson 		   const char *params,
161399a2dd95SBruce Richardson 		   struct rte_tel_data *d)
161499a2dd95SBruce Richardson {
161599a2dd95SBruce Richardson 	int i, ret, port_id = 0;
161699a2dd95SBruce Richardson 	char *end_param;
161799a2dd95SBruce Richardson 	uint8_t dev_id;
161899a2dd95SBruce Richardson 	uint8_t queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
161999a2dd95SBruce Richardson 	uint8_t priorities[RTE_EVENT_MAX_QUEUES_PER_DEV];
162099a2dd95SBruce Richardson 	const char *p_param;
162199a2dd95SBruce Richardson 
162299a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
162399a2dd95SBruce Richardson 		return -1;
162499a2dd95SBruce Richardson 
162599a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
162699a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
162799a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
162899a2dd95SBruce Richardson 
162999a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
163099a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
163199a2dd95SBruce Richardson 		return -1;
163299a2dd95SBruce Richardson 
163399a2dd95SBruce Richardson 	port_id = strtoul(p_param, &end_param, 10);
163499a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
163599a2dd95SBruce Richardson 	if (p_param != NULL)
163699a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
163799a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
163899a2dd95SBruce Richardson 
163999a2dd95SBruce Richardson 	ret = rte_event_port_links_get(dev_id, port_id, queues, priorities);
164099a2dd95SBruce Richardson 	if (ret < 0)
164199a2dd95SBruce Richardson 		return -1;
164299a2dd95SBruce Richardson 
164399a2dd95SBruce Richardson 	rte_tel_data_start_dict(d);
164499a2dd95SBruce Richardson 	for (i = 0; i < ret; i++) {
164599a2dd95SBruce Richardson 		char qid_name[32];
164699a2dd95SBruce Richardson 
164799a2dd95SBruce Richardson 		snprintf(qid_name, 31, "qid_%u", queues[i]);
1648*af0785a2SBruce Richardson 		rte_tel_data_add_dict_uint(d, qid_name, priorities[i]);
164999a2dd95SBruce Richardson 	}
165099a2dd95SBruce Richardson 
165199a2dd95SBruce Richardson 	return 0;
165299a2dd95SBruce Richardson }
165399a2dd95SBruce Richardson 
165499a2dd95SBruce Richardson static int
165599a2dd95SBruce Richardson eventdev_build_telemetry_data(int dev_id,
165699a2dd95SBruce Richardson 			      enum rte_event_dev_xstats_mode mode,
165799a2dd95SBruce Richardson 			      int port_queue_id,
165899a2dd95SBruce Richardson 			      struct rte_tel_data *d)
165999a2dd95SBruce Richardson {
166099a2dd95SBruce Richardson 	struct rte_event_dev_xstats_name *xstat_names;
16611bdfe4d7SPavan Nikhilesh 	uint64_t *ids;
166299a2dd95SBruce Richardson 	uint64_t *values;
166399a2dd95SBruce Richardson 	int i, ret, num_xstats;
166499a2dd95SBruce Richardson 
166599a2dd95SBruce Richardson 	num_xstats = rte_event_dev_xstats_names_get(dev_id,
166699a2dd95SBruce Richardson 						    mode,
166799a2dd95SBruce Richardson 						    port_queue_id,
166899a2dd95SBruce Richardson 						    NULL,
166999a2dd95SBruce Richardson 						    NULL,
167099a2dd95SBruce Richardson 						    0);
167199a2dd95SBruce Richardson 
167299a2dd95SBruce Richardson 	if (num_xstats < 0)
167399a2dd95SBruce Richardson 		return -1;
167499a2dd95SBruce Richardson 
167599a2dd95SBruce Richardson 	/* use one malloc for names */
167699a2dd95SBruce Richardson 	xstat_names = malloc((sizeof(struct rte_event_dev_xstats_name))
167799a2dd95SBruce Richardson 			     * num_xstats);
167899a2dd95SBruce Richardson 	if (xstat_names == NULL)
167999a2dd95SBruce Richardson 		return -1;
168099a2dd95SBruce Richardson 
168199a2dd95SBruce Richardson 	ids = malloc((sizeof(unsigned int)) * num_xstats);
168299a2dd95SBruce Richardson 	if (ids == NULL) {
168399a2dd95SBruce Richardson 		free(xstat_names);
168499a2dd95SBruce Richardson 		return -1;
168599a2dd95SBruce Richardson 	}
168699a2dd95SBruce Richardson 
168799a2dd95SBruce Richardson 	values = malloc((sizeof(uint64_t)) * num_xstats);
168899a2dd95SBruce Richardson 	if (values == NULL) {
168999a2dd95SBruce Richardson 		free(xstat_names);
169099a2dd95SBruce Richardson 		free(ids);
169199a2dd95SBruce Richardson 		return -1;
169299a2dd95SBruce Richardson 	}
169399a2dd95SBruce Richardson 
169499a2dd95SBruce Richardson 	ret = rte_event_dev_xstats_names_get(dev_id, mode, port_queue_id,
169599a2dd95SBruce Richardson 					     xstat_names, ids, num_xstats);
169699a2dd95SBruce Richardson 	if (ret < 0 || ret > num_xstats) {
169799a2dd95SBruce Richardson 		free(xstat_names);
169899a2dd95SBruce Richardson 		free(ids);
169999a2dd95SBruce Richardson 		free(values);
170099a2dd95SBruce Richardson 		return -1;
170199a2dd95SBruce Richardson 	}
170299a2dd95SBruce Richardson 
170399a2dd95SBruce Richardson 	ret = rte_event_dev_xstats_get(dev_id, mode, port_queue_id,
170499a2dd95SBruce Richardson 				       ids, values, num_xstats);
170599a2dd95SBruce Richardson 	if (ret < 0 || ret > num_xstats) {
170699a2dd95SBruce Richardson 		free(xstat_names);
170799a2dd95SBruce Richardson 		free(ids);
170899a2dd95SBruce Richardson 		free(values);
170999a2dd95SBruce Richardson 		return -1;
171099a2dd95SBruce Richardson 	}
171199a2dd95SBruce Richardson 
171299a2dd95SBruce Richardson 	rte_tel_data_start_dict(d);
171399a2dd95SBruce Richardson 	for (i = 0; i < num_xstats; i++)
1714*af0785a2SBruce Richardson 		rte_tel_data_add_dict_uint(d, xstat_names[i].name, values[i]);
171599a2dd95SBruce Richardson 
171699a2dd95SBruce Richardson 	free(xstat_names);
171799a2dd95SBruce Richardson 	free(ids);
171899a2dd95SBruce Richardson 	free(values);
171999a2dd95SBruce Richardson 	return 0;
172099a2dd95SBruce Richardson }
172199a2dd95SBruce Richardson 
172299a2dd95SBruce Richardson static int
172399a2dd95SBruce Richardson handle_dev_xstats(const char *cmd __rte_unused,
172499a2dd95SBruce Richardson 		  const char *params,
172599a2dd95SBruce Richardson 		  struct rte_tel_data *d)
172699a2dd95SBruce Richardson {
172799a2dd95SBruce Richardson 	int dev_id;
172899a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
172999a2dd95SBruce Richardson 	char *end_param;
173099a2dd95SBruce Richardson 
173199a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
173299a2dd95SBruce Richardson 		return -1;
173399a2dd95SBruce Richardson 
173499a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
173599a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
173699a2dd95SBruce Richardson 	if (*end_param != '\0')
173799a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
173899a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
173999a2dd95SBruce Richardson 
174099a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
174199a2dd95SBruce Richardson 
174299a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_DEVICE;
174399a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, 0, d);
174499a2dd95SBruce Richardson }
174599a2dd95SBruce Richardson 
174699a2dd95SBruce Richardson static int
174799a2dd95SBruce Richardson handle_port_xstats(const char *cmd __rte_unused,
174899a2dd95SBruce Richardson 		   const char *params,
174999a2dd95SBruce Richardson 		   struct rte_tel_data *d)
175099a2dd95SBruce Richardson {
175199a2dd95SBruce Richardson 	int dev_id;
175299a2dd95SBruce Richardson 	int port_queue_id = 0;
175399a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
175499a2dd95SBruce Richardson 	char *end_param;
175599a2dd95SBruce Richardson 	const char *p_param;
175699a2dd95SBruce Richardson 
175799a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
175899a2dd95SBruce Richardson 		return -1;
175999a2dd95SBruce Richardson 
176099a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
176199a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
176299a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
176399a2dd95SBruce Richardson 
176499a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
176599a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_PORT;
176699a2dd95SBruce Richardson 
176799a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
176899a2dd95SBruce Richardson 		return -1;
176999a2dd95SBruce Richardson 
177099a2dd95SBruce Richardson 	port_queue_id = strtoul(p_param, &end_param, 10);
177199a2dd95SBruce Richardson 
177299a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
177399a2dd95SBruce Richardson 	if (p_param != NULL)
177499a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
177599a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
177699a2dd95SBruce Richardson 
177799a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, port_queue_id, d);
177899a2dd95SBruce Richardson }
177999a2dd95SBruce Richardson 
178099a2dd95SBruce Richardson static int
178199a2dd95SBruce Richardson handle_queue_xstats(const char *cmd __rte_unused,
178299a2dd95SBruce Richardson 		    const char *params,
178399a2dd95SBruce Richardson 		    struct rte_tel_data *d)
178499a2dd95SBruce Richardson {
178599a2dd95SBruce Richardson 	int dev_id;
178699a2dd95SBruce Richardson 	int port_queue_id = 0;
178799a2dd95SBruce Richardson 	enum rte_event_dev_xstats_mode mode;
178899a2dd95SBruce Richardson 	char *end_param;
178999a2dd95SBruce Richardson 	const char *p_param;
179099a2dd95SBruce Richardson 
179199a2dd95SBruce Richardson 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
179299a2dd95SBruce Richardson 		return -1;
179399a2dd95SBruce Richardson 
179499a2dd95SBruce Richardson 	/* Get dev ID from parameter string */
179599a2dd95SBruce Richardson 	dev_id = strtoul(params, &end_param, 10);
179699a2dd95SBruce Richardson 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
179799a2dd95SBruce Richardson 
179899a2dd95SBruce Richardson 	p_param = strtok(end_param, ",");
179999a2dd95SBruce Richardson 	mode = RTE_EVENT_DEV_XSTATS_QUEUE;
180099a2dd95SBruce Richardson 
180199a2dd95SBruce Richardson 	if (p_param == NULL || strlen(p_param) == 0 || !isdigit(*p_param))
180299a2dd95SBruce Richardson 		return -1;
180399a2dd95SBruce Richardson 
180499a2dd95SBruce Richardson 	port_queue_id = strtoul(p_param, &end_param, 10);
180599a2dd95SBruce Richardson 
180699a2dd95SBruce Richardson 	p_param = strtok(NULL, "\0");
180799a2dd95SBruce Richardson 	if (p_param != NULL)
180899a2dd95SBruce Richardson 		RTE_EDEV_LOG_DEBUG(
180999a2dd95SBruce Richardson 			"Extra parameters passed to eventdev telemetry command, ignoring");
181099a2dd95SBruce Richardson 
181199a2dd95SBruce Richardson 	return eventdev_build_telemetry_data(dev_id, mode, port_queue_id, d);
181299a2dd95SBruce Richardson }
181399a2dd95SBruce Richardson 
1814a3b7b476SChengwen Feng static int
1815a3b7b476SChengwen Feng handle_dev_dump(const char *cmd __rte_unused,
1816a3b7b476SChengwen Feng 		const char *params,
1817a3b7b476SChengwen Feng 		struct rte_tel_data *d)
1818a3b7b476SChengwen Feng {
1819a3b7b476SChengwen Feng 	char *buf, *end_param;
1820a3b7b476SChengwen Feng 	int dev_id, ret;
1821a3b7b476SChengwen Feng 	FILE *f;
1822a3b7b476SChengwen Feng 
1823a3b7b476SChengwen Feng 	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
1824a3b7b476SChengwen Feng 		return -1;
1825a3b7b476SChengwen Feng 
1826a3b7b476SChengwen Feng 	/* Get dev ID from parameter string */
1827a3b7b476SChengwen Feng 	dev_id = strtoul(params, &end_param, 10);
1828a3b7b476SChengwen Feng 	if (*end_param != '\0')
1829a3b7b476SChengwen Feng 		RTE_EDEV_LOG_DEBUG(
1830a3b7b476SChengwen Feng 			"Extra parameters passed to eventdev telemetry command, ignoring");
1831a3b7b476SChengwen Feng 
1832a3b7b476SChengwen Feng 	RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1833a3b7b476SChengwen Feng 
1834a3b7b476SChengwen Feng 	buf = calloc(sizeof(char), RTE_TEL_MAX_SINGLE_STRING_LEN);
1835a3b7b476SChengwen Feng 	if (buf == NULL)
1836a3b7b476SChengwen Feng 		return -ENOMEM;
1837a3b7b476SChengwen Feng 
1838a3b7b476SChengwen Feng 	f = fmemopen(buf, RTE_TEL_MAX_SINGLE_STRING_LEN - 1, "w+");
1839a3b7b476SChengwen Feng 	if (f == NULL) {
1840a3b7b476SChengwen Feng 		free(buf);
1841a3b7b476SChengwen Feng 		return -EINVAL;
1842a3b7b476SChengwen Feng 	}
1843a3b7b476SChengwen Feng 
1844a3b7b476SChengwen Feng 	ret = rte_event_dev_dump(dev_id, f);
1845a3b7b476SChengwen Feng 	fclose(f);
1846a3b7b476SChengwen Feng 	if (ret == 0) {
1847a3b7b476SChengwen Feng 		rte_tel_data_start_dict(d);
1848a3b7b476SChengwen Feng 		rte_tel_data_string(d, buf);
1849a3b7b476SChengwen Feng 	}
1850a3b7b476SChengwen Feng 
1851a3b7b476SChengwen Feng 	free(buf);
1852a3b7b476SChengwen Feng 	return ret;
1853a3b7b476SChengwen Feng }
1854a3b7b476SChengwen Feng 
185599a2dd95SBruce Richardson RTE_INIT(eventdev_init_telemetry)
185699a2dd95SBruce Richardson {
185799a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/dev_list", handle_dev_list,
185899a2dd95SBruce Richardson 			"Returns list of available eventdevs. Takes no parameters");
185999a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/port_list", handle_port_list,
186099a2dd95SBruce Richardson 			"Returns list of available ports. Parameter: DevID");
186199a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_list", handle_queue_list,
186299a2dd95SBruce Richardson 			"Returns list of available queues. Parameter: DevID");
186399a2dd95SBruce Richardson 
186499a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/dev_xstats", handle_dev_xstats,
186599a2dd95SBruce Richardson 			"Returns stats for an eventdev. Parameter: DevID");
186699a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/port_xstats", handle_port_xstats,
186799a2dd95SBruce Richardson 			"Returns stats for an eventdev port. Params: DevID,PortID");
186899a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_xstats",
186999a2dd95SBruce Richardson 			handle_queue_xstats,
187099a2dd95SBruce Richardson 			"Returns stats for an eventdev queue. Params: DevID,QueueID");
1871a3b7b476SChengwen Feng 	rte_telemetry_register_cmd("/eventdev/dev_dump", handle_dev_dump,
1872a3b7b476SChengwen Feng 			"Returns dump information for an eventdev. Parameter: DevID");
187399a2dd95SBruce Richardson 	rte_telemetry_register_cmd("/eventdev/queue_links", handle_queue_links,
187499a2dd95SBruce Richardson 			"Returns links for an eventdev port. Params: DevID,QueueID");
187599a2dd95SBruce Richardson }
1876