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 NXP 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.
39 #include <sys/epoll.h>
41 #include <rte_atomic.h>
42 #include <rte_byteorder.h>
43 #include <rte_common.h>
44 #include <rte_debug.h>
47 #include <rte_fslmc.h>
48 #include <rte_lcore.h>
50 #include <rte_malloc.h>
51 #include <rte_memcpy.h>
52 #include <rte_memory.h>
53 #include <rte_memzone.h>
57 #include <fslmc_vfio.h>
58 #include <dpaa2_hw_pvt.h>
59 #include <dpaa2_hw_mempool.h>
60 #include <dpaa2_hw_dpio.h>
61 #include "dpaa2_eventdev.h"
62 #include <portal/dpaa2_hw_pvt.h>
63 #include <mc/fsl_dpci.h>
66 * Evendev = SoC Instance
67 * Eventport = DPIO Instance
68 * Eventqueue = DPCON Instance
69 * 1 Eventdev can have N Eventqueue
70 * Soft Event Flow is DPCI Instance
74 dpaa2_eventdev_enqueue_burst(void *port, const struct rte_event ev[],
77 struct rte_eventdev *ev_dev =
78 ((struct dpaa2_io_portal_t *)port)->eventdev;
79 struct dpaa2_eventdev *priv = ev_dev->data->dev_private;
80 uint32_t queue_id = ev[0].queue_id;
81 struct evq_info_t *evq_info = &priv->evq_info[queue_id];
83 struct qbman_swp *swp;
84 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
85 uint32_t loop, frames_to_send;
86 struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
92 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
93 ret = dpaa2_affine_qbman_swp();
95 PMD_DRV_LOG(ERR, "Failure in affining portal\n");
100 swp = DPAA2_PER_LCORE_PORTAL;
103 frames_to_send = (nb_events >> 3) ?
104 MAX_TX_RING_SLOTS : nb_events;
106 for (loop = 0; loop < frames_to_send; loop++) {
107 const struct rte_event *event = &ev[num_tx + loop];
109 if (event->sched_type != RTE_SCHED_TYPE_ATOMIC)
110 fqid = evq_info->dpci->queue[
111 DPAA2_EVENT_DPCI_PARALLEL_QUEUE].fqid;
113 fqid = evq_info->dpci->queue[
114 DPAA2_EVENT_DPCI_ATOMIC_QUEUE].fqid;
116 /* Prepare enqueue descriptor */
117 qbman_eq_desc_clear(&eqdesc[loop]);
118 qbman_eq_desc_set_fq(&eqdesc[loop], fqid);
119 qbman_eq_desc_set_no_orp(&eqdesc[loop], 0);
120 qbman_eq_desc_set_response(&eqdesc[loop], 0, 0);
122 if (event->impl_opaque) {
123 uint8_t dqrr_index = event->impl_opaque - 1;
125 qbman_eq_desc_set_dca(&eqdesc[loop], 1,
127 DPAA2_PER_LCORE_DPIO->dqrr_size--;
128 DPAA2_PER_LCORE_DPIO->dqrr_held &=
132 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
135 * todo - need to align with hw context data
138 struct rte_event *ev_temp = rte_malloc(NULL,
139 sizeof(struct rte_event), 0);
140 rte_memcpy(ev_temp, event, sizeof(struct rte_event));
141 DPAA2_SET_FD_ADDR((&fd_arr[loop]), ev_temp);
142 DPAA2_SET_FD_LEN((&fd_arr[loop]),
143 sizeof(struct rte_event));
146 while (loop < frames_to_send) {
147 loop += qbman_swp_enqueue_multiple_desc(swp,
148 &eqdesc[loop], &fd_arr[loop],
149 frames_to_send - loop);
151 num_tx += frames_to_send;
152 nb_events -= frames_to_send;
159 dpaa2_eventdev_enqueue(void *port, const struct rte_event *ev)
161 return dpaa2_eventdev_enqueue_burst(port, ev, 1);
164 static void dpaa2_eventdev_dequeue_wait(uint64_t timeout_ticks)
166 struct epoll_event epoll_ev;
169 qbman_swp_interrupt_clear_status(DPAA2_PER_LCORE_PORTAL,
170 QBMAN_SWP_INTERRUPT_DQRI);
173 ret = epoll_wait(DPAA2_PER_LCORE_DPIO->epoll_fd,
174 &epoll_ev, 1, timeout_ticks);
176 /* sometimes due to some spurious interrupts epoll_wait fails
177 * with errno EINTR. so here we are retrying epoll_wait in such
178 * case to avoid the problem.
180 if (errno == EINTR) {
181 PMD_DRV_LOG(DEBUG, "epoll_wait fails\n");
183 PMD_DRV_LOG(DEBUG, "Dequeue burst Failed\n");
189 static void dpaa2_eventdev_process_parallel(struct qbman_swp *swp,
190 const struct qbman_fd *fd,
191 const struct qbman_result *dq,
192 struct dpaa2_queue *rxq,
193 struct rte_event *ev)
195 struct rte_event *ev_temp =
196 (struct rte_event *)DPAA2_GET_FD_ADDR(fd);
200 rte_memcpy(ev, ev_temp, sizeof(struct rte_event));
203 qbman_swp_dqrr_consume(swp, dq);
206 static void dpaa2_eventdev_process_atomic(struct qbman_swp *swp,
207 const struct qbman_fd *fd,
208 const struct qbman_result *dq,
209 struct dpaa2_queue *rxq,
210 struct rte_event *ev)
212 struct rte_event *ev_temp =
213 (struct rte_event *)DPAA2_GET_FD_ADDR(fd);
214 uint8_t dqrr_index = qbman_get_dqrr_idx(dq);
219 rte_memcpy(ev, ev_temp, sizeof(struct rte_event));
221 ev->impl_opaque = dqrr_index + 1;
222 DPAA2_PER_LCORE_DPIO->dqrr_size++;
223 DPAA2_PER_LCORE_DPIO->dqrr_held |= 1 << dqrr_index;
227 dpaa2_eventdev_dequeue_burst(void *port, struct rte_event ev[],
228 uint16_t nb_events, uint64_t timeout_ticks)
230 const struct qbman_result *dq;
231 struct qbman_swp *swp;
232 const struct qbman_fd *fd;
233 struct dpaa2_queue *rxq;
234 int num_pkts = 0, ret, i = 0;
238 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
239 ret = dpaa2_affine_qbman_swp();
241 PMD_DRV_LOG(ERR, "Failure in affining portal\n");
246 swp = DPAA2_PER_LCORE_PORTAL;
248 /* Check if there are atomic contexts to be released */
249 while (DPAA2_PER_LCORE_DPIO->dqrr_size) {
250 if (DPAA2_PER_LCORE_DPIO->dqrr_held & (1 << i)) {
251 dq = qbman_get_dqrr_from_idx(swp, i);
252 qbman_swp_dqrr_consume(swp, dq);
253 DPAA2_PER_LCORE_DPIO->dqrr_size--;
257 DPAA2_PER_LCORE_DPIO->dqrr_held = 0;
260 dq = qbman_swp_dqrr_next(swp);
262 if (!num_pkts && timeout_ticks) {
263 dpaa2_eventdev_dequeue_wait(timeout_ticks);
270 fd = qbman_result_DQ_fd(dq);
272 rxq = (struct dpaa2_queue *)qbman_result_DQ_fqd_ctx(dq);
274 rxq->cb(swp, fd, dq, rxq, &ev[num_pkts]);
276 qbman_swp_dqrr_consume(swp, dq);
277 PMD_DRV_LOG(ERR, "Null Return VQ received\n");
282 } while (num_pkts < nb_events);
288 dpaa2_eventdev_dequeue(void *port, struct rte_event *ev,
289 uint64_t timeout_ticks)
291 return dpaa2_eventdev_dequeue_burst(port, ev, 1, timeout_ticks);
295 dpaa2_eventdev_info_get(struct rte_eventdev *dev,
296 struct rte_event_dev_info *dev_info)
298 struct dpaa2_eventdev *priv = dev->data->dev_private;
300 PMD_DRV_FUNC_TRACE();
304 memset(dev_info, 0, sizeof(struct rte_event_dev_info));
305 dev_info->min_dequeue_timeout_ns =
306 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
307 dev_info->max_dequeue_timeout_ns =
308 DPAA2_EVENT_MAX_DEQUEUE_TIMEOUT;
309 dev_info->dequeue_timeout_ns =
310 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
311 dev_info->max_event_queues = priv->max_event_queues;
312 dev_info->max_event_queue_flows =
313 DPAA2_EVENT_MAX_QUEUE_FLOWS;
314 dev_info->max_event_queue_priority_levels =
315 DPAA2_EVENT_MAX_QUEUE_PRIORITY_LEVELS;
316 dev_info->max_event_priority_levels =
317 DPAA2_EVENT_MAX_EVENT_PRIORITY_LEVELS;
318 dev_info->max_event_ports = RTE_MAX_LCORE;
319 dev_info->max_event_port_dequeue_depth =
320 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
321 dev_info->max_event_port_enqueue_depth =
322 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
323 dev_info->max_num_events = DPAA2_EVENT_MAX_NUM_EVENTS;
324 dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
325 RTE_EVENT_DEV_CAP_BURST_MODE;
329 dpaa2_eventdev_configure(const struct rte_eventdev *dev)
331 struct dpaa2_eventdev *priv = dev->data->dev_private;
332 struct rte_event_dev_config *conf = &dev->data->dev_conf;
334 PMD_DRV_FUNC_TRACE();
336 priv->dequeue_timeout_ns = conf->dequeue_timeout_ns;
337 priv->nb_event_queues = conf->nb_event_queues;
338 priv->nb_event_ports = conf->nb_event_ports;
339 priv->nb_event_queue_flows = conf->nb_event_queue_flows;
340 priv->nb_event_port_dequeue_depth = conf->nb_event_port_dequeue_depth;
341 priv->nb_event_port_enqueue_depth = conf->nb_event_port_enqueue_depth;
342 priv->event_dev_cfg = conf->event_dev_cfg;
344 PMD_DRV_LOG(DEBUG, "Configured eventdev devid=%d", dev->data->dev_id);
349 dpaa2_eventdev_start(struct rte_eventdev *dev)
351 PMD_DRV_FUNC_TRACE();
359 dpaa2_eventdev_stop(struct rte_eventdev *dev)
361 PMD_DRV_FUNC_TRACE();
367 dpaa2_eventdev_close(struct rte_eventdev *dev)
369 PMD_DRV_FUNC_TRACE();
377 dpaa2_eventdev_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
378 struct rte_event_queue_conf *queue_conf)
380 PMD_DRV_FUNC_TRACE();
383 RTE_SET_USED(queue_id);
384 RTE_SET_USED(queue_conf);
386 queue_conf->nb_atomic_flows = DPAA2_EVENT_QUEUE_ATOMIC_FLOWS;
387 queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY |
388 RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY;
389 queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
393 dpaa2_eventdev_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
395 PMD_DRV_FUNC_TRACE();
398 RTE_SET_USED(queue_id);
402 dpaa2_eventdev_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
403 const struct rte_event_queue_conf *queue_conf)
405 struct dpaa2_eventdev *priv = dev->data->dev_private;
406 struct evq_info_t *evq_info =
407 &priv->evq_info[queue_id];
409 PMD_DRV_FUNC_TRACE();
411 evq_info->event_queue_cfg = queue_conf->event_queue_cfg;
417 dpaa2_eventdev_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
418 struct rte_event_port_conf *port_conf)
420 PMD_DRV_FUNC_TRACE();
423 RTE_SET_USED(port_id);
424 RTE_SET_USED(port_conf);
426 port_conf->new_event_threshold =
427 DPAA2_EVENT_MAX_NUM_EVENTS;
428 port_conf->dequeue_depth =
429 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
430 port_conf->enqueue_depth =
431 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
435 dpaa2_eventdev_port_release(void *port)
437 PMD_DRV_FUNC_TRACE();
443 dpaa2_eventdev_port_setup(struct rte_eventdev *dev, uint8_t port_id,
444 const struct rte_event_port_conf *port_conf)
446 PMD_DRV_FUNC_TRACE();
448 RTE_SET_USED(port_conf);
450 if (!dpaa2_io_portal[port_id].dpio_dev) {
451 dpaa2_io_portal[port_id].dpio_dev =
452 dpaa2_get_qbman_swp(port_id);
453 rte_atomic16_inc(&dpaa2_io_portal[port_id].dpio_dev->ref_count);
454 if (!dpaa2_io_portal[port_id].dpio_dev)
458 dpaa2_io_portal[port_id].eventdev = dev;
459 dev->data->ports[port_id] = &dpaa2_io_portal[port_id];
464 dpaa2_eventdev_port_unlink(struct rte_eventdev *dev, void *port,
465 uint8_t queues[], uint16_t nb_unlinks)
467 struct dpaa2_eventdev *priv = dev->data->dev_private;
468 struct dpaa2_io_portal_t *dpaa2_portal = port;
469 struct evq_info_t *evq_info;
472 PMD_DRV_FUNC_TRACE();
474 for (i = 0; i < nb_unlinks; i++) {
475 evq_info = &priv->evq_info[queues[i]];
476 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
477 evq_info->dpcon->channel_index, 0);
478 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
479 0, dpaa2_portal->dpio_dev->token,
480 evq_info->dpcon->dpcon_id);
484 return (int)nb_unlinks;
488 dpaa2_eventdev_port_link(struct rte_eventdev *dev, void *port,
489 const uint8_t queues[], const uint8_t priorities[],
492 struct dpaa2_eventdev *priv = dev->data->dev_private;
493 struct dpaa2_io_portal_t *dpaa2_portal = port;
494 struct evq_info_t *evq_info;
495 uint8_t channel_index;
498 PMD_DRV_FUNC_TRACE();
500 for (i = 0; i < nb_links; i++) {
501 evq_info = &priv->evq_info[queues[i]];
505 ret = dpio_add_static_dequeue_channel(
506 dpaa2_portal->dpio_dev->dpio,
507 CMD_PRI_LOW, dpaa2_portal->dpio_dev->token,
508 evq_info->dpcon->dpcon_id, &channel_index);
510 PMD_DRV_ERR("Static dequeue cfg failed with ret: %d\n",
515 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
517 evq_info->dpcon->channel_index = channel_index;
521 RTE_SET_USED(priorities);
523 return (int)nb_links;
525 for (n = 0; n < i; n++) {
526 evq_info = &priv->evq_info[queues[n]];
527 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
528 evq_info->dpcon->channel_index, 0);
529 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
530 0, dpaa2_portal->dpio_dev->token,
531 evq_info->dpcon->dpcon_id);
538 dpaa2_eventdev_timeout_ticks(struct rte_eventdev *dev, uint64_t ns,
539 uint64_t *timeout_ticks)
543 PMD_DRV_FUNC_TRACE();
546 *timeout_ticks = ns * scale;
552 dpaa2_eventdev_dump(struct rte_eventdev *dev, FILE *f)
554 PMD_DRV_FUNC_TRACE();
560 static const struct rte_eventdev_ops dpaa2_eventdev_ops = {
561 .dev_infos_get = dpaa2_eventdev_info_get,
562 .dev_configure = dpaa2_eventdev_configure,
563 .dev_start = dpaa2_eventdev_start,
564 .dev_stop = dpaa2_eventdev_stop,
565 .dev_close = dpaa2_eventdev_close,
566 .queue_def_conf = dpaa2_eventdev_queue_def_conf,
567 .queue_setup = dpaa2_eventdev_queue_setup,
568 .queue_release = dpaa2_eventdev_queue_release,
569 .port_def_conf = dpaa2_eventdev_port_def_conf,
570 .port_setup = dpaa2_eventdev_port_setup,
571 .port_release = dpaa2_eventdev_port_release,
572 .port_link = dpaa2_eventdev_port_link,
573 .port_unlink = dpaa2_eventdev_port_unlink,
574 .timeout_ticks = dpaa2_eventdev_timeout_ticks,
575 .dump = dpaa2_eventdev_dump
579 dpaa2_eventdev_setup_dpci(struct dpaa2_dpci_dev *dpci_dev,
580 struct dpaa2_dpcon_dev *dpcon_dev)
582 struct dpci_rx_queue_cfg rx_queue_cfg;
585 /*Do settings to get the frame on a DPCON object*/
586 rx_queue_cfg.options = DPCI_QUEUE_OPT_DEST |
587 DPCI_QUEUE_OPT_USER_CTX;
588 rx_queue_cfg.dest_cfg.dest_type = DPCI_DEST_DPCON;
589 rx_queue_cfg.dest_cfg.dest_id = dpcon_dev->dpcon_id;
590 rx_queue_cfg.dest_cfg.priority = DPAA2_EVENT_DEFAULT_DPCI_PRIO;
592 dpci_dev->queue[DPAA2_EVENT_DPCI_PARALLEL_QUEUE].cb =
593 dpaa2_eventdev_process_parallel;
594 dpci_dev->queue[DPAA2_EVENT_DPCI_ATOMIC_QUEUE].cb =
595 dpaa2_eventdev_process_atomic;
597 for (i = 0 ; i < DPAA2_EVENT_DPCI_MAX_QUEUES; i++) {
598 rx_queue_cfg.user_ctx = (uint64_t)(&dpci_dev->queue[i]);
599 ret = dpci_set_rx_queue(&dpci_dev->dpci,
605 "set_rx_q failed with err code: %d", ret);
613 dpaa2_eventdev_create(const char *name)
615 struct rte_eventdev *eventdev;
616 struct dpaa2_eventdev *priv;
617 struct dpaa2_dpcon_dev *dpcon_dev = NULL;
618 struct dpaa2_dpci_dev *dpci_dev = NULL;
621 eventdev = rte_event_pmd_vdev_init(name,
622 sizeof(struct dpaa2_eventdev),
624 if (eventdev == NULL) {
625 PMD_DRV_ERR("Failed to create eventdev vdev %s", name);
629 eventdev->dev_ops = &dpaa2_eventdev_ops;
630 eventdev->schedule = NULL;
631 eventdev->enqueue = dpaa2_eventdev_enqueue;
632 eventdev->enqueue_burst = dpaa2_eventdev_enqueue_burst;
633 eventdev->enqueue_new_burst = dpaa2_eventdev_enqueue_burst;
634 eventdev->enqueue_forward_burst = dpaa2_eventdev_enqueue_burst;
635 eventdev->dequeue = dpaa2_eventdev_dequeue;
636 eventdev->dequeue_burst = dpaa2_eventdev_dequeue_burst;
638 /* For secondary processes, the primary has done all the work */
639 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
642 priv = eventdev->data->dev_private;
643 priv->max_event_queues = 0;
646 dpcon_dev = rte_dpaa2_alloc_dpcon_dev();
649 priv->evq_info[priv->max_event_queues].dpcon = dpcon_dev;
651 dpci_dev = rte_dpaa2_alloc_dpci_dev();
653 rte_dpaa2_free_dpcon_dev(dpcon_dev);
656 priv->evq_info[priv->max_event_queues].dpci = dpci_dev;
658 ret = dpaa2_eventdev_setup_dpci(dpci_dev, dpcon_dev);
661 "dpci setup failed with err code: %d", ret);
664 priv->max_event_queues++;
665 } while (dpcon_dev && dpci_dev);
673 dpaa2_eventdev_probe(struct rte_vdev_device *vdev)
677 name = rte_vdev_device_name(vdev);
678 PMD_DRV_LOG(INFO, "Initializing %s", name);
679 return dpaa2_eventdev_create(name);
683 dpaa2_eventdev_remove(struct rte_vdev_device *vdev)
687 name = rte_vdev_device_name(vdev);
688 PMD_DRV_LOG(INFO, "Closing %s", name);
690 return rte_event_pmd_vdev_uninit(name);
693 static struct rte_vdev_driver vdev_eventdev_dpaa2_pmd = {
694 .probe = dpaa2_eventdev_probe,
695 .remove = dpaa2_eventdev_remove
698 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_DPAA2_PMD, vdev_eventdev_dpaa2_pmd);