event/dpaa2: remove check on epoll return
[dpdk.git] / drivers / event / dpaa2 / dpaa2_eventdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017 NXP
4  *
5  */
6
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdbool.h>
10 #include <errno.h>
11 #include <stdint.h>
12 #include <string.h>
13 #include <sys/epoll.h>
14
15 #include <rte_atomic.h>
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
18 #include <rte_debug.h>
19 #include <rte_dev.h>
20 #include <rte_eal.h>
21 #include <rte_fslmc.h>
22 #include <rte_lcore.h>
23 #include <rte_log.h>
24 #include <rte_malloc.h>
25 #include <rte_memcpy.h>
26 #include <rte_memory.h>
27 #include <rte_pci.h>
28 #include <rte_bus_vdev.h>
29 #include <rte_ethdev_driver.h>
30 #include <rte_event_eth_rx_adapter.h>
31
32 #include <fslmc_vfio.h>
33 #include <dpaa2_hw_pvt.h>
34 #include <dpaa2_hw_mempool.h>
35 #include <dpaa2_hw_dpio.h>
36 #include <dpaa2_ethdev.h>
37 #include "dpaa2_eventdev.h"
38 #include "dpaa2_eventdev_logs.h"
39 #include <portal/dpaa2_hw_pvt.h>
40 #include <mc/fsl_dpci.h>
41
42 /* Clarifications
43  * Evendev = SoC Instance
44  * Eventport = DPIO Instance
45  * Eventqueue = DPCON Instance
46  * 1 Eventdev can have N Eventqueue
47  * Soft Event Flow is DPCI Instance
48  */
49
50 /* Dynamic logging identified for mempool */
51 int dpaa2_logtype_event;
52
53 static uint16_t
54 dpaa2_eventdev_enqueue_burst(void *port, const struct rte_event ev[],
55                              uint16_t nb_events)
56 {
57         struct rte_eventdev *ev_dev =
58                         ((struct dpaa2_io_portal_t *)port)->eventdev;
59         struct dpaa2_eventdev *priv = ev_dev->data->dev_private;
60         uint32_t queue_id = ev[0].queue_id;
61         struct evq_info_t *evq_info = &priv->evq_info[queue_id];
62         uint32_t fqid;
63         struct qbman_swp *swp;
64         struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
65         uint32_t loop, frames_to_send;
66         struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
67         uint16_t num_tx = 0;
68         int ret;
69
70         RTE_SET_USED(port);
71
72         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
73                 ret = dpaa2_affine_qbman_swp();
74                 if (ret) {
75                         DPAA2_EVENTDEV_ERR("Failure in affining portal");
76                         return 0;
77                 }
78         }
79
80         swp = DPAA2_PER_LCORE_PORTAL;
81
82         while (nb_events) {
83                 frames_to_send = (nb_events >> 3) ?
84                         MAX_TX_RING_SLOTS : nb_events;
85
86                 for (loop = 0; loop < frames_to_send; loop++) {
87                         const struct rte_event *event = &ev[num_tx + loop];
88
89                         if (event->sched_type != RTE_SCHED_TYPE_ATOMIC)
90                                 fqid = evq_info->dpci->rx_queue[
91                                         DPAA2_EVENT_DPCI_PARALLEL_QUEUE].fqid;
92                         else
93                                 fqid = evq_info->dpci->rx_queue[
94                                         DPAA2_EVENT_DPCI_ATOMIC_QUEUE].fqid;
95
96                         /* Prepare enqueue descriptor */
97                         qbman_eq_desc_clear(&eqdesc[loop]);
98                         qbman_eq_desc_set_fq(&eqdesc[loop], fqid);
99                         qbman_eq_desc_set_no_orp(&eqdesc[loop], 0);
100                         qbman_eq_desc_set_response(&eqdesc[loop], 0, 0);
101
102                         if (event->mbuf->seqn) {
103                                 uint8_t dqrr_index = event->mbuf->seqn - 1;
104
105                                 qbman_eq_desc_set_dca(&eqdesc[loop], 1,
106                                                       dqrr_index, 0);
107                                 DPAA2_PER_LCORE_DQRR_SIZE--;
108                                 DPAA2_PER_LCORE_DQRR_HELD &=
109                                         ~(1 << dqrr_index);
110                         }
111
112                         memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
113
114                         /*
115                          * todo - need to align with hw context data
116                          * to avoid copy
117                          */
118                         struct rte_event *ev_temp = rte_malloc(NULL,
119                                 sizeof(struct rte_event), 0);
120
121                         if (!ev_temp) {
122                                 if (!loop)
123                                         return num_tx;
124                                 frames_to_send = loop;
125                                 DPAA2_EVENTDEV_ERR(
126                                         "Unable to allocate event object");
127                                 goto send_partial;
128                         }
129                         rte_memcpy(ev_temp, event, sizeof(struct rte_event));
130                         DPAA2_SET_FD_ADDR((&fd_arr[loop]), (size_t)ev_temp);
131                         DPAA2_SET_FD_LEN((&fd_arr[loop]),
132                                          sizeof(struct rte_event));
133                 }
134 send_partial:
135                 loop = 0;
136                 while (loop < frames_to_send) {
137                         loop += qbman_swp_enqueue_multiple_desc(swp,
138                                         &eqdesc[loop], &fd_arr[loop],
139                                         frames_to_send - loop);
140                 }
141                 num_tx += frames_to_send;
142                 nb_events -= frames_to_send;
143         }
144
145         return num_tx;
146 }
147
148 static uint16_t
149 dpaa2_eventdev_enqueue(void *port, const struct rte_event *ev)
150 {
151         return dpaa2_eventdev_enqueue_burst(port, ev, 1);
152 }
153
154 static void dpaa2_eventdev_dequeue_wait(uint64_t timeout_ticks)
155 {
156         struct epoll_event epoll_ev;
157
158         qbman_swp_interrupt_clear_status(DPAA2_PER_LCORE_PORTAL,
159                                          QBMAN_SWP_INTERRUPT_DQRI);
160
161         epoll_wait(DPAA2_PER_LCORE_DPIO->epoll_fd,
162                          &epoll_ev, 1, timeout_ticks);
163 }
164
165 static void dpaa2_eventdev_process_parallel(struct qbman_swp *swp,
166                                             const struct qbman_fd *fd,
167                                             const struct qbman_result *dq,
168                                             struct dpaa2_queue *rxq,
169                                             struct rte_event *ev)
170 {
171         struct rte_event *ev_temp =
172                 (struct rte_event *)(size_t)DPAA2_GET_FD_ADDR(fd);
173
174         RTE_SET_USED(rxq);
175
176         rte_memcpy(ev, ev_temp, sizeof(struct rte_event));
177         rte_free(ev_temp);
178
179         qbman_swp_dqrr_consume(swp, dq);
180 }
181
182 static void dpaa2_eventdev_process_atomic(struct qbman_swp *swp,
183                                           const struct qbman_fd *fd,
184                                           const struct qbman_result *dq,
185                                           struct dpaa2_queue *rxq,
186                                           struct rte_event *ev)
187 {
188         struct rte_event *ev_temp =
189                 (struct rte_event *)(size_t)DPAA2_GET_FD_ADDR(fd);
190         uint8_t dqrr_index = qbman_get_dqrr_idx(dq);
191
192         RTE_SET_USED(swp);
193         RTE_SET_USED(rxq);
194
195         rte_memcpy(ev, ev_temp, sizeof(struct rte_event));
196         rte_free(ev_temp);
197         ev->mbuf->seqn = dqrr_index + 1;
198         DPAA2_PER_LCORE_DQRR_SIZE++;
199         DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
200 }
201
202 static uint16_t
203 dpaa2_eventdev_dequeue_burst(void *port, struct rte_event ev[],
204                              uint16_t nb_events, uint64_t timeout_ticks)
205 {
206         const struct qbman_result *dq;
207         struct qbman_swp *swp;
208         const struct qbman_fd *fd;
209         struct dpaa2_queue *rxq;
210         int num_pkts = 0, ret, i = 0;
211
212         RTE_SET_USED(port);
213
214         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
215                 ret = dpaa2_affine_qbman_swp();
216                 if (ret) {
217                         DPAA2_EVENTDEV_ERR("Failure in affining portal");
218                         return 0;
219                 }
220         }
221         swp = DPAA2_PER_LCORE_PORTAL;
222
223         /* Check if there are atomic contexts to be released */
224         while (DPAA2_PER_LCORE_DQRR_SIZE) {
225                 if (DPAA2_PER_LCORE_DQRR_HELD & (1 << i)) {
226                         qbman_swp_dqrr_idx_consume(swp, i);
227                         DPAA2_PER_LCORE_DQRR_SIZE--;
228                         DPAA2_PER_LCORE_DQRR_MBUF(i)->seqn =
229                                 DPAA2_INVALID_MBUF_SEQN;
230                 }
231                 i++;
232         }
233         DPAA2_PER_LCORE_DQRR_HELD = 0;
234
235         do {
236                 dq = qbman_swp_dqrr_next(swp);
237                 if (!dq) {
238                         if (!num_pkts && timeout_ticks) {
239                                 dpaa2_eventdev_dequeue_wait(timeout_ticks);
240                                 timeout_ticks = 0;
241                                 continue;
242                         }
243                         return num_pkts;
244                 }
245                 qbman_swp_prefetch_dqrr_next(swp);
246
247                 fd = qbman_result_DQ_fd(dq);
248                 rxq = (struct dpaa2_queue *)(size_t)qbman_result_DQ_fqd_ctx(dq);
249                 if (rxq) {
250                         rxq->cb(swp, fd, dq, rxq, &ev[num_pkts]);
251                 } else {
252                         qbman_swp_dqrr_consume(swp, dq);
253                         DPAA2_EVENTDEV_ERR("Null Return VQ received");
254                         return 0;
255                 }
256
257                 num_pkts++;
258         } while (num_pkts < nb_events);
259
260         return num_pkts;
261 }
262
263 static uint16_t
264 dpaa2_eventdev_dequeue(void *port, struct rte_event *ev,
265                        uint64_t timeout_ticks)
266 {
267         return dpaa2_eventdev_dequeue_burst(port, ev, 1, timeout_ticks);
268 }
269
270 static void
271 dpaa2_eventdev_info_get(struct rte_eventdev *dev,
272                         struct rte_event_dev_info *dev_info)
273 {
274         struct dpaa2_eventdev *priv = dev->data->dev_private;
275
276         EVENTDEV_INIT_FUNC_TRACE();
277
278         RTE_SET_USED(dev);
279
280         memset(dev_info, 0, sizeof(struct rte_event_dev_info));
281         dev_info->min_dequeue_timeout_ns =
282                 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
283         dev_info->max_dequeue_timeout_ns =
284                 DPAA2_EVENT_MAX_DEQUEUE_TIMEOUT;
285         dev_info->dequeue_timeout_ns =
286                 DPAA2_EVENT_MIN_DEQUEUE_TIMEOUT;
287         dev_info->max_event_queues = priv->max_event_queues;
288         dev_info->max_event_queue_flows =
289                 DPAA2_EVENT_MAX_QUEUE_FLOWS;
290         dev_info->max_event_queue_priority_levels =
291                 DPAA2_EVENT_MAX_QUEUE_PRIORITY_LEVELS;
292         dev_info->max_event_priority_levels =
293                 DPAA2_EVENT_MAX_EVENT_PRIORITY_LEVELS;
294         dev_info->max_event_ports = rte_fslmc_get_device_count(DPAA2_IO);
295         dev_info->max_event_port_dequeue_depth =
296                 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
297         dev_info->max_event_port_enqueue_depth =
298                 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
299         dev_info->max_num_events = DPAA2_EVENT_MAX_NUM_EVENTS;
300         dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
301                 RTE_EVENT_DEV_CAP_BURST_MODE|
302                 RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
303                 RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
304                 RTE_EVENT_DEV_CAP_NONSEQ_MODE;
305
306 }
307
308 static int
309 dpaa2_eventdev_configure(const struct rte_eventdev *dev)
310 {
311         struct dpaa2_eventdev *priv = dev->data->dev_private;
312         struct rte_event_dev_config *conf = &dev->data->dev_conf;
313
314         EVENTDEV_INIT_FUNC_TRACE();
315
316         priv->dequeue_timeout_ns = conf->dequeue_timeout_ns;
317         priv->nb_event_queues = conf->nb_event_queues;
318         priv->nb_event_ports = conf->nb_event_ports;
319         priv->nb_event_queue_flows = conf->nb_event_queue_flows;
320         priv->nb_event_port_dequeue_depth = conf->nb_event_port_dequeue_depth;
321         priv->nb_event_port_enqueue_depth = conf->nb_event_port_enqueue_depth;
322         priv->event_dev_cfg = conf->event_dev_cfg;
323
324         DPAA2_EVENTDEV_DEBUG("Configured eventdev devid=%d",
325                              dev->data->dev_id);
326         return 0;
327 }
328
329 static int
330 dpaa2_eventdev_start(struct rte_eventdev *dev)
331 {
332         EVENTDEV_INIT_FUNC_TRACE();
333
334         RTE_SET_USED(dev);
335
336         return 0;
337 }
338
339 static void
340 dpaa2_eventdev_stop(struct rte_eventdev *dev)
341 {
342         EVENTDEV_INIT_FUNC_TRACE();
343
344         RTE_SET_USED(dev);
345 }
346
347 static int
348 dpaa2_eventdev_close(struct rte_eventdev *dev)
349 {
350         EVENTDEV_INIT_FUNC_TRACE();
351
352         RTE_SET_USED(dev);
353
354         return 0;
355 }
356
357 static void
358 dpaa2_eventdev_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
359                               struct rte_event_queue_conf *queue_conf)
360 {
361         EVENTDEV_INIT_FUNC_TRACE();
362
363         RTE_SET_USED(dev);
364         RTE_SET_USED(queue_id);
365         RTE_SET_USED(queue_conf);
366
367         queue_conf->nb_atomic_flows = DPAA2_EVENT_QUEUE_ATOMIC_FLOWS;
368         queue_conf->schedule_type = RTE_SCHED_TYPE_ATOMIC |
369                                       RTE_SCHED_TYPE_PARALLEL;
370         queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
371 }
372
373 static void
374 dpaa2_eventdev_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
375 {
376         EVENTDEV_INIT_FUNC_TRACE();
377
378         RTE_SET_USED(dev);
379         RTE_SET_USED(queue_id);
380 }
381
382 static int
383 dpaa2_eventdev_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
384                            const struct rte_event_queue_conf *queue_conf)
385 {
386         struct dpaa2_eventdev *priv = dev->data->dev_private;
387         struct evq_info_t *evq_info =
388                 &priv->evq_info[queue_id];
389
390         EVENTDEV_INIT_FUNC_TRACE();
391
392         evq_info->event_queue_cfg = queue_conf->event_queue_cfg;
393
394         return 0;
395 }
396
397 static void
398 dpaa2_eventdev_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
399                              struct rte_event_port_conf *port_conf)
400 {
401         EVENTDEV_INIT_FUNC_TRACE();
402
403         RTE_SET_USED(dev);
404         RTE_SET_USED(port_id);
405         RTE_SET_USED(port_conf);
406
407         port_conf->new_event_threshold =
408                 DPAA2_EVENT_MAX_NUM_EVENTS;
409         port_conf->dequeue_depth =
410                 DPAA2_EVENT_MAX_PORT_DEQUEUE_DEPTH;
411         port_conf->enqueue_depth =
412                 DPAA2_EVENT_MAX_PORT_ENQUEUE_DEPTH;
413         port_conf->disable_implicit_release = 0;
414 }
415
416 static void
417 dpaa2_eventdev_port_release(void *port)
418 {
419         EVENTDEV_INIT_FUNC_TRACE();
420
421         RTE_SET_USED(port);
422 }
423
424 static int
425 dpaa2_eventdev_port_setup(struct rte_eventdev *dev, uint8_t port_id,
426                           const struct rte_event_port_conf *port_conf)
427 {
428         EVENTDEV_INIT_FUNC_TRACE();
429
430         RTE_SET_USED(port_conf);
431
432         if (!dpaa2_io_portal[port_id].dpio_dev) {
433                 dpaa2_io_portal[port_id].dpio_dev =
434                                 dpaa2_get_qbman_swp(port_id);
435                 rte_atomic16_inc(&dpaa2_io_portal[port_id].dpio_dev->ref_count);
436                 if (!dpaa2_io_portal[port_id].dpio_dev)
437                         return -1;
438         }
439
440         dpaa2_io_portal[port_id].eventdev = dev;
441         dev->data->ports[port_id] = &dpaa2_io_portal[port_id];
442         return 0;
443 }
444
445 static int
446 dpaa2_eventdev_port_unlink(struct rte_eventdev *dev, void *port,
447                            uint8_t queues[], uint16_t nb_unlinks)
448 {
449         struct dpaa2_eventdev *priv = dev->data->dev_private;
450         struct dpaa2_io_portal_t *dpaa2_portal = port;
451         struct evq_info_t *evq_info;
452         int i;
453
454         EVENTDEV_INIT_FUNC_TRACE();
455
456         for (i = 0; i < nb_unlinks; i++) {
457                 evq_info = &priv->evq_info[queues[i]];
458                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
459                                    evq_info->dpcon->channel_index, 0);
460                 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
461                                         0, dpaa2_portal->dpio_dev->token,
462                         evq_info->dpcon->dpcon_id);
463                 evq_info->link = 0;
464         }
465
466         return (int)nb_unlinks;
467 }
468
469 static int
470 dpaa2_eventdev_port_link(struct rte_eventdev *dev, void *port,
471                          const uint8_t queues[], const uint8_t priorities[],
472                         uint16_t nb_links)
473 {
474         struct dpaa2_eventdev *priv = dev->data->dev_private;
475         struct dpaa2_io_portal_t *dpaa2_portal = port;
476         struct evq_info_t *evq_info;
477         uint8_t channel_index;
478         int ret, i, n;
479
480         EVENTDEV_INIT_FUNC_TRACE();
481
482         for (i = 0; i < nb_links; i++) {
483                 evq_info = &priv->evq_info[queues[i]];
484                 if (evq_info->link)
485                         continue;
486
487                 ret = dpio_add_static_dequeue_channel(
488                         dpaa2_portal->dpio_dev->dpio,
489                         CMD_PRI_LOW, dpaa2_portal->dpio_dev->token,
490                         evq_info->dpcon->dpcon_id, &channel_index);
491                 if (ret < 0) {
492                         DPAA2_EVENTDEV_ERR(
493                                 "Static dequeue config failed: err(%d)", ret);
494                         goto err;
495                 }
496
497                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
498                                    channel_index, 1);
499                 evq_info->dpcon->channel_index = channel_index;
500                 evq_info->link = 1;
501         }
502
503         RTE_SET_USED(priorities);
504
505         return (int)nb_links;
506 err:
507         for (n = 0; n < i; n++) {
508                 evq_info = &priv->evq_info[queues[n]];
509                 qbman_swp_push_set(dpaa2_portal->dpio_dev->sw_portal,
510                                    evq_info->dpcon->channel_index, 0);
511                 dpio_remove_static_dequeue_channel(dpaa2_portal->dpio_dev->dpio,
512                                         0, dpaa2_portal->dpio_dev->token,
513                         evq_info->dpcon->dpcon_id);
514                 evq_info->link = 0;
515         }
516         return ret;
517 }
518
519 static int
520 dpaa2_eventdev_timeout_ticks(struct rte_eventdev *dev, uint64_t ns,
521                              uint64_t *timeout_ticks)
522 {
523         uint32_t scale = 1;
524
525         EVENTDEV_INIT_FUNC_TRACE();
526
527         RTE_SET_USED(dev);
528         *timeout_ticks = ns * scale;
529
530         return 0;
531 }
532
533 static void
534 dpaa2_eventdev_dump(struct rte_eventdev *dev, FILE *f)
535 {
536         EVENTDEV_INIT_FUNC_TRACE();
537
538         RTE_SET_USED(dev);
539         RTE_SET_USED(f);
540 }
541
542 static int
543 dpaa2_eventdev_eth_caps_get(const struct rte_eventdev *dev,
544                             const struct rte_eth_dev *eth_dev,
545                             uint32_t *caps)
546 {
547         const char *ethdev_driver = eth_dev->device->driver->name;
548
549         EVENTDEV_INIT_FUNC_TRACE();
550
551         RTE_SET_USED(dev);
552
553         if (!strcmp(ethdev_driver, "net_dpaa2"))
554                 *caps = RTE_EVENT_ETH_RX_ADAPTER_DPAA2_CAP;
555         else
556                 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
557
558         return 0;
559 }
560
561 static int
562 dpaa2_eventdev_eth_queue_add_all(const struct rte_eventdev *dev,
563                 const struct rte_eth_dev *eth_dev,
564                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
565 {
566         struct dpaa2_eventdev *priv = dev->data->dev_private;
567         uint8_t ev_qid = queue_conf->ev.queue_id;
568         uint16_t dpcon_id = priv->evq_info[ev_qid].dpcon->dpcon_id;
569         int i, ret;
570
571         EVENTDEV_INIT_FUNC_TRACE();
572
573         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
574                 ret = dpaa2_eth_eventq_attach(eth_dev, i,
575                                 dpcon_id, queue_conf);
576                 if (ret) {
577                         DPAA2_EVENTDEV_ERR(
578                                 "Event queue attach failed: err(%d)", ret);
579                         goto fail;
580                 }
581         }
582         return 0;
583 fail:
584         for (i = (i - 1); i >= 0 ; i--)
585                 dpaa2_eth_eventq_detach(eth_dev, i);
586
587         return ret;
588 }
589
590 static int
591 dpaa2_eventdev_eth_queue_add(const struct rte_eventdev *dev,
592                 const struct rte_eth_dev *eth_dev,
593                 int32_t rx_queue_id,
594                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
595 {
596         struct dpaa2_eventdev *priv = dev->data->dev_private;
597         uint8_t ev_qid = queue_conf->ev.queue_id;
598         uint16_t dpcon_id = priv->evq_info[ev_qid].dpcon->dpcon_id;
599         int ret;
600
601         EVENTDEV_INIT_FUNC_TRACE();
602
603         if (rx_queue_id == -1)
604                 return dpaa2_eventdev_eth_queue_add_all(dev,
605                                 eth_dev, queue_conf);
606
607         ret = dpaa2_eth_eventq_attach(eth_dev, rx_queue_id,
608                         dpcon_id, queue_conf);
609         if (ret) {
610                 DPAA2_EVENTDEV_ERR(
611                         "Event queue attach failed: err(%d)", ret);
612                 return ret;
613         }
614         return 0;
615 }
616
617 static int
618 dpaa2_eventdev_eth_queue_del_all(const struct rte_eventdev *dev,
619                              const struct rte_eth_dev *eth_dev)
620 {
621         int i, ret;
622
623         EVENTDEV_INIT_FUNC_TRACE();
624
625         RTE_SET_USED(dev);
626
627         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
628                 ret = dpaa2_eth_eventq_detach(eth_dev, i);
629                 if (ret) {
630                         DPAA2_EVENTDEV_ERR(
631                                 "Event queue detach failed: err(%d)", ret);
632                         return ret;
633                 }
634         }
635
636         return 0;
637 }
638
639 static int
640 dpaa2_eventdev_eth_queue_del(const struct rte_eventdev *dev,
641                              const struct rte_eth_dev *eth_dev,
642                              int32_t rx_queue_id)
643 {
644         int ret;
645
646         EVENTDEV_INIT_FUNC_TRACE();
647
648         if (rx_queue_id == -1)
649                 return dpaa2_eventdev_eth_queue_del_all(dev, eth_dev);
650
651         ret = dpaa2_eth_eventq_detach(eth_dev, rx_queue_id);
652         if (ret) {
653                 DPAA2_EVENTDEV_ERR(
654                         "Event queue detach failed: err(%d)", ret);
655                 return ret;
656         }
657
658         return 0;
659 }
660
661 static int
662 dpaa2_eventdev_eth_start(const struct rte_eventdev *dev,
663                          const struct rte_eth_dev *eth_dev)
664 {
665         EVENTDEV_INIT_FUNC_TRACE();
666
667         RTE_SET_USED(dev);
668         RTE_SET_USED(eth_dev);
669
670         return 0;
671 }
672
673 static int
674 dpaa2_eventdev_eth_stop(const struct rte_eventdev *dev,
675                         const struct rte_eth_dev *eth_dev)
676 {
677         EVENTDEV_INIT_FUNC_TRACE();
678
679         RTE_SET_USED(dev);
680         RTE_SET_USED(eth_dev);
681
682         return 0;
683 }
684
685 static struct rte_eventdev_ops dpaa2_eventdev_ops = {
686         .dev_infos_get    = dpaa2_eventdev_info_get,
687         .dev_configure    = dpaa2_eventdev_configure,
688         .dev_start        = dpaa2_eventdev_start,
689         .dev_stop         = dpaa2_eventdev_stop,
690         .dev_close        = dpaa2_eventdev_close,
691         .queue_def_conf   = dpaa2_eventdev_queue_def_conf,
692         .queue_setup      = dpaa2_eventdev_queue_setup,
693         .queue_release    = dpaa2_eventdev_queue_release,
694         .port_def_conf    = dpaa2_eventdev_port_def_conf,
695         .port_setup       = dpaa2_eventdev_port_setup,
696         .port_release     = dpaa2_eventdev_port_release,
697         .port_link        = dpaa2_eventdev_port_link,
698         .port_unlink      = dpaa2_eventdev_port_unlink,
699         .timeout_ticks    = dpaa2_eventdev_timeout_ticks,
700         .dump             = dpaa2_eventdev_dump,
701         .eth_rx_adapter_caps_get = dpaa2_eventdev_eth_caps_get,
702         .eth_rx_adapter_queue_add = dpaa2_eventdev_eth_queue_add,
703         .eth_rx_adapter_queue_del = dpaa2_eventdev_eth_queue_del,
704         .eth_rx_adapter_start = dpaa2_eventdev_eth_start,
705         .eth_rx_adapter_stop = dpaa2_eventdev_eth_stop,
706 };
707
708 static int
709 dpaa2_eventdev_setup_dpci(struct dpaa2_dpci_dev *dpci_dev,
710                           struct dpaa2_dpcon_dev *dpcon_dev)
711 {
712         struct dpci_rx_queue_cfg rx_queue_cfg;
713         int ret, i;
714
715         /*Do settings to get the frame on a DPCON object*/
716         rx_queue_cfg.options = DPCI_QUEUE_OPT_DEST |
717                   DPCI_QUEUE_OPT_USER_CTX;
718         rx_queue_cfg.dest_cfg.dest_type = DPCI_DEST_DPCON;
719         rx_queue_cfg.dest_cfg.dest_id = dpcon_dev->dpcon_id;
720         rx_queue_cfg.dest_cfg.priority = DPAA2_EVENT_DEFAULT_DPCI_PRIO;
721
722         dpci_dev->rx_queue[DPAA2_EVENT_DPCI_PARALLEL_QUEUE].cb =
723                 dpaa2_eventdev_process_parallel;
724         dpci_dev->rx_queue[DPAA2_EVENT_DPCI_ATOMIC_QUEUE].cb =
725                 dpaa2_eventdev_process_atomic;
726
727         for (i = 0 ; i < DPAA2_EVENT_DPCI_MAX_QUEUES; i++) {
728                 rx_queue_cfg.user_ctx = (size_t)(&dpci_dev->rx_queue[i]);
729                 ret = dpci_set_rx_queue(&dpci_dev->dpci,
730                                         CMD_PRI_LOW,
731                                         dpci_dev->token, i,
732                                         &rx_queue_cfg);
733                 if (ret) {
734                         DPAA2_EVENTDEV_ERR(
735                                 "DPCI Rx queue setup failed: err(%d)",
736                                 ret);
737                         return ret;
738                 }
739         }
740         return 0;
741 }
742
743 static int
744 dpaa2_eventdev_create(const char *name)
745 {
746         struct rte_eventdev *eventdev;
747         struct dpaa2_eventdev *priv;
748         struct dpaa2_dpcon_dev *dpcon_dev = NULL;
749         struct dpaa2_dpci_dev *dpci_dev = NULL;
750         int ret;
751
752         eventdev = rte_event_pmd_vdev_init(name,
753                                            sizeof(struct dpaa2_eventdev),
754                                            rte_socket_id());
755         if (eventdev == NULL) {
756                 DPAA2_EVENTDEV_ERR("Failed to create Event device %s", name);
757                 goto fail;
758         }
759
760         eventdev->dev_ops       = &dpaa2_eventdev_ops;
761         eventdev->enqueue       = dpaa2_eventdev_enqueue;
762         eventdev->enqueue_burst = dpaa2_eventdev_enqueue_burst;
763         eventdev->enqueue_new_burst = dpaa2_eventdev_enqueue_burst;
764         eventdev->enqueue_forward_burst = dpaa2_eventdev_enqueue_burst;
765         eventdev->dequeue       = dpaa2_eventdev_dequeue;
766         eventdev->dequeue_burst = dpaa2_eventdev_dequeue_burst;
767
768         /* For secondary processes, the primary has done all the work */
769         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
770                 return 0;
771
772         priv = eventdev->data->dev_private;
773         priv->max_event_queues = 0;
774
775         do {
776                 dpcon_dev = rte_dpaa2_alloc_dpcon_dev();
777                 if (!dpcon_dev)
778                         break;
779                 priv->evq_info[priv->max_event_queues].dpcon = dpcon_dev;
780
781                 dpci_dev = rte_dpaa2_alloc_dpci_dev();
782                 if (!dpci_dev) {
783                         rte_dpaa2_free_dpcon_dev(dpcon_dev);
784                         break;
785                 }
786                 priv->evq_info[priv->max_event_queues].dpci = dpci_dev;
787
788                 ret = dpaa2_eventdev_setup_dpci(dpci_dev, dpcon_dev);
789                 if (ret) {
790                         DPAA2_EVENTDEV_ERR(
791                                     "DPCI setup failed: err(%d)", ret);
792                         return ret;
793                 }
794                 priv->max_event_queues++;
795         } while (dpcon_dev && dpci_dev);
796
797         return 0;
798 fail:
799         return -EFAULT;
800 }
801
802 static int
803 dpaa2_eventdev_probe(struct rte_vdev_device *vdev)
804 {
805         const char *name;
806
807         name = rte_vdev_device_name(vdev);
808         DPAA2_EVENTDEV_INFO("Initializing %s", name);
809         return dpaa2_eventdev_create(name);
810 }
811
812 static int
813 dpaa2_eventdev_remove(struct rte_vdev_device *vdev)
814 {
815         const char *name;
816
817         name = rte_vdev_device_name(vdev);
818         DPAA2_EVENTDEV_INFO("Closing %s", name);
819
820         return rte_event_pmd_vdev_uninit(name);
821 }
822
823 static struct rte_vdev_driver vdev_eventdev_dpaa2_pmd = {
824         .probe = dpaa2_eventdev_probe,
825         .remove = dpaa2_eventdev_remove
826 };
827
828 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_DPAA2_PMD, vdev_eventdev_dpaa2_pmd);
829
830 RTE_INIT(dpaa2_eventdev_init_log);
831 static void
832 dpaa2_eventdev_init_log(void)
833 {
834         dpaa2_logtype_event = rte_log_register("pmd.event.dpaa2");
835         if (dpaa2_logtype_event >= 0)
836                 rte_log_set_level(dpaa2_logtype_event, RTE_LOG_NOTICE);
837 }