1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Cavium, Inc
13 #include <sys/types.h>
14 #include <sys/queue.h>
16 #include <rte_byteorder.h>
18 #include <rte_debug.h>
20 #include <rte_memory.h>
21 #include <rte_memcpy.h>
22 #include <rte_memzone.h>
24 #include <rte_per_lcore.h>
25 #include <rte_lcore.h>
26 #include <rte_atomic.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_common.h>
29 #include <rte_malloc.h>
30 #include <rte_errno.h>
31 #include <rte_ethdev.h>
32 #include <rte_cryptodev.h>
33 #include <rte_cryptodev_pmd.h>
35 #include "rte_eventdev.h"
36 #include "rte_eventdev_pmd.h"
38 struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
40 struct rte_eventdev *rte_eventdevs = &rte_event_devices[0];
42 static struct rte_eventdev_global eventdev_globals = {
46 struct rte_eventdev_global *rte_eventdev_globals = &eventdev_globals;
48 /* Event dev north bound API implementation */
51 rte_event_dev_count(void)
53 return rte_eventdev_globals->nb_devs;
57 rte_event_dev_get_dev_id(const char *name)
65 for (i = 0; i < rte_eventdev_globals->nb_devs; i++) {
66 cmp = (strncmp(rte_event_devices[i].data->name, name,
67 RTE_EVENTDEV_NAME_MAX_LEN) == 0) ||
68 (rte_event_devices[i].dev ? (strncmp(
69 rte_event_devices[i].dev->driver->name, name,
70 RTE_EVENTDEV_NAME_MAX_LEN) == 0) : 0);
71 if (cmp && (rte_event_devices[i].attached ==
72 RTE_EVENTDEV_ATTACHED))
79 rte_event_dev_socket_id(uint8_t dev_id)
81 struct rte_eventdev *dev;
83 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
84 dev = &rte_eventdevs[dev_id];
86 return dev->data->socket_id;
90 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
92 struct rte_eventdev *dev;
94 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
95 dev = &rte_eventdevs[dev_id];
100 memset(dev_info, 0, sizeof(struct rte_event_dev_info));
102 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
103 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
105 dev_info->dequeue_timeout_ns = dev->data->dev_conf.dequeue_timeout_ns;
107 dev_info->dev = dev->dev;
112 rte_event_eth_rx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
115 struct rte_eventdev *dev;
117 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
118 RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
120 dev = &rte_eventdevs[dev_id];
126 return dev->dev_ops->eth_rx_adapter_caps_get ?
127 (*dev->dev_ops->eth_rx_adapter_caps_get)(dev,
128 &rte_eth_devices[eth_port_id],
133 int __rte_experimental
134 rte_event_timer_adapter_caps_get(uint8_t dev_id, uint32_t *caps)
136 struct rte_eventdev *dev;
137 const struct rte_event_timer_adapter_ops *ops;
139 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
141 dev = &rte_eventdevs[dev_id];
147 return dev->dev_ops->timer_adapter_caps_get ?
148 (*dev->dev_ops->timer_adapter_caps_get)(dev,
155 int __rte_experimental
156 rte_event_crypto_adapter_caps_get(uint8_t dev_id, uint8_t cdev_id,
159 struct rte_eventdev *dev;
160 struct rte_cryptodev *cdev;
162 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
163 if (!rte_cryptodev_pmd_is_valid_dev(cdev_id))
166 dev = &rte_eventdevs[dev_id];
167 cdev = rte_cryptodev_pmd_get_dev(cdev_id);
173 return dev->dev_ops->crypto_adapter_caps_get ?
174 (*dev->dev_ops->crypto_adapter_caps_get)
175 (dev, cdev, caps) : -ENOTSUP;
178 int __rte_experimental
179 rte_event_eth_tx_adapter_caps_get(uint8_t dev_id, uint16_t eth_port_id,
182 struct rte_eventdev *dev;
183 struct rte_eth_dev *eth_dev;
185 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
186 RTE_ETH_VALID_PORTID_OR_ERR_RET(eth_port_id, -EINVAL);
188 dev = &rte_eventdevs[dev_id];
189 eth_dev = &rte_eth_devices[eth_port_id];
196 return dev->dev_ops->eth_tx_adapter_caps_get ?
197 (*dev->dev_ops->eth_tx_adapter_caps_get)(dev,
204 rte_event_dev_queue_config(struct rte_eventdev *dev, uint8_t nb_queues)
206 uint8_t old_nb_queues = dev->data->nb_queues;
207 struct rte_event_queue_conf *queues_cfg;
210 RTE_EDEV_LOG_DEBUG("Setup %d queues on device %u", nb_queues,
213 /* First time configuration */
214 if (dev->data->queues_cfg == NULL && nb_queues != 0) {
215 /* Allocate memory to store queue configuration */
216 dev->data->queues_cfg = rte_zmalloc_socket(
217 "eventdev->data->queues_cfg",
218 sizeof(dev->data->queues_cfg[0]) * nb_queues,
219 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
220 if (dev->data->queues_cfg == NULL) {
221 dev->data->nb_queues = 0;
222 RTE_EDEV_LOG_ERR("failed to get mem for queue cfg,"
223 "nb_queues %u", nb_queues);
227 } else if (dev->data->queues_cfg != NULL && nb_queues != 0) {
228 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
230 for (i = nb_queues; i < old_nb_queues; i++)
231 (*dev->dev_ops->queue_release)(dev, i);
233 /* Re allocate memory to store queue configuration */
234 queues_cfg = dev->data->queues_cfg;
235 queues_cfg = rte_realloc(queues_cfg,
236 sizeof(queues_cfg[0]) * nb_queues,
237 RTE_CACHE_LINE_SIZE);
238 if (queues_cfg == NULL) {
239 RTE_EDEV_LOG_ERR("failed to realloc queue cfg memory,"
240 " nb_queues %u", nb_queues);
243 dev->data->queues_cfg = queues_cfg;
245 if (nb_queues > old_nb_queues) {
246 uint8_t new_qs = nb_queues - old_nb_queues;
248 memset(queues_cfg + old_nb_queues, 0,
249 sizeof(queues_cfg[0]) * new_qs);
251 } else if (dev->data->queues_cfg != NULL && nb_queues == 0) {
252 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
254 for (i = nb_queues; i < old_nb_queues; i++)
255 (*dev->dev_ops->queue_release)(dev, i);
258 dev->data->nb_queues = nb_queues;
262 #define EVENT_QUEUE_SERVICE_PRIORITY_INVALID (0xdead)
265 rte_event_dev_port_config(struct rte_eventdev *dev, uint8_t nb_ports)
267 uint8_t old_nb_ports = dev->data->nb_ports;
270 struct rte_event_port_conf *ports_cfg;
273 RTE_EDEV_LOG_DEBUG("Setup %d ports on device %u", nb_ports,
276 /* First time configuration */
277 if (dev->data->ports == NULL && nb_ports != 0) {
278 dev->data->ports = rte_zmalloc_socket("eventdev->data->ports",
279 sizeof(dev->data->ports[0]) * nb_ports,
280 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
281 if (dev->data->ports == NULL) {
282 dev->data->nb_ports = 0;
283 RTE_EDEV_LOG_ERR("failed to get mem for port meta data,"
284 "nb_ports %u", nb_ports);
288 /* Allocate memory to store port configurations */
289 dev->data->ports_cfg =
290 rte_zmalloc_socket("eventdev->ports_cfg",
291 sizeof(dev->data->ports_cfg[0]) * nb_ports,
292 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
293 if (dev->data->ports_cfg == NULL) {
294 dev->data->nb_ports = 0;
295 RTE_EDEV_LOG_ERR("failed to get mem for port cfg,"
296 "nb_ports %u", nb_ports);
300 /* Allocate memory to store queue to port link connection */
301 dev->data->links_map =
302 rte_zmalloc_socket("eventdev->links_map",
303 sizeof(dev->data->links_map[0]) * nb_ports *
304 RTE_EVENT_MAX_QUEUES_PER_DEV,
305 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
306 if (dev->data->links_map == NULL) {
307 dev->data->nb_ports = 0;
308 RTE_EDEV_LOG_ERR("failed to get mem for port_map area,"
309 "nb_ports %u", nb_ports);
312 for (i = 0; i < nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV; i++)
313 dev->data->links_map[i] =
314 EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
315 } else if (dev->data->ports != NULL && nb_ports != 0) {/* re-config */
316 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
318 ports = dev->data->ports;
319 ports_cfg = dev->data->ports_cfg;
320 links_map = dev->data->links_map;
322 for (i = nb_ports; i < old_nb_ports; i++)
323 (*dev->dev_ops->port_release)(ports[i]);
325 /* Realloc memory for ports */
326 ports = rte_realloc(ports, sizeof(ports[0]) * nb_ports,
327 RTE_CACHE_LINE_SIZE);
329 RTE_EDEV_LOG_ERR("failed to realloc port meta data,"
330 " nb_ports %u", nb_ports);
334 /* Realloc memory for ports_cfg */
335 ports_cfg = rte_realloc(ports_cfg,
336 sizeof(ports_cfg[0]) * nb_ports,
337 RTE_CACHE_LINE_SIZE);
338 if (ports_cfg == NULL) {
339 RTE_EDEV_LOG_ERR("failed to realloc port cfg mem,"
340 " nb_ports %u", nb_ports);
344 /* Realloc memory to store queue to port link connection */
345 links_map = rte_realloc(links_map,
346 sizeof(dev->data->links_map[0]) * nb_ports *
347 RTE_EVENT_MAX_QUEUES_PER_DEV,
348 RTE_CACHE_LINE_SIZE);
349 if (links_map == NULL) {
350 dev->data->nb_ports = 0;
351 RTE_EDEV_LOG_ERR("failed to realloc mem for port_map,"
352 "nb_ports %u", nb_ports);
356 if (nb_ports > old_nb_ports) {
357 uint8_t new_ps = nb_ports - old_nb_ports;
358 unsigned int old_links_map_end =
359 old_nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
360 unsigned int links_map_end =
361 nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
363 memset(ports + old_nb_ports, 0,
364 sizeof(ports[0]) * new_ps);
365 memset(ports_cfg + old_nb_ports, 0,
366 sizeof(ports_cfg[0]) * new_ps);
367 for (i = old_links_map_end; i < links_map_end; i++)
369 EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
372 dev->data->ports = ports;
373 dev->data->ports_cfg = ports_cfg;
374 dev->data->links_map = links_map;
375 } else if (dev->data->ports != NULL && nb_ports == 0) {
376 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
378 ports = dev->data->ports;
379 for (i = nb_ports; i < old_nb_ports; i++)
380 (*dev->dev_ops->port_release)(ports[i]);
383 dev->data->nb_ports = nb_ports;
388 rte_event_dev_configure(uint8_t dev_id,
389 const struct rte_event_dev_config *dev_conf)
391 struct rte_eventdev *dev;
392 struct rte_event_dev_info info;
395 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
396 dev = &rte_eventdevs[dev_id];
398 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
399 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
401 if (dev->data->dev_started) {
403 "device %d must be stopped to allow configuration", dev_id);
407 if (dev_conf == NULL)
410 (*dev->dev_ops->dev_infos_get)(dev, &info);
412 /* Check dequeue_timeout_ns value is in limit */
413 if (!(dev_conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)) {
414 if (dev_conf->dequeue_timeout_ns &&
415 (dev_conf->dequeue_timeout_ns < info.min_dequeue_timeout_ns
416 || dev_conf->dequeue_timeout_ns >
417 info.max_dequeue_timeout_ns)) {
418 RTE_EDEV_LOG_ERR("dev%d invalid dequeue_timeout_ns=%d"
419 " min_dequeue_timeout_ns=%d max_dequeue_timeout_ns=%d",
420 dev_id, dev_conf->dequeue_timeout_ns,
421 info.min_dequeue_timeout_ns,
422 info.max_dequeue_timeout_ns);
427 /* Check nb_events_limit is in limit */
428 if (dev_conf->nb_events_limit > info.max_num_events) {
429 RTE_EDEV_LOG_ERR("dev%d nb_events_limit=%d > max_num_events=%d",
430 dev_id, dev_conf->nb_events_limit, info.max_num_events);
434 /* Check nb_event_queues is in limit */
435 if (!dev_conf->nb_event_queues) {
436 RTE_EDEV_LOG_ERR("dev%d nb_event_queues cannot be zero",
440 if (dev_conf->nb_event_queues > info.max_event_queues) {
441 RTE_EDEV_LOG_ERR("%d nb_event_queues=%d > max_event_queues=%d",
442 dev_id, dev_conf->nb_event_queues, info.max_event_queues);
446 /* Check nb_event_ports is in limit */
447 if (!dev_conf->nb_event_ports) {
448 RTE_EDEV_LOG_ERR("dev%d nb_event_ports cannot be zero", dev_id);
451 if (dev_conf->nb_event_ports > info.max_event_ports) {
452 RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d > max_event_ports= %d",
453 dev_id, dev_conf->nb_event_ports, info.max_event_ports);
457 /* Check nb_event_queue_flows is in limit */
458 if (!dev_conf->nb_event_queue_flows) {
459 RTE_EDEV_LOG_ERR("dev%d nb_flows cannot be zero", dev_id);
462 if (dev_conf->nb_event_queue_flows > info.max_event_queue_flows) {
463 RTE_EDEV_LOG_ERR("dev%d nb_flows=%x > max_flows=%x",
464 dev_id, dev_conf->nb_event_queue_flows,
465 info.max_event_queue_flows);
469 /* Check nb_event_port_dequeue_depth is in limit */
470 if (!dev_conf->nb_event_port_dequeue_depth) {
471 RTE_EDEV_LOG_ERR("dev%d nb_dequeue_depth cannot be zero",
475 if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
476 (dev_conf->nb_event_port_dequeue_depth >
477 info.max_event_port_dequeue_depth)) {
478 RTE_EDEV_LOG_ERR("dev%d nb_dq_depth=%d > max_dq_depth=%d",
479 dev_id, dev_conf->nb_event_port_dequeue_depth,
480 info.max_event_port_dequeue_depth);
484 /* Check nb_event_port_enqueue_depth is in limit */
485 if (!dev_conf->nb_event_port_enqueue_depth) {
486 RTE_EDEV_LOG_ERR("dev%d nb_enqueue_depth cannot be zero",
490 if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
491 (dev_conf->nb_event_port_enqueue_depth >
492 info.max_event_port_enqueue_depth)) {
493 RTE_EDEV_LOG_ERR("dev%d nb_enq_depth=%d > max_enq_depth=%d",
494 dev_id, dev_conf->nb_event_port_enqueue_depth,
495 info.max_event_port_enqueue_depth);
499 /* Copy the dev_conf parameter into the dev structure */
500 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
502 /* Setup new number of queues and reconfigure device. */
503 diag = rte_event_dev_queue_config(dev, dev_conf->nb_event_queues);
505 RTE_EDEV_LOG_ERR("dev%d rte_event_dev_queue_config = %d",
510 /* Setup new number of ports and reconfigure device. */
511 diag = rte_event_dev_port_config(dev, dev_conf->nb_event_ports);
513 rte_event_dev_queue_config(dev, 0);
514 RTE_EDEV_LOG_ERR("dev%d rte_event_dev_port_config = %d",
519 /* Configure the device */
520 diag = (*dev->dev_ops->dev_configure)(dev);
522 RTE_EDEV_LOG_ERR("dev%d dev_configure = %d", dev_id, diag);
523 rte_event_dev_queue_config(dev, 0);
524 rte_event_dev_port_config(dev, 0);
527 dev->data->event_dev_cap = info.event_dev_cap;
532 is_valid_queue(struct rte_eventdev *dev, uint8_t queue_id)
534 if (queue_id < dev->data->nb_queues && queue_id <
535 RTE_EVENT_MAX_QUEUES_PER_DEV)
542 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
543 struct rte_event_queue_conf *queue_conf)
545 struct rte_eventdev *dev;
547 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
548 dev = &rte_eventdevs[dev_id];
550 if (queue_conf == NULL)
553 if (!is_valid_queue(dev, queue_id)) {
554 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
558 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP);
559 memset(queue_conf, 0, sizeof(struct rte_event_queue_conf));
560 (*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
565 is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
568 !(queue_conf->event_queue_cfg &
569 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
570 ((queue_conf->event_queue_cfg &
571 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
572 (queue_conf->schedule_type
573 == RTE_SCHED_TYPE_ATOMIC)
581 is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
584 !(queue_conf->event_queue_cfg &
585 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
586 ((queue_conf->event_queue_cfg &
587 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
588 (queue_conf->schedule_type
589 == RTE_SCHED_TYPE_ORDERED)
598 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
599 const struct rte_event_queue_conf *queue_conf)
601 struct rte_eventdev *dev;
602 struct rte_event_queue_conf def_conf;
604 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
605 dev = &rte_eventdevs[dev_id];
607 if (!is_valid_queue(dev, queue_id)) {
608 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
612 /* Check nb_atomic_flows limit */
613 if (is_valid_atomic_queue_conf(queue_conf)) {
614 if (queue_conf->nb_atomic_flows == 0 ||
615 queue_conf->nb_atomic_flows >
616 dev->data->dev_conf.nb_event_queue_flows) {
618 "dev%d queue%d Invalid nb_atomic_flows=%d max_flows=%d",
619 dev_id, queue_id, queue_conf->nb_atomic_flows,
620 dev->data->dev_conf.nb_event_queue_flows);
625 /* Check nb_atomic_order_sequences limit */
626 if (is_valid_ordered_queue_conf(queue_conf)) {
627 if (queue_conf->nb_atomic_order_sequences == 0 ||
628 queue_conf->nb_atomic_order_sequences >
629 dev->data->dev_conf.nb_event_queue_flows) {
631 "dev%d queue%d Invalid nb_atomic_order_seq=%d max_flows=%d",
632 dev_id, queue_id, queue_conf->nb_atomic_order_sequences,
633 dev->data->dev_conf.nb_event_queue_flows);
638 if (dev->data->dev_started) {
640 "device %d must be stopped to allow queue setup", dev_id);
644 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
646 if (queue_conf == NULL) {
647 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf,
649 (*dev->dev_ops->queue_def_conf)(dev, queue_id, &def_conf);
650 queue_conf = &def_conf;
653 dev->data->queues_cfg[queue_id] = *queue_conf;
654 return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
658 is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
660 if (port_id < dev->data->nb_ports)
667 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
668 struct rte_event_port_conf *port_conf)
670 struct rte_eventdev *dev;
672 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
673 dev = &rte_eventdevs[dev_id];
675 if (port_conf == NULL)
678 if (!is_valid_port(dev, port_id)) {
679 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
683 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf, -ENOTSUP);
684 memset(port_conf, 0, sizeof(struct rte_event_port_conf));
685 (*dev->dev_ops->port_def_conf)(dev, port_id, port_conf);
690 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
691 const struct rte_event_port_conf *port_conf)
693 struct rte_eventdev *dev;
694 struct rte_event_port_conf def_conf;
697 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
698 dev = &rte_eventdevs[dev_id];
700 if (!is_valid_port(dev, port_id)) {
701 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
705 /* Check new_event_threshold limit */
706 if ((port_conf && !port_conf->new_event_threshold) ||
707 (port_conf && port_conf->new_event_threshold >
708 dev->data->dev_conf.nb_events_limit)) {
710 "dev%d port%d Invalid event_threshold=%d nb_events_limit=%d",
711 dev_id, port_id, port_conf->new_event_threshold,
712 dev->data->dev_conf.nb_events_limit);
716 /* Check dequeue_depth limit */
717 if ((port_conf && !port_conf->dequeue_depth) ||
718 (port_conf && port_conf->dequeue_depth >
719 dev->data->dev_conf.nb_event_port_dequeue_depth)) {
721 "dev%d port%d Invalid dequeue depth=%d max_dequeue_depth=%d",
722 dev_id, port_id, port_conf->dequeue_depth,
723 dev->data->dev_conf.nb_event_port_dequeue_depth);
727 /* Check enqueue_depth limit */
728 if ((port_conf && !port_conf->enqueue_depth) ||
729 (port_conf && port_conf->enqueue_depth >
730 dev->data->dev_conf.nb_event_port_enqueue_depth)) {
732 "dev%d port%d Invalid enqueue depth=%d max_enqueue_depth=%d",
733 dev_id, port_id, port_conf->enqueue_depth,
734 dev->data->dev_conf.nb_event_port_enqueue_depth);
738 if (port_conf && port_conf->disable_implicit_release &&
739 !(dev->data->event_dev_cap &
740 RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)) {
742 "dev%d port%d Implicit release disable not supported",
747 if (dev->data->dev_started) {
749 "device %d must be stopped to allow port setup", dev_id);
753 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_setup, -ENOTSUP);
755 if (port_conf == NULL) {
756 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf,
758 (*dev->dev_ops->port_def_conf)(dev, port_id, &def_conf);
759 port_conf = &def_conf;
762 dev->data->ports_cfg[port_id] = *port_conf;
764 diag = (*dev->dev_ops->port_setup)(dev, port_id, port_conf);
766 /* Unlink all the queues from this port(default state after setup) */
768 diag = rte_event_port_unlink(dev_id, port_id, NULL, 0);
777 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
778 uint32_t *attr_value)
780 struct rte_eventdev *dev;
784 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
785 dev = &rte_eventdevs[dev_id];
788 case RTE_EVENT_DEV_ATTR_PORT_COUNT:
789 *attr_value = dev->data->nb_ports;
791 case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
792 *attr_value = dev->data->nb_queues;
794 case RTE_EVENT_DEV_ATTR_STARTED:
795 *attr_value = dev->data->dev_started;
805 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
806 uint32_t *attr_value)
808 struct rte_eventdev *dev;
813 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
814 dev = &rte_eventdevs[dev_id];
815 if (!is_valid_port(dev, port_id)) {
816 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
821 case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
822 *attr_value = dev->data->ports_cfg[port_id].enqueue_depth;
824 case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
825 *attr_value = dev->data->ports_cfg[port_id].dequeue_depth;
827 case RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD:
828 *attr_value = dev->data->ports_cfg[port_id].new_event_threshold;
837 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
838 uint32_t *attr_value)
840 struct rte_event_queue_conf *conf;
841 struct rte_eventdev *dev;
846 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
847 dev = &rte_eventdevs[dev_id];
848 if (!is_valid_queue(dev, queue_id)) {
849 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
853 conf = &dev->data->queues_cfg[queue_id];
856 case RTE_EVENT_QUEUE_ATTR_PRIORITY:
857 *attr_value = RTE_EVENT_DEV_PRIORITY_NORMAL;
858 if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
859 *attr_value = conf->priority;
861 case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS:
862 *attr_value = conf->nb_atomic_flows;
864 case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES:
865 *attr_value = conf->nb_atomic_order_sequences;
867 case RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG:
868 *attr_value = conf->event_queue_cfg;
870 case RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE:
871 if (conf->event_queue_cfg & RTE_EVENT_QUEUE_CFG_ALL_TYPES)
874 *attr_value = conf->schedule_type;
883 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
884 const uint8_t queues[], const uint8_t priorities[],
887 struct rte_eventdev *dev;
888 uint8_t queues_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
889 uint8_t priorities_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
893 RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
894 dev = &rte_eventdevs[dev_id];
896 if (*dev->dev_ops->port_link == NULL) {
897 RTE_PMD_DEBUG_TRACE("Function not supported\n");
898 rte_errno = -ENOTSUP;
902 if (!is_valid_port(dev, port_id)) {
903 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
908 if (queues == NULL) {
909 for (i = 0; i < dev->data->nb_queues; i++)
912 queues = queues_list;
913 nb_links = dev->data->nb_queues;
916 if (priorities == NULL) {
917 for (i = 0; i < nb_links; i++)
918 priorities_list[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
920 priorities = priorities_list;
923 for (i = 0; i < nb_links; i++)
924 if (queues[i] >= dev->data->nb_queues) {
929 diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
930 queues, priorities, nb_links);
934 links_map = dev->data->links_map;
935 /* Point links_map to this port specific area */
936 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
937 for (i = 0; i < diag; i++)
938 links_map[queues[i]] = (uint8_t)priorities[i];
944 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
945 uint8_t queues[], uint16_t nb_unlinks)
947 struct rte_eventdev *dev;
948 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
952 RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
953 dev = &rte_eventdevs[dev_id];
955 if (*dev->dev_ops->port_unlink == NULL) {
956 RTE_PMD_DEBUG_TRACE("Function not supported\n");
957 rte_errno = -ENOTSUP;
961 if (!is_valid_port(dev, port_id)) {
962 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
967 links_map = dev->data->links_map;
968 /* Point links_map to this port specific area */
969 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
971 if (queues == NULL) {
973 for (i = 0; i < dev->data->nb_queues; i++) {
975 EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
982 for (j = 0; j < nb_unlinks; j++) {
983 if (links_map[queues[j]] ==
984 EVENT_QUEUE_SERVICE_PRIORITY_INVALID)
990 for (i = 0; i < nb_unlinks; i++)
991 if (queues[i] >= dev->data->nb_queues) {
996 diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
1002 for (i = 0; i < diag; i++)
1003 links_map[queues[i]] = EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
1008 int __rte_experimental
1009 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id)
1011 struct rte_eventdev *dev;
1013 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1014 dev = &rte_eventdevs[dev_id];
1015 if (!is_valid_port(dev, port_id)) {
1016 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
1020 /* Return 0 if the PMD does not implement unlinks in progress.
1021 * This allows PMDs which handle unlink synchronously to not implement
1022 * this function at all.
1024 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlinks_in_progress, 0);
1026 return (*dev->dev_ops->port_unlinks_in_progress)(dev,
1027 dev->data->ports[port_id]);
1031 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1032 uint8_t queues[], uint8_t priorities[])
1034 struct rte_eventdev *dev;
1035 uint16_t *links_map;
1038 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1039 dev = &rte_eventdevs[dev_id];
1040 if (!is_valid_port(dev, port_id)) {
1041 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
1045 links_map = dev->data->links_map;
1046 /* Point links_map to this port specific area */
1047 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
1048 for (i = 0; i < dev->data->nb_queues; i++) {
1049 if (links_map[i] != EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
1051 priorities[count] = (uint8_t)links_map[i];
1059 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1060 uint64_t *timeout_ticks)
1062 struct rte_eventdev *dev;
1064 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1065 dev = &rte_eventdevs[dev_id];
1066 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timeout_ticks, -ENOTSUP);
1068 if (timeout_ticks == NULL)
1071 return (*dev->dev_ops->timeout_ticks)(dev, ns, timeout_ticks);
1075 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id)
1077 struct rte_eventdev *dev;
1079 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1080 dev = &rte_eventdevs[dev_id];
1082 if (service_id == NULL)
1085 if (dev->data->service_inited)
1086 *service_id = dev->data->service_id;
1088 return dev->data->service_inited ? 0 : -ESRCH;
1092 rte_event_dev_dump(uint8_t dev_id, FILE *f)
1094 struct rte_eventdev *dev;
1096 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1097 dev = &rte_eventdevs[dev_id];
1098 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dump, -ENOTSUP);
1100 (*dev->dev_ops->dump)(dev, f);
1106 xstats_get_count(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
1107 uint8_t queue_port_id)
1109 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1110 if (dev->dev_ops->xstats_get_names != NULL)
1111 return (*dev->dev_ops->xstats_get_names)(dev, mode,
1118 rte_event_dev_xstats_names_get(uint8_t dev_id,
1119 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
1120 struct rte_event_dev_xstats_name *xstats_names,
1121 unsigned int *ids, unsigned int size)
1123 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
1124 const int cnt_expected_entries = xstats_get_count(dev_id, mode,
1126 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1127 (int)size < cnt_expected_entries)
1128 return cnt_expected_entries;
1130 /* dev_id checked above */
1131 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1133 if (dev->dev_ops->xstats_get_names != NULL)
1134 return (*dev->dev_ops->xstats_get_names)(dev, mode,
1135 queue_port_id, xstats_names, ids, size);
1140 /* retrieve eventdev extended statistics */
1142 rte_event_dev_xstats_get(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
1143 uint8_t queue_port_id, const unsigned int ids[],
1144 uint64_t values[], unsigned int n)
1146 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
1147 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1149 /* implemented by the driver */
1150 if (dev->dev_ops->xstats_get != NULL)
1151 return (*dev->dev_ops->xstats_get)(dev, mode, queue_port_id,
1157 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1160 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, 0);
1161 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1162 unsigned int temp = -1;
1165 *id = (unsigned int)-1;
1167 id = &temp; /* ensure driver never gets a NULL value */
1169 /* implemented by driver */
1170 if (dev->dev_ops->xstats_get_by_name != NULL)
1171 return (*dev->dev_ops->xstats_get_by_name)(dev, name, id);
1175 int rte_event_dev_xstats_reset(uint8_t dev_id,
1176 enum rte_event_dev_xstats_mode mode, int16_t queue_port_id,
1177 const uint32_t ids[], uint32_t nb_ids)
1179 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1180 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1182 if (dev->dev_ops->xstats_reset != NULL)
1183 return (*dev->dev_ops->xstats_reset)(dev, mode, queue_port_id,
1188 int rte_event_dev_selftest(uint8_t dev_id)
1190 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1191 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1193 if (dev->dev_ops->dev_selftest != NULL)
1194 return (*dev->dev_ops->dev_selftest)();
1199 rte_event_dev_start(uint8_t dev_id)
1201 struct rte_eventdev *dev;
1204 RTE_EDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
1206 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1207 dev = &rte_eventdevs[dev_id];
1208 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1210 if (dev->data->dev_started != 0) {
1211 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already started",
1216 diag = (*dev->dev_ops->dev_start)(dev);
1218 dev->data->dev_started = 1;
1226 rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
1227 eventdev_stop_flush_t callback, void *userdata)
1229 struct rte_eventdev *dev;
1231 RTE_EDEV_LOG_DEBUG("Stop flush register dev_id=%" PRIu8, dev_id);
1233 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1234 dev = &rte_eventdevs[dev_id];
1236 dev->dev_ops->dev_stop_flush = callback;
1237 dev->data->dev_stop_flush_arg = userdata;
1243 rte_event_dev_stop(uint8_t dev_id)
1245 struct rte_eventdev *dev;
1247 RTE_EDEV_LOG_DEBUG("Stop dev_id=%" PRIu8, dev_id);
1249 RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
1250 dev = &rte_eventdevs[dev_id];
1251 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1253 if (dev->data->dev_started == 0) {
1254 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already stopped",
1259 dev->data->dev_started = 0;
1260 (*dev->dev_ops->dev_stop)(dev);
1264 rte_event_dev_close(uint8_t dev_id)
1266 struct rte_eventdev *dev;
1268 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1269 dev = &rte_eventdevs[dev_id];
1270 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1272 /* Device must be stopped before it can be closed */
1273 if (dev->data->dev_started == 1) {
1274 RTE_EDEV_LOG_ERR("Device %u must be stopped before closing",
1279 return (*dev->dev_ops->dev_close)(dev);
1283 rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
1286 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1287 const struct rte_memzone *mz;
1290 /* Generate memzone name */
1291 n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
1292 if (n >= (int)sizeof(mz_name))
1295 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1296 mz = rte_memzone_reserve(mz_name,
1297 sizeof(struct rte_eventdev_data),
1300 mz = rte_memzone_lookup(mz_name);
1306 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1307 memset(*data, 0, sizeof(struct rte_eventdev_data));
1312 static inline uint8_t
1313 rte_eventdev_find_free_device_index(void)
1317 for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
1318 if (rte_eventdevs[dev_id].attached ==
1319 RTE_EVENTDEV_DETACHED)
1322 return RTE_EVENT_MAX_DEVS;
1326 rte_event_tx_adapter_enqueue(__rte_unused void *port,
1327 __rte_unused struct rte_event ev[],
1328 __rte_unused uint16_t nb_events)
1330 rte_errno = ENOTSUP;
1334 struct rte_eventdev *
1335 rte_event_pmd_allocate(const char *name, int socket_id)
1337 struct rte_eventdev *eventdev;
1340 if (rte_event_pmd_get_named_dev(name) != NULL) {
1341 RTE_EDEV_LOG_ERR("Event device with name %s already "
1342 "allocated!", name);
1346 dev_id = rte_eventdev_find_free_device_index();
1347 if (dev_id == RTE_EVENT_MAX_DEVS) {
1348 RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
1352 eventdev = &rte_eventdevs[dev_id];
1354 eventdev->txa_enqueue = rte_event_tx_adapter_enqueue;
1356 if (eventdev->data == NULL) {
1357 struct rte_eventdev_data *eventdev_data = NULL;
1359 int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data,
1362 if (retval < 0 || eventdev_data == NULL)
1365 eventdev->data = eventdev_data;
1367 snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN,
1370 eventdev->data->dev_id = dev_id;
1371 eventdev->data->socket_id = socket_id;
1372 eventdev->data->dev_started = 0;
1374 eventdev->attached = RTE_EVENTDEV_ATTACHED;
1376 eventdev_globals.nb_devs++;
1383 rte_event_pmd_release(struct rte_eventdev *eventdev)
1386 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1387 const struct rte_memzone *mz;
1389 if (eventdev == NULL)
1392 eventdev->attached = RTE_EVENTDEV_DETACHED;
1393 eventdev_globals.nb_devs--;
1395 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1396 rte_free(eventdev->data->dev_private);
1398 /* Generate memzone name */
1399 ret = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u",
1400 eventdev->data->dev_id);
1401 if (ret >= (int)sizeof(mz_name))
1404 mz = rte_memzone_lookup(mz_name);
1408 ret = rte_memzone_free(mz);
1413 eventdev->data = NULL;