4 * Copyright(c) 2016 Cavium, Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
42 #include <sys/queue.h>
44 #include <rte_byteorder.h>
46 #include <rte_debug.h>
48 #include <rte_memory.h>
49 #include <rte_memcpy.h>
50 #include <rte_memzone.h>
52 #include <rte_per_lcore.h>
53 #include <rte_lcore.h>
54 #include <rte_atomic.h>
55 #include <rte_branch_prediction.h>
56 #include <rte_common.h>
57 #include <rte_malloc.h>
58 #include <rte_errno.h>
60 #include "rte_eventdev.h"
61 #include "rte_eventdev_pmd.h"
63 struct rte_eventdev rte_event_devices[RTE_EVENT_MAX_DEVS];
65 struct rte_eventdev *rte_eventdevs = &rte_event_devices[0];
67 static struct rte_eventdev_global eventdev_globals = {
71 struct rte_eventdev_global *rte_eventdev_globals = &eventdev_globals;
73 /* Event dev north bound API implementation */
76 rte_event_dev_count(void)
78 return rte_eventdev_globals->nb_devs;
82 rte_event_dev_get_dev_id(const char *name)
89 for (i = 0; i < rte_eventdev_globals->nb_devs; i++)
90 if ((strcmp(rte_event_devices[i].data->name, name)
92 (rte_event_devices[i].attached ==
93 RTE_EVENTDEV_ATTACHED))
99 rte_event_dev_socket_id(uint8_t dev_id)
101 struct rte_eventdev *dev;
103 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
104 dev = &rte_eventdevs[dev_id];
106 return dev->data->socket_id;
110 rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
112 struct rte_eventdev *dev;
114 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
115 dev = &rte_eventdevs[dev_id];
117 if (dev_info == NULL)
120 memset(dev_info, 0, sizeof(struct rte_event_dev_info));
122 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
123 (*dev->dev_ops->dev_infos_get)(dev, dev_info);
125 dev_info->dequeue_timeout_ns = dev->data->dev_conf.dequeue_timeout_ns;
127 dev_info->dev = dev->dev;
132 rte_event_dev_queue_config(struct rte_eventdev *dev, uint8_t nb_queues)
134 uint8_t old_nb_queues = dev->data->nb_queues;
135 uint8_t *queues_prio;
138 RTE_EDEV_LOG_DEBUG("Setup %d queues on device %u", nb_queues,
141 /* First time configuration */
142 if (dev->data->queues_prio == NULL && nb_queues != 0) {
143 /* Allocate memory to store queue priority */
144 dev->data->queues_prio = rte_zmalloc_socket(
145 "eventdev->data->queues_prio",
146 sizeof(dev->data->queues_prio[0]) * nb_queues,
147 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
148 if (dev->data->queues_prio == NULL) {
149 dev->data->nb_queues = 0;
150 RTE_EDEV_LOG_ERR("failed to get mem for queue priority,"
151 "nb_queues %u", nb_queues);
155 } else if (dev->data->queues_prio != NULL && nb_queues != 0) {
156 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
158 for (i = nb_queues; i < old_nb_queues; i++)
159 (*dev->dev_ops->queue_release)(dev, i);
161 /* Re allocate memory to store queue priority */
162 queues_prio = dev->data->queues_prio;
163 queues_prio = rte_realloc(queues_prio,
164 sizeof(queues_prio[0]) * nb_queues,
165 RTE_CACHE_LINE_SIZE);
166 if (queues_prio == NULL) {
167 RTE_EDEV_LOG_ERR("failed to realloc queue priority,"
168 " nb_queues %u", nb_queues);
171 dev->data->queues_prio = queues_prio;
173 if (nb_queues > old_nb_queues) {
174 uint8_t new_qs = nb_queues - old_nb_queues;
176 memset(queues_prio + old_nb_queues, 0,
177 sizeof(queues_prio[0]) * new_qs);
179 } else if (dev->data->queues_prio != NULL && nb_queues == 0) {
180 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_release, -ENOTSUP);
182 for (i = nb_queues; i < old_nb_queues; i++)
183 (*dev->dev_ops->queue_release)(dev, i);
186 dev->data->nb_queues = nb_queues;
190 #define EVENT_QUEUE_SERVICE_PRIORITY_INVALID (0xdead)
193 rte_event_dev_port_config(struct rte_eventdev *dev, uint8_t nb_ports)
195 uint8_t old_nb_ports = dev->data->nb_ports;
198 uint8_t *ports_dequeue_depth;
199 uint8_t *ports_enqueue_depth;
202 RTE_EDEV_LOG_DEBUG("Setup %d ports on device %u", nb_ports,
205 /* First time configuration */
206 if (dev->data->ports == NULL && nb_ports != 0) {
207 dev->data->ports = rte_zmalloc_socket("eventdev->data->ports",
208 sizeof(dev->data->ports[0]) * nb_ports,
209 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
210 if (dev->data->ports == NULL) {
211 dev->data->nb_ports = 0;
212 RTE_EDEV_LOG_ERR("failed to get mem for port meta data,"
213 "nb_ports %u", nb_ports);
217 /* Allocate memory to store ports dequeue depth */
218 dev->data->ports_dequeue_depth =
219 rte_zmalloc_socket("eventdev->ports_dequeue_depth",
220 sizeof(dev->data->ports_dequeue_depth[0]) * nb_ports,
221 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
222 if (dev->data->ports_dequeue_depth == NULL) {
223 dev->data->nb_ports = 0;
224 RTE_EDEV_LOG_ERR("failed to get mem for port deq meta,"
225 "nb_ports %u", nb_ports);
229 /* Allocate memory to store ports enqueue depth */
230 dev->data->ports_enqueue_depth =
231 rte_zmalloc_socket("eventdev->ports_enqueue_depth",
232 sizeof(dev->data->ports_enqueue_depth[0]) * nb_ports,
233 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
234 if (dev->data->ports_enqueue_depth == NULL) {
235 dev->data->nb_ports = 0;
236 RTE_EDEV_LOG_ERR("failed to get mem for port enq meta,"
237 "nb_ports %u", nb_ports);
241 /* Allocate memory to store queue to port link connection */
242 dev->data->links_map =
243 rte_zmalloc_socket("eventdev->links_map",
244 sizeof(dev->data->links_map[0]) * nb_ports *
245 RTE_EVENT_MAX_QUEUES_PER_DEV,
246 RTE_CACHE_LINE_SIZE, dev->data->socket_id);
247 if (dev->data->links_map == NULL) {
248 dev->data->nb_ports = 0;
249 RTE_EDEV_LOG_ERR("failed to get mem for port_map area,"
250 "nb_ports %u", nb_ports);
253 for (i = 0; i < nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV; i++)
254 dev->data->links_map[i] =
255 EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
256 } else if (dev->data->ports != NULL && nb_ports != 0) {/* re-config */
257 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
259 ports = dev->data->ports;
260 ports_dequeue_depth = dev->data->ports_dequeue_depth;
261 ports_enqueue_depth = dev->data->ports_enqueue_depth;
262 links_map = dev->data->links_map;
264 for (i = nb_ports; i < old_nb_ports; i++)
265 (*dev->dev_ops->port_release)(ports[i]);
267 /* Realloc memory for ports */
268 ports = rte_realloc(ports, sizeof(ports[0]) * nb_ports,
269 RTE_CACHE_LINE_SIZE);
271 RTE_EDEV_LOG_ERR("failed to realloc port meta data,"
272 " nb_ports %u", nb_ports);
276 /* Realloc memory for ports_dequeue_depth */
277 ports_dequeue_depth = rte_realloc(ports_dequeue_depth,
278 sizeof(ports_dequeue_depth[0]) * nb_ports,
279 RTE_CACHE_LINE_SIZE);
280 if (ports_dequeue_depth == NULL) {
281 RTE_EDEV_LOG_ERR("failed to realloc port dequeue meta,"
282 " nb_ports %u", nb_ports);
286 /* Realloc memory for ports_enqueue_depth */
287 ports_enqueue_depth = rte_realloc(ports_enqueue_depth,
288 sizeof(ports_enqueue_depth[0]) * nb_ports,
289 RTE_CACHE_LINE_SIZE);
290 if (ports_enqueue_depth == NULL) {
291 RTE_EDEV_LOG_ERR("failed to realloc port enqueue meta,"
292 " nb_ports %u", nb_ports);
296 /* Realloc memory to store queue to port link connection */
297 links_map = rte_realloc(links_map,
298 sizeof(dev->data->links_map[0]) * nb_ports *
299 RTE_EVENT_MAX_QUEUES_PER_DEV,
300 RTE_CACHE_LINE_SIZE);
301 if (links_map == NULL) {
302 dev->data->nb_ports = 0;
303 RTE_EDEV_LOG_ERR("failed to realloc mem for port_map,"
304 "nb_ports %u", nb_ports);
308 if (nb_ports > old_nb_ports) {
309 uint8_t new_ps = nb_ports - old_nb_ports;
310 unsigned int old_links_map_end =
311 old_nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
312 unsigned int links_map_end =
313 nb_ports * RTE_EVENT_MAX_QUEUES_PER_DEV;
315 memset(ports + old_nb_ports, 0,
316 sizeof(ports[0]) * new_ps);
317 memset(ports_dequeue_depth + old_nb_ports, 0,
318 sizeof(ports_dequeue_depth[0]) * new_ps);
319 memset(ports_enqueue_depth + old_nb_ports, 0,
320 sizeof(ports_enqueue_depth[0]) * new_ps);
321 for (i = old_links_map_end; i < links_map_end; i++)
323 EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
326 dev->data->ports = ports;
327 dev->data->ports_dequeue_depth = ports_dequeue_depth;
328 dev->data->ports_enqueue_depth = ports_enqueue_depth;
329 dev->data->links_map = links_map;
330 } else if (dev->data->ports != NULL && nb_ports == 0) {
331 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_release, -ENOTSUP);
333 ports = dev->data->ports;
334 for (i = nb_ports; i < old_nb_ports; i++)
335 (*dev->dev_ops->port_release)(ports[i]);
338 dev->data->nb_ports = nb_ports;
343 rte_event_dev_configure(uint8_t dev_id,
344 const struct rte_event_dev_config *dev_conf)
346 struct rte_eventdev *dev;
347 struct rte_event_dev_info info;
350 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
351 dev = &rte_eventdevs[dev_id];
353 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
354 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
356 if (dev->data->dev_started) {
358 "device %d must be stopped to allow configuration", dev_id);
362 if (dev_conf == NULL)
365 (*dev->dev_ops->dev_infos_get)(dev, &info);
367 /* Check dequeue_timeout_ns value is in limit */
368 if (!(dev_conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)) {
369 if (dev_conf->dequeue_timeout_ns &&
370 (dev_conf->dequeue_timeout_ns < info.min_dequeue_timeout_ns
371 || dev_conf->dequeue_timeout_ns >
372 info.max_dequeue_timeout_ns)) {
373 RTE_EDEV_LOG_ERR("dev%d invalid dequeue_timeout_ns=%d"
374 " min_dequeue_timeout_ns=%d max_dequeue_timeout_ns=%d",
375 dev_id, dev_conf->dequeue_timeout_ns,
376 info.min_dequeue_timeout_ns,
377 info.max_dequeue_timeout_ns);
382 /* Check nb_events_limit is in limit */
383 if (dev_conf->nb_events_limit > info.max_num_events) {
384 RTE_EDEV_LOG_ERR("dev%d nb_events_limit=%d > max_num_events=%d",
385 dev_id, dev_conf->nb_events_limit, info.max_num_events);
389 /* Check nb_event_queues is in limit */
390 if (!dev_conf->nb_event_queues) {
391 RTE_EDEV_LOG_ERR("dev%d nb_event_queues cannot be zero",
395 if (dev_conf->nb_event_queues > info.max_event_queues) {
396 RTE_EDEV_LOG_ERR("%d nb_event_queues=%d > max_event_queues=%d",
397 dev_id, dev_conf->nb_event_queues, info.max_event_queues);
401 /* Check nb_event_ports is in limit */
402 if (!dev_conf->nb_event_ports) {
403 RTE_EDEV_LOG_ERR("dev%d nb_event_ports cannot be zero", dev_id);
406 if (dev_conf->nb_event_ports > info.max_event_ports) {
407 RTE_EDEV_LOG_ERR("id%d nb_event_ports=%d > max_event_ports= %d",
408 dev_id, dev_conf->nb_event_ports, info.max_event_ports);
412 /* Check nb_event_queue_flows is in limit */
413 if (!dev_conf->nb_event_queue_flows) {
414 RTE_EDEV_LOG_ERR("dev%d nb_flows cannot be zero", dev_id);
417 if (dev_conf->nb_event_queue_flows > info.max_event_queue_flows) {
418 RTE_EDEV_LOG_ERR("dev%d nb_flows=%x > max_flows=%x",
419 dev_id, dev_conf->nb_event_queue_flows,
420 info.max_event_queue_flows);
424 /* Check nb_event_port_dequeue_depth is in limit */
425 if (!dev_conf->nb_event_port_dequeue_depth) {
426 RTE_EDEV_LOG_ERR("dev%d nb_dequeue_depth cannot be zero",
430 if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
431 (dev_conf->nb_event_port_dequeue_depth >
432 info.max_event_port_dequeue_depth)) {
433 RTE_EDEV_LOG_ERR("dev%d nb_dq_depth=%d > max_dq_depth=%d",
434 dev_id, dev_conf->nb_event_port_dequeue_depth,
435 info.max_event_port_dequeue_depth);
439 /* Check nb_event_port_enqueue_depth is in limit */
440 if (!dev_conf->nb_event_port_enqueue_depth) {
441 RTE_EDEV_LOG_ERR("dev%d nb_enqueue_depth cannot be zero",
445 if ((info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) &&
446 (dev_conf->nb_event_port_enqueue_depth >
447 info.max_event_port_enqueue_depth)) {
448 RTE_EDEV_LOG_ERR("dev%d nb_enq_depth=%d > max_enq_depth=%d",
449 dev_id, dev_conf->nb_event_port_enqueue_depth,
450 info.max_event_port_enqueue_depth);
454 /* Copy the dev_conf parameter into the dev structure */
455 memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
457 /* Setup new number of queues and reconfigure device. */
458 diag = rte_event_dev_queue_config(dev, dev_conf->nb_event_queues);
460 RTE_EDEV_LOG_ERR("dev%d rte_event_dev_queue_config = %d",
465 /* Setup new number of ports and reconfigure device. */
466 diag = rte_event_dev_port_config(dev, dev_conf->nb_event_ports);
468 rte_event_dev_queue_config(dev, 0);
469 RTE_EDEV_LOG_ERR("dev%d rte_event_dev_port_config = %d",
474 /* Configure the device */
475 diag = (*dev->dev_ops->dev_configure)(dev);
477 RTE_EDEV_LOG_ERR("dev%d dev_configure = %d", dev_id, diag);
478 rte_event_dev_queue_config(dev, 0);
479 rte_event_dev_port_config(dev, 0);
482 dev->data->event_dev_cap = info.event_dev_cap;
487 is_valid_queue(struct rte_eventdev *dev, uint8_t queue_id)
489 if (queue_id < dev->data->nb_queues && queue_id <
490 RTE_EVENT_MAX_QUEUES_PER_DEV)
497 rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
498 struct rte_event_queue_conf *queue_conf)
500 struct rte_eventdev *dev;
502 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
503 dev = &rte_eventdevs[dev_id];
505 if (queue_conf == NULL)
508 if (!is_valid_queue(dev, queue_id)) {
509 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
513 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP);
514 memset(queue_conf, 0, sizeof(struct rte_event_queue_conf));
515 (*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
520 is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
523 !(queue_conf->event_queue_cfg &
524 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) && (
525 ((queue_conf->event_queue_cfg &
526 RTE_EVENT_QUEUE_CFG_TYPE_MASK)
527 == RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
528 ((queue_conf->event_queue_cfg &
529 RTE_EVENT_QUEUE_CFG_TYPE_MASK)
530 == RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY)
538 is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
541 !(queue_conf->event_queue_cfg &
542 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) && (
543 ((queue_conf->event_queue_cfg &
544 RTE_EVENT_QUEUE_CFG_TYPE_MASK)
545 == RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
546 ((queue_conf->event_queue_cfg &
547 RTE_EVENT_QUEUE_CFG_TYPE_MASK)
548 == RTE_EVENT_QUEUE_CFG_ORDERED_ONLY)
557 rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
558 const struct rte_event_queue_conf *queue_conf)
560 struct rte_eventdev *dev;
561 struct rte_event_queue_conf def_conf;
563 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
564 dev = &rte_eventdevs[dev_id];
566 if (!is_valid_queue(dev, queue_id)) {
567 RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
571 /* Check nb_atomic_flows limit */
572 if (is_valid_atomic_queue_conf(queue_conf)) {
573 if (queue_conf->nb_atomic_flows == 0 ||
574 queue_conf->nb_atomic_flows >
575 dev->data->dev_conf.nb_event_queue_flows) {
577 "dev%d queue%d Invalid nb_atomic_flows=%d max_flows=%d",
578 dev_id, queue_id, queue_conf->nb_atomic_flows,
579 dev->data->dev_conf.nb_event_queue_flows);
584 /* Check nb_atomic_order_sequences limit */
585 if (is_valid_ordered_queue_conf(queue_conf)) {
586 if (queue_conf->nb_atomic_order_sequences == 0 ||
587 queue_conf->nb_atomic_order_sequences >
588 dev->data->dev_conf.nb_event_queue_flows) {
590 "dev%d queue%d Invalid nb_atomic_order_seq=%d max_flows=%d",
591 dev_id, queue_id, queue_conf->nb_atomic_order_sequences,
592 dev->data->dev_conf.nb_event_queue_flows);
597 if (dev->data->dev_started) {
599 "device %d must be stopped to allow queue setup", dev_id);
603 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
605 if (queue_conf == NULL) {
606 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf,
608 (*dev->dev_ops->queue_def_conf)(dev, queue_id, &def_conf);
609 queue_conf = &def_conf;
612 dev->data->queues_prio[queue_id] = queue_conf->priority;
613 return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
617 rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id)
619 struct rte_eventdev *dev;
621 dev = &rte_eventdevs[dev_id];
622 if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
623 return dev->data->queues_prio[queue_id];
625 return RTE_EVENT_DEV_PRIORITY_NORMAL;
629 is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
631 if (port_id < dev->data->nb_ports)
638 rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
639 struct rte_event_port_conf *port_conf)
641 struct rte_eventdev *dev;
643 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
644 dev = &rte_eventdevs[dev_id];
646 if (port_conf == NULL)
649 if (!is_valid_port(dev, port_id)) {
650 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
654 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf, -ENOTSUP);
655 memset(port_conf, 0, sizeof(struct rte_event_port_conf));
656 (*dev->dev_ops->port_def_conf)(dev, port_id, port_conf);
661 rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
662 const struct rte_event_port_conf *port_conf)
664 struct rte_eventdev *dev;
665 struct rte_event_port_conf def_conf;
668 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
669 dev = &rte_eventdevs[dev_id];
671 if (!is_valid_port(dev, port_id)) {
672 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
676 /* Check new_event_threshold limit */
677 if ((port_conf && !port_conf->new_event_threshold) ||
678 (port_conf && port_conf->new_event_threshold >
679 dev->data->dev_conf.nb_events_limit)) {
681 "dev%d port%d Invalid event_threshold=%d nb_events_limit=%d",
682 dev_id, port_id, port_conf->new_event_threshold,
683 dev->data->dev_conf.nb_events_limit);
687 /* Check dequeue_depth limit */
688 if ((port_conf && !port_conf->dequeue_depth) ||
689 (port_conf && port_conf->dequeue_depth >
690 dev->data->dev_conf.nb_event_port_dequeue_depth)) {
692 "dev%d port%d Invalid dequeue depth=%d max_dequeue_depth=%d",
693 dev_id, port_id, port_conf->dequeue_depth,
694 dev->data->dev_conf.nb_event_port_dequeue_depth);
698 /* Check enqueue_depth limit */
699 if ((port_conf && !port_conf->enqueue_depth) ||
700 (port_conf && port_conf->enqueue_depth >
701 dev->data->dev_conf.nb_event_port_enqueue_depth)) {
703 "dev%d port%d Invalid enqueue depth=%d max_enqueue_depth=%d",
704 dev_id, port_id, port_conf->enqueue_depth,
705 dev->data->dev_conf.nb_event_port_enqueue_depth);
709 if (dev->data->dev_started) {
711 "device %d must be stopped to allow port setup", dev_id);
715 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_setup, -ENOTSUP);
717 if (port_conf == NULL) {
718 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_def_conf,
720 (*dev->dev_ops->port_def_conf)(dev, port_id, &def_conf);
721 port_conf = &def_conf;
724 dev->data->ports_dequeue_depth[port_id] =
725 port_conf->dequeue_depth;
726 dev->data->ports_enqueue_depth[port_id] =
727 port_conf->enqueue_depth;
729 diag = (*dev->dev_ops->port_setup)(dev, port_id, port_conf);
731 /* Unlink all the queues from this port(default state after setup) */
733 diag = rte_event_port_unlink(dev_id, port_id, NULL, 0);
742 rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
743 uint32_t *attr_value)
745 struct rte_eventdev *dev;
749 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
750 dev = &rte_eventdevs[dev_id];
753 case RTE_EVENT_DEV_ATTR_PORT_COUNT:
754 *attr_value = dev->data->nb_ports;
756 case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
757 *attr_value = dev->data->nb_queues;
767 rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
768 uint32_t *attr_value)
770 struct rte_eventdev *dev;
775 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
776 dev = &rte_eventdevs[dev_id];
777 if (!is_valid_port(dev, port_id)) {
778 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
783 case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
784 *attr_value = dev->data->ports_enqueue_depth[port_id];
786 case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
787 *attr_value = dev->data->ports_dequeue_depth[port_id];
796 rte_event_port_link(uint8_t dev_id, uint8_t port_id,
797 const uint8_t queues[], const uint8_t priorities[],
800 struct rte_eventdev *dev;
801 uint8_t queues_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
802 uint8_t priorities_list[RTE_EVENT_MAX_QUEUES_PER_DEV];
806 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
807 dev = &rte_eventdevs[dev_id];
808 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_link, -ENOTSUP);
810 if (!is_valid_port(dev, port_id)) {
811 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
815 if (queues == NULL) {
816 for (i = 0; i < dev->data->nb_queues; i++)
819 queues = queues_list;
820 nb_links = dev->data->nb_queues;
823 if (priorities == NULL) {
824 for (i = 0; i < nb_links; i++)
825 priorities_list[i] = RTE_EVENT_DEV_PRIORITY_NORMAL;
827 priorities = priorities_list;
830 for (i = 0; i < nb_links; i++)
831 if (queues[i] >= dev->data->nb_queues)
834 diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
835 queues, priorities, nb_links);
839 links_map = dev->data->links_map;
840 /* Point links_map to this port specific area */
841 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
842 for (i = 0; i < diag; i++)
843 links_map[queues[i]] = (uint8_t)priorities[i];
849 rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
850 uint8_t queues[], uint16_t nb_unlinks)
852 struct rte_eventdev *dev;
853 uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
857 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
858 dev = &rte_eventdevs[dev_id];
859 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlink, -ENOTSUP);
861 if (!is_valid_port(dev, port_id)) {
862 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
866 if (queues == NULL) {
867 for (i = 0; i < dev->data->nb_queues; i++)
870 nb_unlinks = dev->data->nb_queues;
873 for (i = 0; i < nb_unlinks; i++)
874 if (queues[i] >= dev->data->nb_queues)
877 diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
883 links_map = dev->data->links_map;
884 /* Point links_map to this port specific area */
885 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
886 for (i = 0; i < diag; i++)
887 links_map[queues[i]] = EVENT_QUEUE_SERVICE_PRIORITY_INVALID;
893 rte_event_port_links_get(uint8_t dev_id, uint8_t port_id,
894 uint8_t queues[], uint8_t priorities[])
896 struct rte_eventdev *dev;
900 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
901 dev = &rte_eventdevs[dev_id];
902 if (!is_valid_port(dev, port_id)) {
903 RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
907 links_map = dev->data->links_map;
908 /* Point links_map to this port specific area */
909 links_map += (port_id * RTE_EVENT_MAX_QUEUES_PER_DEV);
910 for (i = 0; i < dev->data->nb_queues; i++) {
911 if (links_map[i] != EVENT_QUEUE_SERVICE_PRIORITY_INVALID) {
913 priorities[count] = (uint8_t)links_map[i];
921 rte_event_dequeue_timeout_ticks(uint8_t dev_id, uint64_t ns,
922 uint64_t *timeout_ticks)
924 struct rte_eventdev *dev;
926 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
927 dev = &rte_eventdevs[dev_id];
928 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timeout_ticks, -ENOTSUP);
930 if (timeout_ticks == NULL)
933 return (*dev->dev_ops->timeout_ticks)(dev, ns, timeout_ticks);
937 rte_event_dev_dump(uint8_t dev_id, FILE *f)
939 struct rte_eventdev *dev;
941 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
942 dev = &rte_eventdevs[dev_id];
943 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dump, -ENOTSUP);
945 (*dev->dev_ops->dump)(dev, f);
951 xstats_get_count(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
952 uint8_t queue_port_id)
954 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
955 if (dev->dev_ops->xstats_get_names != NULL)
956 return (*dev->dev_ops->xstats_get_names)(dev, mode,
963 rte_event_dev_xstats_names_get(uint8_t dev_id,
964 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
965 struct rte_event_dev_xstats_name *xstats_names,
966 unsigned int *ids, unsigned int size)
968 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
969 const int cnt_expected_entries = xstats_get_count(dev_id, mode,
971 if (xstats_names == NULL || cnt_expected_entries < 0 ||
972 (int)size < cnt_expected_entries)
973 return cnt_expected_entries;
975 /* dev_id checked above */
976 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
978 if (dev->dev_ops->xstats_get_names != NULL)
979 return (*dev->dev_ops->xstats_get_names)(dev, mode,
980 queue_port_id, xstats_names, ids, size);
985 /* retrieve eventdev extended statistics */
987 rte_event_dev_xstats_get(uint8_t dev_id, enum rte_event_dev_xstats_mode mode,
988 uint8_t queue_port_id, const unsigned int ids[],
989 uint64_t values[], unsigned int n)
991 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -ENODEV);
992 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
994 /* implemented by the driver */
995 if (dev->dev_ops->xstats_get != NULL)
996 return (*dev->dev_ops->xstats_get)(dev, mode, queue_port_id,
1002 rte_event_dev_xstats_by_name_get(uint8_t dev_id, const char *name,
1005 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, 0);
1006 const struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1007 unsigned int temp = -1;
1010 *id = (unsigned int)-1;
1012 id = &temp; /* ensure driver never gets a NULL value */
1014 /* implemented by driver */
1015 if (dev->dev_ops->xstats_get_by_name != NULL)
1016 return (*dev->dev_ops->xstats_get_by_name)(dev, name, id);
1020 int rte_event_dev_xstats_reset(uint8_t dev_id,
1021 enum rte_event_dev_xstats_mode mode, int16_t queue_port_id,
1022 const uint32_t ids[], uint32_t nb_ids)
1024 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1025 struct rte_eventdev *dev = &rte_eventdevs[dev_id];
1027 if (dev->dev_ops->xstats_reset != NULL)
1028 return (*dev->dev_ops->xstats_reset)(dev, mode, queue_port_id,
1034 rte_event_dev_start(uint8_t dev_id)
1036 struct rte_eventdev *dev;
1039 RTE_EDEV_LOG_DEBUG("Start dev_id=%" PRIu8, dev_id);
1041 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1042 dev = &rte_eventdevs[dev_id];
1043 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
1045 if (dev->data->dev_started != 0) {
1046 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already started",
1051 diag = (*dev->dev_ops->dev_start)(dev);
1053 dev->data->dev_started = 1;
1061 rte_event_dev_stop(uint8_t dev_id)
1063 struct rte_eventdev *dev;
1065 RTE_EDEV_LOG_DEBUG("Stop dev_id=%" PRIu8, dev_id);
1067 RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id);
1068 dev = &rte_eventdevs[dev_id];
1069 RTE_FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
1071 if (dev->data->dev_started == 0) {
1072 RTE_EDEV_LOG_ERR("Device with dev_id=%" PRIu8 "already stopped",
1077 dev->data->dev_started = 0;
1078 (*dev->dev_ops->dev_stop)(dev);
1082 rte_event_dev_close(uint8_t dev_id)
1084 struct rte_eventdev *dev;
1086 RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
1087 dev = &rte_eventdevs[dev_id];
1088 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP);
1090 /* Device must be stopped before it can be closed */
1091 if (dev->data->dev_started == 1) {
1092 RTE_EDEV_LOG_ERR("Device %u must be stopped before closing",
1097 return (*dev->dev_ops->dev_close)(dev);
1101 rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
1104 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1105 const struct rte_memzone *mz;
1108 /* Generate memzone name */
1109 n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
1110 if (n >= (int)sizeof(mz_name))
1113 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1114 mz = rte_memzone_reserve(mz_name,
1115 sizeof(struct rte_eventdev_data),
1118 mz = rte_memzone_lookup(mz_name);
1124 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1125 memset(*data, 0, sizeof(struct rte_eventdev_data));
1130 static inline uint8_t
1131 rte_eventdev_find_free_device_index(void)
1135 for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
1136 if (rte_eventdevs[dev_id].attached ==
1137 RTE_EVENTDEV_DETACHED)
1140 return RTE_EVENT_MAX_DEVS;
1143 struct rte_eventdev *
1144 rte_event_pmd_allocate(const char *name, int socket_id)
1146 struct rte_eventdev *eventdev;
1149 if (rte_event_pmd_get_named_dev(name) != NULL) {
1150 RTE_EDEV_LOG_ERR("Event device with name %s already "
1151 "allocated!", name);
1155 dev_id = rte_eventdev_find_free_device_index();
1156 if (dev_id == RTE_EVENT_MAX_DEVS) {
1157 RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
1161 eventdev = &rte_eventdevs[dev_id];
1163 if (eventdev->data == NULL) {
1164 struct rte_eventdev_data *eventdev_data = NULL;
1166 int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data,
1169 if (retval < 0 || eventdev_data == NULL)
1172 eventdev->data = eventdev_data;
1174 snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN,
1177 eventdev->data->dev_id = dev_id;
1178 eventdev->data->socket_id = socket_id;
1179 eventdev->data->dev_started = 0;
1181 eventdev->attached = RTE_EVENTDEV_ATTACHED;
1183 eventdev_globals.nb_devs++;
1190 rte_event_pmd_release(struct rte_eventdev *eventdev)
1193 char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
1194 const struct rte_memzone *mz;
1196 if (eventdev == NULL)
1199 eventdev->attached = RTE_EVENTDEV_DETACHED;
1200 eventdev_globals.nb_devs--;
1202 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1203 rte_free(eventdev->data->dev_private);
1205 /* Generate memzone name */
1206 ret = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u",
1207 eventdev->data->dev_id);
1208 if (ret >= (int)sizeof(mz_name))
1211 mz = rte_memzone_lookup(mz_name);
1215 ret = rte_memzone_free(mz);
1220 eventdev->data = NULL;