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_string_fns.h>
17 #include <rte_byteorder.h>
19 #include <rte_debug.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_memzone.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_common.h>
30 #include <rte_malloc.h>
31 #include <rte_errno.h>
32 #include <rte_ethdev.h>
33 #include <rte_cryptodev.h>
34 #include <rte_cryptodev_pmd.h>
36 #include "rte_eventdev.h"
37 #include "rte_eventdev_pmd.h"
38 #include "rte_eventdev_trace.h"
40 static struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
42 struct rte_eventdev *rte_eventdevs = rte_event_devices;
44 static struct rte_eventdev_global eventdev_globals = {
48 /* Event dev north bound API implementation */
51 rte_event_dev_count(void)
53 return eventdev_globals.nb_devs;
57 rte_event_dev_get_dev_id(const char *name)
65 for (i = 0; i < 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],
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,
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;
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;
528 rte_eventdev_trace_configure(dev_id, dev_conf, diag);
533 is_valid_queue(struct rte_eventdev *dev, uint8_t queue_id)
535 if (queue_id < dev->data->nb_queues && queue_id <
536 RTE_EVENT_MAX_QUEUES_PER_DEV)
543 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
544 struct rte_event_queue_conf *queue_conf)
546 struct rte_eventdev *dev;
548 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
549 dev = &rte_eventdevs[dev_id];
551 if (queue_conf == NULL)
554 if (!is_valid_queue(dev, queue_id)) {
555 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
559 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP);
560 memset(queue_conf, 0, sizeof(struct rte_event_queue_conf));
561 (*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
566 is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
569 !(queue_conf->event_queue_cfg &
570 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
571 ((queue_conf->event_queue_cfg &
572 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
573 (queue_conf->schedule_type
574 == RTE_SCHED_TYPE_ATOMIC)
582 is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
585 !(queue_conf->event_queue_cfg &
586 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) &&
587 ((queue_conf->event_queue_cfg &
588 RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
589 (queue_conf->schedule_type
590 == RTE_SCHED_TYPE_ORDERED)
599 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
600 const struct rte_event_queue_conf *queue_conf)
602 struct rte_eventdev *dev;
603 struct rte_event_queue_conf def_conf;
605 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
606 dev = &rte_eventdevs[dev_id];
608 if (!is_valid_queue(dev, queue_id)) {
609 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
613 /* Check nb_atomic_flows limit */
614 if (is_valid_atomic_queue_conf(queue_conf)) {
615 if (queue_conf->nb_atomic_flows == 0 ||
616 queue_conf->nb_atomic_flows >
617 dev->data->dev_conf.nb_event_queue_flows) {
619 "dev%d queue%d Invalid nb_atomic_flows=%d max_flows=%d",
620 dev_id, queue_id, queue_conf->nb_atomic_flows,
621 dev->data->dev_conf.nb_event_queue_flows);
626 /* Check nb_atomic_order_sequences limit */
627 if (is_valid_ordered_queue_conf(queue_conf)) {
628 if (queue_conf->nb_atomic_order_sequences == 0 ||
629 queue_conf->nb_atomic_order_sequences >
630 dev->data->dev_conf.nb_event_queue_flows) {
632 "dev%d queue%d Invalid nb_atomic_order_seq=%d max_flows=%d",
633 dev_id, queue_id, queue_conf->nb_atomic_order_sequences,
634 dev->data->dev_conf.nb_event_queue_flows);
639 if (dev->data->dev_started) {
641 "device %d must be stopped to allow queue setup", dev_id);
645 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
647 if (queue_conf == NULL) {
648 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf,
650 (*dev->dev_ops->queue_def_conf)(dev, queue_id, &def_conf);
651 queue_conf = &def_conf;
654 dev->data->queues_cfg[queue_id] = *queue_conf;
655 rte_eventdev_trace_queue_setup(dev_id, queue_id, queue_conf);
656 return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
660 is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
662 if (port_id < dev->data->nb_ports)
669 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
670 struct rte_event_port_conf *port_conf)
672 struct rte_eventdev *dev;
674 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
675 dev = &rte_eventdevs[dev_id];
677 if (port_conf == NULL)
680 if (!is_valid_port(dev, port_id)) {
681 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
685 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf, -ENOTSUP);
686 memset(port_conf, 0, sizeof(struct rte_event_port_conf));
687 (*dev->dev_ops->port_def_conf)(dev, port_id, port_conf);
692 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
693 const struct rte_event_port_conf *port_conf)
695 struct rte_eventdev *dev;
696 struct rte_event_port_conf def_conf;
699 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
700 dev = &rte_eventdevs[dev_id];
702 if (!is_valid_port(dev, port_id)) {
703 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
707 /* Check new_event_threshold limit */
708 if ((port_conf && !port_conf->new_event_threshold) ||
709 (port_conf && port_conf->new_event_threshold >
710 dev->data->dev_conf.nb_events_limit)) {
712 "dev%d port%d Invalid event_threshold=%d nb_events_limit=%d",
713 dev_id, port_id, port_conf->new_event_threshold,
714 dev->data->dev_conf.nb_events_limit);
718 /* Check dequeue_depth limit */
719 if ((port_conf && !port_conf->dequeue_depth) ||
720 (port_conf && port_conf->dequeue_depth >
721 dev->data->dev_conf.nb_event_port_dequeue_depth)) {
723 "dev%d port%d Invalid dequeue depth=%d max_dequeue_depth=%d",
724 dev_id, port_id, port_conf->dequeue_depth,
725 dev->data->dev_conf.nb_event_port_dequeue_depth);
729 /* Check enqueue_depth limit */
730 if ((port_conf && !port_conf->enqueue_depth) ||
731 (port_conf && port_conf->enqueue_depth >
732 dev->data->dev_conf.nb_event_port_enqueue_depth)) {
734 "dev%d port%d Invalid enqueue depth=%d max_enqueue_depth=%d",
735 dev_id, port_id, port_conf->enqueue_depth,
736 dev->data->dev_conf.nb_event_port_enqueue_depth);
740 if (port_conf && port_conf->disable_implicit_release &&
741 !(dev->data->event_dev_cap &
742 RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)) {
744 "dev%d port%d Implicit release disable not supported",
749 if (dev->data->dev_started) {
751 "device %d must be stopped to allow port setup", dev_id);
755 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_setup, -ENOTSUP);
757 if (port_conf == NULL) {
758 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf,
760 (*dev->dev_ops->port_def_conf)(dev, port_id, &def_conf);
761 port_conf = &def_conf;
764 dev->data->ports_cfg[port_id] = *port_conf;
766 diag = (*dev->dev_ops->port_setup)(dev, port_id, port_conf);
768 /* Unlink all the queues from this port(default state after setup) */
770 diag = rte_event_port_unlink(dev_id, port_id, NULL, 0);
772 rte_eventdev_trace_port_setup(dev_id, port_id, port_conf, diag);
780 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
781 uint32_t *attr_value)
783 struct rte_eventdev *dev;
787 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
788 dev = &rte_eventdevs[dev_id];
791 case RTE_EVENT_DEV_ATTR_PORT_COUNT:
792 *attr_value = dev->data->nb_ports;
794 case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
795 *attr_value = dev->data->nb_queues;
797 case RTE_EVENT_DEV_ATTR_STARTED:
798 *attr_value = dev->data->dev_started;
808 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
809 uint32_t *attr_value)
811 struct rte_eventdev *dev;
816 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
817 dev = &rte_eventdevs[dev_id];
818 if (!is_valid_port(dev, port_id)) {
819 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
824 case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
825 *attr_value = dev->data->ports_cfg[port_id].enqueue_depth;
827 case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
828 *attr_value = dev->data->ports_cfg[port_id].dequeue_depth;
830 case RTE_EVENT_PORT_ATTR_NEW_EVENT_THRESHOLD:
831 *attr_value = dev->data->ports_cfg[port_id].new_event_threshold;
840 rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
841 uint32_t *attr_value)
843 struct rte_event_queue_conf *conf;
844 struct rte_eventdev *dev;
849 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
850 dev = &rte_eventdevs[dev_id];
851 if (!is_valid_queue(dev, queue_id)) {
852 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
856 conf = &dev->data->queues_cfg[queue_id];
859 case RTE_EVENT_QUEUE_ATTR_PRIORITY:
860 *attr_value = RTE_EVENT_DEV_PRIORITY_NORMAL;
861 if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
862 *attr_value = conf->priority;
864 case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_FLOWS:
865 *attr_value = conf->nb_atomic_flows;
867 case RTE_EVENT_QUEUE_ATTR_NB_ATOMIC_ORDER_SEQUENCES:
868 *attr_value = conf->nb_atomic_order_sequences;
870 case RTE_EVENT_QUEUE_ATTR_EVENT_QUEUE_CFG:
871 *attr_value = conf->event_queue_cfg;
873 case RTE_EVENT_QUEUE_ATTR_SCHEDULE_TYPE:
874 if (conf->event_queue_cfg & RTE_EVENT_QUEUE_CFG_ALL_TYPES)
877 *attr_value = conf->schedule_type;
886 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
887 const uint8_t queues[], const uint8_t priorities[],
890 struct rte_eventdev *dev;
891 uint8_t queues_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
892 uint8_t priorities_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
896 RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
897 dev = &rte_eventdevs[dev_id];
899 if (*dev->dev_ops->port_link == NULL) {
900 RTE_EDEV_LOG_ERR("Function not supported\n");
905 if (!is_valid_port(dev, port_id)) {
906 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
911 if (queues == NULL) {
912 for (i = 0; i < dev->data->nb_queues; i++)
915 queues = queues_list;
916 nb_links = dev->data->nb_queues;
919 if (priorities == NULL) {
920 for (i = 0; i < nb_links; i++)
921 priorities_list[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
923 priorities = priorities_list;
926 for (i = 0; i < nb_links; i++)
927 if (queues[i] >= dev->data->nb_queues) {
932 diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
933 queues, priorities, nb_links);
937 links_map = dev->data->links_map;
938 /* Point links_map to this port specific area */
939 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
940 for (i = 0; i < diag; i++)
941 links_map[queues[i]] = (uint8_t)priorities[i];
943 rte_eventdev_trace_port_link(dev_id, port_id, nb_links, diag);
948 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
949 uint8_t queues[], uint16_t nb_unlinks)
951 struct rte_eventdev *dev;
952 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
956 RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, EINVAL, 0);
957 dev = &rte_eventdevs[dev_id];
959 if (*dev->dev_ops->port_unlink == NULL) {
960 RTE_EDEV_LOG_ERR("Function not supported");
965 if (!is_valid_port(dev, port_id)) {
966 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
971 links_map = dev->data->links_map;
972 /* Point links_map to this port specific area */
973 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
975 if (queues == NULL) {
977 for (i = 0; i < dev->data->nb_queues; i++) {
979 EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
986 for (j = 0; j < nb_unlinks; j++) {
987 if (links_map[queues[j]] ==
988 EVENT_QUEUE_SERVICE_PRIORITY_INVALID)
994 for (i = 0; i < nb_unlinks; i++)
995 if (queues[i] >= dev->data->nb_queues) {
1000 diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
1001 queues, nb_unlinks);
1006 for (i = 0; i < diag; i++)
1007 links_map[queues[i]] = EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
1009 rte_eventdev_trace_port_unlink(dev_id, port_id, nb_unlinks, diag);
1014 rte_event_port_unlinks_in_progress(uint8_t dev_id, uint8_t port_id)
1016 struct rte_eventdev *dev;
1018 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1019 dev = &rte_eventdevs[dev_id];
1020 if (!is_valid_port(dev, port_id)) {
1021 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
1025 /* Return 0 if the PMD does not implement unlinks in progress.
1026 * This allows PMDs which handle unlink synchronously to not implement
1027 * this function at all.
1029 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlinks_in_progress, 0);
1031 return (*dev->dev_ops->port_unlinks_in_progress)(dev,
1032 dev->data->ports[port_id]);
1036 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
1037 uint8_t queues[], uint8_t priorities[])
1039 struct rte_eventdev *dev;
1040 uint16_t *links_map;
1043 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1044 dev = &rte_eventdevs[dev_id];
1045 if (!is_valid_port(dev, port_id)) {
1046 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
1050 links_map = dev->data->links_map;
1051 /* Point links_map to this port specific area */
1052 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
1053 for (i = 0; i < dev->data->nb_queues; i++) {
1054 if (links_map[i] != EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
1056 priorities[count] = (uint8_t)links_map[i];
1064 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
1065 uint64_t *timeout_ticks)
1067 struct rte_eventdev *dev;
1069 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1070 dev = &rte_eventdevs[dev_id];
1071 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timeout_ticks, -ENOTSUP);
1073 if (timeout_ticks == NULL)
1076 return (*dev->dev_ops->timeout_ticks)(dev, ns, timeout_ticks);
1080 rte_event_dev_service_id_get(uint8_t dev_id, uint32_t *service_id)
1082 struct rte_eventdev *dev;
1084 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1085 dev = &rte_eventdevs[dev_id];
1087 if (service_id == NULL)
1090 if (dev->data->service_inited)
1091 *service_id = dev->data->service_id;
1093 return dev->data->service_inited ? 0 : -ESRCH;
1097 rte_event_dev_dump(uint8_t dev_id, FILE *f)
1099 struct rte_eventdev *dev;
1101 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1102 dev = &rte_eventdevs[dev_id];
1103 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dump, -ENOTSUP);
1105 (*dev->dev_ops->dump)(dev, f);
1111 xstats_get_count(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
1112 uint8_t queue_port_id)
1114 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1115 if (dev->dev_ops->xstats_get_names != NULL)
1116 return (*dev->dev_ops->xstats_get_names)(dev, mode,
1123 rte_event_dev_xstats_names_get(uint8_t dev_id,
1124 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
1125 struct rte_event_dev_xstats_name *xstats_names,
1126 unsigned int *ids, unsigned int size)
1128 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
1129 const int cnt_expected_entries = xstats_get_count(dev_id, mode,
1131 if (xstats_names == NULL || cnt_expected_entries < 0 ||
1132 (int)size < cnt_expected_entries)
1133 return cnt_expected_entries;
1135 /* dev_id checked above */
1136 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1138 if (dev->dev_ops->xstats_get_names != NULL)
1139 return (*dev->dev_ops->xstats_get_names)(dev, mode,
1140 queue_port_id, xstats_names, ids, size);
1145 /* retrieve eventdev extended statistics */
1147 rte_event_dev_xstats_get(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
1148 uint8_t queue_port_id, const unsigned int ids[],
1149 uint64_t values[], unsigned int n)
1151 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
1152 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1154 /* implemented by the driver */
1155 if (dev->dev_ops->xstats_get != NULL)
1156 return (*dev->dev_ops->xstats_get)(dev, mode, queue_port_id,
1162 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1165 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, 0);
1166 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1167 unsigned int temp = -1;
1170 *id = (unsigned int)-1;
1172 id = &temp; /* ensure driver never gets a NULL value */
1174 /* implemented by driver */
1175 if (dev->dev_ops->xstats_get_by_name != NULL)
1176 return (*dev->dev_ops->xstats_get_by_name)(dev, name, id);
1180 int rte_event_dev_xstats_reset(uint8_t dev_id,
1181 enum rte_event_dev_xstats_mode mode, int16_t queue_port_id,
1182 const uint32_t ids[], uint32_t nb_ids)
1184 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1185 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1187 if (dev->dev_ops->xstats_reset != NULL)
1188 return (*dev->dev_ops->xstats_reset)(dev, mode, queue_port_id,
1193 int rte_event_dev_selftest(uint8_t dev_id)
1195 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1196 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1198 if (dev->dev_ops->dev_selftest != NULL)
1199 return (*dev->dev_ops->dev_selftest)();
1204 rte_event_dev_start(uint8_t dev_id)
1206 struct rte_eventdev *dev;
1209 RTE_EDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
1211 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1212 dev = &rte_eventdevs[dev_id];
1213 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1215 if (dev->data->dev_started != 0) {
1216 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already started",
1221 diag = (*dev->dev_ops->dev_start)(dev);
1222 rte_eventdev_trace_start(dev_id, diag);
1224 dev->data->dev_started = 1;
1232 rte_event_dev_stop_flush_callback_register(uint8_t dev_id,
1233 eventdev_stop_flush_t callback, void *userdata)
1235 struct rte_eventdev *dev;
1237 RTE_EDEV_LOG_DEBUG("Stop flush register dev_id=%" PRIu8, dev_id);
1239 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1240 dev = &rte_eventdevs[dev_id];
1242 dev->dev_ops->dev_stop_flush = callback;
1243 dev->data->dev_stop_flush_arg = userdata;
1249 rte_event_dev_stop(uint8_t dev_id)
1251 struct rte_eventdev *dev;
1253 RTE_EDEV_LOG_DEBUG("Stop dev_id=%" PRIu8, dev_id);
1255 RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
1256 dev = &rte_eventdevs[dev_id];
1257 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1259 if (dev->data->dev_started == 0) {
1260 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already stopped",
1265 dev->data->dev_started = 0;
1266 (*dev->dev_ops->dev_stop)(dev);
1267 rte_eventdev_trace_stop(dev_id);
1271 rte_event_dev_close(uint8_t dev_id)
1273 struct rte_eventdev *dev;
1275 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1276 dev = &rte_eventdevs[dev_id];
1277 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1279 /* Device must be stopped before it can be closed */
1280 if (dev->data->dev_started == 1) {
1281 RTE_EDEV_LOG_ERR("Device %u must be stopped before closing",
1286 rte_eventdev_trace_close(dev_id);
1287 return (*dev->dev_ops->dev_close)(dev);
1291 rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
1294 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1295 const struct rte_memzone *mz;
1298 /* Generate memzone name */
1299 n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
1300 if (n >= (int)sizeof(mz_name))
1303 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1304 mz = rte_memzone_reserve(mz_name,
1305 sizeof(struct rte_eventdev_data),
1308 mz = rte_memzone_lookup(mz_name);
1314 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1315 memset(*data, 0, sizeof(struct rte_eventdev_data));
1320 static inline uint8_t
1321 rte_eventdev_find_free_device_index(void)
1325 for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
1326 if (rte_eventdevs[dev_id].attached ==
1327 RTE_EVENTDEV_DETACHED)
1330 return RTE_EVENT_MAX_DEVS;
1334 rte_event_tx_adapter_enqueue(__rte_unused void *port,
1335 __rte_unused struct rte_event ev[],
1336 __rte_unused uint16_t nb_events)
1338 rte_errno = ENOTSUP;
1342 struct rte_eventdev *
1343 rte_event_pmd_allocate(const char *name, int socket_id)
1345 struct rte_eventdev *eventdev;
1348 if (rte_event_pmd_get_named_dev(name) != NULL) {
1349 RTE_EDEV_LOG_ERR("Event device with name %s already "
1350 "allocated!", name);
1354 dev_id = rte_eventdev_find_free_device_index();
1355 if (dev_id == RTE_EVENT_MAX_DEVS) {
1356 RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
1360 eventdev = &rte_eventdevs[dev_id];
1362 eventdev->txa_enqueue = rte_event_tx_adapter_enqueue;
1363 eventdev->txa_enqueue_same_dest = rte_event_tx_adapter_enqueue;
1365 if (eventdev->data == NULL) {
1366 struct rte_eventdev_data *eventdev_data = NULL;
1368 int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data,
1371 if (retval < 0 || eventdev_data == NULL)
1374 eventdev->data = eventdev_data;
1376 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1378 strlcpy(eventdev->data->name, name,
1379 RTE_EVENTDEV_NAME_MAX_LEN);
1381 eventdev->data->dev_id = dev_id;
1382 eventdev->data->socket_id = socket_id;
1383 eventdev->data->dev_started = 0;
1386 eventdev->attached = RTE_EVENTDEV_ATTACHED;
1387 eventdev_globals.nb_devs++;
1394 rte_event_pmd_release(struct rte_eventdev *eventdev)
1397 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1398 const struct rte_memzone *mz;
1400 if (eventdev == NULL)
1403 eventdev->attached = RTE_EVENTDEV_DETACHED;
1404 eventdev_globals.nb_devs--;
1406 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1407 rte_free(eventdev->data->dev_private);
1409 /* Generate memzone name */
1410 ret = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u",
1411 eventdev->data->dev_id);
1412 if (ret >= (int)sizeof(mz_name))
1415 mz = rte_memzone_lookup(mz_name);
1419 ret = rte_memzone_free(mz);
1424 eventdev->data = NULL;